Skip to content

Commit a10260c

Browse files
committed
refactor AESNI implementations and *VECTOR_REGISTERS* macros to allow dynamic as-needed fallback to pure C, via WC_AES_C_DYNAMIC_FALLBACK.
wolfssl/wolfcrypt/aes.h: add key_C_fallback[] to struct Aes, and remove comment that "AESNI needs key first, rounds 2nd, not sure why yet" now that AES_128_Key_Expansion_AESNI no longer writes rounds after the expanded key. wolfcrypt/src/aes.c: * add _AESNI or _aesni suffixes/infixes to AESNI implementations that were missing them: AES_CBC_encrypt(), AES_CBC_decrypt_by*(), AES_ECB_encrypt(), AES_*_Key_Expansion(), AES_set_encrypt_key(), AES_set_decrypt_key(), AES_GCM_encrypt(), AES_GCM_decrypt(), AES_XTS_encrypt(), and AES_XTS_decrypt(). * move key size check from to start of wc_AesSetKeyLocal(). * refactor pure-C AES setkey and cipher implementations to use aes->key_C_fallback when defined(WC_AES_C_DYNAMIC_FALLBACK). * refactor wc_AesSetKeyLocal() to set up both AESNI and pure-C expanded keys when defined(WC_AES_C_DYNAMIC_FALLBACK). * refactor all (haveAESNI && aes->use_aesni) conditions to just (aes->use_aesni). * add macros VECTOR_REGISTERS_PUSH and VECTOR_REGISTERS_POP, which do nothing but push a brace level when !defined(WC_AES_C_DYNAMIC_FALLBACK), but when defined(WC_AES_C_DYNAMIC_FALLBACK), they call SAVE_VECTOR_REGISTERS2() and on failure, temporarily clear aes->use_aesni and restore at _POP(). * refactor all invocations of SAVE_VECTOR_REGISTERS() and RESTORE_VECTOR_REGISTERS() to VECTOR_REGISTERS_PUSH and VECTOR_REGISTERS_POP, except in wc_AesSetKeyLocal(), wc_AesXtsEncrypt(), and wc_AesXtsDecrypt(), which are refactored to use SAVE_VECTOR_REGISTERS2(), with graceful failure concealment if defined(WC_AES_C_DYNAMIC_FALLBACK). * orthogonalize cleanup code in wc_AesCbcEncrypt(), wc_AesCcmEncrypt() and wc_AesCcmDecrypt(). * streamline fallthrough software definitions of wc_AesEncryptDirect() and wc_AesDecryptDirect(), and remove special-casing for defined(WOLFSSL_LINUXKM)&&defined(WOLFSSL_AESNI). wolfcrypt/src/aes_asm.{S,asm}: * remove errant "movl $10, 240(%rsi)" from AES_128_Key_Expansion_AESNI. * add _AESNI suffixes/infixes to implementations that needed them. wolfcrypt/src/{aes_gcm_asm.{S,asm},aes_xts_asm.S}: regenerate from revisions in scripts#357 -- adds _aesni suffixes to implementations that were missing them. wolfssl/wolfcrypt/types.h: remove DEBUG_VECTOR_REGISTER_ACCESS macros, and add dummy fallthrough definitions for SAVE_VECTOR_REGISTERS2 and WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL. wolfssl/wolfcrypt/memory.h: adopt DEBUG_VECTOR_REGISTER_ACCESS code from types.h, and add definitions for WC_DEBUG_VECTOR_REGISTERS_RETVAL_INITVAL and WC_DEBUG_SET_VECTOR_REGISTERS_RETVAL. linuxkm/linuxkm_wc_port.h: add arch-specific macro definitions for SAVE_VECTOR_REGISTERS2(). wolfcrypt/benchmark/benchmark.c: add missing gates around calls to RESTORE_VECTOR_REGISTERS(). configure.ac: * cover various interdependencies in enable-all/enable-all-crypto, for better behavior in combination with --disable-aesgcm, --disable-ecc, --disable-ocsp, --disable-hmac, --disable-chacha, --disable-ed25519, and --disable-ed448. * inhibit aesgcm_stream in enable-all/enable-all-crypto when ENABLED_LINUXKM_DEFAULTS, because it is currently incompatible with WC_AES_C_DYNAMIC_FALLBACK. * add -DWC_AES_C_DYNAMIC_FALLBACK when ENABLED_LINUXKM_DEFAULTS. * add 3 new interdependency checks: "ECCSI requires ECC.", "SAKKE requires ECC.", "WOLFSSH requires HMAC." wolfcrypt/src/asn.c: tweak gating to accommodate defined(NO_RSA) && !defined(HAVE_ECC). wolfcrypt/src/evp.c: tweak gating to accommodate defined(NO_HMAC). wolfcrypt/src/logging.c: remove DEBUG_VECTOR_REGISTER_ACCESS code (moved to memory.c). wolfcrypt/src/memory.c: change #include of settings.h to types.h; adopt DEBUG_VECTOR_REGISTER_ACCESS code from logging.c; add implementation of SAVE_VECTOR_REGISTERS2_fuzzer(). wolfcrypt/src/pwdbased.c: add explanatory #error scrypt requires HMAC. wolfcrypt/test/test.c: * add DEBUG_VECTOR_REGISTER_ACCESS clauses to aes_xts_128_test(), aesecb_test(), aesctr_test(), aes_test() CBC section, aes256_test() CBC section, and aesgcm_default_test_helper() * remove duplicate wc_AesEcbDecrypt() in aesecb_test(). * add gating for pbkdf2_test(). * fix cleanup code in dsa_test(). * fix gating in pkcs7authenveloped_run_vectors() to accommodate !defined(HAVE_AESGCM). * fix gating in cryptocb_test() to accommodate defined(NO_HMAC). wolfssl/wolfcrypt/cryptocb.h: remove gates around "pk" sub-struct of struct wc_CryptoInfo -- wc_CryptoInfo.pk.type (an int) is used unconditionally when --enable-debug, and is used with DH. wolfssl/wolfcrypt/error-crypt.h: fix whitespace.
1 parent e395aad commit a10260c

