ProtoCore v0.0.1
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
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 hmac_sha512.h
6 * @brief HMAC-SHA2-512 (RFC 2104 + FIPS 198-1) - streaming context and one-shot API.
7 *
8 * The shared HMAC-SHA512 primitive. Backs the SSH hmac-sha2-512 / hmac-sha2-512-etm@openssh.com
9 * integrity algorithms. Built over the pc_sha512 streaming functions (SHA-512 block size 128 bytes).
10 * SSH-derived MAC keys are 64 bytes (<= the block size), so the key is zero-padded, not pre-hashed.
11 * Pure crypto; the protocol layer that uses it owns the verify-before-act ordering.
12 *
13 * @author Douglas Quigg (dstroy0)
14 * @date 2026
15 */
16
17#ifndef PROTOCORE_HMAC_SHA512_H
18#define PROTOCORE_HMAC_SHA512_H
19
20#include "crypto/hash/sha512.h"
21#include <stddef.h>
22#include <stdint.h>
23
24/** @brief HMAC-SHA2-512 output length in bytes. */
25#define PC_HMAC_SHA512_LEN 64
26
27/** @brief Streaming HMAC-SHA2-512 context (stores the opad key block + inner hash state). */
28typedef struct
29{
30 uint8_t okey[PC_SHA512_BLOCK_LEN]; ///< (key XOR opad), applied in the final step
31 pc_sha512_ctx inner; ///< inner hash: H((key XOR ipad) || message)
33
34/** @brief Begin an HMAC-SHA2-512 over @p key (keys > 128 bytes are pre-hashed per RFC 2104). */
35void pc_hmac_sha512_init(pc_hmac_sha512_ctx *ctx, const uint8_t *key, size_t key_len);
36/** @brief Feed @p len message bytes. */
37void pc_hmac_sha512_update(pc_hmac_sha512_ctx *ctx, const uint8_t *data, size_t len);
38/** @brief Finish, writing the 64-byte MAC. */
40
41/** @brief One-shot HMAC-SHA2-512 over a single buffer. */
42void pc_hmac_sha512(const uint8_t *key, size_t key_len, const uint8_t *data, size_t len,
43 uint8_t mac[PC_HMAC_SHA512_LEN]);
44
45#endif // PROTOCORE_HMAC_SHA512_H
void pc_hmac_sha512_final(pc_hmac_sha512_ctx *ctx, uint8_t mac[PC_HMAC_SHA512_LEN])
Finish, writing the 64-byte MAC.
void pc_hmac_sha512_init(pc_hmac_sha512_ctx *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 pc_hmac_sha512(const uint8_t *key, size_t key_len, const uint8_t *data, size_t len, uint8_t mac[PC_HMAC_SHA512_LEN])
One-shot HMAC-SHA2-512 over a single buffer.
#define PC_HMAC_SHA512_LEN
HMAC-SHA2-512 output length in bytes.
Definition hmac_sha512.h:25
void pc_hmac_sha512_update(pc_hmac_sha512_ctx *ctx, const uint8_t *data, size_t len)
Feed len message bytes.
SHA-512 (FIPS 180-4) - streaming context and one-shot API.
#define PC_SHA512_BLOCK_LEN
SHA-512 block size in bytes.
Definition sha512.h:27
Streaming HMAC-SHA2-512 context (stores the opad key block + inner hash state).
Definition hmac_sha512.h:29
pc_sha512_ctx inner
inner hash: H((key XOR ipad) || message)
Definition hmac_sha512.h:31
Streaming SHA-512 context.
Definition sha512.h:33