Botan 3.9.0
Crypto and TLS for C&
blake2s.h
Go to the documentation of this file.
1/*
2 * BLAKE2s
3 * (C) 2023 Richard Huveneers
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7
8#ifndef BOTAN_BLAKE2S_H_
9#define BOTAN_BLAKE2S_H_
10
11#include <botan/hash.h>
12
13namespace Botan {
14
15/**
16 * BLAKE2s
17 */
18class BLAKE2s final : public HashFunction /* NOLINT(*-special-member-functions) */ {
19 public:
20 explicit BLAKE2s(size_t output_bits = 256);
21 ~BLAKE2s() override;
22
23 std::string name() const override;
24
25 size_t output_length() const override { return m_outlen; }
26
27 size_t hash_block_size() const override { return 64; }
28
29 std::unique_ptr<HashFunction> copy_state() const override;
30
31 std::unique_ptr<HashFunction> new_object() const override { return std::make_unique<BLAKE2s>(m_outlen << 3); }
32
33 void clear() override;
34
35 private:
36 void add_data(std::span<const uint8_t> input) override;
37 void final_result(std::span<uint8_t> output) override;
38 void state_init(size_t outlen, const uint8_t* key, size_t keylen);
39 void compress(bool last);
40
41 // TODO use secure_vector here
42 uint8_t m_b[64]{}; // input buffer
43 uint32_t m_h[8]{}; // chained state
44 uint32_t m_t[2]{}; // total number of bytes
45 uint8_t m_c = 0; // pointer for b[]
46 size_t m_outlen = 0; // digest size
47};
48
49} // namespace Botan
50
51#endif
void clear() override
Definition blake2s.cpp:116
std::unique_ptr< HashFunction > new_object() const override
Definition blake2s.h:31
std::unique_ptr< HashFunction > copy_state() const override
Definition blake2s.cpp:152
~BLAKE2s() override
Definition blake2s.cpp:171
size_t hash_block_size() const override
Definition blake2s.h:27
BLAKE2s(size_t output_bits=256)
Definition blake2s.cpp:164
std::string name() const override
Definition blake2s.cpp:41
size_t output_length() const override
Definition blake2s.h:25
void final(uint8_t out[])
Definition buf_comp.h:69