OpenVPN
siphash.c
Go to the documentation of this file.
1/*
2 * OpenVPN -- An application to securely tunnel IP networks
3 * over a single UDP port, with support for SSL/TLS-based
4 * session authentication and key exchange,
5 * packet encryption, packet authentication, and
6 * packet compression.
7 *
8 * Copyright (C) 2002-2026 OpenVPN Inc <sales@openvpn.net>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2
12 * as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, see <https://www.gnu.org/licenses/>.
21 */
22
23#ifdef HAVE_CONFIG_H
24#include "config.h"
25#endif
26
27#include <stdlib.h>
28#include "syshead.h"
29#include "siphash.h"
30#include "buffer.h"
31#include "crypto.h"
32#include "list.h"
33
34static_assert(SIPHASH_KEY_SIZE <= HASH_KEY_LEN, "hash map key size must be at least the same as siphash key size");
35
36uint64_t
37siphash_hash_func(const uint8_t *k, uint32_t length, const uint8_t hash_key[SIPHASH_KEY_SIZE])
38{
39 /* This is not endian-safe but we only care about local hashes here
40 * and reversing the byte does not make the hash functions any
41 * weaker or less usable */
42 union
43 {
44 uint8_t out[8];
45 uint64_t hash;
46 } ret;
47 siphash(k, length, hash_key, ret.out, sizeof(ret.out));
48 return ret.hash;
49}
Buffer management functions and garbage collection.
Data Channel Cryptography Module.
#define HASH_KEY_LEN
Definition list.h:53
uint64_t siphash_hash_func(const uint8_t *k, uint32_t length, const uint8_t hash_key[SIPHASH_KEY_SIZE])
Wrapper of the siphash function to be able to use it in the hash map.
Definition siphash.c:37
#define SIPHASH_KEY_SIZE
Definition siphash.h:35
static void siphash(const void *in, size_t inlen, const void *k, uint8_t *out, size_t outlen)
Definition siphash.h:70
Definition list.h:56