Skip to content

Commit 9761b07

Browse files
committed
Add Optimized and HOL Light verified AVX2 Keccak x4
1 parent 741d90d commit 9761b07

4 files changed

Lines changed: 718 additions & 0 deletions

File tree

crypto/fipsmodule/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,14 @@ if(ARCH STREQUAL "aarch64")
342342
)
343343
endif()
344344

345+
if((ARCH STREQUAL "x86_64") AND UNIX AND NOT MY_ASSEMBLER_IS_TOO_OLD_FOR_AVX)
346+
set(S2N_BIGNUM_INCLUDE_DIR "${AWSLC_SOURCE_DIR}/third_party/s2n-bignum/s2n-bignum-imported/include")
347+
list(APPEND BCM_ASM_SOURCES
348+
${AWSLC_SOURCE_DIR}/third_party/s2n-bignum/s2n-bignum-to-be-imported/x86/sha3/sha3_keccak4_f1600_alt.S
349+
)
350+
endif()
351+
352+
345353
# mlkem-native assembly files can be compiled on Unix platforms for x86_64 and arm64 only.
346354
if((ARCH STREQUAL "aarch64") AND UNIX)
347355

crypto/fipsmodule/sha/keccak1600.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ static const uint64_t iotas[] = {
3939
0x8000000080008008ULL
4040
};
4141

42+
#if defined(OPENSSL_X86_64)
43+
static const uint64_t keccak_rho8[4] = {
44+
0x0605040302010007ULL, 0x0E0D0C0B0A09080FULL,
45+
0x0605040302010007ULL, 0x0E0D0C0B0A09080FULL
46+
};
47+
48+
static const uint64_t keccak_rho56[4] = {
49+
0x0007060504030201ULL, 0x080F0E0D0C0B0A09ULL,
50+
0x0007060504030201ULL, 0x080F0E0D0C0B0A09ULL
51+
};
52+
#endif
53+
4254
#if !defined(KECCAK1600_ASM)
4355

4456
static const uint8_t rhotates[KECCAK1600_ROWS][KECCAK1600_ROWS] = {
@@ -449,6 +461,13 @@ static void Keccak1600_x4(uint64_t A[4][KECCAK1600_ROWS][KECCAK1600_ROWS]) {
449461
#endif
450462
#endif
451463

464+
#if defined(KECCAK1600_S2N_BIGNUM_ASM) && defined(OPENSSL_X86_64)
465+
if (CRYPTO_is_AVX2_capable()) {
466+
sha3_keccak4_f1600_alt((uint64_t *)A, iotas, keccak_rho8, keccak_rho56);
467+
return;
468+
}
469+
#endif
470+
452471
// Fallback: 4x individual KeccakF1600 calls (each with their own dispatch)
453472
KeccakF1600(A[0]);
454473
KeccakF1600(A[1]);

third_party/s2n-bignum/s2n-bignum-imported/include/s2n-bignum.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,11 @@ extern void sha3_keccak2_f1600_alt(uint64_t a[S2N_BIGNUM_STATIC 50],const uint64
11161116
// Batched 4-way Keccak-f1600 permutation for SHA3
11171117
// Inputs a[100], rc[24]; output a[100]
11181118
extern void sha3_keccak4_f1600(uint64_t a[S2N_BIGNUM_STATIC 100],const uint64_t rc[S2N_BIGNUM_STATIC 24]);
1119+
#ifdef __x86_64__
1120+
extern void sha3_keccak4_f1600_alt(uint64_t a[S2N_BIGNUM_STATIC 100],const uint64_t rc[S2N_BIGNUM_STATIC 24],const uint64_t rho8[S2N_BIGNUM_STATIC 4],const uint64_t rho56[S2N_BIGNUM_STATIC 4]);
1121+
#else
11191122
extern void sha3_keccak4_f1600_alt(uint64_t a[S2N_BIGNUM_STATIC 100],const uint64_t rc[S2N_BIGNUM_STATIC 24]);
1123+
#endif
11201124
extern void sha3_keccak4_f1600_alt2(uint64_t a[S2N_BIGNUM_STATIC 100],const uint64_t rc[S2N_BIGNUM_STATIC 24]);
11211125

11221126
// Point addition on CC curve SM2 in Montgomery-Jacobian coordinates

0 commit comments

Comments
 (0)