Merge pull request #9153 from effbiae/wc-small-stack

Small stack compress -- 3000line reduction
This commit is contained in:
Daniel Pouzzner
2025-10-13 23:12:01 -05:00
committed by GitHub
62 changed files with 1570 additions and 4644 deletions
+21 -72
View File
@@ -757,11 +757,7 @@ int BufferLoadCRL(WOLFSSL_CRL* crl, const byte* buff, long sz, int type,
int ret = WOLFSSL_SUCCESS;
const byte* myBuffer = buff; /* if DER ok, otherwise switch */
DerBuffer* der = NULL;
#ifdef WOLFSSL_SMALL_STACK
DecodedCRL* dcrl;
#else
DecodedCRL dcrl[1];
#endif
WC_DECLARE_VAR(dcrl, DecodedCRL, 1, 0);
WOLFSSL_ENTER("BufferLoadCRL");
@@ -796,9 +792,7 @@ int BufferLoadCRL(WOLFSSL_CRL* crl, const byte* buff, long sz, int type,
crl->currentEntry = CRL_Entry_new(crl->heap);
if (crl->currentEntry == NULL) {
WOLFSSL_MSG_CERT_LOG("alloc CRL Entry failed");
#ifdef WOLFSSL_SMALL_STACK
XFREE(dcrl, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(dcrl, NULL, DYNAMIC_TYPE_TMP_BUFFER);
FreeDer(&der);
return MEMORY_E;
}
@@ -825,9 +819,7 @@ int BufferLoadCRL(WOLFSSL_CRL* crl, const byte* buff, long sz, int type,
FreeDecodedCRL(dcrl);
#ifdef WOLFSSL_SMALL_STACK
XFREE(dcrl, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(dcrl, NULL, DYNAMIC_TYPE_TMP_BUFFER);
FreeDer(&der);
@@ -843,11 +835,7 @@ int GetCRLInfo(WOLFSSL_CRL* crl, CrlInfo* info, const byte* buff,
const byte* myBuffer = buff; /* if DER ok, otherwise switch */
DerBuffer* der = NULL;
CRL_Entry* crle = NULL;
#ifdef WOLFSSL_SMALL_STACK
DecodedCRL* dcrl;
#else
DecodedCRL dcrl[1];
#endif
WC_DECLARE_VAR(dcrl, DecodedCRL, 1, 0);
WOLFSSL_ENTER("GetCRLInfo");
@@ -883,9 +871,7 @@ int GetCRLInfo(WOLFSSL_CRL* crl, CrlInfo* info, const byte* buff,
crle = CRL_Entry_new(crl->heap);
if (crle == NULL) {
WOLFSSL_MSG("alloc CRL Entry failed");
#ifdef WOLFSSL_SMALL_STACK
XFREE(dcrl, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(dcrl, NULL, DYNAMIC_TYPE_TMP_BUFFER);
FreeDer(&der);
return MEMORY_E;
}
@@ -904,9 +890,7 @@ int GetCRLInfo(WOLFSSL_CRL* crl, CrlInfo* info, const byte* buff,
FreeDecodedCRL(dcrl);
#ifdef WOLFSSL_SMALL_STACK
XFREE(dcrl, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(dcrl, NULL, DYNAMIC_TYPE_TMP_BUFFER);
FreeDer(&der);
CRL_Entry_free(crle, crl->heap);
@@ -1254,23 +1238,14 @@ static int SwapLists(WOLFSSL_CRL* crl)
{
int ret;
CRL_Entry* newList;
#ifdef WOLFSSL_SMALL_STACK
WOLFSSL_CRL* tmp;
#else
WOLFSSL_CRL tmp[1];
#endif
WC_DECLARE_VAR(tmp, WOLFSSL_CRL, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
tmp = (WOLFSSL_CRL*)XMALLOC(sizeof(WOLFSSL_CRL), NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (tmp == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(tmp, WOLFSSL_CRL, 1, NULL, DYNAMIC_TYPE_TMP_BUFFER,
return MEMORY_E);
if (InitCRL(tmp, crl->cm) < 0) {
WOLFSSL_MSG("Init tmp CRL failed");
#ifdef WOLFSSL_SMALL_STACK
XFREE(tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return WOLFSSL_FATAL_ERROR;
}
@@ -1279,9 +1254,7 @@ static int SwapLists(WOLFSSL_CRL* crl)
if (ret != WOLFSSL_SUCCESS) {
WOLFSSL_MSG("PEM LoadCRL on dir change failed");
FreeCRL(tmp, 0);
#ifdef WOLFSSL_SMALL_STACK
XFREE(tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return WOLFSSL_FATAL_ERROR;
}
}
@@ -1291,9 +1264,7 @@ static int SwapLists(WOLFSSL_CRL* crl)
if (ret != WOLFSSL_SUCCESS) {
WOLFSSL_MSG("DER LoadCRL on dir change failed");
FreeCRL(tmp, 0);
#ifdef WOLFSSL_SMALL_STACK
XFREE(tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return WOLFSSL_FATAL_ERROR;
}
}
@@ -1301,9 +1272,7 @@ static int SwapLists(WOLFSSL_CRL* crl)
if (wc_LockRwLock_Wr(&crl->crlLock) != 0) {
WOLFSSL_MSG("wc_LockRwLock_Wr failed");
FreeCRL(tmp, 0);
#ifdef WOLFSSL_SMALL_STACK
XFREE(tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return WOLFSSL_FATAL_ERROR;
}
@@ -1317,9 +1286,7 @@ static int SwapLists(WOLFSSL_CRL* crl)
FreeCRL(tmp, 0);
#ifdef WOLFSSL_SMALL_STACK
XFREE(tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return 0;
}
@@ -1505,11 +1472,7 @@ static THREAD_RETURN WOLFSSL_THREAD DoMonitor(void* arg)
int notifyFd;
int wd = -1;
WOLFSSL_CRL* crl = (WOLFSSL_CRL*)arg;
#ifdef WOLFSSL_SMALL_STACK
char* buff;
#else
char buff[8192];
#endif
WC_DECLARE_VAR(buff, char, 8192, 0);
WOLFSSL_ENTER("DoMonitor");
@@ -1614,9 +1577,7 @@ static THREAD_RETURN WOLFSSL_THREAD DoMonitor(void* arg)
}
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(buff, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(buff, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (wd > 0) {
if (inotify_rm_watch(notifyFd, wd) < 0)
@@ -1826,22 +1787,14 @@ int LoadCRL(WOLFSSL_CRL* crl, const char* path, int type, int monitor)
{
int ret = WOLFSSL_SUCCESS;
char* name = NULL;
#ifdef WOLFSSL_SMALL_STACK
ReadDirCtx* readCtx = NULL;
#else
ReadDirCtx readCtx[1];
#endif
WC_DECLARE_VAR(readCtx, ReadDirCtx, 1, 0);
WOLFSSL_ENTER("LoadCRL");
if (crl == NULL)
return BAD_FUNC_ARG;
#ifdef WOLFSSL_SMALL_STACK
readCtx = (ReadDirCtx*)XMALLOC(sizeof(ReadDirCtx), crl->heap,
DYNAMIC_TYPE_TMP_BUFFER);
if (readCtx == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(readCtx, ReadDirCtx, 1, crl->heap,
DYNAMIC_TYPE_TMP_BUFFER, return MEMORY_E);
/* try to load each regular file in path */
ret = wc_ReadDirFirst(readCtx, path, &name);
@@ -1873,9 +1826,7 @@ int LoadCRL(WOLFSSL_CRL* crl, const char* path, int type, int monitor)
if (ret != WOLFSSL_SUCCESS) {
WOLFSSL_MSG("CRL file load failed");
wc_ReadDirClose(readCtx);
#ifdef WOLFSSL_SMALL_STACK
XFREE(readCtx, crl->heap, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(readCtx, crl->heap, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
}
@@ -1888,9 +1839,7 @@ int LoadCRL(WOLFSSL_CRL* crl, const char* path, int type, int monitor)
/* load failures not reported, for backwards compat */
ret = WOLFSSL_SUCCESS;
#ifdef WOLFSSL_SMALL_STACK
XFREE(readCtx, crl->heap, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(readCtx, crl->heap, DYNAMIC_TYPE_TMP_BUFFER);
if (monitor & WOLFSSL_CRL_MONITOR) {
#ifdef HAVE_CRL_MONITOR
+58 -149
View File
@@ -12221,9 +12221,7 @@ static int BuildMD5(WOLFSSL* ssl, Hashes* hashes, const byte* sender)
}
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(md5, ssl->heap, DYNAMIC_TYPE_HASHCTX);
#endif
WC_FREE_VAR_EX(md5, ssl->heap, DYNAMIC_TYPE_HASHCTX);
return ret;
}
@@ -12267,9 +12265,7 @@ static int BuildSHA(WOLFSSL* ssl, Hashes* hashes, const byte* sender)
}
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(sha, ssl->heap, DYNAMIC_TYPE_HASHCTX);
#endif
WC_FREE_VAR_EX(sha, ssl->heap, DYNAMIC_TYPE_HASHCTX);
return ret;
}
@@ -14060,11 +14056,9 @@ static int ProcessCSR_ex(WOLFSSL* ssl, byte* input, word32* inOutIdx,
* single->isDynamic is set. */
FreeOcspResponse(response);
#ifdef WOLFSSL_SMALL_STACK
XFREE(status, ssl->heap, DYNAMIC_TYPE_OCSP_STATUS);
XFREE(single, ssl->heap, DYNAMIC_TYPE_OCSP_ENTRY);
XFREE(response, ssl->heap, DYNAMIC_TYPE_OCSP_REQUEST);
#endif
WC_FREE_VAR_EX(status, ssl->heap, DYNAMIC_TYPE_OCSP_STATUS);
WC_FREE_VAR_EX(single, ssl->heap, DYNAMIC_TYPE_OCSP_ENTRY);
WC_FREE_VAR_EX(response, ssl->heap, DYNAMIC_TYPE_OCSP_REQUEST);
WOLFSSL_LEAVE("ProcessCSR", ret);
return ret;
@@ -15906,25 +15900,18 @@ int ProcessPeerCerts(WOLFSSL* ssl, byte* input, word32* inOutIdx,
#endif
#if defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2)
if (ret == 0 && addToPendingCAs && !alreadySigner) {
#ifdef WOLFSSL_SMALL_STACK
DecodedCert *dCertAdd = NULL;
#else
DecodedCert dCertAdd[1];
#endif
WC_DECLARE_VAR(dCertAdd, DecodedCert, 1, 0);
int dCertAdd_inited = 0;
DerBuffer *derBuffer = NULL;
buffer* cert = &args->certs[args->certIdx];
Signer *s = NULL;
#ifdef WOLFSSL_SMALL_STACK
dCertAdd = (DecodedCert *)
XMALLOC(sizeof(*dCertAdd), ssl->heap,
DYNAMIC_TYPE_TMP_BUFFER);
if (dCertAdd == NULL) {
ret = MEMORY_E;
WC_ALLOC_VAR_EX(dCertAdd, DecodedCert, 1, ssl->heap,
DYNAMIC_TYPE_TMP_BUFFER,
{
ret=MEMORY_E;
goto exit_req_v2;
}
#endif
});
InitDecodedCert(dCertAdd, cert->buffer, cert->length,
ssl->heap);
dCertAdd_inited = 1;
@@ -15957,9 +15944,8 @@ int ProcessPeerCerts(WOLFSSL* ssl, byte* input, word32* inOutIdx,
FreeDer(&derBuffer);
if (dCertAdd_inited)
FreeDecodedCert(dCertAdd);
#ifdef WOLFSSL_SMALL_STACK
XFREE(dCertAdd, ssl->heap, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(dCertAdd, ssl->heap,
DYNAMIC_TYPE_TMP_BUFFER);
if (ret != 0)
goto exit_ppc;
}
@@ -17213,11 +17199,9 @@ static int DoCertificateStatus(WOLFSSL* ssl, byte* input, word32* inOutIdx,
ssl->status_request_v2 = 0;
#ifdef WOLFSSL_SMALL_STACK
XFREE(status, NULL, DYNAMIC_TYPE_OCSP_STATUS);
XFREE(single, NULL, DYNAMIC_TYPE_OCSP_ENTRY);
XFREE(response, NULL, DYNAMIC_TYPE_OCSP_REQUEST);
#endif
WC_FREE_VAR_EX(status, NULL, DYNAMIC_TYPE_OCSP_STATUS);
WC_FREE_VAR_EX(single, NULL, DYNAMIC_TYPE_OCSP_ENTRY);
WC_FREE_VAR_EX(response, NULL, DYNAMIC_TYPE_OCSP_REQUEST);
}
break;
@@ -23576,9 +23560,7 @@ static int BuildMD5_CertVerify(const WOLFSSL* ssl, byte* digest)
}
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(md5, ssl->heap, DYNAMIC_TYPE_HASHCTX);
#endif
WC_FREE_VAR_EX(md5, ssl->heap, DYNAMIC_TYPE_HASHCTX);
return ret;
}
@@ -23621,9 +23603,7 @@ static int BuildSHA_CertVerify(const WOLFSSL* ssl, byte* digest)
}
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(sha, ssl->heap, DYNAMIC_TYPE_HASHCTX);
#endif
WC_FREE_VAR_EX(sha, ssl->heap, DYNAMIC_TYPE_HASHCTX);
return ret;
}
@@ -24050,18 +24030,11 @@ int BuildMessage(WOLFSSL* ssl, byte* output, int outSz, const byte* input,
#ifdef HAVE_TRUNCATED_HMAC
if (ssl->truncated_hmac &&
ssl->specs.hash_size > args->digestSz) {
#ifdef WOLFSSL_SMALL_STACK
byte* hmac;
#else
byte hmac[WC_MAX_DIGEST_SIZE];
#endif
WC_DECLARE_VAR(hmac, byte, WC_MAX_DIGEST_SIZE, 0);
#ifdef WOLFSSL_SMALL_STACK
hmac = (byte*)XMALLOC(WC_MAX_DIGEST_SIZE, ssl->heap,
DYNAMIC_TYPE_DIGEST);
if (hmac == NULL)
ERROR_OUT(MEMORY_E, exit_buildmsg);
#endif
WC_ALLOC_VAR_EX(hmac, byte, WC_MAX_DIGEST_SIZE, ssl->heap,
DYNAMIC_TYPE_DIGEST,
ERROR_OUT(MEMORY_E,exit_buildmsg));
ret = ssl->hmac(ssl, hmac,
output + args->headerSz + args->ivSz,
@@ -24069,9 +24042,7 @@ int BuildMessage(WOLFSSL* ssl, byte* output, int outSz, const byte* input,
epochOrder);
XMEMCPY(output + args->idx, hmac, args->digestSz);
#ifdef WOLFSSL_SMALL_STACK
XFREE(hmac, ssl->heap, DYNAMIC_TYPE_DIGEST);
#endif
WC_FREE_VAR_EX(hmac, ssl->heap, DYNAMIC_TYPE_DIGEST);
}
else
#endif
@@ -24197,18 +24168,11 @@ int BuildMessage(WOLFSSL* ssl, byte* output, int outSz, const byte* input,
#ifdef HAVE_TRUNCATED_HMAC
if (ssl->truncated_hmac &&
ssl->specs.hash_size > args->digestSz) {
#ifdef WOLFSSL_SMALL_STACK
byte* hmac = NULL;
#else
byte hmac[WC_MAX_DIGEST_SIZE];
#endif
WC_DECLARE_VAR(hmac, byte, WC_MAX_DIGEST_SIZE, 0);
#ifdef WOLFSSL_SMALL_STACK
hmac = (byte*)XMALLOC(WC_MAX_DIGEST_SIZE, ssl->heap,
DYNAMIC_TYPE_DIGEST);
if (hmac == NULL)
ERROR_OUT(MEMORY_E, exit_buildmsg);
#endif
WC_ALLOC_VAR_EX(hmac, byte, WC_MAX_DIGEST_SIZE, ssl->heap,
DYNAMIC_TYPE_DIGEST,
ERROR_OUT(MEMORY_E,exit_buildmsg));
ret = ssl->hmac(ssl, hmac, output + args->headerSz,
args->ivSz + inSz + args->pad + 1, -1,
@@ -24216,9 +24180,7 @@ int BuildMessage(WOLFSSL* ssl, byte* output, int outSz, const byte* input,
XMEMCPY(output + args->idx + args->pad + 1, hmac,
args->digestSz);
#ifdef WOLFSSL_SMALL_STACK
XFREE(hmac, ssl->heap, DYNAMIC_TYPE_DIGEST);
#endif
WC_FREE_VAR_EX(hmac, ssl->heap, DYNAMIC_TYPE_DIGEST);
}
else
#endif
@@ -24522,22 +24484,14 @@ int CreateOcspResponse(WOLFSSL* ssl, OcspRequest** ocspRequest,
if (request == NULL || ssl->buffers.weOwnCert) {
DerBuffer* der = ssl->buffers.certificate;
#ifdef WOLFSSL_SMALL_STACK
DecodedCert* cert = NULL;
#else
DecodedCert cert[1];
#endif
WC_DECLARE_VAR(cert, DecodedCert, 1, 0);
/* unable to fetch status. skip. */
if (der->buffer == NULL || der->length == 0)
return 0;
#ifdef WOLFSSL_SMALL_STACK
cert = (DecodedCert*)XMALLOC(sizeof(DecodedCert), ssl->heap,
DYNAMIC_TYPE_DCERT);
if (cert == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(cert, DecodedCert, 1, ssl->heap, DYNAMIC_TYPE_DCERT,
return MEMORY_E);
request = (OcspRequest*)XMALLOC(sizeof(OcspRequest), ssl->heap,
DYNAMIC_TYPE_OCSP_REQUEST);
if (request == NULL)
@@ -24554,9 +24508,7 @@ int CreateOcspResponse(WOLFSSL* ssl, OcspRequest** ocspRequest,
request = NULL;
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, ssl->heap, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, ssl->heap, DYNAMIC_TYPE_DCERT);
}
if (ret == 0) {
@@ -25379,25 +25331,15 @@ int SendCertificateStatus(WOLFSSL* ssl)
|| ssl->buffers.weOwnCertChain)) {
buffer der;
word32 idx = 0;
#ifdef WOLFSSL_SMALL_STACK
DecodedCert* cert;
#else
DecodedCert cert[1];
#endif
WC_DECLARE_VAR(cert, DecodedCert, 1, 0);
DerBuffer* chain;
#ifdef WOLFSSL_SMALL_STACK
cert = (DecodedCert*)XMALLOC(sizeof(DecodedCert), ssl->heap,
DYNAMIC_TYPE_DCERT);
if (cert == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(cert, DecodedCert, 1, ssl->heap,
DYNAMIC_TYPE_DCERT, return MEMORY_E);
request = (OcspRequest*)XMALLOC(sizeof(OcspRequest), ssl->heap,
DYNAMIC_TYPE_OCSP_REQUEST);
if (request == NULL) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, ssl->heap, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, ssl->heap, DYNAMIC_TYPE_DCERT);
return MEMORY_E;
}
@@ -25440,9 +25382,7 @@ int SendCertificateStatus(WOLFSSL* ssl)
}
if (!ctxOwnsRequest)
XFREE(request, ssl->heap, DYNAMIC_TYPE_OCSP_REQUEST);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, ssl->heap, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, ssl->heap, DYNAMIC_TYPE_DCERT);
}
else {
while (ret == 0 &&
@@ -31905,9 +31845,7 @@ static int HashSkeData(WOLFSSL* ssl, enum wc_HashType hashType,
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, ssl->heap, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, ssl->heap, DYNAMIC_TYPE_DCERT);
if (ret != 0) {
if (name != NULL)
wolfSSL_X509_NAME_free(name);
@@ -33125,20 +33063,14 @@ static int DoServerKeyExchange(WOLFSSL* ssl, const byte* input,
}
#endif
if (IsAtLeastTLSv1_2(ssl)) {
#ifdef WOLFSSL_SMALL_STACK
byte* encodedSig;
#else
byte encodedSig[MAX_ENCODED_SIG_SZ];
#endif
WC_DECLARE_VAR(encodedSig, byte,
MAX_ENCODED_SIG_SZ, 0);
word32 encSigSz;
#ifdef WOLFSSL_SMALL_STACK
encodedSig = (byte*)XMALLOC(MAX_ENCODED_SIG_SZ,
ssl->heap, DYNAMIC_TYPE_SIGNATURE);
if (encodedSig == NULL) {
ERROR_OUT(MEMORY_E, exit_dske);
}
#endif
WC_ALLOC_VAR_EX(encodedSig, byte,
MAX_ENCODED_SIG_SZ, ssl->heap,
DYNAMIC_TYPE_SIGNATURE,
ERROR_OUT(MEMORY_E,exit_dske));
encSigSz = wc_EncodeSignature(encodedSig,
ssl->buffers.digest.buffer,
@@ -33149,9 +33081,8 @@ static int DoServerKeyExchange(WOLFSSL* ssl, const byte* input,
min(encSigSz, MAX_ENCODED_SIG_SZ)) != 0) {
ret = VERIFY_SIGN_ERROR;
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(encodedSig, ssl->heap, DYNAMIC_TYPE_SIGNATURE);
#endif
WC_FREE_VAR_EX(encodedSig, ssl->heap,
DYNAMIC_TYPE_SIGNATURE);
if (ret != 0) {
goto exit_dske;
}
@@ -38984,10 +38915,8 @@ static int DoSessionTicket(WOLFSSL* ssl, const byte* input, word32* inOutIdx,
ret = VERIFY_CERT_ERROR;
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(encodedSig, ssl->heap,
DYNAMIC_TYPE_SIGNATURE);
#endif
WC_FREE_VAR_EX(encodedSig, ssl->heap,
DYNAMIC_TYPE_SIGNATURE);
}
}
else {
@@ -40268,10 +40197,8 @@ static int TicketEncDec(byte* key, int keyLen, byte* iv, byte* aad, int aadSz,
}
wc_HmacFree(hmac);
#ifdef WOLFSSL_SMALL_STACK
XFREE(hmac, heap, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(aes, heap, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(hmac, heap, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(aes, heap, DYNAMIC_TYPE_TMP_BUFFER);
*outLen = inLen;
@@ -40343,19 +40270,12 @@ static int TicketEncDec(byte* key, int keyLen, byte* iv, byte* aad, int aadSz,
void* heap, int enc)
{
int ret;
#ifdef WOLFSSL_SMALL_STACK
Aes* aes;
#else
Aes aes[1];
#endif
WC_DECLARE_VAR(aes, Aes, 1, 0);
(void)heap;
#ifdef WOLFSSL_SMALL_STACK
aes = (Aes*)XMALLOC(sizeof(Aes), heap, DYNAMIC_TYPE_TMP_BUFFER);
if (aes == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(aes, Aes, 1, heap, DYNAMIC_TYPE_TMP_BUFFER,
return MEMORY_E);
if (enc) {
ret = wc_AesInit(aes, NULL, INVALID_DEVID);
@@ -40380,9 +40300,7 @@ static int TicketEncDec(byte* key, int keyLen, byte* iv, byte* aad, int aadSz,
wc_AesFree(aes);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(aes, heap, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(aes, heap, DYNAMIC_TYPE_TMP_BUFFER);
*outLen = inLen;
@@ -40412,19 +40330,12 @@ static int TicketEncDec(byte* key, int keyLen, byte* iv, byte* aad, int aadSz,
void* heap, int enc)
{
int ret;
#ifdef WOLFSSL_SMALL_STACK
wc_Sm4* sm4;
#else
wc_Sm4 sm4[1];
#endif
WC_DECLARE_VAR(sm4, wc_Sm4, 1, 0);
(void)heap;
#ifdef WOLFSSL_SMALL_STACK
sm4 = (wc_Sm4*)XMALLOC(sizeof(wc_Sm4), heap, DYNAMIC_TYPE_TMP_BUFFER);
if (sm4 == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(sm4, wc_Sm4, 1, heap, DYNAMIC_TYPE_TMP_BUFFER,
return MEMORY_E);
if (enc) {
ret = wc_Sm4Init(sm4, NULL, INVALID_DEVID);
@@ -40449,9 +40360,7 @@ static int TicketEncDec(byte* key, int keyLen, byte* iv, byte* aad, int aadSz,
wc_Sm4Free(sm4);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(sm4, heap, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(sm4, heap, DYNAMIC_TYPE_TMP_BUFFER);
*outLen = inLen;
+11 -15
View File
@@ -3934,14 +3934,12 @@ int DeriveKeys(WOLFSSL* ssl)
ret = StoreKeys(ssl, keyData, PROVISION_CLIENT_SERVER);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(shaOutput, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(md5Input, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(shaInput, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(keyData, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(md5, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(sha, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(shaOutput, NULL, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(md5Input, NULL, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(shaInput, NULL, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(keyData, NULL, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(md5, NULL, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(sha, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -4084,13 +4082,11 @@ static int MakeSslMasterSecret(WOLFSSL* ssl)
ret = DeriveKeys(ssl);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(shaOutput, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(md5Input, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(shaInput, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(md5, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(sha, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(shaOutput, NULL, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(md5Input, NULL, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(shaInput, NULL, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(md5, NULL, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(sha, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (ret == 0)
ret = CleanPreMaster(ssl);
+12 -36
View File
@@ -197,11 +197,7 @@ int CheckCertOCSP_ex(WOLFSSL_OCSP* ocsp, DecodedCert* cert, WOLFSSL* ssl)
{
int ret = WC_NO_ERR_TRACE(OCSP_LOOKUP_FAIL);
#ifdef WOLFSSL_SMALL_STACK
OcspRequest* ocspRequest;
#else
OcspRequest ocspRequest[1];
#endif
WC_DECLARE_VAR(ocspRequest, OcspRequest, 1, 0);
WOLFSSL_ENTER("CheckCertOCSP");
@@ -223,9 +219,7 @@ int CheckCertOCSP_ex(WOLFSSL_OCSP* ocsp, DecodedCert* cert, WOLFSSL* ssl)
FreeOcspRequest(ocspRequest);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(ocspRequest, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(ocspRequest, NULL, DYNAMIC_TYPE_TMP_BUFFER);
WOLFSSL_LEAVE("CheckCertOCSP", ret);
return ret;
@@ -475,11 +469,9 @@ end:
}
FreeOcspResponse(ocspResponse);
#ifdef WOLFSSL_SMALL_STACK
XFREE(newStatus, NULL, DYNAMIC_TYPE_OCSP_STATUS);
XFREE(newSingle, NULL, DYNAMIC_TYPE_OCSP_ENTRY);
XFREE(ocspResponse, NULL, DYNAMIC_TYPE_OCSP_REQUEST);
#endif
WC_FREE_VAR_EX(newStatus, NULL, DYNAMIC_TYPE_OCSP_STATUS);
WC_FREE_VAR_EX(newSingle, NULL, DYNAMIC_TYPE_OCSP_ENTRY);
WC_FREE_VAR_EX(ocspResponse, NULL, DYNAMIC_TYPE_OCSP_REQUEST);
return ret;
}
@@ -780,11 +772,7 @@ WOLFSSL_OCSP_CERTID* wolfSSL_OCSP_cert_to_id(
int ret = -1;
DerBuffer* derCert = NULL;
int dgstType;
#ifdef WOLFSSL_SMALL_STACK
DecodedCert *cert = NULL;
#else
DecodedCert cert[1];
#endif
WC_DECLARE_VAR(cert, DecodedCert, 1, 0);
if (dgst == NULL) {
dgstType = WC_HASH_TYPE_SHA;
@@ -803,11 +791,8 @@ WOLFSSL_OCSP_CERTID* wolfSSL_OCSP_cert_to_id(
|| issuer == NULL || issuer->derCert == NULL)
goto out;
#ifdef WOLFSSL_SMALL_STACK
cert = (DecodedCert *)XMALLOC(sizeof(*cert), cm->heap, DYNAMIC_TYPE_DCERT);
if (cert == NULL)
goto out;
#endif
WC_ALLOC_VAR_EX(cert, DecodedCert, 1, cm->heap, DYNAMIC_TYPE_DCERT,
goto out);
ret = AllocDer(&derCert, issuer->derCert->length,
issuer->derCert->type, NULL);
@@ -1027,21 +1012,14 @@ static int OcspFindSigner(WOLFSSL_OCSP_BASICRESP *resp,
static int OcspVerifySigner(WOLFSSL_OCSP_BASICRESP *resp, DecodedCert *cert,
WOLFSSL_X509_STORE *st, unsigned long flags)
{
#ifdef WOLFSSL_SMALL_STACK
DecodedCert *c = NULL;
#else
DecodedCert c[1];
#endif
WC_DECLARE_VAR(c, DecodedCert, 1, 0);
int ret = -1;
if (st == NULL)
return ASN_OCSP_CONFIRM_E;
#ifdef WOLFSSL_SMALL_STACK
c = (DecodedCert *)XMALLOC(sizeof(*c), NULL, DYNAMIC_TYPE_DCERT);
if (c == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(c, DecodedCert, 1, NULL, DYNAMIC_TYPE_DCERT,
return MEMORY_E);
InitDecodedCert(c, cert->source, cert->maxIdx, NULL);
if (ParseCertRelative(c, CERT_TYPE, VERIFY, st->cm, NULL) != 0) {
@@ -1063,9 +1041,7 @@ static int OcspVerifySigner(WOLFSSL_OCSP_BASICRESP *resp, DecodedCert *cert,
err:
FreeDecodedCert(c);
#ifdef WOLFSSL_SMALL_STACK
XFREE(c, NULL, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(c, NULL, DYNAMIC_TYPE_DCERT);
return ret;
}
/* Signature verified in DecodeBasicOcspResponse.
+59 -217
View File
@@ -85,11 +85,7 @@
static int pem_mem_to_der(const char* pem, int pemSz, wc_pem_password_cb* cb,
void* pass, int keyType, int* keyFormat, DerBuffer** der)
{
#ifdef WOLFSSL_SMALL_STACK
EncryptedInfo* info = NULL;
#else
EncryptedInfo info[1];
#endif /* WOLFSSL_SMALL_STACK */
WC_DECLARE_VAR(info, EncryptedInfo, 1, 0);
wc_pem_password_cb* localCb = NULL;
int ret = 0;
@@ -125,9 +121,7 @@ static int pem_mem_to_der(const char* pem, int pemSz, wc_pem_password_cb* cb,
ret = (int)info->consumed;
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(info, NULL, DYNAMIC_TYPE_ENCRYPTEDINFO);
#endif
WC_FREE_VAR_EX(info, NULL, DYNAMIC_TYPE_ENCRYPTEDINFO);
return ret;
}
@@ -372,11 +366,7 @@ int EncryptDerKey(byte *der, int *derSz, const WOLFSSL_EVP_CIPHER* cipher,
int paddingSz = 0;
word32 idx;
word32 cipherInfoSz = 0;
#ifdef WOLFSSL_SMALL_STACK
EncryptedInfo* info = NULL;
#else
EncryptedInfo info[1];
#endif
WC_DECLARE_VAR(info, EncryptedInfo, 1, 0);
WOLFSSL_ENTER("EncryptDerKey");
@@ -471,10 +461,7 @@ int EncryptDerKey(byte *der, int *derSz, const WOLFSSL_EVP_CIPHER* cipher,
}
}
#ifdef WOLFSSL_SMALL_STACK
/* Free dynamically allocated info. */
XFREE(info, NULL, DYNAMIC_TYPE_ENCRYPTEDINFO);
#endif
WC_FREE_VAR_EX(info, NULL, DYNAMIC_TYPE_ENCRYPTEDINFO);
return ret == 0;
}
#endif /* WOLFSSL_KEY_GEN || WOLFSSL_PEM_TO_DER */
@@ -3390,10 +3377,7 @@ static int wolfssl_rsa_generate_key_native(WOLFSSL_RSA* rsa, int bits,
if (initTmpRng) {
wc_FreeRng(tmpRng);
}
#ifdef WOLFSSL_SMALL_STACK
/* Dispose of any allocated RNG. */
XFREE(tmpRng, NULL, DYNAMIC_TYPE_RNG);
#endif
WC_FREE_VAR_EX(tmpRng, NULL, DYNAMIC_TYPE_RNG);
return ret;
#else
@@ -3705,10 +3689,7 @@ int wolfSSL_RSA_padding_add_PKCS1_PSS_mgf1(WOLFSSL_RSA *rsa, unsigned char *em,
if (initTmpRng) {
wc_FreeRng(tmpRng);
}
#ifdef WOLFSSL_SMALL_STACK
/* Dispose of any allocated RNG. */
XFREE(tmpRng, NULL, DYNAMIC_TYPE_RNG);
#endif
WC_FREE_VAR_EX(tmpRng, NULL, DYNAMIC_TYPE_RNG);
return ret;
}
@@ -4155,11 +4136,8 @@ int wolfSSL_RSA_sign_mgf(int hashAlg, const unsigned char* hash,
if (initTmpRng) {
wc_FreeRng(tmpRng);
}
#ifdef WOLFSSL_SMALL_STACK
/* Dispose of any allocated RNG and encoded signature. */
XFREE(tmpRng, NULL, DYNAMIC_TYPE_RNG);
XFREE(encodedSig, NULL, DYNAMIC_TYPE_SIGNATURE);
#endif
WC_FREE_VAR_EX(tmpRng, NULL, DYNAMIC_TYPE_RNG);
WC_FREE_VAR_EX(encodedSig, NULL, DYNAMIC_TYPE_SIGNATURE);
WOLFSSL_LEAVE("wolfSSL_RSA_sign_mgf", ret);
return ret;
@@ -4334,9 +4312,7 @@ int wolfSSL_RSA_verify_mgf(int hashAlg, const unsigned char* hash,
}
/* Dispose of any allocated data. */
#ifdef WOLFSSL_SMALL_STACK
XFREE(encodedSig, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(encodedSig, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(sigDec, NULL, DYNAMIC_TYPE_TMP_BUFFER);
WOLFSSL_LEAVE("wolfSSL_RSA_verify_mgf", ret);
@@ -4455,10 +4431,7 @@ int wolfSSL_RSA_public_encrypt(int len, const unsigned char* from,
if (initTmpRng) {
wc_FreeRng(tmpRng);
}
#ifdef WOLFSSL_SMALL_STACK
/* Dispose of any allocated RNG. */
XFREE(tmpRng, NULL, DYNAMIC_TYPE_RNG);
#endif
WC_FREE_VAR_EX(tmpRng, NULL, DYNAMIC_TYPE_RNG);
/* wolfCrypt error means return -1. */
if (ret <= 0) {
@@ -4732,10 +4705,7 @@ int wolfSSL_RSA_private_encrypt(int len, const unsigned char* from,
if (initTmpRng) {
wc_FreeRng(tmpRng);
}
#ifdef WOLFSSL_SMALL_STACK
/* Dispose of any allocated RNG. */
XFREE(tmpRng, NULL, DYNAMIC_TYPE_RNG);
#endif
WC_FREE_VAR_EX(tmpRng, NULL, DYNAMIC_TYPE_RNG);
/* wolfCrypt error means return -1. */
if (ret <= 0) {
@@ -4762,11 +4732,7 @@ int wolfSSL_RSA_GenAdd(WOLFSSL_RSA* rsa)
int ret = 1;
int err;
mp_int* t = NULL;
#ifdef WOLFSSL_SMALL_STACK
mp_int *tmp = NULL;
#else
mp_int tmp[1];
#endif
WC_DECLARE_VAR(tmp, mp_int, 1, 0);
WOLFSSL_ENTER("wolfSSL_RsaGenAdd");
@@ -5131,17 +5097,10 @@ int wolfSSL_DSA_generate_key(WOLFSSL_DSA* dsa)
{
int initTmpRng = 0;
WC_RNG *rng = NULL;
#ifdef WOLFSSL_SMALL_STACK
WC_RNG *tmpRng;
#else
WC_RNG tmpRng[1];
#endif
WC_DECLARE_VAR(tmpRng, WC_RNG, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
tmpRng = (WC_RNG*)XMALLOC(sizeof(WC_RNG), NULL, DYNAMIC_TYPE_RNG);
if (tmpRng == NULL)
return WOLFSSL_FATAL_ERROR;
#endif
WC_ALLOC_VAR_EX(tmpRng, WC_RNG, 1, NULL, DYNAMIC_TYPE_RNG,
return WOLFSSL_FATAL_ERROR);
if (wc_InitRng(tmpRng) == 0) {
rng = tmpRng;
initTmpRng = 1;
@@ -5169,9 +5128,7 @@ int wolfSSL_DSA_generate_key(WOLFSSL_DSA* dsa)
if (initTmpRng)
wc_FreeRng(tmpRng);
#ifdef WOLFSSL_SMALL_STACK
XFREE(tmpRng, NULL, DYNAMIC_TYPE_RNG);
#endif
WC_FREE_VAR_EX(tmpRng, NULL, DYNAMIC_TYPE_RNG);
}
#else /* WOLFSSL_KEY_GEN */
WOLFSSL_MSG("No Key Gen built in");
@@ -5235,17 +5192,10 @@ int wolfSSL_DSA_generate_parameters_ex(WOLFSSL_DSA* dsa, int bits,
{
int initTmpRng = 0;
WC_RNG *rng = NULL;
#ifdef WOLFSSL_SMALL_STACK
WC_RNG *tmpRng;
#else
WC_RNG tmpRng[1];
#endif
WC_DECLARE_VAR(tmpRng, WC_RNG, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
tmpRng = (WC_RNG*)XMALLOC(sizeof(WC_RNG), NULL, DYNAMIC_TYPE_RNG);
if (tmpRng == NULL)
return WOLFSSL_FATAL_ERROR;
#endif
WC_ALLOC_VAR_EX(tmpRng, WC_RNG, 1, NULL, DYNAMIC_TYPE_RNG,
return WOLFSSL_FATAL_ERROR);
if (wc_InitRng(tmpRng) == 0) {
rng = tmpRng;
initTmpRng = 1;
@@ -5268,9 +5218,7 @@ int wolfSSL_DSA_generate_parameters_ex(WOLFSSL_DSA* dsa, int bits,
if (initTmpRng)
wc_FreeRng(tmpRng);
#ifdef WOLFSSL_SMALL_STACK
XFREE(tmpRng, NULL, DYNAMIC_TYPE_RNG);
#endif
WC_FREE_VAR_EX(tmpRng, NULL, DYNAMIC_TYPE_RNG);
}
#else /* WOLFSSL_KEY_GEN */
WOLFSSL_MSG("No Key Gen built in");
@@ -5562,11 +5510,7 @@ static int dsa_do_sign(const unsigned char* d, int dLen, unsigned char* sigRet,
int ret = WC_NO_ERR_TRACE(WOLFSSL_FATAL_ERROR);
int initTmpRng = 0;
WC_RNG* rng = NULL;
#ifdef WOLFSSL_SMALL_STACK
WC_RNG* tmpRng = NULL;
#else
WC_RNG tmpRng[1];
#endif
WC_DECLARE_VAR(tmpRng, WC_RNG, 1, 0);
if (d == NULL || sigRet == NULL || dsa == NULL) {
WOLFSSL_MSG("Bad function arguments");
@@ -5581,11 +5525,8 @@ static int dsa_do_sign(const unsigned char* d, int dLen, unsigned char* sigRet,
}
}
#ifdef WOLFSSL_SMALL_STACK
tmpRng = (WC_RNG*)XMALLOC(sizeof(WC_RNG), NULL, DYNAMIC_TYPE_RNG);
if (tmpRng == NULL)
return WOLFSSL_FATAL_ERROR;
#endif
WC_ALLOC_VAR_EX(tmpRng, WC_RNG, 1, NULL, DYNAMIC_TYPE_RNG,
return WOLFSSL_FATAL_ERROR);
if (wc_InitRng(tmpRng) == 0) {
rng = tmpRng;
@@ -5621,9 +5562,7 @@ static int dsa_do_sign(const unsigned char* d, int dLen, unsigned char* sigRet,
if (initTmpRng)
wc_FreeRng(tmpRng);
#ifdef WOLFSSL_SMALL_STACK
XFREE(tmpRng, NULL, DYNAMIC_TYPE_RNG);
#endif
WC_FREE_VAR_EX(tmpRng, NULL, DYNAMIC_TYPE_RNG);
return ret;
}
@@ -8469,11 +8408,7 @@ int wolfSSL_DH_set0_key(WOLFSSL_DH *dh, WOLFSSL_BIGNUM *pub_key,
static int wolfssl_dh_check_prime(WOLFSSL_BIGNUM* n, int* isPrime)
{
int ret = 1;
#ifdef WOLFSSL_SMALL_STACK
WC_RNG* tmpRng = NULL;
#else
WC_RNG tmpRng[1];
#endif
WC_DECLARE_VAR(tmpRng, WC_RNG, 1, 0);
WC_RNG* rng;
int localRng;
@@ -8491,9 +8426,7 @@ static int wolfssl_dh_check_prime(WOLFSSL_BIGNUM* n, int* isPrime)
/* Free local random number generator if created. */
if (localRng) {
wc_FreeRng(rng);
#ifdef WOLFSSL_SMALL_STACK
XFREE(rng, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(rng, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
}
@@ -8621,11 +8554,7 @@ int wolfSSL_DH_generate_parameters_ex(WOLFSSL_DH* dh, int prime_len,
{
int ret = 1;
DhKey* key = NULL;
#ifdef WOLFSSL_SMALL_STACK
WC_RNG* tmpRng = NULL;
#else
WC_RNG tmpRng[1];
#endif
WC_DECLARE_VAR(tmpRng, WC_RNG, 1, 0);
WC_RNG* rng = NULL;
int localRng = 0;
@@ -8671,9 +8600,7 @@ int wolfSSL_DH_generate_parameters_ex(WOLFSSL_DH* dh, int prime_len,
/* Free local random number generator if created. */
if (localRng) {
wc_FreeRng(rng);
#ifdef WOLFSSL_SMALL_STACK
XFREE(rng, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(rng, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
if (ret == 1) {
@@ -8714,11 +8641,7 @@ int wolfSSL_DH_generate_key(WOLFSSL_DH* dh)
word32 privSz = 0;
int localRng = 0;
WC_RNG* rng = NULL;
#ifdef WOLFSSL_SMALL_STACK
WC_RNG* tmpRng = NULL;
#else
WC_RNG tmpRng[1];
#endif
WC_DECLARE_VAR(tmpRng, WC_RNG, 1, 0);
unsigned char* pub = NULL;
unsigned char* priv = NULL;
@@ -8815,9 +8738,7 @@ int wolfSSL_DH_generate_key(WOLFSSL_DH* dh)
if (localRng) {
/* Free an initialized local random number generator. */
wc_FreeRng(rng);
#ifdef WOLFSSL_SMALL_STACK
XFREE(rng, NULL, DYNAMIC_TYPE_RNG);
#endif
WC_FREE_VAR_EX(rng, NULL, DYNAMIC_TYPE_RNG);
}
/* Dispose of allocated data. */
XFREE(pub, NULL, DYNAMIC_TYPE_PUBLIC_KEY);
@@ -8966,10 +8887,8 @@ static int _DH_compute_key(unsigned char* key, const WOLFSSL_BIGNUM* otherPub,
ForceZero(priv, (word32)privSz);
}
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(pub, NULL, DYNAMIC_TYPE_PUBLIC_KEY);
XFREE(priv, NULL, DYNAMIC_TYPE_PRIVATE_KEY);
#endif
WC_FREE_VAR_EX(pub, NULL, DYNAMIC_TYPE_PUBLIC_KEY);
WC_FREE_VAR_EX(priv, NULL, DYNAMIC_TYPE_PRIVATE_KEY);
WOLFSSL_LEAVE("wolfSSL_DH_compute_key", ret);
@@ -9781,11 +9700,7 @@ int wolfSSL_EC_GROUP_get_degree(const WOLFSSL_EC_GROUP *group)
int wolfSSL_EC_GROUP_order_bits(const WOLFSSL_EC_GROUP *group)
{
int ret = 0;
#ifdef WOLFSSL_SMALL_STACK
mp_int *order = NULL;
#else
mp_int order[1];
#endif
WC_DECLARE_VAR(order, mp_int, 1, 0);
/* Validate parameter. */
if ((group == NULL) || (group->curve_idx < 0)) {
@@ -9821,10 +9736,7 @@ int wolfSSL_EC_GROUP_order_bits(const WOLFSSL_EC_GROUP *group)
mp_clear(order);
}
#ifdef WOLFSSL_SMALL_STACK
/* Deallocate order. */
XFREE(order, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(order, NULL, DYNAMIC_TYPE_TMP_BUFFER);
/* Convert error code to length of 0. */
if (ret < 0) {
@@ -10792,19 +10704,10 @@ int ec_point_convert_to_affine(const WOLFSSL_EC_GROUP *group,
{
int err = 0;
mp_digit mp = 0;
#ifdef WOLFSSL_SMALL_STACK
mp_int* modulus;
#else
mp_int modulus[1];
#endif
WC_DECLARE_VAR(modulus, mp_int, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
/* Allocate memory for curve's prime modulus. */
modulus = (mp_int*)XMALLOC(sizeof(mp_int), NULL, DYNAMIC_TYPE_BIGINT);
if (modulus == NULL) {
err = 1;
}
#endif
WC_ALLOC_VAR_EX(modulus, mp_int, 1, NULL, DYNAMIC_TYPE_BIGINT, err=1);
/* Initialize the MP integer. */
if ((!err) && (mp_init(modulus) != MP_OKAY)) {
WOLFSSL_MSG("mp_init failed");
@@ -10841,9 +10744,7 @@ int ec_point_convert_to_affine(const WOLFSSL_EC_GROUP *group,
mp_clear(modulus);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(modulus, NULL, DYNAMIC_TYPE_BIGINT);
#endif
WC_FREE_VAR_EX(modulus, NULL, DYNAMIC_TYPE_BIGINT);
return err;
}
@@ -11145,11 +11046,9 @@ static int wolfssl_ec_point_add(int curveIdx, ecc_point* r, ecc_point* p1,
mp_clear(mu);
wc_ecc_del_point_h(montP1, NULL);
wc_ecc_del_point_h(montP2, NULL);
#ifdef WOLFSSL_SMALL_STACK
XFREE(a, NULL, DYNAMIC_TYPE_BIGINT);
XFREE(prime, NULL, DYNAMIC_TYPE_BIGINT);
XFREE(mu, NULL, DYNAMIC_TYPE_BIGINT);
#endif
WC_FREE_VAR_EX(a, NULL, DYNAMIC_TYPE_BIGINT);
WC_FREE_VAR_EX(prime, NULL, DYNAMIC_TYPE_BIGINT);
WC_FREE_VAR_EX(mu, NULL, DYNAMIC_TYPE_BIGINT);
return ret;
}
@@ -11405,10 +11304,8 @@ static int wolfssl_ec_point_mul(int curveIdx, ecc_point* r, mp_int* n,
mp_clear(a);
mp_clear(prime);
#ifdef WOLFSSL_SMALL_STACK
XFREE(a, NULL, DYNAMIC_TYPE_BIGINT);
XFREE(prime, NULL, DYNAMIC_TYPE_BIGINT);
#endif
WC_FREE_VAR_EX(a, NULL, DYNAMIC_TYPE_BIGINT);
WC_FREE_VAR_EX(prime, NULL, DYNAMIC_TYPE_BIGINT);
return ret;
}
@@ -11512,19 +11409,10 @@ int wolfSSL_EC_POINT_mul(const WOLFSSL_EC_GROUP *group, WOLFSSL_EC_POINT *r,
static int wolfssl_ec_point_invert(int curveIdx, ecc_point* point)
{
int ret = 1;
#ifdef WOLFSSL_SMALL_STACK
mp_int* prime = NULL;
#else
mp_int prime[1];
#endif
WC_DECLARE_VAR(prime, mp_int, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
/* Allocate memory for an MP int to hold the prime of the curve. */
prime = (mp_int*)XMALLOC(sizeof(mp_int), NULL, DYNAMIC_TYPE_BIGINT);
if (prime == NULL) {
ret = 0;
}
#endif
WC_ALLOC_VAR_EX(prime, mp_int, 1, NULL, DYNAMIC_TYPE_BIGINT, ret=0);
/* Initialize MP int. */
if ((ret == 1) && (mp_init(prime) != MP_OKAY)) {
@@ -11548,10 +11436,7 @@ static int wolfssl_ec_point_invert(int curveIdx, ecc_point* point)
/* Dispose of memory associated with MP. */
mp_free(prime);
#ifdef WOLFSSL_SMALL_STACK
/* Dispose of dynamically allocated temporaries. */
XFREE(prime, NULL, DYNAMIC_TYPE_BIGINT);
#endif
WC_FREE_VAR_EX(prime, NULL, DYNAMIC_TYPE_BIGINT);
return ret;
}
@@ -13697,11 +13582,7 @@ int wolfSSL_EC_KEY_generate_key(WOLFSSL_EC_KEY *key)
int res = 1;
int initTmpRng = 0;
WC_RNG* rng = NULL;
#ifdef WOLFSSL_SMALL_STACK
WC_RNG* tmpRng = NULL;
#else
WC_RNG tmpRng[1];
#endif
WC_DECLARE_VAR(tmpRng, WC_RNG, 1, 0);
WOLFSSL_ENTER("wolfSSL_EC_KEY_generate_key");
@@ -13769,9 +13650,7 @@ int wolfSSL_EC_KEY_generate_key(WOLFSSL_EC_KEY *key)
/* Dispose of local random number generator if initialized. */
if (initTmpRng) {
wc_FreeRng(rng);
#ifdef WOLFSSL_SMALL_STACK
XFREE(rng, NULL, DYNAMIC_TYPE_RNG);
#endif
WC_FREE_VAR_EX(rng, NULL, DYNAMIC_TYPE_RNG);
}
/* Set the external key from new internal key values. */
@@ -14174,11 +14053,7 @@ WOLFSSL_ECDSA_SIG *wolfSSL_ECDSA_do_sign(const unsigned char *dgst, int dLen,
{
int err = 0;
WOLFSSL_ECDSA_SIG *sig = NULL;
#ifdef WOLFSSL_SMALL_STACK
byte* out = NULL;
#else
byte out[ECC_BUFSIZE];
#endif
WC_DECLARE_VAR(out, byte, ECC_BUFSIZE, 0);
unsigned int outLen = ECC_BUFSIZE;
WOLFSSL_ENTER("wolfSSL_ECDSA_do_sign");
@@ -14220,10 +14095,7 @@ WOLFSSL_ECDSA_SIG *wolfSSL_ECDSA_do_sign(const unsigned char *dgst, int dLen,
sig = wolfSSL_d2i_ECDSA_SIG(NULL, &p, outLen);
}
#ifdef WOLFSSL_SMALL_STACK
/* Dispose of any temporary dynamically allocated data. */
XFREE(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(out, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return sig;
}
@@ -14321,11 +14193,7 @@ int wolfSSL_ECDSA_sign(int type, const unsigned char *digest, int digestSz,
{
int ret = 1;
WC_RNG* rng = NULL;
#ifdef WOLFSSL_SMALL_STACK
WC_RNG* tmpRng = NULL;
#else
WC_RNG tmpRng[1];
#endif
WC_DECLARE_VAR(tmpRng, WC_RNG, 1, 0);
int initTmpRng = 0;
WOLFSSL_ENTER("wolfSSL_ECDSA_sign");
@@ -14355,9 +14223,7 @@ int wolfSSL_ECDSA_sign(int type, const unsigned char *digest, int digestSz,
if (initTmpRng) {
wc_FreeRng(rng);
#ifdef WOLFSSL_SMALL_STACK
XFREE(rng, NULL, DYNAMIC_TYPE_RNG);
#endif
WC_FREE_VAR_EX(rng, NULL, DYNAMIC_TYPE_RNG);
}
return ret;
@@ -14611,11 +14477,7 @@ int wolfSSL_EC25519_generate_key(unsigned char *priv, unsigned int *privSz,
int res = 1;
int initTmpRng = 0;
WC_RNG *rng = NULL;
#ifdef WOLFSSL_SMALL_STACK
WC_RNG *tmpRng = NULL;
#else
WC_RNG tmpRng[1];
#endif
WC_DECLARE_VAR(tmpRng, WC_RNG, 1, 0);
curve25519_key key;
WOLFSSL_ENTER("wolfSSL_EC25519_generate_key");
@@ -14664,9 +14526,7 @@ int wolfSSL_EC25519_generate_key(unsigned char *priv, unsigned int *privSz,
if (initTmpRng) {
wc_FreeRng(rng);
#ifdef WOLFSSL_SMALL_STACK
XFREE(rng, NULL, DYNAMIC_TYPE_RNG);
#endif
WC_FREE_VAR_EX(rng, NULL, DYNAMIC_TYPE_RNG);
}
return res;
@@ -14812,11 +14672,7 @@ int wolfSSL_ED25519_generate_key(unsigned char *priv, unsigned int *privSz,
int res = 1;
int initTmpRng = 0;
WC_RNG *rng = NULL;
#ifdef WOLFSSL_SMALL_STACK
WC_RNG *tmpRng = NULL;
#else
WC_RNG tmpRng[1];
#endif
WC_DECLARE_VAR(tmpRng, WC_RNG, 1, 0);
ed25519_key key;
WOLFSSL_ENTER("wolfSSL_ED25519_generate_key");
@@ -14864,9 +14720,7 @@ int wolfSSL_ED25519_generate_key(unsigned char *priv, unsigned int *privSz,
if (initTmpRng) {
wc_FreeRng(rng);
#ifdef WOLFSSL_SMALL_STACK
XFREE(rng, NULL, DYNAMIC_TYPE_RNG);
#endif
WC_FREE_VAR_EX(rng, NULL, DYNAMIC_TYPE_RNG);
}
return res;
@@ -15084,11 +14938,7 @@ int wolfSSL_EC448_generate_key(unsigned char *priv, unsigned int *privSz,
int res = 1;
int initTmpRng = 0;
WC_RNG *rng = NULL;
#ifdef WOLFSSL_SMALL_STACK
WC_RNG *tmpRng = NULL;
#else
WC_RNG tmpRng[1];
#endif
WC_DECLARE_VAR(tmpRng, WC_RNG, 1, 0);
curve448_key key;
WOLFSSL_ENTER("wolfSSL_EC448_generate_key");
@@ -15137,9 +14987,7 @@ int wolfSSL_EC448_generate_key(unsigned char *priv, unsigned int *privSz,
if (initTmpRng) {
wc_FreeRng(rng);
#ifdef WOLFSSL_SMALL_STACK
XFREE(rng, NULL, DYNAMIC_TYPE_RNG);
#endif
WC_FREE_VAR_EX(rng, NULL, DYNAMIC_TYPE_RNG);
}
return res;
@@ -15278,11 +15126,7 @@ int wolfSSL_ED448_generate_key(unsigned char *priv, unsigned int *privSz,
int res = 1;
int initTmpRng = 0;
WC_RNG *rng = NULL;
#ifdef WOLFSSL_SMALL_STACK
WC_RNG *tmpRng = NULL;
#else
WC_RNG tmpRng[1];
#endif
WC_DECLARE_VAR(tmpRng, WC_RNG, 1, 0);
ed448_key key;
WOLFSSL_ENTER("wolfSSL_ED448_generate_key");
@@ -15330,9 +15174,7 @@ int wolfSSL_ED448_generate_key(unsigned char *priv, unsigned int *privSz,
if (initTmpRng) {
wc_FreeRng(rng);
#ifdef WOLFSSL_SMALL_STACK
XFREE(rng, NULL, DYNAMIC_TYPE_RNG);
#endif
WC_FREE_VAR_EX(rng, NULL, DYNAMIC_TYPE_RNG);
}
return res;
+1 -3
View File
@@ -1119,9 +1119,7 @@ size_t wolfSSL_quic_get_aead_tag_len(const WOLFSSL_EVP_CIPHER* aead_cipher)
}
(void)wolfSSL_EVP_CIPHER_CTX_cleanup(ctx);
#ifdef WOLFSSL_SMALL_STACK
XFREE(ctx, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(ctx, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
+55 -169
View File
@@ -381,16 +381,11 @@ int wolfSSL_CTX_GenerateEchConfig(WOLFSSL_CTX* ctx, const char* publicName,
if (ctx == NULL || publicName == NULL)
return BAD_FUNC_ARG;
#ifdef WOLFSSL_SMALL_STACK
rng = (WC_RNG*)XMALLOC(sizeof(WC_RNG), ctx->heap, DYNAMIC_TYPE_RNG);
if (rng == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(rng, WC_RNG, 1, ctx->heap, DYNAMIC_TYPE_RNG,
return MEMORY_E);
ret = wc_InitRng(rng);
if (ret != 0) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(rng, ctx->heap, DYNAMIC_TYPE_RNG);
#endif
WC_FREE_VAR_EX(rng, ctx->heap, DYNAMIC_TYPE_RNG);
return ret;
}
@@ -494,10 +489,8 @@ int wolfSSL_CTX_GenerateEchConfig(WOLFSSL_CTX* ctx, const char* publicName,
if (ret == 0)
ret = WOLFSSL_SUCCESS;
#ifdef WOLFSSL_SMALL_STACK
XFREE(hpke, ctx->heap, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(rng, ctx->heap, DYNAMIC_TYPE_RNG);
#endif
WC_FREE_VAR_EX(hpke, ctx->heap, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(rng, ctx->heap, DYNAMIC_TYPE_RNG);
return ret;
}
@@ -5888,11 +5881,7 @@ int AddCA(WOLFSSL_CERT_MANAGER* cm, DerBuffer** pDer, int type, int verify)
Signer* signer = NULL;
word32 row;
byte* subjectHash;
#ifdef WOLFSSL_SMALL_STACK
DecodedCert* cert = NULL;
#else
DecodedCert cert[1];
#endif
WC_DECLARE_VAR(cert, DecodedCert, 1, 0);
DerBuffer* der = *pDer;
WOLFSSL_MSG_CERT_LOG("Adding a CA");
@@ -5902,14 +5891,13 @@ int AddCA(WOLFSSL_CERT_MANAGER* cm, DerBuffer** pDer, int type, int verify)
return BAD_FUNC_ARG;
}
#ifdef WOLFSSL_SMALL_STACK
cert = (DecodedCert*)XMALLOC(sizeof(DecodedCert), NULL,
DYNAMIC_TYPE_DCERT);
#ifdef WOLFSSL_SMALL_STACK
cert = (DecodedCert*)XMALLOC(sizeof(DecodedCert), NULL, DYNAMIC_TYPE_DCERT);
if (cert == NULL) {
FreeDer(pDer);
return MEMORY_E;
}
#endif
#endif
InitDecodedCert(cert, der->buffer, der->length, cm->heap);
@@ -5924,12 +5912,6 @@ int AddCA(WOLFSSL_CERT_MANAGER* cm, DerBuffer** pDer, int type, int verify)
WOLFSSL_MSG("\tParsed new CA");
#ifdef WOLFSSL_DEBUG_CERTS
#ifdef WOLFSSL_SMALL_STACK
if (cert == NULL) {
WOLFSSL_MSG_CERT(WOLFSSL_MSG_CERT_INDENT "Failed; cert is NULL");
}
else
#endif
{
const char* err_msg;
if (ret == 0) {
@@ -6148,9 +6130,7 @@ int AddCA(WOLFSSL_CERT_MANAGER* cm, DerBuffer** pDer, int type, int verify)
FreeDecodedCert(cert);
if (ret != 0 && signer != NULL)
FreeSigner(signer, cm->heap);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, NULL, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, NULL, DYNAMIC_TYPE_DCERT);
WOLFSSL_MSG("\tFreeing der CA");
FreeDer(pDer);
WOLFSSL_MSG("\t\tOK Freeing der CA");
@@ -7297,11 +7277,7 @@ static int check_cert_key(DerBuffer* cert, DerBuffer* key, DerBuffer* altKey,
void* heap, int devId, int isKeyLabel, int isKeyId, int altDevId,
int isAltKeyLabel, int isAltKeyId)
{
#ifdef WOLFSSL_SMALL_STACK
DecodedCert* der = NULL;
#else
DecodedCert der[1];
#endif
WC_DECLARE_VAR(der, DecodedCert, 1, 0);
word32 size;
byte* buff;
int ret = WC_NO_ERR_TRACE(WOLFSSL_FAILURE);
@@ -7312,20 +7288,15 @@ static int check_cert_key(DerBuffer* cert, DerBuffer* key, DerBuffer* altKey,
return WOLFSSL_FAILURE;
}
#ifdef WOLFSSL_SMALL_STACK
der = (DecodedCert*)XMALLOC(sizeof(DecodedCert), heap, DYNAMIC_TYPE_DCERT);
if (der == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(der, DecodedCert, 1, heap, DYNAMIC_TYPE_DCERT,
return MEMORY_E);
size = cert->length;
buff = cert->buffer;
InitDecodedCert_ex(der, buff, size, heap, devId);
if (ParseCertRelative(der, CERT_TYPE, NO_VERIFY, NULL, NULL) != 0) {
FreeDecodedCert(der);
#ifdef WOLFSSL_SMALL_STACK
XFREE(der, heap, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(der, heap, DYNAMIC_TYPE_DCERT);
return WOLFSSL_FAILURE;
}
@@ -7418,9 +7389,7 @@ static int check_cert_key(DerBuffer* cert, DerBuffer* key, DerBuffer* altKey,
}
#endif /* WOLFSSL_DUAL_ALG_CERTS */
FreeDecodedCert(der);
#ifdef WOLFSSL_SMALL_STACK
XFREE(der, heap, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(der, heap, DYNAMIC_TYPE_DCERT);
(void)devId;
(void)isKeyLabel;
@@ -7581,9 +7550,7 @@ static int d2iTryRsaKey(WOLFSSL_EVP_PKEY** out, const unsigned char* mem,
XMEMSET(rsa, 0, sizeof(RsaKey));
if (wc_InitRsaKey(rsa, NULL) != 0) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(rsa, NULL, DYNAMIC_TYPE_RSA);
#endif
WC_FREE_VAR_EX(rsa, NULL, DYNAMIC_TYPE_RSA);
return 0;
}
/* test if RSA key */
@@ -7596,9 +7563,7 @@ static int d2iTryRsaKey(WOLFSSL_EVP_PKEY** out, const unsigned char* mem,
(wc_RsaPublicKeyDecode(mem, &keyIdx, rsa, (word32)memSz) == 0);
}
wc_FreeRsaKey(rsa);
#ifdef WOLFSSL_SMALL_STACK
XFREE(rsa, NULL, DYNAMIC_TYPE_RSA);
#endif
WC_FREE_VAR_EX(rsa, NULL, DYNAMIC_TYPE_RSA);
if (!isRsaKey) {
return WOLFSSL_FATAL_ERROR;
@@ -7665,9 +7630,7 @@ static int d2iTryEccKey(WOLFSSL_EVP_PKEY** out, const unsigned char* mem,
XMEMSET(ecc, 0, sizeof(ecc_key));
if (wc_ecc_init(ecc) != 0) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(ecc, NULL, DYNAMIC_TYPE_ECC);
#endif
WC_FREE_VAR_EX(ecc, NULL, DYNAMIC_TYPE_ECC);
return 0;
}
@@ -7680,9 +7643,7 @@ static int d2iTryEccKey(WOLFSSL_EVP_PKEY** out, const unsigned char* mem,
(wc_EccPublicKeyDecode(mem, &keyIdx, ecc, (word32)memSz) == 0);
}
wc_ecc_free(ecc);
#ifdef WOLFSSL_SMALL_STACK
XFREE(ecc, NULL, DYNAMIC_TYPE_ECC);
#endif
WC_FREE_VAR_EX(ecc, NULL, DYNAMIC_TYPE_ECC);
if (!isEccKey) {
return WOLFSSL_FATAL_ERROR;
@@ -7752,9 +7713,7 @@ static int d2iTryDsaKey(WOLFSSL_EVP_PKEY** out, const unsigned char* mem,
XMEMSET(dsa, 0, sizeof(DsaKey));
if (wc_InitDsaKey(dsa) != 0) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(dsa, NULL, DYNAMIC_TYPE_DSA);
#endif
WC_FREE_VAR_EX(dsa, NULL, DYNAMIC_TYPE_DSA);
return 0;
}
@@ -7767,9 +7726,7 @@ static int d2iTryDsaKey(WOLFSSL_EVP_PKEY** out, const unsigned char* mem,
(wc_DsaPublicKeyDecode(mem, &keyIdx, dsa, (word32)memSz) == 0);
}
wc_FreeDsaKey(dsa);
#ifdef WOLFSSL_SMALL_STACK
XFREE(dsa, NULL, DYNAMIC_TYPE_DSA);
#endif
WC_FREE_VAR_EX(dsa, NULL, DYNAMIC_TYPE_DSA);
/* test if DSA key */
if (!isDsaKey) {
@@ -7843,17 +7800,13 @@ static int d2iTryDhKey(WOLFSSL_EVP_PKEY** out, const unsigned char* mem,
XMEMSET(dh, 0, sizeof(DhKey));
if (wc_InitDhKey(dh) != 0) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(dh, NULL, DYNAMIC_TYPE_DH);
#endif
WC_FREE_VAR_EX(dh, NULL, DYNAMIC_TYPE_DH);
return 0;
}
isDhKey = (wc_DhKeyDecode(mem, &keyIdx, dh, (word32)memSz) == 0);
wc_FreeDhKey(dh);
#ifdef WOLFSSL_SMALL_STACK
XFREE(dh, NULL, DYNAMIC_TYPE_DH);
#endif
WC_FREE_VAR_EX(dh, NULL, DYNAMIC_TYPE_DH);
/* test if DH key */
if (!isDhKey) {
@@ -7928,17 +7881,13 @@ static int d2iTryAltDhKey(WOLFSSL_EVP_PKEY** out, const unsigned char* mem,
/* test if DH-public key */
if (wc_InitDhKey(dh) != 0) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(dh, NULL, DYNAMIC_TYPE_DH);
#endif
WC_FREE_VAR_EX(dh, NULL, DYNAMIC_TYPE_DH);
return 0;
}
ret = wc_DhKeyDecode(mem, &keyIdx, dh, (word32)memSz);
wc_FreeDhKey(dh);
#ifdef WOLFSSL_SMALL_STACK
XFREE(dh, NULL, DYNAMIC_TYPE_DH);
#endif
WC_FREE_VAR_EX(dh, NULL, DYNAMIC_TYPE_DH);
if (ret != 0) {
return WOLFSSL_FATAL_ERROR;
@@ -8019,9 +7968,7 @@ static int d2iTryFalconKey(WOLFSSL_EVP_PKEY** out, const unsigned char* mem,
#endif
if (wc_falcon_init(falcon) != 0) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(falcon, NULL, DYNAMIC_TYPE_FALCON);
#endif
WC_FREE_VAR_EX(falcon, NULL, DYNAMIC_TYPE_FALCON);
return 0;
}
@@ -8051,9 +7998,7 @@ static int d2iTryFalconKey(WOLFSSL_EVP_PKEY** out, const unsigned char* mem,
}
}
wc_falcon_free(falcon);
#ifdef WOLFSSL_SMALL_STACK
XFREE(falcon, NULL, DYNAMIC_TYPE_FALCON);
#endif
WC_FREE_VAR_EX(falcon, NULL, DYNAMIC_TYPE_FALCON);
if (!isFalcon) {
return WOLFSSL_FATAL_ERROR;
@@ -8098,9 +8043,7 @@ static int d2iTryDilithiumKey(WOLFSSL_EVP_PKEY** out, const unsigned char* mem,
#endif
if (wc_dilithium_init(dilithium) != 0) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(dilithium, NULL, DYNAMIC_TYPE_DILITHIUM);
#endif
WC_FREE_VAR_EX(dilithium, NULL, DYNAMIC_TYPE_DILITHIUM);
return 0;
}
@@ -8136,9 +8079,7 @@ static int d2iTryDilithiumKey(WOLFSSL_EVP_PKEY** out, const unsigned char* mem,
}
}
wc_dilithium_free(dilithium);
#ifdef WOLFSSL_SMALL_STACK
XFREE(dilithium, NULL, DYNAMIC_TYPE_DILITHIUM);
#endif
WC_FREE_VAR_EX(dilithium, NULL, DYNAMIC_TYPE_DILITHIUM);
if (!isDilithium) {
return WOLFSSL_FATAL_ERROR;
@@ -9546,11 +9487,7 @@ static int wolfSSL_parse_cipher_list(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
int ret = 0;
int listattribute = 0;
int tls13Only = 0;
#ifndef WOLFSSL_SMALL_STACK
byte suitesCpy[WOLFSSL_MAX_SUITE_SZ];
#else
byte* suitesCpy = NULL;
#endif
WC_DECLARE_VAR(suitesCpy, byte, WOLFSSL_MAX_SUITE_SZ, 0);
word16 suitesCpySz = 0;
word16 i = 0;
word16 j = 0;
@@ -9608,9 +9545,7 @@ static int wolfSSL_parse_cipher_list(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
ret = SetCipherList_ex(ctx, ssl, suites, list);
if (ret != 1) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(suitesCpy, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(suitesCpy, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return WOLFSSL_FAILURE;
}
@@ -9656,9 +9591,7 @@ static int wolfSSL_parse_cipher_list(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
}
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(suitesCpy, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(suitesCpy, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -12970,11 +12903,7 @@ cleanup:
if (ssl->options.side == WOLFSSL_CLIENT_END) {
#ifdef HAVE_ECC
#ifdef WOLFSSL_SMALL_STACK
ecc_key* key = NULL;
#else
ecc_key key[1];
#endif
WC_DECLARE_VAR(key, ecc_key, 1, 0);
word32 idx = 0;
#ifdef WOLFSSL_SMALL_STACK
@@ -12995,9 +12924,7 @@ cleanup:
wc_ecc_free(key);
}
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(key, ssl->heap, DYNAMIC_TYPE_ECC);
#endif
WC_FREE_VAR_EX(key, ssl->heap, DYNAMIC_TYPE_ECC);
#endif
#ifndef NO_DH
@@ -14658,20 +14585,12 @@ size_t wolfSSL_get_client_random(const WOLFSSL* ssl, unsigned char* out,
static int DecodeToX509(WOLFSSL_X509* x509, const byte* in, int len)
{
int ret;
#ifdef WOLFSSL_SMALL_STACK
DecodedCert* cert;
#else
DecodedCert cert[1];
#endif
WC_DECLARE_VAR(cert, DecodedCert, 1, 0);
if (x509 == NULL || in == NULL || len <= 0)
return BAD_FUNC_ARG;
#ifdef WOLFSSL_SMALL_STACK
cert = (DecodedCert*)XMALLOC(sizeof(DecodedCert), NULL,
DYNAMIC_TYPE_DCERT);
if (cert == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(cert, DecodedCert, 1, NULL, DYNAMIC_TYPE_DCERT,
return MEMORY_E);
/* Create a DecodedCert object and copy fields into WOLFSSL_X509 object.
*/
@@ -14683,9 +14602,7 @@ size_t wolfSSL_get_client_random(const WOLFSSL* ssl, unsigned char* out,
ret = CopyDecodedToX509(x509, cert);
}
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, NULL, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, NULL, DYNAMIC_TYPE_DCERT);
return ret;
}
@@ -19556,11 +19473,7 @@ WOLFSSL_X509* wolfSSL_get_chain_X509(WOLFSSL_X509_CHAIN* chain, int idx)
{
int ret = 0;
WOLFSSL_X509* x509 = NULL;
#ifdef WOLFSSL_SMALL_STACK
DecodedCert* cert = NULL;
#else
DecodedCert cert[1];
#endif
WC_DECLARE_VAR(cert, DecodedCert, 1, 0);
WOLFSSL_ENTER("wolfSSL_get_chain_X509");
if (chain != NULL && idx < MAX_CHAIN_DEPTH) {
@@ -19594,9 +19507,7 @@ WOLFSSL_X509* wolfSSL_get_chain_X509(WOLFSSL_X509_CHAIN* chain, int idx)
}
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, NULL, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, NULL, DYNAMIC_TYPE_DCERT);
}
}
(void)ret;
@@ -22792,11 +22703,7 @@ static int wolfSSL_TicketKeyCb(WOLFSSL* ssl,
int encTicketLen, int* encLen, void* ctx)
{
byte digest[WC_MAX_DIGEST_SIZE];
#ifdef WOLFSSL_SMALL_STACK
WOLFSSL_EVP_CIPHER_CTX *evpCtx;
#else
WOLFSSL_EVP_CIPHER_CTX evpCtx[1];
#endif
WC_DECLARE_VAR(evpCtx, WOLFSSL_EVP_CIPHER_CTX, 1, 0);
WOLFSSL_HMAC_CTX hmacCtx;
unsigned int mdSz = 0;
int len = 0;
@@ -22826,9 +22733,7 @@ static int wolfSSL_TicketKeyCb(WOLFSSL* ssl,
wolfSSL_EVP_CIPHER_CTX_init(evpCtx);
if (wolfSSL_HMAC_CTX_Init(&hmacCtx) != WOLFSSL_SUCCESS) {
WOLFSSL_MSG("wolfSSL_HMAC_CTX_Init error");
#ifdef WOLFSSL_SMALL_STACK
XFREE(evpCtx, ssl->heap, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(evpCtx, ssl->heap, DYNAMIC_TYPE_TMP_BUFFER);
return WOLFSSL_TICKET_RET_FATAL;
}
res = ssl->ctx->ticketEncWrapCb(ssl, keyName,
@@ -22902,9 +22807,7 @@ end:
(void)wc_HmacFree(&hmacCtx.hmac);
(void)wolfSSL_EVP_CIPHER_CTX_cleanup(evpCtx);
#ifdef WOLFSSL_SMALL_STACK
XFREE(evpCtx, ssl->heap, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(evpCtx, ssl->heap, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -23571,14 +23474,12 @@ int set_curves_list(WOLFSSL* ssl, WOLFSSL_CTX *ctx, const char* names,
#endif
const WOLF_EC_NIST_NAME* nist_name;
#ifdef WOLFSSL_SMALL_STACK
groups = (int*)XMALLOC(sizeof(int)*WOLFSSL_MAX_GROUP_COUNT,
heap, DYNAMIC_TYPE_TMP_BUFFER);
if (groups == NULL) {
ret = MEMORY_E;
WC_ALLOC_VAR_EX(groups, int, WOLFSSL_MAX_GROUP_COUNT, heap,
DYNAMIC_TYPE_TMP_BUFFER,
{
ret=MEMORY_E;
goto leave;
}
#endif
});
for (idx = 1; names[idx-1] != '\0'; idx++) {
if (names[idx] != ':' && names[idx] != '\0')
@@ -25978,9 +25879,7 @@ int wolfSSL_RAND_write_file(const char* fname)
if (initGlobalRNG == 0 && wolfSSL_RAND_Init() != WOLFSSL_SUCCESS) {
WOLFSSL_MSG("No RNG to use");
#ifdef WOLFSSL_SMALL_STACK
XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return 0;
}
@@ -26055,18 +25954,14 @@ int wolfSSL_RAND_egd(const char* nm)
XMEMSET(&rem, 0, sizeof(struct sockaddr_un));
if (nm == NULL) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return WOLFSSL_FATAL_ERROR;
}
fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (fd < 0) {
WOLFSSL_MSG("Error creating socket");
#ifdef WOLFSSL_SMALL_STACK
XFREE(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(buf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return WOLFSSL_FATAL_ERROR;
}
rem.sun_family = AF_UNIX;
@@ -26268,11 +26163,7 @@ int wolfSSL_RAND_bytes(unsigned char* buf, int num)
{
int ret = 0;
WC_RNG* rng = NULL;
#ifdef WOLFSSL_SMALL_STACK
WC_RNG* tmpRNG = NULL;
#else
WC_RNG tmpRNG[1];
#endif
WC_DECLARE_VAR(tmpRNG, WC_RNG, 1, 0);
int initTmpRng = 0;
#ifdef HAVE_GLOBAL_RNG
int used_global = 0;
@@ -26337,11 +26228,8 @@ int wolfSSL_RAND_bytes(unsigned char* buf, int num)
if (used_global == 0)
#endif
{
#ifdef WOLFSSL_SMALL_STACK
tmpRNG = (WC_RNG*)XMALLOC(sizeof(WC_RNG), NULL, DYNAMIC_TYPE_RNG);
if (tmpRNG == NULL)
return ret;
#endif
WC_ALLOC_VAR_EX(tmpRNG, WC_RNG, 1, NULL, DYNAMIC_TYPE_RNG,
return ret);
if (wc_InitRng(tmpRNG) == 0) {
rng = tmpRNG;
initTmpRng = 1;
@@ -26376,9 +26264,7 @@ int wolfSSL_RAND_bytes(unsigned char* buf, int num)
#endif
if (initTmpRng)
wc_FreeRng(tmpRNG);
#ifdef WOLFSSL_SMALL_STACK
XFREE(tmpRNG, NULL, DYNAMIC_TYPE_RNG);
#endif
WC_FREE_VAR_EX(tmpRNG, NULL, DYNAMIC_TYPE_RNG);
return ret;
}
+7 -31
View File
@@ -903,11 +903,7 @@ int wolfSSL_BN_set_bit(WOLFSSL_BIGNUM* bn, int n)
int wolfSSL_BN_clear_bit(WOLFSSL_BIGNUM* bn, int n)
{
int ret = 1;
#ifndef WOLFSSL_SMALL_STACK
mp_int tmp[1];
#else
mp_int* tmp = NULL;
#endif
WC_DECLARE_VAR(tmp, mp_int, 1, 0);
/* Validate parameters. */
if (BN_IS_NULL(bn) || (n < 0)) {
@@ -916,13 +912,8 @@ int wolfSSL_BN_clear_bit(WOLFSSL_BIGNUM* bn, int n)
}
/* Check if bit is set to clear. */
if ((ret == 1) && (mp_is_bit_set((mp_int*)bn->internal, n))) {
#ifdef WOLFSSL_SMALL_STACK
/* Allocate a new MP integer to hold bit to clear. */
tmp = (mp_int*)XMALLOC(sizeof(mp_int), NULL, DYNAMIC_TYPE_BIGINT);
if (tmp == NULL) {
ret = 0;
}
#endif
WC_ALLOC_VAR_EX(tmp, mp_int, 1, NULL, DYNAMIC_TYPE_BIGINT, ret=0);
if (ret == 1) {
/* Reset new MP integer. */
XMEMSET(tmp, 0, sizeof(mp_int));
@@ -942,10 +933,7 @@ int wolfSSL_BN_clear_bit(WOLFSSL_BIGNUM* bn, int n)
/* Free any dynamic memory in MP integer. */
mp_clear(tmp);
#ifdef WOLFSSL_SMALL_STACK
/* Dispose of temporary MP integer. */
XFREE(tmp, NULL, DYNAMIC_TYPE_BIGINT);
#endif
WC_FREE_VAR_EX(tmp, NULL, DYNAMIC_TYPE_BIGINT);
}
return ret;
@@ -2255,11 +2243,7 @@ int wolfSSL_BN_generate_prime_ex(WOLFSSL_BIGNUM* prime, int bits,
WOLFSSL_BN_GENCB* cb)
{
int ret = 1;
#ifdef WOLFSSL_SMALL_STACK
WC_RNG* tmpRng = NULL;
#else
WC_RNG tmpRng[1];
#endif
WC_DECLARE_VAR(tmpRng, WC_RNG, 1, 0);
WC_RNG* rng = NULL;
int localRng = 0;
@@ -2291,9 +2275,7 @@ int wolfSSL_BN_generate_prime_ex(WOLFSSL_BIGNUM* prime, int bits,
if (localRng) {
/* Dispose of local RNG that was created. */
wc_FreeRng(rng);
#ifdef WOLFSSL_SMALL_STACK
XFREE(rng, NULL, DYNAMIC_TYPE_RNG);
#endif
WC_FREE_VAR_EX(rng, NULL, DYNAMIC_TYPE_RNG);
}
WOLFSSL_LEAVE("wolfSSL_BN_generate_prime_ex", ret);
@@ -2318,11 +2300,7 @@ int wolfSSL_BN_is_prime_ex(const WOLFSSL_BIGNUM *bn, int checks,
{
int ret = 1;
WC_RNG* rng = NULL;
#ifdef WOLFSSL_SMALL_STACK
WC_RNG* tmpRng = NULL;
#else
WC_RNG tmpRng[1];
#endif
WC_DECLARE_VAR(tmpRng, WC_RNG, 1, 0);
int localRng = 0;
int res = MP_NO;
@@ -2350,9 +2328,7 @@ int wolfSSL_BN_is_prime_ex(const WOLFSSL_BIGNUM *bn, int checks,
if (localRng) {
wc_FreeRng(rng);
#ifdef WOLFSSL_SMALL_STACK
XFREE(rng, NULL, DYNAMIC_TYPE_RNG);
#endif
WC_FREE_VAR_EX(rng, NULL, DYNAMIC_TYPE_RNG);
}
if ((ret != -1) && (res != MP_YES)) {
+20 -57
View File
@@ -738,26 +738,19 @@ int CM_VerifyBuffer_ex(WOLFSSL_CERT_MANAGER* cm, const unsigned char* buff,
int ret = 0;
int fatal = 0;
DerBuffer* der = NULL;
#ifdef WOLFSSL_SMALL_STACK
DecodedCert* cert = NULL;
#else
DecodedCert cert[1];
#endif
WC_DECLARE_VAR(cert, DecodedCert, 1, 0);
WOLFSSL_ENTER("CM_VerifyBuffer_ex");
(void)prev_err;
#ifdef WOLFSSL_SMALL_STACK
/* Allocate memory for decoded certificate. */
cert = (DecodedCert*)XMALLOC(sizeof(DecodedCert), cm->heap,
DYNAMIC_TYPE_DCERT);
if (cert == NULL) {
ret = MEMORY_E;
fatal = 1;
}
if (ret == 0)
#endif
WC_ALLOC_VAR_EX(cert, DecodedCert, 1, cm->heap, DYNAMIC_TYPE_DCERT,
{
ret=MEMORY_E;
fatal=1;
});
if (WC_VAR_OK(cert))
{
/* Reset fields of decoded certificate. */
XMEMSET(cert, 0, sizeof(DecodedCert));
@@ -806,11 +799,7 @@ int CM_VerifyBuffer_ex(WOLFSSL_CERT_MANAGER* cm, const unsigned char* buff,
#ifndef NO_WOLFSSL_CM_VERIFY
/* Use callback to perform verification too if available. */
if ((!fatal) && cm->verifyCallback) {
#ifdef WOLFSSL_SMALL_STACK
ProcPeerCertArgs* args;
#else
ProcPeerCertArgs args[1];
#endif
WC_DECLARE_VAR(args, ProcPeerCertArgs, 1, 0);
buffer certBuf;
#ifdef WOLFSSL_SMALL_STACK
@@ -843,19 +832,14 @@ int CM_VerifyBuffer_ex(WOLFSSL_CERT_MANAGER* cm, const unsigned char* buff,
/* Use callback to verify certificate. */
ret = DoVerifyCallback(cm, NULL, ret, args);
}
#ifdef WOLFSSL_SMALL_STACK
/* Dispose of allocated callback args. */
XFREE(args, cm->heap, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(args, cm->heap, DYNAMIC_TYPE_TMP_BUFFER);
}
#endif
/* Dispose of allocated memory. */
FreeDecodedCert(cert);
FreeDer(&der);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, cm->heap, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, cm->heap, DYNAMIC_TYPE_DCERT);
/* Convert the ret value to a return value. */
return (ret == 0) ? WOLFSSL_SUCCESS : ret;
@@ -1880,11 +1864,7 @@ int wolfSSL_CertManagerCheckCRL(WOLFSSL_CERT_MANAGER* cm,
const unsigned char* der, int sz)
{
int ret = 0;
#ifdef WOLFSSL_SMALL_STACK
DecodedCert* cert = NULL;
#else
DecodedCert cert[1];
#endif
WC_DECLARE_VAR(cert, DecodedCert, 1, 0);
WOLFSSL_ENTER("wolfSSL_CertManagerCheckCRL");
@@ -1895,14 +1875,10 @@ int wolfSSL_CertManagerCheckCRL(WOLFSSL_CERT_MANAGER* cm,
/* Check if CRL checking enabled. */
if ((ret == 0) && cm->crlEnabled) {
#ifdef WOLFSSL_SMALL_STACK
/* Allocate memory for decoded certificate. */
cert = (DecodedCert*)XMALLOC(sizeof(DecodedCert), NULL,
DYNAMIC_TYPE_DCERT);
if (cert == NULL)
ret = MEMORY_E;
if (ret == 0)
#endif
WC_ALLOC_VAR_EX(cert, DecodedCert, 1, NULL, DYNAMIC_TYPE_DCERT,
ret=MEMORY_E);
if (WC_VAR_OK(cert))
{
/* Initialize decoded certificate with buffer. */
InitDecodedCert(cert, der, (word32)sz, NULL);
@@ -1919,9 +1895,7 @@ int wolfSSL_CertManagerCheckCRL(WOLFSSL_CERT_MANAGER* cm,
/* Dispose of dynamically allocated memory. */
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, NULL, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, NULL, DYNAMIC_TYPE_DCERT);
}
}
@@ -2406,11 +2380,7 @@ int wolfSSL_CertManagerCheckOCSP(WOLFSSL_CERT_MANAGER* cm,
const unsigned char* der, int sz)
{
int ret = 0;
#ifdef WOLFSSL_SMALL_STACK
DecodedCert* cert = NULL;
#else
DecodedCert cert[1];
#endif
WC_DECLARE_VAR(cert, DecodedCert, 1, 0);
WOLFSSL_ENTER("wolfSSL_CertManagerCheckOCSP");
@@ -2421,15 +2391,10 @@ int wolfSSL_CertManagerCheckOCSP(WOLFSSL_CERT_MANAGER* cm,
/* Check if OCSP checking enabled. */
if ((ret == 0) && cm->ocspEnabled) {
#ifdef WOLFSSL_SMALL_STACK
/* Allocate memory for decoded certificate. */
cert = (DecodedCert*)XMALLOC(sizeof(DecodedCert), cm->heap,
DYNAMIC_TYPE_DCERT);
if (cert == NULL) {
ret = MEMORY_E;
}
if (ret == 0)
#endif
WC_ALLOC_VAR_EX(cert, DecodedCert, 1, cm->heap, DYNAMIC_TYPE_DCERT,
ret=MEMORY_E);
if (WC_VAR_OK(cert))
{
/* Initialize decoded certificate with buffer. */
InitDecodedCert(cert, der, (word32)sz, NULL);
@@ -2446,9 +2411,7 @@ int wolfSSL_CertManagerCheckOCSP(WOLFSSL_CERT_MANAGER* cm,
/* Dispose of dynamically allocated memory. */
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, cm->heap, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, cm->heap, DYNAMIC_TYPE_DCERT);
}
}
+28 -108
View File
@@ -1048,11 +1048,7 @@ unsigned char* wolfSSL_SHA1(const unsigned char* data, size_t len,
{
/* Buffer to use when hash is NULL. */
static byte dgst[WC_SHA_DIGEST_SIZE];
#ifdef WOLFSSL_SMALL_STACK
wc_Sha* sha;
#else
wc_Sha sha[1];
#endif
WC_DECLARE_VAR(sha, wc_Sha, 1, 0);
int ret = 0;
WOLFSSL_ENTER("wolfSSL_SHA1");
@@ -1064,13 +1060,9 @@ unsigned char* wolfSSL_SHA1(const unsigned char* data, size_t len,
hash = dgst;
}
#ifdef WOLFSSL_SMALL_STACK
/* Allocate dynamic memory for a wolfSSL SHA object. */
sha = (wc_Sha*)XMALLOC(sizeof(wc_Sha), NULL, DYNAMIC_TYPE_DIGEST);
if (sha == NULL) {
ret = MEMORY_E;
}
#endif
WC_ALLOC_VAR_EX(sha, wc_Sha, 1, NULL, DYNAMIC_TYPE_DIGEST,
ret=MEMORY_E);
if (ret == 0) {
/* Initialize wolfCrypt SHA object. */
@@ -1100,10 +1092,7 @@ unsigned char* wolfSSL_SHA1(const unsigned char* data, size_t len,
wc_ShaFree(sha);
}
#ifdef WOLFSSL_SMALL_STACK
/* Free dynamic memory of a wolfSSL SHA object. */
XFREE(sha, NULL, DYNAMIC_TYPE_DIGEST);
#endif
WC_FREE_VAR_EX(sha, NULL, DYNAMIC_TYPE_DIGEST);
return hash;
}
#endif /* ! NO_SHA */
@@ -1126,11 +1115,7 @@ unsigned char* wolfSSL_SHA224(const unsigned char* data, size_t len,
{
/* Buffer to use when hash is NULL. */
static byte dgst[WC_SHA224_DIGEST_SIZE];
#ifdef WOLFSSL_SMALL_STACK
wc_Sha224* sha224;
#else
wc_Sha224 sha224[1];
#endif
WC_DECLARE_VAR(sha224, wc_Sha224, 1, 0);
int ret = 0;
WOLFSSL_ENTER("wolfSSL_SHA224");
@@ -1142,13 +1127,9 @@ unsigned char* wolfSSL_SHA224(const unsigned char* data, size_t len,
hash = dgst;
}
#ifdef WOLFSSL_SMALL_STACK
/* Allocate dynamic memory for a wolfSSL SHA-224 object. */
sha224 = (wc_Sha224*)XMALLOC(sizeof(wc_Sha224), NULL, DYNAMIC_TYPE_DIGEST);
if (sha224 == NULL) {
ret = MEMORY_E;
}
#endif
WC_ALLOC_VAR_EX(sha224, wc_Sha224, 1, NULL, DYNAMIC_TYPE_DIGEST,
ret=MEMORY_E);
if (ret == 0) {
/* Initialize wolfCrypt SHA224 object. */
@@ -1178,10 +1159,7 @@ unsigned char* wolfSSL_SHA224(const unsigned char* data, size_t len,
wc_Sha224Free(sha224);
}
#ifdef WOLFSSL_SMALL_STACK
/* Free dynamic memory of a wolfSSL SHA-224 object. */
XFREE(sha224, NULL, DYNAMIC_TYPE_DIGEST);
#endif
WC_FREE_VAR_EX(sha224, NULL, DYNAMIC_TYPE_DIGEST);
return hash;
}
#endif
@@ -1204,11 +1182,7 @@ unsigned char* wolfSSL_SHA256(const unsigned char* data, size_t len,
{
/* Buffer to use when hash is NULL. */
static byte dgst[WC_SHA256_DIGEST_SIZE];
#ifdef WOLFSSL_SMALL_STACK
wc_Sha256* sha256;
#else
wc_Sha256 sha256[1];
#endif
WC_DECLARE_VAR(sha256, wc_Sha256, 1, 0);
int ret = 0;
WOLFSSL_ENTER("wolfSSL_SHA256");
@@ -1220,13 +1194,9 @@ unsigned char* wolfSSL_SHA256(const unsigned char* data, size_t len,
hash = dgst;
}
#ifdef WOLFSSL_SMALL_STACK
/* Allocate dynamic memory for a wolfSSL SHA-256 object. */
sha256 = (wc_Sha256*)XMALLOC(sizeof(wc_Sha256), NULL, DYNAMIC_TYPE_DIGEST);
if (sha256 == NULL) {
ret = MEMORY_E;
}
#endif
WC_ALLOC_VAR_EX(sha256, wc_Sha256, 1, NULL, DYNAMIC_TYPE_DIGEST,
ret=MEMORY_E);
if (ret == 0) {
/* Initialize wolfCrypt SHA256 object. */
@@ -1256,10 +1226,7 @@ unsigned char* wolfSSL_SHA256(const unsigned char* data, size_t len,
wc_Sha256Free(sha256);
}
#ifdef WOLFSSL_SMALL_STACK
/* Free dynamic memory of a wolfSSL SHA object. */
XFREE(sha256, NULL, DYNAMIC_TYPE_DIGEST);
#endif
WC_FREE_VAR_EX(sha256, NULL, DYNAMIC_TYPE_DIGEST);
return hash;
}
#endif /* ! NO_SHA256 */
@@ -1282,11 +1249,7 @@ unsigned char* wolfSSL_SHA384(const unsigned char* data, size_t len,
{
/* Buffer to use when hash is NULL. */
static byte dgst[WC_SHA384_DIGEST_SIZE];
#ifdef WOLFSSL_SMALL_STACK
wc_Sha384* sha384;
#else
wc_Sha384 sha384[1];
#endif
WC_DECLARE_VAR(sha384, wc_Sha384, 1, 0);
int ret = 0;
WOLFSSL_ENTER("wolfSSL_SHA384");
@@ -1298,13 +1261,9 @@ unsigned char* wolfSSL_SHA384(const unsigned char* data, size_t len,
hash = dgst;
}
#ifdef WOLFSSL_SMALL_STACK
/* Allocate dynamic memory for a wolfSSL SHA-384 object. */
sha384 = (wc_Sha384*)XMALLOC(sizeof(wc_Sha384), NULL, DYNAMIC_TYPE_DIGEST);
if (sha384 == NULL) {
ret = MEMORY_E;
}
#endif
WC_ALLOC_VAR_EX(sha384, wc_Sha384, 1, NULL, DYNAMIC_TYPE_DIGEST,
ret=MEMORY_E);
if (ret == 0) {
/* Initialize wolfCrypt SHA384 object. */
@@ -1334,10 +1293,7 @@ unsigned char* wolfSSL_SHA384(const unsigned char* data, size_t len,
wc_Sha384Free(sha384);
}
#ifdef WOLFSSL_SMALL_STACK
/* Free dynamic memory of a wolfSSL SHA-384 object. */
XFREE(sha384, NULL, DYNAMIC_TYPE_DIGEST);
#endif
WC_FREE_VAR_EX(sha384, NULL, DYNAMIC_TYPE_DIGEST);
return hash;
}
#endif /* WOLFSSL_SHA384 */
@@ -1360,11 +1316,7 @@ unsigned char* wolfSSL_SHA512(const unsigned char* data, size_t len,
{
/* Buffer to use when hash is NULL. */
static byte dgst[WC_SHA512_DIGEST_SIZE];
#ifdef WOLFSSL_SMALL_STACK
wc_Sha512* sha512;
#else
wc_Sha512 sha512[1];
#endif
WC_DECLARE_VAR(sha512, wc_Sha512, 1, 0);
int ret = 0;
WOLFSSL_ENTER("wolfSSL_SHA512");
@@ -1376,13 +1328,9 @@ unsigned char* wolfSSL_SHA512(const unsigned char* data, size_t len,
hash = dgst;
}
#ifdef WOLFSSL_SMALL_STACK
/* Allocate dynamic memory for a wolfSSL SHA-512 object. */
sha512 = (wc_Sha512*)XMALLOC(sizeof(wc_Sha512), NULL, DYNAMIC_TYPE_DIGEST);
if (sha512 == NULL) {
ret = MEMORY_E;
}
#endif
WC_ALLOC_VAR_EX(sha512, wc_Sha512, 1, NULL, DYNAMIC_TYPE_DIGEST,
ret=MEMORY_E);
if (ret == 0) {
/* Initialize wolfCrypt SHA512 object. */
@@ -1412,10 +1360,7 @@ unsigned char* wolfSSL_SHA512(const unsigned char* data, size_t len,
wc_Sha512Free(sha512);
}
#ifdef WOLFSSL_SMALL_STACK
/* Free dynamic memory of a wolfSSL SHA-512 object. */
XFREE(sha512, NULL, DYNAMIC_TYPE_DIGEST);
#endif
WC_FREE_VAR_EX(sha512, NULL, DYNAMIC_TYPE_DIGEST);
return hash;
}
#endif /* WOLFSSL_SHA512 */
@@ -2062,11 +2007,7 @@ unsigned char* wolfSSL_HMAC(const WOLFSSL_EVP_MD* evp_md, const void* key,
int rc = 0;
int type = 0;
int hmacLen = 0;
#ifdef WOLFSSL_SMALL_STACK
Hmac* hmac = NULL;
#else
Hmac hmac[1];
#endif
WC_DECLARE_VAR(hmac, Hmac, 1, 0);
void* heap = NULL;
/* Validate parameters. */
@@ -2116,10 +2057,7 @@ unsigned char* wolfSSL_HMAC(const WOLFSSL_EVP_MD* evp_md, const void* key,
wc_HmacFree(hmac);
}
#ifdef WOLFSSL_SMALL_STACK
/* Free dynamic memory of a wolfSSL HMAC object. */
XFREE(hmac, heap, DYNAMIC_TYPE_HMAC);
#endif
WC_FREE_VAR_EX(hmac, heap, DYNAMIC_TYPE_HMAC);
return ret;
}
@@ -2715,11 +2653,7 @@ void wolfSSL_DES_cbc_encrypt(const unsigned char* input, unsigned char* output,
long length, WOLFSSL_DES_key_schedule* schedule, WOLFSSL_DES_cblock* ivec,
int enc)
{
#ifdef WOLFSSL_SMALL_STACK
Des* des = NULL;
#else
Des des[1];
#endif
WC_DECLARE_VAR(des, Des, 1, 0);
byte lastBlock[DES_BLOCK_SIZE];
WOLFSSL_ENTER("wolfSSL_DES_cbc_encrypt");
@@ -2767,9 +2701,7 @@ void wolfSSL_DES_cbc_encrypt(const unsigned char* input, unsigned char* output,
}
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(des, NULL, DYNAMIC_TYPE_CIPHER);
#endif
WC_FREE_VAR_EX(des, NULL, DYNAMIC_TYPE_CIPHER);
}
/* Encrypt/decrypt data with DES-CBC. Sets the IV for following operation.
@@ -2834,11 +2766,7 @@ void wolfSSL_DES_ede3_cbc_encrypt(const unsigned char* input,
WOLFSSL_DES_key_schedule* ks2, WOLFSSL_DES_key_schedule* ks3,
WOLFSSL_DES_cblock* ivec, int enc)
{
#ifdef WOLFSSL_SMALL_STACK
Des3* des3;
#else
Des3 des3[1];
#endif
WC_DECLARE_VAR(des3, Des3, 1, 0);
WOLFSSL_ENTER("wolfSSL_DES_ede3_cbc_encrypt");
@@ -2943,9 +2871,7 @@ void wolfSSL_DES_ede3_cbc_encrypt(const unsigned char* input,
wc_Des3Free(des3);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(des3, NULL, DYNAMIC_TYPE_CIPHER);
#endif
WC_FREE_VAR_EX(des3, NULL, DYNAMIC_TYPE_CIPHER);
}
#ifdef WOLFSSL_DES_ECB
@@ -2959,11 +2885,7 @@ void wolfSSL_DES_ede3_cbc_encrypt(const unsigned char* input,
void wolfSSL_DES_ecb_encrypt(WOLFSSL_DES_cblock* in, WOLFSSL_DES_cblock* out,
WOLFSSL_DES_key_schedule* key, int enc)
{
#ifdef WOLFSSL_SMALL_STACK
Des* des = NULL;
#else
Des des[1];
#endif
WC_DECLARE_VAR(des, Des, 1, 0);
WOLFSSL_ENTER("wolfSSL_DES_ecb_encrypt");
@@ -3001,9 +2923,7 @@ void wolfSSL_DES_ecb_encrypt(WOLFSSL_DES_cblock* in, WOLFSSL_DES_cblock* out,
}
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(des, NULL, DYNAMIC_TYPE_CIPHER);
#endif
WC_FREE_VAR_EX(des, NULL, DYNAMIC_TYPE_CIPHER);
}
#endif
#endif /* NO_DES3 */
+37 -138
View File
@@ -468,18 +468,11 @@ static int ProcessBufferTryDecodeRsa(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
int ret;
word32 idx;
/* make sure RSA key can be used */
#ifdef WOLFSSL_SMALL_STACK
RsaKey* key;
#else
RsaKey key[1];
#endif
WC_DECLARE_VAR(key, RsaKey, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
/* Allocate an RSA key to parse into so we can get size. */
key = (RsaKey*)XMALLOC(sizeof(RsaKey), heap, DYNAMIC_TYPE_RSA);
if (key == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(key, RsaKey, 1, heap, DYNAMIC_TYPE_RSA,
return MEMORY_E);
/* Initialize the RSA key. */
ret = wc_InitRsaKey_ex(key, heap, devId);
@@ -529,10 +522,7 @@ static int ProcessBufferTryDecodeRsa(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
wc_FreeRsaKey(key);
}
#ifdef WOLFSSL_SMALL_STACK
/* Dispose of allocated key. */
XFREE(key, heap, DYNAMIC_TYPE_RSA);
#endif
WC_FREE_VAR_EX(key, heap, DYNAMIC_TYPE_RSA);
return ret;
}
@@ -562,18 +552,11 @@ static int ProcessBufferTryDecodeEcc(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
int ret = 0;
word32 idx;
/* make sure ECC key can be used */
#ifdef WOLFSSL_SMALL_STACK
ecc_key* key;
#else
ecc_key key[1];
#endif
WC_DECLARE_VAR(key, ecc_key, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
/* Allocate an ECC key to parse into. */
key = (ecc_key*)XMALLOC(sizeof(ecc_key), heap, DYNAMIC_TYPE_ECC);
if (key == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(key, ecc_key, 1, heap, DYNAMIC_TYPE_ECC,
return MEMORY_E);
/* Initialize ECC key. */
if (wc_ecc_init_ex(key, heap, devId) == 0) {
@@ -638,10 +621,7 @@ static int ProcessBufferTryDecodeEcc(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
wc_ecc_free(key);
}
#ifdef WOLFSSL_SMALL_STACK
/* Dispose of allocated key. */
XFREE(key, heap, DYNAMIC_TYPE_ECC);
#endif
WC_FREE_VAR_EX(key, heap, DYNAMIC_TYPE_ECC);
return ret;
}
#endif /* HAVE_ECC */
@@ -669,19 +649,11 @@ static int ProcessBufferTryDecodeEd25519(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
int ret;
word32 idx;
/* make sure Ed25519 key can be used */
#ifdef WOLFSSL_SMALL_STACK
ed25519_key* key;
#else
ed25519_key key[1];
#endif
WC_DECLARE_VAR(key, ed25519_key, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
/* Allocate an Ed25519 key to parse into. */
key = (ed25519_key*)XMALLOC(sizeof(ed25519_key), heap,
DYNAMIC_TYPE_ED25519);
if (key == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(key, ed25519_key, 1, heap, DYNAMIC_TYPE_ED25519,
return MEMORY_E);
/* Initialize Ed25519 key. */
ret = wc_ed25519_init_ex(key, heap, devId);
@@ -733,10 +705,7 @@ static int ProcessBufferTryDecodeEd25519(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
wc_ed25519_free(key);
}
#ifdef WOLFSSL_SMALL_STACK
/* Dispose of allocated key. */
XFREE(key, heap, DYNAMIC_TYPE_ED25519);
#endif
WC_FREE_VAR_EX(key, heap, DYNAMIC_TYPE_ED25519);
return ret;
}
#endif /* HAVE_ED25519 && HAVE_ED25519_KEY_IMPORT */
@@ -764,18 +733,11 @@ static int ProcessBufferTryDecodeEd448(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
int ret;
word32 idx;
/* make sure Ed448 key can be used */
#ifdef WOLFSSL_SMALL_STACK
ed448_key* key = NULL;
#else
ed448_key key[1];
#endif
WC_DECLARE_VAR(key, ed448_key, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
/* Allocate an Ed448 key to parse into. */
key = (ed448_key*)XMALLOC(sizeof(ed448_key), heap, DYNAMIC_TYPE_ED448);
if (key == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(key, ed448_key, 1, heap, DYNAMIC_TYPE_ED448,
return MEMORY_E);
/* Initialize Ed448 key. */
ret = wc_ed448_init_ex(key, heap, devId);
@@ -824,10 +786,7 @@ static int ProcessBufferTryDecodeEd448(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
wc_ed448_free(key);
}
#ifdef WOLFSSL_SMALL_STACK
/* Dispose of allocated key. */
XFREE(key, heap, DYNAMIC_TYPE_ED448);
#endif
WC_FREE_VAR_EX(key, heap, DYNAMIC_TYPE_ED448);
return ret;
}
#endif /* HAVE_ED448 && HAVE_ED448_KEY_IMPORT */
@@ -1210,11 +1169,7 @@ static int ProcessBufferPrivPkcs8Dec(EncryptedInfo* info, DerBuffer* der,
int ret = 0;
word32 algId;
int passwordSz = NAME_SZ;
#ifndef WOLFSSL_SMALL_STACK
char password[NAME_SZ];
#else
char* password;
#endif
WC_DECLARE_VAR(password, char, NAME_SZ, 0);
(void)heap;
#ifdef WOLFSSL_SMALL_STACK
@@ -1868,20 +1823,11 @@ static int ProcessBufferCertAltPublicKey(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
#ifdef HAVE_ECC
case ECDSAk:
{
#ifdef WOLFSSL_SMALL_STACK
ecc_key* temp_key = NULL;
#else
ecc_key temp_key[1];
#endif
WC_DECLARE_VAR(temp_key, ecc_key, 1, 0);
keyType = ecc_dsa_sa_algo;
#ifdef WOLFSSL_SMALL_STACK
temp_key = (ecc_key*)XMALLOC(sizeof(ecc_key), heap,
DYNAMIC_TYPE_ECC);
if (temp_key == NULL) {
ret = MEMORY_E;
}
#endif
WC_ALLOC_VAR_EX(temp_key, ecc_key, 1, heap, DYNAMIC_TYPE_ECC,
ret=MEMORY_E);
/* Determine ECC key size. We have to decode the sapki for
* that. */
@@ -1897,9 +1843,7 @@ static int ProcessBufferCertAltPublicKey(WOLFSSL_CTX* ctx, WOLFSSL* ssl,
wc_ecc_free(temp_key);
}
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(temp_key, heap, DYNAMIC_TYPE_ECC);
#endif
WC_FREE_VAR_EX(temp_key, heap, DYNAMIC_TYPE_ECC);
if ((ret == 0) && checkKeySz) {
ret = CHECK_KEY_SZ(ssl ? ssl->options.minEccKeySz :
@@ -2068,21 +2012,12 @@ static int ProcessBufferCert(WOLFSSL_CTX* ctx, WOLFSSL* ssl, DerBuffer* der)
#if defined(HAVE_RPK)
RpkState* rpkState = ssl ? &ssl->options.rpkState : &ctx->rpkState;
#endif
#ifdef WOLFSSL_SMALL_STACK
DecodedCert* cert;
#else
DecodedCert cert[1];
#endif
WC_DECLARE_VAR(cert, DecodedCert, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
/* Allocate memory for certificate to be decoded into. */
cert = (DecodedCert*)XMALLOC(sizeof(DecodedCert), heap, DYNAMIC_TYPE_DCERT);
if (cert == NULL) {
ret = MEMORY_E;
}
if (ret == 0)
#endif
WC_ALLOC_VAR_EX(cert, DecodedCert, 1, heap, DYNAMIC_TYPE_DCERT,
ret=MEMORY_E);
if (WC_VAR_OK(cert))
{
/* Get device id from SSL context or SSL object. */
int devId = wolfSSL_CTX_GetDevId(ctx, ssl);
@@ -2129,10 +2064,7 @@ static int ProcessBufferCert(WOLFSSL_CTX* ctx, WOLFSSL* ssl, DerBuffer* der)
/* Dispose of dynamic memory in certificate object. */
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
/* Dispose of certificate object. */
XFREE(cert, heap, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, heap, DYNAMIC_TYPE_DCERT);
return ret;
}
@@ -2409,11 +2341,7 @@ int ProcessBuffer(WOLFSSL_CTX* ctx, const unsigned char* buff, long sz,
DerBuffer* der = NULL;
int ret = 0;
void* heap = WOLFSSL_HEAP(ctx, ssl);
#ifdef WOLFSSL_SMALL_STACK
EncryptedInfo* info = NULL;
#else
EncryptedInfo info[1];
#endif
WC_DECLARE_VAR(info, EncryptedInfo, 1, 0);
int algId = 0;
#ifdef WOLFSSL_DEBUG_CERTIFICATE_LOADS
long usedAtStart = used ? *used : 0L;
@@ -2479,10 +2407,7 @@ int ProcessBuffer(WOLFSSL_CTX* ctx, const unsigned char* buff, long sz,
/* Process the private key. */
ret = ProcessBufferPrivateKey(ctx, ssl, der, format, info, heap, type,
algId);
#ifdef WOLFSSL_SMALL_STACK
/* Info no longer needed - keep max memory usage down. */
XFREE(info, heap, DYNAMIC_TYPE_ENCRYPTEDINFO);
#endif
WC_FREE_VAR_EX(info, heap, DYNAMIC_TYPE_ENCRYPTEDINFO);
}
else if (ret == 0) {
/* Processing a certificate. */
@@ -2515,10 +2440,7 @@ int ProcessBuffer(WOLFSSL_CTX* ctx, const unsigned char* buff, long sz,
#endif /* WOLFSSL_DEBUG_CERTIFICATE_LOADS */
}
#ifdef WOLFSSL_SMALL_STACK
/* Info no longer needed - keep max memory usage down. */
XFREE(info, heap, DYNAMIC_TYPE_ENCRYPTEDINFO);
#endif
WC_FREE_VAR_EX(info, heap, DYNAMIC_TYPE_ENCRYPTEDINFO);
if (ret == 0) {
/* Process the different types of certificates. */
@@ -2885,20 +2807,11 @@ static int wolfssl_ctx_load_path(WOLFSSL_CTX* ctx, const char* path,
char* name = NULL;
int fileRet;
int failCount = 0;
#ifdef WOLFSSL_SMALL_STACK
ReadDirCtx* readCtx;
#else
ReadDirCtx readCtx[1];
#endif
WC_DECLARE_VAR(readCtx, ReadDirCtx, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
/* Allocate memory for directory reading context. */
readCtx = (ReadDirCtx*)XMALLOC(sizeof(ReadDirCtx), ctx->heap,
DYNAMIC_TYPE_DIRCTX);
if (readCtx == NULL) {
ret = MEMORY_E;
}
#endif
WC_ALLOC_VAR_EX(readCtx, ReadDirCtx, 1, ctx->heap, DYNAMIC_TYPE_DIRCTX,
ret=MEMORY_E);
if (ret == 1) {
/* Get name of first file in path. */
@@ -2956,10 +2869,7 @@ static int wolfssl_ctx_load_path(WOLFSSL_CTX* ctx, const char* path,
ret = 1;
}
#ifdef WOLFSSL_SMALL_STACK
/* Dispose of dynamically allocated memory. */
XFREE(readCtx, ctx->heap, DYNAMIC_TYPE_DIRCTX);
#endif
WC_FREE_VAR_EX(readCtx, ctx->heap, DYNAMIC_TYPE_DIRCTX);
}
return ret;
@@ -5652,18 +5562,10 @@ static int wolfssl_check_dh_key(unsigned char* p, int pSz, unsigned char* g,
{
WC_RNG rng;
int ret = 0;
#ifndef WOLFSSL_SMALL_STACK
DhKey checkKey[1];
#else
DhKey *checkKey;
#endif
WC_DECLARE_VAR(checkKey, DhKey, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
checkKey = (DhKey*)XMALLOC(sizeof(DhKey), NULL, DYNAMIC_TYPE_DH);
if (checkKey == NULL) {
ret = MEMORY_E;
}
#endif
WC_ALLOC_VAR_EX(checkKey, DhKey, 1, NULL, DYNAMIC_TYPE_DH,
ret=MEMORY_E);
/* Initialize a new random number generator. */
if ((ret == 0) && ((ret = wc_InitRng(&rng)) == 0)) {
/* Initialize a DH object. */
@@ -5677,10 +5579,7 @@ static int wolfssl_check_dh_key(unsigned char* p, int pSz, unsigned char* g,
wc_FreeRng(&rng);
}
#ifdef WOLFSSL_SMALL_STACK
/* Dispose of dynamically allocated data. */
XFREE(checkKey, NULL, DYNAMIC_TYPE_DH);
#endif
WC_FREE_VAR_EX(checkKey, NULL, DYNAMIC_TYPE_DH);
/* Convert wolfCrypt return code to 1 on success and ret on failure. */
return WC_TO_WS_RC(ret);
}
+8 -24
View File
@@ -578,11 +578,7 @@ static int wolfSSL_BIO_to_MIME_crlf(WOLFSSL_BIO* in, WOLFSSL_BIO* out)
int lineLen = 0;
word32 canonLineLen = 0;
char* canonLine = NULL;
#ifdef WOLFSSL_SMALL_STACK
char* line = NULL;
#else
char line[MAX_MIME_LINE_LEN];
#endif
WC_DECLARE_VAR(line, char, MAX_MIME_LINE_LEN, 0);
if (in == NULL || out == NULL) {
return BAD_FUNC_ARG;
@@ -629,9 +625,7 @@ static int wolfSSL_BIO_to_MIME_crlf(WOLFSSL_BIO* in, WOLFSSL_BIO* out)
}
XFREE(canonLine, NULL, DYNAMIC_TYPE_PKCS7);
#ifdef WOLFSSL_SMALL_STACK
XFREE(line, in->heap, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(line, in->heap, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -1041,18 +1035,14 @@ int wolfSSL_PEM_write_bio_PKCS7(WOLFSSL_BIO* bio, PKCS7* p7)
if ((wolfSSL_BIO_write(bio, pem, pemSz) == pemSz)) {
XFREE(output, bio->heap, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(pem, bio->heap, DYNAMIC_TYPE_TMP_BUFFER);
#ifdef WOLFSSL_SMALL_STACK
XFREE(outputHead, bio->heap, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(outputFoot, bio->heap, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(outputHead, bio->heap, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(outputFoot, bio->heap, DYNAMIC_TYPE_TMP_BUFFER);
return WOLFSSL_SUCCESS;
}
error:
#ifdef WOLFSSL_SMALL_STACK
XFREE(outputHead, bio->heap, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(outputFoot, bio->heap, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(outputHead, bio->heap, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(outputFoot, bio->heap, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(output, bio->heap, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(pem, bio->heap, DYNAMIC_TYPE_TMP_BUFFER);
return WOLFSSL_FAILURE;
@@ -1853,11 +1843,7 @@ int wolfSSL_PKCS12_parse(WC_PKCS12* pkcs12, const char* psw,
byte* pk = NULL;
word32 pkSz;
WC_DerCertList* certList = NULL;
#ifdef WOLFSSL_SMALL_STACK
DecodedCert *DeCert;
#else
DecodedCert DeCert[1];
#endif
WC_DECLARE_VAR(DeCert, DecodedCert, 1, 0);
WOLFSSL_ENTER("wolfSSL_PKCS12_parse");
@@ -2073,9 +2059,7 @@ int wolfSSL_PKCS12_parse(WC_PKCS12* pkcs12, const char* psw,
out:
#ifdef WOLFSSL_SMALL_STACK
XFREE(DeCert, heap, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(DeCert, heap, DYNAMIC_TYPE_DCERT);
return ret;
}
+3 -11
View File
@@ -1167,11 +1167,7 @@ int wolfSSL_GetSessionFromCache(WOLFSSL* ssl, WOLFSSL_SESSION* output)
word32 row;
int error = 0;
#ifdef HAVE_SESSION_TICKET
#ifndef WOLFSSL_SMALL_STACK
byte tmpTicket[PREALLOC_SESSION_TICKET_LEN];
#else
byte* tmpTicket = NULL;
#endif
WC_DECLARE_VAR(tmpTicket, byte, PREALLOC_SESSION_TICKET_LEN, 0);
#ifdef WOLFSSL_TLS13
byte *preallocNonce = NULL;
byte preallocNonceLen = 0;
@@ -1300,9 +1296,7 @@ int wolfSSL_GetSessionFromCache(WOLFSSL* ssl, WOLFSSL_SESSION* output)
output->ticket = output->staticTicket;
output->ticketLenAlloc = 0;
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(tmpTicket, output->heap, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(tmpTicket, output->heap, DYNAMIC_TYPE_TMP_BUFFER);
return WOLFSSL_FAILURE;
}
#endif /* WOLFSSL_TLS13 && HAVE_SESSION_TICKET*/
@@ -1403,9 +1397,7 @@ int wolfSSL_GetSessionFromCache(WOLFSSL* ssl, WOLFSSL_SESSION* output)
XMEMCPY(output->ticket, tmpTicket, output->ticketLen); /* cppcheck-suppress uninitvar */
}
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(tmpTicket, output->heap, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(tmpTicket, output->heap, DYNAMIC_TYPE_TMP_BUFFER);
#if defined(WOLFSSL_TLS13) && defined(WOLFSSL_TICKET_NONCE_MALLOC) && \
(!defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)))
+25 -64
View File
@@ -174,8 +174,8 @@ int BuildTlsFinished(WOLFSSL* ssl, Hashes* hashes, const byte* sender)
#if !defined(WOLFSSL_ASYNC_CRYPT) || defined(WC_ASYNC_NO_HASH)
byte handshake_hash[HSHASH_SZ];
#else
WC_DECLARE_VAR(handshake_hash, byte, HSHASH_SZ, ssl->heap);
WC_ALLOC_VAR(handshake_hash, byte, HSHASH_SZ, ssl->heap);
byte* handshake_hash = NULL;
handshake_hash = XMALLOC(HSHASH_SZ, ssl->heap, DYNAMIC_TYPE_DIGEST);
if (handshake_hash == NULL)
return MEMORY_E;
#endif
@@ -230,7 +230,7 @@ int BuildTlsFinished(WOLFSSL* ssl, Hashes* hashes, const byte* sender)
}
#if defined(WOLFSSL_ASYNC_CRYPT) && !defined(WC_ASYNC_NO_HASH)
WC_FREE_VAR(handshake_hash, ssl->heap);
XFREE(handshake_hash, ssl->heap, DYNAMIC_TYPE_DIGEST);
#elif defined(WOLFSSL_CHECK_MEM_ZERO)
wc_MemZero_Check(handshake_hash, HSHASH_SZ);
#endif
@@ -403,8 +403,8 @@ static int _DeriveTlsKeys(byte* key_dig, word32 key_dig_len,
{
int ret;
#if defined(WOLFSSL_ASYNC_CRYPT) && !defined(WC_ASYNC_NO_HASH)
WC_DECLARE_VAR(seed, byte, SEED_LEN, heap);
WC_ALLOC_VAR(seed, byte, SEED_LEN, heap);
byte* seed = NULL;
seed = XMALLOC(SEED_LEN, heap, DYNAMIC_TYPE_SEED);
if (seed == NULL)
return MEMORY_E;
#else
@@ -441,7 +441,7 @@ static int _DeriveTlsKeys(byte* key_dig, word32 key_dig_len,
#endif
#if defined(WOLFSSL_ASYNC_CRYPT) && !defined(WC_ASYNC_NO_HASH)
WC_FREE_VAR(seed, heap);
XFREE(seed, heap, DYNAMIC_TYPE_SEED);
#endif
return ret;
@@ -464,18 +464,10 @@ int DeriveTlsKeys(WOLFSSL* ssl)
int key_dig_len = 2 * ssl->specs.hash_size +
2 * ssl->specs.key_size +
2 * ssl->specs.iv_size;
#ifdef WOLFSSL_SMALL_STACK
byte* key_dig;
#else
byte key_dig[MAX_PRF_DIG];
#endif
WC_DECLARE_VAR(key_dig, byte, MAX_PRF_DIG, 0);
#ifdef WOLFSSL_SMALL_STACK
key_dig = (byte*)XMALLOC(MAX_PRF_DIG, ssl->heap, DYNAMIC_TYPE_DIGEST);
if (key_dig == NULL) {
return MEMORY_E;
}
#endif
WC_ALLOC_VAR_EX(key_dig, byte, MAX_PRF_DIG, ssl->heap,
DYNAMIC_TYPE_DIGEST, return MEMORY_E);
XMEMSET(key_dig, 0, MAX_PRF_DIG);
@@ -496,9 +488,7 @@ int DeriveTlsKeys(WOLFSSL* ssl)
if (ret == 0)
ret = StoreKeys(ssl, key_dig, PROVISION_CLIENT_SERVER);
#ifdef WOLFSSL_SMALL_STACK
XFREE(key_dig, ssl->heap, DYNAMIC_TYPE_DIGEST);
#endif
WC_FREE_VAR_EX(key_dig, ssl->heap, DYNAMIC_TYPE_DIGEST);
return ret;
}
@@ -513,8 +503,8 @@ static int _MakeTlsMasterSecret(byte* ms, word32 msLen,
#if !defined(WOLFSSL_ASYNC_CRYPT) || defined(WC_ASYNC_NO_HASH)
byte seed[SEED_LEN];
#else
WC_DECLARE_VAR(seed, byte, SEED_LEN, heap);
WC_ALLOC_VAR(seed, byte, SEED_LEN, heap);
byte* seed = NULL;
seed = XMALLOC(SEED_LEN, heap, DYNAMIC_TYPE_SEED);
if (seed == NULL)
return MEMORY_E;
#endif
@@ -543,7 +533,7 @@ static int _MakeTlsMasterSecret(byte* ms, word32 msLen,
#endif
#if defined(WOLFSSL_ASYNC_CRYPT) && !defined(WC_ASYNC_NO_HASH)
WC_FREE_VAR(seed, heap);
XFREE(seed, heap, DYNAMIC_TYPE_SEED);
#endif
return ret;
@@ -709,17 +699,10 @@ int wolfSSL_make_eap_keys(WOLFSSL* ssl, void* key, unsigned int len,
const char* label)
{
int ret;
#ifdef WOLFSSL_SMALL_STACK
byte* seed;
#else
byte seed[SEED_LEN];
#endif
WC_DECLARE_VAR(seed, byte, SEED_LEN, 0);
#ifdef WOLFSSL_SMALL_STACK
seed = (byte*)XMALLOC(SEED_LEN, ssl->heap, DYNAMIC_TYPE_SEED);
if (seed == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(seed, byte, SEED_LEN, ssl->heap, DYNAMIC_TYPE_SEED,
return MEMORY_E);
/*
* As per RFC-5281, the order of the client and server randoms is reversed
@@ -745,9 +728,7 @@ int wolfSSL_make_eap_keys(WOLFSSL* ssl, void* key, unsigned int len,
(void)label;
#endif
#ifdef WOLFSSL_SMALL_STACK
XFREE(seed, ssl->heap, DYNAMIC_TYPE_SEED);
#endif
WC_FREE_VAR_EX(seed, ssl->heap, DYNAMIC_TYPE_SEED);
return ret;
}
@@ -7458,9 +7439,7 @@ static int TLSX_CA_Names_Parse(WOLFSSL *ssl, const byte* input,
if (didInit)
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, ssl->heap, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, ssl->heap, DYNAMIC_TYPE_DCERT);
if (ret != 0)
return ret;
@@ -8440,11 +8419,7 @@ static int TLSX_KeyShare_GenPqcKeyClient(WOLFSSL *ssl, KeyShareEntry* kse)
int ret = 0;
int type = 0;
#ifndef WOLFSSL_TLSX_PQC_MLKEM_STORE_OBJ
#ifdef WOLFSSL_SMALL_STACK
KyberKey *kem = NULL;
#else
KyberKey kem[1];
#endif
WC_DECLARE_VAR(kem, KyberKey, 1, 0);
byte* privKey = NULL;
word32 privSz = 0;
#else
@@ -13117,10 +13092,8 @@ static int TLSX_ECH_Write(WOLFSSL_ECH* ech, byte msgType, byte* writeBuf,
wc_FreeRng(rng);
if (ephemeralKey != NULL)
wc_HpkeFreeKey(hpke, hpke->kem, ephemeralKey, hpke->heap);
#ifdef WOLFSSL_SMALL_STACK
XFREE(hpke, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(rng, NULL, DYNAMIC_TYPE_RNG);
#endif
WC_FREE_VAR_EX(hpke, NULL, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(rng, NULL, DYNAMIC_TYPE_RNG);
}
else {
/* only write enc if this is our first ech, no hpke context */
@@ -15007,11 +14980,7 @@ static int TLSX_GetSizeWithEch(WOLFSSL* ssl, byte* semaphore, byte msgType,
TLSX* echX = NULL;
TLSX* serverNameX = NULL;
TLSX** extensions = NULL;
#ifdef WOLFSSL_SMALL_STACK
char* tmpServerName = NULL;
#else
char tmpServerName[MAX_PUBLIC_NAME_SZ];
#endif
WC_DECLARE_VAR(tmpServerName, char, MAX_PUBLIC_NAME_SZ, 0);
/* calculate the rest of the extensions length with inner ech */
if (ssl->extensions)
@@ -15086,9 +15055,7 @@ static int TLSX_GetSizeWithEch(WOLFSSL* ssl, byte* semaphore, byte msgType,
ret = 0;
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(tmpServerName, ssl->heap, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(tmpServerName, ssl->heap, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -15218,11 +15185,7 @@ static int TLSX_WriteWithEch(WOLFSSL* ssl, byte* output, byte* semaphore,
TLSX* echX = NULL;
TLSX* serverNameX = NULL;
TLSX** extensions = NULL;
#ifdef WOLFSSL_SMALL_STACK
char* tmpServerName = NULL;
#else
char tmpServerName[MAX_PUBLIC_NAME_SZ];
#endif
WC_DECLARE_VAR(tmpServerName, char, MAX_PUBLIC_NAME_SZ, 0);
/* get the echX from either extensions or ctx */
if (ssl->extensions)
@@ -15330,9 +15293,7 @@ static int TLSX_WriteWithEch(WOLFSSL* ssl, byte* output, byte* semaphore,
ret = r;
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(tmpServerName, ssl->heap, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(tmpServerName, ssl->heap, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
+7 -24
View File
@@ -1344,11 +1344,7 @@ int DeriveResumptionPSK(WOLFSSL* ssl, byte* nonce, byte nonceLen, byte* secret)
static int BuildTls13HandshakeHmac(WOLFSSL* ssl, byte* key, byte* hash,
word32* pHashSz)
{
#ifdef WOLFSSL_SMALL_STACK
Hmac* verifyHmac;
#else
Hmac verifyHmac[1];
#endif
WC_DECLARE_VAR(verifyHmac, Hmac, 1, 0);
int hashType = WC_SHA256;
int hashSz = WC_SHA256_DIGEST_SIZE;
int ret = WC_NO_ERR_TRACE(BAD_FUNC_ARG);
@@ -1401,12 +1397,8 @@ static int BuildTls13HandshakeHmac(WOLFSSL* ssl, byte* key, byte* hash,
WOLFSSL_BUFFER(hash, hashSz);
#endif
#ifdef WOLFSSL_SMALL_STACK
verifyHmac = (Hmac*)XMALLOC(sizeof(Hmac), NULL, DYNAMIC_TYPE_HMAC);
if (verifyHmac == NULL) {
return MEMORY_E;
}
#endif
WC_ALLOC_VAR_EX(verifyHmac, Hmac, 1, NULL, DYNAMIC_TYPE_HMAC,
return MEMORY_E);
/* Calculate the verify data. */
ret = wc_HmacInit(verifyHmac, ssl->heap, ssl->devId);
@@ -1419,9 +1411,7 @@ static int BuildTls13HandshakeHmac(WOLFSSL* ssl, byte* key, byte* hash,
wc_HmacFree(verifyHmac);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(verifyHmac, NULL, DYNAMIC_TYPE_HMAC);
#endif
WC_FREE_VAR_EX(verifyHmac, NULL, DYNAMIC_TYPE_HMAC);
#ifdef WOLFSSL_DEBUG_TLS
WOLFSSL_MSG(" Hash");
@@ -1465,11 +1455,7 @@ int DeriveTls13Keys(WOLFSSL* ssl, int secret, int side, int store)
{
int ret = WC_NO_ERR_TRACE(BAD_FUNC_ARG); /* Assume failure */
int i = 0;
#ifdef WOLFSSL_SMALL_STACK
byte* key_dig;
#else
byte key_dig[MAX_PRF_DIG];
#endif
WC_DECLARE_VAR(key_dig, byte, MAX_PRF_DIG, 0);
int provision;
#if defined(WOLFSSL_RENESAS_TSIP_TLS)
@@ -1480,11 +1466,8 @@ int DeriveTls13Keys(WOLFSSL* ssl, int secret, int side, int store)
ret = WC_NO_ERR_TRACE(BAD_FUNC_ARG); /* Assume failure */
#endif
#ifdef WOLFSSL_SMALL_STACK
key_dig = (byte*)XMALLOC(MAX_PRF_DIG, ssl->heap, DYNAMIC_TYPE_DIGEST);
if (key_dig == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(key_dig, byte, MAX_PRF_DIG, ssl->heap,
DYNAMIC_TYPE_DIGEST, return MEMORY_E);
if (side == ENCRYPT_AND_DECRYPT_SIDE) {
provision = PROVISION_CLIENT_SERVER;
+4 -12
View File
@@ -2150,10 +2150,8 @@ int EmbedOcspLookup(void* ctx, const char* url, int urlSz,
}
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(path, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(domainName, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(path, NULL, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(domainName, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -2206,11 +2204,7 @@ int EmbedCrlLookup(WOLFSSL_CRL* crl, const char* url, int urlSz)
SOCKET_T sfd = SOCKET_INVALID;
word16 port;
int ret = -1;
#ifdef WOLFSSL_SMALL_STACK
char* domainName;
#else
char domainName[MAX_URL_ITEM_SIZE];
#endif
WC_DECLARE_VAR(domainName, char, MAX_URL_ITEM_SIZE, 0);
#ifdef WOLFSSL_SMALL_STACK
domainName = (char*)XMALLOC(MAX_URL_ITEM_SIZE, crl->heap,
@@ -2252,9 +2246,7 @@ int EmbedCrlLookup(WOLFSSL_CRL* crl, const char* url, int urlSz)
}
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(domainName, crl->heap, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(domainName, crl->heap, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
+84 -284
View File
@@ -117,11 +117,7 @@ int wolfSSL_X509_get_ext_count(const WOLFSSL_X509* passedCert)
int sz = 0;
word32 idx = 0;
const byte* input;
#ifdef WOLFSSL_SMALL_STACK
DecodedCert *cert;
#else
DecodedCert cert[1];
#endif
WC_DECLARE_VAR(cert, DecodedCert, 1, 0);
WOLFSSL_ENTER("wolfSSL_X509_get_ext_count");
if (passedCert == NULL) {
@@ -196,9 +192,7 @@ int wolfSSL_X509_get_ext_count(const WOLFSSL_X509* passedCert)
out:
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, NULL, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, NULL, DYNAMIC_TYPE_DCERT);
return extCount;
}
@@ -737,11 +731,7 @@ WOLFSSL_X509_EXTENSION* wolfSSL_X509_set_ext(WOLFSSL_X509* x509, int loc)
byte* oidBuf;
word32 oid, idx = 0, tmpIdx = 0, nid;
WOLFSSL_X509_EXTENSION* ext = NULL;
#ifdef WOLFSSL_SMALL_STACK
DecodedCert* cert = NULL;
#else
DecodedCert cert[1];
#endif
WC_DECLARE_VAR(cert, DecodedCert, 1, 0);
WOLFSSL_ENTER("wolfSSL_X509_set_ext");
@@ -788,9 +778,7 @@ WOLFSSL_X509_EXTENSION* wolfSSL_X509_set_ext(WOLFSSL_X509* x509, int loc)
WOLFSSL_MSG("\tCertificate parsing failed");
wolfSSL_X509_EXTENSION_free(ext);
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, NULL, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, NULL, DYNAMIC_TYPE_DCERT);
return NULL;
}
@@ -801,9 +789,7 @@ WOLFSSL_X509_EXTENSION* wolfSSL_X509_set_ext(WOLFSSL_X509* x509, int loc)
WOLFSSL_MSG("\tfail: should be an EXTENSIONS");
wolfSSL_X509_EXTENSION_free(ext);
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, NULL, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, NULL, DYNAMIC_TYPE_DCERT);
return NULL;
}
@@ -815,9 +801,7 @@ WOLFSSL_X509_EXTENSION* wolfSSL_X509_set_ext(WOLFSSL_X509* x509, int loc)
WOLFSSL_MSG("\tfail: should be an EXTENSIONS");
wolfSSL_X509_EXTENSION_free(ext);
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, NULL, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, NULL, DYNAMIC_TYPE_DCERT);
return NULL;
}
@@ -825,9 +809,7 @@ WOLFSSL_X509_EXTENSION* wolfSSL_X509_set_ext(WOLFSSL_X509* x509, int loc)
WOLFSSL_MSG("\tfail: invalid length");
wolfSSL_X509_EXTENSION_free(ext);
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, NULL, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, NULL, DYNAMIC_TYPE_DCERT);
return NULL;
}
}
@@ -836,9 +818,7 @@ WOLFSSL_X509_EXTENSION* wolfSSL_X509_set_ext(WOLFSSL_X509* x509, int loc)
WOLFSSL_MSG("\tfail: should be a SEQUENCE (1)");
wolfSSL_X509_EXTENSION_free(ext);
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, NULL, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, NULL, DYNAMIC_TYPE_DCERT);
return NULL;
}
@@ -849,9 +829,7 @@ WOLFSSL_X509_EXTENSION* wolfSSL_X509_set_ext(WOLFSSL_X509* x509, int loc)
WOLFSSL_MSG("\tfail: should be a SEQUENCE");
wolfSSL_X509_EXTENSION_free(ext);
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, NULL, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, NULL, DYNAMIC_TYPE_DCERT);
return NULL;
}
@@ -861,9 +839,7 @@ WOLFSSL_X509_EXTENSION* wolfSSL_X509_set_ext(WOLFSSL_X509* x509, int loc)
WOLFSSL_MSG("\tfail: OBJECT ID");
wolfSSL_X509_EXTENSION_free(ext);
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, NULL, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, NULL, DYNAMIC_TYPE_DCERT);
return NULL;
}
idx = tmpIdx;
@@ -886,9 +862,7 @@ WOLFSSL_X509_EXTENSION* wolfSSL_X509_set_ext(WOLFSSL_X509* x509, int loc)
WOLFSSL_MSG("\tfail: Invalid OBJECT");
wolfSSL_X509_EXTENSION_free(ext);
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, NULL, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, NULL, DYNAMIC_TYPE_DCERT);
return NULL;
}
}
@@ -934,9 +908,7 @@ WOLFSSL_X509_EXTENSION* wolfSSL_X509_set_ext(WOLFSSL_X509* x509, int loc)
if (a == NULL || !ret) {
wolfSSL_X509_EXTENSION_free(ext);
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, NULL, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, NULL, DYNAMIC_TYPE_DCERT);
return NULL;
}
a->length = (int)x509->pathLength;
@@ -962,9 +934,7 @@ WOLFSSL_X509_EXTENSION* wolfSSL_X509_set_ext(WOLFSSL_X509* x509, int loc)
WOLFSSL_MSG("Failed to malloc stack");
wolfSSL_X509_EXTENSION_free(ext);
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, NULL, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, NULL, DYNAMIC_TYPE_DCERT);
return NULL;
}
@@ -979,9 +949,7 @@ WOLFSSL_X509_EXTENSION* wolfSSL_X509_set_ext(WOLFSSL_X509* x509, int loc)
wolfSSL_sk_ASN1_OBJECT_pop_free(sk, NULL);
wolfSSL_X509_EXTENSION_free(ext);
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, NULL, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, NULL, DYNAMIC_TYPE_DCERT);
return NULL;
}
obj->obj = (byte*)x509->authInfoCaIssuer;
@@ -997,9 +965,7 @@ WOLFSSL_X509_EXTENSION* wolfSSL_X509_set_ext(WOLFSSL_X509* x509, int loc)
wolfSSL_sk_ASN1_OBJECT_pop_free(sk, NULL);
wolfSSL_X509_EXTENSION_free(ext);
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, NULL, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, NULL, DYNAMIC_TYPE_DCERT);
return NULL;
}
}
@@ -1015,9 +981,7 @@ WOLFSSL_X509_EXTENSION* wolfSSL_X509_set_ext(WOLFSSL_X509* x509, int loc)
wolfSSL_sk_ASN1_OBJECT_pop_free(sk, NULL);
wolfSSL_X509_EXTENSION_free(ext);
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, NULL, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, NULL, DYNAMIC_TYPE_DCERT);
return NULL;
}
obj->obj = x509->authInfo;
@@ -1033,9 +997,7 @@ WOLFSSL_X509_EXTENSION* wolfSSL_X509_set_ext(WOLFSSL_X509* x509, int loc)
wolfSSL_sk_ASN1_OBJECT_pop_free(sk, NULL);
wolfSSL_X509_EXTENSION_free(ext);
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, NULL, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, NULL, DYNAMIC_TYPE_DCERT);
return NULL;
}
}
@@ -1049,9 +1011,7 @@ WOLFSSL_X509_EXTENSION* wolfSSL_X509_set_ext(WOLFSSL_X509* x509, int loc)
if (!wolfssl_x509_alt_names_to_gn(x509, ext)) {
wolfSSL_X509_EXTENSION_free(ext);
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, NULL, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, NULL, DYNAMIC_TYPE_DCERT);
return NULL;
}
break;
@@ -1066,9 +1026,7 @@ WOLFSSL_X509_EXTENSION* wolfSSL_X509_set_ext(WOLFSSL_X509* x509, int loc)
WOLFSSL_MSG("Failed to Get ASN Object Id");
wolfSSL_X509_EXTENSION_free(ext);
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, NULL, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, NULL, DYNAMIC_TYPE_DCERT);
return NULL;
}
oidBuf = (byte*)XMALLOC(length+1+MAX_LENGTH_SZ, NULL,
@@ -1077,9 +1035,7 @@ WOLFSSL_X509_EXTENSION* wolfSSL_X509_set_ext(WOLFSSL_X509* x509, int loc)
WOLFSSL_MSG("Failed to malloc tmp buffer");
wolfSSL_X509_EXTENSION_free(ext);
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, NULL, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, NULL, DYNAMIC_TYPE_DCERT);
return NULL;
}
oidBuf[0] = ASN_OBJECT_ID;
@@ -1094,9 +1050,7 @@ WOLFSSL_X509_EXTENSION* wolfSSL_X509_set_ext(WOLFSSL_X509* x509, int loc)
XFREE(oidBuf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
wolfSSL_X509_EXTENSION_free(ext);
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, NULL, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, NULL, DYNAMIC_TYPE_DCERT);
return NULL;
}
}
@@ -1123,9 +1077,7 @@ WOLFSSL_X509_EXTENSION* wolfSSL_X509_set_ext(WOLFSSL_X509* x509, int loc)
wolfSSL_X509_EXTENSION_free(ext);
FreeDecodedCert(cert);
XFREE(oidBuf, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, NULL, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, NULL, DYNAMIC_TYPE_DCERT);
return NULL;
}
ext->obj->dynamic |= WOLFSSL_ASN1_DYNAMIC_DATA;
@@ -1160,9 +1112,7 @@ WOLFSSL_X509_EXTENSION* wolfSSL_X509_set_ext(WOLFSSL_X509* x509, int loc)
wolfSSL_ASN1_OBJECT_free(ext->obj);
wolfSSL_X509_EXTENSION_free(ext);
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, NULL, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, NULL, DYNAMIC_TYPE_DCERT);
return NULL;
}
@@ -1178,9 +1128,7 @@ WOLFSSL_X509_EXTENSION* wolfSSL_X509_set_ext(WOLFSSL_X509* x509, int loc)
wolfSSL_ASN1_OBJECT_free(ext->obj);
wolfSSL_X509_EXTENSION_free(ext);
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, NULL, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, NULL, DYNAMIC_TYPE_DCERT);
return NULL;
}
@@ -1191,9 +1139,7 @@ WOLFSSL_X509_EXTENSION* wolfSSL_X509_set_ext(WOLFSSL_X509* x509, int loc)
wolfSSL_ASN1_OBJECT_free(ext->obj);
wolfSSL_X509_EXTENSION_free(ext);
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, NULL, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, NULL, DYNAMIC_TYPE_DCERT);
return NULL;
}
ext->value.data = (char*)XMALLOC(length, NULL,
@@ -1203,9 +1149,7 @@ WOLFSSL_X509_EXTENSION* wolfSSL_X509_set_ext(WOLFSSL_X509* x509, int loc)
WOLFSSL_MSG("Failed to malloc ASN1_STRING data");
wolfSSL_X509_EXTENSION_free(ext);
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, NULL, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, NULL, DYNAMIC_TYPE_DCERT);
return NULL;
}
XMEMCPY(ext->value.data,input+tmpIdx,length);
@@ -1226,9 +1170,7 @@ WOLFSSL_X509_EXTENSION* wolfSSL_X509_set_ext(WOLFSSL_X509* x509, int loc)
}
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, NULL, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, NULL, DYNAMIC_TYPE_DCERT);
return ext;
}
@@ -1911,11 +1853,7 @@ void* wolfSSL_X509V3_EXT_d2i(WOLFSSL_X509_EXTENSION* ext)
WOLFSSL_ASN1_STRING* asn1String = NULL, *newString = NULL;
WOLFSSL_STACK* sk;
void *data = NULL;
#ifdef WOLFSSL_SMALL_STACK
DecodedCert *cert;
#else
DecodedCert cert[1];
#endif
WC_DECLARE_VAR(cert, DecodedCert, 1, 0);
WOLFSSL_ENTER("wolfSSL_X509V3_EXT_d2i");
@@ -2122,9 +2060,7 @@ void* wolfSSL_X509V3_EXT_d2i(WOLFSSL_X509_EXTENSION* ext)
out:
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, NULL, DYNAMIC_TYPE_X509_EXT);
#endif
WC_FREE_VAR_EX(cert, NULL, DYNAMIC_TYPE_X509_EXT);
return data;
}
@@ -2145,11 +2081,7 @@ int wolfSSL_X509_get_ext_by_NID(const WOLFSSL_X509* x509, int nid, int lastPos)
const byte* rawCert;
const byte* input;
word32 oid, idx = 0, tmpIdx = 0, foundNID;
#ifdef WOLFSSL_SMALL_STACK
DecodedCert *cert;
#else
DecodedCert cert[1];
#endif
WC_DECLARE_VAR(cert, DecodedCert, 1, 0);
WOLFSSL_ENTER("wolfSSL_X509_get_ext_by_NID");
@@ -2254,9 +2186,7 @@ int wolfSSL_X509_get_ext_by_NID(const WOLFSSL_X509* x509, int nid, int lastPos)
out:
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, x509->heap, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, x509->heap, DYNAMIC_TYPE_DCERT);
return found ? extCount : WOLFSSL_FATAL_ERROR;
}
@@ -3890,18 +3820,10 @@ static WOLFSSL_X509* d2i_X509orX509REQ(WOLFSSL_X509** x509,
&& (req == 0 || req == 1)
#endif
) {
#ifdef WOLFSSL_SMALL_STACK
DecodedCert* cert;
#else
DecodedCert cert[1];
#endif
WC_DECLARE_VAR(cert, DecodedCert, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
cert = (DecodedCert*)XMALLOC(sizeof(DecodedCert), NULL,
DYNAMIC_TYPE_DCERT);
if (cert == NULL)
return NULL;
#endif
WC_ALLOC_VAR_EX(cert, DecodedCert, 1, NULL, DYNAMIC_TYPE_DCERT,
return NULL);
InitDecodedCert(cert, (byte*)in, (word32)len, heap);
#ifdef WOLFSSL_CERT_REQ
@@ -3917,9 +3839,7 @@ static WOLFSSL_X509* d2i_X509orX509REQ(WOLFSSL_X509** x509,
}
}
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, NULL, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, NULL, DYNAMIC_TYPE_DCERT);
}
if (x509 != NULL)
@@ -4063,11 +3983,7 @@ int wolfSSL_X509_get_signature(WOLFSSL_X509* x509,
int wolfSSL_X509_get_pubkey_buffer(WOLFSSL_X509* x509,
unsigned char* buf, int* bufSz)
{
#ifdef WOLFSSL_SMALL_STACK
DecodedCert* cert;
#else
DecodedCert cert[1];
#endif
WC_DECLARE_VAR(cert, DecodedCert, 1, 0);
const byte* der;
int length = 0;
int ret = 0, derSz = 0;
@@ -4104,9 +4020,7 @@ int wolfSSL_X509_get_pubkey_buffer(WOLFSSL_X509* x509,
}
FreeDecodedCert(cert);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, x509->heap, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(cert, x509->heap, DYNAMIC_TYPE_TMP_BUFFER);
if (ret < 0) {
WOLFSSL_LEAVE("wolfSSL_X509_get_pubkey_buffer", ret);
@@ -5463,20 +5377,11 @@ static WOLFSSL_X509* loadX509orX509REQFromBuffer(
/* At this point we want `der` to have the certificate in DER format */
/* ready to be decoded. */
if (der != NULL && der->buffer != NULL) {
#ifdef WOLFSSL_SMALL_STACK
DecodedCert* cert;
#else
DecodedCert cert[1];
#endif
WC_DECLARE_VAR(cert, DecodedCert, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
cert = (DecodedCert*)XMALLOC(sizeof(DecodedCert), NULL,
DYNAMIC_TYPE_DCERT);
if (cert == NULL) {
ret = MEMORY_ERROR;
}
else
#endif
WC_ALLOC_VAR_EX(cert, DecodedCert, 1, NULL, DYNAMIC_TYPE_DCERT,
ret=MEMORY_ERROR);
if (WC_VAR_OK(cert))
{
InitDecodedCert(cert, der->buffer, der->length, NULL);
ret = ParseCertRelative(cert, type, 0, NULL, NULL);
@@ -5497,9 +5402,7 @@ static WOLFSSL_X509* loadX509orX509REQFromBuffer(
}
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, NULL, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, NULL, DYNAMIC_TYPE_DCERT);
}
FreeDer(&der);
@@ -7773,11 +7676,7 @@ static int x509AddCertDir(WOLFSSL_BY_DIR *ctx, const char *argc, long argl)
size_t pathLen;
int i, num;
const char* c;
#ifdef WOLFSSL_SMALL_STACK
char *buf;
#else
char buf[MAX_FILENAME_SZ];
#endif
WC_DECLARE_VAR(buf, char, MAX_FILENAME_SZ, 0);
WOLFSSL_ENTER("x509AddCertDir");
@@ -7821,9 +7720,7 @@ static int x509AddCertDir(WOLFSSL_BY_DIR *ctx, const char *argc, long argl)
if (ctx->dir_entry == NULL) {
WOLFSSL_MSG("failed to allocate dir_entry");
#ifdef WOLFSSL_SMALL_STACK
XFREE(buf, 0, DYNAMIC_TYPE_OPENSSL);
#endif
WC_FREE_VAR_EX(buf, 0, DYNAMIC_TYPE_OPENSSL);
return 0;
}
}
@@ -7831,9 +7728,7 @@ static int x509AddCertDir(WOLFSSL_BY_DIR *ctx, const char *argc, long argl)
entry = wolfSSL_BY_DIR_entry_new();
if (entry == NULL) {
WOLFSSL_MSG("failed to allocate dir entry");
#ifdef WOLFSSL_SMALL_STACK
XFREE(buf, 0, DYNAMIC_TYPE_OPENSSL);
#endif
WC_FREE_VAR_EX(buf, 0, DYNAMIC_TYPE_OPENSSL);
return 0;
}
entry->dir_type = (int)argl;
@@ -7843,9 +7738,7 @@ static int x509AddCertDir(WOLFSSL_BY_DIR *ctx, const char *argc, long argl)
if (entry->dir_name == NULL || entry->hashes == NULL) {
WOLFSSL_MSG("failed to allocate dir name");
wolfSSL_BY_DIR_entry_free(entry);
#ifdef WOLFSSL_SMALL_STACK
XFREE(buf, 0, DYNAMIC_TYPE_OPENSSL);
#endif
WC_FREE_VAR_EX(buf, 0, DYNAMIC_TYPE_OPENSSL);
return 0;
}
@@ -7854,9 +7747,7 @@ static int x509AddCertDir(WOLFSSL_BY_DIR *ctx, const char *argc, long argl)
if (wolfSSL_sk_BY_DIR_entry_push(ctx->dir_entry, entry) <= 0) {
wolfSSL_BY_DIR_entry_free(entry);
#ifdef WOLFSSL_SMALL_STACK
XFREE(buf, 0, DYNAMIC_TYPE_OPENSSL);
#endif
WC_FREE_VAR_EX(buf, 0, DYNAMIC_TYPE_OPENSSL);
return 0;
}
}
@@ -7870,9 +7761,7 @@ static int x509AddCertDir(WOLFSSL_BY_DIR *ctx, const char *argc, long argl)
} while(*c++ != '\0');
#ifdef WOLFSSL_SMALL_STACK
XFREE(buf, 0, DYNAMIC_TYPE_OPENSSL);
#endif
WC_FREE_VAR_EX(buf, 0, DYNAMIC_TYPE_OPENSSL);
return WOLFSSL_SUCCESS;
#else
@@ -7961,11 +7850,7 @@ static int loadX509orX509REQFromBio(WOLFSSL_BIO* bio, WOLFSSL_X509* x509,
int ret = WC_NO_ERR_TRACE(WOLFSSL_FAILURE);
/* Get large buffer to hold cert der */
int derSz = X509_BUFFER_SZ;
#ifdef WOLFSSL_SMALL_STACK
byte* der;
#else
byte der[X509_BUFFER_SZ];
#endif
WC_DECLARE_VAR(der, byte, X509_BUFFER_SZ, 0);
WOLFSSL_ENTER("wolfSSL_i2d_X509_bio");
if (bio == NULL || x509 == NULL) {
@@ -7990,9 +7875,7 @@ static int loadX509orX509REQFromBio(WOLFSSL_BIO* bio, WOLFSSL_X509* x509,
ret = WOLFSSL_SUCCESS;
cleanup:
#ifdef WOLFSSL_SMALL_STACK
XFREE(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -8988,9 +8871,7 @@ static int X509CRLPrintExtensions(WOLFSSL_BIO* bio, WOLFSSL_X509_CRL* crl,
mp_free(dec_num);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(dec_num, NULL, DYNAMIC_TYPE_BIGINT);
#endif
WC_FREE_VAR_EX(dec_num, NULL, DYNAMIC_TYPE_BIGINT);
}
#if !defined(NO_SKID)
@@ -11667,21 +11548,13 @@ int wolfSSL_i2d_X509_NAME_canon(WOLFSSL_X509_NAME* name, unsigned char** out)
{
int totalBytes = 0, i, idx;
byte *output, *local = NULL;
#ifdef WOLFSSL_SMALL_STACK
EncodedName* names = NULL;
#else
EncodedName names[MAX_NAME_ENTRIES];
#endif
WC_DECLARE_VAR(names, EncodedName, MAX_NAME_ENTRIES, 0);
if (name == NULL)
return BAD_FUNC_ARG;
#ifdef WOLFSSL_SMALL_STACK
names = (EncodedName*)XMALLOC(sizeof(EncodedName) * MAX_NAME_ENTRIES, NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (names == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(names, EncodedName, MAX_NAME_ENTRIES, NULL,
DYNAMIC_TYPE_TMP_BUFFER, return MEMORY_E);
XMEMSET(names, 0, sizeof(EncodedName) * MAX_NAME_ENTRIES);
@@ -11697,25 +11570,19 @@ int wolfSSL_i2d_X509_NAME_canon(WOLFSSL_X509_NAME* name, unsigned char** out)
cano_data = wolfSSL_ASN1_STRING_new();
if (cano_data == NULL) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(names, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(names, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return MEMORY_E;
}
data = wolfSSL_X509_NAME_ENTRY_get_data(entry);
if (data == NULL) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(names, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(names, NULL, DYNAMIC_TYPE_TMP_BUFFER);
wolfSSL_ASN1_STRING_free(cano_data);
WOLFSSL_MSG("Error getting entry data");
return WOLFSSL_FATAL_ERROR;
}
if (wolfSSL_ASN1_STRING_canon(cano_data, data) != WOLFSSL_SUCCESS) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(names, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(names, NULL, DYNAMIC_TYPE_TMP_BUFFER);
wolfSSL_ASN1_STRING_free(cano_data);
return WOLFSSL_FAILURE;
}
@@ -11724,9 +11591,7 @@ int wolfSSL_i2d_X509_NAME_canon(WOLFSSL_X509_NAME* name, unsigned char** out)
ret = wc_EncodeNameCanonical(&names[i], nameStr, CTC_UTF8,
(byte)ConvertNIDToWolfSSL(entry->nid));
if (ret < 0) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(names, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(names, NULL, DYNAMIC_TYPE_TMP_BUFFER);
wolfSSL_ASN1_STRING_free(cano_data);
WOLFSSL_MSG("EncodeName failed");
return WOLFSSL_FATAL_ERROR;
@@ -11738,9 +11603,7 @@ int wolfSSL_i2d_X509_NAME_canon(WOLFSSL_X509_NAME* name, unsigned char** out)
if (out == NULL) {
/* If out is NULL, caller just wants length. */
#ifdef WOLFSSL_SMALL_STACK
XFREE(names, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(names, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return totalBytes;
}
@@ -11763,9 +11626,7 @@ int wolfSSL_i2d_X509_NAME_canon(WOLFSSL_X509_NAME* name, unsigned char** out)
}
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(names, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(names, NULL, DYNAMIC_TYPE_TMP_BUFFER);
/* used existing buffer passed in, so increment pointer */
if (local == NULL) {
@@ -11802,21 +11663,13 @@ int wolfSSL_i2d_X509_NAME(WOLFSSL_X509_NAME* name, unsigned char** out)
int totalBytes = 0, i, idx;
byte temp[MAX_SEQ_SZ];
byte *output, *local = NULL;
#ifdef WOLFSSL_SMALL_STACK
EncodedName* names = NULL;
#else
EncodedName names[MAX_NAME_ENTRIES];
#endif
WC_DECLARE_VAR(names, EncodedName, MAX_NAME_ENTRIES, 0);
if (name == NULL)
return BAD_FUNC_ARG;
#ifdef WOLFSSL_SMALL_STACK
names = (EncodedName*)XMALLOC(sizeof(EncodedName) * MAX_NAME_ENTRIES, NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (names == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(names, EncodedName, MAX_NAME_ENTRIES, NULL,
DYNAMIC_TYPE_TMP_BUFFER, return MEMORY_E);
XMEMSET(names, 0, sizeof(EncodedName) * MAX_NAME_ENTRIES);
@@ -11832,9 +11685,7 @@ int wolfSSL_i2d_X509_NAME(WOLFSSL_X509_NAME* name, unsigned char** out)
data = wolfSSL_X509_NAME_ENTRY_get_data(entry);
if (data == NULL) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(names, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(names, NULL, DYNAMIC_TYPE_TMP_BUFFER);
WOLFSSL_MSG("Error getting entry data");
return WOLFSSL_FATAL_ERROR;
}
@@ -11858,9 +11709,7 @@ int wolfSSL_i2d_X509_NAME(WOLFSSL_X509_NAME* name, unsigned char** out)
ret = wc_EncodeName(&names[i], nameStr, (char)type,
(byte)ConvertNIDToWolfSSL(entry->nid));
if (ret < 0) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(names, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(names, NULL, DYNAMIC_TYPE_TMP_BUFFER);
WOLFSSL_MSG("EncodeName failed");
return WOLFSSL_FATAL_ERROR;
}
@@ -11871,9 +11720,7 @@ int wolfSSL_i2d_X509_NAME(WOLFSSL_X509_NAME* name, unsigned char** out)
/* header */
idx = (int)SetSequence((word32)totalBytes, temp);
if (totalBytes + idx > ASN_NAME_MAX) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(names, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(names, NULL, DYNAMIC_TYPE_TMP_BUFFER);
WOLFSSL_MSG("Total Bytes is greater than ASN_NAME_MAX");
return BUFFER_E;
}
@@ -11881,9 +11728,7 @@ int wolfSSL_i2d_X509_NAME(WOLFSSL_X509_NAME* name, unsigned char** out)
if (out == NULL) {
/* If out is NULL, caller just wants length. */
totalBytes += idx;
#ifdef WOLFSSL_SMALL_STACK
XFREE(names, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(names, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return totalBytes;
}
@@ -11906,9 +11751,7 @@ int wolfSSL_i2d_X509_NAME(WOLFSSL_X509_NAME* name, unsigned char** out)
}
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(names, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(names, NULL, DYNAMIC_TYPE_TMP_BUFFER);
/* used existing buffer passed in, so increment pointer */
if (local == NULL) {
@@ -11926,11 +11769,7 @@ int wolfSSL_i2d_X509_NAME(WOLFSSL_X509_NAME* name, unsigned char** out)
unsigned char **in, long length)
{
WOLFSSL_X509_NAME* tmp = NULL;
#ifdef WOLFSSL_SMALL_STACK
DecodedCert* cert = NULL;
#else
DecodedCert cert[1];
#endif
WC_DECLARE_VAR(cert, DecodedCert, 1, 0);
WOLFSSL_ENTER("wolfSSL_d2i_X509_NAME");
@@ -11939,13 +11778,8 @@ int wolfSSL_i2d_X509_NAME(WOLFSSL_X509_NAME* name, unsigned char** out)
return NULL;
}
#ifdef WOLFSSL_SMALL_STACK
cert = (DecodedCert*)XMALLOC(sizeof(DecodedCert), NULL,
DYNAMIC_TYPE_DCERT);
if (cert == NULL) {
return NULL;
}
#endif
WC_ALLOC_VAR_EX(cert, DecodedCert, 1, NULL, DYNAMIC_TYPE_DCERT,
return NULL);
/* Set the X509_NAME buffer as the input data for cert.
* in is NOT a full certificate. Just the name. */
@@ -11973,9 +11807,7 @@ int wolfSSL_i2d_X509_NAME(WOLFSSL_X509_NAME* name, unsigned char** out)
*name = tmp;
cleanup:
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, NULL, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, NULL, DYNAMIC_TYPE_DCERT);
return tmp;
}
#endif /* OPENSSL_EXTRA || OPENSSL_ALL || WOLFSSL_WPAS_SMALL */
@@ -14253,11 +14085,7 @@ int wolfSSL_X509_check_host(WOLFSSL_X509 *x, const char *chk, size_t chklen,
{
int ret;
size_t i;
#ifdef WOLFSSL_SMALL_STACK
DecodedCert *dCert;
#else
DecodedCert dCert[1];
#endif
WC_DECLARE_VAR(dCert, DecodedCert, 1, 0);
WOLFSSL_ENTER("wolfSSL_X509_check_host");
@@ -14318,9 +14146,7 @@ int wolfSSL_X509_check_host(WOLFSSL_X509 *x, const char *chk, size_t chklen,
out:
FreeDecodedCert(dCert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(dCert, x->heap, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(dCert, x->heap, DYNAMIC_TYPE_DCERT);
if (ret != 0)
return WOLFSSL_FAILURE;
@@ -14332,11 +14158,7 @@ int wolfSSL_X509_check_ip_asc(WOLFSSL_X509 *x, const char *ipasc,
unsigned int flags)
{
int ret = WC_NO_ERR_TRACE(WOLFSSL_FAILURE);
#ifdef WOLFSSL_SMALL_STACK
DecodedCert *dCert = NULL;
#else
DecodedCert dCert[1];
#endif
WC_DECLARE_VAR(dCert, DecodedCert, 1, 0);
WOLFSSL_ENTER("wolfSSL_X509_check_ip_asc");
@@ -15054,11 +14876,7 @@ int wolfSSL_X509_REQ_sign(WOLFSSL_X509 *req, WOLFSSL_EVP_PKEY *pkey,
const WOLFSSL_EVP_MD *md)
{
int ret;
#ifdef WOLFSSL_SMALL_STACK
byte* der = NULL;
#else
byte der[2048];
#endif
WC_DECLARE_VAR(der, byte, 2048, 0);
int derSz = 2048;
if (req == NULL || pkey == NULL || md == NULL) {
@@ -15066,20 +14884,14 @@ int wolfSSL_X509_REQ_sign(WOLFSSL_X509 *req, WOLFSSL_EVP_PKEY *pkey,
return WOLFSSL_FAILURE;
}
#ifdef WOLFSSL_SMALL_STACK
der = (byte*)XMALLOC(derSz, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (der == NULL) {
return WOLFSSL_FAILURE;
}
#endif
WC_ALLOC_VAR_EX(der, byte, derSz, NULL, DYNAMIC_TYPE_TMP_BUFFER,
return WOLFSSL_FAILURE);
/* Create a Cert that has the certificate request fields. */
req->sigOID = wolfSSL_sigTypeFromPKEY((WOLFSSL_EVP_MD*)md, pkey);
ret = wolfssl_x509_make_der(req, 1, der, &derSz, 0);
if (ret != WOLFSSL_SUCCESS) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
WOLFSSL_MSG("Unable to make DER for X509");
WOLFSSL_LEAVE("wolfSSL_X509_REQ_sign", ret);
return WOLFSSL_FAILURE;
@@ -15087,14 +14899,10 @@ int wolfSSL_X509_REQ_sign(WOLFSSL_X509 *req, WOLFSSL_EVP_PKEY *pkey,
if (wolfSSL_X509_resign_cert(req, 1, der, 2048, derSz,
(WOLFSSL_EVP_MD*)md, pkey) <= 0) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return WOLFSSL_FAILURE;
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return WOLFSSL_SUCCESS;
}
@@ -15138,9 +14946,7 @@ static int regenX509REQDerBuffer(WOLFSSL_X509* x509)
else {
WOLFSSL_MSG("Unable to make DER for X509 REQ");
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(der, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -15767,11 +15573,7 @@ WOLFSSL_X509_ACERT * wolfSSL_X509_ACERT_load_certificate_buffer_ex(
int ret = 0;
WOLFSSL_X509_ACERT * x509 = NULL;
DerBuffer * der = NULL;
#ifdef WOLFSSL_SMALL_STACK
DecodedAcert * acert = NULL;
#else
DecodedAcert acert[1];
#endif
WC_DECLARE_VAR(acert, DecodedAcert, 1, 0);
WOLFSSL_ENTER("wolfSSL_X509_ACERT_load_certificate_buffer");
@@ -15836,9 +15638,7 @@ WOLFSSL_X509_ACERT * wolfSSL_X509_ACERT_load_certificate_buffer_ex(
FreeDecodedAcert(acert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(acert, heap, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(acert, heap, DYNAMIC_TYPE_DCERT);
FreeDer(&der);
+6 -21
View File
@@ -125,11 +125,7 @@ static int x509GetIssuerFromCM(WOLFSSL_X509 **issuer, WOLFSSL_CERT_MANAGER* cm,
WOLFSSL_X509 *x)
{
Signer* ca = NULL;
#ifdef WOLFSSL_SMALL_STACK
DecodedCert* cert = NULL;
#else
DecodedCert cert[1];
#endif
WC_DECLARE_VAR(cert, DecodedCert, 1, 0);
if (cm == NULL || x == NULL || x->derCert == NULL) {
WOLFSSL_MSG("No cert DER buffer or NULL cm. Defining "
@@ -137,11 +133,8 @@ static int x509GetIssuerFromCM(WOLFSSL_X509 **issuer, WOLFSSL_CERT_MANAGER* cm,
return WOLFSSL_FAILURE;
}
#ifdef WOLFSSL_SMALL_STACK
cert = (DecodedCert*)XMALLOC(sizeof(DecodedCert), NULL, DYNAMIC_TYPE_DCERT);
if (cert == NULL)
return WOLFSSL_FAILURE;
#endif
WC_ALLOC_VAR_EX(cert, DecodedCert, 1, NULL, DYNAMIC_TYPE_DCERT,
return WOLFSSL_FAILURE);
/* Use existing CA retrieval APIs that use DecodedCert. */
InitDecodedCert(cert, x->derCert->buffer, x->derCert->length, cm->heap);
@@ -157,9 +150,7 @@ static int x509GetIssuerFromCM(WOLFSSL_X509 **issuer, WOLFSSL_CERT_MANAGER* cm,
#endif /* NO SKID */
}
FreeDecodedCert(cert);
#ifdef WOLFSSL_SMALL_STACK
XFREE(cert, NULL, DYNAMIC_TYPE_DCERT);
#endif
WC_FREE_VAR_EX(cert, NULL, DYNAMIC_TYPE_DCERT);
if (ca == NULL)
return WOLFSSL_FAILURE;
@@ -1669,11 +1660,7 @@ int wolfSSL_X509_STORE_load_locations(WOLFSSL_X509_STORE *str,
WOLFSSL_CTX* ctx;
char *name = NULL;
int ret = WOLFSSL_SUCCESS;
#ifdef WOLFSSL_SMALL_STACK
ReadDirCtx* readCtx = NULL;
#else
ReadDirCtx readCtx[1];
#endif
WC_DECLARE_VAR(readCtx, ReadDirCtx, 1, 0);
WOLFSSL_ENTER("wolfSSL_X509_STORE_load_locations");
@@ -1749,9 +1736,7 @@ int wolfSSL_X509_STORE_load_locations(WOLFSSL_X509_STORE *str,
ret = WOLFSSL_FAILURE;
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(readCtx, ctx->heap, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(readCtx, ctx->heap, DYNAMIC_TYPE_TMP_BUFFER);
}
ctx->cm = NULL;
+1 -5
View File
@@ -14495,11 +14495,7 @@ static int test_wolfSSL_X509_ACERT_asn(void)
0x65, 0x72, 0x2e, 0x65, 0x78,
0x61, 0x6d, 0x70, 0x6c, 0x65};
DerBuffer * der = NULL;
#ifdef WOLFSSL_SMALL_STACK
DecodedAcert * acert = NULL;
#else
DecodedAcert acert[1];
#endif
WC_DECLARE_VAR(acert, DecodedAcert, 1, 0);
rc = wc_PemToDer(acert_ietf, sizeof(acert_ietf), ACERT_TYPE, &der,
HEAP_HINT, NULL, NULL);
+4
View File
@@ -28,6 +28,10 @@
#include <wolfcrypt/src/misc.c>
#endif
#ifdef WOLFSSL_ASYNC_CRYPT
#define WOLFSSL_SMALL_STACK
#endif
#include <wolfssl/wolfcrypt/rsa.h>
#include <wolfssl/wolfcrypt/types.h>
#include <tests/api/api.h>
+5 -4
View File
@@ -69,6 +69,9 @@
/* Macro to disable benchmark */
#ifndef NO_CRYPT_BENCHMARK
#ifdef WOLFSSL_ASYNC_CRYPT
#define WOLFSSL_SMALL_STACK
#endif
#define WC_ALLOC_DO_ON_FAILURE() do { printf("out of memory at benchmark.c L %d\n", __LINE__); ret = MEMORY_E; goto exit; } while (0)
#include <wolfssl/wolfcrypt/types.h>
@@ -9912,10 +9915,8 @@ void bench_mlkem(int type)
wc_KyberKey_Free(key2);
wc_KyberKey_Free(key1);
#ifdef WOLFSSL_SMALL_STACK
XFREE(key1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(key1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(key2, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
}
#endif
+15 -59
View File
@@ -808,11 +808,7 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
const unsigned char* userKey, const int bits, Aes* aes)
{
word32 nr;
#ifdef WOLFSSL_SMALL_STACK
Aes *temp_key;
#else
Aes temp_key[1];
#endif
WC_DECLARE_VAR(temp_key, Aes, 1, 0);
__m128i *Key_Schedule;
__m128i *Temp_Key_Schedule;
@@ -829,9 +825,7 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
if (AES_set_encrypt_key_AESNI(userKey,bits,temp_key)
== WC_NO_ERR_TRACE(BAD_FUNC_ARG)) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(temp_key, aes->heap, DYNAMIC_TYPE_AES);
#endif
WC_FREE_VAR_EX(temp_key, aes->heap, DYNAMIC_TYPE_AES);
return BAD_FUNC_ARG;
}
@@ -864,9 +858,7 @@ block cipher mechanism that uses n-bit binary string parameter key with 128-bits
Key_Schedule[0] = Temp_Key_Schedule[nr];
#ifdef WOLFSSL_SMALL_STACK
XFREE(temp_key, aes->heap, DYNAMIC_TYPE_AES);
#endif
WC_FREE_VAR_EX(temp_key, aes->heap, DYNAMIC_TYPE_AES);
return 0;
}
@@ -11008,11 +11000,7 @@ int wc_Gmac(const byte* key, word32 keySz, byte* iv, word32 ivSz,
const byte* authIn, word32 authInSz,
byte* authTag, word32 authTagSz, WC_RNG* rng)
{
#ifdef WOLFSSL_SMALL_STACK
Aes *aes;
#else
Aes aes[1];
#endif
WC_DECLARE_VAR(aes, Aes, 1, 0);
int ret;
if (key == NULL || iv == NULL || (authIn == NULL && authInSz != 0) ||
@@ -11052,11 +11040,7 @@ int wc_GmacVerify(const byte* key, word32 keySz,
{
int ret;
#ifdef HAVE_AES_DECRYPT
#ifdef WOLFSSL_SMALL_STACK
Aes *aes = NULL;
#else
Aes aes[1];
#endif
WC_DECLARE_VAR(aes, Aes, 1, 0);
if (key == NULL || iv == NULL || (authIn == NULL && authInSz != 0) ||
authTag == NULL || authTagSz == 0 || authTagSz > WC_AES_BLOCK_SIZE) {
@@ -12865,11 +12849,7 @@ int wc_AesKeyWrap_ex(Aes *aes, const byte* in, word32 inSz, byte* out,
int wc_AesKeyWrap(const byte* key, word32 keySz, const byte* in, word32 inSz,
byte* out, word32 outSz, const byte* iv)
{
#ifdef WOLFSSL_SMALL_STACK
Aes *aes = NULL;
#else
Aes aes[1];
#endif
WC_DECLARE_VAR(aes, Aes, 1, 0);
int ret;
if (key == NULL)
@@ -12896,9 +12876,7 @@ int wc_AesKeyWrap(const byte* key, word32 keySz, const byte* in, word32 inSz,
wc_AesFree(aes);
out:
#ifdef WOLFSSL_SMALL_STACK
XFREE(aes, NULL, DYNAMIC_TYPE_AES);
#endif
WC_FREE_VAR_EX(aes, NULL, DYNAMIC_TYPE_AES);
return ret;
}
@@ -12980,11 +12958,7 @@ int wc_AesKeyUnWrap_ex(Aes *aes, const byte* in, word32 inSz, byte* out,
int wc_AesKeyUnWrap(const byte* key, word32 keySz, const byte* in, word32 inSz,
byte* out, word32 outSz, const byte* iv)
{
#ifdef WOLFSSL_SMALL_STACK
Aes *aes = NULL;
#else
Aes aes[1];
#endif
WC_DECLARE_VAR(aes, Aes, 1, 0);
int ret;
(void)iv;
@@ -13014,9 +12988,7 @@ int wc_AesKeyUnWrap(const byte* key, word32 keySz, const byte* in, word32 inSz,
wc_AesFree(aes);
out:
#ifdef WOLFSSL_SMALL_STACK
XFREE(aes, NULL, DYNAMIC_TYPE_AES);
#endif
WC_FREE_VAR_EX(aes, NULL, DYNAMIC_TYPE_AES);
return ret;
}
@@ -14434,13 +14406,9 @@ static WARN_UNUSED_RESULT int S2V(
if (ret == 0) {
if (dataSz >= WC_AES_BLOCK_SIZE) {
#ifdef WOLFSSL_SMALL_STACK
cmac = (Cmac*)XMALLOC(sizeof(Cmac), NULL, DYNAMIC_TYPE_CMAC);
if (cmac == NULL) {
ret = MEMORY_E;
}
if (ret == 0)
#endif
WC_ALLOC_VAR_EX(cmac, Cmac, 1, NULL, DYNAMIC_TYPE_CMAC,
ret=MEMORY_E);
if (WC_VAR_OK(cmac))
{
#ifdef WOLFSSL_CHECK_MEM_ZERO
/* Aes part is checked by wc_AesFree. */
@@ -14499,11 +14467,7 @@ static WARN_UNUSED_RESULT int AesSivCipher(
int enc)
{
int ret = 0;
#ifdef WOLFSSL_SMALL_STACK
Aes* aes = NULL;
#else
Aes aes[1];
#endif
WC_DECLARE_VAR(aes, Aes, 1, 0);
byte sivTmp[WC_AES_BLOCK_SIZE];
if (key == NULL || siv == NULL || out == NULL) {
@@ -15155,11 +15119,7 @@ int wc_AesCtsEncrypt(const byte* key, word32 keySz, byte* out,
const byte* in, word32 inSz,
const byte* iv)
{
#ifdef WOLFSSL_SMALL_STACK
Aes *aes = NULL;
#else
Aes aes[1];
#endif
WC_DECLARE_VAR(aes, Aes, 1, 0);
int ret = 0;
word32 outSz = inSz;
@@ -15193,11 +15153,7 @@ int wc_AesCtsDecrypt(const byte* key, word32 keySz, byte* out,
const byte* in, word32 inSz,
const byte* iv)
{
#ifdef WOLFSSL_SMALL_STACK
Aes *aes = NULL;
#else
Aes aes[1];
#endif
WC_DECLARE_VAR(aes, Aes, 1, 0);
int ret = 0;
word32 outSz = inSz;
+158 -434
View File
File diff suppressed because it is too large Load Diff
+3 -9
View File
@@ -198,9 +198,7 @@ int blake2b_init_key( blake2b_state *S, const byte outlen, const void *key,
secure_zero_memory( block, BLAKE2B_BLOCKBYTES ); /* Burn the key from */
/* memory */
#ifdef WOLFSSL_SMALL_STACK
XFREE(block, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(block, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
return ret;
}
@@ -319,9 +317,7 @@ int blake2b_update( blake2b_state *S, const byte *in, word64 inlen )
}
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(m, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(m, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -377,9 +373,7 @@ int blake2b_final( blake2b_state *S, byte *out, byte outlen )
out:
#ifdef WOLFSSL_SMALL_STACK
XFREE(m, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(m, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
+3 -9
View File
@@ -194,9 +194,7 @@ int blake2s_init_key( blake2s_state *S, const byte outlen, const void *key,
secure_zero_memory( block, BLAKE2S_BLOCKBYTES ); /* Burn the key from */
/* memory */
#ifdef WOLFSSL_SMALL_STACK
XFREE(block, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(block, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
return ret;
}
@@ -313,9 +311,7 @@ int blake2s_update( blake2s_state *S, const byte *in, word32 inlen )
}
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(m, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(m, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -369,9 +365,7 @@ int blake2s_final( blake2s_state *S, byte *out, byte outlen )
out:
#ifdef WOLFSSL_SMALL_STACK
XFREE(m, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(m, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
+4 -8
View File
@@ -704,10 +704,8 @@ static int camellia_setup128(const unsigned char *key, u32 *subkey)
dw = CamelliaSubkeyL(23) ^ CamelliaSubkeyR(23), dw = CAMELLIA_RL8(dw);
CamelliaSubkeyR(23) = CamelliaSubkeyL(23) ^ dw, CamelliaSubkeyL(23) = dw;
#ifdef WOLFSSL_SMALL_STACK
XFREE(subL, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(subR, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(subL, NULL, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(subR, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return 0;
}
@@ -1011,10 +1009,8 @@ static int camellia_setup256(const unsigned char *key, u32 *subkey)
dw = CamelliaSubkeyL(31) ^ CamelliaSubkeyR(31), dw = CAMELLIA_RL8(dw);
CamelliaSubkeyR(31) = CamelliaSubkeyL(31) ^ dw,CamelliaSubkeyL(31) = dw;
#ifdef WOLFSSL_SMALL_STACK
XFREE(subL, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(subR, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(subL, NULL, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(subR, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return 0;
}
+8 -28
View File
@@ -51,11 +51,7 @@ int wc_ChaCha20Poly1305_Encrypt(
byte outAuthTag[CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE])
{
int ret;
#ifdef WOLFSSL_SMALL_STACK
ChaChaPoly_Aead *aead = NULL;
#else
ChaChaPoly_Aead aead[1];
#endif
WC_DECLARE_VAR(aead, ChaChaPoly_Aead, 1, 0);
/* Validate function arguments */
if (!inKey || !inIV ||
@@ -66,12 +62,8 @@ int wc_ChaCha20Poly1305_Encrypt(
return BAD_FUNC_ARG;
}
#ifdef WOLFSSL_SMALL_STACK
aead = (ChaChaPoly_Aead *)XMALLOC(sizeof(*aead), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (aead == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(aead, ChaChaPoly_Aead, 1, NULL, DYNAMIC_TYPE_TMP_BUFFER,
return MEMORY_E);
ret = wc_ChaCha20Poly1305_Init(aead, inKey, inIV,
CHACHA20_POLY1305_AEAD_ENCRYPT);
@@ -83,9 +75,7 @@ int wc_ChaCha20Poly1305_Encrypt(
if (ret == 0)
ret = wc_ChaCha20Poly1305_Final(aead, outAuthTag);
#ifdef WOLFSSL_SMALL_STACK
XFREE(aead, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(aead, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -100,11 +90,7 @@ int wc_ChaCha20Poly1305_Decrypt(
byte* outPlaintext)
{
int ret;
#ifdef WOLFSSL_SMALL_STACK
ChaChaPoly_Aead *aead = NULL;
#else
ChaChaPoly_Aead aead[1];
#endif
WC_DECLARE_VAR(aead, ChaChaPoly_Aead, 1, 0);
byte calculatedAuthTag[CHACHA20_POLY1305_AEAD_AUTHTAG_SIZE];
/* Validate function arguments */
@@ -116,12 +102,8 @@ int wc_ChaCha20Poly1305_Decrypt(
return BAD_FUNC_ARG;
}
#ifdef WOLFSSL_SMALL_STACK
aead = (ChaChaPoly_Aead *)XMALLOC(sizeof(*aead), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (aead == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(aead, ChaChaPoly_Aead, 1, NULL, DYNAMIC_TYPE_TMP_BUFFER,
return MEMORY_E);
XMEMSET(calculatedAuthTag, 0, sizeof(calculatedAuthTag));
@@ -137,9 +119,7 @@ int wc_ChaCha20Poly1305_Decrypt(
if (ret == 0)
ret = wc_ChaCha20Poly1305_CheckTag(inAuthTag, calculatedAuthTag);
#ifdef WOLFSSL_SMALL_STACK
XFREE(aead, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(aead, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
+2 -10
View File
@@ -418,11 +418,7 @@ int wc_AesCmacGenerate(byte* out, word32* outSz,
const byte* key, word32 keySz)
{
int ret = 0;
#ifdef WOLFSSL_SMALL_STACK
Cmac *cmac;
#else
Cmac cmac[1];
#endif
WC_DECLARE_VAR(cmac, Cmac, 1, 0);
if (out == NULL || (in == NULL && inSz > 0) || key == NULL || keySz == 0) {
return BAD_FUNC_ARG;
@@ -498,11 +494,7 @@ int wc_AesCmacVerify(const byte* check, word32 checkSz,
const byte* key, word32 keySz)
{
int ret = 0;
#ifdef WOLFSSL_SMALL_STACK
Cmac *cmac;
#else
Cmac cmac[1];
#endif
WC_DECLARE_VAR(cmac, Cmac, 1, 0);
if (check == NULL || checkSz == 0 || (in == NULL && inSz > 0) ||
key == NULL || keySz == 0) {
+1 -3
View File
@@ -1591,9 +1591,7 @@
}
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(buffer, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(buffer, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
return 0;
+23 -51
View File
@@ -2757,10 +2757,8 @@ static int wc_mldsa_gen_matrix_4x4_avx2(sword32* a, byte* seed)
a += 4 * MLDSA_N;
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(rand, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(rand, NULL, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return 0;
}
@@ -2904,10 +2902,8 @@ static int wc_mldsa_gen_matrix_6x5_avx2(sword32* a, byte* seed)
MLDSA_N - ctr1, p, SHA3_128_BYTES);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(rand, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(rand, NULL, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return 0;
}
@@ -3013,10 +3009,8 @@ static int wc_mldsa_gen_matrix_8x7_avx2(sword32* a, byte* seed)
a += 4 * MLDSA_N;
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(rand, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(rand, NULL, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return 0;
}
@@ -3625,10 +3619,8 @@ static int wc_mldsa_gen_s_4_4_avx2(sword32* s[2], byte* seed)
(ctr3 < MLDSA_N));
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(rand, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(rand, NULL, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return 0;
}
@@ -3780,10 +3772,8 @@ static int wc_mldsa_gen_s_5_6_avx2(sword32* s[2], byte* seed)
/* Create more blocks if too many rejected. */
while ((ctr0 < MLDSA_N) || (ctr1 < MLDSA_N) || (ctr2 < MLDSA_N));
#ifdef WOLFSSL_SMALL_STACK
XFREE(rand, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(rand, NULL, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return 0;
}
@@ -3937,10 +3927,8 @@ static int wc_mldsa_gen_s_7_8_avx2(sword32* s[2], byte* seed)
/* Create more blocks if too many rejected. */
while ((ctr0 < MLDSA_N) || (ctr1 < MLDSA_N) || (ctr2 < MLDSA_N));
#ifdef WOLFSSL_SMALL_STACK
XFREE(rand, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(rand, NULL, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return 0;
}
@@ -4124,10 +4112,8 @@ static int wc_mldsa_gen_y_4_avx2(sword32* y, byte* seed, word16 kappa)
wc_mldsa_decode_gamma1_17_avx2(rand + 3 * DILITHIUM_MAX_V,
y + 3 * DILITHIUM_N);
#ifdef WOLFSSL_SMALL_STACK
XFREE(rand, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(rand, NULL, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return 0;
}
@@ -4206,10 +4192,8 @@ static int wc_mldsa_gen_y_5_avx2(sword32* y, byte* seed, word16 kappa,
wc_mldsa_decode_gamma1_19_avx2(rand, y + 4 * DILITHIUM_N);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(rand, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(rand, NULL, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -4303,10 +4287,8 @@ static int wc_mldsa_gen_y_7_avx2(sword32* y, byte* seed, word16 kappa)
wc_mldsa_decode_gamma1_19_avx2(rand + 2 * DILITHIUM_MAX_V,
y + 6 * DILITHIUM_N);
#ifdef WOLFSSL_SMALL_STACK
XFREE(rand, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(rand, NULL, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return 0;
}
@@ -8256,11 +8238,7 @@ static int dilithium_sign_with_seed_mu(dilithium_key* key,
/* Step 11: Start rejection sampling loop */
do {
#ifdef WOLFSSL_SMALL_STACK
byte *w1e = NULL;
#else
byte w1e[DILITHIUM_MAX_W1_ENC_SZ];
#endif
WC_DECLARE_VAR(w1e, byte, DILITHIUM_MAX_W1_ENC_SZ, 0);
sword32* w = w1;
sword32* y_ntt = z;
sword32* cs2 = ct0;
@@ -8290,13 +8268,9 @@ static int dilithium_sign_with_seed_mu(dilithium_key* key,
if (valid) {
#endif
/* Step 15: Encode w1. */
#ifdef WOLFSSL_SMALL_STACK
w1e = (byte *)XMALLOC(DILITHIUM_MAX_W1_ENC_SZ, key->heap,
DYNAMIC_TYPE_DILITHIUM);
if (w1e == NULL)
ret = MEMORY_E;
if (ret == 0)
#endif
WC_ALLOC_VAR_EX(w1e, byte, DILITHIUM_MAX_W1_ENC_SZ, key->heap,
DYNAMIC_TYPE_DILITHIUM, ret=MEMORY_E);
if (WC_VAR_OK(w1e))
{
dilithium_vec_encode_w1(w1, params->k, params->gamma2, w1e);
/* Step 15: Hash mu and encoded w1.
@@ -8365,9 +8339,7 @@ static int dilithium_sign_with_seed_mu(dilithium_key* key,
}
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(w1e, key->heap, DYNAMIC_TYPE_DILITHIUM);
#endif
WC_FREE_VAR_EX(w1e, key->heap, DYNAMIC_TYPE_DILITHIUM);
}
if (!valid) {
+83 -244
View File
@@ -1539,18 +1539,13 @@ static int xil_mpi_import(mp_int *mpi,
return BUFFER_E;
#endif
#ifdef WOLFSSL_SMALL_STACK
buf = (byte*)XMALLOC(len, heap, DYNAMIC_TYPE_PRIVATE_KEY);
if (buf == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(buf, byte, len, heap, DYNAMIC_TYPE_PRIVATE_KEY,
return MEMORY_E);
buf_reverse(buf, inbuf, len);
err = mp_read_unsigned_bin(mpi, buf, len);
ForceZero(buf, len);
#ifdef WOLFSSL_SMALL_STACK
XFREE(buf, heap, DYNAMIC_TYPE_PRIVATE_KEY);
#endif
WC_FREE_VAR_EX(buf, heap, DYNAMIC_TYPE_PRIVATE_KEY);
return err;
}
#endif
@@ -3178,21 +3173,12 @@ static int ecc_mulmod(const mp_int* k, ecc_point* P, ecc_point* Q,
#ifndef WC_NO_CACHE_RESISTANT
/* First bit always 1 (fix at end) and swap equals first bit */
int swap = 1;
#ifdef WOLFSSL_SMALL_STACK
mp_int* tmp = NULL;
#else
mp_int tmp[1];
#endif
WC_DECLARE_VAR(tmp, mp_int, 1, 0);
#endif
int infinity;
#ifndef WC_NO_CACHE_RESISTANT
#ifdef WOLFSSL_SMALL_STACK
tmp = (mp_int*)XMALLOC(sizeof(mp_int), NULL, DYNAMIC_TYPE_ECC);
if (tmp == NULL) {
err = MEMORY_E;
}
#endif
WC_ALLOC_VAR_EX(tmp, mp_int, 1, NULL, DYNAMIC_TYPE_ECC, err=MEMORY_E);
if (err == MP_OKAY)
err = mp_init(tmp);
#endif
@@ -4392,10 +4378,8 @@ static int wc_ecc_cmp_param(const char* curveParam,
#endif
if ((err = mp_init_multi(a, b, NULL, NULL, NULL, NULL)) != MP_OKAY) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(a, NULL, DYNAMIC_TYPE_ECC);
XFREE(b, NULL, DYNAMIC_TYPE_ECC);
#endif
WC_FREE_VAR_EX(a, NULL, DYNAMIC_TYPE_ECC);
WC_FREE_VAR_EX(b, NULL, DYNAMIC_TYPE_ECC);
return err;
}
@@ -4415,10 +4399,8 @@ static int wc_ecc_cmp_param(const char* curveParam,
mp_clear(a);
mp_clear(b);
#ifdef WOLFSSL_SMALL_STACK
XFREE(b, NULL, DYNAMIC_TYPE_ECC);
XFREE(a, NULL, DYNAMIC_TYPE_ECC);
#endif
WC_FREE_VAR_EX(b, NULL, DYNAMIC_TYPE_ECC);
WC_FREE_VAR_EX(a, NULL, DYNAMIC_TYPE_ECC);
return err;
}
@@ -4765,11 +4747,7 @@ int wc_ecc_shared_secret_gen_sync(ecc_key* private_key, ecc_point* point,
int err = MP_OKAY;
mp_int* k = ecc_get_k(private_key);
#ifdef HAVE_ECC_CDH
#ifdef WOLFSSL_SMALL_STACK
mp_int *k_lcl = NULL;
#else
mp_int k_lcl[1];
#endif
WC_DECLARE_VAR(k_lcl, mp_int, 1, 0);
#endif
#if defined(WOLFSSL_HAVE_SP_ECC) && defined(WC_ECC_NONBLOCK) && \
defined(WC_ECC_NONBLOCK_ONLY)
@@ -4991,9 +4969,7 @@ int wc_ecc_shared_secret_gen_sync(ecc_key* private_key, ecc_point* point,
#ifdef HAVE_ECC_CDH
if (k == k_lcl)
mp_clear(k);
#ifdef WOLFSSL_SMALL_STACK
XFREE(k_lcl, private_key->heap, DYNAMIC_TYPE_ECC_BUFFER);
#endif
WC_FREE_VAR_EX(k_lcl, private_key->heap, DYNAMIC_TYPE_ECC_BUFFER);
#endif
return err;
@@ -6578,10 +6554,8 @@ static int wc_ecc_sign_hash_hw(const byte* in, word32 inlen,
error_out:
ForceZero(K, MAX_ECC_BYTES);
#ifdef WOLFSSL_SMALL_STACK
XFREE(incopy, key->heap, DYNAMIC_TYPE_HASH_TMP);
XFREE(K, key->heap, DYNAMIC_TYPE_PRIVATE_KEY);
#endif
WC_FREE_VAR_EX(incopy, key->heap, DYNAMIC_TYPE_HASH_TMP);
WC_FREE_VAR_EX(K, key->heap, DYNAMIC_TYPE_PRIVATE_KEY);
if (err) {
ForceZero(out, keysize * 2);
return err;
@@ -7469,27 +7443,18 @@ int wc_ecc_sign_hash_ex(const byte* in, word32 inlen, WC_RNG* rng,
#endif /* WOLFSSL_ASYNC_CRYPT && WC_ASYNC_ENABLE_ECC */
if (err == MP_OKAY) {
#ifdef WOLFSSL_SMALL_STACK
ecc_key* pubkey;
#else
ecc_key pubkey[1];
#endif
WC_DECLARE_VAR(pubkey, ecc_key, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
pubkey = (ecc_key*)XMALLOC(sizeof(ecc_key), key->heap, DYNAMIC_TYPE_ECC);
if (pubkey == NULL)
err = MEMORY_E;
else
#endif
WC_ALLOC_VAR_EX(pubkey, ecc_key, 1, key->heap, DYNAMIC_TYPE_ECC,
err=MEMORY_E);
if (WC_VAR_OK(pubkey))
{
/* don't use async for key, since we don't support async return here */
err = wc_ecc_init_ex(pubkey, key->heap, INVALID_DEVID);
if (err == MP_OKAY) {
err = ecc_sign_hash_sw(key, pubkey, rng, curve, e, r, s);
wc_ecc_free(pubkey);
#ifdef WOLFSSL_SMALL_STACK
XFREE(pubkey, key->heap, DYNAMIC_TYPE_ECC);
#endif
WC_FREE_VAR_EX(pubkey, key->heap, DYNAMIC_TYPE_ECC);
}
}
}
@@ -8470,9 +8435,7 @@ int ecc_mul2add(ecc_point* A, mp_int* kA,
XFREE(key, heap, DYNAMIC_TYPE_ECC_BUFFER);
C->key = NULL;
#endif
#ifdef WOLFSSL_SMALL_STACK
XFREE(precomp, heap, DYNAMIC_TYPE_ECC_BUFFER);
#endif
WC_FREE_VAR_EX(precomp, heap, DYNAMIC_TYPE_ECC_BUFFER);
#ifndef WOLFSSL_NO_MALLOC
XFREE(tB, heap, DYNAMIC_TYPE_ECC_BUFFER);
XFREE(tA, heap, DYNAMIC_TYPE_ECC_BUFFER);
@@ -9629,10 +9592,8 @@ int wc_ecc_import_point_der_ex(const byte* in, word32 inLen,
mp_clear(t1);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(t1, NULL, DYNAMIC_TYPE_BIGINT);
XFREE(t2, NULL, DYNAMIC_TYPE_BIGINT);
#endif
WC_FREE_VAR_EX(t1, NULL, DYNAMIC_TYPE_BIGINT);
WC_FREE_VAR_EX(t2, NULL, DYNAMIC_TYPE_BIGINT);
wc_ecc_curve_free(curve);
FREE_CURVE_SPECS();
@@ -9694,11 +9655,7 @@ int wc_ecc_export_point_der(const int curve_idx, ecc_point* point, byte* out,
{
int ret = MP_OKAY;
word32 numlen;
#ifdef WOLFSSL_SMALL_STACK
byte* buf;
#else
byte buf[ECC_BUFSIZE];
#endif
WC_DECLARE_VAR(buf, byte, ECC_BUFSIZE, 0);
if ((curve_idx < 0) || (wc_ecc_is_valid_idx(curve_idx) == 0))
return ECC_BAD_ARG_E;
@@ -9728,11 +9685,8 @@ int wc_ecc_export_point_der(const int curve_idx, ecc_point* point, byte* out,
/* store byte point type */
out[0] = ECC_POINT_UNCOMP;
#ifdef WOLFSSL_SMALL_STACK
buf = (byte*)XMALLOC(ECC_BUFSIZE, NULL, DYNAMIC_TYPE_ECC_BUFFER);
if (buf == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(buf, byte, ECC_BUFSIZE, NULL, DYNAMIC_TYPE_ECC_BUFFER,
return MEMORY_E);
/* pad and store x */
XMEMSET(buf, 0, ECC_BUFSIZE);
@@ -9753,9 +9707,7 @@ int wc_ecc_export_point_der(const int curve_idx, ecc_point* point, byte* out,
*outLen = 1 + 2*numlen;
done:
#ifdef WOLFSSL_SMALL_STACK
XFREE(buf, NULL, DYNAMIC_TYPE_ECC_BUFFER);
#endif
WC_FREE_VAR_EX(buf, NULL, DYNAMIC_TYPE_ECC_BUFFER);
return ret;
}
@@ -9769,11 +9721,7 @@ int wc_ecc_export_point_der_compressed(const int curve_idx, ecc_point* point,
int ret = MP_OKAY;
word32 numlen;
word32 output_len;
#ifdef WOLFSSL_SMALL_STACK
byte* buf;
#else
byte buf[ECC_BUFSIZE];
#endif
WC_DECLARE_VAR(buf, byte, ECC_BUFSIZE, 0);
if ((curve_idx < 0) || (wc_ecc_is_valid_idx(curve_idx) == 0))
return ECC_BAD_ARG_E;
@@ -9805,11 +9753,8 @@ int wc_ecc_export_point_der_compressed(const int curve_idx, ecc_point* point,
out[0] = mp_isodd(point->y) == MP_YES ? ECC_POINT_COMP_ODD :
ECC_POINT_COMP_EVEN;
#ifdef WOLFSSL_SMALL_STACK
buf = (byte*)XMALLOC(ECC_BUFSIZE, NULL, DYNAMIC_TYPE_ECC_BUFFER);
if (buf == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(buf, byte, ECC_BUFSIZE, NULL, DYNAMIC_TYPE_ECC_BUFFER,
return MEMORY_E);
/* pad and store x */
XMEMSET(buf, 0, ECC_BUFSIZE);
@@ -9822,9 +9767,7 @@ int wc_ecc_export_point_der_compressed(const int curve_idx, ecc_point* point,
*outLen = output_len;
done:
#ifdef WOLFSSL_SMALL_STACK
XFREE(buf, NULL, DYNAMIC_TYPE_ECC_BUFFER);
#endif
WC_FREE_VAR_EX(buf, NULL, DYNAMIC_TYPE_ECC_BUFFER);
return ret;
}
@@ -9836,11 +9779,7 @@ int wc_ecc_export_x963(ecc_key* key, byte* out, word32* outLen)
{
int ret = MP_OKAY;
word32 numlen;
#ifdef WOLFSSL_SMALL_STACK
byte* buf;
#else
byte buf[ECC_BUFSIZE];
#endif
WC_DECLARE_VAR(buf, byte, ECC_BUFSIZE, 0);
word32 pubxlen, pubylen;
/* return length needed only */
@@ -9896,11 +9835,8 @@ int wc_ecc_export_x963(ecc_key* key, byte* out, word32* outLen)
/* store byte point type */
out[0] = ECC_POINT_UNCOMP;
#ifdef WOLFSSL_SMALL_STACK
buf = (byte*)XMALLOC(ECC_BUFSIZE, NULL, DYNAMIC_TYPE_ECC_BUFFER);
if (buf == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(buf, byte, ECC_BUFSIZE, NULL, DYNAMIC_TYPE_ECC_BUFFER,
return MEMORY_E);
/* pad and store x */
XMEMSET(buf, 0, ECC_BUFSIZE);
@@ -9919,9 +9855,7 @@ int wc_ecc_export_x963(ecc_key* key, byte* out, word32* outLen)
*outLen = 1 + 2*numlen;
done:
#ifdef WOLFSSL_SMALL_STACK
XFREE(buf, NULL, DYNAMIC_TYPE_ECC_BUFFER);
#endif
WC_FREE_VAR_EX(buf, NULL, DYNAMIC_TYPE_ECC_BUFFER);
return ret;
}
@@ -9971,10 +9905,8 @@ static int _ecc_is_point(ecc_point* ecp, mp_int* a, mp_int* b, mp_int* prime)
#endif
if ((err = mp_init_multi(t1, t2, NULL, NULL, NULL, NULL)) != MP_OKAY) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(t2, NULL, DYNAMIC_TYPE_ECC);
XFREE(t1, NULL, DYNAMIC_TYPE_ECC);
#endif
WC_FREE_VAR_EX(t2, NULL, DYNAMIC_TYPE_ECC);
WC_FREE_VAR_EX(t1, NULL, DYNAMIC_TYPE_ECC);
return err;
}
@@ -10050,10 +9982,8 @@ static int _ecc_is_point(ecc_point* ecp, mp_int* a, mp_int* b, mp_int* prime)
RESTORE_VECTOR_REGISTERS();
#ifdef WOLFSSL_SMALL_STACK
XFREE(t2, NULL, DYNAMIC_TYPE_ECC);
XFREE(t1, NULL, DYNAMIC_TYPE_ECC);
#endif
WC_FREE_VAR_EX(t2, NULL, DYNAMIC_TYPE_ECC);
WC_FREE_VAR_EX(t1, NULL, DYNAMIC_TYPE_ECC);
return err;
#else
@@ -10337,20 +10267,15 @@ static int _ecc_pairwise_consistency_test(ecc_key* key, WC_RNG* rng)
sigLen = (word32)wc_ecc_sig_size(key);
digestLen = WC_SHA256_DIGEST_SIZE;
#ifdef WOLFSSL_SMALL_STACK
sig = (byte*)XMALLOC(sigLen + digestLen, key->heap, DYNAMIC_TYPE_ECC);
if (sig == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(sig, byte, sigLen+digestLen, key->heap,
DYNAMIC_TYPE_ECC, return MEMORY_E);
digest = sig + sigLen;
if (rng == NULL) {
dynRng = 1;
rng = wc_rng_new(NULL, 0, key->heap);
if (rng == NULL) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(sig, key->heap, DYNAMIC_TYPE_ECC);
#endif
WC_FREE_VAR_EX(sig, key->heap, DYNAMIC_TYPE_ECC);
return MEMORY_E;
}
}
@@ -10371,9 +10296,7 @@ static int _ecc_pairwise_consistency_test(ecc_key* key, WC_RNG* rng)
wc_rng_free(rng);
}
ForceZero(sig, sigLen + digestLen);
#ifdef WOLFSSL_SMALL_STACK
XFREE(sig, key->heap, DYNAMIC_TYPE_ECC);
#endif
WC_FREE_VAR_EX(sig, key->heap, DYNAMIC_TYPE_ECC);
}
(void)rng;
@@ -10581,9 +10504,7 @@ static int _ecc_validate_public_key(ecc_key* key, int partial, int priv)
* keys */
if (key->blackKey > 0) {
/* encrypted key was used */
#ifdef WOLFSSL_SMALL_STACK
XFREE(b, key->heap, DYNAMIC_TYPE_ECC);
#endif
WC_FREE_VAR_EX(b, key->heap, DYNAMIC_TYPE_ECC);
FREE_CURVE_SPECS();
return 0;
}
@@ -10593,9 +10514,7 @@ static int _ecc_validate_public_key(ecc_key* key, int partial, int priv)
/* SP 800-56Ar3, section 5.6.2.3.4, process step 1 */
/* pubkey point cannot be at infinity */
if (wc_ecc_point_is_at_infinity(&key->pubkey)) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(b, key->heap, DYNAMIC_TYPE_ECC);
#endif
WC_FREE_VAR_EX(b, key->heap, DYNAMIC_TYPE_ECC);
FREE_CURVE_SPECS();
return ECC_INF_E;
}
@@ -10677,9 +10596,7 @@ static int _ecc_validate_public_key(ecc_key* key, int partial, int priv)
#ifndef USE_ECC_B_PARAM
mp_clear(b);
#ifdef WOLFSSL_SMALL_STACK
XFREE(b, key->heap, DYNAMIC_TYPE_ECC);
#endif
WC_FREE_VAR_EX(b, key->heap, DYNAMIC_TYPE_ECC);
#endif
FREE_CURVE_SPECS();
@@ -10906,10 +10823,8 @@ int wc_ecc_import_x963_ex(const byte* in, word32 inLen, ecc_key* key,
mp_clear(t2);
mp_clear(t1);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(t1, NULL, DYNAMIC_TYPE_BIGINT);
XFREE(t2, NULL, DYNAMIC_TYPE_BIGINT);
#endif
WC_FREE_VAR_EX(t1, NULL, DYNAMIC_TYPE_BIGINT);
WC_FREE_VAR_EX(t2, NULL, DYNAMIC_TYPE_BIGINT);
wc_ecc_curve_free(curve);
FREE_CURVE_SPECS();
@@ -11312,18 +11227,10 @@ int wc_ecc_import_private_key_ex(const byte* priv, word32 privSz,
#endif /* HAVE_WOLF_BIGINT */
#ifdef WOLFSSL_VALIDATE_ECC_IMPORT
if (ret == 0) {
#ifdef WOLFSSL_SMALL_STACK
mp_int* order = NULL;
#else
mp_int order[1];
#endif
WC_DECLARE_VAR(order, mp_int, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
order = (mp_int*)XMALLOC(sizeof(mp_int), key->heap, DYNAMIC_TYPE_ECC);
if (order == NULL) {
ret = MEMORY_E;
}
#endif
WC_ALLOC_VAR_EX(order, mp_int, 1, key->heap, DYNAMIC_TYPE_ECC,
ret=MEMORY_E);
if (ret == 0) {
ret = mp_init(order);
@@ -11342,9 +11249,7 @@ int wc_ecc_import_private_key_ex(const byte* priv, word32 privSz,
ret = ECC_PRIV_KEY_E;
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(order, key->heap, DYNAMIC_TYPE_ECC);
#endif
WC_FREE_VAR_EX(order, key->heap, DYNAMIC_TYPE_ECC);
}
#endif /* WOLFSSL_VALIDATE_ECC_IMPORT */
#ifdef WOLFSSL_ECC_BLIND_K
@@ -11426,10 +11331,8 @@ int wc_ecc_rs_to_sig(const char* r, const char* s, byte* out, word32* outlen)
err = mp_init_multi(rtmp, stmp, NULL, NULL, NULL, NULL);
if (err != MP_OKAY) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(stmp, NULL, DYNAMIC_TYPE_ECC);
XFREE(rtmp, NULL, DYNAMIC_TYPE_ECC);
#endif
WC_FREE_VAR_EX(stmp, NULL, DYNAMIC_TYPE_ECC);
WC_FREE_VAR_EX(rtmp, NULL, DYNAMIC_TYPE_ECC);
return err;
}
@@ -11453,10 +11356,8 @@ int wc_ecc_rs_to_sig(const char* r, const char* s, byte* out, word32* outlen)
mp_clear(rtmp);
mp_clear(stmp);
#ifdef WOLFSSL_SMALL_STACK
XFREE(stmp, NULL, DYNAMIC_TYPE_ECC);
XFREE(rtmp, NULL, DYNAMIC_TYPE_ECC);
#endif
WC_FREE_VAR_EX(stmp, NULL, DYNAMIC_TYPE_ECC);
WC_FREE_VAR_EX(rtmp, NULL, DYNAMIC_TYPE_ECC);
return err;
}
@@ -12635,11 +12536,7 @@ static int build_lut(int idx, mp_int* a, mp_int* modulus, mp_digit mp,
{
int err;
unsigned x, y, bitlen, lut_gap;
#ifdef WOLFSSL_SMALL_STACK
mp_int *tmp = NULL;
#else
mp_int tmp[1];
#endif
WC_DECLARE_VAR(tmp, mp_int, 1, 0);
int infinity;
#ifdef WOLFSSL_SMALL_STACK
@@ -12765,9 +12662,7 @@ static int build_lut(int idx, mp_int* a, mp_int* modulus, mp_digit mp,
errout:
mp_clear(tmp);
#ifdef WOLFSSL_SMALL_STACK
XFREE(tmp, NULL, DYNAMIC_TYPE_ECC_BUFFER);
#endif
WC_FREE_VAR_EX(tmp, NULL, DYNAMIC_TYPE_ECC_BUFFER);
if (err == MP_OKAY) {
fp_cache[idx].LUT_set = 1;
@@ -13280,9 +13175,7 @@ int ecc_mul2add(ecc_point* A, mp_int* kA,
err = mp_init(mu);
if (err != MP_OKAY) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(mu, NULL, DYNAMIC_TYPE_ECC_BUFFER);
#endif
WC_FREE_VAR_EX(mu, NULL, DYNAMIC_TYPE_ECC_BUFFER);
return err;
}
@@ -13295,9 +13188,7 @@ int ecc_mul2add(ecc_point* A, mp_int* kA,
#endif
if (wc_LockMutex(&ecc_fp_lock) != 0) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(mu, NULL, DYNAMIC_TYPE_ECC_BUFFER);
#endif
WC_FREE_VAR_EX(mu, NULL, DYNAMIC_TYPE_ECC_BUFFER);
return BAD_MUTEX_E;
}
#endif /* HAVE_THREAD_LS */
@@ -13392,9 +13283,7 @@ int ecc_mul2add(ecc_point* A, mp_int* kA,
wc_UnLockMutex(&ecc_fp_lock);
#endif /* HAVE_THREAD_LS */
mp_clear(mu);
#ifdef WOLFSSL_SMALL_STACK
XFREE(mu, NULL, DYNAMIC_TYPE_ECC_BUFFER);
#endif
WC_FREE_VAR_EX(mu, NULL, DYNAMIC_TYPE_ECC_BUFFER);
return err;
}
@@ -13417,11 +13306,7 @@ int wc_ecc_mulmod_ex(const mp_int* k, ecc_point *G, ecc_point *R, mp_int* a,
#if !defined(WOLFSSL_SP_MATH)
int idx, err = MP_OKAY;
mp_digit mp = 0;
#ifdef WOLFSSL_SMALL_STACK
mp_int *mu = NULL;
#else
mp_int mu[1];
#endif
WC_DECLARE_VAR(mu, mp_int, 1, 0);
int mpSetup = 0;
#ifndef HAVE_THREAD_LS
int got_ecc_fp_lock = 0;
@@ -13520,9 +13405,7 @@ int wc_ecc_mulmod_ex(const mp_int* k, ecc_point *G, ecc_point *R, mp_int* a,
wc_UnLockMutex(&ecc_fp_lock);
#endif /* HAVE_THREAD_LS */
mp_clear(mu);
#ifdef WOLFSSL_SMALL_STACK
XFREE(mu, NULL, DYNAMIC_TYPE_ECC_BUFFER);
#endif
WC_FREE_VAR_EX(mu, NULL, DYNAMIC_TYPE_ECC_BUFFER);
return err;
@@ -13593,11 +13476,7 @@ int wc_ecc_mulmod_ex2(const mp_int* k, ecc_point *G, ecc_point *R, mp_int* a,
#if !defined(WOLFSSL_SP_MATH)
int idx, err = MP_OKAY;
mp_digit mp = 0;
#ifdef WOLFSSL_SMALL_STACK
mp_int *mu = NULL;
#else
mp_int mu[1];
#endif
WC_DECLARE_VAR(mu, mp_int, 1, 0);
int mpSetup = 0;
#ifndef HAVE_THREAD_LS
int got_ecc_fp_lock = 0;
@@ -13697,9 +13576,7 @@ int wc_ecc_mulmod_ex2(const mp_int* k, ecc_point *G, ecc_point *R, mp_int* a,
wc_UnLockMutex(&ecc_fp_lock);
#endif /* HAVE_THREAD_LS */
mp_clear(mu);
#ifdef WOLFSSL_SMALL_STACK
XFREE(mu, NULL, DYNAMIC_TYPE_ECC_BUFFER);
#endif
WC_FREE_VAR_EX(mu, NULL, DYNAMIC_TYPE_ECC_BUFFER);
return err;
@@ -14458,9 +14335,7 @@ int wc_ecc_encrypt_ex(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
}
wc_AesFree(aes);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(aes, ctx->heap, DYNAMIC_TYPE_AES);
#endif
WC_FREE_VAR_EX(aes, ctx->heap, DYNAMIC_TYPE_AES);
#else
ret = NOT_COMPILED_IN;
#endif
@@ -14501,9 +14376,7 @@ int wc_ecc_encrypt_ex(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
}
wc_AesFree(aes);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(aes, ctx->heap, DYNAMIC_TYPE_AES);
#endif
WC_FREE_VAR_EX(aes, ctx->heap, DYNAMIC_TYPE_AES);
#else
ret = NOT_COMPILED_IN;
#endif
@@ -14547,9 +14420,7 @@ int wc_ecc_encrypt_ex(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
ret = wc_HmacFinal(hmac, out+msgSz);
wc_HmacFree(hmac);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(hmac, ctx->heap, DYNAMIC_TYPE_HMAC);
#endif
WC_FREE_VAR_EX(hmac, ctx->heap, DYNAMIC_TYPE_HMAC);
break;
}
@@ -14571,10 +14442,8 @@ int wc_ecc_encrypt_ex(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
RESTORE_VECTOR_REGISTERS();
#ifdef WOLFSSL_SMALL_STACK
XFREE(sharedSecret, ctx->heap, DYNAMIC_TYPE_ECC_BUFFER);
XFREE(keys, ctx->heap, DYNAMIC_TYPE_ECC_BUFFER);
#endif
WC_FREE_VAR_EX(sharedSecret, ctx->heap, DYNAMIC_TYPE_ECC_BUFFER);
WC_FREE_VAR_EX(keys, ctx->heap, DYNAMIC_TYPE_ECC_BUFFER);
return ret;
}
@@ -14604,11 +14473,7 @@ int wc_ecc_decrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
byte iv[ECC_MAX_IV_SIZE];
#endif
word32 pubKeySz = 0;
#ifdef WOLFSSL_SMALL_STACK
ecc_key* peerKey = NULL;
#else
ecc_key peerKey[1];
#endif
WC_DECLARE_VAR(peerKey, ecc_key, 1, 0);
#endif
word32 digestSz = 0;
ecEncCtx localCtx;
@@ -14738,12 +14603,8 @@ int wc_ecc_decrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
#ifndef WOLFSSL_ECIES_OLD
if (pubKey == NULL) {
#ifdef WOLFSSL_SMALL_STACK
peerKey = (ecc_key*)XMALLOC(sizeof(*peerKey), ctx->heap,
DYNAMIC_TYPE_ECC_BUFFER);
if (peerKey == NULL)
ret = MEMORY_E;
#endif
WC_ALLOC_VAR_EX(peerKey, ecc_key, 1, ctx->heap,
DYNAMIC_TYPE_ECC_BUFFER, ret=MEMORY_E);
pubKey = peerKey;
}
else {
@@ -14883,9 +14744,7 @@ int wc_ecc_decrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
wc_HmacFree(hmac);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(hmac, ctx->heap, DYNAMIC_TYPE_HMAC);
#endif
WC_FREE_VAR_EX(hmac, ctx->heap, DYNAMIC_TYPE_HMAC);
break;
}
@@ -14925,9 +14784,7 @@ int wc_ecc_decrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
}
wc_AesFree(aes);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(aes, ctx->heap, DYNAMIC_TYPE_AES);
#endif
WC_FREE_VAR_EX(aes, ctx->heap, DYNAMIC_TYPE_AES);
break;
}
#endif
@@ -14964,9 +14821,7 @@ int wc_ecc_decrypt(ecc_key* privKey, ecc_key* pubKey, const byte* msg,
}
wc_AesFree(aes);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(aes, ctx->heap, DYNAMIC_TYPE_AES);
#endif
WC_FREE_VAR_EX(aes, ctx->heap, DYNAMIC_TYPE_AES);
break;
}
#endif
@@ -15046,10 +14901,8 @@ static int mp_jacobi(mp_int* a, mp_int* n, int* c)
#endif
if ((res = mp_init_multi(a1, n1, NULL, NULL, NULL, NULL)) != MP_OKAY) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(a1, NULL, DYNAMIC_TYPE_BIGINT);
XFREE(n1, NULL, DYNAMIC_TYPE_BIGINT);
#endif
WC_FREE_VAR_EX(a1, NULL, DYNAMIC_TYPE_BIGINT);
WC_FREE_VAR_EX(n1, NULL, DYNAMIC_TYPE_BIGINT);
return res;
}
@@ -15118,10 +14971,8 @@ done:
mp_clear(n1);
mp_clear(a1);
#ifdef WOLFSSL_SMALL_STACK
XFREE(a1, NULL, DYNAMIC_TYPE_BIGINT);
XFREE(n1, NULL, DYNAMIC_TYPE_BIGINT);
#endif
WC_FREE_VAR_EX(a1, NULL, DYNAMIC_TYPE_BIGINT);
WC_FREE_VAR_EX(n1, NULL, DYNAMIC_TYPE_BIGINT);
return res;
}
@@ -15656,11 +15507,7 @@ int wc_X963_KDF(enum wc_HashType type, const byte* secret, word32 secretSz,
byte counter[4];
byte tmp[WC_MAX_DIGEST_SIZE];
#ifdef WOLFSSL_SMALL_STACK
wc_HashAlg* hash;
#else
wc_HashAlg hash[1];
#endif
WC_DECLARE_VAR(hash, wc_HashAlg, 1, 0);
if (secret == NULL || secretSz == 0 || out == NULL)
return BAD_FUNC_ARG;
@@ -15676,18 +15523,12 @@ int wc_X963_KDF(enum wc_HashType type, const byte* secret, word32 secretSz,
return ret;
digestSz = (word32)ret;
#ifdef WOLFSSL_SMALL_STACK
hash = (wc_HashAlg*)XMALLOC(sizeof(wc_HashAlg), NULL,
DYNAMIC_TYPE_HASHES);
if (hash == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(hash, wc_HashAlg, 1, NULL, DYNAMIC_TYPE_HASHES,
return MEMORY_E);
ret = wc_HashInit(hash, type);
if (ret != 0) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(hash, NULL, DYNAMIC_TYPE_HASHES);
#endif
WC_FREE_VAR_EX(hash, NULL, DYNAMIC_TYPE_HASHES);
return ret;
}
@@ -15729,9 +15570,7 @@ int wc_X963_KDF(enum wc_HashType type, const byte* secret, word32 secretSz,
wc_HashFree(hash, type);
#ifdef WOLFSSL_SMALL_STACK
XFREE(hash, NULL, DYNAMIC_TYPE_HASHES);
#endif
WC_FREE_VAR_EX(hash, NULL, DYNAMIC_TYPE_HASHES);
return ret;
}
+26 -80
View File
@@ -4659,9 +4659,7 @@ static int wolfssl_evp_digest_pk_final(WOLFSSL_EVP_MD_CTX *ctx,
if (ret == WOLFSSL_SUCCESS)
ret = wc_HmacFinal(hmacCopy, md) == 0;
wc_HmacFree(hmacCopy);
#ifdef WOLFSSL_SMALL_STACK
XFREE(hmacCopy, NULL, DYNAMIC_TYPE_OPENSSL);
#endif
WC_FREE_VAR_EX(hmacCopy, NULL, DYNAMIC_TYPE_OPENSSL);
return ret;
}
else {
@@ -4678,9 +4676,7 @@ static int wolfssl_evp_digest_pk_final(WOLFSSL_EVP_MD_CTX *ctx,
if (ret == WOLFSSL_SUCCESS)
ret = wolfSSL_EVP_DigestFinal(ctxCopy, md, mdlen);
wolfSSL_EVP_MD_CTX_cleanup(ctxCopy);
#ifdef WOLFSSL_SMALL_STACK
XFREE(ctxCopy, NULL, DYNAMIC_TYPE_OPENSSL);
#endif
WC_FREE_VAR_EX(ctxCopy, NULL, DYNAMIC_TYPE_OPENSSL);
return ret;
}
}
@@ -6638,11 +6634,7 @@ void wolfSSL_EVP_init(void)
{
int ret;
int hashType = WC_HASH_TYPE_NONE;
#ifdef WOLFSSL_SMALL_STACK
EncryptedInfo* info;
#else
EncryptedInfo info[1];
#endif
WC_DECLARE_VAR(info, EncryptedInfo, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
info = (EncryptedInfo*)XMALLOC(sizeof(EncryptedInfo), NULL,
@@ -6674,9 +6666,7 @@ void wolfSSL_EVP_init(void)
ret = (int)info->keySz;
end:
#ifdef WOLFSSL_SMALL_STACK
XFREE(info, NULL, DYNAMIC_TYPE_ENCRYPTEDINFO);
#endif
WC_FREE_VAR_EX(info, NULL, DYNAMIC_TYPE_ENCRYPTEDINFO);
if (ret < 0)
return 0; /* failure - for compatibility */
@@ -11701,9 +11691,7 @@ static int PrintHexWithColon(WOLFSSL_BIO* out, const byte* input,
idx = 0;
}
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(buff, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(buff, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
#if !defined(NO_RSA)
@@ -11730,26 +11718,16 @@ static int PrintPubKeyRSA(WOLFSSL_BIO* out, const byte* pkey, int pkeySz,
const byte* e = NULL; /* pointer to modulus/exponent */
word32 i;
unsigned long exponent = 0;
#ifdef WOLFSSL_SMALL_STACK
mp_int* a = NULL;
#else
mp_int a[1];
#endif
WC_DECLARE_VAR(a, mp_int, 1, 0);
char line[32] = { 0 };
(void)pctx;
#ifdef WOLFSSL_SMALL_STACK
a = (mp_int*)XMALLOC(sizeof(mp_int), NULL, DYNAMIC_TYPE_BIGINT);
if (a == NULL) {
return WOLFSSL_FAILURE;
}
#endif
WC_ALLOC_VAR_EX(a, mp_int, 1, NULL, DYNAMIC_TYPE_BIGINT,
return WOLFSSL_FAILURE);
if( mp_init(a) != 0) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(a, NULL, DYNAMIC_TYPE_BIGINT);
#endif
WC_FREE_VAR_EX(a, NULL, DYNAMIC_TYPE_BIGINT);
return WOLFSSL_FAILURE;
}
if (indent < 0) {
@@ -11853,9 +11831,7 @@ static int PrintPubKeyRSA(WOLFSSL_BIO* out, const byte* pkey, int pkeySz,
} while (0);
mp_free(a);
#ifdef WOLFSSL_SMALL_STACK
XFREE(a, NULL, DYNAMIC_TYPE_BIGINT);
#endif
WC_FREE_VAR_EX(a, NULL, DYNAMIC_TYPE_BIGINT);
return res;
}
#endif /* !NO_RSA */
@@ -11914,10 +11890,8 @@ static int PrintPubKeyEC(WOLFSSL_BIO* out, const byte* pkey, int pkeySz,
#endif
if (mp_init(a) != 0) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(key, NULL, DYNAMIC_TYPE_ECC);
XFREE(a, NULL, DYNAMIC_TYPE_BIGINT);
#endif
WC_FREE_VAR_EX(key, NULL, DYNAMIC_TYPE_ECC);
WC_FREE_VAR_EX(a, NULL, DYNAMIC_TYPE_BIGINT);
return WOLFSSL_FAILURE;
}
@@ -11925,10 +11899,8 @@ static int PrintPubKeyEC(WOLFSSL_BIO* out, const byte* pkey, int pkeySz,
/* Return early so we don't have to remember if init succeeded
* or not. */
mp_free(a);
#ifdef WOLFSSL_SMALL_STACK
XFREE(key, NULL, DYNAMIC_TYPE_ECC);
XFREE(a, NULL, DYNAMIC_TYPE_BIGINT);
#endif
WC_FREE_VAR_EX(key, NULL, DYNAMIC_TYPE_ECC);
WC_FREE_VAR_EX(a, NULL, DYNAMIC_TYPE_BIGINT);
return WOLFSSL_FAILURE;
}
@@ -12047,10 +12019,8 @@ static int PrintPubKeyEC(WOLFSSL_BIO* out, const byte* pkey, int pkeySz,
wc_ecc_free(key);
mp_free(a);
#ifdef WOLFSSL_SMALL_STACK
XFREE(key, NULL, DYNAMIC_TYPE_ECC);
XFREE(a, NULL, DYNAMIC_TYPE_BIGINT);
#endif
WC_FREE_VAR_EX(key, NULL, DYNAMIC_TYPE_ECC);
WC_FREE_VAR_EX(a, NULL, DYNAMIC_TYPE_BIGINT);
return res;
}
@@ -12078,24 +12048,14 @@ static int PrintPubKeyDSA(WOLFSSL_BIO* out, const byte* pkey, int pkeySz,
word32 inOutIdx = 0;
word32 oid;
byte tagFound;
#ifdef WOLFSSL_SMALL_STACK
mp_int* a = NULL;
#else
mp_int a[1];
#endif
WC_DECLARE_VAR(a, mp_int, 1, 0);
char line[32] = { 0 };
#ifdef WOLFSSL_SMALL_STACK
a = (mp_int*)XMALLOC(sizeof(mp_int), NULL, DYNAMIC_TYPE_BIGINT);
if (a == NULL) {
return WOLFSSL_FAILURE;
}
#endif
WC_ALLOC_VAR_EX(a, mp_int, 1, NULL, DYNAMIC_TYPE_BIGINT,
return WOLFSSL_FAILURE);
if( mp_init(a) != 0) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(a, NULL, DYNAMIC_TYPE_BIGINT);
#endif
WC_FREE_VAR_EX(a, NULL, DYNAMIC_TYPE_BIGINT);
return WOLFSSL_FAILURE;
}
@@ -12268,9 +12228,7 @@ static int PrintPubKeyDSA(WOLFSSL_BIO* out, const byte* pkey, int pkeySz,
} while (0);
mp_free(a);
#ifdef WOLFSSL_SMALL_STACK
XFREE(a, NULL, DYNAMIC_TYPE_BIGINT);
#endif
WC_FREE_VAR_EX(a, NULL, DYNAMIC_TYPE_BIGINT);
return res;
}
#endif /* !NO_DSA */
@@ -12302,24 +12260,14 @@ static int PrintPubKeyDH(WOLFSSL_BIO* out, const byte* pkey, int pkeySz,
byte* publicKey = NULL;
word32 outSz;
byte outHex[3];
#ifdef WOLFSSL_SMALL_STACK
mp_int* a = NULL;
#else
mp_int a[1];
#endif
WC_DECLARE_VAR(a, mp_int, 1, 0);
char line[32] = { 0 };
#ifdef WOLFSSL_SMALL_STACK
a = (mp_int*)XMALLOC(sizeof(mp_int), NULL, DYNAMIC_TYPE_BIGINT);
if (a == NULL) {
return WOLFSSL_FAILURE;
}
#endif
WC_ALLOC_VAR_EX(a, mp_int, 1, NULL, DYNAMIC_TYPE_BIGINT,
return WOLFSSL_FAILURE);
if( mp_init(a) != 0) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(a, NULL, DYNAMIC_TYPE_BIGINT);
#endif
WC_FREE_VAR_EX(a, NULL, DYNAMIC_TYPE_BIGINT);
return WOLFSSL_FAILURE;
}
@@ -12498,9 +12446,7 @@ static int PrintPubKeyDH(WOLFSSL_BIO* out, const byte* pkey, int pkeySz,
} while (0);
mp_free(a);
#ifdef WOLFSSL_SMALL_STACK
XFREE(a, NULL, DYNAMIC_TYPE_BIGINT);
#endif
WC_FREE_VAR_EX(a, NULL, DYNAMIC_TYPE_BIGINT);
return res;
}
#endif /* WOLFSSL_DH_EXTRA */
+2 -4
View File
@@ -11034,10 +11034,8 @@ int ge448_scalarmult_base(ge448_p2* r, const byte* a)
ge448_madd(r, r, t);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(t, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(e, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(t, NULL, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(e, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return 0;
}
+56 -193
View File
@@ -1329,17 +1329,10 @@ int wc_HashGetFlags(wc_HashAlg* hash, enum wc_HashType type, word32* flags)
void* heap, int devId)
{
int ret;
#ifdef WOLFSSL_SMALL_STACK
wc_Md5* md5;
#else
wc_Md5 md5[1];
#endif
WC_DECLARE_VAR(md5, wc_Md5, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
md5 = (wc_Md5*)XMALLOC(sizeof(wc_Md5), NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (md5 == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(md5, wc_Md5, 1, NULL, DYNAMIC_TYPE_TMP_BUFFER,
return MEMORY_E);
if ((ret = wc_InitMd5_ex(md5, heap, devId)) != 0) {
WOLFSSL_MSG("InitMd5 failed");
@@ -1354,9 +1347,7 @@ int wc_HashGetFlags(wc_HashAlg* hash, enum wc_HashType type, word32* flags)
wc_Md5Free(md5);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(md5, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(md5, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -1378,17 +1369,10 @@ int wc_HashGetFlags(wc_HashAlg* hash, enum wc_HashType type, word32* flags)
void* heap, int devId)
{
int ret = 0;
#ifdef WOLFSSL_SMALL_STACK
wc_Sha* sha;
#else
wc_Sha sha[1];
#endif
WC_DECLARE_VAR(sha, wc_Sha, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
sha = (wc_Sha*)XMALLOC(sizeof(wc_Sha), NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (sha == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(sha, wc_Sha, 1, NULL, DYNAMIC_TYPE_TMP_BUFFER,
return MEMORY_E);
if ((ret = wc_InitSha_ex(sha, heap, devId)) != 0) {
WOLFSSL_MSG("InitSha failed");
@@ -1403,9 +1387,7 @@ int wc_HashGetFlags(wc_HashAlg* hash, enum wc_HashType type, word32* flags)
wc_ShaFree(sha);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(sha, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(sha, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -1427,18 +1409,10 @@ int wc_HashGetFlags(wc_HashAlg* hash, enum wc_HashType type, word32* flags)
void* heap, int devId)
{
int ret = 0;
#ifdef WOLFSSL_SMALL_STACK
wc_Sha224* sha224;
#else
wc_Sha224 sha224[1];
#endif
WC_DECLARE_VAR(sha224, wc_Sha224, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
sha224 = (wc_Sha224*)XMALLOC(sizeof(wc_Sha224), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (sha224 == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(sha224, wc_Sha224, 1, NULL, DYNAMIC_TYPE_TMP_BUFFER,
return MEMORY_E);
if ((ret = wc_InitSha224_ex(sha224, heap, devId)) != 0) {
WOLFSSL_MSG("InitSha224 failed");
@@ -1453,9 +1427,7 @@ int wc_HashGetFlags(wc_HashAlg* hash, enum wc_HashType type, word32* flags)
wc_Sha224Free(sha224);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(sha224, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(sha224, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -1531,18 +1503,10 @@ int wc_HashGetFlags(wc_HashAlg* hash, enum wc_HashType type, word32* flags)
void* heap, int devId)
{
int ret = 0;
#ifdef WOLFSSL_SMALL_STACK
wc_Sha512* sha512;
#else
wc_Sha512 sha512[1];
#endif
WC_DECLARE_VAR(sha512, wc_Sha512, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
sha512 = (wc_Sha512*)XMALLOC(sizeof(wc_Sha512), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (sha512 == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(sha512, wc_Sha512, 1, NULL, DYNAMIC_TYPE_TMP_BUFFER,
return MEMORY_E);
if ((ret = wc_InitSha512_ex(sha512, heap, devId)) != 0) {
WOLFSSL_MSG("InitSha512 failed");
@@ -1557,9 +1521,7 @@ int wc_HashGetFlags(wc_HashAlg* hash, enum wc_HashType type, word32* flags)
wc_Sha512Free(sha512);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(sha512, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(sha512, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -1580,18 +1542,10 @@ int wc_HashGetFlags(wc_HashAlg* hash, enum wc_HashType type, word32* flags)
void* heap, int devId)
{
int ret = 0;
#ifdef WOLFSSL_SMALL_STACK
wc_Sha512* sha512;
#else
wc_Sha512 sha512[1];
#endif
WC_DECLARE_VAR(sha512, wc_Sha512, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
sha512 = (wc_Sha512*)XMALLOC(sizeof(wc_Sha512), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (sha512 == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(sha512, wc_Sha512, 1, NULL, DYNAMIC_TYPE_TMP_BUFFER,
return MEMORY_E);
if ((ret = wc_InitSha512_224_ex(sha512, heap, devId)) != 0) {
WOLFSSL_MSG("wc_InitSha512_224 failed");
@@ -1606,9 +1560,7 @@ int wc_HashGetFlags(wc_HashAlg* hash, enum wc_HashType type, word32* flags)
wc_Sha512_224Free(sha512);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(sha512, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(sha512, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -1632,18 +1584,10 @@ int wc_HashGetFlags(wc_HashAlg* hash, enum wc_HashType type, word32* flags)
void* heap, int devId)
{
int ret = 0;
#ifdef WOLFSSL_SMALL_STACK
wc_Sha512* sha512;
#else
wc_Sha512 sha512[1];
#endif
WC_DECLARE_VAR(sha512, wc_Sha512, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
sha512 = (wc_Sha512*)XMALLOC(sizeof(wc_Sha512), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (sha512 == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(sha512, wc_Sha512, 1, NULL, DYNAMIC_TYPE_TMP_BUFFER,
return MEMORY_E);
if ((ret = wc_InitSha512_256_ex(sha512, heap, devId)) != 0) {
WOLFSSL_MSG("wc_InitSha512_256 failed");
@@ -1658,9 +1602,7 @@ int wc_HashGetFlags(wc_HashAlg* hash, enum wc_HashType type, word32* flags)
wc_Sha512_256Free(sha512);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(sha512, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(sha512, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -1685,18 +1627,10 @@ int wc_HashGetFlags(wc_HashAlg* hash, enum wc_HashType type, word32* flags)
void* heap, int devId)
{
int ret = 0;
#ifdef WOLFSSL_SMALL_STACK
wc_Sha384* sha384;
#else
wc_Sha384 sha384[1];
#endif
WC_DECLARE_VAR(sha384, wc_Sha384, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
sha384 = (wc_Sha384*)XMALLOC(sizeof(wc_Sha384), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (sha384 == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(sha384, wc_Sha384, 1, NULL, DYNAMIC_TYPE_TMP_BUFFER,
return MEMORY_E);
if ((ret = wc_InitSha384_ex(sha384, heap, devId)) != 0) {
WOLFSSL_MSG("InitSha384 failed");
@@ -1711,9 +1645,7 @@ int wc_HashGetFlags(wc_HashAlg* hash, enum wc_HashType type, word32* flags)
wc_Sha384Free(sha384);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(sha384, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(sha384, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -1736,18 +1668,10 @@ int wc_HashGetFlags(wc_HashAlg* hash, enum wc_HashType type, word32* flags)
void* heap, int devId)
{
int ret = 0;
#ifdef WOLFSSL_SMALL_STACK
wc_Sha3* sha3;
#else
wc_Sha3 sha3[1];
#endif
WC_DECLARE_VAR(sha3, wc_Sha3, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
sha3 = (wc_Sha3*)XMALLOC(sizeof(wc_Sha3), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (sha3 == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(sha3, wc_Sha3, 1, NULL, DYNAMIC_TYPE_TMP_BUFFER,
return MEMORY_E);
if ((ret = wc_InitSha3_224(sha3, heap, devId)) != 0) {
WOLFSSL_MSG("InitSha3_224 failed");
@@ -1762,9 +1686,7 @@ int wc_HashGetFlags(wc_HashAlg* hash, enum wc_HashType type, word32* flags)
wc_Sha3_224_Free(sha3);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(sha3, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(sha3, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -1786,18 +1708,10 @@ int wc_HashGetFlags(wc_HashAlg* hash, enum wc_HashType type, word32* flags)
void* heap, int devId)
{
int ret = 0;
#ifdef WOLFSSL_SMALL_STACK
wc_Sha3* sha3;
#else
wc_Sha3 sha3[1];
#endif
WC_DECLARE_VAR(sha3, wc_Sha3, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
sha3 = (wc_Sha3*)XMALLOC(sizeof(wc_Sha3), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (sha3 == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(sha3, wc_Sha3, 1, NULL, DYNAMIC_TYPE_TMP_BUFFER,
return MEMORY_E);
if ((ret = wc_InitSha3_256(sha3, heap, devId)) != 0) {
WOLFSSL_MSG("InitSha3_256 failed");
@@ -1812,9 +1726,7 @@ int wc_HashGetFlags(wc_HashAlg* hash, enum wc_HashType type, word32* flags)
wc_Sha3_256_Free(sha3);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(sha3, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(sha3, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -1836,18 +1748,10 @@ int wc_HashGetFlags(wc_HashAlg* hash, enum wc_HashType type, word32* flags)
void* heap, int devId)
{
int ret = 0;
#ifdef WOLFSSL_SMALL_STACK
wc_Sha3* sha3;
#else
wc_Sha3 sha3[1];
#endif
WC_DECLARE_VAR(sha3, wc_Sha3, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
sha3 = (wc_Sha3*)XMALLOC(sizeof(wc_Sha3), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (sha3 == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(sha3, wc_Sha3, 1, NULL, DYNAMIC_TYPE_TMP_BUFFER,
return MEMORY_E);
if ((ret = wc_InitSha3_384(sha3, heap, devId)) != 0) {
WOLFSSL_MSG("InitSha3_384 failed");
@@ -1862,9 +1766,7 @@ int wc_HashGetFlags(wc_HashAlg* hash, enum wc_HashType type, word32* flags)
wc_Sha3_384_Free(sha3);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(sha3, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(sha3, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -1886,18 +1788,10 @@ int wc_HashGetFlags(wc_HashAlg* hash, enum wc_HashType type, word32* flags)
void* heap, int devId)
{
int ret = 0;
#ifdef WOLFSSL_SMALL_STACK
wc_Sha3* sha3;
#else
wc_Sha3 sha3[1];
#endif
WC_DECLARE_VAR(sha3, wc_Sha3, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
sha3 = (wc_Sha3*)XMALLOC(sizeof(wc_Sha3), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (sha3 == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(sha3, wc_Sha3, 1, NULL, DYNAMIC_TYPE_TMP_BUFFER,
return MEMORY_E);
if ((ret = wc_InitSha3_512(sha3, heap, devId)) != 0) {
WOLFSSL_MSG("InitSha3_512 failed");
@@ -1912,9 +1806,7 @@ int wc_HashGetFlags(wc_HashAlg* hash, enum wc_HashType type, word32* flags)
wc_Sha3_512_Free(sha3);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(sha3, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(sha3, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -1936,18 +1828,10 @@ int wc_HashGetFlags(wc_HashAlg* hash, enum wc_HashType type, word32* flags)
word32 hashLen, void* heap, int devId)
{
int ret = 0;
#ifdef WOLFSSL_SMALL_STACK
wc_Shake* shake;
#else
wc_Shake shake[1];
#endif
WC_DECLARE_VAR(shake, wc_Shake, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
shake = (wc_Shake*)XMALLOC(sizeof(wc_Shake), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (shake == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(shake, wc_Shake, 1, NULL, DYNAMIC_TYPE_TMP_BUFFER,
return MEMORY_E);
if ((ret = wc_InitShake128(shake, heap, devId)) != 0) {
WOLFSSL_MSG("InitShake128 failed");
@@ -1962,9 +1846,7 @@ int wc_HashGetFlags(wc_HashAlg* hash, enum wc_HashType type, word32* flags)
wc_Shake128_Free(shake);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(shake, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(shake, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -1988,18 +1870,10 @@ int wc_HashGetFlags(wc_HashAlg* hash, enum wc_HashType type, word32* flags)
word32 hashLen, void* heap, int devId)
{
int ret = 0;
#ifdef WOLFSSL_SMALL_STACK
wc_Shake* shake;
#else
wc_Shake shake[1];
#endif
WC_DECLARE_VAR(shake, wc_Shake, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
shake = (wc_Shake*)XMALLOC(sizeof(wc_Shake), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (shake == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(shake, wc_Shake, 1, NULL, DYNAMIC_TYPE_TMP_BUFFER,
return MEMORY_E);
if ((ret = wc_InitShake256(shake, heap, devId)) != 0) {
WOLFSSL_MSG("InitShake256 failed");
@@ -2014,9 +1888,7 @@ int wc_HashGetFlags(wc_HashAlg* hash, enum wc_HashType type, word32* flags)
wc_Shake256_Free(shake);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(shake, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(shake, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -2041,17 +1913,10 @@ int wc_HashGetFlags(wc_HashAlg* hash, enum wc_HashType type, word32* flags)
void* heap, int devId)
{
int ret = 0;
#ifdef WOLFSSL_SMALL_STACK
wc_Sm3* sm3;
#else
wc_Sm3 sm3[1];
#endif
WC_DECLARE_VAR(sm3, wc_Sm3, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
sm3 = (wc_Sm3*)XMALLOC(sizeof(wc_Sm3), NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (sm3 == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(sm3, wc_Sm3, 1, NULL, DYNAMIC_TYPE_TMP_BUFFER,
return MEMORY_E);
if ((ret = wc_InitSm3(sm3, heap, devId)) != 0) {
WOLFSSL_MSG("InitSm3 failed");
@@ -2066,9 +1931,7 @@ int wc_HashGetFlags(wc_HashAlg* hash, enum wc_HashType type, word32* flags)
wc_Sm3Free(sm3);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(sm3, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(sm3, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
+9 -31
View File
@@ -1449,11 +1449,7 @@ int wolfSSL_GetHmacMaxSize(void)
const byte* inKey, word32 inKeySz, byte* out, void* heap, int devId)
{
byte tmp[WC_MAX_DIGEST_SIZE]; /* localSalt helper */
#ifdef WOLFSSL_SMALL_STACK
Hmac* myHmac;
#else
Hmac myHmac[1];
#endif
WC_DECLARE_VAR(myHmac, Hmac, 1, 0);
int ret;
const byte* localSalt; /* either points to user input or tmp */
word32 hashSz;
@@ -1463,12 +1459,8 @@ int wolfSSL_GetHmacMaxSize(void)
return ret;
}
#ifdef WOLFSSL_SMALL_STACK
myHmac = (Hmac*)XMALLOC(sizeof(Hmac), NULL, DYNAMIC_TYPE_HMAC);
if (myHmac == NULL) {
return MEMORY_E;
}
#endif
WC_ALLOC_VAR_EX(myHmac, Hmac, 1, NULL, DYNAMIC_TYPE_HMAC,
return MEMORY_E);
hashSz = (word32)ret;
localSalt = salt;
@@ -1492,9 +1484,7 @@ int wolfSSL_GetHmacMaxSize(void)
ret = wc_HmacFinal(myHmac, out);
wc_HmacFree(myHmac);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(myHmac, NULL, DYNAMIC_TYPE_HMAC);
#endif
WC_FREE_VAR_EX(myHmac, NULL, DYNAMIC_TYPE_HMAC);
return ret;
}
@@ -1522,11 +1512,7 @@ int wolfSSL_GetHmacMaxSize(void)
void* heap, int devId)
{
byte tmp[WC_MAX_DIGEST_SIZE];
#ifdef WOLFSSL_SMALL_STACK
Hmac* myHmac;
#else
Hmac myHmac[1];
#endif
WC_DECLARE_VAR(myHmac, Hmac, 1, 0);
int ret = 0;
word32 outIdx = 0;
word32 hashSz;
@@ -1545,18 +1531,12 @@ int wolfSSL_GetHmacMaxSize(void)
return BAD_FUNC_ARG;
}
#ifdef WOLFSSL_SMALL_STACK
myHmac = (Hmac*)XMALLOC(sizeof(Hmac), NULL, DYNAMIC_TYPE_HMAC);
if (myHmac == NULL) {
return MEMORY_E;
}
#endif
WC_ALLOC_VAR_EX(myHmac, Hmac, 1, NULL, DYNAMIC_TYPE_HMAC,
return MEMORY_E);
ret = wc_HmacInit(myHmac, heap, devId);
if (ret != 0) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(myHmac, NULL, DYNAMIC_TYPE_HMAC);
#endif
WC_FREE_VAR_EX(myHmac, NULL, DYNAMIC_TYPE_HMAC);
return ret;
}
@@ -1595,9 +1575,7 @@ int wolfSSL_GetHmacMaxSize(void)
}
wc_HmacFree(myHmac);
#ifdef WOLFSSL_SMALL_STACK
XFREE(myHmac, NULL, DYNAMIC_TYPE_HMAC);
#endif
WC_FREE_VAR_EX(myHmac, NULL, DYNAMIC_TYPE_HMAC);
return ret;
}
+41 -138
View File
@@ -465,23 +465,14 @@ static int wc_HpkeLabeledExtract(Hpke* hpke, byte* suite_id,
{
int ret;
byte* labeled_ikm_p;
#ifndef WOLFSSL_SMALL_STACK
byte labeled_ikm[MAX_HPKE_LABEL_SZ];
#else
byte* labeled_ikm;
#endif
WC_DECLARE_VAR(labeled_ikm, byte, MAX_HPKE_LABEL_SZ, 0);
if (hpke == NULL) {
return BAD_FUNC_ARG;
}
#ifdef WOLFSSL_SMALL_STACK
labeled_ikm = (byte*)XMALLOC(MAX_HPKE_LABEL_SZ, hpke->heap,
DYNAMIC_TYPE_TMP_BUFFER);
if (labeled_ikm == NULL) {
return MEMORY_E;
}
#endif
WC_ALLOC_VAR_EX(labeled_ikm, byte, MAX_HPKE_LABEL_SZ, hpke->heap,
DYNAMIC_TYPE_TMP_BUFFER, return MEMORY_E);
/* concat the labeled_ikm */
/* version */
@@ -508,9 +499,7 @@ static int wc_HpkeLabeledExtract(Hpke* hpke, byte* suite_id,
(word32)(size_t)(labeled_ikm_p - labeled_ikm), out);
PRIVATE_KEY_LOCK();
#ifdef WOLFSSL_SMALL_STACK
XFREE(labeled_ikm, hpke->heap, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(labeled_ikm, hpke->heap, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -523,23 +512,14 @@ static int wc_HpkeLabeledExpand(Hpke* hpke, byte* suite_id, word32 suite_id_len,
{
int ret;
byte* labeled_info_p;
#ifndef WOLFSSL_SMALL_STACK
byte labeled_info[MAX_HPKE_LABEL_SZ];
#else
byte* labeled_info;
#endif
WC_DECLARE_VAR(labeled_info, byte, MAX_HPKE_LABEL_SZ, 0);
if (hpke == NULL) {
return BAD_FUNC_ARG;
}
#ifdef WOLFSSL_SMALL_STACK
labeled_info = (byte*)XMALLOC(MAX_HPKE_LABEL_SZ, hpke->heap,
DYNAMIC_TYPE_TMP_BUFFER);
if (labeled_info == NULL) {
return MEMORY_E;
}
#endif
WC_ALLOC_VAR_EX(labeled_info, byte, MAX_HPKE_LABEL_SZ, hpke->heap,
DYNAMIC_TYPE_TMP_BUFFER, return MEMORY_E);
/* copy length */
ret = I2OSP((int)L, 2, labeled_info);
@@ -571,9 +551,7 @@ static int wc_HpkeLabeledExpand(Hpke* hpke, byte* suite_id, word32 suite_id_len,
PRIVATE_KEY_LOCK();
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(labeled_info, hpke->heap, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(labeled_info, hpke->heap, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -606,23 +584,14 @@ static int wc_HpkeExtractAndExpand( Hpke* hpke, byte* dh, word32 dh_len,
{
int ret;
/* max length is the largest hmac digest possible */
#ifndef WOLFSSL_SMALL_STACK
byte eae_prk[WC_MAX_DIGEST_SIZE];
#else
byte* eae_prk;
#endif
WC_DECLARE_VAR(eae_prk, byte, WC_MAX_DIGEST_SIZE, 0);
if (hpke == NULL) {
return BAD_FUNC_ARG;
}
#ifdef WOLFSSL_SMALL_STACK
eae_prk = (byte*)XMALLOC(WC_MAX_DIGEST_SIZE, hpke->heap,
DYNAMIC_TYPE_DIGEST);
if (eae_prk == NULL) {
return MEMORY_E;
}
#endif
WC_ALLOC_VAR_EX(eae_prk, byte, WC_MAX_DIGEST_SIZE, hpke->heap,
DYNAMIC_TYPE_DIGEST, return MEMORY_E);
/* extract */
ret = wc_HpkeLabeledExtract(hpke, hpke->kem_suite_id,
@@ -636,9 +605,7 @@ static int wc_HpkeExtractAndExpand( Hpke* hpke, byte* dh, word32 dh_len,
(byte*)SHARED_SECRET_LABEL_STR, SHARED_SECRET_LABEL_STR_LEN,
kemContext, kem_context_length, hpke->Nsecret, sharedSecret);
#ifdef WOLFSSL_SMALL_STACK
XFREE(eae_prk, hpke->heap, DYNAMIC_TYPE_DIGEST);
#endif
WC_FREE_VAR_EX(eae_prk, hpke->heap, DYNAMIC_TYPE_DIGEST);
return ret;
}
@@ -726,10 +693,9 @@ static int wc_HpkeKeyScheduleBase(Hpke* hpke, HpkeBaseContext* context,
1 + 2 * hpke->Nh, hpke->Nh, context->exporter_secret);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(key_schedule_context, hpke->heap, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(secret, hpke->heap, DYNAMIC_TYPE_DIGEST);
#endif
WC_FREE_VAR_EX(key_schedule_context, hpke->heap,
DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(secret, hpke->heap, DYNAMIC_TYPE_DIGEST);
return ret;
}
@@ -830,10 +796,8 @@ static int wc_HpkeEncap(Hpke* hpke, void* ephemeralKey, void* receiverKey,
hpke->Npk * 2, sharedSecret);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(dh, hpke->heap, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(kemContext, hpke->heap, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(dh, hpke->heap, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(kemContext, hpke->heap, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -843,11 +807,7 @@ static int wc_HpkeSetupBaseSender(Hpke* hpke, HpkeBaseContext* context,
void* ephemeralKey, void* receiverKey, byte* info, word32 infoSz)
{
int ret;
#ifndef WOLFSSL_SMALL_STACK
byte sharedSecret[HPKE_Nsecret_MAX];
#else
byte* sharedSecret;
#endif
WC_DECLARE_VAR(sharedSecret, byte, HPKE_Nsecret_MAX, 0);
if (hpke == NULL) {
return BAD_FUNC_ARG;
@@ -867,9 +827,7 @@ static int wc_HpkeSetupBaseSender(Hpke* hpke, HpkeBaseContext* context,
infoSz);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(sharedSecret, hpke->heap, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(sharedSecret, hpke->heap, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -896,21 +854,13 @@ int wc_HpkeContextSealBase(Hpke* hpke, HpkeBaseContext* context,
{
int ret;
byte nonce[HPKE_Nn_MAX];
#ifndef WOLFSSL_SMALL_STACK
Aes aes[1];
#else
Aes* aes;
#endif
WC_DECLARE_VAR(aes, Aes, 1, 0);
if (hpke == NULL || context == NULL || (aad == NULL && aadSz > 0) ||
plaintext == NULL || out == NULL) {
return BAD_FUNC_ARG;
}
#ifdef WOLFSSL_SMALL_STACK
aes = (Aes*)XMALLOC(sizeof(Aes), hpke->heap, DYNAMIC_TYPE_AES);
if (aes == NULL) {
return MEMORY_E;
}
#endif
WC_ALLOC_VAR_EX(aes, Aes, 1, hpke->heap, DYNAMIC_TYPE_AES,
return MEMORY_E);
ret = wc_AesInit(aes, hpke->heap, INVALID_DEVID);
if (ret == 0) {
/* compute nonce */
@@ -928,9 +878,7 @@ int wc_HpkeContextSealBase(Hpke* hpke, HpkeBaseContext* context,
}
wc_AesFree(aes);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(aes, hpke->heap, DYNAMIC_TYPE_AES);
#endif
WC_FREE_VAR_EX(aes, hpke->heap, DYNAMIC_TYPE_AES);
return ret;
}
@@ -940,11 +888,7 @@ int wc_HpkeSealBase(Hpke* hpke, void* ephemeralKey, void* receiverKey,
word32 ptSz, byte* ciphertext)
{
int ret;
#ifdef WOLFSSL_SMALL_STACK
HpkeBaseContext* context;
#else
HpkeBaseContext context[1];
#endif
WC_DECLARE_VAR(context, HpkeBaseContext, 1, 0);
/* check that all the buffers are non NULL or optional with 0 length */
if (hpke == NULL || ephemeralKey == NULL || receiverKey == NULL ||
@@ -953,13 +897,8 @@ int wc_HpkeSealBase(Hpke* hpke, void* ephemeralKey, void* receiverKey,
return BAD_FUNC_ARG;
}
#ifdef WOLFSSL_SMALL_STACK
context = (HpkeBaseContext*)XMALLOC(sizeof(HpkeBaseContext), hpke->heap,
DYNAMIC_TYPE_TMP_BUFFER);
if (context == NULL) {
return MEMORY_E;
}
#endif
WC_ALLOC_VAR_EX(context, HpkeBaseContext, 1, hpke->heap,
DYNAMIC_TYPE_TMP_BUFFER, return MEMORY_E);
PRIVATE_KEY_UNLOCK();
@@ -975,9 +914,7 @@ int wc_HpkeSealBase(Hpke* hpke, void* ephemeralKey, void* receiverKey,
PRIVATE_KEY_LOCK();
#ifdef WOLFSSL_SMALL_STACK
XFREE(context, hpke->heap, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(context, hpke->heap, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -1095,10 +1032,8 @@ static int wc_HpkeDecap(Hpke* hpke, void* receiverKey, const byte* pubKey,
hpke->Npk * 2, sharedSecret);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(dh, hpke->heap, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(kemContext, hpke->heap, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(dh, hpke->heap, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(kemContext, hpke->heap, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -1109,19 +1044,10 @@ static int wc_HpkeSetupBaseReceiver(Hpke* hpke, HpkeBaseContext* context,
word32 infoSz)
{
int ret;
#ifndef WOLFSSL_SMALL_STACK
byte sharedSecret[HPKE_Nsecret_MAX];
#else
byte* sharedSecret;
#endif
WC_DECLARE_VAR(sharedSecret, byte, HPKE_Nsecret_MAX, 0);
#ifdef WOLFSSL_SMALL_STACK
sharedSecret = (byte*)XMALLOC(hpke->Nsecret, hpke->heap,
DYNAMIC_TYPE_TMP_BUFFER);
if (sharedSecret == NULL) {
return MEMORY_E;
}
#endif
WC_ALLOC_VAR_EX(sharedSecret, byte, hpke->Nsecret, hpke->heap,
DYNAMIC_TYPE_TMP_BUFFER, return MEMORY_E);
/* decap */
ret = wc_HpkeDecap(hpke, receiverKey, pubKey, pubKeySz, sharedSecret);
@@ -1132,9 +1058,7 @@ static int wc_HpkeSetupBaseReceiver(Hpke* hpke, HpkeBaseContext* context,
infoSz);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(sharedSecret, hpke->heap, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(sharedSecret, hpke->heap, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -1159,21 +1083,13 @@ int wc_HpkeContextOpenBase(Hpke* hpke, HpkeBaseContext* context, byte* aad,
{
int ret;
byte nonce[HPKE_Nn_MAX];
#ifndef WOLFSSL_SMALL_STACK
Aes aes[1];
#else
Aes* aes;
#endif
WC_DECLARE_VAR(aes, Aes, 1, 0);
if (hpke == NULL) {
return BAD_FUNC_ARG;
}
XMEMSET(nonce, 0, sizeof(nonce));
#ifdef WOLFSSL_SMALL_STACK
aes = (Aes*)XMALLOC(sizeof(Aes), hpke->heap, DYNAMIC_TYPE_AES);
if (aes == NULL) {
return MEMORY_E;
}
#endif
WC_ALLOC_VAR_EX(aes, Aes, 1, hpke->heap, DYNAMIC_TYPE_AES,
return MEMORY_E);
/* compute nonce */
ret = wc_HpkeContextComputeNonce(hpke, context, nonce);
if (ret == 0)
@@ -1190,9 +1106,7 @@ int wc_HpkeContextOpenBase(Hpke* hpke, HpkeBaseContext* context, byte* aad,
}
wc_AesFree(aes);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(aes, hpke->heap, DYNAMIC_TYPE_AES);
#endif
WC_FREE_VAR_EX(aes, hpke->heap, DYNAMIC_TYPE_AES);
return ret;
}
@@ -1203,11 +1117,7 @@ int wc_HpkeOpenBase(Hpke* hpke, void* receiverKey, const byte* pubKey,
byte* ciphertext, word32 ctSz, byte* plaintext)
{
int ret;
#ifndef WOLFSSL_SMALL_STACK
HpkeBaseContext context[1];
#else
HpkeBaseContext* context;
#endif
WC_DECLARE_VAR(context, HpkeBaseContext, 1, 0);
/* check that all the buffer are non NULL or optional with 0 length */
if (hpke == NULL || receiverKey == NULL || pubKey == NULL ||
@@ -1217,13 +1127,8 @@ int wc_HpkeOpenBase(Hpke* hpke, void* receiverKey, const byte* pubKey,
return BAD_FUNC_ARG;
}
#ifdef WOLFSSL_SMALL_STACK
context = (HpkeBaseContext*)XMALLOC(sizeof(HpkeBaseContext), hpke->heap,
DYNAMIC_TYPE_TMP_BUFFER);
if (context == NULL) {
return MEMORY_E;
}
#endif
WC_ALLOC_VAR_EX(context, HpkeBaseContext, 1, hpke->heap,
DYNAMIC_TYPE_TMP_BUFFER, return MEMORY_E);
PRIVATE_KEY_UNLOCK();
@@ -1239,9 +1144,7 @@ int wc_HpkeOpenBase(Hpke* hpke, void* receiverKey, const byte* pubKey,
PRIVATE_KEY_LOCK();
#ifdef WOLFSSL_SMALL_STACK
XFREE(context, hpke->heap, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(context, hpke->heap, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
+26 -73
View File
@@ -2016,23 +2016,15 @@ int mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y,
mp_int res;
mp_digit buf, mp;
int err, bitbuf, bitcpy, bitcnt, mode, digidx, x, y, winsize;
#ifdef WOLFSSL_SMALL_STACK
mp_int* M;
#else
mp_int M[TAB_SIZE];
#endif
WC_DECLARE_VAR(M, mp_int, TAB_SIZE, 0);
/* use a pointer to the reduction algorithm. This allows us to use
* one of many reduction algorithms without modding the guts of
* the code with if statements everywhere.
*/
int (*redux)(mp_int*,mp_int*,mp_digit) = NULL;
#ifdef WOLFSSL_SMALL_STACK
M = (mp_int*) XMALLOC(sizeof(mp_int) * TAB_SIZE, NULL,
DYNAMIC_TYPE_BIGINT);
if (M == NULL)
return MP_MEM;
#endif
WC_ALLOC_VAR_EX(M, mp_int, TAB_SIZE, NULL, DYNAMIC_TYPE_BIGINT,
return MP_MEM);
/* find window size */
x = mp_count_bits (X);
@@ -2061,9 +2053,7 @@ int mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y,
/* init M array */
/* init first cell */
if ((err = mp_init_size(&M[1], P->alloc)) != MP_OKAY) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(M, NULL, DYNAMIC_TYPE_BIGINT);
#endif
WC_FREE_VAR_EX(M, NULL, DYNAMIC_TYPE_BIGINT);
return err;
}
@@ -2076,9 +2066,7 @@ int mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y,
}
mp_clear(&M[1]);
#ifdef WOLFSSL_SMALL_STACK
XFREE(M, NULL, DYNAMIC_TYPE_BIGINT);
#endif
WC_FREE_VAR_EX(M, NULL, DYNAMIC_TYPE_BIGINT);
return err;
}
@@ -2317,9 +2305,7 @@ LBL_M:
mp_clear (&M[x]);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(M, NULL, DYNAMIC_TYPE_BIGINT);
#endif
WC_FREE_VAR_EX(M, NULL, DYNAMIC_TYPE_BIGINT);
return err;
}
@@ -2527,11 +2513,8 @@ int mp_montgomery_setup (mp_int * n, mp_digit * rho)
int fast_mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho)
{
int ix, res, olduse;
#ifdef WOLFSSL_SMALL_STACK
mp_word* W; /* uses dynamic memory and slower */
#else
mp_word W[MP_WARRAY];
#endif
/* uses dynamic memory and slower */
WC_DECLARE_VAR(W, mp_word, MP_WARRAY, 0);
/* get old used count */
olduse = x->used;
@@ -2543,12 +2526,8 @@ int fast_mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho)
}
}
#ifdef WOLFSSL_SMALL_STACK
W = (mp_word*)XMALLOC(sizeof(mp_word) * (n->used * 2 + 2), NULL,
DYNAMIC_TYPE_BIGINT);
if (W == NULL)
return MP_MEM;
#endif
WC_ALLOC_VAR_EX(W, mp_word, (n->used*2+2), NULL, DYNAMIC_TYPE_BIGINT,
return MP_MEM);
XMEMSET(W, 0, sizeof(mp_word) * (n->used * 2 + 2));
@@ -2668,9 +2647,7 @@ int fast_mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho)
x->used = n->used + 1;
mp_clamp (x);
#ifdef WOLFSSL_SMALL_STACK
XFREE(W, NULL, DYNAMIC_TYPE_BIGINT);
#endif
WC_FREE_VAR_EX(W, NULL, DYNAMIC_TYPE_BIGINT);
/* if A >= m then A = A - m */
if (mp_cmp_mag (x, n) != MP_LT) {
@@ -3384,11 +3361,8 @@ After that loop you do the squares and add them in.
int fast_s_mp_sqr (mp_int * a, mp_int * b)
{
int olduse, res, pa, ix, iz;
#ifdef WOLFSSL_SMALL_STACK
mp_digit* W; /* uses dynamic memory and slower */
#else
mp_digit W[MP_WARRAY];
#endif
/* uses dynamic memory and slower */
WC_DECLARE_VAR(W, mp_digit, MP_WARRAY, 0);
mp_digit *tmpx;
mp_word W1;
@@ -3409,11 +3383,8 @@ int fast_s_mp_sqr (mp_int * a, mp_int * b)
return MP_OKAY;
}
#ifdef WOLFSSL_SMALL_STACK
W = (mp_digit*)XMALLOC(sizeof(mp_digit) * pa, NULL, DYNAMIC_TYPE_BIGINT);
if (W == NULL)
return MP_MEM;
#endif
WC_ALLOC_VAR_EX(W, mp_digit, pa, NULL, DYNAMIC_TYPE_BIGINT,
return MP_MEM);
/* number of output digits to produce */
W1 = 0;
@@ -3482,9 +3453,7 @@ int fast_s_mp_sqr (mp_int * a, mp_int * b)
}
mp_clamp (b);
#ifdef WOLFSSL_SMALL_STACK
XFREE(W, NULL, DYNAMIC_TYPE_BIGINT);
#endif
WC_FREE_VAR_EX(W, NULL, DYNAMIC_TYPE_BIGINT);
return MP_OKAY;
}
@@ -3509,11 +3478,8 @@ int fast_s_mp_sqr (mp_int * a, mp_int * b)
int fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
{
int olduse, res, pa, ix, iz;
#ifdef WOLFSSL_SMALL_STACK
mp_digit* W; /* uses dynamic memory and slower */
#else
mp_digit W[MP_WARRAY];
#endif
/* uses dynamic memory and slower */
WC_DECLARE_VAR(W, mp_digit, MP_WARRAY, 0);
mp_word _W;
/* grow the destination as required */
@@ -3534,11 +3500,8 @@ int fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
return MP_OKAY;
}
#ifdef WOLFSSL_SMALL_STACK
W = (mp_digit*)XMALLOC(sizeof(mp_digit) * pa, NULL, DYNAMIC_TYPE_BIGINT);
if (W == NULL)
return MP_MEM;
#endif
WC_ALLOC_VAR_EX(W, mp_digit, pa, NULL, DYNAMIC_TYPE_BIGINT,
return MP_MEM);
/* clear the carry */
_W = 0;
@@ -3594,9 +3557,7 @@ int fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
}
mp_clamp (c);
#ifdef WOLFSSL_SMALL_STACK
XFREE(W, NULL, DYNAMIC_TYPE_BIGINT);
#endif
WC_FREE_VAR_EX(W, NULL, DYNAMIC_TYPE_BIGINT);
return MP_OKAY;
}
@@ -4247,11 +4208,8 @@ int s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
int fast_s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
{
int olduse, res, pa, ix, iz;
#ifdef WOLFSSL_SMALL_STACK
mp_digit* W; /* uses dynamic memory and slower */
#else
mp_digit W[MP_WARRAY];
#endif
/* uses dynamic memory and slower */
WC_DECLARE_VAR(W, mp_digit, MP_WARRAY, 0);
mp_word _W;
if (a->dp == NULL) { /* JRB, avoid reading uninitialized values */
@@ -4269,11 +4227,8 @@ int fast_s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
if (pa > (int)MP_WARRAY)
return MP_RANGE; /* TAO range check */
#ifdef WOLFSSL_SMALL_STACK
W = (mp_digit*)XMALLOC(sizeof(mp_digit) * pa, NULL, DYNAMIC_TYPE_BIGINT);
if (W == NULL)
return MP_MEM;
#endif
WC_ALLOC_VAR_EX(W, mp_digit, pa, NULL, DYNAMIC_TYPE_BIGINT,
return MP_MEM);
/* number of output digits to produce */
_W = 0;
@@ -4326,9 +4281,7 @@ int fast_s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
}
mp_clamp (c);
#ifdef WOLFSSL_SMALL_STACK
XFREE(W, NULL, DYNAMIC_TYPE_BIGINT);
#endif
WC_FREE_VAR_EX(W, NULL, DYNAMIC_TYPE_BIGINT);
return MP_OKAY;
}
+20 -68
View File
@@ -209,10 +209,8 @@ int wc_PRF(byte* result, word32 resLen, const byte* secret,
wc_MemZero_Check(hmac, sizeof(Hmac));
#endif
#ifdef WOLFSSL_SMALL_STACK
XFREE(current, heap, DYNAMIC_TYPE_DIGEST);
XFREE(hmac, heap, DYNAMIC_TYPE_HMAC);
#endif
WC_FREE_VAR_EX(current, heap, DYNAMIC_TYPE_DIGEST);
WC_FREE_VAR_EX(hmac, heap, DYNAMIC_TYPE_HMAC);
return ret;
}
@@ -278,10 +276,8 @@ int wc_PRF_TLSv1(byte* digest, word32 digLen, const byte* secret,
wc_MemZero_Check(sha_result, MAX_PRF_DIG);
#endif
#ifdef WOLFSSL_SMALL_STACK
XFREE(sha_result, heap, DYNAMIC_TYPE_DIGEST);
XFREE(labelSeed, heap, DYNAMIC_TYPE_DIGEST);
#endif
WC_FREE_VAR_EX(sha_result, heap, DYNAMIC_TYPE_DIGEST);
WC_FREE_VAR_EX(labelSeed, heap, DYNAMIC_TYPE_DIGEST);
return ret;
}
@@ -305,22 +301,14 @@ int wc_PRF_TLS(byte* digest, word32 digLen, const byte* secret, word32 secLen,
if (useAtLeastSha256) {
#ifdef WOLFSSL_SMALL_STACK
byte* labelSeed;
#else
byte labelSeed[MAX_PRF_LABSEED];
#endif
WC_DECLARE_VAR(labelSeed, byte, MAX_PRF_LABSEED, 0);
if (labLen + seedLen > MAX_PRF_LABSEED) {
return BUFFER_E;
}
#ifdef WOLFSSL_SMALL_STACK
labelSeed = (byte*)XMALLOC(MAX_PRF_LABSEED, heap, DYNAMIC_TYPE_DIGEST);
if (labelSeed == NULL) {
return MEMORY_E;
}
#endif
WC_ALLOC_VAR_EX(labelSeed, byte, MAX_PRF_LABSEED, heap,
DYNAMIC_TYPE_DIGEST, return MEMORY_E);
XMEMCPY(labelSeed, label, labLen);
XMEMCPY(labelSeed + labLen, seed, seedLen);
@@ -334,9 +322,7 @@ int wc_PRF_TLS(byte* digest, word32 digLen, const byte* secret, word32 secLen,
ret = wc_PRF(digest, digLen, secret, secLen, labelSeed,
labLen + seedLen, hash_type, heap, devId);
#ifdef WOLFSSL_SMALL_STACK
XFREE(labelSeed, heap, DYNAMIC_TYPE_DIGEST);
#endif
WC_FREE_VAR_EX(labelSeed, heap, DYNAMIC_TYPE_DIGEST);
}
else {
#ifndef NO_OLD_TLS
@@ -448,11 +434,7 @@ int wc_PRF_TLS(byte* digest, word32 digLen, const byte* secret, word32 secLen,
{
int ret = 0;
word32 idx = 0;
#ifdef WOLFSSL_SMALL_STACK
byte* data;
#else
byte data[MAX_TLS13_HKDF_LABEL_SZ];
#endif
WC_DECLARE_VAR(data, byte, MAX_TLS13_HKDF_LABEL_SZ, 0);
/* okmLen (2) + protocol|label len (1) + info len(1) + protocollen +
* labellen + infolen */
@@ -461,12 +443,8 @@ int wc_PRF_TLS(byte* digest, word32 digLen, const byte* secret, word32 secLen,
return BUFFER_E;
}
#ifdef WOLFSSL_SMALL_STACK
data = (byte*)XMALLOC(idx, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (data == NULL) {
return MEMORY_E;
}
#endif
WC_ALLOC_VAR_EX(data, byte, idx, NULL, DYNAMIC_TYPE_TMP_BUFFER,
return MEMORY_E);
idx = 0;
/* Output length. */
@@ -524,9 +502,7 @@ int wc_PRF_TLS(byte* digest, word32 digLen, const byte* secret, word32 secLen,
#ifdef WOLFSSL_CHECK_MEM_ZERO
wc_MemZero_Check(data, idx);
#endif
#ifdef WOLFSSL_SMALL_STACK
XFREE(data, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(data, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -1023,11 +999,7 @@ int wc_SRTP_KDF(const byte* key, word32 keySz, const byte* salt, word32 saltSz,
{
int ret = 0;
byte block[WC_AES_BLOCK_SIZE];
#ifdef WOLFSSL_SMALL_STACK
Aes* aes = NULL;
#else
Aes aes[1];
#endif
WC_DECLARE_VAR(aes, Aes, 1, 0);
int aes_inited = 0;
/* Validate parameters. */
@@ -1078,9 +1050,7 @@ int wc_SRTP_KDF(const byte* key, word32 keySz, const byte* salt, word32 saltSz,
if (aes_inited)
wc_AesFree(aes);
#ifdef WOLFSSL_SMALL_STACK
XFREE(aes, NULL, DYNAMIC_TYPE_CIPHER);
#endif
WC_FREE_VAR_EX(aes, NULL, DYNAMIC_TYPE_CIPHER);
return ret;
}
@@ -1114,11 +1084,7 @@ int wc_SRTCP_KDF_ex(const byte* key, word32 keySz, const byte* salt, word32 salt
{
int ret = 0;
byte block[WC_AES_BLOCK_SIZE];
#ifdef WOLFSSL_SMALL_STACK
Aes* aes = NULL;
#else
Aes aes[1];
#endif
WC_DECLARE_VAR(aes, Aes, 1, 0);
int aes_inited = 0;
int idxLen;
@@ -1177,9 +1143,7 @@ int wc_SRTCP_KDF_ex(const byte* key, word32 keySz, const byte* salt, word32 salt
if (aes_inited)
wc_AesFree(aes);
#ifdef WOLFSSL_SMALL_STACK
XFREE(aes, NULL, DYNAMIC_TYPE_CIPHER);
#endif
WC_FREE_VAR_EX(aes, NULL, DYNAMIC_TYPE_CIPHER);
return ret;
}
@@ -1219,11 +1183,7 @@ int wc_SRTP_KDF_label(const byte* key, word32 keySz, const byte* salt,
{
int ret = 0;
byte block[WC_AES_BLOCK_SIZE];
#ifdef WOLFSSL_SMALL_STACK
Aes* aes = NULL;
#else
Aes aes[1];
#endif
WC_DECLARE_VAR(aes, Aes, 1, 0);
int aes_inited = 0;
/* Validate parameters. */
@@ -1264,9 +1224,7 @@ int wc_SRTP_KDF_label(const byte* key, word32 keySz, const byte* salt,
if (aes_inited)
wc_AesFree(aes);
#ifdef WOLFSSL_SMALL_STACK
XFREE(aes, NULL, DYNAMIC_TYPE_CIPHER);
#endif
WC_FREE_VAR_EX(aes, NULL, DYNAMIC_TYPE_CIPHER);
return ret;
}
@@ -1298,11 +1256,7 @@ int wc_SRTCP_KDF_label(const byte* key, word32 keySz, const byte* salt,
{
int ret = 0;
byte block[WC_AES_BLOCK_SIZE];
#ifdef WOLFSSL_SMALL_STACK
Aes* aes = NULL;
#else
Aes aes[1];
#endif
WC_DECLARE_VAR(aes, Aes, 1, 0);
int aes_inited = 0;
/* Validate parameters. */
@@ -1343,9 +1297,7 @@ int wc_SRTCP_KDF_label(const byte* key, word32 keySz, const byte* salt,
if (aes_inited)
wc_AesFree(aes);
#ifdef WOLFSSL_SMALL_STACK
XFREE(aes, NULL, DYNAMIC_TYPE_CIPHER);
#endif
WC_FREE_VAR_EX(aes, NULL, DYNAMIC_TYPE_CIPHER);
return ret;
}
+1 -3
View File
@@ -402,9 +402,7 @@ static void wolfssl_log(const int logLevel, const char* const file_name,
if ((written > 0) && (loggingCertEnabled != 0)) {
wolfssl_log(INFO_LOG, NULL, 0, msg);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(msg, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(msg, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return 0;
} /* WOLFSSL_MSG_CERT_EX */
#endif /* XVSNPRINTF */
+4 -13
View File
@@ -137,25 +137,16 @@ void wc_Md2Final(wc_Md2* md2, byte* hash)
int wc_Md2Hash(const byte* data, word32 len, byte* hash)
{
#ifdef WOLFSSL_SMALL_STACK
wc_Md2* md2;
#else
wc_Md2 md2[1];
#endif
WC_DECLARE_VAR(md2, wc_Md2, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
md2 = (wc_Md2*)XMALLOC(sizeof(wc_Md2), NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (md2 == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(md2, wc_Md2, 1, NULL, DYNAMIC_TYPE_TMP_BUFFER,
return MEMORY_E);
wc_InitMd2(md2);
wc_Md2Update(md2, data, len);
wc_Md2Final(md2, hash);
#ifdef WOLFSSL_SMALL_STACK
XFREE(md2, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(md2, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return 0;
}
+1 -3
View File
@@ -1119,9 +1119,7 @@ static WARN_UNUSED_RESULT int freeDecCertList(WC_DerCertList** list,
current = current->next;
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(DeCert, heap, DYNAMIC_TYPE_PKCS);
#endif
WC_FREE_VAR_EX(DeCert, heap, DYNAMIC_TYPE_PKCS);
return 0;
}
+204 -436
View File
File diff suppressed because it is too large Load Diff
+9 -22
View File
@@ -1144,9 +1144,7 @@ static int wolfIoT_ecc_sign(WOLFSSL* ssl,
if (ret == 0)
ret = wc_ecc_sign_hash(in, inSz, out, outSz, rng, myKey);
wc_ecc_free(myKey);
#ifdef WOLFSSL_SMALL_STACK
XFREE(myKey, NULL, DYNAMIC_TYPE_ECC);
#endif
WC_FREE_VAR_EX(myKey, NULL, DYNAMIC_TYPE_ECC);
(void)ctx;
return ret;
@@ -1203,10 +1201,8 @@ static int wolfIoT_ecc_verify(WOLFSSL *ssl,
#endif
ret = wc_ecc_init(key);
if (ret != 0) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(key, NULL, DYNAMIC_TYPE_ECC);
XFREE(sig_raw, NULL, DYNAMIC_TYPE_SIGNATURE);
#endif
WC_FREE_VAR_EX(key, NULL, DYNAMIC_TYPE_ECC);
WC_FREE_VAR_EX(sig_raw, NULL, DYNAMIC_TYPE_SIGNATURE);
return ret;
}
@@ -1246,10 +1242,8 @@ static int wolfIoT_ecc_verify(WOLFSSL *ssl,
}
}
wc_ecc_free(key);
#ifdef WOLFSSL_SMALL_STACK
XFREE(key, NULL, DYNAMIC_TYPE_ECC);
XFREE(sig_raw, NULL, DYNAMIC_TYPE_SIGNATURE);
#endif
WC_FREE_VAR_EX(key, NULL, DYNAMIC_TYPE_ECC);
WC_FREE_VAR_EX(sig_raw, NULL, DYNAMIC_TYPE_SIGNATURE);
(void)ctx;
return ret;
}
@@ -1282,16 +1276,11 @@ static int wolfIoT_ecc_shared_secret(WOLFSSL* ssl, struct ecc_key* otherKey,
side == WOLFSSL_CLIENT_END ? "client" : "server", otherKey->dp->id);
#endif
#ifdef WOLFSSL_SMALL_STACK
tmpKey = (ecc_key*)XMALLOC(sizeof(ecc_key), NULL, DYNAMIC_TYPE_ECC);
if (tmpKey == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(tmpKey, ecc_key, 1, NULL, DYNAMIC_TYPE_ECC,
return MEMORY_E);
ret = wc_ecc_init(tmpKey);
if (ret != 0) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(tmpKey, NULL, DYNAMIC_TYPE_ECC);
#endif
WC_FREE_VAR_EX(tmpKey, NULL, DYNAMIC_TYPE_ECC);
return ret;
}
@@ -1405,9 +1394,7 @@ static int wolfIoT_ecc_shared_secret(WOLFSSL* ssl, struct ecc_key* otherKey,
}
}
wc_ecc_free(tmpKey);
#ifdef WOLFSSL_SMALL_STACK
XFREE(tmpKey, NULL, DYNAMIC_TYPE_ECC);
#endif
WC_FREE_VAR_EX(tmpKey, NULL, DYNAMIC_TYPE_ECC);
(void)ctx;
return ret;
}
+4 -16
View File
@@ -780,11 +780,7 @@ int wc_Gmac(const byte* key, word32 keySz, byte* iv, word32 ivSz,
const byte* authIn, word32 authInSz,
byte* authTag, word32 authTagSz, WC_RNG* rng)
{
#ifdef WOLFSSL_SMALL_STACK
Aes *aes = NULL;
#else
Aes aes[1];
#endif
WC_DECLARE_VAR(aes, Aes, 1, 0);
int ret;
if (key == NULL || iv == NULL || (authIn == NULL && authInSz != 0) ||
@@ -810,9 +806,7 @@ int wc_Gmac(const byte* key, word32 keySz, byte* iv, word32 ivSz,
wc_AesFree(aes);
}
ForceZero(aes, sizeof *aes);
#ifdef WOLFSSL_SMALL_STACK
XFREE(aes, NULL, DYNAMIC_TYPE_AES);
#endif
WC_FREE_VAR_EX(aes, NULL, DYNAMIC_TYPE_AES);
return ret;
}
@@ -824,11 +818,7 @@ int wc_GmacVerify(const byte* key, word32 keySz,
{
int ret;
#ifdef HAVE_AES_DECRYPT
#ifdef WOLFSSL_SMALL_STACK
Aes *aes = NULL;
#else
Aes aes[1];
#endif
WC_DECLARE_VAR(aes, Aes, 1, 0);
if (key == NULL || iv == NULL || (authIn == NULL && authInSz != 0) ||
authTag == NULL || authTagSz == 0 || authTagSz > WC_AES_BLOCK_SIZE) {
@@ -851,9 +841,7 @@ int wc_GmacVerify(const byte* key, word32 keySz,
wc_AesFree(aes);
}
ForceZero(aes, sizeof *aes);
#ifdef WOLFSSL_SMALL_STACK
XFREE(aes, NULL, DYNAMIC_TYPE_AES);
#endif
WC_FREE_VAR_EX(aes, NULL, DYNAMIC_TYPE_AES);
#else
(void)key;
(void)keySz;
+4 -13
View File
@@ -138,17 +138,10 @@ static int hashFinal(wolfssl_TI_Hash *hash, byte* result, word32 algo, word32 hs
static int hashHash(const byte* data, word32 len, byte* hash, word32 algo, word32 hsize)
{
int ret = 0;
#ifdef WOLFSSL_SMALL_STACK
wolfssl_TI_Hash* hash_desc;
#else
wolfssl_TI_Hash hash_desc[1];
#endif
WC_DECLARE_VAR(hash_desc, wolfssl_TI_Hash, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
hash_desc = (wolfssl_TI_Hash*)XMALLOC(sizeof(wolfssl_TI_Hash), NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (hash_desc == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(hash_desc, wolfssl_TI_Hash, 1, NULL,
DYNAMIC_TYPE_TMP_BUFFER, return MEMORY_E);
if ((ret = hashInit(hash_desc)) != 0) {
WOLFSSL_MSG("Hash Init failed");
@@ -158,9 +151,7 @@ static int hashHash(const byte* data, word32 len, byte* hash, word32 algo, word3
hashFinal(hash_desc, hash, algo, hsize);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(hash_desc, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(hash_desc, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
+14 -42
View File
@@ -67,11 +67,7 @@ int wc_PBKDF1_ex(byte* key, int keyLen, byte* iv, int ivLen,
int keyOutput = 0;
int digestLen;
byte digest[WC_MAX_DIGEST_SIZE];
#ifdef WOLFSSL_SMALL_STACK
wc_HashAlg* hash = NULL;
#else
wc_HashAlg hash[1];
#endif
WC_DECLARE_VAR(hash, wc_HashAlg, 1, 0);
enum wc_HashType hashT;
(void)heap;
@@ -90,18 +86,12 @@ int wc_PBKDF1_ex(byte* key, int keyLen, byte* iv, int ivLen,
digestLen = err;
/* initialize hash */
#ifdef WOLFSSL_SMALL_STACK
hash = (wc_HashAlg*)XMALLOC(sizeof(wc_HashAlg), heap,
DYNAMIC_TYPE_HASHCTX);
if (hash == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(hash, wc_HashAlg, 1, heap, DYNAMIC_TYPE_HASHCTX,
return MEMORY_E);
err = wc_HashInit_ex(hash, hashT, heap, INVALID_DEVID);
if (err != 0) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(hash, heap, DYNAMIC_TYPE_HASHCTX);
#endif
WC_FREE_VAR_EX(hash, heap, DYNAMIC_TYPE_HASHCTX);
return err;
}
@@ -160,9 +150,7 @@ int wc_PBKDF1_ex(byte* key, int keyLen, byte* iv, int ivLen,
wc_HashFree(hash, hashT);
#ifdef WOLFSSL_SMALL_STACK
XFREE(hash, heap, DYNAMIC_TYPE_HASHCTX);
#endif
WC_FREE_VAR_EX(hash, heap, DYNAMIC_TYPE_HASHCTX);
if (err != 0)
return err;
@@ -306,10 +294,8 @@ int wc_PBKDF2_ex(byte* output, const byte* passwd, int pLen, const byte* salt,
wc_HmacFree(hmac);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(buffer, heap, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(hmac, heap, DYNAMIC_TYPE_HMAC);
#endif
WC_FREE_VAR_EX(buffer, heap, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(hmac, heap, DYNAMIC_TYPE_HMAC);
return ret;
}
@@ -331,11 +317,7 @@ static int DoPKCS12Hash(int hashType, byte* buffer, word32 totalLen,
{
int i;
int ret = 0;
#ifdef WOLFSSL_SMALL_STACK
wc_HashAlg* hash = NULL;
#else
wc_HashAlg hash[1];
#endif
WC_DECLARE_VAR(hash, wc_HashAlg, 1, 0);
enum wc_HashType hashT;
if (buffer == NULL || Ai == NULL) {
@@ -345,18 +327,12 @@ static int DoPKCS12Hash(int hashType, byte* buffer, word32 totalLen,
hashT = wc_HashTypeConvert(hashType);
/* initialize hash */
#ifdef WOLFSSL_SMALL_STACK
hash = (wc_HashAlg*)XMALLOC(sizeof(wc_HashAlg), NULL,
DYNAMIC_TYPE_HASHCTX);
if (hash == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(hash, wc_HashAlg, 1, NULL, DYNAMIC_TYPE_HASHCTX,
return MEMORY_E);
ret = wc_HashInit(hash, hashT);
if (ret != 0) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(hash, NULL, DYNAMIC_TYPE_HASHCTX);
#endif
WC_FREE_VAR_EX(hash, NULL, DYNAMIC_TYPE_HASHCTX);
return ret;
}
@@ -374,9 +350,7 @@ static int DoPKCS12Hash(int hashType, byte* buffer, word32 totalLen,
wc_HashFree(hash, hashT);
#ifdef WOLFSSL_SMALL_STACK
XFREE(hash, NULL, DYNAMIC_TYPE_HASHCTX);
#endif
WC_FREE_VAR_EX(hash, NULL, DYNAMIC_TYPE_HASHCTX);
return ret;
}
@@ -476,10 +450,8 @@ int wc_PKCS12_PBKDF_ex(byte* output, const byte* passwd, int passLen,
if (totalLen > sizeof(staticBuffer)) {
buffer = (byte*)XMALLOC(totalLen, heap, DYNAMIC_TYPE_KEY);
if (buffer == NULL) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(Ai, heap, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(B, heap, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(Ai, heap, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(B, heap, DYNAMIC_TYPE_TMP_BUFFER);
return MEMORY_E;
}
dynamic = 1;
+16 -52
View File
@@ -455,22 +455,14 @@ static int Hash_df(DRBG_internal* drbg, byte* out, word32 outSz, byte type,
static int Hash_DRBG_Reseed(DRBG_internal* drbg, const byte* seed, word32 seedSz)
{
int ret;
#ifdef WOLFSSL_SMALL_STACK
byte* newV;
#else
byte newV[DRBG_SEED_LEN];
#endif
WC_DECLARE_VAR(newV, byte, DRBG_SEED_LEN, 0);
if (drbg == NULL) {
return DRBG_FAILURE;
}
#ifdef WOLFSSL_SMALL_STACK
newV = (byte*)XMALLOC(DRBG_SEED_LEN, drbg->heap, DYNAMIC_TYPE_TMP_BUFFER);
if (newV == NULL) {
return MEMORY_E;
}
#endif
WC_ALLOC_VAR_EX(newV, byte, DRBG_SEED_LEN, drbg->heap,
DYNAMIC_TYPE_TMP_BUFFER, return MEMORY_E);
XMEMSET(newV, 0, DRBG_SEED_LEN);
ret = Hash_df(drbg, newV, DRBG_SEED_LEN, drbgReseed,
@@ -486,9 +478,7 @@ static int Hash_DRBG_Reseed(DRBG_internal* drbg, const byte* seed, word32 seedSz
drbg->reseedCtr = 1;
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(newV, drbg->heap, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(newV, drbg->heap, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -602,10 +592,8 @@ static int Hash_gen(DRBG_internal* drbg, byte* out, word32 outSz, const byte* V)
}
ForceZero(data, DRBG_SEED_LEN);
#ifdef WOLFSSL_SMALL_STACK
XFREE(digest, drbg->heap, DYNAMIC_TYPE_DIGEST);
XFREE(data, drbg->heap, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(digest, drbg->heap, DYNAMIC_TYPE_DIGEST);
WC_FREE_VAR_EX(data, drbg->heap, DYNAMIC_TYPE_TMP_BUFFER);
return (ret == 0) ? DRBG_SUCCESS : DRBG_FAILURE;
}
@@ -1494,20 +1482,13 @@ static wolfSSL_Mutex entropy_mutex WOLFSSL_MUTEX_INITIALIZER_CLAUSE(entropy_mute
int wc_Entropy_Get(int bits, unsigned char* entropy, word32 len)
{
int ret = 0;
#ifdef WOLFSSL_SMALL_STACK
byte *noise = NULL;
#else
byte noise[MAX_NOISE_CNT];
#endif
WC_DECLARE_VAR(noise, byte, MAX_NOISE_CNT, 0);
/* Noise length is the number of 8 byte samples required to get the bits of
* entropy requested. */
int noise_len = (bits + ENTROPY_EXTRA) / ENTROPY_MIN;
#ifdef WOLFSSL_SMALL_STACK
noise = (byte *)XMALLOC(MAX_NOISE_CNT, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (noise == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(noise, byte, MAX_NOISE_CNT, NULL, DYNAMIC_TYPE_TMP_BUFFER,
return MEMORY_E);
/* Lock the mutex as collection uses globals. */
if ((ret == 0) && (wc_LockMutex(&entropy_mutex) != 0)) {
@@ -1568,9 +1549,7 @@ int wc_Entropy_Get(int bits, unsigned char* entropy, word32 len)
wc_UnLockMutex(&entropy_mutex);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(noise, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(noise, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -1841,9 +1820,7 @@ static int _InitRng(WC_RNG* rng, byte* nonce, word32 nonceSz,
} /* ret == 0 */
ForceZero(seed, seedSz);
#ifdef WOLFSSL_SMALL_STACK
XFREE(seed, rng->heap, DYNAMIC_TYPE_SEED);
#endif
WC_FREE_VAR_EX(seed, rng->heap, DYNAMIC_TYPE_SEED);
} /* else swc_RNG_HealthTestLocal was successful */
if (ret == DRBG_SUCCESS) {
@@ -2231,9 +2208,7 @@ exit_rng_ht:
ret = -1;
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(drbg, heap, DYNAMIC_TYPE_RNG);
#endif
WC_FREE_VAR_EX(drbg, heap, DYNAMIC_TYPE_RNG);
return ret;
}
@@ -2292,19 +2267,10 @@ const FLASH_QUALIFIER byte outputB_data[] = {
static int wc_RNG_HealthTestLocal(int reseed, void* heap, int devId)
{
int ret = 0;
#ifdef WOLFSSL_SMALL_STACK
byte* check;
#else
byte check[RNG_HEALTH_TEST_CHECK_SIZE];
#endif
WC_DECLARE_VAR(check, byte, RNG_HEALTH_TEST_CHECK_SIZE, 0);
#ifdef WOLFSSL_SMALL_STACK
check = (byte*)XMALLOC(RNG_HEALTH_TEST_CHECK_SIZE, heap,
DYNAMIC_TYPE_TMP_BUFFER);
if (check == NULL) {
return MEMORY_E;
}
#endif
WC_ALLOC_VAR_EX(check, byte, RNG_HEALTH_TEST_CHECK_SIZE, heap,
DYNAMIC_TYPE_TMP_BUFFER, return MEMORY_E);
if (reseed) {
#ifdef WOLFSSL_USE_FLASHMEM
@@ -2418,9 +2384,7 @@ static int wc_RNG_HealthTestLocal(int reseed, void* heap, int devId)
#endif
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(check, heap, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(check, heap, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
+21 -49
View File
@@ -703,11 +703,7 @@ static int _ifc_pairwise_consistency_test(RsaKey* key, WC_RNG* rng)
int wc_CheckRsaKey(RsaKey* key)
{
#ifdef WOLFSSL_SMALL_STACK
WC_RNG *rng = NULL;
#else
WC_RNG rng[1];
#endif
WC_DECLARE_VAR(rng, WC_RNG, 1, 0);
int ret = 0;
DECL_MP_INT_SIZE_DYN(tmp, (key)? mp_bitsused(&key->n) : 0, RSA_MAX_SIZE);
@@ -722,12 +718,8 @@ int wc_CheckRsaKey(RsaKey* key)
}
#endif
#ifdef WOLFSSL_SMALL_STACK
rng = (WC_RNG*)XMALLOC(sizeof(WC_RNG), NULL, DYNAMIC_TYPE_RNG);
if (rng == NULL) {
return MEMORY_E;
}
#endif
WC_ALLOC_VAR_EX(rng, WC_RNG, 1, NULL, DYNAMIC_TYPE_RNG,
return MEMORY_E);
NEW_MP_INT_SIZE(tmp, mp_bitsused(&key->n), NULL, DYNAMIC_TYPE_RSA);
#ifdef MP_INT_SIZE_CHECK_NULL
if (tmp == NULL) {
@@ -1126,10 +1118,8 @@ static int RsaPad_OAEP(const byte* input, word32 inputLen, byte* pkcsBlock,
if ((ret = wc_Hash(hType, optLabel, labelLen, lHash, hLen)) != 0) {
WOLFSSL_MSG("OAEP hash type possibly not supported or lHash to small");
#ifdef WOLFSSL_SMALL_STACK
XFREE(lHash, heap, DYNAMIC_TYPE_RSA_BUFFER);
XFREE(seed, heap, DYNAMIC_TYPE_RSA_BUFFER);
#endif
WC_FREE_VAR_EX(lHash, heap, DYNAMIC_TYPE_RSA_BUFFER);
WC_FREE_VAR_EX(seed, heap, DYNAMIC_TYPE_RSA_BUFFER);
return ret;
}
@@ -1143,19 +1133,15 @@ static int RsaPad_OAEP(const byte* input, word32 inputLen, byte* pkcsBlock,
*/
if ((2 * hLen + 2) > pkcsBlockLen) {
WOLFSSL_MSG("OAEP pad error hash to big for RSA key size");
#ifdef WOLFSSL_SMALL_STACK
XFREE(lHash, heap, DYNAMIC_TYPE_RSA_BUFFER);
XFREE(seed, heap, DYNAMIC_TYPE_RSA_BUFFER);
#endif
WC_FREE_VAR_EX(lHash, heap, DYNAMIC_TYPE_RSA_BUFFER);
WC_FREE_VAR_EX(seed, heap, DYNAMIC_TYPE_RSA_BUFFER);
return BAD_FUNC_ARG;
}
if (inputLen > (pkcsBlockLen - 2 * hLen - 2)) {
WOLFSSL_MSG("OAEP pad error message too long");
#ifdef WOLFSSL_SMALL_STACK
XFREE(lHash, heap, DYNAMIC_TYPE_RSA_BUFFER);
XFREE(seed, heap, DYNAMIC_TYPE_RSA_BUFFER);
#endif
WC_FREE_VAR_EX(lHash, heap, DYNAMIC_TYPE_RSA_BUFFER);
WC_FREE_VAR_EX(seed, heap, DYNAMIC_TYPE_RSA_BUFFER);
return BAD_FUNC_ARG;
}
@@ -1163,10 +1149,8 @@ static int RsaPad_OAEP(const byte* input, word32 inputLen, byte* pkcsBlock,
idx = pkcsBlockLen - 1 - inputLen;
psLen = (int)pkcsBlockLen - (int)inputLen - 2 * (int)hLen - 2;
if (pkcsBlockLen < inputLen) { /*make sure not writing over end of buffer */
#ifdef WOLFSSL_SMALL_STACK
XFREE(lHash, heap, DYNAMIC_TYPE_RSA_BUFFER);
XFREE(seed, heap, DYNAMIC_TYPE_RSA_BUFFER);
#endif
WC_FREE_VAR_EX(lHash, heap, DYNAMIC_TYPE_RSA_BUFFER);
WC_FREE_VAR_EX(seed, heap, DYNAMIC_TYPE_RSA_BUFFER);
return BUFFER_E;
}
XMEMCPY(pkcsBlock + (pkcsBlockLen - inputLen), input, inputLen);
@@ -1179,10 +1163,8 @@ static int RsaPad_OAEP(const byte* input, word32 inputLen, byte* pkcsBlock,
/* generate random seed */
if ((ret = wc_RNG_GenerateBlock(rng, seed, hLen)) != 0) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(lHash, heap, DYNAMIC_TYPE_RSA_BUFFER);
XFREE(seed, heap, DYNAMIC_TYPE_RSA_BUFFER);
#endif
WC_FREE_VAR_EX(lHash, heap, DYNAMIC_TYPE_RSA_BUFFER);
WC_FREE_VAR_EX(seed, heap, DYNAMIC_TYPE_RSA_BUFFER);
return ret;
}
@@ -1203,29 +1185,23 @@ static int RsaPad_OAEP(const byte* input, word32 inputLen, byte* pkcsBlock,
XMEMSET(dbMask, 0, pkcsBlockLen - hLen - 1); /* help static analyzer */
ret = RsaMGF(mgf, seed, hLen, dbMask, pkcsBlockLen - hLen - 1, heap);
if (ret != 0) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(dbMask, heap, DYNAMIC_TYPE_RSA);
XFREE(lHash, heap, DYNAMIC_TYPE_RSA_BUFFER);
XFREE(seed, heap, DYNAMIC_TYPE_RSA_BUFFER);
#endif
WC_FREE_VAR_EX(dbMask, heap, DYNAMIC_TYPE_RSA);
WC_FREE_VAR_EX(lHash, heap, DYNAMIC_TYPE_RSA_BUFFER);
WC_FREE_VAR_EX(seed, heap, DYNAMIC_TYPE_RSA_BUFFER);
return ret;
}
xorbuf(pkcsBlock + hLen + 1, dbMask,pkcsBlockLen - hLen - 1);
#ifdef WOLFSSL_SMALL_STACK
XFREE(dbMask, heap, DYNAMIC_TYPE_RSA);
#endif
WC_FREE_VAR_EX(dbMask, heap, DYNAMIC_TYPE_RSA);
/* create maskedSeed from seedMask */
pkcsBlock[0] = 0x00;
/* create seedMask inline */
if ((ret = RsaMGF(mgf, pkcsBlock + hLen + 1, pkcsBlockLen - hLen - 1,
pkcsBlock + 1, hLen, heap)) != 0) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(lHash, heap, DYNAMIC_TYPE_RSA_BUFFER);
XFREE(seed, heap, DYNAMIC_TYPE_RSA_BUFFER);
#endif
WC_FREE_VAR_EX(lHash, heap, DYNAMIC_TYPE_RSA_BUFFER);
WC_FREE_VAR_EX(seed, heap, DYNAMIC_TYPE_RSA_BUFFER);
return ret;
}
@@ -1599,9 +1575,7 @@ static int RsaUnPad_OAEP(byte *pkcsBlock, unsigned int pkcsBlockLen,
/* find seedMask value */
if ((ret = RsaMGF(mgf, (byte*)(pkcsBlock + (hLen + 1)),
pkcsBlockLen - hLen - 1, tmp, hLen, heap)) != 0) {
#ifdef WOLFSSL_SMALL_STACK
XFREE(tmp, heap, DYNAMIC_TYPE_RSA_BUFFER);
#endif
WC_FREE_VAR_EX(tmp, heap, DYNAMIC_TYPE_RSA_BUFFER);
return ret;
}
@@ -5311,9 +5285,7 @@ static int CalcDX(mp_int* y, mp_int* x, mp_int* d)
mp_forcezero(m);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(m, NULL, DYNAMIC_TYPE_WOLF_BIGINT);
#endif
WC_FREE_VAR_EX(m, NULL, DYNAMIC_TYPE_WOLF_BIGINT);
return err;
}
+4 -15
View File
@@ -1107,32 +1107,21 @@ void wc_ShaFree(wc_Sha* sha)
int wc_ShaGetHash(wc_Sha* sha, byte* hash)
{
int ret;
#ifdef WOLFSSL_SMALL_STACK
wc_Sha* tmpSha;
#else
wc_Sha tmpSha[1];
#endif
WC_DECLARE_VAR(tmpSha, wc_Sha, 1, 0);
if (sha == NULL || hash == NULL) {
return BAD_FUNC_ARG;
}
#ifdef WOLFSSL_SMALL_STACK
tmpSha = (wc_Sha*)XMALLOC(sizeof(wc_Sha), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (tmpSha == NULL) {
return MEMORY_E;
}
#endif
WC_ALLOC_VAR_EX(tmpSha, wc_Sha, 1, NULL, DYNAMIC_TYPE_TMP_BUFFER,
return MEMORY_E);
ret = wc_ShaCopy(sha, tmpSha);
if (ret == 0) {
ret = wc_ShaFinal(tmpSha, hash);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(tmpSha, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(tmpSha, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
+8 -30
View File
@@ -2430,23 +2430,14 @@ int wc_Sha224_Grow(wc_Sha224* sha224, const byte* in, int inSz)
int wc_Sha224GetHash(wc_Sha224* sha224, byte* hash)
{
int ret;
#ifdef WOLFSSL_SMALL_STACK
wc_Sha224* tmpSha224;
#else
wc_Sha224 tmpSha224[1];
#endif
WC_DECLARE_VAR(tmpSha224, wc_Sha224, 1, 0);
if (sha224 == NULL || hash == NULL) {
return BAD_FUNC_ARG;
}
#ifdef WOLFSSL_SMALL_STACK
tmpSha224 = (wc_Sha224*)XMALLOC(sizeof(wc_Sha224), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (tmpSha224 == NULL) {
return MEMORY_E;
}
#endif
WC_ALLOC_VAR_EX(tmpSha224, wc_Sha224, 1, NULL,
DYNAMIC_TYPE_TMP_BUFFER, return MEMORY_E);
ret = wc_Sha224Copy(sha224, tmpSha224);
if (ret == 0) {
@@ -2454,9 +2445,7 @@ int wc_Sha224_Grow(wc_Sha224* sha224, const byte* in, int inSz)
wc_Sha224Free(tmpSha224);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(tmpSha224, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(tmpSha224, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -2566,23 +2555,14 @@ int wc_Sha224_Grow(wc_Sha224* sha224, const byte* in, int inSz)
int wc_Sha256GetHash(wc_Sha256* sha256, byte* hash)
{
int ret;
#ifdef WOLFSSL_SMALL_STACK
wc_Sha256* tmpSha256;
#else
wc_Sha256 tmpSha256[1];
#endif
WC_DECLARE_VAR(tmpSha256, wc_Sha256, 1, 0);
if (sha256 == NULL || hash == NULL) {
return BAD_FUNC_ARG;
}
#ifdef WOLFSSL_SMALL_STACK
tmpSha256 = (wc_Sha256*)XMALLOC(sizeof(wc_Sha256), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (tmpSha256 == NULL) {
return MEMORY_E;
}
#endif
WC_ALLOC_VAR_EX(tmpSha256, wc_Sha256, 1, NULL, DYNAMIC_TYPE_TMP_BUFFER,
return MEMORY_E);
ret = wc_Sha256Copy(sha256, tmpSha256);
if (ret == 0) {
@@ -2591,9 +2571,7 @@ int wc_Sha256GetHash(wc_Sha256* sha256, byte* hash)
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(tmpSha256, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(tmpSha256, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
+10 -35
View File
@@ -1545,11 +1545,8 @@ int wc_Sha512Transform(wc_Sha512* sha, const unsigned char* data)
{
int ret;
/* back up buffer */
#ifdef WOLFSSL_SMALL_STACK
word64 *buffer;
#else
word64 buffer[WC_SHA512_BLOCK_SIZE / sizeof(word64)];
#endif
WC_DECLARE_VAR(buffer, word64, WC_SHA512_BLOCK_SIZE / sizeof(word64),
0);
/* sanity check */
if (sha == NULL || data == NULL) {
@@ -2001,23 +1998,14 @@ static int Sha512_Family_GetHash(wc_Sha512* sha512, byte* hash,
int (*finalfp)(wc_Sha512*, byte*))
{
int ret;
#ifdef WOLFSSL_SMALL_STACK
wc_Sha512* tmpSha512;
#else
wc_Sha512 tmpSha512[1];
#endif
WC_DECLARE_VAR(tmpSha512, wc_Sha512, 1, 0);
if (sha512 == NULL || hash == NULL) {
return BAD_FUNC_ARG;
}
#ifdef WOLFSSL_SMALL_STACK
tmpSha512 = (wc_Sha512*)XMALLOC(sizeof(wc_Sha512), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (tmpSha512 == NULL) {
return MEMORY_E;
}
#endif
WC_ALLOC_VAR_EX(tmpSha512, wc_Sha512, 1, NULL, DYNAMIC_TYPE_TMP_BUFFER,
return MEMORY_E);
/* copy this sha512 into tmpSha */
ret = wc_Sha512Copy(sha512, tmpSha512);
@@ -2026,9 +2014,7 @@ static int Sha512_Family_GetHash(wc_Sha512* sha512, byte* hash,
wc_Sha512Free(tmpSha512);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(tmpSha512, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(tmpSha512, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -2431,23 +2417,14 @@ int wc_Sha512_256Transform(wc_Sha512* sha, const unsigned char* data)
int wc_Sha384GetHash(wc_Sha384* sha384, byte* hash)
{
int ret;
#ifdef WOLFSSL_SMALL_STACK
wc_Sha384* tmpSha384;
#else
wc_Sha384 tmpSha384[1];
#endif
WC_DECLARE_VAR(tmpSha384, wc_Sha384, 1, 0);
if (sha384 == NULL || hash == NULL) {
return BAD_FUNC_ARG;
}
#ifdef WOLFSSL_SMALL_STACK
tmpSha384 = (wc_Sha384*)XMALLOC(sizeof(wc_Sha384), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (tmpSha384 == NULL) {
return MEMORY_E;
}
#endif
WC_ALLOC_VAR_EX(tmpSha384, wc_Sha384, 1, NULL, DYNAMIC_TYPE_TMP_BUFFER,
return MEMORY_E);
/* copy this sha384 into tmpSha */
ret = wc_Sha384Copy(sha384, tmpSha384);
@@ -2456,9 +2433,7 @@ int wc_Sha384GetHash(wc_Sha384* sha384, byte* hash)
wc_Sha384Free(tmpSha384);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(tmpSha384, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(tmpSha384, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
+6 -24
View File
@@ -473,11 +473,7 @@ int wc_SrpSetPassword(Srp* srp, const byte* password, word32 size)
int wc_SrpGetVerifier(Srp* srp, byte* verifier, word32* size)
{
#ifdef WOLFSSL_SMALL_STACK
mp_int *v = NULL;
#else
mp_int v[1];
#endif
WC_DECLARE_VAR(v, mp_int, 1, 0);
int r;
if (!srp || !verifier || !size || srp->side != SRP_CLIENT_SIDE)
@@ -501,9 +497,7 @@ int wc_SrpGetVerifier(Srp* srp, byte* verifier, word32* size)
if (!r) *size = (word32)mp_unsigned_bin_size(v);
mp_clear(v);
#ifdef WOLFSSL_SMALL_STACK
XFREE(v, srp->heap, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(v, srp->heap, DYNAMIC_TYPE_TMP_BUFFER);
return r;
}
@@ -518,11 +512,7 @@ int wc_SrpSetVerifier(Srp* srp, const byte* verifier, word32 size)
int wc_SrpSetPrivate(Srp* srp, const byte* priv, word32 size)
{
#ifdef WOLFSSL_SMALL_STACK
mp_int *p = NULL;
#else
mp_int p[1];
#endif
WC_DECLARE_VAR(p, mp_int, 1, 0);
int r;
if (!srp || !priv || !size)
@@ -544,9 +534,7 @@ int wc_SrpSetPrivate(Srp* srp, const byte* priv, word32 size)
if (!r) r = mp_iszero(&srp->priv) == MP_YES ? SRP_BAD_KEY_E : 0;
mp_clear(p);
#ifdef WOLFSSL_SMALL_STACK
XFREE(p, srp->heap, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(p, srp->heap, DYNAMIC_TYPE_TMP_BUFFER);
return r;
}
@@ -566,11 +554,7 @@ static int wc_SrpGenPrivate(Srp* srp, byte* priv, word32 size)
int wc_SrpGetPublic(Srp* srp, byte* pub, word32* size)
{
#ifdef WOLFSSL_SMALL_STACK
mp_int *pubkey = NULL;
#else
mp_int pubkey[1];
#endif
WC_DECLARE_VAR(pubkey, mp_int, 1, 0);
word32 modulusSz;
int r;
int hashSize;
@@ -649,9 +633,7 @@ int wc_SrpGetPublic(Srp* srp, byte* pub, word32* size)
if (!r) *size = (word32)mp_unsigned_bin_size(pubkey);
mp_clear(pubkey);
#ifdef WOLFSSL_SMALL_STACK
XFREE(pubkey, srp->heap, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(pubkey, srp->heap, DYNAMIC_TYPE_TMP_BUFFER);
return r;
}
+184 -615
View File
File diff suppressed because it is too large Load Diff
+32 -108
View File
@@ -44,21 +44,14 @@ int wc_AesCbcDecryptWithKey(byte* out, const byte* in, word32 inSz,
const byte* key, word32 keySz, const byte* iv)
{
int ret = 0;
#ifdef WOLFSSL_SMALL_STACK
Aes* aes = NULL;
#else
Aes aes[1];
#endif
WC_DECLARE_VAR(aes, Aes, 1, 0);
if (out == NULL || in == NULL || key == NULL || iv == NULL) {
return BAD_FUNC_ARG;
}
#ifdef WOLFSSL_SMALL_STACK
aes = (Aes*)XMALLOC(sizeof(Aes), NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (aes == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(aes, Aes, 1, NULL, DYNAMIC_TYPE_TMP_BUFFER,
return MEMORY_E);
ret = wc_AesInit(aes, NULL, INVALID_DEVID);
if (ret == 0) {
@@ -69,9 +62,7 @@ int wc_AesCbcDecryptWithKey(byte* out, const byte* in, word32 inSz,
wc_AesFree(aes);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(aes, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(aes, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -81,17 +72,10 @@ int wc_AesCbcEncryptWithKey(byte* out, const byte* in, word32 inSz,
const byte* key, word32 keySz, const byte* iv)
{
int ret = 0;
#ifdef WOLFSSL_SMALL_STACK
Aes* aes;
#else
Aes aes[1];
#endif
WC_DECLARE_VAR(aes, Aes, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
aes = (Aes*)XMALLOC(sizeof(Aes), NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (aes == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(aes, Aes, 1, NULL, DYNAMIC_TYPE_TMP_BUFFER,
return MEMORY_E);
ret = wc_AesInit(aes, NULL, INVALID_DEVID);
if (ret == 0) {
@@ -102,9 +86,7 @@ int wc_AesCbcEncryptWithKey(byte* out, const byte* in, word32 inSz,
wc_AesFree(aes);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(aes, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(aes, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -116,25 +98,16 @@ int wc_Des_CbcEncryptWithKey(byte* out, const byte* in, word32 sz,
const byte* key, const byte* iv)
{
int ret = 0;
#ifdef WOLFSSL_SMALL_STACK
Des* des;
#else
Des des[1];
#endif
WC_DECLARE_VAR(des, Des, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
des = (Des*)XMALLOC(sizeof(Des), NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (des == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(des, Des, 1, NULL, DYNAMIC_TYPE_TMP_BUFFER,
return MEMORY_E);
ret = wc_Des_SetKey(des, key, iv, DES_ENCRYPTION);
if (ret == 0)
ret = wc_Des_CbcEncrypt(des, out, in, sz);
#ifdef WOLFSSL_SMALL_STACK
XFREE(des, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(des, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -143,25 +116,16 @@ int wc_Des_CbcDecryptWithKey(byte* out, const byte* in, word32 sz,
const byte* key, const byte* iv)
{
int ret = 0;
#ifdef WOLFSSL_SMALL_STACK
Des* des;
#else
Des des[1];
#endif
WC_DECLARE_VAR(des, Des, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
des = (Des*)XMALLOC(sizeof(Des), NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (des == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(des, Des, 1, NULL, DYNAMIC_TYPE_TMP_BUFFER,
return MEMORY_E);
ret = wc_Des_SetKey(des, key, iv, DES_DECRYPTION);
if (ret == 0)
ret = wc_Des_CbcDecrypt(des, out, in, sz);
#ifdef WOLFSSL_SMALL_STACK
XFREE(des, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(des, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -171,17 +135,10 @@ int wc_Des3_CbcEncryptWithKey(byte* out, const byte* in, word32 sz,
const byte* key, const byte* iv)
{
int ret = 0;
#ifdef WOLFSSL_SMALL_STACK
Des3* des3;
#else
Des3 des3[1];
#endif
WC_DECLARE_VAR(des3, Des3, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
des3 = (Des3*)XMALLOC(sizeof(Des3), NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (des3 == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(des3, Des3, 1, NULL, DYNAMIC_TYPE_TMP_BUFFER,
return MEMORY_E);
ret = wc_Des3Init(des3, NULL, INVALID_DEVID);
if (ret == 0) {
@@ -191,9 +148,7 @@ int wc_Des3_CbcEncryptWithKey(byte* out, const byte* in, word32 sz,
wc_Des3Free(des3);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(des3, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(des3, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -203,17 +158,10 @@ int wc_Des3_CbcDecryptWithKey(byte* out, const byte* in, word32 sz,
const byte* key, const byte* iv)
{
int ret = 0;
#ifdef WOLFSSL_SMALL_STACK
Des3* des3;
#else
Des3 des3[1];
#endif
WC_DECLARE_VAR(des3, Des3, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
des3 = (Des3*)XMALLOC(sizeof(Des3), NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (des3 == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(des3, Des3, 1, NULL, DYNAMIC_TYPE_TMP_BUFFER,
return MEMORY_E);
ret = wc_Des3Init(des3, NULL, INVALID_DEVID);
if (ret == 0) {
@@ -223,9 +171,7 @@ int wc_Des3_CbcDecryptWithKey(byte* out, const byte* in, word32 sz,
wc_Des3Free(des3);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(des3, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(des3, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -239,11 +185,7 @@ int wc_BufferKeyDecrypt(EncryptedInfo* info, byte* der, word32 derSz,
const byte* password, int passwordSz, int hashType)
{
int ret = WC_NO_ERR_TRACE(NOT_COMPILED_IN);
#ifdef WOLFSSL_SMALL_STACK
byte* key = NULL;
#else
byte key[WC_MAX_SYM_KEY_SIZE];
#endif
WC_DECLARE_VAR(key, byte, WC_MAX_SYM_KEY_SIZE, 0);
(void)derSz;
(void)passwordSz;
@@ -263,12 +205,8 @@ int wc_BufferKeyDecrypt(EncryptedInfo* info, byte* der, word32 derSz,
return BUFFER_E;
}
#ifdef WOLFSSL_SMALL_STACK
key = (byte*)XMALLOC(WC_MAX_SYM_KEY_SIZE, NULL, DYNAMIC_TYPE_SYMMETRIC_KEY);
if (key == NULL) {
return MEMORY_E;
}
#endif
WC_ALLOC_VAR_EX(key, byte, WC_MAX_SYM_KEY_SIZE, NULL,
DYNAMIC_TYPE_SYMMETRIC_KEY, return MEMORY_E);
#ifdef WOLFSSL_CHECK_MEM_ZERO
wc_MemZero_Add("wc_BufferKeyDecrypt key", key, WC_MAX_SYM_KEY_SIZE);
#endif
@@ -313,11 +251,7 @@ int wc_BufferKeyEncrypt(EncryptedInfo* info, byte* der, word32 derSz,
const byte* password, int passwordSz, int hashType)
{
int ret = WC_NO_ERR_TRACE(NOT_COMPILED_IN);
#ifdef WOLFSSL_SMALL_STACK
byte* key = NULL;
#else
byte key[WC_MAX_SYM_KEY_SIZE];
#endif
WC_DECLARE_VAR(key, byte, WC_MAX_SYM_KEY_SIZE, 0);
(void)derSz;
(void)passwordSz;
@@ -328,12 +262,8 @@ int wc_BufferKeyEncrypt(EncryptedInfo* info, byte* der, word32 derSz,
return BAD_FUNC_ARG;
}
#ifdef WOLFSSL_SMALL_STACK
key = (byte*)XMALLOC(WC_MAX_SYM_KEY_SIZE, NULL, DYNAMIC_TYPE_SYMMETRIC_KEY);
if (key == NULL) {
return MEMORY_E;
}
#endif /* WOLFSSL_SMALL_STACK */
WC_ALLOC_VAR_EX(key, byte, WC_MAX_SYM_KEY_SIZE, NULL,
DYNAMIC_TYPE_SYMMETRIC_KEY, return MEMORY_E);
#ifdef WOLFSSL_CHECK_MEM_ZERO
XMEMSET(key, 0xff, WC_MAX_SYM_KEY_SIZE);
wc_MemZero_Add("wc_BufferKeyDecrypt key", key, WC_MAX_SYM_KEY_SIZE);
@@ -392,11 +322,7 @@ int wc_CryptKey(const char* password, int passwordSz, byte* salt,
int typeH = WC_HASH_TYPE_NONE;
word32 derivedLen = 0;
int ret = 0;
#ifdef WOLFSSL_SMALL_STACK
byte* key = NULL;
#else
byte key[PKCS_MAX_KEY_SIZE];
#endif
WC_DECLARE_VAR(key, byte, PKCS_MAX_KEY_SIZE, 0);
(void)input;
(void)length;
@@ -687,9 +613,7 @@ int wc_CryptKey(const char* password, int passwordSz, byte* salt,
if (free_aes)
wc_AesFree(aes);
ForceZero(aes, sizeof(Aes));
#ifdef WOLFSSL_SMALL_STACK
XFREE(aes, NULL, DYNAMIC_TYPE_AES);
#endif
WC_FREE_VAR_EX(aes, NULL, DYNAMIC_TYPE_AES);
break;
}
#endif /* !NO_AES && HAVE_AES_CBC && (WOLFSSL_AES_256 || WOLFSSL_AES_128) */
+20 -64
View File
@@ -764,21 +764,12 @@ int wc_LmsKey_MakeKey(LmsKey* key, WC_RNG* rng)
#endif
}
if (ret == 0) {
#ifdef WOLFSSL_SMALL_STACK
LmsState* state;
#else
LmsState state[1];
#endif
WC_DECLARE_VAR(state, LmsState, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
/* Allocate memory for working state. */
state = (LmsState*)XMALLOC(sizeof(LmsState), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (state == NULL) {
ret = MEMORY_E;
}
if (ret == 0)
#endif
WC_ALLOC_VAR_EX(state, LmsState, 1, NULL, DYNAMIC_TYPE_TMP_BUFFER,
ret=MEMORY_E);
if (WC_VAR_OK(state))
{
/* Initialize working state for use. */
ret = wc_lmskey_state_init(state, key->params);
@@ -789,9 +780,7 @@ int wc_LmsKey_MakeKey(LmsKey* key, WC_RNG* rng)
wc_lmskey_state_free(state);
}
ForceZero(state, sizeof(LmsState));
#ifdef WOLFSSL_SMALL_STACK
XFREE(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
}
if (ret == 0) {
@@ -911,21 +900,12 @@ int wc_LmsKey_Reload(LmsKey* key)
}
if (ret == 0) {
#ifdef WOLFSSL_SMALL_STACK
LmsState* state;
#else
LmsState state[1];
#endif
WC_DECLARE_VAR(state, LmsState, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
/* Allocate memory for working state. */
state = (LmsState*)XMALLOC(sizeof(LmsState), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (state == NULL) {
ret = MEMORY_E;
}
if (ret == 0)
#endif
WC_ALLOC_VAR_EX(state, LmsState, 1, NULL, DYNAMIC_TYPE_TMP_BUFFER,
ret=MEMORY_E);
if (WC_VAR_OK(state))
{
/* Initialize working state for use. */
ret = wc_lmskey_state_init(state, key->params);
@@ -935,9 +915,7 @@ int wc_LmsKey_Reload(LmsKey* key)
key->priv_data, NULL);
}
ForceZero(state, sizeof(LmsState));
#ifdef WOLFSSL_SMALL_STACK
XFREE(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
}
@@ -1010,21 +988,12 @@ int wc_LmsKey_Sign(LmsKey* key, byte* sig, word32* sigSz, const byte* msg,
}
if (ret == 0) {
#ifdef WOLFSSL_SMALL_STACK
LmsState* state;
#else
LmsState state[1];
#endif
WC_DECLARE_VAR(state, LmsState, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
/* Allocate memory for working state. */
state = (LmsState*)XMALLOC(sizeof(LmsState), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (state == NULL) {
ret = MEMORY_E;
}
if (ret == 0)
#endif
WC_ALLOC_VAR_EX(state, LmsState, 1, NULL, DYNAMIC_TYPE_TMP_BUFFER,
ret=MEMORY_E);
if (WC_VAR_OK(state))
{
/* Initialize working state for use. */
ret = wc_lmskey_state_init(state, key->params);
@@ -1035,9 +1004,7 @@ int wc_LmsKey_Sign(LmsKey* key, byte* sig, word32* sigSz, const byte* msg,
wc_lmskey_state_free(state);
}
ForceZero(state, sizeof(LmsState));
#ifdef WOLFSSL_SMALL_STACK
XFREE(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
}
if (ret == 0) {
@@ -1288,21 +1255,12 @@ int wc_LmsKey_Verify(LmsKey* key, const byte* sig, word32 sigSz,
}
if (ret == 0) {
#ifdef WOLFSSL_SMALL_STACK
LmsState* state;
#else
LmsState state[1];
#endif
WC_DECLARE_VAR(state, LmsState, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
/* Allocate memory for working state. */
state = (LmsState*)XMALLOC(sizeof(LmsState), NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (state == NULL) {
ret = MEMORY_E;
}
if (ret == 0)
#endif
WC_ALLOC_VAR_EX(state, LmsState, 1, NULL, DYNAMIC_TYPE_TMP_BUFFER,
ret=MEMORY_E);
if (WC_VAR_OK(state))
{
/* Initialize working state for use. */
ret = wc_lmskey_state_init(state, key->params);
@@ -1312,9 +1270,7 @@ int wc_LmsKey_Verify(LmsKey* key, const byte* sig, word32 sigSz,
wc_lmskey_state_free(state);
}
ForceZero(state, sizeof(LmsState));
#ifdef WOLFSSL_SMALL_STACK
XFREE(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
}
+12 -45
View File
@@ -1797,25 +1797,16 @@ static int wc_lms_treehash(LmsState* state, const byte* id, const byte* seed,
byte* dp = rp + LMS_R_LEN;
byte* left = dp + LMS_D_LEN;
byte* temp = left + params->hash_len;
#ifdef WOLFSSL_SMALL_STACK
byte* stack = NULL;
#else
byte stack[(LMS_MAX_HEIGHT + 1) * LMS_MAX_NODE_LEN];
#endif /* WOLFSSL_SMALL_STACK */
WC_DECLARE_VAR(stack, byte, (LMS_MAX_HEIGHT + 1) * LMS_MAX_NODE_LEN, 0);
byte* sp;
word32 i;
/* I || ... */
XMEMCPY(buffer, id, LMS_I_LEN);
#ifdef WOLFSSL_SMALL_STACK
/* Allocate stack of left side hashes. */
stack = XMALLOC((params->height + 1) * params->hash_len, NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (stack == NULL) {
ret = MEMORY_E;
}
#endif /* WOLFSSL_SMALL_STACK */
WC_ALLOC_VAR_EX(stack, byte, (params->height+1)*params->hash_len, NULL,
DYNAMIC_TYPE_TMP_BUFFER, ret=MEMORY_E);
sp = stack;
/* Compute all nodes requested. */
@@ -1863,9 +1854,7 @@ static int wc_lms_treehash(LmsState* state, const byte* id, const byte* seed,
/* Public key, root node, is top of data stack. */
XMEMCPY(pub, stack, params->hash_len);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(stack, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif /* WOLFSSL_SMALL_STACK */
WC_FREE_VAR_EX(stack, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -1936,11 +1925,7 @@ static int wc_lms_treehash_init(LmsState* state, LmsPrivState* privState,
byte* dp = rp + LMS_R_LEN;
byte* left = dp + LMS_D_LEN;
byte* temp = left + params->hash_len;
#ifdef WOLFSSL_SMALL_STACK
byte* stack = NULL;
#else
byte stack[(LMS_MAX_HEIGHT + 1) * LMS_MAX_NODE_LEN];
#endif /* WOLFSSL_SMALL_STACK */
WC_DECLARE_VAR(stack, byte, (LMS_MAX_HEIGHT + 1) * LMS_MAX_NODE_LEN, 0);
word32 spi = 0;
word32 i;
word32 max_h = (word32)1 << params->height;
@@ -1957,14 +1942,9 @@ static int wc_lms_treehash_init(LmsState* state, LmsPrivState* privState,
/* I || ... */
XMEMCPY(buffer, id, LMS_I_LEN);
#ifdef WOLFSSL_SMALL_STACK
/* Allocate stack of left side hashes. */
stack = (byte*)XMALLOC((params->height + 1) * params->hash_len, NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (stack == NULL) {
ret = MEMORY_E;
}
#endif /* WOLFSSL_SMALL_STACK */
WC_ALLOC_VAR_EX(stack, byte, (params->height+1)*params->hash_len, NULL,
DYNAMIC_TYPE_TMP_BUFFER, ret=MEMORY_E);
/* Compute all nodes requested. */
for (i = 0; (ret == 0) && (i < max_h); i++) {
@@ -2024,9 +2004,7 @@ static int wc_lms_treehash_init(LmsState* state, LmsPrivState* privState,
}
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(stack, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif /* WOLFSSL_SMALL_STACK */
WC_FREE_VAR_EX(stack, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -2071,11 +2049,7 @@ static int wc_lms_treehash_update(LmsState* state, LmsPrivState* privState,
byte* dp = rp + LMS_R_LEN;
byte* left = dp + LMS_D_LEN;
byte* temp = left + params->hash_len;
#ifdef WOLFSSL_SMALL_STACK
byte* stack = NULL;
#else
byte stack[(LMS_MAX_HEIGHT + 1) * LMS_MAX_NODE_LEN];
#endif /* WOLFSSL_SMALL_STACK */
WC_DECLARE_VAR(stack, byte, (LMS_MAX_HEIGHT + 1) * LMS_MAX_NODE_LEN, 0);
byte* sp;
word32 max_cb = (word32)1 << params->cacheBits;
word32 i;
@@ -2083,14 +2057,9 @@ static int wc_lms_treehash_update(LmsState* state, LmsPrivState* privState,
/* I || ... */
XMEMCPY(buffer, id, LMS_I_LEN);
#ifdef WOLFSSL_SMALL_STACK
/* Allocate stack of left side hashes. */
stack = (byte*)XMALLOC((params->height + 1) * params->hash_len, NULL,
DYNAMIC_TYPE_TMP_BUFFER);
if (stack == NULL) {
ret = MEMORY_E;
}
#endif /* WOLFSSL_SMALL_STACK */
WC_ALLOC_VAR_EX(stack, byte, (params->height+1)*params->hash_len, NULL,
DYNAMIC_TYPE_TMP_BUFFER, ret=MEMORY_E);
/* Public key, root node, is top of data stack. */
if (ret == 0) {
@@ -2197,9 +2166,7 @@ static int wc_lms_treehash_update(LmsState* state, LmsPrivState* privState,
stackCache->offset = (word32)((size_t)sp - (size_t)stack);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(stack, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif /* WOLFSSL_SMALL_STACK */
WC_FREE_VAR_EX(stack, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
#endif /* WOLFSSL_WC_LMS_SMALL */
+10 -25
View File
@@ -2369,10 +2369,8 @@ static int mlkem_gen_matrix_k2_avx2(sword16* a, byte* seed, int transposed)
p, XOF_BLOCK_SIZE);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(rand, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(rand, NULL, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return 0;
}
@@ -2525,10 +2523,8 @@ static int mlkem_gen_matrix_k3_avx2(sword16* a, byte* seed, int transposed)
XOF_BLOCK_SIZE);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(rand, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(rand, NULL, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return 0;
}
@@ -2637,10 +2633,8 @@ static int mlkem_gen_matrix_k4_avx2(sword16* a, byte* seed, int transposed)
a += 4 * MLKEM_N;
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(rand, NULL, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(rand, NULL, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return 0;
}
@@ -4208,17 +4202,10 @@ static int mlkem_get_noise_k2_avx2(MLKEM_PRF_T* prf, sword16* vec1,
sword16* vec2, sword16* poly, byte* seed)
{
int ret = 0;
#ifdef WOLFSSL_SMALL_STACK
byte *rand;
#else
byte rand[4 * PRF_RAND_SZ];
#endif
WC_DECLARE_VAR(rand, byte, 4 * PRF_RAND_SZ, 0);
#ifdef WOLFSSL_SMALL_STACK
rand = (byte*)XMALLOC(4 * PRF_RAND_SZ, NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (rand == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(rand, byte, 4*PRF_RAND_SZ, NULL, DYNAMIC_TYPE_TMP_BUFFER,
return MEMORY_E);
mlkem_get_noise_x4_eta3_avx2(rand, seed);
mlkem_cbd_eta3_avx2(vec1 , rand + 0 * PRF_RAND_SZ);
@@ -4235,9 +4222,7 @@ static int mlkem_get_noise_k2_avx2(MLKEM_PRF_T* prf, sword16* vec1,
ret = mlkem_get_noise_eta2_avx2(prf, poly, seed);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(rand, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(rand, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
+8 -28
View File
@@ -3192,19 +3192,11 @@ static int wc_Pkcs11CheckPrivKey_Rsa(RsaKey* priv,
const unsigned char* publicKey, word32 pubKeySize)
{
int ret = 0;
#ifdef WOLFSSL_SMALL_STACK
RsaKey* pub = NULL;
#else
RsaKey pub[1];
#endif
WC_DECLARE_VAR(pub, RsaKey, 1, 0);
word32 keyIdx = 0;
#ifdef WOLFSSL_SMALL_STACK
pub = (RsaKey*)XMALLOC(sizeof(RsaKey), NULL, DYNAMIC_TYPE_RSA);
if (pub == NULL) {
ret = MEMORY_E;
}
#endif
WC_ALLOC_VAR_EX(pub, RsaKey, 1, NULL, DYNAMIC_TYPE_RSA,
ret=MEMORY_E);
if ((ret == 0) && (ret = wc_InitRsaKey(pub, NULL)) == 0) {
if (ret == 0) {
@@ -3222,9 +3214,7 @@ static int wc_Pkcs11CheckPrivKey_Rsa(RsaKey* priv,
}
wc_FreeRsaKey(pub);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(pub, NULL, DYNAMIC_TYPE_RSA);
#endif
WC_FREE_VAR_EX(pub, NULL, DYNAMIC_TYPE_RSA);
return ret;
}
@@ -3338,19 +3328,11 @@ static int wc_Pkcs11CheckPrivKey_Ecc(ecc_key* priv,
const unsigned char* publicKey, word32 pubKeySize)
{
int ret = 0;
#ifdef WOLFSSL_SMALL_STACK
ecc_key* pub = NULL;
#else
ecc_key pub[1];
#endif
WC_DECLARE_VAR(pub, ecc_key, 1, 0);
word32 keyIdx = 0;
#ifdef WOLFSSL_SMALL_STACK
pub = (ecc_key*)XMALLOC(sizeof(ecc_key), NULL, DYNAMIC_TYPE_ECC);
if (pub == NULL) {
ret = MEMORY_E;
}
#endif
WC_ALLOC_VAR_EX(pub, ecc_key, 1, NULL, DYNAMIC_TYPE_ECC,
ret=MEMORY_E);
if ((ret == 0) && (ret = wc_ecc_init(pub)) == 0) {
ret = wc_EccPublicKeyDecode(publicKey, &keyIdx, pub, pubKeySize);
@@ -3367,9 +3349,7 @@ static int wc_Pkcs11CheckPrivKey_Ecc(ecc_key* priv,
}
wc_ecc_free(pub);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(pub, NULL, DYNAMIC_TYPE_ECC);
#endif
WC_FREE_VAR_EX(pub, NULL, DYNAMIC_TYPE_ECC);
return ret;
}
+16 -48
View File
@@ -731,19 +731,11 @@ static WC_INLINE int wc_xmsskey_signupdate(XmssKey* key, byte* sig,
}
if (ret == 0) {
#ifdef WOLFSSL_SMALL_STACK
XmssState* state;
#else
XmssState state[1];
#endif
WC_DECLARE_VAR(state, XmssState, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
state = (XmssState*)XMALLOC(sizeof(XmssState), NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (state == NULL) {
ret = MEMORY_E;
}
if (ret == 0)
#endif
WC_ALLOC_VAR_EX(state, XmssState, 1, NULL, DYNAMIC_TYPE_TMP_BUFFER,
ret=MEMORY_E);
if (WC_VAR_OK(state))
{
/* Initialize state for use in signing. */
ret = wc_xmss_state_init(state, key->params);
@@ -774,9 +766,7 @@ static WC_INLINE int wc_xmsskey_signupdate(XmssKey* key, byte* sig,
/* Free state after use. */
wc_xmss_state_free(state);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
}
@@ -1102,19 +1092,11 @@ int wc_XmssKey_MakeKey(XmssKey* key, WC_RNG* rng)
}
if (ret == 0) {
#ifdef WOLFSSL_SMALL_STACK
XmssState* state;
#else
XmssState state[1];
#endif
WC_DECLARE_VAR(state, XmssState, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
state = (XmssState*)XMALLOC(sizeof(XmssState), NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (state == NULL) {
ret = MEMORY_E;
}
if (ret == 0)
#endif
WC_ALLOC_VAR_EX(state, XmssState, 1, NULL, DYNAMIC_TYPE_TMP_BUFFER,
ret=MEMORY_E);
if (WC_VAR_OK(state))
{
/* Initialize state for use in key generation. */
ret = wc_xmss_state_init(state, key->params);
@@ -1138,9 +1120,7 @@ int wc_XmssKey_MakeKey(XmssKey* key, WC_RNG* rng)
/* Free state after use. */
wc_xmss_state_free(state);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
}
@@ -1161,9 +1141,7 @@ int wc_XmssKey_MakeKey(XmssKey* key, WC_RNG* rng)
key->state = WC_XMSS_STATE_OK;
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(seed, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(seed, NULL, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -1638,19 +1616,11 @@ int wc_XmssKey_Verify(XmssKey* key, const byte* sig, word32 sigLen,
}
if (ret == 0) {
#ifdef WOLFSSL_SMALL_STACK
XmssState* state;
#else
XmssState state[1];
#endif
WC_DECLARE_VAR(state, XmssState, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
state = (XmssState*)XMALLOC(sizeof(XmssState), NULL, DYNAMIC_TYPE_TMP_BUFFER);
if (state == NULL) {
ret = MEMORY_E;
}
if (ret == 0)
#endif
WC_ALLOC_VAR_EX(state, XmssState, 1, NULL, DYNAMIC_TYPE_TMP_BUFFER,
ret=MEMORY_E);
if (WC_VAR_OK(state))
{
/* Initialize state for use in verification. */
ret = wc_xmss_state_init(state, key->params);
@@ -1660,9 +1630,7 @@ int wc_XmssKey_Verify(XmssKey* key, const byte* sig, word32 sigLen,
/* Free state after use. */
wc_xmss_state_free(state);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(state, NULL, DYNAMIC_TYPE_TMP_BUFFER);
}
}
+2 -10
View File
@@ -3312,11 +3312,7 @@ int wc_xmss_keygen(XmssState* state, const unsigned char* seed,
const word8 n = params->n;
/* Offset of root node in public key. */
byte* pk_root = pk;
#ifdef WOLFSSL_SMALL_STACK
BdsState* bds = NULL;
#else
BdsState bds[1];
#endif
WC_DECLARE_VAR(bds, BdsState, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
/* Allocate memory for tree hash instances and put in BDS state. */
@@ -3427,11 +3423,7 @@ int wc_xmss_sign(XmssState* state, const unsigned char* m, word32 mlen,
byte node[WC_XMSS_MAX_N];
word32 idx;
byte* sig_r = sig + XMSS_IDX_LEN;
#ifdef WOLFSSL_SMALL_STACK
BdsState* bds = NULL;
#else
BdsState bds[1];
#endif
WC_DECLARE_VAR(bds, BdsState, 1, 0);
#ifdef WOLFSSL_SMALL_STACK
/* Allocate memory for tree hash instances and put in BDS state. */
+28 -61
View File
@@ -43,6 +43,10 @@
#define WOLFSSL_DEBUG_TRACE_ERROR_CODES_ALWAYS
#endif
#ifdef WOLFSSL_ASYNC_CRYPT
#define WOLFSSL_SMALL_STACK
#endif
#if !defined(NO_CRYPT_TEST) || defined(WC_TEST_EXPORT_SUBTESTS)
#include <wolfssl/version.h>
@@ -4068,11 +4072,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha256_test(void)
#endif
#ifndef NO_LARGE_HASH_TEST
#define LARGE_HASH_TEST_INPUT_SZ 1024
#ifdef WOLFSSL_SMALL_STACK
byte *large_input = NULL;
#else
byte large_input[LARGE_HASH_TEST_INPUT_SZ];
#endif
WC_DECLARE_VAR(large_input, byte, LARGE_HASH_TEST_INPUT_SZ, 0);
#endif
int times = sizeof(test_sha) / sizeof(struct testVector), i;
@@ -4224,14 +4224,9 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha256_test(void)
"\x4f\x45\x79\x7f\x67\x70\xbd\x63\x7f\xbf\x0d\x80\x7c\xbd\xba\xe0";
#endif
#ifdef WOLFSSL_SMALL_STACK
large_input = (byte *)XMALLOC(LARGE_HASH_TEST_INPUT_SZ, HEAP_HINT,
DYNAMIC_TYPE_TMP_BUFFER);
if (large_input == NULL) {
ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), exit);
}
#endif
WC_ALLOC_VAR_EX(large_input, byte, LARGE_HASH_TEST_INPUT_SZ, HEAP_HINT,
DYNAMIC_TYPE_TMP_BUFFER,
ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E),exit));
for (i = 0; i < LARGE_HASH_TEST_INPUT_SZ; i++) {
large_input[i] = (byte)(i & 0xFF);
@@ -4320,11 +4315,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_test(void)
#endif
#ifndef NO_LARGE_HASH_TEST
#define LARGE_HASH_TEST_INPUT_SZ 1024
#ifdef WOLFSSL_SMALL_STACK
byte *large_input = NULL;
#else
byte large_input[LARGE_HASH_TEST_INPUT_SZ];
#endif
WC_DECLARE_VAR(large_input, byte, LARGE_HASH_TEST_INPUT_SZ, 0);
#endif
int times = sizeof(test_sha) / sizeof(struct testVector), i;
@@ -4473,14 +4464,9 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t sha512_test(void)
"\xa5\xdc\xfc\xfa\x9d\x1a\x4d\xc0\xfa\x3a\x14\xf6\x01\x51\x90\xa4";
#endif
#ifdef WOLFSSL_SMALL_STACK
large_input = (byte *)XMALLOC(LARGE_HASH_TEST_INPUT_SZ, HEAP_HINT,
DYNAMIC_TYPE_TMP_BUFFER);
if (large_input == NULL) {
ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E), exit);
}
#endif
WC_ALLOC_VAR_EX(large_input, byte, LARGE_HASH_TEST_INPUT_SZ, HEAP_HINT,
DYNAMIC_TYPE_TMP_BUFFER,
ERROR_OUT(WC_TEST_RET_ENC_EC(MEMORY_E),exit));
for (i = 0; i < LARGE_HASH_TEST_INPUT_SZ; i++) {
large_input[i] = (byte)(i & 0xFF);
@@ -21003,11 +20989,7 @@ WOLFSSL_TEST_SUBROUTINE wc_test_ret_t rsa_no_pad_test(void)
#endif
tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (tmp == NULL
#ifdef WOLFSSL_ASYNC_CRYPT
|| out == NULL || plain == NULL
#endif
) {
if (tmp == NULL) {
ERROR_OUT(WC_TEST_RET_ENC_NC, exit_rsa_nopadding);
}
@@ -29225,9 +29207,7 @@ static wc_test_ret_t hpke_test_single(Hpke* hpke)
if (receiverKey != NULL)
wc_HpkeFreeKey(hpke, hpke->kem, receiverKey, hpke->heap);
#ifdef WOLFSSL_SMALL_STACK
XFREE(pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(pubKey, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (rngRet == 0)
wc_FreeRng(rng);
@@ -30442,11 +30422,7 @@ done:
static wc_test_ret_t ecc_test_deterministic_k(WC_RNG* rng)
{
wc_test_ret_t ret;
#ifdef WOLFSSL_SMALL_STACK
ecc_key *key = NULL;
#else
ecc_key key[1];
#endif
WC_DECLARE_VAR(key, ecc_key, 1, 0);
int key_inited = 0;
WOLFSSL_SMALL_STACK_STATIC const char* msg = "sample";
WOLFSSL_SMALL_STACK_STATIC const char* dIUT =
@@ -30504,11 +30480,8 @@ static wc_test_ret_t ecc_test_deterministic_k(WC_RNG* rng)
};
#endif
#ifdef WOLFSSL_SMALL_STACK
key = (ecc_key *)XMALLOC(sizeof(*key), HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (key == NULL)
return MEMORY_E;
#endif
WC_ALLOC_VAR_EX(key, ecc_key, 1, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER,
return MEMORY_E);
ret = wc_ecc_init_ex(key, HEAP_HINT, devId);
if (ret != 0)
@@ -30549,9 +30522,7 @@ static wc_test_ret_t ecc_test_deterministic_k(WC_RNG* rng)
done:
if (key_inited)
wc_ecc_free(key);
#ifdef WOLFSSL_SMALL_STACK
XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
#endif /* NO_ECC256 || HAVE_ALL_CURVES */
@@ -30726,13 +30697,11 @@ done:
mp_free(expR);
mp_free(expS);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(r, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(s, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(expR, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(expS, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(r, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(s, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(expR, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(expS, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
@@ -30870,13 +30839,11 @@ done:
mp_free(expR);
mp_free(expS);
}
#ifdef WOLFSSL_SMALL_STACK
XFREE(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(r, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(s, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(expR, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
XFREE(expS, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
#endif
WC_FREE_VAR_EX(key, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(r, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(s, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(expR, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
WC_FREE_VAR_EX(expS, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
return ret;
}
+16 -1
View File
@@ -708,10 +708,11 @@ enum {
idx##VAR_NAME = 0; \
}
#if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLFSSL_SMALL_STACK)
#if defined(WOLFSSL_SMALL_STACK)
#define WC_DECLARE_VAR_IS_HEAP_ALLOC
#define WC_DECLARE_VAR(VAR_NAME, VAR_TYPE, VAR_SIZE, HEAP) \
VAR_TYPE* VAR_NAME = NULL
#define WC_VAR_OK(VAR_NAME) ((VAR_NAME) != NULL)
#define WC_ALLOC_VAR(VAR_NAME, VAR_TYPE, VAR_SIZE, HEAP) \
do { \
(VAR_NAME) = (VAR_TYPE*)XMALLOC(sizeof(VAR_TYPE) * (VAR_SIZE), \
@@ -720,6 +721,14 @@ enum {
WC_ALLOC_DO_ON_FAILURE(); \
} \
} while (0)
#define WC_ALLOC_VAR_EX(VAR_NAME, VAR_TYPE, VAR_SIZE, HEAP, TY, ONFAIL)\
do { \
(VAR_NAME) = (VAR_TYPE*)XMALLOC(sizeof(VAR_TYPE) * (VAR_SIZE), \
(HEAP), TY); \
if ((VAR_NAME) == NULL) { \
ONFAIL; \
} \
} while (0)
#define WC_CALLOC_VAR(VAR_NAME, VAR_TYPE, VAR_SIZE, HEAP) \
do { \
WC_ALLOC_VAR(VAR_NAME, VAR_TYPE, VAR_SIZE, HEAP); \
@@ -727,6 +736,8 @@ enum {
} while (0)
#define WC_FREE_VAR(VAR_NAME, HEAP) \
XFREE(VAR_NAME, (HEAP), DYNAMIC_TYPE_WOLF_BIGINT)
#define WC_FREE_VAR_EX(VAR_NAME, HEAP, TYPE) \
XFREE(VAR_NAME, (HEAP), TYPE)
#define WC_DECLARE_ARRAY(VAR_NAME, VAR_TYPE, VAR_ITEMS, VAR_SIZE, HEAP) \
WC_DECLARE_HEAP_ARRAY(VAR_NAME, VAR_TYPE, VAR_ITEMS, VAR_SIZE, HEAP)
#define WC_ARRAY_ARG(VAR_NAME, VAR_TYPE, VAR_ITEMS, VAR_SIZE) \
@@ -743,10 +754,14 @@ enum {
#define WC_DECLARE_VAR(VAR_NAME, VAR_TYPE, VAR_SIZE, HEAP) \
VAR_TYPE VAR_NAME[VAR_SIZE]
#define WC_ALLOC_VAR(VAR_NAME, VAR_TYPE, VAR_SIZE, HEAP) WC_DO_NOTHING
#define WC_ALLOC_VAR_EX(VAR_NAME, VAR_TYPE, VAR_SIZE, HEAP, TYPE, ONFAIL)\
WC_DO_NOTHING
#define WC_VAR_OK(VAR_NAME) 1
#define WC_CALLOC_VAR(VAR_NAME, VAR_TYPE, VAR_SIZE, HEAP) \
XMEMSET(VAR_NAME, 0, sizeof(var))
#define WC_FREE_VAR(VAR_NAME, HEAP) WC_DO_NOTHING \
/* nothing to free, its stack */
#define WC_FREE_VAR_EX(VAR_NAME, HEAP, TYPE) WC_DO_NOTHING
#define WC_DECLARE_ARRAY(VAR_NAME, VAR_TYPE, VAR_ITEMS, VAR_SIZE, HEAP) \
VAR_TYPE VAR_NAME[VAR_ITEMS][(VAR_SIZE) / sizeof(VAR_TYPE)] /* NOLINT(bugprone-sizeof-expression) */
#define WC_ARRAY_ARG(VAR_NAME, VAR_TYPE, VAR_ITEMS, VAR_SIZE) \