Botan 3.13.0
Crypto and TLS for C&
polyval.h
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#ifndef BOTAN_POLYVAL_H_
8#define BOTAN_POLYVAL_H_
9
10#include <botan/sym_algo.h>
11#include <botan/internal/alignment_buffer.h>
12
13namespace Botan {
14
15/**
16* POLYVAL universal hash (RFC 8452), used by AES-GCM-SIV
17*
18* This is not a secure MAC; it must only be used as a component of a
19* construction (like GCM-SIV) which encrypts its output.
20*/
22 private:
23 static constexpr size_t BS = 16;
24
25 public:
26 void update(std::span<const uint8_t> input);
27
28 /// Zero pad the input to a multiple of the block size
29 void zero_pad();
30
31 /// Write the current state to out, and reset the state
32 void final(std::span<uint8_t, BS> out);
33
35
36 bool has_keying_material() const override;
37
38 void clear() override;
39
40 std::string name() const override { return "Polyval"; }
41
42 std::string provider() const;
43
44 private:
45 void key_schedule(std::span<const uint8_t> key) override;
46
47 void polyval_multiply(std::span<uint8_t, BS> x, std::span<const uint8_t> input, size_t blocks);
48
49#if defined(BOTAN_HAS_GHASH_CLMUL_CPU)
50 static void polyval_precompute_cpu(const uint8_t H[16], secure_vector<uint64_t>& H_pow);
51
52 static void polyval_multiply_cpu(uint8_t x[16],
54 const uint8_t input[],
55 size_t blocks);
56#endif
57
58#if defined(BOTAN_HAS_GHASH_AVX512_CLMUL)
59 static void polyval_precompute_avx512_clmul(const uint8_t H[16], uint64_t H_pow[16 * 2]);
60
61 static void polyval_multiply_avx512_clmul(uint8_t x[16],
62 const uint64_t H_pow[16 * 2],
63 const uint8_t input[],
64 size_t blocks);
65#endif
66
67 private:
69
70 /// hash state; in the GHASH byte order if the fallback path is in use
71 std::array<uint8_t, BS> m_state{};
72 secure_vector<uint64_t> m_HM;
73 secure_vector<uint64_t> m_H_pow;
74};
75
76} // namespace Botan
77
78#endif
#define BOTAN_TEST_API
Definition api.h:41
Alignment buffer helper.
void update(std::span< const uint8_t > input)
Definition polyval.cpp:101
std::string name() const override
Definition polyval.h:40
void zero_pad()
Zero pad the input to a multiple of the block size.
Definition polyval.cpp:119
Key_Length_Specification key_spec() const override
Definition polyval.h:34
void final(std::span< uint8_t, BS > out)
Write the current state to out, and reset the state.
Definition polyval.cpp:127
BOTAN_FORCE_INLINE SIMD_4x32 BOTAN_FN_ISA_CLMUL polyval_multiply(const SIMD_4x32 &H, const SIMD_4x32 &x)
Definition polyval_fn.h:150
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:128