Skip to content

Commit 3d57696

Browse files
authored
Update BoringSSL to ab7811ee8751ea699b22095caa70246f641ed3a2 (#289)
1 parent e1f6ac1 commit 3d57696

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+3825
-1984
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import PackageDescription
2222
// Sources/CNIOBoringSSL directory. The source repository is at
2323
// https://boringssl.googlesource.com/boringssl.
2424
//
25-
// BoringSSL Commit: 04b3213d43492b6c9e0434d8e2a4530a9938f958
25+
// BoringSSL Commit: ab7811ee8751ea699b22095caa70246f641ed3a2
2626

2727
let package = Package(
2828
name: "swift-nio-ssl",

Sources/CNIOBoringSSL/crypto/asn1/a_bool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ int i2d_ASN1_BOOLEAN(int a, unsigned char **pp)
7878
}
7979

8080
ASN1_put_object(&p, 0, 1, V_ASN1_BOOLEAN, V_ASN1_UNIVERSAL);
81-
*p = (unsigned char)a;
81+
*p = a ? 0xff : 0x00;
8282

8383
/*
8484
* If a new buffer was allocated, just return it back.

Sources/CNIOBoringSSL/crypto/asn1/a_type.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,28 @@
6666

6767
int ASN1_TYPE_get(const ASN1_TYPE *a)
6868
{
69-
if ((a->value.ptr != NULL) || (a->type == V_ASN1_NULL))
70-
return (a->type);
71-
else
72-
return (0);
69+
if (a->type == V_ASN1_BOOLEAN || a->type == V_ASN1_NULL ||
70+
a->value.ptr != NULL) {
71+
return a->type;
72+
}
73+
return 0;
7374
}
7475

75-
void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value)
76+
const void *asn1_type_value_as_pointer(const ASN1_TYPE *a)
7677
{
77-
if (a->value.ptr != NULL) {
78-
ASN1_TYPE **tmp_a = &a;
79-
ASN1_primitive_free((ASN1_VALUE **)tmp_a, NULL);
78+
if (a->type == V_ASN1_BOOLEAN) {
79+
return a->value.boolean ? (void *)0xff : NULL;
80+
}
81+
if (a->type == V_ASN1_NULL) {
82+
return NULL;
8083
}
84+
return a->value.ptr;
85+
}
86+
87+
void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value)
88+
{
89+
ASN1_TYPE **tmp_a = &a;
90+
ASN1_primitive_free((ASN1_VALUE **)tmp_a, NULL);
8191
a->type = type;
8292
if (type == V_ASN1_BOOLEAN)
8393
a->value.boolean = value ? 0xff : 0;

Sources/CNIOBoringSSL/crypto/asn1/asn1_lib.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,7 @@ int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)
370370

371371
void ASN1_STRING_set0(ASN1_STRING *str, void *data, int len)
372372
{
373-
if (str->data)
374-
OPENSSL_free(str->data);
373+
OPENSSL_free(str->data);
375374
str->data = data;
376375
str->length = len;
377376
}

Sources/CNIOBoringSSL/crypto/asn1/asn1_locl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval,
126126
int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen,
127127
const ASN1_ITEM *it);
128128

129+
/* asn1_type_value_as_pointer returns |a|'s value in pointer form. This is
130+
* usually the value object but, for BOOLEAN values, is 0 or 0xff cast to
131+
* a pointer. */
132+
const void *asn1_type_value_as_pointer(const ASN1_TYPE *a);
133+
129134

130135
#if defined(__cplusplus)
131136
} /* extern C */

Sources/CNIOBoringSSL/crypto/asn1/tasn_enc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ static int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,
569569
if (!*tbool && !it->size)
570570
return -1;
571571
}
572-
c = (unsigned char)*tbool;
572+
c = *tbool ? 0xff : 0x00;
573573
cont = &c;
574574
len = 1;
575575
break;

