Botan 2.1.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
11 #if defined(BOTAN_HAS_EME_OAEP)
12 #include <botan/oaep.h>
13 #endif
14
15 #if defined(BOTAN_HAS_EME_PKCS1v15)
16 #include <botan/eme_pkcs.h>
17 #endif
18
19 #if defined(BOTAN_HAS_EME_RAW)
20 #include <botan/eme_raw.h>
21 #endif
22
23 namespace Botan {
24
25 EME* get_eme(const std::string& algo_spec)
26 {
27 #if defined(BOTAN_HAS_EME_RAW)
28 if(algo_spec == "Raw")
29 return new EME_Raw;
30 #endif
31
32 #if defined(BOTAN_HAS_EME_PKCS1v15)
33 if(algo_spec == "PKCS1v15" || algo_spec == "EME-PKCS1-v1_5")
34 return new EME_PKCS1v15;
35 #endif
36
37 #if defined(BOTAN_HAS_EME_OAEP)
38 SCAN_Name req(algo_spec);
39
40 if(req.algo_name() == "OAEP" ||
41 req.algo_name() == "EME-OAEP" ||
42 req.algo_name() == "EME1")
43 {
44 if(req.arg_count() == 1 ||
45 (req.arg_count() == 2 && req.arg(1) == "MGF1"))
46 {
47 if(auto hash = HashFunction::create(req.arg(0)))
48 return new OAEP(hash.release());
49 }
50 }
51 #endif
52
53 throw Algorithm_Not_Found(algo_spec);
54 }
55
56 /*
57 * Encode a message
58 */
59 secure_vector<uint8_t> EME::encode(const uint8_t msg[], size_t msg_len,
60 size_t key_bits,
61 RandomNumberGenerator& rng) const
62 {
63 return pad(msg, msg_len, key_bits, rng);
64 }
65
66 /*
67 * Encode a message
68 */
69 secure_vector<uint8_t> EME::encode(const secure_vector<uint8_t>& msg,
70 size_t key_bits,
71 RandomNumberGenerator& rng) const
72 {
73 return pad(msg.data(), msg.size(), key_bits, rng);
74 }
75
76
77 }
Botan::SCAN_Name::arg
std::string arg(size_t i) const
Definition: scan_name.cpp:122
Botan::RandomNumberGenerator
Definition: rng.h:25
Botan::OAEP
Definition: oaep.h:19
Botan::SCAN_Name::arg_count
size_t arg_count() const
Definition: scan_name.h:50
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:19
Botan::secure_vector
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:121
Botan::HashFunction::create
static std::unique_ptr< HashFunction > create(const std::string &algo_spec, const std::string &provider="")
Definition: hash.cpp:93
Botan
Definition: alg_id.cpp:13
Botan::get_eme
EME * get_eme(const std::string &algo_spec)
Definition: eme.cpp:25
Botan::SCAN_Name
Definition: scan_name.h:22
Botan::EME_Raw
Definition: eme_raw.h:14
Botan::EME_PKCS1v15
Definition: eme_pkcs.h:18
Botan::SCAN_Name::algo_name
const std::string & algo_name() const
Definition: scan_name.h:45
Botan::Algorithm_Not_Found
Definition: exceptn.h:140
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:59
hash
MechanismType hash
Definition: p11_mechanism.cpp:63