9#include <botan/internal/hybrid_kem.h>
11#include <botan/internal/fmt.h>
12#include <botan/internal/stl_util.h>
17 m_pks(std::move(pks)), m_key_length(0), m_estimated_strength(0) {
18 BOTAN_ARG_CHECK(m_pks.size() >= 2,
"List of public keys must include at least two keys");
19 for(
const auto& pk : m_pks) {
20 BOTAN_ARG_CHECK(pk !=
nullptr,
"List of public keys contains a nullptr");
22 fmt(
"Public key type '{}' does not support key encapsulation", pk->algo_name()).c_str());
23 m_key_length = std::max(m_key_length, pk->key_length());
24 m_estimated_strength = std::max(m_estimated_strength, pk->estimated_strength());
29 return reduce(
public_keys(),
true, [&](
bool ckr,
const auto& key) {
return ckr && key->check_key(rng, strong); });
33 return reduce(
public_keys(), std::vector<uint8_t>(), [](
auto pkb,
const auto& key) {
34 return concat(pkb, key->raw_public_key_bits());
44 std::vector<std::unique_ptr<Private_Key>> new_private_keys;
47 new_private_keys.push_back(pk->generate_another(rng));
49 return new_private_keys;
54 BOTAN_ARG_CHECK(m_sks.size() >= 2,
"List of secret keys must include at least two keys");
55 for(
const auto& sk : m_sks) {
56 BOTAN_ARG_CHECK(sk !=
nullptr,
"List of secret keys contains a nullptr");
58 "Some provided secret key is not compatible with this hybrid wrapper");
67 return reduce(
private_keys(),
true, [&](
bool ckr,
const auto& key) {
return ckr && key->check_key(rng, strong); });
71 const std::vector<std::unique_ptr<Private_Key>>&
private_keys) {
72 std::vector<std::unique_ptr<Public_Key>> public_keys;
75 BOTAN_ARG_CHECK(sk !=
nullptr,
"List of private keys contains a nullptr");
76 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