File syn_sha256.c¶
FileList > src > syntropic > util > syn_sha256.c
Go to the source code of this file
SHA-256 implementation — FIPS 180-4 compliant, pure C99. More...
#include "syn_assert.h"#include "syn_pack.h"#include "syn_sha256.h"#include <string.h>
Public Static Attributes¶
| Type | Name |
|---|---|
| const uint32_t | H_INIT = /* multi line expression */ |
| const uint32_t | K = /* multi line expression */ |
Public Functions¶
| Type | Name |
|---|---|
| void | syn_sha256_final (SYN_SHA256 * ctx, uint8_t hash) Finalize the hash and produce the 32-byte digest. |
| void | syn_sha256_init (SYN_SHA256 * ctx) Initialize a SHA-256 context. |
| void | syn_sha256_update (SYN_SHA256 * ctx, const void * data, size_t len) Feed data into the hash. |
Public Static Functions¶
| Type | Name |
|---|---|
| uint32_t | ch (uint32_t x, uint32_t y, uint32_t z) Choice function: Ch(x,y,z) = (x ∧ y) ⊕ (¬x ∧ z). |
| uint32_t | gamma0 (uint32_t x) Small sigma-0: σ₀(x) = ROTR⁷(x) ⊕ ROTR¹⁸(x) ⊕ SHR³(x). |
| uint32_t | gamma1 (uint32_t x) Small sigma-1: σ₁(x) = ROTR¹⁷(x) ⊕ ROTR¹⁹(x) ⊕ SHR¹⁰(x). |
| uint32_t | maj (uint32_t x, uint32_t y, uint32_t z) Majority function: Maj(x,y,z) = (x ∧ y) ⊕ (x ∧ z) ⊕ (y ∧ z). |
| uint32_t | rotr (uint32_t x, unsigned n) Circular right rotate. |
| void | sha256_transform (uint32_t state, const uint8_t block) Process a single 64-byte block. |
| uint32_t | sigma0 (uint32_t x) Big Sigma-0: Σ₀(x) = ROTR²(x) ⊕ ROTR¹³(x) ⊕ ROTR²²(x). |
| uint32_t | sigma1 (uint32_t x) Big Sigma-1: Σ₁(x) = ROTR⁶(x) ⊕ ROTR¹¹(x) ⊕ ROTR²⁵(x). |
Detailed Description¶
No heap allocation, no floating point, no external dependencies. Static K[64] round constants table consumes ~256 bytes of ROM.
Public Static Attributes Documentation¶
variable H_INIT¶
FIPS 180-4 initial hash values (H0–H7).
variable K¶
FIPS 180-4 round constants (K0–K63).
Public Functions Documentation¶
function syn_sha256_final¶
Finalize the hash and produce the 32-byte digest.
After calling this, the context must be re-initialized before reuse.
Parameters:
ctxSHA-256 context.hashOutput buffer (must be at least 32 bytes).
function syn_sha256_init¶
Initialize a SHA-256 context.
Parameters:
ctxContext to initialize.
function syn_sha256_update¶
Feed data into the hash.
Can be called repeatedly with arbitrary chunk sizes.
Parameters:
ctxSHA-256 context.dataData to hash.lenLength in bytes.
Public Static Functions Documentation¶
function ch¶
Choice function: Ch(x,y,z) = (x ∧ y) ⊕ (¬x ∧ z).
Parameters:
xFirst input.ySecond input.zThird input.
Returns:
Ch(x, y, z).
function gamma0¶
Small sigma-0: σ₀(x) = ROTR⁷(x) ⊕ ROTR¹⁸(x) ⊕ SHR³(x).
Parameters:
xInput word.
Returns:
σ₀(x).
function gamma1¶
Small sigma-1: σ₁(x) = ROTR¹⁷(x) ⊕ ROTR¹⁹(x) ⊕ SHR¹⁰(x).
Parameters:
xInput word.
Returns:
σ₁(x).
function maj¶
Majority function: Maj(x,y,z) = (x ∧ y) ⊕ (x ∧ z) ⊕ (y ∧ z).
Parameters:
xFirst input.ySecond input.zThird input.
Returns:
Maj(x, y, z).
function rotr¶
Circular right rotate.
Parameters:
xValue to rotate.nNumber of bits to rotate.
Returns:
Rotated value.
function sha256_transform¶
Process a single 64-byte block.
Parameters:
stateRunning hash state (8 × uint32_t).block64-byte input block.
function sigma0¶
Big Sigma-0: Σ₀(x) = ROTR²(x) ⊕ ROTR¹³(x) ⊕ ROTR²²(x).
Parameters:
xInput word.
Returns:
Σ₀(x).
function sigma1¶
Big Sigma-1: Σ₁(x) = ROTR⁶(x) ⊕ ROTR¹¹(x) ⊕ ROTR²⁵(x).
Parameters:
xInput word.
Returns:
Σ₁(x).
The documentation for this class was generated from the following file src/syntropic/util/syn_sha256.c