42 #if defined(USE_NSS) || defined(USE_OS400CRYPTO) || \ 43 (defined(USE_MBEDTLS) && !defined(MBEDTLS_MD4_C)) 53 typedef unsigned int MD4_u32plus;
57 MD4_u32plus
a, b, c,
d;
59 MD4_u32plus block[16];
72 #define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) 73 #define G(x, y, z) (((x) & ((y) | (z))) | ((y) & (z))) 74 #define H(x, y, z) ((x) ^ (y) ^ (z)) 79 #define STEP(f, a, b, c, d, x, s) \ 80 (a) += f((b), (c), (d)) + (x); \ 81 (a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); 91 #if defined(__i386__) || defined(__x86_64__) || defined(__vax__) 93 (*(MD4_u32plus *)(void *)&ptr[(n) * 4]) 99 (MD4_u32plus)ptr[(n) * 4] | \ 100 ((MD4_u32plus)ptr[(n) * 4 + 1] << 8) | \ 101 ((MD4_u32plus)ptr[(n) * 4 + 2] << 16) | \ 102 ((MD4_u32plus)ptr[(n) * 4 + 3] << 24)) 111 static const void *
body(MD4_CTX *ctx,
const void *
data,
unsigned long size)
113 const unsigned char *
ptr;
114 MD4_u32plus
a, b, c,
d;
115 MD4_u32plus saved_a, saved_b, saved_c, saved_d;
117 ptr = (
const unsigned char *)data;
133 STEP(F, c, d, a, b, SET(2), 11)
134 STEP(F, b, c, d, a, SET(3), 19)
135 STEP(F, a, b, c, d, SET(4), 3)
136 STEP(F, d, a, b, c, SET(5), 7)
137 STEP(F, c, d, a, b, SET(6), 11)
138 STEP(F, b, c, d, a, SET(7), 19)
139 STEP(F, a, b, c, d, SET(8), 3)
140 STEP(F, d, a, b, c, SET(9), 7)
141 STEP(F, c, d, a, b, SET(10), 11)
142 STEP(F, b, c, d, a, SET(11), 19)
143 STEP(F, a, b, c, d, SET(12), 3)
144 STEP(F, d, a, b, c, SET(13), 7)
145 STEP(F, c, d, a, b, SET(14), 11)
146 STEP(F, b, c, d, a, SET(15), 19)
149 STEP(
G, a, b, c, d,
GET(0) + 0x5a827999, 3)
150 STEP(G, d, a, b, c,
GET(4) + 0x5a827999, 5)
151 STEP(G, c, d, a, b,
GET(8) + 0x5a827999, 9)
152 STEP(G, b, c, d, a,
GET(12) + 0x5a827999, 13)
153 STEP(G, a, b, c, d,
GET(1) + 0x5a827999, 3)
154 STEP(G, d, a, b, c,
GET(5) + 0x5a827999, 5)
155 STEP(G, c, d, a, b,
GET(9) + 0x5a827999, 9)
156 STEP(G, b, c, d, a,
GET(13) + 0x5a827999, 13)
157 STEP(G, a, b, c, d,
GET(2) + 0x5a827999, 3)
158 STEP(G, d, a, b, c,
GET(6) + 0x5a827999, 5)
159 STEP(G, c, d, a, b,
GET(10) + 0x5a827999, 9)
160 STEP(G, b, c, d, a,
GET(14) + 0x5a827999, 13)
161 STEP(G, a, b, c, d,
GET(3) + 0x5a827999, 3)
162 STEP(G, d, a, b, c,
GET(7) + 0x5a827999, 5)
163 STEP(G, c, d, a, b,
GET(11) + 0x5a827999, 9)
164 STEP(G, b, c, d, a,
GET(15) + 0x5a827999, 13)
167 STEP(
H, a, b, c, d,
GET(0) + 0x6ed9eba1, 3)
168 STEP(H, d, a, b, c,
GET(8) + 0x6ed9eba1, 9)
169 STEP(H, c, d, a, b,
GET(4) + 0x6ed9eba1, 11)
170 STEP(H, b, c, d, a,
GET(12) + 0x6ed9eba1, 15)
171 STEP(H, a, b, c, d,
GET(2) + 0x6ed9eba1, 3)
172 STEP(H, d, a, b, c,
GET(10) + 0x6ed9eba1, 9)
173 STEP(H, c, d, a, b,
GET(6) + 0x6ed9eba1, 11)
174 STEP(H, b, c, d, a,
GET(14) + 0x6ed9eba1, 15)
175 STEP(H, a, b, c, d,
GET(1) + 0x6ed9eba1, 3)
176 STEP(H, d, a, b, c,
GET(9) + 0x6ed9eba1, 9)
177 STEP(H, c, d, a, b,
GET(5) + 0x6ed9eba1, 11)
178 STEP(H, b, c, d, a,
GET(13) + 0x6ed9eba1, 15)
179 STEP(H, a, b, c, d,
GET(3) + 0x6ed9eba1, 3)
180 STEP(H, d, a, b, c,
GET(11) + 0x6ed9eba1, 9)
181 STEP(H, c, d, a, b,
GET(7) + 0x6ed9eba1, 11)
182 STEP(H, b, c, d, a,
GET(15) + 0x6ed9eba1, 15)
211 static void MD4_Update(MD4_CTX *ctx,
const void *data,
unsigned long size)
213 MD4_u32plus saved_lo;
214 unsigned long used, available;
217 ctx->lo = (saved_lo +
size) & 0x1fffffff;
218 if(ctx->lo < saved_lo)
220 ctx->hi += (MD4_u32plus)size >> 29;
222 used = saved_lo & 0x3f;
225 available = 64 - used;
227 if(size < available) {
228 memcpy(&ctx->buffer[used], data, size);
232 memcpy(&ctx->buffer[used], data, available);
233 data = (
const unsigned char *)data + available;
235 body(ctx, ctx->buffer, 64);
239 data =
body(ctx, data, size & ~(
unsigned long)0x3f);
243 memcpy(ctx->buffer, data, size);
248 unsigned long used, available;
250 used = ctx->lo & 0x3f;
252 ctx->buffer[used++] = 0x80;
254 available = 64 - used;
257 memset(&ctx->buffer[used], 0, available);
258 body(ctx, ctx->buffer, 64);
263 memset(&ctx->buffer[used], 0, available - 8);
275 body(ctx, ctx->buffer, 64);
294 memset(ctx, 0,
sizeof(*ctx));
299 void Curl_md4it(
unsigned char *
output,
const unsigned char *
input,
size_t len)
unsigned char curlx_ultouc(unsigned long ulnum)
UNITTEST_START char * ptr
static const void * body(MD5_CTX *ctx, const void *data, unsigned long size)
UNITTEST_START int result
memcpy(filename, filename1, strlen(filename1))
UNITTEST_START char * output
unsigned int curlx_uztoui(size_t uznum)
#define STEP(f, a, b, c, d, x, t, s)