mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-31 19:24:42 +02:00
Merge pull request #7337 from gojimmypi/PR-test-certbuf-256
wolfcrypt tests: improve file system gating for USE_CERT_BUFFERS
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
/* test.c
|
/* test.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2006-2023 wolfSSL Inc.
|
* Copyright (C) 2006-2024 wolfSSL Inc.
|
||||||
*
|
*
|
||||||
* This file is part of wolfSSL.
|
* This file is part of wolfSSL.
|
||||||
*
|
*
|
||||||
@@ -18776,8 +18776,10 @@ static wc_test_ret_t rsa_ecc_certgen_test(WC_RNG* rng, byte* tmp)
|
|||||||
word32 idx3 = 0;
|
word32 idx3 = 0;
|
||||||
#if (!defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)) \
|
#if (!defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)) \
|
||||||
|| !defined(USE_CERT_BUFFERS_256)
|
|| !defined(USE_CERT_BUFFERS_256)
|
||||||
|
#ifndef NO_FILESYSTEM
|
||||||
XFILE file3;
|
XFILE file3;
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
wc_test_ret_t ret;
|
wc_test_ret_t ret;
|
||||||
|
|
||||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
|
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
|
||||||
@@ -18829,10 +18831,13 @@ static wc_test_ret_t rsa_ecc_certgen_test(WC_RNG* rng, byte* tmp)
|
|||||||
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
|
ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
|
||||||
|
|
||||||
/* Get Cert Key */
|
/* Get Cert Key */
|
||||||
#ifdef USE_CERT_BUFFERS_256
|
#if defined(USE_CERT_BUFFERS_256)
|
||||||
|
{
|
||||||
XMEMCPY(tmp, ecc_key_pub_der_256, sizeof_ecc_key_pub_der_256);
|
XMEMCPY(tmp, ecc_key_pub_der_256, sizeof_ecc_key_pub_der_256);
|
||||||
bytes3 = sizeof_ecc_key_pub_der_256;
|
bytes3 = sizeof_ecc_key_pub_der_256;
|
||||||
#else
|
}
|
||||||
|
#elif !defined(NO_FILESYSTEM)
|
||||||
|
{
|
||||||
file3 = XFOPEN(eccKeyPubFileDer, "rb");
|
file3 = XFOPEN(eccKeyPubFileDer, "rb");
|
||||||
if (!file3) {
|
if (!file3) {
|
||||||
ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
|
ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
|
||||||
@@ -18842,6 +18847,12 @@ static wc_test_ret_t rsa_ecc_certgen_test(WC_RNG* rng, byte* tmp)
|
|||||||
XFCLOSE(file3);
|
XFCLOSE(file3);
|
||||||
if (bytes3 == 0)
|
if (bytes3 == 0)
|
||||||
ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
|
ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
{
|
||||||
|
WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(1)");
|
||||||
|
ERROR_OUT(ASN_PARSE_E, exit_rsa);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ret = wc_ecc_init_ex(caEccKeyPub, HEAP_HINT, devId);
|
ret = wc_ecc_init_ex(caEccKeyPub, HEAP_HINT, devId);
|
||||||
@@ -27422,10 +27433,12 @@ static wc_test_ret_t ecc_test_make_pub(WC_RNG* rng)
|
|||||||
wc_ecc_init_ex(key, HEAP_HINT, devId);
|
wc_ecc_init_ex(key, HEAP_HINT, devId);
|
||||||
|
|
||||||
#ifndef NO_ECC256
|
#ifndef NO_ECC256
|
||||||
#ifdef USE_CERT_BUFFERS_256
|
#if defined(USE_CERT_BUFFERS_256)
|
||||||
|
{
|
||||||
XMEMCPY(tmp, ecc_key_der_256, (size_t)sizeof_ecc_key_der_256);
|
XMEMCPY(tmp, ecc_key_der_256, (size_t)sizeof_ecc_key_der_256);
|
||||||
tmpSz = (size_t)sizeof_ecc_key_der_256;
|
tmpSz = (size_t)sizeof_ecc_key_der_256;
|
||||||
#else
|
}
|
||||||
|
#elif !defined(NO_FILESYSTEM)
|
||||||
{
|
{
|
||||||
XFILE file = XFOPEN(eccKeyDerFile, "rb");
|
XFILE file = XFOPEN(eccKeyDerFile, "rb");
|
||||||
if (!file) {
|
if (!file) {
|
||||||
@@ -27437,6 +27450,11 @@ static wc_test_ret_t ecc_test_make_pub(WC_RNG* rng)
|
|||||||
if (tmpSz == 0)
|
if (tmpSz == 0)
|
||||||
ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
|
ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
{
|
||||||
|
WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(2)");
|
||||||
|
ERROR_OUT(ASN_PARSE_E, done);
|
||||||
|
}
|
||||||
#endif /* USE_CERT_BUFFERS_256 */
|
#endif /* USE_CERT_BUFFERS_256 */
|
||||||
|
|
||||||
/* import private only then test with */
|
/* import private only then test with */
|
||||||
@@ -28968,10 +28986,12 @@ static wc_test_ret_t ecc_def_curve_test(WC_RNG *rng)
|
|||||||
((defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT)) || \
|
((defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT)) || \
|
||||||
(defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT)))
|
(defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT)))
|
||||||
/* Use test ECC key - ensure real private "d" exists */
|
/* Use test ECC key - ensure real private "d" exists */
|
||||||
#ifdef USE_CERT_BUFFERS_256
|
#if defined(USE_CERT_BUFFERS_256)
|
||||||
|
{
|
||||||
ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &idx, key,
|
ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &idx, key,
|
||||||
sizeof_ecc_key_der_256);
|
sizeof_ecc_key_der_256);
|
||||||
#else
|
}
|
||||||
|
#elif !defined(NO_FILESYSTEM)
|
||||||
{
|
{
|
||||||
XFILE file = XFOPEN(eccKeyDerFile, "rb");
|
XFILE file = XFOPEN(eccKeyDerFile, "rb");
|
||||||
byte der[128];
|
byte der[128];
|
||||||
@@ -28985,6 +29005,12 @@ static wc_test_ret_t ecc_def_curve_test(WC_RNG *rng)
|
|||||||
ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
|
ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
|
||||||
ret = wc_EccPrivateKeyDecode(der, &idx, key, derSz);
|
ret = wc_EccPrivateKeyDecode(der, &idx, key, derSz);
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
{
|
||||||
|
(void)idx;
|
||||||
|
WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(3)");
|
||||||
|
ERROR_OUT(ASN_PARSE_E, done);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
goto done;
|
goto done;
|
||||||
@@ -29913,9 +29939,9 @@ static wc_test_ret_t ecc_test_cert_gen(WC_RNG* rng)
|
|||||||
ecc_key certPubKey[1];
|
ecc_key certPubKey[1];
|
||||||
#endif
|
#endif
|
||||||
int certSz;
|
int certSz;
|
||||||
size_t bytes;
|
size_t bytes = 0;
|
||||||
word32 idx = 0;
|
word32 idx = 0;
|
||||||
#ifndef USE_CERT_BUFFERS_256
|
#if !defined(USE_CERT_BUFFERS_256) && !defined(NO_FILESYSTEM)
|
||||||
XFILE file;
|
XFILE file;
|
||||||
#endif
|
#endif
|
||||||
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
|
#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
|
||||||
@@ -29949,7 +29975,7 @@ static wc_test_ret_t ecc_test_cert_gen(WC_RNG* rng)
|
|||||||
#ifdef USE_CERT_BUFFERS_256
|
#ifdef USE_CERT_BUFFERS_256
|
||||||
XMEMCPY(der, ca_ecc_key_der_384, sizeof_ca_ecc_key_der_384);
|
XMEMCPY(der, ca_ecc_key_der_384, sizeof_ca_ecc_key_der_384);
|
||||||
bytes = sizeof_ca_ecc_key_der_384;
|
bytes = sizeof_ca_ecc_key_der_384;
|
||||||
#else
|
#elif !defined(NO_FILESYSTEM)
|
||||||
file = XFOPEN(eccCaKey384File, "rb");
|
file = XFOPEN(eccCaKey384File, "rb");
|
||||||
if (!file) {
|
if (!file) {
|
||||||
ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
|
ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
|
||||||
@@ -29960,8 +29986,15 @@ static wc_test_ret_t ecc_test_cert_gen(WC_RNG* rng)
|
|||||||
if (bytes == 0)
|
if (bytes == 0)
|
||||||
ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
|
ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
|
||||||
(void)eccCaKeyFile;
|
(void)eccCaKeyFile;
|
||||||
#endif /* USE_CERT_BUFFERS_256 */
|
|
||||||
#else
|
#else
|
||||||
|
WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(4)");
|
||||||
|
ERROR_OUT(ASN_PARSE_E, exit);
|
||||||
|
#endif /* USE_CERT_BUFFERS_256 */
|
||||||
|
|
||||||
|
/* end if ENABLE_ECC384_CERT_GEN_TEST */
|
||||||
|
#else
|
||||||
|
/* !ENABLE_ECC384_CERT_GEN_TEST */
|
||||||
|
|
||||||
#ifdef USE_CERT_BUFFERS_256
|
#ifdef USE_CERT_BUFFERS_256
|
||||||
XMEMCPY(der, ca_ecc_key_der_256, sizeof_ca_ecc_key_der_256);
|
XMEMCPY(der, ca_ecc_key_der_256, sizeof_ca_ecc_key_der_256);
|
||||||
bytes = sizeof_ca_ecc_key_der_256;
|
bytes = sizeof_ca_ecc_key_der_256;
|
||||||
@@ -29974,6 +30007,7 @@ static wc_test_ret_t ecc_test_cert_gen(WC_RNG* rng)
|
|||||||
XFCLOSE(file);
|
XFCLOSE(file);
|
||||||
if (bytes == 0)
|
if (bytes == 0)
|
||||||
ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
|
ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
|
||||||
|
|
||||||
#ifdef ENABLE_ECC384_CERT_GEN_TEST
|
#ifdef ENABLE_ECC384_CERT_GEN_TEST
|
||||||
(void)eccCaKey384File;
|
(void)eccCaKey384File;
|
||||||
#endif
|
#endif
|
||||||
@@ -30041,11 +30075,16 @@ static wc_test_ret_t ecc_test_cert_gen(WC_RNG* rng)
|
|||||||
#if defined(USE_CERT_BUFFERS_256)
|
#if defined(USE_CERT_BUFFERS_256)
|
||||||
ret = wc_SetIssuerBuffer(myCert, ca_ecc_cert_der_384,
|
ret = wc_SetIssuerBuffer(myCert, ca_ecc_cert_der_384,
|
||||||
sizeof_ca_ecc_cert_der_384);
|
sizeof_ca_ecc_cert_der_384);
|
||||||
#else
|
#elif !defined(NO_FILESYSTEM)
|
||||||
ret = wc_SetIssuer(myCert, eccCaCert384File);
|
ret = wc_SetIssuer(myCert, eccCaCert384File);
|
||||||
(void)eccCaCertFile;
|
(void)eccCaCertFile;
|
||||||
#endif
|
|
||||||
#else
|
#else
|
||||||
|
/* not testing with embedded, no file system target */
|
||||||
|
ERROR_OUT(ASN_PARSE_E, exit);
|
||||||
|
#endif /* USE_CERT_BUFFERS_256 */
|
||||||
|
|
||||||
|
#else
|
||||||
|
/* not ENABLE_ECC384_CERT_GEN_TEST */
|
||||||
#if defined(USE_CERT_BUFFERS_256)
|
#if defined(USE_CERT_BUFFERS_256)
|
||||||
ret = wc_SetIssuerBuffer(myCert, ca_ecc_cert_der_256,
|
ret = wc_SetIssuerBuffer(myCert, ca_ecc_cert_der_256,
|
||||||
sizeof_ca_ecc_cert_der_256);
|
sizeof_ca_ecc_cert_der_256);
|
||||||
|
Reference in New Issue
Block a user