Botan 3.14.1
Crypto and TLS for C&
Botan::HPKE::KEM_Ops Class Referenceabstract

#include <hpke_kem.h>

Classes

struct  Encapsulation

Public Member Functions

virtual std::unique_ptr< Botan::Private_Key > adopt_private (std::unique_ptr< Botan::Private_Key > key) const =0
virtual std::unique_ptr< Botan::Public_Key > adopt_public (std::unique_ptr< Botan::Public_Key > key) const =0
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
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.
virtual Encapsulation auth_encap_with_ephemeral (const Botan::Public_Key &pkR, const Botan::Private_Key &skS, const Botan::Private_Key &skE, RandomNumberGenerator &rng) const
virtual secure_vector< uint8_t > decap (std::span< const uint8_t > enc, const Botan::Private_Key &skR, RandomNumberGenerator &rng) const =0
virtual std::unique_ptr< Botan::Private_Key > derive_key_pair (std::span< const uint8_t > ikm) const =0
virtual std::unique_ptr< Botan::Private_Key > deserialize_private (std::span< const uint8_t > bytes) const =0
virtual std::unique_ptr< Botan::Public_Key > deserialize_public (std::span< const uint8_t > bytes) const =0
virtual Encapsulation encap (const Botan::Public_Key &pkR, RandomNumberGenerator &rng) const =0
virtual Encapsulation encap_with_ephemeral (const Botan::Public_Key &pkR, const Botan::Private_Key &skE, RandomNumberGenerator &rng) const
virtual std::unique_ptr< Botan::Private_Key > generate_key (RandomNumberGenerator &rng) const =0
KEM_Id kem_id () const
 KEM_Ops (const KEM_Ops &)=delete
 KEM_Ops (KEM_Ops &&)=delete
KEM_Ops & operator= (const KEM_Ops &)=delete
KEM_Ops & operator= (KEM_Ops &&)=delete
virtual secure_vector< uint8_t > serialize_private (const Botan::Private_Key &key) const =0
virtual std::vector< uint8_t > serialize_public (const Botan::Public_Key &key) const =0
virtual bool supports_auth () const
virtual ~KEM_Ops ()=default

Static Public Member Functions

static std::unique_ptr< const KEM_Ops > create (KEM_Id kem)

Protected Member Functions

 KEM_Ops (KEM_Id kem)

Detailed Description

Internal interface for the KEM operations HPKE requires

Implemented by DHKEM (RFC 9180 Section 4.1) over the key agreement algorithms.

Definition at line 44 of file hpke_kem.h.

Constructor & Destructor Documentation

◆ ~KEM_Ops()

virtual Botan::HPKE::KEM_Ops::~KEM_Ops ( )
virtualdefault

◆ KEM_Ops() [1/3]

Botan::HPKE::KEM_Ops::KEM_Ops ( const KEM_Ops & )
delete

References KEM_Ops().

Referenced by KEM_Ops(), KEM_Ops(), operator=(), and operator=().

◆ KEM_Ops() [2/3]

Botan::HPKE::KEM_Ops::KEM_Ops ( KEM_Ops && )
delete

References KEM_Ops().

◆ KEM_Ops() [3/3]

Botan::HPKE::KEM_Ops::KEM_Ops ( KEM_Id kem)
inlineexplicitprotected

Definition at line 129 of file hpke_kem.h.

129: m_kem(kem) {}

Member Function Documentation

◆ adopt_private()

virtual std::unique_ptr< Botan::Private_Key > Botan::HPKE::KEM_Ops::adopt_private ( std::unique_ptr< Botan::Private_Key > key) const
pure virtual

◆ adopt_public()

virtual std::unique_ptr< Botan::Public_Key > Botan::HPKE::KEM_Ops::adopt_public ( std::unique_ptr< Botan::Public_Key > key) const
pure virtual

Adopt an existing key for use with this KEM

Returns the key itself if it is of the type the KEM operates on, or an equivalent key of that type (for the NIST curves, an ECDSA key is converted to ECDH). Throws Invalid_Argument for any other key, or if the key's group does not match the KEM.

◆ auth_decap()

secure_vector< uint8_t > Botan::HPKE::KEM_Ops::auth_decap ( std::span< const uint8_t > enc,
const Botan::Private_Key & skR,
const Botan::Public_Key & pkS,
RandomNumberGenerator & rng ) const
virtual

Definition at line 96 of file hpke_kem.cpp.

99 {
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}
KEM_Id kem_id() const
Definition hpke_kem.h:65
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53

References Botan::fmt(), and kem_id().

Referenced by decap().

◆ auth_encap()

KEM_Ops::Encapsulation Botan::HPKE::KEM_Ops::auth_encap ( const Botan::Public_Key & pkR,
const Botan::Private_Key & skS,
RandomNumberGenerator & rng ) const
virtual

Only supported if supports_auth(); the default implementations throw.

Definition at line 89 of file hpke_kem.cpp.

91 {
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}

References Botan::fmt(), and kem_id().

