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 *
@@ -18776,7 +18776,9 @@ static wc_test_ret_t rsa_ecc_certgen_test(WC_RNG* rng, byte* tmp)
1877618776 word32 idx3 = 0;
1877718777#if (!defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048)) \
1877818778 || !defined(USE_CERT_BUFFERS_256)
18779- XFILE file3;
18779+ #ifndef NO_FILESYSTEM
18780+ XFILE file3;
18781+ #endif
1878018782#endif
1878118783 wc_test_ret_t ret;
1878218784
@@ -18829,20 +18831,29 @@ static wc_test_ret_t rsa_ecc_certgen_test(WC_RNG* rng, byte* tmp)
1882918831 ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit_rsa);
1883018832
1883118833 /* Get Cert Key */
18832- #ifdef USE_CERT_BUFFERS_256
18833- XMEMCPY(tmp, ecc_key_pub_der_256, sizeof_ecc_key_pub_der_256);
18834- bytes3 = sizeof_ecc_key_pub_der_256;
18835- #else
18836- file3 = XFOPEN(eccKeyPubFileDer, "rb");
18837- if (!file3) {
18838- ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
18834+ #if defined(USE_CERT_BUFFERS_256)
18835+ {
18836+ XMEMCPY(tmp, ecc_key_pub_der_256, sizeof_ecc_key_pub_der_256);
18837+ bytes3 = sizeof_ecc_key_pub_der_256;
1883918838 }
18839+ #elif !defined(NO_FILESYSTEM)
18840+ {
18841+ file3 = XFOPEN(eccKeyPubFileDer, "rb");
18842+ if (!file3) {
18843+ ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
18844+ }
1884018845
18841- bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3);
18842- XFCLOSE(file3);
18843- if (bytes3 == 0)
18844- ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
18845- #endif
18846+ bytes3 = XFREAD(tmp, 1, FOURK_BUF, file3);
18847+ XFCLOSE(file3);
18848+ if (bytes3 == 0)
18849+ ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit_rsa);
18850+ }
18851+ #else
18852+ {
18853+ WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(1)");
18854+ ERROR_OUT(ASN_PARSE_E, exit_rsa);
18855+ }
18856+ #endif
1884618857
1884718858 ret = wc_ecc_init_ex(caEccKeyPub, HEAP_HINT, devId);
1884818859 if (ret != 0)
@@ -27422,10 +27433,12 @@ static wc_test_ret_t ecc_test_make_pub(WC_RNG* rng)
2742227433 wc_ecc_init_ex(key, HEAP_HINT, devId);
2742327434
2742427435#ifndef NO_ECC256
27425- #ifdef USE_CERT_BUFFERS_256
27426- XMEMCPY(tmp, ecc_key_der_256, (size_t)sizeof_ecc_key_der_256);
27427- tmpSz = (size_t)sizeof_ecc_key_der_256;
27428- #else
27436+ #if defined(USE_CERT_BUFFERS_256)
27437+ {
27438+ XMEMCPY(tmp, ecc_key_der_256, (size_t)sizeof_ecc_key_der_256);
27439+ tmpSz = (size_t)sizeof_ecc_key_der_256;
27440+ }
27441+ #elif !defined(NO_FILESYSTEM)
2742927442 {
2743027443 XFILE file = XFOPEN(eccKeyDerFile, "rb");
2743127444 if (!file) {
@@ -27437,6 +27450,11 @@ static wc_test_ret_t ecc_test_make_pub(WC_RNG* rng)
2743727450 if (tmpSz == 0)
2743827451 ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
2743927452 }
27453+ #else
27454+ {
27455+ WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(2)");
27456+ ERROR_OUT(ASN_PARSE_E, done);
27457+ }
2744027458#endif /* USE_CERT_BUFFERS_256 */
2744127459
2744227460 /* import private only then test with */
@@ -28968,10 +28986,12 @@ static wc_test_ret_t ecc_def_curve_test(WC_RNG *rng)
2896828986 ((defined(HAVE_ECC_KEY_IMPORT) && defined(HAVE_ECC_KEY_EXPORT)) || \
2896928987 (defined(HAVE_ECC_KEY_IMPORT) && !defined(WOLFSSL_VALIDATE_ECC_IMPORT)))
2897028988 /* Use test ECC key - ensure real private "d" exists */
28971- #ifdef USE_CERT_BUFFERS_256
28972- ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &idx, key,
28973- sizeof_ecc_key_der_256);
28974- #else
28989+ #if defined(USE_CERT_BUFFERS_256)
28990+ {
28991+ ret = wc_EccPrivateKeyDecode(ecc_key_der_256, &idx, key,
28992+ sizeof_ecc_key_der_256);
28993+ }
28994+ #elif !defined(NO_FILESYSTEM)
2897528995 {
2897628996 XFILE file = XFOPEN(eccKeyDerFile, "rb");
2897728997 byte der[128];
@@ -28985,6 +29005,12 @@ static wc_test_ret_t ecc_def_curve_test(WC_RNG *rng)
2898529005 ERROR_OUT(WC_TEST_RET_ENC_ERRNO, done);
2898629006 ret = wc_EccPrivateKeyDecode(der, &idx, key, derSz);
2898729007 }
29008+ #else
29009+ {
29010+ (void)idx;
29011+ WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(3)");
29012+ ERROR_OUT(ASN_PARSE_E, done);
29013+ }
2898829014 #endif
2898929015 if (ret != 0) {
2899029016 goto done;
@@ -29913,9 +29939,9 @@ static wc_test_ret_t ecc_test_cert_gen(WC_RNG* rng)
2991329939 ecc_key certPubKey[1];
2991429940#endif
2991529941 int certSz;
29916- size_t bytes;
29942+ size_t bytes = 0 ;
2991729943 word32 idx = 0;
29918- #ifndef USE_CERT_BUFFERS_256
29944+ #if !defined( USE_CERT_BUFFERS_256) && !defined(NO_FILESYSTEM)
2991929945 XFILE file;
2992029946#endif
2992129947#if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC)
@@ -29946,38 +29972,46 @@ static wc_test_ret_t ecc_test_cert_gen(WC_RNG* rng)
2994629972 /* Get cert private key */
2994729973#ifdef ENABLE_ECC384_CERT_GEN_TEST
2994829974 /* Get Cert Key 384 */
29949- #ifdef USE_CERT_BUFFERS_256
29950- XMEMCPY(der, ca_ecc_key_der_384, sizeof_ca_ecc_key_der_384);
29951- bytes = sizeof_ca_ecc_key_der_384;
29952- #else
29953- file = XFOPEN(eccCaKey384File, "rb");
29954- if (!file) {
29955- ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
29956- }
29975+ #ifdef USE_CERT_BUFFERS_256
29976+ XMEMCPY(der, ca_ecc_key_der_384, sizeof_ca_ecc_key_der_384);
29977+ bytes = sizeof_ca_ecc_key_der_384;
29978+ #elif !defined(NO_FILESYSTEM)
29979+ file = XFOPEN(eccCaKey384File, "rb");
29980+ if (!file) {
29981+ ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
29982+ }
2995729983
29958- bytes = XFREAD(der, 1, FOURK_BUF, file);
29959- XFCLOSE(file);
29960- if (bytes == 0)
29961- ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
29962- (void)eccCaKeyFile;
29963- #endif /* USE_CERT_BUFFERS_256 */
29964- #else
29965- #ifdef USE_CERT_BUFFERS_256
29966- XMEMCPY(der, ca_ecc_key_der_256, sizeof_ca_ecc_key_der_256);
29967- bytes = sizeof_ca_ecc_key_der_256;
29984+ bytes = XFREAD(der, 1, FOURK_BUF, file);
29985+ XFCLOSE(file);
29986+ if (bytes == 0)
29987+ ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
29988+ (void)eccCaKeyFile;
29989+ #else
29990+ WOLFSSL_MSG("No file system and USE_CERT_BUFFERS_256 not defined.(4)");
29991+ ERROR_OUT(ASN_PARSE_E, exit);
29992+ #endif /* USE_CERT_BUFFERS_256 */
29993+
29994+ /* end if ENABLE_ECC384_CERT_GEN_TEST */
2996829995#else
29969- file = XFOPEN(eccCaKeyFile, "rb");
29970- if (!file) {
29971- ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
29972- }
29973- bytes = XFREAD(der, 1, FOURK_BUF, file);
29974- XFCLOSE(file);
29975- if (bytes == 0)
29976- ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
29977- #ifdef ENABLE_ECC384_CERT_GEN_TEST
29978- (void)eccCaKey384File;
29979- #endif
29980- #endif /* USE_CERT_BUFFERS_256 */
29996+ /* !ENABLE_ECC384_CERT_GEN_TEST */
29997+
29998+ #ifdef USE_CERT_BUFFERS_256
29999+ XMEMCPY(der, ca_ecc_key_der_256, sizeof_ca_ecc_key_der_256);
30000+ bytes = sizeof_ca_ecc_key_der_256;
30001+ #else
30002+ file = XFOPEN(eccCaKeyFile, "rb");
30003+ if (!file) {
30004+ ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
30005+ }
30006+ bytes = XFREAD(der, 1, FOURK_BUF, file);
30007+ XFCLOSE(file);
30008+ if (bytes == 0)
30009+ ERROR_OUT(WC_TEST_RET_ENC_ERRNO, exit);
30010+
30011+ #ifdef ENABLE_ECC384_CERT_GEN_TEST
30012+ (void)eccCaKey384File;
30013+ #endif
30014+ #endif /* USE_CERT_BUFFERS_256 */
2998130015#endif /* ENABLE_ECC384_CERT_GEN_TEST */
2998230016
2998330017 /* Get CA Key */
@@ -30038,23 +30072,28 @@ static wc_test_ret_t ecc_test_cert_gen(WC_RNG* rng)
3003830072#endif /* WOLFSSL_CERT_EXT */
3003930073
3004030074#ifdef ENABLE_ECC384_CERT_GEN_TEST
30041- #if defined(USE_CERT_BUFFERS_256)
30042- ret = wc_SetIssuerBuffer(myCert, ca_ecc_cert_der_384,
30043- sizeof_ca_ecc_cert_der_384);
30044- #else
30045- ret = wc_SetIssuer(myCert, eccCaCert384File);
30046- (void)eccCaCertFile;
30047- #endif
30048- #else
30049- #if defined(USE_CERT_BUFFERS_256)
30050- ret = wc_SetIssuerBuffer(myCert, ca_ecc_cert_der_256,
30051- sizeof_ca_ecc_cert_der_256);
30075+ #if defined(USE_CERT_BUFFERS_256)
30076+ ret = wc_SetIssuerBuffer(myCert, ca_ecc_cert_der_384,
30077+ sizeof_ca_ecc_cert_der_384);
30078+ #elif !defined(NO_FILESYSTEM)
30079+ ret = wc_SetIssuer(myCert, eccCaCert384File);
30080+ (void)eccCaCertFile;
30081+ #else
30082+ /* not testing with embedded, no file system target */
30083+ ERROR_OUT(ASN_PARSE_E, exit);
30084+ #endif /* USE_CERT_BUFFERS_256 */
30085+
3005230086#else
30053- ret = wc_SetIssuer(myCert, eccCaCertFile);
30054- #ifdef ENABLE_ECC384_CERT_GEN_TEST
30055- (void)eccCaCert384File;
30087+ /* not ENABLE_ECC384_CERT_GEN_TEST */
30088+ #if defined(USE_CERT_BUFFERS_256)
30089+ ret = wc_SetIssuerBuffer(myCert, ca_ecc_cert_der_256,
30090+ sizeof_ca_ecc_cert_der_256);
30091+ #else
30092+ ret = wc_SetIssuer(myCert, eccCaCertFile);
30093+ #ifdef ENABLE_ECC384_CERT_GEN_TEST
30094+ (void)eccCaCert384File;
30095+ #endif
3005630096 #endif
30057- #endif
3005830097#endif /* ENABLE_ECC384_CERT_GEN_TEST */
3005930098 if (ret < 0)
3006030099 ERROR_OUT(WC_TEST_RET_ENC_EC(ret), exit);
0 commit comments