Botan 3.8.1
Crypto and TLS for C&
Botan::Buffered_Computation Class Referenceabstract

#include <buf_comp.h>

Inheritance diagram for Botan::Buffered_Computation:
Botan::HashFunction Botan::MessageAuthenticationCode Botan::Adler32 Botan::BLAKE2b Botan::BLAKE2s Botan::CRC24 Botan::CRC32 Botan::Comb4P Botan::GOST_34_11 Botan::Keccak_1600 Botan::MD4 Botan::MD5 Botan::Parallel Botan::RIPEMD_160 Botan::RawHashFunction Botan::SHAKE_128 Botan::SHAKE_256 Botan::SHA_1 Botan::SHA_224 Botan::SHA_256 Botan::SHA_3 Botan::SHA_384 Botan::SHA_512 Botan::SHA_512_256 Botan::SM3 Botan::Skein_512 Botan::Streebog Botan::TPM2::HashFunction Botan::Truncated_Hash Botan::Whirlpool Botan::ANSI_X919_MAC Botan::BLAKE2bMAC Botan::CMAC Botan::GMAC Botan::HMAC Botan::KMAC Botan::Poly1305 Botan::SipHash

Public Member Functions

template<concepts::resizable_byte_buffer T = secure_vector<uint8_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 ()
 
virtual size_t output_length () const =0
 
template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
process (const uint8_t in[], size_t length)
 
template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
process (std::span< const uint8_t > in)
 
template<concepts::resizable_byte_buffer T = secure_vector<uint8_t>>
process (std::string_view in)
 
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)
 
virtual ~Buffered_Computation ()=default
 

Detailed Description

This class represents any kind of computation which uses an internal state, such as hash functions or MACs

Definition at line 22 of file buf_comp.h.

Constructor & Destructor Documentation

◆ ~Buffered_Computation()

virtual Botan::Buffered_Computation::~Buffered_Computation ( )
virtualdefault

Member Function Documentation

◆ final() [1/4]

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

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);
80 return output;
81 }
virtual size_t output_length() const =0

References output_length().

◆ final() [2/4]

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

Definition at line 53 of file buf_comp.cpp.

53 {
54 BOTAN_ARG_CHECK(out.size() >= output_length(), "provided output buffer has insufficient capacity");
55 final_result(out);
56}
#define BOTAN_ARG_CHECK(expr, msg)
Definition assert.h:31

References BOTAN_ARG_CHECK, and output_length().

◆ final() [3/4]

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

Definition at line 88 of file buf_comp.h.

88 {
89 out.resize(output_length());
90 final_result(out);
91 }

References output_length().

◆ final() [4/4]

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

◆ final_stdvec()

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

Definition at line 83 of file buf_comp.h.

83{ return final<std::vector<uint8_t>>(); }
void final(uint8_t out[])
Definition buf_comp.h:69

References final().

◆ 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 )
inline

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

101 {
102 update(in, length);
103 return final<T>();
104 }
void update(const uint8_t in[], size_t length)
Definition buf_comp.h:34

References final(), and update().

Referenced by Botan::Kyber_Symmetric_Primitives::H(), Botan::Kyber_Symmetric_Primitives::H(), and Botan::Kyber_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)
inline

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

125 {
126 update(in);
127 return final<T>();
128 }

References final(), and update().

◆ process() [3/3]

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

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

113 {
114 update(in);
115 return final<T>();
116 }

References final(), and update().

◆ update() [1/4]

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

Add new input to process.

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

Definition at line 34 of file buf_comp.h.

34{ add_data({in, length}); }

Referenced by Botan::ed25519_gen_keypair(), Botan::ed25519_sign(), Botan::ed25519_verify(), Botan::PseudorandomKeyGeneration::gen(), Botan::LMOTS_Public_Key::LMOTS_Public_Key(), Botan::mgf1_mask(), Botan::pbkdf2(), Botan::Sphincs_Hash_Functions_Sha2::PRF_msg(), process(), process(), process(), and Botan::sm2_compute_za().

◆ update() [2/4]

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

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); }

◆ update() [3/4]

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

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 13 of file buf_comp.cpp.

13 {
14 add_data({cast_char_ptr_to_uint8(str.data()), str.size()});
15}
const uint8_t * cast_char_ptr_to_uint8(const char *s)
Definition mem_ops.h:276

References Botan::cast_char_ptr_to_uint8().

◆ update() [4/4]

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

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)

Definition at line 17 of file buf_comp.cpp.

17 {
18 uint8_t inb[sizeof(val)];
19 store_be(val, inb);
20 add_data({inb, sizeof(inb)});
21}
constexpr auto store_be(ParamTs &&... params)
Definition loadstor.h:745

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)

Definition at line 23 of file buf_comp.cpp.

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

References Botan::store_be().

◆ update_be() [3/3]

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

Definition at line 29 of file buf_comp.cpp.

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

References Botan::store_be().

◆ update_le() [1/3]

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

Definition at line 35 of file buf_comp.cpp.

35 {
36 uint8_t inb[sizeof(val)];
37 store_le(val, inb);
38 add_data({inb, sizeof(inb)});
39}
constexpr auto store_le(ParamTs &&... params)
Definition loadstor.h:736

References Botan::store_le().

◆ update_le() [2/3]

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

Definition at line 41 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)

Definition at line 47 of file buf_comp.cpp.

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

References Botan::store_le().


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