Botan 3.6.1
Crypto and TLS for C&
blake2b.h
Go to the documentation of this file.
1/*
2* BLAKE2b
3* (C) 2016 cynecx
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#ifndef BOTAN_BLAKE2B_H_
9#define BOTAN_BLAKE2B_H_
10
11#include <botan/hash.h>
12#include <botan/sym_algo.h>
13#include <botan/internal/alignment_buffer.h>
14#include <memory>
15#include <string>
16
17namespace Botan {
18
19class BLAKE2bMAC;
20
21constexpr size_t BLAKE2B_BLOCKBYTES = 128;
22
23/**
24* BLAKE2B
25*/
26class BLAKE2b final : public HashFunction,
27 public SymmetricAlgorithm {
28 public:
29 /**
30 * @param output_bits the output size of BLAKE2b in bits
31 */
32 explicit BLAKE2b(size_t output_bits = 512);
33
34 size_t hash_block_size() const override { return 128; }
35
36 size_t output_length() const override { return m_output_bits / 8; }
37
38 size_t key_size() const { return m_key_size; }
39
40 Key_Length_Specification key_spec() const override;
41
42 std::unique_ptr<HashFunction> new_object() const override;
43 std::string name() const override;
44 void clear() override;
45 bool has_keying_material() const override;
46
47 std::unique_ptr<HashFunction> copy_state() const override;
48
49 protected:
50 friend class BLAKE2bMAC;
51
52 void key_schedule(std::span<const uint8_t> key) override;
53
54 void add_data(std::span<const uint8_t> input) override;
55 void final_result(std::span<uint8_t> out) override;
56
57 private:
58 void state_init();
59 void compress(const uint8_t* data, size_t blocks, uint64_t increment);
60
61 const size_t m_output_bits;
62
64
66 uint64_t m_T[2];
67 uint64_t m_F;
68
69 size_t m_key_size;
70 secure_vector<uint8_t> m_padded_key_buffer;
71};
72
73} // namespace Botan
74
75#endif
Alignment buffer helper.
size_t key_size() const
Definition blake2b.h:38
BLAKE2b(size_t output_bits=512)
Definition blake2b.cpp:36
Key_Length_Specification key_spec() const override
Definition blake2b.cpp:168
void key_schedule(std::span< const uint8_t > key) override
Definition blake2b.cpp:188
size_t output_length() const override
Definition blake2b.h:36
std::unique_ptr< HashFunction > new_object() const override
Definition blake2b.cpp:176
size_t hash_block_size() const override
Definition blake2b.h:34
std::string name() const override
Definition blake2b.cpp:172
bool has_keying_material() const override
Definition blake2b.cpp:184
void add_data(std::span< const uint8_t > input) override
Definition blake2b.cpp:141
void clear() override
Definition blake2b.cpp:203
std::unique_ptr< HashFunction > copy_state() const override
Definition blake2b.cpp:180
void final_result(std::span< uint8_t > out) override
Definition blake2b.cpp:158
int(* final)(unsigned char *, CTX *)
constexpr size_t BLAKE2B_BLOCKBYTES
Definition blake2b.h:21
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61