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

#include <sha256.h>

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

Public Member Functions

 SHA256 ()
 A SHA256 context does not need any special construction. More...
 
 ~SHA256 ()
 
EMSHAResult Reset () override
 Clear the internal state of the SHA256 context, returning it to its initial state. More...
 
EMSHAResult Update (const std::uint8_t *message, std::uint32_t messageLength) override
 Writes data into the SHA256. More...
 
EMSHAResult Finalise (std::uint8_t *digest) override
 Complete the digest. More...
 
EMSHAResult Result (std::uint8_t *digest) override
 Copy the result from the SHA-256 context into the buffer pointed to by d, running Finalise if needed. Once called, the context cannot be updated until the context is reset. More...
 
std::uint32_t Size () override
 Returns the output size of SHA-256. More...
 

Constructor & Destructor Documentation

◆ SHA256()

emsha::SHA256::SHA256 ( )

A SHA256 context does not need any special construction.

It can be declared and immediately start being used.

◆ ~SHA256()

emsha::SHA256::~SHA256 ( )

The SHA256 destructor will clear out its internal message buffer; all the members are local and not resource handles, so cleanup is minimal.

Member Function Documentation

◆ Finalise()

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

Complete the digest.

Once this method is called, the context cannot be updated unless the context is reset.

Parameters
digestbyte buffer that must be at least SHA256.size() in length.
Returns
An EMSHAResult describing the result of the operation.

Implements emsha::Hash.

◆ Reset()

EMSHAResult emsha::SHA256::Reset ( )
overridevirtual

Clear the internal state of the SHA256 context, returning it to its initial state.

Returns
This should always return EMSHAResult::OK.

Implements emsha::Hash.

◆ Result()

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

Copy the result from the SHA-256 context into the buffer pointed to by d, 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 SHA256.size() in length.
Returns
An EMSHAResult describing the result of the operation.

Implements emsha::Hash.

◆ Size()

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

Returns the output size of 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::SHA256::Update ( const std::uint8_t *  message,
std::uint32_t  messageLength 
)
overridevirtual

Writes data into the SHA256.

While there is an upper limit on the size of data that SHA-256 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 thought to be a concern.

Parameters
messageA byte array containing the message to be written. It must not be NULL (unless the message length is zero).
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: