Botan 3.13.0
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::Ascon_Hash256 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.

Returns
a contiguous container holding the result

Definition at line 104 of file buf_comp.h.

104 {
105 T output(output_length());
106 final_result(output);
107 return output;
108 }
virtual size_t output_length() const =0

References output_length().

◆ final() [2/4]

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

Complete the computation and retrieve the final result

Parameters
outthe buffer to write the result to, must be output_length() bytes

Definition at line 54 of file buf_comp.cpp.

54 {
55 BOTAN_ARG_CHECK(out.size() >= output_length(), "Output buffer has insufficient capacity");
56 // Pass exactly output_length() bytes so that an oversized buffer has the
57 // result written to its leading bytes with the remainder left untouched.
58 final_result(out.first(output_length()));
59}
#define BOTAN_ARG_CHECK(expr, msg)
Definition assert.h:33

References BOTAN_ARG_CHECK, and output_length().

◆ final() [3/4]

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

Complete the computation and retrieve the final result

Parameters
outa container which is resized to hold the result

Definition at line 127 of file buf_comp.h.

127 {
128 out.resize(output_length());
129 final_result(out);
130 }

References output_length().

◆ final() [4/4]

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

Complete the computation and retrieve the final result.

Parameters
outThe byte array to be filled with the result, which must be of length output_length()

Definition at line 97 of file buf_comp.h.

97{ final_result({out, output_length()}); }

References output_length().

Referenced by Botan::expand_message_xmd(), final_stdvec(), Botan::PseudorandomKeyGeneration::gen(), Botan::TPM2::Verification_Operation::is_valid_signature(), Botan::mgf1_mask(), Botan::KMAC::operator=(), Botan::pbkdf2(), Botan::Sphincs_Hash_Functions_Sha2::PRF_msg(), process(), process(), process(), Botan::TPM2::Signature_Operation::sign(), and Botan::sm2_compute_za().

◆ final_stdvec()

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

Complete the computation and retrieve the final result

Returns
a std::vector holding the result

Definition at line 114 of file buf_comp.h.

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

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

140 {
141 update(in, length);
142 return final<T>();
143 }
void update(const uint8_t in[], size_t length)
Definition buf_comp.h:35

References final(), and update().

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

164 {
165 update(in);
166 return final<T>();
167 }

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

152 {
153 update(in);
154 return final<T>();
155 }

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

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

Referenced by Botan::expand_message_xmd(), 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 41 of file buf_comp.h.

41{ 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 14 of file buf_comp.cpp.

14 {
15 add_data(as_span_of_bytes(str));
16}
std::span< const uint8_t > as_span_of_bytes(const char *s, size_t len)
Definition mem_utils.h:59

References Botan::as_span_of_bytes().

◆ update() [4/4]

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

Process a single byte.

Parameters
inthe byte to process

Definition at line 90 of file buf_comp.h.

90{ add_data({&in, 1}); }

◆ update_be() [1/3]

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

Add new input to process, encoded as a big-endian integer

Parameters
valthe value to process

Definition at line 18 of file buf_comp.cpp.

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

References Botan::store_be().

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

◆ update_be() [2/3]

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

Add new input to process, encoded as a big-endian integer

Parameters
valthe value to process

Definition at line 24 of file buf_comp.cpp.

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

References Botan::store_be().

◆ update_be() [3/3]

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

Add new input to process, encoded as a big-endian integer

Parameters
valthe value to process

Definition at line 30 of file buf_comp.cpp.

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

References Botan::store_be().

◆ update_le() [1/3]

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

Add new input to process, encoded as a little-endian integer

Parameters
valthe value to process

Definition at line 36 of file buf_comp.cpp.

36 {
37 uint8_t inb[sizeof(val)];
38 store_le(val, inb);
39 add_data({inb, sizeof(inb)});
40}
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)

Add new input to process, encoded as a little-endian integer

Parameters
valthe value to process

Definition at line 42 of file buf_comp.cpp.

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

References Botan::store_le().

◆ update_le() [3/3]

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

Add new input to process, encoded as a little-endian integer

Parameters
valthe value to process

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