emsha 1.1.0
A compact HMAC-SHA-256 C++11 library.
hmac.h
Go to the documentation of this file.
1
29
30#ifndef EMSHA_HMAC_H
31#define EMSHA_HMAC_H
32
33
34#include <cstdint>
35
36#include "emsha.h"
37#include "sha256.h"
38
39
40namespace emsha {
41
43
50class HMAC : Hash {
51public:
60 HMAC(const uint8_t *k, uint32_t kl);
61
71 EMSHAResult Reset() override;
72
95 EMSHAResult Update(const std::uint8_t *message, std::uint32_t messageLength) override;
96
115 EMSHAResult Finalise(std::uint8_t *digest) override;
116
135 EMSHAResult Result(std::uint8_t *digest) override;
136
137
145 std::uint32_t Size() override;
146
151private:
152 uint8_t hstate;
153 SHA256 ctx;
154 uint8_t k[HMAC_KEY_LENGTH];
155 uint8_t buf[SHA256_HASH_SIZE];
156
157 EMSHAResult reset();
158 inline EMSHAResult finalResult(uint8_t *d);
159};
160
161
172ComputeHMAC(const uint8_t *k, const uint32_t kl,
173 const uint8_t *m, const uint32_t ml,
174 uint8_t *d);
175
176
177} // end of namespace emsha
178
179
180#endif // EMSHA_HMAC_H
Definition: hmac.h:50
HMAC(const uint8_t *k, uint32_t kl)
Construct an HMAC with its initial key.
EMSHAResult Update(const std::uint8_t *message, std::uint32_t messageLength) override
Write data into the context.
EMSHAResult Result(std::uint8_t *digest) override
Copy the current digest into a destination buffer.
EMSHAResult Finalise(std::uint8_t *digest) override
Complete the HMAC computation.
EMSHAResult Reset() override
Clear any data written to the HMAC.
std::uint32_t Size() override
Returns the output size of HMAC-SHA-256.
Definition: emsha.h:93
Definition: sha256.h:46
Declares an interface for an EMbedded Secure HAshing interface.
Definition: emsha.h:39
const std::uint32_t SHA256_HASH_SIZE
SHA256_HASH_SIZE is the output length of SHA-256 in bytes.
Definition: emsha.h:57
const uint32_t HMAC_KEY_LENGTH
Definition: hmac.h:42
const uint32_t SHA256_MB_SIZE
SHA256_MB_SIZE is the size of a message block.
Definition: sha256.h:44
EMSHAResult ComputeHMAC(const uint8_t *k, const uint32_t kl, const uint8_t *m, const uint32_t ml, uint8_t *d)
Perform a single-pass HMAC computation over a message.
EMSHAResult
Describe the result of an EMSHA operation.
Definition: emsha.h:64
Declares an interface for producing SHA-256 hashes.