2 Unix SMB/Netbios implementation.
4 a implementation of MD4 designed for use in the SMB authentication protocol
6 Copyright (C) Andrew Tridgell 1997-1998.
9 The Free Software Foundation, Inc.
11 This file is part of the Midnight Commander.
13 The Midnight Commander is free software: you can redistribute it
14 and/or modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation, either version 3 of the License,
16 or (at your option) any later version.
18 The Midnight Commander is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program. If not, see <http://www.gnu.org/licenses/>.
29 /* NOTE: This code makes no attempt to be fast!
31 It assumes that a int is at least 32 bits long
34 static uint32 A
, B
, C
, D
;
37 F (uint32 X
, uint32 Y
, uint32 Z
)
39 return (X
& Y
) | ((~X
) & Z
);
43 G (uint32 X
, uint32 Y
, uint32 Z
)
45 return (X
& Y
) | (X
& Z
) | (Y
& Z
);
49 H (uint32 X
, uint32 Y
, uint32 Z
)
55 lshift (uint32 x
, int s
)
58 return ((x
<< s
) & 0xFFFFFFFF) | (x
>> (32 - s
));
61 #define ROUND1(a,b,c,d,k,s) a = lshift(a + F(b,c,d) + X[k], s)
62 #define ROUND2(a,b,c,d,k,s) a = lshift(a + G(b,c,d) + X[k] + (uint32)0x5A827999,s)
63 #define ROUND3(a,b,c,d,k,s) a = lshift(a + H(b,c,d) + X[k] + (uint32)0x6ED9EBA1,s)
65 /* this applies md4 to 64 byte chunks */
70 uint32 AA
, BB
, CC
, DD
;
73 for (j
= 0; j
< 16; j
++)
81 ROUND1 (A
, B
, C
, D
, 0, 3);
82 ROUND1 (D
, A
, B
, C
, 1, 7);
83 ROUND1 (C
, D
, A
, B
, 2, 11);
84 ROUND1 (B
, C
, D
, A
, 3, 19);
85 ROUND1 (A
, B
, C
, D
, 4, 3);
86 ROUND1 (D
, A
, B
, C
, 5, 7);
87 ROUND1 (C
, D
, A
, B
, 6, 11);
88 ROUND1 (B
, C
, D
, A
, 7, 19);
89 ROUND1 (A
, B
, C
, D
, 8, 3);
90 ROUND1 (D
, A
, B
, C
, 9, 7);
91 ROUND1 (C
, D
, A
, B
, 10, 11);
92 ROUND1 (B
, C
, D
, A
, 11, 19);
93 ROUND1 (A
, B
, C
, D
, 12, 3);
94 ROUND1 (D
, A
, B
, C
, 13, 7);
95 ROUND1 (C
, D
, A
, B
, 14, 11);
96 ROUND1 (B
, C
, D
, A
, 15, 19);
98 ROUND2 (A
, B
, C
, D
, 0, 3);
99 ROUND2 (D
, A
, B
, C
, 4, 5);
100 ROUND2 (C
, D
, A
, B
, 8, 9);
101 ROUND2 (B
, C
, D
, A
, 12, 13);
102 ROUND2 (A
, B
, C
, D
, 1, 3);
103 ROUND2 (D
, A
, B
, C
, 5, 5);
104 ROUND2 (C
, D
, A
, B
, 9, 9);
105 ROUND2 (B
, C
, D
, A
, 13, 13);
106 ROUND2 (A
, B
, C
, D
, 2, 3);
107 ROUND2 (D
, A
, B
, C
, 6, 5);
108 ROUND2 (C
, D
, A
, B
, 10, 9);
109 ROUND2 (B
, C
, D
, A
, 14, 13);
110 ROUND2 (A
, B
, C
, D
, 3, 3);
111 ROUND2 (D
, A
, B
, C
, 7, 5);
112 ROUND2 (C
, D
, A
, B
, 11, 9);
113 ROUND2 (B
, C
, D
, A
, 15, 13);
115 ROUND3 (A
, B
, C
, D
, 0, 3);
116 ROUND3 (D
, A
, B
, C
, 8, 9);
117 ROUND3 (C
, D
, A
, B
, 4, 11);
118 ROUND3 (B
, C
, D
, A
, 12, 15);
119 ROUND3 (A
, B
, C
, D
, 2, 3);
120 ROUND3 (D
, A
, B
, C
, 10, 9);
121 ROUND3 (C
, D
, A
, B
, 6, 11);
122 ROUND3 (B
, C
, D
, A
, 14, 15);
123 ROUND3 (A
, B
, C
, D
, 1, 3);
124 ROUND3 (D
, A
, B
, C
, 9, 9);
125 ROUND3 (C
, D
, A
, B
, 5, 11);
126 ROUND3 (B
, C
, D
, A
, 13, 15);
127 ROUND3 (A
, B
, C
, D
, 3, 3);
128 ROUND3 (D
, A
, B
, C
, 11, 9);
129 ROUND3 (C
, D
, A
, B
, 7, 11);
130 ROUND3 (B
, C
, D
, A
, 15, 15);
142 for (j
= 0; j
< 16; j
++)
147 copy64 (uint32
* M
, unsigned char *in
)
151 for (i
= 0; i
< 16; i
++)
152 M
[i
] = (in
[i
* 4 + 3] << 24) | (in
[i
* 4 + 2] << 16) |
153 (in
[i
* 4 + 1] << 8) | (in
[i
* 4 + 0] << 0);
157 copy4 (unsigned char *out
, uint32 x
)
160 out
[1] = (x
>> 8) & 0xFF;
161 out
[2] = (x
>> 16) & 0xFF;
162 out
[3] = (x
>> 24) & 0xFF;
165 /* produce a md4 message digest from data of length n bytes */
167 mdfour (unsigned char *out
, unsigned char *in
, int n
)
169 unsigned char buf
[128];
187 for (i
= 0; i
< 128; i
++)
200 copy4 (buf
+ 120, b
);
203 copy64 (M
, buf
+ 64);
207 for (i
= 0; i
< 128; i
++)