Repository navigation
crypto: uniform types (typed signatures and keys, factories by input, secret_key_encryption) - #18
Merged
Merged
Conversation
added 30 commits
November 23, 2026 10:22
…penSSL memory adapter
…tories reads as make
…to_kx is key_exchange's, and crypto::hybrid is free
…change chapter, and the moved comments keep their width
…hpp's @see names its chapter as the page titles it
… stores the optimiser keeps
… elements that are not trivially copyable
…eference renders each span whole
…arameter names they are declared with
…e_from_seed, the name they have
…y and recover takes it
…er, refuses any other, and gives each verify its signature's bytes in one call
…atch-all alone refuses it
… its local has, so the memcheck and MemorySanitizer programs compile again
…n for Valgrind's header, so a mark naming a stale local stops the build everywhere
…der includes Hash2's digest only with the Keccak-256 path that names it
…gner is prehashed_signer
…_prehashed verify refuses it in a test, and whether a scheme takes a message is its traits'
… agreed like the other curves'
…kend that completes by itself stop in a message test
…s users refuse a moved-from one
… before libsodium, beside the weak peer
added 27 commits
November 23, 2026 20:01
…nux clang-tidy asks
…rowser, never a terminated page
On Emscripten, read_entropy called getentropy, which Emscripten's
libwasi.js serves with randomFill (crypto.getRandomValues, or node's
randomFillSync while MIN_NODE_VERSION is below 19), declared
random_get__nothrow: an exception thrown there unwound through
WebAssembly and ended the program. read_entropy now draws with an
EM_ASM_INT that calls crypto.getRandomValues on a fresh array, catches
a throw (entropy_unavailable) and answers not_supported where there is
no crypto.getRandomValues (an audio worklet). EM_ASM_INT, not the
brief's EM_JS (ruling F3): EM_JS defines external symbols per
translation unit, and random_device_browser, linked from two units,
failed with "wasm-ld: error: duplicate symbol:
__em_js_ref_webcpp_crypto_fill_random" with it.
Reproduced first with random_device_browser under node (Emscripten
6.0.11, node 26.13.0), before the fix:
random_device_browser (exceptions on):
libc++abi: terminating
Aborted(native code called abort())
RuntimeError: unreachable
at ... std::terminate()
at ... webcpp::crypto::detail::read_entropy(unsigned char*, unsigned long)
at ... webcpp::crypto::detail::fill_from_system(...)
EXIT STATUS: 1
random_device_browser_no_exceptions:
Error: planted
at Object.planted [as randomFillSync] (random_device_browser_no_exceptions.js:5065:48)
at randomFill (random_device_browser_no_exceptions.js:1243:61)
at _random_get (random_device_browser_no_exceptions.js:4478:39)
at random_device_browser_no_exceptions.wasm.getentropy
at ... webcpp::crypto::detail::read_entropy(unsigned char*, unsigned long)
EXIT STATUS: 1
…onditional, as the Linux clang-tidy asks
…lls back to node's webcrypto on node 18, with a wasm32 check
…a sealed box reports a failed draw
On Emscripten libsodium drew through its own JavaScript, whose stir throws
"No secure random number generator found" when crypto.getRandomValues and
node's randomBytes throw; the throw unwound through WebAssembly. Reproduced
with sodium_entropy_browser before the fix (both sources planted to throw,
then public_key_encryption::sealed_box::seal):
exceptions on: libc++abi: terminating
Aborted(native code called abort())
... at webcpp::crypto::detail::sodium_ready()
... at sealed_box_engine<sealed_box, sodium>::seal(...)
exceptions off: UnhandledPromiseRejection: ... The promise rejected with
the reason "No secure random number generator found".
sodium_ready now installs crypto's entropy as libsodium's generator
(randombytes_set_implementation) once, before its first sodium_init, on
Emscripten, and watches sodium_init's draw (its sodium_malloc canary):
entropy_unavailable when it failed. The sealed box engine watches
crypto_box_seal's draw of the ephemeral key and, when it failed, zeroes the
output and returns entropy_unavailable. A failed draw outside a watched call
ends the program through sodium_misuse, never handing zeros on (P26),
checked by sodium_entropy_unwatched (webcpp.run-fail). Off Emscripten the
watch is a stub with no thread-local state, whose first access allocates on
macOS (allocation_sodium).
…function and installs once through a once_flag, as the Linux clang-tidy asks
…in the browser, and every libsodium function documents the errors of its first call Review fix round 1 of Task X1b. On Emscripten sodium_ready probes crypto's entropy with a small draw before sodium_init, until crypto has seen libsodium initialised: a failed probe returns its error without calling sodium_init, so libsodium never keeps a zero sodium_malloc canary from a source that already fails, and the next call tries again (supersedes F4's consequence). The watch stays for a canary draw that fails after a good probe. A failed draw keeps the source's error: errc::not_supported where there is no generator, as random_device reports it. backends::sodium, error::entropy_unavailable and the header of every family on libsodium state the first call's errors. Comments say why no watched call reaches randombytes_uniform and why call_once holds inside noexcept. sodium_entropy_browser now checks a first from_secret and seal under throwing sources (entropy_unavailable) and with no source (not_supported), that sodium_init has not run after them, and the seal's own draw once libsodium is initialised.
…t's world rule reads as a call
…n the browser's backend The D6 refusal (detail::refuse_aead_on_asynchronous_backend) fires from the synchronous seal, open and from_key as from the asynchronous forms since Task 3.3's fix round, but its text named only async_seal, async_open and async_from_key. It now says that no form of ChaCha20-Poly1305, XChaCha20-Poly1305, the secret box or crypto_box runs on the browser's backend and names a native backend; the ten message tests that pin it, their fixes, the member comment of ciphers/aead.hpp, async.hpp's overview and doc/async.adoc follow.
…cha20_poly1305, named for its algorithm Owner decision 14 (design D12): ciphers::aead<Family, Backend> becomes ciphers::basic_chacha20_poly1305<Family, Backend>, with no alias; the aliases chacha20_poly1305, chacha20_poly1305_original and xchacha20_poly1305 and the header <webcpp/crypto/ciphers/aead.hpp> keep their names (R25). The refusal of a family that is no AEAD's names the new class, the timing seam's member labels follow it, and crypto.json's member functions are basic_chacha20_poly1305::async_*. Two message tests pin the removed name: aead_template_removed (a using-declaration) and aead_template_removed_call (an alias over the old name and a call through it, whose two errors are the same on every clang, unlike the inline template-id, which draws a typo correction to the C library's read that differs with clang's version and the C library).
…ry spell out the names libsecp256k1 abbreviates Owner decision 14 (design D12, R24): pubkey_tweak_add, pubkey_tweak_mul, pubkey_negate and pubkey_combine become public_key_tweak_add, public_key_tweak_mul, public_key_negate and public_key_combine; seckey_tweak_add, seckey_tweak_mul and seckey_negate become secret_key_tweak_add, secret_key_tweak_mul and secret_key_negate; musig::nonce_gen becomes musig::generate_nonce; silent_payments::prevouts_summary and make_prevouts_summary become previous_outputs_summary and make_previous_outputs_summary. No alias; the signatures, guards, timing coverage, capability rows and workspace helpers are unchanged (R25). Every caller moves: tests, examples, the bench, the constant-time paths, the pages and crypto.json. A comment that quotes libsecp256k1 names its C identifier in full, and the BIP vectors keep their field names. Six message tests pin the removed names, as a using-declaration and as a call.
timing_coverage.hpp's file comment rewrapped to 100 columns (clang-format) and four Jam comments to 80.
…error first, and leaves out clang's knock-on errors generate.py kept the last expected-error of a message test, so aead_template_removed_call's row showed the undeclared alias clang adds, and a test of several removed names (async_seal_removed, the secp256k1 and prevouts removals) showed only its last. A row now holds every text its test pins, each once, in the source's order, but a directive that ends with (knock-on), an error clang adds because of another, which the test still checks; two generate_test cases fail on the old reading. Six tests mark their knock-on errors. The pages' renamed lines are rewrapped to their paragraphs' width.
…s state the page's rule Both directives of heavy_without_threads match by a file wildcard, so source order is not clang's order: the refusal's directive now comes first and run_on_work's stand-in is marked knock-on. heavy_without_threads and heavy_without_threads_first's comments describe generate.py's rule (directives in source order, a knock-on one skipped) instead of its old last-directive reading.
…ry call, and the free asynchronous signing forms say which arguments they pass on
…nd the factories by input
… asynchronous family, and the overview names every namespace
…459 stays quiet in the library's templates
…he stack, the probe's and randombytes_random's 4 bytes wiped
…ret(), to_x25519_public, crypto::wipe and erase_secret's pointer and size are gone
…'s wipe and kx's from_keypair
… a dead frame under the padding
…pins clang's generic cast error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the uniform-types change (webcpporg/proposals, libraries/crypto/openspec/changes/uniform-types, owner decisions 1-14).
signreturns its curve's signature type, everyverify/recovertakes it.from_secret,from_bytes,from_key);makeis gone.to_x25519().keypair,signing_keypair,agreement_keypair.secret_key_encryption::aead(conceptscipher,streaming_cipher, freeseal/open/async_seal/async_open),secret_key_encryption::secretboxwithout associated data,secret_key_encryption::authenticated_box; asynchronous seal/open/from_key on every native backend.ecdsa_keccak256_recoverable(Ethereum) andeddsa_prehashed(Ed25519ph);curves::ed25519::prehashed_signer.crypto::erase_secret,crypto::constant_time_equal(wasequal), spelled-out public names (nonce, associated data,basic_chacha20_poly1305, secp256k1'spublic_key_*/secret_key_*,musig::generate_nonce,previous_outputs_summary).getRandomValuesgivesentropy_unavailable, never a terminated page; libsodium draws through crypto's entropy on Emscripten.Verified locally: clang (with hash), gcc-15, Emscripten (both exception variants), wasip2, wasip3, MSVC 14.3 x64, 14.5 x64 and arm64, Linux lint --full and macOS full lint (clean), constant-time lane (memcheck, MSan, dudect), crypto_jamfiles fixtures, generated tables.