Botan 3.14.1
Crypto and TLS for C&
hash_engine_keccak_avx512.cpp
Go to the documentation of this file.
1/*
2* (C) 2026 Jack Lloyd
3*
4* Botan is released under the Simplified BSD License (see license.txt)
5*/
6
7#include <botan/internal/hash_engine_keccak.h>
8
9#include <botan/assert.h>
10#include <botan/internal/isa_extn.h>
11#include <botan/internal/keccak_perm_round.h>
12#include <botan/internal/loadstor.h>
13#include <botan/internal/simd_8x64.h>
14
15namespace Botan {
16
17namespace {} // namespace
18
19BOTAN_FN_ISA_SIMD_8X64 void keccak_mb_permute_x8(uint64_t* states) {
20 SIMD_8x64 A[25];
21 SIMD_8x64 T[25];
22
23 for(size_t w = 0; w != 25; ++w) {
24 A[w] = SIMD_8x64::load_le(states + 8 * w);
25 }
26
27 for(size_t i = 0; i != 24; i += 2) {
30 }
31
32 for(size_t w = 0; w != 25; ++w) {
33 A[w].store_le(states + 8 * w);
34 }
35}
36
37BOTAN_FN_ISA_SIMD_8X64 void keccak_mb_absorb_x8(uint64_t* states,
38 const uint8_t* const* blocks,
39 size_t rate_words,
40 size_t nblocks) {
41 SIMD_8x64 A[25];
42 SIMD_8x64 T[25];
43
44 for(size_t w = 0; w != 25; ++w) {
45 A[w] = SIMD_8x64::load_le(states + 8 * w);
46 }
47
48 // The whole strip is staged into word-major lane order with scalar
49 // loads and stores first; unlike an unpack based transpose these do
50 // not compete with the permutation for the vector ports
51 BOTAN_ASSERT_NOMSG(nblocks <= KECCAK_MB_ABSORB_BLOCKS && rate_words <= 25);
52
53 alignas(64) uint64_t staged[KECCAK_MB_ABSORB_BLOCKS * 25 * 8];
54 for(size_t b = 0; b != nblocks; ++b) {
55 for(size_t l = 0; l != 8; ++l) {
56 const uint8_t* src = blocks[8 * b + l];
57 for(size_t w = 0; w != rate_words; ++w) {
58 staged[(b * rate_words + w) * 8 + l] = load_le<uint64_t>(src, w);
59 }
60 }
61 }
62
63 for(size_t b = 0; b != nblocks; ++b) {
64 for(size_t w = 0; w != rate_words; ++w) {
65 A[w] ^= SIMD_8x64::load_le(staged + (b * rate_words + w) * 8);
66 }
67
68 for(size_t i = 0; i != 24; i += 2) {
71 }
72 }
73
74 for(size_t w = 0; w != 25; ++w) {
75 A[w].store_le(states + 8 * w);
76 }
77}
78
79} // namespace Botan
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:82
void store_le(uint64_t out[8]) const
Definition simd_8x64.h:82
static BOTAN_FN_ISA_SIMD_8X64 SIMD_8x64 load_le(const void *in)
Definition simd_8x64.h:51
BOTAN_FN_ISA_SIMD_8X64 void keccak_mb_absorb_x8(uint64_t *states, const uint8_t *const *blocks, size_t rate_words, size_t nblocks)
BOTAN_FORCE_INLINE void Keccak_Permutation_round(W T[25], const W A[25], uint64_t RC)
constexpr uint64_t KECCAK_RC[24]
constexpr size_t KECCAK_MB_ABSORB_BLOCKS
constexpr auto load_le(ParamTs &&... params)
Definition loadstor.h:495
BOTAN_FN_ISA_SIMD_8X64 void keccak_mb_permute_x8(uint64_t *states)