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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ tag is placed.
| crypto | [api-gaps](libraries/crypto/openspec/changes/api-gaps) | crypto: the API gaps of version 0.2 closed, and dudect judged on hosted runners | wrapper | implementing | | 2026-11-20 | [code](https://github.com/webcpporg/crypto) |
| crypto | [data-independent-timing](libraries/crypto/openspec/changes/data-independent-timing) | crypto: the library sets arm64's DIT around every cryptographic operation | wrapper | implementing | | 2026-11-20 | [code](https://github.com/webcpporg/crypto) |
| crypto | [unified-sign](libraries/crypto/openspec/changes/unified-sign) | crypto: one sign and verify on every curve, the scheme always named, the key pair contract and four forms of each operation | wrapper | implementing | | 2026-11-22 | [code](https://github.com/webcpporg/crypto) |
| crypto | [uniform-types](libraries/crypto/openspec/changes/uniform-types) | crypto: typed signatures, typed X25519 keys, and concepts for key pairs, AEADs and boxes | wrapper | implementing | | 2026-11-22 | [code](https://github.com/webcpporg/crypto) |
| document | [genesis](libraries/document/openspec/changes/archive/2026-10-12-genesis) | document: a JSON document for C++20 that behaves as JavaScript does, in one relocatable image | own | implemented | 0.1.0 | 2026-10-12 | [code](https://github.com/webcpporg/document/tree/ac29296) |
| hash | [genesis](libraries/hash/openspec/changes/genesis) | hash: hashing and key derivation over Boost.Hash2 and C backends | wrapper | accepted | | 2026-11-14 | |
| hash | [data-independent-timing](libraries/hash/openspec/changes/data-independent-timing) | hash: the library sets arm64's DIT around every computation on a secret | wrapper | implementing | | 2026-11-20 | [code](https://github.com/webcpporg/hash) |
Expand Down
11 changes: 11 additions & 0 deletions libraries/crypto/openspec/changes/uniform-types/.openspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
schema: spec-driven
created: 2026-11-22
webcpp:
library: crypto
title: "crypto: typed signatures, typed X25519 keys, and concepts for key pairs, AEADs and boxes"
kind: wrapper
port_of: null
status: implementing
release: null
implementation: https://github.com/webcpporg/crypto
decided: 2026-11-22
742 changes: 742 additions & 0 deletions libraries/crypto/openspec/changes/uniform-types/design.md

Large diffs are not rendered by default.

121 changes: 121 additions & 0 deletions libraries/crypto/openspec/changes/uniform-types/proposal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
## Why

crypto/sign-unified gave every curve typed public keys, one key pair contract and one name per
operation, but three kinds of value are still bare bytes or ad hoc shapes:

- **Signatures** are `std::array<std::uint8_t, 64>` (65 for a recoverable one) on every curve and
scheme, and `verify` takes any `std::span<std::uint8_t const>`: a P-256 signature passed to
secp256k1, or an Ed25519 signature given to a DER encoder, is a run-time failure at best, and the
formats change (`libraries/crypto/openspec/changes/formats/`) cannot refuse `der` on Ed25519 or
know an ECDSA signature's curve.
- **X25519** has no types at all: its public key is `std::array<std::uint8_t, 32>`, its secret a
`secret<32>`, its operations free functions (`curves::x25519::public_key(secret)`,
`curves::x25519::agree(secret, peer)`), while Ed25519, P-256 and secp256k1 have key pairs with
`make`, `generate`, `public_key()`, `secret()` and `agree`. crypto_kx, the boxes and Ed25519's
conversion (`x25519_secret()`, `to_x25519_public`) pass the same raw bytes.
- **Contracts**: the one concept `crypto::keypair` requires `sign`, which an X25519 key pair has
not; the AEADs and boxes share a shape that no concept states, and secretbox carries additional
data it refuses (a "fake" parameter that must be empty).

On 2026-11-22 the owner decided to type all three in one small change merged before formats.

## What Changes

- **Typed signatures**: `ed25519::signature`, `p256::ecdsa_signature`,
`secp256k1::ecdsa_signature`, `secp256k1::recoverable_signature`,
`secp256k1::schnorr_signature`, each made by `from_bytes(bytes)` (its size checked) and giving
`bytes()`; every `sign` returns one, and every `verify` and `recover` takes one, synchronous and
asynchronous, member and free. The bytes overload of crypto/sign-unified (`verify` taking any
span and checking its size) is replaced: a signature from the wire is made first.
- **X25519 typed like the others**: `x25519::public_key` (`from_bytes`, `bytes()`),
`x25519::basic_keypair<B>` (`from_secret`, `generate`, `public_key()`, `secret()`, `agree(peer)`,
`async_agree`, free `crypto::agree` and `crypto::async_agree`); `kx_keypair` built on it; the
boxes take typed keys. The free `curves::x25519::public_key(secret)` and `agree(secret, peer)`
are removed.
- **Ed25519 to X25519 as a typed conversion**: `ed_key.to_x25519()` gives an
`x25519::basic_keypair<B>`, `ed_public_key.to_x25519()` an `x25519::public_key`, with the free
`crypto::to_x25519`; `x25519_secret()` and `curves::ed25519::to_x25519_public` are removed.
- **Three key pair concepts**: `crypto::keypair` (`from_secret`, `generate`, `public_key()`, `secret()`),
`crypto::signing_keypair` (also `sign` for each scheme it declares, at least one) and
`crypto::agreement_keypair` (also `agree`). Ed25519 signs; P-256 and secp256k1 sign and agree;
X25519 agrees.
- **AEAD and box concepts**: `secret_key_encryption::aead::cipher` (sizes, `result_type`,
`from_key(key)`, `seal(nonce, associated_data, data)`, `open(nonce, associated_data, data, tag)`),
its refinement `secret_key_encryption::aead::streaming_cipher` (AES-GCM's incremental seal and
open), and the sibling `secret_key_encryption::authenticated_box` (`seal(nonce, data)`, `open(nonce, data, tag)`)
for secretbox and crypto_box, which lose the additional data they refused. The free
`secret_key_encryption::aead::seal`, `open` and their asynchronous forms, and the box forms, are
constrained by them, and `async_seal` and `async_open` extend to every AEAD and box on native
backends; the browser backend keeps WebCrypto's AES-GCM only, refusing the others with a clear
message.
- **Secret-key encryption and spelled-out names** (owner decision 13, 2026-11-23): the AEAD
contract lives in `crypto::secret_key_encryption::aead`
(`<webcpp/crypto/secret_key_encryption/aead.hpp>`), and the free `seal`, `open`, `async_seal`
and `async_open` move there from `crypto::`; secretbox moves from `crypto::ciphers` to
`crypto::secret_key_encryption` (`<webcpp/crypto/secret_key_encryption/secretbox.hpp>`), beside
`public_key_encryption::box`; the algorithm types stay in `crypto::ciphers`; every public name is
spelled out, algorithm proper names excepted (`nonce`, `associated_data`, `nonce_size`,
`invalid_nonce_size`); no alias; webcpp::trystero migrates later.
- **The ChaCha20-Poly1305 template and libsecp256k1's abbreviations** (owner decision 14,
2026-11-23): `ciphers::aead<Family, Backend>` becomes `ciphers::basic_chacha20_poly1305`, the
aliases keeping their names; secp256k1's `pubkey_*` and `seckey_*` tweaks become `public_key_*`
and `secret_key_*`, MuSig2's `nonce_gen` becomes `generate_nonce`, and silent payments'
`prevouts_summary` becomes `previous_outputs_summary`; `agree`, `agree_hashed` and `agree_point`
stay; no alias.
- **Constructions grouped by purpose**: the namespace `crypto::hybrid` is removed;
`crypto::public_key_encryption` holds `basic_box`, `box`, `box_xchacha20poly1305`,
`basic_sealed_box` and `sealed_box` (`<webcpp/crypto/public_key_encryption/box.hpp>`,
`sealed_box.hpp`), and `crypto::key_exchange` holds `kx_keypair` and `session_keys`, out of
`curves::x25519` (`<webcpp/crypto/key_exchange/kx.hpp>`); no alias. "Hybrid" now names
post-quantum hybrids (X25519MLKEM768, X-Wing), which keep `crypto::hybrid` free; a future HPKE
goes to `public_key_encryption`.
- **Factories named by their input**, `make` removed with no alias: `K::from_secret(bytes)` and
`K::generate()` for key pairs, `T::from_bytes(bytes)` for public keys and signatures (P-256 also
`from_coordinates(x, y)`), `C::from_key(key)` for ciphers, AEADs and secretbox, crypto_box's
`from_keys(own, peer)`, kx's `from_keypair(x25519_keypair)` and `derive_from_seed(seed)`; free
`crypto::from_secret<K>`, `crypto::from_bytes<T>`, `crypto::from_key<C>`, `crypto::generate<K>`,
and `async_from_secret`, `async_from_key`, `async_generate`. `make` read as "make a key": a
caller who passed fixed bytes believing a key was drawn got a predictable private key.
- **Ed25519ph as a scheme** (owner decision 12, 2026-11-23): `crypto::eddsa_prehashed` in the one
list of schemes, which Ed25519's signing key pair declares, taking `crypto::prehashed{digest}` of
64 bytes (the message's SHA-512) and refusing a message at compile time, giving
`ed25519::signature`, with `verify(eddsa_prehashed, signature, prehashed, public_key)` and the
member form, asynchronous on native backends only; the streaming `curves::ed25519::ph<Hash, B>`
is renamed `curves::ed25519::prehashed_signer<Hash, B>`, no alias, and no distinct Ed25519ph
signature type exists.
- **Secret hygiene named by what it does** (owner decision 11, 2026-11-23): `crypto::equal` becomes
`crypto::constant_time_equal` (`<webcpp/crypto/constant_time_equal.hpp>`), no alias, every caller
moved, webcpp::hash's included; the public wipe is `crypto::erase_secret`
(`<webcpp/crypto/erase_secret.hpp>`); the guide groups them with `secret<N>` and
`random_device` in one section about protecting secrets outside the primitives.
- **Four mirrored forms** for every new operation that calls a backend.

## Capabilities

### New Capabilities

None.

### Modified Capabilities

- `crypto`: every signature and every X25519 key has a type of its own; key pairs, AEADs and boxes
are checked by concepts; the AEAD contract and secretbox are `secret_key_encryption`'s; public
names are spelled out; secretbox and crypto_box take no associated data; seal and open are
asynchronous on every native backend.

## Impact

- **Kind:** a wrapper (`"port-of": null`), as the genesis.
- **Breaking:** yes, before the first release. Order: crypto/sign-unified merges; then this change;
then crypto's formats; then phase 3 of
webcpp::trystero's port of Trystero 0.27, which adapts to both.
- **Implementation:** webcpporg/crypto (`signing.hpp`, `keypair.hpp`, `curves/*.hpp`,
`key_exchange/kx.hpp` (was `curves/x25519/kx.hpp`), `ciphers/*.hpp`,
`public_key_encryption/*.hpp` (was `hybrid/*.hpp`), `secret_key_encryption/aead.hpp` (new: the
AEAD contract) and `secret_key_encryption/secretbox.hpp` (was `ciphers/secretbox.hpp`), `secret_key_encryption/authenticated_box.hpp` (new), `async.hpp`, tests, examples, benches, the constant-time lane, `doc/`, `doc/tables/crypto.json` and
the generated files), webcpporg/hash (the callers of `crypto::equal` in its examples, headers'
comments and pages), the superproject's pointers.
- **Status:** approved by the owner on 2026-11-22 (`decided`); `implementing` since 2026-11-24:
built on the branches `crypto/uniform-types` of webcpporg/crypto (head `e07d44a`),
webcpporg/hash (`659e50d`) and the superproject (`0ab0ace`), verified locally on every lane
(`tasks.md`, 4.2); the pull requests, their merges and the CI on GitHub remain.
Loading