Botan 3.0.0
Crypto and TLS for C&
Public Member Functions | Protected Member Functions | List of all members
Botan::PK_Ops::KEM_Encryption_with_KDF Class Referenceabstract

#include <pk_ops_impl.h>

Inheritance diagram for Botan::PK_Ops::KEM_Encryption_with_KDF:
Botan::PK_Ops::KEM_Encryption

Public Member Functions

virtual size_t encapsulated_key_length () const =0
 
void kem_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) override final
 
size_t shared_key_length (size_t desired_shared_key_len) const override final
 

Protected Member Functions

 KEM_Encryption_with_KDF (std::string_view kdf)
 
virtual void raw_kem_encrypt (secure_vector< uint8_t > &out_encapsulated_key, secure_vector< uint8_t > &raw_shared_key, RandomNumberGenerator &rng)=0
 
virtual size_t raw_kem_shared_key_length () const =0
 
 ~KEM_Encryption_with_KDF ()=default
 

Detailed Description

Definition at line 123 of file pk_ops_impl.h.

Constructor & Destructor Documentation

◆ KEM_Encryption_with_KDF()

Botan::PK_Ops::KEM_Encryption_with_KDF::KEM_Encryption_with_KDF ( std::string_view  kdf)
explicitprotected

Definition at line 224 of file pk_ops.cpp.

225 {
226 if(kdf != "Raw")
227 m_kdf = KDF::create_or_throw(kdf);
228 }
static std::unique_ptr< KDF > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition: kdf.cpp:213

References Botan::KDF::create_or_throw().

◆ ~KEM_Encryption_with_KDF()

Botan::PK_Ops::KEM_Encryption_with_KDF::~KEM_Encryption_with_KDF ( )
protecteddefault

Member Function Documentation

◆ encapsulated_key_length()

virtual size_t Botan::PK_Ops::KEM_Encryption::encapsulated_key_length ( ) const
pure virtualinherited

◆ kem_encrypt()

void Botan::PK_Ops::KEM_Encryption_with_KDF::kem_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 
)
finaloverridevirtual

Implements Botan::PK_Ops::KEM_Encryption.

Definition at line 198 of file pk_ops.cpp.

204 {
205 if(salt_len > 0 && m_kdf == nullptr)
206 throw Invalid_Argument("PK_KEM_Encryptor::encrypt requires a KDF to use a salt");
207
208 secure_vector<uint8_t> raw_shared;
209 this->raw_kem_encrypt(out_encapsulated_key, raw_shared, rng);
210
211 BOTAN_ASSERT_EQUAL(out_encapsulated_key.size(), this->encapsulated_key_length(),
212 "KEM produced encapsulated key with different length than expected");
213
214 BOTAN_ASSERT_EQUAL(raw_shared.size(), this->raw_kem_shared_key_length(),
215 "KEM produced shared key with different length than expected");
216
217 out_shared_key = (m_kdf)
218 ? m_kdf->derive_key(desired_shared_key_len,
219 raw_shared.data(), raw_shared.size(),
220 salt, salt_len)
221 : raw_shared;
222 }
#define BOTAN_ASSERT_EQUAL(expr1, expr2, assertion_made)
Definition: assert.h:80
virtual void raw_kem_encrypt(secure_vector< uint8_t > &out_encapsulated_key, secure_vector< uint8_t > &raw_shared_key, RandomNumberGenerator &rng)=0

References BOTAN_ASSERT_EQUAL.

◆ raw_kem_encrypt()

virtual void Botan::PK_Ops::KEM_Encryption_with_KDF::raw_kem_encrypt ( secure_vector< uint8_t > &  out_encapsulated_key,
secure_vector< uint8_t > &  raw_shared_key,
RandomNumberGenerator rng 
)
protectedpure virtual

◆ raw_kem_shared_key_length()

virtual size_t Botan::PK_Ops::KEM_Encryption_with_KDF::raw_kem_shared_key_length ( ) const
protectedpure virtual

◆ shared_key_length()

size_t Botan::PK_Ops::KEM_Encryption_with_KDF::shared_key_length ( size_t  desired_shared_key_len) const
finaloverridevirtual

Implements Botan::PK_Ops::KEM_Encryption.

Definition at line 190 of file pk_ops.cpp.

191 {
192 if(m_kdf)
193 return desired_shared_key_len;
194 else
195 return this->raw_kem_shared_key_length();
196 }
virtual size_t raw_kem_shared_key_length() const =0

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