Coverage Report

Created: 2021-10-13 08:49

/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/internal/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
std::unique_ptr<EME> EME::create(const std::string& algo_spec)
28
0
   {
29
0
#if defined(BOTAN_HAS_EME_RAW)
30
0
   if(algo_spec == "Raw")
31
0
      return std::make_unique<EME_Raw>();
32
0
#endif
33
34
0
#if defined(BOTAN_HAS_EME_PKCS1)
35
0
   if(algo_spec == "PKCS1v15" || algo_spec == "EME-PKCS1-v1_5")
36
0
      return std::make_unique<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 std::make_unique<OAEP>(std::move(hash), 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 std::make_unique<OAEP>(std::move(hash),
64
0
                                             std::move(mgf1_hash),
65
0
                                             req.arg(2, ""));
66
0
               }
67
0
            }
68
0
         }
69
0
      }
70
0
#endif
71
72
0
   throw Algorithm_Not_Found(algo_spec);
73
0
   }
74
75
/*
76
* Encode a message
77
*/
78
secure_vector<uint8_t> EME::encode(const uint8_t msg[], size_t msg_len,
79
                                size_t key_bits,
80
                                RandomNumberGenerator& rng) const
81
0
   {
82
0
   return pad(msg, msg_len, key_bits, rng);
83
0
   }
84
85
/*
86
* Encode a message
87
*/
88
secure_vector<uint8_t> EME::encode(const secure_vector<uint8_t>& msg,
89
                                size_t key_bits,
90
                                RandomNumberGenerator& rng) const
91
0
   {
92
0
   return pad(msg.data(), msg.size(), key_bits, rng);
93
0
   }
94
95
96
}