/* $Id: sph_cubehash.h 180 2010-05-08 02:29:25Z tp $ */1/**2* CubeHash interface. CubeHash is a family of functions which differ by3* their output size; this implementation defines CubeHash for output4* sizes 224, 256, 384 and 512 bits, with the "standard parameters"5* (CubeHash16/32 with the CubeHash specification notations).6*7* ==========================(LICENSE BEGIN)============================8*9* Copyright (c) 2007-2010 Projet RNRT SAPHIR10*11* Permission is hereby granted, free of charge, to any person obtaining12* a copy of this software and associated documentation files (the13* "Software"), to deal in the Software without restriction, including14* without limitation the rights to use, copy, modify, merge, publish,15* distribute, sublicense, and/or sell copies of the Software, and to16* permit persons to whom the Software is furnished to do so, subject to17* the following conditions:18*19* The above copyright notice and this permission notice shall be20* included in all copies or substantial portions of the Software.21*22* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,23* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF24* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.25* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY26* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,27* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE28* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.29*30* ===========================(LICENSE END)=============================31*32* @file sph_cubehash.h33* @author Thomas Pornin <[email protected]>34*/3536#ifndef SPH_CUBEHASH_H__37#define SPH_CUBEHASH_H__3839#ifdef __cplusplus40extern "C"{41#endif4243#include <stddef.h>44#include "sph_types.h"4546/**47* Output size (in bits) for CubeHash-224.48*/49#define SPH_SIZE_cubehash224 2245051/**52* Output size (in bits) for CubeHash-256.53*/54#define SPH_SIZE_cubehash256 2565556/**57* Output size (in bits) for CubeHash-384.58*/59#define SPH_SIZE_cubehash384 3846061/**62* Output size (in bits) for CubeHash-512.63*/64#define SPH_SIZE_cubehash512 5126566/**67* This structure is a context for CubeHash computations: it contains the68* intermediate values and some data from the last entered block. Once69* a CubeHash computation has been performed, the context can be reused for70* another computation.71*72* The contents of this structure are private. A running CubeHash 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[32]; /* first field, for alignment */79size_t ptr;80sph_u32 state[32];81#endif82} sph_cubehash_context;8384/**85* Type for a CubeHash-224 context (identical to the common context).86*/87typedef sph_cubehash_context sph_cubehash224_context;8889/**90* Type for a CubeHash-256 context (identical to the common context).91*/92typedef sph_cubehash_context sph_cubehash256_context;9394/**95* Type for a CubeHash-384 context (identical to the common context).96*/97typedef sph_cubehash_context sph_cubehash384_context;9899/**100* Type for a CubeHash-512 context (identical to the common context).101*/102typedef sph_cubehash_context sph_cubehash512_context;103104/**105* Initialize a CubeHash-224 context. This process performs no memory106* allocation.107*108* @param cc the CubeHash-224 context (pointer to a109* <code>sph_cubehash224_context</code>)110*/111void sph_cubehash224_init(void *cc);112113/**114* Process some data bytes. It is acceptable that <code>len</code> is zero115* (in which case this function does nothing).116*117* @param cc the CubeHash-224 context118* @param data the input data119* @param len the input data length (in bytes)120*/121void sph_cubehash224(void *cc, const void *data, size_t len);122123/**124* Terminate the current CubeHash-224 computation and output the result into125* the provided buffer. The destination buffer must be wide enough to126* accomodate the result (28 bytes). The context is automatically127* reinitialized.128*129* @param cc the CubeHash-224 context130* @param dst the destination buffer131*/132void sph_cubehash224_close(void *cc, void *dst);133134/**135* Add a few additional bits (0 to 7) to the current computation, then136* terminate it and output the result in the provided buffer, which must137* be wide enough to accomodate the result (28 bytes). If bit number i138* in <code>ub</code> has value 2^i, then the extra bits are those139* numbered 7 downto 8-n (this is the big-endian convention at the byte140* level). The context is automatically reinitialized.141*142* @param cc the CubeHash-224 context143* @param ub the extra bits144* @param n the number of extra bits (0 to 7)145* @param dst the destination buffer146*/147void sph_cubehash224_addbits_and_close(148void *cc, unsigned ub, unsigned n, void *dst);149150/**151* Initialize a CubeHash-256 context. This process performs no memory152* allocation.153*154* @param cc the CubeHash-256 context (pointer to a155* <code>sph_cubehash256_context</code>)156*/157void sph_cubehash256_init(void *cc);158159/**160* Process some data bytes. It is acceptable that <code>len</code> is zero161* (in which case this function does nothing).162*163* @param cc the CubeHash-256 context164* @param data the input data165* @param len the input data length (in bytes)166*/167void sph_cubehash256(void *cc, const void *data, size_t len);168169/**170* Terminate the current CubeHash-256 computation and output the result into171* the provided buffer. The destination buffer must be wide enough to172* accomodate the result (32 bytes). The context is automatically173* reinitialized.174*175* @param cc the CubeHash-256 context176* @param dst the destination buffer177*/178void sph_cubehash256_close(void *cc, void *dst);179180/**181* Add a few additional bits (0 to 7) to the current computation, then182* terminate it and output the result in the provided buffer, which must183* be wide enough to accomodate the result (32 bytes). If bit number i184* in <code>ub</code> has value 2^i, then the extra bits are those185* numbered 7 downto 8-n (this is the big-endian convention at the byte186* level). The context is automatically reinitialized.187*188* @param cc the CubeHash-256 context189* @param ub the extra bits190* @param n the number of extra bits (0 to 7)191* @param dst the destination buffer192*/193void sph_cubehash256_addbits_and_close(194void *cc, unsigned ub, unsigned n, void *dst);195196/**197* Initialize a CubeHash-384 context. This process performs no memory198* allocation.199*200* @param cc the CubeHash-384 context (pointer to a201* <code>sph_cubehash384_context</code>)202*/203void sph_cubehash384_init(void *cc);204205/**206* Process some data bytes. It is acceptable that <code>len</code> is zero207* (in which case this function does nothing).208*209* @param cc the CubeHash-384 context210* @param data the input data211* @param len the input data length (in bytes)212*/213void sph_cubehash384(void *cc, const void *data, size_t len);214215/**216* Terminate the current CubeHash-384 computation and output the result into217* the provided buffer. The destination buffer must be wide enough to218* accomodate the result (48 bytes). The context is automatically219* reinitialized.220*221* @param cc the CubeHash-384 context222* @param dst the destination buffer223*/224void sph_cubehash384_close(void *cc, void *dst);225226/**227* Add a few additional bits (0 to 7) to the current computation, then228* terminate it and output the result in the provided buffer, which must229* be wide enough to accomodate the result (48 bytes). If bit number i230* in <code>ub</code> has value 2^i, then the extra bits are those231* numbered 7 downto 8-n (this is the big-endian convention at the byte232* level). The context is automatically reinitialized.233*234* @param cc the CubeHash-384 context235* @param ub the extra bits236* @param n the number of extra bits (0 to 7)237* @param dst the destination buffer238*/239void sph_cubehash384_addbits_and_close(240void *cc, unsigned ub, unsigned n, void *dst);241242/**243* Initialize a CubeHash-512 context. This process performs no memory244* allocation.245*246* @param cc the CubeHash-512 context (pointer to a247* <code>sph_cubehash512_context</code>)248*/249void sph_cubehash512_init(void *cc);250251/**252* Process some data bytes. It is acceptable that <code>len</code> is zero253* (in which case this function does nothing).254*255* @param cc the CubeHash-512 context256* @param data the input data257* @param len the input data length (in bytes)258*/259void sph_cubehash512(void *cc, const void *data, size_t len);260261/**262* Terminate the current CubeHash-512 computation and output the result into263* the provided buffer. The destination buffer must be wide enough to264* accomodate the result (64 bytes). The context is automatically265* reinitialized.266*267* @param cc the CubeHash-512 context268* @param dst the destination buffer269*/270void sph_cubehash512_close(void *cc, void *dst);271272/**273* Add a few additional bits (0 to 7) to the current computation, then274* terminate it and output the result in the provided buffer, which must275* be wide enough to accomodate the result (64 bytes). If bit number i276* in <code>ub</code> has value 2^i, then the extra bits are those277* numbered 7 downto 8-n (this is the big-endian convention at the byte278* level). The context is automatically reinitialized.279*280* @param cc the CubeHash-512 context281* @param ub the extra bits282* @param n the number of extra bits (0 to 7)283* @param dst the destination buffer284*/285void sph_cubehash512_addbits_and_close(286void *cc, unsigned ub, unsigned n, void *dst);287#ifdef __cplusplus288}289#endif290291#endif292293294