Skip to content

Commit

Permalink
Align (gcc-4.8) ADX usage w/ AVX-512 flag
Browse files Browse the repository at this point in the history
  • Loading branch information
justsmth committed Jun 26, 2024
1 parent 2bee79d commit 9d4d510
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion crypto/curve25519/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ extern "C" {

// If (1) x86_64 or aarch64, (2) linux or apple, and (3) OPENSSL_NO_ASM is not
// set, s2n-bignum path is capable.
#if ((defined(OPENSSL_X86_64) && !defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_AVX)) || \
#if ((defined(OPENSSL_X86_64) && !defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_512AVX)) || \
defined(OPENSSL_AARCH64)) && \
(defined(OPENSSL_LINUX) || defined(OPENSSL_APPLE) || \
defined(OPENSSL_OPENBSD)) && \
Expand Down
2 changes: 1 addition & 1 deletion crypto/fipsmodule/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ endif()

# s2n-bignum files can be compiled on Unix platforms only (except Apple),
# and on x86_64 and aarch64 systems only.
if((((ARCH STREQUAL "x86_64") AND NOT MY_ASSEMBLER_IS_TOO_OLD_FOR_AVX) OR
if((((ARCH STREQUAL "x86_64") AND NOT MY_ASSEMBLER_IS_TOO_OLD_FOR_512AVX) OR
ARCH STREQUAL "aarch64") AND UNIX)

# Set the source directory for s2n-bignum assembly files
Expand Down
2 changes: 1 addition & 1 deletion crypto/fipsmodule/ec/ec_nistp.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// set, s2n-bignum path is capable.
#if !defined(OPENSSL_NO_ASM) && \
(defined(OPENSSL_LINUX) || defined(OPENSSL_APPLE)) && \
((defined(OPENSSL_X86_64) && !defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_AVX)) || \
((defined(OPENSSL_X86_64) && !defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_512AVX)) || \
defined(OPENSSL_AARCH64))
# define EC_NISTP_USE_S2N_BIGNUM
# define EC_NISTP_USE_64BIT_LIMB
Expand Down
8 changes: 5 additions & 3 deletions crypto/fipsmodule/modes/gcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,15 @@ void CRYPTO_ghash_init(gmult_func *out_mult, ghash_func *out_hash,
CRYPTO_load_u64_be(gcm_key + 8)};

#if defined(GHASH_ASM_X86_64)
#if !defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_512AVX)
if (crypto_gcm_avx512_enabled()) {
gcm_init_avx512(out_table, H);
*out_mult = gcm_gmult_avx512;
*out_hash = gcm_ghash_avx512;
*out_is_avx = 1;
return;
}
#endif
if (crypto_gcm_clmul_enabled()) {
if (CRYPTO_is_AVX_capable() && CRYPTO_is_MOVBE_capable()) {
gcm_init_avx(out_table, H);
Expand Down Expand Up @@ -335,7 +337,7 @@ void CRYPTO_gcm128_setiv(GCM128_CONTEXT *ctx, const AES_KEY *key,
ctx->ares = 0;
ctx->mres = 0;

#if defined(GHASH_ASM_X86_64)
#if defined(GHASH_ASM_X86_64) && !defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_512AVX)
if (ctx->gcm_key.use_hw_gcm_crypt && crypto_gcm_avx512_enabled()) {
gcm_setiv_avx512(key, ctx, iv, len);
return;
Expand Down Expand Up @@ -621,7 +623,7 @@ int CRYPTO_gcm128_encrypt_ctr32(GCM128_CONTEXT *ctx, const AES_KEY *key,
ctx->ares = 0;
}

#if defined(GHASH_ASM_X86_64)
#if defined(GHASH_ASM_X86_64) && !defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_512AVX)
if (ctx->gcm_key.use_hw_gcm_crypt && crypto_gcm_avx512_enabled() && len > 0) {
aes_gcm_encrypt_avx512(key, ctx, &ctx->mres, in, len, out);
return 1;
Expand Down Expand Up @@ -715,7 +717,7 @@ int CRYPTO_gcm128_decrypt_ctr32(GCM128_CONTEXT *ctx, const AES_KEY *key,
ctx->ares = 0;
}

#if defined(GHASH_ASM_X86_64)
#if defined(GHASH_ASM_X86_64) && !defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_512AVX)
if (ctx->gcm_key.use_hw_gcm_crypt && crypto_gcm_avx512_enabled() && len > 0) {
aes_gcm_decrypt_avx512(key, ctx, &ctx->mres, in, len, out);
return 1;
Expand Down
2 changes: 2 additions & 0 deletions crypto/fipsmodule/modes/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,12 @@ void gcm_init_avx(u128 Htable[16], const uint64_t Xi[2]);
void gcm_gmult_avx(uint8_t Xi[16], const u128 Htable[16]);
void gcm_ghash_avx(uint8_t Xi[16], const u128 Htable[16], const uint8_t *in,
size_t len);
#if !defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_512AVX)
void gcm_init_avx512(u128 Htable[16], const uint64_t Xi[2]);
void gcm_gmult_avx512(uint8_t Xi[2], const u128 Htable[16]);
void gcm_ghash_avx512(uint8_t Xi[2], const u128 Htable[16], const uint8_t *in,
size_t len);
#endif
#define HW_GCM
size_t aesni_gcm_encrypt(const uint8_t *in, uint8_t *out, size_t len,
const AES_KEY *key, uint8_t ivec[16],
Expand Down

0 comments on commit 9d4d510

Please sign in to comment.