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

PowerDNS / pdns / 12247231368

10 Dec 2024 12:57AM UTC coverage: 66.418% (+1.6%) from 64.777%
12247231368

Pull #14948

github

web-flow
Merge 432a0b93c into d0a62cc2d
Pull Request #14948: use boost algorithms

26100 of 54734 branches covered (47.69%)

Branch coverage included in aggregate %.

87 of 101 new or added lines in 28 files covered. (86.14%)

2076 existing lines in 52 files now uncovered.

85923 of 113929 relevant lines covered (75.42%)

4735022.09 hits per line

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

96.93
/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
{
57,931,417✔
29
  a -= b;
57,931,417✔
30
  a -= c;
57,931,417✔
31
  a ^= (c >> 13);
57,931,417✔
32
  b -= c;
57,931,417✔
33
  b -= a;
57,931,417✔
34
  b ^= (a << 8);
57,931,417✔
35
  c -= a;
57,931,417✔
36
  c -= b;
57,931,417✔
37
  c ^= (b >> 13);
57,931,417✔
38
  a -= b;
57,931,417✔
39
  a -= c;
57,931,417✔
40
  a ^= (c >> 12);
57,931,417✔
41
  b -= c;
57,931,417✔
42
  b -= a;
57,931,417✔
43
  b ^= (a << 16);
57,931,417✔
44
  c -= a;
57,931,417✔
45
  c -= b;
57,931,417✔
46
  c ^= (b >> 5);
57,931,417✔
47
  a -= b;
57,931,417✔
48
  a -= c;
57,931,417✔
49
  a ^= (c >> 3);
57,931,417✔
50
  b -= c;
57,931,417✔
51
  b -= a;
57,931,417✔
52
  b ^= (a << 10);
57,931,417✔
53
  c -= a;
57,931,417✔
54
  c -= b;
57,931,417✔
55
  c ^= (b >> 15);
57,931,417✔
56
}
57,931,417✔
57

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

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

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

77
  /*------------------------------------- handle the last 11 bytes */
78
  c += length;
1,613,603✔
79
  switch (len) { /* all the case statements fall through */
1,613,603✔
UNCOV
80
  case 11:
×
UNCOV
81
    c += ((uint32_t)k[10] << 24);
×
82
    /* fall-through */
83
  case 10:
808,472✔
84
    c += ((uint32_t)k[9] << 16);
808,472✔
85
    /* fall-through */
86
  case 9:
808,487✔
87
    c += ((uint32_t)k[8] << 8);
808,487✔
88
    /* the first byte of c is reserved for the length */
89
    /* fall-through */
90
  case 8:
808,500✔
91
    b += ((uint32_t)k[7] << 24);
808,500✔
92
    /* fall-through */
93
  case 7:
809,966✔
94
    b += ((uint32_t)k[6] << 16);
809,966✔
95
    /* fall-through */
96
  case 6:
809,985✔
97
    b += ((uint32_t)k[5] << 8);
809,985✔
98
    /* fall-through */
99
  case 5:
809,985!
100
    b += k[4];
809,985✔
101
    /* fall-through */
102
  case 4:
1,597,573✔
103
    a += ((uint32_t)k[3] << 24);
1,597,573✔
104
    /* fall-through */
105
  case 3:
1,622,904✔
106
    a += ((uint32_t)k[2] << 16);
1,622,904✔
107
    /* fall-through */
108
  case 2:
1,622,921✔
109
    a += ((uint32_t)k[1] << 8);
1,622,921✔
110
    /* fall-through */
111
  case 1:
1,622,921!
112
    a += k[0];
1,622,921✔
113
    /* case 0: nothing left to add */
114
  }
1,613,603✔
115
  burtlemix(a, b, c);
1,637,019✔
116
  /*-------------------------------------------- report the result */
117
  return c;
1,637,016✔
118
}
1,613,603✔
119

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

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

129
  /*---------------------------------------- handle most of the key */
130
  while (len >= 12) {
56,220,835✔
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));
24,165,577✔
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));
24,165,577✔
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));
24,165,577✔
134
    burtlemix(a, b, c);
24,165,577✔
135
    k += 12;
24,165,577✔
136
    len -= 12;
24,165,577✔
137
  }
24,165,577✔
138

139
  /*------------------------------------- handle the last 11 bytes */
140
  c += length;
32,055,258✔
141
  switch (len) { /* all the case statements fall through */
32,055,258✔
142
  case 11:
6,384,754✔
143
    c += ((uint32_t)dns_tolower(k[10]) << 24);
6,384,754✔
144
    /* fall-through */
145
  case 10:
7,874,124✔
146
    c += ((uint32_t)dns_tolower(k[9]) << 16);
7,874,124✔
147
    /* fall-through */
148
  case 9:
8,628,597✔
149
    c += ((uint32_t)dns_tolower(k[8]) << 8);
8,628,597✔
150
    /* the first byte of c is reserved for the length */
151
    /* fall-through */
152
  case 8:
9,430,616✔
153
    b += ((uint32_t)dns_tolower(k[7]) << 24);
9,430,616✔
154
    /* fall-through */
155
  case 7:
9,686,155✔
156
    b += ((uint32_t)dns_tolower(k[6]) << 16);
9,686,155✔
157
    /* fall-through */
158
  case 6:
9,974,318✔
159
    b += ((uint32_t)dns_tolower(k[5]) << 8);
9,974,318✔
160
    /* fall-through */
161
  case 5:
10,319,018✔
162
    b += dns_tolower(k[4]);
10,319,018✔
163
    /* fall-through */
164
  case 4:
13,281,531✔
165
    a += ((uint32_t)dns_tolower(k[3]) << 24);
13,281,531✔
166
    /* fall-through */
167
  case 3:
15,580,253✔
168
    a += ((uint32_t)dns_tolower(k[2]) << 16);
15,580,253✔
169
    /* fall-through */
170
  case 2:
21,892,193✔
171
    a += ((uint32_t)dns_tolower(k[1]) << 8);
21,892,193✔
172
    /* fall-through */
173
  case 1:
27,400,105✔
174
    a += dns_tolower(k[0]);
27,400,105✔
175
    /* case 0: nothing left to add */
176
  }
32,055,258✔
177
  burtlemix(a, b, c);
32,101,074✔
178
  /*-------------------------------------------- report the result */
179
  return c;
32,101,044✔
180
}
32,055,258✔
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