/*-1* Copyright (c) 2013 Andre Oppermann <[email protected]>2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12* 3. The name of the author may not be used to endorse or promote13* products derived from this software without specific prior written14* permission.15*16* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND17* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE18* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE19* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE20* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL21* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS22* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)23* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT24* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY25* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF26* SUCH DAMAGE.27*/2829/*30* SipHash is a family of pseudorandom functions (a.k.a. keyed hash functions)31* optimized for speed on short messages returning a 64bit hash/digest value.32*33* The number of rounds is defined during the initialization:34* SipHash24_Init() for the fast and resonable strong version35* SipHash48_Init() for the strong version (half as fast)36*37* struct SIPHASH_CTX ctx;38* SipHash24_Init(&ctx);39* SipHash_SetKey(&ctx, "16bytes long key");40* SipHash_Update(&ctx, pointer_to_string, length_of_string);41* SipHash_Final(output, &ctx);42*/4344#ifndef _SIPHASH_H_45#define _SIPHASH_H_4647#define SIPHASH_BLOCK_LENGTH 848#define SIPHASH_KEY_LENGTH 1649#define SIPHASH_DIGEST_LENGTH 85051typedef struct _SIPHASH_CTX {52uint64_t v[4];53union {54uint64_t b64;55uint8_t b8[8];56} buf;57uint64_t bytes;58uint8_t buflen;59uint8_t rounds_compr;60uint8_t rounds_final;61uint8_t initialized;62} SIPHASH_CTX;636465#define SipHash24_Init(x) SipHash_InitX((x), 2, 4)66#define SipHash48_Init(x) SipHash_InitX((x), 4, 8)67void SipHash_InitX(SIPHASH_CTX *, int, int);68void SipHash_SetKey(SIPHASH_CTX *,69const uint8_t[__min_size(SIPHASH_KEY_LENGTH)]);70void SipHash_Update(SIPHASH_CTX *, const void *, size_t);71void SipHash_Final(uint8_t[__min_size(SIPHASH_DIGEST_LENGTH)], SIPHASH_CTX *);72uint64_t SipHash_End(SIPHASH_CTX *);7374#define SipHash24(x, y, z, i) SipHashX((x), 2, 4, (y), (z), (i));75#define SipHash48(x, y, z, i) SipHashX((x), 4, 8, (y), (z), (i));76uint64_t SipHashX(SIPHASH_CTX *, int, int,77const uint8_t[__min_size(SIPHASH_KEY_LENGTH)], const void *, size_t);7879int SipHash24_TestVectors(void);8081#endif /* _SIPHASH_H_ */828384