/* $Id: sph_groestl.h 216 2010-06-08 09:46:57Z tp $ */1/**2* Groestl interface. This code implements Groestl with the recommended3* parameters for SHA-3, with outputs of 224, 256, 384 and 512 bits.4*5* ==========================(LICENSE BEGIN)============================6*7* Copyright (c) 2007-2010 Projet RNRT SAPHIR8*9* Permission is hereby granted, free of charge, to any person obtaining10* a copy of this software and associated documentation files (the11* "Software"), to deal in the Software without restriction, including12* without limitation the rights to use, copy, modify, merge, publish,13* distribute, sublicense, and/or sell copies of the Software, and to14* permit persons to whom the Software is furnished to do so, subject to15* the following conditions:16*17* The above copyright notice and this permission notice shall be18* included in all copies or substantial portions of the Software.19*20* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,21* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF22* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.23* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY24* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,25* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE26* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.27*28* ===========================(LICENSE END)=============================29*30* @file sph_groestl.h31* @author Thomas Pornin <[email protected]>32*/3334#ifndef SPH_GROESTL_H__35#define SPH_GROESTL_H__3637#ifdef __cplusplus38extern "C"{39#endif4041#include <stddef.h>42#include "sph_types.h"4344/**45* Output size (in bits) for Groestl-224.46*/47#define SPH_SIZE_groestl224 2244849/**50* Output size (in bits) for Groestl-256.51*/52#define SPH_SIZE_groestl256 2565354/**55* Output size (in bits) for Groestl-384.56*/57#define SPH_SIZE_groestl384 3845859/**60* Output size (in bits) for Groestl-512.61*/62#define SPH_SIZE_groestl512 5126364/**65* This structure is a context for Groestl-224 and Groestl-256 computations:66* it contains the intermediate values and some data from the last67* entered block. Once a Groestl computation has been performed, the68* context can be reused for another computation.69*70* The contents of this structure are private. A running Groestl71* computation can be cloned by copying the context (e.g. with a simple72* <code>memcpy()</code>).73*/74typedef struct {75#ifndef DOXYGEN_IGNORE76unsigned char buf[64]; /* first field, for alignment */77size_t ptr;78union {79#if SPH_6480sph_u64 wide[8];81#endif82sph_u32 narrow[16];83} state;84#if SPH_6485sph_u64 count;86#else87sph_u32 count_high, count_low;88#endif89#endif90} sph_groestl_small_context;9192/**93* This structure is a context for Groestl-224 computations. It is94* identical to the common <code>sph_groestl_small_context</code>.95*/96typedef sph_groestl_small_context sph_groestl224_context;9798/**99* This structure is a context for Groestl-256 computations. It is100* identical to the common <code>sph_groestl_small_context</code>.101*/102typedef sph_groestl_small_context sph_groestl256_context;103104/**105* This structure is a context for Groestl-384 and Groestl-512 computations:106* it contains the intermediate values and some data from the last107* entered block. Once a Groestl computation has been performed, the108* context can be reused for another computation.109*110* The contents of this structure are private. A running Groestl111* computation can be cloned by copying the context (e.g. with a simple112* <code>memcpy()</code>).113*/114typedef struct {115#ifndef DOXYGEN_IGNORE116unsigned char buf[128]; /* first field, for alignment */117size_t ptr;118union {119#if SPH_64120sph_u64 wide[16];121#endif122sph_u32 narrow[32];123} state;124#if SPH_64125sph_u64 count;126#else127sph_u32 count_high, count_low;128#endif129#endif130} sph_groestl_big_context;131132/**133* This structure is a context for Groestl-384 computations. It is134* identical to the common <code>sph_groestl_small_context</code>.135*/136typedef sph_groestl_big_context sph_groestl384_context;137138/**139* This structure is a context for Groestl-512 computations. It is140* identical to the common <code>sph_groestl_small_context</code>.141*/142typedef sph_groestl_big_context sph_groestl512_context;143144/**145* Initialize a Groestl-224 context. This process performs no memory allocation.146*147* @param cc the Groestl-224 context (pointer to a148* <code>sph_groestl224_context</code>)149*/150void sph_groestl224_init(void *cc);151152/**153* Process some data bytes. It is acceptable that <code>len</code> is zero154* (in which case this function does nothing).155*156* @param cc the Groestl-224 context157* @param data the input data158* @param len the input data length (in bytes)159*/160void sph_groestl224(void *cc, const void *data, size_t len);161162/**163* Terminate the current Groestl-224 computation and output the result into164* the provided buffer. The destination buffer must be wide enough to165* accomodate the result (28 bytes). The context is automatically166* reinitialized.167*168* @param cc the Groestl-224 context169* @param dst the destination buffer170*/171void sph_groestl224_close(void *cc, void *dst);172173/**174* Add a few additional bits (0 to 7) to the current computation, then175* terminate it and output the result in the provided buffer, which must176* be wide enough to accomodate the result (28 bytes). If bit number i177* in <code>ub</code> has value 2^i, then the extra bits are those178* numbered 7 downto 8-n (this is the big-endian convention at the byte179* level). The context is automatically reinitialized.180*181* @param cc the Groestl-224 context182* @param ub the extra bits183* @param n the number of extra bits (0 to 7)184* @param dst the destination buffer185*/186void sph_groestl224_addbits_and_close(187void *cc, unsigned ub, unsigned n, void *dst);188189/**190* Initialize a Groestl-256 context. This process performs no memory allocation.191*192* @param cc the Groestl-256 context (pointer to a193* <code>sph_groestl256_context</code>)194*/195void sph_groestl256_init(void *cc);196197/**198* Process some data bytes. It is acceptable that <code>len</code> is zero199* (in which case this function does nothing).200*201* @param cc the Groestl-256 context202* @param data the input data203* @param len the input data length (in bytes)204*/205void sph_groestl256(void *cc, const void *data, size_t len);206207/**208* Terminate the current Groestl-256 computation and output the result into209* the provided buffer. The destination buffer must be wide enough to210* accomodate the result (32 bytes). The context is automatically211* reinitialized.212*213* @param cc the Groestl-256 context214* @param dst the destination buffer215*/216void sph_groestl256_close(void *cc, void *dst);217218/**219* Add a few additional bits (0 to 7) to the current computation, then220* terminate it and output the result in the provided buffer, which must221* be wide enough to accomodate the result (32 bytes). If bit number i222* in <code>ub</code> has value 2^i, then the extra bits are those223* numbered 7 downto 8-n (this is the big-endian convention at the byte224* level). The context is automatically reinitialized.225*226* @param cc the Groestl-256 context227* @param ub the extra bits228* @param n the number of extra bits (0 to 7)229* @param dst the destination buffer230*/231void sph_groestl256_addbits_and_close(232void *cc, unsigned ub, unsigned n, void *dst);233234/**235* Initialize a Groestl-384 context. This process performs no memory allocation.236*237* @param cc the Groestl-384 context (pointer to a238* <code>sph_groestl384_context</code>)239*/240void sph_groestl384_init(void *cc);241242/**243* Process some data bytes. It is acceptable that <code>len</code> is zero244* (in which case this function does nothing).245*246* @param cc the Groestl-384 context247* @param data the input data248* @param len the input data length (in bytes)249*/250void sph_groestl384(void *cc, const void *data, size_t len);251252/**253* Terminate the current Groestl-384 computation and output the result into254* the provided buffer. The destination buffer must be wide enough to255* accomodate the result (48 bytes). The context is automatically256* reinitialized.257*258* @param cc the Groestl-384 context259* @param dst the destination buffer260*/261void sph_groestl384_close(void *cc, void *dst);262263/**264* Add a few additional bits (0 to 7) to the current computation, then265* terminate it and output the result in the provided buffer, which must266* be wide enough to accomodate the result (48 bytes). If bit number i267* in <code>ub</code> has value 2^i, then the extra bits are those268* numbered 7 downto 8-n (this is the big-endian convention at the byte269* level). The context is automatically reinitialized.270*271* @param cc the Groestl-384 context272* @param ub the extra bits273* @param n the number of extra bits (0 to 7)274* @param dst the destination buffer275*/276void sph_groestl384_addbits_and_close(277void *cc, unsigned ub, unsigned n, void *dst);278279/**280* Initialize a Groestl-512 context. This process performs no memory allocation.281*282* @param cc the Groestl-512 context (pointer to a283* <code>sph_groestl512_context</code>)284*/285void sph_groestl512_init(void *cc);286287/**288* Process some data bytes. It is acceptable that <code>len</code> is zero289* (in which case this function does nothing).290*291* @param cc the Groestl-512 context292* @param data the input data293* @param len the input data length (in bytes)294*/295void sph_groestl512(void *cc, const void *data, size_t len);296297/**298* Terminate the current Groestl-512 computation and output the result into299* the provided buffer. The destination buffer must be wide enough to300* accomodate the result (64 bytes). The context is automatically301* reinitialized.302*303* @param cc the Groestl-512 context304* @param dst the destination buffer305*/306void sph_groestl512_close(void *cc, void *dst);307308/**309* Add a few additional bits (0 to 7) to the current computation, then310* terminate it and output the result in the provided buffer, which must311* be wide enough to accomodate the result (64 bytes). If bit number i312* in <code>ub</code> has value 2^i, then the extra bits are those313* numbered 7 downto 8-n (this is the big-endian convention at the byte314* level). The context is automatically reinitialized.315*316* @param cc the Groestl-512 context317* @param ub the extra bits318* @param n the number of extra bits (0 to 7)319* @param dst the destination buffer320*/321void sph_groestl512_addbits_and_close(322void *cc, unsigned ub, unsigned n, void *dst);323324#ifdef __cplusplus325}326#endif327328#endif329330331