Arduino Cryptography Library
Public Member Functions | Static Public Attributes | List of all members
BLAKE2b Class Reference

BLAKE2b hash algorithm. More...

#include <BLAKE2b.h>

Inheritance diagram for BLAKE2b:
Hash

Public Member Functions

 BLAKE2b ()
 Constructs a BLAKE2b hash object.
 
virtual ~BLAKE2b ()
 Destroys this BLAKE2b hash object after clearing sensitive information.
 
size_t hashSize () const
 Size of the hash result from finalize(). More...
 
size_t blockSize () const
 Size of the internal block used by the hash algorithm. More...
 
void reset ()
 Resets the hash ready for a new hashing process. More...
 
void reset (uint8_t outputLength)
 Resets the hash ready for a new hashing process with a specified output length. More...
 
void reset (const void *key, size_t keyLen, uint8_t outputLength=64)
 Resets the hash ready for a new hashing process with a specified key and output length. More...
 
void update (const void *data, size_t len)
 Updates the hash with more data. More...
 
void finalize (void *hash, size_t len)
 Finalizes the hashing process and returns the hash. More...
 
void clear ()
 Clears the hash state, removing all sensitive data, and then resets the hash ready for a new hashing process. More...
 
void resetHMAC (const void *key, size_t keyLen)
 Resets the hash ready for a new HMAC hashing process. More...
 
void finalizeHMAC (const void *key, size_t keyLen, void *hash, size_t hashLen)
 Finalizes the HMAC hashing process and returns the hash. More...
 
- Public Member Functions inherited from Hash
 Hash ()
 Constructs a new hash object.
 
virtual ~Hash ()
 Destroys this hash object. More...
 

Static Public Attributes

static const size_t HASH_SIZE = 64
 Constant for the size of the hash output of BLAKE2b.
 
static const size_t BLOCK_SIZE = 128
 Constant for the block size of BLAKE2b.
 

Additional Inherited Members

- Protected Member Functions inherited from Hash
void formatHMACKey (void *block, const void *key, size_t len, uint8_t pad)
 Formats a HMAC key into a block. More...
 

Detailed Description

BLAKE2b hash algorithm.

BLAKE2b is a variation on the ChaCha stream cipher, designed for hashing, with a 512-bit hash output. It is intended as a high performance replacement for SHA512 for when speed is critical but exact SHA512 compatibility is not.

This class supports two types of keyed hash. The BLAKE2 keyed hash and traditional HMAC. The BLAKE2 keyed hash is recommended unless there is some higher-level application need to be compatible with the HMAC construction. The keyed hash is computed as follows:

BLAKE2b blake;
blake.reset(key, sizeof(key), outputLength);
blake.update(data1, sizeof(data1));
blake.update(data2, sizeof(data2));
...
blake.update(dataN, sizeof(dataN));
blake.finalize(hash, outputLength);
BLAKE2b hash algorithm.
Definition: BLAKE2b.h:29
void finalize(void *hash, size_t len)
Finalizes the hashing process and returns the hash.
Definition: BLAKE2b.cpp:227
void update(const void *data, size_t len)
Updates the hash with more data.
Definition: BLAKE2b.cpp:202
void reset()
Resets the hash ready for a new hashing process.
Definition: BLAKE2b.cpp:119

The HMAC is computed as follows (the output length is always 64):

BLAKE2b blake;
blake.resetHMAC(key, sizeof(key));
blake.update(data1, sizeof(data1));
blake.update(data2, sizeof(data2));
...
blake.update(dataN, sizeof(dataN));
blake.finalizeHMAC(key, sizeof(key), hash, 32);
void finalizeHMAC(const void *key, size_t keyLen, void *hash, size_t hashLen)
Finalizes the HMAC hashing process and returns the hash.
Definition: BLAKE2b.cpp:256
void resetHMAC(const void *key, size_t keyLen)
Resets the hash ready for a new HMAC hashing process.
Definition: BLAKE2b.cpp:249

References: https://blake2.net/, RFC 7693

See also
BLAKE2s, SHA512, SHA3_512

Definition at line 28 of file BLAKE2b.h.

Member Function Documentation

◆ blockSize()

size_t BLAKE2b::blockSize ( ) const
virtual

