/src/botan/build/include/botan/internal/shake.h
Line | Count | Source (jump to first uncovered line) |
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/secmem.h> |
13 | | #include <string> |
14 | | |
15 | | namespace Botan { |
16 | | |
17 | | /** |
18 | | * SHAKE-128 |
19 | | */ |
20 | | class SHAKE_128 final : public HashFunction |
21 | | { |
22 | | public: |
23 | | |
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 | 0 | size_t hash_block_size() const override { return SHAKE_128_BITRATE / 8; } |
31 | 0 | size_t output_length() const override { return m_output_bits / 8; } |
32 | | |
33 | | std::unique_ptr<HashFunction> new_object() const override; |
34 | | std::unique_ptr<HashFunction> copy_state() const override; |
35 | | std::string name() const override; |
36 | | void clear() override; |
37 | | |
38 | | private: |
39 | | void add_data(const uint8_t input[], size_t length) override; |
40 | | void final_result(uint8_t out[]) override; |
41 | | |
42 | | static const size_t SHAKE_128_BITRATE = 1600 - 256; |
43 | | |
44 | | size_t m_output_bits; |
45 | | secure_vector<uint64_t> m_S; |
46 | | size_t m_S_pos; |
47 | | }; |
48 | | |
49 | | /** |
50 | | * SHAKE-256 |
51 | | */ |
52 | | class SHAKE_256 final : public HashFunction |
53 | | { |
54 | | public: |
55 | | |
56 | | /** |
57 | | * @param output_bits the desired output size in bits |
58 | | * must be a multiple of 8 |
59 | | */ |
60 | | explicit SHAKE_256(size_t output_bits); |
61 | | |
62 | 0 | size_t hash_block_size() const override { return SHAKE_256_BITRATE / 8; } |
63 | 0 | size_t output_length() const override { return m_output_bits / 8; } |
64 | | |
65 | | std::unique_ptr<HashFunction> new_object() const override; |
66 | | std::unique_ptr<HashFunction> copy_state() const override; |
67 | | std::string name() const override; |
68 | | void clear() override; |
69 | | |
70 | | private: |
71 | | void add_data(const uint8_t input[], size_t length) override; |
72 | | void final_result(uint8_t out[]) override; |
73 | | |
74 | | static const size_t SHAKE_256_BITRATE = 1600 - 512; |
75 | | |
76 | | size_t m_output_bits; |
77 | | secure_vector<uint64_t> m_S; |
78 | | size_t m_S_pos; |
79 | | }; |
80 | | |
81 | | } |
82 | | |
83 | | #endif |