Sources/CNIOBoringSSL/crypto/asn1/tasn_fre.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
192192
ASN1_TYPE *typ = (ASN1_TYPE *)*pval;
193193
utype = typ->type;
194194
pval = &typ->value.asn1_value;
195-
if (!*pval)
195+
if (utype != V_ASN1_BOOLEAN && !*pval)
196196
return;
197197
} else if (it->itype == ASN1_ITYPE_MSTRING) {
198198
utype = -1;

Sources/CNIOBoringSSL/crypto/cipher_extra/e_tls.c

Lines changed: 1 addition & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ static int aead_tls_open(const EVP_AEAD_CTX *ctx, uint8_t *out, size_t *out_len,
343343
if (EVP_CIPHER_CTX_mode(&tls_ctx->cipher_ctx) == EVP_CIPH_CBC_MODE &&
344344
EVP_tls_cbc_record_digest_supported(tls_ctx->hmac_ctx.md)) {
345345
if (!EVP_tls_cbc_digest_record(tls_ctx->hmac_ctx.md, mac, &mac_len,
346-
ad_fixed, out, data_plus_mac_len, total,
346+
ad_fixed, out, data_len, total,
347347
tls_ctx->mac_key, tls_ctx->mac_key_len)) {
348348
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_BAD_DECRYPT);
349349
return 0;
@@ -406,14 +406,6 @@ static int aead_aes_128_cbc_sha1_tls_implicit_iv_init(
406406
EVP_sha1(), 1);
407407
}
408408

409-
static int aead_aes_128_cbc_sha256_tls_init(EVP_AEAD_CTX *ctx,
410-
const uint8_t *key, size_t key_len,
411-
size_t tag_len,
412-
enum evp_aead_direction_t dir) {
413-
return aead_tls_init(ctx, key, key_len, tag_len, dir, EVP_aes_128_cbc(),
414-
EVP_sha256(), 0);
415-
}
416-
417409
static int aead_aes_256_cbc_sha1_tls_init(EVP_AEAD_CTX *ctx, const uint8_t *key,
418410
size_t key_len, size_t tag_len,
419411
enum evp_aead_direction_t dir) {
@@ -428,22 +420,6 @@ static int aead_aes_256_cbc_sha1_tls_implicit_iv_init(
428420
EVP_sha1(), 1);
429421
}
430422

431-
static int aead_aes_256_cbc_sha256_tls_init(EVP_AEAD_CTX *ctx,
432-
const uint8_t *key, size_t key_len,
433-
size_t tag_len,
434-
enum evp_aead_direction_t dir) {
435-
return aead_tls_init(ctx, key, key_len, tag_len, dir, EVP_aes_256_cbc(),
436-
EVP_sha256(), 0);
437-
}
438-
439-
static int aead_aes_256_cbc_sha384_tls_init(EVP_AEAD_CTX *ctx,
440-
const uint8_t *key, size_t key_len,
441-
size_t tag_len,
442-
enum evp_aead_direction_t dir) {
443-
return aead_tls_init(ctx, key, key_len, tag_len, dir, EVP_aes_256_cbc(),
444-
EVP_sha384(), 0);
445-
}
446-
447423
static int aead_des_ede3_cbc_sha1_tls_init(EVP_AEAD_CTX *ctx,
448424
const uint8_t *key, size_t key_len,
449425
size_t tag_len,
@@ -513,23 +489,6 @@ static const EVP_AEAD aead_aes_128_cbc_sha1_tls_implicit_iv = {
513489
aead_tls_tag_len,
514490
};
515491

516-
static const EVP_AEAD aead_aes_128_cbc_sha256_tls = {
517-
SHA256_DIGEST_LENGTH + 16, // key len (SHA256 + AES128)
518-
16, // nonce len (IV)
519-
16 + SHA256_DIGEST_LENGTH, // overhead (padding + SHA256)
520-
SHA256_DIGEST_LENGTH, // max tag length
521-
0, // seal_scatter_supports_extra_in
522-
523-
NULL, // init
524-
aead_aes_128_cbc_sha256_tls_init,
525-
aead_tls_cleanup,
526-
aead_tls_open,
527-
aead_tls_seal_scatter,
528-
NULL, // open_gather
529-
NULL, // get_iv
530-
aead_tls_tag_len,
531-
};
532-
533492
static const EVP_AEAD aead_aes_256_cbc_sha1_tls = {
534493
SHA_DIGEST_LENGTH + 32, // key len (SHA1 + AES256)
535494
16, // nonce len (IV)
@@ -564,40 +523,6 @@ static const EVP_AEAD aead_aes_256_cbc_sha1_tls_implicit_iv = {
564523
aead_tls_tag_len,
565524
};
566525

567-
static const EVP_AEAD aead_aes_256_cbc_sha256_tls = {
568-
SHA256_DIGEST_LENGTH + 32, // key len (SHA256 + AES256)
569-
16, // nonce len (IV)
570-
16 + SHA256_DIGEST_LENGTH, // overhead (padding + SHA256)
571-
SHA256_DIGEST_LENGTH, // max tag length
572-
0, // seal_scatter_supports_extra_in
573-
574-
NULL, // init
575-
aead_aes_256_cbc_sha256_tls_init,
576-
aead_tls_cleanup,
577-
aead_tls_open,
578-
aead_tls_seal_scatter,
579-
NULL, // open_gather
580-
NULL, // get_iv
581-
aead_tls_tag_len,
582-
};
583-
584-
static const EVP_AEAD aead_aes_256_cbc_sha384_tls = {
585-
SHA384_DIGEST_LENGTH + 32, // key len (SHA384 + AES256)
586-
16, // nonce len (IV)
587-
16 + SHA384_DIGEST_LENGTH, // overhead (padding + SHA384)
588-
SHA384_DIGEST_LENGTH, // max tag length
589-
0, // seal_scatter_supports_extra_in
590-
591-
NULL, // init
592-
aead_aes_256_cbc_sha384_tls_init,
593-
aead_tls_cleanup,
594-
aead_tls_open,
595-
aead_tls_seal_scatter,
596-
NULL, // open_gather
597-
NULL, // get_iv
598-
aead_tls_tag_len,
599-
};
600-
601526
static const EVP_AEAD aead_des_ede3_cbc_sha1_tls = {
602527
SHA_DIGEST_LENGTH + 24, // key len (SHA1 + 3DES)
603528
8, // nonce len (IV)
@@ -657,10 +582,6 @@ const EVP_AEAD *EVP_aead_aes_128_cbc_sha1_tls_implicit_iv(void) {
657582
return &aead_aes_128_cbc_sha1_tls_implicit_iv;
658583
}
659584

660-
const EVP_AEAD *EVP_aead_aes_128_cbc_sha256_tls(void) {
661-
return &aead_aes_128_cbc_sha256_tls;
662-
}
663-
664585
const EVP_AEAD *EVP_aead_aes_256_cbc_sha1_tls(void) {
665586
return &aead_aes_256_cbc_sha1_tls;
666587
}
@@ -669,14 +590,6 @@ const EVP_AEAD *EVP_aead_aes_256_cbc_sha1_tls_implicit_iv(void) {
669590
return &aead_aes_256_cbc_sha1_tls_implicit_iv;
670591
}
671592

672-
const EVP_AEAD *EVP_aead_aes_256_cbc_sha256_tls(void) {
673-
return &aead_aes_256_cbc_sha256_tls;
674-
}
675-
676-
const EVP_AEAD *EVP_aead_aes_256_cbc_sha384_tls(void) {
677-
return &aead_aes_256_cbc_sha384_tls;
678-
}
679-
680593
const EVP_AEAD *EVP_aead_des_ede3_cbc_sha1_tls(void) {
681594
return &aead_des_ede3_cbc_sha1_tls;
682595
}

Sources/CNIOBoringSSL/crypto/cipher_extra/internal.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,17 @@ void EVP_tls_cbc_copy_mac(uint8_t *out, size_t md_size, const uint8_t *in,
9999
// which EVP_tls_cbc_digest_record supports.
100100
int EVP_tls_cbc_record_digest_supported(const EVP_MD *md);
101101

102+
// EVP_sha1_final_with_secret_suffix computes the result of hashing |len| bytes
103+
// from |in| to |ctx| and writes the resulting hash to |out|. |len| is treated
104+
// as secret and must be at most |max_len|, which is treated as public. |in|
105+
// must point to a buffer of at least |max_len| bytes. It returns one on success
106+
// and zero if inputs are too long.
107+
//
108+
// This function is exported for unit tests.
109+
OPENSSL_EXPORT int EVP_sha1_final_with_secret_suffix(
110+
SHA_CTX *ctx, uint8_t out[SHA_DIGEST_LENGTH], const uint8_t *in, size_t len,
111+
size_t max_len);
112+
102113
// EVP_tls_cbc_digest_record computes the MAC of a decrypted, padded TLS
103114
// record.
104115
//
@@ -108,8 +119,8 @@ int EVP_tls_cbc_record_digest_supported(const EVP_MD *md);
108119
// md_out_size: the number of output bytes is written here.
109120
// header: the 13-byte, TLS record header.
110121
// data: the record data itself
111-
// data_plus_mac_size: the secret, reported length of the data and MAC
112-
// once the padding has been removed.
122+
// data_size: the secret, reported length of the data once the padding and MAC
123+
// have been removed.
113124
// data_plus_mac_plus_padding_size: the public length of the whole
114125
// record, including padding.
115126
//
@@ -119,7 +130,7 @@ int EVP_tls_cbc_record_digest_supported(const EVP_MD *md);
119130
// padding too. )
120131
int EVP_tls_cbc_digest_record(const EVP_MD *md, uint8_t *md_out,
121132
size_t *md_out_size, const uint8_t header[13],
122-
const uint8_t *data, size_t data_plus_mac_size,
133+
const uint8_t *data, size_t data_size,
123134
size_t data_plus_mac_plus_padding_size,
124135
const uint8_t *mac_secret,
125136
unsigned mac_secret_length);

0 commit comments

Comments
 (0)