Commit | Line | Data |
---|---|---|
eeccf7a8 | 1 | /* -*-c-*- |
eeccf7a8 | 2 | * |
3 | * Common definitions for the Tiger hash function | |
4 | * | |
5 | * (c) 2000 Straylight/Edgeware | |
6 | */ | |
7 | ||
45c0fd36 | 8 | /*----- Licensing notice --------------------------------------------------* |
eeccf7a8 | 9 | * |
10 | * This file is part of Catacomb. | |
11 | * | |
12 | * Catacomb 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. | |
45c0fd36 | 16 | * |
eeccf7a8 | 17 | * Catacomb 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. | |
45c0fd36 | 21 | * |
eeccf7a8 | 22 | * You should have received a copy of the GNU Library General Public |
23 | * License along with Catacomb; if not, write to the Free | |
24 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, | |
25 | * MA 02111-1307, USA. | |
26 | */ | |
27 | ||
eeccf7a8 | 28 | #ifndef CATACOMB_TIGER_BASE_H |
29 | #define CATACOMB_TIGER_BASE_H | |
30 | ||
31 | #ifdef __cplusplus | |
32 | extern "C" { | |
33 | #endif | |
34 | ||
35 | /*----- Header files ------------------------------------------------------*/ | |
36 | ||
37 | #include <mLib/bits.h> | |
38 | ||
39 | /*----- Macros provided ---------------------------------------------------*/ | |
40 | ||
41 | /* --- The guts of a single round --- */ | |
42 | ||
43 | #define TIGER_ROUND(a, b, c, x, n, op) do { \ | |
44 | kludge64 _t; \ | |
45 | XOR64(c, c, x); \ | |
e5b61a8d MW |
46 | _t = tiger_s[0][U8(LO64(c) >> 0)]; \ |
47 | XOR64(_t, _t, tiger_s[1][U8(LO64(c) >> 16)]); \ | |
48 | XOR64(_t, _t, tiger_s[2][U8(HI64(c) >> 0)]); \ | |
49 | XOR64(_t, _t, tiger_s[3][U8(HI64(c) >> 16)]); \ | |
eeccf7a8 | 50 | SUB64(a, a, _t); \ |
e5b61a8d MW |
51 | _t = tiger_s[3][U8(LO64(c) >> 8)]; \ |
52 | XOR64(_t, _t, tiger_s[2][U8(LO64(c) >> 24)]); \ | |
53 | XOR64(_t, _t, tiger_s[1][U8(HI64(c) >> 8)]); \ | |
54 | XOR64(_t, _t, tiger_s[0][U8(HI64(c) >> 24)]); \ | |
eeccf7a8 | 55 | ADD64(b, b, _t); \ |
56 | LSL64_(_t, b, n); \ | |
57 | op##64(b, _t, b); \ | |
58 | } while (0) | |
59 | ||
60 | /* --- One pass over the buffer --- */ | |
61 | ||
62 | #define TIGER_PASS(a, b, c, x, n, op) do { \ | |
63 | TIGER_ROUND(a, b, c, x[0], n, op); \ | |
64 | TIGER_ROUND(b, c, a, x[1], n, op); \ | |
65 | TIGER_ROUND(c, a, b, x[2], n, op); \ | |
66 | TIGER_ROUND(a, b, c, x[3], n, op); \ | |
67 | TIGER_ROUND(b, c, a, x[4], n, op); \ | |
68 | TIGER_ROUND(c, a, b, x[5], n, op); \ | |
69 | TIGER_ROUND(a, b, c, x[6], n, op); \ | |
70 | TIGER_ROUND(b, c, a, x[7], n, op); \ | |
71 | } while (0) | |
72 | ||
73 | /* --- A step in the `key schedule' --- */ | |
74 | ||
75 | #define TIGER_KSTEP(a, b, c, d, op, n) do { \ | |
76 | kludge64 _u; \ | |
77 | XOR64(b, b, a); \ | |
78 | ADD64(c, c, b); \ | |
79 | CPL64(_u, b); op##64_(_u, _u, n); XOR64(_u, _u, c); SUB64(d, d, _u); \ | |
80 | } while (0) | |
81 | ||
82 | /* --- The `key schedule' -- mangle the buffer --- */ | |
83 | ||
84 | #define TIGER_KSCHED(x) do { \ | |
85 | kludge64 _t; \ | |
86 | \ | |
87 | SET64(_t, 0xa5a5a5a5, 0xa5a5a5a5); \ | |
88 | XOR64(_t, _t, x[7]); SUB64(x[0], x[0], _t); \ | |
89 | TIGER_KSTEP(x[0], x[1], x[2], x[3], LSL, 19); \ | |
90 | TIGER_KSTEP(x[3], x[4], x[5], x[6], LSR, 23); \ | |
91 | TIGER_KSTEP(x[6], x[7], x[0], x[1], LSL, 19); \ | |
92 | TIGER_KSTEP(x[1], x[2], x[3], x[4], LSR, 23); \ | |
93 | XOR64(x[5], x[5], x[4]); \ | |
94 | ADD64(x[6], x[6], x[5]); \ | |
95 | SET64(_t, 0x01234567, 0x89abcdef); \ | |
96 | XOR64(_t, _t, x[6]); SUB64(x[7], x[7], _t); \ | |
97 | } while (0) | |
98 | ||
99 | /* --- The Tiger compression function --- */ | |
100 | ||
101 | #define TIGER_CORE(a, b, c, x) do { \ | |
102 | kludge64 _a, _b, _c; \ | |
103 | _a = a, _b = b, _c = c; \ | |
104 | TIGER_PASS(_a, _b, _c, x, 2, ADD); \ | |
105 | TIGER_KSCHED(x); \ | |
106 | TIGER_PASS(_c, _a, _b, x, 3, SUB); \ | |
107 | TIGER_KSCHED(x); \ | |
108 | TIGER_PASS(_b, _c, _a, x, 3, ADD); \ | |
109 | XOR64(a, _a, a); SUB64(b, _b, b); ADD64(c, _c, c); \ | |
110 | } while (0) | |
111 | ||
112 | /*----- That's all, folks -------------------------------------------------*/ | |
113 | ||
114 | #ifdef __cplusplus | |
115 | } | |
116 | #endif | |
117 | ||
118 | #endif |