1 /* $Id: sph_tiger.h 216 2010-06-08 09:46:57Z tp $ */
2 /**
3  * Tiger / Tiger-2 interface.
4  *
5  * Tiger has been published in: R. Anderson, E. Biham, "Tiger: A Fast
6  * New Hash Function", Fast Software Encryption - FSE'96, LNCS 1039,
7  * Springer (1996), pp. 89--97.
8  *
9  * Tiger2 has never been formally published, but it was described as
10  * identical to Tiger, except for the padding which is the same in
11  * Tiger2 as it is in MD4. Fortunately, an implementation of Tiger2
12  * was submitted to NESSIE, which produced test vectors; the sphlib
13  * implementation of Tiger2 is compatible with the NESSIE test vectors.
14  *
15  * ==========================(LICENSE BEGIN)============================
16  *
17  * Copyright (c) 2007-2010  Projet RNRT SAPHIR
18  *
19  * Permission is hereby granted, free of charge, to any person obtaining
20  * a copy of this software and associated documentation files (the
21  * "Software"), to deal in the Software without restriction, including
22  * without limitation the rights to use, copy, modify, merge, publish,
23  * distribute, sublicense, and/or sell copies of the Software, and to
24  * permit persons to whom the Software is furnished to do so, subject to
25  * the following conditions:
26  *
27  * The above copyright notice and this permission notice shall be
28  * included in all copies or substantial portions of the Software.
29  *
30  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
31  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
33  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
34  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
35  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
36  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37  *
38  * ===========================(LICENSE END)=============================
39  *
40  * @file     sph_tiger.h
41  * @author   Thomas Pornin <thomas.pornin@cryptolog.com>
42  */
43 
44 #ifndef SPH_TIGER_H__
45 #define SPH_TIGER_H__
46 
47 #include <stddef.h>
48 #include "sph_types.h"
49 
50 #if SPH_64
51 
52 /**
53  * Output size (in bits) for Tiger.
54  */
55 #define SPH_SIZE_tiger   192
56 
57 /**
58  * Output size (in bits) for Tiger2.
59  */
60 #define SPH_SIZE_tiger2   192
61 
62 /**
63  * This structure is a context for Tiger computations: it contains the
64  * intermediate values and some data from the last entered block. Once
65  * a Tiger computation has been performed, the context can be reused for
66  * another computation.
67  *
68  * The contents of this structure are private. A running Tiger computation
69  * can be cloned by copying the context (e.g. with a simple
70  * <code>memcpy()</code>).
71  */
72 typedef struct {
73 #ifndef DOXYGEN_IGNORE
74 	unsigned char buf[64];    /* first field, for alignment */
75 	sph_u64 val[3];
76 	sph_u64 count;
77 #endif
78 } sph_tiger_context;
79 
80 /**
81  * Initialize a Tiger context. This process performs no memory allocation.
82  *
83  * @param cc   the Tiger context (pointer to
84  *             a <code>sph_tiger_context</code>)
85  */
86 void sph_tiger_init(void *cc);
87 
88 /**
89  * Process some data bytes. It is acceptable that <code>len</code> is zero
90  * (in which case this function does nothing).
91  *
92  * @param cc     the Tiger context
93  * @param data   the input data
94  * @param len    the input data length (in bytes)
95  */
96 void sph_tiger(void *cc, const void *data, size_t len);
97 
98 /**
99  * Terminate the current Tiger computation and output the result into the
100  * provided buffer. The destination buffer must be wide enough to
101  * accommodate the result (24 bytes). The context is automatically
102  * reinitialized.
103  *
104  * @param cc    the Tiger context
105  * @param dst   the destination buffer
106  */
107 void sph_tiger_close(void *cc, void *dst);
108 
109 /**
110  * Apply the Tiger compression function on the provided data. The
111  * <code>msg</code> parameter contains the 8 64-bit input blocks,
112  * as numerical values (hence after the little-endian decoding). The
113  * <code>val</code> parameter contains the 3 64-bit input blocks for
114  * the compression function; the output is written in place in this
115  * array.
116  *
117  * @param msg   the message block (8 values)
118  * @param val   the function 192-bit input and output
119  */
120 void sph_tiger_comp(const sph_u64 msg[8], sph_u64 val[3]);
121 
122 /**
123  * This structure is a context for Tiger2 computations. It is identical
124  * to the Tiger context, and they may be freely exchanged, since the
125  * difference between Tiger and Tiger2 resides solely in the padding, which
126  * is computed only in the last computation step.
127  */
128 typedef sph_tiger_context sph_tiger2_context;
129 
130 #ifdef DOXYGEN_IGNORE
131 /**
132  * Initialize a Tiger2 context. This function is identical to
133  * <code>sph_tiger_init()</code>.
134  *
135  * @param cc   the Tiger2 context (pointer to
136  *             a <code>sph_tiger2_context</code>)
137  */
138 void sph_tiger2_init(void *cc);
139 #endif
140 
141 #ifndef DOXYGEN_IGNORE
142 #define sph_tiger2_init   sph_tiger_init
143 #endif
144 
145 #ifdef DOXYGEN_IGNORE
146 /**
147  * Process some data bytes. This function is identical to
148  * <code>sph_tiger()</code>.
149  *
150  * @param cc     the Tiger2 context
151  * @param data   the input data
152  * @param len    the input data length (in bytes)
153  */
154 void sph_tiger2(void *cc, const void *data, size_t len);
155 #endif
156 
157 #ifndef DOXYGEN_IGNORE
158 #define sph_tiger2   sph_tiger
159 #endif
160 
161 /**
162  * Terminate the current Tiger2 computation and output the result into the
163  * provided buffer. The destination buffer must be wide enough to
164  * accommodate the result (24 bytes). The context is automatically
165  * reinitialized. Note that this function is NOT identical to
166  * <code>sph_tiger2_close()</code>: this is the exact and unique point
167  * where Tiger and Tiger2 differ.
168  *
169  * @param cc    the Tiger context
170  * @param dst   the destination buffer
171  */
172 void sph_tiger2_close(void *cc, void *dst);
173 
174 #ifdef DOXYGEN_IGNORE
175 /**
176  * Apply the Tiger2 compression function, which is identical to the Tiger
177  * compression function.
178  *
179  * @param msg   the message block (8 values)
180  * @param val   the function 192-bit input and output
181  */
182 void sph_tiger2_comp(const sph_u64 msg[8], sph_u64 val[3]);
183 #endif
184 
185 #ifndef DOXYGEN_IGNORE
186 #define sph_tiger2_comp   sph_tiger_comp
187 #endif
188 
189 #endif
190 
191 #endif
192