From 55392b50f7b69c86bd49333df7038502bc1aa658 Mon Sep 17 00:00:00 2001 From: R Date: Sat, 5 Dec 2026 01:31:52 -0300 Subject: [PATCH 01/12] third_party: NIP-44 version 2's vectors (paulmillr/nip44 at 671a1f0) as /third_party//nip44, test data for crypto's ChaCha20 paulmillr/nip44's nip44.vectors.json, whose SHA-256 NIP-44's text states (269ed0f6...5040, checked), pinned shallow as third_party/libs/nip44: /third_party//nip44 gives a test its directory by WEBCPP_TEST_NIP44, wasmtime is given it on WASI, and a test runs again when the file changes. A build that names it without the checkout stops with the command that checks it out. The repository's JavaScript implementation, released into the public domain by the Unlicense, holds the same bytes; the submodule redistributes nothing. The pin and the refusal are tested in tools/test/third_party_test.py; the guidelines' third-party table, AGENTS.md's lists and the release notes name it. --- .gitmodules | 4 ++++ AGENTS.md | 7 ++++--- CODING-GUIDELINES.md | 1 + doc/releases/0.1.0.adoc | 2 ++ third_party/Jamfile | 26 ++++++++++++++++++++++++++ third_party/libs/nip44 | 1 + tools/test/third_party_test.py | 30 ++++++++++++++++++++++++++++++ 7 files changed, 68 insertions(+), 3 deletions(-) create mode 160000 third_party/libs/nip44 diff --git a/.gitmodules b/.gitmodules index b8dcfa6..3b5005c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -106,3 +106,7 @@ path = third_party/libs/hpke url = https://github.com/cfrg/draft-irtf-cfrg-hpke.git shallow = true +[submodule "third_party/libs/nip44"] + path = third_party/libs/nip44 + url = https://github.com/paulmillr/nip44.git + shallow = true diff --git a/AGENTS.md b/AGENTS.md index 3f7cc47..3cb37b8 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -114,8 +114,8 @@ webcpp/ a submodule under third_party/libs/, pinned at a commit and keeping its own licence (openssl, libdatachannel, bearssl, secp256k1, bitcoin for ctaes, xkcp, libsodium, blake3, and the test data wycheproof, bips, - hpke, JSON-Schema-Test-Suite and nativejson-benchmark), and the Jamfile that - declares it as /webcpp/third_party// and + hpke, nip44, JSON-Schema-Test-Suite and nativejson-benchmark), and the + Jamfile that declares it as /webcpp/third_party// and /third_party// (guidelines chapter 10) doc/ the index page (index.adoc, Jamfile) releases/ each version's release notes, which the index page shows @@ -271,7 +271,8 @@ Jamroot is its build configuration, and `libs/` is its repository. - for crypto: nothing installed, with the pinned submodules initialised: `git submodule update --init third_party/libs/bearssl third_party/libs/secp256k1 third_party/libs/bitcoin third_party/libs/wycheproof - third_party/libs/bips third_party/libs/ed25519-speccheck third_party/libs/hpke`, and + third_party/libs/bips third_party/libs/ed25519-speccheck third_party/libs/hpke + third_party/libs/nip44`, and `third_party/libs/openssl` for its OpenSSL backend (below); b2 builds every backend from its sources; - for Botan (`/third_party//botan`, webcpp::hash's `backends::botan` and diff --git a/CODING-GUIDELINES.md b/CODING-GUIDELINES.md index 8face9e..a34793d 100644 --- a/CODING-GUIDELINES.md +++ b/CODING-GUIDELINES.md @@ -1002,6 +1002,7 @@ update --init third_party/libs/`; a build that needs none never looks. | `json-schema-test-suite` | the JSON Schema Test Suite at `5b0ee16` (2026-09-21), test data: a test that names it reads the suite at run time from the directory its define `WEBCPP_TEST_JSON_SCHEMA_TEST_SUITE` gives, on every target (wasmtime is given it, `webcpp.data`), and runs again when a file of the suite changes | MIT | | `libdatachannel` | libdatachannel 0.24.6 at `6b1e2e620f1e37f0eafeee702eaea0043cb305fd`, with pinned libjuice, libsrtp, plog and usrsctp sources; static native archives built by upstream CMake through B2 against the same source-built OpenSSL, from a staged copy the patches of `tools/libdatachannel/patches` correct | MPL-2.0 and the nested dependencies' own licences | | `nativejson-benchmark` | Milo Yip's nativejson-benchmark at `478d572` (2022-10-28), test data: document's benchmarks (`libs/document/bench`) read its `data/canada.json`, `data/citm_catalog.json` and `data/twitter.json` at run time under the directory its define `WEBCPP_TEST_NATIVEJSON_BENCHMARK` gives, on every target (wasmtime is given it, `webcpp.data`), and run again when one of them changes; its own submodules are never checked out | MIT | +| `nip44` | paulmillr/nip44 at `671a1f04` (2024-12-04), shallow, test data: crypto's tests read `nip44.vectors.json`, NIP-44 version 2's vectors, whose SHA-256 NIP-44's text states, at run time under the directory its define `WEBCPP_TEST_NIP44` gives, on every target (wasmtime is given it, `webcpp.data`), and run again when it changes | public domain (the Unlicense of its JavaScript implementation, whose copy of the file is the same bytes) | | `openssl` | OpenSSL 3.5.9 at `45e844fa2a14ec92d146bd8f5778ac130b6625fb`; static libssl/libcrypto and matching generated headers, built by upstream Configure/Make through B2 for native Clang/GCC/MSVC, WASIp2 single and WASIp3 single/cooperative | Apache-2.0 | | `secp256k1` | libsecp256k1 v0.8.0 at `6e2c8bc`; a static library built file by file by `third_party/Jamfile` (`src/secp256k1.c` and its two precomputed tables, every module on) with webcpp::crypto's canary, on every target; its tables by `webcpp-secp256k1-tables` (`auto`: small on Emscripten, large elsewhere); `WEBCPP_CRYPTO_HAS_SECP256K1=1` | MIT | | `sodium` | libsodium 1.0.22 at `77e1ce5`, the submodule `third_party/libs/libsodium`; a static library built file by file by `third_party/Jamfile` (every `.c` of `src/libsodium/`, no assembly, the defines libsodium's configure finds on each target, upstream's `builds/msvc/version.h` copied into the build directory) with webcpp::hash's canary and webcpp::crypto's (`libs/crypto/src/canary_sodium.c`, configuration `portable`), on every target; `WEBCPP_HASH_HAS_SODIUM=1` and `WEBCPP_CRYPTO_HAS_SODIUM=1`; `sodium-test-config` gives a program its private headers and test defines; shared with webcpp::crypto | ISC | diff --git a/doc/releases/0.1.0.adoc b/doc/releases/0.1.0.adoc index 1feea68..6fffd24 100644 --- a/doc/releases/0.1.0.adoc +++ b/doc/releases/0.1.0.adoc @@ -184,6 +184,8 @@ target through `/webcpp/third_party//wycheproof`. target through `/third_party//bips`. * Added RFC 9180's test vectors (cfrg/draft-irtf-cfrg-hpke) to `third_party/`, which crypto's HPKE tests read on every target through `/third_party//hpke`. +* Added NIP-44 version 2's test vectors (paulmillr/nip44) to `third_party/`, +which crypto's ChaCha20 tests read on every target through `/third_party//nip44`. * Changed `/third_party//bips` to also serve BIP341's `bip-0341/wallet-test-vectors.json`, whose cases run again when it changes. * Changed the lint to never read third-party code under `third_party/libs/`. diff --git a/third_party/Jamfile b/third_party/Jamfile index bae6da1..c19663d 100644 --- a/third_party/Jamfile +++ b/third_party/Jamfile @@ -179,6 +179,32 @@ alias hpke : : @hpke-checked-out : : $(.hpke-files) ; explicit hpke ; +# paulmillr/nip44, shallow: test data, never compiled, released into the public +# domain (its JavaScript implementation's Unlicense, whose copy of the file is +# the same bytes). A test that names nip44 reads NIP-44 version 2's vectors, +# nip44.vectors.json, whose SHA-256 NIP-44's text states, from the directory +# WEBCPP_TEST_NIP44 names, with forward slashes, the directory given to +# wasmtime on WASI (webcpp.data), and runs again when it changes. +path-constant NIP44 : libs/nip44 ; +.nip44 = [ regex.replace $(NIP44) "\\\\" "/" ] ; +.nip44-files = [ glob libs/nip44/nip44.vectors.json ] ; + +rule nip44-checked-out ( properties * ) +{ + if ! [ path.exists [ path.native $(NIP44)/nip44.vectors.json ] ] + { + errors.user-error "third_party/libs/nip44 is not checked out: it holds no" + "nip44.vectors.json. Check it out with `git submodule update --init" + "third_party/libs/nip44`." ; + } +} + +alias nip44 : : @nip44-checked-out : : + "\"WEBCPP_TEST_NIP44=\\\"$(.nip44)\\\"\"" + [ webcpp.data $(NIP44) ] + $(.nip44-files) ; +explicit nip44 ; + # novifinancial/ed25519-speccheck (Apache-2.0), shallow: test data, never # compiled. A test that names ed25519-speccheck reads the twelve Ed25519 edge # cases of "Taming the many EdDSAs", cases.json, from the directory diff --git a/third_party/libs/nip44 b/third_party/libs/nip44 new file mode 160000 index 0000000..671a1f0 --- /dev/null +++ b/third_party/libs/nip44 @@ -0,0 +1 @@ +Subproject commit 671a1f04bcfacaf125b0db68adc45bc9ce0e763b diff --git a/tools/test/third_party_test.py b/tools/test/third_party_test.py index 2a9c998..289da34 100755 --- a/tools/test/third_party_test.py +++ b/tools/test/third_party_test.py @@ -116,6 +116,12 @@ # test-vectors.json (libs/crypto/test/support/hpke_vectors.hpp). HPKE_COMMIT = '5f503c564da00b0687b3de75f1dfbdfc4079ad31' +NIP44 = 'third_party/libs/nip44' + +# The commit paulmillr/nip44 is pinned at: NIP-44 version 2's vectors, its nip44.vectors.json, +# whose SHA-256 NIP-44's text states (libs/crypto/test/support/nip44.hpp). +NIP44_COMMIT = '671a1f04bcfacaf125b0db68adc45bc9ce0e763b' + # The commit novifinancial/ed25519-speccheck is pinned at: the twelve Ed25519 edge cases of # "Taming the many EdDSAs", its cases.json (libs/crypto/test/ed25519_speccheck_test.cpp). ED25519_SPECCHECK_COMMIT = '65519336fda78a3d016e947df6d82848aca0c9da' @@ -376,6 +382,15 @@ def test_hpke_is_pinned(_: Path) -> None: assert listed.stdout.split()[:2] == ['160000', HPKE_COMMIT], listed.stdout +def test_nip44_is_pinned(_: Path) -> None: + listed = subprocess.run(['git', '-C', str(harness.ROOT), 'ls-files', '-s', NIP44], + capture_output=True, text=True, check=True) + assert listed.stdout.split()[:2] == ['160000', NIP44_COMMIT], listed.stdout + shallow = subprocess.run(['git', '-C', str(harness.ROOT), 'config', '-f', '.gitmodules', + f'submodule.{NIP44}.shallow'], capture_output=True, text=True) + assert shallow.stdout.strip() == 'true', shallow.stdout + + def test_bips_target_files(_: Path) -> None: jamfile = (harness.ROOT / 'third_party' / 'Jamfile').read_text() found = re.search(r'^\.bips-files = \[ glob ([^\]]*)\] ;', jamfile, re.MULTILINE) @@ -536,6 +551,19 @@ def test_hpke_not_checked_out_is_refused(root: Path) -> None: harness.expect(harness.run_b2(root, 'libs/demo/test//pass'), True) +def test_nip44_not_checked_out_is_refused(root: Path) -> None: + harness.third_party_of_its_own(root, 'nip44', checked_out=False) + harness.add_library(root, 'nip44_reader', ( + 'import webcpp ;\n\nwebcpp.run reads_vectors : reads_vectors.cpp\n' + ' : /webcpp/third_party//nip44 ;\n'), + {'reads_vectors.cpp': 'int main() { return 0; }\n'}) + result = harness.run_b2(root, 'libs/nip44_reader/test') + harness.expect(result, False, 'third_party/libs/nip44 is not checked out', + 'git submodule update --init third_party/libs/nip44') + # A build that needs no vectors never looks for them. + harness.expect(harness.run_b2(root, 'libs/demo/test//pass'), True) + + def test_ctaes_not_checked_out_is_refused(root: Path) -> None: harness.copy_integration_libraries(root, 'config', 'crypto') harness.third_party_of_its_own(root, 'bitcoin', checked_out=False) @@ -1213,9 +1241,11 @@ def test_botan_test_program_runs(root: Path) -> None: test_a_suite_not_checked_out_is_refused, test_ed25519_speccheck_not_checked_out_is_refused, test_hpke_not_checked_out_is_refused, + test_nip44_not_checked_out_is_refused, test_bips_is_pinned, test_ed25519_speccheck_is_pinned, test_hpke_is_pinned, + test_nip44_is_pinned, test_bips_target_files, test_bip352_vectors_match_libsecp256k1, test_bearssl_is_pinned, From 38a8c59ee42f956608d44eb2b81dc5a113e417e7 Mon Sep 17 00:00:00 2001 From: R Date: Sat, 5 Dec 2026 01:48:41 -0300 Subject: [PATCH 02/12] tools: the crypto fixture chacha20_default --- .../crypto_jamfiles/chacha20_default/Jamfile | 9 ++++ .../crypto_jamfiles/chacha20_default/app.cpp | 48 +++++++++++++++++++ .../chacha20_default/chacha20_default.outcome | 20 ++++++++ 3 files changed, 77 insertions(+) create mode 100644 tools/test/fixtures/crypto_jamfiles/chacha20_default/Jamfile create mode 100644 tools/test/fixtures/crypto_jamfiles/chacha20_default/app.cpp create mode 100644 tools/test/fixtures/crypto_jamfiles/chacha20_default/chacha20_default.outcome diff --git a/tools/test/fixtures/crypto_jamfiles/chacha20_default/Jamfile b/tools/test/fixtures/crypto_jamfiles/chacha20_default/Jamfile new file mode 100644 index 0000000..ea8a9e1 --- /dev/null +++ b/tools/test/fixtures/crypto_jamfiles/chacha20_default/Jamfile @@ -0,0 +1,9 @@ +# 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//chacha20-default ; +# end::jamfile[] diff --git a/tools/test/fixtures/crypto_jamfiles/chacha20_default/app.cpp b/tools/test/fixtures/crypto_jamfiles/chacha20_default/app.cpp new file mode 100644 index 0000000..de89aa1 --- /dev/null +++ b/tools/test/fixtures/crypto_jamfiles/chacha20_default/app.cpp @@ -0,0 +1,48 @@ +// 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) + +// Encrypts RFC 8439's ChaCha20 example (section 2.4.2) on the default backend, checks the +// ciphertext's first and last bytes against the RFC's, decrypts it again, and prints the backend +// that ran. The key and nonce are the RFC's: a real program draws its key from random_device and +// never reuses a nonce under it, and authenticates the nonce and the ciphertext itself, as NIP-44 +// does, since ChaCha20 alone authenticates nothing. +#include + +#include +#include +#include +#include +#include +#include + +int main() { + using cipher = webcpp::crypto::ciphers::chacha20<>; + // The key 0x00, 0x01, ..., 0x1f. + std::array key{}; + for (std::size_t index = 0; index < key.size(); ++index) { + key[index] = static_cast(index); + } + std::array const nonce{0, 0, 0, 0, 0, 0, 0, 0x4a, 0, 0, 0, 0}; + constexpr std::string_view sunscreen = + "Ladies and Gentlemen of the class of '99: If I could offer you only one tip for the " + "future, sunscreen would be it."; + std::array plaintext{}; + std::ranges::copy(sunscreen, plaintext.begin()); + auto data = plaintext; + std::array const expected_head{0x6e, 0x2e, 0x35, 0x9a, 0x25, 0x68, 0xf9, 0x80}; + std::array const expected_tail{0xf2, 0x78, 0x5e, 0x42}; + auto made = cipher::from_key(key); + bool ok = false; + if (made && made->apply_keystream(nonce, data, 1)) { + ok = std::equal(expected_head.begin(), expected_head.end(), data.begin()) && + std::equal(expected_tail.begin(), expected_tail.end(), data.end() - 6) && + made->apply_keystream(nonce, data, 1) && data == plaintext; + } + auto const name = cipher::backend_type::name; + std::printf("chacha20 %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/chacha20_default/chacha20_default.outcome b/tools/test/fixtures/crypto_jamfiles/chacha20_default/chacha20_default.outcome new file mode 100644 index 0000000..4b89b96 --- /dev/null +++ b/tools/test/fixtures/crypto_jamfiles/chacha20_default/chacha20_default.outcome @@ -0,0 +1,20 @@ +# 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] +chacha20 ok backend=sodium +[wasip2] +chacha20 ok backend=sodium +[wasip3] +chacha20 ok backend=sodium +[emscripten] +chacha20 ok backend=sodium +# end::output[] From e0bdfcf90d0e4239ac8ff93ae7d62e7c2a4d59cc Mon Sep 17 00:00:00 2001 From: R Date: Sat, 5 Dec 2026 03:17:00 -0300 Subject: [PATCH 03/12] tools: the crypto fixture poly1305_default --- .../crypto_jamfiles/poly1305_default/Jamfile | 9 ++++ .../crypto_jamfiles/poly1305_default/app.cpp | 44 +++++++++++++++++++ .../poly1305_default/poly1305_default.outcome | 20 +++++++++ 3 files changed, 73 insertions(+) create mode 100644 tools/test/fixtures/crypto_jamfiles/poly1305_default/Jamfile create mode 100644 tools/test/fixtures/crypto_jamfiles/poly1305_default/app.cpp create mode 100644 tools/test/fixtures/crypto_jamfiles/poly1305_default/poly1305_default.outcome diff --git a/tools/test/fixtures/crypto_jamfiles/poly1305_default/Jamfile b/tools/test/fixtures/crypto_jamfiles/poly1305_default/Jamfile new file mode 100644 index 0000000..8d8ce45 --- /dev/null +++ b/tools/test/fixtures/crypto_jamfiles/poly1305_default/Jamfile @@ -0,0 +1,9 @@ +# 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//poly1305-default ; +# end::jamfile[] diff --git a/tools/test/fixtures/crypto_jamfiles/poly1305_default/app.cpp b/tools/test/fixtures/crypto_jamfiles/poly1305_default/app.cpp new file mode 100644 index 0000000..be94513 --- /dev/null +++ b/tools/test/fixtures/crypto_jamfiles/poly1305_default/app.cpp @@ -0,0 +1,44 @@ +// 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) + +// Authenticates RFC 8439's Poly1305 example (section 2.5.2) on the default backend, checks the tag +// against the RFC's, verifies it, refuses it with one bit flipped, and prints the backend that +// ran. The key is the RFC's: a real program derives a fresh key for every message, since a +// Poly1305 key authenticates one message alone. +#include + +#include +#include +#include +#include +#include + +int main() { + using authenticator = webcpp::crypto::authenticators::poly1305<>; + std::array const key{ + 0x85, 0xd6, 0xbe, 0x78, 0x57, 0x55, 0x6d, 0x33, 0x7f, 0x44, 0x52, + 0xfe, 0x42, 0xd5, 0x06, 0xa8, 0x01, 0x03, 0x80, 0x8a, 0xfb, 0x0d, + 0xb2, 0xfd, 0x4a, 0xbf, 0xf6, 0xaf, 0x41, 0x49, 0xf5, 0x1b, + }; + constexpr std::string_view forum = "Cryptographic Forum Research Group"; + std::array message{}; + std::ranges::copy(forum, message.begin()); + std::array const expected{ + 0xa8, 0x06, 0x1d, 0xc1, 0x30, 0x51, 0x36, 0xc6, + 0xc2, 0x2b, 0x8b, 0xaf, 0x0c, 0x01, 0x27, 0xa9, + }; + auto const tag = authenticator::authenticate(key, message); + bool ok = false; + if (tag && std::ranges::equal(*tag, expected) && authenticator::verify(key, message, *tag)) { + auto forged = expected; + forged[0] ^= 1U; + ok = !authenticator::verify(key, message, forged); + } + auto const name = authenticator::backend_type::name; + std::printf("poly1305 %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/poly1305_default/poly1305_default.outcome b/tools/test/fixtures/crypto_jamfiles/poly1305_default/poly1305_default.outcome new file mode 100644 index 0000000..a59ff16 --- /dev/null +++ b/tools/test/fixtures/crypto_jamfiles/poly1305_default/poly1305_default.outcome @@ -0,0 +1,20 @@ +# 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] +poly1305 ok backend=sodium +[wasip2] +poly1305 ok backend=sodium +[wasip3] +poly1305 ok backend=sodium +[emscripten] +poly1305 ok backend=sodium +# end::output[] From 2a48a404345ce9dd41aa25ae91984215b6fa88f9 Mon Sep 17 00:00:00 2001 From: R Date: Sat, 5 Dec 2026 03:32:40 -0300 Subject: [PATCH 04/12] tools: chacha20_default compares the ciphertext's last bytes --- tools/test/fixtures/crypto_jamfiles/chacha20_default/app.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/test/fixtures/crypto_jamfiles/chacha20_default/app.cpp b/tools/test/fixtures/crypto_jamfiles/chacha20_default/app.cpp index de89aa1..3c91ebf 100644 --- a/tools/test/fixtures/crypto_jamfiles/chacha20_default/app.cpp +++ b/tools/test/fixtures/crypto_jamfiles/chacha20_default/app.cpp @@ -33,12 +33,12 @@ int main() { std::ranges::copy(sunscreen, plaintext.begin()); auto data = plaintext; std::array const expected_head{0x6e, 0x2e, 0x35, 0x9a, 0x25, 0x68, 0xf9, 0x80}; - std::array const expected_tail{0xf2, 0x78, 0x5e, 0x42}; + std::array const expected_tail{0x5e, 0x42, 0x87, 0x4d}; auto made = cipher::from_key(key); bool ok = false; if (made && made->apply_keystream(nonce, data, 1)) { ok = std::equal(expected_head.begin(), expected_head.end(), data.begin()) && - std::equal(expected_tail.begin(), expected_tail.end(), data.end() - 6) && + std::equal(expected_tail.begin(), expected_tail.end(), data.end() - 4) && made->apply_keystream(nonce, data, 1) && data == plaintext; } auto const name = cipher::backend_type::name; From 88a49bc2eebf6264fa747783c4f2d5326dba6f45 Mon Sep 17 00:00:00 2001 From: R Date: Sat, 5 Dec 2026 05:16:03 -0300 Subject: [PATCH 05/12] guidelines: crypto's raw ChaCha20 and Poly1305 --- CODING-GUIDELINES.md | 76 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 61 insertions(+), 15 deletions(-) diff --git a/CODING-GUIDELINES.md b/CODING-GUIDELINES.md index a34793d..70ad660 100644 --- a/CODING-GUIDELINES.md +++ b/CODING-GUIDELINES.md @@ -8824,9 +8824,10 @@ 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 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. + level, NIST CAVP's vectors and Botan; the raw ChaCha20 and Poly1305 are + built, not merged. Its constant-time lane, its sizes and throughput, and + ChaCha20-Poly1305 merged with the foundation's increment 1, and its key + formats on codecs with the formats change. - **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 @@ -8885,13 +8886,13 @@ 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 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. +part, its formats change is merged with hash's Base58Check, and its primitives +change is built and not merged, and hash is merged. 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; the formats change built, not 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 merged; the primitives 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 @@ -9015,8 +9016,9 @@ 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).** +**The formats change (built on codecs; merged on 2026-12-02 from the branch +`crypto/formats` of the library, `6052c7c`, and of the superproject, +`b248bdc`).** - **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 @@ -9062,13 +9064,57 @@ superproject; built on codecs, not merged).** `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. + (merged on 2026-12-02 from the branch `hash/base58-with-checksum`).** + 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). +**The primitives change (branch `crypto/primitives` of the library and of +the superproject; built, not merged).** + +- **RFC 8439's raw ChaCha20 is `ciphers::chacha20`, of the family + `families::chacha20` and the template `ciphers::basic_chacha20`, in the + purpose namespace `crypto::unauthenticated_encryption`, whose concept + `stream_cipher` reads the algorithm's own `nonce_size`, `block_size` and + `counter_type` (owner decisions 5 and 7).** `from_key(key)` takes 32 bytes; + `apply_keystream(nonce, data, initial_counter)` XORs the keystream from that + block into `data` in place, encryption and decryption alike, and returns + `error::counter_overflow` (22) before any backend runs when `data` needs + more blocks than the 32-bit counter has left, so no backend wraps or carries + into the nonce. It runs on libsodium, the default on every target, BearSSL + on every target and OpenSSL natively and on WASI; ctaes and libsecp256k1 + are refused at compile time. Its asynchronous forms are + `async_from_key` and `async_apply_keystream`; WebCrypto has no ChaCha20, so + a backend that completes by itself is refused. The name warns: the page + sends a program to `secret_key_encryption` unless its protocol brings its + own authentication, as NIP-44 does with HMAC-SHA256. + Source: `libraries/crypto/openspec/changes/primitives/design.md` D1 to D7 + (proposals); `doc/chacha.adoc` and `doc/unauthenticated_encryption.adoc` + (libs/crypto). +- **RFC 8439's raw Poly1305 is `authenticators::poly1305`, in the + purpose namespace `crypto::single_use_key_authentication` (owner decision + 6): a key used for one message only.** The static `authenticate(key, + message)` gives the 16-byte tag of a 32-byte key; `verify(key, message, + tag)` compares through `secure::constant_time_equal` and returns + `authentication_failed` on a mismatch; there is no keyed object. It runs on + libsodium, the default on every target, and OpenSSL natively and on WASI; + BearSSL, whose Poly1305 lies inside its AEAD, ctaes and libsecp256k1 are + refused at compile time. A reusable key is HMAC's, `hash::mac`. + Source: `libraries/crypto/openspec/changes/primitives/design.md` D11 to + D15 (proposals); `doc/single_use_key_authentication.adoc` (libs/crypto). +- **The tests compose RFC 8439's AEAD from the two raw pieces on every + combination of their backends and find, byte for byte, what + `ciphers::chacha20_poly1305` seals; NIP-44 version 2's vectors prove + ChaCha20 where a protocol uses it; both pieces are in the constant-time + lane and dudect, and in the sizes lane at release on every target.** + NIP-44 itself stays out of crypto: its vectors (`/third_party//nip44`) are + composed in the tests from crypto's ChaCha20 and secp256k1 and + webcpp::hash's HKDF and HMAC. Throughput is not measured yet. + Source: `libraries/crypto/openspec/changes/primitives/design.md` D9, D16 + and D17 (proposals); `doc/tables/sizes.json` (libs/crypto). + **Constant time (increment 1, Task 14; merged).** - **Constant time is checked deterministically on Linux x86-64 and arm64 From fea0d1a792eb50b33821bf982d58cc6f7e60e511 Mon Sep 17 00:00:00 2001 From: R Date: Sat, 5 Dec 2026 05:16:03 -0300 Subject: [PATCH 06/12] libs/crypto: the gitlink at the primitives change (a514b3c) --- libs/crypto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/crypto b/libs/crypto index 36d1279..a514b3c 160000 --- a/libs/crypto +++ b/libs/crypto @@ -1 +1 @@ -Subproject commit 36d1279d9048ff667183ec2e45c6e1961a34dd6a +Subproject commit a514b3c0b83bf2510482c1ab8afb9aed54669ddb From 4e4b3fda4323f4bdfd13a36f7fdfb8dad9fbab3a Mon Sep 17 00:00:00 2001 From: R Date: Sat, 5 Dec 2026 05:17:43 -0300 Subject: [PATCH 07/12] guidelines: the proposals' summary reads as one list --- CODING-GUIDELINES.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CODING-GUIDELINES.md b/CODING-GUIDELINES.md index 70ad660..75ea85e 100644 --- a/CODING-GUIDELINES.md +++ b/CODING-GUIDELINES.md @@ -8886,8 +8886,8 @@ 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 and secure are merged, crypto's foundation is merged in -part, its formats change is merged with hash's Base58Check, and its primitives -change is built and not merged, and hash is merged. While a proposal is open, +part, its formats change is merged with hash's Base58Check and its primitives +change is built and not merged; hash is merged. 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. From 4cfb4b872785b8305837e1ec64b72605addb4da8 Mon Sep 17 00:00:00 2001 From: R Date: Sat, 5 Dec 2026 05:37:58 -0300 Subject: [PATCH 08/12] libs/crypto: the gitlink at the primitives change (280006d) --- libs/crypto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/crypto b/libs/crypto index 7576ecc..280006d 160000 --- a/libs/crypto +++ b/libs/crypto @@ -1 +1 @@ -Subproject commit 7576ecce5cece31c92cb76f15b0c6935cad8e2f4 +Subproject commit 280006d3c13a7fe7939adcd3f7287f58af68e50f From 1a044743f418a93c92038905efa09f50eabcb321 Mon Sep 17 00:00:00 2001 From: R Date: Sat, 5 Dec 2026 07:00:13 -0300 Subject: [PATCH 09/12] libs/crypto: the gitlink at the primitives change (dd6372a) --- libs/crypto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/crypto b/libs/crypto index 280006d..dd6372a 160000 --- a/libs/crypto +++ b/libs/crypto @@ -1 +1 @@ -Subproject commit 280006d3c13a7fe7939adcd3f7287f58af68e50f +Subproject commit dd6372a09312bb5a5d2f5f684700d99cb031bb4a From 34ea790deee21337856768e43475e65c403e269d Mon Sep 17 00:00:00 2001 From: R Date: Sat, 5 Dec 2026 07:18:40 -0300 Subject: [PATCH 10/12] libs/crypto: the gitlink at the primitives change (c638dbf) --- libs/crypto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/crypto b/libs/crypto index dd6372a..c638dbf 160000 --- a/libs/crypto +++ b/libs/crypto @@ -1 +1 @@ -Subproject commit dd6372a09312bb5a5d2f5f684700d99cb031bb4a +Subproject commit c638dbf42b5fa959dc0a81998eadfadadc69e20c From 081fe11e9fab4e774747f40e6153337f3a5485f3 Mon Sep 17 00:00:00 2001 From: R Date: Sat, 5 Dec 2026 09:09:01 -0300 Subject: [PATCH 11/12] libs/crypto: the gitlink at the primitives change (9d66d47) --- libs/crypto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/crypto b/libs/crypto index c638dbf..9d66d47 160000 --- a/libs/crypto +++ b/libs/crypto @@ -1 +1 @@ -Subproject commit c638dbf42b5fa959dc0a81998eadfadadc69e20c +Subproject commit 9d66d476333dddb5fae326a0c346493ed9d0453d From e4c9a8f5614aa49758af6e30a6b9169c0f5c3cf3 Mon Sep 17 00:00:00 2001 From: R Date: Sat, 5 Dec 2026 10:40:00 -0300 Subject: [PATCH 12/12] libs/crypto: the gitlink at the primitives change's merge (webcpporg/crypto#30, 0467566) --- libs/crypto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/crypto b/libs/crypto index 2453484..0467566 160000 --- a/libs/crypto +++ b/libs/crypto @@ -1 +1 @@ -Subproject commit 24534844469c93022cf99f3bcc59eaade072d069 +Subproject commit 0467566f690a60c8b497e9beac1475a4a32b8aaf