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

PowerDNS / pdns / 12246590190

10 Dec 2024 12:02AM UTC coverage: 63.037% (-1.7%) from 64.777%
12246590190

Pull #14948

github

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

12955 of 27310 branches covered (47.44%)

Branch coverage included in aggregate %.

45 of 62 new or added lines in 25 files covered. (72.58%)

2016 existing lines in 67 files now uncovered.

41770 of 59504 relevant lines covered (70.2%)

3428145.75 hits per line

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

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

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

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

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

77
  /*------------------------------------- handle the last 11 bytes */
78
  c += length;
1,609,475✔
79
  switch (len) { /* all the case statements fall through */
1,609,475✔
UNCOV
80
  case 11:
×
UNCOV
81
    c += ((uint32_t)k[10] << 24);
×
82
    /* fall-through */
83
  case 10:
798,753✔
84
    c += ((uint32_t)k[9] << 16);
798,753✔
85
    /* fall-through */
86
  case 9:
798,762✔
87
    c += ((uint32_t)k[8] << 8);
798,762✔
88
    /* the first byte of c is reserved for the length */
89
    /* fall-through */
90
  case 8:
798,763✔
91
    b += ((uint32_t)k[7] << 24);
798,763✔
92
    /* fall-through */
93
  case 7:
800,189✔
94
    b += ((uint32_t)k[6] << 16);
800,189✔
95
    /* fall-through */
96
  case 6:
800,208✔
97
    b += ((uint32_t)k[5] << 8);
800,208✔
98
    /* fall-through */
99
  case 5:
800,208!
100
    b += k[4];
800,208✔
101
    /* fall-through */
102
  case 4:
1,587,945✔
103
    a += ((uint32_t)k[3] << 24);
1,587,945✔
104
    /* fall-through */
105
  case 3:
1,612,383✔
106
    a += ((uint32_t)k[2] << 16);
1,612,383✔
107
    /* fall-through */
108
  case 2:
1,612,383!
109
    a += ((uint32_t)k[1] << 8);
1,612,383✔
110
    /* fall-through */
111
  case 1:
1,612,383!
112
    a += k[0];
1,612,383✔
113
    /* case 0: nothing left to add */
114
  }
1,609,475✔
115
  burtlemix(a, b, c);
1,628,153✔
116
  /*-------------------------------------------- report the result */
117
  return c;
1,628,153✔
118
}
1,609,475✔
119

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

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

129
  /*---------------------------------------- handle most of the key */
130
  while (len >= 12) {
42,431,677✔
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));
17,376,971✔
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));
17,376,971✔
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));
17,376,971✔
134
    burtlemix(a, b, c);
17,376,971✔
135
    k += 12;
17,376,971✔
136
    len -= 12;
17,376,971✔
137
  }
17,376,971✔
138

139
  /*------------------------------------- handle the last 11 bytes */
140
  c += length;
25,054,706✔
141
  switch (len) { /* all the case statements fall through */
25,054,706✔
142
  case 11:
6,317,151✔
143
    c += ((uint32_t)dns_tolower(k[10]) << 24);
6,317,151✔
144
    /* fall-through */
145
  case 10:
7,747,460✔
146
    c += ((uint32_t)dns_tolower(k[9]) << 16);
7,747,460✔
147
    /* fall-through */
148
  case 9:
8,109,026✔
149
    c += ((uint32_t)dns_tolower(k[8]) << 8);
8,109,026✔
150
    /* the first byte of c is reserved for the length */
151
    /* fall-through */
152
  case 8:
8,434,498✔
153
    b += ((uint32_t)dns_tolower(k[7]) << 24);
8,434,498✔
154
    /* fall-through */
155
  case 7:
8,625,780✔
156
    b += ((uint32_t)dns_tolower(k[6]) << 16);
8,625,780✔
157
    /* fall-through */
158
  case 6:
8,793,358✔
159
    b += ((uint32_t)dns_tolower(k[5]) << 8);
8,793,358✔
160
    /* fall-through */
161
  case 5:
8,933,381✔
162
    b += dns_tolower(k[4]);
8,933,381✔
163
    /* fall-through */
164
  case 4:
11,807,601✔
165
    a += ((uint32_t)dns_tolower(k[3]) << 24);
11,807,601✔
166
    /* fall-through */
167
  case 3:
13,871,680✔
168
    a += ((uint32_t)dns_tolower(k[2]) << 16);
13,871,680✔
169
    /* fall-through */
170
  case 2:
15,714,465✔
171
    a += ((uint32_t)dns_tolower(k[1]) << 8);
15,714,465✔
172
    /* fall-through */
173
  case 1:
20,513,807✔
174
    a += dns_tolower(k[0]);
20,513,807✔
175
    /* case 0: nothing left to add */
176
  }
25,054,706✔
177
  burtlemix(a, b, c);
25,094,792✔
178
  /*-------------------------------------------- report the result */
179
  return c;
25,094,792✔
180
}
25,054,706✔
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