4 * Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 * http://www.samsung.com/
7 * Portions of this code from linux/fs/ext3/hash.c
9 * Copyright (C) 2002 by Theodore Ts'o
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 #include <linux/types.h>
17 #include <linux/f2fs_fs.h>
18 #include <linux/cryptohash.h>
19 #include <linux/pagemap.h>
24 * Hashing code copied from ext3
26 #define DELTA 0x9E3779B9
28 static void TEA_transform(unsigned int buf
[4], unsigned int const in
[])
31 __u32 b0
= buf
[0], b1
= buf
[1];
32 __u32 a
= in
[0], b
= in
[1], c
= in
[2], d
= in
[3];
37 b0
+= ((b1
<< 4)+a
) ^ (b1
+sum
) ^ ((b1
>> 5)+b
);
38 b1
+= ((b0
<< 4)+c
) ^ (b0
+sum
) ^ ((b0
>> 5)+d
);
45 static void str2hashbuf(const unsigned char *msg
, size_t len
,
46 unsigned int *buf
, int num
)
51 pad
= (__u32
)len
| ((__u32
)len
<< 8);
57 for (i
= 0; i
< len
; i
++) {
60 val
= msg
[i
] + (val
<< 8);
73 f2fs_hash_t
f2fs_dentry_hash(const struct qstr
*name_info
)
76 f2fs_hash_t f2fs_hash
;
77 const unsigned char *p
;
79 const unsigned char *name
= name_info
->name
;
80 size_t len
= name_info
->len
;
82 if ((len
<= 2) && (name
[0] == '.') &&
83 (name
[1] == '.' || name
[1] == '\0'))
86 /* Initialize the default seed for the hash checksum functions */
94 str2hashbuf(p
, len
, in
, 4);
95 TEA_transform(buf
, in
);
102 f2fs_hash
= cpu_to_le32(hash
& ~F2FS_HASH_COL_BIT
);