/* $Id: sph_shavite.h 208 2010-06-02 20:33:00Z tp $ */1/**2* SHAvite-3 interface. This code implements SHAvite-3 with the3* recommended parameters for SHA-3, with outputs of 224, 256, 384 and4* 512 bits. In the following, we call the function "SHAvite" (without5* the "-3" suffix), thus "SHAvite-224" is "SHAvite-3 with a 224-bit6* output".7*8* ==========================(LICENSE BEGIN)============================9*10* Copyright (c) 2007-2010 Projet RNRT SAPHIR11*12* Permission is hereby granted, free of charge, to any person obtaining13* a copy of this software and associated documentation files (the14* "Software"), to deal in the Software without restriction, including15* without limitation the rights to use, copy, modify, merge, publish,16* distribute, sublicense, and/or sell copies of the Software, and to17* permit persons to whom the Software is furnished to do so, subject to18* the following conditions:19*20* The above copyright notice and this permission notice shall be21* included in all copies or substantial portions of the Software.22*23* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,24* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF25* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.26* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY27* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,28* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE29* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.30*31* ===========================(LICENSE END)=============================32*33* @file sph_shavite.h34* @author Thomas Pornin <[email protected]>35*/3637#ifndef SPH_SHAVITE_H__38#define SPH_SHAVITE_H__3940#include <stddef.h>41#include "sph_types.h"4243#ifdef __cplusplus44extern "C"{45#endif4647/**48* Output size (in bits) for SHAvite-224.49*/50#define SPH_SIZE_shavite224 2245152/**53* Output size (in bits) for SHAvite-256.54*/55#define SPH_SIZE_shavite256 2565657/**58* Output size (in bits) for SHAvite-384.59*/60#define SPH_SIZE_shavite384 3846162/**63* Output size (in bits) for SHAvite-512.64*/65#define SPH_SIZE_shavite512 5126667/**68* This structure is a context for SHAvite-224 and SHAvite-256 computations:69* it contains the intermediate values and some data from the last70* entered block. Once a SHAvite computation has been performed, the71* context can be reused for another computation.72*73* The contents of this structure are private. A running SHAvite74* computation can be cloned by copying the context (e.g. with a simple75* <code>memcpy()</code>).76*/77typedef struct {78#ifndef DOXYGEN_IGNORE79unsigned char buf[64]; /* first field, for alignment */80size_t ptr;81sph_u32 h[8];82sph_u32 count0, count1;83#endif84} sph_shavite_small_context;8586/**87* This structure is a context for SHAvite-224 computations. It is88* identical to the common <code>sph_shavite_small_context</code>.89*/90typedef sph_shavite_small_context sph_shavite224_context;9192/**93* This structure is a context for SHAvite-256 computations. It is94* identical to the common <code>sph_shavite_small_context</code>.95*/96typedef sph_shavite_small_context sph_shavite256_context;9798/**99* This structure is a context for SHAvite-384 and SHAvite-512 computations:100* it contains the intermediate values and some data from the last101* entered block. Once a SHAvite computation has been performed, the102* context can be reused for another computation.103*104* The contents of this structure are private. A running SHAvite105* computation can be cloned by copying the context (e.g. with a simple106* <code>memcpy()</code>).107*/108typedef struct {109#ifndef DOXYGEN_IGNORE110unsigned char buf[128]; /* first field, for alignment */111size_t ptr;112sph_u32 h[16];113sph_u32 count0, count1, count2, count3;114#endif115} sph_shavite_big_context;116117/**118* This structure is a context for SHAvite-384 computations. It is119* identical to the common <code>sph_shavite_small_context</code>.120*/121typedef sph_shavite_big_context sph_shavite384_context;122123/**124* This structure is a context for SHAvite-512 computations. It is125* identical to the common <code>sph_shavite_small_context</code>.126*/127typedef sph_shavite_big_context sph_shavite512_context;128129/**130* Initialize a SHAvite-224 context. This process performs no memory allocation.131*132* @param cc the SHAvite-224 context (pointer to a133* <code>sph_shavite224_context</code>)134*/135void sph_shavite224_init(void *cc);136137/**138* Process some data bytes. It is acceptable that <code>len</code> is zero139* (in which case this function does nothing).140*141* @param cc the SHAvite-224 context142* @param data the input data143* @param len the input data length (in bytes)144*/145void sph_shavite224(void *cc, const void *data, size_t len);146147/**148* Terminate the current SHAvite-224 computation and output the result into149* the provided buffer. The destination buffer must be wide enough to150* accomodate the result (28 bytes). The context is automatically151* reinitialized.152*153* @param cc the SHAvite-224 context154* @param dst the destination buffer155*/156void sph_shavite224_close(void *cc, void *dst);157158/**159* Add a few additional bits (0 to 7) to the current computation, then160* terminate it and output the result in the provided buffer, which must161* be wide enough to accomodate the result (28 bytes). If bit number i162* in <code>ub</code> has value 2^i, then the extra bits are those163* numbered 7 downto 8-n (this is the big-endian convention at the byte164* level). The context is automatically reinitialized.165*166* @param cc the SHAvite-224 context167* @param ub the extra bits168* @param n the number of extra bits (0 to 7)169* @param dst the destination buffer170*/171void sph_shavite224_addbits_and_close(172void *cc, unsigned ub, unsigned n, void *dst);173174/**175* Initialize a SHAvite-256 context. This process performs no memory allocation.176*177* @param cc the SHAvite-256 context (pointer to a178* <code>sph_shavite256_context</code>)179*/180void sph_shavite256_init(void *cc);181182/**183* Process some data bytes. It is acceptable that <code>len</code> is zero184* (in which case this function does nothing).185*186* @param cc the SHAvite-256 context187* @param data the input data188* @param len the input data length (in bytes)189*/190void sph_shavite256(void *cc, const void *data, size_t len);191192/**193* Terminate the current SHAvite-256 computation and output the result into194* the provided buffer. The destination buffer must be wide enough to195* accomodate the result (32 bytes). The context is automatically196* reinitialized.197*198* @param cc the SHAvite-256 context199* @param dst the destination buffer200*/201void sph_shavite256_close(void *cc, void *dst);202203/**204* Add a few additional bits (0 to 7) to the current computation, then205* terminate it and output the result in the provided buffer, which must206* be wide enough to accomodate the result (32 bytes). If bit number i207* in <code>ub</code> has value 2^i, then the extra bits are those208* numbered 7 downto 8-n (this is the big-endian convention at the byte209* level). The context is automatically reinitialized.210*211* @param cc the SHAvite-256 context212* @param ub the extra bits213* @param n the number of extra bits (0 to 7)214* @param dst the destination buffer215*/216void sph_shavite256_addbits_and_close(217void *cc, unsigned ub, unsigned n, void *dst);218219/**220* Initialize a SHAvite-384 context. This process performs no memory allocation.221*222* @param cc the SHAvite-384 context (pointer to a223* <code>sph_shavite384_context</code>)224*/225void sph_shavite384_init(void *cc);226227/**228* Process some data bytes. It is acceptable that <code>len</code> is zero229* (in which case this function does nothing).230*231* @param cc the SHAvite-384 context232* @param data the input data233* @param len the input data length (in bytes)234*/235void sph_shavite384(void *cc, const void *data, size_t len);236237/**238* Terminate the current SHAvite-384 computation and output the result into239* the provided buffer. The destination buffer must be wide enough to240* accomodate the result (48 bytes). The context is automatically241* reinitialized.242*243* @param cc the SHAvite-384 context244* @param dst the destination buffer245*/246void sph_shavite384_close(void *cc, void *dst);247248/**249* Add a few additional bits (0 to 7) to the current computation, then250* terminate it and output the result in the provided buffer, which must251* be wide enough to accomodate the result (48 bytes). If bit number i252* in <code>ub</code> has value 2^i, then the extra bits are those253* numbered 7 downto 8-n (this is the big-endian convention at the byte254* level). The context is automatically reinitialized.255*256* @param cc the SHAvite-384 context257* @param ub the extra bits258* @param n the number of extra bits (0 to 7)259* @param dst the destination buffer260*/261void sph_shavite384_addbits_and_close(262void *cc, unsigned ub, unsigned n, void *dst);263264/**265* Initialize a SHAvite-512 context. This process performs no memory allocation.266*267* @param cc the SHAvite-512 context (pointer to a268* <code>sph_shavite512_context</code>)269*/270void sph_shavite512_init(void *cc);271272/**273* Process some data bytes. It is acceptable that <code>len</code> is zero274* (in which case this function does nothing).275*276* @param cc the SHAvite-512 context277* @param data the input data278* @param len the input data length (in bytes)279*/280void sph_shavite512(void *cc, const void *data, size_t len);281282/**283* Terminate the current SHAvite-512 computation and output the result into284* the provided buffer. The destination buffer must be wide enough to285* accomodate the result (64 bytes). The context is automatically286* reinitialized.287*288* @param cc the SHAvite-512 context289* @param dst the destination buffer290*/291void sph_shavite512_close(void *cc, void *dst);292293/**294* Add a few additional bits (0 to 7) to the current computation, then295* terminate it and output the result in the provided buffer, which must296* be wide enough to accomodate the result (64 bytes). If bit number i297* in <code>ub</code> has value 2^i, then the extra bits are those298* numbered 7 downto 8-n (this is the big-endian convention at the byte299* level). The context is automatically reinitialized.300*301* @param cc the SHAvite-512 context302* @param ub the extra bits303* @param n the number of extra bits (0 to 7)304* @param dst the destination buffer305*/306void sph_shavite512_addbits_and_close(307void *cc, unsigned ub, unsigned n, void *dst);308309#ifdef __cplusplus310}311#endif312313#endif314315316