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

#include <oaep.h>

Inheritance diagram for Botan::OAEP:
Botan::EME

Public Member Functions

size_t maximum_input_size (size_t) const override
 
 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< EMEcreate (std::string_view algo_spec)
 

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 22 of file oaep.h.

Constructor & Destructor Documentation

◆ OAEP() [1/2]

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

Definition at line 149 of file oaep.cpp.

149 : m_mgf1_hash(std::move(hash)) {
150 m_Phash = m_mgf1_hash->process(P);
151}

◆ OAEP() [2/2]

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

Definition at line 153 of file oaep.cpp.

153 :
154 m_mgf1_hash(std::move(mgf1_hash)) {
155 auto phash = std::move(hash);
156 m_Phash = phash->process(P);
157}

Member Function Documentation

◆ create()

std::unique_ptr< EME > Botan::EME::create ( std::string_view algo_spec)
staticinherited

Factory method for EME (message-encoding methods for encryption) objects

Parameters
algo_specthe name of the EME to create
Returns
pointer to newly allocated object of that type

Definition at line 28 of file eme.cpp.

28 {
29#if defined(BOTAN_HAS_EME_RAW)
30 if(algo_spec == "Raw") {
31 return std::make_unique<EME_Raw>();
32 }
33#endif
34
35#if defined(BOTAN_HAS_EME_PKCS1)
36 if(algo_spec == "PKCS1v15" || algo_spec == "EME-PKCS1-v1_5") {
37 return std::make_unique<EME_PKCS1v15>();
38 }
39#endif
40
41#if defined(BOTAN_HAS_EME_OAEP)
42 SCAN_Name req(algo_spec);
43
44 if(req.algo_name() == "OAEP" || req.algo_name() == "EME-OAEP" || req.algo_name() == "EME1") {
45 if(req.arg_count() == 1 || ((req.arg_count() == 2 || req.arg_count() == 3) && req.arg(1) == "MGF1")) {
46 if(auto hash = HashFunction::create(req.arg(0))) {
47 return std::make_unique<OAEP>(std::move(hash), req.arg(2, ""));
48 }
49 } else if(req.arg_count() == 2 || req.arg_count() == 3) {
50 auto mgf_params = parse_algorithm_name(req.arg(1));
51
52 if(mgf_params.size() == 2 && mgf_params[0] == "MGF1") {
53 auto hash = HashFunction::create(req.arg(0));
54 auto mgf1_hash = HashFunction::create(mgf_params[1]);
55
56 if(hash && mgf1_hash) {
57 return std::make_unique<OAEP>(std::move(hash), std::move(mgf1_hash), req.arg(2, ""));
58 }
59 }
60 }
61 }
62#endif
63
64 throw Algorithm_Not_Found(algo_spec);
65}
static std::unique_ptr< HashFunction > create(std::string_view algo_spec, std::string_view provider="")
Definition hash.cpp:107
std::vector< std::string > parse_algorithm_name(std::string_view namex)
Definition parsing.cpp:57

References Botan::SCAN_Name::algo_name(), Botan::SCAN_Name::arg(), Botan::SCAN_Name::arg_count(), Botan::HashFunction::create(), and Botan::parse_algorithm_name().

◆ 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::EME.

Definition at line 141 of file oaep.cpp.

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

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