From 6410708c66381cdb89dd6725827687fb0543125a Mon Sep 17 00:00:00 2001 From: R Date: Mon, 23 Nov 2026 10:22:01 -0300 Subject: [PATCH 01/76] crypto: no local name in a header hides a program's global on MSVC --- doc/llms.txt | 36 +- include/webcpp/crypto/async.hpp | 662 ++++++++++-------- include/webcpp/crypto/backends/bearssl.hpp | 200 +++--- include/webcpp/crypto/backends/openssl.hpp | 129 ++-- include/webcpp/crypto/backends/sodium.hpp | 522 +++++++------- include/webcpp/crypto/ciphers/aead.hpp | 10 +- include/webcpp/crypto/ciphers/aes.hpp | 10 +- include/webcpp/crypto/ciphers/gcm.hpp | 89 +-- include/webcpp/crypto/curves/ed25519.hpp | 26 +- .../webcpp/crypto/curves/ed25519/formats.hpp | 4 +- include/webcpp/crypto/curves/p256.hpp | 20 +- include/webcpp/crypto/curves/p256/formats.hpp | 4 +- include/webcpp/crypto/curves/secp256k1.hpp | 54 +- .../crypto/curves/secp256k1/ellswift.hpp | 8 +- .../crypto/curves/secp256k1/formats.hpp | 8 +- .../webcpp/crypto/curves/secp256k1/musig.hpp | 34 +- .../curves/secp256k1/silent_payments.hpp | 10 +- .../webcpp/crypto/curves/secp256k1/tweak.hpp | 14 +- include/webcpp/crypto/curves/x25519.hpp | 8 +- .../webcpp/crypto/curves/x25519/formats.hpp | 4 +- include/webcpp/crypto/curves/x25519/kx.hpp | 8 +- include/webcpp/crypto/detail/heavy.hpp | 310 ++++---- include/webcpp/crypto/detail/p_curves.hpp | 110 +-- include/webcpp/crypto/detail/timing.hpp | 28 +- include/webcpp/crypto/equal.hpp | 4 +- include/webcpp/crypto/hybrid/box.hpp | 14 +- include/webcpp/crypto/hybrid/sealed_box.hpp | 81 ++- include/webcpp/crypto/keypair.hpp | 2 +- include/webcpp/crypto/make.hpp | 4 +- include/webcpp/crypto/pem.hpp | 318 +++++---- include/webcpp/crypto/secret.hpp | 28 +- include/webcpp/crypto/signing.hpp | 2 +- test/Jamfile | 9 + test/heavy_test.cpp | 8 +- .../heavy_without_threads.cpp | 4 +- .../heavy_without_threads_first.cpp | 4 +- test/msvc/heavy_without_threads/app.cpp | 4 +- test/user_globals_test.cpp | 140 ++++ 38 files changed, 1631 insertions(+), 1299 deletions(-) create mode 100644 test/user_globals_test.cpp diff --git a/doc/llms.txt b/doc/llms.txt index fc07f555..3bd27411 100644 --- a/doc/llms.txt +++ b/doc/llms.txt @@ -13,22 +13,22 @@ Generated by doc/tables/generate.py with the page's tables. Page: https://webcpp - max: The largest value `operator()` gives. - entropy: The entropy of a value, in bits: every bit is the system's. - [async_make, async_seal, async_open](https://webcpporg.github.io/libs/crypto/#crypto-async): AES-GCM's asynchronous make, seal and open, 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; OpenSSL (/webcpp/crypto//openssl) on native, wasip2, wasip3. Use it to: seal or open a record inside an event loop without waiting. - - async_make: Makes an AES-GCM object, an Ed25519 key pair or a P-256 key pair from its key bytes, asynchronously: `Algorithm::make(key_bytes)` run when the operation is initiated, its result posted to `executor`. - - async_seal: Seals a message in place, asynchronously: `aead.seal` run when the operation is initiated, its result posted to `executor`. - - async_open: Opens a message in place, asynchronously: `aead.open` run when the operation is initiated, its result posted to `executor`. + - async_make: Makes an AES-GCM object, an Ed25519 key pair or a P-256 key pair from its key bytes, asynchronously: `Algorithm::make(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_make, async_generate, async_sign, async_verify](https://webcpporg.github.io/libs/crypto/#crypto-async): Ed25519's asynchronous make, generate, sign and verify with `crypto::eddsa`, 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_make: Makes an AES-GCM object, an Ed25519 key pair or a P-256 key pair from its key bytes, asynchronously: `Algorithm::make(key_bytes)` run when the operation is initiated, its result posted to `executor`. - - async_generate: Makes an Ed25519 or a P-256 key pair from a fresh seed or scalar, asynchronously: `Keypair::generate()` run when the operation is initiated (the system's generator is drawn from then), its result posted to `executor`. - - async_sign: Signs with an Ed25519 or a P-256 key pair, asynchronously: `key_pair.sign(scheme, input)` run when the operation is initiated, its result posted to `executor`. - - async_verify: Verifies an Ed25519 signature (RFC 8032's pure Ed25519), asynchronously, strictly: `crypto::verify(crypto::eddsa, signature, message, public_key)` run when the operation is initiated, its result posted to `executor`. + - async_make: Makes an AES-GCM object, an Ed25519 key pair or a P-256 key pair from its key bytes, asynchronously: `Algorithm::make(key_bytes)` run when the operation is initiated, its result posted to `completion_executor`. + - async_generate: Makes an Ed25519 or a P-256 key pair from a fresh seed or scalar, 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_bytes, message_bytes, public_key)` run when the operation is initiated, its result posted to `completion_executor`. - [async_agree](https://webcpporg.github.io/libs/crypto/#crypto-async): X25519's asynchronous agree, 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_agree: Agrees an X25519 shared secret, asynchronously: `curves::x25519::agree` run when the operation is initiated, its result posted to `executor`. + - async_agree: Agrees an X25519 shared secret, asynchronously: `curves::x25519::agree` run when the operation is initiated, its result posted to `completion_executor`. - [async_make, async_generate, async_sign, async_verify, async_agree](https://webcpporg.github.io/libs/crypto/#crypto-async): P-256's asynchronous make, 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_make: Makes an AES-GCM object, an Ed25519 key pair or a P-256 key pair from its key bytes, asynchronously: `Algorithm::make(key_bytes)` run when the operation is initiated, its result posted to `executor`. - - async_generate: Makes an Ed25519 or a P-256 key pair from a fresh seed or scalar, asynchronously: `Keypair::generate()` run when the operation is initiated (the system's generator is drawn from then), its result posted to `executor`. - - async_sign: Signs with an Ed25519 or a P-256 key pair, asynchronously: `key_pair.sign(scheme, input)` run when the operation is initiated, its result posted to `executor`. - - async_verify: Verifies a P-256 ECDSA signature over SHA-256, asynchronously: `crypto::verify(crypto::ecdsa_sha256, signature, input, public_key)` run when the operation is initiated, its result posted to `executor`; the message is hashed with SHA-256, as WebCrypto's ECDSA with SHA-256 verifies, or `crypto::prehashed{digest}` gives its digest. - - async_agree: Agrees a P-256 shared secret, ECDH's raw x coordinate, asynchronously: `key_pair.agree(peer_public_key)` run when the operation is initiated, its result posted to `executor`, as WebCrypto's `deriveBits` with ECDH on P-256 gives its 256 bits. + - async_make: Makes an AES-GCM object, an Ed25519 key pair or a P-256 key pair from its key bytes, asynchronously: `Algorithm::make(key_bytes)` run when the operation is initiated, its result posted to `completion_executor`. + - async_generate: Makes an Ed25519 or a P-256 key pair from a fresh seed or scalar, 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_bytes, 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_agree: Agrees a P-256 shared secret, ECDH's raw x coordinate, asynchronously: `key_pair.agree(peer_public_key)` run when the operation is initiated, its result posted to `completion_executor`, as WebCrypto's `deriveBits` with ECDH on P-256 gives its 256 bits. - [equal](https://webcpporg.github.io/libs/crypto/#crypto-equal): Compares two tags or MACs in constant time. Header . Backends: no backend (/webcpp/crypto//crypto) on native, wasip2, wasip3, emscripten. Use it to: check a webhook's or an API's HMAC signature. - equal: Whether two byte sequences are equal, in a time that does not depend on their contents. - [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. @@ -51,11 +51,11 @@ Generated by doc/tables/generate.py with the page's tables. Page: https://webcpp - decrypt: Decrypts whole blocks in place. - [ciphers::gcm, aes128_gcm, aes256_gcm](https://webcpporg.github.io/libs/crypto/#crypto-gcm): AES-GCM, authenticated encryption in place with an incremental seal and an incremental open in two passes. Header , . Backends: BearSSL (/third_party//bearssl) on native, wasip2, wasip3, emscripten; OpenSSL (/webcpp/crypto//openssl) on native, wasip2, wasip3. Default: OpenSSL on native, Clang and GCC; OpenSSL on native, MSVC; BearSSL on wasip2, wasip3; BearSSL on emscripten. Use it to: encrypt a database field, a cookie or a token at rest. - make: Expands a key into a new object. - - async_make: Expands a key into a new object, asynchronously: `make` run when the operation is initiated, its result posted to `executor`; the member form of `crypto::async_make(executor, key_bytes, token)`, which calls it. + - async_make: Expands a key into a new object, asynchronously: `make` run when the operation is initiated, its result posted to `completion_executor`; the member form of `crypto::async_make(executor, key_bytes, token)`, which calls it. - seal: Seals a message in place: `data_bytes` holds the plaintext before and the ciphertext after. - - async_seal: Seals a message in place, asynchronously: `seal` run when the operation is initiated, its result posted to `executor`; the member form of `crypto::async_seal(executor, aead, iv_bytes, additional_data_bytes, data_bytes, token)`, which calls it. + - async_seal: Seals a message in place, asynchronously: `seal` run when the operation is initiated, its result posted to `completion_executor`; the member form of `crypto::async_seal(executor, aead, iv_bytes, additional_data_bytes, data_bytes, token)`, which calls it. - open: Opens a message in place: `data_bytes` holds the ciphertext before and the plaintext after. - - async_open: Opens a message in place, asynchronously: `open` run when the operation is initiated, its result posted to `executor`; the member form of `crypto::async_open`, which calls it with the executor and the object before this function's arguments. + - async_open: Opens a message in place, asynchronously: `open` run when the operation is initiated, its result posted to `completion_executor`; the member form of `crypto::async_open`, which calls it with the executor and the object before this function's arguments. - begin_seal: Begins an incremental seal: the IV and the whole additional data first, both read before this returns. - update: Encrypts the next piece of the message in place. - result: Ends the message with its tag. @@ -245,8 +245,8 @@ Generated by doc/tables/generate.py with the page's tables. Page: https://webcpp - seal: Seals a message in place: `data_bytes` holds the plaintext before and the ciphertext after. - open: Opens a message in place: `data_bytes` holds the ciphertext before and the plaintext after. - [hybrid::sealed_box](https://webcpporg.github.io/libs/crypto/#crypto-sealed-box): libsodium's sealed boxes, `crypto_box_seal`: anonymous encryption to a public key under a key pair drawn per message, 48 bytes longer than the message, which only the recipient's key pair opens. Header . Backends: libsodium (/third_party//sodium) on native, wasip2, wasip3, emscripten. Default: libsodium on native, wasip2, wasip3, emscripten. Use it to: let anyone send a message that only the recipient can read, without saying who sent it (anonymous feedback, a drop box). - - seal: Seals `message` into `out`, of `message.size() + overhead` bytes: the drawn public key, the tag, then the ciphertext. - - open: Opens `sealed` into `out`, of `sealed.size() - overhead` bytes, with the recipient's keys. + - seal: Seals `message_bytes` into `output_bytes`, of `message_bytes.size() + overhead` bytes: the drawn public key, the tag, then the ciphertext. + - open: Opens `sealed_bytes` into `output_bytes`, of `sealed_bytes.size() - overhead` bytes, with the recipient's keys. ## Default backend per family diff --git a/include/webcpp/crypto/async.hpp b/include/webcpp/crypto/async.hpp index f857c085..65a9adf1 100644 --- a/include/webcpp/crypto/async.hpp +++ b/include/webcpp/crypto/async.hpp @@ -164,71 +164,78 @@ struct async_engine; /** * The initiation of a cheap function on a synchronous backend: runs the synchronous call (its * guards first) when the operation is initiated and posts the completion, its result split by @ref - * completion_of, to `executor`, whence it reaches the handler's associated executor; the post's - * storage is the handler's associated allocator's. + * completion_of, to `completion_executor`, whence it reaches the handler's associated executor; the + * post's storage is the handler's associated allocator's. */ struct post_initiation { /** - * Runs `operation` and posts `handler` with its error code and, for a call that returns a - * value, the value, or on an error the empty one (ruling R-A3). + * Runs `bound_call` and posts `completion_handler` with its error code and, for a call that + * returns a value, the value, or on an error the empty one (ruling R-A3). * - * @param handler The completion handler. - * @param executor The executor the completion is posted to. - * @param operation The synchronous call, bound to its arguments. + * @param completion_handler The completion handler. + * @param completion_executor The executor the completion is posted to. + * @param bound_call The synchronous call, bound to its arguments. */ template - void operator()(Handler&& handler, Executor const& executor, Operation operation) const { - deliver(std::forward(handler), executor, operation()); + void operator()(Handler&& completion_handler, Executor const& completion_executor, + Operation bound_call) const { + deliver(std::forward(completion_handler), completion_executor, bound_call()); } private: // A call without a value completes with its error code alone. template - static void deliver(Handler&& handler, Executor const& executor, - boost::system::result const& done) { - boost::system::error_code const code = done ? boost::system::error_code{} : done.error(); - webcpp::asio::post(executor, webcpp::asio::append(std::forward(handler), code)); + static void deliver(Handler&& completion_handler, Executor const& completion_executor, + boost::system::result const& call_result) { + boost::system::error_code const completion_code = + call_result ? boost::system::error_code{} : call_result.error(); + webcpp::asio::post( + completion_executor, + webcpp::asio::append(std::forward(completion_handler), completion_code)); } // A call with a value completes with it, or on an error with the empty one. template requires(!std::is_void_v) - static void deliver(Handler&& handler, Executor const& executor, - boost::system::result&& done) { - if (done) { - webcpp::asio::post(executor, - webcpp::asio::append(std::forward(handler), - boost::system::error_code{}, *std::move(done))); + static void deliver(Handler&& completion_handler, Executor const& completion_executor, + boost::system::result&& call_result) { + if (call_result) { + webcpp::asio::post( + completion_executor, + webcpp::asio::append(std::forward(completion_handler), + boost::system::error_code{}, *std::move(call_result))); } else { - webcpp::asio::post(executor, - webcpp::asio::append(std::forward(handler), done.error(), - async_access::empty())); + webcpp::asio::post( + completion_executor, + webcpp::asio::append(std::forward(completion_handler), call_result.error(), + async_access::empty())); } } }; /** - * Initiates a cheap function on a synchronous backend (design D23): runs `operation()` when the + * Initiates a cheap function on a synchronous backend (design D23): runs `bound_call()` when the * operation is initiated (on the initiating thread; for `deferred`, when the deferred operation - * is launched), and completes through a post to `executor`, never inside the call, - * with `operation()`'s result split into its error code and its value. + * is launched), and completes through a post to `completion_executor`, never inside the call, + * with `bound_call()`'s result split into its error code and its value. * * @tparam CompletionToken Any completion token, of signature `completion_of::type`, `R` - * `operation()`'s result. - * @param executor The executor the completion is posted to, whence it reaches the handler's - * associated executor. - * @param token The completion token. - * @param operation The synchronous call, bound to its arguments: a `noexcept` call without + * `bound_call()`'s result. + * @param completion_executor The executor the completion is posted to, whence it reaches the + * handler's associated executor. + * @param completion_token The completion token. + * @param bound_call The synchronous call, bound to its arguments: a `noexcept` call without * arguments returning `boost::system::result` or `boost::system::result`, called once. * @return What the completion token's `async_result` gives. */ template -auto complete_by_post(Executor const& executor, CompletionToken& token, Operation operation) { +auto complete_by_post(Executor const& completion_executor, CompletionToken& completion_token, + Operation bound_call) { static_assert(std::is_nothrow_invocable_v, "webcpp::crypto: an asynchronous operation's call reports its errors as values"); using signature = completion_of>::type; return webcpp::asio_backend::async_initiate( - post_initiation{}, token, executor, std::move(operation)); + post_initiation{}, completion_token, completion_executor, std::move(bound_call)); } /** Whether `Type` is an AES-GCM, `ciphers::gcm`. */ @@ -305,15 +312,15 @@ constexpr void refuse_async_sign() noexcept { * argument list, does not have to outlive the call, which a `deferred` operation launches later. * * @tparam Input A message's type or `prehashed`. - * @param input The message or the marker. + * @param signing_input The message or the marker. * @return The view the operation keeps. */ template -[[nodiscard]] constexpr auto kept_input(Input const& input) noexcept { +[[nodiscard]] constexpr auto kept_input(Input const& signing_input) noexcept { if constexpr (is_prehashed_v) { - return input; + return signing_input; } else { - return message_bytes(input); + return message_bytes(signing_input); } } @@ -323,20 +330,20 @@ template * initiated. * * @tparam Algorithm AES-GCM or a key pair of an algorithm WebCrypto has. - * @param executor The executor the completion is posted to. + * @param completion_executor The executor the completion is posted to. * @param key_bytes The key's bytes. - * @param token The completion token. + * @param completion_token The completion token. * @return What the completion token's `async_result` gives. */ template -auto initiate_make(Executor const& executor, std::span key_bytes, - CompletionToken&& token) { +auto initiate_make(Executor const& completion_executor, std::span key_bytes, + CompletionToken&& completion_token) { using backend = Algorithm::backend_type; if constexpr (asynchronous_backend_v) { return async_engine::template make( - executor, key_bytes, std::forward(token)); + completion_executor, key_bytes, std::forward(completion_token)); } else { - return complete_by_post(executor, token, + return complete_by_post(completion_executor, completion_token, [key_bytes]() noexcept { return Algorithm::make(key_bytes); }); } } @@ -347,18 +354,19 @@ auto initiate_make(Executor const& executor, std::span key_b * operation is initiated. * * @tparam Keypair A key pair of an algorithm WebCrypto has. - * @param executor The executor the completion is posted to. - * @param token The completion token. + * @param completion_executor The executor the completion is posted to. + * @param completion_token The completion token. * @return What the completion token's `async_result` gives. */ template -auto initiate_generate(Executor const& executor, CompletionToken&& token) { +auto initiate_generate(Executor const& completion_executor, CompletionToken&& completion_token) { using backend = Keypair::backend_type; if constexpr (asynchronous_backend_v) { return async_engine::template generate( - executor, std::forward(token)); + completion_executor, std::forward(completion_token)); } else { - return complete_by_post(executor, token, []() noexcept { return Keypair::generate(); }); + return complete_by_post(completion_executor, completion_token, + []() noexcept { return Keypair::generate(); }); } } @@ -369,28 +377,31 @@ auto initiate_generate(Executor const& executor, CompletionToken&& token) { * initiated. * * @tparam Keypair An Ed25519 or a P-256 key pair. - * @param executor The executor the completion is posted to. + * @param completion_executor The executor the completion is posted to. * @param key_pair The key pair, the caller's until the completion. - * @param scheme The scheme. - * @param input The message or the marker. - * @param token The completion token. + * @param signing_scheme The scheme. + * @param signing_input The message or the marker. + * @param completion_token The completion token. * @return What the completion token's `async_result` gives. */ template -auto initiate_sign(Executor const& executor, Keypair const& key_pair, Scheme scheme, - Input const& input, CompletionToken&& token) { +auto initiate_sign(Executor const& completion_executor, Keypair const& key_pair, + Scheme signing_scheme, Input const& signing_input, + CompletionToken&& completion_token) { if constexpr (!can_sign) { refuse_async_sign(); } else { using backend = Keypair::backend_type; if constexpr (asynchronous_backend_v) { - return async_engine::sign(executor, key_pair, scheme, kept_input(input), - std::forward(token)); + return async_engine::sign(completion_executor, key_pair, signing_scheme, + kept_input(signing_input), + std::forward(completion_token)); } else { - return complete_by_post(executor, token, - [&key_pair, scheme, kept = kept_input(input)]() noexcept { - return key_pair.sign(scheme, kept); - }); + return complete_by_post( + completion_executor, completion_token, + [&key_pair, signing_scheme, kept = kept_input(signing_input)]() noexcept { + return key_pair.sign(signing_scheme, kept); + }); } } } @@ -403,34 +414,37 @@ auto initiate_sign(Executor const& executor, Keypair const& key_pair, Scheme sch * * @tparam Backend The backend. * @tparam Scheme `eddsa_t`; another scheme stops the build. - * @param executor The executor the completion is posted to. - * @param signature The signature. - * @param message The message. + * @param completion_executor The executor the completion is posted to. + * @param signature_bytes The signature. + * @param message_bytes The message. * @param public_key The public key, copied into the operation. - * @param policy `curves::ed25519::strict`. - * @param token The completion token. + * @param verification_policy `curves::ed25519::strict`. + * @param completion_token The completion token. * @return What the completion token's `async_result` gives. */ template -auto initiate_verify_ed25519(Executor const& executor, std::span signature, - Input const& message, curves::ed25519::public_key const& public_key, - [[maybe_unused]] curves::ed25519::strict_t policy, - CompletionToken&& token) { +auto initiate_verify_ed25519(Executor const& completion_executor, + std::span signature_bytes, + Input const& message_bytes, + curves::ed25519::public_key const& public_key, + [[maybe_unused]] curves::ed25519::strict_t verification_policy, + CompletionToken&& completion_token) { if constexpr (!std::is_same_v) { static_assert(refused_v, "webcpp::crypto: an Ed25519 public key verifies crypto::eddsa."); } else if constexpr (!can_verify) { check_input(); } else if constexpr (asynchronous_backend_v) { - return async_engine::verify(executor, eddsa, signature, kept_input(message), - public_key, policy, - std::forward(token)); + return async_engine::verify( + completion_executor, eddsa, signature_bytes, kept_input(message_bytes), public_key, + verification_policy, std::forward(completion_token)); } else { - return complete_by_post(executor, token, - [signature, kept = kept_input(message), public_key]() noexcept { - return public_key.template verify( - eddsa, signature, kept, curves::ed25519::strict); - }); + return complete_by_post( + completion_executor, completion_token, + [signature_bytes, kept = kept_input(message_bytes), public_key]() noexcept { + return public_key.template verify(eddsa, signature_bytes, kept, + curves::ed25519::strict); + }); } } @@ -439,9 +453,10 @@ auto initiate_verify_ed25519(Executor const& executor, std::span`, on any backend that has it; the other algorithms crypto * has are not in WebCrypto: call their `make`. * @tparam Executor The executor's type, an Asio executor (an `io_context`'s or a strand's). - * @tparam CompletionToken Any completion token for the signature `token` states. - * @param executor The executor the completion is posted to. + * @tparam CompletionToken Any completion token for the signature `completion_token` states. + * @param completion_executor The executor the completion is posted to. * @param key_bytes `Algorithm::key_size` bytes for AES-GCM, the seed's `seed_size` for an * Ed25519 key pair, the secret scalar's `secret_key_size` (32 bytes, big-endian) for a P-256 key * pair. - * @param token The completion token, of signature `void(boost::system::error_code, Algorithm)`; - * on an error the object is empty, and every member refuses with `invalid_state` + * @param completion_token The completion token, of signature `void(boost::system::error_code, + * Algorithm)`; on an error the object is empty, and every member refuses with `invalid_state` * (`invalid_key_size`, `invalid_secret_key` for a P-256 scalar 0 or not below the group order, * `errc::not_enough_memory`, `backend_failure`). * @return What the completion token's `async_result` gives. */ template -auto async_make(Executor const& executor, std::span key_bytes, - CompletionToken&& token) { - detail::timing_guard const timing; +auto async_make(Executor const& completion_executor, std::span key_bytes, + CompletionToken&& completion_token) { + detail::timing_guard const timing_scope; if constexpr (!detail::is_gcm_v && !detail::is_webcrypto_keypair_v) { static_assert(detail::refused_v, "webcpp::crypto: async_make takes AES-GCM or a key pair of an algorithm " "WebCrypto has (Ed25519, P-256): call the synchronous make for the others."); } else { - return Algorithm::async_make(executor, key_bytes, std::forward(token)); + return Algorithm::async_make(completion_executor, key_bytes, + std::forward(completion_token)); } } /** * Makes an Ed25519 or a P-256 key pair from a fresh seed or scalar, asynchronously: * `Keypair::generate()` run when the operation is initiated (the system's generator is drawn from - * then), its result posted to `executor`. + * then), its result posted to `completion_executor`. * - * The free form of `Keypair::async_generate(executor, token)`, which it calls. + * The free form of `Keypair::async_generate(completion_executor, completion_token)`, which it + * calls. * * @tparam Keypair A `curves::ed25519::basic_keypair`, by default the family's * `curves::ed25519::keypair`, or a `curves::p256::basic_keypair`; the other key pairs * are not in WebCrypto: call their `generate`. * @tparam Executor The executor's type, an Asio executor (an `io_context`'s or a strand's). - * @tparam CompletionToken Any completion token for the signature `token` states. - * @param executor The executor the completion is posted to. - * @param token The completion token, of signature `void(boost::system::error_code, Keypair)`; - * on an error the key pair is empty, and every member refuses with `invalid_state` + * @tparam CompletionToken Any completion token for the signature `completion_token` states. + * @param completion_executor The executor the completion is posted to. + * @param completion_token The completion token, of signature `void(boost::system::error_code, + * Keypair)`; on an error the key pair is empty, and every member refuses with `invalid_state` * (`entropy_unavailable`, `backend_failure`). * @return What the completion token's `async_result` gives. */ template -auto async_generate(Executor const& executor, CompletionToken&& token) { - detail::timing_guard const timing; +auto async_generate(Executor const& completion_executor, CompletionToken&& completion_token) { + detail::timing_guard const timing_scope; if constexpr (!detail::is_webcrypto_keypair_v) { static_assert(detail::refused_v, "webcpp::crypto: async_generate takes a key pair of an algorithm WebCrypto " "has (Ed25519, P-256): call the synchronous generate for the others."); } else { - return Keypair::async_generate(executor, std::forward(token)); + return Keypair::async_generate(completion_executor, + std::forward(completion_token)); } } /** - * Seals a message in place, asynchronously: `aead.seal` run when the operation is initiated, its - * result posted to `executor`. + * Seals a message in place, asynchronously: `aead_cipher.seal` run when the operation is initiated, + * its result posted to `completion_executor`. * * The free form of - * `aead.async_seal(executor, iv_bytes, additional_data_bytes, data_bytes, token)`, which it calls. + * `aead_cipher.async_seal(completion_executor, iv_bytes, additional_data_bytes, data_bytes, + * completion_token)`, which it calls. * - * `aead` and the spans are the caller's until the completion: a synchronous backend reads and - * writes them before the call returns, the browser's later. `data_bytes` holds the ciphertext at - * the completion. A guard's refusal (`invalid_iv_size`, `message_too_long`, `invalid_state`) + * `aead_cipher` and the spans are the caller's until the completion: a synchronous backend reads + * and writes them before the call returns, the browser's later. `data_bytes` holds the ciphertext + * at the completion. A guard's refusal (`invalid_iv_size`, `message_too_long`, `invalid_state`) * leaves it untouched, a backend's failure zeroes it, as `seal` does. * * @tparam Gcm A `ciphers::gcm`; the other AEADs are not in WebCrypto: call their `seal`. * @tparam Executor The executor's type, an Asio executor (an `io_context`'s or a strand's). - * @tparam CompletionToken Any completion token for the signature `token` states. - * @param executor The executor the completion is posted to. - * @param aead The keyed object. + * @tparam CompletionToken Any completion token for the signature `completion_token` states. + * @param completion_executor The executor the completion is posted to. + * @param aead_cipher The keyed object. * @param iv_bytes 1 to `max_iv_size` bytes, never reused under this key. * @param additional_data_bytes Authenticated, not encrypted. * @param data_bytes The message. - * @param token The completion token, of signature + * @param completion_token The completion token, of signature * `void(boost::system::error_code, Gcm::result_type)`: the tag; on an error the zeroed tag. * @return What the completion token's `async_result` gives. */ template -auto async_seal(Executor const& executor, Gcm& aead, std::span iv_bytes, +auto async_seal(Executor const& completion_executor, Gcm& aead_cipher, + std::span iv_bytes, std::span additional_data_bytes, - std::span data_bytes, CompletionToken&& token) { - detail::timing_guard const timing; + std::span data_bytes, CompletionToken&& completion_token) { + detail::timing_guard const timing_scope; if constexpr (!detail::is_gcm_v>) { static_assert(detail::refused_v, "webcpp::crypto: async_seal takes AES-GCM, the AEAD WebCrypto has: call seal " "for the others."); } else { - return aead.async_seal(executor, iv_bytes, additional_data_bytes, data_bytes, - std::forward(token)); + return aead_cipher.async_seal(completion_executor, iv_bytes, additional_data_bytes, + data_bytes, std::forward(completion_token)); } } /** - * Opens a message in place, asynchronously: `aead.open` run when the operation is initiated, its - * result posted to `executor`. + * Opens a message in place, asynchronously: `aead_cipher.open` run when the operation is initiated, + * its result posted to `completion_executor`. * * The free form of - * `aead.async_open(executor, iv_bytes, additional_data_bytes, data_bytes, tag_bytes, token)`, which - * it calls. + * `aead_cipher.async_open(completion_executor, iv_bytes, additional_data_bytes, data_bytes, + * tag_bytes, completion_token)`, which it calls. * - * `aead` and the spans are the caller's until the completion. `data_bytes` holds the plaintext at - * a successful completion; a wrong tag (`authentication_failed`) or a backend's failure zeroes - * it, a guard's refusal leaves it untouched, as `open` does. + * `aead_cipher` and the spans are the caller's until the completion. `data_bytes` holds the + * plaintext at a successful completion; a wrong tag (`authentication_failed`) or a backend's + * failure zeroes it, a guard's refusal leaves it untouched, as `open` does. * * @tparam Gcm A `ciphers::gcm`; the other AEADs are not in WebCrypto: call their `open`. * @tparam Executor The executor's type, an Asio executor (an `io_context`'s or a strand's). - * @tparam CompletionToken Any completion token for the signature `token` states. - * @param executor The executor the completion is posted to. - * @param aead The keyed object. + * @tparam CompletionToken Any completion token for the signature `completion_token` states. + * @param completion_executor The executor the completion is posted to. + * @param aead_cipher The keyed object. * @param iv_bytes The IV of the seal. * @param additional_data_bytes The additional data of the seal. * @param data_bytes The ciphertext. * @param tag_bytes The seal's tag, 16 bytes. - * @param token The completion token, of signature `void(boost::system::error_code)`. + * @param completion_token The completion token, of signature `void(boost::system::error_code)`. * @return What the completion token's `async_result` gives. */ template -auto async_open(Executor const& executor, Gcm& aead, std::span iv_bytes, +auto async_open(Executor const& completion_executor, Gcm& aead_cipher, + std::span iv_bytes, std::span additional_data_bytes, std::span data_bytes, std::span tag_bytes, - CompletionToken&& token) { - detail::timing_guard const timing; + CompletionToken&& completion_token) { + detail::timing_guard const timing_scope; if constexpr (!detail::is_gcm_v>) { static_assert(detail::refused_v, "webcpp::crypto: async_open takes AES-GCM, the AEAD WebCrypto has: call open " "for the others."); } else { - return aead.async_open(executor, iv_bytes, additional_data_bytes, data_bytes, tag_bytes, - std::forward(token)); + return aead_cipher.async_open(completion_executor, iv_bytes, additional_data_bytes, + data_bytes, tag_bytes, + std::forward(completion_token)); } } /** - * Signs with an Ed25519 or a P-256 key pair, asynchronously: `key_pair.sign(scheme, input)` run - * when the operation is initiated, its result posted to `executor`. + * 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`. * - * The free form of `key_pair.async_sign(executor, scheme, input, token)`, which it calls. + * The free form of `key_pair.async_sign(completion_executor, signing_scheme, signing_input, + * completion_token)`, which it calls. * * Ed25519 signs the message with `crypto::eddsa`; P-256 signs with `crypto::ecdsa_sha256` the * message, which it hashes with SHA-256, as WebCrypto's ECDSA with SHA-256 signs, or @@ -606,38 +629,41 @@ auto async_open(Executor const& executor, Gcm& aead, std::span`, of any size, * empty included, or for P-256 `crypto::prehashed<32>`. - * @tparam CompletionToken Any completion token for the signature `token` states. - * @param executor The executor the completion is posted to. + * @tparam CompletionToken Any completion token for the signature `completion_token` states. + * @param completion_executor The executor the completion is posted to. * @param key_pair The key pair. - * @param scheme `crypto::eddsa` or `crypto::ecdsa_sha256`. - * @param input The message, or for P-256 `crypto::prehashed{digest}`, its 32-byte SHA-256 digest. - * @param token The completion token, of signature `void(error_code, signature)`, the signature - * a `std::array` of 64 bytes (P-256's r then s, IEEE P1363's form, WebCrypto's); on an error it - * is 64 zeros (`invalid_state`, `backend_failure`). + * @param signing_scheme `crypto::eddsa` or `crypto::ecdsa_sha256`. + * @param signing_input The message, or for P-256 `crypto::prehashed{digest}`, its 32-byte SHA-256 + * digest. + * @param completion_token The completion token, of signature `void(error_code, signature)`, the + * signature a `std::array` of 64 bytes (P-256's r then s, IEEE P1363's form, WebCrypto's); on an + * error it is 64 zeros (`invalid_state`, `backend_failure`). * @return What the completion token's `async_result` gives. */ template -auto async_sign(Executor const& executor, Keypair const& key_pair, Scheme scheme, - Input const& input, CompletionToken&& token) { - detail::timing_guard const timing; +auto async_sign(Executor const& completion_executor, Keypair const& key_pair, Scheme signing_scheme, + Input const& signing_input, CompletionToken&& completion_token) { + detail::timing_guard const timing_scope; if constexpr (!detail::is_webcrypto_keypair_v) { static_assert( detail::refused_v, "webcpp::crypto: async_sign takes a key pair of an algorithm WebCrypto has " "(Ed25519, P-256): call the key pair's synchronous signing function for the others."); } else { - return key_pair.async_sign(executor, scheme, input, std::forward(token)); + return key_pair.async_sign(completion_executor, signing_scheme, signing_input, + std::forward(completion_token)); } } /** * Verifies an Ed25519 signature (RFC 8032's pure Ed25519), asynchronously, strictly: - * `crypto::verify(crypto::eddsa, signature, message, public_key)` run when the operation - * is initiated, its result posted to `executor`. + * `crypto::verify(crypto::eddsa, signature_bytes, message_bytes, public_key)` run when the + * operation is initiated, its result posted to `completion_executor`. * * The free form of - * `public_key.async_verify(executor, crypto::eddsa, signature, message, token)`, which it - * calls, and which runs the key's `verify`, with the same work. + * `public_key.async_verify(completion_executor, crypto::eddsa, signature_bytes, + * message_bytes, completion_token)`, which it calls, and which runs the key's `verify`, with the + * same work. * * The input is checked as `crypto::can_verify` checks it, before anything else: a marker stops * the build (Ed25519 signs the message itself). The signature's and the message's bytes are the @@ -646,25 +672,27 @@ auto async_sign(Executor const& executor, Keypair const& key_pair, Scheme scheme * @tparam Backend The backend; by default the asynchronous family's. * @tparam Executor The executor's type, an Asio executor (an `io_context`'s or a strand's). * @tparam Input A message, bytes that convert to `std::span`. - * @tparam CompletionToken Any completion token for the signature `token` states. - * @param executor The executor the completion is posted to. - * @param scheme `crypto::eddsa`. - * @param signature 64 bytes. - * @param message The signed bytes. + * @tparam CompletionToken Any completion token for the signature `completion_token` states. + * @param completion_executor The executor the completion is posted to. + * @param signing_scheme `crypto::eddsa`. + * @param signature_bytes 64 bytes. + * @param message_bytes The signed bytes. * @param public_key The signer's public key. - * @param token The completion token, of signature `void(boost::system::error_code)`: + * @param completion_token The completion token, of signature `void(boost::system::error_code)`: * `invalid_signature` for a signature of another size, and for one that does not verify; * `backend_failure`. * @return What the completion token's `async_result` gives. */ template , class Executor, class Input, class CompletionToken> -auto async_verify(Executor const& executor, eddsa_t scheme, std::span signature, - Input const& message, curves::ed25519::public_key const& public_key, - CompletionToken&& token) { - detail::timing_guard const timing; - return public_key.template async_verify(executor, scheme, signature, message, - std::forward(token)); +auto async_verify(Executor const& completion_executor, eddsa_t signing_scheme, + std::span signature_bytes, Input const& message_bytes, + curves::ed25519::public_key const& public_key, + CompletionToken&& completion_token) { + detail::timing_guard const timing_scope; + return public_key.template async_verify( + completion_executor, signing_scheme, signature_bytes, message_bytes, + std::forward(completion_token)); } /** @@ -677,36 +705,42 @@ auto async_verify(Executor const& executor, eddsa_t scheme, std::span`. - * @tparam CompletionToken Any completion token for the signature `token` states. - * @param executor The executor the completion is posted to. - * @param scheme `crypto::eddsa`. - * @param signature 64 bytes. - * @param message The signed bytes. + * @tparam CompletionToken Any completion token for the signature `completion_token` states. + * @param completion_executor The executor the completion is posted to. + * @param signing_scheme `crypto::eddsa`. + * @param signature_bytes 64 bytes. + * @param message_bytes The signed bytes. * @param public_key The signer's public key. - * @param policy `curves::ed25519::strict` (libsodium's rules), the only policy declared. - * @param token The completion token, of signature `void(boost::system::error_code)`, as the - * overload without a policy completes. + * @param verification_policy `curves::ed25519::strict` (libsodium's rules), the only policy + * declared. + * @param completion_token The completion token, of signature `void(boost::system::error_code)`, as + * the overload without a policy completes. * @return What the completion token's `async_result` gives. */ template , class Executor, class Input, class CompletionToken> -auto async_verify(Executor const& executor, eddsa_t scheme, std::span signature, - Input const& message, curves::ed25519::public_key const& public_key, - curves::ed25519::strict_t policy, CompletionToken&& token) { - detail::timing_guard const timing; - return public_key.template async_verify(executor, scheme, signature, message, policy, - std::forward(token)); +auto async_verify(Executor const& completion_executor, eddsa_t signing_scheme, + std::span signature_bytes, Input const& message_bytes, + curves::ed25519::public_key const& public_key, + curves::ed25519::strict_t verification_policy, + CompletionToken&& completion_token) { + detail::timing_guard const timing_scope; + return public_key.template async_verify( + completion_executor, signing_scheme, signature_bytes, message_bytes, verification_policy, + std::forward(completion_token)); } /** * Verifies a P-256 ECDSA signature over SHA-256, asynchronously: - * `crypto::verify(crypto::ecdsa_sha256, signature, input, public_key)` run when the operation is - * initiated, its result posted to `executor`; the message is hashed with SHA-256, as WebCrypto's - * ECDSA with SHA-256 verifies, or `crypto::prehashed{digest}` gives its digest. + * `crypto::verify(crypto::ecdsa_sha256, signature_bytes, 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. * * The free form of - * `public_key.async_verify(executor, crypto::ecdsa_sha256, signature, input, token)`, which it - * calls, and which runs the key's `verify`, with the same work. + * `public_key.async_verify(completion_executor, crypto::ecdsa_sha256, signature_bytes, + * signing_input, completion_token)`, which it calls, and which runs the key's `verify`, with the + * same work. * * A high S and a low S are both accepted, as `crypto::verify` and WebCrypto accept them. The * input is checked as `crypto::can_verify` checks it, before anything else: a marker on a backend @@ -718,26 +752,27 @@ auto async_verify(Executor const& executor, eddsa_t scheme, std::span`, of any size, * empty included, or `crypto::prehashed<32>`. - * @tparam CompletionToken Any completion token for the signature `token` states. - * @param executor The executor the completion is posted to. - * @param scheme `crypto::ecdsa_sha256`. - * @param signature 64 bytes, r then s (IEEE P1363's form, WebCrypto's); `curves::p256::from_der` - * reads DER. - * @param input The signed message, or `crypto::prehashed{digest}`, its 32-byte SHA-256 digest. + * @tparam CompletionToken Any completion token for the signature `completion_token` states. + * @param completion_executor The executor the completion is posted to. + * @param signing_scheme `crypto::ecdsa_sha256`. + * @param signature_bytes 64 bytes, r then s (IEEE P1363's form, WebCrypto's); + * `curves::p256::from_der` reads DER. + * @param signing_input The signed message, or `crypto::prehashed{digest}`, its 32-byte SHA-256 + * digest. * @param public_key The signer's public key, validated when it was made. - * @param token The completion token, of signature `void(boost::system::error_code)`: + * @param completion_token The completion token, of signature `void(boost::system::error_code)`: * `invalid_signature` for a signature of another size, an r or an s that is 0 or not below n, and * one that does not verify. * @return What the completion token's `async_result` gives. */ template -auto async_verify(Executor const& executor, ecdsa_sha256_t scheme, - std::span signature, Input const& input, +auto async_verify(Executor const& completion_executor, ecdsa_sha256_t signing_scheme, + std::span signature_bytes, Input const& signing_input, curves::p256::basic_public_key const& public_key, - CompletionToken&& token) { - detail::timing_guard const timing; - return public_key.async_verify(executor, scheme, signature, input, - std::forward(token)); + CompletionToken&& completion_token) { + detail::timing_guard const timing_scope; + return public_key.async_verify(completion_executor, signing_scheme, signature_bytes, + signing_input, std::forward(completion_token)); } /** @@ -753,21 +788,23 @@ auto async_verify(Executor const& executor, ecdsa_sha256_t scheme, * @tparam Input The input's type. * @tparam PublicKey The public key's type. * @tparam CompletionToken The completion token's type. - * @param executor The executor. - * @param scheme The scheme. - * @param signature The signature. - * @param input The message or the marker. + * @param completion_executor The executor. + * @param signing_scheme The scheme. + * @param signature_value The signature. + * @param signing_input The message or the marker. * @param public_key The public key. - * @param token The completion token. + * @param completion_token The completion token. */ template requires(detail::is_scheme_v && !detail::has_async_verifier_v>) -void async_verify([[maybe_unused]] Executor const& executor, [[maybe_unused]] Scheme scheme, - [[maybe_unused]] Signature const& signature, [[maybe_unused]] Input const& input, +void async_verify([[maybe_unused]] Executor const& completion_executor, + [[maybe_unused]] Scheme signing_scheme, + [[maybe_unused]] Signature const& signature_value, + [[maybe_unused]] Input const& signing_input, [[maybe_unused]] PublicKey const& public_key, - [[maybe_unused]] CompletionToken&& token) { + [[maybe_unused]] CompletionToken&& completion_token) { static_assert(detail::refused_v, "webcpp::crypto: async_verify takes crypto::eddsa with a " "curves::ed25519::public_key or crypto::ecdsa_sha256 with a " @@ -777,63 +814,69 @@ void async_verify([[maybe_unused]] Executor const& executor, [[maybe_unused]] Sc /** * Agrees an X25519 shared secret, asynchronously: `curves::x25519::agree` run when the - * operation is initiated, its result posted to `executor`. + * operation is initiated, its result posted to `completion_executor`. * * The spans are the caller's until the completion. * * @tparam Backend The backend; by default the asynchronous family's. * @tparam Executor The executor's type, an Asio executor (an `io_context`'s or a strand's). - * @tparam CompletionToken Any completion token for the signature `token` states. - * @param executor The executor the completion is posted to. + * @tparam CompletionToken Any completion token for the signature `completion_token` states. + * @param completion_executor The executor the completion is posted to. * @param secret_key 32 bytes. * @param peer_public_key 32 bytes. - * @param token The completion token, of signature `void(boost::system::error_code, secret<32>)`: - * the shared secret; on an error a secret of zeros (`invalid_key_size`, `invalid_public_key`, - * `weak_public_key`, `backend_failure`). + * @param completion_token The completion token, of signature `void(boost::system::error_code, + * secret<32>)`: the shared secret; on an error a secret of zeros (`invalid_key_size`, + * `invalid_public_key`, `weak_public_key`, `backend_failure`). * @return What the completion token's `async_result` gives. */ template , class Executor, class CompletionToken> -auto async_agree(Executor const& executor, std::span secret_key, - std::span peer_public_key, CompletionToken&& token) { - detail::timing_guard const timing; +auto async_agree(Executor const& completion_executor, std::span secret_key, + std::span peer_public_key, + CompletionToken&& completion_token) { + detail::timing_guard const timing_scope; if constexpr (detail::asynchronous_backend_v) { - return detail::async_engine::agree(executor, secret_key, peer_public_key, - std::forward(token)); + return detail::async_engine::agree( + completion_executor, secret_key, peer_public_key, + std::forward(completion_token)); } else { - return detail::complete_by_post(executor, token, [secret_key, peer_public_key]() noexcept { - return curves::x25519::agree(secret_key, peer_public_key); - }); + return detail::complete_by_post( + completion_executor, completion_token, [secret_key, peer_public_key]() noexcept { + return curves::x25519::agree(secret_key, peer_public_key); + }); } } /** * Agrees a P-256 shared secret, ECDH's raw x coordinate, asynchronously: * `key_pair.agree(peer_public_key)` run when the operation is initiated, its result posted to - * `executor`, as WebCrypto's `deriveBits` with ECDH on P-256 gives its 256 bits. + * `completion_executor`, as WebCrypto's `deriveBits` with ECDH on P-256 gives its 256 bits. * - * The free form of `key_pair.async_agree(executor, peer_public_key, token)`, which it calls. + * The free form of `key_pair.async_agree(completion_executor, peer_public_key, completion_token)`, + * which it calls. * * The x coordinate is not a key: a protocol hashes it into its keys (with HKDF, for instance). * The key pair and the peer's key are the caller's until the completion. * * @tparam Backend The backend of the key pair and of the peer's key. * @tparam Executor The executor's type, an Asio executor (an `io_context`'s or a strand's). - * @tparam CompletionToken Any completion token for the signature `token` states. - * @param executor The executor the completion is posted to. + * @tparam CompletionToken Any completion token for the signature `completion_token` states. + * @param completion_executor The executor the completion is posted to. * @param key_pair This side's key pair. * @param peer_public_key The peer's public key, validated when it was made. - * @param token The completion token, of signature `void(boost::system::error_code, secret<32>)`: - * the shared x, big-endian; on an error a secret of zeros (`invalid_state` for an empty key pair, - * `backend_failure`). + * @param completion_token The completion token, of signature `void(boost::system::error_code, + * secret<32>)`: the shared x, big-endian; on an error a secret of zeros (`invalid_state` for an + * empty key pair, `backend_failure`). * @return What the completion token's `async_result` gives. */ template -auto async_agree(Executor const& executor, curves::p256::basic_keypair const& key_pair, +auto async_agree(Executor const& completion_executor, + curves::p256::basic_keypair const& key_pair, curves::p256::basic_public_key const& peer_public_key, - CompletionToken&& token) { - detail::timing_guard const timing; - return key_pair.async_agree(executor, peer_public_key, std::forward(token)); + CompletionToken&& completion_token) { + detail::timing_guard const timing_scope; + return key_pair.async_agree(completion_executor, peer_public_key, + std::forward(completion_token)); } // The asynchronous members (design D9), declared in their classes and defined here, so that a @@ -842,27 +885,30 @@ auto async_agree(Executor const& executor, curves::p256::basic_keypair template template -auto ciphers::gcm::async_make(Executor const& executor, +auto ciphers::gcm::async_make(Executor const& completion_executor, std::span key_bytes, - CompletionToken&& token) { - detail::timing_guard const timing; - return detail::initiate_make(executor, key_bytes, std::forward(token)); + CompletionToken&& completion_token) { + detail::timing_guard const timing_scope; + return detail::initiate_make(completion_executor, key_bytes, + std::forward(completion_token)); } template template -auto ciphers::gcm::async_seal(Executor const& executor, +auto ciphers::gcm::async_seal(Executor const& completion_executor, std::span iv_bytes, std::span additional_data_bytes, - std::span data_bytes, CompletionToken&& token) { - detail::timing_guard const timing; + std::span data_bytes, + CompletionToken&& completion_token) { + detail::timing_guard const timing_scope; if constexpr (detail::asynchronous_backend_v) { - return detail::async_engine::seal(executor, *this, iv_bytes, additional_data_bytes, - data_bytes, - std::forward(token)); + return detail::async_engine::seal(completion_executor, *this, iv_bytes, + additional_data_bytes, data_bytes, + std::forward(completion_token)); } else { return detail::complete_by_post( - executor, token, [this, iv_bytes, additional_data_bytes, data_bytes]() noexcept { + completion_executor, completion_token, + [this, iv_bytes, additional_data_bytes, data_bytes]() noexcept { return seal(iv_bytes, additional_data_bytes, data_bytes); }); } @@ -870,20 +916,20 @@ auto ciphers::gcm::async_seal(Executor const& executor, template template -auto ciphers::gcm::async_open(Executor const& executor, +auto ciphers::gcm::async_open(Executor const& completion_executor, std::span iv_bytes, std::span additional_data_bytes, std::span data_bytes, std::span tag_bytes, - CompletionToken&& token) { - detail::timing_guard const timing; + CompletionToken&& completion_token) { + detail::timing_guard const timing_scope; if constexpr (detail::asynchronous_backend_v) { - return detail::async_engine::open(executor, *this, iv_bytes, additional_data_bytes, - data_bytes, tag_bytes, - std::forward(token)); + return detail::async_engine::open(completion_executor, *this, iv_bytes, + additional_data_bytes, data_bytes, tag_bytes, + std::forward(completion_token)); } else { return detail::complete_by_post( - executor, token, + completion_executor, completion_token, [this, iv_bytes, additional_data_bytes, data_bytes, tag_bytes]() noexcept { return open(iv_bytes, additional_data_bytes, data_bytes, tag_bytes); }); @@ -892,119 +938,127 @@ auto ciphers::gcm::async_open(Executor const& executor, template template -auto curves::ed25519::basic_keypair::async_make(Executor const& executor, - std::span seed, - CompletionToken&& token) { - detail::timing_guard const timing; - return detail::initiate_make(executor, seed, - std::forward(token)); +auto curves::ed25519::basic_keypair::async_make(Executor const& completion_executor, + std::span seed_bytes, + CompletionToken&& completion_token) { + detail::timing_guard const timing_scope; + return detail::initiate_make(completion_executor, seed_bytes, + std::forward(completion_token)); } template template -auto curves::ed25519::basic_keypair::async_generate(Executor const& executor, - CompletionToken&& token) { - detail::timing_guard const timing; - return detail::initiate_generate(executor, std::forward(token)); +auto curves::ed25519::basic_keypair::async_generate(Executor const& completion_executor, + CompletionToken&& completion_token) { + detail::timing_guard const timing_scope; + return detail::initiate_generate( + completion_executor, std::forward(completion_token)); } template template -auto curves::ed25519::basic_keypair::async_sign(Executor const& executor, Scheme scheme, - Input const& message, - CompletionToken&& token) const { - detail::timing_guard const timing; - return detail::initiate_sign(executor, *this, scheme, message, - std::forward(token)); +auto curves::ed25519::basic_keypair::async_sign(Executor const& completion_executor, + Scheme signing_scheme, + Input const& message_bytes, + CompletionToken&& completion_token) const { + detail::timing_guard const timing_scope; + return detail::initiate_sign(completion_executor, *this, signing_scheme, message_bytes, + std::forward(completion_token)); } template -auto curves::ed25519::public_key::async_verify(Executor const& executor, - [[maybe_unused]] Scheme scheme, - std::span signature, - Input const& message, - CompletionToken&& token) const { - detail::timing_guard const timing; +auto curves::ed25519::public_key::async_verify(Executor const& completion_executor, + [[maybe_unused]] Scheme signing_scheme, + std::span signature_bytes, + Input const& message_bytes, + CompletionToken&& completion_token) const { + detail::timing_guard const timing_scope; return detail::initiate_verify_ed25519( - executor, signature, message, *this, strict, std::forward(token)); + completion_executor, signature_bytes, message_bytes, *this, strict, + std::forward(completion_token)); } template -auto curves::ed25519::public_key::async_verify(Executor const& executor, - [[maybe_unused]] Scheme scheme, - std::span signature, - Input const& message, strict_t policy, - CompletionToken&& token) const { - detail::timing_guard const timing; +auto curves::ed25519::public_key::async_verify(Executor const& completion_executor, + [[maybe_unused]] Scheme signing_scheme, + std::span signature_bytes, + Input const& message_bytes, + strict_t verification_policy, + CompletionToken&& completion_token) const { + detail::timing_guard const timing_scope; return detail::initiate_verify_ed25519( - executor, signature, message, *this, policy, std::forward(token)); + completion_executor, signature_bytes, message_bytes, *this, verification_policy, + std::forward(completion_token)); } template template -auto curves::p256::basic_keypair::async_make(Executor const& executor, +auto curves::p256::basic_keypair::async_make(Executor const& completion_executor, std::span secret_scalar, - CompletionToken&& token) { - detail::timing_guard const timing; - return detail::initiate_make(executor, secret_scalar, - std::forward(token)); + CompletionToken&& completion_token) { + detail::timing_guard const timing_scope; + return detail::initiate_make(completion_executor, secret_scalar, + std::forward(completion_token)); } template template -auto curves::p256::basic_keypair::async_generate(Executor const& executor, - CompletionToken&& token) { - detail::timing_guard const timing; - return detail::initiate_generate(executor, std::forward(token)); +auto curves::p256::basic_keypair::async_generate(Executor const& completion_executor, + CompletionToken&& completion_token) { + detail::timing_guard const timing_scope; + return detail::initiate_generate( + completion_executor, std::forward(completion_token)); } template template -auto curves::p256::basic_keypair::async_sign(Executor const& executor, Scheme scheme, - Input const& input, - CompletionToken&& token) const { - detail::timing_guard const timing; - return detail::initiate_sign(executor, *this, scheme, input, - std::forward(token)); +auto curves::p256::basic_keypair::async_sign(Executor const& completion_executor, + Scheme signing_scheme, + Input const& signing_input, + CompletionToken&& completion_token) const { + detail::timing_guard const timing_scope; + return detail::initiate_sign(completion_executor, *this, signing_scheme, signing_input, + std::forward(completion_token)); } template template -auto curves::p256::basic_keypair::async_agree(Executor const& executor, - basic_public_key const& peer, - CompletionToken&& token) const { - detail::timing_guard const timing; +auto curves::p256::basic_keypair::async_agree(Executor const& completion_executor, + basic_public_key const& peer_key, + CompletionToken&& completion_token) const { + detail::timing_guard const timing_scope; if constexpr (detail::asynchronous_backend_v) { - return detail::async_engine::agree(executor, *this, peer, - std::forward(token)); + return detail::async_engine::agree( + completion_executor, *this, peer_key, std::forward(completion_token)); } else { - return detail::complete_by_post(executor, token, - [this, &peer]() noexcept { return agree(peer); }); + return detail::complete_by_post(completion_executor, completion_token, + [this, &peer_key]() noexcept { return agree(peer_key); }); } } template template -auto curves::p256::basic_public_key::async_verify(Executor const& executor, - [[maybe_unused]] Scheme scheme, - std::span signature, - Input const& input, - CompletionToken&& token) const { - detail::timing_guard const timing; +auto curves::p256::basic_public_key::async_verify( + Executor const& completion_executor, [[maybe_unused]] Scheme signing_scheme, + std::span signature_bytes, Input const& signing_input, + CompletionToken&& completion_token) const { + detail::timing_guard const timing_scope; if constexpr (!std::is_same_v) { static_assert(detail::refused_v, "webcpp::crypto: a P-256 public key verifies crypto::ecdsa_sha256."); } else if constexpr (!can_verify) { detail::check_input(); } else if constexpr (detail::asynchronous_backend_v) { - return detail::async_engine::verify(executor, ecdsa_sha256, signature, - detail::kept_input(input), *this, - std::forward(token)); + return detail::async_engine::verify( + completion_executor, ecdsa_sha256, signature_bytes, detail::kept_input(signing_input), + *this, std::forward(completion_token)); } else { return detail::complete_by_post( - executor, token, - [this, signature, kept = detail::kept_input(input)]() noexcept - -> boost::system::result { return verify(ecdsa_sha256, signature, kept); }); + completion_executor, completion_token, + [this, signature_bytes, + kept = detail::kept_input(signing_input)]() noexcept -> boost::system::result { + return verify(ecdsa_sha256, signature_bytes, kept); + }); } } diff --git a/include/webcpp/crypto/backends/bearssl.hpp b/include/webcpp/crypto/backends/bearssl.hpp index 19e875e3..0ae3eb6d 100644 --- a/include/webcpp/crypto/backends/bearssl.hpp +++ b/include/webcpp/crypto/backends/bearssl.hpp @@ -414,8 +414,8 @@ struct aead_engine { */ [[nodiscard]] inline br_ec_impl const* bearssl_p256() noexcept { #ifndef WEBCPP_CRYPTO_WEBASSEMBLY - if (br_ec_impl const* wide = br_ec_p256_m62_get()) { - return wide; + if (br_ec_impl const* wide_impl = br_ec_p256_m62_get()) { + return wide_impl; } #endif return &br_ec_p256_m31; @@ -443,18 +443,19 @@ struct p_curve_engine { /** * Keeps the scalar and computes its public point. * - * @param keyed An empty state. - * @param scalar 32 bytes, 0 < d < n (the family's header has checked them). + * @param keyed_state An empty state. + * @param scalar_bytes 32 bytes, 0 < d < n (the family's header has checked them). * @return Nothing; `backend_failure`, which a valid scalar cannot cause. */ [[nodiscard]] static boost::system::result make( - state& keyed, std::span scalar) noexcept { + state& keyed_state, std::span scalar_bytes) noexcept { WEBCPP_CRYPTO_DETAIL_P_CURVE_ENGINE_ENTERED(); read_canary(WEBCPP_CRYPTO_DETAIL_BEARSSL_CANARY); - std::ranges::copy(scalar, keyed.scalar.begin()); - if (bearssl_p256()->mulgen(keyed.point.data(), keyed.scalar.data(), keyed.scalar.size(), - BR_EC_secp256r1) != keyed.point.size()) { - reset(keyed); + std::ranges::copy(scalar_bytes, keyed_state.scalar.begin()); + if (bearssl_p256()->mulgen(keyed_state.point.data(), keyed_state.scalar.data(), + keyed_state.scalar.size(), + BR_EC_secp256r1) != keyed_state.point.size()) { + reset(keyed_state); return error::backend_failure; } return {}; @@ -463,47 +464,47 @@ struct p_curve_engine { /** * Whether an uncompressed point is on the curve, its coordinates below p. * - * @param point 65 bytes, whose first byte is 04 (the family's header has checked it). + * @param point_bytes 65 bytes, whose first byte is 04 (the family's header has checked it). * @return Whether BearSSL decodes it. */ - [[nodiscard]] static bool valid_point(std::span point) noexcept { + [[nodiscard]] static bool valid_point(std::span point_bytes) noexcept { WEBCPP_CRYPTO_DETAIL_P_CURVE_ENGINE_ENTERED(); read_canary(WEBCPP_CRYPTO_DETAIL_BEARSSL_CANARY); // BearSSL decodes, and so checks, a point only to multiply it: by 1 it comes back as it // was, re-encoded, when its coordinates are below p and on the curve (design D36). - std::array decoded{}; - std::ranges::copy(point, decoded.begin()); - constexpr std::array one{1}; - return bearssl_p256()->mul(decoded.data(), decoded.size(), one.data(), one.size(), - BR_EC_secp256r1) == 1 && - std::ranges::equal(decoded, point); + std::array decoded_point{}; + std::ranges::copy(point_bytes, decoded_point.begin()); + constexpr std::array one_scalar{1}; + return bearssl_p256()->mul(decoded_point.data(), decoded_point.size(), one_scalar.data(), + one_scalar.size(), BR_EC_secp256r1) == 1 && + std::ranges::equal(decoded_point, point_bytes); } /** * Signs a digest with ECDSA and RFC 6979's nonce, S as BearSSL computes it (design D36). * - * @param keyed A keyed state. - * @param digest The 32-byte SHA-256 digest. - * @param output 64 bytes, r then s. + * @param keyed_state A keyed state. + * @param digest_bytes The 32-byte SHA-256 digest. + * @param output_bytes 64 bytes, r then s. * @return Nothing; `backend_failure`, which a valid key cannot cause. */ [[nodiscard]] static boost::system::result sign( - state const& keyed, std::span digest, - std::span output) noexcept { + state const& keyed_state, std::span digest_bytes, + std::span output_bytes) noexcept { WEBCPP_CRYPTO_DETAIL_P_CURVE_ENGINE_ENTERED(); read_canary(WEBCPP_CRYPTO_DETAIL_BEARSSL_CANARY); // BearSSL's struct is not const-correct: it only reads the scalar. // NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast): see above - auto* const scalar = const_cast(keyed.scalar.data()); - br_ec_private_key const key{ + auto* const scalar_bytes = const_cast(keyed_state.scalar.data()); + br_ec_private_key const bearssl_key{ .curve = BR_EC_secp256r1, - .x = scalar, - .xlen = keyed.scalar.size(), + .x = scalar_bytes, + .xlen = keyed_state.scalar.size(), }; // RFC 6979's nonce, from HMAC-DRBG over SHA-256: br_sha256_vtable is the hash of the // nonce's derivation, which RFC 6979 makes the digest's own. No random number is drawn. - if (br_ecdsa_i31_sign_raw(bearssl_p256(), &br_sha256_vtable, digest.data(), &key, - output.data()) != output.size()) { + if (br_ecdsa_i31_sign_raw(bearssl_p256(), &br_sha256_vtable, digest_bytes.data(), + &bearssl_key, output_bytes.data()) != output_bytes.size()) { return error::backend_failure; } return {}; @@ -512,155 +513,164 @@ struct p_curve_engine { /** * ECDH: the peer's point multiplied by the scalar, and the product's x coordinate. * - * @param keyed A keyed state. - * @param peer The peer's uncompressed point, valid (its public key was made by BearSSL's + * @param keyed_state A keyed state. + * @param peer_key The peer's uncompressed point, valid (its public key was made by BearSSL's * decoding). - * @param output 32 bytes, a `secret<32>`'s. + * @param output_bytes 32 bytes, a `secret<32>`'s. * @return Nothing; `backend_failure`, which a valid point and a scalar in range cannot cause. */ [[nodiscard]] static boost::system::result ecdh_x( - state const& keyed, std::span peer, - std::span output) noexcept { + state const& keyed_state, std::span peer_key, + std::span output_bytes) noexcept { WEBCPP_CRYPTO_DETAIL_P_CURVE_ENGINE_ENTERED(); read_canary(WEBCPP_CRYPTO_DETAIL_BEARSSL_CANARY); // BearSSL multiplies in place: the copy becomes d * Q, uncompressed, and is wiped after. - std::array shared{}; - std::ranges::copy(peer, shared.begin()); + std::array shared_point{}; + std::ranges::copy(peer_key, shared_point.begin()); // BearSSL's verdict: on br_ec_p256_m62, the point's decoding, its own check of the // scalar's range and whether the product is the point at infinity, so a constant-time // checker holds it secret; on br_ec_p256_m31, the decoding alone. Whether a valid point // and a valid scalar multiply is public. // Not const: the branch reads it again after the mark (detail/declassify.hpp's tip). // NOLINTNEXTLINE(misc-const-correctness): see above - std::uint32_t multiplied = - bearssl_p256()->mul(shared.data(), shared.size(), keyed.scalar.data(), - keyed.scalar.size(), BR_EC_secp256r1); + std::uint32_t multiplied_flag = + bearssl_p256()->mul(shared_point.data(), shared_point.size(), keyed_state.scalar.data(), + keyed_state.scalar.size(), BR_EC_secp256r1); WEBCPP_CRYPTO_DETAIL_DECLASSIFY(&multiplied, sizeof multiplied); - if (multiplied != 1) { - wipe_object(shared); + if (multiplied_flag != 1) { + wipe_object(shared_point); return error::backend_failure; // a validated point and a scalar in range never fail } std::size_t x_size = 0; std::size_t const x_offset = bearssl_p256()->xoff(BR_EC_secp256r1, &x_size); - std::ranges::copy(std::span(shared).subspan(x_offset, x_size), - output.begin()); - wipe_object(shared); + std::ranges::copy(std::span(shared_point).subspan(x_offset, x_size), + output_bytes.begin()); + wipe_object(shared_point); return {}; } /** * Verifies an ECDSA signature; a high S is accepted (design D36). * - * @param point The public key's uncompressed point, valid. - * @param digest The 32-byte SHA-256 digest. - * @param signature 64 bytes, r then s, each in range (the family's header has checked them). + * @param point_bytes The public key's uncompressed point, valid. + * @param digest_bytes The 32-byte SHA-256 digest. + * @param signature_bytes 64 bytes, r then s, each in range (the family's header has checked + * them). * @return Whether the signature verifies. */ - [[nodiscard]] static bool verify(std::span point, - std::span digest, - std::span signature) noexcept { + [[nodiscard]] static bool verify(std::span point_bytes, + std::span digest_bytes, + std::span signature_bytes) noexcept { WEBCPP_CRYPTO_DETAIL_P_CURVE_ENGINE_ENTERED(); read_canary(WEBCPP_CRYPTO_DETAIL_BEARSSL_CANARY); // BearSSL's struct holds a pointer to non-const bytes, which it only reads: a copy keeps // the key's own bytes const without a cast. std::array key_point{}; - std::ranges::copy(point, key_point.begin()); - br_ec_public_key const key{ + std::ranges::copy(point_bytes, key_point.begin()); + br_ec_public_key const bearssl_key{ .curve = BR_EC_secp256r1, .q = key_point.data(), .qlen = key_point.size(), }; - return br_ecdsa_i31_vrfy_raw(bearssl_p256(), digest.data(), digest.size(), &key, - signature.data(), signature.size()) == 1; + return br_ecdsa_i31_vrfy_raw(bearssl_p256(), digest_bytes.data(), digest_bytes.size(), + &bearssl_key, signature_bytes.data(), + signature_bytes.size()) == 1; } /** * Encodes a signature as strict DER. * - * @param signature 64 bytes, r then s, each in range (the family's header has checked them). - * @param output 72 bytes, room for the longest encoding. + * @param signature_bytes 64 bytes, r then s, each in range (the family's header has checked + * them). + * @param output_bytes 72 bytes, room for the longest encoding. * @return The encoding's length, at most 72: 2 + 2 * (2 + 33). */ - [[nodiscard]] static std::size_t to_der(std::span signature, - std::span output) noexcept { + [[nodiscard]] static std::size_t to_der(std::span signature_bytes, + std::span output_bytes) noexcept { WEBCPP_CRYPTO_DETAIL_P_CURVE_ENGINE_ENTERED(); read_canary(WEBCPP_CRYPTO_DETAIL_BEARSSL_CANARY); // In place, and "by no more than 9 bytes" larger (bearssl_ec.h): room for 64 + 9. - std::array work{}; - std::ranges::copy(signature, work.begin()); - std::size_t const length = br_ecdsa_raw_to_asn1(work.data(), signature.size()); - std::ranges::copy(std::span(work).first(length), output.begin()); - return length; + std::array work_bytes{}; + std::ranges::copy(signature_bytes, work_bytes.begin()); + std::size_t const der_length = + br_ecdsa_raw_to_asn1(work_bytes.data(), signature_bytes.size()); + std::ranges::copy(std::span(work_bytes).first(der_length), + output_bytes.begin()); + return der_length; } /** * Decodes a strict DER signature: BearSSL's decoder, then the re-encoding compared with the * input, since BearSSL accepts a few forms strict DER refuses. * - * @param der The encoding, not empty. - * @param output 64 bytes, r then s, padded to 32 bytes each; the caller keeps them only on - * success and checks their range. + * @param der_bytes The encoding, not empty. + * @param output_bytes 64 bytes, r then s, padded to 32 bytes each; the caller keeps them only + * on success and checks their range. * @return Whether the input is strict DER of two integers of at most 32 bytes. */ - [[nodiscard]] static bool from_der(std::span der, - std::span output) noexcept { + [[nodiscard]] static bool from_der(std::span der_bytes, + std::span output_bytes) noexcept { WEBCPP_CRYPTO_DETAIL_P_CURVE_ENGINE_ENTERED(); read_canary(WEBCPP_CRYPTO_DETAIL_BEARSSL_CANARY); - constexpr std::size_t longest = 72; - if (der.size() > longest) { + constexpr std::size_t longest_der = 72; + if (der_bytes.size() > longest_der) { return false; } // In place, and up to twice the source's length (bearssl_ec.h): room for 2 * 72. - std::array work{}; - std::ranges::copy(der, work.begin()); + std::array work_bytes{}; + std::ranges::copy(der_bytes, work_bytes.begin()); // BearSSL strips the integers' leading zeros and writes r and s at the longer one's // length (ecdsa_atr.c), so a raw form shorter than 64 bytes is padded back to 32 each. - std::size_t const raw_size = br_ecdsa_asn1_to_raw(work.data(), der.size()); - std::size_t const half = raw_size / 2; - if (raw_size == 0 || half > 32) { + std::size_t const raw_size = br_ecdsa_asn1_to_raw(work_bytes.data(), der_bytes.size()); + std::size_t const half_size = raw_size / 2; + if (raw_size == 0 || half_size > 32) { return false; } - std::array raw{}; - std::ranges::copy(std::span(work).first(half), - raw.begin() + static_cast(32 - half)); - std::ranges::copy(std::span(work).subspan(half, half), - raw.begin() + static_cast(64 - half)); - std::ranges::copy(std::span(raw).first<64>(), output.begin()); + std::array raw_signature{}; + std::ranges::copy(std::span(work_bytes).first(half_size), + raw_signature.begin() + static_cast(32 - half_size)); + std::ranges::copy(std::span(work_bytes).subspan(half_size, half_size), + raw_signature.begin() + static_cast(64 - half_size)); + std::ranges::copy(std::span(raw_signature).first<64>(), + output_bytes.begin()); // BearSSL's decoder accepts a long SEQUENCE length, needless zero bytes and a negative // integer; strict DER is what re-encodes to the same bytes (design D12). - std::size_t const length = br_ecdsa_raw_to_asn1(raw.data(), 64); - return length == der.size() && - std::ranges::equal(std::span(raw).first(length), der); + std::size_t const der_length = br_ecdsa_raw_to_asn1(raw_signature.data(), 64); + return der_length == der_bytes.size() && + std::ranges::equal(std::span(raw_signature).first(der_length), + der_bytes); } /** * Copies the public point; no BearSSL call. * - * @param keyed A keyed state. - * @param output 65 bytes. + * @param keyed_state A keyed state. + * @param output_bytes 65 bytes. */ - static void public_point(state const& keyed, std::span output) noexcept { - std::ranges::copy(keyed.point, output.begin()); + static void public_point(state const& keyed_state, + std::span output_bytes) noexcept { + std::ranges::copy(keyed_state.point, output_bytes.begin()); } /** * Copies the secret scalar; no BearSSL call. * - * @param keyed A keyed state. - * @param output 32 bytes, a `secret<32>`'s. + * @param keyed_state A keyed state. + * @param output_bytes 32 bytes, a `secret<32>`'s. */ - static void scalar(state const& keyed, std::span output) noexcept { - std::ranges::copy(keyed.scalar, output.begin()); + static void scalar(state const& keyed_state, + std::span output_bytes) noexcept { + std::ranges::copy(keyed_state.scalar, output_bytes.begin()); } /** * Wipes the scalar and the point; the state is empty. * - * @param keyed Any state. + * @param keyed_state Any state. */ - static void reset(state& keyed) noexcept { - wipe_object(keyed.scalar); - wipe_object(keyed.point); + static void reset(state& keyed_state) noexcept { + wipe_object(keyed_state.scalar); + wipe_object(keyed_state.point); } }; diff --git a/include/webcpp/crypto/backends/openssl.hpp b/include/webcpp/crypto/backends/openssl.hpp index 758ab230..0e0344ac 100644 --- a/include/webcpp/crypto/backends/openssl.hpp +++ b/include/webcpp/crypto/backends/openssl.hpp @@ -122,25 +122,25 @@ extern "C" { * OpenSSL's `malloc` under the option: a block of the program's resource, after a header * that holds its size. * - * @param size The bytes OpenSSL asks for; 0, or a size whose header overflows, gives null. + * @param byte_count The bytes OpenSSL asks for; 0, or a size whose header overflows, gives null. * @return The block, or null, which OpenSSL takes as a failure: for those sizes, and with * exceptions for a resource that throws. */ -inline void* webcpp_crypto_openssl_malloc(std::size_t size, char const* /*file*/, +inline void* webcpp_crypto_openssl_malloc(std::size_t byte_count, char const* /*file*/, int /*line*/) noexcept { - constexpr std::size_t header = webcpp::crypto::detail::openssl_block_alignment; + constexpr std::size_t header_size = webcpp::crypto::detail::openssl_block_alignment; // NOLINTNEXTLINE(readability-redundant-parentheses) - if (size == 0 || size > (std::numeric_limits::max)() - header) { + if (byte_count == 0 || byte_count > (std::numeric_limits::max)() - header_size) { return nullptr; } #ifndef WEBCPP_CRYPTO_NO_EXCEPTIONS try { #endif // Never null: a resource fails by throwing (openssl_memory_resource()). - void* const block = - webcpp::crypto::openssl_memory_resource().allocate(header + size, header); - std::memcpy(block, &size, sizeof size); - return static_cast(block) + header; + void* const raw_block = webcpp::crypto::openssl_memory_resource().allocate( + header_size + byte_count, header_size); + std::memcpy(raw_block, &byte_count, sizeof byte_count); + return static_cast(raw_block) + header_size; #ifndef WEBCPP_CRYPTO_NO_EXCEPTIONS } catch (...) { // OpenSSL is C: no exception may cross it return nullptr; @@ -151,20 +151,22 @@ inline void* webcpp_crypto_openssl_malloc(std::size_t size, char const* /*file*/ /** * OpenSSL's `free` under the option: the block back to the program's resource. * - * @param address A block of the adapter's, or null. + * @param block_address A block of the adapter's, or null. */ -inline void webcpp_crypto_openssl_free(void* address, char const* /*file*/, int /*line*/) noexcept { - if (address == nullptr) { +inline void webcpp_crypto_openssl_free(void* block_address, char const* /*file*/, + int /*line*/) noexcept { + if (block_address == nullptr) { return; } - constexpr std::size_t header = webcpp::crypto::detail::openssl_block_alignment; - auto* const block = static_cast(address) - header; - std::size_t size = 0; - std::memcpy(&size, block, sizeof size); + constexpr std::size_t header_size = webcpp::crypto::detail::openssl_block_alignment; + auto* const raw_block = static_cast(block_address) - header_size; + std::size_t byte_count = 0; + std::memcpy(&byte_count, raw_block, sizeof byte_count); #ifndef WEBCPP_CRYPTO_NO_EXCEPTIONS try { #endif - webcpp::crypto::openssl_memory_resource().deallocate(block, header + size, header); + webcpp::crypto::openssl_memory_resource().deallocate(raw_block, header_size + byte_count, + header_size); #ifndef WEBCPP_CRYPTO_NO_EXCEPTIONS // NOLINTNEXTLINE(bugprone-empty-catch): no exception may cross OpenSSL } catch (...) { @@ -176,29 +178,30 @@ inline void webcpp_crypto_openssl_free(void* address, char const* /*file*/, int * OpenSSL's `realloc` under the option, as C's: null is `malloc`, 0 frees and gives null, * and a failure gives null and leaves the old block valid. * - * @param address The block, or null. - * @param size The new size. + * @param block_address The block, or null. + * @param byte_count The new size. * @return The new block, or null. */ -inline void* webcpp_crypto_openssl_realloc(void* address, std::size_t size, char const* file, - int line) noexcept { - if (address == nullptr) { - return webcpp_crypto_openssl_malloc(size, file, line); +inline void* webcpp_crypto_openssl_realloc(void* block_address, std::size_t byte_count, + char const* source_file, int source_line) noexcept { + if (block_address == nullptr) { + return webcpp_crypto_openssl_malloc(byte_count, source_file, source_line); } - if (size == 0) { - webcpp_crypto_openssl_free(address, file, line); + if (byte_count == 0) { + webcpp_crypto_openssl_free(block_address, source_file, source_line); return nullptr; } - void* const moved = webcpp_crypto_openssl_malloc(size, file, line); - if (moved == nullptr) { + void* const moved_block = webcpp_crypto_openssl_malloc(byte_count, source_file, source_line); + if (moved_block == nullptr) { return nullptr; } - constexpr std::size_t header = webcpp::crypto::detail::openssl_block_alignment; - std::size_t old = 0; - std::memcpy(&old, static_cast(address) - header, sizeof old); - std::memcpy(moved, address, (std::min)(old, size)); - webcpp_crypto_openssl_free(address, file, line); - return moved; + constexpr std::size_t header_size = webcpp::crypto::detail::openssl_block_alignment; + std::size_t old_size = 0; + std::memcpy(&old_size, static_cast(block_address) - header_size, + sizeof old_size); + std::memcpy(moved_block, block_address, (std::min)(old_size, byte_count)); + webcpp_crypto_openssl_free(block_address, source_file, source_line); + return moved_block; } } // extern "C" @@ -207,12 +210,13 @@ namespace webcpp::crypto::detail { /** Whether OpenSSL's functions are the adapter's: three loads, no call into OpenSSL's heap. */ inline bool openssl_adapter_installed() noexcept { - CRYPTO_malloc_fn m = nullptr; - CRYPTO_realloc_fn r = nullptr; - CRYPTO_free_fn f = nullptr; - CRYPTO_get_mem_functions(&m, &r, &f); - return m == &webcpp_crypto_openssl_malloc && r == &webcpp_crypto_openssl_realloc && - f == &webcpp_crypto_openssl_free; + CRYPTO_malloc_fn malloc_function = nullptr; + CRYPTO_realloc_fn realloc_function = nullptr; + CRYPTO_free_fn free_function = nullptr; + CRYPTO_get_mem_functions(&malloc_function, &realloc_function, &free_function); + return malloc_function == &webcpp_crypto_openssl_malloc && + realloc_function == &webcpp_crypto_openssl_realloc && + free_function == &webcpp_crypto_openssl_free; } /** @@ -221,11 +225,12 @@ inline bool openssl_adapter_installed() noexcept { * webcpp never builds, is refused by this comparison. */ inline bool openssl_defaults_installed() noexcept { - CRYPTO_malloc_fn m = nullptr; - CRYPTO_realloc_fn r = nullptr; - CRYPTO_free_fn f = nullptr; - CRYPTO_get_mem_functions(&m, &r, &f); - return m == &CRYPTO_malloc && r == &CRYPTO_realloc && f == &CRYPTO_free; + CRYPTO_malloc_fn malloc_function = nullptr; + CRYPTO_realloc_fn realloc_function = nullptr; + CRYPTO_free_fn free_function = nullptr; + CRYPTO_get_mem_functions(&malloc_function, &realloc_function, &free_function); + return malloc_function == &CRYPTO_malloc && realloc_function == &CRYPTO_realloc && + free_function == &CRYPTO_free; } } // namespace webcpp::crypto::detail @@ -348,8 +353,8 @@ inline boost::system::error_code openssl_context(EVP_CIPHER_CTX*& made_context, char const* cipher_name, std::span key_bytes, bool is_encrypting, bool use_padding) noexcept { - if (auto const guard = openssl_memory_guard(); !guard) { - return guard.error(); + if (auto const memory_guard = openssl_memory_guard(); !memory_guard) { + return memory_guard.error(); } ERR_set_mark(); EVP_CIPHER* const fetched_cipher = EVP_CIPHER_fetch(nullptr, cipher_name, nullptr); @@ -608,16 +613,17 @@ struct aead_engine { state& engine_state, std::span iv_bytes, std::span additional_data_bytes, std::span data_bytes, boost::hash2::digest<16>& tag_bytes) noexcept { - sequence::state view{engine_state.context}; - auto const started = sequence::start(view, true, iv_bytes, additional_data_bytes); - if (!started) { - return started; + sequence::state sequence_view{engine_state.context}; + auto const start_result = + sequence::start(sequence_view, true, iv_bytes, additional_data_bytes); + if (!start_result) { + return start_result; } - auto const ran = sequence::run(view, data_bytes); - if (!ran) { - return ran; + auto const run_result = sequence::run(sequence_view, data_bytes); + if (!run_result) { + return run_result; } - return sequence::tag(view, tag_bytes); + return sequence::tag(sequence_view, tag_bytes); } /** @@ -635,18 +641,19 @@ struct aead_engine { state& engine_state, std::span iv_bytes, std::span additional_data_bytes, std::span data_bytes, std::array const& tag_bytes) noexcept { - sequence::state view{engine_state.context}; - auto const started = sequence::start(view, false, iv_bytes, additional_data_bytes); - if (!started) { - return started; + sequence::state sequence_view{engine_state.context}; + auto const start_result = + sequence::start(sequence_view, false, iv_bytes, additional_data_bytes); + if (!start_result) { + return start_result; } - auto const ran = sequence::run(view, data_bytes); - if (!ran) { - return ran; + auto const run_result = sequence::run(sequence_view, data_bytes); + if (!run_result) { + return run_result; } // GCM's check sets the 16-byte tag before the final, without which the provider would // compare 0 bytes (see the class's comment). - return sequence::check(view, tag_bytes); + return sequence::check(sequence_view, tag_bytes); } /** Moves the context, leaving the source empty. */ diff --git a/include/webcpp/crypto/backends/sodium.hpp b/include/webcpp/crypto/backends/sodium.hpp index 793c1e4f..1633dec0 100644 --- a/include/webcpp/crypto/backends/sodium.hpp +++ b/include/webcpp/crypto/backends/sodium.hpp @@ -87,15 +87,15 @@ namespace webcpp::crypto::detail { match or an all-zero shared secret, which webcpp reports and so branches on, here, where it is marked public for the constant-time checks (`WEBCPP_CRYPTO_DETAIL_DECLASSIFY`). - @param returned What the function returned: 0, or -1 when it refused. + @param returned_code What the function returned: 0, or -1 when it refused. @return Whether it refused. */ -[[nodiscard]] inline bool sodium_refused(int returned) noexcept { +[[nodiscard]] inline bool sodium_refused(int returned_code) noexcept { // Not const: the comparison reads it again after the mark (detail/declassify.hpp's tip). // NOLINTNEXTLINE(misc-const-correctness): see above - int verdict = returned; + int call_verdict = returned_code; WEBCPP_CRYPTO_DETAIL_DECLASSIFY(&verdict, sizeof verdict); - return verdict != 0; + return call_verdict != 0; } /** libsodium's detached functions of an AEAD family, which differ only by name. */ @@ -106,32 +106,32 @@ struct sodium_aead_calls; template <> struct sodium_aead_calls { /** Encrypts and computes the tag apart. */ - static constexpr auto encrypt = &crypto_aead_chacha20poly1305_ietf_encrypt_detached; + static constexpr auto encrypt_call = &crypto_aead_chacha20poly1305_ietf_encrypt_detached; /** Checks the tag apart, then decrypts. */ - static constexpr auto decrypt = &crypto_aead_chacha20poly1305_ietf_decrypt_detached; + static constexpr auto decrypt_call = &crypto_aead_chacha20poly1305_ietf_decrypt_detached; }; /** The original ChaCha20-Poly1305: libsodium's functions without a suffix. */ template <> struct sodium_aead_calls { /** Encrypts and computes the tag apart. */ - static constexpr auto encrypt = &crypto_aead_chacha20poly1305_encrypt_detached; + static constexpr auto encrypt_call = &crypto_aead_chacha20poly1305_encrypt_detached; /** Checks the tag apart, then decrypts. */ - static constexpr auto decrypt = &crypto_aead_chacha20poly1305_decrypt_detached; + static constexpr auto decrypt_call = &crypto_aead_chacha20poly1305_decrypt_detached; }; /** XChaCha20-Poly1305: libsodium's `xchacha20poly1305_ietf` functions. */ template <> struct sodium_aead_calls { /** Encrypts and computes the tag apart. */ - static constexpr auto encrypt = &crypto_aead_xchacha20poly1305_ietf_encrypt_detached; + static constexpr auto encrypt_call = &crypto_aead_xchacha20poly1305_ietf_encrypt_detached; /** Checks the tag apart, then decrypts. */ - static constexpr auto decrypt = &crypto_aead_xchacha20poly1305_ietf_decrypt_detached; + static constexpr auto decrypt_call = &crypto_aead_xchacha20poly1305_ietf_decrypt_detached; }; /** An AEAD's state on libsodium: the key, in the object, since libsodium takes it per call. */ template - requires requires { sodium_aead_calls::encrypt; } + requires requires { sodium_aead_calls::encrypt_call; } struct aead_state { /** The key. */ std::array key{}; @@ -143,7 +143,7 @@ struct aead_state { * does not match; `aead` zeroes it too. */ template - requires requires { sodium_aead_calls::encrypt; } + requires requires { sodium_aead_calls::encrypt_call; } struct aead_engine { /** The state. */ using state = aead_state; @@ -153,70 +153,73 @@ struct aead_engine { /** * Initialises libsodium and keeps the key. * - * @param s The state. - * @param key The key, 32 bytes (`aead` has checked its size). + * @param engine_state The state. + * @param key_bytes The key, 32 bytes (`aead` has checked its size). * @return Nothing; `backend_failure` when libsodium cannot start. */ [[nodiscard]] static boost::system::result init( - state& s, std::span key) noexcept { - auto const ready = sodium_ready(); - if (!ready) { - return ready; + state& engine_state, std::span key_bytes) noexcept { + auto const library_ready = sodium_ready(); + if (!library_ready) { + return library_ready; } - std::ranges::copy(key, s.key.begin()); + std::ranges::copy(key_bytes, engine_state.key.begin()); return {}; } /** - * Encrypts `data` in place and writes the tag; libsodium reads the nonce and the + * Encrypts `data_bytes` in place and writes the tag; libsodium reads the nonce and the * additional data before it writes a byte of the ciphertext. * * @return Nothing; `backend_failure` when libsodium fails. */ [[nodiscard]] static boost::system::result seal( - state& s, std::span iv, std::span additional_data, - std::span data, boost::hash2::digest<16>& tag) noexcept { + state& engine_state, std::span iv_bytes, + std::span additional_data, std::span data_bytes, + boost::hash2::digest<16>& tag_bytes) noexcept { read_canary(WEBCPP_CRYPTO_DETAIL_SODIUM_CANARY); unsigned long long tag_length = 0; // libsodium encrypts in place when the output is the input (its documented contract); // an empty span's null data() is never read or written, since every stream of // ChaCha20 returns at once on no byte. - if (calls::encrypt(data.data(), tag.data(), &tag_length, data.data(), data.size(), - additional_data.data(), additional_data.size(), nullptr, iv.data(), - s.key.data()) != 0) { + if (calls::encrypt_call(data_bytes.data(), tag_bytes.data(), &tag_length, data_bytes.data(), + data_bytes.size(), additional_data.data(), additional_data.size(), + nullptr, iv_bytes.data(), engine_state.key.data()) != 0) { return error::backend_failure; } return {}; } /** - * Checks the tag, then decrypts `data` in place. + * Checks the tag, then decrypts `data_bytes` in place. * * @return Nothing; `authentication_failed` when the tag does not match. */ [[nodiscard]] static boost::system::result open( - state& s, std::span iv, std::span additional_data, - std::span data, std::array const& tag) noexcept { + state& engine_state, std::span iv_bytes, + std::span additional_data, std::span data_bytes, + std::array const& tag_bytes) noexcept { read_canary(WEBCPP_CRYPTO_DETAIL_SODIUM_CANARY); // An empty span's null data() makes libsodium check the tag alone: its detached // decryptions return the verdict when the output is null, before clearing or decrypting // it. - if (sodium_refused(calls::decrypt(data.data(), nullptr, data.data(), data.size(), - tag.data(), additional_data.data(), - additional_data.size(), iv.data(), s.key.data()))) { + if (sodium_refused(calls::decrypt_call(data_bytes.data(), nullptr, data_bytes.data(), + data_bytes.size(), tag_bytes.data(), + additional_data.data(), additional_data.size(), + iv_bytes.data(), engine_state.key.data()))) { return error::authentication_failed; } return {}; } /** Moves the key; the source is wiped. */ - static void move(state& to, state& from) noexcept { - to.key = from.key; - wipe_object(from.key); + static void move(state& target_state, state& source_state) noexcept { + target_state.key = source_state.key; + wipe_object(source_state.key); } /** Wipes the key. */ - static void reset(state& s) noexcept { wipe_object(s.key); } + static void reset(state& engine_state) noexcept { wipe_object(engine_state.key); } }; /** libsodium's detached functions of a secret box family, which differ only by name. */ @@ -227,41 +230,43 @@ struct sodium_secretbox_calls; template <> struct sodium_secretbox_calls { /** Encrypts and computes the tag apart. */ - static constexpr auto encrypt = &crypto_secretbox_detached; + static constexpr auto encrypt_call = &crypto_secretbox_detached; /** Checks the tag apart, then decrypts. */ - static constexpr auto decrypt = &crypto_secretbox_open_detached; + static constexpr auto decrypt_call = &crypto_secretbox_open_detached; }; /** `crypto_secretbox_xchacha20poly1305`. */ template <> struct sodium_secretbox_calls { /** Encrypts and computes the tag apart. */ - static constexpr auto encrypt = &crypto_secretbox_xchacha20poly1305_detached; + static constexpr auto encrypt_call = &crypto_secretbox_xchacha20poly1305_detached; /** Checks the tag apart, then decrypts. */ - static constexpr auto decrypt = &crypto_secretbox_xchacha20poly1305_open_detached; + static constexpr auto decrypt_call = &crypto_secretbox_xchacha20poly1305_open_detached; }; /** - * Seals `data` in place with a secret box's detached function under a 32-byte key. libsodium + * Seals `data_bytes` in place with a secret box's detached function under a 32-byte key. libsodium * reads the nonce again after it writes the first bytes of the ciphertext, so a nonce that - * lies in `data` is copied first; an empty span's null data() is never read or written. + * lies in `data_bytes` is copied first; an empty span's null data() is never read or written. * * @return Nothing; `backend_failure` when libsodium fails. */ template [[nodiscard]] boost::system::result sodium_secretbox_seal( - Encrypt encrypt, std::span key, std::span iv, - std::span data, boost::hash2::digest<16>& tag) noexcept { - std::array nonce{}; - std::ranges::copy(iv, nonce.begin()); - if (encrypt(data.data(), tag.data(), data.data(), data.size(), nonce.data(), key.data()) != 0) { + Encrypt encrypt_call, std::span key_bytes, + std::span iv_bytes, std::span data_bytes, + boost::hash2::digest<16>& tag_bytes) noexcept { + std::array nonce_bytes{}; + std::ranges::copy(iv_bytes, nonce_bytes.begin()); + if (encrypt_call(data_bytes.data(), tag_bytes.data(), data_bytes.data(), data_bytes.size(), + nonce_bytes.data(), key_bytes.data()) != 0) { return error::backend_failure; } return {}; } /** - * Checks the tag, then decrypts `data` in place, with a secret box's detached function; the + * Checks the tag, then decrypts `data_bytes` in place, with a secret box's detached function; the * nonce is copied first, as `sodium_secretbox_seal` says. An empty span's null data() makes * libsodium check the tag alone. * @@ -269,12 +274,13 @@ template */ template [[nodiscard]] boost::system::result sodium_secretbox_open( - Decrypt decrypt, std::span key, std::span iv, - std::span data, std::array const& tag) noexcept { - std::array nonce{}; - std::ranges::copy(iv, nonce.begin()); - if (sodium_refused( - decrypt(data.data(), data.data(), tag.data(), data.size(), nonce.data(), key.data()))) { + Decrypt decrypt_call, std::span key_bytes, + std::span iv_bytes, std::span data_bytes, + std::array const& tag_bytes) noexcept { + std::array nonce_bytes{}; + std::ranges::copy(iv_bytes, nonce_bytes.begin()); + if (sodium_refused(decrypt_call(data_bytes.data(), data_bytes.data(), tag_bytes.data(), + data_bytes.size(), nonce_bytes.data(), key_bytes.data()))) { return error::authentication_failed; } return {}; @@ -282,7 +288,7 @@ template /** A secret box's state on libsodium: the key, in the object, since libsodium takes it per call. */ template - requires requires { sodium_secretbox_calls::encrypt; } + requires requires { sodium_secretbox_calls::encrypt_call; } struct aead_state { /** The key. */ std::array key{}; @@ -294,7 +300,7 @@ struct aead_state { * the tag before it writes a byte; `aead` zeroes the data when it does not match. */ template - requires requires { sodium_secretbox_calls::encrypt; } + requires requires { sodium_secretbox_calls::encrypt_call; } struct aead_engine { /** The state. */ using state = aead_state; @@ -307,51 +313,53 @@ struct aead_engine { * @return Nothing; `backend_failure` when libsodium cannot start. */ [[nodiscard]] static boost::system::result init( - state& s, std::span key) noexcept { - auto const ready = sodium_ready(); - if (!ready) { - return ready; + state& engine_state, std::span key_bytes) noexcept { + auto const library_ready = sodium_ready(); + if (!library_ready) { + return library_ready; } - std::ranges::copy(key, s.key.begin()); + std::ranges::copy(key_bytes, engine_state.key.begin()); return {}; } /** - * Encrypts `data` in place and writes the tag. + * Encrypts `data_bytes` in place and writes the tag. * * @return Nothing; `backend_failure` when libsodium fails. */ [[nodiscard]] static boost::system::result seal( - state& s, std::span iv, - std::span /*additional_data*/, std::span data, - boost::hash2::digest<16>& tag) noexcept { + state& engine_state, std::span iv_bytes, + std::span /*additional_data*/, std::span data_bytes, + boost::hash2::digest<16>& tag_bytes) noexcept { read_canary(WEBCPP_CRYPTO_DETAIL_SODIUM_CANARY); - return sodium_secretbox_seal(calls::encrypt, std::span(s.key), - iv.first<24>(), data, tag); + return sodium_secretbox_seal(calls::encrypt_call, + std::span(engine_state.key), + iv_bytes.first<24>(), data_bytes, tag_bytes); } /** - * Checks the tag, then decrypts `data` in place. + * Checks the tag, then decrypts `data_bytes` in place. * * @return Nothing; `authentication_failed` when the tag does not match. */ [[nodiscard]] static boost::system::result open( - state& s, std::span iv, - std::span /*additional_data*/, std::span data, - std::array const& tag) noexcept { + state& engine_state, std::span iv_bytes, + std::span /*additional_data*/, std::span data_bytes, + std::array const& tag_bytes) noexcept { read_canary(WEBCPP_CRYPTO_DETAIL_SODIUM_CANARY); - return sodium_secretbox_open(calls::decrypt, std::span(s.key), - iv.first<24>(), data, tag); + return sodium_secretbox_open(calls::decrypt_call, + std::span(engine_state.key), + iv_bytes.first<24>(), data_bytes, tag_bytes); } /** Moves the key; the source is wiped. */ - static void move(state& to, state& from) noexcept { - to.key = from.key; - wipe_object(from.key); + static void move(state& target_state, state& source_state) noexcept { + target_state.key = source_state.key; + wipe_object(source_state.key); } /** Wipes the key. */ - static void reset(state& s) noexcept { wipe_object(s.key); } + static void reset(state& engine_state) noexcept { wipe_object(engine_state.key); } }; } // namespace webcpp::crypto::detail @@ -396,29 +404,32 @@ struct ed25519_engine { * @return Nothing; `backend_failure`. */ [[nodiscard]] static boost::system::result make( - state& keyed, std::span seed) noexcept { - auto const ready = sodium_ready(); - if (!ready) { - return ready; + state& keyed_state, std::span seed_bytes) noexcept { + auto const library_ready = sodium_ready(); + if (!library_ready) { + return library_ready; } std::array public_key{}; - if (crypto_sign_ed25519_seed_keypair(public_key.data(), keyed.secret_key.data(), - seed.data()) != 0) { + if (crypto_sign_ed25519_seed_keypair(public_key.data(), keyed_state.secret_key.data(), + seed_bytes.data()) != 0) { return error::backend_failure; } return {}; } /** The public key, the secret key's second half. */ - static void public_key(state const& keyed, std::span out) noexcept { + static void public_key(state const& keyed_state, + std::span output_bytes) noexcept { read_canary(WEBCPP_CRYPTO_DETAIL_SODIUM_CANARY); - static_cast(crypto_sign_ed25519_sk_to_pk(out.data(), keyed.secret_key.data())); + static_cast( + crypto_sign_ed25519_sk_to_pk(output_bytes.data(), keyed_state.secret_key.data())); } /** The seed, the secret key's first half, `crypto_sign_ed25519_sk_to_seed`. */ - static void seed(state const& keyed, std::span out) noexcept { + static void seed(state const& keyed_state, std::span output_bytes) noexcept { read_canary(WEBCPP_CRYPTO_DETAIL_SODIUM_CANARY); - static_cast(crypto_sign_ed25519_sk_to_seed(out.data(), keyed.secret_key.data())); + static_cast( + crypto_sign_ed25519_sk_to_seed(output_bytes.data(), keyed_state.secret_key.data())); } /** @@ -427,11 +438,12 @@ struct ed25519_engine { * @return Nothing; `backend_failure`. */ [[nodiscard]] static boost::system::result sign( - state const& keyed, std::span message, - std::span out) noexcept { + state const& keyed_state, std::span message_bytes, + std::span output_bytes) noexcept { read_canary(WEBCPP_CRYPTO_DETAIL_SODIUM_CANARY); - if (crypto_sign_ed25519_detached(out.data(), nullptr, message.data(), message.size(), - keyed.secret_key.data()) != 0) { + if (crypto_sign_ed25519_detached(output_bytes.data(), nullptr, message_bytes.data(), + message_bytes.size(), + keyed_state.secret_key.data()) != 0) { return error::backend_failure; } return {}; @@ -443,14 +455,14 @@ struct ed25519_engine { * @return Nothing; `invalid_signature`; `backend_failure`. */ [[nodiscard]] static boost::system::result verify( - std::span public_key, std::span message, - std::span signature) noexcept { - auto const ready = sodium_ready(); - if (!ready) { - return ready; + std::span public_key, std::span message_bytes, + std::span signature_bytes) noexcept { + auto const library_ready = sodium_ready(); + if (!library_ready) { + return library_ready; } - if (crypto_sign_ed25519_verify_detached(signature.data(), message.data(), message.size(), - public_key.data()) != 0) { + if (crypto_sign_ed25519_verify_detached(signature_bytes.data(), message_bytes.data(), + message_bytes.size(), public_key.data()) != 0) { return error::invalid_signature; } return {}; @@ -462,9 +474,10 @@ struct ed25519_engine { * @return Nothing; `backend_failure`. */ [[nodiscard]] static boost::system::result x25519_secret( - state const& keyed, std::span out) noexcept { + state const& keyed_state, std::span output_bytes) noexcept { read_canary(WEBCPP_CRYPTO_DETAIL_SODIUM_CANARY); - if (crypto_sign_ed25519_sk_to_curve25519(out.data(), keyed.secret_key.data()) != 0) { + if (crypto_sign_ed25519_sk_to_curve25519(output_bytes.data(), + keyed_state.secret_key.data()) != 0) { return error::backend_failure; } return {}; @@ -477,19 +490,20 @@ struct ed25519_engine { * @return Nothing; `invalid_public_key`; `backend_failure`. */ [[nodiscard]] static boost::system::result to_x25519_public( - std::span public_key, std::span out) noexcept { - auto const ready = sodium_ready(); - if (!ready) { - return ready; + std::span public_key, + std::span output_bytes) noexcept { + auto const library_ready = sodium_ready(); + if (!library_ready) { + return library_ready; } - if (crypto_sign_ed25519_pk_to_curve25519(out.data(), public_key.data()) != 0) { + if (crypto_sign_ed25519_pk_to_curve25519(output_bytes.data(), public_key.data()) != 0) { return error::invalid_public_key; } return {}; } /** Wipes the secret key. */ - static void reset(state& keyed) noexcept { wipe_object(keyed.secret_key); } + static void reset(state& keyed_state) noexcept { wipe_object(keyed_state.secret_key); } }; /** What an Ed25519ph signer stores on libsodium: the message's SHA-512 state. */ @@ -510,21 +524,22 @@ struct ed25519ph_engine { * * @return Nothing; `backend_failure`. */ - [[nodiscard]] static boost::system::result begin(state& begun) noexcept { - auto const ready = sodium_ready(); - if (!ready) { - return ready; + [[nodiscard]] static boost::system::result begin(state& begun_state) noexcept { + auto const library_ready = sodium_ready(); + if (!library_ready) { + return library_ready; } - if (crypto_sign_ed25519ph_init(&begun.hashing) != 0) { + if (crypto_sign_ed25519ph_init(&begun_state.hashing) != 0) { return error::backend_failure; } return {}; } /** Adds a piece, `crypto_sign_ed25519ph_update`, which cannot fail. */ - static void update(state& begun, std::span piece) noexcept { + static void update(state& begun_state, std::span piece_bytes) noexcept { read_canary(WEBCPP_CRYPTO_DETAIL_SODIUM_CANARY); - static_cast(crypto_sign_ed25519ph_update(&begun.hashing, piece.data(), piece.size())); + static_cast(crypto_sign_ed25519ph_update(&begun_state.hashing, piece_bytes.data(), + piece_bytes.size())); } /** @@ -533,11 +548,11 @@ struct ed25519ph_engine { * @return Nothing; `backend_failure`. */ [[nodiscard]] static boost::system::result sign( - state& begun, ed25519_state const& keyed, - std::span out) noexcept { + state& begun_state, ed25519_state const& keyed_state, + std::span output_bytes) noexcept { read_canary(WEBCPP_CRYPTO_DETAIL_SODIUM_CANARY); - if (crypto_sign_ed25519ph_final_create(&begun.hashing, out.data(), nullptr, - keyed.secret_key.data()) != 0) { + if (crypto_sign_ed25519ph_final_create(&begun_state.hashing, output_bytes.data(), nullptr, + keyed_state.secret_key.data()) != 0) { return error::backend_failure; } return {}; @@ -549,10 +564,10 @@ struct ed25519ph_engine { * @return Nothing; `invalid_signature`. */ [[nodiscard]] static boost::system::result verify( - state& begun, std::span public_key, - std::span signature) noexcept { + state& begun_state, std::span public_key, + std::span signature_bytes) noexcept { read_canary(WEBCPP_CRYPTO_DETAIL_SODIUM_CANARY); - if (crypto_sign_ed25519ph_final_verify(&begun.hashing, signature.data(), + if (crypto_sign_ed25519ph_final_verify(&begun_state.hashing, signature_bytes.data(), public_key.data()) != 0) { return error::invalid_signature; } @@ -560,7 +575,7 @@ struct ed25519ph_engine { } /** Wipes the message's state. */ - static void reset(state& begun) noexcept { wipe_object(begun.hashing); } + static void reset(state& begun_state) noexcept { wipe_object(begun_state.hashing); } }; } // namespace webcpp::crypto::detail @@ -590,12 +605,13 @@ struct x25519_engine { * @return Nothing; `backend_failure`. */ [[nodiscard]] static boost::system::result base( - std::span secret_key, std::span out) noexcept { - auto const ready = sodium_ready(); - if (!ready) { - return ready; + std::span secret_key, + std::span output_bytes) noexcept { + auto const library_ready = sodium_ready(); + if (!library_ready) { + return library_ready; } - if (crypto_scalarmult_curve25519_base(out.data(), secret_key.data()) != 0) { + if (crypto_scalarmult_curve25519_base(output_bytes.data(), secret_key.data()) != 0) { return error::backend_failure; } return {}; @@ -610,12 +626,12 @@ struct x25519_engine { [[nodiscard]] static boost::system::result agree( std::span secret_key, std::span peer_public_key, - std::span out) noexcept { - auto const ready = sodium_ready(); - if (!ready) { - return ready; + std::span output_bytes) noexcept { + auto const library_ready = sodium_ready(); + if (!library_ready) { + return library_ready; } - if (sodium_refused(crypto_scalarmult_curve25519(out.data(), secret_key.data(), + if (sodium_refused(crypto_scalarmult_curve25519(output_bytes.data(), secret_key.data(), peer_public_key.data()))) { return error::weak_public_key; } @@ -653,27 +669,28 @@ struct sodium_box_calls; template <> struct sodium_box_calls { /** Agrees the key. */ - static constexpr auto beforenm = &crypto_box_beforenm; + static constexpr auto beforenm_call = &crypto_box_beforenm; /** Encrypts and computes the tag apart. */ - static constexpr auto encrypt = &crypto_box_detached_afternm; + static constexpr auto encrypt_call = &crypto_box_detached_afternm; /** Checks the tag apart, then decrypts. */ - static constexpr auto decrypt = &crypto_box_open_detached_afternm; + static constexpr auto decrypt_call = &crypto_box_open_detached_afternm; }; /** `crypto_box_curve25519xchacha20poly1305`, X25519-XChaCha20-Poly1305. */ template <> struct sodium_box_calls { /** Agrees the key. */ - static constexpr auto beforenm = &crypto_box_curve25519xchacha20poly1305_beforenm; + static constexpr auto beforenm_call = &crypto_box_curve25519xchacha20poly1305_beforenm; /** Encrypts and computes the tag apart. */ - static constexpr auto encrypt = &crypto_box_curve25519xchacha20poly1305_detached_afternm; + static constexpr auto encrypt_call = &crypto_box_curve25519xchacha20poly1305_detached_afternm; /** Checks the tag apart, then decrypts. */ - static constexpr auto decrypt = &crypto_box_curve25519xchacha20poly1305_open_detached_afternm; + static constexpr auto decrypt_call = + &crypto_box_curve25519xchacha20poly1305_open_detached_afternm; }; /** What a box stores on libsodium: the key `beforenm` agreed. */ template - requires requires { sodium_box_calls::beforenm; } + requires requires { sodium_box_calls::beforenm_call; } struct box_state { /** The agreed key. */ std::array key{}; @@ -681,7 +698,7 @@ struct box_state { /** A box on libsodium: `beforenm` once, then the `afternm` functions per message. */ template - requires requires { sodium_box_calls::beforenm; } + requires requires { sodium_box_calls::beforenm_call; } struct box_engine { /** The state. */ using state = box_state; @@ -695,55 +712,57 @@ struct box_engine { * @return Nothing; `weak_public_key`; `backend_failure` when libsodium cannot start. */ [[nodiscard]] static boost::system::result init( - state& s, std::span secret_key, + state& engine_state, std::span secret_key, std::span peer_public_key) noexcept { - auto const ready = sodium_ready(); - if (!ready) { - return ready; + auto const library_ready = sodium_ready(); + if (!library_ready) { + return library_ready; } - if (sodium_refused( - calls::beforenm(s.key.data(), peer_public_key.data(), secret_key.data()))) { - wipe_object(s.key); + if (sodium_refused(calls::beforenm_call(engine_state.key.data(), peer_public_key.data(), + secret_key.data()))) { + wipe_object(engine_state.key); return error::weak_public_key; } return {}; } /** - * Encrypts `data` in place and writes the tag. + * Encrypts `data_bytes` in place and writes the tag. * * @return Nothing; `backend_failure` when libsodium fails. */ - [[nodiscard]] static boost::system::result seal(state& s, - std::span iv, - std::span data, - boost::hash2::digest<16>& tag) noexcept { + [[nodiscard]] static boost::system::result seal( + state& engine_state, std::span iv_bytes, + std::span data_bytes, boost::hash2::digest<16>& tag_bytes) noexcept { read_canary(WEBCPP_CRYPTO_DETAIL_SODIUM_CANARY); - return sodium_secretbox_seal(calls::encrypt, std::span(s.key), iv, - data, tag); + return sodium_secretbox_seal(calls::encrypt_call, + std::span(engine_state.key), iv_bytes, + data_bytes, tag_bytes); } /** - * Checks the tag, then decrypts `data` in place. + * Checks the tag, then decrypts `data_bytes` in place. * * @return Nothing; `authentication_failed` when the tag does not match. */ [[nodiscard]] static boost::system::result open( - state& s, std::span iv, std::span data, - std::array const& tag) noexcept { + state& engine_state, std::span iv_bytes, + std::span data_bytes, + std::array const& tag_bytes) noexcept { read_canary(WEBCPP_CRYPTO_DETAIL_SODIUM_CANARY); - return sodium_secretbox_open(calls::decrypt, std::span(s.key), iv, - data, tag); + return sodium_secretbox_open(calls::decrypt_call, + std::span(engine_state.key), iv_bytes, + data_bytes, tag_bytes); } /** Moves the key; the source is wiped. */ - static void move(state& to, state& from) noexcept { - to.key = from.key; - wipe_object(from.key); + static void move(state& target_state, state& source_state) noexcept { + target_state.key = source_state.key; + wipe_object(source_state.key); } /** Wipes the key. */ - static void reset(state& s) noexcept { wipe_object(s.key); } + static void reset(state& engine_state) noexcept { wipe_object(engine_state.key); } }; } // namespace webcpp::crypto::detail @@ -768,20 +787,21 @@ namespace webcpp::crypto::detail { template <> struct sealed_box_engine { /** - * Seals `message` into `out` (`basic_sealed_box` has checked the sizes): libsodium draws - * the key pair from its own generator and wipes its secret key. + * Seals `message_bytes` into `output_bytes` (`basic_sealed_box` has checked the sizes): + * libsodium draws the key pair from its own generator and wipes its secret key. * * @return Nothing; `weak_public_key` for a recipient key of small order, which libsodium's * box refuses; `backend_failure` when libsodium cannot start. */ [[nodiscard]] static boost::system::result seal( std::span recipient_public_key, - std::span message, std::span out) noexcept { - auto const ready = sodium_ready(); - if (!ready) { - return ready; + std::span message_bytes, + std::span output_bytes) noexcept { + auto const library_ready = sodium_ready(); + if (!library_ready) { + return library_ready; } - if (crypto_box_seal(out.data(), message.data(), message.size(), + if (crypto_box_seal(output_bytes.data(), message_bytes.data(), message_bytes.size(), recipient_public_key.data()) != 0) { return error::weak_public_key; } @@ -789,20 +809,20 @@ struct sealed_box_engine { } /** - * Opens `sealed` into `out` (`basic_sealed_box` has checked the sizes). + * Opens `sealed_bytes` into `output_bytes` (`basic_sealed_box` has checked the sizes). * * @return Nothing; `authentication_failed`; `backend_failure` when libsodium cannot start. */ [[nodiscard]] static boost::system::result open( std::span recipient_public_key, std::span recipient_secret_key, - std::span sealed, std::span out) noexcept { - auto const ready = sodium_ready(); - if (!ready) { - return ready; + std::span sealed_bytes, std::span output_bytes) noexcept { + auto const library_ready = sodium_ready(); + if (!library_ready) { + return library_ready; } - if (sodium_refused(crypto_box_seal_open(out.data(), sealed.data(), sealed.size(), - recipient_public_key.data(), + if (sodium_refused(crypto_box_seal_open(output_bytes.data(), sealed_bytes.data(), + sealed_bytes.size(), recipient_public_key.data(), recipient_secret_key.data()))) { return error::authentication_failed; } @@ -843,36 +863,36 @@ struct sodium_rfc8410 { /** * Writes the prefix, then the key. * - * @param prefix The format's prefix. - * @param key 32 bytes. - * @param out The prefix's size and 32 bytes. + * @param prefix_bytes The format's prefix. + * @param key_bytes 32 bytes. + * @param output_bytes The prefix's size and 32 bytes. */ template - static void encode(std::array const& prefix, - std::span key, - std::span out) noexcept { + static void encode(std::array const& prefix_bytes, + std::span key_bytes, + std::span output_bytes) noexcept { read_canary(WEBCPP_CRYPTO_DETAIL_SODIUM_CANARY); - std::ranges::copy(key, std::ranges::copy(prefix, out.begin()).out); + std::ranges::copy(key_bytes, std::ranges::copy(prefix_bytes, output_bytes.begin()).out); } /** * Copies the key out of an encoding whose prefix is the format's. * - * @param prefix The format's prefix. - * @param der The prefix's size and 32 bytes. - * @param key 32 bytes, written only when the prefix is the format's. + * @param prefix_bytes The format's prefix. + * @param der_bytes The prefix's size and 32 bytes. + * @param key_bytes 32 bytes, written only when the prefix is the format's. * @return Nothing; `invalid_encoding`. */ template [[nodiscard]] static boost::system::result decode( - std::array const& prefix, - std::span der, - std::span key) noexcept { + std::array const& prefix_bytes, + std::span der_bytes, + std::span key_bytes) noexcept { read_canary(WEBCPP_CRYPTO_DETAIL_SODIUM_CANARY); - if (!equal(der.template first(), prefix)) { + if (!equal(der_bytes.template first(), prefix_bytes)) { return error::invalid_encoding; } - std::ranges::copy(der.template last<32>(), key.begin()); + std::ranges::copy(der_bytes.template last<32>(), key_bytes.begin()); return {}; } }; @@ -893,8 +913,8 @@ template <> struct ed25519_formats_engine { /** Writes the SPKI. */ static void encode_spki(std::span public_key, - std::span out) noexcept { - sodium_rfc8410::encode(ed25519_spki_prefix, public_key, out); + std::span output_bytes) noexcept { + sodium_rfc8410::encode(ed25519_spki_prefix, public_key, output_bytes); } /** @@ -903,15 +923,17 @@ struct ed25519_formats_engine { * @return Nothing; `invalid_encoding`. */ [[nodiscard]] static boost::system::result decode_spki( - std::span spki, std::span public_key) noexcept { - return sodium_rfc8410::decode(ed25519_spki_prefix, spki, public_key); + std::span spki_bytes, + std::span public_key) noexcept { + return sodium_rfc8410::decode(ed25519_spki_prefix, spki_bytes, public_key); } /** Writes the PKCS#8 of the seed, the first half of libsodium's secret key. */ - static void encode_pkcs8(ed25519_state const& keyed, - std::span out) noexcept { + static void encode_pkcs8(ed25519_state const& keyed_state, + std::span output_bytes) noexcept { sodium_rfc8410::encode(ed25519_pkcs8_prefix, - std::span(keyed.secret_key).first<32>(), out); + std::span(keyed_state.secret_key).first<32>(), + output_bytes); } /** @@ -920,8 +942,9 @@ struct ed25519_formats_engine { * @return Nothing; `invalid_encoding`. */ [[nodiscard]] static boost::system::result decode_pkcs8( - std::span pkcs8, std::span seed) noexcept { - return sodium_rfc8410::decode(ed25519_pkcs8_prefix, pkcs8, seed); + std::span pkcs8_bytes, + std::span seed_bytes) noexcept { + return sodium_rfc8410::decode(ed25519_pkcs8_prefix, pkcs8_bytes, seed_bytes); } }; @@ -941,8 +964,8 @@ template <> struct x25519_formats_engine { /** Writes the SPKI. */ static void encode_spki(std::span public_key, - std::span out) noexcept { - sodium_rfc8410::encode(x25519_spki_prefix, public_key, out); + std::span output_bytes) noexcept { + sodium_rfc8410::encode(x25519_spki_prefix, public_key, output_bytes); } /** @@ -951,14 +974,15 @@ struct x25519_formats_engine { * @return Nothing; `invalid_encoding`. */ [[nodiscard]] static boost::system::result decode_spki( - std::span spki, std::span public_key) noexcept { - return sodium_rfc8410::decode(x25519_spki_prefix, spki, public_key); + std::span spki_bytes, + std::span public_key) noexcept { + return sodium_rfc8410::decode(x25519_spki_prefix, spki_bytes, public_key); } /** Writes the PKCS#8 of a secret key. */ static void encode_pkcs8(std::span secret_key, - std::span out) noexcept { - sodium_rfc8410::encode(x25519_pkcs8_prefix, secret_key, out); + std::span output_bytes) noexcept { + sodium_rfc8410::encode(x25519_pkcs8_prefix, secret_key, output_bytes); } /** @@ -967,8 +991,9 @@ struct x25519_formats_engine { * @return Nothing; `invalid_encoding`. */ [[nodiscard]] static boost::system::result decode_pkcs8( - std::span pkcs8, std::span secret_key) noexcept { - return sodium_rfc8410::decode(x25519_pkcs8_prefix, pkcs8, secret_key); + std::span pkcs8_bytes, + std::span secret_key) noexcept { + return sodium_rfc8410::decode(x25519_pkcs8_prefix, pkcs8_bytes, secret_key); } }; @@ -1013,39 +1038,44 @@ struct pem_engine { /** * The base64 of at most 48 bytes, with padding. * - * @param bytes 1 to 48 bytes. - * @param out Exactly the base64's characters, four per three bytes begun. + * @param input_bytes 1 to 48 bytes. + * @param output_characters Exactly the base64's characters, four per three bytes begun. */ - static void encode(std::span bytes, std::span out) noexcept { + static void encode(std::span input_bytes, + std::span output_characters) noexcept { read_canary(WEBCPP_CRYPTO_DETAIL_SODIUM_CANARY); - // libsodium ends the text with a NUL, which out does not hold. + // libsodium ends the text with a NUL, which `output_characters` does not hold. // NOLINTNEXTLINE(readability-math-missing-parentheses,bugprone-signed-bitwise): its macro - std::array text{}; - static_cast(sodium_bin2base64(text.data(), text.size(), bytes.data(), bytes.size(), + std::array + base64_text{}; + static_cast(sodium_bin2base64(base64_text.data(), base64_text.size(), + input_bytes.data(), input_bytes.size(), sodium_base64_VARIANT_ORIGINAL)); - std::ranges::copy(std::span(text).first(out.size()), out.begin()); - wipe_object(text); + std::ranges::copy(std::span(base64_text).first(output_characters.size()), + output_characters.begin()); + wipe_object(base64_text); } /** * The bytes of at most 64 characters of base64 with padding. * - * @param text 1 to 64 characters. - * @param out 48 bytes, of which the decoded are written. + * @param base64_text 1 to 64 characters. + * @param output_bytes 48 bytes, of which the decoded are written. * @return The bytes' count; `invalid_encoding` for a character outside the alphabet, padding * missing or misplaced, or characters left over. */ [[nodiscard]] static boost::system::result decode( - std::string_view text, std::span out) noexcept { + std::string_view base64_text, std::span output_bytes) noexcept { read_canary(WEBCPP_CRYPTO_DETAIL_SODIUM_CANARY); - std::size_t written = 0; - char const* end = nullptr; - if (sodium_base642bin(out.data(), out.size(), text.data(), text.size(), nullptr, &written, - &end, sodium_base64_VARIANT_ORIGINAL) != 0 || - end != text.data() + text.size()) { + std::size_t written_count = 0; + char const* parse_end = nullptr; + if (sodium_base642bin(output_bytes.data(), output_bytes.size(), base64_text.data(), + base64_text.size(), nullptr, &written_count, &parse_end, + sodium_base64_VARIANT_ORIGINAL) != 0 || + parse_end != base64_text.data() + base64_text.size()) { return error::invalid_encoding; } - return written; + return written_count; } }; @@ -1091,22 +1121,24 @@ struct kx_engine { * @return Nothing; `backend_failure`. */ [[nodiscard]] static boost::system::result make( - state& keyed, std::span seed) noexcept { - auto const ready = sodium_ready(); - if (!ready) { - return ready; + state& keyed_state, + std::span seed_bytes) noexcept { + auto const library_ready = sodium_ready(); + if (!library_ready) { + return library_ready; } - if (crypto_kx_seed_keypair(keyed.public_key.data(), keyed.secret_key.data(), seed.data()) != - 0) { + if (crypto_kx_seed_keypair(keyed_state.public_key.data(), keyed_state.secret_key.data(), + seed_bytes.data()) != 0) { return error::backend_failure; } return {}; } /** The public key. */ - static void public_key(state const& keyed, - std::span out) noexcept { - std::ranges::copy(keyed.public_key, out.begin()); + static void public_key( + state const& keyed_state, + std::span output_bytes) noexcept { + std::ranges::copy(keyed_state.public_key, output_bytes.begin()); } /** @@ -1116,13 +1148,14 @@ struct kx_engine { * @return Nothing; `weak_public_key`. */ [[nodiscard]] static boost::system::result client( - state const& keyed, std::span server_key, - std::span receive, - std::span transmit) noexcept { + state const& keyed_state, + std::span server_key, + std::span receive_key, + std::span transmit_key) noexcept { read_canary(WEBCPP_CRYPTO_DETAIL_SODIUM_CANARY); if (sodium_refused(crypto_kx_client_session_keys( - receive.data(), transmit.data(), keyed.public_key.data(), keyed.secret_key.data(), - server_key.data()))) { + receive_key.data(), transmit_key.data(), keyed_state.public_key.data(), + keyed_state.secret_key.data(), server_key.data()))) { return error::weak_public_key; } return {}; @@ -1135,20 +1168,21 @@ struct kx_engine { * @return Nothing; `weak_public_key`. */ [[nodiscard]] static boost::system::result server( - state const& keyed, std::span client_key, - std::span receive, - std::span transmit) noexcept { + state const& keyed_state, + std::span client_key, + std::span receive_key, + std::span transmit_key) noexcept { read_canary(WEBCPP_CRYPTO_DETAIL_SODIUM_CANARY); if (sodium_refused(crypto_kx_server_session_keys( - receive.data(), transmit.data(), keyed.public_key.data(), keyed.secret_key.data(), - client_key.data()))) { + receive_key.data(), transmit_key.data(), keyed_state.public_key.data(), + keyed_state.secret_key.data(), client_key.data()))) { return error::weak_public_key; } return {}; } /** Wipes the key pair. */ - static void reset(state& keyed) noexcept { wipe_object(keyed); } + static void reset(state& keyed_state) noexcept { wipe_object(keyed_state); } }; } // namespace webcpp::crypto::detail diff --git a/include/webcpp/crypto/ciphers/aead.hpp b/include/webcpp/crypto/ciphers/aead.hpp index fcb47307..a2f22b19 100644 --- a/include/webcpp/crypto/ciphers/aead.hpp +++ b/include/webcpp/crypto/ciphers/aead.hpp @@ -320,7 +320,7 @@ class aead { */ [[nodiscard]] static boost::system::result make( std::span key_bytes) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert( !detail::asynchronous_backend_v, "webcpp::crypto: make on this backend completes asynchronously: call async_make."); @@ -404,7 +404,7 @@ class aead { [[nodiscard]] boost::system::result seal( std::span iv_bytes, std::span additional_data_bytes, std::span data_bytes) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert( !detail::asynchronous_backend_v, "webcpp::crypto: seal on this backend completes asynchronously: call async_seal."); @@ -447,7 +447,7 @@ class aead { [[nodiscard]] boost::system::result open( std::span iv_bytes, std::span additional_data_bytes, std::span data_bytes, std::span tag_bytes) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert( !detail::asynchronous_backend_v, "webcpp::crypto: open on this backend completes asynchronously: call async_open."); @@ -536,7 +536,7 @@ template additional_data_bytes, data_bytes))) -> decltype(keyed_aead.seal(iv_bytes, additional_data_bytes, data_bytes)) { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; return keyed_aead.seal(iv_bytes, additional_data_bytes, data_bytes); } @@ -570,7 +570,7 @@ template additional_data_bytes, data_bytes, tag_bytes))) -> decltype(keyed_aead.open(iv_bytes, additional_data_bytes, data_bytes, tag_bytes)) { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; return keyed_aead.open(iv_bytes, additional_data_bytes, data_bytes, tag_bytes); } diff --git a/include/webcpp/crypto/ciphers/aes.hpp b/include/webcpp/crypto/ciphers/aes.hpp index 8931225f..d9ec52bf 100644 --- a/include/webcpp/crypto/ciphers/aes.hpp +++ b/include/webcpp/crypto/ciphers/aes.hpp @@ -200,7 +200,7 @@ class basic_aes { */ [[nodiscard]] boost::system::result encrypt( std::span block_bytes) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; if (!keyed_) { return error::invalid_state; } @@ -219,7 +219,7 @@ class basic_aes { */ [[nodiscard]] boost::system::result decrypt( std::span block_bytes) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; if (!keyed_) { return error::invalid_state; } @@ -281,7 +281,7 @@ class aes128 : public detail::basic_aes<16, Backend> { */ [[nodiscard]] static boost::system::result make( std::span key_bytes) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; return detail::basic_aes<16, Backend>::template make_as(key_bytes); } @@ -307,7 +307,7 @@ class aes192 : public detail::basic_aes<24, Backend> { */ [[nodiscard]] static boost::system::result make( std::span key_bytes) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; return detail::basic_aes<24, Backend>::template make_as(key_bytes); } @@ -333,7 +333,7 @@ class aes256 : public detail::basic_aes<32, Backend> { */ [[nodiscard]] static boost::system::result make( std::span key_bytes) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; return detail::basic_aes<32, Backend>::template make_as(key_bytes); } diff --git a/include/webcpp/crypto/ciphers/gcm.hpp b/include/webcpp/crypto/ciphers/gcm.hpp index 67b7f2b6..f475f3d7 100644 --- a/include/webcpp/crypto/ciphers/gcm.hpp +++ b/include/webcpp/crypto/ciphers/gcm.hpp @@ -167,7 +167,7 @@ class gcm { */ [[nodiscard]] static boost::system::result make( std::span key_bytes) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert( !detail::asynchronous_backend_v, "webcpp::crypto: make on this backend completes asynchronously: call async_make."); @@ -190,7 +190,7 @@ class gcm { /** * Expands a key into a new object, asynchronously: `make` run when the operation is - * initiated, its result posted to `executor`; the member form of + * initiated, its result posted to `completion_executor`; the member form of * `crypto::async_make(executor, key_bytes, token)`, which calls it. * * Declared here and defined in ``, which a program includes to call @@ -198,17 +198,18 @@ class gcm { * "deduced return type used before it is defined". * * @tparam Executor The executor's type, an Asio executor (an `io_context`'s or a strand's). - * @tparam CompletionToken Any completion token for the signature `token` states. - * @param executor The executor the completion is posted to. + * @tparam CompletionToken Any completion token for the signature `completion_token` states. + * @param completion_executor The executor the completion is posted to. * @param key_bytes `key_size` bytes, the caller's until the completion. - * @param token The completion token, of signature `void(boost::system::error_code, gcm)`; on - * an error the object is empty, and every member refuses with `invalid_state` + * @param completion_token The completion token, of signature `void(boost::system::error_code, + * gcm)`; on an error the object is empty, and every member refuses with `invalid_state` * (`invalid_key_size`, `errc::not_enough_memory`, `backend_failure`). * @return What the completion token's `async_result` gives. */ template - static auto async_make(Executor const& executor, std::span key_bytes, - CompletionToken&& token); + static auto async_make(Executor const& completion_executor, + std::span key_bytes, + CompletionToken&& completion_token); /** * Moves the key; a message in progress is abandoned, and the source is wiped and empty. @@ -219,7 +220,7 @@ class gcm { * @param moved_source The source, empty afterwards. */ gcm(gcm&& moved_source) noexcept : keyed_(std::exchange(moved_source.keyed_, false)) { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; if (keyed_) { moved_source.abandon_message(); engine::move(state_, moved_source.state_); @@ -235,7 +236,7 @@ class gcm { * @return This object. */ gcm& operator=(gcm&& moved_source) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; if (this != &moved_source) { engine::reset(state_); keyed_ = std::exchange(moved_source.keyed_, false); @@ -275,7 +276,7 @@ class gcm { [[nodiscard]] boost::system::result seal( std::span iv_bytes, std::span additional_data_bytes, std::span data_bytes) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert( !detail::asynchronous_backend_v, "webcpp::crypto: seal on this backend completes asynchronously: call async_seal."); @@ -305,7 +306,7 @@ class gcm { /** * Seals a message in place, asynchronously: `seal` run when the operation is initiated, its - * result posted to `executor`; the member form of + * result posted to `completion_executor`; the member form of * `crypto::async_seal(executor, aead, iv_bytes, additional_data_bytes, data_bytes, token)`, * which calls it. * @@ -317,20 +318,20 @@ class gcm { * "deduced return type used before it is defined". * * @tparam Executor The executor's type, an Asio executor (an `io_context`'s or a strand's). - * @tparam CompletionToken Any completion token for the signature `token` states. - * @param executor The executor the completion is posted to. + * @tparam CompletionToken Any completion token for the signature `completion_token` states. + * @param completion_executor The executor the completion is posted to. * @param iv_bytes 1 to `max_iv_size` bytes, never reused under this key. * @param additional_data_bytes Authenticated, not encrypted. * @param data_bytes The message. - * @param token The completion token, of signature + * @param completion_token The completion token, of signature * `void(boost::system::error_code, result_type)`: the tag; on an error the zeroed tag (the * errors of `seal`). * @return What the completion token's `async_result` gives. */ template - auto async_seal(Executor const& executor, std::span iv_bytes, + auto async_seal(Executor const& completion_executor, std::span iv_bytes, std::span additional_data_bytes, - std::span data_bytes, CompletionToken&& token); + std::span data_bytes, CompletionToken&& completion_token); /** * Opens a message in place: `data_bytes` holds the ciphertext before and the plaintext after. @@ -350,7 +351,7 @@ class gcm { [[nodiscard]] boost::system::result open( std::span iv_bytes, std::span additional_data_bytes, std::span data_bytes, std::span tag_bytes) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert( !detail::asynchronous_backend_v, "webcpp::crypto: open on this backend completes asynchronously: call async_open."); @@ -381,8 +382,8 @@ class gcm { /** * Opens a message in place, asynchronously: `open` run when the operation is initiated, its - * result posted to `executor`; the member form of `crypto::async_open`, which calls it with the - * executor and the object before this function's arguments. + * result posted to `completion_executor`; the member form of `crypto::async_open`, which calls + * it with the executor and the object before this function's arguments. * * The object and the spans are the caller's until the completion; `data_bytes` holds the * plaintext at a successful completion. @@ -392,21 +393,21 @@ class gcm { * "deduced return type used before it is defined". * * @tparam Executor The executor's type, an Asio executor (an `io_context`'s or a strand's). - * @tparam CompletionToken Any completion token for the signature `token` states. - * @param executor The executor the completion is posted to. + * @tparam CompletionToken Any completion token for the signature `completion_token` states. + * @param completion_executor The executor the completion is posted to. * @param iv_bytes The IV of the seal. * @param additional_data_bytes The additional data of the seal. * @param data_bytes The ciphertext. * @param tag_bytes The seal's tag, 16 bytes. - * @param token The completion token, of signature `void(boost::system::error_code)` (`open`'s - * errors). + * @param completion_token The completion token, of signature `void(boost::system::error_code)` + * (`open`'s errors). * @return What the completion token's `async_result` gives. */ template - auto async_open(Executor const& executor, std::span iv_bytes, + auto async_open(Executor const& completion_executor, std::span iv_bytes, std::span additional_data_bytes, std::span data_bytes, std::span tag_bytes, - CompletionToken&& token); + CompletionToken&& completion_token); /** * Begins an incremental seal: the IV and the whole additional data first, both read @@ -423,7 +424,7 @@ class gcm { [[nodiscard]] boost::system::result begin_seal( std::span iv_bytes, std::span additional_data_bytes) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; if (!keyed_) { return error::invalid_state; } @@ -457,7 +458,7 @@ class gcm { * `backend_failure`, which ends it. */ [[nodiscard]] boost::system::result update(std::span data_bytes) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; auto const phase_result = require_phase(phase::sealing); if (!phase_result) { return phase_result.error(); @@ -483,7 +484,7 @@ class gcm { * `backend_failure`, which ends the seal too. */ [[nodiscard]] boost::system::result result() noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; auto const phase_result = require_phase(phase::sealing); if (!phase_result) { return phase_result.error(); @@ -514,7 +515,7 @@ class gcm { [[nodiscard]] boost::system::result begin_open( std::span iv_bytes, std::span additional_data_bytes) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; if (!keyed_) { return error::invalid_state; } @@ -554,7 +555,7 @@ class gcm { */ [[nodiscard]] boost::system::result authenticate( std::span ciphertext_piece) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; auto const phase_result = require_phase(phase::authenticating); if (!phase_result) { return phase_result.error(); @@ -563,14 +564,14 @@ class gcm { abandon(); return error::message_too_long; } - std::array scratch{}; + std::array scratch_bytes{}; for (std::size_t piece_start = 0; piece_start < ciphertext_piece.size(); piece_start += scratch_size) { std::size_t const block_size = (std::min)(scratch_size, ciphertext_piece.size() - piece_start); - std::copy_n(ciphertext_piece.data() + piece_start, block_size, scratch.data()); - auto const run_result = engine::run(state_, std::span(scratch).first(block_size)); - detail::wipe(scratch.data(), block_size); + std::copy_n(ciphertext_piece.data() + piece_start, block_size, scratch_bytes.data()); + auto const run_result = engine::run(state_, std::span(scratch_bytes).first(block_size)); + detail::wipe(scratch_bytes.data(), block_size); if (!run_result) { abandon(); return run_result.error(); @@ -591,7 +592,7 @@ class gcm { */ [[nodiscard]] boost::system::result verify( std::span tag_bytes) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; auto const phase_result = require_phase(phase::authenticating); if (!phase_result) { return phase_result.error(); @@ -633,7 +634,7 @@ class gcm { * the message; `backend_failure`, which ends it. */ [[nodiscard]] boost::system::result decrypt(std::span data_piece) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; auto const phase_result = require_phase(phase::decrypting); if (!phase_result) { return phase_result.error(); @@ -660,14 +661,14 @@ class gcm { * which ends the message too. */ [[nodiscard]] boost::system::result end_open() noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; auto const phase_result = require_phase(phase::decrypting); if (!phase_result) { return phase_result.error(); } - bool const whole = decrypted_bytes_ == message_bytes_; + bool const whole_message = decrypted_bytes_ == message_bytes_; abandon(); - if (!whole) { + if (!whole_message) { return error::invalid_input_size; } return {}; @@ -685,13 +686,13 @@ class gcm { gcm() noexcept = default; - // A call of the incremental machine in `expected`: outside it, `invalid_state`, which ends - // a message in another phase. - [[nodiscard]] boost::system::result require_phase(phase expected) noexcept { + // A call of the incremental machine in `expected_phase`: outside it, `invalid_state`, which + // ends a message in another phase. + [[nodiscard]] boost::system::result require_phase(phase expected_phase) noexcept { if (!keyed_) { return error::invalid_state; } - if (phase_ != expected) { + if (phase_ != expected_phase) { if (phase_ != phase::none) { abandon(); } diff --git a/include/webcpp/crypto/curves/ed25519.hpp b/include/webcpp/crypto/curves/ed25519.hpp index f0a017c6..6c38a2e2 100644 --- a/include/webcpp/crypto/curves/ed25519.hpp +++ b/include/webcpp/crypto/curves/ed25519.hpp @@ -198,7 +198,7 @@ class public_key { [[maybe_unused]] Scheme signing_scheme, std::span signature_bytes, Input const& message_input, [[maybe_unused]] Policy verify_policy = Policy{}) const noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert(std::is_same_v, "webcpp::crypto: an Ed25519 public key verifies crypto::eddsa."); static_assert(!detail::asynchronous_backend_v, @@ -338,7 +338,7 @@ class basic_keypair { */ [[nodiscard]] static boost::system::result make( std::span seed_bytes) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert( !detail::asynchronous_backend_v, "webcpp::crypto: make on this backend completes asynchronously: call async_make."); @@ -367,7 +367,7 @@ class basic_keypair { * none; `backend_failure`. */ [[nodiscard]] static boost::system::result generate() noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert(!detail::asynchronous_backend_v, "webcpp::crypto: generate on this backend completes asynchronously: call " "async_generate."); @@ -474,7 +474,7 @@ class basic_keypair { * @return The public key; `invalid_state` moved from. */ [[nodiscard]] boost::system::result public_key() const noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; if (!keyed_) { return error::invalid_state; } @@ -490,7 +490,7 @@ class basic_keypair { * @return 32 secret bytes; `invalid_state` moved from. */ [[nodiscard]] boost::system::result> secret() const noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; if (!keyed_) { return error::invalid_state; } @@ -513,7 +513,7 @@ class basic_keypair { template [[nodiscard]] boost::system::result> sign( [[maybe_unused]] Scheme signing_scheme, Input const& message_input) const noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert(std::is_same_v, "webcpp::crypto: an Ed25519 key signs with crypto::eddsa."); static_assert(!detail::asynchronous_backend_v, @@ -570,7 +570,7 @@ class basic_keypair { * @return 32 secret bytes; `invalid_state`; `backend_failure`. */ [[nodiscard]] boost::system::result> x25519_secret() const noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; if (!keyed_) { return error::invalid_state; } @@ -619,7 +619,7 @@ using keypair = basic_keypair<>; template > [[nodiscard]] boost::system::result> to_x25519_public( public_key const& ed25519_public_key) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; auto const key_bytes = ed25519_public_key.bytes(); std::array converted_secret{}; auto const engine_done = detail::ed25519_engine::to_x25519_public( @@ -671,7 +671,7 @@ class ph { * @return The signer, ready for the message's pieces; `backend_failure`. */ [[nodiscard]] static boost::system::result begin() noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; ph begun_hash; auto const begin_result = engine::begin(begun_hash.state_); if (!begin_result) { @@ -723,7 +723,7 @@ class ph { */ [[nodiscard]] boost::system::result update( std::span piece_bytes) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; if (!begun_) { return error::invalid_state; } @@ -740,7 +740,7 @@ class ph { */ [[nodiscard]] boost::system::result> sign( basic_keypair const& key_pair) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; if (!begun_ || !key_pair.keyed_) { return error::invalid_state; } @@ -765,7 +765,7 @@ class ph { [[nodiscard]] boost::system::result verify( std::span signature_bytes, ::webcpp::crypto::curves::ed25519::public_key const& verifying_key) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; if (!begun_) { return error::invalid_state; } @@ -823,7 +823,7 @@ template , class Input, [[maybe_unused]] eddsa_t signing_scheme, std::span signature_bytes, Input const& message_input, curves::ed25519::public_key const& public_key, [[maybe_unused]] Policy verify_policy = Policy{}) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert(!detail::asynchronous_backend_v, "webcpp::crypto: verify on this backend completes asynchronously: call " "async_verify."); diff --git a/include/webcpp/crypto/curves/ed25519/formats.hpp b/include/webcpp/crypto/curves/ed25519/formats.hpp index f2a2142a..f52cb38b 100644 --- a/include/webcpp/crypto/curves/ed25519/formats.hpp +++ b/include/webcpp/crypto/curves/ed25519/formats.hpp @@ -133,7 +133,7 @@ template > template > [[nodiscard]] boost::system::result decode_spki( std::span spki_bytes) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; if (spki_bytes.size() != max_spki_size) { return error::invalid_encoding; } @@ -186,7 +186,7 @@ template > template > [[nodiscard]] boost::system::result> decode_pkcs8( std::span pkcs8_bytes) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; if (pkcs8_bytes.size() != max_pkcs8_size) { return error::invalid_encoding; } diff --git a/include/webcpp/crypto/curves/p256.hpp b/include/webcpp/crypto/curves/p256.hpp index 5e759b71..aa965939 100644 --- a/include/webcpp/crypto/curves/p256.hpp +++ b/include/webcpp/crypto/curves/p256.hpp @@ -149,7 +149,7 @@ class basic_public_key { */ [[nodiscard]] static boost::system::result make( std::span uncompressed_point) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; if (uncompressed_point.size() != public_key_size || uncompressed_point[0] != 0x04) { return error::invalid_public_key; } @@ -167,7 +167,7 @@ class basic_public_key { [[nodiscard]] static boost::system::result make( std::span x_coordinate, std::span y_coordinate) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; std::array point_bytes{0x04}; std::ranges::copy(x_coordinate, point_bytes.begin() + 1); std::ranges::copy(y_coordinate, point_bytes.begin() + 1 + coordinate_size); @@ -206,7 +206,7 @@ class basic_public_key { [[nodiscard]] boost::system::result verify([[maybe_unused]] Scheme signing_scheme, std::span signature_bytes, Input const& signing_input) const noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert(std::is_same_v, "webcpp::crypto: a P-256 public key verifies crypto::ecdsa_sha256."); static_assert(!detail::asynchronous_backend_v, @@ -321,7 +321,7 @@ class basic_keypair { */ [[nodiscard]] static boost::system::result make( std::span secret_scalar) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert( !detail::asynchronous_backend_v, "webcpp::crypto: make on this backend completes asynchronously: call async_make."); @@ -354,7 +354,7 @@ class basic_keypair { * none; `backend_failure`. */ [[nodiscard]] static boost::system::result generate() noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert(!detail::asynchronous_backend_v, "webcpp::crypto: generate on this backend completes asynchronously: call " "async_generate."); @@ -503,7 +503,7 @@ class basic_keypair { template [[nodiscard]] boost::system::result> sign( [[maybe_unused]] Scheme signing_scheme, Input const& signing_input) const noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert(std::is_same_v, "webcpp::crypto: a P-256 key signs with crypto::ecdsa_sha256."); static_assert(!detail::asynchronous_backend_v, @@ -571,7 +571,7 @@ class basic_keypair { */ [[nodiscard]] boost::system::result> agree( basic_public_key const& peer_key) const noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert( !detail::asynchronous_backend_v, "webcpp::crypto: agree on this backend completes asynchronously: call async_agree."); @@ -671,7 +671,7 @@ template > [[nodiscard]] boost::system::result to_der( std::span signature_bytes, std::span output_bytes) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; using engine = detail::p_curve_engine; if (output_bytes.size() < max_der_size) { return error::invalid_input_size; @@ -698,7 +698,7 @@ template > template > [[nodiscard]] boost::system::result> from_der( std::span der_signature) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; using engine = detail::p_curve_engine; if (der_signature.empty()) { return error::invalid_signature; @@ -784,7 +784,7 @@ template [[maybe_unused]] ecdsa_sha256_t signing_scheme, std::span signature_bytes, Input const& signing_input, curves::p256::basic_public_key const& public_key) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert(!detail::asynchronous_backend_v, "webcpp::crypto: verify on this backend completes asynchronously: call " "async_verify."); diff --git a/include/webcpp/crypto/curves/p256/formats.hpp b/include/webcpp/crypto/curves/p256/formats.hpp index d615c175..e629104e 100644 --- a/include/webcpp/crypto/curves/p256/formats.hpp +++ b/include/webcpp/crypto/curves/p256/formats.hpp @@ -112,7 +112,7 @@ template template > [[nodiscard]] boost::system::result> decode_spki( std::span spki_bytes) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; constexpr std::size_t prefix_size = detail::p256_spki_prefix.size(); if (spki_bytes.size() != max_spki_size || !equal(spki_bytes.first(prefix_size), detail::p256_spki_prefix)) { @@ -176,7 +176,7 @@ template template > [[nodiscard]] boost::system::result> decode_pkcs8( std::span pkcs8_bytes) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; constexpr std::size_t prefix_size = detail::p256_pkcs8_prefix.size(); constexpr std::size_t infix_at = prefix_size + secret_key_size; constexpr std::size_t point_at = infix_at + detail::p256_pkcs8_infix.size(); diff --git a/include/webcpp/crypto/curves/secp256k1.hpp b/include/webcpp/crypto/curves/secp256k1.hpp index 318fe2d2..4fb62317 100644 --- a/include/webcpp/crypto/curves/secp256k1.hpp +++ b/include/webcpp/crypto/curves/secp256k1.hpp @@ -644,7 +644,7 @@ class public_key { template > [[nodiscard]] static boost::system::result make( std::span encoded_key) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert( webcpp::crypto::detail::secp256k1_refuses_others); webcpp::crypto::detail::read_canary(WEBCPP_CRYPTO_DETAIL_SECP256K1_CANARY); @@ -664,7 +664,7 @@ class public_key { */ [[nodiscard]] std::array> compressed() const noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; return encoded>( webcpp::crypto::detail::secp256k1_compressed); } @@ -676,7 +676,7 @@ class public_key { */ [[nodiscard]] std::array> uncompressed() const noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; return encoded>( webcpp::crypto::detail::secp256k1_uncompressed); } @@ -688,7 +688,7 @@ class public_key { * @return 32 bytes. */ [[nodiscard]] std::array xonly() const noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; webcpp::crypto::detail::read_canary(WEBCPP_CRYPTO_DETAIL_SECP256K1_CANARY); secp256k1_selftest(); auto const xonly_key = webcpp::crypto::detail::secp256k1_xonly_of(point_value_); @@ -721,7 +721,7 @@ class public_key { [[nodiscard]] boost::system::result verify([[maybe_unused]] Scheme signing_scheme, std::span signature_bytes, Input const& signing_input) const noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert( webcpp::crypto::detail::secp256k1_refuses_others); constexpr bool is_ecdsa = std::is_same_v; @@ -751,7 +751,7 @@ class public_key { */ [[nodiscard]] friend bool operator==(public_key const& left_key, public_key const& right_key) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; return compare(left_key, right_key) == 0; } @@ -764,7 +764,7 @@ class public_key { */ [[nodiscard]] friend std::strong_ordering operator<=>(public_key const& left_key, public_key const& right_key) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; return compare(left_key, right_key) <=> 0; } @@ -857,7 +857,7 @@ class basic_keypair { [[nodiscard]] static boost::system::result make( std::span secret_bytes, std::pmr::memory_resource* memory_resource = std::pmr::get_default_resource()) { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; if (secret_bytes.size() != secret_key_size) { return error::invalid_key_size; } @@ -902,7 +902,7 @@ class basic_keypair { */ [[nodiscard]] static boost::system::result generate( std::pmr::memory_resource* memory_resource = std::pmr::get_default_resource()) { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; for (int draw_count = 0; draw_count < max_draws; ++draw_count) { crypto::secret secret_key; auto const entropy_drawn = @@ -966,7 +966,7 @@ class basic_keypair { * @return The public key; `invalid_state` moved from. */ [[nodiscard]] boost::system::result public_key() const noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; if (!keyed_) { return error::invalid_state; } @@ -985,7 +985,7 @@ class basic_keypair { * @return 32 secret bytes, big-endian; `invalid_state` moved from. */ [[nodiscard]] boost::system::result> secret() const noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; if (!keyed_) { return error::invalid_state; } @@ -1020,7 +1020,7 @@ class basic_keypair { [[nodiscard]] boost::system::result< std::array>> sign([[maybe_unused]] Scheme signing_scheme, Input const& signing_input) const noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; constexpr bool has_scheme = std::is_same_v || std::is_same_v || std::is_same_v; @@ -1063,7 +1063,7 @@ class basic_keypair { [[nodiscard]] boost::system::result> sign( [[maybe_unused]] ecdsa_sha256_t signing_scheme, Input const& signing_input, std::span extra_entropy) const noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; detail::check_input(); if constexpr (detail::input_valid_v) { webcpp::crypto::detail::secp256k1_secret nonce_data; @@ -1091,7 +1091,7 @@ class basic_keypair { [[nodiscard]] boost::system::result> sign( [[maybe_unused]] schnorr_t signing_scheme, Input const& message_input, std::span aux_random) const noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; detail::check_input(); if constexpr (detail::input_valid_v) { return signed_schnorr(detail::message_bytes(message_input), aux_random); @@ -1115,7 +1115,7 @@ class basic_keypair { */ [[nodiscard]] boost::system::result> agree( public_key_type const& peer_key) const noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; return ecdh_secret<32>(peer_key, webcpp::crypto::detail::webcpp_crypto_detail_secp256k1_copy_x); } @@ -1130,7 +1130,7 @@ class basic_keypair { */ [[nodiscard]] boost::system::result> agree_hashed( public_key_type const& peer_key) const noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; return ecdh_secret<32>(peer_key, nullptr); } @@ -1143,7 +1143,7 @@ class basic_keypair { */ [[nodiscard]] boost::system::result> agree_point( public_key_type const& peer_key) const noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; return ecdh_secret<65>(peer_key, webcpp::crypto::detail::webcpp_crypto_detail_secp256k1_copy_point); } @@ -1164,7 +1164,7 @@ class basic_keypair { */ [[nodiscard]] boost::system::result tweak_xonly( std::span tweak_bytes) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; if (!keyed_) { return error::invalid_state; } @@ -1418,7 +1418,7 @@ template , class Input> [[nodiscard]] boost::system::result recover( [[maybe_unused]] ecdsa_sha256_recoverable_t signing_scheme, std::span recoverable_signature, Input const& signing_input) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert(webcpp::crypto::detail::secp256k1_refuses_others); detail::check_input(); if constexpr (detail::input_valid_v) { @@ -1465,7 +1465,7 @@ template > [[nodiscard]] boost::system::result to_der( std::span compact_signature, std::span output_bytes) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert(webcpp::crypto::detail::secp256k1_refuses_others); if (output_bytes.size() < max_der_size) { return error::invalid_input_size; @@ -1497,7 +1497,7 @@ template > template > [[nodiscard]] boost::system::result> from_der( std::span der_signature) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert(webcpp::crypto::detail::secp256k1_refuses_others); if (der_signature.empty()) { return error::invalid_signature; @@ -1529,7 +1529,7 @@ template > template > [[nodiscard]] boost::system::result> normalize_low_s( std::span compact_signature) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert(webcpp::crypto::detail::secp256k1_refuses_others); webcpp::crypto::detail::read_canary(WEBCPP_CRYPTO_DETAIL_SECP256K1_CANARY); secp256k1_selftest(); @@ -1557,7 +1557,7 @@ template > */ template > [[nodiscard]] bool is_low_s(std::span compact_signature) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert(webcpp::crypto::detail::secp256k1_refuses_others); webcpp::crypto::detail::read_canary(WEBCPP_CRYPTO_DETAIL_SECP256K1_CANARY); secp256k1_selftest(); @@ -1587,7 +1587,7 @@ template > [[nodiscard]] boost::system::result tweak_xonly( std::span xonly_key_bytes, std::span tweak_bytes) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert(webcpp::crypto::detail::secp256k1_refuses_others); webcpp::crypto::detail::read_canary(WEBCPP_CRYPTO_DETAIL_SECP256K1_CANARY); secp256k1_selftest(); @@ -1637,7 +1637,7 @@ template , class Input> [[nodiscard]] boost::system::result verify( [[maybe_unused]] ecdsa_sha256_t signing_scheme, std::span signature_bytes, Input const& signing_input, curves::secp256k1::public_key const& public_key) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert(detail::secp256k1_refuses_others); return detail::secp256k1_verify_ecdsa(signature_bytes, signing_input, detail::secp256k1_access::point(public_key)); @@ -1663,7 +1663,7 @@ template , class Input> [[nodiscard]] boost::system::result verify( [[maybe_unused]] schnorr_t signing_scheme, std::span signature_bytes, Input const& message_input, std::span xonly_public_key) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert(detail::secp256k1_refuses_others); detail::check_input(); if constexpr (detail::input_valid_v) { @@ -1705,7 +1705,7 @@ template , class Input> [[nodiscard]] boost::system::result verify( [[maybe_unused]] schnorr_t signing_scheme, std::span signature_bytes, Input const& message_input, curves::secp256k1::public_key const& public_key) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert(detail::secp256k1_refuses_others); return detail::secp256k1_verify_schnorr_key( signature_bytes, message_input, detail::secp256k1_access::point(public_key)); diff --git a/include/webcpp/crypto/curves/secp256k1/ellswift.hpp b/include/webcpp/crypto/curves/secp256k1/ellswift.hpp index d4b67e58..097d4294 100644 --- a/include/webcpp/crypto/curves/secp256k1/ellswift.hpp +++ b/include/webcpp/crypto/curves/secp256k1/ellswift.hpp @@ -74,7 +74,7 @@ enum class ellswift_party { template > [[nodiscard]] std::array ellswift_encode( public_key const& parsed_key, std::span randomness_bytes) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert( webcpp::crypto::detail::secp256k1_refuses_others); webcpp::crypto::detail::read_canary(WEBCPP_CRYPTO_DETAIL_SECP256K1_CANARY); @@ -97,7 +97,7 @@ template > template > [[nodiscard]] public_key ellswift_decode( std::span encoded_key) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert( webcpp::crypto::detail::secp256k1_refuses_others); webcpp::crypto::detail::read_canary(WEBCPP_CRYPTO_DETAIL_SECP256K1_CANARY); @@ -124,7 +124,7 @@ template [[nodiscard]] boost::system::result> ellswift_create( basic_keypair const& key_pair, std::span randomness_bytes) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert( webcpp::crypto::detail::secp256k1_refuses_others); webcpp::crypto::detail::read_canary(WEBCPP_CRYPTO_DETAIL_SECP256K1_CANARY); @@ -166,7 +166,7 @@ template std::span initiator_encoding, std::span responder_encoding, ellswift_party our_party) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert( webcpp::crypto::detail::secp256k1_refuses_others); webcpp::crypto::detail::read_canary(WEBCPP_CRYPTO_DETAIL_SECP256K1_CANARY); diff --git a/include/webcpp/crypto/curves/secp256k1/formats.hpp b/include/webcpp/crypto/curves/secp256k1/formats.hpp index 747f66fd..2e6cecc1 100644 --- a/include/webcpp/crypto/curves/secp256k1/formats.hpp +++ b/include/webcpp/crypto/curves/secp256k1/formats.hpp @@ -98,7 +98,7 @@ template > [[nodiscard]] boost::system::result encode_spki( public_key const& parsed_key, std::span output_bytes, point_form encoded_form = point_form::compressed) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert(webcpp::crypto::detail::secp256k1_refuses_others); webcpp::crypto::detail::read_canary(WEBCPP_CRYPTO_DETAIL_SECP256K1_CANARY); if (output_bytes.size() < max_spki_size) { @@ -133,7 +133,7 @@ template > template > [[nodiscard]] boost::system::result decode_spki( std::span spki_bytes) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert(webcpp::crypto::detail::secp256k1_refuses_others); webcpp::crypto::detail::read_canary(WEBCPP_CRYPTO_DETAIL_SECP256K1_CANARY); secp256k1_selftest(); @@ -171,7 +171,7 @@ template > template > [[nodiscard]] boost::system::result encode_pkcs8( basic_keypair const& key_pair, std::span output_bytes) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert(webcpp::crypto::detail::secp256k1_refuses_others); webcpp::crypto::detail::read_canary(WEBCPP_CRYPTO_DETAIL_SECP256K1_CANARY); using access = webcpp::crypto::detail::secp256k1_access; @@ -215,7 +215,7 @@ template > [[nodiscard]] boost::system::result> decode_pkcs8( std::span pkcs8_bytes, std::pmr::memory_resource* memory_resource = std::pmr::get_default_resource()) { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert(webcpp::crypto::detail::secp256k1_refuses_others); webcpp::crypto::detail::read_canary(WEBCPP_CRYPTO_DETAIL_SECP256K1_CANARY); secp256k1_selftest(); diff --git a/include/webcpp/crypto/curves/secp256k1/musig.hpp b/include/webcpp/crypto/curves/secp256k1/musig.hpp index 5e1d9d1e..96883ec8 100644 --- a/include/webcpp/crypto/curves/secp256k1/musig.hpp +++ b/include/webcpp/crypto/curves/secp256k1/musig.hpp @@ -86,7 +86,7 @@ class aggregate_key { * @return 32 bytes, the tweaks included. */ [[nodiscard]] std::array xonly_public_key() const noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; webcpp::crypto::detail::read_canary(WEBCPP_CRYPTO_DETAIL_SECP256K1_CANARY); secp256k1_selftest(); public_key full_key = full_public_key(); @@ -107,7 +107,7 @@ class aggregate_key { * @return The key, the tweaks included. */ [[nodiscard]] public_key full_public_key() const noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; webcpp::crypto::detail::read_canary(WEBCPP_CRYPTO_DETAIL_SECP256K1_CANARY); secp256k1_selftest(); using access = webcpp::crypto::detail::secp256k1_access; @@ -130,7 +130,7 @@ class aggregate_key { */ [[nodiscard]] boost::system::result tweak_add( std::span tweak_bytes) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; return tweaked(tweak_bytes, secp256k1_musig_pubkey_ec_tweak_add); } @@ -144,7 +144,7 @@ class aggregate_key { */ [[nodiscard]] boost::system::result tweak_xonly_add( std::span tweak_bytes) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; return tweaked(tweak_bytes, secp256k1_musig_pubkey_xonly_tweak_add); } @@ -315,7 +315,7 @@ struct nonce_pair { template > [[nodiscard]] boost::system::result key_aggregate( std::span signer_keys, workspace pointer_space) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert( webcpp::crypto::detail::secp256k1_refuses_others); webcpp::crypto::detail::read_canary(WEBCPP_CRYPTO_DETAIL_SECP256K1_CANARY); @@ -364,7 +364,7 @@ template basic_keypair const& signer_pair, aggregate_key const& signers_key, std::span message_hash = {}, std::span extra_input = {}) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert( webcpp::crypto::detail::secp256k1_refuses_others); webcpp::crypto::detail::read_canary(WEBCPP_CRYPTO_DETAIL_SECP256K1_CANARY); @@ -420,7 +420,7 @@ template template > [[nodiscard]] boost::system::result nonce_aggregate( std::span signer_nonces, workspace pointer_space) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert( webcpp::crypto::detail::secp256k1_refuses_others); webcpp::crypto::detail::read_canary(WEBCPP_CRYPTO_DETAIL_SECP256K1_CANARY); @@ -462,7 +462,7 @@ template > [[nodiscard]] boost::system::result nonce_process( aggregate_nonce const& nonce_sum, std::span message_bytes, aggregate_key const& signers_key) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert( webcpp::crypto::detail::secp256k1_refuses_others); webcpp::crypto::detail::read_canary(WEBCPP_CRYPTO_DETAIL_SECP256K1_CANARY); @@ -493,7 +493,7 @@ template [[nodiscard]] boost::system::result partial_sign( basic_keypair const& signer_pair, secret_nonce signer_nonce, aggregate_key const& signers_key, session const& signing_session) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert( webcpp::crypto::detail::secp256k1_refuses_others); webcpp::crypto::detail::read_canary(WEBCPP_CRYPTO_DETAIL_SECP256K1_CANARY); @@ -541,7 +541,7 @@ template > partial_signature const& signature_part, public_nonce const& signer_nonce, public_key const& signer_key, aggregate_key const& signers_key, session const& signing_session) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert( webcpp::crypto::detail::secp256k1_refuses_others); webcpp::crypto::detail::read_canary(WEBCPP_CRYPTO_DETAIL_SECP256K1_CANARY); @@ -573,7 +573,7 @@ template > [[nodiscard]] boost::system::result> partial_signature_aggregate( session const& signing_session, std::span signature_parts, workspace pointer_space) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert( webcpp::crypto::detail::secp256k1_refuses_others); webcpp::crypto::detail::read_canary(WEBCPP_CRYPTO_DETAIL_SECP256K1_CANARY); @@ -613,7 +613,7 @@ template > template > [[nodiscard]] boost::system::result parse_public_nonce( std::span encoded_nonce) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert( webcpp::crypto::detail::secp256k1_refuses_others); webcpp::crypto::detail::read_canary(WEBCPP_CRYPTO_DETAIL_SECP256K1_CANARY); @@ -640,7 +640,7 @@ template > template > [[nodiscard]] std::array serialize_public_nonce( public_nonce const& parsed_nonce) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert( webcpp::crypto::detail::secp256k1_refuses_others); webcpp::crypto::detail::read_canary(WEBCPP_CRYPTO_DETAIL_SECP256K1_CANARY); @@ -665,7 +665,7 @@ template > template > [[nodiscard]] boost::system::result parse_aggregate_nonce( std::span encoded_nonce) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert( webcpp::crypto::detail::secp256k1_refuses_others); webcpp::crypto::detail::read_canary(WEBCPP_CRYPTO_DETAIL_SECP256K1_CANARY); @@ -692,7 +692,7 @@ template > template > [[nodiscard]] std::array serialize_aggregate_nonce( aggregate_nonce const& parsed_nonce) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert( webcpp::crypto::detail::secp256k1_refuses_others); webcpp::crypto::detail::read_canary(WEBCPP_CRYPTO_DETAIL_SECP256K1_CANARY); @@ -716,7 +716,7 @@ template > template > [[nodiscard]] boost::system::result parse_partial_signature( std::span encoded_signature) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert( webcpp::crypto::detail::secp256k1_refuses_others); webcpp::crypto::detail::read_canary(WEBCPP_CRYPTO_DETAIL_SECP256K1_CANARY); @@ -744,7 +744,7 @@ template > template > [[nodiscard]] std::array serialize_partial_signature( partial_signature const& parsed_signature) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert( webcpp::crypto::detail::secp256k1_refuses_others); webcpp::crypto::detail::read_canary(WEBCPP_CRYPTO_DETAIL_SECP256K1_CANARY); diff --git a/include/webcpp/crypto/curves/secp256k1/silent_payments.hpp b/include/webcpp/crypto/curves/secp256k1/silent_payments.hpp index 2204cc48..7f71105d 100644 --- a/include/webcpp/crypto/curves/secp256k1/silent_payments.hpp +++ b/include/webcpp/crypto/curves/secp256k1/silent_payments.hpp @@ -302,7 +302,7 @@ template std::span> const* const> taproot_inputs, std::span> const* const> plain_inputs, std::span> output_keys, workspace pointer_space) noexcept { - detail::timing_guard const timing; + detail::timing_guard const timing_scope; static_assert( webcpp::crypto::detail::secp256k1_refuses_others); @@ -396,7 +396,7 @@ template template [[nodiscard]] boost::system::result