25 #ifndef CURL_DISABLE_CRYPTO_AUTH 33 #if defined(USE_GNUTLS_NETTLE) 35 #include <nettle/md5.h> 48 const unsigned char *
input,
49 unsigned int inputLen)
51 md5_update(ctx, inputLen, input);
56 md5_digest(ctx, 16, digest);
59 #elif defined(USE_GNUTLS) 70 gcry_md_open(ctx, GCRY_MD_MD5, 0);
74 const unsigned char *
input,
75 unsigned int inputLen)
77 gcry_md_write(*ctx, input, inputLen);
82 memcpy(digest, gcry_md_read(*ctx, 0), 16);
86 #elif defined(USE_OPENSSL) 88 #include <openssl/md5.h> 93 #elif (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && \ 94 (__MAC_OS_X_VERSION_MAX_ALLOWED >= 1040)) || \ 95 (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && \ 96 (__IPHONE_OS_VERSION_MAX_ALLOWED >= 20000)) 104 # include <CommonCrypto/CommonDigest.h> 105 # define MD5_CTX CC_MD5_CTX 116 const unsigned char *
input,
117 unsigned int inputLen)
119 CC_MD5_Update(ctx, input, inputLen);
124 CC_MD5_Final(digest, ctx);
127 #elif defined(_WIN32) && !defined(CURL_WINDOWS_APP) 129 #include <wincrypt.h> 135 HCRYPTPROV hCryptProv;
141 if(CryptAcquireContext(&ctx->hCryptProv, NULL, NULL,
142 PROV_RSA_FULL, CRYPT_VERIFYCONTEXT)) {
143 CryptCreateHash(ctx->hCryptProv, CALG_MD5, 0, 0, &ctx->hHash);
148 const unsigned char *
input,
149 unsigned int inputLen)
151 CryptHashData(ctx->hHash, (
unsigned char *)input, inputLen, 0);
157 CryptGetHashParam(ctx->hHash, HP_HASHVAL, NULL, &length, 0);
159 CryptGetHashParam(ctx->hHash, HP_HASHVAL, digest, &length, 0);
161 CryptDestroyHash(ctx->hHash);
163 CryptReleaseContext(ctx->hCryptProv, 0);
166 #elif defined(USE_AXTLS) 167 #include <axTLS/config.h> 168 #include <axTLS/os_int.h> 169 #include <axTLS/crypto.h> 223 MD5_u32plus
a, b, c,
d;
225 MD5_u32plus block[16];
239 #define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) 240 #define G(x, y, z) ((y) ^ ((z) & ((x) ^ (y)))) 241 #define H(x, y, z) (((x) ^ (y)) ^ (z)) 242 #define H2(x, y, z) ((x) ^ ((y) ^ (z))) 243 #define I(x, y, z) ((y) ^ ((x) | ~(z))) 248 #define STEP(f, a, b, c, d, x, t, s) \ 249 (a) += f((b), (c), (d)) + (x) + (t); \ 250 (a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); \ 261 #if defined(__i386__) || defined(__x86_64__) || defined(__vax__) 263 (*(MD5_u32plus *)(void *)&ptr[(n) * 4]) 269 (MD5_u32plus)ptr[(n) * 4] | \ 270 ((MD5_u32plus)ptr[(n) * 4 + 1] << 8) | \ 271 ((MD5_u32plus)ptr[(n) * 4 + 2] << 16) | \ 272 ((MD5_u32plus)ptr[(n) * 4 + 3] << 24)) 283 const unsigned char *
ptr;
284 MD5_u32plus
a, b, c,
d;
285 MD5_u32plus saved_a, saved_b, saved_c, saved_d;
287 ptr = (
const unsigned char *)data;
301 STEP(
F, a, b, c, d,
SET(0), 0xd76aa478, 7)
302 STEP(
F, d, a, b, c,
SET(1), 0xe8c7b756, 12)
303 STEP(
F, c, d, a, b,
SET(2), 0x242070db, 17)
304 STEP(
F, b, c, d, a,
SET(3), 0xc1bdceee, 22)
305 STEP(
F, a, b, c, d,
SET(4), 0xf57c0faf, 7)
306 STEP(
F, d, a, b, c,
SET(5), 0x4787c62a, 12)
307 STEP(
F, c, d, a, b,
SET(6), 0xa8304613, 17)
308 STEP(
F, b, c, d, a,
SET(7), 0xfd469501, 22)
309 STEP(
F, a, b, c, d,
SET(8), 0x698098d8, 7)
310 STEP(
F, d, a, b, c,
SET(9), 0x8b44f7af, 12)
311 STEP(
F, c, d, a, b,
SET(10), 0xffff5bb1, 17)
312 STEP(
F, b, c, d, a,
SET(11), 0x895cd7be, 22)
313 STEP(
F, a, b, c, d,
SET(12), 0x6b901122, 7)
314 STEP(
F, d, a, b, c,
SET(13), 0xfd987193, 12)
315 STEP(
F, c, d, a, b,
SET(14), 0xa679438e, 17)
316 STEP(
F, b, c, d, a,
SET(15), 0x49b40821, 22)
319 STEP(
G, a, b, c, d,
GET(1), 0xf61e2562, 5)
320 STEP(
G, d, a, b, c,
GET(6), 0xc040b340, 9)
321 STEP(
G, c, d, a, b,
GET(11), 0x265e5a51, 14)
322 STEP(
G, b, c, d, a,
GET(0), 0xe9b6c7aa, 20)
323 STEP(
G, a, b, c, d,
GET(5), 0xd62f105d, 5)
324 STEP(
G, d, a, b, c,
GET(10), 0x02441453, 9)
325 STEP(
G, c, d, a, b,
GET(15), 0xd8a1e681, 14)
326 STEP(
G, b, c, d, a,
GET(4), 0xe7d3fbc8, 20)
327 STEP(
G, a, b, c, d,
GET(9), 0x21e1cde6, 5)
328 STEP(
G, d, a, b, c,
GET(14), 0xc33707d6, 9)
329 STEP(
G, c, d, a, b,
GET(3), 0xf4d50d87, 14)
330 STEP(
G, b, c, d, a,
GET(8), 0x455a14ed, 20)
331 STEP(
G, a, b, c, d,
GET(13), 0xa9e3e905, 5)
332 STEP(
G, d, a, b, c,
GET(2), 0xfcefa3f8, 9)
333 STEP(
G, c, d, a, b,
GET(7), 0x676f02d9, 14)
334 STEP(
G, b, c, d, a,
GET(12), 0x8d2a4c8a, 20)
337 STEP(
H, a, b, c, d,
GET(5), 0xfffa3942, 4)
338 STEP(
H2, d, a, b, c,
GET(8), 0x8771f681, 11)
339 STEP(
H, c, d, a, b,
GET(11), 0x6d9d6122, 16)
340 STEP(
H2, b, c, d, a,
GET(14), 0xfde5380c, 23)
341 STEP(
H, a, b, c, d,
GET(1), 0xa4beea44, 4)
342 STEP(
H2, d, a, b, c,
GET(4), 0x4bdecfa9, 11)
343 STEP(
H, c, d, a, b,
GET(7), 0xf6bb4b60, 16)
344 STEP(
H2, b, c, d, a,
GET(10), 0xbebfbc70, 23)
345 STEP(
H, a, b, c, d,
GET(13), 0x289b7ec6, 4)
346 STEP(
H2, d, a, b, c,
GET(0), 0xeaa127fa, 11)
347 STEP(
H, c, d, a, b,
GET(3), 0xd4ef3085, 16)
348 STEP(
H2, b, c, d, a,
GET(6), 0x04881d05, 23)
349 STEP(
H, a, b, c, d,
GET(9), 0xd9d4d039, 4)
350 STEP(
H2, d, a, b, c,
GET(12), 0xe6db99e5, 11)
351 STEP(
H, c, d, a, b,
GET(15), 0x1fa27cf8, 16)
352 STEP(
H2, b, c, d, a,
GET(2), 0xc4ac5665, 23)
355 STEP(
I, a, b, c, d,
GET(0), 0xf4292244, 6)
356 STEP(
I, d, a, b, c,
GET(7), 0x432aff97, 10)
357 STEP(
I, c, d, a, b,
GET(14), 0xab9423a7, 15)
358 STEP(
I, b, c, d, a,
GET(5), 0xfc93a039, 21)
359 STEP(
I, a, b, c, d,
GET(12), 0x655b59c3, 6)
360 STEP(
I, d, a, b, c,
GET(3), 0x8f0ccc92, 10)
361 STEP(
I, c, d, a, b,
GET(10), 0xffeff47d, 15)
362 STEP(
I, b, c, d, a,
GET(1), 0x85845dd1, 21)
363 STEP(
I, a, b, c, d,
GET(8), 0x6fa87e4f, 6)
364 STEP(
I, d, a, b, c,
GET(15), 0xfe2ce6e0, 10)
365 STEP(
I, c, d, a, b,
GET(6), 0xa3014314, 15)
366 STEP(
I, b, c, d, a,
GET(13), 0x4e0811a1, 21)
367 STEP(
I, a, b, c, d,
GET(4), 0xf7537e82, 6)
368 STEP(
I, d, a, b, c,
GET(11), 0xbd3af235, 10)
369 STEP(
I, c, d, a, b,
GET(2), 0x2ad7d2bb, 15)
370 STEP(
I, b, c, d, a,
GET(9), 0xeb86d391, 21)
401 MD5_u32plus saved_lo;
402 unsigned long used, available;
405 ctx->
lo = (saved_lo +
size) & 0x1fffffff;
406 if(ctx->
lo < saved_lo)
410 used = saved_lo & 0x3f;
413 available = 64 - used;
415 if(size < available) {
421 data = (
const unsigned char *)data + available;
427 data =
body(ctx, data, size & ~(
unsigned long)0x3f);
436 unsigned long used, available;
438 used = ctx->
lo & 0x3f;
440 ctx->
buffer[used++] = 0x80;
442 available = 64 - used;
445 memset(&ctx->
buffer[used], 0, available);
451 memset(&ctx->
buffer[used], 0, available - 8);
482 memset(ctx, 0,
sizeof(*ctx));
512 const unsigned char *
input)
525 ctxt =
malloc(
sizeof *ctxt);
545 const unsigned char *
data,
int Curl_MD5_update(MD5_context *context, const unsigned char *data, unsigned int len)
static void MD5_Final(unsigned char *result, MD5_CTX *ctx)
unsigned char curlx_ultouc(unsigned long ulnum)
UNITTEST_START char * ptr
static const void * body(MD5_CTX *ctx, const void *data, unsigned long size)
void Curl_md5it(unsigned char *outbuffer, const unsigned char *input)
UNITTEST_START int result
void(* Curl_MD5_final_func)(unsigned char *result, void *context)
Curl_MD5_init_func md5_init_func
void(* HMAC_hupdate_func)(void *context, const unsigned char *data, unsigned int len)
int Curl_MD5_final(MD5_context *context, unsigned char *result)
static void MD5_Init(MD5_CTX *ctx)
void(* Curl_MD5_init_func)(void *context)
const MD5_params Curl_DIGEST_MD5[]
memcpy(filename, filename1, strlen(filename1))
Curl_MD5_final_func md5_final_func
unsigned int curlx_uztoui(size_t uznum)
#define STEP(f, a, b, c, d, x, t, s)
const HMAC_params Curl_HMAC_MD5[]
TFSIMD_FORCE_INLINE tfScalar length(const Quaternion &q)
Curl_MD5_update_func md5_update_func
static void MD5_Update(MD5_CTX *ctx, const void *data, unsigned long size)
void(* HMAC_hinit_func)(void *context)
MD5_context * Curl_MD5_init(const MD5_params *md5params)
struct MD5Context MD5_CTX
unsigned int md5_ctxtsize
const MD5_params * md5_hash
void(* Curl_MD5_update_func)(void *context, const unsigned char *data, unsigned int len)
void(* HMAC_hfinal_func)(unsigned char *result, void *context)