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

randombit / botan / 29673219783

18 Jul 2026 10:42PM UTC coverage: 89.416% (+0.009%) from 89.407%
29673219783

push

github

randombit
Fix EC_Scalar_Data_BN::square_self

It computed the square then failed to update the stored value

114352 of 127887 relevant lines covered (89.42%)

10766049.99 hits per line

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

95.77
/src/lib/modes/cipher_mode.cpp
1
/*
2
* Cipher Modes
3
* (C) 2015 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include <botan/cipher_mode.h>
9

10
#include <botan/exceptn.h>
11
#include <botan/internal/parsing.h>
12
#include <botan/internal/scan_name.h>
13
#include <botan/internal/stream_mode.h>
14
#include <memory>
15
#include <sstream>
16
#include <utility>
17

18
#if defined(BOTAN_HAS_BLOCK_CIPHER)
19
   #include <botan/block_cipher.h>
20
#endif
21

22
#if defined(BOTAN_HAS_AEAD_MODES)
23
   #include <botan/aead.h>
24
#endif
25

26
#if defined(BOTAN_HAS_MODE_CBC)
27
   #include <botan/internal/cbc.h>
28
#endif
29

30
#if defined(BOTAN_HAS_MODE_CFB)
31
   #include <botan/internal/cfb.h>
32
#endif
33

34
#if defined(BOTAN_HAS_MODE_XTS)
35
   #include <botan/internal/xts.h>
36
#endif
37

38
#if defined(BOTAN_HAS_COMMONCRYPTO)
39
   #include <botan/internal/commoncrypto.h>
40
#endif
41

42
namespace Botan {
43

44
std::unique_ptr<Cipher_Mode> Cipher_Mode::create_or_throw(std::string_view algo,
285✔
45
                                                          Cipher_Dir direction,
46
                                                          std::string_view provider) {
47
   if(auto mode = Cipher_Mode::create(algo, direction, provider)) {
285✔
48
      return mode;
284✔
49
   }
284✔
50

51
   throw Lookup_Error("Cipher mode", algo, provider);
1✔
52
}
53

54
std::unique_ptr<Cipher_Mode> Cipher_Mode::create(std::string_view algo,
14,329✔
55
                                                 Cipher_Dir direction,
56
                                                 std::string_view provider) {
57
#if defined(BOTAN_HAS_COMMONCRYPTO)
58
   if(provider.empty() || provider == "commoncrypto") {
59
      if(auto cm = make_commoncrypto_cipher_mode(algo, direction))
60
         return cm;
61

62
      if(!provider.empty())
63
         return nullptr;
64
   }
65
#endif
66

67
   if(provider != "base" && !provider.empty()) {
21,805✔
68
      return nullptr;
1,250✔
69
   }
70

71
#if defined(BOTAN_HAS_STREAM_CIPHER)
72
   if(auto sc = StreamCipher::create(algo)) {
13,079✔
73
      return std::make_unique<Stream_Cipher_Mode>(std::move(sc));
51✔
74
   }
51✔
75
#endif
76

77
#if defined(BOTAN_HAS_AEAD_MODES)
78
   if(auto aead = AEAD_Mode::create(algo, direction)) {
13,028✔
79
      return aead;
663✔
80
   }
663✔
81
#endif
82

83
   if(algo.find('/') != std::string::npos) {
12,365✔
84
      const std::vector<std::string> algo_parts = split_on(algo, '/');
6,049✔
85
      if(algo_parts.size() < 2) {
6,049✔
86
         return std::unique_ptr<Cipher_Mode>();
×
87
      }
88
      const std::string_view cipher_name = algo_parts[0];
6,049✔
89
      const std::vector<std::string> mode_info = parse_algorithm_name(algo_parts[1]);
6,049✔
90

91
      if(mode_info.empty()) {
6,049✔
92
         return std::unique_ptr<Cipher_Mode>();
×
93
      }
94

95
      std::ostringstream mode_name;
6,049✔
96

97
      mode_name << mode_info[0] << '(' << cipher_name;
6,049✔
98
      for(size_t i = 1; i < mode_info.size(); ++i) {
6,281✔
99
         mode_name << ',' << mode_info[i];
232✔
100
      }
101
      for(size_t i = 2; i < algo_parts.size(); ++i) {
7,503✔
102
         mode_name << ',' << algo_parts[i];
1,454✔
103
      }
104
      mode_name << ')';
6,049✔
105

106
      return Cipher_Mode::create(mode_name.str(), direction, provider);
6,049✔
107
   }
6,049✔
108

109
#if defined(BOTAN_HAS_BLOCK_CIPHER)
110

111
   const SCAN_Name spec(algo);
6,316✔
112

113
   if(spec.arg_count() == 0) {
6,316✔
114
      return std::unique_ptr<Cipher_Mode>();
1✔
115
   }
116

117
   auto bc = BlockCipher::create(spec.arg(0), provider);
6,315✔
118

119
   if(!bc) {
6,315✔
120
      return std::unique_ptr<Cipher_Mode>();
2✔
121
   }
122

123
   #if defined(BOTAN_HAS_MODE_CBC)
124
   if(spec.algo_name() == "CBC") {
6,313✔
125
      const std::string padding = spec.arg(1, "PKCS7");
2,786✔
126

127
      if(padding == "CTS") {
2,786✔
128
         if(direction == Cipher_Dir::Encryption) {
218✔
129
            return std::make_unique<CTS_Encryption>(std::move(bc));
133✔
130
         } else {
131
            return std::make_unique<CTS_Decryption>(std::move(bc));
85✔
132
         }
133
      } else {
134
         auto pad = BlockCipherModePaddingMethod::create(padding);
2,568✔
135

136
         if(pad) {
2,568✔
137
            if(direction == Cipher_Dir::Encryption) {
2,568✔
138
               return std::make_unique<CBC_Encryption>(std::move(bc), std::move(pad));
1,550✔
139
            } else {
140
               return std::make_unique<CBC_Decryption>(std::move(bc), std::move(pad));
1,018✔
141
            }
142
         }
143
      }
2,568✔
144
   }
2,786✔
145
   #endif
146

147
   #if defined(BOTAN_HAS_MODE_XTS)
148
   if(spec.algo_name() == "XTS") {
3,527✔
149
      if(direction == Cipher_Dir::Encryption) {
2,822✔
150
         return std::make_unique<XTS_Encryption>(std::move(bc));
1,829✔
151
      } else {
152
         return std::make_unique<XTS_Decryption>(std::move(bc));
993✔
153
      }
154
   }
155
   #endif
156

157
   #if defined(BOTAN_HAS_MODE_CFB)
158
   if(spec.algo_name() == "CFB") {
705✔
159
      const size_t feedback_bits = spec.arg_as_integer(1, 8 * bc->block_size());
705✔
160
      if(direction == Cipher_Dir::Encryption) {
705✔
161
         return std::make_unique<CFB_Encryption>(std::move(bc), feedback_bits);
340✔
162
      } else {
163
         return std::make_unique<CFB_Decryption>(std::move(bc), feedback_bits);
365✔
164
      }
165
   }
166
   #endif
167

168
#endif
169

170
   return std::unique_ptr<Cipher_Mode>();
×
171
}
6,316✔
172

173
//static
174
std::vector<std::string> Cipher_Mode::providers(std::string_view algo_spec) {
1,250✔
175
   const std::vector<std::string>& possible = {"base", "commoncrypto"};
1,250✔
176
   std::vector<std::string> providers;
1,250✔
177
   for(auto&& prov : possible) {
3,750✔
178
      auto mode = Cipher_Mode::create(algo_spec, Cipher_Dir::Encryption, prov);
2,500✔
179
      if(mode) {
2,500✔
180
         providers.push_back(prov);  // available
1,248✔
181
      }
182
   }
2,500✔
183
   return providers;
1,250✔
184
}
1,250✔
185

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

© 2026 Coveralls, Inc