blob: c52df136b7b6f2fb3d49786f61d5afa2fc52605c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
/*
* SHAKE hash functions
* (C) 2010,2016 Jack Lloyd
*
* Botan is released under the Simplified BSD License (see license.txt)
*/
#ifndef BOTAN_SHAKE_HASH_H_
#define BOTAN_SHAKE_HASH_H_
#include <botan/hash.h>
#include <botan/secmem.h>
#include <string>
BOTAN_FUTURE_INTERNAL_HEADER(shake.h)
namespace Botan {
/**
* SHAKE-128
*/
class BOTAN_PUBLIC_API(2,0) SHAKE_128 final : public HashFunction
{
public:
/**
* @param output_bits the desired output size in bits
* must be a multiple of 8
*/
explicit SHAKE_128(size_t output_bits);
size_t hash_block_size() const override { return SHAKE_128_BITRATE / 8; }
size_t output_length() const override { return m_output_bits / 8; }
HashFunction* clone() const override;
std::unique_ptr<HashFunction> copy_state() const override;
std::string name() const override;
void clear() override;
private:
void add_data(const uint8_t input[], size_t length) override;
void final_result(uint8_t out[]) override;
static const size_t SHAKE_128_BITRATE = 1600 - 256;
size_t m_output_bits;
secure_vector<uint64_t> m_S;
size_t m_S_pos;
};
/**
* SHAKE-256
*/
class BOTAN_PUBLIC_API(2,0) SHAKE_256 final : public HashFunction
{
public:
/**
* @param output_bits the desired output size in bits
* must be a multiple of 8
*/
explicit SHAKE_256(size_t output_bits);
size_t hash_block_size() const override { return SHAKE_256_BITRATE / 8; }
size_t output_length() const override { return m_output_bits / 8; }
HashFunction* clone() const override;
std::unique_ptr<HashFunction> copy_state() const override;
std::string name() const override;
void clear() override;
private:
void add_data(const uint8_t input[], size_t length) override;
void final_result(uint8_t out[]) override;
static const size_t SHAKE_256_BITRATE = 1600 - 512;
size_t m_output_bits;
secure_vector<uint64_t> m_S;
size_t m_S_pos;
};
}
#endif
|