Digest interfacev0.1.0

Source
An incremental digest.
pub interface Digest {
    func Update(self: &var Self, bytes: char8[..]);
    func Finish(self: &var Self, into: var char8[..]);
    func DigestLength(self: &Self) -> uint;
    func BlockLength(self: &Self) -> uint;
}

Take one by generic bound and mutable reference — func Sum<D: Digest>(digest: &var D) — so work applies to the caller's state without copying it.

Requirements

Update

func Update(self: &var Self, bytes: char8[..])

Adds bytes to what is being hashed. Any split of the same byte sequence across any number of calls gives the same digest. An empty slice is legal and changes nothing.

NameTypeDescription
byteschar8[..]the bytes to absorb

Source

Finish

func Finish(self: &var Self, into: var char8[..])

Writes the digest into into and leaves the state unusable for further updates. into must be at least DigestLength bytes; anything beyond that is untouched. Finishing twice is a caller error rather than a supported operation — a digest is a one-shot summary of everything fed to it, and an implementation is free to consume its state producing one.

NameTypeDescription
intovar char8[..]receives the output

Source

DigestLength

func DigestLength(self: &Self) -> uint

How many bytes Finish writes.

Returns: how many bytes a digest occupies

Source

BlockLength

func BlockLength(self: &Self) -> uint

How many bytes the algorithm processes at a time. Needed by the constructions built on digests — HMAC pads its key to exactly this — and by callers choosing a buffer size that avoids splitting work.

Returns: how many bytes the compression function consumes at a time

Source

Implementations

TypeSummary
Blake3An incremental BLAKE3 hash.
Sha3An incremental SHA-3 hash at any of its four sizes.
Sha256An incremental SHA-256 or SHA-224.
Sha512An incremental SHA-512, SHA-384, SHA-512/224 or SHA-512/256.