Botan 3.14.1
Crypto and TLS for C&
hpke.h
Go to the documentation of this file.
1/*
2* (C) 2026 Jack Lloyd
3*
4* Botan is released under the Simplified BSD License (see license.txt)
5*/
6
7#ifndef BOTAN_HPKE_H_
8#define BOTAN_HPKE_H_
9
10#include <botan/secmem.h>
11#include <botan/types.h>
12#include <memory>
13#include <optional>
14#include <span>
15#include <string>
16#include <vector>
17
18namespace Botan {
19
20class Public_Key;
21class Private_Key;
23
24} // namespace Botan
25
26namespace Botan::HPKE {
27
28class Private_Key;
29class Sender_Context;
31
32/**
33* HPKE KEM identifiers
34*
35* These codepoints match the IANA "HPKE KEM Identifiers" registry
36* established by RFC 9180 Section 7.1.
37*/
38enum class KEM_Code : uint16_t /* NOLINT(*-enum-size) */ {
39 DHKEM_P256 = 0x0010, // DHKEM(P-256, HKDF-SHA256)
40 DHKEM_P384 = 0x0011, // DHKEM(P-384, HKDF-SHA384)
41 DHKEM_P521 = 0x0012, // DHKEM(P-521, HKDF-SHA512)
42 DHKEM_X25519 = 0x0020, // DHKEM(X25519, HKDF-SHA256)
43 DHKEM_X448 = 0x0021, // DHKEM(X448, HKDF-SHA512)
44};
45
46/**
47* HPKE KDF identifiers (RFC 9180 Section 7.2)
48*/
49enum class KDF_Code : uint16_t /* NOLINT(*-enum-size) */ {
50 HKDF_SHA256 = 0x0001,
51 HKDF_SHA384 = 0x0002,
52 HKDF_SHA512 = 0x0003,
53};
54
55/**
56* HPKE AEAD identifiers (RFC 9180 Section 7.3)
57*/
58enum class AEAD_Code : uint16_t {
59 AES_128_GCM = 0x0001,
60 AES_256_GCM = 0x0002,
62 ExportOnly = 0xFFFF,
63};
64
65/**
66* Identifies the KEM used by an HPKE ciphersuite
67*
68* This may hold any 16-bit codepoint, including values unknown to the
69* library (as may be encountered eg when parsing an ECHConfigList);
70* is_known() and is_available() distinguish what can actually be used.
71*/
72class BOTAN_PUBLIC_API(3, 14) KEM_Id final {
73 public:
74 using enum KEM_Code;
75
76 // NOLINTNEXTLINE(*-explicit-conversions,*-explicit-constructor)
77 constexpr KEM_Id(KEM_Code code) : m_code(code) {}
78
79 // Any codepoint is representable, including ones unknown to this library
80 // NOLINTNEXTLINE(*-explicit-conversions,*-explicit-constructor,clang-analyzer-optin.core.EnumCastOutOfRange)
81 constexpr KEM_Id(uint16_t code) : m_code(static_cast<KEM_Code>(code)) {}
82
83 constexpr KEM_Code code() const { return m_code; }
84
85 constexpr uint16_t wire_code() const { return static_cast<uint16_t>(m_code); }
86
87 constexpr bool operator==(const KEM_Id& other) const { return m_code == other.m_code; }
88
89 constexpr bool operator==(KEM_Code code) const { return m_code == code; }
90
91 /// True if this codepoint is known to this version of the library
92 constexpr bool is_known() const {
93 switch(m_code) {
99 return true;
100 }
101 return false;
102 }
103
104 /// True if the algorithms this KEM requires are available in this build
105 bool is_available() const;
106
107 constexpr bool is_dhkem() const {
108 // See RFC 9180 Section 7.1
109 return m_code == KEM_Code::DHKEM_P256 || m_code == KEM_Code::DHKEM_P384 || m_code == KEM_Code::DHKEM_P521 ||
110 m_code == KEM_Code::DHKEM_X25519 || m_code == KEM_Code::DHKEM_X448;
111 }
112
113 /// Only the DH-based KEMs support the Auth and AuthPSK modes
114 /// See RFC 9180 Section 7.1
115 constexpr bool supports_auth_modes() const { return is_dhkem(); }
116
117 /// Return the constant Nsecret from RFC 9180 Section 7.1, throws for invalid code points
118 size_t shared_secret_length() const;
119
120 /// Return the constant Nenc from RFC 9180 Section 7.1, throws for invalid code points
121 size_t encapsulation_length() const;
122
123 /// Return the constant Npk from RFC 9180 Section 7.1, throws for invalid code points
124 size_t public_key_length() const;
125
126 /// Return the constant Nsk from RFC 9180 Section 7.1, throws for invalid code points
127 size_t private_key_length() const;
128
129 /// Returns std::nullopt for unknown codepoints
130 std::optional<std::string> to_string() const;
131
132 private:
133 KEM_Code m_code;
134};
135
136/**
137* Identifies the KDF used by an HPKE ciphersuite
138*/
139class BOTAN_PUBLIC_API(3, 14) KDF_Id final {
140 public:
141 using enum KDF_Code;
142
143 // NOLINTNEXTLINE(*-explicit-conversions,*-explicit-constructor)
144 constexpr KDF_Id(KDF_Code code) : m_code(code) {}
145
146 // Any codepoint is representable, including ones unknown to this library
147 // NOLINTNEXTLINE(*-explicit-conversions,*-explicit-constructor,clang-analyzer-optin.core.EnumCastOutOfRange)
148 constexpr KDF_Id(uint16_t code) : m_code(static_cast<KDF_Code>(code)) {}
149
150 constexpr KDF_Code code() const { return m_code; }
151
152 constexpr uint16_t wire_code() const { return static_cast<uint16_t>(m_code); }
153
154 constexpr bool operator==(const KDF_Id& other) const { return m_code == other.m_code; }
155
156 constexpr bool operator==(KDF_Code code) const { return m_code == code; }
157
158 constexpr bool is_known() const {
159 switch(m_code) {
163 return true;
164 }
165 return false;
166 }
167
168 bool is_available() const;
169
170 /// The KDF output length Nh; throws Invalid_State for unknown codepoints
171 /// See RFC 9180 Section 7.2
172 size_t output_length() const;
173
174 std::optional<std::string> to_string() const;
175
176 private:
177 KDF_Code m_code;
178};
179
180/**
181* Identifies the AEAD used by an HPKE ciphersuite
182*/
183class BOTAN_PUBLIC_API(3, 14) AEAD_Id final {
184 public:
185 using enum AEAD_Code;
186
187 // NOLINTNEXTLINE(*-explicit-conversions,*-explicit-constructor)
188 constexpr AEAD_Id(AEAD_Code code) : m_code(code) {}
189
190 // Any codepoint is representable, including ones unknown to this library
191 // NOLINTNEXTLINE(*-explicit-conversions,*-explicit-constructor,clang-analyzer-optin.core.EnumCastOutOfRange)
192 constexpr AEAD_Id(uint16_t code) : m_code(static_cast<AEAD_Code>(code)) {}
193
194 constexpr AEAD_Code code() const { return m_code; }
195
196 constexpr uint16_t wire_code() const { return static_cast<uint16_t>(m_code); }
197
198 constexpr bool operator==(const AEAD_Id& other) const { return m_code == other.m_code; }
199
200 constexpr bool operator==(AEAD_Code code) const { return m_code == code; }
201
202 constexpr bool is_known() const {
203 switch(m_code) {
208 return true;
209 }
210 return false;
211 }
212
213 bool is_available() const;
214
215 /// An export-only suite creates contexts usable only for export_secret
216 /// See RFC 9180 Section 5.3
217 constexpr bool is_export_only() const { return m_code == AEAD_Code::ExportOnly; }
218
219 /// Return the constant Nk from RFC 9180 Section 7.3, throws for invalid code points
220 size_t key_length() const;
221
222 /// Return the constant Nn from RFC 9180 Section 7.3, throws for invalid code points
223 size_t nonce_length() const;
224
225 /// Return the constant Nt from RFC 9180 Section 7.3, throws for invalid code points
226 size_t tag_length() const;
227
228 std::optional<std::string> to_string() const;
229
230 private:
231 AEAD_Code m_code;
232};
233
234/**
235* An HPKE ciphersuite: the triple of KEM, KDF and AEAD
236* See RFC 9180 Section 4
237*
238* This is a plain value type; it may hold any combination of codepoints,
239* including unknown ones. Availability is checked when a context is created.
240*/
241class BOTAN_PUBLIC_API(3, 14) Suite final {
242 public:
243 constexpr Suite(KEM_Id kem, KDF_Id kdf, AEAD_Id aead) : m_kem(kem), m_kdf(kdf), m_aead(aead) {}
244
245 constexpr KEM_Id kem() const { return m_kem; }
246
247 constexpr KDF_Id kdf() const { return m_kdf; }
248
249 constexpr AEAD_Id aead() const { return m_aead; }
250
251 constexpr bool operator==(const Suite& other) const {
252 return m_kem == other.m_kem && m_kdf == other.m_kdf && m_aead == other.m_aead;
253 }
254
255 constexpr bool is_known() const { return m_kem.is_known() && m_kdf.is_known() && m_aead.is_known(); }
256
257 bool is_available() const { return m_kem.is_available() && m_kdf.is_available() && m_aead.is_available(); }
258
259 constexpr bool is_export_only() const { return m_aead.is_export_only(); }
260
261 /// Bytes added to each plaintext when sealed (the AEAD tag length)
262 /// See RFC 9180 Section 5.2
263 /// Throws Invalid_State for an export-only suite, which cannot seal
264 size_t ciphertext_overhead() const { return m_aead.tag_length(); }
265
266 std::optional<std::string> to_string() const;
267
268 private:
269 KEM_Id m_kem;
270 KDF_Id m_kdf;
271 AEAD_Id m_aead;
272};
273
274/**
275* An HPKE public key
276*
277* This is a value type (cheap to copy) wrapping an asymmetric key that
278* has been checked against a particular HPKE KEM: its algorithm (and, for
279* the NIST curves, its group) matches the KEM, and a key deserialized from
280* the wire is well formed, which for the NIST curves includes being a point
281* on the curve. One check is deferred: RFC 9180 Section 7.1.4 specifies the
282* rejection of low order X25519/X448 points in terms of the Diffie-Hellman
283* output, so such a key can be constructed, but any context setup using it
284* throws Invalid_Argument. Holding a Public_Key therefore does not by itself
285* establish that an untrusted peer's key is acceptable.
286*
287* It has no inheritance relationship with Botan::Public_Key or with
288* HPKE::Private_Key.
289*/
290class BOTAN_PUBLIC_API(3, 14) Public_Key final {
291 public:
292 /**
293 * DeserializePublicKey from RFC 9180 Section 7.1.1
294 *
295 * Accepts exactly the wire format the KEM defines (raw bytes for
296 * X25519/X448, an uncompressed SEC1 point for the NIST curves).
297 * Throws Decoding_Error if the length or encoding is wrong, or if a
298 * NIST curve point is not on the curve. Low order X25519/X448 points
299 * are not detected here; see the class description.
300 */
301 static Public_Key deserialize(KEM_Id kem, std::span<const uint8_t> bytes);
302
303 /**
304 * Adopt an existing key for use with HPKE
305 *
306 * For the NIST curves both ECDH and ECDSA keys are accepted, the latter
307 * being how keys with the id-ecPublicKey OID (eg from an X.509 certificate)
308 * are loaded; an ECDSA key is converted, so underlying() always returns an
309 * ECDH key. Keys of other EC algorithms (SM2, ECGDSA, ...) are not accepted.
310 *
311 * Throws Invalid_Argument unless the algorithm (and, for the NIST curves,
312 * the group) matches the KEM.
313 */
314 static Public_Key from_key(KEM_Id kem, std::unique_ptr<Botan::Public_Key> key);
315
316 KEM_Id kem() const;
317
318 /// SerializePublicKey from RFC 9180 Section 7.1.1
319 std::vector<uint8_t> serialize() const;
320
321 /**
322 * Access the wrapped key, eg for encoding as a X.509 SubjectPublicKeyInfo
323 *
324 * For the NIST curves this is an ECDH key, which encodes with the
325 * id-ecDH algorithm identifier.
326 */
327 const Botan::Public_Key& underlying() const;
328
329 friend bool operator==(const Public_Key& a, const Public_Key& b) {
330 return a.kem() == b.kem() && a.serialize() == b.serialize();
331 }
332
333 private:
334 class Data;
335
336 explicit Public_Key(std::shared_ptr<const Data> data) : m_data(std::move(data)) {}
337
338 friend class HPKE::Private_Key;
341
342 std::shared_ptr<const Data> m_data;
343};
344
345/**
346* An HPKE private key
347*
348* This is a value type (cheap to copy) wrapping an asymmetric key that
349* has been validated for use with a particular HPKE KEM. It has no
350* inheritance relationship with Botan::Private_Key or with HPKE::Public_Key;
351* the corresponding public key is obtained with public_key().
352*/
353class BOTAN_PUBLIC_API(3, 14) Private_Key final {
354 public:
355 /// GenerateKeyPair from RFC 9180 Section 4
356 static Private_Key generate(KEM_Id kem, RandomNumberGenerator& rng);
357
358 /**
359 * DeriveKeyPair from RFC 9180 Section 7.1.3
360 *
361 * Deterministically derives a key pair from input keying material,
362 * which must be full-entropy secret data of at least Nsk bytes; as
363 * an exception DHKEM(P-521) accepts 64 bytes, since MLS (RFC 9420 Section 7.4)
364 * derives P-521 key pairs from 64-byte node secrets.
365 */
366 static Private_Key derive(KEM_Id kem, std::span<const uint8_t> ikm);
367
368 /**
369 * DeserializePrivateKey from RFC 9180 Section 7.1.2
370 *
371 * Accepts Nsk raw bytes. The scalar is range-checked for the NIST
372 * curves, and clamped (RFC 7748 Section 5) for X25519 and X448.
373 */
374 static Private_Key deserialize(KEM_Id kem, std::span<const uint8_t> bytes);
375
376 /**
377 * Adopt an existing key (eg loaded from PKCS #8) for use with HPKE
378 *
379 * As for Public_Key::from_key, ECDSA keys on the NIST curves are accepted
380 * and converted to ECDH, while other EC algorithms are rejected. Throws
381 * Invalid_Argument unless the key's algorithm (and, for the NIST curves,
382 * its group) matches the KEM.
383 */
384 static Private_Key from_key(KEM_Id kem, std::unique_ptr<Botan::Private_Key> key);
385
386 KEM_Id kem() const;
387
388 /// The corresponding public key
389 Public_Key public_key() const;
390
391 /**
392 * SerializePrivateKey from RFC 9180 Section 7.1.2
393 *
394 * For X25519 and X448 the output is clamped, as RFC 9180 Section 7.1.2
395 * requires.
396 */
398
399 /**
400 * Access the wrapped key, eg for encoding as PKCS #8
401 *
402 * For the NIST curves this is an ECDH key, which encodes with the
403 * id-ecDH algorithm identifier.
404 */
405 const Botan::Private_Key& underlying() const;
406
407 private:
408 class Data;
409
410 explicit Private_Key(std::shared_ptr<const Data> data) : m_data(std::move(data)) {}
411
414
415 std::shared_ptr<const Data> m_data;
416};
417
418/**
419* A pre-shared key plus identity, for the PSK and AuthPSK modes
420*
421* RFC 9180 Section 5.1 requires both fields to be non-empty, and (following the
422* recommendation of its Section 9.5) the PSK must be at least 32 bytes. Section
423* 9.5 further recommends a PSK of at least Nh bytes, the output length of the
424* suite's KDF; that is not enforced, as a PSK is not bound to a suite.
425*/
426class BOTAN_PUBLIC_API(3, 14) PSK final {
427 public:
428 PSK(std::span<const uint8_t> psk, std::span<const uint8_t> psk_id);
429
430 std::span<const uint8_t> secret() const { return m_psk; }
431
432 std::span<const uint8_t> identity() const { return m_psk_id; }
433
434 private:
436 std::vector<uint8_t> m_psk_id;
437};
438
439/// The four HPKE modes, with their codepoints from RFC 9180 Section 5
440enum class Mode : uint8_t {
441 Base = 0x00,
442 PSK = 0x01,
443 Auth = 0x02,
444 AuthPSK = 0x03,
445};
446
447namespace detail {
448
449class Context_Data;
450
451} // namespace detail
452
453/**
454* HPKE sender (encryption) context
455*
456* Created by one of the setup_* factories, each corresponding to an
457* RFC 9180 setup function (SetupBaseS, SetupPSKS, SetupAuthS, SetupAuthPSKS).
458*
459* All factories throw Invalid_Argument if the recipient (or sender identity)
460* key does not match the suite's KEM, if the recipient key is a low order
461* X25519/X448 point, or for an auth mode if the KEM does not support sender
462* authentication. They throw Not_Implemented or Lookup_Error if the suite is
463* not available in this build.
464*/
466 public:
467 static Sender_Context setup_base(const Suite& suite,
468 const Public_Key& recipient_key,
470 std::span<const uint8_t> info = {});
471
472 static Sender_Context setup_psk(const Suite& suite,
473 const Public_Key& recipient_key,
475 const PSK& psk,
476 std::span<const uint8_t> info = {});
477
478 static Sender_Context setup_auth(const Suite& suite,
479 const Public_Key& recipient_key,
480 const Private_Key& sender_identity_key,
482 std::span<const uint8_t> info = {});
483
485 const Public_Key& recipient_key,
486 const Private_Key& sender_identity_key,
488 const PSK& psk,
489 std::span<const uint8_t> info = {});
490
494 Sender_Context& operator=(Sender_Context&&) noexcept;
496
497 /// The KEM encapsulation ("enc") to be transmitted to the recipient
498 const std::vector<uint8_t>& encapsulated_key() const;
499
500 /**
501 * Encrypt a message to the recipient, using the next sequence number
502 *
503 * Throws Invalid_State for an export-only suite, or if the message
504 * limit has been reached.
505 */
506 std::vector<uint8_t> seal(std::span<const uint8_t> aad, std::span<const uint8_t> ptext);
507
508 /**
509 * Secret export (RFC 9180 Section 5.3)
510 *
511 * @p length must be at most 255 times the KDF output length
512 */
513 secure_vector<uint8_t> export_secret(std::span<const uint8_t> exporter_context, size_t length) const;
514
515 /// The sequence number the next call to seal() will use
516 uint64_t next_sequence() const;
517
518 Mode mode() const;
519
520 Suite suite() const;
521
522 private:
523 explicit Sender_Context(std::unique_ptr<detail::Context_Data> data);
524
525 static Sender_Context setup(Mode mode,
526 const Suite& suite,
527 const Public_Key& recipient_key,
528 const Private_Key* sender_identity_key,
529 const PSK* psk,
531 std::span<const uint8_t> info);
532
533 std::unique_ptr<detail::Context_Data> m_data;
534};
535
536/**
537* HPKE recipient (decryption) context
538*
539* Created by one of the setup_* factories, each corresponding to an
540* RFC 9180 setup function (SetupBaseR, SetupPSKR, SetupAuthR, SetupAuthPSKR).
541*
542* The factories throw as described for Sender_Context, and additionally
543* throw Decoding_Error if the encapsulated key is malformed (wrong length
544* or encoding, or not a point on the curve), or Invalid_Argument if it or
545* the sender identity key is a low order X25519/X448 point.
546*/
548 public:
550 const Private_Key& recipient_key,
551 std::span<const uint8_t> enc,
553 std::span<const uint8_t> info = {});
554
556 const Private_Key& recipient_key,
557 std::span<const uint8_t> enc,
559 const PSK& psk,
560 std::span<const uint8_t> info = {});
561
563 const Private_Key& recipient_key,
564 std::span<const uint8_t> enc,
565 const Public_Key& sender_identity_key,
567 std::span<const uint8_t> info = {});
568
570 const Private_Key& recipient_key,
571 std::span<const uint8_t> enc,
572 const Public_Key& sender_identity_key,
574 const PSK& psk,
575 std::span<const uint8_t> info = {});
576
580 Recipient_Context& operator=(Recipient_Context&&) noexcept;
582
583 /**
584 * Decrypt a message, using the next sequence number
585 *
586 * Throws Invalid_Authentication_Tag for truncated or unauthentic ciphertexts,
587 * or Invalid_State for export-only suites or an exhausted sequence counter.
588 * The sequence number is consumed only if decryption succeeds.
589 */
590 secure_vector<uint8_t> open(std::span<const uint8_t> aad, std::span<const uint8_t> ctext);
591
592 /**
593 * Decrypt the message with the given sequence number
594 *
595 * This does not read or modify the sequence counter used by open(),
596 * in order to support out-of-order transports.
597 */
598 secure_vector<uint8_t> open_at_sequence(uint64_t seq,
599 std::span<const uint8_t> aad,
600 std::span<const uint8_t> ctext);
601
602 /**
603 * Secret export (RFC 9180 Section 5.3)
604 *
605 * @p length must be at most 255 times the KDF output length
606 */
607 secure_vector<uint8_t> export_secret(std::span<const uint8_t> exporter_context, size_t length) const;
608
609 /**
610 * The sequence number the next call to open() will use
611 */
612 uint64_t next_sequence() const;
613
614 Mode mode() const;
615
616 Suite suite() const;
617
618 private:
619 explicit Recipient_Context(std::unique_ptr<detail::Context_Data> data);
620
621 static Recipient_Context setup(Mode mode,
622 const Suite& suite,
623 const Private_Key& recipient_key,
624 std::span<const uint8_t> enc,
625 const Public_Key* sender_identity_key,
626 const PSK* psk,
628 std::span<const uint8_t> info);
629
630 std::unique_ptr<detail::Context_Data> m_data;
631};
632
633} // namespace Botan::HPKE
634
635#endif
#define BOTAN_PUBLIC_API(maj, min)
Definition api.h:21
constexpr bool operator==(const AEAD_Id &other) const
Definition hpke.h:198
constexpr bool is_known() const
Definition hpke.h:202
constexpr bool operator==(AEAD_Code code) const
Definition hpke.h:200
constexpr uint16_t wire_code() const
Definition hpke.h:196
constexpr AEAD_Id(AEAD_Code code)
Definition hpke.h:188
constexpr AEAD_Id(uint16_t code)
Definition hpke.h:192
constexpr AEAD_Code code() const
Definition hpke.h:194
constexpr bool is_export_only() const
Definition hpke.h:217
constexpr KDF_Id(KDF_Code code)
Definition hpke.h:144
constexpr bool is_known() const
Definition hpke.h:158
constexpr KDF_Code code() const
Definition hpke.h:150
constexpr bool operator==(const KDF_Id &other) const
Definition hpke.h:154
constexpr bool operator==(KDF_Code code) const
Definition hpke.h:156
constexpr uint16_t wire_code() const
Definition hpke.h:152
constexpr KDF_Id(uint16_t code)
Definition hpke.h:148
constexpr bool operator==(KEM_Code code) const
Definition hpke.h:89
constexpr bool is_known() const
True if this codepoint is known to this version of the library.
Definition hpke.h:92
constexpr KEM_Id(KEM_Code code)
Definition hpke.h:77
constexpr bool supports_auth_modes() const
Definition hpke.h:115
constexpr KEM_Code code() const
Definition hpke.h:83
constexpr bool operator==(const KEM_Id &other) const
Definition hpke.h:87
constexpr bool is_dhkem() const
Definition hpke.h:107
constexpr uint16_t wire_code() const
Definition hpke.h:85
constexpr KEM_Id(uint16_t code)
Definition hpke.h:81
std::span< const uint8_t > identity() const
Definition hpke.h:432
std::span< const uint8_t > secret() const
Definition hpke.h:430
PSK(std::span< const uint8_t > psk, std::span< const uint8_t > psk_id)
Definition hpke.cpp:333
Public_Key public_key() const
The corresponding public key.
Definition hpke.cpp:316
static Private_Key generate(KEM_Id kem, RandomNumberGenerator &rng)
GenerateKeyPair from RFC 9180 Section 4.
Definition hpke.cpp:287
const Botan::Private_Key & underlying() const
Definition hpke.cpp:325
static Private_Key derive(KEM_Id kem, std::span< const uint8_t > ikm)
Definition hpke.cpp:293
static Private_Key deserialize(KEM_Id kem, std::span< const uint8_t > bytes)
Definition hpke.cpp:299
KEM_Id kem() const
Definition hpke.cpp:312
static Private_Key from_key(KEM_Id kem, std::unique_ptr< Botan::Private_Key > key)
Definition hpke.cpp:305
secure_vector< uint8_t > serialize() const
Definition hpke.cpp:321
static Public_Key deserialize(KEM_Id kem, std::span< const uint8_t > bytes)
Definition hpke.cpp:246
std::vector< uint8_t > serialize() const
SerializePublicKey from RFC 9180 Section 7.1.1.
Definition hpke.cpp:263
friend bool operator==(const Public_Key &a, const Public_Key &b)
Definition hpke.h:329
static Public_Key from_key(KEM_Id kem, std::unique_ptr< Botan::Public_Key > key)
Definition hpke.cpp:252
const Botan::Public_Key & underlying() const
Definition hpke.cpp:267
KEM_Id kem() const
Definition hpke.cpp:259
secure_vector< uint8_t > open_at_sequence(uint64_t seq, std::span< const uint8_t > aad, std::span< const uint8_t > ctext)
Definition hpke.cpp:658
secure_vector< uint8_t > export_secret(std::span< const uint8_t > exporter_context, size_t length) const
Definition hpke.cpp:664
static Recipient_Context setup_auth(const Suite &suite, const Private_Key &recipient_key, std::span< const uint8_t > enc, const Public_Key &sender_identity_key, RandomNumberGenerator &rng, std::span< const uint8_t > info={})
Definition hpke.cpp:632
secure_vector< uint8_t > open(std::span< const uint8_t > aad, std::span< const uint8_t > ctext)
Definition hpke.cpp:653
uint64_t next_sequence() const
Definition hpke.cpp:670
Recipient_Context(const Recipient_Context &)=delete
static Recipient_Context setup_psk(const Suite &suite, const Private_Key &recipient_key, std::span< const uint8_t > enc, RandomNumberGenerator &rng, const PSK &psk, std::span< const uint8_t > info={})
Definition hpke.cpp:622
Recipient_Context(Recipient_Context &&) noexcept
Recipient_Context & operator=(const Recipient_Context &)=delete
static Recipient_Context setup_auth_psk(const Suite &suite, const Private_Key &recipient_key, std::span< const uint8_t > enc, const Public_Key &sender_identity_key, RandomNumberGenerator &rng, const PSK &psk, std::span< const uint8_t > info={})
Definition hpke.cpp:642
static Recipient_Context setup_base(const Suite &suite, const Private_Key &recipient_key, std::span< const uint8_t > enc, RandomNumberGenerator &rng, std::span< const uint8_t > info={})
Definition hpke.cpp:613
static Sender_Context setup_psk(const Suite &suite, const Public_Key &recipient_key, RandomNumberGenerator &rng, const PSK &psk, std::span< const uint8_t > info={})
Definition hpke.cpp:520
static Sender_Context setup_auth(const Suite &suite, const Public_Key &recipient_key, const Private_Key &sender_identity_key, RandomNumberGenerator &rng, std::span< const uint8_t > info={})
Definition hpke.cpp:529
static Sender_Context setup_base(const Suite &suite, const Public_Key &recipient_key, RandomNumberGenerator &rng, std::span< const uint8_t > info={})
Definition hpke.cpp:512
secure_vector< uint8_t > export_secret(std::span< const uint8_t > exporter_context, size_t length) const
Definition hpke.cpp:557
std::vector< uint8_t > seal(std::span< const uint8_t > aad, std::span< const uint8_t > ptext)
Definition hpke.cpp:552
Sender_Context(const Sender_Context &)=delete
Sender_Context(Sender_Context &&) noexcept
uint64_t next_sequence() const
The sequence number the next call to seal() will use.
Definition hpke.cpp:562
const std::vector< uint8_t > & encapsulated_key() const
The KEM encapsulation ("enc") to be transmitted to the recipient.
Definition hpke.cpp:548
static Sender_Context setup_auth_psk(const Suite &suite, const Public_Key &recipient_key, const Private_Key &sender_identity_key, RandomNumberGenerator &rng, const PSK &psk, std::span< const uint8_t > info={})
Definition hpke.cpp:538
Sender_Context & operator=(const Sender_Context &)=delete
constexpr AEAD_Id aead() const
Definition hpke.h:249
size_t ciphertext_overhead() const
Definition hpke.h:264
constexpr KDF_Id kdf() const
Definition hpke.h:247
constexpr bool is_export_only() const
Definition hpke.h:259
constexpr KEM_Id kem() const
Definition hpke.h:245
constexpr bool operator==(const Suite &other) const
Definition hpke.h:251
constexpr Suite(KEM_Id kem, KDF_Id kdf, AEAD_Id aead)
Definition hpke.h:243
bool is_available() const
Definition hpke.h:257
constexpr bool is_known() const
Definition hpke.h:255
Mode
The four HPKE modes, with their codepoints from RFC 9180 Section 5.
Definition hpke.h:440
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:128
std::string to_string(ErrorType type)
Convert an ErrorType to string.
Definition exceptn.cpp:13