Botan 3.9.0
Crypto and TLS for C&
hybrid_kem.h
Go to the documentation of this file.
1/**
2* Abstraction for a combined KEM public and private key.
3*
4* (C) 2024 Jack Lloyd
5* 2024 Fabian Albert, René Meusel - Rohde & Schwarz Cybersecurity
6*
7* Botan is released under the Simplified BSD License (see license.txt)
8*/
9
10#ifndef BOTAN_HYBRID_KEM_H_
11#define BOTAN_HYBRID_KEM_H_
12
13#include <botan/pk_algs.h>
14#include <botan/pk_keys.h>
15#include <botan/pubkey.h>
16
17#include <memory>
18#include <vector>
19
20namespace Botan {
21
22/**
23 * @brief Abstraction for a combined KEM public key.
24 *
25 * Two or more KEM public keys are combined into a single KEM public key. Derived classes
26 * must implement the abstract methods to provide the encryption operation, e.g. by
27 * specifying how encryption results are combined to the ciphertext and how a KEM combiner
28 * is applied to derive the shared secret using the individual shared secrets, ciphertexts,
29 * and other context information.
30 */
32 public:
33 /**
34 * @brief Constructor for a list of multiple KEM public keys.
35 *
36 * To use KEX algorithms use the KEX_to_KEM_Adapter_PublicKey.
37 * @param public_keys List of public keys to combine
38 */
39 explicit Hybrid_PublicKey(std::vector<std::unique_ptr<Public_Key>> public_keys);
40
45 ~Hybrid_PublicKey() override = default;
46
47 size_t estimated_strength() const override { return m_estimated_strength; }
48
49 size_t key_length() const override { return m_key_length; }
50
51 bool check_key(RandomNumberGenerator& rng, bool strong) const override;
52
53 std::vector<uint8_t> raw_public_key_bits() const override;
54
55 /**
56 * @brief Return the public key bits of this hybrid key as the concatenated
57 * bytes of the individual public keys (without encoding).
58 *
59 * @return the public key bytes
60 */
61 std::vector<uint8_t> public_key_bits() const override { return raw_public_key_bits(); }
62
63 bool supports_operation(PublicKeyOperation op) const override;
64
65 /// @returns the public keys combined in this hybrid key
66 const std::vector<std::unique_ptr<Public_Key>>& public_keys() const { return m_pks; }
67
68 protected:
69 // Default constructor used for virtual inheritance to prevent, that the derived class
70 // calls the constructor twice.
71 Hybrid_PublicKey() = default;
72
73 /**
74 * @brief Helper function for generate_another. Generate a new private key for each
75 * public key in this hybrid key.
76 */
77 std::vector<std::unique_ptr<Private_Key>> generate_other_sks_from_pks(RandomNumberGenerator& rng) const;
78
79 private:
80 std::vector<std::unique_ptr<Public_Key>> m_pks;
81
82 size_t m_key_length = 0;
83 size_t m_estimated_strength = 0;
84};
85
88
89/**
90 * @brief Abstraction for a combined KEM private key.
91 *
92 * Two or more KEM private keys are combined into a single KEM private key. Derived classes
93 * must implement the abstract methods to provide the decryption operation, e.g. by
94 * specifying how a KEM combiner is applied to derive the shared secret using the
95 * individual shared secrets, ciphertexts, and other context information.
96 */
98 public:
101
104
105 ~Hybrid_PrivateKey() override = default;
106
107 /**
108 * @brief Constructor for a list of multiple KEM private keys.
109 *
110 * To use KEX algorithms use the KEX_to_KEM_Adapter_PrivateKey.
111 * @param private_keys List of private keys to combine
112 */
113 explicit Hybrid_PrivateKey(std::vector<std::unique_ptr<Private_Key>> private_keys);
114
115 /// Disabled by default
117
118 /// @returns the private keys combined in this hybrid key
119 const std::vector<std::unique_ptr<Private_Key>>& private_keys() const { return m_sks; }
120
121 bool check_key(RandomNumberGenerator& rng, bool strong) const override;
122
123 protected:
124 static std::vector<std::unique_ptr<Public_Key>> extract_public_keys(
125 const std::vector<std::unique_ptr<Private_Key>>& private_keys);
126
127 private:
128 std::vector<std::unique_ptr<Private_Key>> m_sks;
129};
130
132
133} // namespace Botan
134
135#endif
#define BOTAN_DIAGNOSTIC_POP
Definition api.h:122
#define BOTAN_DIAGNOSTIC_PUSH
Definition api.h:119
#define BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
Definition api.h:121
#define BOTAN_TEST_API
Definition api.h:41
Hybrid_PrivateKey & operator=(Hybrid_PrivateKey &&)=default
Hybrid_PrivateKey & operator=(const Hybrid_PrivateKey &)=delete
Hybrid_PrivateKey(Hybrid_PrivateKey &&)=default
const std::vector< std::unique_ptr< Private_Key > > & private_keys() const
Definition hybrid_kem.h:119
~Hybrid_PrivateKey() override=default
Hybrid_PrivateKey(const Hybrid_PrivateKey &)=delete
secure_vector< uint8_t > private_key_bits() const override
Disabled by default.
Hybrid_PublicKey(std::vector< std::unique_ptr< Public_Key > > public_keys)
Constructor for a list of multiple KEM public keys.
size_t estimated_strength() const override
Definition hybrid_kem.h:47
size_t key_length() const override
Definition hybrid_kem.h:49
Hybrid_PublicKey & operator=(const Hybrid_PublicKey &)=delete
std::vector< std::unique_ptr< Private_Key > > generate_other_sks_from_pks(RandomNumberGenerator &rng) const
Helper function for generate_another. Generate a new private key for each public key in this hybrid k...
std::vector< uint8_t > raw_public_key_bits() const override
std::vector< uint8_t > public_key_bits() const override
Return the public key bits of this hybrid key as the concatenated bytes of the individual public keys...
Definition hybrid_kem.h:61
~Hybrid_PublicKey() override=default
Hybrid_PublicKey(Hybrid_PublicKey &&)=default
const std::vector< std::unique_ptr< Public_Key > > & public_keys() const
Definition hybrid_kem.h:66
Hybrid_PublicKey(const Hybrid_PublicKey &)=delete
Hybrid_PublicKey & operator=(Hybrid_PublicKey &&)=default
PublicKeyOperation
Definition pk_keys.h:46
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:69