Skip to content

Commit

Permalink
Update hmac.adoc
Browse files Browse the repository at this point in the history
  • Loading branch information
pdimov committed Nov 14, 2024
1 parent 81524dc commit 2c2987d
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions doc/hash2/reference/hmac.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,95 @@ template<class H> class hmac;
} // namespace boost
```

This header implements the https://tools.ietf.org/html/rfc2104[HMAC algorithm].

## hmac

```
template<class H> class hmac
{
public:

using result_type = typename H::result_type;

static constexpr int block_size = H::block_size;

constexpr hmac();
explicit constexpr hmac( std::uint64_t seed );
constexpr hmac( unsigned char const* p, std::size_t n );

void update( void const* p, std::size_t n );
constexpr void update( unsigned char const* p, std::size_t n );

constexpr result_type result();
};
```

The class template `hmac` takes as a parameter a cryptographic _hash algorithm_ `H`
and implements the corresponding _hash-based message authentication code_ (HMAC) algorithm.

For example, HMAC-SHA2-256 is implemented by `hmac<sha2_256>`.

### Constructors

```
constexpr hmac();
```

Default constructor.

Effects: ::
Initializes the internal state using an empty byte sequence as the secret key.

```
explicit constexpr hmac( std::uint64_t seed );
```

Constructor taking an integer seed value.

Effects: ::
If `seed` is zero, initializes the state as if by default construction, otherwise, initializes it using the 8 bytes of the little-endian representation of `seed` as the secret key.

Remarks: ::
By convention, if `seed` is zero, the effect of this constructor is the same as default construction.

```
hmac( unsigned char const* p, std::size_t n );
```

Constructor taking a byte sequence seed.

Effects: ::
Initializes the state as specified by the HMAC algorithm using `[p, p+n)` as the secret key.

Remarks: ::
By convention, if `n` is zero, the effect of this constructor is the same as default construction.

### update

```
void update( void const* p, std::size_t n );
constexpr void update( unsigned char const* p, std::size_t n );
```

Effects: ::
Updates the internal state of the HMAC algorithm from the byte sequence `[p, p+n)`.

Remarks: ::
Consecutive calls to `update` are equivalent to a single call with the concatenated byte sequences of the individual calls.

### result

```
constexpr result_type result();
```

Effects: ::
Pads the accumulated message and finalizes the HMAC digest.

Returns: ::
The HMAC digest of the message formed from the byte sequences of the preceding calls to `update`.

Remarks: ::
Repeated calls to `result()` return a pseudorandom sequence of `result_type` values, effectively extending the output.

0 comments on commit 2c2987d

Please sign in to comment.