Botan 3.10.0
Crypto and TLS for C&
blake2s.h
Go to the documentation of this file.
1/*
2 * BLAKE2s
3 * (C) 2023, 2025 Richard Huveneers
4 * (C) 2025 Kagan Can Sit
5 * (C) 2025 René Meusel, Rohde & Schwarz Cybersecurity
6 *
7 * Botan is released under the Simplified BSD License (see license.txt)
8 */
9
10#ifndef BOTAN_BLAKE2S_H_
11#define BOTAN_BLAKE2S_H_
12
13#include <botan/hash.h>
14#include <botan/internal/alignment_buffer.h>
15
16namespace Botan {
17
18/**
19 * BLAKE2s
20 */
21class BLAKE2s final : public HashFunction {
22 private:
23 static constexpr size_t block_size = 64;
24
25 public:
26 explicit BLAKE2s(size_t output_bits = 256);
27 ~BLAKE2s() override;
28
29 BLAKE2s(const BLAKE2s&) = default;
30 BLAKE2s& operator=(const BLAKE2s&) = delete;
31 BLAKE2s(BLAKE2s&&) = delete;
33
34 std::string name() const override;
35
36 size_t output_length() const override { return m_outlen; }
37
38 size_t hash_block_size() const override { return block_size; }
39
40 std::unique_ptr<HashFunction> copy_state() const override;
41
42 std::unique_ptr<HashFunction> new_object() const override { return std::make_unique<BLAKE2s>(m_outlen << 3); }
43
44 void clear() override;
45
46 private:
47 void add_data(std::span<const uint8_t> input) override;
48 void final_result(std::span<uint8_t> output) override;
49 void state_init(size_t outlen);
50 void compress(bool last, std::span<const uint8_t> buf);
51
52 private:
53 uint64_t m_bytes_processed = 0;
55
56 std::array<uint32_t, 8> m_h{}; // chained state
57 size_t m_outlen = 0; // digest size
58};
59
60} // namespace Botan
61
62#endif
Alignment buffer helper.
BLAKE2s(const BLAKE2s &)=default
void clear() override
Definition blake2s.cpp:106
BLAKE2s(BLAKE2s &&)=delete
std::unique_ptr< HashFunction > new_object() const override
Definition blake2s.h:42
BLAKE2s & operator=(const BLAKE2s &)=delete
std::unique_ptr< HashFunction > copy_state() const override
Definition blake2s.cpp:140
~BLAKE2s() override
Definition blake2s.cpp:154
size_t hash_block_size() const override
Definition blake2s.h:38
BLAKE2s(size_t output_bits=256)
Definition blake2s.cpp:147
BLAKE2s & operator=(BLAKE2s &&)=delete
std::string name() const override
Definition blake2s.cpp:46
size_t output_length() const override
Definition blake2s.h:36
void final(uint8_t out[])
Definition buf_comp.h:69