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

#include <pubkey.h>

Inheritance diagram for Botan::PK_Encryptor_EME:
Botan::PK_Encryptor

Public Member Functions

size_t ciphertext_length (size_t ptext_len) const override
std::vector< uint8_t > encrypt (const uint8_t in[], size_t length, RandomNumberGenerator &rng) const
std::vector< uint8_t > encrypt (std::span< const uint8_t > in, RandomNumberGenerator &rng) const
size_t maximum_input_size () const override
PK_Encryptor_EME & operator= (const PK_Encryptor_EME &)=delete
PK_Encryptor_EME & operator= (PK_Encryptor_EME &&) noexcept
 PK_Encryptor_EME (const PK_Encryptor_EME &)=delete
 PK_Encryptor_EME (const Public_Key &key, RandomNumberGenerator &rng, const PK_Encryption_Options &options)
 PK_Encryptor_EME (const Public_Key &key, RandomNumberGenerator &rng, std::string_view padding, std::string_view provider="")
 PK_Encryptor_EME (PK_Encryptor_EME &&) noexcept
 ~PK_Encryptor_EME () override

Detailed Description

Encryption using a standard message recovery algorithm like RSA or ElGamal, paired with an encoding scheme like OAEP.

Definition at line 541 of file pubkey.h.

Constructor & Destructor Documentation

◆ PK_Encryptor_EME() [1/4]

Botan::PK_Encryptor_EME::PK_Encryptor_EME ( const Public_Key & key,
RandomNumberGenerator & rng,
const PK_Encryption_Options & options )

Construct an instance.

Parameters
keythe key to use inside the encryptor
Random Number Generatorsa RNG object which must outlive this operation object
optionscontrols the behavior of the encryption, eg which padding to use

Note that RSA requires the options to specify at least a padding scheme, and for OAEP also a hash function.

Definition at line 111 of file pubkey.cpp.

113 {
114 const PK_Encryption_Options_Reader reader(options);
115
116 m_op = key._create_encryption_op(rng, reader);
117 if(!m_op) {
118 throw Invalid_Argument(fmt("Key type {} does not support encryption", key.algo_name()));
119 }
120
121 reader.throw_if_unexamined(key.algo_name());
122}
std::string fmt(std::string_view format, const T &... args)
Definition fmt.h:53

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

Referenced by ciphertext_length(), operator=(), operator=(), PK_Encryptor_EME(), PK_Encryptor_EME(), and PK_Encryptor_EME().

◆ PK_Encryptor_EME() [2/4]

Botan::PK_Encryptor_EME::PK_Encryptor_EME ( const Public_Key & key,
RandomNumberGenerator & rng,
std::string_view padding,
std::string_view provider = "" )

Construct an instance.

Parameters
keythe key to use inside the encryptor
Random Number Generatorsa RNG object which must outlive this operation object
paddingthe message encoding scheme to use (eg "OAEP(SHA-256)")
providerthe provider to use

Definition at line 105 of file pubkey.cpp.

108 :
109 PK_Encryptor_EME(key, rng, parse_legacy_enc_options(key, padding).with_provider(provider)) {}
PK_Encryptor_EME(const Public_Key &key, RandomNumberGenerator &rng, const PK_Encryption_Options &options)
Definition pubkey.cpp:111
PK_Encryption_Options parse_legacy_enc_options(const Public_Key &key, std::string_view params)

References Botan::parse_legacy_enc_options(), and PK_Encryptor_EME().

◆ ~PK_Encryptor_EME()

Botan::PK_Encryptor_EME::~PK_Encryptor_EME ( )
overridedefault

◆ PK_Encryptor_EME() [3/4]

Botan::PK_Encryptor_EME::PK_Encryptor_EME ( const PK_Encryptor_EME & )
delete

References PK_Encryptor_EME().

◆ PK_Encryptor_EME() [4/4]

Botan::PK_Encryptor_EME::PK_Encryptor_EME ( PK_Encryptor_EME && )
defaultnoexcept

References PK_Encryptor_EME().

Member Function Documentation

◆ ciphertext_length()

size_t Botan::PK_Encryptor_EME::ciphertext_length ( size_t ptext_len) const
overridevirtual

Return an upper bound on the ciphertext length for a particular plaintext input length

Implements Botan::PK_Encryptor.

Definition at line 129 of file pubkey.cpp.

129 {
130 return m_op->ciphertext_length(ptext_len);
131}

References ciphertext_length(), and PK_Encryptor_EME().

Referenced by ciphertext_length(), and operator=().

◆ encrypt() [1/2]

std::vector< uint8_t > Botan::PK_Encryptor::encrypt ( const uint8_t in[],
size_t length,
RandomNumberGenerator & rng ) const
inlineinherited

Encrypt a message.

Parameters
inthe message as a byte array
lengththe length of the above byte array
Random Number Generatorsthe random number source to use
Returns
encrypted message

Definition at line 37 of file pubkey.h.

37 {
38 return enc(in, length, rng);
39 }

Referenced by Botan::TLS::Client_Key_Exchange::Client_Key_Exchange(), and Botan::KeyPair::encryption_consistency_check().

◆ encrypt() [2/2]

std::vector< uint8_t > Botan::PK_Encryptor::encrypt ( std::span< const uint8_t > in,
RandomNumberGenerator & rng ) const
inlineinherited

Encrypt a message.

Parameters
inthe message
Random Number Generatorsthe random number source to use
Returns
encrypted message

Definition at line 47 of file pubkey.h.

47 {
48 return enc(in.data(), in.size(), rng);
49 }

◆ maximum_input_size()

size_t Botan::PK_Encryptor_EME::maximum_input_size ( ) const
overridevirtual

Return the maximum allowed message size in bytes.

Returns
maximum message size in bytes

Implements Botan::PK_Encryptor.

Definition at line 137 of file pubkey.cpp.

137 {
138 return m_op->max_input_bits() / 8;
139}

Referenced by Botan::KeyPair::encryption_consistency_check().

◆ operator=() [1/2]

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

References PK_Encryptor_EME().

◆ operator=() [2/2]

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

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