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

randombit / botan / 5230455705

10 Jun 2023 02:30PM UTC coverage: 91.715% (-0.03%) from 91.746%
5230455705

push

github

randombit
Merge GH #3584 Change clang-format AllowShortFunctionsOnASingleLine config from All to Inline

77182 of 84154 relevant lines covered (91.72%)

11975295.43 hits per line

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

97.1
/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 {
13✔
76
   return !m_key1.empty() && !m_key2.empty();
13✔
77
}
78

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

85
   const size_t half = length / 2;
3✔
86

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

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

102
std::unique_ptr<BlockCipher> Lion::new_object() const {
1✔
103
   return std::make_unique<Lion>(m_hash->new_object(), m_cipher->new_object(), block_size());
1✔
104
}
105

106
/*
107
* Clear memory of sensitive data
108
*/
109
void Lion::clear() {
5✔
110
   zap(m_key1);
5✔
111
   zap(m_key2);
5✔
112
   m_hash->clear();
5✔
113
   m_cipher->clear();
5✔
114
}
5✔
115

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

127
   if(!m_cipher->valid_keylength(left_size())) {
3✔
128
      throw Invalid_Argument(fmt("Lion does not support combining {} and {}", m_cipher->name(), m_hash->name()));
×
129
   }
130
}
3✔
131

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

© 2026 Coveralls, Inc