Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,7 @@
path = third_party/libs/hpke
url = https://github.com/cfrg/draft-irtf-cfrg-hpke.git
shallow = true
[submodule "third_party/libs/nip44"]
path = third_party/libs/nip44
url = https://github.com/paulmillr/nip44.git
shallow = true
7 changes: 4 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ webcpp/
a submodule under third_party/libs/, pinned at a commit and keeping its
own licence (openssl, libdatachannel, bearssl, secp256k1, bitcoin for
ctaes, xkcp, libsodium, blake3, and the test data wycheproof, bips,
hpke, JSON-Schema-Test-Suite and nativejson-benchmark), and the Jamfile that
declares it as /webcpp/third_party//<target> and
hpke, nip44, JSON-Schema-Test-Suite and nativejson-benchmark), and the
Jamfile that declares it as /webcpp/third_party//<target> and
/third_party//<target> (guidelines chapter 10)
doc/ the index page (index.adoc, Jamfile)
releases/ each version's release notes, which the index page shows
Expand Down Expand Up @@ -271,7 +271,8 @@ Jamroot is its build configuration, and `libs/<name>` is its repository.
- for crypto: nothing installed, with the pinned submodules initialised:
`git submodule update --init third_party/libs/bearssl
third_party/libs/secp256k1 third_party/libs/bitcoin third_party/libs/wycheproof
third_party/libs/bips third_party/libs/ed25519-speccheck third_party/libs/hpke`, and
third_party/libs/bips third_party/libs/ed25519-speccheck third_party/libs/hpke
third_party/libs/nip44`, and
`third_party/libs/openssl` for its OpenSSL backend (below); b2 builds every
backend from its sources;
- for Botan (`/third_party//botan`, webcpp::hash's `backends::botan` and
Expand Down
77 changes: 62 additions & 15 deletions CODING-GUIDELINES.md
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,7 @@ update --init third_party/libs/<name>`; a build that needs none never looks.
| `json-schema-test-suite` | the JSON Schema Test Suite at `5b0ee16` (2026-09-21), test data: a test that names it reads the suite at run time from the directory its define `WEBCPP_TEST_JSON_SCHEMA_TEST_SUITE` gives, on every target (wasmtime is given it, `webcpp.data`), and runs again when a file of the suite changes | MIT |
| `libdatachannel` | libdatachannel 0.24.6 at `6b1e2e620f1e37f0eafeee702eaea0043cb305fd`, with pinned libjuice, libsrtp, plog and usrsctp sources; static native archives built by upstream CMake through B2 against the same source-built OpenSSL, from a staged copy the patches of `tools/libdatachannel/patches` correct | MPL-2.0 and the nested dependencies' own licences |
| `nativejson-benchmark` | Milo Yip's nativejson-benchmark at `478d572` (2022-10-28), test data: document's benchmarks (`libs/document/bench`) read its `data/canada.json`, `data/citm_catalog.json` and `data/twitter.json` at run time under the directory its define `WEBCPP_TEST_NATIVEJSON_BENCHMARK` gives, on every target (wasmtime is given it, `webcpp.data`), and run again when one of them changes; its own submodules are never checked out | MIT |
| `nip44` | paulmillr/nip44 at `671a1f04` (2024-12-04), shallow, test data: crypto's tests read `nip44.vectors.json`, NIP-44 version 2's vectors, whose SHA-256 NIP-44's text states, at run time under the directory its define `WEBCPP_TEST_NIP44` gives, on every target (wasmtime is given it, `webcpp.data`), and run again when it changes | public domain (the Unlicense of its JavaScript implementation, whose copy of the file is the same bytes) |
| `openssl` | OpenSSL 3.5.9 at `45e844fa2a14ec92d146bd8f5778ac130b6625fb`; static libssl/libcrypto and matching generated headers, built by upstream Configure/Make through B2 for native Clang/GCC/MSVC, WASIp2 single and WASIp3 single/cooperative | Apache-2.0 |
| `secp256k1` | libsecp256k1 v0.8.0 at `6e2c8bc`; a static library built file by file by `third_party/Jamfile` (`src/secp256k1.c` and its two precomputed tables, every module on) with webcpp::crypto's canary, on every target; its tables by `webcpp-secp256k1-tables` (`auto`: small on Emscripten, large elsewhere); `WEBCPP_CRYPTO_HAS_SECP256K1=1` | MIT |
| `sodium` | libsodium 1.0.22 at `77e1ce5`, the submodule `third_party/libs/libsodium`; a static library built file by file by `third_party/Jamfile` (every `.c` of `src/libsodium/`, no assembly, the defines libsodium's configure finds on each target, upstream's `builds/msvc/version.h` copied into the build directory) with webcpp::hash's canary and webcpp::crypto's (`libs/crypto/src/canary_sodium.c`, configuration `portable`), on every target; `WEBCPP_HASH_HAS_SODIUM=1` and `WEBCPP_CRYPTO_HAS_SODIUM=1`; `sodium-test-config` gives a program its private headers and test defines; shared with webcpp::crypto | ISC |
Expand Down Expand Up @@ -8823,9 +8824,10 @@ What webcpp does not have yet, and the chapters that mention it:
randomness are webcpp::crypto's, and the relays' WebSockets Beast's.
Trystero can then retain its protocol over those shared facilities.
- **crypto after 0.1** (chapter 17): the browser lane, the CI's nightly
level, NIST CAVP's vectors and Botan; its key formats on codecs are built,
not merged. Its constant-time lane, its sizes and throughput, and
ChaCha20-Poly1305 merged with the foundation's increment 1.
level, NIST CAVP's vectors and Botan; the raw ChaCha20 and Poly1305 are
built, not merged. Its constant-time lane, its sizes and throughput, and
ChaCha20-Poly1305 merged with the foundation's increment 1, and its key
formats on codecs with the formats change.
- **The libraries web developers use most,** brought to C++: a JavaScript
interpreter (QuickJS), libp2p, HTTP fetch.
- **The site, increments 2 to 8.** Increment 1 is done: the site's
Expand Down Expand Up @@ -8884,13 +8886,13 @@ The proposals the owner accepted whose decisions are not yet in chapter 14 or
15, each with its decisions as decided and its heading saying how much of it the
superproject's `main` holds: wasi's redesign and the site's increments 4 and 5
are not built, codecs and secure are merged, crypto's foundation is merged in
part and its formats change, with hash's Base58Check, is built and not merged,
and hash is merged but for its Base58Check. While a proposal is open, its own
`design.md` and specification hold it in full and rule over this summary; the
change that builds it moves its decisions into chapter 14 or 15. Their conflicts
with chapters 1 to 13 are in chapter 19.
part, its formats change is merged with hash's Base58Check and its primitives
change is built and not merged; hash is merged. While a proposal is open,
its own `design.md` and specification hold it in full and rule over this
summary; the change that builds it moves its decisions into chapter 14 or 15.
Their conflicts with chapters 1 to 13 are in chapter 19.

### crypto, after 0.1 (genesis accepted 2026-10-11, foundation accepted 2026-11-14; the foundation's increments 1 and 2, increment 3's P-256 and increment 4's asynchronous family merged; the formats change built, not merged)
### crypto, after 0.1 (genesis accepted 2026-10-11, foundation accepted 2026-11-14; the foundation's increments 1 and 2, increment 3's P-256 and increment 4's asynchronous family merged; the formats change merged; the primitives change built, not merged)

The genesis's plan (`reference/plan.md`, revised on 2026-11-14) built version
0.1 from its increments 1 and 2, and OpenSSL's memory option after it. The
Expand Down Expand Up @@ -9014,8 +9016,9 @@ Tasks 3.1 to 3.6, merged 2026-11-22).**
Source: `libraries/crypto/openspec/changes/foundation/reference/plan.md`
Tasks 3.7 to 3.11 (proposals).

**The formats change (branch `crypto/formats` of the library and of the
superproject; built on codecs, not merged).**
**The formats change (built on codecs; merged on 2026-12-02 from the branch
`crypto/formats` of the library, `6052c7c`, and of the superproject,
`b248bdc`).**

- **crypto's key formats are codecs formats: `crypto::formats::raw`, `spki`,
`pkcs8`, `der` and `pem(spki)` or `pem(pkcs8)` (RFC 7468's armor over the
Expand Down Expand Up @@ -9061,13 +9064,57 @@ superproject; built on codecs, not merged).**
`include/webcpp/crypto/backends/bearssl.hpp` (libs/crypto).
- **hash's `hash::formats::base58_with_checksum` is Base58Check, the codecs
format `basic_base58<100, bitcoin_alphabet, hash::checksums::double_sha256>`
(branch `hash/base58-with-checksum`, not merged).** Bitcoin Core's vectors
test it (chapter 10's `bitcoin_base58_vectors`); a secret decode wipes its
scratch, and the library's wallet guide decodes a WIF key with it. hash
depends on codecs, never the reverse.
(merged on 2026-12-02 from the branch `hash/base58-with-checksum`).**
Bitcoin Core's vectors test it (chapter 10's `bitcoin_base58_vectors`); a
secret decode wipes its scratch, and the library's wallet guide decodes a
WIF key with it. hash depends on codecs, never the reverse.
Source: `libraries/hash/openspec/changes/base58-with-checksum/design.md`
D1 to D4 (proposals); `doc/use-cases/cryptocurrencies.adoc` (libs/hash).

**The primitives change (branch `crypto/primitives` of the library and of
the superproject; built, not merged).**

- **RFC 8439's raw ChaCha20 is `ciphers::chacha20<Backend>`, of the family
`families::chacha20` and the template `ciphers::basic_chacha20`, in the
purpose namespace `crypto::unauthenticated_encryption`, whose concept
`stream_cipher` reads the algorithm's own `nonce_size`, `block_size` and
`counter_type` (owner decisions 5 and 7).** `from_key(key)` takes 32 bytes;
`apply_keystream(nonce, data, initial_counter)` XORs the keystream from that
block into `data` in place, encryption and decryption alike, and returns
`error::counter_overflow` (22) before any backend runs when `data` needs
more blocks than the 32-bit counter has left, so no backend wraps or carries
into the nonce. It runs on libsodium, the default on every target, BearSSL
on every target and OpenSSL natively and on WASI; ctaes and libsecp256k1
are refused at compile time. Its asynchronous forms are
`async_from_key` and `async_apply_keystream`; WebCrypto has no ChaCha20, so
a backend that completes by itself is refused. The name warns: the page
sends a program to `secret_key_encryption` unless its protocol brings its
own authentication, as NIP-44 does with HMAC-SHA256.
Source: `libraries/crypto/openspec/changes/primitives/design.md` D1 to D7
(proposals); `doc/chacha.adoc` and `doc/unauthenticated_encryption.adoc`
(libs/crypto).
- **RFC 8439's raw Poly1305 is `authenticators::poly1305<Backend>`, in the
purpose namespace `crypto::single_use_key_authentication` (owner decision
6): a key used for one message only.** The static `authenticate(key,
message)` gives the 16-byte tag of a 32-byte key; `verify(key, message,
tag)` compares through `secure::constant_time_equal` and returns
`authentication_failed` on a mismatch; there is no keyed object. It runs on
libsodium, the default on every target, and OpenSSL natively and on WASI;
BearSSL, whose Poly1305 lies inside its AEAD, ctaes and libsecp256k1 are
refused at compile time. A reusable key is HMAC's, `hash::mac`.
Source: `libraries/crypto/openspec/changes/primitives/design.md` D11 to
D15 (proposals); `doc/single_use_key_authentication.adoc` (libs/crypto).
- **The tests compose RFC 8439's AEAD from the two raw pieces on every
combination of their backends and find, byte for byte, what
`ciphers::chacha20_poly1305` seals; NIP-44 version 2's vectors prove
ChaCha20 where a protocol uses it; both pieces are in the constant-time
lane and dudect, and in the sizes lane at release on every target.**
NIP-44 itself stays out of crypto: its vectors (`/third_party//nip44`) are
composed in the tests from crypto's ChaCha20 and secp256k1 and
webcpp::hash's HKDF and HMAC. Throughput is not measured yet.
Source: `libraries/crypto/openspec/changes/primitives/design.md` D9, D16
and D17 (proposals); `doc/tables/sizes.json` (libs/crypto).

**Constant time (increment 1, Task 14; merged).**

- **Constant time is checked deterministically on Linux x86-64 and arm64
Expand Down
2 changes: 2 additions & 0 deletions doc/releases/0.1.0.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ target through `/webcpp/third_party//wycheproof`.
target through `/third_party//bips`.
* Added RFC 9180's test vectors (cfrg/draft-irtf-cfrg-hpke) to `third_party/`,
which crypto's HPKE tests read on every target through `/third_party//hpke`.
* Added NIP-44 version 2's test vectors (paulmillr/nip44) to `third_party/`,
which crypto's ChaCha20 tests read on every target through `/third_party//nip44`.
* Changed `/third_party//bips` to also serve BIP341's
`bip-0341/wallet-test-vectors.json`, whose cases run again when it changes.
* Changed the lint to never read third-party code under `third_party/libs/`.
Expand Down
2 changes: 1 addition & 1 deletion libs/crypto
Submodule crypto updated 231 files
26 changes: 26 additions & 0 deletions third_party/Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,32 @@ alias hpke : : <conditional>@hpke-checked-out : :
<dependency>$(.hpke-files) ;
explicit hpke ;

# paulmillr/nip44, shallow: test data, never compiled, released into the public
# domain (its JavaScript implementation's Unlicense, whose copy of the file is
# the same bytes). A test that names nip44 reads NIP-44 version 2's vectors,
# nip44.vectors.json, whose SHA-256 NIP-44's text states, from the directory
# WEBCPP_TEST_NIP44 names, with forward slashes, the directory given to
# wasmtime on WASI (webcpp.data), and runs again when it changes.
path-constant NIP44 : libs/nip44 ;
.nip44 = [ regex.replace $(NIP44) "\\\\" "/" ] ;
.nip44-files = [ glob libs/nip44/nip44.vectors.json ] ;

