master
1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9 *
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at https://curl.se/docs/copyright.html.
13 *
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 * SPDX-License-Identifier: curl
22 *
23 ***************************************************************************/
24#include "curl_setup.h"
26#ifndef CURL_DISABLE_DIGEST_AUTH
28#include "curl_md5.h"
29#include "curl_hmac.h"
31#ifdef USE_OPENSSL
32#include <openssl/opensslconf.h>
33#endif
35#ifdef USE_WOLFSSL
36#include <wolfssl/options.h>
37#endif
39#ifdef USE_MBEDTLS
40#include <mbedtls/version.h>
41#if MBEDTLS_VERSION_NUMBER < 0x03020000
42#error "mbedTLS 3.2.0 or greater required"
43#endif
44#include <psa/crypto_config.h>
45#endif
47#ifdef USE_GNUTLS
48#include <nettle/md5.h>
49#include <nettle/version.h>
51typedef struct md5_ctx my_md5_ctx;
53static CURLcode my_md5_init(void *ctx)
54{
55 md5_init(ctx);
56 return CURLE_OK;
57}
59static void my_md5_update(void *ctx,
60 const unsigned char *input, unsigned int len)
61{
62 md5_update(ctx, len, input);
63}
65static void my_md5_final(unsigned char *digest, void *ctx)
66{
67#if NETTLE_VERSION_MAJOR >= 4
68 md5_digest(ctx, digest);
69#else
70 md5_digest(ctx, MD5_DIGEST_LEN, digest);
71#endif
72}
74#elif defined(USE_OPENSSL) && !defined(OPENSSL_NO_MD5)
75#include <openssl/evp.h>
77typedef EVP_MD_CTX *my_md5_ctx;
79static CURLcode my_md5_init(void *in)
80{
81 EVP_MD_CTX **ctx = (EVP_MD_CTX **)in;
82 *ctx = EVP_MD_CTX_new();
83 if(!*ctx)
84 return CURLE_OUT_OF_MEMORY;
86 if(!EVP_DigestInit_ex(*ctx, EVP_md5(), NULL)) {
87 EVP_MD_CTX_free(*ctx);
88 *ctx = NULL;
89 return CURLE_FAILED_INIT;
90 }
91 return CURLE_OK;
92}
94static void my_md5_update(void *in,
95 const unsigned char *input, unsigned int len)
96{
97 EVP_MD_CTX **ctx = (EVP_MD_CTX **)in;
98 (void)EVP_DigestUpdate(*ctx, input, len);
99}
101static void my_md5_final(unsigned char *digest, void *in)
102{
103 EVP_MD_CTX **ctx = (EVP_MD_CTX **)in;
104 (void)EVP_DigestFinal_ex(*ctx, digest, NULL);
105 EVP_MD_CTX_free(*ctx);
106 *ctx = NULL;
107}
109#elif defined(USE_WOLFSSL) && !defined(NO_MD5)
110#include <wolfssl/wolfcrypt/md5.h>
112typedef wc_Md5 my_md5_ctx;
114static CURLcode my_md5_init(void *ctx)
115{
116 if(wc_InitMd5(ctx))
117 return CURLE_OUT_OF_MEMORY;
118 return CURLE_OK;
119}
121static void my_md5_update(void *ctx,
122 const unsigned char *input, unsigned int len)
123{
124 (void)wc_Md5Update(ctx, input, (word32)len);
125}
127static void my_md5_final(unsigned char *digest, void *ctx)
128{
129 (void)wc_Md5Final(ctx, digest);
130}
132#elif defined(USE_MBEDTLS) && \
133 defined(PSA_WANT_ALG_MD5) && PSA_WANT_ALG_MD5
134#include <psa/crypto.h>
136typedef psa_hash_operation_t my_md5_ctx;
138static CURLcode my_md5_init(void *ctx)
139{
140 psa_hash_operation_t *pctx = (psa_hash_operation_t *)ctx;
141 *pctx = psa_hash_operation_init();
142 if(psa_hash_setup(pctx, PSA_ALG_MD5) != PSA_SUCCESS)
143 return CURLE_OUT_OF_MEMORY;
144 return CURLE_OK;
145}
147static void my_md5_update(void *ctx,
148 const unsigned char *input, unsigned int len)
149{
150 (void)psa_hash_update(ctx, input, len);
151}
153static void my_md5_final(unsigned char *digest, void *ctx)
154{
155 size_t actual_length;
156 (void)psa_hash_finish(ctx, digest, MD5_DIGEST_LEN, &actual_length);
157}
159#elif (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && \
160 __MAC_OS_X_VERSION_MAX_ALLOWED >= 1040 && \
161 defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && \
162 __MAC_OS_X_VERSION_MIN_REQUIRED < 101500) || \
163 (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && \
164 __IPHONE_OS_VERSION_MAX_ALLOWED >= 20000 && \
165 defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && \
166 __IPHONE_OS_VERSION_MIN_REQUIRED < 130000)
167#include <CommonCrypto/CommonDigest.h>
169/* For Apple operating systems: CommonCrypto has the functions we need.
170 These functions are available on Tiger and later, as well as iOS 2.0
171 and later. If you are building for an older cat, well, sorry.
173 Declaring the functions as static like this seems to be a bit more
174 reliable than defining COMMON_DIGEST_FOR_OPENSSL on older cats. */
175# define my_md5_ctx CC_MD5_CTX
177static CURLcode my_md5_init(void *ctx)
178{
179 (void)CC_MD5_Init(ctx); /* always returns 1 */
180 return CURLE_OK;
181}
183static void my_md5_update(void *ctx,
184 const unsigned char *input, unsigned int len)
185{
186 CC_MD5_Update(ctx, input, len);
187}
189static void my_md5_final(unsigned char *digest, void *ctx)
190{
191 CC_MD5_Final(digest, ctx);
192}
194#elif defined(USE_WIN32_CRYPTO)
195#include <wincrypt.h>
197struct md5_ctx {
198 HCRYPTPROV hCryptProv;
199 HCRYPTHASH hHash;
200};
201typedef struct md5_ctx my_md5_ctx;
203static CURLcode my_md5_init(void *in)
204{
205 my_md5_ctx *ctx = (my_md5_ctx *)in;
206 if(!CryptAcquireContext(&ctx->hCryptProv, NULL, NULL, PROV_RSA_FULL,
207 CRYPT_VERIFYCONTEXT | CRYPT_SILENT))
208 return CURLE_OUT_OF_MEMORY;
210 if(!CryptCreateHash(ctx->hCryptProv, CALG_MD5, 0, 0, &ctx->hHash)) {
211 CryptReleaseContext(ctx->hCryptProv, 0);
212 ctx->hCryptProv = 0;
213 return CURLE_FAILED_INIT;
214 }
216 return CURLE_OK;
217}
219static void my_md5_update(void *in,
220 const unsigned char *input, unsigned int len)
221{
222 my_md5_ctx *ctx = in;
223 CryptHashData(ctx->hHash, (const BYTE *)input, len, 0);
224}
226static void my_md5_final(unsigned char *digest, void *in)
227{
228 my_md5_ctx *ctx = (my_md5_ctx *)in;
229 unsigned long length = 0;
230 CryptGetHashParam(ctx->hHash, HP_HASHVAL, NULL, &length, 0);
231 if(length == MD5_DIGEST_LEN)
232 CryptGetHashParam(ctx->hHash, HP_HASHVAL, digest, &length, 0);
233 if(ctx->hHash)
234 CryptDestroyHash(ctx->hHash);
235 if(ctx->hCryptProv)
236 CryptReleaseContext(ctx->hCryptProv, 0);
237}
239#else
241/* When no other crypto library is available we use this code segment */
243/*
244 * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc.
245 * MD5 Message-Digest Algorithm (RFC 1321).
246 *
247 * Homepage:
248 * https://openwall.info/wiki/people/solar/software/public-domain-source-code/md5
249 *
250 * Author:
251 * Alexander Peslyak, better known as Solar Designer <solar at openwall.com>
252 *
253 * This software was written by Alexander Peslyak in 2001. No copyright is
254 * claimed, and the software is hereby placed in the public domain. In case
255 * this attempt to disclaim copyright and place the software in the public
256 * domain is deemed null and void, then the software is Copyright (c) 2001
257 * Alexander Peslyak and it is hereby released to the general public under
258 * the following terms:
259 *
260 * Redistribution and use in source and binary forms, with or without
261 * modification, are permitted.
262 *
263 * There is ABSOLUTELY NO WARRANTY, express or implied.
264 *
265 * (This is a heavily cut-down "BSD license".)
266 */
268struct md5_ctx {
269 uint32_t lo, hi;
270 uint32_t a, b, c, d;
271 unsigned char buffer[64];
272 uint32_t block[16];
273};
274typedef struct md5_ctx my_md5_ctx;
276/*
277 * The basic MD5 functions.
278 *
279 * F and G are optimized compared to their RFC 1321 definitions for
280 * architectures that lack an AND-NOT instruction, like in Colin Plumb's
281 * implementation.
282 */
283#define MD5_F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
284#define MD5_G(x, y, z) ((y) ^ ((z) & ((x) ^ (y))))
285#define MD5_H(x, y, z) (((x) ^ (y)) ^ (z))
286#define MD5_H2(x, y, z) ((x) ^ ((y) ^ (z)))
287#define MD5_I(x, y, z) ((y) ^ ((x) | ~(z)))
289/*
290 * The MD5 transformation for all four rounds.
291 */
292#define MD5_STEP(f, a, b, c, d, x, t, s) \
293 (a) += f(b, c, d) + (x) + (t); \
294 (a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); \
295 (a) += (b);
297/*
298 * SET reads 4 input bytes in little-endian byte order and stores them
299 * in a properly aligned word in host byte order.
300 *
301 * The check for little-endian architectures that tolerate unaligned memory
302 * accesses is an optimization. Nothing will break if it does not work.
303 */
304#if defined(__i386__) || defined(__x86_64__) || defined(__vax__)
305#define MD5_SET(n) (*(const uint32_t *)(const void *)&ptr[(n) * 4])
306#define MD5_GET(n) MD5_SET(n)
307#else
308#define MD5_SET(n) (ctx->block[n] = \
309 (uint32_t)ptr[(n) * 4] | \
310 ((uint32_t)ptr[((n) * 4) + 1] << 8) | \
311 ((uint32_t)ptr[((n) * 4) + 2] << 16) | \
312 ((uint32_t)ptr[((n) * 4) + 3] << 24))
313#define MD5_GET(n) ctx->block[n]
314#endif
316/*
317 * This processes one or more 64-byte data blocks, but does NOT update
318 * the bit counters. There are no alignment requirements.
319 */
320static const void *my_md5_body(my_md5_ctx *ctx,
321 const void *data, unsigned long size)
322{
323 const unsigned char *ptr;
324 uint32_t a, b, c, d;
326 ptr = (const unsigned char *)data;
328 a = ctx->a;
329 b = ctx->b;
330 c = ctx->c;
331 d = ctx->d;
333 do {
334 uint32_t saved_a, saved_b, saved_c, saved_d;
336 saved_a = a;
337 saved_b = b;
338 saved_c = c;
339 saved_d = d;
341 /* Round 1 */
342 MD5_STEP(MD5_F, a, b, c, d, MD5_SET(0), 0xd76aa478, 7)
343 MD5_STEP(MD5_F, d, a, b, c, MD5_SET(1), 0xe8c7b756, 12)
344 MD5_STEP(MD5_F, c, d, a, b, MD5_SET(2), 0x242070db, 17)
345 MD5_STEP(MD5_F, b, c, d, a, MD5_SET(3), 0xc1bdceee, 22)
346 MD5_STEP(MD5_F, a, b, c, d, MD5_SET(4), 0xf57c0faf, 7)
347 MD5_STEP(MD5_F, d, a, b, c, MD5_SET(5), 0x4787c62a, 12)
348 MD5_STEP(MD5_F, c, d, a, b, MD5_SET(6), 0xa8304613, 17)
349 MD5_STEP(MD5_F, b, c, d, a, MD5_SET(7), 0xfd469501, 22)
350 MD5_STEP(MD5_F, a, b, c, d, MD5_SET(8), 0x698098d8, 7)
351 MD5_STEP(MD5_F, d, a, b, c, MD5_SET(9), 0x8b44f7af, 12)
352 MD5_STEP(MD5_F, c, d, a, b, MD5_SET(10), 0xffff5bb1, 17)
353 MD5_STEP(MD5_F, b, c, d, a, MD5_SET(11), 0x895cd7be, 22)
354 MD5_STEP(MD5_F, a, b, c, d, MD5_SET(12), 0x6b901122, 7)
355 MD5_STEP(MD5_F, d, a, b, c, MD5_SET(13), 0xfd987193, 12)
356 MD5_STEP(MD5_F, c, d, a, b, MD5_SET(14), 0xa679438e, 17)
357 MD5_STEP(MD5_F, b, c, d, a, MD5_SET(15), 0x49b40821, 22)
359 /* Round 2 */
360 MD5_STEP(MD5_G, a, b, c, d, MD5_GET(1), 0xf61e2562, 5)
361 MD5_STEP(MD5_G, d, a, b, c, MD5_GET(6), 0xc040b340, 9)
362 MD5_STEP(MD5_G, c, d, a, b, MD5_GET(11), 0x265e5a51, 14)
363 MD5_STEP(MD5_G, b, c, d, a, MD5_GET(0), 0xe9b6c7aa, 20)
364 MD5_STEP(MD5_G, a, b, c, d, MD5_GET(5), 0xd62f105d, 5)
365 MD5_STEP(MD5_G, d, a, b, c, MD5_GET(10), 0x02441453, 9)
366 MD5_STEP(MD5_G, c, d, a, b, MD5_GET(15), 0xd8a1e681, 14)
367 MD5_STEP(MD5_G, b, c, d, a, MD5_GET(4), 0xe7d3fbc8, 20)
368 MD5_STEP(MD5_G, a, b, c, d, MD5_GET(9), 0x21e1cde6, 5)
369 MD5_STEP(MD5_G, d, a, b, c, MD5_GET(14), 0xc33707d6, 9)
370 MD5_STEP(MD5_G, c, d, a, b, MD5_GET(3), 0xf4d50d87, 14)
371 MD5_STEP(MD5_G, b, c, d, a, MD5_GET(8), 0x455a14ed, 20)
372 MD5_STEP(MD5_G, a, b, c, d, MD5_GET(13), 0xa9e3e905, 5)
373 MD5_STEP(MD5_G, d, a, b, c, MD5_GET(2), 0xfcefa3f8, 9)
374 MD5_STEP(MD5_G, c, d, a, b, MD5_GET(7), 0x676f02d9, 14)
375 MD5_STEP(MD5_G, b, c, d, a, MD5_GET(12), 0x8d2a4c8a, 20)
377 /* Round 3 */
378 MD5_STEP(MD5_H, a, b, c, d, MD5_GET(5), 0xfffa3942, 4)
379 MD5_STEP(MD5_H2, d, a, b, c, MD5_GET(8), 0x8771f681, 11)
380 MD5_STEP(MD5_H, c, d, a, b, MD5_GET(11), 0x6d9d6122, 16)
381 MD5_STEP(MD5_H2, b, c, d, a, MD5_GET(14), 0xfde5380c, 23)
382 MD5_STEP(MD5_H, a, b, c, d, MD5_GET(1), 0xa4beea44, 4)
383 MD5_STEP(MD5_H2, d, a, b, c, MD5_GET(4), 0x4bdecfa9, 11)
384 MD5_STEP(MD5_H, c, d, a, b, MD5_GET(7), 0xf6bb4b60, 16)
385 MD5_STEP(MD5_H2, b, c, d, a, MD5_GET(10), 0xbebfbc70, 23)
386 MD5_STEP(MD5_H, a, b, c, d, MD5_GET(13), 0x289b7ec6, 4)
387 MD5_STEP(MD5_H2, d, a, b, c, MD5_GET(0), 0xeaa127fa, 11)
388 MD5_STEP(MD5_H, c, d, a, b, MD5_GET(3), 0xd4ef3085, 16)
389 MD5_STEP(MD5_H2, b, c, d, a, MD5_GET(6), 0x04881d05, 23)
390 MD5_STEP(MD5_H, a, b, c, d, MD5_GET(9), 0xd9d4d039, 4)
391 MD5_STEP(MD5_H2, d, a, b, c, MD5_GET(12), 0xe6db99e5, 11)
392 MD5_STEP(MD5_H, c, d, a, b, MD5_GET(15), 0x1fa27cf8, 16)
393 MD5_STEP(MD5_H2, b, c, d, a, MD5_GET(2), 0xc4ac5665, 23)
395 /* Round 4 */
396 MD5_STEP(MD5_I, a, b, c, d, MD5_GET(0), 0xf4292244, 6)
397 MD5_STEP(MD5_I, d, a, b, c, MD5_GET(7), 0x432aff97, 10)
398 MD5_STEP(MD5_I, c, d, a, b, MD5_GET(14), 0xab9423a7, 15)
399 MD5_STEP(MD5_I, b, c, d, a, MD5_GET(5), 0xfc93a039, 21)
400 MD5_STEP(MD5_I, a, b, c, d, MD5_GET(12), 0x655b59c3, 6)
401 MD5_STEP(MD5_I, d, a, b, c, MD5_GET(3), 0x8f0ccc92, 10)
402 MD5_STEP(MD5_I, c, d, a, b, MD5_GET(10), 0xffeff47d, 15)
403 MD5_STEP(MD5_I, b, c, d, a, MD5_GET(1), 0x85845dd1, 21)
404 MD5_STEP(MD5_I, a, b, c, d, MD5_GET(8), 0x6fa87e4f, 6)
405 MD5_STEP(MD5_I, d, a, b, c, MD5_GET(15), 0xfe2ce6e0, 10)
406 MD5_STEP(MD5_I, c, d, a, b, MD5_GET(6), 0xa3014314, 15)
407 MD5_STEP(MD5_I, b, c, d, a, MD5_GET(13), 0x4e0811a1, 21)
408 MD5_STEP(MD5_I, a, b, c, d, MD5_GET(4), 0xf7537e82, 6)
409 MD5_STEP(MD5_I, d, a, b, c, MD5_GET(11), 0xbd3af235, 10)
410 MD5_STEP(MD5_I, c, d, a, b, MD5_GET(2), 0x2ad7d2bb, 15)
411 MD5_STEP(MD5_I, b, c, d, a, MD5_GET(9), 0xeb86d391, 21)
413 a += saved_a;
414 b += saved_b;
415 c += saved_c;
416 d += saved_d;
418 ptr += 64;
419 } while(size -= 64);
421 ctx->a = a;
422 ctx->b = b;
423 ctx->c = c;
424 ctx->d = d;
426 return ptr;
427}
429static CURLcode my_md5_init(void *in)
430{
431 my_md5_ctx *ctx = (my_md5_ctx *)in;
432 ctx->a = 0x67452301;
433 ctx->b = 0xefcdab89;
434 ctx->c = 0x98badcfe;
435 ctx->d = 0x10325476;
437 ctx->lo = 0;
438 ctx->hi = 0;
440 return CURLE_OK;
441}
443static void my_md5_update(void *in,
444 const unsigned char *input, unsigned int len)
445{
446 uint32_t saved_lo;
447 unsigned int used;
448 my_md5_ctx *ctx = (my_md5_ctx *)in;
450 saved_lo = ctx->lo;
451 ctx->lo = (saved_lo + len) & 0x1fffffff;
452 if(ctx->lo < saved_lo)
453 ctx->hi++;
454 ctx->hi += (uint32_t)len >> 29;
456 used = saved_lo & 0x3f;
458 if(used) {
459 unsigned int available = 64 - used;
461 if(len < available) {
462 memcpy(&ctx->buffer[used], input, len);
463 return;
464 }
466 memcpy(&ctx->buffer[used], input, available);
467 input = (const unsigned char *)input + available;
468 len -= available;
469 my_md5_body(ctx, ctx->buffer, 64);
470 }
472 if(len >= 64) {
473 input = my_md5_body(ctx, input, len & ~(unsigned long)0x3f);
474 len &= 0x3f;
475 }
477 memcpy(ctx->buffer, input, len);
478}
480static void my_md5_final(unsigned char *digest, void *in)
481{
482 unsigned int used, available;
483 my_md5_ctx *ctx = (my_md5_ctx *)in;
485 used = ctx->lo & 0x3f;
487 ctx->buffer[used++] = 0x80;
489 available = 64 - used;
491 if(available < 8) {
492 memset(&ctx->buffer[used], 0, available);
493 my_md5_body(ctx, ctx->buffer, 64);
494 used = 0;
495 available = 64;
496 }
498 memset(&ctx->buffer[used], 0, available - 8);
500 ctx->lo <<= 3;
501 ctx->buffer[56] = curlx_ultouc((ctx->lo) & 0xff);
502 ctx->buffer[57] = curlx_ultouc((ctx->lo >> 8) & 0xff);
503 ctx->buffer[58] = curlx_ultouc((ctx->lo >> 16) & 0xff);
504 ctx->buffer[59] = curlx_ultouc(ctx->lo >> 24);
505 ctx->buffer[60] = curlx_ultouc((ctx->hi) & 0xff);
506 ctx->buffer[61] = curlx_ultouc((ctx->hi >> 8) & 0xff);
507 ctx->buffer[62] = curlx_ultouc((ctx->hi >> 16) & 0xff);
508 ctx->buffer[63] = curlx_ultouc(ctx->hi >> 24);
510 my_md5_body(ctx, ctx->buffer, 64);
512 digest[0] = curlx_ultouc((ctx->a) & 0xff);
513 digest[1] = curlx_ultouc((ctx->a >> 8) & 0xff);
514 digest[2] = curlx_ultouc((ctx->a >> 16) & 0xff);
515 digest[3] = curlx_ultouc(ctx->a >> 24);
516 digest[4] = curlx_ultouc((ctx->b) & 0xff);
517 digest[5] = curlx_ultouc((ctx->b >> 8) & 0xff);
518 digest[6] = curlx_ultouc((ctx->b >> 16) & 0xff);
519 digest[7] = curlx_ultouc(ctx->b >> 24);
520 digest[8] = curlx_ultouc((ctx->c) & 0xff);
521 digest[9] = curlx_ultouc((ctx->c >> 8) & 0xff);
522 digest[10] = curlx_ultouc((ctx->c >> 16) & 0xff);
523 digest[11] = curlx_ultouc(ctx->c >> 24);
524 digest[12] = curlx_ultouc((ctx->d) & 0xff);
525 digest[13] = curlx_ultouc((ctx->d >> 8) & 0xff);
526 digest[14] = curlx_ultouc((ctx->d >> 16) & 0xff);
527 digest[15] = curlx_ultouc(ctx->d >> 24);
529 memset(ctx, 0, sizeof(*ctx));
530}
532#endif /* CRYPTO LIBS */
534const struct HMAC_params Curl_HMAC_MD5 = {
535 my_md5_init, /* Hash initialization function. */
536 my_md5_update, /* Hash update function. */
537 my_md5_final, /* Hash computation end function. */
538 sizeof(my_md5_ctx), /* Size of hash context structure. */
539 64, /* Maximum key length. */
540 MD5_DIGEST_LEN /* Result size. */
541};
543const struct MD5_params Curl_DIGEST_MD5 = {
544 my_md5_init, /* Digest initialization function */
545 my_md5_update, /* Digest update function */
546 my_md5_final, /* Digest computation end function */
547 sizeof(my_md5_ctx), /* Size of digest context struct */
548 MD5_DIGEST_LEN /* Result size */
549};
551/*
552 * @unittest: 1601
553 * Returns CURLE_OK on success.
554 */
555CURLcode Curl_md5it(unsigned char *output,
556 const unsigned char *input, size_t len)
557{
558 CURLcode result;
559 my_md5_ctx ctx;
561 result = my_md5_init(&ctx);
562 if(!result) {
563 do {
564 unsigned int ilen = (unsigned int)CURLMIN(len, UINT_MAX);
565 my_md5_update(&ctx, input, ilen);
566 input += ilen;
567 len -= ilen;
568 } while(len);
569 my_md5_final(output, &ctx);
570 }
571 return result;
572}
574struct MD5_context *Curl_MD5_init(const struct MD5_params *md5params)
575{
576 struct MD5_context *ctxt;
578 /* Create MD5 context */
579 ctxt = curlx_malloc(sizeof(*ctxt));
581 if(!ctxt)
582 return ctxt;
584 ctxt->md5_hashctx = curlx_malloc(md5params->md5_ctxtsize);
586 if(!ctxt->md5_hashctx) {
587 curlx_free(ctxt);
588 return NULL;
589 }
591 ctxt->md5_hash = md5params;
593 if((*md5params->md5_init_func)(ctxt->md5_hashctx)) {
594 curlx_free(ctxt->md5_hashctx);
595 curlx_free(ctxt);
596 return NULL;
597 }
599 return ctxt;
600}
602CURLcode Curl_MD5_update(struct MD5_context *context,
603 const unsigned char *input, unsigned int len)
604{
605 (*context->md5_hash->md5_update_func)(context->md5_hashctx, input, len);
607 return CURLE_OK;
608}
610CURLcode Curl_MD5_final(struct MD5_context *context, unsigned char *result)
611{
612 (*context->md5_hash->md5_final_func)(result, context->md5_hashctx);
614 curlx_free(context->md5_hashctx);
615 curlx_free(context);
617 return CURLE_OK;
618}
620#endif /* Digest */
Diagnostics4 git calls · 344 ms
CallStatusSizeTime0344 ms
discover200152 B5 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200149 B · hit4 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=4 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=4 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=149 git.pkt.payload.max=78 git.ls_refs.count=2 git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit4 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=335 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=4 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=10 git.pkt.data=8 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=293470 git.pkt.payload.max=65516 git.sideband.band1.bytes=293354 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=87 git.pack.bytes=293354 git.pack.ofs_delta=0 git.pack.ref_delta=1 git.pack.chain.max=1 git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0 git.pack.full=86Open pack map
fetch2005.5 KiB335 ms
git.upload-pack fetch http.response.status_code=200 git.response.bytes=5683 git.response.cache=MISS git.response.duration_ms=335 git.fetch.wants=5bcc2b8d4ed37bbbf141ec87fbef271b59ee3a71 git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=5683 git.pkt.payload.max=5662 git.sideband.band1.bytes=5661 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
- Ref
- refs/heads/master
- Commit
- 31c911efe5652725e930f4d2e60c9060e5f6646d
- cf-ray
- a5e172d9aa226102
- Request
- 8c4a3979…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format