3 * Test driver for universal hashing
5 * (c) 2009 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of the mLib utilities library.
12 * mLib is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Library General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
17 * mLib is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with mLib; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
28 /*----- Header files ------------------------------------------------------*/
35 /*----- Main code ---------------------------------------------------------*/
37 static int verify(dstr *v)
47 static const int step[] = { 0, 1, 5, 6, 7, 8, 23, -1 };
49 /* --- Set up for using this key --- */
51 k = *(uint32 *)v[0].buf;
52 h = *(uint32 *)v[2].buf;
53 unihash_setkey(&ui, k);
55 /* --- Hash the data a lot --- */
57 for (i = 0; step[i] >= 0; i++) {
60 hh = unihash(&ui, v[1].buf, v[1].len);
62 hh = UNIHASH_INIT(&ui);
67 hh = unihash_hash(&ui, hh, p, c);
74 fprintf(stderr, "\nunihash failed\n");
75 fprintf(stderr, " key = %08lx\n", (unsigned long)k);
76 fprintf(stderr, " data = %s\n", v[1].buf);
77 fprintf(stderr, " step = %d\n", step[i]);
78 fprintf(stderr, " expected = %08lx\n", (unsigned long)h);
79 fprintf(stderr, " computed = %08lx\n", (unsigned long)hh);
85 static const test_chunk tests[] = {
86 { "hash", verify, { &type_uint32, &type_string, &type_uint32 } },
90 int main(int argc, char *argv[])
92 test_run(argc, argv, tests, "unihash.in");
96 /*----- That's all, folks -------------------------------------------------*/