tobogganSe connecter

louise

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

83 lignes · 3947 octetsBrut · Historique

ADR 0050: std/crypto and std/base64 — the SCRAM primitives

Status: Proposed (2026-10-18, issue #145); needs engineering review (#44).

Context

The postgres package (#145) authenticates with SCRAM-SHA-256 (RFC 5802, RFC 7677), the default since PostgreSQL 14. That needs SHA-256, HMAC-SHA-256, PBKDF2-HMAC-SHA-256 and base64. Nothing in std hashed cryptographically; std/hash is for hashing values, not this.

Decision

Two small std modules over new runtime externs:

// std/crypto
pub fn sha256 :: data: Bytes -> Bytes
pub fn hmac_sha256 :: key: Bytes message: Bytes -> Bytes
pub fn pbkdf2_hmac_sha256 ::
  password: Bytes
  salt: Bytes
  iterations: Int
  length: Int
  -> Bytes

// std/base64
pub fn encode :: data: Bytes -> String
pub fn decode :: text: String -> Result<Bytes, String>
  • Over ring, in louise_rt_prims. ring is already rustls's provider (ADR 0038), so it is in the tree and already cross-built by the aarch64 CI leg; no new dependency enters the tree. The hashes live in louise_rt_prims (which both back ends call) because a hash must never drift between the interpreter and native code — the prims crate exists for exactly that. --gc-sections keeps ring out of programs that never hash (ADR 0042). SHA-1 and MD5 are not offered: SCRAM needs SHA-256, and weak hashes should not be one import away.
  • Base64 is a hand-rolled pure kernel in louise_rt_prims (no dependency), with RFC 4648's vectors.
  • pbkdf2_hmac_sha256 is blocking: the iteration count is the caller's, so the derivation runs on the blocking pool (ADR 0005) and a large count never stalls a scheduler thread — the argon2 precedent. sha256 and hmac_sha256 are pure, base64_* too.
  • Not a cryptography library. A real one (signatures, AEAD) wants a reviewed binding, the way argon2 is a package over a native dependency. TLS itself is in the runtime (std/tls).

Consequences

  • Every check of docs/runtime-abi.md's "Adding a runtime extern" applies; louise_codegen_c/tests/externs.rs cross-checks the five places.
  • Tested by tests/run/crypto.lse on both backends against FIPS 180-4, RFC 2202, RFC 7914-style PBKDF2 and RFC 4648 vectors.
  • The interpreter can now run a full SCRAM exchange (crypto is no longer a native-only story), so the postgres package's codec and handshake are unit-testable with recorded transcripts without a database.

Note — 2026-10-19: ring feature-gated for the no-qemu aarch64 check

The claim above that ring is "already cross-built by the aarch64 CI leg" was wrong: the forge has no qemu, so its aarch64 leg only type-checks and assembles louise_rt with --no-default-features (without tls, ADR 0038 — precisely because ring's build script needs a C cross-compiler). Making louise_rt_prims depend on ring unconditionally broke that leg (CI runs 433+). ring is now optional, behind louise_rt_prims's and louise_rt's default crypto feature; only the no-qemu check builds without it. The tl_crypto_* externs stay exported there and panic "crypto support not built in", the tls precedent: nothing links a program against that build (the archives programs link come from cargo build -p louise_rt, default features, and scripts/runtime.sh, --features mimalloc,tls,crypto), and if one did, it gets that message instead of a link error.

Note — 2026-10-28: Ed25519 is in std after all (ADR 0067)

Status: Proposed; needs engineering review (#44).

"A real one (signatures, AEAD) wants a reviewed binding" is amended for one scheme: ADR 0067 puts Ed25519 verification in std/crypto, with signing for tests and tools, over the ring already linked. A package was not possible: C bindings take no Bytes yet, and there was no source to vendor. Other signature schemes, AEAD and key exchange still belong in packages.