Skip to content

Commit

Permalink
Make kex_to_kem_adapter public
Browse files Browse the repository at this point in the history
  • Loading branch information
FAlbertDev committed Jun 19, 2024
1 parent 168655b commit 9252d58
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/lib/pubkey/hybrid_kem/hybrid_kem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
*/
#include <botan/hybrid_kem.h>

#include <botan/kex_to_kem_adapter.h>
#include <botan/pk_algs.h>
#include <botan/internal/fmt.h>
#include <botan/internal/kex_to_kem_adapter.h>
#include <botan/internal/pk_ops_impl.h>
#include <botan/internal/stl_util.h>

Expand Down
5 changes: 2 additions & 3 deletions src/lib/pubkey/kex_to_kem_adapter/info.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ KEX_TO_KEM_ADAPTER -> 20240504

<module_info>
name -> "KEX to KEM adapter"
type -> "Internal"
</module_info>


<header:internal>
<header:public>
kex_to_kem_adapter.h
</header:internal>
</header:public>

<requires>

Expand Down
16 changes: 9 additions & 7 deletions src/lib/pubkey/kex_to_kem_adapter/kex_to_kem_adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Botan is released under the Simplified BSD License (see license.txt)
*/

#include <botan/internal/kex_to_kem_adapter.h>
#include <botan/kex_to_kem_adapter.h>

#include <botan/internal/fmt.h>
#include <botan/internal/pk_ops_impl.h>
Expand Down Expand Up @@ -103,7 +103,7 @@ std::unique_ptr<PK_Key_Agreement_Key> generate_key_agreement_private_key(const P
return new_kex_key;
}

std::unique_ptr<Public_Key> maybe_get_public_key(const std::unique_ptr<PK_Key_Agreement_Key>& private_key) {
std::unique_ptr<Public_Key> maybe_get_public_key(const std::unique_ptr<Private_Key>& private_key) {
BOTAN_ARG_CHECK(private_key != nullptr, "Private key is a nullptr");
return private_key->public_key();
}
Expand Down Expand Up @@ -210,7 +210,7 @@ std::vector<uint8_t> KEX_to_KEM_Adapter_PublicKey::raw_public_key_bits() const {
}

std::vector<uint8_t> KEX_to_KEM_Adapter_PublicKey::public_key_bits() const {
throw Not_Implemented("The KEX-to-KEM adapter does not support ASN.1-based public key serialization");
return m_public_key->public_key_bits();
}

std::unique_ptr<Private_Key> KEX_to_KEM_Adapter_PublicKey::generate_another(RandomNumberGenerator& rng) const {
Expand All @@ -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<PK_Key_Agreement_Key> 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> private_key) :
KEX_to_KEM_Adapter_PublicKey(maybe_get_public_key(private_key)), m_private_key([&]() {
auto sk = dynamic_cast<PK_Key_Agreement_Key*>(private_key.release());
BOTAN_ARG_CHECK(sk != nullptr, "Private Key must implement the PK_Key_Agreement_Key interface");
return std::unique_ptr<PK_Key_Agreement_Key>(sk);
}()) {}

secure_vector<uint8_t> KEX_to_KEM_Adapter_PrivateKey::private_key_bits() const {
return m_private_key->private_key_bits();
Expand Down
11 changes: 6 additions & 5 deletions src/lib/pubkey/kex_to_kem_adapter/kex_to_kem_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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> public_key);

Expand Down Expand Up @@ -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:
*
Expand All @@ -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<PK_Key_Agreement_Key> private_key);
KEX_to_KEM_Adapter_PrivateKey(std::unique_ptr<Private_Key> private_key);

secure_vector<uint8_t> private_key_bits() const override;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/tls/tls13_pqc/hybrid_public_key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

#include <botan/pk_algs.h>

#include <botan/kex_to_kem_adapter.h>
#include <botan/internal/fmt.h>
#include <botan/internal/hybrid_kem_ops.h>
#include <botan/internal/kex_to_kem_adapter.h>
#include <botan/internal/pk_ops_impl.h>
#include <botan/internal/stl_util.h>

Expand Down
2 changes: 1 addition & 1 deletion src/tests/test_tls_hybrid_kem_key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <botan/kex_to_kem_adapter.h>
#include <botan/pk_algs.h>
#include <botan/internal/hybrid_public_key.h>
#include <botan/internal/kex_to_kem_adapter.h>
#include <botan/internal/stl_util.h>

namespace Botan_Tests {
Expand Down

0 comments on commit 9252d58

Please sign in to comment.