DeterministicESPAsyncWebServer v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
ssh_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_sha512.h
6 * @brief SHA-512 (FIPS 180-4) - streaming context and one-shot API.
7 *
8 * Needed by Ed25519 (RFC 8032), whose signing and verification hash with SHA-512.
9 * On Arduino (ESP32) both the streaming context and the one-shot delegate to mbedtls
10 * (hardware-accelerated where available); on native builds the software FIPS-180-4
11 * implementation is used. Mirrors the ssh_sha256 dual-path structure.
12 *
13 * @author Douglas Quigg (dstroy0)
14 * @date 2026
15 */
16
17#ifndef DETERMINISTICESPASYNCWEBSERVER_SSH_SHA512_H
18#define DETERMINISTICESPASYNCWEBSERVER_SSH_SHA512_H
19
20#include <stddef.h>
21#include <stdint.h>
22
23/** @brief SHA-512 digest length in bytes. */
24#define SSH_SHA512_DIGEST_LEN 64
25
26/** @brief SHA-512 block size in bytes. */
27#define SSH_SHA512_BLOCK_LEN 128
28
29/** @brief Streaming SHA-512 context. */
30#ifdef ARDUINO
31#include <mbedtls/sha512.h>
32typedef struct
33{
34 mbedtls_sha512_context mbed; ///< mbedtls SHA-512 state (ESP32).
36#else
37typedef struct
38{
39 uint64_t s[8]; ///< Running hash words (H0..H7).
40 uint64_t n; ///< Total bytes processed so far.
41 uint8_t buf[128]; ///< Partial block accumulator.
42 uint32_t buflen; ///< Bytes valid in buf[].
44#endif
45
46/** @brief Initialize a streaming SHA-512 context (@p ctx must not be NULL). */
48
49/** @brief Feed @p len bytes of @p data into the running hash. */
50void ssh_sha512_update(SshSha512Ctx *ctx, const uint8_t *data, size_t len);
51
52/**
53 * @brief Finalize the hash and write the 64-byte digest. The context is undefined
54 * afterwards; call init() again before reuse.
55 * @param digest Output buffer, SSH_SHA512_DIGEST_LEN bytes.
56 */
57void ssh_sha512_final(SshSha512Ctx *ctx, uint8_t digest[SSH_SHA512_DIGEST_LEN]);
58
59/** @brief One-shot SHA-512: hash @p len bytes of @p data into @p digest (64 bytes). */
60void ssh_sha512(const uint8_t *data, size_t len, uint8_t digest[SSH_SHA512_DIGEST_LEN]);
61
62#endif // DETERMINISTICESPASYNCWEBSERVER_SSH_SHA512_H
void ssh_sha512_final(SshSha512Ctx *ctx, uint8_t digest[SSH_SHA512_DIGEST_LEN])
Finalize the hash and write the 64-byte digest. The context is undefined afterwards; call init() agai...
void ssh_sha512_init(SshSha512Ctx *ctx)
Initialize a streaming SHA-512 context (ctx must not be NULL).
#define SSH_SHA512_DIGEST_LEN
SHA-512 digest length in bytes.
Definition ssh_sha512.h:24
void ssh_sha512(const uint8_t *data, size_t len, uint8_t digest[SSH_SHA512_DIGEST_LEN])
One-shot SHA-512: hash len bytes of data into digest (64 bytes).
void ssh_sha512_update(SshSha512Ctx *ctx, const uint8_t *data, size_t len)
Feed len bytes of data into the running hash.
Streaming SHA-512 context.
Definition ssh_sha512.h:33
mbedtls_sha512_context mbed
mbedtls SHA-512 state (ESP32).
Definition ssh_sha512.h:34