Skip to content

Commit 460a871

Browse files
authored
Merge pull request #10351 from rizlik/cryptocbonly
CRYPTOCB_ONLY: add test infra + SHA256 + AES
2 parents d0073d9 + cbaf9c1 commit 460a871

32 files changed

Lines changed: 1818 additions & 105 deletions
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: cryptocb-only Tests
2+
3+
# START OF COMMON SECTION
4+
on:
5+
push:
6+
branches: [ 'master', 'main', 'release/**' ]
7+
pull_request:
8+
branches: [ '*' ]
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
# END OF COMMON SECTION
14+
15+
jobs:
16+
make_check:
17+
strategy:
18+
fail-fast: false
19+
matrix:
20+
include:
21+
# WOLF_CRYPTO_CB_ONLY_ECC: strips software ECC; swdev provides the
22+
# software path via cryptocb. FP_ECC / ECCSI / SAKKE / deterministic-k
23+
# test / OPENSSL_EXTRA compat layer all reference stripped primitives
24+
# directly, so they stay off.
25+
- name: ECC
26+
cppflags: -DWOLF_CRYPTO_CB_ONLY_ECC
27+
# WOLF_CRYPTO_CB_ONLY_RSA: strips software RSA; swdev provides the
28+
# software path via cryptocb.
29+
- name: RSA
30+
cppflags: -DWOLF_CRYPTO_CB_ONLY_RSA
31+
# WOLF_CRYPTO_CB_ONLY_SHA256: strips software SHA-256; swdev provides
32+
# the software path via cryptocb. SHA-224 not yet supported.
33+
- name: SHA256
34+
extra_config: --disable-sha224
35+
cppflags: -DWOLF_CRYPTO_CB_ONLY_SHA256
36+
# WOLF_CRYPTO_CB_ONLY_AES: strips software AES; swdev provides the
37+
# software path via cryptocb.
38+
- name: AES
39+
cppflags: -DWOLF_CRYPTO_CB_ONLY_AES
40+
# Same as AES but tells swdev to refuse AES-GCM (SWDEV_AES_ONLYECB).
41+
# That forces the parent's CB_ONLY_AES host-side GCM software path:
42+
# GHASH runs on the host while AES-CTR blocks dispatch back through
43+
# cryptocb ECB. The AES entry above instead has swdev handle GCM
44+
# end-to-end, so the host-side GCM path is otherwise uncovered.
45+
- name: AES_GCM_via_ECB
46+
cppflags: -DWOLF_CRYPTO_CB_ONLY_AES -DSWDEV_AES_ONLYECB
47+
# All four ONLY_* macros at once: every supported software primitive
48+
# is stripped and dispatched through cryptocb. Catches any cross-
49+
# algorithm call that a single-strip entry would still resolve via
50+
# the remaining software paths.
51+
- name: ALL
52+
extra_config: --disable-sha224
53+
cppflags: >-
54+
-DWOLF_CRYPTO_CB_ONLY_ECC -DWOLF_CRYPTO_CB_ONLY_RSA
55+
-DWOLF_CRYPTO_CB_ONLY_SHA256 -DWOLF_CRYPTO_CB_ONLY_AES
56+
name: make check (${{ matrix.name }})
57+
if: github.repository_owner == 'wolfssl'
58+
runs-on: ubuntu-24.04
59+
timeout-minutes: 10
60+
env:
61+
# Common feature set for every entry.
62+
BASE_CONFIG: >-
63+
--enable-swdev --enable-cryptocb --enable-ecc --enable-rsa --enable-dh
64+
--enable-aesgcm --enable-aesccm --enable-aesctr --enable-aescfb
65+
--enable-aeskeywrap --enable-aessiv --enable-aesofb --enable-aesxts
66+
--enable-camellia --enable-chacha --enable-poly1305
67+
--enable-sha --enable-sha3 --enable-shake128 --enable-shake256
68+
--enable-blake2 --enable-blake2s
69+
--enable-hkdf --enable-hashdrbg --enable-hashflags
70+
--enable-curve25519 --enable-ed25519 --enable-curve448 --enable-ed448
71+
--enable-mlkem --enable-dilithium
72+
--enable-scrypt --enable-pwdbased --enable-pkcs7 --enable-pkcs12
73+
--enable-certgen --enable-certreq --enable-certext
74+
--enable-keygen --enable-asn=all
75+
--enable-cmac --enable-xchacha
76+
--enable-crl --enable-ocsp --enable-ocspstapling --enable-ocspstapling2
77+
--enable-dtls --enable-dtls13 --enable-tls13
78+
steps:
79+
- uses: actions/checkout@v4
80+
name: Checkout wolfSSL
81+
82+
- name: Test wolfSSL
83+
run: |
84+
./autogen.sh
85+
./configure $BASE_CONFIG ${{ matrix.extra_config }} CPPFLAGS="${{ matrix.cppflags }}"
86+
make -j 4
87+
make check
88+
89+
- name: Print errors
90+
if: ${{ failure() }}
91+
run: |
92+
for file in scripts/*.log
93+
do
94+
if [ -f "$file" ]; then
95+
echo "${file}:"
96+
cat "$file"
97+
fi
98+
done

configure.ac

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10666,6 +10666,25 @@ then
1066610666
fi
1066710667
1066810668
10669+
# wc_swdev: software crypto-callback device for testing
10670+
AC_ARG_ENABLE([swdev],
10671+
[AS_HELP_STRING([--enable-swdev],[Build wc_swdev software crypto-callback for tests (default: disabled). Requires --enable-cryptocb])],
10672+
[ ENABLED_SWDEV=$enableval ],
10673+
[ ENABLED_SWDEV=no ]
10674+
)
10675+
10676+
if test "$ENABLED_SWDEV" = "yes"
10677+
then
10678+
if test "$ENABLED_CRYPTOCB" != "yes" && test "$enable_usersettings" != "yes"; then
10679+
AC_MSG_ERROR([--enable-swdev requires --enable-cryptocb (or --enable-usersettings with WOLF_CRYPTO_CB defined in user_settings.h)])
10680+
fi
10681+
if test "x$srcdir" != "x."; then
10682+
AC_MSG_ERROR([--enable-swdev currently supports in-tree builds only])
10683+
fi
10684+
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_SWDEV -DWOLF_CRYPTO_CB_FIND"
10685+
fi
10686+
10687+
1066910688
# Asynchronous Crypto
1067010689
AC_ARG_ENABLE([asynccrypt],
1067110690
[AS_HELP_STRING([--enable-asynccrypt],[Enable Asynchronous Crypto (default: disabled)])],
@@ -11923,9 +11942,14 @@ fi
1192311942
if test "x$ENABLED_USERSETTINGS" = "xyes"
1192411943
then
1192511944
# Replace all options and just use WOLFSSL_USER_SETTINGS and
11926-
# WOLFSSL_USER_SETTINGS_ASM.
11945+
# WOLFSSL_USER_SETTINGS_ASM. Re-append build-system flags that affect
11946+
# preprocessor guards in test files and must survive the reset.
1192711947
AM_CFLAGS="-DWOLFSSL_USER_SETTINGS -DWOLFSSL_USER_SETTINGS_ASM"
1192811948
AM_CCASFLAGS="-DWOLFSSL_USER_SETTINGS -DWOLFSSL_USER_SETTINGS_ASM"
11949+
AS_IF([test "x$ENABLED_SWDEV" = "xyes"],[
11950+
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_SWDEV -DWOLF_CRYPTO_CB_FIND"
11951+
AM_CCASFLAGS="$AM_CCASFLAGS -DWOLFSSL_SWDEV -DWOLF_CRYPTO_CB_FIND"
11952+
])
1192911953
1193011954
# Generate assembly-safe user_settings_asm.h (just preprocessor directives
1193111955
# from user_settings.h).
@@ -12286,6 +12310,7 @@ AM_CONDITIONAL([BUILD_MCAPI],[test "x$ENABLED_MCAPI" = "xyes"])
1228612310
AM_CONDITIONAL([BUILD_ASYNCCRYPT],[test "x$ENABLED_ASYNCCRYPT" = "xyes"])
1228712311
AM_CONDITIONAL([BUILD_WOLFEVENT],[test "x$ENABLED_ASYNCCRYPT" = "xyes"])
1228812312
AM_CONDITIONAL([BUILD_CRYPTOCB],[test "x$ENABLED_CRYPTOCB" = "xyes" || test "x$ENABLED_USERSETTINGS" = "xyes"])
12313+
AM_CONDITIONAL([BUILD_SWDEV],[test "x$ENABLED_SWDEV" = "xyes"])
1228912314
AM_CONDITIONAL([BUILD_PSK],[test "x$ENABLED_PSK" = "xyes"])
1229012315
AM_CONDITIONAL([BUILD_TRUST_PEER_CERT],[test "x$ENABLED_TRUSTED_PEER_CERT" = "xyes"])
1229112316
AM_CONDITIONAL([BUILD_PKI],[test "x$ENABLED_PKI" = "xyes"])

examples/client/client.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ static const char *wolfsentry_config_path = NULL;
5151
#include <wolfssl/test.h>
5252
#include <wolfssl/error-ssl.h>
5353

54+
#ifdef WOLFSSL_SWDEV
55+
#include "tests/swdev/swdev_loader.h"
56+
#endif
57+
5458
#ifdef USE_FLAT_TEST_H
5559
#include "client.h"
5660
#else
@@ -5062,6 +5066,12 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
50625066
wolfSSL_Debugging_ON();
50635067
#endif
50645068
wolfSSL_Init();
5069+
#ifdef WOLFSSL_SWDEV
5070+
if (wc_SwDev_Init() != 0) {
5071+
fprintf(stderr, "wc_SwDev_Init failed\n");
5072+
return EXIT_FAILURE;
5073+
}
5074+
#endif
50655075
ChangeToWolfRoot();
50665076

50675077
#if !defined(NO_WOLFSSL_CLIENT) && !defined(NO_TLS)
@@ -5072,6 +5082,9 @@ THREAD_RETURN WOLFSSL_THREAD client_test(void* args)
50725082
#endif
50735083
#else
50745084
fprintf(stderr, "Client not compiled in!\n");
5085+
#endif
5086+
#ifdef WOLFSSL_SWDEV
5087+
wc_SwDev_Cleanup();
50755088
#endif
50765089
wolfSSL_Cleanup();
50775090

examples/client/include.am

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ noinst_HEADERS += examples/client/client.h
77
examples_client_client_SOURCES = examples/client/client.c
88
examples_client_client_LDADD = src/libwolfssl@LIBSUFFIX@.la $(LIB_STATIC_ADD) $(WOLFSENTRY_LIB)
99
examples_client_client_DEPENDENCIES = src/libwolfssl@LIBSUFFIX@.la
10+
if BUILD_SWDEV
11+
examples_client_client_SOURCES += tests/swdev/swdev_loader.c
12+
examples_client_client_LDADD += $(top_builddir)/tests/swdev/build/swdev.o $(LIBM)
13+
examples_client_client_DEPENDENCIES += $(top_builddir)/tests/swdev/build/swdev.o
14+
endif
1015
examples_client_client_CFLAGS = $(WOLFSENTRY_INCLUDE) $(AM_CFLAGS)
1116
endif
1217
EXTRA_DIST += examples/client/client.sln

examples/server/include.am

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ noinst_HEADERS += examples/server/server.h
99
examples_server_server_SOURCES = examples/server/server.c
1010
examples_server_server_LDADD = src/libwolfssl@LIBSUFFIX@.la $(LIB_STATIC_ADD) $(WOLFSENTRY_LIB)
1111
examples_server_server_DEPENDENCIES = src/libwolfssl@LIBSUFFIX@.la
12+
if BUILD_SWDEV
13+
examples_server_server_SOURCES += tests/swdev/swdev_loader.c
14+
examples_server_server_LDADD += $(top_builddir)/tests/swdev/build/swdev.o $(LIBM)
15+
examples_server_server_DEPENDENCIES += $(top_builddir)/tests/swdev/build/swdev.o
16+
endif
1217
examples_server_server_CFLAGS = $(WOLFSENTRY_INCLUDE) $(AM_CFLAGS)
1318
endif
1419
EXTRA_DIST += examples/server/server.sln

examples/server/server.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ static const char *wolfsentry_config_path = NULL;
6767
#include <wolfssl/test.h>
6868
#include <wolfssl/error-ssl.h>
6969

70+
#ifdef WOLFSSL_SWDEV
71+
#include "tests/swdev/swdev_loader.h"
72+
#endif
73+
7074
#ifdef USE_FLAT_TEST_H
7175
#include "server.h"
7276
#else
@@ -4256,6 +4260,12 @@ THREAD_RETURN WOLFSSL_THREAD server_test(void* args)
42564260
wolfSSL_Init();
42574261
#ifdef WC_RNG_SEED_CB
42584262
wc_SetSeed_Cb(WC_GENERATE_SEED_DEFAULT);
4263+
#endif
4264+
#ifdef WOLFSSL_SWDEV
4265+
if (wc_SwDev_Init() != 0) {
4266+
fprintf(stderr, "wc_SwDev_Init failed\n");
4267+
return EXIT_FAILURE;
4268+
}
42594269
#endif
42604270
ChangeToWolfRoot();
42614271

@@ -4269,6 +4279,9 @@ THREAD_RETURN WOLFSSL_THREAD server_test(void* args)
42694279
fprintf(stderr, "Server not compiled in!\n");
42704280
#endif
42714281

4282+
#ifdef WOLFSSL_SWDEV
4283+
wc_SwDev_Cleanup();
4284+
#endif
42724285
wolfSSL_Cleanup();
42734286
FreeTcpReady(&ready);
42744287

tests/api.c

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@
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

3061130620
static 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,
3160831617
static 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

4079240803
static 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

4079740812
static 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

4080540823
void 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

Comments
 (0)