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

randombit / botan / 5111374265

29 May 2023 11:19AM UTC coverage: 92.227% (+0.5%) from 91.723%
5111374265

push

github

randombit
Next release will be 3.1.0. Update release notes

75588 of 81959 relevant lines covered (92.23%)

11886470.91 hits per line

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

97.73
/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) {
134,124✔
40
#if defined(BOTAN_HAS_SHAKE_CIPHER)
41
   if(algo_spec == "SHAKE-128" || algo_spec == "SHAKE-128-XOF") {
139,838✔
42
      if(provider.empty() || provider == "base")
4,580✔
43
         return std::make_unique<SHAKE_128_Cipher>();
2,290✔
44
   }
45

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

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

59
#if defined(BOTAN_HAS_SALSA20)
60
   if(algo_spec == "Salsa20") {
129,711✔
61
      if(provider.empty() || provider == "base")
56✔
62
         return std::make_unique<Salsa20>();
32✔
63
   }
64
#endif
65

66
   const SCAN_Name req(algo_spec);
129,509✔
67

68
#if defined(BOTAN_HAS_CTR_BE)
69
   if((req.algo_name() == "CTR-BE" || req.algo_name() == "CTR") && req.arg_count_between(1, 2)) {
607,231✔
70
      if(provider.empty() || provider == "base") {
94,940✔
71
         auto cipher = BlockCipher::create(req.arg(0));
93,301✔
72
         if(cipher) {
93,301✔
73
            size_t ctr_size = req.arg_as_integer(1, cipher->block_size());
93,300✔
74
            return std::make_unique<CTR_BE>(std::move(cipher), ctr_size);
93,300✔
75
         }
76
      }
93,301✔
77
   }
78
#endif
79

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

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

96
#if defined(BOTAN_HAS_RC4)
97

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

101
      if(provider.empty() || provider == "base") {
302✔
102
         return std::make_unique<RC4>(skip);
152✔
103
      }
104
   }
105

106
#endif
107

108
   BOTAN_UNUSED(req);
20,253✔
109
   BOTAN_UNUSED(provider);
20,253✔
110

111
   return nullptr;
20,253✔
112
}
129,509✔
113

114
//static
115
std::unique_ptr<StreamCipher> StreamCipher::create_or_throw(std::string_view algo, std::string_view provider) {
93,636✔
116
   if(auto sc = StreamCipher::create(algo, provider)) {
93,636✔
117
      return sc;
93,636✔
118
   }
93,636✔
119
   throw Lookup_Error("Stream cipher", algo, provider);
×
120
}
121

122
std::vector<std::string> StreamCipher::providers(std::string_view algo_spec) {
3,584✔
123
   return probe_providers_of<StreamCipher>(algo_spec);
7,168✔
124
}
125

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

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