diff --git a/CODING-GUIDELINES.md b/CODING-GUIDELINES.md index 842fbc4..16d6fa6 100644 --- a/CODING-GUIDELINES.md +++ b/CODING-GUIDELINES.md @@ -340,19 +340,19 @@ A webcpp library that builds on a C library (webcpp::crypto on BearSSL and libsecp256k1, for example) brings it in this way, so that the C code stays exactly its authors' and the program carries only what it calls. -1. The C library is a submodule under `third_party/libs/`, pinned at a - commit and never edited. When upstream is not on GitHub, an unmodified +1. The C library is a submodule under `third_party/libs/`, pinned at an + upstream commit and never edited. When upstream is not on GitHub, a `webcpporg/` mirror stands in (BearSSL's is `webcpporg/bearssl`), - refreshed only when the pin moves. One exception, a security fix upstream - does not have yet: a branch `webcpp` of the mirror carries upstream's - commit and the fix, one commit each, pinned there and carried to each new - pin until upstream has it. The fix is minimal, preserves every value the - library computes, and is reported upstream (an owner item). A library - whose upstream is not mirrored under webcpporg takes such a fix the same - way, in a `webcpporg/` fork created for it, with the same `webcpp` - branch rule. BearSSL's has one, of 2026-11-21: ECDSA decodes RFC 6979's - nonce at its full length, so that signing does not branch on the nonce's - bit length (chapter 15, webcpp::crypto's P-256). + refreshed only when the pin moves. webcpp never modifies third-party code: + a defect found in a dependency is reported to the owner, who submits the + fix upstream. Until upstream applies it, the pin may point at our fork's + branch carrying exactly that submitted patch and nothing else, and it + returns to upstream once the patch is applied. BearSSL is pinned so: + `ae63032` of `webcpporg/bearssl`'s branch + `upstream/ecdsa-bits2int-constant-time`, upstream's `7bea48e` and the ECDSA + nonce fix submitted upstream (owner decision of 2026-12-02, which + superseded the exception of 2026-11-21 that let a mirror's `webcpp` branch + carry a fix of webcpp's own). 2. `third_party/Jamfile` builds it from its own sources, file by file, as a static library, in the library's own C dialect, on every target and with every file: a file that does not apply to a target still compiles, to the @@ -984,9 +984,9 @@ update --init third_party/libs/`; a build that needs none never looks. | Target | What it is | Licence | | --- | --- | --- | -| `bearssl` | BearSSL from webcpp's mirror `webcpporg/bearssl` at `32381d6`, its branch `webcpp`: upstream's `7bea48e` and one fix, ECDSA's nonce decoded at its full length (chapter 5 rule 1); a static library built file by file by `third_party/Jamfile` with webcpp::crypto's and webcpp::hash's canaries (hash's when `libs/hash` is checked out), on every target; `WEBCPP_CRYPTO_HAS_BEARSSL=1`, and `WEBCPP_HASH_HAS_BEARSSL=1` with hash's canary | MIT | +| `bearssl` | BearSSL at `ae63032` of webcpp's fork `webcpporg/bearssl`, branch `upstream/ecdsa-bits2int-constant-time`: upstream's `7bea48e` and exactly the ECDSA nonce fix submitted upstream, until upstream applies it (chapter 5 rule 1); a static library built file by file by `third_party/Jamfile` with webcpp::crypto's and webcpp::hash's canaries (hash's when `libs/hash` is checked out), on every target; `WEBCPP_CRYPTO_HAS_BEARSSL=1`, and `WEBCPP_HASH_HAS_BEARSSL=1` with hash's canary | MIT | | `bips` | `bitcoin/bips` at `927b6de9`, shallow, test data: crypto's tests read BIP340's `bip-0340/test-vectors.csv` and BIP341's `bip-0341/wallet-test-vectors.json` at run time under the directory its define `WEBCPP_TEST_BIPS` gives, on every target (wasmtime is given it, `webcpp.data`), and run again when it changes | BSD-2-Clause, as BIP340's header states | -| `bitcoin_base58_vectors` | Bitcoin Core's base58 vectors, `src/test/data/base58_encode_decode.json` of the submodule `third_party/libs/bitcoin` (Bitcoin Core v31.1 at `9be056a`, shallow), test data that nothing compiles: codecs' tests read it at run time under the directory its define `WEBCPP_TEST_BITCOIN_BASE58_VECTORS` gives, on every target (wasmtime is given it, `webcpp.data`), and run again when it changes | MIT | +| `bitcoin_base58_vectors` | Bitcoin Core's base58 vectors, `src/test/data/base58_encode_decode.json` and `src/test/data/key_io_valid.json` of the submodule `third_party/libs/bitcoin` (Bitcoin Core v31.1 at `9be056a`, shallow), test data that nothing compiles: codecs' tests (the first file) and hash's Base58Check test (the second) read them at run time under the directory its define `WEBCPP_TEST_BITCOIN_BASE58_VECTORS` gives, on every target (wasmtime is given it, `webcpp.data`), and run again when either changes | MIT | | `blake2_vectors` | BLAKE2's reference code package `BLAKE2/BLAKE2` at `ed1974e` (2023-02-12), the submodule `third_party/libs/blake2`, shallow, test data that nothing compiles: hash's tests read `testvectors/blake2b-kat.txt` and `testvectors/blake2-kat.json` at run time under the directory its define `WEBCPP_TEST_BLAKE2_VECTORS` gives, on every target (wasmtime is given it, `webcpp.data`), and run again when one of them changes | CC0-1.0 | | `blake3` | BLAKE3 1.8.7 at `f3149ec`; `third_party/Jamfile` compiles `c/blake3.c`, `blake3_dispatch.c` and `blake3_portable.c` on every target, the intrinsics files on their instruction sets alone (an exception to chapter 5 rule 2), with webcpp::hash's canary; `WEBCPP_HASH_HAS_BLAKE3=1` | CC0-1.0, Apache-2.0, or Apache-2.0 with LLVM exception | | `blake3_vectors` | BLAKE3's official vectors, `test_vectors/test_vectors.json` of the submodule `third_party/libs/blake3` at `f3149ec`, test data: hash's tests read it at run time under the directory its define `WEBCPP_TEST_BLAKE3_VECTORS` gives, on every target (wasmtime is given it, `webcpp.data`), and run again when it changes | CC0-1.0, Apache-2.0, or Apache-2.0 with LLVM exception | @@ -7222,7 +7222,8 @@ since that change); what is decided and not built is in chapter 17. creates libsecp256k1's context in it with `secp256k1_context_preallocated_create`, aligned to `alignof(std::max_align_t)`, and randomizes it from `random_device`; - `crypto::verify` with `crypto::schnorr` and `crypto::ecdsa_sha256` uses + `crypto::verify` with `crypto::signing_schemes::schnorr` and + `crypto::signing_schemes::ecdsa_sha256` uses `secp256k1_context_static` after `secp256k1_selftest()` on every call and allocates nothing.** The resource serves the context alone, so that the counting test sees every allocation; @@ -7234,15 +7235,25 @@ since that change); what is decided and not built is in chapter 17. point. Source: `libraries/crypto/openspec/changes/genesis/reference/spec.md` section 2.8 (proposals). -- **ECDSA's DER is strict (`to_der`, `from_der`, at most 72 bytes) and - `normalize_low_s` gives the low-S form; the x-only tweak takes any 32-byte - tweak, as a free `tweak_xonly` on an x-only key, giving the key and its - parity, and as `keypair::tweak_xonly` in place, and a tweak not below the - group order is `invalid_secret_key` and wipes the key pair.** A wallet's - needs without a protocol's rules: the caller computes BIP341's TapTweak, - and BIP341's vectors test the tweak that way. - Source: `libraries/crypto/openspec/changes/genesis/design.md` (proposals); - `test/secp256k1_xonly_tweak_test.cpp` (libs/crypto). +- **ECDSA's DER is strict (`formats::der`, BIP66, at most 72 bytes) and + an ECDSA signature's `low_s()` gives the low-S form; the x-only tweak takes + any 32-byte tweak, as `xonly_public_key::tweak_add` on the typed x-only key, + giving the key and its parity, which `verify_tweak` checks, and as + `keypair::tweak_xonly` in place, and a tweak not below the group order is + `invalid_secret_key` and wipes the key pair.** A wallet's needs without a + protocol's rules: the caller computes BIP341's TapTweak, and BIP341's vectors + test the tweak that way. + Source: `libraries/crypto/openspec/changes/genesis/design.md`, + `libraries/crypto/openspec/changes/formats/design.md` D12 (proposals); + `test/secp256k1_xonly_tweak_test.cpp`, `test/secp256k1_xonly_key_test.cpp` + (libs/crypto). +- **secp256k1's x-only public key is a type, `xonly_public_key`, never unset + (no default constructor: libsecp256k1 aborts on an unset key); + `crypto::verify` of `schnorr` takes it or a `public_key`, and no 32-byte + span.** Verification is typed; x-only bytes that are protocol data stay + bytes. + Source: `libraries/crypto/openspec/changes/formats/design.md` D12, R30 + (proposals); `test/secp256k1_xonly_key_test.cpp` (libs/crypto). **P-256 (the foundation's increment 3, its first part; built on the branch `crypto/p256`, merged 2026-11-22).** @@ -7263,30 +7274,40 @@ since that change); what is decided and not built is in chapter 17. (proposals); `include/webcpp/crypto/curves/p256.hpp` and `backends/bearssl.hpp` (libs/crypto). - **The key formats are fixed layouts: SPKI of 91 bytes (RFC 5480, the - uncompressed point) and PKCS#8 of 138 bytes (version 0, RFC 5915's - ECPrivateKey version 1 without parameters and with the public key); a - decoder accepts exactly what the encoder writes, the point checked against - the scalar.** The bytes OpenSSL's and BearSSL's encoders and node's - WebCrypto write, checked by the oracles; anything else is - `invalid_encoding`. + uncompressed point), or 59 around the compressed point, and PKCS#8 of 138 + bytes (version 0, RFC 5915's ECPrivateKey version 1 without parameters and + with the public key); a decoder accepts exactly what the encoder writes, the + point checked against the scalar; a compressed point is decompressed by + BearSSL's internal i31 integers, a square root modulo p on public data, + since BearSSL decodes uncompressed points alone.** The bytes OpenSSL's and + BearSSL's encoders and node's WebCrypto write, checked by the oracles; + anything else is `invalid_encoding`. Source: `include/webcpp/crypto/curves/p256/formats.hpp` (libs/crypto). -- **ECDSA signs low S on both curves; P-256's verification accepts both - forms, as FIPS 186-5 and WebCrypto do, and secp256k1's refuses a high S.** - P-256's `sign` normalizes RFC 6979's S after signing, selecting n - s by a - mask without a branch; `normalize_low_s` gives the low form of a signature - made elsewhere and `is_low_s` answers whether one is low, neither calling a - backend. A protocol that requires low S of its peers (Trystero's - handshakes) checks `is_low_s` before `crypto::verify`; the protocol itself - is webcpp::trystero's (D24), which the guide's section on signed handshakes - shows with an example. Their verdict is marked public for the constant-time - checkers, a signature being public once made. +- **ECDSA signs low S on both curves; every verification takes a mandatory + policy after the scheme, which each scheme declares: P-256's ECDSA + `crypto::verification_policies::low_s_only` or `any_s` (both forms, as FIPS + 186-5 and WebCrypto accept), secp256k1's ECDSA and `recover` `low_s_only`, + Ed25519 and BIP340 `canonical`; another policy, or none, stops the build + with the accepted ones.** P-256's `sign` normalizes RFC 6979's S after + signing, selecting n - s by a mask without a branch, and `low_s_only` + refuses a high S before BearSSL; an ECDSA signature's `low_s()` gives the + low form of a signature made elsewhere and `is_low_s()` answers whether one + is low, those of P-256 calling no backend. A protocol that requires low S of + its peers (Trystero's handshakes) verifies under `low_s_only`, a browser's + or a passkey's signature under `any_s`; the protocol itself is + webcpp::trystero's (D24), which the guide's section on signed handshakes + shows with an example. + Their verdict is marked public for the constant-time checkers, a signature + being public once made. Source: `include/webcpp/crypto/curves/p256.hpp`, `doc/p2p.adoc` (libs/crypto); `libraries/crypto/openspec/changes/unified-sign/design.md` - D3 and D4b (proposals). + D3 and D4b, `libraries/crypto/openspec/changes/formats/design.md` D9 + (proposals). - **One name per signing operation, the scheme always named: `key.sign(scheme, - input)` and `crypto::verify(scheme, signature, input, public_key)`, and - their `async_` forms, on Ed25519, P-256 and secp256k1; a digest only as - `crypto::prehashed{digest}`; every key pair a `crypto::keypair`, with a + input)` and `crypto::verify(scheme, policy, signature, input, public_key)`, + and their `async_` forms, on Ed25519, P-256 and secp256k1; a digest only as + `crypto::signing_schemes::prehashed{digest}`; every key pair a + `crypto::keypair`, with a typed public key and `secret()`.** A span is a message whatever its size, so a 32-byte message is never read as a digest; a pair of scheme and input that is not valid stops the build with its reason. `Backend` is the first @@ -7323,7 +7344,7 @@ since that change); what is decided and not built is in chapter 17. 1 to 14, D1 to D12 (proposals). - **Constant time, sizes and throughput cover the family.** memcheck and MemorySanitizer run the key pair's making, signing with its low-S - normalization and check, `agree` and `decode_pkcs8` (`paths.hpp`), each + normalization and check, `agree` and the PKCS#8 decode (`paths.hpp`), each checker failing on a planted early exit in a copy of the scalar check; BearSSL's own branches on its signing's verdicts are listed for memcheck in `bearssl_verdicts.supp`. dudect times `sign` and `agree` against the @@ -7334,16 +7355,24 @@ since that change); what is decided and not built is in chapter 17. Linux container (`linux-lint:arm64`, clang 18, Valgrind 3.22), the lane's CI command: both found upstream BearSSL's signing branching on the RFC 6979 nonce's bit length, `br_ecdsa_i31_bits2int` decoding it with its actual - length and `br_i31_rshift` looping by it (a Minerva-class leak), and nothing - once webcpp's BearSSL carried the fix, one commit setting the order's length - before the shift (chapter 5 rule 1); the planted programs failed and dudect - passed there too: dudect judged P-256's signing with its low-S step (|t| - 1.70 on Linux, 1.63 natively on an Apple M5 Max, release, one run each; - provisional, measured again in the final quiet pass). + length and `br_i31_rshift` looping by it (a Minerva-class leak). From + 2026-11-21 to 2026-12-02 webcpp's BearSSL carried a fix of its own on the + mirror's `webcpp` branch and the checkers found nothing; the owner decision + of 2026-12-02 (chapter 5 rule 1) replaced it with the same fix submitted + upstream: BearSSL is pinned at `ae63032` of `webcpporg/bearssl`'s branch + `upstream/ecdsa-bits2int-constant-time`, upstream's `7bea48e` and that one + patch, until upstream applies it, and the checkers find nothing under it + (2026-12-02). The planted + programs failed and dudect passed there too: dudect judged P-256's signing + with its low-S step (|t| 1.70 on Linux, 1.63 natively on an Apple M5 Max, + release, one run each; provisional, measured again in the final quiet + pass). Source: `libs/crypto/test/constant_time/Jamfile`, `test/sizes/Jamfile`, `bench/throughput.cpp`, `doc/backends.adoc` (libs/crypto); - https://github.com/webcpporg/bearssl/commit/32381d6e787a32cbb7a687246349200d78b8ff7c - (the fix) and BearSSL's `src/ec/ecdsa_i31_bits.c` at `7bea48e` (upstream). + BearSSL's `src/ec/ecdsa_i31_bits.c` at `7bea48e` (upstream) and at + `ae63032` (`webcpporg/bearssl`, the patch submitted upstream); the + superseded fix's commits, `32381d6` and `205c5ff` of the mirror's `webcpp` + branch, are history. **Errors and exceptions.** @@ -7369,15 +7398,16 @@ since that change); what is decided and not built is in chapter 17. measured, a port is a new thing to review. Source: `libraries/crypto/openspec/changes/genesis/design.md` D1 (proposals). -- **BearSSL comes from webcpp's mirror `webcpporg/bearssl`, upstream's code - with one security fix on its branch `webcpp` (chapter 5 rule 1); its - notice ships as `LICENSE-BEARSSL.txt`, and webcpp's canary lives in the - library's `src/`. The backend names its code itself: the CTR class of - AES-NI, then POWER8, then `aes_ct64`, and GHASH by PCLMUL, then POWER8, - then `ghash_ctmul64`; the test seam `WEBCPP_CRYPTO_DETAIL_BEARSSL_PORTABLE` - keeps it on the portable pair.** On wasm32 BearSSL's own default would be - its 32-bit code; the seam lets the agreement test compare both of BearSSL's - code paths with OpenSSL's on x86-64. +- **BearSSL comes from webcpp's fork `webcpporg/bearssl`, upstream's code + and exactly the ECDSA nonce fix submitted upstream, until upstream applies + it (chapter 5 rule 1); its notice ships as `LICENSE-BEARSSL.txt`, + and webcpp's canary lives in the library's `src/`. The backend names its + code itself: the CTR class of AES-NI, then POWER8, then `aes_ct64`, and + GHASH by PCLMUL, then POWER8, then `ghash_ctmul64`; the test seam + `WEBCPP_CRYPTO_DETAIL_BEARSSL_PORTABLE` keeps it on the portable pair.** On + wasm32 BearSSL's own default would be its 32-bit code; the seam lets the + agreement test compare both of BearSSL's code paths with OpenSSL's on + x86-64. Source: `include/webcpp/crypto/backends/bearssl.hpp`, `test/agreement_gcm_portable_test.cpp` (libs/crypto). - **OpenSSL is the superproject's source-built OpenSSL 3.5.9, static, @@ -7655,7 +7685,7 @@ since that change); what is decided and not built is in chapter 17. - **The vectors run on every backend that has the algorithm: the GCM specification's cases and Wycheproof's AES-GCM files, sealed whole and in pieces; FIPS 197 for the block cipher; BIP340's vectors, Wycheproof's - Bitcoin ECDSA file and DER through `from_der`, and BIP341's wallet + Bitcoin ECDSA file and DER through `formats::der`, and BIP341's wallet vectors through the tweak.** Every case runs because keys of 24 bytes and nonces of any size up to 128 are accepted. Source: `test/Jamfile` (libs/crypto); `third_party/libs/wycheproof`, @@ -8782,8 +8812,9 @@ What webcpp does not have yet, and the chapters that mention it: randomness are webcpp::crypto's, and the relays' WebSockets Beast's. Trystero can then retain its protocol over those shared facilities. - **crypto after 0.1** (chapter 17): the browser lane, the CI's nightly - level, NIST CAVP's vectors and Botan. Its constant-time lane, its sizes and - throughput, and ChaCha20-Poly1305 merged with the foundation's increment 1. + level, NIST CAVP's vectors and Botan; its key formats on codecs are built, + not merged. Its constant-time lane, its sizes and throughput, and + ChaCha20-Poly1305 merged with the foundation's increment 1. - **The libraries web developers use most,** brought to C++: a JavaScript interpreter (QuickJS), libp2p, HTTP fetch. - **The site, increments 2 to 8.** Increment 1 is done: the site's @@ -8839,15 +8870,16 @@ What webcpp does not have yet, and the chapters that mention it: ## 17. Decided, not yet in chapters 14 and 15 The proposals the owner accepted whose decisions are not yet in chapter 14 or -15, each with its decisions as decided and its heading saying how much of it -the superproject's `main` holds: wasi's redesign and the site's increments 4 -and 5 are not built, codecs is built and not merged, crypto's foundation is -merged in part, and hash and secure are merged whole. While a proposal is open, its own `design.md` and -specification hold it in full and rule over this summary; the change that -builds it moves its decisions into chapter 14 or 15. Their conflicts with -chapters 1 to 13 are in chapter 19. +15, each with its decisions as decided and its heading saying how much of it the +superproject's `main` holds: wasi's redesign and the site's increments 4 and 5 +are not built, codecs and secure are merged, crypto's foundation is merged in +part and its formats change, with hash's Base58Check, is built and not merged, +and hash is merged but for its Base58Check. While a proposal is open, its own +`design.md` and specification hold it in full and rule over this summary; the +change that builds it moves its decisions into chapter 14 or 15. Their conflicts +with chapters 1 to 13 are in chapter 19. -### crypto, after 0.1 (genesis accepted 2026-10-11, foundation accepted 2026-11-14; the foundation's increments 1 and 2, increment 3's P-256 and increment 4's asynchronous family merged) +### crypto, after 0.1 (genesis accepted 2026-10-11, foundation accepted 2026-11-14; the foundation's increments 1 and 2, increment 3's P-256 and increment 4's asynchronous family merged; the formats change built, not merged) The genesis's plan (`reference/plan.md`, revised on 2026-11-14) built version 0.1 from its increments 1 and 2, and OpenSSL's memory option after it. The @@ -8971,6 +9003,58 @@ Tasks 3.1 to 3.6, merged 2026-11-22).** Source: `libraries/crypto/openspec/changes/foundation/reference/plan.md` Tasks 3.7 to 3.11 (proposals). +**The formats change (branch `crypto/formats` of the library and of the +superproject; built on codecs, not merged).** + +- **crypto's key formats are codecs formats: `crypto::formats::raw`, `spki`, + `pkcs8`, `der` and `pem(spki)` or `pem(pkcs8)` (RFC 7468's armor over the + DER), each with `codecs::value_codec` specializations in the curve's + `formats.hpp`, and the verbs `crypto::encode` and `crypto::decode` (and the + members `encode` and `T::decode`) that check the pair, then call codecs'.** A + pair a type does not have stops the build with the type's list of formats; one + list, `detail::all_formats`, feeds the checks, the tests and the page's table. + The old names (`encode_spki`, `to_der`, `crypto::pem`, the pem defaults, the + `max_*_size` constants) are removed, each with its replacement in the guide's + migration table (`doc/formats.adoc`); no name stays as an alias. A program + that uses one curve's formats includes that curve's formats header and pulls + no other curve. + Source: `libraries/crypto/openspec/changes/formats/design.md` D1 to D8 + (proposals); `doc/formats.adoc`, `doc/changelog.adoc` (libs/crypto). +- **secp256k1's x-only key is a type, `curves::secp256k1::xonly_public_key`, + with the formats of its own.** BIP340's key, made by `from_bytes` (32 bytes) + or taken from a `public_key::xonly()`, a key pair's `xonly_public_key()` + (with `xonly_parity()`) or MuSig2's `aggregate_key::xonly_public_key()`; it + has `bytes()` and an ordering, is checked by `verify` under `canonical`, and + is tweaked by `tweak_add` and checked by `verify_tweak`. Its `formats::raw` + is its 32 bytes; `raw(formats::xonly)` of a `public_key` writes the same 32 + bytes and encodes only, because 32 bytes are not that key: they decode into + the x-only key, and a `public_key` decode of them stops the build. + Source: `libraries/crypto/openspec/changes/formats/design.md` D12 + (proposals); `include/webcpp/crypto/curves/secp256k1/formats.hpp` + (libs/crypto). +- **Every verification takes a policy, `low_s_only`, `any_s` or `canonical` + (`crypto::verification_policies`), after the scheme, which + `crypto::signing_schemes` declares; P-256's decompression of a compressed + point is crypto's, on BearSSL's own i31 integers (owner decision of + 2026-12-01).** BearSSL decodes uncompressed points alone; the square root runs + on public data in `backends/bearssl.hpp`, through prototypes copied from + BearSSL's `inner.h` and pinned by a test that compiles both, with no C file of + crypto's. A secp256k1 key pair's raw, PKCS#8 and PEM decodes may throw where + exceptions exist, since its signing context allocates; + `keypair::decode(format, input, resource)` keeps the arena form of the removed + `decode_pkcs8`. + Source: `libraries/crypto/openspec/changes/formats/design.md` D5, D9 and + D12 (proposals, to be amended at delivery); + `include/webcpp/crypto/backends/bearssl.hpp` (libs/crypto). +- **hash's `hash::formats::base58_with_checksum` is Base58Check, the codecs + format `basic_base58<100, bitcoin_alphabet, hash::checksums::double_sha256>` + (branch `hash/base58-with-checksum`, not merged).** Bitcoin Core's vectors + test it (chapter 10's `bitcoin_base58_vectors`); a secret decode wipes its + scratch, and the library's wallet guide decodes a WIF key with it. hash + depends on codecs, never the reverse. + Source: `libraries/hash/openspec/changes/base58-with-checksum/design.md` + D1 to D4 (proposals); `doc/use-cases/cryptocurrencies.adoc` (libs/hash). + **Constant time (increment 1, Task 14; merged).** - **Constant time is checked deterministically on Linux x86-64 and arm64 @@ -9973,15 +10057,15 @@ delivery. `tools/test/crypto_jamfiles_test.py`, `tools/test/hash_jamfiles_test.py` (webcpp). -### codecs (bytes and values to text and back, and the conversion contract; own; accepted 2026-11-26, built, not merged) +### codecs (bytes and values to text and back, and the conversion contract; own; accepted 2026-11-26, merged) webcpp::codecs is webcpp's one contract for converting bytes and typed values to text and back, and any data through one-shot and stream transformers, with seven formats over it, webcpp's own (`"port-of": null`, categories String and Cryptography). It is implemented in `webcpporg/codecs`, the submodule `libs/codecs`, built on the branch `codecs/genesis` of its repository and of the -superproject and not merged: the owner's CI runs once, at the end, and the -merge follows it. Its headers are ``, the core, which +superproject and merged on 2026-11-30, after the owner's CI ran once, at the +end. Its headers are ``, the core, which registers no format and includes none, and ``, each format reachable only through its own header, with `detail/core/` and @@ -10052,8 +10136,9 @@ The owner's decisions: `basic_base58<100, bitcoin_alphabet, hash::checksums::double_sha256>` (decision 26 renames decision 7's `base58check`); crypto registers its key formats through `value_codec` in a change of its own, and `crypto::encode` and `crypto::decode` - no longer exist. Both are follow-ups, and hash will depend on codecs, never the - reverse. + are that change's verbs over codecs'. Both follow-ups are built (crypto's + `formats` change and hash's `base58-with-checksum`, chapter 17's crypto + entry), and hash depends on codecs, never the reverse. Source: design.md owner decisions 7 and 26 (proposals); `test/messages/base58_with_checksum_unseen` (libs/codecs). - **Owner decision 8: the tests.** RFC 4648 section 10, BIP-173's and BIP-350's diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 373c1bf..4b46b8a 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -58,8 +58,9 @@ Each line is a rule of CODING-GUIDELINES.md, named by its chapter. customize, and on emscripten a library uses what the browser offers (chapter 4). - **A C library is brought in as its authors wrote it:** a pinned submodule, - never edited (an unmodified `webcpporg` mirror when upstream is not on - GitHub), built file by file by webcpp's Jamfile with function sections, named + never edited (a `webcpporg` mirror when upstream is not on GitHub; our + fork's branch carrying exactly a fix submitted upstream, until upstream + applies it), built file by file by webcpp's Jamfile with function sections, named by the program in its own Jamfile (`/third_party//`), and guarded by a compile-time check, a link-time canary and, on MSVC, `detect_mismatch`, each saying what to add (chapter 5, "Bringing a C library into webcpp"). diff --git a/libs/crypto b/libs/crypto index 7b2c776..6052c7c 160000 --- a/libs/crypto +++ b/libs/crypto @@ -1 +1 @@ -Subproject commit 7b2c7769c9d45804e0e365bdce8e465df021c7cc +Subproject commit 6052c7c8df4e14cfa4b53441dc5cf7d7b48ca6e2 diff --git a/libs/hash b/libs/hash index d4d0119..33b8f9e 160000 --- a/libs/hash +++ b/libs/hash @@ -1 +1 @@ -Subproject commit d4d0119ca17ebde9faa00bb61352471d06a7eaa3 +Subproject commit 33b8f9e045399f29930c6db634fd221c36534e9b diff --git a/third_party/Jamfile b/third_party/Jamfile index 1d52dbf..887f329 100644 --- a/third_party/Jamfile +++ b/third_party/Jamfile @@ -278,16 +278,17 @@ rule crypto-checked-out ( properties * ) .c-library = $(.c-sections) @crypto-checked-out $(CRYPTO)/include ; -# BearSSL (MIT), from webcpp's fork webcpporg/bearssl, branch webcpp: upstream -# 7bea48e with one commit, ECDSA's nonce decoded at its full length so that -# signing does not branch on its bit length (CODING-GUIDELINES chapter 5, -# rule 1). Every .c of src/, the POWER8 ones too, which off POWER compile to -# the stubs other files call. One source of entropy, getentropy, with RDRAND -# and /dev/urandom off (libs/crypto's random_device reads the same source): -# wasi-libc and Emscripten declare getentropy only under _DEFAULT_SOURCE, and -# macOS only in , which src/rand/sysrng.c does not include. On -# Windows BearSSL's only seeder is CryptGenRandom, not the system's -# BCryptGenRandom, so every seeder is off there and BearSSL has none. +# BearSSL (MIT) at ae63032 of webcpp's fork webcpporg/bearssl, branch +# upstream/ecdsa-bits2int-constant-time: upstream's 7bea48e and exactly the +# ECDSA nonce fix submitted upstream, until upstream applies it +# (CODING-GUIDELINES chapter 5, rule 1). Every .c of src/, the POWER8 ones too, +# which off POWER compile to the stubs other files call. One source of entropy, +# getentropy, with RDRAND and /dev/urandom off (libs/crypto's random_device +# reads the same source): wasi-libc and Emscripten declare getentropy only +# under _DEFAULT_SOURCE, and macOS only in , which +# src/rand/sysrng.c does not include. On Windows BearSSL's only seeder is +# CryptGenRandom, not the system's BCryptGenRandom, so every seeder is off +# there and BearSSL has none. path-constant BEARSSL : libs/bearssl ; rule bearssl-checked-out ( properties * ) @@ -361,15 +362,17 @@ lib ctaes : libs/bitcoin/src/crypto/ctaes/ctaes.c $(CRYPTO)/src/canary_ctaes.c explicit ctaes ; # Bitcoin Core's base58 vectors (MIT), src/test/data/base58_encode_decode.json -# of the same submodule at the tag, read at run time by codecs' tests from the -# directory WEBCPP_TEST_BITCOIN_BASE58_VECTORS gives, on every target, as test -# data that nothing compiles. Quoted as blake3_vectors' define is, with +# and key_io_valid.json of the same submodule at the tag, read at run time by +# codecs' tests (the first) and by hash's Base58Check test (the second) from +# the directory WEBCPP_TEST_BITCOIN_BASE58_VECTORS gives, on every target, as +# test data that nothing compiles. Quoted as blake3_vectors' define is, with # forward slashes, so that a path with a space or a backslash survives. .bitcoin-base58-vectors = [ regex.replace $(BITCOIN)/src/test/data "\\\\" "/" ] ; alias bitcoin_base58_vectors : : @bitcoin-checked-out : : "\"WEBCPP_TEST_BITCOIN_BASE58_VECTORS=\\\"$(.bitcoin-base58-vectors)\\\"\"" [ webcpp.data $(BITCOIN)/src/test/data ] - libs/bitcoin/src/test/data/base58_encode_decode.json ; + libs/bitcoin/src/test/data/base58_encode_decode.json + libs/bitcoin/src/test/data/key_io_valid.json ; explicit bitcoin_base58_vectors ; # The precomputed tables of libsecp256k1 (spec section 3.5): auto (the diff --git a/third_party/libs/bearssl b/third_party/libs/bearssl index 32381d6..ae63032 160000 --- a/third_party/libs/bearssl +++ b/third_party/libs/bearssl @@ -1 +1 @@ -Subproject commit 32381d6e787a32cbb7a687246349200d78b8ff7c +Subproject commit ae63032d9f30bf53674db5445875adf71b8626b7 diff --git a/tools/ci/matrix.py b/tools/ci/matrix.py index 0970187..467c2a1 100755 --- a/tools/ci/matrix.py +++ b/tools/ci/matrix.py @@ -198,16 +198,17 @@ # native programs under Valgrind's memcheck (valgrind, with valgrind/memcheck.h) and under # MemorySanitizer, whose runtime and sanitizer/ headers are libclang-rt-18-dev's, and their # drivers read MemorySanitizer's frames with llvm-symbolizer-18, which llvm-18 installs; on -# wasip2 crypto's runs dudect alone, which needs none. codecs' fuzz lane links libFuzzer, -# AddressSanitizer and UndefinedBehaviorSanitizer, whose runtimes and sanitizer/ headers (the -# malloc hooks its targets count the heap with) are libclang-rt-18-dev's, and its sanitizers -# symbolise their reports with llvm-symbolizer-18. The lint, which analyses those programs -# natively, installs every package of the table (lint-packages). +# wasip2 crypto's runs dudect alone, which needs none. codecs' and crypto's fuzz lanes link +# libFuzzer, AddressSanitizer and UndefinedBehaviorSanitizer, whose runtimes and sanitizer/ headers +# (the malloc hooks their targets count the heap with) are libclang-rt-18-dev's, and their +# sanitizers symbolise their reports with llvm-symbolizer-18. The lint, which analyses those +# programs natively, installs every package of the table (lint-packages). OWN_LANE_PACKAGES: dict[tuple[str, str, str], tuple[str, ...]] = { ('crypto', 'constant-time', 'native'): ('valgrind', 'llvm-18', 'libclang-rt-18-dev'), ('secure', 'constant-time', 'native'): ('valgrind', 'llvm-18', 'libclang-rt-18-dev'), ('codecs', 'constant-time', 'native'): ('valgrind', 'llvm-18', 'libclang-rt-18-dev'), - ('codecs', 'fuzz', 'native'): ('llvm-18', 'libclang-rt-18-dev')} + ('codecs', 'fuzz', 'native'): ('llvm-18', 'libclang-rt-18-dev'), + ('crypto', 'fuzz', 'native'): ('llvm-18', 'libclang-rt-18-dev')} # MSVC's lanes build 64-bit programs, embed their manifest with the linker and abbreviate b2's # paths against Windows's MAX_PATH, as xstate-cpp's green Windows jobs did. b2 abbreviates each diff --git a/tools/ci/matrix_test.py b/tools/ci/matrix_test.py index bad0ab6..062329f 100755 --- a/tools/ci/matrix_test.py +++ b/tools/ci/matrix_test.py @@ -1338,24 +1338,28 @@ def test_an_own_lane_installs_its_packages(root): # its entry, by library, lane and target: crypto's, secure's and codecs' constant-time lanes # natively have Valgrind, llvm-18 (llvm-symbolizer-18, which reads MemorySanitizer's frames) and # libclang-rt-18-dev (clang-18's MemorySanitizer runtime and its sanitizer/ headers); - # crypto's on wasip2, where it runs dudect alone, none; codecs' fuzz lane natively llvm-18 and - # libclang-rt-18-dev (libFuzzer's and the sanitizers' runtimes, and the sanitizer/ header of - # the malloc hooks), and no Valgrind; every other own lane none. The own-lanes job installs - # them with apt on Linux, only where the list is not empty, before the lane runs. + # crypto's on wasip2, where it runs dudect alone, none; codecs' and crypto's fuzz lanes + # natively llvm-18 and libclang-rt-18-dev (libFuzzer's and the sanitizers' runtimes, and the + # sanitizer/ header of the malloc hooks), and no Valgrind; every other own lane none. The + # own-lanes job installs them with apt on Linux, only where the list is not empty, before the + # lane runs. packages = ('valgrind', 'llvm-18', 'libclang-rt-18-dev') fuzz_packages = ('llvm-18', 'libclang-rt-18-dev') assert matrix.OWN_LANE_PACKAGES == {('crypto', 'constant-time', 'native'): packages, ('secure', 'constant-time', 'native'): packages, ('codecs', 'constant-time', 'native'): packages, - ('codecs', 'fuzz', 'native'): fuzz_packages} + ('codecs', 'fuzz', 'native'): fuzz_packages, + ('crypto', 'fuzz', 'native'): fuzz_packages} boost_only(root) oracle_library(root, 'beta') harness.add_library(root, 'crypto', 'import webcpp ;\n' 'webcpp.targets native wasip2 ;\n' 'webcpp.run plain : plain.cpp ;\n' - 'webcpp.lane constant-time : plain : native wasip2 ;\n', - {'plain.cpp': 'int main() {}\n'}) + 'webcpp.run fuzzed : fuzzed.cpp ;\n' + 'webcpp.lane constant-time : plain : native wasip2 ;\n' + 'webcpp.lane fuzz : fuzzed : native ;\n', + {'plain.cpp': 'int main() {}\n', 'fuzzed.cpp': 'int main() {}\n'}) harness.add_library(root, 'secure', 'import webcpp ;\n' 'webcpp.targets native ;\n' @@ -1372,7 +1376,8 @@ def test_an_own_lane_installs_its_packages(root): {'plain.cpp': 'int main() {}\n', 'fuzzed.cpp': 'int main() {}\n'}) assert {entry.get('id', entry['lane']): entry['apt'] for entry in own_lanes(root)} == { 'oracle': [], 'native.crypto.constant-time': list(packages), - 'wasip2.crypto.constant-time': [], 'native.secure.constant-time': list(packages), + 'wasip2.crypto.constant-time': [], 'native.crypto.fuzz': list(fuzz_packages), + 'native.secure.constant-time': list(packages), 'native.codecs.constant-time': list(packages), 'native.codecs.fuzz': list(fuzz_packages)}, own_lanes(root) steps = job_steps(workflow_jobs()['own-lanes']) @@ -1389,7 +1394,8 @@ def test_the_lint_installs_the_own_lanes_packages(root): # The lint analyses every own lane's programs, natively with clang-18 on Linux, so it needs # their headers: lint-packages prints every package of OWN_LANE_PACKAGES once, sorted, the # one source (crypto's, secure's and codecs' constant-time lanes list the same three, and - # codecs' fuzz lane two of them), and the lint job installs them before the lint runs. + # codecs' and crypto's fuzz lanes two of them), and the lint job installs them before the lint + # runs. result = run(root, 'lint-packages') assert result.returncode == 0, (result.returncode, result.stderr) assert result.stdout == 'libclang-rt-18-dev llvm-18 valgrind\n', result.stdout diff --git a/tools/test/crypto_jamfiles_test.py b/tools/test/crypto_jamfiles_test.py index 6a23350..d36b791 100644 --- a/tools/test/crypto_jamfiles_test.py +++ b/tools/test/crypto_jamfiles_test.py @@ -30,8 +30,8 @@ def main(argv: list[str]) -> int: - return user_jamfiles.main('crypto_jamfiles', CASES, ('config', 'secure', 'crypto', 'hash'), - NOT_YET, argv) + return user_jamfiles.main('crypto_jamfiles', CASES, + ('config', 'secure', 'codecs', 'crypto', 'hash'), NOT_YET, argv) if __name__ == '__main__': diff --git a/tools/test/fixtures/crypto_jamfiles/canary_missing/canary_missing.outcome b/tools/test/fixtures/crypto_jamfiles/canary_missing/canary_missing.outcome index 6d58dbb..80b6e69 100644 --- a/tools/test/fixtures/crypto_jamfiles/canary_missing/canary_missing.outcome +++ b/tools/test/fixtures/crypto_jamfiles/canary_missing/canary_missing.outcome @@ -10,18 +10,18 @@ build: fails # tag::messages[] [native-darwin] contains: Undefined symbols for architecture -contains: _webcpp_crypto_bearssl_32381d6_getentropy__add_third_party_bearssl_to_your_link +contains: _webcpp_crypto_bearssl_ae63032_getentropy__add_third_party_bearssl_to_your_link [native-linux] -contains: webcpp_crypto_bearssl_32381d6_getentropy__add_third_party_bearssl_to_your_link -contains: undefined reference to `webcpp_crypto_bearssl_32381d6_getentropy__add_third_party_bearssl_to_your_link' +contains: webcpp_crypto_bearssl_ae63032_getentropy__add_third_party_bearssl_to_your_link +contains: undefined reference to `webcpp_crypto_bearssl_ae63032_getentropy__add_third_party_bearssl_to_your_link' [wasip2] contains: wasm-ld: error: -contains: undefined symbol: webcpp_crypto_bearssl_32381d6_getentropy__add_third_party_bearssl_to_your_link +contains: undefined symbol: webcpp_crypto_bearssl_ae63032_getentropy__add_third_party_bearssl_to_your_link [wasip3] contains: wasm-ld: error: -contains: undefined symbol: webcpp_crypto_bearssl_32381d6_getentropy__add_third_party_bearssl_to_your_link +contains: undefined symbol: webcpp_crypto_bearssl_ae63032_getentropy__add_third_party_bearssl_to_your_link [emscripten] contains: wasm-ld: error: -contains: undefined symbol: webcpp_crypto_bearssl_32381d6_getentropy__add_third_party_bearssl_to_your_link +contains: undefined symbol: webcpp_crypto_bearssl_ae63032_getentropy__add_third_party_bearssl_to_your_link contains: em++: error: # end::messages[] diff --git a/tools/test/fixtures/crypto_jamfiles/canary_other_configuration/canary_other_configuration.outcome b/tools/test/fixtures/crypto_jamfiles/canary_other_configuration/canary_other_configuration.outcome index de1d559..6cac727 100644 --- a/tools/test/fixtures/crypto_jamfiles/canary_other_configuration/canary_other_configuration.outcome +++ b/tools/test/fixtures/crypto_jamfiles/canary_other_configuration/canary_other_configuration.outcome @@ -10,18 +10,18 @@ build: fails # tag::messages[] [native-darwin] contains: Undefined symbols for architecture -contains: _webcpp_crypto_bearssl_32381d6_sysrng__add_third_party_bearssl_to_your_link +contains: _webcpp_crypto_bearssl_ae63032_sysrng__add_third_party_bearssl_to_your_link [native-linux] -contains: webcpp_crypto_bearssl_32381d6_sysrng__add_third_party_bearssl_to_your_link -contains: undefined reference to `webcpp_crypto_bearssl_32381d6_sysrng__add_third_party_bearssl_to_your_link' +contains: webcpp_crypto_bearssl_ae63032_sysrng__add_third_party_bearssl_to_your_link +contains: undefined reference to `webcpp_crypto_bearssl_ae63032_sysrng__add_third_party_bearssl_to_your_link' [wasip2] contains: wasm-ld: error: -contains: undefined symbol: webcpp_crypto_bearssl_32381d6_sysrng__add_third_party_bearssl_to_your_link +contains: undefined symbol: webcpp_crypto_bearssl_ae63032_sysrng__add_third_party_bearssl_to_your_link [wasip3] contains: wasm-ld: error: -contains: undefined symbol: webcpp_crypto_bearssl_32381d6_sysrng__add_third_party_bearssl_to_your_link +contains: undefined symbol: webcpp_crypto_bearssl_ae63032_sysrng__add_third_party_bearssl_to_your_link [emscripten] contains: wasm-ld: error: -contains: undefined symbol: webcpp_crypto_bearssl_32381d6_sysrng__add_third_party_bearssl_to_your_link +contains: undefined symbol: webcpp_crypto_bearssl_ae63032_sysrng__add_third_party_bearssl_to_your_link contains: em++: error: # end::messages[] diff --git a/tools/test/fixtures/crypto_jamfiles/canary_secp256k1_missing/app.cpp b/tools/test/fixtures/crypto_jamfiles/canary_secp256k1_missing/app.cpp index 9c74a12..c936e3b 100644 --- a/tools/test/fixtures/crypto_jamfiles/canary_secp256k1_missing/app.cpp +++ b/tools/test/fixtures/crypto_jamfiles/canary_secp256k1_missing/app.cpp @@ -18,5 +18,5 @@ int main() { std::array const message{}; std::array const aux{}; auto key = webcpp::crypto::curves::secp256k1::keypair::from_secret(secret); - return key && key->sign(webcpp::crypto::schnorr, message, aux) ? 0 : 1; + return key && key->sign(webcpp::crypto::signing_schemes::schnorr, message, aux) ? 0 : 1; } diff --git a/tools/test/fixtures/crypto_jamfiles/canary_secp256k1_small/app.cpp b/tools/test/fixtures/crypto_jamfiles/canary_secp256k1_small/app.cpp index 9c74a12..c936e3b 100644 --- a/tools/test/fixtures/crypto_jamfiles/canary_secp256k1_small/app.cpp +++ b/tools/test/fixtures/crypto_jamfiles/canary_secp256k1_small/app.cpp @@ -18,5 +18,5 @@ int main() { std::array const message{}; std::array const aux{}; auto key = webcpp::crypto::curves::secp256k1::keypair::from_secret(secret); - return key && key->sign(webcpp::crypto::schnorr, message, aux) ? 0 : 1; + return key && key->sign(webcpp::crypto::signing_schemes::schnorr, message, aux) ? 0 : 1; } diff --git a/tools/test/fixtures/crypto_jamfiles/canary_without/canary_without.outcome b/tools/test/fixtures/crypto_jamfiles/canary_without/canary_without.outcome index d693f32..d33df05 100644 --- a/tools/test/fixtures/crypto_jamfiles/canary_without/canary_without.outcome +++ b/tools/test/fixtures/crypto_jamfiles/canary_without/canary_without.outcome @@ -10,31 +10,31 @@ build: fails # tag::messages[] [native-darwin] contains: Undefined symbols for architecture -contains: _webcpp_crypto_bearssl_32381d6_getentropy__add_third_party_bearssl_to_your_link +contains: _webcpp_crypto_bearssl_ae63032_getentropy__add_third_party_bearssl_to_your_link [native-linux] -contains: webcpp_crypto_bearssl_32381d6_getentropy__add_third_party_bearssl_to_your_link -contains: undefined reference to `webcpp_crypto_bearssl_32381d6_getentropy__add_third_party_bearssl_to_your_link' +contains: webcpp_crypto_bearssl_ae63032_getentropy__add_third_party_bearssl_to_your_link +contains: undefined reference to `webcpp_crypto_bearssl_ae63032_getentropy__add_third_party_bearssl_to_your_link' [wasip2] contains: wasm-ld: error: -contains: undefined symbol: webcpp_crypto_bearssl_32381d6_getentropy__add_third_party_bearssl_to_your_link +contains: undefined symbol: webcpp_crypto_bearssl_ae63032_getentropy__add_third_party_bearssl_to_your_link [wasip3] contains: wasm-ld: error: -contains: undefined symbol: webcpp_crypto_bearssl_32381d6_getentropy__add_third_party_bearssl_to_your_link +contains: undefined symbol: webcpp_crypto_bearssl_ae63032_getentropy__add_third_party_bearssl_to_your_link [emscripten] contains: wasm-ld: error: -contains: undefined symbol: webcpp_crypto_bearssl_32381d6_getentropy__add_third_party_bearssl_to_your_link +contains: undefined symbol: webcpp_crypto_bearssl_ae63032_getentropy__add_third_party_bearssl_to_your_link contains: em++: error: # end::messages[] # The canary is the only link error (spec section 4.3): no line names an undefined symbol or # reference that is not it. Each linker's own words for one. [native-darwin] -not-contains: ", referenced from: unless webcpp_crypto_bearssl_32381d6_getentropy__add_third_party_bearssl_to_your_link +not-contains: ", referenced from: unless webcpp_crypto_bearssl_ae63032_getentropy__add_third_party_bearssl_to_your_link [native-linux] -not-contains: undefined reference unless webcpp_crypto_bearssl_32381d6_getentropy__add_third_party_bearssl_to_your_link +not-contains: undefined reference unless webcpp_crypto_bearssl_ae63032_getentropy__add_third_party_bearssl_to_your_link [wasip2] -not-contains: undefined symbol unless webcpp_crypto_bearssl_32381d6_getentropy__add_third_party_bearssl_to_your_link +not-contains: undefined symbol unless webcpp_crypto_bearssl_ae63032_getentropy__add_third_party_bearssl_to_your_link [wasip3] -not-contains: undefined symbol unless webcpp_crypto_bearssl_32381d6_getentropy__add_third_party_bearssl_to_your_link +not-contains: undefined symbol unless webcpp_crypto_bearssl_ae63032_getentropy__add_third_party_bearssl_to_your_link [emscripten] -not-contains: undefined symbol unless webcpp_crypto_bearssl_32381d6_getentropy__add_third_party_bearssl_to_your_link +not-contains: undefined symbol unless webcpp_crypto_bearssl_ae63032_getentropy__add_third_party_bearssl_to_your_link diff --git a/tools/test/fixtures/crypto_jamfiles/ed25519_default/app.cpp b/tools/test/fixtures/crypto_jamfiles/ed25519_default/app.cpp index 951f29c..0c98eb1 100644 --- a/tools/test/fixtures/crypto_jamfiles/ed25519_default/app.cpp +++ b/tools/test/fixtures/crypto_jamfiles/ed25519_default/app.cpp @@ -36,10 +36,13 @@ int main() { auto const key = ed25519::keypair::from_secret(seed); bool ok = false; if (key) { - auto const signature = key->sign(crypto::eddsa, message); + auto const signature = key->sign(crypto::signing_schemes::eddsa, message); auto const public_key = key->public_key(); - ok = signature && public_key && secure::constant_time_equal(signature->bytes(), expected) && - crypto::verify(crypto::eddsa, *signature, message, *public_key).has_value(); + ok = + signature && public_key && secure::constant_time_equal(signature->bytes(), expected) && + crypto::verify(crypto::signing_schemes::eddsa, crypto::verification_policies::canonical, + *signature, message, *public_key) + .has_value(); } auto const name = ed25519::keypair::backend_type::name; std::printf("ed25519 %s backend=%.*s\n", ok ? "ok" : "FAILED", static_cast(name.size()), diff --git a/tools/test/fixtures/crypto_jamfiles/ed25519_unknown_policy_on_emscripten/app.cpp b/tools/test/fixtures/crypto_jamfiles/ed25519_unknown_policy_on_emscripten/app.cpp index b4e74cd..201dfa3 100644 --- a/tools/test/fixtures/crypto_jamfiles/ed25519_unknown_policy_on_emscripten/app.cpp +++ b/tools/test/fixtures/crypto_jamfiles/ed25519_unknown_policy_on_emscripten/app.cpp @@ -4,8 +4,9 @@ // accompanying file LICENSE_1_0.txt or copy at // https://www.boost.org/LICENSE_1_0.txt) -// A program that names a policy of its own in Ed25519's crypto::verify, on its default backend -// linked, stops where it calls it, with the one policy there is. +// A program that names a policy of its own in Ed25519's crypto::verify, in the policy's place after +// the scheme, on its default backend linked, stops where it calls it, with the one policy Ed25519 +// takes. #include #include @@ -25,8 +26,8 @@ int main() { webcpp::crypto::curves::ed25519::public_key::from_bytes(std::array{}); webcpp::crypto::curves::ed25519::signature const signature{}; return public_key && - webcpp::crypto::verify(webcpp::crypto::eddsa, signature, - std::span{}, *public_key, lenient{}) + webcpp::crypto::verify(webcpp::crypto::signing_schemes::eddsa, lenient{}, + signature, std::span{}, *public_key) ? 0 : 1; } diff --git a/tools/test/fixtures/crypto_jamfiles/ed25519_unknown_policy_on_emscripten/ed25519_unknown_policy_on_emscripten.outcome b/tools/test/fixtures/crypto_jamfiles/ed25519_unknown_policy_on_emscripten/ed25519_unknown_policy_on_emscripten.outcome index 929fb29..97fdf99 100644 --- a/tools/test/fixtures/crypto_jamfiles/ed25519_unknown_policy_on_emscripten/ed25519_unknown_policy_on_emscripten.outcome +++ b/tools/test/fixtures/crypto_jamfiles/ed25519_unknown_policy_on_emscripten/ed25519_unknown_policy_on_emscripten.outcome @@ -12,5 +12,5 @@ targets: emscripten build: fails # tag::messages[] -contains: webcpp::crypto: Ed25519's only verification policy is curves::ed25519::strict. +contains: webcpp::crypto: verify: crypto::signing_schemes::eddsa and eddsa_prehashed take crypto::verification_policies::canonical. # end::messages[] diff --git a/tools/test/fixtures/crypto_jamfiles/encrypt_and_sign/app.cpp b/tools/test/fixtures/crypto_jamfiles/encrypt_and_sign/app.cpp index 41f84cf..987146f 100644 --- a/tools/test/fixtures/crypto_jamfiles/encrypt_and_sign/app.cpp +++ b/tools/test/fixtures/crypto_jamfiles/encrypt_and_sign/app.cpp @@ -50,14 +50,17 @@ int main() { auto pair = secp256k1::keypair::from_secret(secret); bool signed_ok = false; if (pair) { - auto const signature = pair->sign(webcpp::crypto::schnorr, message, aux); + auto const signature = pair->sign(webcpp::crypto::signing_schemes::schnorr, message, aux); auto const public_key = pair->public_key(); - signed_ok = - signature && public_key && - webcpp::crypto::verify(webcpp::crypto::schnorr, *signature, message, *public_key); + signed_ok = signature && public_key && + webcpp::crypto::verify(webcpp::crypto::signing_schemes::schnorr, + webcpp::crypto::verification_policies::canonical, + *signature, message, *public_key); message[0] ^= 1U; - signed_ok = signed_ok && !webcpp::crypto::verify(webcpp::crypto::schnorr, *signature, - message, *public_key); + signed_ok = + signed_ok && !webcpp::crypto::verify(webcpp::crypto::signing_schemes::schnorr, + webcpp::crypto::verification_policies::canonical, + *signature, message, *public_key); } std::printf("schnorr %s\n", signed_ok ? "ok" : "FAILED"); return sealed && opened && signed_ok ? 0 : 1; diff --git a/tools/test/fixtures/crypto_jamfiles/pem_default/Jamfile b/tools/test/fixtures/crypto_jamfiles/pem_default/Jamfile deleted file mode 100644 index dfe9afd..0000000 --- a/tools/test/fixtures/crypto_jamfiles/pem_default/Jamfile +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright (c) 2026 WebCpp.org -# -# Distributed under the Boost Software License, Version 1.0. (See -# accompanying file LICENSE_1_0.txt or copy at -# https://www.boost.org/LICENSE_1_0.txt) - -# tag::jamfile[] -exe app : app.cpp /webcpp/crypto//crypto /webcpp/crypto//pem-default ; -# end::jamfile[] diff --git a/tools/test/fixtures/crypto_jamfiles/pem_default/app.cpp b/tools/test/fixtures/crypto_jamfiles/pem_default/app.cpp deleted file mode 100644 index 3d28b7c..0000000 --- a/tools/test/fixtures/crypto_jamfiles/pem_default/app.cpp +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2026 WebCpp.org -// -// Distributed under the Boost Software License, Version 1.0. (See -// accompanying file LICENSE_1_0.txt or copy at -// https://www.boost.org/LICENSE_1_0.txt) - -// Reads RFC 8410's Ed25519 public key in PEM (section 10.1) on PEM's default backend, armours its -// DER again, checks that the text is the same, and prints the backend that ran. -#include - -#include -#include -#include -#include - -int main() { - namespace pem = webcpp::crypto::pem; - constexpr std::string_view text = - "-----BEGIN PUBLIC KEY-----\n" - "MCowBQYDK2VwAyEAGb9ECWmEzf6FQbrBZ9w7lshQhqowtrbLDFw4rXAxZuE=\n" - "-----END PUBLIC KEY-----\n"; - std::array der{}; - auto const read = pem::unarmour(pem::public_key_label, text, der); - std::array again{}; - auto const written = pem::armour(pem::public_key_label, der, again); - bool const ok = - read && *read == der.size() && written && std::string_view(again.data(), *written) == text; - auto const name = pem::algorithm<>::backend_type::name; - std::printf("pem %s backend=%.*s\n", ok ? "ok" : "FAILED", static_cast(name.size()), - name.data()); - return ok ? 0 : 1; -} diff --git a/tools/test/fixtures/crypto_jamfiles/pem_default/pem_default.outcome b/tools/test/fixtures/crypto_jamfiles/pem_default/pem_default.outcome deleted file mode 100644 index 8684e53..0000000 --- a/tools/test/fixtures/crypto_jamfiles/pem_default/pem_default.outcome +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright (c) 2026 WebCpp.org -# -# Distributed under the Boost Software License, Version 1.0. (See -# accompanying file LICENSE_1_0.txt or copy at -# https://www.boost.org/LICENSE_1_0.txt) - -[all] -targets: native wasip2 wasip3 emscripten -build: succeeds -run: app -# tag::output[] -[native] -pem ok backend=sodium -[wasip2] -pem ok backend=sodium -[wasip3] -pem ok backend=sodium -[emscripten] -pem ok backend=sodium -# end::output[] diff --git a/tools/test/fixtures/crypto_jamfiles/pem_default_not_linked_on_emscripten/Jamfile b/tools/test/fixtures/crypto_jamfiles/pem_default_not_linked_on_emscripten/Jamfile deleted file mode 100644 index 4b12ef4..0000000 --- a/tools/test/fixtures/crypto_jamfiles/pem_default_not_linked_on_emscripten/Jamfile +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright (c) 2026 WebCpp.org -# -# Distributed under the Boost Software License, Version 1.0. (See -# accompanying file LICENSE_1_0.txt or copy at -# https://www.boost.org/LICENSE_1_0.txt) - -# tag::jamfile[] -exe app : app.cpp /webcpp/crypto//crypto ; -# end::jamfile[] diff --git a/tools/test/fixtures/crypto_jamfiles/pem_default_not_linked_on_emscripten/app.cpp b/tools/test/fixtures/crypto_jamfiles/pem_default_not_linked_on_emscripten/app.cpp deleted file mode 100644 index f19bc16..0000000 --- a/tools/test/fixtures/crypto_jamfiles/pem_default_not_linked_on_emscripten/app.cpp +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) 2026 WebCpp.org -// -// Distributed under the Boost Software License, Version 1.0. (See -// accompanying file LICENSE_1_0.txt or copy at -// https://www.boost.org/LICENSE_1_0.txt) - -// A program that armours DER as PEM on its default backend, libsodium on every target, without -// linking it, stops where it calls it, with the line that links libsodium, the one backend that has -// it (design D32). -#include - -#include -#include - -int main() { - std::array const der{}; - std::array out{}; - return webcpp::crypto::pem::armour("A", der, out) ? 0 : 1; -} diff --git a/tools/test/fixtures/crypto_jamfiles/pem_default_not_linked_on_emscripten/pem_default_not_linked_on_emscripten.outcome b/tools/test/fixtures/crypto_jamfiles/pem_default_not_linked_on_emscripten/pem_default_not_linked_on_emscripten.outcome deleted file mode 100644 index 75a70e2..0000000 --- a/tools/test/fixtures/crypto_jamfiles/pem_default_not_linked_on_emscripten/pem_default_not_linked_on_emscripten.outcome +++ /dev/null @@ -1,16 +0,0 @@ -# Copyright (c) 2026 WebCpp.org -# -# Distributed under the Boost Software License, Version 1.0. (See -# accompanying file LICENSE_1_0.txt or copy at -# https://www.boost.org/LICENSE_1_0.txt) - -# The compiler's line of the refusal starts with the header's path on the machine, so the message is -# a contains: line. wasip2 and wasip3 have the same message in a compile-diagnostic -# (test/messages/pem_default_not_linked); compile-diagnostic is clang's and skips Emscripten, so -# this fixture is the Emscripten one. -[all] -targets: emscripten -build: fails -# tag::messages[] -contains: webcpp::crypto: PEM's default backend on this target is libsodium, which is not linked, and the one backend that has it there. Add /webcpp/crypto//pem-default, the default's library on every target, to the program's Jamfile, as in: exe app : app.cpp /webcpp/crypto//crypto /webcpp/crypto//pem-default ; (without b2: define WEBCPP_CRYPTO_HAS_SODIUM=1 and link libsodium built with webcpp's src/canary_sodium.c) -# end::messages[] diff --git a/tools/test/fixtures/crypto_jamfiles/secp256k1_default/app.cpp b/tools/test/fixtures/crypto_jamfiles/secp256k1_default/app.cpp index 477963b..013eadf 100644 --- a/tools/test/fixtures/crypto_jamfiles/secp256k1_default/app.cpp +++ b/tools/test/fixtures/crypto_jamfiles/secp256k1_default/app.cpp @@ -31,11 +31,13 @@ int main() { auto const key = secp256k1::keypair::from_secret(secret); bool ok = false; if (key) { - auto const signature = key->sign(webcpp::crypto::schnorr, message, aux); + auto const signature = key->sign(webcpp::crypto::signing_schemes::schnorr, message, aux); auto const public_key = key->public_key(); ok = signature && public_key && webcpp::secure::constant_time_equal(signature->bytes(), expected) && - webcpp::crypto::verify(webcpp::crypto::schnorr, *signature, message, *public_key); + webcpp::crypto::verify(webcpp::crypto::signing_schemes::schnorr, + webcpp::crypto::verification_policies::canonical, *signature, + message, *public_key); } auto const name = secp256k1::keypair::backend_type::name; std::printf("schnorr %s backend=%.*s\n", ok ? "ok" : "FAILED", static_cast(name.size()), diff --git a/tools/test/fixtures/crypto_jamfiles/secp256k1_musig_default/app.cpp b/tools/test/fixtures/crypto_jamfiles/secp256k1_musig_default/app.cpp index 21a3bd9..175c5ba 100644 --- a/tools/test/fixtures/crypto_jamfiles/secp256k1_musig_default/app.cpp +++ b/tools/test/fixtures/crypto_jamfiles/secp256k1_musig_default/app.cpp @@ -68,8 +68,9 @@ bool sign_and_verify(secp256k1::keypair const& first, secp256k1::keypair const& } std::array const parts{*first_part, *second_part}; auto const signature = musig::partial_signature_aggregate(*session, parts, space); - return signature && webcpp::crypto::verify(webcpp::crypto::schnorr, *signature, message, - aggregate->xonly_public_key()); + return signature && webcpp::crypto::verify(webcpp::crypto::signing_schemes::schnorr, + webcpp::crypto::verification_policies::canonical, + *signature, message, aggregate->xonly_public_key()); } } // namespace diff --git a/tools/test/fixtures/crypto_jamfiles/sign/sign.cpp b/tools/test/fixtures/crypto_jamfiles/sign/sign.cpp index 335fcf0..30de116 100644 --- a/tools/test/fixtures/crypto_jamfiles/sign/sign.cpp +++ b/tools/test/fixtures/crypto_jamfiles/sign/sign.cpp @@ -22,13 +22,16 @@ int main() { auto key = secp256k1::keypair::from_secret(secret); bool ok = false; if (key) { - auto const signature = key->sign(webcpp::crypto::schnorr, message, aux); + auto const signature = key->sign(webcpp::crypto::signing_schemes::schnorr, message, aux); auto const public_key = key->public_key(); ok = signature && public_key && - webcpp::crypto::verify(webcpp::crypto::schnorr, *signature, message, *public_key); + webcpp::crypto::verify(webcpp::crypto::signing_schemes::schnorr, + webcpp::crypto::verification_policies::canonical, *signature, + message, *public_key); message[0] ^= 1U; - ok = ok && - !webcpp::crypto::verify(webcpp::crypto::schnorr, *signature, message, *public_key); + ok = ok && !webcpp::crypto::verify(webcpp::crypto::signing_schemes::schnorr, + webcpp::crypto::verification_policies::canonical, + *signature, message, *public_key); } std::printf("schnorr %s\n", ok ? "ok" : "FAILED"); return ok ? 0 : 1; diff --git a/tools/test/fixtures/crypto_jamfiles/sign_small/sign.cpp b/tools/test/fixtures/crypto_jamfiles/sign_small/sign.cpp index 335fcf0..30de116 100644 --- a/tools/test/fixtures/crypto_jamfiles/sign_small/sign.cpp +++ b/tools/test/fixtures/crypto_jamfiles/sign_small/sign.cpp @@ -22,13 +22,16 @@ int main() { auto key = secp256k1::keypair::from_secret(secret); bool ok = false; if (key) { - auto const signature = key->sign(webcpp::crypto::schnorr, message, aux); + auto const signature = key->sign(webcpp::crypto::signing_schemes::schnorr, message, aux); auto const public_key = key->public_key(); ok = signature && public_key && - webcpp::crypto::verify(webcpp::crypto::schnorr, *signature, message, *public_key); + webcpp::crypto::verify(webcpp::crypto::signing_schemes::schnorr, + webcpp::crypto::verification_policies::canonical, *signature, + message, *public_key); message[0] ^= 1U; - ok = ok && - !webcpp::crypto::verify(webcpp::crypto::schnorr, *signature, message, *public_key); + ok = ok && !webcpp::crypto::verify(webcpp::crypto::signing_schemes::schnorr, + webcpp::crypto::verification_policies::canonical, + *signature, message, *public_key); } std::printf("schnorr %s\n", ok ? "ok" : "FAILED"); return ok ? 0 : 1; diff --git a/tools/test/fixtures/hash_jamfiles/canary_bearssl_missing/canary_bearssl_missing.outcome b/tools/test/fixtures/hash_jamfiles/canary_bearssl_missing/canary_bearssl_missing.outcome index 20202ed..591a0f4 100644 --- a/tools/test/fixtures/hash_jamfiles/canary_bearssl_missing/canary_bearssl_missing.outcome +++ b/tools/test/fixtures/hash_jamfiles/canary_bearssl_missing/canary_bearssl_missing.outcome @@ -9,17 +9,17 @@ targets: native wasip2 wasip3 emscripten build: fails [native-darwin] contains: Undefined symbols for architecture -contains: _webcpp_hash_bearssl_32381d6_getentropy__add_third_party_bearssl_to_your_link +contains: _webcpp_hash_bearssl_ae63032_getentropy__add_third_party_bearssl_to_your_link [native-linux] -contains: webcpp_hash_bearssl_32381d6_getentropy__add_third_party_bearssl_to_your_link -contains: undefined reference to `webcpp_hash_bearssl_32381d6_getentropy__add_third_party_bearssl_to_your_link' +contains: webcpp_hash_bearssl_ae63032_getentropy__add_third_party_bearssl_to_your_link +contains: undefined reference to `webcpp_hash_bearssl_ae63032_getentropy__add_third_party_bearssl_to_your_link' [wasip2] contains: wasm-ld: error: -contains: undefined symbol: webcpp_hash_bearssl_32381d6_getentropy__add_third_party_bearssl_to_your_link +contains: undefined symbol: webcpp_hash_bearssl_ae63032_getentropy__add_third_party_bearssl_to_your_link [wasip3] contains: wasm-ld: error: -contains: undefined symbol: webcpp_hash_bearssl_32381d6_getentropy__add_third_party_bearssl_to_your_link +contains: undefined symbol: webcpp_hash_bearssl_ae63032_getentropy__add_third_party_bearssl_to_your_link [emscripten] contains: wasm-ld: error: -contains: undefined symbol: webcpp_hash_bearssl_32381d6_getentropy__add_third_party_bearssl_to_your_link +contains: undefined symbol: webcpp_hash_bearssl_ae63032_getentropy__add_third_party_bearssl_to_your_link contains: em++: error: diff --git a/tools/test/hash_jamfiles_test.py b/tools/test/hash_jamfiles_test.py index 067fe98..f9f499c 100644 --- a/tools/test/hash_jamfiles_test.py +++ b/tools/test/hash_jamfiles_test.py @@ -99,7 +99,7 @@ def message_faults(cases: list[Path]) -> list[str]: def main(argv: list[str]) -> int: return user_jamfiles.main('hash_jamfiles', CASES, - ('config', 'secure', 'hash', 'crypto', 'asio'), NOT_YET, + ('config', 'secure', 'codecs', 'hash', 'crypto', 'asio'), NOT_YET, argv, message_faults) diff --git a/tools/test/third_party_test.py b/tools/test/third_party_test.py index 094327b..5d189ee 100755 --- a/tools/test/third_party_test.py +++ b/tools/test/third_party_test.py @@ -52,9 +52,10 @@ BEARSSL = 'third_party/libs/bearssl' -# The commit BearSSL is pinned at: webcpporg/bearssl's webcpp branch, upstream 7bea48e with one -# fix (ECDSA decodes the RFC 6979 nonce at its full length). -BEARSSL_COMMIT = '32381d6e787a32cbb7a687246349200d78b8ff7c' +# The commit BearSSL is pinned at: ae63032 of the fork webcpporg/bearssl, branch +# upstream/ecdsa-bits2int-constant-time, upstream's 7bea48e and exactly the ECDSA nonce fix +# submitted upstream (CODING-GUIDELINES chapter 5 rule 1); back to upstream once it is applied. +BEARSSL_COMMIT = 'ae63032d9f30bf53674db5445875adf71b8626b7' BITCOIN = 'third_party/libs/bitcoin' @@ -519,8 +520,8 @@ def test_ctaes_not_checked_out_is_refused(root: Path) -> None: def test_bitcoin_base58_vectors_reach_a_test(root: Path) -> None: # /third_party//bitcoin_base58_vectors gives a program Bitcoin Core's src/test/data at the pin, - # by its define, and the file webcpp::codecs reads is there, natively and on wasip2, where - # wasmtime is given the directory. + # by its define, and the files webcpp::codecs and webcpp::hash read are there, natively and on + # wasip2, where wasmtime is given the directory. harness.add_library(root, 'base58_data', ( 'import webcpp ;\n\n' 'webcpp.targets native wasip2 ;\n\n' @@ -528,7 +529,9 @@ def test_bitcoin_base58_vectors_reach_a_test(root: Path) -> None: {'reads.cpp': '#include \n\nint main() {\n' ' std::ifstream in(WEBCPP_TEST_BITCOIN_BASE58_VECTORS\n' ' "/base58_encode_decode.json");\n' - ' return in ? 0 : 1;\n}\n'}) + ' std::ifstream keys(WEBCPP_TEST_BITCOIN_BASE58_VECTORS\n' + ' "/key_io_valid.json");\n' + ' return in && keys ? 0 : 1;\n}\n'}) result = harness.run_b2(root, '-a', 'libs/base58_data/test') harness.expect(result, True) assert '**passed**' in result.stdout, result.stdout[-4000:]