/* $Id: sph_bmw.h 216 2010-06-08 09:46:57Z tp $ */1/**2* BMW interface. BMW (aka "Blue Midnight Wish") is a family of3* functions which differ by their output size; this implementation4* defines BMW for output 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_bmw.h32* @author Thomas Pornin <[email protected]>33*/3435#ifndef SPH_BMW_H__36#define SPH_BMW_H__3738#ifdef __cplusplus39extern "C"{40#endif4142#include <stddef.h>43#include "sph_types.h"4445/**46* Output size (in bits) for BMW-224.47*/48#define SPH_SIZE_bmw224 2244950/**51* Output size (in bits) for BMW-256.52*/53#define SPH_SIZE_bmw256 2565455#if SPH_645657/**58* Output size (in bits) for BMW-384.59*/60#define SPH_SIZE_bmw384 3846162/**63* Output size (in bits) for BMW-512.64*/65#define SPH_SIZE_bmw512 5126667#endif6869/**70* This structure is a context for BMW-224 and BMW-256 computations:71* it contains the intermediate values and some data from the last72* entered block. Once a BMW computation has been performed, the73* context can be reused for another computation.74*75* The contents of this structure are private. A running BMW76* computation can be cloned by copying the context (e.g. with a simple77* <code>memcpy()</code>).78*/79typedef struct {80#ifndef DOXYGEN_IGNORE81unsigned char buf[64]; /* first field, for alignment */82size_t ptr;83sph_u32 H[16];84#if SPH_6485sph_u64 bit_count;86#else87sph_u32 bit_count_high, bit_count_low;88#endif89#endif90} sph_bmw_small_context;9192/**93* This structure is a context for BMW-224 computations. It is94* identical to the common <code>sph_bmw_small_context</code>.95*/96typedef sph_bmw_small_context sph_bmw224_context;9798/**99* This structure is a context for BMW-256 computations. It is100* identical to the common <code>sph_bmw_small_context</code>.101*/102typedef sph_bmw_small_context sph_bmw256_context;103104#if SPH_64105106/**107* This structure is a context for BMW-384 and BMW-512 computations:108* it contains the intermediate values and some data from the last109* entered block. Once a BMW computation has been performed, the110* context can be reused for another computation.111*112* The contents of this structure are private. A running BMW113* computation can be cloned by copying the context (e.g. with a simple114* <code>memcpy()</code>).115*/116typedef struct {117#ifndef DOXYGEN_IGNORE118unsigned char buf[128]; /* first field, for alignment */119size_t ptr;120sph_u64 H[16];121sph_u64 bit_count;122#endif123} sph_bmw_big_context;124125/**126* This structure is a context for BMW-384 computations. It is127* identical to the common <code>sph_bmw_small_context</code>.128*/129typedef sph_bmw_big_context sph_bmw384_context;130131/**132* This structure is a context for BMW-512 computations. It is133* identical to the common <code>sph_bmw_small_context</code>.134*/135typedef sph_bmw_big_context sph_bmw512_context;136137#endif138139/**140* Initialize a BMW-224 context. This process performs no memory allocation.141*142* @param cc the BMW-224 context (pointer to a143* <code>sph_bmw224_context</code>)144*/145void sph_bmw224_init(void *cc);146147/**148* Process some data bytes. It is acceptable that <code>len</code> is zero149* (in which case this function does nothing).150*151* @param cc the BMW-224 context152* @param data the input data153* @param len the input data length (in bytes)154*/155void sph_bmw224(void *cc, const void *data, size_t len);156157/**158* Terminate the current BMW-224 computation and output the result into159* the provided buffer. The destination buffer must be wide enough to160* accomodate the result (28 bytes). The context is automatically161* reinitialized.162*163* @param cc the BMW-224 context164* @param dst the destination buffer165*/166void sph_bmw224_close(void *cc, void *dst);167168/**169* Add a few additional bits (0 to 7) to the current computation, then170* terminate it and output the result in the provided buffer, which must171* be wide enough to accomodate the result (28 bytes). If bit number i172* in <code>ub</code> has value 2^i, then the extra bits are those173* numbered 7 downto 8-n (this is the big-endian convention at the byte174* level). The context is automatically reinitialized.175*176* @param cc the BMW-224 context177* @param ub the extra bits178* @param n the number of extra bits (0 to 7)179* @param dst the destination buffer180*/181void sph_bmw224_addbits_and_close(182void *cc, unsigned ub, unsigned n, void *dst);183184/**185* Initialize a BMW-256 context. This process performs no memory allocation.186*187* @param cc the BMW-256 context (pointer to a188* <code>sph_bmw256_context</code>)189*/190void sph_bmw256_init(void *cc);191192/**193* Process some data bytes. It is acceptable that <code>len</code> is zero194* (in which case this function does nothing).195*196* @param cc the BMW-256 context197* @param data the input data198* @param len the input data length (in bytes)199*/200void sph_bmw256(void *cc, const void *data, size_t len);201202/**203* Terminate the current BMW-256 computation and output the result into204* the provided buffer. The destination buffer must be wide enough to205* accomodate the result (32 bytes). The context is automatically206* reinitialized.207*208* @param cc the BMW-256 context209* @param dst the destination buffer210*/211void sph_bmw256_close(void *cc, void *dst);212213/**214* Add a few additional bits (0 to 7) to the current computation, then215* terminate it and output the result in the provided buffer, which must216* be wide enough to accomodate the result (32 bytes). If bit number i217* in <code>ub</code> has value 2^i, then the extra bits are those218* numbered 7 downto 8-n (this is the big-endian convention at the byte219* level). The context is automatically reinitialized.220*221* @param cc the BMW-256 context222* @param ub the extra bits223* @param n the number of extra bits (0 to 7)224* @param dst the destination buffer225*/226void sph_bmw256_addbits_and_close(227void *cc, unsigned ub, unsigned n, void *dst);228229#if SPH_64230231/**232* Initialize a BMW-384 context. This process performs no memory allocation.233*234* @param cc the BMW-384 context (pointer to a235* <code>sph_bmw384_context</code>)236*/237void sph_bmw384_init(void *cc);238239/**240* Process some data bytes. It is acceptable that <code>len</code> is zero241* (in which case this function does nothing).242*243* @param cc the BMW-384 context244* @param data the input data245* @param len the input data length (in bytes)246*/247void sph_bmw384(void *cc, const void *data, size_t len);248249/**250* Terminate the current BMW-384 computation and output the result into251* the provided buffer. The destination buffer must be wide enough to252* accomodate the result (48 bytes). The context is automatically253* reinitialized.254*255* @param cc the BMW-384 context256* @param dst the destination buffer257*/258void sph_bmw384_close(void *cc, void *dst);259260/**261* Add a few additional bits (0 to 7) to the current computation, then262* terminate it and output the result in the provided buffer, which must263* be wide enough to accomodate the result (48 bytes). If bit number i264* in <code>ub</code> has value 2^i, then the extra bits are those265* numbered 7 downto 8-n (this is the big-endian convention at the byte266* level). The context is automatically reinitialized.267*268* @param cc the BMW-384 context269* @param ub the extra bits270* @param n the number of extra bits (0 to 7)271* @param dst the destination buffer272*/273void sph_bmw384_addbits_and_close(274void *cc, unsigned ub, unsigned n, void *dst);275276/**277* Initialize a BMW-512 context. This process performs no memory allocation.278*279* @param cc the BMW-512 context (pointer to a280* <code>sph_bmw512_context</code>)281*/282void sph_bmw512_init(void *cc);283284/**285* Process some data bytes. It is acceptable that <code>len</code> is zero286* (in which case this function does nothing).287*288* @param cc the BMW-512 context289* @param data the input data290* @param len the input data length (in bytes)291*/292void sph_bmw512(void *cc, const void *data, size_t len);293294/**295* Terminate the current BMW-512 computation and output the result into296* the provided buffer. The destination buffer must be wide enough to297* accomodate the result (64 bytes). The context is automatically298* reinitialized.299*300* @param cc the BMW-512 context301* @param dst the destination buffer302*/303void sph_bmw512_close(void *cc, void *dst);304305/**306* Add a few additional bits (0 to 7) to the current computation, then307* terminate it and output the result in the provided buffer, which must308* be wide enough to accomodate the result (64 bytes). If bit number i309* in <code>ub</code> has value 2^i, then the extra bits are those310* numbered 7 downto 8-n (this is the big-endian convention at the byte311* level). The context is automatically reinitialized.312*313* @param cc the BMW-512 context314* @param ub the extra bits315* @param n the number of extra bits (0 to 7)316* @param dst the destination buffer317*/318void sph_bmw512_addbits_and_close(319void *cc, unsigned ub, unsigned n, void *dst);320321#endif322323#ifdef __cplusplus324}325#endif326327#endif328329330