File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ /* SPDX-License-Identifier: GPL-2.0-only */
2+
3+ #ifndef _SELINUX_HASH_H_
4+ #define _SELINUX_HASH_H_
5+
6+ /* Based on MurmurHash3, written by Austin Appleby and placed in the
7+ * public domain.
8+ */
9+ static inline u32 avtab_hash (const struct avtab_key * keyp , u32 mask )
10+ {
11+ static const u32 c1 = 0xcc9e2d51 ;
12+ static const u32 c2 = 0x1b873593 ;
13+ static const u32 r1 = 15 ;
14+ static const u32 r2 = 13 ;
15+ static const u32 m = 5 ;
16+ static const u32 n = 0xe6546b64 ;
17+
18+ u32 hash = 0 ;
19+
20+ #define mix (input ) \
21+ do { \
22+ u32 v = input; \
23+ v *= c1; \
24+ v = (v << r1) | (v >> (32 - r1)); \
25+ v *= c2; \
26+ hash ^= v; \
27+ hash = (hash << r2) | (hash >> (32 - r2)); \
28+ hash = hash * m + n; \
29+ } while (0)
30+
31+ mix (keyp -> target_class );
32+ mix (keyp -> target_type );
33+ mix (keyp -> source_type );
34+
35+ #undef mix
36+
37+ hash ^= hash >> 16 ;
38+ hash *= 0x85ebca6b ;
39+ hash ^= hash >> 13 ;
40+ hash *= 0xc2b2ae35 ;
41+ hash ^= hash >> 16 ;
42+
43+ return hash & mask ;
44+ }
45+
46+ #endif /* _SELINUX_HASH_H_ */
Original file line number Diff line number Diff line change 2020#include <linux/errno.h>
2121#include "avtab.h"
2222#include "policydb.h"
23+ #include "hash.h"
2324
2425static struct kmem_cache * avtab_node_cachep __ro_after_init ;
2526static struct kmem_cache * avtab_xperms_cachep __ro_after_init ;
2627
27- /* Based on MurmurHash3, written by Austin Appleby and placed in the
28- * public domain.
29- */
30- static inline u32 avtab_hash (const struct avtab_key * keyp , u32 mask )
31- {
32- static const u32 c1 = 0xcc9e2d51 ;
33- static const u32 c2 = 0x1b873593 ;
34- static const u32 r1 = 15 ;
35- static const u32 r2 = 13 ;
36- static const u32 m = 5 ;
37- static const u32 n = 0xe6546b64 ;
38-
39- u32 hash = 0 ;
40-
41- #define mix (input ) \
42- do { \
43- u32 v = input; \
44- v *= c1; \
45- v = (v << r1) | (v >> (32 - r1)); \
46- v *= c2; \
47- hash ^= v; \
48- hash = (hash << r2) | (hash >> (32 - r2)); \
49- hash = hash * m + n; \
50- } while (0)
51-
52- mix (keyp -> target_class );
53- mix (keyp -> target_type );
54- mix (keyp -> source_type );
55-
56- #undef mix
57-
58- hash ^= hash >> 16 ;
59- hash *= 0x85ebca6b ;
60- hash ^= hash >> 13 ;
61- hash *= 0xc2b2ae35 ;
62- hash ^= hash >> 16 ;
63-
64- return hash & mask ;
65- }
66-
6728static struct avtab_node * avtab_insert_node (struct avtab * h ,
6829 struct avtab_node * * dst ,
6930 const struct avtab_key * key ,
You can’t perform that action at this time.
0 commit comments