Botan  2.1.0
Crypto and TLS for C++11
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 */
70  size_t key_bits,
71  RandomNumberGenerator& rng) const
72  {
73  return pad(msg.data(), msg.size(), key_bits, rng);
74  }
75 
76 
77 }
std::string arg(size_t i) const
Definition: scan_name.cpp:122
size_t arg_count() const
Definition: scan_name.h:50
virtual secure_vector< uint8_t > pad(const uint8_t in[], size_t in_length, size_t key_length, RandomNumberGenerator &rng) const =0
Definition: eme.h:19
std::vector< T, secure_allocator< T >> secure_vector
Definition: secmem.h:121
static std::unique_ptr< HashFunction > create(const std::string &algo_spec, const std::string &provider="")
Definition: hash.cpp:93
Definition: alg_id.cpp:13
EME * get_eme(const std::string &algo_spec)
Definition: eme.cpp:25
const std::string & algo_name() const
Definition: scan_name.h:45
secure_vector< uint8_t > encode(const uint8_t in[], size_t in_length, size_t key_length, RandomNumberGenerator &rng) const
Definition: eme.cpp:59
MechanismType hash