From 6cc84d230120a9bd8e5208f838d499302d91c288 Mon Sep 17 00:00:00 2001 From: Carie Pointer Date: Mon, 21 May 2018 17:11:21 -0600 Subject: [PATCH 1/8] Add initial test_wc_SignatureGetSize() method --- tests/api.c | 145 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) diff --git a/tests/api.c b/tests/api.c index 11bcbded3..c35490fc7 100644 --- a/tests/api.c +++ b/tests/api.c @@ -24,6 +24,10 @@ | Includes *----------------------------------------------------------------------------*/ +#ifndef NO_SIG_WRAPPER + #include +#endif + #ifdef HAVE_CONFIG_H #include #endif @@ -14731,6 +14735,144 @@ static void test_wc_PKCS7_EncodeEncryptedData (void) } /* END test_wc_PKCS7_EncodeEncryptedData() */ +/* Testing wc_SignatureGetSize() */ +static int test_wc_SignatureGetSize(void) { + + int ret = 0; + enum wc_SignatureType sig_type; + word32 key_len; + ecc_key ecc; + + RsaKey rsa_key; + byte* tmp = NULL; + size_t bytes; + + /* Initialize ECC Key */ + const char* qx = "fa2737fb93488d19caef11ae7faf6b7f4bcd67b286e3fc54e8a65c2b74aeccb0"; + const char* qy = "d4ccd6dae698208aa8c3a6f39e45510d03be09b2f124bfc067856c324f9b4d09"; + const char* d = "be34baa8d040a3b991f9075b56ba292f755b90e4b6dc10dad36715c33cfdac25"; + + ret = wc_ecc_init(&ecc); + if (ret != 0) { + ret = WOLFSSL_FATAL_ERROR; + return ret; + } + ret = wc_ecc_import_raw(&ecc, qx, qy, d, "SECP256R1"); + if (ret != 0) { + wc_ecc_free(&ecc); + ret = WOLFSSL_FATAL_ERROR; + return ret; + } + + /* Initialize RSA Key */ + #ifdef USE_CERT_BUFFERS_1024 + bytes = (size_t)sizeof_client_key_der_1024; + if (bytes < (size_t)sizeof_client_key_der_1024) + bytes = (size_t)sizeof_client_cert_der_1024; + #elif defined(USE_CERT_BUFFERS_2048) + bytes = (size_t)sizeof_client_key_der_2048; + if (bytes < (size_t)sizeof_client_cert_der_2048) + bytes = (size_t)sizeof_client_cert_der_2048; + #else + bytes = FOURK_BUF; + #endif + tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + if (tmp == NULL + #ifdef WOLFSSL_ASYNC_CRYPT + || out == NULL || plain == NULL + #endif + ) { + ret = WOLFSSL_FATAL_ERROR; + return ret; + } + #ifdef USE_CERT_BUFFERS_1024 + XMEMCPY(tmp, client_key_der_1024, (size_t)sizeof_client_key_ker_1024); + #elif defined(USE_CERT_BUFFERS_2048) + XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048); + #elif !defined(NO_FILESYSTEM) + file = fopen(clientKey, "rb"); + if (!file) { + ret = WOLFSSL_FATAL_ERROR; + return ret; + } + bytes = fread(tmp, 1, FOURK_BUF, file); + fclose(file); + #else + /* No key to use */ + ret = WOLFSSL_FATAL_ERROR; + return ret; + #endif + ret = wc_InitRsaKey_ex(&rsa_key, HEAP_HINT, devId); + if (ret != 0) { + ret = WOLFSSL_FATAL_ERROR; + } + ret = wc_RsaPrivateKeyDecode(tmp, 0, &rsa_key, (word32)bytes); + if (ret != 0) { + ret = WOLFSSL_FATAL_ERROR; + } + + + /* Input for signature type ECC */ + sig_type = WC_SIGNATURE_TYPE_ECC; + key_len = sizeof(ecc_key); + ret = wc_SignatureGetSize(sig_type, &ecc, key_len); + + if (ret > 0) { + #ifdef HAVE_ECC + sig_type = 100; + ret = wc_SignatureGetSize(sig_type, &ecc, key_len); + if (ret == BAD_FUNC_ARG) { + sig_type = WC_SIGNATURE_TYPE_ECC; + ret = wc_SignatureGetSize(sig_type, NULL, key_len); + } + if (ret == BAD_FUNC_ARG) { + key_len = 0; + ret = wc_SignatureGetSize(sig_type, &ecc, key_len); + } + #else + ret = SIG_TYPE_E; + #endif + if (ret != SIG_TYPE_E) { + return ret; + } + } else { + ret = WOLFSSL_FATAL_ERROR; + } + + /* Input for signature type RSA */ + sig_type = WC_SIGNATURE_TYPE_RSA; + key_len = sizeof(RsaKey); + ret = wc_SignatureGetSize(sig_type, &rsa_key, key_len); + + if (ret > 0) { + #ifndef NO_RSA + sig_type = 100; + ret = wc_SignatureGetSize(sig_type, &rsa_key, key_len); + if (ret == BAD_FUNC_ARG) { + sig_type = WC_SIGNATURE_TYPE_RSA; + ret = wc_SignatureGetSize(sig_type, NULL, key_len); + } + if (ret == BAD_FUNC_ARG) { + key_len = 0; + ret = wc_SignatureGetSize(sig_type, &rsa_key, key_len); + } + #else + ret = SIG_TYPE_E; + #endif + if (ret == SIG_TYPE_E) { + ret = 0; + } + } else { + ret = WOLFSSL_FATAL_ERROR; + } + + wc_ecc_free(&ecc); + wc_FreeRsaKey(&rsa_key); + printf(resultFmt, ret == 0 ? passed : failed); + + return ret; +}/* END test_wc_SignatureGetSize(void) */ + /*----------------------------------------------------------------------------* | Compatibility Tests @@ -18823,6 +18965,9 @@ void ApiTest(void) AssertIntEQ(test_wc_DsaExportParamsRaw(), 0); AssertIntEQ(test_wc_DsaExportKeyRaw(), 0); + /*NEW*/ + AssertIntEQ(test_wc_SignatureGetSize(), 0); + #ifdef OPENSSL_EXTRA /*wolfSSS_EVP_get_cipherbynid test*/ test_wolfSSL_EVP_get_cipherbynid(); From df24bc6096e7a1b5de524a6f91b35f0154eeb597 Mon Sep 17 00:00:00 2001 From: Carie Pointer Date: Tue, 22 May 2018 09:22:01 -0600 Subject: [PATCH 2/8] Update unit test --- tests/api.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/api.c b/tests/api.c index c35490fc7..41dfa94ce 100644 --- a/tests/api.c +++ b/tests/api.c @@ -24,10 +24,6 @@ | Includes *----------------------------------------------------------------------------*/ -#ifndef NO_SIG_WRAPPER - #include -#endif - #ifdef HAVE_CONFIG_H #include #endif @@ -226,6 +222,11 @@ #endif #endif +#ifndef NO_SIG_WRAPPER + #include +#endif + + #ifdef HAVE_AESCCM #include #endif @@ -14741,8 +14742,7 @@ static int test_wc_SignatureGetSize(void) { int ret = 0; enum wc_SignatureType sig_type; word32 key_len; - ecc_key ecc; - + ecc_key ecc; RsaKey rsa_key; byte* tmp = NULL; size_t bytes; @@ -18964,8 +18964,6 @@ void ApiTest(void) AssertIntEQ(test_wc_DsaImportParamsRaw(), 0); AssertIntEQ(test_wc_DsaExportParamsRaw(), 0); AssertIntEQ(test_wc_DsaExportKeyRaw(), 0); - - /*NEW*/ AssertIntEQ(test_wc_SignatureGetSize(), 0); #ifdef OPENSSL_EXTRA From 6321008ef477ee5bf9d70075ea826cde7c6ecc4c Mon Sep 17 00:00:00 2001 From: Carie Pointer Date: Tue, 22 May 2018 13:24:36 -0600 Subject: [PATCH 3/8] Modify wc_SignatureGetSize test for ECC and RSA specific API --- tests/api.c | 147 ++++++++++++++++++++++++++++------------------------ 1 file changed, 80 insertions(+), 67 deletions(-) diff --git a/tests/api.c b/tests/api.c index 41dfa94ce..abf9ad22b 100644 --- a/tests/api.c +++ b/tests/api.c @@ -14737,88 +14737,93 @@ static void test_wc_PKCS7_EncodeEncryptedData (void) /* Testing wc_SignatureGetSize() */ -static int test_wc_SignatureGetSize(void) { +static int test_wc_SignatureGetSize(void) +{ int ret = 0; enum wc_SignatureType sig_type; word32 key_len; - ecc_key ecc; - RsaKey rsa_key; - byte* tmp = NULL; - size_t bytes; /* Initialize ECC Key */ - const char* qx = "fa2737fb93488d19caef11ae7faf6b7f4bcd67b286e3fc54e8a65c2b74aeccb0"; - const char* qy = "d4ccd6dae698208aa8c3a6f39e45510d03be09b2f124bfc067856c324f9b4d09"; - const char* d = "be34baa8d040a3b991f9075b56ba292f755b90e4b6dc10dad36715c33cfdac25"; + #if defined(HAVE_ECC) && !defined(NO_ECC256) + ecc_key ecc; + + const char* qx = + "fa2737fb93488d19caef11ae7faf6b7f4bcd67b286e3fc54e8a65c2b74aeccb0"; + const char* qy = + "d4ccd6dae698208aa8c3a6f39e45510d03be09b2f124bfc067856c324f9b4d09"; + const char* d = + "be34baa8d040a3b991f9075b56ba292f755b90e4b6dc10dad36715c33cfdac25"; - ret = wc_ecc_init(&ecc); - if (ret != 0) { - ret = WOLFSSL_FATAL_ERROR; - return ret; - } - ret = wc_ecc_import_raw(&ecc, qx, qy, d, "SECP256R1"); - if (ret != 0) { - wc_ecc_free(&ecc); - ret = WOLFSSL_FATAL_ERROR; - return ret; - } - - /* Initialize RSA Key */ - #ifdef USE_CERT_BUFFERS_1024 - bytes = (size_t)sizeof_client_key_der_1024; - if (bytes < (size_t)sizeof_client_key_der_1024) - bytes = (size_t)sizeof_client_cert_der_1024; - #elif defined(USE_CERT_BUFFERS_2048) - bytes = (size_t)sizeof_client_key_der_2048; - if (bytes < (size_t)sizeof_client_cert_der_2048) - bytes = (size_t)sizeof_client_cert_der_2048; - #else - bytes = FOURK_BUF; - #endif - tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - if (tmp == NULL - #ifdef WOLFSSL_ASYNC_CRYPT - || out == NULL || plain == NULL - #endif - ) { - ret = WOLFSSL_FATAL_ERROR; - return ret; - } - #ifdef USE_CERT_BUFFERS_1024 - XMEMCPY(tmp, client_key_der_1024, (size_t)sizeof_client_key_ker_1024); - #elif defined(USE_CERT_BUFFERS_2048) - XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048); - #elif !defined(NO_FILESYSTEM) - file = fopen(clientKey, "rb"); - if (!file) { - ret = WOLFSSL_FATAL_ERROR; - return ret; - } - bytes = fread(tmp, 1, FOURK_BUF, file); - fclose(file); - #else - /* No key to use */ - ret = WOLFSSL_FATAL_ERROR; - return ret; - #endif - ret = wc_InitRsaKey_ex(&rsa_key, HEAP_HINT, devId); + ret = wc_ecc_init(&ecc); if (ret != 0) { ret = WOLFSSL_FATAL_ERROR; + goto done; } - ret = wc_RsaPrivateKeyDecode(tmp, 0, &rsa_key, (word32)bytes); + ret = wc_ecc_import_raw(&ecc, qx, qy, d, "SECP256R1"); if (ret != 0) { + wc_ecc_free(&ecc); ret = WOLFSSL_FATAL_ERROR; - } + goto done; + } + #endif + /* Initialize RSA Key */ + #ifndef NO_RSA + RsaKey rsa_key; + byte* tmp = NULL; + size_t bytes; + + #ifdef USE_CERT_BUFFERS_1024 + bytes = (size_t)sizeof_client_key_der_1024; + if (bytes < (size_t)sizeof_client_key_der_1024) + bytes = (size_t)sizeof_client_cert_der_1024; + #elif defined(USE_CERT_BUFFERS_2048) + bytes = (size_t)sizeof_client_key_der_2048; + if (bytes < (size_t)sizeof_client_cert_der_2048) + bytes = (size_t)sizeof_client_cert_der_2048; + #else + bytes = FOURK_BUF; + #endif + tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + if (tmp == NULL) { + ret = WOLFSSL_FATAL_ERROR; + goto done; + } + #ifdef USE_CERT_BUFFERS_1024 + XMEMCPY(tmp, client_key_der_1024, (size_t)sizeof_client_key_ker_1024); + #elif defined(USE_CERT_BUFFERS_2048) + XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048); + #elif !defined(NO_FILESYSTEM) + file = fopen(clientKey, "rb"); + if (!file) { + ret = WOLFSSL_FATAL_ERROR; + goto done; + } + bytes = fread(tmp, 1, FOURK_BUF, file); + fclose(file); + #else + ret = WOLFSSL_FATAL_ERROR; + goto done; + #endif + ret = wc_InitRsaKey_ex(&rsa_key, HEAP_HINT, devId); + if (ret != 0) { + ret = WOLFSSL_FATAL_ERROR; + } + ret = wc_RsaPrivateKeyDecode(tmp, 0, &rsa_key, (word32)bytes); + if (ret != 0) { + ret = WOLFSSL_FATAL_ERROR; + } + #endif /* Input for signature type ECC */ + #ifdef HAVE_ECC sig_type = WC_SIGNATURE_TYPE_ECC; key_len = sizeof(ecc_key); ret = wc_SignatureGetSize(sig_type, &ecc, key_len); + /* Test bad args */ if (ret > 0) { - #ifdef HAVE_ECC sig_type = 100; ret = wc_SignatureGetSize(sig_type, &ecc, key_len); if (ret == BAD_FUNC_ARG) { @@ -14833,19 +14838,21 @@ static int test_wc_SignatureGetSize(void) { ret = SIG_TYPE_E; #endif if (ret != SIG_TYPE_E) { - return ret; + goto done; } } else { ret = WOLFSSL_FATAL_ERROR; + goto done; } /* Input for signature type RSA */ + #ifndef NO_RSA sig_type = WC_SIGNATURE_TYPE_RSA; key_len = sizeof(RsaKey); ret = wc_SignatureGetSize(sig_type, &rsa_key, key_len); + /* Test bad args */ if (ret > 0) { - #ifndef NO_RSA sig_type = 100; ret = wc_SignatureGetSize(sig_type, &rsa_key, key_len); if (ret == BAD_FUNC_ARG) { @@ -14864,11 +14871,17 @@ static int test_wc_SignatureGetSize(void) { } } else { ret = WOLFSSL_FATAL_ERROR; + goto done; } - wc_ecc_free(&ecc); - wc_FreeRsaKey(&rsa_key); - printf(resultFmt, ret == 0 ? passed : failed); + done: + #ifdef HAVE_ECC + wc_ecc_free(&ecc); + #endif + #ifndef NO_RSA + wc_FreeRsaKey(&rsa_key); + #endif + printf(resultFmt, ret == 0 ? passed : failed); return ret; }/* END test_wc_SignatureGetSize(void) */ From 8bd41629ae771266d9a94004022f7ec8c0368366 Mon Sep 17 00:00:00 2001 From: Carie Pointer Date: Wed, 23 May 2018 14:26:35 -0600 Subject: [PATCH 4/8] Split wc_SignatureGetSize test into wc_SignatureGetSize_ecc and wc_SignatureGetSize_rsa tests --- tests/api.c | 230 +++++++++++++++++++++++++++------------------------- 1 file changed, 121 insertions(+), 109 deletions(-) diff --git a/tests/api.c b/tests/api.c index abf9ad22b..399c8a80d 100644 --- a/tests/api.c +++ b/tests/api.c @@ -14736,18 +14736,16 @@ static void test_wc_PKCS7_EncodeEncryptedData (void) } /* END test_wc_PKCS7_EncodeEncryptedData() */ -/* Testing wc_SignatureGetSize() */ -static int test_wc_SignatureGetSize(void) -{ - +/* Testing wc_SignatureGetSize() for signature type ECC */ +static int test_wc_SignatureGetSize_ecc(void) +{ int ret = 0; - enum wc_SignatureType sig_type; - word32 key_len; - - /* Initialize ECC Key */ #if defined(HAVE_ECC) && !defined(NO_ECC256) - ecc_key ecc; - + enum wc_SignatureType sig_type; + word32 key_len; + + /* Initialize ECC Key */ + ecc_key ecc; const char* qx = "fa2737fb93488d19caef11ae7faf6b7f4bcd67b286e3fc54e8a65c2b74aeccb0"; const char* qy = @@ -14756,20 +14754,61 @@ static int test_wc_SignatureGetSize(void) "be34baa8d040a3b991f9075b56ba292f755b90e4b6dc10dad36715c33cfdac25"; ret = wc_ecc_init(&ecc); - if (ret != 0) { - ret = WOLFSSL_FATAL_ERROR; - goto done; + if (ret == 0) { + ret = wc_ecc_import_raw(&ecc, qx, qy, d, "SECP256R1"); } - ret = wc_ecc_import_raw(&ecc, qx, qy, d, "SECP256R1"); - if (ret != 0) { - wc_ecc_free(&ecc); + printf(testingFmt, "wc_SigntureGetSize_ecc()"); + if (ret == 0) { + /* Input for signature type ECC */ + sig_type = WC_SIGNATURE_TYPE_ECC; + key_len = sizeof(ecc_key); + ret = wc_SignatureGetSize(sig_type, &ecc, key_len); + + /* Test bad args */ + if (ret > 0) { + sig_type = 100; + ret = wc_SignatureGetSize(sig_type, &ecc, key_len); + if (ret == BAD_FUNC_ARG) { + sig_type = WC_SIGNATURE_TYPE_ECC; + ret = wc_SignatureGetSize(sig_type, NULL, key_len); + } + if (ret >= 0) { + key_len = 0; + ret = wc_SignatureGetSize(sig_type, &ecc, key_len); + } + if (ret == BAD_FUNC_ARG) { + ret = SIG_TYPE_E; + } + } + } else { ret = WOLFSSL_FATAL_ERROR; - goto done; - } + } + wc_ecc_free(&ecc); + #else + ret = SIG_TYPE_E; #endif - /* Initialize RSA Key */ + if (ret == SIG_TYPE_E) { + ret = 0; + } + else { + ret = WOLFSSL_FATAL_ERROR; + } + + printf(resultFmt, ret == 0 ? passed : failed); + return ret; +}/* END test_wc_SignatureGetSize_ecc() */ + +/* Testing wc_SignatureGetSize() for signature type rsa */ +static int test_wc_SignatureGetSize_rsa(void) +{ + int ret = 0; #ifndef NO_RSA + enum wc_SignatureType sig_type; + word32 key_len; + word32 idx = 0; + + /* Initialize RSA Key */ RsaKey rsa_key; byte* tmp = NULL; size_t bytes; @@ -14785,106 +14824,78 @@ static int test_wc_SignatureGetSize(void) #else bytes = FOURK_BUF; #endif - tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - if (tmp == NULL) { + + tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); + if (tmp != NULL) { + #ifdef USE_CERT_BUFFERS_1024 + XMEMCPY(tmp, client_key_der_1024, + (size_t)sizeof_client_key_ker_1024); + #elif defined(USE_CERT_BUFFERS_2048) + XMEMCPY(tmp, client_key_der_2048, + (size_t)sizeof_client_key_der_2048); + #elif !defined(NO_FILESYSTEM) + file = fopen(clientKey, "rb"); + if (file != NULL) { + bytes = fread(tmp, 1, FOURK_BUF, file); + fclose(file); + } + else { + ret = WOLFSSL_FATAL_ERROR; + } + #else ret = WOLFSSL_FATAL_ERROR; - goto done; + #endif + if (ret == 0) { + ret = wc_InitRsaKey_ex(&rsa_key, HEAP_HINT, devId); + if (ret == 0) { + ret = wc_RsaPrivateKeyDecode(tmp, &idx, &rsa_key, + (word32)bytes); + } } - #ifdef USE_CERT_BUFFERS_1024 - XMEMCPY(tmp, client_key_der_1024, (size_t)sizeof_client_key_ker_1024); - #elif defined(USE_CERT_BUFFERS_2048) - XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048); - #elif !defined(NO_FILESYSTEM) - file = fopen(clientKey, "rb"); - if (!file) { - ret = WOLFSSL_FATAL_ERROR; - goto done; - } - bytes = fread(tmp, 1, FOURK_BUF, file); - fclose(file); - #else + } else { ret = WOLFSSL_FATAL_ERROR; - goto done; - #endif - ret = wc_InitRsaKey_ex(&rsa_key, HEAP_HINT, devId); - if (ret != 0) { - ret = WOLFSSL_FATAL_ERROR; - } - ret = wc_RsaPrivateKeyDecode(tmp, 0, &rsa_key, (word32)bytes); - if (ret != 0) { - ret = WOLFSSL_FATAL_ERROR; - } - #endif + } - /* Input for signature type ECC */ - #ifdef HAVE_ECC - sig_type = WC_SIGNATURE_TYPE_ECC; - key_len = sizeof(ecc_key); - ret = wc_SignatureGetSize(sig_type, &ecc, key_len); - - /* Test bad args */ - if (ret > 0) { - sig_type = 100; - ret = wc_SignatureGetSize(sig_type, &ecc, key_len); - if (ret == BAD_FUNC_ARG) { - sig_type = WC_SIGNATURE_TYPE_ECC; - ret = wc_SignatureGetSize(sig_type, NULL, key_len); - } - if (ret == BAD_FUNC_ARG) { - key_len = 0; - ret = wc_SignatureGetSize(sig_type, &ecc, key_len); - } - #else - ret = SIG_TYPE_E; - #endif - if (ret != SIG_TYPE_E) { - goto done; - } - } else { - ret = WOLFSSL_FATAL_ERROR; - goto done; - } - - /* Input for signature type RSA */ - #ifndef NO_RSA - sig_type = WC_SIGNATURE_TYPE_RSA; - key_len = sizeof(RsaKey); - ret = wc_SignatureGetSize(sig_type, &rsa_key, key_len); - - /* Test bad args */ - if (ret > 0) { - sig_type = 100; - ret = wc_SignatureGetSize(sig_type, &rsa_key, key_len); - if (ret == BAD_FUNC_ARG) { + printf(testingFmt, "wc_SigntureGetSize_rsa()"); + if (ret == 0) { + /* Input for signature type RSA */ sig_type = WC_SIGNATURE_TYPE_RSA; - ret = wc_SignatureGetSize(sig_type, NULL, key_len); - } - if (ret == BAD_FUNC_ARG) { - key_len = 0; + key_len = sizeof(RsaKey); ret = wc_SignatureGetSize(sig_type, &rsa_key, key_len); - } + + /* Test bad args */ + if (ret > 0) { + sig_type = 100; + ret = wc_SignatureGetSize(sig_type, &rsa_key, key_len); + if (ret == BAD_FUNC_ARG) { + sig_type = WC_SIGNATURE_TYPE_RSA; + ret = wc_SignatureGetSize(sig_type, NULL, key_len); + } + if (ret == BAD_FUNC_ARG) { + key_len = 0; + ret = wc_SignatureGetSize(sig_type, &rsa_key, key_len); + } + if (ret == BAD_FUNC_ARG) { + ret = SIG_TYPE_E; + } + } + } else { + ret = WOLFSSL_FATAL_ERROR; + } + wc_FreeRsaKey(&rsa_key); #else ret = SIG_TYPE_E; #endif - if (ret == SIG_TYPE_E) { - ret = 0; - } - } else { + + if (ret == SIG_TYPE_E) { + ret = 0; + }else { ret = WOLFSSL_FATAL_ERROR; - goto done; } - - done: - #ifdef HAVE_ECC - wc_ecc_free(&ecc); - #endif - #ifndef NO_RSA - wc_FreeRsaKey(&rsa_key); - #endif - printf(resultFmt, ret == 0 ? passed : failed); - - return ret; -}/* END test_wc_SignatureGetSize(void) */ + + printf(resultFmt, ret == 0 ? passed : failed); + return ret; +}/* END test_wc_SignatureGetSize_rsa(void) */ /*----------------------------------------------------------------------------* @@ -18977,7 +18988,8 @@ void ApiTest(void) AssertIntEQ(test_wc_DsaImportParamsRaw(), 0); AssertIntEQ(test_wc_DsaExportParamsRaw(), 0); AssertIntEQ(test_wc_DsaExportKeyRaw(), 0); - AssertIntEQ(test_wc_SignatureGetSize(), 0); + AssertIntEQ(test_wc_SignatureGetSize_ecc(), 0); + AssertIntEQ(test_wc_SignatureGetSize_rsa(), 0); #ifdef OPENSSL_EXTRA /*wolfSSS_EVP_get_cipherbynid test*/ From a18f220a5a8475c0659483ab1ccfd4d29d8750e5 Mon Sep 17 00:00:00 2001 From: Carie Pointer Date: Wed, 23 May 2018 14:39:36 -0600 Subject: [PATCH 5/8] Remove trailing whitespaces --- tests/api.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/api.c b/tests/api.c index 399c8a80d..88fb44b75 100644 --- a/tests/api.c +++ b/tests/api.c @@ -14745,7 +14745,7 @@ static int test_wc_SignatureGetSize_ecc(void) word32 key_len; /* Initialize ECC Key */ - ecc_key ecc; + ecc_key ecc; const char* qx = "fa2737fb93488d19caef11ae7faf6b7f4bcd67b286e3fc54e8a65c2b74aeccb0"; const char* qy = @@ -14774,7 +14774,7 @@ static int test_wc_SignatureGetSize_ecc(void) } if (ret >= 0) { key_len = 0; - ret = wc_SignatureGetSize(sig_type, &ecc, key_len); + ret = wc_SignatureGetSize(sig_type, &ecc, key_len); } if (ret == BAD_FUNC_ARG) { ret = SIG_TYPE_E; @@ -14826,7 +14826,7 @@ static int test_wc_SignatureGetSize_rsa(void) #endif tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); - if (tmp != NULL) { + if (tmp != NULL) { #ifdef USE_CERT_BUFFERS_1024 XMEMCPY(tmp, client_key_der_1024, (size_t)sizeof_client_key_ker_1024); From 005a0d4dff2514224c5b4fb906529368d120c606 Mon Sep 17 00:00:00 2001 From: Carie Pointer Date: Wed, 23 May 2018 20:17:11 -0600 Subject: [PATCH 6/8] Define devId if RSA is enabled --- tests/api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/api.c b/tests/api.c index 0c3050c56..e3a4a8cbb 100644 --- a/tests/api.c +++ b/tests/api.c @@ -249,7 +249,7 @@ #include #endif -#if defined(WOLFSSL_SHA3) || defined(HAVE_PKCS7) +#if defined(WOLFSSL_SHA3) || defined(HAVE_PKCS7) || !defined(NO_RSA) static int devId = INVALID_DEVID; #endif #ifndef NO_DSA From 65014248f93f95a58b0213fccc67399338db714e Mon Sep 17 00:00:00 2001 From: Carie Pointer Date: Thu, 24 May 2018 16:32:27 -0600 Subject: [PATCH 7/8] Fix typos, update ret for if HAVE_USER_RSA defined --- tests/api.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/api.c b/tests/api.c index e3a4a8cbb..0eccc4616 100644 --- a/tests/api.c +++ b/tests/api.c @@ -14950,14 +14950,14 @@ static int test_wc_SignatureGetSize_ecc(void) /* Test bad args */ if (ret > 0) { - sig_type = 100; + sig_type = (enum wc_SignatureType) 100; ret = wc_SignatureGetSize(sig_type, &ecc, key_len); if (ret == BAD_FUNC_ARG) { sig_type = WC_SIGNATURE_TYPE_ECC; ret = wc_SignatureGetSize(sig_type, NULL, key_len); } if (ret >= 0) { - key_len = 0; + key_len = (word32) 0; ret = wc_SignatureGetSize(sig_type, &ecc, key_len); } if (ret == BAD_FUNC_ARG) { @@ -15013,7 +15013,7 @@ static int test_wc_SignatureGetSize_rsa(void) if (tmp != NULL) { #ifdef USE_CERT_BUFFERS_1024 XMEMCPY(tmp, client_key_der_1024, - (size_t)sizeof_client_key_ker_1024); + (size_t)sizeof_client_key_der_1024); #elif defined(USE_CERT_BUFFERS_2048) XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048); @@ -15049,14 +15049,18 @@ static int test_wc_SignatureGetSize_rsa(void) /* Test bad args */ if (ret > 0) { - sig_type = 100; + sig_type = (enum wc_SignatureType) 100; ret = wc_SignatureGetSize(sig_type, &rsa_key, key_len); if (ret == BAD_FUNC_ARG) { sig_type = WC_SIGNATURE_TYPE_RSA; ret = wc_SignatureGetSize(sig_type, NULL, key_len); } + #ifndef HAVE_USER_RSA if (ret == BAD_FUNC_ARG) { - key_len = 0; + #else + if (ret == USER_CRYPTO_ERROR) { + #endif + key_len = (word32)0; ret = wc_SignatureGetSize(sig_type, &rsa_key, key_len); } if (ret == BAD_FUNC_ARG) { @@ -15067,6 +15071,7 @@ static int test_wc_SignatureGetSize_rsa(void) ret = WOLFSSL_FATAL_ERROR; } wc_FreeRsaKey(&rsa_key); + XFREE(tmp, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); #else ret = SIG_TYPE_E; #endif From 12dc346058a8cf0b92599a38284e78840d2017ea Mon Sep 17 00:00:00 2001 From: Carie Pointer Date: Fri, 25 May 2018 09:25:25 -0600 Subject: [PATCH 8/8] Change return value to 0 for null key when HAVE_USER_RSA is defined --- tests/api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/api.c b/tests/api.c index 0eccc4616..a9b3871a8 100644 --- a/tests/api.c +++ b/tests/api.c @@ -15058,7 +15058,7 @@ static int test_wc_SignatureGetSize_rsa(void) #ifndef HAVE_USER_RSA if (ret == BAD_FUNC_ARG) { #else - if (ret == USER_CRYPTO_ERROR) { + if (ret == 0) { #endif key_len = (word32)0; ret = wc_SignatureGetSize(sig_type, &rsa_key, key_len);