3 * Keyed 32-bit hash function using TEA in a Davis-Meyer function
5 * Hi = E Mi(Hi-1) + Hi-1
7 * (see Applied Cryptography, 2nd edition, p448).
9 * Jeremy Fitzhardinge <jeremy@zip.com.au> 1998
11 * Jeremy has agreed to the contents of reiserfs/README. -Hans
12 * Yura's function is added (04/07/2000)
15 // Modified by Ingo Weinhold (bonefish), Jan. 2003:
16 // Fixed r5_hash() and added key_offset_for_name().
27 #define DELTA 0x9E3779B9
28 #define FULLROUNDS 10 /* 32 is overkill, 16 is strong crypto */
29 #define PARTROUNDS 6 /* 6 gets complete mixing */
31 /* a, b, c, d - data; h0, h1 - accumulated hash */
32 #define TEACORE(rounds) \
44 b0 += ((b1 << 4)+a) ^ (b1+sum) ^ ((b1 >> 5)+b); \
45 b1 += ((b0 << 4)+c) ^ (b0+sum) ^ ((b0 >> 5)+d); \
53 uint32
keyed_hash(const signed char *msg
, int len
)
55 uint32 k
[] = { 0x9464a485, 0x542e1a94, 0x3e846bff, 0xb75bcfc3};
57 uint32 h0
= k
[0], h1
= k
[1];
63 // assert(len >= 0 && len < 256);
65 pad
= (uint32
)len
| ((uint32
)len
<< 8);
71 (uint32
)msg
[ 1] << 8 |
72 (uint32
)msg
[ 2] << 16|
73 (uint32
)msg
[ 3] << 24;
75 (uint32
)msg
[ 5] << 8 |
76 (uint32
)msg
[ 6] << 16|
77 (uint32
)msg
[ 7] << 24;
79 (uint32
)msg
[ 9] << 8 |
80 (uint32
)msg
[10] << 16|
81 (uint32
)msg
[11] << 24;
83 (uint32
)msg
[13] << 8 |
84 (uint32
)msg
[14] << 16|
85 (uint32
)msg
[15] << 24;
100 (uint32
)msg
[ 1] << 8 |
101 (uint32
)msg
[ 2] << 16|
102 (uint32
)msg
[ 3] << 24;
103 b
= (uint32
)msg
[ 4] |
104 (uint32
)msg
[ 5] << 8 |
105 (uint32
)msg
[ 6] << 16|
106 (uint32
)msg
[ 7] << 24;
107 c
= (uint32
)msg
[ 8] |
108 (uint32
)msg
[ 9] << 8 |
109 (uint32
)msg
[10] << 16|
110 (uint32
)msg
[11] << 24;
113 for(i
= 12; i
< len
; i
++)
124 a
= (uint32
)msg
[ 0] |
125 (uint32
)msg
[ 1] << 8 |
126 (uint32
)msg
[ 2] << 16|
127 (uint32
)msg
[ 3] << 24;
128 b
= (uint32
)msg
[ 4] |
129 (uint32
)msg
[ 5] << 8 |
130 (uint32
)msg
[ 6] << 16|
131 (uint32
)msg
[ 7] << 24;
134 for(i
= 8; i
< len
; i
++)
145 a
= (uint32
)msg
[ 0] |
146 (uint32
)msg
[ 1] << 8 |
147 (uint32
)msg
[ 2] << 16|
148 (uint32
)msg
[ 3] << 24;
151 for(i
= 4; i
< len
; i
++)
163 for(i
= 0; i
< len
; i
++)
176 /* What follows in this file is copyright 2000 by Hans Reiser, and the
177 * licensing of what follows is governed by reiserfs/README */
179 uint32
yura_hash (const signed char *msg
, int len
)
185 for (pow
=1,i
=1; i
< len
; i
++) pow
= pow
* 10;
190 a
= (msg
[0] - 48) * pow
;
192 for (i
=1; i
< len
; i
++) {
194 for (pow
=1,j
=i
; j
< len
-1; j
++) pow
= pow
* 10;
198 for (; i
< 40; i
++) {
200 for (pow
=1,j
=i
; j
< len
-1; j
++) pow
= pow
* 10;
204 for (; i
< 256; i
++) {
206 for (pow
=1,j
=i
; j
< len
-1; j
++) pow
= pow
* 10;
214 uint32
r5_hash (const signed char *msg
, int len
)
217 // bonefish: len was ignored
230 // from reiserfs_fs.h:
231 /* hash value occupies bits from 7 up to 30 */
232 #define GET_HASH_VALUE(offset) ((offset) & 0x7fffff80LL)
233 #define MAX_GENERATION_NUMBER 127
236 // derived from name.c: get_third_component()
238 key_offset_for_name(hash_function_t hash
, const char *name
, int len
)
242 if (!len
|| (len
== 1 && name
[0] == '.'))
244 if (len
== 2 && name
[0] == '.' && name
[1] == '.')
245 return DOT_DOT_OFFSET
;
247 res
= (*hash
)((const signed char*)name
, len
);
249 // take bits from 7-th to 30-th including both bounds
250 res
= GET_HASH_VALUE(res
);
252 // needed to have no names before "." and ".." those have hash
253 // value == 0 and generation conters 1 and 2 accordingly
255 return res
+ MAX_GENERATION_NUMBER
;