Security Scol plugin
shake.h
Go to the documentation of this file.
1// shake.h - written and placed in the public domain by Jeffrey Walton
2
12
13#ifndef CRYPTOPP_SHAKE_H
14#define CRYPTOPP_SHAKE_H
15
16#include "cryptlib.h"
17#include "secblock.h"
18
19NAMESPACE_BEGIN(CryptoPP)
20
21
30{
31protected:
40 SHAKE(unsigned int digestSize) : m_digestSize(digestSize) {Restart();}
41
42public:
43 unsigned int DigestSize() const {return m_digestSize;}
44 unsigned int OptimalDataAlignment() const {return GetAlignmentOf<word64>();}
45
46 void Update(const byte *input, size_t length);
47 void Restart();
48 void TruncatedFinal(byte *hash, size_t size);
49
50protected:
51 inline unsigned int r() const {return BlockSize();}
52
53 // SHAKE-128 and SHAKE-256 effectively allow unlimited
54 // output length. However, we use an unsigned int so
55 // we are limited in practice to UINT_MAX.
56 void ThrowIfInvalidTruncatedSize(size_t size) const;
57
59 unsigned int m_digestSize, m_counter;
60};
61
65template<unsigned int T_Strength>
66class SHAKE_Final : public SHAKE
67{
68public:
69 CRYPTOPP_CONSTANT(DIGESTSIZE = (T_Strength == 128 ? 32 : 64));
70 CRYPTOPP_CONSTANT(BLOCKSIZE = (T_Strength == 128 ? 1344/8 : 1088/8));
71 static std::string StaticAlgorithmName()
72 { return "SHAKE-" + IntToString(T_Strength); }
73
80 SHAKE_Final(unsigned int outputSize=DIGESTSIZE) : SHAKE(outputSize) {}
81
88 unsigned int BlockSize() const { return BLOCKSIZE; }
89
90 std::string AlgorithmName() const { return StaticAlgorithmName(); }
91
92private:
93#if !defined(__BORLANDC__)
94 // ensure there was no underflow in the math
95 CRYPTOPP_COMPILE_ASSERT(BLOCKSIZE < 200);
96#endif
97};
98
107class SHAKE128 : public SHAKE_Final<128>
108{
109public:
118
126 SHAKE128(unsigned int outputSize) : SHAKE_Final<128>(outputSize) {}
127};
128
137class SHAKE256 : public SHAKE_Final<256>
138{
139public:
148
156 SHAKE256(unsigned int outputSize) : SHAKE_Final<256>(outputSize) {}
157};
158
159NAMESPACE_END
160
161#endif
Fixed size stack-based SecBlock.
Definition secblock.h:1246
Interface for hash functions and data processing part of MACs.
Definition cryptlib.h:1113
SHAKE128 message digest.
Definition shake.h:108
SHAKE128(unsigned int outputSize)
Construct a SHAKE128 message digest.
Definition shake.h:126
SHAKE128()
Construct a SHAKE128 message digest.
Definition shake.h:117
SHAKE256 message digest.
Definition shake.h:138
SHAKE256(unsigned int outputSize)
Construct a SHAKE256 message digest.
Definition shake.h:156
SHAKE256()
Construct a SHAKE256 message digest.
Definition shake.h:147
SHAKE message digest template.
Definition shake.h:67
unsigned int BlockSize() const
Provides the block size of the compression function.
Definition shake.h:88
SHAKE_Final(unsigned int outputSize=DIGESTSIZE)
Construct a SHAKE-X message digest.
Definition shake.h:80
std::string AlgorithmName() const
Provides the name of this algorithm.
Definition shake.h:90
SHAKE message digest base class.
Definition shake.h:30
SHAKE(unsigned int digestSize)
Construct a SHAKE.
Definition shake.h:40
unsigned int OptimalDataAlignment() const
Provides input and output data alignment for optimal performance.
Definition shake.h:44
unsigned int DigestSize() const
Definition shake.h:43
Abstract base classes that provide a uniform interface to this library.
std::string IntToString(T value, unsigned int base=10)
Converts a value to a string.
Definition misc.h:724
Classes and functions for secure memory allocations.