rule nip44-checked-out ( properties * )
{
if ! [ path.exists [ path.native $(NIP44)/nip44.vectors.json ] ]
{
errors.user-error "third_party/libs/nip44 is not checked out: it holds no"
"nip44.vectors.json. Check it out with `git submodule update --init"
"third_party/libs/nip44`." ;
}
}

alias nip44 : : <conditional>@nip44-checked-out : :
<define>"\"WEBCPP_TEST_NIP44=\\\"$(.nip44)\\\"\""
[ webcpp.data $(NIP44) ]
<dependency>$(.nip44-files) ;
explicit nip44 ;

# novifinancial/ed25519-speccheck (Apache-2.0), shallow: test data, never
# compiled. A test that names ed25519-speccheck reads the twelve Ed25519 edge
# cases of "Taming the many EdDSAs", cases.json, from the directory
Expand Down
1 change: 1 addition & 0 deletions third_party/libs/nip44
Submodule nip44 added at 671a1f
9 changes: 9 additions & 0 deletions tools/test/fixtures/crypto_jamfiles/chacha20_default/Jamfile
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//chacha20-default ;
# end::jamfile[]
48 changes: 48 additions & 0 deletions tools/test/fixtures/crypto_jamfiles/chacha20_default/app.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) 2026 WebCpp.org
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// https://www.boost.org/LICENSE_1_0.txt)

