3 * $Id: tiger-mktab.c,v 1.1 2000/07/15 10:02:43 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 /*----- Revision history --------------------------------------------------*
32 * $Log: tiger-mktab.c,v $
33 * Revision 1.1 2000/07/15 10:02:43 mdw
34 * Anderson and Biham's Tiger hash function added.
38 /*----- Header files ------------------------------------------------------*/
40 #include <mLib/bits.h>
45 #include "tiger-base.h"
47 /*----- Data structures ---------------------------------------------------*/
49 /*----- Static variables --------------------------------------------------*/
51 static kludge64 s
[4][256];
53 /*----- Main code ---------------------------------------------------------*/
55 /* --- The basic Tiger compression function --- */
57 static void tiger(kludge64
*x
, kludge64
*ss
)
59 TIGER_CORE(ss
[0], ss
[1], ss
[2], x
);
62 /* --- The S-box generator --- */
64 void gen(const char *buf
, unsigned passes
)
72 for (i
= 0; i
< 256; i
++) {
73 for (j
= 0; j
< 4; j
++) {
74 uint32 z
= 0x01010101 * i
;
79 SET64(ss
[0], 0x01234567, 0x89abcdef);
80 SET64(ss
[1], 0xfedcba98, 0x76543210);
81 SET64(ss
[2], 0xf096a5b4, 0xc3b2e187);
84 for (i
= 0; i
< passes
; i
++) {
85 for (j
= 0; j
< 256; j
++) {
86 for (k
= 0; k
< 4; k
++) {
90 for (p
= buf
, n
= 0; n
< 8; n
++, p
+= 8)
94 for (b
= 0; b
< 32; b
+= 8) {
95 n
= U8(LO64(ss
[q
]) >> b
);
96 t
= (LO64(s
[k
][j
]) ^ LO64(s
[k
][n
])) & (0xff << b
);
97 SET64(s
[k
][j
], HI64(s
[k
][j
]), LO64(s
[k
][j
]) ^ t
);
98 SET64(s
[k
][n
], HI64(s
[k
][n
]), LO64(s
[k
][n
]) ^ t
);
100 for (b
= 0; b
< 32; b
+= 8) {
101 n
= U8(HI64(ss
[q
]) >> b
);
102 t
= (HI64(s
[k
][j
]) ^ HI64(s
[k
][n
])) & (0xff << b
);
103 SET64(s
[k
][j
], HI64(s
[k
][j
]) ^ t
, LO64(s
[k
][j
]));
104 SET64(s
[k
][n
], HI64(s
[k
][n
]) ^ t
, LO64(s
[k
][n
]));
115 gen("Tiger - A Fast New Hash Function, by Ross Anderson and Eli Biham", 5);
120 * S-boxes for Tiger [generated]\n\
123 #ifndef CATACOMB_TIGER_TAB_H\n\
124 #define CATACOMB_TIGER_TAB_H\n\
126 #define TIGER_S { \\\n\
129 for (i
= 0; i
< 4; i
++) {
130 for (j
= 0; j
< 256; j
++) {
132 printf("{ 0x%016llxull }", s
[i
][j
]);
134 printf("{ 0x%08lx, 0x%08lx }",
135 (unsigned long)s
[i
][j
].hi
, (unsigned long)s
[i
][j
].lo
);
139 fputs(" } \\\n}\n", stdout
);
144 } else if (j
% 2 == 1)
145 fputs(", \\\n ", stdout
);
151 fputs("\n#endif\n", stdout
);
153 if (fclose(stdout
)) {
154 fprintf(stderr
, "error writing data\n");
161 /*----- That's all, folks -------------------------------------------------*/