Botan 3.14.1
Crypto and TLS for C&
Botan::HPKE::KEM_Id Class Referencefinal

#include <hpke.h>

Public Member Functions

constexpr KEM_Code code () const
size_t encapsulation_length () const
 Return the constant Nenc from RFC 9180 Section 7.1, throws for invalid code points.
bool is_available () const
 True if the algorithms this KEM requires are available in this build.
constexpr bool is_dhkem () const
constexpr bool is_known () const
 True if this codepoint is known to this version of the library.
constexpr KEM_Id (KEM_Code code)
constexpr KEM_Id (uint16_t code)
constexpr bool operator== (const KEM_Id &other) const
constexpr bool operator== (KEM_Code code) const
size_t private_key_length () const
 Return the constant Nsk from RFC 9180 Section 7.1, throws for invalid code points.
size_t public_key_length () const
 Return the constant Npk from RFC 9180 Section 7.1, throws for invalid code points.
size_t shared_secret_length () const
 Return the constant Nsecret from RFC 9180 Section 7.1, throws for invalid code points.
constexpr bool supports_auth_modes () const
std::optional< std::string > to_string () const
 Returns std::nullopt for unknown codepoints.
constexpr uint16_t wire_code () const

Detailed Description

Identifies the KEM used by an HPKE ciphersuite

This may hold any 16-bit codepoint, including values unknown to the library (as may be encountered eg when parsing an ECHConfigList); is_known() and is_available() distinguish what can actually be used.

Definition at line 72 of file hpke.h.

Constructor & Destructor Documentation

◆ KEM_Id() [1/2]

Botan::HPKE::KEM_Id::KEM_Id ( KEM_Code code)
inlineconstexpr

Definition at line 77 of file hpke.h.

77: m_code(code) {}
constexpr KEM_Code code() const
Definition hpke.h:83

References code().

Referenced by operator==().

◆ KEM_Id() [2/2]

Botan::HPKE::KEM_Id::KEM_Id ( uint16_t code)
inlineconstexpr

Definition at line 81 of file hpke.h.

81: m_code(static_cast<KEM_Code>(code)) {}

References code().

Member Function Documentation

◆ code()

KEM_Code Botan::HPKE::KEM_Id::code ( ) const
inlineconstexpr

Definition at line 83 of file hpke.h.

83{ return m_code; }

Referenced by Botan::HPKE::KEM_Ops::create(), KEM_Id(), KEM_Id(), and operator==().

◆ encapsulation_length()

size_t Botan::HPKE::KEM_Id::encapsulation_length ( ) const

Return the constant Nenc from RFC 9180 Section 7.1, throws for invalid code points.

Definition at line 132 of file hpke.cpp.

132 {
133 return require_kem_info(*this).nenc;
134}

◆ is_available()

bool Botan::HPKE::KEM_Id::is_available ( ) const

True if the algorithms this KEM requires are available in this build.

Definition at line 119 of file hpke.cpp.

119 {
120 try {
121 KEM_Ops::create(*this);
122 return true;
123 } catch(Exception&) {
124 return false;
125 }
126}
static std::unique_ptr< const KEM_Ops > create(KEM_Id kem)
Definition hpke_kem.cpp:545

References Botan::HPKE::KEM_Ops::create().

◆ is_dhkem()

bool Botan::HPKE::KEM_Id::is_dhkem ( ) const
inlineconstexpr

Definition at line 107 of file hpke.h.

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

References Botan::HPKE::DHKEM_P256, Botan::HPKE::DHKEM_P384, Botan::HPKE::DHKEM_P521, Botan::HPKE::DHKEM_X25519, and Botan::HPKE::DHKEM_X448.

Referenced by supports_auth_modes().

◆ is_known()

bool Botan::HPKE::KEM_Id::is_known ( ) const
inlineconstexpr

True if this codepoint is known to this version of the library.

Definition at line 92 of file hpke.h.

92 {
93 switch(m_code) {
99 return true;
100 }
101 return false;
102 }

References Botan::HPKE::DHKEM_P256, Botan::HPKE::DHKEM_P384, Botan::HPKE::DHKEM_P521, Botan::HPKE::DHKEM_X25519, and Botan::HPKE::DHKEM_X448.

◆ operator==() [1/2]

bool Botan::HPKE::KEM_Id::operator== ( const KEM_Id & other) const
inlineconstexpr

Definition at line 87 of file hpke.h.

87{ return m_code == other.m_code; }

References KEM_Id().

◆ operator==() [2/2]

bool Botan::HPKE::KEM_Id::operator== ( KEM_Code code) const
inlineconstexpr

Definition at line 89 of file hpke.h.

89{ return m_code == code; }

References code().

◆ private_key_length()

size_t Botan::HPKE::KEM_Id::private_key_length ( ) const

Return the constant Nsk from RFC 9180 Section 7.1, throws for invalid code points.

Definition at line 140 of file hpke.cpp.

140 {
141 return require_kem_info(*this).nsk;
142}

◆ public_key_length()

size_t Botan::HPKE::KEM_Id::public_key_length ( ) const

Return the constant Npk from RFC 9180 Section 7.1, throws for invalid code points.

Definition at line 136 of file hpke.cpp.

136 {
137 return require_kem_info(*this).npk;
138}

◆ shared_secret_length()

size_t Botan::HPKE::KEM_Id::shared_secret_length ( ) const

Return the constant Nsecret from RFC 9180 Section 7.1, throws for invalid code points.

Definition at line 128 of file hpke.cpp.

128 {
129 return require_kem_info(*this).nsecret;
130}

◆ supports_auth_modes()

bool Botan::HPKE::KEM_Id::supports_auth_modes ( ) const
inlineconstexpr

Only the DH-based KEMs support the Auth and AuthPSK modes See RFC 9180 Section 7.1

Definition at line 115 of file hpke.h.

115{ return is_dhkem(); }
constexpr bool is_dhkem() const
Definition hpke.h:107

References is_dhkem().

◆ to_string()

std::optional< std::string > Botan::HPKE::KEM_Id::to_string ( ) const

Returns std::nullopt for unknown codepoints.

Definition at line 144 of file hpke.cpp.

144 {
145 if(const auto info = kem_info(m_code)) {
146 return std::string(info->name);
147 }
148 return std::nullopt;
149}

◆ wire_code()

uint16_t Botan::HPKE::KEM_Id::wire_code ( ) const
inlineconstexpr

Definition at line 85 of file hpke.h.

85{ return static_cast<uint16_t>(m_code); }

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