Botan
1.11.15
|
#include <mdx_hash.h>
Public Types | |
typedef SCAN_Name | Spec |
Public Member Functions | |
virtual HashFunction * | clone () const =0 |
void | final (byte out[]) |
secure_vector< byte > | final () |
template<typename Alloc > | |
void | final (std::vector< byte, Alloc > &out) |
size_t | hash_block_size () const |
MDx_HashFunction (size_t block_length, bool big_byte_endian, bool big_bit_endian, size_t counter_size=8) | |
virtual std::string | name () const =0 |
virtual size_t | output_length () const =0 |
secure_vector< byte > | process (const byte in[], size_t length) |
secure_vector< byte > | process (const secure_vector< byte > &in) |
secure_vector< byte > | process (const std::vector< byte > &in) |
secure_vector< byte > | process (const std::string &in) |
void | update (const byte in[], size_t length) |
void | update (const secure_vector< byte > &in) |
void | update (const std::vector< byte > &in) |
void | update (const std::string &str) |
void | update (byte in) |
template<typename T > | |
void | update_be (const T in) |
Protected Member Functions | |
void | add_data (const byte input[], size_t length) |
void | clear () |
virtual void | compress_n (const byte blocks[], size_t block_n)=0 |
virtual void | copy_out (byte buffer[])=0 |
void | final_result (byte output[]) |
virtual void | write_count (byte out[]) |
MDx Hash Function Base Class
Definition at line 18 of file mdx_hash.h.
typedef SCAN_Name Botan::HashFunction::Spec [inherited] |
Botan::MDx_HashFunction::MDx_HashFunction | ( | size_t | block_length, |
bool | big_byte_endian, | ||
bool | big_bit_endian, | ||
size_t | counter_size = 8 |
||
) |
block_length | is the number of bytes per block |
big_byte_endian | specifies if the hash uses big-endian bytes |
big_bit_endian | specifies if the hash uses big-endian bits |
counter_size | specifies the size of the counter var in bytes |
Definition at line 17 of file mdx_hash.cpp.
: buffer(block_len), BIG_BYTE_ENDIAN(byte_end), BIG_BIT_ENDIAN(bit_end), COUNT_SIZE(cnt_size) { count = position = 0; }
void Botan::MDx_HashFunction::add_data | ( | const byte | input[], |
size_t | length | ||
) | [protected, virtual] |
Add more data to the computation
input | is an input buffer |
length | is the length of input in bytes |
Implements Botan::Buffered_Computation.
Definition at line 41 of file mdx_hash.cpp.
References Botan::buffer_insert(), and compress_n().
{ count += length; if(position) { buffer_insert(buffer, position, input, length); if(position + length >= buffer.size()) { compress_n(&buffer[0], 1); input += (buffer.size() - position); length -= (buffer.size() - position); position = 0; } } const size_t full_blocks = length / buffer.size(); const size_t remaining = length % buffer.size(); if(full_blocks) compress_n(input, full_blocks); buffer_insert(buffer, position, input + full_blocks * buffer.size(), remaining); position += remaining; }
void Botan::MDx_HashFunction::clear | ( | ) | [protected, virtual] |
Implements Botan::HashFunction.
Reimplemented in Botan::SHA_512_256, Botan::SHA_256, Botan::SHA_512, Botan::Tiger, Botan::HAS_160, Botan::SHA_224, Botan::MD4, Botan::MD5, Botan::RIPEMD_128, Botan::RIPEMD_160, Botan::SHA_160, Botan::SHA_384, and Botan::Whirlpool.
Definition at line 32 of file mdx_hash.cpp.
References Botan::zeroise().
Referenced by final_result().
{ zeroise(buffer); count = position = 0; }
virtual HashFunction* Botan::HashFunction::clone | ( | ) | const [pure virtual, inherited] |
Implemented in Botan::SHA_512_256, Botan::SHA_256, Botan::SHA_512, Botan::Comb4P, Botan::Skein_512, Botan::Keccak_1600, Botan::GOST_34_11, Botan::Tiger, Botan::HAS_160, Botan::MD2, Botan::Parallel, Botan::SHA_224, Botan::Adler32, Botan::CRC24, Botan::CRC32, Botan::MD4, Botan::MD5, Botan::RIPEMD_128, Botan::RIPEMD_160, Botan::SHA_160, Botan::SHA_384, Botan::Whirlpool, Botan::MD4_X86_32, Botan::MD5_X86_32, Botan::SHA_160_SSE2, Botan::SHA_160_X86_32, and Botan::SHA_160_X86_64.
virtual void Botan::MDx_HashFunction::compress_n | ( | const byte | blocks[], |
size_t | block_n | ||
) | [protected, pure virtual] |
Run the hash's compression function over a set of blocks
blocks | the input |
block_n | the number of blocks |
Implemented in Botan::SHA_160, Botan::MD4, and Botan::MD5.
Referenced by add_data(), and final_result().
virtual void Botan::MDx_HashFunction::copy_out | ( | byte | buffer[] | ) | [protected, pure virtual] |
Copy the output to the buffer
buffer | to put the output into |
Implemented in Botan::SHA_160, Botan::MD4, and Botan::MD5.
Referenced by final_result().
void Botan::Buffered_Computation::final | ( | byte | out[] | ) | [inline, inherited] |
Complete the computation and retrieve the final result.
out | The byte array to be filled with the result. Must be of length output_length() |
Definition at line 90 of file buf_comp.h.
Referenced by botan_hash_final(), botan_mac_final(), Botan::McEliece_KEM_Decryptor::decrypt(), Botan::TLS::Session::decrypt(), Botan::McEliece_KEM_Encryptor::encrypt(), Botan::TLS::Session::encrypt(), Botan::mgf1_mask(), Botan::pbkdf2(), and Botan::TLS::write_record().
{ final_result(out); }
secure_vector<byte> Botan::Buffered_Computation::final | ( | ) | [inline, inherited] |
Complete the computation and retrieve the final result.
Definition at line 97 of file buf_comp.h.
{ secure_vector<byte> output(output_length()); final_result(&output[0]); return output; }
void Botan::Buffered_Computation::final | ( | std::vector< byte, Alloc > & | out | ) | [inline, inherited] |
Definition at line 105 of file buf_comp.h.
{ out.resize(output_length()); final_result(&out[0]); }
void Botan::MDx_HashFunction::final_result | ( | byte | out[] | ) | [protected, virtual] |
Write the final output to out
out | is an output buffer of output_length() |
Implements Botan::Buffered_Computation.
Definition at line 71 of file mdx_hash.cpp.
References clear(), compress_n(), copy_out(), write_count(), and Botan::zeroise().
{ buffer[position] = (BIG_BIT_ENDIAN ? 0x80 : 0x01); for(size_t i = position+1; i != buffer.size(); ++i) buffer[i] = 0; if(position >= buffer.size() - COUNT_SIZE) { compress_n(&buffer[0], 1); zeroise(buffer); } write_count(&buffer[buffer.size() - COUNT_SIZE]); compress_n(&buffer[0], 1); copy_out(output); clear(); }
size_t Botan::MDx_HashFunction::hash_block_size | ( | ) | const [inline, virtual] |
Reimplemented from Botan::HashFunction.
Definition at line 32 of file mdx_hash.h.
Referenced by Botan::MD4::compress_n(), Botan::MD5::compress_n(), Botan::SHA_160::compress_n(), and write_count().
{ return buffer.size(); }
virtual std::string Botan::HashFunction::name | ( | ) | const [pure virtual, inherited] |
Implemented in Botan::SHA_512_256, Botan::Comb4P, Botan::SHA_256, Botan::SHA_512, Botan::Skein_512, Botan::Keccak_1600, Botan::Parallel, Botan::GOST_34_11, Botan::HAS_160, Botan::SHA_224, Botan::Adler32, Botan::CRC24, Botan::CRC32, Botan::MD2, Botan::MD4, Botan::MD5, Botan::RIPEMD_128, Botan::RIPEMD_160, Botan::SHA_160, Botan::SHA_384, Botan::Tiger, and Botan::Whirlpool.
Referenced by Botan::EMSA_X931::EMSA_X931().
virtual size_t Botan::Buffered_Computation::output_length | ( | ) | const [pure virtual, inherited] |
Implemented in Botan::SHA_512_256, Botan::SHA_256, Botan::SHA_512, Botan::Skein_512, Botan::Comb4P, Botan::Keccak_1600, Botan::Poly1305, Botan::Parallel, Botan::HMAC, Botan::SipHash, Botan::CBC_MAC, Botan::ANSI_X919_MAC, Botan::GOST_34_11, Botan::HAS_160, Botan::SHA_224, Botan::CMAC, Botan::Adler32, Botan::CRC24, Botan::CRC32, Botan::MD2, Botan::MD4, Botan::MD5, Botan::RIPEMD_128, Botan::RIPEMD_160, Botan::SHA_160, Botan::SHA_384, Botan::Tiger, and Botan::Whirlpool.
Referenced by botan_hash_output_length(), botan_mac_output_length(), Botan::pbkdf2(), and write_count().
secure_vector<byte> Botan::Buffered_Computation::process | ( | const byte | in[], |
size_t | length | ||
) | [inline, inherited] |
Update and finalize computation. Does the same as calling update() and final() consecutively.
in | the input to process as a byte array |
length | the length of the byte array |
Definition at line 118 of file buf_comp.h.
Referenced by Botan::HMAC_RNG::HMAC_RNG(), Botan::RTSS_Share::split(), and Botan::Cert_Extension::Subject_Key_ID::Subject_Key_ID().
{ add_data(in, length); return final(); }
secure_vector<byte> Botan::Buffered_Computation::process | ( | const secure_vector< byte > & | in | ) | [inline, inherited] |
Update and finalize computation. Does the same as calling update() and final() consecutively.
in | the input to process |
Definition at line 130 of file buf_comp.h.
{ add_data(&in[0], in.size()); return final(); }
secure_vector<byte> Botan::Buffered_Computation::process | ( | const std::vector< byte > & | in | ) | [inline, inherited] |
Update and finalize computation. Does the same as calling update() and final() consecutively.
in | the input to process |
Definition at line 142 of file buf_comp.h.
{ add_data(&in[0], in.size()); return final(); }
secure_vector<byte> Botan::Buffered_Computation::process | ( | const std::string & | in | ) | [inline, inherited] |
void Botan::Buffered_Computation::update | ( | const byte | in[], |
size_t | length | ||
) | [inline, inherited] |
Add new input to process.
in | the input to process as a byte array |
length | of param in in bytes |
Definition at line 34 of file buf_comp.h.
Referenced by botan_hash_update(), botan_mac_update(), Botan::McEliece_KEM_Decryptor::decrypt(), Botan::TLS::Session::decrypt(), Botan::McEliece_KEM_Encryptor::encrypt(), Botan::TLS::Session::encrypt(), Botan::mgf1_mask(), Botan::pbkdf2(), and Botan::TLS::write_record().
{ add_data(in, length); }
void Botan::Buffered_Computation::update | ( | const secure_vector< byte > & | in | ) | [inline, inherited] |
Add new input to process.
in | the input to process as a secure_vector |
Definition at line 40 of file buf_comp.h.
{ add_data(&in[0], in.size()); }
void Botan::Buffered_Computation::update | ( | const std::vector< byte > & | in | ) | [inline, inherited] |
Add new input to process.
in | the input to process as a std::vector |
Definition at line 49 of file buf_comp.h.
{ add_data(&in[0], in.size()); }
void Botan::Buffered_Computation::update | ( | const std::string & | str | ) | [inline, inherited] |
Add new input to process.
str | the input to process as a std::string. Will be interpreted as a byte array based on the strings encoding. |
Definition at line 73 of file buf_comp.h.
{ add_data(reinterpret_cast<const byte*>(str.data()), str.size()); }
void Botan::Buffered_Computation::update | ( | byte | in | ) | [inline, inherited] |
Process a single byte.
in | the byte to process |
Definition at line 82 of file buf_comp.h.
{ add_data(&in, 1); }
void Botan::Buffered_Computation::update_be | ( | const T | in | ) | [inline, inherited] |
Add an integer in big-endian order
in | the value |
Definition at line 58 of file buf_comp.h.
References Botan::get_byte().
Referenced by Botan::mgf1_mask(), and Botan::pbkdf2().
void Botan::MDx_HashFunction::write_count | ( | byte | out[] | ) | [protected, virtual] |
Write the count, if used, to this spot
out | where to write the counter to |
Definition at line 93 of file mdx_hash.cpp.
References hash_block_size(), Botan::Buffered_Computation::output_length(), Botan::store_be(), and Botan::store_le().
Referenced by final_result().
{ if(COUNT_SIZE < 8) throw Invalid_State("MDx_HashFunction::write_count: COUNT_SIZE < 8"); if(COUNT_SIZE >= output_length() || COUNT_SIZE >= hash_block_size()) throw Invalid_Argument("MDx_HashFunction: COUNT_SIZE is too big"); const u64bit bit_count = count * 8; if(BIG_BYTE_ENDIAN) store_be(bit_count, out + COUNT_SIZE - 8); else store_le(bit_count, out + COUNT_SIZE - 8); }