~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/siphash.h

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /include/linux/siphash.h (Version linux-6.12-rc7) and /include/linux/siphash.h (Version linux-4.16.18)


  1 /* SPDX-License-Identifier: (GPL-2.0-only OR B !!   1 /* Copyright (C) 2016 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
  2 /* Copyright (C) 2016-2022 Jason A. Donenfeld  !!   2  *
                                                   >>   3  * This file is provided under a dual BSD/GPLv2 license.
  3  *                                                  4  *
  4  * SipHash: a fast short-input PRF                  5  * SipHash: a fast short-input PRF
  5  * https://131002.net/siphash/                      6  * https://131002.net/siphash/
  6  *                                                  7  *
  7  * This implementation is specifically for Sip      8  * This implementation is specifically for SipHash2-4 for a secure PRF
  8  * and HalfSipHash1-3/SipHash1-3 for an insecu      9  * and HalfSipHash1-3/SipHash1-3 for an insecure PRF only suitable for
  9  * hashtables.                                     10  * hashtables.
 10  */                                                11  */
 11                                                    12 
 12 #ifndef _LINUX_SIPHASH_H                           13 #ifndef _LINUX_SIPHASH_H
 13 #define _LINUX_SIPHASH_H                           14 #define _LINUX_SIPHASH_H
 14                                                    15 
 15 #include <linux/types.h>                           16 #include <linux/types.h>
 16 #include <linux/kernel.h>                          17 #include <linux/kernel.h>
 17                                                    18 
 18 #define SIPHASH_ALIGNMENT __alignof__(u64)         19 #define SIPHASH_ALIGNMENT __alignof__(u64)
 19 typedef struct {                                   20 typedef struct {
 20         u64 key[2];                                21         u64 key[2];
 21 } siphash_key_t;                                   22 } siphash_key_t;
 22                                                    23 
 23 #define siphash_aligned_key_t siphash_key_t __ << 
 24                                                << 
 25 static inline bool siphash_key_is_zero(const s << 
 26 {                                              << 
 27         return !(key->key[0] | key->key[1]);   << 
 28 }                                              << 
 29                                                << 
 30 u64 __siphash_aligned(const void *data, size_t     24 u64 __siphash_aligned(const void *data, size_t len, const siphash_key_t *key);
                                                   >>  25 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
 31 u64 __siphash_unaligned(const void *data, size     26 u64 __siphash_unaligned(const void *data, size_t len, const siphash_key_t *key);
                                                   >>  27 #endif
 32                                                    28 
 33 u64 siphash_1u64(const u64 a, const siphash_ke     29 u64 siphash_1u64(const u64 a, const siphash_key_t *key);
 34 u64 siphash_2u64(const u64 a, const u64 b, con     30 u64 siphash_2u64(const u64 a, const u64 b, const siphash_key_t *key);
 35 u64 siphash_3u64(const u64 a, const u64 b, con     31 u64 siphash_3u64(const u64 a, const u64 b, const u64 c,
 36                  const siphash_key_t *key);        32                  const siphash_key_t *key);
 37 u64 siphash_4u64(const u64 a, const u64 b, con     33 u64 siphash_4u64(const u64 a, const u64 b, const u64 c, const u64 d,
 38                  const siphash_key_t *key);        34                  const siphash_key_t *key);
 39 u64 siphash_1u32(const u32 a, const siphash_ke     35 u64 siphash_1u32(const u32 a, const siphash_key_t *key);
 40 u64 siphash_3u32(const u32 a, const u32 b, con     36 u64 siphash_3u32(const u32 a, const u32 b, const u32 c,
 41                  const siphash_key_t *key);        37                  const siphash_key_t *key);
 42                                                    38 
 43 static inline u64 siphash_2u32(const u32 a, co     39 static inline u64 siphash_2u32(const u32 a, const u32 b,
 44                                const siphash_k     40                                const siphash_key_t *key)
 45 {                                                  41 {
 46         return siphash_1u64((u64)b << 32 | a,      42         return siphash_1u64((u64)b << 32 | a, key);
 47 }                                                  43 }
 48 static inline u64 siphash_4u32(const u32 a, co     44 static inline u64 siphash_4u32(const u32 a, const u32 b, const u32 c,
 49                                const u32 d, co     45                                const u32 d, const siphash_key_t *key)
 50 {                                                  46 {
 51         return siphash_2u64((u64)b << 32 | a,      47         return siphash_2u64((u64)b << 32 | a, (u64)d << 32 | c, key);
 52 }                                                  48 }
 53                                                    49 
 54                                                    50 
 55 static inline u64 ___siphash_aligned(const __l     51 static inline u64 ___siphash_aligned(const __le64 *data, size_t len,
 56                                      const sip     52                                      const siphash_key_t *key)
 57 {                                                  53 {
 58         if (__builtin_constant_p(len) && len =     54         if (__builtin_constant_p(len) && len == 4)
 59                 return siphash_1u32(le32_to_cp     55                 return siphash_1u32(le32_to_cpup((const __le32 *)data), key);
 60         if (__builtin_constant_p(len) && len =     56         if (__builtin_constant_p(len) && len == 8)
 61                 return siphash_1u64(le64_to_cp     57                 return siphash_1u64(le64_to_cpu(data[0]), key);
 62         if (__builtin_constant_p(len) && len =     58         if (__builtin_constant_p(len) && len == 16)
 63                 return siphash_2u64(le64_to_cp     59                 return siphash_2u64(le64_to_cpu(data[0]), le64_to_cpu(data[1]),
 64                                     key);          60                                     key);
 65         if (__builtin_constant_p(len) && len =     61         if (__builtin_constant_p(len) && len == 24)
 66                 return siphash_3u64(le64_to_cp     62                 return siphash_3u64(le64_to_cpu(data[0]), le64_to_cpu(data[1]),
 67                                     le64_to_cp     63                                     le64_to_cpu(data[2]), key);
 68         if (__builtin_constant_p(len) && len =     64         if (__builtin_constant_p(len) && len == 32)
 69                 return siphash_4u64(le64_to_cp     65                 return siphash_4u64(le64_to_cpu(data[0]), le64_to_cpu(data[1]),
 70                                     le64_to_cp     66                                     le64_to_cpu(data[2]), le64_to_cpu(data[3]),
 71                                     key);          67                                     key);
 72         return __siphash_aligned(data, len, ke     68         return __siphash_aligned(data, len, key);
 73 }                                                  69 }
 74                                                    70 
 75 /**                                                71 /**
 76  * siphash - compute 64-bit siphash PRF value      72  * siphash - compute 64-bit siphash PRF value
 77  * @data: buffer to hash                           73  * @data: buffer to hash
 78  * @size: size of @data                            74  * @size: size of @data
 79  * @key: the siphash key                           75  * @key: the siphash key
 80  */                                                76  */
 81 static inline u64 siphash(const void *data, si     77 static inline u64 siphash(const void *data, size_t len,
 82                           const siphash_key_t      78                           const siphash_key_t *key)
 83 {                                                  79 {
 84         if (IS_ENABLED(CONFIG_HAVE_EFFICIENT_U !!  80 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
 85             !IS_ALIGNED((unsigned long)data, S !!  81         if (!IS_ALIGNED((unsigned long)data, SIPHASH_ALIGNMENT))
 86                 return __siphash_unaligned(dat     82                 return __siphash_unaligned(data, len, key);
                                                   >>  83 #endif
 87         return ___siphash_aligned(data, len, k     84         return ___siphash_aligned(data, len, key);
 88 }                                                  85 }
 89                                                    86 
 90 #define HSIPHASH_ALIGNMENT __alignof__(unsigne     87 #define HSIPHASH_ALIGNMENT __alignof__(unsigned long)
 91 typedef struct {                                   88 typedef struct {
 92         unsigned long key[2];                      89         unsigned long key[2];
 93 } hsiphash_key_t;                                  90 } hsiphash_key_t;
 94                                                    91 
 95 u32 __hsiphash_aligned(const void *data, size_     92 u32 __hsiphash_aligned(const void *data, size_t len,
 96                        const hsiphash_key_t *k     93                        const hsiphash_key_t *key);
                                                   >>  94 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
 97 u32 __hsiphash_unaligned(const void *data, siz     95 u32 __hsiphash_unaligned(const void *data, size_t len,
 98                          const hsiphash_key_t      96                          const hsiphash_key_t *key);
                                                   >>  97 #endif
 99                                                    98 
100 u32 hsiphash_1u32(const u32 a, const hsiphash_     99 u32 hsiphash_1u32(const u32 a, const hsiphash_key_t *key);
101 u32 hsiphash_2u32(const u32 a, const u32 b, co    100 u32 hsiphash_2u32(const u32 a, const u32 b, const hsiphash_key_t *key);
102 u32 hsiphash_3u32(const u32 a, const u32 b, co    101 u32 hsiphash_3u32(const u32 a, const u32 b, const u32 c,
103                   const hsiphash_key_t *key);     102                   const hsiphash_key_t *key);
104 u32 hsiphash_4u32(const u32 a, const u32 b, co    103 u32 hsiphash_4u32(const u32 a, const u32 b, const u32 c, const u32 d,
105                   const hsiphash_key_t *key);     104                   const hsiphash_key_t *key);
106                                                   105 
107 static inline u32 ___hsiphash_aligned(const __    106 static inline u32 ___hsiphash_aligned(const __le32 *data, size_t len,
108                                       const hs    107                                       const hsiphash_key_t *key)
109 {                                                 108 {
110         if (__builtin_constant_p(len) && len =    109         if (__builtin_constant_p(len) && len == 4)
111                 return hsiphash_1u32(le32_to_c    110                 return hsiphash_1u32(le32_to_cpu(data[0]), key);
112         if (__builtin_constant_p(len) && len =    111         if (__builtin_constant_p(len) && len == 8)
113                 return hsiphash_2u32(le32_to_c    112                 return hsiphash_2u32(le32_to_cpu(data[0]), le32_to_cpu(data[1]),
114                                      key);        113                                      key);
115         if (__builtin_constant_p(len) && len =    114         if (__builtin_constant_p(len) && len == 12)
116                 return hsiphash_3u32(le32_to_c    115                 return hsiphash_3u32(le32_to_cpu(data[0]), le32_to_cpu(data[1]),
117                                      le32_to_c    116                                      le32_to_cpu(data[2]), key);
118         if (__builtin_constant_p(len) && len =    117         if (__builtin_constant_p(len) && len == 16)
119                 return hsiphash_4u32(le32_to_c    118                 return hsiphash_4u32(le32_to_cpu(data[0]), le32_to_cpu(data[1]),
120                                      le32_to_c    119                                      le32_to_cpu(data[2]), le32_to_cpu(data[3]),
121                                      key);        120                                      key);
122         return __hsiphash_aligned(data, len, k    121         return __hsiphash_aligned(data, len, key);
123 }                                                 122 }
124                                                   123 
125 /**                                               124 /**
126  * hsiphash - compute 32-bit hsiphash PRF valu    125  * hsiphash - compute 32-bit hsiphash PRF value
127  * @data: buffer to hash                          126  * @data: buffer to hash
128  * @size: size of @data                           127  * @size: size of @data
129  * @key: the hsiphash key                         128  * @key: the hsiphash key
130  */                                               129  */
131 static inline u32 hsiphash(const void *data, s    130 static inline u32 hsiphash(const void *data, size_t len,
132                            const hsiphash_key_    131                            const hsiphash_key_t *key)
133 {                                                 132 {
134         if (IS_ENABLED(CONFIG_HAVE_EFFICIENT_U !! 133 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
135             !IS_ALIGNED((unsigned long)data, H !! 134         if (!IS_ALIGNED((unsigned long)data, HSIPHASH_ALIGNMENT))
136                 return __hsiphash_unaligned(da    135                 return __hsiphash_unaligned(data, len, key);
                                                   >> 136 #endif
137         return ___hsiphash_aligned(data, len,     137         return ___hsiphash_aligned(data, len, key);
138 }                                                 138 }
139                                                << 
140 /*                                             << 
141  * These macros expose the raw SipHash and Hal << 
142  * Do not use them directly! If you think you  << 
143  * be sure to CC the maintainer of this file e << 
144  */                                            << 
145                                                << 
146 #define SIPHASH_PERMUTATION(a, b, c, d) ( \    << 
147         (a) += (b), (b) = rol64((b), 13), (b)  << 
148         (c) += (d), (d) = rol64((d), 16), (d)  << 
149         (a) += (d), (d) = rol64((d), 21), (d)  << 
150         (c) += (b), (b) = rol64((b), 17), (b)  << 
151                                                << 
152 #define SIPHASH_CONST_0 0x736f6d6570736575ULL  << 
153 #define SIPHASH_CONST_1 0x646f72616e646f6dULL  << 
154 #define SIPHASH_CONST_2 0x6c7967656e657261ULL  << 
155 #define SIPHASH_CONST_3 0x7465646279746573ULL  << 
156                                                << 
157 #define HSIPHASH_PERMUTATION(a, b, c, d) ( \   << 
158         (a) += (b), (b) = rol32((b), 5), (b) ^ << 
159         (c) += (d), (d) = rol32((d), 8), (d) ^ << 
160         (a) += (d), (d) = rol32((d), 7), (d) ^ << 
161         (c) += (b), (b) = rol32((b), 13), (b)  << 
162                                                << 
163 #define HSIPHASH_CONST_0 0U                    << 
164 #define HSIPHASH_CONST_1 0U                    << 
165 #define HSIPHASH_CONST_2 0x6c796765U           << 
166 #define HSIPHASH_CONST_3 0x74656462U           << 
167                                                   139 
168 #endif /* _LINUX_SIPHASH_H */                     140 #endif /* _LINUX_SIPHASH_H */
169                                                   141 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php