DeterministicESPAsyncWebServer v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
ssh_hmac_sha512.h
Go to the documentation of this file.
1// Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file ssh_hmac_sha512.h
6 * @brief HMAC-SHA2-512 (RFC 2104 + FIPS 198-1).
7 *
8 * The MAC for the hmac-sha2-512 and hmac-sha2-512-etm@openssh.com SSH integrity algorithms.
9 * Implemented over the ssh_sha512 streaming functions (SHA-512 block size 128 bytes). SSH-derived
10 * MAC keys are 64 bytes (<= the block size), so the key is zero-padded, not pre-hashed. Pure.
11 *
12 * @author Douglas Quigg (dstroy0)
13 * @date 2026
14 */
15
16#ifndef DETERMINISTICESPASYNCWEBSERVER_SSH_HMAC_SHA512_H
17#define DETERMINISTICESPASYNCWEBSERVER_SSH_HMAC_SHA512_H
18
20#include <stddef.h>
21#include <stdint.h>
22
23/** @brief HMAC-SHA2-512 output length in bytes. */
24#define SSH_HMAC_SHA512_LEN 64
25
26/** @brief Streaming HMAC-SHA2-512 context (stores the opad key block + inner hash state). */
27typedef struct
28{
29 uint8_t okey[SSH_SHA512_BLOCK_LEN]; ///< (key XOR opad), applied in the final step
30 SshSha512Ctx inner; ///< inner hash: H((key XOR ipad) || message)
32
33/** @brief Begin an HMAC-SHA2-512 over @p key (keys > 128 bytes are pre-hashed per RFC 2104). */
34void ssh_hmac_sha512_init(SshHmacSha512Ctx *ctx, const uint8_t *key, size_t key_len);
35/** @brief Feed @p len message bytes. */
36void ssh_hmac_sha512_update(SshHmacSha512Ctx *ctx, const uint8_t *data, size_t len);
37/** @brief Finish, writing the 64-byte MAC. */
39
40/** @brief One-shot HMAC-SHA2-512 over a single buffer. */
41void ssh_hmac_sha512(const uint8_t *key, size_t key_len, const uint8_t *data, size_t len,
42 uint8_t mac[SSH_HMAC_SHA512_LEN]);
43
44#endif // DETERMINISTICESPASYNCWEBSERVER_SSH_HMAC_SHA512_H
void ssh_hmac_sha512_final(SshHmacSha512Ctx *ctx, uint8_t mac[SSH_HMAC_SHA512_LEN])
Finish, writing the 64-byte MAC.
void ssh_hmac_sha512(const uint8_t *key, size_t key_len, const uint8_t *data, size_t len, uint8_t mac[SSH_HMAC_SHA512_LEN])
One-shot HMAC-SHA2-512 over a single buffer.
#define SSH_HMAC_SHA512_LEN
HMAC-SHA2-512 output length in bytes.
void ssh_hmac_sha512_init(SshHmacSha512Ctx *ctx, const uint8_t *key, size_t key_len)
Begin an HMAC-SHA2-512 over key (keys > 128 bytes are pre-hashed per RFC 2104).
void ssh_hmac_sha512_update(SshHmacSha512Ctx *ctx, const uint8_t *data, size_t len)
Feed len message bytes.
SHA-512 (FIPS 180-4) - streaming context and one-shot API.
#define SSH_SHA512_BLOCK_LEN
SHA-512 block size in bytes.
Definition ssh_sha512.h:27
Streaming HMAC-SHA2-512 context (stores the opad key block + inner hash state).
SshSha512Ctx inner
inner hash: H((key XOR ipad) || message)
Streaming SHA-512 context.
Definition ssh_sha512.h:33