Skip to content

crypto: primitives - RFC 8439's raw ChaCha20 and Poly1305: ciphers::chacha20 on libsodium, BearSSL and OpenSSL, authenticators::poly1305 on libsodium and OpenSSL - #30

Merged
pinhopro merged 26 commits into
mainfrom
crypto/primitives
Dec 5, 2026

Conversation

@pinhopro

@pinhopro pinhopro commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

crypto's change primitives (proposals: libraries/crypto/openspec/changes/primitives), Tasks 1-13 of its plan: RFC 8439's raw ChaCha20 and Poly1305.

  • ciphers::chacha20<> (basic_chacha20<Family, Backend>), RFC 8439's raw stream cipher, in the new crypto::unauthenticated_encryption with the concept stream_cipher and the free forms apply_keystream / async_apply_keystream; the concept and free forms read the algorithm's own nonce_size, block_size and counter_type (owner decision 7), the counter's end computed by detail::counter_overflows, error::counter_overflow (22) when it would wrap. On libsodium (the default on every target), BearSSL and OpenSSL; OpenSSL runs in pieces of 2^30 bytes.
  • authenticators::poly1305<Backend>, RFC 8439's one-time authenticator (owner decision 6): no object, static authenticate and verify, in the new crypto::single_use_key_authentication with the concept single_use_key_authenticator and its four forms. On libsodium and OpenSSL; BearSSL refused by name.
  • Asynchronous forms, member and free; on a backend that completes by itself (WebCrypto) each refuses with its own message alone: the stream, AEAD, secretbox and box refusal structs take bool = asynchronous_backend_v<Backend>, so the engine's generated refusal stays silent there (found by the final review; pinned by message tests).
  • Tests: the backends' agreement (2^30 + 64 bytes included), NIP-44 version 2's end-to-end vectors through ChaCha20 on the three backends, RFC 8439's AEAD composed from the raw pieces as an 18-cell cross-backend test, every refusal a message test with its MSVC twin; the constant-time lane (memcheck, MemorySanitizer, dudect: keystream, authenticate, verify of two failing tags).
  • Docs: the ChaCha20 section and a Poly1305 page in the guide, two examples, sizes and bench programs; the generator resolves namespace-qualified free functions (a bare name two namespaces declare is a Fault).

Verification, all local and green on this head: five local lanes (clang 776, gcc-15 550, wasip2 723, wasip3 705, emscripten 455, 0 failed), agreement at release, c-suites, docs and tools tests, both full lints, Linux constant-time, Mac dudect, MSVC 14.3 and 14.5 x64 debug, arm64 14.5 timing set (table: proposals' reference/STATUS.md). No CI ran: the owner's one CI on main comes at the end.

🤖 Generated with Claude Code

R added 26 commits December 5, 2026 01:26
…, the concept stream_cipher and its free form, on libsodium
… three backends, NIP-44 composed in the tests alone
…er memcheck and MemorySanitizer, OpenSSL under memcheck) and in dudect
…the concept single_use_key_authenticator and its free forms, on libsodium
…'s refusal pinned, the stream cipher's fallbacks, BearSSL's code paths checked, NIP-44's keys wiped
… composed from the raw pieces as an 18-cell cross-backend test, the asynchronous forms and the refusal on a backend that completes by itself
…s a macro (near), so composition_rfc8439 compiles on MSVC
…and MemorySanitizer, OpenSSL under memcheck) and in dudect
… brief kept apart, the error completions posted, makes_empty_v through friendship
…afe_value, which clang-tidy's exception-escape accepts in a noexcept from_key
…nd that completes by itself, OpenSSL's ChaCha20 in pieces of 2^30, the synchronous verify's refusal pinned
…oly1305's message pointer named apart from a program's globals
@pinhopro
pinhopro merged commit 0467566 into main Dec 5, 2026
1 of 3 checks passed
@pinhopro
pinhopro deleted the crypto/primitives branch December 5, 2026 16:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant