6565#include <tests/utils.h>
6666#include <testsuite/utils.h>
6767
68+ #ifdef WOLFSSL_SWDEV
69+ #include "swdev/swdev_loader.h"
70+ #endif
71+
6872/* for testing compatibility layer callbacks */
6973#include "examples/server/server.h"
7074
@@ -6367,7 +6371,10 @@ static void test_client_reuse_WOLFSSLobj(void* args, cbType cb,
63676371/* Generic TLS client / server with callbacks for API unit tests
63686372 * Used by SNI / ALPN / crypto callback helper functions */
63696373#if defined(HAVE_IO_TESTS_DEPENDENCIES) && \
6370- (defined(HAVE_SNI) || defined(HAVE_ALPN) || defined(WOLF_CRYPTO_CB) || \
6374+ (defined(HAVE_SNI) || defined(HAVE_ALPN) || \
6375+ (defined(WOLF_CRYPTO_CB) && \
6376+ !defined(WOLF_CRYPTO_CB_ONLY_RSA) && !defined(WOLF_CRYPTO_CB_ONLY_ECC) && \
6377+ !defined(WOLF_CRYPTO_CB_ONLY_SHA256) && !defined(WOLF_CRYPTO_CB_ONLY_AES)) || \
63716378 defined(HAVE_ALPN_PROTOS_SUPPORT)) || defined(WOLFSSL_STATIC_MEMORY)
63726379 #define ENABLE_TLS_CALLBACK_TEST
63736380#endif
@@ -30606,7 +30613,9 @@ static int test_SSL_CIPHER_get_xxx(void)
3060630613 return EXPECT_RESULT();
3060730614}
3060830615
30609- #if defined(WOLF_CRYPTO_CB) && defined(HAVE_IO_TESTS_DEPENDENCIES)
30616+ #if defined(WOLF_CRYPTO_CB) && defined(HAVE_IO_TESTS_DEPENDENCIES) && \
30617+ (!defined(WOLF_CRYPTO_CB_ONLY_SHA256) && !defined(WOLF_CRYPTO_CB_ONLY_AES) && \
30618+ !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(WOLF_CRYPTO_CB_ONLY_RSA))
3061030619
3061130620static int load_pem_key_file_as_der(const char* privKeyFile, DerBuffer** pDer,
3061230621 int* keyFormat)
@@ -31608,7 +31617,9 @@ static int test_wc_CryptoCb_TLS(int tlsVer,
3160831617static int test_wc_CryptoCb(void)
3160931618{
3161031619 EXPECT_DECLS;
31611- #ifdef WOLF_CRYPTO_CB
31620+ #if defined(WOLF_CRYPTO_CB) && \
31621+ (!defined(WOLF_CRYPTO_CB_ONLY_SHA256) && !defined(WOLF_CRYPTO_CB_ONLY_AES) && \
31622+ !defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(WOLF_CRYPTO_CB_ONLY_RSA))
3161231623 /* TODO: Add crypto callback API tests */
3161331624
3161431625#ifdef HAVE_IO_TESTS_DEPENDENCIES
@@ -39851,7 +39862,7 @@ static int test_pkcs7_padding(void)
3985139862
3985239863 /* Encode EncryptedData */
3985339864 XMEMSET(&pkcs7, 0, sizeof(pkcs7));
39854- ExpectIntEQ(wc_PKCS7_Init(&pkcs7, NULL, 0 ), 0);
39865+ ExpectIntEQ(wc_PKCS7_Init(&pkcs7, NULL, INVALID_DEVID ), 0);
3985539866 pkcs7.content = plaintext;
3985639867 pkcs7.contentSz = sizeof(plaintext);
3985739868 pkcs7.contentOID = DATA;
@@ -39880,7 +39891,7 @@ static int test_pkcs7_padding(void)
3988039891
3988139892 /* Decrypt modified ciphertext - must fail, not succeed */
3988239893 XMEMSET(&pkcs7, 0, sizeof(pkcs7));
39883- ExpectIntEQ(wc_PKCS7_Init(&pkcs7, NULL, 0 ), 0);
39894+ ExpectIntEQ(wc_PKCS7_Init(&pkcs7, NULL, INVALID_DEVID ), 0);
3988439895 pkcs7.encryptionKey = key;
3988539896 pkcs7.encryptionKeySz = sizeof(key);
3988639897
@@ -40791,7 +40802,11 @@ TEST_CASE testCases[] = {
4079140802
4079240803static void TestSetup(void)
4079340804{
40794- /* Stub, for now. Add common test setup code here. */
40805+ #ifdef WOLFSSL_SWDEV
40806+ /* Re-arm the swdev cryptocb registration in case the previous test
40807+ * tore down wolfCrypt and wiped gCryptoDev. */
40808+ (void)wc_SwDev_Init();
40809+ #endif
4079540810}
4079640811
4079740812static void TestCleanup(void)
@@ -40800,6 +40815,9 @@ static void TestCleanup(void)
4080040815 /* Clear any errors added to the error queue during the test run. */
4080140816 wolfSSL_ERR_clear_error();
4080240817#endif /* OPENSSL_EXTRA || DEBUG_WOLFSSL_VERBOSE */
40818+ #ifdef WOLFSSL_SWDEV
40819+ wc_SwDev_Cleanup();
40820+ #endif
4080340821}
4080440822
4080540823void ApiTest_StopOnFail(void)
@@ -41013,20 +41031,24 @@ int ApiTest(void)
4101341031 printf(" Begin API Tests\n");
4101441032 fflush(stdout);
4101541033
41016- /* we must perform init and cleanup if not all tests are running */
41017- if (!testAll) {
41018- #ifdef WOLFCRYPT_ONLY
41019- if (wolfCrypt_Init() != 0) {
41020- printf("wolfCrypt Initialization failed\n");
41021- res = 1;
41022- }
41023- #else
41024- if (wolfSSL_Init() != WOLFSSL_SUCCESS) {
41025- printf("wolfSSL Initialization failed\n");
41026- res = 1;
41027- }
41028- #endif
41034+ #ifdef WOLFCRYPT_ONLY
41035+ if (wolfCrypt_Init() != 0) {
41036+ printf("wolfCrypt Initialization failed\n");
41037+ res = 1;
41038+ }
41039+ #else
41040+ if (wolfSSL_Init() != WOLFSSL_SUCCESS) {
41041+ printf("wolfSSL Initialization failed\n");
41042+ res = 1;
4102941043 }
41044+ #endif
41045+
41046+ #ifdef WOLFSSL_SWDEV
41047+ if (res == 0 && wc_SwDev_Init() != 0) {
41048+ printf("wc_SwDev_Init failed\n");
41049+ res = 1;
41050+ }
41051+ #endif
4103041052
4103141053 #ifdef WOLFSSL_DUMP_MEMIO_STREAM
4103241054 if (res == 0) {
@@ -41118,13 +41140,15 @@ int ApiTest(void)
4111841140 wc_ecc_fp_free(); /* free per thread cache */
4111941141#endif
4112041142
41121- if (!testAll) {
41122- #ifdef WOLFCRYPT_ONLY
41123- wolfCrypt_Cleanup();
41124- #else
41125- wolfSSL_Cleanup();
41126- #endif
41127- }
41143+ #ifdef WOLFSSL_SWDEV
41144+ wc_SwDev_Cleanup();
41145+ #endif
41146+
41147+ #ifdef WOLFCRYPT_ONLY
41148+ wolfCrypt_Cleanup();
41149+ #else
41150+ wolfSSL_Cleanup();
41151+ #endif
4112841152
4112941153 (void)testDevId;
4113041154
0 commit comments