Mercurial > dropbear
annotate src/hashes/md4.c @ 210:4768b55c5240 libtomcrypt
propagate from branch 'au.asn.ucc.matt.ltc-orig' (head 33c416b902f1a44913d825bae7ad9a160f703ed3)
to branch 'au.asn.ucc.matt.dropbear.ltc' (head 4d6aec6e6121e13f68c11c149b6579c41cb63e74)
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 06 Jul 2005 12:10:23 +0000 |
parents | 39d5d58461d6 |
children |
rev | line source |
---|---|
191
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
2 * |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
3 * LibTomCrypt is a library that provides various cryptographic |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
4 * algorithms in a highly modular and flexible manner. |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
5 * |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
6 * The library is free for all purposes without any express |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
7 * guarantee it works. |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
8 * |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
9 * Tom St Denis, [email protected], http://libtomcrypt.org |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
10 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
11 #include "tomcrypt.h" |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
12 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
13 /** |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
14 @param md4.c |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
15 Submitted by Dobes Vandermeer ([email protected]) |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
16 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
17 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
18 #ifdef MD4 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
19 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
20 const struct ltc_hash_descriptor md4_desc = |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
21 { |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
22 "md4", |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
23 6, |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
24 16, |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
25 64, |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
26 |
209 | 27 /* OID */ |
28 { 1, 2, 840, 113549, 2, 4, }, | |
29 6, | |
191
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
30 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
31 &md4_init, |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
32 &md4_process, |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
33 &md4_done, |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
34 &md4_test |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
35 }; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
36 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
37 #define S11 3 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
38 #define S12 7 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
39 #define S13 11 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
40 #define S14 19 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
41 #define S21 3 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
42 #define S22 5 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
43 #define S23 9 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
44 #define S24 13 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
45 #define S31 3 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
46 #define S32 9 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
47 #define S33 11 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
48 #define S34 15 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
49 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
50 /* F, G and H are basic MD4 functions. */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
51 #define F(x, y, z) (z ^ (x & (y ^ z))) |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
52 #define G(x, y, z) ((x & y) | (z & (x | y))) |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
53 #define H(x, y, z) ((x) ^ (y) ^ (z)) |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
54 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
55 /* ROTATE_LEFT rotates x left n bits. */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
56 #define ROTATE_LEFT(x, n) ROLc(x, n) |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
57 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
58 /* FF, GG and HH are transformations for rounds 1, 2 and 3 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
59 /* Rotation is separate from addition to prevent recomputation */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
60 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
61 #define FF(a, b, c, d, x, s) { \ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
62 (a) += F ((b), (c), (d)) + (x); \ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
63 (a) = ROTATE_LEFT ((a), (s)); \ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
64 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
65 #define GG(a, b, c, d, x, s) { \ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
66 (a) += G ((b), (c), (d)) + (x) + 0x5a827999UL; \ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
67 (a) = ROTATE_LEFT ((a), (s)); \ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
68 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
69 #define HH(a, b, c, d, x, s) { \ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
70 (a) += H ((b), (c), (d)) + (x) + 0x6ed9eba1UL; \ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
71 (a) = ROTATE_LEFT ((a), (s)); \ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
72 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
73 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
74 #ifdef LTC_CLEAN_STACK |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
75 static int _md4_compress(hash_state *md, unsigned char *buf) |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
76 #else |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
77 static int md4_compress(hash_state *md, unsigned char *buf) |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
78 #endif |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
79 { |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
80 ulong32 x[16], a, b, c, d; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
81 int i; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
82 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
83 /* copy state */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
84 a = md->md4.state[0]; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
85 b = md->md4.state[1]; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
86 c = md->md4.state[2]; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
87 d = md->md4.state[3]; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
88 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
89 /* copy the state into 512-bits into W[0..15] */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
90 for (i = 0; i < 16; i++) { |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
91 LOAD32L(x[i], buf + (4*i)); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
92 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
93 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
94 /* Round 1 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
95 FF (a, b, c, d, x[ 0], S11); /* 1 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
96 FF (d, a, b, c, x[ 1], S12); /* 2 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
97 FF (c, d, a, b, x[ 2], S13); /* 3 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
98 FF (b, c, d, a, x[ 3], S14); /* 4 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
99 FF (a, b, c, d, x[ 4], S11); /* 5 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
100 FF (d, a, b, c, x[ 5], S12); /* 6 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
101 FF (c, d, a, b, x[ 6], S13); /* 7 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
102 FF (b, c, d, a, x[ 7], S14); /* 8 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
103 FF (a, b, c, d, x[ 8], S11); /* 9 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
104 FF (d, a, b, c, x[ 9], S12); /* 10 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
105 FF (c, d, a, b, x[10], S13); /* 11 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
106 FF (b, c, d, a, x[11], S14); /* 12 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
107 FF (a, b, c, d, x[12], S11); /* 13 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
108 FF (d, a, b, c, x[13], S12); /* 14 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
109 FF (c, d, a, b, x[14], S13); /* 15 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
110 FF (b, c, d, a, x[15], S14); /* 16 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
111 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
112 /* Round 2 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
113 GG (a, b, c, d, x[ 0], S21); /* 17 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
114 GG (d, a, b, c, x[ 4], S22); /* 18 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
115 GG (c, d, a, b, x[ 8], S23); /* 19 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
116 GG (b, c, d, a, x[12], S24); /* 20 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
117 GG (a, b, c, d, x[ 1], S21); /* 21 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
118 GG (d, a, b, c, x[ 5], S22); /* 22 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
119 GG (c, d, a, b, x[ 9], S23); /* 23 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
120 GG (b, c, d, a, x[13], S24); /* 24 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
121 GG (a, b, c, d, x[ 2], S21); /* 25 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
122 GG (d, a, b, c, x[ 6], S22); /* 26 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
123 GG (c, d, a, b, x[10], S23); /* 27 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
124 GG (b, c, d, a, x[14], S24); /* 28 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
125 GG (a, b, c, d, x[ 3], S21); /* 29 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
126 GG (d, a, b, c, x[ 7], S22); /* 30 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
127 GG (c, d, a, b, x[11], S23); /* 31 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
128 GG (b, c, d, a, x[15], S24); /* 32 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
129 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
130 /* Round 3 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
131 HH (a, b, c, d, x[ 0], S31); /* 33 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
132 HH (d, a, b, c, x[ 8], S32); /* 34 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
133 HH (c, d, a, b, x[ 4], S33); /* 35 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
134 HH (b, c, d, a, x[12], S34); /* 36 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
135 HH (a, b, c, d, x[ 2], S31); /* 37 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
136 HH (d, a, b, c, x[10], S32); /* 38 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
137 HH (c, d, a, b, x[ 6], S33); /* 39 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
138 HH (b, c, d, a, x[14], S34); /* 40 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
139 HH (a, b, c, d, x[ 1], S31); /* 41 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
140 HH (d, a, b, c, x[ 9], S32); /* 42 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
141 HH (c, d, a, b, x[ 5], S33); /* 43 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
142 HH (b, c, d, a, x[13], S34); /* 44 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
143 HH (a, b, c, d, x[ 3], S31); /* 45 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
144 HH (d, a, b, c, x[11], S32); /* 46 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
145 HH (c, d, a, b, x[ 7], S33); /* 47 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
146 HH (b, c, d, a, x[15], S34); /* 48 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
147 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
148 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
149 /* Update our state */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
150 md->md4.state[0] = md->md4.state[0] + a; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
151 md->md4.state[1] = md->md4.state[1] + b; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
152 md->md4.state[2] = md->md4.state[2] + c; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
153 md->md4.state[3] = md->md4.state[3] + d; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
154 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
155 return CRYPT_OK; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
156 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
157 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
158 #ifdef LTC_CLEAN_STACK |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
159 static int md4_compress(hash_state *md, unsigned char *buf) |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
160 { |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
161 int err; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
162 err = _md4_compress(md, buf); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
163 burn_stack(sizeof(ulong32) * 20 + sizeof(int)); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
164 return err; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
165 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
166 #endif |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
167 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
168 /** |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
169 Initialize the hash state |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
170 @param md The hash state you wish to initialize |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
171 @return CRYPT_OK if successful |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
172 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
173 int md4_init(hash_state * md) |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
174 { |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
175 LTC_ARGCHK(md != NULL); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
176 md->md4.state[0] = 0x67452301UL; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
177 md->md4.state[1] = 0xefcdab89UL; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
178 md->md4.state[2] = 0x98badcfeUL; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
179 md->md4.state[3] = 0x10325476UL; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
180 md->md4.length = 0; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
181 md->md4.curlen = 0; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
182 return CRYPT_OK; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
183 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
184 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
185 /** |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
186 Process a block of memory though the hash |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
187 @param md The hash state |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
188 @param in The data to hash |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
189 @param inlen The length of the data (octets) |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
190 @return CRYPT_OK if successful |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
191 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
192 HASH_PROCESS(md4_process, md4_compress, md4, 64) |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
193 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
194 /** |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
195 Terminate the hash to get the digest |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
196 @param md The hash state |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
197 @param out [out] The destination of the hash (16 bytes) |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
198 @return CRYPT_OK if successful |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
199 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
200 int md4_done(hash_state * md, unsigned char *out) |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
201 { |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
202 int i; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
203 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
204 LTC_ARGCHK(md != NULL); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
205 LTC_ARGCHK(out != NULL); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
206 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
207 if (md->md4.curlen >= sizeof(md->md4.buf)) { |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
208 return CRYPT_INVALID_ARG; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
209 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
210 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
211 /* increase the length of the message */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
212 md->md4.length += md->md4.curlen * 8; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
213 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
214 /* append the '1' bit */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
215 md->md4.buf[md->md4.curlen++] = (unsigned char)0x80; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
216 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
217 /* if the length is currently above 56 bytes we append zeros |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
218 * then compress. Then we can fall back to padding zeros and length |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
219 * encoding like normal. |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
220 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
221 if (md->md4.curlen > 56) { |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
222 while (md->md4.curlen < 64) { |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
223 md->md4.buf[md->md4.curlen++] = (unsigned char)0; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
224 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
225 md4_compress(md, md->md4.buf); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
226 md->md4.curlen = 0; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
227 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
228 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
229 /* pad upto 56 bytes of zeroes */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
230 while (md->md4.curlen < 56) { |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
231 md->md4.buf[md->md4.curlen++] = (unsigned char)0; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
232 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
233 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
234 /* store length */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
235 STORE64L(md->md4.length, md->md4.buf+56); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
236 md4_compress(md, md->md4.buf); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
237 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
238 /* copy output */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
239 for (i = 0; i < 4; i++) { |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
240 STORE32L(md->md4.state[i], out+(4*i)); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
241 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
242 #ifdef LTC_CLEAN_STACK |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
243 zeromem(md, sizeof(hash_state)); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
244 #endif |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
245 return CRYPT_OK; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
246 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
247 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
248 /** |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
249 Self-test the hash |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
250 @return CRYPT_OK if successful, CRYPT_NOP if self-tests have been disabled |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
251 */ |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
252 int md4_test(void) |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
253 { |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
254 #ifndef LTC_TEST |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
255 return CRYPT_NOP; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
256 #else |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
257 static const struct md4_test_case { |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
258 char *input; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
259 unsigned char digest[16]; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
260 } cases[] = { |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
261 { "", |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
262 {0x31, 0xd6, 0xcf, 0xe0, 0xd1, 0x6a, 0xe9, 0x31, |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
263 0xb7, 0x3c, 0x59, 0xd7, 0xe0, 0xc0, 0x89, 0xc0} }, |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
264 { "a", |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
265 {0xbd, 0xe5, 0x2c, 0xb3, 0x1d, 0xe3, 0x3e, 0x46, |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
266 0x24, 0x5e, 0x05, 0xfb, 0xdb, 0xd6, 0xfb, 0x24} }, |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
267 { "abc", |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
268 {0xa4, 0x48, 0x01, 0x7a, 0xaf, 0x21, 0xd8, 0x52, |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
269 0x5f, 0xc1, 0x0a, 0xe8, 0x7a, 0xa6, 0x72, 0x9d} }, |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
270 { "message digest", |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
271 {0xd9, 0x13, 0x0a, 0x81, 0x64, 0x54, 0x9f, 0xe8, |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
272 0x18, 0x87, 0x48, 0x06, 0xe1, 0xc7, 0x01, 0x4b} }, |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
273 { "abcdefghijklmnopqrstuvwxyz", |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
274 {0xd7, 0x9e, 0x1c, 0x30, 0x8a, 0xa5, 0xbb, 0xcd, |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
275 0xee, 0xa8, 0xed, 0x63, 0xdf, 0x41, 0x2d, 0xa9} }, |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
276 { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
277 {0x04, 0x3f, 0x85, 0x82, 0xf2, 0x41, 0xdb, 0x35, |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
278 0x1c, 0xe6, 0x27, 0xe1, 0x53, 0xe7, 0xf0, 0xe4} }, |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
279 { "12345678901234567890123456789012345678901234567890123456789012345678901234567890", |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
280 {0xe3, 0x3b, 0x4d, 0xdc, 0x9c, 0x38, 0xf2, 0x19, |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
281 0x9c, 0x3e, 0x7b, 0x16, 0x4f, 0xcc, 0x05, 0x36} }, |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
282 }; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
283 int i; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
284 hash_state md; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
285 unsigned char digest[16]; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
286 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
287 for(i = 0; i < (int)(sizeof(cases) / sizeof(cases[0])); i++) { |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
288 md4_init(&md); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
289 md4_process(&md, (unsigned char *)cases[i].input, (unsigned long)strlen(cases[i].input)); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
290 md4_done(&md, digest); |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
291 if (memcmp(digest, cases[i].digest, 16) != 0) { |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
292 return CRYPT_FAIL_TESTVECTOR; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
293 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
294 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
295 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
296 return CRYPT_OK; |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
297 #endif |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
298 } |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
299 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
300 #endif |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
301 |
1c15b283127b
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
Matt Johnston <matt@ucc.asn.au>
parents:
diff
changeset
|
302 |
209 | 303 |
304 /* $Source: /cvs/libtom/libtomcrypt/src/hashes/md4.c,v $ */ | |
305 /* $Revision: 1.5 $ */ | |
306 /* $Date: 2005/05/23 02:42:07 $ */ |