Crypto
Cryptographic digest functions for byte data.
Use Crypto.SHA256.hash(bytes) or Crypto.BLAKE3.hash(bytes) when the
whole input is already in memory. The result is an algorithm-specific
typed digest, so SHA-256 digests compare only with SHA-256 digests and
BLAKE3 digests compare only with BLAKE3 digests.
Digest bytes and hex are both available: to_bytes returns the raw
32-byte digest, while to_hex returns 64 lowercase hexadecimal
characters. from_bytes and from_hex validate that external digest data
has the exact expected length before producing a typed digest.
For input that arrives in pieces, use hash_chunks(chunks) with an
Iter(List(U8)), or use Hasher.empty, Hasher.write, and
Hasher.finish manually. finish observes the current hasher state; it
does not consume the prior value.
These are digest APIs. They are not password hashing, KDF, HMAC, keyed
BLAKE3, or digital signature APIs.
:= [WrongLength({ expected : U64, actual : U64 })]:= [WrongLength({ expected : U64, actual : U64 }), InvalidHex({ index : U64, byte : U8 })]SHA-256 hashing.
Use hash for one input list, hash_chunks for an iterator of byte
chunks, and Hasher when you want to thread the state yourself.
hash : List(U8) -> Digest Hash all bytes in one SHA-256 operation.
digest = Crypto.SHA256.hash("abc".to_utf8())
hex = digest.to_hex()
hash_chunks : Iter(List(U8)) -> Digest Hash byte chunks in order with SHA-256.
digest = Crypto.SHA256.hash_chunks(["a".to_utf8(), "bc".to_utf8()].iter())
to_bytes : Digest -> List(U8) Return this SHA-256 digest as its 32 raw bytes.
Return this SHA-256 digest as 64 lowercase hexadecimal characters.
from_bytes : List(U8) -> Try(Digest, DigestBytesErr) Build a SHA-256 digest from exactly 32 raw bytes.
from_hex : Str -> Try(Digest, DigestHexErr) Build a SHA-256 digest from exactly 64 ASCII hex characters.
Uppercase and lowercase hex are accepted; 0x prefixes are not.
is_eq : Digest, Digest -> Bool Returns True if both SHA-256 digests contain the same bytes.
to_hash : Digest, Hasher -> Hasher Feed the digest bytes into a regular non-cryptographic Hasher.
to_inspect : Digest -> Str Return a typed, human-readable SHA-256 digest.
Incremental SHA-256 state.
Start a fresh SHA-256 hasher.
write : Hasher, List(U8) -> Hasher Add bytes to this SHA-256 hasher and return the updated hasher.
finish : Hasher -> Digest Finish a SHA-256 hasher snapshot and return its digest.
The hasher value is immutable, so callers can also continue writing to the prior state.
BLAKE3 hashing in the default unkeyed digest mode.
Use hash for one input list, hash_chunks for an iterator of byte
chunks, and Hasher when you want to thread the state yourself.
hash : List(U8) -> Digest Hash all bytes in one BLAKE3 operation.
digest = Crypto.BLAKE3.hash("abc".to_utf8())
hex = digest.to_hex()
hash_chunks : Iter(List(U8)) -> Digest Hash byte chunks in order with BLAKE3.
digest = Crypto.BLAKE3.hash_chunks(["a".to_utf8(), "bc".to_utf8()].iter())
to_bytes : Digest -> List(U8) Return this BLAKE3 digest as its 32 raw bytes.
Return this BLAKE3 digest as 64 lowercase hexadecimal characters.
from_bytes : List(U8) -> Try(Digest, DigestBytesErr) Build a BLAKE3 digest from exactly 32 raw bytes.
from_hex : Str -> Try(Digest, DigestHexErr) Build a BLAKE3 digest from exactly 64 ASCII hex characters.
Uppercase and lowercase hex are accepted; 0x prefixes are not.
is_eq : Digest, Digest -> Bool Returns True if both BLAKE3 digests contain the same bytes.
to_hash : Digest, Hasher -> Hasher Feed the digest bytes into a regular non-cryptographic Hasher.
to_inspect : Digest -> Str Return a typed, human-readable BLAKE3 digest.
Incremental BLAKE3 state.
Start a fresh BLAKE3 hasher.
write : Hasher, List(U8) -> Hasher Add bytes to this BLAKE3 hasher and return the updated hasher.
finish : Hasher -> Digest Finish a BLAKE3 hasher snapshot and return its digest.
The hasher value is immutable, so callers can also continue writing to the prior state.