/* $Id: sph_gost.h 216 2010-06-08 09:46:57Z tp $ */1/**2* GOST interface. This is the interface for GOST R 12 with the3* recommended parameters for SHA-3, with output lengths 2564* 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_gost.h32* @author Mish <[email protected]>33*/3435#ifndef SPH_GOST_H__36#define SPH_GOST_H__3738#ifdef __cplusplus39extern "C"{40#endif4142#include <stddef.h>43#include "sph_types.h"4445/**46* Output size (in bits) for GOST-256.47*/48#define SPH_SIZE_gost256 2564950/**51* Output size (in bits) for GOST-512.52*/53#define SPH_SIZE_gost512 5125455/**56* This structure is a context for Keccak computations: it contains the57* intermediate values and some data from the last entered block. Once a58* GOST computation has been performed, the context can be reused for59* another computation.60*61* The contents of this structure are private. A running GOST computation62* can be cloned by copying the context (e.g. with a simple63* <code>memcpy()</code>).64*/6566/**67* This structure is a context for Gost-256 computations.68*/6970typedef struct {71#ifndef DOXYGEN_IGNORE72unsigned char buf[32]; /* first field, for alignment */73size_t ptr;74sph_u32 V[3][8];75#endif76} sph_gost256_context;7778/**79* This structure is a context for Gost-512 computations.80*/81typedef struct {82#ifndef DOXYGEN_IGNORE83unsigned char buf[64]; /* first field, for alignment */84size_t ptr;85sph_u32 V[5][8];86#endif87} sph_gost512_context;888990/**91* Initialize a GOST-256 context. This process performs no memory allocation.92*93* @param cc the GOST-256 context (pointer to a94* <code>sph_gost256_context</code>)95*/96void sph_gost256_init(void *cc);9798/**99* Process some data bytes. It is acceptable that <code>len</code> is zero100* (in which case this function does nothing).101*102* @param cc the Gost-256 context103* @param data the input data104* @param len the input data length (in bytes)105*/106void sph_gost256(void *cc, const void *data, size_t len);107108/**109* Terminate the current GOST-256 computation and output the result into110* the provided buffer. The destination buffer must be wide enough to111* accomodate the result (32 bytes). The context is automatically112* reinitialized.113*114* @param cc the GOST-256 context115* @param dst the destination buffer116*/117void sph_gost256_close(void *cc, void *dst);118119/**120* Add a few additional bits (0 to 7) to the current computation, then121* terminate it and output the result in the provided buffer, which must122* be wide enough to accomodate the result (32 bytes). If bit number i123* in <code>ub</code> has value 2^i, then the extra bits are those124* numbered 7 downto 8-n (this is the big-endian convention at the byte125* level). The context is automatically reinitialized.126*127* @param cc the GOST-256 context128* @param ub the extra bits129* @param n the number of extra bits (0 to 7)130* @param dst the destination buffer131*/132void sph_gost256_addbits_and_close(133void *cc, unsigned ub, unsigned n, void *dst);134135/**136* Initialize a Gost-512 context. This process performs no memory allocation.137*138* @param cc the GOST-512 context (pointer to a139* <code>sph_gost512_context</code>)140*/141void sph_gost512_init(void *cc);142143/**144* Process some data bytes. It is acceptable that <code>len</code> is zero145* (in which case this function does nothing).146*147* @param cc the GOST-512 context148* @param data the input data149* @param len the input data length (in bytes)150*/151void sph_gost512(void *cc, const void *data, size_t len);152153/**154* Terminate the current GOST-512 computation and output the result into155* the provided buffer. The destination buffer must be wide enough to156* accomodate the result (64 bytes). The context is automatically157* reinitialized.158*159* @param cc the GOST-512 context160* @param dst the destination buffer161*/162void sph_gost512_close(void *cc, void *dst);163164/**165* Add a few additional bits (0 to 7) to the current computation, then166* terminate it and output the result in the provided buffer, which must167* be wide enough to accomodate the result (64 bytes). If bit number i168* in <code>ub</code> has value 2^i, then the extra bits are those169* numbered 7 downto 8-n (this is the big-endian convention at the byte170* level). The context is automatically reinitialized.171*172* @param cc the GOST-512 context173* @param ub the extra bits174* @param n the number of extra bits (0 to 7)175* @param dst the destination buffer176*/177void sph_gost512_addbits_and_close(178void *cc, unsigned ub, unsigned n, void *dst);179180#ifdef __cplusplus181}182#endif183184#endif185186187