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

randombit / botan / 5123321399

30 May 2023 04:06PM UTC coverage: 92.213% (+0.004%) from 92.209%
5123321399

Pull #3558

github

web-flow
Merge dd72f7389 into 057bcbc35
Pull Request #3558: Add braces around all if/else statements

75602 of 81986 relevant lines covered (92.21%)

11859779.3 hits per line

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

97.78
/src/lib/stream/stream_cipher.cpp
1
/*
2
* Stream Ciphers
3
* (C) 2015,2016 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include <botan/stream_cipher.h>
9

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

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

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

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

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

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

33
#if defined(BOTAN_HAS_RC4)
34
   #include <botan/internal/rc4.h>
35
#endif
36

37
namespace Botan {
38

39
std::unique_ptr<StreamCipher> StreamCipher::create(std::string_view algo_spec, std::string_view provider) {
133,963✔
40
#if defined(BOTAN_HAS_SHAKE_CIPHER)
41
   if(algo_spec == "SHAKE-128" || algo_spec == "SHAKE-128-XOF") {
139,677✔
42
      if(provider.empty() || provider == "base") {
4,580✔
43
         return std::make_unique<SHAKE_128_Cipher>();
2,290✔
44
      }
45
   }
46

47
   if(algo_spec == "SHAKE-256" || algo_spec == "SHAKE-256-XOF") {
135,097✔
48
      if(provider.empty() || provider == "base") {
4,580✔
49
         return std::make_unique<SHAKE_256_Cipher>();
2,290✔
50
      }
51
   }
52
#endif
53

54
#if defined(BOTAN_HAS_CHACHA)
55
   if(algo_spec == "ChaCha20") {
129,521✔
56
      if(provider.empty() || provider == "base") {
6✔
57
         return std::make_unique<ChaCha>(20);
3✔
58
      }
59
   }
60
#endif
61

62
#if defined(BOTAN_HAS_SALSA20)
63
   if(algo_spec == "Salsa20") {
129,550✔
64
      if(provider.empty() || provider == "base") {
56✔
65
         return std::make_unique<Salsa20>();
32✔
66
      }
67
   }
68
#endif
69

70
   const SCAN_Name req(algo_spec);
129,348✔
71

72
#if defined(BOTAN_HAS_CTR_BE)
73
   if((req.algo_name() == "CTR-BE" || req.algo_name() == "CTR") && req.arg_count_between(1, 2)) {
606,438✔
74
      if(provider.empty() || provider == "base") {
94,779✔
75
         auto cipher = BlockCipher::create(req.arg(0));
93,140✔
76
         if(cipher) {
93,140✔
77
            size_t ctr_size = req.arg_as_integer(1, cipher->block_size());
93,139✔
78
            return std::make_unique<CTR_BE>(std::move(cipher), ctr_size);
93,139✔
79
         }
80
      }
93,140✔
81
   }
82
#endif
83

84
#if defined(BOTAN_HAS_CHACHA)
85
   if(req.algo_name() == "ChaCha") {
75,570✔
86
      if(provider.empty() || provider == "base") {
16,418✔
87
         return std::make_unique<ChaCha>(req.arg_as_integer(0, 20));
15,770✔
88
      }
89
   }
90
#endif
91

92
#if defined(BOTAN_HAS_OFB)
93
   if(req.algo_name() == "OFB" && req.arg_count() == 1) {
61,317✔
94
      if(provider.empty() || provider == "base") {
68✔
95
         if(auto cipher = BlockCipher::create(req.arg(0))) {
68✔
96
            return std::make_unique<OFB>(std::move(cipher));
34✔
97
         }
34✔
98
      }
99
   }
100
#endif
101

102
#if defined(BOTAN_HAS_RC4)
103

104
   if(req.algo_name() == "RC4" || req.algo_name() == "ARC4" || req.algo_name() == "MARK-4") {
125,024✔
105
      const size_t skip = (req.algo_name() == "MARK-4") ? 256 : req.arg_as_integer(0, 0);
304✔
106

107
      if(provider.empty() || provider == "base") {
302✔
108
         return std::make_unique<RC4>(skip);
152✔
109
      }
110
   }
111

112
#endif
113

114
   BOTAN_UNUSED(req);
20,253✔
115
   BOTAN_UNUSED(provider);
20,253✔
116

117
   return nullptr;
20,253✔
118
}
129,348✔
119

120
//static
121
std::unique_ptr<StreamCipher> StreamCipher::create_or_throw(std::string_view algo, std::string_view provider) {
93,475✔
122
   if(auto sc = StreamCipher::create(algo, provider)) {
93,475✔
123
      return sc;
93,475✔
124
   }
93,475✔
125
   throw Lookup_Error("Stream cipher", algo, provider);
×
126
}
127

128
std::vector<std::string> StreamCipher::providers(std::string_view algo_spec) {
3,584✔
129
   return probe_providers_of<StreamCipher>(algo_spec);
7,168✔
130
}
131

132
size_t StreamCipher::default_iv_length() const { return 0; }
4,730✔
133

134
}  // 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

© 2025 Coveralls, Inc