Botan 3.14.1
Crypto and TLS for C&
hpke_kem.cpp
Go to the documentation of this file.
1/*
2* HPKE KEMs
3* (C) 2026 Jack Lloyd
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#include <botan/internal/hpke_kem.h>
9
10#include <botan/ec_apoint.h>
11#include <botan/ec_group.h>
12#include <botan/ec_scalar.h>
13#include <botan/ecdh.h>
14#include <botan/exceptn.h>
15#include <botan/mac.h>
16#include <botan/pubkey.h>
17#include <botan/rng.h>
18#include <botan/internal/concat_util.h>
19#include <botan/internal/fmt.h>
20#include <botan/internal/hkdf.h>
21#include <botan/internal/loadstor.h>
22#include <botan/internal/mem_utils.h>
23#include <algorithm>
24#include <optional>
25#include <type_traits>
26
27#if defined(BOTAN_HAS_X25519)
28 #include <botan/x25519.h>
29#endif
30
31#if defined(BOTAN_HAS_X448)
32 #include <botan/x448.h>
33#endif
34
35#if defined(BOTAN_HAS_ECDSA)
36 #include <botan/ecdsa.h>
37#endif
38
39namespace Botan::HPKE {
40
41namespace {
42
43std::string kem_name(KEM_Id kem) {
44 return kem.to_string().value_or(std::to_string(kem.wire_code()));
45}
46
47} // namespace
48
50 std::span<const uint8_t> suite_id,
51 std::span<const uint8_t> salt,
52 std::string_view label,
53 std::span<const uint8_t> ikm) {
54 // See RFC 9180 Section 4
55 auto prf = MessageAuthenticationCode::create_or_throw(fmt("HMAC({})", hash));
56 const size_t nh = prf->output_length();
57 const HKDF_Extract kdf(std::move(prf));
58
59 const auto labeled_ikm = concat<secure_vector<uint8_t>>(
60 as_span_of_bytes(std::string_view("HPKE-v1")), suite_id, as_span_of_bytes(label), ikm);
61
62 return kdf.derive_key<secure_vector<uint8_t>>(nh, labeled_ikm, salt, std::span<const uint8_t>{});
63}
64
66 std::span<const uint8_t> suite_id,
67 std::span<const uint8_t> prk,
68 std::string_view label,
69 std::span<const uint8_t> info,
70 size_t length) {
71 // See RFC 9180 Section 4
72 BOTAN_ARG_CHECK(length <= 0xFFFF, "HPKE LabeledExpand output length too large");
73
74 if(length == 0) {
75 return {};
76 }
77
79
80 const auto labeled_info = concat<std::vector<uint8_t>>(store_be(static_cast<uint16_t>(length)),
81 as_span_of_bytes(std::string_view("HPKE-v1")),
82 suite_id,
83 as_span_of_bytes(label),
84 info);
85
86 return kdf.derive_key<secure_vector<uint8_t>>(length, prk, std::span<const uint8_t>{}, labeled_info);
87}
88
90 const Botan::Private_Key& /*skS*/,
91 RandomNumberGenerator& /*rng*/) const {
92 // See RFC 9180 Section 7.1.5
93 throw Invalid_Argument(fmt("HPKE KEM {} does not support the Auth modes", kem_name(kem_id())));
94}
95
96secure_vector<uint8_t> KEM_Ops::auth_decap(std::span<const uint8_t> /*enc*/,
97 const Botan::Private_Key& /*skR*/,
98 const Botan::Public_Key& /*pkS*/,
99 RandomNumberGenerator& /*rng*/) const {
100 // See RFC 9180 Section 7.1.5
101 throw Invalid_Argument(fmt("HPKE KEM {} does not support the Auth modes", kem_name(kem_id())));
102}
103
105 const Botan::Private_Key& /*skE*/,
106 RandomNumberGenerator& /*rng*/) const {
107 throw Not_Implemented(fmt("HPKE KEM {} does not support deterministic encapsulation", kem_name(kem_id())));
108}
109
111 const Botan::Private_Key& /*skS*/,
112 const Botan::Private_Key& /*skE*/,
113 RandomNumberGenerator& /*rng*/) const {
114 throw Not_Implemented(fmt("HPKE KEM {} does not support deterministic encapsulation", kem_name(kem_id())));
115}
116
117namespace {
118
119std::vector<uint8_t> kem_suite_id(KEM_Id kem) {
120 // See RFC 9180 Section 4.1
121 const uint16_t code = kem.wire_code();
122 return {'K', 'E', 'M', static_cast<uint8_t>(code >> 8), static_cast<uint8_t>(code & 0xFF)};
123}
124
125enum class DH_Group : uint8_t { P256, P384, P521, X25519, X448 };
126
127/// The private or public key type of an algorithm
128template <bool is_private, typename PrivateT, typename PublicT>
129using select_key_t = std::conditional_t<is_private, PrivateT, PublicT>;
130
131/*
132* Scalar clamping as in RFC 7748 Section 5 (decodeScalar25519 and
133* decodeScalar448). RFC 9180 Section 7.1.2 requires SerializePrivateKey to
134* clamp its output and DeserializePrivateKey to clamp its input.
135*/
136void clamp_scalar(DH_Group group, std::span<uint8_t> sk) {
137 if(group == DH_Group::X25519) {
138 BOTAN_ASSERT_NOMSG(sk.size() == 32);
139 sk[0] &= 248;
140 sk[31] &= 127;
141 sk[31] |= 64;
142 } else if(group == DH_Group::X448) {
143 BOTAN_ASSERT_NOMSG(sk.size() == 56);
144 sk[0] &= 252;
145 sk[55] |= 128;
146 }
147}
148
149class DHKEM final : public KEM_Ops {
150 public:
151 DHKEM(KEM_Id id, DH_Group group, std::string_view hash, std::string_view curve, uint8_t candidate_mask) :
152 KEM_Ops(id),
153 m_group(group),
154 m_hash(hash),
155 m_nh(MessageAuthenticationCode::create_or_throw(fmt("HMAC({})", hash))->output_length()),
156 m_candidate_mask(candidate_mask),
157 m_suite_id(kem_suite_id(id)) {
158 if(!curve.empty()) {
159 m_ec_group = EC_Group::from_name(curve);
160 }
161 }
162
163 // See RFC 9180 Section 7.1
164 bool supports_auth() const override { return true; }
165
166 Encapsulation encap(const Botan::Public_Key& pkR, RandomNumberGenerator& rng) const override {
167 // See RFC 9180 Section 4.1
168 const auto skE = generate_key(rng);
169 return encap_impl(pkR, *skE, rng);
170 }
171
172 Encapsulation encap_with_ephemeral(const Botan::Public_Key& pkR,
173 const Botan::Private_Key& skE,
174 RandomNumberGenerator& rng) const override {
175 BOTAN_ARG_CHECK(is_dhkem_private_key(skE), "Ephemeral key does not match the KEM");
176 return encap_impl(pkR, skE, rng);
177 }
178
179 secure_vector<uint8_t> decap(std::span<const uint8_t> enc,
180 const Botan::Private_Key& skR,
181 RandomNumberGenerator& rng) const override {
182 // See RFC 9180 Section 4.1
183 check_public_encoding(enc);
184
185 const auto pkRm = serialize_public(skR);
186 const auto dh_value = dh(skR, enc, rng);
187 const auto kem_context = concat<std::vector<uint8_t>>(enc, pkRm);
188 return extract_and_expand(dh_value, kem_context);
189 }
190
191 Encapsulation auth_encap(const Botan::Public_Key& pkR,
192 const Botan::Private_Key& skS,
193 RandomNumberGenerator& rng) const override {
194 // See RFC 9180 Section 4.1
195 const auto skE = generate_key(rng);
196 return auth_encap_impl(pkR, skS, *skE, rng);
197 }
198
199 Encapsulation auth_encap_with_ephemeral(const Botan::Public_Key& pkR,
200 const Botan::Private_Key& skS,
201 const Botan::Private_Key& skE,
202 RandomNumberGenerator& rng) const override {
203 BOTAN_ARG_CHECK(is_dhkem_private_key(skE), "Ephemeral key does not match the KEM");
204 return auth_encap_impl(pkR, skS, skE, rng);
205 }
206
207 secure_vector<uint8_t> auth_decap(std::span<const uint8_t> enc,
208 const Botan::Private_Key& skR,
209 const Botan::Public_Key& pkS,
210 RandomNumberGenerator& rng) const override {
211 // See RFC 9180 Section 4.1
212 check_public_encoding(enc);
213
214 const auto pkRm = serialize_public(skR);
215 const auto pkSm = serialize_public(pkS);
216
217 const auto dh_value = concat<secure_vector<uint8_t>>(dh(skR, enc, rng), dh(skR, pkSm, rng));
218
219 const auto kem_context = concat<std::vector<uint8_t>>(enc, pkRm, pkSm);
220 return extract_and_expand(dh_value, kem_context);
221 }
222
223 std::unique_ptr<Botan::Private_Key> generate_key(RandomNumberGenerator& rng) const override {
224 // See RFC 9180 Section 4
225 return this->derive_key_pair(rng.random_vec(kem_id().private_key_length()));
226 }
227
228 std::unique_ptr<Botan::Private_Key> derive_key_pair(std::span<const uint8_t> ikm) const override {
229 // See RFC 9180 Section 7.1.3
230 const size_t nsk = kem_id().private_key_length();
231 // The extract step caps usable ikm entropy at the hash length, and MLS
232 // (RFC 9420 Section 7.4) derives P-521 key pairs from 64 byte node secrets
233 BOTAN_ARG_CHECK(ikm.size() >= std::min(nsk, m_nh), "HPKE DeriveKeyPair ikm too short");
234
235 const auto dkp_prk = labeled_extract(m_hash, m_suite_id, {}, "dkp_prk", ikm);
236
237 switch(m_group) {
238#if defined(BOTAN_HAS_X25519)
239 case DH_Group::X25519: {
240 auto sk = labeled_expand(m_hash, m_suite_id, dkp_prk, "sk", {}, nsk);
241 clamp_scalar(m_group, sk);
242 return std::make_unique<X25519_PrivateKey>(sk);
243 }
244#endif
245#if defined(BOTAN_HAS_X448)
246 case DH_Group::X448: {
247 auto sk = labeled_expand(m_hash, m_suite_id, dkp_prk, "sk", {}, nsk);
248 clamp_scalar(m_group, sk);
249 return std::make_unique<X448_PrivateKey>(sk);
250 }
251#endif
252 case DH_Group::P256:
253 case DH_Group::P384:
254 case DH_Group::P521: {
255 const auto& group = ec_group();
256 for(uint16_t counter = 0; counter != 256; ++counter) {
257 const std::array<uint8_t, 1> counter_octet{static_cast<uint8_t>(counter)};
258 auto candidate = labeled_expand(m_hash, m_suite_id, dkp_prk, "candidate", counter_octet, nsk);
259 candidate[0] &= m_candidate_mask;
260
261 if(const auto scalar = EC_Scalar::deserialize(group, candidate);
262 scalar.has_value() && scalar->is_nonzero()) {
263 return std::make_unique<ECDH_PrivateKey>(group, *scalar);
264 }
265 }
266 // Probability ~2^-256 per candidate for the supported curves
267 throw Internal_Error("HPKE DeriveKeyPair rejection sampling failed");
268 }
269 default:
270 throw Not_Implemented("HPKE DHKEM group not available");
271 }
272 }
273
274 std::unique_ptr<Botan::Public_Key> deserialize_public(std::span<const uint8_t> bytes) const override {
275 // See RFC 9180 Section 7.1.1
276 check_public_encoding(bytes);
277
278 switch(m_group) {
279#if defined(BOTAN_HAS_X25519)
280 case DH_Group::X25519:
281 return std::make_unique<X25519_PublicKey>(bytes);
282#endif
283#if defined(BOTAN_HAS_X448)
284 case DH_Group::X448:
285 return std::make_unique<X448_PublicKey>(bytes);
286#endif
287 case DH_Group::P256:
288 case DH_Group::P384:
289 case DH_Group::P521: {
290 const auto& group = ec_group();
291 // See RFC 9180 Section 7.1.4
292 if(const auto point = EC_AffinePoint::deserialize(group, bytes)) {
293 return std::make_unique<ECDH_PublicKey>(group, *point);
294 }
295 throw Decoding_Error("HPKE DHKEM public key is not a valid point");
296 }
297 default:
298 throw Not_Implemented("HPKE DHKEM group not available");
299 }
300 }
301
302 std::unique_ptr<Botan::Private_Key> deserialize_private(std::span<const uint8_t> bytes) const override {
303 // See RFC 9180 Section 7.1.2
304 if(bytes.size() != kem_id().private_key_length()) {
305 throw Decoding_Error(fmt("Invalid private key length for HPKE KEM {}", kem_name(kem_id())));
306 }
307
308 switch(m_group) {
309#if defined(BOTAN_HAS_X25519)
310 case DH_Group::X25519: {
311 secure_vector<uint8_t> sk(bytes.begin(), bytes.end());
312 clamp_scalar(m_group, sk);
313 return std::make_unique<X25519_PrivateKey>(sk);
314 }
315#endif
316#if defined(BOTAN_HAS_X448)
317 case DH_Group::X448: {
318 secure_vector<uint8_t> sk(bytes.begin(), bytes.end());
319 clamp_scalar(m_group, sk);
320 return std::make_unique<X448_PrivateKey>(sk);
321 }
322#endif
323 case DH_Group::P256:
324 case DH_Group::P384:
325 case DH_Group::P521: {
326 const auto& group = ec_group();
327 if(const auto scalar = EC_Scalar::deserialize(group, bytes);
328 scalar.has_value() && scalar->is_nonzero()) {
329 return std::make_unique<ECDH_PrivateKey>(group, *scalar);
330 }
331 throw Decoding_Error("HPKE DHKEM private key is out of range");
332 }
333 default:
334 throw Not_Implemented("HPKE DHKEM group not available");
335 }
336 }
337
338 std::vector<uint8_t> serialize_public(const Botan::Public_Key& key) const override {
339 // See RFC 9180 Section 7.1.1
340 if(const auto* ecdh = dynamic_cast<const ECDH_PublicKey*>(&key)) {
341 // HPKE requires uncompressed encoding for NIST curves
342 return ecdh->public_value(EC_Point_Format::Uncompressed);
343 }
344 auto bytes = key.raw_public_key_bits();
345 BOTAN_ASSERT_NOMSG(bytes.size() == kem_id().public_key_length());
346 return bytes;
347 }
348
349 secure_vector<uint8_t> serialize_private(const Botan::Private_Key& key) const override {
350 // See RFC 9180 Section 7.1.2
351 auto bytes = key.raw_private_key_bits();
352 BOTAN_ASSERT_NOMSG(bytes.size() == kem_id().private_key_length());
353 // Keys adopted via from_key may hold an unclamped scalar
354 clamp_scalar(m_group, bytes);
355 return bytes;
356 }
357
358 std::unique_ptr<Botan::Public_Key> adopt_public(std::unique_ptr<Botan::Public_Key> key) const override {
359 return adopt_key(std::move(key));
360 }
361
362 std::unique_ptr<Botan::Private_Key> adopt_private(std::unique_ptr<Botan::Private_Key> key) const override {
363 return adopt_key(std::move(key));
364 }
365
366 private:
367 /*
368 * Accept a key if its type matches this KEM's group. KeyT is either
369 * Botan::Public_Key or Botan::Private_Key, and selects which of the
370 * algorithm's key types is required.
371 */
372 template <typename KeyT>
373 std::unique_ptr<KeyT> adopt_key(std::unique_ptr<KeyT> key) const {
374 constexpr bool is_private = std::is_same_v<KeyT, Botan::Private_Key>;
375
376 switch(m_group) {
377#if defined(BOTAN_HAS_X25519)
378 case DH_Group::X25519:
379 if(dynamic_cast<const select_key_t<is_private, X25519_PrivateKey, X25519_PublicKey>*>(key.get()) !=
380 nullptr) {
381 return key;
382 }
383 break;
384#endif
385#if defined(BOTAN_HAS_X448)
386 case DH_Group::X448:
387 if(dynamic_cast<const select_key_t<is_private, X448_PrivateKey, X448_PublicKey>*>(key.get()) !=
388 nullptr) {
389 return key;
390 }
391 break;
392#endif
393 case DH_Group::P256:
394 case DH_Group::P384:
395 case DH_Group::P521:
396 if(const auto* ecdh =
397 dynamic_cast<const select_key_t<is_private, ECDH_PrivateKey, ECDH_PublicKey>*>(key.get())) {
398 check_ec_group(ecdh->domain());
399 return key;
400 }
401#if defined(BOTAN_HAS_ECDSA)
402 /*
403 * Keys with the id-ecPublicKey OID, as found in X.509 and PKCS
404 * #8, load as ECDSA keys; RFC 3279 Section 2.3.5 allows using that
405 * OID for ECDH, so accept ECDSA and convert.
406 */
407 if(const auto* ecdsa =
408 dynamic_cast<const select_key_t<is_private, ECDSA_PrivateKey, ECDSA_PublicKey>*>(key.get())) {
409 check_ec_group(ecdsa->domain());
410 if constexpr(is_private) {
411 return std::make_unique<ECDH_PrivateKey>(ec_group(), ecdsa->_private_key());
412 } else {
413 return std::make_unique<ECDH_PublicKey>(ec_group(), ecdsa->public_ec_point());
414 }
415 }
416#endif
417 break;
418 default:
419 break;
420 }
421
422 throw Invalid_Argument(
423 fmt("Key of type {} cannot be used with HPKE KEM {}", key->algo_name(), kem_name(kem_id())));
424 }
425
426 const EC_Group& ec_group() const {
427 BOTAN_ASSERT_NOMSG(m_ec_group.has_value());
428 return *m_ec_group;
429 }
430
431 void check_ec_group(const EC_Group& group) const {
432 if(group != ec_group()) {
433 throw Invalid_Argument(fmt("EC key on curve {} cannot be used with HPKE KEM {}",
434 group.get_curve_oid().to_formatted_string(),
435 kem_name(kem_id())));
436 }
437 }
438
439 /// True if the key is of the type this KEM's operations use directly
440 bool is_dhkem_private_key(const Botan::Private_Key& key) const {
441 switch(m_group) {
442#if defined(BOTAN_HAS_X25519)
443 case DH_Group::X25519:
444 return dynamic_cast<const X25519_PrivateKey*>(&key) != nullptr;
445#endif
446#if defined(BOTAN_HAS_X448)
447 case DH_Group::X448:
448 return dynamic_cast<const X448_PrivateKey*>(&key) != nullptr;
449#endif
450 case DH_Group::P256:
451 case DH_Group::P384:
452 case DH_Group::P521: {
453 const auto* ecdh = dynamic_cast<const ECDH_PrivateKey*>(&key);
454 return ecdh != nullptr && ecdh->domain() == ec_group();
455 }
456 default:
457 return false;
458 }
459 }
460
461 bool is_nist_curve() const {
462 return m_group == DH_Group::P256 || m_group == DH_Group::P384 || m_group == DH_Group::P521;
463 }
464
465 /*
466 * Checks the length of a serialized public key, and for the NIST curves
467 * that it uses the uncompressed encoding (RFC 9180 Section 7.1.1). Point
468 * validation is left to deserialize_public or the key agreement.
469 */
470 void check_public_encoding(std::span<const uint8_t> bytes) const {
471 if(bytes.size() != kem_id().public_key_length()) {
472 throw Decoding_Error(fmt("Invalid public key length for HPKE KEM {}", kem_name(kem_id())));
473 }
474 if(is_nist_curve() && bytes[0] != 0x04) {
475 throw Decoding_Error("HPKE requires uncompressed EC point encoding");
476 }
477 }
478
479 Encapsulation encap_impl(const Botan::Public_Key& pkR,
480 const Botan::Private_Key& skE,
481 RandomNumberGenerator& rng) const {
482 // See RFC 9180 Section 4.1
483 const auto pkRm = serialize_public(pkR);
484 const auto dh_value = dh(skE, pkRm, rng);
485
486 auto enc = serialize_public(skE);
487 const auto kem_context = concat<std::vector<uint8_t>>(enc, pkRm);
488 auto shared_secret = extract_and_expand(dh_value, kem_context);
489 return {std::move(enc), std::move(shared_secret)};
490 }
491
492 Encapsulation auth_encap_impl(const Botan::Public_Key& pkR,
493 const Botan::Private_Key& skS,
494 const Botan::Private_Key& skE,
495 RandomNumberGenerator& rng) const {
496 // See RFC 9180 Section 4.1
497 const auto pkRm = serialize_public(pkR);
498 const auto pkSm = serialize_public(skS);
499 auto enc = serialize_public(skE);
500
501 const auto dh_value = concat<secure_vector<uint8_t>>(dh(skE, pkRm, rng), dh(skS, pkRm, rng));
502
503 const auto kem_context = concat<std::vector<uint8_t>>(enc, pkRm, pkSm);
504 auto shared_secret = extract_and_expand(dh_value, kem_context);
505 return {std::move(enc), std::move(shared_secret)};
506 }
507
508 /*
509 * The key agreement operations perform the peer key validation that
510 * RFC 9180 Section 7.1.4 requires: ECDH rejects encodings that are not
511 * a point on the curve, or are the identity, with Decoding_Error, while
512 * X25519 and X448 reject low order points by checking for an all-zero
513 * shared secret (RFC 7748 Sections 6.1 and 6.2), throwing Invalid_Argument.
514 */
515 secure_vector<uint8_t> dh(const Botan::Private_Key& sk,
516 std::span<const uint8_t> peer,
517 RandomNumberGenerator& rng) const {
518 // See RFC 9180 Section 4.1
519 const PK_Key_Agreement ka(sk, rng, "Raw");
520 return ka.derive_key(0, peer).bits_of();
521 }
522
523 secure_vector<uint8_t> extract_and_expand(std::span<const uint8_t> dh_value,
524 std::span<const uint8_t> kem_context) const {
525 // See RFC 9180 Section 4.1
526 const auto eae_prk = labeled_extract(m_hash, m_suite_id, {}, "eae_prk", dh_value);
527 return labeled_expand(
528 m_hash, m_suite_id, eae_prk, "shared_secret", kem_context, kem_id().shared_secret_length());
529 }
530
531 DH_Group m_group;
532 std::string m_hash;
533 size_t m_nh;
534 uint8_t m_candidate_mask;
535 std::vector<uint8_t> m_suite_id;
536 std::optional<EC_Group> m_ec_group;
537};
538
539bool hmac_available(std::string_view hash) {
540 return MessageAuthenticationCode::create(fmt("HMAC({})", hash)) != nullptr;
541}
542
543} // namespace
544
545std::unique_ptr<const KEM_Ops> KEM_Ops::create(KEM_Id kem) {
546 // See RFC 9180 Sections 7.1 and 7.1.3
547 switch(kem.code()) {
549 if(EC_Group::supports_named_group("secp256r1") && hmac_available("SHA-256")) {
550 return std::make_unique<DHKEM>(kem, DH_Group::P256, "SHA-256", "secp256r1", 0xFF);
551 }
552 break;
553
555 if(EC_Group::supports_named_group("secp384r1") && hmac_available("SHA-384")) {
556 return std::make_unique<DHKEM>(kem, DH_Group::P384, "SHA-384", "secp384r1", 0xFF);
557 }
558 break;
559
561 if(EC_Group::supports_named_group("secp521r1") && hmac_available("SHA-512")) {
562 return std::make_unique<DHKEM>(kem, DH_Group::P521, "SHA-512", "secp521r1", 0x01);
563 }
564 break;
565
567#if defined(BOTAN_HAS_X25519)
568 if(hmac_available("SHA-256")) {
569 return std::make_unique<DHKEM>(kem, DH_Group::X25519, "SHA-256", "", 0x00);
570 }
571#endif
572 break;
573
575#if defined(BOTAN_HAS_X448)
576 if(hmac_available("SHA-512")) {
577 return std::make_unique<DHKEM>(kem, DH_Group::X448, "SHA-512", "", 0x00);
578 }
579#endif
580 break;
581
582 default:
583 break;
584 }
585
586 throw Not_Implemented(fmt("HPKE KEM {} is not available in this build", kem_name(kem)));
587}
588
589} // namespace Botan::HPKE
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:82
#define BOTAN_ARG_CHECK(expr, msg)
Definition assert.h:33
static std::optional< EC_AffinePoint > deserialize(const EC_Group &group, std::span< const uint8_t > bytes)
static bool supports_named_group(std::string_view name)
Definition ec_group.cpp:473
static std::optional< EC_Scalar > deserialize(const EC_Group &group, std::span< const uint8_t > bytes)
constexpr KEM_Code code() const
Definition hpke.h:83
constexpr uint16_t wire_code() const
Definition hpke.h:85
virtual secure_vector< uint8_t > auth_decap(std::span< const uint8_t > enc, const Botan::Private_Key &skR, const Botan::Public_Key &pkS, RandomNumberGenerator &rng) const
Definition hpke_kem.cpp:96
virtual Encapsulation auth_encap(const Botan::Public_Key &pkR, const Botan::Private_Key &skS, RandomNumberGenerator &rng) const
Only supported if supports_auth(); the default implementations throw.
Definition hpke_kem.cpp:89
static std::unique_ptr< const KEM_Ops > create(KEM_Id kem)
Definition hpke_kem.cpp:545
virtual Encapsulation encap_with_ephemeral(const Botan::Public_Key &pkR, const Botan::Private_Key &skE, RandomNumberGenerator &rng) const
Definition hpke_kem.cpp:104
KEM_Id kem_id() const
Definition hpke_kem.h:65
virtual Encapsulation auth_encap_with_ephemeral(const Botan::Public_Key &pkR, const Botan::Private_Key &skS, const Botan::Private_Key &skE, RandomNumberGenerator &rng) const
Definition hpke_kem.cpp:110
T derive_key(size_t key_len, const uint8_t secret[], size_t secret_len, const uint8_t salt[], size_t salt_len, const uint8_t label[]=nullptr, size_t label_len=0) const
Definition kdf.h:93
static std::unique_ptr< MessageAuthenticationCode > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition mac.cpp:142
static std::unique_ptr< MessageAuthenticationCode > create(std::string_view algo_spec, std::string_view provider="")
Definition mac.cpp:51
virtual secure_vector< uint8_t > raw_private_key_bits() const
Definition pk_keys.cpp:89
virtual std::vector< uint8_t > raw_public_key_bits() const =0
secure_vector< uint8_t > labeled_extract(std::string_view hash, std::span< const uint8_t > suite_id, std::span< const uint8_t > salt, std::string_view label, std::span< const uint8_t > ikm)
Definition hpke_kem.cpp:49
secure_vector< uint8_t > labeled_expand(std::string_view hash, std::span< const uint8_t > suite_id, std::span< const uint8_t > prk, std::string_view label, std::span< const uint8_t > info, size_t length)
Definition hpke_kem.cpp:65
std::span< const uint8_t > as_span_of_bytes(const char *s, size_t len)
Definition mem_utils.h:59
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53
constexpr auto concat(Rs &&... ranges)
Definition concat_util.h:95
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:128
constexpr auto store_be(ParamTs &&... params)
Definition loadstor.h:745