20 files changed

Lines changed: 1907 additions & 1318 deletions

File tree

configure.ac

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,6 @@ 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
724723
test "$enable_aesccm" = "" && enable_aesccm=yes
725724
test "$enable_aesctr" = "" && enable_aesctr=yes
726725
test "$enable_aeseax" = "" && enable_aeseax=yes
@@ -741,22 +740,22 @@ then
741740
test "$enable_hkdf" = "" && enable_hkdf=yes
742741
test "$enable_curve25519" = "" && enable_curve25519=yes
743742
test "$enable_curve448" = "" && enable_curve448=yes
744-
test "$enable_fpecc" = "" && enable_fpecc=yes
745-
test "$enable_eccencrypt" = "" && enable_eccencrypt=yes
743+
test "$enable_fpecc" = "" && test "$enable_ecc" != "no" && enable_fpecc=yes
744+
test "$enable_eccencrypt" = "" && test "$enable_ecc" != "no" && enable_eccencrypt=yes
746745
test "$enable_psk" = "" && enable_psk=yes
747746
test "$enable_cmac" = "" && enable_cmac=yes
748747
test "$enable_siphash" = "" && enable_siphash=yes
749748
test "$enable_xts" = "" && enable_xts=yes
750749
test "$enable_ocsp" = "" && enable_ocsp=yes
751-
test "$enable_ocspstapling" = "" && enable_ocspstapling=yes
752-
test "$enable_ocspstapling2" = "" && enable_ocspstapling2=yes
750+
test "$enable_ocspstapling" = "" && test "$enable_ocsp" != "no" && enable_ocspstapling=yes
751+
test "$enable_ocspstapling2" = "" && test "$enable_ocsp" != "no" && enable_ocspstapling2=yes
753752
test "$enable_crl" = "" && enable_crl=yes
754753
test "$enable_supportedcurves" = "" && enable_supportedcurves=yes
755754
test "$enable_tlsx" = "" && enable_tlsx=yes
756755
test "$enable_pwdbased" = "" && enable_pwdbased=yes
757756
test "$enable_aeskeywrap" = "" && enable_aeskeywrap=yes
758757
test "$enable_x963kdf" = "" && enable_x963kdf=yes
759-
test "$enable_scrypt" = "" && enable_scrypt=yes
758+
test "$enable_scrypt" = "" && test "$enable_hmac" != "no" && enable_scrypt=yes
760759
test "$enable_indef" = "" && enable_indef=yes
761760
test "$enable_enckeys" = "" && enable_enckeys=yes
762761
test "$enable_hashflags" = "" && enable_hashflags=yes
@@ -771,7 +770,7 @@ then
771770
test "$enable_md4" = "" && enable_md4=yes
772771
test "$enable_cryptocb" = "" && enable_cryptocb=yes
773772
test "$enable_anon" = "" && enable_anon=yes
774-
test "$enable_ssh" = "" && enable_ssh=yes
773+
test "$enable_ssh" = "" && test "$enable_hmac" != "no" && enable_ssh=yes
775774

