(125 lines)
1 // This file holds the internals for the SipHash implementation. For a few2 // cases, we want to include this for incrementally computing hashes.3 // Otherwise, it suffices to just use the siphash24() function from siphash.h13 /* <MIT License>14 Copyright (c) 2013 Marek Majkowski <marek@popcount.org>15 Copyright (c) 2018 Samantha McVey <samantham@posteo.net>16 Copyright (c) 2024 Bruce Hill <bruce@bruce-hill.com>18 Permission is hereby granted, free of charge, to any person obtaining a copy19 of this software and associated documentation files (the "Software"), to deal20 in the Software without restriction, including without limitation the rights21 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell22 copies of the Software, and to permit persons to whom the Software is23 furnished to do so, subject to the following conditions:25 The above copyright notice and this permission notice shall be included in26 all copies or substantial portions of the Software.28 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR29 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,30 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE31 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER32 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,33 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN34 THE SOFTWARE.35 </MIT License>37 Original location:38 https://github.com/majek/csiphash/40 Original solution inspired by code from:41 Samuel Neves (supercop/crypto_auth/siphash24/little)42 djb (supercop/crypto_auth/siphash24/little2)43 Jean-Philippe Aumasson (https://131002.net/siphash/siphash24.c)45 Extensive modifications for MoarVM by Samantha McVey47 Further modifications for Tomo by Bruce Hill48 */50 uint64_t v0;51 uint64_t v1;52 uint64_t v2;53 uint64_t v3;54 uint64_t b;55 };60 a += b; \61 c += d; \80 }83 sh->v3 ^= mi;85 sh->v0 ^= mi;86 }88 sh->b |= t;89 sh->v3 ^= sh->b;91 sh->v0 ^= sh->b;96 }97 /* This union helps us avoid doing weird things with pointers that can cause old98 * compilers like GCC 4 to generate bad code. In addition it is nicely more C99 * standards compliant to keep type punning to a minimum. */101 uint64_t u64;102 uint32_t u32;104 };123 }125 }