Botan 3.6.1
Crypto and TLS for C&
Botan::PK_KEM_Encryptor Class Referencefinal

#include <pubkey.h>

Public Member Functions

size_t encapsulated_key_length () const
 
KEM_Encapsulation encrypt (RandomNumberGenerator &rng, size_t desired_shared_key_len=32, std::span< const uint8_t > salt={})
 
void encrypt (secure_vector< uint8_t > &out_encapsulated_key, secure_vector< uint8_t > &out_shared_key, RandomNumberGenerator &rng, size_t desired_shared_key_len=32, std::span< const uint8_t > salt={})
 
void encrypt (secure_vector< uint8_t > &out_encapsulated_key, secure_vector< uint8_t > &out_shared_key, size_t desired_shared_key_len, RandomNumberGenerator &rng, const uint8_t salt[], size_t salt_len)
 
void encrypt (secure_vector< uint8_t > &out_encapsulated_key, secure_vector< uint8_t > &out_shared_key, size_t desired_shared_key_len, RandomNumberGenerator &rng, std::span< const uint8_t > salt={})
 
void encrypt (std::span< uint8_t > out_encapsulated_key, std::span< uint8_t > out_shared_key, RandomNumberGenerator &rng, size_t desired_shared_key_len=32, std::span< const uint8_t > salt={})
 
PK_KEM_Encryptoroperator= (const PK_KEM_Encryptor &)=delete
 
PK_KEM_Encryptoroperator= (PK_KEM_Encryptor &&) noexcept
 
 PK_KEM_Encryptor (const PK_KEM_Encryptor &)=delete
 
 PK_KEM_Encryptor (const Public_Key &key, RandomNumberGenerator &rng, std::string_view kem_param="", std::string_view provider="")
 
 PK_KEM_Encryptor (const Public_Key &key, std::string_view kem_param="", std::string_view provider="")
 
 PK_KEM_Encryptor (PK_KEM_Encryptor &&) noexcept
 
size_t shared_key_length (size_t desired_shared_key_len) const
 
 ~PK_KEM_Encryptor ()
 

Detailed Description

Public Key Key Encapsulation Mechanism Encryption.

Definition at line 584 of file pubkey.h.

Constructor & Destructor Documentation

◆ PK_KEM_Encryptor() [1/4]

Botan::PK_KEM_Encryptor::PK_KEM_Encryptor ( const Public_Key & key,
std::string_view kem_param = "",
std::string_view provider = "" )

Construct an instance.

Parameters
keythe key to encrypt to
kem_paramadditional KEM parameters
providerthe provider to use

Definition at line 137 of file pubkey.cpp.

137 {
138 m_op = key.create_kem_encryption_op(param, provider);
139 if(!m_op) {
140 throw Invalid_Argument(fmt("Key type {} does not support KEM encryption", key.algo_name()));
141 }
142}
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53

References Botan::Asymmetric_Key::algo_name(), Botan::Public_Key::create_kem_encryption_op(), and Botan::fmt().

◆ PK_KEM_Encryptor() [2/4]

Botan::PK_KEM_Encryptor::PK_KEM_Encryptor ( const Public_Key & key,
RandomNumberGenerator & rng,
std::string_view kem_param = "",
std::string_view provider = "" )
inline

Construct an instance.

Parameters
keythe key to encrypt to
rngthe RNG to use
kem_paramadditional KEM parameters
providerthe provider to use

Definition at line 602 of file pubkey.h.

605 :
606 PK_KEM_Encryptor(key, kem_param, provider) {
607 BOTAN_UNUSED(rng);
608 }
#define BOTAN_UNUSED
Definition assert.h:118
PK_KEM_Encryptor(const Public_Key &key, std::string_view kem_param="", std::string_view provider="")
Definition pubkey.cpp:137

References BOTAN_UNUSED.

◆ ~PK_KEM_Encryptor()

Botan::PK_KEM_Encryptor::~PK_KEM_Encryptor ( )
default

◆ PK_KEM_Encryptor() [3/4]

Botan::PK_KEM_Encryptor::PK_KEM_Encryptor ( const PK_KEM_Encryptor & )
delete

◆ PK_KEM_Encryptor() [4/4]

Botan::PK_KEM_Encryptor::PK_KEM_Encryptor ( PK_KEM_Encryptor && )
defaultnoexcept

Member Function Documentation

◆ encapsulated_key_length()

size_t Botan::PK_KEM_Encryptor::encapsulated_key_length ( ) const

Return the length in bytes of encapsulated keys returned by this KEM

Definition at line 153 of file pubkey.cpp.

153 {
154 return m_op->encapsulated_key_length();
155}

Referenced by encrypt().

◆ encrypt() [1/5]

KEM_Encapsulation Botan::PK_KEM_Encryptor::encrypt ( RandomNumberGenerator & rng,
size_t desired_shared_key_len = 32,
std::span< const uint8_t > salt = {} )
inline

Generate a shared key for data encryption.

Parameters
rngthe RNG to use
desired_shared_key_lendesired size of the shared key in bytes for the KDF (ignored if no KDF is used)
salta salt value used in the KDF (ignored if no KDF is used)
Returns
a struct with both the shared secret and its encapsulation

Definition at line 650 of file pubkey.h.

