/* $Id: sph_shabal.h 175 2010-05-07 16:03:20Z tp $ */1/**2* Shabal interface. Shabal is a family of functions which differ by3* their output size; this implementation defines Shabal for output4* sizes 192, 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_shabal.h32* @author Thomas Pornin <[email protected]>33*/3435#ifndef SPH_SHABAL_H__36#define SPH_SHABAL_H__3738#include <stddef.h>39#include "sph_types.h"40#ifdef __cplusplus41extern "C"{42#endif4344/**45* Output size (in bits) for Shabal-192.46*/47#define SPH_SIZE_shabal192 1924849/**50* Output size (in bits) for Shabal-224.51*/52#define SPH_SIZE_shabal224 2245354/**55* Output size (in bits) for Shabal-256.56*/57#define SPH_SIZE_shabal256 2565859/**60* Output size (in bits) for Shabal-384.61*/62#define SPH_SIZE_shabal384 3846364/**65* Output size (in bits) for Shabal-512.66*/67#define SPH_SIZE_shabal512 5126869/**70* This structure is a context for Shabal computations: it contains the71* intermediate values and some data from the last entered block. Once72* a Shabal computation has been performed, the context can be reused for73* another computation.74*75* The contents of this structure are private. A running Shabal computation76* can be cloned by copying the context (e.g. with a simple77* <code>memcpy()</code>).78*/79typedef struct {80#ifndef DOXYGEN_IGNORE81unsigned char buf[64]; /* first field, for alignment */82size_t ptr;83sph_u32 A[12], B[16], C[16];84sph_u32 Whigh, Wlow;85#endif86} sph_shabal_context;8788/**89* Type for a Shabal-192 context (identical to the common context).90*/91typedef sph_shabal_context sph_shabal192_context;9293/**94* Type for a Shabal-224 context (identical to the common context).95*/96typedef sph_shabal_context sph_shabal224_context;9798/**99* Type for a Shabal-256 context (identical to the common context).100*/101typedef sph_shabal_context sph_shabal256_context;102103/**104* Type for a Shabal-384 context (identical to the common context).105*/106typedef sph_shabal_context sph_shabal384_context;107108/**109* Type for a Shabal-512 context (identical to the common context).110*/111typedef sph_shabal_context sph_shabal512_context;112113/**114* Initialize a Shabal-192 context. This process performs no memory allocation.115*116* @param cc the Shabal-192 context (pointer to a117* <code>sph_shabal192_context</code>)118*/119void sph_shabal192_init(void *cc);120121/**122* Process some data bytes. It is acceptable that <code>len</code> is zero123* (in which case this function does nothing).124*125* @param cc the Shabal-192 context126* @param data the input data127* @param len the input data length (in bytes)128*/129void sph_shabal192(void *cc, const void *data, size_t len);130131/**132* Terminate the current Shabal-192 computation and output the result into133* the provided buffer. The destination buffer must be wide enough to134* accomodate the result (24 bytes). The context is automatically135* reinitialized.136*137* @param cc the Shabal-192 context138* @param dst the destination buffer139*/140void sph_shabal192_close(void *cc, void *dst);141142/**143* Add a few additional bits (0 to 7) to the current computation, then144* terminate it and output the result in the provided buffer, which must145* be wide enough to accomodate the result (24 bytes). If bit number i146* in <code>ub</code> has value 2^i, then the extra bits are those147* numbered 7 downto 8-n (this is the big-endian convention at the byte148* level). The context is automatically reinitialized.149*150* @param cc the Shabal-192 context151* @param ub the extra bits152* @param n the number of extra bits (0 to 7)153* @param dst the destination buffer154*/155void sph_shabal192_addbits_and_close(156void *cc, unsigned ub, unsigned n, void *dst);157158/**159* Initialize a Shabal-224 context. This process performs no memory allocation.160*161* @param cc the Shabal-224 context (pointer to a162* <code>sph_shabal224_context</code>)163*/164void sph_shabal224_init(void *cc);165166/**167* Process some data bytes. It is acceptable that <code>len</code> is zero168* (in which case this function does nothing).169*170* @param cc the Shabal-224 context171* @param data the input data172* @param len the input data length (in bytes)173*/174void sph_shabal224(void *cc, const void *data, size_t len);175176/**177* Terminate the current Shabal-224 computation and output the result into178* the provided buffer. The destination buffer must be wide enough to179* accomodate the result (28 bytes). The context is automatically180* reinitialized.181*182* @param cc the Shabal-224 context183* @param dst the destination buffer184*/185void sph_shabal224_close(void *cc, void *dst);186187/**188* Add a few additional bits (0 to 7) to the current computation, then189* terminate it and output the result in the provided buffer, which must190* be wide enough to accomodate the result (28 bytes). If bit number i191* in <code>ub</code> has value 2^i, then the extra bits are those192* numbered 7 downto 8-n (this is the big-endian convention at the byte193* level). The context is automatically reinitialized.194*195* @param cc the Shabal-224 context196* @param ub the extra bits197* @param n the number of extra bits (0 to 7)198* @param dst the destination buffer199*/200void sph_shabal224_addbits_and_close(201void *cc, unsigned ub, unsigned n, void *dst);202203/**204* Initialize a Shabal-256 context. This process performs no memory allocation.205*206* @param cc the Shabal-256 context (pointer to a207* <code>sph_shabal256_context</code>)208*/209void sph_shabal256_init(void *cc);210211/**212* Process some data bytes. It is acceptable that <code>len</code> is zero213* (in which case this function does nothing).214*215* @param cc the Shabal-256 context216* @param data the input data217* @param len the input data length (in bytes)218*/219void sph_shabal256(void *cc, const void *data, size_t len);220221/**222* Terminate the current Shabal-256 computation and output the result into223* the provided buffer. The destination buffer must be wide enough to224* accomodate the result (32 bytes). The context is automatically225* reinitialized.226*227* @param cc the Shabal-256 context228* @param dst the destination buffer229*/230void sph_shabal256_close(void *cc, void *dst);231232/**233* Add a few additional bits (0 to 7) to the current computation, then234* terminate it and output the result in the provided buffer, which must235* be wide enough to accomodate the result (32 bytes). If bit number i236* in <code>ub</code> has value 2^i, then the extra bits are those237* numbered 7 downto 8-n (this is the big-endian convention at the byte238* level). The context is automatically reinitialized.239*240* @param cc the Shabal-256 context241* @param ub the extra bits242* @param n the number of extra bits (0 to 7)243* @param dst the destination buffer244*/245void sph_shabal256_addbits_and_close(246void *cc, unsigned ub, unsigned n, void *dst);247248/**249* Initialize a Shabal-384 context. This process performs no memory allocation.250*251* @param cc the Shabal-384 context (pointer to a252* <code>sph_shabal384_context</code>)253*/254void sph_shabal384_init(void *cc);255256/**257* Process some data bytes. It is acceptable that <code>len</code> is zero258* (in which case this function does nothing).259*260* @param cc the Shabal-384 context261* @param data the input data262* @param len the input data length (in bytes)263*/264void sph_shabal384(void *cc, const void *data, size_t len);265266/**267* Terminate the current Shabal-384 computation and output the result into268* the provided buffer. The destination buffer must be wide enough to269* accomodate the result (48 bytes). The context is automatically270* reinitialized.271*272* @param cc the Shabal-384 context273* @param dst the destination buffer274*/275void sph_shabal384_close(void *cc, void *dst);276277/**278* Add a few additional bits (0 to 7) to the current computation, then279* terminate it and output the result in the provided buffer, which must280* be wide enough to accomodate the result (48 bytes). If bit number i281* in <code>ub</code> has value 2^i, then the extra bits are those282* numbered 7 downto 8-n (this is the big-endian convention at the byte283* level). The context is automatically reinitialized.284*285* @param cc the Shabal-384 context286* @param ub the extra bits287* @param n the number of extra bits (0 to 7)288* @param dst the destination buffer289*/290void sph_shabal384_addbits_and_close(291void *cc, unsigned ub, unsigned n, void *dst);292293/**294* Initialize a Shabal-512 context. This process performs no memory allocation.295*296* @param cc the Shabal-512 context (pointer to a297* <code>sph_shabal512_context</code>)298*/299void sph_shabal512_init(void *cc);300301/**302* Process some data bytes. It is acceptable that <code>len</code> is zero303* (in which case this function does nothing).304*305* @param cc the Shabal-512 context306* @param data the input data307* @param len the input data length (in bytes)308*/309void sph_shabal512(void *cc, const void *data, size_t len);310311/**312* Terminate the current Shabal-512 computation and output the result into313* the provided buffer. The destination buffer must be wide enough to314* accomodate the result (64 bytes). The context is automatically315* reinitialized.316*317* @param cc the Shabal-512 context318* @param dst the destination buffer319*/320void sph_shabal512_close(void *cc, void *dst);321322/**323* Add a few additional bits (0 to 7) to the current computation, then324* terminate it and output the result in the provided buffer, which must325* be wide enough to accomodate the result (64 bytes). If bit number i326* in <code>ub</code> has value 2^i, then the extra bits are those327* numbered 7 downto 8-n (this is the big-endian convention at the byte328* level). The context is automatically reinitialized.329*330* @param cc the Shabal-512 context331* @param ub the extra bits332* @param n the number of extra bits (0 to 7)333* @param dst the destination buffer334*/335void sph_shabal512_addbits_and_close(336void *cc, unsigned ub, unsigned n, void *dst);337338#ifdef __cplusplus339}340#endif341342#endif343344345