/* $Id: sph_hamsi.h 216 2010-06-08 09:46:57Z tp $ */1/**2* Hamsi interface. This code implements Hamsi 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_hamsi.h31* @author Thomas Pornin <[email protected]>32*/3334#ifndef SPH_HAMSI_H__35#define SPH_HAMSI_H__3637#include <stddef.h>38#include "sph_types.h"3940#ifdef __cplusplus41extern "C"{42#endif4344/**45* Output size (in bits) for Hamsi-224.46*/47#define SPH_SIZE_hamsi224 2244849/**50* Output size (in bits) for Hamsi-256.51*/52#define SPH_SIZE_hamsi256 2565354/**55* Output size (in bits) for Hamsi-384.56*/57#define SPH_SIZE_hamsi384 3845859/**60* Output size (in bits) for Hamsi-512.61*/62#define SPH_SIZE_hamsi512 5126364/**65* This structure is a context for Hamsi-224 and Hamsi-256 computations:66* it contains the intermediate values and some data from the last67* entered block. Once a Hamsi computation has been performed, the68* context can be reused for another computation.69*70* The contents of this structure are private. A running Hamsi71* computation can be cloned by copying the context (e.g. with a simple72* <code>memcpy()</code>).73*/74typedef struct {75#ifndef DOXYGEN_IGNORE76unsigned char partial[4];77size_t partial_len;78sph_u32 h[8];79#if SPH_6480sph_u64 count;81#else82sph_u32 count_high, count_low;83#endif84#endif85} sph_hamsi_small_context;8687/**88* This structure is a context for Hamsi-224 computations. It is89* identical to the common <code>sph_hamsi_small_context</code>.90*/91typedef sph_hamsi_small_context sph_hamsi224_context;9293/**94* This structure is a context for Hamsi-256 computations. It is95* identical to the common <code>sph_hamsi_small_context</code>.96*/97typedef sph_hamsi_small_context sph_hamsi256_context;9899/**100* This structure is a context for Hamsi-384 and Hamsi-512 computations:101* it contains the intermediate values and some data from the last102* entered block. Once a Hamsi computation has been performed, the103* context can be reused for another computation.104*105* The contents of this structure are private. A running Hamsi106* computation can be cloned by copying the context (e.g. with a simple107* <code>memcpy()</code>).108*/109typedef struct {110#ifndef DOXYGEN_IGNORE111unsigned char partial[8];112size_t partial_len;113sph_u32 h[16];114#if SPH_64115sph_u64 count;116#else117sph_u32 count_high, count_low;118#endif119#endif120} sph_hamsi_big_context;121122/**123* This structure is a context for Hamsi-384 computations. It is124* identical to the common <code>sph_hamsi_small_context</code>.125*/126typedef sph_hamsi_big_context sph_hamsi384_context;127128/**129* This structure is a context for Hamsi-512 computations. It is130* identical to the common <code>sph_hamsi_small_context</code>.131*/132typedef sph_hamsi_big_context sph_hamsi512_context;133134/**135* Initialize a Hamsi-224 context. This process performs no memory allocation.136*137* @param cc the Hamsi-224 context (pointer to a138* <code>sph_hamsi224_context</code>)139*/140void sph_hamsi224_init(void *cc);141142/**143* Process some data bytes. It is acceptable that <code>len</code> is zero144* (in which case this function does nothing).145*146* @param cc the Hamsi-224 context147* @param data the input data148* @param len the input data length (in bytes)149*/150void sph_hamsi224(void *cc, const void *data, size_t len);151152/**153* Terminate the current Hamsi-224 computation and output the result into154* the provided buffer. The destination buffer must be wide enough to155* accomodate the result (28 bytes). The context is automatically156* reinitialized.157*158* @param cc the Hamsi-224 context159* @param dst the destination buffer160*/161void sph_hamsi224_close(void *cc, void *dst);162163/**164* Add a few additional bits (0 to 7) to the current computation, then165* terminate it and output the result in the provided buffer, which must166* be wide enough to accomodate the result (28 bytes). If bit number i167* in <code>ub</code> has value 2^i, then the extra bits are those168* numbered 7 downto 8-n (this is the big-endian convention at the byte169* level). The context is automatically reinitialized.170*171* @param cc the Hamsi-224 context172* @param ub the extra bits173* @param n the number of extra bits (0 to 7)174* @param dst the destination buffer175*/176void sph_hamsi224_addbits_and_close(177void *cc, unsigned ub, unsigned n, void *dst);178179/**180* Initialize a Hamsi-256 context. This process performs no memory allocation.181*182* @param cc the Hamsi-256 context (pointer to a183* <code>sph_hamsi256_context</code>)184*/185void sph_hamsi256_init(void *cc);186187/**188* Process some data bytes. It is acceptable that <code>len</code> is zero189* (in which case this function does nothing).190*191* @param cc the Hamsi-256 context192* @param data the input data193* @param len the input data length (in bytes)194*/195void sph_hamsi256(void *cc, const void *data, size_t len);196197/**198* Terminate the current Hamsi-256 computation and output the result into199* the provided buffer. The destination buffer must be wide enough to200* accomodate the result (32 bytes). The context is automatically201* reinitialized.202*203* @param cc the Hamsi-256 context204* @param dst the destination buffer205*/206void sph_hamsi256_close(void *cc, void *dst);207208/**209* Add a few additional bits (0 to 7) to the current computation, then210* terminate it and output the result in the provided buffer, which must211* be wide enough to accomodate the result (32 bytes). If bit number i212* in <code>ub</code> has value 2^i, then the extra bits are those213* numbered 7 downto 8-n (this is the big-endian convention at the byte214* level). The context is automatically reinitialized.215*216* @param cc the Hamsi-256 context217* @param ub the extra bits218* @param n the number of extra bits (0 to 7)219* @param dst the destination buffer220*/221void sph_hamsi256_addbits_and_close(222void *cc, unsigned ub, unsigned n, void *dst);223224/**225* Initialize a Hamsi-384 context. This process performs no memory allocation.226*227* @param cc the Hamsi-384 context (pointer to a228* <code>sph_hamsi384_context</code>)229*/230void sph_hamsi384_init(void *cc);231232/**233* Process some data bytes. It is acceptable that <code>len</code> is zero234* (in which case this function does nothing).235*236* @param cc the Hamsi-384 context237* @param data the input data238* @param len the input data length (in bytes)239*/240void sph_hamsi384(void *cc, const void *data, size_t len);241242/**243* Terminate the current Hamsi-384 computation and output the result into244* the provided buffer. The destination buffer must be wide enough to245* accomodate the result (48 bytes). The context is automatically246* reinitialized.247*248* @param cc the Hamsi-384 context249* @param dst the destination buffer250*/251void sph_hamsi384_close(void *cc, void *dst);252253/**254* Add a few additional bits (0 to 7) to the current computation, then255* terminate it and output the result in the provided buffer, which must256* be wide enough to accomodate the result (48 bytes). If bit number i257* in <code>ub</code> has value 2^i, then the extra bits are those258* numbered 7 downto 8-n (this is the big-endian convention at the byte259* level). The context is automatically reinitialized.260*261* @param cc the Hamsi-384 context262* @param ub the extra bits263* @param n the number of extra bits (0 to 7)264* @param dst the destination buffer265*/266void sph_hamsi384_addbits_and_close(267void *cc, unsigned ub, unsigned n, void *dst);268269/**270* Initialize a Hamsi-512 context. This process performs no memory allocation.271*272* @param cc the Hamsi-512 context (pointer to a273* <code>sph_hamsi512_context</code>)274*/275void sph_hamsi512_init(void *cc);276277/**278* Process some data bytes. It is acceptable that <code>len</code> is zero279* (in which case this function does nothing).280*281* @param cc the Hamsi-512 context282* @param data the input data283* @param len the input data length (in bytes)284*/285void sph_hamsi512(void *cc, const void *data, size_t len);286287/**288* Terminate the current Hamsi-512 computation and output the result into289* the provided buffer. The destination buffer must be wide enough to290* accomodate the result (64 bytes). The context is automatically291* reinitialized.292*293* @param cc the Hamsi-512 context294* @param dst the destination buffer295*/296void sph_hamsi512_close(void *cc, void *dst);297298/**299* Add a few additional bits (0 to 7) to the current computation, then300* terminate it and output the result in the provided buffer, which must301* be wide enough to accomodate the result (64 bytes). If bit number i302* in <code>ub</code> has value 2^i, then the extra bits are those303* numbered 7 downto 8-n (this is the big-endian convention at the byte304* level). The context is automatically reinitialized.305*306* @param cc the Hamsi-512 context307* @param ub the extra bits308* @param n the number of extra bits (0 to 7)309* @param dst the destination buffer310*/311void sph_hamsi512_addbits_and_close(312void *cc, unsigned ub, unsigned n, void *dst);313314315316#ifdef __cplusplus317}318#endif319320#endif321322