5 * Copyright (C) 2002 by Theodore Ts'o
7 * This file is released under the GPL v2.
9 * This file may be redistributed under the terms of the GNU Public
13 #include "kerncompat.h"
14 #define DELTA 0x9E3779B9
16 static void TEA_transform(__u32 buf
[2], __u32
const in
[])
19 __u32 b0
= buf
[0], b1
= buf
[1];
20 __u32 a
= in
[0], b
= in
[1], c
= in
[2], d
= in
[3];
25 b0
+= ((b1
<< 4)+a
) ^ (b1
+sum
) ^ ((b1
>> 5)+b
);
26 b1
+= ((b0
<< 4)+c
) ^ (b0
+sum
) ^ ((b0
>> 5)+d
);
33 static void str2hashbuf(const char *msg
, int len
, __u32
*buf
, int num
)
38 pad
= (__u32
)len
| ((__u32
)len
<< 8);
44 for (i
=0; i
< len
; i
++) {
47 val
= msg
[i
] + (val
<< 8);
60 int btrfs_name_hash(const char *name
, int len
, u64
*hash_result
)
67 /* Initialize the default seed for the hash checksum functions */
75 str2hashbuf(p
, len
, in
, 4);
76 TEA_transform(buf
, in
);
82 *hash_result
= buf
[0];
84 *hash_result
|= buf
[1];