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 /*----- Static variables --------------------------------------------------*/
39 static kludge64 tiger_s
[4][256];
41 /*----- Main code ---------------------------------------------------------*/
43 /* --- The basic Tiger compression function --- */
45 static void tiger(kludge64
*x
, kludge64
*ss
)
47 TIGER_CORE(ss
[0], ss
[1], ss
[2], x
);
50 /* --- The S-box generator --- */
52 void gen(const char *buf
, unsigned passes
)
60 for (i
= 0; i
< 256; i
++) {
61 for (j
= 0; j
< 4; j
++) {
62 uint32 z
= 0x01010101 * i
;
63 SET64(tiger_s
[j
][i
], z
, z
);
67 SET64(ss
[0], 0x01234567, 0x89abcdef);
68 SET64(ss
[1], 0xfedcba98, 0x76543210);
69 SET64(ss
[2], 0xf096a5b4, 0xc3b2e187);
72 for (i
= 0; i
< passes
; i
++) {
73 for (j
= 0; j
< 256; j
++) {
74 for (k
= 0; k
< 4; k
++) {
78 for (p
= buf
, n
= 0; n
< 8; n
++, p
+= 8)
82 for (b
= 0; b
< 32; b
+= 8) {
83 n
= U8(LO64(ss
[q
]) >> b
);
84 t
= (LO64(tiger_s
[k
][j
]) ^ LO64(tiger_s
[k
][n
])) & (0xff << b
);
85 SET64(tiger_s
[k
][j
], HI64(tiger_s
[k
][j
]), LO64(tiger_s
[k
][j
]) ^ t
);
86 SET64(tiger_s
[k
][n
], HI64(tiger_s
[k
][n
]), LO64(tiger_s
[k
][n
]) ^ t
);
88 for (b
= 0; b
< 32; b
+= 8) {
89 n
= U8(HI64(ss
[q
]) >> b
);
90 t
= (HI64(tiger_s
[k
][j
]) ^ HI64(tiger_s
[k
][n
])) & (0xff << b
);
91 SET64(tiger_s
[k
][j
], HI64(tiger_s
[k
][j
]) ^ t
, LO64(tiger_s
[k
][j
]));
92 SET64(tiger_s
[k
][n
], HI64(tiger_s
[k
][n
]) ^ t
, LO64(tiger_s
[k
][n
]));
103 gen("Tiger - A Fast New Hash Function, by Ross Anderson and Eli Biham", 5);
108 * S-boxes for Tiger [generated]\n\
111 #include <mLib/bits.h>\n\
113 const kludge64 tiger_s[4][256] = {\n\
116 for (i
= 0; i
< 4; i
++) {
117 for (j
= 0; j
< 256; j
++) {
118 printf("X64(%08lx, %08lx)",
119 (unsigned long)HI64(tiger_s
[i
][j
]),
120 (unsigned long)LO64(tiger_s
[i
][j
]));
123 fputs(" }\n};\n", stdout
);
125 fputs(" },\n\n { ", stdout
);
126 } else if (j
% 2 == 1)
127 fputs(",\n ", stdout
);
133 if (fclose(stdout
)) {
134 fprintf(stderr
, "error writing data\n");
141 /*----- That's all, folks -------------------------------------------------*/