Botan 3.1.1
Crypto and TLS for C&
Public Member Functions | Static Public Member Functions | Protected Member Functions | Friends | List of all members
Botan::BLAKE2b Class Referencefinal

#include <blake2b.h>

Inheritance diagram for Botan::BLAKE2b:
Botan::HashFunction Botan::SymmetricAlgorithm Botan::Buffered_Computation

Public Member Functions

 BLAKE2b (size_t output_bits=512)
 
void clear () override
 
HashFunctionclone () const
 
std::unique_ptr< HashFunctioncopy_state () const override
 
template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
T final ()
 
void final (std::span< uint8_t > out)
 
template<concepts::resizable_byte_buffer T>
void final (T &out)
 
void final (uint8_t out[])
 
std::vector< uint8_t > final_stdvec ()
 
bool has_keying_material () const override
 
size_t hash_block_size () const override
 
size_t key_size () const
 
Key_Length_Specification key_spec () const override
 
size_t maximum_keylength () const
 
size_t minimum_keylength () const
 
std::string name () const override
 
std::unique_ptr< HashFunctionnew_object () const override
 
size_t output_length () const override
 
template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
T process (const uint8_t in[], size_t length)
 
template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
T process (std::span< const uint8_t > in)
 
template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
T process (std::string_view in)
 
virtual std::string provider () const
 
void set_key (const SymmetricKey &key)
 
void set_key (const uint8_t key[], size_t length)
 
void set_key (std::span< const uint8_t > key)
 
void update (const uint8_t in[], size_t length)
 
void update (std::span< const uint8_t > in)
 
void update (std::string_view str)
 
void update (uint8_t in)
 
void update_be (uint16_t val)
 
void update_be (uint32_t val)
 
void update_be (uint64_t val)
 
void update_le (uint16_t val)
 
void update_le (uint32_t val)
 
void update_le (uint64_t val)
 
bool valid_keylength (size_t length) const
 

Static Public Member Functions

static std::unique_ptr< HashFunctioncreate (std::string_view algo_spec, std::string_view provider="")
 
static std::unique_ptr< HashFunctioncreate_or_throw (std::string_view algo_spec, std::string_view provider="")
 
static std::vector< std::string > providers (std::string_view algo_spec)
 

Protected Member Functions

void add_data (const uint8_t input[], size_t length) override
 
void assert_key_material_set () const
 
void assert_key_material_set (bool predicate) const
 
void final_result (uint8_t out[]) override
 
void key_schedule (const uint8_t key[], size_t length) override
 

Friends

class BLAKE2bMAC
 

Detailed Description

BLAKE2B

Definition at line 23 of file blake2b.h.

Constructor & Destructor Documentation

◆ BLAKE2b()

Botan::BLAKE2b::BLAKE2b ( size_t  output_bits = 512)
explicit
Parameters
output_bitsthe output size of BLAKE2b in bits

Definition at line 35 of file blake2b.cpp.

35 :
36 m_output_bits(output_bits),
37 m_buffer(BLAKE2B_BLOCKBYTES),
38 m_bufpos(0),
39 m_H(BLAKE2B_IVU64COUNT),
40 m_T(),
41 m_F(),
42 m_key_size(0) {
43 if(output_bits == 0 || output_bits > 512 || output_bits % 8 != 0) {
44 throw Invalid_Argument("Bad output bits size for BLAKE2b");
45 }
46
47 state_init();
48}

Member Function Documentation

◆ add_data()

void Botan::BLAKE2b::add_data ( const uint8_t  input[],
size_t  length 
)
overrideprotectedvirtual

Add more data to the computation

Parameters
inputis an input buffer
lengthis the length of input in bytes

Implements Botan::Buffered_Computation.

Definition at line 151 of file blake2b.cpp.

151 {
152 if(length == 0) {
153 return;
154 }
155
156 if(m_bufpos > 0) {
157 if(m_bufpos < BLAKE2B_BLOCKBYTES) {
158 const size_t take = std::min(BLAKE2B_BLOCKBYTES - m_bufpos, length);
159 copy_mem(&m_buffer[m_bufpos], input, take);
160 m_bufpos += take;
161 length -= take;
162 input += take;
163 }
164
165 if(m_bufpos == m_buffer.size() && length > 0) {
166 compress(m_buffer.data(), 1, BLAKE2B_BLOCKBYTES);
167 m_bufpos = 0;
168 }
169 }
170
171 if(length > BLAKE2B_BLOCKBYTES) {
172 const size_t full_blocks = ((length - 1) / BLAKE2B_BLOCKBYTES);
173 compress(input, full_blocks, BLAKE2B_BLOCKBYTES);
174
175 input += full_blocks * BLAKE2B_BLOCKBYTES;
176 length -= full_blocks * BLAKE2B_BLOCKBYTES;
177 }
178
179 if(length > 0) {
180 copy_mem(&m_buffer[m_bufpos], input, length);
181 m_bufpos += length;
182 }
183}
constexpr void copy_mem(T *out, const T *in, size_t n)
Definition: mem_ops.h:120

References Botan::copy_mem().

◆ assert_key_material_set() [1/2]

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

Definition at line 139 of file sym_algo.h.

virtual bool has_keying_material() const =0
void assert_key_material_set() const
Definition: sym_algo.h:139

References Botan::SymmetricAlgorithm::assert_key_material_set().

Referenced by Botan::SymmetricAlgorithm::assert_key_material_set(), Botan::Salsa20::cipher_bytes(), Botan::AES_128::decrypt_n(), Botan::AES_192::decrypt_n(), Botan::AES_256::decrypt_n(), Botan::ARIA_128::decrypt_n(), Botan::ARIA_192::decrypt_n(), Botan::ARIA_256::decrypt_n(), Botan::Blowfish::decrypt_n(), Botan::Camellia_128::decrypt_n(), Botan::Camellia_192::decrypt_n(), Botan::Camellia_256::decrypt_n(), Botan::CAST_128::decrypt_n(), Botan::DES::decrypt_n(), Botan::TripleDES::decrypt_n(), Botan::GOST_28147_89::decrypt_n(), Botan::IDEA::decrypt_n(), Botan::Lion::decrypt_n(), Botan::Noekeon::decrypt_n(), Botan::SEED::decrypt_n(), Botan::Serpent::decrypt_n(), Botan::SHACAL2::decrypt_n(), Botan::SM4::decrypt_n(), Botan::Threefish_512::decrypt_n(), Botan::Twofish::decrypt_n(), Botan::AES_128::encrypt_n(), Botan::AES_192::encrypt_n(), Botan::AES_256::encrypt_n(), Botan::ARIA_128::encrypt_n(), Botan::ARIA_192::encrypt_n(), Botan::ARIA_256::encrypt_n(), Botan::Blowfish::encrypt_n(), Botan::Camellia_128::encrypt_n(), Botan::Camellia_192::encrypt_n(), Botan::Camellia_256::encrypt_n(), Botan::CAST_128::encrypt_n(), Botan::DES::encrypt_n(), Botan::TripleDES::encrypt_n(), Botan::GOST_28147_89::encrypt_n(), Botan::IDEA::encrypt_n(), Botan::Lion::encrypt_n(), Botan::Noekeon::encrypt_n(), Botan::SEED::encrypt_n(), Botan::Serpent::encrypt_n(), Botan::SHACAL2::encrypt_n(), Botan::SM4::encrypt_n(), Botan::Threefish_512::encrypt_n(), Botan::Twofish::encrypt_n(), Botan::GHASH::final(), Botan::GHASH::ghash_update(), Botan::ChaCha::seek(), Botan::CTR_BE::seek(), Botan::Salsa20::seek(), Botan::OCB_Mode::set_associated_data_n(), Botan::Salsa20::set_iv_bytes(), Botan::GHASH::update(), and Botan::GHASH::update_associated_data().

