Botan  2.8.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  * Add final padding and permute. The padding is assumed to be
54  * init_pad || 00... || fini_pad
55  *
56  * @param bitrate the bitrate to absorb into the sponge
57  * @param S the sponge state
58  * @param S_pos where to begin absorbing into S
59  * @param init_pad the leading pad bits
60  * @param fini_pad the final pad bits
61  */
62  static void finish(size_t bitrate,
63  secure_vector<uint64_t>& S, size_t S_pos,
64  uint8_t init_pad, uint8_t fini_pad);
65 
66  /**
67  * Expand from provided state
68  * @param bitrate sponge parameter
69  * @param S the state
70  * @param output the output buffer
71  * @param output_length the size of output in bytes
72  */
73  static void expand(size_t bitrate,
75  uint8_t output[], size_t output_length);
76 
77  /**
78  * The bare Keccak-1600 permutation
79  */
80  static void permute(uint64_t A[25]);
81 
82  private:
83  void add_data(const uint8_t input[], size_t length) override;
84  void final_result(uint8_t out[]) override;
85 
86  size_t m_output_bits, m_bitrate;
88  size_t m_S_pos;
89  };
90 
91 /**
92 * SHA-3-224
93 */
95  {
96  public:
97  SHA_3_224() : SHA_3(224) {}
98  };
99 
100 /**
101 * SHA-3-256
102 */
104  {
105  public:
106  SHA_3_256() : SHA_3(256) {}
107  };
108 
109 /**
110 * SHA-3-384
111 */
113  {
114  public:
115  SHA_3_384() : SHA_3(384) {}
116  };
117 
118 /**
119 * SHA-3-512
120 */
122  {
123  public:
124  SHA_3_512() : SHA_3(512) {}
125  };
126 
127 }
128 
129 #endif
size_t hash_block_size() const override
Definition: sha3.h:30
int(* final)(unsigned char *, CTX *)
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
std::string name
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