Botan  2.4.0
Crypto and TLS for C++11
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_PUBLIC_API(2,0) 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  explicit 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::unique_ptr<HashFunction> copy_state() const override;
35  std::string name() const override;
36  void clear() override;
37 
38  // Static functions for internal usage
39 
40  /**
41  * Absorb data into the provided state
42  * @param bitrate the bitrate to absorb into the sponge
43  * @param S the sponge state
44  * @param S_pos where to begin absorbing into S
45  * @param input the input data
46  * @param length size of input in bytes
47  */
48  static size_t absorb(size_t bitrate,
49  secure_vector<uint64_t>& S, size_t S_pos,
50  const uint8_t input[], size_t length);
51 
52  /**
53  * Expand from provided state
54  * @param bitrate sponge parameter
55  * @param S the state
56  * @param output the output buffer
57  * @param output_length the size of output in bytes
58  */
59  static void expand(size_t bitrate,
61  uint8_t output[], size_t output_length);
62 
63  /**
64  * The bare Keccak-1600 permutation
65  */
66  static void permute(uint64_t A[25]);
67 
68  private:
69  void add_data(const uint8_t input[], size_t length) override;
70  void final_result(uint8_t out[]) override;
71 
72  size_t m_output_bits, m_bitrate;
74  size_t m_S_pos;
75  };
76 
77 /**
78 * SHA-3-224
79 */
80 class BOTAN_PUBLIC_API(2,0) SHA_3_224 final : public SHA_3
81  {
82  public:
83  SHA_3_224() : SHA_3(224) {}
84  };
85 
86 /**
87 * SHA-3-256
88 */
89 class BOTAN_PUBLIC_API(2,0) SHA_3_256 final : public SHA_3
90  {
91  public:
92  SHA_3_256() : SHA_3(256) {}
93  };
94 
95 /**
96 * SHA-3-384
97 */
98 class BOTAN_PUBLIC_API(2,0) SHA_3_384 final : public SHA_3
99  {
100  public:
101  SHA_3_384() : SHA_3(384) {}
102  };
103 
104 /**
105 * SHA-3-512
106 */
107 class BOTAN_PUBLIC_API(2,0) SHA_3_512 final : public SHA_3
108  {
109  public:
110  SHA_3_512() : SHA_3(512) {}
111  };
112 
113 }
114 
115 #endif
size_t hash_block_size() const override
Definition: sha3.h:30
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
size_t output_length() const override
Definition: sha3.h:31
Definition: alg_id.cpp:13
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88