18 #ifndef CRYPTOPP_BLAKE2_H 19 #define CRYPTOPP_BLAKE2_H 31 template <
bool T_64bit>
35 CRYPTOPP_CONSTANT(MIN_KEYLENGTH = KeyBase::MIN_KEYLENGTH)
36 CRYPTOPP_CONSTANT(MAX_KEYLENGTH = KeyBase::MAX_KEYLENGTH)
37 CRYPTOPP_CONSTANT(DEFAULT_KEYLENGTH = KeyBase::DEFAULT_KEYLENGTH)
39 CRYPTOPP_CONSTANT(BLOCKSIZE = (T_64bit ? 128 : 64))
40 CRYPTOPP_CONSTANT(DIGESTSIZE = (T_64bit ? 64 : 32))
41 CRYPTOPP_CONSTANT(SALTSIZE = (T_64bit ? 16 : 8))
42 CRYPTOPP_CONSTANT(PERSONALIZATIONSIZE = (T_64bit ? 16 : 8))
44 CRYPTOPP_CONSTEXPR
static const char *StaticAlgorithmName() {
return (T_64bit ?
"BLAKE2b" :
"BLAKE2s");}
53 template <
bool T_64bit>
60 struct CRYPTOPP_NO_VTABLE BLAKE2_ParameterBlock<true>
66 BLAKE2_ParameterBlock()
68 memset(
this, 0x00,
sizeof(*
this));
69 digestLength = DIGESTSIZE;
73 BLAKE2_ParameterBlock(
size_t digestSize)
75 assert(digestSize <= DIGESTSIZE);
76 memset(
this, 0x00,
sizeof(*
this));
77 digestLength = (byte)digestSize;
81 BLAKE2_ParameterBlock(
size_t digestSize,
size_t keyLength,
const byte* salt,
size_t saltLength,
82 const byte* personalization,
size_t personalizationLength);
85 byte keyLength, fanout, depth;
88 byte nodeDepth, innerLength, rfu[14];
90 byte personalization[PERSONALIZATIONSIZE];
95 struct CRYPTOPP_NO_VTABLE BLAKE2_ParameterBlock<false>
101 BLAKE2_ParameterBlock()
103 memset(
this, 0x00,
sizeof(*
this));
104 digestLength = DIGESTSIZE;
108 BLAKE2_ParameterBlock(
size_t digestSize)
110 assert(digestSize <= DIGESTSIZE);
111 memset(
this, 0x00,
sizeof(*
this));
112 digestLength = (byte)digestSize;
116 BLAKE2_ParameterBlock(
size_t digestSize,
size_t keyLength,
const byte* salt,
size_t saltLength,
117 const byte* personalization,
size_t personalizationLength);
120 byte keyLength, fanout, depth;
123 byte nodeDepth, innerLength;
125 byte personalization[PERSONALIZATIONSIZE];
135 template <
class W,
bool T_64bit>
143 h[0]=h[1]=h[2]=h[3]=h[4]=h[5]=h[6]=h[7] = 0;
144 t[0]=t[1]=f[0]=f[1] = 0;
150 byte buffer[BLOCKSIZE];
161 template <
class W,
bool T_64bit>
195 void Update(
const byte *input,
size_t length);
217 void TruncatedFinal(byte *hash,
size_t size);
221 BLAKE2_Base(
bool treeMode,
unsigned int digestSize);
222 BLAKE2_Base(
const byte *key,
size_t keyLength,
const byte* salt,
size_t saltLength,
223 const byte* personalization,
size_t personalizationLength,
224 bool treeMode,
unsigned int digestSize);
227 void Compress(
const byte *input);
228 inline void IncrementCounter(
size_t count=BLOCKSIZE);
230 void UncheckedSetKey(
const byte* key,
unsigned int length,
const CryptoPP::NameValuePairs& params);
233 AlignedState m_state;
234 AlignedParameterBlock m_block;
259 BLAKE2b(
bool treeMode=
false,
unsigned int digestSize = DIGESTSIZE) : ThisBase(treeMode, digestSize) {}
270 BLAKE2b(
const byte *key,
size_t keyLength,
const byte* salt = NULL,
size_t saltLength = 0,
271 const byte* personalization = NULL,
size_t personalizationLength = 0,
272 bool treeMode=
false,
unsigned int digestSize = DIGESTSIZE)
273 : ThisBase(key, keyLength, salt, saltLength, personalization, personalizationLength, treeMode, digestSize) {}
295 BLAKE2s(
bool treeMode=
false,
unsigned int digestSize = DIGESTSIZE) : ThisBase(treeMode, digestSize) {}
306 BLAKE2s(
const byte *key,
size_t keyLength,
const byte* salt = NULL,
size_t saltLength = 0,
307 const byte* personalization = NULL,
size_t personalizationLength = 0,
308 bool treeMode=
false,
unsigned int digestSize = DIGESTSIZE)
309 : ThisBase(key, keyLength, salt, saltLength, personalization, personalizationLength, treeMode, digestSize) {}
const char * DigestSize()
int, in bytes
BLAKE2b(const byte *key, size_t keyLength, const byte *salt=NULL, size_t saltLength=0, const byte *personalization=NULL, size_t personalizationLength=0, bool treeMode=false, unsigned int digestSize=DIGESTSIZE)
Construct a BLAKE2b hash.
BLAKE2 hash implementation.
bool GetTreeMode() const
Get tree mode.
Provides a base implementation of SimpleKeyingInterface.
Secure memory block with allocator and cleanup.
Abstract base classes that provide a uniform interface to this library.
BLAKE2s(bool treeMode=false, unsigned int digestSize=DIGESTSIZE)
Construct a BLAKE2s hash.
The BLAKE2s cryptographic hash function.
Classes and functions for secure memory allocations.
Classes and functions for implementing secret key algorithms.
#define CRYPTOPP_COMPILE_ASSERT(expr)
Compile time assertion.
std::string AlgorithmName() const
Retrieve the object's name.
Interface for algorithms that take byte strings as keys.
SecBlock using AllocatorWithCleanup<byte, true> typedef.
BLAKE2s parameter block specialization.
Inherited by keyed algorithms with variable key length.
BLAKE2 state information.
unsigned int DigestSize() const
Provides the digest size of the hash.
void SetTreeMode(bool mode)
Set tree mode.
std::string IntToString(T value, unsigned int base=10)
Converts a value to a string.
unsigned int OptimalDataAlignment() const
Provides input and output data alignment for optimal performance.
Crypto++ library namespace.
BLAKE2b(bool treeMode=false, unsigned int digestSize=DIGESTSIZE)
Construct a BLAKE2b hash.
BLAKE2s(const byte *key, size_t keyLength, const byte *salt=NULL, size_t saltLength=0, const byte *personalization=NULL, size_t personalizationLength=0, bool treeMode=false, unsigned int digestSize=DIGESTSIZE)
Construct a BLAKE2s hash.
The BLAKE2b cryptographic hash function.
BLAKE2b parameter block specialization.