diff --git a/src/internal.c b/src/internal.c index df5c660cc..43b5eceb9 100755 --- a/src/internal.c +++ b/src/internal.c @@ -3340,10 +3340,18 @@ int InitSSL(WOLFSSL* ssl, WOLFSSL_CTX* ctx) return MEMORY_E; } + /* FIPS RNG API does not accept a heap hint */ +#ifndef HAVE_FIPS if ( (ret = wc_InitRng_ex(ssl->rng, ssl->heap)) != 0) { WOLFSSL_MSG("RNG Init error"); return ret; } +#else + if ( (ret = wc_InitRng(ssl->rng)) != 0) { + WOLFSSL_MSG("RNG Init error"); + return ret; + } +#endif #if defined(WOLFSSL_DTLS) && !defined(NO_WOLFSSL_SERVER) if (ssl->options.dtls && ssl->options.side == WOLFSSL_SERVER_END) { diff --git a/src/ssl.c b/src/ssl.c index f557405f9..ecb053630 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -640,10 +640,10 @@ int wolfSSL_init_memory_heap(WOLFSSL_HEAP* heap) XMEMSET(heap, 0, sizeof(WOLFSSL_HEAP)); /* default pool sizes and distribution, else leave a 0's for now */ - if (WOLFMEM_DEF_BUCKETS == WOLFMEM_MAX_BUCKETS) { + #if WOLFMEM_DEF_BUCKETS == WOLFMEM_MAX_BUCKETS XMEMCPY(heap->sizeList, wc_defaultMemSz, sizeof(wc_defaultMemSz)); XMEMCPY(heap->distList, wc_defaultDist, sizeof(wc_defaultMemSz)); - } + #endif if (InitMutex(&(heap->memory_mutex)) != 0) { WOLFSSL_MSG("Error creating heap memory mutex"); @@ -17437,7 +17437,7 @@ WOLFSSL_X509* wolfSSL_get_chain_X509(WOLFSSL_X509_CHAIN* chain, int idx) WOLFSSL_MSG("Failed alloc X509"); } else { - InitX509(x509, 1); + InitX509(x509, 1, NULL); if ((ret = CopyDecodedToX509(x509, cert)) != 0) { WOLFSSL_MSG("Failed to copy decoded"); @@ -17848,7 +17848,7 @@ void* wolfSSL_GetRsaDecCtx(WOLFSSL* ssl) #ifndef NO_CERTS void wolfSSL_X509_NAME_free(WOLFSSL_X509_NAME *name){ - FreeX509Name(name); + FreeX509Name(name, NULL); WOLFSSL_ENTER("wolfSSL_X509_NAME_free"); WOLFSSL_STUB("wolfSSL_X509_NAME_free"); } diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index 8523cab52..84d2133bc 100644 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -1955,6 +1955,8 @@ static INLINE void FreeTmpDsas(byte** tmps, void* heap) for (i = 0; i < DSA_INTS; i++) XFREE(tmps[i], heap, DYNAMIC_TYPE_DSA); + + (void)heap; } /* Convert DsaKey key to DER format, write to output (inLen), return bytes diff --git a/wolfcrypt/src/ecc.c b/wolfcrypt/src/ecc.c index ff2135672..19d260b9c 100644 --- a/wolfcrypt/src/ecc.c +++ b/wolfcrypt/src/ecc.c @@ -831,9 +831,9 @@ int ecc_map(ecc_point* P, mp_int* modulus, mp_digit* mp) */ #ifdef FP_ECC static int normal_ecc_mulmod(mp_int* k, ecc_point *G, ecc_point *R, - mp_int* modulus, int map) + mp_int* modulus, int map, void* heap) #else -static int wc_ecc_mulmod_ex(mp_int* k, ecc_point *G, ecc_point *R, +int wc_ecc_mulmod_ex(mp_int* k, ecc_point *G, ecc_point *R, mp_int* modulus, int map, void* heap) #endif { @@ -1055,7 +1055,7 @@ int wc_ecc_mulmod(mp_int* k, ecc_point *G, ecc_point *R, static int normal_ecc_mulmod(mp_int* k, ecc_point *G, ecc_point *R, mp_int* modulus, int map, void* heap) #else -static int wc_ecc_mulmod_ex(mp_int* k, ecc_point *G, ecc_point *R, +int wc_ecc_mulmod_ex(mp_int* k, ecc_point *G, ecc_point *R, mp_int* modulus, int map, void* heap) #endif { @@ -4501,7 +4501,7 @@ int ecc_mul2add(ecc_point* A, mp_int* kA, int wc_ecc_mulmod(mp_int* k, ecc_point *G, ecc_point *R, mp_int* modulus, int map) { - return wc_ecc_mulmod_h(k, G, R, modulus, map, NULL); + return wc_ecc_mulmod_ex(k, G, R, modulus, map, NULL); } @@ -4514,7 +4514,7 @@ int wc_ecc_mulmod(mp_int* k, ecc_point *G, ecc_point *R, mp_int* modulus, otherwise it's left in jacobian-montgomery form return MP_OKAY if successful */ -int wc_ecc_mulmod_h(mp_int* k, ecc_point *G, ecc_point *R, mp_int* modulus, +int wc_ecc_mulmod_ex(mp_int* k, ecc_point *G, ecc_point *R, mp_int* modulus, int map, void* heap) { int idx, err = MP_OKAY; diff --git a/wolfcrypt/src/memory.c b/wolfcrypt/src/memory.c index b5bc701f9..0f70966bd 100644 --- a/wolfcrypt/src/memory.c +++ b/wolfcrypt/src/memory.c @@ -218,7 +218,7 @@ int wolfSSL_load_static_memory(byte* buffer, word32 sz, int flag, } /* align pt */ - while ((word64)pt % WOLFSSL_STATIC_ALIGN && pt < (buffer + sz)) { + while ((long)pt % WOLFSSL_STATIC_ALIGN && pt < (buffer + sz)) { *pt = 0x00; pt++; } @@ -379,8 +379,12 @@ void* wolfSSL_Malloc(size_t size, void* heap, int type) res = NULL; } #else + #ifndef WOLFSSL_NO_MALLOC res = malloc(size); - #endif + #else + WOLFSSL_MSG("No heap hint found to use and no malloc"); + #endif /* WOLFSSL_NO_MALLOC */ + #endif /* WOLFSSL_HEAP_TEST */ } else { WOLFSSL_HEAP_HINT* hint = (WOLFSSL_HEAP_HINT*)heap; @@ -489,7 +493,11 @@ void wolfSSL_Free(void *ptr, void* heap, int type) WOLFSSL_MSG("ERROR null heap hint passed into XFREE\n"); } #endif + #ifndef WOLFSSL_NO_MALLOC free(ptr); + #else + WOLFSSL_MSG("Error trying to call free when turned off"); + #endif /* WOLFSSL_NO_MALLOC */ } else { WOLFSSL_HEAP_HINT* hint = (WOLFSSL_HEAP_HINT*)heap; @@ -571,7 +579,11 @@ void* wolfSSL_Realloc(void *ptr, size_t size, void* heap, int type) #ifdef WOLFSSL_HEAP_TEST WOLFSSL_MSG("ERROR null heap hint passed in to XREALLOC\n"); #endif - res = realloc(ptr, size); + #ifndef WOLFSSL_NO_MALLOC + res = realloc(ptr, size); + #else + WOLFSSL_MSG("NO heap found to use for realloc"); + #endif /* WOLFSSL_NO_MALLOC */ } else { WOLFSSL_HEAP_HINT* hint = (WOLFSSL_HEAP_HINT*)heap; diff --git a/wolfssl/wolfcrypt/ecc.h b/wolfssl/wolfcrypt/ecc.h index 1b97eb388..5f176269f 100644 --- a/wolfssl/wolfcrypt/ecc.h +++ b/wolfssl/wolfcrypt/ecc.h @@ -235,8 +235,8 @@ WOLFSSL_API int wc_ecc_mulmod(mp_int* k, ecc_point *G, ecc_point *R, mp_int* modulus, int map); -WOLFSSL_API -int wc_ecc_mulmod_h(mp_int* k, ecc_point *G, ecc_point *R, +WOLFSSL_LOCAL +int wc_ecc_mulmod_ex(mp_int* k, ecc_point *G, ecc_point *R, mp_int* modulus, int map, void* heap); #ifdef HAVE_ECC_KEY_EXPORT /* ASN key helpers */ diff --git a/wolfssl/wolfcrypt/types.h b/wolfssl/wolfcrypt/types.h index 839ec0dde..9b0468766 100644 --- a/wolfssl/wolfcrypt/types.h +++ b/wolfssl/wolfcrypt/types.h @@ -211,12 +211,6 @@ #endif - /* sleep function for static memory */ - #ifdef WOLFSSL_STATIC_MEMORY - #include - #define XSLEEP(t) sleep((t)) - #endif /* WOLFSSL_STATIC_MEMORY */ - #ifndef STRING_USER #include char* mystrnstr(const char* s1, const char* s2, unsigned int n);