StormByte-Crypto 3.1.0
C++26 cryptography module of the StormByte suite
Loading...
Searching...
No Matches
StormByte::Crypto::HMAC Namespace Reference

One-shot message authentication codes. More...

Typedefs

using ExpectedTag = StormByte::Expected<StormByte::Safe::Binary, Error>
 Expected full-length binary HMAC tag or a typed error.
using ExpectedVerification = StormByte::Expected<bool, Error>
 Expected verification result or a typed error.

Enumerations

enum class  Algorithm { SHA256 , SHA384 }
 Supported HMAC hash functions. More...
enum class  Error { UnsupportedAlgorithm , InvalidTagSize , BackendFailure }
 Errors returned by HMAC operations. More...

Functions

ExpectedTag Compute (Algorithm algorithm, const Secure::Password &key, std::span< const std::byte > message)
 Compute a full-length HMAC over binary input.
ExpectedVerification Verify (Algorithm algorithm, const Secure::Password &key, std::span< const std::byte > message, std::span< const std::byte > tag)
 Verify a full-length binary HMAC in constant time with respect to tag bytes.

Detailed Description

One-shot message authentication codes.

Typedef Documentation

◆ ExpectedTag

◆ ExpectedVerification

Expected verification result or a typed error.

Enumeration Type Documentation

◆ Algorithm

Supported HMAC hash functions.

Enumerator
SHA256 

HMAC-SHA-256 (32-byte tag).

SHA384 

HMAC-SHA-384 (48-byte tag).

◆ Error

enum class StormByte::Crypto::HMAC::Error
strong

Errors returned by HMAC operations.

Enumerator
UnsupportedAlgorithm 

The supplied algorithm value is not supported.

InvalidTagSize 

The supplied verification tag is not full length.

BackendFailure 

The cryptographic backend could not complete the operation.

Function Documentation

◆ Compute()

ExpectedTag StormByte::Crypto::HMAC::Compute ( Algorithm algorithm,
const Secure::Password & key,
std::span< const std::byte > message )

Compute a full-length HMAC over binary input.

Parameters
algorithmHMAC-SHA-256 or HMAC-SHA-384.
keyWiped key storage; an empty key follows HMAC semantics.
messageBorrowed message bytes, including any NUL bytes.
Returns
Exact-size binary tag, or an error.
Note
Keys longer than the hash block size are normalized by HMAC as specified. The key's raw bytes and Crypto++ backend types are not exposed publicly.

◆ Verify()

ExpectedVerification StormByte::Crypto::HMAC::Verify ( Algorithm algorithm,
const Secure::Password & key,
std::span< const std::byte > message,
std::span< const std::byte > tag )

Verify a full-length binary HMAC in constant time with respect to tag bytes.

Parameters
algorithmHMAC-SHA-256 or HMAC-SHA-384.
keyWiped key storage; an empty key follows HMAC semantics.
messageBorrowed message bytes, including any NUL bytes.
tagCandidate binary tag; truncated or oversized tags are rejected.
Returns
true for a matching tag, false for a full-length nonmatching tag, or an error.