diff --git a/CODING-GUIDELINES.md b/CODING-GUIDELINES.md index 3d25e93..c9590c6 100644 --- a/CODING-GUIDELINES.md +++ b/CODING-GUIDELINES.md @@ -8570,7 +8570,7 @@ each with its decisions as decided. While a proposal is open, its own 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 increment 1 built on its branch, not merged) +### crypto, after 0.1 (genesis accepted 2026-10-11, foundation accepted 2026-11-14; the foundation's increment 1 merged, its increment 2 built on its branch, 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 @@ -8581,17 +8581,17 @@ Its rules are webcpp::hash's: one default backend per family and target with its reason stated, no profile and no per-family override (design D32), tables of size and speed only from release builds, and primitives only (D24). What is built is in chapter 15; what follows is decided and not built, except -increment 1, whose state is first. +increments 1 and 2, whose state is first. -**The foundation's increment 1 (plan Tasks 1 to 16).** +**The foundation's increment 1 (plan Tasks 1 to 16; merged).** -- **Built on the branch `crypto/foundation-1` of the library and the - superproject, awaiting the owner's merge: libsodium's backend, the families - on it, the capability table, the fixed defaults, the three own lanes and - the page.** `backends::sodium` on `/third_party//sodium`, shared with - webcpp::hash, with crypto's canary; `curves::ed25519` (strict verification - over the twelve edge cases, Ed25519ph, the conversion, RFC 8410's formats and - PEM), `curves::x25519` and `kx_keypair`, `ciphers::aead` with +- **Merged on 2026-11-19 from the branch `crypto/foundation-1` of the library + (`dae9e84`) and of the superproject (`485c5e0`): libsodium's backend, the + families on it, the capability table, the fixed defaults, the three own + lanes and the page.** `backends::sodium` on `/third_party//sodium`, shared + with webcpp::hash, with crypto's canary; `curves::ed25519` (strict + verification over the twelve edge cases, Ed25519ph, the conversion, RFC 8410's + formats and PEM), `curves::x25519` and `kx_keypair`, `ciphers::aead` with `chacha20_poly1305` (also on BearSSL and OpenSSL), its original form and `xchacha20_poly1305`, `ciphers::secretbox`, `hybrid::box` and `sealed_box`, and `secret` with the errors 15 to 20. `supports_v` and @@ -8617,15 +8617,60 @@ increment 1, whose state is first. page says, as it says that OpenSSL's `open` is left out of memcheck. Source: `libs/crypto/doc/generated/constant-time.adoc`, `doc/tables/crypto.json` (libs/crypto). -- **What is not built is in the other increments: libsecp256k1's remaining - modules (2), BearSSL's (3), the browser backend and the asynchronous family - (4), libsodium completed (5), blst (6), Botan as a submodule (7), OpenSSL's - remaining algorithms (8), KZG, BN254, Shamir and HPKE (9 to 12).** The +- **What is not built is in the other increments: BearSSL's remaining + modules (3), the browser backend and the asynchronous family (4), libsodium + completed (5), blst (6), Botan as a submodule (7), OpenSSL's remaining + algorithms (8), KZG, BN254, Shamir and HPKE (9 to 12).** Increment 2's merges, the CI's run and the proposals' status are the owner's. Source: `libraries/crypto/openspec/changes/foundation/reference/roadmap.md` (proposals). -**Constant time (increment 1, Task 14; built on the branch).** +**The foundation's increment 2 (plan Tasks 2.1 to 2.7; built on its branch).** + +- **Built on the branch `crypto/secp256k1-modules` of the library and the + superproject, on increment 1's merged trees, awaiting the owner's merge: + libsecp256k1's remaining modules.** ECDH in three forms (`ecdh` returning a + `secret<32>`, `ecdh_x`, `ecdh_point`), recoverable signatures + (`sign_recoverable` of the key pair and `recover`), the tweaks, negation and + combination of whole keys (`curves/secp256k1/tweak.hpp`), keys in SPKI, + PKCS#8 and PEM (`formats.hpp`), BIP 324's ElligatorSwift (`ellswift.hpp`), + BIP 327's MuSig2 (`musig.hpp`) and BIP 352's silent payments + (`silent_payments.hpp`); the last three are families of their own, each with + its own default alias and its own refusal of a backend other than + libsecp256k1. Two examples teach MuSig2 across a network (every public part + as bytes, each partial signature checked before it is added) and under a + Taproot key (the key tweaked before any nonce). + Source: `libraries/crypto/openspec/changes/foundation/reference/plan.md` + Tasks 2.1 to 2.7 and their "As built" notes (proposals); + `libs/crypto/doc/secp256k1.adoc`. +- **Where libsecp256k1 would abort on a bad argument, webcpp refuses first, + and the caller lends the workspace.** libsecp256k1 checks counts, a used + nonce and an id with `ARG_CHECK`, whose callback aborts; the functions + return `invalid_input_size` or another error before it is reached. A + function that needs scratch space (`pubkey_combine`, the MuSig2 aggregates) + takes a `workspace` the caller sizes with `combine_workspace_size` or + `workspace_size`, and wipes it on every return, a refusal's included, so no + function allocates. A silent payments label lookup returns exactly + `std::optional>` into bytes it owns: + libsecp256k1 reads them after the lookup returns, so a result by value, a + convertible one included, is refused at compile time. + Source: `libs/crypto/include/webcpp/crypto/curves/secp256k1/tweak.hpp`, + `musig.hpp` and `silent_payments.hpp`. +- **Constant time and sizes extend to the modules.** Memcheck and + MemorySanitizer check libsecp256k1's own `ctime_tests.c` and webcpp's code + around each module (the key pair's making, its signatures and tweak, the + three ECDH forms, the key tweaks, PKCS#8, ElligatorSwift's `create` and + `xdh`, MuSig2's `nonce_gen` and `partial_sign`, the silent payments' + `create_outputs`, `create_label` and `scan_outputs`, each workspace's wipe + included), written once in `test/constant_time/paths.hpp`; dudect times + `ecdh_x` natively and on wasip2, in a program of its own, so that + libsecp256k1 stays off BearSSL's. The Linux x86-64 run of the lane is the + CI's. The sizes lane measures `ecdh_x`, `recover`, ElligatorSwift's + exchange, a two-signer MuSig2 signature and a silent payments output, all + from release builds through `webcpp.program-sizes`. + Source: `libs/crypto/test/constant_time/Jamfile` and `test/sizes/Jamfile`. + +**Constant time (increment 1, Task 14; merged).** - **Constant time is checked deterministically on Linux x86-64 and arm64 (Valgrind memcheck and MemorySanitizer, each harness failing on a planted @@ -8639,10 +8684,10 @@ increment 1, whose state is first. Source: `libraries/crypto/openspec/changes/genesis/reference/spec.md` sections 3.2 and 8.3 (proposals); `test/constant_time/Jamfile` (libs/crypto). -**Sizes and throughput (increment 1, Task 11'; built on the branch).** +**Sizes and throughput (increment 1, Task 11'; merged).** - **Sizes are measured at `variant=release` on every target by the own lane - `sizes`, through `webcpp.size-table`; throughput by webcpp's own program + `sizes`, through `webcpp.program-sizes`; throughput by webcpp's own program (`bench/collect.py`, which refuses a build that is not a release) on the developer's machine, dated; neither decides a default.** b2 has no -O2 that reaches the libraries a program names, so the tables are dated references; @@ -8679,7 +8724,7 @@ increment 1, whose state is first. Source: `libraries/crypto/openspec/changes/genesis/reference/plan.md` C11 (proposals). -**ChaCha20-Poly1305 (built in increment 1, Task 8b, on the branch; the genesis's increment 4).** +**ChaCha20-Poly1305 (built in increment 1, Task 8b, merged; the genesis's increment 4).** - **`ciphers::chacha20_poly1305` on BearSSL and OpenSSL is one shot only, with an IV of exactly 12 bytes, refuses a message over 2^38 - 64 bytes with diff --git a/libs/crypto b/libs/crypto index 1fc5140..e7c71db 160000 --- a/libs/crypto +++ b/libs/crypto @@ -1 +1 @@ -Subproject commit 1fc5140e1a2285b996021de1af354a14397fa68c +Subproject commit e7c71dbdd4ac2f9a477e092914ee7f414e9ff63c diff --git a/third_party/Jamfile b/third_party/Jamfile index 81171fa..6152f7e 100644 --- a/third_party/Jamfile +++ b/third_party/Jamfile @@ -109,16 +109,33 @@ alias wycheproof : : @wycheproof-checked-out : : $(.wycheproof-files) ; explicit wycheproof ; -# bitcoin/bips (BSD-2-Clause, as BIP340's header states), shallow: test data, -# never compiled. A test that names bips reads BIP340's -# bip-0340/test-vectors.csv and BIP341's bip-0341/wallet-test-vectors.json -# from the directory WEBCPP_TEST_BIPS names, with forward slashes, the -# directory given to wasmtime on WASI (webcpp.data), and runs again when one -# of the two files changes. +# bitcoin/bips, shallow: test data, never compiled, each BIP's files under the +# licence its header states (BIP340 and BIP 352 BSD-2-Clause; BIP341, BIP 324 +# and BIP 327 BSD-3-Clause). A test that names bips reads BIP340's +# bip-0340/test-vectors.csv, BIP341's bip-0341/wallet-test-vectors.json, +# BIP 324's bip-0324/ellswift_decode_test_vectors.csv and +# bip-0324/packet_encoding_test_vectors.csv, BIP 327's eight +# bip-0327/vectors/*_vectors.json, and BIP 352's +# bip-0352/send_and_receive_test_vectors.json (whose copy in libsecp256k1 its +# vectors.h is derived from) from the directory +# WEBCPP_TEST_BIPS names, with forward slashes, the directory given to +# wasmtime on WASI (webcpp.data), and runs again when one of the files +# changes. path-constant BIPS : libs/bips ; .bips = [ regex.replace $(BIPS) "\\\\" "/" ] ; .bips-files = [ glob libs/bips/bip-0340/test-vectors.csv - libs/bips/bip-0341/wallet-test-vectors.json ] ; + libs/bips/bip-0341/wallet-test-vectors.json + libs/bips/bip-0324/ellswift_decode_test_vectors.csv + libs/bips/bip-0324/packet_encoding_test_vectors.csv + libs/bips/bip-0327/vectors/det_sign_vectors.json + libs/bips/bip-0327/vectors/key_agg_vectors.json + libs/bips/bip-0327/vectors/key_sort_vectors.json + libs/bips/bip-0327/vectors/nonce_agg_vectors.json + libs/bips/bip-0327/vectors/nonce_gen_vectors.json + libs/bips/bip-0327/vectors/sig_agg_vectors.json + libs/bips/bip-0327/vectors/sign_verify_vectors.json + libs/bips/bip-0327/vectors/tweak_vectors.json + libs/bips/bip-0352/send_and_receive_test_vectors.json ] ; rule bips-checked-out ( properties * ) { diff --git a/tools/test/fixtures/crypto_jamfiles/secp256k1_ellswift_default/Jamfile b/tools/test/fixtures/crypto_jamfiles/secp256k1_ellswift_default/Jamfile new file mode 100644 index 0000000..bfc02cc --- /dev/null +++ b/tools/test/fixtures/crypto_jamfiles/secp256k1_ellswift_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//secp256k1_ellswift-default ; +# end::jamfile[] diff --git a/tools/test/fixtures/crypto_jamfiles/secp256k1_ellswift_default/app.cpp b/tools/test/fixtures/crypto_jamfiles/secp256k1_ellswift_default/app.cpp new file mode 100644 index 0000000..e6d0ec2 --- /dev/null +++ b/tools/test/fixtures/crypto_jamfiles/secp256k1_ellswift_default/app.cpp @@ -0,0 +1,55 @@ +// 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) + +// Makes the ElligatorSwift encodings of two fixed key pairs on ElligatorSwift's default backend, +// checks that each decodes to its key pair's public key and that both sides of BIP 324's +// exchange agree, and prints the backend that ran. The secrets and the randomness are fixed: a +// real program draws its own, and never prints a shared secret. +#include +#include +#include + +#include +#include +#include + +namespace { + +std::array repeated(std::uint8_t value) { + std::array bytes{}; + bytes.fill(value); + return bytes; +} + +} // namespace + +int main() { + namespace crypto = webcpp::crypto; + namespace secp256k1 = webcpp::crypto::curves::secp256k1; + auto const initiator = secp256k1::keypair::make(repeated(0x11)); + auto const responder = secp256k1::keypair::make(repeated(0x22)); + bool ok = false; + if (initiator && responder) { + auto const sent = secp256k1::ellswift_create(*initiator, repeated(0x33)); + auto const received = secp256k1::ellswift_create(*responder, repeated(0x44)); + auto const initiator_key = initiator->public_key(); + auto const responder_key = responder->public_key(); + if (sent && received && initiator_key && responder_key && + secp256k1::serialize_public_key(secp256k1::ellswift_decode(*sent)) == *initiator_key && + secp256k1::serialize_public_key(secp256k1::ellswift_decode(*received)) == + *responder_key) { + auto const mine = secp256k1::ellswift_xdh(*initiator, *sent, *received, + secp256k1::ellswift_party::initiator); + auto const theirs = secp256k1::ellswift_xdh(*responder, *sent, *received, + secp256k1::ellswift_party::responder); + ok = mine && theirs && crypto::equal(mine->bytes(), theirs->bytes()); + } + } + auto const name = crypto::default_backend_t::name; + std::printf("ellswift %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/secp256k1_ellswift_default/secp256k1_ellswift_default.outcome b/tools/test/fixtures/crypto_jamfiles/secp256k1_ellswift_default/secp256k1_ellswift_default.outcome new file mode 100644 index 0000000..0e2a85b --- /dev/null +++ b/tools/test/fixtures/crypto_jamfiles/secp256k1_ellswift_default/secp256k1_ellswift_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] +ellswift ok backend=secp256k1 +[wasip2] +ellswift ok backend=secp256k1 +[wasip3] +ellswift ok backend=secp256k1 +[emscripten] +ellswift ok backend=secp256k1 +# end::output[] diff --git a/tools/test/fixtures/crypto_jamfiles/secp256k1_musig_default/Jamfile b/tools/test/fixtures/crypto_jamfiles/secp256k1_musig_default/Jamfile new file mode 100644 index 0000000..d7fd2e8 --- /dev/null +++ b/tools/test/fixtures/crypto_jamfiles/secp256k1_musig_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//secp256k1_musig-default ; +# end::jamfile[] diff --git a/tools/test/fixtures/crypto_jamfiles/secp256k1_musig_default/app.cpp b/tools/test/fixtures/crypto_jamfiles/secp256k1_musig_default/app.cpp new file mode 100644 index 0000000..219f537 --- /dev/null +++ b/tools/test/fixtures/crypto_jamfiles/secp256k1_musig_default/app.cpp @@ -0,0 +1,90 @@ +// 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) + +// Aggregates two fixed key pairs' public keys with BIP 327's MuSig2 on MuSig2's default backend, +// signs a message in its two rounds, verifies the aggregate as one BIP 340 signature, and prints +// the backend that ran. The secrets are fixed: a real program draws its own. The nonces are drawn +// inside nonce_gen. +#include +#include + +#include +#include +#include +#include +#include +#include + +namespace { + +std::array repeated(std::uint8_t value) { + std::array bytes{}; + bytes.fill(value); + return bytes; +} + +namespace secp256k1 = webcpp::crypto::curves::secp256k1; +namespace musig = webcpp::crypto::curves::secp256k1::musig; + +bool sign_and_verify(secp256k1::keypair const& first, secp256k1::keypair const& second) { + auto const first_encoding = first.public_key(); + auto const second_encoding = second.public_key(); + if (!first_encoding || !second_encoding) { + return false; + } + auto const first_key = secp256k1::parse_public_key(*first_encoding); + auto const second_key = secp256k1::parse_public_key(*second_encoding); + if (!first_key || !second_key) { + return false; + } + std::array keys{*first_key, *second_key}; + std::ranges::sort(keys); + alignas(std::max_align_t) std::array space{}; + auto const aggregate = musig::key_aggregate(keys, space); + if (!aggregate) { + return false; + } + auto const message = repeated(0x5a); + auto first_nonce = musig::nonce_gen(first, *aggregate, message); + auto second_nonce = musig::nonce_gen(second, *aggregate, message); + if (!first_nonce || !second_nonce) { + return false; + } + std::array const nonces{first_nonce->public_part, + second_nonce->public_part}; + auto const nonce_sum = musig::nonce_aggregate(nonces, space); + if (!nonce_sum) { + return false; + } + auto const session = musig::nonce_process(*nonce_sum, message, *aggregate); + if (!session) { + return false; + } + auto const first_part = + musig::partial_sign(first, std::move(first_nonce->secret_part), *aggregate, *session); + auto const second_part = + musig::partial_sign(second, std::move(second_nonce->secret_part), *aggregate, *session); + if (!first_part || !second_part) { + return false; + } + std::array const parts{*first_part, *second_part}; + auto const signature = musig::partial_signature_aggregate(*session, parts, space); + return signature && + secp256k1::verify_schnorr(*signature, message, aggregate->xonly_public_key()); +} + +} // namespace + +int main() { + namespace crypto = webcpp::crypto; + auto const first = secp256k1::keypair::make(repeated(0x11)); + auto const second = secp256k1::keypair::make(repeated(0x22)); + bool const ok = first && second && sign_and_verify(*first, *second); + auto const name = crypto::default_backend_t::name; + std::printf("musig %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/secp256k1_musig_default/secp256k1_musig_default.outcome b/tools/test/fixtures/crypto_jamfiles/secp256k1_musig_default/secp256k1_musig_default.outcome new file mode 100644 index 0000000..cb3d876 --- /dev/null +++ b/tools/test/fixtures/crypto_jamfiles/secp256k1_musig_default/secp256k1_musig_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] +musig ok backend=secp256k1 +[wasip2] +musig ok backend=secp256k1 +[wasip3] +musig ok backend=secp256k1 +[emscripten] +musig ok backend=secp256k1 +# end::output[] diff --git a/tools/test/fixtures/crypto_jamfiles/secp256k1_silent_payments_default/Jamfile b/tools/test/fixtures/crypto_jamfiles/secp256k1_silent_payments_default/Jamfile new file mode 100644 index 0000000..59523d0 --- /dev/null +++ b/tools/test/fixtures/crypto_jamfiles/secp256k1_silent_payments_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//secp256k1_silent_payments-default ; +# end::jamfile[] diff --git a/tools/test/fixtures/crypto_jamfiles/secp256k1_silent_payments_default/app.cpp b/tools/test/fixtures/crypto_jamfiles/secp256k1_silent_payments_default/app.cpp new file mode 100644 index 0000000..3bd9eb7 --- /dev/null +++ b/tools/test/fixtures/crypto_jamfiles/secp256k1_silent_payments_default/app.cpp @@ -0,0 +1,85 @@ +// 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) + +// Pays a BIP 352 silent payments recipient (its scan and spend keys) from one fixed input on +// silent payments' default backend, scans the output with the recipient's scan key pair, checks +// that the payment is found as the output created, and prints the backend that ran. The secrets +// are fixed: a real program draws its own. +#include +#include + +#include +#include +#include +#include + +namespace { + +std::array repeated(std::uint8_t value) { + std::array bytes{}; + bytes.fill(value); + return bytes; +} + +namespace secp256k1 = webcpp::crypto::curves::secp256k1; +namespace silent_payments = webcpp::crypto::curves::secp256k1::silent_payments; + +bool pay_and_scan(secp256k1::keypair const& scan_pair, secp256k1::keypair const& spend_pair, + secp256k1::keypair const& donor) { + auto const scan_encoding = scan_pair.public_key(); + auto const spend_encoding = spend_pair.public_key(); + auto const donor_encoding = donor.public_key(); + if (!scan_encoding || !spend_encoding || !donor_encoding) { + return false; + } + auto const scan_key = secp256k1::parse_public_key(*scan_encoding); + auto const spend_key = secp256k1::parse_public_key(*spend_encoding); + auto const donor_key = secp256k1::parse_public_key(*donor_encoding); + if (!scan_key || !spend_key || !donor_key) { + return false; + } + std::array const recipients{ + silent_payments::recipient{.scan_key = *scan_key, .spend_key = *spend_key}}; + std::array smallest_outpoint{}; + smallest_outpoint.fill(0x01); + std::array const plain_inputs{&donor}; + std::array, 1> outputs{}; + alignas(std::max_align_t) std::array + send_space{}; + if (!silent_payments::create_outputs(recipients, smallest_outpoint, {}, plain_inputs, outputs, + send_space)) { + return false; + } + std::array const input_keys{*donor_key}; + alignas(std::max_align_t) std::array + summary_space{}; + auto const summary = + silent_payments::make_prevouts_summary(smallest_outpoint, {}, input_keys, summary_space); + if (!summary) { + return false; + } + std::array found{}; + alignas(std::max_align_t) std::array + scan_space{}; + auto const count = + silent_payments::scan_outputs(scan_pair, *spend_key, *summary, outputs, found, scan_space); + return count && *count == 1 && found[0].output_key == outputs[0]; +} + +} // namespace + +int main() { + namespace crypto = webcpp::crypto; + auto const scan_pair = secp256k1::keypair::make(repeated(0x51)); + auto const spend_pair = secp256k1::keypair::make(repeated(0x52)); + auto const donor = secp256k1::keypair::make(repeated(0x53)); + bool const ok = + scan_pair && spend_pair && donor && pay_and_scan(*scan_pair, *spend_pair, *donor); + auto const name = crypto::default_backend_t::name; + std::printf("silent payments %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/secp256k1_silent_payments_default/secp256k1_silent_payments_default.outcome b/tools/test/fixtures/crypto_jamfiles/secp256k1_silent_payments_default/secp256k1_silent_payments_default.outcome new file mode 100644 index 0000000..14ceb78 --- /dev/null +++ b/tools/test/fixtures/crypto_jamfiles/secp256k1_silent_payments_default/secp256k1_silent_payments_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] +silent payments ok backend=secp256k1 +[wasip2] +silent payments ok backend=secp256k1 +[wasip3] +silent payments ok backend=secp256k1 +[emscripten] +silent payments ok backend=secp256k1 +# end::output[] diff --git a/tools/test/third_party_test.py b/tools/test/third_party_test.py index d0fe8a3..25d0bb6 100755 --- a/tools/test/third_party_test.py +++ b/tools/test/third_party_test.py @@ -85,7 +85,10 @@ BIPS = 'third_party/libs/bips' # The commit the Bitcoin Improvement Proposals' repository is pinned at: the test vectors of -# BIP340 and BIP341 (libs/crypto/test/secp256k1_bip340_test.cpp, secp256k1_xonly_tweak_test.cpp). +# BIP340, BIP341, BIP 324, BIP 327 and BIP 352 (libs/crypto/test/secp256k1_bip340_test.cpp, +# secp256k1_xonly_tweak_test.cpp, secp256k1_ellswift_test.cpp, secp256k1_musig_test.cpp; +# secp256k1_silent_payments_test.cpp reads BIP 352's through libsecp256k1's vectors.h, derived +# from the same file, which test_bip352_vectors_match_libsecp256k1 checks). BIPS_COMMIT = '927b6de9915c9262615a6399de51b200f81e5aa4' BLAKE2 = 'third_party/libs/blake2' @@ -101,6 +104,24 @@ # "Taming the many EdDSAs", its cases.json (libs/crypto/test/ed25519_speccheck_test.cpp). ED25519_SPECCHECK_COMMIT = '65519336fda78a3d016e947df6d82848aca0c9da' +# The files of bitcoin/bips that /third_party//bips depends on, so that a test that names it runs +# again when one of them changes: the vectors the secp256k1 tests read. +BIPS_FILES = [ + 'libs/bips/bip-0340/test-vectors.csv', + 'libs/bips/bip-0341/wallet-test-vectors.json', + 'libs/bips/bip-0324/ellswift_decode_test_vectors.csv', + 'libs/bips/bip-0324/packet_encoding_test_vectors.csv', + 'libs/bips/bip-0327/vectors/det_sign_vectors.json', + 'libs/bips/bip-0327/vectors/key_agg_vectors.json', + 'libs/bips/bip-0327/vectors/key_sort_vectors.json', + 'libs/bips/bip-0327/vectors/nonce_agg_vectors.json', + 'libs/bips/bip-0327/vectors/nonce_gen_vectors.json', + 'libs/bips/bip-0327/vectors/sig_agg_vectors.json', + 'libs/bips/bip-0327/vectors/sign_verify_vectors.json', + 'libs/bips/bip-0327/vectors/tweak_vectors.json', + 'libs/bips/bip-0352/send_and_receive_test_vectors.json', +] + SECP256K1 = 'third_party/libs/secp256k1' # libsecp256k1 v0.8.0, the commit it is pinned at. @@ -333,6 +354,25 @@ def test_ed25519_speccheck_is_pinned(_: Path) -> None: assert listed.stdout.split()[:2] == ['160000', ED25519_SPECCHECK_COMMIT], listed.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) + assert found is not None, 'third_party/Jamfile holds no .bips-files glob' + listed = found.group(1).split() + assert listed == BIPS_FILES, ( + f'missing: {[name for name in BIPS_FILES if name not in listed]}, ' + f'unexpected: {[name for name in listed if name not in BIPS_FILES]}') + + +def test_bip352_vectors_match_libsecp256k1(_: Path) -> None: + # libsecp256k1's vectors.h, which the silent payments test reads, is derived from its copy of + # BIP 352's vectors; the two pins hold the same bytes, so the test checks BIP 352's own. + bips_copy = harness.ROOT / BIPS / 'bip-0352' / 'send_and_receive_test_vectors.json' + secp256k1_copy = (harness.ROOT / SECP256K1 / 'src' / 'modules' / 'silentpayments' + / 'bip352_send_and_receive_test_vectors.json') + assert bips_copy.read_bytes() == secp256k1_copy.read_bytes(), (bips_copy, secp256k1_copy) + + def test_bearssl_is_pinned(_: Path) -> None: listed = subprocess.run(['git', '-C', str(harness.ROOT), 'ls-files', '-s', BEARSSL], capture_output=True, text=True, check=True) @@ -882,6 +922,8 @@ def test_hash_not_checked_out_stops_blake3(root: Path) -> None: test_ed25519_speccheck_not_checked_out_is_refused, test_bips_is_pinned, test_ed25519_speccheck_is_pinned, + test_bips_target_files, + test_bip352_vectors_match_libsecp256k1, test_bearssl_is_pinned, test_bearssl_is_built_file_by_file, test_bearssl_without_hash_has_cryptos_canary_alone,