emsha 1.1.1
A compact HMAC-SHA-256 C++11 library.
Loading...
Searching...
No Matches
Public Member Functions | List of all members
emsha::HMAC Class Reference

#include <hmac.h>

Inheritance diagram for emsha::HMAC:
Inheritance graph
[legend]
Collaboration diagram for emsha::HMAC:
Collaboration graph
[legend]

Public Member Functions

 HMAC (const uint8_t *k, uint32_t kl)
 Construct an HMAC with its initial key.
 
EMSHAResult Reset () override
 Clear any data written to the HMAC.
 
EMSHAResult Update (const std::uint8_t *message, std::uint32_t messageLength) override
 Write data into the context.
 
EMSHAResult Finalise (std::uint8_t *digest) override
 Complete the HMAC computation.
 
EMSHAResult Result (std::uint8_t *digest) override
 Copy the current digest into a destination buffer.
 
std::uint32_t Size () override
 Returns the output size of HMAC-SHA-256.
 
 ~HMAC ()
 

Detailed Description

HMAC is a keyed hash that can be used to produce an authenticated hash of some data. The HMAC is built on (and uses internally) the SHA256 class; it's helpful to note that faults that occur in the SHA-256 code will be propagated up as the return value from many of the HMAC functions.

Constructor & Destructor Documentation

◆ HMAC()

emsha::HMAC::HMAC ( const uint8_t *  k,
uint32_t  kl 
)

Construct an HMAC with its initial key.

An HMAC is constructed with a key and the length of the key. This key is stored in the HMAC context, and is wiped by the HMAC destructor.

Parameters
kThe HMAC key.
klTHe length of the HMAC key.

◆ ~HMAC()

emsha::HMAC::~HMAC ( )

When an HMAC context is destroyed, it is reset and the key material is zeroised using the STL fill function.

Member Function Documentation

◆ Finalise()

EMSHAResult emsha::HMAC::Finalise ( std::uint8_t *  digest)
overridevirtual

Complete the HMAC computation.

Note
Once Finalise is called, the context cannot be updated unless the context is reset.
Parameters
digestA byte buffer that must be at least Size() in length.
Returns
An EMSHAResult describing the result of this method:

Implements emsha::Hash.

◆ Reset()

EMSHAResult emsha::HMAC::Reset ( )
overridevirtual

Clear any data written to the HMAC.

This is equivalent to constructing a new HMAC, but it preserves the keys.

Returns
EMSHAResult::OK is returned if the reset occurred without (detected) fault. If a fault occurs with the underlying SHA256 context, the error code is returned.

Implements emsha::Hash.

◆ Result()

EMSHAResult emsha::HMAC::Result ( std::uint8_t *  digest)
overridevirtual

Copy the current digest into a destination buffer.

Copy the current digest from the HMAC context into digest, running Finalise if needed. Once called, the context cannot be updated until the context is reset.

Parameters
digestA byte buffer that must be at least Size() in length.
Returns
An EMSHAResult describing the result of this method:

Implements emsha::Hash.

◆ Size()

std::uint32_t emsha::HMAC::Size ( )
overridevirtual

Returns the output size of HMAC-SHA-256.

The buffers passed to Update and Finalise should be at least this size.

Returns
The expected size of buffers passed to result and finalize.

Implements emsha::Hash.

◆ Update()

EMSHAResult emsha::HMAC::Update ( const std::uint8_t *  message,
std::uint32_t  messageLength 
)
overridevirtual

Write data into the context.

While there is an upper limit on the size of data that the underlying hash can operate on, this package is designed for small systems that will not approach that level of data (which is on the order of 2 exabytes), so it is not a concern for this library.

Parameters
messageA byte array containing the message to be written.
messageLengthThe message length, in bytes.
Returns
An EMSHAResult describing the result of the operation.

Implements emsha::Hash.


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