Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
3c35613
crypto: PEM decodes through codecs' over in place, the two-step decod…
Dec 3, 2026
ad246df
crypto: the fuzz Jamfile's comment lint fix
Dec 3, 2026
346ec6f
crypto: pem_decode_from_bytes gives an array of bytes, whose type eve…
Dec 3, 2026
e00b552
crypto: the fuzz check of no intermediate past the bound counts the a…
Dec 3, 2026
3d6bbf6
crypto: the fuzz decode check's reference wipes in a helper (lint fix)
Dec 3, 2026
0af4260
crypto: the fuzz decode check's reference count const (lint fix)
Dec 3, 2026
a893a9a
crypto: the fuzz decode check's wipes in helpers, its complexity unde…
Dec 3, 2026
f49337b
crypto: the PEM fuzz wipe check and the X25519 past-bound count compl…
Dec 3, 2026
1e38f39
crypto: crypto's types are declared to codecs, with D3's sentences; P…
Dec 3, 2026
a6dd216
crypto: the PEM label test split, a trailing comma, an unused alias r…
Dec 3, 2026
2d16078
crypto: the key pair's decode with a resource refuses a composition w…
Dec 3, 2026
64d713a
crypto: the composition message test's Jamfiles' licence notice (lint…
Dec 3, 2026
07ba862
crypto: every caller writes codecs::encode and codecs::decode; crypto…
Dec 3, 2026
7babcab
crypto: the removal tests of crypto::encode and crypto::decode state …
Dec 3, 2026
3beefea
crypto: four unused namespace aliases removed (lint fix)
Dec 3, 2026
4a938b2
crypto: the removal tests' Jamfile comments wrapped (lint fix)
Dec 3, 2026
77d0566
crypto: formats.hpp's overview says codecs' verbs check every pair
Dec 3, 2026
8c5e682
crypto: the guide, the README and the tables write codecs' verbs, PEM…
Dec 3, 2026
155db5d
crypto: the errors page lists every pair's bound and the size rows wi…
Dec 3, 2026
121eb92
crypto: PKCS#8 version 2 of Ed25519 and X25519 is input_too_long thro…
Dec 3, 2026
7888c9e
crypto: the key pair's decode with a resource refuses a PEM given byt…
Dec 3, 2026
27e6a6c
crypto: pem of a format that is no DER key is the build's one error a…
Dec 3, 2026
fd7bd2f
crypto: the tests compare codecs' verb with the member and the input …
Dec 3, 2026
e617347
crypto: the secp256k1 PEM fuzz target checks the key pair's decode wi…
Dec 3, 2026
66bde7e
crypto: pem's one error is claimed on crypto's types, as the headers …
Dec 3, 2026
6f26621
Merge origin/main (main-ci-fix) into crypto/one-verb
Dec 3, 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
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ MSVC), wasip2, wasip3 and Emscripten.
- `webcpp::crypto::curves::p256`: P-256's ECDSA signatures over SHA-256, low S or any S as the
verification policy says, and its ECDH, on BearSSL natively and on WebCrypto in a browser.
- `webcpp::crypto::formats`: every curve's keys and signatures in their formats, as OpenSSL,
WebCrypto and node write them, through `crypto::encode` and `crypto::decode` (codecs' value
codecs): a key's raw bytes with its point forms, RFC 5480's and RFC 8410's SPKI, PKCS#8, an ECDSA
signature's strict DER, and the PEM of the SPKI and PKCS#8, `formats::pem`, codecs' armor over
the DER, each decoded strictly.
WebCrypto and node write them, through `codecs::encode` and `codecs::decode` (crypto has no
verbs of its own; its types are declared to codecs): a key's raw bytes with its point forms,
RFC 5480's and RFC 8410's SPKI, PKCS#8, an ECDSA signature's strict DER, and the PEM of the SPKI
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.
Expand Down
14 changes: 7 additions & 7 deletions doc/changelog.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ of every version are on webcpp's index page.
=== Unreleased

// tag::unreleased[]
* *Breaking change:* Changed the key formats into codecs formats: `crypto::encode`, `crypto::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:* Removed `crypto::encode` and `crypto::decode`: `codecs::encode` and `codecs::decode` are the verbs, the members unchanged.
* *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.
* Added random_device, the AES block ciphers, ciphers::gcm (incremental seal, two-pass open), supports_v, per-target defaults and /webcpp/crypto//<family>-default, refusals naming their Jamfile line.
* Added backends::bearssl (AES-GCM, ChaCha20-Poly1305, curves::p256: keys, low-S ECDSA, agree; allocating nothing), backends::openssl natively and on WASI, its memory option, and backends::ctaes.
* Added curves::secp256k1: ECDSA (hedged too), recoverable ECDSA over SHA-256 or Keccak-256, BIP 340 Schnorr, agree's three forms, tweaks, ElligatorSwift, MuSig2, silent payments.
* Added curves::ed25519 and curves::x25519 on libsodium: canonical verification (twelve edge cases), Ed25519ph and its streaming prehashed_signer, the conversion, all-zero agreements refused.
* Added backends::sodium (shared with webcpp::hash), every backend's canary and C suite, ChaCha20-Poly1305 AEADs, secretbox and secretbox_xchacha20poly1305, boxes, sealed boxes, kx_keypair.
* Added the page: chapters per namespace and use case, the key formats' table generated from the one list, Jamfiles, messages, llms.txt, release-built sizes and throughput, timing findings.
* 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 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[]
10 changes: 5 additions & 5 deletions doc/curves.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ derivation and of watch-only wallets: `secret_key_tweak_add`,
`public_key_tweak_mul`, `public_key_negate` and `public_key_combine`
(<<crypto-secp256k1-tweaks>>);
* `secp256k1/formats.hpp`, the formats of its keys and signatures for
`crypto::encode` and `crypto::decode`: a public key's point (uncompressed by
`codecs::encode` and `codecs::decode`: a public key's point (uncompressed by
default, compressed, and its x-only key), the SPKI and PKCS#8 files that
OpenSSL and node exchange, their PEM, the x-only key's 32 bytes and an ECDSA
signature's strict DER (<<crypto-secp256k1-formats>>);
Expand Down Expand Up @@ -199,9 +199,9 @@ key, `curves::secp256k1::xonly_public_key`, made by its `from_bytes`, which lift
the 32 bytes to the point of even y and refuses those that are no point's x, so
that a key is never unset (design D12). It is also a format's value: a Nostr
event's 32-byte key decodes with
`crypto::decode<curves::secp256k1::xonly_public_key>(crypto::formats::raw, bytes)`,
`codecs::decode<curves::secp256k1::xonly_public_key>(crypto::formats::raw, bytes)`,
and a `public_key` writes its x-only key with
`crypto::encode(crypto::formats::raw(crypto::formats::xonly), key)`
`codecs::encode(crypto::formats::raw(crypto::formats::xonly), key)`
(<<crypto-key-formats-point-forms>>). Its `tweak_add(tweak)` is BIP 341's output
key and parity, a `tweaked_xonly_key`, and `verify_tweak(tweak, tweaked)` checks
an output key against its internal key, so that Taproot's arithmetic needs no
Expand Down Expand Up @@ -367,9 +367,9 @@ passes the same scheme to `sign` and to `verify`.

DER, low S and the 64-byte form are forms of a signature, not schemes, and
they need the curve's order. DER and the 64-byte form are formats:
`crypto::encode(crypto::formats::der, signature)` writes strict DER, 8 to 72
`codecs::encode(crypto::formats::der, signature)` writes strict DER, 8 to 72
bytes, allocating nothing, and
`crypto::decode<ecdsa_signature>(crypto::formats::der, der)` reads strict DER
`codecs::decode<ecdsa_signature>(crypto::formats::der, der)` reads strict DER
back into the curve's `ecdsa_signature` (each curve's `formats.hpp`,
<<crypto-key-formats>>).

Expand Down
6 changes: 3 additions & 3 deletions doc/ed25519.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ policy's to judge, so a key that `crypto::verify` refuses can still be made.

`<webcpp/crypto/curves/ed25519/formats.hpp>` gives the three types their
formats (<<crypto-key-formats>>), synchronous on every backend:
`crypto::encode(crypto::formats::spki, public_key)` and
`crypto::decode<public_key>(crypto::formats::spki, bytes)`, or the members
`codecs::encode(crypto::formats::spki, public_key)` and
`codecs::decode<public_key>(crypto::formats::spki, bytes)`, or the members
`public_key.encode(format)` and `public_key::decode(format, input)`, with
`formats::raw`, `formats::spki` and `formats::pem(formats::spki)` for a public
key; `formats::raw` (the seed, secret), `formats::pkcs8` and
`formats::pem(formats::pkcs8)` for a key pair, whose results are secret and
wiped; and `formats::raw` for a signature, which has no DER form. Without that
header, a member's call is the compiler's "deduced return type used before it
is defined", and `crypto::encode` names the header to include.
is defined", and `codecs::encode` names the header to include.

Each operation has its four forms, the member and its free form, synchronous
and asynchronous, with the same work, errors and refusals
Expand Down
46 changes: 28 additions & 18 deletions doc/errors.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ bytes) or 04 (65 bytes), or not a point of the curve.
DER, or an r or an s that is zero or not below the group order.
|12 |`backend_failure` |A backend failed where its contract says it does not.
|13 |`memory_functions_refused` |OpenSSL's memory functions could not be installed: OpenSSL has
already allocated, or another party installed its own. From `backends::openssl::install_memory_functions`,
with `WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE`.
already allocated, or another party installed its own. From
`backends::openssl::install_memory_functions`, with `WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE`.
|14 |`memory_functions_not_installed` |OpenSSL's memory functions are not webcpp::crypto's. From
every `from_key` of the OpenSSL backend, with `WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE`.
|15 |`weak_public_key` |A public key of small order, or one that gives an all-zero shared secret.
Expand All @@ -55,9 +55,9 @@ every `from_key` of the OpenSSL backend, with `WEBCPP_CRYPTO_OPENSSL_MEMORY_RESO
|18 |`invalid_padding` |Padding that cannot be removed, whatever the cause: one value for every
cause, so that no padding oracle is built from it.
|19 |`invalid_encoding` |A key's `spki` or `pkcs8` that does not decode, or is not the one encoding
the format allows, or a PEM whose payload is longer than its inner format's longest encoding. A
`raw` or a `der` gives the key's or the signature's own error, and the armor's own faults are
codecs' (below).
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.
|===

Expand All @@ -73,8 +73,8 @@ include::generated/backends-error.adoc[]

[#crypto-errors-categories]
*Two categories: crypto's and codecs'.* The key formats are formats of
webcpp::codecs (<<crypto-key-formats>>), so a call of `crypto::encode` or
`crypto::decode` reports either category, and a program that tells refusals
webcpp::codecs (<<crypto-key-formats>>), so a call of `codecs::encode` or
`codecs::decode` reports either category, and a program that tells refusals
apart compares with the enumeration of the category it is in
(`error_code::category()` says which; each enumeration compares equal only to
its own):
Expand All @@ -83,24 +83,22 @@ its own):
|===
|Refusal |Value |Category

|An `spki` or a `pkcs8` that is not the one encoding: another curve's
identifier, BER where DER is required, a byte left over, PKCS#8 version 2, a
|An `spki` or a `pkcs8` within the pair's bound that is not the one encoding:
another curve's identifier, BER where DER is required, a byte left over, a
point or a scalar the key refuses, a PKCS#8 whose public key is not its
scalar's
|`crypto::error::invalid_encoding` |`webcpp.crypto`
|A PEM whose payload is longer than its inner format's longest encoding (an RSA
key's SPKI read as P-256's)
|`crypto::error::invalid_encoding` |`webcpp.crypto`
|A public key's `raw` of a size its form does not have, a point that is not on
the curve, a compressed x that is no point's or not below p
|A public key's `raw` of a size its form does not have, within the bound, a point
that is not on the curve, a compressed x that is no point's or not below p
|`crypto::error::invalid_public_key` |`webcpp.crypto`
|A key pair's `raw` of another size than 32 bytes, or a secret key that is
zero or not below the order
|A key pair's `raw` shorter than 32 bytes (a longer one is `input_too_long`), or a
secret key that is zero or not below the order
|`crypto::error::invalid_key_size`, `invalid_secret_key` |`webcpp.crypto`
|A key pair's decode whose `from_secret` fails: secp256k1's signing context
without entropy, a backend's failure (P-256's PKCS#8 on BearSSL)
|`crypto::error::entropy_unavailable`, `backend_failure` |`webcpp.crypto`
|A signature's `raw` of another size; a `der` that is not strict DER; a
|A signature's `raw` shorter than its size (a longer one is `input_too_long`); a
`der` that is not strict DER; a
signature given to `der` or `low_s()` whose r or s is 0 or not below n
|`crypto::error::invalid_signature` |`webcpp.crypto`
|A moved-from key pair given to a private format
Expand All @@ -115,7 +113,19 @@ encoding
|`codecs::error::invalid_character`, `invalid_padding` |`webcpp.codecs`
|A span or a fixed token shorter than the exact encoding
|`codecs::error::output_too_small` |`webcpp.codecs`
|An input past a bound codecs checks
|An input longer than the pair's bound, `formats::max_decode_input_size<Format, T>`,
on every path: a DER or a raw input past it (an RSA key's SPKI given to P-256's
`spki`, an Ed25519 or X25519 PKCS#8 version 2 of 83 bytes given to `pkcs8`, whose
bound is 48), and a PEM whose payload is past its inner format's bound (the same key
as `pem(spki)`), checked before the value codec reads a byte. A pair's bound is
its longest encoding, the cell of the table in <<crypto-key-formats-table>>
(a PEM's is its inner format's): Ed25519's and X25519's public key `raw` 32 and
`spki` 44, their key pair `raw` 32 and `pkcs8` 48, Ed25519's signature `raw` 64;
P-256's public key `raw` 65 (33 for `raw(formats::compressed)`) and `spki` 91
(59), its key pair `raw` 32 and `pkcs8` 138, its signature `raw` 64 and `der` 72;
secp256k1's public key `raw` 65 (33) and `spki` 88 (56), its x-only key `raw`
32, its key pair `raw` 32 and `pkcs8` 135, its ECDSA signature `raw` 64 and `der`
72, its recoverable signature `raw` 65 and its Schnorr signature `raw` 64
|`codecs::error::input_too_long` |`webcpp.codecs`
|A Base58Check text (a WIF key, an address) whose checksum differs, through
webcpp::hash's `base58_with_checksum`
Expand Down
6 changes: 3 additions & 3 deletions doc/everyday.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ server stores it and later checks what the device signs.

*The idea.* The browser exports the key with `exportKey("spki")`, or as PEM
text, and the server reads it with
`crypto::decode<curves::p256::public_key>(crypto::formats::pem(crypto::formats::spki), text)`,
`codecs::decode<curves::p256::public_key>(crypto::formats::pem(crypto::formats::spki), text)`,
or `crypto::formats::spki` for the bytes, which checks that it is P-256's SPKI
and a point of the curve; it stores the bytes `crypto::encode` writes back, the
and a point of the curve; it stores the bytes `codecs::encode` writes back, the
one encoding (<<crypto-key-formats>>, <<crypto-p256-formats>>). Nothing of it
allocates.

Expand All @@ -177,7 +177,7 @@ include::{examples}/uploaded_key.expected[]
----

*Mistakes to avoid.* Storing what the browser sent rather than what
`crypto::encode` writes back: a key uploaded as a compressed SPKI, 59 bytes,
`codecs::encode` writes back: a key uploaded as a compressed SPKI, 59 bytes,
and the same key uncompressed, 91, compare unequal as bytes, though both decode
to the one key; the strict decode refuses every other second encoding.
Reading an SPKI as another algorithm's key: the decode of the type the program
Expand Down
Loading
Loading