/* $Id: sph_tiger.h 216 2010-06-08 09:46:57Z tp $ */1/**2* Tiger / Tiger-2 interface.3*4* Tiger has been published in: R. Anderson, E. Biham, "Tiger: A Fast5* New Hash Function", Fast Software Encryption - FSE'96, LNCS 1039,6* Springer (1996), pp. 89--97.7*8* Tiger2 has never been formally published, but it was described as9* identical to Tiger, except for the padding which is the same in10* Tiger2 as it is in MD4. Fortunately, an implementation of Tiger211* was submitted to NESSIE, which produced test vectors; the sphlib12* implementation of Tiger2 is compatible with the NESSIE test vectors.13*14* ==========================(LICENSE BEGIN)============================15*16* Copyright (c) 2007-2010 Projet RNRT SAPHIR17*18* Permission is hereby granted, free of charge, to any person obtaining19* a copy of this software and associated documentation files (the20* "Software"), to deal in the Software without restriction, including21* without limitation the rights to use, copy, modify, merge, publish,22* distribute, sublicense, and/or sell copies of the Software, and to23* permit persons to whom the Software is furnished to do so, subject to24* the following conditions:25*26* The above copyright notice and this permission notice shall be27* included in all copies or substantial portions of the Software.28*29* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,30* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF31* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.32* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY33* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,34* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE35* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.36*37* ===========================(LICENSE END)=============================38*39* @file sph_tiger.h40* @author Thomas Pornin <[email protected]>41*/4243#ifndef SPH_TIGER_H__44#define SPH_TIGER_H__4546#include <stddef.h>47#include "sph_types.h"4849#if SPH_645051/**52* Output size (in bits) for Tiger.53*/54#define SPH_SIZE_tiger 1925556/**57* Output size (in bits) for Tiger2.58*/59#define SPH_SIZE_tiger2 1926061/**62* This structure is a context for Tiger computations: it contains the63* intermediate values and some data from the last entered block. Once64* a Tiger computation has been performed, the context can be reused for65* another computation.66*67* The contents of this structure are private. A running Tiger computation68* can be cloned by copying the context (e.g. with a simple69* <code>memcpy()</code>).70*/71typedef struct {72#ifndef DOXYGEN_IGNORE73unsigned char buf[64]; /* first field, for alignment */74sph_u64 val[3];75sph_u64 count;76#endif77} sph_tiger_context;7879/**80* Initialize a Tiger context. This process performs no memory allocation.81*82* @param cc the Tiger context (pointer to83* a <code>sph_tiger_context</code>)84*/85void sph_tiger_init(void *cc);8687/**88* Process some data bytes. It is acceptable that <code>len</code> is zero89* (in which case this function does nothing).90*91* @param cc the Tiger context92* @param data the input data93* @param len the input data length (in bytes)94*/95void sph_tiger(void *cc, const void *data, size_t len);9697/**98* Terminate the current Tiger computation and output the result into the99* provided buffer. The destination buffer must be wide enough to100* accomodate the result (24 bytes). The context is automatically101* reinitialized.102*103* @param cc the Tiger context104* @param dst the destination buffer105*/106void sph_tiger_close(void *cc, void *dst);107108/**109* Apply the Tiger compression function on the provided data. The110* <code>msg</code> parameter contains the 8 64-bit input blocks,111* as numerical values (hence after the little-endian decoding). The112* <code>val</code> parameter contains the 3 64-bit input blocks for113* the compression function; the output is written in place in this114* array.115*116* @param msg the message block (8 values)117* @param val the function 192-bit input and output118*/119void sph_tiger_comp(const sph_u64 msg[8], sph_u64 val[3]);120121/**122* This structure is a context for Tiger2 computations. It is identical123* to the Tiger context, and they may be freely exchanged, since the124* difference between Tiger and Tiger2 resides solely in the padding, which125* is computed only in the last computation step.126*/127typedef sph_tiger_context sph_tiger2_context;128129#ifdef DOXYGEN_IGNORE130/**131* Initialize a Tiger2 context. This function is identical to132* <code>sph_tiger_init()</code>.133*134* @param cc the Tiger2 context (pointer to135* a <code>sph_tiger2_context</code>)136*/137void sph_tiger2_init(void *cc);138#endif139140#ifndef DOXYGEN_IGNORE141#define sph_tiger2_init sph_tiger_init142#endif143144#ifdef DOXYGEN_IGNORE145/**146* Process some data bytes. This function is identical to147* <code>sph_tiger()</code>.148*149* @param cc the Tiger2 context150* @param data the input data151* @param len the input data length (in bytes)152*/153void sph_tiger2(void *cc, const void *data, size_t len);154#endif155156#ifndef DOXYGEN_IGNORE157#define sph_tiger2 sph_tiger158#endif159160/**161* Terminate the current Tiger2 computation and output the result into the162* provided buffer. The destination buffer must be wide enough to163* accomodate the result (24 bytes). The context is automatically164* reinitialized. Note that this function is NOT identical to165* <code>sph_tiger2_close()</code>: this is the exact and unique point166* where Tiger and Tiger2 differ.167*168* @param cc the Tiger context169* @param dst the destination buffer170*/171void sph_tiger2_close(void *cc, void *dst);172173#ifdef DOXYGEN_IGNORE174/**175* Apply the Tiger2 compression function, which is identical to the Tiger176* compression function.177*178* @param msg the message block (8 values)179* @param val the function 192-bit input and output180*/181void sph_tiger2_comp(const sph_u64 msg[8], sph_u64 val[3]);182#endif183184#ifndef DOXYGEN_IGNORE185#define sph_tiger2_comp sph_tiger_comp186#endif187188#endif189190#endif191192193