776775
test "$enable_savesession" = "" && enable_savesession=yes
777776
test "$enable_savecert" = "" && enable_savecert=yes
@@ -797,6 +796,7 @@ then
797796

798797
if test "$ENABLED_LINUXKM_DEFAULTS" != "yes"
799798
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" = "" && enable_quic=yes
802802
AM_CFLAGS="$AM_CFLAGS -DHAVE_CRL_IO -DHAVE_IO_TIMEOUT"
@@ -836,17 +836,17 @@ then
836836
if test "$ENABLED_FIPS" = "no"
837837
then
838838
test "$enable_pkcallbacks" = "" && enable_pkcallbacks=yes
839-
test "$enable_xchacha" = "" && enable_xchacha=yes
839+
test "$enable_xchacha" = "" && test "$enable_chacha" != "no" && enable_xchacha=yes
840840
test "$enable_scep" = "" && enable_scep=yes
841841
test "$enable_pkcs7" = "" && enable_pkcs7=yes
842842
test "$enable_nullcipher" = "" && enable_nullcipher=yes
843843
test "$enable_mcast" = "" && enable_mcast=yes
844844
if test "$ENABLED_32BIT" != "yes"
845845
then
846846
test "$enable_ed25519" = "" && enable_ed25519=yes
847-
test "$enable_ed25519_stream" = "" && enable_ed25519_stream=yes
847+
test "$enable_ed25519_stream" = "" && test "$enable_ed25519" != "no" && enable_ed25519_stream=yes
848848
test "$enable_ed448" = "" && enable_ed448=yes
849-
test "$enable_ed448_stream" = "" && enable_ed448_stream=yes
849+
test "$enable_ed448_stream" = "" && test "$enable_ed448" != "no" && enable_ed448_stream=yes
850850
fi
851851

852852
if test "$ENABLED_LINUXKM_DEFAULTS" != "yes"
@@ -856,8 +856,8 @@ then
856856
test "$enable_curl" = "" && enable_curl=yes
857857
test "$enable_tcpdump" = "" && enable_tcpdump=yes
858858

859-
test "$enable_eccsi" = "" && enable_eccsi=yes
860-
test "$enable_sakke" = "" && enable_sakke=yes
859+
test "$enable_eccsi" = "" && test "$enable_ecc" != "no" && enable_eccsi=yes
860+
test "$enable_sakke" = "" && test "$enable_ecc" != "no" && enable_sakke=yes
861861
fi
862862
fi
863863

@@ -908,7 +908,6 @@ if test "$ENABLED_ALL_CRYPT" = "yes"
908908
then
909909
test "$enable_atomicuser" = "" && enable_atomicuser=yes
910910
test "$enable_aesgcm" = "" && enable_aesgcm=yes
911-
test "$enable_aesgcm_stream" = "" && test "$enable_aesgcm" = "yes" && enable_aesgcm_stream=yes
912911
test "$enable_aesccm" = "" && enable_aesccm=yes
913912
test "$enable_aesctr" = "" && enable_aesctr=yes
914913
test "$enable_aeseax" = "" && enable_aeseax=yes
@@ -929,22 +928,22 @@ then
929928
test "$enable_hkdf" = "" && enable_hkdf=yes
930929
test "$enable_curve25519" = "" && enable_curve25519=yes
931930
test "$enable_curve448" = "" && enable_curve448=yes
932-
test "$enable_fpecc" = "" && enable_fpecc=yes
933-
test "$enable_eccencrypt" = "" && enable_eccencrypt=yes
931+
test "$enable_fpecc" = "" && test "$enable_ecc" != "no" && enable_fpecc=yes
932+
test "$enable_eccencrypt" = "" && test "$enable_ecc" != "no" && enable_eccencrypt=yes
934933
test "$enable_psk" = "" && enable_psk=yes
935934
test "$enable_cmac" = "" && enable_cmac=yes
936935
test "$enable_siphash" = "" && enable_siphash=yes
937936
test "$enable_xts" = "" && enable_xts=yes
938937
test "$enable_ocsp" = "" && enable_ocsp=yes
939-
test "$enable_ocspstapling" = "" && enable_ocspstapling=yes
940-
test "$enable_ocspstapling2" = "" && enable_ocspstapling2=yes
938+
test "$enable_ocspstapling" = "" && test "$enable_ocsp" != "no" && enable_ocspstapling=yes
939+
test "$enable_ocspstapling2" = "" && test "$enable_ocsp" != "no" && enable_ocspstapling2=yes
941940
test "$enable_crl" = "" && enable_crl=yes
942941
test "$enable_supportedcurves" = "" && enable_supportedcurves=yes
943942
test "$enable_tlsx" = "" && enable_tlsx=yes
944943
test "$enable_pwdbased" = "" && enable_pwdbased=yes
945944
test "$enable_aeskeywrap" = "" && enable_aeskeywrap=yes
946945
test "$enable_x963kdf" = "" && enable_x963kdf=yes
947-
test "$enable_scrypt" = "" && enable_scrypt=yes
946+
test "$enable_scrypt" = "" && test "$enable_hmac" != "no" && enable_scrypt=yes
948947
test "$enable_indef" = "" && enable_indef=yes
949948
test "$enable_enckeys" = "" && enable_enckeys=yes
950949
test "$enable_hashflags" = "" && enable_hashflags=yes
@@ -959,7 +958,7 @@ then
959958
test "$enable_md4" = "" && enable_md4=yes
960959
test "$enable_cryptocb" = "" && enable_cryptocb=yes
961960
test "$enable_anon" = "" && enable_anon=yes
962-
test "$enable_ssh" = "" && enable_ssh=yes
961+
test "$enable_ssh" = "" && test "$enable_hmac" != "no" && enable_ssh=yes
963962

964963
if test "$ENABLED_32BIT" != "yes"
965964
then
@@ -969,6 +968,7 @@ then
969968

970969
if test "$ENABLED_LINUXKM_DEFAULTS" != "yes"
971970
then
971+
test "$enable_aesgcm_stream" = "" && test "$enable_aesgcm" = "yes" && enable_aesgcm_stream=yes
972972
test "$enable_compkey" = "" && enable_compkey=yes
973973
fi
974974

@@ -983,21 +983,21 @@ then
983983
if test "$ENABLED_FIPS" = "no"
984984
then
985985
test "$enable_pkcallbacks" = "" && enable_pkcallbacks=yes
986-
test "$enable_xchacha" = "" && enable_xchacha=yes
986+
test "$enable_xchacha" = "" && test "$enable_chacha" != "no" && enable_xchacha=yes
987987
test "$enable_pkcs7" = "" && enable_pkcs7=yes
988988
test "$enable_nullcipher" = "" && enable_nullcipher=yes
989989
if test "$ENABLED_32BIT" != "yes"
990990
then
991991
test "$enable_ed25519" = "" && enable_ed25519=yes
992-
test "$enable_ed25519_stream" = "" && enable_ed25519_stream=yes
992+
test "$enable_ed25519_stream" = "" && test "$enable_ed25519" != "no" && enable_ed25519_stream=yes
993993
test "$enable_ed448" = "" && enable_ed448=yes
994-
test "$enable_ed448_stream" = "" && enable_ed448_stream=yes
994+
test "$enable_ed448_stream" = "" && test "$enable_ed448" != "no" && enable_ed448_stream=yes
995995
fi
996996

997997
if test "$ENABLED_LINUXKM_DEFAULTS" != "yes"
998998
then
999-
test "$enable_eccsi" = "" && enable_eccsi=yes
1000-
test "$enable_sakke" = "" && enable_sakke=yes
999+
test "$enable_eccsi" = "" && test "$enable_ecc" != "no" && enable_eccsi=yes
1000+
test "$enable_sakke" = "" && test "$enable_ecc" != "no" && enable_sakke=yes
10011001
fi
10021002
fi
10031003

@@ -2896,6 +2896,10 @@ then
28962896
if test "$ENABLED_AESNI" = "yes" || test "$ENABLED_INTELASM" = "yes"
28972897
then
28982898
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_AESNI"
2899+
if test "$ENABLED_LINUXKM_DEFAULTS" = "yes"
2900+
then
2901+
AM_CFLAGS="$AM_CFLAGS -DWC_AES_C_DYNAMIC_FALLBACK"
2902+
fi
28992903
if test "$CC" != "icc"
29002904
then
29012905
case $host_os in
@@ -3951,6 +3955,10 @@ AC_ARG_ENABLE([eccsi],
39513955

39523956
if test "x$ENABLED_ECCSI" = "xyes"
39533957
then
3958+
if test "$ENABLED_ECC" = "no"
3959+
then
3960+
AC_MSG_ERROR([ECCSI requires ECC.])
3961+
fi
39543962
AM_CFLAGS="$AM_CFLAGS -DWOLFCRYPT_HAVE_ECCSI -DWOLFSSL_PUBLIC_MP"
39553963
fi
39563964

@@ -3961,6 +3969,11 @@ AC_ARG_ENABLE([sakke],
39613969
[ ENABLED_SAKKE=no ]
39623970
)
39633971

3972+
if test "$ENABLED_SAKKE" != "no" && test "$ENABLED_ECC" = "no"
3973+
then
3974+
AC_MSG_ERROR([SAKKE requires ECC.])
3975+
fi
3976+
39643977
if test "x$ENABLED_SAKKE" = "xsmall"
39653978
then
39663979
ENABLED_SAKKE="yes"
@@ -8926,6 +8939,11 @@ if test "x$ENABLED_OPENSSLCOEXIST" = "xyes"; then
89268939
fi
89278940
fi
89288941

8942+
if test "$ENABLED_WOLFSSH" = "yes" && test "$ENABLED_HMAC" = "no"
8943+
then
8944+
AC_MSG_ERROR([WOLFSSH requires HMAC.])
8945+
fi
8946+
89298947
AS_IF([test "x$ENABLED_WOLFSSH" = "xyes"],[AM_CPPFLAGS="$AM_CPPFLAGS -DWOLFSSL_WOLFSSH"])
89308948

89318949
# only allow secure renegotiation info with TLSV12 and ASN

linuxkm/linuxkm_wc_port.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@
185185
#endif
186186
#ifndef SAVE_VECTOR_REGISTERS
187187
#define SAVE_VECTOR_REGISTERS(fail_clause) { int _svr_ret = save_vector_registers_x86(); if (_svr_ret != 0) { fail_clause } }
188+
#define SAVE_VECTOR_REGISTERS2() save_vector_registers_x86()
188189
#endif
189190
#ifndef RESTORE_VECTOR_REGISTERS
190191
#define RESTORE_VECTOR_REGISTERS() restore_vector_registers_x86()
@@ -193,6 +194,7 @@
193194
#include <asm/fpsimd.h>
194195
#ifndef SAVE_VECTOR_REGISTERS
195196
#define SAVE_VECTOR_REGISTERS(fail_clause) { int _svr_ret = save_vector_registers_arm(); if (_svr_ret != 0) { fail_clause } }
197+
#define SAVE_VECTOR_REGISTERS2() save_vector_registers_arm()
196198
#endif
197199
#ifndef RESTORE_VECTOR_REGISTERS
198200
#define RESTORE_VECTOR_REGISTERS() restore_vector_registers_arm()

wolfcrypt/benchmark/benchmark.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2125,7 +2125,9 @@ static void bench_stats_sym_finish(const char* desc, int useDeviceID,
21252125
(void)useDeviceID;
21262126
(void)ret;
21272127

2128+
#ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
21282129
RESTORE_VECTOR_REGISTERS();
2130+
#endif
21292131

21302132
TEST_SLEEP();
21312133
} /* bench_stats_sym_finish */
@@ -2283,7 +2285,9 @@ static void bench_stats_asym_finish_ex(const char* algo, int strength,
22832285
(void)useDeviceID;
22842286
(void)ret;
22852287

2288+
#ifdef WOLFSSL_LINUXKM_USE_SAVE_VECTOR_REGISTERS
22862289
RESTORE_VECTOR_REGISTERS();
2290+
#endif
22872291

22882292
TEST_SLEEP();
22892293
} /* bench_stats_asym_finish_ex */

0 commit comments

Comments
 (0)