/src/botan/build/include/botan/sha3.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * SHA-3 |
3 | | * (C) 2010,2016 Jack Lloyd |
4 | | * |
5 | | * Botan is released under the Simplified BSD License (see license.txt) |
6 | | */ |
7 | | |
8 | | #ifndef BOTAN_SHA3_H_ |
9 | | #define BOTAN_SHA3_H_ |
10 | | |
11 | | #include <botan/hash.h> |
12 | | #include <botan/secmem.h> |
13 | | #include <string> |
14 | | |
15 | | BOTAN_FUTURE_INTERNAL_HEADER(sha3.h) |
16 | | |
17 | | namespace Botan { |
18 | | |
19 | | /** |
20 | | * SHA-3 |
21 | | */ |
22 | | class BOTAN_PUBLIC_API(2,0) SHA_3 : public HashFunction |
23 | | { |
24 | | public: |
25 | | |
26 | | /** |
27 | | * @param output_bits the size of the hash output; must be one of |
28 | | * 224, 256, 384, or 512 |
29 | | */ |
30 | | explicit SHA_3(size_t output_bits); |
31 | | |
32 | 0 | size_t hash_block_size() const override { return m_bitrate / 8; } |
33 | 0 | size_t output_length() const override { return m_output_bits / 8; } |
34 | | |
35 | | HashFunction* clone() const override; |
36 | | std::unique_ptr<HashFunction> copy_state() const override; |
37 | | std::string name() const override; |
38 | | void clear() override; |
39 | | std::string provider() const override; |
40 | | |
41 | | // Static functions for internal usage |
42 | | |
43 | | /** |
44 | | * Absorb data into the provided state |
45 | | * @param bitrate the bitrate to absorb into the sponge |
46 | | * @param S the sponge state |
47 | | * @param S_pos where to begin absorbing into S |
48 | | * @param input the input data |
49 | | * @param length size of input in bytes |
50 | | */ |
51 | | static size_t absorb(size_t bitrate, |
52 | | secure_vector<uint64_t>& S, size_t S_pos, |
53 | | const uint8_t input[], size_t length); |
54 | | |
55 | | /** |
56 | | * Add final padding and permute. The padding is assumed to be |
57 | | * init_pad || 00... || fini_pad |
58 | | * |
59 | | * @param bitrate the bitrate to absorb into the sponge |
60 | | * @param S the sponge state |
61 | | * @param S_pos where to begin absorbing into S |
62 | | * @param init_pad the leading pad bits |
63 | | * @param fini_pad the final pad bits |
64 | | */ |
65 | | static void finish(size_t bitrate, |
66 | | secure_vector<uint64_t>& S, size_t S_pos, |
67 | | uint8_t init_pad, uint8_t fini_pad); |
68 | | |
69 | | /** |
70 | | * Expand from provided state |
71 | | * @param bitrate sponge parameter |
72 | | * @param S the state |
73 | | * @param output the output buffer |
74 | | * @param output_length the size of output in bytes |
75 | | */ |
76 | | static void expand(size_t bitrate, |
77 | | secure_vector<uint64_t>& S, |
78 | | uint8_t output[], size_t output_length); |
79 | | |
80 | | /** |
81 | | * The bare Keccak-1600 permutation |
82 | | */ |
83 | | static void permute(uint64_t A[25]); |
84 | | |
85 | | private: |
86 | | void add_data(const uint8_t input[], size_t length) override; |
87 | | void final_result(uint8_t out[]) override; |
88 | | |
89 | | #if defined(BOTAN_HAS_SHA3_BMI2) |
90 | | static void permute_bmi2(uint64_t A[25]); |
91 | | #endif |
92 | | |
93 | | size_t m_output_bits, m_bitrate; |
94 | | secure_vector<uint64_t> m_S; |
95 | | size_t m_S_pos; |
96 | | }; |
97 | | |
98 | | /** |
99 | | * SHA-3-224 |
100 | | */ |
101 | | class BOTAN_PUBLIC_API(2,0) SHA_3_224 final : public SHA_3 |
102 | | { |
103 | | public: |
104 | 0 | SHA_3_224() : SHA_3(224) {} |
105 | | }; |
106 | | |
107 | | /** |
108 | | * SHA-3-256 |
109 | | */ |
110 | | class BOTAN_PUBLIC_API(2,0) SHA_3_256 final : public SHA_3 |
111 | | { |
112 | | public: |
113 | 0 | SHA_3_256() : SHA_3(256) {} |
114 | | }; |
115 | | |
116 | | /** |
117 | | * SHA-3-384 |
118 | | */ |
119 | | class BOTAN_PUBLIC_API(2,0) SHA_3_384 final : public SHA_3 |
120 | | { |
121 | | public: |
122 | 0 | SHA_3_384() : SHA_3(384) {} |
123 | | }; |
124 | | |
125 | | /** |
126 | | * SHA-3-512 |
127 | | */ |
128 | | class BOTAN_PUBLIC_API(2,0) SHA_3_512 final : public SHA_3 |
129 | | { |
130 | | public: |
131 | 0 | SHA_3_512() : SHA_3(512) {} |
132 | | }; |
133 | | |
134 | | } |
135 | | |
136 | | #endif |