diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b423452426c..fa1e1dae29b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,14 +70,18 @@ jobs: include: - compiler: gcc target: shared + host_os: ubuntu-22.04 - compiler: gcc target: amalgamation + host_os: ubuntu-22.04 - compiler: gcc target: static + host_os: ubuntu-22.04 - compiler: clang target: shared + host_os: ubuntu-24.04 - runs-on: ubuntu-22.04 + runs-on: ${{ matrix.host_os }} steps: - uses: actions/checkout@v4 @@ -89,7 +93,7 @@ jobs: uses: ./.github/actions/setup-build-agent with: target: ${{ matrix.target }} - cache-key: linux-${{ matrix.compiler }}-x86_64-${{ matrix.target }} + cache-key: linux-${{ matrix.compiler }}-x86_64-${{ matrix.target }}-{{ matrix.host_os }} - name: Build and Test Botan run: python3 ./src/scripts/ci_build.py --cc='${{ matrix.compiler }}' --test-results-dir=junit_results ${{ matrix.target }} diff --git a/doc/support.rst b/doc/support.rst index 6b248c85f4e..fd2f74ad71a 100644 --- a/doc/support.rst +++ b/doc/support.rst @@ -9,7 +9,7 @@ Supported Platforms For Botan 3, the tier-1 supported platforms are * Linux x86-64, GCC 11.2 or later -* Linux x86-64, Clang 14 or later +* Linux x86-64, Clang 17 or later * Linux aarch64, GCC 11.2 or later * Linux ppc64le, GCC 11.2 or later * Windows x86-64, Visual C++ 2022 or later @@ -26,7 +26,7 @@ For Botan 3, the tier-2 supported platforms are * Android aarch64, latest NDK Clang * Linux arm32, GCC 11.2 or later * Linux x86-32, GCC 11.2 or later -* FreeBSD x86-64, Clang 14 or later +* FreeBSD x86-64, Clang 17 or later .. note:: diff --git a/src/build-data/cc/clang.txt b/src/build-data/cc/clang.txt index ee2762b48d0..e7cb23f74c5 100644 --- a/src/build-data/cc/clang.txt +++ b/src/build-data/cc/clang.txt @@ -2,7 +2,7 @@ macro_name CLANG binary_name clang++ -minimum_supported_version 14.0 +minimum_supported_version 17.0 lang_flags "-std=c++20 -D_REENTRANT" diff --git a/src/lib/ffi/ffi_block.cpp b/src/lib/ffi/ffi_block.cpp index b4f7544e613..19b96c92abc 100644 --- a/src/lib/ffi/ffi_block.cpp +++ b/src/lib/ffi/ffi_block.cpp @@ -41,7 +41,7 @@ int botan_block_cipher_destroy(botan_block_cipher_t bc) { } int botan_block_cipher_clear(botan_block_cipher_t bc) { - return BOTAN_FFI_VISIT(bc, [](auto& b) { b.clear(); }); + return botan_ffi_visit(bc, [](auto& b) { b.clear(); }); } /** @@ -51,7 +51,7 @@ int botan_block_cipher_set_key(botan_block_cipher_t bc, const uint8_t key[], siz if(key == nullptr) { return BOTAN_FFI_ERROR_NULL_POINTER; } - return BOTAN_FFI_VISIT(bc, [=](auto& b) { b.set_key(key, len); }); + return botan_ffi_visit(bc, [=](auto& b) { b.set_key(key, len); }); } /** @@ -59,21 +59,21 @@ int botan_block_cipher_set_key(botan_block_cipher_t bc, const uint8_t key[], siz * indicate an error */ int botan_block_cipher_block_size(botan_block_cipher_t bc) { - return BOTAN_FFI_VISIT(bc, [](const auto& b) { return static_cast(b.block_size()); }); + return botan_ffi_visit(bc, [](const auto& b) { return static_cast(b.block_size()); }); } int botan_block_cipher_encrypt_blocks(botan_block_cipher_t bc, const uint8_t in[], uint8_t out[], size_t blocks) { if(in == nullptr || out == nullptr) { return BOTAN_FFI_ERROR_NULL_POINTER; } - return BOTAN_FFI_VISIT(bc, [=](const auto& b) { b.encrypt_n(in, out, blocks); }); + return botan_ffi_visit(bc, [=](const auto& b) { b.encrypt_n(in, out, blocks); }); } int botan_block_cipher_decrypt_blocks(botan_block_cipher_t bc, const uint8_t in[], uint8_t out[], size_t blocks) { if(in == nullptr || out == nullptr) { return BOTAN_FFI_ERROR_NULL_POINTER; } - return BOTAN_FFI_VISIT(bc, [=](const auto& b) { b.decrypt_n(in, out, blocks); }); + return botan_ffi_visit(bc, [=](const auto& b) { b.decrypt_n(in, out, blocks); }); } int botan_block_cipher_name(botan_block_cipher_t cipher, char* name, size_t* name_len) { @@ -81,14 +81,14 @@ int botan_block_cipher_name(botan_block_cipher_t cipher, char* name, size_t* nam return BOTAN_FFI_ERROR_NULL_POINTER; } - return BOTAN_FFI_VISIT(cipher, [=](const auto& bc) { return write_str_output(name, name_len, bc.name()); }); + return botan_ffi_visit(cipher, [=](const auto& bc) { return write_str_output(name, name_len, bc.name()); }); } int botan_block_cipher_get_keyspec(botan_block_cipher_t cipher, size_t* out_minimum_keylength, size_t* out_maximum_keylength, size_t* out_keylength_modulo) { - return BOTAN_FFI_VISIT(cipher, [=](const auto& bc) { + return botan_ffi_visit(cipher, [=](const auto& bc) { if(out_minimum_keylength) { *out_minimum_keylength = bc.minimum_keylength(); } diff --git a/src/lib/ffi/ffi_cert.cpp b/src/lib/ffi/ffi_cert.cpp index 504d6990a05..9d144529761 100644 --- a/src/lib/ffi/ffi_cert.cpp +++ b/src/lib/ffi/ffi_cert.cpp @@ -104,7 +104,7 @@ int botan_x509_cert_get_public_key(botan_x509_cert_t cert, botan_pubkey_t* key) int botan_x509_cert_get_issuer_dn( botan_x509_cert_t cert, const char* key, size_t index, uint8_t out[], size_t* out_len) { #if defined(BOTAN_HAS_X509_CERTIFICATES) - return BOTAN_FFI_VISIT(cert, + return botan_ffi_visit(cert, [=](const auto& c) { return write_str_output(out, out_len, c.issuer_info(key).at(index)); }); #else BOTAN_UNUSED(cert, key, index, out, out_len); @@ -115,7 +115,7 @@ int botan_x509_cert_get_issuer_dn( int botan_x509_cert_get_subject_dn( botan_x509_cert_t cert, const char* key, size_t index, uint8_t out[], size_t* out_len) { #if defined(BOTAN_HAS_X509_CERTIFICATES) - return BOTAN_FFI_VISIT(cert, + return botan_ffi_visit(cert, [=](const auto& c) { return write_str_output(out, out_len, c.subject_info(key).at(index)); }); #else BOTAN_UNUSED(cert, key, index, out, out_len); @@ -129,7 +129,7 @@ int botan_x509_cert_to_string(botan_x509_cert_t cert, char out[], size_t* out_le int botan_x509_cert_view_as_string(botan_x509_cert_t cert, botan_view_ctx ctx, botan_view_str_fn view) { #if defined(BOTAN_HAS_X509_CERTIFICATES) - return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return invoke_view_callback(view, ctx, c.to_string()); }); + return botan_ffi_visit(cert, [=](const auto& c) { return invoke_view_callback(view, ctx, c.to_string()); }); #else BOTAN_UNUSED(cert, ctx, view); return BOTAN_FFI_ERROR_NOT_IMPLEMENTED; @@ -138,7 +138,7 @@ int botan_x509_cert_view_as_string(botan_x509_cert_t cert, botan_view_ctx ctx, b int botan_x509_cert_allowed_usage(botan_x509_cert_t cert, unsigned int key_usage) { #if defined(BOTAN_HAS_X509_CERTIFICATES) - return BOTAN_FFI_VISIT(cert, [=](const auto& c) -> int { + return botan_ffi_visit(cert, [=](const auto& c) -> int { const Botan::Key_Constraints k = static_cast(key_usage); if(c.allowed_usage(k)) { return BOTAN_FFI_SUCCESS; @@ -162,7 +162,7 @@ int botan_x509_cert_destroy(botan_x509_cert_t cert) { int botan_x509_cert_get_time_starts(botan_x509_cert_t cert, char out[], size_t* out_len) { #if defined(BOTAN_HAS_X509_CERTIFICATES) - return BOTAN_FFI_VISIT(cert, + return botan_ffi_visit(cert, [=](const auto& c) { return write_str_output(out, out_len, c.not_before().to_string()); }); #else BOTAN_UNUSED(cert, out, out_len); @@ -172,7 +172,7 @@ int botan_x509_cert_get_time_starts(botan_x509_cert_t cert, char out[], size_t* int botan_x509_cert_get_time_expires(botan_x509_cert_t cert, char out[], size_t* out_len) { #if defined(BOTAN_HAS_X509_CERTIFICATES) - return BOTAN_FFI_VISIT(cert, + return botan_ffi_visit(cert, [=](const auto& c) { return write_str_output(out, out_len, c.not_after().to_string()); }); #else BOTAN_UNUSED(cert, out, out_len); @@ -182,7 +182,7 @@ int botan_x509_cert_get_time_expires(botan_x509_cert_t cert, char out[], size_t* int botan_x509_cert_not_before(botan_x509_cert_t cert, uint64_t* time_since_epoch) { #if defined(BOTAN_HAS_X509_CERTIFICATES) - return BOTAN_FFI_VISIT(cert, [=](const auto& c) { *time_since_epoch = c.not_before().time_since_epoch(); }); + return botan_ffi_visit(cert, [=](const auto& c) { *time_since_epoch = c.not_before().time_since_epoch(); }); #else BOTAN_UNUSED(cert, time_since_epoch); return BOTAN_FFI_ERROR_NOT_IMPLEMENTED; @@ -191,7 +191,7 @@ int botan_x509_cert_not_before(botan_x509_cert_t cert, uint64_t* time_since_epoc int botan_x509_cert_not_after(botan_x509_cert_t cert, uint64_t* time_since_epoch) { #if defined(BOTAN_HAS_X509_CERTIFICATES) - return BOTAN_FFI_VISIT(cert, [=](const auto& c) { *time_since_epoch = c.not_after().time_since_epoch(); }); + return botan_ffi_visit(cert, [=](const auto& c) { *time_since_epoch = c.not_after().time_since_epoch(); }); #else BOTAN_UNUSED(cert, time_since_epoch); return BOTAN_FFI_ERROR_NOT_IMPLEMENTED; @@ -200,7 +200,7 @@ int botan_x509_cert_not_after(botan_x509_cert_t cert, uint64_t* time_since_epoch int botan_x509_cert_get_serial_number(botan_x509_cert_t cert, uint8_t out[], size_t* out_len) { #if defined(BOTAN_HAS_X509_CERTIFICATES) - return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return write_vec_output(out, out_len, c.serial_number()); }); + return botan_ffi_visit(cert, [=](const auto& c) { return write_vec_output(out, out_len, c.serial_number()); }); #else BOTAN_UNUSED(cert, out, out_len); return BOTAN_FFI_ERROR_NOT_IMPLEMENTED; @@ -209,7 +209,7 @@ int botan_x509_cert_get_serial_number(botan_x509_cert_t cert, uint8_t out[], siz int botan_x509_cert_get_fingerprint(botan_x509_cert_t cert, const char* hash, uint8_t out[], size_t* out_len) { #if defined(BOTAN_HAS_X509_CERTIFICATES) - return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return write_str_output(out, out_len, c.fingerprint(hash)); }); + return botan_ffi_visit(cert, [=](const auto& c) { return write_str_output(out, out_len, c.fingerprint(hash)); }); #else BOTAN_UNUSED(cert, hash, out, out_len); return BOTAN_FFI_ERROR_NOT_IMPLEMENTED; @@ -218,7 +218,7 @@ int botan_x509_cert_get_fingerprint(botan_x509_cert_t cert, const char* hash, ui int botan_x509_cert_get_authority_key_id(botan_x509_cert_t cert, uint8_t out[], size_t* out_len) { #if defined(BOTAN_HAS_X509_CERTIFICATES) - return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return write_vec_output(out, out_len, c.authority_key_id()); }); + return botan_ffi_visit(cert, [=](const auto& c) { return write_vec_output(out, out_len, c.authority_key_id()); }); #else BOTAN_UNUSED(cert, out, out_len); return BOTAN_FFI_ERROR_NOT_IMPLEMENTED; @@ -227,7 +227,7 @@ int botan_x509_cert_get_authority_key_id(botan_x509_cert_t cert, uint8_t out[], int botan_x509_cert_get_subject_key_id(botan_x509_cert_t cert, uint8_t out[], size_t* out_len) { #if defined(BOTAN_HAS_X509_CERTIFICATES) - return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return write_vec_output(out, out_len, c.subject_key_id()); }); + return botan_ffi_visit(cert, [=](const auto& c) { return write_vec_output(out, out_len, c.subject_key_id()); }); #else BOTAN_UNUSED(cert, out, out_len); return BOTAN_FFI_ERROR_NOT_IMPLEMENTED; @@ -240,7 +240,7 @@ int botan_x509_cert_get_public_key_bits(botan_x509_cert_t cert, uint8_t out[], s int botan_x509_cert_view_public_key_bits(botan_x509_cert_t cert, botan_view_ctx ctx, botan_view_bin_fn view) { #if defined(BOTAN_HAS_X509_CERTIFICATES) - return BOTAN_FFI_VISIT(cert, + return botan_ffi_visit(cert, [=](const auto& c) { return invoke_view_callback(view, ctx, c.subject_public_key_bits()); }); #else BOTAN_UNUSED(cert, ctx, view); @@ -254,7 +254,7 @@ int botan_x509_cert_hostname_match(botan_x509_cert_t cert, const char* hostname) } #if defined(BOTAN_HAS_X509_CERTIFICATES) - return BOTAN_FFI_VISIT(cert, [=](const auto& c) { return c.matches_dns_name(hostname) ? 0 : -1; }); + return botan_ffi_visit(cert, [=](const auto& c) { return c.matches_dns_name(hostname) ? 0 : -1; }); #else BOTAN_UNUSED(cert); return BOTAN_FFI_ERROR_NOT_IMPLEMENTED; @@ -394,7 +394,7 @@ int botan_x509_crl_destroy(botan_x509_crl_t crl) { int botan_x509_is_revoked(botan_x509_crl_t crl, botan_x509_cert_t cert) { #if defined(BOTAN_HAS_X509_CERTIFICATES) - return BOTAN_FFI_VISIT(crl, [=](const auto& c) { return c.is_revoked(safe_get(cert)) ? 0 : -1; }); + return botan_ffi_visit(crl, [=](const auto& c) { return c.is_revoked(safe_get(cert)) ? 0 : -1; }); #else BOTAN_UNUSED(cert); BOTAN_UNUSED(crl); diff --git a/src/lib/ffi/ffi_cipher.cpp b/src/lib/ffi/ffi_cipher.cpp index fc75b43dfde..6fe12341f34 100644 --- a/src/lib/ffi/ffi_cipher.cpp +++ b/src/lib/ffi/ffi_cipher.cpp @@ -116,11 +116,11 @@ int botan_cipher_destroy(botan_cipher_t cipher) { } int botan_cipher_clear(botan_cipher_t cipher) { - return BOTAN_FFI_VISIT(cipher, [](auto& c) { c.clear(); }); + return botan_ffi_visit(cipher, [](auto& c) { c.clear(); }); } int botan_cipher_reset(botan_cipher_t cipher) { - return BOTAN_FFI_VISIT(cipher, [](auto& c) { c.reset(); }); + return botan_ffi_visit(cipher, [](auto& c) { c.reset(); }); } int botan_cipher_output_length(botan_cipher_t cipher, size_t in_len, size_t* out_len) { @@ -128,11 +128,11 @@ int botan_cipher_output_length(botan_cipher_t cipher, size_t in_len, size_t* out return BOTAN_FFI_ERROR_NULL_POINTER; } - return BOTAN_FFI_VISIT(cipher, [=](const auto& c) { *out_len = c.output_length(in_len); }); + return botan_ffi_visit(cipher, [=](const auto& c) { *out_len = c.output_length(in_len); }); } int botan_cipher_query_keylen(botan_cipher_t cipher, size_t* out_minimum_keylength, size_t* out_maximum_keylength) { - return BOTAN_FFI_VISIT(cipher, [=](const auto& c) { + return botan_ffi_visit(cipher, [=](const auto& c) { *out_minimum_keylength = c.key_spec().minimum_keylength(); *out_maximum_keylength = c.key_spec().maximum_keylength(); }); @@ -142,7 +142,7 @@ int botan_cipher_get_keyspec(botan_cipher_t cipher, size_t* out_minimum_keylength, size_t* out_maximum_keylength, size_t* out_keylength_modulo) { - return BOTAN_FFI_VISIT(cipher, [=](const auto& c) { + return botan_ffi_visit(cipher, [=](const auto& c) { if(out_minimum_keylength) { *out_minimum_keylength = c.key_spec().minimum_keylength(); } @@ -156,7 +156,7 @@ int botan_cipher_get_keyspec(botan_cipher_t cipher, } int botan_cipher_set_key(botan_cipher_t cipher, const uint8_t* key, size_t key_len) { - return BOTAN_FFI_VISIT(cipher, [=](auto& c) { c.set_key(key, key_len); }); + return botan_ffi_visit(cipher, [=](auto& c) { c.set_key(key, key_len); }); } int botan_cipher_start(botan_cipher_t cipher_obj, const uint8_t* nonce, size_t nonce_len) { @@ -286,7 +286,7 @@ int botan_cipher_update(botan_cipher_t cipher_obj, } int botan_cipher_set_associated_data(botan_cipher_t cipher, const uint8_t* ad, size_t ad_len) { - return BOTAN_FFI_VISIT(cipher, [=](auto& c) { + return botan_ffi_visit(cipher, [=](auto& c) { if(Botan::AEAD_Mode* aead = dynamic_cast(&c)) { aead->set_associated_data(ad, ad_len); return BOTAN_FFI_SUCCESS; @@ -296,34 +296,34 @@ int botan_cipher_set_associated_data(botan_cipher_t cipher, const uint8_t* ad, s } int botan_cipher_valid_nonce_length(botan_cipher_t cipher, size_t nl) { - return BOTAN_FFI_VISIT(cipher, [=](const auto& c) { return c.valid_nonce_length(nl) ? 1 : 0; }); + return botan_ffi_visit(cipher, [=](const auto& c) { return c.valid_nonce_length(nl) ? 1 : 0; }); } int botan_cipher_get_default_nonce_length(botan_cipher_t cipher, size_t* nl) { - return BOTAN_FFI_VISIT(cipher, [=](const auto& c) { *nl = c.default_nonce_length(); }); + return botan_ffi_visit(cipher, [=](const auto& c) { *nl = c.default_nonce_length(); }); } int botan_cipher_get_update_granularity(botan_cipher_t cipher, size_t* ug) { - return BOTAN_FFI_VISIT(cipher, [=](const auto& /*c*/) { *ug = cipher->update_size(); }); + return botan_ffi_visit(cipher, [=](const auto& /*c*/) { *ug = cipher->update_size(); }); } int botan_cipher_get_ideal_update_granularity(botan_cipher_t cipher, size_t* ug) { - return BOTAN_FFI_VISIT(cipher, [=](const auto& c) { *ug = c.ideal_granularity(); }); + return botan_ffi_visit(cipher, [=](const auto& c) { *ug = c.ideal_granularity(); }); } int botan_cipher_get_tag_length(botan_cipher_t cipher, size_t* tl) { - return BOTAN_FFI_VISIT(cipher, [=](const auto& c) { *tl = c.tag_size(); }); + return botan_ffi_visit(cipher, [=](const auto& c) { *tl = c.tag_size(); }); } int botan_cipher_is_authenticated(botan_cipher_t cipher) { - return BOTAN_FFI_VISIT(cipher, [=](const auto& c) { return c.authenticated() ? 1 : 0; }); + return botan_ffi_visit(cipher, [=](const auto& c) { return c.authenticated() ? 1 : 0; }); } int botan_cipher_requires_entire_message(botan_cipher_t cipher) { - return BOTAN_FFI_VISIT(cipher, [=](const auto& c) { return c.requires_entire_message() ? 1 : 0; }); + return botan_ffi_visit(cipher, [=](const auto& c) { return c.requires_entire_message() ? 1 : 0; }); } int botan_cipher_name(botan_cipher_t cipher, char* name, size_t* name_len) { - return BOTAN_FFI_VISIT(cipher, [=](const auto& c) { return write_str_output(name, name_len, c.name()); }); + return botan_ffi_visit(cipher, [=](const auto& c) { return write_str_output(name, name_len, c.name()); }); } } diff --git a/src/lib/ffi/ffi_hash.cpp b/src/lib/ffi/ffi_hash.cpp index 49da8ca196b..02f88e648ea 100644 --- a/src/lib/ffi/ffi_hash.cpp +++ b/src/lib/ffi/ffi_hash.cpp @@ -42,18 +42,18 @@ int botan_hash_output_length(botan_hash_t hash, size_t* out) { if(out == nullptr) { return BOTAN_FFI_ERROR_NULL_POINTER; } - return BOTAN_FFI_VISIT(hash, [=](const auto& h) { *out = h.output_length(); }); + return botan_ffi_visit(hash, [=](const auto& h) { *out = h.output_length(); }); } int botan_hash_block_size(botan_hash_t hash, size_t* out) { if(out == nullptr) { return BOTAN_FFI_ERROR_NULL_POINTER; } - return BOTAN_FFI_VISIT(hash, [=](const auto& h) { *out = h.hash_block_size(); }); + return botan_ffi_visit(hash, [=](const auto& h) { *out = h.hash_block_size(); }); } int botan_hash_clear(botan_hash_t hash) { - return BOTAN_FFI_VISIT(hash, [](auto& h) { h.clear(); }); + return botan_ffi_visit(hash, [](auto& h) { h.clear(); }); } int botan_hash_update(botan_hash_t hash, const uint8_t* buf, size_t len) { @@ -65,18 +65,18 @@ int botan_hash_update(botan_hash_t hash, const uint8_t* buf, size_t len) { return BOTAN_FFI_ERROR_NULL_POINTER; } - return BOTAN_FFI_VISIT(hash, [=](auto& h) { h.update(buf, len); }); + return botan_ffi_visit(hash, [=](auto& h) { h.update(buf, len); }); } int botan_hash_final(botan_hash_t hash, uint8_t out[]) { if(out == nullptr) { return BOTAN_FFI_ERROR_NULL_POINTER; } - return BOTAN_FFI_VISIT(hash, [=](auto& h) { h.final(out); }); + return botan_ffi_visit(hash, [=](auto& h) { h.final(out); }); } int botan_hash_copy_state(botan_hash_t* dest, const botan_hash_t source) { - return BOTAN_FFI_VISIT(source, [=](const auto& src) { *dest = new botan_hash_struct(src.copy_state()); }); + return botan_ffi_visit(source, [=](const auto& src) { *dest = new botan_hash_struct(src.copy_state()); }); } int botan_hash_name(botan_hash_t hash, char* name, size_t* name_len) { @@ -84,6 +84,6 @@ int botan_hash_name(botan_hash_t hash, char* name, size_t* name_len) { return BOTAN_FFI_ERROR_NULL_POINTER; } - return BOTAN_FFI_VISIT(hash, [=](const auto& h) { return write_str_output(name, name_len, h.name()); }); + return botan_ffi_visit(hash, [=](const auto& h) { return write_str_output(name, name_len, h.name()); }); } } diff --git a/src/lib/ffi/ffi_hotp.cpp b/src/lib/ffi/ffi_hotp.cpp index e829a1b0381..ab9e2d8198d 100644 --- a/src/lib/ffi/ffi_hotp.cpp +++ b/src/lib/ffi/ffi_hotp.cpp @@ -57,7 +57,7 @@ int botan_hotp_generate(botan_hotp_t hotp, uint32_t* hotp_code, uint64_t hotp_co return BOTAN_FFI_ERROR_NULL_POINTER; } - return BOTAN_FFI_VISIT(hotp, [=](auto& h) { *hotp_code = h.generate_hotp(hotp_counter); }); + return botan_ffi_visit(hotp, [=](auto& h) { *hotp_code = h.generate_hotp(hotp_counter); }); #else BOTAN_UNUSED(hotp, hotp_code, hotp_counter); @@ -68,7 +68,7 @@ int botan_hotp_generate(botan_hotp_t hotp, uint32_t* hotp_code, uint64_t hotp_co int botan_hotp_check( botan_hotp_t hotp, uint64_t* next_hotp_counter, uint32_t hotp_code, uint64_t hotp_counter, size_t resync_range) { #if defined(BOTAN_HAS_HOTP) - return BOTAN_FFI_VISIT(hotp, [=](auto& h) { + return botan_ffi_visit(hotp, [=](auto& h) { auto resp = h.verify_hotp(hotp_code, hotp_counter, resync_range); if(next_hotp_counter) { diff --git a/src/lib/ffi/ffi_mac.cpp b/src/lib/ffi/ffi_mac.cpp index fd6724fd655..9cf4b697554 100644 --- a/src/lib/ffi/ffi_mac.cpp +++ b/src/lib/ffi/ffi_mac.cpp @@ -37,38 +37,38 @@ int botan_mac_destroy(botan_mac_t mac) { } int botan_mac_set_key(botan_mac_t mac, const uint8_t* key, size_t key_len) { - return BOTAN_FFI_VISIT(mac, [=](auto& m) { m.set_key(key, key_len); }); + return botan_ffi_visit(mac, [=](auto& m) { m.set_key(key, key_len); }); } int botan_mac_set_nonce(botan_mac_t mac, const uint8_t* nonce, size_t nonce_len) { - return BOTAN_FFI_VISIT(mac, [=](auto& m) { m.start(nonce, nonce_len); }); + return botan_ffi_visit(mac, [=](auto& m) { m.start(nonce, nonce_len); }); } int botan_mac_output_length(botan_mac_t mac, size_t* out) { - return BOTAN_FFI_VISIT(mac, [=](const auto& m) { *out = m.output_length(); }); + return botan_ffi_visit(mac, [=](const auto& m) { *out = m.output_length(); }); } int botan_mac_clear(botan_mac_t mac) { - return BOTAN_FFI_VISIT(mac, [](auto& m) { m.clear(); }); + return botan_ffi_visit(mac, [](auto& m) { m.clear(); }); } int botan_mac_update(botan_mac_t mac, const uint8_t* buf, size_t len) { - return BOTAN_FFI_VISIT(mac, [=](auto& m) { m.update(buf, len); }); + return botan_ffi_visit(mac, [=](auto& m) { m.update(buf, len); }); } int botan_mac_final(botan_mac_t mac, uint8_t out[]) { - return BOTAN_FFI_VISIT(mac, [=](auto& m) { m.final(out); }); + return botan_ffi_visit(mac, [=](auto& m) { m.final(out); }); } int botan_mac_name(botan_mac_t mac, char* name, size_t* name_len) { - return BOTAN_FFI_VISIT(mac, [=](const auto& m) { return write_str_output(name, name_len, m.name()); }); + return botan_ffi_visit(mac, [=](const auto& m) { return write_str_output(name, name_len, m.name()); }); } int botan_mac_get_keyspec(botan_mac_t mac, size_t* out_minimum_keylength, size_t* out_maximum_keylength, size_t* out_keylength_modulo) { - return BOTAN_FFI_VISIT(mac, [=](auto& m) { + return botan_ffi_visit(mac, [=](auto& m) { if(out_minimum_keylength) { *out_minimum_keylength = m.minimum_keylength(); } diff --git a/src/lib/ffi/ffi_mp.cpp b/src/lib/ffi/ffi_mp.cpp index 5ca0acc948d..4f03bf65e32 100644 --- a/src/lib/ffi/ffi_mp.cpp +++ b/src/lib/ffi/ffi_mp.cpp @@ -31,19 +31,19 @@ int botan_mp_init(botan_mp_t* mp_out) { } int botan_mp_clear(botan_mp_t mp) { - return BOTAN_FFI_VISIT(mp, [](auto& bn) { bn.clear(); }); + return botan_ffi_visit(mp, [](auto& bn) { bn.clear(); }); } int botan_mp_set_from_int(botan_mp_t mp, int initial_value) { - return BOTAN_FFI_VISIT(mp, [=](auto& bn) { bn = Botan::BigInt::from_s32(initial_value); }); + return botan_ffi_visit(mp, [=](auto& bn) { bn = Botan::BigInt::from_s32(initial_value); }); } int botan_mp_set_from_str(botan_mp_t mp, const char* str) { - return BOTAN_FFI_VISIT(mp, [=](auto& bn) { bn = Botan::BigInt(str); }); + return botan_ffi_visit(mp, [=](auto& bn) { bn = Botan::BigInt(str); }); } int botan_mp_set_from_radix_str(botan_mp_t mp, const char* str, size_t radix) { - return BOTAN_FFI_VISIT(mp, [=](auto& bn) { + return botan_ffi_visit(mp, [=](auto& bn) { Botan::BigInt::Base base; if(radix == 10) { base = Botan::BigInt::Decimal; @@ -62,34 +62,34 @@ int botan_mp_set_from_radix_str(botan_mp_t mp, const char* str, size_t radix) { } int botan_mp_set_from_mp(botan_mp_t dest, const botan_mp_t source) { - return BOTAN_FFI_VISIT(dest, [=](auto& bn) { bn = safe_get(source); }); + return botan_ffi_visit(dest, [=](auto& bn) { bn = safe_get(source); }); } int botan_mp_is_negative(const botan_mp_t mp) { - return BOTAN_FFI_VISIT(mp, [](const auto& bn) { return bn.is_negative() ? 1 : 0; }); + return botan_ffi_visit(mp, [](const auto& bn) { return bn.is_negative() ? 1 : 0; }); } int botan_mp_is_positive(const botan_mp_t mp) { - return BOTAN_FFI_VISIT(mp, [](const auto& bn) { return bn.is_positive() ? 1 : 0; }); + return botan_ffi_visit(mp, [](const auto& bn) { return bn.is_positive() ? 1 : 0; }); } int botan_mp_flip_sign(botan_mp_t mp) { - return BOTAN_FFI_VISIT(mp, [](auto& bn) { bn.flip_sign(); }); + return botan_ffi_visit(mp, [](auto& bn) { bn.flip_sign(); }); } int botan_mp_from_bin(botan_mp_t mp, const uint8_t bin[], size_t bin_len) { - return BOTAN_FFI_VISIT(mp, [=](auto& bn) { bn._assign_from_bytes({bin, bin_len}); }); + return botan_ffi_visit(mp, [=](auto& bn) { bn._assign_from_bytes({bin, bin_len}); }); } int botan_mp_to_hex(const botan_mp_t mp, char* out) { - return BOTAN_FFI_VISIT(mp, [=](const auto& bn) { + return botan_ffi_visit(mp, [=](const auto& bn) { const std::string hex = bn.to_hex_string(); std::memcpy(out, hex.c_str(), 1 + hex.size()); }); } int botan_mp_to_str(const botan_mp_t mp, uint8_t digit_base, char* out, size_t* out_len) { - return BOTAN_FFI_VISIT(mp, [=](const auto& bn) -> int { + return botan_ffi_visit(mp, [=](const auto& bn) -> int { if(digit_base == 0 || digit_base == 10) { return write_str_output(out, out_len, bn.to_dec_string()); } else if(digit_base == 16) { @@ -101,14 +101,14 @@ int botan_mp_to_str(const botan_mp_t mp, uint8_t digit_base, char* out, size_t* } int botan_mp_to_bin(const botan_mp_t mp, uint8_t vec[]) { - return BOTAN_FFI_VISIT(mp, [=](const auto& bn) { bn.serialize_to(std::span{vec, bn.bytes()}); }); + return botan_ffi_visit(mp, [=](const auto& bn) { bn.serialize_to(std::span{vec, bn.bytes()}); }); } int botan_mp_to_uint32(const botan_mp_t mp, uint32_t* val) { if(val == nullptr) { return BOTAN_FFI_ERROR_NULL_POINTER; } - return BOTAN_FFI_VISIT(mp, [=](const auto& bn) { *val = bn.to_u32bit(); }); + return botan_ffi_visit(mp, [=](const auto& bn) { *val = bn.to_u32bit(); }); } int botan_mp_destroy(botan_mp_t mp) { @@ -116,7 +116,7 @@ int botan_mp_destroy(botan_mp_t mp) { } int botan_mp_add(botan_mp_t result, const botan_mp_t x, const botan_mp_t y) { - return BOTAN_FFI_VISIT(result, [=](auto& res) { + return botan_ffi_visit(result, [=](auto& res) { if(result == x) { res += safe_get(y); } else { @@ -126,7 +126,7 @@ int botan_mp_add(botan_mp_t result, const botan_mp_t x, const botan_mp_t y) { } int botan_mp_sub(botan_mp_t result, const botan_mp_t x, const botan_mp_t y) { - return BOTAN_FFI_VISIT(result, [=](auto& res) { + return botan_ffi_visit(result, [=](auto& res) { if(result == x) { res -= safe_get(y); } else { @@ -136,7 +136,7 @@ int botan_mp_sub(botan_mp_t result, const botan_mp_t x, const botan_mp_t y) { } int botan_mp_add_u32(botan_mp_t result, const botan_mp_t x, uint32_t y) { - return BOTAN_FFI_VISIT(result, [=](auto& res) { + return botan_ffi_visit(result, [=](auto& res) { if(result == x) { res += static_cast(y); } else { @@ -146,7 +146,7 @@ int botan_mp_add_u32(botan_mp_t result, const botan_mp_t x, uint32_t y) { } int botan_mp_sub_u32(botan_mp_t result, const botan_mp_t x, uint32_t y) { - return BOTAN_FFI_VISIT(result, [=](auto& res) { + return botan_ffi_visit(result, [=](auto& res) { if(result == x) { res -= static_cast(y); } else { @@ -156,7 +156,7 @@ int botan_mp_sub_u32(botan_mp_t result, const botan_mp_t x, uint32_t y) { } int botan_mp_mul(botan_mp_t result, const botan_mp_t x, const botan_mp_t y) { - return BOTAN_FFI_VISIT(result, [=](auto& res) { + return botan_ffi_visit(result, [=](auto& res) { if(result == x) { res *= safe_get(y); } else { @@ -166,7 +166,7 @@ int botan_mp_mul(botan_mp_t result, const botan_mp_t x, const botan_mp_t y) { } int botan_mp_div(botan_mp_t quotient, botan_mp_t remainder, const botan_mp_t x, const botan_mp_t y) { - return BOTAN_FFI_VISIT(quotient, [=](auto& q) { + return botan_ffi_visit(quotient, [=](auto& q) { Botan::BigInt r; Botan::vartime_divide(safe_get(x), safe_get(y), q, r); safe_get(remainder) = r; @@ -174,88 +174,88 @@ int botan_mp_div(botan_mp_t quotient, botan_mp_t remainder, const botan_mp_t x, } int botan_mp_equal(const botan_mp_t x_w, const botan_mp_t y_w) { - return BOTAN_FFI_VISIT(x_w, [=](const auto& x) -> int { return x == safe_get(y_w); }); + return botan_ffi_visit(x_w, [=](const auto& x) -> int { return x == safe_get(y_w); }); } int botan_mp_is_zero(const botan_mp_t mp) { - return BOTAN_FFI_VISIT(mp, [](const auto& bn) -> int { return bn.is_zero(); }); + return botan_ffi_visit(mp, [](const auto& bn) -> int { return bn.is_zero(); }); } int botan_mp_is_odd(const botan_mp_t mp) { - return BOTAN_FFI_VISIT(mp, [](const auto& bn) -> int { return bn.is_odd(); }); + return botan_ffi_visit(mp, [](const auto& bn) -> int { return bn.is_odd(); }); } int botan_mp_is_even(const botan_mp_t mp) { - return BOTAN_FFI_VISIT(mp, [](const auto& bn) -> int { return bn.is_even(); }); + return botan_ffi_visit(mp, [](const auto& bn) -> int { return bn.is_even(); }); } int botan_mp_cmp(int* result, const botan_mp_t x_w, const botan_mp_t y_w) { - return BOTAN_FFI_VISIT(x_w, [=](auto& x) { *result = x.cmp(safe_get(y_w)); }); + return botan_ffi_visit(x_w, [=](auto& x) { *result = x.cmp(safe_get(y_w)); }); } int botan_mp_swap(botan_mp_t x_w, botan_mp_t y_w) { - return BOTAN_FFI_VISIT(x_w, [=](auto& x) { x.swap(safe_get(y_w)); }); + return botan_ffi_visit(x_w, [=](auto& x) { x.swap(safe_get(y_w)); }); } // Return (base^exponent) % modulus int botan_mp_powmod(botan_mp_t out, const botan_mp_t base, const botan_mp_t exponent, const botan_mp_t modulus) { - return BOTAN_FFI_VISIT( + return botan_ffi_visit( out, [=](auto& o) { o = Botan::power_mod(safe_get(base), safe_get(exponent), safe_get(modulus)); }); } int botan_mp_lshift(botan_mp_t out, const botan_mp_t in, size_t shift) { - return BOTAN_FFI_VISIT(out, [=](auto& o) { o = safe_get(in) << shift; }); + return botan_ffi_visit(out, [=](auto& o) { o = safe_get(in) << shift; }); } int botan_mp_rshift(botan_mp_t out, const botan_mp_t in, size_t shift) { - return BOTAN_FFI_VISIT(out, [=](auto& o) { o = safe_get(in) >> shift; }); + return botan_ffi_visit(out, [=](auto& o) { o = safe_get(in) >> shift; }); } int botan_mp_mod_inverse(botan_mp_t out, const botan_mp_t in, const botan_mp_t modulus) { - return BOTAN_FFI_VISIT(out, [=](auto& o) { o = Botan::inverse_mod(safe_get(in), safe_get(modulus)); }); + return botan_ffi_visit(out, [=](auto& o) { o = Botan::inverse_mod(safe_get(in), safe_get(modulus)); }); } int botan_mp_mod_mul(botan_mp_t out, const botan_mp_t x, const botan_mp_t y, const botan_mp_t modulus) { - return BOTAN_FFI_VISIT(out, [=](auto& o) { + return botan_ffi_visit(out, [=](auto& o) { Botan::Modular_Reducer reducer(safe_get(modulus)); o = reducer.multiply(safe_get(x), safe_get(y)); }); } int botan_mp_rand_bits(botan_mp_t rand_out, botan_rng_t rng, size_t bits) { - return BOTAN_FFI_VISIT(rng, [=](auto& r) { safe_get(rand_out).randomize(r, bits); }); + return botan_ffi_visit(rng, [=](auto& r) { safe_get(rand_out).randomize(r, bits); }); } int botan_mp_rand_range(botan_mp_t rand_out, botan_rng_t rng, const botan_mp_t lower, const botan_mp_t upper) { - return BOTAN_FFI_VISIT( + return botan_ffi_visit( rng, [=](auto& r) { safe_get(rand_out) = Botan::BigInt::random_integer(r, safe_get(lower), safe_get(upper)); }); } int botan_mp_gcd(botan_mp_t out, const botan_mp_t x, const botan_mp_t y) { - return BOTAN_FFI_VISIT(out, [=](auto& o) { o = Botan::gcd(safe_get(x), safe_get(y)); }); + return botan_ffi_visit(out, [=](auto& o) { o = Botan::gcd(safe_get(x), safe_get(y)); }); } int botan_mp_is_prime(const botan_mp_t mp, botan_rng_t rng, size_t test_prob) { - return BOTAN_FFI_VISIT(mp, [=](const auto& n) { return (Botan::is_prime(n, safe_get(rng), test_prob)) ? 1 : 0; }); + return botan_ffi_visit(mp, [=](const auto& n) { return (Botan::is_prime(n, safe_get(rng), test_prob)) ? 1 : 0; }); } int botan_mp_get_bit(const botan_mp_t mp, size_t bit) { - return BOTAN_FFI_VISIT(mp, [=](const auto& n) -> int { return n.get_bit(bit); }); + return botan_ffi_visit(mp, [=](const auto& n) -> int { return n.get_bit(bit); }); } int botan_mp_set_bit(botan_mp_t mp, size_t bit) { - return BOTAN_FFI_VISIT(mp, [=](auto& n) { n.set_bit(bit); }); + return botan_ffi_visit(mp, [=](auto& n) { n.set_bit(bit); }); } int botan_mp_clear_bit(botan_mp_t mp, size_t bit) { - return BOTAN_FFI_VISIT(mp, [=](auto& n) { n.clear_bit(bit); }); + return botan_ffi_visit(mp, [=](auto& n) { n.clear_bit(bit); }); } int botan_mp_num_bits(const botan_mp_t mp, size_t* bits) { - return BOTAN_FFI_VISIT(mp, [=](const auto& n) { *bits = n.bits(); }); + return botan_ffi_visit(mp, [=](const auto& n) { *bits = n.bits(); }); } int botan_mp_num_bytes(const botan_mp_t mp, size_t* bytes) { - return BOTAN_FFI_VISIT(mp, [=](const auto& n) { *bytes = n.bytes(); }); + return botan_ffi_visit(mp, [=](const auto& n) { *bytes = n.bytes(); }); } } diff --git a/src/lib/ffi/ffi_pk_op.cpp b/src/lib/ffi/ffi_pk_op.cpp index cc6f57d8cd4..4a1ca89880e 100644 --- a/src/lib/ffi/ffi_pk_op.cpp +++ b/src/lib/ffi/ffi_pk_op.cpp @@ -51,7 +51,7 @@ int botan_pk_op_encrypt_output_length(botan_pk_op_encrypt_t op, size_t ptext_len if(ctext_len == nullptr) { return BOTAN_FFI_ERROR_NULL_POINTER; } - return BOTAN_FFI_VISIT(op, [=](const auto& o) { *ctext_len = o.ciphertext_length(ptext_len); }); + return botan_ffi_visit(op, [=](const auto& o) { *ctext_len = o.ciphertext_length(ptext_len); }); } int botan_pk_op_encrypt(botan_pk_op_encrypt_t op, @@ -60,7 +60,7 @@ int botan_pk_op_encrypt(botan_pk_op_encrypt_t op, size_t* out_len, const uint8_t plaintext[], size_t plaintext_len) { - return BOTAN_FFI_VISIT(op, [=](const auto& o) { + return botan_ffi_visit(op, [=](const auto& o) { return write_vec_output(out, out_len, o.encrypt(plaintext, plaintext_len, safe_get(rng_obj))); }); } @@ -97,12 +97,12 @@ int botan_pk_op_decrypt_output_length(botan_pk_op_decrypt_t op, size_t ctext_len if(ptext_len == nullptr) { return BOTAN_FFI_ERROR_NULL_POINTER; } - return BOTAN_FFI_VISIT(op, [=](const auto& o) { *ptext_len = o.plaintext_length(ctext_len); }); + return botan_ffi_visit(op, [=](const auto& o) { *ptext_len = o.plaintext_length(ctext_len); }); } int botan_pk_op_decrypt( botan_pk_op_decrypt_t op, uint8_t out[], size_t* out_len, const uint8_t ciphertext[], size_t ciphertext_len) { - return BOTAN_FFI_VISIT( + return botan_ffi_visit( op, [=](const auto& o) { return write_vec_output(out, out_len, o.decrypt(ciphertext, ciphertext_len)); }); } @@ -139,15 +139,15 @@ int botan_pk_op_sign_output_length(botan_pk_op_sign_t op, size_t* sig_len) { return BOTAN_FFI_ERROR_NULL_POINTER; } - return BOTAN_FFI_VISIT(op, [=](const auto& o) { *sig_len = o.signature_length(); }); + return botan_ffi_visit(op, [=](const auto& o) { *sig_len = o.signature_length(); }); } int botan_pk_op_sign_update(botan_pk_op_sign_t op, const uint8_t in[], size_t in_len) { - return BOTAN_FFI_VISIT(op, [=](auto& o) { o.update(in, in_len); }); + return botan_ffi_visit(op, [=](auto& o) { o.update(in, in_len); }); } int botan_pk_op_sign_finish(botan_pk_op_sign_t op, botan_rng_t rng_obj, uint8_t out[], size_t* out_len) { - return BOTAN_FFI_VISIT(op, [=](auto& o) { return write_vec_output(out, out_len, o.signature(safe_get(rng_obj))); }); + return botan_ffi_visit(op, [=](auto& o) { return write_vec_output(out, out_len, o.signature(safe_get(rng_obj))); }); } int botan_pk_op_verify_create(botan_pk_op_verify_t* op, botan_pubkey_t key_obj, const char* hash, uint32_t flags) { @@ -174,11 +174,11 @@ int botan_pk_op_verify_destroy(botan_pk_op_verify_t op) { } int botan_pk_op_verify_update(botan_pk_op_verify_t op, const uint8_t in[], size_t in_len) { - return BOTAN_FFI_VISIT(op, [=](auto& o) { o.update(in, in_len); }); + return botan_ffi_visit(op, [=](auto& o) { o.update(in, in_len); }); } int botan_pk_op_verify_finish(botan_pk_op_verify_t op, const uint8_t sig[], size_t sig_len) { - return BOTAN_FFI_VISIT(op, [=](auto& o) { + return botan_ffi_visit(op, [=](auto& o) { const bool legit = o.check_signature(sig, sig_len); if(legit) { @@ -215,7 +215,7 @@ int botan_pk_op_key_agreement_export_public(botan_privkey_t key, uint8_t out[], } int botan_pk_op_key_agreement_view_public(botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view) { - return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int { + return botan_ffi_visit(key, [=](const auto& k) -> int { if(auto kak = dynamic_cast(&k)) { return invoke_view_callback(view, ctx, kak->public_value()); } else { @@ -225,7 +225,7 @@ int botan_pk_op_key_agreement_view_public(botan_privkey_t key, botan_view_ctx ct } int botan_pk_op_key_agreement_size(botan_pk_op_ka_t op, size_t* out_len) { - return BOTAN_FFI_VISIT(op, [=](const auto& o) { + return botan_ffi_visit(op, [=](const auto& o) { if(out_len == nullptr) { return BOTAN_FFI_ERROR_NULL_POINTER; } @@ -241,7 +241,7 @@ int botan_pk_op_key_agreement(botan_pk_op_ka_t op, size_t other_key_len, const uint8_t salt[], size_t salt_len) { - return BOTAN_FFI_VISIT(op, [=](const auto& o) { + return botan_ffi_visit(op, [=](const auto& o) { auto k = o.derive_key(*out_len, other_key, other_key_len, salt, salt_len).bits_of(); return write_vec_output(out, out_len, k); }); @@ -270,7 +270,7 @@ int botan_pk_op_kem_encrypt_shared_key_length(botan_pk_op_kem_encrypt_t op, return BOTAN_FFI_ERROR_NULL_POINTER; } - return BOTAN_FFI_VISIT(op, [=](auto& kem) { + return botan_ffi_visit(op, [=](auto& kem) { *output_shared_key_length = kem.shared_key_length(desired_shared_key_length); return BOTAN_FFI_SUCCESS; }); @@ -282,7 +282,7 @@ int botan_pk_op_kem_encrypt_encapsulated_key_length(botan_pk_op_kem_encrypt_t op return BOTAN_FFI_ERROR_NULL_POINTER; } - return BOTAN_FFI_VISIT(op, [=](auto& kem) { + return botan_ffi_visit(op, [=](auto& kem) { *output_encapsulated_key_length = kem.encapsulated_key_length(); return BOTAN_FFI_SUCCESS; }); @@ -297,7 +297,7 @@ int botan_pk_op_kem_encrypt_create_shared_key(botan_pk_op_kem_encrypt_t op, size_t* shared_key_len, uint8_t encapsulated_key_out[], size_t* encapsulated_key_len) { - return BOTAN_FFI_VISIT(op, [=](auto& kem) { + return botan_ffi_visit(op, [=](auto& kem) { const auto result = kem.encrypt(safe_get(rng), desired_shared_key_len, {salt, salt_len}); int rc = write_vec_output(encapsulated_key_out, encapsulated_key_len, result.encapsulated_shared_key()); @@ -329,7 +329,7 @@ int botan_pk_op_kem_decrypt_shared_key_length(botan_pk_op_kem_decrypt_t op, return BOTAN_FFI_ERROR_NULL_POINTER; } - return BOTAN_FFI_VISIT(op, [=](auto& kem) { + return botan_ffi_visit(op, [=](auto& kem) { *output_shared_key_length = kem.shared_key_length(desired_shared_key_length); return BOTAN_FFI_SUCCESS; }); @@ -343,7 +343,7 @@ int botan_pk_op_kem_decrypt_shared_key(botan_pk_op_kem_decrypt_t op, size_t desired_shared_key_len, uint8_t shared_key_out[], size_t* shared_key_len) { - return BOTAN_FFI_VISIT(op, [=](auto& kem) { + return botan_ffi_visit(op, [=](auto& kem) { const auto shared_key = kem.decrypt(encapsulated_key, encapsulated_key_len, desired_shared_key_len, salt, salt_len); diff --git a/src/lib/ffi/ffi_pkey.cpp b/src/lib/ffi/ffi_pkey.cpp index 40339c6d9a0..04a2b0a8748 100644 --- a/src/lib/ffi/ffi_pkey.cpp +++ b/src/lib/ffi/ffi_pkey.cpp @@ -109,24 +109,24 @@ int botan_privkey_export_pubkey(botan_pubkey_t* pubout, botan_privkey_t key_obj) } int botan_privkey_algo_name(botan_privkey_t key, char out[], size_t* out_len) { - return BOTAN_FFI_VISIT(key, [=](const auto& k) { return write_str_output(out, out_len, k.algo_name()); }); + return botan_ffi_visit(key, [=](const auto& k) { return write_str_output(out, out_len, k.algo_name()); }); } int botan_pubkey_algo_name(botan_pubkey_t key, char out[], size_t* out_len) { - return BOTAN_FFI_VISIT(key, [=](const auto& k) { return write_str_output(out, out_len, k.algo_name()); }); + return botan_ffi_visit(key, [=](const auto& k) { return write_str_output(out, out_len, k.algo_name()); }); } int botan_pubkey_check_key(botan_pubkey_t key, botan_rng_t rng, uint32_t flags) { const bool strong = (flags & BOTAN_CHECK_KEY_EXPENSIVE_TESTS); - return BOTAN_FFI_VISIT(key, [=](const auto& k) { + return botan_ffi_visit(key, [=](const auto& k) { return (k.check_key(safe_get(rng), strong) == true) ? 0 : BOTAN_FFI_ERROR_INVALID_INPUT; }); } int botan_privkey_check_key(botan_privkey_t key, botan_rng_t rng, uint32_t flags) { const bool strong = (flags & BOTAN_CHECK_KEY_EXPENSIVE_TESTS); - return BOTAN_FFI_VISIT(key, [=](const auto& k) { + return botan_ffi_visit(key, [=](const auto& k) { return (k.check_key(safe_get(rng), strong) == true) ? 0 : BOTAN_FFI_ERROR_INVALID_INPUT; }); } @@ -144,17 +144,17 @@ int botan_pubkey_export(botan_pubkey_t key, uint8_t out[], size_t* out_len, uint } int botan_pubkey_view_der(botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view) { - return BOTAN_FFI_VISIT( + return botan_ffi_visit( key, [=](const auto& k) -> int { return invoke_view_callback(view, ctx, Botan::X509::BER_encode(k)); }); } int botan_pubkey_view_pem(botan_pubkey_t key, botan_view_ctx ctx, botan_view_str_fn view) { - return BOTAN_FFI_VISIT( + return botan_ffi_visit( key, [=](const auto& k) -> int { return invoke_view_callback(view, ctx, Botan::X509::PEM_encode(k)); }); } int botan_pubkey_view_raw(botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view) { - return BOTAN_FFI_VISIT( + return botan_ffi_visit( key, [=](const auto& k) -> int { return invoke_view_callback(view, ctx, k.raw_public_key_bits()); }); } @@ -171,17 +171,17 @@ int botan_privkey_export(botan_privkey_t key, uint8_t out[], size_t* out_len, ui } int botan_privkey_view_der(botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view) { - return BOTAN_FFI_VISIT( + return botan_ffi_visit( key, [=](const auto& k) -> int { return invoke_view_callback(view, ctx, Botan::PKCS8::BER_encode(k)); }); } int botan_privkey_view_pem(botan_privkey_t key, botan_view_ctx ctx, botan_view_str_fn view) { - return BOTAN_FFI_VISIT( + return botan_ffi_visit( key, [=](const auto& k) -> int { return invoke_view_callback(view, ctx, Botan::PKCS8::PEM_encode(k)); }); } int botan_privkey_view_raw(botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view) { - return BOTAN_FFI_VISIT( + return botan_ffi_visit( key, [=](const auto& k) -> int { return invoke_view_callback(view, ctx, k.raw_private_key_bits()); }); } @@ -232,7 +232,7 @@ int botan_privkey_view_encrypted_der_timed(botan_privkey_t key, return BOTAN_FFI_ERROR_NULL_POINTER; } - return BOTAN_FFI_VISIT(key, [=](const auto& k) { + return botan_ffi_visit(key, [=](const auto& k) { const std::chrono::milliseconds pbkdf_time(pbkdf_runtime_msec); Botan::RandomNumberGenerator& rng = safe_get(rng_obj); @@ -258,7 +258,7 @@ int botan_privkey_view_encrypted_pem_timed(botan_privkey_t key, return BOTAN_FFI_ERROR_NULL_POINTER; } - return BOTAN_FFI_VISIT(key, [=](const auto& k) { + return botan_ffi_visit(key, [=](const auto& k) { const std::chrono::milliseconds pbkdf_time(pbkdf_runtime_msec); Botan::RandomNumberGenerator& rng = safe_get(rng_obj); @@ -304,7 +304,7 @@ int botan_privkey_view_encrypted_der(botan_privkey_t key, return BOTAN_FFI_ERROR_NULL_POINTER; } - return BOTAN_FFI_VISIT(key, [=](const auto& k) { + return botan_ffi_visit(key, [=](const auto& k) { Botan::RandomNumberGenerator& rng = safe_get(rng_obj); const std::string cipher = (maybe_cipher ? maybe_cipher : ""); @@ -329,7 +329,7 @@ int botan_privkey_view_encrypted_pem(botan_privkey_t key, return BOTAN_FFI_ERROR_NULL_POINTER; } - return BOTAN_FFI_VISIT(key, [=](const auto& k) { + return botan_ffi_visit(key, [=](const auto& k) { Botan::RandomNumberGenerator& rng = safe_get(rng_obj); const std::string cipher = (maybe_cipher ? maybe_cipher : ""); @@ -343,11 +343,11 @@ int botan_privkey_view_encrypted_pem(botan_privkey_t key, } int botan_pubkey_estimated_strength(botan_pubkey_t key, size_t* estimate) { - return BOTAN_FFI_VISIT(key, [=](const auto& k) { *estimate = k.estimated_strength(); }); + return botan_ffi_visit(key, [=](const auto& k) { *estimate = k.estimated_strength(); }); } int botan_pubkey_fingerprint(botan_pubkey_t key, const char* hash_fn, uint8_t out[], size_t* out_len) { - return BOTAN_FFI_VISIT(key, [=](const auto& k) { + return botan_ffi_visit(key, [=](const auto& k) { auto h = Botan::HashFunction::create_or_throw(hash_fn); return write_vec_output(out, out_len, h->process(k.public_key_bits())); }); diff --git a/src/lib/ffi/ffi_pkey_algs.cpp b/src/lib/ffi/ffi_pkey_algs.cpp index 083c099edae..fdfb63adb2d 100644 --- a/src/lib/ffi/ffi_pkey_algs.cpp +++ b/src/lib/ffi/ffi_pkey_algs.cpp @@ -185,7 +185,7 @@ int botan_pubkey_get_field(botan_mp_t output, botan_pubkey_t key, const char* fi const std::string field_name(field_name_cstr); - return BOTAN_FFI_VISIT(key, [=](const auto& k) { safe_get(output) = pubkey_get_field(k, field_name); }); + return botan_ffi_visit(key, [=](const auto& k) { safe_get(output) = pubkey_get_field(k, field_name); }); } int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char* field_name_cstr) { @@ -195,7 +195,7 @@ int botan_privkey_get_field(botan_mp_t output, botan_privkey_t key, const char* const std::string field_name(field_name_cstr); - return BOTAN_FFI_VISIT(key, [=](const auto& k) { safe_get(output) = privkey_get_field(k, field_name); }); + return botan_ffi_visit(key, [=](const auto& k) { safe_get(output) = privkey_get_field(k, field_name); }); } /* RSA specific operations */ @@ -286,7 +286,7 @@ int botan_pubkey_rsa_get_n(botan_mp_t n, botan_pubkey_t key) { int botan_privkey_rsa_get_privkey(botan_privkey_t rsa_key, uint8_t out[], size_t* out_len, uint32_t flags) { #if defined(BOTAN_HAS_RSA) - return BOTAN_FFI_VISIT(rsa_key, [=](const auto& k) -> int { + return botan_ffi_visit(rsa_key, [=](const auto& k) -> int { if(const Botan::RSA_PrivateKey* rsa = dynamic_cast(&k)) { if(flags == BOTAN_PRIVKEY_EXPORT_FLAG_DER) { return write_vec_output(out, out_len, rsa->private_key_bits()); @@ -710,7 +710,7 @@ int botan_pubkey_load_ed25519(botan_pubkey_t* key, const uint8_t pubkey[32]) { int botan_privkey_ed25519_get_privkey(botan_privkey_t key, uint8_t output[64]) { #if defined(BOTAN_HAS_ED25519) - return BOTAN_FFI_VISIT(key, [=](const auto& k) { + return botan_ffi_visit(key, [=](const auto& k) { if(auto ed = dynamic_cast(&k)) { const auto ed_key = ed->raw_private_key_bits(); if(ed_key.size() != 64) { @@ -730,7 +730,7 @@ int botan_privkey_ed25519_get_privkey(botan_privkey_t key, uint8_t output[64]) { int botan_pubkey_ed25519_get_pubkey(botan_pubkey_t key, uint8_t output[32]) { #if defined(BOTAN_HAS_ED25519) - return BOTAN_FFI_VISIT(key, [=](const auto& k) { + return botan_ffi_visit(key, [=](const auto& k) { if(auto ed = dynamic_cast(&k)) { const std::vector& ed_key = ed->get_public_key(); if(ed_key.size() != 32) { @@ -780,7 +780,7 @@ int botan_pubkey_load_ed448(botan_pubkey_t* key, const uint8_t pubkey[57]) { int botan_privkey_ed448_get_privkey(botan_privkey_t key, uint8_t output[57]) { #if defined(BOTAN_HAS_ED448) - return BOTAN_FFI_VISIT(key, [=](const auto& k) { + return botan_ffi_visit(key, [=](const auto& k) { if(auto ed = dynamic_cast(&k)) { const auto ed_key = ed->raw_private_key_bits(); Botan::copy_mem(std::span(output, 57), ed_key); @@ -797,7 +797,7 @@ int botan_privkey_ed448_get_privkey(botan_privkey_t key, uint8_t output[57]) { int botan_pubkey_ed448_get_pubkey(botan_pubkey_t key, uint8_t output[57]) { #if defined(BOTAN_HAS_ED448) - return BOTAN_FFI_VISIT(key, [=](const auto& k) { + return botan_ffi_visit(key, [=](const auto& k) { if(auto ed = dynamic_cast(&k)) { const auto ed_key = ed->public_key_bits(); Botan::copy_mem(std::span(output, 57), ed_key); @@ -846,7 +846,7 @@ int botan_pubkey_load_x25519(botan_pubkey_t* key, const uint8_t pubkey[32]) { int botan_privkey_x25519_get_privkey(botan_privkey_t key, uint8_t output[32]) { #if defined(BOTAN_HAS_X25519) - return BOTAN_FFI_VISIT(key, [=](const auto& k) { + return botan_ffi_visit(key, [=](const auto& k) { if(auto x25519 = dynamic_cast(&k)) { const auto x25519_key = x25519->raw_private_key_bits(); if(x25519_key.size() != 32) { @@ -866,7 +866,7 @@ int botan_privkey_x25519_get_privkey(botan_privkey_t key, uint8_t output[32]) { int botan_pubkey_x25519_get_pubkey(botan_pubkey_t key, uint8_t output[32]) { #if defined(BOTAN_HAS_X25519) - return BOTAN_FFI_VISIT(key, [=](const auto& k) { + return botan_ffi_visit(key, [=](const auto& k) { if(auto x25519 = dynamic_cast(&k)) { const std::vector& x25519_key = x25519->public_value(); if(x25519_key.size() != 32) { @@ -916,7 +916,7 @@ int botan_pubkey_load_x448(botan_pubkey_t* key, const uint8_t pubkey[56]) { int botan_privkey_x448_get_privkey(botan_privkey_t key, uint8_t output[56]) { #if defined(BOTAN_HAS_X448) - return BOTAN_FFI_VISIT(key, [=](const auto& k) { + return botan_ffi_visit(key, [=](const auto& k) { if(auto x448 = dynamic_cast(&k)) { const auto x448_key = x448->raw_private_key_bits(); Botan::copy_mem(std::span(output, 56), x448_key); @@ -933,7 +933,7 @@ int botan_privkey_x448_get_privkey(botan_privkey_t key, uint8_t output[56]) { int botan_pubkey_x448_get_pubkey(botan_pubkey_t key, uint8_t output[56]) { #if defined(BOTAN_HAS_X448) - return BOTAN_FFI_VISIT(key, [=](const auto& k) { + return botan_ffi_visit(key, [=](const auto& k) { if(auto x448 = dynamic_cast(&k)) { const std::vector& x448_key = x448->public_value(); Botan::copy_mem(std::span(output, 56), x448_key); @@ -1024,7 +1024,7 @@ int botan_pubkey_load_kyber(botan_pubkey_t* key, const uint8_t pubkey[], size_t int botan_privkey_view_kyber_raw_key(botan_privkey_t key, botan_view_ctx ctx, botan_view_bin_fn view) { #if defined(BOTAN_HAS_KYBER) - return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int { + return botan_ffi_visit(key, [=](const auto& k) -> int { if(auto kyber = dynamic_cast(&k)) { return invoke_view_callback(view, ctx, kyber->raw_private_key_bits()); } else { @@ -1039,7 +1039,7 @@ int botan_privkey_view_kyber_raw_key(botan_privkey_t key, botan_view_ctx ctx, bo int botan_pubkey_view_kyber_raw_key(botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view) { #if defined(BOTAN_HAS_KYBER) - return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int { + return botan_ffi_visit(key, [=](const auto& k) -> int { if(auto kyber = dynamic_cast(&k)) { return invoke_view_callback(view, ctx, kyber->public_key_bits()); } else { @@ -1304,7 +1304,7 @@ int botan_pubkey_load_classic_mceliece(botan_pubkey_t* key, int botan_pubkey_view_ec_public_point(const botan_pubkey_t key, botan_view_ctx ctx, botan_view_bin_fn view) { #if defined(BOTAN_HAS_ECC_PUBLIC_KEY_CRYPTO) - return BOTAN_FFI_VISIT(key, [=](const auto& k) -> int { + return botan_ffi_visit(key, [=](const auto& k) -> int { if(auto ecc = dynamic_cast(&k)) { auto pt = ecc->public_point().encode(Botan::EC_Point_Format::Uncompressed); return invoke_view_callback(view, ctx, pt); diff --git a/src/lib/ffi/ffi_rng.cpp b/src/lib/ffi/ffi_rng.cpp index d3790d1eee8..47af2adee68 100644 --- a/src/lib/ffi/ffi_rng.cpp +++ b/src/lib/ffi/ffi_rng.cpp @@ -154,7 +154,7 @@ int botan_rng_destroy(botan_rng_t rng) { } int botan_rng_get(botan_rng_t rng, uint8_t* out, size_t out_len) { - return BOTAN_FFI_VISIT(rng, [=](auto& r) { r.randomize(out, out_len); }); + return botan_ffi_visit(rng, [=](auto& r) { r.randomize(out, out_len); }); } int botan_system_rng_get(uint8_t* out, size_t out_len) { @@ -165,14 +165,14 @@ int botan_system_rng_get(uint8_t* out, size_t out_len) { } int botan_rng_reseed(botan_rng_t rng, size_t bits) { - return BOTAN_FFI_VISIT(rng, [=](auto& r) { r.reseed_from_rng(Botan::system_rng(), bits); }); + return botan_ffi_visit(rng, [=](auto& r) { r.reseed_from_rng(Botan::system_rng(), bits); }); } int botan_rng_add_entropy(botan_rng_t rng, const uint8_t* input, size_t len) { - return BOTAN_FFI_VISIT(rng, [=](auto& r) { r.add_entropy(input, len); }); + return botan_ffi_visit(rng, [=](auto& r) { r.add_entropy(input, len); }); } int botan_rng_reseed_from_rng(botan_rng_t rng, botan_rng_t source_rng, size_t bits) { - return BOTAN_FFI_VISIT(rng, [=](auto& r) { r.reseed_from_rng(safe_get(source_rng), bits); }); + return botan_ffi_visit(rng, [=](auto& r) { r.reseed_from_rng(safe_get(source_rng), bits); }); } } diff --git a/src/lib/ffi/ffi_srp6.cpp b/src/lib/ffi/ffi_srp6.cpp index 7c574467992..d85d9232460 100644 --- a/src/lib/ffi/ffi_srp6.cpp +++ b/src/lib/ffi/ffi_srp6.cpp @@ -70,7 +70,7 @@ int botan_srp6_server_session_step1(botan_srp6_server_session_t srp6, uint8_t b_pub[], size_t* b_pub_len) { #if defined(BOTAN_HAS_SRP6) - return BOTAN_FFI_VISIT(srp6, [=](auto& s) -> int { + return botan_ffi_visit(srp6, [=](auto& s) -> int { if(!verifier || !group_id || !hash_id || !rng_obj) { return BOTAN_FFI_ERROR_NULL_POINTER; } @@ -94,7 +94,7 @@ int botan_srp6_server_session_step1(botan_srp6_server_session_t srp6, int botan_srp6_server_session_step2( botan_srp6_server_session_t srp6, const uint8_t a[], size_t a_len, uint8_t key[], size_t* key_len) { #if defined(BOTAN_HAS_SRP6) - return BOTAN_FFI_VISIT(srp6, [=](auto& s) -> int { + return botan_ffi_visit(srp6, [=](auto& s) -> int { if(!a) { return BOTAN_FFI_ERROR_NULL_POINTER; } diff --git a/src/lib/ffi/ffi_totp.cpp b/src/lib/ffi/ffi_totp.cpp index f9d15be7d4f..972b574580e 100644 --- a/src/lib/ffi/ffi_totp.cpp +++ b/src/lib/ffi/ffi_totp.cpp @@ -58,7 +58,7 @@ int botan_totp_generate(botan_totp_t totp, uint32_t* totp_code, uint64_t timesta return BOTAN_FFI_ERROR_NULL_POINTER; } - return BOTAN_FFI_VISIT(totp, [=](auto& t) { *totp_code = t.generate_totp(timestamp); }); + return botan_ffi_visit(totp, [=](auto& t) { *totp_code = t.generate_totp(timestamp); }); #else BOTAN_UNUSED(totp, totp_code, timestamp); @@ -68,7 +68,7 @@ int botan_totp_generate(botan_totp_t totp, uint32_t* totp_code, uint64_t timesta int botan_totp_check(botan_totp_t totp, uint32_t totp_code, uint64_t timestamp, size_t acceptable_clock_drift) { #if defined(BOTAN_HAS_TOTP) - return BOTAN_FFI_VISIT(totp, [=](auto& t) { + return botan_ffi_visit(totp, [=](auto& t) { const bool ok = t.verify_totp(totp_code, timestamp, acceptable_clock_drift); return (ok ? BOTAN_FFI_SUCCESS : BOTAN_FFI_INVALID_VERIFIER); }); diff --git a/src/lib/ffi/ffi_tpm2.cpp b/src/lib/ffi/ffi_tpm2.cpp index 5be01d17640..f4d548f256e 100644 --- a/src/lib/ffi/ffi_tpm2.cpp +++ b/src/lib/ffi/ffi_tpm2.cpp @@ -151,7 +151,7 @@ int botan_tpm2_ctx_from_esys(botan_tpm2_ctx_t* ctx_out, ESYS_CONTEXT* esys_ctx) int botan_tpm2_ctx_enable_crypto_backend(botan_tpm2_ctx_t ctx, botan_rng_t rng) { #if defined(BOTAN_HAS_TPM2) - return BOTAN_FFI_VISIT(ctx, [=](botan_tpm2_ctx_wrapper& ctx_wrapper) -> int { + return botan_ffi_visit(ctx, [=](botan_tpm2_ctx_wrapper& ctx_wrapper) -> int { Botan::RandomNumberGenerator& rng_ref = safe_get(rng); // The lifetime of the RNG used for the crypto backend should be managed @@ -219,7 +219,7 @@ int botan_tpm2_rng_init(botan_rng_t* rng_out, botan_tpm2_session_t s2, botan_tpm2_session_t s3) { #if defined(BOTAN_HAS_TPM2) - return BOTAN_FFI_VISIT(ctx, [=](botan_tpm2_ctx_wrapper& ctx_wrapper) -> int { + return botan_ffi_visit(ctx, [=](botan_tpm2_ctx_wrapper& ctx_wrapper) -> int { if(rng_out == nullptr) { return BOTAN_FFI_ERROR_NULL_POINTER; } @@ -236,7 +236,7 @@ int botan_tpm2_rng_init(botan_rng_t* rng_out, int botan_tpm2_unauthenticated_session_init(botan_tpm2_session_t* session_out, botan_tpm2_ctx_t ctx) { #if defined(BOTAN_HAS_TPM2) - return BOTAN_FFI_VISIT(ctx, [=](botan_tpm2_ctx_wrapper& ctx_wrapper) -> int { + return botan_ffi_visit(ctx, [=](botan_tpm2_ctx_wrapper& ctx_wrapper) -> int { if(session_out == nullptr) { return BOTAN_FFI_ERROR_NULL_POINTER; } diff --git a/src/lib/ffi/ffi_util.h b/src/lib/ffi/ffi_util.h index 03bc9760a62..f65db86202c 100644 --- a/src/lib/ffi/ffi_util.h +++ b/src/lib/ffi/ffi_util.h @@ -13,6 +13,7 @@ #include #include #include +#include #include namespace Botan_FFI { @@ -78,7 +79,7 @@ T& safe_get(botan_struct* p) { int ffi_guard_thunk(const char* func_name, const std::function& thunk); template -int botan_ffi_visit(botan_struct* o, F func, const char* func_name) { +int botan_ffi_visit(botan_struct* o, F func, const std::source_location sl = std::source_location::current()) { using RetT = std::invoke_result_t; static_assert(std::is_void_v || std::is_same_v || std::is_same_v, "BOTAN_FFI_DO must be used with a block that returns either nothing, int or BOTAN_FFI_ERROR"); @@ -97,32 +98,15 @@ int botan_ffi_visit(botan_struct* o, F func, const char* func_name) { } if constexpr(std::is_void_v) { - return ffi_guard_thunk(func_name, [&] { + return ffi_guard_thunk(sl.function_name(), [&] { func(*p); return BOTAN_FFI_SUCCESS; }); } else { - return ffi_guard_thunk(func_name, [&] { return func(*p); }); + return ffi_guard_thunk(sl.function_name(), [&] { return func(*p); }); } } -// TODO: C++20 introduces std::source_location which will allow to eliminate this -// macro altogether. Instead, using code would just call the C++ function -// that makes use of std::source_location like so: -// -// template -// int botan_ffi_visit(botan_struct* obj, F func, -// const std::source_location sl = std::source_location::current()) -// { -// // [...] -// if constexpr(...) -// { -// return ffi_guard_thunk(sl.function_name(), [&] { return func(*p); }) -// } -// // [...] -// } -#define BOTAN_FFI_VISIT(obj, lambda) botan_ffi_visit(obj, lambda, __func__) - template int ffi_delete_object(botan_struct* obj, const char* func_name) { return ffi_guard_thunk(func_name, [=]() -> int { diff --git a/src/lib/math/mp/mp_core.h b/src/lib/math/mp/mp_core.h index 6c9247e92b2..05777541e9d 100644 --- a/src/lib/math/mp/mp_core.h +++ b/src/lib/math/mp/mp_core.h @@ -860,9 +860,8 @@ inline constexpr W shift_right(std::array& x) { return carry; } -// Should be consteval but this triggers a bug in Clang 14 template -constexpr auto hex_to_words(const char (&s)[N]) { +consteval auto hex_to_words(const char (&s)[N]) { // Char count includes null terminator which we ignore const constexpr size_t C = N - 1; diff --git a/src/lib/math/pcurves/pcurves_impl/pcurves_impl.h b/src/lib/math/pcurves/pcurves_impl/pcurves_impl.h index dae2456f03b..60f91515259 100644 --- a/src/lib/math/pcurves/pcurves_impl/pcurves_impl.h +++ b/src/lib/math/pcurves/pcurves_impl/pcurves_impl.h @@ -1483,7 +1483,7 @@ class BlindedScalarBits final { static constexpr size_t Bits = C::Scalar::BITS + (BlindingEnabled ? BlindingBits : 0); static constexpr size_t Bytes = (Bits + 7) / 8; - BlindedScalarBits(const typename C::Scalar& scalar, RandomNumberGenerator& rng) { + BlindedScalarBits(const C::Scalar& scalar, RandomNumberGenerator& rng) { if constexpr(BlindingEnabled) { constexpr size_t mask_words = BlindingBits / WordInfo::bits; constexpr size_t mask_bytes = mask_words * WordInfo::bytes; @@ -1552,7 +1552,7 @@ class UnblindedScalarBits final { public: static constexpr size_t Bits = C::Scalar::BITS; - UnblindedScalarBits(const typename C::Scalar& scalar) { scalar.serialize_to(std::span{m_bytes}); } + UnblindedScalarBits(const C::Scalar& scalar) { scalar.serialize_to(std::span{m_bytes}); } size_t get_window(size_t offset) const { // Extract a WindowBits sized window out of s, depending on offset. @@ -1973,7 +1973,7 @@ const auto& SSWU_C1() * See RFC 9380 ("Hashing to Elliptic Curves") section 6.6.2 */ template -inline auto map_to_curve_sswu(const typename C::FieldElement& u) -> typename C::AffinePoint { +inline auto map_to_curve_sswu(const typename C::FieldElement& u) -> C::AffinePoint { CT::poison(u); const auto z_u2 = C::SSWU_Z * u.square(); // z * u^2 const auto z2_u4 = z_u2.square(); diff --git a/src/lib/math/pcurves/pcurves_impl/pcurves_wrap.h b/src/lib/math/pcurves/pcurves_impl/pcurves_wrap.h index 1d6876d98b1..3c1357b6e40 100644 --- a/src/lib/math/pcurves/pcurves_impl/pcurves_wrap.h +++ b/src/lib/math/pcurves/pcurves_impl/pcurves_wrap.h @@ -31,8 +31,7 @@ class PrimeOrderCurveImpl final : public PrimeOrderCurve { const WindowedMul2Table& table() const { return m_table; } - explicit PrecomputedMul2TableC(const typename C::AffinePoint& x, const typename C::AffinePoint& y) : - m_table(x, y) {} + explicit PrecomputedMul2TableC(const C::AffinePoint& x, const C::AffinePoint& y) : m_table(x, y) {} private: WindowedMul2Table m_table; @@ -324,24 +323,24 @@ class PrimeOrderCurveImpl final : public PrimeOrderCurve { } private: - static Scalar stash(const typename C::Scalar& s) { + static Scalar stash(const C::Scalar& s) { return Scalar::_create(instance(), s.template stash_value()); } - static typename C::Scalar from_stash(const Scalar& s) { + static C::Scalar from_stash(const Scalar& s) { if(s._curve() != instance()) { throw Invalid_Argument("Curve mismatch"); } return C::Scalar::from_stash(s._value()); } - static AffinePoint stash(const typename C::AffinePoint& pt) { + static AffinePoint stash(const C::AffinePoint& pt) { auto x_w = pt.x().template stash_value(); auto y_w = pt.y().template stash_value(); return AffinePoint::_create(instance(), x_w, y_w); } - static typename C::AffinePoint from_stash(const AffinePoint& pt) { + static C::AffinePoint from_stash(const AffinePoint& pt) { if(pt._curve() != instance()) { throw Invalid_Argument("Curve mismatch"); } @@ -350,14 +349,14 @@ class PrimeOrderCurveImpl final : public PrimeOrderCurve { return typename C::AffinePoint(x, y); } - static ProjectivePoint stash(const typename C::ProjectivePoint& pt) { + static ProjectivePoint stash(const C::ProjectivePoint& pt) { auto x_w = pt.x().template stash_value(); auto y_w = pt.y().template stash_value(); auto z_w = pt.z().template stash_value(); return ProjectivePoint::_create(instance(), x_w, y_w, z_w); } - static typename C::ProjectivePoint from_stash(const ProjectivePoint& pt) { + static C::ProjectivePoint from_stash(const ProjectivePoint& pt) { if(pt._curve() != instance()) { throw Invalid_Argument("Curve mismatch"); }