9#include <botan/internal/hybrid_kem.h>
11#include <botan/pk_algs.h>
12#include <botan/internal/fmt.h>
13#include <botan/internal/kex_to_kem_adapter.h>
14#include <botan/internal/pk_ops_impl.h>
15#include <botan/internal/stl_util.h>
20 m_pks(std::move(pks)), m_key_length(0), m_estimated_strength(0) {
21 BOTAN_ARG_CHECK(m_pks.size() >= 2,
"List of public keys must include at least two keys");
22 for(
const auto& pk : m_pks) {
23 BOTAN_ARG_CHECK(pk !=
nullptr,
"List of public keys contains a nullptr");
25 fmt(
"Public key type '{}' does not support key encapsulation", pk->algo_name()).c_str());
26 m_key_length = std::max(m_key_length, pk->key_length());
27 m_estimated_strength = std::max(m_estimated_strength, pk->estimated_strength());
32 return reduce(
public_keys(),
true, [&](
bool ckr,
const auto& key) {
return ckr && key->check_key(rng, strong); });
36 return reduce(
public_keys(), std::vector<uint8_t>(), [](
auto pkb,
const auto& key) {
37 return concat(pkb, key->raw_public_key_bits());
47 std::vector<std::unique_ptr<Private_Key>> new_private_keys;
50 new_private_keys.push_back(pk->generate_another(rng));
52 return new_private_keys;
57 BOTAN_ARG_CHECK(m_sks.size() >= 2,
"List of secret keys must include at least two keys");
58 for(
const auto& sk : m_sks) {
59 BOTAN_ARG_CHECK(sk !=
nullptr,
"List of secret keys contains a nullptr");
61 "Some provided secret key is not compatible with this hybrid wrapper");
70 return reduce(
private_keys(),
true, [&](
bool ckr,
const auto& key) {
return ckr && key->check_key(rng, strong); });
74 const std::vector<std::unique_ptr<Private_Key>>&
private_keys) {
75 std::vector<std::unique_ptr<Public_Key>> public_keys;
78 BOTAN_ARG_CHECK(sk !=
nullptr,
"List of private keys contains a nullptr");
79 public_keys.push_back(sk->public_key());
#define BOTAN_ARG_CHECK(expr, msg)
bool check_key(RandomNumberGenerator &rng, bool strong) const override
const std::vector< std::unique_ptr< Private_Key > > & private_keys() const
Hybrid_PrivateKey(const Hybrid_PrivateKey &)=delete
secure_vector< uint8_t > private_key_bits() const override
Disabled by default.
static std::vector< std::unique_ptr< Public_Key > > extract_public_keys(const std::vector< std::unique_ptr< Private_Key > > &private_keys)
bool supports_operation(PublicKeyOperation op) const override
bool check_key(RandomNumberGenerator &rng, bool strong) const override
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...
Hybrid_PublicKey()=default
std::vector< uint8_t > raw_public_key_bits() const override
const std::vector< std::unique_ptr< Public_Key > > & public_keys() const
std::string fmt(std::string_view format, const T &... args)
RetT reduce(const std::vector< KeyT > &keys, RetT acc, ReducerT reducer)
constexpr auto concat(Rs &&... ranges)
std::vector< T, secure_allocator< T > > secure_vector