Botan 3.13.0
Crypto and TLS for C&
Botan::Polyval Class Referencefinal

#include <polyval.h>

Inheritance diagram for Botan::Polyval:
Botan::SymmetricAlgorithm

Public Member Functions

void clear () override
void final (std::span< uint8_t, BS > out)
 Write the current state to out, and reset the state.
bool has_keying_material () const override
Key_Length_Specification key_spec () const override
size_t maximum_keylength () const
size_t minimum_keylength () const
std::string name () const override
std::string provider () const
void set_key (const OctetString &key)
void set_key (const uint8_t key[], size_t length)
void set_key (std::span< const uint8_t > key)
void update (std::span< const uint8_t > input)
bool valid_keylength (size_t length) const
void zero_pad ()
 Zero pad the input to a multiple of the block size.

Protected Member Functions

void assert_key_material_set () const
void assert_key_material_set (bool predicate) const

Detailed Description

POLYVAL universal hash (RFC 8452), used by AES-GCM-SIV

This is not a secure MAC; it must only be used as a component of a construction (like GCM-SIV) which encrypts its output.

Definition at line 21 of file polyval.h.

Member Function Documentation

◆ assert_key_material_set() [1/2]

◆ assert_key_material_set() [2/2]

void Botan::SymmetricAlgorithm::assert_key_material_set ( bool predicate) const
inlineprotectedinherited

Throw Key_Not_Set unless the predicate holds

Parameters
predicateif false, a Key_Not_Set exception is thrown

Definition at line 186 of file sym_algo.h.

186 {
187 if(!predicate) {
188 throw_key_not_set_error();
189 }
190 }

◆ clear()

void Botan::Polyval::clear ( )
overridevirtual

Reset the internal state. This includes not just the key, but any partial message that may have been in process.

Implements Botan::SymmetricAlgorithm.

Definition at line 141 of file polyval.cpp.

141 {
142 zap(m_HM);
143 zap(m_H_pow);
144 secure_scrub_memory(m_state);
145 m_buffer.clear();
146}
void zap(std::vector< T, Alloc > &vec)
Definition secmem.h:261
void secure_scrub_memory(void *ptr, size_t n)
Definition mem_utils.cpp:25

References Botan::secure_scrub_memory(), and Botan::zap().

◆ final()

void Botan::Polyval::final ( std::span< uint8_t, BS > out)

Write the current state to out, and reset the state.

Definition at line 127 of file polyval.cpp.

127 {
129 BOTAN_STATE_CHECK(m_buffer.in_alignment());
130
131 if(m_H_pow.empty()) {
132 // Fallback path; the state is in the GHASH byte order
133 copy_mem(out, byte_reverse(m_state));
134 } else {
135 copy_mem(out, m_state);
136 }
137
138 secure_scrub_memory(m_state);
139}
#define BOTAN_STATE_CHECK(expr)
Definition assert.h:49
constexpr void copy_mem(T *out, const T *in, size_t n)
Definition mem_ops.h:144

References Botan::SymmetricAlgorithm::assert_key_material_set(), BOTAN_STATE_CHECK, Botan::copy_mem(), and Botan::secure_scrub_memory().

◆ has_keying_material()

bool Botan::Polyval::has_keying_material ( ) const
overridevirtual

Test whether a key has been set on this object

Returns
true if a key has been set on this object

Implements Botan::SymmetricAlgorithm.

Definition at line 51 of file polyval.cpp.

51 {
52 return !m_HM.empty() || !m_H_pow.empty();
53}

◆ key_spec()

Key_Length_Specification Botan::Polyval::key_spec ( ) const
inlineoverridevirtual

Return the key lengths supported by this algorithm

Returns
object describing limits on key size

Implements Botan::SymmetricAlgorithm.

Definition at line 34 of file polyval.h.

34{ return Key_Length_Specification(BS); }

◆ maximum_keylength()

size_t Botan::SymmetricAlgorithm::maximum_keylength ( ) const
inlineinherited

Return the largest acceptable key length

Returns
maximum allowed key length

Definition at line 130 of file sym_algo.h.

130{ return key_spec().maximum_keylength(); }
size_t maximum_keylength() const
Definition sym_algo.h:58
virtual Key_Length_Specification key_spec() const =0

References key_spec().

◆ minimum_keylength()