652 {}) {
653 std::vector<uint8_t> encapsulated_shared_key(encapsulated_key_length());
654 secure_vector<uint8_t> shared_key(shared_key_length(desired_shared_key_len));
655
656 encrypt(std::span{encapsulated_shared_key}, std::span{shared_key}, rng, desired_shared_key_len, salt);
657 return KEM_Encapsulation(std::move(encapsulated_shared_key), std::move(shared_key));
658 }
KEM_Encapsulation encrypt(RandomNumberGenerator &rng, size_t desired_shared_key_len=32, std::span< const uint8_t > salt={})
Definition pubkey.h:650
size_t shared_key_length(size_t desired_shared_key_len) const
Definition pubkey.cpp:149
size_t encapsulated_key_length() const
Definition pubkey.cpp:153
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61

Referenced by Botan::Kyber_PrivateKey::check_key(), and Botan::TLS::Callbacks::tls_kem_encapsulate().

◆ encrypt() [2/5]

void Botan::PK_KEM_Encryptor::encrypt ( secure_vector< uint8_t > & out_encapsulated_key,
secure_vector< uint8_t > & out_shared_key,
RandomNumberGenerator & rng,
size_t desired_shared_key_len = 32,
std::span< const uint8_t > salt = {} )
inline

Generate a shared key for data encryption.

Parameters
out_encapsulated_keythe generated encapsulated key
out_shared_keythe generated shared key
rngthe RNG to use
desired_shared_key_lendesired size of the shared key in bytes (ignored if no KDF is used)
salta salt value used in the KDF (ignored if no KDF is used)

Definition at line 670 of file pubkey.h.

674 {}) {
675 out_encapsulated_key.resize(encapsulated_key_length());
676 out_shared_key.resize(shared_key_length(desired_shared_key_len));
677 encrypt(std::span{out_encapsulated_key}, std::span{out_shared_key}, rng, desired_shared_key_len, salt);
678 }

◆ encrypt() [3/5]

void Botan::PK_KEM_Encryptor::encrypt ( secure_vector< uint8_t > & out_encapsulated_key,
secure_vector< uint8_t > & out_shared_key,
size_t desired_shared_key_len,
RandomNumberGenerator & rng,
const uint8_t salt[],
size_t salt_len )
inline

Definition at line 697 of file pubkey.h.

702 {
703 this->encrypt(out_encapsulated_key, out_shared_key, rng, desired_shared_key_len, {salt, salt_len});
704 }

◆ encrypt() [4/5]

void Botan::PK_KEM_Encryptor::encrypt ( secure_vector< uint8_t > & out_encapsulated_key,
secure_vector< uint8_t > & out_shared_key,
size_t desired_shared_key_len,
RandomNumberGenerator & rng,
std::span< const uint8_t > salt = {} )
inline

Definition at line 707 of file pubkey.h.

711 {}) {
712 out_encapsulated_key.resize(encapsulated_key_length());
713 out_shared_key.resize(shared_key_length(desired_shared_key_len));
714 encrypt(out_encapsulated_key, out_shared_key, rng, desired_shared_key_len, salt);
715 }

◆ encrypt() [5/5]

void Botan::PK_KEM_Encryptor::encrypt ( std::span< uint8_t > out_encapsulated_key,
std::span< uint8_t > out_shared_key,
RandomNumberGenerator & rng,
size_t desired_shared_key_len = 32,
std::span< const uint8_t > salt = {} )

Generate a shared key for data encryption.

Parameters
out_encapsulated_keythe generated encapsulated key
out_shared_keythe generated shared key
rngthe RNG to use
desired_shared_key_lendesired size of the shared key in bytes (ignored if no KDF is used)
salta salt value used in the KDF (ignored if no KDF is used)

Definition at line 157 of file pubkey.cpp.

161 {
162 BOTAN_ARG_CHECK(out_encapsulated_key.size() == encapsulated_key_length(), "not enough space for encapsulated key");
163 BOTAN_ARG_CHECK(out_shared_key.size() == shared_key_length(desired_shared_key_len),
164 "not enough space for shared key");
165 m_op->kem_encrypt(out_encapsulated_key, out_shared_key, rng, desired_shared_key_len, salt);
166}
#define BOTAN_ARG_CHECK(expr, msg)
Definition assert.h:29

References BOTAN_ARG_CHECK, encapsulated_key_length(), and shared_key_length().

◆ operator=() [1/2]

PK_KEM_Encryptor & Botan::PK_KEM_Encryptor::operator= ( const PK_KEM_Encryptor & )
delete

◆ operator=() [2/2]

PK_KEM_Encryptor & Botan::PK_KEM_Encryptor::operator= ( PK_KEM_Encryptor && )
defaultnoexcept

◆ shared_key_length()

size_t Botan::PK_KEM_Encryptor::shared_key_length ( size_t desired_shared_key_len) const

Return the length of the shared key returned by this KEM

If this KEM was used with a KDF, then it will always return exactly the desired key length, because the output of the KEM will be hashed by the KDF.

However if the KEM was used with "Raw" kdf, to request the algorithmic output of the KEM directly, then the desired key length will be ignored and a bytestring that depends on the algorithm is returned

Parameters
desired_shared_key_lenis the requested length

Definition at line 149 of file pubkey.cpp.

149 {
150 return m_op->shared_key_length(desired_shared_key_len);
151}

References shared_key_length().

Referenced by encrypt(), and shared_key_length().


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