Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
54eb7c0
libs/crypto: secp256k1's ECDH returns secret<32>, and gives the raw x…
Nov 17, 2026
26fe0da
libs/crypto: secp256k1's recoverable signatures, hedged ECDSA and the…
Nov 17, 2026
3ce4633
libs/crypto: the curves page and its Ethereum rule say what secp256k1…
Nov 17, 2026
191aa42
libs/crypto: secp256k1's tweaks, negation and combination, and its SP…
Nov 17, 2026
0aed8db
third_party: BIP 324's ElligatorSwift and packet vectors among the bi…
Nov 17, 2026
4455fc7
libs/crypto: secp256k1's ElligatorSwift against BIP 324's vectors, an…
Nov 17, 2026
b1852d2
third_party: the bips target's comment states each BIP's licence, BIP…
Nov 17, 2026
0c50aa2
third_party: BIP 327's vectors among the bips target's files
Nov 17, 2026
163aa7e
libs/crypto: secp256k1's MuSig2 against BIP 327's vectors, and Task 2…
Nov 17, 2026
5930949
third_party: BIP 352's vectors among the bips target's files, the sam…
Nov 17, 2026
a63b2ba
libs/crypto: secp256k1's silent payments against BIP 352's vectors, a…
Nov 17, 2026
f4afa7a
libs/crypto: secp256k1's modules as families of their own, and Task 2…
Nov 18, 2026
7a5d0af
tools: libs/crypto at the fix round 1 of the secp256k1 module families
Nov 18, 2026
e0ed1f6
tools: libs/crypto at the fix round 2 of the secp256k1 module families
Nov 18, 2026
c50371e
tools: the secp256k1 module fixtures check the responder's encoding a…
Nov 18, 2026
12e0d6f
tools: libs/crypto at secp256k1's keys in PEM
Nov 18, 2026
b784a9b
libs/crypto: clang-tidy passes on the secp256k1 header, tests and exa…
Nov 18, 2026
518eed1
libs/crypto: secp256k1's constant-time cases, sizes and teaching sect…
Nov 19, 2026
4d6a3b0
libs/crypto: two MuSig2 examples, the network's byte buffers and a Ta…
Nov 19, 2026
2b99ec6
libs/crypto: the B final fix wave, a label lookup's exact result type…
Nov 19, 2026
221357e
libs/crypto: the B full verification's MSVC fix, two secp256k1 tests'…
Nov 20, 2026
d25b22f
guidelines: chapter 17 states webcpp::crypto's increment 2 as built, …
Nov 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 63 additions & 18 deletions CODING-GUIDELINES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<N>` with the errors 15 to 20. `supports_v` and
Expand All @@ -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<std::span<std::uint8_t const, 32>>` 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
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion libs/crypto
Submodule crypto updated 119 files
31 changes: 24 additions & 7 deletions third_party/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,33 @@ alias wycheproof : : <conditional>@wycheproof-checked-out : :
<dependency>$(.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 * )
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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[]
Original file line number Diff line number Diff line change
@@ -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 <webcpp/crypto/curves/secp256k1.hpp>
#include <webcpp/crypto/curves/secp256k1/ellswift.hpp>
#include <webcpp/crypto/equal.hpp>

#include <array>
#include <cstdint>
#include <cstdio>

namespace {

std::array<std::uint8_t, 32> repeated(std::uint8_t value) {
std::array<std::uint8_t, 32> 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<crypto::families::secp256k1_ellswift>::name;
std::printf("ellswift %s backend=%.*s\n", ok ? "ok" : "FAILED", static_cast<int>(name.size()),
name.data());
return ok ? 0 : 1;
}
Original file line number Diff line number Diff line change
@@ -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[]
Original file line number Diff line number Diff line change
@@ -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[]
Original file line number Diff line number Diff line change
@@ -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 <webcpp/crypto/curves/secp256k1.hpp>
#include <webcpp/crypto/curves/secp256k1/musig.hpp>

#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <utility>

namespace {

std::array<std::uint8_t, 32> repeated(std::uint8_t value) {
std::array<std::uint8_t, 32> 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<secp256k1::public_key, 2> keys{*first_key, *second_key};
std::ranges::sort(keys);
alignas(std::max_align_t) std::array<std::byte, musig::workspace_size(2)> 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<musig::public_nonce, 2> 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<musig::partial_signature, 2> 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<crypto::families::secp256k1_musig>::name;
std::printf("musig %s backend=%.*s\n", ok ? "ok" : "FAILED", static_cast<int>(name.size()),
name.data());
return ok ? 0 : 1;
}
Original file line number Diff line number Diff line change
@@ -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[]
Original file line number Diff line number Diff line change
@@ -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[]
Loading
Loading