2 * SipHash reference C implementation
4 * Copyright (c) 2016 Jean-Philippe Aumasson <jeanphilippe.aumasson@gmail.com>
6 * To the extent possible under law, the author(s) have dedicated all copyright
7 * and related and neighboring rights to this software to the public domain
8 * worldwide. This software is distributed without any warranty.
10 * You should have received a copy of the CC0 Public Domain Dedication along
11 * with this software. If not, see
12 * <http://creativecommons.org/publicdomain/zero/1.0/>.
22 /* The below siphash logic is taken from the source
23 * https://github.com/veorq/SipHash
30 #include <rte_debug.h>
32 #define STATE_V2 0x6c796765
33 #define STATE_V3 0x74656462
35 #define ROTL(x, b) (uint32_t)(((x) << (b)) | ((x) >> (32 - (b))))
38 * Siphash hash functionality logically divided into different
39 * phases and the functions are named based on the same.
40 * SipHash-2-4 is used i.e: 2 compression rounds and 4 finalization rounds.
43 sipround(rte_xmm_t *v)
45 v->u32[0] += v->u32[1];
46 v->u32[1] = ROTL(v->u32[1], 5);
47 v->u32[1] ^= v->u32[0];
48 v->u32[0] = ROTL(v->u32[0], 16);
49 v->u32[2] += v->u32[3];
50 v->u32[3] = ROTL(v->u32[3], 8);
51 v->u32[3] ^= v->u32[2];
52 v->u32[0] += v->u32[3];
53 v->u32[3] = ROTL(v->u32[3], 7);
54 v->u32[3] ^= v->u32[0];
55 v->u32[2] += v->u32[1];
56 v->u32[1] = ROTL(v->u32[1], 13);
57 v->u32[1] ^= v->u32[2];
58 v->u32[2] = ROTL(v->u32[2], 16);
62 siphash_initialization(rte_xmm_t *v, const rte_xmm_t *k)
64 uint32_t k0 = k->u32[0];
65 uint32_t k1 = k->u32[1];
69 v->u32[2] = STATE_V2 ^ k0;
70 v->u32[3] = STATE_V3 ^ k1;
74 siphash_compression(const uint32_t *in, size_t len, rte_xmm_t *v)
78 for (i = 0; i < len; i++) {
87 siphash_finalization(rte_xmm_t *v)
100 #endif /* __SIPHASH__ */