From 6178afd87c8b7af679956fb2517f84d5a7815efa Mon Sep 17 00:00:00 2001 From: R Date: Sun, 22 Nov 2026 14:50:24 -0300 Subject: [PATCH 01/11] crypto fixtures: Ed25519's Jamfile fixtures sign with crypto::eddsa and verify with crypto::verify --- .../fixtures/crypto_jamfiles/ed25519_default/app.cpp | 8 +++++--- .../ed25519_unknown_policy_on_emscripten/app.cpp | 11 ++++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/tools/test/fixtures/crypto_jamfiles/ed25519_default/app.cpp b/tools/test/fixtures/crypto_jamfiles/ed25519_default/app.cpp index 17bda9b..64f6c14 100644 --- a/tools/test/fixtures/crypto_jamfiles/ed25519_default/app.cpp +++ b/tools/test/fixtures/crypto_jamfiles/ed25519_default/app.cpp @@ -9,6 +9,7 @@ // it, and prints the backend that ran. The seed is the RFC's: a real program draws its own. #include #include +#include #include #include @@ -16,6 +17,7 @@ #include int main() { + namespace crypto = webcpp::crypto; namespace ed25519 = webcpp::crypto::curves::ed25519; std::array const seed{ 0x9d, 0x61, 0xb1, 0x9d, 0xef, 0xfd, 0x5a, 0x60, 0xba, 0x84, 0x4a, @@ -33,10 +35,10 @@ int main() { auto const key = ed25519::keypair::make(seed); bool ok = false; if (key) { - auto const signature = key->sign(message); + auto const signature = key->sign(crypto::eddsa, message); auto const public_key = key->public_key(); - ok = signature && public_key && webcpp::crypto::equal(*signature, expected) && - ed25519::verify(*public_key, message, *signature).has_value(); + ok = signature && public_key && crypto::equal(*signature, expected) && + crypto::verify(crypto::eddsa, *signature, message, *public_key).has_value(); } auto const name = ed25519::keypair::backend_type::name; std::printf("ed25519 %s backend=%.*s\n", ok ? "ok" : "FAILED", static_cast(name.size()), diff --git a/tools/test/fixtures/crypto_jamfiles/ed25519_unknown_policy_on_emscripten/app.cpp b/tools/test/fixtures/crypto_jamfiles/ed25519_unknown_policy_on_emscripten/app.cpp index fc97fcc..e801369 100644 --- a/tools/test/fixtures/crypto_jamfiles/ed25519_unknown_policy_on_emscripten/app.cpp +++ b/tools/test/fixtures/crypto_jamfiles/ed25519_unknown_policy_on_emscripten/app.cpp @@ -4,12 +4,14 @@ // accompanying file LICENSE_1_0.txt or copy at // https://www.boost.org/LICENSE_1_0.txt) -// A program that names a policy of its own in Ed25519's verify, on its default backend linked, -// stops where it calls it, with the one policy there is. +// A program that names a policy of its own in Ed25519's crypto::verify, on its default backend +// linked, stops where it calls it, with the one policy there is. #include +#include #include #include +#include namespace { @@ -21,5 +23,8 @@ struct lenient {}; int main() { std::array const public_key{}; std::array const signature{}; - return webcpp::crypto::curves::ed25519::verify(public_key, {}, signature) ? 0 : 1; + return webcpp::crypto::verify(webcpp::crypto::eddsa, signature, + std::span{}, public_key) + ? 0 + : 1; } From 19c9a6b9592d94ca34d5ddeb0391d909ae4d7d1e Mon Sep 17 00:00:00 2001 From: R Date: Sun, 22 Nov 2026 15:57:54 -0300 Subject: [PATCH 02/11] crypto fixtures: secp256k1's Jamfile fixtures sign with their scheme tags, and Ed25519's policy is an argument --- .../crypto_jamfiles/canary_secp256k1_missing/app.cpp | 3 ++- .../crypto_jamfiles/canary_secp256k1_small/app.cpp | 3 ++- .../ed25519_unknown_policy_on_emscripten/app.cpp | 4 ++-- .../fixtures/crypto_jamfiles/encrypt_and_sign/app.cpp | 9 ++++++--- .../fixtures/crypto_jamfiles/secp256k1_default/app.cpp | 5 +++-- .../crypto_jamfiles/secp256k1_musig_default/app.cpp | 5 +++-- tools/test/fixtures/crypto_jamfiles/sign/sign.cpp | 9 ++++++--- tools/test/fixtures/crypto_jamfiles/sign_small/sign.cpp | 9 ++++++--- 8 files changed, 30 insertions(+), 17 deletions(-) diff --git a/tools/test/fixtures/crypto_jamfiles/canary_secp256k1_missing/app.cpp b/tools/test/fixtures/crypto_jamfiles/canary_secp256k1_missing/app.cpp index b0df35e..f6b4a1b 100644 --- a/tools/test/fixtures/crypto_jamfiles/canary_secp256k1_missing/app.cpp +++ b/tools/test/fixtures/crypto_jamfiles/canary_secp256k1_missing/app.cpp @@ -7,6 +7,7 @@ // Makes a key pair and signs once: the program reads libsecp256k1's canary, so that a library // built other than by webcpp's third_party/Jamfile fails to link. #include +#include #include #include @@ -17,5 +18,5 @@ int main() { std::array const message{}; std::array const aux{}; auto key = webcpp::crypto::curves::secp256k1::keypair::make(secret); - return key && key->sign_schnorr(message, aux) ? 0 : 1; + return key && key->sign(webcpp::crypto::schnorr, message, aux) ? 0 : 1; } diff --git a/tools/test/fixtures/crypto_jamfiles/canary_secp256k1_small/app.cpp b/tools/test/fixtures/crypto_jamfiles/canary_secp256k1_small/app.cpp index b0df35e..f6b4a1b 100644 --- a/tools/test/fixtures/crypto_jamfiles/canary_secp256k1_small/app.cpp +++ b/tools/test/fixtures/crypto_jamfiles/canary_secp256k1_small/app.cpp @@ -7,6 +7,7 @@ // Makes a key pair and signs once: the program reads libsecp256k1's canary, so that a library // built other than by webcpp's third_party/Jamfile fails to link. #include +#include #include #include @@ -17,5 +18,5 @@ int main() { std::array const message{}; std::array const aux{}; auto key = webcpp::crypto::curves::secp256k1::keypair::make(secret); - return key && key->sign_schnorr(message, aux) ? 0 : 1; + return key && key->sign(webcpp::crypto::schnorr, message, aux) ? 0 : 1; } diff --git a/tools/test/fixtures/crypto_jamfiles/ed25519_unknown_policy_on_emscripten/app.cpp b/tools/test/fixtures/crypto_jamfiles/ed25519_unknown_policy_on_emscripten/app.cpp index e801369..84c4670 100644 --- a/tools/test/fixtures/crypto_jamfiles/ed25519_unknown_policy_on_emscripten/app.cpp +++ b/tools/test/fixtures/crypto_jamfiles/ed25519_unknown_policy_on_emscripten/app.cpp @@ -23,8 +23,8 @@ struct lenient {}; int main() { std::array const public_key{}; std::array const signature{}; - return webcpp::crypto::verify(webcpp::crypto::eddsa, signature, - std::span{}, public_key) + return webcpp::crypto::verify(webcpp::crypto::eddsa, signature, std::span{}, + public_key, lenient{}) ? 0 : 1; } diff --git a/tools/test/fixtures/crypto_jamfiles/encrypt_and_sign/app.cpp b/tools/test/fixtures/crypto_jamfiles/encrypt_and_sign/app.cpp index 355a9bc..c5eef9e 100644 --- a/tools/test/fixtures/crypto_jamfiles/encrypt_and_sign/app.cpp +++ b/tools/test/fixtures/crypto_jamfiles/encrypt_and_sign/app.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -48,12 +49,14 @@ int main() { auto pair = secp256k1::keypair::make(secret); bool signed_ok = false; if (pair) { - auto const signature = pair->sign_schnorr(message, aux); + auto const signature = pair->sign(webcpp::crypto::schnorr, message, aux); auto const public_key = pair->xonly_public_key(); signed_ok = - signature && public_key && secp256k1::verify_schnorr(*signature, message, *public_key); + signature && public_key && + webcpp::crypto::verify(webcpp::crypto::schnorr, *signature, message, *public_key); message[0] ^= 1U; - signed_ok = signed_ok && !secp256k1::verify_schnorr(*signature, message, *public_key); + signed_ok = signed_ok && !webcpp::crypto::verify(webcpp::crypto::schnorr, *signature, + message, *public_key); } std::printf("schnorr %s\n", signed_ok ? "ok" : "FAILED"); return sealed && opened && signed_ok ? 0 : 1; diff --git a/tools/test/fixtures/crypto_jamfiles/secp256k1_default/app.cpp b/tools/test/fixtures/crypto_jamfiles/secp256k1_default/app.cpp index 84d7bac..6643a0f 100644 --- a/tools/test/fixtures/crypto_jamfiles/secp256k1_default/app.cpp +++ b/tools/test/fixtures/crypto_jamfiles/secp256k1_default/app.cpp @@ -9,6 +9,7 @@ // and prints the backend that ran. The secret key is the vector's: a real program draws its own. #include #include +#include #include #include @@ -30,10 +31,10 @@ int main() { auto const key = secp256k1::keypair::make(secret); bool ok = false; if (key) { - auto const signature = key->sign_schnorr(message, aux); + auto const signature = key->sign(webcpp::crypto::schnorr, message, aux); auto const public_key = key->xonly_public_key(); ok = signature && public_key && webcpp::crypto::equal(*signature, expected) && - secp256k1::verify_schnorr(*signature, message, *public_key); + webcpp::crypto::verify(webcpp::crypto::schnorr, *signature, message, *public_key); } auto const name = secp256k1::keypair::backend_type::name; std::printf("schnorr %s backend=%.*s\n", ok ? "ok" : "FAILED", static_cast(name.size()), diff --git a/tools/test/fixtures/crypto_jamfiles/secp256k1_musig_default/app.cpp b/tools/test/fixtures/crypto_jamfiles/secp256k1_musig_default/app.cpp index 219f537..b6cfff7 100644 --- a/tools/test/fixtures/crypto_jamfiles/secp256k1_musig_default/app.cpp +++ b/tools/test/fixtures/crypto_jamfiles/secp256k1_musig_default/app.cpp @@ -10,6 +10,7 @@ // inside nonce_gen. #include #include +#include #include #include @@ -72,8 +73,8 @@ bool sign_and_verify(secp256k1::keypair const& first, secp256k1::keypair const& } std::array const parts{*first_part, *second_part}; auto const signature = musig::partial_signature_aggregate(*session, parts, space); - return signature && - secp256k1::verify_schnorr(*signature, message, aggregate->xonly_public_key()); + return signature && webcpp::crypto::verify(webcpp::crypto::schnorr, *signature, message, + aggregate->xonly_public_key()); } } // namespace diff --git a/tools/test/fixtures/crypto_jamfiles/sign/sign.cpp b/tools/test/fixtures/crypto_jamfiles/sign/sign.cpp index fe328c2..d4a9c1c 100644 --- a/tools/test/fixtures/crypto_jamfiles/sign/sign.cpp +++ b/tools/test/fixtures/crypto_jamfiles/sign/sign.cpp @@ -6,6 +6,7 @@ // Signs a message with BIP340 through libsecp256k1, verifies it, and refuses a changed one. #include +#include #include #include @@ -21,11 +22,13 @@ int main() { auto key = secp256k1::keypair::make(secret); bool ok = false; if (key) { - auto const signature = key->sign_schnorr(message, aux); + auto const signature = key->sign(webcpp::crypto::schnorr, message, aux); auto const public_key = key->xonly_public_key(); - ok = signature && public_key && secp256k1::verify_schnorr(*signature, message, *public_key); + ok = signature && public_key && + webcpp::crypto::verify(webcpp::crypto::schnorr, *signature, message, *public_key); message[0] ^= 1U; - ok = ok && !secp256k1::verify_schnorr(*signature, message, *public_key); + ok = ok && + !webcpp::crypto::verify(webcpp::crypto::schnorr, *signature, message, *public_key); } std::printf("schnorr %s\n", ok ? "ok" : "FAILED"); return ok ? 0 : 1; diff --git a/tools/test/fixtures/crypto_jamfiles/sign_small/sign.cpp b/tools/test/fixtures/crypto_jamfiles/sign_small/sign.cpp index fe328c2..d4a9c1c 100644 --- a/tools/test/fixtures/crypto_jamfiles/sign_small/sign.cpp +++ b/tools/test/fixtures/crypto_jamfiles/sign_small/sign.cpp @@ -6,6 +6,7 @@ // Signs a message with BIP340 through libsecp256k1, verifies it, and refuses a changed one. #include +#include #include #include @@ -21,11 +22,13 @@ int main() { auto key = secp256k1::keypair::make(secret); bool ok = false; if (key) { - auto const signature = key->sign_schnorr(message, aux); + auto const signature = key->sign(webcpp::crypto::schnorr, message, aux); auto const public_key = key->xonly_public_key(); - ok = signature && public_key && secp256k1::verify_schnorr(*signature, message, *public_key); + ok = signature && public_key && + webcpp::crypto::verify(webcpp::crypto::schnorr, *signature, message, *public_key); message[0] ^= 1U; - ok = ok && !secp256k1::verify_schnorr(*signature, message, *public_key); + ok = ok && + !webcpp::crypto::verify(webcpp::crypto::schnorr, *signature, message, *public_key); } std::printf("schnorr %s\n", ok ? "ok" : "FAILED"); return ok ? 0 : 1; From fcbab78eb27927fdd56c34b3d110803fd7304b4d Mon Sep 17 00:00:00 2001 From: R Date: Sun, 22 Nov 2026 16:46:55 -0300 Subject: [PATCH 03/11] crypto fixtures: Ed25519's policy fixture verifies with the typed public key --- .../ed25519_unknown_policy_on_emscripten/app.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tools/test/fixtures/crypto_jamfiles/ed25519_unknown_policy_on_emscripten/app.cpp b/tools/test/fixtures/crypto_jamfiles/ed25519_unknown_policy_on_emscripten/app.cpp index 84c4670..30ebac0 100644 --- a/tools/test/fixtures/crypto_jamfiles/ed25519_unknown_policy_on_emscripten/app.cpp +++ b/tools/test/fixtures/crypto_jamfiles/ed25519_unknown_policy_on_emscripten/app.cpp @@ -21,10 +21,12 @@ struct lenient {}; } // namespace int main() { - std::array const public_key{}; + auto const public_key = + webcpp::crypto::curves::ed25519::public_key::make(std::array{}); std::array const signature{}; - return webcpp::crypto::verify(webcpp::crypto::eddsa, signature, std::span{}, - public_key, lenient{}) + return public_key && + webcpp::crypto::verify(webcpp::crypto::eddsa, signature, + std::span{}, *public_key, lenient{}) ? 0 : 1; } From cbb2adca4d8aab311bcbc5099b97c3f7c70eb71e Mon Sep 17 00:00:00 2001 From: R Date: Sun, 22 Nov 2026 17:13:49 -0300 Subject: [PATCH 04/11] crypto fixtures: secp256k1's fixtures use the typed public key and agree --- .../crypto_jamfiles/encrypt_and_sign/app.cpp | 2 +- .../crypto_jamfiles/secp256k1_default/app.cpp | 2 +- .../secp256k1_ellswift_default/app.cpp | 5 ++--- .../crypto_jamfiles/secp256k1_musig_default/app.cpp | 9 ++------- .../secp256k1_silent_payments_default/app.cpp | 12 +++--------- tools/test/fixtures/crypto_jamfiles/sign/sign.cpp | 2 +- .../fixtures/crypto_jamfiles/sign_small/sign.cpp | 2 +- 7 files changed, 11 insertions(+), 23 deletions(-) diff --git a/tools/test/fixtures/crypto_jamfiles/encrypt_and_sign/app.cpp b/tools/test/fixtures/crypto_jamfiles/encrypt_and_sign/app.cpp index c5eef9e..9f68789 100644 --- a/tools/test/fixtures/crypto_jamfiles/encrypt_and_sign/app.cpp +++ b/tools/test/fixtures/crypto_jamfiles/encrypt_and_sign/app.cpp @@ -50,7 +50,7 @@ int main() { bool signed_ok = false; if (pair) { auto const signature = pair->sign(webcpp::crypto::schnorr, message, aux); - auto const public_key = pair->xonly_public_key(); + auto const public_key = pair->public_key(); signed_ok = signature && public_key && webcpp::crypto::verify(webcpp::crypto::schnorr, *signature, message, *public_key); diff --git a/tools/test/fixtures/crypto_jamfiles/secp256k1_default/app.cpp b/tools/test/fixtures/crypto_jamfiles/secp256k1_default/app.cpp index 6643a0f..e26d612 100644 --- a/tools/test/fixtures/crypto_jamfiles/secp256k1_default/app.cpp +++ b/tools/test/fixtures/crypto_jamfiles/secp256k1_default/app.cpp @@ -32,7 +32,7 @@ int main() { bool ok = false; if (key) { auto const signature = key->sign(webcpp::crypto::schnorr, message, aux); - auto const public_key = key->xonly_public_key(); + auto const public_key = key->public_key(); ok = signature && public_key && webcpp::crypto::equal(*signature, expected) && webcpp::crypto::verify(webcpp::crypto::schnorr, *signature, message, *public_key); } 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 e6d0ec2..6f65e02 100644 --- a/tools/test/fixtures/crypto_jamfiles/secp256k1_ellswift_default/app.cpp +++ b/tools/test/fixtures/crypto_jamfiles/secp256k1_ellswift_default/app.cpp @@ -38,9 +38,8 @@ int main() { 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) { + secp256k1::ellswift_decode(*sent) == *initiator_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 b6cfff7..149f598 100644 --- a/tools/test/fixtures/crypto_jamfiles/secp256k1_musig_default/app.cpp +++ b/tools/test/fixtures/crypto_jamfiles/secp256k1_musig_default/app.cpp @@ -31,13 +31,8 @@ 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); + auto const first_key = first.public_key(); + auto const second_key = second.public_key(); 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 3bd9eb7..38b8343 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 @@ -29,15 +29,9 @@ 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); + auto const scan_key = scan_pair.public_key(); + auto const spend_key = spend_pair.public_key(); + auto const donor_key = donor.public_key(); if (!scan_key || !spend_key || !donor_key) { return false; } diff --git a/tools/test/fixtures/crypto_jamfiles/sign/sign.cpp b/tools/test/fixtures/crypto_jamfiles/sign/sign.cpp index d4a9c1c..f634623 100644 --- a/tools/test/fixtures/crypto_jamfiles/sign/sign.cpp +++ b/tools/test/fixtures/crypto_jamfiles/sign/sign.cpp @@ -23,7 +23,7 @@ int main() { bool ok = false; if (key) { auto const signature = key->sign(webcpp::crypto::schnorr, message, aux); - auto const public_key = key->xonly_public_key(); + auto const public_key = key->public_key(); ok = signature && public_key && webcpp::crypto::verify(webcpp::crypto::schnorr, *signature, message, *public_key); message[0] ^= 1U; diff --git a/tools/test/fixtures/crypto_jamfiles/sign_small/sign.cpp b/tools/test/fixtures/crypto_jamfiles/sign_small/sign.cpp index d4a9c1c..f634623 100644 --- a/tools/test/fixtures/crypto_jamfiles/sign_small/sign.cpp +++ b/tools/test/fixtures/crypto_jamfiles/sign_small/sign.cpp @@ -23,7 +23,7 @@ int main() { bool ok = false; if (key) { auto const signature = key->sign(webcpp::crypto::schnorr, message, aux); - auto const public_key = key->xonly_public_key(); + auto const public_key = key->public_key(); ok = signature && public_key && webcpp::crypto::verify(webcpp::crypto::schnorr, *signature, message, *public_key); message[0] ^= 1U; From 897022a73b272a40bf29cbc3bacdb0f624670115 Mon Sep 17 00:00:00 2001 From: R Date: Sun, 22 Nov 2026 17:32:30 -0300 Subject: [PATCH 05/11] guidelines: crypto's examples name sign and crypto::verify with their schemes --- CODING-GUIDELINES.md | 60 ++++++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/CODING-GUIDELINES.md b/CODING-GUIDELINES.md index 92fa571..9a376ee 100644 --- a/CODING-GUIDELINES.md +++ b/CODING-GUIDELINES.md @@ -7133,18 +7133,20 @@ and not built is in chapter 17. creates libsecp256k1's context in it with `secp256k1_context_preallocated_create`, aligned to `alignof(std::max_align_t)`, and randomizes it from `random_device`; - `verify_schnorr` and `verify_ecdsa` use `secp256k1_context_static` after - `secp256k1_selftest()` on every call and allocate nothing.** The resource + `crypto::verify` with `crypto::schnorr` and `crypto::ecdsa_sha256` uses + `secp256k1_context_static` after `secp256k1_selftest()` on every call and + allocates nothing.** The resource serves the context alone, so that the counting test sees every allocation; a run-once flag would be the static mutable state the rulebook forbids. Source: `include/webcpp/crypto/curves/secp256k1.hpp` (libs/crypto). -- **`ecdh` takes the secret into a local array, wipes it on every path, and - returns the SHA-256 of the compressed shared point.** libsecp256k1's - default hash. +- **`agree_hashed` takes the secret into a local array, wipes it on every + path, and returns the SHA-256 of the compressed shared point.** + libsecp256k1's default hash; `agree` gives the raw x and `agree_point` the + point. Source: `libraries/crypto/openspec/changes/genesis/reference/spec.md` section 2.8 (proposals). - **ECDSA's DER is strict (`to_der`, `from_der`, at most 72 bytes) and - `normalize_ecdsa` gives the low-S form; the x-only tweak takes any 32-byte + `normalize_low_s` gives the low-S form; the x-only tweak takes any 32-byte tweak, as a free `tweak_xonly` on an x-only key, giving the key and its parity, and as `keypair::tweak_xonly` in place, and a tweak not below the group order is `invalid_secret_key` and wipes the key pair.** A wallet's @@ -7179,24 +7181,37 @@ and not built is in chapter 17. WebCrypto write, checked by the oracles; anything else is `invalid_encoding`. Source: `include/webcpp/crypto/curves/p256/formats.hpp` (libs/crypto). -- **Low S is two primitives, not a mode: `sign_ecdsa` returns S as computed - and `verify_ecdsa` accepts both forms, as FIPS 186-5 and WebCrypto do; - `normalize_ecdsa` gives the low form and `check_low_s` refuses the high - one, neither calling a backend.** A protocol that requires low S - (Trystero's handshakes) applies them; the protocol itself is - webcpp::trystero's (D24), which the guide's section on signed handshakes +- **ECDSA signs low S on both curves; P-256's verification accepts both + forms, as FIPS 186-5 and WebCrypto do, and secp256k1's refuses a high S.** + P-256's `sign` normalizes RFC 6979's S after signing, selecting n - s by a + mask without a branch; `normalize_low_s` gives the low form of a signature + made elsewhere and `is_low_s` answers whether one is low, neither calling a + backend. A protocol that requires low S of its peers (Trystero's + handshakes) checks `is_low_s` before `crypto::verify`; the protocol itself + is webcpp::trystero's (D24), which the guide's section on signed handshakes shows with an example. Their verdict is marked public for the constant-time checkers, a signature being public once made. Source: `include/webcpp/crypto/curves/p256.hpp`, `doc/p2p.adoc` - (libs/crypto). + (libs/crypto); `libraries/crypto/openspec/changes/unified-sign/design.md` + D3 and D4b (proposals). +- **One name per signing operation, the scheme always named: `key.sign(scheme, + input)` and `crypto::verify(scheme, signature, input, public_key)`, and + their `async_` forms, on Ed25519, P-256 and secp256k1; a digest only as + `crypto::prehashed{digest}`; every key pair a `crypto::keypair`, with a + typed public key, `secret()` and `agree`.** A span is a message whatever + its size, so a 32-byte message is never read as a digest; a pair of scheme + and input that is not valid stops the build with its reason. `Backend` is + the first template parameter of every `crypto::verify`. + Source: `include/webcpp/crypto/signing.hpp`, `keypair.hpp` (libs/crypto); + `libraries/crypto/openspec/changes/unified-sign/design.md` (proposals). - **Constant time, sizes and throughput cover the family.** memcheck and MemorySanitizer run the key pair's making, signing with its low-S - normalization and check, `ecdh_x` and `decode_pkcs8` (`paths.hpp`), each + normalization and check, `agree` and `decode_pkcs8` (`paths.hpp`), each checker failing on a planted early exit in a copy of the scalar check; BearSSL's own branches on its signing's verdicts are listed for memcheck in - `bearssl_verdicts.supp`. dudect times `sign_ecdsa` and `ecdh_x` against the + `bearssl_verdicts.supp`. dudect times `sign` and `agree` against the scalar natively and on wasip2. The sizes lane measures signing, - verification and `ecdh_x`, and the throughput page the same three, from + verification and `agree`, and the throughput page the same three, from release builds. The checkers ran on 2026-11-21 in an arm64 Linux container (`linux-lint:arm64`, clang 18, Valgrind 3.22), the lane's CI command: both found upstream BearSSL's signing branching on the RFC 6979 nonce's bit @@ -7328,7 +7343,7 @@ and not built is in chapter 17. webcpp never calls `RAND_bytes`.** No backend chooses its own entropy. Source: `third_party/Jamfile` (webcpp). - **webcpp's code allocates only `keypair::make`'s context, in the resource - the user gives; no seal, open, `encrypt`, `fill`, signature, `ecdh` or + the user gives; no seal, open, `encrypt`, `fill`, signature, `agree` or verification allocates on any backend; OpenSSL's `make` allocates its context through OpenSSL's own allocator, which its page states and `allocation_openssl` counts, unless the program takes OpenSSL's memory @@ -8753,9 +8768,10 @@ increments 1 and 2, whose state is first. - **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 + libsecp256k1's remaining modules.** ECDH in three forms, each a `secret` + (`agree_hashed`, `agree`, `agree_point` since unified-sign), recoverable + signatures (`sign(crypto::ecdsa_sha256_recoverable, input)` 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 @@ -8787,9 +8803,9 @@ increments 1 and 2, whose state is first. `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 + `agree` 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 + CI's. The sizes lane measures `agree`, `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`. From 5eaf2cb3051bb66d3d808d56b756b43daf2fa05a Mon Sep 17 00:00:00 2001 From: R Date: Sun, 22 Nov 2026 17:37:47 -0300 Subject: [PATCH 06/11] guidelines: crypto's constant-time note says the low-S rerun is pending --- CODING-GUIDELINES.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CODING-GUIDELINES.md b/CODING-GUIDELINES.md index 9a376ee..72f18a7 100644 --- a/CODING-GUIDELINES.md +++ b/CODING-GUIDELINES.md @@ -7212,7 +7212,8 @@ and not built is in chapter 17. `bearssl_verdicts.supp`. dudect times `sign` and `agree` against the scalar natively and on wasip2. The sizes lane measures signing, verification and `agree`, and the throughput page the same three, from - release builds. The checkers ran on 2026-11-21 in an arm64 Linux container + release builds. The checkers ran on 2026-11-21 (the signing before its + low-S step; the rerun with it is pending) in an arm64 Linux container (`linux-lint:arm64`, clang 18, Valgrind 3.22), the lane's CI command: both found upstream BearSSL's signing branching on the RFC 6979 nonce's bit length, `br_ecdsa_i31_bits2int` decoding it with its actual length and From 405f1faf9f8022d478a1b54cd5280a020e0c69cb Mon Sep 17 00:00:00 2001 From: R Date: Sun, 22 Nov 2026 19:18:58 -0300 Subject: [PATCH 07/11] crypto: one sign and verify on every curve, the key pair contract and the four forms of each operation --- libs/crypto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/crypto b/libs/crypto index 185c1e0..f21d798 160000 --- a/libs/crypto +++ b/libs/crypto @@ -1 +1 @@ -Subproject commit 185c1e049be95acbcef29cbac0c1d19989659ffe +Subproject commit f21d798192e9fde20b7292b4229461c6bb95a613 From 2d5ad62183f7027dc19ba3bff37a2ea9159ee3c9 Mon Sep 17 00:00:00 2001 From: R Date: Sun, 22 Nov 2026 19:32:34 -0300 Subject: [PATCH 08/11] crypto: the constant-time lane's rerun of P-256's low-S signing, in the guidelines and the pointer --- CODING-GUIDELINES.md | 18 ++++++++++-------- libs/crypto | 2 +- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/CODING-GUIDELINES.md b/CODING-GUIDELINES.md index 72f18a7..4a91740 100644 --- a/CODING-GUIDELINES.md +++ b/CODING-GUIDELINES.md @@ -7212,15 +7212,17 @@ and not built is in chapter 17. `bearssl_verdicts.supp`. dudect times `sign` and `agree` against the scalar natively and on wasip2. The sizes lane measures signing, verification and `agree`, and the throughput page the same three, from - release builds. The checkers ran on 2026-11-21 (the signing before its - low-S step; the rerun with it is pending) in an arm64 Linux container - (`linux-lint:arm64`, clang 18, Valgrind 3.22), the lane's CI command: both - found upstream BearSSL's signing branching on the RFC 6979 nonce's bit - length, `br_ecdsa_i31_bits2int` decoding it with its actual length and - `br_i31_rshift` looping by it (a Minerva-class leak), and nothing once - webcpp's BearSSL carried the fix, one commit setting the order's length + release builds. The checkers ran on 2026-11-21 and again on 2026-11-22 (the + rerun with the signing's low-S step found nothing under either) in an arm64 + Linux container (`linux-lint:arm64`, clang 18, Valgrind 3.22), the lane's CI + command: both found upstream BearSSL's signing branching on the RFC 6979 + nonce's bit length, `br_ecdsa_i31_bits2int` decoding it with its actual + length and `br_i31_rshift` looping by it (a Minerva-class leak), and nothing + once webcpp's BearSSL carried the fix, one commit setting the order's length before the shift (chapter 5 rule 1); the planted programs failed and dudect - passed there too. + passed there too: dudect judged P-256's signing with its low-S step (|t| + 1.70 on Linux, 1.63 natively on an Apple M5 Max, release, one run each; + provisional, measured again in the final quiet pass). Source: `libs/crypto/test/constant_time/Jamfile`, `test/sizes/Jamfile`, `bench/throughput.cpp`, `doc/backends.adoc` (libs/crypto); https://github.com/webcpporg/bearssl/commit/32381d6e787a32cbb7a687246349200d78b8ff7c diff --git a/libs/crypto b/libs/crypto index f21d798..0f9f8dd 160000 --- a/libs/crypto +++ b/libs/crypto @@ -1 +1 @@ -Subproject commit f21d798192e9fde20b7292b4229461c6bb95a613 +Subproject commit 0f9f8dd7adb438fd45d23ee7af0d81c4d13fa3e2 From ee82989eb117a288a71140173b52314a0ff6196e Mon Sep 17 00:00:00 2001 From: R Date: Sun, 22 Nov 2026 21:07:45 -0300 Subject: [PATCH 09/11] crypto: the missing-include message test's Jam comment keeps to 80 columns --- libs/crypto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/crypto b/libs/crypto index 0f9f8dd..e262e50 160000 --- a/libs/crypto +++ b/libs/crypto @@ -1 +1 @@ -Subproject commit 0f9f8dd7adb438fd45d23ee7af0d81c4d13fa3e2 +Subproject commit e262e506acdac39abc39638368133a580bf8fe1c From 6057a7241a48e15f55642b5e0d2e8b9b36ad96bf Mon Sep 17 00:00:00 2001 From: R Date: Mon, 23 Nov 2026 01:06:59 -0300 Subject: [PATCH 10/11] crypto: the key pair concept hides no user name on MSVC --- libs/crypto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/crypto b/libs/crypto index e262e50..26e5cbf 160000 --- a/libs/crypto +++ b/libs/crypto @@ -1 +1 @@ -Subproject commit e262e506acdac39abc39638368133a580bf8fe1c +Subproject commit 26e5cbfa49a1167abb430cb597056faefad1ba5d From d512cdd35a1ef2e568c89da741fc32a23e47f5b5 Mon Sep 17 00:00:00 2001 From: R Date: Mon, 23 Nov 2026 06:10:17 -0300 Subject: [PATCH 11/11] crypto: the pointer follows webcpporg/crypto's merge of the unified sign --- libs/crypto | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/crypto b/libs/crypto index 26e5cbf..0255206 160000 --- a/libs/crypto +++ b/libs/crypto @@ -1 +1 @@ -Subproject commit 26e5cbfa49a1167abb430cb597056faefad1ba5d +Subproject commit 025520686003828307e7de26f17a645b492f5183