Botan
1.11.15
|
#include <md5.h>
Public Types | |
typedef SCAN_Name | Spec |
Public Member Functions | |
void | clear () |
HashFunction * | clone () const |
void | final (byte out[]) |
secure_vector< byte > | final () |
template<typename Alloc > | |
void | final (std::vector< byte, Alloc > &out) |
size_t | hash_block_size () const |
MD5 () | |
std::string | name () const |
size_t | output_length () const |
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 | compress_n (const byte[], size_t blocks) |
void | copy_out (byte[]) |
void | final_result (byte output[]) |
virtual void | write_count (byte out[]) |
Protected Attributes | |
secure_vector< u32bit > | digest |
secure_vector< u32bit > | M |
typedef SCAN_Name Botan::HashFunction::Spec [inherited] |
Botan::MD5::MD5 | ( | ) | [inline] |
void Botan::MDx_HashFunction::add_data | ( | const byte | input[], |
size_t | length | ||
) | [protected, virtual, inherited] |
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 Botan::MDx_HashFunction::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::MD5::clear | ( | ) | [virtual] |
Reimplemented from Botan::MDx_HashFunction.
Definition at line 126 of file md5.cpp.
References digest, M, and Botan::zeroise().
HashFunction* Botan::MD5::clone | ( | ) | const [inline, virtual] |
Implements Botan::HashFunction.
Reimplemented in Botan::MD5_X86_32.
Definition at line 23 of file md5.h.
{ return new MD5; }
void Botan::MD5::compress_n | ( | const byte | blocks[], |
size_t | block_n | ||
) | [protected, virtual] |
Run the hash's compression function over a set of blocks
blocks | the input |
block_n | the number of blocks |
Implements Botan::MDx_HashFunction.
Definition at line 62 of file md5.cpp.
References digest, Botan::MDx_HashFunction::hash_block_size(), Botan::load_le(), and M.
{ u32bit A = digest[0], B = digest[1], C = digest[2], D = digest[3]; for(size_t i = 0; i != blocks; ++i) { load_le(&M[0], input, M.size()); FF(A,B,C,D,M[ 0], 7,0xD76AA478); FF(D,A,B,C,M[ 1],12,0xE8C7B756); FF(C,D,A,B,M[ 2],17,0x242070DB); FF(B,C,D,A,M[ 3],22,0xC1BDCEEE); FF(A,B,C,D,M[ 4], 7,0xF57C0FAF); FF(D,A,B,C,M[ 5],12,0x4787C62A); FF(C,D,A,B,M[ 6],17,0xA8304613); FF(B,C,D,A,M[ 7],22,0xFD469501); FF(A,B,C,D,M[ 8], 7,0x698098D8); FF(D,A,B,C,M[ 9],12,0x8B44F7AF); FF(C,D,A,B,M[10],17,0xFFFF5BB1); FF(B,C,D,A,M[11],22,0x895CD7BE); FF(A,B,C,D,M[12], 7,0x6B901122); FF(D,A,B,C,M[13],12,0xFD987193); FF(C,D,A,B,M[14],17,0xA679438E); FF(B,C,D,A,M[15],22,0x49B40821); GG(A,B,C,D,M[ 1], 5,0xF61E2562); GG(D,A,B,C,M[ 6], 9,0xC040B340); GG(C,D,A,B,M[11],14,0x265E5A51); GG(B,C,D,A,M[ 0],20,0xE9B6C7AA); GG(A,B,C,D,M[ 5], 5,0xD62F105D); GG(D,A,B,C,M[10], 9,0x02441453); GG(C,D,A,B,M[15],14,0xD8A1E681); GG(B,C,D,A,M[ 4],20,0xE7D3FBC8); GG(A,B,C,D,M[ 9], 5,0x21E1CDE6); GG(D,A,B,C,M[14], 9,0xC33707D6); GG(C,D,A,B,M[ 3],14,0xF4D50D87); GG(B,C,D,A,M[ 8],20,0x455A14ED); GG(A,B,C,D,M[13], 5,0xA9E3E905); GG(D,A,B,C,M[ 2], 9,0xFCEFA3F8); GG(C,D,A,B,M[ 7],14,0x676F02D9); GG(B,C,D,A,M[12],20,0x8D2A4C8A); HH(A,B,C,D,M[ 5], 4,0xFFFA3942); HH(D,A,B,C,M[ 8],11,0x8771F681); HH(C,D,A,B,M[11],16,0x6D9D6122); HH(B,C,D,A,M[14],23,0xFDE5380C); HH(A,B,C,D,M[ 1], 4,0xA4BEEA44); HH(D,A,B,C,M[ 4],11,0x4BDECFA9); HH(C,D,A,B,M[ 7],16,0xF6BB4B60); HH(B,C,D,A,M[10],23,0xBEBFBC70); HH(A,B,C,D,M[13], 4,0x289B7EC6); HH(D,A,B,C,M[ 0],11,0xEAA127FA); HH(C,D,A,B,M[ 3],16,0xD4EF3085); HH(B,C,D,A,M[ 6],23,0x04881D05); HH(A,B,C,D,M[ 9], 4,0xD9D4D039); HH(D,A,B,C,M[12],11,0xE6DB99E5); HH(C,D,A,B,M[15],16,0x1FA27CF8); HH(B,C,D,A,M[ 2],23,0xC4AC5665); II(A,B,C,D,M[ 0], 6,0xF4292244); II(D,A,B,C,M[ 7],10,0x432AFF97); II(C,D,A,B,M[14],15,0xAB9423A7); II(B,C,D,A,M[ 5],21,0xFC93A039); II(A,B,C,D,M[12], 6,0x655B59C3); II(D,A,B,C,M[ 3],10,0x8F0CCC92); II(C,D,A,B,M[10],15,0xFFEFF47D); II(B,C,D,A,M[ 1],21,0x85845DD1); II(A,B,C,D,M[ 8], 6,0x6FA87E4F); II(D,A,B,C,M[15],10,0xFE2CE6E0); II(C,D,A,B,M[ 6],15,0xA3014314); II(B,C,D,A,M[13],21,0x4E0811A1); II(A,B,C,D,M[ 4], 6,0xF7537E82); II(D,A,B,C,M[11],10,0xBD3AF235); II(C,D,A,B,M[ 2],15,0x2AD7D2BB); II(B,C,D,A,M[ 9],21,0xEB86D391); A = (digest[0] += A); B = (digest[1] += B); C = (digest[2] += C); D = (digest[3] += D); input += hash_block_size(); } }
void Botan::MD5::copy_out | ( | byte | buffer[] | ) | [protected, virtual] |
Copy the output to the buffer
buffer | to put the output into |
Implements Botan::MDx_HashFunction.
Definition at line 118 of file md5.cpp.
References Botan::copy_out_vec_le(), digest, and output_length().
{ copy_out_vec_le(output, output_length(), digest); }
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, inherited] |
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 Botan::MDx_HashFunction::clear(), Botan::MDx_HashFunction::compress_n(), Botan::MDx_HashFunction::copy_out(), Botan::MDx_HashFunction::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, inherited] |
Reimplemented from Botan::HashFunction.
Definition at line 32 of file mdx_hash.h.
Referenced by Botan::MD4::compress_n(), compress_n(), Botan::SHA_160::compress_n(), and Botan::MDx_HashFunction::write_count().
{ return buffer.size(); }
std::string Botan::MD5::name | ( | ) | const [inline, virtual] |
size_t Botan::MD5::output_length | ( | ) | const [inline, virtual] |
Implements Botan::Buffered_Computation.
Definition at line 22 of file md5.h.
Referenced by copy_out().
{ return 16; }
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, inherited] |
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 Botan::MDx_HashFunction::hash_block_size(), Botan::Buffered_Computation::output_length(), Botan::store_be(), and Botan::store_le().
Referenced by Botan::MDx_HashFunction::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); }
secure_vector<u32bit> Botan::MD5::digest [protected] |
The digest value, exposed for use by subclasses (x86 asm)
Definition at line 41 of file md5.h.
Referenced by clear(), compress_n(), and copy_out().
secure_vector<u32bit> Botan::MD5::M [protected] |
The message buffer, exposed for use by subclasses (x86 asm)
Definition at line 36 of file md5.h.
Referenced by clear(), and compress_n().