size_t Botan::SymmetricAlgorithm::minimum_keylength ( ) const
inlineinherited

Return the smallest acceptable key length

Returns
minimum allowed key length

Definition at line 136 of file sym_algo.h.

136{ return key_spec().minimum_keylength(); }
size_t minimum_keylength() const
Definition sym_algo.h:52

References key_spec().

◆ name()

std::string Botan::Polyval::name ( ) const
inlineoverridevirtual

Return the name of this algorithm

Returns
the algorithm name

Implements Botan::SymmetricAlgorithm.

Definition at line 40 of file polyval.h.

40{ return "Polyval"; }

◆ provider()

std::string Botan::Polyval::provider ( ) const

Definition at line 29 of file polyval.cpp.

29 {
30#if defined(BOTAN_HAS_GHASH_AVX512_CLMUL)
32 return *feat;
33 }
34#endif
35
36#if defined(BOTAN_HAS_GHASH_CLMUL_CPU)
37 if(auto feat = CPUID::check(CPUID::Feature::HW_CLMUL)) {
38 return *feat;
39 }
40#endif
41
42#if defined(BOTAN_HAS_GHASH_CLMUL_VPERM)
44 return *feat;
45 }
46#endif
47
48 return "base";
49}
static std::optional< std::string > check(CPUID::Feature feat)
Definition cpuid.h:67

References Botan::CPUFeature::AVX512_CLMUL, Botan::CPUID::check(), Botan::CPUFeature::HW_CLMUL, and Botan::CPUFeature::SIMD_4X32.

◆ set_key() [1/3]

◆ set_key() [2/3]

void Botan::SymmetricAlgorithm::set_key ( const uint8_t key[],
size_t length )
inlineinherited

Set the symmetric key of this object.

Parameters
keythe to be set as a byte array.
lengthin bytes of key param

Definition at line 162 of file sym_algo.h.

162{ set_key(std::span{key, length}); }

References set_key().

Referenced by set_key().

◆ set_key() [3/3]

void Botan::SymmetricAlgorithm::set_key ( std::span< const uint8_t > key)
inherited

Set the symmetric key of this object.

Parameters
keythe contiguous byte range to be set.

Definition at line 22 of file sym_algo.cpp.

22 {
23 if(!valid_keylength(key.size())) {
24 throw Invalid_Key_Length(name(), key.size());
25 }
26 key_schedule(key);
27}
bool valid_keylength(size_t length) const
Definition sym_algo.h:143
virtual std::string name() const =0

References name(), and valid_keylength().

◆ update()

void Botan::Polyval::update ( std::span< const uint8_t > input)

Definition at line 101 of file polyval.cpp.

101 {
103 BufferSlicer in(input);
104 while(!in.empty()) {
105 if(const auto one_block = m_buffer.handle_unaligned_data(in)) {
106 polyval_multiply(m_state, one_block.value(), 1);
107 }
108
109 if(m_buffer.in_alignment()) {
110 const auto [aligned_data, full_blocks] = m_buffer.aligned_data_to_process(in);
111 if(full_blocks > 0) {
112 polyval_multiply(m_state, aligned_data, full_blocks);
113 }
114 }
115 }
116 BOTAN_ASSERT_NOMSG(in.empty());
117}
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:75

References Botan::SymmetricAlgorithm::assert_key_material_set(), BOTAN_ASSERT_NOMSG, and Botan::BufferSlicer::empty().

◆ valid_keylength()

bool Botan::SymmetricAlgorithm::valid_keylength ( size_t length) const
inlineinherited

Check whether a given key length is valid for this algorithm.

Parameters
lengththe key length to be checked.
Returns
true if the key length is valid.

Definition at line 143 of file sym_algo.h.

143{ return key_spec().valid_keylength(length); }
bool valid_keylength(size_t length) const
Definition sym_algo.h:44

References key_spec().

Referenced by set_key().

◆ zero_pad()

void Botan::Polyval::zero_pad ( )

Zero pad the input to a multiple of the block size.

Definition at line 119 of file polyval.cpp.

119 {
121 if(!m_buffer.in_alignment()) {
122 m_buffer.fill_up_with_zeros();
123 polyval_multiply(m_state, m_buffer.consume(), 1);
124 }
125}

References Botan::SymmetricAlgorithm::assert_key_material_set().


The documentation for this class was generated from the following files: