summaryrefslogtreecommitdiff
path: root/cookie.c
blob: 9ee1ac6aebc5cc2f9a46482f095c249ee2dbfb8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <syslog.h>

#include "cookie.h"

static char const *priov[] = {
	[LOG_EMERG]	=	"EMERG:",
	[LOG_ALERT]	=	"ALERT:",
	[LOG_CRIT]	=	"CRIT:",
	[LOG_ERR]	=	"ERR:",
	[LOG_WARNING]	=	"WARNING:",
	[LOG_NOTICE]	=	"NOTICE:",
	[LOG_INFO]	=	"INFO:",
	[LOG_DEBUG]	=	"DEBUG:",
};

static ssize_t cookie_writer(void *cookie, char const *data, size_t leng)
{
	int prio = LOG_DEBUG, len;

	do {
		len = strlen(priov[prio]);
	} while (memcmp(data, priov[prio], len) && --prio >= 0);

	if (prio < 0) {
		prio = LOG_INFO;
	} else {
		data += len;
		leng -= len;
	}

	while (*data == ' ') {
		 ++data;
		--leng;
	}

	syslog(prio, "%.*s", (int) leng, data);

	return leng;
}

static cookie_io_functions_t cookie_log = {
	.write		=	cookie_writer,
};

void to_std_log(FILE **fp)
{
	setvbuf(*fp = fopencookie(NULL, "w", cookie_log), NULL, _IOLBF, 0);
}
a1001b70d52e1&id2=2c956a60778cbb6a27e0c7a8a52a91378c90e1d1'>diff)
siphash: implement HalfSipHash1-3 for hash tables
HalfSipHash, or hsiphash, is a shortened version of SipHash, which generates 32-bit outputs using a weaker 64-bit key. It has *much* lower security margins, and shouldn't be used for anything too sensitive, but it could be used as a hashtable key function replacement, if the output is never exposed, and if the security requirement is not too high. The goal is to make this something that performance-critical jhash users would be willing to use. On 64-bit machines, HalfSipHash1-3 is slower than SipHash1-3, so we alias SipHash1-3 to HalfSipHash1-3 on those systems. 64-bit x86_64: [ 0.509409] test_siphash: SipHash2-4 cycles: 4049181 [ 0.510650] test_siphash: SipHash1-3 cycles: 2512884 [ 0.512205] test_siphash: HalfSipHash1-3 cycles: 3429920 [ 0.512904] test_siphash: JenkinsHash cycles: 978267 So, we map hsiphash() -> SipHash1-3 32-bit x86: [ 0.509868] test_siphash: SipHash2-4 cycles: 14812892 [ 0.513601] test_siphash: SipHash1-3 cycles: 9510710 [ 0.515263] test_siphash: HalfSipHash1-3 cycles: 3856157 [ 0.515952] test_siphash: JenkinsHash cycles: 1148567 So, we map hsiphash() -> HalfSipHash1-3 hsiphash() is roughly 3 times slower than jhash(), but comes with a considerable security improvement. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com> Reviewed-by: Jean-Philippe Aumasson <jeanphilippe.aumasson@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'Documentation')