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
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ MSVC), wasip2, wasip3 and Emscripten.
and PKCS#8, `formats::pem`, codecs' armor over the DER with its label in its type, each decoded
strictly, and an input past a format's bound refused as `codecs::error::input_too_long`.
- `webcpp::crypto::public_key_encryption`: NaCl's and libsodium's boxes between two key pairs
(`box`, `box_xchacha20poly1305`), refusing a peer key of small order, and sealed boxes
(`sealed_box`), anonymous encryption to a public key.
(`box`, `box_xchacha20poly1305`), refusing a peer key of small order, sealed boxes
(`sealed_box`), anonymous encryption to a public key, and RFC 9180's HPKE
(`hpke::suite`), composed from X25519 or P-256, webcpp::hash's HKDF and AES-GCM or
ChaCha20-Poly1305, in its four modes, as MLS and Marmot use it.
- `webcpp::crypto::key_exchange`: `kx_keypair`, libsodium's `crypto_kx`, a session key for each
direction of a client and a server.

Expand Down
8 changes: 8 additions & 0 deletions doc/async.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ include::{examples}/async_sign.cpp[tag=program,indent=0]
include::{examples}/async_sign.expected[]
----

HPKE's setups, single-shot calls, contexts' `seal` and `open` and
`derive_from_seed` have their asynchronous forms too, the synchronous arguments
between the executor and the completion token: `hpke::async_begin_sending<Suite>(executor,
recipient_public_key, application_info, token)` completes with the sender's
context, and `sender.async_seal(executor, associated_data, plaintext,
ciphertext, token)` with the seal's code (<<crypto-hpke>>). WebCrypto has no
HPKE: on the browser's backend they stop the build.

*The completion's value on an error.* A value that is a keyed object or a
secret has no meaning when the call failed, and the completion gives the
empty object a move leaves: a `gcm` or a key pair without a key, a `secure::secret<32>`
Expand Down
17 changes: 14 additions & 3 deletions doc/backends.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,18 @@ One measurement is an open finding, listed under the table with its numbers:
libsodium's X25519 `agree` under wasmtime, on wasip2. Its cause is measured:
wasmtime does not set DIT, and with DIT set in wasmtime's main thread, an
experiment and not the lane, the case passes. The WebAssembly cannot set it,
so the lane prints its value on wasip2 without judging it, and judges
everything else.
so the lane prints its value on wasip2 without judging it.

