Botan 3.6.1
Crypto and TLS for C&
Botan::Kyber_KEM_Encryptor_Base Class Referenceabstract

#include <kyber_encaps_base.h>

Inheritance diagram for Botan::Kyber_KEM_Encryptor_Base:
Botan::PK_Ops::KEM_Encryption_with_KDF Botan::Kyber_KEM_Operation_Base Botan::PK_Ops::KEM_Encryption Botan::Kyber_KEM_Encryptor Botan::ML_KEM_Encryptor

Public Member Functions

size_t encapsulated_key_length () const override
 
void kem_encrypt (std::span< uint8_t > out_encapsulated_key, std::span< uint8_t > out_shared_key, RandomNumberGenerator &rng, size_t desired_shared_key_len, std::span< const uint8_t > salt) final
 
void raw_kem_encrypt (std::span< uint8_t > out_encapsulated_key, std::span< uint8_t > out_shared_key, RandomNumberGenerator &rng) final
 
size_t raw_kem_shared_key_length () const override
 
size_t shared_key_length (size_t desired_shared_key_len) const final
 

Protected Member Functions

virtual void encapsulate (StrongSpan< KyberCompressedCiphertext > out_encapsulated_key, StrongSpan< KyberSharedSecret > out_shared_key, RandomNumberGenerator &rng)=0
 
 Kyber_KEM_Encryptor_Base (std::string_view kdf, const Kyber_PublicKeyInternal &pk)
 
virtual const KyberConstantsmode () const =0
 
const KyberPolyMatprecomputed_matrix_At () const
 

Detailed Description

Definition at line 32 of file kyber_encaps_base.h.

Constructor & Destructor Documentation

◆ Kyber_KEM_Encryptor_Base()

Botan::Kyber_KEM_Encryptor_Base::Kyber_KEM_Encryptor_Base ( std::string_view kdf,
const Kyber_PublicKeyInternal & pk )
inlineprotected

Definition at line 48 of file kyber_encaps_base.h.

48 :
49 PK_Ops::KEM_Encryption_with_KDF(kdf), Kyber_KEM_Operation_Base(pk) {}
Kyber_KEM_Operation_Base(const Kyber_PublicKeyInternal &pk)

Member Function Documentation

◆ encapsulate()

virtual void Botan::Kyber_KEM_Encryptor_Base::encapsulate ( StrongSpan< KyberCompressedCiphertext > out_encapsulated_key,
StrongSpan< KyberSharedSecret > out_shared_key,
RandomNumberGenerator & rng )
protectedpure virtual

◆ encapsulated_key_length()

size_t Botan::Kyber_KEM_Encryptor_Base::encapsulated_key_length ( ) const
inlineoverridevirtual

Implements Botan::PK_Ops::KEM_Encryption.

Definition at line 37 of file kyber_encaps_base.h.

37{ return mode().ciphertext_bytes(); }
size_t ciphertext_bytes() const
byte length of an encoded ciphertext
virtual const KyberConstants & mode() const =0

References Botan::KyberConstants::ciphertext_bytes(), and mode().

◆ kem_encrypt()

void Botan::PK_Ops::KEM_Encryption_with_KDF::kem_encrypt ( std::span< uint8_t > out_encapsulated_key,
std::span< uint8_t > out_shared_key,
RandomNumberGenerator & rng,
size_t desired_shared_key_len,
std::span< const uint8_t > salt )
finalvirtualinherited

Implements Botan::PK_Ops::KEM_Encryption.

Definition at line 184 of file pk_ops.cpp.

188 {
189 BOTAN_ARG_CHECK(salt.empty() || m_kdf, "PK_KEM_Encryptor::encrypt requires a KDF to use a salt");
190 BOTAN_ASSERT_NOMSG(out_encapsulated_key.size() == encapsulated_key_length());
191
192 if(m_kdf) {
194 out_shared_key.size(), desired_shared_key_len, "KDF output length and shared key length match");
195
197 this->raw_kem_encrypt(out_encapsulated_key, raw_shared, rng);
198 m_kdf->derive_key(out_shared_key, raw_shared, salt, {});
199 } else {
200 BOTAN_ASSERT_EQUAL(out_shared_key.size(), raw_kem_shared_key_length(), "Shared key has raw KEM output length");
201 this->raw_kem_encrypt(out_encapsulated_key, out_shared_key, rng);
202 }
203}
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:59
#define BOTAN_ASSERT_EQUAL(expr1, expr2, assertion_made)
Definition assert.h:68
#define BOTAN_ARG_CHECK(expr, msg)
Definition assert.h:29
virtual size_t raw_kem_shared_key_length() const =0
virtual void raw_kem_encrypt(std::span< uint8_t > out_encapsulated_key, std::span< uint8_t > out_raw_shared_key, RandomNumberGenerator &rng)=0
virtual size_t encapsulated_key_length() const =0
std::vector< T, secure_allocator< T > > secure_vector
Definition secmem.h:61

References BOTAN_ARG_CHECK, BOTAN_ASSERT_EQUAL, and BOTAN_ASSERT_NOMSG.

◆ mode()

virtual const KyberConstants & Botan::Kyber_KEM_Encryptor_Base::mode ( ) const
protectedpure virtual

◆ precomputed_matrix_At()

const KyberPolyMat & Botan::Kyber_KEM_Operation_Base::precomputed_matrix_At ( ) const
inlineprotectedinherited

◆ raw_kem_encrypt()

void Botan::Kyber_KEM_Encryptor_Base::raw_kem_encrypt ( std::span< uint8_t > out_encapsulated_key,
std::span< uint8_t > out_shared_key,
RandomNumberGenerator & rng )
inlinefinalvirtual

Implements Botan::PK_Ops::KEM_Encryption_with_KDF.

Definition at line 39 of file kyber_encaps_base.h.

41 {
42 encapsulate(StrongSpan<KyberCompressedCiphertext>(out_encapsulated_key),
43 StrongSpan<KyberSharedSecret>(out_shared_key),
44 rng);
45 }
virtual void encapsulate(StrongSpan< KyberCompressedCiphertext > out_encapsulated_key, StrongSpan< KyberSharedSecret > out_shared_key, RandomNumberGenerator &rng)=0

References encapsulate().

◆ raw_kem_shared_key_length()

size_t Botan::Kyber_KEM_Encryptor_Base::raw_kem_shared_key_length ( ) const
inlineoverridevirtual

Implements Botan::PK_Ops::KEM_Encryption_with_KDF.

Definition at line 35 of file kyber_encaps_base.h.

35{ return mode().shared_key_bytes(); }
constexpr size_t shared_key_bytes() const
byte length of the shared key

References mode(), and Botan::KyberConstants::shared_key_bytes().

◆ shared_key_length()

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

Implements Botan::PK_Ops::KEM_Encryption.

Definition at line 176 of file pk_ops.cpp.

176 {
177 if(m_kdf) {
178 return desired_shared_key_len;
179 } else {
180 return this->raw_kem_shared_key_length();
181 }
182}

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