DeterministicESPAsyncWebServer v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
ssh_sha256.h File Reference

SHA-256 (FIPS 180-4) - streaming context and one-shot API. More...

#include <stddef.h>
#include <stdint.h>
#include <mbedtls/sha256.h>

Go to the source code of this file.

Classes

struct  SshSha256Ctx
 Streaming SHA-256 context. More...
 

Macros

#define SSH_SHA256_DIGEST_LEN   32
 SHA-256 digest length in bytes.
 
#define SSH_SHA256_BLOCK_LEN   64
 SHA-256 block size in bytes.
 

Functions

void ssh_sha256_init (SshSha256Ctx *ctx)
 Initialize a streaming SHA-256 context.
 
void ssh_sha256_update (SshSha256Ctx *ctx, const uint8_t *data, size_t len)
 Feed len bytes of data into the running hash.
 
void ssh_sha256_final (SshSha256Ctx *ctx, uint8_t digest[SSH_SHA256_DIGEST_LEN])
 Finalize the hash and write the 32-byte digest.
 
void ssh_sha256 (const uint8_t *data, size_t len, uint8_t digest[SSH_SHA256_DIGEST_LEN])
 One-shot SHA-256: hash len bytes and write the digest.
 

Detailed Description

SHA-256 (FIPS 180-4) - streaming context and one-shot API.

On Arduino (ESP32) targets BOTH the one-shot and the streaming context (init / update / final) delegate to mbedtls, which routes SHA-256 to the hardware accelerator. The streaming path backs the per-packet HMAC (ssh_hmac_sha256, run on every inbound and outbound SSH packet) as well as the KEX exchange-hash, so hardware acceleration matters for bulk throughput, not just the handshake. On native builds the software implementation is used.

The context therefore holds an mbedtls_sha256_context on Arduino (pulling in <mbedtls/sha256.h>) and the software hash state on native.

Author
Douglas Quigg (dstroy0)
Date
2026

Definition in file ssh_sha256.h.

Macro Definition Documentation

◆ SSH_SHA256_DIGEST_LEN

#define SSH_SHA256_DIGEST_LEN   32

SHA-256 digest length in bytes.

Definition at line 29 of file ssh_sha256.h.

◆ SSH_SHA256_BLOCK_LEN

#define SSH_SHA256_BLOCK_LEN   64

SHA-256 block size in bytes.

Definition at line 32 of file ssh_sha256.h.

Function Documentation

◆ ssh_sha256_init()

void ssh_sha256_init ( SshSha256Ctx ctx)

Initialize a streaming SHA-256 context.

Parameters
ctxMust not be NULL.

Definition at line 28 of file ssh_sha256.cpp.

References SshSha256Ctx::mbed.

Referenced by ssh_hmac_sha256_final(), ssh_hmac_sha256_init(), and ssh_kdf_derive().

◆ ssh_sha256_update()

void ssh_sha256_update ( SshSha256Ctx ctx,
const uint8_t *  data,
size_t  len 
)

Feed len bytes of data into the running hash.

Parameters
ctxInitialized context.
dataInput bytes.
lenNumber of input bytes.

Definition at line 38 of file ssh_sha256.cpp.

References SshSha256Ctx::mbed.

Referenced by ssh_hmac_sha256_final(), ssh_hmac_sha256_init(), ssh_hmac_sha256_update(), and ssh_kdf_derive().

◆ ssh_sha256_final()

void ssh_sha256_final ( SshSha256Ctx ctx,
uint8_t  digest[SSH_SHA256_DIGEST_LEN] 
)

Finalize the hash and write the 32-byte digest.

The context is in an undefined state after this call; do not call update() again without first calling init().

Parameters
ctxInitialized context with all data already fed.
digestOutput buffer, must be SSH_SHA256_DIGEST_LEN bytes.

Definition at line 47 of file ssh_sha256.cpp.

References SshSha256Ctx::mbed.

Referenced by ssh_hmac_sha256_final(), and ssh_kdf_derive().

◆ ssh_sha256()

void ssh_sha256 ( const uint8_t *  data,
size_t  len,
uint8_t  digest[SSH_SHA256_DIGEST_LEN] 
)

One-shot SHA-256: hash len bytes and write the digest.

On Arduino uses the mbedtls hardware-accelerated path. On native uses the software streaming implementation.

Parameters
dataInput bytes.
lenNumber of input bytes.
digestOutput buffer, must be SSH_SHA256_DIGEST_LEN bytes.

Definition at line 57 of file ssh_sha256.cpp.

Referenced by ssh_ecdsa_p256_sign(), ssh_ecdsa_p256_verify(), ssh_rsa_sign(), and ssh_rsa_verify().