• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 12976978465

26 Jan 2025 05:48PM UTC coverage: 91.26% (+0.004%) from 91.256%
12976978465

Pull #4600

github

web-flow
Merge 8a3c2576f into 9beda9f0f
Pull Request #4600: Avoid using IEEE 1363 EMSA names in OID data or EMSA::name

93990 of 102992 relevant lines covered (91.26%)

11458809.91 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.55
/src/lib/pk_pad/emsa.cpp
1
/*
2
* (C) 2015 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6

7
#include <botan/internal/emsa.h>
8

9
#include <botan/exceptn.h>
10
#include <botan/hash.h>
11
#include <botan/internal/scan_name.h>
12

13
#if defined(BOTAN_HAS_EMSA_X931)
14
   #include <botan/internal/emsa_x931.h>
15
#endif
16

17
#if defined(BOTAN_HAS_EMSA_PKCS1)
18
   #include <botan/internal/emsa_pkcs1.h>
19
#endif
20

21
#if defined(BOTAN_HAS_EMSA_PSSR)
22
   #include <botan/internal/pssr.h>
23
#endif
24

25
#if defined(BOTAN_HAS_EMSA_RAW)
26
   #include <botan/internal/emsa_raw.h>
27
#endif
28

29
#if defined(BOTAN_HAS_ISO_9796)
30
   #include <botan/internal/iso9796.h>
31
#endif
32

33
namespace Botan {
34

35
std::unique_ptr<EMSA> EMSA::create(std::string_view algo_spec) {
16,092✔
36
   SCAN_Name req(algo_spec);
16,092✔
37

38
#if defined(BOTAN_HAS_EMSA_PKCS1)
39
   // TODO(Botan4) Remove all but "PKCS1v15"
40
   if(req.algo_name() == "EMSA_PKCS1" || req.algo_name() == "PKCS1v15" || req.algo_name() == "EMSA-PKCS1-v1_5" ||
16,092✔
41
      req.algo_name() == "EMSA3") {
3,434✔
42
      if(req.arg_count() == 2 && req.arg(0) == "Raw") {
12,716✔
43
         return std::make_unique<EMSA_PKCS1v15_Raw>(req.arg(1));
4✔
44
      } else if(req.arg_count() == 1) {
12,712✔
45
         if(req.arg(0) == "Raw") {
12,712✔
46
            return std::make_unique<EMSA_PKCS1v15_Raw>();
12✔
47
         } else {
48
            if(auto hash = HashFunction::create(req.arg(0))) {
25,400✔
49
               return std::make_unique<EMSA_PKCS1v15>(std::move(hash));
12,699✔
50
            }
12,700✔
51
         }
52
      }
53
   }
54
#endif
55

56
#if defined(BOTAN_HAS_EMSA_PSSR)
57
   // TODO(Botan4) Remove all but "PSS_Raw"
58
   if(req.algo_name() == "PSS_Raw" || req.algo_name() == "PSSR_Raw") {
3,377✔
59
      if(req.arg_count_between(1, 3) && req.arg(1, "MGF1") == "MGF1") {
326✔
60
         if(auto hash = HashFunction::create(req.arg(0))) {
326✔
61
            if(req.arg_count() == 3) {
162✔
62
               const size_t salt_size = req.arg_as_integer(2, 0);
161✔
63
               return std::make_unique<PSSR_Raw>(std::move(hash), salt_size);
161✔
64
            } else {
65
               return std::make_unique<PSSR_Raw>(std::move(hash));
1✔
66
            }
67
         }
163✔
68
      }
69
   }
70

71
   // TODO(Botan4) Remove all but "PSS"
72
   if(req.algo_name() == "PSS" || req.algo_name() == "PSSR" || req.algo_name() == "EMSA-PSS" ||
3,215✔
73
      req.algo_name() == "PSS-MGF1" || req.algo_name() == "EMSA4") {
3,516✔
74
      if(req.arg_count_between(1, 3) && req.arg(1, "MGF1") == "MGF1") {
5,870✔
75
         if(auto hash = HashFunction::create(req.arg(0))) {
5,868✔
76
            if(req.arg_count() == 3) {
2,933✔
77
               const size_t salt_size = req.arg_as_integer(2, 0);
2,471✔
78
               return std::make_unique<PSSR>(std::move(hash), salt_size);
2,471✔
79
            } else {
80
               return std::make_unique<PSSR>(std::move(hash));
462✔
81
            }
82
         }
2,934✔
83
      }
84
   }
85
#endif
86

87
#if defined(BOTAN_HAS_ISO_9796)
88
   if(req.algo_name() == "ISO_9796_DS2") {
282✔
89
      if(req.arg_count_between(1, 3)) {
9✔
90
         if(auto hash = HashFunction::create(req.arg(0))) {
18✔
91
            const size_t salt_size = req.arg_as_integer(2, hash->output_length());
8✔
92
            const bool implicit = req.arg(1, "exp") == "imp";
8✔
93
            return std::make_unique<ISO_9796_DS2>(std::move(hash), implicit, salt_size);
8✔
94
         }
9✔
95
      }
96
   }
97
   //ISO-9796-2 DS 3 is deterministic and DS2 without a salt
98
   if(req.algo_name() == "ISO_9796_DS3") {
274✔
99
      if(req.arg_count_between(1, 2)) {
9✔
100
         if(auto hash = HashFunction::create(req.arg(0))) {
18✔
101
            const bool implicit = req.arg(1, "exp") == "imp";
8✔
102
            return std::make_unique<ISO_9796_DS3>(std::move(hash), implicit);
8✔
103
         }
9✔
104
      }
105
   }
106
#endif
107

108
#if defined(BOTAN_HAS_EMSA_X931)
109
   // TODO(Botan4) Remove all but "X9.31"
110
   if(req.algo_name() == "EMSA_X931" || req.algo_name() == "EMSA2" || req.algo_name() == "X9.31") {
266✔
111
      if(req.arg_count() == 1) {
57✔
112
         if(auto hash = HashFunction::create(req.arg(0))) {
112✔
113
            return std::make_unique<EMSA_X931>(std::move(hash));
55✔
114
         }
56✔
115
      }
116
   }
117
#endif
118

119
#if defined(BOTAN_HAS_EMSA_RAW)
120
   if(req.algo_name() == "Raw") {
211✔
121
      if(req.arg_count() == 0) {
202✔
122
         return std::make_unique<EMSA_Raw>();
202✔
123
      } else {
124
         auto hash = HashFunction::create(req.arg(0));
×
125
         if(hash) {
×
126
            return std::make_unique<EMSA_Raw>(hash->output_length());
×
127
         }
128
      }
×
129
   }
130
#endif
131

132
   return nullptr;
9✔
133
}
16,092✔
134

135
std::unique_ptr<EMSA> EMSA::create_or_throw(std::string_view algo_spec) {
16,074✔
136
   auto emsa = EMSA::create(algo_spec);
16,074✔
137
   if(emsa) {
16,074✔
138
      return emsa;
16,065✔
139
   }
140
   throw Algorithm_Not_Found(algo_spec);
9✔
141
}
9✔
142

143
}  // namespace Botan
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc