Skip to content

Commit c03c909

Browse files
nodejs-github-botaduh95
authored andcommitted
deps: update ngtcp2 to 1.25.0
PR-URL: #64944 Reviewed-By: Tim Perry <pimterry@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent ebbb978 commit c03c909

35 files changed

Lines changed: 899 additions & 679 deletions

deps/ngtcp2/ngtcp2/crypto/boringssl/boringssl.c

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -278,33 +278,44 @@ int ngtcp2_crypto_cipher_ctx_encrypt_init(ngtcp2_crypto_cipher_ctx *cipher_ctx,
278278
const uint8_t *key) {
279279
ngtcp2_crypto_boringssl_cipher *hp_cipher = cipher->native_handle;
280280
ngtcp2_crypto_boringssl_cipher_ctx *ctx;
281-
int rv;
282-
(void)rv;
281+
int rv = 0;
283282

284283
ctx = malloc(sizeof(*ctx));
285284
if (ctx == NULL) {
286285
return -1;
287286
}
288287

289-
ctx->type = hp_cipher->type;
290-
cipher_ctx->native_handle = ctx;
291-
292288
switch (hp_cipher->type) {
293289
case NGTCP2_CRYPTO_BORINGSSL_CIPHER_TYPE_AES_128:
294-
rv = AES_set_encrypt_key(key, 128, &ctx->aes_key);
295-
assert(0 == rv);
296-
return 0;
290+
if (AES_set_encrypt_key(key, 128, &ctx->aes_key) != 0) {
291+
rv = -1;
292+
}
293+
294+
break;
297295
case NGTCP2_CRYPTO_BORINGSSL_CIPHER_TYPE_AES_256:
298-
rv = AES_set_encrypt_key(key, 256, &ctx->aes_key);
299-
assert(0 == rv);
300-
return 0;
296+
if (AES_set_encrypt_key(key, 256, &ctx->aes_key) != 0) {
297+
rv = -1;
298+
}
299+
300+
break;
301301
case NGTCP2_CRYPTO_BORINGSSL_CIPHER_TYPE_CHACHA20:
302302
memcpy(ctx->key, key, sizeof(ctx->key));
303-
return 0;
303+
break;
304304
default:
305305
assert(0);
306306
abort();
307307
};
308+
309+
if (rv != 0) {
310+
free(ctx);
311+
312+
return rv;
313+
}
314+
315+
ctx->type = hp_cipher->type;
316+
cipher_ctx->native_handle = ctx;
317+
318+
return 0;
308319
}
309320

