DigestBytesErr
:= [WrongLength({ expected : U64, actual : U64 })]
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 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())
A typed SHA-256 digest.
Return this SHA-256 digest as its 32 raw bytes.
to_hex : Digest -> Str
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.
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 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())
A typed BLAKE3 digest.
Return this BLAKE3 digest as its 32 raw bytes.
to_hex : Digest -> Str
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.