Skip to content

Commit 50f25c5

Browse files
authored
Merge pull request #9254 from douzzer/20250929-WOLFSSL_KERNEL_MODE
20250929-WOLFSSL_KERNEL_MODE
2 parents 1247d2b + 7ea66ae commit 50f25c5

36 files changed

+158
-225
lines changed

.wolfssl_known_macro_extras

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@ WC_DILITHIUM_CACHE_PUB_VECTORS
600600
WC_DILITHIUM_FIXED_ARRAY
601601
WC_DISABLE_RADIX_ZERO_PAD
602602
WC_ECC_NONBLOCK_ONLY
603+
WC_FLAG_DONT_USE_AESNI
603604
WC_KDF_NIST_SP_800_56C
604605
WC_LMS_FULL_HASH
605606
WC_NO_RNG_SIMPLE
@@ -617,7 +618,7 @@ WC_SHA512
617618
WC_SKIP_INCLUDED_C_FILES
618619
WC_SSIZE_TYPE
619620
WC_STRICT_SIG
620-
WC_WANT_FLAG_DONT_USE_AESNI
621+
WC_WANT_FLAG_DONT_USE_VECTOR_OPS
621622
WC_XMSS_FULL_HASH
622623
WIFIESPAT
623624
WIFI_101

linuxkm/linuxkm_wc_port.h

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@
147147
#endif
148148
#define WOLFSSL_LINUXKM_SIMD
149149
#define WOLFSSL_LINUXKM_SIMD_X86
150-
#ifndef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
151-
#define WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
150+
#ifndef WOLFSSL_USE_SAVE_VECTOR_REGISTERS
151+
#define WOLFSSL_USE_SAVE_VECTOR_REGISTERS
152152
#endif
153153
#elif defined(WOLFSSL_ARMASM) || defined(WOLFSSL_SP_ARM32_ASM) || \
154154
defined(WOLFSSL_SP_ARM64_ASM) || defined(WOLFSSL_SP_ARM_THUMB_ASM) ||\
@@ -158,8 +158,8 @@
158158
#endif
159159
#define WOLFSSL_LINUXKM_SIMD
160160
#define WOLFSSL_LINUXKM_SIMD_ARM
161-
#ifndef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
162-
#define WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
161+
#ifndef WOLFSSL_USE_SAVE_VECTOR_REGISTERS
162+
#define WOLFSSL_USE_SAVE_VECTOR_REGISTERS
163163
#endif
164164
#endif
165165

@@ -469,11 +469,11 @@
469469
* SAVE_VECTOR_REGISTERS().
470470
*/
471471
#if defined(WOLFSSL_LINUXKM_BENCHMARKS) && \
472-
!defined(WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS)
473-
#define WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
472+
!defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS)
473+
#define WOLFSSL_USE_SAVE_VECTOR_REGISTERS
474474
#endif
475475

476-
#if defined(WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS) && \
476+
#if defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS) && \
477477
defined(CONFIG_X86)
478478

479479
extern __must_check int allocate_wolfcrypt_linuxkm_fpu_states(void);
@@ -526,7 +526,7 @@
526526
#define REENABLE_VECTOR_REGISTERS() wc_restore_vector_registers_x86(WC_SVR_FLAG_INHIBIT)
527527
#endif
528528

529-
#elif defined(WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS) && (defined(CONFIG_ARM) || defined(CONFIG_ARM64))
529+
#elif defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS) && (defined(CONFIG_ARM) || defined(CONFIG_ARM64))
530530

531531
#error kernel module ARM SIMD is not yet tested or usable.
532532

@@ -562,9 +562,9 @@
562562
#define RESTORE_VECTOR_REGISTERS() restore_vector_registers_arm()
563563
#endif
564564

565-
#elif defined(WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS)
566-
#error WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS is set for an unimplemented architecture.
567-
#endif /* WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS */
565+
#elif defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS)
566+
#error WOLFSSL_USE_SAVE_VECTOR_REGISTERS is set for an unimplemented architecture.
567+
#endif /* WOLFSSL_USE_SAVE_VECTOR_REGISTERS */
568568

569569
_Pragma("GCC diagnostic pop");
570570

@@ -817,7 +817,7 @@
817817

818818
struct task_struct *(*get_current)(void);
819819

820-
#ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
820+
#ifdef WOLFSSL_USE_SAVE_VECTOR_REGISTERS
821821

822822
#ifdef CONFIG_X86
823823
typeof(allocate_wolfcrypt_linuxkm_fpu_states) *allocate_wolfcrypt_linuxkm_fpu_states;
@@ -826,10 +826,10 @@
826826
typeof(wc_restore_vector_registers_x86) *wc_restore_vector_registers_x86;
827827
typeof(wc_save_vector_registers_x86) *wc_save_vector_registers_x86;
828828
#else /* !CONFIG_X86 */
829-
#error WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS is set for an unimplemented architecture.
829+
#error WOLFSSL_USE_SAVE_VECTOR_REGISTERS is set for an unimplemented architecture.
830830
#endif /* arch */
831831

832-
#endif /* WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS */
832+
#endif /* WOLFSSL_USE_SAVE_VECTOR_REGISTERS */
833833

834834
typeof(__mutex_init) *__mutex_init;
835835
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0)
@@ -1113,15 +1113,15 @@
11131113
#undef get_current
11141114
#define get_current WC_LKM_INDIRECT_SYM(get_current)
11151115

1116-
#if defined(WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS) && defined(CONFIG_X86)
1116+
#if defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS) && defined(CONFIG_X86)
11171117
#define allocate_wolfcrypt_linuxkm_fpu_states WC_LKM_INDIRECT_SYM(allocate_wolfcrypt_linuxkm_fpu_states)
11181118
#define wc_can_save_vector_registers_x86 WC_LKM_INDIRECT_SYM(wc_can_save_vector_registers_x86)
11191119
#define free_wolfcrypt_linuxkm_fpu_states WC_LKM_INDIRECT_SYM(free_wolfcrypt_linuxkm_fpu_states)
11201120
#define wc_restore_vector_registers_x86 WC_LKM_INDIRECT_SYM(wc_restore_vector_registers_x86)
11211121
#define wc_save_vector_registers_x86 WC_LKM_INDIRECT_SYM(wc_save_vector_registers_x86)
1122-
#elif defined(WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS)
1123-
#error WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS is set for an unimplemented architecture.
1124-
#endif /* WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS */
1122+
#elif defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS)
1123+
#error WOLFSSL_USE_SAVE_VECTOR_REGISTERS is set for an unimplemented architecture.
1124+
#endif /* WOLFSSL_USE_SAVE_VECTOR_REGISTERS */
11251125

11261126
#define __mutex_init WC_LKM_INDIRECT_SYM(__mutex_init)
11271127
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0)
@@ -1217,11 +1217,11 @@
12171217
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 15, 0)) || \
12181218
(defined(RHEL_MAJOR) && \
12191219
((RHEL_MAJOR > 9) || ((RHEL_MAJOR == 9) && (RHEL_MINOR >= 5))))
1220-
#define lkm_printf(format, args...) _printk(KERN_INFO "wolfssl: %s(): " format, __func__, ## args)
1220+
#define wc_km_printf(format, args...) _printk(KERN_INFO "wolfssl: %s(): " format, __func__, ## args)
12211221
#else
1222-
#define lkm_printf(format, args...) printk(KERN_INFO "wolfssl: %s(): " format, __func__, ## args)
1222+
#define wc_km_printf(format, args...) printk(KERN_INFO "wolfssl: %s(): " format, __func__, ## args)
12231223
#endif
1224-
#define printf(...) lkm_printf(__VA_ARGS__)
1224+
#define printf(...) wc_km_printf(__VA_ARGS__)
12251225

12261226
#ifdef HAVE_FIPS
12271227
extern void fipsEntry(void);
@@ -1250,7 +1250,7 @@
12501250

12511251
#if !defined(BUILDING_WOLFSSL)
12521252
/* some caller code needs these. */
1253-
#if defined(WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS)
1253+
#if defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS)
12541254
#if defined(CONFIG_X86)
12551255
WOLFSSL_API __must_check int wc_can_save_vector_registers_x86(void);
12561256
WOLFSSL_API __must_check int wc_save_vector_registers_x86(enum wc_svr_flags flags);
@@ -1262,9 +1262,9 @@
12621262
#define REENABLE_VECTOR_REGISTERS() wc_restore_vector_registers_x86(WC_SVR_FLAG_INHIBIT)
12631263
#endif
12641264
#else /* !CONFIG_X86 */
1265-
#error WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS is set for an unimplemented architecture.
1265+
#error WOLFSSL_USE_SAVE_VECTOR_REGISTERS is set for an unimplemented architecture.
12661266
#endif /* !CONFIG_X86 */
1267-
#endif /* WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS */
1267+
#endif /* WOLFSSL_USE_SAVE_VECTOR_REGISTERS */
12681268
#endif /* !BUILDING_WOLFSSL */
12691269

12701270
/* Copied from wc_port.h: For FIPS keep the function names the same */

linuxkm/lkcapi_aes_glue.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,13 @@
7070

7171
#include <wolfssl/wolfcrypt/aes.h>
7272

73-
#if defined(WC_LINUXKM_C_FALLBACK_IN_SHIMS) && !defined(WC_FLAG_DONT_USE_AESNI)
74-
#error WC_LINUXKM_C_FALLBACK_IN_SHIMS is defined but WC_FLAG_DONT_USE_AESNI is missing.
73+
#if defined(WC_FLAG_DONT_USE_AESNI) && !defined(WC_FLAG_DONT_USE_VECTOR_OPS)
74+
/* backward compat */
75+
#define WC_FLAG_DONT_USE_VECTOR_OPS WC_FLAG_DONT_USE_AESNI
76+
#endif
77+
78+
#if defined(WC_LINUXKM_C_FALLBACK_IN_SHIMS) && !defined(WC_FLAG_DONT_USE_VECTOR_OPS)
79+
#error WC_LINUXKM_C_FALLBACK_IN_SHIMS is defined but WC_FLAG_DONT_USE_VECTOR_OPS is missing.
7580
#endif
7681

