From a67f99fb8f556e89f16267e4ea97d347fe04fa51 Mon Sep 17 00:00:00 2001 From: cynecx Date: Tue, 26 Jan 2016 23:21:47 +0100 Subject: Add Blake2b hash function --- src/lib/hash/blake2/blake2b.h | 56 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/lib/hash/blake2/blake2b.h (limited to 'src/lib/hash/blake2/blake2b.h') diff --git a/src/lib/hash/blake2/blake2b.h b/src/lib/hash/blake2/blake2b.h new file mode 100644 index 000000000..d330c1452 --- /dev/null +++ b/src/lib/hash/blake2/blake2b.h @@ -0,0 +1,56 @@ +#ifndef BLAKE2B_H__ +#define BLAKE2B_H__ + +#include +#include +#include + +namespace Botan { + +enum blake2b_constant { + BLAKE2B_BLOCKBYTES = 128, + BLAKE2B_OUTBYTES = 64, + BLAKE2B_IVU64COUNT = 8 +}; + +/** +* BLAKE2B +*/ +class BOTAN_DLL Blake2b final : public HashFunction + { + public: + /** + * @param output_bits the output size of Blake2b in bits + */ + Blake2b(size_t output_bits = 512); + + size_t hash_block_size() const override { return BLAKE2B_BLOCKBYTES; } + size_t output_length() const override { return m_output_bits / 8; } + + static Blake2b* make(const Spec& spec); + + HashFunction* clone() const override; + std::string name() const override; + void clear() override; + + private: + void add_data(const byte input[], size_t length) override; + void final_result(byte out[]) override; + + inline void state_init(); + inline void increment_counter(const u64bit inc); + void compress(bool lastblock = false); + + size_t m_output_bits; + + secure_vector m_buffer; + size_t m_buflen; + + secure_vector m_H; + u64bit m_T[2]; + u64bit m_F[2]; + }; + +} + +#endif -- cgit v1.2.3