Botan 3.14.1
Crypto and TLS for C&
kex_to_kem_adapter.h
Go to the documentation of this file.
1/**
2 * Adapter that allows using a KEX key as a KEM, using an ephemeral
3 * key in the KEM encapsulation.
4 *
5 * (C) 2023 Jack Lloyd
6 * 2023,2024 Fabian Albert, René Meusel - Rohde & Schwarz Cybersecurity
7 *
8 * Botan is released under the Simplified BSD License (see license.txt)
9 */
10
11#ifndef BOTAN_TLS_13_KEX_TO_KEM_ADAPTER_H_
12#define BOTAN_TLS_13_KEX_TO_KEM_ADAPTER_H_
13
14#include <botan/pubkey.h>
15
16#include <memory>
17
18namespace Botan {
19
20/**
21 * Adapter to use a key agreement key pair (e.g. ECDH) as a key encapsulation
22 * mechanism.
23 */
25 public:
26 explicit KEX_to_KEM_Adapter_PublicKey(std::unique_ptr<Public_Key> public_key);
27
28 std::string algo_name() const override;
29 size_t estimated_strength() const override;
30 size_t key_length() const override;
31 bool check_key(RandomNumberGenerator& rng, bool strong) const override;
33 std::vector<uint8_t> raw_public_key_bits() const override;
34 std::vector<uint8_t> public_key_bits() const override;
35 std::unique_ptr<Private_Key> generate_another(RandomNumberGenerator& rng) const final;
36
37 bool supports_operation(PublicKeyOperation op) const override;
38
39 std::unique_ptr<PK_Ops::KEM_Encryption> _create_kem_encryption_op(
40 const PK_KEM_Options_Reader& options) const override;
41
42 /**
43 * @return the adapted key agreement public key
44 */
45 const Public_Key& kex_public_key() const { return *m_public_key; }
46
47 private:
48 std::shared_ptr<const Public_Key> m_public_key;
49};
50
53
54/**
55 * Adapter to use a key agreement key pair (e.g. ECDH) as a key encapsulation
56 * mechanism. This works by generating an ephemeral key pair during the
57 * encapsulation. The following Botan key types are supported:
58 * ECDH, DH, X25519 and X448.
59 *
60 * The abstract interface of a key exchange mechanism (KEX) is mapped like so:
61 *
62 * * KEM-generate(rng) -> tuple[PublicKey, PrivateKey]
63 * => KEX-generate(rng) -> tuple[PublicKey, PrivateKey]
64 *
65 * * KEM-encapsulate(PublicKey, rng) -> tuple[SharedSecret, EncapsulatedSharedSecret]
66 * => eph_pk, eph_sk = KEX-generate(rng)
67 * secret = KEX-agree(eph_sk, PublicKey)
68 * [secret, eph_pk]
69 *
70 * * KEM-decapsulate(PrivateKey, EncapsulatedSharedSecret) -> SharedSecret
71 * => KEX-agree(PrivateKey, EncapsulatedSharedSecret)
72 */
74 public virtual Private_Key {
75 public:
76 explicit KEX_to_KEM_Adapter_PrivateKey(std::unique_ptr<Private_Key> private_key);
77
79
81
82 std::unique_ptr<Public_Key> public_key() const override;
83
84 bool check_key(RandomNumberGenerator& rng, bool strong) const override;
85
86 std::unique_ptr<PK_Ops::KEM_Decryption> _create_kem_decryption_op(
87 RandomNumberGenerator& rng, const PK_KEM_Options_Reader& options) const override;
88
89 private:
90 std::unique_ptr<PK_Key_Agreement_Key> m_private_key;
91};
92
94
95} // namespace Botan
96
97#endif
#define BOTAN_DIAGNOSTIC_POP
Definition api.h:128
#define BOTAN_DIAGNOSTIC_PUSH
Definition api.h:125
#define BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
Definition api.h:127
#define BOTAN_TEST_API
Definition api.h:41
secure_vector< uint8_t > private_key_bits() const override
std::unique_ptr< Public_Key > public_key() const override
secure_vector< uint8_t > raw_private_key_bits() const override
KEX_to_KEM_Adapter_PrivateKey(std::unique_ptr< Private_Key > private_key)
std::unique_ptr< PK_Ops::KEM_Decryption > _create_kem_decryption_op(RandomNumberGenerator &rng, const PK_KEM_Options_Reader &options) const override
bool check_key(RandomNumberGenerator &rng, bool strong) const override
KEX_to_KEM_Adapter_PublicKey(std::unique_ptr< Public_Key > public_key)
std::string algo_name() const override
std::unique_ptr< PK_Ops::KEM_Encryption > _create_kem_encryption_op(const PK_KEM_Options_Reader &options) const override
bool check_key(RandomNumberGenerator &rng, bool strong) const override
std::vector< uint8_t > raw_public_key_bits() const override
const Public_Key & kex_public_key() const
std::unique_ptr< Private_Key > generate_another(RandomNumberGenerator &rng) const final
AlgorithmIdentifier algorithm_identifier() const override
bool supports_operation(PublicKeyOperation op) const override
std::vector< uint8_t > public_key_bits() const override
PublicKeyOperation
Definition pk_keys.h:50
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:128