7782
/* note the FIPS code will be returned on failure even in non-FIPS builds. */
@@ -500,7 +505,7 @@ static int km_AesSetKeyCommon(struct km_AesCtx * ctx, const u8 *in_key,
500505
#ifdef WC_LINUXKM_C_FALLBACK_IN_SHIMS
501506

502507
if (ctx->aes_encrypt->use_aesni) {
503-
ctx->aes_encrypt_C->use_aesni = WC_FLAG_DONT_USE_AESNI;
508+
ctx->aes_encrypt_C->use_aesni = WC_FLAG_DONT_USE_VECTOR_OPS;
504509

505510
err = wc_AesSetKey(ctx->aes_encrypt_C, in_key, key_len, NULL, AES_ENCRYPTION);
506511

@@ -516,7 +521,7 @@ static int km_AesSetKeyCommon(struct km_AesCtx * ctx, const u8 *in_key,
516521
}
517522

518523
if (ctx->aes_decrypt_C && ctx->aes_decrypt->use_aesni) {
519-
ctx->aes_decrypt_C->use_aesni = WC_FLAG_DONT_USE_AESNI;
524+
ctx->aes_decrypt_C->use_aesni = WC_FLAG_DONT_USE_VECTOR_OPS;
520525

521526
err = wc_AesSetKey(ctx->aes_decrypt_C, in_key, key_len, NULL,
522527
AES_DECRYPTION);
@@ -927,7 +932,7 @@ static int km_AesGcmSetKey(struct crypto_aead *tfm, const u8 *in_key,
927932

928933
#ifdef WC_LINUXKM_C_FALLBACK_IN_SHIMS
929934
if (ctx->aes_encrypt->use_aesni) {
930-
ctx->aes_encrypt_C->use_aesni = WC_FLAG_DONT_USE_AESNI;
935+
ctx->aes_encrypt_C->use_aesni = WC_FLAG_DONT_USE_VECTOR_OPS;
931936

932937
err = wc_AesGcmSetKey(ctx->aes_encrypt_C, in_key, key_len);
933938

@@ -975,7 +980,7 @@ static int km_AesGcmSetKey_Rfc4106(struct crypto_aead *tfm, const u8 *in_key,
975980

976981
#ifdef WC_LINUXKM_C_FALLBACK_IN_SHIMS
977982
if (ctx->aes_encrypt->use_aesni) {
978-
ctx->aes_encrypt_C->use_aesni = WC_FLAG_DONT_USE_AESNI;
983+
ctx->aes_encrypt_C->use_aesni = WC_FLAG_DONT_USE_VECTOR_OPS;
979984

980985
err = wc_AesGcmSetKey(ctx->aes_encrypt_C, in_key, key_len);
981986

@@ -1612,7 +1617,7 @@ static int km_AesXtsSetKey(struct crypto_skcipher *tfm, const u8 *in_key,
16121617
}
16131618

16141619
/* It's possible to set ctx->aesXts->{tweak,aes,aes_decrypt}.use_aesni to
1615-
* WC_FLAG_DONT_USE_AESNI here, for WC_LINUXKM_C_FALLBACK_IN_SHIMS in
1620+
* WC_FLAG_DONT_USE_VECTOR_OPS here, for WC_LINUXKM_C_FALLBACK_IN_SHIMS in
16161621
* AES-XTS, but we can use the WC_C_DYNAMIC_FALLBACK mechanism
16171622
* unconditionally because there's no AES-XTS in Cert 4718.
16181623
*/

linuxkm/module_hooks.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ int wc_linuxkm_GenerateSeed_IntelRD(struct OS_Seed* os, byte* output, word32 sz)
366366

367367
#endif /* WC_LINUXKM_RDSEED_IN_GLUE_LAYER */
368368

369-
#if defined(WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS) && defined(CONFIG_X86)
369+
#if defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS) && defined(CONFIG_X86)
370370
#include "linuxkm/x86_vector_register_glue.c"
371371
#endif
372372

@@ -1025,15 +1025,15 @@ static int set_up_wolfssl_linuxkm_pie_redirect_table(void) {
10251025

10261026
wolfssl_linuxkm_pie_redirect_table.get_current = my_get_current_thread;
10271027

1028-
#if defined(WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS) && defined(CONFIG_X86)
1028+
#if defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS) && defined(CONFIG_X86)
10291029
wolfssl_linuxkm_pie_redirect_table.allocate_wolfcrypt_linuxkm_fpu_states = allocate_wolfcrypt_linuxkm_fpu_states;
10301030
wolfssl_linuxkm_pie_redirect_table.wc_can_save_vector_registers_x86 = wc_can_save_vector_registers_x86;
10311031
wolfssl_linuxkm_pie_redirect_table.free_wolfcrypt_linuxkm_fpu_states = free_wolfcrypt_linuxkm_fpu_states;
10321032
wolfssl_linuxkm_pie_redirect_table.wc_restore_vector_registers_x86 = wc_restore_vector_registers_x86;
10331033
wolfssl_linuxkm_pie_redirect_table.wc_save_vector_registers_x86 = wc_save_vector_registers_x86;
1034-
#elif defined(WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS)
1035-
#error WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS is set for an unsupported architecture.
1036-
#endif /* WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS */
1034+
#elif defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS)
1035+
#error WOLFSSL_USE_SAVE_VECTOR_REGISTERS is set for an unsupported architecture.
1036+
#endif /* WOLFSSL_USE_SAVE_VECTOR_REGISTERS */
10371037

10381038
wolfssl_linuxkm_pie_redirect_table.__mutex_init = __mutex_init;
10391039
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0)

linuxkm/x86_vector_register_glue.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
/* included by linuxkm/module_hooks.c */
2424
#ifndef WC_SKIP_INCLUDED_C_FILES
2525

26-
#if !defined(WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS) || !defined(CONFIG_X86)
26+
#if !defined(WOLFSSL_USE_SAVE_VECTOR_REGISTERS) || !defined(CONFIG_X86)
2727
#error x86_vector_register_glue.c included in non-vectorized/non-x86 project.
2828
#endif
2929

@@ -39,7 +39,7 @@
3939
* checks in __kernel_fpu_begin(), and lacks TIF_NEED_FPU_LOAD.
4040
*/
4141
#if (LINUX_VERSION_CODE < KERNEL_VERSION(5, 4, 0))
42-
#error WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS on x86 requires kernel 5.4.0 or higher.
42+
#error WOLFSSL_USE_SAVE_VECTOR_REGISTERS on x86 requires kernel 5.4.0 or higher.
4343
#endif
4444

4545
static unsigned int wc_linuxkm_fpu_states_n_tracked = 0;

src/crl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ CRL Options:
4141
#include <wolfssl/error-ssl.h>
4242
#include <wolfssl/wolfcrypt/logging.h>
4343

44-
#ifndef WOLFSSL_LINUXKM
44+
#ifndef NO_STRING_H
4545
#include <string.h>
4646
#endif
4747

src/dtls13.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ static int Dtls13GetRnMask(WOLFSSL* ssl, const byte* ciphertext, byte* mask,
255255
return BAD_STATE_E;
256256
#if !defined(HAVE_SELFTEST) && \
257257
(!defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)) \
258-
|| defined(WOLFSSL_LINUXKM))
258+
|| defined(WOLFSSL_KERNEL_MODE))
259259
return wc_AesEncryptDirect(c->aes, mask, ciphertext);
260260
#else
261261
wc_AesEncryptDirect(c->aes, mask, ciphertext);

src/ssl_crypto.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3102,7 +3102,7 @@ void wolfSSL_AES_encrypt(const unsigned char* input, unsigned char* output,
31023102
else
31033103
#if !defined(HAVE_SELFTEST) && \
31043104
(!defined(HAVE_FIPS) || (defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,3)) \
3105-
|| defined(WOLFSSL_LINUXKM))
3105+
|| defined(WOLFSSL_KERNEL_MODE))
31063106
/* Encrypt a block with wolfCrypt AES. */
31073107
if (wc_AesEncryptDirect((Aes*)key, output, input) != 0) {
31083108
WOLFSSL_MSG("wc_AesEncryptDirect failed");

wolfcrypt/benchmark/benchmark.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2343,7 +2343,7 @@ static WC_INLINE void bench_stats_start(int* count, double* start)
23432343
#endif
23442344
}
23452345

2346-
#ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
2346+
#ifdef WOLFSSL_USE_SAVE_VECTOR_REGISTERS
23472347
#define bench_stats_start(count, start) do { \
23482348
SAVE_VECTOR_REGISTERS(pr_err( \
23492349
"ERROR: SAVE_VECTOR_REGISTERS failed for benchmark run."); \
@@ -2746,7 +2746,7 @@ static void bench_stats_sym_finish(const char* desc, int useDeviceID,
27462746
(void)useDeviceID;
27472747
(void)ret;
27482748

2749-
#ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
2749+
#ifdef WOLFSSL_USE_SAVE_VECTOR_REGISTERS
27502750
RESTORE_VECTOR_REGISTERS();
27512751
#elif defined(WOLFSSL_LINUXKM)
27522752
kernel_fpu_end();
@@ -3009,7 +3009,7 @@ static void bench_stats_asym_finish_ex(const char* algo, int strength,
30093009
(void)useDeviceID;
30103010
(void)ret;
30113011

3012-
#ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
3012+
#ifdef WOLFSSL_USE_SAVE_VECTOR_REGISTERS
30133013
RESTORE_VECTOR_REGISTERS();
30143014
#elif defined(WOLFSSL_LINUXKM)
30153015
kernel_fpu_end();
@@ -5021,7 +5021,7 @@ static void bench_aesecb_internal(int useDeviceID,
50215021
if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
50225022
&times, outer_loop_limit, &pending)) {
50235023
#ifdef HAVE_FIPS
5024-
#if defined(WOLFSSL_LINUXKM) || FIPS_VERSION_GE(6, 0)
5024+
#if defined(WOLFSSL_KERNEL_MODE) || FIPS_VERSION_GE(6, 0)
50255025
ret = wc_AesEncryptDirect(enc[i], bench_cipher, bench_plain);
50265026
if (ret != 0)
50275027
goto exit_aes_enc;
@@ -5078,7 +5078,7 @@ static void bench_aesecb_internal(int useDeviceID,
50785078
if (bench_async_check(&ret, BENCH_ASYNC_GET_DEV(enc[i]), 0,
50795079
&times, outer_loop_limit, &pending)) {
50805080
#ifdef HAVE_FIPS
5081-
#if defined(WOLFSSL_LINUXKM) || FIPS_VERSION_GE(6, 0)
5081+
#if defined(WOLFSSL_KERNEL_MODE) || FIPS_VERSION_GE(6, 0)
50825082
ret = wc_AesDecryptDirect(enc[i], bench_plain, bench_cipher);
50835083
if (ret != 0)
50845084
goto exit_aes_dec;

wolfcrypt/src/aes.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4682,12 +4682,12 @@ static void AesSetKey_C(Aes* aes, const byte* key, word32 keySz, int dir)
46824682
* AES-NI is disabled, and a nonzero value if it's enabled.
46834683
*
46844684
* An additional, optional semantic is available via
4685-
* WC_FLAG_DONT_USE_AESNI, and is used in some kernel module builds to
4686-
* let the caller inhibit AES-NI. When this macro is defined,
4685+
* WC_FLAG_DONT_USE_VECTOR_OPS, and is used in some kernel module builds
4686+
* to let the caller inhibit AES-NI. When this macro is defined,
46874687
* wc_AesInit() before wc_AesSetKey() is imperative, to avoid a read of
46884688
* uninitialized data in aes->use_aesni. That's why support for
4689-
* WC_FLAG_DONT_USE_AESNI must remain optional -- wc_AesInit() was only
4690-
* added in release 3.11.0, so legacy applications inevitably call
4689+
* WC_FLAG_DONT_USE_VECTOR_OPS must remain optional -- wc_AesInit() was
4690+
* only added in release 3.11.0, so legacy applications inevitably call
46914691
* wc_AesSetKey() on uninitialized Aes contexts. This must continue to
46924692
* function correctly with default build settings.
46934693
*/
@@ -4697,25 +4697,28 @@ static void AesSetKey_C(Aes* aes, const byte* key, word32 keySz, int dir)
46974697
checkedAESNI = 1;
46984698
}
46994699
if (haveAESNI
4700-
#if defined(WC_FLAG_DONT_USE_AESNI) && !defined(WC_C_DYNAMIC_FALLBACK)
4701-
&& (aes->use_aesni != WC_FLAG_DONT_USE_AESNI)
4700+
#if defined(WC_FLAG_DONT_USE_VECTOR_OPS) && !defined(WC_C_DYNAMIC_FALLBACK)
4701+
&& (aes->use_aesni != WC_FLAG_DONT_USE_VECTOR_OPS)
47024702
#endif
47034703
)
47044704
{
4705-
#if defined(WC_FLAG_DONT_USE_AESNI)
4706-
if (aes->use_aesni == WC_FLAG_DONT_USE_AESNI) {
4705+
#if defined(WC_FLAG_DONT_USE_VECTOR_OPS)
4706+
if (aes->use_aesni == WC_FLAG_DONT_USE_VECTOR_OPS) {
47074707
aes->use_aesni = 0;
47084708
return 0;
47094709
}
47104710
#endif
47114711
aes->use_aesni = 0;
4712-
#ifdef WOLFSSL_LINUXKM
4712+
#ifdef WOLFSSL_KERNEL_MODE
47134713
/* runtime alignment check */
47144714
if ((wc_ptr_t)&aes->key & (wc_ptr_t)0xf) {
4715-
return BAD_ALIGN_E;
4715+
ret = BAD_ALIGN_E;
4716+
}
4717+
else
4718+
#endif /* WOLFSSL_KERNEL_MODE */
4719+
{
4720+
ret = SAVE_VECTOR_REGISTERS2();
47164721
}
4717-
#endif /* WOLFSSL_LINUXKM */
4718-
ret = SAVE_VECTOR_REGISTERS2();
47194722
if (ret == 0) {
47204723
if (dir == AES_ENCRYPTION)
47214724
ret = AES_set_encrypt_key_AESNI(userKey, (int)keylen * 8, aes);

0 commit comments

Comments
 (0)