forked from wolfSSL/wolfssl
Modify wc_SignatureGetSize test for ECC and RSA specific API
This commit is contained in:
149
tests/api.c
149
tests/api.c
@ -14737,88 +14737,93 @@ 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";
|
|
||||||
|
|
||||||
ret = wc_ecc_init(&ecc);
|
const char* qx =
|
||||||
if (ret != 0) {
|
"fa2737fb93488d19caef11ae7faf6b7f4bcd67b286e3fc54e8a65c2b74aeccb0";
|
||||||
ret = WOLFSSL_FATAL_ERROR;
|
const char* qy =
|
||||||
return ret;
|
"d4ccd6dae698208aa8c3a6f39e45510d03be09b2f124bfc067856c324f9b4d09";
|
||||||
}
|
const char* d =
|
||||||
ret = wc_ecc_import_raw(&ecc, qx, qy, d, "SECP256R1");
|
"be34baa8d040a3b991f9075b56ba292f755b90e4b6dc10dad36715c33cfdac25";
|
||||||
if (ret != 0) {
|
|
||||||
wc_ecc_free(&ecc);
|
|
||||||
ret = WOLFSSL_FATAL_ERROR;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Initialize RSA Key */
|
ret = wc_ecc_init(&ecc);
|
||||||
#ifdef USE_CERT_BUFFERS_1024
|
if (ret != 0) {
|
||||||
bytes = (size_t)sizeof_client_key_der_1024;
|
ret = WOLFSSL_FATAL_ERROR;
|
||||||
if (bytes < (size_t)sizeof_client_key_der_1024)
|
goto done;
|
||||||
bytes = (size_t)sizeof_client_cert_der_1024;
|
}
|
||||||
#elif defined(USE_CERT_BUFFERS_2048)
|
ret = wc_ecc_import_raw(&ecc, qx, qy, d, "SECP256R1");
|
||||||
bytes = (size_t)sizeof_client_key_der_2048;
|
if (ret != 0) {
|
||||||
if (bytes < (size_t)sizeof_client_cert_der_2048)
|
wc_ecc_free(&ecc);
|
||||||
bytes = (size_t)sizeof_client_cert_der_2048;
|
ret = WOLFSSL_FATAL_ERROR;
|
||||||
#else
|
goto done;
|
||||||
bytes = FOURK_BUF;
|
}
|
||||||
#endif
|
#endif
|
||||||
tmp = (byte*)XMALLOC(bytes, HEAP_HINT, DYNAMIC_TYPE_TMP_BUFFER);
|
|
||||||
if (tmp == NULL
|
/* Initialize RSA Key */
|
||||||
#ifdef WOLFSSL_ASYNC_CRYPT
|
#ifndef NO_RSA
|
||||||
|| out == NULL || plain == NULL
|
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
|
#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;
|
ret = WOLFSSL_FATAL_ERROR;
|
||||||
return ret;
|
goto done;
|
||||||
}
|
#endif
|
||||||
#ifdef USE_CERT_BUFFERS_1024
|
ret = wc_InitRsaKey_ex(&rsa_key, HEAP_HINT, devId);
|
||||||
XMEMCPY(tmp, client_key_der_1024, (size_t)sizeof_client_key_ker_1024);
|
if (ret != 0) {
|
||||||
#elif defined(USE_CERT_BUFFERS_2048)
|
ret = WOLFSSL_FATAL_ERROR;
|
||||||
XMEMCPY(tmp, client_key_der_2048, (size_t)sizeof_client_key_der_2048);
|
}
|
||||||
#elif !defined(NO_FILESYSTEM)
|
ret = wc_RsaPrivateKeyDecode(tmp, 0, &rsa_key, (word32)bytes);
|
||||||
file = fopen(clientKey, "rb");
|
if (ret != 0) {
|
||||||
if (!file) {
|
ret = WOLFSSL_FATAL_ERROR;
|
||||||
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
|
#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 */
|
/* 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,11 +14871,17 @@ static int test_wc_SignatureGetSize(void) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ret = WOLFSSL_FATAL_ERROR;
|
ret = WOLFSSL_FATAL_ERROR;
|
||||||
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
wc_ecc_free(&ecc);
|
done:
|
||||||
wc_FreeRsaKey(&rsa_key);
|
#ifdef HAVE_ECC
|
||||||
printf(resultFmt, ret == 0 ? passed : failed);
|
wc_ecc_free(&ecc);
|
||||||
|
#endif
|
||||||
|
#ifndef NO_RSA
|
||||||
|
wc_FreeRsaKey(&rsa_key);
|
||||||
|
#endif
|
||||||
|
printf(resultFmt, ret == 0 ? passed : failed);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}/* END test_wc_SignatureGetSize(void) */
|
}/* END test_wc_SignatureGetSize(void) */
|
||||||
|
Reference in New Issue
Block a user