3 * $Id: tiger-base.h,v 1.1 2000/07/15 10:02:43 mdw Exp $
5 * Common definitions for the Tiger hash function
7 * (c) 2000 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Catacomb.
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.
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.
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,
30 /*----- Revision history --------------------------------------------------*
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.
38 #ifndef CATACOMB_TIGER_BASE_H
39 #define CATACOMB_TIGER_BASE_H
45 /*----- Header files ------------------------------------------------------*/
47 #include <mLib/bits.h>
49 /*----- Macros provided ---------------------------------------------------*/
51 /* --- The guts of a single round --- */
53 #define TIGER_ROUND(a, b, c, x, n, op) do { \
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)]); \
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)]); \
70 /* --- One pass over the buffer --- */
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); \
83 /* --- A step in the `key schedule' --- */
85 #define TIGER_KSTEP(a, b, c, d, op, n) do { \
89 CPL64(_u, b); op##64_(_u, _u, n); XOR64(_u, _u, c); SUB64(d, d, _u); \
92 /* --- The `key schedule' -- mangle the buffer --- */
94 #define TIGER_KSCHED(x) do { \
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); \
109 /* --- The Tiger compression function --- */
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); \
116 TIGER_PASS(_c, _a, _b, x, 3, SUB); \
118 TIGER_PASS(_b, _c, _a, x, 3, ADD); \
119 XOR64(a, _a, a); SUB64(b, _b, b); ADD64(c, _c, c); \
122 /*----- That's all, folks -------------------------------------------------*/