forked from wolfSSL/wolfssl
Split wc_SignatureGetSize test into wc_SignatureGetSize_ecc and wc_SignatureGetSize_rsa tests
This commit is contained in:
158
tests/api.c
158
tests/api.c
@@ -14736,18 +14736,16 @@ static void test_wc_PKCS7_EncodeEncryptedData (void)
|
|||||||
} /* END test_wc_PKCS7_EncodeEncryptedData() */
|
} /* END test_wc_PKCS7_EncodeEncryptedData() */
|
||||||
|
|
||||||
|
|
||||||
/* Testing wc_SignatureGetSize() */
|
/* Testing wc_SignatureGetSize() for signature type ECC */
|
||||||
static int test_wc_SignatureGetSize(void)
|
static int test_wc_SignatureGetSize_ecc(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
#if defined(HAVE_ECC) && !defined(NO_ECC256)
|
||||||
enum wc_SignatureType sig_type;
|
enum wc_SignatureType sig_type;
|
||||||
word32 key_len;
|
word32 key_len;
|
||||||
|
|
||||||
/* Initialize ECC Key */
|
/* Initialize ECC Key */
|
||||||
#if defined(HAVE_ECC) && !defined(NO_ECC256)
|
|
||||||
ecc_key ecc;
|
ecc_key ecc;
|
||||||
|
|
||||||
const char* qx =
|
const char* qx =
|
||||||
"fa2737fb93488d19caef11ae7faf6b7f4bcd67b286e3fc54e8a65c2b74aeccb0";
|
"fa2737fb93488d19caef11ae7faf6b7f4bcd67b286e3fc54e8a65c2b74aeccb0";
|
||||||
const char* qy =
|
const char* qy =
|
||||||
@@ -14756,20 +14754,61 @@ static int test_wc_SignatureGetSize(void)
|
|||||||
"be34baa8d040a3b991f9075b56ba292f755b90e4b6dc10dad36715c33cfdac25";
|
"be34baa8d040a3b991f9075b56ba292f755b90e4b6dc10dad36715c33cfdac25";
|
||||||
|
|
||||||
ret = wc_ecc_init(&ecc);
|
ret = wc_ecc_init(&ecc);
|
||||||
if (ret != 0) {
|
if (ret == 0) {
|
||||||
ret = WOLFSSL_FATAL_ERROR;
|
|
||||||
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) {
|
|
||||||
wc_ecc_free(&ecc);
|
|
||||||
ret = WOLFSSL_FATAL_ERROR;
|
|
||||||
goto done;
|
|
||||||
}
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
wc_ecc_free(&ecc);
|
||||||
|
#else
|
||||||
|
ret = SIG_TYPE_E;
|
||||||
#endif
|
#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
|
#ifndef NO_RSA
|
||||||
|
enum wc_SignatureType sig_type;
|
||||||
|
word32 key_len;
|
||||||
|
word32 idx = 0;
|
||||||
|
|
||||||
|
/* Initialize RSA Key */
|
||||||
RsaKey rsa_key;
|
RsaKey rsa_key;
|
||||||
byte* tmp = NULL;
|
byte* tmp = NULL;
|
||||||
size_t bytes;
|
size_t bytes;
|
||||||
@@ -14785,68 +14824,41 @@ static int test_wc_SignatureGetSize(void)
|
|||||||
#else
|
#else
|
||||||
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) {
|
||||||
ret = WOLFSSL_FATAL_ERROR;
|
|
||||||
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);
|
||||||
#elif defined(USE_CERT_BUFFERS_2048)
|
#elif defined(USE_CERT_BUFFERS_2048)
|
||||||
XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048);
|
XMEMCPY(tmp, client_key_der_2048,
|
||||||
|
(size_t)sizeof_client_key_der_2048);
|
||||||
#elif !defined(NO_FILESYSTEM)
|
#elif !defined(NO_FILESYSTEM)
|
||||||
file = fopen(clientKey, "rb");
|
file = fopen(clientKey, "rb");
|
||||||
if (!file) {
|
if (file != NULL) {
|
||||||
ret = WOLFSSL_FATAL_ERROR;
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
bytes = fread(tmp, 1, FOURK_BUF, file);
|
bytes = fread(tmp, 1, FOURK_BUF, file);
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ret = WOLFSSL_FATAL_ERROR;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
ret = WOLFSSL_FATAL_ERROR;
|
ret = WOLFSSL_FATAL_ERROR;
|
||||||
goto done;
|
|
||||||
#endif
|
#endif
|
||||||
|
if (ret == 0) {
|
||||||
ret = wc_InitRsaKey_ex(&rsa_key, HEAP_HINT, devId);
|
ret = wc_InitRsaKey_ex(&rsa_key, HEAP_HINT, devId);
|
||||||
if (ret != 0) {
|
if (ret == 0) {
|
||||||
ret = WOLFSSL_FATAL_ERROR;
|
ret = wc_RsaPrivateKeyDecode(tmp, &idx, &rsa_key,
|
||||||
|
(word32)bytes);
|
||||||
}
|
}
|
||||||
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 {
|
} else {
|
||||||
ret = WOLFSSL_FATAL_ERROR;
|
ret = WOLFSSL_FATAL_ERROR;
|
||||||
goto done;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printf(testingFmt, "wc_SigntureGetSize_rsa()");
|
||||||
|
if (ret == 0) {
|
||||||
/* 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);
|
||||||
@@ -14863,28 +14875,27 @@ static int test_wc_SignatureGetSize(void)
|
|||||||
key_len = 0;
|
key_len = 0;
|
||||||
ret = wc_SignatureGetSize(sig_type, &rsa_key, key_len);
|
ret = wc_SignatureGetSize(sig_type, &rsa_key, key_len);
|
||||||
}
|
}
|
||||||
#else
|
if (ret == BAD_FUNC_ARG) {
|
||||||
ret = SIG_TYPE_E;
|
ret = SIG_TYPE_E;
|
||||||
#endif
|
}
|
||||||
if (ret == SIG_TYPE_E) {
|
|
||||||
ret = 0;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ret = WOLFSSL_FATAL_ERROR;
|
ret = WOLFSSL_FATAL_ERROR;
|
||||||
goto done;
|
}
|
||||||
|
wc_FreeRsaKey(&rsa_key);
|
||||||
|
#else
|
||||||
|
ret = SIG_TYPE_E;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (ret == SIG_TYPE_E) {
|
||||||
|
ret = 0;
|
||||||
|
}else {
|
||||||
|
ret = WOLFSSL_FATAL_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
done:
|
|
||||||
#ifdef HAVE_ECC
|
|
||||||
wc_ecc_free(&ecc);
|
|
||||||
#endif
|
|
||||||
#ifndef NO_RSA
|
|
||||||
wc_FreeRsaKey(&rsa_key);
|
|
||||||
#endif
|
|
||||||
printf(resultFmt, ret == 0 ? passed : failed);
|
printf(resultFmt, ret == 0 ? passed : failed);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}/* END test_wc_SignatureGetSize(void) */
|
}/* END test_wc_SignatureGetSize_rsa(void) */
|
||||||
|
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*
|
/*----------------------------------------------------------------------------*
|
||||||
@@ -18977,7 +18988,8 @@ void ApiTest(void)
|
|||||||
AssertIntEQ(test_wc_DsaImportParamsRaw(), 0);
|
AssertIntEQ(test_wc_DsaImportParamsRaw(), 0);
|
||||||
AssertIntEQ(test_wc_DsaExportParamsRaw(), 0);
|
AssertIntEQ(test_wc_DsaExportParamsRaw(), 0);
|
||||||
AssertIntEQ(test_wc_DsaExportKeyRaw(), 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
|
#ifdef OPENSSL_EXTRA
|
||||||
/*wolfSSS_EVP_get_cipherbynid test*/
|
/*wolfSSS_EVP_get_cipherbynid test*/
|
||||||
|
Reference in New Issue
Block a user