/* $Id: sph_echo.h 216 2010-06-08 09:46:57Z tp $ */1/**2* ECHO interface. ECHO is a family of functions which differ by3* their output size; this implementation defines ECHO 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_echo.h32* @author Thomas Pornin <[email protected]>33*/3435#ifndef SPH_ECHO_H__36#define SPH_ECHO_H__3738#ifdef __cplusplus39extern "C"{40#endif4142#include <stddef.h>43#include "sph_types.h"4445/**46* Output size (in bits) for ECHO-224.47*/48#define SPH_SIZE_echo224 2244950/**51* Output size (in bits) for ECHO-256.52*/53#define SPH_SIZE_echo256 2565455/**56* Output size (in bits) for ECHO-384.57*/58#define SPH_SIZE_echo384 3845960/**61* Output size (in bits) for ECHO-512.62*/63#define SPH_SIZE_echo512 5126465/**66* This structure is a context for ECHO computations: it contains the67* intermediate values and some data from the last entered block. Once68* an ECHO computation has been performed, the context can be reused for69* another computation. This specific structure is used for ECHO-22470* and ECHO-256.71*72* The contents of this structure are private. A running ECHO 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[192]; /* first field, for alignment */79size_t ptr;80union {81sph_u32 Vs[4][4];82#if SPH_6483sph_u64 Vb[4][2];84#endif85} u;86sph_u32 C0, C1, C2, C3;87#endif88} sph_echo_small_context;8990/**91* This structure is a context for ECHO computations: it contains the92* intermediate values and some data from the last entered block. Once93* an ECHO computation has been performed, the context can be reused for94* another computation. This specific structure is used for ECHO-38495* and ECHO-512.96*97* The contents of this structure are private. A running ECHO computation98* can be cloned by copying the context (e.g. with a simple99* <code>memcpy()</code>).100*/101typedef struct {102#ifndef DOXYGEN_IGNORE103unsigned char buf[128]; /* first field, for alignment */104size_t ptr;105union {106sph_u32 Vs[8][4];107#if SPH_64108sph_u64 Vb[8][2];109#endif110} u;111sph_u32 C0, C1, C2, C3;112#endif113} sph_echo_big_context;114115/**116* Type for a ECHO-224 context (identical to the common "small" context).117*/118typedef sph_echo_small_context sph_echo224_context;119120/**121* Type for a ECHO-256 context (identical to the common "small" context).122*/123typedef sph_echo_small_context sph_echo256_context;124125/**126* Type for a ECHO-384 context (identical to the common "big" context).127*/128typedef sph_echo_big_context sph_echo384_context;129130/**131* Type for a ECHO-512 context (identical to the common "big" context).132*/133typedef sph_echo_big_context sph_echo512_context;134135/**136* Initialize an ECHO-224 context. This process performs no memory allocation.137*138* @param cc the ECHO-224 context (pointer to a139* <code>sph_echo224_context</code>)140*/141void sph_echo224_init(void *cc);142143/**144* Process some data bytes. It is acceptable that <code>len</code> is zero145* (in which case this function does nothing).146*147* @param cc the ECHO-224 context148* @param data the input data149* @param len the input data length (in bytes)150*/151void sph_echo224(void *cc, const void *data, size_t len);152153/**154* Terminate the current ECHO-224 computation and output the result into155* the provided buffer. The destination buffer must be wide enough to156* accomodate the result (28 bytes). The context is automatically157* reinitialized.158*159* @param cc the ECHO-224 context160* @param dst the destination buffer161*/162void sph_echo224_close(void *cc, void *dst);163164/**165* Add a few additional bits (0 to 7) to the current computation, then166* terminate it and output the result in the provided buffer, which must167* be wide enough to accomodate the result (28 bytes). If bit number i168* in <code>ub</code> has value 2^i, then the extra bits are those169* numbered 7 downto 8-n (this is the big-endian convention at the byte170* level). The context is automatically reinitialized.171*172* @param cc the ECHO-224 context173* @param ub the extra bits174* @param n the number of extra bits (0 to 7)175* @param dst the destination buffer176*/177void sph_echo224_addbits_and_close(178void *cc, unsigned ub, unsigned n, void *dst);179180/**181* Initialize an ECHO-256 context. This process performs no memory allocation.182*183* @param cc the ECHO-256 context (pointer to a184* <code>sph_echo256_context</code>)185*/186void sph_echo256_init(void *cc);187188/**189* Process some data bytes. It is acceptable that <code>len</code> is zero190* (in which case this function does nothing).191*192* @param cc the ECHO-256 context193* @param data the input data194* @param len the input data length (in bytes)195*/196void sph_echo256(void *cc, const void *data, size_t len);197198/**199* Terminate the current ECHO-256 computation and output the result into200* the provided buffer. The destination buffer must be wide enough to201* accomodate the result (32 bytes). The context is automatically202* reinitialized.203*204* @param cc the ECHO-256 context205* @param dst the destination buffer206*/207void sph_echo256_close(void *cc, void *dst);208209/**210* Add a few additional bits (0 to 7) to the current computation, then211* terminate it and output the result in the provided buffer, which must212* be wide enough to accomodate the result (32 bytes). If bit number i213* in <code>ub</code> has value 2^i, then the extra bits are those214* numbered 7 downto 8-n (this is the big-endian convention at the byte215* level). The context is automatically reinitialized.216*217* @param cc the ECHO-256 context218* @param ub the extra bits219* @param n the number of extra bits (0 to 7)220* @param dst the destination buffer221*/222void sph_echo256_addbits_and_close(223void *cc, unsigned ub, unsigned n, void *dst);224225/**226* Initialize an ECHO-384 context. This process performs no memory allocation.227*228* @param cc the ECHO-384 context (pointer to a229* <code>sph_echo384_context</code>)230*/231void sph_echo384_init(void *cc);232233/**234* Process some data bytes. It is acceptable that <code>len</code> is zero235* (in which case this function does nothing).236*237* @param cc the ECHO-384 context238* @param data the input data239* @param len the input data length (in bytes)240*/241void sph_echo384(void *cc, const void *data, size_t len);242243/**244* Terminate the current ECHO-384 computation and output the result into245* the provided buffer. The destination buffer must be wide enough to246* accomodate the result (48 bytes). The context is automatically247* reinitialized.248*249* @param cc the ECHO-384 context250* @param dst the destination buffer251*/252void sph_echo384_close(void *cc, void *dst);253254/**255* Add a few additional bits (0 to 7) to the current computation, then256* terminate it and output the result in the provided buffer, which must257* be wide enough to accomodate the result (48 bytes). If bit number i258* in <code>ub</code> has value 2^i, then the extra bits are those259* numbered 7 downto 8-n (this is the big-endian convention at the byte260* level). The context is automatically reinitialized.261*262* @param cc the ECHO-384 context263* @param ub the extra bits264* @param n the number of extra bits (0 to 7)265* @param dst the destination buffer266*/267void sph_echo384_addbits_and_close(268void *cc, unsigned ub, unsigned n, void *dst);269270/**271* Initialize an ECHO-512 context. This process performs no memory allocation.272*273* @param cc the ECHO-512 context (pointer to a274* <code>sph_echo512_context</code>)275*/276void sph_echo512_init(void *cc);277278/**279* Process some data bytes. It is acceptable that <code>len</code> is zero280* (in which case this function does nothing).281*282* @param cc the ECHO-512 context283* @param data the input data284* @param len the input data length (in bytes)285*/286void sph_echo512(void *cc, const void *data, size_t len);287288/**289* Terminate the current ECHO-512 computation and output the result into290* the provided buffer. The destination buffer must be wide enough to291* accomodate the result (64 bytes). The context is automatically292* reinitialized.293*294* @param cc the ECHO-512 context295* @param dst the destination buffer296*/297void sph_echo512_close(void *cc, void *dst);298299/**300* Add a few additional bits (0 to 7) to the current computation, then301* terminate it and output the result in the provided buffer, which must302* be wide enough to accomodate the result (64 bytes). If bit number i303* in <code>ub</code> has value 2^i, then the extra bits are those304* numbered 7 downto 8-n (this is the big-endian convention at the byte305* level). The context is automatically reinitialized.306*307* @param cc the ECHO-512 context308* @param ub the extra bits309* @param n the number of extra bits (0 to 7)310* @param dst the destination buffer311*/312void sph_echo512_addbits_and_close(313void *cc, unsigned ub, unsigned n, void *dst);314315#ifdef __cplusplus316}317#endif318319#endif320321322