Botan 3.3.0
Crypto and TLS for C&
Public Member Functions | List of all members
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 136 of file pubkey.cpp.

136 {
137 m_op = key.create_kem_encryption_op(param, provider);
138 if(!m_op) {
139 throw Invalid_Argument(fmt("Key type {} does not support KEM encryption", key.algo_name()));
140 }
141}
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 603 of file pubkey.h.

606 :
607 PK_KEM_Encryptor(key, kem_param, provider) {
608 BOTAN_UNUSED(rng);
609 }
#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:136

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 152 of file pubkey.cpp.

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

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 651 of file pubkey.h.

653 {}) {
654 std::vector<uint8_t> encapsulated_shared_key(encapsulated_key_length());
655 secure_vector<uint8_t> shared_key(shared_key_length(desired_shared_key_len));
656
657 encrypt(std::span{encapsulated_shared_key}, std::span{shared_key}, rng, desired_shared_key_len, salt);
658 return KEM_Encapsulation(std::move(encapsulated_shared_key), std::move(shared_key));
659 }
KEM_Encapsulation encrypt(RandomNumberGenerator &rng, size_t desired_shared_key_len=32, std::span< const uint8_t > salt={})
Definition pubkey.h:651
size_t shared_key_length(size_t desired_shared_key_len) const
Definition pubkey.cpp:148
size_t encapsulated_key_length() const
Definition pubkey.cpp:152

Referenced by 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 671 of file pubkey.h.

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

◆ 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 699 of file pubkey.h.

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

◆ 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 710 of file pubkey.h.

714 {}) {
715 out_encapsulated_key.resize(encapsulated_key_length());
716 out_shared_key.resize(shared_key_length(desired_shared_key_len));
717 encrypt(out_encapsulated_key, out_shared_key, rng, desired_shared_key_len, salt);
718 }

◆ 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 156 of file pubkey.cpp.

160 {
161 BOTAN_ARG_CHECK(out_encapsulated_key.size() == encapsulated_key_length(), "not enough space for encapsulated key");
162 BOTAN_ARG_CHECK(out_shared_key.size() == shared_key_length(desired_shared_key_len),
163 "not enough space for shared key");
164 m_op->kem_encrypt(out_encapsulated_key, out_shared_key, rng, desired_shared_key_len, salt);
165}
#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 148 of file pubkey.cpp.

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

References shared_key_length().

Referenced by encrypt(), and shared_key_length().


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