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 <linux/types.h>
15 #define DELTA 0x9E3779B9
17 static void TEA_transform(__u32 buf[2], __u32 const in[])
20 __u32 b0 = buf[0], b1 = buf[1];
21 __u32 a = in[0], b = in[1], c = in[2], d = in[3];
26 b0 += ((b1 << 4)+a) ^ (b1+sum) ^ ((b1 >> 5)+b);
27 b1 += ((b0 << 4)+c) ^ (b0+sum) ^ ((b0 >> 5)+d);
34 static void str2hashbuf(const char *msg, int len, __u32 *buf, int num)
39 pad = (__u32)len | ((__u32)len << 8);
45 for (i=0; i < len; i++) {
48 val = msg[i] + (val << 8);
61 int btrfs_name_hash(const char *name, int len, u64 *hash_result)
68 if (len == 1 && *name == '.') {
71 } else if (len == 2 && name[0] == '.' && name[1] == '.') {
76 /* Initialize the default seed for the hash checksum functions */
84 str2hashbuf(p, len, in, 4);
85 TEA_transform(buf, in);
91 *hash_result = buf[0];
93 *hash_result |= buf[1];