/* $Id: sph_skein.h 253 2011-06-07 18:33:10Z tp $ */1/**2* Skein interface. The Skein specification defines three main3* functions, called Skein-256, Skein-512 and Skein-1024, which can be4* further parameterized with an output length. For the SHA-35* competition, Skein-512 is used for output sizes of 224, 256, 384 and6* 512 bits; this is what this code implements. Thus, we hereafter call7* Skein-224, Skein-256, Skein-384 and Skein-512 what the Skein8* specification defines as Skein-512-224, Skein-512-256, Skein-512-3849* and Skein-512-512, respectively.10*11* ==========================(LICENSE BEGIN)============================12*13* Copyright (c) 2007-2010 Projet RNRT SAPHIR14*15* Permission is hereby granted, free of charge, to any person obtaining16* a copy of this software and associated documentation files (the17* "Software"), to deal in the Software without restriction, including18* without limitation the rights to use, copy, modify, merge, publish,19* distribute, sublicense, and/or sell copies of the Software, and to20* permit persons to whom the Software is furnished to do so, subject to21* the following conditions:22*23* The above copyright notice and this permission notice shall be24* included in all copies or substantial portions of the Software.25*26* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,27* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF28* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.29* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY30* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,31* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE32* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.33*34* ===========================(LICENSE END)=============================35*36* @file sph_skein.h37* @author Thomas Pornin <[email protected]>38*/3940#ifndef SPH_SKEIN_H__41#define SPH_SKEIN_H__4243#ifdef __cplusplus44extern "C"{45#endif4647#include <stddef.h>48#include "sph_types.h"4950#if SPH_645152/**53* Output size (in bits) for Skein-224.54*/55#define SPH_SIZE_skein224 2245657/**58* Output size (in bits) for Skein-256.59*/60#define SPH_SIZE_skein256 2566162/**63* Output size (in bits) for Skein-384.64*/65#define SPH_SIZE_skein384 3846667/**68* Output size (in bits) for Skein-512.69*/70#define SPH_SIZE_skein512 5127172/**73* This structure is a context for Skein computations (with a 384- or74* 512-bit output): it contains the intermediate values and some data75* from the last entered block. Once a Skein computation has been76* performed, the context can be reused for another computation.77*78* The contents of this structure are private. A running Skein computation79* can be cloned by copying the context (e.g. with a simple80* <code>memcpy()</code>).81*/82typedef struct {83#ifndef DOXYGEN_IGNORE84unsigned char buf[64]; /* first field, for alignment */85size_t ptr;86sph_u64 h0, h1, h2, h3, h4, h5, h6, h7;87sph_u64 bcount;88#endif89} sph_skein_big_context;9091/**92* Type for a Skein-224 context (identical to the common "big" context).93*/94typedef sph_skein_big_context sph_skein224_context;9596/**97* Type for a Skein-256 context (identical to the common "big" context).98*/99typedef sph_skein_big_context sph_skein256_context;100101/**102* Type for a Skein-384 context (identical to the common "big" context).103*/104typedef sph_skein_big_context sph_skein384_context;105106/**107* Type for a Skein-512 context (identical to the common "big" context).108*/109typedef sph_skein_big_context sph_skein512_context;110111/**112* Initialize a Skein-224 context. This process performs no memory allocation.113*114* @param cc the Skein-224 context (pointer to a115* <code>sph_skein224_context</code>)116*/117void sph_skein224_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 Skein-224 context124* @param data the input data125* @param len the input data length (in bytes)126*/127void sph_skein224(void *cc, const void *data, size_t len);128129/**130* Terminate the current Skein-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 Skein-224 context136* @param dst the destination buffer137*/138void sph_skein224_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 Skein-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_skein224_addbits_and_close(154void *cc, unsigned ub, unsigned n, void *dst);155156/**157* Initialize a Skein-256 context. This process performs no memory allocation.158*159* @param cc the Skein-256 context (pointer to a160* <code>sph_skein256_context</code>)161*/162void sph_skein256_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 Skein-256 context169* @param data the input data170* @param len the input data length (in bytes)171*/172void sph_skein256(void *cc, const void *data, size_t len);173174/**175* Terminate the current Skein-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 Skein-256 context181* @param dst the destination buffer182*/183void sph_skein256_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 Skein-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_skein256_addbits_and_close(199void *cc, unsigned ub, unsigned n, void *dst);200201/**202* Initialize a Skein-384 context. This process performs no memory allocation.203*204* @param cc the Skein-384 context (pointer to a205* <code>sph_skein384_context</code>)206*/207void sph_skein384_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 Skein-384 context214* @param data the input data215* @param len the input data length (in bytes)216*/217void sph_skein384(void *cc, const void *data, size_t len);218219/**220* Terminate the current Skein-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 Skein-384 context226* @param dst the destination buffer227*/228void sph_skein384_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 Skein-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_skein384_addbits_and_close(244void *cc, unsigned ub, unsigned n, void *dst);245246/**247* Initialize a Skein-512 context. This process performs no memory allocation.248*249* @param cc the Skein-512 context (pointer to a250* <code>sph_skein512_context</code>)251*/252void sph_skein512_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 Skein-512 context259* @param data the input data260* @param len the input data length (in bytes)261*/262void sph_skein512(void *cc, const void *data, size_t len);263264/**265* Terminate the current Skein-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 Skein-512 context271* @param dst the destination buffer272*/273void sph_skein512_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 Skein-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_skein512_addbits_and_close(289void *cc, unsigned ub, unsigned n, void *dst);290291#endif292293#ifdef __cplusplus294}295#endif296297#endif298299300