◆ assert_key_material_set() [2/2]

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

Definition at line 141 of file sym_algo.h.

141 {
142 if(!predicate)
143 throw_key_not_set_error();
144 }

◆ clear()

void Botan::BLAKE2b::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 230 of file blake2b.cpp.

230 {
231 zeroise(m_H);
232 zeroise(m_buffer);
233 zeroise(m_padded_key_buffer);
234 m_bufpos = 0;
235 m_key_size = 0;
236 state_init();
237}
void zeroise(std::vector< T, Alloc > &vec)
Definition: secmem.h:108

References Botan::zeroise().

Referenced by Botan::BLAKE2bMAC::clear().

◆ clone()

HashFunction * Botan::HashFunction::clone ( ) const
inlineinherited
Returns
new object representing the same algorithm as *this

Definition at line 87 of file hash.h.

87{ return this->new_object().release(); }
virtual std::unique_ptr< HashFunction > new_object() const =0

◆ copy_state()

std::unique_ptr< HashFunction > Botan::BLAKE2b::copy_state ( ) const
overridevirtual

Return a new hash object with the same state as *this. This allows computing the hash of several messages with a common prefix more efficiently than would otherwise be possible.

This function should be called clone but that was already used for the case of returning an uninitialized object.

Returns
new hash object

Implements Botan::HashFunction.

Definition at line 207 of file blake2b.cpp.

207 {
208 return std::make_unique<BLAKE2b>(*this);
209}

◆ create()

std::unique_ptr< HashFunction > Botan::HashFunction::create ( std::string_view  algo_spec,
std::string_view  provider = "" 
)
staticinherited

Create an instance based on a name, or return null if the algo/provider combination cannot be found. If provider is empty then best available is chosen.

Definition at line 103 of file hash.cpp.

103 {
104#if defined(BOTAN_HAS_COMMONCRYPTO)
105 if(provider.empty() || provider == "commoncrypto") {
106 if(auto hash = make_commoncrypto_hash(algo_spec))
107 return hash;
108
109 if(!provider.empty())
110 return nullptr;
111 }
112#endif
113
114 if(provider.empty() == false && provider != "base") {
115 return nullptr; // unknown provider
116 }
117
118#if defined(BOTAN_HAS_SHA1)
119 if(algo_spec == "SHA-1") {
120 return std::make_unique<SHA_1>();
121 }
122#endif
123
124#if defined(BOTAN_HAS_SHA2_32)
125 if(algo_spec == "SHA-224") {
126 return std::make_unique<SHA_224>();
127 }
128
129 if(algo_spec == "SHA-256") {
130 return std::make_unique<SHA_256>();
131 }
132#endif
133
134#if defined(BOTAN_HAS_SHA2_64)
135 if(algo_spec == "SHA-384") {
136 return std::make_unique<SHA_384>();
137 }
138
139 if(algo_spec == "SHA-512") {
140 return std::make_unique<SHA_512>();
141 }
142
143 if(algo_spec == "SHA-512-256") {
144 return std::make_unique<SHA_512_256>();
145 }
146#endif
147
148#if defined(BOTAN_HAS_RIPEMD_160)
149 if(algo_spec == "RIPEMD-160") {
150 return std::make_unique<RIPEMD_160>();
151 }
152#endif
153
154#if defined(BOTAN_HAS_WHIRLPOOL)
155 if(algo_spec == "Whirlpool") {
156 return std::make_unique<Whirlpool>();
157 }
158#endif
159
160#if defined(BOTAN_HAS_MD5)
161 if(algo_spec == "MD5") {
162 return std::make_unique<MD5>();
163 }
164#endif
165
166#if defined(BOTAN_HAS_MD4)
167 if(algo_spec == "MD4") {
168 return std::make_unique<MD4>();
169 }
170#endif
171
172#if defined(BOTAN_HAS_GOST_34_11)
173 if(algo_spec == "GOST-R-34.11-94" || algo_spec == "GOST-34.11") {
174 return std::make_unique<GOST_34_11>();
175 }
176#endif
177
178#if defined(BOTAN_HAS_ADLER32)
179 if(algo_spec == "Adler32") {
180 return std::make_unique<Adler32>();
181 }
182#endif
183
184#if defined(BOTAN_HAS_CRC24)
185 if(algo_spec == "CRC24") {
186 return std::make_unique<CRC24>();
187 }
188#endif
189
190#if defined(BOTAN_HAS_CRC32)
191 if(algo_spec == "CRC32") {
192 return std::make_unique<CRC32>();
193 }
194#endif
195
196#if defined(BOTAN_HAS_STREEBOG)
197 if(algo_spec == "Streebog-256") {
198 return std::make_unique<Streebog>(256);
199 }
200 if(algo_spec == "Streebog-512") {
201 return std::make_unique<Streebog>(512);
202 }
203#endif
204
205#if defined(BOTAN_HAS_SM3)
206 if(algo_spec == "SM3") {
207 return std::make_unique<SM3>();
208 }
209#endif
210
211 const SCAN_Name req(algo_spec);
212
213#if defined(BOTAN_HAS_SKEIN_512)
214 if(req.algo_name() == "Skein-512") {
215 return std::make_unique<Skein_512>(req.arg_as_integer(0, 512), req.arg(1, ""));
216 }
217#endif
218
219#if defined(BOTAN_HAS_BLAKE2B)
220 if(req.algo_name() == "Blake2b" || req.algo_name() == "BLAKE2b") {
221 return std::make_unique<BLAKE2b>(req.arg_as_integer(0, 512));
222 }
223#endif
224
225#if defined(BOTAN_HAS_KECCAK)
226 if(req.algo_name() == "Keccak-1600") {
227 return std::make_unique<Keccak_1600>(req.arg_as_integer(0, 512));
228 }
229#endif
230
231#if defined(BOTAN_HAS_SHA3)
232 if(req.algo_name() == "SHA-3") {
233 return std::make_unique<SHA_3>(req.arg_as_integer(0, 512));
234 }
235#endif
236
237#if defined(BOTAN_HAS_SHAKE)
238 if(req.algo_name() == "SHAKE-128" && req.arg_count() == 1) {
239 return std::make_unique<SHAKE_128>(req.arg_as_integer(0));
240 }
241 if(req.algo_name() == "SHAKE-256" && req.arg_count() == 1) {
242 return std::make_unique<SHAKE_256>(req.arg_as_integer(0));
243 }
244#endif
245
246#if defined(BOTAN_HAS_PARALLEL_HASH)
247 if(req.algo_name() == "Parallel") {
248 std::vector<std::unique_ptr<HashFunction>> hashes;
249
250 for(size_t i = 0; i != req.arg_count(); ++i) {
251 auto h = HashFunction::create(req.arg(i));
252 if(!h) {
253 return nullptr;
254 }
255 hashes.push_back(std::move(h));
256 }
257
258 return std::make_unique<Parallel>(hashes);
259 }
260#endif
261
262#if defined(BOTAN_HAS_TRUNCATED_HASH)
263 if(req.algo_name() == "Truncated" && req.arg_count() == 2) {
264 auto hash = HashFunction::create(req.arg(0));
265 if(!hash) {
266 return nullptr;
267 }
268
269 return std::make_unique<Truncated_Hash>(std::move(hash), req.arg_as_integer(1));
270 }
271#endif
272
273#if defined(BOTAN_HAS_COMB4P)
274 if(req.algo_name() == "Comb4P" && req.arg_count() == 2) {
275 auto h1 = HashFunction::create(req.arg(0));
276 auto h2 = HashFunction::create(req.arg(1));
277
278 if(h1 && h2) {
279 return std::make_unique<Comb4P>(std::move(h1), std::move(h2));
280 }
281 }
282#endif
283
284 return nullptr;
285}
virtual std::string provider() const
Definition: hash.h:49
static std::unique_ptr< HashFunction > create(std::string_view algo_spec, std::string_view provider="")
Definition: hash.cpp:103
std::unique_ptr< HashFunction > make_commoncrypto_hash(std::string_view name)

