Line data Source code
1 : /*
2 : * hash.c
3 : * Patater GUI Kit
4 : *
5 : * Created by Jaeden Amero on 2019-05-04.
6 : * Copyright 2019. SPDX-License-Identifier: AGPL-3.0-or-later
7 : */
8 :
9 : #include "guikit/hash.h"
10 : #include "ptest/test.h"
11 :
12 1 : static int hash_test_chongo(void)
13 : {
14 : unsigned long h;
15 1 : char test[] = "chongo <Landon Curt Noll> /\\../\\";
16 :
17 1 : h = hash(test, sizeof(test) - 1);
18 1 : TEST_EQU(h, 0x9a4e92e6UL);
19 :
20 1 : return 0;
21 : }
22 :
23 1 : static int hash_test_deadbeef(void)
24 : {
25 : unsigned long h;
26 1 : char test[] = {-34, -83, -66, -17, 0, -91, 90};
27 :
28 1 : h = hash(test, 0);
29 1 : TEST_EQU(h, 0x811c9dc5UL);
30 :
31 1 : h = hash(test, 1);
32 1 : TEST_EQU(h, 0x5b0b5181UL);
33 :
34 1 : h = hash(test, 2);
35 1 : TEST_EQU(h, 0x7ed0c844UL);
36 :
37 1 : h = hash(test, 3);
38 1 : TEST_EQU(h, 0x9cac618eUL);
39 :
40 1 : h = hash(test, 4);
41 1 : TEST_EQU(h, 0x045d4bb3UL);
42 :
43 1 : h = hash(test, 5);
44 1 : TEST_EQU(h, 0x91de2ac9UL);
45 :
46 1 : h = hash(test, 6);
47 1 : TEST_EQU(h, 0x0cbcc804UL);
48 :
49 1 : h = hash(test, 7);
50 1 : TEST_EQU(h, 0x6b2f6bfaUL);
51 :
52 1 : return 0;
53 : }
54 :
55 : #define LEN(x) (sizeof(x)-1)
56 : /* TESTV macro does not include trailing NUL byte in the test vector */
57 : #define TESTV(x) {x, LEN(x)}
58 : /* TESTV0 macro includes the trailing NUL byte in the test vector */
59 : #define TESTV0(x) {x, sizeof(x)}
60 : /* REPEAT500 - repeat a string 500 times */
61 : #define R500(x) R100(x)R100(x)R100(x)R100(x)R100(x)
62 : #define R100(x) R10(x)R10(x)R10(x)R10(x)R10(x)R10(x)R10(x)R10(x)R10(x)R10(x)
63 : #define R10(x) x x x x x x x x x x
64 :
65 : /*
66 : * these test vectors are used as part o the FNV test suite
67 : */
68 : struct test_vector {
69 : void *buf; /* start of test vector buffer */
70 : int len; /* length of test vector */
71 : };
72 : struct fnv1a_32_test_vector {
73 : struct test_vector *test; /* test vector buffer to hash */
74 : unsigned int fnv1a_32; /* expected FNV-1a 32 bit hash value */
75 : };
76 : struct fnv1a_64_test_vector {
77 : struct test_vector *test; /* test vector buffer to hash */
78 : unsigned int fnv1a_64[2]; /* expected FNV-1a 64 bit hash value */
79 : };
80 :
81 : struct test_vector fnv_test_str[] = {
82 : TESTV(""),
83 : TESTV("a"),
84 : TESTV("b"),
85 : TESTV("c"),
86 : TESTV("d"),
87 : TESTV("e"),
88 :
89 : TESTV("f"),
90 : TESTV("fo"),
91 : TESTV("foo"),
92 : TESTV("foob"),
93 : TESTV("fooba"),
94 : TESTV("foobar"),
95 :
96 : TESTV0(""),
97 : TESTV0("a"),
98 : TESTV0("b"),
99 : TESTV0("c"),
100 : TESTV0("d"),
101 : TESTV0("e"),
102 :
103 : TESTV0("f"),
104 : TESTV0("fo"),
105 : TESTV0("foo"),
106 : TESTV0("foob"),
107 : TESTV0("fooba"),
108 : TESTV0("foobar"),
109 :
110 : TESTV("ch"),
111 : TESTV("cho"),
112 : TESTV("chon"),
113 : TESTV("chong"),
114 : TESTV("chongo"),
115 : TESTV("chongo "),
116 : TESTV("chongo w"),
117 : TESTV("chongo wa"),
118 : TESTV("chongo was"),
119 : TESTV("chongo was "),
120 : TESTV("chongo was h"),
121 : TESTV("chongo was he"),
122 : TESTV("chongo was her"),
123 : TESTV("chongo was here"),
124 : TESTV("chongo was here!"),
125 : TESTV("chongo was here!\n"),
126 :
127 : TESTV0("ch"),
128 : TESTV0("cho"),
129 : TESTV0("chon"),
130 : TESTV0("chong"),
131 : TESTV0("chongo"),
132 : TESTV0("chongo "),
133 : TESTV0("chongo w"),
134 : TESTV0("chongo wa"),
135 : TESTV0("chongo was"),
136 : TESTV0("chongo was "),
137 : TESTV0("chongo was h"),
138 : TESTV0("chongo was he"),
139 : TESTV0("chongo was her"),
140 : TESTV0("chongo was here"),
141 : TESTV0("chongo was here!"),
142 : TESTV0("chongo was here!\n"),
143 :
144 : TESTV("cu"),
145 : TESTV("cur"),
146 : TESTV("curd"),
147 : TESTV("curds"),
148 : TESTV("curds "),
149 : TESTV("curds a"),
150 : TESTV("curds an"),
151 : TESTV("curds and"),
152 : TESTV("curds and "),
153 : TESTV("curds and w"),
154 : TESTV("curds and wh"),
155 : TESTV("curds and whe"),
156 : TESTV("curds and whey"),
157 : TESTV("curds and whey\n"),
158 :
159 : TESTV0("cu"),
160 : TESTV0("cur"),
161 : TESTV0("curd"),
162 : TESTV0("curds"),
163 : TESTV0("curds "),
164 : TESTV0("curds a"),
165 : TESTV0("curds an"),
166 : TESTV0("curds and"),
167 : TESTV0("curds and "),
168 : TESTV0("curds and w"),
169 : TESTV0("curds and wh"),
170 : TESTV0("curds and whe"),
171 : TESTV0("curds and whey"),
172 : TESTV0("curds and whey\n"),
173 :
174 : TESTV("hi"),
175 : TESTV0("hi"),
176 :
177 : TESTV("hello"),
178 : TESTV0("hello"),
179 :
180 : TESTV("\xff\x00\x00\x01"),
181 : TESTV("\x01\x00\x00\xff"),
182 : TESTV("\xff\x00\x00\x02"),
183 : TESTV("\x02\x00\x00\xff"),
184 : TESTV("\xff\x00\x00\x03"),
185 : TESTV("\x03\x00\x00\xff"),
186 : TESTV("\xff\x00\x00\x04"),
187 : TESTV("\x04\x00\x00\xff"),
188 : TESTV("\x40\x51\x4e\x44"),
189 : TESTV("\x44\x4e\x51\x40"),
190 : TESTV("\x40\x51\x4e\x4a"),
191 : TESTV("\x4a\x4e\x51\x40"),
192 : TESTV("\x40\x51\x4e\x54"),
193 : TESTV("\x54\x4e\x51\x40"),
194 :
195 : TESTV("127.0.0.1"),
196 : TESTV0("127.0.0.1"),
197 : TESTV("127.0.0.2"),
198 : TESTV0("127.0.0.2"),
199 : TESTV("127.0.0.3"),
200 : TESTV0("127.0.0.3"),
201 : TESTV("64.81.78.68"),
202 : TESTV0("64.81.78.68"),
203 : TESTV("64.81.78.74"),
204 : TESTV0("64.81.78.74"),
205 : TESTV("64.81.78.84"),
206 : TESTV0("64.81.78.84"),
207 :
208 : TESTV("feedface"),
209 : TESTV0("feedface"),
210 : TESTV("feedfacedaffdeed"),
211 : TESTV0("feedfacedaffdeed"),
212 : TESTV("feedfacedeadbeef"),
213 : TESTV0("feedfacedeadbeef"),
214 :
215 : TESTV("line 1\nline 2\nline 3"),
216 :
217 : TESTV("chongo <Landon Curt Noll> /\\../\\"),
218 : TESTV0("chongo <Landon Curt Noll> /\\../\\"),
219 :
220 : TESTV("chongo (Landon Curt Noll) /\\../\\"),
221 : TESTV0("chongo (Landon Curt Noll) /\\../\\"),
222 :
223 : TESTV("http://antwrp.gsfc.nasa.gov/apod/astropix.html"),
224 : TESTV("http://en.wikipedia.org/wiki/Fowler_Noll_Vo_hash"),
225 : TESTV("http://epod.usra.edu/"),
226 : TESTV("http://exoplanet.eu/"),
227 : TESTV("http://hvo.wr.usgs.gov/cam3/"),
228 : TESTV("http://hvo.wr.usgs.gov/cams/HMcam/"),
229 : TESTV("http://hvo.wr.usgs.gov/kilauea/update/deformation.html"),
230 : TESTV("http://hvo.wr.usgs.gov/kilauea/update/images.html"),
231 : TESTV("http://hvo.wr.usgs.gov/kilauea/update/maps.html"),
232 : TESTV("http://hvo.wr.usgs.gov/volcanowatch/current_issue.html"),
233 : TESTV("http://neo.jpl.nasa.gov/risk/"),
234 : TESTV("http://norvig.com/21-days.html"),
235 : TESTV("http://primes.utm.edu/curios/home.php"),
236 : TESTV("http://slashdot.org/"),
237 : TESTV("http://tux.wr.usgs.gov/Maps/155.25-19.5.html"),
238 : TESTV("http://volcano.wr.usgs.gov/kilaueastatus.php"),
239 : TESTV("http://www.avo.alaska.edu/activity/Redoubt.php"),
240 : TESTV("http://www.dilbert.com/fast/"),
241 : TESTV("http://www.fourmilab.ch/gravitation/orbits/"),
242 : TESTV("http://www.fpoa.net/"),
243 : TESTV("http://www.ioccc.org/index.html"),
244 : TESTV("http://www.isthe.com/cgi-bin/number.cgi"),
245 : TESTV("http://www.isthe.com/chongo/bio.html"),
246 : TESTV("http://www.isthe.com/chongo/index.html"),
247 : TESTV("http://www.isthe.com/chongo/src/calc/lucas-calc"),
248 : TESTV("http://www.isthe.com/chongo/tech/astro/venus2004.html"),
249 : TESTV("http://www.isthe.com/chongo/tech/astro/vita.html"),
250 : TESTV("http://www.isthe.com/chongo/tech/comp/c/expert.html"),
251 : TESTV("http://www.isthe.com/chongo/tech/comp/calc/index.html"),
252 : TESTV("http://www.isthe.com/chongo/tech/comp/fnv/index.html"),
253 : TESTV("http://www.isthe.com/chongo/tech/math/number/howhigh.html"),
254 : TESTV("http://www.isthe.com/chongo/tech/math/number/number.html"),
255 : TESTV("http://www.isthe.com/chongo/tech/math/prime/mersenne.html"),
256 : TESTV("http://www.isthe.com/chongo/tech/math/prime/mersenne.html#largest"),
257 : TESTV("http://www.lavarnd.org/cgi-bin/corpspeak.cgi"),
258 : TESTV("http://www.lavarnd.org/cgi-bin/haiku.cgi"),
259 : TESTV("http://www.lavarnd.org/cgi-bin/rand-none.cgi"),
260 : TESTV("http://www.lavarnd.org/cgi-bin/randdist.cgi"),
261 : TESTV("http://www.lavarnd.org/index.html"),
262 : TESTV("http://www.lavarnd.org/what/nist-test.html"),
263 : TESTV("http://www.macosxhints.com/"),
264 : TESTV("http://www.mellis.com/"),
265 : TESTV("http://www.nature.nps.gov/air/webcams/parks/havoso2alert/havoalert.cfm"),
266 : TESTV("http://www.nature.nps.gov/air/webcams/parks/havoso2alert/timelines_24.cfm"),
267 : TESTV("http://www.paulnoll.com/"),
268 : TESTV("http://www.pepysdiary.com/"),
269 : TESTV("http://www.sciencenews.org/index/home/activity/view"),
270 : TESTV("http://www.skyandtelescope.com/"),
271 : TESTV("http://www.sput.nl/~rob/sirius.html"),
272 : TESTV("http://www.systemexperts.com/"),
273 : TESTV("http://www.tq-international.com/phpBB3/index.php"),
274 : TESTV("http://www.travelquesttours.com/index.htm"),
275 : TESTV("http://www.wunderground.com/global/stations/89606.html"),
276 :
277 : TESTV(R10("21701")),
278 : TESTV(R10("M21701")),
279 : TESTV(R10("2^21701-1")),
280 : TESTV(R10("\x54\xc5")),
281 : TESTV(R10("\xc5\x54")),
282 : TESTV(R10("23209")),
283 : TESTV(R10("M23209")),
284 : TESTV(R10("2^23209-1")),
285 : TESTV(R10("\x5a\xa9")),
286 : TESTV(R10("\xa9\x5a")),
287 : TESTV(R10("391581216093")),
288 : TESTV(R10("391581*2^216093-1")),
289 : TESTV(R10("\x05\xf9\x9d\x03\x4c\x81")),
290 : TESTV(R10("FEDCBA9876543210")),
291 : TESTV(R10("\xfe\xdc\xba\x98\x76\x54\x32\x10")),
292 : TESTV(R10("EFCDAB8967452301")),
293 : TESTV(R10("\xef\xcd\xab\x89\x67\x45\x23\x01")),
294 : TESTV(R10("0123456789ABCDEF")),
295 : TESTV(R10("\x01\x23\x45\x67\x89\xab\xcd\xef")),
296 : TESTV(R10("1032547698BADCFE")),
297 : TESTV(R10("\x10\x32\x54\x76\x98\xba\xdc\xfe")),
298 : TESTV(R500("\x00")),
299 : TESTV(R500("\x07")),
300 : TESTV(R500("~")),
301 : TESTV(R500("\x7f")),
302 :
303 : {NULL, 0} /* MUST BE LAST */
304 : };
305 :
306 : struct fnv1a_32_test_vector fnv1a_32_vector[] = {
307 : { &fnv_test_str[0], 0x811c9dc5UL },
308 : { &fnv_test_str[1], 0xe40c292cUL },
309 : { &fnv_test_str[2], 0xe70c2de5UL },
310 : { &fnv_test_str[3], 0xe60c2c52UL },
311 : { &fnv_test_str[4], 0xe10c2473UL },
312 : { &fnv_test_str[5], 0xe00c22e0UL },
313 : { &fnv_test_str[6], 0xe30c2799UL },
314 : { &fnv_test_str[7], 0x6222e842UL },
315 : { &fnv_test_str[8], 0xa9f37ed7UL },
316 : { &fnv_test_str[9], 0x3f5076efUL },
317 : { &fnv_test_str[10], 0x39aaa18aUL },
318 : { &fnv_test_str[11], 0xbf9cf968UL },
319 : { &fnv_test_str[12], 0x050c5d1fUL },
320 : { &fnv_test_str[13], 0x2b24d044UL },
321 : { &fnv_test_str[14], 0x9d2c3f7fUL },
322 : { &fnv_test_str[15], 0x7729c516UL },
323 : { &fnv_test_str[16], 0xb91d6109UL },
324 : { &fnv_test_str[17], 0x931ae6a0UL },
325 : { &fnv_test_str[18], 0x052255dbUL },
326 : { &fnv_test_str[19], 0xbef39fe6UL },
327 : { &fnv_test_str[20], 0x6150ac75UL },
328 : { &fnv_test_str[21], 0x9aab3a3dUL },
329 : { &fnv_test_str[22], 0x519c4c3eUL },
330 : { &fnv_test_str[23], 0x0c1c9eb8UL },
331 : { &fnv_test_str[24], 0x5f299f4eUL },
332 : { &fnv_test_str[25], 0xef8580f3UL },
333 : { &fnv_test_str[26], 0xac297727UL },
334 : { &fnv_test_str[27], 0x4546b9c0UL },
335 : { &fnv_test_str[28], 0xbd564e7dUL },
336 : { &fnv_test_str[29], 0x6bdd5c67UL },
337 : { &fnv_test_str[30], 0xdd77ed30UL },
338 : { &fnv_test_str[31], 0xf4ca9683UL },
339 : { &fnv_test_str[32], 0x4aeb9bd0UL },
340 : { &fnv_test_str[33], 0xe0e67ad0UL },
341 : { &fnv_test_str[34], 0xc2d32fa8UL },
342 : { &fnv_test_str[35], 0x7f743fb7UL },
343 : { &fnv_test_str[36], 0x6900631fUL },
344 : { &fnv_test_str[37], 0xc59c990eUL },
345 : { &fnv_test_str[38], 0x448524fdUL },
346 : { &fnv_test_str[39], 0xd49930d5UL },
347 : { &fnv_test_str[40], 0x1c85c7caUL },
348 : { &fnv_test_str[41], 0x0229fe89UL },
349 : { &fnv_test_str[42], 0x2c469265UL },
350 : { &fnv_test_str[43], 0xce566940UL },
351 : { &fnv_test_str[44], 0x8bdd8ec7UL },
352 : { &fnv_test_str[45], 0x34787625UL },
353 : { &fnv_test_str[46], 0xd3ca6290UL },
354 : { &fnv_test_str[47], 0xddeaf039UL },
355 : { &fnv_test_str[48], 0xc0e64870UL },
356 : { &fnv_test_str[49], 0xdad35570UL },
357 : { &fnv_test_str[50], 0x5a740578UL },
358 : { &fnv_test_str[51], 0x5b004d15UL },
359 : { &fnv_test_str[52], 0x6a9c09cdUL },
360 : { &fnv_test_str[53], 0x2384f10aUL },
361 : { &fnv_test_str[54], 0xda993a47UL },
362 : { &fnv_test_str[55], 0x8227df4fUL },
363 : { &fnv_test_str[56], 0x4c298165UL },
364 : { &fnv_test_str[57], 0xfc563735UL },
365 : { &fnv_test_str[58], 0x8cb91483UL },
366 : { &fnv_test_str[59], 0x775bf5d0UL },
367 : { &fnv_test_str[60], 0xd5c428d0UL },
368 : { &fnv_test_str[61], 0x34cc0ea3UL },
369 : { &fnv_test_str[62], 0xea3b4cb7UL },
370 : { &fnv_test_str[63], 0x8e59f029UL },
371 : { &fnv_test_str[64], 0x2094de2bUL },
372 : { &fnv_test_str[65], 0xa65a0ad4UL },
373 : { &fnv_test_str[66], 0x9bbee5f4UL },
374 : { &fnv_test_str[67], 0xbe836343UL },
375 : { &fnv_test_str[68], 0x22d5344eUL },
376 : { &fnv_test_str[69], 0x19a1470cUL },
377 : { &fnv_test_str[70], 0x4a56b1ffUL },
378 : { &fnv_test_str[71], 0x70b8e86fUL },
379 : { &fnv_test_str[72], 0x0a5b4a39UL },
380 : { &fnv_test_str[73], 0xb5c3f670UL },
381 : { &fnv_test_str[74], 0x53cc3f70UL },
382 : { &fnv_test_str[75], 0xc03b0a99UL },
383 : { &fnv_test_str[76], 0x7259c415UL },
384 : { &fnv_test_str[77], 0x4095108bUL },
385 : { &fnv_test_str[78], 0x7559bdb1UL },
386 : { &fnv_test_str[79], 0xb3bf0bbcUL },
387 : { &fnv_test_str[80], 0x2183ff1cUL },
388 : { &fnv_test_str[81], 0x2bd54279UL },
389 : { &fnv_test_str[82], 0x23a156caUL },
390 : { &fnv_test_str[83], 0x64e2d7e4UL },
391 : { &fnv_test_str[84], 0x683af69aUL },
392 : { &fnv_test_str[85], 0xaed2346eUL },
393 : { &fnv_test_str[86], 0x4f9f2cabUL },
394 : { &fnv_test_str[87], 0x02935131UL },
395 : { &fnv_test_str[88], 0xc48fb86dUL },
396 : { &fnv_test_str[89], 0x2269f369UL },
397 : { &fnv_test_str[90], 0xc18fb3b4UL },
398 : { &fnv_test_str[91], 0x50ef1236UL },
399 : { &fnv_test_str[92], 0xc28fb547UL },
400 : { &fnv_test_str[93], 0x96c3bf47UL },
401 : { &fnv_test_str[94], 0xbf8fb08eUL },
402 : { &fnv_test_str[95], 0xf3e4d49cUL },
403 : { &fnv_test_str[96], 0x32179058UL },
404 : { &fnv_test_str[97], 0x280bfee6UL },
405 : { &fnv_test_str[98], 0x30178d32UL },
406 : { &fnv_test_str[99], 0x21addaf8UL },
407 : { &fnv_test_str[100], 0x4217a988UL },
408 : { &fnv_test_str[101], 0x772633d6UL },
409 : { &fnv_test_str[102], 0x08a3d11eUL },
410 : { &fnv_test_str[103], 0xb7e2323aUL },
411 : { &fnv_test_str[104], 0x07a3cf8bUL },
412 : { &fnv_test_str[105], 0x91dfb7d1UL },
413 : { &fnv_test_str[106], 0x06a3cdf8UL },
414 : { &fnv_test_str[107], 0x6bdd3d68UL },
415 : { &fnv_test_str[108], 0x1d5636a7UL },
416 : { &fnv_test_str[109], 0xd5b808e5UL },
417 : { &fnv_test_str[110], 0x1353e852UL },
418 : { &fnv_test_str[111], 0xbf16b916UL },
419 : { &fnv_test_str[112], 0xa55b89edUL },
420 : { &fnv_test_str[113], 0x3c1a2017UL },
421 : { &fnv_test_str[114], 0x0588b13cUL },
422 : { &fnv_test_str[115], 0xf22f0174UL },
423 : { &fnv_test_str[116], 0xe83641e1UL },
424 : { &fnv_test_str[117], 0x6e69b533UL },
425 : { &fnv_test_str[118], 0xf1760448UL },
426 : { &fnv_test_str[119], 0x64c8bd58UL },
427 : { &fnv_test_str[120], 0x97b4ea23UL },
428 : { &fnv_test_str[121], 0x9a4e92e6UL },
429 : { &fnv_test_str[122], 0xcfb14012UL },
430 : { &fnv_test_str[123], 0xf01b2511UL },
431 : { &fnv_test_str[124], 0x0bbb59c3UL },
432 : { &fnv_test_str[125], 0xce524afaUL },
433 : { &fnv_test_str[126], 0xdd16ef45UL },
434 : { &fnv_test_str[127], 0x60648bb3UL },
435 : { &fnv_test_str[128], 0x7fa4bcfcUL },
436 : { &fnv_test_str[129], 0x5053ae17UL },
437 : { &fnv_test_str[130], 0xc9302890UL },
438 : { &fnv_test_str[131], 0x956ded32UL },
439 : { &fnv_test_str[132], 0x9136db84UL },
440 : { &fnv_test_str[133], 0xdf9d3323UL },
441 : { &fnv_test_str[134], 0x32bb6cd0UL },
442 : { &fnv_test_str[135], 0xc8f8385bUL },
443 : { &fnv_test_str[136], 0xeb08bfbaUL },
444 : { &fnv_test_str[137], 0x62cc8e3dUL },
445 : { &fnv_test_str[138], 0xc3e20f5cUL },
446 : { &fnv_test_str[139], 0x39e97f17UL },
447 : { &fnv_test_str[140], 0x7837b203UL },
448 : { &fnv_test_str[141], 0x319e877bUL },
449 : { &fnv_test_str[142], 0xd3e63f89UL },
450 : { &fnv_test_str[143], 0x29b50b38UL },
451 : { &fnv_test_str[144], 0x5ed678b8UL },
452 : { &fnv_test_str[145], 0xb0d5b793UL },
453 : { &fnv_test_str[146], 0x52450be5UL },
454 : { &fnv_test_str[147], 0xfa72d767UL },
455 : { &fnv_test_str[148], 0x95066709UL },
456 : { &fnv_test_str[149], 0x7f52e123UL },
457 : { &fnv_test_str[150], 0x76966481UL },
458 : { &fnv_test_str[151], 0x063258b0UL },
459 : { &fnv_test_str[152], 0x2ded6e8aUL },
460 : { &fnv_test_str[153], 0xb07d7c52UL },
461 : { &fnv_test_str[154], 0xd0c71b71UL },
462 : { &fnv_test_str[155], 0xf684f1bdUL },
463 : { &fnv_test_str[156], 0x868ecfa8UL },
464 : { &fnv_test_str[157], 0xf794f684UL },
465 : { &fnv_test_str[158], 0xd19701c3UL },
466 : { &fnv_test_str[159], 0x346e171eUL },
467 : { &fnv_test_str[160], 0x91f8f676UL },
468 : { &fnv_test_str[161], 0x0bf58848UL },
469 : { &fnv_test_str[162], 0x6317b6d1UL },
470 : { &fnv_test_str[163], 0xafad4c54UL },
471 : { &fnv_test_str[164], 0x0f25681eUL },
472 : { &fnv_test_str[165], 0x91b18d49UL },
473 : { &fnv_test_str[166], 0x7d61c12eUL },
474 : { &fnv_test_str[167], 0x5147d25cUL },
475 : { &fnv_test_str[168], 0x9a8b6805UL },
476 : { &fnv_test_str[169], 0x4cd2a447UL },
477 : { &fnv_test_str[170], 0x1e549b14UL },
478 : { &fnv_test_str[171], 0x2fe1b574UL },
479 : { &fnv_test_str[172], 0xcf0cd31eUL },
480 : { &fnv_test_str[173], 0x6c471669UL },
481 : { &fnv_test_str[174], 0x0e5eef1eUL },
482 : { &fnv_test_str[175], 0x2bed3602UL },
483 : { &fnv_test_str[176], 0xb26249e0UL },
484 : { &fnv_test_str[177], 0x2c9b86a4UL },
485 : { &fnv_test_str[178], 0xe415e2bbUL },
486 : { &fnv_test_str[179], 0x18a98d1dUL },
487 : { &fnv_test_str[180], 0xb7df8b7bUL },
488 : { &fnv_test_str[181], 0x241e9075UL },
489 : { &fnv_test_str[182], 0x063f70ddUL },
490 : { &fnv_test_str[183], 0x0295aed9UL },
491 : { &fnv_test_str[184], 0x56a7f781UL },
492 : { &fnv_test_str[185], 0x253bc645UL },
493 : { &fnv_test_str[186], 0x46610921UL },
494 : { &fnv_test_str[187], 0x7c1577f9UL },
495 : { &fnv_test_str[188], 0x512b2851UL },
496 : { &fnv_test_str[189], 0x76823999UL },
497 : { &fnv_test_str[190], 0xc0586935UL },
498 : { &fnv_test_str[191], 0xf3415c85UL },
499 : { &fnv_test_str[192], 0x0ae4ff65UL },
500 : { &fnv_test_str[193], 0x58b79725UL },
501 : { &fnv_test_str[194], 0xdea43aa5UL },
502 : { &fnv_test_str[195], 0x2bb3be35UL },
503 : { &fnv_test_str[196], 0xea777a45UL },
504 : { &fnv_test_str[197], 0x8f21c305UL },
505 : { &fnv_test_str[198], 0x5c9d0865UL },
506 : { &fnv_test_str[199], 0xfa823dd5UL },
507 : { &fnv_test_str[200], 0x21a27271UL },
508 : { &fnv_test_str[201], 0x83c5c6d5UL },
509 : { &fnv_test_str[202], 0x813b0881UL },
510 : { NULL, 0 }
511 : };
512 :
513 : struct fnv1a_64_test_vector fnv1a_64_vector[] = {
514 : { &fnv_test_str[0], {0x84222325UL, 0xcbf29ce4UL} },
515 : { &fnv_test_str[1], {0x8601ec8cUL, 0xaf63dc4cUL} },
516 : { &fnv_test_str[2], {0x8601f1a5UL, 0xaf63df4cUL} },
517 : { &fnv_test_str[3], {0x8601eff2UL, 0xaf63de4cUL} },
518 : { &fnv_test_str[4], {0x8601e773UL, 0xaf63d94cUL} },
519 : { &fnv_test_str[5], {0x8601e5c0UL, 0xaf63d84cUL} },
520 : { &fnv_test_str[6], {0x8601ead9UL, 0xaf63db4cUL} },
521 : { &fnv_test_str[7], {0xb541d342UL, 0x08985907UL} },
522 : { &fnv_test_str[8], {0xfed9d577UL, 0xdcb27518UL} },
523 : { &fnv_test_str[9], {0x0c2512afUL, 0xdd120e79UL} },
524 : { &fnv_test_str[10], {0xa2fef40aUL, 0xcac165afUL} },
525 : { &fnv_test_str[11], {0xf73967e8UL, 0x85944171UL} },
526 : { &fnv_test_str[12], {0x8601b7dfUL, 0xaf63bd4cUL} },
527 : { &fnv_test_str[13], {0xb544f1e4UL, 0x089be207UL} },
528 : { &fnv_test_str[14], {0xb54d9b5fUL, 0x08a61407UL} },
529 : { &fnv_test_str[15], {0xb54ab836UL, 0x08a2ae07UL} },
530 : { &fnv_test_str[16], {0xb53c4869UL, 0x0891b007UL} },
531 : { &fnv_test_str[17], {0xb5396540UL, 0x088e4a07UL} },
532 : { &fnv_test_str[18], {0xb5420ebbUL, 0x08987c07UL} },
533 : { &fnv_test_str[19], {0xfed9f926UL, 0xdcb28a18UL} },
534 : { &fnv_test_str[20], {0x0c25b935UL, 0xdd127079UL} },
535 : { &fnv_test_str[21], {0xa2febf5dUL, 0xcac146afUL} },
536 : { &fnv_test_str[22], {0xf738acfeUL, 0x8593d371UL} },
537 : { &fnv_test_str[23], {0x168b8f38UL, 0x34531ca7UL} },
538 : { &fnv_test_str[24], {0xb54a22aeUL, 0x08a25607UL} },
539 : { &fnv_test_str[25], {0x0cf90df3UL, 0xf5faf019UL} },
540 : { &fnv_test_str[26], {0x0b3221c7UL, 0xf2739791UL} },
541 : { &fnv_test_str[27], {0x062f22e0UL, 0x2c8c2b76UL} },
542 : { &fnv_test_str[28], {0x8217b8fdUL, 0xe150688cUL} },
543 : { &fnv_test_str[29], {0x0e4f1f87UL, 0xf35a83c1UL} },
544 : { &fnv_test_str[30], {0x507344d0UL, 0xd1edd10bUL} },
545 : { &fnv_test_str[31], {0xb3ddb8c3UL, 0x2a5ee739UL} },
546 : { &fnv_test_str[32], {0xa1c0d310UL, 0xdcfb970cUL} },
547 : { &fnv_test_str[33], {0xdaa6da90UL, 0x4054da76UL} },
548 : { &fnv_test_str[34], {0x89861368UL, 0xf70a2ff5UL} },
549 : { &fnv_test_str[35], {0xaed25f17UL, 0x4c628b38UL} },
550 : { &fnv_test_str[36], {0x0f78189fUL, 0x9dd1f651UL} },
551 : { &fnv_test_str[37], {0x491270ceUL, 0xa3de85bdUL} },
552 : { &fnv_test_str[38], {0x2a55e61dUL, 0x858e2fa3UL} },
553 : { &fnv_test_str[39], {0xeff5f915UL, 0x46810940UL} },
554 : { &fnv_test_str[40], {0x0cf8edaaUL, 0xf5fadd19UL} },
555 : { &fnv_test_str[41], {0x0b32b3e9UL, 0xf273ed91UL} },
556 : { &fnv_test_str[42], {0x062f6525UL, 0x2c8c5276UL} },
557 : { &fnv_test_str[43], {0x821842a0UL, 0xe150b98cUL} },
558 : { &fnv_test_str[44], {0x0e4f55e7UL, 0xf35aa3c1UL} },
559 : { &fnv_test_str[45], {0x50729265UL, 0xd1ed680bUL} },
560 : { &fnv_test_str[46], {0xb3dded70UL, 0x2a5f0639UL} },
561 : { &fnv_test_str[47], {0xa1c0f359UL, 0xdcfbaa0cUL} },
562 : { &fnv_test_str[48], {0xdaa6a430UL, 0x4054ba76UL} },
563 : { &fnv_test_str[49], {0x898562b0UL, 0xf709c7f5UL} },
564 : { &fnv_test_str[50], {0xaed2f9b8UL, 0x4c62e638UL} },
565 : { &fnv_test_str[51], {0x0f779415UL, 0x9dd1a851UL} },
566 : { &fnv_test_str[52], {0x4911d62dUL, 0xa3de2abdUL} },
567 : { &fnv_test_str[53], {0x2a55ae0aUL, 0x858e0ea3UL} },
568 : { &fnv_test_str[54], {0xeff60347UL, 0x46810f40UL} },
569 : { &fnv_test_str[55], {0xbef63eafUL, 0xc33bce57UL} },
570 : { &fnv_test_str[56], {0xb54a0265UL, 0x08a24307UL} },
571 : { &fnv_test_str[57], {0x0cc18d15UL, 0xf5b9fd19UL} },
572 : { &fnv_test_str[58], {0xace35703UL, 0x4c968290UL} },
573 : { &fnv_test_str[59], {0xc64d9350UL, 0x07174bd5UL} },
574 : { &fnv_test_str[60], {0xf5d18750UL, 0x5a294c3fUL} },
575 : { &fnv_test_str[61], {0xb308b843UL, 0x05b3c1aeUL} },
576 : { &fnv_test_str[62], {0x37d0f477UL, 0xb92a48daUL} },
577 : { &fnv_test_str[63], {0xd80ebc49UL, 0x73cdddccUL} },
578 : { &fnv_test_str[64], {0x210a266bUL, 0xd58c4c13UL} },
579 : { &fnv_test_str[65], {0x243ec194UL, 0xe78b6081UL} },
580 : { &fnv_test_str[66], {0x96a39f34UL, 0xb096f770UL} },
581 : { &fnv_test_str[67], {0xf807b6a3UL, 0xb425c54fUL} },
582 : { &fnv_test_str[68], {0x751bb46eUL, 0x23e520e2UL} },
583 : { &fnv_test_str[69], {0xfe1385ecUL, 0x1a0b44ccUL} },
584 : { &fnv_test_str[70], {0x0cc2119fUL, 0xf5ba4b19UL} },
585 : { &fnv_test_str[71], {0xace2baafUL, 0x4c962690UL} },
586 : { &fnv_test_str[72], {0xc64cda19UL, 0x0716ded5UL} },
587 : { &fnv_test_str[73], {0xf5d150f0UL, 0x5a292c3fUL} },
588 : { &fnv_test_str[74], {0xb308ecf0UL, 0x05b3e0aeUL} },
589 : { &fnv_test_str[75], {0x37d119d9UL, 0xb92a5edaUL} },
590 : { &fnv_test_str[76], {0xd80f6635UL, 0x73ce41ccUL} },
591 : { &fnv_test_str[77], {0x2109f00bUL, 0xd58c2c13UL} },
592 : { &fnv_test_str[78], {0x243f47d1UL, 0xe78baf81UL} },
593 : { &fnv_test_str[79], {0x96a2ee7cUL, 0xb0968f70UL} },
594 : { &fnv_test_str[80], {0xf807855cUL, 0xb425a84fUL} },
595 : { &fnv_test_str[81], {0x751b56f9UL, 0x23e4e9e2UL} },
596 : { &fnv_test_str[82], {0xfe1396eaUL, 0x1a0b4eccUL} },
597 : { &fnv_test_str[83], {0xbb2c9004UL, 0x54abd453UL} },
598 : { &fnv_test_str[84], {0xb55ec3daUL, 0x08ba5f07UL} },
599 : { &fnv_test_str[85], {0x3006cb6eUL, 0x33735419UL} },
600 : { &fnv_test_str[86], {0x80aabd0bUL, 0xa430d846UL} },
601 : { &fnv_test_str[87], {0xa21f39b1UL, 0xa9bc8accUL} },
602 : { &fnv_test_str[88], {0x91cc682dUL, 0x69611964UL} },
603 : { &fnv_test_str[89], {0x4799dfe9UL, 0xad2bb177UL} },
604 : { &fnv_test_str[90], {0x91cc6314UL, 0x69611664UL} },
605 : { &fnv_test_str[91], {0x4a3b1236UL, 0x8d1bb390UL} },
606 : { &fnv_test_str[92], {0x91cc64c7UL, 0x69611764UL} },
607 : { &fnv_test_str[93], {0xf40434c7UL, 0xed205d87UL} },
608 : { &fnv_test_str[94], {0x91cc5faeUL, 0x69611464UL} },
609 : { &fnv_test_str[95], {0x44f8ad9cUL, 0xcd3baf5eUL} },
610 : { &fnv_test_str[96], {0x127cd6d8UL, 0xe3b36596UL} },
611 : { &fnv_test_str[97], {0xc8e8a646UL, 0xf77f1072UL} },
612 : { &fnv_test_str[98], {0x127cd372UL, 0xe3b36396UL} },
613 : { &fnv_test_str[99], {0x932ad458UL, 0x6067dce9UL} },
614 : { &fnv_test_str[100], {0x127cf208UL, 0xe3b37596UL} },
615 : { &fnv_test_str[101], {0x9fe83936UL, 0x4b7b10faUL} },
616 : { &fnv_test_str[102], {0x04d914beUL, 0xaabafe71UL} },
617 : { &fnv_test_str[103], {0x3cde3edaUL, 0xf4d3180bUL} },
618 : { &fnv_test_str[104], {0x04d9130bUL, 0xaabafd71UL} },
619 : { &fnv_test_str[105], {0x3cdb5bb1UL, 0xf4cfb20bUL} },
620 : { &fnv_test_str[106], {0x04d91158UL, 0xaabafc71UL} },
621 : { &fnv_test_str[107], {0x3cd87888UL, 0xf4cc4c0bUL} },
622 : { &fnv_test_str[108], {0xd2a8d3a7UL, 0xe729bac5UL} },
623 : { &fnv_test_str[109], {0xf4dfa4c5UL, 0x74bc0524UL} },
624 : { &fnv_test_str[110], {0xd2a5b352UL, 0xe72630c5UL} },
625 : { &fnv_test_str[111], {0xef8fb456UL, 0x6b983224UL} },
626 : { &fnv_test_str[112], {0xd2ae266dUL, 0xe73042c5UL} },
627 : { &fnv_test_str[113], {0xfdeb4b37UL, 0x8527e324UL} },
628 : { &fnv_test_str[114], {0xee952abcUL, 0x0a83c86fUL} },
629 : { &fnv_test_str[115], {0x67779d74UL, 0x73185232UL} },
630 : { &fnv_test_str[116], {0x6b8caca1UL, 0x3e66d3d5UL} },
631 : { &fnv_test_str[117], {0xc0095593UL, 0x956694a5UL} },
632 : { &fnv_test_str[118], {0xbb1a6fc8UL, 0xcac54572UL} },
633 : { &fnv_test_str[119], {0xedebf0d8UL, 0xa7a4c9f3UL} },
634 : { &fnv_test_str[120], {0xac17b143UL, 0x7829851fUL} },
635 : { &fnv_test_str[121], {0xf81bcf06UL, 0x2c8f4c9aUL} },
636 : { &fnv_test_str[122], {0x9740c732UL, 0xd34e3153UL} },
637 : { &fnv_test_str[123], {0x253d2db1UL, 0x3605a2acUL} },
638 : { &fnv_test_str[124], {0x46f4a3c3UL, 0x08c11b83UL} },
639 : { &fnv_test_str[125], {0x9ce8a6daUL, 0x6be39628UL} },
640 : { &fnv_test_str[126], {0x7fe794c5UL, 0xd9b957fbUL} },
641 : { &fnv_test_str[127], {0x04560a93UL, 0x05be33daUL} },
642 : { &fnv_test_str[128], {0x7ba9747cUL, 0x0957f157UL} },
643 : { &fnv_test_str[129], {0xc24fba57UL, 0xda2cc3acUL} },
644 : { &fnv_test_str[130], {0x5b29e7f0UL, 0x74136f18UL} },
645 : { &fnv_test_str[131], {0x0edb93b2UL, 0xb2f2b459UL} },
646 : { &fnv_test_str[132], {0x8b86ae04UL, 0xb3608fceUL} },
647 : { &fnv_test_str[133], {0x79359063UL, 0x4a3a8650UL} },
648 : { &fnv_test_str[134], {0x96880a50UL, 0x5b3a7ef4UL} },
649 : { &fnv_test_str[135], {0x3854c23bUL, 0x48fae316UL} },
650 : { &fnv_test_str[136], {0x476e0b9aUL, 0x07aaa640UL} },
651 : { &fnv_test_str[137], {0x383a687dUL, 0x2f653656UL} },
652 : { &fnv_test_str[138], {0x7599d79cUL, 0xa1031f8eUL} },
653 : { &fnv_test_str[139], {0x8ff92477UL, 0xa3190817UL} },
654 : { &fnv_test_str[140], {0x14c3fb83UL, 0x097edf3cUL} },
655 : { &fnv_test_str[141], {0xeaa0971bUL, 0xb51ca83fUL} },
656 : { &fnv_test_str[142], {0xd784f2e9UL, 0xdd3c0d96UL} },
657 : { &fnv_test_str[143], {0xea767d78UL, 0x86cd26a9UL} },
658 : { &fnv_test_str[144], {0x54a30c18UL, 0xe6b215ffUL} },
659 : { &fnv_test_str[145], {0xc5531093UL, 0xec5b06a1UL} },
660 : { &fnv_test_str[146], {0x9f9ec5e5UL, 0x45665a92UL} },
661 : { &fnv_test_str[147], {0xa9f10907UL, 0x8c7609b4UL} },
662 : { &fnv_test_str[148], {0x91f0d729UL, 0x89aac3a4UL} },
663 : { &fnv_test_str[149], {0xe0f4a403UL, 0x32ce6b26UL} },
664 : { &fnv_test_str[150], {0x02b53e01UL, 0x614ab44eUL} },
665 : { &fnv_test_str[151], {0x6eef3290UL, 0xfa6472ebUL} },
666 : { &fnv_test_str[152], {0x1948eb6aUL, 0x9e5d75ebUL} },
667 : { &fnv_test_str[153], {0xa8671852UL, 0xb6d12ad4UL} },
668 : { &fnv_test_str[154], {0xeba07af1UL, 0x88826f56UL} },
669 : { &fnv_test_str[155], {0x645bc0fdUL, 0x44535bf2UL} },
670 : { &fnv_test_str[156], {0xc21e3728UL, 0x169388ffUL} },
671 : { &fnv_test_str[157], {0x396d8224UL, 0xf68aac9eUL} },
672 : { &fnv_test_str[158], {0x472b3883UL, 0x8e87d7e7UL} },
673 : { &fnv_test_str[159], {0xa8b423deUL, 0x295c26caUL} },
674 : { &fnv_test_str[160], {0x92e72176UL, 0x322c8142UL} },
675 : { &fnv_test_str[161], {0xb8af7268UL, 0x8a06550eUL} },
676 : { &fnv_test_str[162], {0x661bcf71UL, 0xef86d60eUL} },
677 : { &fnv_test_str[163], {0x7f30ee54UL, 0x9e5426c8UL} },
678 : { &fnv_test_str[164], {0x26fd047eUL, 0xf1ea8aa8UL} },
679 : { &fnv_test_str[165], {0x642cb769UL, 0x0babaf9aUL} },
680 : { &fnv_test_str[166], {0x068d012eUL, 0x4b3341d4UL} },
681 : { &fnv_test_str[167], {0xc30a335cUL, 0xd15605cbUL} },
682 : { &fnv_test_str[168], {0xed8412e5UL, 0x5b21060aUL} },
683 : { &fnv_test_str[169], {0xce6f4227UL, 0x45e2cda1UL} },
684 : { &fnv_test_str[170], {0x033ad7d4UL, 0x50ae3745UL} },
685 : { &fnv_test_str[171], {0xd46bf414UL, 0xaa4588ceUL} },
686 : { &fnv_test_str[172], {0x4a95467eUL, 0xc1b0056cUL} },
687 : { &fnv_test_str[173], {0xde8b4089UL, 0x56576a71UL} },
688 : { &fnv_test_str[174], {0xa6dc927eUL, 0xbf20965fUL} },
689 : { &fnv_test_str[175], {0xc2040882UL, 0x569f8383UL} },
690 : { &fnv_test_str[176], {0xa08feca0UL, 0xe1e772fbUL} },
691 : { &fnv_test_str[177], {0x97138ac4UL, 0x4ced94afUL} },
692 : { &fnv_test_str[178], {0x337a82fbUL, 0xc4112ffbUL} },
693 : { &fnv_test_str[179], {0x1de38b7dUL, 0xd64a4fd4UL} },
694 : { &fnv_test_str[180], {0x9edebcbbUL, 0x4cfc3232UL} },
695 : { &fnv_test_str[181], {0x45050395UL, 0x08035644UL} },
696 : { &fnv_test_str[182], {0xf4642ffdUL, 0xaa1574ecUL} },
697 : { &fnv_test_str[183], {0x4cc315f9UL, 0x694bc4e5UL} },
698 : { &fnv_test_str[184], {0x3b011721UL, 0xa3d7cb27UL} },
699 : { &fnv_test_str[185], {0x6115bfa5UL, 0x577c2f8bUL} },
700 : { &fnv_test_str[186], {0x769fb4c1UL, 0xb7ec8c1aUL} },
701 : { &fnv_test_str[187], {0x3359ab19UL, 0x5d5cfce6UL} },
702 : { &fnv_test_str[188], {0xd65b5f71UL, 0x33b96c3cUL} },
703 : { &fnv_test_str[189], {0x80602bb9UL, 0xd8450977UL} },
704 : { &fnv_test_str[190], {0xd02da3d5UL, 0x84d47645UL} },
705 : { &fnv_test_str[191], {0xb58773a5UL, 0x83544f33UL} },
706 : { &fnv_test_str[192], {0x160836c5UL, 0x9175cbb2UL} },
707 : { &fnv_test_str[193], {0x75e72bc5UL, 0xc71b3bc1UL} },
708 : { &fnv_test_str[194], {0x222ec985UL, 0x636806acUL} },
709 : { &fnv_test_str[195], {0x50f52ed5UL, 0xb6ef0e69UL} },
710 : { &fnv_test_str[196], {0xf3dfdaa5UL, 0xead3d8a0UL} },
711 : { &fnv_test_str[197], {0x9a861ba5UL, 0x922908feUL} },
712 : { &fnv_test_str[198], {0x275fd5c5UL, 0x6d4821deUL} },
713 : { &fnv_test_str[199], {0x2bd816b5UL, 0x1fe3fce6UL} },
714 : { &fnv_test_str[200], {0xd6f70591UL, 0xc23e9fccUL} },
715 : { &fnv_test_str[201], {0xfe16b5b5UL, 0xc1af12bdUL} },
716 : { &fnv_test_str[202], {0x2f85e221UL, 0x39e9f18fUL} },
717 : { NULL, {0,0} }
718 : };
719 :
720 1 : static int hash_test_fnv1a_official(void)
721 : {
722 1 : struct fnv1a_32_test_vector *v = fnv1a_32_vector;
723 204 : while (v->test)
724 : {
725 203 : unsigned int h = hash(v->test->buf, v->test->len);
726 203 : TEST_EQU(h, v->fnv1a_32);
727 :
728 203 : ++v;
729 : }
730 1 : return 0;
731 : }
732 :
733 1 : static int hash_test_fnv1a64_official(void)
734 : {
735 1 : struct fnv1a_64_test_vector *v = fnv1a_64_vector;
736 204 : while (v->test)
737 : {
738 203 : u32 h[2];
739 203 : hash64(h, v->test->buf, v->test->len);
740 203 : TEST_EQU(h[0], v->fnv1a_64[0]);
741 203 : TEST_EQU(h[1], v->fnv1a_64[1]);
742 :
743 203 : ++v;
744 : }
745 1 : return 0;
746 : }
747 :
748 : const test_fn tests[] =
749 : {
750 : hash_test_deadbeef,
751 : hash_test_chongo,
752 : hash_test_fnv1a_official,
753 : hash_test_fnv1a64_official,
754 : 0
755 : };
|