/* $Id: sph_jh.h 216 2010-06-08 09:46:57Z tp $ */1/**2* JH interface. JH is a family of functions which differ by3* their output size; this implementation defines JH for output4* sizes 224, 256, 384 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_jh.h32* @author Thomas Pornin <[email protected]>33*/3435#ifndef SPH_JH_H__36#define SPH_JH_H__3738#ifdef __cplusplus39extern "C"{40#endif4142#include <stddef.h>43#include "sph_types.h"4445/**46* Output size (in bits) for JH-224.47*/48#define SPH_SIZE_jh224 2244950/**51* Output size (in bits) for JH-256.52*/53#define SPH_SIZE_jh256 2565455/**56* Output size (in bits) for JH-384.57*/58#define SPH_SIZE_jh384 3845960/**61* Output size (in bits) for JH-512.62*/63#define SPH_SIZE_jh512 5126465/**66* This structure is a context for JH computations: it contains the67* intermediate values and some data from the last entered block. Once68* a JH computation has been performed, the context can be reused for69* another computation.70*71* The contents of this structure are private. A running JH computation72* can be cloned by copying the context (e.g. with a simple73* <code>memcpy()</code>).74*/75typedef struct {76#ifndef DOXYGEN_IGNORE77unsigned char buf[64]; /* first field, for alignment */78size_t ptr;79union {80#if SPH_6481sph_u64 wide[16];82#endif83sph_u32 narrow[32];84} H;85#if SPH_6486sph_u64 block_count;87#else88sph_u32 block_count_high, block_count_low;89#endif90#endif91} sph_jh_context;9293/**94* Type for a JH-224 context (identical to the common context).95*/96typedef sph_jh_context sph_jh224_context;9798/**99* Type for a JH-256 context (identical to the common context).100*/101typedef sph_jh_context sph_jh256_context;102103/**104* Type for a JH-384 context (identical to the common context).105*/106typedef sph_jh_context sph_jh384_context;107108/**109* Type for a JH-512 context (identical to the common context).110*/111typedef sph_jh_context sph_jh512_context;112113/**114* Initialize a JH-224 context. This process performs no memory allocation.115*116* @param cc the JH-224 context (pointer to a117* <code>sph_jh224_context</code>)118*/119void sph_jh224_init(void *cc);120121/**122* Process some data bytes. It is acceptable that <code>len</code> is zero123* (in which case this function does nothing).124*125* @param cc the JH-224 context126* @param data the input data127* @param len the input data length (in bytes)128*/129void sph_jh224(void *cc, const void *data, size_t len);130131/**132* Terminate the current JH-224 computation and output the result into133* the provided buffer. The destination buffer must be wide enough to134* accomodate the result (28 bytes). The context is automatically135* reinitialized.136*137* @param cc the JH-224 context138* @param dst the destination buffer139*/140void sph_jh224_close(void *cc, void *dst);141142/**143* Add a few additional bits (0 to 7) to the current computation, then144* terminate it and output the result in the provided buffer, which must145* be wide enough to accomodate the result (28 bytes). If bit number i146* in <code>ub</code> has value 2^i, then the extra bits are those147* numbered 7 downto 8-n (this is the big-endian convention at the byte148* level). The context is automatically reinitialized.149*150* @param cc the JH-224 context151* @param ub the extra bits152* @param n the number of extra bits (0 to 7)153* @param dst the destination buffer154*/155void sph_jh224_addbits_and_close(156void *cc, unsigned ub, unsigned n, void *dst);157158/**159* Initialize a JH-256 context. This process performs no memory allocation.160*161* @param cc the JH-256 context (pointer to a162* <code>sph_jh256_context</code>)163*/164void sph_jh256_init(void *cc);165166/**167* Process some data bytes. It is acceptable that <code>len</code> is zero168* (in which case this function does nothing).169*170* @param cc the JH-256 context171* @param data the input data172* @param len the input data length (in bytes)173*/174void sph_jh256(void *cc, const void *data, size_t len);175176/**177* Terminate the current JH-256 computation and output the result into178* the provided buffer. The destination buffer must be wide enough to179* accomodate the result (32 bytes). The context is automatically180* reinitialized.181*182* @param cc the JH-256 context183* @param dst the destination buffer184*/185void sph_jh256_close(void *cc, void *dst);186187/**188* Add a few additional bits (0 to 7) to the current computation, then189* terminate it and output the result in the provided buffer, which must190* be wide enough to accomodate the result (32 bytes). If bit number i191* in <code>ub</code> has value 2^i, then the extra bits are those192* numbered 7 downto 8-n (this is the big-endian convention at the byte193* level). The context is automatically reinitialized.194*195* @param cc the JH-256 context196* @param ub the extra bits197* @param n the number of extra bits (0 to 7)198* @param dst the destination buffer199*/200void sph_jh256_addbits_and_close(201void *cc, unsigned ub, unsigned n, void *dst);202203/**204* Initialize a JH-384 context. This process performs no memory allocation.205*206* @param cc the JH-384 context (pointer to a207* <code>sph_jh384_context</code>)208*/209void sph_jh384_init(void *cc);210211/**212* Process some data bytes. It is acceptable that <code>len</code> is zero213* (in which case this function does nothing).214*215* @param cc the JH-384 context216* @param data the input data217* @param len the input data length (in bytes)218*/219void sph_jh384(void *cc, const void *data, size_t len);220221/**222* Terminate the current JH-384 computation and output the result into223* the provided buffer. The destination buffer must be wide enough to224* accomodate the result (48 bytes). The context is automatically225* reinitialized.226*227* @param cc the JH-384 context228* @param dst the destination buffer229*/230void sph_jh384_close(void *cc, void *dst);231232/**233* Add a few additional bits (0 to 7) to the current computation, then234* terminate it and output the result in the provided buffer, which must235* be wide enough to accomodate the result (48 bytes). If bit number i236* in <code>ub</code> has value 2^i, then the extra bits are those237* numbered 7 downto 8-n (this is the big-endian convention at the byte238* level). The context is automatically reinitialized.239*240* @param cc the JH-384 context241* @param ub the extra bits242* @param n the number of extra bits (0 to 7)243* @param dst the destination buffer244*/245void sph_jh384_addbits_and_close(246void *cc, unsigned ub, unsigned n, void *dst);247248/**249* Initialize a JH-512 context. This process performs no memory allocation.250*251* @param cc the JH-512 context (pointer to a252* <code>sph_jh512_context</code>)253*/254void sph_jh512_init(void *cc);255256/**257* Process some data bytes. It is acceptable that <code>len</code> is zero258* (in which case this function does nothing).259*260* @param cc the JH-512 context261* @param data the input data262* @param len the input data length (in bytes)263*/264void sph_jh512(void *cc, const void *data, size_t len);265266/**267* Terminate the current JH-512 computation and output the result into268* the provided buffer. The destination buffer must be wide enough to269* accomodate the result (64 bytes). The context is automatically270* reinitialized.271*272* @param cc the JH-512 context273* @param dst the destination buffer274*/275void sph_jh512_close(void *cc, void *dst);276277/**278* Add a few additional bits (0 to 7) to the current computation, then279* terminate it and output the result in the provided buffer, which must280* be wide enough to accomodate the result (64 bytes). If bit number i281* in <code>ub</code> has value 2^i, then the extra bits are those282* numbered 7 downto 8-n (this is the big-endian convention at the byte283* level). The context is automatically reinitialized.284*285* @param cc the JH-512 context286* @param ub the extra bits287* @param n the number of extra bits (0 to 7)288* @param dst the destination buffer289*/290void sph_jh512_addbits_and_close(291void *cc, unsigned ub, unsigned n, void *dst);292293#ifdef __cplusplus294}295#endif296297#endif298299300