References Botan::SCAN_Name::algo_name(), Botan::SCAN_Name::arg(), Botan::SCAN_Name::arg_as_integer(), Botan::SCAN_Name::arg_count(), Botan::HashFunction::create(), Botan::make_commoncrypto_hash(), and Botan::HashFunction::provider().

Referenced by botan_hash_init(), Botan::EME::create(), Botan::EMSA::create(), Botan::BlockCipher::create(), Botan::HashFunction::create(), Botan::KDF::create(), Botan::MessageAuthenticationCode::create(), Botan::PBKDF::create(), Botan::PasswordHashFamily::create(), Botan::HashFunction::create_or_throw(), Botan::Certificate_Store_In_Memory::find_cert_by_pubkey_sha1(), Botan::Certificate_Store_In_Memory::find_cert_by_raw_subject_dn_sha256(), and Botan::X942_PRF::kdf().

◆ create_or_throw()

std::unique_ptr< HashFunction > Botan::HashFunction::create_or_throw ( std::string_view  algo_spec,
std::string_view  provider = "" 
)
staticinherited

◆ final() [1/4]

template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
T Botan::Buffered_Computation::final ( )
inlineinherited

Complete the computation and retrieve the final result as a container of your choice.

Returns
a contiguous container holding the result

Definition at line 77 of file buf_comp.h.

77 {
78 T output(output_length());
79 final_result(output.data());
80 return output;
81 }
virtual size_t output_length() const =0
FE_25519 T
Definition: ge.cpp:34

References T.

◆ final() [2/4]

void Botan::Buffered_Computation::final ( std::span< uint8_t >  out)
inlineinherited

Definition at line 85 of file buf_comp.h.

85 {
86 BOTAN_ASSERT_NOMSG(out.size() >= output_length());
87 final_result(out.data());
88 }
#define BOTAN_ASSERT_NOMSG(expr)
Definition: assert.h:59

References BOTAN_ASSERT_NOMSG.

◆ final() [3/4]

template<concepts::resizable_byte_buffer T>
void Botan::Buffered_Computation::final ( T out)
inlineinherited

Definition at line 91 of file buf_comp.h.

91 {
92 out.resize(output_length());
93 final_result(out.data());
94 }

◆ final() [4/4]

void Botan::Buffered_Computation::final ( uint8_t  out[])
inlineinherited

Complete the computation and retrieve the final result.

Parameters
outThe byte array to be filled with the result. Must be of length output_length()

Definition at line 69 of file buf_comp.h.

69{ final_result(out); }

Referenced by Botan::ed25519_gen_keypair(), Botan::ed25519_sign(), Botan::ed25519_verify(), Botan::mgf1_mask(), Botan::pbkdf2(), Botan::Dilithium::Polynomial::poly_challenge(), Botan::Kyber_Modern_Symmetric_Primitives::PRF(), Botan::Sphincs_Hash_Functions_Sha2::PRF_msg(), Botan::Sphincs_Hash_Functions_Shake::PRF_msg(), and Botan::sm2_compute_za().

◆ final_result()

void Botan::BLAKE2b::final_result ( uint8_t  out[])
overrideprotectedvirtual

Write the final output to out

Parameters
outis an output buffer of output_length()

Implements Botan::Buffered_Computation.

Definition at line 185 of file blake2b.cpp.

