Botan 3.8.1
Crypto and TLS for C&
hybrid_public_key.h
Go to the documentation of this file.
1/**
2* Composite key pair that exposes the Public/Private key API but combines
3* multiple key agreement schemes into a hybrid algorithm.
4*
5* (C) 2023 Jack Lloyd
6* 2023 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_HYBRID_KEM_PUBLIC_KEY_H_
12#define BOTAN_TLS_13_HYBRID_KEM_PUBLIC_KEY_H_
13
14#include <botan/pubkey.h>
15
16#include <botan/tls_algos.h>
17#include <botan/internal/hybrid_kem.h>
18
19#include <memory>
20#include <vector>
21
22namespace Botan::TLS {
23
24/**
25 * Composes a number of public keys as defined in this IETF draft:
26 * https://datatracker.ietf.org/doc/html/draft-ietf-tls-hybrid-design-04
27 *
28 * To an upstream user, this composite key pair is presented as a KEM. Each
29 * individual key pair must either work as a KEX or as a KEM. Currently, the
30 * class can deal with ECC keys and Kyber.
31 *
32 * The typical use case provides exactly two keys (one traditional KEX and one
33 * post-quantum secure KEM). However, this class technically allows composing
34 * any number of such keys. Composing more than two keys simply generates a
35 * shared secret based on more algorithms.
36 *
37 * Note that this class is not generic enough for arbitrary use cases but
38 * serializes and parses keys and ciphertexts as described in the
39 * above-mentioned IETF draft for a post-quantum TLS 1.3.
40 */
42 public:
43 static std::unique_ptr<Hybrid_KEM_PublicKey> load_for_group(Group_Params group,
44 std::span<const uint8_t> concatenated_public_values);
45
46 public:
47 explicit Hybrid_KEM_PublicKey(std::vector<std::unique_ptr<Public_Key>> pks);
48
49 std::string algo_name() const override;
51 std::vector<uint8_t> raw_public_key_bits() const override;
52 std::vector<uint8_t> public_key_bits() const override;
53 std::unique_ptr<Private_Key> generate_another(RandomNumberGenerator& rng) const final;
54
55 // no KDF support
56 std::unique_ptr<PK_Ops::KEM_Encryption> create_kem_encryption_op(
57 std::string_view params, std::string_view provider = "base") const override;
58
59 protected:
61};
62
65
66/**
67 * Composes a number of private keys for hybrid key agreement as defined in this
68 * IETF draft: https://datatracker.ietf.org/doc/html/draft-ietf-tls-hybrid-design-04
69 */
71 public Hybrid_PrivateKey {
72 public:
73 /**
74 * Generate a hybrid private key for the given TLS code point.
75 */
76 static std::unique_ptr<Hybrid_KEM_PrivateKey> generate_from_group(Group_Params group, RandomNumberGenerator& rng);
77
78 public:
79 Hybrid_KEM_PrivateKey(std::vector<std::unique_ptr<Private_Key>> private_keys);
80
81 std::unique_ptr<Public_Key> public_key() const override {
82 return std::make_unique<Hybrid_KEM_PublicKey>(extract_public_keys(private_keys()));
83 }
84
85 bool check_key(RandomNumberGenerator& rng, bool strong) const override {
86 return Hybrid_PrivateKey::check_key(rng, strong);
87 }
88
89 // no KDF support
90 std::unique_ptr<PK_Ops::KEM_Decryption> create_kem_decryption_op(
91 RandomNumberGenerator& rng, std::string_view params, std::string_view provider = "base") const override;
92};
93
94} // namespace Botan::TLS
95
96#endif
#define BOTAN_DIAGNOSTIC_PUSH
Definition api.h:105
#define BOTAN_DIAGNOSTIC_IGNORE_INHERITED_VIA_DOMINANCE
Definition api.h:107
#define BOTAN_TEST_API
Definition api.h:39
bool check_key(RandomNumberGenerator &rng, bool strong) const override
const std::vector< std::unique_ptr< Private_Key > > & private_keys() const
Definition hybrid_kem.h:119
Hybrid_PrivateKey(const Hybrid_PrivateKey &)=delete
static std::vector< std::unique_ptr< Public_Key > > extract_public_keys(const std::vector< std::unique_ptr< Private_Key > > &private_keys)
Hybrid_PublicKey(std::vector< std::unique_ptr< Public_Key > > public_keys)
Constructor for a list of multiple KEM public keys.
static std::unique_ptr< Hybrid_KEM_PrivateKey > generate_from_group(Group_Params group, RandomNumberGenerator &rng)
bool check_key(RandomNumberGenerator &rng, bool strong) const override
std::unique_ptr< Public_Key > public_key() const override
Hybrid_KEM_PrivateKey(std::vector< std::unique_ptr< Private_Key > > private_keys)
AlgorithmIdentifier algorithm_identifier() const override
std::vector< uint8_t > raw_public_key_bits() const override
Hybrid_KEM_PublicKey(std::vector< std::unique_ptr< Public_Key > > pks)
static std::unique_ptr< Hybrid_KEM_PublicKey > load_for_group(Group_Params group, std::span< const uint8_t > concatenated_public_values)
std::unique_ptr< Private_Key > generate_another(RandomNumberGenerator &rng) const final
std::string algo_name() const override
std::unique_ptr< PK_Ops::KEM_Encryption > create_kem_encryption_op(std::string_view params, std::string_view provider="base") const override
std::vector< uint8_t > public_key_bits() const override