From e1edadafe17e24b62eb0c20a741257e732e0d88e Mon Sep 17 00:00:00 2001 From: Jacob Barthelmeh Date: Mon, 6 Jun 2016 16:19:33 -0600 Subject: [PATCH] ocsp with static memory, remove unused function --- src/ocsp.c | 8 +++++--- src/ssl.c | 8 ++++---- wolfcrypt/src/ecc.c | 6 +++--- wolfcrypt/test/test.c | 18 ------------------ wolfssl/ocsp.h | 2 +- wolfssl/ssl.h | 2 +- wolfssl/wolfcrypt/ecc.h | 2 ++ 7 files changed, 16 insertions(+), 30 deletions(-) diff --git a/src/ocsp.c b/src/ocsp.c index 59a8cf057..74b147f39 100644 --- a/src/ocsp.c +++ b/src/ocsp.c @@ -88,7 +88,7 @@ static void FreeOcspEntry(OcspEntry* entry) } -void FreeOCSP(WOLFSSL_OCSP* ocsp, int dynamic) +void FreeOCSP(WOLFSSL_OCSP* ocsp, int dynamic, void* heap) { OcspEntry *entry, *next; @@ -97,13 +97,15 @@ void FreeOCSP(WOLFSSL_OCSP* ocsp, int dynamic) for (entry = ocsp->ocspList; entry; entry = next) { next = entry->next; FreeOcspEntry(entry); - XFREE(entry, NULL, DYNAMIC_TYPE_OCSP_ENTRY); + XFREE(entry, heap, DYNAMIC_TYPE_OCSP_ENTRY); } FreeMutex(&ocsp->ocspLock); if (dynamic) - XFREE(ocsp, NULL, DYNAMIC_TYPE_OCSP); + XFREE(ocsp, heap, DYNAMIC_TYPE_OCSP); + + (void)heap; } diff --git a/src/ssl.c b/src/ssl.c index ecb053630..964587ae1 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -2133,11 +2133,11 @@ void wolfSSL_CertManagerFree(WOLFSSL_CERT_MANAGER* cm) #endif #ifdef HAVE_OCSP if (cm->ocsp) - FreeOCSP(cm->ocsp, 1); + FreeOCSP(cm->ocsp, 1, cm->heap); #if defined(HAVE_CERTIFICATE_STATUS_REQUEST) \ || defined(HAVE_CERTIFICATE_STATUS_REQUEST_V2) if (cm->ocsp_stapling) - FreeOCSP(cm->ocsp_stapling, 1); + FreeOCSP(cm->ocsp_stapling, 1, cm->heap); #endif #endif FreeSignerTable(cm->caTable, CA_TABLE_SIZE, cm->heap); @@ -4308,7 +4308,7 @@ int wolfSSL_CertManagerEnableOCSP(WOLFSSL_CERT_MANAGER* cm, int options) if (InitOCSP(cm->ocsp, cm) != 0) { WOLFSSL_MSG("Init OCSP failed"); - FreeOCSP(cm->ocsp, 1); + FreeOCSP(cm->ocsp, 1, cm->heap); cm->ocsp = NULL; return SSL_FAILURE; } @@ -4364,7 +4364,7 @@ int wolfSSL_CertManagerEnableOCSPStapling(WOLFSSL_CERT_MANAGER* cm) if (InitOCSP(cm->ocsp_stapling, cm) != 0) { WOLFSSL_MSG("Init OCSP failed"); - FreeOCSP(cm->ocsp_stapling, 1); + FreeOCSP(cm->ocsp_stapling, 1, cm->heap); cm->ocsp_stapling = NULL; return SSL_FAILURE; } diff --git a/wolfcrypt/src/ecc.c b/wolfcrypt/src/ecc.c index 19d260b9c..77bfc1ca3 100644 --- a/wolfcrypt/src/ecc.c +++ b/wolfcrypt/src/ecc.c @@ -4813,7 +4813,7 @@ int wc_ecc_ctx_reset(ecEncCtx* ctx, WC_RNG* rng) } -ecEncCtx* wc_ecc_ctx_new_h(int flags, WC_RNG* rng, void* heap) +ecEncCtx* wc_ecc_ctx_new_ex(int flags, WC_RNG* rng, void* heap) { int ret = 0; ecEncCtx* ctx = (ecEncCtx*)XMALLOC(sizeof(ecEncCtx), heap, @@ -4837,7 +4837,7 @@ ecEncCtx* wc_ecc_ctx_new_h(int flags, WC_RNG* rng, void* heap) /* alloc/init and set defaults, return new Context */ ecEncCtx* wc_ecc_ctx_new(int flags, WC_RNG* rng) { - return wc_ecc_ctx_new_h(flags, rng, NULL); + return wc_ecc_ctx_new_ex(flags, rng, NULL); } @@ -4846,7 +4846,7 @@ void wc_ecc_ctx_free(ecEncCtx* ctx) { if (ctx) { ForceZero(ctx, sizeof(ecEncCtx)); - XFREE(ctx, 0, DYNAMIC_TYPE_ECC); + XFREE(ctx, ctx->heap, DYNAMIC_TYPE_ECC); } } diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index 8af170df0..a6419c756 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -246,9 +246,6 @@ int certext_test(void); #ifdef HAVE_IDEA int idea_test(void); #endif -#ifdef WOLFSSL_STATIC_MEMORY - int memory_test(void); -#endif /* General big buffer size for many tests. */ #define FOURK_BUF 4096 @@ -314,13 +311,6 @@ int wolfcrypt_test(void* args) #endif /* USE_FAST_MATH */ #endif /* !NO_BIG_INT */ -#ifdef WOLFSSL_STATIC_MEMORY - if ( (ret = memory_test()) != 0) - return err_sys("MEMORY test failed!\n", ret); - else - printf( "MEMORY test passed!\n"); -#endif - #ifndef NO_MD5 if ( (ret = md5_test()) != 0) return err_sys("MD5 test failed!\n", ret); @@ -712,14 +702,6 @@ static int OpenNitroxDevice(int dma_mode,int dev_id) #endif /* NO_MAIN_DRIVER */ -#ifdef WOLFSSL_STATIC_MEMORY -int memory_test() -{ - return 0; -} -#endif /* WOLFSSL_STATIC_MEMORY */ - - #ifdef WOLFSSL_MD2 int md2_test() { diff --git a/wolfssl/ocsp.h b/wolfssl/ocsp.h index af083410b..7865302fb 100644 --- a/wolfssl/ocsp.h +++ b/wolfssl/ocsp.h @@ -39,7 +39,7 @@ struct buffer; typedef struct WOLFSSL_OCSP WOLFSSL_OCSP; WOLFSSL_LOCAL int InitOCSP(WOLFSSL_OCSP*, WOLFSSL_CERT_MANAGER*); -WOLFSSL_LOCAL void FreeOCSP(WOLFSSL_OCSP*, int dynamic); +WOLFSSL_LOCAL void FreeOCSP(WOLFSSL_OCSP*, int dynamic, void* heap); WOLFSSL_LOCAL int CheckCertOCSP(WOLFSSL_OCSP*, DecodedCert*, struct buffer* responseBuffer); diff --git a/wolfssl/ssl.h b/wolfssl/ssl.h index 671f04040..b9da0c5f1 100644 --- a/wolfssl/ssl.h +++ b/wolfssl/ssl.h @@ -262,7 +262,7 @@ WOLFSSL_API int wolfSSL_dtls_export(WOLFSSL* ssl, unsigned char* buf, typedef struct WOLFSSL_MEM_STATS WOLFSSL_MEM_STATS; typedef struct WOLFSSL_MEM_CONN_STATS WOLFSSL_MEM_CONN_STATS; WOLFSSL_API int wolfSSL_CTX_load_static_memory(WOLFSSL_CTX** ctx, - wolfSSLStaticMethod method, + wolfSSLStaticMethod method, unsigned char* buf, unsigned int sz, int flag, int max); WOLFSSL_API int wolfSSL_CTX_is_static_memory(WOLFSSL_CTX* ctx, diff --git a/wolfssl/wolfcrypt/ecc.h b/wolfssl/wolfcrypt/ecc.h index 5f176269f..f834eed31 100644 --- a/wolfssl/wolfcrypt/ecc.h +++ b/wolfssl/wolfcrypt/ecc.h @@ -320,6 +320,8 @@ typedef struct ecEncCtx ecEncCtx; WOLFSSL_API ecEncCtx* wc_ecc_ctx_new(int flags, WC_RNG* rng); WOLFSSL_API +ecEncCtx* wc_ecc_ctx_new_ex(int flags, WC_RNG* rng, void* heap); +WOLFSSL_API void wc_ecc_ctx_free(ecEncCtx*); WOLFSSL_API int wc_ecc_ctx_reset(ecEncCtx*, WC_RNG*); /* reset for use again w/o alloc/free */