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

PowerDNS / pdns / 19741624072

27 Nov 2025 03:45PM UTC coverage: 73.086% (+0.02%) from 73.065%
19741624072

Pull #16570

github

web-flow
Merge 08a2cdb1d into f94a3f63f
Pull Request #16570: rec: rewrite all unwrap calls in web.rs

38523 of 63408 branches covered (60.75%)

Branch coverage included in aggregate %.

128044 of 164496 relevant lines covered (77.84%)

6531485.83 hits per line

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

99.4
/pdns/burtle.hh
1
/*
2
 * This file is part of PowerDNS or dnsdist.
3
 * Copyright -- PowerDNS.COM B.V. and its contributors
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of version 2 of the GNU General Public License as
7
 * published by the Free Software Foundation.
8
 *
9
 * In addition, for the avoidance of any doubt, permission is granted to
10
 * link this program with OpenSSL and to (re)distribute the binaries
11
 * produced as the result of such linking.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
 */
22

23
#pragma once
24

25
#include <cinttypes>
26

27
inline void burtlemix(uint32_t& a, uint32_t& b, uint32_t& c)
28
{
88,650,301✔
29
  a -= b;
88,650,301✔
30
  a -= c;
88,650,301✔
31
  a ^= (c >> 13);
88,650,301✔
32
  b -= c;
88,650,301✔
33
  b -= a;
88,650,301✔
34
  b ^= (a << 8);
88,650,301✔
35
  c -= a;
88,650,301✔
36
  c -= b;
88,650,301✔
37
  c ^= (b >> 13);
88,650,301✔
38
  a -= b;
88,650,301✔
39
  a -= c;
88,650,301✔
40
  a ^= (c >> 12);
88,650,301✔
41
  b -= c;
88,650,301✔
42
  b -= a;
88,650,301✔
43
  b ^= (a << 16);
88,650,301✔
44
  c -= a;
88,650,301✔
45
  c -= b;
88,650,301✔
46
  c ^= (b >> 5);
88,650,301✔
47
  a -= b;
88,650,301✔
48
  a -= c;
88,650,301✔
49
  a ^= (c >> 3);
88,650,301✔
50
  b -= c;
88,650,301✔
51
  b -= a;
88,650,301✔
52
  b ^= (a << 10);
88,650,301✔
53
  c -= a;
88,650,301✔
54
  c -= b;
88,650,301✔
55
  c ^= (b >> 15);
88,650,301✔
56
}
88,650,301✔
57

58
inline uint32_t burtle(const unsigned char* k, uint32_t length, uint32_t initval)
59
{
18,489,055✔
60
  uint32_t a, b, c, len;
18,489,055✔
61

62
  /* Set up the internal state */
63
  len = length;
18,489,055✔
64
  a = b = 0x9e3779b9; /* the golden ratio; an arbitrary value */
18,489,055✔
65
  c = initval; /* the previous hash value */
18,489,055✔
66

67
  /*---------------------------------------- handle most of the key */
68
  while (len >= 12) {
18,534,948✔
69
    a += (k[0] + ((uint32_t)k[1] << 8) + ((uint32_t)k[2] << 16) + ((uint32_t)k[3] << 24));
45,893✔
70
    b += (k[4] + ((uint32_t)k[5] << 8) + ((uint32_t)k[6] << 16) + ((uint32_t)k[7] << 24));
45,893✔
71
    c += (k[8] + ((uint32_t)k[9] << 8) + ((uint32_t)k[10] << 16) + ((uint32_t)k[11] << 24));
45,893✔
72
    burtlemix(a, b, c);
45,893✔
73
    k += 12;
45,893✔
74
    len -= 12;
45,893✔
75
  }
45,893✔
76

77
  /*------------------------------------- handle the last 11 bytes */
78
  c += length;
18,489,055✔
79
  switch (len) { /* all the case statements fall through */
18,489,055✔
80
  case 11:
33✔
81
    c += ((uint32_t)k[10] << 24);
33✔
82
    /* fall-through */
83
  case 10:
6,162,321✔
84
    c += ((uint32_t)k[9] << 16);
6,162,321✔
85
    /* fall-through */
86
  case 9:
6,162,332✔
87
    c += ((uint32_t)k[8] << 8);
6,162,332✔
88
    /* the first byte of c is reserved for the length */
89
    /* fall-through */
90
  case 8:
6,162,394✔
91
    b += ((uint32_t)k[7] << 24);
6,162,394✔
92
    /* fall-through */
93
  case 7:
6,163,922✔
94
    b += ((uint32_t)k[6] << 16);
6,163,922✔
95
    /* fall-through */
96
  case 6:
6,163,941✔
97
    b += ((uint32_t)k[5] << 8);
6,163,941✔
98
    /* fall-through */
99
  case 5:
6,163,941!
100
    b += k[4];
6,163,941✔
101
    /* fall-through */
102
  case 4:
13,242,460✔
103
    a += ((uint32_t)k[3] << 24);
13,242,460✔
104
    /* fall-through */
105
  case 3:
13,269,059✔
106
    a += ((uint32_t)k[2] << 16);
13,269,059✔
107
    /* fall-through */
108
  case 2:
13,312,939✔
109
    a += ((uint32_t)k[1] << 8);
13,312,939✔
110
    /* fall-through */
111
  case 1:
18,670,811✔
112
    a += k[0];
18,670,811✔
113
    /* case 0: nothing left to add */
114
  }
18,489,055✔
115
  burtlemix(a, b, c);
18,603,636✔
116
  /*-------------------------------------------- report the result */
117
  return c;
18,603,631✔
118
}
18,489,055✔
119

