2 * Copyright (C) 2007 Oracle. All rights reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public
14 * License along with this program; if not, write to the
15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 * Boston, MA 021110-1307, USA.
21 * linux/fs/ext3/hash.c
23 * Copyright (C) 2002 by Theodore Ts'o
25 * This file is released under the GPL v2.
27 * This file may be redistributed under the terms of the GNU Public
31 #include "kerncompat.h"
32 #define DELTA 0x9E3779B9
34 static void TEA_transform(__u32 buf
[2], __u32
const in
[])
37 __u32 b0
= buf
[0], b1
= buf
[1];
38 __u32 a
= in
[0], b
= in
[1], c
= in
[2], d
= in
[3];
43 b0
+= ((b1
<< 4)+a
) ^ (b1
+sum
) ^ ((b1
>> 5)+b
);
44 b1
+= ((b0
<< 4)+c
) ^ (b0
+sum
) ^ ((b0
>> 5)+d
);
51 static void str2hashbuf(const char *msg
, int len
, __u32
*buf
, int num
)
56 pad
= (__u32
)len
| ((__u32
)len
<< 8);
62 for (i
=0; i
< len
; i
++) {
65 val
= msg
[i
] + (val
<< 8);
78 u64
btrfs_name_hash(const char *name
, int len
)
86 /* Initialize the default seed for the hash checksum functions */
94 str2hashbuf(p
, len
, in
, 4);
95 TEA_transform(buf
, in
);
101 hash_result
= buf
[0];
103 hash_result
|= buf
[1];