Skip to content

std/sha256 ​

Pure-Milo SHA-256 (FIPS 180-4) — no platform crypto dependency. Constant-time by construction (every branch and memory access is on public data) and WCET-analyzable: the round loops are fixed counts, so milo wcet resolves a worst-case time bound and milo safety confirms termination.

milo
from "std/sha256" import { Sha256 }

Example ​

milo
let hex = Sha256.hash("hello world")
// "b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9"

API reference ​

Sha256 ​

milo
pub struct Sha256

Sha256 namespace — Sha256.hash(input) hex digest, Sha256.bytes(input) raw 32-byte digest.

Sha256.bytes ​

milo
fn Sha256.bytes(input: &string): string

SHA-256 digest as 32 raw bytes. Use this when the digest feeds further bytes (HMAC, key derivation); Sha256.hash wraps it for the common hex case.

Sha256.hash ​

milo
fn Sha256.hash(input: &string): string

SHA-256 digest as a 64-char lowercase hex string.