File: hash.h

package info (click to toggle)
linux 6.19.2-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 1,759,612 kB
  • sloc: ansic: 27,004,852; asm: 273,402; sh: 151,313; python: 81,277; makefile: 58,544; perl: 34,311; xml: 21,064; cpp: 5,984; yacc: 4,841; lex: 2,901; awk: 1,707; sed: 30; ruby: 25
file content (47 lines) | stat: -rw-r--r-- 1,125 bytes parent folder | download | duplicates (2)
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
/* SPDX-License-Identifier: GPL-2.0-only */

#ifndef _SELINUX_HASH_H_
#define _SELINUX_HASH_H_

/*
 * Based on MurmurHash3, written by Austin Appleby and placed in the
 * public domain.
 */
static inline u32 av_hash(u32 key1, u32 key2, u32 key3, u32 mask)
{
	static const u32 c1 = 0xcc9e2d51;
	static const u32 c2 = 0x1b873593;
	static const u32 r1 = 15;
	static const u32 r2 = 13;
	static const u32 m = 5;
	static const u32 n = 0xe6546b64;

	u32 hash = 0;

#define mix(input)                                         \
	do {                                               \
		u32 v = input;                             \
		v *= c1;                                   \
		v = (v << r1) | (v >> (32 - r1));          \
		v *= c2;                                   \
		hash ^= v;                                 \
		hash = (hash << r2) | (hash >> (32 - r2)); \
		hash = hash * m + n;                       \
	} while (0)

	mix(key1);
	mix(key2);
	mix(key3);

#undef mix

	hash ^= hash >> 16;
	hash *= 0x85ebca6b;
	hash ^= hash >> 13;
	hash *= 0xc2b2ae35;
	hash ^= hash >> 16;

	return hash & mask;
}

#endif /* _SELINUX_HASH_H_ */