Artifactspublic-v0

curl

master
ply4 git calls32 ms292 KiB3 cachedprotocol v2
512 lines15 KiBRaw
1/***************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
7 *
8 * Copyright (C) Florin Petriuc, <petriuc.florin@gmail.com>
9 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
10 *
11 * This software is licensed as described in the file COPYING, which
12 * you should have received as part of this distribution. The terms
13 * are also available at https://curl.se/docs/copyright.html.
14 *
15 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
16 * copies of the Software, and permit persons to whom the Software is
17 * furnished to do so, under the terms of the COPYING file.
18 *
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
21 *
22 * SPDX-License-Identifier: curl
23 *
24 ***************************************************************************/
25#include "curl_setup.h"
27#if !defined(CURL_DISABLE_AWS) || !defined(CURL_DISABLE_DIGEST_AUTH) || \
28 defined(USE_LIBSSH2) || defined(USE_SSL)
30#include "curl_sha256.h"
32#ifdef USE_MBEDTLS
33#include <mbedtls/version.h>
34#if MBEDTLS_VERSION_NUMBER < 0x03020000
35#error "mbedTLS 3.2.0 or greater required"
36#endif
37#include <psa/crypto_config.h>
38#endif
40/* Please keep the SSL backend-specific #if branches in this order:
41 *
42 * 1. USE_OPENSSL
43 * 2. USE_WOLFSSL
44 * 3. USE_GNUTLS
45 * 4. USE_MBEDTLS
46 * 5. USE_WIN32_CRYPTO
47 * 6. USE_COMMON_CRYPTO
48 *
49 * This ensures that the same SSL branch gets activated throughout this source
50 * file even if multiple backends are enabled at the same time.
51 */
53#ifdef USE_OPENSSL
54#include <openssl/evp.h>
56struct ossl_sha256_ctx {
57 EVP_MD_CTX *openssl_ctx;
58};
59typedef struct ossl_sha256_ctx my_sha256_ctx;
61static CURLcode my_sha256_init(void *in)
63 my_sha256_ctx *ctx = (my_sha256_ctx *)in;
64 ctx->openssl_ctx = EVP_MD_CTX_new();
65 if(!ctx->openssl_ctx)
66 return CURLE_OUT_OF_MEMORY;
68 if(!EVP_DigestInit_ex(ctx->openssl_ctx, EVP_sha256(), NULL)) {
69 EVP_MD_CTX_free(ctx->openssl_ctx);
70 return CURLE_FAILED_INIT;
71 }
72 return CURLE_OK;
75static void my_sha256_update(void *in,
76 const unsigned char *data,
77 unsigned int length)
79 my_sha256_ctx *ctx = (my_sha256_ctx *)in;
80 EVP_DigestUpdate(ctx->openssl_ctx, data, length);
83static void my_sha256_final(unsigned char *digest, void *in)
85 my_sha256_ctx *ctx = (my_sha256_ctx *)in;
86 EVP_DigestFinal_ex(ctx->openssl_ctx, digest, NULL);
87 EVP_MD_CTX_free(ctx->openssl_ctx);
90#elif defined(USE_WOLFSSL)
91#include <wolfssl/options.h>
92#include <wolfssl/wolfcrypt/sha256.h>
94typedef struct wc_Sha256 my_sha256_ctx;
96static CURLcode my_sha256_init(void *in)
98 if(wc_InitSha256(in))
99 return CURLE_FAILED_INIT;
100 return CURLE_OK;
103static void my_sha256_update(void *in,
104 const unsigned char *data,
105 unsigned int length)
107 (void)wc_Sha256Update(in, data, (word32)length);
110static void my_sha256_final(unsigned char *digest, void *in)
112 (void)wc_Sha256Final(in, digest);
115#elif defined(USE_GNUTLS)
116#include <nettle/sha2.h>
117#include <nettle/version.h>
119typedef struct sha256_ctx my_sha256_ctx;
121static CURLcode my_sha256_init(void *ctx)
123 sha256_init(ctx);
124 return CURLE_OK;
127static void my_sha256_update(void *ctx,
128 const unsigned char *data,
129 unsigned int length)
131 sha256_update(ctx, length, data);
134static void my_sha256_final(unsigned char *digest, void *ctx)
136#if NETTLE_VERSION_MAJOR >= 4
137 sha256_digest(ctx, digest);
138#else
139 sha256_digest(ctx, SHA256_DIGEST_SIZE, digest);
140#endif
143#elif defined(USE_MBEDTLS) && \
144 defined(PSA_WANT_ALG_SHA_256) && PSA_WANT_ALG_SHA_256
145#include <psa/crypto.h>
147typedef psa_hash_operation_t my_sha256_ctx;
149static CURLcode my_sha256_init(void *ctx)
151 psa_hash_operation_t *pctx = (psa_hash_operation_t *)ctx;
152 *pctx = psa_hash_operation_init();
153 if(psa_hash_setup(pctx, PSA_ALG_SHA_256) != PSA_SUCCESS)
154 return CURLE_OUT_OF_MEMORY;
155 return CURLE_OK;
158static void my_sha256_update(void *ctx,
159 const unsigned char *data,
160 unsigned int length)
162 (void)psa_hash_update(ctx, data, length);
165static void my_sha256_final(unsigned char *digest, void *ctx)
167 size_t actual_length;
168 (void)psa_hash_finish(ctx, digest, CURL_SHA256_DIGEST_LENGTH,
169 &actual_length);
172#elif (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && \
173 __MAC_OS_X_VERSION_MAX_ALLOWED >= 1040) || \
174 (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && \
175 __IPHONE_OS_VERSION_MAX_ALLOWED >= 20000)
176#include <CommonCrypto/CommonDigest.h>
178typedef CC_SHA256_CTX my_sha256_ctx;
180static CURLcode my_sha256_init(void *ctx)
182 (void)CC_SHA256_Init(ctx); /* always returns 1 */
183 return CURLE_OK;
186static void my_sha256_update(void *ctx,
187 const unsigned char *data,
188 unsigned int length)
190 (void)CC_SHA256_Update(ctx, data, length);
193static void my_sha256_final(unsigned char *digest, void *ctx)
195 (void)CC_SHA256_Final(digest, ctx);
198#elif defined(USE_WIN32_CRYPTO)
199#include <wincrypt.h>
201struct sha256_ctx {
202 HCRYPTPROV hCryptProv;
203 HCRYPTHASH hHash;
204};
205typedef struct sha256_ctx my_sha256_ctx;
207static CURLcode my_sha256_init(void *in)
209 my_sha256_ctx *ctx = (my_sha256_ctx *)in;
210 if(!CryptAcquireContext(&ctx->hCryptProv, NULL, NULL, PROV_RSA_AES,
211 CRYPT_VERIFYCONTEXT | CRYPT_SILENT))
212 return CURLE_OUT_OF_MEMORY;
214 if(!CryptCreateHash(ctx->hCryptProv, CALG_SHA_256, 0, 0, &ctx->hHash)) {
215 CryptReleaseContext(ctx->hCryptProv, 0);
216 ctx->hCryptProv = 0;
217 return CURLE_FAILED_INIT;
218 }
220 return CURLE_OK;
223static void my_sha256_update(void *in,
224 const unsigned char *data,
225 unsigned int length)
227 my_sha256_ctx *ctx = (my_sha256_ctx *)in;
228 CryptHashData(ctx->hHash, (const BYTE *)data, length, 0);
231static void my_sha256_final(unsigned char *digest, void *in)
233 my_sha256_ctx *ctx = (my_sha256_ctx *)in;
234 unsigned long length = 0;
236 CryptGetHashParam(ctx->hHash, HP_HASHVAL, NULL, &length, 0);
237 if(length == CURL_SHA256_DIGEST_LENGTH)
238 CryptGetHashParam(ctx->hHash, HP_HASHVAL, digest, &length, 0);
240 if(ctx->hHash)
241 CryptDestroyHash(ctx->hHash);
243 if(ctx->hCryptProv)
244 CryptReleaseContext(ctx->hCryptProv, 0);
247#else
249/* When no other crypto library is available we use this code segment */
251/* This is based on the SHA256 implementation in LibTomCrypt that was released
252 * into public domain. */
254#define WPA_GET_BE32(a) \
255 ((((unsigned long)(a)[0]) << 24) | \
256 (((unsigned long)(a)[1]) << 16) | \
257 (((unsigned long)(a)[2]) << 8) | \
258 ((unsigned long)(a)[3]))
259#define WPA_PUT_BE32(a, val) \
260 do { \
261 (a)[0] = (unsigned char)((((unsigned long)(val)) >> 24) & 0xff); \
262 (a)[1] = (unsigned char)((((unsigned long)(val)) >> 16) & 0xff); \
263 (a)[2] = (unsigned char)((((unsigned long)(val)) >> 8) & 0xff); \
264 (a)[3] = (unsigned char)(((unsigned long)(val)) & 0xff); \
265 } while(0)
267#define WPA_PUT_BE64(a, val) \
268 do { \
269 (a)[0] = (unsigned char)(((uint64_t)(val)) >> 56); \
270 (a)[1] = (unsigned char)(((uint64_t)(val)) >> 48); \
271 (a)[2] = (unsigned char)(((uint64_t)(val)) >> 40); \
272 (a)[3] = (unsigned char)(((uint64_t)(val)) >> 32); \
273 (a)[4] = (unsigned char)(((uint64_t)(val)) >> 24); \
274 (a)[5] = (unsigned char)(((uint64_t)(val)) >> 16); \
275 (a)[6] = (unsigned char)(((uint64_t)(val)) >> 8); \
276 (a)[7] = (unsigned char)(((uint64_t)(val)) & 0xff); \
277 } while(0)
279struct sha256_state {
280 uint64_t length;
281 unsigned long state[8], curlen;
282 unsigned char buf[64];
283};
284typedef struct sha256_state my_sha256_ctx;
286/* The K array */
287static const unsigned long K[64] = {
288 0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL, 0x3956c25bUL,
289 0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL, 0xd807aa98UL, 0x12835b01UL,
290 0x243185beUL, 0x550c7dc3UL, 0x72be5d74UL, 0x80deb1feUL, 0x9bdc06a7UL,
291 0xc19bf174UL, 0xe49b69c1UL, 0xefbe4786UL, 0x0fc19dc6UL, 0x240ca1ccUL,
292 0x2de92c6fUL, 0x4a7484aaUL, 0x5cb0a9dcUL, 0x76f988daUL, 0x983e5152UL,
293 0xa831c66dUL, 0xb00327c8UL, 0xbf597fc7UL, 0xc6e00bf3UL, 0xd5a79147UL,
294 0x06ca6351UL, 0x14292967UL, 0x27b70a85UL, 0x2e1b2138UL, 0x4d2c6dfcUL,
295 0x53380d13UL, 0x650a7354UL, 0x766a0abbUL, 0x81c2c92eUL, 0x92722c85UL,
296 0xa2bfe8a1UL, 0xa81a664bUL, 0xc24b8b70UL, 0xc76c51a3UL, 0xd192e819UL,
297 0xd6990624UL, 0xf40e3585UL, 0x106aa070UL, 0x19a4c116UL, 0x1e376c08UL,
298 0x2748774cUL, 0x34b0bcb5UL, 0x391c0cb3UL, 0x4ed8aa4aUL, 0x5b9cca4fUL,
299 0x682e6ff3UL, 0x748f82eeUL, 0x78a5636fUL, 0x84c87814UL, 0x8cc70208UL,
300 0x90befffaUL, 0xa4506cebUL, 0xbef9a3f7UL, 0xc67178f2UL
301};
303/* Various logical functions */
304#define RORc(x, y) \
305 (((((unsigned long)(x) & 0xFFFFFFFFUL) >> (unsigned long)((y) & 31)) | \
306 ((unsigned long)(x) << (unsigned long)(32 - ((y) & 31)))) & 0xFFFFFFFFUL)
308#define Sha256_Ch(x, y, z) (z ^ (x & (y ^ z)))
309#define Sha256_Maj(x, y, z) (((x | y) & z) | (x & y))
310#define Sha256_S(x, n) RORc(x, n)
311#define Sha256_R(x, n) (((x) & 0xFFFFFFFFUL) >> (n))
313#define Sigma0(x) (Sha256_S(x, 2) ^ Sha256_S(x, 13) ^ Sha256_S(x, 22))
314#define Sigma1(x) (Sha256_S(x, 6) ^ Sha256_S(x, 11) ^ Sha256_S(x, 25))
315#define Gamma0(x) (Sha256_S(x, 7) ^ Sha256_S(x, 18) ^ Sha256_R(x, 3))
316#define Gamma1(x) (Sha256_S(x, 17) ^ Sha256_S(x, 19) ^ Sha256_R(x, 10))
318/* Compress 512 bits */
319static int sha256_compress(struct sha256_state *md, const unsigned char *buf)
321 unsigned long S[8], W[64];
322 int i;
324 /* Copy state into S */
325 for(i = 0; i < 8; i++) {
326 S[i] = md->state[i];
327 }
328 /* copy the state into 512 bits into W[0..15] */
329 for(i = 0; i < 16; i++)
330 W[i] = WPA_GET_BE32(buf + (4 * i));
331 /* fill W[16..63] */
332 for(i = 16; i < 64; i++) {
333 W[i] = Gamma1(W[i - 2]) + W[i - 7] + Gamma0(W[i - 15]) + W[i - 16];
334 }
336 /* Compress */
337#define RND(a, b, c, d, e, f, g, h, i) \
338 do { \
339 unsigned long t0 = h + Sigma1(e) + Sha256_Ch(e, f, g) + K[i] + W[i]; \
340 unsigned long t1 = Sigma0(a) + Sha256_Maj(a, b, c); \
341 d += t0; \
342 h = t0 + t1; \
343 } while(0)
345 for(i = 0; i < 64; ++i) {
346 unsigned long t;
347 RND(S[0], S[1], S[2], S[3], S[4], S[5], S[6], S[7], i);
348 t = S[7];
349 S[7] = S[6];
350 S[6] = S[5];
351 S[5] = S[4];
352 S[4] = S[3];
353 S[3] = S[2];
354 S[2] = S[1];
355 S[1] = S[0];
356 S[0] = t;
357 }
359 /* Feedback */
360 for(i = 0; i < 8; i++) {
361 md->state[i] = md->state[i] + S[i];
362 }
364 return 0;
367/* Initialize the hash state */
368static CURLcode my_sha256_init(void *in)
370 struct sha256_state *md = (struct sha256_state *)in;
371 md->curlen = 0;
372 md->length = 0;
373 md->state[0] = 0x6A09E667UL;
374 md->state[1] = 0xBB67AE85UL;
375 md->state[2] = 0x3C6EF372UL;
376 md->state[3] = 0xA54FF53AUL;
377 md->state[4] = 0x510E527FUL;
378 md->state[5] = 0x9B05688CUL;
379 md->state[6] = 0x1F83D9ABUL;
380 md->state[7] = 0x5BE0CD19UL;
382 return CURLE_OK;
385/* Process a block of memory though the hash
386 @param md The hash state
387 @param in The data to hash
388 @param inlen The length of the data (octets)
389 */
390static void my_sha256_update(void *ctx,
391 const unsigned char *in,
392 unsigned int len)
394 unsigned long inlen = len;
395 unsigned long n;
396 struct sha256_state *md = (struct sha256_state *)ctx;
397#define CURL_SHA256_BLOCK_SIZE 64
398 if(md->curlen > sizeof(md->buf))
399 return;
400 while(inlen > 0) {
401 if(md->curlen == 0 && inlen >= CURL_SHA256_BLOCK_SIZE) {
402 if(sha256_compress(md, in) < 0)
403 return;
404 md->length += CURL_SHA256_BLOCK_SIZE * 8;
405 in += CURL_SHA256_BLOCK_SIZE;
406 inlen -= CURL_SHA256_BLOCK_SIZE;
407 }
408 else {
409 n = CURLMIN(inlen, (CURL_SHA256_BLOCK_SIZE - md->curlen));
410 memcpy(md->buf + md->curlen, in, n);
411 md->curlen += n;
412 in += n;
413 inlen -= n;
414 if(md->curlen == CURL_SHA256_BLOCK_SIZE) {
415 if(sha256_compress(md, md->buf) < 0)
416 return;
417 md->length += 8 * CURL_SHA256_BLOCK_SIZE;
418 md->curlen = 0;
419 }
420 }
421 }
424/* Terminate the hash to get the digest
425 @param md The hash state
426 @param out [out] The destination of the hash (32 bytes)
427 @return 0 if successful
428 */
429static void my_sha256_final(unsigned char *out, void *ctx)
431 struct sha256_state *md = ctx;
432 int i;
434 if(md->curlen >= sizeof(md->buf))
435 return;
437 /* Increase the length of the message */
438 md->length += md->curlen * 8;
440 /* Append the '1' bit */
441 md->buf[md->curlen++] = (unsigned char)0x80;
443 /* If the length is currently above 56 bytes we append zeros
444 * then compress. Then we can fall back to padding zeros and length
445 * encoding like normal.
446 */
447 if(md->curlen > 56) {
448 while(md->curlen < 64) {
449 md->buf[md->curlen++] = 0;
450 }
451 sha256_compress(md, md->buf);
452 md->curlen = 0;
453 }
455 /* Pad up to 56 bytes of zeroes */
456 while(md->curlen < 56) {
457 md->buf[md->curlen++] = 0;
458 }
460 /* Store length */
461 WPA_PUT_BE64(md->buf + 56, md->length);
462 sha256_compress(md, md->buf);
464 /* Copy output */
465 for(i = 0; i < 8; i++)
466 WPA_PUT_BE32(out + (4 * i), md->state[i]);
469#endif /* CRYPTO LIBS */
471/*
472 * Curl_sha256it()
473 *
474 * Generates a SHA256 hash for the given input data.
475 *
476 * Parameters:
477 *
478 * output [in/out] - The output buffer.
479 * input [in] - The input data.
480 * length [in] - The input length.
481 *
482 * Returns CURLE_OK on success.
483 */
484CURLcode Curl_sha256it(unsigned char *output, const unsigned char *input,
485 size_t len)
487 CURLcode result;
488 my_sha256_ctx ctx;
490 result = my_sha256_init(&ctx);
491 if(!result) {
492 do {
493 unsigned int ilen = (unsigned int)CURLMIN(len, UINT_MAX);
494 my_sha256_update(&ctx, input, ilen);
495 len -= ilen;
496 input += ilen;
497 } while(len);
498 my_sha256_final(output, &ctx);
499 }
500 return result;
503const struct HMAC_params Curl_HMAC_SHA256 = {
504 my_sha256_init, /* Hash initialization function. */
505 my_sha256_update, /* Hash update function. */
506 my_sha256_final, /* Hash computation end function. */
507 sizeof(my_sha256_ctx), /* Size of hash context structure. */
508 64, /* Maximum key length. */
509 32 /* Result size. */
510};
512#endif /* AWS, DIGEST, or libssh2 */
Diagnostics4 git calls · 32 ms
CallStatusSizeTime032 ms
discover200152 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
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 · hit3 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=149
git.response.cache=HIT
git.response.duration_ms=3
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 · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=293470
git.response.cache=HIT
git.response.duration_ms=3
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=86
Open pack map
fetch2004.9 KiB · hit26 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=26
git.response.bytes=5060
git.response.cache=HIT
git.response.duration_ms=26
git.fetch.wants=a6b1f1373cb6a75f970286cd8696d9533a0e9670
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=5060
git.pkt.payload.max=5039
git.sideband.band1.bytes=5038
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
a5e2bd898febcfc3
Request
ef14ec96…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format