Botan 3.14.1
Crypto and TLS for C&
hash_engine_keccak_avx2.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/internal/isa_extn.h>
10#include <botan/internal/keccak_perm_round.h>
11#include <botan/internal/simd_4x64.h>
12
13namespace Botan {
14
15namespace {
16
17BOTAN_FN_ISA_SIMD_4X64 BOTAN_FORCE_INLINE void absorb4(SIMD_4x64 A[25],
18 const uint8_t* const* blocks,
19 size_t w0,
20 size_t skip) {
21 SIMD_4x64 M[4];
22 for(size_t l = 0; l != 4; ++l) {
23 M[l] = SIMD_4x64::load_le(blocks[l] + 8 * w0);
24 }
25 SIMD_4x64::transpose(M[0], M[1], M[2], M[3]);
26 for(size_t w = skip; w != 4; ++w) {
27 A[w0 + w] ^= M[w];
28 }
29}
30
31/**
32* XOR one rate block of each lane into the state, transposing from the
33* per lane byte order into the word-major lane order. Any words past a
34* multiple of the group size are handled by a final group overlapping
35* the previous one, which requires rate_words >= 4 (the smallest rate,
36* SHA-3-512, has 9 words).
37*/
38BOTAN_FN_ISA_SIMD_4X64 BOTAN_FORCE_INLINE void absorb_block(SIMD_4x64 A[25],
39 const uint8_t* const* blocks,
40 size_t rate_words) {
41 size_t w = 0;
42 for(; w + 4 <= rate_words; w += 4) {
43 absorb4(A, blocks, w, 0);
44 }
45 if(w != rate_words) {
46 absorb4(A, blocks, rate_words - 4, 4 - (rate_words - w));
47 }
48}
49
50} // namespace
51
52BOTAN_FN_ISA_SIMD_4X64 void keccak_mb_permute_x4(uint64_t* states) {
53 SIMD_4x64 A[25];
54 SIMD_4x64 T[25];
55
56 for(size_t w = 0; w != 25; ++w) {
57 A[w] = SIMD_4x64::load_le(states + 4 * w);
58 }
59
60 for(size_t i = 0; i != 24; i += 2) {
63 }
64
65 for(size_t w = 0; w != 25; ++w) {
66 A[w].store_le(states + 4 * w);
67 }
68}
69
70BOTAN_FN_ISA_SIMD_4X64 void keccak_mb_absorb_x4(uint64_t* states,
71 const uint8_t* const* blocks,
72 size_t rate_words,
73 size_t nblocks) {
74 SIMD_4x64 A[25];
75 SIMD_4x64 T[25];
76
77 for(size_t w = 0; w != 25; ++w) {
78 A[w] = SIMD_4x64::load_le(states + 4 * w);
79 }
80
81 for(size_t b = 0; b != nblocks; ++b) {
82 absorb_block(A, blocks + 4 * b, rate_words);
83
84 for(size_t i = 0; i != 24; i += 2) {
87 }
88 }
89
90 for(size_t w = 0; w != 25; ++w) {
91 A[w].store_le(states + 4 * w);
92 }
93}
94
95} // namespace Botan
void BOTAN_FN_ISA_SIMD_4X64 store_le(uint64_t out[4]) const
Definition simd_4x64.h:72
static BOTAN_FN_ISA_SIMD_4X64 void transpose(SIMD_4x64 &B0, SIMD_4x64 &B1, SIMD_4x64 &B2, SIMD_4x64 &B3)
Definition simd_4x64.h:211
static BOTAN_FN_ISA_SIMD_4X64 SIMD_4x64 load_le(const void *in)
Definition simd_4x64.h:45
#define BOTAN_FORCE_INLINE
Definition compiler.h:86
BOTAN_FORCE_INLINE void Keccak_Permutation_round(W T[25], const W A[25], uint64_t RC)
BOTAN_FN_ISA_SIMD_4X64 void keccak_mb_absorb_x4(uint64_t *states, const uint8_t *const *blocks, size_t rate_words, size_t nblocks)
constexpr uint64_t KECCAK_RC[24]
BOTAN_FN_ISA_SIMD_4X64 void keccak_mb_permute_x4(uint64_t *states)