From b57e576abdcf3a4b3bf046aa9a4aa05eabf878fb Mon Sep 17 00:00:00 2001 From: David Garske Date: Wed, 28 Dec 2016 11:18:41 -0800 Subject: [PATCH] =?UTF-8?q?Fixes=20for=20compiler=20warnings=20with=20IAR?= =?UTF-8?q?=20EWARM=208.=20*=20Fix=20=E2=80=9Cwc=5FPKCS7=5FDecodeUnprotect?= =?UTF-8?q?edAttributes=E2=80=9D=20return=20prior=20to=20free=20in=20GetSe?= =?UTF-8?q?t=20error=20case.=20*=20Fix=20=E2=80=9Cwc=5FPKCS7=5FKariGenerat?= =?UTF-8?q?eKEK=E2=80=9D=20type=20mismatch=20for=20kdfType.=20*=20Fix=20ae?= =?UTF-8?q?s.c=20roll=5Fauth=20use=20of=20inSz=20over=2024-bit.=20*=20Fix?= =?UTF-8?q?=20ecc=20=E2=80=9Cbuild=5Flut=E2=80=9D,=20=E2=80=9Caccel=5Ffp?= =?UTF-8?q?=5Fmul=E2=80=9D=20and=20=E2=80=9Caccel=5Ffp=5Fmul2add=E2=80=9D?= =?UTF-8?q?=20use=20of=20err=20as=20unsigned.=20*=20Fix=20=E2=80=9Cwc=5FHK?= =?UTF-8?q?DF=E2=80=9D=20use=20of=20un-initialized=20=E2=80=9CmyHmac?= =?UTF-8?q?=E2=80=9D=20for=20heap.=20*=20Fix=20undefined=20reference=20to?= =?UTF-8?q?=20=5F=5FREV=20for=20IAR=20due=20to=20missing=20intrinsics.h.?= =?UTF-8?q?=20*=20Fix=20build=20error=20for=20=E2=80=9CwolfSSL=5FCTX=5Fset?= =?UTF-8?q?=5Ftmp=5Fdh=E2=80=9D=20if=20OPENSSL=5FEXTRA=20not=20defined=20a?= =?UTF-8?q?nd=20=E2=80=9CHAVE=5FLIGHTY=20||=20HAVE=5FSTUNNEL=20||=20WOLFSS?= =?UTF-8?q?L=5FMYSQL=5FCOMPATIBLE=E2=80=9D.=20*=20Cleanup=20of=20=E2=80=9C?= =?UTF-8?q?wolfSSL=5Fget=5Fchain=5FX509=E2=80=9D=20brace..=20*=20Cleanup?= =?UTF-8?q?=20SSL=5FCtxResourceFree=20use=20of=20`i`=20and=20define=20comm?= =?UTF-8?q?ents.=20*=20Added=20=E2=80=9CSIZEOF=5FLONG=5FLONG=E2=80=9D=20to?= =?UTF-8?q?=20IAR-EWARM=20user=5Fsettings.h=20to=20support=20word64=20(req?= =?UTF-8?q?uired=20for=20SHA512,=20etc).?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- IDE/IAR-EWARM/Projects/user_settings.h | 1 + src/internal.c | 30 ++++++++++++-------------- src/ssl.c | 7 +++--- wolfcrypt/src/aes.c | 4 ++-- wolfcrypt/src/ecc.c | 15 +++++++------ wolfcrypt/src/hmac.c | 10 ++++----- wolfcrypt/src/misc.c | 6 ++++++ wolfcrypt/src/pkcs7.c | 5 +++-- 8 files changed, 43 insertions(+), 35 deletions(-) diff --git a/IDE/IAR-EWARM/Projects/user_settings.h b/IDE/IAR-EWARM/Projects/user_settings.h index 5e4f36e9a..2652f6df1 100644 --- a/IDE/IAR-EWARM/Projects/user_settings.h +++ b/IDE/IAR-EWARM/Projects/user_settings.h @@ -8,6 +8,7 @@ #define NO_DEV_RANDOM #define USE_CERT_BUFFERS_2048 #define WOLFSSL_USER_CURRTIME +#define SIZEOF_LONG_LONG 8 #define CUSTOM_RAND_GENERATE custom_rand_generate /* warning "write a real random seed!!!!, just for testing now" */ diff --git a/src/internal.c b/src/internal.c index efce9c491..31063cd15 100644 --- a/src/internal.c +++ b/src/internal.c @@ -1435,9 +1435,9 @@ int InitSSL_Ctx(WOLFSSL_CTX* ctx, WOLFSSL_METHOD* method, void* heap) /* In case contexts are held in array and don't want to free actual ctx */ void SSL_CtxResourceFree(WOLFSSL_CTX* ctx) { +#ifdef HAVE_CERTIFICATE_STATUS_REQUEST_V2 int i; - - (void)i; +#endif #ifdef HAVE_WOLF_EVENT wolfEventQueue_Free(&ctx->event_queue); @@ -1450,14 +1450,14 @@ void SSL_CtxResourceFree(WOLFSSL_CTX* ctx) #ifndef NO_DH XFREE(ctx->serverDH_G.buffer, ctx->heap, DYNAMIC_TYPE_DH); XFREE(ctx->serverDH_P.buffer, ctx->heap, DYNAMIC_TYPE_DH); -#endif +#endif /* !NO_DH */ #ifdef SINGLE_THREADED if (ctx->rng) { wc_FreeRng(ctx->rng); XFREE(ctx->rng, ctx->heap, DYNAMIC_TYPE_RNG); } -#endif +#endif /* SINGLE_THREADED */ #ifndef NO_CERTS FreeDer(&ctx->privateKey); @@ -1467,16 +1467,15 @@ void SSL_CtxResourceFree(WOLFSSL_CTX* ctx) if (ctx->ourCert) { XFREE(ctx->ourCert, ctx->heap, DYNAMIC_TYPE_X509); } - #endif + #endif /* KEEP_OUR_CERT */ FreeDer(&ctx->certChain); wolfSSL_CertManagerFree(ctx->cm); -#endif +#endif /* !NO_CERTS */ #ifdef HAVE_TLS_EXTENSIONS TLSX_FreeAll(ctx->extensions, ctx->heap); #ifndef NO_WOLFSSL_SERVER - #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) \ || defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2) if (ctx->certOcspRequest) { @@ -1485,29 +1484,28 @@ void SSL_CtxResourceFree(WOLFSSL_CTX* ctx) } #endif -#if defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2) +#ifdef HAVE_CERTIFICATE_STATUS_REQUEST_V2 for (i = 0; i < MAX_CHAIN_DEPTH; i++) { if (ctx->chainOcspRequest[i]) { FreeOcspRequest(ctx->chainOcspRequest[i]); XFREE(ctx->chainOcspRequest[i], ctx->heap, DYNAMIC_TYPE_OCSP_REQUEST); } } -#endif - -#endif /* NO_WOLFSSL_SERVER */ +#endif /* HAVE_CERTIFICATE_STATUS_REQUEST_V2 */ +#endif /* !NO_WOLFSSL_SERVER */ #endif /* HAVE_TLS_EXTENSIONS */ + #ifdef WOLFSSL_STATIC_MEMORY if (ctx->heap != NULL) { #ifdef WOLFSSL_HEAP_TEST /* avoid derefrencing a test value */ - if (ctx->heap != (void*)WOLFSSL_HEAP_TEST) { + if (ctx->heap != (void*)WOLFSSL_HEAP_TEST) #endif - WOLFSSL_HEAP_HINT* hint = (WOLFSSL_HEAP_HINT*)(ctx->heap); - wc_FreeMutex(&((WOLFSSL_HEAP*)(hint->memory))->memory_mutex); -#ifdef WOLFSSL_HEAP_TEST + { + WOLFSSL_HEAP_HINT* hint = (WOLFSSL_HEAP_HINT*)(ctx->heap); + wc_FreeMutex(&((WOLFSSL_HEAP*)(hint->memory))->memory_mutex); } -#endif } #endif /* WOLFSSL_STATIC_MEMORY */ } diff --git a/src/ssl.c b/src/ssl.c index d02cced24..c361320ce 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -18046,8 +18046,9 @@ WOLFSSL_X509* wolfSSL_get_chain_X509(WOLFSSL_X509_CHAIN* chain, int idx) InitDecodedCert(cert, chain->certs[idx].buffer, chain->certs[idx].length, NULL); - if ((ret = ParseCertRelative(cert, CERT_TYPE, 0, NULL)) != 0) + if ((ret = ParseCertRelative(cert, CERT_TYPE, 0, NULL)) != 0) { WOLFSSL_MSG("Failed to parse cert"); + } else { x509 = (WOLFSSL_X509*)XMALLOC(sizeof(WOLFSSL_X509), NULL, DYNAMIC_TYPE_X509); @@ -18677,7 +18678,7 @@ int PEM_write_bio_WOLFSSL_X509(WOLFSSL_BIO *bp, WOLFSSL_X509 *x) { } -#ifndef NO_DH +#if defined(OPENSSL_EXTRA) && !defined(NO_DH) /* Intialize ctx->dh with dh's params. Return SSL_SUCCESS on ok */ long wolfSSL_CTX_set_tmp_dh(WOLFSSL_CTX* ctx, WOLFSSL_DH* dh) { @@ -18718,7 +18719,7 @@ long wolfSSL_CTX_set_tmp_dh(WOLFSSL_CTX* ctx, WOLFSSL_DH* dh) return pSz > 0 && gSz > 0 ? ret : SSL_FATAL_ERROR; } -#endif /* NO_DH */ +#endif /* OPENSSL_EXTRA && !NO_DH */ #endif /* HAVE_LIGHTY || HAVE_STUNNEL || WOLFSSL_MYSQL_COMPATIBLE */ diff --git a/wolfcrypt/src/aes.c b/wolfcrypt/src/aes.c index c1f1f74e8..a5ebc19c3 100644 --- a/wolfcrypt/src/aes.c +++ b/wolfcrypt/src/aes.c @@ -4464,12 +4464,12 @@ static void roll_auth(Aes* aes, const byte* in, word32 inSz, byte* out) word32 remainder; /* encode the length in */ - if (inSz <= 0xFEFF) { + if (inSz <= 0xFEFF) { /* 16-bit */ authLenSz = 2; out[0] ^= ((inSz & 0xFF00) >> 8); out[1] ^= (inSz & 0x00FF); } - else if (inSz <= 0xFFFFFFFF) { + else if (inSz <= 0xFFFFFF) { /* 24-bit */ authLenSz = 6; out[0] ^= 0xFF; out[1] ^= 0xFE; out[2] ^= ((inSz & 0xFF000000) >> 24); diff --git a/wolfcrypt/src/ecc.c b/wolfcrypt/src/ecc.c index ecdc408a2..16bd3a631 100644 --- a/wolfcrypt/src/ecc.c +++ b/wolfcrypt/src/ecc.c @@ -3873,9 +3873,9 @@ int wc_ecc_export_x963_ex(ecc_key* key, byte* out, word32* outLen, #ifdef HAVE_COMP_KEY else return wc_ecc_export_x963_compressed(key, out, outLen); -#endif - +#else return NOT_COMPILED_IN; +#endif } #endif /* HAVE_ECC_KEY_EXPORT */ @@ -5239,7 +5239,8 @@ static int add_entry(int idx, ecc_point *g) static int build_lut(int idx, mp_int* a, mp_int* modulus, mp_digit mp, mp_int* mu) { - unsigned x, y, err, bitlen, lut_gap; + int err; + unsigned x, y, bitlen, lut_gap; mp_int tmp; if (mp_init(&tmp) != MP_OKAY) @@ -5385,8 +5386,8 @@ static int accel_fp_mul(int idx, mp_int* k, ecc_point *R, mp_int* a, #else unsigned char kb[KB_SIZE]; #endif - int x; - unsigned y, z = 0, err, bitlen, bitpos, lut_gap, first; + int x, err; + unsigned y, z = 0, bitlen, bitpos, lut_gap, first; mp_int tk, order; if (mp_init_multi(&tk, &order, NULL, NULL, NULL, NULL) != MP_OKAY) @@ -5534,8 +5535,8 @@ static int accel_fp_mul2add(int idx1, int idx2, #else unsigned char kb[2][KB_SIZE]; #endif - int x; - unsigned y, z, err, bitlen, bitpos, lut_gap, first, zA, zB; + int x, err; + unsigned y, z, bitlen, bitpos, lut_gap, first, zA, zB; mp_int tka, tkb, order; if (mp_init_multi(&tka, &tkb, &order, NULL, NULL, NULL) != MP_OKAY) diff --git a/wolfcrypt/src/hmac.c b/wolfcrypt/src/hmac.c index a699b6542..a292cc440 100644 --- a/wolfcrypt/src/hmac.c +++ b/wolfcrypt/src/hmac.c @@ -815,13 +815,13 @@ int wc_HKDF(int type, const byte* inKey, word32 inKeySz, return BAD_FUNC_ARG; #ifdef WOLFSSL_SMALL_STACK - tmp = (byte*)XMALLOC(MAX_DIGEST_SIZE, myHmac.heap, DYNAMIC_TYPE_TMP_BUFFER); + tmp = (byte*)XMALLOC(MAX_DIGEST_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (tmp == NULL) return MEMORY_E; - prk = (byte*)XMALLOC(MAX_DIGEST_SIZE, myHmac.heap, DYNAMIC_TYPE_TMP_BUFFER); + prk = (byte*)XMALLOC(MAX_DIGEST_SIZE, NULL, DYNAMIC_TYPE_TMP_BUFFER); if (prk == NULL) { - XFREE(tmp, myHmac.heap, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER); return MEMORY_E; } #endif @@ -873,8 +873,8 @@ int wc_HKDF(int type, const byte* inKey, word32 inKeySz, } #ifdef WOLFSSL_SMALL_STACK - XFREE(tmp, myHmac.heap, DYNAMIC_TYPE_TMP_BUFFER); - XFREE(prk, myHmac.heap, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(tmp, NULL, DYNAMIC_TYPE_TMP_BUFFER); + XFREE(prk, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return ret; diff --git a/wolfcrypt/src/misc.c b/wolfcrypt/src/misc.c index cbd63c959..83f71f532 100644 --- a/wolfcrypt/src/misc.c +++ b/wolfcrypt/src/misc.c @@ -50,6 +50,12 @@ #else + +#if defined(__ICCARM__) + #include +#endif + + #ifdef INTEL_INTRINSICS #include /* get intrinsic definitions */ diff --git a/wolfcrypt/src/pkcs7.c b/wolfcrypt/src/pkcs7.c index d5eb9d022..6bcc8df8d 100644 --- a/wolfcrypt/src/pkcs7.c +++ b/wolfcrypt/src/pkcs7.c @@ -1415,7 +1415,8 @@ static int wc_PKCS7_KariGenerateKEK(WC_PKCS7_KARI* kari, int keyWrapOID, int keyEncOID) { int ret; - int kSz, kdfType; + int kSz; + enum wc_HashType kdfType; byte* secret; word32 secretSz; @@ -3571,9 +3572,9 @@ static int wc_PKCS7_DecodeUnprotectedAttributes(PKCS7* pkcs7, byte* pkiMsg, /* save attribute value bytes and size */ if (GetSet(pkiMsg, &idx, &length, pkiMsgSz) < 0) { - return ASN_PARSE_E; XFREE(attrib->oid, pkcs7->heap, DYNAMIC_TYPE_PKCS); XFREE(attrib, pkcs7->heap, DYNAMIC_TYPE_PKCS); + return ASN_PARSE_E; } if ((pkiMsgSz - idx) < (word32)length) {