diff --git a/libraries/hash/openspec/changes/genesis/design.md b/libraries/hash/openspec/changes/genesis/design.md index 82a56ce..0d67c67 100644 --- a/libraries/hash/openspec/changes/genesis/design.md +++ b/libraries/hash/openspec/changes/genesis/design.md @@ -10,7 +10,9 @@ scrypt for passwords, BLAKE3 on demand. Boost.Hash2 1.92 already has SHA-1/2/3, BLAKE2 and HMAC, and none of these. The specification is `reference/spec.md`, the plan `reference/plan.md`. Increment 1 (the plan's Tasks 0 to 24) is built in the library's own repository and green on every local lane, not yet published (the owner's gates); D25 to D32 -record what building it decided, and the spec and the plan are amended to match. +record what building it decided, and the spec and the plan are amended to match. D33 records the +owner's decision of 2026-11-16 that every key derivation defaults to `backends::hash2`, which +retires the measured defaults, the profiles and the overrides of D8, D20, D28 and D32. Constraints every decision works within, from the superproject's `CODING-GUIDELINES.md`: @@ -34,12 +36,12 @@ Constraints every decision works within, from the superproject's `CODING-GUIDELI - Boost.Hash2's algorithms and HMAC under webcpp::hash's names, as the Hash2 types themselves. - Keccak-256 (Ethereum's) and BLAKE3 (with keyed hashing, key derivation and extendable output) in Hash2's HashAlgorithm form, so that `hash_append` and the rest of Hash2 work with them. -- HKDF and PBKDF2 over any Hash2 hmac, each on a backend chosen by a template parameter, with a - default chosen by the owner's rule, on every target. +- HKDF and PBKDF2 over any Hash2 hmac, each on a backend chosen by a template parameter, with + `backends::hash2` as the default on every target (D33). - Argon2id and scrypt from libsodium. - Proof by the RFCs' vectors, the C libraries' own suites, agreement between backends, WebCrypto as an outside oracle, a counting allocation test and a test for every message; the size table - and the PBKDF2 throughput measured. + and the PBKDF2 throughput measured, kept as dated reference that decides no default (D33). **Non-Goals:** @@ -125,7 +127,8 @@ first 64. `template >` function templates, `Kdf` the tag of the operation itself (D25); `argon2id` and `scrypt` are `template >` (and `kdfs::scrypt`), which is -`backends::sodium` in increment 1 and honours or refuses their overrides. The backends are +`backends::sodium` (until 2026-11-16 it also honoured or refused their overrides, retired by D33; +the default of every other key derivation is `backends::hash2`, D33). The backends are `backends::hash2`, `backends::sodium`, `backends::bearssl`, `backends::openssl` (and later `backends::botan`). The public functions do every guard once; a backend's header specialises `detail::hkdf_engine`, `detail::pbkdf2_engine`, @@ -173,6 +176,11 @@ wiped; it compares no secret. ### D8. The default backend: the fastest natively, the smallest on WebAssembly, per KDF +> **Superseded on 2026-11-16 by D33.** No measurement decides a default any more: every key +> derivation defaults to `backends::hash2`, and argon2id and scrypt to `backends::sodium`. +> `detail/ranking.hpp` and the lane `measure` are retired. What still holds: the second +> parameter of `default_kdf_backend`, its name and its signature. + `default_kdf_backend`: the program's override or profile when it gives one (D20); natively the first linked backend having the KDF over the hmac in the measured throughput order (the owner's "OpenSSL when linked, else hash2", which the measurement confirms or reports to @@ -300,6 +308,11 @@ library; exceptions on and off; every lane. ### D18. The measurements the owner asked for are tasks of the plan +> **Superseded in part on 2026-11-16 by D33.** The measured table no longer orders the backends +> or decides a default: `doc/measurements.json` and `doc/measurements.adoc` stay as a dated +> reference measured on 2026-11-16, and no lane re-measures them. What still holds: the +> measurements were made, and the PBKDF2-HMAC-SHA-512 throughput of `doc/performance.adoc`. + The measured table (D8, D20) and PBKDF2-HMAC-SHA-512 at 1,000,000 iterations for `backends::hash2`, OpenSSL and libsodium. libsodium has no PBKDF2, so its line measures RFC 8018's loop over `crypto_auth_hmacsha512_*` in the benchmark program, never in the library: the measurement of @@ -328,6 +341,13 @@ provides each function; every refusal names the backends that have it. ### D20. One profile changes every default; overrides per algorithm; a measured table +> **Superseded on 2026-11-16 by D33.** Every profile (`WEBCPP_HASH_PROFILE_FASTEST`, `_SMALLEST`, +> `_PORTABLE`, `_BACKEND_`), hash's reading of webcpp's umbrella `WEBCPP_PROFILE_*`, the +> per-algorithm overrides `WEBCPP_HASH_DEFAULT_BACKEND__`, MSVC's +> `detect_mismatch` of the profile and of the overrides, `detail/ranking.hpp` and the lane +> `measure` are retired. Nothing of this decision still holds but its history; the measurements +> it named are a dated reference (D18). + `config.hpp` takes exactly one profile define: none (`auto`, the owner's rule: fastest natively, smallest on WebAssembly), `WEBCPP_HASH_PROFILE_FASTEST`, `_SMALLEST`, `_PORTABLE` (the same code on every target: hash2, xkcp, blake3, sodium, bearssl, in that order) or `_BACKEND_`; and @@ -423,6 +443,14 @@ Emscripten, a pool thread with a synchronous backend. ### D25. HKDF's two steps are public tags, and the default backend is chosen per operation +> **Superseded in part on 2026-11-16 by D33.** The default is no longer chosen per operation from +> a profile's order or a measured row: it is `backends::hash2` for `hkdf`, `hkdf_extract`, +> `hkdf_expand` and `pbkdf2` alike, and there is no override. What still holds: the public tags +> `kdfs::hkdf`, `kdfs::hkdf_extract`, `kdfs::hkdf_expand`, `kdfs::pbkdf2`, `kdfs::argon2id` and +> `kdfs::scrypt`; each function's default named through its own tag; `backend_has_v` answering +> for the two steps (false for `backends::bearssl`); and BearSSL's HKDF refusing the steps at +> compile time when named. + `kdfs` declares a tag per operation of increment 1: `hkdf` (both steps at once, the function `hkdf`), `hkdf_extract`, `hkdf_expand`, `pbkdf2`, `argon2id` and `scrypt`. `default_backend< Algorithm, Hmac>` (and `default_kdf_backend`, the same) is chosen for the operation @@ -484,6 +512,10 @@ tests link with the flag. ### D28. The overrides' refusals live behind `kdf.hpp`, not `config.hpp` +> **Superseded on 2026-11-16 by D33.** The overrides are retired, and with them the generated +> `detail/overrides.hpp`, `tools/hash/measure.py` (deleted whole), `overrides_list_test` and their +> `#error`s and `detect_mismatch`. Nothing of this decision still holds but its history. + `config.hpp` keeps the profile's refusals (two library profiles, two umbrella profiles, `WEBCPP_HASH_PROFILE_BACKEND_OPENSSL` and `/webcpp/hash//openssl` on Emscripten) and the profile's `detect_mismatch`. The per-algorithm overrides, one block per algorithm of @@ -552,6 +584,11 @@ measurements. ### D32. The measured native HKDF order is provisional +> **Superseded on 2026-11-16 by D33.** No order is committed or compared any more, so none is +> provisional, and no re-measurement is due before a release; O2 is closed. What still holds: the +> facts it records about increment 1's measurement (one loaded macOS arm64 machine, HKDF's native +> medians under 1 percent apart), which D33 cites among its reasons. + The committed measurements were made on one machine, macOS on arm64 (Apple clang 21), shared and loaded (`doc/measurements.json` records `loaded: true`). The order follows spec 4.2's rule alone: by the median of the invocations' medians, a first measurement by the medians alone, and a committed @@ -572,6 +609,90 @@ orders are always compared. decides, and a noise rule is the spec's to give); the recorded expectation kept against the measurement (the owner asked for a measured order). +### D33. Every key derivation defaults to `backends::hash2`; no measurement decides a default + +The owner decided on 2026-11-16 to replace the measured default (D8, D20, D25's orders, D32) by a +fixed one. Increment 1 had built the rule as specified: a profile per program, an override per +algorithm, and orders of backends by size and throughput generated into `detail/ranking.hpp` from +`doc/measurements.json` and checked by the own lane `measure`. Its measurements showed that the +rule bought little: for HKDF the native medians of libsodium, hash2 and OpenSSL were under 1 +percent apart on a loaded machine (D32), and on WebAssembly the backends' isolated programs +differed by a few KB; a default that followed them could change with a machine's load, a pin move +or the set of libraries a program happened to link. + +- **The default.** The default backend of every key derivation, `hkdf`, `hkdf_extract`, + `hkdf_expand` and `pbkdf2`, over every hmac, on every target and whatever the program links, is + `backends::hash2`. `backends::sodium` is the default only for what hash2 does not offer, + `argon2id` and `scrypt`, of which it is the only backend; a program that calls them without + linking libsodium stops with libsodium's "needs" message (spec 5.7), which the primary template + of the default backend's engine in `detail/engines.hpp` raises for `backends::sodium`, tested by + the messages `argon2id_default_not_linked` and `scrypt_default_not_linked`. +- **The capability table names each default.** `doc/capabilities.json` (layout version 3) gives + each function row a `"default"`: `hash2` for `hkdf_extract`, `hkdf_expand`, `hkdf` and `pbkdf2`, + `sodium` for `argon2id` and `scrypt`, `null` for a type; `capabilities_test` compares it with + `default_backend`, and `tools/hash/doc_tables.py` renders it. The backends' `"portable"` field + and the algorithms' `"overridable"` field are removed. +- **The other backends are explicit choices.** `backends::bearssl` and `backends::openssl`, and + `backends::sodium`'s HKDF, stay and are tested as before (their vectors, the agreement tests, + their limits and refusals), but a program reaches them only by naming them in the type, as + `hkdf`; none is ever a default. +- **The public names stay.** `default_backend` and + `default_kdf_backend` keep their names and signatures, and the tags + `kdfs::hkdf_extract` and `kdfs::hkdf_expand` stay, so that `backend_has_v` answers for the steps; + the aliases' answer no longer depends on the hmac, the libraries linked or the target. +- **No define changes a default.** A former profile or override define has no effect; + `default_backend_former_defines`, `default_backend_test` built with + `WEBCPP_HASH_PROFILE_FASTEST`, `WEBCPP_HASH_PROFILE_SMALLEST`, + `WEBCPP_HASH_PROFILE_BACKEND_BEARSSL`, `WEBCPP_PROFILE_FASTEST`, + `WEBCPP_HASH_DEFAULT_BACKEND_HKDF_SODIUM` and `WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_BEARSSL` with + every library linked, proves it on the four targets. +- **Why hash2:** it is the only backend that covers every hmac, every operation and every target + (D7); it is header-only, so a program carries only the code it calls and shares the SHA code of + Boost.Hash2 it already uses; and the measured differences that would have chosen another + backend are nanoseconds natively for HKDF and a few KB isolated on WebAssembly. A default that + is the same everywhere is one a reader of the call can name without knowing the build. +- **Why the overrides go too** (the implementer's decision, recorded): with the backends named in + the type, an override that changes what `hkdf` means across a whole program would make + `backends::bearssl` or `backends::openssl` a default again, against this decision, and would hide + the backend from the reader of the call; and `argon2id` and `scrypt` have one backend, so their + overrides choose nothing. +- **Retired:** every profile, `WEBCPP_HASH_PROFILE_FASTEST`, `_SMALLEST`, `_PORTABLE` (which now + equals the default, since hash2 exists on every target) and `_BACKEND_` (which would make + another backend a default); hash's reading of webcpp's umbrella `WEBCPP_PROFILE_*`; MSVC's + `detect_mismatch` of the profile (`webcpp_hash_profile`) and of the overrides + (`webcpp_hash_default_backend_`), since a fixed default cannot differ between two + translation units; the per-algorithm overrides + `WEBCPP_HASH_DEFAULT_BACKEND__` with the generated `detail/overrides.hpp` and + `overrides_list_test`; the generated `include/webcpp/hash/detail/ranking.hpp` and the code that + reads it; the profiles' tests and messages; the CI's measure lane, the matrix entry "Own lane + (hash, measure)" and `libs/hash/test/measure`; `tools/hash/measure.py` whole (`--write`, + `--check`, `--capabilities`, `--overrides`, `--refusals`) with `tools/test/hash_measure_test.py`; + and, used by the measure lane alone, `tools/ci/matrix.py`'s `EVERY_TARGET_LANES` (an own lane + naming no target that builds every target) and `tools/lint/compile_commands.py`'s handling of a + native lane's WebAssembly commands, each with its test. +- **Kept:** `doc/measurements.json`, its records and orders unchanged, its about and layout text + relabelled as a reference measured on 2026-11-16 that decides nothing and its digest recomputed; + `doc/measurements.adoc`, now rendered from it by `tools/hash/doc_tables.py` without the orders and + the default of each key derivation, with that label and why hash2 is the default; `doc_tables.py` + also renders `doc/backends.adoc` from `doc/capabilities.json`, and its `--check`, run at every + documentation build, fails when `measurements.json`'s digest does not match its content (a hand + edit of the reference); the guide's comparison tables still read the measurements (D31); the + PBKDF2-HMAC-SHA-512 throughput of `doc/performance.adoc` (D18), its times measured by hand with + `bench/collect.py`, while the benchmark's correctness program `pbkdf2_sha512_key` (its derived + keys checked, never its time) runs in every lane of `libs/hash/test`; the guide's chapter on the + profile, now `choosing_backend.adoc` (anchors `hash-choosing-backend` and + `hash-default-backend`), with `guide.json`'s use-case field `profile` renamed `backend` (layout + version 2); `doc/capabilities.json` and + `capabilities_test`; every backend with its tests; and the asynchronous family's + `default_async_backend` (D23, increment 7), which this decision does not change: WebCrypto on + Emscripten for the algorithms it serves, else `default_backend`. +- **Alternatives:** keeping the measured rule (a default that follows a loaded machine's + medians, a pin move or the link set, guarded by a lane that re-measures on four targets and an + open question per platform, O2, for differences of nanoseconds and a few KB); keeping the + overrides without the profiles (one define would still turn `hkdf` into BearSSL's or + OpenSSL's across a program, unseen at the call, and would choose nothing for argon2id and + scrypt). + ## Risks / Trade-offs - [libsodium's `sodium_init` on Emscripten stirs its random generator through JavaScript that @@ -580,20 +701,15 @@ orders are always compared. and a failure there is investigated as a build difference before anything else. - [The 1 GiB scrypt vector on wasm32] -> its own program; the plan measures on which WebAssembly targets it runs, and the page states the memory a WebAssembly program needs. -- [OpenSSL `no-asm` on MSVC, wasip2 and wasip3] -> OpenSSL stays the native default (the - owner's rule, as webcpp::crypto's D22 rules); the throughput table shows the difference and the - page says how to choose `backends::hash2`. -- [The size order may differ between hmacs or between targets] -> the generated file holds one - order per target and algorithm (KDFs over the two measured hmacs); a change is caught by the - `measure` lane. -- [Throughput differs between machines] -> a committed native order changes only past a 10 percent - difference in the median, and the table records the machine; the owner sees each change. -- [Increment 1's throughput was measured on one loaded macOS arm64 machine, and the native HKDF - order rests on medians under 1 percent apart] -> D32: re-measured on an idle machine before a - release; a lane on another native toolchain skips the native order comparison. -- [The CI's own-lanes job for `measure` builds and runs every program on four targets] -> it may - reach the job's 60-minute limit; a later change can generate the measure lane's programs at - build time or split the lane by target. +- [OpenSSL `no-asm` on MSVC, wasip2 and wasip3] -> OpenSSL is never a default (D33); the + throughput table shows the difference, and a program that wants OpenSSL's speed natively names + `backends::openssl` in the type. +- [hash2 is slower than OpenSSL for PBKDF2 natively (OpenSSL 1.7 to 3.6 times faster in the + dated measurement)] -> accepted by the owner for a default that is the same on every target + (D33); the guide's comparison table and `doc/performance.adoc` show it, and the page says how to + name `backends::openssl`. +- [The dated measurements age as the pins move] -> they decide nothing (D33) and are labelled + with their date. - [The scope of increments 2 to 6 is wide] -> each increment is usable alone and merged before the next; a cell of the capability table is checked against the library at its pin by the increment's first task, never assumed. @@ -617,13 +733,28 @@ later change moves its HKDF need onto it (spec 9.2) and its libsodium backend on `/third_party//sodium`. To start, follow `reference/STATUS.md` ("How to resume"). Rollback: the change is a proposal; withdrawing it deletes `openspec/changes/genesis/`. -## Open Questions +D33 changes increment 1's built code before anything is published: the profiles, the overrides, +`detail/ranking.hpp`, `detail/overrides.hpp`, their tests and messages and the lane `measure` are +removed in the library's repository and the superproject's integration branch, and +`default_backend` answers `backends::hash2` (`backends::sodium` for `argon2id` and `scrypt`). A +program that named a backend in the type is unchanged; one that gave a former profile or override +define still compiles, the define having no effect, and runs on `backends::hash2`; one that relied +on a define to reach BearSSL or OpenSSL names that backend in the type instead. -- **O2. One native order, or one per platform?** The native throughput orders were measured on - macOS arm64 alone (D32). Whether that one order serves Linux and Windows (and x86-64), or each - platform gets an order of its own measured on it, is the owner's to decide before a release; - until then a lane on another native toolchain skips the native order comparison. +## Open Questions -O1 (a browser backend over WebCrypto) was answered by the owner on 2026-11-14: D23. The owner's +- **O3. The default of the families for an algorithm hash2 lacks.** D33 decides the defaults of + increment 1. From increment 2 on, `digest`, `hasher`, `mac` and `argon2` default to + `default_backend` over algorithms Boost.Hash2 does not have (Keccak-224, KMAC, + BLAKE2b with a salt, Argon2i, ...). The proposed answer, in D33's spirit, is a fixed default + written beside the capability table: the first that has the algorithm of `backends::hash2`, + `backends::xkcp`, `backends::blake3` and `backends::sodium`, never `backends::bearssl`, + `backends::openssl` or `backends::botan`; an algorithm only those have would then have no + default, and a call names its backend. It is the owner's to decide before increment 2's first + task. + +O1 (a browser backend over WebCrypto) was answered by the owner on 2026-11-14: D23. O2 (one +native throughput order, or one per platform) was closed by the owner's decision of 2026-11-16, +D33: no measured order decides a default any more. The owner's gates (creating `webcpporg/hash`, adding `libs/hash`, every push and merge, and opening the Boost.Hash2 contribution) are in the plan's "Owner gates". diff --git a/libraries/hash/openspec/changes/genesis/proposal.md b/libraries/hash/openspec/changes/genesis/proposal.md index aa23aa9..fa5745b 100644 --- a/libraries/hash/openspec/changes/genesis/proposal.md +++ b/libraries/hash/openspec/changes/genesis/proposal.md @@ -12,12 +12,15 @@ only that HKDF "is written on Hash2's hmac when needed". The owner proposed a library of its own on 2026-11-14: one entry point for hashing and key derivation, on every target webcpp has (native, wasip2, wasip3, Emscripten), whose primitives are Boost.Hash2's and proven C libraries', whose key derivations have backends as webcpp::crypto's -algorithms do, and whose default backend is the fastest natively and the smallest on the web. He -decided its shape the same day and accepted it, then widened it: every backend exposes all its -library offers for hashing and key derivation, in increments by value; one profile in the -configuration changes every default at once; the browser's WebCrypto becomes a backend through a -parallel asynchronous API. Increment 1 is built in the library's own repository and green on -every local lane; it is not yet published, and the spec records what building it decided. +algorithms do, and whose default backend was first to be the fastest natively and the smallest +on the web. He decided its shape the same day and accepted it, then widened it: every backend +exposes all its library offers for hashing and key derivation, in increments by value; the +browser's WebCrypto becomes a backend through a parallel asynchronous API. Increment 1 is built in +the library's own repository and green on every local lane; it is not yet published, and the spec +records what building it decided. Its measurements showed differences of nanoseconds natively and +a few KB on WebAssembly between the backends of HKDF, so on 2026-11-16 the owner replaced the +measured default, the profiles and the overrides by one default: `backends::hash2` for every key +derivation on every target (design D33). ## What Changes @@ -35,7 +38,7 @@ every local lane; it is not yet published, and the spec records what building it dispatch natively. - **HKDF (RFC 5869: `hkdf_extract`, `hkdf_expand`, `hkdf`) and PBKDF2 (RFC 8018: `pbkdf2`)** as function templates `template >`, - the default chosen per operation through the public tags `kdfs::hkdf`, `kdfs::hkdf_extract`, + the default named per operation through the public tags `kdfs::hkdf`, `kdfs::hkdf_extract`, `kdfs::hkdf_expand` and `kdfs::pbkdf2`, over backends named after the library that does the work: `backends::hash2` (webcpp's construction over any Hash2 hmac, every target, the recorded departure from "webcpp writes no @@ -44,11 +47,13 @@ every local lane; it is not yet published, and the spec records what building it later `backends::botan`. A backend without the function refuses at compile time, naming those that have it; a backend whose C interface holds a length in an `int` refuses past `INT_MAX` (OpenSSL, `detail::backend_limits`). Every function that returns a result is `[[nodiscard]]`. -- **The default backend:** natively the fastest linked (the owner expected OpenSSL when linked, - else hash2; increment 1's measurement, on one loaded machine, put libsodium and hash2 ahead for - HKDF by under 1 percent, to be re-measured on an idle machine before a release); on - WebAssembly the one giving the smallest binary, from a measured size table (one KDF program per - backend per target), regenerated at every pin move and checked by an own lane. +- **The default backend** (the owner's decision of 2026-11-16, design D33): `backends::hash2` + for `hkdf`, `hkdf_extract`, `hkdf_expand` and `pbkdf2`, over every hmac, on every target and + whatever the program links; `backends::sodium` for `argon2id` and `scrypt`, its only backend. + BearSSL, OpenSSL and libsodium's HKDF stay, tested as before, reached only by naming them in the + type (`hkdf`). No measurement and no define decides a default: + the measured default of increment 1, its profiles, its overrides, `detail/ranking.hpp` and the + lane `measure` are retired. - **`argon2id` and `scrypt`** from libsodium (`crypto_pwhash_argon2id`, `crypto_pwhash_scryptsalsa208sha256_ll`), with libsodium's allocation of their memory recorded as a departure; the Argon2 reference implementation's allocation callbacks stay the @@ -59,17 +64,20 @@ every local lane; it is not yet published, and the spec records what building it program), `third_party/libs/xkcp` (`/third_party//xkcp`) and `third_party/libs/blake3` (`/third_party//blake3`). `/third_party//bearssl` gains webcpp::hash's canary. - **The superproject gains** `/webcpp/hash//openssl` (the one OpenSSL provider), - `tools/hash/measure.py` and the own lane `measure`, `tools/hash/doc_tables.py`, - `tools/test/hash_jamfiles_test.py` with its fixtures, chapter 10's three rows and chapter 17's - entry; libsodium links with `-sALLOW_MEMORY_GROWTH=1` on Emscripten. BLAKE3's own test program - runs in the library's own lane `c-suites`, beside libsodium's and XKCP's suites. + `tools/hash/doc_tables.py` (which renders `doc/backends.adoc` and the dated + `doc/measurements.adoc`; `tools/hash/measure.py` and the lane `measure` are retired by design + D33), `tools/test/hash_jamfiles_test.py` with its fixtures, chapter 10's + three rows and chapter 17's entry; libsodium links with `-sALLOW_MEMORY_GROWTH=1` on Emscripten. + BLAKE3's own test program runs in the library's own lane `c-suites`, beside libsodium's and XKCP's + suites. - **Tests:** RFC 5869, 6070, 7914 and 9106 vectors, Keccak-256's and BLAKE3's official vectors, cross-backend agreement natively (all backends, random inputs) and on WebAssembly (hash2 against sodium and bearssl), WebCrypto as an outside oracle on Emscripten under node, the C libraries' own suites, a test per message, a counting allocation test, every lane (native, wasip2, wasip3, emscripten, gcc-15; MSVC and Apple clang in the CI at the end), exceptions on and off. -- **Measurements:** the measured table (program size per target, throughput natively), and - PBKDF2-HMAC-SHA-512 at 1,000,000 iterations for hash2, OpenSSL and libsodium. +- **Measurements:** the measured table (program size per target, throughput natively), kept as + a reference dated 2026-11-16 that decides nothing, and PBKDF2-HMAC-SHA-512 at 1,000,000 + iterations for hash2, OpenSSL and libsodium. - **Seven increments, the highest value first** (spec 1.5): 1, the above; 2, libsodium's whole hashing surface (BLAKE2b with key, salt, personalisation and length; SipHash-2-4 and -2-4x; `crypto_kdf` subkeys; Argon2i; SHAKE and TurboSHAKE; its SHA-2, SHA-3 and HMACs); 3, XKCP's @@ -81,13 +89,12 @@ every local lane; it is not yet published, and the spec records what building it says which backend provides each function, and every refusal names the backends that have it. From increment 2, `digest`, `hasher`, `mac` and the KDF functions reach every backend; Hash2's form stays for Hash2's types, `keccak_256` and `blake3`. -- **One profile changes every default backend,** for hash alone or, through webcpp's umbrella - `WEBCPP_PROFILE_FASTEST`/`_SMALLEST`/`_PORTABLE`, for every library (crypto by a later change): - none (`auto`: fastest natively, smallest on - WebAssembly), `WEBCPP_HASH_PROFILE_FASTEST`, `_SMALLEST`, `_PORTABLE` or `_BACKEND_`, - plus per-algorithm overrides `WEBCPP_HASH_DEFAULT_BACKEND__` (precedence: override, - library profile, umbrella profile, measured default); the defaults come from - the build and a committed table of webcpp's own measurements, regenerated at every pin move. +- **No profile and no override** (retired on 2026-11-16, design D33): increment 1 built one + profile per program (`WEBCPP_HASH_PROFILE_*` and webcpp's umbrella `WEBCPP_PROFILE_*`) and + per-algorithm overrides `WEBCPP_HASH_DEFAULT_BACKEND__`; with the backend named + in the type, a define that changed what `hkdf` means across a program would make BearSSL + or OpenSSL a default again and hide the backend from the call's reader, so a former define has + no effect. - **The browser backend through a parallel asynchronous API** (the owner's answer to O1): `async_digest`, `async_hmac`, `async_hkdf` and `async_pbkdf2` take a webcpp::asio completion token (callback, coroutine in Asio or Cobalt, future); on Emscripten they default to @@ -104,8 +111,8 @@ every local lane; it is not yet published, and the spec records what building it ### New Capabilities - `hash`: webcpp::hash, Boost.Hash2's algorithms and HMAC by alias, Keccak-256 and BLAKE3 in - Hash2's form, HKDF and PBKDF2 over backends with a measured default, Argon2id and scrypt, every - backend's further hashing and KDF functions in increments, the configuration profile, the + Hash2's form, HKDF and PBKDF2 over backends with `backends::hash2` as the default, Argon2id and + scrypt, every backend's further hashing and KDF functions in increments, the browser backend's asynchronous family, with their interface, error values, backends, build, messages, allocation rules, tests, measurements and documentation. @@ -123,17 +130,18 @@ None. submodule `libs/hash` (gate G2), BSL-1.0, "Copyright (c) 2026 WebCpp.org". - **Implementation:** increment 1 (the plan's Tasks 0 to 24) is built: the library's repository (branch `main`, not yet on GitHub) and the superproject's integration branch hold it, green on - native, wasip2, wasip3, Emscripten and gcc-15 locally; MSVC and Apple clang wait for the CI - after the owner's gates. Increments 2 to 7 are not started. **The reference code - is the code written in the tasks of `reference/plan.md`:** Task 1 (`build.jam`, `config.hpp`, - the test Jamfile's `hash-run`), Task 2 (`error.hpp`), Task 3 (`algorithms.hpp`, `hmac.hpp`), - Task 4 (the XKCP target, `xkcp_adapter.c`, `canary.h`, `canary_xkcp.c`), Task 5 - (`keccak.hpp`), Tasks 6 and 7 (the BLAKE3 target, `blake3.hpp`), Task 8 (the libsodium target), - Task 9 (`kdf.hpp`, `hkdf.hpp`, `detail/engines.hpp`, `backends/hash2.hpp`), Task 10 - (`pbkdf2.hpp`), Tasks 11 to 13 (`backends/sodium.hpp`, `backends/openssl.hpp`, - `backends/bearssl.hpp`), Task 15 (`argon2.hpp`), Task 16 (`scrypt.hpp`) and Task 21 - (`tools/hash/measure.py`), and the tasks of increments 2 to 7 (Tasks 25 to 47), with the tests - and Jamfiles the other tasks give. + native, wasip2, wasip3, Emscripten and gcc-15 locally; MSVC and Apple clang wait for the CI after + the owner's gates. Increments 2 to 7 are not started. **The reference code is the code written in + the tasks of `reference/plan.md`:** Task 1 (`build.jam`, `config.hpp`, the test Jamfile's + `hash-run`), Task 2 (`error.hpp`), Task 3 (`algorithms.hpp`, `hmac.hpp`), Task 4 (the XKCP target, + `xkcp_adapter.c`, `canary.h`, `canary_xkcp.c`), Task 5 (`keccak.hpp`), Tasks 6 and 7 (the BLAKE3 + target, `blake3.hpp`), Task 8 (the libsodium target), Task 9 (`kdf.hpp`, `hkdf.hpp`, + `detail/engines.hpp`, `backends/hash2.hpp`), Task 10 (`pbkdf2.hpp`), Tasks 11 to 13 + (`backends/sodium.hpp`, `backends/openssl.hpp`, `backends/bearssl.hpp`), Task 15 (`argon2.hpp`), + Task 16 (`scrypt.hpp`) and Task 21 (`tools/hash/measure.py`, deleted by design D33), and the tasks + of increments 2 to 7 (Tasks 25 to 47), with the tests and Jamfiles the other tasks give. What + Tasks 14 and 21 built for the profiles, the overrides, the ranking and the lane `measure` is + retired by design D33 (task 1.26). `reference/spec.md` is the full specification and `reference/STATUS.md` says where things stand and how to start. - **Dependencies:** Boost 1.92 (Hash2, System, Core's `lightweight_test`, JSON in tests); @@ -149,7 +157,8 @@ None. (replacing its spec 1.2's "written on Hash2's hmac when needed"), its libsodium backend (version 0.2) uses `/third_party//sodium` as built here, and `/third_party//bearssl`, which its plan adds, gains webcpp::hash's canary here (the BearSSL task waits for that target on `main`). - A later change of webcpp::crypto takes the same profile idea for its own defaults, and + webcpp::hash reads no profile, webcpp's umbrella `WEBCPP_PROFILE_*` included (design D33); + whether webcpp::crypto takes a profile for its own defaults is that library's own later change. webcpp::crypto's Botan provisioning (its increment 5) is what increment 6 waits for. `libraries/asio` supplies the completion-token model and `browser::async_await` the asynchronous family uses. `organization` carries the rulebook this plan extends (chapter 10's diff --git a/libraries/hash/openspec/changes/genesis/reference/STATUS.md b/libraries/hash/openspec/changes/genesis/reference/STATUS.md index 79e8e65..ad130f2 100644 --- a/libraries/hash/openspec/changes/genesis/reference/STATUS.md +++ b/libraries/hash/openspec/changes/genesis/reference/STATUS.md @@ -1,14 +1,18 @@ # webcpp::hash: where the implementation stands, and how to start -Written 2026-11-14, when this proposal was made, and brought up to date on 2026-11-15, when -increment 1 was built. The owner decided the library's shape on 2026-11-14, widened it the same -day (every backend's whole hashing and KDF surface, in increments; one profile for every default -backend; documentation in noble's and libsodium's manner) and answered O1 (the browser backend -through a parallel asynchronous family), and accepted it. `spec.md` is the -specification, `plan.md` the implementation plan of 48 tasks (0 to 47) in seven increments, -`../tasks.md` the checklist. **The reference code is the code written in the plan's tasks** -(listed in `../proposal.md`, "Implementation"). There is no `source/` directory: increment 1's -code is in the library's own repository, which the owner publishes at gate G1. +Written 2026-11-14, when this proposal was made, brought up to date on 2026-11-15, when increment 1 +was built, and on 2026-11-16, when the owner fixed the default backends (design D33). The owner +decided the library's shape on 2026-11-14, widened it the same day (every backend's whole hashing +and KDF surface, in increments; one profile for every default backend, retired on 2026-11-16; +documentation in noble's and libsodium's manner) and answered O1 (the browser backend through a +parallel asynchronous family), and accepted it. On 2026-11-16 he decided that every key derivation +defaults to `backends::hash2` on every target and link set, and `argon2id` and `scrypt` to +`backends::sodium`, which retires the profiles, the overrides, the measured ranking and the lane +`measure` (design D33). `spec.md` is the specification, `plan.md` the implementation plan of 48 +tasks (0 to 47) in seven increments, `../tasks.md` the checklist. **The reference code is the code +written in the plan's tasks** (listed in `../proposal.md`, "Implementation"). There is no `source/` +directory: increment 1's code is in the library's own repository, which the owner publishes at gate +G1. ## Where it stands @@ -20,9 +24,9 @@ code is in the library's own repository, which the owner publishes at gate G1. - **Green locally, from scratch:** native, wasip2, wasip3, Emscripten and gcc-15 (the library's tests and examples, each with its `_no_exceptions` twin), the own lanes `c-suites` (XKCP's, BLAKE3's and libsodium's own suites, 105 programs on every target) and `measure` (284 cells on - four targets), the tools' tests, the documentation's build and the lint (`lint: clean`); an - amd64 lane in the CI's image under emulation. MSVC and Apple clang run only in the CI, after the - gates (their cases are written). + four targets, retired since by design D33), the tools' tests, the documentation's build and the + lint (`lint: clean`); an amd64 lane in the CI's image under emulation. MSVC and Apple clang run + only in the CI, after the gates (their cases are written). - **The spec and the design are amended** to what increment 1 built (design D25 to D32): the public tags `kdfs::hkdf_extract` and `kdfs::hkdf_expand` and a default backend per operation; `detail::backend_limits`, with OpenSSL refusing past `INT_MAX`; libsodium's @@ -30,8 +34,16 @@ code is in the library's own repository, which the owner publishes at gate G1. behind `kdf.hpp`; BLAKE3's own program in the lane `c-suites` instead of `tools/test/blake3_c_suite.py`; `[[nodiscard]]` on every result; two comparison tables a chapter; the native orders provisional. -- **The measurements are provisional.** They were made on one loaded macOS arm64 machine - (`loaded: true`); the native HKDF order rests on medians under 1 percent apart (design D32). +- **The default backends are fixed (design D33, 2026-11-16), and built** (`../tasks.md` 1.26) on + the branches `hash/defaults-hash2` of the library and of the superproject: `default_backend` + answers `backends::hash2` (`backends::sodium` for `argon2id` and `scrypt`); the profiles, the + umbrella's reading, the overrides with `detail/overrides.hpp`, `detail/ranking.hpp`, their + `detect_mismatch`, tests and messages, the lane `measure` and `tools/hash/measure.py` are + removed; `tools/hash/doc_tables.py` renders `doc/backends.adoc` and the dated + `doc/measurements.adoc`. +- **The measurements are a dated reference.** `doc/measurements.*` stay, labelled as measured on + 2026-11-16, and decide nothing; no re-measurement is due before a release (design D32 is + superseded). - **The pins** are those read on 2026-11-14: libsodium 1.0.22 (`77e1ce5d6dee871c49ef211222ba18ef0c486bda`, tag `1.0.22-RELEASE`), XKCP `master` (`d20c8fcaecc543f816a0721d0dfc13b4cf27c14d`, 2026-11-10; XKCP has no release tags), BLAKE3 @@ -51,8 +63,7 @@ code is in the library's own repository, which the owner publishes at gate G1. push, no pull request and no CI run by an agent; all evidence is local until the owner asks. - **webcpp::crypto's version 0.1 on `main`**, which increment 1 is built on (`/third_party//bearssl`, `webcpp.same-program`). -- **A measurement on an idle machine** before a release (design D32), and the owner's answer to - O2 (one native order, or one per platform). +- **The owner's merge of the branches `hash/defaults-hash2`** (task 1.26, design D33). - **webcpp::crypto's Botan provisioning** (its increment 5) for increment 6. - **webcpp::asio's `browser::async_await`** on `main` for increment 7. @@ -62,9 +73,9 @@ Prerequisites are the superproject's (its `AGENTS.md`, chapter 1): Boost 1.92, b compiler, wasi-sdk 34, wasmtime, Emscripten 6.0.11 with node 26.7.0, Python 3.9 or newer, `.local/user-config.jam`. -1. **Increment 1** is done (Tasks 0 to 24); what remains of it is the owner's: the gates G1, - G2 and G4, then the CI's MSVC and Apple clang lanes, and the re-measurement of design D32 before - a release. +1. **Increment 1** is done (Tasks 0 to 24, and task 1.26 of design D33 on the branches + `hash/defaults-hash2`); what remains of it is the owner's: the gates G1, G2 and G4, then the + CI's MSVC and Apple clang lanes. 2. **Increment 2 starts with Task 25** (the families), from the library's `main` and the superproject's integration branch; it waits for nothing else. 3. **Increments 3 to 7** after Task 25, in parallel streams by backend, as `plan.md`'s table of @@ -78,15 +89,17 @@ lanes and their commands are in `plan.md`'s "Global Constraints". 1. The library's `main` builds and passes from scratch on the native lane: `$B2 -a libs/hash/test libs/hash/example`, every test and its `_no_exceptions` twin. -2. The lane `measure` agrees with the committed table on its four targets, or, on another native - toolchain, prints that it skips the native order comparison (design D32). +2. `default_backend_test` and `default_backend_former_defines` show `backends::hash2` for every + key derivation (`backends::sodium` for `argon2id` and `scrypt`) on the four targets with every + library linked, and no `WEBCPP_HASH_PROFILE_*`, `WEBCPP_PROFILE_*` or + `WEBCPP_HASH_DEFAULT_BACKEND_*` is read by `include/` (design D33). 3. The rulebook and the lint: `lint: clean`, with `libs/hash/meta/lint.json`'s "nodiscard results" rule (design D30). ## Decisions pending -- **O2** (design, Open Questions): whether one native throughput order, measured on macOS - arm64, serves Linux and Windows, or each platform gets its own; and the re-measurement on an - idle machine before a release (design D32). +- **O3** (design, Open Questions): the default of the families of increments 2 to 7 for an + algorithm Boost.Hash2 lacks, before increment 2's first task. -O1 is decided (design D23). The owner's gates are actions, not decisions. +O1 is decided (design D23). O2 is closed by design D33: no measured order decides a default. +The owner's gates are actions, not decisions. diff --git a/libraries/hash/openspec/changes/genesis/reference/plan.md b/libraries/hash/openspec/changes/genesis/reference/plan.md index 37d0d36..04b336b 100644 --- a/libraries/hash/openspec/changes/genesis/reference/plan.md +++ b/libraries/hash/openspec/changes/genesis/reference/plan.md @@ -9,10 +9,23 @@ created: 2026-11-14 > **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. +> **Amended on 2026-11-16 (design D33).** The owner decided that every key derivation defaults to +> `backends::hash2` on every target and link set, and `argon2id` and `scrypt` to `backends::sodium`; +> BearSSL, OpenSSL and libsodium's HKDF are reached only by naming them in the type. The profiles, +> hash's reading of webcpp's umbrella profile, the per-algorithm overrides with +> `detail/overrides.hpp`, `detail/ranking.hpp`, MSVC's `detect_mismatch` of the profile and of the +> overrides, and the own lane `measure` (`tools/hash/measure.py --check`, the CI matrix entry "Own +> lane (hash, measure)", `test/measure`) are retired, with `tools/hash/measure.py` whole and its +> test; `doc/measurements.*` stay as a reference dated 2026-11-16 that decides nothing, rendered and +> checked by `tools/hash/doc_tables.py`. Increment 1's tasks that built them (9, 14, 21, 22, 24) +> keep their steps as written, the record of what was built, with a note at their head; the Global +> Constraints, the Review Focus and the tasks of increments 2 to 7 are amended. The retirement +> itself is `../tasks.md` 1.26. + **Goal:** a new library, webcpp::hash, at `libs/hash`, in seven increments (spec 1.5). Increment 1: Boost.Hash2 1.92's algorithms and HMAC by alias; `keccak_256` over XKCP's Keccak-p[1600] and `blake3` over BLAKE3's C implementation, both in Hash2's HashAlgorithm form; HKDF and PBKDF2 over four backends (`backends::hash2`, `sodium`, -`bearssl`, `openssl`) with the owner's default rule and its measured size table; Argon2id and +`bearssl`, `openssl`) with `backends::hash2` as the default (design D33); Argon2id and scrypt from libsodium; on native, wasip2, wasip3 and Emscripten, every test with exceptions on and off; and the PBKDF2-HMAC-SHA-512 throughput measured. Increments 2 to 6: every further hashing and KDF function of libsodium, XKCP, OpenSSL, BearSSL and Botan 3, through the families of spec 2.15. @@ -24,8 +37,8 @@ Increment 7: the browser backend through the parallel asynchronous family (spec specialises only the engines of `webcpp::hash::detail` (`hkdf_engine`, `pbkdf2_engine`, `argon2id_engine`, `scrypt_engine`), whose primary templates and refusing specialisations hold the `static_assert`s of spec 3.3. The - default backend is `default_kdf_backend` (spec 4), from the `HAS` defines and the - generated `detail/ranking.hpp`, under the profile and the overrides of spec 4.1. + default backend is `default_kdf_backend` (spec 4.1): `backends::hash2` for every key + derivation, `backends::sodium` for `argon2id` and `scrypt` (design D33). - **The C libraries** are submodules under `third_party/libs/` (`xkcp`, `blake3`, `libsodium`; BearSSL is webcpp::crypto's), built file by file by `third_party/Jamfile` into static libraries whose usage requirements give `WEBCPP_HASH_HAS_=1`; webcpp::hash's @@ -33,7 +46,8 @@ Increment 7: the browser backend through the parallel asynchronous family (spec `src/xkcp/config.h`. OpenSSL is the superproject's provider, through hash's alias `/webcpp/hash//openssl`. - **The superproject** gains: three submodules and their targets; the test-data target - `/third_party//blake3_vectors`; `tools/hash/measure.py` and the own lane `measure`; + `/third_party//blake3_vectors`; `tools/hash/measure.py` and the own lane `measure` (both + retired by design D33); `tools/test/hash_jamfiles_test.py` and its fixtures; CODING-GUIDELINES.md chapter 10's three rows and chapter 17's entry. BLAKE3's own test program runs in the library's own lane `c-suites` (Task 6, Step 5; design D29). @@ -158,9 +172,9 @@ favour of the real one. - gcc: `$B2 -a --build-dir=bin/lane-gcc toolset=gcc-15 libs/hash/test libs/hash/example`; - MSVC and Apple clang in the CI only, at the end (G4); - the own lane `c-suites` on target ``: the target's command with - `libs/hash/test/c_suites//c-suites` in place of the two directories; the own lane `measure`: - `$B2 -a --build-dir=bin/lane-measure libs/hash/test/measure//measure` (it builds for the four - targets itself, Task 21); + `libs/hash/test/c_suites//c-suites` in place of the two directories (the own lane `measure`, + `$B2 -a --build-dir=bin/lane-measure libs/hash/test/measure//measure`, Task 21's, is retired + on 2026-11-16 by design D33); - the user's Jamfiles: `python3 tools/test/hash_jamfiles_test.py`. - The lint: `tools/lint/lint.sh --clang-format .local/wasi-sdk/bin/clang-format --clang-tidy .local/wasi-sdk/bin/clang-tidy`, ending `lint: clean`. @@ -224,8 +238,8 @@ favour of the real one. | `WEBCPP_HASH_DETAIL_TEST_OPENSSL_DIGEST` | the seam that replaces OpenSSL's digest name, to provoke a backend failure (Task 12) | | `WEBCPP_HASH_DETAIL_TEST_WIPE_RECORD` | the seam through which `detail::wipe` reports each wipe to a test (Task 9) | | `tools/test/hash_jamfiles_test.py`, `tools/test/fixtures/hash_jamfiles//` | the user's Jamfiles and the build's stops (Task 19) | -| `tools/hash/measure.py` | the measured table and `detail/ranking.hpp` (Task 21) | -| own lanes `c-suites`, `measure` | `libs/hash/test/c_suites`, `libs/hash/test/measure` | +| `tools/hash/measure.py` | the measured table and `detail/ranking.hpp` (Task 21); deleted by design D33, `tools/hash/doc_tables.py` renders the reference of 2026-11-16 | +| own lane `c-suites` | `libs/hash/test/c_suites` (the lane `measure`, `libs/hash/test/measure`, retired by design D33) | | `.superpowers/sdd/WEBCPP_HASH_PLAN/progress.md` | the ledger, in the worktree, untracked | ## Review Focus @@ -244,9 +258,10 @@ favour of the real one. call it is about, and only there: including a backend's header or naming `backends::bearssl` as a type is not an error; calling `hkdf_expand` on it is. Tasks 9, 13 and 14 test it. -4. **The default backend on WebAssembly is per KDF.** `default_kdf_backend` must never be `backends::sodium` or `backends::bearssl`, whatever the measured - order or the profile says. Task 14 tests it on each target with every library linked. +4. **The default backend is `backends::hash2`.** `default_kdf_backend` is + `backends::hash2` for every hmac and every key derivation, on each target with every library + linked, and a former profile or override define changes nothing (design D33; until 2026-11-16 + this item was the measured default per KDF). Task 14's test, as task 1.26 rewrites it. 5. **Secrets left behind.** HKDF's T blocks, PBKDF2's U values and accumulator, the keyed hmac copies and BearSSL's context are wiped on success and on failure; a backend's failure zeroes the output; a guard's refusal leaves it untouched. Tasks 9, 10 and 13 test it. @@ -255,11 +270,12 @@ favour of the real one. 7. **One copy per program.** A program naming `/webcpp/hash//openssl` and `/webcpp/crypto//openssl` links each OpenSSL archive once; `/third_party//bearssl` with both canaries is one archive. Tasks 12 and 13. -8. **A lane or a check that passes having built nothing.** Every own lane names its targets; a - measure program that a target skips is a failure of the `measure` lane, not a missing row. Tasks 4, - 6, 8 and 21. -9. **Generated files.** `detail/ranking.hpp` and `doc/measurements.*` are written only by - `tools/hash/measure.py`; the `measure` lane fails on a hand edit. Task 21. +8. **A lane or a check that passes having built nothing.** Every own lane names its targets. + Tasks 4, 6 and 8 (and Task 21's lane `measure` until design D33 retired it). +9. **Generated files.** Until 2026-11-16 `detail/ranking.hpp` and `doc/measurements.*` were + written only by `tools/hash/measure.py`, checked by the lane `measure`; design D33 retired the + ranking, the lane and the tool, and `doc/measurements.*` stay as a reference dated 2026-11-16 + whose digest `tools/hash/doc_tables.py --check` checks at every documentation build. 10. **The asynchronous family completes, never inline.** A completion handler must not run inside the initiating call on any target, and an operation keeps the caller's spans until it completes or is cancelled (then `output` is zeroed). Task 46 tests it. @@ -1436,6 +1452,9 @@ for local name in $(.sodium-tests) ## Task 9: The key derivations' layer, and HKDF on `backends::hash2` +> **Note of 2026-11-16 (design D33).** The provisional `detail/ranking.hpp` and the rule it +> encoded are retired: `default_kdf_backend` answers `backends::hash2` (`../tasks.md` 1.26). + **Files:** - Create (library): `test/messages/Jamfile` (a temporary copy until Task 5's merges), `test/messages/kdf_not_digest/`, `include/webcpp/hash/kdf.hpp`, `include/webcpp/hash/hkdf.hpp`, @@ -1892,6 +1911,17 @@ struct hkdf_engine { ## Task 14: The profile, the overrides and the default backend +> **Note of 2026-11-16 (design D33).** Built as written, then retired: the profiles, the umbrella's +> reading, the overrides, their `detect_mismatch`, `overrides_list_test`, the profiles' tests +> (`default_fastest_test`, `default_smallest_test`, `default_portable_test`, `default_named_test`, +> `default_override_test`, `default_umbrella_test`) and the messages `two_profiles`, +> `two_umbrella_profiles`, `two_overrides` and `override_cannot_serve`, with Task 19's fixture of +> OpenSSL's profile on Emscripten and the MSVC cases of the profile and the overrides. +> `default_backend`, `default_kdf_backend`, the public tags, `doc/capabilities.json` and +> `capabilities_test` stay; +> `default_backend_test` checks `backends::hash2` everywhere and that a former define has no +> effect (`../tasks.md` 1.26). + **Files:** - Modify (library): `include/webcpp/hash/config.hpp` (the profile and override defines, their refusals, `detect_mismatch`), `include/webcpp/hash/kdf.hpp` (`default_backend`, @@ -2079,6 +2109,12 @@ template struct override_choice; // void without ## Task 21: The measured table +> **Note of 2026-11-16 (design D33).** Built as written, then retired: `detail/ranking.hpp`, the +> own lane `measure` (`test/measure/`, `measure.py --check`, the CI matrix entry "Own lane (hash, +> measure)"), `measure.py` whole and `hash_measure_test.py`. `doc/measurements.json` and +> `doc/measurements.adoc` stay, labelled as a reference measured on 2026-11-16 that decides +> nothing, rendered and checked by `tools/hash/doc_tables.py` (`../tasks.md` 1.26). + **Files:** - Create (superproject): `tools/hash/measure.py`, `tools/test/hash_measure_test.py`. - Create (library): `test/measure/Jamfile`, `test/measure/_.cpp` (one per @@ -2103,6 +2139,10 @@ template struct override_choice; // void without ## Task 22: PBKDF2-HMAC-SHA-512 at 1,000,000 iterations +> **Note of 2026-11-16 (design D33).** The benchmark leaves the retired lane `measure`: its +> correctness program `pbkdf2_sha512_key` runs in every lane of `libs/hash/test`, its times are +> measured by hand with `bench/collect.py`, and `doc/performance.adoc` decides no default. + **Files:** - Create (library): `bench/Jamfile`, `bench/pbkdf2_sha512.cpp`, `doc/performance.adoc`. @@ -2121,7 +2161,9 @@ template struct override_choice; // void without **Files:** - Create (library): `doc/` parts (one per header and per algorithm, in noble's README's manner: what it is, an example, its pitfalls), `doc/backends.adoc` (the capability table rendered from - `doc/capabilities.json` by `tools/hash/measure.py --capabilities`), `doc/profile.adoc`, + `doc/capabilities.json` by `tools/hash/doc_tables.py`, since design D33; first by + `tools/hash/measure.py --capabilities`), `doc/profile.adoc` (`doc/choosing_backend.adoc` since + design D33), `doc/departures.adoc`, `doc/use-cases/{p2p,cryptocurrencies,privacy}.adoc`, `doc/upstream.adoc`, `NOTICE.md`, `example/*.cpp` (each section's example) and its Jamfile. @@ -2144,6 +2186,9 @@ template struct override_choice; // void without ## Task 24: Increment 1 whole +> **Note of 2026-11-16 (design D33).** The own lane `measure` of Step 2 is retired; the lanes are +> the others. + - [ ] **Step 1: The rulebook and the lint.** CODING-GUIDELINES.md chapter 10's rows (Tasks 4, 6, 8, 13) are in; chapter 17's entry describes increment 1 as built; chapter 5's rule 2 records its three exceptions: BLAKE3's intrinsics files on their instruction sets alone, XKCP built from the @@ -2172,7 +2217,7 @@ Each increment's first task reads its backend at the pin and corrects its column never assumed. Each function follows increment 1's pattern: the official vectors first and seen failing, the engine, every target the backend has, exceptions on and off, agreement with every other backend that has the function (Task 17's tests gain each pair), the WebCrypto oracle where -WebCrypto has it (Task 18's test gains it), the measured table regenerated (Task 21's lane), the +WebCrypto has it (Task 18's test gains it), the capability table and the documentation's section (noble's manner: what it is, an example, its pitfalls), the changelog line. @@ -2186,11 +2231,13 @@ Stream `sodium-2`, first; every later increment builds on it. `include/webcpp/hash/argon2.hpp` gains `argon2_parameters` and `argon2`; `include/webcpp/hash/detail/engines.hpp` gains `digest_engine`, `mac_engine`, `argon2_engine`, each primary template refusing - with the text generated from `doc/capabilities.json` (the backends of its row); + with the text of its row of `doc/capabilities.json` (the backends that have it), written by + hand and checked by `capabilities_test` against that file; `test/families_test.cpp`, `test/hasher_state_test.cpp`. - Modify (library): `error.hpp` (value 9, `invalid_state`, "the hasher was finished or moved from"), `kdf.hpp` (`default_backend` over every tag), `doc/capabilities.json`, - `tools/hash/measure.py --refusals` (superproject) to generate the refusal texts. + the refusal texts written and checked by `capabilities_test` against it (no generator: + `tools/hash/measure.py` is deleted by design D33). **Interfaces:** - Produces: spec 2.15; `hasher` is move-only, wipes its context in its destructor and on move, @@ -2374,8 +2421,7 @@ Stream `openssl-4`; native, wasip2 and wasip3. ## Task 38: Increment 4 whole -- [ ] Task 47 for increment 4: the agreement tests gain every OpenSSL pair; the measured table - gains its rows. Commit (library) `"hash: increment 4 whole"`. +- [ ] Task 47 for increment 4: the agreement tests gain every OpenSSL pair. Commit (library) `"hash: increment 4 whole"`. ## Task 39: BearSSL's hashes, HMAC and SHAKE @@ -2391,8 +2437,8 @@ Stream `bearssl-5`. ## Task 40: Increment 5 whole -- [ ] Task 47 for increment 5: the `smallest` profile's choices on WebAssembly re-read from the - regenerated table and reported in the ledger. Commit (library) `"hash: increment 5 whole"`. +- [ ] Task 47 for increment 5: BearSSL's functions reached by naming `backends::bearssl` in the + type, never a default (design D33). Commit (library) `"hash: increment 5 whole"`. ## Task 41: Botan's column, at its pin @@ -2496,10 +2542,11 @@ Stream `async-7`. ## Task 47: An increment whole (run once per increment 2 to 7) -- [ ] **Step 1:** `doc/capabilities.json` and `capabilities_test` agree; the refusal texts are - regenerated (`python3 tools/hash/measure.py --refusals --check`). -- [ ] **Step 2:** the measured table regenerated (`python3 tools/hash/measure.py --write`), the - throughput re-measured natively, the `measure` lane green. +- [ ] **Step 1:** `doc/capabilities.json` and `capabilities_test` agree, its defaults included; + the refusal texts are checked by `capabilities_test` against it, and `doc/backends.adoc` is + rendered by `tools/hash/doc_tables.py`. +- [ ] **Step 2:** every new algorithm's default is the one design O3's answer gives, named + beside `doc/capabilities.json`, and no measurement decides it (design D33). - [ ] **Step 3:** every lane from scratch, the own lanes, the tools' tests, the lint, as Task 24's Step 2; a review by someone who did not write the increment. - [ ] **Step 4:** the documentation's sections of the increment (noble's manner; libsodium's diff --git a/libraries/hash/openspec/changes/genesis/reference/spec.md b/libraries/hash/openspec/changes/genesis/reference/spec.md index 9fb6be2..00aebc3 100644 --- a/libraries/hash/openspec/changes/genesis/reference/spec.md +++ b/libraries/hash/openspec/changes/genesis/reference/spec.md @@ -74,7 +74,7 @@ this library on 2026-11-14, both constructions over an audited primitive, never `detail::keccak_base<0x01, 512, 256>` is an oracle in a test on random call sequences; the type becomes an alias of Boost.Hash2's public `keccak_256` once Boost publishes one (spec 9.1). -### 1.4 The owner's decisions, as recorded on 2026-11-14 +### 1.4 The owner's decisions, as recorded on 2026-11-14 and 2026-11-16 - "A new library, webcpp::hash, proposed by the owner: one entry point for hashing and key derivation." Boost.Hash2's algorithms and hmac re-exported by alias, no wrapper; Keccak-256 @@ -105,6 +105,18 @@ this library on 2026-11-14, both constructions over an audited primitive, never (section 11), and WebCrypto as an oracle of every algorithm it has stays in any case; the documentation follows noble's README (one short section per algorithm: what it is, an example, its pitfalls) and libsodium's documentation (ISC, adapted with attribution), with teaching chapters by use case. +- The defaults of 2026-11-16 (design D33), which replace the "Default backend rule" and the + profile of the widening above: the default backend of every key derivation (`hkdf`, + `hkdf_extract`, `hkdf_expand`, `pbkdf2`), on every target and whatever the program links, is + `backends::hash2`; `backends::sodium` is the default only for what hash2 does not offer, + Argon2id and scrypt, of which it is the only backend. `backends::bearssl`, `backends::openssl` + and libsodium's HKDF stay, tested as before, as explicit choices named in the type, never a + default. Every profile, hash's reading of webcpp's umbrella profile, the per-algorithm + overrides, `detail/ranking.hpp` and the lane `measure` are retired; the measured table stays as + a reference dated 2026-11-16 that decides nothing. Why hash2: it is the only backend covering + every hmac, operation and target; it is header-only, so a program carries only what it calls + and shares the SHA code it already uses; and the measured differences for HKDF are nanoseconds + natively and a few KB isolated on WebAssembly. ### 1.5 The increments @@ -113,7 +125,7 @@ grouped by them and, inside each, into streams by backend (plan, "The order of t | Increment | What it adds | Backends | Why this rank | | --- | --- | --- | --- | -| 1 | Hash2 by alias; `keccak_256`; `blake3`; HKDF, PBKDF2; Argon2id, scrypt; the profile and the measured table; the oracle | hash2, xkcp, blake3, sodium, bearssl, openssl | what Ethereum, Bitcoin (BIP39), Nostr and every key hierarchy need now | +| 1 | Hash2 by alias; `keccak_256`; `blake3`; HKDF, PBKDF2; Argon2id, scrypt; the default backend and the measured table, a dated reference (section 4); the oracle | hash2, xkcp, blake3, sodium, bearssl, openssl | what Ethereum, Bitcoin (BIP39), Nostr and every key hierarchy need now | | 2 | libsodium's whole hashing surface: generic hashing (BLAKE2b with key, salt, personalisation and variable length), short hashing (SipHash-2-4, SipHash-2-4x), subkey derivation (`crypto_kdf`, BLAKE2b), Argon2i, the XOFs (SHAKE128/256, TurboSHAKE128/256), SHA-256, SHA-512, SHA3-256, SHA3-512 and HMAC-SHA-256/512/512-256 as digests | sodium | Zcash-family and WireGuard-style formats, hash tables under attack, libsodium interoperability; one library already linked | | 3 | XKCP's Keccak family: Keccak-224/384/512, SHA-3 and SHAKE as XKCP computes them, cSHAKE, KMAC (and its XOF), TupleHash, ParallelHash (SP 800-185), KangarooTwelve (KT128, KT256), TurboSHAKE128/256 | xkcp | the Keccak team's reference for everything above Keccak-p; one library already linked | | 4 | OpenSSL's whole hashing and KDF surface: every EVP digest of the default provider (SHA-1/2/3, SHAKE, KECCAK-224 to -512, SM3, BLAKE2b-512, BLAKE2s-256, RIPEMD-160, MD5), KMAC, BLAKE2 MACs, scrypt, Argon2d/i/id with every RFC 9106 parameter (lanes, secret, associated data), KBKDF (SP 800-108), SSKDF (SP 800-56C), X9.63 KDF | openssl | full Argon2 on servers; KDFs of standards (ECIES, TLS-adjacent formats); native, wasip2, wasip3 | @@ -170,14 +182,6 @@ opts the library into the lint's rule "nodiscard results" with that reason (desi #undef WEBCPP_HASH_HAS_BEARSSL #define WEBCPP_HASH_HAS_OPENSSL 1 #undef WEBCPP_HASH_HAS_OPENSSL -#define WEBCPP_HASH_PROFILE_FASTEST -#undef WEBCPP_HASH_PROFILE_FASTEST -#define WEBCPP_HASH_PROFILE_SMALLEST -#undef WEBCPP_HASH_PROFILE_SMALLEST -#define WEBCPP_HASH_PROFILE_PORTABLE -#undef WEBCPP_HASH_PROFILE_PORTABLE -// ... and WEBCPP_HASH_PROFILE_BACKEND_, WEBCPP_HASH_DEFAULT_BACKEND__ and -// webcpp's umbrella WEBCPP_PROFILE_FASTEST, _SMALLEST, _PORTABLE (spec 4.1) #endif #if !defined(WEBCPP_HAS_EXCEPTIONS) && !defined(WEBCPP_HASH_NO_EXCEPTIONS) @@ -194,13 +198,7 @@ opts the library into the lint's rule "nodiscard results" with that reason (desi #if defined(WEBCPP_TARGET_EMSCRIPTEN) && defined(WEBCPP_HASH_HAS_OPENSSL) #error "webcpp::hash: OpenSSL is not built for Emscripten. In the program's Jamfile, remove /webcpp/hash//openssl: hkdf and pbkdf2 then run on backends::hash2." #endif -#if defined(WEBCPP_TARGET_EMSCRIPTEN) && defined(WEBCPP_HASH_PROFILE_BACKEND_OPENSSL) -#error "webcpp::hash: WEBCPP_HASH_PROFILE_BACKEND_OPENSSL selects OpenSSL, which is not built for Emscripten. Remove that define." -#endif -// The profile's refusals (spec 4.1): more than one profile of one level, OpenSSL selected on -// Emscripten by the profile. The overrides' refusals (two overrides of one algorithm, an OpenSSL -// override on Emscripten) are not here: they are in detail/overrides.hpp, which kdf.hpp includes -// (spec 4.1, design D28). +// No profile and no override define is read (spec 4.1, design D33). // clang-format on namespace webcpp::hash::backends { @@ -218,7 +216,7 @@ struct openssl; namespace webcpp::hash::kdfs { -/** HKDF, RFC 5869: the operation `hkdf`; its override applies to both steps too. */ +/** HKDF, RFC 5869: the operation `hkdf`. */ struct hkdf; /** HKDF-Extract alone, the operation `hkdf_extract` (RFC 5869, section 2.2). */ struct hkdf_extract; @@ -571,10 +569,9 @@ inline constexpr bool backend_has_v = /* the table of spec 3.2 */; /** The backend `hkdf_extract`, `hkdf_expand`, `hkdf` and `pbkdf2` use when the program names none: - the override's backend, else the profile's choice among the linked backends that have the - operation `Kdf` over `Hmac`, from the measured table (spec 4.1, 4.2); `default_backend`. - Chosen per operation, so that `kdfs::hkdf_extract` and `kdfs::hkdf_expand` never name a backend - that has HKDF only whole (design D25). + `backends::hash2`, for every `Kdf` and `Hmac`, on every target and whatever the program links + (spec 4.1, design D33); `default_backend`. Another backend is named in the call's + type. @tparam Hmac A Boost.Hash2 hmac. @tparam Kdf `kdfs::hkdf` (the default), `kdfs::hkdf_extract`, `kdfs::hkdf_expand` or `kdfs::pbkdf2`. @@ -822,8 +819,9 @@ work, and is called only with valid arguments. `detail/canary.h` (spec 5.4), `detail/wipe.hpp` (stores of zero through `volatile` over a span and over a trivially copyable object), `detail/limits.hpp` (`exceeds`), `detail/engines.hpp` -(the primary templates of 2.12), `detail/ranking.hpp` (generated, spec 4.2), -`detail/xkcp.hpp` (the adapter's declarations). +(the primary templates of 2.12), `detail/xkcp.hpp` (the adapter's declarations). Until +2026-11-16 it also held the generated `detail/ranking.hpp` and `detail/overrides.hpp`, retired by +design D33. ### 2.15 The families of increments 2 to 7 @@ -1032,106 +1030,80 @@ which corrects the table where Botan lacks a function; no cell is assumed. ## 4. The default backend -### 4.1 The profile and the overrides +### 4.1 The default: `backends::hash2` (the owner's decision of 2026-11-16) -One setting in `config.hpp` changes every default backend at once, a **profile**, one macro per -value. A program gives it for webcpp::hash alone (`WEBCPP_HASH_PROFILE_*`) or for every library -at once through webcpp's umbrella, `WEBCPP_PROFILE_FASTEST`, `WEBCPP_PROFILE_SMALLEST` or -`WEBCPP_PROFILE_PORTABLE`, which webcpp::crypto reads too (its later change). Two library -profiles, or two umbrella profiles, are an `#error` naming both defines, as -"webcpp::hash: WEBCPP_HASH_PROFILE_FASTEST and WEBCPP_HASH_PROFILE_SMALLEST are both defined. -Keep one." A library profile beside an umbrella profile is not an error: the library's wins. +The default backend of every key derivation, `hkdf`, `hkdf_extract`, `hkdf_expand` and `pbkdf2`, +over every hmac, on native, wasip2, wasip3 and Emscripten and whatever the program links, is +`backends::hash2`. `backends::sodium` is the default only for what hash2 does not offer: +`argon2id` and `scrypt`, of which it is the only backend; a program that calls them without +`/third_party//sodium` stops with libsodium's "needs" message (5.7), raised for `backends::sodium` +by the primary template of the engine in `detail/engines.hpp` and tested by the messages +`argon2id_default_not_linked` and `scrypt_default_not_linked`. +`doc/capabilities.json` (layout version 3) names each function row's `"default"`, as the table +below (`null` for a type), and `capabilities_test` compares it with `default_backend`. -| Define | Profile | The default of each algorithm | -| --- | --- | --- | -| none | `auto`, the owner's rule, the build's measured default | natively `fastest`; on WebAssembly `smallest` | -| `WEBCPP_PROFILE_FASTEST`, `_SMALLEST`, `_PORTABLE` | the umbrella, for every webcpp library | as the library profile of the same name | -| `WEBCPP_HASH_PROFILE_FASTEST` | fastest | the linked backend that has it with the best measured throughput on this target (natively measured; on a WebAssembly target its own measurement where the table has one, else the native order) | -| `WEBCPP_HASH_PROFILE_SMALLEST` | smallest | the linked backend that has it with the smallest measured program on this target | -| `WEBCPP_HASH_PROFILE_PORTABLE` | portable | the first that has it of `hash2`, `xkcp`, `blake3`, `sodium`, `bearssl`: the same code on every target, never a backend absent from one (OpenSSL, Botan, WebCrypto) | -| `WEBCPP_HASH_PROFILE_BACKEND_` | a named backend (`HASH2`, `XKCP`, `BLAKE3`, `SODIUM`, `BEARSSL`, `OPENSSL`, `BOTAN`; never `WEBCRYPTO`, which serves the asynchronous family alone, section 11) | that backend for every algorithm it has; for the others, `auto`'s choice | - -**Precedence:** a per-algorithm override, then the library's profile, then webcpp's umbrella -profile, then the build's measured default (`auto`). - -**Per operation (design D25).** A profile chooses for the operation the call makes, each a tag of -`kdfs`: `hkdf`, `hkdf_extract`, `hkdf_expand`, `pbkdf2`, `argon2id`, `scrypt`. The choice is the -first backend of the profile's order (each step has its own row of the measured table) that the -program links and that has that operation over that hmac (`backend_has_v`); so an order that puts -`backends::bearssl` first, as the size order of `hkdf` does on every WebAssembly target, never -makes `hkdf_extract` or `hkdf_expand` refuse. When no linked backend has it, the first of the -order that has it, whose engine then refuses with its "needs" message (5.7). - -An **override** names the backend of one algorithm, whatever the profile, spelled as -webcpp::crypto's `WEBCPP_CRYPTO_DEFAULT_BACKEND__`: -`WEBCPP_HASH_DEFAULT_BACKEND__` (`WEBCPP_HASH_DEFAULT_BACKEND_HKDF_SODIUM`, -`WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_HASH2`, `WEBCPP_HASH_DEFAULT_BACKEND_SHA2_256_OPENSSL`); an override whose -backend lacks the algorithm over the hmac used fails to compile with that backend's text of 3.3; -two overrides of one algorithm are an `#error`. OpenSSL selected on Emscripten, by profile or -override, is an `#error`. A backend the program does not link is never chosen by a profile; an -override of an unlinked backend fails with that backend's "needs" message (5.7). An override -names an algorithm, not a step: `WEBCPP_HASH_DEFAULT_BACKEND_HKDF_` applies to `hkdf_extract`, -`hkdf_expand` and `hkdf`, and with `BEARSSL` the two steps refuse at compile time with 3.3's text. - -**Where the overrides live (design D28).** Not in `config.hpp`: one block per algorithm of -`doc/capabilities.json` and one define per backend that has it, in `detail/overrides.hpp`, -generated by `tools/hash/measure.py --overrides` from that file and checked by -`overrides_list_test`. It holds `override_choice`, the overrides' `#error`s (two -overrides of one algorithm; an OpenSSL override on Emscripten) and, on MSVC, each algorithm's -`#pragma detect_mismatch("webcpp_hash_default_backend_", ...)`, `"none"` without an -override. `kdf.hpp`, the one reader of the overrides, includes it, so every key derivation header -brings the refusals; a translation unit that includes no key derivation header reads no -default and is not stopped. - -The increment-1 spelling stays: `default_kdf_backend` is -`default_backend`, the general `template using -default_backend`. `backends::hash2` (or, for a hash webcpp has only over a C library, that -library's backend) is always a candidate, so a default always exists for every function of -increment 1. On MSVC `config.hpp` carries -`#pragma detect_mismatch("webcpp_hash_profile", "")` and `detail/overrides.hpp` each -algorithm's, so that two translation units of one program cannot choose differently. - -### 4.2 The measured table - -The defaults come from the build (the target, the `HAS` macros, the profile and overrides) and a -committed table of webcpp's own measurements, never estimated: - -- **size, per target** (native, wasip2, wasip3, Emscripten): for each algorithm of the - capability table (for a KDF, over `hmac_sha2_256` and `hmac_sha2_512`), each backend that has - it on that target, one program under `libs/hash/test/measure/` that computes it once from - fixed inputs and prints the result, built at `variant=release optimization=space`, linked with - only that backend's library; its size the bytes of the native executable, stripped, or of the - `.wasm`; -- **throughput, natively** (and on each WebAssembly target where the program runs within the - lane's bound): the same algorithms at a fixed workload (a hash over 1 MiB, a KDF's output of - 32 bytes, PBKDF2 at 100,000 iterations, the memory-hard functions at their interactive costs), - the median of five runs, built at `variant=release optimization=speed`. - -`tools/hash/measure.py` runs them, writes `doc/measurements.json` (with the machine, compiler, -target, date and each pin), renders `doc/measurements.adoc`, and generates -`include/webcpp/hash/detail/ranking.hpp`, which holds per target and operation (`hkdf_extract` and -`hkdf_expand` each with its own row) two orders of backends, by size and by throughput. The own lane -`measure` re-measures the sizes (deterministic for a toolchain) and fails when the order of any row -differs from the committed file, naming `python3 tools/hash/measure.py --write`; throughput is -re-measured by hand at every pin move and a committed order changes only when the median moves by -more than 10 percent, which keeps the defaults stable across machines. A first measurement orders by -the median of the invocations' medians alone, with no clause of its own (an exact tie keeps the -capability table's order of backends). Every pin move of a library a program links runs both -(CODING-GUIDELINES.md chapter 5 rule 12). - -**The native toolchain.** `doc/measurements.json` records the machine, whether it was loaded -(the larger 1-minute load average past the core count) and `native_toolchain`, the compiler, the -host's operating system and processor, and the strip the native orders were measured with. A -`measure` lane whose native toolchain differs builds and checks every program and skips the -native order comparison with one printed line; WebAssembly orders are always compared. - -**Increment 1's orders are provisional (design D32).** They were measured on one machine, macOS on -arm64 with Apple clang 21, shared and loaded (`loaded: true`). The native HKDF order over -`hmac_sha2_256`, libsodium then hash2 then OpenSSL, rests on medians each under 1 percent from the -next (1,540, 1,554 and 1,564 ns), and differs from the expectation "OpenSSL when linked" recorded in -design D8. Before a release the throughput is re-measured on an idle machine and the orders -regenerated. Whether one native order serves Linux and Windows (and x86-64), or each platform gets -its own, is an open question for the owner (design O2). +| Operation (tag of `kdfs`) | Default backend | +| --- | --- | +| `hkdf`, `hkdf_extract`, `hkdf_expand`, `pbkdf2` | `backends::hash2` | +| `argon2id`, `scrypt` | `backends::sodium` | + +`default_backend` and `default_kdf_backend` +(which is `default_backend`) keep their names and signatures; their answer is the +table's and depends neither on the hmac, nor on the libraries linked, nor on the target. Each +function names its default through its own tag (`hkdf_extract` through `kdfs::hkdf_extract`, ...), +and `backend_has_v` answers for the two steps through `kdfs::hkdf_extract` and `kdfs::hkdf_expand`. + +**The other backends are explicit choices.** `backends::bearssl`, `backends::openssl` and the HKDF +of `backends::sodium` stay, with their vectors, agreement tests, limits and refusals, and are +reached only by naming them in the type, as `hkdf`; none is +ever a default. + +**No define changes a default.** webcpp::hash reads no profile (`WEBCPP_HASH_PROFILE_FASTEST`, +`_SMALLEST`, `_PORTABLE`, `_BACKEND_`), not webcpp's umbrella `WEBCPP_PROFILE_FASTEST`, +`_SMALLEST` and `_PORTABLE`, and no override `WEBCPP_HASH_DEFAULT_BACKEND__`; a +former define has no effect, which `default_backend_former_defines` proves on the four targets +with every library linked. No `#pragma detect_mismatch` guards a profile or an override, since a +fixed default cannot differ between two translation units. + +**What it replaces.** Until 2026-11-16 this section held one profile per program (`auto`: +natively the fastest, on WebAssembly the smallest; `fastest`; `smallest`; `portable`, the first +that has it of `hash2`, `xkcp`, `blake3`, `sodium`, `bearssl`; a named backend), webcpp's umbrella +profile, per-algorithm overrides in the generated `detail/overrides.hpp`, and a choice per +operation from the measured orders of `detail/ranking.hpp` (design D8, D20, D25, D28). Increment 1 +built them; the owner retired them all (design D33). `portable` equals the new default, since +hash2 exists on every target; a named backend would make another backend a default; and with the +backend named in the type an override would make BearSSL or OpenSSL a default again and hide the +backend from the reader of the call, while Argon2id and scrypt have one backend, which an +override cannot change. + +The families of increments 2 to 7 (2.15) name their default through `default_backend` +too; for an algorithm Boost.Hash2 lacks it is the owner's to decide before increment 2 (design O3). + +### 4.2 The measured table, a dated reference + +`doc/measurements.json` and `doc/measurements.adoc` hold webcpp's own measurements of increment +1: the size of one program per algorithm, backend and target (native, wasip2, wasip3, +Emscripten), built at `variant=release optimization=space` and linked with only that backend's +library, and the throughput natively (and on each WebAssembly target where it ran), at +`optimization=speed`, with the machine, compiler, target, date and each pin. They are kept as a +reference measured on 2026-11-16, labelled so, that decides nothing: no default and no order of +backends comes from them, and the guide's comparison tables (section 8) read them as reference. + +`doc/measurements.json` keeps its records and orders; its about and layout text carry the label +and its digest is recomputed. `tools/hash/doc_tables.py` renders `doc/measurements.adoc` from it, +without the orders and without a default per key derivation, with the label and why hash2 is the +default, and its `--check`, run at every documentation build, fails when the digest does not match +the content (a hand edit of the reference). + +No lane re-measures or compares them. The own lane `measure` (its programs under +`libs/hash/test/measure/`, the CI matrix entry "Own lane (hash, measure)"), `tools/hash/measure.py` +whole with its test, and the generated `include/webcpp/hash/detail/ranking.hpp` are retired (design +D33), and +with them the rule of orders that changed only past 10 percent, the native toolchain's +comparison and the re-measurement on an idle machine before a release (design D32). What the +measurements showed is recorded in design D32 and D33: for HKDF over `hmac_sha2_256` the native +medians of libsodium, hash2 and OpenSSL were under 1 percent apart on one loaded macOS arm64 +machine, and the isolated programs on WebAssembly differed by a few KB. ### 4.3 The throughput measurement the owner named @@ -1140,9 +1112,10 @@ with 1,000,000 iterations, three runs, the median reported, for: `backends::hash `backends::openssl` (native, wasip2, wasip3); libsodium, which has no PBKDF2, through RFC 8018's loop written in the benchmark over `crypto_auth_hmacsha512_init/update/final` (a measurement of libsodium's HMAC-SHA-512 in PBKDF2's shape, never part of the library). The results go to -`doc/performance.adoc` with the machine, compiler, target and date. A measurement where -`backends::hash2` is faster than OpenSSL natively changes the `fastest` order (that is the -table's purpose) and is reported to the owner. +`doc/performance.adoc` with the machine, compiler, target and date, its times measured by hand +with `bench/collect.py`; the benchmark's correctness program `pbkdf2_sha512_key` (its derived keys +checked, never its time) runs in every lane of `libs/hash/test`. Its table, like 4.2's, decides no +default (design D33). ## 5. Build @@ -1235,9 +1208,8 @@ The three layers (CODING-GUIDELINES.md chapter 5 rule 6): the header's `#error` commit or configuration fails to link with the symbol's name; and on MSVC `#pragma detect_mismatch("webcpp_hash_backend_", "--")` in the header and the canary. OpenSSL has no canary (the provider injects nothing into upstream, -chapter 5 rule 7); its layers are the compile-time message and, for the default backend, -`#pragma detect_mismatch("webcpp_hash_default_kdf_backend", "")` on MSVC in `kdf.hpp`, -whose value is the selected backend's name, or `auto` without a selection. +chapter 5 rule 7); its layer is the compile-time message. It is never a default (4.1), so no +`detect_mismatch` guards a default backend. ### 5.5 One copy per program @@ -1279,9 +1251,12 @@ whose `#error` is the first message of spec 2.2. | `backends/openssl.hpp` without `WEBCPP_HASH_HAS_OPENSSL` | "webcpp::hash: backends::openssl needs OpenSSL. Add /webcpp/hash//openssl to the program's Jamfile (native, wasip2 and wasip3): exe app : app.cpp /webcpp/hash//hash /webcpp/hash//openssl ;" | | OpenSSL on Emscripten | spec 2.2's first `#error` | | a link without the library | the canary's symbol, as undefined | -| two TUs, two configurations, MSVC | LNK2038 on `webcpp_hash_backend_`, `webcpp_hash_profile` or `webcpp_hash_default_backend_` | -| two overrides of one algorithm | `detail/overrides.hpp`'s `#error`, "webcpp::hash: WEBCPP_HASH_DEFAULT_BACKEND__ and WEBCPP_HASH_DEFAULT_BACKEND__ are both defined. Keep one." | -| an OpenSSL override on Emscripten | `detail/overrides.hpp`'s `#error`, "webcpp::hash: WEBCPP_HASH_DEFAULT_BACKEND__OPENSSL selects OpenSSL, which is not built for Emscripten. Remove that define." | +| two TUs, two configurations, MSVC | LNK2038 on `webcpp_hash_backend_` | + +The messages of the profiles and the overrides (two profiles of one level, two overrides of one +algorithm, OpenSSL selected on Emscripten by a profile or an override, LNK2038 on +`webcpp_hash_profile` or `webcpp_hash_default_backend_`) are retired with them on +2026-11-16 (design D33): a former define has no effect. ## 6. Allocation and wiping @@ -1413,8 +1388,9 @@ difference. ### 7.9 The lanes Native, wasip2, wasip3, Emscripten and gcc-15 locally, from scratch (`-a`); MSVC and Apple clang -in the CI at the end. Own lanes: `c-suites`, `measure`; the throughput programs are run by hand on -each target and their numbers recorded (spec 4.2, 4.3). +in the CI at the end. Own lane: `c-suites` (the lane `measure` is retired, design D33); the +throughput benchmark's times of 4.3 are measured by hand, and its correctness program runs in every +lane. ## 8. Documentation @@ -1444,8 +1420,11 @@ reads a table of eight columns or more as a matrix that scrolls in its box rathe Per backend: its Jamfile line, its column of the capability table (rendered from `doc/capabilities.json`), what it allocates, and every message with its fix (CODING-GUIDELINES.md -chapter 5 rule 9, written so that an AI agent writes a correct Jamfile at once). The profile, the -overrides and the measured table. The departures of 1.3 and 6.2 with their conditions. +chapter 5 rule 9, written so that an AI agent writes a correct Jamfile at once). The default +backend (4.1) and how to name another one in the type, in the chapter `choosing_backend.adoc` +(anchors `hash-choosing-backend` and `hash-default-backend`), and `doc/backends.adoc` rendered +from `doc/capabilities.json` by `tools/hash/doc_tables.py`; the measured table as a reference dated +2026-11-16 that decides nothing (4.2). The departures of 1.3 and 6.2 with their conditions. **Teaching chapters by use case**, framed as raising the security of what a reader builds, with examples that are webcpp's own code: peer-to-peer networks (content addressing with BLAKE3 and @@ -1484,25 +1463,30 @@ library's plan, which changes nothing a crypto program links. backend and fails on another. - PBKDF2 on OpenSSL with `pkcs5 = 1` (2.9; design D10). - `default_kdf_backend` takes the KDF as a second, defaulted parameter, because libsodium and - BearSSL have HKDF and no PBKDF2 (design D8). + BearSSL have HKDF and no PBKDF2 (design D8); the parameter and its name stay, though every + key derivation's default is now `backends::hash2` (design D33). - Argon2id's memory must be a multiple of 1,024 bytes (2.10). - BLAKE3's SIMD files are compiled on the targets of their instruction sets alone, a recorded exception to chapter 5 rule 2's "every file on every target": they include x86 or Arm intrinsics headers that no WebAssembly sysroot has (design D6). - From increment 2 on, the families of 2.15 are not Hash2's form: one finalisation, and `invalid_state` (value 9) after it. -- The profile is one define of five (4.1); `auto` is the owner's rule; WebCrypto is never chosen - by a profile and serves the asynchronous family alone (section 11). +- Every key derivation defaults to `backends::hash2`, and Argon2id and scrypt to + `backends::sodium`, on every target and link set; BearSSL, OpenSSL and libsodium's HKDF only + when named in the type; no profile, no override, no measured order (4.1, 4.2; design D33, the + owner's decision of 2026-11-16, which retires the profile of five defines of design D20). + WebCrypto serves the asynchronous family alone (section 11). - The cheap asynchronous functions exist only for the algorithms WebCrypto serves, on every target, completing through `post` on a synchronous backend (11.2); the heavy ones run on another thread and exist only with threads (11.5). - Increment 1's amendments (design D25 to D32): the public tags `kdfs::hkdf_extract` and `kdfs::hkdf_expand` and a default backend per operation (4.1); `detail::backend_limits`, with OpenSSL refusing past `INT_MAX` (2.8); libsodium's `-sALLOW_MEMORY_GROWTH=1` on Emscripten (5.2, - 7.8); the overrides' refusals in `detail/overrides.hpp` behind `kdf.hpp` (4.1); BLAKE3's own + 7.8); the overrides' refusals in `detail/overrides.hpp` behind `kdf.hpp` (retired with the + overrides by design D33); BLAKE3's own program in the lane `c-suites` (7.3); `[[nodiscard]]` on every result (2.1); two comparison tables a chapter, each under eight columns (8); the native orders provisional until re-measured - on an idle machine (4.2). + on an idle machine (retired with the orders by design D33). - No `LICENSE-.txt` in the library's repository: webcpp::hash's code derives from no C library's (chapter 10, "The licence"); the README and the third-party table name each library and its licence. `NOTICE.md` holds libsodium-doc's copyright notice and ISC licence, @@ -1573,12 +1557,12 @@ never inline. A rejected promise is `error::backend_failure`; a cancelled operat threads; with a synchronous backend it runs on another thread, and exists so only where the build has threads. - **`default_async_backend`** is `backends::webcrypto` on Emscripten for every algorithm it - serves, whatever the profile (4.1): the asynchronous family exists for the browser; elsewhere, + serves (design D33 does not change it): the asynchronous family exists for the browser; elsewhere, and for an algorithm it does not serve, it is `default_backend`. - **The synchronous functions never use `backends::webcrypto`:** naming it in `hkdf`, `pbkdf2`, `digest` or `mac` fails to compile with "webcpp::hash: backends::webcrypto is asynchronous: call async_hkdf (or async_pbkdf2, async_digest, async_hmac) with a completion token, or name a - synchronous backend." No profile or override selects it for a synchronous function. + synchronous backend." It is never a synchronous function's default (4.1). - `` needs webcpp::asio (`/webcpp/asio//asio`), which the convenience header does not bring (chapter 3: an optional heavy dependency, named in its comment); `backends::webcrypto` needs nothing else on Emscripten and names no C library. diff --git a/libraries/hash/openspec/changes/genesis/specs/hash/spec.md b/libraries/hash/openspec/changes/genesis/specs/hash/spec.md index 2da19aa..88da3ed 100644 --- a/libraries/hash/openspec/changes/genesis/specs/hash/spec.md +++ b/libraries/hash/openspec/changes/genesis/specs/hash/spec.md @@ -4,7 +4,8 @@ webcpp::hash is a header-only C++20 library that gives a program one entry point key derivation on native, wasip2, wasip3 and Emscripten: Boost.Hash2's algorithms and HMAC by alias, Keccak-256 and BLAKE3 in Hash2's HashAlgorithm form over XKCP and BLAKE3's C implementation, HKDF and PBKDF2 over backends (webcpp's own over Hash2's hmac, libsodium, -BearSSL, OpenSSL) with a measured default, and Argon2id and scrypt from libsodium. These +BearSSL, OpenSSL) with `backends::hash2` as the default on every target, and Argon2id and scrypt +from libsodium. These requirements are the structured form of `reference/spec.md` and of the build, tests and tools of `reference/plan.md`; increment 1 is built in the library's repository, not yet published. @@ -18,7 +19,7 @@ The library SHALL be header-only C++20 in namespace `webcpp::hash` (with `webcpp - **THEN** it builds and runs on native, wasip2, wasip3 and Emscripten with no library of `/third_party` named or built ### Requirement: Library: configuration and exceptions -`` SHALL define `WEBCPP_HASH_NO_EXCEPTIONS` exactly when `WEBCPP_HAS_EXCEPTIONS` is not defined, keep it when a developer defines it, define `WEBCPP_HASH_WEBASSEMBLY` on wasip2, wasip3 and Emscripten, declare the backend tags `backends::hash2`, `sodium`, `bearssl` and `openssl` and the public KDF tags `kdfs::hkdf`, `kdfs::hkdf_extract`, `kdfs::hkdf_expand`, `kdfs::pbkdf2`, `kdfs::argon2id` and `kdfs::scrypt`, one per operation, and refuse with `#error` OpenSSL on Emscripten (`/webcpp/hash//openssl` or `WEBCPP_HASH_PROFILE_BACKEND_OPENSSL`) and more than one profile define of one level. The overrides' refusals MUST NOT be in `config.hpp`: they are in `detail/overrides.hpp`, which `kdf.hpp` includes. No function of the library SHALL throw, with exceptions on or off. +`` SHALL define `WEBCPP_HASH_NO_EXCEPTIONS` exactly when `WEBCPP_HAS_EXCEPTIONS` is not defined, keep it when a developer defines it, define `WEBCPP_HASH_WEBASSEMBLY` on wasip2, wasip3 and Emscripten, declare the backend tags `backends::hash2`, `sodium`, `bearssl` and `openssl` and the public KDF tags `kdfs::hkdf`, `kdfs::hkdf_extract`, `kdfs::hkdf_expand`, `kdfs::pbkdf2`, `kdfs::argon2id` and `kdfs::scrypt`, one per operation, and refuse with `#error` OpenSSL on Emscripten (`/webcpp/hash//openssl`). It MUST read no profile and no override define (design D33). No function of the library SHALL throw, with exceptions on or off. #### Scenario: The configuration test three ways - **WHEN** `test/config_test.cpp` is built as the build asks, with `WEBCPP_NO_EXCEPTIONS`, and with `WEBCPP_HASH_NO_EXCEPTIONS` on the command line @@ -103,8 +104,8 @@ The documentation SHALL state that a public `keccak_256` contributed to Boost.Ha - **THEN** each returns A.1's 42-byte OKM #### Scenario: A step never defaults to a backend that lacks it -- **WHEN** a wasip2 program that names `/third_party//bearssl` and `/third_party//sodium` and gives no profile calls `hkdf_extract` and `hkdf` -- **THEN** `hkdf` runs on `backends::bearssl`, the first of the size order, and `hkdf_extract` on the first backend of its own order that has the step, never `backends::bearssl`, and both compile +- **WHEN** a wasip2 program that names `/third_party//bearssl` and `/third_party//sodium` calls `hkdf_extract` and `hkdf` +- **THEN** both compile and run on `backends::hash2`, and `backend_has_v` is false ### Requirement: Key derivation: a backend's narrower lengths are its limits A backend whose C interface holds a length in a type narrower than `std::size_t` SHALL declare its limits in `detail::backend_limits` (`detail/engines.hpp`), one member per input and output of each operation, the primary template having no limit beyond the spec's. The public functions MUST read it after the spec's own guards and before any call of the backend, refusing a longer output with `invalid_output_size` and a longer input with `input_too_long`, the output untouched. `backends::openssl` MUST limit HKDF's salt and PRK and PBKDF2's password, salt and output to `INT_MAX` bytes, the lengths OpenSSL 3.5.9 holds in an `int` (a PBKDF2 output of 2^31 bytes crashed it), and its documentation MUST state them; `backends::hash2` accepts these lengths. @@ -153,58 +154,68 @@ A call of a KDF on a backend that lacks it, or over an hmac the backend lacks, S - **WHEN** RFC 6070's six SHA-1 cases and RFC 7914 section 11's two SHA-256 cases run through `pbkdf2` on `backends::hash2` and `backends::openssl` - **THEN** every derived key matches, the 16,777,216-iteration case included, in its own program -### Requirement: The default backend: one profile, per-algorithm overrides -`config.hpp` SHALL read webcpp's umbrella profile (`WEBCPP_PROFILE_FASTEST`, `_SMALLEST`, `_PORTABLE`) and SHALL take at most one library profile define: none (`auto`: natively the fastest, on WebAssembly the smallest), `WEBCPP_HASH_PROFILE_FASTEST`, `WEBCPP_HASH_PROFILE_SMALLEST`, `WEBCPP_HASH_PROFILE_PORTABLE` (the first that has the algorithm of hash2, xkcp, blake3, sodium, bearssl) or `WEBCPP_HASH_PROFILE_BACKEND_`, and per-algorithm overrides `WEBCPP_HASH_DEFAULT_BACKEND__`; `default_backend` (and `default_kdf_backend`, the same) MUST be the override's backend, else the profile's choice among the linked backends that have the algorithm, by the build (target, `HAS` macros) and the measured orders of `detail/ranking.hpp`, chosen per operation: the first backend of the order that the program links and that has that operation over that hmac. The precedence MUST be: per-algorithm override, library profile, umbrella profile, the build's measured default. Two profiles of one level (each `#error` naming both defines), two overrides of one algorithm, or OpenSSL selected on Emscripten MUST be an `#error`; on MSVC the profile and each override MUST carry `#pragma detect_mismatch`. The overrides, their refusals and their `detect_mismatch` (`webcpp_hash_default_backend_`) MUST be in `detail/overrides.hpp`, generated by `tools/hash/measure.py --overrides` from `doc/capabilities.json` and included by `kdf.hpp`, the one reader of the overrides; an override of HKDF applies to `hkdf_extract`, `hkdf_expand` and `hkdf`. +### Requirement: The default backend is backends::hash2 for every key derivation +`default_kdf_backend` and `default_backend` SHALL keep their names and signatures, and for `kdfs::hkdf`, `kdfs::hkdf_extract`, `kdfs::hkdf_expand` and `kdfs::pbkdf2` over every hmac they MUST be `backends::hash2`, on native, wasip2, wasip3 and Emscripten, whatever libraries the program links; their answer MUST NOT depend on the hmac, the link set or the target. For `kdfs::argon2id` and `kdfs::scrypt`, which `backends::hash2` does not offer, `default_backend` MUST be `backends::sodium`, their only backend. No measurement SHALL decide a default (design D33). -#### Scenario: Natively with OpenSSL, auto -- **WHEN** a native program that names `/webcpp/hash//openssl` and gives no profile reads `default_kdf_backend` -- **THEN** it is `backends::hash2`, since OpenSSL lacks RIPEMD-128; and `default_kdf_backend` is the faster of OpenSSL and hash2 in the committed native throughput order (hash2 in the provisional order of increment 1) +#### Scenario: HKDF's expand step with libsodium linked +- **WHEN** a native program that names `/third_party//sodium` calls `hkdf_expand` with RFC 5869 A.1's PRK and info +- **THEN** `default_kdf_backend` is `backends::hash2` and the call returns A.1's OKM computed by `backends::hash2` -#### Scenario: On wasip2 with libsodium, for PBKDF2 -- **WHEN** a wasip2 program that names `/third_party//sodium` reads `default_kdf_backend` -- **THEN** it is a backend that has PBKDF2 (`backends::hash2`), never `backends::sodium` +#### Scenario: PBKDF2 with OpenSSL linked +- **WHEN** a native program that names `/webcpp/hash//openssl` calls `pbkdf2` +- **THEN** it runs on `backends::hash2`, and `default_kdf_backend` is `backends::hash2` -#### Scenario: One switch for the whole program -- **WHEN** a native program that links libsodium and OpenSSL is built with `WEBCPP_HASH_PROFILE_PORTABLE` -- **THEN** every default is a backend present on all four targets (HKDF over SHA-256 is `hash2` or `sodium` by the portable order, never `openssl`) +#### Scenario: Every library linked, every target +- **WHEN** `default_backend_test` is built on native, wasip2, wasip3 and Emscripten with every library the target has, and reads `default_kdf_backend` for each hmac and each of `kdfs::hkdf`, `kdfs::hkdf_extract`, `kdfs::hkdf_expand` and `kdfs::pbkdf2` +- **THEN** every answer is `backends::hash2`, and `default_backend` and `default_backend` are `backends::sodium` -#### Scenario: The umbrella and the precedence -- **WHEN** a native program that links libsodium and OpenSSL is built with `WEBCPP_PROFILE_SMALLEST`, `WEBCPP_HASH_PROFILE_PORTABLE` and `WEBCPP_HASH_DEFAULT_BACKEND_HKDF_OPENSSL` -- **THEN** `hkdf` runs on OpenSSL (the override), `pbkdf2` on `backends::hash2` (the library's portable profile over the umbrella's smallest), and with only `WEBCPP_PROFILE_SMALLEST` both follow the measured size order +#### Scenario: Argon2id without libsodium +- **WHEN** a program calls `argon2id` (or `scrypt`) with the default backend and does not name `/third_party//sodium`, as the messages `argon2id_default_not_linked` and `scrypt_default_not_linked` do +- **THEN** compilation fails at the primary template of the engine in `detail/engines.hpp` with "webcpp::hash: backends::sodium, argon2id and scrypt need libsodium. Add /third_party//sodium to the program's Jamfile: exe app : app.cpp /webcpp/hash//hash /third_party//sodium ;" -#### Scenario: Two profiles at once -- **WHEN** a program defines `WEBCPP_HASH_PROFILE_FASTEST` and `WEBCPP_HASH_PROFILE_SMALLEST` -- **THEN** compilation fails with "webcpp::hash: WEBCPP_HASH_PROFILE_FASTEST and WEBCPP_HASH_PROFILE_SMALLEST are both defined. Keep one." +### Requirement: BearSSL, OpenSSL and libsodium's HKDF only when named in the type +`backends::bearssl`, `backends::openssl` and the HKDF of `backends::sodium` SHALL stay, with their vectors, agreement tests, limits and refusals as before, and SHALL be reached only by naming the backend in the call's type, as `hkdf`; none of them MUST ever be a default, on any target or link set. + +#### Scenario: OpenSSL named in the type +- **WHEN** a native program that names `/webcpp/hash//openssl` calls `hkdf` and `hkdf` with RFC 5869 A.1's inputs +- **THEN** the first runs on `backends::openssl`, the second on `backends::hash2`, and both return A.1's OKM + +#### Scenario: BearSSL named in the type +- **WHEN** a wasip2 program that names `/third_party//bearssl` calls `hkdf` and `hkdf` +- **THEN** the first runs on `backends::bearssl` and the second on `backends::hash2` -#### Scenario: An override that cannot serve -- **WHEN** a program defines `WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_SODIUM` and calls `pbkdf2` -- **THEN** compilation fails with spec 3.3's text for PBKDF2 on `backends::sodium` +### Requirement: No define changes a default +webcpp::hash SHALL have no profile and no per-algorithm override: it MUST NOT read `WEBCPP_HASH_PROFILE_FASTEST`, `WEBCPP_HASH_PROFILE_SMALLEST`, `WEBCPP_HASH_PROFILE_PORTABLE`, `WEBCPP_HASH_PROFILE_BACKEND_`, webcpp's umbrella `WEBCPP_PROFILE_FASTEST`, `_SMALLEST` and `_PORTABLE`, or `WEBCPP_HASH_DEFAULT_BACKEND__`, and a former profile or override define MUST have no effect. The library MUST hold no `detail/ranking.hpp`, no `detail/overrides.hpp` and no `#pragma detect_mismatch` of a profile or of an override. -#### Scenario: Two overrides of one algorithm -- **WHEN** a program defines `WEBCPP_HASH_DEFAULT_BACKEND_HKDF_HASH2` and `WEBCPP_HASH_DEFAULT_BACKEND_HKDF_SODIUM` and includes `` -- **THEN** compilation fails at `detail/overrides.hpp` with "webcpp::hash: WEBCPP_HASH_DEFAULT_BACKEND_HKDF_HASH2 and WEBCPP_HASH_DEFAULT_BACKEND_HKDF_SODIUM are both defined. Keep one.", and a translation unit that includes only `` compiles +#### Scenario: A former profile define +- **WHEN** a native program that names `/webcpp/hash//openssl` is built with `WEBCPP_HASH_PROFILE_FASTEST` (or `WEBCPP_PROFILE_SMALLEST`, or `WEBCPP_HASH_PROFILE_BACKEND_OPENSSL`) and calls `pbkdf2` +- **THEN** it compiles with no diagnostic from webcpp::hash and runs on `backends::hash2`, as without the define -#### Scenario: HKDF's override on BearSSL and the two steps -- **WHEN** a program that links BearSSL defines `WEBCPP_HASH_DEFAULT_BACKEND_HKDF_BEARSSL` and calls `hkdf` and `hkdf_extract` -- **THEN** `hkdf` runs on `backends::bearssl` and `hkdf_extract` fails to compile with spec 3.3's text for the two steps on `backends::bearssl` +#### Scenario: Former override defines +- **WHEN** `default_backend_former_defines`, `default_backend_test` built with `WEBCPP_HASH_PROFILE_FASTEST`, `WEBCPP_HASH_PROFILE_SMALLEST`, `WEBCPP_HASH_PROFILE_BACKEND_BEARSSL`, `WEBCPP_PROFILE_FASTEST`, `WEBCPP_HASH_DEFAULT_BACKEND_HKDF_SODIUM` and `WEBCPP_HASH_DEFAULT_BACKEND_PBKDF2_BEARSSL` and every library linked, runs on native, wasip2, wasip3 and Emscripten +- **THEN** every default stays `backends::hash2` for the key derivations and `backends::sodium` for `argon2id` and `scrypt` + +#### Scenario: Two former profiles at once +- **WHEN** a program defines `WEBCPP_HASH_PROFILE_FASTEST` and `WEBCPP_HASH_PROFILE_SMALLEST` +- **THEN** it compiles, and every default is `backends::hash2` -### Requirement: The defaults come from webcpp's own measurements, regenerated at every pin move -For every target, every algorithm of the capability table and every backend that has it there, a program under `libs/hash/test/measure/` SHALL be built and its size measured (`variant=release optimization=space`), and natively, and on WebAssembly where it runs within the lane's bound, its throughput (`optimization=speed`, median of five runs); `tools/hash/measure.py` MUST write `doc/measurements.json`, `doc/measurements.adoc` and `include/webcpp/hash/detail/ranking.hpp` (an order by size and an order by throughput per target and operation, `hkdf_extract` and `hkdf_expand` each with its own); the own lane `measure` MUST fail when a regenerated size order differs from the committed one, naming `python3 tools/hash/measure.py --write`. A first measurement MUST order by the median of the invocations' medians alone, with no clause of its own, and a committed throughput order changes only past a 10 percent difference in the median. The data MUST record the machine, whether it was loaded, and the native toolchain's identity (compiler, operating system, processor, strip); a lane whose native toolchain differs MUST build and check every program and skip the native order comparison with one printed line, and WebAssembly orders are always compared. Increment 1's native throughput orders are provisional: measured on one loaded macOS arm64 machine, the native HKDF order rests on medians under 1 percent apart, and they MUST be re-measured on an idle machine before a release. +### Requirement: The measured table is dated reference documentation +`doc/measurements.json` SHALL be kept as a reference measured on 2026-11-16, labelled so, which decides no default and orders no backend, and `doc/measurements.adoc` SHALL be rendered from it by `tools/hash/doc_tables.py` with that label, without the orders and without a default per key derivation; the guide's comparison tables MAY read them. `tools/hash/doc_tables.py --check`, run at every documentation build, MUST fail when `measurements.json`'s digest does not match its content. No lane SHALL re-measure or compare them: the own lane `measure`, `tools/hash/measure.py` (every mode) and its test, the CI matrix entry "Own lane (hash, measure)" and `libs/hash/test/measure` MUST NOT exist. -#### Scenario: A pin move without regeneration -- **WHEN** a pin of libsodium, BearSSL, OpenSSL, XKCP or BLAKE3 moves and a size order changes while `ranking.hpp` is unchanged -- **THEN** the `measure` lane fails and names the command that regenerates the files +#### Scenario: The reference is labelled +- **WHEN** a reader opens `doc/measurements.adoc` +- **THEN** it says that the table was measured on 2026-11-16, that it is a reference, and that it decides no default -#### Scenario: Another native toolchain -- **WHEN** the `measure` lane runs natively with a compiler, operating system or processor other than `doc/measurements.json`'s `native_toolchain` -- **THEN** it builds and checks every program, prints one line saying the native order comparison is skipped, and still compares the WebAssembly orders +#### Scenario: A hand edit of the reference +- **WHEN** a number of `doc/measurements.json` is changed by hand and the documentation is built +- **THEN** `tools/hash/doc_tables.py --check` fails, since the digest no longer matches the content -#### Scenario: A release after a loaded measurement -- **WHEN** a release of webcpp::hash is prepared while `doc/measurements.json` records `loaded: true` -- **THEN** the throughput is re-measured on an idle machine and the orders regenerated before the release +#### Scenario: A pin move +- **WHEN** a pin of libsodium, BearSSL, OpenSSL, XKCP or BLAKE3 moves +- **THEN** no lane re-measures sizes or throughput, no default changes, and the measured table keeps its date ### Requirement: The throughput of PBKDF2-HMAC-SHA-512 -`libs/hash/bench/pbkdf2_sha512.cpp` SHALL measure PBKDF2-HMAC-SHA-512 at 1,000,000 iterations and 64 bytes of output, the median of three runs, for `backends::hash2`, `backends::openssl` (native, wasip2, wasip3) and libsodium's HMAC-SHA-512 in RFC 8018's loop (libsodium has no PBKDF2), and `doc/performance.adoc` MUST record the results with the machine, compiler, target and date. +`libs/hash/bench/pbkdf2_sha512.cpp` SHALL measure PBKDF2-HMAC-SHA-512 at 1,000,000 iterations and 64 bytes of output, the median of three runs, for `backends::hash2`, `backends::openssl` (native, wasip2, wasip3) and libsodium's HMAC-SHA-512 in RFC 8018's loop (libsodium has no PBKDF2), and `doc/performance.adoc` MUST record the results with the machine, compiler, target and date, measured by hand with `bench/collect.py`; the benchmark's correctness program `pbkdf2_sha512_key`, which checks the derived keys and never the time, MUST run in every lane of `libs/hash/test`. #### Scenario: The table is filled - **WHEN** the throughput task is done @@ -301,7 +312,7 @@ Every test program SHALL be declared through the test Jamfile's rule `hash-run`, - **THEN** every test and its `_no_exceptions` twin passes ### Requirement: Documentation -The library's page SHALL open the chapter of each namespace (digests, MACs, key derivations, password hashing, the non-cryptographic hashes) with two comparison tables generated by `tools/hash/doc_tables.py` from `doc/capabilities.json` and the measurements, "What each of X is" and "How to choose among X", each led by the name and each of fewer than eight columns, so that no comparison is a matrix that scrolls in its box; it SHALL give one short section per algorithm (what it is, an example that is a program of `libs/hash/example/` built on every target, its pitfalls), in the manner of noble's README without its text; per backend its Jamfile line, its column of the capability table rendered from `doc/capabilities.json`, what it allocates and every message with its fix; the profile, the overrides and the measured table; the departures with their conditions; and teaching chapters by use case (peer-to-peer networks, cryptocurrencies, privacy), framed as raising security, with webcpp's own code as examples. Text adapted from libsodium's documentation (ISC, `jedisct1/libsodium-doc` at `6d1ea27`) MUST say so and `NOTICE.md` MUST keep its copyright notice and licence; Wikipedia MUST only be cited, never copied. +The library's page SHALL open the chapter of each namespace (digests, MACs, key derivations, password hashing, the non-cryptographic hashes) with two comparison tables generated by `tools/hash/doc_tables.py` from `doc/capabilities.json` and the measurements, "What each of X is" and "How to choose among X", each led by the name and each of fewer than eight columns, so that no comparison is a matrix that scrolls in its box; it SHALL give one short section per algorithm (what it is, an example that is a program of `libs/hash/example/` built on every target, its pitfalls), in the manner of noble's README without its text; per backend its Jamfile line, its column of the capability table rendered from `doc/capabilities.json`, what it allocates and every message with its fix; the default backend, `backends::hash2` (`backends::sodium` for Argon2id and scrypt), and how to name another backend in the type, in the chapter `choosing_backend.adoc`, and the measured table as a reference dated 2026-11-16 that decides nothing; the departures with their conditions; and teaching chapters by use case (peer-to-peer networks, cryptocurrencies, privacy), framed as raising security, with webcpp's own code as examples. Text adapted from libsodium's documentation (ISC, `jedisct1/libsodium-doc` at `6d1ea27`) MUST say so and `NOTICE.md` MUST keep its copyright notice and licence; Wikipedia MUST only be cited, never copied. #### Scenario: An agent writes the Jamfile - **WHEN** an agent reads the page's backend table to derive PBKDF2-HMAC-SHA-512 in a program for Emscripten @@ -312,11 +323,11 @@ The library's page SHALL open the chapter of each namespace (digests, MACs, key - **THEN** each chapter has two tables led by `Name`, each of fewer than eight columns, the second with the measured columns only when there are measurements ### Requirement: Increments by value, and a capability table -The library SHALL be built in the seven increments of spec 1.5, each usable alone and merged before the next: 1 (Hash2, `keccak_256`, `blake3`, HKDF, PBKDF2, Argon2id, scrypt, the profile, the measured table), 2 (libsodium's whole hashing surface), 3 (XKCP's Keccak family), 4 (OpenSSL's), 5 (BearSSL's), 6 (Botan 3's, after webcpp::crypto provisions Botan), 7 (the browser backend). `doc/capabilities.json` MUST hold spec 3.5's table, a test MUST compare it with `backend_has_v` for every cell, and each increment's first task MUST check its column against the library at its pin. +The library SHALL be built in the seven increments of spec 1.5, each usable alone and merged before the next: 1 (Hash2, `keccak_256`, `blake3`, HKDF, PBKDF2, Argon2id, scrypt, the default backend, the measured table as dated reference), 2 (libsodium's whole hashing surface), 3 (XKCP's Keccak family), 4 (OpenSSL's), 5 (BearSSL's), 6 (Botan 3's, after webcpp::crypto provisions Botan), 7 (the browser backend). `doc/capabilities.json` MUST hold spec 3.5's table and, for each function row, its `"default"` backend (`hash2`, `sodium`, or `null` for a type), and a test MUST compare it with `backend_has_v` for every cell and with `default_backend` for every default, and each increment's first task MUST check its column against the library at its pin. #### Scenario: The table and the code agree - **WHEN** `capabilities_test` reads `doc/capabilities.json` and evaluates `backend_has_v` for every function and backend -- **THEN** every cell agrees, and a cell changed in one place alone fails the test +- **THEN** every cell and every default agrees, and a cell changed in one place alone fails the test ### Requirement: Families for every backend's hashes, MACs and KDFs From increment 2 on, `digest`, `hasher` (`make`, `update`, `finish`, move-only, wiped, `invalid_state` after the finalisation), `mac` and `argon2` with `argon2_parameters` (passes, memory in KiB, lanes, secret, associated data) SHALL reach every backend's implementation over the tags of `digests`, `macs` and `kdfs`, with `digest_options` and `mac_options` per tag, the guards in one place and engines per backend; a parameter a backend does not take MUST return `error::unsupported_by_backend`. The Hash2-form types stay Hash2's own, `keccak_256` and `blake3`. diff --git a/libraries/hash/openspec/changes/genesis/tasks.md b/libraries/hash/openspec/changes/genesis/tasks.md index 5e6d4cd..847af99 100644 --- a/libraries/hash/openspec/changes/genesis/tasks.md +++ b/libraries/hash/openspec/changes/genesis/tasks.md @@ -4,12 +4,13 @@ Each task points to its section in `reference/plan.md`, which holds its files, i steps, code and expected output. Increment 1 is built and committed in the library's own repository (branch `main`, not yet on GitHub) and the superproject's integration branch, reviewed and green on every local lane; each of its tasks says what was built, with the design decision -where the build changed the plan. Increments 2 to 7 and the publication are open. The groups are +where the build changed the plan; a note dated 2026-11-16 marks the work design D33 retires. +Increments 2 to 7 and the publication are open. The groups are the spec's increments (spec 1.5); inside each, the plan's "The order of the work, and the parallel streams" says which tasks run in parallel, by backend. `reference/STATUS.md` says how to start. -## 1. Increment 1: Hash2, Keccak-256, BLAKE3, HKDF, PBKDF2, Argon2id, scrypt, the profile +## 1. Increment 1: Hash2, Keccak-256, BLAKE3, HKDF, PBKDF2, Argon2id, scrypt, the default backend - [x] 1.1 The worktree, the ledger and the baseline (plan: Task 0). Built: the superproject's integration branch on webcpp::crypto's version 0.1, the ledger, and the baseline lanes and lint recorded - [x] 1.2 The library's skeleton, the test rule `hash-run` and chapter 17's entry (plan: Task 1). Built: `build.jam`, `config.hpp`, the test Jamfile's `hash-run` (each test with its `_no_exceptions` twin), third_party's shared hash block and `detail/canary.h`, chapter 17's entry @@ -25,17 +26,18 @@ parallel streams" says which tasks run in parallel, by backend. - [x] 1.12 HKDF on `backends::sodium` (plan: Task 11; stream `kdf-sodium`). Built: `backends/sodium.hpp` over `crypto_kdf_hkdf_sha256_*` and `_sha512_*` - [x] 1.13 `/webcpp/hash//openssl` and `backends::openssl` (plan: Task 12; stream `kdf-openssl`). Built: the alias, `backends/openssl.hpp` (HKDF and PBKDF2 with `pkcs5 = 1`), its refusal on Emscripten, and `detail::backend_limits` with OpenSSL's `INT_MAX` (design D26) - [x] 1.14 HKDF on `backends::bearssl`, after webcpp::crypto's BearSSL is on `main` (plan: Task 13; stream `kdf-bearssl`). Built: `backends/bearssl.hpp` and hash's canary in `/third_party//bearssl`, on webcpp::crypto's version 0.1 integration branch (its `main` waits for crypto's gates) -- [x] 1.15 The profile, the overrides, the default backend, the capability table (plan: Task 14; stream `default`). Built: the profiles and the umbrella in `config.hpp`, the public tags `kdfs::hkdf_extract`, `kdfs::hkdf_expand`, `kdfs::argon2id` and `kdfs::scrypt` with a default per operation (design D25), the generated `detail/overrides.hpp` included by `kdf.hpp` (design D28), `doc/capabilities.json` and `capabilities_test` +- [x] 1.15 The profile, the overrides, the default backend, the capability table (plan: Task 14; stream `default`). Built: the profiles and the umbrella in `config.hpp`, the public tags `kdfs::hkdf_extract`, `kdfs::hkdf_expand`, `kdfs::argon2id` and `kdfs::scrypt` with a default per operation (design D25), the generated `detail/overrides.hpp` included by `kdf.hpp` (design D28), `doc/capabilities.json` and `capabilities_test`. Retired on 2026-11-16 by design D33: the profiles, the umbrella's reading, the overrides with `detail/overrides.hpp` and `overrides_list_test`, the profiles' tests and messages and their `detect_mismatch`; the public tags, `default_backend`, `default_kdf_backend`, `doc/capabilities.json` and `capabilities_test` stay (task 1.26) - [x] 1.16 Argon2id on libsodium, RFC 9106 through its core (plan: Task 15; stream `pwhash`). Built: `argon2.hpp`, RFC 9106's case through `argon2_ctx`, the presets and the guards - [x] 1.17 scrypt on libsodium (plan: Task 16; stream `pwhash`). Built: `scrypt.hpp`, RFC 7914's cases, the 1 GiB case in its own program - [x] 1.18 Agreement between backends on every target (plan: Task 17; stream `agreement`). Built: `agreement_hkdf_test` and `agreement_pbkdf2_test`, every linked backend that has the function against every other on each target, 1,000 seeded random cases per hmac, the empty inputs first - [x] 1.19 WebCrypto under node as an outside oracle (plan: Task 18; stream `webcrypto`). Built: `webcrypto_oracle_test` on Emscripten, HKDF and PBKDF2 over SHA-1, SHA-256, SHA-384 and SHA-512 - [x] 1.20 The user's Jamfiles, the canaries at link time, one program (plan: Task 19; stream `build`). Built: `tools/test/hash_jamfiles_test.py` and its fixtures, the link-fail cases, `webcpp.same-program` per C library with libsodium's flag as its one difference on Emscripten (design D27) - [x] 1.21 Allocation (plan: Task 20; stream `allocation`). Built: `allocation_test` (exact counts), OpenSSL's allocations counted apart, `doc/measurements.allocation.json` -- [x] 1.22 The measured table and `detail/ranking.hpp` (plan: Task 21; stream `measure`). Built: `tools/hash/measure.py`, the own lane `measure` (284 cells on four targets), `doc/measurements.json` and `.adoc`, rankings per operation with the native toolchain's identity; provisional, measured on one loaded machine, to be re-measured on an idle one before a release (design D32) -- [x] 1.23 PBKDF2-HMAC-SHA-512 at 1,000,000 iterations (plan: Task 22; stream `throughput`). Built: `bench/pbkdf2_sha512.cpp` in the lane `measure`, `doc/performance.adoc` (natively OpenSSL about 2.2 times faster than hash2) +- [x] 1.22 The measured table and `detail/ranking.hpp` (plan: Task 21; stream `measure`). Built: `tools/hash/measure.py`, the own lane `measure` (284 cells on four targets), `doc/measurements.json` and `.adoc`, rankings per operation with the native toolchain's identity; provisional, measured on one loaded machine, to be re-measured on an idle one before a release (design D32). Retired on 2026-11-16 by design D33: `detail/ranking.hpp` and the code reading it, the own lane `measure` (`tools/hash/measure.py --check`, the CI matrix entry "Own lane (hash, measure)", `libs/hash/test/measure`) and the re-measurement before a release; `doc/measurements.json` and `.adoc` stay as a reference dated 2026-11-16 that decides nothing (task 1.26) +- [x] 1.23 PBKDF2-HMAC-SHA-512 at 1,000,000 iterations (plan: Task 22; stream `throughput`). Built: `bench/pbkdf2_sha512.cpp` in the lane `measure`, `doc/performance.adoc` (natively OpenSSL about 2.2 times faster than hash2). On 2026-11-16 the lane `measure` is retired by design D33; the correctness program `pbkdf2_sha512_key` runs in every lane, the times are measured by hand with `bench/collect.py`, and the table stays - [x] 1.24 The documentation, the examples and the Boost.Hash2 proposal's text (plan: Task 23). Built: the guide, generated by `tools/hash/doc_tables.py` with two comparison tables a chapter, each under eight columns (design D31); the examples on every target; `doc/upstream.adoc` -- [x] 1.25 Increment 1 whole: the rulebook, green, review, the gates (plan: Task 24). Built: chapter 5's exceptions and chapter 17 as built, the lint's canary pins over hash, `[[nodiscard]]` on every result under the lint's rule (design D30); native, wasip2, wasip3, Emscripten, gcc-15, `c-suites`, `measure` and the lint green from scratch; the whole review. The gates are 8.1 and 8.2 +- [x] 1.25 Increment 1 whole: the rulebook, green, review, the gates (plan: Task 24). Built: chapter 5's exceptions and chapter 17 as built, the lint's canary pins over hash, `[[nodiscard]]` on every result under the lint's rule (design D30); native, wasip2, wasip3, Emscripten, gcc-15, `c-suites`, `measure` and the lint green from scratch; the whole review. The gates are 8.1 and 8.2. The lane `measure` is retired on 2026-11-16 by design D33 +- [x] 1.26 Every key derivation defaults to `backends::hash2` (design D33, the owner's decision of 2026-11-16; plan: the notes of 2026-11-16 at Tasks 14 and 21). Built on the branches `hash/defaults-hash2` of `webcpporg/hash` and of the superproject: `default_backend` and `default_kdf_backend` answer `backends::hash2` for `hkdf`, `hkdf_extract`, `hkdf_expand` and `pbkdf2` on every target and link set, `backends::sodium` for `argon2id` and `scrypt`, whose engine's primary template refuses an unlinked libsodium with its "needs" text (messages `argon2id_default_not_linked` and `scrypt_default_not_linked`, their Emscripten fixtures and MSVC cases); `default_backend_former_defines` shows that former profile and override defines change nothing; the profiles, the umbrella's reading, the overrides, `detail/ranking.hpp`, `detail/overrides.hpp`, their `detect_mismatch`, tests and messages removed; the lane `measure`, `tools/hash/measure.py` whole with `hash_measure_test.py`, `tools/ci/matrix.py`'s `EVERY_TARGET_LANES` and `tools/lint/compile_commands.py`'s native WebAssembly commands removed with their tests; `doc/capabilities.json` at layout version 3 with a `"default"` per function row (no `"portable"`, no `"overridable"`); `tools/hash/doc_tables.py` renders `doc/backends.adoc` and `doc/measurements.adoc`, the reference of 2026-11-16, and its `--check` guards `measurements.json`'s digest; `pbkdf2_sha512_key` in every lane, the times by hand with `bench/collect.py`; the chapter `choosing_backend.adoc` and `guide.json`'s use-case field `backend` (layout version 2) ## 2. Increment 2: libsodium's whole hashing surface (stream `sodium-2`)