From 6b51f2d5b2dd7196540c98e38456ce46bfd0794d Mon Sep 17 00:00:00 2001 From: Tesfa Mael Date: Tue, 23 Apr 2019 16:45:52 -0700 Subject: [PATCH] Added unit test for wc_ecc_get_curve_id_from_dp_params --- tests/api.c | 52 +++++++++++++++++++++++++++++++++++++++++++++----- wolfssl/test.h | 6 ++++-- 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/tests/api.c b/tests/api.c index 87efb38b1..6753a45fb 100644 --- a/tests/api.c +++ b/tests/api.c @@ -2107,7 +2107,7 @@ static THREAD_RETURN WOLFSSL_THREAD test_server_loop(void* args) if (cbf != NULL && cbf->ctx_ready != NULL) { cbf->ctx_ready(ctx); } - + while(count != loop_count) { ssl = wolfSSL_new(ctx); if (ssl == NULL) { @@ -2125,7 +2125,7 @@ static THREAD_RETURN WOLFSSL_THREAD test_server_loop(void* args) "Please run from wolfSSL home dir");*/ goto done; } - + #if !defined(NO_FILESYSTEM) && !defined(NO_DH) wolfSSL_SetTmpDH_file(ssl, dhParamFile, WOLFSSL_FILETYPE_PEM); #elif !defined(NO_DH) @@ -2470,7 +2470,7 @@ static void test_client_reuse_WOLFSSLobj(void* args, void *cb, void* server_args if(wolfSSL_KeepHandshakeResources(ssl)) { /* err_sys("SSL_KeepHandshakeResources failed"); */ goto done; - } + } if (sharedCtx && wolfSSL_use_certificate_file(ssl, cliCertFile, WOLFSSL_FILETYPE_PEM) != WOLFSSL_SUCCESS) { /*err_sys("can't load client cert file, " @@ -22701,6 +22701,48 @@ static void test_wc_ecc_get_curve_id_from_name(void) #endif /* HAVE_ECC */ } +#if defined(OPENSSL_EXTRA) +static void test_wc_ecc_get_curve_id_from_dp_params(void) +{ +#ifdef HAVE_ECC + int id; + int curve_id; + int ret = 0; + WOLFSSL_EC_KEY *ecKey; + ecc_key* key; + const ecc_set_type* params; + + printf(testingFmt, "wc_ecc_get_curve_id_from_dp_params"); + + #if !defined(NO_ECC256) && !defined(NO_ECC_SECP) + id = wc_ecc_get_curve_id_from_name("SECP256R1"); + AssertIntEQ(id, ECC_SECP256R1); + #endif + + ecKey = wolfSSL_EC_KEY_new_by_curve_name(id); + AssertNotNull(ecKey); + + ret = wolfSSL_EC_KEY_generate_key(ecKey); + + if (ret == 0) { + /* normal test */ + key = (ecc_key*)ecKey->internal; + params = key->dp; + + curve_id = wc_ecc_get_curve_id_from_dp_params(params); + AssertIntEQ(curve_id, id); + } + + /* invalid case, NULL input*/ + + id = wc_ecc_get_curve_id_from_dp_params(NULL); + AssertIntEQ(id, BAD_FUNC_ARG); + + printf(resultFmt, passed); +#endif /* HAVE_ECC */ +} +#endif /* OPENSSL_EXTRA */ + static void test_wc_ecc_get_curve_id_from_params(void) { #ifdef HAVE_ECC @@ -24344,7 +24386,7 @@ void ApiTest(void) test_wolfSSL_read_write(); #if defined(OPENSSL_EXTRA) && !defined(NO_SESSION_CACHE) && !defined(WOLFSSL_TLS13) test_wolfSSL_reuse_WOLFSSLobj(); -#endif +#endif #endif test_wolfSSL_dtls_export(); AssertIntEQ(test_wolfSSL_SetMinVersion(), WOLFSSL_SUCCESS); @@ -24501,7 +24543,6 @@ void ApiTest(void) test_wc_ecc_get_curve_size_from_name(); test_wc_ecc_get_curve_id_from_name(); test_wc_ecc_get_curve_id_from_params(); - #ifdef WOLFSSL_TLS13 /* TLS v1.3 API tests */ test_tls13_apis(); @@ -24648,6 +24689,7 @@ void ApiTest(void) test_wolfSSL_EVP_get_cipherbynid(); test_wolfSSL_EC(); test_wolfSSL_ECDSA_SIG(); + test_wc_ecc_get_curve_id_from_dp_params(); #endif #ifdef HAVE_HASHDRBG diff --git a/wolfssl/test.h b/wolfssl/test.h index e8a58e6b2..7d2f9ad10 100644 --- a/wolfssl/test.h +++ b/wolfssl/test.h @@ -155,10 +155,12 @@ #pragma warning(disable:4244 4996) #endif -#define WOLFSSL_CIPHER_LIST_MAX_SIZE 4096 +#ifndef WOLFSSL_CIPHER_LIST_MAX_SIZE + #define WOLFSSL_CIPHER_LIST_MAX_SIZE 4096 +#endif /* Buffer for benchmark tests */ #ifndef TEST_BUFFER_SIZE -#define TEST_BUFFER_SIZE 16384 + #define TEST_BUFFER_SIZE 16384 #endif #ifndef WOLFSSL_HAVE_MIN