1
0
mirror of https://github.com/taigrr/arduinolibs synced 2025-01-18 04:33:12 -08:00

Copying hash states to allow obtaining intermediate hash values

This commit is contained in:
Rhys Weatherley
2018-06-20 19:41:47 +10:00
parent e4b90184fd
commit 3e3e90b19e
14 changed files with 269 additions and 0 deletions

View File

@@ -150,6 +150,40 @@ void SHA1::finalizeHMAC(const void *key, size_t keyLen, void *hash, size_t hashL
clean(temp);
}
/**
* \brief Copies the entire hash state from another object.
*
* \param other The other object to copy the state from.
*
* This function is intended for scenarios where the application needs to
* finalize the state to get an intermediate hash value, but must then
* continue hashing new data into the original state.
*
* In the following example, h1 will be the hash over data1 and h2 will
* be the hash over data1 concatenated with data2:
*
* \code
* // Hash the initial data.
* SHA1 hash1;
* hash1.update(data1, sizeof(data1));
*
* // Copy the hash state and finalize to create h1.
* SHA1 hash2;
* hash2.copyFrom(hash1);
* hash2.finalize(h1, sizeof(h1));
*
* // Continue adding data to the original unfinalized hash.
* hash1.update(data2, sizeof(data2));
*
* // Get the final hash value h2.
* hash1.finalize(h2, sizeof(h2));
* \endcode
*/
void SHA1::copyFrom(const SHA1 &other)
{
state = other.state;
}
/**
* \brief Processes a single 512-bit chunk with the core SHA-1 algorithm.
*

View File

@@ -43,6 +43,8 @@ public:
void resetHMAC(const void *key, size_t keyLen);
void finalizeHMAC(const void *key, size_t keyLen, void *hash, size_t hashLen);
void copyFrom(const SHA1 &other);
private:
struct {
uint32_t h[5];