diff --git a/src/lib/pubkey/hybrid_kem/hybrid_kem.cpp b/src/lib/pubkey/hybrid_kem/hybrid_kem.cpp index 51a9d51d5e5..7920a7ea4da 100644 --- a/src/lib/pubkey/hybrid_kem/hybrid_kem.cpp +++ b/src/lib/pubkey/hybrid_kem/hybrid_kem.cpp @@ -8,9 +8,9 @@ */ #include +#include #include #include -#include #include #include diff --git a/src/lib/pubkey/kex_to_kem_adapter/info.txt b/src/lib/pubkey/kex_to_kem_adapter/info.txt index f251f46b071..e2e6f260939 100644 --- a/src/lib/pubkey/kex_to_kem_adapter/info.txt +++ b/src/lib/pubkey/kex_to_kem_adapter/info.txt @@ -4,13 +4,12 @@ KEX_TO_KEM_ADAPTER -> 20240504 name -> "KEX to KEM adapter" -type -> "Internal" - + kex_to_kem_adapter.h - + diff --git a/src/lib/pubkey/kex_to_kem_adapter/kex_to_kem_adapter.cpp b/src/lib/pubkey/kex_to_kem_adapter/kex_to_kem_adapter.cpp index c90c8027249..7301b06f9d7 100644 --- a/src/lib/pubkey/kex_to_kem_adapter/kex_to_kem_adapter.cpp +++ b/src/lib/pubkey/kex_to_kem_adapter/kex_to_kem_adapter.cpp @@ -8,7 +8,7 @@ * Botan is released under the Simplified BSD License (see license.txt) */ -#include +#include #include #include @@ -103,7 +103,7 @@ std::unique_ptr generate_key_agreement_private_key(const P return new_kex_key; } -std::unique_ptr maybe_get_public_key(const std::unique_ptr& private_key) { +std::unique_ptr maybe_get_public_key(const std::unique_ptr& private_key) { BOTAN_ARG_CHECK(private_key != nullptr, "Private key is a nullptr"); return private_key->public_key(); } @@ -221,10 +221,12 @@ bool KEX_to_KEM_Adapter_PublicKey::supports_operation(PublicKeyOperation op) con return op == PublicKeyOperation::KeyEncapsulation; } -KEX_to_KEM_Adapter_PrivateKey::KEX_to_KEM_Adapter_PrivateKey(std::unique_ptr private_key) : - KEX_to_KEM_Adapter_PublicKey(maybe_get_public_key(private_key)), m_private_key(std::move(private_key)) { - BOTAN_ARG_CHECK(m_private_key->supports_operation(PublicKeyOperation::KeyAgreement), "Private key is no KEX key"); -} +KEX_to_KEM_Adapter_PrivateKey::KEX_to_KEM_Adapter_PrivateKey(std::unique_ptr private_key) : + KEX_to_KEM_Adapter_PublicKey(maybe_get_public_key(private_key)), m_private_key([&]() { + auto sk = dynamic_cast(private_key.release()); + BOTAN_ARG_CHECK(sk != nullptr, "Private Key must implement the PK_Key_Agreement_Key interface"); + return std::unique_ptr(sk); + }()) {} secure_vector KEX_to_KEM_Adapter_PrivateKey::private_key_bits() const { return m_private_key->private_key_bits(); diff --git a/src/lib/pubkey/kex_to_kem_adapter/kex_to_kem_adapter.h b/src/lib/pubkey/kex_to_kem_adapter/kex_to_kem_adapter.h index 67eb822a0ef..37e2c8b9f09 100644 --- a/src/lib/pubkey/kex_to_kem_adapter/kex_to_kem_adapter.h +++ b/src/lib/pubkey/kex_to_kem_adapter/kex_to_kem_adapter.h @@ -21,7 +21,7 @@ namespace Botan { * Adapter to use a key agreement key pair (e.g. ECDH) as a key encapsulation * mechanism. */ -class BOTAN_TEST_API KEX_to_KEM_Adapter_PublicKey : public virtual Public_Key { +class BOTAN_PUBLIC_API(3, 5) KEX_to_KEM_Adapter_PublicKey : public virtual Public_Key { public: KEX_to_KEM_Adapter_PublicKey(std::unique_ptr public_key); @@ -49,7 +49,8 @@ BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE /** * Adapter to use a key agreement key pair (e.g. ECDH) as a key encapsulation * mechanism. This works by generating an ephemeral key pair during the - * encapsulation. + * encapsulation. The following Botan key types are supported: + * ECDH, DH, X25519 and X448. * * The abstract interface of a key exchange mechanism (KEX) is mapped like so: * @@ -64,10 +65,10 @@ BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE * * KEM-decapsulate(PrivateKey, EncapsulatedSharedSecret) -> SharedSecret * => KEX-agree(PrivateKey, EncapsulatedSharedSecret) */ -class BOTAN_TEST_API KEX_to_KEM_Adapter_PrivateKey final : public KEX_to_KEM_Adapter_PublicKey, - public virtual Private_Key { +class BOTAN_PUBLIC_API(3, 5) KEX_to_KEM_Adapter_PrivateKey final : public KEX_to_KEM_Adapter_PublicKey, + public virtual Private_Key { public: - KEX_to_KEM_Adapter_PrivateKey(std::unique_ptr private_key); + KEX_to_KEM_Adapter_PrivateKey(std::unique_ptr private_key); secure_vector private_key_bits() const override; diff --git a/src/lib/tls/tls13_pqc/hybrid_public_key.cpp b/src/lib/tls/tls13_pqc/hybrid_public_key.cpp index c326456b0a1..dd4d696a337 100644 --- a/src/lib/tls/tls13_pqc/hybrid_public_key.cpp +++ b/src/lib/tls/tls13_pqc/hybrid_public_key.cpp @@ -12,9 +12,9 @@ #include +#include #include #include -#include #include #include diff --git a/src/tests/test_tls_hybrid_kem_key.cpp b/src/tests/test_tls_hybrid_kem_key.cpp index adcf7a2fb55..9956cc02ccb 100644 --- a/src/tests/test_tls_hybrid_kem_key.cpp +++ b/src/tests/test_tls_hybrid_kem_key.cpp @@ -10,9 +10,9 @@ #if defined(BOTAN_HAS_TLS_13_PQC) && defined(BOTAN_HAS_KYBER) && defined(BOTAN_HAS_DIFFIE_HELLMAN) && \ defined(BOTAN_HAS_ECDSA) + #include #include #include - #include #include namespace Botan_Tests {