Skip to content

Commit

Permalink
Update BoringSSL to a9670a8b476470e6f874fef3554e8059683e1413
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukasa authored and glbrntt committed Nov 10, 2021
1 parent d549440 commit 4b7979a
Show file tree
Hide file tree
Showing 140 changed files with 4,189 additions and 3,542 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import class Foundation.ProcessInfo
// Sources/CNIOBoringSSL directory. The source repository is at
// https://boringssl.googlesource.com/boringssl.
//
// BoringSSL Commit: 25773430c07075a368416c3646fa4b07daf4968a
// BoringSSL Commit: a9670a8b476470e6f874fef3554e8059683e1413

/// This function generates the dependencies we want to express.
///
Expand Down
30 changes: 19 additions & 11 deletions Sources/CNIOBoringSSL/crypto/asn1/a_bitstr.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,25 @@
#include <CNIOBoringSSL_mem.h>

#include "../internal.h"
#include "internal.h"


int ASN1_BIT_STRING_set(ASN1_BIT_STRING *x, const unsigned char *d, int len)
{
return ASN1_STRING_set(x, d, len);
}

static int asn1_bit_string_length(const ASN1_BIT_STRING *str,
uint8_t *out_padding_bits) {
int asn1_bit_string_length(const ASN1_BIT_STRING *str,
uint8_t *out_padding_bits) {
int len = str->length;
if (str->flags & ASN1_STRING_FLAG_BITS_LEFT) {
// If the string is already empty, it cannot have padding bits.
*out_padding_bits = len == 0 ? 0 : str->flags & 0x07;
return len;
}

// TODO(davidben): If we move this logic to |ASN1_BIT_STRING_set_bit|, can
// we remove this representation?
// TODO(https://crbug.com/boringssl/447): If we move this logic to
// |ASN1_BIT_STRING_set_bit|, can we remove this representation?
while (len > 0 && str->data[len - 1] == 0) {
len--;
}
Expand Down Expand Up @@ -158,33 +159,40 @@ ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,

p = *pp;
padding = *(p++);
len--;
if (padding > 7) {
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_BIT_STRING_BITS_LEFT);
goto err;
}

/* Unused bits in a BIT STRING must be zero. */
uint8_t padding_mask = (1 << padding) - 1;
if (padding != 0 &&
(len < 1 || (p[len - 1] & padding_mask) != 0)) {
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_BIT_STRING_PADDING);
goto err;
}

/*
* We do this to preserve the settings. If we modify the settings, via
* the _set_bit function, we will recalculate on output
*/
ret->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07); /* clear */
ret->flags |= (ASN1_STRING_FLAG_BITS_LEFT | padding); /* set */

if (len-- > 1) { /* using one because of the bits left byte */
s = (unsigned char *)OPENSSL_malloc((int)len);
if (len > 0) {
s = OPENSSL_memdup(p, len);
if (s == NULL) {
OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
goto err;
}
OPENSSL_memcpy(s, p, (int)len);
s[len - 1] &= (0xff << padding);
p += len;
} else
} else {
s = NULL;
}

ret->length = (int)len;
if (ret->data != NULL)
OPENSSL_free(ret->data);
OPENSSL_free(ret->data);
ret->data = s;
ret->type = V_ASN1_BIT_STRING;
if (a != NULL)
Expand Down
43 changes: 21 additions & 22 deletions Sources/CNIOBoringSSL/crypto/asn1/a_bool.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
#include <CNIOBoringSSL_err.h>
#include <CNIOBoringSSL_mem.h>

int i2d_ASN1_BOOLEAN(int a, unsigned char **pp)
int i2d_ASN1_BOOLEAN(ASN1_BOOLEAN a, unsigned char **pp)
{
int r;
unsigned char *p, *allocated = NULL;
Expand All @@ -71,7 +71,7 @@ int i2d_ASN1_BOOLEAN(int a, unsigned char **pp)
if (*pp == NULL) {
if ((p = allocated = OPENSSL_malloc(r)) == NULL) {
OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
return 0;
return -1;
}
} else {
p = *pp;
Expand All @@ -88,36 +88,35 @@ int i2d_ASN1_BOOLEAN(int a, unsigned char **pp)
return r;
}

int d2i_ASN1_BOOLEAN(int *a, const unsigned char **pp, long length)
{
int ret = -1;
const unsigned char *p;
ASN1_BOOLEAN d2i_ASN1_BOOLEAN(ASN1_BOOLEAN *a, const unsigned char **pp,
long length) {
const unsigned char *p = *pp;
long len;
int inf, tag, xclass;
int i = 0;

p = *pp;
inf = ASN1_get_object(&p, &len, &tag, &xclass, length);
if (inf & 0x80) {
i = ASN1_R_BAD_OBJECT_HEADER;
goto err;
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_OBJECT_HEADER);
return -1;
}

if (tag != V_ASN1_BOOLEAN) {
i = ASN1_R_EXPECTING_A_BOOLEAN;
goto err;
if (inf & V_ASN1_CONSTRUCTED) {
OPENSSL_PUT_ERROR(ASN1, ASN1_R_TYPE_NOT_PRIMITIVE);
return -1;
}

if (tag != V_ASN1_BOOLEAN || xclass != V_ASN1_UNIVERSAL) {
OPENSSL_PUT_ERROR(ASN1, ASN1_R_EXPECTING_A_BOOLEAN);
return -1;
}

if (len != 1) {
i = ASN1_R_BOOLEAN_IS_WRONG_LENGTH;
goto err;
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BOOLEAN_IS_WRONG_LENGTH);
return -1;
}
ret = (int)*(p++);
if (a != NULL)
ASN1_BOOLEAN ret = (ASN1_BOOLEAN)*(p++);
if (a != NULL) {
(*a) = ret;
}
*pp = p;
return (ret);
err:
OPENSSL_PUT_ERROR(ASN1, i);
return (ret);
return ret;
}
91 changes: 54 additions & 37 deletions Sources/CNIOBoringSSL/crypto/asn1/a_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,26 @@

int i2d_ASN1_OBJECT(const ASN1_OBJECT *a, unsigned char **pp)
{
unsigned char *p, *allocated = NULL;
int objsize;
if (a == NULL) {
OPENSSL_PUT_ERROR(ASN1, ERR_R_PASSED_NULL_PARAMETER);
return -1;
}

if ((a == NULL) || (a->data == NULL))
return (0);
if (a->length == 0) {
OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_OBJECT);
return -1;
}

objsize = ASN1_object_size(0, a->length, V_ASN1_OBJECT);
if (pp == NULL || objsize == -1)
int objsize = ASN1_object_size(0, a->length, V_ASN1_OBJECT);
if (pp == NULL || objsize == -1) {
return objsize;
}

unsigned char *p, *allocated = NULL;
if (*pp == NULL) {
if ((p = allocated = OPENSSL_malloc(objsize)) == NULL) {
OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
return 0;
return -1;
}
} else {
p = *pp;
Expand All @@ -104,54 +110,65 @@ int i2t_ASN1_OBJECT(char *buf, int buf_len, const ASN1_OBJECT *a)
return OBJ_obj2txt(buf, buf_len, a, 0);
}

static int write_str(BIO *bp, const char *str)
{
int len = strlen(str);
return BIO_write(bp, str, len) == len ? len : -1;
}

int i2a_ASN1_OBJECT(BIO *bp, const ASN1_OBJECT *a)
{
char buf[80], *p = buf;
int i;
if (a == NULL || a->data == NULL) {
return write_str(bp, "NULL");
}

if ((a == NULL) || (a->data == NULL))
return (BIO_write(bp, "NULL", 4));
i = i2t_ASN1_OBJECT(buf, sizeof buf, a);
if (i > (int)(sizeof(buf) - 1)) {
p = OPENSSL_malloc(i + 1);
if (!p)
char buf[80], *allocated = NULL;
const char *str = buf;
int len = i2t_ASN1_OBJECT(buf, sizeof(buf), a);
if (len > (int)sizeof(buf) - 1) {
/* The input was truncated. Allocate a buffer that fits. */
allocated = OPENSSL_malloc(len + 1);
if (allocated == NULL) {
return -1;
i2t_ASN1_OBJECT(p, i + 1, a);
}
len = i2t_ASN1_OBJECT(allocated, len + 1, a);
str = allocated;
}
if (len <= 0) {
str = "<INVALID>";
}
if (i <= 0)
return BIO_write(bp, "<INVALID>", 9);
BIO_write(bp, p, i);
if (p != buf)
OPENSSL_free(p);
return (i);

int ret = write_str(bp, str);
OPENSSL_free(allocated);
return ret;
}

ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
long length)
{
const unsigned char *p;
long len;
int tag, xclass;
int inf, i;
ASN1_OBJECT *ret = NULL;
p = *pp;
inf = ASN1_get_object(&p, &len, &tag, &xclass, length);
const unsigned char *p = *pp;
int inf = ASN1_get_object(&p, &len, &tag, &xclass, length);
if (inf & 0x80) {
i = ASN1_R_BAD_OBJECT_HEADER;
goto err;
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_OBJECT_HEADER);
return NULL;
}

if (tag != V_ASN1_OBJECT) {
i = ASN1_R_EXPECTING_AN_OBJECT;
goto err;
if (inf & V_ASN1_CONSTRUCTED) {
OPENSSL_PUT_ERROR(ASN1, ASN1_R_TYPE_NOT_PRIMITIVE);
return NULL;
}
ret = c2i_ASN1_OBJECT(a, &p, len);
if (ret)

if (tag != V_ASN1_OBJECT || xclass != V_ASN1_UNIVERSAL) {
OPENSSL_PUT_ERROR(ASN1, ASN1_R_EXPECTING_AN_OBJECT);
return NULL;
}
ASN1_OBJECT *ret = c2i_ASN1_OBJECT(a, &p, len);
if (ret) {
*pp = p;
}
return ret;
err:
OPENSSL_PUT_ERROR(ASN1, i);
return (NULL);
}

ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
Expand Down
Loading

0 comments on commit 4b7979a

Please sign in to comment.