/* $Id: sph_luffa.h 154 2010-04-26 17:00:24Z tp $ */1/**2* Luffa interface. Luffa is a family of functions which differ by3* their output size; this implementation defines Luffa 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_luffa.h32* @author Thomas Pornin <[email protected]>33*/3435#ifndef SPH_LUFFA_H__36#define SPH_LUFFA_H__3738#ifdef __cplusplus39extern "C"{40#endif4142#include <stddef.h>43#include "sph_types.h"4445/**46* Output size (in bits) for Luffa-224.47*/48#define SPH_SIZE_luffa224 2244950/**51* Output size (in bits) for Luffa-256.52*/53#define SPH_SIZE_luffa256 2565455/**56* Output size (in bits) for Luffa-384.57*/58#define SPH_SIZE_luffa384 3845960/**61* Output size (in bits) for Luffa-512.62*/63#define SPH_SIZE_luffa512 5126465/**66* This structure is a context for Luffa-224 computations: it contains67* the intermediate values and some data from the last entered block.68* Once a Luffa computation has been performed, the context can be69* reused for another computation.70*71* The contents of this structure are private. A running Luffa72* computation can be cloned by copying the context (e.g. with a simple73* <code>memcpy()</code>).74*/75typedef struct {76#ifndef DOXYGEN_IGNORE77unsigned char buf[32]; /* first field, for alignment */78size_t ptr;79sph_u32 V[3][8];80#endif81} sph_luffa224_context;8283/**84* This structure is a context for Luffa-256 computations. It is85* identical to <code>sph_luffa224_context</code>.86*/87typedef sph_luffa224_context sph_luffa256_context;8889/**90* This structure is a context for Luffa-384 computations.91*/92typedef struct {93#ifndef DOXYGEN_IGNORE94unsigned char buf[32]; /* first field, for alignment */95size_t ptr;96sph_u32 V[4][8];97#endif98} sph_luffa384_context;99100/**101* This structure is a context for Luffa-512 computations.102*/103typedef struct {104#ifndef DOXYGEN_IGNORE105unsigned char buf[32]; /* first field, for alignment */106size_t ptr;107sph_u32 V[5][8];108#endif109} sph_luffa512_context;110111/**112* Initialize a Luffa-224 context. This process performs no memory allocation.113*114* @param cc the Luffa-224 context (pointer to a115* <code>sph_luffa224_context</code>)116*/117void sph_luffa224_init(void *cc);118119/**120* Process some data bytes. It is acceptable that <code>len</code> is zero121* (in which case this function does nothing).122*123* @param cc the Luffa-224 context124* @param data the input data125* @param len the input data length (in bytes)126*/127void sph_luffa224(void *cc, const void *data, size_t len);128129/**130* Terminate the current Luffa-224 computation and output the result into131* the provided buffer. The destination buffer must be wide enough to132* accomodate the result (28 bytes). The context is automatically133* reinitialized.134*135* @param cc the Luffa-224 context136* @param dst the destination buffer137*/138void sph_luffa224_close(void *cc, void *dst);139140/**141* Add a few additional bits (0 to 7) to the current computation, then142* terminate it and output the result in the provided buffer, which must143* be wide enough to accomodate the result (28 bytes). If bit number i144* in <code>ub</code> has value 2^i, then the extra bits are those145* numbered 7 downto 8-n (this is the big-endian convention at the byte146* level). The context is automatically reinitialized.147*148* @param cc the Luffa-224 context149* @param ub the extra bits150* @param n the number of extra bits (0 to 7)151* @param dst the destination buffer152*/153void sph_luffa224_addbits_and_close(154void *cc, unsigned ub, unsigned n, void *dst);155156/**157* Initialize a Luffa-256 context. This process performs no memory allocation.158*159* @param cc the Luffa-256 context (pointer to a160* <code>sph_luffa256_context</code>)161*/162void sph_luffa256_init(void *cc);163164/**165* Process some data bytes. It is acceptable that <code>len</code> is zero166* (in which case this function does nothing).167*168* @param cc the Luffa-256 context169* @param data the input data170* @param len the input data length (in bytes)171*/172void sph_luffa256(void *cc, const void *data, size_t len);173174/**175* Terminate the current Luffa-256 computation and output the result into176* the provided buffer. The destination buffer must be wide enough to177* accomodate the result (32 bytes). The context is automatically178* reinitialized.179*180* @param cc the Luffa-256 context181* @param dst the destination buffer182*/183void sph_luffa256_close(void *cc, void *dst);184185/**186* Add a few additional bits (0 to 7) to the current computation, then187* terminate it and output the result in the provided buffer, which must188* be wide enough to accomodate the result (32 bytes). If bit number i189* in <code>ub</code> has value 2^i, then the extra bits are those190* numbered 7 downto 8-n (this is the big-endian convention at the byte191* level). The context is automatically reinitialized.192*193* @param cc the Luffa-256 context194* @param ub the extra bits195* @param n the number of extra bits (0 to 7)196* @param dst the destination buffer197*/198void sph_luffa256_addbits_and_close(199void *cc, unsigned ub, unsigned n, void *dst);200201/**202* Initialize a Luffa-384 context. This process performs no memory allocation.203*204* @param cc the Luffa-384 context (pointer to a205* <code>sph_luffa384_context</code>)206*/207void sph_luffa384_init(void *cc);208209/**210* Process some data bytes. It is acceptable that <code>len</code> is zero211* (in which case this function does nothing).212*213* @param cc the Luffa-384 context214* @param data the input data215* @param len the input data length (in bytes)216*/217void sph_luffa384(void *cc, const void *data, size_t len);218219/**220* Terminate the current Luffa-384 computation and output the result into221* the provided buffer. The destination buffer must be wide enough to222* accomodate the result (48 bytes). The context is automatically223* reinitialized.224*225* @param cc the Luffa-384 context226* @param dst the destination buffer227*/228void sph_luffa384_close(void *cc, void *dst);229230/**231* Add a few additional bits (0 to 7) to the current computation, then232* terminate it and output the result in the provided buffer, which must233* be wide enough to accomodate the result (48 bytes). If bit number i234* in <code>ub</code> has value 2^i, then the extra bits are those235* numbered 7 downto 8-n (this is the big-endian convention at the byte236* level). The context is automatically reinitialized.237*238* @param cc the Luffa-384 context239* @param ub the extra bits240* @param n the number of extra bits (0 to 7)241* @param dst the destination buffer242*/243void sph_luffa384_addbits_and_close(244void *cc, unsigned ub, unsigned n, void *dst);245246/**247* Initialize a Luffa-512 context. This process performs no memory allocation.248*249* @param cc the Luffa-512 context (pointer to a250* <code>sph_luffa512_context</code>)251*/252void sph_luffa512_init(void *cc);253254/**255* Process some data bytes. It is acceptable that <code>len</code> is zero256* (in which case this function does nothing).257*258* @param cc the Luffa-512 context259* @param data the input data260* @param len the input data length (in bytes)261*/262void sph_luffa512(void *cc, const void *data, size_t len);263264/**265* Terminate the current Luffa-512 computation and output the result into266* the provided buffer. The destination buffer must be wide enough to267* accomodate the result (64 bytes). The context is automatically268* reinitialized.269*270* @param cc the Luffa-512 context271* @param dst the destination buffer272*/273void sph_luffa512_close(void *cc, void *dst);274275/**276* Add a few additional bits (0 to 7) to the current computation, then277* terminate it and output the result in the provided buffer, which must278* be wide enough to accomodate the result (64 bytes). If bit number i279* in <code>ub</code> has value 2^i, then the extra bits are those280* numbered 7 downto 8-n (this is the big-endian convention at the byte281* level). The context is automatically reinitialized.282*283* @param cc the Luffa-512 context284* @param ub the extra bits285* @param n the number of extra bits (0 to 7)286* @param dst the destination buffer287*/288void sph_luffa512_addbits_and_close(289void *cc, unsigned ub, unsigned n, void *dst);290291#ifdef __cplusplus292}293#endif294295#endif296297298