11/* test.c
22 *
3- * Copyright (C) 2006-2023 wolfSSL Inc.
3+ * Copyright (C) 2006-2024 wolfSSL Inc.
44 *
55 * This file is part of wolfSSL.
66 *
@@ -18697,7 +18697,9 @@ static wc_test_ret_t rsa_ecc_certgen_test(WC_RNG* rng, byte* tmp)
1869718697 word32 idx3 = 0;
1869818698#if (!defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)) \
1869918699 || !defined(USE_CERT_BUFFERS_256)
18700- XFILE file3;
18700+ #ifndef NO_FILESYSTEM
18701+ XFILE file3;
18702+ #endif
1870118703#endif
1870218704 wc_test_ret_t ret;
1870318705
@@ -18750,20 +18752,29 @@ static wc_test_ret_t rsa_ecc_certgen_test(WC_RNG* rng, byte* tmp)
1875018752 ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
1875118753
1875218754 /* Get Cert Key */
18753- #ifdef USE_CERT_BUFFERS_256
18754- XMEMCPY(tmp, ecc_key_pub_der_256, sizeof_ecc_key_pub_der_256);
18755- bytes3 = sizeof_ecc_key_pub_der_256;
18756- #else
18757- file3 = XFOPEN(eccKeyPubFileDer, "rb");
18758- if (!file3) {
18759- ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
18755+ #if defined(USE_CERT_BUFFERS_256)
18756+ {
18757+ XMEMCPY(tmp, ecc_key_pub_der_256, sizeof_ecc_key_pub_der_256);
18758+ bytes3 = sizeof_ecc_key_pub_der_256;
1876018759 }
18760+ #elif !defined(NO_FILESYSTEM)
18761+ {
18762+ file3 = XFOPEN(eccKeyPubFileDer, "rb");
18763+ if (!file3) {
18764+ ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
18765+ }
1876118766
18762- bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3);
18763- XFCLOSE(file3);
18764- if (bytes3 == 0)
18765- ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
18766- #endif
18767+ bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3);
18768+ XFCLOSE(file3);
18769+ if (bytes3 == 0)
18770+ ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
18771+ }
18772+ #else
18773+ {
18774+ WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(1)");
18775+ ERROR_OUT(ASN_PARSE_E, exit_rsa);
18776+ }
18777+ #endif
1876718778
1876818779 ret = wc_ecc_init_ex(caEccKeyPub, HEAP_HINT, devId);
1876918780 if (ret != 0)
@@ -27343,10 +27354,12 @@ static wc_test_ret_t ecc_test_make_pub(WC_RNG* rng)
2734327354 wc_ecc_init_ex(key, HEAP_HINT, devId);
2734427355
2734527356#ifndef NO_ECC256
27346- #ifdef USE_CERT_BUFFERS_256
27347- XMEMCPY(tmp, ecc_key_der_256, (size_t)sizeof_ecc_key_der_256);
27348- tmpSz = (size_t)sizeof_ecc_key_der_256;
27349- #else
27357+ #if defined(USE_CERT_BUFFERS_256)
27358+ {
27359+ XMEMCPY(tmp, ecc_key_der_256, (size_t)sizeof_ecc_key_der_256);
27360+ tmpSz = (size_t)sizeof_ecc_key_der_256;
27361+ }
27362+ #elif !defined(NO_FILESYSTEM)
2735027363 {
2735127364 XFILE file = XFOPEN(eccKeyDerFile, "rb");
2735227365 if (!file) {
@@ -27358,6 +27371,11 @@ static wc_test_ret_t ecc_test_make_pub(WC_RNG* rng)
2735827371 if (tmpSz == 0)
2735927372 ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
2736027373 }
27374+ #else
27375+ {
27376+ WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(2)");
27377+ ERROR_OUT(ASN_PARSE_E, done);
27378+ }
2736127379#endif /* USE_CERT_BUFFERS_256 */
2736227380
2736327381 /* import private only then test with */
@@ -28889,10 +28907,12 @@ static wc_test_ret_t ecc_def_curve_test(WC_RNG *rng)
2888928907 ((defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT)) || \
2889028908 (defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT)))
2889128909 /* Use test ECC key - ensure real private "d" exists */
28892- #ifdef USE_CERT_BUFFERS_256
28893- ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &idx, key,
28894- sizeof_ecc_key_der_256);
28895- #else
28910+ #if defined(USE_CERT_BUFFERS_256)
28911+ {
28912+ ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &idx, key,
28913+ sizeof_ecc_key_der_256);
28914+ }
28915+ #elif !defined(NO_FILESYSTEM)
2889628916 {
2889728917 XFILE file = XFOPEN(eccKeyDerFile, "rb");
2889828918 byte der[128];
@@ -28906,6 +28926,12 @@ static wc_test_ret_t ecc_def_curve_test(WC_RNG *rng)
2890628926 ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
2890728927 ret = wc_EccPrivateKeyDecode(der, &idx, key, derSz);
2890828928 }
28929+ #else
28930+ {
28931+ (void)idx;
28932+ WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(3)");
28933+ ERROR_OUT(ASN_PARSE_E, done);
28934+ }
2890928935 #endif
2891028936 if (ret != 0) {
2891128937 goto done;
@@ -29834,9 +29860,9 @@ static wc_test_ret_t ecc_test_cert_gen(WC_RNG* rng)
2983429860 ecc_key certPubKey[1];
2983529861#endif
2983629862 int certSz;
29837- size_t bytes;
29863+ size_t bytes = 0 ;
2983829864 word32 idx = 0;
29839- #ifndef USE_CERT_BUFFERS_256
29865+ #if !defined( USE_CERT_BUFFERS_256) && !defined(NO_FILESYSTEM)
2984029866 XFILE file;
2984129867#endif
2984229868#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
@@ -29867,38 +29893,46 @@ static wc_test_ret_t ecc_test_cert_gen(WC_RNG* rng)
2986729893 /* Get cert private key */
2986829894#ifdef ENABLE_ECC384_CERT_GEN_TEST
2986929895 /* Get Cert Key 384 */
29870- #ifdef USE_CERT_BUFFERS_256
29871- XMEMCPY(der, ca_ecc_key_der_384, sizeof_ca_ecc_key_der_384);
29872- bytes = sizeof_ca_ecc_key_der_384;
29873- #else
29874- file = XFOPEN(eccCaKey384File, "rb");
29875- if (!file) {
29876- ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
29877- }
29896+ #ifdef USE_CERT_BUFFERS_256
29897+ XMEMCPY(der, ca_ecc_key_der_384, sizeof_ca_ecc_key_der_384);
29898+ bytes = sizeof_ca_ecc_key_der_384;
29899+ #elif !defined(NO_FILESYSTEM)
29900+ file = XFOPEN(eccCaKey384File, "rb");
29901+ if (!file) {
29902+ ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
29903+ }
2987829904
29879- bytes = XFREAD(der, 1, FOURK_BUF, file);
29880- XFCLOSE(file);
29881- if (bytes == 0)
29882- ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
29883- (void)eccCaKeyFile;
29884- #endif /* USE_CERT_BUFFERS_256 */
29885- #else
29886- #ifdef USE_CERT_BUFFERS_256
29887- XMEMCPY(der, ca_ecc_key_der_256, sizeof_ca_ecc_key_der_256);
29888- bytes = sizeof_ca_ecc_key_der_256;
29905+ bytes = XFREAD(der, 1, FOURK_BUF, file);
29906+ XFCLOSE(file);
29907+ if (bytes == 0)
29908+ ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
29909+ (void)eccCaKeyFile;
29910+ #else
29911+ WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(4)");
29912+ ERROR_OUT(ASN_PARSE_E, exit);
29913+ #endif /* USE_CERT_BUFFERS_256 */
29914+
29915+ /* end if ENABLE_ECC384_CERT_GEN_TEST */
2988929916#else
29890- file = XFOPEN(eccCaKeyFile, "rb");
29891- if (!file) {
29892- ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
29893- }
29894- bytes = XFREAD(der, 1, FOURK_BUF, file);
29895- XFCLOSE(file);
29896- if (bytes == 0)
29897- ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
29898- #ifdef ENABLE_ECC384_CERT_GEN_TEST
29899- (void)eccCaKey384File;
29900- #endif
29901- #endif /* USE_CERT_BUFFERS_256 */
29917+ /* !ENABLE_ECC384_CERT_GEN_TEST */
29918+
29919+ #ifdef USE_CERT_BUFFERS_256
29920+ XMEMCPY(der, ca_ecc_key_der_256, sizeof_ca_ecc_key_der_256);
29921+ bytes = sizeof_ca_ecc_key_der_256;
29922+ #else
29923+ file = XFOPEN(eccCaKeyFile, "rb");
29924+ if (!file) {
29925+ ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
29926+ }
29927+ bytes = XFREAD(der, 1, FOURK_BUF, file);
29928+ XFCLOSE(file);
29929+ if (bytes == 0)
29930+ ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
29931+
29932+ #ifdef ENABLE_ECC384_CERT_GEN_TEST
29933+ (void)eccCaKey384File;
29934+ #endif
29935+ #endif /* USE_CERT_BUFFERS_256 */
2990229936#endif /* ENABLE_ECC384_CERT_GEN_TEST */
2990329937
2990429938 /* Get CA Key */
@@ -29959,23 +29993,28 @@ static wc_test_ret_t ecc_test_cert_gen(WC_RNG* rng)
2995929993#endif /* WOLFSSL_CERT_EXT */
2996029994
2996129995#ifdef ENABLE_ECC384_CERT_GEN_TEST
29962- #if defined(USE_CERT_BUFFERS_256)
29963- ret = wc_SetIssuerBuffer(myCert, ca_ecc_cert_der_384,
29964- sizeof_ca_ecc_cert_der_384);
29965- #else
29966- ret = wc_SetIssuer(myCert, eccCaCert384File);
29967- (void)eccCaCertFile;
29968- #endif
29969- #else
29970- #if defined(USE_CERT_BUFFERS_256)
29971- ret = wc_SetIssuerBuffer(myCert, ca_ecc_cert_der_256,
29972- sizeof_ca_ecc_cert_der_256);
29996+ #if defined(USE_CERT_BUFFERS_256)
29997+ ret = wc_SetIssuerBuffer(myCert, ca_ecc_cert_der_384,
29998+ sizeof_ca_ecc_cert_der_384);
29999+ #elif !defined(NO_FILESYSTEM)
30000+ ret = wc_SetIssuer(myCert, eccCaCert384File);
30001+ (void)eccCaCertFile;
30002+ #else
30003+ /* not testing with embedded, no file system target */
30004+ ERROR_OUT(ASN_PARSE_E, exit);
30005+ #endif /* USE_CERT_BUFFERS_256 */
30006+
2997330007#else
29974- ret = wc_SetIssuer(myCert, eccCaCertFile);
29975- #ifdef ENABLE_ECC384_CERT_GEN_TEST
29976- (void)eccCaCert384File;
30008+ /* not ENABLE_ECC384_CERT_GEN_TEST */
30009+ #if defined(USE_CERT_BUFFERS_256)
30010+ ret = wc_SetIssuerBuffer(myCert, ca_ecc_cert_der_256,
30011+ sizeof_ca_ecc_cert_der_256);
30012+ #else
30013+ ret = wc_SetIssuer(myCert, eccCaCertFile);
30014+ #ifdef ENABLE_ECC384_CERT_GEN_TEST
30015+ (void)eccCaCert384File;
30016+ #endif
2997730017 #endif
29978- #endif
2997930018#endif /* ENABLE_ECC384_CERT_GEN_TEST */
2998030019 if (ret < 0)
2998130020 ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
0 commit comments