1 /* Copyright (C) 2016 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
3 * This file is provided under a dual BSD/GPLv2 license.
5 * SipHash: a fast short-input PRF
6 * https://131002.net/siphash/
8 * This implementation is specifically for SipHash2-4 for a secure PRF
9 * and HalfSipHash1-3/SipHash1-3 for an insecure PRF only suitable for
13 #ifndef _LINUX_SIPHASH_H
14 #define _LINUX_SIPHASH_H
21 #define SIPHASH_ALIGNMENT __alignof__(uint64_t)
26 static inline bool siphash_key_is_zero(const siphash_key_t
*key
)
28 return !(key
->key
[0] | key
->key
[1]);
31 uint64_t siphash(const void *data
, size_t len
, const siphash_key_t
*key
);
33 static inline void siphash_to_le64(void *dest
, const void *data
, size_t len
,
34 const siphash_key_t
*key
)
36 uint64_t hash
= siphash(data
, len
, key
);
38 *(uint64_t *)dest
= cpu_to_le64(hash
);
41 static inline void siphash_to_be64(void *dest
, const void *data
, size_t len
,
42 const siphash_key_t
*key
)
44 uint64_t hash
= siphash(data
, len
, key
);
46 *(uint64_t *)dest
= cpu_to_be64(hash
);
49 #endif /* _LINUX_SIPHASH_H */