On a WASI target the lane prints every case of `dudect_bearssl` (BearSSL's
AEADs and P-256, ctaes, `secure::constant_time_equal` and hash's Base58Check
decode) and judges none of them, by the owner's decision of 2026-12-04: under
wasmtime their timing follows the processor of the runner, not the code
measured. On GitHub's hosted AMD EPYC 9V74, wasip2 runs read |t| 30 to 150 on
`secure::constant_time_equal` and 11 to 12 on AES-GCM's seal and on ctaes,
failing changes that touched none of them, so a verdict there would pass or
fail with the machine drawn. The lane judges everything else: every program
natively, and under wasmtime `dudect_sodium` (X25519's agreement excepted) and
`dudect_secp256k1`.

dudect's two classes differ in the secret's bytes and in nothing else: the
preparation of each measurement reads both inputs and writes the secret with
Expand All @@ -247,7 +257,8 @@ program but `dudect_planted` also measures an A/A control case, whose classes
are prepared by the same instructions with the same value: it shows what the
machine itself does. Valgrind's memcheck and MemorySanitizer, which do not
measure time, are judged there; dudect is judged by the program itself
wherever else the lane runs, on a machine of one's own, in one process.
wherever else the lane runs, on a machine of one's own, in one process, except
`dudect_bearssl` on a WASI target, which judges none of its cases.

Whether a tag matched, or a shared secret came out all zero, is public by
design, since the operation reports it, but it is computed from the secrets: it
Expand Down
6 changes: 3 additions & 3 deletions doc/changelog.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ of every version are on webcpp's index page.
* *Breaking change:* Changed the key formats into codecs formats: `codecs::encode`, `codecs::decode` and members replace encode_spki, to_der and their kin, `formats::max_encoded_size` their sizes, and `formats::pem` replaces `crypto::pem` and pem-default.
* *Breaking change:* Changed the schemes into `crypto::signing_schemes`; every verification, `recover` and `can_verify` takes a policy after the scheme, `low_s_only`, `any_s` or `canonical` (Ed25519's former `strict`).
* *Breaking change:* Changed low S into signatures' `is_low_s()` and `low_s()`, free tweak_xonly, span Schnorr verify and `xonly()` bytes into the typed `xonly_public_key`, and secp256k1's SPKI default to uncompressed.
* Changed PEM: its label is in its type, a PEM result is exactly as long as its longest text, and a hand-built armor over a key format does not build.
* Changed PEM decode: through codecs' over, in place; an input past a format's bound is codecs' `input_too_long` on every path.
* Added crypto, C-backed primitives on webcpp::secure's guard (DIT on arm64): errors 1 to 20, `+[[nodiscard]]+` results, typed signatures, key pair concepts, factories, WEBCPP_CRYPTO_HAS_THREADS, Asio's asynchronous functions.
* Changed PEM: its label is in its type, its result as long as its longest text, its decode in place through codecs' over, and a hand-built armor fails to build.
* Added crypto, C-backed primitives on webcpp::secure's guard (DIT on arm64): errors 1 to 21, `+[[nodiscard]]+` results, typed signatures, key pair concepts, factories, WEBCPP_CRYPTO_HAS_THREADS, Asio's asynchronous functions.
* Added random_device, the AES block ciphers, ciphers::gcm, per-target defaults, backends::bearssl (AES-GCM, ChaCha20-Poly1305, curves::p256 keys, low-S ECDSA, agree), backends::openssl and backends::ctaes.
* Added curves::secp256k1 (ECDSA, recoverable ECDSA, BIP 340 Schnorr, agree, tweaks, ElligatorSwift, MuSig2, silent payments), and curves::ed25519 and curves::x25519 on libsodium, Ed25519's verification canonical.
* Added public_key_encryption::hpke, RFC 9180's HPKE on X25519 or P-256, HKDF, and AES-GCM or ChaCha20-Poly1305.
* Added backends::sodium, ChaCha20-Poly1305 AEADs, secretbox, boxes, sealed boxes, kx_keypair, and the page: chapters per namespace and use case, generated tables, Jamfiles, messages, llms.txt, measurements.
// end::unreleased[]
2 changes: 2 additions & 0 deletions doc/errors.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ the format allows. An input longer than the pair's bound is codecs'
`input_too_long`, not this. A `raw` or a `der` gives the key's or the signature's own error, and the
armor's own faults are codecs' (below).
|20 |`invalid_ciphertext_size` |A KEM or RSA ciphertext of another size than the key's.
|21 |`message_limit_reached` |An HPKE context has sealed or opened as many messages as its nonce
allows: its 64-bit sequence number reached 2^64^ - 1 (RFC 9180's `MessageLimitReachedError`).
|===

A value that `error` does not define
Expand Down
4 changes: 2 additions & 2 deletions doc/generated/backends-aes_block.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ The backends of `+ciphers::aes128+`, `+aes192+`, `+aes256+`, from the test progr
|OpenSSL
|`+/webcpp/crypto//openssl+`
|`+<webcpp/crypto/backends/openssl.hpp>+`
|native, wasip2, wasip3 (tested by `+aes_openssl+`, `+agreement_aes+`); not on emscripten: `+/webcpp/crypto//openssl+` stops the build there
|native, wasip2, wasip3 (tested by `+aes_openssl+`, `+agreement_aes+`, `+quic_rfc9001_openssl+`); not on emscripten: `+/webcpp/crypto//openssl+` stops the build there

|ctaes
|`+/third_party//ctaes+`
|`+<webcpp/crypto/backends/ctaes.hpp>+`
|native, wasip2, wasip3, emscripten (tested by `+aes_ctaes+`, `+agreement_aes+`)
|native, wasip2, wasip3, emscripten (tested by `+aes_ctaes+`, `+agreement_aes+`, `+quic_rfc9001_bearssl+`)
|===

`+aes128<>+`, `+aes192<>+` and `+aes256<>+` name the default backend; `+gcm<aes256<>>+` names AES-GCM's. The default per target, whatever the program links, as <<crypto-backends-defaults>> gives it with its reasons and tests:
Expand Down
4 changes: 2 additions & 2 deletions doc/generated/backends-gcm.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ The backends of `+ciphers::gcm+`, `+aes128_gcm+`, `+aes256_gcm+`, from the test
|BearSSL
|`+/third_party//bearssl+`
|`+<webcpp/crypto/backends/bearssl.hpp>+`
|native, wasip2, wasip3, emscripten (tested by `+gcm_bearssl+`, `+gcm_wycheproof_bearssl+`, `+agreement_gcm+`, `+agreement_gcm_portable+`)
|native, wasip2, wasip3, emscripten (tested by `+gcm_bearssl+`, `+gcm_wycheproof_bearssl+`, `+agreement_gcm+`, `+agreement_gcm_portable+`, `+quic_rfc9001_bearssl+`)

|OpenSSL
|`+/webcpp/crypto//openssl+`
|`+<webcpp/crypto/backends/openssl.hpp>+`
|native, wasip2, wasip3 (tested by `+gcm_openssl+`, `+gcm_wycheproof_openssl+`, `+agreement_gcm+`, `+agreement_gcm_portable+`); not on emscripten: `+/webcpp/crypto//openssl+` stops the build there
|native, wasip2, wasip3 (tested by `+gcm_openssl+`, `+gcm_wycheproof_openssl+`, `+agreement_gcm+`, `+agreement_gcm_portable+`, `+quic_rfc9001_openssl+`); not on emscripten: `+/webcpp/crypto//openssl+` stops the build there

|ctaes
|`+/third_party//ctaes+`
Expand Down
25 changes: 25 additions & 0 deletions doc/generated/backends-hpke.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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)

// Generated by doc/tables/generate.py from doc/tables/crypto.json, the test Jamfiles,
// the message tests and the Jamfile fixtures: run it again, never edit this file.

The backends of `+public_key_encryption::hpke::suite+`, from the test programs that run it:

[cols="1,2,2,4",options="header"]
|===
|Backend |Jamfile |Header |Targets

|BearSSL
|`+/third_party//bearssl+`
|`+<webcpp/crypto/backends/bearssl.hpp>+`
|native, wasip2, wasip3, emscripten (tested by `+hpke_vectors_bearssl+`, `+hpke_async+`, `+hpke_allocation+`, `+timing_coverage_bearssl+`)

|libsodium
|`+/third_party//sodium+`
|`+<webcpp/crypto/backends/sodium.hpp>+`
|native, wasip2, wasip3, emscripten (tested by `+hpke_vectors_default+`, `+hpke+`, `+hpke_async+`, `+hpke_allocation+`, `+timing_coverage_sodium+`)
|===
8 changes: 4 additions & 4 deletions doc/generated/constant-time.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
|BearSSL
|by design: `+aes_ct64+` and `+ghash_ctmul64+`, or AES-NI and PCLMUL where the CPU has them; on a 32-bit host a 64-bit multiplication may not be constant time, which BearSSL documents; ECDSA signing at webcpp's pin, whose patch submitted upstream closes upstream's leak of the RFC 6979 nonce's bit length (link:https://www.bearssl.org/gitweb/?p=BearSSL;a=blob;f=src/ec/ecdsa_i31_bits.c;hb=7bea48e5e850ab4cafbe68d3765cdaba13a86d6f#l44[BearSSL's ecdsa_i31_bits.c at upstream 7bea48e, lines 44 and 45: the nonce decoded with its actual bit length in the integer's header, then shifted over the words that length needs]; link:https://minerva.crocs.fi.muni.cz/[Minerva: the leak of an ECDSA nonce's bit length through timing, and the lattice that recovers the key (CVE-2019-15809)]; the patch: link:https://github.com/webcpporg/bearssl/commit/ae63032d9f30bf53674db5445875adf71b8626b7[webcpporg/bearssl, commit ae63032 on its branch upstream/ecdsa-bits2int-constant-time, one of the two patches of webcpp's pin f8a2f3d (upstream 7bea48e plus exactly the patches submitted upstream): br_ecdsa_i31_bits2int and br_ecdsa_i15_bits2int setting the integer's header, before the right shift, to the larger of the decoded bit length and the order's, both public; the pin returns to upstream once upstream applies it]); P-256's `+mul+`, which ECDH calls, at webcpp's pin, whose other patch submitted upstream removes the jump on the secret scalar that Clang makes on x86-64 of upstream's scalar check (link:https://www.bearssl.org/gitweb/?p=BearSSL;a=blob;f=src/ec/ec_p256_m62.c;hb=7bea48e5e850ab4cafbe68d3765cdaba13a86d6f#l1623[BearSSL's ec_p256_m62.c at upstream 7bea48e, lines 1623 to 1627: the scalar compared with the order through masks that Clang on x86-64 compiles into a conditional jump on the comparison so far]; the patch: link:https://github.com/webcpporg/bearssl/commit/ec57f886ee0a0783acfca1b465b43ccd62b71046[webcpporg/bearssl, commit ec57f88 on its branch upstream/ec-p256-check-scalar-constant-time, the other patch of webcpp's pin f8a2f3d: check_scalar in ec_p256_m62.c and ec_p256_m64.c computing 0 < k < n as k - 1 < n - 1 with two borrow chains, no select for a compiler to turn into a jump; the pin returns to upstream once upstream applies it]); link:https://www.bearssl.org/constanttime.html[BearSSL, constant-time crypto]; link:https://www.bearssl.org/ctmul.html[BearSSL, constant-time multiplications]
|Valgrind's memcheck (Linux): AES-GCM, ChaCha20-Poly1305, P-256 (the key pair's making, `+sign+` of a digest (`+crypto::signing_schemes::prehashed+`), which makes its signature low S without a branch, then `+low_s()+` and `+is_low_s()+` of it, `+agree+` and the private formats, `+pkcs8+`, `+raw+` and `+pem(pkcs8)+` both ways; BearSSL's own branches on its signing's verdicts listed in `+bearssl_verdicts.supp+`; nothing found at webcpp's pin f8a2f3d, whose patches submitted upstream close upstream's leak of the nonce's bit length in `+sign+` that this checker found on 2026-11-21 and the jump on the scalar in P-256's scalar check that it found under `+agree+` on the x86-64 runner on 2026-12-03, `+sign+` with its low-S step included (Valgrind 3.22, arm64 Linux container, 2026-12-02; x86-64, `+ctgrind+` and `+ctgrind_space+`, 2026-12-04)); MemorySanitizer (Linux, clang): AES-GCM, ChaCha20-Poly1305, P-256 (the same paths as memcheck's; the same leak in `+sign+` on 2026-11-21 on upstream's BearSSL, nothing at webcpp's pin ae63032, `+sign+` with its low-S step included (clang 18, arm64 Linux container, 2026-12-02); MemorySanitizer checks the select of P-256's scalar check before the code generator makes it a jump, so the second patch changes nothing it sees); dudect (judged; on a runner GitHub hosts, by two of three runs): AES-GCM, ChaCha20-Poly1305, P-256 (`+sign+` of a digest and `+agree+`, each against the key pair's scalar; `+sign+` with its low-S step judged constant time, \|t\| 1.70 on Linux and 1.63 natively on an Apple M5 Max (release, one run each, 2026-11-22; provisional, measured again in the final quiet pass))
|dudect (judged; on a runner GitHub hosts, by two of three runs): AES-GCM, ChaCha20-Poly1305, P-256 (`+sign+` of a digest and `+agree+`, each against the key pair's scalar; `+sign+` with its low-S step judged constant time, \|t\| 1.70 on Linux and 1.63 natively on an Apple M5 Max (release, one run each, 2026-11-22; provisional, measured again in the final quiet pass))
|dudect (printed, not judged: under wasmtime its timing follows the runner's processor): AES-GCM, ChaCha20-Poly1305, P-256
|not measured yet
|not measured yet

Expand All @@ -28,7 +28,7 @@
|ctaes
|by design: bitsliced, no table and no branch on secret data; link:https://github.com/bitcoin/bitcoin/tree/master/src/crypto/ctaes[ctaes, constant-time AES]
|Valgrind's memcheck (Linux): AES block cipher; MemorySanitizer (Linux, clang): AES block cipher; dudect (judged; on a runner GitHub hosts, by two of three runs): AES block cipher
|dudect (judged; on a runner GitHub hosts, by two of three runs): AES block cipher
|dudect (printed, not judged: under wasmtime its timing follows the runner's processor): AES block cipher
|not measured yet
|not measured yet

Expand All @@ -55,8 +55,8 @@

|no backend
|webcpp::secure's `+secure::constant_time_equal+`, which crypto's code calls, is constant time in the contents: every byte is read, no branch and no index depends on one
|Valgrind's memcheck (Linux): `+secure::constant_time_equal+`, `+is_all_zero+` and the wipe of `+secure::secret<N>+`; MemorySanitizer (Linux, clang): `+secure::constant_time_equal+`, `+is_all_zero+` and the wipe of `+secure::secret<N>+`; dudect (judged; on a runner GitHub hosts, by two of three runs): `+secure::constant_time_equal+`
|dudect (judged; on a runner GitHub hosts, by two of three runs): `+secure::constant_time_equal+`
|Valgrind's memcheck (Linux): `+secure::constant_time_equal+`, `+is_all_zero+` and the wipe of `+secure::secret<N>+`, HPKE's composition, `+public_key_encryption::hpke+`: its key schedule over webcpp::hash's HKDF, the setups in base and auth_psk mode, seal, open and export, on X25519 with ChaCha20-Poly1305 (libsodium) and P-256 with AES-128-GCM (BearSSL); MemorySanitizer (Linux, clang): `+secure::constant_time_equal+`, `+is_all_zero+` and the wipe of `+secure::secret<N>+`, HPKE's composition, `+public_key_encryption::hpke+`: its key schedule over webcpp::hash's HKDF, the setups in base and auth_psk mode, seal, open and export, on X25519 with ChaCha20-Poly1305 (libsodium) and P-256 with AES-128-GCM (BearSSL); dudect (judged; on a runner GitHub hosts, by two of three runs): `+secure::constant_time_equal+`, HPKE's composition, `+public_key_encryption::hpke+`: its key schedule over webcpp::hash's HKDF, the setups in base and auth_psk mode, seal, open and export, on X25519 with ChaCha20-Poly1305 (libsodium) and P-256 with AES-128-GCM (BearSSL)
|dudect (printed, not judged: under wasmtime its timing follows the runner's processor): `+secure::constant_time_equal+`, HPKE's composition, `+public_key_encryption::hpke+`: its key schedule over webcpp::hash's HKDF, the setups in base and auth_psk mode, seal, open and export, on X25519 with ChaCha20-Poly1305 (libsodium) and P-256 with AES-128-GCM (BearSSL)
|not measured yet
|not measured yet
|===
Expand Down
24 changes: 20 additions & 4 deletions doc/generated/matrix.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,22 @@
|`+ciphers::aes128+`, `+aes192+`, `+aes256+`
|OpenSSL
|native, wasip2, wasip3; not on emscripten: `+/webcpp/crypto//openssl+` stops the build there
|`+aes_openssl+`, `+agreement_aes+`
|`+aes_openssl+`, `+agreement_aes+`, `+quic_rfc9001_openssl+`

|`+ciphers::aes128+`, `+aes192+`, `+aes256+`
|ctaes
|native, wasip2, wasip3, emscripten
|`+aes_ctaes+`, `+agreement_aes+`
|`+aes_ctaes+`, `+agreement_aes+`, `+quic_rfc9001_bearssl+`

|`+ciphers::gcm+`, `+aes128_gcm+`, `+aes256_gcm+`
|BearSSL
|native, wasip2, wasip3, emscripten
|`+gcm_bearssl+`, `+gcm_wycheproof_bearssl+`, `+agreement_gcm+`, `+agreement_gcm_portable+`
|`+gcm_bearssl+`, `+gcm_wycheproof_bearssl+`, `+agreement_gcm+`, `+agreement_gcm_portable+`, `+quic_rfc9001_bearssl+`

|`+ciphers::gcm+`, `+aes128_gcm+`, `+aes256_gcm+`
|OpenSSL
|native, wasip2, wasip3; not on emscripten: `+/webcpp/crypto//openssl+` stops the build there
|`+gcm_openssl+`, `+gcm_wycheproof_openssl+`, `+agreement_gcm+`, `+agreement_gcm_portable+`
|`+gcm_openssl+`, `+gcm_wycheproof_openssl+`, `+agreement_gcm+`, `+agreement_gcm_portable+`, `+quic_rfc9001_openssl+`

|`+ciphers::gcm+`, `+aes128_gcm+`, `+aes256_gcm+`
|ctaes
Expand Down Expand Up @@ -221,6 +221,16 @@
|native, wasip2, wasip3, emscripten
|`+box_sodium+`, `+allocation_sodium+`

|`+public_key_encryption::hpke::suite+`
|BearSSL
|native, wasip2, wasip3, emscripten
|`+hpke_vectors_bearssl+`, `+hpke_async+`, `+hpke_allocation+`, `+timing_coverage_bearssl+`

|`+public_key_encryption::hpke::suite+`
|libsodium
|native, wasip2, wasip3, emscripten
|`+hpke_vectors_default+`, `+hpke+`, `+hpke_async+`, `+hpke_allocation+`, `+timing_coverage_sodium+`

|`+curves::secp256k1::recover+`
|libsecp256k1
|native, wasip2, wasip3, emscripten
Expand Down Expand Up @@ -499,6 +509,12 @@ The same, by target: the backends each operation runs on.
|libsodium
|libsodium

|`+public_key_encryption::hpke::suite+`
|BearSSL, libsodium
|BearSSL, libsodium
|BearSSL, libsodium
|BearSSL, libsodium

|`+curves::secp256k1::recover+`
|libsecp256k1
|libsecp256k1
Expand Down
Loading
Loading