Modify wc_SignatureGetSize test for ECC and RSA specific API

This commit is contained in:
Carie Pointer
2018-05-22 13:24:36 -06:00
parent df24bc6096
commit 6321008ef4

View File

@ -14737,34 +14737,43 @@ static void test_wc_PKCS7_EncodeEncryptedData (void)
/* Testing wc_SignatureGetSize() */ /* Testing wc_SignatureGetSize() */
static int test_wc_SignatureGetSize(void) { static int test_wc_SignatureGetSize(void)
{
int ret = 0; int ret = 0;
enum wc_SignatureType sig_type; enum wc_SignatureType sig_type;
word32 key_len; word32 key_len;
ecc_key ecc;
RsaKey rsa_key;
byte* tmp = NULL;
size_t bytes;
/* Initialize ECC Key */ /* Initialize ECC Key */
const char* qx = "fa2737fb93488d19caef11ae7faf6b7f4bcd67b286e3fc54e8a65c2b74aeccb0"; #if defined(HAVE_ECC) && !defined(NO_ECC256)
const char* qy = "d4ccd6dae698208aa8c3a6f39e45510d03be09b2f124bfc067856c324f9b4d09"; ecc_key ecc;
const char* d = "be34baa8d040a3b991f9075b56ba292f755b90e4b6dc10dad36715c33cfdac25";
const char* qx =
"fa2737fb93488d19caef11ae7faf6b7f4bcd67b286e3fc54e8a65c2b74aeccb0";
const char* qy =
"d4ccd6dae698208aa8c3a6f39e45510d03be09b2f124bfc067856c324f9b4d09";
const char* d =
"be34baa8d040a3b991f9075b56ba292f755b90e4b6dc10dad36715c33cfdac25";
ret = wc_ecc_init(&ecc); ret = wc_ecc_init(&ecc);
if (ret != 0) { if (ret != 0) {
ret = WOLFSSL_FATAL_ERROR; ret = WOLFSSL_FATAL_ERROR;
return ret; goto done;
} }
ret = wc_ecc_import_raw(&ecc, qx, qy, d, "SECP256R1"); ret = wc_ecc_import_raw(&ecc, qx, qy, d, "SECP256R1");
if (ret != 0) { if (ret != 0) {
wc_ecc_free(&ecc); wc_ecc_free(&ecc);
ret = WOLFSSL_FATAL_ERROR; ret = WOLFSSL_FATAL_ERROR;
return ret; goto done;
} }
#endif
/* Initialize RSA Key */ /* Initialize RSA Key */
#ifndef NO_RSA
RsaKey rsa_key;
byte* tmp = NULL;
size_t bytes;
#ifdef USE_CERT_BUFFERS_1024 #ifdef USE_CERT_BUFFERS_1024
bytes = (size_t)sizeof_client_key_der_1024; bytes = (size_t)sizeof_client_key_der_1024;
if (bytes < (size_t)sizeof_client_key_der_1024) if (bytes < (size_t)sizeof_client_key_der_1024)
@ -14777,13 +14786,9 @@ static int test_wc_SignatureGetSize(void) {
bytes = FOURK_BUF; bytes = FOURK_BUF;
#endif #endif
tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER); tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
if (tmp == NULL if (tmp == NULL) {
#ifdef WOLFSSL_ASYNC_CRYPT
|| out == NULL || plain == NULL
#endif
) {
ret = WOLFSSL_FATAL_ERROR; ret = WOLFSSL_FATAL_ERROR;
return ret; goto done;
} }
#ifdef USE_CERT_BUFFERS_1024 #ifdef USE_CERT_BUFFERS_1024
XMEMCPY(tmp, client_key_der_1024, (size_t)sizeof_client_key_ker_1024); XMEMCPY(tmp, client_key_der_1024, (size_t)sizeof_client_key_ker_1024);
@ -14793,14 +14798,13 @@ static int test_wc_SignatureGetSize(void) {
file = fopen(clientKey, "rb"); file = fopen(clientKey, "rb");
if (!file) { if (!file) {
ret = WOLFSSL_FATAL_ERROR; ret = WOLFSSL_FATAL_ERROR;
return ret; goto done;
} }
bytes = fread(tmp, 1, FOURK_BUF, file); bytes = fread(tmp, 1, FOURK_BUF, file);
fclose(file); fclose(file);
#else #else
/* No key to use */
ret = WOLFSSL_FATAL_ERROR; ret = WOLFSSL_FATAL_ERROR;
return ret; goto done;
#endif #endif
ret = wc_InitRsaKey_ex(&rsa_key, HEAP_HINT, devId); ret = wc_InitRsaKey_ex(&rsa_key, HEAP_HINT, devId);
if (ret != 0) { if (ret != 0) {
@ -14810,15 +14814,16 @@ static int test_wc_SignatureGetSize(void) {
if (ret != 0) { if (ret != 0) {
ret = WOLFSSL_FATAL_ERROR; ret = WOLFSSL_FATAL_ERROR;
} }
#endif
/* Input for signature type ECC */ /* Input for signature type ECC */
#ifdef HAVE_ECC
sig_type = WC_SIGNATURE_TYPE_ECC; sig_type = WC_SIGNATURE_TYPE_ECC;
key_len = sizeof(ecc_key); key_len = sizeof(ecc_key);
ret = wc_SignatureGetSize(sig_type, &ecc, key_len); ret = wc_SignatureGetSize(sig_type, &ecc, key_len);
/* Test bad args */
if (ret > 0) { if (ret > 0) {
#ifdef HAVE_ECC
sig_type = 100; sig_type = 100;
ret = wc_SignatureGetSize(sig_type, &ecc, key_len); ret = wc_SignatureGetSize(sig_type, &ecc, key_len);
if (ret == BAD_FUNC_ARG) { if (ret == BAD_FUNC_ARG) {
@ -14833,19 +14838,21 @@ static int test_wc_SignatureGetSize(void) {
ret = SIG_TYPE_E; ret = SIG_TYPE_E;
#endif #endif
if (ret != SIG_TYPE_E) { if (ret != SIG_TYPE_E) {
return ret; goto done;
} }
} else { } else {
ret = WOLFSSL_FATAL_ERROR; ret = WOLFSSL_FATAL_ERROR;
goto done;
} }
/* Input for signature type RSA */ /* Input for signature type RSA */
#ifndef NO_RSA
sig_type = WC_SIGNATURE_TYPE_RSA; sig_type = WC_SIGNATURE_TYPE_RSA;
key_len = sizeof(RsaKey); key_len = sizeof(RsaKey);
ret = wc_SignatureGetSize(sig_type, &rsa_key, key_len); ret = wc_SignatureGetSize(sig_type, &rsa_key, key_len);
/* Test bad args */
if (ret > 0) { if (ret > 0) {
#ifndef NO_RSA
sig_type = 100; sig_type = 100;
ret = wc_SignatureGetSize(sig_type, &rsa_key, key_len); ret = wc_SignatureGetSize(sig_type, &rsa_key, key_len);
if (ret == BAD_FUNC_ARG) { if (ret == BAD_FUNC_ARG) {
@ -14864,10 +14871,16 @@ static int test_wc_SignatureGetSize(void) {
} }
} else { } else {
ret = WOLFSSL_FATAL_ERROR; ret = WOLFSSL_FATAL_ERROR;
goto done;
} }
done:
#ifdef HAVE_ECC
wc_ecc_free(&ecc); wc_ecc_free(&ecc);
#endif
#ifndef NO_RSA
wc_FreeRsaKey(&rsa_key); wc_FreeRsaKey(&rsa_key);
#endif
printf(resultFmt, ret == 0 ? passed : failed); printf(resultFmt, ret == 0 ? passed : failed);
return ret; return ret;