diff --git a/libraries/crypto/openspec/changes/foundation/design.md b/libraries/crypto/openspec/changes/foundation/design.md index a8019f4..0a7e7e0 100644 --- a/libraries/crypto/openspec/changes/foundation/design.md +++ b/libraries/crypto/openspec/changes/foundation/design.md @@ -993,7 +993,9 @@ by target. It never differs by what the program links. compilation with an `#error` that names the type to write (the owner's answer Q3), since a silently ignored define would change which code a program runs. - **Measurements are references.** The own lane `sizes` builds every (family, backend) program - through the superproject's `webcpp.size-table`, which requires `release`, and the + through the superproject's `webcpp.size-table`, which requires `release` and extends, + by the owner's decision of 2026-11-17 (C36), from Emscripten page programs to plain linked + programs on every target (Task 11'), and the generated size matrix reads its table; throughput is measured by hand with a collect script that refuses a program or data not built at `variant=release` (hash's `bench/collect.py` is the model), on the machines the page names, and published as a dated page. Neither decides a diff --git a/libraries/crypto/openspec/changes/foundation/reference/roadmap.md b/libraries/crypto/openspec/changes/foundation/reference/roadmap.md index b645c19..d58d2f2 100644 --- a/libraries/crypto/openspec/changes/foundation/reference/roadmap.md +++ b/libraries/crypto/openspec/changes/foundation/reference/roadmap.md @@ -39,15 +39,15 @@ decision is cited, `D` is the foundation's `design.md` and `genesis D` the at `77e1ce5` and `/third_party//sodium` (webcpp::hash), and webcpp::hash with `backends::hash2` as every key derivation's default. - **The release-build rule exists in the superproject** (`69bf8ab`): `webcpp.size-table` - requires `release`, and hash's `bench/collect.py` refuses a program or data not built + requires `release` (and, by C36 of 2026-11-17, serves plain linked programs on every target through foundation Task 11', not only Emscripten page programs), and hash's `bench/collect.py` refuses a program or data not built at `variant=release`. crypto's size and throughput tables use the same tools. ## Every overlap, resolved | Item | Where it goes | Why | | --- | --- | --- | -| Genesis Task 31 (trystero's sealer and `random`) | dropped | the owner's decision; trystero keeps its own sealer until a change of trystero's own adopts crypto | -| Genesis Task 32 (trystero's signer) | dropped | the same; its build half (Task 30a) is in version 0.1 | +| Genesis Task 31 (trystero's sealer and `random`) | dropped by the owner, 2026-11-17 | trystero keeps its own sealer until a change of trystero's own adopts crypto | +| Genesis Task 32 (trystero's signer) | dropped by the owner, 2026-11-17 | its build half (Task 30a) is in version 0.1 | | Genesis Task 33 (the memory option beside Boost.Asio's SSL, libdatachannel and a TLS handshake) | stream M, task M3, **moved into crypto's own `test/openssl_memory/`** | it proves the option in any webcpp process that also holds Beast's TLS or libdatachannel's DTLS (webcpp::beast, webcpp::webrtc), not only trystero's; the owner's answer Q6 | | Genesis Task 34 (increment 3 whole) | stream M, task M4 | what is left of increment 3 is the memory option | | Genesis Tasks 15 and 16 (the memory option) | stream M, tasks M1 and M2 | Task 33 needs them, and D16 routes OpenSSL's per-call allocations through them | @@ -210,6 +210,13 @@ is the recommendation, and `../design.md` D32 to D34 and the genesis's design re `implemented` once version 0.1 and stream M are merged with the CI green on both `main`s; the nightly level and NIST's archives (O2, O3) go with it if decided by then, or move to a change of their own. +- **Q8. The memory option is native only (2026-11-17).** OpenSSL's memory option (genesis Tasks + 15, 16, 33 and 34) is refused on every WebAssembly target, WASI included (wasip2, wasip3 and + Emscripten). `/webcpp/crypto//openssl` is a separate matter: OpenSSL builds on WASI, so the + alias is refused on Emscripten alone. +- **Q9. Size tooling reaches every target (2026-11-17, C36).** The superproject's release-only + `webcpp.size-table` extends from Emscripten page programs to plain linked programs on every + target; crypto's own lane `sizes` (foundation Task 11') builds on that. - Still open from before: O1 (a ZIP-215 verifier), O2 (the nightly level), O3 (NIST's archives), and the genesis's O5 departure C17 (C16, a throughput workflow, falls away with D32). diff --git a/libraries/crypto/openspec/changes/foundation/specs/crypto/spec.md b/libraries/crypto/openspec/changes/foundation/specs/crypto/spec.md index 73c407c..3666f46 100644 --- a/libraries/crypto/openspec/changes/foundation/specs/crypto/spec.md +++ b/libraries/crypto/openspec/changes/foundation/specs/crypto/spec.md @@ -59,7 +59,7 @@ No macro SHALL change a default: the library MUST NOT read `WEBCPP_CRYPTO_PROFIL - **THEN** its backend is libsodium, as without the define ### Requirement: Measurements: references from release builds that decide nothing -The own lane `sizes` SHALL build the baseline program and one program per (family, backend) through the superproject's `webcpp.size-table`, which requires `release`, on native, wasip2, wasip3 and Emscripten, and the documentation's size matrix MUST be generated from its table. Throughput MUST be measured only from programs built at `variant=release`, by a collect script that refuses any other program or data, and published as a dated page that names the machines. No size or throughput MAY decide a default, an order of backends or an API. +The own lane `sizes` SHALL build the baseline program and one program per (family, backend) through the superproject's `webcpp.size-table`, which requires `release` and, by the owner's decision of 2026-11-17 (C36), reaches plain linked programs on every target and not only Emscripten page programs (foundation Task 11'), on native, wasip2, wasip3 and Emscripten, and the documentation's size matrix MUST be generated from its table. Throughput MUST be measured only from programs built at `variant=release`, by a collect script that refuses any other program or data, and published as a dated page that names the machines. No size or throughput MAY decide a default, an order of backends or an API. #### Scenario: A debug build is offered to the throughput page - **WHEN** the collect script is given a program built at `variant=debug` diff --git a/libraries/crypto/openspec/changes/genesis/design.md b/libraries/crypto/openspec/changes/genesis/design.md index 9597c29..a9438ba 100644 --- a/libraries/crypto/openspec/changes/genesis/design.md +++ b/libraries/crypto/openspec/changes/genesis/design.md @@ -54,7 +54,8 @@ Constraints every decision below works within, from the superproject's rulebook - An incremental `open` (a later increment may add it only with the plaintext withheld until the tag verifies), an incremental ChaCha20-Poly1305, tags shorter than 16 bytes. - A Botan build for WebAssembly, which is a later increment's if a user needs it. -- OpenSSL on WebAssembly, or the memory option anywhere but native. +- OpenSSL on Emscripten, or the memory option anywhere but native (never on a WebAssembly target, + WASI included). - The CI's three levels as a whole: this plan builds only the nightly level of the own lanes. - Routing Botan's allocations through the user's allocator: Botan 3.13.0 offers no hook. @@ -220,6 +221,9 @@ adapter functions that store each block's size in a header. The resource is neve because OpenSSL frees through it after `main`, and on Windows with a shared libcrypto after every static destructor. Every `make` of the backend checks that the functions are webcpp's and otherwise returns `memory_functions_not_installed`; a missing definition is a link error. +The option is native only and `config.hpp` refuses it on every WebAssembly target, WASI included +(wasip2, wasip3 and Emscripten), by the owner's decision of 2026-11-17; OpenSSL itself still builds +on WASI, and `/webcpp/crypto//openssl` is refused on Emscripten alone. - **Why a function the program defines:** OpenSSL's hook carries no user data, so any other form would keep the resource in a global variable of webcpp's, which the rulebook forbids; Boost @@ -340,7 +344,7 @@ foundation's design D32 to D35 hold the decisions shared with it. trystero's repository into crypto's own `test/openssl_memory/` (the option beside Boost.Asio's SSL, libdatachannel and a TLS handshake, which webcpp::beast's and webcpp::webrtc's programs are too), and Task 34 as its close: stream M of the roadmap, beside the foundation's - increments 1 and 2. Tasks 31 and 32 (trystero's sealer, `random` and signer) are dropped; + increments 1 and 2. Tasks 31 and 32 (trystero's sealer, `random` and signer: the migration) are dropped by the owner, 2026-11-17; trystero keeps its code until a change of trystero's own adopts crypto. - **Increment 4** (Task 35) is built in the foundation's increment 1 as its Task 8b, over the foundation's `ciphers::aead`, whose `aead_state` and `aead_engine` replace @@ -404,8 +408,8 @@ foundation's design D32 to D35 hold the decisions shared with it. ## Migration Plan Nothing to migrate: version 0.1 moved trystero's build onto `/third_party//secp256k1` (Task -30a, its code unchanged), and the owner dropped the rest of trystero's migration on 2026-11-17 -(D23). A later change of trystero's own may adopt `aes256_gcm`, `random_device` and +30a, its code unchanged), and trystero's migration onto the library (Tasks 31 and 32) was +dropped by the owner, 2026-11-17 (D23); no step of it remains. A later change of trystero's own may adopt `aes256_gcm`, `random_device` and `curves::secp256k1::keypair`; the plan's Tasks 31 and 32 stay as its reference. To resume (details in `reference/STATUS.md`): the order is the foundation's diff --git a/libraries/crypto/openspec/changes/genesis/proposal.md b/libraries/crypto/openspec/changes/genesis/proposal.md index ab0a5da..7c7bd3f 100644 --- a/libraries/crypto/openspec/changes/genesis/proposal.md +++ b/libraries/crypto/openspec/changes/genesis/proposal.md @@ -57,7 +57,8 @@ foundation change in one order (`design.md` D23, and the foundation's `reference `BCryptGenRandom` on Windows), no generator in user space, no weaker fallback. - **OpenSSL's memory functions are an option of the config:** with `WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE` a program names a `std::pmr::memory_resource` and - every allocation of OpenSSL in the process goes to it. Without the option OpenSSL's and + every allocation of OpenSSL in the process goes to it; the option is native only and refused on + every WebAssembly target, WASI included. Without the option OpenSSL's and Botan's `make` allocate outside the program's allocator, a departure the owner accepted. - **webcpp::trystero** names `/third_party//secp256k1` since version 0.1 (its build alone); its sealer, entropy and signer are not changed by this library's work (the owner's decision diff --git a/libraries/crypto/openspec/changes/genesis/reference/plan.md b/libraries/crypto/openspec/changes/genesis/reference/plan.md index 1f9b8d2..a754ec2 100644 --- a/libraries/crypto/openspec/changes/genesis/reference/plan.md +++ b/libraries/crypto/openspec/changes/genesis/reference/plan.md @@ -37,7 +37,7 @@ the decision. Measured tables come only from release builds. | 22 | the foundation's Task 11' (task 1.11): the own lane `sizes` through `webcpp.size-table`, which requires `release`; throughput measured by hand by a collect script that refuses a program or data not built at `variant=release`; no `runners.yml`, no ranking; nothing decides a default | | 23 | the foundation's increment 4 (task 4.4), Chrome's throughput from release builds | | 25b, 9's NIST half | stream N, behind gates O2 and O3 | -| 31, 32 | **dropped**; kept as the reference of a future change of trystero's own | +| 31, 32 | **dropped by the owner, 2026-11-17**; kept as the reference of a future change of trystero's own | | 33 | stream M, **moved into crypto's own tests** (below) | | 34 | stream M's close (below) | | 35 | the foundation's Task 8b (task 1.8b), re-cut onto `ciphers::aead` | @@ -5548,7 +5548,9 @@ option's own change; before it runs, re-read it against the source-built provide `/webcpp/third_party//openssl` and named through `/webcpp/crypto//openssl` (Task 11), version 3.5.9, on native, wasip2 and wasip3; the feature `webcpp-crypto-openssl-link`, `OPENSSL_ROOT` and the shared link it names are gone; the error values 13 and 14 are reserved and undeclared; -and the measured counts are 3.6.4's. +and the measured counts are 3.6.4's. The option itself is native only and is refused on every +WebAssembly target, WASI included (wasip2, wasip3 and Emscripten), by the owner's decision of +2026-11-17; only `/webcpp/crypto//openssl` is refused on Emscripten alone. **Files:** - Modify: `include/webcpp/crypto/backends/openssl.hpp`. @@ -5962,7 +5964,9 @@ option's own change; before it runs, re-read it against the source-built provide `/webcpp/third_party//openssl` and named through `/webcpp/crypto//openssl` (Task 11), version 3.5.9, on native, wasip2 and wasip3; the feature `webcpp-crypto-openssl-link`, `OPENSSL_ROOT` and the shared link it names are gone; the error values 13 and 14 are reserved and undeclared; -and the measured counts are 3.6.4's. +and the measured counts are 3.6.4's. The option itself is native only and is refused on every +WebAssembly target, WASI included (wasip2, wasip3 and Emscripten), by the owner's decision of +2026-11-17; only `/webcpp/crypto//openssl` is refused on Emscripten alone. **Files:** - Create, in `test/openssl_memory/`: `support.hpp` (the counting resource that is never @@ -10581,6 +10585,8 @@ still moves trystero's code onto webcpp::crypto later; Task 32 Step 3's build ha # Increment 3: trystero's migration +**Dropped by the owner, 2026-11-17** (Tasks 31 and 32 below, and this increment's precondition, are not built; Task 30a's build half is merged in version 0.1). The text below stays as the reference of a future change of trystero's own, and the plan's numbering is kept. + **Deferred after version 0.1 (revision of 2026-11-14).** Kept as written; before it starts, re-read it against the tree of that day. Already true at the revision: trystero's shared-connection change has integrated (the precondition below holds, but its table of call @@ -10626,7 +10632,7 @@ Before Task 31 starts: ## Task 31: trystero seals with `aes256_gcm` directly, and draws from `random_device` -**Dropped** by the owner's decision of 2026-11-17 (the revision of that day); kept as the reference of a future change of trystero's own. +**Dropped by the owner, 2026-11-17** (the revision of that day); kept as the reference of a future change of trystero's own. **Files (in `libs/trystero`):** - Create: `include/webcpp/trystero/detail/sealer.hpp`, `test/sealer_test.cpp`. @@ -10876,7 +10882,7 @@ private: ## Task 32: trystero signs with `secp256k1::keypair`, and libsecp256k1 comes from `third_party` -**Dropped** by the owner's decision of 2026-11-17 (the revision of that day); its build half is Task 30a, merged in version 0.1. +**Dropped by the owner, 2026-11-17** (the revision of that day); its build half is Task 30a, merged in version 0.1. **Files (in `libs/trystero`):** - Modify: `include/webcpp/trystero/protocol/nostr.hpp` (`signer`, `verify`), @@ -10973,7 +10979,8 @@ inline bool verify(std::span sig, std::spanWEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE`, a macro of the config as `WEBCPP_CRYPTO_DEFAULT_BACKEND_` is (section 5), for native builds - only. It is given to every target of the program that includes a header of + only, refused on every WebAssembly target, WASI included. It is given to every target of the program that includes a header of webcpp::crypto, its own libraries included, and every target that gets it names `/webcpp/crypto//openssl`: the project's requirements carry both, `WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE /webcpp/crypto//openssl`, and a @@ -1183,8 +1187,12 @@ limits. import table's `__imp_CRYPTO_malloc`, which exists only with the shared link, is decorated differently on x86, and is a reserved name; it answers for any DLL name and either link. OpenSSL names its defaults through no API of its own, and calling the functions to see - would allocate, which clears the flag. The Windows branch is unmeasured: section 8.5's MSVC - lane runs the `late` and `foreign` tests on the shared and the static link. The header + would allocate, which clears the flag. The Windows branch is unmeasured, and the tree departs from it (R5): + webcpp builds OpenSSL static only, so the branch could never run in a test, and a libcrypto + DLL (a program built without b2) is refused with `memory_functions_refused`; the departure + is recorded in the superproject's CODING-GUIDELINES.md, chapter 19, and serving such a + program takes this branch back, never measured. Section 8.5's MSVC lane runs the `late` and + `foreign` tests on the static link. The header includes `` for it through ``, under `NOMINMAX` and `WIN32_LEAN_AND_MEAN` (section 2.2), with `lint-world:` and its reason (AGENTS:641-649). @@ -1256,7 +1264,16 @@ limits. functions of a message allocate nothing (above), so a failing resource cannot reach them. **A failure during OpenSSL's first initialisation is permanent:** OpenSSL then stays unusable for the rest of the process, and every later `make` gives `backend_failure` - (above). A bounded resource is sized for the first `make`: 6,061 allocations, 192 + (above), on a single-threaded OpenSSL. On a threaded OpenSSL (MSVC's always), a resource that fails during + OpenSSL's base initialisation is unrecoverable, since OpenSSL re-enters its own + initialisation: the resource must serve OpenSSL's start-up. On a single-threaded OpenSSL, + when the failing allocation is OpenSSL's base initialisation (OpenSSL 3.5.9: its first + lock, `crypto/init.c:66`), OpenSSL never registers its cleanup, and `OPENSSL_cleanup` frees nothing (`init.c:384`): the blocks + it took meanwhile stay in use in the resource until the process ends (2,206 on macOS and + 2,262 on Linux for one `make`, measured 2026-11-17), and the thread's error queue takes no + entry afterwards either. The test `fail_init` pins this on a single-threaded OpenSSL and prints how many blocks stay; + its threaded twin `fail_init_threads` (built with `multi`) checks that the first + `make` takes blocks of the resource. A bounded resource is sized for the first `make`: 6,061 allocations, 192 reallocations and 4,621 blocks still live after it, with OpenSSL's configuration file read (PROBE-R3, OpenSSL 3.6.4 on macOS; other versions and configurations differ). - **What the program's resource must be:** @@ -1276,7 +1293,7 @@ limits. - **Where it exists, and the layers that stop a wrong build.** The option exists where the OpenSSL backend does, natively (section 3.3). `config.hpp` refuses it (layer 1, section 4.3; new text, with its tests, section 8.6): - - on WebAssembly: `webcpp::crypto: WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE configures OpenSSL, a native backend, and this program is built for WebAssembly. Remove that define from the program's Jamfile.` + - on WebAssembly: `webcpp::crypto: WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE is an option of native programs, and this program is built for WebAssembly. Remove that define from the program's Jamfile.` - natively, without `WEBCPP_CRYPTO_HAS_OPENSSL`: `webcpp::crypto: WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE routes OpenSSL's allocations, and OpenSSL is not linked. In the program's Jamfile, add /webcpp/crypto//openssl beside /webcpp/crypto//crypto, or remove that define. (without b2: define WEBCPP_CRYPTO_HAS_OPENSSL=1 and link libcrypto)` **A missing definition is a link error** (crypto-r3-review I2). Under the option every @@ -1603,8 +1620,7 @@ be read and checked by anyone, and documented (DESIGN, 2026-10-11 "entropy, safe This is the section of the library's documentation for its users. Every Jamfile line and every printed result in it was built and run with b2 on native (clang-darwin), clang-wasip2, clang-wasip3 and Emscripten (C-LIBS:527-542, PROBES `jam/app//Jamfile`), except the new -error texts of sections 3.7, 4.3 and 4.4, and the memory option of section 7.3, whose OpenSSL -calls PROBE-R3 ran natively without b2 and whose interface is not built yet. The C++ of the +error texts of sections 3.7, 4.3 and 4.4. The C++ of the programs follows section 2's interface; the probes ran the same programs on the prototype's sketch (`jam/crypto/include`), whose `seal` wrote the tag into a span, whose key type was `schnorr_key`, and whose ctaes backend was a free function, `backends::ctaes::aes256_encrypt` (`jam/app/ctaes/block.cpp`). @@ -1720,8 +1736,8 @@ things below; section 3.7 says why each is needed. builds only: `config.hpp` stops a target that has the define without OpenSSL, or that is built for WebAssembly, with an `#error` (section 7.7). Carrying `/webcpp/crypto//openssl` in the same requirements is what keeps every target that gets the define linked with OpenSSL, - a tool or a library that only uses `random_device` or `equal` included (this form is not - yet built with b2; section 7's introduction): + a tool or a library that only uses `random_device` or `equal` included (the fixture + `memory_option` builds and runs this form with b2, natively): project app : requirements WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE @@ -1804,8 +1820,10 @@ What to know: library of the program's that includes the backend's header has its own copy of webcpp's functions, and its `make` returns `memory_functions_not_installed`. - When the resource cannot allocate: during the first `make` of the process, OpenSSL's own - initialisation fails, and OpenSSL stays unusable for the rest of the process (`make` gives - `backend_failure` from then on); later, `make` gives `not_enough_memory` or + initialisation fails, and OpenSSL stays unusable for the rest of the process (on a + single-threaded OpenSSL `make` gives `backend_failure` from then on; on a threaded OpenSSL, + MSVC's always, a resource failing during OpenSSL's base initialisation is unrecoverable, + so the resource must serve OpenSSL's start-up); later, `make` gives `not_enough_memory` or `backend_failure`. `seal` and `open` allocate nothing. A resource with a fixed size needs room for the first `make`: about 6,100 allocations, 4,621 of them still live afterwards, with OpenSSL 3.6.4 on macOS (section 3.7). Without exceptions, a resource that throws ends @@ -1913,7 +1931,7 @@ int main() { | Name in the Jamfile | Library | Targets | Options | What it exports | | ------------------------- | ------------------------------------------------------- | ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | `/third_party//bearssl` | BearSSL, built from source | native, emscripten, wasip2, wasip3 | none | `gcm>` (`aes256_gcm` by default on WebAssembly, and natively without OpenSSL), `chacha20_poly1305`; BearSSL's whole C API through `` | -| `/webcpp/crypto//openssl` | OpenSSL 3.5.9's libcrypto, built from source, static | native, wasip2, wasip3 | none; `WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE` with `/webcpp/crypto//openssl` in the project's requirements, natively only, OpenSSL's allocations in the program's resource (section 7.3) | `aes128/192/256`, `gcm<...>` (`aes256_gcm` by default natively when linked; on MSVC, wasip2 and wasip3 without assembly), `chacha20_poly1305`; OpenSSL's C API through `` | +| `/webcpp/crypto//openssl` | OpenSSL 3.5.9's libcrypto, built from source, static | native, wasip2, wasip3 | none; `WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE` with `/webcpp/crypto//openssl` in the project's requirements, natively only (refused on wasip2, wasip3 and Emscripten), OpenSSL's allocations in the program's resource (section 7.3) | `aes128/192/256`, `gcm<...>` (`aes256_gcm` by default natively when linked; on MSVC, wasip2 and wasip3 without assembly), `chacha20_poly1305`; OpenSSL's C API through `` | | `/third_party//secp256k1` | libsecp256k1 v0.8.0, built from source, every module on | native, emscripten, wasip2, wasip3 | `auto` (default: small on Emscripten, large elsewhere), `small` or `large` | `webcpp::crypto::curves::secp256k1::keypair` (BIP340, ECDSA, ECDH), `verify_schnorr`, `verify_ecdsa` in ``; the C API of `` and its modules: ecdh, recovery, extrakeys, schnorrsig, musig, ellswift, silentpayments | | `/third_party//ctaes` | ctaes as Bitcoin Core v31.1 ships it, built from source | native, emscripten, wasip2, wasip3 | none | `aes128/192/256` in ``: the AES block cipher alone, constant time, no mode; the C API of ``, `AES128/192/256_init`, `_encrypt`, `_decrypt` | | `/third_party//botan` | Botan 3, found on the system | native only, for now | `shared` (default) or `static`; `-sBOTAN_ROOT=` | `aes128/192/256`, `gcm<...>`, `chacha20_poly1305`, only in a build with exceptions; Botan's C++ API | @@ -1938,7 +1956,7 @@ At compile time, the first error is the one to read: the lines after it | `webcpp::crypto: the backend Botan needs exceptions, and this program is built without them. ...` | Build with exceptions, or name BearSSL or OpenSSL. | | `/third_party//botan: ...` on WebAssembly (from b2), or `webcpp::crypto: Botan is a native backend ...` (without b2) | Name `/third_party//bearssl`: Botan is native only for now. | | Botan not found for a program, or a wrong `-sBOTAN_ROOT=` (from b2; the texts come with increment 5, section 4.4) | Install Botan, or give `-sBOTAN_ROOT=`, the directory of its `include/` and `lib/`, or use BearSSL or OpenSSL (section 4.4). | -| `webcpp::crypto: WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE configures OpenSSL, a native backend, and this program is built for WebAssembly. ...` | Remove `WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE` from the WebAssembly build: give that build a project of its own, without the define and OpenSSL, naming `/third_party//bearssl` (section 7.3). On WebAssembly the backend is BearSSL, which allocates nothing. | +| `webcpp::crypto: WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE is an option of native programs, and this program is built for WebAssembly. ...` | Remove `WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE` from the WebAssembly build: give that build a project of its own, without the define and OpenSSL, naming `/third_party//bearssl` (section 7.3). On WebAssembly the backend is BearSSL, which allocates nothing. | | `webcpp::crypto: WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE routes OpenSSL's allocations, and OpenSSL is not linked. ...` | A target has the define and not OpenSSL: put `/webcpp/crypto//openssl` in the same project requirements as the define (section 7.3), or remove the define. | | `Undefined symbols ...: "webcpp::crypto::openssl_memory_resource()"`, at link time (ld64, PROBE-R3; GNU ld and MSVC's `link.exe` name the same function in their own forms, which the link test of section 8.6 fixes) | The program sets `WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE`, uses the OpenSSL backend (any `make`, or the install) and does not define the function: define `std::pmr::memory_resource& webcpp::crypto::openssl_memory_resource() noexcept` once, returning a resource that is never destroyed, as in section 7.3. | | `LNK2038: mismatch detected for 'webcpp_crypto_openssl_memory'` (MSVC) | Some files of the program were compiled with `WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE` and some without: give the define in the requirements of the program's project, with OpenSSL beside it, `project app : requirements WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE /webcpp/crypto//openssl ;`, so that every target of the program gets both (natively only; section 7.3). | @@ -1950,7 +1968,7 @@ what to do (section 3.7): | --- | --- | | `memory_functions_refused`, from `install_memory_functions()`: "OpenSSL's memory functions cannot be installed: OpenSSL has already allocated, or another party installed its own. ..." | Make the call the first statement of `main`. If it is already, a static object of another library used OpenSSL, or called `CRYPTO_set_mem_functions`, before `main`: remove that use, or drop the option. | | `memory_functions_not_installed`, from `make` on OpenSSL: "OpenSSL's memory functions are not webcpp::crypto's. ..." | Call `install_memory_functions()` first in `main`, and check that nothing else in the process calls `CRYPTO_set_mem_functions`. If the `make` is in a DLL or a shared library of the program's, move the code that uses the OpenSSL backend into the module that calls the install (section 3.7). | -| `backend_failure` from every `make` on OpenSSL, under the option, after the resource failed once early in the process | The resource could not allocate during OpenSSL's first initialisation, which OpenSSL does not retry: the process cannot use OpenSSL any more. Give the resource room for the first `make` (section 7.3) and restart. | +| `backend_failure` from every `make` on OpenSSL, under the option, after the resource failed once early in the process (single-threaded OpenSSL; a threaded one cannot recover from a failing base initialisation) | The resource could not allocate during OpenSSL's base initialisation, which OpenSSL does not retry: the process cannot use OpenSSL any more. Give the resource room for the first `make` (section 7.3) and restart. | At link time, a symbol whose name is the instruction reports a backend library that is missing, or that is of another commit or configuration than the headers. With b2 this cannot @@ -2211,9 +2229,12 @@ parts on `chacha20_poly1305` land with it, in increment 4 (section 9). (crypto-r3-review mode `failsecond`); its second allocation fails: `make` gives `backend_failure` (from `EVP_EncryptInit_ex`); - in a program of its own, the first allocation after the install fails, inside OpenSSL's - first initialisation: `make` gives `backend_failure`, and so does a `make` after the - resource has stopped failing, which is the permanence section 3.7 documents - (crypto-r3-review mode `failinit`); + first initialisation: `make` gives `backend_failure`, and, on a single-threaded OpenSSL, so + does a `make` after the resource has stopped failing, which is the permanence section 3.7 + documents (crypto-r3-review mode `failinit`; the test `fail_init`); its threaded twin + `fail_init_threads`, built with `multi`, checks that the first `make` takes + blocks of the resource, since a threaded OpenSSL does not recover from a failing base + initialisation; - before each `make`, the test raises an entry of its own in the thread's queue, and after it the queue holds that entry alone, whatever `make` returned (`ERR_set_mark`, section 3.3); diff --git a/libraries/crypto/openspec/changes/genesis/specs/crypto/spec.md b/libraries/crypto/openspec/changes/genesis/specs/crypto/spec.md index e0f36dc..8efa7d5 100644 --- a/libraries/crypto/openspec/changes/genesis/specs/crypto/spec.md +++ b/libraries/crypto/openspec/changes/genesis/specs/crypto/spec.md @@ -432,10 +432,10 @@ Every call into Botan SHALL sit in one `try`: `Botan::Invalid_Authentication_Tag - **THEN** the second equals BearSSL's seal of that message with none ### Requirement: Memory option: the define and where it exists -The option SHALL be `WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE`, a macro of the config, for native builds only, given to every target of the program that includes a header of the library, its own libraries included, and every target that gets it MUST name `/webcpp/crypto//openssl`: the project's requirements carry `WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE /webcpp/crypto//openssl`, and a WebAssembly build is a project of its own, without the define, naming `/third_party//bearssl`. `config.hpp` MUST refuse it on WebAssembly with "webcpp::crypto: WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE configures OpenSSL, a native backend, and this program is built for WebAssembly. Remove that define from the program's Jamfile." and natively without `WEBCPP_CRYPTO_HAS_OPENSSL` with "webcpp::crypto: WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE routes OpenSSL's allocations, and OpenSSL is not linked. In the program's Jamfile, add /webcpp/crypto//openssl beside /webcpp/crypto//crypto, or remove that define. (without b2: define WEBCPP_CRYPTO_HAS_OPENSSL=1 and link libcrypto)". +The option SHALL be `WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE`, a macro of the config, for native builds only (refused on every WebAssembly target, WASI included: wasip2, wasip3 and Emscripten), given to every target of the program that includes a header of the library, its own libraries included, and every target that gets it MUST name `/webcpp/crypto//openssl`: the project's requirements carry `WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE /webcpp/crypto//openssl`, and a WebAssembly build is a project of its own, without the define, naming `/third_party//bearssl`. `config.hpp` MUST refuse it on every WebAssembly target, wasip2, wasip3 and Emscripten alike, with "webcpp::crypto: WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE is an option of native programs, and this program is built for WebAssembly. Remove that define from the program's Jamfile." and natively without `WEBCPP_CRYPTO_HAS_OPENSSL` with "webcpp::crypto: WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE routes OpenSSL's allocations, and OpenSSL is not linked. In the program's Jamfile, add /webcpp/crypto//openssl beside /webcpp/crypto//crypto, or remove that define. (without b2: define WEBCPP_CRYPTO_HAS_OPENSSL=1 and link libcrypto)". -#### Scenario: The option on wasip2 -- **WHEN** a wasip2 program is built with the define +#### Scenario: The option on every WebAssembly target +- **WHEN** a wasip2, wasip3 or Emscripten program is built with the define - **THEN** compilation stops with the first text ### Requirement: Memory option: a resource the program defines @@ -486,11 +486,11 @@ The adapter SHALL be three functions, `extern "C"`, `inline`, `noexcept` and of - **THEN** the results are null, null, a copy, a copy, null with `p` freed, and null with the old block still valid ### Requirement: Memory option: exceptions and a failing resource -With exceptions each call into the resource SHALL sit in a `try` whose `catch (...)` returns null, because no exception may cross OpenSSL's C; without exceptions there MUST be no `try`, a resource that throws ends the process at the adapter's `noexcept`, and only a resource that returns null reports a failure. `make` on a failing resource MUST return `not_enough_memory` (from `EVP_CIPHER_CTX_new`) or `backend_failure` (from `EVP_EncryptInit_ex`) by the call that failed; a failure during OpenSSL's first initialisation is permanent for the process, and every later `make` returns `backend_failure`. `seal` and `open` MUST allocate nothing, so a failing resource cannot reach them. +With exceptions each call into the resource SHALL sit in a `try` whose `catch (...)` returns null, because no exception may cross OpenSSL's C; without exceptions there MUST be no `try`, a resource that throws ends the process at the adapter's `noexcept`, and only a resource that returns null reports a failure. `make` on a failing resource MUST return `not_enough_memory` (from `EVP_CIPHER_CTX_new`) or `backend_failure` (from `EVP_EncryptInit_ex`) by the call that failed; a failure during OpenSSL's first initialisation is permanent for the process, and on a single-threaded OpenSSL every later `make` returns `backend_failure`; on a threaded OpenSSL (MSVC's always) a resource failing during OpenSSL's base initialisation is unrecoverable, since OpenSSL re-enters its own initialisation, so the resource MUST serve OpenSSL's start-up. `seal` and `open` MUST allocate nothing, so a failing resource cannot reach them. #### Scenario: The first allocation after the install fails - **WHEN** the first allocation after the install fails, inside OpenSSL's first initialisation -- **THEN** `make` returns `backend_failure`, and so does a `make` after the resource has stopped failing +- **THEN** `make` returns `backend_failure`, and, on a single-threaded OpenSSL, so does a `make` after the resource has stopped failing (on a threaded OpenSSL the failure is unrecoverable: the resource must serve OpenSSL's base initialisation) ### Requirement: Memory option: what it routes Under the option every allocation of the libcrypto the program links, in the whole process (Beast's TLS and libdatachannel's DTLS included), SHALL go through the program's resource, `CRYPTO_zalloc`, `CRYPTO_aligned_alloc`, `CRYPTO_clear_realloc` and `CRYPTO_clear_free` included; it MUST NOT claim to route OpenSSL's secure heap (only if the program calls `CRYPTO_secure_malloc_init`) nor the C library's own allocations inside functions OpenSSL calls, such as the `FILE` and buffer of the configuration file (one or two blocks, by C library). Nothing else in the process MAY call `CRYPTO_set_mem_functions`, and the option does nothing for Botan, BearSSL, ctaes and libsecp256k1. diff --git a/libraries/crypto/openspec/changes/genesis/tasks.md b/libraries/crypto/openspec/changes/genesis/tasks.md index 409d2a0..a03e093 100644 --- a/libraries/crypto/openspec/changes/genesis/tasks.md +++ b/libraries/crypto/openspec/changes/genesis/tasks.md @@ -47,8 +47,8 @@ foundation change's `reference/roadmap.md`.** `reference/STATUS.md` says how to Tasks 3.1 and 3.2 are stream M with group 4. Tasks 3.3 to 3.5 are built by the foundation change (its tasks 1.14a and 1.14, 1.11, and 4.4); they are checked here when those are. -- [ ] 3.1 OpenSSL's memory functions, an option of the config: the adapter and the install (plan: Task 15; stream M) -- [ ] 3.2 The memory option, process by process (plan: Task 16; stream M) +- [ ] 3.1 OpenSSL's memory functions, an option of the config: the adapter and the install (plan: Task 15; stream M; native only, refused on every WebAssembly target, WASI included) +- [ ] 3.2 The memory option, process by process (plan: Task 16; stream M; native only, refused on every WebAssembly target, WASI included) - [ ] 3.3 Constant time: Valgrind, MemorySanitizer and dudect, over version 0.1's backends (plan: Task 20; built as the foundation's tasks 1.14a and 1.14) - [ ] 3.4 Sizes from release builds through `webcpp.size-table`, throughput measured by hand from release builds, deciding nothing; no `runners.yml` (plan: Task 22, re-cut; built as the foundation's task 1.11) - [ ] 3.5 The browser: WebCrypto as an outside oracle, the audio worklet, throughput in Chrome from release builds (plan: Task 23; built as the foundation's task 4.4) @@ -57,11 +57,11 @@ change (its tasks 1.14a and 1.14, 1.11, and 4.4); they are checked here when tho ## 4. After version 0.1: increment 3, the memory option without trystero's migration (stream M) -Tasks 31 and 32 (trystero's sealer, `random` and signer) are dropped by the owner's decision of -2026-11-17 (`design.md` D23); they stay in the plan as the reference of a future change of +Tasks 31 and 32 (trystero's sealer, `random` and signer; the plan's "Increment 3: trystero's +migration") are dropped by the owner, 2026-11-17 (`design.md` D23); they stay in the plan as the reference of a future change of trystero's own. -- [ ] 4.3 The memory option beside Boost.Asio's SSL, libdatachannel and a TLS handshake, in crypto's own `test/openssl_memory/` (plan: Task 33, moved by the revision of 2026-11-17; the owner's answer Q6) +- [ ] 4.3 The memory option beside Boost.Asio's SSL, libdatachannel and a TLS handshake, in crypto's own `test/openssl_memory/` (plan: Task 33, moved by the revision of 2026-11-17; the owner's answer Q6; native only, refused on every WebAssembly target, WASI included) - [ ] 4.4 Increment 3 whole: green, review, the pull requests (plan: Task 34) ## 5. After version 0.1: increment 4, ChaCha20-Poly1305 (built by the foundation, version 0.2)