Module crypto/sha512
SHA-512 (FIPS 180-4) — streaming hasher + one-shot helpers
(plans/archive/STD_API_AUDIT.md §7 P0 item 7).
64-bit words, 128-byte blocks, 80 rounds. The message-length field is
128 bits in the spec; this implementation tracks the total as a u64
BYTE count (caps input at 2^61 bytes — two exbibytes) and writes the
high 64 bits of the bit length as total >> 61.
{ sha512_hex } :: import("std/crypto/sha512");
digest := sha512_hex(data); // 128-char lowercase hex
Stability
unstable — the FIPS vectors pass (tests/crypto/digest.test.yo), but
this module carries a deviation that becomes a promise the moment it is
frozen: the spec's message-length field is 128 bits and this
implementation tracks a u64 byte count, so inputs are capped at 2^61
bytes and the high half of the length field is derived rather than
counted. Nothing in reach of a Yo program hits that, yet "SHA-512 as
specified" and "SHA-512 up to two exbibytes" are different contracts.
SHA-384 — the same compression function with a different IV and a
truncated output — is also absent, and adding it may well change how
this file is organised. The finish / finish_bytes double surface and
the single-use finish are the std/crypto/digest questions.
Types
SHA-512 streaming state (the Sha256 skeleton at 64-bit width).
Fields
| Name | Type | Description |
|---|---|---|
_h | Array(u64, 8) | |
_buf | Array(u8, 128) | |
_buflen | usize | |
_total | u64 |
Trait Implementations
impl(Sha512, ...)
new : (Sha512) fn() -> Sha512A hasher seeded with the FIPS 180-4 SHA-512 initial state.
Returns: Sha512
update : (Sha512) fn(self : Sha512, data : ArrayList(u8)) -> Sha512finish : (Sha512) fn(self : Sha512) -> Array(u8, 64)Append the padding and the 128-bit length field, fold the last block in, and return the 64-byte digest.
Single use — the padding goes into the hasher's own buffer, so a
second finish returns a digest of the padded state rather than of
the message. One hasher, one message.
Parameters
| Name | Type | Notes |
|---|---|---|
self | Sha512 |
Returns: Array(u8, 64)
impl(Sha512, Digest(...))
new : (Sha512) fn() -> Sha512A hasher seeded with the FIPS 180-4 SHA-512 initial state.
Returns: Sha512
update : (Sha512) fn(self : Sha512, data : ArrayList(u8)) -> Sha512digest_size : (Sha512) fn() -> usizeThe digest length in bytes (32/64/20/16).
Returns: usize
block_size : (Sha512) fn() -> usizeThe compression block size in bytes (64, or 128 for SHA-512) — what HMAC pads keys to.
Returns: usize
Functions
SHA-512 of data in one call — the 64-byte digest. Exactly
Sha512.new().update(data).finish().
Parameters
| Name | Type | Notes |
|---|---|---|
data | ArrayList(u8) |
Returns: Array(u8, usize(64))