From eecca14affa7b6dcccab6d1901c80e851b127131 Mon Sep 17 00:00:00 2001 From: R Date: Sat, 5 Dec 2026 08:14:11 -0300 Subject: [PATCH 01/22] crypto: backend-concepts as built from the primitives head: the device-backends text, stream_cipher and authenticator in D4, GCM on BearSSL and OpenSSL, base64 out of crypto, STATUS with the bases and rulings --- .../changes/backend-concepts/design.md | 42 ++++++++++++++++++- .../backend-concepts/reference/STATUS.md | 39 +++++++++++++++++ 2 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md diff --git a/libraries/crypto/openspec/changes/backend-concepts/design.md b/libraries/crypto/openspec/changes/backend-concepts/design.md index cc71687..868e697 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/design.md +++ b/libraries/crypto/openspec/changes/backend-concepts/design.md @@ -36,6 +36,28 @@ the engines it describes (typed keys and signatures, X25519's key pair, the boxe link. `capabilities_test` checks that a present cell has a specialization; nothing checks the specialization's operations. +## As built from (2026-12-05) + +The implementation starts from crypto `c638dbf` (the primitives change, branch `crypto/primitives`, +not yet merged) and the superproject `34ea790`; formats, codecs, HPKE, api-gaps and async part A are +merged. What that changes in the context above, ruled while building (`reference/STATUS.md`): + +- **Two engines more**: the primitives change added `stream_engine` (`init`, + `apply(state, nonce, initial_counter, data)`, `move`, `reset`) on libsodium, BearSSL and OpenSSL, + and `authenticator_engine` (one static `authenticate(key, message, tag)`, + no state) on libsodium and OpenSSL. D4 gains `stream_cipher` and + `authenticator`. +- **GCM is on BearSSL and OpenSSL only**, and the AES block cipher on ctaes and OpenSSL (BearSSL's + `block_engine` is a refusal of its own); the incremental open is today's `start`, `run` and + `check`, so `gcm_incremental_open` is not a concept of its own. +- **base64 left crypto**: the codecs library (webcpp::codecs) encodes and decodes base64, and the + PEM engine is gone; the encoding area of D4 has no concept, and R4's `base64_engine` is not built. +- **The box families are tags without sizes**: both crypto_box families have a 24-byte nonce and a + 16-byte tag, which the `box` concept names as constants. +- **The formats engines** are `ed25519_formats_engine` and `x25519_formats_engine` on libsodium; + P-256's and secp256k1's formats call the curve's engine or library directly. +- **HPKE** composes the curves' and webcpp::hash's public types and has no engine of its own. + ## Intent (owner, 2026-11-22) Put the library's capabilities into concepts; a backend implements only the concepts it has. The @@ -151,6 +173,13 @@ and in `capabilities_test`, the coverage tests and the lanes): ### D3. The opaque key +> **Amended on 2026-11-30 by device-backends**: "a backend whose keys never leave it implements +> neither `*_import` nor `*_export`" is now said by two public traits generated from the table: +> `crypto::exports_secret_keys_v` (no `*_export`, browser-backend's D16) and +> `crypto::imports_secret_keys_v` (no `*_import`), whose refusals speak before the capability +> assertions of D9; a backend may also keep `*_import` and refuse one key at run time (a PKCS#11 token, +> `not_supported`). The text below is as approved. + A key capability is split by what it does to the key: | Capability | Meaning | Needs the secret in memory | @@ -185,10 +214,12 @@ It is a test tool, not a shipped backend: outside the table, `supports_v` and th | Area | Concept (`detail::backend::`) | Operations | Engines checked | |---|---|---|---| | Symmetric | `block_cipher` | `init`, `encrypt`, `decrypt`, `move`, `reset` | `block_engine` on OpenSSL, ctaes | -| | `gcm` | `init`, `start`, `run`, `tag`, `check`, `move`, `abandon`, `reset` | `gcm_engine` on BearSSL, OpenSSL, ctaes | +| | `gcm` | `init`, `start`, `run`, `tag`, `check`, `move`, `abandon`, `reset` | `gcm_engine` on BearSSL, OpenSSL | | | `gcm_incremental_open` | the incremental open's `start`, `authenticate`, `decrypt`, `verify`, `finish` | as GCM where offered | | | `aead` | `init`, `seal(iv, ad, data, tag)`, `open(iv, ad, data, tag)`, `move`, `reset` | `aead_engine` for each family on BearSSL, OpenSSL, libsodium | | | `authenticated_box` | `init`, `seal(iv, data, tag)`, `open(iv, data, tag)`, `move`, `reset` | secretbox on libsodium | +| | `stream_cipher` | `init`, `apply(nonce, initial_counter, data)`, `move`, `reset`; the nonce the family's `nonce_size`, the counter its `counter_type` | `stream_engine` on libsodium, BearSSL, OpenSSL | +| | `authenticator` | one static `authenticate(key, message, tag)`, no state; `verify` is crypto's own constant-time comparison | `authenticator_engine` on libsodium, OpenSSL | | Public-key encryption | `box` | `init(own, peer)`, `seal`, `open`, `move`, `reset` | `box_engine` on libsodium | | | `sealed_box` | `seal(recipient, data, out)`, `open(recipient, sealed, out)` | `sealed_box_engine` on libsodium | | Key exchange | `kx` | `derive_from_seed`, `client_session_keys`, `server_session_keys` over X25519 states | `kx_engine` on libsodium | @@ -224,6 +255,15 @@ failed). ### D6. Asynchronous and opaque together +> **Amended on 2026-11-30 by browser-backend** (owner decision of 2026-11-23): a backend that +> completes by itself may also implement the synchronous concepts by waiting for its own +> completion; `backends::browser` does, its synchronous engine functions suspending the +> WebAssembly stack (and refusing with `error::cannot_suspend` where it cannot suspend). The +> public synchronous forms refuse only where the engine lacks the synchronous capability. Whether a +> backend lets secret key bytes leave it is the trait `detail::exports_secret_keys_v` +> (browser-backend's D16, owner decision of 2026-11-30), checked against the `*_export` concepts. +> The paragraph below is the text as approved. + A backend that completes by itself (`asynchronous_backend_v`) implements the `async_*` concepts and none of the synchronous ones; the public synchronous forms keep refusing with the name of their `async_` form (crypto/sign-unified's D9). Export of an extractable opaque key is `async_export`, diff --git a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md new file mode 100644 index 0000000..2bfe434 --- /dev/null +++ b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md @@ -0,0 +1,39 @@ +# webcpp::crypto backend-concepts: where the implementation stands + +2026-12-05: task 1.1 built (the symmetric and box concepts and their test), on the primitives +change's head; tasks 1.2 to 4.2 not started. Nothing is pushed: the primitives change merges first. + +## The bases + +| Repository | Branch | Base | +| --- | --- | --- | +| webcpporg/crypto | `crypto/backend-concepts` | `c638dbf` (primitives, `crypto/primitives`) | +| webcpporg/webcpp | `backend-concepts` | `34ea790` (primitives' superproject) | +| webcpporg/proposals | `crypto/backend-concepts` | `origin/main`, with this change's text from `629bfb3` (the device-backends planning branch, the newest) | + +## Rulings made while building + +- **The plan's text is the device-backends planning branch's (`629bfb3`)**: the newest, carrying + browser-backend's and device-backends' amendments to D3 and D6; `origin/main` has the 2026-11-23 + text without them. Cost if wrong: two amendment notes to drop. +- **`stream_cipher` and `authenticator` join D4** (the primitives change's 7.4 note), with the + engines' operations as built. Cost: none. +- **`gcm_incremental_open` is not a concept of its own**: the incremental open is GCM's `start`, + `run` and `check`, which `gcm` already requires. Cost: none. +- **No `base64` concept**: base64 moved to webcpp::codecs and the PEM engine is gone; R4's + `base64_engine` is not built. Cost if wrong: one concept to add if crypto takes an encoding + engine back. +- **The `box` concept names the sizes as constants** (24-byte nonce, 16-byte tag): the box family + types are tags without sizes. Cost: none. +- **Task 1.1's "message tests for a missing operation" are a run test of stand-ins**: a compiler's + concept-failure notes differ between Clang, GCC and MSVC versions, so `-verify` on them would + pin one compiler's wording; `backend_concepts_symmetric_test` proves each requirement with a + stand-in that lacks it. The plain-words messages are task 3.2's, which name the capability. + Cost if wrong: message tests to add in 3.2. +- **No implementer or reviewer subagents in this run**: the stream ran as a fork that may not start + subagents, so task 1.1 has no independent review yet. Cost: the review is owed before delivery. + +## Verification + +- Task 1.1: `backend_concepts_symmetric` (with and without exceptions) and the three headers + compiled alone, green on Clang, GCC 15, wasip2 and Emscripten. From 4d5fc073f0550911cd730412223c763a5475151d Mon Sep 17 00:00:00 2001 From: R Date: Sat, 5 Dec 2026 09:11:25 -0300 Subject: [PATCH 02/22] crypto: backend-concepts STATUS: task 1.1's commits and verification --- .../openspec/changes/backend-concepts/reference/STATUS.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md index 2bfe434..9e864a6 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md +++ b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md @@ -35,5 +35,6 @@ change's head; tasks 1.2 to 4.2 not started. Nothing is pushed: the primitives c ## Verification -- Task 1.1: `backend_concepts_symmetric` (with and without exceptions) and the three headers - compiled alone, green on Clang, GCC 15, wasip2 and Emscripten. +- Task 1.1 (crypto `c0e05f4`, superproject `53ea243`): `backend_concepts_symmetric` (with and + without exceptions) and the three headers compiled alone, green on Clang, GCC 15, wasip2 and + Emscripten; the macOS clang-tidy and the Linux lint clean. MSVC not run yet. From 03caf017a7e566619d06d91c0cba14d953fea4fd Mon Sep 17 00:00:00 2001 From: R Date: Sat, 5 Dec 2026 09:25:48 -0300 Subject: [PATCH 03/22] crypto: backend-concepts: task 1.1's review rulings (no KeySize, box without family, kx names, stand-ins per requirement, R7 load-bearing, 3.2 owns D5's diagnostic) --- .../changes/backend-concepts/design.md | 11 +++++++- .../backend-concepts/reference/STATUS.md | 27 +++++++++++++++++++ .../changes/backend-concepts/tasks.md | 2 +- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/libraries/crypto/openspec/changes/backend-concepts/design.md b/libraries/crypto/openspec/changes/backend-concepts/design.md index 868e697..ba4ad21 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/design.md +++ b/libraries/crypto/openspec/changes/backend-concepts/design.md @@ -53,7 +53,16 @@ merged. What that changes in the context above, ruled while building (`reference - **base64 left crypto**: the codecs library (webcpp::codecs) encodes and decodes base64, and the PEM engine is gone; the encoding area of D4 has no concept, and R4's `base64_engine` is not built. - **The box families are tags without sizes**: both crypto_box families have a 24-byte nonce and a - 16-byte tag, which the `box` concept names as constants. + 16-byte tag, which the `box` concept names as constants; `box` therefore takes no family (D4's + `box` is `box`). +- **The key size is the engine class's, not the concept's**: `block_engine` and + `gcm_engine` are one class per key size and `init` takes a dynamic span the public + type has sized, so D4's `block_cipher` and `gcm` are `block_cipher` + and `gcm`, asserted once per key size. +- **kx and the sealed box keep the engines' names**: D4's `derive_from_seed`, + `client_session_keys`, `server_session_keys` and the three-argument sealed-box `open` are the + engines' `seed_keypair`, `client`, `server` and `open(recipient_public, recipient_secret, sealed, + out)`. - **The formats engines** are `ed25519_formats_engine` and `x25519_formats_engine` on libsodium; P-256's and secp256k1's formats call the curve's engine or library directly. - **HPKE** composes the curves' and webcpp::hash's public types and has no engine of its own. diff --git a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md index 9e864a6..2b57c8c 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md +++ b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md @@ -30,6 +30,30 @@ change's head; tasks 1.2 to 4.2 not started. Nothing is pushed: the primitives c pin one compiler's wording; `backend_concepts_symmetric_test` proves each requirement with a stand-in that lacks it. The plain-words messages are task 3.2's, which name the capability. Cost if wrong: message tests to add in 3.2. +- **1.1-I2: `block_cipher` and `gcm` take no `KeySize`** (D4 wrote `block_cipher`, + `gcm`): `init` takes the key as a dynamic span the public type has sized, so no + expression of the concept could check a key size; the engine is one class per key size and the + tests assert the concept for each (16, 24, 32). Cost if wrong: a `key_size` member on every block + and GCM engine, and the parameter back. +- **1.1-M1: `box` takes no family**: both families share the sizes and their types are tags without + them, so a `Family` parameter would be unchecked. Cost: none. +- **1.1-M2: kx and the sealed box follow the engines' names** (`seed_keypair`, `client`, `server`, + the four-argument `open`), not D4's (`derive_from_seed`, `client_session_keys`, + `server_session_keys`, `open(recipient, sealed, out)`): the concepts are written against the real + engines (D1). Cost if wrong: renaming three engine functions in task 2.1. +- **1.1-I1: every requirement has a negative stand-in**: `test/support/backend_stand_in.hpp` makes a + stand-in a class template over a defect (one operation missing, not noexcept or of another + result; one parameter of another size or type), and `rejects_every_defect` and + `rejects_every_shape` assert the concept refuses each. A by-value counter of a wider integer + converts, so `stream_cipher` checks that the family's `counter_type` converts to the engine's. + Cost: none. +- **1.1-M7: D5's diagnostic is task 3.2's**: tasks.md 3.2 now owns a message test of the + diagnostic naming the concept and the missing operation. +- **1.1-M10: BearSSL's refusing `block_engine` already satisfies `block_cipher`** (its templated + members have explicit return types, and the requires-expression never instantiates the refusal's + body), so task 3.1's specialization marker (R7) is load-bearing, not a convenience; 3.1 adds a + test that `block_engine` carries no marker. The `Engine::state&` without `typename` + in requires parameters needs the MSVC 14.3/14.5 run before delivery. - **No implementer or reviewer subagents in this run**: the stream ran as a fork that may not start subagents, so task 1.1 has no independent review yet. Cost: the review is owed before delivery. @@ -38,3 +62,6 @@ change's head; tasks 1.2 to 4.2 not started. Nothing is pushed: the primitives c - Task 1.1 (crypto `c0e05f4`, superproject `53ea243`): `backend_concepts_symmetric` (with and without exceptions) and the three headers compiled alone, green on Clang, GCC 15, wasip2 and Emscripten; the macOS clang-tidy and the Linux lint clean. MSVC not run yet. +- Task 1.1's review fixes (crypto `1106124`, superproject `0678e27`): `backend_concepts_symmetric` + and `backend_concepts_boxes` (with and without exceptions) green on Clang, GCC 15, wasip2 and + Emscripten; the three headers compiled alone; the macOS clang-tidy clean. diff --git a/libraries/crypto/openspec/changes/backend-concepts/tasks.md b/libraries/crypto/openspec/changes/backend-concepts/tasks.md index 9712d02..a23c42e 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/tasks.md +++ b/libraries/crypto/openspec/changes/backend-concepts/tasks.md @@ -17,7 +17,7 @@ the end of every task. A plan with code goes in `reference/plan.md` when the pro ## 3. The table and the public API - [ ] 3.1 `crypto.json`'s family rows list their capabilities, one cell per capability; `generate.py` writes `supports_capability_v`, `detail::shipped_backends` and the specialization marker's check; `capabilities_test` checks the cells against the concepts both ways on every target and lane; `supports_v` header-free, meaning the use operations (D5, D7, R1, R7, R8) -- [ ] 3.2 Every public member asserts the capability it uses, after the primaries' generated refusals; message tests for each area (D9) +- [ ] 3.2 Every public member asserts the capability it uses, after the primaries' generated refusals; message tests for each area (D9), including D5's diagnostic naming the concept and the operation an engine lacks (owned here by ruling 1.1-M7: task 1.1 proved the requirements with stand-ins, not messages) ## 4. The page and the delivery From 6b5897154ca6432bfd1a0b9f26a1d885076ad3f5 Mon Sep 17 00:00:00 2001 From: R Date: Sat, 5 Dec 2026 09:47:34 -0300 Subject: [PATCH 04/22] crypto: backend-concepts: task 1.2's rulings and verification; task 1.1 re-review minors (3.1 owns the BearSSL marker test, both concept tests named, any integer counter converts) --- .../changes/backend-concepts/design.md | 4 ++ .../backend-concepts/reference/STATUS.md | 45 ++++++++++++++++--- .../changes/backend-concepts/tasks.md | 2 +- 3 files changed, 44 insertions(+), 7 deletions(-) diff --git a/libraries/crypto/openspec/changes/backend-concepts/design.md b/libraries/crypto/openspec/changes/backend-concepts/design.md index ba4ad21..5840b70 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/design.md +++ b/libraries/crypto/openspec/changes/backend-concepts/design.md @@ -63,6 +63,10 @@ merged. What that changes in the context above, ruled while building (`reference `client_session_keys`, `server_session_keys` and the three-argument sealed-box `open` are the engines' `seed_keypair`, `client`, `server` and `open(recipient_public, recipient_secret, sealed, out)`. +- **The key engines take one set of names in task 2.1**: `import_secret`, `generate`, + `public_key` (fallible), `export_secret` (fallible) and `move` on every curve; X25519's engine, + stateless today, becomes state-based so that an opaque X25519 key has a state. P-256's + `p256_point` has no `compress` (the public type's, on bytes it has). - **The formats engines** are `ed25519_formats_engine` and `x25519_formats_engine` on libsodium; P-256's and secp256k1's formats call the curve's engine or library directly. - **HPKE** composes the curves' and webcpp::hash's public types and has no engine of its own. diff --git a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md index 2b57c8c..5c7b796 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md +++ b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md @@ -1,7 +1,7 @@ # webcpp::crypto backend-concepts: where the implementation stands -2026-12-05: task 1.1 built (the symmetric and box concepts and their test), on the primitives -change's head; tasks 1.2 to 4.2 not started. Nothing is pushed: the primitives change merges first. +2026-12-05: tasks 1.1 (reviewed clean) and 1.2 built, on the primitives change's head; tasks +2.1 to 4.2 not started. Nothing is pushed: the primitives change merges first. ## The bases @@ -27,8 +27,8 @@ change's head; tasks 1.2 to 4.2 not started. Nothing is pushed: the primitives c types are tags without sizes. Cost: none. - **Task 1.1's "message tests for a missing operation" are a run test of stand-ins**: a compiler's concept-failure notes differ between Clang, GCC and MSVC versions, so `-verify` on them would - pin one compiler's wording; `backend_concepts_symmetric_test` proves each requirement with a - stand-in that lacks it. The plain-words messages are task 3.2's, which name the capability. + pin one compiler's wording; `backend_concepts_symmetric_test` and `backend_concepts_boxes_test` + prove each requirement with a stand-in that lacks it. The plain-words messages are task 3.2's, which name the capability. Cost if wrong: message tests to add in 3.2. - **1.1-I2: `block_cipher` and `gcm` take no `KeySize`** (D4 wrote `block_cipher`, `gcm`): `init` takes the key as a dynamic span the public type has sized, so no @@ -44,8 +44,9 @@ change's head; tasks 1.2 to 4.2 not started. Nothing is pushed: the primitives c - **1.1-I1: every requirement has a negative stand-in**: `test/support/backend_stand_in.hpp` makes a stand-in a class template over a defect (one operation missing, not noexcept or of another result; one parameter of another size or type), and `rejects_every_defect` and - `rejects_every_shape` assert the concept refuses each. A by-value counter of a wider integer - converts, so `stream_cipher` checks that the family's `counter_type` converts to the engine's. + `rejects_every_shape` assert the concept refuses each. A by-value counter of any integer type + converts, wider or narrower, so `stream_cipher` checks only that the family's `counter_type` + converts to the engine's; the width is the family's, pinned by the public type. Cost: none. - **1.1-M7: D5's diagnostic is task 3.2's**: tasks.md 3.2 now owns a message test of the diagnostic naming the concept and the missing operation. @@ -54,6 +55,34 @@ change's head; tasks 1.2 to 4.2 not started. Nothing is pushed: the primitives c body), so task 3.1's specialization marker (R7) is load-bearing, not a convenience; 3.1 adds a test that `block_engine` carries no marker. The `Engine::state&` without `typename` in requires parameters needs the MSVC 14.3/14.5 run before delivery. +- **1.2: the key concepts live in one header per curve** (`ed25519.hpp`, `x25519.hpp`, + `p256.hpp`) over the shared `keys.hpp` (`key_import`, `key_generate`, `key_public`, + `key_export`), with the same operation names on every curve: `import_secret`, `generate`, + `public_key`, `export_secret`. `public_key` and `export_secret` return `result`: an opaque + key's backend may fail or refuse at run time. Cost: none. +- **1.2: the key engines are reshaped in task 2.1, not now**: P-256's `public_point` and `scalar` + become `public_key` and `export_secret` and it gains `move`; Ed25519's `seed_keypair` and `seed` + become `import_secret` and `export_secret`, its `public_key` returns `result` and it gains + `move`; X25519's stateless `base` and `agree` become a state-based engine (`import_secret`, + `generate`, `public_key`, `export_secret`, `agree(state, peer, out)`), which the opaque key of + D3 needs. Until then the test asserts the shipped engines whose shape already matches + (Ed25519's verifying and Ed25519ph on libsodium; P-256's points, verifying and DER on BearSSL). + Cost if wrong: none, the rename is the plan's 2.1. +- **1.2: a use concept requires a `stateful_engine`** (a key engine has `move` and `reset`), but + Ed25519ph's hashing state, which holds no secret and no handle, needs no `move`. Cost: none. +- **1.2: the asynchronous concepts take the executor and token types as parameters** and constrain + neither noexcept nor the result (both the token's `async_result`), so `asynchronous.hpp` needs no + asio include; the test shows each operation's absence and a wrong executor type are refused; a + real asynchronous engine is asserted in task 2.3's opaque backend. Cost: none. +- **1.2: `entropy_source` is a concept over a type with a static `fill`**; today's source is the + free function `fill_from_system`, which task 2.1 wraps in `detail::system_entropy` and asserts. + Cost: one small struct. +- **1.2: every curve size is a named constant** in its header (`ed25519_signature_size`, + `p256_point_size`, ...); `x25519_key_size` moved from `boxes.hpp` to `x25519.hpp`, which + `boxes.hpp` includes. Cost: none. +- **1.2: `p256_point` has `valid_point` and `decompress`, no `compress`** (D4 listed validate, + compress, decompress): compressing is the parity of y in a prefix byte, which the public type + does on bytes it has, with no backend call. Cost if wrong: one operation to add. - **No implementer or reviewer subagents in this run**: the stream ran as a fork that may not start subagents, so task 1.1 has no independent review yet. Cost: the review is owed before delivery. @@ -65,3 +94,7 @@ change's head; tasks 1.2 to 4.2 not started. Nothing is pushed: the primitives c - Task 1.1's review fixes (crypto `1106124`, superproject `0678e27`): `backend_concepts_symmetric` and `backend_concepts_boxes` (with and without exceptions) green on Clang, GCC 15, wasip2 and Emscripten; the three headers compiled alone; the macOS clang-tidy clean. +- Task 1.2 (crypto `834ed23`, superproject `a869c00`): `backend_concepts_keys` and + `backend_concepts_asynchronous` (with and without exceptions), with the symmetric and boxes tests + and the ten `detail/backend` headers compiled alone, green on Clang, GCC 15, wasip2 and + Emscripten; the macOS clang-tidy clean. diff --git a/libraries/crypto/openspec/changes/backend-concepts/tasks.md b/libraries/crypto/openspec/changes/backend-concepts/tasks.md index a23c42e..54cd833 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/tasks.md +++ b/libraries/crypto/openspec/changes/backend-concepts/tasks.md @@ -16,7 +16,7 @@ the end of every task. A plan with code goes in `reference/plan.md` when the pro ## 3. The table and the public API -- [ ] 3.1 `crypto.json`'s family rows list their capabilities, one cell per capability; `generate.py` writes `supports_capability_v`, `detail::shipped_backends` and the specialization marker's check; `capabilities_test` checks the cells against the concepts both ways on every target and lane; `supports_v` header-free, meaning the use operations (D5, D7, R1, R7, R8) +- [ ] 3.1 `crypto.json`'s family rows list their capabilities, one cell per capability; `generate.py` writes `supports_capability_v`, `detail::shipped_backends` and the specialization marker's check; `capabilities_test` checks the cells against the concepts both ways on every target and lane; `supports_v` header-free, meaning the use operations; a test that BearSSL's refusing `block_engine` carries no specialization marker (ruling 1.1-M10) (D5, D7, R1, R7, R8) - [ ] 3.2 Every public member asserts the capability it uses, after the primaries' generated refusals; message tests for each area (D9), including D5's diagnostic naming the concept and the operation an engine lacks (owned here by ruling 1.1-M7: task 1.1 proved the requirements with stand-ins, not messages) ## 4. The page and the delivery From be48603f75fdc57a84c62ae43604f8c546f5e69f Mon Sep 17 00:00:00 2001 From: R Date: Sat, 5 Dec 2026 12:05:22 -0300 Subject: [PATCH 05/22] crypto/backend-concepts: task 2.1 and its review fixes as built (rulings, verification) --- .../changes/backend-concepts/design.md | 6 ++- .../backend-concepts/reference/STATUS.md | 50 +++++++++++++++++++ .../changes/backend-concepts/tasks.md | 2 +- 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/libraries/crypto/openspec/changes/backend-concepts/design.md b/libraries/crypto/openspec/changes/backend-concepts/design.md index 5840b70..4f175cf 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/design.md +++ b/libraries/crypto/openspec/changes/backend-concepts/design.md @@ -68,7 +68,11 @@ merged. What that changes in the context above, ruled while building (`reference stateless today, becomes state-based so that an opaque X25519 key has a state. P-256's `p256_point` has no `compress` (the public type's, on bytes it has). - **The formats engines** are `ed25519_formats_engine` and `x25519_formats_engine` on libsodium; - P-256's and secp256k1's formats call the curve's engine or library directly. + P-256's and secp256k1's formats call the curve's engine or library directly. Task 2.1 dissolves + the two into `detail::rfc8410`, a fixed prefix and the key, with no backend: PKCS#8 reads the + secret through the key engine's `export_secret`. +- **The sized families move to `detail/families.hpp`**, so that a backend header, which includes + no public header, can assert D5's concepts after each specialization. - **HPKE** composes the curves' and webcpp::hash's public types and has no engine of its own. ## Intent (owner, 2026-11-22) diff --git a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md index 5c7b796..06c2341 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md +++ b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md @@ -83,6 +83,48 @@ - **1.2: `p256_point` has `valid_point` and `decompress`, no `compress`** (D4 listed validate, compress, decompress): compressing is the parity of y in a prefix byte, which the public type does on bytes it has, with no backend call. Cost if wrong: one operation to add. +- **2.1: the formats engines dissolve into `detail::rfc8410`**: RFC 8410's SubjectPublicKeyInfo + and PKCS#8 for Ed25519 and X25519 are a fixed prefix and the 32-byte key, so encoding and + decoding need no backend; the SPKI codecs lose their `Backend` parameter, and PKCS#8's encoding + reads the secret through the key engine's `export_secret`, so a backend that refuses export + refuses PKCS#8 too (D6's export trait). `ed25519_formats_engine` and `x25519_formats_engine` and + their refusals are gone. Cost: none. +- **2.1: X25519's engine is state-based**: `x25519_state` holds the key (libsodium's + `secret_key`), and the key pair calls `import_secret`, `public_key`, `export_secret`, + `agree(state, peer, out)`, `move` and `reset`. `x25519_access::secret_bytes`, which crypto_kx + and crypto_box read, reads `state_.secret_key`: those constructions are libsodium's alone, whose + state holds the bytes. Cost if wrong: kx and box read through `export_secret` instead. +- **2.1: an engine's `move` copies the state, then wipes the source**; a key pair's move + constructor is the engine's `move`, its move assignment `reset` then `move`, and its destructor + `reset`, on every curve. Cost: none. +- **2.1: a crypto_kx key pair on a backend without crypto_kx holds no X25519 key pair**: X25519's + special members now call its engine, whose refusal would follow kx's own (ruling C22 wants the + one message), so the refused key pair holds an empty placeholder. Cost: none. +- **2.1: the shipped backends have no engine `generate`**: a key is still drawn from + `random_device` and imported (`import_secret`), the entropy policy of one source and no backend + generator; a backend's own generation is task 2.3's (R3), for a backend that keeps its keys. + Cost: none. +- **2.1: the sized symmetric families live in `detail/families.hpp`** (ChaCha20-Poly1305 and its + two variants, ChaCha20, Poly1305, both secret boxes), which their public headers include: a + backend header includes none of those, and D5's assertions read the families' sizes. The names + and the public headers are unchanged. Cost: none. +- **2.1: `detail::system_entropy`** wraps `fill_from_system` as an `entropy_source`, asserted in + `detail/entropy.hpp`; `random_device::fill` draws through it. The concept's contract names + `errc::not_supported` beside `entropy_unavailable` (an Emscripten audio worklet has no source). + Cost: none. +- **2.1 review: a public key's RFC 8410 formats are a row of their own, on no backend** + (`ed25519_public_formats`, `x25519_public_formats` in `crypto.json`), beside the key pair's + formats on libsodium; `generate.py` names no default for an operation that runs on no backend, + and `rfc8410_no_backend` links none and round-trips both SPKIs (review M1, M2). Cost: none. +- **2.1 review: `x25519_access::secret_bytes` refuses a backend whose state lacks `secret_key`** + by name (`x25519_state_holds_secret_key`), so a kx or box key pair of another backend stops with + that sentence, not a member-access error (review M3). Cost: none. +- **2.1 review: libsodium's header includes each concept header in the section that asserts it** + (review M4). Cost: none. +- **2.1 lint: the `` max-macro parentheses in `counter_overflows` (primitives' code, + unchanged on main) carry the suppression with its reason, as `random_device` does**, and + `system_entropy`'s Doc Comment names no entropy API (the lint's clock, disk and network rule). + Cost: none. - **No implementer or reviewer subagents in this run**: the stream ran as a fork that may not start subagents, so task 1.1 has no independent review yet. Cost: the review is owed before delivery. @@ -98,3 +140,11 @@ `backend_concepts_asynchronous` (with and without exceptions), with the symmetric and boxes tests and the ten `detail/backend` headers compiled alone, green on Clang, GCC 15, wasip2 and Emscripten; the macOS clang-tidy clean. +- Task 2.1 (crypto `4f35e9d`, `f9123d3`, `669165c`; superproject `5042a34`, `9967677`, + `da064d5`): every crypto test, the four backend headers' D5 assertions and the new + `backend_concepts_keys` assertions on the shipped engines, green on Clang (the whole suite), GCC + 15, wasip2 and Emscripten; the macOS clang-tidy and the Linux lint clean. +- Task 2.1's review fixes (crypto `96ae0bd`, superproject `fcc1b0a`): the whole suite on Clang, + with `keypair_engine_failure` and `rfc8410_no_backend` new and mutation-checked; the generated + table files regenerated and `generate_test.py` passing; the macOS clang-tidy and the Linux lint + clean. diff --git a/libraries/crypto/openspec/changes/backend-concepts/tasks.md b/libraries/crypto/openspec/changes/backend-concepts/tasks.md index 54cd833..6409496 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/tasks.md +++ b/libraries/crypto/openspec/changes/backend-concepts/tasks.md @@ -10,7 +10,7 @@ the end of every task. A plan with code goes in `reference/plan.md` when the pro ## 2. The engines checked -- [ ] 2.1 Every backend header asserts its engines' concepts; the formats engines dissolve into key and encoding capabilities (D5, R4) +- [x] 2.1 Every backend header asserts its engines' concepts; the formats engines dissolve into key and encoding capabilities (D5, R4) - [ ] 2.2 secp256k1's calls behind `secp256k1_engine`, split into its capabilities, each concept asserted; its no-allocation and constant-time tests unchanged (D8, R2) - [ ] 2.3 The test-only opaque backend for P-256 and X25519, synchronous and asynchronous, outside the table; the `async_*` concepts tested on it; `generate()` through a backend's own generation (D3, R3, R6, R9) From 0ddd845470a1646fffc4f30586c10f3e61ed15f7 Mon Sep 17 00:00:00 2001 From: R Date: Sat, 5 Dec 2026 12:21:45 -0300 Subject: [PATCH 06/22] crypto/backend-concepts: task 1.2's review fixes (rulings I1-I3, M1-M9; base64 out of 1.2 and the spec) --- .../changes/backend-concepts/design.md | 21 ++++++ .../backend-concepts/reference/STATUS.md | 66 ++++++++++++++++++- .../backend-concepts/specs/crypto/spec.md | 2 +- .../changes/backend-concepts/tasks.md | 6 +- 4 files changed, 89 insertions(+), 6 deletions(-) diff --git a/libraries/crypto/openspec/changes/backend-concepts/design.md b/libraries/crypto/openspec/changes/backend-concepts/design.md index 4f175cf..746b532 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/design.md +++ b/libraries/crypto/openspec/changes/backend-concepts/design.md @@ -71,6 +71,11 @@ merged. What that changes in the context above, ruled while building (`reference P-256's and secp256k1's formats call the curve's engine or library directly. Task 2.1 dissolves the two into `detail::rfc8410`, a fixed prefix and the key, with no backend: PKCS#8 reads the secret through the key engine's `export_secret`. +- **The key concepts take their review's shape (task 1.2's review)**: P-256 signs and verifies + in a digest form or a message form (WebCrypto's); the asynchronous concepts mirror + `async.hpp`'s calls exactly (const executor, const lvalues, the token forwarded) and are + `async_import_secret` and `async_import_key`, with no `async_export`; `ed25519ph` takes the key + engine as a second parameter. - **The sized families move to `detail/families.hpp`**, so that a backend header, which includes no public header, can assert D5's concepts after each specialization. - **HPKE** composes the curves' and webcpp::hash's public types and has no engine of its own. @@ -249,6 +254,18 @@ It is a test tool, not a shipped backend: outside the table, `supports_v` and th | Entropy | `entropy_source` | `fill(span)` returning `result` (`entropy_unavailable`) | the platform sources of `detail/entropy.hpp` | | Asynchronous | `async_import` (behind `async_from_secret` and `async_from_key`), `async_generate`, `async_seal`, `async_open`, `async_sign`, `async_verify`, `async_agree`, `async_export` | the shapes `async.hpp` documents: executor first, token last, completion signatures as the public functions' | `async_engine` (part B), the stand-in | +> **As built (task 1.2 and its review, `reference/STATUS.md`)**: `ed25519ph` takes +> the key engine whose state `sign` reads; P-256's signing and verifying come in two forms, the +> digest one above (`sign(state, digest, signature)`, BearSSL's) and a message one, +> `p256_ecdsa_message_signing` (`sign_message(state, message, signature)`) and +> `p256_ecdsa_message_verifying` (`verify_message(point, message, signature)`), for a backend that +> hashes inside as WebCrypto does (browser-backend's D3 signs the message); a backend has either or +> both. The asynchronous row is `async_import_secret` (behind `async_from_secret`) and +> `async_import_key` (behind `async_from_key`), `async_generate`, `async_seal`, `async_open`, +> `async_sign`, `async_verify`, `async_agree`, each over the executor and token types, and no +> `async_export` (browser-backend's owner decision 6: a backend that completes by itself keeps its +> keys). There is no `base64` (base64 left crypto), and `p256_point` has no `compress`. + The formats change's per-curve formats engines dissolve into these: a format codec needs a key's `*_public`, `*_import`, `*_export`, `p256_point`, `ecdsa_der` and `base64`, and holds no engine of its own. @@ -287,6 +304,10 @@ none of the synchronous ones; the public synchronous forms keep refusing with th the operation the formats change left to part B; a non-extractable key has none, and the private formats are refused by type. +> **As built (task 1.2's review)**: there is no `async_export`. Browser-backend's owner decision 6 +> keeps every key of a backend that completes by itself non-extractable, so no caller exists; the +> concept comes back with the first backend that exports asynchronously. + ### D7. One source of truth, and the table (a ruling, R1) The concepts are the truth of what a backend implements: a backend implements a capability exactly diff --git a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md index 06c2341..7bd9d74 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md +++ b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md @@ -1,7 +1,8 @@ # webcpp::crypto backend-concepts: where the implementation stands -2026-12-05: tasks 1.1 (reviewed clean) and 1.2 built, on the primitives change's head; tasks -2.1 to 4.2 not started. Nothing is pushed: the primitives change merges first. +2026-12-05: tasks 1.1 (reviewed clean), 1.2 and 2.1 built and their review fixes made, on the +primitives change's head (primitives merged since; origin/main is merged in before delivery); +tasks 2.2 to 4.2 not started. Nothing is pushed. ## The bases @@ -125,6 +126,63 @@ unchanged on main) carry the suppression with its reason, as `random_device` does**, and `system_entropy`'s Doc Comment names no entropy API (the lint's clock, disk and network rule). Cost: none. +- **1.2-I1: the asynchronous concepts mirror `async.hpp`'s calls exactly**: the executor as + `Executor const&`; a key pair, a public key, a signature, a scheme and a policy as const + lvalues; the views as const lvalues of dynamic extent; the AEAD as a mutable lvalue (its + `async_seal` and `async_open` are non-const); the token forwarded; `from_secret`, `from_key` and + `generate` as member templates. `backend_concepts_asynchronous` proves each with a stand-in that + takes it otherwise (another or a mutable executor, a mutable object, an rvalue AEAD, a + fixed-extent view, another token, a non-template member); a mutation back to a by-value + executor fails the test. The header states the contract the concepts cannot (views valid until + the completion, the guard held by the public function, the completion posted, never inline, + errors as `crypto::error`, allocation through the handler's allocator). Cost: none. +- **1.2-I2: P-256 signs and verifies in a digest form or a message form**: browser-backend's D3 + gives its synchronous P-256 engine `sign(state, message, signature)`, WebCrypto hashing the + message with SHA-256, and WebCrypto cannot sign a digest; so beside `p256_ecdsa_signing` and + `p256_ecdsa_verifying` (the digest, BearSSL's form) come `p256_ecdsa_message_signing` + (`sign_message(state, message, signature)`, fallible) and `p256_ecdsa_message_verifying` + (`verify_message(point, message, signature)`, fallible: `invalid_signature` when it does not + verify, another error when the backend fails, which WebCrypto can). A backend has either form or + both; task 3.1's `supports_v` counts P-256 signing and verifying as supported with either; part B + wires the public functions to the message form with its engine. The test proves a WebCrypto-like + engine satisfies the message form and not the digest one, and BearSSL's the reverse. Cost if + wrong: two concepts to drop. +- **1.2-I3: `ed25519ph`** (D4 wrote `ed25519ph`): `sign` and `sign_digest` read + the key's state, which is the Ed25519 key engine's, so the concept names that engine to type the + parameter. Cost: none. +- **1.2-I3: `async_import_secret` and `async_import_key`** (D4 wrote one `async_import` + behind both): a key pair is made from a secret by `from_secret`, a cipher from a key by + `from_key`, two calls of different names, so two concepts, named alike after what they + import. Browser-backend lists `async_import` among the names it assumes and follows a rename + (its text: "this change follows them"); the delivery's note to part B names the two. Cost: none. +- **1.2-I3: no `async_export`**: browser-backend's owner decision 6 makes every key of a backend + that completes by itself non-extractable, and its list of assumed concepts excludes it by name; + `async.hpp` has no caller. The concept comes back with the first backend that exports + asynchronously, its shape then fixed by that caller. Cost if wrong: one concept to add. +- **1.2-M1: `ed25519_to_x25519`'s `x25519_secret` is an export in all but name**: the concept's + doc says the derived secret leaves the backend and is refused wherever `ed25519_export` is; task + 3.1's export trait governs it too. Cost: none. +- **1.2-M2: the amendments' traits are owned by tasks 3.1 and 3.2** (generation and the two-way + check; the order of diagnostics), now named there. Cost: none. +- **1.2-M3: the four key concepts take no curve**: `*_import`, `*_generate` and `*_export` are the + same constraint on every curve over the shared `secret_key_size`, and only `*_public` differs; + `keys.hpp` and each curve header say so, and the family a table cell carries tells the curves + apart (3.1). Cost: none. +- **1.2-M4: `entropy_source`'s contract** (no state, so concurrent calls from any thread; no + allocation; a library source reads its canary first) is in `entropy.hpp`. Cost: none. +- **1.2-M5: `decompress` stays a backend operation, unlike `compress`**: compressing writes the + parity of y into a prefix byte, on bytes the public type has; decompressing is a field square + root mod p, arithmetic a backend that holds keys in hardware may supply and the public type + cannot do without big-number code of its own. Cost if wrong: one operation moved to the public + type, with that arithmetic. +- **1.2-M6: every dynamic view and the parity byte have a wrong-shape stand-in** (Ed25519's + `message_bytes`, Ed25519ph's `piece_bytes`, DER's `der_bytes`, P-256's message views and + `parity_prefix`). Ed25519 has no opaque-key case: D3 asks P-256 and X25519. Cost: none. +- **1.2-M7: every stand-in numbers its operations from `first_op`**, so none reads as `move_op` + or `reset_op`. Cost: none. +- **1.2-M9: MSVC 14.3/14.5 is on the delivery checklist** (`ledger.md`) for the + `requires(Engine::state ...)` parameters without `typename` and `KeyEngine::state const&`. + Cost: none. - **No implementer or reviewer subagents in this run**: the stream ran as a fork that may not start subagents, so task 1.1 has no independent review yet. Cost: the review is owed before delivery. @@ -148,3 +206,7 @@ with `keypair_engine_failure` and `rfc8410_no_backend` new and mutation-checked; the generated table files regenerated and `generate_test.py` passing; the macOS clang-tidy and the Linux lint clean. +- Task 1.2's review fixes (crypto `c083588`, superproject `f4bfddd`): `backend_concepts_keys` and + `backend_concepts_asynchronous` green on Clang, each new requirement mutation-checked (a + by-value executor, a fixed-extent message view); the macOS clang-tidy and the Linux lint clean. + GCC 15, wasip2 and Emscripten run again on the final head (scoped fix round). diff --git a/libraries/crypto/openspec/changes/backend-concepts/specs/crypto/spec.md b/libraries/crypto/openspec/changes/backend-concepts/specs/crypto/spec.md index 6fe36c6..8cb9d7a 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/specs/crypto/spec.md +++ b/libraries/crypto/openspec/changes/backend-concepts/specs/crypto/spec.md @@ -1,7 +1,7 @@ ## ADDED Requirements ### Requirement: Backend capabilities: one concept per capability -`` SHALL declare, in namespace `webcpp::crypto::detail::backend` and including no backend, one concept per capability of the catalogue in `design.md` D4 (block cipher, GCM and its incremental open, each AEAD family, authenticated box, box, sealed box, kx, Ed25519 and X25519 and P-256 split into import, generate, public, use and export, Ed25519ph, P-256's point and DER, secp256k1 split as the other curves are, with its protocol capabilities, constant-time base64, entropy, and the asynchronous operations), each requiring static `noexcept` functions of the engine over its `state`, results of `boost::system::result` or `result` (or `bool` for a predicate on public data), outputs into fixed-size spans, and `move` and `reset` for a state that holds anything. Each concept's documentation MUST state its semantic contract: the public function holds the timing guard and the engine none, the engine allocates nothing through the C++ heap or the program's allocators, engine functions are safe on distinct states concurrently, `reset` wipes secrets and releases handles, the backend's canary is read before its first call. Each backend header MUST `static_assert` every concept its table cells promise, after each specialization. +`` SHALL declare, in namespace `webcpp::crypto::detail::backend` and including no backend, one concept per capability of the catalogue in `design.md` D4 (block cipher, GCM and its incremental open, each AEAD family, authenticated box, box, sealed box, kx, Ed25519 and X25519 and P-256 split into import, generate, public, use and export, Ed25519ph, P-256's point and DER, secp256k1 split as the other curves are, with its protocol capabilities, entropy, and the asynchronous operations), each requiring static `noexcept` functions of the engine over its `state`, results of `boost::system::result` or `result` (or `bool` for a predicate on public data), outputs into fixed-size spans, and `move` and `reset` for a state that holds anything. Each concept's documentation MUST state its semantic contract: the public function holds the timing guard and the engine none, the engine allocates nothing through the C++ heap or the program's allocators, engine functions are safe on distinct states concurrently, `reset` wipes secrets and releases handles, the backend's canary is read before its first call. Each backend header MUST `static_assert` every concept its table cells promise, after each specialization. #### Scenario: Every backend checked - **WHEN** each backend's header is compiled on every target where its library builds diff --git a/libraries/crypto/openspec/changes/backend-concepts/tasks.md b/libraries/crypto/openspec/changes/backend-concepts/tasks.md index 6409496..0268093 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/tasks.md +++ b/libraries/crypto/openspec/changes/backend-concepts/tasks.md @@ -6,7 +6,7 @@ the end of every task. A plan with code goes in `reference/plan.md` when the pro ## 1. The concepts - [ ] 1.1 `detail/backend/*.hpp`: the shared requirements and the symmetric, box and kx concepts, each with its documented contract; message tests for a missing operation (design D1, D2, D4) -- [ ] 1.2 The key concepts of Ed25519, X25519 and P-256 split by import, generate, public, use and export; P-256's point and DER; base64; entropy; the asynchronous operations (D3, D4, D6) +- [x] 1.2 The key concepts of Ed25519, X25519 and P-256 split by import, generate, public, use and export; P-256's point and DER, and its signing in a digest and a message form; entropy; the asynchronous operations (D3, D4, D6). No base64 concept: base64 left crypto for webcpp::codecs (ruling) ## 2. The engines checked @@ -16,8 +16,8 @@ the end of every task. A plan with code goes in `reference/plan.md` when the pro ## 3. The table and the public API -- [ ] 3.1 `crypto.json`'s family rows list their capabilities, one cell per capability; `generate.py` writes `supports_capability_v`, `detail::shipped_backends` and the specialization marker's check; `capabilities_test` checks the cells against the concepts both ways on every target and lane; `supports_v` header-free, meaning the use operations; a test that BearSSL's refusing `block_engine` carries no specialization marker (ruling 1.1-M10) (D5, D7, R1, R7, R8) -- [ ] 3.2 Every public member asserts the capability it uses, after the primaries' generated refusals; message tests for each area (D9), including D5's diagnostic naming the concept and the operation an engine lacks (owned here by ruling 1.1-M7: task 1.1 proved the requirements with stand-ins, not messages) +- [ ] 3.1 `crypto.json`'s family rows list their capabilities, one cell per capability; `generate.py` writes `supports_capability_v`, `detail::shipped_backends` and the specialization marker's check; `capabilities_test` checks the cells against the concepts both ways on every target and lane; `supports_v` header-free, meaning the use operations; a test that BearSSL's refusing `block_engine` carries no specialization marker (ruling 1.1-M10); P-256 signing and verifying supported when the engine has the digest form or the message form (ruling 1.2-I2); D3's and D6's amendment traits `crypto::exports_secret_keys_v`, `crypto::imports_secret_keys_v` and `detail::exports_secret_keys_v` generated and checked both ways against the `*_export` and `*_import` concepts, `ed25519_to_x25519`'s `x25519_secret` counted as an export (ruling 1.2-M1) (D3, D5, D6, D7, R1, R7, R8) +- [ ] 3.2 Every public member asserts the capability it uses, after the primaries' generated refusals; message tests for each area (D9), including D5's diagnostic naming the concept and the operation an engine lacks (owned here by ruling 1.1-M7: task 1.1 proved the requirements with stand-ins, not messages); the export and import traits' refusals (D3's and D6's amendments) speak before D9's capability assertions, and a message test shows that order (ruling 1.2-M2) ## 4. The page and the delivery From fd60bd4b3a5e1b5e4f635a56d0336ee4788b32bc Mon Sep 17 00:00:00 2001 From: R Date: Sat, 5 Dec 2026 13:00:57 -0300 Subject: [PATCH 07/22] crypto/backend-concepts: task 1.2's second review fixes (N1-N5) and task 2.1's re-review minors as built --- .../changes/backend-concepts/design.md | 26 ++++++++++-------- .../changes/backend-concepts/proposal.md | 2 +- .../backend-concepts/reference/STATUS.md | 27 +++++++++++++++---- .../changes/backend-concepts/tasks.md | 4 +-- 4 files changed, 40 insertions(+), 19 deletions(-) diff --git a/libraries/crypto/openspec/changes/backend-concepts/design.md b/libraries/crypto/openspec/changes/backend-concepts/design.md index 746b532..f34c6b0 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/design.md +++ b/libraries/crypto/openspec/changes/backend-concepts/design.md @@ -248,13 +248,13 @@ It is a test tool, not a shipped backend: outside the table, `supports_v` and th | Ed25519 | `ed25519_import`, `ed25519_generate`, `ed25519_public`, `ed25519_signing`, `ed25519_verifying`, `ed25519_export`, `ed25519_to_x25519` | per D3 | `ed25519_engine` on libsodium | | | `ed25519ph` | `begin`, `update`, `sign`, `verify` | `ed25519ph_engine` on libsodium | | X25519 | `x25519_import`, `x25519_generate`, `x25519_public`, `x25519_agreement`, `x25519_export` | per D3; `agree` refuses an all-zero result | `x25519_engine` on libsodium | -| P-256 | `p256_import`, `p256_generate`, `p256_public`, `p256_point` (validate, compress, decompress), `p256_ecdsa_signing`, `p256_ecdsa_verifying`, `p256_ecdh`, `p256_export`, `ecdsa_der` | per D3 | `p_curve_engine` on BearSSL (and OpenSSL where the table has it) | +| P-256 | `p256_import`, `p256_generate`, `p256_public`, `p256_point` (validate, decompress), `p256_ecdsa_signing` and `p256_ecdsa_verifying` (over a digest), `p256_ecdsa_message_signing` and `p256_ecdsa_message_verifying` (over a message, hashed inside), `p256_ecdh`, `p256_export`, `ecdsa_der` | per D3 | `p_curve_engine` on BearSSL (and OpenSSL where the table has it) | | secp256k1 | `secp256k1_import`, `secp256k1_generate`, `secp256k1_public`, `secp256k1_export`, `secp256k1_ecdsa_signing`, `secp256k1_ecdsa_verifying`, `secp256k1_schnorr_signing`, `secp256k1_schnorr_verifying`, `secp256k1_recoverable` (sign and recover), `secp256k1_ecdh`, `secp256k1_tweak`, `secp256k1_ellswift`, `secp256k1_musig`, `secp256k1_silent_payments` | per D3 for the keys; one per protocol for the rest | `secp256k1_engine` (D8) | -| Encoding | `base64` | constant-time `encode` and `decode`, standard with padding and URL-safe without, into fixed spans | `pem_engine` on libsodium (renamed `base64_engine`) | | Entropy | `entropy_source` | `fill(span)` returning `result` (`entropy_unavailable`) | the platform sources of `detail/entropy.hpp` | -| Asynchronous | `async_import` (behind `async_from_secret` and `async_from_key`), `async_generate`, `async_seal`, `async_open`, `async_sign`, `async_verify`, `async_agree`, `async_export` | the shapes `async.hpp` documents: executor first, token last, completion signatures as the public functions' | `async_engine` (part B), the stand-in | +| Asynchronous | `async_import_secret` (behind `async_from_secret`), `async_import_key` (behind `async_from_key`), `async_generate`, `async_seal`, `async_open`, `async_sign`, `async_verify`, `async_agree`, each over the executor and token types | the shapes `async.hpp` documents: executor first, token last, completion signatures as the public functions' | `async_engine` (part B), the stand-in | -> **As built (task 1.2 and its review, `reference/STATUS.md`)**: `ed25519ph` takes +> **As built (task 1.2 and its review, `reference/STATUS.md`)**; the rows above are corrected in +> place, and this note keeps what the approved text said: `ed25519ph` takes > the key engine whose state `sign` reads; P-256's signing and verifying come in two forms, the > digest one above (`sign(state, digest, signature)`, BearSSL's) and a message one, > `p256_ecdsa_message_signing` (`sign_message(state, message, signature)`) and @@ -264,10 +264,12 @@ It is a test tool, not a shipped backend: outside the table, `supports_v` and th > `async_import_key` (behind `async_from_key`), `async_generate`, `async_seal`, `async_open`, > `async_sign`, `async_verify`, `async_agree`, each over the executor and token types, and no > `async_export` (browser-backend's owner decision 6: a backend that completes by itself keeps its -> keys). There is no `base64` (base64 left crypto), and `p256_point` has no `compress`. +> keys). There is no `base64` (base64 left crypto), and `p256_point` has no `compress`. The approved +> rows read `p256_point` (validate, compress, decompress), an Encoding row `base64` on the PEM +> engine, and an Asynchronous row of `async_import` behind both imports and `async_export`. The formats change's per-curve formats engines dissolve into these: a format codec needs a key's -`*_public`, `*_import`, `*_export`, `p256_point`, `ecdsa_der` and `base64`, and holds no engine of +`*_public`, `*_import`, `*_export`, `p256_point` and `ecdsa_der` (base64 is webcpp::codecs'), and holds no engine of its own. ### D5. Every engine is checked @@ -296,15 +298,17 @@ failed). > public synchronous forms refuse only where the engine lacks the synchronous capability. Whether a > backend lets secret key bytes leave it is the trait `detail::exports_secret_keys_v` > (browser-backend's D16, owner decision of 2026-11-30), checked against the `*_export` concepts. -> The paragraph below is the text as approved. +> The paragraph below is the text as approved, corrected in place by task 1.2's review (the note +> after it keeps the approved sentence). A backend that completes by itself (`asynchronous_backend_v`) implements the `async_*` concepts and none of the synchronous ones; the public synchronous forms keep refusing with the name of their -`async_` form (crypto/sign-unified's D9). Export of an extractable opaque key is `async_export`, -the operation the formats change left to part B; a non-extractable key has none, and the private -formats are refused by type. +`async_` form (crypto/sign-unified's D9). Such a backend keeps every key non-extractable: there is +no asynchronous export, and the private formats are refused by type. -> **As built (task 1.2's review)**: there is no `async_export`. Browser-backend's owner decision 6 +> **As built (task 1.2's review)**: there is no `async_export` (the paragraph above is corrected in +> place; the approved text said: "Export of an extractable opaque key is `async_export`, the +> operation the formats change left to part B; a non-extractable key has none"). Browser-backend's owner decision 6 > keeps every key of a backend that completes by itself non-extractable, so no caller exists; the > concept comes back with the first backend that exports asynchronously. diff --git a/libraries/crypto/openspec/changes/backend-concepts/proposal.md b/libraries/crypto/openspec/changes/backend-concepts/proposal.md index 696cd54..9a72bb7 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/proposal.md +++ b/libraries/crypto/openspec/changes/backend-concepts/proposal.md @@ -26,7 +26,7 @@ crypto's public types and the backends it ships. crypto_box), the sealed box, crypto_kx, Ed25519 (import, generate, sign, verify, export, to X25519), Ed25519ph, X25519 (import, generate, agree, export), P-256 (import, generate, public point, ECDSA sign and verify, ECDH, export, DER), secp256k1 (import, generate, public, export, ECDSA, - Schnorr, recoverable, ECDH, tweaks, ElligatorSwift, MuSig2, silent payments), constant-time base64, the + Schnorr, recoverable, ECDH, tweaks, ElligatorSwift, MuSig2, silent payments), the entropy source, and the asynchronous engine's operations. Each names its operations, their results (`result`, `result` or `bool` for a public predicate, outputs into fixed spans), `noexcept`, and states the semantic contract the compiler cannot check: who holds the timing diff --git a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md index 7bd9d74..fdbdac0 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md +++ b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md @@ -1,8 +1,8 @@ # webcpp::crypto backend-concepts: where the implementation stands -2026-12-05: tasks 1.1 (reviewed clean), 1.2 and 2.1 built and their review fixes made, on the -primitives change's head (primitives merged since; origin/main is merged in before delivery); -tasks 2.2 to 4.2 not started. Nothing is pushed. +2026-12-05: tasks 1.1 and 2.1 built and reviewed clean, 1.2 built and its two review rounds' fixes +made, on the primitives change's head (primitives merged since; origin/main is merged in before +delivery); task 2.2 in progress, 2.3 to 4.2 not started. Nothing is pushed. ## The bases @@ -143,8 +143,15 @@ tasks 2.2 to 4.2 not started. Nothing is pushed. (`sign_message(state, message, signature)`, fallible) and `p256_ecdsa_message_verifying` (`verify_message(point, message, signature)`, fallible: `invalid_signature` when it does not verify, another error when the backend fails, which WebCrypto can). A backend has either form or - both; task 3.1's `supports_v` counts P-256 signing and verifying as supported with either; part B - wires the public functions to the message form with its engine. The test proves a WebCrypto-like + both. Task 3.1's cells name the form an engine has; `supports_v` counts signing and verifying a + message as supported with either form, and a prehashed digest only with the digest form, which + 3.2's assertion for a prehashed input checks, so that a message-only backend (WebCrypto) refuses + it by name (1.2-fix review N1). Part B wires the public functions to the message form with its + engine; the delivery's note to part B names `p256_ecdsa_message_signing` and + `p256_ecdsa_message_verifying` and their functions `sign_message` and `verify_message`, which its + browser engine takes in place of `sign` and `verify` (N2). The forms differ by name on purpose: a + 32-byte digest view converts to a view of any length, so a test shows an engine whose `sign` takes + any length satisfies the digest concepts and never the message ones (N4). The test proves a WebCrypto-like engine satisfies the message form and not the digest one, and BearSSL's the reverse. Cost if wrong: two concepts to drop. - **1.2-I3: `ed25519ph`** (D4 wrote `ed25519ph`): `sign` and `sign_digest` read @@ -159,6 +166,10 @@ tasks 2.2 to 4.2 not started. Nothing is pushed. that completes by itself non-extractable, and its list of assumed concepts excludes it by name; `async.hpp` has no caller. The concept comes back with the first backend that exports asynchronously, its shape then fixed by that caller. Cost if wrong: one concept to add. +- **1.2-fix review: the catalogue is corrected in place** (D4's P-256, Encoding and Asynchronous + rows, the formats paragraph, D6's paragraph on export, the proposal's list), the As-built notes + keeping the approved wording; `async.hpp` states the reason for no asynchronous export itself, not + another change's decision number (N3, N5). Cost: none. - **1.2-M1: `ed25519_to_x25519`'s `x25519_secret` is an export in all but name**: the concept's doc says the derived secret leaves the backend and is refused wherever `ed25519_export` is; task 3.1's export trait governs it too. Cost: none. @@ -210,3 +221,9 @@ tasks 2.2 to 4.2 not started. Nothing is pushed. `backend_concepts_asynchronous` green on Clang, each new requirement mutation-checked (a by-value executor, a fixed-extent message view); the macOS clang-tidy and the Linux lint clean. GCC 15, wasip2 and Emscripten run again on the final head (scoped fix round). +- Task 2.1's re-review minors (crypto `8823fbb`, `98ab701`; superproject `cee8f8b`, `b6aafc9`): + the x25519 mock tests and `keypair_engine_failure` green on Clang; the macOS clang-tidy and the + Linux lint clean. +- Task 1.2's second review fixes (crypto `b84dd2f`, superproject `b6aafc9`): + `backend_concepts_keys` and `backend_concepts_asynchronous` green on Clang; the macOS clang-tidy + and the Linux lint clean. diff --git a/libraries/crypto/openspec/changes/backend-concepts/tasks.md b/libraries/crypto/openspec/changes/backend-concepts/tasks.md index 0268093..8b79e25 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/tasks.md +++ b/libraries/crypto/openspec/changes/backend-concepts/tasks.md @@ -16,8 +16,8 @@ the end of every task. A plan with code goes in `reference/plan.md` when the pro ## 3. The table and the public API -- [ ] 3.1 `crypto.json`'s family rows list their capabilities, one cell per capability; `generate.py` writes `supports_capability_v`, `detail::shipped_backends` and the specialization marker's check; `capabilities_test` checks the cells against the concepts both ways on every target and lane; `supports_v` header-free, meaning the use operations; a test that BearSSL's refusing `block_engine` carries no specialization marker (ruling 1.1-M10); P-256 signing and verifying supported when the engine has the digest form or the message form (ruling 1.2-I2); D3's and D6's amendment traits `crypto::exports_secret_keys_v`, `crypto::imports_secret_keys_v` and `detail::exports_secret_keys_v` generated and checked both ways against the `*_export` and `*_import` concepts, `ed25519_to_x25519`'s `x25519_secret` counted as an export (ruling 1.2-M1) (D3, D5, D6, D7, R1, R7, R8) -- [ ] 3.2 Every public member asserts the capability it uses, after the primaries' generated refusals; message tests for each area (D9), including D5's diagnostic naming the concept and the operation an engine lacks (owned here by ruling 1.1-M7: task 1.1 proved the requirements with stand-ins, not messages); the export and import traits' refusals (D3's and D6's amendments) speak before D9's capability assertions, and a message test shows that order (ruling 1.2-M2) +- [ ] 3.1 `crypto.json`'s family rows list their capabilities, one cell per capability; `generate.py` writes `supports_capability_v`, `detail::shipped_backends` and the specialization marker's check; `capabilities_test` checks the cells against the concepts both ways on every target and lane; `supports_v` header-free, meaning the use operations; a test that BearSSL's refusing `block_engine` carries no specialization marker (ruling 1.1-M10); P-256's cells name the form the engine has (`p256_ecdsa_signing`/`p256_ecdsa_verifying`, the digest form, or `p256_ecdsa_message_signing`/`p256_ecdsa_message_verifying`, the message form), `supports_v` for signing and verifying a message is the OR of the two forms, and for a prehashed digest needs the digest form itself (ruling 1.2-I2); D3's and D6's amendment traits `crypto::exports_secret_keys_v`, `crypto::imports_secret_keys_v` and `detail::exports_secret_keys_v` generated and checked both ways against the `*_export` and `*_import` concepts, `ed25519_to_x25519`'s `x25519_secret` counted as an export (ruling 1.2-M1) (D3, D5, D6, D7, R1, R7, R8) +- [ ] 3.2 Every public member asserts the capability it uses, after the primaries' generated refusals; message tests for each area (D9), including D5's diagnostic naming the concept and the operation an engine lacks (owned here by ruling 1.1-M7: task 1.1 proved the requirements with stand-ins, not messages); the export and import traits' refusals (D3's and D6's amendments) speak before D9's capability assertions, and a message test shows that order (ruling 1.2-M2); P-256's sign and verify of a prehashed input assert the digest form, so that a message-only backend refuses it by name (ruling 1.2-I2) ## 4. The page and the delivery From a3646e130577ffe4bcaebf032af43735a036d106 Mon Sep 17 00:00:00 2001 From: R Date: Sat, 5 Dec 2026 13:41:12 -0300 Subject: [PATCH 08/22] crypto/backend-concepts: task 2.2 as built (secp256k1 behind engines: rulings, verification) --- .../changes/backend-concepts/design.md | 8 +++++ .../backend-concepts/reference/STATUS.md | 34 ++++++++++++++++++- .../changes/backend-concepts/tasks.md | 2 +- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/libraries/crypto/openspec/changes/backend-concepts/design.md b/libraries/crypto/openspec/changes/backend-concepts/design.md index f34c6b0..d116dee 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/design.md +++ b/libraries/crypto/openspec/changes/backend-concepts/design.md @@ -351,6 +351,14 @@ MuSig2, silent payments), in `backends/secp256k1.hpp`, so that the curve uses th curve uses and is split as they are (owner decision 3). The static context, the self test, the canary and the no-allocation verification stay as they are; the memory option's workspace for MuSig2 and silent payments is part of those concepts. +> **As built (task 2.2, `reference/STATUS.md`)**: one specialization per tag of +> `detail::backend::secp256k1_capabilities`, the key pair's four capabilities one `key` engine, with +> two engines more than the list above, `point` (parsing, serializing and comparing points and +> x-only keys) and ECDSA's signature forms in the `ecdsa` engine (`secp256k1_ecdsa_forms`). The +> curve's headers reach them through `secp256k1_engine_of`, fixed to +> `backends::secp256k1`. The key pair keeps allocating the context's storage from its memory +> resource; the engine creates the context in it (`context_size`, `start`). + ### D9. The public API's constraints Each public type checks, in the member that needs it, the capability it uses: `basic_keypair::from_secret` diff --git a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md index fdbdac0..e8014b3 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md +++ b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md @@ -2,7 +2,7 @@ 2026-12-05: tasks 1.1 and 2.1 built and reviewed clean, 1.2 built and its two review rounds' fixes made, on the primitives change's head (primitives merged since; origin/main is merged in before -delivery); task 2.2 in progress, 2.3 to 4.2 not started. Nothing is pushed. +delivery); 2.2 built; 2.3 to 4.2 not started. Nothing is pushed. ## The bases @@ -126,6 +126,33 @@ delivery); task 2.2 in progress, 2.3 to 4.2 not started. Nothing is pushed. unchanged on main) carry the suppression with its reason, as `random_device` does**, and `system_entropy`'s Doc Comment names no entropy API (the lint's clock, disk and network rule). Cost: none. +- **2.2: one specialization per tag of `detail::backend::secp256k1_capabilities`** (key, point, + ecdsa, schnorr, recoverable, ecdh, tweak, ellswift, musig, silent_payments), the curve's headers + reaching them through `secp256k1_engine_of`, fixed to `backends::secp256k1`: the curve + has one backend, so its public types take no backend parameter (D8 moves the calls, not the API). + D8's import, generate, public and export are one `key` engine, as every other curve's key engine + is. Cost if wrong: a backend parameter on the curve's types when a second backend comes. +- **2.2: the engines name their native types** (`key_state`, `point`, `xonly_point`, MuSig2's + caches, nonces, sessions and signatures, silent payments' recipients, summaries and found + outputs), and the public layer holds them: the opaque classes keep their layout, the curve's + headers reach libsecp256k1 only through `backends/secp256k1.hpp` and call none of its functions. The backend header + asserts every engine reads the `key` engine's state and holds the `point` engine's types. Cost: + none. +- **2.2: the context's storage stays in the public layer**: `secp256k1_import` requires + `context_size`, `valid_secret` and `start(state, storage, seed)`, the key pair allocating + `context_size()` bytes from its memory resource and the engine creating the context in them, so + that the memory option and the no-allocation test are unchanged and no engine allocates (D8). The + engine's `reset` wipes and destroys, the key pair returns the storage. Cost: none. +- **2.2: the use engines read a `key_state const&`**, the key pair's context and keypair together; + only the tweak engine's `key_xonly_add` writes one. Cost: none. +- **2.2: concepts beyond D4's list**: `secp256k1_point` (parse, serialize, compare, x-only), and + `secp256k1_ecdsa_forms` (compact validity, low S, DER), which the formats header and the verifier + policies need; `secp256k1_import`'s context functions. Cost if wrong: two concepts to fold. +- **2.2: pointer arrays are spans of the C API's pointer type**: silent payments' outputs and + found outputs are `span`, as libsecp256k1 takes `T**`; the rest are `span`. + Cost: none. +- **2.2: `recover` returns the key of any S**: refusing a high S is the caller's, as + libsecp256k1's own recovery leaves it; the public function still refuses one first. Cost: none. - **1.2-I1: the asynchronous concepts mirror `async.hpp`'s calls exactly**: the executor as `Executor const&`; a key pair, a public key, a signature, a scheme and a policy as const lvalues; the views as const lvalues of dynamic extent; the AEAD as a mutable lvalue (its @@ -227,3 +254,8 @@ delivery); task 2.2 in progress, 2.3 to 4.2 not started. Nothing is pushed. - Task 1.2's second review fixes (crypto `b84dd2f`, superproject `b6aafc9`): `backend_concepts_keys` and `backend_concepts_asynchronous` green on Clang; the macOS clang-tidy and the Linux lint clean. +- Task 2.2 (crypto `2eba99c`, superproject `b2de91d`): every crypto test on Clang, GCC 15, wasip2 + and Emscripten, with `backend_concepts_secp256k1` new (every capability's concepts asserted on + libsecp256k1's engines, and on stand-ins that fail them with any one operation or shape wrong), + the concept header compiled alone, and the no-allocation, constant-time and wipe tests unchanged + and green; the macOS clang-tidy and the Linux lint clean. diff --git a/libraries/crypto/openspec/changes/backend-concepts/tasks.md b/libraries/crypto/openspec/changes/backend-concepts/tasks.md index 8b79e25..af5ff16 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/tasks.md +++ b/libraries/crypto/openspec/changes/backend-concepts/tasks.md @@ -11,7 +11,7 @@ the end of every task. A plan with code goes in `reference/plan.md` when the pro ## 2. The engines checked - [x] 2.1 Every backend header asserts its engines' concepts; the formats engines dissolve into key and encoding capabilities (D5, R4) -- [ ] 2.2 secp256k1's calls behind `secp256k1_engine`, split into its capabilities, each concept asserted; its no-allocation and constant-time tests unchanged (D8, R2) +- [x] 2.2 secp256k1's calls behind `secp256k1_engine`, split into its capabilities, each concept asserted; its no-allocation and constant-time tests unchanged (D8, R2) - [ ] 2.3 The test-only opaque backend for P-256 and X25519, synchronous and asynchronous, outside the table; the `async_*` concepts tested on it; `generate()` through a backend's own generation (D3, R3, R6, R9) ## 3. The table and the public API From fc1aa03b3d320eb9d90e1e370348a87a5e211330 Mon Sep 17 00:00:00 2001 From: R Date: Sat, 5 Dec 2026 14:29:43 -0300 Subject: [PATCH 09/22] crypto: backend-concepts task 2.3 as built, task 2.2's review minors, R4 without base64_engine, origin/main merged before 3.1 --- .../changes/backend-concepts/design.md | 10 ++++- .../backend-concepts/reference/STATUS.md | 37 ++++++++++++++++--- .../changes/backend-concepts/tasks.md | 6 +-- 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/libraries/crypto/openspec/changes/backend-concepts/design.md b/libraries/crypto/openspec/changes/backend-concepts/design.md index d116dee..ee3bef6 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/design.md +++ b/libraries/crypto/openspec/changes/backend-concepts/design.md @@ -231,6 +231,12 @@ shape is proven before part B exists; it has a synchronous form and an asynchron It is a test tool, not a shipped backend: outside the table, `supports_v` and the two-way check (R6). Part B's browser backend is the first real consumer of both shapes. +> **As built (task 2.3, `reference/STATUS.md`)**: `test/backends/opaque.hpp`, backends `opaque` +> and `opaque_async` of `webcpp::test::opaque_backend`, whose table holds BearSSL's P-256 and +> libsodium's X25519 states; `generate()` on Ed25519, X25519 and P-256 calls the engine's +> `generate` when it has one. The asynchronous engine reaches a key pair's work through +> `detail::async_access` (`generated`, `agreed`, `signed_digest`). + ### D4. The catalogue | Area | Concept (`detail::backend::`) | Operations | Engines checked | @@ -397,8 +403,8 @@ The public factories are named by their input (uniform-types' owner decision 9: - **R2 (owner decision 3): secp256k1 moves behind engines, split into capabilities** (D8). - **R3 (owner decision 4): `generate()` uses the engine's `*_generate` when the backend has one**, mandatory for opaque keys; else `random_device` and `*_import`. -- **R4: the formats engines dissolve** (D4) into key and encoding capabilities; the PEM family's - engine becomes `base64_engine` under the family `families::pem`, which keeps its table row. +- **R4: the formats engines dissolve** (D4) into key capabilities; the PEM family's engine is gone + with base64, which left crypto for webcpp::codecs, so no `base64_engine` is built. - **R5: the concepts' headers live in `detail/backend/`**, not `detail/capabilities/`, which would sit beside the generated `detail/capabilities.hpp` and read as its part. - **R6 (coordinator): the test-only opaque backend lives outside the table and the two-way check**; diff --git a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md index e8014b3..d9e3a12 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md +++ b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md @@ -1,16 +1,16 @@ # webcpp::crypto backend-concepts: where the implementation stands -2026-12-05: tasks 1.1 and 2.1 built and reviewed clean, 1.2 built and its two review rounds' fixes -made, on the primitives change's head (primitives merged since; origin/main is merged in before -delivery); 2.2 built; 2.3 to 4.2 not started. Nothing is pushed. +2026-12-05: tasks 1.1, 1.2, 2.1 and 2.2 built and reviewed clean, on the primitives change's head; +2.3 built; `origin/main` (primitives merged) merged into the three branches before 3.1, the full +lanes green on the merged head; 3.1 to 4.2 not started. Nothing is pushed. ## The bases | Repository | Branch | Base | | --- | --- | --- | -| webcpporg/crypto | `crypto/backend-concepts` | `c638dbf` (primitives, `crypto/primitives`) | -| webcpporg/webcpp | `backend-concepts` | `34ea790` (primitives' superproject) | -| webcpporg/proposals | `crypto/backend-concepts` | `origin/main`, with this change's text from `629bfb3` (the device-backends planning branch, the newest) | +| webcpporg/crypto | `crypto/backend-concepts` | `c638dbf` (primitives, `crypto/primitives`); `origin/main` merged at `96c2f82` | +| webcpporg/webcpp | `backend-concepts` | `34ea790` (primitives' superproject); `origin/main` merged at `ec4af9b` | +| webcpporg/proposals | `crypto/backend-concepts` | `origin/main`, with this change's text from `629bfb3` (the device-backends planning branch, the newest); `origin/main` merged at `91cfe2a` | ## Rulings made while building @@ -153,6 +153,25 @@ delivery); 2.2 built; 2.3 to 4.2 not started. Nothing is pushed. Cost: none. - **2.2: `recover` returns the key of any S**: refusing a high S is the caller's, as libsecp256k1's own recovery leaves it; the public function still refuses one first. Cost: none. +- **2.2 review: the secp256k1 engines check what libsecp256k1 would misread** (M2): ECDSA's + `sign` refuses extra entropy of a size other than 0 or 32 (`backend_failure`), `from_der` an + empty view, as `recover` refuses an id above 3; the public functions refuse all three first, so + no public behaviour changes. The scan runs the self test again (M3). Cost: none. +- **2.3: `generate()` asks the engine first on every curve with a generate concept** (Ed25519, + X25519, P-256): a private `generated()` calls the engine's `generate` when it satisfies + `*_generate`, else draws from `random_device` and imports, as before (R3). The shipped backends + have no `generate`, so their path is unchanged. secp256k1 has one backend and no generate: R3 + is not wired there. Cost if wrong: one branch on secp256k1 when a backend draws its keys. +- **2.3: the asynchronous engine reaches a key pair's work through `detail::async_access`**, + already every key pair's friend: `generated()`, `agreed(key_pair, peer)` and P-256's + `signed_digest(key_pair, digest)`, each the synchronous member's work without its guard and its + refusal on a backend that completes by itself (P-256's and X25519's `agree` now call a private + `agreed`). Part B's engine needs the same doors. Cost if wrong: the doors change with part B. +- **2.3: the opaque backend's keys are BearSSL's and libsodium's states in its table**, so that + its signatures and agreements are checked against the shipped backends; it draws the key + itself. The handle is a slot index; the table has eight slots per curve and is not thread-safe + (one test drives it). Its asynchronous form runs the same engines and posts through + `complete_by_post`. Cost: none. - **1.2-I1: the asynchronous concepts mirror `async.hpp`'s calls exactly**: the executor as `Executor const&`; a key pair, a public key, a signature, a scheme and a policy as const lvalues; the views as const lvalues of dynamic extent; the AEAD as a mutable lvalue (its @@ -259,3 +278,9 @@ delivery); 2.2 built; 2.3 to 4.2 not started. Nothing is pushed. libsecp256k1's engines, and on stand-ins that fail them with any one operation or shape wrong), the concept header compiled alone, and the no-allocation, constant-time and wipe tests unchanged and green; the macOS clang-tidy and the Linux lint clean. +- Task 2.3 (crypto `9e896b2`, superproject `a0e0666`): every crypto test on Clang, GCC 15, wasip2 + and Emscripten, with `opaque_backend` new (with and without exceptions); the macOS clang-tidy and + the Linux lint clean. +- Task 2.2's review minors (crypto `d2482e5`, superproject `c37a20f`): every crypto test on Clang, + `backend_concepts_secp256k1` on GCC 15 too, its new run-time guards mutation-checked (the entropy + size and the recovery id); the macOS clang-tidy and the Linux lint clean. diff --git a/libraries/crypto/openspec/changes/backend-concepts/tasks.md b/libraries/crypto/openspec/changes/backend-concepts/tasks.md index af5ff16..ba8ca97 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/tasks.md +++ b/libraries/crypto/openspec/changes/backend-concepts/tasks.md @@ -5,19 +5,19 @@ the end of every task. A plan with code goes in `reference/plan.md` when the pro ## 1. The concepts -- [ ] 1.1 `detail/backend/*.hpp`: the shared requirements and the symmetric, box and kx concepts, each with its documented contract; message tests for a missing operation (design D1, D2, D4) +- [x] 1.1 `detail/backend/*.hpp`: the shared requirements and the symmetric, box and kx concepts, each with its documented contract; message tests for a missing operation (design D1, D2, D4) - [x] 1.2 The key concepts of Ed25519, X25519 and P-256 split by import, generate, public, use and export; P-256's point and DER, and its signing in a digest and a message form; entropy; the asynchronous operations (D3, D4, D6). No base64 concept: base64 left crypto for webcpp::codecs (ruling) ## 2. The engines checked - [x] 2.1 Every backend header asserts its engines' concepts; the formats engines dissolve into key and encoding capabilities (D5, R4) - [x] 2.2 secp256k1's calls behind `secp256k1_engine`, split into its capabilities, each concept asserted; its no-allocation and constant-time tests unchanged (D8, R2) -- [ ] 2.3 The test-only opaque backend for P-256 and X25519, synchronous and asynchronous, outside the table; the `async_*` concepts tested on it; `generate()` through a backend's own generation (D3, R3, R6, R9) +- [x] 2.3 The test-only opaque backend for P-256 and X25519, synchronous and asynchronous, outside the table; the `async_*` concepts tested on it; `generate()` through a backend's own generation (D3, R3, R6, R9) ## 3. The table and the public API - [ ] 3.1 `crypto.json`'s family rows list their capabilities, one cell per capability; `generate.py` writes `supports_capability_v`, `detail::shipped_backends` and the specialization marker's check; `capabilities_test` checks the cells against the concepts both ways on every target and lane; `supports_v` header-free, meaning the use operations; a test that BearSSL's refusing `block_engine` carries no specialization marker (ruling 1.1-M10); P-256's cells name the form the engine has (`p256_ecdsa_signing`/`p256_ecdsa_verifying`, the digest form, or `p256_ecdsa_message_signing`/`p256_ecdsa_message_verifying`, the message form), `supports_v` for signing and verifying a message is the OR of the two forms, and for a prehashed digest needs the digest form itself (ruling 1.2-I2); D3's and D6's amendment traits `crypto::exports_secret_keys_v`, `crypto::imports_secret_keys_v` and `detail::exports_secret_keys_v` generated and checked both ways against the `*_export` and `*_import` concepts, `ed25519_to_x25519`'s `x25519_secret` counted as an export (ruling 1.2-M1) (D3, D5, D6, D7, R1, R7, R8) -- [ ] 3.2 Every public member asserts the capability it uses, after the primaries' generated refusals; message tests for each area (D9), including D5's diagnostic naming the concept and the operation an engine lacks (owned here by ruling 1.1-M7: task 1.1 proved the requirements with stand-ins, not messages); the export and import traits' refusals (D3's and D6's amendments) speak before D9's capability assertions, and a message test shows that order (ruling 1.2-M2); P-256's sign and verify of a prehashed input assert the digest form, so that a message-only backend refuses it by name (ruling 1.2-I2) +- [ ] 3.2 Every public member asserts the capability it uses, after the primaries' generated refusals; message tests for each area (D9), including D5's diagnostic naming the concept and the operation an engine lacks (owned here by ruling 1.1-M7: task 1.1 proved the requirements with stand-ins, not messages); the export and import traits' refusals (D3's and D6's amendments) speak before D9's capability assertions, and a message test shows that order (ruling 1.2-M2); P-256's sign and verify of a prehashed input assert the digest form, so that a message-only backend refuses it by name (ruling 1.2-I2); secp256k1, whose `secp256k1_engine` has no primary template, shows the same order: a backend other than `backends::secp256k1` is refused by the curve's `secp256k1_refuses_others` before any engine is named, by a message test (review 2.2 M5) ## 4. The page and the delivery From ba1b71c93ab6ef01a36112460f2e8e05ce482378 Mon Sep 17 00:00:00 2001 From: R Date: Sat, 5 Dec 2026 14:32:44 -0300 Subject: [PATCH 10/22] crypto: backend-concepts task 3.1 built: capability cells, the marker as a variable template, the secret-key traits --- .../changes/backend-concepts/design.md | 13 +++++ .../backend-concepts/reference/STATUS.md | 47 ++++++++++++++++++- .../changes/backend-concepts/tasks.md | 2 +- 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/libraries/crypto/openspec/changes/backend-concepts/design.md b/libraries/crypto/openspec/changes/backend-concepts/design.md index ee3bef6..8decbdf 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/design.md +++ b/libraries/crypto/openspec/changes/backend-concepts/design.md @@ -295,6 +295,14 @@ list nor in the table (R6). A missing operation is a diagnostic naming the conce operation (each concept is a conjunction of named sub-requirements, so compilers print which one failed). +> **As built (task 3.1, `reference/STATUS.md`)**: the marker is a variable template beside each +> specialisation, `detail::specialized_engine_v`, not a member, since reading a member +> would instantiate a refusing primary; a family row lists its capabilities (`"capabilities"`, +> each with its kind, concept and engines) and a backend's cell those its engines have; +> `capabilities_test` folds over `detail::shipped_backends` and checks each capability's engines, +> counted only where marked, against its cell, and the secret-key traits against the export and +> import engines. + ### D6. Asynchronous and opaque together > **Amended on 2026-11-30 by browser-backend** (owner decision of 2026-11-23): a backend that @@ -348,6 +356,11 @@ when its engine satisfies the concept. The table stays, as the header-free decla program asks `supports_capability_v` before it calls `secret()`. Both stay header-free and both are checked against the concepts. +> **As built (task 3.1)**: the capability tags are `crypto::capabilities::`, and a capability +> is of a kind, `use` among them, which `supports_v` counts; P-256's digest and message forms each +> count for signing and verifying. `exports_secret_keys_v` and `imports_secret_keys_v` are public +> in `` beside `supports_capability_v`, generated into `detail`. + ### D8. secp256k1 behind an engine The curve's headers call libsecp256k1 directly today. Their calls move, unchanged, behind diff --git a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md index d9e3a12..8912df9 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md +++ b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md @@ -2,7 +2,7 @@ 2026-12-05: tasks 1.1, 1.2, 2.1 and 2.2 built and reviewed clean, on the primitives change's head; 2.3 built; `origin/main` (primitives merged) merged into the three branches before 3.1, the full -lanes green on the merged head; 3.1 to 4.2 not started. Nothing is pushed. +lanes green on the merged head; 3.1 built; 3.2 to 4.2 not started. Nothing is pushed. ## The bases @@ -172,6 +172,51 @@ lanes green on the merged head; 3.1 to 4.2 not started. Nothing is pushed. itself. The handle is a slot index; the table has eight slots per curve and is not thread-safe (one test drives it). Its asynchronous form runs the same engines and posts through `complete_by_post`. Cost: none. +- **3.1: the specialisation marker is a variable template beside the engine**, + `detail::specialized_engine_v`, not D5's member `is_specialization`: the reverse check + asks it of every capability's engine on every shipped backend, a family's refusing primary + among them, and reading a member instantiates the class, whose body is the refusal, which would + stop the check's own build. The variable template's specialisations never instantiate the + engine. Each backend header states its markers after its D5 assertions; BearSSL's refusing + `block_engine` has none, and a mutation that gives it one fails `capabilities_test` (its + templated members meet `block_cipher`, ruling 1.1-M10). Cost: none. +- **3.1: one tag per capability, in `crypto::capabilities`**: the key capabilities keep the + catalogue's names (`p256_export`, `ed25519_to_x25519`, ...), P-256's DER is `p256_ecdsa_der` + (the concept `ecdsa_der`), and a family whose one capability is a concept other families share + (`aead`, `authenticated_box`, `box`, `block_cipher`, `stream_cipher`, `authenticator`) names its + tag after itself (`capabilities::chacha20_poly1305`, `capabilities::aes_block`), so that + `supports_capability_v` answers one family's cell. Cost: none. +- **3.1: a capability's kind decides what `supports_v` counts** (R8): `import`, `generate`, + `public`, `export` (Ed25519's `ed25519_to_x25519` among them, ruling 1.2-M1), `use`, which + `supports_v` counts, and `auxiliary`, operations on public values the types need that are no + algorithm's use: P-256's `p256_point` and `p256_ecdsa_der`, secp256k1's `point`, its ECDSA + signature forms and its tweaks. secp256k1's uses are ECDSA and Schnorr signing and verifying, + recoverable signatures and ECDH; ElligatorSwift, MuSig2 and silent payments are families of + their own, each its one use. The generator refuses a cell that lacks a use of one of its + family's algorithms; P-256's digest and message forms stand for each other (`either`), so either + counts (ruling 1.2-I2). A capability of several engines (GCM's and the block cipher's three key + sizes) is present exactly where all of them meet it. Cost if wrong: a kind changed in + `crypto.json`. +- **3.1: the secret-key traits are generated into `detail` and read by `crypto::`** in + `supports.hpp`, the header of `supports_v` (device-backends' D1 names ``, + which crypto does not have; that change moves them if it keeps the name), from a backend row's + `exports_secret_keys` and `imports_secret_keys`, true unless the row says false; a type that is + no backend of the table, the test-only opaque backend among them, has both false. The generator + refuses a row whose cells contradict its traits, and one that imports nothing and does not + generate a family's keys (device-backends' D1 check, taken here). `capabilities_test` checks + them against the engines: a backend whose trait is false has no engine meeting an export (or + import) concept; one whose trait is true has a family's exports wherever it has its import, and + its import wherever it has its public key. Cost: none. +- **3.1: the two-way check is a fold over `detail::shipped_backends`** (a `backend_list` of the + five tags): one class per backend whose assertions compare, on a backend the target links, each + capability's count of engines that are marked and meet the concept with its cell. A dropped cell + (BearSSL's `p256_export`) and a marker on a refusal (BearSSL's `block_engine`) each fail it, by + mutation. The cells the engines gave: BearSSL's P-256 without `p256_generate` and the message + forms, libsodium's Ed25519 and X25519 and libsecp256k1's keys without `*_generate`. + `supports_header_free` asks `supports_v`, `supports_capability_v` and the traits with no backend + header and no library. Cost: none. +- **3.1: `llms.txt` was stale after task 2.3** (its `generate()` comments): regenerated in a commit + of its own; every task now runs `generate.py --check` with its lanes. Cost: none. - **1.2-I1: the asynchronous concepts mirror `async.hpp`'s calls exactly**: the executor as `Executor const&`; a key pair, a public key, a signature, a scheme and a policy as const lvalues; the views as const lvalues of dynamic extent; the AEAD as a mutable lvalue (its diff --git a/libraries/crypto/openspec/changes/backend-concepts/tasks.md b/libraries/crypto/openspec/changes/backend-concepts/tasks.md index ba8ca97..85232f5 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/tasks.md +++ b/libraries/crypto/openspec/changes/backend-concepts/tasks.md @@ -16,7 +16,7 @@ the end of every task. A plan with code goes in `reference/plan.md` when the pro ## 3. The table and the public API -- [ ] 3.1 `crypto.json`'s family rows list their capabilities, one cell per capability; `generate.py` writes `supports_capability_v`, `detail::shipped_backends` and the specialization marker's check; `capabilities_test` checks the cells against the concepts both ways on every target and lane; `supports_v` header-free, meaning the use operations; a test that BearSSL's refusing `block_engine` carries no specialization marker (ruling 1.1-M10); P-256's cells name the form the engine has (`p256_ecdsa_signing`/`p256_ecdsa_verifying`, the digest form, or `p256_ecdsa_message_signing`/`p256_ecdsa_message_verifying`, the message form), `supports_v` for signing and verifying a message is the OR of the two forms, and for a prehashed digest needs the digest form itself (ruling 1.2-I2); D3's and D6's amendment traits `crypto::exports_secret_keys_v`, `crypto::imports_secret_keys_v` and `detail::exports_secret_keys_v` generated and checked both ways against the `*_export` and `*_import` concepts, `ed25519_to_x25519`'s `x25519_secret` counted as an export (ruling 1.2-M1) (D3, D5, D6, D7, R1, R7, R8) +- [x] 3.1 `crypto.json`'s family rows list their capabilities, one cell per capability; `generate.py` writes `supports_capability_v`, `detail::shipped_backends` and the specialization marker's check; `capabilities_test` checks the cells against the concepts both ways on every target and lane; `supports_v` header-free, meaning the use operations; a test that BearSSL's refusing `block_engine` carries no specialization marker (ruling 1.1-M10); P-256's cells name the form the engine has (`p256_ecdsa_signing`/`p256_ecdsa_verifying`, the digest form, or `p256_ecdsa_message_signing`/`p256_ecdsa_message_verifying`, the message form), `supports_v` for signing and verifying a message is the OR of the two forms, and for a prehashed digest needs the digest form itself (ruling 1.2-I2); D3's and D6's amendment traits `crypto::exports_secret_keys_v`, `crypto::imports_secret_keys_v` and `detail::exports_secret_keys_v` generated and checked both ways against the `*_export` and `*_import` concepts, `ed25519_to_x25519`'s `x25519_secret` counted as an export (ruling 1.2-M1) (D3, D5, D6, D7, R1, R7, R8) - [ ] 3.2 Every public member asserts the capability it uses, after the primaries' generated refusals; message tests for each area (D9), including D5's diagnostic naming the concept and the operation an engine lacks (owned here by ruling 1.1-M7: task 1.1 proved the requirements with stand-ins, not messages); the export and import traits' refusals (D3's and D6's amendments) speak before D9's capability assertions, and a message test shows that order (ruling 1.2-M2); P-256's sign and verify of a prehashed input assert the digest form, so that a message-only backend refuses it by name (ruling 1.2-I2); secp256k1, whose `secp256k1_engine` has no primary template, shows the same order: a backend other than `backends::secp256k1` is refused by the curve's `secp256k1_refuses_others` before any engine is named, by a message test (review 2.2 M5) ## 4. The page and the delivery From 5fbbe61608329d46f3606475481b81fa2dd2d42a Mon Sep 17 00:00:00 2001 From: R Date: Sat, 5 Dec 2026 14:50:13 -0300 Subject: [PATCH 11/22] crypto: backend-concepts task 2.3's review I2: task 3.2 names the opaque backend's refusals and their message tests --- libraries/crypto/openspec/changes/backend-concepts/tasks.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/crypto/openspec/changes/backend-concepts/tasks.md b/libraries/crypto/openspec/changes/backend-concepts/tasks.md index 85232f5..e036752 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/tasks.md +++ b/libraries/crypto/openspec/changes/backend-concepts/tasks.md @@ -17,7 +17,7 @@ the end of every task. A plan with code goes in `reference/plan.md` when the pro ## 3. The table and the public API - [x] 3.1 `crypto.json`'s family rows list their capabilities, one cell per capability; `generate.py` writes `supports_capability_v`, `detail::shipped_backends` and the specialization marker's check; `capabilities_test` checks the cells against the concepts both ways on every target and lane; `supports_v` header-free, meaning the use operations; a test that BearSSL's refusing `block_engine` carries no specialization marker (ruling 1.1-M10); P-256's cells name the form the engine has (`p256_ecdsa_signing`/`p256_ecdsa_verifying`, the digest form, or `p256_ecdsa_message_signing`/`p256_ecdsa_message_verifying`, the message form), `supports_v` for signing and verifying a message is the OR of the two forms, and for a prehashed digest needs the digest form itself (ruling 1.2-I2); D3's and D6's amendment traits `crypto::exports_secret_keys_v`, `crypto::imports_secret_keys_v` and `detail::exports_secret_keys_v` generated and checked both ways against the `*_export` and `*_import` concepts, `ed25519_to_x25519`'s `x25519_secret` counted as an export (ruling 1.2-M1) (D3, D5, D6, D7, R1, R7, R8) -- [ ] 3.2 Every public member asserts the capability it uses, after the primaries' generated refusals; message tests for each area (D9), including D5's diagnostic naming the concept and the operation an engine lacks (owned here by ruling 1.1-M7: task 1.1 proved the requirements with stand-ins, not messages); the export and import traits' refusals (D3's and D6's amendments) speak before D9's capability assertions, and a message test shows that order (ruling 1.2-M2); P-256's sign and verify of a prehashed input assert the digest form, so that a message-only backend refuses it by name (ruling 1.2-I2); secp256k1, whose `secp256k1_engine` has no primary template, shows the same order: a backend other than `backends::secp256k1` is refused by the curve's `secp256k1_refuses_others` before any engine is named, by a message test (review 2.2 M5) +- [ ] 3.2 Every public member asserts the capability it uses, after the primaries' generated refusals; message tests for each area (D9), including D5's diagnostic naming the concept and the operation an engine lacks (owned here by ruling 1.1-M7: task 1.1 proved the requirements with stand-ins, not messages); the export and import traits' refusals (D3's and D6's amendments) speak before D9's capability assertions, and a message test shows that order (ruling 1.2-M2); P-256's sign and verify of a prehashed input assert the digest form, so that a message-only backend refuses it by name (ruling 1.2-I2); secp256k1, whose `secp256k1_engine` has no primary template, shows the same order: a backend other than `backends::secp256k1` is refused by the curve's `secp256k1_refuses_others` before any engine is named, by a message test (review 2.2 M5); the test-only opaque backend's public-type refusals are named refusals with message tests (review 2.3 I2): `from_secret`, `secret()`, `pkcs8` and `raw` on `basic_keypair`, and `async_from_secret` on the asynchronous opaque backend, each reusing `test/backends/opaque.hpp` ## 4. The page and the delivery From d0ad2fbf3cad26a693b6286c612b3c2082fd0056 Mon Sep 17 00:00:00 2001 From: R Date: Sat, 5 Dec 2026 14:58:55 -0300 Subject: [PATCH 12/22] crypto: backend-concepts task 3.1's review folded: program-facing capability texts, one form per cell, entropy and async_* deferred, generate_test's unlisted cases, 4.1 names the new traits (M6) --- .../backend-concepts/reference/STATUS.md | 18 ++++++++++++++++++ .../openspec/changes/backend-concepts/tasks.md | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md index 8912df9..daedf40 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md +++ b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md @@ -215,6 +215,24 @@ lanes green on the merged head; 3.1 built; 3.2 to 4.2 not started. Nothing is pu forms, libsodium's Ed25519 and X25519 and libsecp256k1's keys without `*_generate`. `supports_header_free` asks `supports_v`, `supports_capability_v` and the traits with no backend header and no library. Cost: none. +- **3.1 review: a public tag's comment speaks a program's terms** (review 3.1 I1, D10): each + capability carries a `text` in `crypto.json` (`p256_export`: "`secret()`, `pkcs8` and the + private PEM of a P-256 key pair"), which its tag's comment says; the concept it names is the + generated test's alone, and the generator refuses a capability without a text or one naming + `detail::`. Cost: none. +- **3.1 review: a cell has its uses in one form** (review 3.1 M1): a capability that may stand for + another (`either`) names its `form` (P-256's `digest`, `message`), partners two forms; the + generator refuses a cell in which no one form has every use (signing a digest and verifying a + message alone), which `supports_v` would otherwise count. Cost: none. +- **3.1 review: entropy and the asynchronous concepts have no tag yet** (review 3.1 M3): the + capabilities are those of the shipped backends; `entropy_source` and `async_*` get their tags and + cells with the first backend of the table that has them, part B's browser backend; the test-only + opaque backend is outside the table (R6). `crypto.json`'s comment says the same. Cost: none. +- **3.1 review: generate_test's capability cases did not run** (found folding review 3.1): task + 3.1's six cases were defined and not listed in `CASES`; they are listed, and generate_test now + refuses a case it defines and does not list. `supports_header_free` asks a public type, + `ciphers::aes256_gcm`, and generate.py checks that its guards name every tag of `backends` + (review 3.1 M5). Cost: none. - **3.1: `llms.txt` was stale after task 2.3** (its `generate()` comments): regenerated in a commit of its own; every task now runs `generate.py --check` with its lanes. Cost: none. - **1.2-I1: the asynchronous concepts mirror `async.hpp`'s calls exactly**: the executor as diff --git a/libraries/crypto/openspec/changes/backend-concepts/tasks.md b/libraries/crypto/openspec/changes/backend-concepts/tasks.md index e036752..0db0674 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/tasks.md +++ b/libraries/crypto/openspec/changes/backend-concepts/tasks.md @@ -21,5 +21,5 @@ the end of every task. A plan with code goes in `reference/plan.md` when the pro ## 4. The page and the delivery -- [ ] 4.1 The guide's chapter on backends: the catalogue, the contract, the opaque key as a program sees it, no public backend API (D10); `crypto.json`'s generated files; the changelog line +- [ ] 4.1 The guide's chapter on backends: the catalogue, the contract, the opaque key as a program sees it, no public backend API (D10); `crypto.json`'s generated files; the changelog line; the chapter names `supports_capability_v`, `exports_secret_keys_v` and `imports_secret_keys_v`, what a partial cell means (`supports_v` counts the use operations alone), and P-256's digest and message forms, and `doc/backends.adoc` and `doc/choosing_backend.adoc` stop saying `supports_v` "has the algorithm" (review 3.1 M6) - [ ] 4.2 Full local verification on every lane, pull requests, merge, one CI at the end From 306fab0afc0b5395b3702fd52c6722d2d3c1f7c7 Mon Sep 17 00:00:00 2001 From: R Date: Sat, 5 Dec 2026 15:45:55 -0300 Subject: [PATCH 13/22] crypto backend-concepts: task 3.2 done, its rulings in STATUS --- .../backend-concepts/reference/STATUS.md | 57 +++++++++++++++++++ .../changes/backend-concepts/tasks.md | 2 +- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md index daedf40..767660f 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md +++ b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md @@ -235,6 +235,63 @@ lanes green on the merged head; 3.1 built; 3.2 to 4.2 not started. Nothing is pu (review 3.1 M5). Cost: none. - **3.1: `llms.txt` was stale after task 2.3** (its `generate()` comments): regenerated in a commit of its own; every task now runs `generate.py --check` with its lanes. Cost: none. +- **3.2: an assertion speaks only to a marked engine**: each member asserts its capability under + `if constexpr (detail::specialized_engine_v)`, and calls the engine in an `if constexpr` + branch that `detail::capability_usable_v` opens, so a refused member adds no error of its own. A + family's primary engine is unmarked: its generated refusal speaks, as D9 orders. A test's + unmarked stand-in is taken at its word, as task 3.1's two-way check takes it. No class-scope + constant asks a concept: it would instantiate a refusing primary wherever the class is named + (`supports_v` among them). Cost: none. +- **3.2: the capability is asserted alone, not inside `||`**: clang explains a failed concept (its + notes name the concept and the operation the engine lacks, D5's diagnostic) only for a bare + concept-id; under `!marked || concept` it prints the expression and stops. Hence the + `if constexpr` guard above, and one `if constexpr` per family in the helpers of the families + that share an engine template (`aead_capability_checked`, `secretbox_capability_checked`, + `box_capability_checked`). Cost: none. +- **3.2: a message says "this backend"**: a `static_assert` message is a literal in C++20 and + cannot name its template argument; the compiler's instantiation notes name the backend and the + member. A curve names the capability in the message (`p256_point`, `ed25519_export`); a family + with one capability names it as the family's (`chacha20`, `gcm`). Cost: none. +- **3.2: the symmetric families and the boxes ask one helper per family** + (`gcm_capability_checked`, `stream_capability_checked`, `poly1305_capability_checked`, ..., + beside each family's primary engine), from every public member that calls the engine: + `from_key`, `seal`, `open`, the incremental members of GCM, `encrypt` and `decrypt` of AES's + block, `apply_keystream`, Poly1305's `compute`, `from_keys`, crypto_kx's `derive_from_seed` and + `session`. Moves and the destructor call `move` and `reset`, which every capability requires + (`stateful_engine`), and assert nothing. Cost: none. +- **3.2: the secret-key traits are asked first, each by its own message, then the capability** + (D3's and D6's amendments, 1.2-M2): `detail::secret_keys_enter_v` and + `detail::secret_keys_leave_v` (`detail/secret_keys.hpp`) read the backend's + `imports_secret_keys_v` and `exports_secret_keys_v` for a marked engine and are true otherwise; + the capability's assertion is conditioned on the trait holding, so one message speaks. An + Ed25519 key pair's `to_x25519()` asks the export trait (1.2-M1); `generate()` without a + backend's own generation asks the import trait and `*_import` ("neither *_generate nor + *_import"); `async_from_secret` on a backend that completes by itself asks the import trait + before its engine's `async_import_secret`. Message tests `opaque_keys_kept` and + `opaque_async_from_secret` show the order: the trait's errors alone. Cost: none. +- **3.2: a key pair's private formats are refused for a kept key first** (D3's amendment, the + formats change's D7): `*_private_formats_v` is false where a marked engine's secret neither + enters nor leaves the backend, and the new `refusal_reason::private_kept` names the two traits; + it speaks before `private_on_asynchronous`, WebCrypto's reason, on a backend that is both (the + opaque backend's asynchronous form). One reason covers both directions, as the formats' reasons + do: a backend that takes keys and gives none, or the reverse, has no private format, since + encoding and decoding are one pair. Cost if wrong: two reasons, one per direction. +- **3.2: P-256's sign and verify assert the digest form for a message and a digest alike** + (1.2-I2): a message is hashed and signed as a digest today, so a message-only backend refuses + both, and the message names both; the message form's wiring (`sign_message`, + `verify_message`) is part B's, with its first backend. Message test + `p256_prehashed_message_only`, on the test-only `test/backends/message_only.hpp`. Cost: none. +- **3.2: secp256k1's members assert no capability**: its one backend is libsecp256k1, every other + refused by `secp256k1_refuses_others` before any engine is named (`secp256k1_engine` has no + primary), and the backend header's D5 assertions prove every capability its cell promises; + message test `secp256k1_other_backend_first` shows the refusal alone (review 2.2 M5). Cost if + wrong: a second secp256k1 backend adds the members' assertions. +- **3.2: one message test per area of the capability tests** (keys, symmetric, boxes, + asynchronous, secp256k1): `p256_operation_named` (D5's diagnostic: the assertion, the concept + and the missing `decompress` as notes, ruling 1.1-M7), `chacha20_capability_missing`, + `secretbox_capability_missing`, `opaque_async_from_secret`, `secp256k1_other_backend_first`; + with `opaque_keys_kept` and `p256_prehashed_message_only`. Each runs `alone`, with an MSVC twin + and a fix in `crypto.json`. The fix texts name no test-only backend. Cost: none. - **1.2-I1: the asynchronous concepts mirror `async.hpp`'s calls exactly**: the executor as `Executor const&`; a key pair, a public key, a signature, a scheme and a policy as const lvalues; the views as const lvalues of dynamic extent; the AEAD as a mutable lvalue (its diff --git a/libraries/crypto/openspec/changes/backend-concepts/tasks.md b/libraries/crypto/openspec/changes/backend-concepts/tasks.md index 0db0674..c2ed56c 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/tasks.md +++ b/libraries/crypto/openspec/changes/backend-concepts/tasks.md @@ -17,7 +17,7 @@ the end of every task. A plan with code goes in `reference/plan.md` when the pro ## 3. The table and the public API - [x] 3.1 `crypto.json`'s family rows list their capabilities, one cell per capability; `generate.py` writes `supports_capability_v`, `detail::shipped_backends` and the specialization marker's check; `capabilities_test` checks the cells against the concepts both ways on every target and lane; `supports_v` header-free, meaning the use operations; a test that BearSSL's refusing `block_engine` carries no specialization marker (ruling 1.1-M10); P-256's cells name the form the engine has (`p256_ecdsa_signing`/`p256_ecdsa_verifying`, the digest form, or `p256_ecdsa_message_signing`/`p256_ecdsa_message_verifying`, the message form), `supports_v` for signing and verifying a message is the OR of the two forms, and for a prehashed digest needs the digest form itself (ruling 1.2-I2); D3's and D6's amendment traits `crypto::exports_secret_keys_v`, `crypto::imports_secret_keys_v` and `detail::exports_secret_keys_v` generated and checked both ways against the `*_export` and `*_import` concepts, `ed25519_to_x25519`'s `x25519_secret` counted as an export (ruling 1.2-M1) (D3, D5, D6, D7, R1, R7, R8) -- [ ] 3.2 Every public member asserts the capability it uses, after the primaries' generated refusals; message tests for each area (D9), including D5's diagnostic naming the concept and the operation an engine lacks (owned here by ruling 1.1-M7: task 1.1 proved the requirements with stand-ins, not messages); the export and import traits' refusals (D3's and D6's amendments) speak before D9's capability assertions, and a message test shows that order (ruling 1.2-M2); P-256's sign and verify of a prehashed input assert the digest form, so that a message-only backend refuses it by name (ruling 1.2-I2); secp256k1, whose `secp256k1_engine` has no primary template, shows the same order: a backend other than `backends::secp256k1` is refused by the curve's `secp256k1_refuses_others` before any engine is named, by a message test (review 2.2 M5); the test-only opaque backend's public-type refusals are named refusals with message tests (review 2.3 I2): `from_secret`, `secret()`, `pkcs8` and `raw` on `basic_keypair`, and `async_from_secret` on the asynchronous opaque backend, each reusing `test/backends/opaque.hpp` +- [x] 3.2 Every public member asserts the capability it uses, after the primaries' generated refusals; message tests for each area (D9), including D5's diagnostic naming the concept and the operation an engine lacks (owned here by ruling 1.1-M7: task 1.1 proved the requirements with stand-ins, not messages); the export and import traits' refusals (D3's and D6's amendments) speak before D9's capability assertions, and a message test shows that order (ruling 1.2-M2); P-256's sign and verify of a prehashed input assert the digest form, so that a message-only backend refuses it by name (ruling 1.2-I2); secp256k1, whose `secp256k1_engine` has no primary template, shows the same order: a backend other than `backends::secp256k1` is refused by the curve's `secp256k1_refuses_others` before any engine is named, by a message test (review 2.2 M5); the test-only opaque backend's public-type refusals are named refusals with message tests (review 2.3 I2): `from_secret`, `secret()`, `pkcs8` and `raw` on `basic_keypair`, and `async_from_secret` on the asynchronous opaque backend, each reusing `test/backends/opaque.hpp` ## 4. The page and the delivery From bda8f04cbcf980036d67d13d284c3346aaeb2731 Mon Sep 17 00:00:00 2001 From: R Date: Sat, 5 Dec 2026 16:14:56 -0300 Subject: [PATCH 14/22] crypto backend-concepts: the 3.2 review's fixes, their rulings in STATUS --- .../backend-concepts/reference/STATUS.md | 58 ++++++++++++++----- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md index 767660f..b0da2e0 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md +++ b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md @@ -2,7 +2,8 @@ 2026-12-05: tasks 1.1, 1.2, 2.1 and 2.2 built and reviewed clean, on the primitives change's head; 2.3 built; `origin/main` (primitives merged) merged into the three branches before 3.1, the full -lanes green on the merged head; 3.1 built; 3.2 to 4.2 not started. Nothing is pushed. +lanes green on the merged head; 3.1 built; 3.2 built and its review's fixes folded; 4.1 and 4.2 not +started. Nothing is pushed. ## The bases @@ -250,8 +251,9 @@ lanes green on the merged head; 3.1 built; 3.2 to 4.2 not started. Nothing is pu `box_capability_checked`). Cost: none. - **3.2: a message says "this backend"**: a `static_assert` message is a literal in C++20 and cannot name its template argument; the compiler's instantiation notes name the backend and the - member. A curve names the capability in the message (`p256_point`, `ed25519_export`); a family - with one capability names it as the family's (`chacha20`, `gcm`). Cost: none. + member. Every message names a capability by its public tag, `crypto::capabilities::p256_point`, + `crypto::capabilities::chacha20`, curves and families alike, and a secret-key trait as + `crypto::imports_secret_keys_v` (review 3.2 M6). Cost: none. - **3.2: the symmetric families and the boxes ask one helper per family** (`gcm_capability_checked`, `stream_capability_checked`, `poly1305_capability_checked`, ..., beside each family's primary engine), from every public member that calls the engine: @@ -271,16 +273,38 @@ lanes green on the merged head; 3.1 built; 3.2 to 4.2 not started. Nothing is pu `opaque_async_from_secret` show the order: the trait's errors alone. Cost: none. - **3.2: a key pair's private formats are refused for a kept key first** (D3's amendment, the formats change's D7): `*_private_formats_v` is false where a marked engine's secret neither - enters nor leaves the backend, and the new `refusal_reason::private_kept` names the two traits; - it speaks before `private_on_asynchronous`, WebCrypto's reason, on a backend that is both (the - opaque backend's asynchronous form). One reason covers both directions, as the formats' reasons - do: a backend that takes keys and gives none, or the reverse, has no private format, since - encoding and decoding are one pair. Cost if wrong: two reasons, one per direction. -- **3.2: P-256's sign and verify assert the digest form for a message and a digest alike** - (1.2-I2): a message is hashed and signed as a digest today, so a message-only backend refuses - both, and the message names both; the message form's wiring (`sign_message`, - `verify_message`) is part B's, with its first backend. Message test - `p256_prehashed_message_only`, on the test-only `test/backends/message_only.hpp`. Cost: none. + enters nor leaves the backend, and the new `refusal_reason::private_kept_raw` (`raw`) and + `private_kept_pkcs8` (`pkcs8` and `pem(pkcs8)`) name the two traits, each format with a sentence + a test can tell apart (review 3.2 M1); they speak before `private_on_asynchronous`, WebCrypto's + reason, on a backend that is both (the opaque backend's asynchronous form). One reason covers both + directions, as the formats' reasons do: a backend that takes keys and gives none, or the reverse, + has no private format, since encoding and decoding are one pair. Cost if wrong: one reason per + direction. +- **3.2: P-256's sign and verify of a message take the engine's message form when it has one** + (1.2-I2, review 3.2 I1, the coordinator's ruling): `sign_message` and `verify_message` when the + engine has `p256_ecdsa_message_signing` or `_verifying`, else the message's SHA-256 on the digest + form; the signature is made low S either way, and the policy is checked before either. A + prehashed digest asserts the digest form alone; an engine with neither form, for a message, gets + one message that names both. So `sign` and `verify` agree with `supports_v`, which counts a + message signed on either form. `detail::p256_signing_checked` and + `p256_verifying_checked` ask it once per engine and kind of input. Run test + `p256_message_form` signs and verifies a message on the test-only + `test/backends/message_only.hpp` (the message reaches the engine whole, the S comes back low, a + high S is refused before the engine); message test `p256_prehashed_message_only` shows the + prehashed refusal, once though crypto's function and the member each ask it. Cost: none. +- **3.2: a refusal is said once per engine, whatever the call shape** (review 3.2 M2): the + verifications and the DER codec ask a helper per engine, as the families do + (`p256_verifying_checked`, `ed25519_verifying_checked`, `ed25519ph_verifying_checked`, + `p256_der_checked`), not an assertion inside a function template over the policy and the input. + Cost: none. +- **3.2: the asynchronous members assert their engine's `async_*` concept** (review 3.2 M4): on a + backend that completes by itself, `async_from_key`, `async_generate`, `async_sign`, + `async_verify` (P-256's and Ed25519's), GCM's `async_seal` and `async_open` and the two + `async_agree` each assert `async_import_key`, `async_generate`, `async_sign`, `async_verify`, + `async_seal`, `async_open` or `async_agree`, by a message that names it, and call the engine only + in the branch it opens; the other branch, never compiled into a program, completes through + `detail::refused_by_engine` with the operation's own result, so the assertion is the build's only + error. Every asynchronous backend specialises `async_engine`, so no mark is asked. Cost: none. - **3.2: secp256k1's members assert no capability**: its one backend is libsecp256k1, every other refused by `secp256k1_refuses_others` before any engine is named (`secp256k1_engine` has no primary), and the backend header's D5 assertions prove every capability its cell promises; @@ -291,7 +315,9 @@ lanes green on the merged head; 3.1 built; 3.2 to 4.2 not started. Nothing is pu and the missing `decompress` as notes, ruling 1.1-M7), `chacha20_capability_missing`, `secretbox_capability_missing`, `opaque_async_from_secret`, `secp256k1_other_backend_first`; with `opaque_keys_kept` and `p256_prehashed_message_only`. Each runs `alone`, with an MSVC twin - and a fix in `crypto.json`. The fix texts name no test-only backend. Cost: none. + and a fix in `crypto.json`. The fix texts name no test-only backend, and speak in the program's + terms: a capability the table promises and the engine lacks is "a defect of the backend, not of + the program: report it" (review 3.2 M5). Cost: none. - **1.2-I1: the asynchronous concepts mirror `async.hpp`'s calls exactly**: the executor as `Executor const&`; a key pair, a public key, a signature, a scheme and a policy as const lvalues; the views as const lvalues of dynamic extent; the AEAD as a mutable lvalue (its @@ -312,8 +338,8 @@ lanes green on the merged head; 3.1 built; 3.2 to 4.2 not started. Nothing is pu both. Task 3.1's cells name the form an engine has; `supports_v` counts signing and verifying a message as supported with either form, and a prehashed digest only with the digest form, which 3.2's assertion for a prehashed input checks, so that a message-only backend (WebCrypto) refuses - it by name (1.2-fix review N1). Part B wires the public functions to the message form with its - engine; the delivery's note to part B names `p256_ecdsa_message_signing` and + it by name (1.2-fix review N1). Task 3.2's fix wires the public functions to the message form + (review 3.2 I1); the delivery's note to part B names `p256_ecdsa_message_signing` and `p256_ecdsa_message_verifying` and their functions `sign_message` and `verify_message`, which its browser engine takes in place of `sign` and `verify` (N2). The forms differ by name on purpose: a 32-byte digest view converts to a view of any length, so a test shows an engine whose `sign` takes From bcce9fe02593f6aa249165b6be79f54bf6c5f6c9 Mon Sep 17 00:00:00 2001 From: R Date: Sat, 5 Dec 2026 16:35:26 -0300 Subject: [PATCH 15/22] crypto backend-concepts: the 3.2 re-review's async message test in STATUS --- .../openspec/changes/backend-concepts/reference/STATUS.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md index b0da2e0..97e3774 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md +++ b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md @@ -304,7 +304,10 @@ started. Nothing is pushed. `async_seal`, `async_open` or `async_agree`, by a message that names it, and call the engine only in the branch it opens; the other branch, never compiled into a program, completes through `detail::refused_by_engine` with the operation's own result, so the assertion is the build's only - error. Every asynchronous backend specialises `async_engine`, so no mark is asked. Cost: none. + error. Every asynchronous backend specialises `async_engine`, so no mark is asked. Message test + `opaque_async_engine_missing` pins it: Ed25519's `async_verify` on the opaque backend's + asynchronous form, whose engine verifies P-256 alone, stops with the assertion alone (re-review + 3.2 N2). Cost: none. - **3.2: secp256k1's members assert no capability**: its one backend is libsecp256k1, every other refused by `secp256k1_refuses_others` before any engine is named (`secp256k1_engine` has no primary), and the backend header's D5 assertions prove every capability its cell promises; From a9eb1bad446065b3595aa8c46f4ea704f0cae41d Mon Sep 17 00:00:00 2001 From: R Date: Sat, 5 Dec 2026 16:36:29 -0300 Subject: [PATCH 16/22] crypto backend-concepts: task 4.1 done, its rulings in STATUS --- .../changes/backend-concepts/reference/STATUS.md | 16 +++++++++++++++- .../openspec/changes/backend-concepts/tasks.md | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md index 97e3774..820855e 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md +++ b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md @@ -2,7 +2,7 @@ 2026-12-05: tasks 1.1, 1.2, 2.1 and 2.2 built and reviewed clean, on the primitives change's head; 2.3 built; `origin/main` (primitives merged) merged into the three branches before 3.1, the full -lanes green on the merged head; 3.1 built; 3.2 built and its review's fixes folded; 4.1 and 4.2 not +lanes green on the merged head; 3.1 built; 3.2 built and reviewed clean; 4.1 built; 4.2 not started. Nothing is pushed. ## The bases @@ -321,6 +321,20 @@ started. Nothing is pushed. and a fix in `crypto.json`. The fix texts name no test-only backend, and speak in the program's terms: a capability the table promises and the engine lacks is "a defect of the backend, not of the program: report it" (review 3.2 M5). Cost: none. +- **4.1: the guide's catalogue is generated**: `generate.py` writes `generated/capabilities.adoc` + from `crypto.json`'s capability cells, each family's capabilities with their tag, kind, text and + the backends whose cell has them (targets named where fewer than the backend's own; "none yet" + for a capability no shipped backend has, `p256_generate` and the message forms among them), and + each backend's two secret-key traits; `generate_test` checks the page. The chapter on backends + ("What a backend has, operation by operation") states what `supports_v` counts, a partial cell, + `supports_capability_v`, P-256's two forms, the keys that never leave their backend and the + promises every backend keeps, and says the backend interfaces are crypto's own (D10). + `choosing_backend.adoc` names both traits of the table in place of "has the algorithm". Cost: + none. +- **4.1: the reference's Doc Comment faults found by the page's build are fixed with it**: the + three briefs of `supports.hpp` (1.2's) held several sentences, and `secp256k1_same_key_state`, + `secp256k1_same_point` and `secp256k1_same_xonly_point` (2.2's) had no brief; the lanes build no + page, so only the documentation's build saw them. 4.2 builds the page with the lanes. Cost: none. - **1.2-I1: the asynchronous concepts mirror `async.hpp`'s calls exactly**: the executor as `Executor const&`; a key pair, a public key, a signature, a scheme and a policy as const lvalues; the views as const lvalues of dynamic extent; the AEAD as a mutable lvalue (its diff --git a/libraries/crypto/openspec/changes/backend-concepts/tasks.md b/libraries/crypto/openspec/changes/backend-concepts/tasks.md index c2ed56c..667d72b 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/tasks.md +++ b/libraries/crypto/openspec/changes/backend-concepts/tasks.md @@ -21,5 +21,5 @@ the end of every task. A plan with code goes in `reference/plan.md` when the pro ## 4. The page and the delivery -- [ ] 4.1 The guide's chapter on backends: the catalogue, the contract, the opaque key as a program sees it, no public backend API (D10); `crypto.json`'s generated files; the changelog line; the chapter names `supports_capability_v`, `exports_secret_keys_v` and `imports_secret_keys_v`, what a partial cell means (`supports_v` counts the use operations alone), and P-256's digest and message forms, and `doc/backends.adoc` and `doc/choosing_backend.adoc` stop saying `supports_v` "has the algorithm" (review 3.1 M6) +- [x] 4.1 The guide's chapter on backends: the catalogue, the contract, the opaque key as a program sees it, no public backend API (D10); `crypto.json`'s generated files; the changelog line; the chapter names `supports_capability_v`, `exports_secret_keys_v` and `imports_secret_keys_v`, what a partial cell means (`supports_v` counts the use operations alone), and P-256's digest and message forms, and `doc/backends.adoc` and `doc/choosing_backend.adoc` stop saying `supports_v` "has the algorithm" (review 3.1 M6) - [ ] 4.2 Full local verification on every lane, pull requests, merge, one CI at the end From f94d46d4f343e080065eb5a76869196b0c03c89c Mon Sep 17 00:00:00 2001 From: R Date: Sat, 5 Dec 2026 16:46:08 -0300 Subject: [PATCH 17/22] crypto backend-concepts: the 4.1 review's fixes, their rulings in STATUS --- .../backend-concepts/reference/STATUS.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md index 820855e..af80156 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md +++ b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md @@ -2,7 +2,7 @@ 2026-12-05: tasks 1.1, 1.2, 2.1 and 2.2 built and reviewed clean, on the primitives change's head; 2.3 built; `origin/main` (primitives merged) merged into the three branches before 3.1, the full -lanes green on the merged head; 3.1 built; 3.2 built and reviewed clean; 4.1 built; 4.2 not +lanes green on the merged head; 3.1 built; 3.2 built and reviewed clean; 4.1 built, its review's fixes folded; 4.2 not started. Nothing is pushed. ## The bases @@ -335,6 +335,23 @@ started. Nothing is pushed. three briefs of `supports.hpp` (1.2's) held several sentences, and `secp256k1_same_key_state`, `secp256k1_same_point` and `secp256k1_same_xonly_point` (2.2's) had no brief; the lanes build no page, so only the documentation's build saw them. 4.2 builds the page with the lanes. Cost: none. +- **4.1-I1: the contract names each backend's allocations**: the chapter's promise "no backend + allocates through the program's allocators" was false for libsecp256k1, whose key pair allocates + its signing context in the `std::pmr::memory_resource` the program gives `from_secret` or a + decode. The bullet now names each backend against the facts page: BearSSL, ctaes and libsodium + allocate nothing; OpenSSL a cipher's context through its own allocator (or + `openssl_memory_resource()` under `WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE`), its failure an error + value; libsecp256k1 in the program's resource, whose failure is the resource's to report. Cost: + none. +- **4.1-I2: `imports_secret_keys_v` covers a key pair's secret alone**: the code consults it in a + key pair's `from_secret`, `async_from_secret` and private decodes, never in a cipher's + `from_key`; the brief now says so, matching the chapter. Whether a backend that keeps its keys + should refuse a cipher's raw key too is the device backends' question, raised with them, not + decided here. Cost: none. +- **4.1-M5: the secret-key traits are a generated page of their own**: `generate.py` writes + `generated/secret-key-traits.adoc`, one table whose headers name the two traits, included in + "Keys that never leave their backend", where the traits are explained; `capabilities.adoc` is the + catalogue's one table. `generate_test` checks both pages. Cost: none. - **1.2-I1: the asynchronous concepts mirror `async.hpp`'s calls exactly**: the executor as `Executor const&`; a key pair, a public key, a signature, a scheme and a policy as const lvalues; the views as const lvalues of dynamic extent; the AEAD as a mutable lvalue (its From fb942ad21aee4a1541c8a0daa8bbedd2f14796ac Mon Sep 17 00:00:00 2001 From: R Date: Sat, 5 Dec 2026 16:48:15 -0300 Subject: [PATCH 18/22] crypto backend-concepts: the 4.1 re-review's minors, 4.1 reviewed clean --- .../changes/backend-concepts/reference/STATUS.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md index af80156..f56a1c9 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md +++ b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md @@ -2,7 +2,7 @@ 2026-12-05: tasks 1.1, 1.2, 2.1 and 2.2 built and reviewed clean, on the primitives change's head; 2.3 built; `origin/main` (primitives merged) merged into the three branches before 3.1, the full -lanes green on the merged head; 3.1 built; 3.2 built and reviewed clean; 4.1 built, its review's fixes folded; 4.2 not +lanes green on the merged head; 3.1 built; 3.2 built and reviewed clean; 4.1 built and reviewed clean; 4.2 not started. Nothing is pushed. ## The bases @@ -341,8 +341,11 @@ started. Nothing is pushed. decode. The bullet now names each backend against the facts page: BearSSL, ctaes and libsodium allocate nothing; OpenSSL a cipher's context through its own allocator (or `openssl_memory_resource()` under `WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE`), its failure an error - value; libsecp256k1 in the program's resource, whose failure is the resource's to report. Cost: - none. + value; libsecp256k1 in the program's resource, whose failure is the resource's to report. The + re-review (N1) found the lead "no backend allocates through the C++ heap" false too, since the + default resource is the heap: the bullet now leads with "what a backend allocates is named + in its row". OpenSSL's facts row (in `crypto.json`) and the chapter name Poly1305's MAC + context, made and freed at each call, as `backends/openssl.hpp` documents. Cost: none. - **4.1-I2: `imports_secret_keys_v` covers a key pair's secret alone**: the code consults it in a key pair's `from_secret`, `async_from_secret` and private decodes, never in a cipher's `from_key`; the brief now says so, matching the chapter. Whether a backend that keeps its keys From 071bd7ff8e778d5553b30e49218b28e97250fb72 Mon Sep 17 00:00:00 2001 From: R Date: Sat, 5 Dec 2026 17:09:45 -0300 Subject: [PATCH 19/22] crypto backend-concepts: the spec describes what was built, the final review's rulings --- .../changes/backend-concepts/design.md | 26 ++++++++++ .../backend-concepts/reference/STATUS.md | 51 ++++++++++++++++--- .../backend-concepts/specs/crypto/spec.md | 38 ++++++++++++-- 3 files changed, 104 insertions(+), 11 deletions(-) diff --git a/libraries/crypto/openspec/changes/backend-concepts/design.md b/libraries/crypto/openspec/changes/backend-concepts/design.md index 8decbdf..d1f860a 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/design.md +++ b/libraries/crypto/openspec/changes/backend-concepts/design.md @@ -158,6 +158,12 @@ it, and is named after the capability, never after a backend: `backend::aead`. Each family header includes its area's header, and no concept header includes a backend. +> **As built (`reference/STATUS.md`)**: no `encoding.hpp` (base64 moved to webcpp::codecs and the +> PEM engine is gone, ruling "No `base64` concept"); `common.hpp` holds the shared contract and the +> requirements every capability reuses, and `keys.hpp` the four key concepts that take no curve +> (`key_import`, `key_generate`, `key_public`, `key_export`, ruling 1.2-M3), which each curve's +> header names (`p256_import = key_import`). + ### D2. The contract every capability shares What a concept checks (C++ requirements): @@ -393,6 +399,16 @@ uniform-types concepts (`crypto::keypair`, `crypto::aead`, ...) are the public a the backend concepts are what their members require of a backend, and the names never collide (`crypto::aead` versus `detail::backend::aead`). +> **As built (task 3.2, `reference/STATUS.md`)**: a message says "this backend", not the +> backend's name (a C++20 `static_assert` message is a literal; the instantiation notes name the +> backend), and names the capability by its public tag: "webcpp::crypto: this backend has P-256 +> but not crypto::capabilities::p256_ecdsa_signing: ...". Before any capability, the secret-key +> traits speak, each by its own message and alone (D3's and D6's amendments): `from_secret`, +> `async_from_secret`, `secret()`, the private formats and `to_x25519()` on a backend that keeps +> its keys name `crypto::imports_secret_keys_v` or `exports_secret_keys_v`, whatever its engine +> has. `can_sign` and `can_verify` agree with `sign` and `verify` on P-256's two forms (final +> review M4). + ### D10. No public backend API (owner decision 5) The concepts, the engines and the states stay in `detail`; no `crypto::backend` namespace, no @@ -486,6 +502,16 @@ struct opaque_p256_engine { }; // no import, no export: from_secret(bytes) and secret() refuse, naming p256_import and p256_export ``` +> **As built (`reference/STATUS.md`)**: the block above is the approved sketch. `supports_v` +> counts the use operations alone (R8, ruling 3.1 "a capability's kind decides what `supports_v` +> counts"): BearSSL's P-256 row is its signing, verifying and agreement, never `p256_import`, and +> the generated `capabilities_test` checks each capability's cell against its concept both ways. +> An opaque engine's public key is the fallible `public_key(state, point)` (the concept +> `key_public`), not `void public_point`; and `from_secret(bytes)` and +> `secret()` on it refuse by the secret-key traits, `crypto::imports_secret_keys_v` and +> `exports_secret_keys_v`, before `p256_import` and `p256_export` (`test/backends/opaque.hpp`, +> message test `opaque_keys_kept`). + ## Risks / Trade-offs - **Concepts too narrow for the browser backend**: mitigated by the opaque stand-in now, synchronous diff --git a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md index f56a1c9..11717b2 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md +++ b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md @@ -1,9 +1,10 @@ # webcpp::crypto backend-concepts: where the implementation stands -2026-12-05: tasks 1.1, 1.2, 2.1 and 2.2 built and reviewed clean, on the primitives change's head; -2.3 built; `origin/main` (primitives merged) merged into the three branches before 3.1, the full -lanes green on the merged head; 3.1 built; 3.2 built and reviewed clean; 4.1 built and reviewed clean; 4.2 not -started. Nothing is pushed. +2026-12-05: tasks 1.1, 1.2, 2.1, 2.2 and 2.3 built and reviewed clean, on the primitives change's +head; `origin/main` (primitives merged) merged into the three branches before 3.1, the full lanes +green on the merged head; 3.1, 3.2 and 4.1 built and reviewed clean; `origin/main` merged again +for 4.2; the final whole-branch review's fixes folded, their re-review and 4.2's final lanes +pending. Nothing is pushed. ## The bases @@ -423,8 +424,25 @@ started. Nothing is pushed. - **1.2-M9: MSVC 14.3/14.5 is on the delivery checklist** (`ledger.md`) for the `requires(Engine::state ...)` parameters without `typename` and `KeyEngine::state const&`. Cost: none. -- **No implementer or reviewer subagents in this run**: the stream ran as a fork that may not start - subagents, so task 1.1 has no independent review yet. Cost: the review is owed before delivery. +- **Final review M3: `async_from_secret` asks the import trait whatever its engine has**: the + trait's assertion was `imports || imports_secret_keys_v`, so an asynchronous engine with + `from_secret` on a backend that keeps its keys would have imported one; it now asserts the trait + first and alone, then the engine's `async_import_secret`, and calls the engine only under both. + Message test `kept_async_engine_imports` (with its MSVC twin) gives such an engine to a backend + of its own and expects the trait's message alone; it fails on the code before the fix. Cost: + none. +- **Final review M4: `can_sign` and `can_verify` ask the curve's digest form for a prehashed + input**: `detail::signs_digest_v` and `verifies_digest_v` + (`signing.hpp`), true unless the curve's header says otherwise; P-256's are true where the engine + is unmarked or has `p256_ecdsa_signing` (`_verifying`), as `p256_signing_checked` asks it. + `async_sign` keeps `input_valid_v` as its own check, so that on a synchronous message-only + backend a prehashed digest reaches `sign`'s own message (`p256_prehashed_message_only`). + `p256_message_form` asserts both concepts on the message-only stand-in. Cost: none. +- **Final review M5: the public-key formats have a use case of their own**: `crypto.json`'s use + case for Ed25519's and X25519's key formats lists the key pair's operations + (`ed25519_formats`, `x25519_formats`), and a new one, "read or write an Ed25519 or X25519 public + key ... with no backend: raw or SPKI", lists the public-key rows, so `llms.txt` promises no + PKCS#8 of a public key. Cost: none. ## Verification @@ -467,3 +485,24 @@ started. Nothing is pushed. - Task 2.2's review minors (crypto `d2482e5`, superproject `c37a20f`): every crypto test on Clang, `backend_concepts_secp256k1` on GCC 15 too, its new run-time guards mutation-checked (the entropy size and the recovery id); the macOS clang-tidy and the Linux lint clean. +- Task 2.3's review fixes (crypto `ff217b7`, superproject `1e30171`): re-review approved; the + affected tests on Clang, the macOS clang-tidy and the Linux lint clean. +- `origin/main` merged before 3.1 (crypto `96c2f82`, superproject `ec4af9b`): every crypto test on + Clang, GCC 15, wasip2 and Emscripten. +- Task 3.1 (crypto `369a04c`, superproject `986c78c`) and its review fixes (crypto `0aa2f31`, + superproject `c5843e7`): every crypto test on Clang, GCC 15, wasip2 and Emscripten, the + generated `capabilities_test` among them; `generate.py --check` and `generate_test.py` (with the + capability cases now in `CASES`); the macOS clang-tidy and the Linux lint clean. +- Task 3.2 (crypto `7cec9aa`, superproject `7040141`), its review fixes (crypto `db9fa30`) and + minors (crypto `ca53123`): every crypto test on Clang, GCC 15, wasip2 and Emscripten for 3.2, the + whole suite on Clang for its fixes (0 failed), the message tests with their MSVC twins + registered; the macOS clang-tidy and the Linux lint clean. +- Task 4.1 (crypto `4cf9cb1`) and its review fixes (crypto `87889e1`, `2fdc397`): the page built + with its Doc Comment and rendered checks, `generate.py --check`, `generate_test.py`; the macOS + clang-tidy clean and the Linux lint clean at `4cf9cb1` (the fixes' Linux lint is 4.2's full + one). +- The final review's fixes (crypto, after `2fdc397`): the affected message tests, `p256_message_form`, + `signing`, `opaque_backend` and `backend_concepts_asynchronous` on Clang, the new message test + failing on the code before the fix; `generate.py --check`, `generate_test.py` and the Jamfile + tools tests; the macOS clang-tidy. Task 4.2's full lanes (Clang, GCC 15, wasip2, wasip3, + Emscripten, MSVC 14.3 and 14.5, the constant-time lane, both full lints) run on the final head. diff --git a/libraries/crypto/openspec/changes/backend-concepts/specs/crypto/spec.md b/libraries/crypto/openspec/changes/backend-concepts/specs/crypto/spec.md index 8cb9d7a..32a0db0 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/specs/crypto/spec.md +++ b/libraries/crypto/openspec/changes/backend-concepts/specs/crypto/spec.md @@ -1,25 +1,53 @@ ## ADDED Requirements ### Requirement: Backend capabilities: one concept per capability -`` SHALL declare, in namespace `webcpp::crypto::detail::backend` and including no backend, one concept per capability of the catalogue in `design.md` D4 (block cipher, GCM and its incremental open, each AEAD family, authenticated box, box, sealed box, kx, Ed25519 and X25519 and P-256 split into import, generate, public, use and export, Ed25519ph, P-256's point and DER, secp256k1 split as the other curves are, with its protocol capabilities, entropy, and the asynchronous operations), each requiring static `noexcept` functions of the engine over its `state`, results of `boost::system::result` or `result` (or `bool` for a predicate on public data), outputs into fixed-size spans, and `move` and `reset` for a state that holds anything. Each concept's documentation MUST state its semantic contract: the public function holds the timing guard and the engine none, the engine allocates nothing through the C++ heap or the program's allocators, engine functions are safe on distinct states concurrently, `reset` wipes secrets and releases handles, the backend's canary is read before its first call. Each backend header MUST `static_assert` every concept its table cells promise, after each specialization. +`` SHALL declare, in namespace `webcpp::crypto::detail::backend` and including no backend, one concept per capability of the catalogue in `design.md` D4 (block cipher, GCM, whose incremental open is GCM's own `start`, `run` and `check` and no concept of its own, each AEAD family, stream cipher, authenticator, authenticated box, box, sealed box, kx, Ed25519 and X25519 and P-256 split into import, generate, public, use and export, Ed25519ph, P-256's point and DER, secp256k1 split as the other curves are, with its protocol capabilities, entropy, and the asynchronous operations: `async_import_secret` for a key pair made from its secret, `async_import_key` for a cipher made from its key, `async_generate`, `async_sign`, `async_verify`, `async_agree`, `async_seal` and `async_open`, and no `async_export`), each requiring static `noexcept` functions of the engine over its `state`, results of `boost::system::result` or `result` (or `bool` for a predicate on public data), outputs into fixed-size spans, and `move` and `reset` for a state that holds anything. Each concept's documentation MUST state its semantic contract: the public function holds the timing guard and the engine none, the engine allocates nothing through the C++ heap or the program's allocators, engine functions are safe on distinct states concurrently, `reset` wipes secrets and releases handles, the backend's canary is read before its first call. Each backend header MUST `static_assert` every concept its table cells promise, after each specialization. #### Scenario: Every backend checked - **WHEN** each backend's header is compiled on every target where its library builds - **THEN** every engine it specializes satisfies the concepts its cells promise, and the build fails naming the concept and the operation otherwise ### Requirement: Backend capabilities: the opaque key -Key capabilities SHALL be split into import (a state from secret bytes), generate (a state whose secret the backend draws), public (the public key of a state), use (sign, verify, agree) and export (the secret bytes back), and no use capability MUST require the secret in memory. A backend that implements generate, public and the uses without import or export MUST be usable through the public key pair types, whose `from_secret(bytes)`, `secret()` and private formats then stop the build with a message naming the missing capability. A test-only opaque backend whose states are handles MUST implement P-256 and X25519 this way, in a synchronous and an asynchronous form, so that the asynchronous concepts are tested; it MUST stay outside the capability table and its checks. `generate()` MUST use a backend's own generation when it has one, and `random_device` with import only for a backend that can only import. +Key capabilities SHALL be split into import (a state from secret bytes), generate (a state whose secret the backend draws), public (the public key of a state), use (sign, verify, agree) and export (the secret bytes back), and no use capability MUST require the secret in memory. A backend that implements generate, public and the uses without import or export MUST be usable through the public key pair types, whose `from_secret(bytes)`, `secret()` and private formats then stop the build with a message naming the secret-key trait that refuses them (see "the secret-key traits"). A test-only opaque backend whose states are handles MUST implement P-256 and X25519 this way, in a synchronous and an asynchronous form, so that the asynchronous concepts are tested; it MUST stay outside the capability table and its checks. `generate()` MUST use a backend's own generation when it has one, and `random_device` with import only for a backend that can only import. #### Scenario: A key that never leaves its backend - **WHEN** a P-256 key pair on the test-only opaque backend is generated, signs a message and agrees with a peer -- **THEN** its signature verifies on BearSSL, its agreement equals the peer's, and a call of `secret()` or `from_secret(bytes)` on it does not compile, naming `p256_export` and `p256_import` +- **THEN** its signature verifies on BearSSL, its agreement equals the peer's, and a call of `secret()` or `from_secret(bytes)` on it does not compile, naming `crypto::exports_secret_keys_v` and `crypto::imports_secret_keys_v` ### Requirement: Backend capabilities: refusals name the missing capability -Each public member that calls an engine SHALL check, in a `static_assert`, the capability it uses, with a message naming the backend, the algorithm and the missing capability; where the engine is not specialized at all, the generated refusal of the primary engine MUST fire first with its existing message. +Each public member that calls an engine SHALL check, in a `static_assert`, the capability it uses, with one message that says "this backend" (a C++20 `static_assert` message is a literal and cannot name its template argument; the compiler's instantiation notes name the backend and the member), names the algorithm and names the missing capability by its tag of `crypto::capabilities`. Where the engine is not specialized at all, the generated refusal of the primary engine MUST fire first with its existing message; where a secret-key trait refuses the call, the trait's message MUST speak before the capability's, and alone. A refusal MUST be said once per engine, whatever the call shape. #### Scenario: Two diagnostics, in order - **WHEN** a program calls `curves::ed25519::basic_keypair::from_secret(seed)`, and then `secret()` on a key pair of the opaque test backend -- **THEN** the first stops with the generated message naming the backends that have Ed25519, and the second with the message naming the missing export capability +- **THEN** the first stops with the generated message naming the backends that have Ed25519, and the second with the message naming `crypto::exports_secret_keys_v`, and no message about `capabilities::p256_export` + +### Requirement: Backend capabilities: the secret-key traits +`` SHALL declare `crypto::exports_secret_keys_v`, whether a secret key's bytes may leave the backend, and `crypto::imports_secret_keys_v`, whether they may enter it, generated from the table and needing no backend's header; both MUST be true for every backend crypto ships and false for a tag outside the table. They cover a key pair's secret: `from_secret`, `async_from_secret`, `secret()`, a key pair's private formats both ways and Ed25519's `to_x25519()`; a cipher's `from_key` MUST NOT consult them. Each call they cover MUST stop the build with the trait's message before any capability's, on a synchronous backend and on one that completes by itself, whatever the backend's engine has. + +#### Scenario: A kept key's import, on an engine that could import +- **WHEN** a program calls `async_from_secret` of a P-256 key pair on a backend that completes by itself, whose `imports_secret_keys_v` is false and whose asynchronous engine has `async_import_secret` +- **THEN** the build stops with the import trait's message alone, naming `crypto::imports_secret_keys_v` and `async_generate` + +### Requirement: Backend capabilities: the capability tags +`crypto::capabilities` SHALL hold one public tag per capability of the catalogue, named after the capability (`p256_export`, `p256_ecdsa_signing`, `p256_ecdsa_message_signing`, ...) or, for a family whose one capability is a concept other families share, after the family (`capabilities::chacha20_poly1305`, `capabilities::aes_block`), and `supports_capability_v` MUST take them. Each tag's kind (import, generate, public, export, use or auxiliary) MUST decide whether `supports_v` counts it: the use capabilities alone. + +#### Scenario: A tag a program asks +- **WHEN** a program evaluates `supports_capability_v` with no backend's header included +- **THEN** it is `true`, and the guide's generated catalogue lists `p256_export` with BearSSL among its backends + +### Requirement: Backend capabilities: P-256's digest and message forms +P-256's ECDSA SHALL have two forms of signing and of verifying: the digest form (`capabilities::p256_ecdsa_signing`, `p256_ecdsa_verifying`, a SHA-256 digest) and the message form (`p256_ecdsa_message_signing`, `p256_ecdsa_message_verifying`, the message hashed inside the backend). `sign` and `verify` of a message MUST give the message to the message form when the engine has it, and otherwise hash it with SHA-256 and use the digest form; the signature MUST be made low S either way, and the verification policy MUST be checked before the engine sees the signature. A digest given as `signing_schemes::prehashed` MUST need the digest form, and `can_sign` and `can_verify` MUST be false for it where the backend lacks that form, as `sign` and `verify` refuse it. `supports_v` MUST be true when either form is present. + +#### Scenario: A backend with the message form alone +- **WHEN** a P-256 key pair on a backend whose engine has only the message form signs a message, and a program asks `can_sign` of a `prehashed<32>` marker and then signs one +- **THEN** the message reaches the engine whole and the signature comes back low S, `can_sign` is `false`, and the prehashed `sign` stops the build naming `crypto::capabilities::p256_ecdsa_signing` + +### Requirement: Backend capabilities: private formats of a kept key +A key pair's private formats SHALL be refused, before any other reason, on a backend whose secret keys neither enter nor leave it: `formats::raw` with `refusal_reason::private_kept_raw`, and `formats::pkcs8` and `formats::pem(formats::pkcs8)` with `private_kept_pkcs8`, each message naming the two secret-key traits, both directions refused since encoding and decoding are one pair; on a backend that is also asynchronous, these reasons MUST speak before `private_on_asynchronous`. + +#### Scenario: PKCS#8 of a kept key +- **WHEN** a program encodes a P-256 key pair of the test-only opaque backend as `formats::pkcs8` +- **THEN** the build stops with the `private_kept_pkcs8` message, naming `crypto::exports_secret_keys_v` and `crypto::imports_secret_keys_v` ### Requirement: Backend capabilities: secp256k1 behind engines, split into capabilities The calls of `curves::secp256k1` and its modules into libsecp256k1 SHALL go through `detail::secp256k1_engine`, one specialization per capability (import, generate, public, export, ECDSA signing and verifying, Schnorr signing and verifying, recoverable, ECDH, tweaks, ElligatorSwift, MuSig2, silent payments), each checked against its concept, keeping the static context, the self test, the canary and no allocation; no single concept MUST cover the curve's whole interface. From 1b1cccf4a9b3d3fd9f123d809b92b7cdc04ec554 Mon Sep 17 00:00:00 2001 From: R Date: Sat, 5 Dec 2026 17:18:46 -0300 Subject: [PATCH 20/22] crypto backend-concepts: the final re-review's spec wording and rulings --- .../changes/backend-concepts/reference/STATUS.md | 13 +++++++++++++ .../changes/backend-concepts/specs/crypto/spec.md | 6 +++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md index 11717b2..670ac57 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md +++ b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md @@ -438,6 +438,19 @@ pending. Nothing is pushed. `async_sign` keeps `input_valid_v` as its own check, so that on a synchronous message-only backend a prehashed digest reaches `sign`'s own message (`p256_prehashed_message_only`). `p256_message_form` asserts both concepts on the message-only stand-in. Cost: none. +- **Final re-review N1: the digest-form query is a query**: `signs_digest_v` and + `verifies_digest_v` of P-256 formed `p256_ecdsa_signing` even for an unspecialised + engine, so `can_sign` and `can_verify` of a prehashed digest stopped the build on a backend + without P-256 (libsodium) and on the default key pair without its backend's header, where at + `2fdc397` they answered. `detail::p256_signs_digest` and `p256_verifies_digest` (`consteval`) + form the concept only for a specialised engine; `p256_message_form` asserts both queries on + libsodium and on the default key pair, and fails to compile on the code before the fix (Clang + and GCC 15). Cost: none. +- **Follow-up, not this stream: archiving needs `libraries/crypto/openspec/specs/crypto`**: + OpenSpec 1.16's validation says an archive would refuse this change's `## MODIFIED + Requirements`, since no crypto change was ever archived and the spec does not exist yet; CI's + 1.10.0 passes. Whoever archives crypto's first change creates the spec (or turns the MODIFIED + requirements into ADDED ones). Cost: none here. - **Final review M5: the public-key formats have a use case of their own**: `crypto.json`'s use case for Ed25519's and X25519's key formats lists the key pair's operations (`ed25519_formats`, `x25519_formats`), and a new one, "read or write an Ed25519 or X25519 public diff --git a/libraries/crypto/openspec/changes/backend-concepts/specs/crypto/spec.md b/libraries/crypto/openspec/changes/backend-concepts/specs/crypto/spec.md index 32a0db0..9b5cba2 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/specs/crypto/spec.md +++ b/libraries/crypto/openspec/changes/backend-concepts/specs/crypto/spec.md @@ -15,11 +15,11 @@ Key capabilities SHALL be split into import (a state from secret bytes), generat - **THEN** its signature verifies on BearSSL, its agreement equals the peer's, and a call of `secret()` or `from_secret(bytes)` on it does not compile, naming `crypto::exports_secret_keys_v` and `crypto::imports_secret_keys_v` ### Requirement: Backend capabilities: refusals name the missing capability -Each public member that calls an engine SHALL check, in a `static_assert`, the capability it uses, with one message that says "this backend" (a C++20 `static_assert` message is a literal and cannot name its template argument; the compiler's instantiation notes name the backend and the member), names the algorithm and names the missing capability by its tag of `crypto::capabilities`. Where the engine is not specialized at all, the generated refusal of the primary engine MUST fire first with its existing message; where a secret-key trait refuses the call, the trait's message MUST speak before the capability's, and alone. A refusal MUST be said once per engine, whatever the call shape. +Each public member that calls an engine SHALL check, in a `static_assert`, the capability it uses, with one message that says "this backend" (a C++20 `static_assert` message is a literal and cannot name its template argument; the compiler's instantiation notes name the backend and the member), names the algorithm and names the missing capability by its tag of `crypto::capabilities`; an asynchronous engine's refusal names its asynchronous concept (`async_import_secret`, `async_sign`, ...), which has no tag. Where the engine is not specialized at all, the generated refusal of the primary engine MUST fire first with its existing message; where a secret-key trait refuses the call, the trait's message MUST speak before the capability's, and alone. A refusal MUST be said once per engine, whatever the call shape. #### Scenario: Two diagnostics, in order - **WHEN** a program calls `curves::ed25519::basic_keypair::from_secret(seed)`, and then `secret()` on a key pair of the opaque test backend -- **THEN** the first stops with the generated message naming the backends that have Ed25519, and the second with the message naming `crypto::exports_secret_keys_v`, and no message about `capabilities::p256_export` +- **THEN** the first stops with the generated message naming the backends that have Ed25519, and the second with the message naming `crypto::exports_secret_keys_v`, and no second message, from the `p256_export` capability's assertion ### Requirement: Backend capabilities: the secret-key traits `` SHALL declare `crypto::exports_secret_keys_v`, whether a secret key's bytes may leave the backend, and `crypto::imports_secret_keys_v`, whether they may enter it, generated from the table and needing no backend's header; both MUST be true for every backend crypto ships and false for a tag outside the table. They cover a key pair's secret: `from_secret`, `async_from_secret`, `secret()`, a key pair's private formats both ways and Ed25519's `to_x25519()`; a cipher's `from_key` MUST NOT consult them. Each call they cover MUST stop the build with the trait's message before any capability's, on a synchronous backend and on one that completes by itself, whatever the backend's engine has. @@ -43,7 +43,7 @@ P-256's ECDSA SHALL have two forms of signing and of verifying: the digest form - **THEN** the message reaches the engine whole and the signature comes back low S, `can_sign` is `false`, and the prehashed `sign` stops the build naming `crypto::capabilities::p256_ecdsa_signing` ### Requirement: Backend capabilities: private formats of a kept key -A key pair's private formats SHALL be refused, before any other reason, on a backend whose secret keys neither enter nor leave it: `formats::raw` with `refusal_reason::private_kept_raw`, and `formats::pkcs8` and `formats::pem(formats::pkcs8)` with `private_kept_pkcs8`, each message naming the two secret-key traits, both directions refused since encoding and decoding are one pair; on a backend that is also asynchronous, these reasons MUST speak before `private_on_asynchronous`. +A key pair's private formats SHALL be refused, before any other reason, on a backend whose secret keys may not enter it or may not leave it: `formats::raw` with `refusal_reason::private_kept_raw`, and `formats::pkcs8` and `formats::pem(formats::pkcs8)` with `private_kept_pkcs8`, each message naming the two secret-key traits, both directions refused since encoding and decoding are one pair; on a backend that is also asynchronous, these reasons MUST speak before `private_on_asynchronous`. #### Scenario: PKCS#8 of a kept key - **WHEN** a program encodes a P-256 key pair of the test-only opaque backend as `formats::pkcs8` From d17c4954ed95b5275037032f4acc2867ae14bcbf Mon Sep 17 00:00:00 2001 From: R Date: Sat, 5 Dec 2026 19:22:15 -0300 Subject: [PATCH 21/22] crypto backend-concepts: task 4.2's final lanes in STATUS --- .../changes/backend-concepts/reference/STATUS.md | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md index 670ac57..d81ccb3 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md +++ b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md @@ -3,8 +3,8 @@ 2026-12-05: tasks 1.1, 1.2, 2.1, 2.2 and 2.3 built and reviewed clean, on the primitives change's head; `origin/main` (primitives merged) merged into the three branches before 3.1, the full lanes green on the merged head; 3.1, 3.2 and 4.1 built and reviewed clean; `origin/main` merged again -for 4.2; the final whole-branch review's fixes folded, their re-review and 4.2's final lanes -pending. Nothing is pushed. +for 4.2; the final whole-branch review clean after two fix rounds; 4.2's final lanes green on +crypto `fa3ed86` / superproject `14740f3`; the pull requests open, their one CI pending. ## The bases @@ -519,3 +519,11 @@ pending. Nothing is pushed. failing on the code before the fix; `generate.py --check`, `generate_test.py` and the Jamfile tools tests; the macOS clang-tidy. Task 4.2's full lanes (Clang, GCC 15, wasip2, wasip3, Emscripten, MSVC 14.3 and 14.5, the constant-time lane, both full lints) run on the final head. +- Task 4.2's final lanes, local (crypto `b56e53a`, superproject `021fd63`): Clang 820, GCC 15 + 584, wasip2 767, wasip3 748, Emscripten 489, 0 failed, with crypto's tests, examples and bench; hash's examples and + `openssl_one_copy` on Clang; the C suites on four toolsets; the page; `generate.py --check`, + `generate_test.py` and the tools tests; the five-lane report; the full macOS lint clean; Mac + dudect at release green, the planted leak found; the constant-time Linux lane (status 0); the + full Linux lint CLEAN; MSVC 14.5 arm64 timing set green; MSVC 14.3 (747 passed) and 14.5 with a + fresh third-party build (828 passed) found one defect, `p256_message_form`'s C4267 (a `size_t` + assigned to a byte, since 3.2), fixed in crypto `fa3ed86` and rerun green on both. From 99674f2e28f8168edcd39df04dec50341cb47e95 Mon Sep 17 00:00:00 2001 From: R Date: Sat, 5 Dec 2026 23:57:40 -0300 Subject: [PATCH 22/22] crypto backend-concepts: task 4.2 done, the pull requests' CI green --- .../changes/backend-concepts/reference/STATUS.md | 9 ++++++++- .../crypto/openspec/changes/backend-concepts/tasks.md | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md index d81ccb3..8254ed9 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md +++ b/libraries/crypto/openspec/changes/backend-concepts/reference/STATUS.md @@ -4,7 +4,8 @@ head; `origin/main` (primitives merged) merged into the three branches before 3.1, the full lanes green on the merged head; 3.1, 3.2 and 4.1 built and reviewed clean; `origin/main` merged again for 4.2; the final whole-branch review clean after two fix rounds; 4.2's final lanes green on -crypto `fa3ed86` / superproject `14740f3`; the pull requests open, their one CI pending. +crypto `4ad34c8` / superproject `03a2fbd`; the pull requests' CI green (webcpporg/crypto#31, +webcpporg/webcpp#71, webcpporg/proposals#44), the merge the coordinator's. ## The bases @@ -527,3 +528,9 @@ crypto `fa3ed86` / superproject `14740f3`; the pull requests open, their one CI full Linux lint CLEAN; MSVC 14.5 arm64 timing set green; MSVC 14.3 (747 passed) and 14.5 with a fresh third-party build (828 passed) found one defect, `p256_message_form`'s C4267 (a `size_t` assigned to a byte, since 3.2), fixed in crypto `fa3ed86` and rerun green on both. +- The pull requests' CI: webcpporg/webcpp#71's Site job found the capability catalogue's five + header cells without a scope (html-validate's wcag/h63: the family's title spanning its rows + makes the table complex), which the local lanes do not check; the family column became a header + column (crypto `4ad34c8`), the page rebuilt and the site's html-validate run on it locally, + clean. Then green: crypto#31's CI (run 47590120338, at `4ad34c8`) and webcpp#71's (run + 47590120690, at `03a2fbd`), every lane and the site. diff --git a/libraries/crypto/openspec/changes/backend-concepts/tasks.md b/libraries/crypto/openspec/changes/backend-concepts/tasks.md index 667d72b..e4353f5 100644 --- a/libraries/crypto/openspec/changes/backend-concepts/tasks.md +++ b/libraries/crypto/openspec/changes/backend-concepts/tasks.md @@ -22,4 +22,4 @@ the end of every task. A plan with code goes in `reference/plan.md` when the pro ## 4. The page and the delivery - [x] 4.1 The guide's chapter on backends: the catalogue, the contract, the opaque key as a program sees it, no public backend API (D10); `crypto.json`'s generated files; the changelog line; the chapter names `supports_capability_v`, `exports_secret_keys_v` and `imports_secret_keys_v`, what a partial cell means (`supports_v` counts the use operations alone), and P-256's digest and message forms, and `doc/backends.adoc` and `doc/choosing_backend.adoc` stop saying `supports_v` "has the algorithm" (review 3.1 M6) -- [ ] 4.2 Full local verification on every lane, pull requests, merge, one CI at the end +- [x] 4.2 Full local verification on every lane, pull requests, merge, one CI at the end