diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /lib/halfmd4.c |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'lib/halfmd4.c')
-rw-r--r-- | lib/halfmd4.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/lib/halfmd4.c b/lib/halfmd4.c new file mode 100644 index 000000000000..e11db26f8ae5 --- /dev/null +++ b/lib/halfmd4.c | |||
@@ -0,0 +1,66 @@ | |||
1 | #include <linux/kernel.h> | ||
2 | #include <linux/module.h> | ||
3 | #include <linux/cryptohash.h> | ||
4 | |||
5 | /* F, G and H are basic MD4 functions: selection, majority, parity */ | ||
6 | #define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) | ||
7 | #define G(x, y, z) (((x) & (y)) + (((x) ^ (y)) & (z))) | ||
8 | #define H(x, y, z) ((x) ^ (y) ^ (z)) | ||
9 | |||
10 | /* | ||
11 | * The generic round function. The application is so specific that | ||
12 | * we don't bother protecting all the arguments with parens, as is generally | ||
13 | * good macro practice, in favor of extra legibility. | ||
14 | * Rotation is separate from addition to prevent recomputation | ||
15 | */ | ||
16 | #define ROUND(f, a, b, c, d, x, s) \ | ||
17 | (a += f(b, c, d) + x, a = (a << s) | (a >> (32 - s))) | ||
18 | #define K1 0 | ||
19 | #define K2 013240474631UL | ||
20 | #define K3 015666365641UL | ||
21 | |||
22 | /* | ||
23 | * Basic cut-down MD4 transform. Returns only 32 bits of result. | ||
24 | */ | ||
25 | __u32 half_md4_transform(__u32 buf[4], __u32 const in[8]) | ||
26 | { | ||
27 | __u32 a = buf[0], b = buf[1], c = buf[2], d = buf[3]; | ||
28 | |||
29 | /* Round 1 */ | ||
30 | ROUND(F, a, b, c, d, in[0] + K1, 3); | ||
31 | ROUND(F, d, a, b, c, in[1] + K1, 7); | ||
32 | ROUND(F, c, d, a, b, in[2] + K1, 11); | ||
33 | ROUND(F, b, c, d, a, in[3] + K1, 19); | ||
34 | ROUND(F, a, b, c, d, in[4] + K1, 3); | ||
35 | ROUND(F, d, a, b, c, in[5] + K1, 7); | ||
36 | ROUND(F, c, d, a, b, in[6] + K1, 11); | ||
37 | ROUND(F, b, c, d, a, in[7] + K1, 19); | ||
38 | |||
39 | /* Round 2 */ | ||
40 | ROUND(G, a, b, c, d, in[1] + K2, 3); | ||
41 | ROUND(G, d, a, b, c, in[3] + K2, 5); | ||
42 | ROUND(G, c, d, a, b, in[5] + K2, 9); | ||
43 | ROUND(G, b, c, d, a, in[7] + K2, 13); | ||
44 | ROUND(G, a, b, c, d, in[0] + K2, 3); | ||
45 | ROUND(G, d, a, b, c, in[2] + K2, 5); | ||
46 | ROUND(G, c, d, a, b, in[4] + K2, 9); | ||
47 | ROUND(G, b, c, d, a, in[6] + K2, 13); | ||
48 | |||
49 | /* Round 3 */ | ||
50 | ROUND(H, a, b, c, d, in[3] + K3, 3); | ||
51 | ROUND(H, d, a, b, c, in[7] + K3, 9); | ||
52 | ROUND(H, c, d, a, b, in[2] + K3, 11); | ||
53 | ROUND(H, b, c, d, a, in[6] + K3, 15); | ||
54 | ROUND(H, a, b, c, d, in[1] + K3, 3); | ||
55 | ROUND(H, d, a, b, c, in[5] + K3, 9); | ||
56 | ROUND(H, c, d, a, b, in[0] + K3, 11); | ||
57 | ROUND(H, b, c, d, a, in[4] + K3, 15); | ||
58 | |||
59 | buf[0] += a; | ||
60 | buf[1] += b; | ||
61 | buf[2] += c; | ||
62 | buf[3] += d; | ||
63 | |||
64 | return buf[1]; /* "most hashed" word */ | ||
65 | } | ||
66 | EXPORT_SYMBOL(half_md4_transform); | ||