Botan 3.14.1
Crypto and TLS for C&
Botan::PK_KEM_Options Class Referencefinal

#include <pk_options.h>

Public Member Functions

PK_KEM_Options & operator= (const PK_KEM_Options &other)=default
PK_KEM_Options & operator= (PK_KEM_Options &&other)=default
 PK_KEM_Options ()=default
 PK_KEM_Options (const PK_KEM_Options &)=default
 PK_KEM_Options (PK_KEM_Options &&other)=default
std::string to_string () const
PK_KEM_Options with_kdf (std::string_view kdf)
PK_KEM_Options with_provider (std::string_view provider)
PK_KEM_Options with_raw_shared_key ()
 ~PK_KEM_Options ()

Friends

class PK_KEM_Options_Reader

Detailed Description

Key encapsulation options

The normal usage of this is in a builder style, eg

PK_KEM_Options().with_kdf("HKDF(SHA-256)")

As with PK_Signature_Options, every option that is set must be understood by the KEM in use; constructing the PK_KEM_Encryptor or PK_KEM_Decryptor throws an exception otherwise.

Definition at line 292 of file pk_options.h.

Constructor & Destructor Documentation

◆ PK_KEM_Options() [1/3]

Botan::PK_KEM_Options::PK_KEM_Options ( )
default

◆ PK_KEM_Options() [2/3]

Botan::PK_KEM_Options::PK_KEM_Options ( PK_KEM_Options && other)
default

References PK_KEM_Options().

◆ PK_KEM_Options() [3/3]

Botan::PK_KEM_Options::PK_KEM_Options ( const PK_KEM_Options & )
default

References PK_KEM_Options().

◆ ~PK_KEM_Options()

Botan::PK_KEM_Options::~PK_KEM_Options ( )
default

Member Function Documentation

◆ operator=() [1/2]

PK_KEM_Options & Botan::PK_KEM_Options::operator= ( const PK_KEM_Options & other)
default

References PK_KEM_Options().

◆ operator=() [2/2]

PK_KEM_Options & Botan::PK_KEM_Options::operator= ( PK_KEM_Options && other)
default

References PK_KEM_Options().

◆ to_string()

std::string Botan::PK_KEM_Options::to_string ( ) const

Format this PK_KEM_Options as a string

This is primarily intended for debugging and error messages; the format is not fixed

Definition at line 461 of file pk_options.cpp.

461 {
462 std::ostringstream out;
463
464 if(m_kdf) {
465 out << "KDF='" << *m_kdf << "' ";
466 }
467 if(m_raw_shared_key) {
468 out << "RawSharedKey ";
469 }
470 if(m_provider) {
471 out << "Provider='" << *m_provider << "' ";
472 }
473
474 return out.str();
475}

Referenced by ~PK_KEM_Options().

◆ with_kdf()

PK_KEM_Options Botan::PK_KEM_Options::with_kdf ( std::string_view kdf)

Specify a KDF used to derive the shared key from the KEM output

The salt and desired length passed to the encrypt/decrypt operations are inputs to this KDF.

The name must not be empty; this cannot be combined with with_raw_shared_key

Definition at line 397 of file pk_options.cpp.

397 {
398 BOTAN_STATE_CHECK_MSG(!m_kdf.has_value(), "PK_KEM_Options::with_kdf cannot specify KDF twice");
399 BOTAN_STATE_CHECK_MSG(!m_raw_shared_key, "PK_KEM_Options::with_kdf cannot be combined with with_raw_shared_key");
400 // Silently accepting an empty name would turn a request for a KDF into the raw shared key
401 BOTAN_ARG_CHECK(!kdf.empty(), "PK_KEM_Options::with_kdf requires a KDF name");
402 auto next = (*this);
403 next.m_kdf = kdf;
404 return next;
405}
#define BOTAN_ARG_CHECK(expr, msg)
Definition assert.h:33
#define BOTAN_STATE_CHECK_MSG(expr, msg)
Definition assert.h:59

References BOTAN_ARG_CHECK, BOTAN_STATE_CHECK_MSG, and PK_KEM_Options().

Referenced by Botan::parse_legacy_kem_options(), and ~PK_KEM_Options().

◆ with_provider()

PK_KEM_Options Botan::PK_KEM_Options::with_provider ( std::string_view provider)

Specify a provider that should be used

This is rarely relevant

Definition at line 415 of file pk_options.cpp.

415 {
416 BOTAN_STATE_CHECK_MSG(provider.empty() || !m_provider.has_value(),
417 "PK_KEM_Options::with_provider cannot specify provider twice");
418 auto next = (*this);
419 if(!provider.empty()) {
420 next.m_provider = provider;
421 }
422 return next;
423}

References BOTAN_STATE_CHECK_MSG, and PK_KEM_Options().

Referenced by Botan::Private_Key::create_kem_decryption_op(), Botan::Public_Key::create_kem_encryption_op(), and ~PK_KEM_Options().

◆ with_raw_shared_key()

PK_KEM_Options Botan::PK_KEM_Options::with_raw_shared_key ( )

Request the raw output of the KEM as the shared key

If neither this nor with_kdf is used, KEMs whose output is already a uniformly random key (for example ML-KEM) return that output directly, while KEMs whose output is not (for example RSA-KEM or a key agreement used as a KEM) reject the request.

This cannot be combined with with_kdf

Definition at line 407 of file pk_options.cpp.

407 {
408 BOTAN_STATE_CHECK_MSG(!m_raw_shared_key, "PK_KEM_Options::with_raw_shared_key cannot be specified twice");
409 BOTAN_STATE_CHECK_MSG(!m_kdf.has_value(), "PK_KEM_Options::with_raw_shared_key cannot be combined with with_kdf");
410 auto next = (*this);
411 next.m_raw_shared_key = true;
412 return next;
413}

References BOTAN_STATE_CHECK_MSG, and PK_KEM_Options().

Referenced by Botan::parse_legacy_kem_options(), and ~PK_KEM_Options().

◆ PK_KEM_Options_Reader

friend class PK_KEM_Options_Reader
friend

Definition at line 333 of file pk_options.h.

References PK_KEM_Options_Reader.

Referenced by PK_KEM_Options_Reader.


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