Botan 3.0.0-alpha0
Crypto and TLS for C&
Public Member Functions | Static Public Member Functions | List of all members
Botan::SHAKE_256 Class Referencefinal

#include <shake.h>

Inheritance diagram for Botan::SHAKE_256:
Botan::HashFunction Botan::Buffered_Computation

Public Member Functions

void clear () override
 
HashFunctionclone () const
 
std::unique_ptr< HashFunctioncopy_state () const override
 
secure_vector< uint8_t > final ()
 
template<typename Alloc >
void final (std::vector< uint8_t, Alloc > &out)
 
void final (uint8_t out[])
 
std::vector< uint8_t > final_stdvec ()
 
size_t hash_block_size () const override
 
std::string name () const override
 
std::unique_ptr< HashFunctionnew_object () const override
 
size_t output_length () const override
 
secure_vector< uint8_t > process (const secure_vector< uint8_t > &in)
 
secure_vector< uint8_t > process (const std::string &in)
 
secure_vector< uint8_t > process (const std::vector< uint8_t > &in)
 
secure_vector< uint8_t > process (const uint8_t in[], size_t length)
 
virtual std::string provider () const
 
 SHAKE_256 (size_t output_bits)
 
void update (const secure_vector< uint8_t > &in)
 
void update (const std::string &str)
 
void update (const std::vector< uint8_t > &in)
 
void update (const uint8_t in[], size_t length)
 
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)
 

Static Public Member Functions

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

Detailed Description

SHAKE-256

Definition at line 52 of file shake.h.

Constructor & Destructor Documentation

◆ SHAKE_256()

Botan::SHAKE_256::SHAKE_256 ( size_t  output_bits)
explicit
Parameters
output_bitsthe desired output size in bits must be a multiple of 8

Definition at line 55 of file shake.cpp.

55 :
56 m_output_bits(output_bits), m_S(25), m_S_pos(0)
57 {
58 if(output_bits % 8 != 0)
59 throw Invalid_Argument("SHAKE_256: Invalid output length " +
60 std::to_string(output_bits));
61 }
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:209

References Botan::ASN1::to_string().

Member Function Documentation

◆ clear()

void Botan::SHAKE_256::clear ( )
overridevirtual

Reset the state.

Implements Botan::HashFunction.

Definition at line 78 of file shake.cpp.

79 {
80 zeroise(m_S);
81 m_S_pos = 0;
82 }
void zeroise(std::vector< T, Alloc > &vec)
Definition: secmem.h:114

References Botan::zeroise().

◆ clone()

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

Definition at line 91 of file hash.h.

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

◆ copy_state()

std::unique_ptr< HashFunction > Botan::SHAKE_256::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 73 of file shake.cpp.

74 {
75 return std::make_unique<SHAKE_256>(*this);
76 }

◆ create()

