diff --git a/.gitattributes b/.gitattributes index cc23192c..cf5eb6ea 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,4 @@ * text=auto eol=lf *.bat text eol=crlf +# The fuzz corpora are inputs byte for byte: no line ending of theirs is converted. +test/fuzz/corpus/** -text diff --git a/AGENTS.md b/AGENTS.md index 7f729c4f..c83afd3b 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -12,9 +12,11 @@ specific to crypto. - **webcpp's own library** (`"port-of": null`) over C backends: BearSSL, OpenSSL, ctaes, libsecp256k1 and libsodium (the superproject's `/third_party//sodium`, shared with webcpp::hash). The algorithms are the backends'; crypto is the interface shaped as Boost.Hash2's. - crypto depends on config, hash and secure: the timing guard, `erase_secret`, + crypto depends on config, hash, secure and codecs: the timing guard, `erase_secret`, `constant_time_equal`, `secret` and `declassify` are webcpp::secure's, with no copy and no - alias in crypto. + alias in crypto; the key formats are codecs formats, registered through `codecs::value_codec`, + and only `include/webcpp/crypto/formats.hpp` and each `curves//formats.hpp` include a + codecs header (an include boundary). - **No oracle.** No original runs beside crypto: the evidence is the published vectors (the GCM specification's cases, Wycheproof, FIPS 197, RFC 8439 and RFC 8032, BIP340 and BIP341), the backends' own suites in the lane `c-suites`, and the agreement tests, which compare two backends @@ -66,8 +68,12 @@ specific to crypto. form `(q | -q) >> 31`), so the public point and `agree` are checked traced by memcheck alone. - A test of a backend is a `.cpp` of its own per backend, never a define that changes the backend of one source (spec section 4.3's pitfall). -- Every C library is upstream code, unchanged except where CODING-GUIDELINES.md chapter 5 rule 1 - allows a security fix on the mirror's `webcpp` branch (BearSSL: 32381d6, ECDSA's nonce - decoding); a moved pin carries that commit. A moved pin is a change of its own (rule 12). +- Every C library is upstream code (CODING-GUIDELINES.md chapter 5 rule 1): never modify + third-party code; a defect found in a dependency is reported to the owner, who submits the fix + upstream, and until upstream applies it the pin may point at our fork's branch carrying exactly + that patch. BearSSL is ae63032 of webcpporg/bearssl's branch + upstream/ecdsa-bits2int-constant-time: upstream 7bea48e and the ECDSA nonce fix submitted + upstream (bits2int, a Minerva-class leak); the pin returns to upstream once the patch is + applied. A moved pin is a change of its own (rule 12). - X25519's constant time on wasip2 is an open finding (the page's constant-time table): do not describe it as a pass. diff --git a/README.md b/README.md index 9bc1a652..f9414ae3 100644 --- a/README.md +++ b/README.md @@ -16,13 +16,18 @@ MSVC), wasip2, wasip3 and Emscripten. `aead::seal` and `aead::open` of every AEAD. - `webcpp::crypto::curves::secp256k1`: BIP 340 Schnorr and ECDSA signatures, their verification, ECDH, ECDSA's strict DER and low-S forms, and the x-only tweak. -- `webcpp::crypto::curves::ed25519`: Ed25519 signatures (RFC 8032) with strict verification, the +- `webcpp::crypto::curves::ed25519`: Ed25519 signatures (RFC 8032) with canonical verification, the conversion of a key pair and of a public key to X25519's typed keys, `to_x25519()`, and Ed25519ph over SHA-512 for a message given in pieces. - `webcpp::crypto::curves::x25519`: X25519 key agreement (RFC 7748), refusing an all-zero shared secret, with a peer known by its Ed25519 key once its `to_x25519()` converts it. -- Ed25519's and X25519's keys in RFC 8410's SPKI and PKCS#8, as OpenSSL and WebCrypto write them, - and `webcpp::crypto::pem` for their PEM text, each decoded strictly. +- `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. - `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. diff --git a/bench/operations.hpp b/bench/operations.hpp index 16e62201..be4f3afa 100644 --- a/bench/operations.hpp +++ b/bench/operations.hpp @@ -187,12 +187,16 @@ class secp256k1 { filled<32>(static_cast(seed | 1U))), "from_secret")) {} - std::uint8_t run() { return take(key_.sign(schnorr, message_, aux_), "sign").bytes()[0]; } + std::uint8_t run() { + return take(key_.sign(signing_schemes::schnorr, message_, aux_), "sign").bytes()[0]; + } bool check() { - auto const signature = take(key_.sign(schnorr, message_, aux_), "sign"); + auto const signature = take(key_.sign(signing_schemes::schnorr, message_, aux_), "sign"); auto const public_key = take(key_.public_key(), "public_key"); - return crypto::verify(schnorr, signature, message_, public_key).has_value(); + return crypto::verify(signing_schemes::schnorr, verification_policies::canonical, signature, + message_, public_key) + .has_value(); } private: @@ -249,19 +253,25 @@ class secp256k1_recover { key_(take(curves::secp256k1::basic_keypair::from_secret( filled<32>(static_cast(seed | 1U))), "from_secret")), - signature_(take(key_.sign(ecdsa_sha256_recoverable, prehashed{hash_}), "sign")) {} + signature_(take(key_.sign(signing_schemes::ecdsa_sha256_recoverable, + signing_schemes::prehashed{hash_}), + "sign")) {} std::uint8_t run() { - auto const recovered = take(curves::secp256k1::recover( - ecdsa_sha256_recoverable, signature_, prehashed{hash_}), - "recover"); + auto const recovered = + take(curves::secp256k1::recover(signing_schemes::ecdsa_sha256_recoverable, + verification_policies::low_s_only, signature_, + signing_schemes::prehashed{hash_}), + "recover"); return recovered.compressed()[1]; } bool check() { - auto const recovered = take(curves::secp256k1::recover( - ecdsa_sha256_recoverable, signature_, prehashed{hash_}), - "recover"); + auto const recovered = + take(curves::secp256k1::recover(signing_schemes::ecdsa_sha256_recoverable, + verification_policies::low_s_only, signature_, + signing_schemes::prehashed{hash_}), + "recover"); return recovered == take(key_.public_key(), "public_key"); } @@ -339,7 +349,8 @@ class secp256k1_musig { std::uint8_t run() { return sign().bytes()[0]; } bool check() { - return crypto::verify(schnorr, sign(), message_, signers_key_.xonly_public_key()) + return crypto::verify(signing_schemes::schnorr, verification_policies::canonical, sign(), + message_, signers_key_.xonly_public_key()) .has_value(); } @@ -466,15 +477,19 @@ class p256 { "from_secret")) {} std::uint8_t run() { - return take(key_.sign(ecdsa_sha256, prehashed{digest_}), "sign").bytes()[0]; + return take(key_.sign(signing_schemes::ecdsa_sha256, signing_schemes::prehashed{digest_}), + "sign") + .bytes()[0]; } bool check() { - auto const signature = take(key_.sign(ecdsa_sha256, prehashed{digest_}), "sign"); + auto const signature = take( + key_.sign(signing_schemes::ecdsa_sha256, signing_schemes::prehashed{digest_}), "sign"); auto const public_key = take(key_.public_key(), "public_key"); - return crypto::verify(ecdsa_sha256, signature, prehashed{digest_}, public_key) + return crypto::verify(signing_schemes::ecdsa_sha256, verification_policies::low_s_only, + signature, signing_schemes::prehashed{digest_}, public_key) .has_value() && - curves::p256::is_low_s(signature); + signature.is_low_s(); } private: @@ -483,8 +498,8 @@ class p256 { }; // The verification of an ECDSA signature of a 32-byte SHA-256 digest on P-256, `crypto::verify( -// ecdsa_sha256, signature, prehashed{digest}, public_key)`; the signature and the public key are -// made once, outside what is measured. +// ecdsa_sha256, low_s_only, signature, prehashed{digest}, public_key)`, the policy of a signature +// crypto made; the signature and the public key are made once, outside what is measured. template class p256_verify_ecdsa { public: @@ -496,10 +511,14 @@ class p256_verify_ecdsa { filled<32>(static_cast(seed | 1U))), "from_secret")), public_key_(take(key_.public_key(), "public_key")), - signature_(take(key_.sign(ecdsa_sha256, prehashed{digest_}), "sign")) {} + signature_( + take(key_.sign(signing_schemes::ecdsa_sha256, signing_schemes::prehashed{digest_}), + "sign")) {} std::uint8_t run() { - take(crypto::verify(ecdsa_sha256, signature_, prehashed{digest_}, public_key_), "verify"); + take(crypto::verify(signing_schemes::ecdsa_sha256, verification_policies::low_s_only, + signature_, signing_schemes::prehashed{digest_}, public_key_), + "verify"); return signature_.bytes()[0]; } @@ -508,9 +527,12 @@ class p256_verify_ecdsa { other_bytes[63] ^= 1U; auto const other = take(curves::p256::ecdsa_signature::from_bytes(other_bytes), "from_bytes"); - return crypto::verify(ecdsa_sha256, signature_, prehashed{digest_}, public_key_) + return crypto::verify(signing_schemes::ecdsa_sha256, verification_policies::low_s_only, + signature_, signing_schemes::prehashed{digest_}, public_key_) .has_value() && - !crypto::verify(ecdsa_sha256, other, prehashed{digest_}, public_key_).has_value(); + !crypto::verify(signing_schemes::ecdsa_sha256, verification_policies::low_s_only, + other, signing_schemes::prehashed{digest_}, public_key_) + .has_value(); } private: @@ -565,13 +587,15 @@ class ed25519 { key_(take(curves::ed25519::basic_keypair::from_secret(filled<32>(seed)), "from_secret")) {} - std::uint8_t run() { return take(key_.sign(eddsa, message_), "sign").bytes()[0]; } + std::uint8_t run() { + return take(key_.sign(signing_schemes::eddsa, message_), "sign").bytes()[0]; + } bool check() { - auto const signature = take(key_.sign(eddsa, message_), "sign"); + auto const signature = take(key_.sign(signing_schemes::eddsa, message_), "sign"); auto const public_key = take(key_.public_key(), "public_key"); - return crypto::verify(eddsa, signature, message_, public_key, - curves::ed25519::strict) + return crypto::verify(signing_schemes::eddsa, verification_policies::canonical, + signature, message_, public_key) .has_value(); } diff --git a/build.jam b/build.jam index cc0f05d1..f8181c0a 100644 --- a/build.jam +++ b/build.jam @@ -19,14 +19,17 @@ project /webcpp/crypto ; # Header-only, on webcpp's configuration, with webcpp::hash's header-only # alias, whose algorithms name a signature's prehash (Ed25519ph's SHA-512; -# design D1), and webcpp::secure's, whose timing guard, erase_secret, +# design D1), webcpp::secure's, whose timing guard, erase_secret, # constant_time_equal, secret and declassify crypto's code holds and -# returns. random_device reads Windows' generator through bcrypt -# (BCryptGenRandom), a system library. +# returns, and webcpp::codecs', header-only on config and secure, into which +# the key formats register (formats.hpp and each curve's formats.hpp, the +# only headers that include codecs'; design R32). +# random_device reads Windows' generator through bcrypt (BCryptGenRandom), a +# system library. # tag::crypto[] alias crypto : : : : include /boost//headers /webcpp/config//config /webcpp/hash//hash - /webcpp/secure//secure + /webcpp/secure//secure /webcpp/codecs//codecs windows:bcrypt ; # end::crypto[] @@ -125,17 +128,6 @@ rule kx-default-linked ( properties * ) } } alias kx-default : : : : @kx-default-linked ; -rule pem-default-linked ( properties * ) -{ - switch [ webcpp-target.target-of $(properties) ] - { - case native : return /third_party//sodium ; - case wasip2 : return /third_party//sodium ; - case wasip3 : return /third_party//sodium ; - case emscripten : return /third_party//sodium ; - } -} -alias pem-default : : : : @pem-default-linked ; rule chacha20_poly1305-default-linked ( properties * ) { switch [ webcpp-target.target-of $(properties) ] diff --git a/doc/async.adoc b/doc/async.adoc index 0cbbc843..d0dcd425 100644 --- a/doc/async.adoc +++ b/doc/async.adoc @@ -52,7 +52,7 @@ its own, and the handler would run off the program's loop. | `void(error_code, Secretbox)` for `async_from_key`, `void(error_code, tag)` for `async_seal`, `void(error_code)` for `async_open` | Ed25519 (<>) -| `async_from_secret(executor, seed, token)`, `async_generate(executor, token)`, `async_sign(executor, key_pair, crypto::eddsa, message, token)`, `async_verify(executor, crypto::eddsa, signature, message, public_key, token)`, the policy optional before the token; on a native backend the same under `crypto::eddsa_prehashed` with `+crypto::prehashed{digest}+`, the message's SHA-512 (<>), which the browser's backend refuses at compile time +| `async_from_secret(executor, seed, token)`, `async_generate(executor, token)`, `async_sign(executor, key_pair, crypto::signing_schemes::eddsa, message, token)`, `async_verify(executor, crypto::signing_schemes::eddsa, crypto::verification_policies::canonical, signature, message, public_key, token)`; on a native backend the same under `crypto::signing_schemes::eddsa_prehashed` with `+crypto::signing_schemes::prehashed{digest}+`, the message's SHA-512 (<>), which the browser's backend refuses at compile time | `void(error_code, Keypair)` for `async_from_secret` and `async_generate`, `void(error_code, signature)` for `async_sign`, `void(error_code)` for `async_verify` | X25519 (<>) @@ -60,7 +60,7 @@ its own, and the handler would run off the program's loop. | `void(error_code, Keypair)` for `async_from_secret` and `async_generate`, `void(error_code, secure::secret<32>)` for `async_agree` | P-256 (<>) -| `async_from_secret(executor, scalar, token)`, `async_generate(executor, token)`, `async_sign(executor, key_pair, crypto::ecdsa_sha256, input, token)`, `async_verify(executor, crypto::ecdsa_sha256, signature, input, public_key, token)`, `async_agree(executor, key_pair, peer_public_key, token)` +| `async_from_secret(executor, scalar, token)`, `async_generate(executor, token)`, `async_sign(executor, key_pair, crypto::signing_schemes::ecdsa_sha256, input, token)`, `async_verify(executor, crypto::signing_schemes::ecdsa_sha256, crypto::verification_policies::low_s_only, signature, input, public_key, token)`, `async_agree(executor, key_pair, peer_public_key, token)` | `void(error_code, Keypair)` for `async_from_secret` and `async_generate`, `void(error_code, signature)` for `async_sign`, `void(error_code)` for `async_verify`, `void(error_code, secure::secret<32>)` for `async_agree` |=== @@ -68,7 +68,7 @@ Each function has its member form, which the free function calls, with the same arguments but the object: `Keypair::async_from_secret(executor, bytes, token)`, `Keypair::async_generate(executor, token)`, `key_pair.async_sign(executor, scheme, input, token)`, -`public_key.async_verify(executor, scheme, signature, input, token)`, +`public_key.async_verify(executor, scheme, policy, signature, input, token)`, `key_pair.async_agree(executor, peer, token)` on X25519 and P-256, and every AEAD's and secret box's `C::async_from_key`, `aead.async_seal` and `aead.async_open`, and a crypto_box's `box.async_seal` and `box.async_open`. @@ -82,18 +82,21 @@ the call does not compile, the compiler saying that the member's deduced return type is used before it is defined (<>). `async_sign` and `async_verify` take the scheme and the input of the -synchronous `sign` and `crypto::verify`, and check them as `crypto::can_sign` -and `crypto::can_verify` do before anything else, so that a pair the +synchronous `sign` and `crypto::verify`, `async_verify` the policy after the +scheme too, and check them as `crypto::can_sign` and `crypto::can_verify` do +before anything else, so that a pair the synchronous call refuses stops the build here too (<>). P-256's input is the message, which they hash with SHA-256, as WebCrypto's `+sign({name: "ECDSA", hash: "SHA-256"}, ...)+` hashes and signs in one call (link:https://www.w3.org/TR/WebCryptoAPI/#ecdsa-operations[W3C, ECDSA's -operations]), or `+crypto::prehashed{digest}+`, signed as given. WebCrypto has no +operations]), or `+crypto::signing_schemes::prehashed{digest}+`, signed as given. WebCrypto has no prehash mode, so a backend that completes by itself, as the browser's will (<>), refuses the marker at compile time. The signature -is r then s, 64 bytes, WebCrypto's form, low S as `sign` gives it; one of -another size completes `async_verify` with `invalid_signature`. Their keys are +is r then s, 64 bytes, WebCrypto's form, low S as `sign` gives it, verified +under `crypto::verification_policies::low_s_only` or `any_s` as the synchronous +call is (<>); one of another size completes `async_verify` +with `invalid_signature`. Their keys are P-256's own types, the key pair and the validated `public_key`, and `async_agree` gives the shared point's raw x, as WebCrypto's `deriveBits` does (<>). diff --git a/doc/backends.adoc b/doc/backends.adoc index 83d7f5f4..576f4277 100644 --- a/doc/backends.adoc +++ b/doc/backends.adoc @@ -62,10 +62,14 @@ is BearSSL's `br_ecdsa_i31_sign_raw` and `br_ecdsa_i31_vrfy_raw` on every target, over the curve code chosen. [#crypto-backends-bearssl-fix] -webcpp's BearSSL is upstream's commit `7bea48e` with one fix of webcpp's, on -the branch `webcpp` of its mirror -(link:https://github.com/webcpporg/bearssl/commit/32381d6e787a32cbb7a687246349200d78b8ff7c[webcpporg/bearssl -32381d6]). Upstream's ECDSA signing reads RFC 6979's nonce through +webcpp's BearSSL is `ae63032` of its fork's branch +`upstream/ecdsa-bits2int-constant-time` +(link:https://github.com/webcpporg/bearssl/commit/ae63032d9f30bf53674db5445875adf71b8626b7[webcpporg/bearssl +ae63032]): upstream's commit `7bea48e` and exactly one patch, the fix below, +which the owner submits upstream. webcpp never modifies third-party code: a +defect found in a dependency is reported to the owner, who submits the fix +upstream, and the pin returns to upstream once upstream applies it +(CODING-GUIDELINES.md chapter 5, rule 1). Upstream's ECDSA signing reads RFC 6979's nonce through `br_ecdsa_i31_bits2int` (link:https://www.bearssl.org/gitweb/?p=BearSSL;a=blob;f=src/ec/ecdsa_i31_bits.c;hb=7bea48e5e850ab4cafbe68d3765cdaba13a86d6f#l44[ecdsa_i31_bits.c, lines 44 and 45]): `br_i31_decode` writes the nonce's actual bit length into @@ -74,14 +78,17 @@ store over the words that length needs, 8 rather than 9 for a P-256 nonce below 2^248^, one signature in about 256. A signature's time then tells whether its nonce is short, the leak a lattice turns into the key from enough timed signatures -(link:https://minerva.crocs.fi.muni.cz/[Minerva, CVE-2019-15809]). -The fix sets the header back to the order's length before the shift, which -then runs over every word: the words above the nonce are zero, so the nonce is -unchanged. The constant-time lane below found the leak on 2026-11-21 under -memcheck and MemorySanitizer; dudect, which would see one measurement in about -256 differ by a few instructions, did not. The 15-bit copy, which webcpp does -not call, has the same fix. Each move of BearSSL's pin carries the commit -until upstream has it. +(link:https://minerva.crocs.fi.muni.cz/[Minerva, CVE-2019-15809]). The 15-bit +copy, `br_ecdsa_i15_bits2int`, which webcpp does not call, has the same leak. +The patch sets the header, before the shift, to the larger of the decoded bit +length and the order's, both public, so the shift runs over the same words for +every nonce: the words above the nonce are zero, and the nonce is unchanged, +P-521's 66-byte nonce included, whose decoded length exceeds the order's. It +changes `br_ecdsa_i31_bits2int` and `br_ecdsa_i15_bits2int` alone. The +constant-time lane found the leak on 2026-11-21 under memcheck and +MemorySanitizer; dudect, which would see one measurement in about 256 differ +by a few instructions, did not. At the pin both checkers find nothing in +P-256's `sign` (<>). A program has one copy of each library: libsecp256k1's tables and OpenSSL's state are global symbols, so webcpp's build is never linked with another copy. @@ -137,9 +144,10 @@ ElligatorSwift's `ellswift_create` and `ellswift_xdh`, MuSig2's `generate_nonce` and `partial_sign`, and silent payments' `create_outputs`, `create_label` and `scan_outputs`, with the wipe of their workspaces; and BearSSL's P-256: the key -pair's making, `sign` of a digest (`crypto::prehashed`), which makes its -signature low S without a branch, then `normalize_low_s` and `is_low_s` on the -fresh signature, `agree` and `decode_pkcs8`. Both checkers run the same paths, +pair's making, `sign` of a digest (`crypto::signing_schemes::prehashed`), which makes its +signature low S without a branch, then `low_s()` and `is_low_s()` of the +fresh signature, `agree`, and its private formats, `pkcs8`, `raw` and +`pem(pkcs8)` both ways. Both checkers run the same paths, written once (`paths.hpp`), memcheck OpenSSL's besides. Each check is shown to fail on a planted branch on a key byte, and on a copy of P-256's range check of a scalar that returns at the first byte that differs, and each path's output is @@ -176,10 +184,12 @@ measured again in the final quiet pass. memcheck and MemorySanitizer last ran the lane on 2026-11-22 with the command the CI runs it with, in an arm64 Linux container (Ubuntu 24.04, the image `linux-lint:arm64` of webcpp's Linux lint, Valgrind 3.22, clang 18), on an -Apple M5 Max. Every path above passed under both, P-256's with webcpp's fix to -BearSSL (<>) and its signing with its low-S step: -neither found anything there. The run before the fix, without it, both -reported the nonce's leak. Each planted program failed where it must, and the +Apple M5 Max, while webcpp's BearSSL carried a fix of its own on its mirror's +`webcpp` branch, replaced on 2026-12-02 by the same fix submitted upstream +(<>). Every path above passed under both, P-256's +signing with its low-S step included, and again on 2026-12-02 at the pin +`ae63032`. The run of 2026-11-21 on upstream's BearSSL, without the fix, +reported the nonce's leak under both. Each planted program failed where it must, and the lane's dudect programs passed there too, with `dudect_planted` at 34.89 on the 2026-11-21 run. @@ -217,7 +227,7 @@ check of a scalar and its low-S test, and each verdict of libsecp256k1's that webcpp reads), so that the checkers report every other branch. A signature is public once it is made, but one fresh from `sign` is computed from the scalar: the low-S step of `sign` selects n - s by a mask, without a branch and without -marking anything public, and `normalize_low_s` and `is_low_s` mark their verdict +marking anything public, and `low_s()` and `is_low_s()` of a signature mark their verdict public, so that a program that checks its own signatures under a checker sees no report. libsecp256k1 marks its own public values (a nonce's retry, a verdict, a public key it loads) when its context is made with diff --git a/doc/changelog.adoc b/doc/changelog.adoc index 6e007898..fbdc41b2 100644 --- a/doc/changelog.adoc +++ b/doc/changelog.adoc @@ -16,14 +16,14 @@ of every version are on webcpp's index page. === Unreleased // tag::unreleased[] -* Added crypto, C-backed primitives on webcpp::secure's guard, DIT on arm64 Apple, Linux and Windows: ciphers, curves, randomness, errors 1 to 20, `+[[nodiscard]]+` results, WEBCPP_CRYPTO_HAS_THREADS, asynchronous functions on Asio. -* Added random_device, pem on libsodium, the AES block cipher ciphers::aes128, aes192 and aes256 with a per-target default, and ciphers::gcm, aes128_gcm and aes256_gcm: incremental seal, two-pass open, failures zeroing data. -* Added supports_v with its family tags, the capability table per target, default_backend_t and /webcpp/crypto//-default per family and target (secp256k1's modules among them), and refusals naming their Jamfile line. -* Added backends::bearssl (AES-GCM, ChaCha20-Poly1305, curves::p256: keys, low-S ECDSA, agree, SPKI/PKCS#8; allocating nothing), backends::openssl natively and on WASI (allocating at from_key only, or in openssl_memory_resource with WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE), and backends::ctaes. -* Added curves::secp256k1: key pairs signing with crypto::ecdsa_sha256 (hedged too), ecdsa_sha256_recoverable, ecdsa_keccak256_recoverable (Ethereum's recoverable ECDSA) and schnorr, agree's three forms, strict DER, low-S, tweaks, SPKI, PKCS#8, PEM, ElligatorSwift, MuSig2, silent payments. -* Added curves::ed25519 and curves::x25519 on libsodium: strict verification (twelve edge cases), Ed25519ph as crypto::eddsa_prehashed and the streaming prehashed_signer over hash's sha2_512, the conversion, all-zero agreements refused, RFC 8410's SPKI, PKCS#8. -* Added backends::sodium on /third_party//sodium, shared with webcpp::hash, every backend's link-time canary and C suite, and ciphers::basic_chacha20_poly1305: chacha20_poly1305 (also BearSSL, OpenSSL), the original form, xchacha20_poly1305, failed seals and opens zeroing data. -* Added secret_key_encryption's secretbox and secretbox_xchacha20poly1305 without associated data, public_key_encryption's box, box_xchacha20poly1305 and sealed_box, key_exchange::kx_keypair on libsodium, on typed X25519 keys. -* Added the page: chapters per namespace and use case, the memory option's guide, generated tables, Jamfiles, messages, llms.txt, release-built sizes and throughput, X25519 timing findings (wasip2, DIT). -* Added signing.hpp, keypair.hpp, factories.hpp, secret_key_encryption/aead.hpp: typed signatures, sign(scheme, input), verify; keypair, signing_keypair, agreement_keypair; aead::cipher, authenticated_box; from_secret, from_bytes, from_key; secret, constant_time_equal, erase_secret are webcpp::secure's, no alias. +* *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:* 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. +* 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//-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. // end::unreleased[] diff --git a/doc/choosing_backend.adoc b/doc/choosing_backend.adoc index 78cfc4da..423a95e7 100644 --- a/doc/choosing_backend.adoc +++ b/doc/choosing_backend.adoc @@ -40,8 +40,9 @@ WebAssembly, constant time by design. libsecp256k1 is the only backend of secp256k1. The three ChaCha20-Poly1305 AEADs' default is libsodium on every target; RFC 8439's form also runs on BearSSL, on every target, and on OpenSSL, natively and on WASI, each named in the type. Every other family of this -version, Ed25519, X25519, `kx`, the secret boxes, the boxes, the sealed box and -PEM, has libsodium alone, on every target. In {cpp}, +version, Ed25519, X25519, `kx`, the secret boxes, the boxes and the sealed box, +has libsodium alone, on every target; PEM is codecs' armor, which needs no +backend. In {cpp}, `default_backend_t` names a family's default on the target being compiled, and `default_backend` AES-GCM's. diff --git a/doc/curves.adoc b/doc/curves.adoc index 6f071dd6..3befbb50 100644 --- a/doc/curves.adoc +++ b/doc/curves.adoc @@ -28,21 +28,26 @@ the recovery of a signer's public key from a signature, and the uncompressed key by header: * `secp256k1.hpp`, the key pair and its signatures and ECDH: -`keypair::from_secret`, `generate`, and the key pair's `public_key`, `secret`, -`sign` with `crypto::schnorr`, `crypto::ecdsa_sha256`, -`crypto::ecdsa_sha256_recoverable` and `crypto::ecdsa_keccak256_recoverable`, +`keypair::from_secret`, `generate`, and the key pair's `public_key`, +`xonly_public_key`, `xonly_parity`, `secret`, +`sign` with `crypto::signing_schemes::schnorr`, `crypto::signing_schemes::ecdsa_sha256`, +`crypto::signing_schemes::ecdsa_sha256_recoverable` and `crypto::signing_schemes::ecdsa_keccak256_recoverable`, `agree`, `agree_hashed`, `agree_point` and `tweak_xonly`; the `public_key` -type's `from_bytes`, `compressed`, `uncompressed` and `xonly`; `crypto::verify` -with `crypto::schnorr` and `crypto::ecdsa_sha256`, `recover`, `to_der`, -`from_der`, `normalize_low_s`, `is_low_s` and the x-only key's `tweak_xonly`; +type's `from_bytes`, `compressed`, `uncompressed` and `xonly`; the typed x-only +key's (`xonly_public_key`) `from_bytes`, `bytes`, `verify`, `tweak_add` and +`verify_tweak`; `crypto::verify` +with `crypto::signing_schemes::schnorr` and `crypto::signing_schemes::ecdsa_sha256`, `recover` and +the low-S members of its ECDSA signatures; * `secp256k1/tweak.hpp`, tweaks of whole keys, the arithmetic of BIP 32's derivation and of watch-only wallets: `secret_key_tweak_add`, `secret_key_tweak_mul`, `secret_key_negate`, `public_key_tweak_add`, `public_key_tweak_mul`, `public_key_negate` and `public_key_combine` (<>); -* `secp256k1/formats.hpp`, keys in the SPKI and PKCS#8 files that OpenSSL -exchanges: `encode_spki`, `decode_spki`, `encode_pkcs8` and `decode_pkcs8` -(<>); +* `secp256k1/formats.hpp`, the formats of its keys and signatures for +`crypto::encode` and `crypto::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 (<>); * `secp256k1/ellswift.hpp`, keys sent as random-looking bytes, BIP 324's ElligatorSwift: `ellswift_create`, `ellswift_encode`, `ellswift_decode` and `ellswift_xdh` (<>); @@ -91,14 +96,15 @@ include::generated/namespace-curves.adoc[] `` gives every curve one way to sign and one way to verify. A key pair signs with `key.sign(scheme, input)`, and -`crypto::verify(scheme, signature, input, public_key)`, in the namespace -`webcpp::crypto`, checks a signature with the public key alone. The scheme is a +`crypto::verify(scheme, policy, signature, input, public_key)`, in the namespace +`webcpp::crypto`, checks a signature with the public key alone, under a +verification policy the scheme accepts (<>). The scheme is a tag object that names the algorithm and, for ECDSA, its hash, as WebCrypto's `+{name: "ECDSA", hash: "SHA-256"}+` does (link:https://www.w3.org/TR/WebCryptoAPI/#ecdsa-operations[W3C, ECDSA's -operations]): `crypto::eddsa`, `crypto::eddsa_prehashed`, -`crypto::ecdsa_sha256`, `crypto::ecdsa_sha256_recoverable`, -`crypto::ecdsa_keccak256_recoverable` and `crypto::schnorr`. It is named at +operations]): `crypto::signing_schemes::eddsa`, `crypto::signing_schemes::eddsa_prehashed`, +`crypto::signing_schemes::ecdsa_sha256`, `crypto::signing_schemes::ecdsa_sha256_recoverable`, +`crypto::signing_schemes::ecdsa_keccak256_recoverable` and `crypto::signing_schemes::schnorr`. It is named at every call, on every curve, so that the call says what it signs; a tag's constructor is explicit, so that `+{}+` never stands for a scheme. @@ -107,12 +113,12 @@ The input is a message or a digest, and the program says which: * A *message* is any bytes that convert to `std::span`: a span, a `std::array`, a `std::vector`, of any size, the empty one included. ECDSA hashes it with SHA-256 inside the call, as WebCrypto does, and Ethereum's -`crypto::ecdsa_keccak256_recoverable` with Keccak-256; EdDSA and Schnorr sign it -as given; Ed25519ph, `crypto::eddsa_prehashed`, takes none. -* A *digest* is `+crypto::prehashed{digest}+`, made from a +`crypto::signing_schemes::ecdsa_keccak256_recoverable` with Keccak-256; EdDSA and Schnorr sign it +as given; Ed25519ph, `crypto::signing_schemes::eddsa_prehashed`, takes none. +* A *digest* is `+crypto::signing_schemes::prehashed{digest}+`, made from a `std::array`, a span of the fixed size N, or a Boost.Hash2 digest such as the result of `webcpp::hash::sha2_256`. ECDSA signs it as -given, and so does Ed25519ph, `crypto::eddsa_prehashed`, a message's SHA-512. +given, and so does Ed25519ph, `crypto::signing_schemes::eddsa_prehashed`, a message's SHA-512. The marker refers to its digest, as a span does, and must not outlive it. The hazard this removes is the 32-byte message. A SHA-256 digest is 32 bytes, @@ -121,109 +127,155 @@ takes a digest as a span of bytes, a 32-byte message passed to it compiles, signs the message unhashed, and verifies under the same mistake, and a program that moves from one function or one curve to another changes the meaning of its argument without a diagnostic. Here a span is a message whatever its size, -and no conversion turns a span into a `crypto::prehashed` or a -`crypto::prehashed` into a span: a digest is a digest because the program says +and no conversion turns a span into a `crypto::signing_schemes::prehashed` or a +`crypto::signing_schemes::prehashed` into a span: a digest is a digest because the program says so. .The schemes, their keys and their inputs [cols="2,3,2,2,2",options="header"] |=== | Scheme | Key pair; the public key `crypto::verify` takes | A message -| `+crypto::prehashed{digest}+` | Signature +| `+crypto::signing_schemes::prehashed{digest}+` | Signature -| `crypto::eddsa` +| `crypto::signing_schemes::eddsa` | Ed25519: `curves::ed25519::keypair`; `curves::ed25519::public_key` | signed as given (RFC 8032's PureEdDSA) | does not compile | `curves::ed25519::signature`, 64 bytes -| `crypto::eddsa_prehashed` +| `crypto::signing_schemes::eddsa_prehashed` | Ed25519: `curves::ed25519::keypair`; `curves::ed25519::public_key` (native backends) | does not compile | 64 bytes, the message's SHA-512 (RFC 8032's Ed25519ph) | `curves::ed25519::signature`, 64 bytes, not interchangeable with a signature -of `crypto::eddsa` +of `crypto::signing_schemes::eddsa` -| `crypto::ecdsa_sha256` +| `crypto::signing_schemes::ecdsa_sha256` | P-256: `curves::p256::keypair`; `curves::p256::public_key` | hashed with SHA-256 inside the call | 32 bytes, signed as given | `curves::p256::ecdsa_signature`, 64 bytes, r then s, low S -| `crypto::ecdsa_sha256` +| `crypto::signing_schemes::ecdsa_sha256` | secp256k1: `curves::secp256k1::keypair`; `curves::secp256k1::public_key` | hashed with SHA-256 inside the call | 32 bytes, signed as given | `curves::secp256k1::ecdsa_signature`, 64 bytes, r then s, low S -| `crypto::ecdsa_sha256_recoverable` +| `crypto::signing_schemes::ecdsa_sha256_recoverable` | secp256k1: `curves::secp256k1::keypair`; none: `recover` gives the key | hashed with SHA-256 inside the call | 32 bytes, signed as given | `curves::secp256k1::recoverable_signature`, 65 bytes, r, s and the recovery id -| `crypto::ecdsa_keccak256_recoverable` +| `crypto::signing_schemes::ecdsa_keccak256_recoverable` | secp256k1: `curves::secp256k1::keypair`; none: `recover` gives the key | hashed with Keccak-256 inside the call (`/third_party//xkcp` linked) | 32 bytes, signed as given | `curves::secp256k1::recoverable_signature`, 65 bytes, r, s and the recovery id -| `crypto::schnorr` +| `crypto::signing_schemes::schnorr` | secp256k1: `curves::secp256k1::keypair`; `curves::secp256k1::public_key`, or -its 32-byte x-only form +its x-only key, `curves::secp256k1::xonly_public_key` | signed as given (BIP 340) | does not compile | `curves::secp256k1::schnorr_signature`, 64 bytes |=== Every other pair stops the build in a `static_assert` whose message says why: a -scheme the key's curve does not have, `crypto::eddsa` or `crypto::schnorr` with -a marker, `crypto::eddsa_prehashed` with a message, a marker whose digest is not +scheme the key's curve does not have, `crypto::signing_schemes::eddsa` or `crypto::signing_schemes::schnorr` with +a marker, `crypto::signing_schemes::eddsa_prehashed` with a message, a marker whose digest is not the scheme's size (32 bytes, or Ed25519ph's 64), a marker made from a span whose size the type does not know, a marker on a backend that cannot sign a digest; <> gives each with its fix. The concepts `crypto::can_sign` and -`crypto::can_verify` give a program's own +`crypto::can_verify` give a program's own templates the same answer. A public key's type says its curve: ECDSA's key is a -validated object on both curves, never bytes, so that `crypto::ecdsa_sha256` -never infers its curve from a number of bytes. BIP 340's keys are bytes on the -wire, so `crypto::schnorr` also takes the 32-byte x-only key. +validated object on both curves, never bytes, so that `crypto::signing_schemes::ecdsa_sha256` +never infers its curve from a number of bytes. BIP 340's keys, 32 bytes on the +wire, are typed too: `crypto::signing_schemes::schnorr` also takes the x-only +key, `curves::secp256k1::xonly_public_key`, made by its `from_bytes`, which lifts +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(crypto::formats::raw, bytes)`, +and a `public_key` writes its x-only key with +`crypto::encode(crypto::formats::raw(crypto::formats::xonly), key)` +(<>). 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 +bytes (<>, <>). The signature is a type of its curve and scheme, the table's last column, and nothing else is taken where one is expected (<>). +[#crypto-curves-policies] +*Verification policies.* Every verification takes a policy second, after the +scheme, from `crypto::verification_policies`, and each scheme accepts its own; +another one, or none, stops the build with a message that names the ones it +accepts (design D9): + +.The policies each scheme accepts +[cols="2,2,2,4",options="header"] +|=== +| Scheme | Key | Policies | What the policy does + +| `ecdsa_sha256` +| `curves::secp256k1::public_key` +| `low_s_only` +| a high S is `invalid_signature`, as libsecp256k1 and Bitcoin's policy refuse it +(link:https://github.com/bitcoin/bips/blob/master/bip-0146.mediawiki[BIP 146]) + +| `ecdsa_sha256_recoverable`, `ecdsa_keccak256_recoverable` (`recover`) +| none: recovered +| `low_s_only` +| a high S is `invalid_signature` before recovery, as EIP-2 refuses one in a +transaction + +| `ecdsa_sha256` +| `curves::p256::basic_public_key` +| `low_s_only`, `any_s` +| `low_s_only`: a high S is `invalid_signature` before any backend call, for a +signature crypto made; `any_s`: either form, as FIPS 186-5 and WebCrypto accept, +for a signature a browser or a passkey made + +| `eddsa`, `eddsa_prehashed` +| `curves::ed25519::public_key` +| `canonical` +| libsodium's rules: S below L, canonical R and A, A not of small order + +| `schnorr` +| `curves::secp256k1::public_key`, `curves::secp256k1::xonly_public_key` +| `canonical` +| BIP 340's verification, which accepts only r below p and s below n +|=== + ECDSA signs low S on both curves, s at most (n - 1) / 2: libsecp256k1 signs so, and P-256's RFC 6979 signature is normalized after it is made, n - s -selected by a mask, without a branch on the secret. Verification differs on -purpose. secp256k1's `crypto::verify` refuses a high S, as libsecp256k1 and -Bitcoin's policy do -(link:https://github.com/bitcoin/bips/blob/master/bip-0146.mediawiki[BIP -146]); P-256's accepts both forms, as FIPS 186-5 and WebCrypto do, whose own -signatures may be high. A protocol that requires low S from a P-256 peer -checks `is_low_s` before `crypto::verify` (<>). +selected by a mask, without a branch on the secret. So `low_s_only` verifies +what crypto signs on either curve; P-256 also takes `any_s` because WebCrypto's +own signatures may be high (<>). secp256k1 keeps a third argument where it has a reason of its own: hedged ECDSA, -`sign(crypto::ecdsa_sha256, input, extra_entropy)`, mixes 32 fresh bytes of the -caller's into the nonce, and `sign(crypto::schnorr, message, +`sign(crypto::signing_schemes::ecdsa_sha256, input, extra_entropy)`, mixes 32 fresh bytes of the +caller's into the nonce, and `sign(crypto::signing_schemes::schnorr, message, auxiliary_random_bytes)` takes BIP 340's auxiliary randomness from the caller, -for test vectors; `sign(crypto::schnorr, message)` draws it from +for test vectors; `sign(crypto::signing_schemes::schnorr, message)` draws it from `random_device`, and returns `entropy_unavailable` when it cannot. `recover` takes the scheme and the inputs of signing, -`recover(crypto::ecdsa_sha256_recoverable, signature, input)` or -`recover(crypto::ecdsa_keccak256_recoverable, signature, input)` +`recover(crypto::signing_schemes::ecdsa_sha256_recoverable, crypto::verification_policies::low_s_only, signature, input)` or +`recover(crypto::signing_schemes::ecdsa_keccak256_recoverable, crypto::verification_policies::low_s_only, signature, input)` (<>). Every `crypto::verify` takes its backend as its first template parameter, -`crypto::verify(scheme, signature, input, public_key)`, so that the -call reads the same on every curve: P-256 deduces it from the key, Ed25519 +`crypto::verify(scheme, policy, signature, input, public_key)`, so that +the call reads the same on every curve: P-256 deduces it from the key, Ed25519 takes its family's default, and secp256k1 libsecp256k1, its only backend. -`recover` and `async_verify` take it first too. Ed25519's verification policy -is a trailing argument, `curves::ed25519::strict` by default -(<>). +`recover` and `async_verify` take it first too. In an event loop, `async_sign(executor, key_pair, scheme, input, token)` and -`async_verify(executor, scheme, signature, input, public_key, token)`, and the +`async_verify(executor, scheme, policy, signature, input, public_key, token)`, and the members `key_pair.async_sign` and `public_key.async_verify`, take the same schemes and inputs on the curves WebCrypto has, Ed25519 and P-256, and check them as `crypto::can_sign` and `crypto::can_verify` do @@ -242,31 +294,32 @@ namespace: | `curves::ed25519::signature` | 64 -| `crypto::eddsa` and `crypto::eddsa_prehashed`; Ed25519ph's streaming +| `crypto::signing_schemes::eddsa` and `crypto::signing_schemes::eddsa_prehashed`; Ed25519ph's streaming `prehashed_signer` -| `verify` under the scheme that made it, `crypto::eddsa` or -`crypto::eddsa_prehashed`: the two are not interchangeable +| `verify` under the scheme that made it, `crypto::signing_schemes::eddsa` or +`crypto::signing_schemes::eddsa_prehashed`: the two are not interchangeable; +`formats::raw` | `curves::p256::ecdsa_signature` | 64, r then s -| `crypto::ecdsa_sha256` -| `verify` under `crypto::ecdsa_sha256`; P-256's format functions +| `crypto::signing_schemes::ecdsa_sha256` +| `verify` under `crypto::signing_schemes::ecdsa_sha256`; `formats::raw` and `formats::der` | `curves::secp256k1::ecdsa_signature` | 64, r then s -| `crypto::ecdsa_sha256` -| `verify` under `crypto::ecdsa_sha256`; secp256k1's format functions +| `crypto::signing_schemes::ecdsa_sha256` +| `verify` under `crypto::signing_schemes::ecdsa_sha256`; `formats::raw` and `formats::der` | `curves::secp256k1::recoverable_signature` | 65, r, s and the recovery id -| `crypto::ecdsa_sha256_recoverable` and -`crypto::ecdsa_keccak256_recoverable` -| `recover` under the scheme that made it +| `crypto::signing_schemes::ecdsa_sha256_recoverable` and +`crypto::signing_schemes::ecdsa_keccak256_recoverable` +| `recover` under the scheme that made it; `formats::raw` | `curves::secp256k1::schnorr_signature` | 64 -| `crypto::schnorr` -| `verify` under `crypto::schnorr` +| `crypto::signing_schemes::schnorr` +| `verify` under `crypto::signing_schemes::schnorr`; `formats::raw` |=== `sign` returns its scheme's type, and every `verify`, member and free, @@ -312,15 +365,26 @@ verifies only its own scheme's, a signature of the other being Which of the two a protocol uses is the protocol's choice, and the program passes the same scheme to `sign` and to `verify`. -DER, low S and the 64-byte form are formats of a signature, not schemes, and -they need the curve's order: each ECDSA curve's namespace has the same four -functions, typed by its `ecdsa_signature`. `to_der(signature, output)` writes -strict DER into at least `max_der_size` bytes and returns its length, -allocating nothing; `from_der(der)` reads strict DER back into the curve's -`ecdsa_signature`; `normalize_low_s(signature)` returns the low-S form, and -`invalid_signature` for an r or an s that is 0 or not below n; -`is_low_s(signature)` is true exactly when r is between 1 and n - 1 and s -between 1 and (n - 1) / 2, and does not verify. A P-256 signature given to +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 +bytes, allocating nothing, and +`crypto::decode(crypto::formats::der, der)` reads strict DER +back into the curve's `ecdsa_signature` (each curve's `formats.hpp`, +<>). + +*Low S.* An ECDSA signature (r, s) and (r, n - s) both verify: whoever holds +one makes the other, a second valid signature of the same message, which a +protocol that names a message by its signature sees as another message +(link:https://github.com/bitcoin/bips/blob/master/bip-0146.mediawiki[BIP 146]). +Low S chooses the one with s at most (n - 1) / 2. Low S is a member of each ECDSA signature type (and of +secp256k1's `recoverable_signature`), not a function of the namespace: +`signature.low_s()` returns the low-S form, and `invalid_signature` for an r or +an s that is 0 or not below n (and, for a recoverable signature, a recovery id +above 3), flipping bit 0 of a recoverable signature's recovery id when it +replaces s, which keeps the signer; `signature.is_low_s()` is true exactly when +r is between 1 and n - 1 and s between 1 and (n - 1) / 2, and does not verify. +An Ed25519 or Schnorr signature has neither. A P-256 signature given to secp256k1's functions, or the reverse, stops the build. [#crypto-curves-factories] @@ -442,7 +506,8 @@ the curves of that column. Each public key type is made from bytes by its own `from_bytes`, and gives its byte forms as members named after the encoding: Ed25519's `bytes()` (32 bytes), P-256's `uncompressed()` (65), and secp256k1's `compressed()` (33), -`uncompressed()` (65) and `xonly()` (32). P-256's and secp256k1's +`uncompressed()` (65) and `xonly()`, its typed x-only key, whose `bytes()` +are 32. P-256's and secp256k1's `from_bytes` check the point, as P-256's `from_coordinates(x, y)` does; Ed25519's checks the size alone, whether the point is canonical and not of small order being its verification policy's judgment. @@ -480,14 +545,14 @@ event loop. | Member | `K::from_secret(secret_bytes)`, `T::from_bytes(bytes)`, `C::from_key(key)`, `K::generate()`, `key_pair.sign(scheme, input)`, -`key_pair.agree(peer)`, `public_key.verify(scheme, signature, input)`, +`key_pair.agree(peer)`, `public_key.verify(scheme, policy, signature, input)`, `aead.seal(nonce, associated_data, data)`, `aead.open(nonce, associated_data, data, tag)` | `K::async_from_secret(executor, secret_bytes, token)`, `C::async_from_key(executor, key, token)`, `K::async_generate(executor, token)`, `key_pair.async_sign(executor, scheme, input, token)`, `key_pair.async_agree(executor, peer, token)`, -`public_key.async_verify(executor, scheme, signature, input, token)`, +`public_key.async_verify(executor, scheme, policy, signature, input, token)`, `aead.async_seal(executor, nonce, associated_data, data, token)`, `aead.async_open(executor, nonce, associated_data, data, tag, token)` @@ -495,7 +560,7 @@ event loop. | `crypto::from_secret(secret_bytes)`, `crypto::from_bytes(bytes)`, `crypto::from_key(key)`, `crypto::generate()`, `crypto::sign(key_pair, scheme, input)`, `crypto::agree(key_pair, peer)`, -`crypto::verify(scheme, signature, input, public_key)`, +`crypto::verify(scheme, policy, signature, input, public_key)`, `secret_key_encryption::aead::seal(aead, nonce, associated_data, data)`, `secret_key_encryption::aead::open(aead, nonce, associated_data, data, tag)` | `crypto::async_from_secret(executor, secret_bytes, token)`, @@ -503,7 +568,7 @@ event loop. `crypto::async_generate(executor, token)`, `crypto::async_sign(executor, key_pair, scheme, input, token)`, `crypto::async_agree(executor, key_pair, peer, token)`, -`crypto::async_verify(executor, scheme, signature, input, public_key, token)`, +`crypto::async_verify(executor, scheme, policy, signature, input, public_key, token)`, `secret_key_encryption::aead::async_seal(executor, aead, nonce, associated_data, data, token)`, `secret_key_encryption::aead::async_open(executor, aead, nonce, @@ -520,8 +585,8 @@ Ed25519's, X25519's and P-256's key pairs and public keys (`async_agree` on X25519 and P-256), and AES-GCM; and, on a native backend, every other AEAD and box (<>). A public key has no `async_from_bytes`: the asynchronous family makes key pairs (`async_from_secret`), AEADs and secret boxes -(`async_from_key`) only. Ed25519's verification policy is an optional argument -of all four, before the token in the asynchronous ones; secp256k1's 32 bytes of +(`async_from_key`) only. The verification policy follows the scheme in all +four (<>); secp256k1's 32 bytes of extra entropy or auxiliary randomness follow the input of `sign` and `crypto::sign`. @@ -543,14 +608,15 @@ function without a backend call does, so the free form adds none either: a guard there would only set DIT around a copy (<>), at the guard's own cost (<>). -An unqualified call finds the free forms by argument-dependent lookup, a scheme -tag being of the namespace `webcpp::crypto`: `verify(crypto::eddsa, signature, -message, public_key)` is `crypto::verify`. The catch-alls that stop the build -with a message, those of `crypto::sign`, `crypto::verify` and -`crypto::async_verify`, take only a scheme tag in the place of the scheme, and -the one of `crypto::agree` only a key pair of the contract, so that a function -`sign` or `verify` of the program, of the same arity, called unqualified on the -program's own types, is never captured by one of them. +The free forms are called qualified, `+crypto::verify(...)+`, or after +`using webcpp::crypto::verify;`: argument-dependent lookup does not find them, the +scheme and policy tags being of the nested namespaces `crypto::signing_schemes` +and `crypto::verification_policies`, not of `webcpp::crypto` itself. The +catch-alls that stop the build with a message, those of `crypto::sign`, +`crypto::verify` and `crypto::async_verify`, take only a scheme tag in the place +of the scheme, and the one of `crypto::agree` only a key pair of the contract, +so that a function `sign` or `verify` of the program, of the same arity, called +on the program's own types, is never captured by one of them. The asynchronous members are declared in their classes and defined in ``, so that a curve's or a cipher's header never @@ -602,7 +668,7 @@ SHA-256 of the transaction's serialization (link:https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki[BIP 143]): a protocol's digest. crypto holds primitives only, so the program, or a domain library, computes the sighash with webcpp::hash and signs -`+crypto::prehashed{sighash}+` under `crypto::ecdsa_sha256`. That is honest: the +`+crypto::signing_schemes::prehashed{sighash}+` under `crypto::signing_schemes::ecdsa_sha256`. That is honest: the sighash is the SHA-256 of a SHA-256, the second hash being the scheme's own, and no scheme of its own is needed: @@ -613,7 +679,7 @@ include::{examples}/bitcoin_sighash.cpp[tag=sign,indent=0] The sighash's computation, and the signature written as DER, are in <>. A taproot sighash, BIP 341's tagged hash, is the -message of `crypto::schnorr` instead, signed as given +message of `crypto::signing_schemes::schnorr` instead, signed as given (<>, <>). [#crypto-curves-signatures-ethereum] @@ -621,12 +687,12 @@ message of `crypto::schnorr` instead, signed as given Ethereum signs Keccak-256 digests with recoverable ECDSA (link:https://ethereum.github.io/yellowpaper/paper.pdf[Ethereum's yellow paper, -appendix F]), and its scheme says so: `crypto::ecdsa_keccak256_recoverable` +appendix F]), and its scheme says so: `crypto::signing_schemes::ecdsa_keccak256_recoverable` hashes a message with Keccak-256, the original padding Ethereum uses and never SHA3-256, and signs a digest the program builds, EIP-191's, EIP-712's or a -transaction's, given as `+crypto::prehashed{digest}+`. Its signature is the +transaction's, given as `+crypto::signing_schemes::prehashed{digest}+`. Its signature is the `curves::secp256k1::recoverable_signature` of -`crypto::ecdsa_sha256_recoverable`, and a message recovered under the other +`crypto::signing_schemes::ecdsa_sha256_recoverable`, and a message recovered under the other scheme, hashed with the other hash, gives another key, which the program's comparison refuses. <> shows the digest, `v` and the address, which the program computes. diff --git a/doc/ed25519.adoc b/doc/ed25519.adoc index 8a734e86..ae89bfb8 100644 --- a/doc/ed25519.adoc +++ b/doc/ed25519.adoc @@ -25,12 +25,12 @@ Ethereum and Nostr sign on secp256k1 instead (<>). A `keypair` is made from a seed with `from_secret(seed)`, or drawn from `random_device` with `generate()`; it gives its public key (`public_key()`), its seed back (`secret()`, a `secure::secret<32>`), signs -(`sign(crypto::eddsa, message)`), and converts itself to an X25519 key pair +(`sign(crypto::signing_schemes::eddsa, message)`), and converts itself to an X25519 key pair (`to_x25519()`, <>), so that one seed serves for signatures and for key agreement. The key pair wipes its secret key when it is moved from and -destroyed. `crypto::verify(crypto::eddsa, signature, message, public_key)` -checks a signature with the public key alone. The scheme `crypto::eddsa` signs -the message itself, of any length: a `crypto::prehashed` digest does not +destroyed. `crypto::verify(crypto::signing_schemes::eddsa, crypto::verification_policies::canonical, signature, message, public_key)` +checks a signature with the public key alone. The scheme `crypto::signing_schemes::eddsa` signs +the message itself, of any length: a `crypto::signing_schemes::prehashed` digest does not compile, and the key pair is a `crypto::signing_keypair` and no `crypto::agreement_keypair` (<>). @@ -39,12 +39,24 @@ makes one from them, checking their size alone, and `bytes()` gives them back. Whether the point is canonical and not of small order is the verification policy's to judge, so a key that `crypto::verify` refuses can still be made. +`` gives the three types their +formats (<>), synchronous on every backend: +`crypto::encode(crypto::formats::spki, public_key)` and +`crypto::decode(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. + Each operation has its four forms, the member and its free form, synchronous and asynchronous, with the same work, errors and refusals (<>); `public_key::from_bytes(bytes)` and `crypto::from_bytes(bytes)` make the public key, synchronously only. -Verification takes the policy as an optional last argument, before the token -in the asynchronous forms. An asynchronous form needs +Verification takes the policy second, after the scheme, in every form: +`crypto::verification_policies::canonical`, the only one Ed25519 takes. An asynchronous form needs `` and `/webcpp/asio//asio` in the Jamfile: .Ed25519's operations in their four forms @@ -65,26 +77,26 @@ in the asynchronous forms. An asynchronous form needs `crypto::async_generate(executor, token)` | Sign -| `key_pair.sign(crypto::eddsa, message)` + -`crypto::sign(key_pair, crypto::eddsa, message)` -| `key_pair.async_sign(executor, crypto::eddsa, message, token)` + -`crypto::async_sign(executor, key_pair, crypto::eddsa, message, token)` +| `key_pair.sign(crypto::signing_schemes::eddsa, message)` + +`crypto::sign(key_pair, crypto::signing_schemes::eddsa, message)` +| `key_pair.async_sign(executor, crypto::signing_schemes::eddsa, message, token)` + +`crypto::async_sign(executor, key_pair, crypto::signing_schemes::eddsa, message, token)` | Verify -| `public_key.verify(crypto::eddsa, signature, message)` + -`crypto::verify(crypto::eddsa, signature, message, public_key)` -| `public_key.async_verify(executor, crypto::eddsa, signature, message, token)` + -`crypto::async_verify(executor, crypto::eddsa, signature, message, public_key, token)` +| `public_key.verify(crypto::signing_schemes::eddsa, crypto::verification_policies::canonical, signature, message)` + +`crypto::verify(crypto::signing_schemes::eddsa, crypto::verification_policies::canonical, signature, message, public_key)` +| `public_key.async_verify(executor, crypto::signing_schemes::eddsa, crypto::verification_policies::canonical, signature, message, token)` + +`crypto::async_verify(executor, crypto::signing_schemes::eddsa, crypto::verification_policies::canonical, signature, message, public_key, token)` |=== *Ed25519ph* signs the SHA-512 of a message instead of the message (RFC 8032's prehashed form). A program that has the digest already signs it under the -scheme `crypto::eddsa_prehashed`, marked as one: -`+key_pair.sign(crypto::eddsa_prehashed, crypto::prehashed{digest})+`, `digest` +scheme `crypto::signing_schemes::eddsa_prehashed`, marked as one: +`+key_pair.sign(crypto::signing_schemes::eddsa_prehashed, crypto::signing_schemes::prehashed{digest})+`, `digest` the 64 bytes of the message's SHA-512 (webcpp::hash's `sha2_512` computes it), -and `+crypto::verify(crypto::eddsa_prehashed, signature, crypto::prehashed{digest}, -public_key)+` or `+public_key.verify(crypto::eddsa_prehashed, signature, -crypto::prehashed{digest})+` checks it, strictly, as `crypto::eddsa` does. The +and `+crypto::verify(crypto::signing_schemes::eddsa_prehashed, crypto::verification_policies::canonical, signature, crypto::signing_schemes::prehashed{digest}, +public_key)+` or `+public_key.verify(crypto::signing_schemes::eddsa_prehashed, crypto::verification_policies::canonical, signature, +crypto::signing_schemes::prehashed{digest})+` checks it, under `canonical`, as `crypto::signing_schemes::eddsa` does. The scheme takes the digest alone: a message, even one of 64 bytes, and a digest of another size do not compile. @@ -92,21 +104,22 @@ A program that signs a large file it reads in pieces gives each to the streaming signer, `prehashed_signer`, which hashes them, and signs once at the end. Its type names the hash, which the header brings with it, since RFC 8032 fixes it; another hash does not compile. It signs with a -key pair, `sign(key_pair)`, and verifies with `verify(signature, public_key)`, -the signature first, as in every `verify`; over the same message it gives the +key pair, `sign(key_pair)`, and verifies with +`verify(crypto::verification_policies::canonical, signature, public_key)`, the +policy first and then the signature, as in every `verify`; over the same message it gives the signature the scheme gives of the message's SHA-512, and each verifies the other's. -Both give a `curves::ed25519::signature`, the type `crypto::eddsa` gives, but the +Both give a `curves::ed25519::signature`, the type `crypto::signing_schemes::eddsa` gives, but the two schemes are not interchangeable: RFC 8032 separates their domains, so an Ed25519ph signature is not an Ed25519 signature of the same message, and neither verifies under the other scheme, which reports `invalid_signature`. A protocol says which of the two it uses. Ed25519ph runs on a native backend: WebCrypto has no Ed25519ph, and on the -browser's backend every function under `crypto::eddsa_prehashed`, `sign`, +browser's backend every function under `crypto::signing_schemes::eddsa_prehashed`, `sign`, `verify` and their asynchronous forms, stops the build with that reason; sign -the message with `crypto::eddsa` there. On libsodium, the scheme calls the +the message with `crypto::signing_schemes::eddsa` there. On libsodium, the scheme calls the internal Ed25519 function that libsodium's own Ed25519ph ends in, since its public functions sign only a digest they computed; webcpp builds libsodium from its sources, and RFC 8032's Ed25519ph vectors check the result on every target. @@ -117,20 +130,20 @@ its sources, and RFC 8032's Ed25519ph vectors check the result on every target. | Operation | Synchronous: the member; its free form | Asynchronous: the member; its free form | Sign a digest -| `+key_pair.sign(crypto::eddsa_prehashed, crypto::prehashed{digest})+` + -`+crypto::sign(key_pair, crypto::eddsa_prehashed, crypto::prehashed{digest})+` -| `+key_pair.async_sign(executor, crypto::eddsa_prehashed, crypto::prehashed{digest}, token)+` + -`+crypto::async_sign(executor, key_pair, crypto::eddsa_prehashed, crypto::prehashed{digest}, token)+` +| `+key_pair.sign(crypto::signing_schemes::eddsa_prehashed, crypto::signing_schemes::prehashed{digest})+` + +`+crypto::sign(key_pair, crypto::signing_schemes::eddsa_prehashed, crypto::signing_schemes::prehashed{digest})+` +| `+key_pair.async_sign(executor, crypto::signing_schemes::eddsa_prehashed, crypto::signing_schemes::prehashed{digest}, token)+` + +`+crypto::async_sign(executor, key_pair, crypto::signing_schemes::eddsa_prehashed, crypto::signing_schemes::prehashed{digest}, token)+` | Verify a digest -| `+public_key.verify(crypto::eddsa_prehashed, signature, crypto::prehashed{digest})+` + -`+crypto::verify(crypto::eddsa_prehashed, signature, crypto::prehashed{digest}, public_key)+` -| `+public_key.async_verify(executor, crypto::eddsa_prehashed, signature, crypto::prehashed{digest}, token)+` + -`+crypto::async_verify(executor, crypto::eddsa_prehashed, signature, crypto::prehashed{digest}, public_key, token)+` +| `+public_key.verify(crypto::signing_schemes::eddsa_prehashed, crypto::verification_policies::canonical, signature, crypto::signing_schemes::prehashed{digest})+` + +`+crypto::verify(crypto::signing_schemes::eddsa_prehashed, crypto::verification_policies::canonical, signature, crypto::signing_schemes::prehashed{digest}, public_key)+` +| `+public_key.async_verify(executor, crypto::signing_schemes::eddsa_prehashed, crypto::verification_policies::canonical, signature, crypto::signing_schemes::prehashed{digest}, token)+` + +`+crypto::async_verify(executor, crypto::signing_schemes::eddsa_prehashed, crypto::verification_policies::canonical, signature, crypto::signing_schemes::prehashed{digest}, public_key, token)+` | A message in pieces | `prehashed_signer::begin()`, `update(piece)`, then -`sign(key_pair)` or `verify(signature, public_key)` +`sign(key_pair)` or `verify(crypto::verification_policies::canonical, signature, public_key)` | none |=== @@ -144,7 +157,7 @@ include::generated/backends-ed25519ph.adoc[] *Example.* RFC 8032's second test signed and verified, then its Ed25519ph test, the message given in two pieces to the streaming signer, and its SHA-512 signed -under `crypto::eddsa_prehashed` into the same signature: +under `crypto::signing_schemes::eddsa_prehashed` into the same signature: [source,cpp] ---- @@ -156,12 +169,13 @@ include::{examples}/ed25519_sign.cpp[tag=program] include::{examples}/ed25519_sign.expected[] ---- -*Strict verification.* Implementations of Ed25519 disagree on some signatures +*Canonical verification.* Implementations of Ed25519 disagree on some signatures that no honest signer produces: a scalar `S` not reduced below the group order, a point encoded in a non-canonical form, a public key of small order. -`crypto::verify` takes a verification policy as its last argument, -`curves::ed25519::strict` by default and the only one in this version: -libsodium's rules, which refuse all three +`crypto::verify` takes a verification policy second, after the scheme, +`crypto::verification_policies::canonical`, the only one `eddsa` and +`eddsa_prehashed` take (another one, or none, stops the build with the policy +they take): libsodium's rules, which refuse all three (link:https://doc.libsodium.org/public-key_cryptography/public-key_signatures[libsodium's documentation]). Every valid signature of Wycheproof's EdDSA file is accepted and every invalid one refused (`ed25519_wycheproof_sodium`). @@ -171,11 +185,11 @@ EdDSAs" (link:https://eprint.iacr.org/2020/1244[IACR ePrint 2020/1244]), give twelve signatures on which implementations disagree, in their suite (link:https://github.com/novifinancial/ed25519-speccheck[novifinancial/ed25519-speccheck]). They run against every Ed25519 backend: its own verdict (raw), and its verdict -under `strict`, which is libsodium's on every backend. The test +under `canonical`, which is libsodium's on every backend. The test `ed25519_speccheck` asserts the table below, so that a new version of a backend that changes a verdict fails until the table is regenerated. WebCrypto in node is an outside view, recorded with the node and the OpenSSL that gave it (node's -Ed25519 is OpenSSL's) and never held to `strict`. The suite's results of 2021 +Ed25519 is OpenSSL's) and never held to `canonical`. The suite's results of 2021 show OpenSSL 3.0 accepting cases 0 to 2 and 11; the newer OpenSSL of the column's node refuses them, as libsodium does. @@ -187,11 +201,11 @@ for them. In the suite's results of 2021 (link:https://github.com/novifinancial/ed25519-speccheck#results[the suite's results], whose `Cargo.toml` pins them), Rust peers that used the default `verify` of ed25519-dalek 1.0.0-pre.4 accepted cases 0 to 2 and 11, which -`strict` refuses, and ed25519-zebra 2.1.1, a ZIP-215 verifier +`canonical` refuses, and ed25519-zebra 2.1.1, a ZIP-215 verifier (link:https://zips.z.cash/zip-0215[ZIP 215], the rule of Zcash), accepted every case but 6 to 8. ZIP-215 does so by design: it verifies with the cofactor and accepts non-canonical encodings of `A` and `R`, so that every -ZIP-215 verifier agrees on every signature. `strict` refuses the cases ZIP-215 +ZIP-215 verifier agrees on every signature. `canonical` refuses the cases ZIP-215 accepts beyond it; `zip215` is not a policy of this version, and waits for a mature C or {cpp} implementation of ZIP-215. @@ -204,7 +218,7 @@ print fixed signatures. that must refuse a replayed message signs a counter, a time or a context with it. -Parts of this section, libsodium's rules of strict verification, are adapted +Parts of this section, libsodium's rules of canonical verification, are adapted from libsodium's documentation (link:https://github.com/jedisct1/libsodium-doc/tree/6d1ea27b79b853b2a04f09ae9e1a8231c90e3b56[jedisct1/libsodium-doc] at `6d1ea27`, ISC, `LICENSE-LIBSODIUM-DOC.txt`). diff --git a/doc/errors.adoc b/doc/errors.adoc index 1add13d1..8920c058 100644 --- a/doc/errors.adoc +++ b/doc/errors.adoc @@ -28,9 +28,9 @@ of 32 bytes. |2 |`invalid_nonce_size` |A nonce of a size the algorithm does not accept: a GCM nonce that is empty or longer than 128 bytes, another AEAD's or a box's nonce of another size than its own. |3 |`invalid_tag_size` |A tag given to `open` or `verify` that is not of 16 bytes. -|4 |`invalid_input_size` |Data given to a block cipher that is not a whole number of blocks, a -DER output shorter than `max_der_size`, or the incremental open's `decrypt` past the -authenticated length and `end_open` short of it. +|4 |`invalid_input_size` |Data given to a block cipher that is not a whole number of blocks, the +incremental open's `decrypt` past the authenticated length and `end_open` short of it, or a +workspace or an output shorter than the function needs (MuSig2, silent payments). |5 |`message_too_long` |A message or associated data longer than the algorithm allows. |6 |`authentication_failed` |The tag does not match: the message or its associated data changed, or the key differs. @@ -54,8 +54,10 @@ every `from_key` of the OpenSSL backend, with `WEBCPP_CRYPTO_OPENSSL_MEMORY_RESO |17 |`invalid_scalar` |A scalar that is not reduced, or zero where zero is refused. |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` |Hexadecimal, base64, PEM, or a key's DER form that does not decode, or is -not the one encoding the format allows. +|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). |20 |`invalid_ciphertext_size` |A KEM or RSA ciphertext of another size than the key's. |=== @@ -69,6 +71,62 @@ means and what to do. include::generated/backends-error.adoc[] +[#crypto-errors-categories] +*Two categories: crypto's and codecs'.* The key formats are formats of +webcpp::codecs (<>), so a call of `crypto::encode` or +`crypto::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): + +[cols="4,3,2",options="header"] +|=== +|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 +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 +|`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 +|`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 +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 +|`crypto::error::invalid_state` |`webcpp.crypto` +|A PEM boundary or label that is not the format's, text before BEGIN or after +END +|`codecs::error::invalid_prefix` |`webcpp.codecs` +|A PEM line of another length than 64 but the last +|`codecs::error::invalid_length` |`webcpp.codecs` +|A character outside base64's alphabet, or padding that is not the one +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 +|`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` +|`codecs::error::checksum_mismatch` |`webcpp.codecs` +|=== + +A value codec returns crypto's error unchanged, and codecs adds none to it; the +armor's, the output's and the bounds' are codecs' own +(link:{webcpp-libs}/codecs/{webcpp-page}#codecs-errors[codecs' errors]). Every +other operation of crypto reports crypto's category alone. + *Example.* A message is sealed, then opened three ways: with a flipped bit, with an empty nonce and with a short tag. Only the first is an attack, and only the first decrypted anything, which `open` has zeroed: diff --git a/doc/everyday.adoc b/doc/everyday.adoc index 7e5bac94..06b715d9 100644 --- a/doc/everyday.adoc +++ b/doc/everyday.adoc @@ -115,10 +115,11 @@ who can change the download, a compromised mirror, a network in the middle, could ship code that the program then runs. *The idea.* The publisher signs each update with ECDSA over SHA-256, -`crypto::ecdsa_sha256`, which hashes the update inside the call; the program +`crypto::signing_schemes::ecdsa_sha256`, which hashes the update inside the call; the program ships with the publisher's public key and accepts an update only when -its signature verifies. Only the publisher's secret key can produce a signature -the program accepts. +its signature verifies, under `crypto::verification_policies::low_s_only`, the +policy secp256k1's ECDSA takes (<>). Only the +publisher's secret key can produce a signature the program accepts. [source,cpp] ---- @@ -140,3 +141,45 @@ include::{examples}/signed_update.cpp[tag=program] *Mistakes to avoid.* Verify the bytes that will run, not a copy of them. Keep the publisher's secret key off the build machines that anyone can reach. Never fall back on an unsigned update when verification fails. + +[#crypto-everyday-uploaded-key] +=== A public key a browser uploads + +*The problem.* A web app lets a user register a device: the browser makes a +P-256 key pair with WebCrypto, keeps its secret, and uploads the public key; the +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(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 +one encoding (<>, <>). Nothing of it +allocates. + +[source,cpp] +---- +include::{examples}/uploaded_key.cpp[tag=register,indent=0] +---- + +The device signs what the server asks it to; WebCrypto's ECDSA signatures may be +high S, so the server verifies under `crypto::verification_policies::any_s`, +which takes either form (<>): + +[source,cpp] +---- +include::{examples}/uploaded_key.cpp[tag=verify,indent=0] +---- + +[listing] +---- +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, +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 +expects refuses another curve. Treating a decoded key as a registered one: the +key proves nothing until the device signs a challenge the server drew. diff --git a/doc/formats.adoc b/doc/formats.adoc index 36282f69..b5cce390 100644 --- a/doc/formats.adoc +++ b/doc/formats.adoc @@ -5,7 +5,7 @@ // https://www.boost.org/LICENSE_1_0.txt) [#crypto-key-formats] -=== Key formats: SPKI, PKCS#8 and PEM +=== Key formats: raw, SPKI, PKCS#8, DER and PEM A key leaves a program in a standard form when another program must read it: OpenSSL's command line, a browser's WebCrypto, an SSH or TLS tool, a server @@ -16,11 +16,386 @@ ASN.1, carry a key with the name of its algorithm: *SPKI*, a public key link:https://www.rfc-editor.org/rfc/rfc5958[RFC 5958]). *PEM* writes either as text between `-----BEGIN PUBLIC KEY-----` and `-----END PUBLIC KEY-----`, or `PRIVATE KEY`, so that it can be pasted into a file, a form or an e-mail -(link:https://www.rfc-editor.org/rfc/rfc7468[RFC 7468]). A chat app that lets -a user export an identity key to another device, or a server that accepts a -public key uploaded by a browser, speaks these forms. +(link:https://www.rfc-editor.org/rfc/rfc7468[RFC 7468]). A key's or a +signature's own bytes, the *raw* form, are what WebCrypto's `exportKey("raw")` +gives and what a protocol sends on the wire, and an ECDSA signature also has +*DER*, the form of X.509, TLS and Bitcoin. A chat app that lets a user export an +identity key to another device, or a server that accepts a public key uploaded +by a browser, speaks these forms. -For Ed25519 and X25519, RFC 8410 fixes them to one layout each +Every one of them is a format of webcpp::codecs +(link:{webcpp-libs}/codecs/{webcpp-page}#codecs-overview[codecs' overview]): a +tag of `webcpp::crypto::formats`, in ``, and, for +each pair of a format and a type, a `codecs::value_codec` specialization in the +type's curve's formats header, `/formats.hpp>`. +crypto's verbs, `crypto::encode` and `crypto::decode`, check the pair against +the type's formats and call codecs' verbs; a program may call +`codecs::encode` and `codecs::decode` with the same formats and gets the same +bytes. A program that uses one curve's formats includes that curve's formats +header, and pulls no other curve and no other backend. + +[#crypto-key-formats-forms] +==== The four forms of a call + +[cols="2,4,4",options="header"] +|=== +| | Encode | Decode + +| Free, the main form +| `crypto::encode(format, value)`: a result held on the stack, `codecs::bytes` +or `codecs::text`, or their secret forms +| `crypto::decode(format, input)`: `boost::system::result` + +| Free, a token +| `crypto::encode(format, value, token)`: any token of codecs', such as +`codecs::tokens::append_to(text)`, or of Boost.URL's +| (the typed decode builds `T`) + +| Free, the caller's memory +| `crypto::encode(format, value, output)`: the size written, into a span the +caller sized with `formats::max_encoded_size` +| + +| Member +| `value.encode(format)` +| `T::decode(format, input)` +|=== + +The four give the same bytes. The members call the free verbs, and are defined +by the curve's formats header: a curve's own header declares them and includes +no format, so that calling `key.encode(formats::spki)` without +`/formats.hpp>` is the compiler's "function with +deduced return type cannot be used before it is defined". The input of a +decode is bytes, `std::span` or what converts to one, for a +binary format, `raw`, `spki`, `pkcs8` and `der`, and a text, a +`std::string_view` or another contiguous range of `char`, for a PEM: PEM text +is never read as DER, nor the reverse. + +[#crypto-key-formats-table] +==== The formats and the types + +`webcpp::crypto::formats` holds four format tags, `formats::raw`, +`formats::spki`, `formats::pkcs8` and `formats::der`, each a `codecs::format` +with its `name` and an explicit default constructor, so that `+{}+` never stands +for a format; the point forms `formats::compressed`, `formats::uncompressed` and +`formats::xonly`, which `raw(form)` and `spki(form)` take +(<>); and `formats::pem(inner)`, PEM over `spki` +or `pkcs8` (<>). The library holds one list of them, +`detail::all_formats`: `raw`, `spki`, `pkcs8`, `der`, `pem(spki)` and +`pem(pkcs8)`, each of its default form. Each type declares the formats it has in +one place, beside its value codecs, a list of formats of that list, and crypto's +check, the tests and the table below derive from it. A format added later, JWK, +is one more tag, one line of the list, and its value codecs, with no change to +any call (<>). + +The valid pairs, each cell the exact size `encode` writes, in bytes for the +binary formats and in characters for PEM; "secret" marks a pair whose results +are codecs' secret ones, and "-" a pair that stops the build: + +include::generated/formats.adoc[] + +The table is generated from `doc/tables/crypto.json`, whose list of formats +generate.py checks against `detail::all_formats` as `formats.hpp` declares it; +the test `formats_table` takes every format of `detail::all_formats` with every +point form over every type, and asserts that codecs' own concepts, +`codecs::encodable` and `codecs::decodable`, and crypto's check are true for +the table's pairs and no other, and that each binary size is the value codec's +`max_encoded_size`. A key pair is on a backend that holds its secret: one whose +key pairs live in WebCrypto has no private format (<>). +A PEM's size is RFC 7468's: for P-256's SPKI of 91 bytes, 124 base64 characters +in 2 lines of at most 64, each ended by a line feed, 27 characters before them +and 25 after, 178 in all. + +A pair the type does not have stops the build in crypto's check, before codecs +is reached, with a fixed sentence and, in the failed requirement the compiler +prints, the type's list of formats, so that the diagnostic names what the type +has with no text written by hand. Some pairs add a sentence of their own: `der` +of an Ed25519 or BIP340 signature ("their 64 bytes are the signature"), `der` of +a recoverable signature, `raw(formats::xonly)` decoded into a +`secp256k1::public_key` ("an x-only key decodes into +curves::secp256k1::xonly_public_key"), a private format of a key pair whose +secret lives in WebCrypto, a type whose curve's formats header is not included +("include /formats.hpp>"), and `pem` of another +format than `spki` and `pkcs8`. <> gives each with its fix. A type that is not crypto's is left to +codecs, whose own diagnostic says the pair has no value codec. + +[#crypto-key-formats-point-forms] +==== Point forms + +A point of an elliptic curve is written in one of SEC 1's forms +(link:https://www.secg.org/sec1-v2.pdf[SEC 1, section 2.3.3]): uncompressed, +`04`, x and y, 65 bytes on a 256-bit curve; compressed, `02` or `03` for the +parity of y, then x, 33 bytes. The default form of every EC format is the +uncompressed point: `raw` of a P-256 key is WebCrypto's `exportKey("raw")`, and +`spki` writes what OpenSSL's `i2d_PUBKEY`, node and WebCrypto write. A modifier +names another form: + +* `formats::raw(formats::compressed)` and `formats::spki(formats::compressed)` +write the compressed point, on P-256 and secp256k1, on every backend: 33 bytes, +and an SPKI of 59 bytes (P-256) or 56 (secp256k1), the same AlgorithmIdentifier +around a shorter BIT STRING; `formats::uncompressed` names the default form; +`formats::pem(formats::spki(formats::compressed))` is the compressed SPKI's PEM. +* `formats::raw(formats::xonly)` writes BIP 340's x-only key of a +`secp256k1::public_key`, its 32 bytes of x +(link:https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki[BIP 340]): +to encode only, since 32 bytes are not that key. They decode into the typed +x-only key, `secp256k1::xonly_public_key`, the point of even y, whose +`formats::raw` and `raw(formats::xonly)` are the same 32 bytes +(<>). + +Encoding a form copies or computes bytes from the point the key holds and calls +no backend. Decoding with the default form accepts what the key's `from_bytes` +accepts, the 65 or the 33 bytes, in `raw` and in `spki`, so that a stored +compressed SPKI still decodes; a decode that names a form accepts that form +alone. A compressed point is decompressed before it is checked. libsecp256k1 +decompresses secp256k1's itself. BearSSL, P-256's backend, decodes uncompressed +points alone, so crypto decompresses P-256's on BearSSL's own 31-bit integers, +from `backends/bearssl.hpp`: y is SEC 1's square root for a prime p = 3 mod 4, +`pass:[y = (x^3 - 3x + b)^((p + 1) / 4) mod p]`, checked by squaring it and negated when its +parity is not the prefix's, on public data only. Then the point is checked as +`from_bytes` checks it. An x not below p, an x that is no point's, a prefix `02` +or `03` with 65 bytes and a prefix `04` with 33 are `invalid_public_key` in +`raw`, and `invalid_encoding` in `spki`, whose decoder refuses every input that +is not the one encoding with that error +(<>, <>). Ed25519's and X25519's +keys have one form, their 32 bytes, and take no modifier. + +The public keys keep their accessors, `bytes()`, `uncompressed()`, +`compressed()` and, on secp256k1, `xonly()`, which returns the typed x-only key: +they are the value's own bytes, which `raw` calls, not a second format API. + +[#crypto-key-formats-pem] +==== PEM over codecs' armor + +`formats::pem(formats::spki)` and `formats::pem(formats::pkcs8)` are codecs' +armor over the key's DER, `codecs::over` +(link:{webcpp-libs}/codecs/{webcpp-page}#codecs-armor[codecs' armor]): RFC 7468's +text, its label `PUBLIC KEY` for every point form of `spki` and `PRIVATE KEY` +for `pkcs8`, taken from the inner format, never from the caller, so that no +call writes a public key under a private key's label. `pem` of any other format +stops the build: "PEM carries a DER key: pem(formats::spki) or +pem(formats::pkcs8)". Its base64 is codecs', constant time on every call, a +private key's included, and needs no backend. + +`crypto::decode` of a PEM decodes in place, in two steps: the armor's payload +into a buffer on the stack of the inner format's decode bound, +`formats::max_decode_input_size` (at most 138 bytes, P-256's +PKCS#8), then the inner format's value codec; the buffer is wiped after a +PKCS#8, on every path. Nothing is allocated. A payload longer than the inner +format's longest encoding, an RSA key's SPKI labelled `PUBLIC KEY` among them, +is crypto's `invalid_encoding`, found before the buffer is written past. +`codecs::decode` of the same text, from a text of dynamic size, takes the +armor's intermediate from its allocator: the result is the same, and only +crypto's verb avoids the heap. + +PEM is read as Windows and OpenSSL's tools write it: lines ended by a line feed +or by a carriage return and a line feed, the last line's end optional. Text +before BEGIN or after END, what `openssl ec -text` prints before the key, a +label other than the format's, is `codecs::error::invalid_prefix`, never a key; +a line of another length than 64 but the last, and base64 that is not the one +encoding of its bytes, are codecs' errors (<>). + +[#crypto-key-formats-results] +==== codecs' results and tokens + +The result of `crypto::encode` is codecs': `codecs::bytes` for a binary format and +`codecs::text` for PEM, held in place, N the value codec's +`max_encoded_size`, so that nothing is allocated; `size()` is the encoding's +length, `capacity()` N, and `view()` the bytes or the characters, a view of the +result that is refused at compile time on a temporary. A public result compares +by content. A private format, a key pair's `raw`, `pkcs8` and `pem(pkcs8)`, +gives `codecs::secret_bytes` and `codecs::secret_text` instead: move-only, +copied by `clone()` alone, with no `==`, and wiped by `secure::erase_secret` +when destroyed or moved from +(link:{webcpp-libs}/codecs/{webcpp-page}#codecs-results[codecs' results], +link:{webcpp-libs}/codecs/{webcpp-page}#codecs-secrecy[codecs' secrecy]). A +PEM result's capacity is codecs' bound of the armor for the longest label, 64 +characters: 221 for Ed25519's SPKI of 44 bytes, 286 for P-256's of 91, 347 for +P-256's PKCS#8 of 138, while its size is the table's. + +Two bounds size a program's own buffers: `formats::max_encoded_size`, +the longest encoding `encode` writes, and +`formats::max_decode_input_size`, the longest input `decode` accepts; +the two are equal for every pair of this version, and an encode-only pair, +`raw(formats::xonly)` of a `secp256k1::public_key`, states the first alone. The +span form, `crypto::encode(format, value, output)`, takes +`std::span` for a binary format and `std::span` for PEM, +writes at the start of the span, and refuses one shorter than the exact +encoding with `codecs::error::output_too_small`, writing nothing; it writes +nothing on any error. A token puts the encoding where the program wants it, +`codecs::tokens::append_to(text)` at the end of a string the program keeps, +`codecs::tokens::secret` into a secret result +(link:{webcpp-libs}/codecs/{webcpp-page}#codecs-tokens[codecs' tokens]); an +encoding that fails leaves a token of codecs' as it was. + +What each call costs in memory: + +[cols="3,2,5",options="header"] +|=== +| Call | Heap | Stack + +| `encode` of every format, the default result +| none +| the result, at most 347 characters (P-256's `pem(pkcs8)` capacity), and for a +PEM the armor's intermediate of the inner format's bound, at most 138 bytes, +wiped for `pkcs8` + +| `encode` into a span +| none +| the armor's intermediate, for a PEM + +| `encode` into a token that allocates +| the token's own +| as above + +| `decode` of `raw`, `spki`, `pkcs8`, `der` +| none +| a re-encoding to check that the input is the one encoding, wiped for `pkcs8` + +| `crypto::decode` of `pem(F)` +| none +| the DER, at most `max_decode_input_size` of the inner format, wiped for `pkcs8` + +| `codecs::decode` of `pem(F)` from a text of dynamic size +| the armor's intermediate, from its allocator +| the result +|=== + +secp256k1's key pair is the exception it is everywhere: decoding one makes its +signing context, the one allocation of `keypair::from_secret`, from +`std::pmr::get_default_resource()`, or from the program's own resource with +`keypair::decode(format, input, resource)` (<>). + +*Errors.* A value codec's errors are crypto's, unchanged: `invalid_encoding` +for bytes no encoder writes, `invalid_public_key`, `invalid_signature`, +`invalid_key_size`, `invalid_secret_key`, and `invalid_state` for a moved-from +key pair given to a private format, with nothing written; a key pair's decode +also gives the errors of its `from_secret`, `entropy_unavailable` and +`backend_failure` (secp256k1's signing context, P-256's PKCS#8 on BearSSL). +The armor's faults, +a short output and an input past a bound codecs checks are codecs' errors, in +the category `webcpp.codecs`: <> lists which category +each refusal is in. + +[#crypto-key-formats-before] +==== Before and after + +The formats replaced a function per curve and per format, and a PEM namespace +of crypto's own. What a program wrote before, and writes now: + +[cols="1,1",options="header"] +|=== +| Before | After + +| `p256::encode_spki(public_key, der)` into an array of `p256::max_spki_size`, +then `+pem::armour(pem::public_key_label, der, text)+` into an array of +`+pem::armoured_size(...)+` +| `crypto::encode(formats::pem(formats::spki), public_key)`, or +`public_key.encode(formats::pem(formats::spki))` + +| `+pem::unarmour(pem::private_key_label, pem_text, der)+`, then +`p256::decode_pkcs8(der)` +| `crypto::decode(formats::pem(formats::pkcs8), pem_text)`, or +`p256::keypair::decode(formats::pem(formats::pkcs8), pem_text)` + +| `key.sign(crypto::ecdsa_sha256, message)`, then `p256::to_der(signature, der)` +| `key.sign(signing_schemes::ecdsa_sha256, message)`, then +`crypto::encode(formats::der, signature)` + +| `crypto::verify(crypto::ecdsa_sha256, signature, message, key)` +| `crypto::verify(signing_schemes::ecdsa_sha256, verification_policies::any_s, +signature, message, key)`, or `low_s_only` + +| `p256::normalize_low_s(signature)`, `p256::is_low_s(signature)` +| `signature.low_s()`, `signature.is_low_s()` + +| `secp256k1::tweak_xonly(key, tweak)`; `crypto::verify(crypto::schnorr, +signature, message, bytes)` over 32 bytes +| `xonly_key.tweak_add(tweak)`; `crypto::verify(signing_schemes::schnorr, +verification_policies::canonical, signature, message, xonly_key)` over the typed +key +|=== + +The new calls, each checked by the test `formats_before_after`: + +[source,cpp] +---- +include::{library-root}/test/formats_before_after_test.cpp[tag=after,indent=0] +---- + +The names that went have no alias, and four signatures changed; each has its +replacement: + +[cols="1,1",options="header"] +|=== +| Removed | Its replacement + +| each curve's `encode_spki`, `decode_spki`, `encode_pkcs8`, `decode_pkcs8` +| `crypto::encode` and `crypto::decode` with `formats::spki` and +`formats::pkcs8`, or the members + +| secp256k1's `decode_pkcs8(bytes, resource)` +| `keypair::decode(format, input, resource)`, for `raw`, `pkcs8` and +`pem(pkcs8)` + +| P-256's and secp256k1's `to_der`, `from_der` +| `crypto::encode(formats::der, signature)`, +`crypto::decode(formats::der, bytes)` + +| `max_spki_size`, `max_pkcs8_size`, `max_der_size`, secp256k1's +`spki_compressed_size` and `spki_uncompressed_size` +| `formats::max_encoded_size`, a point form named in `Format` +(`formats::spki_t`) + +| P-256's and secp256k1's free `normalize_low_s` and `is_low_s` +| the signature's members `low_s()` and `is_low_s()` + +| ``, `crypto::pem` (`armour`, `unarmour`, +`public_key_label`, `private_key_label`, `armoured_size`), `families::pem` +| `formats::pem(formats::spki)` and `formats::pem(formats::pkcs8)`, codecs' +armor, the label taken from the inner format + +| `/webcpp/crypto//pem-default` +| nothing: PEM needs no backend, so a Jamfile drops the line + +| the scheme tags in `crypto::` (`crypto::eddsa`, ..., `crypto::schnorr`) and +`crypto::prehashed` +| the same names in `crypto::signing_schemes`, `signing_schemes::prehashed` +among them + +| Ed25519's `strict_t` and `strict` +| `verification_policies::canonical`, every verification taking a policy after +the scheme (<>) + +| secp256k1's free `tweak_xonly` +| `xonly_public_key::tweak_add(tweak)`, checked by `verify_tweak`; the key +pair's `tweak_xonly` stays + +| secp256k1's `crypto::verify` of a Schnorr signature over a 32-byte span +| `crypto::verify` with a `secp256k1::xonly_public_key`, made from the 32 bytes +by `from_bytes` or `crypto::decode` + +| secp256k1's `public_key::xonly()`, MuSig2's +`aggregate_key::xonly_public_key()` and `tweaked_xonly_key::key`, each +`std::array` +| the typed `xonly_public_key`, whose `bytes()` gives the 32 bytes + +| `crypto::can_verify` +| `crypto::can_verify` + +| Ed25519's `prehashed_signer::verify(signature, key)` +| `prehashed_signer::verify(verification_policies::canonical, signature, key)` +|=== + +One default changed: secp256k1's `spki` writes the uncompressed point, 88 bytes, +as OpenSSL and node write it, where it wrote the compressed one; the default +form still reads a compressed SPKI. + +[#crypto-key-formats-curves] +==== Each curve's layouts + +For Ed25519 and X25519, RFC 8410 fixes the DER forms to one layout each (link:https://www.rfc-editor.org/rfc/rfc8410[RFC 8410]): an SPKI is 12 bytes that name the curve, then the 32 bytes of the public key, 44 bytes in all; a PKCS#8 is 16 bytes, then the 32 bytes of the seed (Ed25519) or secret key @@ -31,66 +406,51 @@ and `i2d_PrivateKey` and WebCrypto's `exportKey("spki")` and OpenSSL's `PEM_write_bio_PUBKEY` and `PEM_write_bio_PrivateKey` write: the tests compare every byte with OpenSSL's natively and on WASI (`formats_25519_openssl_oracle`) and with node's WebCrypto on Emscripten -(`formats_25519_webcrypto_oracle`), 200 keys per curve each. - -For P-256, RFC 5480's SPKI and a PKCS#8 holding RFC 5915's ECPrivateKey are -fixed layouts too (link:https://www.rfc-editor.org/rfc/rfc5480[RFC 5480]; -link:https://www.rfc-editor.org/rfc/rfc5915[RFC 5915]), on BearSSL: -`` gives `encode_spki`, `decode_spki`, -`encode_pkcs8` and `decode_pkcs8` in `webcpp::crypto::curves::p256`: an -SPKI of 91 bytes with the uncompressed point, WebCrypto's `exportKey("spki")` -form -(link:https://www.w3.org/TR/WebCryptoAPI/#ecdsa-operations-export-key[W3C, -ECDSA's export]), and a PKCS#8 of 138 bytes with the public key and without -the curve inside the ECPrivateKey, OpenSSL's form -(link:https://docs.openssl.org/master/man7/EVP_PKEY-EC/[OpenSSL's EVP_PKEY-EC]) -and BearSSL's, which WebCrypto's `importKey("pkcs8")` reads -(link:https://www.w3.org/TR/WebCryptoAPI/#ecdsa-operations-import-key[W3C, -ECDSA's import]). A compressed point, explicit curve parameters and a PKCS#8 -that carries the curve inside its ECPrivateKey, the form the W3C text gives -WebCrypto's `exportKey("pkcs8")`, are refused; `pem` armours both -(<>). - -`` gives, in -`webcpp::crypto::curves::ed25519`, `encode_spki(public_key, out)`, -`decode_spki(spki)`, `encode_pkcs8(keypair, out)` and `decode_pkcs8(pkcs8)`, -which makes the key pair at once; `` -gives the same four in `webcpp::crypto::curves::x25519`, where a PKCS#8 -holds a 32-byte secret key and `decode_pkcs8` gives it as a `secure::secret<32>`, which -wipes itself. `max_spki_size` and `max_pkcs8_size`, 44 and 48, size the -caller's buffers. `` gives, in `webcpp::crypto::pem`, -`armour(label, der, out)` and `unarmour(label, text, out)`, with the labels -`public_key_label` and `private_key_label`, and `armoured_size`, the text's -size. Each writes into the caller's buffer and returns how many bytes or -characters it wrote; on a refusal it writes nothing. All run on libsodium -(`/third_party//sodium`, or the families' aliases `/webcpp/crypto//ed25519-default`, -`/webcpp/crypto//x25519-default` and `/webcpp/crypto//pem-default`), whose base64 runs -in a time that does not depend on the bytes, those of a private key included -(link:https://doc.libsodium.org/helpers#base64-encoding-decoding[libsodium's documentation]). - -*Strict decoding.* A decoder accepts an input only if encoding what it -decoded gives the same bytes (design D30): the one form that OpenSSL and -WebCrypto write, and nothing else. It refuses with `invalid_encoding` another -curve's identifier (an Ed25519 key given to X25519's decoder), a byte left -over, a length in BER's long form where DER requires the short one, -PKCS#8 version 2, which carries the public key beside the seed, attributes, -and PEM with another label than the expected, lines of another length than 64, -carriage returns, text before or after the key, or base64 that is not the one -encoding of its bytes. A key that one library accepts and another refuses -lets two programs that should agree on a key disagree on it; one form, and -one verdict on every backend, closes that door. A program that receives -version 2, or PEM with Windows line ends, converts it with OpenSSL's -`openssl pkey` first. +(`formats_25519_webcrypto_oracle`), 200 keys per curve each. A key pair's +`formats::raw` is its seed (Ed25519) or its secret key (X25519), `secret()` and +`from_secret` under the format's name, and an Ed25519 signature's is its 64 +bytes. A public key, which names no backend, is encoded and decoded on its +family's default, libsodium on every target (`/webcpp/crypto//ed25519-default` +and `/webcpp/crypto//x25519-default` link it); +`crypto::decode(formats::spki, bytes)` gives the typed key +a key pair's `agree` takes. + +For P-256, RFC 5480's SPKI and a PKCS#8 holding RFC 5915's ECPrivateKey with +the public key and without the curve inside it, OpenSSL's form and BearSSL's, +which WebCrypto's `importKey("pkcs8")` reads +(link:https://www.rfc-editor.org/rfc/rfc5480[RFC 5480]; +link:https://www.rfc-editor.org/rfc/rfc5915[RFC 5915]; +link:https://docs.openssl.org/master/man7/EVP_PKEY-EC/[OpenSSL's EVP_PKEY-EC]); +explicit curve parameters, and a PKCS#8 that carries the curve inside its +ECPrivateKey, the form the W3C text gives WebCrypto's `exportKey("pkcs8")`, are +refused (<>). For secp256k1, the same layouts with +secp256k1's OID, its ECDSA signature's DER through libsecp256k1's own encoder +and parser, strict DER as BIP 66 has it, and a Schnorr or a recoverable +signature with `formats::raw` alone (<>). An ECDSA +signature's `formats::der` is strict DER of 8 to 72 bytes, its exact size +computed from r and s before any write, and refuses an r or an s that is 0 or +not below n with `invalid_signature` (<>). + +*Strict decoding.* A decoder accepts an input only if encoding what it decoded +gives the same bytes (design D30): the one form that OpenSSL and WebCrypto +write, and nothing else. It refuses with `invalid_encoding` another curve's +identifier (an Ed25519 key given to X25519's decoder), a byte left over, a +length in BER's long form where DER requires the short one, PKCS#8 version 2, +which carries the public key beside the seed, and attributes. A key that one +library accepts and another refuses lets two programs that should agree on a +key disagree on it; one form, and one verdict on every backend, closes that +door. A program that receives version 2 converts it with OpenSSL's +`openssl pkey` first; a later version accepts it on decoding +(<>). include::generated/backends-ed25519_formats.adoc[] include::generated/backends-x25519_formats.adoc[] -include::generated/backends-pem.adoc[] - -*Example.* RFC 8410's own Ed25519 key pair read from PEM, its public key written -back as PEM, which is the RFC's to the character, and a signature; an X25519 -public key's SPKI; and the RFC's version 2 of the same private key refused: +*Example.* RFC 8410's own Ed25519 key pair read from PEM with `crypto::decode`, +its public key written back as PEM with `crypto::encode`, which is the RFC's to +the character, and a signature; an X25519 public key's PEM, with its member +`encode`; and the RFC's version 2 of the same private key refused: [source,cpp] ---- @@ -102,15 +462,68 @@ include::{examples}/key_formats.cpp[tag=program] include::{examples}/key_formats.expected[] ---- -*Pitfalls.* +[#crypto-key-formats-webcrypto] +==== Keys that live in WebCrypto + +Encoding and decoding are synchronous: they read bytes the program holds. A +backend whose key pairs live in a WebCrypto `CryptoKey` (the asynchronous +family's browser backend, <>) holds no secret bytes, and +a non-extractable key has none to give. The private formats, a key pair's +`raw`, `pkcs8` and `pem(pkcs8)`, have no value codec for such a backend, and +`crypto::encode` says so, naming WebCrypto's `exportKey`; its public key keeps +`raw`, `spki` and `pem(spki)`, computed from the public key the backend keeps. + +[#crypto-key-formats-jwk] +==== Deferred: JWK and PKCS#8 version 2 + +JWK, the JSON form of a key that WebCrypto's `exportKey("jwk")` writes +(link:https://www.rfc-editor.org/rfc/rfc7517[RFC 7517]), is not in this +version. It comes last of three steps, none of them in crypto yet: + +. a JSON Schema validator, webcpp's json_schema, whose first version is drafted; +. that validator on webcpp::document's values, with document's streaming parser +applying a compiled schema as it parses, so that what the schema forbids (a +member not allowed, a string longer than its `maxLength`, a value of the wrong +type) is refused before it is buffered, and what it does not need is skipped; +. crypto's JWK: a schema per key type checks the shape and the limits, and +crypto's own small reader reads a private key's `d` in constant time; JWK joins +the list as `formats::jwk`, a value codec of text per key type, with no change +to any call. The list leaves room for it: a test adds a stand-in text format to +a copy of `detail::all_formats` and checks that the check, codecs' results and +the verbs take it unchanged (`formats_stand_in`). + +Until then, a program that exchanges JWK reads it with webcpp::document and +builds the typed keys through `raw`: `p256::keypair::from_secret(d)`, and +`p256::public_key::from_bytes` of `04`, x and y, as webcpp::trystero does with +Trystero's keys (<>). + +PKCS#8 version 2, RFC 5958's OneAsymmetricKey with `[1] publicKey` after the +seed (83 bytes for Ed25519 and X25519), is refused with `invalid_encoding` in +this version. A later version accepts it on decoding only, the public key +checked against the seed's: its decode bound, +`formats::max_decode_input_size`, becomes 83 for those two types, the encoder +keeps writing version 1, and no call changes. + +[#crypto-key-formats-pitfalls] +==== Pitfalls -* A PKCS#8, as DER or as PEM, is the secret key: kept in a `secure::secret`, as the -example does, it is wiped when it goes; written to a file or a database, it is -sealed first, as any secret at rest (<>). -* `decode_spki` checks the form, not the key: `crypto::verify` with -`crypto::eddsa` refuses a public key that is not a point of the curve, and -X25519's `agree` one of low order (`weak_public_key`). A key read from outside -is used through those, which check it. +* A PKCS#8, as DER or as PEM, is the secret key: kept in the secret result +`crypto::encode` gives, or decoded in place as the example does, it is wiped +when it goes; written to a file or a database, it is sealed first, as any +secret at rest (<>). A secret result's `clone()` is a second +copy to look after. +* On Ed25519 and X25519, decoding an SPKI checks the form, not the key: +`crypto::verify` with `crypto::signing_schemes::eddsa` refuses a public key that +is not a point of the curve, and X25519's `agree` one of low order +(`weak_public_key`). A key read from outside is used through those, which check +it. P-256's and secp256k1's SPKI decode checks the point itself, as `from_bytes` +does. * SPKI names the algorithm, the raw 32 bytes do not: an Ed25519 key and an X25519 key of the same bytes are different keys, and the identifier keeps a program from using one as the other. +* `codecs::decode` of a PEM from a `std::string` allocates the armor's +intermediate; `crypto::decode` of the same text does not. A program that +must not allocate calls crypto's verb. +* A decode with the default form reads both points; a program that must store +one form encodes with that form named, as secp256k1's `spki` changed its +default in this version. diff --git a/doc/generated/backend-facts.adoc b/doc/generated/backend-facts.adoc index 628802a2..4a49878d 100644 --- a/doc/generated/backend-facts.adoc +++ b/doc/generated/backend-facts.adoc @@ -54,7 +54,7 @@ The library behind each, and what it costs a program: |Backend |Library |Licence |Its own API, reachable |Allocation |BearSSL -|BearSSL, upstream commit 7bea48e5 and one fix of webcpp's, commit 32381d6e of the mirror webcpporg/bearssl's branch webcpp, built from source +|BearSSL at webcpporg/bearssl commit ae63032d, upstream commit 7bea48e5 plus exactly the ECDSA nonce fix submitted upstream, until upstream applies it, built from source |MIT |`++`, all of it |none: the key schedule and GCM's state live inside the object @@ -75,7 +75,7 @@ The library behind each, and what it costs a program: |libsecp256k1 v0.8.0, built from source with every module on |MIT |`++` and its modules -|`+keypair::from_secret+` allocates the signing context, once, in the `+std::pmr::memory_resource+` it is given; nothing else allocates +|`+keypair::from_secret+` allocates the signing context, once, in the `+std::pmr::memory_resource+` it is given, and so does a key pair's decode, `+keypair::decode(format, input, memory_resource)+` in the resource it is given; nothing else allocates |libsodium |libsodium 1.0.22, built from source diff --git a/doc/generated/backends-ed25519_formats.adoc b/doc/generated/backends-ed25519_formats.adoc index fcc9876c..8ba18d9a 100644 --- a/doc/generated/backends-ed25519_formats.adoc +++ b/doc/generated/backends-ed25519_formats.adoc @@ -7,7 +7,7 @@ // Generated by doc/tables/generate.py from doc/tables/crypto.json, the test Jamfiles, // the message tests and the Jamfile fixtures: run it again, never edit this file. -The backends of `+curves::ed25519::encode_spki+`, `+decode_spki+`, `+encode_pkcs8+`, `+decode_pkcs8+`, from the test programs that run it: +The backends of `+crypto::encode+`, `+crypto::decode+`, `+curves::ed25519::public_key::encode+`, `+curves::ed25519::public_key::decode+`, `+curves::ed25519::keypair::encode+`, `+curves::ed25519::keypair::decode+`, `+curves::ed25519::signature::encode+`, `+curves::ed25519::signature::decode+`, from the test programs that run it: [cols="1,2,2,4",options="header"] |=== @@ -16,7 +16,7 @@ The backends of `+curves::ed25519::encode_spki+`, `+decode_spki+`, `+encode_pkcs |libsodium |`+/third_party//sodium+` |`++` -|native, wasip2, wasip3, emscripten (tested by `+formats_25519_sodium+`, `+formats_25519_openssl_oracle+`, `+formats_25519_webcrypto_oracle+`, `+allocation_sodium+`) +|native, wasip2, wasip3, emscripten (tested by `+formats_ed25519_sodium+`, `+formats_25519_openssl_oracle+`, `+formats_25519_webcrypto_oracle+`, `+allocation_sodium+`) |=== A call that names no backend takes the family's default on each target, whatever the program links, as <> gives it with its reasons and tests: diff --git a/doc/generated/backends-encodings.adoc b/doc/generated/backends-encodings.adoc index 95f009a0..f974f3c8 100644 --- a/doc/generated/backends-encodings.adoc +++ b/doc/generated/backends-encodings.adoc @@ -7,7 +7,7 @@ // Generated by doc/tables/generate.py from doc/tables/crypto.json, the test Jamfiles, // the message tests and the Jamfile fixtures: run it again, never edit this file. -The backends of `+curves::secp256k1::to_der+`, `+from_der+`, `+normalize_low_s+`, `+is_low_s+`, from the test programs that run it: +The backends of `+curves::secp256k1::ecdsa_signature::is_low_s+`, `+low_s; recoverable_signature::is_low_s+`, `+low_s+`, from the test programs that run it: [cols="1,2,2,4",options="header"] |=== diff --git a/doc/generated/backends-key_formats.adoc b/doc/generated/backends-key_formats.adoc index 895543f6..c591d8e2 100644 --- a/doc/generated/backends-key_formats.adoc +++ b/doc/generated/backends-key_formats.adoc @@ -7,7 +7,7 @@ // Generated by doc/tables/generate.py from doc/tables/crypto.json, the test Jamfiles, // the message tests and the Jamfile fixtures: run it again, never edit this file. -The backends of `+curves::secp256k1::encode_spki+`, `+decode_spki+`, `+encode_pkcs8+`, `+decode_pkcs8+`, from the test programs that run it: +The backends of `+crypto::encode+`, `+crypto::decode+`, `+curves::secp256k1::public_key::encode+`, `+curves::secp256k1::public_key::decode+`, `+curves::secp256k1::xonly_public_key::encode+`, `+curves::secp256k1::xonly_public_key::decode+`, `+curves::secp256k1::keypair::encode+`, `+curves::secp256k1::keypair::decode (also with a std::pmr::memory_resource)+`, `+curves::secp256k1::ecdsa_signature::encode+`, `+curves::secp256k1::ecdsa_signature::decode+`, `+curves::secp256k1::recoverable_signature::encode+`, `+curves::secp256k1::recoverable_signature::decode+`, `+curves::secp256k1::schnorr_signature::encode+`, `+curves::secp256k1::schnorr_signature::decode+`, from the test programs that run it: [cols="1,2,2,4",options="header"] |=== @@ -16,7 +16,7 @@ The backends of `+curves::secp256k1::encode_spki+`, `+decode_spki+`, `+encode_pk |libsecp256k1 |`+/third_party//secp256k1+` |`++` -|native, wasip2, wasip3, emscripten (tested by `+secp256k1_formats+`, `+secp256k1_formats_openssl+`) +|native, wasip2, wasip3, emscripten (tested by `+secp256k1_formats+`, `+secp256k1_formats_openssl+`, `+secp256k1_node_oracle+`, `+secp256k1_der+`, `+secp256k1_allocation+`) |=== A call that names no backend takes the family's default on each target, whatever the program links, as <> gives it with its reasons and tests: diff --git a/doc/generated/backends-keypair.adoc b/doc/generated/backends-keypair.adoc index b13bae8e..9f61ff44 100644 --- a/doc/generated/backends-keypair.adoc +++ b/doc/generated/backends-keypair.adoc @@ -16,7 +16,7 @@ The backends of `+curves::secp256k1::keypair+`, from the test programs that run |libsecp256k1 |`+/third_party//secp256k1+` |`++` -|native, wasip2, wasip3, emscripten (tested by `+secp256k1+`, `+secp256k1_generate+`, `+secp256k1_bip340+`, `+secp256k1_xonly_tweak+`, `+secp256k1_ecdh+`, `+secp256k1_recovery+`) +|native, wasip2, wasip3, emscripten (tested by `+secp256k1+`, `+secp256k1_generate+`, `+secp256k1_bip340+`, `+secp256k1_xonly_tweak+`, `+secp256k1_xonly_key+`, `+secp256k1_ecdh+`, `+secp256k1_recovery+`) |=== A call that names no backend takes the family's default on each target, whatever the program links, as <> gives it with its reasons and tests: diff --git a/doc/generated/backends-p256_ecdsa.adoc b/doc/generated/backends-p256_ecdsa.adoc index 35e2ec80..1aae8ef7 100644 --- a/doc/generated/backends-p256_ecdsa.adoc +++ b/doc/generated/backends-p256_ecdsa.adoc @@ -7,7 +7,7 @@ // Generated by doc/tables/generate.py from doc/tables/crypto.json, the test Jamfiles, // the message tests and the Jamfile fixtures: run it again, never edit this file. -The backends of `+curves::p256::keypair::sign; crypto::verify+`, `+to_der+`, `+from_der+`, `+normalize_low_s+`, `+is_low_s+`, from the test programs that run it: +The backends of `+curves::p256::keypair::sign; crypto::verify; ecdsa_signature::is_low_s+`, `+low_s+`, from the test programs that run it: [cols="1,2,2,4",options="header"] |=== diff --git a/doc/generated/backends-p256_formats.adoc b/doc/generated/backends-p256_formats.adoc index 65d739ac..f89d1231 100644 --- a/doc/generated/backends-p256_formats.adoc +++ b/doc/generated/backends-p256_formats.adoc @@ -7,7 +7,7 @@ // Generated by doc/tables/generate.py from doc/tables/crypto.json, the test Jamfiles, // the message tests and the Jamfile fixtures: run it again, never edit this file. -The backends of `+curves::p256::encode_spki+`, `+decode_spki+`, `+encode_pkcs8+`, `+decode_pkcs8+`, from the test programs that run it: +The backends of `+crypto::encode+`, `+crypto::decode+`, `+curves::p256::public_key::encode+`, `+curves::p256::public_key::decode+`, `+curves::p256::keypair::encode+`, `+curves::p256::keypair::decode+`, `+curves::p256::ecdsa_signature::encode+`, `+curves::p256::ecdsa_signature::decode+`, from the test programs that run it: [cols="1,2,2,4",options="header"] |=== diff --git a/doc/generated/backends-pem.adoc b/doc/generated/backends-pem.adoc deleted file mode 100644 index f74e7342..00000000 --- a/doc/generated/backends-pem.adoc +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) 2026 WebCpp.org -// -// Distributed under the Boost Software License, Version 1.0. (See -// accompanying file LICENSE_1_0.txt or copy at -// https://www.boost.org/LICENSE_1_0.txt) - -// Generated by doc/tables/generate.py from doc/tables/crypto.json, the test Jamfiles, -// the message tests and the Jamfile fixtures: run it again, never edit this file. - -The backends of `+pem::armour+`, `+pem::unarmour+`, from the test programs that run it: - -[cols="1,2,2,4",options="header"] -|=== -|Backend |Jamfile |Header |Targets - -|libsodium -|`+/third_party//sodium+` -|`++` -|native, wasip2, wasip3, emscripten (tested by `+formats_25519_sodium+`, `+formats_25519_openssl_oracle+`, `+allocation_sodium+`, `+p256_formats_bearssl+`) -|=== - -A call that names no backend takes the family's default on each target, whatever the program links, as <> gives it with its reasons and tests: - -[cols="1,1",options="header"] -|=== -|Target |Default - -|native, wasip2, wasip3, emscripten -|libsodium -|=== diff --git a/doc/generated/backends-verify.adoc b/doc/generated/backends-verify.adoc index 11097e81..4cc07ec5 100644 --- a/doc/generated/backends-verify.adoc +++ b/doc/generated/backends-verify.adoc @@ -16,7 +16,7 @@ The backends of `+crypto::verify+`, `+curves::secp256k1::recover+`, from the tes |libsecp256k1 |`+/third_party//secp256k1+` |`++` -|native, wasip2, wasip3, emscripten (tested by `+secp256k1_bip340+`, `+secp256k1_wycheproof+`, `+secp256k1_recovery+`, `+signing_curves+`) +|native, wasip2, wasip3, emscripten (tested by `+secp256k1_bip340+`, `+secp256k1_xonly_key+`, `+secp256k1_wycheproof+`, `+secp256k1_recovery+`, `+signing_curves+`) |=== A call that names no backend takes the family's default on each target, whatever the program links, as <> gives it with its reasons and tests: diff --git a/doc/generated/backends-x25519_formats.adoc b/doc/generated/backends-x25519_formats.adoc index 009cdad7..e850441d 100644 --- a/doc/generated/backends-x25519_formats.adoc +++ b/doc/generated/backends-x25519_formats.adoc @@ -7,7 +7,7 @@ // Generated by doc/tables/generate.py from doc/tables/crypto.json, the test Jamfiles, // the message tests and the Jamfile fixtures: run it again, never edit this file. -The backends of `+curves::x25519::encode_spki+`, `+decode_spki+`, `+encode_pkcs8+`, `+decode_pkcs8+`, from the test programs that run it: +The backends of `+crypto::encode+`, `+crypto::decode+`, `+curves::x25519::public_key::encode+`, `+curves::x25519::public_key::decode+`, `+curves::x25519::keypair::encode+`, `+curves::x25519::keypair::decode+`, from the test programs that run it: [cols="1,2,2,4",options="header"] |=== @@ -16,7 +16,7 @@ The backends of `+curves::x25519::encode_spki+`, `+decode_spki+`, `+encode_pkcs8 |libsodium |`+/third_party//sodium+` |`++` -|native, wasip2, wasip3, emscripten (tested by `+formats_25519_sodium+`, `+formats_25519_openssl_oracle+`, `+formats_25519_webcrypto_oracle+`, `+allocation_sodium+`) +|native, wasip2, wasip3, emscripten (tested by `+formats_x25519_sodium+`, `+formats_25519_openssl_oracle+`, `+formats_25519_webcrypto_oracle+`, `+allocation_sodium+`) |=== A call that names no backend takes the family's default on each target, whatever the program links, as <> gives it with its reasons and tests: diff --git a/doc/generated/backends-tweak.adoc b/doc/generated/backends-xonly_public_key.adoc similarity index 85% rename from doc/generated/backends-tweak.adoc rename to doc/generated/backends-xonly_public_key.adoc index bd3035f0..1d83cb8f 100644 --- a/doc/generated/backends-tweak.adoc +++ b/doc/generated/backends-xonly_public_key.adoc @@ -7,7 +7,7 @@ // Generated by doc/tables/generate.py from doc/tables/crypto.json, the test Jamfiles, // the message tests and the Jamfile fixtures: run it again, never edit this file. -The backends of `+curves::secp256k1::tweak_xonly+`, from the test programs that run it: +The backends of `+curves::secp256k1::xonly_public_key+`, `+tweaked_xonly_key+`, from the test programs that run it: [cols="1,2,2,4",options="header"] |=== @@ -16,7 +16,7 @@ The backends of `+curves::secp256k1::tweak_xonly+`, from the test programs that |libsecp256k1 |`+/third_party//secp256k1+` |`++` -|native, wasip2, wasip3, emscripten (tested by `+secp256k1_xonly_tweak+`) +|native, wasip2, wasip3, emscripten (tested by `+secp256k1_xonly_key+`, `+secp256k1_xonly_tweak+`) |=== A call that names no backend takes the family's default on each target, whatever the program links, as <> gives it with its reasons and tests: diff --git a/doc/generated/constant-time.adoc b/doc/generated/constant-time.adoc index 7725ce01..0fd9a274 100644 --- a/doc/generated/constant-time.adoc +++ b/doc/generated/constant-time.adoc @@ -12,8 +12,8 @@ |Backend |By design |Measured, native |Measured, wasip2 |Measured, wasip3 |Measured, emscripten |BearSSL -|by design: `+aes_ct64+` and `+ghash_ctmul64+`, or AES-NI and PCLMUL where the CPU has them; on a 32-bit host a 64-bit multiplication may not be constant time, which BearSSL documents; ECDSA signing with webcpp's fix, since upstream's decoding of the RFC 6979 nonce branches on its bit length (link:https://www.bearssl.org/gitweb/?p=BearSSL;a=blob;f=src/ec/ecdsa_i31_bits.c;hb=7bea48e5e850ab4cafbe68d3765cdaba13a86d6f#l44[BearSSL's ecdsa_i31_bits.c at upstream 7bea48e, lines 44 and 45: the nonce decoded with its actual bit length in the integer's header, then shifted over the words that length needs]; link:https://minerva.crocs.fi.muni.cz/[Minerva: the leak of an ECDSA nonce's bit length through timing, and the lattice that recovers the key (CVE-2019-15809)]; the fix: link:https://github.com/webcpporg/bearssl/commit/32381d6e787a32cbb7a687246349200d78b8ff7c[webcpporg/bearssl, commit 32381d6 on its branch webcpp: the header set back to the order's length before the shift, in ecdsa_i31_bits.c and ecdsa_i15_bits.c]); link:https://www.bearssl.org/constanttime.html[BearSSL, constant-time crypto]; link:https://www.bearssl.org/ctmul.html[BearSSL, constant-time multiplications] -|Valgrind's memcheck (Linux): AES-GCM, ChaCha20-Poly1305, P-256 (the key pair's making, `+sign+` of a digest (`+crypto::prehashed+`), which makes its signature low S without a branch, then `+normalize_low_s+` and `+is_low_s+` on it, `+agree+` and `+decode_pkcs8+`; BearSSL's own branches on its signing's verdicts listed in `+bearssl_verdicts.supp+`; nothing found with webcpp's fix to BearSSL's decoding of the nonce, whose leak of the nonce's bit length this checker found on 2026-11-21, including `+sign+` with its low-S step (Valgrind 3.22, arm64 Linux container, 2026-11-22)); MemorySanitizer (Linux, clang): AES-GCM, ChaCha20-Poly1305, P-256 (the same paths as memcheck's; for the previous signing, found the same leak, nothing after the fix, including `+sign+` with its low-S step (clang 18, arm64 Linux container, 2026-11-22)); dudect (judged; on a runner GitHub hosts, by two of three runs): AES-GCM, ChaCha20-Poly1305, P-256 (`+sign+` of a digest and `+agree+`, each against the key pair's scalar; `+sign+` with its low-S step judged constant time, \|t\| 1.70 on Linux and 1.63 natively on an Apple M5 Max (release, one run each, 2026-11-22; provisional, measured again in the final quiet pass)) +|by design: `+aes_ct64+` and `+ghash_ctmul64+`, or AES-NI and PCLMUL where the CPU has them; on a 32-bit host a 64-bit multiplication may not be constant time, which BearSSL documents; ECDSA signing at webcpp's pin, whose patch submitted upstream closes upstream's leak of the RFC 6979 nonce's bit length (link:https://www.bearssl.org/gitweb/?p=BearSSL;a=blob;f=src/ec/ecdsa_i31_bits.c;hb=7bea48e5e850ab4cafbe68d3765cdaba13a86d6f#l44[BearSSL's ecdsa_i31_bits.c at upstream 7bea48e, lines 44 and 45: the nonce decoded with its actual bit length in the integer's header, then shifted over the words that length needs]; link:https://minerva.crocs.fi.muni.cz/[Minerva: the leak of an ECDSA nonce's bit length through timing, and the lattice that recovers the key (CVE-2019-15809)]; the patch: link:https://github.com/webcpporg/bearssl/commit/ae63032d9f30bf53674db5445875adf71b8626b7[webcpporg/bearssl, commit ae63032 on its branch upstream/ecdsa-bits2int-constant-time, webcpp's pin: upstream 7bea48e plus exactly the patch submitted upstream, br_ecdsa_i31_bits2int and br_ecdsa_i15_bits2int setting the integer's header, before the right shift, to the larger of the decoded bit length and the order's, both public; the pin returns to upstream once upstream applies it]); link:https://www.bearssl.org/constanttime.html[BearSSL, constant-time crypto]; link:https://www.bearssl.org/ctmul.html[BearSSL, constant-time multiplications] +|Valgrind's memcheck (Linux): AES-GCM, ChaCha20-Poly1305, P-256 (the key pair's making, `+sign+` of a digest (`+crypto::signing_schemes::prehashed+`), which makes its signature low S without a branch, then `+low_s()+` and `+is_low_s()+` of it, `+agree+` and the private formats, `+pkcs8+`, `+raw+` and `+pem(pkcs8)+` both ways; BearSSL's own branches on its signing's verdicts listed in `+bearssl_verdicts.supp+`; nothing found at webcpp's pin ae63032, whose patch submitted upstream closes upstream's leak of the nonce's bit length in `+sign+` that this checker found on 2026-11-21, `+sign+` with its low-S step included (Valgrind 3.22, arm64 Linux container, 2026-12-02)); MemorySanitizer (Linux, clang): AES-GCM, ChaCha20-Poly1305, P-256 (the same paths as memcheck's; the same leak in `+sign+` on 2026-11-21 on upstream's BearSSL, nothing at webcpp's pin ae63032, `+sign+` with its low-S step included (clang 18, arm64 Linux container, 2026-12-02)); dudect (judged; on a runner GitHub hosts, by two of three runs): AES-GCM, ChaCha20-Poly1305, P-256 (`+sign+` of a digest and `+agree+`, each against the key pair's scalar; `+sign+` with its low-S step judged constant time, \|t\| 1.70 on Linux and 1.63 natively on an Apple M5 Max (release, one run each, 2026-11-22; provisional, measured again in the final quiet pass)) |dudect (judged; on a runner GitHub hosts, by two of three runs): AES-GCM, ChaCha20-Poly1305, P-256 (`+sign+` of a digest and `+agree+`, each against the key pair's scalar; `+sign+` with its low-S step judged constant time, \|t\| 1.70 on Linux and 1.63 natively on an Apple M5 Max (release, one run each, 2026-11-22; provisional, measured again in the final quiet pass)) |not measured yet |not measured yet diff --git a/doc/generated/default-aliases.adoc b/doc/generated/default-aliases.adoc index 2695b74d..6964eb63 100644 --- a/doc/generated/default-aliases.adoc +++ b/doc/generated/default-aliases.adoc @@ -41,11 +41,6 @@ |`+/third_party//sodium+` on every target |<> -|`+/webcpp/crypto//pem-default+` -|PEM -|`+/third_party//sodium+` on every target -|<> - |`+/webcpp/crypto//chacha20_poly1305-default+` |ChaCha20-Poly1305 |`+/third_party//sodium+` on every target diff --git a/doc/generated/defaults.adoc b/doc/generated/defaults.adoc index 20318d22..62a2f9d0 100644 --- a/doc/generated/defaults.adoc +++ b/doc/generated/defaults.adoc @@ -62,7 +62,7 @@ |Ed25519 |native, wasip2, wasip3, emscripten |libsodium -|the only backend in this version, on every target, and its verification is the policy `strict` (link:https://doc.libsodium.org/public-key_cryptography/public-key_signatures[libsodium's documentation, public-key signatures]; link:https://www.rfc-editor.org/rfc/rfc8032[RFC 8032, the Edwards-curve Digital Signature Algorithm (EdDSA)]) +|the only backend in this version, on every target, and its verification is the policy `canonical` (link:https://doc.libsodium.org/public-key_cryptography/public-key_signatures[libsodium's documentation, public-key signatures]; link:https://www.rfc-editor.org/rfc/rfc8032[RFC 8032, the Edwards-curve Digital Signature Algorithm (EdDSA)]) |`+ed25519_sodium+`, `+default_backend_none_linked+` |X25519 @@ -77,12 +77,6 @@ |the only backend that has it: libsodium's own construction, whose session keys only another `crypto_kx` derives (link:https://doc.libsodium.org/key_exchange[libsodium's documentation, key exchange]) |`+kx_sodium+`, `+default_backend_none_linked+` -|PEM -|native, wasip2, wasip3, emscripten -|libsodium -|the only backend in this version, on every target; its base64 runs in a time that does not depend on the bytes, a private key's in a PKCS#8 (link:https://doc.libsodium.org/helpers#base64-encoding-decoding[libsodium's documentation, helpers: base64 encoding and decoding]) -|`+formats_25519_sodium+`, `+default_backend_none_linked+` - |ChaCha20-Poly1305 |native, wasip2, wasip3, emscripten |libsodium diff --git a/doc/generated/ed25519-cases.adoc b/doc/generated/ed25519-cases.adoc index 9cb99e4f..01e416a4 100644 --- a/doc/generated/ed25519-cases.adoc +++ b/doc/generated/ed25519-cases.adoc @@ -9,7 +9,7 @@ [cols="1,5,2,2,2",options="header"] |=== -|Case |What it tests |libsodium, raw |libsodium, strict |WebCrypto in node 26.13.0 (OpenSSL 4.1.0), outside view +|Case |What it tests |libsodium, raw |libsodium, canonical |WebCrypto in node 26.13.0 (OpenSSL 4.1.0), outside view |0 |`+S+` = 0, `+A+` and `+R+` of small order diff --git a/doc/generated/formats.adoc b/doc/generated/formats.adoc new file mode 100644 index 00000000..4a920cc1 --- /dev/null +++ b/doc/generated/formats.adoc @@ -0,0 +1,125 @@ +// Copyright (c) 2026 WebCpp.org +// +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +// Generated by doc/tables/generate.py from doc/tables/crypto.json, the test Jamfiles, +// the message tests and the Jamfile fixtures: run it again, never edit this file. + +[options="header"] +|=== +|Type |raw |spki |pem(spki) |pkcs8 |pem(pkcs8) |der + +|`+ed25519::public_key+` +|32 +|44 +|113 +|- +|- +|- + +|`+x25519::public_key+` +|32 +|44 +|113 +|- +|- +|- + +|`+p256::basic_public_key+` +|65; `+compressed+` 33; `+uncompressed+` 65 +|91; `+compressed+` 59; `+uncompressed+` 91 +|178; `+compressed+` 134; `+uncompressed+` 178 +|- +|- +|- + +|`+secp256k1::public_key+` +|65; `+compressed+` 33; `+uncompressed+` 65; `+xonly+` 32 (encode only) +|88; `+compressed+` 56; `+uncompressed+` 88 +|174; `+compressed+` 130; `+uncompressed+` 174 +|- +|- +|- + +|`+secp256k1::xonly_public_key+` +|32; `+xonly+` 32 +|- +|- +|- +|- +|- + +|`+ed25519::basic_keypair+` +|32, secret +|- +|- +|48, secret +|119, secret +|- + +|`+x25519::basic_keypair+` +|32, secret +|- +|- +|48, secret +|119, secret +|- + +|`+p256::basic_keypair+` +|32, secret +|- +|- +|138, secret +|241, secret +|- + +|`+secp256k1::basic_keypair+` +|32, secret +|- +|- +|135, secret +|237, secret +|- + +|`+p256::ecdsa_signature+` +|64 +|- +|- +|- +|- +|8 to 72 + +|`+secp256k1::ecdsa_signature+` +|64 +|- +|- +|- +|- +|8 to 72 + +|`+secp256k1::recoverable_signature+` +|65 +|- +|- +|- +|- +|- + +|`+secp256k1::schnorr_signature+` +|64 +|- +|- +|- +|- +|- + +|`+ed25519::signature+` +|64 +|- +|- +|- +|- +|- +|=== diff --git a/doc/generated/jamfiles.adoc b/doc/generated/jamfiles.adoc index 3452cd14..dd77af3d 100644 --- a/doc/generated/jamfiles.adoc +++ b/doc/generated/jamfiles.adoc @@ -231,22 +231,6 @@ It prints: include::{webcpp-root}/tools/test/fixtures/crypto_jamfiles/p256_default/p256_default.outcome[tag=output] ---- -`+pem_default+`:: RFC 8410's Ed25519 public key read from PEM and armoured again to the same text on PEM's default on every target, with the one line `+/webcpp/crypto//pem-default+`, which links libsodium. -+ -Its Jamfile, built and run on native, wasip2, wasip3, emscripten: -+ -[listing] ----- -include::{webcpp-root}/tools/test/fixtures/crypto_jamfiles/pem_default/Jamfile[tag=jamfile] ----- -+ -It prints: -+ -[listing] ----- -include::{webcpp-root}/tools/test/fixtures/crypto_jamfiles/pem_default/pem_default.outcome[tag=output] ----- - `+sealed_box_default+`:: A message sealed to Bob's public key and opened with his key pair on the default on every target, with the one line `+/webcpp/crypto//sealed_box-default+`, which links libsodium. + Its Jamfile, built and run on native, wasip2, wasip3, emscripten: diff --git a/doc/generated/matrix.adoc b/doc/generated/matrix.adoc index 0d59f2c1..c3288210 100644 --- a/doc/generated/matrix.adoc +++ b/doc/generated/matrix.adoc @@ -84,22 +84,22 @@ |`+curves::secp256k1::keypair+` |libsecp256k1 |native, wasip2, wasip3, emscripten -|`+secp256k1+`, `+secp256k1_generate+`, `+secp256k1_bip340+`, `+secp256k1_xonly_tweak+`, `+secp256k1_ecdh+`, `+secp256k1_recovery+` +|`+secp256k1+`, `+secp256k1_generate+`, `+secp256k1_bip340+`, `+secp256k1_xonly_tweak+`, `+secp256k1_xonly_key+`, `+secp256k1_ecdh+`, `+secp256k1_recovery+` |`+crypto::verify+`, `+curves::secp256k1::recover+` |libsecp256k1 |native, wasip2, wasip3, emscripten -|`+secp256k1_bip340+`, `+secp256k1_wycheproof+`, `+secp256k1_recovery+`, `+signing_curves+` +|`+secp256k1_bip340+`, `+secp256k1_xonly_key+`, `+secp256k1_wycheproof+`, `+secp256k1_recovery+`, `+signing_curves+` -|`+curves::secp256k1::to_der+`, `+from_der+`, `+normalize_low_s+`, `+is_low_s+` +|`+curves::secp256k1::ecdsa_signature::is_low_s+`, `+low_s; recoverable_signature::is_low_s+`, `+low_s+` |libsecp256k1 |native, wasip2, wasip3, emscripten |`+secp256k1_der+` -|`+curves::secp256k1::tweak_xonly+` +|`+curves::secp256k1::xonly_public_key+`, `+tweaked_xonly_key+` |libsecp256k1 |native, wasip2, wasip3, emscripten -|`+secp256k1_xonly_tweak+` +|`+secp256k1_xonly_key+`, `+secp256k1_xonly_tweak+` |`+openssl_memory_resource+`, `+backends::openssl::install_memory_functions+` |OpenSSL @@ -151,20 +151,15 @@ |native, wasip2, wasip3, emscripten |`+x25519_sodium+`, `+oracle_25519+` -|`+curves::ed25519::encode_spki+`, `+decode_spki+`, `+encode_pkcs8+`, `+decode_pkcs8+` +|`+crypto::encode+`, `+crypto::decode+`, `+curves::ed25519::public_key::encode+`, `+curves::ed25519::public_key::decode+`, `+curves::ed25519::keypair::encode+`, `+curves::ed25519::keypair::decode+`, `+curves::ed25519::signature::encode+`, `+curves::ed25519::signature::decode+` |libsodium |native, wasip2, wasip3, emscripten -|`+formats_25519_sodium+`, `+formats_25519_openssl_oracle+`, `+formats_25519_webcrypto_oracle+`, `+allocation_sodium+` +|`+formats_ed25519_sodium+`, `+formats_25519_openssl_oracle+`, `+formats_25519_webcrypto_oracle+`, `+allocation_sodium+` -|`+curves::x25519::encode_spki+`, `+decode_spki+`, `+encode_pkcs8+`, `+decode_pkcs8+` +|`+crypto::encode+`, `+crypto::decode+`, `+curves::x25519::public_key::encode+`, `+curves::x25519::public_key::decode+`, `+curves::x25519::keypair::encode+`, `+curves::x25519::keypair::decode+` |libsodium |native, wasip2, wasip3, emscripten -|`+formats_25519_sodium+`, `+formats_25519_openssl_oracle+`, `+formats_25519_webcrypto_oracle+`, `+allocation_sodium+` - -|`+pem::armour+`, `+pem::unarmour+` -|libsodium -|native, wasip2, wasip3, emscripten -|`+formats_25519_sodium+`, `+formats_25519_openssl_oracle+`, `+allocation_sodium+`, `+p256_formats_bearssl+` +|`+formats_x25519_sodium+`, `+formats_25519_openssl_oracle+`, `+formats_25519_webcrypto_oracle+`, `+allocation_sodium+` |`+key_exchange::kx_keypair+` |libsodium @@ -241,10 +236,10 @@ |native, wasip2, wasip3, emscripten |`+secp256k1_tweak+` -|`+curves::secp256k1::encode_spki+`, `+decode_spki+`, `+encode_pkcs8+`, `+decode_pkcs8+` +|`+crypto::encode+`, `+crypto::decode+`, `+curves::secp256k1::public_key::encode+`, `+curves::secp256k1::public_key::decode+`, `+curves::secp256k1::xonly_public_key::encode+`, `+curves::secp256k1::xonly_public_key::decode+`, `+curves::secp256k1::keypair::encode+`, `+curves::secp256k1::keypair::decode (also with a std::pmr::memory_resource)+`, `+curves::secp256k1::ecdsa_signature::encode+`, `+curves::secp256k1::ecdsa_signature::decode+`, `+curves::secp256k1::recoverable_signature::encode+`, `+curves::secp256k1::recoverable_signature::decode+`, `+curves::secp256k1::schnorr_signature::encode+`, `+curves::secp256k1::schnorr_signature::decode+` |libsecp256k1 |native, wasip2, wasip3, emscripten -|`+secp256k1_formats+`, `+secp256k1_formats_openssl+` +|`+secp256k1_formats+`, `+secp256k1_formats_openssl+`, `+secp256k1_node_oracle+`, `+secp256k1_der+`, `+secp256k1_allocation+` |`+curves::secp256k1::ellswift_encode+`, `+ellswift_decode+`, `+ellswift_create+`, `+ellswift_xdh+` |libsecp256k1 @@ -281,12 +276,12 @@ |refused at compile time |`+p256_on_sodium+` -|`+curves::p256::keypair::sign; crypto::verify+`, `+to_der+`, `+from_der+`, `+normalize_low_s+`, `+is_low_s+` +|`+curves::p256::keypair::sign; crypto::verify; ecdsa_signature::is_low_s+`, `+low_s+` |BearSSL |native, wasip2, wasip3, emscripten |`+p256_ecdsa_bearssl+`, `+p256_wycheproof_bearssl+`, `+p256_openssl_oracle+`, `+p256_webcrypto_oracle+`, `+allocation_bearssl+` -|`+curves::p256::keypair::sign; crypto::verify+`, `+to_der+`, `+from_der+`, `+normalize_low_s+`, `+is_low_s+` +|`+curves::p256::keypair::sign; crypto::verify; ecdsa_signature::is_low_s+`, `+low_s+` |libsodium |refused at compile time |`+p256_on_sodium+` @@ -301,12 +296,12 @@ |refused at compile time |`+p256_on_sodium+` -|`+curves::p256::encode_spki+`, `+decode_spki+`, `+encode_pkcs8+`, `+decode_pkcs8+` +|`+crypto::encode+`, `+crypto::decode+`, `+curves::p256::public_key::encode+`, `+curves::p256::public_key::decode+`, `+curves::p256::keypair::encode+`, `+curves::p256::keypair::decode+`, `+curves::p256::ecdsa_signature::encode+`, `+curves::p256::ecdsa_signature::decode+` |BearSSL |native, wasip2, wasip3, emscripten |`+p256_formats_bearssl+`, `+p256_openssl_oracle+`, `+p256_webcrypto_oracle+`, `+allocation_bearssl+` -|`+curves::p256::encode_spki+`, `+decode_spki+`, `+encode_pkcs8+`, `+decode_pkcs8+` +|`+crypto::encode+`, `+crypto::decode+`, `+curves::p256::public_key::encode+`, `+curves::p256::public_key::decode+`, `+curves::p256::keypair::encode+`, `+curves::p256::keypair::decode+`, `+curves::p256::ecdsa_signature::encode+`, `+curves::p256::ecdsa_signature::decode+` |libsodium |refused at compile time |`+p256_on_sodium+` @@ -378,13 +373,13 @@ The same, by target: the backends each operation runs on. |libsecp256k1 |libsecp256k1 -|`+curves::secp256k1::to_der+`, `+from_der+`, `+normalize_low_s+`, `+is_low_s+` +|`+curves::secp256k1::ecdsa_signature::is_low_s+`, `+low_s; recoverable_signature::is_low_s+`, `+low_s+` |libsecp256k1 |libsecp256k1 |libsecp256k1 |libsecp256k1 -|`+curves::secp256k1::tweak_xonly+` +|`+curves::secp256k1::xonly_public_key+`, `+tweaked_xonly_key+` |libsecp256k1 |libsecp256k1 |libsecp256k1 @@ -438,19 +433,13 @@ The same, by target: the backends each operation runs on. |libsodium |libsodium -|`+curves::ed25519::encode_spki+`, `+decode_spki+`, `+encode_pkcs8+`, `+decode_pkcs8+` -|libsodium -|libsodium -|libsodium -|libsodium - -|`+curves::x25519::encode_spki+`, `+decode_spki+`, `+encode_pkcs8+`, `+decode_pkcs8+` +|`+crypto::encode+`, `+crypto::decode+`, `+curves::ed25519::public_key::encode+`, `+curves::ed25519::public_key::decode+`, `+curves::ed25519::keypair::encode+`, `+curves::ed25519::keypair::decode+`, `+curves::ed25519::signature::encode+`, `+curves::ed25519::signature::decode+` |libsodium |libsodium |libsodium |libsodium -|`+pem::armour+`, `+pem::unarmour+` +|`+crypto::encode+`, `+crypto::decode+`, `+curves::x25519::public_key::encode+`, `+curves::x25519::public_key::decode+`, `+curves::x25519::keypair::encode+`, `+curves::x25519::keypair::decode+` |libsodium |libsodium |libsodium @@ -528,7 +517,7 @@ The same, by target: the backends each operation runs on. |libsecp256k1 |libsecp256k1 -|`+curves::secp256k1::encode_spki+`, `+decode_spki+`, `+encode_pkcs8+`, `+decode_pkcs8+` +|`+crypto::encode+`, `+crypto::decode+`, `+curves::secp256k1::public_key::encode+`, `+curves::secp256k1::public_key::decode+`, `+curves::secp256k1::xonly_public_key::encode+`, `+curves::secp256k1::xonly_public_key::decode+`, `+curves::secp256k1::keypair::encode+`, `+curves::secp256k1::keypair::decode (also with a std::pmr::memory_resource)+`, `+curves::secp256k1::ecdsa_signature::encode+`, `+curves::secp256k1::ecdsa_signature::decode+`, `+curves::secp256k1::recoverable_signature::encode+`, `+curves::secp256k1::recoverable_signature::decode+`, `+curves::secp256k1::schnorr_signature::encode+`, `+curves::secp256k1::schnorr_signature::decode+` |libsecp256k1 |libsecp256k1 |libsecp256k1 @@ -564,7 +553,7 @@ The same, by target: the backends each operation runs on. |BearSSL |BearSSL -|`+curves::p256::keypair::sign; crypto::verify+`, `+to_der+`, `+from_der+`, `+normalize_low_s+`, `+is_low_s+` +|`+curves::p256::keypair::sign; crypto::verify; ecdsa_signature::is_low_s+`, `+low_s+` |BearSSL |BearSSL |BearSSL @@ -576,7 +565,7 @@ The same, by target: the backends each operation runs on. |BearSSL |BearSSL -|`+curves::p256::encode_spki+`, `+decode_spki+`, `+encode_pkcs8+`, `+decode_pkcs8+` +|`+crypto::encode+`, `+crypto::decode+`, `+curves::p256::public_key::encode+`, `+curves::p256::public_key::decode+`, `+curves::p256::keypair::encode+`, `+curves::p256::keypair::decode+`, `+curves::p256::ecdsa_signature::encode+`, `+curves::p256::ecdsa_signature::decode+` |BearSSL |BearSSL |BearSSL diff --git a/doc/generated/messages.adoc b/doc/generated/messages.adoc index 16a097ff..7e7fde7c 100644 --- a/doc/generated/messages.adoc +++ b/doc/generated/messages.adoc @@ -163,21 +163,21 @@ The fix: Name a native backend, such as `+backends::sodium+`, for `+async_seal+` |`+async_sign_ed25519_prehashed+` |native, wasip2, wasip3 -|`+webcpp::crypto: crypto::eddsa signs the message itself (RFC 8032's pure Ed25519) and takes no digest; a message's SHA-512 is signed with crypto::eddsa_prehashed (Ed25519ph).+` +|`+webcpp::crypto: crypto::signing_schemes::eddsa signs the message itself (RFC 8032's pure Ed25519) and takes no digest; a message's SHA-512 is signed with crypto::signing_schemes::eddsa_prehashed (Ed25519ph).+` -The fix: Give `+async_sign+` the message itself with `+crypto::eddsa+`, RFC 8032's pure Ed25519, which takes no digest, as the synchronous `+sign+` does; a message's SHA-512 is signed with `+crypto::eddsa_prehashed+` (Ed25519ph), on a native backend. +The fix: Give `+async_sign+` the message itself with `+crypto::signing_schemes::eddsa+`, RFC 8032's pure Ed25519, which takes no digest, as the synchronous `+sign+` does; a message's SHA-512 is signed with `+crypto::signing_schemes::eddsa_prehashed+` (Ed25519ph), on a native backend. |`+async_sign_eddsa_prehashed_asynchronous_backend+` |native, wasip2, wasip3 -|`+webcpp::crypto: WebCrypto has no Ed25519ph: crypto::eddsa_prehashed's sign, verify, async_sign and async_verify run on a native backend.+` +|`+webcpp::crypto: WebCrypto has no Ed25519ph: crypto::signing_schemes::eddsa_prehashed's sign, verify, async_sign and async_verify run on a native backend.+` -The fix: As `+sign_eddsa_prehashed_asynchronous_backend+`: `+async_sign+` under `+crypto::eddsa_prehashed+` runs on a native backend. +The fix: As `+sign_eddsa_prehashed_asynchronous_backend+`: `+async_sign+` under `+crypto::signing_schemes::eddsa_prehashed+` runs on a native backend. |`+async_sign_p256_eddsa+` |native, wasip2, wasip3 -|`+webcpp::crypto: async_sign: this key pair does not sign with this scheme: an Ed25519 key pair signs with crypto::eddsa or crypto::eddsa_prehashed, a P-256 key pair with crypto::ecdsa_sha256.+` +|`+webcpp::crypto: async_sign: this key pair does not sign with this scheme: an Ed25519 key pair signs with crypto::signing_schemes::eddsa or crypto::signing_schemes::eddsa_prehashed, a P-256 key pair with crypto::signing_schemes::ecdsa_sha256.+` -The fix: Give `+async_sign+` the key pair's own scheme: `+crypto::ecdsa_sha256+` for a P-256 key pair, `+crypto::eddsa+` or `+crypto::eddsa_prehashed+` for an Ed25519 key pair. +The fix: Give `+async_sign+` the key pair's own scheme: `+crypto::signing_schemes::ecdsa_sha256+` for a P-256 key pair, `+crypto::signing_schemes::eddsa+` or `+crypto::signing_schemes::eddsa_prehashed+` for an Ed25519 key pair. |`+async_sign_secp256k1+` |native, wasip2, wasip3 @@ -193,21 +193,21 @@ The fix: As `+sign_x25519+`: give `+async_sign+` an Ed25519 key pair, which sign |`+async_verify_eddsa_bytes_key+` |native, wasip2, wasip3 -|`+webcpp::crypto: async_verify takes crypto::eddsa or crypto::eddsa_prehashed with a curves::ed25519::public_key or crypto::ecdsa_sha256 with a curves::p256::basic_public_key, the algorithms WebCrypto has: call crypto::verify for the others.+` +|`+webcpp::crypto: async_verify takes crypto::signing_schemes::eddsa or crypto::signing_schemes::eddsa_prehashed with a curves::ed25519::public_key or crypto::signing_schemes::ecdsa_sha256 with a curves::p256::basic_public_key, the algorithms WebCrypto has: call crypto::verify for the others.+` -The fix: Give `+async_verify+` with `+crypto::eddsa+` the public key as a `+curves::ed25519::public_key+`, as `+crypto::verify+` takes it: `+key_pair.public_key()+`, or `+curves::ed25519::public_key::from_bytes(bytes)+`. +The fix: Give `+async_verify+` with `+crypto::signing_schemes::eddsa+` the public key as a `+curves::ed25519::public_key+`, as `+crypto::verify+` takes it: `+key_pair.public_key()+`, or `+curves::ed25519::public_key::from_bytes(bytes)+`. |`+async_verify_eddsa_prehashed_asynchronous_backend+` |native, wasip2, wasip3 -|`+webcpp::crypto: WebCrypto has no Ed25519ph: crypto::eddsa_prehashed's sign, verify, async_sign and async_verify run on a native backend.+` +|`+webcpp::crypto: WebCrypto has no Ed25519ph: crypto::signing_schemes::eddsa_prehashed's sign, verify, async_sign and async_verify run on a native backend.+` -The fix: As `+verify_eddsa_prehashed_asynchronous_backend+`: `+async_verify+` under `+crypto::eddsa_prehashed+`, free and member, runs on a native backend. +The fix: As `+verify_eddsa_prehashed_asynchronous_backend+`: `+async_verify+` under `+crypto::signing_schemes::eddsa_prehashed+`, free and member, runs on a native backend. |`+async_verify_named_backend+` |native, wasip2, wasip3 -|`+webcpp::crypto: async_verify takes crypto::eddsa or crypto::eddsa_prehashed with a curves::ed25519::public_key or crypto::ecdsa_sha256 with a curves::p256::basic_public_key, the algorithms WebCrypto has: call crypto::verify for the others.+` +|`+webcpp::crypto: async_verify takes crypto::signing_schemes::eddsa or crypto::signing_schemes::eddsa_prehashed with a curves::ed25519::public_key or crypto::signing_schemes::ecdsa_sha256 with a curves::p256::basic_public_key, the algorithms WebCrypto has: call crypto::verify for the others.+` -The fix: As `+async_verify_wrong_key+`: naming the backend does not add a scheme; call `+crypto::verify+` for `+crypto::schnorr+` and secp256k1's keys. +The fix: As `+async_verify_wrong_key+`: naming the backend does not add a scheme; call `+crypto::verify+` for `+crypto::signing_schemes::schnorr+` and secp256k1's keys. |`+async_verify_p256_bytes_signature+` |native, wasip2, wasip3 @@ -215,11 +215,23 @@ The fix: As `+async_verify_wrong_key+`: naming the backend does not add a scheme The fix: As `+verify_p256_secp256k1_signature+`: make the 64 bytes received into a `+curves::p256::ecdsa_signature+` with `+from_bytes+`, then give it to `+async_verify+`. +|`+async_verify_secp256k1_without_policy+` +|native, wasip2, wasip3 +|`+webcpp::crypto: async_verify takes crypto::signing_schemes::eddsa or crypto::signing_schemes::eddsa_prehashed with a curves::ed25519::public_key or crypto::signing_schemes::ecdsa_sha256 with a curves::p256::basic_public_key, the algorithms WebCrypto has: call crypto::verify for the others.+` + +The fix: As `+async_verify_wrong_key+`: call `+crypto::verify(crypto::signing_schemes::ecdsa_sha256, crypto::verification_policies::low_s_only, signature, input, public_key)+` for a secp256k1 key, which the asynchronous family lacks. + +|`+async_verify_without_policy+` +|native, wasip2, wasip3 +|`+webcpp::crypto: verify takes a verification policy after the scheme: crypto::signing_schemes::ecdsa_sha256 on a P-256 key takes crypto::verification_policies::low_s_only or any_s.+` + +The fix: As `+verify_without_policy+`: `+async_verify(executor, crypto::signing_schemes::ecdsa_sha256, crypto::verification_policies::low_s_only, signature, input, public_key, token)+` for a signature crypto made, `+any_s+` for one a browser's WebCrypto or a passkey made, whose S may be high. + |`+async_verify_wrong_key+` |native, wasip2, wasip3 -|`+webcpp::crypto: async_verify takes crypto::eddsa or crypto::eddsa_prehashed with a curves::ed25519::public_key or crypto::ecdsa_sha256 with a curves::p256::basic_public_key, the algorithms WebCrypto has: call crypto::verify for the others.+` +|`+webcpp::crypto: async_verify takes crypto::signing_schemes::eddsa or crypto::signing_schemes::eddsa_prehashed with a curves::ed25519::public_key or crypto::signing_schemes::ecdsa_sha256 with a curves::p256::basic_public_key, the algorithms WebCrypto has: call crypto::verify for the others.+` -The fix: Call `+crypto::verify+` for a key the asynchronous family lacks (secp256k1's, Schnorr's x-only key): `+async_verify+` has a `+curves::ed25519::public_key+` with `+crypto::eddsa+` or `+crypto::eddsa_prehashed+` and a `+curves::p256::basic_public_key+` with `+crypto::ecdsa_sha256+`. +The fix: Call `+crypto::verify+` for a key the asynchronous family lacks (secp256k1's, Schnorr's x-only key): `+async_verify+` has a `+curves::ed25519::public_key+` with `+crypto::signing_schemes::eddsa+` or `+crypto::signing_schemes::eddsa_prehashed+` and a `+curves::p256::basic_public_key+` with `+crypto::signing_schemes::ecdsa_sha256+`. |`+bearssl_not_linked+` |native, wasip2 @@ -287,6 +299,24 @@ The fix: Call `+webcpp::secure::constant_time_equal+`, from `+>.+` @@ -299,12 +329,44 @@ The fix: Remove the define, and name `+gcm>+` where th The fix: Remove the define, and name `+gcm>+` where the program wants BearSSL. +|`+der_on_ed25519+` +|native, wasip2, wasip3 +|`+webcpp::crypto: Ed25519 and BIP340 signatures have no DER form; their 64 bytes are the signature+` + +The fix: Encode an Ed25519 signature with `+crypto::formats::raw+`, or its member `+signature.encode(crypto::formats::raw)+`: its 64 bytes are the signature, and it has no DER form. + +|`+der_on_recoverable+` +|native, wasip2, wasip3 +|`+webcpp::crypto: a recoverable signature has no DER form+` + +The fix: Encode a recoverable signature with `+crypto::formats::raw+`, its 65 bytes, r, s and the recovery id, or its member `+signature.encode(crypto::formats::raw)+`; it has no DER form. A Bitcoin script's DER is that of an `+ecdsa_signature+`: sign with `+crypto::signing_schemes::ecdsa_sha256+` and encode it in `+crypto::formats::der+`. + +|`+der_on_schnorr+` +|native, wasip2, wasip3 +|`+webcpp::crypto: Ed25519 and BIP340 signatures have no DER form; their 64 bytes are the signature+` + +The fix: Encode a BIP340 signature with `+crypto::formats::raw+`, or its member `+signature.encode(crypto::formats::raw)+`: its 64 bytes are the signature, and it has no DER form. + +|`+der_short_name_removed_p256+` +|native, wasip2, wasip3 +|`+no member named 'to_der' in namespace 'webcpp::crypto::curves::p256'+` + +`+no member named 'from_der' in namespace 'webcpp::crypto::curves::p256'+` + +The fix: Write a P-256 signature's DER with `+crypto::encode(crypto::formats::der, signature)+` or its member `+signature.encode(crypto::formats::der)+`, and read it with `+crypto::decode(crypto::formats::der, bytes)+`; the free `+to_der+` and `+from_der+` are gone, with no alias. + |`+ed25519_default_not_linked+` |native, wasip2, wasip3 |`+webcpp::crypto: Ed25519's default backend on this target is libsodium, which is not linked, and the one backend that has it there. Add /webcpp/crypto//ed25519-default, the default's library on every target, to the program's Jamfile, as in: exe app : app.cpp /webcpp/crypto//crypto /webcpp/crypto//ed25519-default ; (without b2: define WEBCPP_CRYPTO_HAS_SODIUM=1 and link libsodium built with webcpp's src/canary_sodium.c)+` The fix: Add `+/webcpp/crypto//ed25519-default+`, which links `+/third_party//sodium+` on every target. +|`+ed25519_formats_header_missing+` +|native, wasip2, wasip3 +|`+webcpp::crypto: include to encode or decode this type+` + +The fix: Include `++`, which registers Ed25519's formats, beside `++`. + |`+ed25519_on_bearssl+` |native, wasip2, wasip3 |`+webcpp::crypto: bearssl has no Ed25519. The backends that have it: sodium (native, wasip2, wasip3, emscripten).+` @@ -313,9 +375,9 @@ The fix: Leave the backend out, as in `+curves::ed25519::keypair+`, or name `+ba |`+ed25519_unknown_policy+` |native, wasip2, wasip3 -|`+webcpp::crypto: Ed25519's only verification policy is curves::ed25519::strict.+` +|`+webcpp::crypto: verify: crypto::signing_schemes::eddsa and eddsa_prehashed take crypto::verification_policies::canonical.+` -The fix: Leave the policy out, as in `+crypto::verify(crypto::eddsa, signature, message, public_key)+`, or name `+curves::ed25519::strict+`. +The fix: Name `+crypto::verification_policies::canonical+` after the scheme, Ed25519's only policy: `+crypto::verify(crypto::signing_schemes::eddsa, crypto::verification_policies::canonical, signature, message, public_key)+`. |`+ed25519ph_sha256+` |native, wasip2, wasip3 @@ -347,6 +409,30 @@ The fix: Call `+webcpp::secure::constant_time_equal+`, the same comparison of tw The fix: Call `+webcpp::secure::erase_secret+`, from `++`, the same erasure; `+crypto::erase_secret+` moved to webcpp::secure, with no alias. +|`+format_header_missing_toy+` +|native, wasip2, wasip3 +|`+webcpp::crypto: include to encode or decode this type+` + +The fix: Include the formats header of the type's curve, the one the assertion names, `+/formats.hpp>+`, beside the curve's own header, which declares no format. + +|`+format_refused_toy+` +|native, wasip2, wasip3 +|`+webcpp::crypto::detail::format_list, webcpp::crypto::formats::spki_t, webcpp::codecs::over, std::allocator>>>': webcpp::crypto: this type has no such format; the formats it has are the format_list named in this assertion+` + +The fix: Encode or decode a type in a format of its list, the `+format_list+` the assertion names: another type's format (`+der+` is an ECDSA signature's, `+pkcs8+` a key pair's) does not convert it. + +|`+format_without_header+` +|native, wasip2, wasip3 +|`+no member named 'spki' in namespace 'webcpp::crypto::formats'+` + +The fix: Include `++`, or the curve's `+/formats.hpp>+`, which includes it: `+crypto::formats+` is declared by `+config.hpp+` and filled by the formats headers alone. + +|`+forms_without_default+` +|native, wasip2, wasip3 +|`+webcpp::crypto: a forms_of specialization lists formats::default_form_t, the form of a format named without one+` + +The fix: List `+crypto::formats::default_form_t+` in each `+detail::forms_of+` specialization, with the other point forms the type accepts. + |`+gcm_default_openssl_not_linked+` |native |`+webcpp::crypto: AES-GCM's default backend on this target is OpenSSL, which is not linked. Add /webcpp/crypto//gcm-default, the default's library on every target, to the program's Jamfile, as in: exe app : app.cpp /webcpp/crypto//crypto /webcpp/crypto//gcm-default ; or name another backend in the type, as in ciphers::gcm>. The backends that have it: bearssl (native, wasip2, wasip3, emscripten), openssl (native, wasip2, wasip3). (without b2: define WEBCPP_CRYPTO_HAS_OPENSSL=1 and link libcrypto)+` @@ -393,6 +479,18 @@ The fix: Name `+crypto::public_key_encryption::box+`, `+box_xchacha20poly1305+` The fix: Name nonce_size, max_nonce_size and error::invalid_nonce_size: crypto spells its names out. +|`+keypair_decode_resource_from_text+` +|native, wasip2, wasip3 +|`+webcpp::crypto: a key pair decodes from bytes: a std::span, or what converts to one+` + +The fix: Give the key pair's decode with a memory resource bytes for `+crypto::formats::raw+` and `+crypto::formats::pkcs8+`, a `+std::span+` or what converts to one (`+std::array+`, `+std::vector+`, a result's `+view()+`); a PEM text decodes with `+crypto::formats::pem(crypto::formats::pkcs8)+`. + +|`+keypair_decode_resource_spki+` +|native, wasip2, wasip3 +|`+webcpp::crypto: this type has no such format; the formats it has are the format_list named in this assertion+` + +The fix: Decode a secp256k1 key pair, with or without a memory resource, from one of its formats: `+crypto::formats::raw+`, its secret key, `+crypto::formats::pkcs8+` or `+crypto::formats::pem(crypto::formats::pkcs8)+`; an SPKI holds a public key, which `+crypto::curves::secp256k1::public_key::decode(crypto::formats::spki, bytes)+` gives. + |`+kx_default_not_linked+` |native, wasip2, wasip3 |`+webcpp::crypto: crypto_kx's default backend on this target is libsodium, which is not linked, and the one backend that has it there. Add /webcpp/crypto//kx-default, the default's library on every target, to the program's Jamfile, as in: exe app : app.cpp /webcpp/crypto//crypto /webcpp/crypto//kx-default ; (without b2: define WEBCPP_CRYPTO_HAS_SODIUM=1 and link libsodium built with webcpp's src/canary_sodium.c)+` @@ -405,6 +503,12 @@ The fix: Add `+/webcpp/crypto//kx-default+`, which links `+/third_party//sodium+ The fix: Return `+std::optional>+`, a span over a tweak the lookup keeps, such as a map's entry; never the tweak by value. +|`+low_s_on_ed25519+` +|native, wasip2, wasip3 +|`+invalid reference to function 'low_s': constraints not satisfied+` + +The fix: Only an ECDSA signature has low S: Ed25519 and Schnorr signatures have no `+is_low_s()+` or `+low_s()+`, and need none, for no other S verifies as theirs. + |`+make_removed+` |native, wasip2, wasip3 |`+no member named 'make' in+` @@ -489,11 +593,35 @@ The fix: Add `+/webcpp/crypto//p256-default+`, which links `+/third_party//bears The fix: Leave the backend out, as in `+curves::p256::keypair+`, or name `+backends::bearssl+`, and add `+/third_party//bearssl+`. -|`+pem_default_not_linked+` +|`+pem_decode_from_bytes+` +|native, wasip2, wasip3 +|`+webcpp::crypto: a PEM decodes from a text: a std::string_view, or a contiguous range of char+` + +The fix: Give a PEM to `+crypto::decode+` as a text: a `+std::string_view+`, a `+std::string+`, or a contiguous range of `+char+` such as `+std::span+`; DER bytes decode with `+crypto::formats::spki+` or `+crypto::formats::pkcs8+` themselves. + +|`+pem_header_removed+` +|native, wasip2, wasip3 +|`+'webcpp/crypto/pem.hpp' file not found+` + +The fix: Write and read PEM with `+crypto::encode+` and `+crypto::decode+` and `+crypto::formats::pem(crypto::formats::spki)+` or `+crypto::formats::pem(crypto::formats::pkcs8)+`, in `++`, codecs' armor over the key's DER; `+pem.hpp+` is gone, with no header left at its path. + +|`+pem_namespace_removed+` +|native, wasip2, wasip3 +|`+no member named 'pem' in namespace 'webcpp::crypto'+` + +The fix: Write and read PEM with `+crypto::encode+` and `+crypto::decode+` and `+crypto::formats::pem(crypto::formats::spki)+` or `+crypto::formats::pem(crypto::formats::pkcs8)+`, which take the label from the inner format; `+crypto::pem+`, its `+armour+`, `+unarmour+`, labels and `+armoured_size+`, is gone, with no alias. + +|`+pem_of_der+` |native, wasip2, wasip3 -|`+webcpp::crypto: PEM's default backend on this target is libsodium, which is not linked, and the one backend that has it there. Add /webcpp/crypto//pem-default, the default's library on every target, to the program's Jamfile, as in: exe app : app.cpp /webcpp/crypto//crypto /webcpp/crypto//pem-default ; (without b2: define WEBCPP_CRYPTO_HAS_SODIUM=1 and link libsodium built with webcpp's src/canary_sodium.c)+` +|`+webcpp::crypto: PEM carries a DER key: pem(formats::spki) or pem(formats::pkcs8)+` -The fix: Add `+/webcpp/crypto//pem-default+`, which links `+/third_party//sodium+` on every target. +The fix: Armor the DER of a key: `+crypto::formats::pem(crypto::formats::spki)+` for a public key, `+crypto::formats::pem(crypto::formats::pkcs8)+` for a key pair; a signature's DER has no PEM. + +|`+pem_of_raw+` +|native, wasip2, wasip3 +|`+webcpp::crypto: PEM carries a DER key: pem(formats::spki) or pem(formats::pkcs8)+` + +The fix: As `+pem_of_der+`: armor the DER of a key, `+crypto::formats::pem(crypto::formats::spki)+` or `+crypto::formats::pem(crypto::formats::pkcs8)+`; a key's raw bytes have no PEM. |`+ph_removed+` |native, wasip2, wasip3 @@ -501,11 +629,29 @@ The fix: Add `+/webcpp/crypto//pem-default+`, which links `+/third_party//sodium The fix: Name Ed25519ph's streaming signer `+curves::ed25519::prehashed_signer+`, the same `+begin+`, `+update+`, `+sign+` and `+verify+`; `+curves::ed25519::ph+` is gone, with no alias. +|`+pkcs8_on_asynchronous_ed25519+` +|native, wasip2, wasip3 +|`+webcpp::crypto: this key pair's secret lives in WebCrypto: export it with WebCrypto's exportKey, which this backend does not offer synchronously+` + +The fix: Export the key pair with WebCrypto's `+exportKey+`, on the backend that keeps it, or make the key pair on a backend whose secret is in the program, libsodium, to encode it in `+crypto::formats::pkcs8+`, `+crypto::formats::raw+` or `+crypto::formats::pem(crypto::formats::pkcs8)+`; its public key's formats are available on every backend. + +|`+pkcs8_on_asynchronous_p256+` +|native, wasip2, wasip3 +|`+webcpp::crypto: this key pair's secret lives in WebCrypto: export it with WebCrypto's exportKey, which this backend does not offer synchronously+` + +The fix: Export the key pair with WebCrypto's `+exportKey+`, on the backend that keeps it, or make the key pair on a backend whose secret is in the program, BearSSL, to encode it in `+crypto::formats::pkcs8+`, `+crypto::formats::raw+` or `+crypto::formats::pem(crypto::formats::pkcs8)+`; its public key's formats are available on every backend. + |`+prehashed_dynamic+` |native, wasip2, wasip3 -|`+webcpp::crypto: crypto::prehashed takes a digest of a fixed size: a std::array or a std::span.+` +|`+webcpp::crypto: crypto::signing_schemes::prehashed takes a digest of a fixed size: a std::array or a std::span.+` + +The fix: Give `+crypto::signing_schemes::prehashed+` a digest of a fixed size: a `+std::array+`, a `+std::span+` or a `+boost::hash2::digest<32>+`. + +|`+prehashed_signer_verify_without_policy+` +|native, wasip2, wasip3 +|`+webcpp::crypto: curves::ed25519::prehashed_signer::verify takes a verification policy first: crypto::verification_policies::canonical.+` -The fix: Give `+crypto::prehashed+` a digest of a fixed size: a `+std::array+`, a `+std::span+` or a `+boost::hash2::digest<32>+`. +The fix: Name the policy first: `+signer.verify(crypto::verification_policies::canonical, signature, public_key)+`, Ed25519ph's only policy. |`+prevouts_summary_removed+` |native, wasip2 @@ -521,11 +667,47 @@ The fix: Name silent_payments::previous_outputs_summary and make_previous_output The fix: As `+prevouts_summary_removed+`. +|`+raw_on_asynchronous_x25519+` +|native, wasip2, wasip3 +|`+webcpp::crypto: this key pair's secret lives in WebCrypto: export it with WebCrypto's exportKey, which this backend does not offer synchronously+` + +The fix: Export the key pair with WebCrypto's `+exportKey+`, on the backend that keeps it, or make the key pair on a backend whose secret is in the program, libsodium, to read its secret with `+crypto::formats::raw+`, `+crypto::formats::pkcs8+` or `+crypto::formats::pem(crypto::formats::pkcs8)+`; its public key's formats are available on every backend. + +|`+recover_any_s+` +|native, wasip2, wasip3 +|`+webcpp::crypto: curves::secp256k1::recover takes crypto::verification_policies::low_s_only.+` + +The fix: Recover under `+crypto::verification_policies::low_s_only+`, its only policy: a signature whose S is high is refused before recovery; made low first, n - s with bit 0 of the recovery id flipped, it keeps its signer. + |`+recover_ecdsa_signature+` |native, wasip2, wasip3 |`+webcpp::crypto: recover takes a curves::secp256k1::recoverable_signature: make one from 65 bytes with curves::secp256k1::recoverable_signature::from_bytes.+` -The fix: Give `+recover+` a `+curves::secp256k1::recoverable_signature+`, which `+sign(crypto::ecdsa_sha256_recoverable, input)+` gives, or made from 65 bytes with `+from_bytes+`; an ECDSA signature without its recovery id verifies with `+crypto::verify+` and the signer's public key. +The fix: Give `+recover+` a `+curves::secp256k1::recoverable_signature+`, which `+sign(crypto::signing_schemes::ecdsa_sha256_recoverable, input)+` gives, or made from 65 bytes with `+from_bytes+`; an ECDSA signature without its recovery id verifies with `+crypto::verify+` and the signer's public key. + +|`+recover_ecdsa_without_policy+` +|native, wasip2, wasip3 +|`+webcpp::crypto: curves::secp256k1::recover takes crypto::signing_schemes::ecdsa_sha256_recoverable or crypto::signing_schemes::ecdsa_keccak256_recoverable, then crypto::verification_policies::low_s_only; another scheme's signature verifies with crypto::verify.+` + +The fix: Give `+recover+` a recoverable scheme and its policy, `+recover(crypto::signing_schemes::ecdsa_sha256_recoverable, crypto::verification_policies::low_s_only, signature, input)+` of a `+curves::secp256k1::recoverable_signature+`; an ECDSA signature without its recovery id verifies with `+crypto::verify+` and the signer's public key. + +|`+recover_without_policy+` +|native, wasip2, wasip3 +|`+webcpp::crypto: recover takes a verification policy after the scheme: curves::secp256k1::recover takes crypto::verification_policies::low_s_only.+` + +The fix: Name the policy after the scheme: `+curves::secp256k1::recover(crypto::signing_schemes::ecdsa_sha256_recoverable, crypto::verification_policies::low_s_only, signature, input)+`, its only policy. + +|`+refusal_reason_toy+` +|native, wasip2, wasip3 +|`+webcpp::crypto: Ed25519 and BIP340 signatures have no DER form; their 64 bytes are the signature+` + +The fix: Encode the signature with `+crypto::formats::raw+`: an Ed25519 or BIP340 signature has no DER form, its 64 bytes are the signature. + +|`+scheme_in_crypto_namespace+` +|native, wasip2, wasip3 +|`+no member named 'ecdsa_sha256' in namespace 'webcpp::crypto'+` + +The fix: Name the scheme in `+crypto::signing_schemes+`: `+crypto::signing_schemes::ecdsa_sha256+`; the tags are no longer in `+crypto+`, with no alias. |`+seal_asynchronous_backend+` |native, wasip2, wasip3 @@ -665,105 +847,105 @@ The fix: Call `+async_sign+` on a backend that completes by itself: its synchron |`+sign_ed25519_ecdsa+` |native, wasip2, wasip3 -|`+webcpp::crypto: an Ed25519 key signs with crypto::eddsa or crypto::eddsa_prehashed.+` +|`+webcpp::crypto: an Ed25519 key signs with crypto::signing_schemes::eddsa or crypto::signing_schemes::eddsa_prehashed.+` -The fix: Sign with `+crypto::eddsa+` or `+crypto::eddsa_prehashed+`, Ed25519's schemes; `+crypto::ecdsa_sha256+` is P-256's and secp256k1's. +The fix: Sign with `+crypto::signing_schemes::eddsa+` or `+crypto::signing_schemes::eddsa_prehashed+`, Ed25519's schemes; `+crypto::signing_schemes::ecdsa_sha256+` is P-256's and secp256k1's. |`+sign_ed25519_keccak+` |native, wasip2, wasip3 -|`+webcpp::crypto: an Ed25519 key signs with crypto::eddsa or crypto::eddsa_prehashed.+` +|`+webcpp::crypto: an Ed25519 key signs with crypto::signing_schemes::eddsa or crypto::signing_schemes::eddsa_prehashed.+` -The fix: Sign with `+crypto::eddsa+` or `+crypto::eddsa_prehashed+`, Ed25519's schemes; Ethereum's `+crypto::ecdsa_keccak256_recoverable+` is secp256k1's. +The fix: Sign with `+crypto::signing_schemes::eddsa+` or `+crypto::signing_schemes::eddsa_prehashed+`, Ed25519's schemes; Ethereum's `+crypto::signing_schemes::ecdsa_keccak256_recoverable+` is secp256k1's. |`+sign_ed25519_prehashed+` |native, wasip2, wasip3 -|`+webcpp::crypto: crypto::eddsa signs the message itself (RFC 8032's pure Ed25519) and takes no digest; a message's SHA-512 is signed with crypto::eddsa_prehashed (Ed25519ph).+` +|`+webcpp::crypto: crypto::signing_schemes::eddsa signs the message itself (RFC 8032's pure Ed25519) and takes no digest; a message's SHA-512 is signed with crypto::signing_schemes::eddsa_prehashed (Ed25519ph).+` -The fix: Sign the message itself with `+crypto::eddsa+`, RFC 8032's pure Ed25519, which takes no digest; to sign a message's SHA-512, use Ed25519ph, `+crypto::eddsa_prehashed+`, or for a message given in pieces `+curves::ed25519::prehashed_signer+`. +The fix: Sign the message itself with `+crypto::signing_schemes::eddsa+`, RFC 8032's pure Ed25519, which takes no digest; to sign a message's SHA-512, use Ed25519ph, `+crypto::signing_schemes::eddsa_prehashed+`, or for a message given in pieces `+curves::ed25519::prehashed_signer+`. |`+sign_eddsa_prehashed_asynchronous_backend+` |native, wasip2, wasip3 -|`+webcpp::crypto: WebCrypto has no Ed25519ph: crypto::eddsa_prehashed's sign, verify, async_sign and async_verify run on a native backend.+` +|`+webcpp::crypto: WebCrypto has no Ed25519ph: crypto::signing_schemes::eddsa_prehashed's sign, verify, async_sign and async_verify run on a native backend.+` -The fix: Sign under `+crypto::eddsa_prehashed+` with a key pair of a native backend: WebCrypto has no Ed25519ph; on the browser's backend, sign the message with `+crypto::eddsa+`. +The fix: Sign under `+crypto::signing_schemes::eddsa_prehashed+` with a key pair of a native backend: WebCrypto has no Ed25519ph; on the browser's backend, sign the message with `+crypto::signing_schemes::eddsa+`. |`+sign_eddsa_prehashed_digest_32+` |native, wasip2, wasip3 -|`+webcpp::crypto: crypto::eddsa_prehashed takes a 64-byte digest, SHA-512's: crypto::prehashed{digest} of a std::array.+` +|`+webcpp::crypto: crypto::signing_schemes::eddsa_prehashed takes a 64-byte digest, SHA-512's: crypto::signing_schemes::prehashed{digest} of a std::array.+` -The fix: Give `+crypto::eddsa_prehashed+` SHA-512's 64-byte digest, `+crypto::prehashed{digest}+` of a `+std::array+`: RFC 8032 defines Ed25519ph over SHA-512. +The fix: Give `+crypto::signing_schemes::eddsa_prehashed+` SHA-512's 64-byte digest, `+crypto::signing_schemes::prehashed{digest}+` of a `+std::array+`: RFC 8032 defines Ed25519ph over SHA-512. |`+sign_eddsa_prehashed_message+` |native, wasip2, wasip3 -|`+webcpp::crypto: crypto::eddsa_prehashed (RFC 8032's Ed25519ph) signs a digest, the message's SHA-512: crypto::prehashed{digest} of a std::array; sign the message itself with crypto::eddsa, or give it in pieces to curves::ed25519::prehashed_signer.+` +|`+webcpp::crypto: crypto::signing_schemes::eddsa_prehashed (RFC 8032's Ed25519ph) signs a digest, the message's SHA-512: crypto::signing_schemes::prehashed{digest} of a std::array; sign the message itself with crypto::signing_schemes::eddsa, or give it in pieces to curves::ed25519::prehashed_signer.+` -The fix: Give `+crypto::eddsa_prehashed+` the message's SHA-512 marked as a digest, `+crypto::prehashed{digest}+` of a `+std::array+`; sign the message itself with `+crypto::eddsa+`, or give it in pieces to `+curves::ed25519::prehashed_signer+`. +The fix: Give `+crypto::signing_schemes::eddsa_prehashed+` the message's SHA-512 marked as a digest, `+crypto::signing_schemes::prehashed{digest}+` of a `+std::array+`; sign the message itself with `+crypto::signing_schemes::eddsa+`, or give it in pieces to `+curves::ed25519::prehashed_signer+`. |`+sign_free_ed25519_ecdsa+` |native, wasip2, wasip3 -|`+webcpp::crypto: an Ed25519 key signs with crypto::eddsa or crypto::eddsa_prehashed.+` +|`+webcpp::crypto: an Ed25519 key signs with crypto::signing_schemes::eddsa or crypto::signing_schemes::eddsa_prehashed.+` -The fix: As `+sign_ed25519_ecdsa+`: `+crypto::sign+` calls the key pair's own `+sign+`, so sign with `+crypto::eddsa+` or `+crypto::eddsa_prehashed+`, Ed25519's schemes. +The fix: As `+sign_ed25519_ecdsa+`: `+crypto::sign+` calls the key pair's own `+sign+`, so sign with `+crypto::signing_schemes::eddsa+` or `+crypto::signing_schemes::eddsa_prehashed+`, Ed25519's schemes. |`+sign_free_public_key+` |native, wasip2, wasip3 |`+webcpp::crypto: sign: the first argument is a key pair, and the others are its sign's: crypto::sign(key_pair, scheme, input), and on secp256k1 its 32 bytes of extra entropy or auxiliary randomness after the input; a public key verifies, with crypto::verify.+` -The fix: Give `+crypto::sign+` the key pair, whose public key verifies: `+crypto::sign(key_pair, scheme, input)+`, then `+crypto::verify(scheme, signature, input, public_key)+` or `+public_key.verify(scheme, signature, input)+`. +The fix: Give `+crypto::sign+` the key pair, whose public key verifies: `+crypto::sign(key_pair, scheme, input)+`, then `+crypto::verify(scheme, policy, signature, input, public_key)+` or `+public_key.verify(scheme, policy, signature, input)+`. |`+sign_keccak_digest_20+` |native, wasip2, wasip3 -|`+webcpp::crypto: crypto::ecdsa_keccak256_recoverable takes a 32-byte digest, Keccak-256's: crypto::prehashed{digest} of a std::array.+` +|`+webcpp::crypto: crypto::signing_schemes::ecdsa_keccak256_recoverable takes a 32-byte digest, Keccak-256's: crypto::signing_schemes::prehashed{digest} of a std::array.+` -The fix: As `+sign_p256_digest_48+`: give `+crypto::ecdsa_keccak256_recoverable+` Keccak-256's 32-byte digest, or the message itself, which it hashes with Keccak-256. +The fix: As `+sign_p256_digest_48+`: give `+crypto::signing_schemes::ecdsa_keccak256_recoverable+` Keccak-256's 32-byte digest, or the message itself, which it hashes with Keccak-256. |`+sign_keccak_without_xkcp+` |native, wasip2, wasip3 -|`+webcpp::crypto: crypto::ecdsa_keccak256_recoverable hashes a message with webcpp::hash's keccak_256, which needs XKCP: add /third_party//xkcp to the program's Jamfile, or sign crypto::prehashed{digest}.+` +|`+webcpp::crypto: crypto::signing_schemes::ecdsa_keccak256_recoverable hashes a message with webcpp::hash's keccak_256, which needs XKCP: add /third_party//xkcp to the program's Jamfile, or sign crypto::signing_schemes::prehashed{digest}.+` -The fix: Add `+/third_party//xkcp+` to the program's Jamfile, whose Keccak-256 hashes the message, or build the 32-byte digest elsewhere and sign `+crypto::prehashed{digest}+`, which needs no XKCP. +The fix: Add `+/third_party//xkcp+` to the program's Jamfile, whose Keccak-256 hashes the message, or build the 32-byte digest elsewhere and sign `+crypto::signing_schemes::prehashed{digest}+`, which needs no XKCP. |`+sign_p256_digest_48+` |native, wasip2, wasip3 -|`+webcpp::crypto: crypto::ecdsa_sha256 takes a 32-byte digest, SHA-256's: crypto::prehashed{digest} of a std::array.+` +|`+webcpp::crypto: crypto::signing_schemes::ecdsa_sha256 takes a 32-byte digest, SHA-256's: crypto::signing_schemes::prehashed{digest} of a std::array.+` -The fix: Give `+crypto::ecdsa_sha256+` SHA-256's 32-byte digest, `+crypto::prehashed{digest}+` of a `+std::array+`, or the message itself, which it hashes. +The fix: Give `+crypto::signing_schemes::ecdsa_sha256+` SHA-256's 32-byte digest, `+crypto::signing_schemes::prehashed{digest}+` of a `+std::array+`, or the message itself, which it hashes. |`+sign_p256_keccak+` |native, wasip2, wasip3 -|`+webcpp::crypto: a P-256 key signs with crypto::ecdsa_sha256.+` +|`+webcpp::crypto: a P-256 key signs with crypto::signing_schemes::ecdsa_sha256.+` -The fix: Sign with `+crypto::ecdsa_sha256+`, P-256's scheme; Ethereum's `+crypto::ecdsa_keccak256_recoverable+` is secp256k1's. +The fix: Sign with `+crypto::signing_schemes::ecdsa_sha256+`, P-256's scheme; Ethereum's `+crypto::signing_schemes::ecdsa_keccak256_recoverable+` is secp256k1's. |`+sign_p256_schnorr+` |native, wasip2, wasip3 -|`+webcpp::crypto: a P-256 key signs with crypto::ecdsa_sha256.+` +|`+webcpp::crypto: a P-256 key signs with crypto::signing_schemes::ecdsa_sha256.+` -The fix: Sign with `+crypto::ecdsa_sha256+`, P-256's scheme; BIP340's `+crypto::schnorr+` is secp256k1's. +The fix: Sign with `+crypto::signing_schemes::ecdsa_sha256+`, P-256's scheme; BIP340's `+crypto::signing_schemes::schnorr+` is secp256k1's. |`+sign_schnorr_prehashed+` |native, wasip2, wasip3 -|`+webcpp::crypto: crypto::schnorr (BIP340) signs a message of any length and has no prehash mode: pass the message.+` +|`+webcpp::crypto: crypto::signing_schemes::schnorr (BIP340) signs a message of any length and has no prehash mode: pass the message.+` -The fix: Sign the message itself with `+crypto::schnorr+`, BIP340's, which has no prehash mode; a taproot sighash, BIP341's tagged hash, is that message. +The fix: Sign the message itself with `+crypto::signing_schemes::schnorr+`, BIP340's, which has no prehash mode; a taproot sighash, BIP341's tagged hash, is that message. |`+sign_secp256k1_eddsa+` |native, wasip2, wasip3 -|`+webcpp::crypto: a secp256k1 key signs with crypto::ecdsa_sha256, crypto::ecdsa_sha256_recoverable, crypto::ecdsa_keccak256_recoverable or crypto::schnorr.+` +|`+webcpp::crypto: a secp256k1 key signs with crypto::signing_schemes::ecdsa_sha256, crypto::signing_schemes::ecdsa_sha256_recoverable, crypto::signing_schemes::ecdsa_keccak256_recoverable or crypto::signing_schemes::schnorr.+` -The fix: Sign with `+crypto::ecdsa_sha256+`, `+crypto::ecdsa_sha256_recoverable+`, `+crypto::ecdsa_keccak256_recoverable+` or `+crypto::schnorr+`, secp256k1's schemes; `+crypto::eddsa+` is Ed25519's. +The fix: Sign with `+crypto::signing_schemes::ecdsa_sha256+`, `+crypto::signing_schemes::ecdsa_sha256_recoverable+`, `+crypto::signing_schemes::ecdsa_keccak256_recoverable+` or `+crypto::signing_schemes::schnorr+`, secp256k1's schemes; `+crypto::signing_schemes::eddsa+` is Ed25519's. |`+sign_secp256k1_not_a_scheme+` |native, wasip2, wasip3 -|`+webcpp::crypto: a secp256k1 key signs with crypto::ecdsa_sha256, crypto::ecdsa_sha256_recoverable, crypto::ecdsa_keccak256_recoverable or crypto::schnorr.+` +|`+webcpp::crypto: a secp256k1 key signs with crypto::signing_schemes::ecdsa_sha256, crypto::signing_schemes::ecdsa_sha256_recoverable, crypto::signing_schemes::ecdsa_keccak256_recoverable or crypto::signing_schemes::schnorr.+` -The fix: Name the scheme with its tag: `+crypto::ecdsa_sha256+`, `+crypto::ecdsa_sha256_recoverable+`, `+crypto::ecdsa_keccak256_recoverable+` or `+crypto::schnorr+`. +The fix: Name the scheme with its tag: `+crypto::signing_schemes::ecdsa_sha256+`, `+crypto::signing_schemes::ecdsa_sha256_recoverable+`, `+crypto::signing_schemes::ecdsa_keccak256_recoverable+` or `+crypto::signing_schemes::schnorr+`. |`+sign_secp256k1_recoverable_digest_48+` |native, wasip2, wasip3 -|`+webcpp::crypto: crypto::ecdsa_sha256_recoverable takes a 32-byte digest, SHA-256's: crypto::prehashed{digest} of a std::array.+` +|`+webcpp::crypto: crypto::signing_schemes::ecdsa_sha256_recoverable takes a 32-byte digest, SHA-256's: crypto::signing_schemes::prehashed{digest} of a std::array.+` -The fix: As `+sign_p256_digest_48+`: give `+crypto::ecdsa_sha256_recoverable+` SHA-256's 32-byte digest, or the message itself, which it hashes. +The fix: As `+sign_p256_digest_48+`: give `+crypto::signing_schemes::ecdsa_sha256_recoverable+` SHA-256's 32-byte digest, or the message itself, which it hashes. |`+sign_x25519+` |native, wasip2, wasip3 @@ -791,33 +973,39 @@ The fix: Call `+async_verify+` on a backend that completes by itself: its synchr |`+verify_ecdsa_bytes_key+` |native, wasip2, wasip3 -|`+webcpp::crypto: verify: this public key does not go with this scheme: crypto::eddsa and crypto::eddsa_prehashed take a curves::ed25519::public_key, crypto::ecdsa_sha256 a curves::p256::basic_public_key or a curves::secp256k1::public_key, crypto::schnorr a curves::secp256k1::public_key or a 32-byte x-only key; a crypto::ecdsa_sha256_recoverable or a crypto::ecdsa_keccak256_recoverable signature gives its key to curves::secp256k1::recover.+` +|`+webcpp::crypto: verify: this public key does not go with this scheme: crypto::signing_schemes::eddsa and crypto::signing_schemes::eddsa_prehashed take a curves::ed25519::public_key, crypto::signing_schemes::ecdsa_sha256 a curves::p256::basic_public_key or a curves::secp256k1::public_key, crypto::signing_schemes::schnorr a curves::secp256k1::public_key or a curves::secp256k1::xonly_public_key; a crypto::signing_schemes::ecdsa_sha256_recoverable or a crypto::signing_schemes::ecdsa_keccak256_recoverable signature gives its key to curves::secp256k1::recover.+` -The fix: Give `+crypto::ecdsa_sha256+` the public key as a typed object, `+curves::secp256k1::public_key::from_bytes(bytes)+` or `+curves::p256::public_key::from_bytes(bytes)+`: bytes never choose the curve. +The fix: Give `+crypto::signing_schemes::ecdsa_sha256+` the public key as a typed object, `+curves::secp256k1::public_key::from_bytes(bytes)+` or `+curves::p256::public_key::from_bytes(bytes)+`: bytes never choose the curve. |`+verify_ed25519_bytes_signature+` |native, wasip2, wasip3 -|`+webcpp::crypto: verify: an Ed25519 key verifies a curves::ed25519::signature under crypto::eddsa: make one from 64 bytes with curves::ed25519::signature::from_bytes.+` +|`+webcpp::crypto: verify: an Ed25519 key verifies a curves::ed25519::signature under crypto::signing_schemes::eddsa: make one from 64 bytes with curves::ed25519::signature::from_bytes.+` The fix: Make the 64 bytes received into a `+curves::ed25519::signature+` with `+curves::ed25519::signature::from_bytes+`, which checks their size, and verify that. |`+verify_eddsa_bytes_key+` |native, wasip2, wasip3 -|`+webcpp::crypto: verify: this public key does not go with this scheme: crypto::eddsa and crypto::eddsa_prehashed take a curves::ed25519::public_key, crypto::ecdsa_sha256 a curves::p256::basic_public_key or a curves::secp256k1::public_key, crypto::schnorr a curves::secp256k1::public_key or a 32-byte x-only key; a crypto::ecdsa_sha256_recoverable or a crypto::ecdsa_keccak256_recoverable signature gives its key to curves::secp256k1::recover.+` +|`+webcpp::crypto: verify: this public key does not go with this scheme: crypto::signing_schemes::eddsa and crypto::signing_schemes::eddsa_prehashed take a curves::ed25519::public_key, crypto::signing_schemes::ecdsa_sha256 a curves::p256::basic_public_key or a curves::secp256k1::public_key, crypto::signing_schemes::schnorr a curves::secp256k1::public_key or a curves::secp256k1::xonly_public_key; a crypto::signing_schemes::ecdsa_sha256_recoverable or a crypto::signing_schemes::ecdsa_keccak256_recoverable signature gives its key to curves::secp256k1::recover.+` -The fix: Give `+crypto::eddsa+` (or `+crypto::eddsa_prehashed+`) the public key as a `+curves::ed25519::public_key+`: `+key_pair.public_key()+`, or `+curves::ed25519::public_key::from_bytes(bytes)+` for a key received as bytes. +The fix: Give `+crypto::signing_schemes::eddsa+` (or `+crypto::signing_schemes::eddsa_prehashed+`) the public key as a `+curves::ed25519::public_key+`: `+key_pair.public_key()+`, or `+curves::ed25519::public_key::from_bytes(bytes)+` for a key received as bytes. + +|`+verify_eddsa_low_s_only+` +|native, wasip2, wasip3 +|`+webcpp::crypto: verify: crypto::signing_schemes::eddsa and eddsa_prehashed take crypto::verification_policies::canonical.+` + +The fix: Verify Ed25519 and Ed25519ph under `+crypto::verification_policies::canonical+`, libsodium's rules, their only policy; `+low_s_only+` and `+any_s+` are ECDSA's. |`+verify_eddsa_prehashed_asynchronous_backend+` |native, wasip2, wasip3 -|`+webcpp::crypto: WebCrypto has no Ed25519ph: crypto::eddsa_prehashed's sign, verify, async_sign and async_verify run on a native backend.+` +|`+webcpp::crypto: WebCrypto has no Ed25519ph: crypto::signing_schemes::eddsa_prehashed's sign, verify, async_sign and async_verify run on a native backend.+` -The fix: Verify under `+crypto::eddsa_prehashed+` on a native backend, `+crypto::verify+` and the key's `+verify+` alike: WebCrypto has no Ed25519ph; on the browser's backend, verify a signature of the message with `+crypto::eddsa+`. +The fix: Verify under `+crypto::signing_schemes::eddsa_prehashed+` on a native backend, `+crypto::verify+` and the key's `+verify+` alike: WebCrypto has no Ed25519ph; on the browser's backend, verify a signature of the message with `+crypto::signing_schemes::eddsa+`. |`+verify_eddsa_prehashed_message+` |native, wasip2, wasip3 -|`+webcpp::crypto: crypto::eddsa_prehashed (RFC 8032's Ed25519ph) signs a digest, the message's SHA-512: crypto::prehashed{digest} of a std::array; sign the message itself with crypto::eddsa, or give it in pieces to curves::ed25519::prehashed_signer.+` +|`+webcpp::crypto: crypto::signing_schemes::eddsa_prehashed (RFC 8032's Ed25519ph) signs a digest, the message's SHA-512: crypto::signing_schemes::prehashed{digest} of a std::array; sign the message itself with crypto::signing_schemes::eddsa, or give it in pieces to curves::ed25519::prehashed_signer.+` -The fix: As `+sign_eddsa_prehashed_message+`: verify under `+crypto::eddsa_prehashed+` the marker of the message's SHA-512, or the message itself under `+crypto::eddsa+`. +The fix: As `+sign_eddsa_prehashed_message+`: verify under `+crypto::signing_schemes::eddsa_prehashed+` the marker of the message's SHA-512, or the message itself under `+crypto::signing_schemes::eddsa+`. |`+verify_free_asynchronous_backend+` |native, wasip2, wasip3 @@ -827,39 +1015,45 @@ The fix: As `+verify_asynchronous_backend+`. |`+verify_free_secp256k1_recoverable+` |native, wasip2, wasip3 -|`+webcpp::crypto: verify: this public key does not go with this scheme: crypto::eddsa and crypto::eddsa_prehashed take a curves::ed25519::public_key, crypto::ecdsa_sha256 a curves::p256::basic_public_key or a curves::secp256k1::public_key, crypto::schnorr a curves::secp256k1::public_key or a 32-byte x-only key; a crypto::ecdsa_sha256_recoverable or a crypto::ecdsa_keccak256_recoverable signature gives its key to curves::secp256k1::recover.+` +|`+webcpp::crypto: verify: this public key does not go with this scheme: crypto::signing_schemes::eddsa and crypto::signing_schemes::eddsa_prehashed take a curves::ed25519::public_key, crypto::signing_schemes::ecdsa_sha256 a curves::p256::basic_public_key or a curves::secp256k1::public_key, crypto::signing_schemes::schnorr a curves::secp256k1::public_key or a curves::secp256k1::xonly_public_key; a crypto::signing_schemes::ecdsa_sha256_recoverable or a crypto::signing_schemes::ecdsa_keccak256_recoverable signature gives its key to curves::secp256k1::recover.+` -The fix: As `+verify_member_secp256k1_recoverable+`: give a recoverable signature to `+curves::secp256k1::recover+`, which gives the signer's key; `+crypto::verify+` takes `+crypto::ecdsa_sha256+` and `+crypto::schnorr+` with a secp256k1 key. +The fix: As `+verify_member_secp256k1_recoverable+`: give a recoverable signature to `+curves::secp256k1::recover+`, which gives the signer's key; `+crypto::verify+` takes `+crypto::signing_schemes::ecdsa_sha256+` and `+crypto::signing_schemes::schnorr+` with a secp256k1 key. |`+verify_keccak_recoverable+` |native, wasip2, wasip3 -|`+webcpp::crypto: verify: this public key does not go with this scheme: crypto::eddsa and crypto::eddsa_prehashed take a curves::ed25519::public_key, crypto::ecdsa_sha256 a curves::p256::basic_public_key or a curves::secp256k1::public_key, crypto::schnorr a curves::secp256k1::public_key or a 32-byte x-only key; a crypto::ecdsa_sha256_recoverable or a crypto::ecdsa_keccak256_recoverable signature gives its key to curves::secp256k1::recover.+` +|`+webcpp::crypto: verify: this public key does not go with this scheme: crypto::signing_schemes::eddsa and crypto::signing_schemes::eddsa_prehashed take a curves::ed25519::public_key, crypto::signing_schemes::ecdsa_sha256 a curves::p256::basic_public_key or a curves::secp256k1::public_key, crypto::signing_schemes::schnorr a curves::secp256k1::public_key or a curves::secp256k1::xonly_public_key; a crypto::signing_schemes::ecdsa_sha256_recoverable or a crypto::signing_schemes::ecdsa_keccak256_recoverable signature gives its key to curves::secp256k1::recover.+` -The fix: Give the signature to `+curves::secp256k1::recover(crypto::ecdsa_keccak256_recoverable, signature, input)+`, which gives the signer's key, and compare that key, or its address, with the one expected: Ethereum's recoverable ECDSA has no `+verify+`. +The fix: Give the signature to `+curves::secp256k1::recover(crypto::signing_schemes::ecdsa_keccak256_recoverable, crypto::verification_policies::low_s_only, signature, input)+`, which gives the signer's key, and compare that key, or its address, with the one expected: Ethereum's recoverable ECDSA has no `+verify+`. |`+verify_member_ed25519_ecdsa+` |native, wasip2, wasip3 -|`+webcpp::crypto: an Ed25519 public key verifies crypto::eddsa or crypto::eddsa_prehashed.+` +|`+webcpp::crypto: an Ed25519 public key verifies crypto::signing_schemes::eddsa or crypto::signing_schemes::eddsa_prehashed.+` -The fix: Verify with `+crypto::eddsa+` or `+crypto::eddsa_prehashed+`, Ed25519's schemes; `+crypto::ecdsa_sha256+` is P-256's and secp256k1's, whose keys are `+curves::p256::basic_public_key+` and `+curves::secp256k1::public_key+`. +The fix: Verify with `+crypto::signing_schemes::eddsa+` or `+crypto::signing_schemes::eddsa_prehashed+`, Ed25519's schemes; `+crypto::signing_schemes::ecdsa_sha256+` is P-256's and secp256k1's, whose keys are `+curves::p256::basic_public_key+` and `+curves::secp256k1::public_key+`. |`+verify_member_eddsa_prehashed+` |native, wasip2, wasip3 -|`+webcpp::crypto: crypto::eddsa signs the message itself (RFC 8032's pure Ed25519) and takes no digest; a message's SHA-512 is signed with crypto::eddsa_prehashed (Ed25519ph).+` +|`+webcpp::crypto: crypto::signing_schemes::eddsa signs the message itself (RFC 8032's pure Ed25519) and takes no digest; a message's SHA-512 is signed with crypto::signing_schemes::eddsa_prehashed (Ed25519ph).+` -The fix: Verify the message itself with `+crypto::eddsa+`, RFC 8032's pure Ed25519, which takes no digest, as `+crypto::verify+` does; a signature of a message's SHA-512 is Ed25519ph's, verified with `+crypto::eddsa_prehashed+`, or for a message given in pieces with `+curves::ed25519::prehashed_signer+`. +The fix: Verify the message itself with `+crypto::signing_schemes::eddsa+`, RFC 8032's pure Ed25519, which takes no digest, as `+crypto::verify+` does; a signature of a message's SHA-512 is Ed25519ph's, verified with `+crypto::signing_schemes::eddsa_prehashed+`, or for a message given in pieces with `+curves::ed25519::prehashed_signer+`. |`+verify_member_p256_eddsa+` |native, wasip2, wasip3 -|`+webcpp::crypto: a P-256 public key verifies crypto::ecdsa_sha256.+` +|`+webcpp::crypto: a P-256 public key verifies crypto::signing_schemes::ecdsa_sha256.+` -The fix: Verify with `+crypto::ecdsa_sha256+`, P-256's scheme; `+crypto::eddsa+` is Ed25519's, whose key is a `+curves::ed25519::public_key+`. +The fix: Verify with `+crypto::signing_schemes::ecdsa_sha256+`, P-256's scheme; `+crypto::signing_schemes::eddsa+` is Ed25519's, whose key is a `+curves::ed25519::public_key+`. |`+verify_member_secp256k1_recoverable+` |native, wasip2, wasip3 -|`+webcpp::crypto: a secp256k1 public key verifies crypto::ecdsa_sha256 or crypto::schnorr; a crypto::ecdsa_sha256_recoverable or a crypto::ecdsa_keccak256_recoverable signature gives its key to curves::secp256k1::recover.+` +|`+webcpp::crypto: a secp256k1 public key verifies crypto::signing_schemes::ecdsa_sha256 or crypto::signing_schemes::schnorr; a crypto::signing_schemes::ecdsa_sha256_recoverable or a crypto::signing_schemes::ecdsa_keccak256_recoverable signature gives its key to curves::secp256k1::recover.+` + +The fix: Give a recoverable signature to `+curves::secp256k1::recover(crypto::signing_schemes::ecdsa_sha256_recoverable, crypto::verification_policies::low_s_only, signature, input)+`, which gives the signer's key; a public key verifies `+crypto::signing_schemes::ecdsa_sha256+` and `+crypto::signing_schemes::schnorr+`. + +|`+verify_p256_canonical+` +|native, wasip2, wasip3 +|`+webcpp::crypto: verify: crypto::signing_schemes::ecdsa_sha256 on a P-256 key takes crypto::verification_policies::low_s_only or any_s.+` -The fix: Give a recoverable signature to `+curves::secp256k1::recover(crypto::ecdsa_sha256_recoverable, signature, input)+`, which gives the signer's key; a public key verifies `+crypto::ecdsa_sha256+` and `+crypto::schnorr+`. +The fix: Verify P-256's ECDSA under `+crypto::verification_policies::low_s_only+`, for a signature crypto made, or `+any_s+`, for one a browser's WebCrypto or a passkey made, whose S may be high; `+canonical+` is Ed25519's and BIP340's. |`+verify_p256_secp256k1_signature+` |native, wasip2, wasip3 @@ -867,11 +1061,41 @@ The fix: Give a recoverable signature to `+curves::secp256k1::recover(crypto::ec The fix: Give a P-256 key a `+curves::p256::ecdsa_signature+`, made from the 64 bytes received with `+curves::p256::ecdsa_signature::from_bytes+`; a secp256k1 signature verifies with a `+curves::secp256k1::public_key+`. +|`+verify_schnorr_any_s+` +|native, wasip2, wasip3 +|`+webcpp::crypto: verify: crypto::signing_schemes::schnorr takes crypto::verification_policies::canonical.+` + +The fix: Verify BIP340 under `+crypto::verification_policies::canonical+`, its only policy; `+low_s_only+` and `+any_s+` are ECDSA's. + |`+verify_schnorr_as_ecdsa+` |native, wasip2, wasip3 -|`+webcpp::crypto: verify: a secp256k1 key verifies a curves::secp256k1::ecdsa_signature under crypto::ecdsa_sha256: make one from 64 bytes with curves::secp256k1::ecdsa_signature::from_bytes.+` +|`+webcpp::crypto: verify: a secp256k1 key verifies a curves::secp256k1::ecdsa_signature under crypto::signing_schemes::ecdsa_sha256: make one from 64 bytes with curves::secp256k1::ecdsa_signature::from_bytes.+` + +The fix: Verify a BIP340 signature with `+crypto::signing_schemes::schnorr+`, its scheme; `+crypto::signing_schemes::ecdsa_sha256+` takes a `+curves::secp256k1::ecdsa_signature+`, which `+sign(crypto::signing_schemes::ecdsa_sha256, input)+` gives. + +|`+verify_schnorr_span_removed+` +|native, wasip2, wasip3 +|`+webcpp::crypto: verify: this public key does not go with this scheme: crypto::signing_schemes::eddsa and crypto::signing_schemes::eddsa_prehashed take a curves::ed25519::public_key, crypto::signing_schemes::ecdsa_sha256 a curves::p256::basic_public_key or a curves::secp256k1::public_key, crypto::signing_schemes::schnorr a curves::secp256k1::public_key or a curves::secp256k1::xonly_public_key; a crypto::signing_schemes::ecdsa_sha256_recoverable or a crypto::signing_schemes::ecdsa_keccak256_recoverable signature gives its key to curves::secp256k1::recover.+` + +The fix: Make the 32 bytes into a typed key first, `+curves::secp256k1::xonly_public_key::from_bytes(bytes)+`, and give it to `+crypto::verify+`: the overload over a 32-byte span is removed, verification is typed. + +|`+verify_secp256k1_any_s+` +|native, wasip2, wasip3 +|`+webcpp::crypto: verify: crypto::signing_schemes::ecdsa_sha256 on a secp256k1 key takes crypto::verification_policies::low_s_only.+` -The fix: Verify a BIP340 signature with `+crypto::schnorr+`, its scheme; `+crypto::ecdsa_sha256+` takes a `+curves::secp256k1::ecdsa_signature+`, which `+sign(crypto::ecdsa_sha256, input)+` gives. +The fix: Verify secp256k1's ECDSA under `+crypto::verification_policies::low_s_only+`, its only policy, as libsecp256k1 and Bitcoin's rule; a signature whose S is high is made low with `+signature.low_s()+` first. + +|`+verify_without_policy+` +|native, wasip2, wasip3 +|`+webcpp::crypto: verify takes a verification policy after the scheme: crypto::signing_schemes::eddsa takes crypto::verification_policies::canonical.+` + +The fix: Name the verification policy after the scheme: `+crypto::verify(crypto::signing_schemes::eddsa, crypto::verification_policies::canonical, signature, message, public_key)+`; each scheme takes its own, `+canonical+` for Ed25519 and BIP340, `+low_s_only+` for secp256k1's ECDSA and `+recover+`, `+low_s_only+` or `+any_s+` for P-256's ECDSA. + +|`+verify_xonly_any_s+` +|native, wasip2, wasip3 +|`+webcpp::crypto: verify: crypto::signing_schemes::schnorr takes crypto::verification_policies::canonical.+` + +The fix: Verify BIP340 against the x-only key under `+crypto::verification_policies::canonical+`, its only policy, member and free; `+low_s_only+` and `+any_s+` are ECDSA's. |`+wipe_removed+` |native, wasip2, wasip3 @@ -905,6 +1129,12 @@ The fix: Name a backend that has X25519 as well, as libsodium, the default of cr The fix: Add `+/webcpp/crypto//x25519-default+`, which links `+/third_party//sodium+` on every target. +|`+x25519_formats_header_missing+` +|native, wasip2, wasip3 +|`+webcpp::crypto: include to encode or decode this type+` + +The fix: Include `++`, which registers X25519's formats, beside `++`. + |`+x25519_free_functions_removed+` |native, wasip2, wasip3 |`+no member named 'agree' in namespace 'webcpp::crypto::curves::x25519'+` @@ -912,6 +1142,18 @@ The fix: Add `+/webcpp/crypto//x25519-default+`, which links `+/third_party//sod `+no matching conversion for functional-style cast+` The fix: Make the key pair with `+curves::x25519::keypair::from_secret(secret)+`, then call its `+public_key()+`, and its `+agree+` with the peer's `+curves::x25519::public_key+` from `+from_bytes+`; the free functions over bytes are gone, with no alias. The `+x25519::public_key(secret)+` half pins clang's generic "no matching conversion for functional-style cast", since `+public_key+` now names the type. + +|`+xonly_default_constructed+` +|native, wasip2, wasip3 +|`+no matching constructor for initialization of 'webcpp::crypto::curves::secp256k1::xonly_public_key'+` + +The fix: Make the x-only key with a value: `+curves::secp256k1::xonly_public_key::from_bytes(bytes)+`, a public key's `+xonly()+`, a key pair's `+xonly_public_key()+` or MuSig2's `+aggregate_key::xonly_public_key()+`; it is never unset, since libsecp256k1 aborts on an unset key. + +|`+xonly_into_public_key+` +|native, wasip2, wasip3 +|`+webcpp::crypto: an x-only key decodes into curves::secp256k1::xonly_public_key+` + +The fix: A 32-byte x-only key decodes into `+crypto::curves::secp256k1::xonly_public_key+`: `+crypto::decode(crypto::formats::raw(crypto::formats::xonly), bytes)+`, or its member `+xonly_public_key::decode+`; `+raw(crypto::formats::xonly)+` encodes a public key's x-only key, and its 33- or 65-byte SEC 1 point decodes into a `+public_key+` with `+crypto::formats::raw+`. |=== At build and link time, from the fixtures of the user's Jamfiles, each built on a scratch superproject: the texts the build's output contains, per target and linker, as each fixture checks them. @@ -1017,19 +1259,19 @@ On each target, the build's output contains: + * native, macOS: ** `+Undefined symbols for architecture+` -** `+_webcpp_crypto_bearssl_32381d6_getentropy__add_third_party_bearssl_to_your_link+` +** `+_webcpp_crypto_bearssl_ae63032_getentropy__add_third_party_bearssl_to_your_link+` * native, Linux: -** `+webcpp_crypto_bearssl_32381d6_getentropy__add_third_party_bearssl_to_your_link+` -** `pass:[undefined reference to `webcpp_crypto_bearssl_32381d6_getentropy__add_third_party_bearssl_to_your_link']` +** `+webcpp_crypto_bearssl_ae63032_getentropy__add_third_party_bearssl_to_your_link+` +** `pass:[undefined reference to `webcpp_crypto_bearssl_ae63032_getentropy__add_third_party_bearssl_to_your_link']` * wasip2: ** `+wasm-ld: error:+` -** `+undefined symbol: webcpp_crypto_bearssl_32381d6_getentropy__add_third_party_bearssl_to_your_link+` +** `+undefined symbol: webcpp_crypto_bearssl_ae63032_getentropy__add_third_party_bearssl_to_your_link+` * wasip3: ** `+wasm-ld: error:+` -** `+undefined symbol: webcpp_crypto_bearssl_32381d6_getentropy__add_third_party_bearssl_to_your_link+` +** `+undefined symbol: webcpp_crypto_bearssl_ae63032_getentropy__add_third_party_bearssl_to_your_link+` * emscripten: ** `+wasm-ld: error:+` -** `+undefined symbol: webcpp_crypto_bearssl_32381d6_getentropy__add_third_party_bearssl_to_your_link+` +** `+undefined symbol: webcpp_crypto_bearssl_ae63032_getentropy__add_third_party_bearssl_to_your_link+` ** `pass:[em++: error:]` `+canary_other_commit+`:: A BearSSL of another commit than the headers'. The fix: Build the library at the commit of webcpp's submodule, or link it through b2. @@ -1073,19 +1315,19 @@ On each target, the build's output contains: + * native, macOS: ** `+Undefined symbols for architecture+` -** `+_webcpp_crypto_bearssl_32381d6_sysrng__add_third_party_bearssl_to_your_link+` +** `+_webcpp_crypto_bearssl_ae63032_sysrng__add_third_party_bearssl_to_your_link+` * native, Linux: -** `+webcpp_crypto_bearssl_32381d6_sysrng__add_third_party_bearssl_to_your_link+` -** `pass:[undefined reference to `webcpp_crypto_bearssl_32381d6_sysrng__add_third_party_bearssl_to_your_link']` +** `+webcpp_crypto_bearssl_ae63032_sysrng__add_third_party_bearssl_to_your_link+` +** `pass:[undefined reference to `webcpp_crypto_bearssl_ae63032_sysrng__add_third_party_bearssl_to_your_link']` * wasip2: ** `+wasm-ld: error:+` -** `+undefined symbol: webcpp_crypto_bearssl_32381d6_sysrng__add_third_party_bearssl_to_your_link+` +** `+undefined symbol: webcpp_crypto_bearssl_ae63032_sysrng__add_third_party_bearssl_to_your_link+` * wasip3: ** `+wasm-ld: error:+` -** `+undefined symbol: webcpp_crypto_bearssl_32381d6_sysrng__add_third_party_bearssl_to_your_link+` +** `+undefined symbol: webcpp_crypto_bearssl_ae63032_sysrng__add_third_party_bearssl_to_your_link+` * emscripten: ** `+wasm-ld: error:+` -** `+undefined symbol: webcpp_crypto_bearssl_32381d6_sysrng__add_third_party_bearssl_to_your_link+` +** `+undefined symbol: webcpp_crypto_bearssl_ae63032_sysrng__add_third_party_bearssl_to_your_link+` ** `pass:[em++: error:]` `+canary_secp256k1_missing+`:: libsecp256k1's headers used without its library. The fix: Link `+/third_party//secp256k1+`. @@ -1185,19 +1427,19 @@ On each target, the build's output contains: + * native, macOS: ** `+Undefined symbols for architecture+` -** `+_webcpp_crypto_bearssl_32381d6_getentropy__add_third_party_bearssl_to_your_link+` +** `+_webcpp_crypto_bearssl_ae63032_getentropy__add_third_party_bearssl_to_your_link+` * native, Linux: -** `+webcpp_crypto_bearssl_32381d6_getentropy__add_third_party_bearssl_to_your_link+` -** `pass:[undefined reference to `webcpp_crypto_bearssl_32381d6_getentropy__add_third_party_bearssl_to_your_link']` +** `+webcpp_crypto_bearssl_ae63032_getentropy__add_third_party_bearssl_to_your_link+` +** `pass:[undefined reference to `webcpp_crypto_bearssl_ae63032_getentropy__add_third_party_bearssl_to_your_link']` * wasip2: ** `+wasm-ld: error:+` -** `+undefined symbol: webcpp_crypto_bearssl_32381d6_getentropy__add_third_party_bearssl_to_your_link+` +** `+undefined symbol: webcpp_crypto_bearssl_ae63032_getentropy__add_third_party_bearssl_to_your_link+` * wasip3: ** `+wasm-ld: error:+` -** `+undefined symbol: webcpp_crypto_bearssl_32381d6_getentropy__add_third_party_bearssl_to_your_link+` +** `+undefined symbol: webcpp_crypto_bearssl_ae63032_getentropy__add_third_party_bearssl_to_your_link+` * emscripten: ** `+wasm-ld: error:+` -** `+undefined symbol: webcpp_crypto_bearssl_32381d6_getentropy__add_third_party_bearssl_to_your_link+` +** `+undefined symbol: webcpp_crypto_bearssl_ae63032_getentropy__add_third_party_bearssl_to_your_link+` ** `pass:[em++: error:]` `+chacha_default_not_linked_on_emscripten+`:: A program for Emscripten that calls the three ChaCha20-Poly1305 AEADs on their default, libsodium, and links none. The fix: As `+chacha_default_not_linked+`. @@ -1328,7 +1570,7 @@ On each target, the build's output contains: * emscripten: ** `+webcpp::crypto: bearssl has no Ed25519. The backends that have it: sodium (native, wasip2, wasip3, emscripten).+` -`+ed25519_unknown_policy_on_emscripten+`:: A program for Emscripten that names a policy of its own in Ed25519's `+crypto::verify+`. The fix: As `+ed25519_unknown_policy+`. +`+ed25519_unknown_policy_on_emscripten+`:: A program for Emscripten that names a policy of its own after the scheme in Ed25519's `+crypto::verify+`. The fix: As `+ed25519_unknown_policy+`. + Its Jamfile: + @@ -1340,7 +1582,7 @@ include::{webcpp-root}/tools/test/fixtures/crypto_jamfiles/ed25519_unknown_polic On each target, the build's output contains: + * emscripten: -** `+webcpp::crypto: Ed25519's only verification policy is curves::ed25519::strict.+` +** `+webcpp::crypto: verify: crypto::signing_schemes::eddsa and eddsa_prehashed take crypto::verification_policies::canonical.+` `+ed25519ph_sha256_on_emscripten+`:: A program for Emscripten that names SHA-256 in Ed25519ph's streaming signer, `+curves::ed25519::prehashed_signer+`, which RFC 8032 defines over SHA-512. The fix: As `+ed25519ph_sha256+`. + @@ -1502,20 +1744,6 @@ On each target, the build's output contains: * emscripten: ** `+webcpp::crypto: sodium has no P-256. The backends that have it: bearssl (native, wasip2, wasip3, emscripten).+` -`+pem_default_not_linked_on_emscripten+`:: A program for Emscripten that armours DER as PEM on its default, libsodium, and links none. The fix: As `+pem_default_not_linked+`. -+ -Its Jamfile: -+ -[listing] ----- -include::{webcpp-root}/tools/test/fixtures/crypto_jamfiles/pem_default_not_linked_on_emscripten/Jamfile[tag=jamfile] ----- -+ -On each target, the build's output contains: -+ -* emscripten: -** `+webcpp::crypto: PEM's default backend on this target is libsodium, which is not linked, and the one backend that has it there. Add /webcpp/crypto//pem-default, the default's library on every target, to the program's Jamfile, as in: exe app : app.cpp /webcpp/crypto//crypto /webcpp/crypto//pem-default ; (without b2: define WEBCPP_CRYPTO_HAS_SODIUM=1 and link libsodium built with webcpp's src/canary_sodium.c)+` - `+sodium_not_linked_on_emscripten+`:: A program for Emscripten that names libsodium and links none. The fix: Add `+/third_party//sodium+` to the program's sources. + Its Jamfile: @@ -1554,6 +1782,14 @@ On MSVC, each case of `test/msvc` is proven to stop the build, at compile or at |the compile |Name one of the three ChaCha20-Poly1305 families; AES-GCM is `+ciphers::gcm+`, as in `+aes256_gcm+`, and a secret box `+secret_key_encryption::basic_secretbox+`, as in `+secret_key_encryption::secretbox<>+`. +|`+aead_template_removed+` +|the compile +|Name `+ciphers::basic_chacha20_poly1305+`, or its aliases `+chacha20_poly1305+`, `+chacha20_poly1305_original+` and `+xchacha20_poly1305+`: the template is named for its algorithm, with no alias. + +|`+aead_template_removed_call+` +|the compile +|As `+aead_template_removed+`: name `+ciphers::basic_chacha20_poly1305+`. + |`+aes_block_default_not_linked+` |the compile |Natively the block cipher's default is OpenSSL: add `+/webcpp/crypto//aes_block-default+`, which links `+/webcpp/crypto//openssl+` there, or name ctaes in the type, as in `+aes256+`. @@ -1562,6 +1798,34 @@ On MSVC, each case of `test/msvc` is proven to stop the build, at compile or at |the compile |Name `+ciphers::aes256+`, include `++` and add `+/third_party//ctaes+`. +|`+agree_asynchronous_backend+` +|the compile +|Call `+async_agree+` on a backend that completes by itself: its synchronous forms cannot wait for it. + +|`+agree_ed25519+` +|the compile +|Convert the Ed25519 key pair with `+to_x25519()+` and agree with the X25519 key pair it gives, and the peer's key converted with `+public_key.to_x25519()+`: an Ed25519 key pair signs and does not agree. + +|`+agree_free_wrong_peer+` +|the compile +|Give `+agree+` the peer's typed public key of the key pair's own curve and backend: `+curves::x25519::public_key::from_bytes(bytes)+` for X25519, `+curves::p256::basic_public_key::from_bytes(bytes)+` for P-256, `+curves::secp256k1::public_key::from_bytes(bytes)+` for secp256k1. + +|`+async_agree_ed25519+` +|the compile +|As `+agree_ed25519+`: give `+async_agree+` the X25519 key pair that the Ed25519 key pair's `+to_x25519()+` gives, and the peer's converted key. + +|`+async_agree_secp256k1+` +|the compile +|Call the key pair's own `+agree+`: secp256k1 is not in WebCrypto, so only X25519's and P-256's key pairs have `+async_agree+`. + +|`+async_agree_wrong_peer+` +|the compile +|As `+agree_free_wrong_peer+`: give `+async_agree+` the peer's typed public key of the key pair's own curve and backend, `+curves::x25519::public_key::from_bytes(bytes)+` for X25519, `+curves::p256::basic_public_key::from_bytes(bytes)+` for P-256. + +|`+async_from_key_secretbox_async_backend+` +|the compile +|Name a native backend, such as `+backends::sodium+`, for the secret box's `+async_from_key+`: WebCrypto has no secret box. + |`+async_from_key_xchacha+` |the compile |Name a native backend, such as `+backends::sodium+`, for `+async_from_key+`: WebCrypto has no XChaCha20-Poly1305, so no form of it runs on the browser's backend, where only AES-GCM seals and opens. @@ -1570,18 +1834,90 @@ On MSVC, each case of `test/msvc` is proven to stop the build, at compile or at |the compile |Call the synchronous `+from_secret+`: secp256k1 is not in WebCrypto, so only Ed25519's, X25519's and P-256's key pairs have `+async_from_secret+`. +|`+async_member_without_async_hpp+` +|the compile +|Include `++`, which defines the asynchronous members, and add `+/webcpp/asio//asio+` to the program's Jamfile. + +|`+async_open_box_asynchronous_backend+` +|the compile +|Name a native backend, such as `+backends::sodium+`, for the crypto_box: WebCrypto has no crypto_box, so no form of it runs on the browser's backend, where only AES-GCM seals and opens. + |`+async_open_xchacha+` |the compile |Name a native backend, such as `+backends::sodium+`, for `+async_open+`, or open with AES-GCM on the browser's backend: WebCrypto has no XChaCha20-Poly1305. +|`+async_seal_box_associated_data+` +|the compile +|Call the box form, `+secret_key_encryption::async_seal(executor, box, nonce, data, token)+`, or the box's own `+async_seal(executor, nonce, data, token)+`: a secret box or a crypto_box takes no associated data. + +|`+async_seal_box_asynchronous_backend+` +|the compile +|Name a native backend, such as `+backends::sodium+`, for the secret box: WebCrypto has no secret box, so no form of it runs on the browser's backend, where only AES-GCM seals and opens. + +|`+async_seal_member_asynchronous_backend+` +|the compile +|As `+async_seal_xchacha+`: name a native backend, such as `+backends::sodium+`, for XChaCha20-Poly1305's `+async_seal+`. + +|`+async_seal_removed+` +|the compile +|Call crypto::secret_key_encryption::aead::async_seal and async_open. clang's suggestion, `+secret_key_encryption::async_seal+` and `+async_open+`, is the box form, which takes no associated data and is wrong for an AES-GCM or ChaCha20-Poly1305 user. + +|`+async_seal_removed_declaration+` +|the compile +|As `+async_seal_removed+`: call crypto::secret_key_encryption::aead::async_seal and async_open, in . + |`+async_seal_xchacha+` |the compile |Name a native backend, such as `+backends::sodium+`, for `+async_seal+`, or seal with AES-GCM on the browser's backend: WebCrypto has no XChaCha20-Poly1305. +|`+async_sign_ed25519_prehashed+` +|the compile +|Give `+async_sign+` the message itself with `+crypto::signing_schemes::eddsa+`, RFC 8032's pure Ed25519, which takes no digest, as the synchronous `+sign+` does; a message's SHA-512 is signed with `+crypto::signing_schemes::eddsa_prehashed+` (Ed25519ph), on a native backend. + +|`+async_sign_ed25519ph_on_async_backend+` +|the compile +|As `+sign_eddsa_prehashed_asynchronous_backend+`: `+async_sign+` under `+crypto::signing_schemes::eddsa_prehashed+` runs on a native backend. + +|`+async_sign_p256_eddsa+` +|the compile +|Give `+async_sign+` the key pair's own scheme: `+crypto::signing_schemes::ecdsa_sha256+` for a P-256 key pair, `+crypto::signing_schemes::eddsa+` or `+crypto::signing_schemes::eddsa_prehashed+` for an Ed25519 key pair. + |`+async_sign_secp256k1+` |the compile |Call the key pair's own signing function: secp256k1 is not in WebCrypto, so only Ed25519's and P-256's key pairs have `+async_sign+`. +|`+async_sign_x25519+` +|the compile +|As `+sign_x25519+`: give `+async_sign+` an Ed25519 key pair, which signs; an X25519 key pair agrees, with `+async_agree+`. + +|`+async_verify_ed25519ph_on_async_backend+` +|the compile +|As `+verify_eddsa_prehashed_asynchronous_backend+`: `+async_verify+` under `+crypto::signing_schemes::eddsa_prehashed+`, free and member, runs on a native backend. + +|`+async_verify_eddsa_bytes_key+` +|the compile +|Give `+async_verify+` with `+crypto::signing_schemes::eddsa+` the public key as a `+curves::ed25519::public_key+`, as `+crypto::verify+` takes it: `+key_pair.public_key()+`, or `+curves::ed25519::public_key::from_bytes(bytes)+`. + +|`+async_verify_named_backend+` +|the compile +|As `+async_verify_wrong_key+`: naming the backend does not add a scheme; call `+crypto::verify+` for `+crypto::signing_schemes::schnorr+` and secp256k1's keys. + +|`+async_verify_p256_bytes_signature+` +|the compile +|As `+verify_p256_secp256k1_signature+`: make the 64 bytes received into a `+curves::p256::ecdsa_signature+` with `+from_bytes+`, then give it to `+async_verify+`. + +|`+async_verify_secp256k1_without_policy+` +|the compile +|As `+async_verify_wrong_key+`: call `+crypto::verify(crypto::signing_schemes::ecdsa_sha256, crypto::verification_policies::low_s_only, signature, input, public_key)+` for a secp256k1 key, which the asynchronous family lacks. + +|`+async_verify_without_policy+` +|the compile +|As `+verify_without_policy+`: `+async_verify(executor, crypto::signing_schemes::ecdsa_sha256, crypto::verification_policies::low_s_only, signature, input, public_key, token)+` for a signature crypto made, `+any_s+` for one a browser's WebCrypto or a passkey made, whose S may be high. + +|`+async_verify_wrong_key+` +|the compile +|Call `+crypto::verify+` for a key the asynchronous family lacks (secp256k1's, Schnorr's x-only key): `+async_verify+` has a `+curves::ed25519::public_key+` with `+crypto::signing_schemes::eddsa+` or `+crypto::signing_schemes::eddsa_prehashed+` and a `+curves::p256::basic_public_key+` with `+crypto::signing_schemes::ecdsa_sha256+`. + |`+bearssl_not_linked+` |the compile |Add `+/third_party//bearssl+`. @@ -1646,10 +1982,26 @@ On MSVC, each case of `test/msvc` is proven to stop the build, at compile or at |the compile |Name a backend of `+webcpp::crypto::backends+` that has the family, as `+backends::bearssl+`, or leave the backend out for the family's default: `+chacha20_poly1305<>+`. +|`+constant_time_equal_moved+` +|the compile +|Call `+webcpp::secure::constant_time_equal+`, from `++`, the same comparison in constant time; `+crypto::constant_time_equal+` moved to webcpp::secure, with no alias. + |`+ctaes_not_linked+` |the compile |Add `+/third_party//ctaes+`. +|`+decode_bound_differs+` +|the compile +|Make `+max_decode_input_size+` equal to `+max_encoded_size+`, or, where a change rules that the decode accepts a longer form (as PKCS#8 version 2 will), specialize `+detail::bounds_may_differ_v+` for the pair beside its value codec. + +|`+decode_bound_missing+` +|the compile +|State `+static constexpr std::size_t max_decode_input_size+` in the value codec that decodes: the longest encoded input its `+decode+` accepts, equal to its `+max_encoded_size+` unless a change rules otherwise. + +|`+decode_refusal_reason_toy+` +|the compile +|Decode the x-only form into the type that holds it, as secp256k1's `+curves::secp256k1::xonly_public_key+`; the type this refuses has the form to encode only. + |`+default_openssl_wasm+` |the compile |Remove the define, and name `+gcm>+` where the program wants OpenSSL. @@ -1658,17 +2010,37 @@ On MSVC, each case of `test/msvc` is proven to stop the build, at compile or at |the compile |Remove the define, and name `+gcm>+` where the program wants BearSSL. +|`+der_on_ed25519+` +|the compile +|Encode an Ed25519 signature with `+crypto::formats::raw+`, or its member `+signature.encode(crypto::formats::raw)+`: its 64 bytes are the signature, and it has no DER form. + +|`+der_on_recoverable+` +|the compile +|Encode a recoverable signature with `+crypto::formats::raw+`, its 65 bytes, r, s and the recovery id, or its member `+signature.encode(crypto::formats::raw)+`; it has no DER form. A Bitcoin script's DER is that of an `+ecdsa_signature+`: sign with `+crypto::signing_schemes::ecdsa_sha256+` and encode it in `+crypto::formats::der+`. + +|`+der_on_schnorr+` +|the compile +|Encode a BIP340 signature with `+crypto::formats::raw+`, or its member `+signature.encode(crypto::formats::raw)+`: its 64 bytes are the signature, and it has no DER form. + +|`+der_short_name_removed_p256+` +|the compile +|Write a P-256 signature's DER with `+crypto::encode(crypto::formats::der, signature)+` or its member `+signature.encode(crypto::formats::der)+`, and read it with `+crypto::decode(crypto::formats::der, bytes)+`; the free `+to_der+` and `+from_der+` are gone, with no alias. + |`+ed25519_default_not_linked+` |the compile |Add `+/webcpp/crypto//ed25519-default+`, which links `+/third_party//sodium+` on every target. +|`+ed25519_formats_header_missing+` +|the compile +|Include `++`, which registers Ed25519's formats, beside `++`. + |`+ed25519_on_bearssl+` |the compile |Leave the backend out, as in `+curves::ed25519::keypair+`, or name `+backends::sodium+`, and add `+/third_party//sodium+`. |`+ed25519_unknown_policy+` |the compile -|Leave the policy out, as in `+crypto::verify(crypto::eddsa, signature, message, public_key)+`, or name `+curves::ed25519::strict+`. +|Name `+crypto::verification_policies::canonical+` after the scheme, Ed25519's only policy: `+crypto::verify(crypto::signing_schemes::eddsa, crypto::verification_policies::canonical, signature, message, public_key)+`. |`+ed25519ph_sha256+` |the compile @@ -1678,6 +2050,34 @@ On MSVC, each case of `test/msvc` is proven to stop the build, at compile or at |the compile |Name `+backends::secp256k1+`, or leave the backend out: `+curves::secp256k1::ellswift_decode(encoded_key)+`. +|`+equal_header_removed+` +|the compile +|Include `++`, the header of `+secure::constant_time_equal+`; `+equal.hpp+` is gone, with no header left at its path. + +|`+equal_removed+` +|the compile +|Call `+webcpp::secure::constant_time_equal+`, the same comparison of two byte sequences in constant time; `+crypto::equal+` is gone, with no alias. + +|`+erase_secret_moved+` +|the compile +|Call `+webcpp::secure::erase_secret+`, from `++`, the same erasure; `+crypto::erase_secret+` moved to webcpp::secure, with no alias. + +|`+format_header_missing_toy+` +|the compile +|Include the formats header of the type's curve, the one the assertion names, `+/formats.hpp>+`, beside the curve's own header, which declares no format. + +|`+format_refused_toy+` +|the compile +|Encode or decode a type in a format of its list, the `+format_list+` the assertion names: another type's format (`+der+` is an ECDSA signature's, `+pkcs8+` a key pair's) does not convert it. + +|`+format_without_header+` +|the compile +|Include `++`, or the curve's `+/formats.hpp>+`, which includes it: `+crypto::formats+` is declared by `+config.hpp+` and filled by the formats headers alone. + +|`+forms_without_default+` +|the compile +|List `+crypto::formats::default_form_t+` in each `+detail::forms_of+` specialization, with the other point forms the type accepts. + |`+gcm_default_openssl_not_linked+` |the compile |Natively the default is OpenSSL: add `+/webcpp/crypto//gcm-default+`, which links `+/webcpp/crypto//openssl+` there, or name BearSSL in the type, as in `+gcm>+`. @@ -1690,6 +2090,30 @@ On MSVC, each case of `test/msvc` is proven to stop the build, at compile or at |the compile |Call the synchronous operation the message names, or build with threads: natively without `+WEBCPP_CRYPTO_NO_THREADS+`, on Emscripten with `+-pthread+`; WASI has none. +|`+heavy_without_threads_first+` +|the compile +|As `+heavy_without_threads+`. + +|`+hybrid_header_removed+` +|the compile +|Include `++` for `+box+` and `+box_xchacha20poly1305+`, `++` for `+sealed_box+`, `++` for `+kx_keypair+`; the old directory is kept free for post-quantum hybrids. + +|`+hybrid_names_removed+` +|the compile +|Name `+crypto::public_key_encryption::box+`, `+box_xchacha20poly1305+` and `+sealed_box+`, and `+crypto::key_exchange::kx_keypair+` and `+session_keys+`; `+crypto::hybrid+` and the names in `+curves::x25519+` are gone, with no alias. + +|`+iv_size_removed+` +|the compile +|Name nonce_size, max_nonce_size and error::invalid_nonce_size: crypto spells its names out. + +|`+keypair_decode_resource_from_text+` +|the compile +|Give the key pair's decode with a memory resource bytes for `+crypto::formats::raw+` and `+crypto::formats::pkcs8+`, a `+std::span+` or what converts to one (`+std::array+`, `+std::vector+`, a result's `+view()+`); a PEM text decodes with `+crypto::formats::pem(crypto::formats::pkcs8)+`. + +|`+keypair_decode_resource_spki+` +|the compile +|Decode a secp256k1 key pair, with or without a memory resource, from one of its formats: `+crypto::formats::raw+`, its secret key, `+crypto::formats::pkcs8+` or `+crypto::formats::pem(crypto::formats::pkcs8)+`; an SPKI holds a public key, which `+crypto::curves::secp256k1::public_key::decode(crypto::formats::spki, bytes)+` gives. + |`+kx_default_not_linked+` |the compile |Add `+/webcpp/crypto//kx-default+`, which links `+/third_party//sodium+` on every target. @@ -1698,6 +2122,14 @@ On MSVC, each case of `test/msvc` is proven to stop the build, at compile or at |the compile |Return `+std::optional>+`, a span over a tweak the lookup keeps, such as a map's entry; never the tweak by value. +|`+low_s_on_ed25519+` +|the compile +|Only an ECDSA signature has low S: Ed25519 and Schnorr signatures have no `+is_low_s()+` or `+low_s()+`, and need none, for no other S verifies as theirs. + +|`+make_removed+` +|the compile +|Call the factory named by its input, member or free: `+from_secret+` for a key pair, `+from_bytes+` for a public key, `+from_key+` for a cipher (`+crypto::from_secret(bytes)+`, `+K::from_secret(bytes)+`); `+make+` is gone, with no alias. + |`+memory_missing_definition_from_key+` |the link |Define `+std::pmr::memory_resource& webcpp::crypto::openssl_memory_resource() noexcept+` once in the program, returning a resource that is never destroyed. @@ -1714,10 +2146,22 @@ On MSVC, each case of `test/msvc` is proven to stop the build, at compile or at |the compile |Pass the nonce with std::move, once: a secret nonce signs one message. +|`+musig_nonce_gen_removed+` +|the compile +|Call musig::generate_nonce: crypto spells out the names libsecp256k1 abbreviates. + +|`+musig_nonce_gen_removed_call+` +|the compile +|As `+musig_nonce_gen_removed+`. + |`+musig_other_backend+` |the compile |Name `+backends::secp256k1+`, or leave the backend out: `+curves::secp256k1::musig::parse_public_nonce(encoded_nonce)+`. +|`+open_asynchronous_backend+` +|the compile +|Name a native backend, such as `+backends::sodium+`, for ChaCha20-Poly1305: WebCrypto has no ChaCha20-Poly1305, so neither its `+open+` nor its `+async_open+` completes on the browser's backend; there, use AES-GCM. + |`+openssl_memory_not_linked+` |the compile |A target has the define and not OpenSSL: put `+/webcpp/crypto//openssl+` in the same project requirements as the define, or remove the define. @@ -1738,9 +2182,105 @@ On MSVC, each case of `test/msvc` is proven to stop the build, at compile or at |the compile |Leave the backend out, as in `+curves::p256::keypair+`, or name `+backends::bearssl+`, and add `+/third_party//bearssl+`. -|`+pem_default_not_linked+` +|`+pem_decode_from_bytes+` +|the compile +|Give a PEM to `+crypto::decode+` as a text: a `+std::string_view+`, a `+std::string+`, or a contiguous range of `+char+` such as `+std::span+`; DER bytes decode with `+crypto::formats::spki+` or `+crypto::formats::pkcs8+` themselves. + +|`+pem_header_removed+` +|the compile +|Write and read PEM with `+crypto::encode+` and `+crypto::decode+` and `+crypto::formats::pem(crypto::formats::spki)+` or `+crypto::formats::pem(crypto::formats::pkcs8)+`, in `++`, codecs' armor over the key's DER; `+pem.hpp+` is gone, with no header left at its path. + +|`+pem_namespace_removed+` +|the compile +|Write and read PEM with `+crypto::encode+` and `+crypto::decode+` and `+crypto::formats::pem(crypto::formats::spki)+` or `+crypto::formats::pem(crypto::formats::pkcs8)+`, which take the label from the inner format; `+crypto::pem+`, its `+armour+`, `+unarmour+`, labels and `+armoured_size+`, is gone, with no alias. + +|`+pem_of_der+` +|the compile +|Armor the DER of a key: `+crypto::formats::pem(crypto::formats::spki)+` for a public key, `+crypto::formats::pem(crypto::formats::pkcs8)+` for a key pair; a signature's DER has no PEM. + +|`+pem_of_raw+` +|the compile +|As `+pem_of_der+`: armor the DER of a key, `+crypto::formats::pem(crypto::formats::spki)+` or `+crypto::formats::pem(crypto::formats::pkcs8)+`; a key's raw bytes have no PEM. + +|`+ph_removed+` +|the compile +|Name Ed25519ph's streaming signer `+curves::ed25519::prehashed_signer+`, the same `+begin+`, `+update+`, `+sign+` and `+verify+`; `+curves::ed25519::ph+` is gone, with no alias. + +|`+pkcs8_on_asynchronous_ed25519+` +|the compile +|Export the key pair with WebCrypto's `+exportKey+`, on the backend that keeps it, or make the key pair on a backend whose secret is in the program, libsodium, to encode it in `+crypto::formats::pkcs8+`, `+crypto::formats::raw+` or `+crypto::formats::pem(crypto::formats::pkcs8)+`; its public key's formats are available on every backend. + +|`+pkcs8_on_asynchronous_p256+` +|the compile +|Export the key pair with WebCrypto's `+exportKey+`, on the backend that keeps it, or make the key pair on a backend whose secret is in the program, BearSSL, to encode it in `+crypto::formats::pkcs8+`, `+crypto::formats::raw+` or `+crypto::formats::pem(crypto::formats::pkcs8)+`; its public key's formats are available on every backend. + +|`+prehashed_dynamic+` +|the compile +|Give `+crypto::signing_schemes::prehashed+` a digest of a fixed size: a `+std::array+`, a `+std::span+` or a `+boost::hash2::digest<32>+`. + +|`+prehashed_signer_verify_without_policy+` +|the compile +|Name the policy first: `+signer.verify(crypto::verification_policies::canonical, signature, public_key)+`, Ed25519ph's only policy. + +|`+prevouts_summary_removed+` +|the compile +|Name silent_payments::previous_outputs_summary and make_previous_outputs_summary: crypto spells out libsecp256k1's prevouts. + +|`+prevouts_summary_removed_call+` +|the compile +|As `+prevouts_summary_removed+`. + +|`+raw_on_asynchronous_x25519+` +|the compile +|Export the key pair with WebCrypto's `+exportKey+`, on the backend that keeps it, or make the key pair on a backend whose secret is in the program, libsodium, to read its secret with `+crypto::formats::raw+`, `+crypto::formats::pkcs8+` or `+crypto::formats::pem(crypto::formats::pkcs8)+`; its public key's formats are available on every backend. + +|`+recover_any_s+` +|the compile +|Recover under `+crypto::verification_policies::low_s_only+`, its only policy: a signature whose S is high is refused before recovery; made low first, n - s with bit 0 of the recovery id flipped, it keeps its signer. + +|`+recover_ecdsa_signature+` +|the compile +|Give `+recover+` a `+curves::secp256k1::recoverable_signature+`, which `+sign(crypto::signing_schemes::ecdsa_sha256_recoverable, input)+` gives, or made from 65 bytes with `+from_bytes+`; an ECDSA signature without its recovery id verifies with `+crypto::verify+` and the signer's public key. + +|`+recover_ecdsa_without_policy+` +|the compile +|Give `+recover+` a recoverable scheme and its policy, `+recover(crypto::signing_schemes::ecdsa_sha256_recoverable, crypto::verification_policies::low_s_only, signature, input)+` of a `+curves::secp256k1::recoverable_signature+`; an ECDSA signature without its recovery id verifies with `+crypto::verify+` and the signer's public key. + +|`+recover_without_policy+` +|the compile +|Name the policy after the scheme: `+curves::secp256k1::recover(crypto::signing_schemes::ecdsa_sha256_recoverable, crypto::verification_policies::low_s_only, signature, input)+`, its only policy. + +|`+refusal_reason_toy+` +|the compile +|Encode the signature with `+crypto::formats::raw+`: an Ed25519 or BIP340 signature has no DER form, its 64 bytes are the signature. + +|`+scheme_in_crypto_namespace+` +|the compile +|Name the scheme in `+crypto::signing_schemes+`: `+crypto::signing_schemes::ecdsa_sha256+`; the tags are no longer in `+crypto+`, with no alias. + +|`+seal_asynchronous_backend+` +|the compile +|Call `+async_seal+` on a backend that completes by itself: its synchronous forms cannot wait for it. + +|`+seal_box_associated_data+` +|the compile +|Call the box form, `+secret_key_encryption::seal(box, nonce, data)+` or the box's own `+seal(nonce, data)+`: a secret box or a crypto_box takes no associated data; authenticate it with an AEAD, as `+ciphers::xchacha20_poly1305<>+`. + +|`+seal_box_asynchronous_backend+` +|the compile +|Name a native backend, such as `+backends::sodium+`, for the crypto_box: WebCrypto has no crypto_box, so neither its `+seal+` nor its `+async_seal+` completes on the browser's backend. + +|`+seal_removed+` +|the compile +|Call crypto::secret_key_encryption::aead::seal and open, in , which every AEAD's header includes. + +|`+seal_removed_call+` +|the compile +|As `+seal_removed+`: call crypto::secret_key_encryption::aead::seal and open, which the cipher's header brings. + +|`+seal_secretbox_asynchronous_backend+` |the compile -|Add `+/webcpp/crypto//pem-default+`, which links `+/third_party//sodium+` on every target. +|Name a native backend, such as `+backends::sodium+`, for the secret box: WebCrypto has no secret box, so neither its `+seal+` nor its `+async_seal+` completes on the browser's backend; there, use AES-GCM. |`+secp256k1_not_linked+` |the compile @@ -1750,13 +2290,109 @@ On MSVC, each case of `test/msvc` is proven to stop the build, at compile or at |the compile |Name `+backends::secp256k1+`, or leave the backend out: `+curves::secp256k1::keypair+`. +|`+secp256k1_tweak_names_removed+` +|the compile +|Call public_key_tweak_add, public_key_tweak_mul, public_key_negate, public_key_combine, secret_key_tweak_add, secret_key_tweak_mul and secret_key_negate: crypto spells out the names libsecp256k1 abbreviates. + +|`+secp256k1_tweak_names_removed_call+` +|the compile +|As `+secp256k1_tweak_names_removed+`. + +|`+secret_moved+` +|the compile +|Name `+webcpp::secure::secret+`, from `++`, the type every secret crypto returns; `+crypto::secret+` moved to webcpp::secure, with no alias. + +|`+secretbox_header_removed+` +|the compile +|Include `++`, the secret boxes' header; `+ciphers/secretbox.hpp+` is gone, with no header left at its path. + +|`+secretbox_not_a_family+` +|the compile +|Name `+families::secretbox_xsalsa20poly1305+` or `+families::secretbox_xchacha20poly1305+`, or use `+secret_key_encryption::secretbox<>+` or `+secret_key_encryption::secretbox_xchacha20poly1305<>+`; an AEAD is `+ciphers::basic_chacha20_poly1305+`, as in `+ciphers::xchacha20_poly1305<>+`. + +|`+secretbox_removed+` +|the compile +|Name `+crypto::secret_key_encryption::secretbox+` and `+secretbox_xchacha20poly1305+`, the secret boxes' namespace; `+ciphers::secretbox+` is gone, with no alias. + +|`+secretbox_removed_call+` +|the compile +|As `+secretbox_removed+`: name `+crypto::secret_key_encryption::secretbox<>+` and `+secretbox_xchacha20poly1305<>+`, the names clang offers. + +|`+sign_asynchronous_backend+` +|the compile +|Call `+async_sign+` on a backend that completes by itself: its synchronous forms cannot wait for it. + +|`+sign_ed25519_ecdsa+` +|the compile +|Sign with `+crypto::signing_schemes::eddsa+` or `+crypto::signing_schemes::eddsa_prehashed+`, Ed25519's schemes; `+crypto::signing_schemes::ecdsa_sha256+` is P-256's and secp256k1's. + +|`+sign_ed25519_keccak+` +|the compile +|Sign with `+crypto::signing_schemes::eddsa+` or `+crypto::signing_schemes::eddsa_prehashed+`, Ed25519's schemes; Ethereum's `+crypto::signing_schemes::ecdsa_keccak256_recoverable+` is secp256k1's. + +|`+sign_ed25519_prehashed+` +|the compile +|Sign the message itself with `+crypto::signing_schemes::eddsa+`, RFC 8032's pure Ed25519, which takes no digest; to sign a message's SHA-512, use Ed25519ph, `+crypto::signing_schemes::eddsa_prehashed+`, or for a message given in pieces `+curves::ed25519::prehashed_signer+`. + +|`+sign_eddsa_prehashed_asynchronous_backend+` +|the compile +|Sign under `+crypto::signing_schemes::eddsa_prehashed+` with a key pair of a native backend: WebCrypto has no Ed25519ph; on the browser's backend, sign the message with `+crypto::signing_schemes::eddsa+`. + +|`+sign_eddsa_prehashed_digest_32+` +|the compile +|Give `+crypto::signing_schemes::eddsa_prehashed+` SHA-512's 64-byte digest, `+crypto::signing_schemes::prehashed{digest}+` of a `+std::array+`: RFC 8032 defines Ed25519ph over SHA-512. + |`+sign_eddsa_prehashed_message+` |the compile -|Give `+crypto::eddsa_prehashed+` the message's SHA-512 marked as a digest, `+crypto::prehashed{digest}+` of a `+std::array+`; sign the message itself with `+crypto::eddsa+`, or give it in pieces to `+curves::ed25519::prehashed_signer+`. +|Give `+crypto::signing_schemes::eddsa_prehashed+` the message's SHA-512 marked as a digest, `+crypto::signing_schemes::prehashed{digest}+` of a `+std::array+`; sign the message itself with `+crypto::signing_schemes::eddsa+`, or give it in pieces to `+curves::ed25519::prehashed_signer+`. + +|`+sign_free_ed25519_ecdsa+` +|the compile +|As `+sign_ed25519_ecdsa+`: `+crypto::sign+` calls the key pair's own `+sign+`, so sign with `+crypto::signing_schemes::eddsa+` or `+crypto::signing_schemes::eddsa_prehashed+`, Ed25519's schemes. + +|`+sign_free_public_key+` +|the compile +|Give `+crypto::sign+` the key pair, whose public key verifies: `+crypto::sign(key_pair, scheme, input)+`, then `+crypto::verify(scheme, policy, signature, input, public_key)+` or `+public_key.verify(scheme, policy, signature, input)+`. + +|`+sign_keccak_digest_20+` +|the compile +|As `+sign_p256_digest_48+`: give `+crypto::signing_schemes::ecdsa_keccak256_recoverable+` Keccak-256's 32-byte digest, or the message itself, which it hashes with Keccak-256. |`+sign_keccak_without_xkcp+` |the compile -|Add `+/third_party//xkcp+` to the program's Jamfile, whose Keccak-256 hashes the message, or build the 32-byte digest elsewhere and sign `+crypto::prehashed{digest}+`, which needs no XKCP. +|Add `+/third_party//xkcp+` to the program's Jamfile, whose Keccak-256 hashes the message, or build the 32-byte digest elsewhere and sign `+crypto::signing_schemes::prehashed{digest}+`, which needs no XKCP. + +|`+sign_p256_digest_48+` +|the compile +|Give `+crypto::signing_schemes::ecdsa_sha256+` SHA-256's 32-byte digest, `+crypto::signing_schemes::prehashed{digest}+` of a `+std::array+`, or the message itself, which it hashes. + +|`+sign_p256_keccak+` +|the compile +|Sign with `+crypto::signing_schemes::ecdsa_sha256+`, P-256's scheme; Ethereum's `+crypto::signing_schemes::ecdsa_keccak256_recoverable+` is secp256k1's. + +|`+sign_p256_schnorr+` +|the compile +|Sign with `+crypto::signing_schemes::ecdsa_sha256+`, P-256's scheme; BIP340's `+crypto::signing_schemes::schnorr+` is secp256k1's. + +|`+sign_schnorr_prehashed+` +|the compile +|Sign the message itself with `+crypto::signing_schemes::schnorr+`, BIP340's, which has no prehash mode; a taproot sighash, BIP341's tagged hash, is that message. + +|`+sign_secp256k1_eddsa+` +|the compile +|Sign with `+crypto::signing_schemes::ecdsa_sha256+`, `+crypto::signing_schemes::ecdsa_sha256_recoverable+`, `+crypto::signing_schemes::ecdsa_keccak256_recoverable+` or `+crypto::signing_schemes::schnorr+`, secp256k1's schemes; `+crypto::signing_schemes::eddsa+` is Ed25519's. + +|`+sign_secp256k1_not_a_scheme+` +|the compile +|Name the scheme with its tag: `+crypto::signing_schemes::ecdsa_sha256+`, `+crypto::signing_schemes::ecdsa_sha256_recoverable+`, `+crypto::signing_schemes::ecdsa_keccak256_recoverable+` or `+crypto::signing_schemes::schnorr+`. + +|`+sign_secp256k1_recoverable_digest_48+` +|the compile +|As `+sign_p256_digest_48+`: give `+crypto::signing_schemes::ecdsa_sha256_recoverable+` SHA-256's 32-byte digest, or the message itself, which it hashes. + +|`+sign_x25519+` +|the compile +|Sign with an Ed25519 key pair, a `+crypto::signing_keypair+`: an X25519 key pair agrees and does not sign. One Ed25519 key pair can do both: `+to_x25519()+` gives the X25519 key pair that agrees. |`+silent_payments_other_backend+` |the compile @@ -1766,9 +2402,125 @@ On MSVC, each case of `test/msvc` is proven to stop the build, at compile or at |the compile |Add `+/third_party//sodium+`. +|`+verify_asynchronous_backend+` +|the compile +|Call `+async_verify+` on a backend that completes by itself: its synchronous forms cannot wait for it. + +|`+verify_ecdsa_bytes_key+` +|the compile +|Give `+crypto::signing_schemes::ecdsa_sha256+` the public key as a typed object, `+curves::secp256k1::public_key::from_bytes(bytes)+` or `+curves::p256::public_key::from_bytes(bytes)+`: bytes never choose the curve. + +|`+verify_ed25519_bytes_signature+` +|the compile +|Make the 64 bytes received into a `+curves::ed25519::signature+` with `+curves::ed25519::signature::from_bytes+`, which checks their size, and verify that. + +|`+verify_ed25519ph_on_async_backend+` +|the compile +|Verify under `+crypto::signing_schemes::eddsa_prehashed+` on a native backend, `+crypto::verify+` and the key's `+verify+` alike: WebCrypto has no Ed25519ph; on the browser's backend, verify a signature of the message with `+crypto::signing_schemes::eddsa+`. + +|`+verify_eddsa_bytes_key+` +|the compile +|Give `+crypto::signing_schemes::eddsa+` (or `+crypto::signing_schemes::eddsa_prehashed+`) the public key as a `+curves::ed25519::public_key+`: `+key_pair.public_key()+`, or `+curves::ed25519::public_key::from_bytes(bytes)+` for a key received as bytes. + +|`+verify_eddsa_low_s_only+` +|the compile +|Verify Ed25519 and Ed25519ph under `+crypto::verification_policies::canonical+`, libsodium's rules, their only policy; `+low_s_only+` and `+any_s+` are ECDSA's. + +|`+verify_eddsa_prehashed_message+` +|the compile +|As `+sign_eddsa_prehashed_message+`: verify under `+crypto::signing_schemes::eddsa_prehashed+` the marker of the message's SHA-512, or the message itself under `+crypto::signing_schemes::eddsa+`. + +|`+verify_free_asynchronous_backend+` +|the compile +|As `+verify_asynchronous_backend+`. + +|`+verify_free_secp256k1_recoverable+` +|the compile +|As `+verify_member_secp256k1_recoverable+`: give a recoverable signature to `+curves::secp256k1::recover+`, which gives the signer's key; `+crypto::verify+` takes `+crypto::signing_schemes::ecdsa_sha256+` and `+crypto::signing_schemes::schnorr+` with a secp256k1 key. + +|`+verify_keccak_recoverable+` +|the compile +|Give the signature to `+curves::secp256k1::recover(crypto::signing_schemes::ecdsa_keccak256_recoverable, crypto::verification_policies::low_s_only, signature, input)+`, which gives the signer's key, and compare that key, or its address, with the one expected: Ethereum's recoverable ECDSA has no `+verify+`. + +|`+verify_member_ed25519_ecdsa+` +|the compile +|Verify with `+crypto::signing_schemes::eddsa+` or `+crypto::signing_schemes::eddsa_prehashed+`, Ed25519's schemes; `+crypto::signing_schemes::ecdsa_sha256+` is P-256's and secp256k1's, whose keys are `+curves::p256::basic_public_key+` and `+curves::secp256k1::public_key+`. + +|`+verify_member_eddsa_prehashed+` +|the compile +|Verify the message itself with `+crypto::signing_schemes::eddsa+`, RFC 8032's pure Ed25519, which takes no digest, as `+crypto::verify+` does; a signature of a message's SHA-512 is Ed25519ph's, verified with `+crypto::signing_schemes::eddsa_prehashed+`, or for a message given in pieces with `+curves::ed25519::prehashed_signer+`. + +|`+verify_member_p256_eddsa+` +|the compile +|Verify with `+crypto::signing_schemes::ecdsa_sha256+`, P-256's scheme; `+crypto::signing_schemes::eddsa+` is Ed25519's, whose key is a `+curves::ed25519::public_key+`. + +|`+verify_member_secp256k1_recoverable+` +|the compile +|Give a recoverable signature to `+curves::secp256k1::recover(crypto::signing_schemes::ecdsa_sha256_recoverable, crypto::verification_policies::low_s_only, signature, input)+`, which gives the signer's key; a public key verifies `+crypto::signing_schemes::ecdsa_sha256+` and `+crypto::signing_schemes::schnorr+`. + +|`+verify_p256_canonical+` +|the compile +|Verify P-256's ECDSA under `+crypto::verification_policies::low_s_only+`, for a signature crypto made, or `+any_s+`, for one a browser's WebCrypto or a passkey made, whose S may be high; `+canonical+` is Ed25519's and BIP340's. + +|`+verify_p256_secp256k1_signature+` +|the compile +|Give a P-256 key a `+curves::p256::ecdsa_signature+`, made from the 64 bytes received with `+curves::p256::ecdsa_signature::from_bytes+`; a secp256k1 signature verifies with a `+curves::secp256k1::public_key+`. + +|`+verify_schnorr_any_s+` +|the compile +|Verify BIP340 under `+crypto::verification_policies::canonical+`, its only policy; `+low_s_only+` and `+any_s+` are ECDSA's. + +|`+verify_schnorr_as_ecdsa+` +|the compile +|Verify a BIP340 signature with `+crypto::signing_schemes::schnorr+`, its scheme; `+crypto::signing_schemes::ecdsa_sha256+` takes a `+curves::secp256k1::ecdsa_signature+`, which `+sign(crypto::signing_schemes::ecdsa_sha256, input)+` gives. + +|`+verify_schnorr_span_removed+` +|the compile +|Make the 32 bytes into a typed key first, `+curves::secp256k1::xonly_public_key::from_bytes(bytes)+`, and give it to `+crypto::verify+`: the overload over a 32-byte span is removed, verification is typed. + +|`+verify_secp256k1_any_s+` +|the compile +|Verify secp256k1's ECDSA under `+crypto::verification_policies::low_s_only+`, its only policy, as libsecp256k1 and Bitcoin's rule; a signature whose S is high is made low with `+signature.low_s()+` first. + +|`+verify_without_policy+` +|the compile +|Name the verification policy after the scheme: `+crypto::verify(crypto::signing_schemes::eddsa, crypto::verification_policies::canonical, signature, message, public_key)+`; each scheme takes its own, `+canonical+` for Ed25519 and BIP340, `+low_s_only+` for secp256k1's ECDSA and `+recover+`, `+low_s_only+` or `+any_s+` for P-256's ECDSA. + +|`+verify_xonly_any_s+` +|the compile +|Verify BIP340 against the x-only key under `+crypto::verification_policies::canonical+`, its only policy, member and free; `+low_s_only+` and `+any_s+` are ECDSA's. + +|`+wipe_removed+` +|the compile +|Call `+webcpp::secure::erase_secret+`, which zeroes a contiguous range the program owns (a `+std::string&+`, a `+std::span+`) with stores the optimiser keeps; `+crypto::wipe+` is gone, with no alias. + +|`+x25519_asynchronous_backend+` +|the compile +|Call `+async_from_secret+`, `+async_generate+` or `+async_agree+` on a backend that completes by itself: an X25519 key pair's synchronous forms cannot wait for it. + +|`+x25519_constructions_other_backend+` +|the compile +|Name a backend that has X25519 as well, as libsodium, the default of crypto_kx, the boxes and the sealed box on every target: each takes an X25519 key pair of its own backend. + |`+x25519_default_not_linked+` |the compile |Add `+/webcpp/crypto//x25519-default+`, which links `+/third_party//sodium+` on every target. + +|`+x25519_formats_header_missing+` +|the compile +|Include `++`, which registers X25519's formats, beside `++`. + +|`+x25519_free_functions_removed+` +|the compile +|Make the key pair with `+curves::x25519::keypair::from_secret(secret)+`, then call its `+public_key()+`, and its `+agree+` with the peer's `+curves::x25519::public_key+` from `+from_bytes+`; the free functions over bytes are gone, with no alias. The `+x25519::public_key(secret)+` half pins clang's generic "no matching conversion for functional-style cast", since `+public_key+` now names the type. + +|`+xonly_default_constructed+` +|the compile +|Make the x-only key with a value: `+curves::secp256k1::xonly_public_key::from_bytes(bytes)+`, a public key's `+xonly()+`, a key pair's `+xonly_public_key()+` or MuSig2's `+aggregate_key::xonly_public_key()+`; it is never unset, since libsecp256k1 aborts on an unset key. + +|`+xonly_into_public_key+` +|the compile +|A 32-byte x-only key decodes into `+crypto::curves::secp256k1::xonly_public_key+`: `+crypto::decode(crypto::formats::raw(crypto::formats::xonly), bytes)+`, or its member `+xonly_public_key::decode+`; `+raw(crypto::formats::xonly)+` encodes a public key's x-only key, and its 33- or 65-byte SEC 1 point decodes into a `+public_key+` with `+crypto::formats::raw+`. |=== Elsewhere than MSVC these mistakes build, and nothing stops them; the fixtures record it: diff --git a/doc/generated/namespace-curves.adoc b/doc/generated/namespace-curves.adoc index 30fc16e0..07f0f983 100644 --- a/doc/generated/namespace-curves.adoc +++ b/doc/generated/namespace-curves.adoc @@ -13,7 +13,7 @@ |What it does |BIP 340 Schnorr and ECDSA signatures, recoverable signatures, ECDH in three forms, tweaks, ElligatorSwift, MuSig2, silent payments, SPKI and PKCS#8 -|Ed25519 signatures, and Ed25519ph over SHA-512, of a digest (`crypto::eddsa_prehashed`) or of a message given in pieces; a key pair's and a public key's conversion to X25519's typed keys +|Ed25519 signatures, and Ed25519ph over SHA-512, of a digest (`crypto::signing_schemes::eddsa_prehashed`) or of a message given in pieces; a key pair's and a public key's conversion to X25519's typed keys |Key agreement (Diffie-Hellman on Curve25519): two parties who exchanged public keys share a 32-byte secret, which `key_exchange::kx_keypair` and the boxes of `public_key_encryption` build on |Key pairs made from a 32-byte scalar or drawn from `random_device`, public keys validated once, as SEC 1's uncompressed point or two coordinates, ECDSA over SHA-256 of a message or a digest with RFC 6979's nonce, signed low S, raw and DER, and low S checked or normalized, ECDH's raw x coordinate, SPKI and PKCS#8 @@ -45,7 +45,7 @@ |libsecp256k1: native, Valgrind's memcheck (Linux; libsecp256k1's own `+ctime_tests.c+`, and webcpp's code around it: the key pair's making and `+secret()+`, its signatures and x-only tweak, ECDH in three forms (`+agree+`, `+agree_hashed+` and `+agree_point+`), the secret key's tweaks and negation, and PKCS#8), MemorySanitizer (Linux, clang; the same paths as memcheck's) and dudect (judged; on a runner GitHub hosts, by two of three runs; `+agree+`), nothing found; wasip2, dudect (judged; on a runner GitHub hosts, by two of three runs; `+agree+`), nothing found; not measured yet on wasip3, emscripten (<>) |libsodium: native, Valgrind's memcheck (Linux), MemorySanitizer (Linux, clang) and dudect (judged; on a runner GitHub hosts, by two of three runs), nothing found; wasip2, dudect (judged; on a runner GitHub hosts, by two of three runs), nothing found; not measured yet on wasip3, emscripten (<>) |libsodium: native, Valgrind's memcheck (Linux) and MemorySanitizer (Linux, clang), nothing found, and dudect (judged; on a runner GitHub hosts, by two of three runs): nothing found with arm64's DIT (data-independent timing) bit set, which webcpp sets around every call on 64-bit ARM under macOS, iOS, Linux, Android and Windows where the CPU has it, as Apple requires of constant-time code (link:https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms#Enable-DIT-for-constant-time-cryptographic-operations[Apple, Writing ARM64 code for Apple platforms: enable DIT for constant-time cryptographic operations]); the lane's dudect sets nothing itself and measures what a program gets: \|t\| 1.8 to 2.8 against the threshold 10 (2026-11-21, five runs), while its `dudect_planted`, an early-exit scan of the secret key run inside the same guard, reads \|t\| 66.72 and 65.53 (2026-11-21): DIT does not hide a leak. Without DIT, dudect times `agree` with an all-zero secret key against random ones at \|t\| 6.7 to 14.5 (2026-11-19) and 4.3 to 7.8 (2026-11-21, three runs): about one nanosecond in 15 µs. Each on an Apple M5 Max, from a release build. libsodium does not set DIT, and webcpp sets nothing on x86 or WebAssembly; wasip2, dudect (judged; on a runner GitHub hosts, by two of three runs): an open finding, its cause measured: dudect times `agree` with an all-zero secret key against random ones at \|t\| 13 to 32 (2026-11-18; a fixed key against another fixed key: 22.9) and 107 to 260 (2026-11-19), and 25.25 in the lane on 2026-11-21, against the threshold 10, under wasmtime 47 on an Apple M5 Max, from a release build. The cause is Apple silicon's DIT (data-independent timing), which wasmtime does not set (link:https://developer.apple.com/documentation/xcode/writing-arm64-code-for-apple-platforms#Enable-DIT-for-constant-time-cryptographic-operations[Apple, Writing ARM64 code for Apple platforms: enable DIT for constant-time cryptographic operations]): with DIT set in wasmtime's main thread, an experiment and not the lane, the same case reads \|t\| 1.5 to 2.1; no branch on a secret was found in the WebAssembly or in wasmtime's compiled code. The lane cannot set DIT from inside the WebAssembly, so it prints this value on wasip2 without judging it; the CI's x86-64 run measures it next; not measured yet on wasip3, emscripten (<>) -|BearSSL: native, Valgrind's memcheck (Linux; the key pair's making, `+sign+` of a digest (`+crypto::prehashed+`), which makes its signature low S without a branch, then `+normalize_low_s+` and `+is_low_s+` on it, `+agree+` and `+decode_pkcs8+`; BearSSL's own branches on its signing's verdicts listed in `+bearssl_verdicts.supp+`; nothing found with webcpp's fix to BearSSL's decoding of the nonce, whose leak of the nonce's bit length this checker found on 2026-11-21, including `+sign+` with its low-S step (Valgrind 3.22, arm64 Linux container, 2026-11-22)), MemorySanitizer (Linux, clang; the same paths as memcheck's; for the previous signing, found the same leak, nothing after the fix, including `+sign+` with its low-S step (clang 18, arm64 Linux container, 2026-11-22)) and dudect (judged; on a runner GitHub hosts, by two of three runs; `+sign+` of a digest and `+agree+`, each against the key pair's scalar; `+sign+` with its low-S step judged constant time, \|t\| 1.70 on Linux and 1.63 natively on an Apple M5 Max (release, one run each, 2026-11-22; provisional, measured again in the final quiet pass)), nothing found; wasip2, dudect (judged; on a runner GitHub hosts, by two of three runs; `+sign+` of a digest and `+agree+`, each against the key pair's scalar; `+sign+` with its low-S step judged constant time, \|t\| 1.70 on Linux and 1.63 natively on an Apple M5 Max (release, one run each, 2026-11-22; provisional, measured again in the final quiet pass)), nothing found; not measured yet on wasip3, emscripten (<>) +|BearSSL: native, Valgrind's memcheck (Linux; the key pair's making, `+sign+` of a digest (`+crypto::signing_schemes::prehashed+`), which makes its signature low S without a branch, then `+low_s()+` and `+is_low_s()+` of it, `+agree+` and the private formats, `+pkcs8+`, `+raw+` and `+pem(pkcs8)+` both ways; BearSSL's own branches on its signing's verdicts listed in `+bearssl_verdicts.supp+`; nothing found at webcpp's pin ae63032, whose patch submitted upstream closes upstream's leak of the nonce's bit length in `+sign+` that this checker found on 2026-11-21, `+sign+` with its low-S step included (Valgrind 3.22, arm64 Linux container, 2026-12-02)), MemorySanitizer (Linux, clang; the same paths as memcheck's; the same leak in `+sign+` on 2026-11-21 on upstream's BearSSL, nothing at webcpp's pin ae63032, `+sign+` with its low-S step included (clang 18, arm64 Linux container, 2026-12-02)) and dudect (judged; on a runner GitHub hosts, by two of three runs; `+sign+` of a digest and `+agree+`, each against the key pair's scalar; `+sign+` with its low-S step judged constant time, \|t\| 1.70 on Linux and 1.63 natively on an Apple M5 Max (release, one run each, 2026-11-22; provisional, measured again in the final quiet pass)), nothing found; wasip2, dudect (judged; on a runner GitHub hosts, by two of three runs; `+sign+` of a digest and `+agree+`, each against the key pair's scalar; `+sign+` with its low-S step judged constant time, \|t\| 1.70 on Linux and 1.63 natively on an Apple M5 Max (release, one run each, 2026-11-22; provisional, measured again in the final quiet pass)), nothing found; not measured yet on wasip3, emscripten (<>) |Standards |link:https://www.secg.org/sec2-v2.pdf[SEC 2, Recommended Elliptic Curve Domain Parameters], link:https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki[BIP 340, Schnorr signatures for secp256k1], link:https://www.rfc-editor.org/rfc/rfc6979[RFC 6979, deterministic ECDSA nonces], link:https://github.com/bitcoin/bips/blob/master/bip-0324.mediawiki[BIP 324, version 2 P2P encrypted transport protocol], link:https://github.com/bitcoin/bips/blob/master/bip-0327.mediawiki[BIP 327, MuSig2 for BIP340-compatible multi-signatures], link:https://github.com/bitcoin/bips/blob/master/bip-0352.mediawiki[BIP 352, Silent Payments] @@ -67,7 +67,7 @@ |Choose it for compatibility with |Bitcoin's keys and signatures; Nostr's event signatures (link:https://github.com/nostr-protocol/nips/blob/master/01.md[Nostr NIP-01, events signed with BIP 340 on secp256k1]); Ethereum's ECDSA verification with a known key; ECDH in the raw x-coordinate form of Nostr's encrypted messages (link:https://github.com/nostr-protocol/nips/blob/master/44.md[Nostr NIP-44, encrypted payloads]); Ethereum's recoverable signatures and uncompressed keys (link:https://ethereum.github.io/yellowpaper/paper.pdf[The Ethereum yellow paper, appendix F: ECDSA on secp256k1]), the address hashing being a domain library's; BIP 32's tweaks of the full key, its derivation of the tweak being a domain library's (link:https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki[BIP 32, hierarchical deterministic wallets]); keys exchanged with OpenSSL as SPKI or PKCS#8 (link:https://www.rfc-editor.org/rfc/rfc5480[RFC 5480, Elliptic Curve Cryptography Subject Public Key Information], link:https://www.rfc-editor.org/rfc/rfc5915[RFC 5915, Elliptic Curve Private Key Structure]), in DER or PEM (link:https://www.rfc-editor.org/rfc/rfc7468[RFC 7468, textual encodings of PKIX, PKCS and CMS structures (PEM)]); Bitcoin's version 2 transport, whose keys are ElligatorSwift encodings (link:https://github.com/bitcoin/bips/blob/master/bip-0324.mediawiki[BIP 324, version 2 P2P encrypted transport protocol]); MuSig2's multisignatures (link:https://github.com/bitcoin/bips/blob/master/bip-0327.mediawiki[BIP 327, MuSig2 for BIP340-compatible multi-signatures]); silent payments (link:https://github.com/bitcoin/bips/blob/master/bip-0352.mediawiki[BIP 352, Silent Payments]), the addresses and transactions being a domain library's -|SSH, Tor and Solana keys and signatures, and any protocol that names RFC 8032's Ed25519 or Ed25519ph; verification is strict (libsodium's rules), which some lenient verifiers are not. Not Bitcoin, Ethereum or Nostr, whose keys are secp256k1's +|SSH, Tor and Solana keys and signatures, and any protocol that names RFC 8032's Ed25519 or Ed25519ph; verification is canonical (libsodium's rules), which some lenient verifiers are not. Not Bitcoin, Ethereum or Nostr, whose keys are secp256k1's |TLS 1.3's and SSH's key exchange, WireGuard, Signal; libsodium's `crypto_box` keys, and the session keys of `crypto_kx` with `key_exchange::kx_keypair` (link:https://doc.libsodium.org/key_exchange[libsodium's documentation, key exchange]). The Ed25519 public key of a peer converts with its `to_x25519()`. A shared secret goes through a KDF before it keys a cipher. Every case of Wycheproof's X25519 file is tested (link:https://github.com/C2SP/wycheproof[Project Wycheproof, test vectors for cryptographic libraries]) |Browsers' WebCrypto, whose raw export of a P-256 public key is the uncompressed point `public_key::from_bytes` takes (link:https://www.w3.org/TR/WebCryptoAPI/[W3C Web Cryptography API]) and whose ECDH `deriveBits` is the raw x `agree` gives (link:https://www.w3.org/TR/WebCryptoAPI/#ecdh-operations[W3C Web Cryptography API, ECDH's deriveBits: the shared point's x coordinate, its first length bits]); passkeys and TLS. Not Bitcoin, Ethereum or Nostr, whose keys are secp256k1's |=== diff --git a/doc/generated/namespace-root.adoc b/doc/generated/namespace-root.adoc index 15013edd..b279056e 100644 --- a/doc/generated/namespace-root.adoc +++ b/doc/generated/namespace-root.adoc @@ -9,7 +9,7 @@ [cols="2h,5,5,5,5,5,5,5,5,5,5",options="header"] |=== -|Name |`random_device` |`secure::constant_time_equal` |`secure::erase_secret` |`secure::secret` |`error` |`pem` |`openssl_memory_resource` |Signatures |The key pair concepts |Making by type +|Name |`random_device` |`secure::constant_time_equal` |`secure::erase_secret` |`secure::secret` |`error` |`formats::pem` |`openssl_memory_resource` |Signatures |The key pair concepts |Making by type |Names | @@ -19,7 +19,7 @@ | | | -|`eddsa`, `eddsa_prehashed`, `ecdsa_sha256`, `ecdsa_sha256_recoverable`, `ecdsa_keccak256_recoverable`, `schnorr`, `prehashed`, `can_sign`, `can_verify`, `verify` +|`eddsa`, `eddsa_prehashed`, `ecdsa_sha256`, `ecdsa_sha256_recoverable`, `ecdsa_keccak256_recoverable`, `schnorr`, `prehashed`, `can_sign`, `can_verify`, `verify`, `low_s_only`, `any_s`, `canonical` |`keypair`, `signing_keypair`, `agreement_keypair`, `sign`, `agree` |`from_secret`, `from_bytes`, `from_key`, `generate` @@ -31,7 +31,7 @@ |Telling failures apart |A key's SPKI or PKCS#8 as text, to paste, store or exchange with OpenSSL |Keeping every allocation of OpenSSL's in the program's own resource, natively -|Naming the scheme of every signature, a digest as a digest, and a signature as a value of its curve and scheme, on every curve +|Naming the scheme and the verification policy of every signature, a digest as a digest, and a signature as a value of its curve and scheme, on every curve |Code written once for every curve's key pair, by what it does |Making a key pair from its secret, a public key or a signature from its bytes, or an AEAD or a secret box from its key, or drawing a key pair, the type named once @@ -41,7 +41,7 @@ |`` |`` |`` -|`` +|`` |`` |`` |`` @@ -53,9 +53,9 @@ |none |none |its values are the errors -|`invalid_encoding`, `invalid_input_size` +|codecs' `invalid_prefix`, `invalid_length`, `invalid_character`, `invalid_padding` for the armor; `invalid_encoding` for its DER |`memory_functions_refused`, `memory_functions_not_installed` -|`verify`: `invalid_signature`, and `invalid_public_key` for 32 x-only bytes that are no point; `sign`: `invalid_state`, `entropy_unavailable` (Schnorr's drawn randomness), `backend_failure`; a scheme and an input that do not go together stop the build +|`verify`: `invalid_signature`, and `invalid_public_key` for 32 x-only bytes that are no point; `sign`: `invalid_state`, `entropy_unavailable` (Schnorr's drawn randomness), `backend_failure`; a scheme and an input that do not go together, and a policy the scheme does not take or none, stop the build |the concepts: none, checked at compile time; `sign` and `agree`: what the key pair's own returns, and a key pair that does not do the operation, or arguments it does not take, stop the build |the member's: `from_secret(bytes)` returns what `K::from_secret(bytes)` returns, `from_bytes(bytes)` what `T::from_bytes(bytes)` returns, `from_key(key)` what `C::from_key(key)` returns, `generate()` what `K::generate()` returns @@ -65,7 +65,7 @@ |link:https://cwe.mitre.org/data/definitions/14.html[CWE-14, compiler removal of code to clear buffers] |link:https://cwe.mitre.org/data/definitions/14.html[CWE-14, compiler removal of code to clear buffers] |none -|link:https://www.rfc-editor.org/rfc/rfc7468[RFC 7468, textual encodings of PKIX, PKCS and CMS structures (PEM)], link:https://doc.libsodium.org/helpers#base64-encoding-decoding[libsodium's documentation, helpers: base64 encoding and decoding] +|link:https://www.rfc-editor.org/rfc/rfc7468[RFC 7468, textual encodings of PKIX, PKCS and CMS structures (PEM)] |link:https://docs.openssl.org/3.5/man3/OPENSSL_malloc/[OpenSSL 3.5's OPENSSL_malloc(3), CRYPTO_set_mem_functions] |link:https://www.rfc-editor.org/rfc/rfc8032[RFC 8032, the Edwards-curve Digital Signature Algorithm (EdDSA)], link:https://csrc.nist.gov/pubs/fips/186-5/final[FIPS 186-5, the Digital Signature Standard], link:https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki[BIP 340, Schnorr signatures for secp256k1], link:https://www.w3.org/TR/WebCryptoAPI/[W3C Web Cryptography API] |link:https://www.rfc-editor.org/rfc/rfc8032[RFC 8032, the Edwards-curve Digital Signature Algorithm (EdDSA)], link:https://www.rfc-editor.org/rfc/rfc7748[RFC 7748, Elliptic Curves for Security (X25519 and X448)], link:https://csrc.nist.gov/pubs/fips/186-5/final[FIPS 186-5, the Digital Signature Standard], link:https://www.secg.org/sec1-v2.pdf[SEC 1 version 2, Elliptic Curve Cryptography, sections 2.3.3 and 2.3.4: a point's encodings] @@ -77,9 +77,9 @@ |a secret sits in a `std::string`, a `std::vector` or an array of the program's and must not outlive its use; never `memset`, which the optimiser may drop; <> |crypto returns a secret: it wipes itself when destroyed or moved from, is copied only by `clone()`, and gives its bytes with `bytes()`; keep it in one variable; <> |you branch on a failure: forged data, a wrong size, no entropy -|a key goes to or comes from a file, a form or a tool as `-----BEGIN PUBLIC KEY-----` text; with the `encode_spki` and `encode_pkcs8` of `curves::ed25519`, `curves::x25519`, `curves::secp256k1` or `curves::p256` +|a key goes to or comes from a file, a form or a tool as `-----BEGIN PUBLIC KEY-----` text: `crypto::encode(formats::pem(formats::spki), public_key)`, or `formats::pem(formats::pkcs8)` of a key pair, on every curve, codecs' armor over the DER with the label of the inner format; <> |a native program on OpenSSL must allocate only from its own arena; on WebAssembly, BearSSL allocates nothing -|a key pair signs with `key_pair.sign(scheme, input)` or `sign(key_pair, scheme, input)`, and a signature is checked with `public_key.verify(scheme, signature, input)` or `verify(scheme, signature, input, public_key)`; a digest computed elsewhere, such as a Bitcoin sighash, an Ethereum EIP-191 digest or the SHA-512 Ed25519ph signs, goes in marked as `prehashed`, never as a bare span; the two recoverable schemes have no `verify`: their signature gives its key to `curves::secp256k1::recover`; a signature is a type of its curve and scheme, made from received bytes by `from_bytes` (<>) +|a key pair signs with `key_pair.sign(scheme, input)` or `sign(key_pair, scheme, input)`, and a signature is checked with `public_key.verify(scheme, policy, signature, input)` or `verify(scheme, policy, signature, input, public_key)`, the policy one the scheme takes (<>); a digest computed elsewhere, such as a Bitcoin sighash, an Ethereum EIP-191 digest or the SHA-512 Ed25519ph signs, goes in marked as `prehashed`, never as a bare span; the two recoverable schemes have no `verify`: their signature gives its key to `curves::secp256k1::recover`; a signature is a type of its curve and scheme, made from received bytes by `from_bytes` (<>) |a template takes any curve's key pair: `from_secret`, `generate`, a typed `public_key()`, `secret()`; a `signing_keypair` (Ed25519, P-256, secp256k1) adds `sign(scheme, input)`, whose `crypto::sign(key_pair, scheme, input)` is the free form, an `agreement_keypair` (X25519, P-256, secp256k1) `agree(peer)`, whose free form is `agree(key_pair, peer)` (<>) |generic code makes any key pair, public key, signature or AEAD by its type, each factory named by its input, or draws a key pair, `generate()`; the free forms of the static members `from_secret`, `from_bytes`, `from_key` and `generate`; a new key is drawn by `generate`, never made by `from_secret` from fixed bytes (<>) |=== diff --git a/doc/generated/sizes.adoc b/doc/generated/sizes.adoc index e166c784..87f28f1f 100644 --- a/doc/generated/sizes.adoc +++ b/doc/generated/sizes.adoc @@ -79,12 +79,6 @@ The lane sizes measured on 2026-11-21, at variant=release: native, clang-21 on D |not measured yet |not measured yet -|PEM on libsodium: armour of a 44-byte SPKI as PEM -|not measured yet -|not measured yet -|not measured yet -|not measured yet - |ChaCha20-Poly1305 on libsodium: seal of 16 KiB, 256-bit key |+35,984 B, gzip +22,273 B |+13,788 B, gzip +4,863 B diff --git a/doc/generated/use-cases.adoc b/doc/generated/use-cases.adoc index 58617e49..2f82efd4 100644 --- a/doc/generated/use-cases.adoc +++ b/doc/generated/use-cases.adoc @@ -73,14 +73,14 @@ |<> |Prove who wrote a message posted to a relay -|In `+curves::secp256k1+`: `+keypair::sign(crypto::schnorr, message)+`, `+crypto::verify+` +|In `+curves::secp256k1+`: `+keypair::sign(crypto::signing_schemes::schnorr, message)+`, `+crypto::verify+` |libsecp256k1 |`+/webcpp/crypto//crypto+` + `+/third_party//secp256k1+` |<> |Check a software update or a licence file -|In `+curves::secp256k1+`: `+keypair::sign(crypto::ecdsa_sha256, message)+`, `+public_key::from_bytes+`, `+crypto::verify+` +|In `+curves::secp256k1+`: `+keypair::sign(crypto::signing_schemes::ecdsa_sha256, message)+`, `+public_key::from_bytes+`, `+crypto::verify+` |libsecp256k1 |`+/webcpp/crypto//crypto+` + `+/third_party//secp256k1+` @@ -102,7 +102,7 @@ |<> |Find who signed a message or a transaction without being sent their key (Ethereum's signatures) -|In `+curves::secp256k1+`: `+keypair::sign(crypto::ecdsa_keccak256_recoverable, message)+`, `+recover+` +|In `+curves::secp256k1+`: `+keypair::sign(crypto::signing_schemes::ecdsa_keccak256_recoverable, message)+`, `+recover+` |libsecp256k1 |`+/webcpp/crypto//crypto+` + `+/third_party//secp256k1+` + @@ -116,12 +116,11 @@ `+/third_party//secp256k1+` |<> -|Store or exchange a secp256k1 key with OpenSSL or a config file -|In `+curves::secp256k1+`: `+encode_spki+`, `+decode_spki+`, `+encode_pkcs8+`, `+decode_pkcs8+`; `+webcpp::crypto::pem::armour+`, `+unarmour+` -|libsecp256k1, libsodium for PEM +|Store or exchange a secp256k1 key with OpenSSL, node or a config file, or publish its x-only key (the point, compressed or not, x-only, SPKI, PKCS#8, as DER or PEM text) +|In `+curves::secp256k1+`: `+crypto::encode+` and `+crypto::decode+` with `+crypto::formats::raw+`, `+spki+`, `+pkcs8+` and `+pem+`, and `+crypto::formats::compressed+` and `+xonly+`, on secp256k1's keys +|libsecp256k1 |`+/webcpp/crypto//crypto+` + -`+/third_party//secp256k1+` + -`+/webcpp/crypto//pem-default+` +`+/third_party//secp256k1+` |<> |Make a peer-to-peer connection's key exchange look like random bytes (BIP 324's transport; its packets are a domain library's) @@ -153,22 +152,30 @@ `+/webcpp/crypto//gcm-default+` |<> +|Read or write a wallet's key as WIF and its address as Base58Check text (a domain library's job) +|In `+curves::secp256k1+`: `+crypto::decode(crypto::formats::raw, bytes)+`, `+keypair.encode(crypto::formats::raw)+`, `+crypto::encode(crypto::formats::raw(crypto::formats::compressed), public_key)+`, with webcpp::hash's `+hash::formats::base58_with_checksum+` +|libsecp256k1 +|`+/webcpp/crypto//crypto+` + +`+/third_party//secp256k1+` + +`+/webcpp/hash//base58_with_checksum+` +|<> + |Sign a Bitcoin SegWit v0 input (a domain library's job) -|In `+curves::secp256k1+`: `+keypair::sign(crypto::ecdsa_sha256, crypto::prehashed{sighash})+`, `+to_der+`, `+is_low_s+`, `+normalize_low_s+` +|In `+curves::secp256k1+`: `+keypair::sign(crypto::signing_schemes::ecdsa_sha256, crypto::signing_schemes::prehashed{sighash})+`, `+signature.encode(crypto::formats::der)+`, `+signature.is_low_s()+`, `+signature.low_s()+` |libsecp256k1 |`+/webcpp/crypto//crypto+` + `+/third_party//secp256k1+` |<> |Derive a Bitcoin Taproot output key and spend by key path (a domain library's job) -|In `+curves::secp256k1+`: `+tweak_xonly+`, `+keypair::tweak_xonly+` +|In `+curves::secp256k1+`: `+keypair::xonly_public_key+`, `+xonly_public_key::tweak_add+`, `+xonly_public_key::verify_tweak+`, `+keypair::tweak_xonly+` |libsecp256k1 |`+/webcpp/crypto//crypto+` + `+/third_party//secp256k1+` |<> |Sign where allocation is restricted to the program's arena -|In `+curves::secp256k1+`: `+keypair::from_secret(secret, resource)+` +|In `+curves::secp256k1+`: `+keypair::from_secret(secret, resource)+`, or a stored key's `+keypair::decode(crypto::formats::pkcs8, bytes, resource)+` |libsecp256k1 |`+/webcpp/crypto//crypto+` + `+/third_party//secp256k1+` @@ -194,7 +201,7 @@ |<> |Sign and verify with Ed25519 (RFC 8032), or with Ed25519ph a message's SHA-512 or a large message in pieces -|In `+curves::ed25519+`: `+keypair::from_secret+`, `+keypair::generate+`, `+keypair::sign(crypto::eddsa, message)+`, `+keypair::sign(crypto::eddsa_prehashed, crypto::prehashed{digest})+`, `+crypto::verify+`; `+prehashed_signer+` +|In `+curves::ed25519+`: `+keypair::from_secret+`, `+keypair::generate+`, `+keypair::sign(crypto::signing_schemes::eddsa, message)+`, `+keypair::sign(crypto::signing_schemes::eddsa_prehashed, crypto::signing_schemes::prehashed{digest})+`, `+crypto::verify+`; `+prehashed_signer+` |libsodium |`+/webcpp/crypto//crypto+` + `+/webcpp/crypto//ed25519-default+` @@ -215,12 +222,11 @@ |<> |Export or import an Ed25519 or X25519 key in the standard forms OpenSSL and WebCrypto use: SPKI and PKCS#8 (RFC 8410), as DER or PEM text -|In `+curves+`: `+ed25519::encode_spki+`, `+decode_spki+`, `+encode_pkcs8+`, `+decode_pkcs8+`, the same in `+x25519+`; `+webcpp::crypto::pem::armour+`, `+unarmour+` +|In `+curves+`: `+crypto::encode+` and `+crypto::decode+` with `+crypto::formats::raw+`, `+spki+`, `+pkcs8+` and `+pem+`, on Ed25519's and X25519's keys |libsodium |`+/webcpp/crypto//crypto+` + `+/webcpp/crypto//ed25519-default+` + -`+/webcpp/crypto//x25519-default+` + -`+/webcpp/crypto//pem-default+` +`+/webcpp/crypto//x25519-default+` |<> |Encrypt messages in a chat app, on the web and natively, each with a random nonce @@ -268,7 +274,7 @@ |<> |Sign what a browser's WebCrypto verifies and verify what it signs (ECDSA on P-256 with SHA-256), low S where a protocol requires it, as webcpp::trystero's handshakes -|In `+curves::p256+`: `+keypair::sign(crypto::ecdsa_sha256, message)+`, `+crypto::verify+`, `+is_low_s+`, `+normalize_low_s+`; `+to_der+`, `+from_der+` for X.509 +|In `+curves::p256+`: `+keypair::sign(crypto::signing_schemes::ecdsa_sha256, message)+`, `+crypto::verify+`, `+signature.is_low_s()+`, `+signature.low_s()+`; `+crypto::encode+` and `+crypto::decode+` with `+crypto::formats::der+` for X.509 |BearSSL |`+/webcpp/crypto//crypto+` + `+/webcpp/crypto//p256-default+` @@ -281,16 +287,22 @@ `+/webcpp/crypto//p256-default+` |<> -|Export or import a P-256 key in the forms OpenSSL and WebCrypto's spki and pkcs8 use (SPKI, PKCS#8), as DER or PEM text -|In `+curves::p256+`: `+encode_spki+`, `+decode_spki+`, `+encode_pkcs8+`, `+decode_pkcs8+`; `+webcpp::crypto::pem::armour+`, `+unarmour+` -|BearSSL, libsodium for PEM +|Export or import a P-256 key in the forms OpenSSL and WebCrypto's raw, spki and pkcs8 use (the point, compressed or not, SPKI, PKCS#8), as DER or PEM text +|In `+curves::p256+`: `+crypto::encode+` and `+crypto::decode+` with `+crypto::formats::raw+`, `+spki+`, `+pkcs8+` and `+pem+`, and `+crypto::formats::compressed+`, on P-256's keys +|BearSSL |`+/webcpp/crypto//crypto+` + -`+/webcpp/crypto//p256-default+` + -`+/webcpp/crypto//pem-default+` +`+/webcpp/crypto//p256-default+` |<> +|Register a public key a browser or a device uploads as PEM, store it as the one SPKI, and verify its signatures, high S too +|In `+curves::p256+`: `+crypto::decode(crypto::formats::pem(crypto::formats::spki), text)+`, `+crypto::encode(crypto::formats::spki, key)+`, `+crypto::verify+` under `+crypto::verification_policies::any_s+` +|BearSSL +|`+/webcpp/crypto//crypto+` + +`+/webcpp/crypto//p256-default+` +|<> + |Sign a peer-to-peer handshake a browser's WebCrypto verifies, low S, check the peer's, and derive the session key from ECDH (Trystero's protocol is webcpp::trystero's) -|In `+curves::p256+`: `+keypair::sign(crypto::ecdsa_sha256, crypto::prehashed{digest})+`, `+is_low_s+`, `+crypto::verify+`, `+keypair::agree+`; `+webcpp::hash::hkdf+` for the key +|In `+curves::p256+`: `+keypair::sign(crypto::signing_schemes::ecdsa_sha256, crypto::signing_schemes::prehashed{digest})+`, `+signature.is_low_s()+`, `+crypto::verify+`, `+keypair::agree+`; `+webcpp::hash::hkdf+` for the key |BearSSL |`+/webcpp/crypto//crypto+` + `+/webcpp/crypto//p256-default+` diff --git a/doc/llms.txt b/doc/llms.txt index 41f947a2..b413455b 100644 --- a/doc/llms.txt +++ b/doc/llms.txt @@ -16,20 +16,20 @@ Generated by doc/tables/generate.py with the page's tables. Page: https://webcpp - async_from_key: Makes an AEAD or a secret box from its key bytes, asynchronously: `Cipher::from_key(key_bytes)` run when the operation is initiated, its result posted to `completion_executor`. - async_seal: Seals a message in place, asynchronously: `aead_cipher.seal` run when the operation is initiated, its result posted to `completion_executor`. - async_open: Opens a message in place, asynchronously: `aead_cipher.open` run when the operation is initiated, its result posted to `completion_executor`. -- [async_from_secret, async_generate, async_sign, async_verify](https://webcpporg.github.io/libs/crypto/#crypto-async): Ed25519's asynchronous from_secret, generate, sign and verify with `crypto::eddsa`, and on a native backend with `crypto::eddsa_prehashed` (Ed25519ph, which WebCrypto lacks), each completing through a post to the executor the call gives, with any Asio completion token. Header . Backends: libsodium (/third_party//sodium) on native, wasip2, wasip3, emscripten. Use it to: sign and verify with Ed25519 in a coroutine. +- [async_from_secret, async_generate, async_sign, async_verify](https://webcpporg.github.io/libs/crypto/#crypto-async): Ed25519's asynchronous from_secret, generate, sign and verify with `crypto::signing_schemes::eddsa`, and on a native backend with `crypto::signing_schemes::eddsa_prehashed` (Ed25519ph, which WebCrypto lacks), each completing through a post to the executor the call gives, with any Asio completion token. Header . Backends: libsodium (/third_party//sodium) on native, wasip2, wasip3, emscripten. Use it to: sign and verify with Ed25519 in a coroutine. - async_from_secret: Makes an Ed25519, an X25519 or a P-256 key pair from its secret bytes, asynchronously: `Keypair::from_secret(secret_bytes)` run when the operation is initiated, its result posted to `completion_executor`. - async_generate: Makes an Ed25519, an X25519 or a P-256 key pair from a fresh secret, asynchronously: `Keypair::generate()` run when the operation is initiated (the system's generator is drawn from then), its result posted to `completion_executor`. - async_sign: Signs with an Ed25519 or a P-256 key pair, asynchronously: `key_pair.sign(signing_scheme, signing_input)` run when the operation is initiated, its result posted to `completion_executor`. - - async_verify: Verifies an Ed25519 signature (RFC 8032's pure Ed25519), asynchronously, strictly: `crypto::verify(crypto::eddsa, signature_value, message_bytes, public_key)` run when the operation is initiated, its result posted to `completion_executor`. + - async_verify: Verifies an Ed25519 signature (RFC 8032's pure Ed25519) under a verification policy, asynchronously: `crypto::verify(crypto::signing_schemes::eddsa, crypto::verification_policies::canonical, ...)` run when the operation is initiated, its result posted to `completion_executor`. - [async_from_secret, async_generate, async_agree](https://webcpporg.github.io/libs/crypto/#crypto-async): X25519's asynchronous from_secret, generate and agree, of a key pair and a peer's `curves::x25519::public_key`, each completing through a post to the executor the call gives, with any Asio completion token. Header . Backends: libsodium (/third_party//sodium) on native, wasip2, wasip3, emscripten. - async_from_secret: Makes an Ed25519, an X25519 or a P-256 key pair from its secret bytes, asynchronously: `Keypair::from_secret(secret_bytes)` run when the operation is initiated, its result posted to `completion_executor`. - async_generate: Makes an Ed25519, an X25519 or a P-256 key pair from a fresh secret, asynchronously: `Keypair::generate()` run when the operation is initiated (the system's generator is drawn from then), its result posted to `completion_executor`. - async_agree: Agrees a shared secret, asynchronously: `key_pair.agree(peer_public_key)` run when the operation is initiated, its result posted to `completion_executor`: X25519's (RFC 7748), or P-256's ECDH raw x coordinate, as WebCrypto's `deriveBits` with ECDH on P-256 gives its 256 bits. -- [async_from_secret, async_generate, async_sign, async_verify, async_agree](https://webcpporg.github.io/libs/crypto/#crypto-async): P-256's asynchronous from_secret, generate, ECDSA sign and verify with `crypto::ecdsa_sha256`, of a message hashed with SHA-256 or `crypto::prehashed{digest}`, and ECDH's raw x, each completing through a post to the executor the call gives, with any Asio completion token. Header . Backends: BearSSL (/third_party//bearssl) on native, wasip2, wasip3, emscripten. +- [async_from_secret, async_generate, async_sign, async_verify, async_agree](https://webcpporg.github.io/libs/crypto/#crypto-async): P-256's asynchronous from_secret, generate, ECDSA sign and verify with `crypto::signing_schemes::ecdsa_sha256`, of a message hashed with SHA-256 or `crypto::signing_schemes::prehashed{digest}`, and ECDH's raw x, each completing through a post to the executor the call gives, with any Asio completion token. Header . Backends: BearSSL (/third_party//bearssl) on native, wasip2, wasip3, emscripten. - async_from_secret: Makes an Ed25519, an X25519 or a P-256 key pair from its secret bytes, asynchronously: `Keypair::from_secret(secret_bytes)` run when the operation is initiated, its result posted to `completion_executor`. - async_generate: Makes an Ed25519, an X25519 or a P-256 key pair from a fresh secret, asynchronously: `Keypair::generate()` run when the operation is initiated (the system's generator is drawn from then), its result posted to `completion_executor`. - async_sign: Signs with an Ed25519 or a P-256 key pair, asynchronously: `key_pair.sign(signing_scheme, signing_input)` run when the operation is initiated, its result posted to `completion_executor`. - - async_verify: Verifies a P-256 ECDSA signature over SHA-256, asynchronously: `crypto::verify(crypto::ecdsa_sha256, signature_value, signing_input, public_key)` run when the operation is initiated, its result posted to `completion_executor`; the message is hashed with SHA-256, as WebCrypto's ECDSA with SHA-256 verifies, or `crypto::prehashed{digest}` gives its digest. + - async_verify: Verifies a P-256 ECDSA signature over SHA-256 under a verification policy, asynchronously: `crypto::verify(crypto::signing_schemes::ecdsa_sha256, verification_policy, ...)` run when the operation is initiated, its result posted to `completion_executor`; the message is hashed with SHA-256, as WebCrypto's ECDSA with SHA-256 verifies, or `crypto::signing_schemes::prehashed{digest}` gives its digest. - async_agree: Agrees a shared secret, asynchronously: `key_pair.agree(peer_public_key)` run when the operation is initiated, its result posted to `completion_executor`: X25519's (RFC 7748), or P-256's ECDH raw x coordinate, as WebCrypto's `deriveBits` with ECDH on P-256 gives its 256 bits. - [error](https://webcpporg.github.io/libs/crypto/#crypto-errors): Every failure's value, fixed and never reused, in the category webcpp.crypto. Header . Backends: no backend (/webcpp/crypto//crypto) on native, wasip2, wasip3, emscripten. Use it to: tell a forged message from a malformed one. - error_category: The category of every error. @@ -38,10 +38,6 @@ Generated by doc/tables/generate.py with the page's tables. Page: https://webcpp - [openssl_memory_resource, backends::openssl::install_memory_functions](https://webcpporg.github.io/libs/crypto/#crypto-memory-openssl): With `WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE`, natively, every allocation of OpenSSL's in the process goes to a `std::pmr::memory_resource` the program defines. Header . Backends: OpenSSL (/webcpp/crypto//openssl) on native. Use it to: keep every allocation of OpenSSL's in the program's arena. - openssl_memory_resource: The resource every allocation of OpenSSL's in the process goes to, from any thread: declared by `` under `WEBCPP_CRYPTO_OPENSSL_MEMORY_RESOURCE` and defined once by the program. - install_memory_functions: Installs webcpp's adapter as OpenSSL's memory functions, so that every allocation of OpenSSL's in the process goes to `openssl_memory_resource()`. -- [pem::armour, pem::unarmour](https://webcpporg.github.io/libs/crypto/#crypto-key-formats): PEM (RFC 7468): DER as base64 between `-----BEGIN