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

#include <oaep.h>

Inheritance diagram for Botan::OAEP:
Botan::EncryptionPaddingScheme

Public Member Functions

size_t maximum_input_size (size_t keybits) const override
 OAEP (const PK_Encryption_Options_Reader &options)
 OAEP (std::unique_ptr< HashFunction > hash, std::string_view P="")
 OAEP (std::unique_ptr< HashFunction > hash, std::unique_ptr< HashFunction > mgf1_hash, std::string_view P="")

Static Public Member Functions

static std::unique_ptr< EncryptionPaddingScheme > create_or_throw (const PK_Encryption_Options_Reader &options)

Detailed Description

OAEP (called EME1 in IEEE 1363 and in earlier versions of the library) as specified in PKCS#1 v2.0 (RFC 2437) or PKCS#1 v2.1 (RFC 3447)

Definition at line 24 of file oaep.h.

Constructor & Destructor Documentation

◆ OAEP() [1/3]

Botan::OAEP::OAEP ( const PK_Encryption_Options_Reader & options)
explicit
Parameters
optionsmust specify the hash; may specify a distinct MGF1 hash and a label (as the context)

Definition at line 150 of file oaep.cpp.

150 {
151 if(!options.using_hash()) {
152 throw Lookup_Error("OAEP requires specifying a hash function");
153 }
154
155 auto hash = HashFunction::create_or_throw(options.hash_function_name());
156
157 if(options.using_mgf1_hash()) {
158 m_mgf1_hash = HashFunction::create_or_throw(options.mgf1_hash_function().value());
159 } else {
160 m_mgf1_hash = hash->new_object();
161 }
162
163 // The label is optional and defaults to empty
164 if(const auto& label = options.context()) {
165 hash->update(*label);
166 }
167 m_Phash = hash->final();
168}
static std::unique_ptr< HashFunction > create_or_throw(std::string_view algo_spec, std::string_view provider="")
Definition hash.cpp:311

References Botan::PK_Encryption_Options_Reader::context(), Botan::HashFunction::create_or_throw(), Botan::PK_Encryption_Options_Reader::hash_function_name(), Botan::PK_Encryption_Options_Reader::mgf1_hash_function(), Botan::PK_Encryption_Options_Reader::using_hash(), and Botan::PK_Encryption_Options_Reader::using_mgf1_hash().

◆ OAEP() [2/3]

Botan::OAEP::OAEP ( std::unique_ptr< HashFunction > hash,
std::string_view P = "" )
explicit
Parameters
Hashesfunction to use for hashing (takes ownership)
Pan optional label. Normally empty.

Definition at line 170 of file oaep.cpp.

170 : m_mgf1_hash(std::move(hash)) {
171 m_Phash = m_mgf1_hash->process(P);
172}

◆ OAEP() [3/3]

Botan::OAEP::OAEP ( std::unique_ptr< HashFunction > hash,
std::unique_ptr< HashFunction > mgf1_hash,
std::string_view P = "" )
Parameters
Hashesfunction to use for hashing (takes ownership)
mgf1_hashfunction to use for MGF1 (takes ownership)
Pan optional label. Normally empty.

Definition at line 174 of file oaep.cpp.

174 :
175 m_mgf1_hash(std::move(mgf1_hash)) {
176 auto phash = std::move(hash);
177 m_Phash = phash->process(P);
178}

Member Function Documentation

◆ create_or_throw()

std::unique_ptr< EncryptionPaddingScheme > Botan::EncryptionPaddingScheme::create_or_throw ( const PK_Encryption_Options_Reader & options)
staticinherited

Factory method for encryption padding schemes

Parameters
optionsthe padding scheme and its parameters
Returns
pointer to newly allocated object of that type, or throws

Definition at line 26 of file enc_padding.cpp.

27 {
28 // Encrypting without padding is dangerous, so it must be requested explicitly
29 if(!options.using_padding()) {
30 throw Lookup_Error("Public key encryption requires specifying a padding scheme");
31 }
32
33 const std::string& padding = options.padding().value();
34
35 // Any option not examined by the selected scheme is rejected by the caller
36
37#if defined(BOTAN_HAS_EME_RAW)
38 if(padding == "Raw") {
39 return std::make_unique<EME_Raw>();
40 }
41#endif
42
43#if defined(BOTAN_HAS_EME_PKCS1)
44 if(padding == "PKCS1v15") {
45 return std::make_unique<EME_PKCS1v15>();
46 }
47#endif
48
49#if defined(BOTAN_HAS_EME_OAEP)
50 if(padding == "OAEP") {
51 return std::make_unique<OAEP>(options);
52 }
53#endif
54
55 throw Lookup_Error("Invalid or unavailable encryption padding scheme " + options.to_string());
56}

References Botan::PK_Encryption_Options_Reader::padding(), Botan::PK_Encryption_Options_Reader::to_string(), and Botan::PK_Encryption_Options_Reader::using_padding().

Referenced by ~EncryptionPaddingScheme().

◆ maximum_input_size()

size_t Botan::OAEP::maximum_input_size ( size_t keybits) const
overridevirtual

Return the maximum input size in bytes we can support

Parameters
keybitsthe size of the key in bits
Returns
upper bound of input in bytes

Implements Botan::EncryptionPaddingScheme.

Definition at line 142 of file oaep.cpp.

142 {
143 if(keybits / 8 > 2 * m_Phash.size() + 1) {
144 return ((keybits / 8) - 2 * m_Phash.size() - 1);
145 } else {
146 return 0;
147 }
148}

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