Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion crypto/chacha/chacha.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static void ChaCha20_ctr32(uint8_t *out, const uint8_t *in, size_t in_len,
return;
}
#endif
#if defined(CHACHA20_ASM_AVX2) && !defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_512AVX)
#if defined(CHACHA20_ASM_AVX2)
if (ChaCha20_ctr32_avx2_capable(in_len)) {
ChaCha20_ctr32_avx2(out, in, in_len, key, counter);
return;
Expand Down Expand Up @@ -245,3 +245,15 @@ void CRYPTO_chacha_20(uint8_t *out, const uint8_t *in, size_t in_len,
}

#endif

#if defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_512AVX)

#if defined(CHACHA20_ASM_AVX2)
void ChaCha20_ctr32_avx2(uint8_t *out, const uint8_t *in, size_t in_len,
const uint32_t key[8], const uint32_t counter[4]) {
perror("ChaCha20_ctr32_avx2");
abort();
}
#endif // defined(CHACHA20_ASM_AVX2)

#endif // defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_512AVX)
2 changes: 1 addition & 1 deletion crypto/chacha/chacha_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ static void check_abi(uint8_t *out, const uint8_t *in, size_t in_len,
CHECK_ABI(ChaCha20_ctr32_neon, out, in, in_len, key, counter);
}
#endif
#if defined(CHACHA20_ASM_AVX2) && !defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_512AVX)
#if defined(CHACHA20_ASM_AVX2)
if (ChaCha20_ctr32_avx2_capable(in_len)) {
CHECK_ABI(ChaCha20_ctr32_avx2, out, in, in_len, key, counter);
}
Expand Down
3 changes: 3 additions & 0 deletions crypto/chacha/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ void ChaCha20_ctr32_neon(uint8_t *out, const uint8_t *in, size_t in_len,

#define CHACHA20_ASM_AVX2
OPENSSL_INLINE int ChaCha20_ctr32_avx2_capable(size_t len) {
#if defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_512AVX)
return 0;
#endif // defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_512AVX)
return len > 128 && CRYPTO_is_AVX2_capable();
}
void ChaCha20_ctr32_avx2(uint8_t *out, const uint8_t *in, size_t in_len,
Expand Down
18 changes: 18 additions & 0 deletions crypto/fipsmodule/sha/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ void sha1_block_data_order_ssse3(uint32_t state[5], const uint8_t *data,

#define SHA1_ASM_AVX
OPENSSL_INLINE int sha1_avx_capable(void) {
#if defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_AVX)
return 0;
#endif // defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_AVX)
// Pre-Zen AMD CPUs had slow SHLD/SHRD; Zen added the SHA extension; see the
// discussion in sha1-586.pl.
//
Expand All @@ -215,6 +218,9 @@ void sha256_block_data_order_ssse3(uint32_t state[8], const uint8_t *data,

#define SHA256_ASM_AVX
OPENSSL_INLINE int sha256_avx_capable(void) {
#if defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_AVX)
return 0;
#endif // defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_AVX)
// Pre-Zen AMD CPUs had slow SHLD/SHRD; Zen added the SHA extension; see the
// discussion in sha1-586.pl.
//
Expand Down Expand Up @@ -245,6 +251,9 @@ OPENSSL_INLINE int sha1_hw_capable(void) {

#define SHA1_ASM_AVX2
OPENSSL_INLINE int sha1_avx2_capable(void) {
#if defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_AVX)
return 0;
#endif // defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_AVX)
// TODO: Simplify this logic, which was extracted from the assembly:
// * Does AVX2 imply SSSE3?
// * sha1_block_data_order_avx2 does not seem to use SSSE3 instructions.
Expand All @@ -256,6 +265,9 @@ void sha1_block_data_order_avx2(uint32_t state[5], const uint8_t *data,

#define SHA1_ASM_AVX
OPENSSL_INLINE int sha1_avx_capable(void) {
#if defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_AVX)
return 0;
#endif // defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_AVX)
// TODO: Simplify this logic, which was extracted from the assembly:
// * Does AVX imply SSSE3?
// * sha1_block_data_order_avx does not seem to use SSSE3 instructions.
Expand All @@ -281,6 +293,9 @@ OPENSSL_INLINE int sha256_hw_capable(void) {

#define SHA256_ASM_AVX
OPENSSL_INLINE int sha256_avx_capable(void) {
#if defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_AVX)
return 0;
#endif // defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_AVX)
// TODO: Simplify this logic, which was extracted from the assembly:
// * Does AVX imply SSSE3?
// * sha256_block_data_order_avx does not seem to use SSSE3 instructions.
Expand All @@ -301,6 +316,9 @@ void sha256_block_data_order_ssse3(uint32_t state[8], const uint8_t *data,

#define SHA512_ASM_AVX
OPENSSL_INLINE int sha512_avx_capable(void) {
#if defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_AVX)
return 0;
#endif // defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_AVX)
// TODO: Simplify this logic, which was extracted from the assembly:
// * Does AVX imply SSSE3?
// * sha512_block_data_order_avx does not seem to use SSSE3 instructions.
Expand Down
24 changes: 22 additions & 2 deletions crypto/fipsmodule/sha/sha1.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,13 +396,13 @@ static void sha1_block_data_order(uint32_t state[5], const uint8_t *data,
return;
}
#endif
#if defined(SHA1_ASM_AVX2) && !defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_AVX)
#if defined(SHA1_ASM_AVX2)
if (sha1_avx2_capable()) {
sha1_block_data_order_avx2(state, data, num);
return;
}
#endif
#if defined(SHA1_ASM_AVX) && !defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_AVX)
#if defined(SHA1_ASM_AVX)
if (sha1_avx_capable()) {
sha1_block_data_order_avx(state, data, num);
return;
Expand Down Expand Up @@ -441,3 +441,23 @@ static void sha1_block_data_order(uint32_t state[5], const uint8_t *data,
#undef BODY_40_59
#undef BODY_60_79
#undef X

#if defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_512AVX)

#if defined(ASH1_ASM_AVX2)
void sha1_block_data_order_avx2(uint32_t state[5], const uint8_t *data,
size_t num) {
perror("sha1_block_data_order_avx2");
abort();
}
#endif // defined(ASH1_ASM_AVX2)

#if defined(SHA1_ASM_AVX)
void sha1_block_data_order_avx(uint32_t state[5], const uint8_t *data,
size_t num) {
perror("sha1_block_data_order_avx");
abort();
}
#endif // defined(SHA1_ASM_AVX)

#endif // defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_512AVX)
14 changes: 13 additions & 1 deletion crypto/fipsmodule/sha/sha256.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ static void sha256_block_data_order(uint32_t state[8], const uint8_t *data,
return;
}
#endif
#if defined(SHA256_ASM_AVX) && !defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_AVX)
#if defined(SHA256_ASM_AVX)
if (sha256_avx_capable()) {
sha256_block_data_order_avx(state, data, num);
return;
Expand Down Expand Up @@ -429,3 +429,15 @@ void SHA256_TransformBlocks(uint32_t state[8], const uint8_t *data,
#undef Maj
#undef ROUND_00_15
#undef ROUND_16_63

#if defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_AVX)

#if defined(SHA256_ASM_AVX)
void sha256_block_data_order_avx(uint32_t state[8], const uint8_t *data,
size_t num) {
perror("sha256_block_data_order_avx");
abort();
}
#endif // defined(SHA256_ASM_AVX)

#endif // defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_AVX)
14 changes: 13 additions & 1 deletion crypto/fipsmodule/sha/sha512.c
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ static void sha512_block_data_order(uint64_t state[8], const uint8_t *data,
return;
}
#endif
#if defined(SHA512_ASM_AVX) && !defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_AVX)
#if defined(SHA512_ASM_AVX)
if (sha512_avx_capable()) {
sha512_block_data_order_avx(state, data, num);
return;
Expand All @@ -714,3 +714,15 @@ static void sha512_block_data_order(uint64_t state[8], const uint8_t *data,
#undef Maj
#undef ROUND_00_15
#undef ROUND_16_80

#if defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_AVX)

#if defined(SHA512_ASM_AVX)
void sha512_block_data_order_avx(uint64_t state[8], const uint8_t *data,
size_t num) {
perror("sha512_block_data_order_avx");
abort();
}
#endif // defined(SHA512_ASM_AVX)

#endif // defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_AVX)
8 changes: 4 additions & 4 deletions crypto/fipsmodule/sha/sha_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ TEST(SHATest, SHA1ABI) {
CHECK_ABI(sha1_block_data_order_hw, ctx.h, kBuf, blocks);
}
#endif
#if defined(SHA1_ASM_AVX2) && !defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_AVX)
#if defined(SHA1_ASM_AVX2)
if (sha1_avx2_capable()) {
CHECK_ABI(sha1_block_data_order_avx2, ctx.h, kBuf, blocks);
}
#endif
#if defined(SHA1_ASM_AVX) && !defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_AVX)
#if defined(SHA1_ASM_AVX)
if (sha1_avx_capable()) {
CHECK_ABI(sha1_block_data_order_avx, ctx.h, kBuf, blocks);
}
Expand Down Expand Up @@ -76,7 +76,7 @@ TEST(SHATest, SHA256ABI) {
CHECK_ABI(sha256_block_data_order_hw, ctx.h, kBuf, blocks);
}
#endif
#if defined(SHA256_ASM_AVX) && !defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_AVX)
#if defined(SHA256_ASM_AVX)
if (sha256_avx_capable()) {
CHECK_ABI(sha256_block_data_order_avx, ctx.h, kBuf, blocks);
}
Expand Down Expand Up @@ -111,7 +111,7 @@ TEST(SHATest, SHA512ABI) {
CHECK_ABI(sha512_block_data_order_hw, ctx.h, kBuf, blocks);
}
#endif
#if defined(SHA512_ASM_AVX) && !defined(MY_ASSEMBLER_IS_TOO_OLD_FOR_AVX)
#if defined(SHA512_ASM_AVX)
if (sha512_avx_capable()) {
CHECK_ABI(sha512_block_data_order_avx, ctx.h, kBuf, blocks);
}
Expand Down
Loading