Botan 3.0.0-alpha0
Crypto and TLS for C&
Public Member Functions | Static Public Member Functions | List of all members
Botan::OAEP Class Referencefinal

#include <oaep.h>

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

Public Member Functions

secure_vector< uint8_t > encode (const secure_vector< uint8_t > &in, size_t key_length, RandomNumberGenerator &rng) const
 
secure_vector< uint8_t > encode (const uint8_t in[], size_t in_length, size_t key_length, RandomNumberGenerator &rng) const
 
size_t maximum_input_size (size_t) const override
 
 OAEP (std::unique_ptr< HashFunction > hash, const std::string &P="")
 
 OAEP (std::unique_ptr< HashFunction > hash, std::unique_ptr< HashFunction > mgf1_hash, const std::string &P="")
 

Static Public Member Functions

static std::unique_ptr< EMEcreate (const std::string &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 20 of file oaep.h.

Constructor & Destructor Documentation

◆ OAEP() [1/2]

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

Definition at line 152 of file oaep.cpp.

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

◆ OAEP() [2/2]

Botan::OAEP::OAEP ( std::unique_ptr< HashFunction hash,
std::unique_ptr< HashFunction mgf1_hash,
const std::string &  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 159 of file oaep.cpp.

161 :
162 m_mgf1_hash(std::move(mgf1_hash))
163 {
164 auto phash = std::move(hash);
165 m_Phash = phash->process(P);
166 }

References hash.

Member Function Documentation

◆ create()

std::unique_ptr< EME > Botan::EME::create ( const std::string &  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 27 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#endif
33
34#if defined(BOTAN_HAS_EME_PKCS1)
35 if(algo_spec == "PKCS1v15" || algo_spec == "EME-PKCS1-v1_5")
36 return std::make_unique<EME_PKCS1v15>();
37#endif
38
39#if defined(BOTAN_HAS_EME_OAEP)
40 SCAN_Name req(algo_spec);
41
42 if(req.algo_name() == "OAEP" ||
43 req.algo_name() == "EME-OAEP" ||
44 req.algo_name() == "EME1")
45 {
46 if(req.arg_count() == 1 ||
47 ((req.arg_count() == 2 || req.arg_count() == 3) && req.arg(1) == "MGF1"))
48 {
49 if(auto hash = HashFunction::create(req.arg(0)))
50 return std::make_unique<OAEP>(std::move(hash), req.arg(2, ""));
51 }
52 else if(req.arg_count() == 2 || req.arg_count() == 3)
53 {
54 auto mgf_params = parse_algorithm_name(req.arg(1));
55
56 if(mgf_params.size() == 2 && mgf_params[0] == "MGF1")
57 {
58 auto hash = HashFunction::create(req.arg(0));
59 auto mgf1_hash = HashFunction::create(mgf_params[1]);
60
61 if(hash && mgf1_hash)
62 {
63 return std::make_unique<OAEP>(std::move(hash),
64 std::move(mgf1_hash),
65 req.arg(2, ""));
66 }
67 }
68 }
69 }
70#endif
71
72 throw Algorithm_Not_Found(algo_spec);
73 }
static std::unique_ptr< HashFunction > create(const std::string &algo_spec, const std::string &provider="")
Definition: hash.cpp:98
std::vector< std::string > parse_algorithm_name(const std::string &namex)
Definition: parsing.cpp:58

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

◆ encode() [1/2]

secure_vector< uint8_t > Botan::EME::encode ( const secure_vector< uint8_t > &  in,
size_t  key_length,
RandomNumberGenerator rng 
) const
inherited

Encode an input

Parameters
inthe plaintext
key_lengthlength of the key in bits
rnga random number generator
Returns
encoded plaintext

Definition at line 88 of file eme.cpp.

91 {
92 return pad(msg.data(), msg.size(), key_bits, rng);
93 }
virtual secure_vector< uint8_t > pad(const uint8_t in[], size_t in_length, size_t key_length, RandomNumberGenerator &rng) const =0

References Botan::EME::pad().

◆ encode() [2/2]

secure_vector< uint8_t > Botan::EME::encode ( const uint8_t  in[],
size_t  in_length,
size_t  key_length,
RandomNumberGenerator rng 
) const
inherited

Encode an input

Parameters
inthe plaintext
in_lengthlength of plaintext in bytes
key_lengthlength of the key in bits
rnga random number generator
Returns
encoded plaintext

Definition at line 78 of file eme.cpp.

81 {
82 return pad(msg, msg_len, key_bits, rng);
83 }

References Botan::EME::pad().

◆ 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 144 of file oaep.cpp.

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

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