Botan  2.6.0
Crypto and TLS for C++11
shake.h
Go to the documentation of this file.
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 BOTAN_PUBLIC_API(2,0) 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  size_t hash_block_size() const override { return SHAKE_128_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  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;
46  size_t m_S_pos;
47  };
48 
49 /**
50 * SHAKE-256
51 */
52 class BOTAN_PUBLIC_API(2,0) 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  size_t hash_block_size() const override { return SHAKE_256_BITRATE / 8; }
63  size_t output_length() const override { return m_output_bits / 8; }
64 
65  HashFunction* clone() 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;
78  size_t m_S_pos;
79  };
80 
81 }
82 
83 #endif
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:27
size_t hash_block_size() const override
Definition: shake.h:62
size_t output_length() const override
Definition: shake.h:31
size_t hash_block_size() const override
Definition: shake.h:30
Definition: alg_id.cpp:13
size_t output_length() const override
Definition: shake.h:63
std::vector< T, secure_allocator< T > > secure_vector
Definition: secmem.h:88