Abstract base class for cryptographic hash algorithms.
More...
#include <Hash.h>
|
| Hash () |
| Constructs a new hash object.
|
|
virtual | ~Hash () |
| Destroys this hash object. More...
|
|
virtual size_t | hashSize () const =0 |
| Size of the hash result from finalize(). More...
|
|
virtual size_t | blockSize () const =0 |
| Size of the internal block used by the hash algorithm. More...
|
|
virtual void | reset ()=0 |
| Resets the hash ready for a new hashing process. More...
|
|
virtual void | update (const void *data, size_t len)=0 |
| Updates the hash with more data. More...
|
|
virtual void | finalize (void *hash, size_t len)=0 |
| Finalizes the hashing process and returns the hash. More...
|
|
virtual void | clear ()=0 |
| Clears the hash state, removing all sensitive data, and then resets the hash ready for a new hashing process. More...
|
|
virtual void | resetHMAC (const void *key, size_t keyLen)=0 |
| Resets the hash ready for a new HMAC hashing process. More...
|
|
virtual void | finalizeHMAC (const void *key, size_t keyLen, void *hash, size_t hashLen)=0 |
| Finalizes the HMAC hashing process and returns the hash. More...
|
|
|
void | formatHMACKey (void *block, const void *key, size_t len, uint8_t pad) |
| Formats a HMAC key into a block. More...
|
|
Abstract base class for cryptographic hash algorithms.
- See also
- SHA224, SHA256, SHA384, SHA3_256, BLAKE2s
Definition at line 29 of file Hash.h.
◆ ~Hash()
Destroys this hash object.
- Note
- Subclasses are responsible for clearing any sensitive data that remains in the hash object when it is destroyed.
- See also
- clear()
Definition at line 48 of file Hash.cpp.
◆ blockSize()
size_t Hash::blockSize |
( |
| ) |
const |
|
pure virtual |
◆ clear()
◆ finalize()
void Hash::finalize |
( |
void * |
hash, |
|
|
size_t |
len |
|
) |
| |
|
pure virtual |
Finalizes the hashing process and returns the hash.
- Parameters
-
hash | The buffer to return the hash value in. |
len | The 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()
Implemented in SHA1, SHA512, SHA3_512, SHA3_256, SHA256, BLAKE2s, and BLAKE2b.
◆ finalizeHMAC()
void Hash::finalizeHMAC |
( |
const void * |
key, |
|
|
size_t |
keyLen, |
|
|
void * |
hash, |
|
|
size_t |
hashLen |
|
) |
| |
|
pure virtual |
Finalizes the HMAC hashing process and returns the hash.
- Parameters
-
key | Points to the HMAC key for the hashing process. The contents of this array must be identical to the value passed to resetHMAC(). |
keyLen | Size of the HMAC key in bytes. |
hash | The buffer to return the hash value in. |
hashLen | The length of the hash buffer, normally hashSize(). |
- See also
- resetHMAC(), finalize()
Implemented in SHA1, SHA512, SHA3_512, SHA3_256, SHA256, BLAKE2s, and BLAKE2b.
◆ formatHMACKey()
void Hash::formatHMACKey |
( |
void * |
block, |
|
|
const void * |
key, |
|
|
size_t |
len, |
|
|
uint8_t |
pad |
|
) |
| |
|
protected |
Formats a HMAC key into a block.
- Parameters
-
block | The block to format the key into. Must be at least blockSize() bytes in length. |
key | Points to the HMAC key for the hashing process. |
len | Length of the HMAC key in bytes. |
pad | Inner (0x36) or outer (0x5C) padding value to XOR with the formatted HMAC key. |
This function is intended to help subclasses implement resetHMAC() and finalizeHMAC() by directly formatting the HMAC key into the subclass's internal block buffer and resetting the hash.
Definition at line 162 of file Hash.cpp.
◆ hashSize()
size_t Hash::hashSize |
( |
| ) |
const |
|
pure virtual |
◆ reset()
Resets the hash ready for a new hashing process.
- See also
- update(), finalize(), resetHMAC()
Implemented in SHA1, SHA512, SHA384, SHA3_512, SHA3_256, SHA256, SHA224, BLAKE2s, and BLAKE2b.
◆ resetHMAC()
void Hash::resetHMAC |
( |
const void * |
key, |
|
|
size_t |
keyLen |
|
) |
| |
|
pure virtual |
Resets the hash ready for a new HMAC hashing process.
- Parameters
-
key | Points to the HMAC key for the hashing process. |
keyLen | Size 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()
Implemented in SHA1, SHA512, SHA3_512, SHA3_256, SHA256, BLAKE2s, and BLAKE2b.
◆ update()
void Hash::update |
( |
const void * |
data, |
|
|
size_t |
len |
|
) |
| |
|
pure virtual |
The documentation for this class was generated from the following files: