Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

sha3.h
Go to the documentation of this file.
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 namespace Botan {
16
17 /**
18 * SHA-3
19 */
20 class BOTAN_DLL SHA_3 : public HashFunction
21 {
22 public:
23
24 /**
25 * @param output_bits the size of the hash output; must be one of
26 * 224, 256, 384, or 512
27 */
28 SHA_3(size_t output_bits);
29
30 size_t hash_block_size() const override { return m_bitrate / 8; }
31 size_t output_length() const override { return m_output_bits / 8; }
32
33 HashFunction* clone() const override;
34 std::string name() const override;
35 void clear() override;
36
37 // Static functions for internal usage
38
39 /**
40 * Absorb data into the provided state
41 * @param bitrate the bitrate to absorb into the sponge
42 * @param S the sponge state
43 * @param S_pos where to begin absorbing into S
44 * @param input the input data
45 * @param length size of input in bytes
46 */
47 static size_t absorb(size_t bitrate,
48 secure_vector<uint64_t>& S, size_t S_pos,
49 const uint8_t input[], size_t length);
50
51 /**
52 * Expand from provided state
53 * @param bitrate sponge parameter
54 * @param S the state
55 * @param output the output buffer
56 * @param output_length the size of output in bytes
57 */
58 static void expand(size_t bitrate,
59 secure_vector<uint64_t>& S,
60 uint8_t output[], size_t output_length);
61
62 /**
63 * The bare Keccak-1600 permutation
64 */
65 static void permute(uint64_t A[25]);
66
67 private:
68 void add_data(const uint8_t input[], size_t length) override;
69 void final_result(uint8_t out[]) override;
70
71 size_t m_output_bits, m_bitrate;
72 secure_vector<uint64_t> m_S;
73 size_t m_S_pos;
74 };
75
76 /**
77 * SHA-3-224
78 */
79 class BOTAN_DLL SHA_3_224 final : public SHA_3
80 {
81 public:
82 SHA_3_224() : SHA_3(224) {}
83 };
84
85 /**
86 * SHA-3-256
87 */
88 class BOTAN_DLL SHA_3_256 final : public SHA_3
89 {
90 public:
91 SHA_3_256() : SHA_3(256) {}
92 };
93
94 /**
95 * SHA-3-384
96 */
97 class BOTAN_DLL SHA_3_384 final : public SHA_3
98 {
99 public:
100 SHA_3_384() : SHA_3(384) {}
101 };
102
103 /**
104 * SHA-3-512
105 */
106 class BOTAN_DLL SHA_3_512 final : public SHA_3
107 {
108 public:
109 SHA_3_512() : SHA_3(512) {}
110 };
111
112 }
113
114 #endif
Botan::SHA_3_256::SHA_3_256
SHA_3_256()
Definition: sha3.h:91
Botan::SHA_3
Definition: sha3.h:20
Botan::SHA_3_256
Definition: sha3.h:88
Botan::SHA_3::hash_block_size
size_t hash_block_size() const override
Definition: sha3.h:30
Botan::SHA_3_224
Definition: sha3.h:79
Botan::SHA_3_224::SHA_3_224
SHA_3_224()
Definition: sha3.h:82
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:121
Botan::SHA_3_512
Definition: sha3.h:106
Botan::SHA_3_512::SHA_3_512
SHA_3_512()
Definition: sha3.h:109
Botan::SHA_3_384::SHA_3_384
SHA_3_384()
Definition: sha3.h:100
Botan::SHA_3::output_length
size_t output_length() const override
Definition: sha3.h:31
Botan
Definition: alg_id.cpp:13
Botan::HashFunction
Definition: hash.h:19
Botan::SHA_3_384
Definition: sha3.h:97