310321
void ngtcp2_crypto_cipher_ctx_free(ngtcp2_crypto_cipher_ctx *cipher_ctx) {

deps/ngtcp2/ngtcp2/crypto/ossl/ossl.c

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -730,8 +730,8 @@ int ngtcp2_crypto_hkdf_extract(uint8_t *dest, const ngtcp2_crypto_md *md,
730730
const uint8_t *secret, size_t secretlen,
731731
const uint8_t *salt, size_t saltlen) {
732732
const EVP_MD *prf = md->native_handle;
733-
EVP_KDF *kdf = crypto_kdf_hkdf();
734-
EVP_KDF_CTX *kctx = EVP_KDF_CTX_new(kdf);
733+
EVP_KDF *kdf;
734+
EVP_KDF_CTX *kctx;
735735
int mode = EVP_KDF_HKDF_MODE_EXTRACT_ONLY;
736736
OSSL_PARAM params[] = {
737737
OSSL_PARAM_construct_int(OSSL_KDF_PARAM_MODE, &mode),
@@ -745,13 +745,24 @@ int ngtcp2_crypto_hkdf_extract(uint8_t *dest, const ngtcp2_crypto_md *md,
745745
};
746746
int rv = 0;
747747

748-
crypto_kdf_hkdf_free(kdf);
748+
kdf = crypto_kdf_hkdf();
749+
if (!kdf) {
750+
return -1;
751+
}
752+
753+
kctx = EVP_KDF_CTX_new(kdf);
754+
if (!kctx) {
755+
rv = -1;
756+
goto fail_kdf_ctx_new;
757+
}
749758

750759
if (EVP_KDF_derive(kctx, dest, (size_t)EVP_MD_size(prf), params) <= 0) {
751760
rv = -1;
752761
}
753762

754763
EVP_KDF_CTX_free(kctx);
764+
fail_kdf_ctx_new:
765+
crypto_kdf_hkdf_free(kdf);
755766

756767
return rv;
757768
}
@@ -761,8 +772,8 @@ int ngtcp2_crypto_hkdf_expand(uint8_t *dest, size_t destlen,
761772
size_t secretlen, const uint8_t *info,
762773
size_t infolen) {
763774
const EVP_MD *prf = md->native_handle;
764-
EVP_KDF *kdf = crypto_kdf_hkdf();
765-
EVP_KDF_CTX *kctx = EVP_KDF_CTX_new(kdf);
775+
EVP_KDF *kdf;
776+
EVP_KDF_CTX *kctx;
766777
int mode = EVP_KDF_HKDF_MODE_EXPAND_ONLY;
767778
OSSL_PARAM params[] = {
768779
OSSL_PARAM_construct_int(OSSL_KDF_PARAM_MODE, &mode),
@@ -776,13 +787,24 @@ int ngtcp2_crypto_hkdf_expand(uint8_t *dest, size_t destlen,
776787
};
777788
int rv = 0;
778789

779-
crypto_kdf_hkdf_free(kdf);
790+
kdf = crypto_kdf_hkdf();
791+
if (!kdf) {
792+
return -1;
793+
}
794+
795+
kctx = EVP_KDF_CTX_new(kdf);
796+
if (!kctx) {
797+
rv = -1;
798+
goto fail_kdf_ctx_new;
799+
}
780800

781801
if (EVP_KDF_derive(kctx, dest, destlen, params) <= 0) {
782802
rv = -1;
783803
}
784804

785805
EVP_KDF_CTX_free(kctx);
806+
fail_kdf_ctx_new:
807+
crypto_kdf_hkdf_free(kdf);
786808

787809
return rv;
788810
}
@@ -792,8 +814,8 @@ int ngtcp2_crypto_hkdf(uint8_t *dest, size_t destlen,
792814
size_t secretlen, const uint8_t *salt, size_t saltlen,
793815
const uint8_t *info, size_t infolen) {
794816
const EVP_MD *prf = md->native_handle;
795-
EVP_KDF *kdf = crypto_kdf_hkdf();
796-
EVP_KDF_CTX *kctx = EVP_KDF_CTX_new(kdf);
817+
EVP_KDF *kdf;
818+
EVP_KDF_CTX *kctx;
797819
OSSL_PARAM params[] = {
798820
OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST,
799821
(char *)EVP_MD_get0_name(prf), 0),
@@ -807,13 +829,24 @@ int ngtcp2_crypto_hkdf(uint8_t *dest, size_t destlen,
807829
};
808830
int rv = 0;
809831

810-
crypto_kdf_hkdf_free(kdf);
832+
kdf = crypto_kdf_hkdf();
833+
if (!kdf) {
834+
return -1;
835+
}
836+
837+
kctx = EVP_KDF_CTX_new(kdf);
838+
if (!kctx) {
839+
rv = -1;
840+
goto fail_kdf_ctx_new;
841+
}
811842

812843
if (EVP_KDF_derive(kctx, dest, destlen, params) <= 0) {
813844
rv = -1;
814845
}
815846

816847
EVP_KDF_CTX_free(kctx);
848+
fail_kdf_ctx_new:
849+
crypto_kdf_hkdf_free(kdf);
817850

818851
return rv;
819852
}

deps/ngtcp2/ngtcp2/crypto/quictls/quictls.c

Lines changed: 48 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
#include "shared.h"
4545

4646
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
47-
static int crypto_initialized;
4847
static EVP_CIPHER *crypto_aes_128_gcm;
4948
static EVP_CIPHER *crypto_aes_256_gcm;
5049
static EVP_CIPHER *crypto_chacha20_poly1305;
@@ -57,57 +56,19 @@ static EVP_MD *crypto_sha384;
5756
static EVP_KDF *crypto_hkdf;
5857

5958
int ngtcp2_crypto_quictls_init(void) {
59+
/* We do not care whether the pre-fetch succeeds or not. If it
60+
fails, it returns NULL, which is still the default value, and our
61+
code should still work with it. */
6062
crypto_aes_128_gcm = EVP_CIPHER_fetch(NULL, "AES-128-GCM", NULL);
61-
if (crypto_aes_128_gcm == NULL) {
62-
return -1;
63-
}
64-
6563
crypto_aes_256_gcm = EVP_CIPHER_fetch(NULL, "AES-256-GCM", NULL);
66-
if (crypto_aes_256_gcm == NULL) {
67-
return -1;
68-
}
69-
7064
crypto_chacha20_poly1305 = EVP_CIPHER_fetch(NULL, "ChaCha20-Poly1305", NULL);
71-
if (crypto_chacha20_poly1305 == NULL) {
72-
return -1;
73-
}
74-
7565
crypto_aes_128_ccm = EVP_CIPHER_fetch(NULL, "AES-128-CCM", NULL);
76-
if (crypto_aes_128_ccm == NULL) {
77-
return -1;
78-
}
79-
8066
crypto_aes_128_ecb = EVP_CIPHER_fetch(NULL, "AES-128-ECB", NULL);
81-
if (crypto_aes_128_ecb == NULL) {
82-
return -1;
83-
}
84-
8567
crypto_aes_256_ecb = EVP_CIPHER_fetch(NULL, "AES-256-ECB", NULL);
86-
if (crypto_aes_256_ecb == NULL) {
87-
return -1;
88-
}
89-
9068
crypto_chacha20 = EVP_CIPHER_fetch(NULL, "ChaCha20", NULL);
91-
if (crypto_chacha20 == NULL) {
92-
return -1;
93-
}
94-
9569
crypto_sha256 = EVP_MD_fetch(NULL, "sha256", NULL);
96-
if (crypto_sha256 == NULL) {
97-
return -1;
98-
}
99-
10070
crypto_sha384 = EVP_MD_fetch(NULL, "sha384", NULL);
101-
if (crypto_sha384 == NULL) {
102-
return -1;
103-
}
104-
10571
crypto_hkdf = EVP_KDF_fetch(NULL, "hkdf", NULL);
106-
if (crypto_hkdf == NULL) {
107-
return -1;
108-
}
109-
110-
crypto_initialized = 1;
11172

11273
return 0;
11374
}
@@ -191,6 +152,12 @@ static EVP_KDF *crypto_kdf_hkdf(void) {
191152

192153
return EVP_KDF_fetch(NULL, "hkdf", NULL);
193154
}
155+
156+
static void crypto_kdf_hkdf_free(EVP_KDF *kdf) {
157+
if (kdf && crypto_hkdf != kdf) {
158+
EVP_KDF_free(kdf);
159+
}
160+
}
194161
#else /* !(OPENSSL_VERSION_NUMBER >= 0x30000000L) */
195162
# define crypto_aead_aes_128_gcm EVP_aes_128_gcm
196163
# define crypto_aead_aes_256_gcm EVP_aes_256_gcm
@@ -524,8 +491,8 @@ int ngtcp2_crypto_hkdf_extract(uint8_t *dest, const ngtcp2_crypto_md *md,
524491
const uint8_t *salt, size_t saltlen) {
525492
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
526493
const EVP_MD *prf = md->native_handle;
527-
EVP_KDF *kdf = crypto_kdf_hkdf();
528-
EVP_KDF_CTX *kctx = EVP_KDF_CTX_new(kdf);
494+
EVP_KDF *kdf;
495+
EVP_KDF_CTX *kctx;
529496
int mode = EVP_KDF_HKDF_MODE_EXTRACT_ONLY;
530497
OSSL_PARAM params[] = {
531498
OSSL_PARAM_construct_int(OSSL_KDF_PARAM_MODE, &mode),
@@ -539,15 +506,24 @@ int ngtcp2_crypto_hkdf_extract(uint8_t *dest, const ngtcp2_crypto_md *md,
539506
};
540507
int rv = 0;
541508

542-
if (!crypto_initialized) {
543-
EVP_KDF_free(kdf);
509+
kdf = crypto_kdf_hkdf();
510+
if (!kdf) {
511+
return -1;
512+
}
513+
514+
kctx = EVP_KDF_CTX_new(kdf);
515+
if (!kctx) {
516+
rv = -1;
517+
goto fail_kdf_ctx_new;
544518
}
545519

546520
if (EVP_KDF_derive(kctx, dest, (size_t)EVP_MD_size(prf), params) <= 0) {
547521
rv = -1;
548522
}
549523

550524
EVP_KDF_CTX_free(kctx);
525+
fail_kdf_ctx_new:
526+
crypto_kdf_hkdf_free(kdf);
551527

552528
return rv;
553529
#else /* !(OPENSSL_VERSION_NUMBER >= 0x30000000L) */
@@ -581,8 +557,8 @@ int ngtcp2_crypto_hkdf_expand(uint8_t *dest, size_t destlen,
581557
size_t infolen) {
582558
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
583559
const EVP_MD *prf = md->native_handle;
584-
EVP_KDF *kdf = crypto_kdf_hkdf();
585-
EVP_KDF_CTX *kctx = EVP_KDF_CTX_new(kdf);
560+
EVP_KDF *kdf;
561+
EVP_KDF_CTX *kctx;
586562
int mode = EVP_KDF_HKDF_MODE_EXPAND_ONLY;
587563
OSSL_PARAM params[] = {
588564
OSSL_PARAM_construct_int(OSSL_KDF_PARAM_MODE, &mode),
@@ -596,15 +572,24 @@ int ngtcp2_crypto_hkdf_expand(uint8_t *dest, size_t destlen,
596572
};
597573
int rv = 0;
598574

599-
if (!crypto_initialized) {
600-
EVP_KDF_free(kdf);
575+
kdf = crypto_kdf_hkdf();
576+
if (!kdf) {
577+
return -1;
578+
}
579+
580+
kctx = EVP_KDF_CTX_new(kdf);
581+
if (!kctx) {
582+
rv = -1;
583+
goto fail_kdf_ctx_new;
601584
}
602585

603586
if (EVP_KDF_derive(kctx, dest, destlen, params) <= 0) {
604587
rv = -1;
605588
}
606589

607590
EVP_KDF_CTX_free(kctx);
591+
fail_kdf_ctx_new:
592+
crypto_kdf_hkdf_free(kdf);
608593

609594
return rv;
610595
#else /* !(OPENSSL_VERSION_NUMBER >= 0x30000000L) */
@@ -637,8 +622,8 @@ int ngtcp2_crypto_hkdf(uint8_t *dest, size_t destlen,
637622
const uint8_t *info, size_t infolen) {
638623
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
639624
const EVP_MD *prf = md->native_handle;
640-
EVP_KDF *kdf = crypto_kdf_hkdf();
641-
EVP_KDF_CTX *kctx = EVP_KDF_CTX_new(kdf);
625+
EVP_KDF *kdf;
626+
EVP_KDF_CTX *kctx;
642627
OSSL_PARAM params[] = {
643628
OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST,
644629
(char *)EVP_MD_get0_name(prf), 0),
@@ -652,15 +637,24 @@ int ngtcp2_crypto_hkdf(uint8_t *dest, size_t destlen,
652637
};
653638
int rv = 0;
654639

655-
if (!crypto_initialized) {
656-
EVP_KDF_free(kdf);
640+
kdf = crypto_kdf_hkdf();
641+
if (!kdf) {
642+
return -1;
643+
}
644+
645+
kctx = EVP_KDF_CTX_new(kdf);
646+
if (!kctx) {
647+
rv = -1;
648+
goto fail_kdf_ctx_new;
657649
}
658650

659651
if (EVP_KDF_derive(kctx, dest, destlen, params) <= 0) {
660652
rv = -1;
661653
}
662654

663655
EVP_KDF_CTX_free(kctx);
656+
fail_kdf_ctx_new:
657+
crypto_kdf_hkdf_free(kdf);
664658

665659
return rv;
666660
#else /* !(OPENSSL_VERSION_NUMBER >= 0x30000000L) */

0 commit comments

Comments
 (0)