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

randombit / botan / 5079590438

25 May 2023 12:28PM UTC coverage: 92.228% (+0.5%) from 91.723%
5079590438

Pull #3502

github

Pull Request #3502: Apply clang-format to the codebase

75589 of 81959 relevant lines covered (92.23%)

12139530.51 hits per line

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

96.55
/src/lib/modes/aead/aead.cpp
1
/*
2
* (C) 2013,2015 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6

7
#include <botan/aead.h>
8

9
#include <botan/internal/parsing.h>
10
#include <botan/internal/scan_name.h>
11
#include <sstream>
12

13
#if defined(BOTAN_HAS_BLOCK_CIPHER)
14
   #include <botan/block_cipher.h>
15
#endif
16

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

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

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

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

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

37
#if defined(BOTAN_HAS_AEAD_SIV)
38
   #include <botan/internal/siv.h>
39
#endif
40

41
namespace Botan {
42

43
std::unique_ptr<AEAD_Mode> AEAD_Mode::create_or_throw(std::string_view algo,
6,178✔
44
                                                      Cipher_Dir dir,
45
                                                      std::string_view provider) {
46
   if(auto aead = AEAD_Mode::create(algo, dir, provider))
6,178✔
47
      return aead;
6,178✔
48

49
   throw Lookup_Error("AEAD", algo, provider);
×
50
}
51

52
std::unique_ptr<AEAD_Mode> AEAD_Mode::create(std::string_view algo, Cipher_Dir dir, std::string_view provider) {
50,285✔
53
   BOTAN_UNUSED(provider);
50,285✔
54
#if defined(BOTAN_HAS_AEAD_CHACHA20_POLY1305)
55
   if(algo == "ChaCha20Poly1305") {
50,673✔
56
      if(dir == Cipher_Dir::Encryption)
13,099✔
57
         return std::make_unique<ChaCha20Poly1305_Encryption>();
6,552✔
58
      else
59
         return std::make_unique<ChaCha20Poly1305_Decryption>();
6,547✔
60
   }
61
#endif
62

63
   if(algo.find('/') != std::string::npos) {
37,186✔
64
      const std::vector<std::string> algo_parts = split_on(algo, '/');
14,501✔
65
      std::string_view cipher_name = algo_parts[0];
14,501✔
66
      const std::vector<std::string> mode_info = parse_algorithm_name(algo_parts[1]);
14,501✔
67

68
      if(mode_info.empty())
14,501✔
69
         return std::unique_ptr<AEAD_Mode>();
×
70

71
      std::ostringstream mode_name;
14,501✔
72

73
      mode_name << mode_info[0] << '(' << cipher_name;
14,501✔
74
      for(size_t i = 1; i < mode_info.size(); ++i)
15,513✔
75
         mode_name << ',' << mode_info[i];
1,012✔
76
      for(size_t i = 2; i < algo_parts.size(); ++i)
16,494✔
77
         mode_name << ',' << algo_parts[i];
1,993✔
78
      mode_name << ')';
14,501✔
79

80
      return AEAD_Mode::create(mode_name.str(), dir);
14,501✔
81
   }
14,501✔
82

83
#if defined(BOTAN_HAS_BLOCK_CIPHER)
84

85
   SCAN_Name req(algo);
22,685✔
86

87
   if(req.arg_count() == 0) {
22,685✔
88
      return std::unique_ptr<AEAD_Mode>();
42✔
89
   }
90

91
   auto bc = BlockCipher::create(req.arg(0), provider);
22,643✔
92

93
   if(!bc) {
22,643✔
94
      return std::unique_ptr<AEAD_Mode>();
3✔
95
   }
96

97
   #if defined(BOTAN_HAS_AEAD_CCM)
98
   if(req.algo_name() == "CCM") {
45,280✔
99
      size_t tag_len = req.arg_as_integer(1, 16);
236✔
100
      size_t L_len = req.arg_as_integer(2, 3);
236✔
101
      if(dir == Cipher_Dir::Encryption)
236✔
102
         return std::make_unique<CCM_Encryption>(std::move(bc), tag_len, L_len);
118✔
103
      else
104
         return std::make_unique<CCM_Decryption>(std::move(bc), tag_len, L_len);
118✔
105
   }
106
   #endif
107

108
   #if defined(BOTAN_HAS_AEAD_GCM)
109
   if(req.algo_name() == "GCM") {
44,808✔
110
      size_t tag_len = req.arg_as_integer(1, 16);
3,345✔
111
      if(dir == Cipher_Dir::Encryption)
3,345✔
112
         return std::make_unique<GCM_Encryption>(std::move(bc), tag_len);
2,001✔
113
      else
114
         return std::make_unique<GCM_Decryption>(std::move(bc), tag_len);
1,344✔
115
   }
116
   #endif
117

118
   #if defined(BOTAN_HAS_AEAD_OCB)
119
   if(req.algo_name() == "OCB") {
38,118✔
120
      size_t tag_len = req.arg_as_integer(1, 16);
292✔
121
      if(dir == Cipher_Dir::Encryption)
292✔
122
         return std::make_unique<OCB_Encryption>(std::move(bc), tag_len);
146✔
123
      else
124
         return std::make_unique<OCB_Decryption>(std::move(bc), tag_len);
146✔
125
   }
126
   #endif
127

128
   #if defined(BOTAN_HAS_AEAD_EAX)
129
   if(req.algo_name() == "EAX") {
37,534✔
130
      size_t tag_len = req.arg_as_integer(1, bc->block_size());
1,149✔
131
      if(dir == Cipher_Dir::Encryption)
1,149✔
132
         return std::make_unique<EAX_Encryption>(std::move(bc), tag_len);
574✔
133
      else
134
         return std::make_unique<EAX_Decryption>(std::move(bc), tag_len);
575✔
135
   }
136
   #endif
137

138
   #if defined(BOTAN_HAS_AEAD_SIV)
139
   if(req.algo_name() == "SIV") {
35,236✔
140
      if(dir == Cipher_Dir::Encryption)
1,297✔
141
         return std::make_unique<SIV_Encryption>(std::move(bc));
651✔
142
      else
143
         return std::make_unique<SIV_Decryption>(std::move(bc));
646✔
144
   }
145
   #endif
146

147
#endif
148

149
   return std::unique_ptr<AEAD_Mode>();
22,643✔
150
}
22,685✔
151

152
}
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