120
inline uint32_t burtleCI(const unsigned char* k, uint32_t length, uint32_t initval)
121
{
38,960,008✔
122
  uint32_t a, b, c, len;
38,960,008✔
123

124
  /* Set up the internal state */
125
  len = length;
38,960,008✔
126
  a = b = 0x9e3779b9; /* the golden ratio; an arbitrary value */
38,960,008✔
127
  c = initval; /* the previous hash value */
38,960,008✔
128

129
  /*---------------------------------------- handle most of the key */
130
  while (len >= 12) {
70,001,371✔
131
    a += (dns_tolower(k[0]) + ((uint32_t)dns_tolower(k[1]) << 8) + ((uint32_t)dns_tolower(k[2]) << 16) + ((uint32_t)dns_tolower(k[3]) << 24));
31,041,363✔
132
    b += (dns_tolower(k[4]) + ((uint32_t)dns_tolower(k[5]) << 8) + ((uint32_t)dns_tolower(k[6]) << 16) + ((uint32_t)dns_tolower(k[7]) << 24));
31,041,363✔
133
    c += (dns_tolower(k[8]) + ((uint32_t)dns_tolower(k[9]) << 8) + ((uint32_t)dns_tolower(k[10]) << 16) + ((uint32_t)dns_tolower(k[11]) << 24));
31,041,363✔
134
    burtlemix(a, b, c);
31,041,363✔
135
    k += 12;
31,041,363✔
136
    len -= 12;
31,041,363✔
137
  }
31,041,363✔
138

139
  /*------------------------------------- handle the last 11 bytes */
140
  c += length;
38,960,008✔
141
  switch (len) { /* all the case statements fall through */
38,960,008✔
142
  case 11:
6,673,885✔
143
    c += ((uint32_t)dns_tolower(k[10]) << 24);
6,673,885✔
144
    /* fall-through */
145
  case 10:
8,291,015✔
146
    c += ((uint32_t)dns_tolower(k[9]) << 16);
8,291,015✔
147
    /* fall-through */
148
  case 9:
9,067,905✔
149
    c += ((uint32_t)dns_tolower(k[8]) << 8);
9,067,905✔
150
    /* the first byte of c is reserved for the length */
151
    /* fall-through */
152
  case 8:
10,858,644✔
153
    b += ((uint32_t)dns_tolower(k[7]) << 24);
10,858,644✔
154
    /* fall-through */
155
  case 7:
11,608,642✔
156
    b += ((uint32_t)dns_tolower(k[6]) << 16);
11,608,642✔
157
    /* fall-through */
158
  case 6:
11,979,444✔
159
    b += ((uint32_t)dns_tolower(k[5]) << 8);
11,979,444✔
160
    /* fall-through */
161
  case 5:
12,449,497✔
162
    b += dns_tolower(k[4]);
12,449,497✔
163
    /* fall-through */
164
  case 4:
17,251,844✔
165
    a += ((uint32_t)dns_tolower(k[3]) << 24);
17,251,844✔
166
    /* fall-through */
167
  case 3:
19,585,106✔
168
    a += ((uint32_t)dns_tolower(k[2]) << 16);
19,585,106✔
169
    /* fall-through */
170
  case 2:
28,101,412✔
171
    a += ((uint32_t)dns_tolower(k[1]) << 8);
28,101,412✔
172
    /* fall-through */
173
  case 1:
34,094,470✔
174
    a += dns_tolower(k[0]);
34,094,470✔
175
    /* case 0: nothing left to add */
176
  }
38,960,008✔
177
  burtlemix(a, b, c);
39,091,367✔
178
  /*-------------------------------------------- report the result */
179
  return c;
39,086,613✔
180
}
38,960,008✔
181

182
template <typename T>
183
inline uint32_t burtleCI(const T& k, uint32_t initval)
184
{
32,543,599✔
185
  return burtleCI(reinterpret_cast<const unsigned char*>(k.data()), k.length(), initval); // NOLINT(cppcoreguidelines-pro-type-reinterpret-cast): can't static_cast because of sign difference
32,543,599✔
186
}
32,543,599✔
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