/* $Id: sph_simd.h 154 2010-04-26 17:00:24Z tp $ */1/**2* SIMD interface. SIMD is a family of functions which differ by3* their output size; this implementation defines SIMD for output4* sizes 224, 256, 384 and 512 bits.5*6* ==========================(LICENSE BEGIN)============================7*8* Copyright (c) 2007-2010 Projet RNRT SAPHIR9*10* Permission is hereby granted, free of charge, to any person obtaining11* a copy of this software and associated documentation files (the12* "Software"), to deal in the Software without restriction, including13* without limitation the rights to use, copy, modify, merge, publish,14* distribute, sublicense, and/or sell copies of the Software, and to15* permit persons to whom the Software is furnished to do so, subject to16* the following conditions:17*18* The above copyright notice and this permission notice shall be19* included in all copies or substantial portions of the Software.20*21* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,22* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF23* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.24* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY25* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,26* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE27* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.28*29* ===========================(LICENSE END)=============================30*31* @file sph_simd.h32* @author Thomas Pornin <[email protected]>33*/3435#ifndef SPH_SIMD_H__36#define SPH_SIMD_H__3738#ifdef __cplusplus39extern "C"{40#endif4142#include <stddef.h>43#include "sph_types.h"4445/**46* Output size (in bits) for SIMD-224.47*/48#define SPH_SIZE_simd224 2244950/**51* Output size (in bits) for SIMD-256.52*/53#define SPH_SIZE_simd256 2565455/**56* Output size (in bits) for SIMD-384.57*/58#define SPH_SIZE_simd384 3845960/**61* Output size (in bits) for SIMD-512.62*/63#define SPH_SIZE_simd512 5126465/**66* This structure is a context for SIMD computations: it contains the67* intermediate values and some data from the last entered block. Once68* an SIMD computation has been performed, the context can be reused for69* another computation. This specific structure is used for SIMD-22470* and SIMD-256.71*72* The contents of this structure are private. A running SIMD computation73* can be cloned by copying the context (e.g. with a simple74* <code>memcpy()</code>).75*/76typedef struct {77#ifndef DOXYGEN_IGNORE78unsigned char buf[64]; /* first field, for alignment */79size_t ptr;80sph_u32 state[16];81sph_u32 count_low, count_high;82#endif83} sph_simd_small_context;8485/**86* This structure is a context for SIMD computations: it contains the87* intermediate values and some data from the last entered block. Once88* an SIMD computation has been performed, the context can be reused for89* another computation. This specific structure is used for SIMD-38490* and SIMD-512.91*92* The contents of this structure are private. A running SIMD computation93* can be cloned by copying the context (e.g. with a simple94* <code>memcpy()</code>).95*/96typedef struct {97#ifndef DOXYGEN_IGNORE98unsigned char buf[128]; /* first field, for alignment */99size_t ptr;100sph_u32 state[32];101sph_u32 count_low, count_high;102#endif103} sph_simd_big_context;104105/**106* Type for a SIMD-224 context (identical to the common "small" context).107*/108typedef sph_simd_small_context sph_simd224_context;109110/**111* Type for a SIMD-256 context (identical to the common "small" context).112*/113typedef sph_simd_small_context sph_simd256_context;114115/**116* Type for a SIMD-384 context (identical to the common "big" context).117*/118typedef sph_simd_big_context sph_simd384_context;119120/**121* Type for a SIMD-512 context (identical to the common "big" context).122*/123typedef sph_simd_big_context sph_simd512_context;124125/**126* Initialize an SIMD-224 context. This process performs no memory allocation.127*128* @param cc the SIMD-224 context (pointer to a129* <code>sph_simd224_context</code>)130*/131void sph_simd224_init(void *cc);132133/**134* Process some data bytes. It is acceptable that <code>len</code> is zero135* (in which case this function does nothing).136*137* @param cc the SIMD-224 context138* @param data the input data139* @param len the input data length (in bytes)140*/141void sph_simd224(void *cc, const void *data, size_t len);142143/**144* Terminate the current SIMD-224 computation and output the result into145* the provided buffer. The destination buffer must be wide enough to146* accomodate the result (28 bytes). The context is automatically147* reinitialized.148*149* @param cc the SIMD-224 context150* @param dst the destination buffer151*/152void sph_simd224_close(void *cc, void *dst);153154/**155* Add a few additional bits (0 to 7) to the current computation, then156* terminate it and output the result in the provided buffer, which must157* be wide enough to accomodate the result (28 bytes). If bit number i158* in <code>ub</code> has value 2^i, then the extra bits are those159* numbered 7 downto 8-n (this is the big-endian convention at the byte160* level). The context is automatically reinitialized.161*162* @param cc the SIMD-224 context163* @param ub the extra bits164* @param n the number of extra bits (0 to 7)165* @param dst the destination buffer166*/167void sph_simd224_addbits_and_close(168void *cc, unsigned ub, unsigned n, void *dst);169170/**171* Initialize an SIMD-256 context. This process performs no memory allocation.172*173* @param cc the SIMD-256 context (pointer to a174* <code>sph_simd256_context</code>)175*/176void sph_simd256_init(void *cc);177178/**179* Process some data bytes. It is acceptable that <code>len</code> is zero180* (in which case this function does nothing).181*182* @param cc the SIMD-256 context183* @param data the input data184* @param len the input data length (in bytes)185*/186void sph_simd256(void *cc, const void *data, size_t len);187188/**189* Terminate the current SIMD-256 computation and output the result into190* the provided buffer. The destination buffer must be wide enough to191* accomodate the result (32 bytes). The context is automatically192* reinitialized.193*194* @param cc the SIMD-256 context195* @param dst the destination buffer196*/197void sph_simd256_close(void *cc, void *dst);198199/**200* Add a few additional bits (0 to 7) to the current computation, then201* terminate it and output the result in the provided buffer, which must202* be wide enough to accomodate the result (32 bytes). If bit number i203* in <code>ub</code> has value 2^i, then the extra bits are those204* numbered 7 downto 8-n (this is the big-endian convention at the byte205* level). The context is automatically reinitialized.206*207* @param cc the SIMD-256 context208* @param ub the extra bits209* @param n the number of extra bits (0 to 7)210* @param dst the destination buffer211*/212void sph_simd256_addbits_and_close(213void *cc, unsigned ub, unsigned n, void *dst);214215/**216* Initialize an SIMD-384 context. This process performs no memory allocation.217*218* @param cc the SIMD-384 context (pointer to a219* <code>sph_simd384_context</code>)220*/221void sph_simd384_init(void *cc);222223/**224* Process some data bytes. It is acceptable that <code>len</code> is zero225* (in which case this function does nothing).226*227* @param cc the SIMD-384 context228* @param data the input data229* @param len the input data length (in bytes)230*/231void sph_simd384(void *cc, const void *data, size_t len);232233/**234* Terminate the current SIMD-384 computation and output the result into235* the provided buffer. The destination buffer must be wide enough to236* accomodate the result (48 bytes). The context is automatically237* reinitialized.238*239* @param cc the SIMD-384 context240* @param dst the destination buffer241*/242void sph_simd384_close(void *cc, void *dst);243244/**245* Add a few additional bits (0 to 7) to the current computation, then246* terminate it and output the result in the provided buffer, which must247* be wide enough to accomodate the result (48 bytes). If bit number i248* in <code>ub</code> has value 2^i, then the extra bits are those249* numbered 7 downto 8-n (this is the big-endian convention at the byte250* level). The context is automatically reinitialized.251*252* @param cc the SIMD-384 context253* @param ub the extra bits254* @param n the number of extra bits (0 to 7)255* @param dst the destination buffer256*/257void sph_simd384_addbits_and_close(258void *cc, unsigned ub, unsigned n, void *dst);259260/**261* Initialize an SIMD-512 context. This process performs no memory allocation.262*263* @param cc the SIMD-512 context (pointer to a264* <code>sph_simd512_context</code>)265*/266void sph_simd512_init(void *cc);267268/**269* Process some data bytes. It is acceptable that <code>len</code> is zero270* (in which case this function does nothing).271*272* @param cc the SIMD-512 context273* @param data the input data274* @param len the input data length (in bytes)275*/276void sph_simd512(void *cc, const void *data, size_t len);277278/**279* Terminate the current SIMD-512 computation and output the result into280* the provided buffer. The destination buffer must be wide enough to281* accomodate the result (64 bytes). The context is automatically282* reinitialized.283*284* @param cc the SIMD-512 context285* @param dst the destination buffer286*/287void sph_simd512_close(void *cc, void *dst);288289/**290* Add a few additional bits (0 to 7) to the current computation, then291* terminate it and output the result in the provided buffer, which must292* be wide enough to accomodate the result (64 bytes). If bit number i293* in <code>ub</code> has value 2^i, then the extra bits are those294* numbered 7 downto 8-n (this is the big-endian convention at the byte295* level). The context is automatically reinitialized.296*297* @param cc the SIMD-512 context298* @param ub the extra bits299* @param n the number of extra bits (0 to 7)300* @param dst the destination buffer301*/302void sph_simd512_addbits_and_close(303void *cc, unsigned ub, unsigned n, void *dst);304#ifdef __cplusplus305}306#endif307308#endif309310311