Module digest

Module digest 

Source
Expand description

Digests and the two encodings a digest is written in.

The half of Wave 2’s crypto item that belongs to the host under lib/README.md’s division: a hash function is somebody else’s table and base64 is somebody else’s grammar, so both are primitives rather than Beck. What is composition — a signed token, a fingerprint, a check that reads the two halves apart — is lib/crypto.beck.

Three constraints shaped what is here.

  • A digest is a pure function. It performs no effect and it is the same on every replay, so nothing about it has to be recorded on an envelope. That is the difference between hashing and the other two things a crypto library usually offers: random bytes and a clock are nondeterministic, and Beck already has uuid() and now() for those, both charged nondet.
  • Only one function turns a secret[Str] into a Str, and it is keyed. §3.5’s property is that a secret cannot reach a browser; a message authentication code exists precisely to be handed to one, so the declassification is the point rather than a hole in it — but it is charged cap.sign so that a view cannot mint one, and docs/adr/0014 is the record of that decision.
  • Comparing a digest is not ==. same is constant-time, because a verifier that returns early tells the caller where the first wrong byte was.

BLAKE3 rather than SHA-2 because it is already in this tree — beck-rt’s SignedIdentity (docs/48) and the signal graph’s stable ids both use it — and adding a second hash function to avoid reusing one is a dependency taken for symmetry. docs/adr/0015 records why ring was not taken instead, and what that leaves unbuilt.

Functions§

base64_decode
The inverse of base64_encode, tolerant of padding and of the standard alphabet.
base64_decode_bytes
The same decoder, stopping before the text.
base64_encode
RFC 4648 §5 — the URL-and-filename-safe alphabet, without padding.
base64_encode_bytes
The same encoder, starting before the text.
hex_decode
The inverse of hex_encode, or why it is not one.
hex_encode
Lowercase hex, two digits per byte of UTF-8.
keyed
A message authentication code over message under key, as 64 lowercase hex digits.
of
BLAKE3 of text, as 64 lowercase hex digits.
same
Equality that does not stop at the first difference.
uuid_normalise
A UUID in the canonical 8-4-4-4-12 form, lowercased, or why it is not one.
uuid_version
Which version a canonical UUID declares, as the digit in the third group.