3 * Generate S-boxes for the Tiger hash function
5 * (c) 2000 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of Catacomb.
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.
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.
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,
28 /*----- Header files ------------------------------------------------------*/
30 #include <mLib/bits.h>
35 #include "tiger-base.h"
37 /*----- Data structures ---------------------------------------------------*/
39 /*----- Static variables --------------------------------------------------*/
41 static kludge64 s[4][256];
43 /*----- Main code ---------------------------------------------------------*/
45 /* --- The basic Tiger compression function --- */
47 static void tiger(kludge64 *x, kludge64 *ss)
49 TIGER_CORE(ss[0], ss[1], ss[2], x);
52 /* --- The S-box generator --- */
54 void gen(const char *buf, unsigned passes)
62 for (i = 0; i < 256; i++) {
63 for (j = 0; j < 4; j++) {
64 uint32 z = 0x01010101 * i;
69 SET64(ss[0], 0x01234567, 0x89abcdef);
70 SET64(ss[1], 0xfedcba98, 0x76543210);
71 SET64(ss[2], 0xf096a5b4, 0xc3b2e187);
74 for (i = 0; i < passes; i++) {
75 for (j = 0; j < 256; j++) {
76 for (k = 0; k < 4; k++) {
80 for (p = buf, n = 0; n < 8; n++, p += 8)
84 for (b = 0; b < 32; b += 8) {
85 n = U8(LO64(ss[q]) >> b);
86 t = (LO64(s[k][j]) ^ LO64(s[k][n])) & (0xff << b);
87 SET64(s[k][j], HI64(s[k][j]), LO64(s[k][j]) ^ t);
88 SET64(s[k][n], HI64(s[k][n]), LO64(s[k][n]) ^ t);
90 for (b = 0; b < 32; b += 8) {
91 n = U8(HI64(ss[q]) >> b);
92 t = (HI64(s[k][j]) ^ HI64(s[k][n])) & (0xff << b);
93 SET64(s[k][j], HI64(s[k][j]) ^ t, LO64(s[k][j]));
94 SET64(s[k][n], HI64(s[k][n]) ^ t, LO64(s[k][n]));
105 gen("Tiger - A Fast New Hash Function, by Ross Anderson and Eli Biham", 5);
110 * S-boxes for Tiger [generated]\n\
113 #ifndef CATACOMB_TIGER_TAB_H\n\
114 #define CATACOMB_TIGER_TAB_H\n\
116 #define TIGER_S { \\\n\
119 for (i = 0; i < 4; i++) {
120 for (j = 0; j < 256; j++) {
122 printf("{ 0x%016llxull }", s[i][j].i);
124 printf("{ 0x%08lx, 0x%08lx }",
125 (unsigned long)s[i][j].hi, (unsigned long)s[i][j].lo);
129 fputs(" } \\\n}\n", stdout);
134 } else if (j % 2 == 1)
135 fputs(", \\\n ", stdout);
141 fputs("\n#endif\n", stdout);
143 if (fclose(stdout)) {
144 fprintf(stderr, "error writing data\n");
151 /*----- That's all, folks -------------------------------------------------*/