Coverage Report

Created: 2020-06-30 13:58

/src/botan/src/lib/pk_pad/eme.cpp
Line
Count
Source (jump to first uncovered line)
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
63
   {
29
63
#if defined(BOTAN_HAS_EME_RAW)
30
63
   if(algo_spec == "Raw")
31
0
      return new EME_Raw;
32
63
#endif
33
63
34
63
#if defined(BOTAN_HAS_EME_PKCS1)
35
63
   if(algo_spec == "PKCS1v15" || algo_spec == "EME-PKCS1-v1_5")
36
63
      return new EME_PKCS1v15;
37
0
#endif
38
0
39
0
#if defined(BOTAN_HAS_EME_OAEP)
40
0
   SCAN_Name req(algo_spec);
41
0
42
0
   if(req.algo_name() == "OAEP" ||
43
0
      req.algo_name() == "EME-OAEP" ||
44
0
      req.algo_name() == "EME1")
45
0
      {
46
0
      if(req.arg_count() == 1 ||
47
0
         ((req.arg_count() == 2 || req.arg_count() == 3) && req.arg(1) == "MGF1"))
48
0
         {
49
0
         if(auto hash = HashFunction::create(req.arg(0)))
50
0
            return new OAEP(hash.release(), req.arg(2, ""));
51
0
         }
52
0
      else if(req.arg_count() == 2 || req.arg_count() == 3)
53
0
         {
54
0
         auto mgf_params = parse_algorithm_name(req.arg(1));
55
0
56
0
         if(mgf_params.size() == 2 && mgf_params[0] == "MGF1")
57
0
            {
58
0
            auto hash = HashFunction::create(req.arg(0));
59
0
            auto mgf1_hash = HashFunction::create(mgf_params[1]);
60
0
61
0
            if(hash && mgf1_hash)
62
0
               {
63
0
               return new OAEP(hash.release(), mgf1_hash.release(), req.arg(2, ""));
64
0
               }
65
0
            }
66
0
         }
67
0
      }
68
0
#endif
69
0
70
0
   throw Algorithm_Not_Found(algo_spec);
71
0
   }
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
62
   {
80
62
   return pad(msg, msg_len, key_bits, rng);
81
62
   }
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
0
   {
90
0
   return pad(msg.data(), msg.size(), key_bits, rng);
91
0
   }
92
93
94
}