diff --git a/README.md b/README.md index 9fd1983..79e63df 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ tag is placed. | crypto | [api-gaps](libraries/crypto/openspec/changes/api-gaps) | crypto: the API gaps of version 0.2 closed, and dudect judged on hosted runners | wrapper | implementing | | 2026-11-20 | [code](https://github.com/webcpporg/crypto) | | crypto | [data-independent-timing](libraries/crypto/openspec/changes/data-independent-timing) | crypto: the library sets arm64's DIT around every cryptographic operation | wrapper | implementing | | 2026-11-20 | [code](https://github.com/webcpporg/crypto) | | crypto | [unified-sign](libraries/crypto/openspec/changes/unified-sign) | crypto: one sign and verify on every curve, the scheme always named, the key pair contract and four forms of each operation | wrapper | implementing | | 2026-11-22 | [code](https://github.com/webcpporg/crypto) | +| crypto | [uniform-types](libraries/crypto/openspec/changes/uniform-types) | crypto: typed signatures, typed X25519 keys, and concepts for key pairs, AEADs and boxes | wrapper | implementing | | 2026-11-22 | [code](https://github.com/webcpporg/crypto) | | document | [genesis](libraries/document/openspec/changes/archive/2026-10-12-genesis) | document: a JSON document for C++20 that behaves as JavaScript does, in one relocatable image | own | implemented | 0.1.0 | 2026-10-12 | [code](https://github.com/webcpporg/document/tree/ac29296) | | hash | [genesis](libraries/hash/openspec/changes/genesis) | hash: hashing and key derivation over Boost.Hash2 and C backends | wrapper | accepted | | 2026-11-14 | | | hash | [data-independent-timing](libraries/hash/openspec/changes/data-independent-timing) | hash: the library sets arm64's DIT around every computation on a secret | wrapper | implementing | | 2026-11-20 | [code](https://github.com/webcpporg/hash) | diff --git a/libraries/crypto/openspec/changes/uniform-types/.openspec.yaml b/libraries/crypto/openspec/changes/uniform-types/.openspec.yaml new file mode 100644 index 0000000..a8f3b37 --- /dev/null +++ b/libraries/crypto/openspec/changes/uniform-types/.openspec.yaml @@ -0,0 +1,11 @@ +schema: spec-driven +created: 2026-11-22 +webcpp: + library: crypto + title: "crypto: typed signatures, typed X25519 keys, and concepts for key pairs, AEADs and boxes" + kind: wrapper + port_of: null + status: implementing + release: null + implementation: https://github.com/webcpporg/crypto + decided: 2026-11-22 diff --git a/libraries/crypto/openspec/changes/uniform-types/design.md b/libraries/crypto/openspec/changes/uniform-types/design.md new file mode 100644 index 0000000..16c105f --- /dev/null +++ b/libraries/crypto/openspec/changes/uniform-types/design.md @@ -0,0 +1,742 @@ +## Context + +This change builds on crypto/sign-unified as merged: typed public keys (`ed25519::public_key`, +`p256::basic_public_key`, `secp256k1::public_key`), the concept `crypto::keypair` in +`` (`make`, `generate`, `public_key()`, `secret()` and `sign` for every +scheme of `detail::all_schemes` it declares), `agree(peer)` on P-256 and secp256k1, scheme tags as +values, the backend first among template parameters, and four mirrored forms per operation (its +D9: member and free, synchronous and asynchronous, one implementation, the asynchronous members +defined in `async.hpp`). Its rule for a signature is a span: every `sign` returns +`std::array` and every `verify` and `recover` takes `std::span`, +checking its size first. + +What is not typed on that branch: + +| Value | Today | +|---|---| +| Ed25519 signature | `std::array` | +| P-256 and secp256k1 ECDSA signatures | `std::array` | +| secp256k1 recoverable and BIP340 signatures | `std::array`, `std::array` | +| X25519 public key | `std::array` from the free `curves::x25519::public_key(secret)` | +| X25519 secret key | `secret<32>`; agreement by the free `curves::x25519::agree(secret, peer)` | +| crypto_kx | `kx_keypair::make(seed)`, peers as 32-byte spans | +| Ed25519 to X25519 | `basic_keypair::x25519_secret()` (`secret<32>`), free `to_x25519_public(public_key)` (an array) | +| crypto_box, sealed box | made from secret and public key bytes | +| secretbox | `ciphers::aead`, whose `seal` takes additional data it refuses unless empty | + +The AEADs are `ciphers::gcm` (AES-GCM, with an incremental seal and open: `begin_seal`, +`update`, `result`, `begin_open`, `authenticate`, `decrypt`, `verify`, `end_open`) and +`ciphers::aead` (ChaCha20-Poly1305 in three nonce sizes); the asynchronous family has +`async_seal` and `async_open` for AES-GCM only, by the foundation's rule that no `async_` variant +of a cheap algorithm WebCrypto lacks exists. + +## Goals / Non-Goals + +**Goals:** a type for every signature of every curve and scheme, returned by `sign` and taken by +`verify` and `recover`; X25519's keys typed as the other curves' are, with crypto_kx, the boxes and +Ed25519's conversion on them; three key pair concepts that every key pair meets according to what +it does; concepts for AEADs, AES-GCM's incremental form and the boxes, constraining the free and +asynchronous forms; asynchronous seal and open for every AEAD and box on native backends; every +caller moved, the old names removed with no alias. + +**Non-goals:** key and signature formats (the formats change, which builds on this one); sealed +boxes in a concept (their shape, a recipient's key per call, is neither an AEAD's nor a box's); +new algorithms; the browser backend itself (part B of the asynchronous family). + +## Owner decisions (2026-11-22, binding) + +1. **Typed signatures per curve and scheme**, returned by `sign` on every curve and taken by + `verify` and `recover`, replacing crypto/sign-unified's span rule, each with `bytes()` and + `from_bytes(bytes)` (named `make` when decided, renamed by decision 9); whether `verify` keeps a bytes overload is ruled here (R1). +2. **X25519 typed like the others**: `x25519::public_key` (`from_bytes`, `bytes`), + `x25519::basic_keypair` (`from_secret`, `generate`, `public_key()`, `secret()`, `agree(peer)` with + `async_agree` and the free `crypto::agree`), `kx_keypair` built on it; Ed25519's + `x25519_secret()` and `to_x25519_public` become a typed conversion (`ed_key.to_x25519()` giving + an `x25519::keypair`, `ed_pub.to_x25519()` an `x25519::public_key`); the old functions removed. +3. **Key pair concepts split**: `keypair` (`from_secret`, `generate`, `public_key()`, `secret()`), + `signing_keypair` (also `sign` for each declared scheme, at least one), `agreement_keypair` + (also `agree`). Ed25519 signs; P-256 and secp256k1 do both; X25519 agrees. +4. **`concept aead`** (`key_size`, `iv_size`, `tag_size`, `result_type`, `static from_key(key)` + returning `result`, `seal(iv, ad, data)` returning `result`, + `open(iv, ad, data, tag)` returning `result`), with a `static_assert` per cipher; the + refinement **`streaming_aead`** (AES-GCM's `begin_seal`, `update`, `result`, `begin_open`, + `authenticate`, `decrypt`, `verify`, `end_open`); option (a) for the boxes: box and secretbox + get the sibling concept **`authenticated_box`** (`seal(iv, data)`, `open(iv, data, tag)`), with + no fake additional data. `crypto::seal`, `crypto::open` and the asynchronous forms are + constrained by these concepts; `async_seal` and `async_open` extend to any AEAD on native + backends, the browser staying WebCrypto-only and refusing with a clear message. +5. **Four mirrored forms apply to everything new.** + +Second round, the same day, answering the first draft's rulings: + +6. **`verify` takes only the typed signature**, with no bytes overload; a signature from the wire + goes through `from_bytes` first (R1 confirmed). +7. **libsodium's seeded kx derivation keeps a distinct name**, option (b): + `key_exchange::kx_keypair::derive_from_seed(seed)` (`crypto_kx_seed_keypair`: the secret is + BLAKE2b-256 of the seed), beside `from_keypair(x25519_keypair)` and `generate()`; the factory + named by its input says the bytes or the key are the secret (R5 replaced; names per decision 9). + +Third round, the same day: + +8. **`crypto::hybrid` is removed as a namespace; constructions are grouped by purpose**: + `crypto::public_key_encryption::{basic_box, box, box_xchacha20poly1305, basic_sealed_box, + sealed_box}` and `crypto::key_exchange::{kx_keypair, session_keys}` (out of `curves::x25519`), + with no alias for the old names; kx's `derive_from_seed` is unchanged. The reason: "hybrid + encryption" (a KEM with a DEM) does not describe crypto_kx, and "hybrid" now means post-quantum + hybrids (X25519MLKEM768, X-Wing), so `crypto::hybrid` stays free for those. `curves` holds curve + primitives only, `ciphers` symmetric ciphers, and the two new namespaces the composed + constructions, named by the problem they solve; a future HPKE (RFC 9180) lives in + `public_key_encryption`. + +Fourth round, the same day: + +9. **The fallible factory `make` is renamed by what it takes**, with no alias: a key pair's + `K::from_secret(secret_bytes)` (and `K::generate()`, unchanged); a public key's and a + signature's `T::from_bytes(bytes)`; a cipher's, an AEAD's and a secretbox's + `C::from_key(key)`; and, by this change's rulings, P-256's public key from raw coordinates + `from_coordinates(x, y)`, crypto_box's `from_keys(own_keypair, peer_public_key)`, and kx's + `from_keypair(x25519_keypair)` beside `derive_from_seed(seed)` and `generate()`. The concept + `keypair` requires `from_secret` and `generate`. The four forms follow: the free + `crypto::from_secret(bytes)`, `crypto::from_bytes(bytes)`, `crypto::from_key(key)` and + `crypto::generate()`; the asynchronous `async_from_secret`, `async_from_key` and + `async_generate`, member and free. The reason: `make`, a fallible constructor in the style of + `std::make_*`, reads as "make a key", and a caller who passes fixed bytes believing a key is + drawn gets a predictable private key; the name of the input makes the call site say where the + secret comes from. The backends' internal capabilities keep their names (`*_import`, + `*_generate`). + +Fifth round, 2026-11-23: + +10. **Ethereum's recoverable ECDSA is a scheme of this change**, `crypto::ecdsa_keccak256_recoverable`, + on secp256k1 alone: the input a message, hashed inside with Keccak-256 (the pre-NIST padding + Ethereum uses, never SHA3-256), or `crypto::prehashed{digest}` of 32 bytes for a digest the + program builds (EIP-191's `personal_sign`, EIP-712, a transaction's sighash: protocol work, + outside crypto); the output the typed `secp256k1::recoverable_signature` (r, s, the recovery id + 0 to 3, always low S as EIP-2 requires); `recover(ecdsa_keccak256_recoverable, signature, input)` + gives the signer's `secp256k1::public_key`. Ethereum's `v` (27 or 28, or EIP-155's chain-id + form) and the address are protocol encodings: the guide shows them, crypto computes neither (D8). + +Sixth round, 2026-11-23 (the owner's reason for both: readability): + +11. **The secret-hygiene utilities are named by what they do** (D10): the public wipe of the + controller's Task X2 is `crypto::erase_secret` in `` (never + `crypto::wipe`), with the plan's contract unchanged (a contiguous sized range of non-const + trivially copyable elements, `noexcept`, no pointer and size overload, a `static_assert` whose + message names the ranges it accepts), `detail::wipe` staying the internal primitive; and + `crypto::equal`, both overloads (spans, and `boost::hash2::digest`), is renamed + `crypto::constant_time_equal` in ``, with no alias, every + caller moved (tests, examples, the page, `crypto.json`, the constant-time lane's paths and + suppressions, the message and MSVC tests, the superproject's fixtures, and other libraries' + callers such as webcpp::hash's, through the superproject's pointers). webcpp::trystero's + port of Trystero 0.27 is not touched; its call sites are listed in the stream's handback. + The guide gains one section about protecting secrets outside the primitives (memory and + timing hygiene) grouping `constant_time_equal`, `erase_secret`, `secret` and + `random_device`; no new namespace: they stay at the top of `webcpp::crypto`. +12. **Ed25519ph (RFC 8032) is a scheme, `crypto::eddsa_prehashed`**, in the one list of schemes, + which Ed25519's signing key pair declares (D9): its input is `crypto::prehashed{digest}` of 64 + bytes only, the message's SHA-512 as RFC 8032's Ed25519ph defines it, a message being refused + at compile time with a clear message (the opposite of `eddsa`, which refuses a digest); its + result `ed25519::signature`, the same 64-byte type, an `eddsa` and an `eddsa_prehashed` + signature not being interchangeable (the page says so); `verify(eddsa_prehashed, signature, + prehashed, public_key)` and the member form; the asynchronous forms on native backends only, + refused on the browser's backend (WebCrypto has no Ed25519ph). The streaming signer + `curves::ed25519::ph` is renamed `curves::ed25519::prehashed_signer` + (`begin`, `update`, `sign`, `verify` unchanged), with no alias, its callers moved. RFC 8032's + Ed25519ph vectors stay, and a test checks that the streaming signer and + `sign(eddsa_prehashed, prehashed{sha512(message)})` give the same signature. Ruling R14 (a + distinct `ph_signature`) is superseded: no such type exists. + +Seventh round, 2026-11-23 (the owner's reason: names that say what a thing is, read without a +glossary): + +13. **The AEAD contract has a namespace of its own, secretbox joins it, and public names are spelled + out** (D11): + - the AEAD contract lives in namespace `webcpp::crypto::secret_key_encryption::aead`, in + ``: the concept decision 4 called + `crypto::aead` is `secret_key_encryption::aead::cipher`, its refinement `streaming_aead` is + `secret_key_encryption::aead::streaming_cipher`, and the free `seal`, `open`, `async_seal` + and `async_open` move there from `crypto::`, where no free AEAD `seal` or `open` remains; the + members (`cipher.seal`, `open`, `async_seal`, `async_open`) are unchanged; + - the algorithm types stay in `crypto::ciphers` with their names: `gcm`, + `gcm`, `chacha20_poly1305`, `xchacha20_poly1305`, `aes128`, `aes256`, and later + `chacha20`; + - secretbox moves from `crypto::ciphers` to `crypto::secret_key_encryption`, parallel to + `public_key_encryption::box`: `secret_key_encryption::secretbox` and + `secretbox_xchacha20poly1305` in ``, with + no alias, the library being before 1.0; + - parameter names are spelled out everywhere in crypto's public API: `iv` and `iv_bytes` + become `nonce` and `nonce_bytes`, `additional_data` becomes `associated_data`, `ctx` becomes + `context`, and any other abbreviation in a public parameter name gets its full name; only + algorithm proper names stay acronyms (`aes`, `gcm`, `hkdf`, `hmac`, `ecdsa`, `sha256`, ...). + CODING-GUIDELINES.md's crypto and hash rules gain the rule: public names spelled out, + algorithm proper names excepted; + - every call site moves: crypto's code, pages, examples and tests, and the superproject's + fixtures. Out of scope: webcpp::trystero's port of Trystero 0.27, not in the tree, which + migrates later; webcpp::hash's HKDF names (`ikm`, `prk`, `info`), which a change of hash's + renames. + Decision 4's names (`crypto::aead`, `crypto::streaming_aead`, `crypto::seal`, `crypto::open`, + `iv`, `ad`) are superseded by these; D5, D6, D11, R7, R21 and R22 give the result. + The controller's ruling on how it is built (2026-11-23, R23): 3.2 and 3.3 are written with + decision 13's names; X4 covers the renames they do not touch. + +Eighth round, 2026-11-23 (the owner's reason: `ciphers::aead` reads like the namespace +`secret_key_encryption::aead`, and libsecp256k1's abbreviations are the glossary decision 13 +removed): + +14. **The one-shot AEAD template is named for its algorithm, and the names crypto took from + libsecp256k1 are spelled out** (D12): + - the class template `ciphers::aead` is + `ciphers::basic_chacha20_poly1305`, the pattern of + `public_key_encryption::basic_box` and `secret_key_encryption::basic_secretbox`; the aliases + `chacha20_poly1305`, `chacha20_poly1305_original` and `xchacha20_poly1305` keep their names; + - secp256k1's MuSig2 `musig::nonce_gen` is `musig::generate_nonce`; the key tweaks + `pubkey_tweak_add`, `pubkey_tweak_mul`, `pubkey_negate` and `pubkey_combine` are + `public_key_tweak_add`, `public_key_tweak_mul`, `public_key_negate` and + `public_key_combine`; `seckey_tweak_add`, `seckey_tweak_mul` and `seckey_negate` are + `secret_key_tweak_add`, `secret_key_tweak_mul` and `secret_key_negate`; + - any other public abbreviation of the same kind in crypto's public headers is spelled out + (R24 lists the one found); algorithm proper names stay (`musig`, `ellswift`, `ecdh`, + `xonly`, ...), and libsecp256k1's own C names (`secp256k1_ec_pubkey_*`), which crypto calls, + are not crypto's public names; + - secp256k1's `agree`, `agree_hashed` and `agree_point` stay as they are; + - no compatibility alias; every call site moves (crypto's code, pages, examples, tests, + fixtures, the constant-time lane, the benches and the superproject's fixtures); + webcpp::trystero's port of Trystero 0.27 is out of scope, listed by the HANDBACK. + The controller's ruling on how it is built (2026-11-23): Task X5 "remaining spelled-out + names" runs after X1b and before 4.1, and its first commit rewords D6's refusal (D6), which + 3.3's fix round made fire from the synchronous forms too. + +## Approaches + +**Signatures.** (a) Keep bytes and add a scheme check at run time: a P-256 signature given to +secp256k1's `verify` still compiles. (b) One generic `crypto::signature`: `ecdsa_sha256` +is the scheme of two curves, so the type would not know its curve, which DER needs (P-256's +encoder refuses r or s not below its n). (c) One type per curve and scheme (chosen): the type says +the curve and the scheme, so `crypto::verify` refuses a mismatch at compile time and the formats +change can gate `der` by type. + +**Boxes.** (a) A sibling concept `authenticated_box` without additional data (chosen by the +owner); (b) keep secretbox an `aead` whose additional data must be empty: a parameter that exists +only to be refused; (c) give boxes additional data by hashing it into the nonce: an invented +construction, not libsodium's. + +## Decisions + +### D1. Typed signatures + +| Type | Bytes | `sign` of | `verify` / `recover` under | +|---|---|---|---| +| `curves::ed25519::signature` | 64 | `ed25519::basic_keypair::sign(eddsa, ...)`, `sign(eddsa_prehashed, ...)` and `prehashed_signer::sign` (D9) | `eddsa`, `eddsa_prehashed` (not interchangeable: each verifies its own scheme's) | +| `curves::p256::ecdsa_signature` | 64, r then s | `p256::basic_keypair::sign(ecdsa_sha256, ...)` | `ecdsa_sha256` | +| `curves::secp256k1::ecdsa_signature` | 64, r then s | `secp256k1::basic_keypair::sign(ecdsa_sha256, ...)` | `ecdsa_sha256` | +| `curves::secp256k1::recoverable_signature` | 65, r, s, the id | `sign(ecdsa_sha256_recoverable, ...)`, `sign(ecdsa_keccak256_recoverable, ...)` (D8) | `recover(...)` under the same scheme | +| `curves::secp256k1::schnorr_signature` | 64 | `sign(schnorr, ...)` | `schnorr` | + +Each is a regular value type (copyable, comparable with `==`; a signature is public), implemented +by one class template in `detail` with a distinct tag per type, so that no two convert into each +other. Each has `static constexpr std::size_t size`; `static from_bytes(std::span)` +returning `result`, `invalid_signature` for another size and nothing else checked (whether r and +s are below n, or R canonical, is verification's judgment, as crypto/sign-unified's R16 rules for +Ed25519's public key); `bytes()` returning `std::array const&`; and nothing +that converts implicitly. `recoverable_signature` adds `recovery_id()` (0 to 3). The free +`crypto::from_bytes(bytes)` (D3c) serves them. + +`sign` returns `result` on every key pair and scheme, the asynchronous `sign` completes with +`void(error_code, T)`; `crypto::verify(scheme, signature, input, public_key)`, `pub.verify`, +their asynchronous forms and `recover` take `T`. The trait that pairs a scheme with its key's types +(`detail::signs_with_v`, crypto/sign-unified's D5) gains the signature type, so `can_verify` is +false for a signature of another curve or scheme, with a message naming the type it expects. +`normalize_low_s` and `is_low_s` take and return the curve's `ecdsa_signature`. + +### D2. X25519's types + +- `curves::x25519::public_key`: `static from_bytes(std::span)` returning + `result`, `invalid_public_key` for another size than 32 and nothing else checked + (a small-order key is refused where it matters, by `agree`, as `weak_public_key`); `bytes()`. +- `curves::x25519::basic_keypair` (and `x25519::keypair`, its default): `public_key_type`, + `secret_key_size` 32; `static from_secret(secret_bytes)` (RFC 7748's 32-byte scalar, clamped by the + backend as today) and `static generate()`, returning `result`; `public_key()` + returning `result`; `secret()` returning `result>`; `agree(peer)`, `peer` + a `public_key`, returning `result>` and `weak_public_key` when the shared secret is + all zero, on every backend, as the foundation requires; moved from, every call returns + `invalid_state`; its state wiped on destruction and move, as the other key pairs are. +- The four forms: `from_secret`, `generate`, `agree` as members; `crypto::from_secret`, `crypto::generate`, + `crypto::agree(key, peer)` free (crypto/sign-unified's generic ones, now constrained by D3); + `K::async_from_secret`, `K::async_generate`, `key.async_agree(executor, peer, token)` and the free + `async_from_secret`, `async_generate`, `async_agree`, defined in `async.hpp`. X25519 is in WebCrypto, so + the asynchronous forms exist on every backend, the browser's included once part B lands. +- Removed: the free `curves::x25519::public_key(secret)` (its name is the type's now) and + `curves::x25519::agree(secret, peer)`; `curves::x25519::algorithm` moves into `detail`, its + family `families::x25519` unchanged. + +### D3. crypto_kx, the boxes and Ed25519's conversion on typed keys + +- `key_exchange::kx_keypair` holds an `x25519::basic_keypair`: made from one + (`from_keypair(x25519_keypair)`), by `generate()`, or by `derive_from_seed(seed)`, libsodium's seeded + derivation (`crypto_kx_seed_keypair`: the secret is BLAKE2b-256 of the 32-byte seed), kept under + its own name because programs store kx seeds (owner decision 7). The two differ on the same 32 + bytes: `from_keypair(*x25519::keypair::from_secret(bytes))` takes them as the secret, `derive_from_seed(bytes)` + hashes them first; the guide says so, and a test checks that `derive_from_seed` gives + `crypto_kx_seed_keypair`'s keys and differs from `from_keypair` on the same bytes; `public_key()` returns + `x25519::public_key`; `client_session_keys(server)` and `server_session_keys(client)` take an + `x25519::public_key` and return `session_keys` as today. Its seed and secret are the inner key + pair's (`keypair()` gives it by reference). +- `public_key_encryption::basic_box::from_keys(own, peer)`, `own` an `x25519::basic_keypair`, `peer` an + `x25519::public_key`, computing the shared key once (libsodium's `beforenm`) as today. +- `public_key_encryption::basic_sealed_box::seal(recipient, message, out)`, `recipient` an + `x25519::public_key`; `open(recipient, sealed, out)`, `recipient` an `x25519::basic_keypair`. +- `ed25519::basic_keypair::to_x25519()` returns `result>`, `B'` the + X25519 family's backend that matches (libsodium for libsodium), and + `ed25519::public_key::to_x25519()` returns `result`, `invalid_public_key` for + a key that is not canonical or of small order; the free `crypto::to_x25519(value)` calls either. + They are conversions of bytes the program holds and WebCrypto has none: synchronous only, member + and free (R4). `x25519_secret()` and `curves::ed25519::to_x25519_public` are removed. + +### D3b. Namespaces by purpose (owner decision 8) + +| Before | After | Header | +|---|---|---| +| `hybrid::basic_box`, `hybrid::box`, `hybrid::box_xchacha20poly1305` | `public_key_encryption::basic_box`, `box`, `box_xchacha20poly1305` | `` (was `hybrid/box.hpp`) | +| `hybrid::basic_sealed_box`, `hybrid::sealed_box` | `public_key_encryption::basic_sealed_box`, `sealed_box` | `` (was `hybrid/sealed_box.hpp`) | +| `curves::x25519::kx_keypair`, `curves::x25519::session_keys` | `key_exchange::kx_keypair`, `key_exchange::session_keys` | `` (was `curves/x25519/kx.hpp`) | + +The namespaces follow the directories, as `ciphers` and `curves` do; `detail`'s engines and states +of these types move with them (`detail::box_engine` and the others keep their names). The families +(`families::box_xsalsa20poly1305`, `families::box_xchacha20poly1305`, `families::sealed_box`, +`families::kx`), their backends and their capability rows are unchanged: only the namespaces and +headers of the public types move, and `crypto.json`'s entries that name a header or a type are +updated and its generated files rerun. The convenience header includes the new headers in place of +the old. The directory `hybrid/` and the namespace `crypto::hybrid` stay empty and unused in this +change, free for a later post-quantum hybrid (X25519MLKEM768, X-Wing). + +### D3c. Factories named by their input (owner decision 9) + +| Type | Before | After | +|---|---|---| +| every key pair (`ed25519`, `x25519`, `p256`, `secp256k1`) | `K::make(secret_bytes)`, `generate()` | `K::from_secret(secret_bytes)`, `K::generate()` | +| every public key | `T::make(bytes)` | `T::from_bytes(bytes)` | +| P-256's public key from raw coordinates | `make(x, y)` | `from_coordinates(x, y)` (R10) | +| every signature type | `T::make(bytes)` | `T::from_bytes(bytes)` | +| `ciphers::gcm`, `ciphers::basic_chacha20_poly1305` (was `ciphers::aead`, decision 14), `secret_key_encryption::basic_secretbox` (decision 13), the block cipher | `C::make(key)` | `C::from_key(key)` | +| `public_key_encryption::basic_box` | `make(own, peer)` | `from_keys(own, peer)` (R11) | +| `key_exchange::kx_keypair` | `make(x25519_keypair)`, `make(seed)` | `from_keypair(x25519_keypair)` (R12), `derive_from_seed(seed)`, `generate()` | +| free forms | `crypto::make(...)` | `crypto::from_secret`, `crypto::from_bytes`, `crypto::from_key`; `crypto::generate` unchanged | +| asynchronous | `async_make` (member and free) | `async_from_secret`, `async_from_key`; `async_generate` unchanged | + +The header `` of crypto/sign-unified, which holds the free factories, +becomes `` (R13). No alias of `make` or `async_make` remains. A key +pair's `from_secret` and its `secret()` are inverses by name, and `from_bytes` and `bytes()` for +public values. + +### D4. The key pair concepts + +`` declares, folding over `detail::all_schemes` as crypto/sign-unified +does: + +- `crypto::keypair`: `K::from_secret(secret_bytes)` and `K::generate()` returning `result`, + `public_key()` returning `result`, `secret()` returning + `result>`; +- `crypto::signing_keypair`: `keypair` and `sign(scheme, input)` for every scheme `K` + declares, at least one, its result the scheme's signature type for `K`'s curve (D1); +- `crypto::agreement_keypair`: `keypair` and `agree(peer)`, `peer` a + `typename K::public_key_type`, returning `result>`. + +| Key pair | `keypair` | `signing_keypair` | `agreement_keypair` | +|---|---|---|---| +| `ed25519::basic_keypair` | yes | yes | no (`to_x25519()` converts) | +| `x25519::basic_keypair` | yes | no | yes | +| `p256::basic_keypair` | yes | yes | yes | +| `secp256k1::basic_keypair` | yes | yes | yes | + +Each curve's header checks its row with `static_assert`s. `crypto::sign` and `async_sign` are +constrained by `signing_keypair`, `crypto::agree` and `async_agree` by `agreement_keypair`, and a +call with a key pair that does not do the operation stops the build with a message naming what the +key pair does ("X25519 key pairs agree; they do not sign"). + +### D5. The AEAD and box concepts + +The AEAD contract is `secret_key_encryption::aead`'s (owner decision 13, D11). A new header +`` (no backend; `ciphers/aead.hpp` keeps the +one-shot template, `ciphers::basic_chacha20_poly1305` by decision 14, and includes it) declares, +in namespace +`webcpp::crypto::secret_key_encryption::aead`: + +- `cipher`: `C::key_size`, `C::nonce_size`, `C::tag_size` (`std::size_t` constants), + `typename C::result_type`; `C::from_key(std::span)` returning `result`; + `c.seal(nonce, associated_data, data)` returning `result`, `data` + sealed in place; `c.open(nonce, associated_data, data, tag)` returning `result`, `data` + opened in place and zeroed on failure. +- `streaming_cipher`: `cipher` and `begin_seal(nonce, associated_data)`, `update(data)`, + `result()`, `begin_open(nonce, associated_data)`, `authenticate(data)`, `decrypt(data)`, + `verify(tag)` and `end_open()`, with AES-GCM's signatures. + +`` (no backend) declares +`secret_key_encryption::authenticated_box`: +`C::key_size`, `C::nonce_size`, `C::tag_size`, `typename C::result_type`; `c.seal(nonce, data)` +returning `result`; `c.open(nonce, data, tag)` returning `result`, `data` +zeroed on failure. The factory is not part of it: a secretbox is made by `from_key`, a crypto_box +by `from_keys` from two X25519 keys. The concept lives beside the secret box, in +`secret_key_encryption`; crypto_box, in `public_key_encryption`, satisfies it too (R21). + +| Type | Concept | +|---|---| +| `ciphers::gcm` (`aes128_gcm`, `aes256_gcm`) | `secret_key_encryption::aead::streaming_cipher` | +| `ciphers::chacha20_poly1305`, `chacha20_poly1305_original`, `xchacha20_poly1305` | `secret_key_encryption::aead::cipher` | +| `secret_key_encryption::secretbox`, `secretbox_xchacha20poly1305` | `authenticated_box` | +| `public_key_encryption::box`, `box_xchacha20poly1305` | `authenticated_box` | + +Each header checks its row with a `static_assert`. secretbox leaves the one-shot AEAD template +(`ciphers::aead` when built, `ciphers::basic_chacha20_poly1305` by decision 14): +it becomes `secret_key_encryption::basic_secretbox` with `from_key(key)`, +`seal(nonce, data)` and `open(nonce, data, tag)`, the guards and the zeroing of the AEAD template, +and no associated data; `detail::aead_family` and its `max_associated_data_size` 0 +are removed. + +The free forms: `secret_key_encryption::aead::seal(c, nonce, associated_data, data)` and +`secret_key_encryption::aead::open(c, nonce, associated_data, data, tag)` constrained by `cipher`; +`secret_key_encryption::seal(c, nonce, data)` and `secret_key_encryption::open(c, nonce, data, tag)` +constrained by `authenticated_box`, for a secret box and a crypto_box alike (R21). No free `seal` +or `open` exists in `crypto::` nor in `public_key_encryption`. A box given to `secret_key_encryption::aead::seal` or `open` stops the build with a +message naming the box forms; the arities differ, so no call is ambiguous. + +### D6. Asynchronous seal and open everywhere native + +`async_seal` and `async_open`, member (`c.async_seal(executor, ...)`) and free +(`secret_key_encryption::aead::async_seal(executor, c, ...)` for a `cipher`; +`secret_key_encryption::async_seal` for an `authenticated_box`, R21), with the synchronous arguments between the executor and the token, +exist for every `secret_key_encryption::aead::cipher` and every +`secret_key_encryption::authenticated_box`. On a synchronous backend they run +the synchronous member and complete through `asio::post`, never inline, as the family does today. +On `backends::browser` (a backend whose `detail::asynchronous_backend_v` is true), only AES-GCM is +offered, through WebCrypto; any other stops the build, from every form, synchronous or +asynchronous, member or free (3.3's fix round, the controller's ruling), with one text that says no +form of them runs there: "webcpp::crypto: WebCrypto has no ChaCha20-Poly1305, XChaCha20-Poly1305, +secret box or crypto_box: no form of them, synchronous or asynchronous, runs on the browser's +backend; name a native backend for them. On the browser's backend only AES-GCM seals and opens." +(X5 rewords it so; 3.3 wrote "their async_seal, async_open and async_from_key run on a native +backend", which named only the asynchronous forms.) This supersedes the foundation's sentence that +no `async_` variant of a cheap algorithm WebCrypto lacks may exist, for seal and open only, by the +owner's decision; `async_from_key` follows the same rule for the types these concepts cover. + +### D8. Ethereum's recoverable ECDSA (owner decision 10) + +- The tag `ecdsa_keccak256_recoverable_t` (explicit default constructor) and the value + `crypto::ecdsa_keccak256_recoverable` join `detail::all_schemes`; `scheme_traits` gives a 65-byte + signature and a 32-byte digest; `signs_with_v, ...>` is true, and + `signature_of` of it is `secp256k1::recoverable_signature`, the type `ecdsa_sha256_recoverable` + gives (the bytes are the same; the scheme is the input's hash). +- `key.sign(ecdsa_keccak256_recoverable, input)` and `crypto::sign(key, ...)`: a message is hashed + with `webcpp::hash::keccak_256` (``, over XKCP), a marker's 32 bytes are + signed as they are; libsecp256k1's `secp256k1_ecdsa_sign_recoverable` with RFC 6979's nonce, low S. +- `curves::secp256k1::recover(ecdsa_keccak256_recoverable, signature, input)`, member-free as + `ecdsa_sha256_recoverable`'s, with its checks (a recovery id above 3, r or s not below n, no key: + `invalid_signature`). No `crypto::verify` overload: `ecdsa_sha256_recoverable` has none (its + signature gives its key to `recover`), and Ethereum compares recovered keys or addresses (R18). +- Forms: the synchronous member and free forms; no asynchronous form, as no secp256k1 operation has + one (crypto/sign-unified's R8). +- Keccak-256 needs `/third_party//xkcp`, which builds on every target and toolset; secp256k1's + header includes `keccak.hpp` only where `WEBCPP_HASH_HAS_XKCP` is defined, and a message input + without it stops the build with the Jamfile line (R19). A marker needs no XKCP. +- The guide: the digests a program builds (EIP-191 with an example program over `webcpp::hash`), + `recovery_id()` to `v` (27 + id for `personal_sign`, 35 + 2 x chain id + id for EIP-155, the + id itself as `yParity` for typed transactions), and the address (the last 20 bytes of the + Keccak-256 of the uncompressed key without its 0x04), in the example, not in crypto. + +### D9. Ed25519ph as the scheme `eddsa_prehashed` (owner decision 12) + +- The tag `eddsa_prehashed_t` (explicit default constructor) and the value + `crypto::eddsa_prehashed` join `detail::all_schemes` (after `eddsa_t`); `scheme_traits` gives a + 64-byte signature and a 64-byte digest, SHA-512's; `signs_with_v, ...>` + and `verifies_with_v` are true, and `signature_of` of either is + `ed25519::signature`. +- The input is `crypto::prehashed{digest}` of 64 bytes alone: a message stops the build with a + message naming the marker, `eddsa` and the streaming signer; a digest of another size with one + naming SHA-512's 64 bytes; `eddsa` keeps refusing a marker, its text now naming + `eddsa_prehashed`. +- `key.sign(eddsa_prehashed, prehashed{digest})`, `crypto::sign`, `crypto::verify(eddsa_prehashed, + signature, prehashed{digest}, public_key[, policy])` and `public_key.verify(...)`, strict as + `eddsa` is; their asynchronous forms run on native backends and stop the build on a backend + whose `asynchronous_backend_v` is true, WebCrypto having no Ed25519ph. +- `curves::ed25519::prehashed_signer` (was `ph`) streams the message, SHA-512 inside, and + its `sign` and `verify` give and take `ed25519::signature`; over the same message it gives the + signature `sign(eddsa_prehashed, prehashed{sha512(message)})` gives. +- An `eddsa` and an `eddsa_prehashed` signature have one type: one given to the other scheme's + `verify` is `invalid_signature` at run time, as RFC 8032's domain separation makes it; the page + says which a protocol uses is the protocol's choice. + +### D10. Protecting secrets: `constant_time_equal` and `erase_secret` (owner decision 11) + +| Before | After | Header | +|---|---|---| +| `crypto::equal(span, span)`, `crypto::equal(digest, digest)` | `crypto::constant_time_equal`, both overloads, the same work | `` (was `equal.hpp`) | +| (none; the plan's `crypto::wipe`, never released) | `crypto::erase_secret(range)` over `detail::wipe` | `` | + +Both stay at the top of `webcpp::crypto`, beside `secret` and `random_device`; the guide's +section "Protecting secrets outside the primitives" groups the four (memory hygiene: `secret`, +`erase_secret`; timing hygiene: `constant_time_equal`; drawing: `random_device`). + +### D11. Secret-key encryption and spelled-out names (owner decision 13) + +| Before | After | Header | +|---|---|---| +| `crypto::seal`, `crypto::open` (the AEAD forms) | `secret_key_encryption::aead::seal`, `open` | `` (were in `ciphers/aead.hpp`), which every AEAD's header includes | +| `crypto::async_seal`, `crypto::async_open` | `secret_key_encryption::aead::async_seal`, `async_open` | ``, which defines every asynchronous form | +| `crypto::aead`, `crypto::streaming_aead` (planned, never built) | `secret_key_encryption::aead::cipher`, `streaming_cipher` | `` | +| `ciphers::secretbox`, `ciphers::secretbox_xchacha20poly1305` (and the planned `ciphers::basic_secretbox`) | `secret_key_encryption::secretbox`, `secretbox_xchacha20poly1305`, `basic_secretbox` | `` (was `ciphers/secretbox.hpp`) | +| `ciphers::gcm`, `aes128_gcm`, `aes256_gcm`, `chacha20_poly1305`, `chacha20_poly1305_original`, `xchacha20_poly1305`, `aes128`, `aes192`, `aes256` | unchanged | unchanged | +| the template `ciphers::aead` | `ciphers::basic_chacha20_poly1305` (decision 14, D12) | ``, unchanged (R25) | + +The namespaces by purpose, with D3b's: + +| Namespace | Holds | +|---|---| +| `crypto` | the root: `random_device`, `constant_time_equal`, `erase_secret`, `secret`, `error`, the signing vocabulary, the key pair concepts, the free factories | +| `crypto::ciphers` | symmetric algorithms: AES, AES-GCM, ChaCha20-Poly1305 in three nonce sizes | +| `crypto::secret_key_encryption` | constructions under one secret key: `secretbox`, the concept `authenticated_box` and the box forms `seal`/`open`; `aead`, the AEAD contract over `ciphers`' AEADs | +| `crypto::public_key_encryption` | constructions between key pairs: `box`, `sealed_box` | +| `crypto::key_exchange` | crypto_kx: `kx_keypair`, `session_keys` | +| `crypto::curves` | curve primitives | + +The naming rule: every public name of crypto is spelled out; algorithm and format proper names +stay acronyms (`aes`, `gcm`, `chacha20`, `hmac`, `hkdf`, `ecdsa`, `eddsa`, `sha256`, `kx`, `der`, +`pem`, `spki`, `pkcs8`, BIP340's `xonly`), and so do a standard's own variable names (ECDSA's `r` and +`s`). The pages and doc comments say "nonce" and "associated data" (RFC 5116's term); a comment +that quotes a backend or a standard in its own words (OpenSSL's IV, NIST SP 800-38D's IV and +additional authenticated data) keeps them. + +| Before | After | +|---|---| +| parameters `iv`, `iv_bytes` | `nonce`, `nonce_bytes` | +| parameters `additional_data`, `additional_data_bytes`, `ad` | `associated_data`, `associated_data_bytes` | +| parameter `ctx` | `context` (none in crypto when decided) | +| secp256k1's `sign(schnorr, message, aux_random)` | `auxiliary_random_bytes` | +| member constants `iv_size`, `max_iv_size`, `max_additional_data_size` | `nonce_size`, `max_nonce_size`, `max_associated_data_size` (R22) | +| `error::invalid_iv_size` (value 2) | `error::invalid_nonce_size` (value 2; "the nonce is not of a size the algorithm accepts") (R22) | + +### D12. The ChaCha20-Poly1305 template and secp256k1's names spelled out (owner decision 14) + +| Before | After | Header | +|---|---|---| +| `ciphers::aead` | `ciphers::basic_chacha20_poly1305`; its refusal of a family that is no AEAD's names it ("webcpp::crypto: ciphers::basic_chacha20_poly1305 takes an AEAD family: ...") | `` (R25) | +| `curves::secp256k1::musig::nonce_gen` | `musig::generate_nonce` | `curves/secp256k1/musig.hpp` | +| `curves::secp256k1::pubkey_tweak_add`, `pubkey_tweak_mul`, `pubkey_negate`, `pubkey_combine` | `public_key_tweak_add`, `public_key_tweak_mul`, `public_key_negate`, `public_key_combine` | `curves/secp256k1/tweak.hpp` | +| `curves::secp256k1::seckey_tweak_add`, `seckey_tweak_mul`, `seckey_negate` | `secret_key_tweak_add`, `secret_key_tweak_mul`, `secret_key_negate` | `curves/secp256k1/tweak.hpp` | +| `curves::secp256k1::silent_payments::prevouts_summary`, `make_prevouts_summary` | `previous_outputs_summary`, `make_previous_outputs_summary` (R24) | `curves/secp256k1/silent_payments.hpp` | +| `chacha20_poly1305`, `chacha20_poly1305_original`, `xchacha20_poly1305`; secp256k1's `agree`, `agree_hashed`, `agree_point`; `combine_workspace_size`, `workspace_size`, `scan_workspace_size`, `send_workspace_size`, `summary_workspace_size` (no abbreviation, R25); `ellswift_*`, `tweak_xonly`, `tweak_xonly_add`, MuSig2's `key_aggregate`, `nonce_aggregate`, `nonce_process`, `partial_sign` and the other spelled-out names | unchanged | unchanged | + +The signatures, the behaviour, the guards, the timing coverage and the capability rows +(`key_tweaks`, `musig`, `silent_payments`) are unchanged: only the names move. The timing seam's +member labels follow the class (`ciphers::basic_chacha20_poly1305::seal` for +`ciphers::aead::seal`). A doc comment that quotes libsecp256k1's own names (`secp256k1_ec_pubkey_tweak_add`, +the keyagg cache, `pubnonce`, `aggnonce`, `partial_sig`, `prevouts_summary` as libsecp256k1's type) +or a test vector's field names (BIP352's `scan_pubkey`, BIP327's `nonce_gen_vectors`) keeps them. + +### D7. Removed, and callers + +Removed with no alias: the span `verify` and `recover` overloads of crypto/sign-unified; `sign`'s +array results; `curves::x25519::public_key(secret)`, `curves::x25519::agree(secret, peer)`; +`ed25519::basic_keypair::x25519_secret()`, `curves::ed25519::to_x25519_public`; +`kx_keypair::make(seed)` (now `derive_from_seed`); every `make` and `async_make` (D3c); the namespace `crypto::hybrid` and the headers +`hybrid/box.hpp`, `hybrid/sealed_box.hpp` and `curves/x25519/kx.hpp` (D3b); the boxes' +byte-key factories, `seal` and `open`; secretbox's additional data; `crypto::equal` and +`` (D10); `curves::ed25519::ph` (now `prehashed_signer`, D9); the +free `crypto::seal`, `crypto::open`, `crypto::async_seal`, `crypto::async_open`, +`ciphers::secretbox`, `ciphers::secretbox_xchacha20poly1305`, ``, +`iv_size`, `max_iv_size`, `max_additional_data_size` and `error::invalid_iv_size` (D11); +`ciphers::aead`, `musig::nonce_gen`, `pubkey_tweak_add`, `pubkey_tweak_mul`, `pubkey_negate`, +`pubkey_combine`, `seckey_tweak_add`, `seckey_tweak_mul`, `seckey_negate`, `prevouts_summary` and +`make_prevouts_summary` (D12). No public +`crypto::wipe` ever exists (D10). Every caller in libs/crypto moves +in the same change: tests, examples, fixtures, the page, the constant-time harnesses and suppressions, the +benches, the message tests, the MSVC tests, `doc/tables/crypto.json` and its generated files +(rerun, never edited); `crypto::equal`'s callers in other libraries (webcpp::hash) move in the +same change, through the superproject's pointers. webcpp::trystero's port of Trystero 0.27 moves +later, by its own stream (decisions 11 and 13). The X25519 format functions keep their names here and leave with the +formats change, which gives them the typed keys' formats. + +## Rulings + +- **R1 (owner decision 6): `verify` takes the typed signature only; no bytes overload.** A signature from the wire is + made first (`p256::ecdsa_signature::from_bytes(bytes)` or `crypto::from_bytes(bytes)`), where its size is + checked; then the type says its curve and scheme, and a mismatch is a compile-time error rather + than an `invalid_signature` at run time. One form keeps the four mirrored forms one, and matches + crypto/sign-unified's R17 for public keys. BIP340's x-only key bytes keep their `verify` overload: + that is a key, not a signature. +- **R2: a signature's `from_bytes` checks the size only** (D1), so that a high-S or out-of-range + signature from a peer can still be made, normalized and refused by `verify` with the policy of + its curve. +- **R3: an X25519 public key's `from_bytes` checks the size only** (D2), as Ed25519's does; small order + is `agree`'s refusal, `weak_public_key`, where RFC 7748 puts it. +- **R4: conversions and value construction are synchronous only, member and free**: `from_bytes` of a + signature or a public key and `to_x25519` call no backend that WebCrypto could replace (WebCrypto + converts nothing between Ed25519 and X25519), so "four mirrored forms" applies to the operations + that call a backend (`from_secret` and `generate` of a key pair, `from_key` of a cipher, `sign`, `verify`, `agree`, `seal`, + `open`), as crypto/sign-unified's D9 table lists them. +- **R5 (owner decision 7): the seeded derivation is `kx_keypair::derive_from_seed(seed)`**, never a + factory named after another input, so that the call site says a seed is hashed (D3). +- **R6: sealed boxes stay out of the concepts** (Non-goals) but take typed keys (D3). +- **R10: P-256's public key from coordinates is `from_coordinates(x, y)`**, not a second + `from_bytes` overload, so that the name says the input is two coordinates (a COSE key's), not an + encoded point. +- **R11: crypto_box is made by `from_keys(own_keypair, peer_public_key)`**: two keys, the plural + name says so, and neither is "the" secret alone. +- **R12: kx wraps a key pair by `from_keypair(x25519_keypair)`**: its input is a key pair, not + secret bytes, so `from_secret` would misname it; a kx key pair from raw secret bytes is + `from_keypair(*x25519::keypair::from_secret(bytes))`. +- **R13: the free factories' header is ``** (was `make.hpp`). +- R8 and R9 were not assigned; the numbers are kept so that R10 to R13 keep the names other + documents use. +- **R14 (superseded by owner decision 12): Ed25519ph's signature is `curves::ed25519::signature`**. + The first draft ruled a sixth type, `ph_signature`; Ed25519ph is now the scheme + `eddsa_prehashed` (D9), whose signature is Ed25519's 64-byte type, so no `ph_signature` exists, + and an Ed25519ph signature given to the pure `verify` fails at run time with + `invalid_signature` (D9's last point). +- **R15: `to_der`, `from_der`, `normalize_low_s` and `is_low_s` take and give the curve's + `ecdsa_signature`** on P-256 and secp256k1, so that no function takes a signature as bytes; the + formats change builds on typed values. +- **R16: X25519's `algorithm` becomes `detail::x25519_operations`**, the unguarded workers + (`base`, `agree`) the key pair and the asynchronous family share (D2). +- **R17: no function is named `make`, a detail engine's included** (`import_secret`, + `seed_keypair`, `allocate`); decision 9's "internal capabilities keep their names" means the + capability table's rows (`*_import`, `*_generate`), which are not functions. +- **R18: `ecdsa_keccak256_recoverable` has `recover` and no `verify`**, mirroring + `ecdsa_sha256_recoverable` (D8). +- **R19: Keccak-256's message form needs XKCP linked**; without it, "webcpp::crypto: + crypto::ecdsa_keccak256_recoverable hashes a message with webcpp::hash's keccak_256, which needs + XKCP: add /third_party//xkcp to the program's Jamfile, or sign crypto::prehashed{digest}." (D8). +- **R20: both recoverable schemes give `secp256k1::recoverable_signature`** (the owner's + ruling): a signature recovered under the other scheme gives another key, which the program's + comparison of keys or addresses refuses. +- **R7 (amended by owner decision 13): the AEAD concepts live in + ``** (was ``), beside the + free AEAD forms, which `ciphers/aead.hpp` and `ciphers/gcm.hpp` include; it includes no backend. +- **R21 (the coordinator's refinement of decision 13, 2026-11-23): `authenticated_box` is + `crypto::secret_key_encryption::authenticated_box`**, beside the secret box, in + `` (no backend), which + `secret_key_encryption/secretbox.hpp` and `public_key_encryption/box.hpp` include; its box forms + follow it: `secret_key_encryption::seal(box, nonce, data)`, `open(box, nonce, data, tag)`, + `async_seal` and `async_open`, for a secret box and a crypto_box alike (argument-dependent lookup + finds them for a secret box; a crypto_box is sealed by `secret_key_encryption::seal` named in + full, or by its member). No free `seal` or `open` exists in `crypto::` nor in + `public_key_encryption`. +- **R22: decision 13's rule covers every public name, not only parameters**: the members + `iv_size`, `max_iv_size` and `max_additional_data_size`, which the concepts require, become + `nonce_size`, `max_nonce_size` and `max_associated_data_size`, and the error + `invalid_iv_size` becomes `invalid_nonce_size` (its value 2 kept), so that a nonce is never + called an IV in one name and a nonce in the next; `max_` stays, the standard library's own word + (`std::numeric_limits::max`, `max_size`). Accepted by the coordinator on 2026-11-23; X4 does it. +- **R23 (controller ruling, 2026-11-23): 3.2 and 3.3 are written with decision 13's names; X4 + covers the renames they do not touch.** 3.2 creates `secret_key_encryption/aead.hpp` and + `secret_key_encryption/authenticated_box.hpp`, moves the free `crypto::seal`/`open` into + `secret_key_encryption::aead` and `ciphers::secretbox` into `secret_key_encryption` (header + `secret_key_encryption/secretbox.hpp`), and migrates their callers; 3.3 moves the free + `crypto::async_seal`/`async_open` into `secret_key_encryption::aead` and migrates theirs. X4, + which runs before 2.2, renames what stays where it is: `iv` and `additional_data` on the existing + members, free forms and engines, `nonce_size`, `max_nonce_size`, `max_associated_data_size`, + `error::invalid_nonce_size`, `aux_random`, any other abbreviation, every call site of those names, + and the CODING-GUIDELINES rule; so the names 3.2 and 3.3 move already carry the renames. +- **R24: decision 14's "any other public abbreviation of the same kind" is silent payments' + `prevouts`** (the amendment's reading, for the owner to confirm): libsecp256k1 names BIP352's + summary of the previous outputs `prevouts_summary`, and crypto took the name for its type and its + factory, so they become `previous_outputs_summary` and `make_previous_outputs_summary` (the verb + kept: R17 forbids a function named `make` alone, and this one says what it makes). A survey of + every public name in `include/webcpp/crypto` (outside `detail` and the backends) found no other: + `outpoint` is Bitcoin's own term, `xdh` (`ellswift_xdh`) RFC 7748's and BIP324's, `xonly` + BIP340's, and MuSig2's other names were spelled out when built (`key_aggregate`, + `nonce_aggregate`, `partial_signature`). +- **R25: decision 14 renames names, not headers or helpers without an abbreviation**: the template + stays in ``, which `ciphers/chacha20_poly1305.hpp` includes and + which also holds the AEAD families (a program includes the aliases' header, so no include + moves); the workspace helpers (`combine_workspace_size` for `public_key_combine`, MuSig2's + `workspace_size`, silent payments' three) carry no abbreviation and keep their names; the message + tests and fixture named `aead_not_a_family*` keep their directory names (as P29), their code and + texts following the class. + +## As built + +Built on the branches `crypto/uniform-types` (crypto `e07d44a`, hash `659e50d`, superproject +`0ab0ace`). The rulings made while building that change or refine the design above: + +- **P27, Ed25519ph on libsodium's internals (D9):** `sign(eddsa_prehashed, ...)` and its `verify` + call libsodium's `_crypto_sign_ed25519_detached` and `_crypto_sign_ed25519_verify_detached` with + `prehashed` 1, since its public API cannot sign a finished digest; they link because libsodium is + built from source. A rename upstream or a prebuilt libsodium breaks it, and RFC 8032's Ed25519ph + vectors then fail at once. No other shipped backend implements Ed25519 (`backends/openssl.hpp` + has none; the family's default is libsodium on every target), so no public path exists yet. +- **`check_signature` takes three arguments (D1, R1):** `detail::check_signature`, `Verifier` the scheme tag or `ed25519ph_verifier_t` (the streaming + signer's `verify`), beside `checked_signature_bytes`: a signature of another type stops the + build with one message, and Ed25519ph's shared `ed25519::signature` has its explicit branch. +- **`can_verify` takes the signature (D1, P7, F8):** `can_verify`, true only for the type of the key's curve and scheme (the spec amended); internal + input checks call `detail::input_valid_v`, never `!can_verify`. +- **Signatures (D1, P6):** the default constructor stays non-explicit (all zeros, `std::regular`), + so `verify(scheme, {}, input, key)` compiles and fails; `recovery_id()` gives the stored byte and + `recover` refuses an id above 3. +- **Guards of `from_bytes` (D3c, P19, F12):** the free `crypto::from_bytes` holds no guard + (`from_secret` and `from_key` keep theirs); P-256's and secp256k1's public keys' `from_bytes` and + `from_coordinates` validate the point through the backend and hold it; the signatures', Ed25519's + and X25519's public keys' `from_bytes` enter none. R4's "call no backend" is read accordingly. +- **`detail::x25519_access::keyed` (D2, D3, P13):** reads, without a guard, whether an X25519 key + pair was moved from, so kx, the boxes and the sealed box refuse one with `invalid_state` before + reading its zeroed bytes. +- **`detail::kx_engine_defined` (D3):** derived from the capability table (supported and linked), + not written by hand; it relies on `kx.hpp`'s tail include and one kx backend, which its comment + says. The boxes and kx are refused by `supports_v`, and libsodium's sections + for them key on `WEBCPP_CRYPTO_DETAIL_{BOX,SEALED_BOX,KX}_DECLARED`, breaking the include cycle + through `curves/x25519.hpp` as the formats headers do. +- **Key pair concepts (D4):** the free `crypto::sign` lives in `keypair.hpp`; `async_agree` is one + template over the key pair (`detail::agrees_with_peer`); Ed25519's unreachable `agree` clause is + gone, `agreement_keypair` refusing first. +- **D6's text covers the synchronous forms:** on an asynchronous backend, ChaCha20-Poly1305, + XChaCha20-Poly1305, secretbox and crypto_box refuse their synchronous `seal`, `open` and + `from_key(s)` too, with D6's text (no form of the constructions WebCrypto lacks runs on the + browser's backend), through `detail::refuse_aead_on_asynchronous_backend`; AES-GCM's synchronous + forms keep "call async_seal". +- **The timing seam matches every qualifier:** the test seam that ties a timing guard to the + function a coverage check names compares every component of the label, not only the last, so the + member `ciphers::basic_chacha20_poly1305::seal` and the free `secret_key_encryption::aead::seal` + are told apart; it also reads GCC's spelling of a trailing requires-clause. +- **The browser's draw (X1, F3, P15):** `EM_ASM_INT` inside the inline `read_entropy`, never an + `EM_JS` in a header; a throwing `getRandomValues` is `entropy_unavailable`, and its JavaScript + array is zeroed after the copy and after a throw. +- **node 18's WebCrypto (X1):** without `globalThis.crypto`, the draw falls back to + `require('node:crypto').webcrypto` inside the same `try` (Emscripten's minimum is node 18.3), + superseding P15's cost; a bundler that cannot resolve it fails closed as `entropy_unavailable`. +- **The probe before `sodium_init` (X1b), superseding F4's consequence:** on Emscripten, + `sodium_ready` draws a small probe through crypto's entropy before `sodium_init`; a failed probe + returns its error and leaves libsodium uninitialised, so the next call retries and no zero + `sodium_malloc` canary is kept. The watch around `sodium_init` stays for a good probe followed by + a failing canary draw (a zero canary then, documented). The stack copies of each draw are wiped. +- **The native draw watch is a stateless stub (X1b):** a `thread_local` state allocated on macOS + at first access, which `allocation_sodium` counts; the watched state exists on Emscripten only. +- **`generate.py`'s message rows:** the messages page lists every text a message test pins, each + once, in the source's order, and leaves out a directive marked `(knock-on)`, so that each row + leads with the refusal, not with an error that follows from it. +- **Removed-name message tests (3.2, X5):** a using-declaration and a call per group, since + clang's typo correction differs by version; `ciphers::aead`'s removal is pinned through an alias + (`aead_template_removed_call`). +- **The C4459 test rename (4.2):** MSVC flagged two tests' globals, `associated_data` and + `secret_key`, which a library template's parameter names hide; the tests' names changed + (`test_associated_data`, `secret_key_hex`), not the parameter, which decision 13 fixes. +- **X3's survey** renamed one-word locals and parameters only; static data members (`name`, + `size`, `order`, `overhead`) keep their names, which C4459 does not concern. + +## Risks / Trade-offs + +- Every signing caller changes its result type; the migration is mechanical (`.bytes()` where bytes + were used) and the build finds every site. +- Programs that verify wire signatures gain a `from_bytes` call (R1). +- Every `make` in libs/crypto and its users is renamed (D3c); the build finds each site. +- Async seal and open on native backends add instantiations only where called. + +## Migration Plan + +crypto/sign-unified merges; then this change; then crypto's formats; then phase 3 of webcpp::trystero's port of +Trystero 0.27. Branches `crypto/uniform-types` of webcpporg/crypto, webcpporg/proposals and the +superproject; local verification on every lane; merged by the controller; one CI at the end. + +## Open Questions + +None: the owner's decisions 1 to 14 settle the change (R21 to R23 settle how decision 13 is +built, R24 and R25 read decision 14 where it is silent). diff --git a/libraries/crypto/openspec/changes/uniform-types/proposal.md b/libraries/crypto/openspec/changes/uniform-types/proposal.md new file mode 100644 index 0000000..28b2115 --- /dev/null +++ b/libraries/crypto/openspec/changes/uniform-types/proposal.md @@ -0,0 +1,121 @@ +## Why + +crypto/sign-unified gave every curve typed public keys, one key pair contract and one name per +operation, but three kinds of value are still bare bytes or ad hoc shapes: + +- **Signatures** are `std::array` (65 for a recoverable one) on every curve and + scheme, and `verify` takes any `std::span`: a P-256 signature passed to + secp256k1, or an Ed25519 signature given to a DER encoder, is a run-time failure at best, and the + formats change (`libraries/crypto/openspec/changes/formats/`) cannot refuse `der` on Ed25519 or + know an ECDSA signature's curve. +- **X25519** has no types at all: its public key is `std::array`, its secret a + `secret<32>`, its operations free functions (`curves::x25519::public_key(secret)`, + `curves::x25519::agree(secret, peer)`), while Ed25519, P-256 and secp256k1 have key pairs with + `make`, `generate`, `public_key()`, `secret()` and `agree`. crypto_kx, the boxes and Ed25519's + conversion (`x25519_secret()`, `to_x25519_public`) pass the same raw bytes. +- **Contracts**: the one concept `crypto::keypair` requires `sign`, which an X25519 key pair has + not; the AEADs and boxes share a shape that no concept states, and secretbox carries additional + data it refuses (a "fake" parameter that must be empty). + +On 2026-11-22 the owner decided to type all three in one small change merged before formats. + +## What Changes + +- **Typed signatures**: `ed25519::signature`, `p256::ecdsa_signature`, + `secp256k1::ecdsa_signature`, `secp256k1::recoverable_signature`, + `secp256k1::schnorr_signature`, each made by `from_bytes(bytes)` (its size checked) and giving + `bytes()`; every `sign` returns one, and every `verify` and `recover` takes one, synchronous and + asynchronous, member and free. The bytes overload of crypto/sign-unified (`verify` taking any + span and checking its size) is replaced: a signature from the wire is made first. +- **X25519 typed like the others**: `x25519::public_key` (`from_bytes`, `bytes()`), + `x25519::basic_keypair` (`from_secret`, `generate`, `public_key()`, `secret()`, `agree(peer)`, + `async_agree`, free `crypto::agree` and `crypto::async_agree`); `kx_keypair` built on it; the + boxes take typed keys. The free `curves::x25519::public_key(secret)` and `agree(secret, peer)` + are removed. +- **Ed25519 to X25519 as a typed conversion**: `ed_key.to_x25519()` gives an + `x25519::basic_keypair`, `ed_public_key.to_x25519()` an `x25519::public_key`, with the free + `crypto::to_x25519`; `x25519_secret()` and `curves::ed25519::to_x25519_public` are removed. +- **Three key pair concepts**: `crypto::keypair` (`from_secret`, `generate`, `public_key()`, `secret()`), + `crypto::signing_keypair` (also `sign` for each scheme it declares, at least one) and + `crypto::agreement_keypair` (also `agree`). Ed25519 signs; P-256 and secp256k1 sign and agree; + X25519 agrees. +- **AEAD and box concepts**: `secret_key_encryption::aead::cipher` (sizes, `result_type`, + `from_key(key)`, `seal(nonce, associated_data, data)`, `open(nonce, associated_data, data, tag)`), + its refinement `secret_key_encryption::aead::streaming_cipher` (AES-GCM's incremental seal and + open), and the sibling `secret_key_encryption::authenticated_box` (`seal(nonce, data)`, `open(nonce, data, tag)`) + for secretbox and crypto_box, which lose the additional data they refused. The free + `secret_key_encryption::aead::seal`, `open` and their asynchronous forms, and the box forms, are + constrained by them, and `async_seal` and `async_open` extend to every AEAD and box on native + backends; the browser backend keeps WebCrypto's AES-GCM only, refusing the others with a clear + message. +- **Secret-key encryption and spelled-out names** (owner decision 13, 2026-11-23): the AEAD + contract lives in `crypto::secret_key_encryption::aead` + (``), and the free `seal`, `open`, `async_seal` + and `async_open` move there from `crypto::`; secretbox moves from `crypto::ciphers` to + `crypto::secret_key_encryption` (``), beside + `public_key_encryption::box`; the algorithm types stay in `crypto::ciphers`; every public name is + spelled out, algorithm proper names excepted (`nonce`, `associated_data`, `nonce_size`, + `invalid_nonce_size`); no alias; webcpp::trystero migrates later. +- **The ChaCha20-Poly1305 template and libsecp256k1's abbreviations** (owner decision 14, + 2026-11-23): `ciphers::aead` becomes `ciphers::basic_chacha20_poly1305`, the + aliases keeping their names; secp256k1's `pubkey_*` and `seckey_*` tweaks become `public_key_*` + and `secret_key_*`, MuSig2's `nonce_gen` becomes `generate_nonce`, and silent payments' + `prevouts_summary` becomes `previous_outputs_summary`; `agree`, `agree_hashed` and `agree_point` + stay; no alias. +- **Constructions grouped by purpose**: the namespace `crypto::hybrid` is removed; + `crypto::public_key_encryption` holds `basic_box`, `box`, `box_xchacha20poly1305`, + `basic_sealed_box` and `sealed_box` (``, + `sealed_box.hpp`), and `crypto::key_exchange` holds `kx_keypair` and `session_keys`, out of + `curves::x25519` (``); no alias. "Hybrid" now names + post-quantum hybrids (X25519MLKEM768, X-Wing), which keep `crypto::hybrid` free; a future HPKE + goes to `public_key_encryption`. +- **Factories named by their input**, `make` removed with no alias: `K::from_secret(bytes)` and + `K::generate()` for key pairs, `T::from_bytes(bytes)` for public keys and signatures (P-256 also + `from_coordinates(x, y)`), `C::from_key(key)` for ciphers, AEADs and secretbox, crypto_box's + `from_keys(own, peer)`, kx's `from_keypair(x25519_keypair)` and `derive_from_seed(seed)`; free + `crypto::from_secret`, `crypto::from_bytes`, `crypto::from_key`, `crypto::generate`, + and `async_from_secret`, `async_from_key`, `async_generate`. `make` read as "make a key": a + caller who passed fixed bytes believing a key was drawn got a predictable private key. +- **Ed25519ph as a scheme** (owner decision 12, 2026-11-23): `crypto::eddsa_prehashed` in the one + list of schemes, which Ed25519's signing key pair declares, taking `crypto::prehashed{digest}` of + 64 bytes (the message's SHA-512) and refusing a message at compile time, giving + `ed25519::signature`, with `verify(eddsa_prehashed, signature, prehashed, public_key)` and the + member form, asynchronous on native backends only; the streaming `curves::ed25519::ph` + is renamed `curves::ed25519::prehashed_signer`, no alias, and no distinct Ed25519ph + signature type exists. +- **Secret hygiene named by what it does** (owner decision 11, 2026-11-23): `crypto::equal` becomes + `crypto::constant_time_equal` (``), no alias, every caller + moved, webcpp::hash's included; the public wipe is `crypto::erase_secret` + (``); the guide groups them with `secret` and + `random_device` in one section about protecting secrets outside the primitives. +- **Four mirrored forms** for every new operation that calls a backend. + +## Capabilities + +### New Capabilities + +None. + +### Modified Capabilities + +- `crypto`: every signature and every X25519 key has a type of its own; key pairs, AEADs and boxes + are checked by concepts; the AEAD contract and secretbox are `secret_key_encryption`'s; public + names are spelled out; secretbox and crypto_box take no associated data; seal and open are + asynchronous on every native backend. + +## Impact + +- **Kind:** a wrapper (`"port-of": null`), as the genesis. +- **Breaking:** yes, before the first release. Order: crypto/sign-unified merges; then this change; + then crypto's formats; then phase 3 of + webcpp::trystero's port of Trystero 0.27, which adapts to both. +- **Implementation:** webcpporg/crypto (`signing.hpp`, `keypair.hpp`, `curves/*.hpp`, + `key_exchange/kx.hpp` (was `curves/x25519/kx.hpp`), `ciphers/*.hpp`, + `public_key_encryption/*.hpp` (was `hybrid/*.hpp`), `secret_key_encryption/aead.hpp` (new: the + AEAD contract) and `secret_key_encryption/secretbox.hpp` (was `ciphers/secretbox.hpp`), `secret_key_encryption/authenticated_box.hpp` (new), `async.hpp`, tests, examples, benches, the constant-time lane, `doc/`, `doc/tables/crypto.json` and + the generated files), webcpporg/hash (the callers of `crypto::equal` in its examples, headers' + comments and pages), the superproject's pointers. +- **Status:** approved by the owner on 2026-11-22 (`decided`); `implementing` since 2026-11-24: + built on the branches `crypto/uniform-types` of webcpporg/crypto (head `e07d44a`), + webcpporg/hash (`659e50d`) and the superproject (`0ab0ace`), verified locally on every lane + (`tasks.md`, 4.2); the pull requests, their merges and the CI on GitHub remain. diff --git a/libraries/crypto/openspec/changes/uniform-types/reference/plan.md b/libraries/crypto/openspec/changes/uniform-types/reference/plan.md new file mode 100644 index 0000000..63d8830 --- /dev/null +++ b/libraries/crypto/openspec/changes/uniform-types/reference/plan.md @@ -0,0 +1,619 @@ +# Uniform types Implementation Plan + +> **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. + +**Goal:** Every signature and every X25519 key of webcpp::crypto has a type of its own; Ethereum's recoverable ECDSA and Ed25519ph (`eddsa_prehashed`) are schemes; key pairs, AEADs and boxes are checked by concepts; constructions are grouped by purpose; every fallible factory is named by its input; plus three small fixes (a throwing `getRandomValues` in the browser, a public `crypto::erase_secret` with `crypto::equal` renamed `crypto::constant_time_equal`, no one-word local in a header); the AEAD contract in `crypto::secret_key_encryption::aead` with secretbox beside it in `crypto::secret_key_encryption`, and every public name spelled out (owner decision 13), the one-shot ChaCha20-Poly1305 template named `ciphers::basic_chacha20_poly1305` and the names taken from libsecp256k1 spelled out (owner decision 14). + +**Architecture:** One class template `detail::basic_signature` (new `detail/signature.hpp`) gives the five signature types by tag (Ed25519ph's scheme `eddsa_prehashed` gives `ed25519::signature`, owner decision 12); the trait `detail::signature_of` pairs a key with its signature type, and every `verify` overload takes `Signature const&` and checks it with a `static_assert` that names the type expected. `curves/x25519.hpp` gains `public_key` and `basic_keypair`; `key_exchange/kx.hpp`, `public_key_encryption/box.hpp` and `sealed_box.hpp` (moved from `curves/x25519/` and `hybrid/`) take them. `keypair.hpp` splits the contract into `keypair`, `signing_keypair`, `agreement_keypair`; `secret_key_encryption/aead.hpp` holds the AEAD contract, `secret_key_encryption::aead::cipher`, `streaming_cipher` and the free `seal`/`open` (3.2 creates it and moves the free forms there, 3.3 the asynchronous ones), and `secret_key_encryption/authenticated_box.hpp` the box concept `secret_key_encryption::authenticated_box` and the box forms; `factories.hpp` (was `make.hpp`) holds `from_secret`, `from_bytes`, `from_key`, `generate`. `async.hpp` defines every asynchronous member, as on crypto/sign-unified. Every caller of a removed name moves in the task that removes it (design D7), so libs/crypto builds and its tests pass at the end of every task. + +**Tech Stack:** C++20, header-only, b2 (`webcpp.run`, `webcpp.compile-diagnostic`, `webcpp.headers-alone`), BearSSL, libsodium, libsecp256k1, OpenSSL, ctaes, webcpp::hash, webcpp::asio; Emscripten's `EM_JS`. + +**Spec:** `libraries/crypto/openspec/changes/uniform-types/` in webcpporg/proposals (proposal.md; design.md with owner decisions 1-14, D1-D12, R1-R25; specs/crypto/spec.md; tasks.md). Binding; read design.md D1, D3c, D5, D11 and D12 before any task. + +**Order, and why:** X3, 2.5, 2.4, X2, 1.1, 1.2, 1.3, 1.4, 2.1, X4, 2.2, 2.3, 3.1, 3.2, 3.3, X1, X1b, X5, 4.1, 4.2. +- X3 first (the controller's ruling): mechanical, so every later task writes its code with the new local names. +- 2.5 (factories) second, before any task creates a type: the signature types, X25519's key pair and kx's factories are then born with their final names (`from_bytes`, `from_secret`, `from_keypair`, `derive_from_seed`) instead of a `make` that a later task renames across ~250 files a second time, and 3.1's concept can require `from_secret` without a migration of its own. The cost: 2.5 renames crypto_box's byte factory to `from_keys(secret_bytes, peer_bytes)`, which 2.2 retypes (about ten call sites edited twice). +- 2.4 (namespaces) third, also mechanical, so that 2.2 edits the moved files once. +- X2 (owner decision 11: `erase_secret`, and `equal` renamed `constant_time_equal` across libs/crypto, libs/hash and the fixtures) right after the mechanical renames and before any task writes a new test, so that every later test compares with `constant_time_equal` and none is migrated twice; 1.1-1.2 next (no dependency on X25519); 1.3 (owner decision 10) right after 1.2, whose typed `recoverable_signature` it returns; 1.4 (owner decision 12) right after 1.3: it adds a scheme to the list 1.3 has just grown and signs into the `ed25519::signature` 1.2 returns, and it precedes 3.1, whose `signing_keypair` folds over every scheme Ed25519 declares; 2.1 before 2.2 and 2.3 (both need the X25519 types); 3.1 needs every key pair typed; 3.2 before 3.3; X1 and X1b are independent, placed before 4.1 so that the page and the changelog see them; X1b after X1, whose entropy path it reuses. +- X4 (owner decision 13, recorded 2026-11-23 after 2.1 was built; the controller's ruling, P30, R23) right after 2.1 and before every task still to come: it spells the public names out where they are (`nonce`, `associated_data`, `nonce_size`, `invalid_nonce_size`); 3.2 and 3.3 then move the AEAD forms and secretbox into `secret_key_encryption`, written with decision 13's names, so that nothing is renamed twice. +- X5 (owner decision 14, recorded 2026-11-23 after X1 was built; the controller's ruling, P33) after X1b and before 4.1: every name it renames is built by then, and 4.1's pages, tables and changelog are written once with the final names; its first commit rewords D6's refusal, a minor carried from 3.3's review. + +**Build and test:** from the superproject worktree, `b2 --user-config=/Users/you/dev/webcpporg/webcpp/.local/user-config.jam -j10 toolset=clang ` (written `b2 ... toolset=clang` below), targets as `libs/crypto/test//x25519_sodium`, `libs/crypto/test/messages//make_removed`, `libs/crypto/example//kx_session`. A whole-directory build (`libs/crypto/test libs/crypto/example libs/crypto/bench`) and any gcc, Emscripten or MSVC run go through `/Users/you/dev/webcpporg/heavy.sh crypto-types`. Emscripten: `EM_CACHE=/Users/you/dev/webcpp/.local/emscripten-cache b2 ... toolset=emscripten`. Generated files: `python3 libs/crypto/doc/tables/generate.py`, then `--check` (exit 0) and `python3 libs/crypto/doc/tables/generate_test.py`. Fixtures: `python3 tools/test/crypto_jamfiles_test.py ... [--target native]`. + +**Superproject touch points** (separate superproject commits, listed per task): `tools/test/fixtures/crypto_jamfiles/*` (2.5, 2.4, X2, 1.2, 1.4, 2.1, X4, 2.2, 2.3, 3.2, X5), `CODING-GUIDELINES.md` crypto chapter (X2's current rules naming `equal`; X4's naming rule, also in hash's chapter, and the incremental seal's bullet; X5's sentence in the naming rule; 4.1), the `libs/hash` pointer (X2), the `libs/crypto` pointer (4.2). Increment 1's dated record in CODING-GUIDELINES.md (around line 8753, "`hybrid::box` and `sealed_box`") keeps the names of its time. + +## Global Constraints + +- Worktree `/Users/you/dev/webcpporg/crypto-types/webcpp` (superproject, branch `crypto/uniform-types` from d53bf53); `libs/crypto` on branch `crypto/uniform-types` from 0255206; `libs/hash` on branch `crypto/uniform-types` from 3af42a2 (X2 only). Commit in `libs/crypto` unless a task says superproject or hash. +- Read `libs/crypto/AGENTS.md`, the superproject's `AGENTS.md` and `CODING-GUIDELINES.md` (crypto chapter) first: doc comments, `[[nodiscard]]`, `noexcept`, include order, the timing guard rule, generated files, message tests (`fixes` in `crypto.json` in the same commit). +- English only. Never the em dash character; a plain "-". Commit messages `crypto: `, no trailer of any kind. +- Never edit a generated file (`doc/generated/*`, `doc/llms.txt`, `detail/capabilities.hpp`, `detail/defaults.hpp`, `test/capabilities_test.cpp`, the defaults' aliases in `build.jam`) nor `CHANGELOG.md`, `doc/tables/sizes.json`, `doc/performance.json`; the changelog is `doc/changelog.adoc`'s unreleased list (10 lines at most, 30 words each), edited in 4.1 only. +- Removed with no alias, shim or deprecation (D7, D3c): every `make`/`async_make` (member and free) and `make.hpp`; `curves::x25519::public_key(secret)`, `curves::x25519::agree(secret, peer)`, the byte-key `async_agree`; `x25519_secret()`, `to_x25519_public`; `crypto::hybrid`, `hybrid/box.hpp`, `hybrid/sealed_box.hpp`, `curves/x25519/kx.hpp`, `curves::x25519::kx_keypair`, `session_keys`; every `verify`/`recover` taking a signature as bytes; `sign`'s array results; secretbox's additional data and its `ciphers::aead` aliases; `crypto::equal` (both overloads) and ``, now `crypto::constant_time_equal` in `` (X2); `curves::ed25519::ph`, now `curves::ed25519::prehashed_signer` (1.4); the free `crypto::seal`, `crypto::open`, `crypto::async_seal`, `crypto::async_open` (now `secret_key_encryption::aead`'s), `ciphers::secretbox`, `ciphers::secretbox_xchacha20poly1305` and `ciphers/secretbox.hpp` (now `secret_key_encryption`'s; 3.2, 3.3), `iv_size`, `max_iv_size`, `max_additional_data_size`, `error::invalid_iv_size` and every public parameter named `iv`, `additional_data` or `aux_random` (X4); `ciphers::aead` (now `ciphers::basic_chacha20_poly1305`), `musig::nonce_gen`, `pubkey_tweak_add`, `pubkey_tweak_mul`, `pubkey_negate`, `pubkey_combine`, `seckey_tweak_add`, `seckey_tweak_mul`, `seckey_negate`, `silent_payments::prevouts_summary` and `make_prevouts_summary` (X5, owner decision 14). Never created: `crypto::aead`, `crypto::streaming_aead`, `` (the concepts are `secret_key_encryption::aead::cipher` and `streaming_cipher`, owner decision 13). Never created: a public `crypto::wipe` (the public wipe is `crypto::erase_secret`; `detail::wipe` stays the internal primitive) and a distinct Ed25519ph signature type (`ph_signature`): both are named only in this plan's history. +- A public function that calls a backend holds `detail::timing_guard const timing_scope;` (X3's name) first and joins `test/timing_coverage__test.cpp`; one that calls none (a signature's `from_bytes` and `bytes()`, Ed25519's and X25519's public keys' `from_bytes`, the free `crypto::from_bytes`, X25519's `public_key()` and `secret()`, `crypto::erase_secret`) is checked to enter none; P-256's and secp256k1's public keys' `from_bytes` (and P-256's `from_coordinates`) validate the point through the backend and hold the guard; `crypto::constant_time_equal` calls no backend but keeps its guard (DIT around a secret comparison). +- On a backend whose `detail::asynchronous_backend_v` is true every synchronous member refuses with "webcpp::crypto: on this backend completes asynchronously: call async_." (as P-256's do). +- A flaky or failing test or a lint warning seen on the way is fixed or reported to the controller, never skipped. + +## Review Focus + +1. A signature of the wrong length from the wire: 63 and 65 bytes (64 and 66 for the recoverable type) give `invalid_signature` from `from_bytes` on all five types, and nothing reaches a backend (Task 1.1, `signature_from_wire`). +2. A moved-from X25519 key pair: `public_key()`, `secret()`, `agree` return `invalid_state`, and the source's secret storage reads zero (Task 2.1, `moved_from`). +3. A failed `open` of a secret box or a crypto_box zeroes `data`; a guard's refusal (a 12-byte nonce) leaves it untouched (Task 3.2 and 2.2, `open_failures`). +4. `async_seal`/`async_open` of every new AEAD and box on a synchronous backend never complete inside the initiating call (Task 3.3, `never_inline`). +5. A throwing `crypto.getRandomValues` gives `entropy_unavailable` with the output zeroed, and a missing `crypto` object `not_supported`, never a terminated page (Task X1). + +--- + +### Task X3: No one-word local in a header (MSVC C4459) + +crypto-sign's handback: a program global named like a header's local (`timing`, `executor`, `token`, `state`) trips C4459, an error at /W4 /WX. There is no existing "hides no user name" test: 48ca7ef renamed `make.hpp`'s parameters and a200e69 moved a test's global into a local. This task creates the test. + +**Files:** +- Modify: every header under `libs/crypto/include/webcpp/crypto/` (backends/, detail/, curves/, ciphers/, hybrid/, root), except the generated `detail/capabilities.hpp` and `detail/defaults.hpp` (if they hold a one-word local, change `doc/tables/generate.py` and regenerate). +- Create: `libs/crypto/test/user_globals_test.cpp`; `test/Jamfile`: `crypto-run user_globals : user_globals_test.cpp : /third_party//bearssl /third_party//ctaes /third_party//secp256k1 /third_party//sodium /webcpp/crypto//openssl /webcpp/asio//asio : native ;` + +- [ ] **Step 1: Survey the names.** An aggregate translation unit of every public header, its AST dumped, every `ParmVarDecl`, `VarDecl` and `BindingDecl` inside a function of `libs/crypto/include` whose name matches `^[a-z][a-z0-9]*$`: + +```sh +cd /Users/you/dev/webcpporg/crypto-types/webcpp +(cd libs/crypto/include && find webcpp -name '*.hpp' | sort | sed 's/.*/#include <&>/'; echo 'int main() {}') > /tmp/all.cpp +clang++ -std=c++20 -fsyntax-only -Xclang -ast-dump $INCLUDES \ + -DWEBCPP_CRYPTO_HAS_BEARSSL=1 -DWEBCPP_CRYPTO_HAS_SECP256K1=1 -DWEBCPP_CRYPTO_HAS_SODIUM=1 \ + -DWEBCPP_CRYPTO_HAS_CTAES=1 -DWEBCPP_CRYPTO_HAS_OPENSSL=1 -DWEBCPP_CRYPTO_HAS_THREADS=1 /tmp/all.cpp > /tmp/ast.txt +python3 - /tmp/ast.txt <<'EOF' +import re, sys, collections +here, seen = None, collections.Counter() +for line in open(sys.argv[1], errors='replace'): + m = re.search(r'[<, ]([\w./-]+\.(?:hpp|h)):\d+:\d+', line) + if m: here = m.group(1) + d = re.search(r'(ParmVarDecl|VarDecl|BindingDecl) 0x\w+ <[^>]*> \S+(?: used| referenced)* ([a-z][a-z0-9]*) ', line) + if d and here and 'libs/crypto/include/' in here: seen[d.group(2)] += 1 +for name, count in seen.most_common(): print(count, name) +EOF +``` + +`$INCLUDES` is `-I` of `libs/*/include`, the third-party include directories (BearSSL `inc`, libsecp256k1 `include`, libsodium `src/libsodium/include`, ctaes, OpenSSL's) and Boost. Drop namespace-scope variables (`eddsa`, `schnorr`, `strict`, the generated tables' `supported`, `linked`) and names the location tracking attributes to std's algorithms. The survey on 0255206 found (count): timing 162, executor 39, token 33, out 26, keyed 19, s 18, ready 14, signature 14, key 13, scheme 11, message 10, data 9, work 9, c 9, size 8, encrypt 8, decrypt 8, iv 8, tag 8, output 8, other 8, handler 8, borrow 7, i 7, text 7, input 7, der 6, label 6, prefix 6, allocator 6, code 6, state 5, decoded 5, at 5, begun 5, run 5, count 4, expected 4, name 4, half 4, characters 4, bytes 4, seed 4, done 4, and some 70 names of 1 to 3 uses (verdict, order, sealed, held, policy, nonce, digest, peer, scalar, point, receive, transmit, beforenm, spki, pkcs8, piece, agreed, opened, guard, job, ...; `value`, `extent`, `implicit` to confirm by hand). Record the confirmed list in the test's comment. + +- [ ] **Step 2: Write the failing test `user_globals_test.cpp`.** (1) Every header of another library that a crypto header includes (`grep -rhoE '#include <[^>]+>' libs/crypto/include | grep -v webcpp/crypto | sort -u`: Boost, webcpp::asio, webcpp::hash, ``, ``, ``, ``, ``, the standard library), first, so that their own names are parsed before the globals exist. (2) In the global namespace, `extern int const ;` for every confirmed name. (3) Every public header: ``, ``, `` and each header the convenience header leaves out. (4) `int main() { return 0; }`. File comment: why it exists (C4459 at /W4 /WX; clang and GCC never warn across namespaces, so the test is MSVC's) and how the list was made. +- [ ] **Step 3: See it fail on MSVC:** `webcpp-msvc 14.5 -- libs/crypto/test//user_globals` - Expected: FAIL, C4459 "declaration of 'timing' hides global declaration" and one per name. On clang it passes already (`b2 ... toolset=clang libs/crypto/test//user_globals`). If MSVC reports C4459 inside webcpp::hash or another library, stop and report to the controller (out of scope). +- [ ] **Step 4: Rename** every confirmed local and parameter, rule "the role, then the kind", two words joined by an underscore; doc comments' `@param` follow. Fixed names: + +| one word | new name | one word | new name | +|---|---|---|---| +| `timing` (`timing_guard const`) | `timing_scope` | `executor` (cheap ops, completion) | `completion_executor` | +| `work` (heavy.hpp's executor) | `work_executor` | `token` | `completion_token` | +| `handler` | `completion_handler` | `code` | `completion_code` | +| `state` (heavy.hpp) | `operation_state` | `state` (timing.hpp) | `saved_state` | +| `s` (`state& s`, backends) | `engine_state` | `keyed` | `keyed_state` | +| `key` (bytes / state) | `key_bytes` / `key_state` | `out`, `output` | `output_bytes` | +| `ready` | `library_ready` | `signature` | `signature_bytes` | +| `scheme` | `signing_scheme` | `input` | `signing_input` | +| `message` | `message_bytes` | `data`, `iv`, `tag`, `nonce`, `digest`, `seed`, `scalar`, `point`, `der` | `_bytes` | +| `peer` | `peer_key` | `policy` | `verification_policy` | +| `encrypt`, `decrypt` (libsodium calls) | `encrypt_call`, `decrypt_call` | `i` (limbs) | `limb_index` | +| `c`, `text`, `label` (pem.hpp) | `pem_character`, `pem_text`, `pem_label` | `size`, `count` | `byte_count`, `item_count` | + +- [ ] **Step 5: Run** the survey again - Expected: only the dropped namespace-scope names. `webcpp-msvc 14.5 -- libs/crypto/test//user_globals` - Expected: PASS. Then the clang whole build through `heavy.sh crypto-types` of `libs/crypto/test libs/crypto/example libs/crypto/bench` and `python3 libs/crypto/doc/tables/generate.py --check` - Expected: all pass. +- [ ] **Step 6: Commit** `crypto: no local name in a header hides a program's global on MSVC`. + +### Task 2.5: Factories named by their input (D3c, owner decision 9) + +**Files:** `include/webcpp/crypto/make.hpp` -> `factories.hpp` (`git mv`, guard `WEBCPP_CRYPTO_FACTORIES_HPP`), `crypto.hpp`, `keypair.hpp`, `async.hpp`, `ciphers/{aes,gcm,aead}.hpp`, `curves/{ed25519,p256,secp256k1}.hpp` and their `formats.hpp`, `curves/x25519/kx.hpp`, `hybrid/box.hpp`, `backends/{bearssl,openssl,sodium,secp256k1}.hpp` (engine renames), `detail/{p_curves,heavy}.hpp`, `meta/include-boundaries.json`, `test/Jamfile` (headers-alone list), every caller (`grep -rlE '\b(async_)?make\b' libs/crypto`: ~169 tests, 37 examples, bench, 12 doc pages, `crypto.json`, the MSVC and message tests, `test/constant_time/*`); new message test `test/messages/make_removed/`. Superproject: `tools/test/fixtures/crypto_jamfiles/*` (51 files). + +**Interfaces (Produces):** + +| Class | Before | After | +|---|---|---| +| `ciphers::aes128/192/256` (aes.hpp) | `make(key)` | `from_key(key)` | +| `ciphers::gcm` | `make`, `async_make` | `from_key`, `async_from_key` | +| `ciphers::aead` (and secretbox, an alias until 3.2) | `make(key)` | `from_key(key)` | +| `hybrid::basic_box` | `make(secret_key, peer_public_key)` | `from_keys(secret_key, peer_public_key)` (bytes until 2.2) | +| `curves::x25519::kx_keypair` | `make(seed)` | `derive_from_seed(seed)` (`generate()` unchanged) | +| `ed25519::public_key`, `secp256k1::public_key` | `make(bytes)` | `from_bytes(bytes)` (secp256k1's keeps its `Backend` parameter first) | +| `p256::basic_public_key` | `make(point)`, `make(x, y)` | `from_bytes(point)`, `from_coordinates(x, y)` | +| `ed25519`, `p256`, `secp256k1` `basic_keypair` | `make(secret[, memory_resource])`, `async_make` | `from_secret(secret_bytes[, memory_resource])`, `async_from_secret` | +| free (`factories.hpp`) | `crypto::make(...)` | `from_secret(...)`, `from_bytes(...)`, `from_key(...)`; `generate(...)` moves here unchanged | +| free (`async.hpp`) | `async_make(ex, bytes, token)` | `async_from_secret(ex, secret_bytes, token)` (key pairs WebCrypto has), `async_from_key(ex, key_bytes, token)` (AES-GCM) | +| detail engines | `p_curve_engine::make`, Ed25519's `engine::make`, `kx_engine::make`, `heavy_state::make` | `import_secret`, `seed_keypair`, `seed_keypair`, `allocate` (ruling P4) | + +- Each free factory: `template requires requires { Keypair::from_secret(std::declval()...); } [[nodiscard]] auto from_secret(Arguments&&... forwarded_arguments) noexcept(noexcept(...)) -> decltype(Keypair::from_secret(std::forward(forwarded_arguments)...))`, holding the guard as `make` did; `from_bytes` and `from_key` the same over their members. +- `async.hpp`: `detail::initiate_make` becomes `initiate_from_secret` and `initiate_from_key`; `async_engine`'s documented shapes `from_secret(executor, secret_bytes, token)` and `from_key(executor, key_bytes, token)`; refusal texts name `async_from_secret`/`async_from_key`. +- `keypair.hpp`'s concept requires `Keypair::from_secret(std::span&)`. +- Asynchronous refusals: "webcpp::crypto: from_secret on this backend completes asynchronously: call async_from_secret." (and `from_key`/`async_from_key`). + +- [ ] **Step 1: Failing tests.** `test/synchronous_forms_test.cpp`: `crypto::from_secret(scalar)`, `(seed)`, `(secret)` have the members' public keys; `crypto::from_bytes(point) == p256::public_key::from_bytes(point)`; `p256::public_key::from_coordinates(x, y) == from_bytes(04 || x || y)`; `crypto::from_key(key)` seals as `gcm::from_key(key)`. `test/kx_sodium_test.cpp`: `kx_keypair::derive_from_seed(seed)` gives the keys the old `make(seed)` vectors give. `test/async_p256_test.cpp`, `async_25519_test.cpp`, `async_gcm_test.cpp`: the `async_from_secret`/`async_from_key` forms, member and free. +- [ ] **Step 2: Run** `b2 ... toolset=clang libs/crypto/test//synchronous_forms` - Expected: compile errors, no `from_secret`. +- [ ] **Step 3: Implement** the table; `git mv make.hpp factories.hpp`; `include-boundaries.json` names `factories.hpp`. +- [ ] **Step 4: Migrate every caller**, the doc pages' prose and code (`curves.adoc`'s "`crypto::make` ... in `make.hpp`"), `crypto.json` (the root row "`make`, `generate`: Making by type" becomes "`from_secret`, `from_bytes`, `from_key`, `generate`: Making by type", the `fixes` texts that say `make`, the message `async_make_xchacha` renamed `async_from_key_xchacha` with its MSVC twin); regenerate. +- [ ] **Step 5: Message test `make_removed`**: `crypto::curves::p256::keypair::make(scalar)` and `crypto::make(scalar)`, two `expected-error` lines (`{{no member named 'make' in}}`, substring), `alone`, native wasip2 wasip3, its `crypto.json` entry; regenerate. +- [ ] **Step 6: Run** `grep -rnE '\b(async_)?make\b *(<[^>]*>)? *\(|make\.hpp' libs/crypto/include libs/crypto/test libs/crypto/example libs/crypto/bench libs/crypto/doc/*.adoc libs/crypto/doc/tables/crypto.json tools/test/fixtures/crypto_jamfiles` - Expected: only `make_removed`'s two lines. Then the clang whole build through `heavy.sh crypto-types`, `generate.py --check`, and `python3 tools/test/crypto_jamfiles_test.py --target native` - Expected: all pass. +- [ ] **Step 7: Commit** `crypto: every factory is named by its input, and make is gone`; superproject: `crypto fixtures: key pairs are made by from_secret, public keys by from_bytes, ciphers by from_key`. + +### Task 2.4: Constructions grouped by purpose (D3b, owner decision 8) + +**Files:** `git mv` `hybrid/box.hpp` -> `public_key_encryption/box.hpp`, `hybrid/sealed_box.hpp` -> `public_key_encryption/sealed_box.hpp`, `curves/x25519/kx.hpp` -> `key_exchange/kx.hpp` (guards renamed); `crypto.hpp`, `test/Jamfile` (headers-alone), `doc/hybrid.adoc` -> `doc/public_key_encryption.adoc` (anchor `crypto-public-key-encryption`, every xref; `crypto.adoc`'s include), `doc/kx.adoc`, `crypto.json` (`namespaces` entries and rows naming the headers or types), callers (14 tests, 2 examples, `test/constant_time/paths.hpp`, the MSVC and message tests `box_*`, `kx_*`); new message tests `hybrid_header_removed`, `hybrid_names_removed`. Superproject: fixtures `box_*`, `sealed_box_default`, `kx_*` (8 cases). + +**Interfaces (Produces):** namespaces `webcpp::crypto::public_key_encryption` (`basic_box`, `box`, `box_xchacha20poly1305`, `basic_sealed_box`, `sealed_box`) and `webcpp::crypto::key_exchange` (`kx_keypair`, `session_keys`); `detail::box_engine`, `box_state`, `sealed_box_engine`, `kx_engine` keep their names; families and capability rows unchanged. + +- [ ] **Step 1: Failing tests**: `box_sodium_test.cpp`, `kx_sodium_test.cpp` include the new headers and name the new namespaces. Run `b2 ... toolset=clang libs/crypto/test//box_sodium libs/crypto/test//kx_sodium` - Expected: file not found. +- [ ] **Step 2: Implement** the moves; the file comments say why the namespaces (D3b: "hybrid" names post-quantum hybrids; HPKE later goes to `public_key_encryption`). +- [ ] **Step 3: Migrate** every caller and page; regenerate. +- [ ] **Step 4: Message tests** `hybrid_header_removed` (`#include `, `{{'webcpp/crypto/hybrid/box.hpp' file not found}}`) and `hybrid_names_removed` (`crypto::hybrid::box<>`, `crypto::curves::x25519::kx_keypair<>`: `{{no member named 'hybrid'}}`, `{{no member named 'kx_keypair'}}`), `alone`, with `crypto.json` entries. +- [ ] **Step 5: Run** `grep -rn 'hybrid::\|hybrid/\|x25519/kx.hpp\|x25519::kx_keypair\|x25519::session_keys' libs/crypto tools/test/fixtures/crypto_jamfiles --include=*.hpp --include=*.cpp --include=*.adoc --include=*.json --include=Jamfile` - Expected: only the two message tests and `changelog.adoc` (4.1). The touched targets, the two message tests, `example//box_messages example//kx_session example//file_share`, `generate.py --check`, the fixtures named above - Expected: pass. +- [ ] **Step 6: Commit** `crypto: crypto_box and sealed boxes are public_key_encryption's, crypto_kx is key_exchange's, and crypto::hybrid is free`; superproject `crypto fixtures: the boxes and crypto_kx in their namespaces by purpose`. + +### Task X2: `crypto::erase_secret` and `crypto::constant_time_equal` (controller ruling, owner decision 11, design D10) + +Two parts, one commit each in `libs/crypto`: the public erasure (A), then the rename of `equal` (B), whose callers span libs/crypto, libs/hash and the superproject's fixtures. Both stay at the top of `webcpp::crypto` (no new namespace); the guide's section that groups them with `secret` and `random_device` is Task 4.1's. + +**Files (A):** Create `include/webcpp/crypto/erase_secret.hpp`, `test/erase_secret_test.cpp` (`crypto-run erase_secret : erase_secret_test.cpp : $(OPTIMISED) full ;`), `test/messages/erase_secret_const_range/`, `doc/erase_secret.adoc` (`[#crypto-erase-secret] === Erasing a secret from a buffer`, included after `equal.adoc` in `crypto.adoc`, which part B renames `constant_time_equal.adoc`). Modify `crypto.hpp`, `test/Jamfile` (headers-alone list), `meta/include-boundaries.json` (`erase_secret.hpp` in the backend-free boundary), `crypto.json` (root row, `fixes`). + +**Files (B):** `git mv` `include/webcpp/crypto/equal.hpp` -> `constant_time_equal.hpp` (guard `WEBCPP_CRYPTO_CONSTANT_TIME_EQUAL_HPP`, file comment), `test/equal_test.cpp` -> `test/constant_time_equal_test.cpp` (target `constant_time_equal`), `doc/equal.adoc` -> `doc/constant_time_equal.adoc` (`[#crypto-constant-time-equal] === Comparing tags in constant time`, `crypto.adoc`'s include), `example/equal_hmac.cpp` and `.expected` -> `example/constant_time_equal_hmac.cpp` and `.expected` (`example/Jamfile`). Modify the callers `grep -rlE 'crypto::equal|crypto/equal\.hpp|crypto-equal' libs tools` and the unqualified calls inside `namespace webcpp::crypto` (`grep -rnE '(^|[^:_.a-z])equal\(' libs/crypto/include`) show on 834390f: +- headers: `crypto.hpp`, `pem.hpp`, `curves/p256/formats.hpp`, `curves/secp256k1/formats.hpp`, `backends/bearssl.hpp` (the tag check), `backends/sodium.hpp` (the DER prefix check); `meta/include-boundaries.json`; `test/Jamfile` (headers-alone list, the `equal` target, the comments of `timing_unseamed`); +- tests: `timing_test.cpp` (`require_enters("constant_time_equal(span, span)", "crypto::constant_time_equal(span", ...)` and the digest case), `timing_unseamed_test.cpp` (its comment, the include, the masked name `"webcpp::crypto::constant_time_equal#"`), `convenience_header_test.cpp`, `p256_openssl_oracle_test.cpp`, `secp256k1_ellswift_test.cpp`, `allocation_bearssl_test.cpp`, `windows_h_before_test.cpp`, `windows_h_after_test.cpp`, `support/aead_checks.hpp`, `support/gcm_checks.hpp`; +- the constant-time lane: `test/constant_time/paths.hpp` (`equal_path` -> `constant_time_equal_path`, its check name `"constant_time_equal"`), `dudect_test.cpp` (the case `"equal"` -> `"constant_time_equal"`, its comment), `dudect_harness_test.cpp` (the selection test's case names), `test/constant_time/Jamfile` (comments); the suppressions (`bearssl_verdicts.supp`, `sodium_verdicts.supp`, `openssl.supp`) name no `equal` frame on 834390f: `grep -n 'equal' libs/crypto/test/constant_time/*.supp` again after 2.5 and 2.4, and rename any frame it shows; +- examples: `aes256_gcm_bearssl`, `ecdh_session`, `ecdh_x_coordinate`, `ellswift_handshake`, `kx_session`, `p256_ecdh`, `p256_handshake`, `taproot_tweak`, `wallet_key`, `x25519_agree` (`.expected` only if output changes); +- pages and tables: `doc/crypto.adoc`, `doc/everyday.adoc`, `doc/overview.adoc` (prose and `<>`), `doc/tables/crypto.json` (the `llms` text's "a constant-time equal", the `none` backend's `header`, `constant_time` and `lane_paths` texts, the root row `equal` (`id`, `functions`, `api`, `header`, `section`, `tests`), the advice row in section `crypto-equal`, the root table's row, the use case "Check a webhook's or an API's HMAC signature"), `doc/tables/generate_test.py`'s sample `lane_paths` (`` `equal` `` -> `` `constant_time_equal` ``, its asserted page line); the message and MSVC tests call no `equal` on 834390f (`grep -rln 'equal' libs/crypto/test/messages libs/crypto/test/msvc` again before Step 7). +- **libs/hash** (branch `crypto/uniform-types`): `include/webcpp/hash/hmac.hpp` and `mac.hpp` (file comments), examples `hmac_sha256`, `hmac_sodium`, `kmac`, `mac_family`, `blake2b_mac_sodium`, `password_storage` and `example/Jamfile`'s comment, pages `digests.adoc`, `macs.adoc`, `overview.adoc`, `password_hashing.adoc`, `use-cases/privacy.adoc`, `doc/guide.json`; generated `doc/generated/choose.adoc` and `doc/llms.txt` rerun by `python3 tools/hash/doc_tables.py --write`, never edited. +- **Superproject:** `tools/test/fixtures/crypto_jamfiles/*/app.cpp` (17 cases: `both_bearssl_named`, `box_xchacha20poly1305_default`, `box_xsalsa20poly1305_default`, `chacha20_poly1305_default`, `chacha20_poly1305_original_default`, `ed25519_default`, `encrypt_and_sign`, `gcm_default`, `kx_default`, `secp256k1_default`, `secp256k1_ellswift_default`, `secretbox_xchacha20poly1305_default`, `secretbox_xsalsa20poly1305_default`, `server`, `web`, `x25519_default`, `xchacha20_poly1305_default`); `CODING-GUIDELINES.md`'s current crypto rules that name `equal` (around lines 6977, 6986, 7038, 7045-7052: the root list, the backend-free headers, the rule "`equal` compares in constant time" and its Source line `include/webcpp/crypto/constant_time_equal.hpp`), dated records (around line 8859 onwards) keeping the names of their time; the `libs/hash` pointer. +- **Not touched:** webcpp::trystero's port of Trystero 0.27 (`/Users/you/dev/webcpporg/trystero-027`): its `crypto::equal` and `crypto/equal.hpp` call sites (`grep -rnE 'crypto::equal|crypto/equal\.hpp' /Users/you/dev/webcpporg/trystero-027/webcpp/libs/trystero`, every file and line) are listed in this stream's HANDBACK for that stream to move. + +**Interfaces (Produces):** + +```cpp +namespace webcpp::crypto { +template + requires std::ranges::contiguous_range && std::ranges::sized_range && + (!std::is_const_v>>) && + std::is_trivially_copyable_v> +void erase_secret(Range&& erased_range) noexcept { + detail::wipe(std::ranges::data(erased_range), + std::ranges::size(erased_range) * sizeof(std::ranges::range_value_t)); +} +// A contiguous sized range of const or non-trivially-copyable elements: static_assert with +// "webcpp::crypto: erase_secret zeroes a buffer the program may write, of trivially copyable elements: a std::vector, a std::string, a std::array, a std::span; this range's elements are const or not trivially copyable." + +[[nodiscard]] inline bool constant_time_equal(std::span first_operand, + std::span second_operand) noexcept; +template +[[nodiscard]] bool constant_time_equal(boost::hash2::digest const& first_operand, + boost::hash2::digest const& second_operand) noexcept; +} +``` + +`erase_secret`: no `(void*, std::size_t)` overload: every caller found (trystero's `detail::wipe(x.data(), x.size())`) has a range. No guard (no backend call). `constant_time_equal`: `equal`'s bodies, guards and doc comments unchanged but for the name; no alias, no deprecated `equal`. +- [ ] **Step 1: Failing test** `erase_secret_test.cpp`: after `crypto::erase_secret(x)`, every byte is zero for `std::vector`, `std::string` (its size, not its capacity), `std::array`, `std::span` over a stack buffer (bytes around the span untouched), `unsigned char[16]`, `std::vector`; an empty vector is a no-op; `static_assert(noexcept(crypto::erase_secret(vector)))`; `static_assert(!requires { crypto::erase_secret(std::declval&>()); })` and for `std::vector`; a buffer erased at the end of a function whose storage the test inspects afterwards as `secret_test.cpp` does (`$(OPTIMISED) full`). Run `b2 ... toolset=clang libs/crypto/test//erase_secret` - Expected: `erase_secret.hpp` not found. +- [ ] **Step 2: Implement** `erase_secret.hpp` (file comment: the dead-store hazard, `@see` the page); `grep -rn '[^:_]wipe(' libs/crypto/include` - Expected: only `detail::`-qualified calls or calls inside `namespace detail`, so that no public name `wipe` exists; `grep -rn 'crypto::wipe\b' libs/crypto` - Expected: nothing. +- [ ] **Step 3: Message test `erase_secret_const_range`** (`crypto::erase_secret(std::string const&)`, the message above, `alone`); the page section (why `memset` is dropped, the call, what it is not: no `mlock`); the root row `["\`erase_secret\`", "Erasing a password, a key or a plaintext from a buffer the program owns", "\`\`", "none", "{cwe14}", ...]` (add `cwe14` to the attributes if absent); regenerate. +- [ ] **Step 4: Run** `erase_secret`, `wipe`, `convenience_header`, the message test, `generate.py --check`, the doc build `b2 ... libs/crypto/doc` - Expected: pass. +- [ ] **Step 5: Commit** `crypto: crypto::erase_secret zeroes any buffer the program owns, with stores the optimiser keeps`. +- [ ] **Step 6: Failing test for B**: `git mv test/equal_test.cpp test/constant_time_equal_test.cpp`; every case calls `crypto::constant_time_equal` and includes ``; the Jamfile target `crypto-run constant_time_equal : constant_time_equal_test.cpp ;`. Run `b2 ... toolset=clang libs/crypto/test//constant_time_equal` - Expected: `constant_time_equal.hpp` not found. +- [ ] **Step 7: Implement and migrate**: `git mv` the header, rename both overloads, then every caller listed in Files (B) in libs/crypto; the page renamed with its anchor and every xref; `crypto.json` as listed; regenerate. +- [ ] **Step 8: Message tests**, each `alone` with its `crypto.json` entry, native wasip2 wasip3: `equal_header_removed` (`#include `: `{{'webcpp/crypto/equal.hpp' file not found}}`) and `equal_removed` (`` included, `webcpp::crypto::equal(first, second)` of two spans: `{{no member named 'equal' in namespace 'webcpp::crypto'}}`, substring); regenerate. +- [ ] **Step 9: Run** `grep -rnE 'crypto::equal\b|crypto/equal\.hpp|crypto-equal|(^|[^_])equal_hmac|(^|[^:_.a-z])equal\(' libs/crypto/include libs/crypto/test libs/crypto/example libs/crypto/bench libs/crypto/doc/*.adoc libs/crypto/doc/tables libs/crypto/meta tools/test/fixtures/crypto_jamfiles libs/hash/include libs/hash/example libs/hash/doc/*.adoc libs/hash/doc/use-cases libs/hash/doc/guide.json | grep -vE 'std::(ranges::)?equal|ranges::equal'` - Expected: only the two message tests and `changelog.adoc` (4.1). Then `constant_time_equal`, `timing`, `timing_unseamed`, `timing_unseamed_release`, `convenience_header`, `windows_h_before`, `windows_h_after`, the message tests, `example//constant_time_equal_hmac`, the constant-time lane's `paths` build natively (`libs/crypto/test/constant_time`, through `heavy.sh crypto-types`), `libs/hash/example`, `python3 tools/hash/doc_tables.py --check`, the 17 fixtures (`python3 tools/test/crypto_jamfiles_test.py ... --target native`), `generate.py --check`, `generate_test.py`, the doc builds `b2 ... libs/crypto/doc libs/hash/doc` - Expected: all pass. +- [ ] **Step 10: Commit** `crypto: equal is constant_time_equal, a name that says what it guarantees`; hash: `hash: MACs are checked with crypto::constant_time_equal`; superproject: `crypto fixtures and guidelines: tags are compared with constant_time_equal`, then the `libs/hash` pointer `hash: the MAC pages and examples call constant_time_equal`. Record trystero-027's call sites for the HANDBACK. + +### Task 1.1: The signature types (D1) + +**Files:** Create `include/webcpp/crypto/detail/signature.hpp`, `test/signature_types_test.cpp` (`crypto-run signature_types : signature_types_test.cpp ;`). Modify `signing.hpp` (the trait), `curves/{ed25519,p256,secp256k1}.hpp` (tags, aliases, trait specializations), `test/Jamfile` (headers-alone). + +**Interfaces (Produces):** + +```cpp +namespace webcpp::crypto::detail { +template +class basic_signature { +public: + static constexpr std::size_t size = Size; + basic_signature() noexcept = default; // all zeros: the types are std::regular (ruling P6) + [[nodiscard]] static boost::system::result from_bytes( + std::span signature_bytes) noexcept; // invalid_signature unless Size bytes + [[nodiscard]] std::array const& bytes() const noexcept; + [[nodiscard]] std::uint8_t recovery_id() const noexcept requires Tag::recoverable; // bytes()[64] + [[nodiscard]] bool operator==(basic_signature const&) const noexcept = default; +private: + friend struct signature_access; // signature_access::of(std::array const&) + std::array signature_bytes_{}; +}; +template struct signature_of { using type = void; }; +template using signature_of_t = typename signature_of::type; +} +``` + +- Tags (empty structs in `detail`, `recoverable` true only on the recoverable one) and aliases: `curves::ed25519::signature` (64; Ed25519ph's signature too, owner decision 12: no `ph_signature`), `curves::p256::ecdsa_signature` (64), `curves::secp256k1::ecdsa_signature` (64), `recoverable_signature` (65), `schnorr_signature` (64). +- `signature_of` specialized in each curve header for its key pairs and public keys under each scheme of `signs_with_v`/`verifies_with_v` (Ed25519 `eddsa`; P-256 `ecdsa_sha256`; secp256k1 the three, and the 32-byte x-only key under `schnorr`). +- [ ] **Step 1: Failing test** `signature_types_test.cpp`: `signature_from_wire` - for each of the five types, `from_bytes` of `size` bytes round-trips through `bytes()`, of `size - 1` and `size + 1` bytes returns `invalid_signature`; `recoverable_signature::from_bytes(65 bytes ending 0x02)->recovery_id() == 2`; `static_assert(std::regular)` for each; `!std::is_convertible_v` and `!std::is_constructible_v` between every pair of the five and between each and `std::span` / `std::array`, both ways; `!requires { ecdsa_signature{}.recovery_id(); }`; `std::is_same_v, p256::ecdsa_signature>` and the other pairs; `signature_of_t` is `void`. Run - Expected: header not found. +- [ ] **Step 2: Implement**; `timing_coverage_{sodium,bearssl,secp256k1}_test.cpp` check `from_bytes` and `bytes()` enter no guard. +- [ ] **Step 3: Run** `signature_types`, `signing`, `keypair`, the three timing coverage tests, `generate.py --check` - Expected: pass. +- [ ] **Step 4: Commit** `crypto: a signature type per curve and scheme, made from bytes of its size alone`. + +### Task 1.2: Every sign returns its type, every verify and recover takes it (D1, R1, owner decision 6) + +**Files:** `signing.hpp`, `keypair.hpp`, `async.hpp`, `curves/{ed25519,p256,secp256k1}.hpp`, `curves/secp256k1/musig.hpp`, every caller: tests (`p256_*`, `ed25519_*`, `ed25519ph_*`, `secp256k1_*`, `crypto_secp256k1_test`, `signing_*`, `keypair_test`, `synchronous_forms_test`, `async_*`, `timing_coverage_*`, `oracle_25519_test`, `formats_25519_*`, `allocation_*`, `test/support/secp256k1_checks.hpp`), `test/constant_time/{paths.hpp,dudect_*}`, `test/sizes/*`, examples (`p256_sign`, `ecdsa_der`, `p256_handshake`, `signed_update`, `ed25519_sign`, `signed_message`, `arena_signer`, `schnorr_sign`, `recover_signer`, `bitcoin_sighash`, `musig_*`, `wallet_key`, `taproot_tweak`, `four_forms`, `async_sign`; `.expected` only if output changes), `bench/operations.hpp`, the doc pages' code, the message and MSVC tests that call `verify`; new message tests below. Superproject: fixtures `sign`, `sign_small`, `encrypt_and_sign`, `secp256k1_*`, `ed25519_default` where they verify or print a signature. + +**Interfaces (Produces):** +- `sign` returns `result>` on all three curves (secp256k1's hedged and explicit-aux overloads too); Ed25519ph's streaming signer (`ph` until 1.4 renames it `prehashed_signer`) retyped onto `ed25519::signature`: its `sign(key_pair)` returns `result` and its `verify` takes `Signature const&` checked against `ed25519::signature` (owner decision 12; no `ph_signature`); `async_sign` completes with `void(error_code, T)`, the default `T` on an error. +- Every `verify` (free, member, asynchronous, free and member) takes `Signature const& signature_value` as a template parameter and first calls `detail::check_signature()`, a `static_assert(std::is_same_v, )` with these texts: + - "webcpp::crypto: verify: a P-256 key verifies a curves::p256::ecdsa_signature: make one from 64 bytes with curves::p256::ecdsa_signature::from_bytes." + - "webcpp::crypto: verify: a secp256k1 key verifies a curves::secp256k1::ecdsa_signature under crypto::ecdsa_sha256: make one from 64 bytes with curves::secp256k1::ecdsa_signature::from_bytes." + - "webcpp::crypto: verify: crypto::schnorr verifies a curves::secp256k1::schnorr_signature: make one from 64 bytes with curves::secp256k1::schnorr_signature::from_bytes." + - "webcpp::crypto: verify: an Ed25519 key verifies a curves::ed25519::signature under crypto::eddsa: make one from 64 bytes with curves::ed25519::signature::from_bytes." (the streaming signer's `verify`: "webcpp::crypto: verify: Ed25519ph verifies a curves::ed25519::signature: make one from 64 bytes with curves::ed25519::signature::from_bytes.") + - `recover`: "webcpp::crypto: recover takes a curves::secp256k1::recoverable_signature: make one from 65 bytes with curves::secp256k1::recoverable_signature::from_bytes." +- The size checks inside the workers go (the type has its size); `p256_verify`, `ed25519_verify` and secp256k1's workers take `std::span` of `signature_value.bytes()`. +- `can_verify` (ruling P7): adds `std::is_same_v, detail::signature_of_t, Scheme>>`. +- Format helpers typed on both curves (ruling P8): `to_der(ecdsa_signature const&, std::span der_output) -> result`, `from_der(std::span) -> result`, `normalize_low_s(ecdsa_signature const&) -> result`, `is_low_s(ecdsa_signature const&) -> bool`. +- MuSig2's `partial_signature_aggregate` returns `result` (ruling P9); partial signatures (32 bytes) unchanged. +- [ ] **Step 1: Failing tests**, every existing case kept: `p256_ecdsa_bearssl_test.cpp` - `sign` returns `p256::ecdsa_signature`; RFC 6979 A.2.5's high-S signature, made with `from_bytes`, verifies and `normalize_low_s` of it equals `sign`'s; `signature_from_vector`: a `std::vector` of 64 bytes made into the type verifies through `key.verify`, `crypto::verify`, `key.async_verify`, `crypto::async_verify` (in `async_p256_test.cpp`), 63 and 65 bytes give `invalid_signature` from `from_bytes`; the same on Ed25519 (`ed25519_sodium_test.cpp`, `async_25519_test.cpp`) and synchronously on secp256k1 (`secp256k1_test.cpp`: the three types, `recover` with a `recoverable_signature`); `static_assert(!crypto::can_verify, p256::public_key>)`; `to_der`/`from_der` round trip typed on both curves; MuSig2's aggregate verifies with `crypto::verify(crypto::schnorr, aggregate, message, key)`. Run `b2 ... toolset=clang libs/crypto/test//p256_ecdsa_bearssl` - Expected: compile errors. +- [ ] **Step 2: Implement** the interfaces; the old "verify takes bytes of any size" tests of f21d798 become the `from_bytes` checks above. +- [ ] **Step 3: Migrate every caller** (`.bytes()` where bytes were used; `T::from_bytes(bytes)` where a signature arrives as bytes); constant-time paths sign and verify through the types (what they measure is unchanged). +- [ ] **Step 4: Message tests**, each `alone` with its `crypto.json` entry: `verify_p256_secp256k1_signature` (the spec's wrong-curve scenario: the P-256 text), `verify_schnorr_as_ecdsa` (a `schnorr_signature` under `ecdsa_sha256` with a secp256k1 key), `verify_ed25519_bytes_signature` (a `std::array`), `recover_ecdsa_signature`, `async_verify_p256_bytes_signature`; regenerate. +- [ ] **Step 5: Run** `grep -rnE 'std::span signature' libs/crypto/include` - Expected: nothing. The clang whole build through `heavy.sh crypto-types`; `EM_CACHE=... b2 ... toolset=emscripten libs/crypto/test//p256_webcrypto_oracle libs/crypto/test//formats_25519_webcrypto_oracle libs/crypto/test//async_p256 libs/crypto/test//async_25519` through `heavy.sh`; the fixtures named above; `generate.py --check` - Expected: all pass. +- [ ] **Step 6: Commit** `crypto: every sign returns its curve's signature type and every verify and recover takes it`; superproject `crypto fixtures: signatures are typed values`. + +### Task 1.3: Ethereum's recoverable ECDSA (owner decision 10, design D8, R18-R20) + +**Files:** `signing.hpp` (tag, value, `all_schemes`, `scheme_traits`, the digest-size text, the catch-all `verify`'s text), `curves/secp256k1.hpp` (`signs_with_v`, `signature_of`, `sign`'s dispatch, `recover`'s overload, the Keccak digest), new `test/secp256k1_ethereum_test.cpp` (`crypto-run secp256k1_ethereum : secp256k1_ethereum_test.cpp : /third_party//secp256k1 /third_party//xkcp ;`), `test/signing_test.cpp`, `test/keypair_test.cpp`, `timing_coverage_secp256k1_test.cpp`, `test/constant_time/paths.hpp` (`secp256k1_signing` signs under the new scheme too), new `example/ethereum_personal_sign.cpp` (+ `.expected`, `example/Jamfile` with `/third_party//xkcp`), `doc/secp256k1.adoc` (a section "Ethereum"), `doc/wallets.adoc` (a link), `crypto.json` (the signing row's text, `fixes`), message tests below; every hand list of the schemes `grep -rn 'ecdsa_sha256_recoverable' libs/crypto` shows (the generator included). + +**Interfaces (Produces):** +- `struct ecdsa_keccak256_recoverable_t { explicit ecdsa_keccak256_recoverable_t() = default; }; inline constexpr ecdsa_keccak256_recoverable_t ecdsa_keccak256_recoverable{};` in `all_schemes` (after `ecdsa_sha256_recoverable_t`); `scheme_traits`: `signature_size` 65, `digest_size` 32; `check_input`'s marker-size text for it: "webcpp::crypto: crypto::ecdsa_keccak256_recoverable takes a 32-byte digest, Keccak-256's: crypto::prehashed{digest} of a std::array." +- `signs_with_v, ecdsa_keccak256_recoverable_t>` true; `signature_of` of it `secp256k1::recoverable_signature` (R20); `sign`'s scheme refusal lists four schemes. +- `secp256k1.hpp`: `#if defined(WEBCPP_HASH_HAS_XKCP)` `#include `; `template std::array detail::secp256k1_keccak_digest(Input const&)` (the marker's bytes, or `webcpp::hash::keccak_256` over `message_bytes`); a message input without XKCP stops at R19's text through a dependent `static_assert`; the signing worker is the existing `signed_recoverable(digest)`. +- `template , class Signature, class Input> [[nodiscard]] result recover(ecdsa_keccak256_recoverable_t, Signature const& signature_value, Input const& signing_input) noexcept`, guard first, `check_signature()`, the checks of `ecdsa_sha256_recoverable`'s `recover` (high S accepted, as libsecp256k1's recovery and Ethereum's `ecrecover` accept it). No `crypto::verify` overload (R18): the catch-all's text gains "a crypto::ecdsa_keccak256_recoverable signature gives its key to curves::secp256k1::recover". No asynchronous form (crypto-sign's R8). +- [ ] **Step 1: Failing tests** `secp256k1_ethereum_test.cpp`, each vector's source URL and commit in a comment: `geth_recover`: go-ethereum `crypto/signature_test.go`'s `testmsg`, `testsig`, `testpubkey` (record the commit): `recover(ecdsa_keccak256_recoverable, recoverable_signature::from_bytes(testsig), prehashed{testmsg})` gives `testpubkey` (uncompressed); `personal_sign`: web3.js 1.x documentation's `web3.eth.accounts.sign('Some data', '0x4c08...2318')` vector (record the URL): the EIP-191 digest built in the test with `webcpp::hash::keccak_256`, `sign(ecdsa_keccak256_recoverable, prehashed{digest})` gives the documented r and s and `recovery_id() == v - 27`; `keccak_not_sha3`: `keccak_256("")` is `c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470` and SHA3-256's `a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a` differs; `message_is_hashed`: `sign(scheme, m) == sign(scheme, prehashed{keccak_256(m)})` and `!=` over `sha3_256(m)`, for a 32-byte `m` too; `recover` with the message gives the signer; `always_low_s`: 256 signatures, `is_low_s` of their first 64 bytes; `empty_message`; `wrong_scheme_key`: recovering a keccak signature under `ecdsa_sha256_recoverable` gives another key. Run `b2 ... toolset=clang libs/crypto/test//secp256k1_ethereum` - Expected: compile errors. +- [ ] **Step 2: Implement**; `timing_coverage_secp256k1_test.cpp`: `sign` and `recover` under the scheme, message and marker, each enter their own guard. +- [ ] **Step 3: Message tests**, each `alone` with `crypto.json` `fixes`: `sign_keccak_digest_20` (the digest-size text), `sign_p256_keccak` and `sign_ed25519_keccak` (their curves' scheme texts), `verify_keccak_recoverable` (the catch-all's text), `sign_keccak_without_xkcp` (R19's text, a Jamfile without `/third_party//xkcp`, native wasip2 wasip3); MSVC twin of `sign_keccak_without_xkcp` (a build message). +- [ ] **Step 4: Example** `ethereum_personal_sign.cpp`: builds EIP-191's digest (`"\x19Ethereum Signed Message:\n"`, the length in decimal, the message) with `webcpp::hash::keccak_256`, signs it as `prehashed`, prints r, s and `v = 27 + recovery_id()`, recovers the key and prints the address (the last 20 bytes of Keccak-256 over the uncompressed key without its 0x04); comments say that crypto computes no digest, no `v` (EIP-155's `35 + 2 x chain_id + id`, typed transactions' `yParity`) and no address. The page section shows it by tag, with D8's table of `v`. +- [ ] **Step 5: Run** `secp256k1_ethereum`, `secp256k1_test`, `secp256k1_recovery`, `signing`, `keypair`, the coverage test, the message tests, `example//ethereum_personal_sign`, `generate.py --check`; wasip2 and Emscripten `secp256k1_ethereum` through `heavy.sh` - Expected: pass. +- [ ] **Step 6: Commit** `crypto: secp256k1 signs and recovers Ethereum's recoverable ECDSA over Keccak-256`. +- [ ] **Step 7: Review**: a fresh reviewer reads D8, R18-R20 and this task's diff (the vectors' provenance, the Keccak padding, the refusal without XKCP) before 2.1 starts. + +### Task 1.4: Ed25519ph as the scheme `eddsa_prehashed` (owner decision 12, design D9) + +**Files:** `signing.hpp` (tag, value, `all_schemes`, `scheme_traits`, `check_input`'s texts), `curves/ed25519.hpp` (`signs_with_v`, `verifies_with_v`, `has_verifier_v` and `signature_of` of `eddsa_prehashed_t`; `basic_keypair::sign`'s dispatch and its scheme text; `public_key::verify` and the free `crypto::verify` under the new scheme; `ph` renamed `prehashed_signer`, its `static_assert` text, every doc comment that says `@ref ph`), `backends/sodium.hpp` (`ed25519ph_engine` gains `sign_digest` and `verify_digest`; ruling P27), the primary `ed25519ph_engine` (never-called members for the two), `async.hpp` (`async_sign` and `async_verify` of Ed25519 under the new scheme, the browser refusal), tests: `ed25519ph_sodium_test.cpp`, `async_25519_test.cpp`, `signing_test.cpp`, `keypair_test.cpp`, `timing_coverage_sodium_test.cpp`, `allocation_sodium_test.cpp`, `ed25519_wipe_sodium_test.cpp`, `timing_hash_interop_test.cpp` (the type renamed), `test/constant_time/paths.hpp` (`sodium_ed25519` signs under `eddsa_prehashed` too), `example/ed25519_sign.cpp` (+ `.expected` if its output changes), `doc/ed25519.adoc` (the Ed25519ph section), `doc/tables/crypto.json` (the `ed25519ph` row's `functions` and `api`, the `types` entry `curves::ed25519::prehashed_signer`, the Ed25519 curve row and use case naming `ph`, the signing row's scheme list, the `fixes` of `ed25519ph_sha256`, `ed25519ph_sha256_on_emscripten`, `sign_ed25519_prehashed`, `verify_member_eddsa_prehashed`, `async_sign_ed25519_prehashed`), the generated files rerun (`test/capabilities_test.cpp` names the type); message tests: the existing `sign_ed25519_prehashed`, `async_sign_ed25519_prehashed`, `verify_member_eddsa_prehashed` (`eddsa`'s new text), `sign_ed25519_ecdsa`, `sign_free_ed25519_ecdsa` (the scheme text), `ed25519ph_sha256` and its MSVC twin `test/msvc/ed25519ph_sha256` (the type renamed, its text), and the new ones below; every hand list of the schemes `grep -rn 'ecdsa_sha256_recoverable_t\|eddsa_t' libs/crypto` shows (the generator included). Superproject: fixture `ed25519ph_sha256_on_emscripten` (the type renamed). + +**Interfaces (Produces):** +- `struct eddsa_prehashed_t { explicit eddsa_prehashed_t() = default; }; inline constexpr eddsa_prehashed_t eddsa_prehashed{};` in `all_schemes` (after `eddsa_t`); `scheme_traits`: `signature_size` 64, `digest_size` 64 (SHA-512's). +- `check_input`, each the first message reached, in this order for the scheme: + - `eddsa` with a marker (replaces the text naming `curves::ed25519::ph`): "webcpp::crypto: crypto::eddsa signs the message itself (RFC 8032's pure Ed25519) and takes no digest; a message's SHA-512 is signed with crypto::eddsa_prehashed (Ed25519ph)." + - `eddsa_prehashed` with a message, a 64-byte `std::array` included (a message, never a digest): "webcpp::crypto: crypto::eddsa_prehashed (RFC 8032's Ed25519ph) signs a digest, the message's SHA-512: crypto::prehashed{digest} of a std::array; sign the message itself with crypto::eddsa, or give it in pieces to curves::ed25519::prehashed_signer." + - `eddsa_prehashed` with a marker of another size: "webcpp::crypto: crypto::eddsa_prehashed takes a 64-byte digest, SHA-512's: crypto::prehashed{digest} of a std::array." +- On a backend whose `detail::asynchronous_backend_v` is true, every form under `eddsa_prehashed` (`sign`, `verify`, member and free, and their `async_` forms) stops at its first statement after the guard, before the "completes asynchronously" text and before any engine is named (as P12 rules for D6), with: "webcpp::crypto: WebCrypto has no Ed25519ph: crypto::eddsa_prehashed's sign, verify, async_sign and async_verify run on a native backend." +- `ed25519::basic_keypair`: `signs_with_v<..., eddsa_prehashed_t>` true; `signature_of` of it `ed25519::signature`; `sign`'s scheme text "webcpp::crypto: an Ed25519 key signs with crypto::eddsa or crypto::eddsa_prehashed."; `sign(eddsa_prehashed_t, prehashed<64> const&)` returns `result` through `ed25519ph_engine::sign_digest(key_state, std::span digest_bytes, std::span output_bytes)`; `invalid_state` moved from. +- `ed25519::public_key`: `verifies_with_v` and `has_verifier_v` of `eddsa_prehashed_t` true; `signature_of` of it `ed25519::signature`; `template , class Signature, class Input, class Policy = strict_t> result verify(eddsa_prehashed_t, Signature const& signature_value, Input const& digest_input, Policy = Policy{}) const noexcept` and the free `crypto::verify(eddsa_prehashed_t, signature, input, public_key[, policy])`, guard first, then `check_signature()` with "webcpp::crypto: verify: an Ed25519 key verifies a curves::ed25519::signature under crypto::eddsa_prehashed: make one from 64 bytes with curves::ed25519::signature::from_bytes.", then `check_input`; `ed25519ph_engine::verify_digest(key_bytes, digest_bytes, signature_bytes)`, strict as `eddsa` (libsodium's `_crypto_sign_ed25519_verify_detached` with `prehashed` 1 is the function `crypto_sign_ed25519ph_final_verify` calls). +- `async.hpp`: `key.async_sign(executor, eddsa_prehashed, marker, token)`, `crypto::async_sign(executor, key, eddsa_prehashed, marker, token)`, `public_key.async_verify(executor, eddsa_prehashed, signature, marker[, policy], token)` and `crypto::async_verify(...)`: on a synchronous backend `complete_by_post` of the synchronous member, completing with `void(error_code, ed25519::signature)` and `void(error_code)`; on an asynchronous backend the refusal above, `async_engine` never named. +- `curves::ed25519::prehashed_signer` (was `ph`): `begin`, `update`, `sign(key_pair)` returning `result` (1.2's type), `verify(signature_value, public_key)` taking `Signature const&` checked against `ed25519::signature` (1.2's text), moves and wiping unchanged; `name_type` stays `tags::ed25519ph` and the capability row `ed25519ph` keeps its name (R17); its `static_assert`: "webcpp::crypto: Ed25519ph is defined over SHA-512 (RFC 8032 section 5.1); name curves::ed25519::prehashed_signer." Removed: `ph`, no alias. +- [ ] **Step 1: Failing tests** in `ed25519ph_sodium_test.cpp`, every existing case kept with the type renamed (`rfc8032_ph`: RFC 8032 section 7.3's "abc" in one piece and in two; `spent_and_moved`): `rfc8032_ph_scheme`: section 7.3's key pair signs `crypto::prehashed{sha512("abc")}` (the digest from `webcpp::hash::sha2_512` in the test) with `sign(crypto::eddsa_prehashed, ...)` into the RFC's signature; `crypto::verify(crypto::eddsa_prehashed, signature, marker, public_key)` and `public_key.verify(crypto::eddsa_prehashed, signature, marker)` accept it; a flipped byte of the signature and of the digest give `invalid_signature`; `streaming_equals_scheme`: for messages of 0, 1, 64 and 1000 bytes, given to `prehashed_signer` whole, in pieces of 1 byte and of 7, `sign(key_pair)` equals `key_pair.sign(crypto::eddsa_prehashed, crypto::prehashed{sha512(message)})`, the signer's `verify` accepts the scheme's signature and `crypto::verify(crypto::eddsa_prehashed, ...)` the signer's; `not_interchangeable`: `crypto::verify(crypto::eddsa, prehashed_signature_value, "abc", public_key)` and `crypto::verify(crypto::eddsa_prehashed, key.sign(crypto::eddsa, "abc").value(), crypto::prehashed{sha512("abc")}, public_key)` both return `invalid_signature`; `typed`: `static_assert(std::is_same_v>)` and the same for the signer's `sign`; `std::is_same_v, ed25519::signature>`; `crypto::can_sign>`, and not with `std::span`, `prehashed<32>`, nor for `p256::keypair` or `secp256k1::keypair`; `moved_from`: a moved-from key pair's `sign(crypto::eddsa_prehashed, marker)` is `invalid_state`. `async_25519_test.cpp`: `eddsa_prehashed_async`: `key.async_sign` and `crypto::async_sign` give the synchronous signature, `async_verify` member and free accept it, and a callback's flag is unset when the initiating call returns. Run `b2 ... toolset=clang libs/crypto/test//ed25519ph_sodium` - Expected: compile errors, no `eddsa_prehashed` nor `prehashed_signer`. +- [ ] **Step 2: Implement** the interfaces; `git grep -n 'ed25519::ph\b\|class ph\b\|@ref ph\b' libs/crypto/include` - Expected: nothing; `timing_coverage_sodium_test.cpp`: `sign` and `verify` under the scheme, member and free, and the asynchronous forms each enter their own guard; `allocation_sodium_test.cpp`: signing under the scheme allocates nothing. +- [ ] **Step 3: Migrate** the callers of `ph` (tests, `example/ed25519_sign.cpp`, which also signs the RFC's digest with `crypto::eddsa_prehashed` and prints that both signatures are equal, the page, `crypto.json`, the MSVC twin, the fixture); the page's Ed25519ph section: the scheme first (a digest the program has), the streaming signer for a message given in pieces, the signature of one type and two schemes, not interchangeable, the protocol saying which it uses; native backends only, the browser refusing. +- [ ] **Step 4: Message tests**, each `alone` with its `crypto.json` `fixes`, native wasip2 wasip3: `sign_eddsa_prehashed_message` (`key.sign(crypto::eddsa_prehashed, std::array{})`: the message text), `sign_eddsa_prehashed_digest_32` (`crypto::prehashed{std::array{}}`: the size text), `verify_eddsa_prehashed_message` (`crypto::verify(crypto::eddsa_prehashed, signature, message, public_key)`: the message text), `sign_eddsa_prehashed_asynchronous_backend` and `async_sign_eddsa_prehashed_asynchronous_backend` (an `ed25519::basic_keypair const&` parameter, as `sign_asynchronous_backend` does: the WebCrypto text, `crypto::sign` and `crypto::async_sign`), `ph_removed` (`crypto::curves::ed25519::ph::begin()`: `{{no member named 'ph' in namespace}}`); the existing ones' texts updated (`sign_ed25519_prehashed`, `async_sign_ed25519_prehashed`, `verify_member_eddsa_prehashed`: `eddsa`'s new text; `sign_ed25519_ecdsa`, `sign_free_ed25519_ecdsa`: the two schemes; `ed25519ph_sha256`: `prehashed_signer`); MSVC twin of `sign_eddsa_prehashed_message` (a build message); regenerate. If the capability table's refusal fires before the WebCrypto text on the stand-in (P12's case), stop and report to the controller. +- [ ] **Step 5: Run** `grep -rnE 'ed25519::ph\b|\bph<|ph_signature' libs/crypto tools/test/fixtures/crypto_jamfiles --include=*.hpp --include=*.cpp --include=*.adoc --include=*.json --include=Jamfile` - Expected: only `ph_removed` and `changelog.adoc` (4.1). `ed25519ph_sodium`, `ed25519_sodium`, `async_25519`, `signing`, `keypair`, `timing_coverage_sodium`, `allocation_sodium`, `ed25519_wipe_sodium`, `timing_hash_interop`, the message tests, `example//ed25519_sign`, the fixture `ed25519ph_sha256_on_emscripten`, `generate.py --check`; `ed25519ph_sodium` and `async_25519` on wasip2 and Emscripten and the MSVC twins through `heavy.sh` - Expected: pass. +- [ ] **Step 6: Commit** `crypto: Ed25519ph is the scheme eddsa_prehashed, and its streaming signer is prehashed_signer`; superproject `crypto fixtures: Ed25519ph's streaming signer is prehashed_signer`. + +### Task 2.1: X25519 typed (D2, R3) + +**Files:** `curves/x25519.hpp` (rewritten), `backends/sodium.hpp` (engine unchanged but for X3/2.5 names), `async.hpp`, `keypair.hpp` (the `agree` catch-all's text), callers: `x25519_sodium_test`, `x25519_mock_test`, `x25519_wycheproof_sodium_test`, `oracle_25519_test`, `formats_25519_*`, `async_25519_test`, `timing_coverage_sodium_test`, `test/constant_time/{paths.hpp (sodium_x25519), dudect_sodium_test.cpp}`, `bench/operations.hpp`, examples `x25519_agree`, `ecdh_session` and any `grep -rn 'x25519::agree\|x25519::public_key(' libs/crypto` hit (the boxes and kx are fed `secret()->bytes()` and `public_key()->bytes()` until 2.2), `doc/x25519.adoc`. Superproject: fixtures `x25519_default`, `x25519_default_not_linked_on_emscripten`. + +**Interfaces (Produces):** in `curves::x25519`: +- `class public_key`: `static constexpr std::size_t public_key_size = 32;` `[[nodiscard]] static result from_bytes(std::span) noexcept` (`invalid_public_key` unless 32 bytes; nothing else checked; no guard); `[[nodiscard]] std::array const& bytes() const noexcept`; `operator==`; private default constructor, `friend struct detail::x25519_access;`. +- `template > class basic_keypair`: `family_type`, `name_type`, `backend_type`, `using public_key_type = x25519::public_key;`, `static constexpr std::size_t secret_key_size = 32;`; `static result from_secret(std::span secret_bytes) noexcept` (guard; `invalid_key_size`; the public key computed once by `engine::base`); `static result generate() noexcept` (guard; `random_device`; `entropy_unavailable`); `result public_key() const noexcept` and `result> secret() const noexcept` (copies, no guard; `invalid_state` when moved from); `result> agree(public_key_type const& peer_key) const noexcept` (guard; `weak_public_key` for an all-zero result, declassified as today); `async_from_secret`, `async_generate` (static), `async_agree(completion_executor, peer_key, completion_token) const` declared here, defined in `async.hpp`. State: `crypto::secret<32> secret_value_`, `std::array public_bytes_`, `bool keyed_` (moves exchange `keyed_`; `secret<32>`'s move wipes the source). `using keypair = basic_keypair<>;` +- `detail::x25519_access` (friend): `secret_bytes(kp) -> std::span` and `public_bytes(kp)`, for kx, the boxes and the sealed box without a nested guard (ruling P13); `curves::x25519::algorithm` becomes `detail::x25519_operations` (unguarded `base` and `agree` workers). +- `async.hpp`: `is_x25519_keypair_v` joins `is_webcrypto_keypair_v`; `async_agree(executor, x25519::basic_keypair const&, x25519::public_key const&, token)` calls the member; the byte form goes; `async_engine`'s shapes add `agree(executor, key_pair, peer_public_key, token)` for X25519. +- Removed: free `public_key(secret)`, `agree(secret, peer)`, `algorithm`. +- [ ] **Step 1: Failing tests** in `x25519_sodium_test.cpp`: `rfc7748`: section 6.1's Alice and Bob (the vectors already in the file) made with `from_secret` give the RFC's public keys and agree in both directions on the shared secret, and through `async_agree` (in `async_25519_test.cpp`, member and free); `secret_round_trip`: `from_secret(k.secret()->bytes())` has `k`'s public key; `from_bytes` of 31 and 33 bytes is `invalid_public_key`; `weak_peer`: `agree` with `from_bytes` of 32 zero bytes is `weak_public_key`; `moved_from` (Review Focus 2): a moved-from key pair's three members return `invalid_state`; `crypto::agree(k, peer)` and `crypto::from_secret` equal the members; `generate()` twice differ. `x25519_wycheproof_sodium_test.cpp` drives the typed forms. Run - Expected: compile errors. +- [ ] **Step 2: Implement**; `timing_coverage_sodium_test.cpp`: `from_secret`, `generate`, `agree` and the asynchronous forms enter their own guard, `public_key()`, `secret()`, `from_bytes` none. +- [ ] **Step 3: Migrate** the callers; `keypair.hpp`'s agree refusal text names `to_x25519()` once 2.3 lands (until then "an Ed25519 key pair agrees through X25519"). +- [ ] **Step 4: Run** `grep -rn 'x25519::agree\|x25519::public_key(\|x25519::algorithm' libs/crypto tools/test/fixtures/crypto_jamfiles` - Expected: nothing. Touched targets, `example//x25519_agree`, Emscripten `oracle_25519 formats_25519_webcrypto_oracle async_25519`, the two fixtures, `generate.py --check` - Expected: pass. +- [ ] **Step 5: Commit** `crypto: X25519 has a typed public key and a key pair, made, drawn and agreed like the other curves'`; superproject `crypto fixtures: X25519 agrees with typed keys`. + +### Task X4: Public names spelled out (controller ruling, owner decision 13, design D11, R22, R23) + +Runs right after 2.1 and before 2.2 (controller ruling, P30). It covers what 3.2 and 3.3 do not touch (R23): 3.2 moves the free `crypto::seal`/`open` and `ciphers::secretbox` into `secret_key_encryption` and 3.3 the free `crypto::async_seal`/`async_open`, written with decision 13's names; X4 renames, where they are today, the names those tasks then move and every other public abbreviation, so that nothing is renamed twice. No namespace or header moves here. Two commits in `libs/crypto`, parameters (A) and the other public names (B, R22, accepted by the coordinator), then one superproject commit. + +**Scope, measured on crypto a2ad4d1 and superproject 29a3439** (generated files, `doc/llms.txt` and `test/capabilities_test.cpp` excluded): `iv_bytes` 124 uses, `additional_data_bytes` 93, `iv_size` 81, `invalid_iv_size` 69, `max_iv_size` 12, `max_additional_data_size` 19, `aux_random`/`aux_random_bytes` 17; `ctx` none; no other abbreviated public parameter found (`der`, `pem`, `spki`, `pkcs8`, `xonly`, `kx`, ECDSA's `r`/`s` are proper names). In all 53 files in libs/crypto and 4 in the superproject (fixtures `chacha20_poly1305_default`, `chacha20_poly1305_original_default`, `xchacha20_poly1305_default`, and `CODING-GUIDELINES.md`). Recount with the Step 2 and Step 5 greps on the base the task starts from. + +**Files (A):** the parameters `iv_bytes`, `additional_data_bytes`, `aux_random`, `aux_random_bytes` (and the locals `zero_iv_bytes`, `aux_randomness` beside them) with their `@param` lines and the prose of the doc comments ("the IV", "additional data" become "the nonce", "associated data"), in every header that has them, the free `crypto::seal`/`open` (`ciphers/aead.hpp`) and `crypto::async_seal`/`async_open` (`async.hpp`) included in place, and the backends' engines and `detail/engines.hpp`'s contract comment, so that one grep proves it: `async.hpp`, `backends/bearssl.hpp`, `backends/openssl.hpp`, `backends/sodium.hpp`, `ciphers/aead.hpp`, `ciphers/gcm.hpp`, `curves/secp256k1.hpp` (BIP340's `sign(schnorr_t, Input const&, std::span auxiliary_random_bytes)` and the local `auxiliary_randomness`), `detail/engines.hpp`, `public_key_encryption/box.hpp`. A comment quoting a backend or a standard in its own words keeps them (OpenSSL's `EVP_CipherInit_ex` IV in `backends/openssl.hpp` lines 443-519, NIST SP 800-38D): each kept line is listed in the report. Pages: `aead.adoc`, `chacha.adoc`, `secretbox.adoc`, `public_key_encryption.adoc`, `async.adoc`, `secp256k1.adoc`, `curves.adoc`, and `crypto.json`'s texts that name a parameter or say "additional data" (the `ciphers` and `public_key_encryption` columns "Nonce (IV)" become "Nonce"; "yes, without additional data" becomes "yes, without associated data"). Examples, whose code the pages show: `async_seal.cpp`, `xchacha_seal.cpp`, `box_messages.cpp`, `file_share.cpp`, `failure_reasons.cpp` (locals `iv` become `nonce`, `additional_data` `associated_data`; `.expected` only if the output changes). `bench/operations.hpp`. Tests: the support headers whose functions mirror the API (`support/aead_checks.hpp`, `gcm_checks.hpp`, `timing_coverage.hpp`, `mock_backend.hpp`, `wycheproof_aead.hpp`, `wycheproof_gcm.hpp`, `gcm_spec_vectors.hpp`, `agreement.hpp`: their parameters and members named `iv`, `additional_data`) and the mock engines (`aead_box_mock_test.cpp`, `timing_mock_test.cpp`, `gcm_mock_test.cpp`); a test's own locals may keep `iv`. Superproject: the three fixtures (their locals `iv`, `additional_data`, as the examples). + +**Files (B):** `iv_size` -> `nonce_size`, `max_iv_size` -> `max_nonce_size`, `max_additional_data_size` -> `max_associated_data_size` (`ciphers/aead.hpp`'s families, `detail::aead_family` and the template, `ciphers/gcm.hpp`, `public_key_encryption/box.hpp`, the backends' uses), `error::invalid_iv_size` -> `error::invalid_nonce_size` in `error.hpp` (value 2 kept; doc comment "A nonce of a size the algorithm does not accept: a GCM nonce that is empty or longer than 128 bytes, another AEAD's or a box's nonce of another size than its own."; message "the nonce is not of a size the algorithm accepts"); every user, `grep -rlwE 'iv_size|max_iv_size|invalid_iv_size|max_additional_data_size' libs/crypto` (27 files on a2ad4d1, among them `error_test.cpp`, `doc/errors.adoc`'s table, `example/failure_reasons.cpp` and `.expected` ("empty iv: invalid_iv_size" becomes "empty nonce: invalid_nonce_size"), `example/file_share.cpp`, the `chacha_*`, `xchacha_sodium`, `gcm_*`, `secretbox_sodium`, `box_sodium` tests), `crypto.json`'s texts and `fixes`. +- **Not touched:** the namespaces and headers of the AEAD forms and secretbox (3.2, 3.3); webcpp::trystero's port of Trystero 0.27 (`/Users/you/dev/webcpporg/trystero-027`): its uses of the renamed names (`grep -rnwE 'iv_size|max_iv_size|invalid_iv_size|max_additional_data_size|aux_random' /Users/you/dev/webcpporg/trystero-027/webcpp/libs/trystero`, every file and line) go to this stream's HANDBACK; the superproject's `libs/trystero` names no crypto. webcpp::hash's HKDF parameters (`ikm`, `prk`, `info`): a change of hash's. + +**Interfaces (Produces):** +- Members and free forms unchanged but for the names: `seal(nonce_bytes, associated_data_bytes, data_bytes)`, `open(nonce_bytes, associated_data_bytes, data_bytes, tag_bytes)`, `gcm`'s `begin_seal(nonce_bytes, associated_data_bytes)`, `begin_open(nonce_bytes, associated_data_bytes)`, `async_seal(completion_executor, nonce_bytes, associated_data_bytes, data_bytes, completion_token)` and `async_open`, the boxes' `seal(nonce_bytes, data_bytes)` and `open(nonce_bytes, data_bytes, tag_bytes)`; the free `crypto::seal(keyed_aead, nonce_bytes, associated_data_bytes, data_bytes)`, `crypto::open`, `crypto::async_seal`, `crypto::async_open` (moved by 3.2 and 3.3); secp256k1's `sign(schnorr_t, Input const& message_input, std::span auxiliary_random_bytes)`. +- `static constexpr std::size_t nonce_size` (was `iv_size`) on `ciphers::aead`, `ciphers::gcm` (12, the recommended size), `public_key_encryption::basic_box` and the families; `ciphers::gcm::max_nonce_size` (128); `max_associated_data_size` on the families and `ciphers::aead`; `error::invalid_nonce_size = 2`. +- Removed with no alias: `iv_size`, `max_iv_size`, `max_additional_data_size`, `error::invalid_iv_size`. + +- [ ] **Step 1: Rename (A)** every name in Files (A); no behaviour changes, so the build (clang's `-Wdocumentation` checks every `@param` against its parameter), the doc build and the greps are its test. +- [ ] **Step 2: Run (A)** `grep -rnwE 'iv|ivs|iv_bytes|zero_iv_bytes|additional_data|additional_data_bytes|ad|aux_random|aux_random_bytes|aux_randomness|ctx' libs/crypto/include libs/crypto/example libs/crypto/bench libs/crypto/doc/*.adoc tools/test/fixtures/crypto_jamfiles` and `grep -rniE 'additional data|\bIVs?\b' libs/crypto/include libs/crypto/doc/*.adoc libs/crypto/doc/tables/crypto.json` - Expected: only the comments that quote a backend or a standard (listed in the report) and `changelog.adoc` (4.1). Then the clang whole build through `heavy.sh crypto-types` (`libs/crypto/test libs/crypto/example libs/crypto/bench`), the three fixtures, `generate.py --check`, the doc build `b2 ... libs/crypto/doc` - Expected: pass. +- [ ] **Step 3: Commit (A)** `crypto: public parameters are spelled out: nonce, associated data, auxiliary randomness`. +- [ ] **Step 4: Failing test (B)** `error_test.cpp`: `static_cast(crypto::error::invalid_nonce_size) == 2` and its message "the nonce is not of a size the algorithm accepts"; `static_assert`s in `synchronous_forms_test.cpp`: `ciphers::xchacha20_poly1305<>::nonce_size == 24`, `ciphers::aes256_gcm::nonce_size == 12`, `ciphers::aes256_gcm::max_nonce_size == 128`, `ciphers::secretbox<>::nonce_size == 24` (3.2 renames the namespace), `public_key_encryption::box<>::nonce_size == 24`, `ciphers::xchacha20_poly1305<>::max_associated_data_size` defined. Run `b2 ... toolset=clang libs/crypto/test//error libs/crypto/test//synchronous_forms` - Expected: no member `invalid_nonce_size`, `nonce_size`. +- [ ] **Step 5: Implement and migrate (B)**; message test `iv_size_removed` (`ciphers::xchacha20_poly1305<>::iv_size` and `crypto::error::invalid_iv_size`: `{{no member named 'iv_size' in}}` and `{{no member named 'invalid_iv_size' in}}`, substrings; `alone`, native wasip2 wasip3; fixes "Name nonce_size, max_nonce_size and error::invalid_nonce_size: crypto spells its names out."); regenerate. Run `grep -rnwE 'iv_size|max_iv_size|invalid_iv_size|max_additional_data_size|iv_bytes|additional_data_bytes|aux_random|aux_random_bytes' libs/crypto/include libs/crypto/test libs/crypto/example libs/crypto/bench libs/crypto/doc/*.adoc libs/crypto/doc/tables libs/crypto/meta tools/test/fixtures/crypto_jamfiles` - Expected: only `iv_size_removed` and `changelog.adoc` (4.1). Then the clang whole build through `heavy.sh crypto-types`; the message tests whose code changed (native, wasip2, wasip3) and their MSVC twins (`webcpp-msvc 14.5 -- libs/crypto/test/msvc//...` through `heavy.sh`); `example//async_seal example//file_share example//xchacha_seal example//box_messages example//failure_reasons`; Emscripten `async_gcm secretbox_sodium chacha_sodium` through `heavy.sh`; the constant-time lane's `paths` natively (`libs/crypto/test/constant_time`, through `heavy.sh crypto-types`); the fixtures `python3 tools/test/crypto_jamfiles_test.py chacha20_poly1305_default chacha20_poly1305_original_default xchacha20_poly1305_default` (native, then Emscripten); `generate.py --check`, `generate_test.py`, the doc build - Expected: pass. +- [ ] **Step 6: Commit (B)** `crypto: a nonce's size and its error say nonce, and the associated data's limit says associated data`; superproject: `crypto fixtures and guidelines: crypto's public names are spelled out` (the three fixtures; `CODING-GUIDELINES.md`: in the crypto chapter's current rules, the bullet at about line 7107 becomes "The incremental seal is `begin_seal(nonce, associated_data)`, `update(data)` and `result()`", "Additional data is taken whole" becomes "Associated data is taken whole"; a new bullet after the namespaces' bullet: "**Public names are spelled out; only algorithm and format proper names stay acronyms.** A nonce is `nonce` (`nonce_bytes`, `nonce_size`, `invalid_nonce_size`), associated data `associated_data`, a context `context`; `aes`, `gcm`, `chacha20`, `hmac`, `hkdf`, `ecdsa`, `eddsa`, `sha256`, `kx`, `der`, `pem`, `spki` and `pkcs8` stay, as do a standard's own variable names (ECDSA's `r` and `s`) and the standard library's `max_`. The owner's rule of 2026-11-23: a reader should not need a glossary for a parameter. Source: `libraries/crypto/openspec/changes/uniform-types/design.md` owner decision 13, D11 (proposals)."; in hash's chapter, one bullet: "**hash follows crypto's naming rule: public names spelled out, algorithm proper names excepted.** HKDF's `ikm`, `prk` and `info` are renamed by a change of hash's." with the same Source; dated records (about line 8756 onwards) keep the names of their time). Record trystero-027's uses for the HANDBACK. + +### Task 2.2: crypto_kx, the boxes and the sealed box on typed keys (D3, R5, R6, owner decision 7) + +**Files:** `key_exchange/kx.hpp`, `public_key_encryption/{box,sealed_box}.hpp`, `backends/sodium.hpp` (kx engine over bytes; `kx_state` removed; the sealed box engine unchanged), callers: `kx_sodium_test`, `kx_wipe_sodium_test`, `box_sodium_test`, `aead_box_mock_test`, `timing_coverage_sodium_test`, `paths.hpp` (`sodium_box`, `sodium_sealed_box`, `sodium_kx`), examples `kx_session`, `box_messages`, `file_share`, `doc/kx.adoc`, `doc/public_key_encryption.adoc`. Superproject: fixtures `kx_default`, `box_*_default`, `sealed_box_default`. + +**Interfaces (Produces):** +- `key_exchange::kx_keypair`: `static result from_keypair(x25519::basic_keypair key_pair) noexcept` (a sink, by value; ruling P14); `static result derive_from_seed(std::span seed_bytes) noexcept` (`invalid_key_size` unless 32; `engine::seed_keypair` = `crypto_kx_seed_keypair`, its public half wiped, the secret given to `x25519::basic_keypair::from_secret`); `static result generate() noexcept`; `result public_key() const noexcept`; `x25519::basic_keypair const& keypair() const noexcept`; `result client_session_keys(x25519::public_key const& server_public_key) const noexcept` and `server_session_keys(x25519::public_key const& client_public_key)`; `weak_public_key` where libsodium refuses. Engine: `seed_keypair(seed, secret_out)`, `client(secret, public, peer, receive, transmit)`, `server(...)`, each over `std::span`; a `static_assert(supports_v)` with the text "webcpp::crypto: key_exchange::kx_keypair holds an X25519 key pair of its own backend, which has no X25519." +- `public_key_encryption::basic_box::from_keys(x25519::basic_keypair const& own_keypair, x25519::public_key const& peer_public_key)`; the byte form goes. +- `basic_sealed_box::seal(x25519::public_key const& recipient_public_key, std::span message_bytes, std::span output_bytes)`, `open(x25519::basic_keypair const& recipient_keypair, std::span sealed_bytes, std::span output_bytes)`; the byte forms go. +- [ ] **Step 1: Failing tests**: `kx_sodium_test.cpp` - `client_server`: the client's transmit key is the server's receive key and the reverse; `seed_is_not_secret` (spec): `derive_from_seed(seed)` gives the public key and session keys of libsodium's `crypto_kx_seed_keypair(seed)` called in the test, and its public key differs from `from_keypair(*x25519::keypair::from_secret(seed))`'s; `from_keypair` keeps the key pair (`keypair().public_key()`); a session with a zero peer key is `weak_public_key`. `box_sodium_test.cpp` - two parties' `from_keys` seal and open each other's messages; `open_failures` (Review Focus 3): one flipped byte gives `authentication_failed` with `data` zeroed, a 12-byte nonce `invalid_nonce_size` with `data` untouched; a small-order peer gives `weak_public_key`; the sealed box round trip and its tampered case (`authentication_failed`, `output` zeroed). `kx_wipe_sodium_test.cpp` probes the inner key pair's secret storage after a move and after destruction. Run - Expected: compile errors. +- [ ] **Step 2: Implement**; coverage: every new function enters its own guard; `keypair()` and `public_key()` none. +- [ ] **Step 3: Migrate** the callers and pages; the kx page says `derive_from_seed` hashes the seed (BLAKE2b-256) and `from_keypair` takes the secret as is. +- [ ] **Step 4: Run** the touched tests, `example//kx_session example//box_messages example//file_share`, the fixtures, `generate.py --check` - Expected: pass. +- [ ] **Step 5: Commit** `crypto: crypto_kx, crypto_box and the sealed box take X25519's typed keys`; superproject `crypto fixtures: crypto_kx and the boxes on typed X25519 keys`. + +### Task 2.3: Ed25519 to X25519, typed (D3, R4) + +**Files:** `curves/ed25519.hpp` (includes `curves/x25519.hpp`), `keypair.hpp` (agree refusal text), callers (`grep -rn 'x25519_secret\|to_x25519_public' libs/crypto`: 6 tests, 1 example, 7 doc pages, `README.md`), `paths.hpp` (`sodium_ed25519` converts). + +**Interfaces (Produces):** +- `[[nodiscard]] result> ed25519::basic_keypair::to_x25519() const noexcept` (guard; `static_assert(supports_v, "webcpp::crypto: to_x25519: this backend has no X25519; libsodium has both.")`; `engine::x25519_secret`, then `x25519::basic_keypair::from_secret`, the intermediate secret a `secret<32>`; ruling P20). +- `template > [[nodiscard]] result ed25519::public_key::to_x25519() const noexcept` (guard; `invalid_public_key` when libsodium's `pk_to_curve25519` refuses: not canonical or of small order). +- Free `template requires requires(Value const& v) { v.to_x25519(); } [[nodiscard]] auto to_x25519(Value const& converted_value) noexcept` in `ed25519.hpp`, guard, calling the member. Synchronous only (R4). +- Removed: `x25519_secret()`, `to_x25519_public`. Engine functions keep their names. +- [ ] **Step 1: Failing tests** in `ed25519_sodium_test.cpp`: `conversion` (spec): RFC 8032 test 1's key pair `to_x25519()` has `public_key()` equal to `public_key()->to_x25519()`, and both equal libsodium's `crypto_sign_ed25519_sk_to_curve25519`/`pk_to_curve25519` called in the test; ed25519-speccheck's small-order key 0 and a non-canonical key give `invalid_public_key`; `crypto::to_x25519` equals both members; the converted key pair agrees with an X25519 peer. Run - Expected: compile errors. +- [ ] **Step 2: Implement**; coverage: both members and the free form enter their own guard. +- [ ] **Step 3: Migrate** the callers; `agree`'s refusal text: "... an Ed25519 key pair agrees through X25519: convert it with to_x25519()." +- [ ] **Step 4: Run** `grep -rn 'x25519_secret\|to_x25519_public' libs/crypto --include=*.hpp --include=*.cpp --include=*.adoc --include=*.json --include=*.md` - Expected: only the engine functions, which keep their names (`x25519_secret` and `to_x25519_public` in `backends/sodium.hpp` and in the primary `ed25519_engine` of `curves/ed25519.hpp`, with their two calls there), and `changelog.adoc` (4.1). Touched tests, Emscripten `oracle_25519`, `generate.py --check` - Expected: pass. +- [ ] **Step 5: Commit** `crypto: Ed25519's key pair and public key convert to X25519's typed keys`. + +### Task 3.1: Three key pair concepts (D4) + +**Files:** `keypair.hpp`, `signing.hpp` (`crypto::sign`'s refusal), `async.hpp`, `curves/{ed25519,x25519,p256,secp256k1}.hpp` (`static_assert`s where the default backend is linked, as today), `test/keypair_test.cpp`, `test/signing_curves_test.cpp`, new message tests `sign_x25519`, `agree_ed25519`, `async_sign_x25519`. + +**Interfaces (Produces):** + +```cpp +template +concept keypair = requires { + typename Keypair::public_key_type; + { Keypair::from_secret(std::declval&>()) } -> std::same_as>; + { Keypair::generate() } -> std::same_as>; + { std::declval().public_key() } -> std::same_as>; + { std::declval().secret() } -> std::same_as>>; +}; +namespace detail { +// signs_as_declared also requires the result to be result> +template +concept signing_keypair_over = keypair && signs_some_scheme_v && signs_every_declared_v; +template inline constexpr bool is_secret_result_v = false; // true for result> +} +template concept signing_keypair = detail::signing_keypair_over; +template concept agreement_keypair = keypair && requires { + requires detail::is_secret_result_v().agree( + std::declval()))>; +}; +``` + +- `crypto::sign`/`async_sign` require `signing_keypair`; `crypto::agree`/`async_agree` require `agreement_keypair` (`async_agree` becomes one template for P-256 and X25519). Refusals, each the first `static_assert` reached: `crypto::sign` of an `agreement_keypair` that is not a `signing_keypair`: "webcpp::crypto: sign: X25519 key pairs agree; they do not sign: sign with an Ed25519 key pair, which to_x25519() converts for agreement."; `crypto::agree` of a `signing_keypair` that is not an `agreement_keypair`: "webcpp::crypto: agree: Ed25519 key pairs sign; they do not agree: convert one with to_x25519() and agree with the X25519 key pair."; the existing texts stay for the other mismatches. +- `static_assert`s per D4's table in each curve header. +- [ ] **Step 1: Failing tests** `keypair_test.cpp`: stand-ins (signing only, agreement only, both, missing `from_secret`, `sign` returning bytes) give the three concepts' verdicts; the four curves' rows of D4's table; `from_secret_round_trip` (spec) for the four curves. Run - Expected: failures. +- [ ] **Step 2: Implement**; the message tests `sign_x25519`, `agree_ed25519`, `async_sign_x25519` (`alone`, `crypto.json` entries); regenerate. +- [ ] **Step 3: Run** `keypair`, `signing`, `signing_curves`, `synchronous_forms`, the async tests, the message tests, a clang whole build through `heavy.sh crypto-types`, `generate.py --check` - Expected: pass. +- [ ] **Step 4: Commit** `crypto: key pairs are checked by what they do: keypair, signing_keypair and agreement_keypair`. + +### Task 3.2: The AEAD and box concepts, the AEAD forms and secretbox moved to `secret_key_encryption`, secretbox without associated data (D5, D11, R7, R21, R23, owner decision 13) + +Written with decision 13's names (R23): this task creates the AEAD contract's header and namespace, moves the free `crypto::seal`/`open` and `ciphers::secretbox` there, and migrates their callers; X4 has already spelled the names out (`nonce_bytes`, `associated_data_bytes`, `nonce_size`, `max_associated_data_size`, `invalid_nonce_size`), so what moves carries them. + +**Files:** Create `include/webcpp/crypto/secret_key_encryption/aead.hpp` (guard `WEBCPP_CRYPTO_SECRET_KEY_ENCRYPTION_AEAD_HPP`; file comment: the AEAD contract's namespace and why, D11; no backend; in the backend-free include boundary and the headers-alone list): namespace `webcpp::crypto::secret_key_encryption::aead` with the concepts and the free `seal`/`open` moved from `ciphers/aead.hpp` (bodies, guards and doc comments kept, now constrained by `cipher`); `ciphers/aead.hpp` and `ciphers/gcm.hpp` include it, so that every AEAD's header still brings its free forms. Create `include/webcpp/crypto/secret_key_encryption/authenticated_box.hpp` (the concept and the box forms, no backend; in the include boundary and the headers-alone list; included by `secret_key_encryption/secretbox.hpp` and `public_key_encryption/box.hpp`), `test/aead_concepts_test.cpp`, message test `seal_box_associated_data`. `git mv include/webcpp/crypto/ciphers/secretbox.hpp include/webcpp/crypto/secret_key_encryption/secretbox.hpp` (guard `WEBCPP_CRYPTO_SECRET_KEY_ENCRYPTION_SECRETBOX_HPP`, namespace `webcpp::crypto::secret_key_encryption`, file comment: why the namespace, parallel to `public_key_encryption::box`): `basic_secretbox`, the families, `detail::secretbox_state`/`secretbox_engine` primaries with the generated `REFUSE_SECRETBOX_*` macros. Modify `ciphers/aead.hpp` (secretbox families and `aead_family` specializations out; the free forms out; file comment), `ciphers/gcm.hpp` (file comment lines 10-11, include comment line 20, the doc comments naming `crypto::seal`), `public_key_encryption/box.hpp` (includes `authenticated_box.hpp`; its `static_assert`), `backends/sodium.hpp` (`secretbox_state`/`secretbox_engine` specializations replace the `aead_engine` ones, no associated-data parameter; ruling P10), `crypto.hpp` (the two new headers and `secret_key_encryption/secretbox.hpp` in place of `ciphers/secretbox.hpp`; its file comment), `meta/include-boundaries.json`, `test/Jamfile` (headers-alone list; the comments at lines 619 and 681), `test/messages/aead_not_a_family` and its MSVC twin (its text lists four families fewer). Callers of the moved names (`grep -rnE 'crypto::(seal|open)([^_a-zA-Z]|$)|ciphers::(basic_)?secretbox|ciphers/secretbox\.hpp'`, on a2ad4d1: 17 tests among them `synchronous_forms_test.cpp`, `support/timing_coverage.hpp` (its labels and `covered`'s second argument, the name the guard is expected to enter, become `secret_key_encryption::aead::seal` and `open`), `timing_coverage_{bearssl,openssl,sodium}_test.cpp`, `secretbox_sodium_test.cpp`, `box_sodium_test.cpp`, `allocation_sodium_test.cpp`, `wipe_objects_test.cpp`, `windows_h_before_test.cpp`, `windows_h_after_test.cpp`, `default_backend_test.cpp` (its `#error` text), `test/constant_time/paths.hpp` (`seal_and_open`); message tests `seal_asynchronous_backend`, `box_default_not_linked` and its MSVC twin; examples `file_share.cpp`, `xchacha_seal.cpp`; `README.md` line 12). Pages: new `doc/secret_key_encryption.adoc` (`[#crypto-secret-key-encryption] == Secret-key encryption: \`webcpp::crypto::secret_key_encryption\``, built as `public_key_encryption.adoc` is: what the namespace holds and why (D11), `include::generated/namespace-secret_key_encryption.adoc[]`, a section `[#crypto-aead-contract] === The AEAD contract: \`secret_key_encryption::aead\``, the box forms, then `include::secretbox.adoc[]`); `crypto.adoc` (includes it after `block.adoc` in place of `secretbox.adoc`; the namespaces' list at line 93); `secretbox.adoc` (anchor `crypto-secretbox` kept), `aead.adoc`, `curves.adoc` (the four forms), `chacha.adoc`, `everyday.adoc`, `public_key_encryption.adoc`, `backends.adoc`. `doc/tables/crypto.json`: the rows `secretbox` and `secretbox_xchacha20poly1305` (`namespace` `secret_key_encryption`, `api`, `header`), the two families' capability entries (`group` `secret_key_encryption`, `header`, `type` `secret_key_encryption::secretbox<{backend}>` and its twin), a new `namespaces` entry `secret_key_encryption` (the `ciphers` table's columns; the two secret box rows moved from `ciphers`, whose part "Secret boxes" goes; a row "`aead`: the AEAD contract"), the use cases and `fixes` naming a secret box or `crypto::seal`, the new message tests' `fixes`; `generate.py` reads `namespaces` generically (if a check refuses the new one, add it there and in `generate_test.py`); regenerate. Superproject: fixtures `secretbox_xsalsa20poly1305_default`, `secretbox_xchacha20poly1305_default`, `box_default_not_linked_on_emscripten`. + +**Interfaces (Produces):** +- `secret_key_encryption::aead::cipher`: `C::key_size`, `C::nonce_size`, `C::tag_size` convertible to `std::size_t`; `typename C::result_type`; `{ C::from_key(span&) } -> same_as>`; `{ c.seal(span const&, span const&, std::span&) } -> same_as>`; `{ c.open(span, span, std::span, span) } -> same_as>`. +- `secret_key_encryption::aead::streaming_cipher`: `cipher` and `begin_seal(nonce, associated_data)`, `update(data)`, `result()`, `begin_open(nonce, associated_data)`, `authenticate(associated_data_piece)`, `decrypt(data)`, `verify(tag)`, `end_open()` with `gcm`'s types. +- `secret_key_encryption::authenticated_box` (in `secret_key_encryption/authenticated_box.hpp`, R21): the sizes, `result_type`, `{ c.seal(span, std::span&) } -> same_as>`, `{ c.open(span, std::span, span) } -> same_as>`. +- `template class secret_key_encryption::basic_secretbox` with `from_key`, `seal(nonce, data)`, `open(nonce, data, tag)`, the guards, zeroing and move rules of `ciphers::aead`; `secret_key_encryption::secretbox` and `secretbox_xchacha20poly1305` its aliases. +- Free forms: `secret_key_encryption::aead::seal(C& keyed_cipher, std::span nonce_bytes, std::span associated_data_bytes, std::span data_bytes)`/`open(..., std::span tag_bytes)` requiring `cipher` (the bodies of `crypto::seal`/`open`); `secret_key_encryption::seal(C&, nonce, data)`/`open(C&, nonce, data, tag)` requiring `authenticated_box`, in `authenticated_box.hpp`, for a secret box and a crypto_box alike (R21), none in `crypto::` nor in `public_key_encryption`; a catch-all `secret_key_encryption::aead::seal(C&, nonce, associated_data, data)` for an `authenticated_box` with "webcpp::crypto: seal: a secret box or a crypto_box takes no associated data: secret_key_encryption::seal(box, nonce, data)." (and `open`'s twin). +- `static_assert`s per D5's table in `ciphers/gcm.hpp`, `ciphers/chacha20_poly1305.hpp`, `secret_key_encryption/secretbox.hpp` and `public_key_encryption/box.hpp`. +- Removed with no alias: `crypto::seal`, `crypto::open`, `ciphers::secretbox`, `ciphers::secretbox_xchacha20poly1305`, ``. Unchanged: `ciphers::gcm`, `aes128_gcm`, `aes256_gcm`, `chacha20_poly1305`, `chacha20_poly1305_original`, `xchacha20_poly1305`, the AES block ciphers and the template `ciphers::aead` (owner decision 13); the families, their capability rows and Jamfile aliases. +- [ ] **Step 1: Failing tests**: `secretbox_sodium_test.cpp` includes `` - `secret_key_encryption::secretbox<>`'s `seal(nonce, data)` gives `crypto_secretbox_detached`'s ciphertext and tag (called in the test), and `secret_key_encryption::seal(box, nonce, data)` the same (and `secret_key_encryption::seal(crypto_box, nonce, data)` the crypto_box's member's, in `box_sodium_test.cpp`); `!requires { box.seal(nonce, associated_data, data); }`; `open_failures` (Review Focus 3); `synchronous_forms_test.cpp`: `crypto::secret_key_encryption::aead::seal(cipher, nonce, associated_data, data)` and `open` on AES-GCM and XChaCha20-Poly1305 give the members' results, `` alone included for the second (spec: a cipher's header brings its free forms); `aead_concepts_test.cpp` - D5's table and stand-ins (a type without `open` is no `cipher`; `gcm` is a `streaming_cipher`, `chacha20_poly1305` a `cipher` and not a `streaming_cipher`; no type is both `cipher` and `authenticated_box`). Run - Expected: failures. +- [ ] **Step 2: Implement**; coverage of `basic_secretbox`'s three members on sodium, and of the moved free forms under their new names. +- [ ] **Step 3: Migrate** every caller, page and `crypto.json` entry listed; message tests, each `alone` with its `crypto.json` `fixes`, native wasip2 wasip3: `seal_box_associated_data` (`secret_key_encryption::aead::seal(secretbox, nonce, associated_data, data)`: the catch-all's text); `seal_removed` (`` included, `webcpp::crypto::seal(cipher, nonce, associated_data, data)` and `webcpp::crypto::open(...)` on a `chacha20_poly1305<>&` parameter: `{{no member named 'seal' in namespace 'webcpp::crypto'}}`, `{{no member named 'open' in namespace 'webcpp::crypto'}}`; fixes "Call crypto::secret_key_encryption::aead::seal and open, in , which every AEAD's header includes."); `secretbox_header_removed` (`#include `: `{{'webcpp/crypto/ciphers/secretbox.hpp' file not found}}`); `secretbox_removed` (`crypto::ciphers::secretbox<>` and `secretbox_xchacha20poly1305<>` with the new header included: `{{no member named 'secretbox' in namespace 'webcpp::crypto::ciphers'}}`, `{{no member named 'secretbox_xchacha20poly1305' in namespace 'webcpp::crypto::ciphers'}}`); regenerate. +- [ ] **Step 4: Run** `grep -rn 'aead/third_party//sodium /webcpp/asio//asio ;`), `test/async_post_test.cpp`, `test/async_gcm_test.cpp` (callers of the moved forms), `example/async_seal.cpp`; message tests `async_seal_xchacha`, `async_open_xchacha`, `async_from_key_xchacha` (messages and MSVC twins) rewritten on a stand-in browser backend, and new `async_seal_removed`; `doc/async.adoc`, `doc/secret_key_encryption.adoc`, the file comment of `async.hpp`; `crypto.json` (the asynchronous row's `api` "async_from_key, secret_key_encryption::aead::async_seal, secret_key_encryption::aead::async_open"; the use case whose `api` is `async_seal`, `async_open`). + +**Interfaces (Produces):** +- Free `secret_key_encryption::aead::async_seal(executor, C& c, nonce, associated_data, data, token)` and `secret_key_encryption::aead::async_open(executor, C& c, nonce, associated_data, data, tag, token)` requiring `cipher` (the moved AES-GCM forms, extended); `secret_key_encryption::async_seal(executor, C& c, nonce, data, token)` and `secret_key_encryption::async_open(executor, C& c, nonce, data, tag, token)` requiring `authenticated_box`, for a secret box and a crypto_box (R21); `crypto::async_from_key(executor, key_bytes, token)` for every `cipher` and secretbox. Members `c.async_seal`, `c.async_open` on `ciphers::aead`, `secret_key_encryption::basic_secretbox`, `public_key_encryption::basic_box`, and static `async_from_key` on `ciphers::aead` and `basic_secretbox`, declared in the classes, defined in `async.hpp`. No `async_from_keys` for crypto_box (ruling P11). Removed with no alias: `crypto::async_seal`, `crypto::async_open`. +- On a synchronous backend: `complete_by_post` of the synchronous member. On a backend with `asynchronous_backend_v`: AES-GCM goes to `async_engine`; any other type stops at the first statement after the guard, before any member of `C` is named (ruling P12): "webcpp::crypto: WebCrypto has no ChaCha20-Poly1305, XChaCha20-Poly1305, secret box or crypto_box: their async_seal, async_open and async_from_key run on a native backend; on the browser's backend only AES-GCM is asynchronous." +- [ ] **Step 1: Failing tests** `async_aead_test.cpp`: `xchacha_async` (spec): `co_await crypto::secret_key_encryption::aead::async_seal(executor, cipher, nonce, associated_data, data, use_awaitable)` with `ciphers::xchacha20_poly1305` completes with the synchronous `seal`'s tag and ciphertext, member and free, then `async_open` restores the plaintext; the same for `chacha20_poly1305`, and for `secret_key_encryption::secretbox` and `public_key_encryption::box` through `secret_key_encryption::async_seal`; `async_from_key` equals `from_key`; `never_inline` (Review Focus 4): a callback's flag is unset when `async_seal`/`async_open` return and set after `run()`; a wrong tag completes with `authentication_failed` and zeroed data. Run - Expected: compile errors. +- [ ] **Step 2: Implement**; coverage: each new free and member function enters its own guard; migrate the moved forms' callers (`async_gcm_test.cpp`, `async_post_test.cpp`, `example/async_seal.cpp`, the pages, `crypto.json`). +- [ ] **Step 3: Message tests**: the three cases take a `stand_in_browser` backend (`asynchronous_backend_v` specialized true, as `seal_asynchronous_backend` does) and a function taking `ciphers::xchacha20_poly1305&` (or `secret_key_encryption::secretbox`), expecting the text above, `alone`; their MSVC twins likewise; `async_seal_removed` (`` and `` included, `webcpp::crypto::async_seal(executor, cipher, nonce, associated_data, data, token)` on an `aes256_gcm&` parameter: `{{no member named 'async_seal' in namespace 'webcpp::crypto'}}`; fixes "Call crypto::secret_key_encryption::aead::async_seal and async_open.", `alone`, native wasip2 wasip3); `crypto.json` `fixes` rewritten; regenerate. +- [ ] **Step 4: Run** `grep -rnE 'crypto::async_(seal|open)([^_a-zA-Z]|$)' libs/crypto/include libs/crypto/test libs/crypto/example libs/crypto/doc/*.adoc libs/crypto/doc/tables tools/test/fixtures/crypto_jamfiles` - Expected: only `async_seal_removed` and `changelog.adoc` (4.1). `async_aead`, `async_gcm`, `async_post`, the message tests, `example//async_seal`, `EM_CACHE=... b2 ... toolset=emscripten libs/crypto/test//async_aead libs/crypto/test//async_gcm` through `heavy.sh`, `generate.py --check` - Expected: pass. +- [ ] **Step 5: Commit** `crypto: every AEAD and box seals and opens asynchronously on a native backend through secret_key_encryption, the browser keeping AES-GCM`. + +### Task X1: A throwing `getRandomValues` never terminates the page (controller ruling) + +**Context:** on Emscripten `read_entropy` calls `getentropy`, which Emscripten's `libwasi.js` serves with `randomFill` (`crypto.getRandomValues`, or node's `randomFillSync` while `MIN_NODE_VERSION` is below 19; `random_get__nothrow`): an exception thrown there unwinds through WebAssembly and aborts the program. webcpp::trystero's note P2-R16 keeps it out of WebAssembly the same way. + +**Files:** `include/webcpp/crypto/detail/entropy.hpp`, new `test/random_device_browser_test.cpp` (`crypto-run random_device_browser : random_device_browser_test.cpp : /third_party//bearssl : emscripten ;`), `doc/entropy.adoc`. + +- [ ] **Step 1: Reproduce end to end.** `random_device_browser_test.cpp`, under node: `EM_ASM` replaces `globalThis.crypto.getRandomValues` and, when `typeof require === 'function'`, `require('node:crypto').randomFillSync` with functions that throw `new Error('planted')`, before any draw; then `random_device{}.fill(buffer)` must return `error::entropy_unavailable` with `buffer` zeroed (it was filled with `0xa5`), and `curves::p256::basic_keypair::generate()` `entropy_unavailable`; restoring the originals, `fill` succeeds; `Object.defineProperty(globalThis, 'crypto', {value: undefined, configurable: true})` gives `errc::not_supported` (an audio worklet's case). Run `EM_CACHE=... b2 ... toolset=emscripten libs/crypto/test//random_device_browser` - Expected today: the program aborts with "planted" (record the output in the commit message's body). +- [ ] **Step 2: Fix** in `entropy.hpp`, under `#elif defined(__EMSCRIPTEN__)` (the test seam keeps priority): + +```cpp +// 0: filled; 1: no crypto.getRandomValues (an audio worklet); 2: it threw. +EM_JS(int, webcpp_crypto_fill_random, (std::uint8_t* output_bytes, std::size_t byte_count), { + const source = globalThis.crypto; + if (!source || typeof source.getRandomValues !== 'function') return 1; + try { + const drawn = new Uint8Array(byte_count); // a fresh buffer: never a view of shared memory + source.getRandomValues(drawn); + HEAPU8.set(drawn, output_bytes); + return 0; + } catch (error) { + return 2; + } +}); +``` + +`read_entropy` maps 1 to `errc::not_supported` and 2 to `error::entropy_unavailable` (ruling P15); the doc comment says why Emscripten's `getentropy` is not called. +- [ ] **Step 3: Run** `random_device_browser`, `random_device`, `random_device_failing` on Emscripten and `random_device` natively - Expected: pass. +- [ ] **Step 4: The page** (`entropy.adoc`): the browser case in the errors' list. +- [ ] **Step 5: Commit** `crypto: a throwing getRandomValues gives entropy_unavailable in the browser, never a terminated page`. + +### Task X1b: libsodium's randomness through crypto on Emscripten (controller ruling) + +**Context:** on Emscripten libsodium draws from its own JavaScript (`randombytes.c`: `javascript_stir`, which `sodium_init` runs, tries `crypto.getRandomValues`, then node's `require('crypto').randomBytes`, then throws "No secure random number generator found"; `javascript_random` serves every `randombytes_buf`, the sealed box's ephemeral key among them). A throw there unwinds through WebAssembly. Feasible without patching libsodium: `randombytes_set_implementation` is public API, and an implementation installed before the first `sodium_init` replaces the JavaScript one, stir included. Its `buf` returns `void`, so a failure is observed through a flag that crypto reads around the calls it makes. + +**Files:** `backends/sodium.hpp` (`sodium_ready`, the sealed box engine's `seal`), new `test/sodium_entropy_browser_test.cpp` (`crypto-run sodium_entropy_browser : sodium_entropy_browser_test.cpp : /third_party//sodium : emscripten ;`, a program of its own so that no libsodium call precedes the plant), `doc/entropy.adoc`. + +- [ ] **Step 1: Reproduce.** `EM_ASM` replaces `globalThis.crypto.getRandomValues` and `require('crypto').randomBytes` with throwing functions before any libsodium call; then `public_key_encryption::sealed_box::seal(recipient, message, output)` (`recipient` from `x25519::public_key::from_bytes`, which calls no backend). Run `EM_CACHE=... b2 ... toolset=emscripten libs/crypto/test//sodium_entropy_browser` - Expected today: the program aborts ("No secure random number generator found"); record the output in the commit message's body. +- [ ] **Step 2: Implement** in `backends/sodium.hpp`, under `#ifdef __EMSCRIPTEN__`: + +```cpp +namespace webcpp::crypto::detail { +inline thread_local int sodium_draws_watched = 0; // the depth of the calls crypto observes +inline thread_local bool sodium_draw_failed = false; // set by a failed draw inside one +inline void sodium_entropy_buf(void* output_data, std::size_t byte_count) { + if (!fill_from_system({static_cast(output_data), byte_count})) { // zeroed + if (sodium_draws_watched == 0) { + sodium_misuse(); // no caller could see the failure: libsodium's own reaction + } + sodium_draw_failed = true; + } +} +// random() draws 4 bytes through buf; stir() does nothing; implementation_name() "webcpp-crypto"; +// uniform and close are null (libsodium derives uniform from random). +inline randombytes_implementation const sodium_entropy{&sodium_entropy_name, &sodium_entropy_random, + &sodium_entropy_stir, nullptr, + &sodium_entropy_buf, nullptr}; +struct sodium_draw_watch { // RAII: ++watched and clears the flag; --watched on exit + [[nodiscard]] bool failed() const noexcept { return sodium_draw_failed; } +}; +} +``` + +`sodium_ready()` calls `randombytes_set_implementation(&sodium_entropy)` once (a function-local static), before its first `sodium_init()`, on Emscripten only. The sealed box engine's `seal` holds a `sodium_draw_watch` around `crypto_box_seal` and, when a draw failed, wipes `out` and returns `error::entropy_unavailable`. +- [ ] **Step 3: Tests** in the same program, after the plant: `seal` returns `entropy_unavailable` with `output` zeroed; `ed25519::keypair::from_secret(seed)` succeeds (`sodium_init`'s stir is crypto's); restoring the originals, `seal` succeeds and `open` with the recipient's key pair restores the message. Run it, `box_sodium` and `random_device_browser` on Emscripten, `box_sodium` natively - Expected: pass. +- [ ] **Step 4: The page** (`entropy.adoc`): libsodium draws through crypto on Emscripten; a program that sets its own libsodium implementation sets it after crypto's first libsodium call. +- [ ] **Step 5: Commit** `crypto: libsodium draws through crypto's entropy in the browser, and a sealed box reports a failed draw`. + +### Task X5: The remaining spelled-out names (controller ruling, owner decision 14, design D12, R24, R25) + +Runs after X1b and before 4.1 (controller ruling, P33): every name it renames is built by then, and 4.1 writes the pages, the tables and the changelog once, with the final names. No behaviour changes: the signatures, guards, capability rows (`key_tweaks`, `musig`, `silent_payments`), Jamfile aliases and headers stay; only the names move (R25). No compatibility alias. Three commits in `libs/crypto` (the refusal's text; the AEAD template; secp256k1's names), so that review can take them apart, then one superproject commit. + +**Scope, measured on crypto 0197c8c and superproject c5da5cf** (tracked files; generated files, `doc/llms.txt` and `test/capabilities_test.cpp` excluded, which `generate.py` rewrites): the template `ciphers::aead` (`ciphers::aead`, `aead<`, `class aead`) about 72 uses in 25 files; `nonce_gen` 61, `pubkey_tweak_add` 22, `pubkey_tweak_mul` 17, `pubkey_negate` 18, `pubkey_combine` 32, `seckey_tweak_add` 35, `seckey_tweak_mul` 21, `seckey_negate` 19 (225 uses in 27 files); `prevouts_summary` 14 and `make_prevouts_summary` 40 (54 uses in 15 files, R24); D6's old text in 13 files (`detail/asynchronous.hpp`, `ciphers/aead.hpp`'s comment, `crypto.json`, ten message tests). In all 64 files in libs/crypto. Superproject: 7 uses in 3 fixtures (`aead_not_a_family_on_emscripten`'s `app.cpp` and `.outcome`, `secp256k1_musig_default`, `secp256k1_silent_payments_default`) and the naming rule in `CODING-GUIDELINES.md`; the dated records of section 17 (about lines 8767, 8825, 8838, 8948) keep the names of their time. A survey of every public name in `include/webcpp/crypto` outside `detail` and the backends found no other abbreviation taken from libsecp256k1 (R24). Recount with Step 6's grep on the base the task starts from. + +**Files (A), the refusal's text** (the minor carried from 3.3's review, the first commit): `detail/asynchronous.hpp`'s `refuse_aead_on_asynchronous_backend`, whose `static_assert` text becomes, on one line of the message tests: + +```cpp +static_assert(!asynchronous_backend_v, + "webcpp::crypto: WebCrypto has no ChaCha20-Poly1305, XChaCha20-Poly1305, " + "secret box or crypto_box: no form of them, synchronous or asynchronous, runs on " + "the browser's backend; name a native backend for them. On the browser's backend " + "only AES-GCM seals and opens."); +``` + +and its doc comment and the file comment say so; `ciphers/aead.hpp`'s member comment (about line 287: "On a native backend only: WebCrypto has no ChaCha20-Poly1305, and on a backend that completes by itself the call stops the build (design D6)") stays true and names the synchronous forms too; the `expected-error` line of the ten message tests that pin it (`async_seal_xchacha`, `async_open_xchacha`, `async_from_key_xchacha`, `async_seal_member_asynchronous_backend`, `async_seal_box_asynchronous_backend`, `async_open_box_asynchronous_backend`, `async_from_key_secretbox_asynchronous_backend`, `open_asynchronous_backend`, `seal_box_asynchronous_backend`, `seal_secretbox_asynchronous_backend`) and their header comments where they say only the asynchronous forms refuse; `crypto.json`'s `fixes` of those ten where they say "async_seal ... run on a native backend"; `doc/async.adoc`'s sentence about the refusal (about line 106). The MSVC twins (`test/msvc/async_*_xchacha`, `compile-fail` without a text) change only where a comment says otherwise. + +**Files (B), the AEAD template:** `ciphers/aead.hpp` (`class basic_chacha20_poly1305`, the file comment, every `ciphers::aead` and `aead<` in its comments, the refusal "webcpp::crypto: ciphers::basic_chacha20_poly1305 takes an AEAD family: ..."), `ciphers/chacha20_poly1305.hpp` (the three aliases over `basic_chacha20_poly1305<...>`), `async.hpp` (the three out-of-class member definitions at about lines 1386, 1401, 1420), `detail/engines.hpp`'s and `secret_key_encryption/aead.hpp`'s comments; tests: the `static_assert`s of `chacha_{sodium,bearssl,openssl}_test.cpp`, `chacha_original_sodium_test.cpp`, `xchacha_sodium_test.cpp`, `aead_box_mock_test.cpp`, `timing_mock_test.cpp`, `support/aead_checks.hpp`, `support/wycheproof_aead.hpp`, `support/timing_seam.hpp`'s comment, `test/Jamfile`'s comment; the timing seam's member labels in `support/timing_coverage.hpp` (`"ciphers::aead::seal"` becomes `"ciphers::basic_chacha20_poly1305::seal"`, and `open`, `from_key`, `async_seal`, `async_open`, `async_from_key` likewise) and `timing_test.cpp`'s sample names (the `__PRETTY_FUNCTION__` and MSVC `__FUNCSIG__` strings of the renamed class, as each compiler prints them, and the labels they are matched against); message test `aead_not_a_family` and its MSVC twin (code and text; directory name kept, R25), `open_asynchronous_backend`'s type; pages `chacha.adoc` (about line 29), `curves.adoc` (about line 346); `crypto.json` (`aead_not_a_family_on_emscripten`'s and `secretbox_not_a_family`'s texts, any `api` naming the template). A test's local alias named `aead` becomes `cipher`. Superproject: fixture `aead_not_a_family_on_emscripten` (`app.cpp`, and `.outcome`'s `contains:` line with the new refusal). + +**Files (C), secp256k1's names:** `curves/secp256k1/tweak.hpp` (the seven functions, their doc comments, `combine_workspace_size`'s comment naming `public_key_combine`), `curves/secp256k1/musig.hpp` (`generate_nonce`, the comments "made only by `nonce_gen`", "True from `nonce_gen`", "What `nonce_gen` returns", `partial_sign`'s `@param`), `curves/secp256k1/silent_payments.hpp` (`class previous_outputs_summary`, `make_previous_outputs_summary`, `summary_workspace_size`'s comment, the comment naming `seckey_tweak_add` at about line 131). A comment that quotes libsecp256k1 names its C identifier in full (`secp256k1_ec_seckey_tweak_add`, `secp256k1_musig_nonce_gen`, `secp256k1_silentpayments_prevouts_summary`) and keeps it; a test vector's field names keep theirs (BIP352's `scan_pubkey`, `plain_seckeys`, ... in `support/bip352_vectors.{c,h}`, generated from the BIP; BIP327's `nonce_gen_vectors`). Every caller: `bench/operations.hpp`; examples `key_tweak.cpp`, `musig_network.cpp`, `musig_taproot.cpp`, `musig_wallet.cpp`, `silent_payment.cpp` (`.expected` only if the output changes); tests `crypto_secp256k1_test.cpp`, `secp256k1_tweak_test.cpp`, `secp256k1_musig_test.cpp`, `secp256k1_musig_entropy_test.cpp`, `secp256k1_silent_payments_test.cpp`, `secp256k1_allocation_test.cpp`, `timing_coverage_secp256k1_test.cpp` (calls and labels), `wipe_objects_test.cpp`, `support/secp256k1_checks.hpp`, `constant_time/paths.hpp` (calls and check texts "secp256k1's secret_key_tweak_add", "secp256k1's generate_nonce", "secp256k1's make_previous_outputs_summary"); message tests `musig_nonce_copied`, `label_lookup_by_value`, `silent_payments_other_backend` and their MSVC twins; pages `secp256k1.adoc`, `curves.adoc`, `backends.adoc`, `memory.adoc`, `wallets.adoc`; `crypto.json` (the `api` and texts of the tweak, MuSig2 and silent payments rows and use cases). Superproject: fixtures `secp256k1_musig_default/app.cpp` (two calls and the comment at line 10) and `secp256k1_silent_payments_default/app.cpp`. + +- **Not touched:** secp256k1's `agree`, `agree_hashed`, `agree_point`; the aliases `chacha20_poly1305`, `chacha20_poly1305_original`, `xchacha20_poly1305`; ``'s path and the families it holds; the workspace helpers' names (R25); detail names (`detail::aead_family`, `refuse_aead_on_asynchronous_backend`, `secp256k1_seckey_tweak`); `doc/changelog.adoc` (4.1). webcpp::trystero's port of Trystero 0.27 (`/Users/you/dev/webcpporg/trystero-027`): `grep -rnwE 'nonce_gen|pubkey_tweak_add|pubkey_tweak_mul|pubkey_negate|pubkey_combine|seckey_tweak_add|seckey_tweak_mul|seckey_negate|prevouts_summary|make_prevouts_summary' /Users/you/dev/webcpporg/trystero-027/webcpp/libs/trystero` and `grep -rnE 'ciphers::aead\b' ...` (none on 2026-11-23) go to this stream's HANDBACK, every file and line. + +**Interfaces (Produces):** +- `template class ciphers::basic_chacha20_poly1305` (was `ciphers::aead`), members unchanged; `ciphers::chacha20_poly1305`, `chacha20_poly1305_original`, `xchacha20_poly1305` its aliases. +- `curves::secp256k1::secret_key_tweak_add(secret_key, tweak_bytes)`, `secret_key_tweak_mul`, `secret_key_negate(secret_key)`, `public_key_tweak_add(parsed_key, tweak_bytes)`, `public_key_tweak_mul`, `public_key_negate(parsed_key)`, `public_key_combine(parsed_keys, pointer_space)`: the same signatures and results. +- `curves::secp256k1::musig::generate_nonce(signer_pair, signers_key, message_hash = {}, extra_input = {})` returning `result`. +- `curves::secp256k1::silent_payments::previous_outputs_summary` and `make_previous_outputs_summary(smallest_outpoint, taproot_input_keys, plain_input_keys, pointer_space)` returning `result`; `scan_outputs` takes it as before. +- Removed with no alias: `ciphers::aead`, `musig::nonce_gen`, `pubkey_tweak_add`, `pubkey_tweak_mul`, `pubkey_negate`, `pubkey_combine`, `seckey_tweak_add`, `seckey_tweak_mul`, `seckey_negate`, `silent_payments::prevouts_summary`, `silent_payments::make_prevouts_summary`. + +- [ ] **Step 1: The refusal's text (A)**: edit Files (A); regenerate (`generate.py`). Run `grep -rn "their async_seal, async_open and async_from_key run" libs/crypto` - Expected: nothing. Then the ten message tests on the targets their Jamfiles name (`b2 ... toolset=clang libs/crypto/test/messages//async_seal_xchacha ...`, and wasip2, wasip3 through `heavy.sh crypto-types`), the three MSVC twins (`webcpp-msvc 14.5 -- libs/crypto/test/msvc//async_seal_xchacha libs/crypto/test/msvc//async_open_xchacha libs/crypto/test/msvc//async_from_key_xchacha` through `heavy.sh`), `generate.py --check`, `generate_test.py`, the doc build `b2 ... libs/crypto/doc` - Expected: pass. Commit `crypto: a construction WebCrypto lacks says that no form of it runs on the browser's backend`. +- [ ] **Step 2: Failing tests (B, C)**: eight message tests, written as 3.2's were, each removed name once as a using-declaration and once as a call, `alone` (the names' errors the compile's only ones), with their `crypto.json` `fixes` in the same commit: + - `aead_template_removed`: `` included; `using webcpp::crypto::ciphers::aead;` - `{{no member named 'aead' in namespace 'webcpp::crypto::ciphers'}}`; native wasip2 wasip3. Fixes: "Name `ciphers::basic_chacha20_poly1305`, or its aliases `chacha20_poly1305`, `chacha20_poly1305_original` and `xchacha20_poly1305`: the template is named for its algorithm, with no alias." + - `aead_template_removed_call`: a function making `webcpp::crypto::ciphers::aead::from_key(key)` (`/third_party//sodium`), the same error; every further error clang gives for the call (the template arguments of an unknown name) is pinned too, as `async_seal_removed` pins its four; native, and a `_wasi` twin only if WASI's clang differs (as `seal_removed_call_wasi`). Fixes: "As `aead_template_removed`: name `ciphers::basic_chacha20_poly1305`." + - `secp256k1_tweak_names_removed`: `` included; seven using-declarations `using webcpp::crypto::curves::secp256k1::pubkey_tweak_add;` ... `seckey_negate;` - `{{no member named 'pubkey_tweak_add' in namespace 'webcpp::crypto::curves::secp256k1'}}` and the six others (a substring: clang may add "; did you mean 'public_key_tweak_add'?"); `/third_party//secp256k1`, native wasip2 (as `musig_nonce_copied`). Fixes: "Call public_key_tweak_add, public_key_tweak_mul, public_key_negate, public_key_combine, secret_key_tweak_add, secret_key_tweak_mul and secret_key_negate: crypto spells out the names libsecp256k1 abbreviates." + - `secp256k1_tweak_names_removed_call`: one call of each of the seven with the arguments it takes (a parsed key from `public_key::from_bytes`, a 32-byte tweak, a workspace for `pubkey_combine`), the same seven errors; native wasip2. Fixes: "As `secp256k1_tweak_names_removed`." + - `musig_nonce_gen_removed`: ``; `using webcpp::crypto::curves::secp256k1::musig::nonce_gen;` - `{{no member named 'nonce_gen' in namespace 'webcpp::crypto::curves::secp256k1::musig'}}`; native wasip2. Fixes: "Call musig::generate_nonce: crypto spells out the names libsecp256k1 abbreviates." + - `musig_nonce_gen_removed_call`: `musig::nonce_gen(signer_pair, signers_key, message)` in a function taking a key pair and an `aggregate_key` by reference, the same error; native wasip2. Fixes: "As `musig_nonce_gen_removed`." + - `prevouts_summary_removed`: ``; `using ...::silent_payments::prevouts_summary;` and `using ...::silent_payments::make_prevouts_summary;`, two errors `{{no member named 'prevouts_summary' in namespace 'webcpp::crypto::curves::secp256k1::silent_payments'}}` and the same for `make_prevouts_summary`; native wasip2. Fixes: "Name silent_payments::previous_outputs_summary and make_previous_outputs_summary: crypto spells out libsecp256k1's prevouts." + - `prevouts_summary_removed_call`: `silent_payments::make_prevouts_summary(outpoint, {}, input_keys, summary_space)`, the same error; native wasip2. Fixes: "As `prevouts_summary_removed`." + Each joins `test/messages/Jamfile`'s `build-project` list beside `iv_size_removed`; no MSVC twin (3.2's and X4's removal tests have none). Run them - Expected: each fails, the old name compiling. +- [ ] **Step 3: Rename (B)**: every name in Files (B); the eight `static_assert`s of the chacha tests compare the aliases with `ciphers::basic_chacha20_poly1305`. Run `aead_template_removed`, `aead_template_removed_call`, `aead_not_a_family`, `open_asynchronous_backend`, `chacha_sodium`, `chacha_bearssl`, `chacha_openssl`, `chacha_original_sodium`, `xchacha_sodium`, `aead_box_mock`, `timing`, `timing_mock`, `timing_coverage_sodium`, `timing_coverage_bearssl`, `timing_coverage_openssl` with clang natively, the same timing tests with `toolset=gcc-15` and on MSVC 14.5 through `heavy.sh` (the seam reads each compiler's function name), `aead_not_a_family`'s MSVC twin - Expected: pass. Commit `crypto: the one-shot ChaCha20-Poly1305 template is ciphers::basic_chacha20_poly1305, named for its algorithm`. +- [ ] **Step 4: Rename (C)**: every name in Files (C); regenerate. Run the six secp256k1 removal tests, `secp256k1_tweak`, `secp256k1_musig`, `secp256k1_musig_entropy`, `secp256k1_silent_payments`, `secp256k1_allocation`, `crypto_secp256k1`, `timing_coverage_secp256k1`, `wipe_objects`, the three secp256k1 message tests and their MSVC twins, `example//key_tweak example//musig_network example//musig_taproot example//musig_wallet example//silent_payment` - Expected: pass. Commit `crypto: secp256k1's tweaks, MuSig2's nonce and silent payments' summary spell out the names libsecp256k1 abbreviates`. +- [ ] **Step 5: Superproject**: the three fixtures; `CODING-GUIDELINES.md`'s naming bullet (about line 6996, "Public names are spelled out") gains, before its Source: "Names taken from a C library are spelled out too: secp256k1's `public_key_tweak_add` and `secret_key_negate` (libsecp256k1's `pubkey`, `seckey`), MuSig2's `generate_nonce`, silent payments' `previous_outputs_summary`; a class template is named for its algorithm, as `ciphers::basic_chacha20_poly1305`, `basic_box` and `basic_secretbox` are." and its Source line adds "owner decision 14, D12"; the dated records keep their names. Commit `crypto fixtures and guidelines: basic_chacha20_poly1305 and secp256k1's spelled-out names`, with the `libs/crypto` pointer. +- [ ] **Step 6: Run** the grep that must come back empty, from the superproject worktree: + +```bash +grep -rnE 'ciphers::aead\b|(^|[^:_a-zA-Z])aead<|class aead\b|\b(nonce_gen|pubkey_tweak_add|pubkey_tweak_mul|pubkey_negate|pubkey_combine|seckey_tweak_add|seckey_tweak_mul|seckey_negate|prevouts_summary|make_prevouts_summary)\b|their async_seal, async_open and async_from_key run' \ + libs/crypto/include libs/crypto/test libs/crypto/example libs/crypto/bench libs/crypto/doc/*.adoc \ + libs/crypto/doc/tables libs/crypto/doc/generated libs/crypto/doc/llms.txt libs/crypto/meta libs/crypto/README.md \ + tools/test/fixtures/crypto_jamfiles \ + --exclude-dir=aead_template_removed --exclude-dir=aead_template_removed_call \ + --exclude-dir=secp256k1_tweak_names_removed --exclude-dir=secp256k1_tweak_names_removed_call \ + --exclude-dir=musig_nonce_gen_removed --exclude-dir=musig_nonce_gen_removed_call \ + --exclude-dir=prevouts_summary_removed --exclude-dir=prevouts_summary_removed_call \ + --exclude=messages.adoc --exclude=changelog.adoc +``` + +Expected: nothing (`\b` keeps libsecp256k1's `secp256k1_ec_pubkey_tweak_add`, `secp256k1_musig_nonce_gen` and BIP327's `nonce_gen_vectors` out; `messages.adoc` is checked by `generate.py --check`, its rows being the message tests' texts; `changelog.adoc` line 25 is 4.1's). Then: the clang whole build through `heavy.sh crypto-types` (`libs/crypto/test libs/crypto/example libs/crypto/bench`); Emscripten `chacha_sodium xchacha_sodium secp256k1_tweak secp256k1_musig secp256k1_silent_payments` through `heavy.sh`; wasip2 (`testing.launcher=wasmtime`) of the touched message tests and `chacha_sodium secp256k1_tweak secp256k1_musig secp256k1_silent_payments`; the constant-time lane's `paths` natively (`libs/crypto/test/constant_time`, through `heavy.sh crypto-types`); the fixtures `python3 tools/test/crypto_jamfiles_test.py secp256k1_musig_default secp256k1_silent_payments_default` (native, then Emscripten) and `aead_not_a_family_on_emscripten` (Emscripten); `generate.py --check`, `generate_test.py`, the doc build; clang-format (wasi-sdk's pinned) on every changed `.cpp` and `.hpp`; the X3 survey (no new one-word local); the Linux lint, run by the implementer: `linux-lint/run.sh --files` on every source the task touched, on a self-contained copy of the tree (msvc-lane's `make-tree.py` at the superproject commit), through `heavy.sh` - Expected: "run.sh: verdict: CLEAN: the CI lint would pass"; every finding of one run fixed in one commit (`crypto: `, with a superproject pointer commit), then one rerun. Record trystero-027's uses for the HANDBACK. + +### Task 4.1: The page, the tables, the changelog + +**Files:** `doc/curves.adoc` (in "Signatures: the scheme and the input": a subsection "Signatures as values": the five types, Ed25519's shared by `eddsa` and `eddsa_prehashed` (not interchangeable), `from_bytes` at the wire, `bytes()`, `recovery_id()`, the typed format helpers; a subsection "Factories named by their input" with D3c's table and the predictable-key hazard; "Key pairs by what they do" with D4's table), `doc/x25519.adoc` (typed keys, the four forms, the conversion), `doc/kx.adoc` (`derive_from_seed` against `from_keypair`), `doc/aead.adoc` (the three concepts, D5's table, the free forms, asynchronous on native, the browser's AES-GCM; with decision 14's names, which X5 has already put in the code and the pages: the one-shot template `ciphers::basic_chacha20_poly1305`, and D6's refusal as X5 worded it, no form of the constructions WebCrypto lacks running on the browser's backend), `doc/secret_key_encryption.adoc` (3.2's chapter: the AEAD contract `secret_key_encryption::aead` with `cipher` and `streaming_cipher`, `authenticated_box` and the box forms, D11's namespaces table), `doc/public_key_encryption.adoc` (the namespaces by purpose), `doc/protecting_secrets.adoc` (new, owner decision 11: `[#crypto-protecting-secrets] === Protecting secrets outside the primitives`, included in the root chapter in place of `entropy.adoc` and `constant_time_equal.adoc`, before `errors.adoc`: an opening table of the four utilities, what each guards against (timing: `constant_time_equal`, {cwe208}; memory: `secret`, which wipes itself, and `erase_secret` for a buffer the program owns, {cwe14}; drawing: `random_device`), then `constant_time_equal.adoc`, `erase_secret.adoc`, a `secret` subsection moved from `root.adoc` and `entropy.adoc` as its subsections (`====`, their anchors kept); every name stays at the top of `webcpp::crypto`, the section says there is no namespace of its own), `doc/tables/crypto.json` (the signing, key pair and factories rows; rows for `secret_key_encryption/aead.hpp`'s concepts and `secret_key_encryption/authenticated_box.hpp`; the root rows of the four utilities point to the section), `doc/changelog.adoc`. Every name a section, a table row or a changelog line writes is the final one (owner decisions 13 and 14): `ciphers::basic_chacha20_poly1305`, secp256k1's `public_key_tweak_add`, `public_key_tweak_mul`, `public_key_negate`, `public_key_combine`, `secret_key_tweak_add`, `secret_key_tweak_mul`, `secret_key_negate`, MuSig2's `generate_nonce`, silent payments' `previous_outputs_summary` and `make_previous_outputs_summary`. Superproject: `CODING-GUIDELINES.md` crypto chapter, a bullet beside "One name per signing operation" ("Every value has its type: signatures per curve and scheme, X25519's keys; key pairs, AEADs and boxes checked by concepts; constructions by purpose; factories named by their input", with its Source lines). +- [ ] **Step 1:** Write the sections; each code snippet is an example's own code included by tag (`four_forms.cpp`, `x25519_agree.cpp`, `kx_session.cpp`, `xchacha_seal.cpp`, `signed_message.cpp`, `constant_time_equal_hmac.cpp`). +- [ ] **Step 2: Changelog** (no new line; ten at most): line 8 becomes "Added secret_key_encryption's secretbox and secretbox_xchacha20poly1305 without associated data, public_key_encryption's box, box_xchacha20poly1305 and sealed_box, key_exchange::kx_keypair on libsodium, on typed X25519 keys." (30 words or fewer); line 10 becomes "Added signing.hpp, keypair.hpp, factories.hpp, secret_key_encryption/aead.hpp, erase_secret.hpp: typed signatures, sign(scheme, input), verify; keypair, signing_keypair, agreement_keypair; aead::cipher, authenticated_box; from_secret, from_bytes, from_key." (30 words or fewer; drop "four forms per operation" if needed); a line that names `crypto::seal`, `crypto::open`, `iv` or `invalid_iv_size` says `secret_key_encryption::aead::seal`, `open`, `nonce`, `invalid_nonce_size`; line 20 names `equal`, a removed function: "Added equal" becomes "Added constant_time_equal"; line 25's "ciphers::aead: chacha20_poly1305" becomes "ciphers::basic_chacha20_poly1305: chacha20_poly1305" (owner decision 14; the word count unchanged); line 24's "Ed25519ph over hash's sha2_512" becomes "Ed25519ph as crypto::eddsa_prehashed and the streaming prehashed_signer over hash's sha2_512" (30 words or fewer, shortened elsewhere in the line if needed); the other lines stay unless they name a removed function. Count the words. +- [ ] **Step 3: Run** `grep -rn 'hybrid::\|x25519_secret\|to_x25519_public\|make\.hpp\|crypto::make\b\|crypto::equal\b\|crypto/equal\.hpp\|crypto-equal\|ed25519::ph\b\|crypto::wipe\b\|crypto::seal\b\|crypto::open\b\|crypto::async_seal\b\|crypto::async_open\b\|ciphers::secretbox\|ciphers/secretbox\.hpp\|iv_size\|invalid_iv_size\|streaming_aead\|crypto::aead\b\|ciphers::aead\b\|\bnonce_gen\b\|\bpubkey_\|\bseckey_\|\bprevouts_summary\|make_prevouts_summary\|their async_seal, async_open and async_from_key run' libs/crypto/doc --exclude=messages.adoc` - Expected: nothing (`messages.adoc` holds the removal message tests' texts, X5's among them, and `generate.py --check` checks it). `generate.py`, `--check`, `generate_test.py`, `b2 ... libs/crypto/doc` - Expected: no warning about an anchor or include. +- [ ] **Step 4: Commit** `crypto: the page shows typed signatures, typed X25519, the concepts and the factories by input`; superproject `guidelines: crypto's values are typed, checked by concepts and made by factories named by their input`; the bullet adds "Ed25519ph is a scheme, eddsa_prehashed; the secret-hygiene utilities are named by what they do: constant_time_equal, erase_secret; the AEAD contract is secret_key_encryption::aead's and the secret boxes secret_key_encryption's; the one-shot ChaCha20-Poly1305 template is ciphers::basic_chacha20_poly1305" (X4 wrote the naming rule, X5 its sentence on names taken from a C library). + +### Task 4.2: Full local verification and delivery (controller) + +Each through `/Users/you/dev/webcpporg/heavy.sh crypto-types`: +- [ ] clang full lane `-a` of `libs/crypto/test libs/crypto/example libs/crypto/bench`, with `libs/hash/test libs/hash/example`; gcc-15 (`toolset=gcc-15`) and Emscripten full lanes of the same three crypto directories. +- [ ] wasip2 (`toolset=clang-wasip2 testing.launcher=wasmtime`) and wasip3 (`toolset=clang-wasip3 testing.launcher=tools/boost/asio-wasip3/run.sh`) of `libs/crypto/test libs/crypto/example`. +- [ ] MSVC 14.3 and 14.5 with msvc-lane on a self-contained tree (`run-lane.sh --tree DIR --fresh -- libs/crypto/test libs/crypto/example`); `user_globals` passes on both. +- [ ] Linux lint `--full` (self-contained clone, `linux-lint`) and the macOS full lint. +- [ ] Constant-time lane (memcheck, MemorySanitizer, dudect) for the changed secret paths: secp256k1's `sign(ecdsa_keccak256_recoverable, ...)`, the sealed box's seal with crypto's entropy (X1b, Emscripten has no checker: natively the path is unchanged), X25519's typed key pair (`from_secret`, `agree`, the moved-from wipe), kx `derive_from_seed` and `from_keypair`, Ed25519's `to_x25519`, secretbox `seal`/`open` without additional data, `crypto::erase_secret`, `crypto::constant_time_equal` under its new name (its memcheck, msan and dudect paths, the dudect case `constant_time_equal`, native and wasip2), Ed25519's `sign(eddsa_prehashed, ...)`, secp256k1's key tweaks, `musig::generate_nonce` and `make_previous_outputs_summary` under their new names (X5), the renamed factories (`from_secret` on the three signing curves, `from_key` of AES-GCM, ChaCha20-Poly1305, secretbox), and P-256 and secp256k1 signing returning the typed signature; `paths.hpp` and the suppressions (`bearssl_verdicts.supp`, `sodium_verdicts.supp` frames renamed by X3 and 2.5) updated by the tasks; dudect natively and on wasip2. +- [ ] `python3 tools/test/crypto_jamfiles_test.py` (every case, native and Emscripten); `generate.py --check`; the X3 survey (empty). +- [ ] Merge `origin/main` into the three branches; pull requests in webcpporg/crypto, webcpporg/hash (X2's callers), webcpporg/proposals (tasks ticked, design.md's "As built", status `implementing`), webcpporg/webcpp (the pointers of libs/crypto and libs/hash); the HANDBACK lists trystero-027's `crypto::equal`, `ed25519::ph`, `crypto::seal`/`open`, `ciphers::secretbox` and `iv`-named call sites (X2, 1.4, X4) and its uses of X5's removed names (`ciphers::aead`, `nonce_gen`, `pubkey_*`, `seckey_*`, `prevouts_summary`; none on 2026-11-23); merge commits; one CI at the end. + +## Rulings made in the plan + +- **P1, the order** (header): X3, 2.5 and 2.4 first. Cost if wrong: none in behaviour; a late 2.5 would rename the new types' `make` twice. +- **P2, X3's test is new.** The brief's "existing MSVC hides-no-user-name test" (48ca7ef) does not exist: that commit renamed `make.hpp`'s parameters; a200e69 moved a test's global into a local. `user_globals_test.cpp` declares the survey's names before every public header, its third-party headers included first; only MSVC diagnoses (clang and GCC `-Wshadow` never warn across namespaces, checked). Cost: a one-word name added later outside the list is caught only when it collides on MSVC. +- **P3, X3's names**: the table in X3, "role then kind"; `timing_scope` for the guard. Cost: a rename of renames if the owner prefers another word. +- **P4, engine statics named `make` are renamed** (`import_secret`, `seed_keypair`, `heavy_state::allocate`): the spec says no function is named `make`; decision 9's "backends' internal capabilities keep their names" means the capability rows (`*_import`), which stay. Cost: internal only. +- **P5 (superseded by owner decision 12, 2026-11-23): no distinct Ed25519ph signature type.** The first ruling was `curves::ed25519::ph_signature`; Ed25519ph is now the scheme `eddsa_prehashed` (Task 1.4, design D9), whose signature is `ed25519::signature`, so 1.1 creates no `ph_signature` and 1.2 retypes the streaming signer onto `ed25519::signature`. Cost: an Ed25519ph signature given to the pure `verify` fails at run time with `invalid_signature` instead of stopping the build (RFC 8032's domain separation makes it fail; the page says the two are not interchangeable). +- **P6, signatures have a public default constructor (all zeros)**, so they are `std::regular` as the spec says and the asynchronous error completion's empty value exists. Cost: a zero signature can be named; every verify refuses it. +- **P7, `can_verify` gains the signature: `can_verify`** (D1 says it is false for a signature of another curve), with `detail::signature_of` as "the trait gains the signature type" (a scheme alone does not know its curve). Cost: callers of the concept add one argument. +- **P8, `to_der`, `from_der`, `normalize_low_s`, `is_low_s` take and give the typed ECDSA signature** on both curves (D1 names the last two; the first two would otherwise be the last byte-signature functions). Cost: the formats change builds on typed values, as it intends. +- **P9, MuSig2's aggregate is a `schnorr_signature`**; partial signatures keep their bytes (crypto-sign's R7). Cost: MuSig2 callers add `.bytes()`. +- **P10, secretbox gets its own engine** (`detail::secretbox_state`/`secretbox_engine`, no associated-data parameter) and its families move to `secret_key_encryption/secretbox.hpp` (X4 moved the header), so that `ciphers::aead` names only AEADs. Cost: sodium.hpp's two specializations rewritten. +- **P11, no `async_from_keys` for crypto_box**: D6 lists `async_from_key` alone; a box is made from typed keys. Cost: a program that wants it posts the synchronous call itself. +- **P12, D6's refusal fires before any member of the type is named**, and its text lists the algorithms (a C++20 `static_assert` cannot compose the type's name). Cost: the message does not name the one type used. +- **P13, `detail::x25519_access`** gives kx, the boxes and the sealed box the key pair's bytes without a nested guard or a copy. Cost: one friend struct. +- **P14, `kx_keypair::from_keypair` takes the key pair by value** (a sink; the key pair is move-only), and `keypair()` gives it back by reference. Cost: an lvalue needs `std::move`. +- **P15, X1 calls `crypto.getRandomValues` from its own `EM_JS`** through a fresh `Uint8Array`: no `crypto` object is `not_supported` (the audio worklet's case, kept), a throw is `entropy_unavailable`. Cost: node versions without `globalThis.crypto` (before 19, which webcpp does not run) would read `not_supported`. +- **P16, `crypto::erase_secret` (owner decision 11; `crypto::wipe` in the first draft) is one constrained template plus a refusing overload**; no `(void*, size)` form (no caller needs it). Cost: a C buffer of runtime size goes through `std::span`. +- **P17, the free X25519 byte `async_agree` is removed in 2.1** and `async_agree` becomes one template constrained by `agreement_keypair` in 3.1. +- **P18, `doc/hybrid.adoc` becomes `doc/public_key_encryption.adoc`** with its anchor; `kx.adoc` keeps its name. +- **P19, the free factories hold a guard**, as `crypto::make` did, even over a member that calls no backend (`from_bytes` of a signature). Cost: DIT set around a copy. +- **P20, `to_x25519()` gives a key pair of the same backend**, refused at compile time when that backend has no X25519. +- **P21, 1.1's message tests for a signature of another curve move to 1.2**, where `verify` first takes the types. + +- **P22, the Keccak message form needs `/third_party//xkcp` in the program's Jamfile** (R19): secp256k1's family default does not bring XKCP, which builds on every target and toolset; a marker needs none. Cost: an Ethereum program adds one Jamfile line. +- **P23, both recoverable schemes share `recoverable_signature`** (the controller's ruling, R20). Cost: a signature recovered under the wrong scheme gives a wrong key at run time, not a build error. +- **P24, `ecdsa_keccak256_recoverable` has no `verify`**: `ecdsa_sha256_recoverable` has none (the catch-all sends its signature to `recover`), so symmetry says none (R18). +- **P25, X1b installs crypto's implementation unconditionally on Emscripten**, before crypto's first `sodium_init`: libsodium has no way to read the current implementation without initialising it, which runs the stir that throws. Cost: a program's own implementation set earlier is replaced (the page says to set it later). +- **P26, a failed draw outside a call crypto observes calls `sodium_misuse()`**, libsodium's abort: handing zeros to a caller that cannot see a failure would be worse. Cost: the program's own libsodium calls still stop on a failed generator, as libsodium intends. +- **P27, `sign(eddsa_prehashed, ...)` and its `verify` call libsodium's `_crypto_sign_ed25519_detached` and `_crypto_sign_ed25519_verify_detached` with `prehashed` 1**, declared `extern "C"` in `backends/sodium.hpp` as libsodium's private `crypto_sign/ed25519/ref10/sign_ed25519_ref10.h` declares them: libsodium's public API signs Ed25519ph only from its own SHA-512 state (`crypto_sign_ed25519ph_final_create`), which cannot be given a finished digest, and these are the functions that state's `final_create` and `final_verify` call, so strictness and the signature are libsodium's. They link because webcpp builds libsodium from source as a static library on every target. Cost: an internal symbol a libsodium upgrade could rename (the vendored version is pinned; `ed25519ph_sodium`'s `streaming_equals_scheme` catches a mismatch); the alternative, Ed25519ph rebuilt over libsodium's public scalar and point operations, would be a new secret path of crypto's own. +- **P28, X2 lands before 1.1** with both parts of owner decision 11, so that the new tests of 1.1 to 3.3 call `constant_time_equal` from the start; `equal` and `ph` each get a removal message test (`equal_removed`, `equal_header_removed`, `ph_removed`), as `make_removed` does. Cost: X2 touches libs/hash and 17 fixtures early, in a task the first draft called small. +- **P30, X4 runs right after 2.1, and 3.2 and 3.3 do the moves** (the controller's ruling on owner decision 13, R23, recorded when 2.1 was built): "3.2 and 3.3 are written with decision 13's names; X4 covers the renames they do not touch". X4 renames in place (parameters, `nonce_size`, `max_nonce_size`, `max_associated_data_size`, `invalid_nonce_size`, `auxiliary_random_bytes`, the guideline), so the names 3.2 and 3.3 move already carry the renames and their new signatures use `nonce`, `nonce_size` and `associated_data` from the start. X4 is two commits (parameters; other public names) so that review can take them apart. Cost: X4 touches 53 files of libs/crypto and 4 of the superproject before 2.2; 3.2 grows by the moves of the free forms and secretbox (17 tests, 2 examples, the pages, 3 fixtures). +- **P31, the box forms follow `authenticated_box` into `secret_key_encryption`** (design R21, the coordinator's refinement): `secret_key_encryption::authenticated_box` in `secret_key_encryption/authenticated_box.hpp`, beside the secret box, and `secret_key_encryption::seal`/`open` (3.3: `async_seal`/`async_open`) for a secret box and a crypto_box alike; none in `crypto::` nor in `public_key_encryption`. Cost: a crypto_box's free form is named through `secret_key_encryption`, not found by argument-dependent lookup. +- **P32, decision 13 covers the public names around the parameters** (design R22, accepted by the coordinator): `iv_size`, `max_iv_size`, `max_additional_data_size` and `error::invalid_iv_size` become `nonce_size`, `max_nonce_size`, `max_associated_data_size` and `invalid_nonce_size` (value 2 kept), in X4; `max_` stays (the standard library's word); BIP340's `aux_random` becomes `auxiliary_random_bytes`. Cost: an error enumerator renamed (69 uses). + +- **P33, X5 runs after X1b and before 4.1** (the controller's ruling on owner decision 14, recorded after X1 was built): every name it renames exists by then, so nothing is renamed twice, and 4.1 writes the pages and the changelog once with the final names; its first commit is the minor carried from 3.3's review (D6's refusal named only the asynchronous forms after 3.3's fix round made the synchronous ones give it too). Three `libs/crypto` commits (the text, the template, secp256k1's names) so that review can take them apart. The removal message tests follow 3.2's (a using-declaration and a call per group, `alone`); clang's typo correction may add "did you mean" to an error, which the substring keeps, and any further error of a call is pinned. Cost: X5 touches 64 files of libs/crypto and 4 of the superproject; `silent_payments::prevouts_summary` is renamed on the amendment's reading (R24), which the owner may strike. + +- **P29, the message tests and the fixture named `ed25519ph_*` keep their directory names** (Ed25519ph is the algorithm's name; the capability row `ed25519ph` keeps its name, R17); only their code and texts change. Cost: none. + +## Design defects and gaps found + +Recorded in design.md (R8/R9 noted, R14-R25, decisions 1 to 14, D9, D10, D11 and D12, the spec's `make` sentence aligned with R17); what remains: + +- D6's refusal cannot be the first message unless it precedes every use of the AEAD's members: naming an AEAD's engine on an unknown or browser backend fires the capability table's refusal first (P12). +- Open item: if webcpp::hash, which shares libsodium, calls `sodium_init` before crypto's first call, libsodium's JavaScript stir runs first and can still throw; crypto cannot reach it (hash would install the same implementation). +- Open item: natively, libsodium's `randombytes_sysrandom` aborts on a failed generator; X1b changes Emscripten only, as ruled. diff --git a/libraries/crypto/openspec/changes/uniform-types/specs/crypto/spec.md b/libraries/crypto/openspec/changes/uniform-types/specs/crypto/spec.md new file mode 100644 index 0000000..73b7ca3 --- /dev/null +++ b/libraries/crypto/openspec/changes/uniform-types/specs/crypto/spec.md @@ -0,0 +1,291 @@ +## ADDED Requirements + +### Requirement: Signatures: a type per curve and scheme +The library SHALL offer `curves::ed25519::signature` (64 bytes), `curves::p256::ecdsa_signature` (64 bytes, r then s), `curves::secp256k1::ecdsa_signature` (64 bytes, r then s), `curves::secp256k1::recoverable_signature` (65 bytes, r, s and the recovery id, with `recovery_id()`) and `curves::secp256k1::schnorr_signature` (64 bytes), distinct regular value types, each with `static from_bytes(std::span)` returning `result` (`invalid_signature` for another size, nothing else checked) and `bytes()`, and none converting implicitly to another type or to bytes. Every `sign` MUST return the type of its curve and scheme, and every `verify` and `recover`, member and free, synchronous and asynchronous, MUST take it; no overload taking a signature as bytes MUST exist, and a signature of another curve or scheme MUST stop the build with a message naming the type expected, except between the schemes that share a type: `eddsa` and `eddsa_prehashed` (`ed25519::signature`), and the two recoverable schemes (`recoverable_signature`). + +#### Scenario: A signature from the wire +- **WHEN** 64 bytes received from a peer are made into a `p256::ecdsa_signature` with `from_bytes` and given to `crypto::verify(crypto::ecdsa_sha256, signature, message, public_key)`, and 63 bytes are given to `from_bytes` +- **THEN** the first verifies and the second returns `invalid_signature` from `from_bytes` + +#### Scenario: The wrong curve +- **WHEN** a program passes a `secp256k1::ecdsa_signature` to `crypto::verify(crypto::ecdsa_sha256, signature, message, p256_public_key)` +- **THEN** compilation stops with a message naming `p256::ecdsa_signature` + +### Requirement: X25519: typed keys +`curves::x25519::public_key` SHALL be made by `from_bytes` from 32 bytes (`invalid_public_key` for another size, nothing else checked) and give `bytes()`; `curves::x25519::basic_keypair` (and `x25519::keypair`) SHALL be made by `from_secret` from a 32-byte secret or by `generate()`, give `public_key()`, `secret()` and `agree(peer)` (`peer` an `x25519::public_key`, the result `secret<32>`, `weak_public_key` when it is all zero, on every backend), with `async_from_secret`, `async_generate` and `async_agree` members and the free `crypto::from_secret`, `crypto::generate`, `crypto::agree` and their asynchronous forms. The free functions `curves::x25519::public_key(secret)` and `curves::x25519::agree(secret, peer)` MUST NOT exist. + +#### Scenario: RFC 7748's agreement +- **WHEN** Alice's and Bob's key pairs of RFC 7748 section 6.1 are made from their secrets and agree with each other's `public_key()` +- **THEN** both give the RFC's shared secret, synchronously and through `async_agree` + +### Requirement: Key pairs: three concepts +`` SHALL declare `crypto::keypair` (`K::from_secret(secret_bytes)` and `K::generate()` returning `result`, `public_key()` returning `result`, `secret()` returning `result>`), `crypto::signing_keypair` (`keypair` and `sign(scheme, input)` for every scheme `K` declares, at least one, returning the scheme's signature type) and `crypto::agreement_keypair` (`keypair` and `agree(peer)` returning `result>`). Ed25519's key pair MUST be a `signing_keypair` and not an `agreement_keypair`; X25519's an `agreement_keypair` and not a `signing_keypair`; P-256's and secp256k1's both; each checked by `static_assert`s in its curve's header. `crypto::sign` and `async_sign` MUST be constrained by `signing_keypair`, `crypto::agree` and `async_agree` by `agreement_keypair`. + +#### Scenario: An X25519 key pair does not sign +- **WHEN** a program calls `crypto::sign(x25519_key, crypto::eddsa, message)` +- **THEN** compilation stops with a message saying that X25519 key pairs agree and do not sign + +#### Scenario: A key pair made again from its secret +- **WHEN** `K::from_secret(k.secret()->bytes())` is called for a key pair `k` of each of the four curves +- **THEN** the new key pair has the same public key + +### Requirement: Ed25519: a typed conversion to X25519 +`curves::ed25519::basic_keypair::to_x25519()` SHALL return `result>` and `curves::ed25519::public_key::to_x25519()` SHALL return `result` (`invalid_public_key` for a key that is not canonical or of small order), with the free `crypto::to_x25519(value)`; `x25519_secret()` and `curves::ed25519::to_x25519_public` MUST NOT exist. + +#### Scenario: Conversion agrees with signing keys +- **WHEN** an Ed25519 key pair is converted with `to_x25519()` and its public key with `public_key()->to_x25519()` +- **THEN** the converted key pair's `public_key()` equals the converted public key, and libsodium's `crypto_sign_ed25519_sk_to_curve25519` and `pk_to_curve25519` give the same bytes + +### Requirement: AEADs and boxes: concepts +`` SHALL declare, in namespace `webcpp::crypto::secret_key_encryption::aead`, the concept `cipher` (`key_size`, `nonce_size`, `tag_size`, `result_type`, `static from_key(key)` returning `result`, `seal(nonce, associated_data, data)` returning `result`, `open(nonce, associated_data, data, tag)` returning `result`) and its refinement `streaming_cipher` (`begin_seal`, `update`, `result`, `begin_open`, `authenticate`, `decrypt`, `verify`, `end_open`); `` SHALL declare the sibling `secret_key_encryption::authenticated_box` (`key_size`, `nonce_size`, `tag_size`, `result_type`, `seal(nonce, data)`, `open(nonce, data, tag)`). `ciphers::gcm` MUST be a `streaming_cipher`; `ciphers::chacha20_poly1305`, `chacha20_poly1305_original` and `xchacha20_poly1305` `cipher`s; `secret_key_encryption::secretbox`, `secret_key_encryption::secretbox_xchacha20poly1305`, `public_key_encryption::box` and `box_xchacha20poly1305` `authenticated_box`es taking no associated data; each checked by a `static_assert` in its header. The free `secret_key_encryption::aead::seal` and `open` MUST exist with associated data, constrained by `cipher`, and the box forms `secret_key_encryption::seal(box, nonce, data)` and `secret_key_encryption::open(box, nonce, data, tag)` without, constrained by `authenticated_box`, for a secret box and a crypto_box alike; no free `seal` or `open` MUST exist in `webcpp::crypto` nor in `public_key_encryption`. + +#### Scenario: secretbox has no associated data +- **WHEN** a program calls `secretbox.seal(nonce, associated_data, data)`, or `secret_key_encryption::aead::seal(secretbox, nonce, associated_data, data)` +- **THEN** neither compiles, the second with a message naming the box forms, and `secretbox.seal(nonce, data)` and `secret_key_encryption::seal(secretbox, nonce, data)` seal as libsodium's `crypto_secretbox_detached` does + +### Requirement: AEADs and boxes: asynchronous on every native backend +`async_seal` and `async_open`, member and free (`secret_key_encryption::aead::async_seal` and `async_open` for a `cipher`; `secret_key_encryption::async_seal` and `async_open` for an `authenticated_box`), SHALL exist for every `secret_key_encryption::aead::cipher` and every `secret_key_encryption::authenticated_box`, completing through `asio::post` on a synchronous backend; on a backend whose `detail::asynchronous_backend_v` is true, only AES-GCM SHALL be offered, and any other type MUST stop the build, from every form of it, synchronous or asynchronous, member or free, with a message saying WebCrypto has no such algorithm, that no form of it runs on the browser's backend, and to name a native backend. + +#### Scenario: XChaCha20-Poly1305 asynchronously +- **WHEN** a coroutine `co_await crypto::secret_key_encryption::aead::async_seal(executor, cipher, nonce, associated_data, data, use_awaitable)` runs with `ciphers::xchacha20_poly1305` on libsodium natively +- **THEN** it completes with the tag the synchronous `seal` gives, and the same call on a stand-in browser backend does not compile + +### Requirement: Constructions: grouped by purpose +The library SHALL offer crypto_box and sealed boxes in namespace `webcpp::crypto::public_key_encryption` (`basic_box`, `box`, `box_xchacha20poly1305` in ``; `basic_sealed_box`, `sealed_box` in ``) and crypto_kx in namespace `webcpp::crypto::key_exchange` (`kx_keypair`, `session_keys` in ``). The namespace `webcpp::crypto::hybrid`, the headers `hybrid/box.hpp`, `hybrid/sealed_box.hpp` and `curves/x25519/kx.hpp`, and `curves::x25519::kx_keypair` and `curves::x25519::session_keys` MUST NOT exist, with no alias; `curves` MUST hold curve primitives only. + +#### Scenario: The old names are gone +- **WHEN** a program includes `` or names `crypto::hybrid::box` or `crypto::curves::x25519::kx_keypair` +- **THEN** it does not compile, and the same program with ``, `crypto::public_key_encryption::box` and `crypto::key_exchange::kx_keypair` builds and runs + +### Requirement: Factories: named by their input +The library SHALL name every fallible factory by what it takes: `K::from_secret(secret_bytes)` and `K::generate()` for every key pair, `T::from_bytes(bytes)` for every public key and signature, `p256::basic_public_key::from_coordinates(x, y)`, `C::from_key(key)` for every cipher, AEAD and `secret_key_encryption` secretbox, `public_key_encryption::basic_box::from_keys(own_keypair, peer_public_key)`, and `key_exchange::kx_keypair::from_keypair(x25519_keypair)` beside `derive_from_seed(seed)` and `generate()`; with the free `crypto::from_secret`, `crypto::from_bytes`, `crypto::from_key` and `crypto::generate` in ``, and `async_from_secret`, `async_from_key` and `async_generate`, member and free. No function, member or free, synchronous or asynchronous, public or in `detail`, MUST be named `make` or `async_make`; the capability table's rows (`*_import`, `*_generate`), which are not functions, keep their names. A signature's `from_bytes`, Ed25519's and X25519's public keys' `from_bytes` and the free `crypto::from_bytes` call no backend and MUST enter no timing guard; P-256's and secp256k1's public keys' `from_bytes` (and P-256's `from_coordinates`) validate the point through the backend and MUST hold `detail::timing_guard`. + +#### Scenario: The call site says where the secret comes from +- **WHEN** a program calls `p256::keypair::from_secret(bytes)` and `p256::keypair::generate()`, and then `p256::keypair::make(bytes)` +- **THEN** the first two compile, the first giving the key of those bytes and the second a drawn key, and the third does not compile + +### Requirement: Signatures: Ethereum's recoverable ECDSA +`` SHALL declare the scheme tag `ecdsa_keccak256_recoverable`, in the library's one list of schemes, which `curves::secp256k1::basic_keypair` alone declares: `sign(crypto::ecdsa_keccak256_recoverable, input)` SHALL return a `curves::secp256k1::recoverable_signature` with low S, the input a message hashed inside with Keccak-256 (`webcpp::hash::keccak_256`, the original padding, never SHA3-256) or `crypto::prehashed{digest}` of 32 bytes, and `curves::secp256k1::recover(crypto::ecdsa_keccak256_recoverable, signature, input)` SHALL return the signer's `curves::secp256k1::public_key`. No `crypto::verify` overload MUST exist for the scheme, no asynchronous form, and crypto MUST NOT compute Ethereum's `v` nor an address. A message input without `/third_party//xkcp` linked MUST stop the build with a message naming that Jamfile line. + +#### Scenario: go-ethereum's recovery vector +- **WHEN** go-ethereum's `crypto/signature_test.go` digest and signature are given to `recover(crypto::ecdsa_keccak256_recoverable, signature, crypto::prehashed{digest})` +- **THEN** it returns that file's public key + +#### Scenario: A message is hashed with Keccak-256 +- **WHEN** a key pair signs a message with `sign(crypto::ecdsa_keccak256_recoverable, message)` +- **THEN** the signature equals `sign(crypto::ecdsa_keccak256_recoverable, crypto::prehashed{keccak_256(message)})`, differs from the one over SHA3-256's digest, and `recover` of it with the message gives the key pair's public key + +#### Scenario: A digest of another size +- **WHEN** a program signs `crypto::prehashed{std::array{}}` with `crypto::ecdsa_keccak256_recoverable`, or a P-256 or Ed25519 key pair signs with the scheme +- **THEN** compilation stops with a message naming the 32-byte digest, or the schemes the key pair has + +### Requirement: Signatures: Ed25519ph as the scheme eddsa_prehashed +`` SHALL declare the scheme tag `eddsa_prehashed` (RFC 8032's Ed25519ph), in the library's one list of schemes, which `curves::ed25519::basic_keypair` declares beside `eddsa`: `sign(crypto::eddsa_prehashed, crypto::prehashed{digest})`, `digest` the 64 bytes of the message's SHA-512, SHALL return a `curves::ed25519::signature`, and `crypto::verify(crypto::eddsa_prehashed, signature, crypto::prehashed{digest}, public_key)` and `public_key.verify(crypto::eddsa_prehashed, ...)` SHALL verify it, strictly as `eddsa` does. A message input MUST stop the build with a message naming `crypto::prehashed{digest}` of 64 bytes, a digest of another size with a message naming SHA-512's 64 bytes, and `eddsa` MUST keep refusing a marker with a message naming `eddsa_prehashed`. The asynchronous forms (`async_sign`, `async_verify`, member and free) SHALL exist on native backends, and MUST stop the build on a backend whose `detail::asynchronous_backend_v` is true with a message saying WebCrypto has no Ed25519ph. The streaming signer SHALL be `curves::ed25519::prehashed_signer`, its `sign` and `verify` giving and taking `ed25519::signature`; `curves::ed25519::ph` and a distinct Ed25519ph signature type MUST NOT exist. The documentation MUST say that an `eddsa` signature and an `eddsa_prehashed` signature, of one type, are not interchangeable. + +#### Scenario: RFC 8032's Ed25519ph vector as a scheme +- **WHEN** the key pair of RFC 8032 section 7.3 signs `crypto::prehashed{sha512("abc")}` with `crypto::eddsa_prehashed` +- **THEN** the signature is the RFC's, `crypto::verify(crypto::eddsa_prehashed, signature, crypto::prehashed{digest}, public_key)` accepts it, and `crypto::verify(crypto::eddsa, signature, "abc", public_key)` returns `invalid_signature` + +#### Scenario: The streaming signer and the scheme agree +- **WHEN** a message is given in pieces to `prehashed_signer` and signed, and its SHA-512 is signed with `sign(crypto::eddsa_prehashed, crypto::prehashed{digest})` +- **THEN** the two signatures are equal + +#### Scenario: A message under eddsa_prehashed +- **WHEN** a program calls `key.sign(crypto::eddsa_prehashed, message)` with a message, or with `crypto::prehashed{std::array{}}` +- **THEN** compilation stops with a message naming `crypto::prehashed{digest}` of 64 bytes, SHA-512's + +### Requirement: Secrets: erasing a buffer the program owns +`` SHALL declare `crypto::erase_secret(range)`, `noexcept`, for any contiguous sized range of non-const trivially copyable elements, zeroing its `size() * sizeof(element)` bytes with stores the optimiser keeps (`detail::wipe`); a range of const or non-trivially-copyable elements MUST stop the build with a message naming the ranges it accepts, and no pointer and size overload MUST exist. No function named `crypto::wipe` MUST exist. The guide SHALL group `constant_time_equal`, `erase_secret`, `secret` and `random_device` in one section about protecting secrets outside the primitives, all at the top of `webcpp::crypto`. + +#### Scenario: A password erased +- **WHEN** `crypto::erase_secret(password)` is called on a `std::string`, and on a `std::string const&` +- **THEN** the first zeroes its `size()` bytes, and the second does not compile, naming the ranges accepted + +### Requirement: Secret-key encryption: one namespace, and names spelled out +The library SHALL offer the AEAD contract in namespace `webcpp::crypto::secret_key_encryption::aead` (``, which every AEAD's header includes): the free `seal(cipher, nonce, associated_data, data)` and `open(cipher, nonce, associated_data, data, tag)`, and, in ``, `async_seal` and `async_open`; and NaCl's secret boxes in namespace `webcpp::crypto::secret_key_encryption` (`secretbox`, `secretbox_xchacha20poly1305` in ``). The algorithm types SHALL stay in `crypto::ciphers` under their names (`gcm`, `aes128_gcm`, `aes256_gcm`, `chacha20_poly1305`, `chacha20_poly1305_original`, `xchacha20_poly1305`, `aes128`, `aes192`, `aes256`). `crypto::seal`, `crypto::open`, `crypto::async_seal`, `crypto::async_open`, `ciphers::secretbox`, `ciphers::secretbox_xchacha20poly1305` and `` MUST NOT exist, with no alias. Every public name SHALL be spelled out, algorithm and format proper names excepted: a nonce is `nonce` (`nonce_bytes`, `nonce_size`, `max_nonce_size`, `error::invalid_nonce_size`, value 2), associated data `associated_data` (`associated_data_bytes`, `max_associated_data_size`), BIP340's auxiliary randomness `auxiliary_random_bytes`; no public name MUST contain `iv`, `additional_data`, `ad` or `ctx` as a word. + +#### Scenario: The old names are gone +- **WHEN** a program calls `crypto::seal(cipher, nonce, associated_data, data)`, names `crypto::ciphers::secretbox<>`, includes ``, or names `ciphers::xchacha20_poly1305<>::iv_size` or `crypto::error::invalid_iv_size` +- **THEN** it does not compile, and the same program with `crypto::secret_key_encryption::aead::seal`, `crypto::secret_key_encryption::secretbox<>`, ``, `nonce_size` and `invalid_nonce_size` builds and runs + +#### Scenario: A cipher's header brings its free forms +- **WHEN** a program includes `` alone and calls `crypto::secret_key_encryption::aead::seal(cipher, nonce, associated_data, data)` +- **THEN** it compiles and seals as `cipher.seal(nonce, associated_data, data)` does + +### Requirement: Names: the abbreviations taken from libsecp256k1 spelled out +The library SHALL name its one-shot AEAD template `ciphers::basic_chacha20_poly1305` (in ``), its aliases `ciphers::chacha20_poly1305`, `chacha20_poly1305_original` and `xchacha20_poly1305` keeping their names; and secp256k1's functions with their words spelled out: `musig::generate_nonce`, `public_key_tweak_add`, `public_key_tweak_mul`, `public_key_negate`, `public_key_combine`, `secret_key_tweak_add`, `secret_key_tweak_mul`, `secret_key_negate`, and silent payments' `previous_outputs_summary` and `make_previous_outputs_summary`. `ciphers::aead`, `musig::nonce_gen`, `pubkey_tweak_add`, `pubkey_tweak_mul`, `pubkey_negate`, `pubkey_combine`, `seckey_tweak_add`, `seckey_tweak_mul`, `seckey_negate`, `silent_payments::prevouts_summary` and `make_prevouts_summary` MUST NOT exist, with no alias. Algorithm and format proper names (`musig`, `ellswift`, `ecdh`, `xonly`, `xdh`) and secp256k1's `agree`, `agree_hashed` and `agree_point` SHALL keep their names; libsecp256k1's own C functions, which crypto calls, are not crypto's names. + +#### Scenario: The abbreviated names are gone +- **WHEN** a program names `crypto::ciphers::aead`, or calls `curves::secp256k1::pubkey_tweak_add`, `seckey_negate` or `musig::nonce_gen`, by a using-declaration or a call +- **THEN** it does not compile, and the same program with `ciphers::basic_chacha20_poly1305`, `public_key_tweak_add`, `secret_key_negate` and `musig::generate_nonce` builds and gives the same results + +#### Scenario: BIP327's nonce through the new name +- **WHEN** `musig::generate_nonce` runs BIP327's nonce generation vectors +- **THEN** it gives the vectors' public nonces, as `nonce_gen` did + +## MODIFIED Requirements + +### Requirement: Signatures: one name per operation, the scheme always named +`` SHALL declare, in namespace `webcpp::crypto`, the scheme tags `eddsa` (Ed25519, RFC 8032's pure form), `eddsa_prehashed` (Ed25519ph, RFC 8032's form over a SHA-512 digest), `ecdsa_sha256` (ECDSA with SHA-256 on P-256 and secp256k1), `ecdsa_sha256_recoverable` (secp256k1, the signature with its recovery id), `ecdsa_keccak256_recoverable` (secp256k1, Ethereum's recoverable ECDSA over Keccak-256) and `schnorr` (BIP340, secp256k1), constexpr objects of empty types whose default constructors are explicit; the marker `prehashed`, holding `std::span digest` and made by explicit constructors only, deduced from a `std::array`, a fixed-size span or a `boost::hash2::digest`, and refused for `std::dynamic_extent`; and the concepts `can_sign` and `can_verify`, the latter true only when `Signature` is the signature type of the public key's curve and of `Scheme`. Every key pair SHALL sign with `key.sign(scheme, input)`, returning `boost::system::result`, `T` the signature type of the key's curve and scheme, and every signature SHALL be verified with the free `crypto::verify(scheme, signature, input, public_key)`, returning `boost::system::result`, the input being a message (anything that converts to `std::span`) or a `prehashed` digest. Every `verify`, member and free, synchronous and asynchronous, and `curves::secp256k1::recover` SHALL take the signature as its typed value, made from bytes by the type's `from_bytes`, which returns `invalid_signature` for another size. No function MUST choose between a message and a digest by a span's extent or size, and no form without a scheme MUST exist. + +#### Scenario: A 32-byte message is a message +- **WHEN** a P-256 key pair signs `std::array` with `sign(crypto::ecdsa_sha256, message)` +- **THEN** the signature is that of the message's SHA-256, equal to `sign(crypto::ecdsa_sha256, crypto::prehashed{sha256_of_message})`, and `crypto::verify(crypto::ecdsa_sha256, signature, message, public_key)` accepts it + +#### Scenario: The backend named the same way on every curve +- **WHEN** a program calls `crypto::verify(scheme, signature, input, key)` with `B` the key's backend on P-256, `backends::sodium` on Ed25519 and `backends::secp256k1` on secp256k1 +- **THEN** each compiles and verifies, and on P-256 a `B` other than the key's backend does not compile + +#### Scenario: A signature received as bytes +- **WHEN** a signature arrives as a `std::vector`, is made into its curve's signature type and given to `key.verify`, `crypto::verify`, `key.async_verify` and `crypto::async_verify`, and the same with 63 or 65 bytes +- **THEN** every form compiles, the asynchronous ones on Ed25519 and P-256; the 64 bytes verify and the others give `invalid_signature` from `from_bytes`, on every curve + +#### Scenario: A call without a scheme +- **WHEN** a program calls `key.sign(message)` on any key pair +- **THEN** it does not compile + +### Requirement: Key pairs: one contract +`` SHALL declare the concept `crypto::keypair`: `K::from_secret(secret_bytes)` and `K::generate()` returning `result`, `public_key()` returning `result` and `secret()` returning `result>`, refined by `crypto::signing_keypair` and `crypto::agreement_keypair`. Every `basic_keypair` of Ed25519, X25519, P-256 and secp256k1 MUST satisfy `keypair`, checked by a `static_assert` in its curve's header; the public key a signing key pair gives MUST be accepted by `crypto::verify` for each of the curve's verifying schemes; ECDH MUST be named `agree(peer)` on every curve that has it, the peer the curve's typed public key, giving the shared secret (the shared point's raw x coordinate on P-256 and secp256k1, RFC 7748's output on X25519). + +#### Scenario: A key pair's public key verifies its signature +- **WHEN** any signing key pair `k` of the three signing curves signs `m` with one of its schemes `s` +- **THEN** `crypto::verify(s, signature, m, *k.public_key())` succeeds, with no conversion at the call + +#### Scenario: A key pair made again from its secret +- **WHEN** `K::from_secret(k.secret()->bytes())` is called for a key pair `k` +- **THEN** the new key pair has the same public key + +### Requirement: Ed25519: key pairs, signatures and strict verification +`curves::ed25519::basic_keypair` SHALL be made from a 32-byte seed (RFC 8032) or by `generate()`, give its public key as a `curves::ed25519::public_key` (`from_bytes` from 32 bytes, `bytes()` back), give its seed back with `secret()`, sign a message into a `curves::ed25519::signature` with `sign(crypto::eddsa, message)` and a message's SHA-512 with `sign(crypto::eddsa_prehashed, crypto::prehashed{digest})`, and convert itself to an X25519 key pair with `to_x25519()`; `crypto::verify(crypto::eddsa, signature, message, public_key[, policy])`, `public_key` a `curves::ed25519::public_key`, the policy a trailing tag object, `curves::ed25519::strict` by default, MUST return nothing on success and `invalid_signature` otherwise; a key of another size is refused earlier, by `curves::ed25519::public_key::from_bytes` with `invalid_public_key`. On libsodium verification is strict (canonical encodings, no small-order key, `S` reduced); the documentation MUST say which inputs other backends accept that libsodium refuses, as Wycheproof's EdDSA file shows. + +#### Scenario: RFC 8032's test 1 +- **WHEN** the key pair is made from RFC 8032 section 7.1's first secret key and signs the empty message with `sign(crypto::eddsa, message)` +- **THEN** the public key and the signature are the RFC's, and `crypto::verify(crypto::eddsa, signature, message, public_key)` accepts them + +#### Scenario: A small-order public key +- **WHEN** `crypto::verify(crypto::eddsa, signature, message, public_key, curves::ed25519::strict)` is given a small-order public key (ed25519-speccheck's case 0) +- **THEN** it returns `invalid_signature` + +### Requirement: Ed25519ph: an incremental signer +`curves::ed25519::prehashed_signer`, with `Hash` webcpp::hash's `sha2_512` as RFC 8032 requires, SHALL sign and verify a message given in pieces (`begin`, `update`, `sign(key)` giving a `curves::ed25519::signature`, or `verify(signature, public_key)` taking one) through libsodium's `crypto_sign_ed25519ph_*`, and refuse another hash at compile time with a message naming `curves::ed25519::prehashed_signer`; its signature MUST equal `sign(crypto::eddsa_prehashed, crypto::prehashed{digest})` of the message's SHA-512. `curves::ed25519::ph` MUST NOT exist, with no alias. + +#### Scenario: RFC 8032's Ed25519ph vector +- **WHEN** RFC 8032 section 7.3's message is given in two pieces +- **THEN** the signature is the RFC's + +### Requirement: Equal: constant time on tags +`constant_time_equal(digest const&, digest const&)`, in ``, SHALL be `noexcept`, read every byte, and neither branch nor index on one: it accumulates the XOR of every pair of bytes with OR in a `volatile` local read once after the loop, and reduces the result to one bit without a branch, as BearSSL's tag check does. It MUST serve Boost.Hash2's `hmac::result()` as much as the library's tags. `crypto::equal` and `` MUST NOT exist, with no alias. + +#### Scenario: Two 32-byte digests differing in the last byte +- **WHEN** `constant_time_equal` compares them +- **THEN** it returns false after reading all 32 bytes, and the deterministic check passes at -O2 and -Os + +### Requirement: Equal: spans of different sizes +`constant_time_equal(std::span, std::span)` SHALL compare spans of different sizes as unequal without reading their contents, because a size is public, and MUST take a `digest` against a `std::array` (a digest is a contiguous range of `unsigned char`); two empty spans are equal. + +#### Scenario: Empty spans +- **WHEN** `constant_time_equal` compares two empty spans +- **THEN** it returns true + +### Requirement: X25519: agreement and the conversion +`curves::x25519::basic_keypair` SHALL give its `x25519::public_key` from its 32-byte secret, agree a `secret<32>` with a peer's `x25519::public_key` by `agree(peer)`, and return `weak_public_key` when the result is all zero on every backend. `curves::ed25519::public_key::to_x25519()` MUST return the birational map's result as an `x25519::public_key`, or `invalid_public_key` for a key that is not canonical or of small order. + +#### Scenario: RFC 7748's agreement +- **WHEN** Alice's and Bob's key pairs of RFC 7748 section 6.1 agree in both directions +- **THEN** both give the RFC's shared secret + +#### Scenario: Conversion agrees with signing keys +- **WHEN** an Ed25519 key pair's `to_x25519()` gives an X25519 key pair +- **THEN** its `public_key()` equals the Ed25519 key pair's public key's `to_x25519()` + +### Requirement: Boxes: crypto_box, sealed boxes and secretbox +The library SHALL offer `public_key_encryption::box` (X25519, XSalsa20-Poly1305) and `public_key_encryption::box_xchacha20poly1305`, made from an `x25519::basic_keypair` and a peer's `x25519::public_key` so that the shared key is computed once (libsodium's `beforenm`), with `seal(nonce, data)` and `open(nonce, data, tag)` in place and the 16-byte tag apart; `public_key_encryption::sealed_box::seal(recipient, data, out)`, `recipient` an `x25519::public_key`, and `open(recipient, sealed, out)`, `recipient` an `x25519::basic_keypair`; and `secret_key_encryption::secretbox` and `secret_key_encryption::secretbox_xchacha20poly1305`, in ``, keyed objects over 32-byte keys with 24-byte nonces, `seal(nonce, data)` and `open(nonce, data, tag)`, taking no associated data. A failed `open` MUST zero `data`, as the genesis's AEADs do. + +#### Scenario: A sealed box opened by its recipient +- **WHEN** a message is sealed to a recipient's `x25519::public_key` and opened with the recipient's key pair +- **THEN** it opens, and a sealed box changed in one byte returns `authentication_failed` with `data` zeroed + +### Requirement: Key exchange: crypto_kx +`key_exchange::kx_keypair` SHALL be made from an `x25519::basic_keypair` by `from_keypair`, by `generate()`, or from a 32-byte seed by `derive_from_seed(seed)`, libsodium's `crypto_kx_seed_keypair` (the secret is BLAKE2b-256 of the seed), no other factory taking a seed, give its `x25519::public_key`, and compute `client_session_keys(server_public_key)` and `server_session_keys(client_public_key)`, each peer an `x25519::public_key`, each returning a receive key and a transmit key as `secret<32>`, through libsodium's `crypto_kx`, and return `weak_public_key` where libsodium refuses the peer's key. + +#### Scenario: Client and server agree +- **WHEN** a client and a server compute their session keys from each other's public keys +- **THEN** the client's transmit key is the server's receive key and the reverse + +#### Scenario: A seed is not a secret +- **WHEN** the same 32 bytes are given to `kx_keypair::derive_from_seed` and, as an X25519 secret, to `kx_keypair::from_keypair(*x25519::keypair::from_secret(bytes))` +- **THEN** `derive_from_seed` gives the keys of libsodium's `crypto_kx_seed_keypair` for that seed, and its public key differs from `from_keypair`'s + +### Requirement: Interface: one AEAD template for the one-shot AEADs +`ciphers::basic_chacha20_poly1305` (named `ciphers::aead` before owner decision 14) SHALL implement the guards, the in-place `seal` and `open`, the tag apart, the zeroing of `data` after a failed `open` and the move rules of the genesis's `ciphers::chacha20_poly1305` for every one-shot AEAD with associated data, its family tag giving `key_size`, `nonce_size`, `tag_size`, `max_message_size` and `max_associated_data_size`, and every instance MUST satisfy `secret_key_encryption::aead::cipher`. `ciphers::chacha20_poly1305` (12-byte nonce), `ciphers::chacha20_poly1305_original` (8-byte nonce) and `ciphers::xchacha20_poly1305` (24-byte nonce) MUST be its aliases; secretbox is not, being an `authenticated_box` (`secret_key_encryption::basic_secretbox`); `ciphers::gcm` keeps its own class and its incremental seal and open, a `secret_key_encryption::aead::streaming_cipher`. + +#### Scenario: XChaCha20-Poly1305's nonce +- **WHEN** `ciphers::xchacha20_poly1305::seal` is called with a 12-byte nonce +- **THEN** it returns `invalid_nonce_size` and `data` is untouched + +### Requirement: P-256: a key pair from a raw scalar, raw ECDH and low S +Increment 3 SHALL add, on BearSSL on all four targets and first of the P-curves (`design.md` D36), `curves::p256::basic_keypair::from_secret` from a raw 32-byte big-endian secret scalar d, refusing another size with `invalid_key_size` and d = 0 or d >= n with `invalid_secret_key` by a constant-time comparison before any backend call, and computing the public key; `generate()`, drawing from `random_device` until the scalar is valid; `secret()`, the scalar as `secret<32>`; `sign(crypto::ecdsa_sha256, input)` over the message's SHA-256 or a 32-byte `prehashed` digest, with RFC 6979's nonce, returning a `p256::ecdsa_signature`, `r || s` (IEEE P1363, 64 bytes) with low S: RFC 6979's signature, its s replaced by n - s when above (n - 1) / 2; `agree` with a validated peer key, returning the shared point's x coordinate as `secret<32>` (WebCrypto's `deriveBits` of 256 bits); `crypto::verify(crypto::ecdsa_sha256, signature, input, public_key)` accepting a valid signature whatever its S, refusing with `invalid_signature` a signature whose r or s is 0 or not below n (checked by webcpp before any backend call) and one that does not verify, and refusing a signature over a digest whose value modulo n is 0 (32 zero bytes, or n itself) as `invalid_signature` even when `sign` made it, BearSSL's verification refusing a zero multiplier, a limit its documentation states (no SHA-256 of a message gives that digest in practice); and `normalize_low_s` (the low-S form) and `is_low_s` (true exactly when 0 < r < n and 0 < s <= (n - 1) / 2), which call no backend. Verification MUST NOT impose low S, since WebCrypto's signatures may be high; a protocol that requires it of its peers (Trystero) checks `is_low_s` before `crypto::verify`. Every public function of the family that calls a backend MUST hold `detail::timing_guard` and be called by `test/timing_coverage_bearssl_test.cpp`; those that call none MUST be checked to enter none. Tests MUST run RFC 6979 section A.2.5's P-256 and SHA-256 cases, OpenSSL natively with deterministic nonces as a byte-for-byte oracle, and node's WebCrypto on Emscripten both ways. + +#### Scenario: A Trystero peer's stored scalar +- **WHEN** `basic_keypair::from_secret` is given the 32-byte scalar of RFC 6979 section A.2.5's P-256 key +- **THEN** `public_key().uncompressed()` is `0x04` followed by that section's Ux and Uy, `secret()` gives the 32 bytes back, and `sign(crypto::ecdsa_sha256, "sample")` is the section's r and n - s, the section's s being high + +#### Scenario: A scalar out of range +- **WHEN** `from_secret` is given n, n + 1 or 32 zero bytes +- **THEN** it returns `invalid_secret_key` without calling BearSSL, and 31 or 33 bytes give `invalid_key_size` + +#### Scenario: ECDH with WebCrypto +- **WHEN** node's WebCrypto imports the same scalar (`pkcs8` from `encode_pkcs8`) and a peer's raw public key and derives 256 bits +- **THEN** the bits equal `agree` of the key pair with the peer's `basic_public_key` + +#### Scenario: A high-S signature from a peer +- **WHEN** `crypto::verify` is given RFC 6979's signature of "sample" as the section prints it, whose S is high, as WebCrypto may sign +- **THEN** it accepts it, `is_low_s` is false, and `normalize_low_s` returns `r || n - s`, which is what `sign` gives, `is_low_s` accepts, and WebCrypto verifies + +#### Scenario: A digest that is 0 modulo n +- **WHEN** `sign(crypto::ecdsa_sha256, crypto::prehashed{digest})` signs 32 zero bytes, or the 32 bytes of n, and `crypto::verify` is given that signature, the same marker and the key pair's public key, on BearSSL +- **THEN** `sign` succeeds and `crypto::verify` returns `invalid_signature` + +### Requirement: Asynchronous family: completion tokens, for what the browser offers +`` SHALL offer `async_from_secret`, `async_from_key`, `async_generate`, `async_seal`, `async_open`, `async_encrypt`, `async_decrypt`, `async_sign`, `async_verify`, `async_agree`, `async_wrap`, `async_unwrap` and `async_export` for every algorithm WebCrypto offers, each an Asio asynchronous operation in webcpp::asio's model (initiated through `async_initiate`, any completion token: a callback, `use_awaitable`, Cobalt's, `use_future`) taking first the executor its completion is posted to, and completing with `void(boost::system::error_code, T)`, `T` the empty object a move leaves when the code is an error, or with `void(boost::system::error_code)` where the synchronous call returns no value. Each family's asynchronous default backend MUST be its synchronous default on every target, Emscripten included; `backends::browser` is used only where a type names it. On `backends::browser` each MUST call WebCrypto, with or without pthreads, and await its promise through `webcpp::asio::browser::async_await`, completing on the handler's associated executor; on a synchronous backend each MUST run the synchronous call and complete through `asio::post`, never inside the initiating call. An `async_` variant of a cheap algorithm WebCrypto lacks MUST NOT exist, except `async_from_key`, `async_seal` and `async_open` of every `secret_key_encryption::aead::cipher` and `secret_key_encryption::authenticated_box` (the free AEAD forms in `secret_key_encryption::aead`, the box forms in `secret_key_encryption`), which exist on every native backend and stop the build on `backends::browser` for any algorithm but AES-GCM, from their synchronous forms too, with a message saying WebCrypto has no such algorithm and no form of it runs there. The synchronous API MUST NOT call WebCrypto. The convenience header MUST leave out `async.hpp` and `backends/browser.hpp`, naming webcpp::asio as the reason. + +#### Scenario: One coroutine, two targets +- **WHEN** a coroutine `co_await secret_key_encryption::aead::async_seal(executor, cipher, nonce, associated_data, data, use_awaitable)` runs natively on BearSSL and on Emscripten on the browser +- **THEN** both complete with the same ciphertext and tag for the same key, nonce and message + +#### Scenario: A callback is never called inline +- **WHEN** `async_seal` on a synchronous backend is given an `io_context`'s executor and a callback that sets a flag +- **THEN** the flag is unset when `async_seal` returns, and set after the executor runs + +#### Scenario: No asynchronous variant of a cheap algorithm the browser lacks +- **WHEN** a program calls `async_seal` on `ciphers::xchacha20_poly1305` on libsodium, and on a backend whose `asynchronous_backend_v` is true +- **THEN** the first compiles and seals as `ciphers::xchacha20_poly1305::seal` does, and the second does not compile + +### Requirement: secp256k1: recovery, raw ECDH, tweaks and key forms +Increment 2 SHALL add, as thin wrappers over libsecp256k1 v0.8.0: `sign(crypto::ecdsa_sha256_recoverable, input)` and `recover(crypto::ecdsa_sha256_recoverable, signature, input)` (65-byte signatures with the recovery id, the input a message hashed with SHA-256 or a 32-byte `prehashed` digest); `agree` (the shared point's 32-byte x coordinate) and `agree_point` (its 65-byte uncompressed form) as `secret<32>` and `secret<65>`; `secret_key_tweak_add`, `secret_key_tweak_mul`, `secret_key_negate`, `public_key_tweak_add`, `public_key_tweak_mul`, `public_key_negate` and `public_key_combine` (named `seckey_*` and `pubkey_*` before owner decision 14); `public_key::from_bytes` of 33 and 65 bytes and the key's `compressed()` and `uncompressed()`; and `sign(crypto::ecdsa_sha256, input, extra_entropy)` (hedged signing). + +#### Scenario: Ethereum's recovery +- **WHEN** a recoverable signature of a digest is made with `prehashed` and `recover` is given the scheme, the signature and the same marker +- **THEN** it returns the signer's public key, for random keys and for libsecp256k1's own recovery test cases + +#### Scenario: Nostr's shared x coordinate +- **WHEN** two key pairs compute `agree` with each other's public keys +- **THEN** both give the same 32 bytes, the x coordinate of the shared point, unhashed + +### Requirement: secp256k1: the tweaks share one shape +`public_key_negate` SHALL return `result`, `noexcept`, returning `backend_failure` should libsecp256k1 refuse a parsed key, as `secret_key_tweak_add`, `secret_key_tweak_mul`, `secret_key_negate`, `public_key_tweak_add`, `public_key_tweak_mul` and `public_key_combine` return `result<>`. `basic_keypair::agree_hashed` (was `ecdh`), `agree` (was `ecdh_x`) and `agree_point` (was `ecdh_point`) SHALL return `result>`, `result>` and `result>`, pinned by a compile-time check. + +#### Scenario: Negation twice +- **WHEN** a parsed key P is negated twice with `public_key_negate` +- **THEN** both results hold values and the second equals P + +### Requirement: ChaCha20-Poly1305: on libsodium, BearSSL and OpenSSL in version 0.2 +Increment 1 SHALL add `ciphers::chacha20_poly1305` (RFC 8439, a 32-byte key, a 12-byte nonce, a 16-byte tag) over `ciphers::basic_chacha20_poly1305` (named `ciphers::aead` before owner decision 14) on libsodium (every target), BearSSL (every target) and OpenSSL (native, wasip2, wasip3), which is the genesis's increment 4 built on the foundation's AEAD template. Its tests MUST be the genesis's: RFC 8439's vectors, Wycheproof's ChaCha20-Poly1305 file on each backend, the cross-backend agreement of the three, the counting allocation tests, OpenSSL's error queue left as found, ctaes's refusal from a message test of its own, the constant-time cases, and, once the memory option has merged, its part of the memory option's tests. + +#### Scenario: Three backends agree +- **WHEN** `agree_aead` runs natively on libsodium, BearSSL and OpenSSL from one seed +- **THEN** every ciphertext and tag is identical and each backend opens the others' + +#### Scenario: ctaes has no ChaCha +- **WHEN** a program names `ciphers::basic_chacha20_poly1305` +- **THEN** compilation stops naming the backends that have ChaCha20-Poly1305 diff --git a/libraries/crypto/openspec/changes/uniform-types/tasks.md b/libraries/crypto/openspec/changes/uniform-types/tasks.md new file mode 100644 index 0000000..d3d752a --- /dev/null +++ b/libraries/crypto/openspec/changes/uniform-types/tasks.md @@ -0,0 +1,65 @@ +# Tasks + +Implemented after crypto/sign-unified merges and before crypto's formats. Each task writes its +tests first; the library builds at the end of every task, and every caller of a removed name moves +in the task that removes it. A plan with code goes in `reference/plan.md` when the proposal is +accepted. + +Built (2026-11-23 and 2026-11-24) in the order X3, 2.5, 2.4, X2, 1.1 to 1.4, 2.1, X4, 2.2, 2.3, 3.1 +to 3.3, X1, X1b, X5, 4.1, on the branches `crypto/uniform-types` of webcpporg/crypto (head +`e07d44a`), webcpporg/hash (`659e50d`, X2's callers, `main` merged into it) and the superproject +(`0ab0ace`), each task reviewed clean. Where the code differs from the design or the plan, +`design.md` says so under "As built". + +## 1. Typed signatures + +- [x] 1.1 The signature class template in `detail` and its five types (no distinct Ed25519ph type: owner decision 12), `from_bytes`, `bytes()`, `recovery_id()`; the scheme traits gain the signature type; message tests for a signature of another curve or scheme (design D1) +- [x] 1.2 Every `sign` returns its type and every `verify` and `recover` takes it, the four forms, the asynchronous completions; the span overloads removed; `normalize_low_s` and `is_low_s` on the ECDSA types; Ed25519ph's streaming signer retyped onto `ed25519::signature`; callers moved (D1, R1) +- [x] 1.3 `crypto::ecdsa_keccak256_recoverable` on secp256k1: Keccak-256 inside or `prehashed`, the typed recoverable signature, `recover`, no `verify`; go-ethereum's vectors, an EIP-191 example, the refusal without XKCP (owner decision 10, D8) +- [x] 1.4 Ed25519ph as the scheme `crypto::eddsa_prehashed` on Ed25519's key pair: `crypto::prehashed{digest}` of 64 bytes only, a message refused at compile time, `ed25519::signature`, `verify` member and free, asynchronous on native backends only; `curves::ed25519::ph` renamed `prehashed_signer`, no alias; RFC 8032's Ed25519ph vectors and the streaming signer equal to the scheme (owner decision 12, D9) + +## 2. X25519 typed + +- [x] 2.1 `x25519::public_key` and `x25519::basic_keypair` with `from_secret`, `generate`, `public_key()`, `secret()`, `agree`, the asynchronous members and the free forms; the free `public_key(secret)` and `agree(secret, peer)` removed; RFC 7748's vectors (D2) +- [x] 2.2 `kx_keypair` on the typed key pair, `from_keypair`, `generate` and `derive_from_seed`, tested against `crypto_kx_seed_keypair` and against `from_keypair` on the same bytes; the boxes and the sealed box on typed keys (D3, R5, R6, owner decision 7) +- [x] 2.3 Ed25519's `to_x25519()` on the key pair and the public key, the free `crypto::to_x25519`; `x25519_secret()` and `to_x25519_public` removed (D3, R4) + +- [x] 2.4 `crypto::public_key_encryption` and `crypto::key_exchange`: the boxes, the sealed boxes, `kx_keypair` and `session_keys` moved with their headers, `crypto::hybrid` removed with no alias; every caller moved (tests, examples, fixtures, the page, `crypto.json` and its generated files, the MSVC and message tests), the convenience header updated (D3b, owner decision 8) + +- [x] 2.5 Factories named by their input: every `make` and `async_make` renamed (`from_secret`, `from_bytes`, `from_coordinates`, `from_key`, `from_keys`, `from_keypair`), `make.hpp` to `factories.hpp`, no alias; every caller moved; a message test that `make` no longer exists (D3c, owner decision 9) + +## 3. Concepts + +- [x] 3.1 `keypair`, `signing_keypair`, `agreement_keypair` and each curve's `static_assert`s; `crypto::sign`, `crypto::agree` and their asynchronous forms constrained; message tests (D4) +- [x] 3.2 ``: `secret_key_encryption::aead::cipher` and `streaming_cipher`, and the free `crypto::seal`/`open` moved there as `secret_key_encryption::aead::seal`/`open`, constrained; ``: `secret_key_encryption::authenticated_box` and the box forms `secret_key_encryption::seal`/`open`; `ciphers::secretbox` moved to `secret_key_encryption/secretbox.hpp` as `secret_key_encryption::basic_secretbox`, `secretbox`, `secretbox_xchacha20poly1305`, without associated data, no alias; each cipher's `static_assert`; every caller of the moved names migrated; message tests for the removed names (D5, R7, R21, R23, owner decision 13) +- [x] 3.3 `async_seal`, `async_open` and `async_from_key` for every AEAD and box on native backends: the free `crypto::async_seal`/`async_open` moved into `secret_key_encryption::aead` (callers migrated, a message test for the removed names), the box forms `secret_key_encryption`'s; the browser stand-in's refusal (D6, R21, R23) + +## 4. The page, the generated files and the delivery + +- [x] 4.1 The guide's chapters (signatures, X25519, AEADs and `secret_key_encryption`, with decision 14's names: `ciphers::basic_chacha20_poly1305`, secp256k1's spelled-out functions), the section about protecting secrets outside the primitives (`constant_time_equal`, `erase_secret`, `secret`, `random_device`; owner decision 11), `crypto.json` and its generated files, the changelog line +- [ ] 4.2 Full local verification on every lane (native, Emscripten, wasip2, wasip3, MSVC, gcc, the constant-time lane, the Linux lint), pull requests, merge, one CI at the end (plan: Task 4.2) + - [x] Native clang 836 passed, 0 failed; gcc-15 407/0; Emscripten 329/0 (both variants); wasip2 492/0; wasip3 474/0; `generate.py`, the doc tables and the doc build pass; X3's survey is empty (superproject `586b869`, crypto `e7dc82e`, hash `659e50d`) + - [x] `crypto_jamfiles_test.py`: 168 passed and 1 failed (`heavy_without_threads_on_emscripten` still named `token`, X3's rename), the fixture fixed in fix round 1: 169 passed + - [x] MSVC 14.3 x64, 14.5 x64 and 14.5 arm64: 461 passed each, `user_globals` passes; `async_aead` and `async_aead_no_exceptions` failed on C4459 (a test's global named after a library parameter), fixed in fix round 1 by renaming the test's globals; MSVC 14.5 x64 8/8 on the touched targets + - [x] Linux lint `--full` CLEAN (1309 translation units), the macOS full lint clean; fix round 1's files CLEAN (1310) + - [x] Constant-time lane 14/14 (memcheck, MemorySanitizer, dudect), `x25519_agree`'s |t| 1.74 to 2.49, within `crypto.json`'s range; fix round 1 adds the paths of `erase_secret`, X25519's key pair's wipe and kx's `from_keypair`: 14/14 + - [x] The whole-branch review's findings fixed (fix round 1: crypto `e7dc82e..e07d44a`, superproject `586b869..0ab0ace`): the browser's JavaScript array zeroed after a draw, the stack copies of libsodium's draws wiped, the guidelines' present-tense names, the removed names pinned, the changelog, the include boundary, the overview's namespaces + - [ ] The fix round's scoped re-review + - [ ] `origin/main` merged into the branches; the pull requests in webcpporg/crypto, webcpporg/hash, webcpporg/proposals and webcpporg/webcpp (the pointers of libs/crypto and libs/hash); merge commits; one CI at the end, green on GitHub + +## 5. Small fixes found along the way + +- [x] X1 In the browser a throwing `crypto.getRandomValues` gives `entropy_unavailable` to `random_device` and every caller of `detail::read_entropy`, never a terminated page; reproduced first under node (controller ruling) +- [x] X1b libsodium's own randomness on Emscripten (its stir in `sodium_init`, the sealed box's ephemeral key) goes through crypto's entropy, so that a throwing `getRandomValues` is `entropy_unavailable` there too; reproduced first (controller ruling) +- [x] X2 A public `crypto::erase_secret` in `` for any non-const contiguous sized range of trivially copyable elements, over `detail::wipe`; `crypto::equal` renamed `crypto::constant_time_equal` (``), no alias, every caller moved, webcpp::hash's and the superproject's fixtures included; tests, message tests, the pages and the namespace table's rows (controller ruling, owner decision 11, D10) +- [x] X3 No one-word local or parameter in a public header (MSVC C4459 at /W4 /WX): renamed, and a test whose globals carry every such name compiles warning-free on MSVC (controller ruling) +- [x] X4 Public names spelled out, on the names that stay where they are (3.2 and 3.3 move the AEAD forms and secretbox with decision 13's names, R23): `iv`/`iv_bytes` -> `nonce`/`nonce_bytes` and `additional_data` -> `associated_data` on the existing members, free forms and engines; `nonce_size`, `max_nonce_size`, `max_associated_data_size`, `error::invalid_nonce_size` (value 2 kept); `aux_random` -> `auxiliary_random_bytes`, `ctx` -> `context` and any other abbreviation; every call site of those names, the superproject's fixtures included; the rule in CODING-GUIDELINES.md; webcpp::trystero and hash's HKDF names out of scope; runs after 2.1, before 2.2 (controller ruling, owner decision 13, D11, R22, R23) +- [x] X5 The remaining spelled-out names (owner decision 14, D12, R24, R25), after X1b and before 4.1: first commit, D6's refusal reworded to say no form of the constructions WebCrypto lacks runs on the browser's backend, its message tests and generated pages; then `ciphers::aead` -> `ciphers::basic_chacha20_poly1305` (aliases unchanged, header unchanged, the timing seam's member labels following); `musig::nonce_gen` -> `generate_nonce`; `pubkey_tweak_add`/`_mul`/`negate`/`combine` -> `public_key_*`; `seckey_tweak_add`/`_mul`/`negate` -> `secret_key_*`; silent payments' `prevouts_summary`/`make_prevouts_summary` -> `previous_outputs_summary`/`make_previous_outputs_summary`; no alias; every call site, doc, example, test, fixture and the superproject migrated; message tests for the removed names, `alone`; webcpp::trystero out of scope (controller ruling) + +## Open + +- [ ] webcpp::trystero's port of Trystero 0.27 moves to the new names by its own stream (decisions 11, 13 and 14): `crypto::equal` in `room_keys.hpp` (its include and line 231) and `doc/protocol.adoc`, and any use of `ed25519::ph`, `crypto::seal`/`open`, `ciphers::secretbox` or an `iv` parameter; none of X5's removed names on 2026-11-23. +- [ ] An Ed25519 backend other than libsodium (OpenSSL's `Ed25519ph` signs a finished digest through a public API): until one exists, `eddsa_prehashed` depends on libsodium's internal functions (design "As built", P27). +- [ ] If webcpp::hash, which shares libsodium, calls `sodium_init` before crypto's first call, libsodium's JavaScript stir runs first and can still throw on Emscripten; crypto cannot reach it. +- [ ] Natively, libsodium's `randombytes_sysrandom` still aborts on a failed generator; X1b changes Emscripten only. +- [ ] R24 (`prevouts_summary` read as an abbreviation of decision 14) waits for the owner's confirmation.