Referenced by decap().

◆ auth_encap_with_ephemeral()

KEM_Ops::Encapsulation Botan::HPKE::KEM_Ops::auth_encap_with_ephemeral ( const Botan::Public_Key & pkR,
const Botan::Private_Key & skS,
const Botan::Private_Key & skE,
RandomNumberGenerator & rng ) const
virtual

Deterministic authenticated encapsulation with a caller-provided ephemeral key, for known-answer testing of DHKEMs. The default implementation throws.

Definition at line 110 of file hpke_kem.cpp.

113 {
114 throw Not_Implemented(fmt("HPKE KEM {} does not support deterministic encapsulation", kem_name(kem_id())));
115}

References Botan::fmt(), and kem_id().

Referenced by decap().

◆ create()

std::unique_ptr< const KEM_Ops > Botan::HPKE::KEM_Ops::create ( KEM_Id kem)
static

Create the operations for a KEM

Throws Not_Implemented if the codepoint is unknown or the required algorithms are not available in this build.

Definition at line 545 of file hpke_kem.cpp.

545 {
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}
static bool supports_named_group(std::string_view name)
Definition ec_group.cpp:473

References Botan::HPKE::KEM_Id::code(), Botan::HPKE::DHKEM_P256, Botan::HPKE::DHKEM_P384, Botan::HPKE::DHKEM_P521, Botan::HPKE::DHKEM_X25519, Botan::HPKE::DHKEM_X448, Botan::fmt(), and Botan::EC_Group::supports_named_group().

Referenced by Botan::HPKE::Private_Key::derive(), Botan::HPKE::Private_Key::deserialize(), Botan::HPKE::Public_Key::deserialize(), Botan::HPKE::Private_Key::from_key(), Botan::HPKE::Public_Key::from_key(), Botan::HPKE::Private_Key::generate(), and Botan::HPKE::KEM_Id::is_available().

◆ decap()

virtual secure_vector< uint8_t > Botan::HPKE::KEM_Ops::decap ( std::span< const uint8_t > enc,
const Botan::Private_Key & skR,
RandomNumberGenerator & rng ) const
pure virtual

◆ derive_key_pair()

virtual std::unique_ptr< Botan::Private_Key > Botan::HPKE::KEM_Ops::derive_key_pair ( std::span< const uint8_t > ikm) const
pure virtual

◆ deserialize_private()

virtual std::unique_ptr< Botan::Private_Key > Botan::HPKE::KEM_Ops::deserialize_private ( std::span< const uint8_t > bytes) const
pure virtual

◆ deserialize_public()

virtual std::unique_ptr< Botan::Public_Key > Botan::HPKE::KEM_Ops::deserialize_public ( std::span< const uint8_t > bytes) const
pure virtual

◆ encap()

virtual Encapsulation Botan::HPKE::KEM_Ops::encap ( const Botan::Public_Key & pkR,
RandomNumberGenerator & rng ) const
pure virtual

◆ encap_with_ephemeral()

KEM_Ops::Encapsulation Botan::HPKE::KEM_Ops::encap_with_ephemeral ( const Botan::Public_Key & pkR,
const Botan::Private_Key & skE,
RandomNumberGenerator & rng ) const
virtual

Deterministic encapsulation with a caller-provided ephemeral key, for known-answer testing of DHKEMs. The default implementation throws.

Definition at line 104 of file hpke_kem.cpp.

106 {
107 throw Not_Implemented(fmt("HPKE KEM {} does not support deterministic encapsulation", kem_name(kem_id())));
108}

References Botan::fmt(), and kem_id().

Referenced by decap().

◆ generate_key()

virtual std::unique_ptr< Botan::Private_Key > Botan::HPKE::KEM_Ops::generate_key ( RandomNumberGenerator & rng) const
pure virtual

◆ kem_id()

KEM_Id Botan::HPKE::KEM_Ops::kem_id ( ) const
inline

Definition at line 65 of file hpke_kem.h.

65{ return m_kem; }

Referenced by auth_decap(), auth_encap(), auth_encap_with_ephemeral(), and encap_with_ephemeral().

◆ operator=() [1/2]

KEM_Ops & Botan::HPKE::KEM_Ops::operator= ( const KEM_Ops & )
delete

References KEM_Ops().

◆ operator=() [2/2]

KEM_Ops & Botan::HPKE::KEM_Ops::operator= ( KEM_Ops && )
delete

References KEM_Ops().

◆ serialize_private()

virtual secure_vector< uint8_t > Botan::HPKE::KEM_Ops::serialize_private ( const Botan::Private_Key & key) const
pure virtual

◆ serialize_public()

virtual std::vector< uint8_t > Botan::HPKE::KEM_Ops::serialize_public ( const Botan::Public_Key & key) const
pure virtual

◆ supports_auth()

virtual bool Botan::HPKE::KEM_Ops::supports_auth ( ) const
inlinevirtual

Definition at line 68 of file hpke_kem.h.

68{ return false; }

The documentation for this class was generated from the following files: