From c9d840ed8de3cb319bef94c96c934617574a4346 Mon Sep 17 00:00:00 2001 From: David Garske Date: Tue, 27 Mar 2018 14:29:39 -0700 Subject: [PATCH] Fix for the `HAVE_THEAD_LS` case with `FP_ECC` where starting a new thead and doing ECC operations and not calling `wc_ecc_fp_free`. Added missing `wolfCrypt_Init` to API docs. --- doc/dox_comments/header_files/wc_port.h | 22 ++++++++++++++++++++++ wolfcrypt/benchmark/benchmark.c | 5 +++++ wolfcrypt/test/test.c | 18 ++++++++++++++---- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/doc/dox_comments/header_files/wc_port.h b/doc/dox_comments/header_files/wc_port.h index 2a187cf72..e81bd471f 100644 --- a/doc/dox_comments/header_files/wc_port.h +++ b/doc/dox_comments/header_files/wc_port.h @@ -1,3 +1,25 @@ +/*! + \ingroup wolfCrypt + + \brief Used to initialize resources used by wolfCrypt. + + \return 0 upon success. + \return <0 upon failure of init resources. + + \param none No parameters. + + _Example_ + \code + ... + if (wolfCrypt_Init() != 0) { + WOLFSSL_MSG("Error with wolfCrypt_Init call"); + } + \endcode + + \sa wolfCrypt_Cleanup +*/ +WOLFSSL_API int wolfCrypt_Init(void); + /*! \ingroup wolfCrypt diff --git a/wolfcrypt/benchmark/benchmark.c b/wolfcrypt/benchmark/benchmark.c index a4655c09f..f0e1226ef 100644 --- a/wolfcrypt/benchmark/benchmark.c +++ b/wolfcrypt/benchmark/benchmark.c @@ -1439,6 +1439,11 @@ exit: wolfAsync_DevClose(&devId); #endif +/* cleanup the thread if fixed point cache is enabled and have thread local */ +#if defined(HAVE_THREAD_LS) && defined(HAVE_ECC) && defined(FP_ECC) + wc_ecc_fp_free(); +#endif + (void)bench_cipher_algs; (void)bench_digest_algs; (void)bench_mac_algs; diff --git a/wolfcrypt/test/test.c b/wolfcrypt/test/test.c index 94de04890..2cd25546d 100644 --- a/wolfcrypt/test/test.c +++ b/wolfcrypt/test/test.c @@ -954,6 +954,11 @@ initDefaultName(); wolfAsync_DevClose(&devId); #endif + /* cleanup the thread if fixed point cache is enabled and have thread local */ +#if defined(HAVE_THREAD_LS) && defined(HAVE_ECC) && defined(FP_ECC) + wc_ecc_fp_free(); +#endif + ((func_args*)args)->return_code = ret; EXIT_TEST(ret); @@ -965,6 +970,7 @@ initDefaultName(); /* so overall tests can pull in test function */ int main(int argc, char** argv) { + int ret; func_args args; #ifdef HAVE_WNR @@ -977,7 +983,10 @@ initDefaultName(); args.argc = argc; args.argv = argv; - wolfCrypt_Init(); + if ((ret = wolfCrypt_Init()) != 0) { + printf("wolfCrypt_Init failed %d\n", ret); + err_sys("Error with wolfCrypt_Init!\n", -1003); + } #ifdef HAVE_STACK_SIZE StackSizeCheck(&args, wolfcrypt_test); @@ -985,13 +994,14 @@ initDefaultName(); wolfcrypt_test(&args); #endif - if (wolfCrypt_Cleanup() != 0) { - err_sys("Error with wolfCrypt_Cleanup!\n", -1003); + if ((ret = wolfCrypt_Cleanup()) != 0) { + printf("wolfCrypt_Cleanup failed %d\n", ret); + err_sys("Error with wolfCrypt_Cleanup!\n", -1004); } #ifdef HAVE_WNR if (wc_FreeNetRandom() < 0) - err_sys("Failed to free netRandom context", -1004); + err_sys("Failed to free netRandom context", -1005); #endif /* HAVE_WNR */ return args.return_code;