aboutgitcodebugslistschat
path: root/siphash.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2023-09-28 11:21:02 +1000
committerStefano Brivio <sbrivio@redhat.com>2023-09-30 12:40:53 +0200
commitfc8f0f8c48ef12edbf60f74f37024917f5812385 (patch)
tree470cc57b733611a8447b725635fa5d9e18b7315d /siphash.c
parent04b10a8d907d8ceb09e3adb4885c02f546841bbc (diff)
downloadpasst-fc8f0f8c48ef12edbf60f74f37024917f5812385.tar
passt-fc8f0f8c48ef12edbf60f74f37024917f5812385.tar.gz
passt-fc8f0f8c48ef12edbf60f74f37024917f5812385.tar.bz2
passt-fc8f0f8c48ef12edbf60f74f37024917f5812385.tar.lz
passt-fc8f0f8c48ef12edbf60f74f37024917f5812385.tar.xz
passt-fc8f0f8c48ef12edbf60f74f37024917f5812385.tar.zst
passt-fc8f0f8c48ef12edbf60f74f37024917f5812385.zip
siphash: Use incremental rather than all-at-once siphash functions
We have a bunch of variants of the siphash functions for different data sizes. The callers, in tcp.c, need to pack the various values they want to hash into a temporary structure, then call the appropriate version. We can avoid the copy into the temporary by directly using the incremental siphash functions. The length specific hash functions also have an undocumented constraint that the data pointer they take must, in fact, be aligned to avoid unaligned accesses, which may cause crashes on some architectures. So, prefer the incremental approach and remove the length-specific functions. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'siphash.c')
-rw-r--r--siphash.c121
1 files changed, 0 insertions, 121 deletions
diff --git a/siphash.c b/siphash.c
deleted file mode 100644
index d2b068c..0000000
--- a/siphash.c
+++ /dev/null
@@ -1,121 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-
-/* PASST - Plug A Simple Socket Transport
- * for qemu/UNIX domain socket mode
- *
- * PASTA - Pack A Subtle Tap Abstraction
- * for network namespace/tap device mode
- *
- * siphash.c - SipHash routines
- *
- * Copyright (c) 2020-2021 Red Hat GmbH
- * Author: Stefano Brivio <sbrivio@redhat.com>
- */
-
-#include <stddef.h>
-#include <stdint.h>
-
-#include "siphash.h"
-
-/**
- * siphash_8b() - Table index or timestamp offset for TCP over IPv4 (8 bytes in)
- * @in: Input data (remote address and two ports, or two addresses)
- * @k: Hash function key, 128 bits
- *
- * Return: the 64-bit hash output
- */
-/* NOLINTNEXTLINE(clang-diagnostic-unknown-attributes) */
-__attribute__((optimize("-fno-strict-aliasing"))) /* See csum_16b() */
-/* cppcheck-suppress unusedFunction */
-uint64_t siphash_8b(const uint8_t *in, const uint64_t *k)
-{
- struct siphash_state state = SIPHASH_INIT(k);
-
- siphash_feed(&state, *(uint64_t *)in);
-
- return siphash_final(&state, 8, 0);
-}
-
-/**
- * siphash_12b() - Initial sequence number for TCP over IPv4 (12 bytes in)
- * @in: Input data (two addresses, two ports)
- * @k: Hash function key, 128 bits
- *
- * Return: the 64-bit hash output
- */
-/* NOLINTNEXTLINE(clang-diagnostic-unknown-attributes) */
-__attribute__((optimize("-fno-strict-aliasing"))) /* See csum_16b() */
-/* cppcheck-suppress unusedFunction */
-uint64_t siphash_12b(const uint8_t *in, const uint64_t *k)
-{
- struct siphash_state state = SIPHASH_INIT(k);
- uint32_t *in32 = (uint32_t *)in;
-
- siphash_feed(&state, (uint64_t)(*(in32 + 1)) << 32 | *in32);
-
- return siphash_final(&state, 12, *(in32 + 2));
-}
-
-/**
- * siphash_20b() - Table index for TCP over IPv6 (20 bytes in)
- * @in: Input data (remote address, two ports)
- * @k: Hash function key, 128 bits
- *
- * Return: the 64-bit hash output
- */
-/* NOLINTNEXTLINE(clang-diagnostic-unknown-attributes) */
-__attribute__((optimize("-fno-strict-aliasing"))) /* See csum_16b() */
-uint64_t siphash_20b(const uint8_t *in, const uint64_t *k)
-{
- struct siphash_state state = SIPHASH_INIT(k);
- uint32_t *in32 = (uint32_t *)in;
- int i;
-
- for (i = 0; i < 2; i++, in32 += 2)
- siphash_feed(&state, (uint64_t)(*(in32 + 1)) << 32 | *in32);
-
- return siphash_final(&state, 20, *in32);
-}
-
-/**
- * siphash_32b() - Timestamp offset for TCP over IPv6 (32 bytes in)
- * @in: Input data (two addresses)
- * @k: Hash function key, 128 bits
- *
- * Return: the 64-bit hash output
- */
-/* NOLINTNEXTLINE(clang-diagnostic-unknown-attributes) */
-__attribute__((optimize("-fno-strict-aliasing"))) /* See csum_16b() */
-/* cppcheck-suppress unusedFunction */
-uint64_t siphash_32b(const uint8_t *in, const uint64_t *k)
-{
- struct siphash_state state = SIPHASH_INIT(k);
- uint64_t *in64 = (uint64_t *)in;
- int i;
-
- for (i = 0; i < 4; i++, in64++)
- siphash_feed(&state, *in64);
-
- return siphash_final(&state, 32, 0);
-}
-
-/**
- * siphash_36b() - Initial sequence number for TCP over IPv6 (36 bytes in)
- * @in: Input data (two addresses, two ports)
- * @k: Hash function key, 128 bits
- *
- * Return: the 64-bit hash output
- */
-/* NOLINTNEXTLINE(clang-diagnostic-unknown-attributes) */
-__attribute__((optimize("-fno-strict-aliasing"))) /* See csum_16b() */
-uint64_t siphash_36b(const uint8_t *in, const uint64_t *k)
-{
- struct siphash_state state = SIPHASH_INIT(k);
- uint32_t *in32 = (uint32_t *)in;
- int i;
-
- for (i = 0; i < 4; i++, in32 += 2)
- siphash_feed(&state, (uint64_t)(*(in32 + 1)) << 32 | *in32);
-
- return siphash_final(&state, 36, *in32);
-}