Size of the internal block used by the hash algorithm.

See also
update(), hashSize()

Implements Hash.

Definition at line 104 of file BLAKE2b.cpp.

◆ clear()

void BLAKE2b::clear ( )
virtual

Clears the hash state, removing all sensitive data, and then resets the hash ready for a new hashing process.

See also
reset()

Implements Hash.

Definition at line 243 of file BLAKE2b.cpp.

◆ finalize()

void BLAKE2b::finalize ( void *  hash,
size_t  len 
)
virtual

Finalizes the hashing process and returns the hash.

Parameters
hashThe buffer to return the hash value in.
lenThe length of the hash buffer, normally hashSize().

If len is less than hashSize(), then the hash value will be truncated to the first len bytes. If len is greater than hashSize(), then the remaining bytes will left unchanged.

If finalize() is called again, then the returned hash value is undefined. Call reset() first to start a new hashing process.

See also
reset(), update(), finalizeHMAC()

Implements Hash.

Definition at line 227 of file BLAKE2b.cpp.

◆ finalizeHMAC()

void BLAKE2b::finalizeHMAC ( const void *  key,
size_t  keyLen,
void *  hash,
size_t  hashLen 
)
virtual

Finalizes the HMAC hashing process and returns the hash.

Parameters
keyPoints to the HMAC key for the hashing process. The contents of this array must be identical to the value passed to resetHMAC().
keyLenSize of the HMAC key in bytes.
hashThe buffer to return the hash value in.
hashLenThe length of the hash buffer, normally hashSize().
See also
resetHMAC(), finalize()

Implements Hash.

Definition at line 256 of file BLAKE2b.cpp.

◆ hashSize()

size_t BLAKE2b::hashSize ( ) const
virtual

Size of the hash result from finalize().

See also
finalize(), blockSize()

Implements Hash.

Definition at line 99 of file BLAKE2b.cpp.

◆ reset() [1/3]

void BLAKE2b::reset ( )
virtual

Resets the hash ready for a new hashing process.

See also
update(), finalize(), resetHMAC()

Implements Hash.

Definition at line 119 of file BLAKE2b.cpp.

◆ reset() [2/3]

void BLAKE2b::reset ( const void *  key,
size_t  keyLen,
uint8_t  outputLength = 64 
)

Resets the hash ready for a new hashing process with a specified key and output length.

Parameters
keyPoints to the key.
keyLenThe length of the key in bytes, between 0 and 64.
outputLengthThe output length to use for the final hash in bytes, between 1 and 64.

If keyLen is greater than 64, then the key will be truncated to the first 64 bytes.

Definition at line 172 of file BLAKE2b.cpp.

◆ reset() [3/3]

void BLAKE2b::reset ( uint8_t  outputLength)

Resets the hash ready for a new hashing process with a specified output length.

Parameters
outputLengthThe output length to use for the final hash in bytes, between 1 and 64.

Definition at line 141 of file BLAKE2b.cpp.

◆ resetHMAC()

void BLAKE2b::resetHMAC ( const void *  key,
size_t  keyLen 
)
virtual

Resets the hash ready for a new HMAC hashing process.

Parameters
keyPoints to the HMAC key for the hashing process.
keyLenSize of the HMAC key in bytes.

The following example computes a HMAC over a series of data blocks with a specific key:

hash.resetHMAC(key, sizeof(key));
hash.update(data1, sizeof(data1));
hash.update(data2, sizeof(data2));
...
hash.update(dataN, sizeof(dataN));
hash.finalizeHMAC(key, sizeof(key), hmac, sizeof(hmac));

The same key must be passed to both resetHMAC() and finalizeHMAC().

See also
finalizeHMAC(), reset()

Implements Hash.

Definition at line 249 of file BLAKE2b.cpp.

◆ update()

void BLAKE2b::update ( const void *  data,
size_t  len 
)
virtual

Updates the hash with more data.

Parameters
dataData to be hashed.
lenNumber of bytes of data to be hashed.

If finalize() has already been called, then the behavior of update() will be undefined. Call reset() first to start a new hashing process.

See also
reset(), finalize()

Implements Hash.

Definition at line 202 of file BLAKE2b.cpp.


The documentation for this class was generated from the following files: