@@ -27751,13 +27751,13 @@ int wc_RsaKeyToDer(RsaKey* key, byte* output, word32 inLen)
2775127751 int ret = 0, i;
2775227752 int mpSz;
2775327753 word32 seqSz = 0, verSz = 0, intTotalLen = 0, outLen = 0;
27754- word32 sizes[RSA_INTS];
2775527754 byte seq[MAX_SEQ_SZ];
2775627755 byte ver[MAX_VERSION_SZ];
2775727756 mp_int* keyInt;
2775827757#ifndef WOLFSSL_NO_MALLOC
2775927758 word32 rawLen;
2776027759 byte* tmps[RSA_INTS];
27760+ word32 sizes[RSA_INTS];
2776127761#endif
2776227762
2776327763 if (key == NULL)
@@ -27797,7 +27797,9 @@ int wc_RsaKeyToDer(RsaKey* key, byte* output, word32 inLen)
2779727797 ret = mpSz;
2779827798 break;
2779927799 }
27800+ #ifndef WOLFSSL_NO_MALLOC
2780027801 sizes[i] = (word32)mpSz;
27802+ #endif
2780127803 intTotalLen += (word32)mpSz;
2780227804 }
2780327805
@@ -31430,11 +31432,13 @@ static int MakeSignature(CertSignCtx* certSignCtx, const byte* buf, word32 sz,
3143031432 case CERTSIGN_STATE_DIGEST:
3143131433
3143231434 certSignCtx->state = CERTSIGN_STATE_DIGEST;
31435+ #ifndef WOLFSSL_NO_MALLOC
3143331436 certSignCtx->digest = (byte*)XMALLOC(WC_MAX_DIGEST_SIZE, heap,
3143431437 DYNAMIC_TYPE_TMP_BUFFER);
3143531438 if (certSignCtx->digest == NULL) {
3143631439 ret = MEMORY_E; goto exit_ms;
3143731440 }
31441+ #endif
3143831442
3143931443 ret = HashForSignature(buf, sz, sigAlgoType, certSignCtx->digest,
3144031444 &typeH, &digestSz, 0);
@@ -31448,11 +31452,13 @@ static int MakeSignature(CertSignCtx* certSignCtx, const byte* buf, word32 sz,
3144831452 case CERTSIGN_STATE_ENCODE:
3144931453 #ifndef NO_RSA
3145031454 if (rsaKey) {
31455+ #ifndef WOLFSSL_NO_MALLOC
3145131456 certSignCtx->encSig = (byte*)XMALLOC(MAX_DER_DIGEST_SZ, heap,
3145231457 DYNAMIC_TYPE_TMP_BUFFER);
3145331458 if (certSignCtx->encSig == NULL) {
3145431459 ret = MEMORY_E; goto exit_ms;
3145531460 }
31461+ #endif
3145631462
3145731463 /* signature */
3145831464 certSignCtx->encSigSz = (int)wc_EncodeSignature(certSignCtx->encSig,
@@ -31560,14 +31566,17 @@ static int MakeSignature(CertSignCtx* certSignCtx, const byte* buf, word32 sz,
3156031566 }
3156131567#endif
3156231568
31569+ #ifndef WOLFSSL_NO_MALLOC
3156331570#ifndef NO_RSA
3156431571 if (rsaKey) {
3156531572 XFREE(certSignCtx->encSig, heap, DYNAMIC_TYPE_TMP_BUFFER);
31573+ certSignCtx->encSig = NULL;
3156631574 }
3156731575#endif /* !NO_RSA */
3156831576
3156931577 XFREE(certSignCtx->digest, heap, DYNAMIC_TYPE_TMP_BUFFER);
3157031578 certSignCtx->digest = NULL;
31579+ #endif /* !WOLFSSL_NO_MALLOC */
3157131580
3157231581 /* reset state */
3157331582 certSignCtx->state = CERTSIGN_STATE_BEGIN;
@@ -33334,12 +33343,14 @@ static int SignCert(int requestSz, int sType, byte* buf, word32 buffSz,
3333433343 #endif /* HAVE_ECC */
3333533344 }
3333633345
33346+ #ifndef WOLFSSL_NO_MALLOC
3333733347 if (certSignCtx->sig == NULL) {
3333833348 certSignCtx->sig = (byte*)XMALLOC(MAX_ENCODED_SIG_SZ, heap,
3333933349 DYNAMIC_TYPE_TMP_BUFFER);
3334033350 if (certSignCtx->sig == NULL)
3334133351 return MEMORY_E;
3334233352 }
33353+ #endif
3334333354
3334433355 sigSz = MakeSignature(certSignCtx, buf, (word32)requestSz, certSignCtx->sig,
3334533356 MAX_ENCODED_SIG_SZ, rsaKey, eccKey, ed25519Key, ed448Key,
@@ -33360,8 +33371,10 @@ static int SignCert(int requestSz, int sType, byte* buf, word32 buffSz,
3336033371 sType);
3336133372 }
3336233373
33374+ #ifndef WOLFSSL_NO_MALLOC
3336333375 XFREE(certSignCtx->sig, heap, DYNAMIC_TYPE_TMP_BUFFER);
3336433376 certSignCtx->sig = NULL;
33377+ #endif
3336533378
3336633379 return sigSz;
3336733380}
@@ -33468,12 +33481,14 @@ int wc_MakeSigWithBitStr(byte *sig, int sigSz, int sType, byte* buf,
3346833481 #endif /* HAVE_ECC */
3346933482 }
3347033483
33484+ #ifndef WOLFSSL_NO_MALLOC
3347133485 if (certSignCtx->sig == NULL) {
3347233486 certSignCtx->sig = (byte*)XMALLOC(MAX_ENCODED_SIG_SZ, heap,
3347333487 DYNAMIC_TYPE_TMP_BUFFER);
3347433488 if (certSignCtx->sig == NULL)
3347533489 return MEMORY_E;
3347633490 }
33491+ #endif
3347733492
3347833493 ret = MakeSignature(certSignCtx, buf, (word32)bufSz, certSignCtx->sig,
3347933494 MAX_ENCODED_SIG_SZ, rsaKey, eccKey, ed25519Key, ed448Key,
@@ -33487,8 +33502,10 @@ int wc_MakeSigWithBitStr(byte *sig, int sigSz, int sType, byte* buf,
3348733502#endif
3348833503
3348933504 if (ret <= 0) {
33505+ #ifndef WOLFSSL_NO_MALLOC
3349033506 XFREE(certSignCtx->sig, heap, DYNAMIC_TYPE_TMP_BUFFER);
3349133507 certSignCtx->sig = NULL;
33508+ #endif
3349233509 return ret;
3349333510 }
3349433511
@@ -33503,8 +33520,10 @@ int wc_MakeSigWithBitStr(byte *sig, int sigSz, int sType, byte* buf,
3350333520 ret += headerSz;
3350433521 }
3350533522
33523+ #ifndef WOLFSSL_NO_MALLOC
3350633524 XFREE(certSignCtx->sig, heap, DYNAMIC_TYPE_TMP_BUFFER);
3350733525 certSignCtx->sig = NULL;
33526+ #endif
3350833527 return ret;
3350933528}
3351033529#endif /* WOLFSSL_DUAL_ALG_CERTS */
0 commit comments