eeccf7a8 |
1 | /* -*-c-*- |
2 | * |
3 | * $Id: tiger-base.h,v 1.1 2000/07/15 10:02:43 mdw Exp $ |
4 | * |
5 | * Common definitions for the Tiger hash function |
6 | * |
7 | * (c) 2000 Straylight/Edgeware |
8 | */ |
9 | |
10 | /*----- Licensing notice --------------------------------------------------* |
11 | * |
12 | * This file is part of Catacomb. |
13 | * |
14 | * Catacomb is free software; you can redistribute it and/or modify |
15 | * it under the terms of the GNU Library General Public License as |
16 | * published by the Free Software Foundation; either version 2 of the |
17 | * License, or (at your option) any later version. |
18 | * |
19 | * Catacomb is distributed in the hope that it will be useful, |
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22 | * GNU Library General Public License for more details. |
23 | * |
24 | * You should have received a copy of the GNU Library General Public |
25 | * License along with Catacomb; if not, write to the Free |
26 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
27 | * MA 02111-1307, USA. |
28 | */ |
29 | |
30 | /*----- Revision history --------------------------------------------------* |
31 | * |
32 | * $Log: tiger-base.h,v $ |
33 | * Revision 1.1 2000/07/15 10:02:43 mdw |
34 | * Anderson and Biham's Tiger hash function added. |
35 | * |
36 | */ |
37 | |
38 | #ifndef CATACOMB_TIGER_BASE_H |
39 | #define CATACOMB_TIGER_BASE_H |
40 | |
41 | #ifdef __cplusplus |
42 | extern "C" { |
43 | #endif |
44 | |
45 | /*----- Header files ------------------------------------------------------*/ |
46 | |
47 | #include <mLib/bits.h> |
48 | |
49 | /*----- Macros provided ---------------------------------------------------*/ |
50 | |
51 | /* --- The guts of a single round --- */ |
52 | |
53 | #define TIGER_ROUND(a, b, c, x, n, op) do { \ |
54 | kludge64 _t; \ |
55 | XOR64(c, c, x); \ |
56 | _t = s[0][U8(LO64(c) >> 0)]; \ |
57 | XOR64(_t, _t, s[1][U8(LO64(c) >> 16)]); \ |
58 | XOR64(_t, _t, s[2][U8(HI64(c) >> 0)]); \ |
59 | XOR64(_t, _t, s[3][U8(HI64(c) >> 16)]); \ |
60 | SUB64(a, a, _t); \ |
61 | _t = s[3][U8(LO64(c) >> 8)]; \ |
62 | XOR64(_t, _t, s[2][U8(LO64(c) >> 24)]); \ |
63 | XOR64(_t, _t, s[1][U8(HI64(c) >> 8)]); \ |
64 | XOR64(_t, _t, s[0][U8(HI64(c) >> 24)]); \ |
65 | ADD64(b, b, _t); \ |
66 | LSL64_(_t, b, n); \ |
67 | op##64(b, _t, b); \ |
68 | } while (0) |
69 | |
70 | /* --- One pass over the buffer --- */ |
71 | |
72 | #define TIGER_PASS(a, b, c, x, n, op) do { \ |
73 | TIGER_ROUND(a, b, c, x[0], n, op); \ |
74 | TIGER_ROUND(b, c, a, x[1], n, op); \ |
75 | TIGER_ROUND(c, a, b, x[2], n, op); \ |
76 | TIGER_ROUND(a, b, c, x[3], n, op); \ |
77 | TIGER_ROUND(b, c, a, x[4], n, op); \ |
78 | TIGER_ROUND(c, a, b, x[5], n, op); \ |
79 | TIGER_ROUND(a, b, c, x[6], n, op); \ |
80 | TIGER_ROUND(b, c, a, x[7], n, op); \ |
81 | } while (0) |
82 | |
83 | /* --- A step in the `key schedule' --- */ |
84 | |
85 | #define TIGER_KSTEP(a, b, c, d, op, n) do { \ |
86 | kludge64 _u; \ |
87 | XOR64(b, b, a); \ |
88 | ADD64(c, c, b); \ |
89 | CPL64(_u, b); op##64_(_u, _u, n); XOR64(_u, _u, c); SUB64(d, d, _u); \ |
90 | } while (0) |
91 | |
92 | /* --- The `key schedule' -- mangle the buffer --- */ |
93 | |
94 | #define TIGER_KSCHED(x) do { \ |
95 | kludge64 _t; \ |
96 | \ |
97 | SET64(_t, 0xa5a5a5a5, 0xa5a5a5a5); \ |
98 | XOR64(_t, _t, x[7]); SUB64(x[0], x[0], _t); \ |
99 | TIGER_KSTEP(x[0], x[1], x[2], x[3], LSL, 19); \ |
100 | TIGER_KSTEP(x[3], x[4], x[5], x[6], LSR, 23); \ |
101 | TIGER_KSTEP(x[6], x[7], x[0], x[1], LSL, 19); \ |
102 | TIGER_KSTEP(x[1], x[2], x[3], x[4], LSR, 23); \ |
103 | XOR64(x[5], x[5], x[4]); \ |
104 | ADD64(x[6], x[6], x[5]); \ |
105 | SET64(_t, 0x01234567, 0x89abcdef); \ |
106 | XOR64(_t, _t, x[6]); SUB64(x[7], x[7], _t); \ |
107 | } while (0) |
108 | |
109 | /* --- The Tiger compression function --- */ |
110 | |
111 | #define TIGER_CORE(a, b, c, x) do { \ |
112 | kludge64 _a, _b, _c; \ |
113 | _a = a, _b = b, _c = c; \ |
114 | TIGER_PASS(_a, _b, _c, x, 2, ADD); \ |
115 | TIGER_KSCHED(x); \ |
116 | TIGER_PASS(_c, _a, _b, x, 3, SUB); \ |
117 | TIGER_KSCHED(x); \ |
118 | TIGER_PASS(_b, _c, _a, x, 3, ADD); \ |
119 | XOR64(a, _a, a); SUB64(b, _b, b); ADD64(c, _c, c); \ |
120 | } while (0) |
121 | |
122 | /*----- That's all, folks -------------------------------------------------*/ |
123 | |
124 | #ifdef __cplusplus |
125 | } |
126 | #endif |
127 | |
128 | #endif |