Botan 2.13.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 BOTAN_FUTURE_INTERNAL_HEADER(sha3.h)
16
17 namespace Botan {
18
19 /**
20 * SHA-3
21 */
22 class BOTAN_PUBLIC_API(2,0) SHA_3 : public HashFunction
23 {
24 public:
25
26 /**
27 * @param output_bits the size of the hash output; must be one of
28 * 224, 256, 384, or 512
29 */
30 explicit SHA_3(size_t output_bits);
31
32 size_t hash_block_size() const override { return m_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 std::string provider() const override;
40
41 // Static functions for internal usage
42
43 /**
44 * Absorb data into the provided state
45 * @param bitrate the bitrate to absorb into the sponge
46 * @param S the sponge state
47 * @param S_pos where to begin absorbing into S
48 * @param input the input data
49 * @param length size of input in bytes
50 */
51 static size_t absorb(size_t bitrate,
52 secure_vector<uint64_t>& S, size_t S_pos,
53 const uint8_t input[], size_t length);
54
55 /**
56 * Add final padding and permute. The padding is assumed to be
57 * init_pad || 00... || fini_pad
58 *
59 * @param bitrate the bitrate to absorb into the sponge
60 * @param S the sponge state
61 * @param S_pos where to begin absorbing into S
62 * @param init_pad the leading pad bits
63 * @param fini_pad the final pad bits
64 */
65 static void finish(size_t bitrate,
66 secure_vector<uint64_t>& S, size_t S_pos,
67 uint8_t init_pad, uint8_t fini_pad);
68
69 /**
70 * Expand from provided state
71 * @param bitrate sponge parameter
72 * @param S the state
73 * @param output the output buffer
74 * @param output_length the size of output in bytes
75 */
76 static void expand(size_t bitrate,
77 secure_vector<uint64_t>& S,
78 uint8_t output[], size_t output_length);
79
80 /**
81 * The bare Keccak-1600 permutation
82 */
83 static void permute(uint64_t A[25]);
84
85 private:
86 void add_data(const uint8_t input[], size_t length) override;
87 void final_result(uint8_t out[]) override;
88
89 #if defined(BOTAN_HAS_SHA3_BMI2)
90 static void permute_bmi2(uint64_t A[25]);
91 #endif
92
93 size_t m_output_bits, m_bitrate;
94 secure_vector<uint64_t> m_S;
95 size_t m_S_pos;
96 };
97
98 /**
99 * SHA-3-224
100 */
101 class BOTAN_PUBLIC_API(2,0) SHA_3_224 final : public SHA_3
102 {
103 public:
104 SHA_3_224() : SHA_3(224) {}
105 };
106
107 /**
108 * SHA-3-256
109 */
110 class BOTAN_PUBLIC_API(2,0) SHA_3_256 final : public SHA_3
111 {
112 public:
113 SHA_3_256() : SHA_3(256) {}
114 };
115
116 /**
117 * SHA-3-384
118 */
119 class BOTAN_PUBLIC_API(2,0) SHA_3_384 final : public SHA_3
120 {
121 public:
122 SHA_3_384() : SHA_3(384) {}
123 };
124
125 /**
126 * SHA-3-512
127 */
128 class BOTAN_PUBLIC_API(2,0) SHA_3_512 final : public SHA_3
129 {
130 public:
131 SHA_3_512() : SHA_3(512) {}
132 };
133
134 }
135
136 #endif
Botan::SHA_3_256::SHA_3_256
SHA_3_256()
Definition: sha3.h:113
Botan::SHA_3
Definition: sha3.h:22
Botan::SHA_3_256
Definition: sha3.h:110
Botan::SHA_3::hash_block_size
size_t hash_block_size() const override
Definition: sha3.h:32
Botan::SHA_3_224
Definition: sha3.h:101
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::provider
virtual std::string provider() const
Definition: hash.h:58
Botan::HashFunction::name
virtual std::string name() const =0
Botan::HashFunction::clone
virtual HashFunction * clone() const =0
Botan::SHA_3_224::SHA_3_224
SHA_3_224()
Definition: sha3.h:104
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:65
Botan::SHA_3_512
Definition: sha3.h:128
Botan::SHA_3_512::SHA_3_512
SHA_3_512()
Definition: sha3.h:131
Botan::SHA_3_384::SHA_3_384
SHA_3_384()
Definition: sha3.h:122
Botan::SHA_3::output_length
size_t output_length() const override
Definition: sha3.h:33
Botan
Definition: alg_id.cpp:13
Botan::HashFunction
Definition: hash.h:20
Botan::HashFunction::clear
virtual void clear()=0
Botan::HashFunction::copy_state
virtual std::unique_ptr< HashFunction > copy_state() const =0
Botan::SHA_3_384
Definition: sha3.h:119
BOTAN_FUTURE_INTERNAL_HEADER
#define BOTAN_FUTURE_INTERNAL_HEADER(hdr)
Definition: compiler.h:139