185 {
186 if(m_bufpos != BLAKE2B_BLOCKBYTES) {
187 clear_mem(&m_buffer[m_bufpos], BLAKE2B_BLOCKBYTES - m_bufpos);
188 }
189 m_F[0] = 0xFFFFFFFFFFFFFFFF;
190 compress(m_buffer.data(), 1, m_bufpos);
191 copy_out_vec_le(output, output_length(), m_H);
192 state_init();
193}
size_t output_length() const override
Definition: blake2b.h:33
void copy_out_vec_le(uint8_t out[], size_t out_bytes, const std::vector< T, Alloc > &in)
Definition: loadstor.h:644
constexpr void clear_mem(T *ptr, size_t n)
Definition: mem_ops.h:109

References Botan::clear_mem(), Botan::copy_out_vec_le(), and output_length().

◆ final_stdvec()

std::vector< uint8_t > Botan::Buffered_Computation::final_stdvec ( )
inlineinherited

Definition at line 83 of file buf_comp.h.

83{ return final<std::vector<uint8_t>>(); }

◆ has_keying_material()

bool Botan::BLAKE2b::has_keying_material ( ) const
overridevirtual
Returns
true if a key has been set on this object

Implements Botan::SymmetricAlgorithm.

Definition at line 211 of file blake2b.cpp.

211 {
212 return m_key_size > 0;
213}

Referenced by Botan::BLAKE2bMAC::has_keying_material().

◆ hash_block_size()

size_t Botan::BLAKE2b::hash_block_size ( ) const
inlineoverridevirtual
Returns
hash block size as defined for this algorithm

Reimplemented from Botan::HashFunction.

Definition at line 31 of file blake2b.h.

31{ return 128; }

◆ key_schedule()

void Botan::BLAKE2b::key_schedule ( const uint8_t  key[],
size_t  length 
)
overrideprotectedvirtual

Run the key schedule

Parameters
keythe key
lengthof key

Implements Botan::SymmetricAlgorithm.

Definition at line 215 of file blake2b.cpp.

215 {
216 BOTAN_ASSERT_NOMSG(length <= m_buffer.size());
217
218 m_key_size = length;
219 m_padded_key_buffer.resize(m_buffer.size());
220
221 if(m_padded_key_buffer.size() > length) {
222 size_t padding = m_padded_key_buffer.size() - length;
223 clear_mem(m_padded_key_buffer.data() + length, padding);
224 }
225
226 copy_mem(m_padded_key_buffer.data(), key, length);
227 state_init();
228}

References BOTAN_ASSERT_NOMSG, Botan::clear_mem(), and Botan::copy_mem().

◆ key_size()

size_t Botan::BLAKE2b::key_size ( ) const
inline

Definition at line 35 of file blake2b.h.

35{ return m_key_size; }

◆ key_spec()

Key_Length_Specification Botan::BLAKE2b::key_spec ( ) const
overridevirtual
Returns
object describing limits on key size

Implements Botan::SymmetricAlgorithm.

Definition at line 195 of file blake2b.cpp.

195 {
196 return Key_Length_Specification(1, 64);
197}

Referenced by Botan::BLAKE2bMAC::key_spec().

◆ maximum_keylength()

size_t Botan::SymmetricAlgorithm::maximum_keylength ( ) const
inlineinherited
Returns
maximum allowed key length

Definition at line 95 of file sym_algo.h.

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

◆ minimum_keylength()

size_t Botan::SymmetricAlgorithm::minimum_keylength ( ) const
inlineinherited
Returns
minimum allowed key length

Definition at line 100 of file sym_algo.h.

100{ return key_spec().minimum_keylength(); }
size_t minimum_keylength() const
Definition: sym_algo.h:49

◆ name()

std::string Botan::BLAKE2b::name ( ) const
overridevirtual
Returns
the algorithm name

Implements Botan::SymmetricAlgorithm.

Definition at line 199 of file blake2b.cpp.

199 {
200 return fmt("BLAKE2b({})", m_output_bits);
201}
std::string fmt(std::string_view format, const T &... args)
Definition: fmt.h:53

References Botan::fmt().

Referenced by Botan::BLAKE2bMAC::name().

◆ new_object()