// Encrypts RFC 8439's ChaCha20 example (section 2.4.2) on the default backend, checks the
// ciphertext's first and last bytes against the RFC's, decrypts it again, and prints the backend
// that ran. The key and nonce are the RFC's: a real program draws its key from random_device and
// never reuses a nonce under it, and authenticates the nonce and the ciphertext itself, as NIP-44
// does, since ChaCha20 alone authenticates nothing.
#include <webcpp/crypto/ciphers/chacha20.hpp>

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

int main() {
using cipher = webcpp::crypto::ciphers::chacha20<>;
// The key 0x00, 0x01, ..., 0x1f.
std::array<std::uint8_t, 32> key{};
for (std::size_t index = 0; index < key.size(); ++index) {
key[index] = static_cast<std::uint8_t>(index);
}
std::array<std::uint8_t, 12> const nonce{0, 0, 0, 0, 0, 0, 0, 0x4a, 0, 0, 0, 0};
constexpr std::string_view sunscreen =
"Ladies and Gentlemen of the class of '99: If I could offer you only one tip for the "
"future, sunscreen would be it.";
std::array<std::uint8_t, sunscreen.size()> plaintext{};
std::ranges::copy(sunscreen, plaintext.begin());
auto data = plaintext;
std::array<std::uint8_t, 8> const expected_head{0x6e, 0x2e, 0x35, 0x9a, 0x25, 0x68, 0xf9, 0x80};
std::array<std::uint8_t, 4> const expected_tail{0x5e, 0x42, 0x87, 0x4d};
auto made = cipher::from_key(key);
bool ok = false;
if (made && made->apply_keystream(nonce, data, 1)) {
ok = std::equal(expected_head.begin(), expected_head.end(), data.begin()) &&
std::equal(expected_tail.begin(), expected_tail.end(), data.end() - 4) &&
made->apply_keystream(nonce, data, 1) && data == plaintext;
}
auto const name = cipher::backend_type::name;
std::printf("chacha20 %s backend=%.*s\n", ok ? "ok" : "FAILED", static_cast<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]
chacha20 ok backend=sodium
[wasip2]
chacha20 ok backend=sodium
[wasip3]
chacha20 ok backend=sodium
[emscripten]
chacha20 ok backend=sodium
# end::output[]
9 changes: 9 additions & 0 deletions tools/test/fixtures/crypto_jamfiles/poly1305_default/Jamfile
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//poly1305-default ;
# end::jamfile[]
44 changes: 44 additions & 0 deletions tools/test/fixtures/crypto_jamfiles/poly1305_default/app.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) 2026 WebCpp.org
//
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// https://www.boost.org/LICENSE_1_0.txt)

