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

randombit / botan / 27737522519

18 Jun 2026 02:59AM UTC coverage: 89.397% (-2.3%) from 91.708%
27737522519

push

github

randombit
Remove unused member variable from Encrypted_PSK_Database

111425 of 124641 relevant lines covered (89.4%)

11108238.09 hits per line

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

99.0
/src/lib/mac/siphash/siphash.cpp
1
/*
2
* SipHash
3
* (C) 2014,2015 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

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

10
#include <botan/exceptn.h>
11
#include <botan/internal/buffer_slicer.h>
12
#include <botan/internal/fmt.h>
13
#include <botan/internal/loadstor.h>
14
#include <botan/internal/rotate.h>
15

16
namespace Botan {
17

18
namespace {
19

20
void SipRounds(uint64_t M, secure_vector<uint64_t>& V, size_t r) {
7,616✔
21
   uint64_t V0 = V[0];
7,616✔
22
   uint64_t V1 = V[1];
7,616✔
23
   uint64_t V2 = V[2];
7,616✔
24
   uint64_t V3 = V[3];
7,616✔
25

26
   V3 ^= M;
7,616✔
27
   for(size_t i = 0; i != r; ++i) {
24,132✔
28
      V0 += V1;
16,516✔
29
      V2 += V3;
16,516✔
30
      V1 = rotl<13>(V1);
16,516✔
31
      V3 = rotl<16>(V3);
16,516✔
32
      V1 ^= V0;
16,516✔
33
      V3 ^= V2;
16,516✔
34
      V0 = rotl<32>(V0);
16,516✔
35

36
      V2 += V1;
16,516✔
37
      V0 += V3;
16,516✔
38
      V1 = rotl<17>(V1);
16,516✔
39
      V3 = rotl<21>(V3);
16,516✔
40
      V1 ^= V2;
16,516✔
41
      V3 ^= V0;
16,516✔
42
      V2 = rotl<32>(V2);
16,516✔
43
   }
44
   V0 ^= M;
7,616✔
45

46
   V[0] = V0;
7,616✔
47
   V[1] = V1;
7,616✔
48
   V[2] = V2;
7,616✔
49
   V[3] = V3;
7,616✔
50
}
7,616✔
51

52
}  // namespace
53

54
SipHash::SipHash(size_t c, size_t d) : m_C(c), m_D(d) {
178✔
55
   BOTAN_ARG_CHECK(m_C > 0 && m_C <= 64, "SipHash C parameter out of range");
178✔
56
   BOTAN_ARG_CHECK(m_D > 0 && m_D <= 64, "SipHash D parameter out of range");
178✔
57
}
178✔
58

59
void SipHash::add_data(std::span<const uint8_t> input) {
1,216✔
60
   assert_key_material_set();
1,216✔
61

62
   // SipHash counts the message length mod 256
63
   m_words += static_cast<uint8_t>(input.size());
1,098✔
64

65
   BufferSlicer in(input);
1,098✔
66

67
   if(m_mbuf_pos > 0) {
1,098✔
68
      while(!in.empty() && m_mbuf_pos != 8) {
2,024✔
69
         m_mbuf = (m_mbuf >> 8) | (static_cast<uint64_t>(in.take_byte()) << 56);
806✔
70
         ++m_mbuf_pos;
806✔
71
      }
72

73
      if(m_mbuf_pos == 8) {
206✔
74
         SipRounds(m_mbuf, m_V, m_C);
106✔
75
         m_mbuf_pos = 0;
106✔
76
         m_mbuf = 0;
106✔
77
      }
78
   }
79

80
   while(in.remaining() >= 8) {
7,324✔
81
      SipRounds(load_le<uint64_t>(in.take(8).data(), 0), m_V, m_C);
6,226✔
82
   }
83

84
   while(!in.empty()) {
3,999✔
85
      m_mbuf = (m_mbuf >> 8) | (static_cast<uint64_t>(in.take_byte()) << 56);
2,901✔
86
      m_mbuf_pos++;
2,901✔
87
   }
88
}
1,098✔
89

90
void SipHash::final_result(std::span<uint8_t> mac) {
701✔
91
   assert_key_material_set();
701✔
92

93
   if(m_mbuf_pos == 0) {
642✔
94
      m_mbuf = (static_cast<uint64_t>(m_words) << 56);
84✔
95
   } else if(m_mbuf_pos < 8) {
558✔
96
      m_mbuf = (m_mbuf >> (64 - m_mbuf_pos * 8)) | (static_cast<uint64_t>(m_words) << 56);
558✔
97
   }
98

99
   SipRounds(m_mbuf, m_V, m_C);
642✔
100

101
   m_V[2] ^= 0xFF;
642✔
102
   SipRounds(0, m_V, m_D);
642✔
103

104
   const uint64_t X = m_V[0] ^ m_V[1] ^ m_V[2] ^ m_V[3];
642✔
105

106
   store_le(X, mac.data());
642✔
107

108
   reset_msg();
642✔
109
}
642✔
110

111
void SipHash::start_msg(std::span<const uint8_t> nonce) {
759✔
112
   if(!nonce.empty()) {
759✔
113
      throw Invalid_IV_Length(name(), nonce.size());
×
114
   }
115
   assert_key_material_set();
759✔
116

117
   reset_msg();
759✔
118
}
759✔
119

120
void SipHash::reset_msg() {
2,043✔
121
   m_V.resize(4);
2,043✔
122
   m_V[0] = m_K[0] ^ 0x736F6D6570736575;
2,043✔
123
   m_V[1] = m_K[1] ^ 0x646F72616E646F6D;
2,043✔
124
   m_V[2] = m_K[0] ^ 0x6C7967656E657261;
2,043✔
125
   m_V[3] = m_K[1] ^ 0x7465646279746573;
2,043✔
126
   m_mbuf = 0;
2,043✔
127
   m_mbuf_pos = 0;
2,043✔
128
   m_words = 0;
2,043✔
129
}
2,043✔
130

131
bool SipHash::has_keying_material() const {
2,853✔
132
   return !m_V.empty();
2,853✔
133
}
134

135
void SipHash::key_schedule(std::span<const uint8_t> key) {
642✔
136
   const uint64_t K0 = load_le<uint64_t>(key.data(), 0);
642✔
137
   const uint64_t K1 = load_le<uint64_t>(key.data(), 1);
642✔
138

139
   m_K.resize(2);
642✔
140
   m_K[0] = K0;
642✔
141
   m_K[1] = K1;
642✔
142

143
   m_V.resize(4);
642✔
144
   reset_msg();
642✔
145
}
642✔
146

147
void SipHash::clear() {
118✔
148
   zap(m_K);
118✔
149
   zap(m_V);
118✔
150
   m_mbuf = 0;
118✔
151
   m_mbuf_pos = 0;
118✔
152
   m_words = 0;
118✔
153
}
118✔
154

155
std::string SipHash::name() const {
354✔
156
   return fmt("SipHash({},{})", m_C, m_D);
354✔
157
}
158

159
std::unique_ptr<MessageAuthenticationCode> SipHash::new_object() const {
59✔
160
   return std::make_unique<SipHash>(m_C, m_D);
59✔
161
}
162

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