std::unique_ptr< HashFunction > Botan::BLAKE2b::new_object ( ) const
overridevirtual
Returns
new object representing the same algorithm as *this

Implements Botan::HashFunction.

Definition at line 203 of file blake2b.cpp.

203 {
204 return std::make_unique<BLAKE2b>(m_output_bits);
205}

◆ output_length()

size_t Botan::BLAKE2b::output_length ( ) const
inlineoverridevirtual
Returns
length of the output of this function in bytes

Implements Botan::Buffered_Computation.

Definition at line 33 of file blake2b.h.

33{ return m_output_bits / 8; }

Referenced by final_result(), Botan::BLAKE2bMAC::new_object(), and Botan::BLAKE2bMAC::output_length().

◆ process() [1/3]

template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
T Botan::Buffered_Computation::process ( const uint8_t  in[],
size_t  length 
)
inlineinherited

Update and finalize computation. Does the same as calling update() and final() consecutively.

Parameters
inthe input to process as a byte array
lengththe length of the byte array
Returns
the result of the call to final()

Definition at line 104 of file buf_comp.h.

104 {
105 update(in, length);
106 return final<T>();
107 }
int(* update)(CTX *, const void *, CC_LONG len)

References update.

Referenced by Botan::Dilithium_Symmetric_Primitives::CRH(), and Botan::Dilithium_Symmetric_Primitives::H().

◆ process() [2/3]

template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
T Botan::Buffered_Computation::process ( std::span< const uint8_t >  in)
inlineinherited

Update and finalize computation. Does the same as calling update() and final() consecutively.

Parameters
inthe input to process as a contiguous container
Returns
the result of the call to final()

Definition at line 128 of file buf_comp.h.

128 {
129 update(in);
130 return final<T>();
131 }

References update.

◆ process() [3/3]

template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
T Botan::Buffered_Computation::process ( std::string_view  in)
inlineinherited

Update and finalize computation. Does the same as calling update() and final() consecutively.

Parameters
inthe input to process as a string
Returns
the result of the call to final()

Definition at line 116 of file buf_comp.h.

116 {
117 update(in);
118 return final<T>();
119 }

References update.

◆ provider()

virtual std::string Botan::HashFunction::provider ( ) const
inlinevirtualinherited
Returns
provider information about this implementation. Default is "base", might also return "sse2", "avx2", "openssl", or some other arbitrary string.

Reimplemented in Botan::SHA_1, Botan::SHA_224, Botan::SHA_256, Botan::SHA_384, Botan::SHA_512, Botan::SHA_512_256, and Botan::SHA_3.

Definition at line 49 of file hash.h.

49{ return "base"; }

Referenced by Botan::HashFunction::create(), and Botan::HashFunction::create_or_throw().

◆ providers()

std::vector< std::string > Botan::HashFunction::providers ( std::string_view  algo_spec)
staticinherited
Returns
list of available providers for this algorithm, empty if not available
Parameters
algo_specalgorithm name

Definition at line 295 of file hash.cpp.

295 {
296 return probe_providers_of<HashFunction>(algo_spec, {"base", "commoncrypto"});
297}

◆ set_key() [1/3]

void Botan::SymmetricAlgorithm::set_key ( const SymmetricKey key)
inlineinherited

◆ set_key() [2/3]

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

Set the symmetric key of this object.

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

Definition at line 17 of file sym_algo.cpp.

17 {
18 if(!valid_keylength(length)) {
19 throw Invalid_Key_Length(name(), length);
20 }
21 key_schedule(key, length);
22}
bool valid_keylength(size_t length) const
Definition: sym_algo.h:107
virtual std::string name() const =0

References Botan::SymmetricAlgorithm::name(), and Botan::SymmetricAlgorithm::valid_keylength().

◆ set_key() [3/3]

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

Set the symmetric key of this object.

Parameters
keythe contiguous byte range to be set.

Definition at line 119 of file sym_algo.h.

119{ set_key(key.data(), key.size()); }

References Botan::SymmetricAlgorithm::set_key().

Referenced by Botan::SymmetricAlgorithm::set_key().

◆ update() [1/4]

void Botan::Buffered_Computation::update ( const uint8_t  in[],
size_t  length 
)
inlineinherited

◆ update() [2/4]

void Botan::Buffered_Computation::update ( std::span< const uint8_t >  in)
inlineinherited

Add new input to process.

Parameters
inthe input to process as a contiguous data range

Definition at line 40 of file buf_comp.h.

40{ add_data(in.data(), in.size()); }

◆ update() [3/4]

void Botan::Buffered_Computation::update ( std::string_view  str)
inlineinherited

Add new input to process.

Parameters
strthe input to process as a std::string_view. Will be interpreted as a byte array based on the strings encoding.

Definition at line 55 of file buf_comp.h.

55{ add_data(cast_char_ptr_to_uint8(str.data()), str.size()); }
const uint8_t * cast_char_ptr_to_uint8(const char *s)
Definition: mem_ops.h:177

References Botan::cast_char_ptr_to_uint8().

◆ update() [4/4]

void Botan::Buffered_Computation::update ( uint8_t  in)
inlineinherited

Process a single byte.

Parameters
inthe byte to process

Definition at line 61 of file buf_comp.h.

61{ add_data(&in, 1); }

◆ update_be() [1/3]

void Botan::Buffered_Computation::update_be ( uint16_t  val)
inherited

Definition at line 13 of file buf_comp.cpp.

13 {
14 uint8_t inb[sizeof(val)];
15 store_be(val, inb);
16 add_data(inb, sizeof(inb));
17}
constexpr void store_be(uint16_t in, uint8_t out[2])
Definition: loadstor.h:407

References Botan::store_be().

Referenced by Botan::mgf1_mask(), and Botan::pbkdf2().

◆ update_be() [2/3]

void Botan::Buffered_Computation::update_be ( uint32_t  val)
inherited

Definition at line 19 of file buf_comp.cpp.

19 {
20 uint8_t inb[sizeof(val)];
21 store_be(val, inb);
22 add_data(inb, sizeof(inb));
23}

References Botan::store_be().

◆ update_be() [3/3]

void Botan::Buffered_Computation::update_be ( uint64_t  val)
inherited

Definition at line 25 of file buf_comp.cpp.

25 {
26 uint8_t inb[sizeof(val)];
27 store_be(val, inb);
28 add_data(inb, sizeof(inb));
29}

References Botan::store_be().

◆ update_le() [1/3]

void Botan::Buffered_Computation::update_le ( uint16_t  val)
inherited

Definition at line 31 of file buf_comp.cpp.

31 {
32 uint8_t inb[sizeof(val)];
33 store_le(val, inb);
34 add_data(inb, sizeof(inb));
35}
constexpr void store_le(uint16_t in, uint8_t out[2])
Definition: loadstor.h:422

References Botan::store_le().

◆ update_le() [2/3]

void Botan::Buffered_Computation::update_le ( uint32_t  val)
inherited

Definition at line 37 of file buf_comp.cpp.

37 {
38 uint8_t inb[sizeof(val)];
39 store_le(val, inb);
40 add_data(inb, sizeof(inb));
41}

References Botan::store_le().

◆ update_le() [3/3]

void Botan::Buffered_Computation::update_le ( uint64_t  val)
inherited

Definition at line 43 of file buf_comp.cpp.

43 {
44 uint8_t inb[sizeof(val)];
45 store_le(val, inb);
46 add_data(inb, sizeof(inb));
47}

References Botan::store_le().

◆ 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 107 of file sym_algo.h.

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

Referenced by Botan::SymmetricAlgorithm::set_key().

Friends And Related Function Documentation

◆ BLAKE2bMAC

friend class BLAKE2bMAC
friend

Definition at line 47 of file blake2b.h.


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