1 /* $Id: sph_simd.h 154 2010-04-26 17:00:24Z tp $ */
3 * SIMD interface. SIMD is a family of functions which differ by
4 * their output size; this implementation defines SIMD for output
5 * sizes 224, 256, 384 and 512 bits.
7 * ==========================(LICENSE BEGIN)============================
9 * Copyright (c) 2007-2010 Projet RNRT SAPHIR
11 * Permission is hereby granted, free of charge, to any person obtaining
12 * a copy of this software and associated documentation files (the
13 * "Software"), to deal in the Software without restriction, including
14 * without limitation the rights to use, copy, modify, merge, publish,
15 * distribute, sublicense, and/or sell copies of the Software, and to
16 * permit persons to whom the Software is furnished to do so, subject to
17 * the following conditions:
19 * The above copyright notice and this permission notice shall be
20 * included in all copies or substantial portions of the Software.
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
26 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 * ===========================(LICENSE END)=============================
44 #include "sph_types.h"
47 * Output size (in bits) for SIMD-224.
49 #define SPH_SIZE_simd224 224
52 * Output size (in bits) for SIMD-256.
54 #define SPH_SIZE_simd256 256
57 * Output size (in bits) for SIMD-384.
59 #define SPH_SIZE_simd384 384
62 * Output size (in bits) for SIMD-512.
64 #define SPH_SIZE_simd512 512
67 * This structure is a context for SIMD computations: it contains the
68 * intermediate values and some data from the last entered block. Once
69 * an SIMD computation has been performed, the context can be reused for
70 * another computation. This specific structure is used for SIMD-224
73 * The contents of this structure are private. A running SIMD computation
74 * can be cloned by copying the context (e.g. with a simple
75 * <code>memcpy()</code>).
78 #ifndef DOXYGEN_IGNORE
79 unsigned char buf[64]; /* first field, for alignment */
82 sph_u32 count_low, count_high;
84 } sph_simd_small_context;
87 * This structure is a context for SIMD computations: it contains the
88 * intermediate values and some data from the last entered block. Once
89 * an SIMD computation has been performed, the context can be reused for
90 * another computation. This specific structure is used for SIMD-384
93 * The contents of this structure are private. A running SIMD computation
94 * can be cloned by copying the context (e.g. with a simple
95 * <code>memcpy()</code>).
98 #ifndef DOXYGEN_IGNORE
99 unsigned char buf[128]; /* first field, for alignment */
102 sph_u32 count_low, count_high;
104 } sph_simd_big_context;
107 * Type for a SIMD-224 context (identical to the common "small" context).
109 typedef sph_simd_small_context sph_simd224_context;
112 * Type for a SIMD-256 context (identical to the common "small" context).
114 typedef sph_simd_small_context sph_simd256_context;
117 * Type for a SIMD-384 context (identical to the common "big" context).
119 typedef sph_simd_big_context sph_simd384_context;
122 * Type for a SIMD-512 context (identical to the common "big" context).
124 typedef sph_simd_big_context sph_simd512_context;
127 * Initialize an SIMD-224 context. This process performs no memory allocation.
129 * @param cc the SIMD-224 context (pointer to a
130 * <code>sph_simd224_context</code>)
132 void sph_simd224_init(void *cc);
135 * Process some data bytes. It is acceptable that <code>len</code> is zero
136 * (in which case this function does nothing).
138 * @param cc the SIMD-224 context
139 * @param data the input data
140 * @param len the input data length (in bytes)
142 void sph_simd224(void *cc, const void *data, size_t len);
145 * Terminate the current SIMD-224 computation and output the result into
146 * the provided buffer. The destination buffer must be wide enough to
147 * accomodate the result (28 bytes). The context is automatically
150 * @param cc the SIMD-224 context
151 * @param dst the destination buffer
153 void sph_simd224_close(void *cc, void *dst);
156 * Add a few additional bits (0 to 7) to the current computation, then
157 * terminate it and output the result in the provided buffer, which must
158 * be wide enough to accomodate the result (28 bytes). If bit number i
159 * in <code>ub</code> has value 2^i, then the extra bits are those
160 * numbered 7 downto 8-n (this is the big-endian convention at the byte
161 * level). The context is automatically reinitialized.
163 * @param cc the SIMD-224 context
164 * @param ub the extra bits
165 * @param n the number of extra bits (0 to 7)
166 * @param dst the destination buffer
168 void sph_simd224_addbits_and_close(
169 void *cc, unsigned ub, unsigned n, void *dst);
172 * Initialize an SIMD-256 context. This process performs no memory allocation.
174 * @param cc the SIMD-256 context (pointer to a
175 * <code>sph_simd256_context</code>)
177 void sph_simd256_init(void *cc);
180 * Process some data bytes. It is acceptable that <code>len</code> is zero
181 * (in which case this function does nothing).
183 * @param cc the SIMD-256 context
184 * @param data the input data
185 * @param len the input data length (in bytes)
187 void sph_simd256(void *cc, const void *data, size_t len);
190 * Terminate the current SIMD-256 computation and output the result into
191 * the provided buffer. The destination buffer must be wide enough to
192 * accomodate the result (32 bytes). The context is automatically
195 * @param cc the SIMD-256 context
196 * @param dst the destination buffer
198 void sph_simd256_close(void *cc, void *dst);
201 * Add a few additional bits (0 to 7) to the current computation, then
202 * terminate it and output the result in the provided buffer, which must
203 * be wide enough to accomodate the result (32 bytes). If bit number i
204 * in <code>ub</code> has value 2^i, then the extra bits are those
205 * numbered 7 downto 8-n (this is the big-endian convention at the byte
206 * level). The context is automatically reinitialized.
208 * @param cc the SIMD-256 context
209 * @param ub the extra bits
210 * @param n the number of extra bits (0 to 7)
211 * @param dst the destination buffer
213 void sph_simd256_addbits_and_close(
214 void *cc, unsigned ub, unsigned n, void *dst);
217 * Initialize an SIMD-384 context. This process performs no memory allocation.
219 * @param cc the SIMD-384 context (pointer to a
220 * <code>sph_simd384_context</code>)
222 void sph_simd384_init(void *cc);
225 * Process some data bytes. It is acceptable that <code>len</code> is zero
226 * (in which case this function does nothing).
228 * @param cc the SIMD-384 context
229 * @param data the input data
230 * @param len the input data length (in bytes)
232 void sph_simd384(void *cc, const void *data, size_t len);
235 * Terminate the current SIMD-384 computation and output the result into
236 * the provided buffer. The destination buffer must be wide enough to
237 * accomodate the result (48 bytes). The context is automatically
240 * @param cc the SIMD-384 context
241 * @param dst the destination buffer
243 void sph_simd384_close(void *cc, void *dst);
246 * Add a few additional bits (0 to 7) to the current computation, then
247 * terminate it and output the result in the provided buffer, which must
248 * be wide enough to accomodate the result (48 bytes). If bit number i
249 * in <code>ub</code> has value 2^i, then the extra bits are those
250 * numbered 7 downto 8-n (this is the big-endian convention at the byte
251 * level). The context is automatically reinitialized.
253 * @param cc the SIMD-384 context
254 * @param ub the extra bits
255 * @param n the number of extra bits (0 to 7)
256 * @param dst the destination buffer
258 void sph_simd384_addbits_and_close(
259 void *cc, unsigned ub, unsigned n, void *dst);
262 * Initialize an SIMD-512 context. This process performs no memory allocation.
264 * @param cc the SIMD-512 context (pointer to a
265 * <code>sph_simd512_context</code>)
267 void sph_simd512_init(void *cc);
270 * Process some data bytes. It is acceptable that <code>len</code> is zero
271 * (in which case this function does nothing).
273 * @param cc the SIMD-512 context
274 * @param data the input data
275 * @param len the input data length (in bytes)
277 void sph_simd512(void *cc, const void *data, size_t len);
280 * Terminate the current SIMD-512 computation and output the result into
281 * the provided buffer. The destination buffer must be wide enough to
282 * accomodate the result (64 bytes). The context is automatically
285 * @param cc the SIMD-512 context
286 * @param dst the destination buffer
288 void sph_simd512_close(void *cc, void *dst);
291 * Add a few additional bits (0 to 7) to the current computation, then
292 * terminate it and output the result in the provided buffer, which must
293 * be wide enough to accomodate the result (64 bytes). If bit number i
294 * in <code>ub</code> has value 2^i, then the extra bits are those
295 * numbered 7 downto 8-n (this is the big-endian convention at the byte
296 * level). The context is automatically reinitialized.
298 * @param cc the SIMD-512 context
299 * @param ub the extra bits
300 * @param n the number of extra bits (0 to 7)
301 * @param dst the destination buffer
303 void sph_simd512_addbits_and_close(
304 void *cc, unsigned ub, unsigned n, void *dst);