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

#include <hpke.h>

Public Member Functions

KEM_Id kem () const
Public_Key public_key () const
 The corresponding public key.
secure_vector< uint8_t > serialize () const
const Botan::Private_Key & underlying () const

Static Public Member Functions

static Private_Key derive (KEM_Id kem, std::span< const uint8_t > ikm)
static Private_Key deserialize (KEM_Id kem, std::span< const uint8_t > bytes)
static Private_Key from_key (KEM_Id kem, std::unique_ptr< Botan::Private_Key > key)
static Private_Key generate (KEM_Id kem, RandomNumberGenerator &rng)
 GenerateKeyPair from RFC 9180 Section 4.

Friends

class HPKE::Recipient_Context
class HPKE::Sender_Context

Detailed Description

An HPKE private key

This is a value type (cheap to copy) wrapping an asymmetric key that has been validated for use with a particular HPKE KEM. It has no inheritance relationship with Botan::Private_Key or with HPKE::Public_Key; the corresponding public key is obtained with public_key().

Definition at line 353 of file hpke.h.

Member Function Documentation

◆ derive()

Private_Key Botan::HPKE::Private_Key::derive ( KEM_Id kem,
std::span< const uint8_t > ikm )
static

DeriveKeyPair from RFC 9180 Section 7.1.3

Deterministically derives a key pair from input keying material, which must be full-entropy secret data of at least Nsk bytes; as an exception DHKEM(P-521) accepts 64 bytes, since MLS (RFC 9420 Section 7.4) derives P-521 key pairs from 64-byte node secrets.

Definition at line 293 of file hpke.cpp.

293 {
294 std::shared_ptr<const KEM_Ops> ops = KEM_Ops::create(kem);
295 auto key = ops->derive_key_pair(ikm);
296 return Private_Key(std::make_shared<Data>(std::move(ops), std::move(key)));
297}
static std::unique_ptr< const KEM_Ops > create(KEM_Id kem)
Definition hpke_kem.cpp:545
KEM_Id kem() const
Definition hpke.cpp:312

References Botan::HPKE::KEM_Ops::create(), and kem().

◆ deserialize()

Private_Key Botan::HPKE::Private_Key::deserialize ( KEM_Id kem,
std::span< const uint8_t > bytes )
static

DeserializePrivateKey from RFC 9180 Section 7.1.2

Accepts Nsk raw bytes. The scalar is range-checked for the NIST curves, and clamped (RFC 7748 Section 5) for X25519 and X448.

Definition at line 299 of file hpke.cpp.

299 {
300 std::shared_ptr<const KEM_Ops> ops = KEM_Ops::create(kem);
301 auto key = ops->deserialize_private(bytes);
302 return Private_Key(std::make_shared<Data>(std::move(ops), std::move(key)));
303}

References Botan::HPKE::KEM_Ops::create(), and kem().

◆ from_key()

Private_Key Botan::HPKE::Private_Key::from_key ( KEM_Id kem,
std::unique_ptr< Botan::Private_Key > key )
static

Adopt an existing key (eg loaded from PKCS #8) for use with HPKE

As for Public_Key::from_key, ECDSA keys on the NIST curves are accepted and converted to ECDH, while other EC algorithms are rejected. Throws Invalid_Argument unless the key's algorithm (and, for the NIST curves, its group) matches the KEM.

Definition at line 305 of file hpke.cpp.

305 {
306 BOTAN_ARG_CHECK(key != nullptr, "HPKE::Private_Key::from_key: key is null");
307 std::shared_ptr<const KEM_Ops> ops = KEM_Ops::create(kem);
308 auto adopted = ops->adopt_private(std::move(key));
309 return Private_Key(std::make_shared<Data>(std::move(ops), std::move(adopted)));
310}
#define BOTAN_ARG_CHECK(expr, msg)
Definition assert.h:33

References BOTAN_ARG_CHECK, Botan::HPKE::KEM_Ops::create(), and kem().

◆ generate()

Private_Key Botan::HPKE::Private_Key::generate ( KEM_Id kem,
RandomNumberGenerator & rng )
static

GenerateKeyPair from RFC 9180 Section 4.

Definition at line 287 of file hpke.cpp.

287 {
288 std::shared_ptr<const KEM_Ops> ops = KEM_Ops::create(kem);
289 auto key = ops->generate_key(rng);
290 return Private_Key(std::make_shared<Data>(std::move(ops), std::move(key)));
291}

References Botan::HPKE::KEM_Ops::create(), and kem().

◆ kem()

KEM_Id Botan::HPKE::Private_Key::kem ( ) const

Definition at line 312 of file hpke.cpp.

312 {
313 return m_data->ops().kem_id();
314}

Referenced by derive(), deserialize(), from_key(), and generate().

◆ public_key()

Public_Key Botan::HPKE::Private_Key::public_key ( ) const

The corresponding public key.

Definition at line 316 of file hpke.cpp.

316 {
317 auto pub = m_data->key().public_key();
318 return Public_Key(std::make_shared<Public_Key::Data>(m_data->ops_ptr(), std::move(pub)));
319}

◆ serialize()

secure_vector< uint8_t > Botan::HPKE::Private_Key::serialize ( ) const

SerializePrivateKey from RFC 9180 Section 7.1.2

For X25519 and X448 the output is clamped, as RFC 9180 Section 7.1.2 requires.

Definition at line 321 of file hpke.cpp.

321 {
322 return m_data->ops().serialize_private(m_data->key());
323}

◆ underlying()

const Botan::Private_Key & Botan::HPKE::Private_Key::underlying ( ) const

Access the wrapped key, eg for encoding as PKCS #8

For the NIST curves this is an ECDH key, which encodes with the id-ecDH algorithm identifier.

Definition at line 325 of file hpke.cpp.

325 {
326 return m_data->key();
327}

◆ HPKE::Recipient_Context

friend class HPKE::Recipient_Context
friend

Definition at line 413 of file hpke.h.

◆ HPKE::Sender_Context

friend class HPKE::Sender_Context
friend

Definition at line 412 of file hpke.h.


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