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 @@ -60,6 +60,7 @@ tag is placed.
| 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 | [formats](libraries/crypto/openspec/changes/formats) | crypto: one encode and one decode for every key and signature format, the format as a value | wrapper | implementing | | 2026-11-22 | [code](https://github.com/webcpporg/crypto) |
| crypto | [one-verb](libraries/crypto/openspec/changes/one-verb) | crypto: codecs' verbs are crypto's: crypto::encode and crypto::decode removed, the check declared to codecs, PEM on a fixed label and decoded in place | wrapper | implementing | | 2026-12-02 | [code](https://github.com/webcpporg/crypto) |
| crypto | [rfc9001-tests](libraries/crypto/openspec/changes/rfc9001-tests) | crypto: RFC 9001 Appendix A's QUIC packet protection vectors as interop tests, on every AES-GCM backend, no QUIC API | wrapper | implementing | | 2026-12-01 | [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) |
Expand Down
11 changes: 11 additions & 0 deletions libraries/crypto/openspec/changes/rfc9001-tests/.openspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
schema: spec-driven
created: 2026-12-04
webcpp:
library: crypto
title: "crypto: RFC 9001 Appendix A's QUIC packet protection vectors as interop tests, on every AES-GCM backend, no QUIC API"
kind: wrapper
port_of: null
status: implementing
release: null
implementation: https://github.com/webcpporg/crypto
decided: 2026-12-01
98 changes: 98 additions & 0 deletions libraries/crypto/openspec/changes/rfc9001-tests/design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
## Context

Read on crypto's `main` of 2026-12-04 (`c3c584b`) and hash's (`dc0068a`):

- `ciphers::gcm<aes128<B>>` (`ciphers/gcm.hpp`) seals in place, `seal(nonce, associated_data,
data)` returning the 16-byte tag, and opens in place, `open(nonce, associated_data, data, tag)`,
`data` zeroed on `authentication_failed`; on BearSSL and OpenSSL. `aes128_gcm` is
`gcm<aes128<>>`, AES-GCM's default: OpenSSL natively, BearSSL on wasip2, wasip3 and Emscripten
(`/webcpp/crypto//gcm-default`).
- `ciphers::aes128<B>` (`ciphers/aes.hpp`) is the public AES block cipher: `from_key(key)`, then
`encrypt(blocks)` in place on whole 16-byte blocks, on OpenSSL and ctaes; BearSSL has none
(`aes_on_bearssl`, refused at build time). `aes128<>` is the block cipher's default: OpenSSL
natively, ctaes on WebAssembly (`/webcpp/crypto//aes_block-default`).
- `hash::hkdf_extract<hash::hmac_sha2_256>(salt, input_key_material)` and
`hash::hkdf_expand<hash::hmac_sha2_256>(output, pseudorandom_key, byte_pieces{...})`
(`<webcpp/hash/hkdf.hpp>`, hash's change `hkdf-pieces`), on hash's default backend (Boost.Hash2)
on every target.
- ChaCha20-Poly1305 is public as an AEAD (`ciphers::chacha20_poly1305<B>`); raw ChaCha20 is not:
it is inside the AEAD's engines alone, and the change `../primitives` plans
`ciphers::chacha20<B>::apply_keystream`.
- The GCM tests are one program per backend (`test/gcm_bearssl_test.cpp`, `gcm_openssl_test.cpp`)
over shared checks (`test/support/gcm_checks.hpp`), each built with exceptions on and off by
the Jamfile's `crypto-run`.

RFC 9001 Appendix A: A.1 the Initial keys of the Destination Connection ID 0x8394c8f03e515708
(with section 5.2's `initial_salt`), A.2 the client's Initial (1,200 bytes, packet number 2 on 4
bytes), A.3 the server's Initial (packet number 1 on 2 bytes), A.4 a Retry packet and its
integrity tag (section 5.8's fixed key and nonce), A.5 a ChaCha20-Poly1305 short header packet.

## Goals / Non-Goals

**Goals:** every value of A.1 to A.4 reproduced byte for byte by crypto's public API, in both
directions (protect gives the RFC's packet, unprotect gives back the RFC's header and payload),
on OpenSSL, on BearSSL (with ctaes for the block), and on the defaults of every target.

**Non-goals:** a QUIC API, a public HKDF-Expand-Label, packet number decoding (RFC 9000 Appendix
A.3), A.5, key updates, the AEAD limits of RFC 9001 section 6.6.

## Decisions (the stream's rulings)

- **R1. Tests only, no public function.** TLS 1.3's `HKDF-Expand-Label` is written in
`test/support/quic_rfc9001.hpp`: the label `HkdfLabel` (RFC 8446 section 7.1) is passed to
`hash::hkdf_expand` as pieces, `{length, label length, "tls13 ", label, context length}`, with no
buffer. QUIC and TLS 1.3 belong to a later library, not to crypto; with no public function, no
timing guard or coverage test changes.
- **R2. A single AES block is public.** Header protection's `AES-ECB(hp, sample)` is
`aes128<B>::from_key(hp)` and `encrypt` on a copy of the 16-byte sample: no new API. BearSSL has
no block cipher, so its program pairs `gcm<aes128<backends::bearssl>>` with
`aes128<backends::ctaes>`, the pair the defaults make on WebAssembly.
- **R3. Three programs, one support header.** `quic_rfc9001_openssl` (OpenSSL for both, native,
wasip2, wasip3), `quic_rfc9001_bearssl` (BearSSL and ctaes, every target, Emscripten included),
`quic_rfc9001_default` (`aes128_gcm` and `aes128<>` through the two default aliases, every
target); each also `_no_exceptions`. The checks are templates over the GCM's and the block's
backends in `test/support/quic_rfc9001.hpp`; the vectors are in
`test/support/quic_rfc9001_vectors.hpp`, each with its RFC section.
- **R4. HKDF on hash's default backend.** HKDF is webcpp::hash's and tested there on every hash
backend; these tests use `hash::hmac_sha2_256` on the default (Boost.Hash2) in every program,
so that each program differs only in crypto's backends.
- **R5. Both directions, and one refusal.** Protect: seal with the nonce `iv XOR packet number`
and the unprotected header as associated data, sample at packet number offset + 4, mask the
first byte's low 4 bits (long header) and the packet number bytes, equal to the RFC's packet.
Unprotect: unmask from the same sample, read the packet number length from the unmasked first
byte, open, equal to the RFC's header and payload. A packet with one bit flipped in its
ciphertext is `authentication_failed` with the payload zeroed. The packet number is the RFC's
(2 and 1); its reconstruction from the truncated field is QUIC's, not crypto's.
- **R6. The Retry tag both ways.** The tag is `seal` of an empty plaintext under section 5.8's key
and nonce, the Retry pseudo-packet (ODCID length, ODCID, the Retry packet without its tag) as
associated data, equal to A.4's last 16 bytes; `open` of the empty plaintext with the RFC's tag
succeeds, with a changed ODCID it is `authentication_failed`.
- **R7. A.5 left out.** Its payload AEAD is public, but its header protection needs raw ChaCha20
(`ChaCha20(hp, counter, nonce, {0,0,0,0,0})`), which crypto does not expose; A.5 joins these
tests in the change `../primitives`, with `ciphers::chacha20`. Testing A.5's payload alone would
check half a vector and is not done.
- **R8. The capability table.** `doc/tables/crypto.json` adds `quic_rfc9001_openssl` to the
evidence of `gcm` and `aes_block` on OpenSSL, `quic_rfc9001_bearssl` to `gcm` on BearSSL and
`aes_block` on ctaes; `generate.py` regenerates the pages. No changelog line: nothing a user
calls changes.
- **R9. Provenance.** The vectors are copied from the RFC Editor's text of RFC 9001
(https://www.rfc-editor.org/rfc/rfc9001.txt): section 5.2 (`initial_salt`), section 5.8 (the
Retry key and nonce), Appendix A.1 to A.4; each constant names its section.

## Risks / Trade-offs

- [The packet number length comes from the unmasked first byte] The unprotect path reads it as a
receiver must; a wrong mask shows as a wrong length and a failed open, not as a silent pass.
- [The defaults' program repeats a pair] Natively it is the OpenSSL pair again; on WebAssembly the
BearSSL and ctaes pair. It pins that the defaults a user writes, `aes128_gcm` and `aes128<>`,
do QUIC on every target.

## As built

Built on 2026-12-04 on crypto's branch `crypto/rfc9001-tests` (webcpporg/crypto#24), as designed.
Two things the lint asked for, which change nothing of the rulings: the labels are
`std::string_view` constants viewed as bytes (`bytes_of`, as `secp256k1_ethereum_test.cpp` does),
not C arrays; the header protection's bit operations are on `unsigned`. Local verification: clang
and gcc-15 natively, wasip2 and wasip3 6 of 6 each; Emscripten 4 of 4 (no OpenSSL there); MSVC
14.3 and 14.5 x64 debug 6 of 6 each; the checks seen failing with one byte of the Retry key and of
A.2's mask changed; the macOS lint and the Linux lint clean.
45 changes: 45 additions & 0 deletions libraries/crypto/openspec/changes/rfc9001-tests/proposal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## Why

The roadmap's item "crypto aes128-gcm" asked for AES-128-GCM. It already exists:
`ciphers::aes128_gcm` is `gcm<aes128<>>` (`<webcpp/crypto/ciphers/aes256_gcm.hpp>`), OpenSSL
natively and BearSSL on WebAssembly. On 2026-12-01 the owner shrank the item to what is still
missing: evidence, with published vectors, that webcpp::crypto (with webcpp::hash's HKDF) does
QUIC version 1's packet protection byte for byte, as RFC 9001 Appendix A shows it. QUIC is the
first protocol a webcpp user is likely to build on AES-128-GCM, and its appendix exercises the
pieces together: HKDF-Extract and HKDF-Expand-Label, the AEAD with a nonce from the packet
number, the header protection's single AES block, and the Retry integrity tag.

## What Changes

- **Tests only.** New test programs of `libs/crypto/test` run RFC 9001 Appendix A.1 to A.4 on
every backend pair that provides AES-128-GCM and the AES block cipher: OpenSSL with OpenSSL,
BearSSL with ctaes (BearSSL has no block cipher), and the families' defaults.
- **No QUIC API and no new public function.** TLS 1.3's HKDF-Expand-Label ("tls13 " labels) is
written in the test's support header over `hash::hkdf_expand`'s pieces form; header protection
calls the public `ciphers::aes128<B>::encrypt` on one 16-byte block.
- **A.5 (ChaCha20-Poly1305 short header) is left out:** crypto exposes the ChaCha20-Poly1305
AEAD but not raw ChaCha20, which its header protection needs; it is the planned
`ciphers::chacha20` of the later change `primitives`, which adds A.5's vector.
- The capability table names the new tests among the evidence of AES-GCM and the AES block
cipher (`doc/tables/crypto.json`, its generated pages regenerated).

## Capabilities

### New Capabilities

None.

### Modified Capabilities

- `crypto`: AES-128-GCM and the AES block cipher are tested against RFC 9001 Appendix A's QUIC
packet protection vectors on every backend that provides them.

## Impact

- **Kind:** a change to a wrapper (`"port-of": null`), tests and the generated table only.
- **Implementation:** the branch `crypto/rfc9001-tests` of the library, by
`reference/plan.md`; the superproject only moves its gitlink.
- **Status:** decided by the owner on 2026-12-01 (the item shrunk to these tests); the calls
left to the stream are the rulings of `design.md`.
- **Dependencies:** none new. HKDF is webcpp::hash's, which crypto already depends on.
- **Other proposals:** `../primitives` (raw ChaCha20) adds RFC 9001 A.5 when it lands.
110 changes: 110 additions & 0 deletions libraries/crypto/openspec/changes/rfc9001-tests/reference/plan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
---
title: "webcpp::crypto, RFC 9001 Appendix A interop tests: Implementation Plan"
tags: [webcpp, crypto, gcm, aes, quic, rfc9001, tests, plan]
status: accepted
created: 2026-12-04
---

# webcpp::crypto, RFC 9001 Appendix A interop tests: Implementation Plan

**Goal:** RFC 9001 Appendix A.1 to A.4 reproduced byte for byte by crypto's public API on
OpenSSL, on BearSSL with ctaes, and on the defaults, on every target each builds on.

**Architecture:** tests only (`../design.md` R1 to R9). One header of vectors, one header of
checks templated on the AEAD and the block cipher, three programs, their Jamfile lines and the
capability table's evidence.

**Spec:** `../proposal.md`, `../design.md`, `../specs/crypto/spec.md`, `../tasks.md`.

Paths are relative to the library, `libs/crypto/` of the superproject. `$B2` is
`env -u CPATH -u CPLUS_INCLUDE_PATH -u C_INCLUDE_PATH b2 --user-config=.local/user-config.jam`,
run from the superproject's root.

## Global Constraints

- English everywhere, no em dash, no trailer in commits; never edit a generated file (run
`python3 doc/tables/generate.py`).
- Every vector is copied from https://www.rfc-editor.org/rfc/rfc9001.txt and names its section;
a script checks that every hex string of the vectors' header occurs in the RFC's text.
- No public function is added (R1); nothing goes to known-failures.

## Task 1: the vectors and the checks

Files: `test/support/quic_rfc9001_vectors.hpp`, `test/support/quic_rfc9001.hpp`.

- [ ] Step 1: the vectors: section 5.2's salt, the connection ID, A.1's five HkdfLabels and
secrets, A.2's CRYPTO frame (PADDING to 1,162 bytes), header, sample, mask and packet, A.3's
payload, header, sample, mask and packet, A.4's Retry packet, section 5.8's key and nonce.
- [ ] Step 2: the checks, HKDF-Expand-Label as pieces:

```cpp
template <std::size_t N>
std::array<std::uint8_t, N> expand_label(std::span<std::uint8_t const> secret,
std::span<std::uint8_t const> label) {
hkdf_label const info(N, label); // {length, label length, "tls13 ", label, 0}
auto const info_pieces = info.pieces();
std::array<std::uint8_t, N> output{};
auto const expanded =
webcpp::hash::hkdf_expand<webcpp::hash::hmac_sha2_256>(output, secret, info_pieces);
require(BOOST_TEST(expanded.has_value()));
return output;
}
```

and the header protection's mask on one public AES block (R2):

```cpp
template <class Block>
std::array<std::uint8_t, 5> header_protection_mask(std::span<std::uint8_t const> hp,
std::span<std::uint8_t const> sample) {
auto cipher = Block::from_key(hp);
require(BOOST_TEST(cipher.has_value()));
std::array<std::uint8_t, 16> block{};
std::copy_n(sample.begin(), block.size(), block.begin());
require(BOOST_TEST(cipher->encrypt(block).has_value()));
std::array<std::uint8_t, 5> mask{};
std::copy_n(block.begin(), mask.size(), mask.begin());
return mask;
}
```

then `protect` and `unprotect` (R5), `check_keys`, `check_client_initial`,
`check_server_initial`, `check_tampered_initial`, `check_retry` (R6) and `check_appendix_a`.

## Task 2: the programs

Files: `test/quic_rfc9001_openssl_test.cpp`, `test/quic_rfc9001_bearssl_test.cpp`,
`test/quic_rfc9001_default_test.cpp`, `test/Jamfile`.

- [ ] Step 1: the three programs and their lines (R3):

```jam
crypto-run quic_rfc9001_openssl : quic_rfc9001_openssl_test.cpp
: <library>/webcpp/crypto//openssl : native wasip2 wasip3 ;
crypto-run quic_rfc9001_bearssl : quic_rfc9001_bearssl_test.cpp
: <library>/third_party//bearssl <library>/third_party//ctaes ;
crypto-run quic_rfc9001_default : quic_rfc9001_default_test.cpp
: <library>/webcpp/crypto//gcm-default <library>/webcpp/crypto//aes_block-default ;
```

- [ ] Step 2: seen failing: one byte of the Retry key and of A.2's mask changed, the program
fails on exactly those checks; restored, it passes.
- [ ] Step 3: `$B2 toolset=clang` natively, then `toolset=clang-wasip2`, `clang-wasip3` and
`emscripten`, each program with and without exceptions.

## Task 3: the capability table

- [ ] `doc/tables/crypto.json`: `quic_rfc9001_openssl` under `gcm` and `aes_block` on OpenSSL,
`quic_rfc9001_bearssl` under `gcm` on BearSSL and `aes_block` on ctaes (R8);
`python3 doc/tables/generate.py`, then `--check`.

## Task 4: local verification

- [ ] clang-format and clang-tidy on the new files (macOS), the Linux lint through `heavy.sh`
(`--files` with the new sources), the MSVC lane once on the three programs (14.3 and 14.5 x64).

## Task 5: delivery

- [ ] crypto's pull request and proposals' pull request; their CI green; merged. Then, once
webcpp#65 is merged, the superproject's pull request moving `libs/crypto` to the merge, its CI
green, merged; `tasks.md` ticked and the status written back.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## ADDED Requirements

### Requirement: QUIC packet protection: RFC 9001 Appendix A's vectors
The library's tests SHALL reproduce RFC 9001 Appendix A.1 to A.4 byte for byte with the public API alone (`ciphers::gcm<aes128<B>>`, `ciphers::aes128<B>`, and webcpp::hash's `hkdf_extract` and `hkdf_expand` over pieces for HKDF-Expand-Label), on OpenSSL, on BearSSL with ctaes as the block cipher, and on the families' defaults, on every target where each pair builds, with exceptions on and off. The library MUST NOT gain a QUIC or TLS function for it.

#### Scenario: The Initial keys
- **WHEN** the test derives the initial secret from section 5.2's salt and the connection ID 0x8394c8f03e515708, then the client's and the server's secrets, keys, IVs and header protection keys with the "tls13 " labels
- **THEN** each equals A.1's value, and each encoded HkdfLabel equals A.1's label bytes

#### Scenario: The client's and the server's Initial packets
- **WHEN** the test protects A.2's and A.3's headers and payloads with the nonce `iv XOR packet number` and the header protection mask `AES-ECB(hp, sample)`
- **THEN** the packet equals the RFC's protected packet, and unprotecting the RFC's packet gives back its header and payload

#### Scenario: A tampered packet
- **WHEN** one bit of A.2's protected payload is flipped and the packet is unprotected
- **THEN** the open returns `authentication_failed` and the payload is zeroed

#### Scenario: The Retry integrity tag
- **WHEN** the test seals an empty plaintext under section 5.8's key and nonce with A.4's Retry pseudo-packet as associated data
- **THEN** the tag equals A.4's last 16 bytes, it opens, and with another original connection ID it does not

#### Scenario: A.5 waits for raw ChaCha20
- **WHEN** a reader looks for A.5 (ChaCha20-Poly1305 short header)
- **THEN** the design says it joins with the change `primitives`, whose `ciphers::chacha20` gives the header protection's keystream
18 changes: 18 additions & 0 deletions libraries/crypto/openspec/changes/rfc9001-tests/tasks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Tasks

Each task points to its section in `reference/plan.md`.

## 1. Tests

- [x] 1.1 The vectors and the checks: `test/support/quic_rfc9001_vectors.hpp` and
`test/support/quic_rfc9001.hpp` (plan: Task 1)
- [x] 1.2 The three programs and their Jamfile lines, seen failing first, then passing on every
lane (plan: Task 2)
- [x] 1.3 The capability table's evidence, regenerated (plan: Task 3)

## 2. Delivery

- [x] 2.1 Local verification: the programs on native, wasip2, wasip3, Emscripten; the macOS lint
and the Linux lint; the MSVC lane once (plan: Task 4)
- [ ] 2.2 The pull requests (crypto, proposals), their CI, the merges; the superproject's gitlink
after webcpp#65 (plan: Task 5)