3 * $Id: tiger-base.h,v 1.2 2004/04/08 01:36:15 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 #ifndef CATACOMB_TIGER_BASE_H
31 #define CATACOMB_TIGER_BASE_H
37 /*----- Header files ------------------------------------------------------*/
39 #include <mLib/bits.h>
41 /*----- Macros provided ---------------------------------------------------*/
43 /* --- The guts of a single round --- */
45 #define TIGER_ROUND(a, b, c, x, n, op) do { \
48 _t = s[0][U8(LO64(c) >> 0)]; \
49 XOR64(_t, _t, s[1][U8(LO64(c) >> 16)]); \
50 XOR64(_t, _t, s[2][U8(HI64(c) >> 0)]); \
51 XOR64(_t, _t, s[3][U8(HI64(c) >> 16)]); \
53 _t = s[3][U8(LO64(c) >> 8)]; \
54 XOR64(_t, _t, s[2][U8(LO64(c) >> 24)]); \
55 XOR64(_t, _t, s[1][U8(HI64(c) >> 8)]); \
56 XOR64(_t, _t, s[0][U8(HI64(c) >> 24)]); \
62 /* --- One pass over the buffer --- */
64 #define TIGER_PASS(a, b, c, x, n, op) do { \
65 TIGER_ROUND(a, b, c, x[0], n, op); \
66 TIGER_ROUND(b, c, a, x[1], n, op); \
67 TIGER_ROUND(c, a, b, x[2], n, op); \
68 TIGER_ROUND(a, b, c, x[3], n, op); \
69 TIGER_ROUND(b, c, a, x[4], n, op); \
70 TIGER_ROUND(c, a, b, x[5], n, op); \
71 TIGER_ROUND(a, b, c, x[6], n, op); \
72 TIGER_ROUND(b, c, a, x[7], n, op); \
75 /* --- A step in the `key schedule' --- */
77 #define TIGER_KSTEP(a, b, c, d, op, n) do { \
81 CPL64(_u, b); op##64_(_u, _u, n); XOR64(_u, _u, c); SUB64(d, d, _u); \
84 /* --- The `key schedule' -- mangle the buffer --- */
86 #define TIGER_KSCHED(x) do { \
89 SET64(_t, 0xa5a5a5a5, 0xa5a5a5a5); \
90 XOR64(_t, _t, x[7]); SUB64(x[0], x[0], _t); \
91 TIGER_KSTEP(x[0], x[1], x[2], x[3], LSL, 19); \
92 TIGER_KSTEP(x[3], x[4], x[5], x[6], LSR, 23); \
93 TIGER_KSTEP(x[6], x[7], x[0], x[1], LSL, 19); \
94 TIGER_KSTEP(x[1], x[2], x[3], x[4], LSR, 23); \
95 XOR64(x[5], x[5], x[4]); \
96 ADD64(x[6], x[6], x[5]); \
97 SET64(_t, 0x01234567, 0x89abcdef); \
98 XOR64(_t, _t, x[6]); SUB64(x[7], x[7], _t); \
101 /* --- The Tiger compression function --- */
103 #define TIGER_CORE(a, b, c, x) do { \
104 kludge64 _a, _b, _c; \
105 _a = a, _b = b, _c = c; \
106 TIGER_PASS(_a, _b, _c, x, 2, ADD); \
108 TIGER_PASS(_c, _a, _b, x, 3, SUB); \
110 TIGER_PASS(_b, _c, _a, x, 3, ADD); \
111 XOR64(a, _a, a); SUB64(b, _b, b); ADD64(c, _c, c); \
114 /*----- That's all, folks -------------------------------------------------*/