3 * $Id: tiger-mktab.c,v 1.2 2004/04/08 01:36:15 mdw Exp $
5 * Generate S-boxes 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 /*----- Header files ------------------------------------------------------*/
32 #include <mLib/bits.h>
37 #include "tiger-base.h"
39 /*----- Data structures ---------------------------------------------------*/
41 /*----- Static variables --------------------------------------------------*/
43 static kludge64 s
[4][256];
45 /*----- Main code ---------------------------------------------------------*/
47 /* --- The basic Tiger compression function --- */
49 static void tiger(kludge64
*x
, kludge64
*ss
)
51 TIGER_CORE(ss
[0], ss
[1], ss
[2], x
);
54 /* --- The S-box generator --- */
56 void gen(const char *buf
, unsigned passes
)
64 for (i
= 0; i
< 256; i
++) {
65 for (j
= 0; j
< 4; j
++) {
66 uint32 z
= 0x01010101 * i
;
71 SET64(ss
[0], 0x01234567, 0x89abcdef);
72 SET64(ss
[1], 0xfedcba98, 0x76543210);
73 SET64(ss
[2], 0xf096a5b4, 0xc3b2e187);
76 for (i
= 0; i
< passes
; i
++) {
77 for (j
= 0; j
< 256; j
++) {
78 for (k
= 0; k
< 4; k
++) {
82 for (p
= buf
, n
= 0; n
< 8; n
++, p
+= 8)
86 for (b
= 0; b
< 32; b
+= 8) {
87 n
= U8(LO64(ss
[q
]) >> b
);
88 t
= (LO64(s
[k
][j
]) ^ LO64(s
[k
][n
])) & (0xff << b
);
89 SET64(s
[k
][j
], HI64(s
[k
][j
]), LO64(s
[k
][j
]) ^ t
);
90 SET64(s
[k
][n
], HI64(s
[k
][n
]), LO64(s
[k
][n
]) ^ t
);
92 for (b
= 0; b
< 32; b
+= 8) {
93 n
= U8(HI64(ss
[q
]) >> b
);
94 t
= (HI64(s
[k
][j
]) ^ HI64(s
[k
][n
])) & (0xff << b
);
95 SET64(s
[k
][j
], HI64(s
[k
][j
]) ^ t
, LO64(s
[k
][j
]));
96 SET64(s
[k
][n
], HI64(s
[k
][n
]) ^ t
, LO64(s
[k
][n
]));
107 gen("Tiger - A Fast New Hash Function, by Ross Anderson and Eli Biham", 5);
112 * S-boxes for Tiger [generated]\n\
115 #ifndef CATACOMB_TIGER_TAB_H\n\
116 #define CATACOMB_TIGER_TAB_H\n\
118 #define TIGER_S { \\\n\
121 for (i
= 0; i
< 4; i
++) {
122 for (j
= 0; j
< 256; j
++) {
124 printf("{ 0x%016llxull }", s
[i
][j
].i
);
126 printf("{ 0x%08lx, 0x%08lx }",
127 (unsigned long)s
[i
][j
].hi
, (unsigned long)s
[i
][j
].lo
);
131 fputs(" } \\\n}\n", stdout
);
136 } else if (j
% 2 == 1)
137 fputs(", \\\n ", stdout
);
143 fputs("\n#endif\n", stdout
);
145 if (fclose(stdout
)) {
146 fprintf(stderr
, "error writing data\n");
153 /*----- That's all, folks -------------------------------------------------*/