// Authenticates RFC 8439's Poly1305 example (section 2.5.2) on the default backend, checks the tag
// against the RFC's, verifies it, refuses it with one bit flipped, and prints the backend that
// ran. The key is the RFC's: a real program derives a fresh key for every message, since a
// Poly1305 key authenticates one message alone.
#include <webcpp/crypto/authenticators/poly1305.hpp>

#include <algorithm>
#include <array>
#include <cstdint>
#include <cstdio>
#include <string_view>

int main() {
using authenticator = webcpp::crypto::authenticators::poly1305<>;
std::array<std::uint8_t, 32> const key{
0x85, 0xd6, 0xbe, 0x78, 0x57, 0x55, 0x6d, 0x33, 0x7f, 0x44, 0x52,
0xfe, 0x42, 0xd5, 0x06, 0xa8, 0x01, 0x03, 0x80, 0x8a, 0xfb, 0x0d,
0xb2, 0xfd, 0x4a, 0xbf, 0xf6, 0xaf, 0x41, 0x49, 0xf5, 0x1b,
};
constexpr std::string_view forum = "Cryptographic Forum Research Group";
std::array<std::uint8_t, forum.size()> message{};
std::ranges::copy(forum, message.begin());
std::array<std::uint8_t, 16> const expected{
0xa8, 0x06, 0x1d, 0xc1, 0x30, 0x51, 0x36, 0xc6,
0xc2, 0x2b, 0x8b, 0xaf, 0x0c, 0x01, 0x27, 0xa9,
};
auto const tag = authenticator::authenticate(key, message);
bool ok = false;
if (tag && std::ranges::equal(*tag, expected) && authenticator::verify(key, message, *tag)) {
auto forged = expected;
forged[0] ^= 1U;
ok = !authenticator::verify(key, message, forged);
}
auto const name = authenticator::backend_type::name;
std::printf("poly1305 %s backend=%.*s\n", ok ? "ok" : "FAILED", static_cast<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]
poly1305 ok backend=sodium
[wasip2]
poly1305 ok backend=sodium
[wasip3]
poly1305 ok backend=sodium
[emscripten]
poly1305 ok backend=sodium
# end::output[]
Loading
Loading