18 #ifndef CRYPTOPP_BLAKE2_H
19 #define CRYPTOPP_BLAKE2_H
25 NAMESPACE_BEGIN(CryptoPP)
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>
68 memset(
this, 0x00,
sizeof(*
this));
69 digestLength = DIGESTSIZE;
76 memset(
this, 0x00,
sizeof(*
this));
77 digestLength = (byte)digestSize;
82 const byte* personalization,
size_t personalizationLength);
85 byte keyLength, fanout, depth;
88 byte nodeDepth, innerLength, rfu[14];
90 byte personalization[PERSONALIZATIONSIZE];
103 memset(
this, 0x00,
sizeof(*
this));
104 digestLength = DIGESTSIZE;
111 memset(
this, 0x00,
sizeof(*
this));
112 digestLength = (byte)digestSize;
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);
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) {}
void Restart()
Restart the hash.
unsigned int OptimalDataAlignment() const
Provides input and output data alignment for optimal performance.
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.
Provides a base implementation of SimpleKeyingInterface.
void TruncatedFinal(byte *hash, size_t size)
Computes the hash of the current message.
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.
Interface for algorithms that take byte strings as keys.
SecBlock using AllocatorWithCleanup<byte, true> typedef.
#define CRYPTOPP_ASSERT(exp)
Debugging and diagnostic assertion.
BLAKE2s parameter block specialization.
Inherited by keyed algorithms with variable key length.
BLAKE2 state information.
std::string AlgorithmName() const
Retrieve the object's name.
bool GetTreeMode() const
Get tree mode.
void SetTreeMode(bool mode)
Set tree mode.
std::string IntToString(T value, unsigned int base=10)
Converts a value to a string.
static const char * StaticAlgorithmName()
Retrieve the static algorithm name.
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.
unsigned int DigestSize() const
Provides the digest size of the hash.
The BLAKE2b cryptographic hash function.
BLAKE2b parameter block specialization.
void Update(const byte *input, size_t length)
Updates a hash with additional input.