From a17bc2a42e66e9e6e15bd34bbf08ffd43a40a14c Mon Sep 17 00:00:00 2001 From: David Garske Date: Fri, 5 Aug 2016 12:19:30 -0700 Subject: [PATCH] Fix build issue with ASN enabled and no HMAC (missing MAX_DIGEST_SIZE). Switch to using WC_MAX_DIGEST_SIZE from hash.h, which is always available. Added small stack option for digest in MakeSignature. Fixed build error with unused "testVerifyCount" if "NO_ECC_SIGN" or "NO_ECC_VERIFY". --- wolfcrypt/src/asn.c | 27 ++++++++++++++++++++++----- wolfcrypt/test/test.c | 2 ++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index b151f16a9..dfbde3f8c 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -3573,11 +3573,11 @@ static int ConfirmSignature(const byte* buf, word32 bufSz, #ifdef WOLFSSL_SMALL_STACK byte* digest; #else - byte digest[MAX_DIGEST_SIZE]; + byte digest[WC_MAX_DIGEST_SIZE]; #endif #ifdef WOLFSSL_SMALL_STACK - digest = (byte*)XMALLOC(MAX_DIGEST_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER); + digest = (byte*)XMALLOC(WC_MAX_DIGEST_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (digest == NULL) return 0; /* not confirmed */ #endif @@ -7227,7 +7227,11 @@ static int MakeSignature(const byte* buffer, int sz, byte* sig, int sigSz, int sigAlgoType) { int encSigSz, digestSz, typeH = 0, ret = 0; - byte digest[MAX_DIGEST_SIZE]; /* max size */ +#ifdef WOLFSSL_SMALL_STACK + byte* digest; +#else + byte digest[WC_MAX_DIGEST_SIZE]; /* max size */ +#endif #ifdef WOLFSSL_SMALL_STACK byte* encSig; #else @@ -7248,6 +7252,12 @@ static int MakeSignature(const byte* buffer, int sz, byte* sig, int sigSz, (void)eccKey; (void)rng; +#ifdef WOLFSSL_SMALL_STACK + digest = (byte*)XMALLOC(WC_MAX_DIGEST_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER); + if (digest == NULL) + return 0; /* not confirmed */ +#endif + switch (sigAlgoType) { #ifndef NO_MD5 case CTC_MD5wRSA: @@ -7289,14 +7299,20 @@ static int MakeSignature(const byte* buffer, int sz, byte* sig, int sigSz, ret = ALGO_ID_E; } - if (ret != 0) + if (ret != 0) { + #ifdef WOLFSSL_SMALL_STACK + XFREE(digest, NULL, DYNAMIC_TYPE_TMP_BUFFER); + #endif return ret; + } #ifdef WOLFSSL_SMALL_STACK encSig = (byte*)XMALLOC(MAX_DER_DIGEST_SZ, NULL, DYNAMIC_TYPE_TMP_BUFFER); - if (encSig == NULL) + if (encSig == NULL) { + XFREE(digest, NULL, DYNAMIC_TYPE_TMP_BUFFER); return MEMORY_E; + } #endif ret = ALGO_ID_E; @@ -7320,6 +7336,7 @@ static int MakeSignature(const byte* buffer, int sz, byte* sig, int sigSz, #endif #ifdef WOLFSSL_SMALL_STACK + XFREE(digest, NULL, DYNAMIC_TYPE_TMP_BUFFER); XFREE(encSig, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index 05321dbaa..5d2bff6c9 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -6842,6 +6842,8 @@ static int ecc_test_curve_size(WC_RNG* rng, int keySize, int testVerifyCount, int ret; ecc_key userA, userB, pubKey; + (void)testVerifyCount; + wc_ecc_init(&userA); wc_ecc_init(&userB); wc_ecc_init(&pubKey);