Coverage Report

Created: 2020-11-21 08:34

/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/internal/eme.h>
9
#include <botan/scan_name.h>
10
#include <botan/exceptn.h>
11
#include <botan/internal/parsing.h>
12
13
#if defined(BOTAN_HAS_EME_OAEP)
14
#include <botan/internal/oaep.h>
15
#endif
16
17
#if defined(BOTAN_HAS_EME_PKCS1)
18
#include <botan/internal/eme_pkcs.h>
19
#endif
20
21
#if defined(BOTAN_HAS_EME_RAW)
22
#include <botan/internal/eme_raw.h>
23
#endif
24
25
namespace Botan {
26
27
EME* get_eme(const std::string& algo_spec)
28
64
   {
29
64
#if defined(BOTAN_HAS_EME_RAW)
30
64
   if(algo_spec == "Raw")
31
0
      return new EME_Raw;
32
64
#endif
33
34
64
#if defined(BOTAN_HAS_EME_PKCS1)
35
64
   if(algo_spec == "PKCS1v15" || algo_spec == "EME-PKCS1-v1_5")
36
64
      return new EME_PKCS1v15;
37
0
#endif
38
39
0
#if defined(BOTAN_HAS_EME_OAEP)
40
0
   SCAN_Name req(algo_spec);
41
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
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
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
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
64
   {
80
64
   return pad(msg, msg_len, key_bits, rng);
81
64
   }
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
}