Botan 3.13.0
Crypto and TLS for C&
shake.h
Go to the documentation of this file.
1/*
2* SHAKE hash functions
3* (C) 2010,2016 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#ifndef BOTAN_SHAKE_HASH_H_
9#define BOTAN_SHAKE_HASH_H_
10
11#include <botan/hash.h>
12#include <botan/internal/keccak_perm.h>
13
14#include <algorithm>
15#include <string>
16
17namespace Botan {
18
19/**
20* SHAKE-128
21*/
23 public:
24 /**
25 * @param output_bits the desired output size in bits
26 * must be a multiple of 8
27 */
28 explicit SHAKE_128(size_t output_bits);
29
30 size_t hash_block_size() const override { return m_keccak.byte_rate(); }
31
32 size_t output_length() const override { return m_output_bits / 8; }
33
34 size_t security_level() const override { return std::min<size_t>(m_output_bits / 2, 128); }
35
36 std::unique_ptr<HashFunction> new_object() const override;
37 std::unique_ptr<HashFunction> copy_state() const override;
38 std::string name() const override;
39
40 void clear() override { m_keccak.clear(); }
41
42 std::string provider() const override { return m_keccak.provider(); }
43
44 private:
45 void add_data(std::span<const uint8_t> input) override;
46 void final_result(std::span<uint8_t> out) override;
47
48 Keccak_Permutation m_keccak;
49 size_t m_output_bits;
50};
51
52/**
53* SHAKE-256
54*/
56 public:
57 /**
58 * @param output_bits the desired output size in bits
59 * must be a multiple of 8
60 */
61 explicit SHAKE_256(size_t output_bits);
62
63 size_t hash_block_size() const override { return m_keccak.byte_rate(); }
64
65 size_t output_length() const override { return m_output_bits / 8; }
66
67 size_t security_level() const override { return std::min<size_t>(m_output_bits / 2, 256); }
68
69 std::unique_ptr<HashFunction> new_object() const override;
70 std::unique_ptr<HashFunction> copy_state() const override;
71 std::string name() const override;
72
73 void clear() override { m_keccak.clear(); }
74
75 std::string provider() const override { return m_keccak.provider(); }
76
77 private:
78 void add_data(std::span<const uint8_t> input) override;
79 void final_result(std::span<uint8_t> out) override;
80
81 Keccak_Permutation m_keccak;
82 size_t m_output_bits;
83};
84
85} // namespace Botan
86
87#endif
void final(uint8_t out[])
Definition buf_comp.h:97
std::unique_ptr< HashFunction > new_object() const override
Definition shake.cpp:26
SHAKE_128(size_t output_bits)
Definition shake.cpp:15
std::string provider() const override
Definition shake.h:42
void clear() override
Definition shake.h:40
size_t hash_block_size() const override
Definition shake.h:30
std::string name() const override
Definition shake.cpp:22
size_t output_length() const override
Definition shake.h:32
size_t security_level() const override
Definition shake.h:34
std::unique_ptr< HashFunction > copy_state() const override
Definition shake.cpp:30
std::unique_ptr< HashFunction > new_object() const override
Definition shake.cpp:55
size_t security_level() const override
Definition shake.h:67
size_t output_length() const override
Definition shake.h:65
void clear() override
Definition shake.h:73
SHAKE_256(size_t output_bits)
Definition shake.cpp:44
std::string provider() const override
Definition shake.h:75
size_t hash_block_size() const override
Definition shake.h:63
std::string name() const override
Definition shake.cpp:51
std::unique_ptr< HashFunction > copy_state() const override
Definition shake.cpp:59