Skip to content

Commit 63fe12e

Browse files
committed
wolfcrypt/src/aes.c: fix WOLFSSL_AESGCM_STREAM && WC_AES_C_DYNAMIC_FALLBACK: establish AESNI status dynamically at time of wc_AesGcmSetKey(), and stick to it (or return failure) until the next wc_AesGcmSetKey(). this matches the semantics of the Linux kernel in-tree implementation, allowing safe registration of the wolfCrypt AESNI implementation with the LKCAPI.
configure.ac: move enable_aesgcm_stream=yes clauses in enable-all and enable-all-crypto to the main section, from the !ENABLED_LINUXKM_DEFAULTS section, and in ENABLED_LINUXKM_LKCAPI_REGISTER setup, remove the !ENABLED_AESNI from the condition for forcing on ENABLED_AESGCM_STREAM. linuxkm/lkcapi_glue.c: * remove all special-casing for AES-GCM with AESNI. * add support for a LINUXKM_LKCAPI_PRIORITY_ALLOW_MASKING macro. wolfssl/wolfcrypt/memory.h: add missing definition of SAVE_VECTOR_REGISTERS2() when DEBUG_VECTOR_REGISTER_ACCESS_FUZZING && !DEBUG_VECTOR_REGISTER_ACCESS. wolfcrypt/src/memory.c: * define SAVE_VECTOR_REGISTERS2_fuzzer() if DEBUG_VECTOR_REGISTER_ACCESS_FUZZING, regardless of DEBUG_VECTOR_REGISTER_ACCESS. * add a DEBUG_VECTOR_REGISTER_ACCESS clause to the !HAVE_THREAD_LS version of SAVE_VECTOR_REGISTERS2_fuzzer(). wolfcrypt/test/test.c: remove several errant wc_AesFree()s in aes256_test().
1 parent 6146485 commit 63fe12e

6 files changed

Lines changed: 101 additions & 99 deletions

File tree

configure.ac

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,7 @@ then
720720
# this set is also enabled by enable-all-crypto:
721721
test "$enable_atomicuser" = "" && enable_atomicuser=yes
722722
test "$enable_aesgcm" = "" && enable_aesgcm=yes
723+
test "$enable_aesgcm_stream" = "" && test "$enable_aesgcm" = "yes" && enable_aesgcm_stream=yes
723724
test "$enable_aesccm" = "" && enable_aesccm=yes
724725
test "$enable_aesctr" = "" && enable_aesctr=yes
725726
test "$enable_aeseax" = "" && enable_aeseax=yes
@@ -796,7 +797,6 @@ then
796797

797798
if test "$ENABLED_LINUXKM_DEFAULTS" != "yes"
798799
then
799-
test "$enable_aesgcm_stream" = "" && test "$enable_aesgcm" = "yes" && enable_aesgcm_stream=yes
800800
test "$enable_compkey" = "" && enable_compkey=yes
801801
test "$enable_quic" = "" && test "$enable_cryptonly" != "yes" && enable_quic=yes
802802
AM_CFLAGS="$AM_CFLAGS -DHAVE_CRL_IO -DHAVE_IO_TIMEOUT"
@@ -909,6 +909,7 @@ if test "$ENABLED_ALL_CRYPT" = "yes"
909909
then
910910
test "$enable_atomicuser" = "" && enable_atomicuser=yes
911911
test "$enable_aesgcm" = "" && enable_aesgcm=yes
912+
test "$enable_aesgcm_stream" = "" && test "$enable_aesgcm" = "yes" && enable_aesgcm_stream=yes
912913
test "$enable_aesccm" = "" && enable_aesccm=yes
913914
test "$enable_aesctr" = "" && enable_aesctr=yes
914915
test "$enable_aeseax" = "" && enable_aeseax=yes
@@ -969,7 +970,6 @@ then
969970

