• 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

97.01
/src/lib/block/lion/lion.cpp
1
/*
2
* Lion
3
* (C) 1999-2007,2014 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include <botan/internal/lion.h>
9

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

13
namespace Botan {
14

15
/*
16
* Lion Encryption
17
*/
18
void Lion::encrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const {
5✔
19
   assert_key_material_set();
5✔
20

21
   const size_t LEFT_SIZE = left_size();
3✔
22
   const size_t RIGHT_SIZE = right_size();
3✔
23

24
   secure_vector<uint8_t> buffer_vec(LEFT_SIZE);
3✔
25
   uint8_t* buffer = buffer_vec.data();
3✔
26

27
   for(size_t i = 0; i != blocks; ++i) {
6✔
28
      xor_buf(buffer, in, m_key1.data(), LEFT_SIZE);
3✔
29
      m_cipher->set_key(buffer, LEFT_SIZE);
3✔
30
      m_cipher->cipher(in + LEFT_SIZE, out + LEFT_SIZE, RIGHT_SIZE);
3✔
31

32
      m_hash->update(out + LEFT_SIZE, RIGHT_SIZE);
3✔
33
      m_hash->final(buffer);
3✔
34
      xor_buf(out, in, buffer, LEFT_SIZE);
3✔
35

36
      xor_buf(buffer, out, m_key2.data(), LEFT_SIZE);
3✔
37
      m_cipher->set_key(buffer, LEFT_SIZE);
3✔
38
      m_cipher->cipher1(out + LEFT_SIZE, RIGHT_SIZE);
3✔
39

40
      in += m_block_size;
3✔
41
      out += m_block_size;
3✔
42
   }
43
}
3✔
44

45
/*
46
* Lion Decryption
47
*/
48
void Lion::decrypt_n(const uint8_t in[], uint8_t out[], size_t blocks) const {
4✔
49
   assert_key_material_set();
4✔
50

51
   const size_t LEFT_SIZE = left_size();
4✔
52
   const size_t RIGHT_SIZE = right_size();
2✔
53

54
   secure_vector<uint8_t> buffer_vec(LEFT_SIZE);
2✔
55
   uint8_t* buffer = buffer_vec.data();
2✔
56

57
   for(size_t i = 0; i != blocks; ++i) {
4✔
58
      xor_buf(buffer, in, m_key2.data(), LEFT_SIZE);
2✔
59
      m_cipher->set_key(buffer, LEFT_SIZE);
2✔
60
      m_cipher->cipher(in + LEFT_SIZE, out + LEFT_SIZE, RIGHT_SIZE);
2✔
61

62
      m_hash->update(out + LEFT_SIZE, RIGHT_SIZE);
2✔
63
      m_hash->final(buffer);
2✔
64
      xor_buf(out, in, buffer, LEFT_SIZE);
2✔
65

66
      xor_buf(buffer, out, m_key1.data(), LEFT_SIZE);
2✔
67
      m_cipher->set_key(buffer, LEFT_SIZE);
2✔
68
      m_cipher->cipher1(out + LEFT_SIZE, RIGHT_SIZE);
2✔
69

70
      in += m_block_size;
2✔
71
      out += m_block_size;
2✔
72
   }
73
}
2✔
74

75
bool Lion::has_keying_material() const { return !m_key1.empty() && !m_key2.empty(); }
13✔
76

77
/*
78
* Lion Key Schedule
79
*/
80
void Lion::key_schedule(const uint8_t key[], size_t length) {
3✔
81
   clear();
3✔
82

83
   const size_t half = length / 2;
3✔
84

85
   m_key1.resize(left_size());
3✔
86
   m_key2.resize(left_size());
3✔
87
   clear_mem(m_key1.data(), m_key1.size());
3✔
88
   clear_mem(m_key2.data(), m_key2.size());
3✔
89
   copy_mem(m_key1.data(), key, half);
3✔
90
   copy_mem(m_key2.data(), key + half, half);
3✔
91
}
3✔
92

93
/*
94
* Return the name of this type
95
*/
96
std::string Lion::name() const { return fmt("Lion({},{},{})", m_hash->name(), m_cipher->name(), block_size()); }
7✔
97

98
std::unique_ptr<BlockCipher> Lion::new_object() const {
1✔
99
   return std::make_unique<Lion>(m_hash->new_object(), m_cipher->new_object(), block_size());
1✔
100
}
101

102
/*
103
* Clear memory of sensitive data
104
*/
105
void Lion::clear() {
5✔
106
   zap(m_key1);
5✔
107
   zap(m_key2);
5✔
108
   m_hash->clear();
5✔
109
   m_cipher->clear();
5✔
110
}
5✔
111

112
/*
113
* Lion Constructor
114
*/
115
Lion::Lion(std::unique_ptr<HashFunction> hash, std::unique_ptr<StreamCipher> cipher, size_t bs) :
3✔
116
      m_block_size(std::max<size_t>(2 * hash->output_length() + 1, bs)),
3✔
117
      m_hash(std::move(hash)),
3✔
118
      m_cipher(std::move(cipher)) {
6✔
119
   if(2 * left_size() + 1 > m_block_size) {
3✔
120
      throw Invalid_Argument(fmt("Block size {} is too small for {}", m_block_size, name()));
×
121
   }
122

123
   if(!m_cipher->valid_keylength(left_size())) {
3✔
124
      throw Invalid_Argument(fmt("Lion does not support combining {} and {}", m_cipher->name(), m_hash->name()));
×
125
   }
126
}
3✔
127

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