std::unique_ptr< HashFunction > Botan::HashFunction::create ( const std::string &  algo_spec,
const std::string &  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 98 of file hash.cpp.

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

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

Referenced by botan_hash_init(), botan_pubkey_fingerprint(), 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 ( const std::string &  algo_spec,
const std::string &  provider = "" 
)
staticinherited

Create an instance based on a name If provider is empty then best available is chosen.

Parameters
algo_specalgorithm name
providerprovider implementation to use Throws Lookup_Error if not found.

Definition at line 312 of file hash.cpp.

314 {
315 if(auto hash = HashFunction::create(algo, provider))
316 {
317 return hash;
318 }
319 throw Lookup_Error("Hash", algo, provider);
320 }

References Botan::HashFunction::create(), hash, and Botan::HashFunction::provider().

Referenced by botan_pubkey_sm2_compute_za(), Botan::OCSP::CertID::CertID(), Botan::TLS::Client_Hello::Client_Hello(), Botan::create_hex_fingerprint(), Botan::Sodium::crypto_hash_sha256(), Botan::Sodium::crypto_hash_sha512(), Botan::Bcrypt_PBKDF::derive_key(), Botan::EMSA_PKCS1v15_Raw::EMSA_PKCS1v15_Raw(), Botan::expand_message_xmd(), Botan::TLS::Handshake_Hash::final(), Botan::Kyber_Modern_Symmetric_Primitives::G(), Botan::Kyber_90s_Symmetric_Primitives::G(), Botan::generate_dsa_primes(), Botan::generate_srp6_verifier(), Botan::Kyber_Modern_Symmetric_Primitives::H(), Botan::Kyber_90s_Symmetric_Primitives::H(), Botan::OCSP::CertID::is_id_for(), Botan::Kyber_Modern_Symmetric_Primitives::KDF(), Botan::Kyber_90s_Symmetric_Primitives::KDF(), Botan::TLS::make_hello_random(), Botan::newhope_shareda(), Botan::newhope_sharedb(), Botan::Roughtime::nonce_from_blind(), Botan::TLS::Transcript_Hash_State::set_algorithm(), Botan::srp6_client_agree(), Botan::SRP6_Server_Session::step1(), Botan::SRP6_Server_Session::step2(), and Botan::Cert_Extension::Subject_Key_ID::Subject_Key_ID().

◆ final() [1/3]

secure_vector< uint8_t > Botan::Buffered_Computation::final ( )
inlineinherited

Complete the computation and retrieve the final result.

Returns
secure_vector holding the result

Definition at line 90 of file buf_comp.h.

91 {
92 secure_vector<uint8_t> output(output_length());
93 final_result(output.data());
94 return output;
95 }
virtual size_t output_length() const =0

◆ final() [2/3]

template<typename Alloc >
void Botan::Buffered_Computation::final ( std::vector< uint8_t, Alloc > &  out)
inlineinherited

Definition at line 105 of file buf_comp.h.

106 {
107 out.resize(output_length());
108 final_result(out.data());
109 }

◆ final() [3/3]

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 83 of file buf_comp.h.

83{ final_result(out); }

Referenced by botan_mac_final(), Botan::ed25519_gen_keypair(), Botan::ed25519_sign(), Botan::ed25519_verify(), Botan::TLS::TLS_CBC_HMAC_AEAD_Encryption::finish(), Botan::TLS::TLS_CBC_HMAC_AEAD_Decryption::finish(), Botan::pbkdf2(), and Botan::Kyber_Modern_Symmetric_Primitives::PRF().

◆ final_stdvec()

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

Definition at line 97 of file buf_comp.h.

98 {
99 std::vector<uint8_t> output(output_length());
100 final_result(output.data());
101 return output;
102 }

◆ hash_block_size()

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

Reimplemented from Botan::HashFunction.

Definition at line 62 of file shake.h.

62{ return SHAKE_256_BITRATE / 8; }

◆ name()

std::string Botan::SHAKE_256::name ( ) const
overridevirtual
Returns
the hash function name

Implements Botan::HashFunction.

Definition at line 63 of file shake.cpp.

64 {
65 return "SHAKE-256(" + std::to_string(m_output_bits) + ")";
66 }

References Botan::ASN1::to_string().

◆ new_object()

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

Implements Botan::HashFunction.

Definition at line 68 of file shake.cpp.

69 {
70 return std::make_unique<SHAKE_256>(m_output_bits);
71 }

◆ output_length()

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

Implements Botan::Buffered_Computation.

Definition at line 63 of file shake.h.

63{ return m_output_bits / 8; }

◆ process() [1/4]

secure_vector< uint8_t > Botan::Buffered_Computation::process ( const secure_vector< uint8_t > &  in)
inlineinherited

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

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

Definition at line 130 of file buf_comp.h.

131 {
132 add_data(in.data(), in.size());
133 return final();
134 }

◆ process() [2/4]

secure_vector< uint8_t > Botan::Buffered_Computation::process ( const std::string &  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 154 of file buf_comp.h.

155 {
156 update(in);
157 return final();
158 }
void update(const uint8_t in[], size_t length)
Definition: buf_comp.h:33

References update.

◆ process() [3/4]

secure_vector< uint8_t > Botan::Buffered_Computation::process ( const std::vector< uint8_t > &  in)
inlineinherited

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

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

Definition at line 142 of file buf_comp.h.

143 {
144 add_data(in.data(), in.size());
145 return final();
146 }

◆ process() [4/4]

secure_vector< uint8_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 118 of file buf_comp.h.

119 {
120 add_data(in, length);
121 return final();
122 }

◆ 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_224, Botan::SHA_256, Botan::SHA_384, Botan::SHA_512, Botan::SHA_512_256, and Botan::SHA_3.

Definition at line 53 of file hash.h.

53{ return "base"; }

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

◆ providers()

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

Definition at line 322 of file hash.cpp.

323 {
324 return probe_providers_of<HashFunction>(algo_spec, {"base", "commoncrypto"});
325 }

◆ update() [1/5]

void Botan::Buffered_Computation::update ( const secure_vector< uint8_t > &  in)
inlineinherited

Add new input to process.

Parameters
inthe input to process as a secure_vector

Definition at line 39 of file buf_comp.h.

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

◆ update() [2/5]

void Botan::Buffered_Computation::update ( const std::string &  str)
inlineinherited

Add new input to process.

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

Definition at line 66 of file buf_comp.h.

67 {
68 add_data(cast_char_ptr_to_uint8(str.data()), str.size());
69 }
const uint8_t * cast_char_ptr_to_uint8(const char *s)
Definition: mem_ops.h:183

References Botan::cast_char_ptr_to_uint8().

◆ update() [3/5]

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

Add new input to process.

Parameters
inthe input to process as a std::vector

Definition at line 48 of file buf_comp.h.

49 {
50 add_data(in.data(), in.size());
51 }

◆ update() [4/5]

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

Add new input to process.

Parameters
inthe input to process as a byte array
lengthof param in in bytes

Definition at line 33 of file buf_comp.h.

33{ add_data(in, length); }

Referenced by botan_mac_update(), Botan::ed25519_gen_keypair(), Botan::ed25519_sign(), Botan::ed25519_verify(), Botan::TLS::TLS_CBC_HMAC_AEAD_Encryption::finish(), Botan::TLS::TLS_CBC_HMAC_AEAD_Decryption::finish(), Botan::pbkdf2(), and Botan::Kyber_Modern_Symmetric_Primitives::PRF().

◆ update() [5/5]

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

Process a single byte.

Parameters
inthe byte to process

Definition at line 75 of file buf_comp.h.

75{ add_data(&in, 1); }

◆ update_be() [1/3]

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

Definition at line 12 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:449

References Botan::store_be().

Referenced by 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.

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

References Botan::store_be().

◆ update_be() [3/3]

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

Definition at line 26 of file buf_comp.cpp.

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

References Botan::store_be().

◆ update_le() [1/3]

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

Definition at line 33 of file buf_comp.cpp.

34 {
35 uint8_t inb[sizeof(val)];
36 store_le(val, inb);
37 add_data(inb, sizeof(inb));
38 }
constexpr void store_le(uint16_t in, uint8_t out[2])
Definition: loadstor.h:465

References Botan::store_le().

◆ update_le() [2/3]

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

Definition at line 40 of file buf_comp.cpp.

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

References Botan::store_le().

◆ update_le() [3/3]

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

Definition at line 47 of file buf_comp.cpp.

48 {
49 uint8_t inb[sizeof(val)];
50 store_le(val, inb);
51 add_data(inb, sizeof(inb));
52 }

References Botan::store_le().


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