Skip to content

std/sha512

Pure-Milo SHA-512 and SHA-384 (FIPS 180-4), no platform crypto dependency.

milo
from "std/sha512" import { Sha512, Sha384 }

The same shape as std/sha256, one size up: 64-bit lanes, a 128-byte block, 80 rounds, and a 128-bit length field. SHA-384 is the identical compression function with a different initial state, truncated to 48 bytes — the truncation is what makes it resistant to the length-extension attack SHA-512 admits.

Every branch and memory access is on public data (round index, message length), so the trace is input-independent.

Functions

Sha512.hash

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

64-byte SHA-512 digest as 128-char lowercase hex.

Sha512.bytes

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

Raw 64-byte SHA-512 digest. Use this when the digest feeds further bytes (HMAC, key derivation) rather than a display string.

Sha384.hash / Sha384.bytes

milo
fn Sha384.hash(input: &string): string
fn Sha384.bytes(input: &string): string

96-char hex, and the raw 48-byte digest.

Checked against the FIPS 180-4 / RFC 6234 vectors in tests/fixtures/sha512Vectors.milo.