ProtoCore v0.0.1
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
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  pc_sha256_ctx
 Streaming SHA-256 context. More...
 

Macros

#define PC_SHA256_DIGEST_LEN   32
 SHA-256 digest length in bytes.
 
#define PC_SHA256_BLOCK_LEN   64
 SHA-256 block size in bytes.
 

Functions

void pc_sha256_init (pc_sha256_ctx *ctx)
 Initialize a streaming SHA-256 context (ctx must not be NULL).
 
void pc_sha256_update (pc_sha256_ctx *ctx, const uint8_t *data, size_t len)
 Feed len bytes of data into the running hash.
 
void pc_sha256_final (pc_sha256_ctx *ctx, uint8_t digest[PC_SHA256_DIGEST_LEN])
 Finalize the hash and write the 32-byte digest. The context is undefined afterwards; call init() again before reuse.
 
void pc_sha256 (const uint8_t *data, size_t len, uint8_t digest[PC_SHA256_DIGEST_LEN])
 One-shot SHA-256: hash len bytes of data into digest (32 bytes).
 

Detailed Description

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

The shared SHA-256 primitive for the whole library (SSH per-packet HMAC and KEX exchange-hash, TLS 1.3 / QUIC / DTLS key schedules, SNMPv3, JWT, CSRF, SMB 2.x message signing). On Arduino (ESP32) BOTH the streaming context and the one-shot delegate to mbedtls, which routes SHA-256 to the hardware accelerator; on native builds the software FIPS-180-4 implementation below is used. Mirrors the sha512 dual-path structure.

Author
Douglas Quigg (dstroy0)
Date
2026

Definition in file sha256.h.

Macro Definition Documentation

◆ PC_SHA256_DIGEST_LEN

#define PC_SHA256_DIGEST_LEN   32

SHA-256 digest length in bytes.

Definition at line 25 of file sha256.h.

◆ PC_SHA256_BLOCK_LEN

#define PC_SHA256_BLOCK_LEN   64

SHA-256 block size in bytes.

Definition at line 28 of file sha256.h.

Function Documentation

◆ pc_sha256_init()

void pc_sha256_init ( pc_sha256_ctx ctx)

Initialize a streaming SHA-256 context (ctx must not be NULL).

Definition at line 29 of file sha256.cpp.

References pc_sha256_ctx::mbed.

Referenced by pc_hmac_sha256(), pc_hmac_sha256_final(), pc_hmac_sha256_init(), and pc_kdf_ctr_hmac_sha256().

◆ pc_sha256_update()

void pc_sha256_update ( pc_sha256_ctx ctx,
const uint8_t *  data,
size_t  len 
)

Feed len bytes of data into the running hash.

Definition at line 39 of file sha256.cpp.

References pc_sha256_ctx::mbed.

Referenced by pc_hmac_sha256(), pc_hmac_sha256_final(), pc_hmac_sha256_init(), pc_hmac_sha256_update(), and pc_kdf_ctr_hmac_sha256().

◆ pc_sha256_final()

void pc_sha256_final ( pc_sha256_ctx ctx,
uint8_t  digest[PC_SHA256_DIGEST_LEN] 
)

Finalize the hash and write the 32-byte digest. The context is undefined afterwards; call init() again before reuse.

Parameters
digestOutput buffer, PC_SHA256_DIGEST_LEN bytes.

Definition at line 48 of file sha256.cpp.

References pc_sha256_ctx::mbed.

Referenced by pc_hmac_sha256(), pc_hmac_sha256_final(), and pc_kdf_ctr_hmac_sha256().

◆ pc_sha256()

void pc_sha256 ( const uint8_t *  data,
size_t  len,
uint8_t  digest[PC_SHA256_DIGEST_LEN] 
)

One-shot SHA-256: hash len bytes of data into digest (32 bytes).

Definition at line 58 of file sha256.cpp.

Referenced by PC_CRYPTO_HOT::build_key_block(), pc_ecdsa_p256_sign(), pc_ecdsa_p256_verify(), pc_kdf_ctr_hmac_sha256(), pc_rsa_verify(), and ssh_rsa_sign().