970971
if test "$ENABLED_LINUXKM_DEFAULTS" != "yes"
971972
then
972-
test "$enable_aesgcm_stream" = "" && test "$enable_aesgcm" = "yes" && enable_aesgcm_stream=yes
973973
test "$enable_compkey" = "" && enable_compkey=yes
974974
fi
975975

@@ -8050,7 +8050,7 @@ if test "$ENABLED_LINUXKM_LKCAPI_REGISTER" != "none"
80508050
then
80518051
AM_CFLAGS="$AM_CFLAGS -DLINUXKM_LKCAPI_REGISTER"
80528052

8053-
if test "$ENABLED_AESGCM" != "no" && test "$ENABLED_AESGCM_STREAM" = "no" && test "$ENABLED_AESNI" = "no" && test "$ENABLED_ARMASM" = "no" && test "$ENABLED_FIPS" = "no"; then
8053+
if test "$ENABLED_AESGCM" != "no" && test "$ENABLED_AESGCM_STREAM" = "no" && test "$ENABLED_ARMASM" = "no" && test "$ENABLED_FIPS" = "no"; then
80548054
ENABLED_AESGCM_STREAM=yes
80558055
fi
80568056

linuxkm/lkcapi_glue.c

Lines changed: 58 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@
2424
#error lkcapi_glue.c included in non-LINUXKM_LKCAPI_REGISTER project.
2525
#endif
2626

27-
#if defined(LINUXKM_LKCAPI_REGISTER_AESGCM) && defined(WOLFSSL_AESNI) && \
28-
defined(WC_AES_C_DYNAMIC_FALLBACK)
29-
/* xxx temporary */
30-
#error LINUXKM_LKCAPI_REGISTER_AESGCM is incompatible with WOLFSSL_AESNI && WC_AES_C_DYNAMIC_FALLBACK
31-
#endif
32-
3327
#ifndef WOLFSSL_LINUXKM_LKCAPI_PRIORITY
3428
/* Larger number means higher priority. The highest in-tree priority is 4001,
3529
* in the Cavium driver.
@@ -88,8 +82,7 @@ static int linuxkm_test_aescfb(void);
8882
#endif
8983
#if defined(HAVE_AESGCM) && \
9084
(defined(LINUXKM_LKCAPI_REGISTER_ALL) || \
91-
defined(LINUXKM_LKCAPI_REGISTER_AESGCM)) && \
92-
(! (defined(WOLFSSL_AESNI) && defined(WC_AES_C_DYNAMIC_FALLBACK)))
85+
defined(LINUXKM_LKCAPI_REGISTER_AESGCM))
9386
static int linuxkm_test_aesgcm(void);
9487
#endif
9588
#if defined(WOLFSSL_AES_XTS) && \
@@ -503,8 +496,7 @@ static int cfbAesAlg_loaded = 0;
503496

504497
#if defined(HAVE_AESGCM) && \
505498
(defined(LINUXKM_LKCAPI_REGISTER_ALL) || \
506-
defined(LINUXKM_LKCAPI_REGISTER_AESGCM)) && \
507-
(! (defined(WOLFSSL_AESNI) && defined(WC_AES_C_DYNAMIC_FALLBACK)))
499+
defined(LINUXKM_LKCAPI_REGISTER_AESGCM))
508500

509501
#ifndef WOLFSSL_AESGCM_STREAM
510502
#error LKCAPI registration of AES-GCM requires WOLFSSL_AESGCM_STREAM (--enable-aesgcm-stream).
@@ -790,7 +782,6 @@ static int gcmAesAead_loaded = 0;
790782

791783
#endif /* HAVE_AESGCM &&
792784
* (LINUXKM_LKCAPI_REGISTER_ALL || LINUXKM_LKCAPI_REGISTER_AESGCM) &&
793-
* (! (WOLFSSL_AESNI && WC_AES_C_DYNAMIC_FALLBACK))
794785
*/
795786

796787
#if defined(WOLFSSL_AES_XTS) && \
@@ -1009,8 +1000,6 @@ static int linuxkm_test_aescbc(void)
10091000
u8 * enc2 = NULL;
10101001
u8 * dec2 = NULL;
10111002

1012-
const char *driver_name;
1013-
10141003
XMEMSET(enc, 0, sizeof(enc));
10151004
XMEMSET(dec, 0, sizeof(enc));
10161005

@@ -1086,13 +1075,18 @@ static int linuxkm_test_aescbc(void)
10861075
goto test_cbc_end;
10871076
}
10881077

1089-
driver_name = crypto_tfm_alg_driver_name(crypto_skcipher_tfm(tfm));
1090-
if (strcmp(driver_name, WOLFKM_AESCBC_DRIVER)) {
1091-
pr_err("error: unexpected implementation for %s: %s (expected %s)\n",
1092-
WOLFKM_AESCBC_NAME, driver_name, WOLFKM_AESCBC_DRIVER);
1093-
ret = -ENOENT;
1094-
goto test_cbc_end;
1078+
#ifndef LINUXKM_LKCAPI_PRIORITY_ALLOW_MASKING
1079+
{
1080+
const char *driver_name =
1081+
crypto_tfm_alg_driver_name(crypto_skcipher_tfm(tfm));
1082+
if (strcmp(driver_name, WOLFKM_AESCBC_DRIVER)) {
1083+
pr_err("error: unexpected implementation for %s: %s (expected %s)\n",
1084+
WOLFKM_AESCBC_NAME, driver_name, WOLFKM_AESCBC_DRIVER);
1085+
ret = -ENOENT;
1086+
goto test_cbc_end;
1087+
}
10951088
}
1089+
#endif
10961090

10971091
ret = crypto_skcipher_setkey(tfm, key32, AES_BLOCK_SIZE * 2);
10981092
if (ret) {
@@ -1199,7 +1193,6 @@ static int linuxkm_test_aescfb(void)
11991193
byte dec[sizeof(p_vector)];
12001194
u8 * enc2 = NULL;
12011195
u8 * dec2 = NULL;
1202-
const char *driver_name;
12031196

12041197
XMEMSET(enc, 0, sizeof(enc));
12051198
XMEMSET(dec, 0, sizeof(enc));
@@ -1276,13 +1269,18 @@ static int linuxkm_test_aescfb(void)
12761269
goto test_cfb_end;
12771270
}
12781271

1279-
driver_name = crypto_tfm_alg_driver_name(crypto_skcipher_tfm(tfm));
1280-
if (strcmp(driver_name, WOLFKM_AESCFB_DRIVER)) {
1281-
pr_err("error: unexpected implementation for %s: %s (expected %s)\n",
1282-
WOLFKM_AESCFB_NAME, driver_name, WOLFKM_AESCFB_DRIVER);
1283-
ret = -ENOENT;
1284-
goto test_cfb_end;
1272+
#ifndef LINUXKM_LKCAPI_PRIORITY_ALLOW_MASKING
1273+
{
1274+
const char *driver_name =
1275+
crypto_tfm_alg_driver_name(crypto_skcipher_tfm(tfm));
1276+
if (strcmp(driver_name, WOLFKM_AESCFB_DRIVER)) {
1277+
pr_err("error: unexpected implementation for %s: %s (expected %s)\n",
1278+
WOLFKM_AESCFB_NAME, driver_name, WOLFKM_AESCFB_DRIVER);
1279+
ret = -ENOENT;
1280+
goto test_cfb_end;
1281+
}
12851282
}
1283+
#endif
12861284

12871285
ret = crypto_skcipher_setkey(tfm, key32, AES_BLOCK_SIZE * 2);
12881286
if (ret) {
@@ -1352,8 +1350,7 @@ static int linuxkm_test_aescfb(void)
13521350

13531351
#if defined(HAVE_AESGCM) && \
13541352
(defined(LINUXKM_LKCAPI_REGISTER_ALL) || \
1355-
defined(LINUXKM_LKCAPI_REGISTER_AESGCM)) && \
1356-
(! (defined(WOLFSSL_AESNI) && defined(WC_AES_C_DYNAMIC_FALLBACK)))
1353+
defined(LINUXKM_LKCAPI_REGISTER_AESGCM))
13571354

13581355
static int linuxkm_test_aesgcm(void)
13591356
{
@@ -1404,7 +1401,6 @@ static int linuxkm_test_aesgcm(void)
14041401
u8 * iv = NULL;
14051402
size_t encryptLen = sizeof(p_vector);
14061403
size_t decryptLen = sizeof(p_vector) + sizeof(authTag);
1407-
const char *driver_name;
14081404

14091405
/* Init stack variables. */
14101406
XMEMSET(enc, 0, sizeof(p_vector));
@@ -1525,13 +1521,17 @@ static int linuxkm_test_aesgcm(void)
15251521
goto test_gcm_end;
15261522
}
15271523

1528-
driver_name = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
1529-
if (strcmp(driver_name, WOLFKM_AESGCM_DRIVER)) {
1530-
pr_err("error: unexpected implementation for %s: %s (expected %s)\n",
1531-
WOLFKM_AESGCM_NAME, driver_name, WOLFKM_AESGCM_DRIVER);
1532-
ret = -ENOENT;
1533-
goto test_gcm_end;
1524+
#ifndef LINUXKM_LKCAPI_PRIORITY_ALLOW_MASKING
1525+
{
1526+
const char *driver_name = crypto_tfm_alg_driver_name(crypto_aead_tfm(tfm));
1527+
if (strcmp(driver_name, WOLFKM_AESGCM_DRIVER)) {
1528+
pr_err("error: unexpected implementation for %s: %s (expected %s)\n",
1529+
WOLFKM_AESGCM_NAME, driver_name, WOLFKM_AESGCM_DRIVER);
1530+
ret = -ENOENT;
1531+
goto test_gcm_end;
1532+
}
15341533
}
1534+
#endif
15351535

15361536
ret = crypto_aead_setkey(tfm, key32, AES_BLOCK_SIZE * 2);
15371537
if (ret) {
@@ -1628,7 +1628,6 @@ static int linuxkm_test_aesgcm(void)
16281628

16291629
#endif /* HAVE_AESGCM &&
16301630
* (LINUXKM_LKCAPI_REGISTER_ALL || LINUXKM_LKCAPI_REGISTER_AESGCM) &&
1631-
* (! (WOLFSSL_AESNI && WC_AES_C_DYNAMIC_FALLBACK))
16321631
*/
16331632

16341633
#if defined(WOLFSSL_AES_XTS) && \
@@ -1654,7 +1653,6 @@ static int aes_xts_128_test(void)
16541653
struct crypto_skcipher *tfm = NULL;
16551654
struct skcipher_request *req = NULL;
16561655
u8 iv[AES_BLOCK_SIZE];
1657-
const char *driver_name;
16581656

16591657
/* 128 key tests */
16601658
static const unsigned char k1[] = {
@@ -2024,13 +2022,18 @@ static int aes_xts_128_test(void)
20242022
goto test_xts_end;
20252023
}
20262024

2027-
driver_name = crypto_tfm_alg_driver_name(crypto_skcipher_tfm(tfm));
2028-
if (strcmp(driver_name, WOLFKM_AESXTS_DRIVER)) {
2029-
pr_err("error: unexpected implementation for %s: %s (expected %s)\n",
2030-
WOLFKM_AESXTS_NAME, driver_name, WOLFKM_AESXTS_DRIVER);
2031-
ret = -ENOENT;
2032-
goto test_xts_end;
2025+
#ifndef LINUXKM_LKCAPI_PRIORITY_ALLOW_MASKING
2026+
{
2027+
const char *driver_name =
2028+
crypto_tfm_alg_driver_name(crypto_skcipher_tfm(tfm));
2029+
if (strcmp(driver_name, WOLFKM_AESXTS_DRIVER)) {
2030+
pr_err("error: unexpected implementation for %s: %s (expected %s)\n",
2031+
WOLFKM_AESXTS_NAME, driver_name, WOLFKM_AESXTS_DRIVER);
2032+
ret = -ENOENT;
2033+
goto test_xts_end;
2034+
}
20332035
}
2036+
#endif
20342037

20352038
ret = crypto_skcipher_ivsize(tfm);
20362039
if (ret != sizeof(iv)) {
@@ -2194,7 +2197,6 @@ static int aes_xts_256_test(void)
21942197
struct crypto_skcipher *tfm = NULL;
21952198
struct skcipher_request *req = NULL;
21962199
u8 iv[AES_BLOCK_SIZE];
2197-
const char *driver_name;
21982200

21992201
/* 256 key tests */
22002202
static const unsigned char k1[] = {
@@ -2404,13 +2406,17 @@ static int aes_xts_256_test(void)
24042406
goto test_xts_end;
24052407
}
24062408

2407-
driver_name = crypto_tfm_alg_driver_name(crypto_skcipher_tfm(tfm));
2408-
if (strcmp(driver_name, WOLFKM_AESXTS_DRIVER)) {
2409-
pr_err("error: unexpected implementation for %s: %s (expected %s)\n",
2410-
WOLFKM_AESXTS_NAME, driver_name, WOLFKM_AESXTS_DRIVER);
2411-
ret = -ENOENT;
2412-
goto test_xts_end;
2409+
#ifndef LINUXKM_LKCAPI_PRIORITY_ALLOW_MASKING
2410+
{
2411+
const char *driver_name = crypto_tfm_alg_driver_name(crypto_skcipher_tfm(tfm));
2412+
if (strcmp(driver_name, WOLFKM_AESXTS_DRIVER)) {
2413+
pr_err("error: unexpected implementation for %s: %s (expected %s)\n",
2414+
WOLFKM_AESXTS_NAME, driver_name, WOLFKM_AESXTS_DRIVER);
2415+
ret = -ENOENT;
2416+
goto test_xts_end;
2417+
}
24132418
}
2419+
#endif
24142420

24152421
ret = crypto_skcipher_ivsize(tfm);
24162422
if (ret != sizeof(iv)) {
@@ -2640,8 +2646,7 @@ static int linuxkm_lkcapi_register(void)
26402646

26412647
#if defined(HAVE_AESGCM) && \
26422648
(defined(LINUXKM_LKCAPI_REGISTER_ALL) || \
2643-
defined(LINUXKM_LKCAPI_REGISTER_AESGCM)) && \
2644-
(! (defined(WOLFSSL_AESNI) && defined(WC_AES_C_DYNAMIC_FALLBACK)))
2649+
defined(LINUXKM_LKCAPI_REGISTER_AESGCM))
26452650

26462651
REGISTER_ALG(gcmAesAead, crypto_register_aead, linuxkm_test_aesgcm);
26472652
#endif
@@ -2681,8 +2686,7 @@ static void linuxkm_lkcapi_unregister(void)
26812686
#endif
26822687
#if defined(HAVE_AESGCM) && \
26832688
(defined(LINUXKM_LKCAPI_REGISTER_ALL) || \
2684-
defined(LINUXKM_LKCAPI_REGISTER_AESGCM)) && \
2685-
(! (defined(WOLFSSL_AESNI) && defined(WC_AES_C_DYNAMIC_FALLBACK)))
2689+
defined(LINUXKM_LKCAPI_REGISTER_AESGCM))
26862690

26872691
UNREGISTER_ALG(gcmAesAead, crypto_unregister_aead);
26882692
#endif

0 commit comments

Comments
 (0)