From 54eb7c0cfeab1d4e4f679b59010b32cb6059d737 Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 12:37:21 -0300 Subject: [PATCH 01/22] libs/crypto: secp256k1's ECDH returns secret<32>, and gives the raw x coordinate and the shared point --- libs/crypto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/crypto b/libs/crypto index 1fc5140..398acb8 160000 --- a/libs/crypto +++ b/libs/crypto @@ -1 +1 @@ -Subproject commit 1fc5140e1a2285b996021de1af354a14397fa68c +Subproject commit 398acb891940a05d1445e9ef6b240a15642bc999 From 26fe0da0a568aec0a12f8c2e82aa4a1af6fe8d13 Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 14:02:17 -0300 Subject: [PATCH 02/22] libs/crypto: secp256k1's recoverable signatures, hedged ECDSA and the parsed public key in both forms --- libs/crypto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/crypto b/libs/crypto index 398acb8..730f3fc 160000 --- a/libs/crypto +++ b/libs/crypto @@ -1 +1 @@ -Subproject commit 398acb891940a05d1445e9ef6b240a15642bc999 +Subproject commit 730f3fc3323105ae2dd6d57415d08fb1c387d3c9 From 3ce4633271c709f5099f9842caccdadef57aec0c Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 14:32:55 -0300 Subject: [PATCH 03/22] libs/crypto: the curves page and its Ethereum rule say what secp256k1's modules added --- libs/crypto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/crypto b/libs/crypto index 730f3fc..294bd2b 160000 --- a/libs/crypto +++ b/libs/crypto @@ -1 +1 @@ -Subproject commit 730f3fc3323105ae2dd6d57415d08fb1c387d3c9 +Subproject commit 294bd2b4190bb3cfc0cf89875e3fc11e39f4414b From 191aa42f9ec2106f7b20bc29a7f51f68b694be79 Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 16:59:48 -0300 Subject: [PATCH 04/22] libs/crypto: secp256k1's tweaks, negation and combination, and its SPKI and PKCS#8 --- libs/crypto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/crypto b/libs/crypto index 294bd2b..9bbad30 160000 --- a/libs/crypto +++ b/libs/crypto @@ -1 +1 @@ -Subproject commit 294bd2b4190bb3cfc0cf89875e3fc11e39f4414b +Subproject commit 9bbad30cf7312ea35e06646eb10b50be722cc2ca From 0aed8db1001cd61dd23aea1f559397452976c968 Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 17:43:26 -0300 Subject: [PATCH 05/22] third_party: BIP 324's ElligatorSwift and packet vectors among the bips target's files --- third_party/Jamfile | 14 +++++++++----- tools/test/third_party_test.py | 23 ++++++++++++++++++++++- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/third_party/Jamfile b/third_party/Jamfile index 81171fa..4336a80 100644 --- a/third_party/Jamfile +++ b/third_party/Jamfile @@ -111,14 +111,18 @@ 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. +# bip-0340/test-vectors.csv, BIP341's bip-0341/wallet-test-vectors.json and +# BIP 324's bip-0324/ellswift_decode_test_vectors.csv and +# bip-0324/packet_encoding_test_vectors.csv 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 ] ; rule bips-checked-out ( properties * ) { diff --git a/tools/test/third_party_test.py b/tools/test/third_party_test.py index d0fe8a3..013cc12 100755 --- a/tools/test/third_party_test.py +++ b/tools/test/third_party_test.py @@ -85,7 +85,8 @@ 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 and BIP 324 (libs/crypto/test/secp256k1_bip340_test.cpp, +# secp256k1_xonly_tweak_test.cpp, secp256k1_ellswift_test.cpp). BIPS_COMMIT = '927b6de9915c9262615a6399de51b200f81e5aa4' BLAKE2 = 'third_party/libs/blake2' @@ -101,6 +102,15 @@ # "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', +] + SECP256K1 = 'third_party/libs/secp256k1' # libsecp256k1 v0.8.0, the commit it is pinned at. @@ -333,6 +343,16 @@ 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_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 +902,7 @@ 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_bearssl_is_pinned, test_bearssl_is_built_file_by_file, test_bearssl_without_hash_has_cryptos_canary_alone, From 4455fc75620fc79b289a9ec425baaf6677228740 Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 17:43:26 -0300 Subject: [PATCH 06/22] libs/crypto: secp256k1's ElligatorSwift against BIP 324's vectors, and Task 2.3's review fixes --- libs/crypto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/crypto b/libs/crypto index 9bbad30..4573e95 160000 --- a/libs/crypto +++ b/libs/crypto @@ -1 +1 @@ -Subproject commit 9bbad30cf7312ea35e06646eb10b50be722cc2ca +Subproject commit 4573e957e2ddb4f394579eda8bf6fea59b0e1dfb From b1852d2cc6bd957516cb1cdf28268947419f99a6 Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 18:55:56 -0300 Subject: [PATCH 07/22] third_party: the bips target's comment states each BIP's licence, BIP 324's BSD-3-Clause included --- third_party/Jamfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/third_party/Jamfile b/third_party/Jamfile index 4336a80..ac8cc10 100644 --- a/third_party/Jamfile +++ b/third_party/Jamfile @@ -109,8 +109,9 @@ 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 +# bitcoin/bips, shallow: test data, never compiled, each BIP's files under the +# licence its header states (BIP340 BSD-2-Clause; BIP341 and BIP 324 +# BSD-3-Clause). A test that names bips reads BIP340's # bip-0340/test-vectors.csv, BIP341's bip-0341/wallet-test-vectors.json and # BIP 324's bip-0324/ellswift_decode_test_vectors.csv and # bip-0324/packet_encoding_test_vectors.csv from the directory From 0c50aa25ee2f68454bc974821cc4c2eb844f0cdf Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 19:08:32 -0300 Subject: [PATCH 08/22] third_party: BIP 327's vectors among the bips target's files --- third_party/Jamfile | 17 +++++++++++++---- tools/test/third_party_test.py | 12 ++++++++++-- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/third_party/Jamfile b/third_party/Jamfile index ac8cc10..db2586a 100644 --- a/third_party/Jamfile +++ b/third_party/Jamfile @@ -110,11 +110,12 @@ alias wycheproof : : @wycheproof-checked-out : : explicit wycheproof ; # bitcoin/bips, shallow: test data, never compiled, each BIP's files under the -# licence its header states (BIP340 BSD-2-Clause; BIP341 and BIP 324 +# licence its header states (BIP340 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 and +# 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 from the directory +# bip-0324/packet_encoding_test_vectors.csv, and BIP 327's eight +# bip-0327/vectors/*_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 files # changes. @@ -123,7 +124,15 @@ path-constant BIPS : libs/bips ; .bips-files = [ glob 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-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 ] ; rule bips-checked-out ( properties * ) { diff --git a/tools/test/third_party_test.py b/tools/test/third_party_test.py index 013cc12..b23d0fc 100755 --- a/tools/test/third_party_test.py +++ b/tools/test/third_party_test.py @@ -85,8 +85,8 @@ BIPS = 'third_party/libs/bips' # The commit the Bitcoin Improvement Proposals' repository is pinned at: the test vectors of -# BIP340, BIP341 and BIP 324 (libs/crypto/test/secp256k1_bip340_test.cpp, -# secp256k1_xonly_tweak_test.cpp, secp256k1_ellswift_test.cpp). +# BIP340, BIP341, BIP 324 and BIP 327 (libs/crypto/test/secp256k1_bip340_test.cpp, +# secp256k1_xonly_tweak_test.cpp, secp256k1_ellswift_test.cpp, secp256k1_musig_test.cpp). BIPS_COMMIT = '927b6de9915c9262615a6399de51b200f81e5aa4' BLAKE2 = 'third_party/libs/blake2' @@ -109,6 +109,14 @@ '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', ] SECP256K1 = 'third_party/libs/secp256k1' From 163aa7e47774669718443d36444c46b948316012 Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 19:58:40 -0300 Subject: [PATCH 09/22] libs/crypto: secp256k1's MuSig2 against BIP 327's vectors, and Task 2.4's review fixes --- libs/crypto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/crypto b/libs/crypto index 4573e95..8d92728 160000 --- a/libs/crypto +++ b/libs/crypto @@ -1 +1 @@ -Subproject commit 4573e957e2ddb4f394579eda8bf6fea59b0e1dfb +Subproject commit 8d9272828e451f3728c40f90451b9c465c2b44aa From 59309491b58cfc52026865d196912c99de83ba4d Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 20:31:02 -0300 Subject: [PATCH 10/22] third_party: BIP 352's vectors among the bips target's files, the same as libsecp256k1's copy --- third_party/Jamfile | 13 ++++++++----- tools/test/third_party_test.py | 17 +++++++++++++++-- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/third_party/Jamfile b/third_party/Jamfile index db2586a..6152f7e 100644 --- a/third_party/Jamfile +++ b/third_party/Jamfile @@ -110,12 +110,14 @@ alias wycheproof : : @wycheproof-checked-out : : explicit wycheproof ; # bitcoin/bips, shallow: test data, never compiled, each BIP's files under the -# licence its header states (BIP340 BSD-2-Clause; BIP341, BIP 324 and BIP 327 -# BSD-3-Clause). A test that names bips reads BIP340's +# 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, and BIP 327's eight -# bip-0327/vectors/*_vectors.json from the directory +# 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. @@ -132,7 +134,8 @@ path-constant BIPS : libs/bips ; 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-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/third_party_test.py b/tools/test/third_party_test.py index b23d0fc..25d0bb6 100755 --- a/tools/test/third_party_test.py +++ b/tools/test/third_party_test.py @@ -85,8 +85,10 @@ BIPS = 'third_party/libs/bips' # The commit the Bitcoin Improvement Proposals' repository is pinned at: the test vectors of -# BIP340, BIP341, BIP 324 and BIP 327 (libs/crypto/test/secp256k1_bip340_test.cpp, -# secp256k1_xonly_tweak_test.cpp, secp256k1_ellswift_test.cpp, secp256k1_musig_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' @@ -117,6 +119,7 @@ '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' @@ -361,6 +364,15 @@ def test_bips_target_files(_: Path) -> None: 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) @@ -911,6 +923,7 @@ def test_hash_not_checked_out_stops_blake3(root: Path) -> None: 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, From a63b2ba6237074bbae743f591a1b41d6ea6338bb Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 20:31:03 -0300 Subject: [PATCH 11/22] libs/crypto: secp256k1's silent payments against BIP 352's vectors, and Task 2.5's review fixes --- libs/crypto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/crypto b/libs/crypto index 8d92728..807d967 160000 --- a/libs/crypto +++ b/libs/crypto @@ -1 +1 @@ -Subproject commit 8d9272828e451f3728c40f90451b9c465c2b44aa +Subproject commit 807d967774f6836914058ec3996fc0ab53e8232b From f4afa7af887ac852fe4044ba098703846d5ea36a Mon Sep 17 00:00:00 2001 From: R Date: Tue, 17 Nov 2026 21:47:04 -0300 Subject: [PATCH 12/22] libs/crypto: secp256k1's modules as families of their own, and Task 2.6's review fixes --- libs/crypto | 2 +- .../secp256k1_ellswift_default/Jamfile | 9 ++ .../secp256k1_ellswift_default/app.cpp | 52 ++++++++++++ .../secp256k1_ellswift_default.outcome | 20 +++++ .../secp256k1_musig_default/Jamfile | 9 ++ .../secp256k1_musig_default/app.cpp | 85 +++++++++++++++++++ .../secp256k1_musig_default.outcome | 20 +++++ .../secp256k1_silent_payments_default/Jamfile | 9 ++ .../secp256k1_silent_payments_default/app.cpp | 79 +++++++++++++++++ .../secp256k1_silent_payments_default.outcome | 20 +++++ 10 files changed, 304 insertions(+), 1 deletion(-) create mode 100644 tools/test/fixtures/crypto_jamfiles/secp256k1_ellswift_default/Jamfile create mode 100644 tools/test/fixtures/crypto_jamfiles/secp256k1_ellswift_default/app.cpp create mode 100644 tools/test/fixtures/crypto_jamfiles/secp256k1_ellswift_default/secp256k1_ellswift_default.outcome create mode 100644 tools/test/fixtures/crypto_jamfiles/secp256k1_musig_default/Jamfile create mode 100644 tools/test/fixtures/crypto_jamfiles/secp256k1_musig_default/app.cpp create mode 100644 tools/test/fixtures/crypto_jamfiles/secp256k1_musig_default/secp256k1_musig_default.outcome create mode 100644 tools/test/fixtures/crypto_jamfiles/secp256k1_silent_payments_default/Jamfile create mode 100644 tools/test/fixtures/crypto_jamfiles/secp256k1_silent_payments_default/app.cpp create mode 100644 tools/test/fixtures/crypto_jamfiles/secp256k1_silent_payments_default/secp256k1_silent_payments_default.outcome diff --git a/libs/crypto b/libs/crypto index 807d967..b4ad83f 160000 --- a/libs/crypto +++ b/libs/crypto @@ -1 +1 @@ -Subproject commit 807d967774f6836914058ec3996fc0ab53e8232b +Subproject commit b4ad83f672fd8eb04a3c26b62bba0a1d3ebf1269 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..c91bfb6 --- /dev/null +++ b/tools/test/fixtures/crypto_jamfiles/secp256k1_ellswift_default/app.cpp @@ -0,0 +1,52 @@ +// 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(); + if (sent && received && initiator_key && + secp256k1::serialize_public_key(secp256k1::ellswift_decode(*sent)) == *initiator_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..ef89a6d --- /dev/null +++ b/tools/test/fixtures/crypto_jamfiles/secp256k1_musig_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) + +// 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_key = secp256k1::parse_public_key(*first.public_key()); + auto const second_key = secp256k1::parse_public_key(*second.public_key()); + 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..9545715 --- /dev/null +++ b/tools/test/fixtures/crypto_jamfiles/secp256k1_silent_payments_default/app.cpp @@ -0,0 +1,79 @@ +// 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 address 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 paid, 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_key = secp256k1::parse_public_key(*scan_pair.public_key()); + auto const spend_key = secp256k1::parse_public_key(*spend_pair.public_key()); + auto const donor_key = secp256k1::parse_public_key(*donor.public_key()); + 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[] From 7a5d0afe0ff500590baf6eeaf729d366fd2baa7a Mon Sep 17 00:00:00 2001 From: R Date: Wed, 18 Nov 2026 02:20:18 -0300 Subject: [PATCH 13/22] tools: libs/crypto at the fix round 1 of the secp256k1 module families --- libs/crypto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/crypto b/libs/crypto index b4ad83f..c5059f1 160000 --- a/libs/crypto +++ b/libs/crypto @@ -1 +1 @@ -Subproject commit b4ad83f672fd8eb04a3c26b62bba0a1d3ebf1269 +Subproject commit c5059f13321775282cde0e228e1e476b10917f36 From e0ed1f67a30f9c01f854f4106ad6d37969d386bd Mon Sep 17 00:00:00 2001 From: R Date: Wed, 18 Nov 2026 03:23:27 -0300 Subject: [PATCH 14/22] tools: libs/crypto at the fix round 2 of the secp256k1 module families --- libs/crypto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/crypto b/libs/crypto index c5059f1..178373d 160000 --- a/libs/crypto +++ b/libs/crypto @@ -1 +1 @@ -Subproject commit c5059f13321775282cde0e228e1e476b10917f36 +Subproject commit 178373dc0faa94af24196f6ff8f1f29f0ce95c6b From c50371e32a305b3616861dbcc407651efa101ab3 Mon Sep 17 00:00:00 2001 From: R Date: Wed, 18 Nov 2026 07:57:32 -0300 Subject: [PATCH 15/22] tools: the secp256k1 module fixtures check the responder's encoding and every public key --- .../secp256k1_ellswift_default/app.cpp | 7 +++++-- .../secp256k1_musig_default/app.cpp | 9 +++++++-- .../secp256k1_silent_payments_default/app.cpp | 20 ++++++++++++------- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/tools/test/fixtures/crypto_jamfiles/secp256k1_ellswift_default/app.cpp b/tools/test/fixtures/crypto_jamfiles/secp256k1_ellswift_default/app.cpp index c91bfb6..e6d0ec2 100644 --- a/tools/test/fixtures/crypto_jamfiles/secp256k1_ellswift_default/app.cpp +++ b/tools/test/fixtures/crypto_jamfiles/secp256k1_ellswift_default/app.cpp @@ -36,8 +36,11 @@ int main() { 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(); - if (sent && received && initiator_key && - secp256k1::serialize_public_key(secp256k1::ellswift_decode(*sent)) == *initiator_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, 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 ef89a6d..219f537 100644 --- a/tools/test/fixtures/crypto_jamfiles/secp256k1_musig_default/app.cpp +++ b/tools/test/fixtures/crypto_jamfiles/secp256k1_musig_default/app.cpp @@ -30,8 +30,13 @@ 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_key = secp256k1::parse_public_key(*first.public_key()); - auto const second_key = secp256k1::parse_public_key(*second.public_key()); + 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; } 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 index 9545715..3bd9eb7 100644 --- a/tools/test/fixtures/crypto_jamfiles/secp256k1_silent_payments_default/app.cpp +++ b/tools/test/fixtures/crypto_jamfiles/secp256k1_silent_payments_default/app.cpp @@ -4,10 +4,10 @@ // accompanying file LICENSE_1_0.txt or copy at // https://www.boost.org/LICENSE_1_0.txt) -// Pays a BIP 352 silent payments address 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 paid, and prints the backend that ran. The secrets are fixed: a real program -// draws its own. +// 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 @@ -29,9 +29,15 @@ 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_key = secp256k1::parse_public_key(*scan_pair.public_key()); - auto const spend_key = secp256k1::parse_public_key(*spend_pair.public_key()); - auto const donor_key = secp256k1::parse_public_key(*donor.public_key()); + 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; } From 12e0d6fbbaf632741f565f0182fe294cc4611626 Mon Sep 17 00:00:00 2001 From: R Date: Wed, 18 Nov 2026 08:18:34 -0300 Subject: [PATCH 16/22] tools: libs/crypto at secp256k1's keys in PEM --- libs/crypto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/crypto b/libs/crypto index 178373d..8218b9e 160000 --- a/libs/crypto +++ b/libs/crypto @@ -1 +1 @@ -Subproject commit 178373dc0faa94af24196f6ff8f1f29f0ce95c6b +Subproject commit 8218b9e114fd38ff63641e3024fe50e320787788 From b784a9ba8e299bea6d71c631d45df9c68bcf6f78 Mon Sep 17 00:00:00 2001 From: R Date: Wed, 18 Nov 2026 18:24:17 -0300 Subject: [PATCH 17/22] libs/crypto: clang-tidy passes on the secp256k1 header, tests and examples --- libs/crypto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/crypto b/libs/crypto index 8218b9e..cd7ea7c 160000 --- a/libs/crypto +++ b/libs/crypto @@ -1 +1 @@ -Subproject commit 8218b9e114fd38ff63641e3024fe50e320787788 +Subproject commit cd7ea7c60e109140aeb00f707c458363d2636cf8 From 518eed15a5f4953e4c5fa187a7b022003197e7a5 Mon Sep 17 00:00:00 2001 From: R Date: Thu, 19 Nov 2026 00:06:22 -0300 Subject: [PATCH 18/22] libs/crypto: secp256k1's constant-time cases, sizes and teaching sections, and their fix round 1 (gitlink 62b0412) --- libs/crypto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/crypto b/libs/crypto index cd7ea7c..62b0412 160000 --- a/libs/crypto +++ b/libs/crypto @@ -1 +1 @@ -Subproject commit cd7ea7c60e109140aeb00f707c458363d2636cf8 +Subproject commit 62b0412e372013b3486c0cfca54f570ee385d0d9 From 4d6a3b091914f3a013d1b3eedaf57850eadd6026 Mon Sep 17 00:00:00 2001 From: R Date: Thu, 19 Nov 2026 17:38:59 -0300 Subject: [PATCH 19/22] libs/crypto: two MuSig2 examples, the network's byte buffers and a Taproot key-path output (gitlink 0f450ef) --- libs/crypto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/crypto b/libs/crypto index 62b0412..0f450ef 160000 --- a/libs/crypto +++ b/libs/crypto @@ -1 +1 @@ -Subproject commit 62b0412e372013b3486c0cfca54f570ee385d0d9 +Subproject commit 0f450ef949574871250c026e778e31418934ac96 From 2b99ec6395eb79edce2ca06bad196974ea884c62 Mon Sep 17 00:00:00 2001 From: R Date: Thu, 19 Nov 2026 17:57:42 -0300 Subject: [PATCH 20/22] libs/crypto: the B final fix wave, a label lookup's exact result type and the review's documentation fixes (gitlink 24397cd) --- libs/crypto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/crypto b/libs/crypto index 0f450ef..24397cd 160000 --- a/libs/crypto +++ b/libs/crypto @@ -1 +1 @@ -Subproject commit 0f450ef949574871250c026e778e31418934ac96 +Subproject commit 24397cdb27c3234c4115f28b7e7c66308379bc37 From 221357ecc4ca2afb71a762f78a8cf5dc512cd687 Mon Sep 17 00:00:00 2001 From: R Date: Thu, 19 Nov 2026 22:06:59 -0300 Subject: [PATCH 21/22] libs/crypto: the B full verification's MSVC fix, two secp256k1 tests' byte lists typed as std::uint8_t (gitlink e7c71db) --- libs/crypto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/crypto b/libs/crypto index 24397cd..e7c71db 160000 --- a/libs/crypto +++ b/libs/crypto @@ -1 +1 @@ -Subproject commit 24397cdb27c3234c4115f28b7e7c66308379bc37 +Subproject commit e7c71dbdd4ac2f9a477e092914ee7f414e9ff63c From d25b22f01bcc6b4ffbf58eb04b7c8b799bc70b1f Mon Sep 17 00:00:00 2001 From: R Date: Thu, 19 Nov 2026 22:56:42 -0300 Subject: [PATCH 22/22] guidelines: chapter 17 states webcpp::crypto's increment 2 as built, and increment 1 merged --- CODING-GUIDELINES.md | 81 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 63 insertions(+), 18 deletions(-) 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