Botan 2.13.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

eme.cpp
Go to the documentation of this file.
1 /*
2 * EME Base Class
3 * (C) 1999-2008 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7
8 #include <botan/eme.h>
9 #include <botan/scan_name.h>
10 #include <botan/exceptn.h>
11 #include <botan/parsing.h>
12
13 #if defined(BOTAN_HAS_EME_OAEP)
14 #include <botan/oaep.h>
15 #endif
16
17 #if defined(BOTAN_HAS_EME_PKCS1)
18 #include <botan/eme_pkcs.h>
19 #endif
20
21 #if defined(BOTAN_HAS_EME_RAW)
22 #include <botan/eme_raw.h>
23 #endif
24
25 namespace Botan {
26
27 EME* get_eme(const std::string& algo_spec)
28 {
29 #if defined(BOTAN_HAS_EME_RAW)
30 if(algo_spec == "Raw")
31 return new 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 new 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 new OAEP(hash.release(), 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 new OAEP(hash.release(), mgf1_hash.release(), req.arg(2, ""));
64 }
65 }
66 }
67 }
68 #endif
69
70 throw Algorithm_Not_Found(algo_spec);
71 }
72
73 /*
74 * Encode a message
75 */
76 secure_vector<uint8_t> EME::encode(const uint8_t msg[], size_t msg_len,
77 size_t key_bits,
78 RandomNumberGenerator& rng) const
79 {
80 return pad(msg, msg_len, key_bits, rng);
81 }
82
83 /*
84 * Encode a message
85 */
86 secure_vector<uint8_t> EME::encode(const secure_vector<uint8_t>& msg,
87 size_t key_bits,
88 RandomNumberGenerator& rng) const
89 {
90 return pad(msg.data(), msg.size(), key_bits, rng);
91 }
92
93
94 }
Botan::get_eme
EME * get_eme(const std::string &algo_spec)
Definition: eme.cpp:27
Botan::SCAN_Name::arg
std::string arg(size_t i) const
Definition: scan_name.cpp:124
Botan::RandomNumberGenerator
Definition: rng.h:24
Botan::OAEP
Definition: oaep.h:22
Botan::SCAN_Name::arg_count
size_t arg_count() const
Definition: scan_name.h:56
Botan::EME::pad
virtual secure_vector< uint8_t > pad(const uint8_t in[], size_t in_length, size_t key_length, RandomNumberGenerator &rng) const =0
Botan::EME
Definition: eme.h:23
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:65
Botan::HashFunction::create
static std::unique_ptr< HashFunction > create(const std::string &algo_spec, const std::string &provider="")
Definition: hash.cpp:106
Botan::parse_algorithm_name
std::vector< std::string > parse_algorithm_name(const std::string &namex)
Definition: parsing.cpp:95
Botan
Definition: alg_id.cpp:13
Botan::SCAN_Name
Definition: scan_name.h:23
Botan::EME_Raw
Definition: eme_raw.h:16
Botan::EME_PKCS1v15
Definition: eme_pkcs.h:20
Botan::SCAN_Name::algo_name
const std::string & algo_name() const
Definition: scan_name.h:51
Botan::EME::encode
secure_vector< uint8_t > encode(const uint8_t in[], size_t in_length, size_t key_length, RandomNumberGenerator &rng) const
Definition: eme.cpp:76
hash
MechanismType hash
Definition: p11_mechanism.cpp:64
Botan::Algorithm_Not_Found
Definition: exceptn.h:265