7a26c4fe6c46757d12ecff9b71ded0729cbad6dd
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 #include <linux/kernel.h>
17 #include <asm/types.h>
19 #define DELTA 0x9E3779B9
20 #define FULLROUNDS 10 /* 32 is overkill, 16 is strong crypto */
21 #define PARTROUNDS 6 /* 6 gets complete mixing */
23 /* a, b, c, d - data; h0, h1 - accumulated hash */
24 #define TEACORE(rounds) \
36 b0 += ((b1 << 4)+a) ^ (b1+sum) ^ ((b1 >> 5)+b); \
37 b1 += ((b0 << 4)+c) ^ (b0+sum) ^ ((b0 >> 5)+d); \
44 u32
keyed_hash(const signed char *msg
, int len
)
46 u32 k
[] = { 0x9464a485, 0x542e1a94, 0x3e846bff, 0xb75bcfc3 };
48 u32 h0
= k
[0], h1
= k
[1];
53 /* assert(len >= 0 && len < 256); */
55 pad
= (u32
) len
| ((u32
) len
<< 8);
60 (u32
) msg
[1] << 8 | (u32
) msg
[2] << 16 | (u32
) msg
[3] << 24;
62 (u32
) msg
[5] << 8 | (u32
) msg
[6] << 16 | (u32
) msg
[7] << 24;
65 (u32
) msg
[10] << 16 | (u32
) msg
[11] << 24;
68 (u32
) msg
[14] << 16 | (u32
) msg
[15] << 24;
78 (u32
) msg
[1] << 8 | (u32
) msg
[2] << 16 | (u32
) msg
[3] << 24;
80 (u32
) msg
[5] << 8 | (u32
) msg
[6] << 16 | (u32
) msg
[7] << 24;
83 (u32
) msg
[10] << 16 | (u32
) msg
[11] << 24;
86 for (i
= 12; i
< len
; i
++) {
90 } else if (len
>= 8) {
92 (u32
) msg
[1] << 8 | (u32
) msg
[2] << 16 | (u32
) msg
[3] << 24;
94 (u32
) msg
[5] << 8 | (u32
) msg
[6] << 16 | (u32
) msg
[7] << 24;
97 for (i
= 8; i
< len
; i
++) {
101 } else if (len
>= 4) {
103 (u32
) msg
[1] << 8 | (u32
) msg
[2] << 16 | (u32
) msg
[3] << 24;
106 for (i
= 4; i
< len
; i
++) {
112 for (i
= 0; i
< len
; i
++) {
125 * What follows in this file is copyright 2000 by Hans Reiser, and the
126 * licensing of what follows is governed by reiserfs/README
128 u32
yura_hash(const signed char *msg
, int len
)
134 for (pow
= 1, i
= 1; i
< len
; i
++)
140 a
= (msg
[0] - 48) * pow
;
142 for (i
= 1; i
< len
; i
++) {
144 for (pow
= 1, j
= i
; j
< len
- 1; j
++)
149 for (; i
< 40; i
++) {
151 for (pow
= 1, j
= i
; j
< len
- 1; j
++)
156 for (; i
< 256; i
++) {
158 for (pow
= 1, j
= i
; j
< len
- 1; j
++)
167 u32
r5_hash(const signed char *msg
, int len
)