Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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 BOTAN_FUTURE_INTERNAL_HEADER(shake.h)
16
17 namespace Botan {
18
19 /**
20 * SHAKE-128
21 */
22 class BOTAN_PUBLIC_API(2,0) SHAKE_128 final : public HashFunction
23 {
24 public:
25
26 /**
27 * @param output_bits the desired output size in bits
28 * must be a multiple of 8
29 */
30 explicit SHAKE_128(size_t output_bits);
31
32 size_t hash_block_size() const override { return SHAKE_128_BITRATE / 8; }
33 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
40 private:
41 void add_data(const uint8_t input[], size_t length) override;
42 void final_result(uint8_t out[]) override;
43
44 static const size_t SHAKE_128_BITRATE = 1600 - 256;
45
46 size_t m_output_bits;
47 secure_vector<uint64_t> m_S;
48 size_t m_S_pos;
49 };
50
51 /**
52 * SHAKE-256
53 */
54 class BOTAN_PUBLIC_API(2,0) SHAKE_256 final : public HashFunction
55 {
56 public:
57
58 /**
59 * @param output_bits the desired output size in bits
60 * must be a multiple of 8
61 */
62 explicit SHAKE_256(size_t output_bits);
63
64 size_t hash_block_size() const override { return SHAKE_256_BITRATE / 8; }
65 size_t output_length() const override { return m_output_bits / 8; }
66
67 HashFunction* clone() const override;
68 std::unique_ptr<HashFunction> copy_state() const override;
69 std::string name() const override;
70 void clear() override;
71
72 private:
73 void add_data(const uint8_t input[], size_t length) override;
74 void final_result(uint8_t out[]) override;
75
76 static const size_t SHAKE_256_BITRATE = 1600 - 512;
77
78 size_t m_output_bits;
79 secure_vector<uint64_t> m_S;
80 size_t m_S_pos;
81 };
82
83 }
84
85 #endif
final
int(* final)(unsigned char *, CTX *)
Definition: commoncrypto_hash.cpp:28
BOTAN_PUBLIC_API
#define BOTAN_PUBLIC_API(maj, min)
Definition: compiler.h:31
Botan::HashFunction::name
virtual std::string name() const =0
Botan::HashFunction::clone
virtual HashFunction * clone() const =0
Botan::SHAKE_256::hash_block_size
size_t hash_block_size() const override
Definition: shake.h:64
Botan::SHAKE_128
Definition: shake.h:22
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:65
Botan::SHAKE_128::output_length
size_t output_length() const override
Definition: shake.h:33
Botan::SHAKE_128::hash_block_size
size_t hash_block_size() const override
Definition: shake.h:32
Botan
Definition: alg_id.cpp:13
Botan::SHAKE_256::output_length
size_t output_length() const override
Definition: shake.h:65
Botan::HashFunction
Definition: hash.h:20
Botan::SHAKE_256
Definition: shake.h:54
Botan::HashFunction::clear
virtual void clear()=0
Botan::HashFunction::copy_state
virtual std::unique_ptr< HashFunction > copy_state() const =0
BOTAN_FUTURE_INTERNAL_HEADER
#define BOTAN_FUTURE_INTERNAL_HEADER(hdr)
Definition: compiler.h:139