diff --git a/Package.swift b/Package.swift index c2f91ea6..f83d2b96 100644 --- a/Package.swift +++ b/Package.swift @@ -20,7 +20,7 @@ // Sources/CCryptoBoringSSL directory. The source repository is at // https://boringssl.googlesource.com/boringssl. // -// BoringSSL Commit: 25773430c07075a368416c3646fa4b07daf4968a +// BoringSSL Commit: a9670a8b476470e6f874fef3554e8059683e1413 import PackageDescription diff --git a/Sources/CCryptoBoringSSL/CMakeLists.txt b/Sources/CCryptoBoringSSL/CMakeLists.txt index f3983610..dc7193c2 100644 --- a/Sources/CCryptoBoringSSL/CMakeLists.txt +++ b/Sources/CCryptoBoringSSL/CMakeLists.txt @@ -34,7 +34,6 @@ add_library(CCryptoBoringSSL STATIC "crypto/asn1/asn1_lib.c" "crypto/asn1/asn1_par.c" "crypto/asn1/asn_pack.c" - "crypto/asn1/f_enum.c" "crypto/asn1/f_int.c" "crypto/asn1/f_string.c" "crypto/asn1/tasn_dec.c" diff --git a/Sources/CCryptoBoringSSL/crypto/asn1/a_bitstr.c b/Sources/CCryptoBoringSSL/crypto/asn1/a_bitstr.c index d82fb260..b09f0f29 100644 --- a/Sources/CCryptoBoringSSL/crypto/asn1/a_bitstr.c +++ b/Sources/CCryptoBoringSSL/crypto/asn1/a_bitstr.c @@ -63,6 +63,7 @@ #include #include "../internal.h" +#include "internal.h" int ASN1_BIT_STRING_set(ASN1_BIT_STRING *x, const unsigned char *d, int len) @@ -70,8 +71,8 @@ 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. @@ -79,8 +80,8 @@ static int asn1_bit_string_length(const ASN1_BIT_STRING *str, 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--; } @@ -158,11 +159,20 @@ 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 @@ -170,21 +180,19 @@ ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, 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) diff --git a/Sources/CCryptoBoringSSL/crypto/asn1/a_bool.c b/Sources/CCryptoBoringSSL/crypto/asn1/a_bool.c index df023bad..b6a812b6 100644 --- a/Sources/CCryptoBoringSSL/crypto/asn1/a_bool.c +++ b/Sources/CCryptoBoringSSL/crypto/asn1/a_bool.c @@ -59,7 +59,7 @@ #include #include -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; @@ -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; @@ -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; } diff --git a/Sources/CCryptoBoringSSL/crypto/asn1/a_object.c b/Sources/CCryptoBoringSSL/crypto/asn1/a_object.c index b7a236a8..27ba2954 100644 --- a/Sources/CCryptoBoringSSL/crypto/asn1/a_object.c +++ b/Sources/CCryptoBoringSSL/crypto/asn1/a_object.c @@ -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; @@ -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 (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) - return -1; - i2t_ASN1_OBJECT(p, i + 1, a); + if (a == NULL || a->data == NULL) { + return write_str(bp, "NULL"); } - if (i <= 0) - return BIO_write(bp, "", 9); - BIO_write(bp, p, i); - if (p != buf) - OPENSSL_free(p); - return (i); + + 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; + } + len = i2t_ASN1_OBJECT(allocated, len + 1, a); + str = allocated; + } + if (len <= 0) { + str = ""; + } + + 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, diff --git a/Sources/CCryptoBoringSSL/crypto/asn1/a_strnid.c b/Sources/CCryptoBoringSSL/crypto/asn1/a_strnid.c index 627a7da1..f563a7dd 100644 --- a/Sources/CCryptoBoringSSL/crypto/asn1/a_strnid.c +++ b/Sources/CCryptoBoringSSL/crypto/asn1/a_strnid.c @@ -56,18 +56,23 @@ #include -#include /* For bsearch */ +#include +#include #include #include #include #include -#include -DEFINE_STACK_OF(ASN1_STRING_TABLE) +#include "../internal.h" +#include "../lhash/internal.h" +#include "internal.h" -static STACK_OF(ASN1_STRING_TABLE) *stable = NULL; -static void st_free(ASN1_STRING_TABLE *tbl); + +DEFINE_LHASH_OF(ASN1_STRING_TABLE) + +static LHASH_OF(ASN1_STRING_TABLE) *string_tables = NULL; +static struct CRYPTO_STATIC_MUTEX string_tables_lock = CRYPTO_STATIC_MUTEX_INIT; void ASN1_STRING_set_default_mask(unsigned long mask) { @@ -83,34 +88,36 @@ int ASN1_STRING_set_default_mask_asc(const char *p) return 1; } +static const ASN1_STRING_TABLE *asn1_string_table_get(int nid); + /* * The following function generates an ASN1_STRING based on limits in a * table. Frequently the types and length of an ASN1_STRING are restricted by * a corresponding OID. For example certificates and certificate requests. */ -ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out, - const unsigned char *in, int inlen, - int inform, int nid) +ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out, const unsigned char *in, + int len, int inform, int nid) { - ASN1_STRING_TABLE *tbl; ASN1_STRING *str = NULL; - unsigned long mask; int ret; - if (!out) + if (!out) { out = &str; - tbl = ASN1_STRING_TABLE_get(nid); - if (tbl) { - mask = tbl->mask; - if (!(tbl->flags & STABLE_NO_MASK)) - mask &= B_ASN1_UTF8STRING; - ret = ASN1_mbstring_ncopy(out, in, inlen, inform, mask, - tbl->minsize, tbl->maxsize); - } else { - ret = ASN1_mbstring_copy(out, in, inlen, inform, B_ASN1_UTF8STRING); } - if (ret <= 0) + const ASN1_STRING_TABLE *tbl = asn1_string_table_get(nid); + if (tbl != NULL) { + unsigned long mask = tbl->mask; + if (!(tbl->flags & STABLE_NO_MASK)) { + mask &= B_ASN1_UTF8STRING; + } + ret = ASN1_mbstring_ncopy(out, in, len, inform, mask, tbl->minsize, + tbl->maxsize); + } else { + ret = ASN1_mbstring_copy(out, in, len, inform, B_ASN1_UTF8STRING); + } + if (ret <= 0) { return NULL; + } return *out; } @@ -118,15 +125,13 @@ ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out, * Now the tables and helper functions for the string table: */ -/* size limits: this stuff is taken straight from RFC 3280 */ - +/* See RFC 5280. */ #define ub_name 32768 #define ub_common_name 64 #define ub_locality_name 128 #define ub_state_name 128 #define ub_organization_name 64 #define ub_organization_unit_name 64 -#define ub_title 64 #define ub_email_address 128 #define ub_serial_number 64 @@ -157,120 +162,105 @@ static const ASN1_STRING_TABLE tbl_standard[] = { {NID_ms_csp_name, -1, -1, B_ASN1_BMPSTRING, STABLE_NO_MASK} }; -static int sk_table_cmp(const ASN1_STRING_TABLE **a, - const ASN1_STRING_TABLE **b) +static int table_cmp(const ASN1_STRING_TABLE *a, const ASN1_STRING_TABLE *b) { - return (*a)->nid - (*b)->nid; + if (a->nid < b->nid) { + return -1; + } + if (a->nid > b->nid) { + return 1; + } + return 0; } -static int table_cmp(const void *in_a, const void *in_b) +static int table_cmp_void(const void *a, const void *b) { - const ASN1_STRING_TABLE *a = in_a; - const ASN1_STRING_TABLE *b = in_b; - return a->nid - b->nid; + return table_cmp(a, b); } -ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid) +static uint32_t table_hash(const ASN1_STRING_TABLE *tbl) { - int found; - size_t idx; - ASN1_STRING_TABLE *ttmp; - ASN1_STRING_TABLE fnd; - fnd.nid = nid; - - ttmp = - bsearch(&fnd, tbl_standard, - sizeof(tbl_standard) / sizeof(ASN1_STRING_TABLE), - sizeof(ASN1_STRING_TABLE), table_cmp); - if (ttmp) - return ttmp; - if (!stable) - return NULL; - sk_ASN1_STRING_TABLE_sort(stable); - found = sk_ASN1_STRING_TABLE_find(stable, &idx, &fnd); - if (!found) - return NULL; - return sk_ASN1_STRING_TABLE_value(stable, idx); + return OPENSSL_hash32(&tbl->nid, sizeof(tbl->nid)); } -int ASN1_STRING_TABLE_add(int nid, - long minsize, long maxsize, unsigned long mask, - unsigned long flags) +static const ASN1_STRING_TABLE *asn1_string_table_get(int nid) { - ASN1_STRING_TABLE *tmp; - char new_nid = 0; - flags &= ~STABLE_FLAGS_MALLOC; - if (!stable) - stable = sk_ASN1_STRING_TABLE_new(sk_table_cmp); - if (!stable) { - OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE); + ASN1_STRING_TABLE key; + key.nid = nid; + const ASN1_STRING_TABLE *tbl = + bsearch(&key, tbl_standard, OPENSSL_ARRAY_SIZE(tbl_standard), + sizeof(ASN1_STRING_TABLE), table_cmp_void); + if (tbl != NULL) { + return tbl; + } + + CRYPTO_STATIC_MUTEX_lock_read(&string_tables_lock); + if (string_tables != NULL) { + tbl = lh_ASN1_STRING_TABLE_retrieve(string_tables, &key); + } + CRYPTO_STATIC_MUTEX_unlock_read(&string_tables_lock); + /* Note returning |tbl| without the lock is only safe because + * |ASN1_STRING_TABLE_add| cannot modify or delete existing entries. If we + * wish to support that, this function must copy the result under a lock. */ + return tbl; +} + +int ASN1_STRING_TABLE_add(int nid, long minsize, long maxsize, + unsigned long mask, unsigned long flags) +{ + /* Existing entries cannot be overwritten. */ + if (asn1_string_table_get(nid) != NULL) { + OPENSSL_PUT_ERROR(ASN1, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); return 0; } - if (!(tmp = ASN1_STRING_TABLE_get(nid))) { - tmp = OPENSSL_malloc(sizeof(ASN1_STRING_TABLE)); - if (!tmp) { - OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE); - return 0; + + int ret = 0; + CRYPTO_STATIC_MUTEX_lock_write(&string_tables_lock); + + if (string_tables == NULL) { + string_tables = lh_ASN1_STRING_TABLE_new(table_hash, table_cmp); + if (string_tables == NULL) { + goto err; } - tmp->flags = flags | STABLE_FLAGS_MALLOC; - tmp->nid = nid; - tmp->minsize = tmp->maxsize = -1; - new_nid = 1; - } else - tmp->flags = (tmp->flags & STABLE_FLAGS_MALLOC) | flags; - if (minsize != -1) - tmp->minsize = minsize; - if (maxsize != -1) - tmp->maxsize = maxsize; - tmp->mask = mask; - if (new_nid) - sk_ASN1_STRING_TABLE_push(stable, tmp); - return 1; + } else { + /* Check again for an existing entry. One may have been added while + * unlocked. */ + ASN1_STRING_TABLE key; + key.nid = nid; + if (lh_ASN1_STRING_TABLE_retrieve(string_tables, &key) != NULL) { + OPENSSL_PUT_ERROR(ASN1, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); + goto err; + } + } + + ASN1_STRING_TABLE *tbl = OPENSSL_malloc(sizeof(ASN1_STRING_TABLE)); + if (tbl == NULL) { + goto err; + } + tbl->nid = nid; + tbl->flags = flags; + tbl->minsize = minsize; + tbl->maxsize = maxsize; + tbl->mask = mask; + ASN1_STRING_TABLE *old_tbl; + if (!lh_ASN1_STRING_TABLE_insert(string_tables, &old_tbl, tbl)) { + OPENSSL_free(tbl); + goto err; + } + assert(old_tbl == NULL); + ret = 1; + +err: + CRYPTO_STATIC_MUTEX_unlock_write(&string_tables_lock); + return ret; } void ASN1_STRING_TABLE_cleanup(void) { - STACK_OF(ASN1_STRING_TABLE) *tmp; - tmp = stable; - if (!tmp) - return; - stable = NULL; - sk_ASN1_STRING_TABLE_pop_free(tmp, st_free); } -static void st_free(ASN1_STRING_TABLE *tbl) -{ - if (tbl->flags & STABLE_FLAGS_MALLOC) - OPENSSL_free(tbl); +void asn1_get_string_table_for_testing(const ASN1_STRING_TABLE **out_ptr, + size_t *out_len) { + *out_ptr = tbl_standard; + *out_len = OPENSSL_ARRAY_SIZE(tbl_standard); } - -#ifdef STRING_TABLE_TEST - -int main(void) -{ - ASN1_STRING_TABLE *tmp; - int i, last_nid = -1; - - for (tmp = tbl_standard, i = 0; - i < sizeof(tbl_standard) / sizeof(ASN1_STRING_TABLE); i++, tmp++) { - if (tmp->nid < last_nid) { - last_nid = 0; - break; - } - last_nid = tmp->nid; - } - - if (last_nid != 0) { - printf("Table order OK\n"); - exit(0); - } - - for (tmp = tbl_standard, i = 0; - i < sizeof(tbl_standard) / sizeof(ASN1_STRING_TABLE); i++, tmp++) - printf("Index %d, NID %d, Name=%s\n", i, tmp->nid, - OBJ_nid2ln(tmp->nid)); - - return 0; -} - -#endif diff --git a/Sources/CCryptoBoringSSL/crypto/asn1/a_time.c b/Sources/CCryptoBoringSSL/crypto/asn1/a_time.c index d6bad643..14b07fca 100644 --- a/Sources/CCryptoBoringSSL/crypto/asn1/a_time.c +++ b/Sources/CCryptoBoringSSL/crypto/asn1/a_time.c @@ -73,7 +73,7 @@ IMPLEMENT_ASN1_MSTRING(ASN1_TIME, B_ASN1_TIME) -IMPLEMENT_ASN1_FUNCTIONS(ASN1_TIME) +IMPLEMENT_ASN1_FUNCTIONS_const(ASN1_TIME) ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t t) { diff --git a/Sources/CCryptoBoringSSL/crypto/asn1/asn1_lib.c b/Sources/CCryptoBoringSSL/crypto/asn1/asn1_lib.c index d79db13d..81964333 100644 --- a/Sources/CCryptoBoringSSL/crypto/asn1/asn1_lib.c +++ b/Sources/CCryptoBoringSSL/crypto/asn1/asn1_lib.c @@ -64,6 +64,7 @@ #include #include "../internal.h" +#include "internal.h" /* Cross-module errors from crypto/x509/i2d_pr.c. */ @@ -103,8 +104,7 @@ OPENSSL_DECLARE_ERROR_REASON(ASN1, UNKNOWN_FORMAT) OPENSSL_DECLARE_ERROR_REASON(ASN1, UNKNOWN_TAG) OPENSSL_DECLARE_ERROR_REASON(ASN1, UNSUPPORTED_TYPE) -static int asn1_get_length(const unsigned char **pp, int *inf, long *rl, - long max); +static int asn1_get_length(const unsigned char **pp, long *rl, long max); static void asn1_put_length(unsigned char **pp, int length); int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag, @@ -113,7 +113,7 @@ int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag, int i, ret; long l; const unsigned char *p = *pp; - int tag, xclass, inf; + int tag, xclass; long max = omax; if (!max) @@ -152,58 +152,43 @@ int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag, *ptag = tag; *pclass = xclass; - if (!asn1_get_length(&p, &inf, plength, max)) + if (!asn1_get_length(&p, plength, max)) goto err; - if (inf && !(ret & V_ASN1_CONSTRUCTED)) - goto err; - -#if 0 - fprintf(stderr, "p=%d + *plength=%ld > omax=%ld + *pp=%d (%d > %d)\n", - (int)p, *plength, omax, (int)*pp, (int)(p + *plength), - (int)(omax + *pp)); - -#endif if (*plength > (omax - (p - *pp))) { OPENSSL_PUT_ERROR(ASN1, ASN1_R_TOO_LONG); - /* - * Set this so that even if things are not long enough the values are - * set correctly - */ - ret |= 0x80; + return 0x80; } *pp = p; - return (ret | inf); + return ret; err: OPENSSL_PUT_ERROR(ASN1, ASN1_R_HEADER_TOO_LONG); - return (0x80); + return 0x80; } -static int asn1_get_length(const unsigned char **pp, int *inf, long *rl, - long max) +static int asn1_get_length(const unsigned char **pp, long *rl, long max) { const unsigned char *p = *pp; unsigned long ret = 0; unsigned long i; - if (max-- < 1) + if (max-- < 1) { return 0; + } if (*p == 0x80) { - *inf = 1; - ret = 0; - p++; + /* We do not support BER indefinite-length encoding. */ + return 0; + } + i = *p & 0x7f; + if (*(p++) & 0x80) { + if (i > sizeof(ret) || max < (long)i) + return 0; + while (i-- > 0) { + ret <<= 8L; + ret |= *(p++); + } } else { - *inf = 0; - i = *p & 0x7f; - if (*(p++) & 0x80) { - if (i > sizeof(ret) || max < (long)i) - return 0; - while (i-- > 0) { - ret <<= 8L; - ret |= *(p++); - } - } else - ret = i; + ret = i; } /* * Bound the length to comfortably fit in an int. Lengths in this module @@ -406,17 +391,44 @@ void ASN1_STRING_free(ASN1_STRING *str) int ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b) { - int i; + /* Capture padding bits and implicit truncation in BIT STRINGs. */ + int a_length = a->length, b_length = b->length; + uint8_t a_padding = 0, b_padding = 0; + if (a->type == V_ASN1_BIT_STRING) { + a_length = asn1_bit_string_length(a, &a_padding); + } + if (b->type == V_ASN1_BIT_STRING) { + b_length = asn1_bit_string_length(b, &b_padding); + } - i = (a->length - b->length); - if (i == 0) { - i = OPENSSL_memcmp(a->data, b->data, a->length); - if (i == 0) - return (a->type - b->type); - else - return (i); - } else - return (i); + if (a_length < b_length) { + return -1; + } + if (a_length > b_length) { + return 1; + } + /* In a BIT STRING, the number of bits is 8 * length - padding. Invert this + * comparison so we compare by lengths. */ + if (a_padding > b_padding) { + return -1; + } + if (a_padding < b_padding) { + return 1; + } + + int ret = OPENSSL_memcmp(a->data, b->data, a_length); + if (ret != 0) { + return ret; + } + + /* Comparing the type first is more natural, but this matches OpenSSL. */ + if (a->type < b->type) { + return -1; + } + if (a->type > b->type) { + return 1; + } + return 0; } int ASN1_STRING_length(const ASN1_STRING *str) diff --git a/Sources/CCryptoBoringSSL/crypto/asn1/asn_pack.c b/Sources/CCryptoBoringSSL/crypto/asn1/asn_pack.c index dd394902..35ca738a 100644 --- a/Sources/CCryptoBoringSSL/crypto/asn1/asn_pack.c +++ b/Sources/CCryptoBoringSSL/crypto/asn1/asn_pack.c @@ -59,47 +59,43 @@ #include #include -/* ASN1_ITEM versions of the above */ -ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct) +ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **out) { - ASN1_STRING *octmp; - - if (!oct || !*oct) { - if (!(octmp = ASN1_STRING_new())) { - OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE); - return NULL; - } - if (oct) - *oct = octmp; - } else - octmp = *oct; - - if (octmp->data) { - OPENSSL_free(octmp->data); - octmp->data = NULL; - } - - if (!(octmp->length = ASN1_item_i2d(obj, &octmp->data, it))) { + uint8_t *new_data = NULL; + int len = ASN1_item_i2d(obj, &new_data, it); + if (len <= 0) { OPENSSL_PUT_ERROR(ASN1, ASN1_R_ENCODE_ERROR); return NULL; } - if (!octmp->data) { - OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE); - return NULL; - } - return octmp; -} -/* Extract an ASN1 object from an ASN1_STRING */ + ASN1_STRING *ret = NULL; + if (out == NULL || *out == NULL) { + ret = ASN1_STRING_new(); + if (ret == NULL) { + OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE); + OPENSSL_free(new_data); + return NULL; + } + } else { + ret = *out; + } + + ASN1_STRING_set0(ret, new_data, len); + if (out != NULL) { + *out = ret; + } + return ret; +} void *ASN1_item_unpack(const ASN1_STRING *oct, const ASN1_ITEM *it) { - const unsigned char *p; - void *ret; - - p = oct->data; - if (!(ret = ASN1_item_d2i(NULL, &p, oct->length, it))) + const unsigned char *p = oct->data; + void *ret = ASN1_item_d2i(NULL, &p, oct->length, it); + if (ret == NULL || p != oct->data + oct->length) { OPENSSL_PUT_ERROR(ASN1, ASN1_R_DECODE_ERROR); + ASN1_item_free(ret, it); + return NULL; + } return ret; } diff --git a/Sources/CCryptoBoringSSL/crypto/asn1/f_enum.c b/Sources/CCryptoBoringSSL/crypto/asn1/f_enum.c deleted file mode 100644 index 6ecfed6a..00000000 --- a/Sources/CCryptoBoringSSL/crypto/asn1/f_enum.c +++ /dev/null @@ -1,93 +0,0 @@ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. - * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. - * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] */ - -#include - -#include - -/* Based on a_int.c: equivalent ENUMERATED functions */ - -int i2a_ASN1_ENUMERATED(BIO *bp, const ASN1_ENUMERATED *a) -{ - int i, n = 0; - static const char *h = "0123456789ABCDEF"; - char buf[2]; - - if (a == NULL) - return (0); - - if (a->length == 0) { - if (BIO_write(bp, "00", 2) != 2) - goto err; - n = 2; - } else { - for (i = 0; i < a->length; i++) { - if ((i != 0) && (i % 35 == 0)) { - if (BIO_write(bp, "\\\n", 2) != 2) - goto err; - n += 2; - } - buf[0] = h[((unsigned char)a->data[i] >> 4) & 0x0f]; - buf[1] = h[((unsigned char)a->data[i]) & 0x0f]; - if (BIO_write(bp, buf, 2) != 2) - goto err; - n += 2; - } - } - return (n); - err: - return (-1); -} diff --git a/Sources/CCryptoBoringSSL/crypto/asn1/f_int.c b/Sources/CCryptoBoringSSL/crypto/asn1/f_int.c index 71ed899d..e6b6b92a 100644 --- a/Sources/CCryptoBoringSSL/crypto/asn1/f_int.c +++ b/Sources/CCryptoBoringSSL/crypto/asn1/f_int.c @@ -95,3 +95,8 @@ int i2a_ASN1_INTEGER(BIO *bp, const ASN1_INTEGER *a) err: return (-1); } + +int i2a_ASN1_ENUMERATED(BIO *bp, const ASN1_ENUMERATED *a) +{ + return i2a_ASN1_INTEGER(bp, a); +} diff --git a/Sources/CCryptoBoringSSL/crypto/asn1/internal.h b/Sources/CCryptoBoringSSL/crypto/asn1/internal.h index f2c1a537..dae0a226 100644 --- a/Sources/CCryptoBoringSSL/crypto/asn1/internal.h +++ b/Sources/CCryptoBoringSSL/crypto/asn1/internal.h @@ -62,6 +62,7 @@ #include #include +#include #if defined(__cplusplus) extern "C" { @@ -106,6 +107,25 @@ struct asn1_object_st { int flags; /* Should we free this one */ }; +ASN1_OBJECT *ASN1_OBJECT_new(void); + +// ASN1_ENCODING structure: this is used to save the received +// encoding of an ASN1 type. This is useful to get round +// problems with invalid encodings which can break signatures. +typedef struct ASN1_ENCODING_st { + unsigned char *enc; // DER encoding + long len; // Length of encoding + int modified; // set to 1 if 'enc' is invalid + // alias_only is zero if |enc| owns the buffer that it points to + // (although |enc| may still be NULL). If one, |enc| points into a + // buffer that is owned elsewhere. + unsigned alias_only : 1; + // alias_only_on_next_parse is one iff the next parsing operation + // should avoid taking a copy of the input and rather set + // |alias_only|. + unsigned alias_only_on_next_parse : 1; +} ASN1_ENCODING; + int asn1_utctime_to_tm(struct tm *tm, const ASN1_UTCTIME *d); int asn1_generalizedtime_to_tm(struct tm *tm, const ASN1_GENERALIZEDTIME *d); @@ -123,15 +143,31 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_ITEM *it, int tag, int aclass, char opt, ASN1_TLC *ctx); +/* ASN1_item_ex_i2d encodes |*pval| as a value of type |it| to |out| under the + * i2d output convention. It returns a non-zero length on success and -1 on + * error. If |tag| is -1. the tag and class come from |it|. Otherwise, the tag + * number is |tag| and the class is |aclass|. This is used for implicit tagging. + * This function treats a missing value as an error, not an optional field. */ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass); + void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it); +/* asn1_get_choice_selector returns the CHOICE selector value for |*pval|, which + * must of type |it|. */ int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it); + int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it); +/* asn1_get_field_ptr returns a pointer to the field in |*pval| corresponding to + * |tt|. */ ASN1_VALUE **asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt); +/* asn1_do_adb returns the |ASN1_TEMPLATE| for the ANY DEFINED BY field |tt|, + * based on the selector INTEGER or OID in |*pval|. If |tt| is not an ADB field, + * it returns |tt|. If the selector does not match any value, it returns NULL. + * If |nullerr| is non-zero, it will additionally push an error to the error + * queue when there is no match. */ const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, int nullerr); @@ -140,8 +176,13 @@ int asn1_refcount_dec_and_test_zero(ASN1_VALUE **pval, const ASN1_ITEM *it); void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it); void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it); + +/* asn1_enc_restore, if |*pval| has a saved encoding, writes it to |out| under + * the i2d output convention, sets |*len| to the length, and returns one. If it + * has no saved encoding, it returns zero. */ int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, const ASN1_ITEM *it); + int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen, const ASN1_ITEM *it); @@ -154,6 +195,27 @@ const void *asn1_type_value_as_pointer(const ASN1_TYPE *a); * ASN.1 PrintableString, and zero otherwise. */ int asn1_is_printable(uint32_t value); +/* asn1_bit_string_length returns the number of bytes in |str| and sets + * |*out_padding_bits| to the number of padding bits. + * + * This function should be used instead of |ASN1_STRING_length| to correctly + * handle the non-|ASN1_STRING_FLAG_BITS_LEFT| case. */ +int asn1_bit_string_length(const ASN1_BIT_STRING *str, + uint8_t *out_padding_bits); + +typedef struct { + int nid; + long minsize; + long maxsize; + unsigned long mask; + unsigned long flags; +} ASN1_STRING_TABLE; + +/* asn1_get_string_table_for_testing sets |*out_ptr| and |*out_len| to the table + * of built-in |ASN1_STRING_TABLE| values. It is exported for testing. */ +OPENSSL_EXPORT void asn1_get_string_table_for_testing( + const ASN1_STRING_TABLE **out_ptr, size_t *out_len); + #if defined(__cplusplus) } /* extern C */ diff --git a/Sources/CCryptoBoringSSL/crypto/asn1/tasn_dec.c b/Sources/CCryptoBoringSSL/crypto/asn1/tasn_dec.c index 89b3fd12..ca6bdc03 100644 --- a/Sources/CCryptoBoringSSL/crypto/asn1/tasn_dec.c +++ b/Sources/CCryptoBoringSSL/crypto/asn1/tasn_dec.c @@ -60,7 +60,6 @@ #include #include -#include #include #include @@ -76,16 +75,9 @@ #define ASN1_MAX_CONSTRUCTED_NEST 30 static int asn1_check_eoc(const unsigned char **in, long len); -static int asn1_find_end(const unsigned char **in, long len, char inf); - -static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len, - char inf, int tag, int aclass, int depth); - -static int collect_data(BUF_MEM *buf, const unsigned char **p, long plen); static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, - char *inf, char *cst, - const unsigned char **in, long len, + char *cst, const unsigned char **in, long len, int exptag, int expclass, char opt, ASN1_TLC *ctx); static int asn1_template_ex_d2i(ASN1_VALUE **pval, @@ -97,7 +89,7 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val, const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx, int depth); static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, - int utype, char *free_cont, const ASN1_ITEM *it); + int utype, const ASN1_ITEM *it); static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_ITEM *it, @@ -170,11 +162,9 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, { const ASN1_TEMPLATE *tt, *errtt = NULL; const ASN1_EXTERN_FUNCS *ef; - const ASN1_AUX *aux = it->funcs; - ASN1_aux_cb *asn1_cb; const unsigned char *p = NULL, *q; unsigned char oclass; - char seq_eoc, seq_nolen, cst, isopt; + char cst, isopt; int i; int otag; int ret = 0; @@ -183,10 +173,6 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, aclass &= ~ASN1_TFLG_COMBINE; if (!pval) return 0; - if (aux && aux->asn1_cb) - asn1_cb = aux->asn1_cb; - else - asn1_cb = 0; /* * Bound |len| to comfortably fit in an int. Lengths in this module often @@ -234,7 +220,7 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, p = *in; /* Just read in tag and class */ - ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, NULL, + ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, &p, len, -1, 0, 1, ctx); if (!ret) { OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR); @@ -264,7 +250,7 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, ef = it->funcs; return ef->asn1_ex_d2i(pval, in, len, it, tag, aclass, opt, ctx); - case ASN1_ITYPE_CHOICE: + case ASN1_ITYPE_CHOICE: { /* * It never makes sense for CHOICE types to have implicit tagging, so if * tag != -1, then this looks like an error in the template. @@ -274,6 +260,8 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, goto err; } + const ASN1_AUX *aux = it->funcs; + ASN1_aux_cb *asn1_cb = aux != NULL ? aux->asn1_cb : NULL; if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL)) goto auxerr; @@ -327,8 +315,9 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, goto auxerr; *in = p; return 1; + } - case ASN1_ITYPE_SEQUENCE: + case ASN1_ITYPE_SEQUENCE: { p = *in; /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */ @@ -337,15 +326,13 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, aclass = V_ASN1_UNIVERSAL; } /* Get SEQUENCE length and update len, p */ - ret = asn1_check_tlen(&len, NULL, NULL, &seq_eoc, &cst, + ret = asn1_check_tlen(&len, NULL, NULL, &cst, &p, len, tag, aclass, opt, ctx); if (!ret) { OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR); goto err; } else if (ret == -1) return -1; - /* If indefinite we don't do a length check */ - seq_nolen = seq_eoc; if (!cst) { OPENSSL_PUT_ERROR(ASN1, ASN1_R_SEQUENCE_NOT_CONSTRUCTED); goto err; @@ -356,6 +343,8 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, goto err; } + const ASN1_AUX *aux = it->funcs; + ASN1_aux_cb *asn1_cb = aux != NULL ? aux->asn1_cb : NULL; if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL)) goto auxerr; @@ -384,15 +373,12 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, if (!len) break; q = p; + /* TODO(https://crbug.com/boringssl/455): Although we've removed + * indefinite-length support, this check is not quite a no-op. + * Reject [UNIVERSAL 0] in the tag parsers themselves. */ if (asn1_check_eoc(&p, len)) { - if (!seq_eoc) { - OPENSSL_PUT_ERROR(ASN1, ASN1_R_UNEXPECTED_EOC); - goto err; - } - len -= p - q; - seq_eoc = 0; - q = p; - break; + OPENSSL_PUT_ERROR(ASN1, ASN1_R_UNEXPECTED_EOC); + goto err; } /* * This determines the OPTIONAL flag value. The field cannot be @@ -424,13 +410,8 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, len -= p - q; } - /* Check for EOC if expecting one */ - if (seq_eoc && !asn1_check_eoc(&p, len)) { - OPENSSL_PUT_ERROR(ASN1, ASN1_R_MISSING_EOC); - goto err; - } /* Check all data read */ - if (!seq_nolen && len) { + if (len) { OPENSSL_PUT_ERROR(ASN1, ASN1_R_SEQUENCE_LENGTH_MISMATCH); goto err; } @@ -462,6 +443,7 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, goto auxerr; *in = p; return 1; + } default: return 0; @@ -500,7 +482,6 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val, int ret; long len; const unsigned char *p, *q; - char exp_eoc; if (!val) return 0; flags = tt->flags; @@ -515,7 +496,7 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val, * Need to work out amount of data available to the inner content and * where it starts: so read in EXPLICIT header to get the info. */ - ret = asn1_check_tlen(&len, NULL, NULL, &exp_eoc, &cst, + ret = asn1_check_tlen(&len, NULL, NULL, &cst, &p, inlen, tt->tag, aclass, opt, ctx); q = p; if (!ret) { @@ -535,20 +516,10 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val, } /* We read the field in OK so update length */ len -= p - q; - if (exp_eoc) { - /* If NDEF we must have an EOC here */ - if (!asn1_check_eoc(&p, len)) { - OPENSSL_PUT_ERROR(ASN1, ASN1_R_MISSING_EOC); - goto err; - } - } else { - /* - * Otherwise we must hit the EXPLICIT tag end or its an error - */ - if (len) { - OPENSSL_PUT_ERROR(ASN1, ASN1_R_EXPLICIT_LENGTH_MISMATCH); - goto err; - } + /* Check for trailing data. */ + if (len) { + OPENSSL_PUT_ERROR(ASN1, ASN1_R_EXPLICIT_LENGTH_MISMATCH); + goto err; } } else return asn1_template_noexp_d2i(val, in, inlen, tt, opt, ctx, depth); @@ -579,7 +550,6 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val, if (flags & ASN1_TFLG_SK_MASK) { /* SET OF, SEQUENCE OF */ int sktag, skaclass; - char sk_eoc; /* First work out expected inner tag value */ if (flags & ASN1_TFLG_IMPTAG) { sktag = tt->tag; @@ -592,7 +562,7 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val, sktag = V_ASN1_SEQUENCE; } /* Get the tag */ - ret = asn1_check_tlen(&len, NULL, NULL, &sk_eoc, NULL, + ret = asn1_check_tlen(&len, NULL, NULL, NULL, &p, len, sktag, skaclass, opt, ctx); if (!ret) { OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR); @@ -622,15 +592,12 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val, while (len > 0) { ASN1_VALUE *skfield; const unsigned char *q = p; - /* See if EOC found */ + /* TODO(https://crbug.com/boringssl/455): Although we've removed + * indefinite-length support, this check is not quite a no-op. + * Reject [UNIVERSAL 0] in the tag parsers themselves. */ if (asn1_check_eoc(&p, len)) { - if (!sk_eoc) { - OPENSSL_PUT_ERROR(ASN1, ASN1_R_UNEXPECTED_EOC); - goto err; - } - len -= p - q; - sk_eoc = 0; - break; + OPENSSL_PUT_ERROR(ASN1, ASN1_R_UNEXPECTED_EOC); + goto err; } skfield = NULL; if (!asn1_item_ex_d2i(&skfield, &p, len, ASN1_ITEM_ptr(tt->item), @@ -645,10 +612,6 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val, goto err; } } - if (sk_eoc) { - OPENSSL_PUT_ERROR(ASN1, ASN1_R_MISSING_EOC); - goto err; - } } else if (flags & ASN1_TFLG_IMPTAG) { /* IMPLICIT tagging */ ret = asn1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), tt->tag, @@ -685,9 +648,8 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, { int ret = 0, utype; long plen; - char cst, inf, free_cont = 0; + char cst; const unsigned char *p; - BUF_MEM buf = {0, NULL, 0 }; const unsigned char *cont = NULL; long len; if (!pval) { @@ -713,7 +675,7 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, return 0; } p = *in; - ret = asn1_check_tlen(NULL, &utype, &oclass, NULL, NULL, + ret = asn1_check_tlen(NULL, &utype, &oclass, NULL, &p, inlen, -1, 0, 0, ctx); if (!ret) { OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR); @@ -728,7 +690,7 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, } p = *in; /* Check header */ - ret = asn1_check_tlen(&plen, NULL, NULL, &inf, &cst, + ret = asn1_check_tlen(&plen, NULL, NULL, &cst, &p, inlen, tag, aclass, opt, ctx); if (!ret) { OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR); @@ -753,43 +715,14 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, } cont = *in; - /* If indefinite length constructed find the real end */ - if (inf) { - if (!asn1_find_end(&p, plen, inf)) - goto err; - len = p - cont; - } else { - len = p - cont + plen; - p += plen; - } + len = p - cont + plen; + p += plen; } else if (cst) { - if (utype == V_ASN1_NULL || utype == V_ASN1_BOOLEAN - || utype == V_ASN1_OBJECT || utype == V_ASN1_INTEGER - || utype == V_ASN1_ENUMERATED) { - /* These types only have primitive encodings. */ - OPENSSL_PUT_ERROR(ASN1, ASN1_R_TYPE_NOT_PRIMITIVE); - return 0; - } - - /* Free any returned 'buf' content */ - free_cont = 1; - /* - * Should really check the internal tags are correct but some things - * may get this wrong. The relevant specs say that constructed string - * types should be OCTET STRINGs internally irrespective of the type. - * So instead just check for UNIVERSAL class and ignore the tag. - */ - if (!asn1_collect(&buf, &p, plen, inf, -1, V_ASN1_UNIVERSAL, 0)) { - goto err; - } - len = buf.length; - /* Append a final null to string */ - if (!BUF_MEM_grow_clean(&buf, len + 1)) { - OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE); - goto err; - } - buf.data[len] = 0; - cont = (const unsigned char *)buf.data; + /* This parser historically supported BER constructed strings. We no + * longer do and will gradually tighten this parser into a DER + * parser. BER types should use |CBS_asn1_ber_to_der|. */ + OPENSSL_PUT_ERROR(ASN1, ASN1_R_TYPE_NOT_PRIMITIVE); + return 0; } else { cont = p; len = plen; @@ -797,22 +730,19 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, } /* We now have content length and type: translate into a structure */ - /* asn1_ex_c2i may reuse allocated buffer, and so sets free_cont to 0 */ - if (!asn1_ex_c2i(pval, cont, len, utype, &free_cont, it)) + if (!asn1_ex_c2i(pval, cont, len, utype, it)) goto err; *in = p; ret = 1; err: - if (free_cont && buf.data) - OPENSSL_free(buf.data); return ret; } /* Translate ASN1 content octets into a structure */ static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, - int utype, char *free_cont, const ASN1_ITEM *it) + int utype, const ASN1_ITEM *it) { ASN1_VALUE **opval = NULL; ASN1_STRING *stmp; @@ -916,20 +846,11 @@ static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, stmp = (ASN1_STRING *)*pval; stmp->type = utype; } - /* If we've already allocated a buffer use it */ - if (*free_cont) { - if (stmp->data) - OPENSSL_free(stmp->data); - stmp->data = (unsigned char *)cont; /* UGLY CAST! RL */ - stmp->length = len; - *free_cont = 0; - } else { - if (!ASN1_STRING_set(stmp, cont, len)) { - OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE); - ASN1_STRING_free(stmp); - *pval = NULL; - goto err; - } + if (!ASN1_STRING_set(stmp, cont, len)) { + OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE); + ASN1_STRING_free(stmp); + *pval = NULL; + goto err; } break; } @@ -947,145 +868,6 @@ static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, return ret; } -/* - * This function finds the end of an ASN1 structure when passed its maximum - * length, whether it is indefinite length and a pointer to the content. This - * is more efficient than calling asn1_collect because it does not recurse on - * each indefinite length header. - */ - -static int asn1_find_end(const unsigned char **in, long len, char inf) -{ - int expected_eoc; - long plen; - const unsigned char *p = *in, *q; - /* If not indefinite length constructed just add length */ - if (inf == 0) { - *in += len; - return 1; - } - expected_eoc = 1; - /* - * Indefinite length constructed form. Find the end when enough EOCs are - * found. If more indefinite length constructed headers are encountered - * increment the expected eoc count otherwise just skip to the end of the - * data. - */ - while (len > 0) { - if (asn1_check_eoc(&p, len)) { - expected_eoc--; - if (expected_eoc == 0) - break; - len -= 2; - continue; - } - q = p; - /* Just read in a header: only care about the length */ - if (!asn1_check_tlen(&plen, NULL, NULL, &inf, NULL, &p, len, - -1, 0, 0, NULL)) { - OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR); - return 0; - } - if (inf) - expected_eoc++; - else - p += plen; - len -= p - q; - } - if (expected_eoc) { - OPENSSL_PUT_ERROR(ASN1, ASN1_R_MISSING_EOC); - return 0; - } - *in = p; - return 1; -} - -/* - * This function collects the asn1 data from a constructred string type into - * a buffer. The values of 'in' and 'len' should refer to the contents of the - * constructed type and 'inf' should be set if it is indefinite length. - */ - -/* - * This determines how many levels of recursion are permitted in ASN1 string - * types. If it is not limited stack overflows can occur. If set to zero no - * recursion is allowed at all. Although zero should be adequate examples - * exist that require a value of 1. So 5 should be more than enough. - */ -#define ASN1_MAX_STRING_NEST 5 - -static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len, - char inf, int tag, int aclass, int depth) -{ - const unsigned char *p, *q; - long plen; - char cst, ininf; - p = *in; - inf &= 1; - /* - * If no buffer and not indefinite length constructed just pass over the - * encoded data - */ - if (!buf && !inf) { - *in += len; - return 1; - } - while (len > 0) { - q = p; - /* Check for EOC */ - if (asn1_check_eoc(&p, len)) { - /* - * EOC is illegal outside indefinite length constructed form - */ - if (!inf) { - OPENSSL_PUT_ERROR(ASN1, ASN1_R_UNEXPECTED_EOC); - return 0; - } - inf = 0; - break; - } - - if (!asn1_check_tlen(&plen, NULL, NULL, &ininf, &cst, &p, - len, tag, aclass, 0, NULL)) { - OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR); - return 0; - } - - /* If indefinite length constructed update max length */ - if (cst) { - if (depth >= ASN1_MAX_STRING_NEST) { - OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_STRING); - return 0; - } - if (!asn1_collect(buf, &p, plen, ininf, tag, aclass, depth + 1)) - return 0; - } else if (plen && !collect_data(buf, &p, plen)) - return 0; - len -= p - q; - } - if (inf) { - OPENSSL_PUT_ERROR(ASN1, ASN1_R_MISSING_EOC); - return 0; - } - *in = p; - return 1; -} - -static int collect_data(BUF_MEM *buf, const unsigned char **p, long plen) -{ - int len; - if (buf) { - len = buf->length; - if (!BUF_MEM_grow_clean(buf, len + plen)) { - OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE); - return 0; - } - OPENSSL_memcpy(buf->data + len, *p, plen); - } - *p += plen; - return 1; -} - /* Check for ASN1 EOC and swallow it if found */ static int asn1_check_eoc(const unsigned char **in, long len) @@ -1102,15 +884,12 @@ static int asn1_check_eoc(const unsigned char **in, long len) } /* - * Check an ASN1 tag and length: a bit like ASN1_get_object but it sets the - * length for indefinite length constructed form, we don't know the exact - * length but we can set an upper bound to the amount of data available minus - * the header length just read. + * Check an ASN1 tag and length: a bit like ASN1_get_object but it handles + * the ASN1_TLC cache and checks the expected tag. */ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, - char *inf, char *cst, - const unsigned char **in, long len, + char *cst, const unsigned char **in, long len, int exptag, int expclass, char opt, ASN1_TLC *ctx) { int i; @@ -1136,10 +915,13 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, ctx->hdrlen = p - q; ctx->valid = 1; /* - * If definite length, and no error, length + header can't exceed - * total amount of data available. + * If no error, length + header can't exceed total amount of data + * available. + * + * TODO(davidben): Is this check necessary? |ASN1_get_object| + * should already guarantee this. */ - if (!(i & 0x81) && ((plen + ctx->hdrlen) > len)) { + if (!(i & 0x80) && ((plen + ctx->hdrlen) > len)) { OPENSSL_PUT_ERROR(ASN1, ASN1_R_TOO_LONG); asn1_tlc_clear(ctx); return 0; @@ -1170,12 +952,6 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, asn1_tlc_clear(ctx); } - if (i & 1) - plen = len - (p - q); - - if (inf) - *inf = i & 1; - if (cst) *cst = i & V_ASN1_CONSTRUCTED; diff --git a/Sources/CCryptoBoringSSL/crypto/asn1/tasn_enc.c b/Sources/CCryptoBoringSSL/crypto/asn1/tasn_enc.c index 1fad8641..7de9b119 100644 --- a/Sources/CCryptoBoringSSL/crypto/asn1/tasn_enc.c +++ b/Sources/CCryptoBoringSSL/crypto/asn1/tasn_enc.c @@ -56,6 +56,7 @@ #include +#include #include #include @@ -66,53 +67,47 @@ #include "internal.h" +static int asn1_item_ex_i2d_opt(ASN1_VALUE **pval, unsigned char **out, + const ASN1_ITEM *it, int tag, int aclass, + int optional); static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, - const ASN1_ITEM *it, int tag, int aclass); -static int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, - const ASN1_ITEM *it); + const ASN1_ITEM *it, int tag, int aclass, + int optional); +static int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cont, int *out_omit, + int *putype, const ASN1_ITEM *it); static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, - int skcontlen, const ASN1_ITEM *item, - int do_sort, int iclass); + int skcontlen, const ASN1_ITEM *item, int do_sort); static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_TEMPLATE *tt, int tag, int aclass); -static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out, - const ASN1_ITEM *it, int flags); /* * Top level i2d equivalents */ int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it) -{ - return asn1_item_flags_i2d(val, out, it, 0); -} - -/* - * Encode an ASN1 item, this is use by the standard 'i2d' function. 'out' - * points to a buffer to output the data to. The new i2d has one additional - * feature. If the output buffer is NULL (i.e. *out == NULL) then a buffer is - * allocated and populated with the encoding. - */ - -static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out, - const ASN1_ITEM *it, int flags) { if (out && !*out) { unsigned char *p, *buf; - int len; - len = ASN1_item_ex_i2d(&val, NULL, it, -1, flags); - if (len <= 0) + int len = ASN1_item_ex_i2d(&val, NULL, it, /*tag=*/-1, /*aclass=*/0); + if (len <= 0) { return len; + } buf = OPENSSL_malloc(len); - if (!buf) + if (!buf) { + OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE); return -1; + } p = buf; - ASN1_item_ex_i2d(&val, &p, it, -1, flags); + int len2 = ASN1_item_ex_i2d(&val, &p, it, /*tag=*/-1, /*aclass=*/0); + if (len2 <= 0) { + return len2; + } + assert(len == len2); *out = buf; return len; } - return ASN1_item_ex_i2d(&val, out, it, -1, flags); + return ASN1_item_ex_i2d(&val, out, it, /*tag=*/-1, /*aclass=*/0); } /* @@ -122,27 +117,48 @@ static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out, int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass) +{ + int ret = asn1_item_ex_i2d_opt(pval, out, it, tag, aclass, /*optional=*/0); + assert(ret != 0); + return ret; +} + +/* asn1_item_ex_i2d_opt behaves like |ASN1_item_ex_i2d| but, if |optional| is + * non-zero and |*pval| is omitted, it returns zero and writes no bytes. */ +int asn1_item_ex_i2d_opt(ASN1_VALUE **pval, unsigned char **out, + const ASN1_ITEM *it, int tag, int aclass, + int optional) { const ASN1_TEMPLATE *tt = NULL; int i, seqcontlen, seqlen; - const ASN1_EXTERN_FUNCS *ef; - const ASN1_AUX *aux = it->funcs; - ASN1_aux_cb *asn1_cb = 0; - if ((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval) - return 0; + /* Historically, |aclass| was repurposed to pass additional flags into the + * encoding process. */ + assert((aclass & ASN1_TFLG_TAG_CLASS) == aclass); + /* If not overridding the tag, |aclass| is ignored and should be zero. */ + assert(tag != -1 || aclass == 0); - if (aux && aux->asn1_cb) - asn1_cb = aux->asn1_cb; + /* All fields are pointers, except for boolean |ASN1_ITYPE_PRIMITIVE|s. + * Optional primitives are handled later. */ + if ((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval) { + if (optional) { + return 0; + } + OPENSSL_PUT_ERROR(ASN1, ASN1_R_MISSING_VALUE); + return -1; + } switch (it->itype) { case ASN1_ITYPE_PRIMITIVE: - if (it->templates) - return asn1_template_ex_i2d(pval, out, it->templates, - tag, aclass); - return asn1_i2d_ex_primitive(pval, out, it, tag, aclass); - break; + if (it->templates) { + if (it->templates->flags & ASN1_TFLG_OPTIONAL) { + OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE); + return -1; + } + return asn1_template_ex_i2d(pval, out, it->templates, tag, aclass); + } + return asn1_i2d_ex_primitive(pval, out, it, tag, aclass, optional); case ASN1_ITYPE_MSTRING: /* @@ -153,9 +169,9 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE); return -1; } - return asn1_i2d_ex_primitive(pval, out, it, -1, aclass); + return asn1_i2d_ex_primitive(pval, out, it, -1, 0, optional); - case ASN1_ITYPE_CHOICE: + case ASN1_ITYPE_CHOICE: { /* * It never makes sense for CHOICE types to have implicit tagging, so if * tag != -1, then this looks like an error in the template. @@ -164,31 +180,39 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE); return -1; } - if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL)) - return 0; i = asn1_get_choice_selector(pval, it); - if ((i >= 0) && (i < it->tcount)) { - ASN1_VALUE **pchval; - const ASN1_TEMPLATE *chtt; - chtt = it->templates + i; - pchval = asn1_get_field_ptr(pval, chtt); - return asn1_template_ex_i2d(pchval, out, chtt, -1, aclass); + if (i < 0 || i >= it->tcount) { + OPENSSL_PUT_ERROR(ASN1, ASN1_R_NO_MATCHING_CHOICE_TYPE); + return -1; } - /* Fixme: error condition if selector out of range */ - if (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it, NULL)) - return 0; - break; + const ASN1_TEMPLATE *chtt = it->templates + i; + if (chtt->flags & ASN1_TFLG_OPTIONAL) { + OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE); + return -1; + } + ASN1_VALUE **pchval = asn1_get_field_ptr(pval, chtt); + return asn1_template_ex_i2d(pchval, out, chtt, -1, 0); + } - case ASN1_ITYPE_EXTERN: + case ASN1_ITYPE_EXTERN: { /* If new style i2d it does all the work */ - ef = it->funcs; - return ef->asn1_ex_i2d(pval, out, it, tag, aclass); + const ASN1_EXTERN_FUNCS *ef = it->funcs; + int ret = ef->asn1_ex_i2d(pval, out, it, tag, aclass); + if (ret == 0) { + /* |asn1_ex_i2d| should never return zero. We have already checked + * for optional values generically, and |ASN1_ITYPE_EXTERN| fields + * must be pointers. */ + OPENSSL_PUT_ERROR(ASN1, ERR_R_INTERNAL_ERROR); + return -1; + } + return ret; + } - case ASN1_ITYPE_SEQUENCE: + case ASN1_ITYPE_SEQUENCE: { i = asn1_enc_restore(&seqcontlen, out, pval, it); /* An error occurred */ if (i < 0) - return 0; + return -1; /* We have a valid cached encoding... */ if (i > 0) return seqcontlen; @@ -197,12 +221,8 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */ if (tag == -1) { tag = V_ASN1_SEQUENCE; - /* Retain any other flags in aclass */ - aclass = (aclass & ~ASN1_TFLG_TAG_CLASS) - | V_ASN1_UNIVERSAL; + aclass = V_ASN1_UNIVERSAL; } - if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL)) - return 0; /* First work out sequence content length */ for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) { const ASN1_TEMPLATE *seqtt; @@ -210,9 +230,9 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, int tmplen; seqtt = asn1_do_adb(pval, tt, 1); if (!seqtt) - return 0; + return -1; pseqval = asn1_get_field_ptr(pval, seqtt); - tmplen = asn1_template_ex_i2d(pseqval, NULL, seqtt, -1, aclass); + tmplen = asn1_template_ex_i2d(pseqval, NULL, seqtt, -1, 0); if (tmplen == -1 || (tmplen > INT_MAX - seqcontlen)) return -1; seqcontlen += tmplen; @@ -228,40 +248,49 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, ASN1_VALUE **pseqval; seqtt = asn1_do_adb(pval, tt, 1); if (!seqtt) - return 0; + return -1; pseqval = asn1_get_field_ptr(pval, seqtt); - /* FIXME: check for errors in enhanced version */ - asn1_template_ex_i2d(pseqval, out, seqtt, -1, aclass); + if (asn1_template_ex_i2d(pseqval, out, seqtt, -1, 0) < 0) { + return -1; + } } - if (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it, NULL)) - return 0; return seqlen; + } default: - return 0; - + OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE); + return -1; } - return 0; } +/* asn1_template_ex_i2d behaves like |asn1_item_ex_i2d_opt| but uses an + * |ASN1_TEMPLATE| instead of an |ASN1_ITEM|. An |ASN1_TEMPLATE| wraps an + * |ASN1_ITEM| with modifiers such as tagging, SEQUENCE or SET, etc. Instead of + * taking an |optional| parameter, it uses the |ASN1_TFLG_OPTIONAL| flag. */ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_TEMPLATE *tt, int tag, int iclass) { int i, ret, flags, ttag, tclass; size_t j; flags = tt->flags; + + /* Historically, |iclass| was repurposed to pass additional flags into the + * encoding process. */ + assert((iclass & ASN1_TFLG_TAG_CLASS) == iclass); + /* If not overridding the tag, |iclass| is ignored and should be zero. */ + assert(tag != -1 || iclass == 0); + /* * Work out tag and class to use: tagging may come either from the * template or the arguments, not both because this would create - * ambiguity. Additionally the iclass argument may contain some - * additional flags which should be noted and passed down to other - * levels. + * ambiguity. */ if (flags & ASN1_TFLG_TAG_MASK) { /* Error if argument and template tagging */ - if (tag != -1) - /* FIXME: error code here */ + if (tag != -1) { + OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE); return -1; + } /* Get tagging from template */ ttag = tt->tag; tclass = flags & ASN1_TFLG_TAG_CLASS; @@ -273,14 +302,12 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, ttag = -1; tclass = 0; } - /* - * Remove any class mask from iflag. - */ - iclass &= ~ASN1_TFLG_TAG_CLASS; + + const int optional = (flags & ASN1_TFLG_OPTIONAL) != 0; /* - * At this point 'ttag' contains the outer tag to use, 'tclass' is the - * class and iclass is any flags passed to this function. + * At this point 'ttag' contains the outer tag to use, and 'tclass' is the + * class. */ if (flags & ASN1_TFLG_SK_MASK) { @@ -290,8 +317,13 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, int skcontlen, sklen; ASN1_VALUE *skitem; - if (!*pval) - return 0; + if (!*pval) { + if (optional) { + return 0; + } + OPENSSL_PUT_ERROR(ASN1, ASN1_R_MISSING_VALUE); + return -1; + } if (flags & ASN1_TFLG_SET_OF) { isset = 1; @@ -323,7 +355,7 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, int tmplen; skitem = sk_ASN1_VALUE_value(sk, j); tmplen = ASN1_item_ex_i2d(&skitem, NULL, ASN1_ITEM_ptr(tt->item), - -1, iclass); + -1, 0); if (tmplen == -1 || (skcontlen > INT_MAX - tmplen)) return -1; skcontlen += tmplen; @@ -347,30 +379,36 @@ static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, /* SET or SEQUENCE and IMPLICIT tag */ ASN1_put_object(out, /*constructed=*/1, skcontlen, sktag, skaclass); /* And the stuff itself */ - asn1_set_seq_out(sk, out, skcontlen, ASN1_ITEM_ptr(tt->item), - isset, iclass); + if (!asn1_set_seq_out(sk, out, skcontlen, ASN1_ITEM_ptr(tt->item), + isset)) { + return -1; + } return ret; } if (flags & ASN1_TFLG_EXPTAG) { /* EXPLICIT tagging */ /* Find length of tagged item */ - i = ASN1_item_ex_i2d(pval, NULL, ASN1_ITEM_ptr(tt->item), -1, iclass); - if (!i) - return 0; + i = asn1_item_ex_i2d_opt(pval, NULL, ASN1_ITEM_ptr(tt->item), -1, 0, + optional); + if (i <= 0) + return i; /* Find length of EXPLICIT tag */ ret = ASN1_object_size(/*constructed=*/1, i, ttag); if (out && ret != -1) { /* Output tag and item */ ASN1_put_object(out, /*constructed=*/1, i, ttag, tclass); - ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), -1, iclass); + if (ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), -1, + 0) < 0) { + return -1; + } } return ret; } - /* Either normal or IMPLICIT tagging: combine class and flags */ - return ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), - ttag, tclass | iclass); + /* Either normal or IMPLICIT tagging */ + return asn1_item_ex_i2d_opt(pval, out, ASN1_ITEM_ptr(tt->item), + ttag, tclass, optional); } @@ -392,93 +430,96 @@ static int der_cmp(const void *a, const void *b) return d1->length - d2->length; } -/* Output the content octets of SET OF or SEQUENCE OF */ - +/* asn1_set_seq_out writes |sk| to |out| under the i2d output convention, + * excluding the tag and length. It returns one on success and zero on error. + * |skcontlen| must be the total encoded size. If |do_sort| is non-zero, the + * elements are sorted for a SET OF type. Each element of |sk| has type + * |item|. */ static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, - int skcontlen, const ASN1_ITEM *item, - int do_sort, int iclass) + int skcontlen, const ASN1_ITEM *item, int do_sort) { - size_t i; - ASN1_VALUE *skitem; - unsigned char *tmpdat = NULL, *p = NULL; - DER_ENC *derlst = NULL, *tder; - if (do_sort) { - /* Don't need to sort less than 2 items */ - if (sk_ASN1_VALUE_num(sk) < 2) - do_sort = 0; - else { - derlst = OPENSSL_malloc(sk_ASN1_VALUE_num(sk) - * sizeof(*derlst)); - if (!derlst) - return 0; - tmpdat = OPENSSL_malloc(skcontlen); - if (!tmpdat) { - OPENSSL_free(derlst); + /* No need to sort if there are fewer than two items. */ + if (!do_sort || sk_ASN1_VALUE_num(sk) < 2) { + for (size_t i = 0; i < sk_ASN1_VALUE_num(sk); i++) { + ASN1_VALUE *skitem = sk_ASN1_VALUE_value(sk, i); + if (ASN1_item_ex_i2d(&skitem, out, item, -1, 0) < 0) { return 0; } } - } - /* If not sorting just output each item */ - if (!do_sort) { - for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) { - skitem = sk_ASN1_VALUE_value(sk, i); - ASN1_item_ex_i2d(&skitem, out, item, -1, iclass); - } return 1; } - p = tmpdat; - /* Doing sort: build up a list of each member's DER encoding */ - for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) { - skitem = sk_ASN1_VALUE_value(sk, i); - tder->data = p; - tder->length = ASN1_item_ex_i2d(&skitem, &p, item, -1, iclass); + if (sk_ASN1_VALUE_num(sk) > ((size_t)-1) / sizeof(DER_ENC)) { + OPENSSL_PUT_ERROR(ASN1, ERR_R_OVERFLOW); + return 0; } - /* Now sort them */ - qsort(derlst, sk_ASN1_VALUE_num(sk), sizeof(*derlst), der_cmp); - /* Output sorted DER encoding */ + int ret = 0; + unsigned char *const buf = OPENSSL_malloc(skcontlen); + DER_ENC *encoded = OPENSSL_malloc(sk_ASN1_VALUE_num(sk) * sizeof(*encoded)); + if (encoded == NULL || buf == NULL) { + OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE); + goto err; + } + + /* Encode all the elements into |buf| and populate |encoded|. */ + unsigned char *p = buf; + for (size_t i = 0; i < sk_ASN1_VALUE_num(sk); i++) { + ASN1_VALUE *skitem = sk_ASN1_VALUE_value(sk, i); + encoded[i].data = p; + encoded[i].length = ASN1_item_ex_i2d(&skitem, &p, item, -1, 0); + if (encoded[i].length < 0) { + goto err; + } + assert(p - buf <= skcontlen); + } + + qsort(encoded, sk_ASN1_VALUE_num(sk), sizeof(*encoded), der_cmp); + + /* Output the elements in sorted order. */ p = *out; - for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) { - OPENSSL_memcpy(p, tder->data, tder->length); - p += tder->length; + for (size_t i = 0; i < sk_ASN1_VALUE_num(sk); i++) { + OPENSSL_memcpy(p, encoded[i].data, encoded[i].length); + p += encoded[i].length; } *out = p; - OPENSSL_free(derlst); - OPENSSL_free(tmpdat); - return 1; + + ret = 1; + +err: + OPENSSL_free(encoded); + OPENSSL_free(buf); + return ret; } +/* asn1_i2d_ex_primitive behaves like |ASN1_item_ex_i2d| but |item| must be a + * a PRIMITIVE or MSTRING type that is not an |ASN1_ITEM_TEMPLATE|. */ static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, - const ASN1_ITEM *it, int tag, int aclass) + const ASN1_ITEM *it, int tag, int aclass, + int optional) { - int len; - int utype; - int usetag; - - utype = it->utype; - - /* - * Get length of content octets and maybe find out the underlying type. - */ - - len = asn1_ex_i2c(pval, NULL, &utype, it); + /* Get length of content octets and maybe find out the underlying type. */ + int omit; + int utype = it->utype; + int len = asn1_ex_i2c(pval, NULL, &omit, &utype, it); + if (len < 0) { + return -1; + } + if (omit) { + if (optional) { + return 0; + } + OPENSSL_PUT_ERROR(ASN1, ASN1_R_MISSING_VALUE); + return -1; + } /* * If SEQUENCE, SET or OTHER then header is included in pseudo content * octets so don't include tag+length. We need to check here because the * call to asn1_ex_i2c() could change utype. */ - if ((utype == V_ASN1_SEQUENCE) || (utype == V_ASN1_SET) || - (utype == V_ASN1_OTHER)) - usetag = 0; - else - usetag = 1; - - /* -1 means omit type */ - - if (len == -1) - return 0; + int usetag = utype != V_ASN1_SEQUENCE && utype != V_ASN1_SET && + utype != V_ASN1_OTHER; /* If not implicitly tagged get tag from underlying type */ if (tag == -1) @@ -486,21 +527,42 @@ static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, /* Output tag+length followed by content octets */ if (out) { - if (usetag) + if (usetag) { ASN1_put_object(out, /*constructed=*/0, len, tag, aclass); - asn1_ex_i2c(pval, *out, &utype, it); + } + int len2 = asn1_ex_i2c(pval, *out, &omit, &utype, it); + if (len2 < 0) { + return -1; + } + assert(len == len2); + assert(!omit); *out += len; } - if (usetag) + if (usetag) { return ASN1_object_size(/*constructed=*/0, len, tag); + } return len; } -/* Produce content octets from a structure */ - -static int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, - const ASN1_ITEM *it) +/* asn1_ex_i2c writes the |*pval| to |cout| under the i2d output convention, + * excluding the tag and length. It returns the number of bytes written, + * possibly zero, on success or -1 on error. If |*pval| should be omitted, it + * returns zero and sets |*out_omit| to true. + * + * If |it| is an MSTRING or ANY type, it gets the underlying type from |*pval|, + * which must be an |ASN1_STRING| or |ASN1_TYPE|, respectively. It then updates + * |*putype| with the tag number of type used, or |V_ASN1_OTHER| if it was not a + * universal type. If |*putype| is set to |V_ASN1_SEQUENCE|, |V_ASN1_SET|, or + * |V_ASN1_OTHER|, it additionally outputs the tag and length, so the caller + * must not do so. + * + * Otherwise, |*putype| must contain |it->utype|. + * + * WARNING: Unlike most functions in this file, |asn1_ex_i2c| can return zero + * without omitting the element. ASN.1 values may have empty contents. */ +static int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *out_omit, + int *putype, const ASN1_ITEM *it) { ASN1_BOOLEAN *tbool = NULL; ASN1_STRING *strtmp; @@ -514,17 +576,26 @@ static int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, * |ASN1_PRIMITIVE_FUNCS| table of callbacks. */ assert(it->funcs == NULL); + *out_omit = 0; + /* Should type be omitted? */ if ((it->itype != ASN1_ITYPE_PRIMITIVE) || (it->utype != V_ASN1_BOOLEAN)) { - if (!*pval) - return -1; + if (!*pval) { + *out_omit = 1; + return 0; + } } if (it->itype == ASN1_ITYPE_MSTRING) { /* If MSTRING type set the underlying type */ strtmp = (ASN1_STRING *)*pval; utype = strtmp->type; + if (utype < 0 && utype != V_ASN1_OTHER) { + /* MSTRINGs can have type -1 when default-constructed. */ + OPENSSL_PUT_ERROR(ASN1, ASN1_R_WRONG_TYPE); + return -1; + } /* Negative INTEGER and ENUMERATED values use |ASN1_STRING| type values * that do not match their corresponding utype values. INTEGERs cannot * participate in MSTRING types, but ENUMERATEDs can. @@ -545,6 +616,11 @@ static int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, ASN1_TYPE *typ; typ = (ASN1_TYPE *)*pval; utype = typ->type; + if (utype < 0 && utype != V_ASN1_OTHER) { + /* |ASN1_TYPE|s can have type -1 when default-constructed. */ + OPENSSL_PUT_ERROR(ASN1, ASN1_R_WRONG_TYPE); + return -1; + } *putype = utype; pval = &typ->value.asn1_value; } else @@ -555,8 +631,11 @@ static int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, otmp = (ASN1_OBJECT *)*pval; cont = otmp->data; len = otmp->length; - if (cont == NULL || len == 0) + if (len == 0) { + /* Some |ASN1_OBJECT|s do not have OIDs and cannot be serialized. */ + OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_OBJECT); return -1; + } break; case V_ASN1_NULL: @@ -566,34 +645,39 @@ static int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, case V_ASN1_BOOLEAN: tbool = (ASN1_BOOLEAN *)pval; - if (*tbool == -1) - return -1; + if (*tbool == -1) { + *out_omit = 1; + return 0; + } if (it->utype != V_ASN1_ANY) { /* * Default handling if value == size field then omit */ - if (*tbool && (it->size > 0)) - return -1; - if (!*tbool && !it->size) - return -1; + if ((*tbool && (it->size > 0)) || + (!*tbool && !it->size)) { + *out_omit = 1; + return 0; + } } c = *tbool ? 0xff : 0x00; cont = &c; len = 1; break; - case V_ASN1_BIT_STRING: - return i2c_ASN1_BIT_STRING((ASN1_BIT_STRING *)*pval, - cout ? &cout : NULL); - break; + case V_ASN1_BIT_STRING: { + int ret = i2c_ASN1_BIT_STRING((ASN1_BIT_STRING *)*pval, + cout ? &cout : NULL); + /* |i2c_ASN1_BIT_STRING| returns zero on error instead of -1. */ + return ret <= 0 ? -1 : ret; + } case V_ASN1_INTEGER: - case V_ASN1_ENUMERATED: - /* - * These are all have the same content format as ASN1_INTEGER - */ - return i2c_ASN1_INTEGER((ASN1_INTEGER *)*pval, cout ? &cout : NULL); - break; + case V_ASN1_ENUMERATED: { + /* |i2c_ASN1_INTEGER| also handles ENUMERATED. */ + int ret = i2c_ASN1_INTEGER((ASN1_INTEGER *)*pval, cout ? &cout : NULL); + /* |i2c_ASN1_INTEGER| returns zero on error instead of -1. */ + return ret <= 0 ? -1 : ret; + } case V_ASN1_OCTET_STRING: case V_ASN1_NUMERICSTRING: diff --git a/Sources/CCryptoBoringSSL/crypto/asn1/tasn_fre.c b/Sources/CCryptoBoringSSL/crypto/asn1/tasn_fre.c index 26e36d77..26d88f8d 100644 --- a/Sources/CCryptoBoringSSL/crypto/asn1/tasn_fre.c +++ b/Sources/CCryptoBoringSSL/crypto/asn1/tasn_fre.c @@ -79,17 +79,11 @@ void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine) { const ASN1_TEMPLATE *tt = NULL, *seqtt; const ASN1_EXTERN_FUNCS *ef; - const ASN1_AUX *aux = it->funcs; - ASN1_aux_cb *asn1_cb; int i; if (!pval) return; if ((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval) return; - if (aux && aux->asn1_cb) - asn1_cb = aux->asn1_cb; - else - asn1_cb = 0; switch (it->itype) { @@ -104,7 +98,9 @@ void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine) ASN1_primitive_free(pval, it); break; - case ASN1_ITYPE_CHOICE: + case ASN1_ITYPE_CHOICE: { + const ASN1_AUX *aux = it->funcs; + ASN1_aux_cb *asn1_cb = aux != NULL ? aux->asn1_cb : NULL; if (asn1_cb) { i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL); if (i == 2) @@ -124,6 +120,7 @@ void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine) *pval = NULL; } break; + } case ASN1_ITYPE_EXTERN: ef = it->funcs; @@ -131,9 +128,11 @@ void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine) ef->asn1_ex_free(pval, it); break; - case ASN1_ITYPE_SEQUENCE: + case ASN1_ITYPE_SEQUENCE: { if (!asn1_refcount_dec_and_test_zero(pval, it)) return; + const ASN1_AUX *aux = it->funcs; + ASN1_aux_cb *asn1_cb = aux != NULL ? aux->asn1_cb : NULL; if (asn1_cb) { i = asn1_cb(ASN1_OP_FREE_PRE, pval, it, NULL); if (i == 2) @@ -162,6 +161,7 @@ void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine) } break; } + } } void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) diff --git a/Sources/CCryptoBoringSSL/crypto/asn1/tasn_new.c b/Sources/CCryptoBoringSSL/crypto/asn1/tasn_new.c index 534a9bc0..2e4d1ef8 100644 --- a/Sources/CCryptoBoringSSL/crypto/asn1/tasn_new.c +++ b/Sources/CCryptoBoringSSL/crypto/asn1/tasn_new.c @@ -95,14 +95,8 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, { const ASN1_TEMPLATE *tt = NULL; const ASN1_EXTERN_FUNCS *ef; - const ASN1_AUX *aux = it->funcs; - ASN1_aux_cb *asn1_cb; ASN1_VALUE **pseqval; int i; - if (aux && aux->asn1_cb) - asn1_cb = aux->asn1_cb; - else - asn1_cb = 0; switch (it->itype) { @@ -127,7 +121,9 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, goto memerr; break; - case ASN1_ITYPE_CHOICE: + case ASN1_ITYPE_CHOICE: { + const ASN1_AUX *aux = it->funcs; + ASN1_aux_cb *asn1_cb = aux != NULL ? aux->asn1_cb : NULL; if (asn1_cb) { i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL); if (!i) @@ -146,8 +142,11 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL)) goto auxerr2; break; + } - case ASN1_ITYPE_SEQUENCE: + case ASN1_ITYPE_SEQUENCE: { + const ASN1_AUX *aux = it->funcs; + ASN1_aux_cb *asn1_cb = aux != NULL ? aux->asn1_cb : NULL; if (asn1_cb) { i = asn1_cb(ASN1_OP_NEW_PRE, pval, it, NULL); if (!i) @@ -173,6 +172,7 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, goto auxerr2; break; } + } return 1; memerr2: diff --git a/Sources/CCryptoBoringSSL/crypto/asn1/tasn_typ.c b/Sources/CCryptoBoringSSL/crypto/asn1/tasn_typ.c index 357d721e..e547452a 100644 --- a/Sources/CCryptoBoringSSL/crypto/asn1/tasn_typ.c +++ b/Sources/CCryptoBoringSSL/crypto/asn1/tasn_typ.c @@ -62,7 +62,7 @@ #define IMPLEMENT_ASN1_STRING_FUNCTIONS(sname) \ IMPLEMENT_ASN1_TYPE(sname) \ - IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(sname, sname, sname) \ + IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(sname, sname, sname) \ sname *sname##_new(void) \ { \ return ASN1_STRING_type_new(V_##sname); \ @@ -88,7 +88,7 @@ IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_UNIVERSALSTRING) IMPLEMENT_ASN1_STRING_FUNCTIONS(ASN1_BMPSTRING) IMPLEMENT_ASN1_TYPE(ASN1_NULL) -IMPLEMENT_ASN1_FUNCTIONS(ASN1_NULL) +IMPLEMENT_ASN1_FUNCTIONS_const(ASN1_NULL) IMPLEMENT_ASN1_TYPE(ASN1_OBJECT) @@ -97,18 +97,20 @@ IMPLEMENT_ASN1_TYPE(ASN1_ANY) /* Just swallow an ASN1_SEQUENCE in an ASN1_STRING */ IMPLEMENT_ASN1_TYPE(ASN1_SEQUENCE) -IMPLEMENT_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE) +IMPLEMENT_ASN1_FUNCTIONS_const_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE) /* Multistring types */ IMPLEMENT_ASN1_MSTRING(ASN1_PRINTABLE, B_ASN1_PRINTABLE) -IMPLEMENT_ASN1_FUNCTIONS_name(ASN1_STRING, ASN1_PRINTABLE) +IMPLEMENT_ASN1_FUNCTIONS_const_fname(ASN1_STRING, ASN1_PRINTABLE, + ASN1_PRINTABLE) IMPLEMENT_ASN1_MSTRING(DISPLAYTEXT, B_ASN1_DISPLAYTEXT) -IMPLEMENT_ASN1_FUNCTIONS_name(ASN1_STRING, DISPLAYTEXT) +IMPLEMENT_ASN1_FUNCTIONS_const_fname(ASN1_STRING, DISPLAYTEXT, DISPLAYTEXT) IMPLEMENT_ASN1_MSTRING(DIRECTORYSTRING, B_ASN1_DIRECTORYSTRING) -IMPLEMENT_ASN1_FUNCTIONS_name(ASN1_STRING, DIRECTORYSTRING) +IMPLEMENT_ASN1_FUNCTIONS_const_fname(ASN1_STRING, DIRECTORYSTRING, + DIRECTORYSTRING) /* Three separate BOOLEAN type: normal, DEFAULT TRUE and DEFAULT FALSE */ IMPLEMENT_ASN1_TYPE_ex(ASN1_BOOLEAN, ASN1_BOOLEAN, -1) diff --git a/Sources/CCryptoBoringSSL/crypto/asn1/tasn_utl.c b/Sources/CCryptoBoringSSL/crypto/asn1/tasn_utl.c index 470cfb98..cbe6df65 100644 --- a/Sources/CCryptoBoringSSL/crypto/asn1/tasn_utl.c +++ b/Sources/CCryptoBoringSSL/crypto/asn1/tasn_utl.c @@ -118,6 +118,7 @@ int asn1_refcount_dec_and_test_zero(ASN1_VALUE **pval, const ASN1_ITEM *it) { } static ASN1_ENCODING *asn1_get_enc_ptr(ASN1_VALUE **pval, const ASN1_ITEM *it) { + assert(it->itype == ASN1_ITYPE_SEQUENCE); const ASN1_AUX *aux; if (!pval || !*pval) { return NULL; diff --git a/Sources/CCryptoBoringSSL/crypto/base64/base64.c b/Sources/CCryptoBoringSSL/crypto/base64/base64.c index 679f1065..bf44ad74 100644 --- a/Sources/CCryptoBoringSSL/crypto/base64/base64.c +++ b/Sources/CCryptoBoringSSL/crypto/base64/base64.c @@ -265,14 +265,17 @@ static uint8_t base64_ascii_to_bin(uint8_t a) { const uint8_t is_slash = constant_time_eq_8(a, '/'); const uint8_t is_equals = constant_time_eq_8(a, '='); - uint8_t ret = 0xff; // 0xff signals invalid. - ret = constant_time_select_8(is_upper, a - 'A', ret); // [0,26) - ret = constant_time_select_8(is_lower, a - 'a' + 26, ret); // [26,52) - ret = constant_time_select_8(is_digit, a - '0' + 52, ret); // [52,62) - ret = constant_time_select_8(is_plus, 62, ret); - ret = constant_time_select_8(is_slash, 63, ret); - // Padding maps to zero, to be further handled by the caller. - ret = constant_time_select_8(is_equals, 0, ret); + uint8_t ret = 0; + ret |= is_upper & (a - 'A'); // [0,26) + ret |= is_lower & (a - 'a' + 26); // [26,52) + ret |= is_digit & (a - '0' + 52); // [52,62) + ret |= is_plus & 62; + ret |= is_slash & 63; + // Invalid inputs, 'A', and '=' have all been mapped to zero. Map invalid + // inputs to 0xff. Note '=' is padding and handled separately by the caller. + const uint8_t is_valid = + is_upper | is_lower | is_digit | is_plus | is_slash | is_equals; + ret |= ~is_valid; return ret; } diff --git a/Sources/CCryptoBoringSSL/crypto/blake2/blake2.c b/Sources/CCryptoBoringSSL/crypto/blake2/blake2.c index 09463849..05a21517 100644 --- a/Sources/CCryptoBoringSSL/crypto/blake2/blake2.c +++ b/Sources/CCryptoBoringSSL/crypto/blake2/blake2.c @@ -42,19 +42,17 @@ static const uint8_t kSigma[10 * 16] = { // clang-format on }; -#define RIGHT_ROTATE(v, n) (((v) >> (n)) | ((v) << (64 - (n)))) - // https://tools.ietf.org/html/rfc7693#section-3.1 static void blake2b_mix(uint64_t v[16], int a, int b, int c, int d, uint64_t x, uint64_t y) { v[a] = v[a] + v[b] + x; - v[d] = RIGHT_ROTATE(v[d] ^ v[a], 32); + v[d] = CRYPTO_rotr_u64(v[d] ^ v[a], 32); v[c] = v[c] + v[d]; - v[b] = RIGHT_ROTATE(v[b] ^ v[c], 24); + v[b] = CRYPTO_rotr_u64(v[b] ^ v[c], 24); v[a] = v[a] + v[b] + y; - v[d] = RIGHT_ROTATE(v[d] ^ v[a], 16); + v[d] = CRYPTO_rotr_u64(v[d] ^ v[a], 16); v[c] = v[c] + v[d]; - v[b] = RIGHT_ROTATE(v[b] ^ v[c], 63); + v[b] = CRYPTO_rotr_u64(v[b] ^ v[c], 63); } static void blake2b_transform( diff --git a/Sources/CCryptoBoringSSL/crypto/bytestring/ber.c b/Sources/CCryptoBoringSSL/crypto/bytestring/ber.c index 08c34755..57aa5777 100644 --- a/Sources/CCryptoBoringSSL/crypto/bytestring/ber.c +++ b/Sources/CCryptoBoringSSL/crypto/bytestring/ber.c @@ -29,8 +29,10 @@ static const unsigned kMaxDepth = 2048; // is_string_type returns one if |tag| is a string type and zero otherwise. It // ignores the constructed bit. static int is_string_type(unsigned tag) { + // While BER supports constructed BIT STRINGS, OpenSSL misparses them. To + // avoid acting on an ambiguous input, we do not support constructed BIT + // STRINGS. See https://github.com/openssl/openssl/issues/12810. switch (tag & ~CBS_ASN1_CONSTRUCTED) { - case CBS_ASN1_BITSTRING: case CBS_ASN1_OCTETSTRING: case CBS_ASN1_UTF8STRING: case CBS_ASN1_NUMERICSTRING: diff --git a/Sources/CCryptoBoringSSL/crypto/chacha/chacha-x86.linux.x86.S b/Sources/CCryptoBoringSSL/crypto/chacha/chacha-x86.linux.x86.S index 406f941c..f0feaf16 100644 --- a/Sources/CCryptoBoringSSL/crypto/chacha/chacha-x86.linux.x86.S +++ b/Sources/CCryptoBoringSSL/crypto/chacha/chacha-x86.linux.x86.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__i386__) && defined(__linux__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__i386__) #if defined(BORINGSSL_PREFIX) diff --git a/Sources/CCryptoBoringSSL/crypto/chacha/chacha-x86.windows.x86.S b/Sources/CCryptoBoringSSL/crypto/chacha/chacha-x86.windows.x86.S index 1ef41a95..cf3da966 100644 --- a/Sources/CCryptoBoringSSL/crypto/chacha/chacha-x86.windows.x86.S +++ b/Sources/CCryptoBoringSSL/crypto/chacha/chacha-x86.windows.x86.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__i386__) && defined(_WIN32) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__i386__) #if defined(BORINGSSL_PREFIX) diff --git a/Sources/CCryptoBoringSSL/crypto/chacha/chacha-x86_64.linux.x86_64.S b/Sources/CCryptoBoringSSL/crypto/chacha/chacha-x86_64.linux.x86_64.S index a9aa8052..202a4876 100644 --- a/Sources/CCryptoBoringSSL/crypto/chacha/chacha-x86_64.linux.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/chacha/chacha-x86_64.linux.x86_64.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__x86_64__) && defined(__linux__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__has_feature) #if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) diff --git a/Sources/CCryptoBoringSSL/crypto/chacha/chacha-x86_64.mac.x86_64.S b/Sources/CCryptoBoringSSL/crypto/chacha/chacha-x86_64.mac.x86_64.S index 84e3c7ce..652690f6 100644 --- a/Sources/CCryptoBoringSSL/crypto/chacha/chacha-x86_64.mac.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/chacha/chacha-x86_64.mac.x86_64.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__x86_64__) && defined(__APPLE__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__has_feature) #if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) diff --git a/Sources/CCryptoBoringSSL/crypto/chacha/chacha.c b/Sources/CCryptoBoringSSL/crypto/chacha/chacha.c index a232372b..26da9090 100644 --- a/Sources/CCryptoBoringSSL/crypto/chacha/chacha.c +++ b/Sources/CCryptoBoringSSL/crypto/chacha/chacha.c @@ -25,22 +25,20 @@ #include "internal.h" -#define U8TO32_LITTLE(p) \ - (((uint32_t)((p)[0])) | ((uint32_t)((p)[1]) << 8) | \ - ((uint32_t)((p)[2]) << 16) | ((uint32_t)((p)[3]) << 24)) - // sigma contains the ChaCha constants, which happen to be an ASCII string. static const uint8_t sigma[16] = { 'e', 'x', 'p', 'a', 'n', 'd', ' ', '3', '2', '-', 'b', 'y', 't', 'e', ' ', 'k' }; -#define ROTATE(v, n) (((v) << (n)) | ((v) >> (32 - (n)))) - // QUARTERROUND updates a, b, c, d with a ChaCha "quarter" round. -#define QUARTERROUND(a, b, c, d) \ - x[a] += x[b]; x[d] = ROTATE(x[d] ^ x[a], 16); \ - x[c] += x[d]; x[b] = ROTATE(x[b] ^ x[c], 12); \ - x[a] += x[b]; x[d] = ROTATE(x[d] ^ x[a], 8); \ - x[c] += x[d]; x[b] = ROTATE(x[b] ^ x[c], 7); +#define QUARTERROUND(a, b, c, d) \ + x[a] += x[b]; \ + x[d] = CRYPTO_rotl_u32(x[d] ^ x[a], 16); \ + x[c] += x[d]; \ + x[b] = CRYPTO_rotl_u32(x[b] ^ x[c], 12); \ + x[a] += x[b]; \ + x[d] = CRYPTO_rotl_u32(x[d] ^ x[a], 8); \ + x[c] += x[d]; \ + x[b] = CRYPTO_rotl_u32(x[b] ^ x[c], 7); void CRYPTO_hchacha20(uint8_t out[32], const uint8_t key[32], const uint8_t nonce[16]) { @@ -71,24 +69,25 @@ void CRYPTO_chacha_20(uint8_t *out, const uint8_t *in, size_t in_len, uint32_t counter) { assert(!buffers_alias(out, in_len, in, in_len) || in == out); - uint32_t counter_nonce[4]; counter_nonce[0] = counter; - counter_nonce[1] = U8TO32_LITTLE(nonce + 0); - counter_nonce[2] = U8TO32_LITTLE(nonce + 4); - counter_nonce[3] = U8TO32_LITTLE(nonce + 8); + uint32_t counter_nonce[4]; + counter_nonce[0] = counter; + counter_nonce[1] = CRYPTO_load_u32_le(nonce + 0); + counter_nonce[2] = CRYPTO_load_u32_le(nonce + 4); + counter_nonce[3] = CRYPTO_load_u32_le(nonce + 8); const uint32_t *key_ptr = (const uint32_t *)key; #if !defined(OPENSSL_X86) && !defined(OPENSSL_X86_64) // The assembly expects the key to be four-byte aligned. uint32_t key_u32[8]; if ((((uintptr_t)key) & 3) != 0) { - key_u32[0] = U8TO32_LITTLE(key + 0); - key_u32[1] = U8TO32_LITTLE(key + 4); - key_u32[2] = U8TO32_LITTLE(key + 8); - key_u32[3] = U8TO32_LITTLE(key + 12); - key_u32[4] = U8TO32_LITTLE(key + 16); - key_u32[5] = U8TO32_LITTLE(key + 20); - key_u32[6] = U8TO32_LITTLE(key + 24); - key_u32[7] = U8TO32_LITTLE(key + 28); + key_u32[0] = CRYPTO_load_u32_le(key + 0); + key_u32[1] = CRYPTO_load_u32_le(key + 4); + key_u32[2] = CRYPTO_load_u32_le(key + 8); + key_u32[3] = CRYPTO_load_u32_le(key + 12); + key_u32[4] = CRYPTO_load_u32_le(key + 16); + key_u32[5] = CRYPTO_load_u32_le(key + 20); + key_u32[6] = CRYPTO_load_u32_le(key + 24); + key_u32[7] = CRYPTO_load_u32_le(key + 28); key_ptr = key_u32; } @@ -99,14 +98,6 @@ void CRYPTO_chacha_20(uint8_t *out, const uint8_t *in, size_t in_len, #else -#define U32TO8_LITTLE(p, v) \ - { \ - (p)[0] = (v >> 0) & 0xff; \ - (p)[1] = (v >> 8) & 0xff; \ - (p)[2] = (v >> 16) & 0xff; \ - (p)[3] = (v >> 24) & 0xff; \ - } - // chacha_core performs 20 rounds of ChaCha on the input words in // |input| and writes the 64 output bytes to |output|. static void chacha_core(uint8_t output[64], const uint32_t input[16]) { @@ -129,7 +120,7 @@ static void chacha_core(uint8_t output[64], const uint32_t input[16]) { x[i] += input[i]; } for (i = 0; i < 16; ++i) { - U32TO8_LITTLE(output + 4 * i, x[i]); + CRYPTO_store_u32_le(output + 4 * i, x[i]); } } @@ -142,25 +133,25 @@ void CRYPTO_chacha_20(uint8_t *out, const uint8_t *in, size_t in_len, uint8_t buf[64]; size_t todo, i; - input[0] = U8TO32_LITTLE(sigma + 0); - input[1] = U8TO32_LITTLE(sigma + 4); - input[2] = U8TO32_LITTLE(sigma + 8); - input[3] = U8TO32_LITTLE(sigma + 12); + input[0] = CRYPTO_load_u32_le(sigma + 0); + input[1] = CRYPTO_load_u32_le(sigma + 4); + input[2] = CRYPTO_load_u32_le(sigma + 8); + input[3] = CRYPTO_load_u32_le(sigma + 12); - input[4] = U8TO32_LITTLE(key + 0); - input[5] = U8TO32_LITTLE(key + 4); - input[6] = U8TO32_LITTLE(key + 8); - input[7] = U8TO32_LITTLE(key + 12); + input[4] = CRYPTO_load_u32_le(key + 0); + input[5] = CRYPTO_load_u32_le(key + 4); + input[6] = CRYPTO_load_u32_le(key + 8); + input[7] = CRYPTO_load_u32_le(key + 12); - input[8] = U8TO32_LITTLE(key + 16); - input[9] = U8TO32_LITTLE(key + 20); - input[10] = U8TO32_LITTLE(key + 24); - input[11] = U8TO32_LITTLE(key + 28); + input[8] = CRYPTO_load_u32_le(key + 16); + input[9] = CRYPTO_load_u32_le(key + 20); + input[10] = CRYPTO_load_u32_le(key + 24); + input[11] = CRYPTO_load_u32_le(key + 28); input[12] = counter; - input[13] = U8TO32_LITTLE(nonce + 0); - input[14] = U8TO32_LITTLE(nonce + 4); - input[15] = U8TO32_LITTLE(nonce + 8); + input[13] = CRYPTO_load_u32_le(nonce + 0); + input[14] = CRYPTO_load_u32_le(nonce + 4); + input[15] = CRYPTO_load_u32_le(nonce + 8); while (in_len > 0) { todo = sizeof(buf); diff --git a/Sources/CCryptoBoringSSL/crypto/cipher_extra/aes128gcmsiv-x86_64.linux.x86_64.S b/Sources/CCryptoBoringSSL/crypto/cipher_extra/aes128gcmsiv-x86_64.linux.x86_64.S index 50484ec7..0b242a58 100644 --- a/Sources/CCryptoBoringSSL/crypto/cipher_extra/aes128gcmsiv-x86_64.linux.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/cipher_extra/aes128gcmsiv-x86_64.linux.x86_64.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__x86_64__) && defined(__linux__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__has_feature) #if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) diff --git a/Sources/CCryptoBoringSSL/crypto/cipher_extra/aes128gcmsiv-x86_64.mac.x86_64.S b/Sources/CCryptoBoringSSL/crypto/cipher_extra/aes128gcmsiv-x86_64.mac.x86_64.S index 90c0c95b..76d3d64a 100644 --- a/Sources/CCryptoBoringSSL/crypto/cipher_extra/aes128gcmsiv-x86_64.mac.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/cipher_extra/aes128gcmsiv-x86_64.mac.x86_64.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__x86_64__) && defined(__APPLE__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__has_feature) #if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) diff --git a/Sources/CCryptoBoringSSL/crypto/cipher_extra/chacha20_poly1305_x86_64.linux.x86_64.S b/Sources/CCryptoBoringSSL/crypto/cipher_extra/chacha20_poly1305_x86_64.linux.x86_64.S index d8f63042..46af8568 100644 --- a/Sources/CCryptoBoringSSL/crypto/cipher_extra/chacha20_poly1305_x86_64.linux.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/cipher_extra/chacha20_poly1305_x86_64.linux.x86_64.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__x86_64__) && defined(__linux__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__has_feature) #if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) diff --git a/Sources/CCryptoBoringSSL/crypto/cipher_extra/chacha20_poly1305_x86_64.mac.x86_64.S b/Sources/CCryptoBoringSSL/crypto/cipher_extra/chacha20_poly1305_x86_64.mac.x86_64.S index fd01d78c..a0e57647 100644 --- a/Sources/CCryptoBoringSSL/crypto/cipher_extra/chacha20_poly1305_x86_64.mac.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/cipher_extra/chacha20_poly1305_x86_64.mac.x86_64.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__x86_64__) && defined(__APPLE__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__has_feature) #if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) diff --git a/Sources/CCryptoBoringSSL/crypto/cipher_extra/cipher_extra.c b/Sources/CCryptoBoringSSL/crypto/cipher_extra/cipher_extra.c index 3ca6868f..086d5ce3 100644 --- a/Sources/CCryptoBoringSSL/crypto/cipher_extra/cipher_extra.c +++ b/Sources/CCryptoBoringSSL/crypto/cipher_extra/cipher_extra.c @@ -67,25 +67,42 @@ #include "../internal.h" +static const struct { + int nid; + const char *name; + const EVP_CIPHER *(*func)(void); +} kCiphers[] = { + {NID_aes_128_cbc, "aes-128-cbc", EVP_aes_128_cbc}, + {NID_aes_128_ctr, "aes-128-ctr", EVP_aes_128_ctr}, + {NID_aes_128_ecb, "aes-128-ecb", EVP_aes_128_ecb}, + {NID_aes_128_gcm, "aes-128-gcm", EVP_aes_128_gcm}, + {NID_aes_128_ofb128, "aes-128-ofb", EVP_aes_128_ofb}, + {NID_aes_192_cbc, "aes-192-cbc", EVP_aes_192_cbc}, + {NID_aes_192_ctr, "aes-192-ctr", EVP_aes_192_ctr}, + {NID_aes_192_ecb, "aes-192-ecb", EVP_aes_192_ecb}, + {NID_aes_192_gcm, "aes-192-gcm", EVP_aes_192_gcm}, + {NID_aes_192_ofb128, "aes-192-ofb", EVP_aes_192_ofb}, + {NID_aes_256_cbc, "aes-256-cbc", EVP_aes_256_cbc}, + {NID_aes_256_ctr, "aes-256-ctr", EVP_aes_256_ctr}, + {NID_aes_256_ecb, "aes-256-ecb", EVP_aes_256_ecb}, + {NID_aes_256_gcm, "aes-256-gcm", EVP_aes_256_gcm}, + {NID_aes_256_ofb128, "aes-256-ofb", EVP_aes_256_ofb}, + {NID_des_cbc, "des-cbc", EVP_des_cbc}, + {NID_des_ecb, "des-ecb", EVP_des_ecb}, + {NID_des_ede_cbc, "des-ede-cbc", EVP_des_ede_cbc}, + {NID_des_ede_ecb, "des-ede", EVP_des_ede}, + {NID_des_ede3_cbc, "des-ede3-cbc", EVP_des_ede3_cbc}, + {NID_rc2_cbc, "rc2-cbc", EVP_rc2_cbc}, + {NID_rc4, "rc4", EVP_rc4}, +}; + const EVP_CIPHER *EVP_get_cipherbynid(int nid) { - switch (nid) { - case NID_rc2_cbc: - return EVP_rc2_cbc(); - case NID_rc2_40_cbc: - return EVP_rc2_40_cbc(); - case NID_des_ede3_cbc: - return EVP_des_ede3_cbc(); - case NID_des_ede_cbc: - return EVP_des_cbc(); - case NID_aes_128_cbc: - return EVP_aes_128_cbc(); - case NID_aes_192_cbc: - return EVP_aes_192_cbc(); - case NID_aes_256_cbc: - return EVP_aes_256_cbc(); - default: - return NULL; + for (size_t i = 0; i < OPENSSL_ARRAY_SIZE(kCiphers); i++) { + if (kCiphers[i].nid == nid) { + return kCiphers[i].func(); + } } + return NULL; } const EVP_CIPHER *EVP_get_cipherbyname(const char *name) { @@ -93,54 +110,17 @@ const EVP_CIPHER *EVP_get_cipherbyname(const char *name) { return NULL; } - if (OPENSSL_strcasecmp(name, "rc4") == 0) { - return EVP_rc4(); - } else if (OPENSSL_strcasecmp(name, "des-cbc") == 0) { - return EVP_des_cbc(); - } else if (OPENSSL_strcasecmp(name, "des-ede3-cbc") == 0 || - // This is not a name used by OpenSSL, but tcpdump registers it - // with |EVP_add_cipher_alias|. Our |EVP_add_cipher_alias| is a - // no-op, so we support the name here. - OPENSSL_strcasecmp(name, "3des") == 0) { - return EVP_des_ede3_cbc(); - } else if (OPENSSL_strcasecmp(name, "aes-128-cbc") == 0) { - return EVP_aes_128_cbc(); - } else if (OPENSSL_strcasecmp(name, "aes-192-cbc") == 0) { - return EVP_aes_192_cbc(); - } else if (OPENSSL_strcasecmp(name, "aes-256-cbc") == 0) { - return EVP_aes_256_cbc(); - } else if (OPENSSL_strcasecmp(name, "aes-128-ctr") == 0) { - return EVP_aes_128_ctr(); - } else if (OPENSSL_strcasecmp(name, "aes-192-ctr") == 0) { - return EVP_aes_192_ctr(); - } else if (OPENSSL_strcasecmp(name, "aes-256-ctr") == 0) { - return EVP_aes_256_ctr(); - } else if (OPENSSL_strcasecmp(name, "aes-128-ecb") == 0) { - return EVP_aes_128_ecb(); - } else if (OPENSSL_strcasecmp(name, "aes-192-ecb") == 0) { - return EVP_aes_192_ecb(); - } else if (OPENSSL_strcasecmp(name, "aes-256-ecb") == 0) { - return EVP_aes_256_ecb(); - } else if (OPENSSL_strcasecmp(name, "aes-128-gcm") == 0) { - return EVP_aes_128_gcm(); - } else if (OPENSSL_strcasecmp(name, "aes-192-gcm") == 0) { - return EVP_aes_192_gcm(); - } else if (OPENSSL_strcasecmp(name, "aes-256-gcm") == 0) { - return EVP_aes_256_gcm(); - } else if (OPENSSL_strcasecmp(name, "aes-128-ofb") == 0) { - return EVP_aes_128_ofb(); - } else if (OPENSSL_strcasecmp(name, "aes-192-ofb") == 0) { - return EVP_aes_192_ofb(); - } else if (OPENSSL_strcasecmp(name, "aes-256-ofb") == 0) { - return EVP_aes_256_ofb(); - } else if (OPENSSL_strcasecmp(name, "des-ecb") == 0) { - return EVP_des_ecb(); - } else if (OPENSSL_strcasecmp(name, "des-ede") == 0) { - return EVP_des_ede(); - } else if (OPENSSL_strcasecmp(name, "des-ede-cbc") == 0) { - return EVP_des_ede_cbc(); - } else if (OPENSSL_strcasecmp(name, "rc2-cbc") == 0) { - return EVP_rc2_cbc(); + // This is not a name used by OpenSSL, but tcpdump registers it with + // |EVP_add_cipher_alias|. Our |EVP_add_cipher_alias| is a no-op, so we + // support the name here. + if (OPENSSL_strcasecmp(name, "3des") == 0) { + name = "des-ede3-cbc"; + } + + for (size_t i = 0; i < OPENSSL_ARRAY_SIZE(kCiphers); i++) { + if (OPENSSL_strcasecmp(kCiphers[i].name, name) == 0) { + return kCiphers[i].func(); + } } return NULL; diff --git a/Sources/CCryptoBoringSSL/crypto/err/err_data.c b/Sources/CCryptoBoringSSL/crypto/err/err_data.c index 63611c96..4e4c483c 100644 --- a/Sources/CCryptoBoringSSL/crypto/err/err_data.c +++ b/Sources/CCryptoBoringSSL/crypto/err/err_data.c @@ -55,185 +55,185 @@ OPENSSL_STATIC_ASSERT(ERR_LIB_USER == 33, "library value changed"); OPENSSL_STATIC_ASSERT(ERR_NUM_LIBS == 34, "number of libraries changed"); const uint32_t kOpenSSLReasonValues[] = { - 0xc320847, - 0xc328861, - 0xc330870, - 0xc338880, - 0xc34088f, - 0xc3488a8, - 0xc3508b4, - 0xc3588d1, - 0xc3608f1, - 0xc3688ff, - 0xc37090f, - 0xc37891c, - 0xc38092c, - 0xc388937, - 0xc39094d, - 0xc39895c, - 0xc3a0970, - 0xc3a8854, + 0xc320862, + 0xc32887c, + 0xc33088b, + 0xc33889b, + 0xc3408aa, + 0xc3488c3, + 0xc3508cf, + 0xc3588ec, + 0xc36090c, + 0xc36891a, + 0xc37092a, + 0xc378937, + 0xc380947, + 0xc388952, + 0xc390968, + 0xc398977, + 0xc3a098b, + 0xc3a886f, 0xc3b00f7, - 0xc3b88e3, - 0x10320854, - 0x103295ca, - 0x103315d6, - 0x103395ef, - 0x10341602, - 0x10348f34, - 0x10350c6d, - 0x10359615, - 0x1036163f, - 0x10369652, - 0x10371671, - 0x1037968a, - 0x1038169f, - 0x103896bd, - 0x103916cc, - 0x103996e8, - 0x103a1703, - 0x103a9712, - 0x103b172e, - 0x103b9749, - 0x103c176f, + 0xc3b88fe, + 0x1032086f, + 0x103295e5, + 0x103315f1, + 0x1033960a, + 0x1034161d, + 0x10348f4f, + 0x10350c88, + 0x10359630, + 0x1036165a, + 0x1036966d, + 0x1037168c, + 0x103796a5, + 0x103816ba, + 0x103896d8, + 0x103916e7, + 0x10399703, + 0x103a171e, + 0x103a972d, + 0x103b1749, + 0x103b9764, + 0x103c178a, 0x103c80f7, - 0x103d1780, - 0x103d9794, - 0x103e17b3, - 0x103e97c2, - 0x103f17d9, - 0x103f97ec, - 0x10400c31, - 0x104097ff, - 0x1041181d, - 0x10419830, - 0x1042184a, - 0x1042985a, - 0x1043186e, - 0x10439884, - 0x1044189c, - 0x104498b1, - 0x104518c5, - 0x104598d7, - 0x1046060a, - 0x1046895c, - 0x104718ec, - 0x10479903, - 0x10481918, - 0x10489926, - 0x10490e80, - 0x10499760, - 0x104a162a, - 0x14320c14, - 0x14328c22, - 0x14330c31, - 0x14338c43, + 0x103d179b, + 0x103d97af, + 0x103e17ce, + 0x103e97dd, + 0x103f17f4, + 0x103f9807, + 0x10400c4c, + 0x1040981a, + 0x10411838, + 0x1041984b, + 0x10421865, + 0x10429875, + 0x10431889, + 0x1043989f, + 0x104418b7, + 0x104498cc, + 0x104518e0, + 0x104598f2, + 0x10460625, + 0x10468977, + 0x10471907, + 0x1047991e, + 0x10481933, + 0x10489941, + 0x10490e9b, + 0x1049977b, + 0x104a1645, + 0x14320c2f, + 0x14328c3d, + 0x14330c4c, + 0x14338c5e, 0x143400b9, 0x143480f7, 0x18320090, - 0x18328f8a, + 0x18328fa5, 0x183300b9, - 0x18338fa0, - 0x18340fb4, + 0x18338fbb, + 0x18340fcf, 0x183480f7, - 0x18350fd3, - 0x18358feb, - 0x18361000, - 0x18369014, - 0x1837104c, - 0x18379062, - 0x18381076, - 0x18389086, - 0x18390a82, - 0x18399096, - 0x183a10bc, - 0x183a90e2, - 0x183b0c8c, - 0x183b9131, - 0x183c1143, - 0x183c914e, - 0x183d115e, - 0x183d916f, - 0x183e1180, - 0x183e9192, - 0x183f11bb, - 0x183f91d4, - 0x184011ec, - 0x184086e2, - 0x18411105, - 0x184190d0, - 0x184210ef, - 0x18428c79, - 0x184310ab, - 0x18439117, - 0x18440fc9, - 0x18449038, - 0x20321226, - 0x20329213, - 0x24321232, - 0x243289a2, - 0x24331244, - 0x24339251, - 0x2434125e, - 0x24349270, - 0x2435127f, - 0x2435929c, - 0x243612a9, - 0x243692b7, - 0x243712c5, - 0x243792d3, - 0x243812dc, - 0x243892e9, - 0x243912fc, - 0x28320c61, - 0x28328c8c, - 0x28330c31, - 0x28338c9f, - 0x28340c6d, + 0x18350fee, + 0x18359006, + 0x1836101b, + 0x1836902f, + 0x18371067, + 0x1837907d, + 0x18381091, + 0x183890a1, + 0x18390a9d, + 0x183990b1, + 0x183a10d7, + 0x183a90fd, + 0x183b0ca7, + 0x183b914c, + 0x183c115e, + 0x183c9169, + 0x183d1179, + 0x183d918a, + 0x183e119b, + 0x183e91ad, + 0x183f11d6, + 0x183f91ef, + 0x18401207, + 0x184086fd, + 0x18411120, + 0x184190eb, + 0x1842110a, + 0x18428c94, + 0x184310c6, + 0x18439132, + 0x18440fe4, + 0x18449053, + 0x20321241, + 0x2032922e, + 0x2432124d, + 0x243289bd, + 0x2433125f, + 0x2433926c, + 0x24341279, + 0x2434928b, + 0x2435129a, + 0x243592b7, + 0x243612c4, + 0x243692d2, + 0x243712e0, + 0x243792ee, + 0x243812f7, + 0x24389304, + 0x24391317, + 0x28320c7c, + 0x28328ca7, + 0x28330c4c, + 0x28338cba, + 0x28340c88, 0x283480b9, 0x283500f7, - 0x28358c79, - 0x2c32326b, - 0x2c329313, - 0x2c333279, - 0x2c33b28b, - 0x2c34329f, - 0x2c34b2b1, - 0x2c3532cc, - 0x2c35b2de, - 0x2c36330e, + 0x28358c94, + 0x2c323286, + 0x2c32932e, + 0x2c333294, + 0x2c33b2a6, + 0x2c3432ba, + 0x2c34b2cc, + 0x2c3532e7, + 0x2c35b2f9, + 0x2c363329, 0x2c36833a, - 0x2c37331b, - 0x2c37b347, - 0x2c38336c, - 0x2c38b383, - 0x2c3933a1, - 0x2c39b3b1, - 0x2c3a33c3, - 0x2c3ab3d7, - 0x2c3b33e8, - 0x2c3bb407, - 0x2c3c1325, - 0x2c3c933b, - 0x2c3d341b, - 0x2c3d9354, - 0x2c3e3438, - 0x2c3eb446, - 0x2c3f345e, - 0x2c3fb476, - 0x2c4034a0, - 0x2c409226, - 0x2c4134b1, - 0x2c41b4c4, - 0x2c4211ec, - 0x2c42b4d5, - 0x2c43072f, - 0x2c43b3f9, - 0x2c44335a, - 0x2c44b483, - 0x2c4532f1, - 0x2c45b32d, - 0x2c463391, + 0x2c373336, + 0x2c37b362, + 0x2c383387, + 0x2c38b39e, + 0x2c3933bc, + 0x2c39b3cc, + 0x2c3a33de, + 0x2c3ab3f2, + 0x2c3b3403, + 0x2c3bb422, + 0x2c3c1340, + 0x2c3c9356, + 0x2c3d3436, + 0x2c3d936f, + 0x2c3e3453, + 0x2c3eb461, + 0x2c3f3479, + 0x2c3fb491, + 0x2c4034bb, + 0x2c409241, + 0x2c4134cc, + 0x2c41b4df, + 0x2c421207, + 0x2c42b4f0, + 0x2c43074a, + 0x2c43b414, + 0x2c443375, + 0x2c44b49e, + 0x2c45330c, + 0x2c45b348, + 0x2c4633ac, 0x30320000, 0x30328015, 0x3033001f, @@ -276,528 +276,530 @@ const uint32_t kOpenSSLReasonValues[] = { 0x30458306, 0x3046031f, 0x3046833a, - 0x30470357, - 0x30478369, - 0x30480377, - 0x30488388, - 0x30490397, - 0x304983af, - 0x304a03c1, - 0x304a83d5, - 0x304b03ed, - 0x304b8400, - 0x304c040b, - 0x304c841c, - 0x304d0428, - 0x304d843e, - 0x304e044c, - 0x304e8462, - 0x304f0474, - 0x304f8486, - 0x305004a9, - 0x305084bc, - 0x305104cd, - 0x305184dd, - 0x305204f5, - 0x3052850a, - 0x30530522, - 0x30538536, - 0x3054054e, - 0x30548567, - 0x30550580, - 0x3055859d, - 0x305605a8, - 0x305685c0, - 0x305705d0, - 0x305785e1, - 0x305805f4, - 0x3058860a, - 0x30590613, - 0x30598628, - 0x305a063b, - 0x305a864a, - 0x305b066a, - 0x305b8679, - 0x305c069a, - 0x305c86b6, - 0x305d06c2, - 0x305d86e2, - 0x305e06fe, - 0x305e870f, - 0x305f0725, - 0x305f872f, - 0x30600499, + 0x30470372, + 0x30478384, + 0x30480392, + 0x304883a3, + 0x304903b2, + 0x304983ca, + 0x304a03dc, + 0x304a83f0, + 0x304b0408, + 0x304b841b, + 0x304c0426, + 0x304c8437, + 0x304d0443, + 0x304d8459, + 0x304e0467, + 0x304e847d, + 0x304f048f, + 0x304f84a1, + 0x305004c4, + 0x305084d7, + 0x305104e8, + 0x305184f8, + 0x30520510, + 0x30528525, + 0x3053053d, + 0x30538551, + 0x30540569, + 0x30548582, + 0x3055059b, + 0x305585b8, + 0x305605c3, + 0x305685db, + 0x305705eb, + 0x305785fc, + 0x3058060f, + 0x30588625, + 0x3059062e, + 0x30598643, + 0x305a0656, + 0x305a8665, + 0x305b0685, + 0x305b8694, + 0x305c06b5, + 0x305c86d1, + 0x305d06dd, + 0x305d86fd, + 0x305e0719, + 0x305e872a, + 0x305f0740, + 0x305f874a, + 0x306004b4, 0x3060804a, - 0x34320b72, - 0x34328b86, - 0x34330ba3, - 0x34338bb6, - 0x34340bc5, - 0x34348bfe, - 0x34350be2, + 0x30610357, + 0x34320b8d, + 0x34328ba1, + 0x34330bbe, + 0x34338bd1, + 0x34340be0, + 0x34348c19, + 0x34350bfd, 0x3c320090, - 0x3c328cc9, - 0x3c330ce2, - 0x3c338cfd, - 0x3c340d1a, - 0x3c348d44, - 0x3c350d5f, - 0x3c358d85, - 0x3c360d9e, - 0x3c368db6, - 0x3c370dc7, - 0x3c378dd5, - 0x3c380de2, - 0x3c388df6, - 0x3c390c8c, - 0x3c398e19, - 0x3c3a0e2d, - 0x3c3a891c, - 0x3c3b0e3d, - 0x3c3b8e58, - 0x3c3c0e6a, - 0x3c3c8e9d, - 0x3c3d0ea7, - 0x3c3d8ebb, - 0x3c3e0ec9, - 0x3c3e8eee, - 0x3c3f0cb5, - 0x3c3f8ed7, + 0x3c328ce4, + 0x3c330cfd, + 0x3c338d18, + 0x3c340d35, + 0x3c348d5f, + 0x3c350d7a, + 0x3c358da0, + 0x3c360db9, + 0x3c368dd1, + 0x3c370de2, + 0x3c378df0, + 0x3c380dfd, + 0x3c388e11, + 0x3c390ca7, + 0x3c398e34, + 0x3c3a0e48, + 0x3c3a8937, + 0x3c3b0e58, + 0x3c3b8e73, + 0x3c3c0e85, + 0x3c3c8eb8, + 0x3c3d0ec2, + 0x3c3d8ed6, + 0x3c3e0ee4, + 0x3c3e8f09, + 0x3c3f0cd0, + 0x3c3f8ef2, 0x3c4000b9, 0x3c4080f7, - 0x3c410d35, - 0x3c418d74, - 0x3c420e80, - 0x3c428e0a, - 0x403219b8, - 0x403299ce, - 0x403319fc, - 0x40339a06, - 0x40341a1d, - 0x40349a3b, - 0x40351a4b, - 0x40359a5d, - 0x40361a6a, - 0x40369a76, - 0x40371a8b, - 0x40379a9d, - 0x40381aa8, - 0x40389aba, - 0x40390f34, - 0x40399aca, - 0x403a1add, - 0x403a9afe, - 0x403b1b0f, - 0x403b9b1f, + 0x3c410d50, + 0x3c418d8f, + 0x3c420e9b, + 0x3c428e25, + 0x403219d3, + 0x403299e9, + 0x40331a17, + 0x40339a21, + 0x40341a38, + 0x40349a56, + 0x40351a66, + 0x40359a78, + 0x40361a85, + 0x40369a91, + 0x40371aa6, + 0x40379ab8, + 0x40381ac3, + 0x40389ad5, + 0x40390f4f, + 0x40399ae5, + 0x403a1af8, + 0x403a9b19, + 0x403b1b2a, + 0x403b9b3a, 0x403c0071, 0x403c8090, - 0x403d1b80, - 0x403d9b96, - 0x403e1ba5, - 0x403e9bdd, - 0x403f1bf7, - 0x403f9c1f, - 0x40401c34, - 0x40409c48, - 0x40411c83, - 0x40419c9e, - 0x40421cb7, - 0x40429cca, - 0x40431cde, - 0x40439d0c, - 0x40441d23, + 0x403d1b9b, + 0x403d9bb1, + 0x403e1bc0, + 0x403e9bf8, + 0x403f1c12, + 0x403f9c3a, + 0x40401c4f, + 0x40409c63, + 0x40411c9e, + 0x40419cb9, + 0x40421cd2, + 0x40429ce5, + 0x40431cf9, + 0x40439d27, + 0x40441d3e, 0x404480b9, - 0x40451d38, - 0x40459d4a, - 0x40461d6e, - 0x40469d8e, - 0x40471d9c, - 0x40479dc3, - 0x40481e34, - 0x40489eee, - 0x40491f05, - 0x40499f1f, - 0x404a1f36, - 0x404a9f54, - 0x404b1f6c, - 0x404b9f99, - 0x404c1faf, - 0x404c9fc1, - 0x404d1fe2, - 0x404da01b, - 0x404e202f, - 0x404ea03c, - 0x404f20d6, - 0x404fa14c, - 0x405021a3, - 0x4050a1b7, - 0x405121ea, - 0x405221fa, - 0x4052a21e, - 0x40532236, - 0x4053a249, - 0x4054225e, - 0x4054a281, - 0x405522ac, - 0x4055a2e9, - 0x4056230e, - 0x4056a327, - 0x4057233f, - 0x4057a352, - 0x40582367, - 0x4058a38e, - 0x405923bd, - 0x4059a3ea, - 0x405a23fe, - 0x405aa40e, - 0x405b2426, - 0x405ba437, - 0x405c244a, - 0x405ca489, - 0x405d2496, - 0x405da4bb, - 0x405e24f9, - 0x405e8ac0, - 0x405f2534, - 0x405fa541, - 0x4060254f, - 0x4060a571, - 0x406125d2, - 0x4061a60a, - 0x40622621, - 0x4062a632, - 0x4063267f, - 0x4063a694, - 0x406426ab, - 0x4064a6d7, - 0x406526f2, - 0x4065a709, - 0x40662721, - 0x4066a74b, - 0x40672776, - 0x4067a7bb, - 0x40682803, - 0x4068a824, - 0x40692856, - 0x4069a884, - 0x406a28a5, - 0x406aa8c5, - 0x406b2a4d, - 0x406baa70, - 0x406c2a86, - 0x406cad90, - 0x406d2dbf, - 0x406dade7, - 0x406e2e15, - 0x406eae62, - 0x406f2ebb, - 0x406faef3, - 0x40702f06, - 0x4070af23, - 0x4071080f, - 0x4071af35, - 0x40722f48, - 0x4072af7e, - 0x40732f96, - 0x40739525, - 0x40742faa, - 0x4074afc4, - 0x40752fd5, - 0x4075afe9, - 0x40762ff7, - 0x407692e9, - 0x4077301c, - 0x4077b05c, - 0x40783077, - 0x4078b0b0, - 0x407930c7, - 0x4079b0dd, - 0x407a3109, - 0x407ab11c, - 0x407b3131, - 0x407bb143, - 0x407c3174, - 0x407cb17d, - 0x407d283f, - 0x407da15c, - 0x407e308c, - 0x407ea39e, - 0x407f1db0, - 0x407f9f83, - 0x408020e6, - 0x40809dd8, - 0x4081220c, - 0x4081a08a, - 0x40822e00, - 0x40829b2b, - 0x40832379, - 0x4083a6bc, - 0x40841dec, - 0x4084a3d6, - 0x4085245b, - 0x4085a599, - 0x408624db, - 0x4086a176, - 0x40872e46, - 0x4087a5e7, - 0x40881b69, - 0x4088a7ce, - 0x40891bb8, - 0x40899b45, - 0x408a2abe, - 0x408a993d, - 0x408b3158, - 0x408baed0, - 0x408c246b, - 0x408c9975, - 0x408d1ed4, - 0x408d9e1e, - 0x408e2004, - 0x408ea2c9, - 0x408f27e2, - 0x408fa5b5, - 0x40902797, - 0x4090a4ad, - 0x40912aa6, - 0x4091999b, - 0x40921c05, - 0x4092ae81, - 0x40932f61, - 0x4093a187, - 0x40941e00, - 0x4094aad7, - 0x40952643, - 0x4095b0e9, - 0x40962e2d, - 0x4096a0ff, - 0x409721d2, - 0x4097a053, - 0x40981c65, - 0x4098a657, - 0x40992e9d, - 0x4099a2f6, - 0x409a228f, - 0x409a9959, - 0x409b1e5a, - 0x409b9e85, - 0x409c303e, - 0x409c9ead, - 0x409d20bb, - 0x409da0a0, - 0x409e1cf6, - 0x409ea134, - 0x409f211c, - 0x409f9e4d, - 0x40a0251a, - 0x40a0a06d, - 0x41f42978, - 0x41f92a0a, - 0x41fe28fd, - 0x41feabb3, - 0x41ff2ce1, - 0x42032991, - 0x420829b3, - 0x4208a9ef, - 0x420928e1, - 0x4209aa29, - 0x420a2938, - 0x420aa918, - 0x420b2958, - 0x420ba9d1, - 0x420c2cfd, - 0x420caae7, - 0x420d2b9a, - 0x420dabd1, - 0x42122c04, - 0x42172cc4, - 0x4217ac46, - 0x421c2c68, - 0x421f2c23, - 0x42212d75, - 0x42262ca7, - 0x422b2d53, - 0x422bab75, - 0x422c2d35, - 0x422cab28, - 0x422d2b01, - 0x422dad14, - 0x422e2b54, - 0x42302c83, - 0x4230abeb, - 0x4432073a, - 0x44328749, - 0x44330755, - 0x44338763, - 0x44340776, - 0x44348787, - 0x4435078e, - 0x44358798, - 0x443607ab, - 0x443687c1, - 0x443707d3, - 0x443787e0, - 0x443807ef, - 0x443887f7, - 0x4439080f, - 0x4439881d, - 0x443a0830, - 0x48321313, - 0x48329325, - 0x4833133b, - 0x48339354, - 0x4c321379, - 0x4c329389, - 0x4c33139c, - 0x4c3393bc, + 0x40451d53, + 0x40459d65, + 0x40461d89, + 0x40469da9, + 0x40471db7, + 0x40479dde, + 0x40481e4f, + 0x40489f09, + 0x40491f20, + 0x40499f3a, + 0x404a1f51, + 0x404a9f6f, + 0x404b1f87, + 0x404b9fb4, + 0x404c1fca, + 0x404c9fdc, + 0x404d1ffd, + 0x404da036, + 0x404e204a, + 0x404ea057, + 0x404f20f1, + 0x404fa167, + 0x405021be, + 0x4050a1d2, + 0x40512205, + 0x40522215, + 0x4052a239, + 0x40532251, + 0x4053a264, + 0x40542279, + 0x4054a29c, + 0x405522c7, + 0x4055a304, + 0x40562329, + 0x4056a342, + 0x4057235a, + 0x4057a36d, + 0x40582382, + 0x4058a3a9, + 0x405923d8, + 0x4059a405, + 0x405a2419, + 0x405aa429, + 0x405b2441, + 0x405ba452, + 0x405c2465, + 0x405ca4a4, + 0x405d24b1, + 0x405da4d6, + 0x405e2514, + 0x405e8adb, + 0x405f254f, + 0x405fa55c, + 0x4060256a, + 0x4060a58c, + 0x406125ed, + 0x4061a625, + 0x4062263c, + 0x4062a64d, + 0x4063269a, + 0x4063a6af, + 0x406426c6, + 0x4064a6f2, + 0x4065270d, + 0x4065a724, + 0x4066273c, + 0x4066a766, + 0x40672791, + 0x4067a7d6, + 0x4068281e, + 0x4068a83f, + 0x40692871, + 0x4069a89f, + 0x406a28c0, + 0x406aa8e0, + 0x406b2a68, + 0x406baa8b, + 0x406c2aa1, + 0x406cadab, + 0x406d2dda, + 0x406dae02, + 0x406e2e30, + 0x406eae7d, + 0x406f2ed6, + 0x406faf0e, + 0x40702f21, + 0x4070af3e, + 0x4071082a, + 0x4071af50, + 0x40722f63, + 0x4072af99, + 0x40732fb1, + 0x40739540, + 0x40742fc5, + 0x4074afdf, + 0x40752ff0, + 0x4075b004, + 0x40763012, + 0x40769304, + 0x40773037, + 0x4077b077, + 0x40783092, + 0x4078b0cb, + 0x407930e2, + 0x4079b0f8, + 0x407a3124, + 0x407ab137, + 0x407b314c, + 0x407bb15e, + 0x407c318f, + 0x407cb198, + 0x407d285a, + 0x407da177, + 0x407e30a7, + 0x407ea3b9, + 0x407f1dcb, + 0x407f9f9e, + 0x40802101, + 0x40809df3, + 0x40812227, + 0x4081a0a5, + 0x40822e1b, + 0x40829b46, + 0x40832394, + 0x4083a6d7, + 0x40841e07, + 0x4084a3f1, + 0x40852476, + 0x4085a5b4, + 0x408624f6, + 0x4086a191, + 0x40872e61, + 0x4087a602, + 0x40881b84, + 0x4088a7e9, + 0x40891bd3, + 0x40899b60, + 0x408a2ad9, + 0x408a9958, + 0x408b3173, + 0x408baeeb, + 0x408c2486, + 0x408c9990, + 0x408d1eef, + 0x408d9e39, + 0x408e201f, + 0x408ea2e4, + 0x408f27fd, + 0x408fa5d0, + 0x409027b2, + 0x4090a4c8, + 0x40912ac1, + 0x409199b6, + 0x40921c20, + 0x4092ae9c, + 0x40932f7c, + 0x4093a1a2, + 0x40941e1b, + 0x4094aaf2, + 0x4095265e, + 0x4095b104, + 0x40962e48, + 0x4096a11a, + 0x409721ed, + 0x4097a06e, + 0x40981c80, + 0x4098a672, + 0x40992eb8, + 0x4099a311, + 0x409a22aa, + 0x409a9974, + 0x409b1e75, + 0x409b9ea0, + 0x409c3059, + 0x409c9ec8, + 0x409d20d6, + 0x409da0bb, + 0x409e1d11, + 0x409ea14f, + 0x409f2137, + 0x409f9e68, + 0x40a02535, + 0x40a0a088, + 0x41f42993, + 0x41f92a25, + 0x41fe2918, + 0x41feabce, + 0x41ff2cfc, + 0x420329ac, + 0x420829ce, + 0x4208aa0a, + 0x420928fc, + 0x4209aa44, + 0x420a2953, + 0x420aa933, + 0x420b2973, + 0x420ba9ec, + 0x420c2d18, + 0x420cab02, + 0x420d2bb5, + 0x420dabec, + 0x42122c1f, + 0x42172cdf, + 0x4217ac61, + 0x421c2c83, + 0x421f2c3e, + 0x42212d90, + 0x42262cc2, + 0x422b2d6e, + 0x422bab90, + 0x422c2d50, + 0x422cab43, + 0x422d2b1c, + 0x422dad2f, + 0x422e2b6f, + 0x42302c9e, + 0x4230ac06, + 0x44320755, + 0x44328764, + 0x44330770, + 0x4433877e, + 0x44340791, + 0x443487a2, + 0x443507a9, + 0x443587b3, + 0x443607c6, + 0x443687dc, + 0x443707ee, + 0x443787fb, + 0x4438080a, + 0x44388812, + 0x4439082a, + 0x44398838, + 0x443a084b, + 0x4832132e, + 0x48329340, + 0x48331356, + 0x4833936f, + 0x4c321394, + 0x4c3293a4, + 0x4c3313b7, + 0x4c3393d7, 0x4c3400b9, 0x4c3480f7, - 0x4c3513c8, - 0x4c3593d6, - 0x4c3613f2, - 0x4c369418, - 0x4c371427, - 0x4c379435, - 0x4c38144a, - 0x4c389456, - 0x4c391476, - 0x4c3994a0, - 0x4c3a14b9, - 0x4c3a94d2, - 0x4c3b060a, - 0x4c3b94eb, - 0x4c3c14fd, - 0x4c3c950c, - 0x4c3d1525, - 0x4c3d8c54, - 0x4c3e1592, - 0x4c3e9534, - 0x4c3f15b4, - 0x4c3f92e9, - 0x4c40154a, - 0x4c409365, - 0x4c411582, - 0x4c419405, - 0x4c42156e, - 0x503234e7, - 0x5032b4f6, - 0x50333501, - 0x5033b511, - 0x5034352a, - 0x5034b544, - 0x50353552, - 0x5035b568, - 0x5036357a, - 0x5036b590, - 0x503735a9, - 0x5037b5bc, - 0x503835d4, - 0x5038b5e5, - 0x503935fa, - 0x5039b60e, - 0x503a362e, - 0x503ab644, - 0x503b365c, - 0x503bb66e, - 0x503c368a, - 0x503cb6a1, - 0x503d36ba, - 0x503db6d0, - 0x503e36dd, - 0x503eb6f3, - 0x503f3705, - 0x503f8388, - 0x50403718, - 0x5040b728, - 0x50413742, - 0x5041b751, - 0x5042376b, - 0x5042b788, - 0x50433798, - 0x5043b7a8, - 0x504437c5, - 0x5044843e, - 0x504537d9, - 0x5045b7f7, - 0x5046380a, - 0x5046b820, - 0x50473832, - 0x5047b847, - 0x5048386d, - 0x5048b87b, - 0x5049388e, - 0x5049b8a3, - 0x504a38b9, - 0x504ab8c9, - 0x504b38e9, - 0x504bb8fc, - 0x504c391f, - 0x504cb94d, - 0x504d395f, - 0x504db97c, - 0x504e3997, - 0x504eb9b3, - 0x504f39c5, - 0x504fb9dc, - 0x505039eb, - 0x505086fe, - 0x505139fe, - 0x5051b7b7, - 0x58320f72, - 0x68320f34, - 0x68328c8c, - 0x68330c9f, - 0x68338f42, - 0x68340f52, + 0x4c3513e3, + 0x4c3593f1, + 0x4c36140d, + 0x4c369433, + 0x4c371442, + 0x4c379450, + 0x4c381465, + 0x4c389471, + 0x4c391491, + 0x4c3994bb, + 0x4c3a14d4, + 0x4c3a94ed, + 0x4c3b0625, + 0x4c3b9506, + 0x4c3c1518, + 0x4c3c9527, + 0x4c3d1540, + 0x4c3d8c6f, + 0x4c3e15ad, + 0x4c3e954f, + 0x4c3f15cf, + 0x4c3f9304, + 0x4c401565, + 0x4c409380, + 0x4c41159d, + 0x4c419420, + 0x4c421589, + 0x50323502, + 0x5032b511, + 0x5033351c, + 0x5033b52c, + 0x50343545, + 0x5034b55f, + 0x5035356d, + 0x5035b583, + 0x50363595, + 0x5036b5ab, + 0x503735c4, + 0x5037b5d7, + 0x503835ef, + 0x5038b600, + 0x50393615, + 0x5039b629, + 0x503a3649, + 0x503ab65f, + 0x503b3677, + 0x503bb689, + 0x503c36a5, + 0x503cb6bc, + 0x503d36d5, + 0x503db6eb, + 0x503e36f8, + 0x503eb70e, + 0x503f3720, + 0x503f83a3, + 0x50403733, + 0x5040b743, + 0x5041375d, + 0x5041b76c, + 0x50423786, + 0x5042b7a3, + 0x504337b3, + 0x5043b7c3, + 0x504437e0, + 0x50448459, + 0x504537f4, + 0x5045b812, + 0x50463825, + 0x5046b83b, + 0x5047384d, + 0x5047b862, + 0x50483888, + 0x5048b896, + 0x504938a9, + 0x5049b8be, + 0x504a38d4, + 0x504ab8e4, + 0x504b3904, + 0x504bb917, + 0x504c393a, + 0x504cb968, + 0x504d3995, + 0x504db9b2, + 0x504e39cd, + 0x504eb9e9, + 0x504f39fb, + 0x504fba12, + 0x50503a21, + 0x50508719, + 0x50513a34, + 0x5051b7d2, + 0x5052397a, + 0x58320f8d, + 0x68320f4f, + 0x68328ca7, + 0x68330cba, + 0x68338f5d, + 0x68340f6d, 0x683480f7, - 0x6c320efa, - 0x6c328c43, - 0x6c330f05, - 0x6c338f1e, - 0x74320a28, + 0x6c320f15, + 0x6c328c5e, + 0x6c330f20, + 0x6c338f39, + 0x74320a43, 0x743280b9, - 0x74330c54, - 0x7832098d, - 0x783289a2, - 0x783309ae, + 0x74330c6f, + 0x783209a8, + 0x783289bd, + 0x783309c9, 0x78338090, - 0x783409bd, - 0x783489d2, - 0x783509f1, - 0x78358a13, - 0x78360a28, - 0x78368a3e, - 0x78370a4e, - 0x78378a6f, - 0x78380a82, - 0x78388a94, - 0x78390aa1, - 0x78398ac0, - 0x783a0ad5, - 0x783a8ae3, - 0x783b0aed, - 0x783b8b01, - 0x783c0b18, - 0x783c8b2d, - 0x783d0b44, - 0x783d8b59, - 0x783e0aaf, - 0x783e8a61, - 0x7c321202, - 0x80321418, + 0x783409d8, + 0x783489ed, + 0x78350a0c, + 0x78358a2e, + 0x78360a43, + 0x78368a59, + 0x78370a69, + 0x78378a8a, + 0x78380a9d, + 0x78388aaf, + 0x78390abc, + 0x78398adb, + 0x783a0af0, + 0x783a8afe, + 0x783b0b08, + 0x783b8b1c, + 0x783c0b33, + 0x783c8b48, + 0x783d0b5f, + 0x783d8b74, + 0x783e0aca, + 0x783e8a7c, + 0x7c32121d, + 0x80321433, 0x80328090, - 0x8033323a, + 0x80333255, 0x803380b9, - 0x80343249, - 0x8034b1b1, - 0x803531cf, - 0x8035b25d, - 0x80363211, - 0x8036b1c0, - 0x80373203, - 0x8037b19e, - 0x80383224, - 0x8038b1e0, - 0x803931f5, + 0x80343264, + 0x8034b1cc, + 0x803531ea, + 0x8035b278, + 0x8036322c, + 0x8036b1db, + 0x8037321e, + 0x8037b1b9, + 0x8038323f, + 0x8038b1fb, + 0x80393210, }; const size_t kOpenSSLReasonValuesLen = sizeof(kOpenSSLReasonValues) / sizeof(kOpenSSLReasonValues[0]); @@ -846,6 +848,7 @@ const char kOpenSSLReasonStringData[] = "INTEGER_NOT_ASCII_FORMAT\0" "INTEGER_TOO_LARGE_FOR_LONG\0" "INVALID_BIT_STRING_BITS_LEFT\0" + "INVALID_BIT_STRING_PADDING\0" "INVALID_BMPSTRING\0" "INVALID_DIGIT\0" "INVALID_MODIFIER\0" @@ -1477,6 +1480,7 @@ const char kOpenSSLReasonStringData[] = "POLICY_PATH_LENGTH_ALREADY_DEFINED\0" "POLICY_WHEN_PROXY_LANGUAGE_REQUIRES_NO_POLICY\0" "SECTION_NOT_FOUND\0" + "TRAILING_DATA_IN_EXTENSION\0" "UNABLE_TO_GET_ISSUER_DETAILS\0" "UNABLE_TO_GET_ISSUER_KEYID\0" "UNKNOWN_BIT_STRING_ARGUMENT\0" diff --git a/Sources/CCryptoBoringSSL/crypto/evp/evp_asn1.c b/Sources/CCryptoBoringSSL/crypto/evp/evp_asn1.c index dff43b26..513865ff 100644 --- a/Sources/CCryptoBoringSSL/crypto/evp/evp_asn1.c +++ b/Sources/CCryptoBoringSSL/crypto/evp/evp_asn1.c @@ -369,8 +369,8 @@ EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **out, const uint8_t **inp, // Unlike OpenSSL, we do not support EC keys with this API. The raw EC // public key serialization requires knowing the group. In OpenSSL, calling // this function with |EVP_PKEY_EC| and setting |out| to NULL does not work. - // It requires |*out| to include a partially-initiazed |EVP_PKEY| to extract - // the group. + // It requires |*out| to include a partially-initialized |EVP_PKEY| to + // extract the group. default: OPENSSL_PUT_ERROR(EVP, EVP_R_UNSUPPORTED_PUBLIC_KEY_TYPE); goto err; diff --git a/Sources/CCryptoBoringSSL/crypto/evp/scrypt.c b/Sources/CCryptoBoringSSL/crypto/evp/scrypt.c index aca09f62..8d4511d6 100644 --- a/Sources/CCryptoBoringSSL/crypto/evp/scrypt.c +++ b/Sources/CCryptoBoringSSL/crypto/evp/scrypt.c @@ -32,8 +32,6 @@ typedef struct { uint32_t words[16]; } block_t; OPENSSL_STATIC_ASSERT(sizeof(block_t) == 64, "block_t has padding"); -#define R(a, b) (((a) << (b)) | ((a) >> (32 - (b)))) - // salsa208_word_specification implements the Salsa20/8 core function, also // described in RFC 7914, section 3. It modifies the block at |inout| // in-place. @@ -42,38 +40,38 @@ static void salsa208_word_specification(block_t *inout) { OPENSSL_memcpy(&x, inout, sizeof(x)); for (int i = 8; i > 0; i -= 2) { - x.words[4] ^= R(x.words[0] + x.words[12], 7); - x.words[8] ^= R(x.words[4] + x.words[0], 9); - x.words[12] ^= R(x.words[8] + x.words[4], 13); - x.words[0] ^= R(x.words[12] + x.words[8], 18); - x.words[9] ^= R(x.words[5] + x.words[1], 7); - x.words[13] ^= R(x.words[9] + x.words[5], 9); - x.words[1] ^= R(x.words[13] + x.words[9], 13); - x.words[5] ^= R(x.words[1] + x.words[13], 18); - x.words[14] ^= R(x.words[10] + x.words[6], 7); - x.words[2] ^= R(x.words[14] + x.words[10], 9); - x.words[6] ^= R(x.words[2] + x.words[14], 13); - x.words[10] ^= R(x.words[6] + x.words[2], 18); - x.words[3] ^= R(x.words[15] + x.words[11], 7); - x.words[7] ^= R(x.words[3] + x.words[15], 9); - x.words[11] ^= R(x.words[7] + x.words[3], 13); - x.words[15] ^= R(x.words[11] + x.words[7], 18); - x.words[1] ^= R(x.words[0] + x.words[3], 7); - x.words[2] ^= R(x.words[1] + x.words[0], 9); - x.words[3] ^= R(x.words[2] + x.words[1], 13); - x.words[0] ^= R(x.words[3] + x.words[2], 18); - x.words[6] ^= R(x.words[5] + x.words[4], 7); - x.words[7] ^= R(x.words[6] + x.words[5], 9); - x.words[4] ^= R(x.words[7] + x.words[6], 13); - x.words[5] ^= R(x.words[4] + x.words[7], 18); - x.words[11] ^= R(x.words[10] + x.words[9], 7); - x.words[8] ^= R(x.words[11] + x.words[10], 9); - x.words[9] ^= R(x.words[8] + x.words[11], 13); - x.words[10] ^= R(x.words[9] + x.words[8], 18); - x.words[12] ^= R(x.words[15] + x.words[14], 7); - x.words[13] ^= R(x.words[12] + x.words[15], 9); - x.words[14] ^= R(x.words[13] + x.words[12], 13); - x.words[15] ^= R(x.words[14] + x.words[13], 18); + x.words[4] ^= CRYPTO_rotl_u32(x.words[0] + x.words[12], 7); + x.words[8] ^= CRYPTO_rotl_u32(x.words[4] + x.words[0], 9); + x.words[12] ^= CRYPTO_rotl_u32(x.words[8] + x.words[4], 13); + x.words[0] ^= CRYPTO_rotl_u32(x.words[12] + x.words[8], 18); + x.words[9] ^= CRYPTO_rotl_u32(x.words[5] + x.words[1], 7); + x.words[13] ^= CRYPTO_rotl_u32(x.words[9] + x.words[5], 9); + x.words[1] ^= CRYPTO_rotl_u32(x.words[13] + x.words[9], 13); + x.words[5] ^= CRYPTO_rotl_u32(x.words[1] + x.words[13], 18); + x.words[14] ^= CRYPTO_rotl_u32(x.words[10] + x.words[6], 7); + x.words[2] ^= CRYPTO_rotl_u32(x.words[14] + x.words[10], 9); + x.words[6] ^= CRYPTO_rotl_u32(x.words[2] + x.words[14], 13); + x.words[10] ^= CRYPTO_rotl_u32(x.words[6] + x.words[2], 18); + x.words[3] ^= CRYPTO_rotl_u32(x.words[15] + x.words[11], 7); + x.words[7] ^= CRYPTO_rotl_u32(x.words[3] + x.words[15], 9); + x.words[11] ^= CRYPTO_rotl_u32(x.words[7] + x.words[3], 13); + x.words[15] ^= CRYPTO_rotl_u32(x.words[11] + x.words[7], 18); + x.words[1] ^= CRYPTO_rotl_u32(x.words[0] + x.words[3], 7); + x.words[2] ^= CRYPTO_rotl_u32(x.words[1] + x.words[0], 9); + x.words[3] ^= CRYPTO_rotl_u32(x.words[2] + x.words[1], 13); + x.words[0] ^= CRYPTO_rotl_u32(x.words[3] + x.words[2], 18); + x.words[6] ^= CRYPTO_rotl_u32(x.words[5] + x.words[4], 7); + x.words[7] ^= CRYPTO_rotl_u32(x.words[6] + x.words[5], 9); + x.words[4] ^= CRYPTO_rotl_u32(x.words[7] + x.words[6], 13); + x.words[5] ^= CRYPTO_rotl_u32(x.words[4] + x.words[7], 18); + x.words[11] ^= CRYPTO_rotl_u32(x.words[10] + x.words[9], 7); + x.words[8] ^= CRYPTO_rotl_u32(x.words[11] + x.words[10], 9); + x.words[9] ^= CRYPTO_rotl_u32(x.words[8] + x.words[11], 13); + x.words[10] ^= CRYPTO_rotl_u32(x.words[9] + x.words[8], 18); + x.words[12] ^= CRYPTO_rotl_u32(x.words[15] + x.words[14], 7); + x.words[13] ^= CRYPTO_rotl_u32(x.words[12] + x.words[15], 9); + x.words[14] ^= CRYPTO_rotl_u32(x.words[13] + x.words[12], 13); + x.words[15] ^= CRYPTO_rotl_u32(x.words[14] + x.words[13], 18); } for (int i = 0; i < 16; ++i) { diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/aesni-gcm-x86_64.linux.x86_64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/aesni-gcm-x86_64.linux.x86_64.S index ff150a36..c78dc452 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/aesni-gcm-x86_64.linux.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/aesni-gcm-x86_64.linux.x86_64.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__x86_64__) && defined(__linux__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__has_feature) #if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/aesni-gcm-x86_64.mac.x86_64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/aesni-gcm-x86_64.mac.x86_64.S index 870c9d87..4a768db2 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/aesni-gcm-x86_64.mac.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/aesni-gcm-x86_64.mac.x86_64.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__x86_64__) && defined(__APPLE__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__has_feature) #if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/aesni-x86.linux.x86.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/aesni-x86.linux.x86.S index be04e265..42ba650d 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/aesni-x86.linux.x86.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/aesni-x86.linux.x86.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__i386__) && defined(__linux__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__i386__) #if defined(BORINGSSL_PREFIX) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/aesni-x86.windows.x86.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/aesni-x86.windows.x86.S index 83475993..5e1ee312 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/aesni-x86.windows.x86.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/aesni-x86.windows.x86.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__i386__) && defined(_WIN32) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__i386__) #if defined(BORINGSSL_PREFIX) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/aesni-x86_64.linux.x86_64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/aesni-x86_64.linux.x86_64.S index daceddf4..2849eddb 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/aesni-x86_64.linux.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/aesni-x86_64.linux.x86_64.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__x86_64__) && defined(__linux__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__has_feature) #if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/aesni-x86_64.mac.x86_64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/aesni-x86_64.mac.x86_64.S index 89ab5472..9eaf2553 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/aesni-x86_64.mac.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/aesni-x86_64.mac.x86_64.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__x86_64__) && defined(__APPLE__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__has_feature) #if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn-586.linux.x86.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn-586.linux.x86.S index 73910162..add87184 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn-586.linux.x86.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn-586.linux.x86.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__i386__) && defined(__linux__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__i386__) #if defined(BORINGSSL_PREFIX) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn-586.windows.x86.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn-586.windows.x86.S index 006a67f9..39f9a777 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn-586.windows.x86.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn-586.windows.x86.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__i386__) && defined(_WIN32) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__i386__) #if defined(BORINGSSL_PREFIX) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn/sqrt.c b/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn/sqrt.c index d216fd10..0f47df7e 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn/sqrt.c +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn/sqrt.c @@ -75,10 +75,8 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) { if (ret == NULL) { ret = BN_new(); } - if (ret == NULL) { - goto end; - } - if (!BN_set_word(ret, BN_is_bit_set(a, 0))) { + if (ret == NULL || + !BN_set_word(ret, BN_is_bit_set(a, 0))) { if (ret != in) { BN_free(ret); } @@ -88,17 +86,15 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) { } OPENSSL_PUT_ERROR(BN, BN_R_P_IS_NOT_PRIME); - return (NULL); + return NULL; } if (BN_is_zero(a) || BN_is_one(a)) { if (ret == NULL) { ret = BN_new(); } - if (ret == NULL) { - goto end; - } - if (!BN_set_word(ret, BN_is_one(a))) { + if (ret == NULL || + !BN_set_word(ret, BN_is_one(a))) { if (ret != in) { BN_free(ret); } diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/cipher/e_aes.c b/Sources/CCryptoBoringSSL/crypto/fipsmodule/cipher/e_aes.c index 2c5e5305..6efbab17 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/cipher/e_aes.c +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/cipher/e_aes.c @@ -911,6 +911,16 @@ static int aead_aes_gcm_init_impl(struct aead_aes_gcm_ctx *gcm_ctx, size_t key_len, size_t tag_len) { const size_t key_bits = key_len * 8; + switch (key_bits) { + case 128: + boringssl_fips_inc_counter(fips_counter_evp_aes_128_gcm); + break; + + case 256: + boringssl_fips_inc_counter(fips_counter_evp_aes_256_gcm); + break; + } + if (key_bits != 128 && key_bits != 192 && key_bits != 256) { OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_BAD_KEY_LENGTH); return 0; // EVP_AEAD_CTX_init should catch this. diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/co-586.linux.x86.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/co-586.linux.x86.S index 277dcbb0..fad49af3 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/co-586.linux.x86.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/co-586.linux.x86.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__i386__) && defined(__linux__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__i386__) #if defined(BORINGSSL_PREFIX) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/co-586.windows.x86.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/co-586.windows.x86.S index f74cbc6c..a190dd4d 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/co-586.windows.x86.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/co-586.windows.x86.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__i386__) && defined(_WIN32) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__i386__) #if defined(BORINGSSL_PREFIX) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/des/des.c b/Sources/CCryptoBoringSSL/crypto/fipsmodule/des/des.c index 504ee6f7..3380f942 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/des/des.c +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/des/des.c @@ -342,10 +342,10 @@ void DES_set_key(const DES_cblock *key, DES_key_schedule *schedule) { // table contained 0213 4657 t2 = ((t << 16L) | (s & 0x0000ffffL)) & 0xffffffffL; - schedule->subkeys[i][0] = ROTATE(t2, 30) & 0xffffffffL; + schedule->subkeys[i][0] = CRYPTO_rotr_u32(t2, 30); t2 = ((s >> 16L) | (t & 0xffff0000L)); - schedule->subkeys[i][1] = ROTATE(t2, 26) & 0xffffffffL; + schedule->subkeys[i][1] = CRYPTO_rotr_u32(t2, 26); } } @@ -392,8 +392,8 @@ static void DES_encrypt1(uint32_t *data, const DES_key_schedule *ks, int enc) { // <71755.204@CompuServe.COM> for pointing this out. // clear the top bits on machines with 8byte longs // shift left by 2 - r = ROTATE(r, 29) & 0xffffffffL; - l = ROTATE(l, 29) & 0xffffffffL; + r = CRYPTO_rotr_u32(r, 29); + l = CRYPTO_rotr_u32(l, 29); // I don't know if it is worth the effort of loop unrolling the // inner loop @@ -434,8 +434,8 @@ static void DES_encrypt1(uint32_t *data, const DES_key_schedule *ks, int enc) { } // rotate and clear the top bits on machines with 8byte longs - l = ROTATE(l, 3) & 0xffffffffL; - r = ROTATE(r, 3) & 0xffffffffL; + l = CRYPTO_rotr_u32(l, 3); + r = CRYPTO_rotr_u32(r, 3); FP(r, l); data[0] = l; @@ -454,8 +454,8 @@ static void DES_encrypt2(uint32_t *data, const DES_key_schedule *ks, int enc) { // sparc2. Thanks to Richard Outerbridge <71755.204@CompuServe.COM> for // pointing this out. // clear the top bits on machines with 8byte longs - r = ROTATE(r, 29) & 0xffffffffL; - l = ROTATE(l, 29) & 0xffffffffL; + r = CRYPTO_rotr_u32(r, 29); + l = CRYPTO_rotr_u32(l, 29); // I don't know if it is worth the effort of loop unrolling the // inner loop @@ -495,8 +495,8 @@ static void DES_encrypt2(uint32_t *data, const DES_key_schedule *ks, int enc) { D_ENCRYPT(ks, r, l, 0); } // rotate and clear the top bits on machines with 8byte longs - data[0] = ROTATE(l, 3) & 0xffffffffL; - data[1] = ROTATE(r, 3) & 0xffffffffL; + data[0] = CRYPTO_rotr_u32(l, 3); + data[1] = CRYPTO_rotr_u32(r, 3); } void DES_encrypt3(uint32_t *data, const DES_key_schedule *ks1, @@ -782,4 +782,3 @@ void DES_set_key_unchecked(const DES_cblock *key, DES_key_schedule *schedule) { #undef D_ENCRYPT #undef ITERATIONS #undef HALF_ITERATIONS -#undef ROTATE diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/des/internal.h b/Sources/CCryptoBoringSSL/crypto/fipsmodule/des/internal.h index 69b1d903..0b642f1b 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/des/internal.h +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/des/internal.h @@ -218,7 +218,7 @@ how to use xors :-) I got it to its final state. #define D_ENCRYPT(ks, LL, R, S) \ do { \ LOAD_DATA(ks, R, S, u, t, E0, E1); \ - t = ROTATE(t, 4); \ + t = CRYPTO_rotr_u32(t, 4); \ (LL) ^= \ DES_SPtrans[0][(u >> 2L) & 0x3f] ^ DES_SPtrans[2][(u >> 10L) & 0x3f] ^ \ DES_SPtrans[4][(u >> 18L) & 0x3f] ^ \ @@ -230,8 +230,6 @@ how to use xors :-) I got it to its final state. #define ITERATIONS 16 #define HALF_ITERATIONS 8 -#define ROTATE(a, n) (((a) >> (n)) + ((a) << (32 - (n)))) - #if defined(__cplusplus) } // extern C diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/ecdsa/ecdsa.c b/Sources/CCryptoBoringSSL/crypto/fipsmodule/ecdsa/ecdsa.c index ef226e2d..7da65d9f 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/ecdsa/ecdsa.c +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/ecdsa/ecdsa.c @@ -68,8 +68,7 @@ // digest_to_scalar interprets |digest_len| bytes from |digest| as a scalar for -// ECDSA. Note this value is not fully reduced modulo the order, only the -// correct number of bits. +// ECDSA. static void digest_to_scalar(const EC_GROUP *group, EC_SCALAR *out, const uint8_t *digest, size_t digest_len) { const BIGNUM *order = &group->order; diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-ssse3-x86.linux.x86.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-ssse3-x86.linux.x86.S index 452ef10b..bf8ba0a0 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-ssse3-x86.linux.x86.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-ssse3-x86.linux.x86.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__i386__) && defined(__linux__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__i386__) #if defined(BORINGSSL_PREFIX) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-ssse3-x86.windows.x86.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-ssse3-x86.windows.x86.S index a47ee3a3..7818c72c 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-ssse3-x86.windows.x86.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-ssse3-x86.windows.x86.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__i386__) && defined(_WIN32) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__i386__) #if defined(BORINGSSL_PREFIX) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-ssse3-x86_64.linux.x86_64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-ssse3-x86_64.linux.x86_64.S index a820cd99..58c63779 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-ssse3-x86_64.linux.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-ssse3-x86_64.linux.x86_64.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__x86_64__) && defined(__linux__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__has_feature) #if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-ssse3-x86_64.mac.x86_64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-ssse3-x86_64.mac.x86_64.S index 4dcfacfc..8cb21830 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-ssse3-x86_64.mac.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-ssse3-x86_64.mac.x86_64.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__x86_64__) && defined(__APPLE__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__has_feature) #if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-x86.linux.x86.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-x86.linux.x86.S index 5cb9c131..20ab9cb8 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-x86.linux.x86.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-x86.linux.x86.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__i386__) && defined(__linux__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__i386__) #if defined(BORINGSSL_PREFIX) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-x86.windows.x86.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-x86.windows.x86.S index e24e06f8..6c04499e 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-x86.windows.x86.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-x86.windows.x86.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__i386__) && defined(_WIN32) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__i386__) #if defined(BORINGSSL_PREFIX) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-x86_64.linux.x86_64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-x86_64.linux.x86_64.S index a3b69807..43fc10cc 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-x86_64.linux.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-x86_64.linux.x86_64.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__x86_64__) && defined(__linux__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__has_feature) #if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-x86_64.mac.x86_64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-x86_64.mac.x86_64.S index ef65dd24..e0202641 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-x86_64.mac.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-x86_64.mac.x86_64.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__x86_64__) && defined(__APPLE__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__has_feature) #if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/md4/md4.c b/Sources/CCryptoBoringSSL/crypto/fipsmodule/md4/md4.c index b98bf098..808c4667 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/md4/md4.c +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/md4/md4.c @@ -113,24 +113,22 @@ int MD4_Final(uint8_t out[MD4_DIGEST_LENGTH], MD4_CTX *c) { #define G(b, c, d) (((b) & (c)) | ((b) & (d)) | ((c) & (d))) #define H(b, c, d) ((b) ^ (c) ^ (d)) -#define ROTATE(a, n) (((a) << (n)) | ((a) >> (32 - (n)))) - #define R0(a, b, c, d, k, s, t) \ do { \ (a) += ((k) + (t) + F((b), (c), (d))); \ - (a) = ROTATE(a, s); \ + (a) = CRYPTO_rotl_u32(a, s); \ } while (0) #define R1(a, b, c, d, k, s, t) \ do { \ (a) += ((k) + (t) + G((b), (c), (d))); \ - (a) = ROTATE(a, s); \ + (a) = CRYPTO_rotl_u32(a, s); \ } while (0) #define R2(a, b, c, d, k, s, t) \ do { \ (a) += ((k) + (t) + H((b), (c), (d))); \ - (a) = ROTATE(a, s); \ + (a) = CRYPTO_rotl_u32(a, s); \ } while (0) void md4_block_data_order(uint32_t *state, const uint8_t *data, size_t num) { @@ -237,7 +235,6 @@ void md4_block_data_order(uint32_t *state, const uint8_t *data, size_t num) { #undef F #undef G #undef H -#undef ROTATE #undef R0 #undef R1 #undef R2 diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/md5-586.linux.x86.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/md5-586.linux.x86.S index e0db549a..e3e4c3b3 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/md5-586.linux.x86.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/md5-586.linux.x86.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__i386__) && defined(__linux__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__i386__) #if defined(BORINGSSL_PREFIX) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/md5-586.windows.x86.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/md5-586.windows.x86.S index 11d416cc..decb96cb 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/md5-586.windows.x86.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/md5-586.windows.x86.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__i386__) && defined(_WIN32) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__i386__) #if defined(BORINGSSL_PREFIX) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/md5-x86_64.linux.x86_64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/md5-x86_64.linux.x86_64.S index bb5f27f9..7dc7446c 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/md5-x86_64.linux.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/md5-x86_64.linux.x86_64.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__x86_64__) && defined(__linux__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__has_feature) #if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/md5-x86_64.mac.x86_64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/md5-x86_64.mac.x86_64.S index 656564ef..1babf630 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/md5-x86_64.mac.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/md5-x86_64.mac.x86_64.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__x86_64__) && defined(__APPLE__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__has_feature) #if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/md5/md5.c b/Sources/CCryptoBoringSSL/crypto/fipsmodule/md5/md5.c index 105036b9..5394eb8f 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/md5/md5.c +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/md5/md5.c @@ -119,33 +119,31 @@ int MD5_Final(uint8_t out[MD5_DIGEST_LENGTH], MD5_CTX *c) { #define H(b, c, d) ((b) ^ (c) ^ (d)) #define I(b, c, d) (((~(d)) | (b)) ^ (c)) -#define ROTATE(a, n) (((a) << (n)) | ((a) >> (32 - (n)))) - #define R0(a, b, c, d, k, s, t) \ do { \ (a) += ((k) + (t) + F((b), (c), (d))); \ - (a) = ROTATE(a, s); \ + (a) = CRYPTO_rotl_u32(a, s); \ (a) += (b); \ } while (0) #define R1(a, b, c, d, k, s, t) \ do { \ (a) += ((k) + (t) + G((b), (c), (d))); \ - (a) = ROTATE(a, s); \ + (a) = CRYPTO_rotl_u32(a, s); \ (a) += (b); \ } while (0) #define R2(a, b, c, d, k, s, t) \ do { \ (a) += ((k) + (t) + H((b), (c), (d))); \ - (a) = ROTATE(a, s); \ + (a) = CRYPTO_rotl_u32(a, s); \ (a) += (b); \ } while (0) #define R3(a, b, c, d, k, s, t) \ do { \ (a) += ((k) + (t) + I((b), (c), (d))); \ - (a) = ROTATE(a, s); \ + (a) = CRYPTO_rotl_u32(a, s); \ (a) += (b); \ } while (0) @@ -280,7 +278,6 @@ static void md5_block_data_order(uint32_t *state, const uint8_t *data, #undef G #undef H #undef I -#undef ROTATE #undef R0 #undef R1 #undef R2 diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/p256-x86_64-asm.linux.x86_64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/p256-x86_64-asm.linux.x86_64.S index 5006b678..7417084d 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/p256-x86_64-asm.linux.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/p256-x86_64-asm.linux.x86_64.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__x86_64__) && defined(__linux__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__has_feature) #if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/p256-x86_64-asm.mac.x86_64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/p256-x86_64-asm.mac.x86_64.S index 756bb669..2de15d64 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/p256-x86_64-asm.mac.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/p256-x86_64-asm.mac.x86_64.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__x86_64__) && defined(__APPLE__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__has_feature) #if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/p256_beeu-x86_64-asm.linux.x86_64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/p256_beeu-x86_64-asm.linux.x86_64.S index 2b3841cc..6cc3fee1 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/p256_beeu-x86_64-asm.linux.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/p256_beeu-x86_64-asm.linux.x86_64.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__x86_64__) && defined(__linux__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__has_feature) #if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/p256_beeu-x86_64-asm.mac.x86_64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/p256_beeu-x86_64-asm.mac.x86_64.S index 83e2d94a..c95c5a66 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/p256_beeu-x86_64-asm.mac.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/p256_beeu-x86_64-asm.mac.x86_64.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__x86_64__) && defined(__APPLE__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__has_feature) #if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/rdrand-x86_64.linux.x86_64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/rdrand-x86_64.linux.x86_64.S index 5736f490..70851a8e 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/rdrand-x86_64.linux.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/rdrand-x86_64.linux.x86_64.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__x86_64__) && defined(__linux__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__has_feature) #if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/rdrand-x86_64.mac.x86_64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/rdrand-x86_64.mac.x86_64.S index 5a6d7432..430abb58 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/rdrand-x86_64.mac.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/rdrand-x86_64.mac.x86_64.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__x86_64__) && defined(__APPLE__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__has_feature) #if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/rsa/rsa.c b/Sources/CCryptoBoringSSL/crypto/fipsmodule/rsa/rsa.c index 91a862ae..17862ea0 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/rsa/rsa.c +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/rsa/rsa.c @@ -206,6 +206,12 @@ void RSA_get0_factors(const RSA *rsa, const BIGNUM **out_p, } } +const RSA_PSS_PARAMS *RSA_get0_pss_params(const RSA *rsa) { + // We do not support the id-RSASSA-PSS key encoding. If we add support later, + // the |maskHash| field should be filled in for OpenSSL compatibility. + return NULL; +} + void RSA_get0_crt_params(const RSA *rsa, const BIGNUM **out_dmp1, const BIGNUM **out_dmq1, const BIGNUM **out_iqmp) { if (out_dmp1 != NULL) { diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/rsaz-avx2.linux.x86_64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/rsaz-avx2.linux.x86_64.S index 1cf1a9b8..4205cae7 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/rsaz-avx2.linux.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/rsaz-avx2.linux.x86_64.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__x86_64__) && defined(__linux__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__has_feature) #if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/rsaz-avx2.mac.x86_64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/rsaz-avx2.mac.x86_64.S index 1e7f038f..e976ef26 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/rsaz-avx2.mac.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/rsaz-avx2.mac.x86_64.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__x86_64__) && defined(__APPLE__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__has_feature) #if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/self_check/self_check.c b/Sources/CCryptoBoringSSL/crypto/fipsmodule/self_check/self_check.c index 81895908..1662a652 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/self_check/self_check.c +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/self_check/self_check.c @@ -290,27 +290,27 @@ err: } #if defined(OPENSSL_ANDROID) -static const size_t kModuleDigestSize = SHA256_DIGEST_LENGTH; +#define MODULE_DIGEST_SIZE SHA256_DIGEST_LENGTH #else -static const size_t kModuleDigestSize = SHA512_DIGEST_LENGTH; +#define MODULE_DIGEST_SIZE SHA512_DIGEST_LENGTH #endif int boringssl_fips_self_test( const uint8_t *module_hash, size_t module_hash_len) { #if defined(BORINGSSL_FIPS_SELF_TEST_FLAG_FILE) - char flag_path[sizeof(kFlagPrefix) + 2*kModuleDigestSize]; + char flag_path[sizeof(kFlagPrefix) + 2 * MODULE_DIGEST_SIZE]; if (module_hash_len != 0) { - if (module_hash_len != kModuleDigestSize) { + if (module_hash_len != MODULE_DIGEST_SIZE) { fprintf(stderr, - "module hash of length %zu does not match expected length %zu\n", - module_hash_len, kModuleDigestSize); + "module hash of length %zu does not match expected length %d\n", + module_hash_len, MODULE_DIGEST_SIZE); BORINGSSL_FIPS_abort(); } // Test whether the flag file exists. memcpy(flag_path, kFlagPrefix, sizeof(kFlagPrefix) - 1); static const char kHexTable[17] = "0123456789abcdef"; - for (size_t i = 0; i < kModuleDigestSize; i++) { + for (size_t i = 0; i < MODULE_DIGEST_SIZE; i++) { flag_path[sizeof(kFlagPrefix) - 1 + 2 * i] = kHexTable[module_hash[i] >> 4]; flag_path[sizeof(kFlagPrefix) - 1 + 2 * i + 1] = diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha/sha1.c b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha/sha1.c index 246c3fc8..ac7c4b44 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha/sha1.c +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha/sha1.c @@ -111,11 +111,10 @@ int SHA1_Final(uint8_t out[SHA_DIGEST_LENGTH], SHA_CTX *c) { return 1; } -#define ROTATE(a, n) (((a) << (n)) | ((a) >> (32 - (n)))) -#define Xupdate(a, ix, ia, ib, ic, id) \ - do { \ - (a) = ((ia) ^ (ib) ^ (ic) ^ (id)); \ - (ix) = (a) = ROTATE((a), 1); \ +#define Xupdate(a, ix, ia, ib, ic, id) \ + do { \ + (a) = ((ia) ^ (ib) ^ (ic) ^ (id)); \ + (ix) = (a) = CRYPTO_rotl_u32((a), 1); \ } while (0) #define K_00_19 0x5a827999UL @@ -133,45 +132,47 @@ int SHA1_Final(uint8_t out[SHA_DIGEST_LENGTH], SHA_CTX *c) { #define F_40_59(b, c, d) (((b) & (c)) | (((b) | (c)) & (d))) #define F_60_79(b, c, d) F_20_39(b, c, d) -#define BODY_00_15(i, a, b, c, d, e, f, xi) \ - do { \ - (f) = (xi) + (e) + K_00_19 + ROTATE((a), 5) + F_00_19((b), (c), (d)); \ - (b) = ROTATE((b), 30); \ +#define BODY_00_15(i, a, b, c, d, e, f, xi) \ + do { \ + (f) = (xi) + (e) + K_00_19 + CRYPTO_rotl_u32((a), 5) + \ + F_00_19((b), (c), (d)); \ + (b) = CRYPTO_rotl_u32((b), 30); \ } while (0) -#define BODY_16_19(i, a, b, c, d, e, f, xi, xa, xb, xc, xd) \ - do { \ - Xupdate(f, xi, xa, xb, xc, xd); \ - (f) += (e) + K_00_19 + ROTATE((a), 5) + F_00_19((b), (c), (d)); \ - (b) = ROTATE((b), 30); \ +#define BODY_16_19(i, a, b, c, d, e, f, xi, xa, xb, xc, xd) \ + do { \ + Xupdate(f, xi, xa, xb, xc, xd); \ + (f) += (e) + K_00_19 + CRYPTO_rotl_u32((a), 5) + F_00_19((b), (c), (d)); \ + (b) = CRYPTO_rotl_u32((b), 30); \ } while (0) -#define BODY_20_31(i, a, b, c, d, e, f, xi, xa, xb, xc, xd) \ - do { \ - Xupdate(f, xi, xa, xb, xc, xd); \ - (f) += (e) + K_20_39 + ROTATE((a), 5) + F_20_39((b), (c), (d)); \ - (b) = ROTATE((b), 30); \ +#define BODY_20_31(i, a, b, c, d, e, f, xi, xa, xb, xc, xd) \ + do { \ + Xupdate(f, xi, xa, xb, xc, xd); \ + (f) += (e) + K_20_39 + CRYPTO_rotl_u32((a), 5) + F_20_39((b), (c), (d)); \ + (b) = CRYPTO_rotl_u32((b), 30); \ } while (0) -#define BODY_32_39(i, a, b, c, d, e, f, xa, xb, xc, xd) \ - do { \ - Xupdate(f, xa, xa, xb, xc, xd); \ - (f) += (e) + K_20_39 + ROTATE((a), 5) + F_20_39((b), (c), (d)); \ - (b) = ROTATE((b), 30); \ +#define BODY_32_39(i, a, b, c, d, e, f, xa, xb, xc, xd) \ + do { \ + Xupdate(f, xa, xa, xb, xc, xd); \ + (f) += (e) + K_20_39 + CRYPTO_rotl_u32((a), 5) + F_20_39((b), (c), (d)); \ + (b) = CRYPTO_rotl_u32((b), 30); \ } while (0) -#define BODY_40_59(i, a, b, c, d, e, f, xa, xb, xc, xd) \ - do { \ - Xupdate(f, xa, xa, xb, xc, xd); \ - (f) += (e) + K_40_59 + ROTATE((a), 5) + F_40_59((b), (c), (d)); \ - (b) = ROTATE((b), 30); \ +#define BODY_40_59(i, a, b, c, d, e, f, xa, xb, xc, xd) \ + do { \ + Xupdate(f, xa, xa, xb, xc, xd); \ + (f) += (e) + K_40_59 + CRYPTO_rotl_u32((a), 5) + F_40_59((b), (c), (d)); \ + (b) = CRYPTO_rotl_u32((b), 30); \ } while (0) -#define BODY_60_79(i, a, b, c, d, e, f, xa, xb, xc, xd) \ - do { \ - Xupdate(f, xa, xa, xb, xc, xd); \ - (f) = (xa) + (e) + K_60_79 + ROTATE((a), 5) + F_60_79((b), (c), (d)); \ - (b) = ROTATE((b), 30); \ +#define BODY_60_79(i, a, b, c, d, e, f, xa, xb, xc, xd) \ + do { \ + Xupdate(f, xa, xa, xb, xc, xd); \ + (f) = (xa) + (e) + K_60_79 + CRYPTO_rotl_u32((a), 5) + \ + F_60_79((b), (c), (d)); \ + (b) = CRYPTO_rotl_u32((b), 30); \ } while (0) #ifdef X @@ -338,7 +339,6 @@ static void sha1_block_data_order(uint32_t *state, const uint8_t *data, } #endif -#undef ROTATE #undef Xupdate #undef K_00_19 #undef K_20_39 diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha/sha256.c b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha/sha256.c index 26ed09ef..3370ec7f 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha/sha256.c +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha/sha256.c @@ -184,15 +184,17 @@ static const uint32_t K256[64] = { 0x682e6ff3UL, 0x748f82eeUL, 0x78a5636fUL, 0x84c87814UL, 0x8cc70208UL, 0x90befffaUL, 0xa4506cebUL, 0xbef9a3f7UL, 0xc67178f2UL}; -#define ROTATE(a, n) (((a) << (n)) | ((a) >> (32 - (n)))) - -// FIPS specification refers to right rotations, while our ROTATE macro -// is left one. This is why you might notice that rotation coefficients -// differ from those observed in FIPS document by 32-N... -#define Sigma0(x) (ROTATE((x), 30) ^ ROTATE((x), 19) ^ ROTATE((x), 10)) -#define Sigma1(x) (ROTATE((x), 26) ^ ROTATE((x), 21) ^ ROTATE((x), 7)) -#define sigma0(x) (ROTATE((x), 25) ^ ROTATE((x), 14) ^ ((x) >> 3)) -#define sigma1(x) (ROTATE((x), 15) ^ ROTATE((x), 13) ^ ((x) >> 10)) +// See FIPS 180-4, section 4.1.2. +#define Sigma0(x) \ + (CRYPTO_rotr_u32((x), 2) ^ CRYPTO_rotr_u32((x), 13) ^ \ + CRYPTO_rotr_u32((x), 22)) +#define Sigma1(x) \ + (CRYPTO_rotr_u32((x), 6) ^ CRYPTO_rotr_u32((x), 11) ^ \ + CRYPTO_rotr_u32((x), 25)) +#define sigma0(x) \ + (CRYPTO_rotr_u32((x), 7) ^ CRYPTO_rotr_u32((x), 18) ^ ((x) >> 3)) +#define sigma1(x) \ + (CRYPTO_rotr_u32((x), 17) ^ CRYPTO_rotr_u32((x), 19) ^ ((x) >> 10)) #define Ch(x, y, z) (((x) & (y)) ^ ((~(x)) & (z))) #define Maj(x, y, z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) @@ -309,7 +311,6 @@ void SHA256_TransformBlocks(uint32_t state[8], const uint8_t *data, sha256_block_data_order(state, data, num_blocks); } -#undef ROTATE #undef Sigma0 #undef Sigma1 #undef sigma0 diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha/sha512.c b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha/sha512.c index 1735db98..1cc703a7 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha/sha512.c +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha/sha512.c @@ -321,42 +321,16 @@ static const uint64_t K512[80] = { UINT64_C(0x5fcb6fab3ad6faec), UINT64_C(0x6c44198c4a475817), }; -#if defined(__GNUC__) && __GNUC__ >= 2 && !defined(OPENSSL_NO_ASM) -#if defined(__x86_64) || defined(__x86_64__) -#define ROTR(a, n) \ - ({ \ - uint64_t ret; \ - __asm__("rorq %1, %0" : "=r"(ret) : "J"(n), "0"(a) : "cc"); \ - ret; \ - }) -#elif(defined(_ARCH_PPC) && defined(__64BIT__)) || defined(_ARCH_PPC64) -#define ROTR(a, n) \ - ({ \ - uint64_t ret; \ - __asm__("rotrdi %0, %1, %2" : "=r"(ret) : "r"(a), "K"(n)); \ - ret; \ - }) -#elif defined(__aarch64__) -#define ROTR(a, n) \ - ({ \ - uint64_t ret; \ - __asm__("ror %0, %1, %2" : "=r"(ret) : "r"(a), "I"(n)); \ - ret; \ - }) -#endif -#elif defined(_MSC_VER) && defined(_WIN64) -#pragma intrinsic(_rotr64) -#define ROTR(a, n) _rotr64((a), n) -#endif - -#ifndef ROTR -#define ROTR(x, s) (((x) >> s) | (x) << (64 - s)) -#endif - -#define Sigma0(x) (ROTR((x), 28) ^ ROTR((x), 34) ^ ROTR((x), 39)) -#define Sigma1(x) (ROTR((x), 14) ^ ROTR((x), 18) ^ ROTR((x), 41)) -#define sigma0(x) (ROTR((x), 1) ^ ROTR((x), 8) ^ ((x) >> 7)) -#define sigma1(x) (ROTR((x), 19) ^ ROTR((x), 61) ^ ((x) >> 6)) +#define Sigma0(x) \ + (CRYPTO_rotr_u64((x), 28) ^ CRYPTO_rotr_u64((x), 34) ^ \ + CRYPTO_rotr_u64((x), 39)) +#define Sigma1(x) \ + (CRYPTO_rotr_u64((x), 14) ^ CRYPTO_rotr_u64((x), 18) ^ \ + CRYPTO_rotr_u64((x), 41)) +#define sigma0(x) \ + (CRYPTO_rotr_u64((x), 1) ^ CRYPTO_rotr_u64((x), 8) ^ ((x) >> 7)) +#define sigma1(x) \ + (CRYPTO_rotr_u64((x), 19) ^ CRYPTO_rotr_u64((x), 61) ^ ((x) >> 6)) #define Ch(x, y, z) (((x) & (y)) ^ ((~(x)) & (z))) #define Maj(x, y, z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) @@ -524,7 +498,6 @@ static void sha512_block_data_order(uint64_t *state, const uint8_t *in, #endif // !SHA512_ASM -#undef ROTR #undef Sigma0 #undef Sigma1 #undef sigma0 diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha1-586.linux.x86.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha1-586.linux.x86.S index c099d636..4ae06789 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha1-586.linux.x86.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha1-586.linux.x86.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__i386__) && defined(__linux__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__i386__) #if defined(BORINGSSL_PREFIX) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha1-586.windows.x86.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha1-586.windows.x86.S index 972b26d2..6383f860 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha1-586.windows.x86.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha1-586.windows.x86.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__i386__) && defined(_WIN32) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__i386__) #if defined(BORINGSSL_PREFIX) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha1-x86_64.linux.x86_64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha1-x86_64.linux.x86_64.S index c29b772d..ee166b2c 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha1-x86_64.linux.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha1-x86_64.linux.x86_64.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__x86_64__) && defined(__linux__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__has_feature) #if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha1-x86_64.mac.x86_64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha1-x86_64.mac.x86_64.S index f42ce912..a3d5aedd 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha1-x86_64.mac.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha1-x86_64.mac.x86_64.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__x86_64__) && defined(__APPLE__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__has_feature) #if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha256-586.linux.x86.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha256-586.linux.x86.S index 6d39e621..c1b7ef3c 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha256-586.linux.x86.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha256-586.linux.x86.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__i386__) && defined(__linux__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__i386__) #if defined(BORINGSSL_PREFIX) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha256-586.windows.x86.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha256-586.windows.x86.S index 8534e91c..9e422d1f 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha256-586.windows.x86.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha256-586.windows.x86.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__i386__) && defined(_WIN32) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__i386__) #if defined(BORINGSSL_PREFIX) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha256-x86_64.linux.x86_64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha256-x86_64.linux.x86_64.S index ee631c08..55b8205c 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha256-x86_64.linux.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha256-x86_64.linux.x86_64.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__x86_64__) && defined(__linux__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__has_feature) #if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha256-x86_64.mac.x86_64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha256-x86_64.mac.x86_64.S index 33bd48bd..dc41bbea 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha256-x86_64.mac.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha256-x86_64.mac.x86_64.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__x86_64__) && defined(__APPLE__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__has_feature) #if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha512-586.linux.x86.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha512-586.linux.x86.S index 5b43eb7a..47515d33 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha512-586.linux.x86.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha512-586.linux.x86.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__i386__) && defined(__linux__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__i386__) #if defined(BORINGSSL_PREFIX) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha512-586.windows.x86.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha512-586.windows.x86.S index 13285c7e..12c15a95 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha512-586.windows.x86.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha512-586.windows.x86.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__i386__) && defined(_WIN32) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__i386__) #if defined(BORINGSSL_PREFIX) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha512-x86_64.linux.x86_64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha512-x86_64.linux.x86_64.S index ba6bdc6d..f25fd3d1 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha512-x86_64.linux.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha512-x86_64.linux.x86_64.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__x86_64__) && defined(__linux__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__has_feature) #if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha512-x86_64.mac.x86_64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha512-x86_64.mac.x86_64.S index f2ccd556..f88930e2 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha512-x86_64.mac.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha512-x86_64.mac.x86_64.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__x86_64__) && defined(__APPLE__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__has_feature) #if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/vpaes-armv8.ios.aarch64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/vpaes-armv8.ios.aarch64.S index 1981a97f..531bf1c5 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/vpaes-armv8.ios.aarch64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/vpaes-armv8.ios.aarch64.S @@ -1101,8 +1101,8 @@ Lcbc_enc_loop: st1 {v0.16b}, [x4] // write ivec ldp x29,x30,[sp],#16 - AARCH64_VALIDATE_LINK_REGISTER Lcbc_abort: + AARCH64_VALIDATE_LINK_REGISTER ret diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/vpaes-armv8.linux.aarch64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/vpaes-armv8.linux.aarch64.S index e81a697d..80ee2f77 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/vpaes-armv8.linux.aarch64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/vpaes-armv8.linux.aarch64.S @@ -1102,8 +1102,8 @@ vpaes_cbc_encrypt: st1 {v0.16b}, [x4] // write ivec ldp x29,x30,[sp],#16 - AARCH64_VALIDATE_LINK_REGISTER .Lcbc_abort: + AARCH64_VALIDATE_LINK_REGISTER ret .size vpaes_cbc_encrypt,.-vpaes_cbc_encrypt diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/vpaes-x86.linux.x86.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/vpaes-x86.linux.x86.S index c4d067f5..ee6177fd 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/vpaes-x86.linux.x86.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/vpaes-x86.linux.x86.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__i386__) && defined(__linux__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__i386__) #if defined(BORINGSSL_PREFIX) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/vpaes-x86.windows.x86.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/vpaes-x86.windows.x86.S index feb5b901..f8ebf3ac 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/vpaes-x86.windows.x86.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/vpaes-x86.windows.x86.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__i386__) && defined(_WIN32) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__i386__) #if defined(BORINGSSL_PREFIX) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/vpaes-x86_64.linux.x86_64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/vpaes-x86_64.linux.x86_64.S index bab69742..89625d76 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/vpaes-x86_64.linux.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/vpaes-x86_64.linux.x86_64.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__x86_64__) && defined(__linux__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__has_feature) #if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/vpaes-x86_64.mac.x86_64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/vpaes-x86_64.mac.x86_64.S index afffbbbd..6112eafb 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/vpaes-x86_64.mac.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/vpaes-x86_64.mac.x86_64.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__x86_64__) && defined(__APPLE__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__has_feature) #if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/x86-mont.linux.x86.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/x86-mont.linux.x86.S index 5df808d7..e1258130 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/x86-mont.linux.x86.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/x86-mont.linux.x86.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__i386__) && defined(__linux__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__i386__) #if defined(BORINGSSL_PREFIX) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/x86-mont.windows.x86.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/x86-mont.windows.x86.S index 945a9102..65d2669a 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/x86-mont.windows.x86.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/x86-mont.windows.x86.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__i386__) && defined(_WIN32) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__i386__) #if defined(BORINGSSL_PREFIX) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/x86_64-mont.linux.x86_64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/x86_64-mont.linux.x86_64.S index 50febc95..586ba96d 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/x86_64-mont.linux.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/x86_64-mont.linux.x86_64.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__x86_64__) && defined(__linux__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__has_feature) #if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/x86_64-mont.mac.x86_64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/x86_64-mont.mac.x86_64.S index 474ee38f..a8c86a7b 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/x86_64-mont.mac.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/x86_64-mont.mac.x86_64.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__x86_64__) && defined(__APPLE__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__has_feature) #if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/x86_64-mont5.linux.x86_64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/x86_64-mont5.linux.x86_64.S index cd9ce70e..39b06692 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/x86_64-mont5.linux.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/x86_64-mont5.linux.x86_64.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__x86_64__) && defined(__linux__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__has_feature) #if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/x86_64-mont5.mac.x86_64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/x86_64-mont5.mac.x86_64.S index ca859d85..2e6740f1 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/x86_64-mont5.mac.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/x86_64-mont5.mac.x86_64.S @@ -1,7 +1,7 @@ #define BORINGSSL_PREFIX CCryptoBoringSSL #if defined(__x86_64__) && defined(__APPLE__) -# This file is generated from a similarly-named Perl script in the BoringSSL -# source tree. Do not edit by hand. +// This file is generated from a similarly-named Perl script in the BoringSSL +// source tree. Do not edit by hand. #if defined(__has_feature) #if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM) diff --git a/Sources/CCryptoBoringSSL/crypto/internal.h b/Sources/CCryptoBoringSSL/crypto/internal.h index b422e917..81813aba 100644 --- a/Sources/CCryptoBoringSSL/crypto/internal.h +++ b/Sources/CCryptoBoringSSL/crypto/internal.h @@ -890,6 +890,45 @@ static inline void CRYPTO_store_word_le(void *out, crypto_word_t v) { } +// Bit rotation functions. +// +// Note these functions use |(-shift) & 31|, etc., because shifting by the bit +// width is undefined. Both Clang and GCC recognize this pattern as a rotation, +// but MSVC does not. Instead, we call MSVC's built-in functions. + +static inline uint32_t CRYPTO_rotl_u32(uint32_t value, int shift) { +#if defined(_MSC_VER) + return _rotl(value, shift); +#else + return (value << shift) | (value >> ((-shift) & 31)); +#endif +} + +static inline uint32_t CRYPTO_rotr_u32(uint32_t value, int shift) { +#if defined(_MSC_VER) + return _rotr(value, shift); +#else + return (value >> shift) | (value << ((-shift) & 31)); +#endif +} + +static inline uint64_t CRYPTO_rotl_u64(uint64_t value, int shift) { +#if defined(_MSC_VER) + return _rotl64(value, shift); +#else + return (value << shift) | (value >> ((-shift) & 63)); +#endif +} + +static inline uint64_t CRYPTO_rotr_u64(uint64_t value, int shift) { +#if defined(_MSC_VER) + return _rotr64(value, shift); +#else + return (value >> shift) | (value << ((-shift) & 63)); +#endif +} + + // FIPS functions. #if defined(BORINGSSL_FIPS) diff --git a/Sources/CCryptoBoringSSL/crypto/mem.c b/Sources/CCryptoBoringSSL/crypto/mem.c index 66e1ace9..de8ac0e1 100644 --- a/Sources/CCryptoBoringSSL/crypto/mem.c +++ b/Sources/CCryptoBoringSSL/crypto/mem.c @@ -125,6 +125,16 @@ WEAK_SYMBOL_FUNC(void*, OPENSSL_memory_alloc, (size_t size)); WEAK_SYMBOL_FUNC(void, OPENSSL_memory_free, (void *ptr)); WEAK_SYMBOL_FUNC(size_t, OPENSSL_memory_get_size, (void *ptr)); +// kBoringSSLBinaryTag is a distinctive byte sequence to identify binaries that +// are linking in BoringSSL and, roughly, what version they are using. +static const uint8_t kBoringSSLBinaryTag[18] = { + // 16 bytes of magic tag. + 0x8c, 0x62, 0x20, 0x0b, 0xd2, 0xa0, 0x72, 0x58, + 0x44, 0xa8, 0x96, 0x69, 0xad, 0x55, 0x7e, 0xec, + // Current source iteration. Incremented ~monthly. + 1, 0, +}; + void *OPENSSL_malloc(size_t size) { if (OPENSSL_memory_alloc != NULL) { assert(OPENSSL_memory_free != NULL); @@ -133,6 +143,14 @@ void *OPENSSL_malloc(size_t size) { } if (size + OPENSSL_MALLOC_PREFIX < size) { + // |OPENSSL_malloc| is a central function in BoringSSL thus a reference to + // |kBoringSSLBinaryTag| is created here so that the tag isn't discarded by + // the linker. The following is sufficient to stop GCC, Clang, and MSVC + // optimising away the reference at the time of writing. Since this + // probably results in an actual memory reference, it is put in this very + // rare code path. + uint8_t unused = *(volatile uint8_t *)kBoringSSLBinaryTag; + (void) unused; return NULL; } @@ -380,3 +398,13 @@ void *OPENSSL_memdup(const void *data, size_t size) { OPENSSL_memcpy(ret, data, size); return ret; } + +void *CRYPTO_malloc(size_t size, const char *file, int line) { + return OPENSSL_malloc(size); +} + +void *CRYPTO_realloc(void *ptr, size_t new_size, const char *file, int line) { + return OPENSSL_realloc(ptr, new_size); +} + +void CRYPTO_free(void *ptr, const char *file, int line) { OPENSSL_free(ptr); } diff --git a/Sources/CCryptoBoringSSL/crypto/pkcs7/internal.h b/Sources/CCryptoBoringSSL/crypto/pkcs7/internal.h index 8e9d4e73..d7ac8f0c 100644 --- a/Sources/CCryptoBoringSSL/crypto/pkcs7/internal.h +++ b/Sources/CCryptoBoringSSL/crypto/pkcs7/internal.h @@ -32,14 +32,23 @@ extern "C" { // NULL. int pkcs7_parse_header(uint8_t **der_bytes, CBS *out, CBS *cbs); -// pkcs7_bundle writes a PKCS#7, SignedData structure to |out| and then calls -// |cb| with a CBB to which certificate or CRL data can be written, and the -// opaque context pointer, |arg|. The callback can return zero to indicate an -// error. +// pkcs7_add_signed_data writes a PKCS#7, SignedData structure to |out|. While +// doing so it makes callbacks to let the caller fill in parts of the structure. +// All callbacks are ignored if NULL and return one on success or zero on error. // -// pkcs7_bundle returns one on success or zero on error. -int pkcs7_bundle(CBB *out, int (*cb)(CBB *out, const void *arg), - const void *arg); +// digest_algos_cb: may write AlgorithmIdentifiers into the given CBB, which +// is a SET of digest algorithms. +// cert_crl_cb: may write the |certificates| or |crls| fields. +// (See https://datatracker.ietf.org/doc/html/rfc2315#section-9.1) +// signer_infos_cb: may write the contents of the |signerInfos| field. +// (See https://datatracker.ietf.org/doc/html/rfc2315#section-9.1) +// +// pkcs7_add_signed_data returns one on success or zero on error. +int pkcs7_add_signed_data(CBB *out, + int (*digest_algos_cb)(CBB *out, const void *arg), + int (*cert_crl_cb)(CBB *out, const void *arg), + int (*signer_infos_cb)(CBB *out, const void *arg), + const void *arg); #if defined(__cplusplus) diff --git a/Sources/CCryptoBoringSSL/crypto/pkcs7/pkcs7.c b/Sources/CCryptoBoringSSL/crypto/pkcs7/pkcs7.c index ec3a74d5..28467af0 100644 --- a/Sources/CCryptoBoringSSL/crypto/pkcs7/pkcs7.c +++ b/Sources/CCryptoBoringSSL/crypto/pkcs7/pkcs7.c @@ -131,8 +131,11 @@ err: return ret; } -int pkcs7_bundle(CBB *out, int (*cb)(CBB *out, const void *arg), - const void *arg) { +int pkcs7_add_signed_data(CBB *out, + int (*digest_algos_cb)(CBB *out, const void *arg), + int (*cert_crl_cb)(CBB *out, const void *arg), + int (*signer_infos_cb)(CBB *out, const void *arg), + const void *arg) { CBB outer_seq, oid, wrapped_seq, seq, version_bytes, digest_algos_set, content_info, signer_infos; @@ -147,11 +150,13 @@ int pkcs7_bundle(CBB *out, int (*cb)(CBB *out, const void *arg), !CBB_add_asn1(&seq, &version_bytes, CBS_ASN1_INTEGER) || !CBB_add_u8(&version_bytes, 1) || !CBB_add_asn1(&seq, &digest_algos_set, CBS_ASN1_SET) || + (digest_algos_cb != NULL && !digest_algos_cb(&digest_algos_set, arg)) || !CBB_add_asn1(&seq, &content_info, CBS_ASN1_SEQUENCE) || !CBB_add_asn1(&content_info, &oid, CBS_ASN1_OBJECT) || !CBB_add_bytes(&oid, kPKCS7Data, sizeof(kPKCS7Data)) || - !cb(&seq, arg) || - !CBB_add_asn1(&seq, &signer_infos, CBS_ASN1_SET)) { + (cert_crl_cb != NULL && !cert_crl_cb(&seq, arg)) || + !CBB_add_asn1(&seq, &signer_infos, CBS_ASN1_SET) || + (signer_infos_cb != NULL && !signer_infos_cb(&signer_infos, arg))) { return 0; } diff --git a/Sources/CCryptoBoringSSL/crypto/pkcs7/pkcs7_x509.c b/Sources/CCryptoBoringSSL/crypto/pkcs7/pkcs7_x509.c index aed92bbe..11c78808 100644 --- a/Sources/CCryptoBoringSSL/crypto/pkcs7/pkcs7_x509.c +++ b/Sources/CCryptoBoringSSL/crypto/pkcs7/pkcs7_x509.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -197,7 +198,9 @@ static int pkcs7_bundle_certificates_cb(CBB *out, const void *arg) { } int PKCS7_bundle_certificates(CBB *out, const STACK_OF(X509) *certs) { - return pkcs7_bundle(out, pkcs7_bundle_certificates_cb, certs); + return pkcs7_add_signed_data(out, /*digest_algos_cb=*/NULL, + pkcs7_bundle_certificates_cb, + /*signer_infos_cb=*/NULL, certs); } static int pkcs7_bundle_crls_cb(CBB *out, const void *arg) { @@ -228,7 +231,9 @@ static int pkcs7_bundle_crls_cb(CBB *out, const void *arg) { } int PKCS7_bundle_CRLs(CBB *out, const STACK_OF(X509_CRL) *crls) { - return pkcs7_bundle(out, pkcs7_bundle_crls_cb, crls); + return pkcs7_add_signed_data(out, /*digest_algos_cb=*/NULL, + pkcs7_bundle_crls_cb, + /*signer_infos_cb=*/NULL, crls); } static PKCS7 *pkcs7_new(CBS *cbs) { @@ -362,26 +367,160 @@ int PKCS7_type_is_enveloped(const PKCS7 *p7) { return 0; } int PKCS7_type_is_signed(const PKCS7 *p7) { return 1; } int PKCS7_type_is_signedAndEnveloped(const PKCS7 *p7) { return 0; } +// write_sha256_ai writes an AlgorithmIdentifier for SHA-256 to +// |digest_algos_set|. +static int write_sha256_ai(CBB *digest_algos_set, const void *arg) { + CBB seq; + return CBB_add_asn1(digest_algos_set, &seq, CBS_ASN1_SEQUENCE) && + OBJ_nid2cbb(&seq, NID_sha256) && // + // https://datatracker.ietf.org/doc/html/rfc5754#section-2 + // "Implementations MUST generate SHA2 AlgorithmIdentifiers with absent + // parameters." + CBB_flush(digest_algos_set); +} + +// sign_sha256 writes at most |max_out_sig| bytes of the signature of |data| by +// |pkey| to |out_sig| and sets |*out_sig_len| to the number of bytes written. +// It returns one on success or zero on error. +static int sign_sha256(uint8_t *out_sig, size_t *out_sig_len, + size_t max_out_sig, EVP_PKEY *pkey, BIO *data) { + static const size_t kBufSize = 4096; + uint8_t *buffer = OPENSSL_malloc(kBufSize); + if (!buffer) { + return 0; + } + + EVP_MD_CTX ctx; + EVP_MD_CTX_init(&ctx); + + int ret = 0; + if (!EVP_DigestSignInit(&ctx, NULL, EVP_sha256(), NULL, pkey)) { + goto out; + } + + for (;;) { + const int n = BIO_read(data, buffer, kBufSize); + if (n == 0) { + break; + } else if (n < 0 || !EVP_DigestSignUpdate(&ctx, buffer, n)) { + goto out; + } + } + + *out_sig_len = max_out_sig; + if (!EVP_DigestSignFinal(&ctx, out_sig, out_sig_len)) { + goto out; + } + + ret = 1; + +out: + EVP_MD_CTX_cleanup(&ctx); + OPENSSL_free(buffer); + return ret; +} + +struct signer_info_data { + const X509 *sign_cert; + uint8_t *signature; + size_t signature_len; +}; + +// write_signer_info writes the SignerInfo structure from +// https://datatracker.ietf.org/doc/html/rfc2315#section-9.2 to |out|. It +// returns one on success or zero on error. +static int write_signer_info(CBB *out, const void *arg) { + const struct signer_info_data *const si_data = arg; + + int ret = 0; + uint8_t *subject_bytes = NULL; + uint8_t *serial_bytes = NULL; + + const int subject_len = + i2d_X509_NAME(X509_get_subject_name(si_data->sign_cert), &subject_bytes); + const int serial_len = i2d_ASN1_INTEGER( + (ASN1_INTEGER *)X509_get0_serialNumber(si_data->sign_cert), + &serial_bytes); + + CBB seq, issuer_and_serial, signing_algo, null, signature; + if (subject_len < 0 || + serial_len < 0 || + !CBB_add_asn1(out, &seq, CBS_ASN1_SEQUENCE) || + // version + !CBB_add_asn1_uint64(&seq, 1) || + !CBB_add_asn1(&seq, &issuer_and_serial, CBS_ASN1_SEQUENCE) || + !CBB_add_bytes(&issuer_and_serial, subject_bytes, subject_len) || + !CBB_add_bytes(&issuer_and_serial, serial_bytes, serial_len) || + !write_sha256_ai(&seq, NULL) || + !CBB_add_asn1(&seq, &signing_algo, CBS_ASN1_SEQUENCE) || + !OBJ_nid2cbb(&signing_algo, NID_rsaEncryption) || + !CBB_add_asn1(&signing_algo, &null, CBS_ASN1_NULL) || + !CBB_add_asn1(&seq, &signature, CBS_ASN1_OCTETSTRING) || + !CBB_add_bytes(&signature, si_data->signature, si_data->signature_len) || + !CBB_flush(out)) { + goto out; + } + + ret = 1; + +out: + OPENSSL_free(subject_bytes); + OPENSSL_free(serial_bytes); + return ret; +} + PKCS7 *PKCS7_sign(X509 *sign_cert, EVP_PKEY *pkey, STACK_OF(X509) *certs, BIO *data, int flags) { - if (sign_cert != NULL || pkey != NULL || flags != PKCS7_DETACHED) { - OPENSSL_PUT_ERROR(PKCS7, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); + CBB cbb; + if (!CBB_init(&cbb, 2048)) { return NULL; } - uint8_t *der; + uint8_t *der = NULL; size_t len; - CBB cbb; - if (!CBB_init(&cbb, 2048) || - !PKCS7_bundle_certificates(&cbb, certs) || - !CBB_finish(&cbb, &der, &len)) { - CBB_cleanup(&cbb); - return NULL; + PKCS7 *ret = NULL; + + if (sign_cert == NULL && pkey == NULL && flags == PKCS7_DETACHED) { + // Caller just wants to bundle certificates. + if (!PKCS7_bundle_certificates(&cbb, certs)) { + goto out; + } + } else if (sign_cert != NULL && pkey != NULL && certs == NULL && + data != NULL && + flags == (PKCS7_NOATTR | PKCS7_BINARY | PKCS7_NOCERTS | + PKCS7_DETACHED) && + EVP_PKEY_id(pkey) == NID_rsaEncryption) { + // sign-file.c from the Linux kernel. + const size_t signature_max_len = EVP_PKEY_size(pkey); + struct signer_info_data si_data = { + .sign_cert = sign_cert, + .signature = OPENSSL_malloc(signature_max_len), + }; + + if (!si_data.signature || + !sign_sha256(si_data.signature, &si_data.signature_len, + signature_max_len, pkey, data) || + !pkcs7_add_signed_data(&cbb, write_sha256_ai, /*cert_crl_cb=*/NULL, + write_signer_info, &si_data)) { + OPENSSL_free(si_data.signature); + goto out; + } + OPENSSL_free(si_data.signature); + } else { + OPENSSL_PUT_ERROR(PKCS7, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); + goto out; + } + + if (!CBB_finish(&cbb, &der, &len)) { + goto out; } CBS cbs; CBS_init(&cbs, der, len); - PKCS7 *ret = pkcs7_new(&cbs); + ret = pkcs7_new(&cbs); + +out: + CBB_cleanup(&cbb); OPENSSL_free(der); return ret; } diff --git a/Sources/CCryptoBoringSSL/crypto/pool/internal.h b/Sources/CCryptoBoringSSL/crypto/pool/internal.h index e0b8bc9a..f3ea349e 100644 --- a/Sources/CCryptoBoringSSL/crypto/pool/internal.h +++ b/Sources/CCryptoBoringSSL/crypto/pool/internal.h @@ -18,18 +18,22 @@ #include #include +#include "../lhash/internal.h" + + #if defined(__cplusplus) extern "C" { #endif -DECLARE_LHASH_OF(CRYPTO_BUFFER) +DEFINE_LHASH_OF(CRYPTO_BUFFER) struct crypto_buffer_st { CRYPTO_BUFFER_POOL *pool; uint8_t *data; size_t len; CRYPTO_refcount_t references; + int data_is_static; }; struct crypto_buffer_pool_st { diff --git a/Sources/CCryptoBoringSSL/crypto/pool/pool.c b/Sources/CCryptoBoringSSL/crypto/pool/pool.c index ef3fcbc3..ca524564 100644 --- a/Sources/CCryptoBoringSSL/crypto/pool/pool.c +++ b/Sources/CCryptoBoringSSL/crypto/pool/pool.c @@ -22,12 +22,9 @@ #include #include "../internal.h" -#include "../lhash/internal.h" #include "internal.h" -DEFINE_LHASH_OF(CRYPTO_BUFFER) - static uint32_t CRYPTO_BUFFER_hash(const CRYPTO_BUFFER *buf) { return OPENSSL_hash32(buf->data, buf->len); } @@ -73,16 +70,28 @@ void CRYPTO_BUFFER_POOL_free(CRYPTO_BUFFER_POOL *pool) { OPENSSL_free(pool); } -CRYPTO_BUFFER *CRYPTO_BUFFER_new(const uint8_t *data, size_t len, - CRYPTO_BUFFER_POOL *pool) { +static void crypto_buffer_free_object(CRYPTO_BUFFER *buf) { + if (!buf->data_is_static) { + OPENSSL_free(buf->data); + } + OPENSSL_free(buf); +} + +static CRYPTO_BUFFER *crypto_buffer_new(const uint8_t *data, size_t len, + int data_is_static, + CRYPTO_BUFFER_POOL *pool) { if (pool != NULL) { CRYPTO_BUFFER tmp; tmp.data = (uint8_t *) data; tmp.len = len; CRYPTO_MUTEX_lock_read(&pool->lock); - CRYPTO_BUFFER *const duplicate = - lh_CRYPTO_BUFFER_retrieve(pool->bufs, &tmp); + CRYPTO_BUFFER *duplicate = lh_CRYPTO_BUFFER_retrieve(pool->bufs, &tmp); + if (data_is_static && duplicate != NULL && !duplicate->data_is_static) { + // If the new |CRYPTO_BUFFER| would have static data, but the duplicate + // does not, we replace the old one with the new static version. + duplicate = NULL; + } if (duplicate != NULL) { CRYPTO_refcount_inc(&duplicate->references); } @@ -99,10 +108,15 @@ CRYPTO_BUFFER *CRYPTO_BUFFER_new(const uint8_t *data, size_t len, } OPENSSL_memset(buf, 0, sizeof(CRYPTO_BUFFER)); - buf->data = OPENSSL_memdup(data, len); - if (len != 0 && buf->data == NULL) { - OPENSSL_free(buf); - return NULL; + if (data_is_static) { + buf->data = (uint8_t *)data; + buf->data_is_static = 1; + } else { + buf->data = OPENSSL_memdup(data, len); + if (len != 0 && buf->data == NULL) { + OPENSSL_free(buf); + return NULL; + } } buf->len = len; @@ -116,11 +130,18 @@ CRYPTO_BUFFER *CRYPTO_BUFFER_new(const uint8_t *data, size_t len, CRYPTO_MUTEX_lock_write(&pool->lock); CRYPTO_BUFFER *duplicate = lh_CRYPTO_BUFFER_retrieve(pool->bufs, buf); + if (data_is_static && duplicate != NULL && !duplicate->data_is_static) { + // If the new |CRYPTO_BUFFER| would have static data, but the duplicate does + // not, we replace the old one with the new static version. + duplicate = NULL; + } int inserted = 0; if (duplicate == NULL) { CRYPTO_BUFFER *old = NULL; inserted = lh_CRYPTO_BUFFER_insert(pool->bufs, &old, buf); - assert(old == NULL); + // |old| may be non-NULL if a match was found but ignored. |pool->bufs| does + // not increment refcounts, so there is no need to clean up after the + // replacement. } else { CRYPTO_refcount_inc(&duplicate->references); } @@ -129,14 +150,18 @@ CRYPTO_BUFFER *CRYPTO_BUFFER_new(const uint8_t *data, size_t len, if (!inserted) { // We raced to insert |buf| into the pool and lost, or else there was an // error inserting. - OPENSSL_free(buf->data); - OPENSSL_free(buf); + crypto_buffer_free_object(buf); return duplicate; } return buf; } +CRYPTO_BUFFER *CRYPTO_BUFFER_new(const uint8_t *data, size_t len, + CRYPTO_BUFFER_POOL *pool) { + return crypto_buffer_new(data, len, /*data_is_static=*/0, pool); +} + CRYPTO_BUFFER *CRYPTO_BUFFER_alloc(uint8_t **out_data, size_t len) { CRYPTO_BUFFER *const buf = OPENSSL_malloc(sizeof(CRYPTO_BUFFER)); if (buf == NULL) { @@ -156,10 +181,16 @@ CRYPTO_BUFFER *CRYPTO_BUFFER_alloc(uint8_t **out_data, size_t len) { return buf; } -CRYPTO_BUFFER* CRYPTO_BUFFER_new_from_CBS(CBS *cbs, CRYPTO_BUFFER_POOL *pool) { +CRYPTO_BUFFER *CRYPTO_BUFFER_new_from_CBS(const CBS *cbs, + CRYPTO_BUFFER_POOL *pool) { return CRYPTO_BUFFER_new(CBS_data(cbs), CBS_len(cbs), pool); } +CRYPTO_BUFFER *CRYPTO_BUFFER_new_from_static_data_unsafe( + const uint8_t *data, size_t len, CRYPTO_BUFFER_POOL *pool) { + return crypto_buffer_new(data, len, /*data_is_static=*/1, pool); +} + void CRYPTO_BUFFER_free(CRYPTO_BUFFER *buf) { if (buf == NULL) { return; @@ -171,8 +202,7 @@ void CRYPTO_BUFFER_free(CRYPTO_BUFFER *buf) { // If a reference count of zero is observed, there cannot be a reference // from any pool to this buffer and thus we are able to free this // buffer. - OPENSSL_free(buf->data); - OPENSSL_free(buf); + crypto_buffer_free_object(buf); } return; @@ -188,13 +218,19 @@ void CRYPTO_BUFFER_free(CRYPTO_BUFFER *buf) { // find this buffer and increment the reference count. Thus, if the count is // zero there are and can never be any more references and thus we can free // this buffer. - void *found = lh_CRYPTO_BUFFER_delete(pool->bufs, buf); - assert(found != NULL); - assert(found == buf); - (void)found; + // + // Note it is possible |buf| is no longer in the pool, if it was replaced by a + // static version. If that static version was since removed, it is even + // possible for |found| to be NULL. + CRYPTO_BUFFER *found = lh_CRYPTO_BUFFER_retrieve(pool->bufs, buf); + if (found == buf) { + found = lh_CRYPTO_BUFFER_delete(pool->bufs, buf); + assert(found == buf); + (void)found; + } + CRYPTO_MUTEX_unlock_write(&buf->pool->lock); - OPENSSL_free(buf->data); - OPENSSL_free(buf); + crypto_buffer_free_object(buf); } int CRYPTO_BUFFER_up_ref(CRYPTO_BUFFER *buf) { diff --git a/Sources/CCryptoBoringSSL/crypto/siphash/siphash.c b/Sources/CCryptoBoringSSL/crypto/siphash/siphash.c index df398fbe..01c1eda0 100644 --- a/Sources/CCryptoBoringSSL/crypto/siphash/siphash.c +++ b/Sources/CCryptoBoringSSL/crypto/siphash/siphash.c @@ -23,18 +23,18 @@ static void siphash_round(uint64_t v[4]) { v[0] += v[1]; v[2] += v[3]; - v[1] = (v[1] << 13) | (v[1] >> (64 - 13)); - v[3] = (v[3] << 16) | (v[3] >> (64 - 16)); + v[1] = CRYPTO_rotl_u64(v[1], 13); + v[3] = CRYPTO_rotl_u64(v[3], 16); v[1] ^= v[0]; v[3] ^= v[2]; - v[0] = (v[0] << 32) | (v[0] >> 32); + v[0] = CRYPTO_rotl_u64(v[0], 32); v[2] += v[1]; v[0] += v[3]; - v[1] = (v[1] << 17) | (v[1] >> (64 - 17)); - v[3] = (v[3] << 21) | (v[3] >> (64 - 21)); + v[1] = CRYPTO_rotl_u64(v[1], 17); + v[3] = CRYPTO_rotl_u64(v[3], 21); v[1] ^= v[2]; v[3] ^= v[0]; - v[2] = (v[2] << 32) | (v[2] >> 32); + v[2] = CRYPTO_rotl_u64(v[2], 32); } uint64_t SIPHASH_24(const uint64_t key[2], const uint8_t *input, diff --git a/Sources/CCryptoBoringSSL/crypto/x509/asn1_gen.c b/Sources/CCryptoBoringSSL/crypto/x509/asn1_gen.c index 5477741f..b7a25890 100644 --- a/Sources/CCryptoBoringSSL/crypto/x509/asn1_gen.c +++ b/Sources/CCryptoBoringSSL/crypto/x509/asn1_gen.c @@ -66,6 +66,7 @@ #include "../internal.h" #include "../x509v3/internal.h" +#include "internal.h" /* * Although this file is in crypto/x509 for layering purposes, it emits @@ -136,17 +137,6 @@ static ASN1_TYPE *asn1_multi(int utype, const char *section, X509V3_CTX *cnf, static ASN1_TYPE *asn1_str2type(const char *str, int format, int utype); static int asn1_str2tag(const char *tagstr, int len); -ASN1_TYPE *ASN1_generate_nconf(const char *str, CONF *nconf) -{ - X509V3_CTX cnf; - - if (!nconf) - return ASN1_generate_v3(str, NULL); - - X509V3_set_nconf(&cnf, nconf); - return ASN1_generate_v3(str, &cnf); -} - ASN1_TYPE *ASN1_generate_v3(const char *str, X509V3_CTX *cnf) { int err = 0; @@ -225,13 +215,7 @@ static ASN1_TYPE *generate_v3(const char *str, X509V3_CTX *cnf, int depth, * For IMPLICIT tagging the length should match the original length * and constructed flag should be consistent. */ - if (r & 0x1) { - /* Indefinite length constructed */ - hdr_constructed = 2; - hdr_len = 0; - } else - /* Just retain constructed flag */ - hdr_constructed = r & V_ASN1_CONSTRUCTED; + hdr_constructed = r & V_ASN1_CONSTRUCTED; /* * Work out new length with IMPLICIT tag: ignore constructed because * it will mess up if indefinite length diff --git a/Sources/CCryptoBoringSSL/crypto/x509/internal.h b/Sources/CCryptoBoringSSL/crypto/x509/internal.h index 30280f77..82e6004f 100644 --- a/Sources/CCryptoBoringSSL/crypto/x509/internal.h +++ b/Sources/CCryptoBoringSSL/crypto/x509/internal.h @@ -63,6 +63,8 @@ #include #include +#include "../asn1/internal.h" + #if defined(__cplusplus) extern "C" { #endif @@ -70,10 +72,12 @@ extern "C" { /* Internal structures. */ -struct X509_val_st { +typedef struct X509_val_st { ASN1_TIME *notBefore; ASN1_TIME *notAfter; -} /* X509_VAL */; +} X509_VAL; + +DECLARE_ASN1_FUNCTIONS(X509_VAL) struct X509_pubkey_st { X509_ALGOR *algor; @@ -268,7 +272,6 @@ struct x509_store_st { int cache; // if true, stash any hits STACK_OF(X509_OBJECT) *objs; // Cache of all objects CRYPTO_MUTEX objs_lock; - STACK_OF(X509) *additional_untrusted; // These are external lookup methods STACK_OF(X509_LOOKUP) *get_cert_methods; @@ -355,6 +358,8 @@ struct x509_store_ctx_st { CRYPTO_EX_DATA ex_data; } /* X509_STORE_CTX */; +ASN1_TYPE *ASN1_generate_v3(const char *str, X509V3_CTX *cnf); + /* RSA-PSS functions. */ diff --git a/Sources/CCryptoBoringSSL/crypto/x509/rsa_pss.c b/Sources/CCryptoBoringSSL/crypto/x509/rsa_pss.c index eaa22acb..cc67c641 100644 --- a/Sources/CCryptoBoringSSL/crypto/x509/rsa_pss.c +++ b/Sources/CCryptoBoringSSL/crypto/x509/rsa_pss.c @@ -67,12 +67,21 @@ #include "internal.h" -ASN1_SEQUENCE(RSA_PSS_PARAMS) = { +static int rsa_pss_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, + void *exarg) { + if (operation == ASN1_OP_FREE_PRE) { + RSA_PSS_PARAMS *pss = (RSA_PSS_PARAMS *)*pval; + X509_ALGOR_free(pss->maskHash); + } + return 1; +} + +ASN1_SEQUENCE_cb(RSA_PSS_PARAMS, rsa_pss_cb) = { ASN1_EXP_OPT(RSA_PSS_PARAMS, hashAlgorithm, X509_ALGOR,0), ASN1_EXP_OPT(RSA_PSS_PARAMS, maskGenAlgorithm, X509_ALGOR,1), ASN1_EXP_OPT(RSA_PSS_PARAMS, saltLength, ASN1_INTEGER,2), ASN1_EXP_OPT(RSA_PSS_PARAMS, trailerField, ASN1_INTEGER,3), -} ASN1_SEQUENCE_END(RSA_PSS_PARAMS) +} ASN1_SEQUENCE_END_cb(RSA_PSS_PARAMS, RSA_PSS_PARAMS) IMPLEMENT_ASN1_FUNCTIONS(RSA_PSS_PARAMS) diff --git a/Sources/CCryptoBoringSSL/crypto/x509/x509_lu.c b/Sources/CCryptoBoringSSL/crypto/x509/x509_lu.c index d0a97816..3693f5ea 100644 --- a/Sources/CCryptoBoringSSL/crypto/x509/x509_lu.c +++ b/Sources/CCryptoBoringSSL/crypto/x509/x509_lu.c @@ -404,11 +404,6 @@ int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x) return ret; } -void X509_STORE_set0_additional_untrusted(X509_STORE *ctx, - STACK_OF(X509) *untrusted) { - ctx->additional_untrusted = untrusted; -} - int X509_OBJECT_up_ref_count(X509_OBJECT *a) { switch (a->type) { diff --git a/Sources/CCryptoBoringSSL/crypto/x509/x509_vfy.c b/Sources/CCryptoBoringSSL/crypto/x509/x509_vfy.c index 411f1dd4..d3499b88 100644 --- a/Sources/CCryptoBoringSSL/crypto/x509/x509_vfy.c +++ b/Sources/CCryptoBoringSSL/crypto/x509/x509_vfy.c @@ -222,8 +222,7 @@ int X509_verify_cert(X509_STORE_CTX *ctx) X509_up_ref(ctx->cert); ctx->last_untrusted = 1; - /* We use a temporary STACK so we can chop and hack at it. - * sktmp = ctx->untrusted ++ ctx->ctx->additional_untrusted */ + /* We use a temporary STACK so we can chop and hack at it. */ if (ctx->untrusted != NULL && (sktmp = sk_X509_dup(ctx->untrusted)) == NULL) { OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE); @@ -231,28 +230,6 @@ int X509_verify_cert(X509_STORE_CTX *ctx) goto end; } - if (ctx->ctx->additional_untrusted != NULL) { - if (sktmp == NULL) { - sktmp = sk_X509_new_null(); - if (sktmp == NULL) { - OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE); - ctx->error = X509_V_ERR_OUT_OF_MEM; - goto end; - } - } - - for (size_t k = 0; k < sk_X509_num(ctx->ctx->additional_untrusted); - k++) { - if (!sk_X509_push(sktmp, - sk_X509_value(ctx->ctx->additional_untrusted, - k))) { - OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE); - ctx->error = X509_V_ERR_OUT_OF_MEM; - goto end; - } - } - } - num = sk_X509_num(ctx->chain); x = sk_X509_value(ctx->chain, num - 1); depth = param->depth; @@ -1351,17 +1328,6 @@ static void crl_akid_check(X509_STORE_CTX *ctx, X509_CRL *crl, return; } } - - for (i = 0; i < sk_X509_num(ctx->ctx->additional_untrusted); i++) { - crl_issuer = sk_X509_value(ctx->ctx->additional_untrusted, i); - if (X509_NAME_cmp(X509_get_subject_name(crl_issuer), cnm)) - continue; - if (X509_check_akid(crl_issuer, crl->akid) == X509_V_OK) { - *pissuer = crl_issuer; - *pcrl_score |= CRL_SCORE_AKID; - return; - } - } } /* diff --git a/Sources/CCryptoBoringSSL/crypto/x509/x509_vpm.c b/Sources/CCryptoBoringSSL/crypto/x509/x509_vpm.c index a78fbe45..a2c14ca3 100644 --- a/Sources/CCryptoBoringSSL/crypto/x509/x509_vpm.c +++ b/Sources/CCryptoBoringSSL/crypto/x509/x509_vpm.c @@ -528,7 +528,7 @@ static const X509_VERIFY_PARAM default_table[] = { (char *)"default", /* X509 default parameters */ 0, /* Check time */ 0, /* internal flags */ - 0, /* flags */ + X509_V_FLAG_TRUSTED_FIRST, /* flags */ 0, /* purpose */ 0, /* trust */ 100, /* depth */ diff --git a/Sources/CCryptoBoringSSL/crypto/x509/x_name.c b/Sources/CCryptoBoringSSL/crypto/x509/x_name.c index 17bf1417..ed3b4fbc 100644 --- a/Sources/CCryptoBoringSSL/crypto/x509/x_name.c +++ b/Sources/CCryptoBoringSSL/crypto/x509/x_name.c @@ -261,17 +261,13 @@ static int x509_name_ex_d2i(ASN1_VALUE **val, static int x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass) { - int ret; X509_NAME *a = (X509_NAME *)*val; - if (a->modified) { - ret = x509_name_encode(a); - if (ret < 0) - return ret; - ret = x509_name_canon(a); - if (ret < 0) - return ret; + if (a->modified && + (!x509_name_encode(a) || + !x509_name_canon(a))) { + return -1; } - ret = a->bytes->length; + int ret = a->bytes->length; if (out != NULL) { OPENSSL_memcpy(*out, a->bytes->data, ret); *out += ret; @@ -307,22 +303,29 @@ static int x509_name_encode(X509_NAME *a) goto memerr; } ASN1_VALUE *intname_val = (ASN1_VALUE *)intname; - len = ASN1_item_ex_i2d(&intname_val, NULL, - ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1); + len = + ASN1_item_ex_i2d(&intname_val, NULL, ASN1_ITEM_rptr(X509_NAME_INTERNAL), + /*tag=*/-1, /*aclass=*/0); + if (len <= 0) { + goto err; + } if (!BUF_MEM_grow(a->bytes, len)) goto memerr; p = (unsigned char *)a->bytes->data; - ASN1_item_ex_i2d(&intname_val, - &p, ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1); + if (ASN1_item_ex_i2d(&intname_val, &p, ASN1_ITEM_rptr(X509_NAME_INTERNAL), + /*tag=*/-1, /*aclass=*/0) <= 0) { + goto err; + } sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname, local_sk_X509_NAME_ENTRY_free); a->modified = 0; - return len; + return 1; memerr: + OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE); +err: sk_STACK_OF_X509_NAME_ENTRY_pop_free(intname, local_sk_X509_NAME_ENTRY_free); - OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE); - return -1; + return 0; } /* @@ -504,8 +507,8 @@ static int i2d_name_canon(STACK_OF(STACK_OF_X509_NAME_ENTRY) * _intname, len = 0; for (i = 0; i < sk_ASN1_VALUE_num(intname); i++) { v = sk_ASN1_VALUE_value(intname, i); - ltmp = ASN1_item_ex_i2d(&v, in, - ASN1_ITEM_rptr(X509_NAME_ENTRIES), -1, -1); + ltmp = ASN1_item_ex_i2d(&v, in, ASN1_ITEM_rptr(X509_NAME_ENTRIES), + /*tag=*/-1, /*aclass=*/0); if (ltmp < 0) return ltmp; len += ltmp; diff --git a/Sources/CCryptoBoringSSL/crypto/x509/x_x509.c b/Sources/CCryptoBoringSSL/crypto/x509/x_x509.c index 46c3fa30..fc0b1438 100644 --- a/Sources/CCryptoBoringSSL/crypto/x509/x_x509.c +++ b/Sources/CCryptoBoringSSL/crypto/x509/x_x509.c @@ -289,13 +289,15 @@ static int i2d_x509_aux_internal(X509 *a, unsigned char **pp) return length; } - tmplen = i2d_X509_CERT_AUX(a->aux, pp); - if (tmplen < 0) { - if (start != NULL) - *pp = start; - return tmplen; + if (a->aux != NULL) { + tmplen = i2d_X509_CERT_AUX(a->aux, pp); + if (tmplen < 0) { + if (start != NULL) + *pp = start; + return tmplen; + } + length += tmplen; } - length += tmplen; return length; } diff --git a/Sources/CCryptoBoringSSL/crypto/x509v3/internal.h b/Sources/CCryptoBoringSSL/crypto/x509v3/internal.h index d3b2e7d9..fb213b18 100644 --- a/Sources/CCryptoBoringSSL/crypto/x509v3/internal.h +++ b/Sources/CCryptoBoringSSL/crypto/x509v3/internal.h @@ -1,16 +1,60 @@ -/* Copyright (c) 2018, Google Inc. +/* + * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project + * 2004. + */ +/* ==================================================================== + * Copyright (c) 2004 The OpenSSL Project. All rights reserved. * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY - * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION - * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. All advertising materials mentioning features or use of this + * software must display the following acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" + * + * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to + * endorse or promote products derived from this software without + * prior written permission. For written permission, please contact + * licensing@OpenSSL.org. + * + * 5. Products derived from this software may not be called "OpenSSL" + * nor may "OpenSSL" appear in their names without prior written + * permission of the OpenSSL Project. + * + * 6. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by the OpenSSL Project + * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" + * + * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR + * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. + * ==================================================================== + * + * This product includes cryptographic software written by Eric Young + * (eay@cryptsoft.com). This product includes software written by Tim + * Hudson (tjh@cryptsoft.com). + * + */ #ifndef OPENSSL_HEADER_X509V3_INTERNAL_H #define OPENSSL_HEADER_X509V3_INTERNAL_H @@ -18,6 +62,8 @@ #include #include +#include +#include #if defined(__cplusplus) extern "C" { @@ -76,6 +122,165 @@ typedef struct { int x509V3_add_value_asn1_string(const char *name, const ASN1_STRING *value, STACK_OF(CONF_VALUE) **extlist); +typedef struct X509_POLICY_DATA_st X509_POLICY_DATA; + +DEFINE_STACK_OF(X509_POLICY_DATA) + +/* Internal structures */ + +/* + * This structure and the field names correspond to the Policy 'node' of + * RFC 3280. NB this structure contains no pointers to parent or child data: + * X509_POLICY_NODE contains that. This means that the main policy data can + * be kept static and cached with the certificate. + */ + +struct X509_POLICY_DATA_st { + unsigned int flags; + /* Policy OID and qualifiers for this data */ + ASN1_OBJECT *valid_policy; + STACK_OF(POLICYQUALINFO) *qualifier_set; + STACK_OF(ASN1_OBJECT) *expected_policy_set; +}; + +/* X509_POLICY_DATA flags values */ + +/* + * This flag indicates the structure has been mapped using a policy mapping + * extension. If policy mapping is not active its references get deleted. + */ + +#define POLICY_DATA_FLAG_MAPPED 0x1 + +/* + * This flag indicates the data doesn't correspond to a policy in Certificate + * Policies: it has been mapped to any policy. + */ + +#define POLICY_DATA_FLAG_MAPPED_ANY 0x2 + +/* AND with flags to see if any mapping has occurred */ + +#define POLICY_DATA_FLAG_MAP_MASK 0x3 + +/* qualifiers are shared and shouldn't be freed */ + +#define POLICY_DATA_FLAG_SHARED_QUALIFIERS 0x4 + +/* Parent node is an extra node and should be freed */ + +#define POLICY_DATA_FLAG_EXTRA_NODE 0x8 + +/* Corresponding CertificatePolicies is critical */ + +#define POLICY_DATA_FLAG_CRITICAL 0x10 + +/* This structure is cached with a certificate */ + +struct X509_POLICY_CACHE_st { + /* anyPolicy data or NULL if no anyPolicy */ + X509_POLICY_DATA *anyPolicy; + /* other policy data */ + STACK_OF(X509_POLICY_DATA) *data; + /* If InhibitAnyPolicy present this is its value or -1 if absent. */ + long any_skip; + /* + * If policyConstraints and requireExplicitPolicy present this is its + * value or -1 if absent. + */ + long explicit_skip; + /* + * If policyConstraints and policyMapping present this is its value or -1 + * if absent. + */ + long map_skip; +}; + +/* + * #define POLICY_CACHE_FLAG_CRITICAL POLICY_DATA_FLAG_CRITICAL + */ + +/* This structure represents the relationship between nodes */ + +struct X509_POLICY_NODE_st { + /* node data this refers to */ + const X509_POLICY_DATA *data; + /* Parent node */ + X509_POLICY_NODE *parent; + /* Number of child nodes */ + int nchild; +}; + +struct X509_POLICY_LEVEL_st { + /* Cert for this level */ + X509 *cert; + /* nodes at this level */ + STACK_OF(X509_POLICY_NODE) *nodes; + /* anyPolicy node */ + X509_POLICY_NODE *anyPolicy; + /* Extra data */ + /* + * STACK_OF(X509_POLICY_DATA) *extra_data; + */ + unsigned int flags; +}; + +struct X509_POLICY_TREE_st { + /* This is the tree 'level' data */ + X509_POLICY_LEVEL *levels; + int nlevel; + /* + * Extra policy data when additional nodes (not from the certificate) are + * required. + */ + STACK_OF(X509_POLICY_DATA) *extra_data; + /* This is the authority constained policy set */ + STACK_OF(X509_POLICY_NODE) *auth_policies; + STACK_OF(X509_POLICY_NODE) *user_policies; + unsigned int flags; +}; + +/* Set if anyPolicy present in user policies */ +#define POLICY_FLAG_ANY_POLICY 0x2 + +/* Useful macros */ + +#define node_data_critical(data) ((data)->flags & POLICY_DATA_FLAG_CRITICAL) +#define node_critical(node) node_data_critical((node)->data) + +/* Internal functions */ + +X509_POLICY_DATA *policy_data_new(POLICYINFO *policy, const ASN1_OBJECT *id, + int crit); +void policy_data_free(X509_POLICY_DATA *data); + +X509_POLICY_DATA *policy_cache_find_data(const X509_POLICY_CACHE *cache, + const ASN1_OBJECT *id); +int policy_cache_set_mapping(X509 *x, POLICY_MAPPINGS *maps); + +STACK_OF(X509_POLICY_NODE) *policy_node_cmp_new(void); + +void policy_cache_init(void); + +void policy_cache_free(X509_POLICY_CACHE *cache); + +X509_POLICY_NODE *level_find_node(const X509_POLICY_LEVEL *level, + const X509_POLICY_NODE *parent, + const ASN1_OBJECT *id); + +X509_POLICY_NODE *tree_find_sk(STACK_OF(X509_POLICY_NODE) *sk, + const ASN1_OBJECT *id); + +X509_POLICY_NODE *level_add_node(X509_POLICY_LEVEL *level, + X509_POLICY_DATA *data, + X509_POLICY_NODE *parent, + X509_POLICY_TREE *tree); +void policy_node_free(X509_POLICY_NODE *node); +int policy_node_match(const X509_POLICY_LEVEL *lvl, + const X509_POLICY_NODE *node, const ASN1_OBJECT *oid); + +const X509_POLICY_CACHE *policy_cache_set(X509 *x); + #if defined(__cplusplus) } /* extern C */ diff --git a/Sources/CCryptoBoringSSL/crypto/x509v3/pcy_cache.c b/Sources/CCryptoBoringSSL/crypto/x509v3/pcy_cache.c index f400ee77..f00fd765 100644 --- a/Sources/CCryptoBoringSSL/crypto/x509v3/pcy_cache.c +++ b/Sources/CCryptoBoringSSL/crypto/x509v3/pcy_cache.c @@ -60,9 +60,9 @@ #include #include -#include "pcy_int.h" #include "../internal.h" #include "../x509/internal.h" +#include "internal.h" static int policy_data_cmp(const X509_POLICY_DATA **a, const X509_POLICY_DATA **b); diff --git a/Sources/CCryptoBoringSSL/crypto/x509v3/pcy_data.c b/Sources/CCryptoBoringSSL/crypto/x509v3/pcy_data.c index 41ac6116..647619f2 100644 --- a/Sources/CCryptoBoringSSL/crypto/x509v3/pcy_data.c +++ b/Sources/CCryptoBoringSSL/crypto/x509v3/pcy_data.c @@ -62,7 +62,7 @@ #include #include -#include "pcy_int.h" +#include "internal.h" /* Policy Node routines */ diff --git a/Sources/CCryptoBoringSSL/crypto/x509v3/pcy_int.h b/Sources/CCryptoBoringSSL/crypto/x509v3/pcy_int.h deleted file mode 100644 index aee71d6f..00000000 --- a/Sources/CCryptoBoringSSL/crypto/x509v3/pcy_int.h +++ /dev/null @@ -1,217 +0,0 @@ -/* pcy_int.h */ -/* - * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project - * 2004. - */ -/* ==================================================================== - * Copyright (c) 2004 The OpenSSL Project. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * 3. All advertising materials mentioning features or use of this - * software must display the following acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" - * - * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to - * endorse or promote products derived from this software without - * prior written permission. For written permission, please contact - * licensing@OpenSSL.org. - * - * 5. Products derived from this software may not be called "OpenSSL" - * nor may "OpenSSL" appear in their names without prior written - * permission of the OpenSSL Project. - * - * 6. Redistributions of any form whatsoever must retain the following - * acknowledgment: - * "This product includes software developed by the OpenSSL Project - * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" - * - * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY - * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR - * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * ==================================================================== - * - * This product includes cryptographic software written by Eric Young - * (eay@cryptsoft.com). This product includes software written by Tim - * Hudson (tjh@cryptsoft.com). - * - */ - -typedef struct X509_POLICY_DATA_st X509_POLICY_DATA; - -DEFINE_STACK_OF(X509_POLICY_DATA) - -/* Internal structures */ - -/* - * This structure and the field names correspond to the Policy 'node' of - * RFC 3280. NB this structure contains no pointers to parent or child data: - * X509_POLICY_NODE contains that. This means that the main policy data can - * be kept static and cached with the certificate. - */ - -struct X509_POLICY_DATA_st { - unsigned int flags; - /* Policy OID and qualifiers for this data */ - ASN1_OBJECT *valid_policy; - STACK_OF(POLICYQUALINFO) *qualifier_set; - STACK_OF(ASN1_OBJECT) *expected_policy_set; -}; - -/* X509_POLICY_DATA flags values */ - -/* - * This flag indicates the structure has been mapped using a policy mapping - * extension. If policy mapping is not active its references get deleted. - */ - -#define POLICY_DATA_FLAG_MAPPED 0x1 - -/* - * This flag indicates the data doesn't correspond to a policy in Certificate - * Policies: it has been mapped to any policy. - */ - -#define POLICY_DATA_FLAG_MAPPED_ANY 0x2 - -/* AND with flags to see if any mapping has occurred */ - -#define POLICY_DATA_FLAG_MAP_MASK 0x3 - -/* qualifiers are shared and shouldn't be freed */ - -#define POLICY_DATA_FLAG_SHARED_QUALIFIERS 0x4 - -/* Parent node is an extra node and should be freed */ - -#define POLICY_DATA_FLAG_EXTRA_NODE 0x8 - -/* Corresponding CertificatePolicies is critical */ - -#define POLICY_DATA_FLAG_CRITICAL 0x10 - -/* This structure is cached with a certificate */ - -struct X509_POLICY_CACHE_st { - /* anyPolicy data or NULL if no anyPolicy */ - X509_POLICY_DATA *anyPolicy; - /* other policy data */ - STACK_OF(X509_POLICY_DATA) *data; - /* If InhibitAnyPolicy present this is its value or -1 if absent. */ - long any_skip; - /* - * If policyConstraints and requireExplicitPolicy present this is its - * value or -1 if absent. - */ - long explicit_skip; - /* - * If policyConstraints and policyMapping present this is its value or -1 - * if absent. - */ - long map_skip; -}; - -/* - * #define POLICY_CACHE_FLAG_CRITICAL POLICY_DATA_FLAG_CRITICAL - */ - -/* This structure represents the relationship between nodes */ - -struct X509_POLICY_NODE_st { - /* node data this refers to */ - const X509_POLICY_DATA *data; - /* Parent node */ - X509_POLICY_NODE *parent; - /* Number of child nodes */ - int nchild; -}; - -struct X509_POLICY_LEVEL_st { - /* Cert for this level */ - X509 *cert; - /* nodes at this level */ - STACK_OF(X509_POLICY_NODE) *nodes; - /* anyPolicy node */ - X509_POLICY_NODE *anyPolicy; - /* Extra data */ - /* - * STACK_OF(X509_POLICY_DATA) *extra_data; - */ - unsigned int flags; -}; - -struct X509_POLICY_TREE_st { - /* This is the tree 'level' data */ - X509_POLICY_LEVEL *levels; - int nlevel; - /* - * Extra policy data when additional nodes (not from the certificate) are - * required. - */ - STACK_OF(X509_POLICY_DATA) *extra_data; - /* This is the authority constained policy set */ - STACK_OF(X509_POLICY_NODE) *auth_policies; - STACK_OF(X509_POLICY_NODE) *user_policies; - unsigned int flags; -}; - -/* Set if anyPolicy present in user policies */ -#define POLICY_FLAG_ANY_POLICY 0x2 - -/* Useful macros */ - -#define node_data_critical(data) ((data)->flags & POLICY_DATA_FLAG_CRITICAL) -#define node_critical(node) node_data_critical((node)->data) - -/* Internal functions */ - -X509_POLICY_DATA *policy_data_new(POLICYINFO *policy, const ASN1_OBJECT *id, - int crit); -void policy_data_free(X509_POLICY_DATA *data); - -X509_POLICY_DATA *policy_cache_find_data(const X509_POLICY_CACHE *cache, - const ASN1_OBJECT *id); -int policy_cache_set_mapping(X509 *x, POLICY_MAPPINGS *maps); - -STACK_OF(X509_POLICY_NODE) *policy_node_cmp_new(void); - -void policy_cache_init(void); - -void policy_cache_free(X509_POLICY_CACHE *cache); - -X509_POLICY_NODE *level_find_node(const X509_POLICY_LEVEL *level, - const X509_POLICY_NODE *parent, - const ASN1_OBJECT *id); - -X509_POLICY_NODE *tree_find_sk(STACK_OF(X509_POLICY_NODE) *sk, - const ASN1_OBJECT *id); - -X509_POLICY_NODE *level_add_node(X509_POLICY_LEVEL *level, - X509_POLICY_DATA *data, - X509_POLICY_NODE *parent, - X509_POLICY_TREE *tree); -void policy_node_free(X509_POLICY_NODE *node); -int policy_node_match(const X509_POLICY_LEVEL *lvl, - const X509_POLICY_NODE *node, const ASN1_OBJECT *oid); - -const X509_POLICY_CACHE *policy_cache_set(X509 *x); diff --git a/Sources/CCryptoBoringSSL/crypto/x509v3/pcy_lib.c b/Sources/CCryptoBoringSSL/crypto/x509v3/pcy_lib.c index 2262f702..cda8e891 100644 --- a/Sources/CCryptoBoringSSL/crypto/x509v3/pcy_lib.c +++ b/Sources/CCryptoBoringSSL/crypto/x509v3/pcy_lib.c @@ -58,7 +58,7 @@ #include #include -#include "pcy_int.h" +#include "internal.h" /* accessor functions */ diff --git a/Sources/CCryptoBoringSSL/crypto/x509v3/pcy_map.c b/Sources/CCryptoBoringSSL/crypto/x509v3/pcy_map.c index b37d124a..758e6c9d 100644 --- a/Sources/CCryptoBoringSSL/crypto/x509v3/pcy_map.c +++ b/Sources/CCryptoBoringSSL/crypto/x509v3/pcy_map.c @@ -61,8 +61,8 @@ #include #include -#include "pcy_int.h" #include "../x509/internal.h" +#include "internal.h" /* * Set policy mapping entries in cache. Note: this modifies the passed diff --git a/Sources/CCryptoBoringSSL/crypto/x509v3/pcy_node.c b/Sources/CCryptoBoringSSL/crypto/x509v3/pcy_node.c index a1d7a729..a6b6d076 100644 --- a/Sources/CCryptoBoringSSL/crypto/x509v3/pcy_node.c +++ b/Sources/CCryptoBoringSSL/crypto/x509v3/pcy_node.c @@ -61,7 +61,7 @@ #include #include -#include "pcy_int.h" +#include "internal.h" static int node_cmp(const X509_POLICY_NODE **a, const X509_POLICY_NODE **b) { diff --git a/Sources/CCryptoBoringSSL/crypto/x509v3/pcy_tree.c b/Sources/CCryptoBoringSSL/crypto/x509v3/pcy_tree.c index ebf5bd4f..f7d4ffae 100644 --- a/Sources/CCryptoBoringSSL/crypto/x509v3/pcy_tree.c +++ b/Sources/CCryptoBoringSSL/crypto/x509v3/pcy_tree.c @@ -65,9 +65,9 @@ #include #include -#include "pcy_int.h" #include "../internal.h" #include "../x509/internal.h" +#include "internal.h" /* * Enable this to print out the complete policy tree at various point during diff --git a/Sources/CCryptoBoringSSL/crypto/x509v3/v3_alt.c b/Sources/CCryptoBoringSSL/crypto/x509v3/v3_alt.c index 28d8ed53..738a6669 100644 --- a/Sources/CCryptoBoringSSL/crypto/x509v3/v3_alt.c +++ b/Sources/CCryptoBoringSSL/crypto/x509v3/v3_alt.c @@ -64,6 +64,7 @@ #include #include +#include "../x509/internal.h" #include "internal.h" diff --git a/Sources/CCryptoBoringSSL/crypto/x509v3/v3_cpols.c b/Sources/CCryptoBoringSSL/crypto/x509v3/v3_cpols.c index 3de17125..1a6a1345 100644 --- a/Sources/CCryptoBoringSSL/crypto/x509v3/v3_cpols.c +++ b/Sources/CCryptoBoringSSL/crypto/x509v3/v3_cpols.c @@ -70,7 +70,6 @@ #include #include "internal.h" -#include "pcy_int.h" /* Certificate policies extension support: this one is a bit complex... */ diff --git a/Sources/CCryptoBoringSSL/crypto/x509v3/v3_lib.c b/Sources/CCryptoBoringSSL/crypto/x509v3/v3_lib.c index db0b849e..9818740b 100644 --- a/Sources/CCryptoBoringSSL/crypto/x509v3/v3_lib.c +++ b/Sources/CCryptoBoringSSL/crypto/x509v3/v3_lib.c @@ -213,10 +213,27 @@ void *X509V3_EXT_d2i(const X509_EXTENSION *ext) if (!(method = X509V3_EXT_get(ext))) return NULL; p = ext->value->data; - if (method->it) - return ASN1_item_d2i(NULL, &p, ext->value->length, - ASN1_ITEM_ptr(method->it)); - return method->d2i(NULL, &p, ext->value->length); + void *ret; + if (method->it) { + ret = ASN1_item_d2i(NULL, &p, ext->value->length, + ASN1_ITEM_ptr(method->it)); + } else { + ret = method->d2i(NULL, &p, ext->value->length); + } + if (ret == NULL) { + return NULL; + } + /* Check for trailing data. */ + if (p != ext->value->data + ext->value->length) { + if (method->it) { + ASN1_item_free(ret, ASN1_ITEM_ptr(method->it)); + } else { + method->ext_free(ret); + } + OPENSSL_PUT_ERROR(X509V3, X509V3_R_TRAILING_DATA_IN_EXTENSION); + return NULL; + } + return ret; } void *X509V3_get_d2i(const STACK_OF(X509_EXTENSION) *extensions, int nid, diff --git a/Sources/CCryptoBoringSSL/crypto/x509v3/v3_purp.c b/Sources/CCryptoBoringSSL/crypto/x509v3/v3_purp.c index c10d525d..c100f58c 100644 --- a/Sources/CCryptoBoringSSL/crypto/x509v3/v3_purp.c +++ b/Sources/CCryptoBoringSSL/crypto/x509v3/v3_purp.c @@ -64,7 +64,6 @@ #include #include #include -#include #include #include "../internal.h" diff --git a/Sources/CCryptoBoringSSL/hash.txt b/Sources/CCryptoBoringSSL/hash.txt index 9575d13a..0a6620cb 100644 --- a/Sources/CCryptoBoringSSL/hash.txt +++ b/Sources/CCryptoBoringSSL/hash.txt @@ -1 +1 @@ -This directory is derived from BoringSSL cloned from https://boringssl.googlesource.com/boringssl at revision 25773430c07075a368416c3646fa4b07daf4968a +This directory is derived from BoringSSL cloned from https://boringssl.googlesource.com/boringssl at revision a9670a8b476470e6f874fef3554e8059683e1413 diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_asn1.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_asn1.h index 2101eba4..8e595071 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_asn1.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_asn1.h @@ -63,11 +63,10 @@ #include #include "CCryptoBoringSSL_bio.h" +#include "CCryptoBoringSSL_bn.h" #include "CCryptoBoringSSL_stack.h" -#include "CCryptoBoringSSL_bn.h" - -#ifdef __cplusplus +#if defined(__cplusplus) extern "C" { #endif @@ -75,8 +74,12 @@ extern "C" { // Legacy ASN.1 library. // // This header is part of OpenSSL's ASN.1 implementation. It is retained for -// compatibility but otherwise underdocumented and not actively maintained. Use -// the new |CBS| and |CBB| library in instead. +// compatibility but should not be used by new code. The functions are difficult +// to use correctly, and have buggy or non-standard behaviors. They are thus +// particularly prone to behavior changes and API removals, as BoringSSL +// iterates on these issues. +// +// Use the new |CBS| and |CBB| library in instead. // Tag constants. @@ -174,11 +177,307 @@ extern "C" { #define B_ASN1_GENERALIZEDTIME 0x8000 #define B_ASN1_SEQUENCE 0x10000 +// ASN1_tag2bit converts |tag| from the tag number of a universal type to a +// corresponding |B_ASN1_*| constant, |B_ASN1_UNKNOWN|, or zero. If the +// |B_ASN1_*| constant above is defined, it will map the corresponding +// |V_ASN1_*| constant to it. Otherwise, whether it returns |B_ASN1_UNKNOWN| or +// zero is ill-defined and callers should not rely on it. +// +// TODO(https://crbug.com/boringssl/412): Figure out what |B_ASN1_UNNOWN| vs +// zero is meant to be. The main impact is what values go in |B_ASN1_PRINTABLE|. +// To that end, we must return zero on types that can't go in |ASN1_STRING|. +OPENSSL_EXPORT unsigned long ASN1_tag2bit(int tag); + // ASN1_tag2str returns a string representation of |tag|, interpret as a tag // number for a universal type, or |V_ASN1_NEG_*|. OPENSSL_EXPORT const char *ASN1_tag2str(int tag); +// API conventions. +// +// The following sample functions document the calling conventions used by +// legacy ASN.1 APIs. + +#if 0 // Sample functions + +// d2i_SAMPLE parses a structure from up to |len| bytes at |*inp|. On success, +// it advances |*inp| by the number of bytes read and returns a newly-allocated +// |SAMPLE| object containing the parsed structure. If |out| is non-NULL, it +// additionally frees the previous value at |*out| and updates |*out| to the +// result. If parsing or allocating the result fails, it returns NULL. +// +// This function does not reject trailing data in the input. This allows the +// caller to parse a sequence of concatenated structures. Callers parsing only +// one structure should check for trailing data by comparing the updated |*inp| +// with the end of the input. +// +// Note: If |out| and |*out| are both non-NULL, the object at |*out| is not +// updated in-place. Instead, it is freed, and the pointer is updated to the +// new object. This differs from OpenSSL, which behaves more like +// |d2i_SAMPLE_with_reuse|. Callers are recommended to set |out| to NULL and +// instead use the return value. +SAMPLE *d2i_SAMPLE(SAMPLE **out, const uint8_t **inp, long len); + +// d2i_SAMPLE_with_reuse parses a structure from up to |len| bytes at |*inp|. On +// success, it advances |*inp| by the number of bytes read and returns a +// non-NULL pointer to an object containing the parsed structure. The object is +// determined from |out| as follows: +// +// If |out| is NULL, the function places the result in a newly-allocated +// |SAMPLE| object and returns it. This mode is recommended. +// +// If |out| is non-NULL, but |*out| is NULL, the function also places the result +// in a newly-allocated |SAMPLE| object. It sets |*out| to this object and also +// returns it. +// +// If |out| and |*out| are both non-NULL, the function updates the object at +// |*out| in-place with the result and returns |*out|. +// +// If any of the above fail, the function returns NULL. +// +// This function does not reject trailing data in the input. This allows the +// caller to parse a sequence of concatenated structures. Callers parsing only +// one structure should check for trailing data by comparing the updated |*inp| +// with the end of the input. +// +// WARNING: Callers should not rely on the in-place update mode. It often +// produces the wrong result or breaks the type's internal invariants. Future +// revisions of BoringSSL may standardize on the |d2i_SAMPLE| behavior. +SAMPLE *d2i_SAMPLE_with_reuse(SAMPLE **out, const uint8_t **inp, long len); + +// i2d_SAMPLE marshals |in|. On error, it returns a negative value. On success, +// it returns the length of the result and outputs it via |outp| as follows: +// +// If |outp| is NULL, the function writes nothing. This mode can be used to size +// buffers. +// +// If |outp| is non-NULL but |*outp| is NULL, the function sets |*outp| to a +// newly-allocated buffer containing the result. The caller is responsible for +// releasing |*outp| with |OPENSSL_free|. This mode is recommended for most +// callers. +// +// If |outp| and |*outp| are non-NULL, the function writes the result to +// |*outp|, which must have enough space available, and advances |*outp| just +// past the output. +// +// WARNING: In the third mode, the function does not internally check output +// bounds. Failing to correctly size the buffer will result in a potentially +// exploitable memory error. +int i2d_SAMPLE(const SAMPLE *in, uint8_t **outp); + +#endif // Sample functions + +// The following typedefs are sometimes used for pointers to functions like +// |d2i_SAMPLE| and |i2d_SAMPLE|. Note, however, that these act on |void*|. +// Calling a function with a different pointer type is undefined in C, so this +// is only valid with a wrapper. +typedef void *d2i_of_void(void **, const unsigned char **, long); +typedef int i2d_of_void(const void *, unsigned char **); + + +// ASN.1 types. +// +// An |ASN1_ITEM| represents an ASN.1 type and allows working with ASN.1 types +// generically. +// +// |ASN1_ITEM|s use a different namespace from C types and are accessed via +// |ASN1_ITEM_*| macros. So, for example, |ASN1_OCTET_STRING| is both a C type +// and the name of an |ASN1_ITEM|, referenced as +// |ASN1_ITEM_rptr(ASN1_OCTET_STRING)|. +// +// Each |ASN1_ITEM| has a corresponding C type, typically with the same name, +// which represents values in the ASN.1 type. This type is either a pointer type +// or |ASN1_BOOLEAN|. When it is a pointer, NULL pointers represent omitted +// values. For example, an OCTET STRING value is declared with the C type +// |ASN1_OCTET_STRING*| and uses the |ASN1_ITEM| named |ASN1_OCTET_STRING|. An +// OPTIONAL OCTET STRING uses the same C type and represents an omitted value +// with a NULL pointer. |ASN1_BOOLEAN| is described in a later section. + +// DECLARE_ASN1_ITEM declares an |ASN1_ITEM| with name |name|. The |ASN1_ITEM| +// may be referenced with |ASN1_ITEM_rptr|. Uses of this macro should document +// the corresponding ASN.1 and C types. +#define DECLARE_ASN1_ITEM(name) extern OPENSSL_EXPORT const ASN1_ITEM name##_it; + +// ASN1_ITEM_rptr returns the |const ASN1_ITEM *| named |name|. +#define ASN1_ITEM_rptr(name) (&(name##_it)) + +// ASN1_ITEM_EXP is an abstraction for referencing an |ASN1_ITEM| in a +// constant-initialized structure, such as a method table. It exists because, on +// some OpenSSL platforms, |ASN1_ITEM| references are indirected through +// functions. Structures reference the |ASN1_ITEM| by declaring a field like +// |ASN1_ITEM_EXP *item| and initializing it with |ASN1_ITEM_ref|. +typedef const ASN1_ITEM ASN1_ITEM_EXP; + +// ASN1_ITEM_ref returns an |ASN1_ITEM_EXP*| for the |ASN1_ITEM| named |name|. +#define ASN1_ITEM_ref(name) (&(name##_it)) + +// ASN1_ITEM_ptr converts |iptr|, which must be an |ASN1_ITEM_EXP*| to a +// |const ASN1_ITEM*|. +#define ASN1_ITEM_ptr(iptr) (iptr) + +// ASN1_VALUE_st (aka |ASN1_VALUE|) is an opaque type used as a placeholder for +// the C type corresponding to an |ASN1_ITEM|. +typedef struct ASN1_VALUE_st ASN1_VALUE; + +// ASN1_item_new allocates a new value of the C type corresponding to |it|, or +// NULL on error. On success, the caller must release the value with +// |ASN1_item_free|, or the corresponding C type's free function, when done. The +// new value will initialize fields of the value to some default state, such as +// an empty string. Note, however, that this default state sometimes omits +// required values, such as with CHOICE types. +// +// This function may not be used with |ASN1_ITEM|s whose C type is +// |ASN1_BOOLEAN|. +// +// WARNING: Casting the result of this function to the wrong type is a +// potentially exploitable memory error. Callers must ensure the value is used +// consistently with |it|. Prefer using type-specific functions such as +// |ASN1_OCTET_STRING_new|. +OPENSSL_EXPORT ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it); + +// ASN1_item_free releases memory associated with |val|, which must be an object +// of the C type corresponding to |it|. +// +// This function may not be used with |ASN1_ITEM|s whose C type is +// |ASN1_BOOLEAN|. +// +// WARNING: Passing a pointer of the wrong type into this function is a +// potentially exploitable memory error. Callers must ensure |val| is consistent +// with |it|. Prefer using type-specific functions such as +// |ASN1_OCTET_STRING_free|. +OPENSSL_EXPORT void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it); + +// ASN1_item_d2i parses the ASN.1 type |it| from up to |len| bytes at |*inp|. +// It behaves like |d2i_SAMPLE_with_reuse|, except that |out| and the return +// value are cast to |ASN1_VALUE| pointers. +// +// TODO(https://crbug.com/boringssl/444): C strict aliasing forbids type-punning +// |T*| and |ASN1_VALUE*| the way this function signature does. When that bug is +// resolved, we will need to pick which type |*out| is (probably |T*|). Do not +// use a non-NULL |out| to avoid ending up on the wrong side of this question. +// +// This function may not be used with |ASN1_ITEM|s whose C type is +// |ASN1_BOOLEAN|. +// +// WARNING: Casting the result of this function to the wrong type, or passing a +// pointer of the wrong type into this function, are potentially exploitable +// memory errors. Callers must ensure |out| is consistent with |it|. Prefer +// using type-specific functions such as |d2i_ASN1_OCTET_STRING|. +OPENSSL_EXPORT ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **out, + const unsigned char **inp, long len, + const ASN1_ITEM *it); + +// ASN1_item_i2d marshals |val| as the ASN.1 type associated with |it|, as +// described in |i2d_SAMPLE|. +// +// This function may not be used with |ASN1_ITEM|s whose C type is +// |ASN1_BOOLEAN|. +// +// WARNING: Passing a pointer of the wrong type into this function is a +// potentially exploitable memory error. Callers must ensure |val| is consistent +// with |it|. Prefer using type-specific functions such as +// |i2d_ASN1_OCTET_STRING|. +OPENSSL_EXPORT int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **outp, + const ASN1_ITEM *it); + +// ASN1_item_dup returns a newly-allocated copy of |x|, or NULL on error. |x| +// must be an object of |it|'s C type. +// +// This function may not be used with |ASN1_ITEM|s whose C type is +// |ASN1_BOOLEAN|. +// +// WARNING: Casting the result of this function to the wrong type, or passing a +// pointer of the wrong type into this function, are potentially exploitable +// memory errors. Prefer using type-specific functions such as +// |ASN1_STRING_dup|. +OPENSSL_EXPORT void *ASN1_item_dup(const ASN1_ITEM *it, void *x); + +// The following functions behave like |ASN1_item_d2i| but read from |in| +// instead. |out| is the same parameter as in |ASN1_item_d2i|, but written with +// |void*| instead. The return values similarly match. +// +// These functions may not be used with |ASN1_ITEM|s whose C type is +// |ASN1_BOOLEAN|. +// +// WARNING: These functions do not bound how much data is read from |in|. +// Parsing an untrusted input could consume unbounded memory. +OPENSSL_EXPORT void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *out); +OPENSSL_EXPORT void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *out); + +// The following functions behave like |ASN1_item_i2d| but write to |out| +// instead. |in| is the same parameter as in |ASN1_item_i2d|, but written with +// |void*| instead. +// +// These functions may not be used with |ASN1_ITEM|s whose C type is +// |ASN1_BOOLEAN|. +OPENSSL_EXPORT int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *in); +OPENSSL_EXPORT int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *in); + +// ASN1_item_unpack parses |oct|'s contents as |it|'s ASN.1 type. It returns a +// newly-allocated instance of |it|'s C type on success, or NULL on error. +// +// This function may not be used with |ASN1_ITEM|s whose C type is +// |ASN1_BOOLEAN|. +// +// WARNING: Casting the result of this function to the wrong type is a +// potentially exploitable memory error. Callers must ensure the value is used +// consistently with |it|. +OPENSSL_EXPORT void *ASN1_item_unpack(const ASN1_STRING *oct, + const ASN1_ITEM *it); + +// ASN1_item_pack marshals |obj| as |it|'s ASN.1 type. If |out| is NULL, it +// returns a newly-allocated |ASN1_STRING| with the result, or NULL on error. +// If |out| is non-NULL, but |*out| is NULL, it does the same but additionally +// sets |*out| to the result. If both |out| and |*out| are non-NULL, it writes +// the result to |*out| and returns |*out| on success or NULL on error. +// +// This function may not be used with |ASN1_ITEM|s whose C type is +// |ASN1_BOOLEAN|. +// +// WARNING: Passing a pointer of the wrong type into this function is a +// potentially exploitable memory error. Callers must ensure |val| is consistent +// with |it|. +OPENSSL_EXPORT ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, + ASN1_STRING **out); + + +// Booleans. +// +// This library represents ASN.1 BOOLEAN values with |ASN1_BOOLEAN|, which is an +// integer type. FALSE is zero, TRUE is 0xff, and an omitted OPTIONAL BOOLEAN is +// -1. + +// d2i_ASN1_BOOLEAN parses a DER-encoded ASN.1 BOOLEAN from up to |len| bytes at +// |*inp|. On success, it advances |*inp| by the number of bytes read and +// returns the result. If |out| is non-NULL, it additionally writes the result +// to |*out|. On error, it returns -1. +// +// This function does not reject trailing data in the input. This allows the +// caller to parse a sequence of concatenated structures. Callers parsing only +// one structure should check for trailing data by comparing the updated |*inp| +// with the end of the input. +// +// WARNING: This function's is slightly different from other |d2i_*| functions +// because |ASN1_BOOLEAN| is not a pointer type. +// +// TODO(https://crbug.com/boringssl/354): This function currently also accepts +// BER, but this will be removed in the future. +OPENSSL_EXPORT ASN1_BOOLEAN d2i_ASN1_BOOLEAN(ASN1_BOOLEAN *out, + const unsigned char **inp, + long len); + +// i2d_ASN1_BOOLEAN marshals |a| as a DER-encoded ASN.1 BOOLEAN, as described in +// |i2d_SAMPLE|. +OPENSSL_EXPORT int i2d_ASN1_BOOLEAN(ASN1_BOOLEAN a, unsigned char **outp); + +// The following |ASN1_ITEM|s have ASN.1 type BOOLEAN and C type |ASN1_BOOLEAN|. +// |ASN1_TBOOLEAN| and |ASN1_FBOOLEAN| must be marked OPTIONAL. When omitted, +// they are parsed as TRUE and FALSE, respectively, rather than -1. +DECLARE_ASN1_ITEM(ASN1_BOOLEAN) +DECLARE_ASN1_ITEM(ASN1_TBOOLEAN) +DECLARE_ASN1_ITEM(ASN1_FBOOLEAN) + + // Strings. // // ASN.1 contains a myriad of string types, as well as types that contain data @@ -237,9 +536,10 @@ OPENSSL_EXPORT const char *ASN1_tag2str(int tag); // invariants on the |X509| object and break the |X509_get0_serialNumber| // invariant. // -// TODO(davidben): This is very unfriendly. Getting the type field wrong should -// not cause memory errors, but it may do strange things. We should add runtime -// checks to anything that consumes |ASN1_STRING|s from the caller. +// TODO(https://crbug.com/boringssl/445): This is very unfriendly. Getting the +// type field wrong should not cause memory errors, but it may do strange +// things. We should add runtime checks to anything that consumes |ASN1_STRING|s +// from the caller. struct asn1_string_st { int length; int type; @@ -300,12 +600,8 @@ OPENSSL_EXPORT int ASN1_STRING_length(const ASN1_STRING *str); // suitable for sorting, callers should not rely on the exact order when |a| // and |b| are different types. // -// If |a| or |b| are BIT STRINGs, this function does not compare the -// |ASN1_STRING_FLAG_BITS_LEFT| flags. Additionally, if |a| and |b| are -// INTEGERs, this comparison does not order the values numerically. For a -// numerical comparison, use |ASN1_INTEGER_cmp|. -// -// TODO(davidben): The BIT STRING comparison seems like a bug. Fix it? +// Note that, if |a| and |b| are INTEGERs, this comparison does not order the +// values numerically. For a numerical comparison, use |ASN1_INTEGER_cmp|. OPENSSL_EXPORT int ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b); // ASN1_STRING_set sets the contents of |str| to a copy of |len| bytes from @@ -317,6 +613,102 @@ OPENSSL_EXPORT int ASN1_STRING_set(ASN1_STRING *str, const void *data, int len); // |OPENSSL_malloc|. OPENSSL_EXPORT void ASN1_STRING_set0(ASN1_STRING *str, void *data, int len); +// The following functions call |ASN1_STRING_type_new| with the corresponding +// |V_ASN1_*| constant. +OPENSSL_EXPORT ASN1_BMPSTRING *ASN1_BMPSTRING_new(void); +OPENSSL_EXPORT ASN1_GENERALSTRING *ASN1_GENERALSTRING_new(void); +OPENSSL_EXPORT ASN1_IA5STRING *ASN1_IA5STRING_new(void); +OPENSSL_EXPORT ASN1_OCTET_STRING *ASN1_OCTET_STRING_new(void); +OPENSSL_EXPORT ASN1_PRINTABLESTRING *ASN1_PRINTABLESTRING_new(void); +OPENSSL_EXPORT ASN1_T61STRING *ASN1_T61STRING_new(void); +OPENSSL_EXPORT ASN1_UNIVERSALSTRING *ASN1_UNIVERSALSTRING_new(void); +OPENSSL_EXPORT ASN1_UTF8STRING *ASN1_UTF8STRING_new(void); +OPENSSL_EXPORT ASN1_VISIBLESTRING *ASN1_VISIBLESTRING_new(void); + +// The following functions call |ASN1_STRING_free|. +OPENSSL_EXPORT void ASN1_BMPSTRING_free(ASN1_BMPSTRING *str); +OPENSSL_EXPORT void ASN1_GENERALSTRING_free(ASN1_GENERALSTRING *str); +OPENSSL_EXPORT void ASN1_IA5STRING_free(ASN1_IA5STRING *str); +OPENSSL_EXPORT void ASN1_OCTET_STRING_free(ASN1_OCTET_STRING *str); +OPENSSL_EXPORT void ASN1_PRINTABLESTRING_free(ASN1_PRINTABLESTRING *str); +OPENSSL_EXPORT void ASN1_T61STRING_free(ASN1_T61STRING *str); +OPENSSL_EXPORT void ASN1_UNIVERSALSTRING_free(ASN1_UNIVERSALSTRING *str); +OPENSSL_EXPORT void ASN1_UTF8STRING_free(ASN1_UTF8STRING *str); +OPENSSL_EXPORT void ASN1_VISIBLESTRING_free(ASN1_VISIBLESTRING *str); + +// The following functions parse up to |len| bytes from |*inp| as a +// DER-encoded ASN.1 value of the corresponding type, as described in +// |d2i_SAMPLE_with_reuse|. +// +// TODO(https://crbug.com/boringssl/354): This function currently also accepts +// BER, but this will be removed in the future. +OPENSSL_EXPORT ASN1_BMPSTRING *d2i_ASN1_BMPSTRING(ASN1_BMPSTRING **out, + const uint8_t **inp, + long len); +OPENSSL_EXPORT ASN1_GENERALSTRING *d2i_ASN1_GENERALSTRING( + ASN1_GENERALSTRING **out, const uint8_t **inp, long len); +OPENSSL_EXPORT ASN1_IA5STRING *d2i_ASN1_IA5STRING(ASN1_IA5STRING **out, + const uint8_t **inp, + long len); +OPENSSL_EXPORT ASN1_OCTET_STRING *d2i_ASN1_OCTET_STRING(ASN1_OCTET_STRING **out, + const uint8_t **inp, + long len); +OPENSSL_EXPORT ASN1_PRINTABLESTRING *d2i_ASN1_PRINTABLESTRING( + ASN1_PRINTABLESTRING **out, const uint8_t **inp, long len); +OPENSSL_EXPORT ASN1_T61STRING *d2i_ASN1_T61STRING(ASN1_T61STRING **out, + const uint8_t **inp, + long len); +OPENSSL_EXPORT ASN1_UNIVERSALSTRING *d2i_ASN1_UNIVERSALSTRING( + ASN1_UNIVERSALSTRING **out, const uint8_t **inp, long len); +OPENSSL_EXPORT ASN1_UTF8STRING *d2i_ASN1_UTF8STRING(ASN1_UTF8STRING **out, + const uint8_t **inp, + long len); +OPENSSL_EXPORT ASN1_VISIBLESTRING *d2i_ASN1_VISIBLESTRING( + ASN1_VISIBLESTRING **out, const uint8_t **inp, long len); + +// The following functions marshal |in| as a DER-encoded ASN.1 value of the +// corresponding type, as described in |i2d_SAMPLE|. +OPENSSL_EXPORT int i2d_ASN1_BMPSTRING(const ASN1_BMPSTRING *in, uint8_t **outp); +OPENSSL_EXPORT int i2d_ASN1_GENERALSTRING(const ASN1_GENERALSTRING *in, + uint8_t **outp); +OPENSSL_EXPORT int i2d_ASN1_IA5STRING(const ASN1_IA5STRING *in, uint8_t **outp); +OPENSSL_EXPORT int i2d_ASN1_OCTET_STRING(const ASN1_OCTET_STRING *in, + uint8_t **outp); +OPENSSL_EXPORT int i2d_ASN1_PRINTABLESTRING(const ASN1_PRINTABLESTRING *in, + uint8_t **outp); +OPENSSL_EXPORT int i2d_ASN1_T61STRING(const ASN1_T61STRING *in, uint8_t **outp); +OPENSSL_EXPORT int i2d_ASN1_UNIVERSALSTRING(const ASN1_UNIVERSALSTRING *in, + uint8_t **outp); +OPENSSL_EXPORT int i2d_ASN1_UTF8STRING(const ASN1_UTF8STRING *in, + uint8_t **outp); +OPENSSL_EXPORT int i2d_ASN1_VISIBLESTRING(const ASN1_VISIBLESTRING *in, + uint8_t **outp); + +// The following |ASN1_ITEM|s have the ASN.1 type referred to in their name and +// C type |ASN1_STRING*|. The C type may also be written as the corresponding +// typedef. +DECLARE_ASN1_ITEM(ASN1_BMPSTRING) +DECLARE_ASN1_ITEM(ASN1_GENERALSTRING) +DECLARE_ASN1_ITEM(ASN1_IA5STRING) +DECLARE_ASN1_ITEM(ASN1_OCTET_STRING) +DECLARE_ASN1_ITEM(ASN1_PRINTABLESTRING) +DECLARE_ASN1_ITEM(ASN1_T61STRING) +DECLARE_ASN1_ITEM(ASN1_UNIVERSALSTRING) +DECLARE_ASN1_ITEM(ASN1_UTF8STRING) +DECLARE_ASN1_ITEM(ASN1_VISIBLESTRING) + +// ASN1_OCTET_STRING_dup calls |ASN1_STRING_dup|. +OPENSSL_EXPORT ASN1_OCTET_STRING *ASN1_OCTET_STRING_dup( + const ASN1_OCTET_STRING *a); + +// ASN1_OCTET_STRING_cmp calls |ASN1_STRING_cmp|. +OPENSSL_EXPORT int ASN1_OCTET_STRING_cmp(const ASN1_OCTET_STRING *a, + const ASN1_OCTET_STRING *b); + +// ASN1_OCTET_STRING_set calls |ASN1_STRING_set|. +OPENSSL_EXPORT int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *str, + const unsigned char *data, int len); + // ASN1_STRING_to_UTF8 converts |in| to UTF-8. On success, sets |*out| to a // newly-allocated buffer containing the resulting string and returns the length // of the string. The caller must call |OPENSSL_free| to release |*out| when @@ -325,10 +717,9 @@ OPENSSL_EXPORT int ASN1_STRING_to_UTF8(unsigned char **out, const ASN1_STRING *in); // The following formats define encodings for use with functions like -// |ASN1_mbstring_copy|. +// |ASN1_mbstring_copy|. Note |MBSTRING_ASC| refers to Latin-1, not ASCII. #define MBSTRING_FLAG 0x1000 #define MBSTRING_UTF8 (MBSTRING_FLAG) -// |MBSTRING_ASC| refers to Latin-1, not ASCII. #define MBSTRING_ASC (MBSTRING_FLAG | 1) #define MBSTRING_BMP (MBSTRING_FLAG | 2) #define MBSTRING_UNIV (MBSTRING_FLAG | 4) @@ -370,7 +761,125 @@ OPENSSL_EXPORT int ASN1_mbstring_ncopy(ASN1_STRING **out, const uint8_t *in, int len, int inform, unsigned long mask, long minsize, long maxsize); -// TODO(davidben): Expand and document function prototypes generated in macros. +// ASN1_STRING_set_by_NID behaves like |ASN1_mbstring_ncopy|, but determines +// |mask|, |minsize|, and |maxsize| based on |nid|. When |nid| is a recognized +// X.509 attribute type, it will pick a suitable ASN.1 string type and bounds. +// For most attribute types, it preferentially chooses UTF8String. If |nid| is +// unrecognized, it uses UTF8String by default. +// +// Slightly unlike |ASN1_mbstring_ncopy|, this function interprets |out| and +// returns its result as follows: If |out| is NULL, it returns a newly-allocated +// |ASN1_STRING| containing the result. If |out| is non-NULL and +// |*out| is NULL, it additionally sets |*out| to the result. If both |out| and +// |*out| are non-NULL, it instead updates the object at |*out| and returns +// |*out|. In all cases, it returns NULL on error. +// +// This function supports the following NIDs: |NID_countryName|, +// |NID_dnQualifier|, |NID_domainComponent|, |NID_friendlyName|, +// |NID_givenName|, |NID_initials|, |NID_localityName|, |NID_ms_csp_name|, +// |NID_name|, |NID_organizationalUnitName|, |NID_organizationName|, +// |NID_pkcs9_challengePassword|, |NID_pkcs9_emailAddress|, +// |NID_pkcs9_unstructuredAddress|, |NID_pkcs9_unstructuredName|, +// |NID_serialNumber|, |NID_stateOrProvinceName|, and |NID_surname|. Additional +// NIDs may be registered with |ASN1_STRING_set_by_NID|, but it is recommended +// to call |ASN1_mbstring_ncopy| directly instead. +OPENSSL_EXPORT ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out, + const unsigned char *in, + int len, int inform, + int nid); + +// STABLE_NO_MASK causes |ASN1_STRING_TABLE_add| to allow types other than +// UTF8String. +#define STABLE_NO_MASK 0x02 + +// ASN1_STRING_TABLE_add registers the corresponding parameters with |nid|, for +// use with |ASN1_STRING_set_by_NID|. It returns one on success and zero on +// error. It is an error to call this function if |nid| is a built-in NID, or +// was already registered by a previous call. +// +// WARNING: This function affects global state in the library. If two libraries +// in the same address space register information for the same OID, one call +// will fail. Prefer directly passing the desired parametrs to +// |ASN1_mbstring_copy| or |ASN1_mbstring_ncopy| instead. +OPENSSL_EXPORT int ASN1_STRING_TABLE_add(int nid, long minsize, long maxsize, + unsigned long mask, + unsigned long flags); + + +// Multi-strings. +// +// A multi-string, or "MSTRING", is an |ASN1_STRING| that represents a CHOICE of +// several string or string-like types, such as X.509's DirectoryString. The +// |ASN1_STRING|'s type field determines which type is used. +// +// Multi-string types are associated with a bitmask, using the |B_ASN1_*| +// constants, which defines which types are valid. + +// B_ASN1_DIRECTORYSTRING is a bitmask of types allowed in an X.509 +// DirectoryString (RFC 5280). +#define B_ASN1_DIRECTORYSTRING \ + (B_ASN1_PRINTABLESTRING | B_ASN1_TELETEXSTRING | B_ASN1_BMPSTRING | \ + B_ASN1_UNIVERSALSTRING | B_ASN1_UTF8STRING) + +// DIRECTORYSTRING_new returns a newly-allocated |ASN1_STRING| with type -1, or +// NULL on error. The resulting |ASN1_STRING| is not a valid X.509 +// DirectoryString until initialized with a value. +OPENSSL_EXPORT ASN1_STRING *DIRECTORYSTRING_new(void); + +// DIRECTORYSTRING_free calls |ASN1_STRING_free|. +OPENSSL_EXPORT void DIRECTORYSTRING_free(ASN1_STRING *str); + +// d2i_DIRECTORYSTRING parses up to |len| bytes from |*inp| as a DER-encoded +// X.509 DirectoryString (RFC 5280), as described in |d2i_SAMPLE_with_reuse|. +// +// TODO(https://crbug.com/boringssl/354): This function currently also accepts +// BER, but this will be removed in the future. +// +// TODO(https://crbug.com/boringssl/449): DirectoryString's non-empty string +// requirement is not currently enforced. +OPENSSL_EXPORT ASN1_STRING *d2i_DIRECTORYSTRING(ASN1_STRING **out, + const uint8_t **inp, long len); + +// i2d_DIRECTORYSTRING marshals |in| as a DER-encoded X.509 DirectoryString (RFC +// 5280), as described in |i2d_SAMPLE|. +OPENSSL_EXPORT int i2d_DIRECTORYSTRING(const ASN1_STRING *in, uint8_t **outp); + +// DIRECTORYSTRING is an |ASN1_ITEM| whose ASN.1 type is X.509 DirectoryString +// (RFC 5280) and C type is |ASN1_STRING*|. +DECLARE_ASN1_ITEM(DIRECTORYSTRING) + +// B_ASN1_DISPLAYTEXT is a bitmask of types allowed in an X.509 DisplayText (RFC +// 5280). +#define B_ASN1_DISPLAYTEXT \ + (B_ASN1_IA5STRING | B_ASN1_VISIBLESTRING | B_ASN1_BMPSTRING | \ + B_ASN1_UTF8STRING) + +// DISPLAYTEXT_new returns a newly-allocated |ASN1_STRING| with type -1, or NULL +// on error. The resulting |ASN1_STRING| is not a valid X.509 DisplayText until +// initialized with a value. +OPENSSL_EXPORT ASN1_STRING *DISPLAYTEXT_new(void); + +// DISPLAYTEXT_free calls |ASN1_STRING_free|. +OPENSSL_EXPORT void DISPLAYTEXT_free(ASN1_STRING *str); + +// d2i_DISPLAYTEXT parses up to |len| bytes from |*inp| as a DER-encoded X.509 +// DisplayText (RFC 5280), as described in |d2i_SAMPLE_with_reuse|. +// +// TODO(https://crbug.com/boringssl/354): This function currently also accepts +// BER, but this will be removed in the future. +// +// TODO(https://crbug.com/boringssl/449): DisplayText's size limits are not +// currently enforced. +OPENSSL_EXPORT ASN1_STRING *d2i_DISPLAYTEXT(ASN1_STRING **out, + const uint8_t **inp, long len); + +// i2d_DISPLAYTEXT marshals |in| as a DER-encoded X.509 DisplayText (RFC 5280), +// as described in |i2d_SAMPLE|. +OPENSSL_EXPORT int i2d_DISPLAYTEXT(const ASN1_STRING *in, uint8_t **outp); + +// DISPLAYTEXT is an |ASN1_ITEM| whose ASN.1 type is X.509 DisplayText (RFC +// 5280) and C type is |ASN1_STRING*|. +DECLARE_ASN1_ITEM(DISPLAYTEXT) // Bit strings. @@ -406,7 +915,58 @@ OPENSSL_EXPORT int ASN1_mbstring_ncopy(ASN1_STRING **out, const uint8_t *in, // {0x80} and flags of ASN1_STRING_FLAG_BITS_LEFT | 6. If // |ASN1_STRING_FLAG_BITS_LEFT| is unset, trailing zero bits are implicitly // removed. Callers should not rely this representation when constructing bit -// strings. +// strings. The padding bits in the |ASN1_STRING| data must be zero. + +// ASN1_BIT_STRING_new calls |ASN1_STRING_type_new| with |V_ASN1_BIT_STRING|. +OPENSSL_EXPORT ASN1_BIT_STRING *ASN1_BIT_STRING_new(void); + +// ASN1_BIT_STRING_free calls |ASN1_STRING_free|. +OPENSSL_EXPORT void ASN1_BIT_STRING_free(ASN1_BIT_STRING *str); + +// d2i_ASN1_BIT_STRING parses up to |len| bytes from |*inp| as a DER-encoded +// ASN.1 BIT STRING, as described in |d2i_SAMPLE_with_reuse|. +// +// TODO(https://crbug.com/boringssl/354): This function currently also accepts +// BER, but this will be removed in the future. +OPENSSL_EXPORT ASN1_BIT_STRING *d2i_ASN1_BIT_STRING(ASN1_BIT_STRING **out, + const uint8_t **inp, + long len); + +// i2d_ASN1_BIT_STRING marshals |in| as a DER-encoded ASN.1 BIT STRING, as +// described in |i2d_SAMPLE|. +OPENSSL_EXPORT int i2d_ASN1_BIT_STRING(const ASN1_BIT_STRING *in, + uint8_t **outp); + +// c2i_ASN1_BIT_STRING decodes |len| bytes from |*inp| as the contents of a +// DER-encoded BIT STRING, excluding the tag and length. It behaves like +// |d2i_SAMPLE_with_reuse| except, on success, it always consumes all |len| +// bytes. +// +// TODO(https://crbug.com/boringssl/354): This function currently also accepts +// BER, but this will be removed in the future. +OPENSSL_EXPORT ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **out, + const uint8_t **inp, + long len); + +// i2c_ASN1_BIT_STRING encodes |in| as the contents of a DER-encoded BIT STRING, +// excluding the tag and length. If |outp| is non-NULL, it writes the result to +// |*outp|, advances |*outp| just past the output, and returns the number of +// bytes written. |*outp| must have space available for the result. If |outp| is +// NULL, it returns the number of bytes without writing anything. On error, it +// returns a value <= 0. +// +// Note this function differs slightly from |i2d_SAMPLE|. If |outp| is non-NULL +// and |*outp| is NULL, it does not allocate a new buffer. +// +// TODO(davidben): This function currently returns zero on error instead of -1, +// but it is also mostly infallible. I've currently documented <= 0 to suggest +// callers work with both. +OPENSSL_EXPORT int i2c_ASN1_BIT_STRING(const ASN1_BIT_STRING *in, + uint8_t **outp); + +// ASN1_BIT_STRING is an |ASN1_ITEM| with ASN.1 type BIT STRING and C type +// |ASN1_BIT_STRING*|. +DECLARE_ASN1_ITEM(ASN1_BIT_STRING) // ASN1_BIT_STRING_num_bytes computes the length of |str| in bytes. If |str|'s // bit length is a multiple of 8, it sets |*out| to the byte length and returns @@ -445,8 +1005,6 @@ OPENSSL_EXPORT int ASN1_BIT_STRING_check(const ASN1_BIT_STRING *str, const unsigned char *flags, int flags_len); -// TODO(davidben): Expand and document function prototypes generated in macros. - // Integers and enumerated values. // @@ -457,12 +1015,65 @@ OPENSSL_EXPORT int ASN1_BIT_STRING_check(const ASN1_BIT_STRING *str, // |V_ASN1_NEG_INTEGER| or |V_ASN1_NEG_ENUMERATED|. Note this differs from DER's // two's complement representation. +DEFINE_STACK_OF(ASN1_INTEGER) + +// ASN1_INTEGER_new calls |ASN1_STRING_type_new| with |V_ASN1_INTEGER|. The +// resulting object has value zero. +OPENSSL_EXPORT ASN1_INTEGER *ASN1_INTEGER_new(void); + +// ASN1_INTEGER_free calls |ASN1_STRING_free|. +OPENSSL_EXPORT void ASN1_INTEGER_free(ASN1_INTEGER *str); + +// ASN1_INTEGER_dup calls |ASN1_STRING_dup|. +OPENSSL_EXPORT ASN1_INTEGER *ASN1_INTEGER_dup(const ASN1_INTEGER *x); + +// d2i_ASN1_INTEGER parses up to |len| bytes from |*inp| as a DER-encoded +// ASN.1 INTEGER, as described in |d2i_SAMPLE_with_reuse|. +// +// TODO(https://crbug.com/boringssl/354): This function currently also accepts +// BER, but this will be removed in the future. +OPENSSL_EXPORT ASN1_INTEGER *d2i_ASN1_INTEGER(ASN1_INTEGER **out, + const uint8_t **inp, long len); + +// i2d_ASN1_INTEGER marshals |in| as a DER-encoded ASN.1 INTEGER, as +// described in |i2d_SAMPLE|. +OPENSSL_EXPORT int i2d_ASN1_INTEGER(const ASN1_INTEGER *in, uint8_t **outp); + +// c2i_ASN1_INTEGER decodes |len| bytes from |*inp| as the contents of a +// DER-encoded INTEGER, excluding the tag and length. It behaves like +// |d2i_SAMPLE_with_reuse| except, on success, it always consumes all |len| +// bytes. +// +// TODO(https://crbug.com/boringssl/354): This function currently also accepts +// some invalid inputs, but this will be removed in the future. +OPENSSL_EXPORT ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **in, + const uint8_t **outp, long len); + +// i2c_ASN1_INTEGER encodes |in| as the contents of a DER-encoded INTEGER, +// excluding the tag and length. If |outp| is non-NULL, it writes the result to +// |*outp|, advances |*outp| just past the output, and returns the number of +// bytes written. |*outp| must have space available for the result. If |outp| is +// NULL, it returns the number of bytes without writing anything. On error, it +// returns a value <= 0. +// +// Note this function differs slightly from |i2d_SAMPLE|. If |outp| is non-NULL +// and |*outp| is NULL, it does not allocate a new buffer. +// +// TODO(davidben): This function currently returns zero on error instead of -1, +// but it is also mostly infallible. I've currently documented <= 0 to suggest +// callers work with both. +OPENSSL_EXPORT int i2c_ASN1_INTEGER(const ASN1_INTEGER *in, uint8_t **outp); + +// ASN1_INTEGER is an |ASN1_ITEM| with ASN.1 type INTEGER and C type +// |ASN1_INTEGER*|. +DECLARE_ASN1_ITEM(ASN1_INTEGER) + // ASN1_INTEGER_set sets |a| to an INTEGER with value |v|. It returns one on // success and zero on error. OPENSSL_EXPORT int ASN1_INTEGER_set(ASN1_INTEGER *a, long v); -// ASN1_INTEGER_set sets |a| to an INTEGER with value |v|. It returns one on -// success and zero on error. +// ASN1_INTEGER_set_uint64 sets |a| to an INTEGER with value |v|. It returns one +// on success and zero on error. OPENSSL_EXPORT int ASN1_INTEGER_set_uint64(ASN1_INTEGER *out, uint64_t v); // ASN1_INTEGER_get returns the value of |a| as a |long|, or -1 if |a| is out of @@ -487,12 +1098,37 @@ OPENSSL_EXPORT BIGNUM *ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn); OPENSSL_EXPORT int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y); +// ASN1_ENUMERATED_new calls |ASN1_STRING_type_new| with |V_ASN1_ENUMERATED|. +// The resulting object has value zero. +OPENSSL_EXPORT ASN1_ENUMERATED *ASN1_ENUMERATED_new(void); + +// ASN1_ENUMERATED_free calls |ASN1_STRING_free|. +OPENSSL_EXPORT void ASN1_ENUMERATED_free(ASN1_ENUMERATED *str); + +// d2i_ASN1_ENUMERATED parses up to |len| bytes from |*inp| as a DER-encoded +// ASN.1 ENUMERATED, as described in |d2i_SAMPLE_with_reuse|. +// +// TODO(https://crbug.com/boringssl/354): This function currently also accepts +// BER, but this will be removed in the future. +OPENSSL_EXPORT ASN1_ENUMERATED *d2i_ASN1_ENUMERATED(ASN1_ENUMERATED **out, + const uint8_t **inp, + long len); + +// i2d_ASN1_ENUMERATED marshals |in| as a DER-encoded ASN.1 ENUMERATED, as +// described in |i2d_SAMPLE|. +OPENSSL_EXPORT int i2d_ASN1_ENUMERATED(const ASN1_ENUMERATED *in, + uint8_t **outp); + +// ASN1_ENUMERATED is an |ASN1_ITEM| with ASN.1 type ENUMERATED and C type +// |ASN1_ENUMERATED*|. +DECLARE_ASN1_ITEM(ASN1_ENUMERATED) + // ASN1_ENUMERATED_set sets |a| to an ENUMERATED with value |v|. It returns one // on success and zero on error. OPENSSL_EXPORT int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v); -// ASN1_INTEGER_get returns the value of |a| as a |long|, or -1 if |a| is out of -// range or the wrong type. +// ASN1_ENUMERATED_get returns the value of |a| as a |long|, or -1 if |a| is out +// of range or the wrong type. OPENSSL_EXPORT long ASN1_ENUMERATED_get(const ASN1_ENUMERATED *a); // BN_to_ASN1_ENUMERATED sets |ai| to an ENUMERATED with value |bn| and returns @@ -508,8 +1144,6 @@ OPENSSL_EXPORT ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(const BIGNUM *bn, OPENSSL_EXPORT BIGNUM *ASN1_ENUMERATED_to_BN(const ASN1_ENUMERATED *ai, BIGNUM *bn); -// TODO(davidben): Expand and document function prototypes generated in macros. - // Time. // @@ -525,8 +1159,33 @@ OPENSSL_EXPORT BIGNUM *ASN1_ENUMERATED_to_BN(const ASN1_ENUMERATED *ai, // BER, and the additional restrictions from RFC 5280, but future versions may. // Callers should not rely on fractional seconds and non-UTC time zones. // -// The |ASN1_TIME| typedef represents the X.509 Time type, which is a CHOICE of -// GeneralizedTime and UTCTime, using UTCTime when the value is in range. +// The |ASN1_TIME| typedef is a multi-string representing the X.509 Time type, +// which is a CHOICE of GeneralizedTime and UTCTime, using UTCTime when the +// value is in range. + +// ASN1_UTCTIME_new calls |ASN1_STRING_type_new| with |V_ASN1_UTCTIME|. The +// resulting object contains empty contents and must be initialized to be a +// valid UTCTime. +OPENSSL_EXPORT ASN1_UTCTIME *ASN1_UTCTIME_new(void); + +// ASN1_UTCTIME_free calls |ASN1_STRING_free|. +OPENSSL_EXPORT void ASN1_UTCTIME_free(ASN1_UTCTIME *str); + +// d2i_ASN1_UTCTIME parses up to |len| bytes from |*inp| as a DER-encoded +// ASN.1 UTCTime, as described in |d2i_SAMPLE_with_reuse|. +// +// TODO(https://crbug.com/boringssl/354): This function currently also accepts +// BER, but this will be removed in the future. +OPENSSL_EXPORT ASN1_UTCTIME *d2i_ASN1_UTCTIME(ASN1_UTCTIME **out, + const uint8_t **inp, long len); + +// i2d_ASN1_UTCTIME marshals |in| as a DER-encoded ASN.1 UTCTime, as +// described in |i2d_SAMPLE|. +OPENSSL_EXPORT int i2d_ASN1_UTCTIME(const ASN1_UTCTIME *in, uint8_t **outp); + +// ASN1_UTCTIME is an |ASN1_ITEM| with ASN.1 type UTCTime and C type +// |ASN1_UTCTIME*|. +DECLARE_ASN1_ITEM(ASN1_UTCTIME) // ASN1_UTCTIME_check returns one if |a| is a valid UTCTime and zero otherwise. OPENSSL_EXPORT int ASN1_UTCTIME_check(const ASN1_UTCTIME *a); @@ -558,6 +1217,31 @@ OPENSSL_EXPORT int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str); // they are equal, 1 if |s| > |t|, and -2 on error. OPENSSL_EXPORT int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t); +// ASN1_GENERALIZEDTIME_new calls |ASN1_STRING_type_new| with +// |V_ASN1_GENERALIZEDTIME|. The resulting object contains empty contents and +// must be initialized to be a valid GeneralizedTime. +OPENSSL_EXPORT ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_new(void); + +// ASN1_GENERALIZEDTIME_free calls |ASN1_STRING_free|. +OPENSSL_EXPORT void ASN1_GENERALIZEDTIME_free(ASN1_GENERALIZEDTIME *str); + +// d2i_ASN1_GENERALIZEDTIME parses up to |len| bytes from |*inp| as a +// DER-encoded ASN.1 GeneralizedTime, as described in |d2i_SAMPLE_with_reuse|. +// +// TODO(https://crbug.com/boringssl/354): This function currently also accepts +// BER, but this will be removed in the future. +OPENSSL_EXPORT ASN1_GENERALIZEDTIME *d2i_ASN1_GENERALIZEDTIME( + ASN1_GENERALIZEDTIME **out, const uint8_t **inp, long len); + +// i2d_ASN1_GENERALIZEDTIME marshals |in| as a DER-encoded ASN.1 +// GeneralizedTime, as described in |i2d_SAMPLE|. +OPENSSL_EXPORT int i2d_ASN1_GENERALIZEDTIME(const ASN1_GENERALIZEDTIME *in, + uint8_t **outp); + +// ASN1_GENERALIZEDTIME is an |ASN1_ITEM| with ASN.1 type GeneralizedTime and C +// type |ASN1_GENERALIZEDTIME*|. +DECLARE_ASN1_ITEM(ASN1_GENERALIZEDTIME) + // ASN1_GENERALIZEDTIME_check returns one if |a| is a valid GeneralizedTime and // zero otherwise. OPENSSL_EXPORT int ASN1_GENERALIZEDTIME_check(const ASN1_GENERALIZEDTIME *a); @@ -588,6 +1272,33 @@ OPENSSL_EXPORT ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj( OPENSSL_EXPORT int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str); +// B_ASN1_TIME is a bitmask of types allowed in an X.509 Time. +#define B_ASN1_TIME (B_ASN1_UTCTIME | B_ASN1_GENERALIZEDTIME) + +// ASN1_TIME_new returns a newly-allocated |ASN1_TIME| with type -1, or NULL on +// error. The resulting |ASN1_TIME| is not a valid X.509 Time until initialized +// with a value. +OPENSSL_EXPORT ASN1_TIME *ASN1_TIME_new(void); + +// ASN1_TIME_free releases memory associated with |str|. +OPENSSL_EXPORT void ASN1_TIME_free(ASN1_TIME *str); + +// d2i_ASN1_TIME parses up to |len| bytes from |*inp| as a DER-encoded X.509 +// Time (RFC 5280), as described in |d2i_SAMPLE_with_reuse|. +// +// TODO(https://crbug.com/boringssl/354): This function currently also accepts +// BER, but this will be removed in the future. +OPENSSL_EXPORT ASN1_TIME *d2i_ASN1_TIME(ASN1_TIME **out, const uint8_t **inp, + long len); + +// i2d_ASN1_TIME marshals |in| as a DER-encoded X.509 Time (RFC 5280), as +// described in |i2d_SAMPLE|. +OPENSSL_EXPORT int i2d_ASN1_TIME(const ASN1_TIME *in, uint8_t **outp); + +// ASN1_TIME is an |ASN1_ITEM| whose ASN.1 type is X.509 Time (RFC 5280) and C +// type is |ASN1_TIME*|. +DECLARE_ASN1_ITEM(ASN1_TIME) + // ASN1_TIME_diff computes |to| - |from|. On success, it sets |*out_days| to the // difference in days, rounded towards zero, sets |*out_seconds| to the // remainder, and returns one. On error, it returns zero. @@ -641,15 +1352,95 @@ OPENSSL_EXPORT int ASN1_TIME_set_string(ASN1_TIME *s, const char *str); // TODO(davidben): Expand and document function prototypes generated in macros. +// NULL values. +// +// This library represents the ASN.1 NULL value by a non-NULL pointer to the +// opaque type |ASN1_NULL|. An omitted OPTIONAL ASN.1 NULL value is a NULL +// pointer. Unlike other pointer types, it is not necessary to free |ASN1_NULL| +// pointers, but it is safe to do so. + +// ASN1_NULL_new returns an opaque, non-NULL pointer. It is safe to call +// |ASN1_NULL_free| on the result, but not necessary. +OPENSSL_EXPORT ASN1_NULL *ASN1_NULL_new(void); + +// ASN1_NULL_free does nothing. +OPENSSL_EXPORT void ASN1_NULL_free(ASN1_NULL *null); + +// d2i_ASN1_NULL parses a DER-encoded ASN.1 NULL value from up to |len| bytes +// at |*inp|, as described in |d2i_SAMPLE|. +// +// TODO(https://crbug.com/boringssl/354): This function currently also accepts +// BER, but this will be removed in the future. +OPENSSL_EXPORT ASN1_NULL *d2i_ASN1_NULL(ASN1_NULL **out, const uint8_t **inp, + long len); + +// i2d_ASN1_NULL marshals |in| as a DER-encoded ASN.1 NULL value, as described +// in |i2d_SAMPLE|. +OPENSSL_EXPORT int i2d_ASN1_NULL(const ASN1_NULL *in, uint8_t **outp); + +// ASN1_NULL is an |ASN1_ITEM| with ASN.1 type NULL and C type |ASN1_NULL*|. +DECLARE_ASN1_ITEM(ASN1_NULL) + + +// Object identifiers. +// +// An |ASN1_OBJECT| represents a ASN.1 OBJECT IDENTIFIER. See also obj.h for +// additional functions relating to |ASN1_OBJECT|. +// +// TODO(davidben): What's the relationship between asn1.h and obj.h? Most of +// obj.h deals with the large NID table, but then functions like |OBJ_get0_data| +// or |OBJ_dup| are general |ASN1_OBJECT| functions. + +DEFINE_STACK_OF(ASN1_OBJECT) + +// ASN1_OBJECT_create returns a newly-allocated |ASN1_OBJECT| with |len| bytes +// from |data| as the encoded OID, or NULL on error. |data| should contain the +// DER-encoded identifier, excluding the tag and length. +// +// |nid| should be |NID_undef|. Passing a NID value that does not match |data| +// will cause some functions to misbehave. |sn| and |ln| should be NULL. If +// non-NULL, they are stored as short and long names, respectively, but these +// values have no effect for |ASN1_OBJECT|s created through this function. +// +// TODO(davidben): Should we just ignore all those parameters? NIDs and names +// are only relevant for |ASN1_OBJECT|s in the obj.h table. +OPENSSL_EXPORT ASN1_OBJECT *ASN1_OBJECT_create(int nid, const uint8_t *data, + int len, const char *sn, + const char *ln); + +// ASN1_OBJECT_free releases memory associated with |a|. If |a| is a static +// |ASN1_OBJECT|, returned from |OBJ_nid2obj|, this function does nothing. +OPENSSL_EXPORT void ASN1_OBJECT_free(ASN1_OBJECT *a); + +// d2i_ASN1_OBJECT parses a DER-encoded ASN.1 OBJECT IDENTIFIER from up to |len| +// bytes at |*inp|, as described in |d2i_SAMPLE_with_reuse|. +// +// TODO(https://crbug.com/boringssl/354): This function currently also accepts +// BER, but this will be removed in the future. +OPENSSL_EXPORT ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **out, + const uint8_t **inp, long len); + +// i2d_ASN1_OBJECT marshals |in| as a DER-encoded ASN.1 OBJECT IDENTIFIER, as +// described in |i2d_SAMPLE|. +OPENSSL_EXPORT int i2d_ASN1_OBJECT(const ASN1_OBJECT *a, uint8_t **outp); + +// c2i_ASN1_OBJECT decodes |len| bytes from |*inp| as the contents of a +// DER-encoded OBJECT IDENTIFIER, excluding the tag and length. It behaves like +// |d2i_SAMPLE_with_reuse| except, on success, it always consumes all |len| +// bytes. +OPENSSL_EXPORT ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **out, + const uint8_t **inp, long len); + +// ASN1_OBJECT is an |ASN1_ITEM| with ASN.1 type OBJECT IDENTIFIER and C type +// |ASN1_OBJECT*|. +DECLARE_ASN1_ITEM(ASN1_OBJECT) + + // Arbitrary elements. -// ASN1_VALUE_st (aka |ASN1_VALUE|) is an opaque type used internally in the -// library. -typedef struct ASN1_VALUE_st ASN1_VALUE; - // An asn1_type_st (aka |ASN1_TYPE|) represents an arbitrary ASN.1 element, -// typically used used for ANY types. It contains a |type| field and a |value| -// union dependent on |type|. +// typically used for ANY types. It contains a |type| field and a |value| union +// dependent on |type|. // // WARNING: This struct has a complex representation. Callers must not construct // |ASN1_TYPE| values manually. Use |ASN1_TYPE_set| and |ASN1_TYPE_set1| @@ -715,6 +1506,34 @@ struct asn1_type_st { } value; }; +DEFINE_STACK_OF(ASN1_TYPE) + +// ASN1_TYPE_new returns a newly-allocated |ASN1_TYPE|, or NULL on allocation +// failure. The resulting object has type -1 and must be initialized to be +// a valid ANY value. +OPENSSL_EXPORT ASN1_TYPE *ASN1_TYPE_new(void); + +// ASN1_TYPE_free releases memory associated with |a|. +OPENSSL_EXPORT void ASN1_TYPE_free(ASN1_TYPE *a); + +// d2i_ASN1_TYPE parses up to |len| bytes from |*inp| as an ASN.1 value of any +// type, as described in |d2i_SAMPLE_with_reuse|. Note this function only +// validates primitive, universal types supported by this library. Values of +// type |V_ASN1_SEQUENCE|, |V_ASN1_SET|, |V_ASN1_OTHER|, or an unsupported +// primitive type must be validated by the caller when interpreting. +// +// TODO(https://crbug.com/boringssl/354): This function currently also accepts +// BER, but this will be removed in the future. +OPENSSL_EXPORT ASN1_TYPE *d2i_ASN1_TYPE(ASN1_TYPE **out, const uint8_t **inp, + long len); + +// i2d_ASN1_TYPE marshals |in| as DER, as described in |i2d_SAMPLE|. +OPENSSL_EXPORT int i2d_ASN1_TYPE(const ASN1_TYPE *in, uint8_t **outp); + +// ASN1_ANY is an |ASN1_ITEM| with ASN.1 type ANY and C type |ASN1_TYPE*|. Note +// the |ASN1_ITEM| name and C type do not match. +DECLARE_ASN1_ITEM(ASN1_ANY) + // ASN1_TYPE_get returns the type of |a|, which will be one of the |V_ASN1_*| // constants, or zero if |a| is not fully initialized. OPENSSL_EXPORT int ASN1_TYPE_get(const ASN1_TYPE *a); @@ -742,8 +1561,39 @@ OPENSSL_EXPORT int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value); // ordering. OPENSSL_EXPORT int ASN1_TYPE_cmp(const ASN1_TYPE *a, const ASN1_TYPE *b); -// TODO(davidben): Most of |ASN1_TYPE|'s APIs are hidden behind macros. Expand -// the macros, document them, and move them to this section. +typedef STACK_OF(ASN1_TYPE) ASN1_SEQUENCE_ANY; + +// d2i_ASN1_SEQUENCE_ANY parses up to |len| bytes from |*inp| as a DER-encoded +// ASN.1 SEQUENCE OF ANY structure, as described in |d2i_SAMPLE_with_reuse|. The +// resulting |ASN1_SEQUENCE_ANY| owns its contents and thus must be released +// with |sk_ASN1_TYPE_pop_free| and |ASN1_TYPE_free|, not |sk_ASN1_TYPE_free|. +// +// TODO(https://crbug.com/boringssl/354): This function currently also accepts +// BER, but this will be removed in the future. +OPENSSL_EXPORT ASN1_SEQUENCE_ANY *d2i_ASN1_SEQUENCE_ANY(ASN1_SEQUENCE_ANY **out, + const uint8_t **inp, + long len); + +// i2d_ASN1_SEQUENCE_ANY marshals |in| as a DER-encoded SEQUENCE OF ANY +// structure, as described in |i2d_SAMPLE|. +OPENSSL_EXPORT int i2d_ASN1_SEQUENCE_ANY(const ASN1_SEQUENCE_ANY *in, + uint8_t **outp); + +// d2i_ASN1_SET_ANY parses up to |len| bytes from |*inp| as a DER-encoded ASN.1 +// SET OF ANY structure, as described in |d2i_SAMPLE_with_reuse|. The resulting +// |ASN1_SEQUENCE_ANY| owns its contents and thus must be released with +// |sk_ASN1_TYPE_pop_free| and |ASN1_TYPE_free|, not |sk_ASN1_TYPE_free|. +// +// TODO(https://crbug.com/boringssl/354): This function currently also accepts +// BER, but this will be removed in the future. +OPENSSL_EXPORT ASN1_SEQUENCE_ANY *d2i_ASN1_SET_ANY(ASN1_SEQUENCE_ANY **out, + const uint8_t **inp, + long len); + +// i2d_ASN1_SET_ANY marshals |in| as a DER-encoded SET OF ANY structure, as +// described in |i2d_SAMPLE|. +OPENSSL_EXPORT int i2d_ASN1_SET_ANY(const ASN1_SEQUENCE_ANY *in, + uint8_t **outp); // Human-readable output. @@ -838,48 +1688,90 @@ OPENSSL_EXPORT int ASN1_STRING_print_ex(BIO *out, const ASN1_STRING *str, OPENSSL_EXPORT int ASN1_STRING_print_ex_fp(FILE *fp, const ASN1_STRING *str, unsigned long flags); +// i2a_ASN1_INTEGER writes a human-readable representation of |a| to |bp|. It +// returns the number of bytes written on success, or a negative number on +// error. On error, this function may have written a partial output to |bp|. +OPENSSL_EXPORT int i2a_ASN1_INTEGER(BIO *bp, const ASN1_INTEGER *a); -// Underdocumented functions. +// i2a_ASN1_ENUMERATED writes a human-readable representation of |a| to |bp|. It +// returns the number of bytes written on success, or a negative number on +// error. On error, this function may have written a partial output to |bp|. +OPENSSL_EXPORT int i2a_ASN1_ENUMERATED(BIO *bp, const ASN1_ENUMERATED *a); + +// i2a_ASN1_OBJECT writes a human-readable representation of |a| to |bp|. It +// returns the number of bytes written on success, or a negative number on +// error. On error, this function may have written a partial output to |bp|. +OPENSSL_EXPORT int i2a_ASN1_OBJECT(BIO *bp, const ASN1_OBJECT *a); + +// i2a_ASN1_STRING writes a text representation of |a|'s contents to |bp|. It +// returns the number of bytes written on success, or a negative number on +// error. On error, this function may have written a partial output to |bp|. +// |type| is ignored. // -// The following functions are not yet documented and organized. +// This function does not decode |a| into a Unicode string. It only hex-encodes +// the internal representation of |a|. This is suitable for printing an OCTET +// STRING, but may not be human-readable for any other string type. +OPENSSL_EXPORT int i2a_ASN1_STRING(BIO *bp, const ASN1_STRING *a, int type); -DEFINE_STACK_OF(ASN1_OBJECT) +// i2t_ASN1_OBJECT calls |OBJ_obj2txt| with |always_return_oid| set to zero. +OPENSSL_EXPORT int i2t_ASN1_OBJECT(char *buf, int buf_len, + const ASN1_OBJECT *a); -// ASN1_ENCODING structure: this is used to save the received -// encoding of an ASN1 type. This is useful to get round -// problems with invalid encodings which can break signatures. -typedef struct ASN1_ENCODING_st { - unsigned char *enc; // DER encoding - long len; // Length of encoding - int modified; // set to 1 if 'enc' is invalid - // alias_only is zero if |enc| owns the buffer that it points to - // (although |enc| may still be NULL). If one, |enc| points into a - // buffer that is owned elsewhere. - unsigned alias_only : 1; - // alias_only_on_next_parse is one iff the next parsing operation - // should avoid taking a copy of the input and rather set - // |alias_only|. - unsigned alias_only_on_next_parse : 1; -} ASN1_ENCODING; +// Low-level encoding functions. -#define STABLE_FLAGS_MALLOC 0x01 -#define STABLE_NO_MASK 0x02 +// ASN1_get_object parses a BER element from up to |max_len| bytes at |*inp|. It +// returns |V_ASN1_CONSTRUCTED| if it successfully parsed a constructed element, +// zero if it successfully parsed a primitive element, and 0x80 on error. On +// success, it additionally advances |*inp| to the element body, sets +// |*out_length|, |*out_tag|, and |*out_class| to the element's length, tag +// number, and tag class, respectively, +// +// Unlike OpenSSL, this function does not support indefinite-length elements. +// +// This function is difficult to use correctly. Use |CBS_get_asn1| and related +// functions from bytestring.h. +// +// TODO(https://crbug.com/boringssl/354): Remove support for non-minimal +// lengths. +OPENSSL_EXPORT int ASN1_get_object(const unsigned char **inp, long *out_length, + int *out_tag, int *out_class, long max_len); -typedef struct asn1_string_table_st { - int nid; - long minsize; - long maxsize; - unsigned long mask; - unsigned long flags; -} ASN1_STRING_TABLE; +// ASN1_put_object writes the header for a DER or BER element to |*outp| and +// advances |*outp| by the number of bytes written. The caller is responsible +// for ensuring |*outp| has enough space for the output. The header describes an +// element with length |length|, tag number |tag|, and class |xclass|. |xclass| +// should be one of the |V_ASN1_*| tag class constants. The element is primitive +// if |constructed| is zero and constructed if it is one or two. If +// |constructed| is two, |length| is ignored and the element uses +// indefinite-length encoding. +// +// Use |CBB_add_asn1| instead. +OPENSSL_EXPORT void ASN1_put_object(unsigned char **outp, int constructed, + int length, int tag, int xclass); -// Declarations for template structures: for full definitions -// see asn1t.h -typedef struct ASN1_TEMPLATE_st ASN1_TEMPLATE; -typedef struct ASN1_TLC_st ASN1_TLC; +// ASN1_put_eoc writes two zero bytes to |*outp|, advances |*outp| to point past +// those bytes, and returns two. +// +// Use definite-length encoding instead. +OPENSSL_EXPORT int ASN1_put_eoc(unsigned char **outp); -// Declare ASN1 functions: the implement macro in in asn1t.h +// ASN1_object_size returns the number of bytes needed to encode a DER or BER +// value with length |length| and tag number |tag|, or -1 on error. |tag| should +// not include the constructed bit or tag class. If |constructed| is zero or +// one, the result uses a definite-length encoding with minimally-encoded +// length, as in DER. If |constructed| is two, the result uses BER +// indefinite-length encoding. +// +// Use |CBB_add_asn1| instead. +OPENSSL_EXPORT int ASN1_object_size(int constructed, int length, int tag); + + +// Function declaration macros. +// +// The following macros declare functions for ASN.1 types. Prefer writing the +// prototypes directly. Particularly when |type|, |itname|, or |name| differ, +// the macros can be difficult to understand. #define DECLARE_ASN1_FUNCTIONS(type) DECLARE_ASN1_FUNCTIONS_name(type, type) @@ -914,71 +1806,29 @@ typedef struct ASN1_TLC_st ASN1_TLC; OPENSSL_EXPORT type *name##_new(void); \ OPENSSL_EXPORT void name##_free(type *a); -#define DECLARE_ASN1_PRINT_FUNCTION(stname) \ - DECLARE_ASN1_PRINT_FUNCTION_fname(stname, stname) -#define DECLARE_ASN1_PRINT_FUNCTION_fname(stname, fname) \ - OPENSSL_EXPORT int fname##_print_ctx(BIO *out, stname *x, int indent, \ - const ASN1_PCTX *pctx); +// Deprecated functions. -typedef void *d2i_of_void(void **, const unsigned char **, long); -typedef int i2d_of_void(const void *, unsigned char **); - -// The following macros and typedefs allow an ASN1_ITEM -// to be embedded in a structure and referenced. Since -// the ASN1_ITEM pointers need to be globally accessible -// (possibly from shared libraries) they may exist in -// different forms. On platforms that support it the -// ASN1_ITEM structure itself will be globally exported. -// Other platforms will export a function that returns -// an ASN1_ITEM pointer. -// -// To handle both cases transparently the macros below -// should be used instead of hard coding an ASN1_ITEM -// pointer in a structure. -// -// The structure will look like this: -// -// typedef struct SOMETHING_st { -// ... -// ASN1_ITEM_EXP *iptr; -// ... -// } SOMETHING; -// -// It would be initialised as e.g.: -// -// SOMETHING somevar = {...,ASN1_ITEM_ref(X509),...}; -// -// and the actual pointer extracted with: -// -// const ASN1_ITEM *it = ASN1_ITEM_ptr(somevar.iptr); -// -// Finally an ASN1_ITEM pointer can be extracted from an -// appropriate reference with: ASN1_ITEM_rptr(X509). This -// would be used when a function takes an ASN1_ITEM * argument. +// ASN1_PRINTABLE_type interprets |len| bytes from |s| as a Latin-1 string. It +// returns the first of |V_ASN1_PRINTABLESTRING|, |V_ASN1_IA5STRING|, or +// |V_ASN1_T61STRING| that can represent every character. If |len| is negative, +// |strlen(s)| is used instead. // +// TODO(davidben): Remove this once all copies of Conscrypt have been updated +// past https://github.com/google/conscrypt/pull/1032. +OPENSSL_EXPORT int ASN1_PRINTABLE_type(const unsigned char *s, int len); -// ASN1_ITEM pointer exported type -typedef const ASN1_ITEM ASN1_ITEM_EXP; +// ASN1_STRING_set_default_mask does nothing. +OPENSSL_EXPORT void ASN1_STRING_set_default_mask(unsigned long mask); -// Macro to obtain ASN1_ITEM pointer from exported type -#define ASN1_ITEM_ptr(iptr) (iptr) +// ASN1_STRING_set_default_mask_asc returns one. +OPENSSL_EXPORT int ASN1_STRING_set_default_mask_asc(const char *p); -// Macro to include ASN1_ITEM pointer from base type -#define ASN1_ITEM_ref(iptr) (&(iptr##_it)) +// ASN1_STRING_get_default_mask returns |B_ASN1_UTF8STRING|. +OPENSSL_EXPORT unsigned long ASN1_STRING_get_default_mask(void); -#define ASN1_ITEM_rptr(ref) (&(ref##_it)) - -#define DECLARE_ASN1_ITEM(name) extern OPENSSL_EXPORT const ASN1_ITEM name##_it; - -DEFINE_STACK_OF(ASN1_INTEGER) - -DEFINE_STACK_OF(ASN1_TYPE) - -typedef STACK_OF(ASN1_TYPE) ASN1_SEQUENCE_ANY; - -DECLARE_ASN1_ENCODE_FUNCTIONS_const(ASN1_SEQUENCE_ANY, ASN1_SEQUENCE_ANY) -DECLARE_ASN1_ENCODE_FUNCTIONS_const(ASN1_SEQUENCE_ANY, ASN1_SET_ANY) +// ASN1_STRING_TABLE_cleanup does nothing. +OPENSSL_EXPORT void ASN1_STRING_TABLE_cleanup(void); // M_ASN1_* are legacy aliases for various |ASN1_STRING| functions. Use the // functions themselves. @@ -1028,159 +1878,53 @@ DECLARE_ASN1_ENCODE_FUNCTIONS_const(ASN1_SEQUENCE_ANY, ASN1_SET_ANY) #define M_ASN1_UTF8STRING_new() ASN1_UTF8STRING_new() #define M_ASN1_UTF8STRING_free(a) ASN1_UTF8STRING_free(a) -#define B_ASN1_TIME B_ASN1_UTCTIME | B_ASN1_GENERALIZEDTIME - +// B_ASN1_PRINTABLE is a bitmask for an ad-hoc subset of string-like types. Note +// the presence of |B_ASN1_UNKNOWN| means it includes types which |ASN1_tag2bit| +// maps to |B_ASN1_UNKNOWN|. +// +// Do not use this. Despite the name, it has no connection to PrintableString or +// printable characters. See https://crbug.com/boringssl/412. #define B_ASN1_PRINTABLE \ - B_ASN1_NUMERICSTRING | B_ASN1_PRINTABLESTRING | B_ASN1_T61STRING | \ - B_ASN1_IA5STRING | B_ASN1_BIT_STRING | B_ASN1_UNIVERSALSTRING | \ - B_ASN1_BMPSTRING | B_ASN1_UTF8STRING | B_ASN1_SEQUENCE | B_ASN1_UNKNOWN + (B_ASN1_NUMERICSTRING | B_ASN1_PRINTABLESTRING | B_ASN1_T61STRING | \ + B_ASN1_IA5STRING | B_ASN1_BIT_STRING | B_ASN1_UNIVERSALSTRING | \ + B_ASN1_BMPSTRING | B_ASN1_UTF8STRING | B_ASN1_SEQUENCE | B_ASN1_UNKNOWN) -#define B_ASN1_DIRECTORYSTRING \ - B_ASN1_PRINTABLESTRING | B_ASN1_TELETEXSTRING | B_ASN1_BMPSTRING | \ - B_ASN1_UNIVERSALSTRING | B_ASN1_UTF8STRING +// ASN1_PRINTABLE_new returns a newly-allocated |ASN1_STRING| with type -1, or +// NULL on error. The resulting |ASN1_STRING| is not a valid ASN.1 value until +// initialized with a value. +OPENSSL_EXPORT ASN1_STRING *ASN1_PRINTABLE_new(void); -#define B_ASN1_DISPLAYTEXT \ - B_ASN1_IA5STRING | B_ASN1_VISIBLESTRING | B_ASN1_BMPSTRING | B_ASN1_UTF8STRING +// ASN1_PRINTABLE_free calls |ASN1_STRING_free|. +OPENSSL_EXPORT void ASN1_PRINTABLE_free(ASN1_STRING *str); -DECLARE_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE) +// d2i_ASN1_PRINTABLE parses up to |len| bytes from |*inp| as a DER-encoded +// CHOICE of an ad-hoc subset of string-like types, as described in +// |d2i_SAMPLE_with_reuse|. +// +// Do not use this. Despite, the name it has no connection to PrintableString or +// printable characters. See https://crbug.com/boringssl/412. +// +// TODO(https://crbug.com/boringssl/354): This function currently also accepts +// BER, but this will be removed in the future. +OPENSSL_EXPORT ASN1_STRING *d2i_ASN1_PRINTABLE(ASN1_STRING **out, + const uint8_t **inp, long len); -OPENSSL_EXPORT ASN1_OBJECT *ASN1_OBJECT_new(void); -OPENSSL_EXPORT void ASN1_OBJECT_free(ASN1_OBJECT *a); -OPENSSL_EXPORT int i2d_ASN1_OBJECT(const ASN1_OBJECT *a, unsigned char **pp); -OPENSSL_EXPORT ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, - const unsigned char **pp, - long length); -OPENSSL_EXPORT ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, - const unsigned char **pp, - long length); +// i2d_ASN1_PRINTABLE marshals |in| as DER, as described in |i2d_SAMPLE|. +// +// Do not use this. Despite the name, it has no connection to PrintableString or +// printable characters. See https://crbug.com/boringssl/412. +OPENSSL_EXPORT int i2d_ASN1_PRINTABLE(const ASN1_STRING *in, uint8_t **outp); -DECLARE_ASN1_ITEM(ASN1_OBJECT) - -DECLARE_ASN1_FUNCTIONS(ASN1_BIT_STRING) -OPENSSL_EXPORT int i2c_ASN1_BIT_STRING(const ASN1_BIT_STRING *a, - unsigned char **pp); -OPENSSL_EXPORT ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, - const unsigned char **pp, - long length); - -OPENSSL_EXPORT int i2d_ASN1_BOOLEAN(int a, unsigned char **pp); -OPENSSL_EXPORT int d2i_ASN1_BOOLEAN(int *a, const unsigned char **pp, - long length); - -DECLARE_ASN1_FUNCTIONS(ASN1_INTEGER) -OPENSSL_EXPORT int i2c_ASN1_INTEGER(const ASN1_INTEGER *a, unsigned char **pp); -OPENSSL_EXPORT ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, - const unsigned char **pp, - long length); -OPENSSL_EXPORT ASN1_INTEGER *ASN1_INTEGER_dup(const ASN1_INTEGER *x); - -DECLARE_ASN1_FUNCTIONS(ASN1_ENUMERATED) - -DECLARE_ASN1_FUNCTIONS(ASN1_OCTET_STRING) -OPENSSL_EXPORT ASN1_OCTET_STRING *ASN1_OCTET_STRING_dup( - const ASN1_OCTET_STRING *a); -OPENSSL_EXPORT int ASN1_OCTET_STRING_cmp(const ASN1_OCTET_STRING *a, - const ASN1_OCTET_STRING *b); -OPENSSL_EXPORT int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *str, - const unsigned char *data, int len); - -DECLARE_ASN1_FUNCTIONS(ASN1_VISIBLESTRING) -DECLARE_ASN1_FUNCTIONS(ASN1_UNIVERSALSTRING) -DECLARE_ASN1_FUNCTIONS(ASN1_UTF8STRING) -DECLARE_ASN1_FUNCTIONS(ASN1_NULL) -DECLARE_ASN1_FUNCTIONS(ASN1_BMPSTRING) - -DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, ASN1_PRINTABLE) - -DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DIRECTORYSTRING) -DECLARE_ASN1_FUNCTIONS_name(ASN1_STRING, DISPLAYTEXT) -DECLARE_ASN1_FUNCTIONS(ASN1_PRINTABLESTRING) -DECLARE_ASN1_FUNCTIONS(ASN1_T61STRING) -DECLARE_ASN1_FUNCTIONS(ASN1_IA5STRING) -DECLARE_ASN1_FUNCTIONS(ASN1_GENERALSTRING) -DECLARE_ASN1_FUNCTIONS(ASN1_UTCTIME) -DECLARE_ASN1_FUNCTIONS(ASN1_GENERALIZEDTIME) -DECLARE_ASN1_FUNCTIONS(ASN1_TIME) - -OPENSSL_EXPORT int i2a_ASN1_INTEGER(BIO *bp, const ASN1_INTEGER *a); -OPENSSL_EXPORT int i2a_ASN1_ENUMERATED(BIO *bp, const ASN1_ENUMERATED *a); -OPENSSL_EXPORT int i2a_ASN1_OBJECT(BIO *bp, const ASN1_OBJECT *a); -OPENSSL_EXPORT int i2a_ASN1_STRING(BIO *bp, const ASN1_STRING *a, int type); -OPENSSL_EXPORT int i2t_ASN1_OBJECT(char *buf, int buf_len, - const ASN1_OBJECT *a); - -OPENSSL_EXPORT ASN1_OBJECT *ASN1_OBJECT_create(int nid, - const unsigned char *data, - int len, const char *sn, - const char *ln); - -// ASN1_PRINTABLE_type interprets |len| bytes from |s| as a Latin-1 string. It -// returns the first of |V_ASN1_PRINTABLESTRING|, |V_ASN1_IA5STRING|, or -// |V_ASN1_T61STRING| that can represent every character. If |len| is negative, -// |strlen(s)| is used instead. -OPENSSL_EXPORT int ASN1_PRINTABLE_type(const unsigned char *s, int len); - -OPENSSL_EXPORT unsigned long ASN1_tag2bit(int tag); - -// SPECIALS -OPENSSL_EXPORT int ASN1_get_object(const unsigned char **pp, long *plength, - int *ptag, int *pclass, long omax); -OPENSSL_EXPORT void ASN1_put_object(unsigned char **pp, int constructed, - int length, int tag, int xclass); -OPENSSL_EXPORT int ASN1_put_eoc(unsigned char **pp); -OPENSSL_EXPORT int ASN1_object_size(int constructed, int length, int tag); - -OPENSSL_EXPORT void *ASN1_item_dup(const ASN1_ITEM *it, void *x); - -OPENSSL_EXPORT void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x); -OPENSSL_EXPORT int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x); - -OPENSSL_EXPORT void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x); -OPENSSL_EXPORT int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x); - -// Used to load and write netscape format cert - -OPENSSL_EXPORT void *ASN1_item_unpack(const ASN1_STRING *oct, - const ASN1_ITEM *it); - -OPENSSL_EXPORT ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, - ASN1_OCTET_STRING **oct); - -// ASN1_STRING_set_default_mask does nothing. -OPENSSL_EXPORT void ASN1_STRING_set_default_mask(unsigned long mask); - -// ASN1_STRING_set_default_mask_asc returns one. -OPENSSL_EXPORT int ASN1_STRING_set_default_mask_asc(const char *p); - -// ASN1_STRING_get_default_mask returns |B_ASN1_UTF8STRING|. -OPENSSL_EXPORT unsigned long ASN1_STRING_get_default_mask(void); - -OPENSSL_EXPORT ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out, - const unsigned char *in, - int inlen, int inform, - int nid); -OPENSSL_EXPORT ASN1_STRING_TABLE *ASN1_STRING_TABLE_get(int nid); -OPENSSL_EXPORT int ASN1_STRING_TABLE_add(int, long, long, unsigned long, - unsigned long); -OPENSSL_EXPORT void ASN1_STRING_TABLE_cleanup(void); - -// ASN1 template functions - -// Old API compatible functions -OPENSSL_EXPORT ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it); -OPENSSL_EXPORT void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it); -OPENSSL_EXPORT ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **val, - const unsigned char **in, long len, - const ASN1_ITEM *it); -OPENSSL_EXPORT int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, - const ASN1_ITEM *it); - -OPENSSL_EXPORT ASN1_TYPE *ASN1_generate_nconf(const char *str, CONF *nconf); -OPENSSL_EXPORT ASN1_TYPE *ASN1_generate_v3(const char *str, X509V3_CTX *cnf); +// ASN1_PRINTABLE is an |ASN1_ITEM| whose ASN.1 type is a CHOICE of an ad-hoc +// subset of string-like types, and whose C type is |ASN1_STRING*|. +// +// Do not use this. Despite the name, it has no connection to PrintableString or +// printable characters. See https://crbug.com/boringssl/412. +DECLARE_ASN1_ITEM(ASN1_PRINTABLE) -#ifdef __cplusplus -} +#if defined(__cplusplus) +} // extern C extern "C++" { @@ -1290,5 +2034,6 @@ BSSL_NAMESPACE_END #define ASN1_R_WRONG_TYPE 191 #define ASN1_R_NESTED_TOO_DEEP 192 #define ASN1_R_BAD_TEMPLATE 193 +#define ASN1_R_INVALID_BIT_STRING_PADDING 194 #endif diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_asn1t.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_asn1t.h index 5f1d517a..d29c19e7 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_asn1t.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_asn1t.h @@ -72,6 +72,9 @@ extern "C" { * |CBB| library in instead. */ +typedef struct ASN1_TEMPLATE_st ASN1_TEMPLATE; +typedef struct ASN1_TLC_st ASN1_TLC; + /* Macro to obtain ASN1_ADB pointer from a type (only used internally) */ #define ASN1_ADB_ptr(iptr) ((const ASN1_ADB *)(iptr)) @@ -595,8 +598,8 @@ typedef struct ASN1_AUX_st { #define ASN1_OP_FREE_POST 3 #define ASN1_OP_D2I_PRE 4 #define ASN1_OP_D2I_POST 5 -#define ASN1_OP_I2D_PRE 6 -#define ASN1_OP_I2D_POST 7 +/* ASN1_OP_I2D_PRE and ASN1_OP_I2D_POST are not supported. We leave the + * constants undefined so code relying on them does not accidentally compile. */ #define ASN1_OP_PRINT_PRE 8 #define ASN1_OP_PRINT_POST 9 #define ASN1_OP_STREAM_PRE 10 @@ -705,9 +708,6 @@ typedef struct ASN1_AUX_st { /* external definitions for primitive types */ -DECLARE_ASN1_ITEM(ASN1_BOOLEAN) -DECLARE_ASN1_ITEM(ASN1_TBOOLEAN) -DECLARE_ASN1_ITEM(ASN1_FBOOLEAN) DECLARE_ASN1_ITEM(ASN1_SEQUENCE) DEFINE_STACK_OF(ASN1_VALUE) diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_base.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_base.h index 50a62104..5dfc13be 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_base.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_base.h @@ -336,8 +336,11 @@ enum ssl_verify_result_t BORINGSSL_ENUM_INT; // CRYPTO_THREADID is a dummy value. typedef int CRYPTO_THREADID; +// An |ASN1_NULL| is an opaque type. asn1.h represents the ASN.1 NULL value as +// an opaque, non-NULL |ASN1_NULL*| pointer. +typedef struct asn1_null_st ASN1_NULL; + typedef int ASN1_BOOLEAN; -typedef int ASN1_NULL; typedef struct ASN1_ITEM_st ASN1_ITEM; typedef struct asn1_object_st ASN1_OBJECT; typedef struct asn1_pctx_st ASN1_PCTX; @@ -381,7 +384,6 @@ typedef struct X509_name_st X509_NAME; typedef struct X509_pubkey_st X509_PUBKEY; typedef struct X509_req_st X509_REQ; typedef struct X509_sig_st X509_SIG; -typedef struct X509_val_st X509_VAL; typedef struct bignum_ctx BN_CTX; typedef struct bignum_st BIGNUM; typedef struct bio_method_st BIO_METHOD; @@ -430,6 +432,7 @@ typedef struct private_key_st X509_PKEY; typedef struct rand_meth_st RAND_METHOD; typedef struct rc4_key_st RC4_KEY; typedef struct rsa_meth_st RSA_METHOD; +typedef struct rsa_pss_params_st RSA_PSS_PARAMS; typedef struct rsa_st RSA; typedef struct sha256_state_st SHA256_CTX; typedef struct sha512_state_st SHA512_CTX; @@ -438,6 +441,7 @@ typedef struct spake2_ctx_st SPAKE2_CTX; typedef struct srtp_protection_profile_st SRTP_PROTECTION_PROFILE; typedef struct ssl_cipher_st SSL_CIPHER; typedef struct ssl_ctx_st SSL_CTX; +typedef struct ssl_early_callback_ctx SSL_CLIENT_HELLO; typedef struct ssl_ech_keys_st SSL_ECH_KEYS; typedef struct ssl_method_st SSL_METHOD; typedef struct ssl_private_key_method_st SSL_PRIVATE_KEY_METHOD; diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_bn.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_bn.h index 9313e2be..119a96ba 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_bn.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_bn.h @@ -687,9 +687,9 @@ OPENSSL_EXPORT int BN_generate_prime_ex(BIGNUM *ret, int bits, int safe, // BN_prime_checks_for_validation can be used as the |checks| argument to the // primarily testing functions when validating an externally-supplied candidate // prime. It gives a false positive rate of at most 2^{-128}. (The worst case -// false positive rate for a single iteration is 1/4, so we perform 32 -// iterations.) -#define BN_prime_checks_for_validation 32 +// false positive rate for a single iteration is 1/4 per +// https://eprint.iacr.org/2018/749. (1/4)^64 = 2^{-128}.) +#define BN_prime_checks_for_validation 64 // BN_prime_checks_for_generation can be used as the |checks| argument to the // primality testing functions when generating random primes. It gives a false diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_boringssl_prefix_symbols.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_boringssl_prefix_symbols.h index ce984b7f..c7fa2310 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_boringssl_prefix_symbols.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_boringssl_prefix_symbols.h @@ -102,7 +102,6 @@ #define ASN1_SET_ANY_it BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_SET_ANY_it) #define ASN1_STRING_TABLE_add BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_STRING_TABLE_add) #define ASN1_STRING_TABLE_cleanup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_STRING_TABLE_cleanup) -#define ASN1_STRING_TABLE_get BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_STRING_TABLE_get) #define ASN1_STRING_cmp BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_STRING_cmp) #define ASN1_STRING_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_STRING_copy) #define ASN1_STRING_data BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_STRING_data) @@ -162,7 +161,6 @@ #define ASN1_VISIBLESTRING_it BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_VISIBLESTRING_it) #define ASN1_VISIBLESTRING_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_VISIBLESTRING_new) #define ASN1_digest BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_digest) -#define ASN1_generate_nconf BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_generate_nconf) #define ASN1_generate_v3 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_generate_v3) #define ASN1_get_object BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_get_object) #define ASN1_item_d2i BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_item_d2i) @@ -548,6 +546,7 @@ #define CRYPTO_BUFFER_len BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_BUFFER_len) #define CRYPTO_BUFFER_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_BUFFER_new) #define CRYPTO_BUFFER_new_from_CBS BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_BUFFER_new_from_CBS) +#define CRYPTO_BUFFER_new_from_static_data_unsafe BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_BUFFER_new_from_static_data_unsafe) #define CRYPTO_BUFFER_up_ref BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_BUFFER_up_ref) #define CRYPTO_MUTEX_cleanup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_MUTEX_cleanup) #define CRYPTO_MUTEX_init BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_MUTEX_init) @@ -576,6 +575,7 @@ #define CRYPTO_ctr128_encrypt BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_ctr128_encrypt) #define CRYPTO_ctr128_encrypt_ctr32 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_ctr128_encrypt_ctr32) #define CRYPTO_fork_detect_ignore_madv_wipeonfork_for_testing BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_fork_detect_ignore_madv_wipeonfork_for_testing) +#define CRYPTO_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_free) #define CRYPTO_free_ex_data BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_free_ex_data) #define CRYPTO_gcm128_aad BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_gcm128_aad) #define CRYPTO_gcm128_decrypt BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_gcm128_decrypt) @@ -604,6 +604,7 @@ #define CRYPTO_is_NEON_capable_at_runtime BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_is_NEON_capable_at_runtime) #define CRYPTO_is_confidential_build BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_is_confidential_build) #define CRYPTO_library_init BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_library_init) +#define CRYPTO_malloc BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_malloc) #define CRYPTO_malloc_init BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_malloc_init) #define CRYPTO_memcmp BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_memcmp) #define CRYPTO_new_ex_data BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_new_ex_data) @@ -616,6 +617,7 @@ #define CRYPTO_pre_sandbox_init BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_pre_sandbox_init) #define CRYPTO_rdrand BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_rdrand) #define CRYPTO_rdrand_multiple8_buf BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_rdrand_multiple8_buf) +#define CRYPTO_realloc BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_realloc) #define CRYPTO_refcount_dec_and_test_zero BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_refcount_dec_and_test_zero) #define CRYPTO_refcount_inc BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_refcount_inc) #define CRYPTO_set_add_lock_callback BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_set_add_lock_callback) @@ -1523,6 +1525,7 @@ #define RSA_get0_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RSA_get0_key) #define RSA_get0_n BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RSA_get0_n) #define RSA_get0_p BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RSA_get0_p) +#define RSA_get0_pss_params BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RSA_get0_pss_params) #define RSA_get0_q BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RSA_get0_q) #define RSA_get_ex_data BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RSA_get_ex_data) #define RSA_get_ex_new_index BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RSA_get_ex_new_index) @@ -1965,7 +1968,6 @@ #define X509_STORE_get_verify_cb BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_get_verify_cb) #define X509_STORE_load_locations BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_load_locations) #define X509_STORE_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_new) -#define X509_STORE_set0_additional_untrusted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_set0_additional_untrusted) #define X509_STORE_set1_param BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_set1_param) #define X509_STORE_set_cert_crl BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_set_cert_crl) #define X509_STORE_set_check_crl BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_set_check_crl) @@ -2208,6 +2210,7 @@ #define aesgcmsiv_polyval_horner BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, aesgcmsiv_polyval_horner) #define aesni_gcm_decrypt BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, aesni_gcm_decrypt) #define aesni_gcm_encrypt BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, aesni_gcm_encrypt) +#define asn1_bit_string_length BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, asn1_bit_string_length) #define asn1_do_adb BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, asn1_do_adb) #define asn1_enc_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, asn1_enc_free) #define asn1_enc_init BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, asn1_enc_init) @@ -2216,6 +2219,7 @@ #define asn1_generalizedtime_to_tm BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, asn1_generalizedtime_to_tm) #define asn1_get_choice_selector BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, asn1_get_choice_selector) #define asn1_get_field_ptr BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, asn1_get_field_ptr) +#define asn1_get_string_table_for_testing BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, asn1_get_string_table_for_testing) #define asn1_is_printable BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, asn1_is_printable) #define asn1_item_combine_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, asn1_item_combine_free) #define asn1_refcount_dec_and_test_zero BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, asn1_refcount_dec_and_test_zero) @@ -2711,7 +2715,7 @@ #define pkcs12_iterations_acceptable BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, pkcs12_iterations_acceptable) #define pkcs12_key_gen BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, pkcs12_key_gen) #define pkcs12_pbe_encrypt_init BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, pkcs12_pbe_encrypt_init) -#define pkcs7_bundle BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, pkcs7_bundle) +#define pkcs7_add_signed_data BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, pkcs7_add_signed_data) #define pkcs7_parse_header BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, pkcs7_parse_header) #define pkcs8_pbe_decrypt BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, pkcs8_pbe_decrypt) #define pmbtoken_exp1_blind BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, pmbtoken_exp1_blind) @@ -2848,29 +2852,6 @@ #define x509v3_hex_to_bytes BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, x509v3_hex_to_bytes) #define x509v3_looks_like_dns_name BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, x509v3_looks_like_dns_name) #define x509v3_name_cmp BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, x509v3_name_cmp) -#define sk_ASN1_STRING_TABLE_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_STRING_TABLE_call_free_func) -#define sk_ASN1_STRING_TABLE_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_STRING_TABLE_call_copy_func) -#define sk_ASN1_STRING_TABLE_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_STRING_TABLE_call_cmp_func) -#define sk_ASN1_STRING_TABLE_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_STRING_TABLE_new) -#define sk_ASN1_STRING_TABLE_new_null BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_STRING_TABLE_new_null) -#define sk_ASN1_STRING_TABLE_num BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_STRING_TABLE_num) -#define sk_ASN1_STRING_TABLE_zero BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_STRING_TABLE_zero) -#define sk_ASN1_STRING_TABLE_value BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_STRING_TABLE_value) -#define sk_ASN1_STRING_TABLE_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_STRING_TABLE_set) -#define sk_ASN1_STRING_TABLE_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_STRING_TABLE_free) -#define sk_ASN1_STRING_TABLE_pop_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_STRING_TABLE_pop_free) -#define sk_ASN1_STRING_TABLE_insert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_STRING_TABLE_insert) -#define sk_ASN1_STRING_TABLE_delete BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_STRING_TABLE_delete) -#define sk_ASN1_STRING_TABLE_delete_ptr BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_STRING_TABLE_delete_ptr) -#define sk_ASN1_STRING_TABLE_find BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_STRING_TABLE_find) -#define sk_ASN1_STRING_TABLE_shift BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_STRING_TABLE_shift) -#define sk_ASN1_STRING_TABLE_push BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_STRING_TABLE_push) -#define sk_ASN1_STRING_TABLE_pop BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_STRING_TABLE_pop) -#define sk_ASN1_STRING_TABLE_dup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_STRING_TABLE_dup) -#define sk_ASN1_STRING_TABLE_sort BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_STRING_TABLE_sort) -#define sk_ASN1_STRING_TABLE_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_STRING_TABLE_is_sorted) -#define sk_ASN1_STRING_TABLE_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_STRING_TABLE_set_cmp_func) -#define sk_ASN1_STRING_TABLE_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_STRING_TABLE_deep_copy) #define sk_TRUST_TOKEN_PRETOKEN_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_TRUST_TOKEN_PRETOKEN_call_free_func) #define sk_TRUST_TOKEN_PRETOKEN_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_TRUST_TOKEN_PRETOKEN_call_copy_func) #define sk_TRUST_TOKEN_PRETOKEN_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_TRUST_TOKEN_PRETOKEN_call_cmp_func) @@ -3262,6 +3243,75 @@ #define sk_X509_INFO_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_is_sorted) #define sk_X509_INFO_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_set_cmp_func) #define sk_X509_INFO_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_deep_copy) +#define sk_X509_LOOKUP_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_call_free_func) +#define sk_X509_LOOKUP_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_call_copy_func) +#define sk_X509_LOOKUP_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_call_cmp_func) +#define sk_X509_LOOKUP_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_new) +#define sk_X509_LOOKUP_new_null BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_new_null) +#define sk_X509_LOOKUP_num BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_num) +#define sk_X509_LOOKUP_zero BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_zero) +#define sk_X509_LOOKUP_value BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_value) +#define sk_X509_LOOKUP_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_set) +#define sk_X509_LOOKUP_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_free) +#define sk_X509_LOOKUP_pop_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_pop_free) +#define sk_X509_LOOKUP_insert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_insert) +#define sk_X509_LOOKUP_delete BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_delete) +#define sk_X509_LOOKUP_delete_ptr BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_delete_ptr) +#define sk_X509_LOOKUP_find BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_find) +#define sk_X509_LOOKUP_shift BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_shift) +#define sk_X509_LOOKUP_push BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_push) +#define sk_X509_LOOKUP_pop BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_pop) +#define sk_X509_LOOKUP_dup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_dup) +#define sk_X509_LOOKUP_sort BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_sort) +#define sk_X509_LOOKUP_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_is_sorted) +#define sk_X509_LOOKUP_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_set_cmp_func) +#define sk_X509_LOOKUP_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_deep_copy) +#define sk_X509_OBJECT_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_call_free_func) +#define sk_X509_OBJECT_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_call_copy_func) +#define sk_X509_OBJECT_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_call_cmp_func) +#define sk_X509_OBJECT_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_new) +#define sk_X509_OBJECT_new_null BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_new_null) +#define sk_X509_OBJECT_num BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_num) +#define sk_X509_OBJECT_zero BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_zero) +#define sk_X509_OBJECT_value BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_value) +#define sk_X509_OBJECT_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_set) +#define sk_X509_OBJECT_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_free) +#define sk_X509_OBJECT_pop_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_pop_free) +#define sk_X509_OBJECT_insert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_insert) +#define sk_X509_OBJECT_delete BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_delete) +#define sk_X509_OBJECT_delete_ptr BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_delete_ptr) +#define sk_X509_OBJECT_find BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_find) +#define sk_X509_OBJECT_shift BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_shift) +#define sk_X509_OBJECT_push BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_push) +#define sk_X509_OBJECT_pop BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_pop) +#define sk_X509_OBJECT_dup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_dup) +#define sk_X509_OBJECT_sort BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_sort) +#define sk_X509_OBJECT_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_is_sorted) +#define sk_X509_OBJECT_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_set_cmp_func) +#define sk_X509_OBJECT_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_deep_copy) +#define sk_X509_VERIFY_PARAM_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_call_free_func) +#define sk_X509_VERIFY_PARAM_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_call_copy_func) +#define sk_X509_VERIFY_PARAM_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_call_cmp_func) +#define sk_X509_VERIFY_PARAM_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_new) +#define sk_X509_VERIFY_PARAM_new_null BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_new_null) +#define sk_X509_VERIFY_PARAM_num BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_num) +#define sk_X509_VERIFY_PARAM_zero BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_zero) +#define sk_X509_VERIFY_PARAM_value BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_value) +#define sk_X509_VERIFY_PARAM_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_set) +#define sk_X509_VERIFY_PARAM_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_free) +#define sk_X509_VERIFY_PARAM_pop_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_pop_free) +#define sk_X509_VERIFY_PARAM_insert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_insert) +#define sk_X509_VERIFY_PARAM_delete BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_delete) +#define sk_X509_VERIFY_PARAM_delete_ptr BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_delete_ptr) +#define sk_X509_VERIFY_PARAM_find BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_find) +#define sk_X509_VERIFY_PARAM_shift BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_shift) +#define sk_X509_VERIFY_PARAM_push BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_push) +#define sk_X509_VERIFY_PARAM_pop BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_pop) +#define sk_X509_VERIFY_PARAM_dup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_dup) +#define sk_X509_VERIFY_PARAM_sort BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_sort) +#define sk_X509_VERIFY_PARAM_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_is_sorted) +#define sk_X509_VERIFY_PARAM_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_set_cmp_func) +#define sk_X509_VERIFY_PARAM_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_deep_copy) #define sk_CRYPTO_BUFFER_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_CRYPTO_BUFFER_call_free_func) #define sk_CRYPTO_BUFFER_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_CRYPTO_BUFFER_call_copy_func) #define sk_CRYPTO_BUFFER_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_CRYPTO_BUFFER_call_cmp_func) @@ -3285,29 +3335,6 @@ #define sk_CRYPTO_BUFFER_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_CRYPTO_BUFFER_is_sorted) #define sk_CRYPTO_BUFFER_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_CRYPTO_BUFFER_set_cmp_func) #define sk_CRYPTO_BUFFER_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_CRYPTO_BUFFER_deep_copy) -#define sk_ASN1_OBJECT_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_call_free_func) -#define sk_ASN1_OBJECT_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_call_copy_func) -#define sk_ASN1_OBJECT_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_call_cmp_func) -#define sk_ASN1_OBJECT_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_new) -#define sk_ASN1_OBJECT_new_null BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_new_null) -#define sk_ASN1_OBJECT_num BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_num) -#define sk_ASN1_OBJECT_zero BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_zero) -#define sk_ASN1_OBJECT_value BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_value) -#define sk_ASN1_OBJECT_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_set) -#define sk_ASN1_OBJECT_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_free) -#define sk_ASN1_OBJECT_pop_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_pop_free) -#define sk_ASN1_OBJECT_insert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_insert) -#define sk_ASN1_OBJECT_delete BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_delete) -#define sk_ASN1_OBJECT_delete_ptr BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_delete_ptr) -#define sk_ASN1_OBJECT_find BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_find) -#define sk_ASN1_OBJECT_shift BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_shift) -#define sk_ASN1_OBJECT_push BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_push) -#define sk_ASN1_OBJECT_pop BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_pop) -#define sk_ASN1_OBJECT_dup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_dup) -#define sk_ASN1_OBJECT_sort BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_sort) -#define sk_ASN1_OBJECT_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_is_sorted) -#define sk_ASN1_OBJECT_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_set_cmp_func) -#define sk_ASN1_OBJECT_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_deep_copy) #define sk_ASN1_INTEGER_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_INTEGER_call_free_func) #define sk_ASN1_INTEGER_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_INTEGER_call_copy_func) #define sk_ASN1_INTEGER_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_INTEGER_call_cmp_func) @@ -3331,6 +3358,29 @@ #define sk_ASN1_INTEGER_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_INTEGER_is_sorted) #define sk_ASN1_INTEGER_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_INTEGER_set_cmp_func) #define sk_ASN1_INTEGER_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_INTEGER_deep_copy) +#define sk_ASN1_OBJECT_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_call_free_func) +#define sk_ASN1_OBJECT_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_call_copy_func) +#define sk_ASN1_OBJECT_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_call_cmp_func) +#define sk_ASN1_OBJECT_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_new) +#define sk_ASN1_OBJECT_new_null BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_new_null) +#define sk_ASN1_OBJECT_num BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_num) +#define sk_ASN1_OBJECT_zero BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_zero) +#define sk_ASN1_OBJECT_value BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_value) +#define sk_ASN1_OBJECT_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_set) +#define sk_ASN1_OBJECT_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_free) +#define sk_ASN1_OBJECT_pop_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_pop_free) +#define sk_ASN1_OBJECT_insert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_insert) +#define sk_ASN1_OBJECT_delete BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_delete) +#define sk_ASN1_OBJECT_delete_ptr BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_delete_ptr) +#define sk_ASN1_OBJECT_find BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_find) +#define sk_ASN1_OBJECT_shift BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_shift) +#define sk_ASN1_OBJECT_push BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_push) +#define sk_ASN1_OBJECT_pop BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_pop) +#define sk_ASN1_OBJECT_dup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_dup) +#define sk_ASN1_OBJECT_sort BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_sort) +#define sk_ASN1_OBJECT_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_is_sorted) +#define sk_ASN1_OBJECT_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_set_cmp_func) +#define sk_ASN1_OBJECT_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_OBJECT_deep_copy) #define sk_ASN1_TYPE_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_TYPE_call_free_func) #define sk_ASN1_TYPE_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_TYPE_call_copy_func) #define sk_ASN1_TYPE_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_TYPE_call_cmp_func) @@ -3653,75 +3703,6 @@ #define sk_CONF_VALUE_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_CONF_VALUE_is_sorted) #define sk_CONF_VALUE_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_CONF_VALUE_set_cmp_func) #define sk_CONF_VALUE_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_CONF_VALUE_deep_copy) -#define sk_X509_LOOKUP_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_call_free_func) -#define sk_X509_LOOKUP_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_call_copy_func) -#define sk_X509_LOOKUP_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_call_cmp_func) -#define sk_X509_LOOKUP_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_new) -#define sk_X509_LOOKUP_new_null BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_new_null) -#define sk_X509_LOOKUP_num BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_num) -#define sk_X509_LOOKUP_zero BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_zero) -#define sk_X509_LOOKUP_value BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_value) -#define sk_X509_LOOKUP_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_set) -#define sk_X509_LOOKUP_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_free) -#define sk_X509_LOOKUP_pop_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_pop_free) -#define sk_X509_LOOKUP_insert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_insert) -#define sk_X509_LOOKUP_delete BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_delete) -#define sk_X509_LOOKUP_delete_ptr BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_delete_ptr) -#define sk_X509_LOOKUP_find BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_find) -#define sk_X509_LOOKUP_shift BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_shift) -#define sk_X509_LOOKUP_push BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_push) -#define sk_X509_LOOKUP_pop BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_pop) -#define sk_X509_LOOKUP_dup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_dup) -#define sk_X509_LOOKUP_sort BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_sort) -#define sk_X509_LOOKUP_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_is_sorted) -#define sk_X509_LOOKUP_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_set_cmp_func) -#define sk_X509_LOOKUP_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_deep_copy) -#define sk_X509_OBJECT_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_call_free_func) -#define sk_X509_OBJECT_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_call_copy_func) -#define sk_X509_OBJECT_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_call_cmp_func) -#define sk_X509_OBJECT_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_new) -#define sk_X509_OBJECT_new_null BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_new_null) -#define sk_X509_OBJECT_num BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_num) -#define sk_X509_OBJECT_zero BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_zero) -#define sk_X509_OBJECT_value BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_value) -#define sk_X509_OBJECT_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_set) -#define sk_X509_OBJECT_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_free) -#define sk_X509_OBJECT_pop_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_pop_free) -#define sk_X509_OBJECT_insert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_insert) -#define sk_X509_OBJECT_delete BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_delete) -#define sk_X509_OBJECT_delete_ptr BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_delete_ptr) -#define sk_X509_OBJECT_find BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_find) -#define sk_X509_OBJECT_shift BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_shift) -#define sk_X509_OBJECT_push BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_push) -#define sk_X509_OBJECT_pop BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_pop) -#define sk_X509_OBJECT_dup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_dup) -#define sk_X509_OBJECT_sort BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_sort) -#define sk_X509_OBJECT_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_is_sorted) -#define sk_X509_OBJECT_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_set_cmp_func) -#define sk_X509_OBJECT_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_deep_copy) -#define sk_X509_VERIFY_PARAM_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_call_free_func) -#define sk_X509_VERIFY_PARAM_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_call_copy_func) -#define sk_X509_VERIFY_PARAM_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_call_cmp_func) -#define sk_X509_VERIFY_PARAM_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_new) -#define sk_X509_VERIFY_PARAM_new_null BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_new_null) -#define sk_X509_VERIFY_PARAM_num BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_num) -#define sk_X509_VERIFY_PARAM_zero BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_zero) -#define sk_X509_VERIFY_PARAM_value BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_value) -#define sk_X509_VERIFY_PARAM_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_set) -#define sk_X509_VERIFY_PARAM_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_free) -#define sk_X509_VERIFY_PARAM_pop_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_pop_free) -#define sk_X509_VERIFY_PARAM_insert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_insert) -#define sk_X509_VERIFY_PARAM_delete BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_delete) -#define sk_X509_VERIFY_PARAM_delete_ptr BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_delete_ptr) -#define sk_X509_VERIFY_PARAM_find BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_find) -#define sk_X509_VERIFY_PARAM_shift BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_shift) -#define sk_X509_VERIFY_PARAM_push BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_push) -#define sk_X509_VERIFY_PARAM_pop BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_pop) -#define sk_X509_VERIFY_PARAM_dup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_dup) -#define sk_X509_VERIFY_PARAM_sort BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_sort) -#define sk_X509_VERIFY_PARAM_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_is_sorted) -#define sk_X509_VERIFY_PARAM_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_set_cmp_func) -#define sk_X509_VERIFY_PARAM_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_VERIFY_PARAM_deep_copy) #define sk_void_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_void_call_free_func) #define sk_void_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_void_call_copy_func) #define sk_void_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_void_call_cmp_func) @@ -3814,6 +3795,20 @@ #define sk_ASN1_VALUE_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_VALUE_is_sorted) #define sk_ASN1_VALUE_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_VALUE_set_cmp_func) #define sk_ASN1_VALUE_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ASN1_VALUE_deep_copy) +#define lh_ASN1_STRING_TABLE_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, lh_ASN1_STRING_TABLE_call_cmp_func) +#define lh_ASN1_STRING_TABLE_call_hash_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, lh_ASN1_STRING_TABLE_call_hash_func) +#define lh_ASN1_STRING_TABLE_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, lh_ASN1_STRING_TABLE_new) +#define lh_ASN1_STRING_TABLE_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, lh_ASN1_STRING_TABLE_free) +#define lh_ASN1_STRING_TABLE_num_items BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, lh_ASN1_STRING_TABLE_num_items) +#define lh_ASN1_STRING_TABLE_retrieve BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, lh_ASN1_STRING_TABLE_retrieve) +#define lh_ASN1_STRING_TABLE_call_cmp_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, lh_ASN1_STRING_TABLE_call_cmp_key) +#define lh_ASN1_STRING_TABLE_retrieve_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, lh_ASN1_STRING_TABLE_retrieve_key) +#define lh_ASN1_STRING_TABLE_insert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, lh_ASN1_STRING_TABLE_insert) +#define lh_ASN1_STRING_TABLE_delete BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, lh_ASN1_STRING_TABLE_delete) +#define lh_ASN1_STRING_TABLE_call_doall BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, lh_ASN1_STRING_TABLE_call_doall) +#define lh_ASN1_STRING_TABLE_call_doall_arg BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, lh_ASN1_STRING_TABLE_call_doall_arg) +#define lh_ASN1_STRING_TABLE_doall BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, lh_ASN1_STRING_TABLE_doall) +#define lh_ASN1_STRING_TABLE_doall_arg BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, lh_ASN1_STRING_TABLE_doall_arg) #define lh_ASN1_OBJECT_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, lh_ASN1_OBJECT_call_cmp_func) #define lh_ASN1_OBJECT_call_hash_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, lh_ASN1_OBJECT_call_hash_func) #define lh_ASN1_OBJECT_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, lh_ASN1_OBJECT_new) diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_boringssl_prefix_symbols_asm.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_boringssl_prefix_symbols_asm.h index 6b14d955..17e8a0be 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_boringssl_prefix_symbols_asm.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_boringssl_prefix_symbols_asm.h @@ -107,7 +107,6 @@ #define _ASN1_SET_ANY_it BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_SET_ANY_it) #define _ASN1_STRING_TABLE_add BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_STRING_TABLE_add) #define _ASN1_STRING_TABLE_cleanup BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_STRING_TABLE_cleanup) -#define _ASN1_STRING_TABLE_get BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_STRING_TABLE_get) #define _ASN1_STRING_cmp BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_STRING_cmp) #define _ASN1_STRING_copy BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_STRING_copy) #define _ASN1_STRING_data BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_STRING_data) @@ -167,7 +166,6 @@ #define _ASN1_VISIBLESTRING_it BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_VISIBLESTRING_it) #define _ASN1_VISIBLESTRING_new BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_VISIBLESTRING_new) #define _ASN1_digest BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_digest) -#define _ASN1_generate_nconf BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_generate_nconf) #define _ASN1_generate_v3 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_generate_v3) #define _ASN1_get_object BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_get_object) #define _ASN1_item_d2i BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_item_d2i) @@ -553,6 +551,7 @@ #define _CRYPTO_BUFFER_len BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_BUFFER_len) #define _CRYPTO_BUFFER_new BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_BUFFER_new) #define _CRYPTO_BUFFER_new_from_CBS BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_BUFFER_new_from_CBS) +#define _CRYPTO_BUFFER_new_from_static_data_unsafe BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_BUFFER_new_from_static_data_unsafe) #define _CRYPTO_BUFFER_up_ref BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_BUFFER_up_ref) #define _CRYPTO_MUTEX_cleanup BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_MUTEX_cleanup) #define _CRYPTO_MUTEX_init BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_MUTEX_init) @@ -581,6 +580,7 @@ #define _CRYPTO_ctr128_encrypt BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_ctr128_encrypt) #define _CRYPTO_ctr128_encrypt_ctr32 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_ctr128_encrypt_ctr32) #define _CRYPTO_fork_detect_ignore_madv_wipeonfork_for_testing BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_fork_detect_ignore_madv_wipeonfork_for_testing) +#define _CRYPTO_free BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_free) #define _CRYPTO_free_ex_data BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_free_ex_data) #define _CRYPTO_gcm128_aad BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_gcm128_aad) #define _CRYPTO_gcm128_decrypt BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_gcm128_decrypt) @@ -609,6 +609,7 @@ #define _CRYPTO_is_NEON_capable_at_runtime BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_is_NEON_capable_at_runtime) #define _CRYPTO_is_confidential_build BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_is_confidential_build) #define _CRYPTO_library_init BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_library_init) +#define _CRYPTO_malloc BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_malloc) #define _CRYPTO_malloc_init BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_malloc_init) #define _CRYPTO_memcmp BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_memcmp) #define _CRYPTO_new_ex_data BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_new_ex_data) @@ -621,6 +622,7 @@ #define _CRYPTO_pre_sandbox_init BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_pre_sandbox_init) #define _CRYPTO_rdrand BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_rdrand) #define _CRYPTO_rdrand_multiple8_buf BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_rdrand_multiple8_buf) +#define _CRYPTO_realloc BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_realloc) #define _CRYPTO_refcount_dec_and_test_zero BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_refcount_dec_and_test_zero) #define _CRYPTO_refcount_inc BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_refcount_inc) #define _CRYPTO_set_add_lock_callback BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_set_add_lock_callback) @@ -1528,6 +1530,7 @@ #define _RSA_get0_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RSA_get0_key) #define _RSA_get0_n BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RSA_get0_n) #define _RSA_get0_p BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RSA_get0_p) +#define _RSA_get0_pss_params BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RSA_get0_pss_params) #define _RSA_get0_q BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RSA_get0_q) #define _RSA_get_ex_data BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RSA_get_ex_data) #define _RSA_get_ex_new_index BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RSA_get_ex_new_index) @@ -1970,7 +1973,6 @@ #define _X509_STORE_get_verify_cb BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_get_verify_cb) #define _X509_STORE_load_locations BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_load_locations) #define _X509_STORE_new BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_new) -#define _X509_STORE_set0_additional_untrusted BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_set0_additional_untrusted) #define _X509_STORE_set1_param BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_set1_param) #define _X509_STORE_set_cert_crl BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_set_cert_crl) #define _X509_STORE_set_check_crl BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_set_check_crl) @@ -2213,6 +2215,7 @@ #define _aesgcmsiv_polyval_horner BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, aesgcmsiv_polyval_horner) #define _aesni_gcm_decrypt BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, aesni_gcm_decrypt) #define _aesni_gcm_encrypt BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, aesni_gcm_encrypt) +#define _asn1_bit_string_length BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, asn1_bit_string_length) #define _asn1_do_adb BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, asn1_do_adb) #define _asn1_enc_free BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, asn1_enc_free) #define _asn1_enc_init BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, asn1_enc_init) @@ -2221,6 +2224,7 @@ #define _asn1_generalizedtime_to_tm BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, asn1_generalizedtime_to_tm) #define _asn1_get_choice_selector BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, asn1_get_choice_selector) #define _asn1_get_field_ptr BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, asn1_get_field_ptr) +#define _asn1_get_string_table_for_testing BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, asn1_get_string_table_for_testing) #define _asn1_is_printable BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, asn1_is_printable) #define _asn1_item_combine_free BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, asn1_item_combine_free) #define _asn1_refcount_dec_and_test_zero BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, asn1_refcount_dec_and_test_zero) @@ -2716,7 +2720,7 @@ #define _pkcs12_iterations_acceptable BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, pkcs12_iterations_acceptable) #define _pkcs12_key_gen BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, pkcs12_key_gen) #define _pkcs12_pbe_encrypt_init BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, pkcs12_pbe_encrypt_init) -#define _pkcs7_bundle BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, pkcs7_bundle) +#define _pkcs7_add_signed_data BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, pkcs7_add_signed_data) #define _pkcs7_parse_header BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, pkcs7_parse_header) #define _pkcs8_pbe_decrypt BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, pkcs8_pbe_decrypt) #define _pmbtoken_exp1_blind BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, pmbtoken_exp1_blind) diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_cipher.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_cipher.h index 07c4095a..6c9aba30 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_cipher.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_cipher.h @@ -106,7 +106,10 @@ OPENSSL_EXPORT const EVP_CIPHER *EVP_rc2_cbc(void); const EVP_CIPHER *EVP_rc2_40_cbc(void); // EVP_get_cipherbynid returns the cipher corresponding to the given NID, or -// NULL if no such cipher is known. +// NULL if no such cipher is known. Note using this function links almost every +// cipher implemented by BoringSSL into the binary, whether the caller uses them +// or not. Size-conscious callers, such as client software, should not use this +// function. OPENSSL_EXPORT const EVP_CIPHER *EVP_get_cipherbynid(int nid); @@ -409,7 +412,10 @@ OPENSSL_EXPORT int EVP_DecryptInit(EVP_CIPHER_CTX *ctx, OPENSSL_EXPORT int EVP_add_cipher_alias(const char *a, const char *b); // EVP_get_cipherbyname returns an |EVP_CIPHER| given a human readable name in -// |name|, or NULL if the name is unknown. +// |name|, or NULL if the name is unknown. Note using this function links almost +// every cipher implemented by BoringSSL into the binary, not just the ones the +// caller requests. Size-conscious callers, such as client software, should not +// use this function. OPENSSL_EXPORT const EVP_CIPHER *EVP_get_cipherbyname(const char *name); // These AEADs are deprecated AES-GCM implementations that set diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_dh.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_dh.h index 4ef5778e..eff77c5c 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_dh.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_dh.h @@ -267,22 +267,14 @@ OPENSSL_EXPORT DH *DH_generate_parameters(int prime_len, int generator, void (*callback)(int, int, void *), void *cb_arg); -// d2i_DHparams parses an ASN.1, DER encoded Diffie-Hellman parameters structure -// from |len| bytes at |*inp|. If |ret| is not NULL then, on exit, a pointer to -// the result is in |*ret|. Note that, even if |*ret| is already non-NULL on -// entry, it will not be written to. Rather, a fresh |DH| is allocated and the -// previous one is freed. -// -// On successful exit, |*inp| is advanced past the DER structure. It -// returns the result or NULL on error. +// d2i_DHparams parses a DER-encoded DHParameter structure (PKCS #3) from |len| +// bytes at |*inp|, as in |d2i_SAMPLE|. // // Use |DH_parse_parameters| instead. OPENSSL_EXPORT DH *d2i_DHparams(DH **ret, const unsigned char **inp, long len); -// i2d_DHparams marshals |in| to an ASN.1, DER structure. If |outp| is not NULL -// then the result is written to |*outp| and |*outp| is advanced just past the -// output. It returns the number of bytes in the result, whether written or -// not, or a negative value on error. +// i2d_DHparams marshals |in| to a DER-encoded DHParameter structure (PKCS #3), +// as described in |i2d_SAMPLE|. // // Use |DH_marshal_parameters| instead. OPENSSL_EXPORT int i2d_DHparams(const DH *in, unsigned char **outp); diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_dsa.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_dsa.h index 5da0e953..2960f4ef 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_dsa.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_dsa.h @@ -299,7 +299,7 @@ OPENSSL_EXPORT int DSA_marshal_private_key(CBB *cbb, const DSA *dsa); OPENSSL_EXPORT DSA *DSA_parse_parameters(CBS *cbs); // DSA_marshal_parameters marshals |dsa| as a DER-encoded Dss-Parms structure -// (RFC 3447) and appends the result to |cbb|. It returns one on success and +// (RFC 3279) and appends the result to |cbb|. It returns one on success and // zero on failure. OPENSSL_EXPORT int DSA_marshal_parameters(CBB *cbb, const DSA *dsa); @@ -326,75 +326,51 @@ OPENSSL_EXPORT void *DSA_get_ex_data(const DSA *dsa, int idx); // Deprecated functions. -// d2i_DSA_SIG parses an ASN.1, DER-encoded, DSA signature from |len| bytes at -// |*inp|. If |out_sig| is not NULL then, on exit, a pointer to the result is -// in |*out_sig|. Note that, even if |*out_sig| is already non-NULL on entry, it -// will not be written to. Rather, a fresh |DSA_SIG| is allocated and the -// previous one is freed. On successful exit, |*inp| is advanced past the DER -// structure. It returns the result or NULL on error. +// d2i_DSA_SIG parses a DER-encoded DSA-Sig-Value structure from |len| bytes at +// |*inp|, as described in |d2i_SAMPLE|. // // Use |DSA_SIG_parse| instead. OPENSSL_EXPORT DSA_SIG *d2i_DSA_SIG(DSA_SIG **out_sig, const uint8_t **inp, long len); -// i2d_DSA_SIG marshals |in| to an ASN.1, DER structure. If |outp| is not NULL -// then the result is written to |*outp| and |*outp| is advanced just past the -// output. It returns the number of bytes in the result, whether written or not, -// or a negative value on error. +// i2d_DSA_SIG marshals |in| to a DER-encoded DSA-Sig-Value structure, as +// described in |i2d_SAMPLE|. // // Use |DSA_SIG_marshal| instead. OPENSSL_EXPORT int i2d_DSA_SIG(const DSA_SIG *in, uint8_t **outp); -// d2i_DSAPublicKey parses an ASN.1, DER-encoded, DSA public key from |len| -// bytes at |*inp|. If |out| is not NULL then, on exit, a pointer to the result -// is in |*out|. Note that, even if |*ou| is already non-NULL on entry, it will -// not be written to. Rather, a fresh |DSA| is allocated and the previous one is -// freed. On successful exit, |*inp| is advanced past the DER structure. It -// returns the result or NULL on error. +// d2i_DSAPublicKey parses a DER-encoded DSA public key from |len| bytes at +// |*inp|, as described in |d2i_SAMPLE|. // // Use |DSA_parse_public_key| instead. OPENSSL_EXPORT DSA *d2i_DSAPublicKey(DSA **out, const uint8_t **inp, long len); -// i2d_DSAPublicKey marshals a public key from |in| to an ASN.1, DER structure. -// If |outp| is not NULL then the result is written to |*outp| and |*outp| is -// advanced just past the output. It returns the number of bytes in the result, -// whether written or not, or a negative value on error. +// i2d_DSAPublicKey marshals |in| as a DER-encoded DSA public key, as described +// in |i2d_SAMPLE|. // // Use |DSA_marshal_public_key| instead. OPENSSL_EXPORT int i2d_DSAPublicKey(const DSA *in, uint8_t **outp); -// d2i_DSAPrivateKey parses an ASN.1, DER-encoded, DSA private key from |len| -// bytes at |*inp|. If |out| is not NULL then, on exit, a pointer to the result -// is in |*out|. Note that, even if |*out| is already non-NULL on entry, it will -// not be written to. Rather, a fresh |DSA| is allocated and the previous one is -// freed. On successful exit, |*inp| is advanced past the DER structure. It -// returns the result or NULL on error. +// d2i_DSAPrivateKey parses a DER-encoded DSA private key from |len| bytes at +// |*inp|, as described in |d2i_SAMPLE|. // // Use |DSA_parse_private_key| instead. OPENSSL_EXPORT DSA *d2i_DSAPrivateKey(DSA **out, const uint8_t **inp, long len); -// i2d_DSAPrivateKey marshals a private key from |in| to an ASN.1, DER -// structure. If |outp| is not NULL then the result is written to |*outp| and -// |*outp| is advanced just past the output. It returns the number of bytes in -// the result, whether written or not, or a negative value on error. +// i2d_DSAPrivateKey marshals |in| as a DER-encoded DSA private key, as +// described in |i2d_SAMPLE|. // // Use |DSA_marshal_private_key| instead. OPENSSL_EXPORT int i2d_DSAPrivateKey(const DSA *in, uint8_t **outp); -// d2i_DSAparams parses ASN.1, DER-encoded, DSA parameters from |len| bytes at -// |*inp|. If |out| is not NULL then, on exit, a pointer to the result is in -// |*out|. Note that, even if |*out| is already non-NULL on entry, it will not -// be written to. Rather, a fresh |DSA| is allocated and the previous one is -// freed. On successful exit, |*inp| is advanced past the DER structure. It -// returns the result or NULL on error. +// d2i_DSAparams parses a DER-encoded Dss-Parms structure (RFC 3279) from |len| +// bytes at |*inp|, as described in |d2i_SAMPLE|. // // Use |DSA_parse_parameters| instead. OPENSSL_EXPORT DSA *d2i_DSAparams(DSA **out, const uint8_t **inp, long len); -// i2d_DSAparams marshals DSA parameters from |in| to an ASN.1, DER structure. -// If |outp| is not NULL then the result is written to |*outp| and |*outp| is -// advanced just past the output. It returns the number of bytes in the result, -// whether written or not, or a negative value on error. +// i2d_DSAparams marshals |in|'s parameters as a DER-encoded Dss-Parms structure +// (RFC 3279), as described in |i2d_SAMPLE|. // // Use |DSA_marshal_parameters| instead. OPENSSL_EXPORT int i2d_DSAparams(const DSA *in, uint8_t **outp); diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_ec_key.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_ec_key.h index 8c19597f..766ea475 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_ec_key.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_ec_key.h @@ -294,43 +294,30 @@ struct ecdsa_method_st { // EC_KEY_set_asn1_flag does nothing. OPENSSL_EXPORT void EC_KEY_set_asn1_flag(EC_KEY *key, int flag); -// d2i_ECPrivateKey parses an ASN.1, DER-encoded, private key from |len| bytes -// at |*inp|. If |out_key| is not NULL then, on exit, a pointer to the result -// is in |*out_key|. Note that, even if |*out_key| is already non-NULL on entry, -// it * will not be written to. Rather, a fresh |EC_KEY| is allocated and the -// previous * one is freed. On successful exit, |*inp| is advanced past the DER -// structure. It returns the result or NULL on error. -// -// On input, if |*out_key| is non-NULL and has a group configured, the -// parameters field may be omitted but must match that group if present. +// d2i_ECPrivateKey parses a DER-encoded ECPrivateKey structure (RFC 5915) from +// |len| bytes at |*inp|, as described in |d2i_SAMPLE|. On input, if |*out_key| +// is non-NULL and has a group configured, the parameters field may be omitted +// but must match that group if present. // // Use |EC_KEY_parse_private_key| instead. OPENSSL_EXPORT EC_KEY *d2i_ECPrivateKey(EC_KEY **out_key, const uint8_t **inp, long len); -// i2d_ECPrivateKey marshals an EC private key from |key| to an ASN.1, DER -// structure. If |outp| is not NULL then the result is written to |*outp| and -// |*outp| is advanced just past the output. It returns the number of bytes in -// the result, whether written or not, or a negative value on error. +// i2d_ECPrivateKey marshals |key| as a DER-encoded ECPrivateKey structure (RFC +// 5915), as described in |i2d_SAMPLE|. // // Use |EC_KEY_marshal_private_key| instead. OPENSSL_EXPORT int i2d_ECPrivateKey(const EC_KEY *key, uint8_t **outp); -// d2i_ECParameters parses an ASN.1, DER-encoded, set of EC parameters from -// |len| bytes at |*inp|. If |out_key| is not NULL then, on exit, a pointer to -// the result is in |*out_key|. Note that, even if |*out_key| is already -// non-NULL on entry, it will not be written to. Rather, a fresh |EC_KEY| is -// allocated and the previous one is freed. On successful exit, |*inp| is -// advanced past the DER structure. It returns the result or NULL on error. +// d2i_ECParameters parses a DER-encoded ECParameters structure (RFC 5480) from +// |len| bytes at |*inp|, as described in |d2i_SAMPLE|. // // Use |EC_KEY_parse_parameters| or |EC_KEY_parse_curve_name| instead. OPENSSL_EXPORT EC_KEY *d2i_ECParameters(EC_KEY **out_key, const uint8_t **inp, long len); -// i2d_ECParameters marshals EC parameters from |key| to an ASN.1, DER -// structure. If |outp| is not NULL then the result is written to |*outp| and -// |*outp| is advanced just past the output. It returns the number of bytes in -// the result, whether written or not, or a negative value on error. +// i2d_ECParameters marshals |key|'s parameters as a DER-encoded OBJECT +// IDENTIFIER, as described in |i2d_SAMPLE|. // // Use |EC_KEY_marshal_curve_name| instead. OPENSSL_EXPORT int i2d_ECParameters(const EC_KEY *key, uint8_t **outp); @@ -344,10 +331,8 @@ OPENSSL_EXPORT int i2d_ECParameters(const EC_KEY *key, uint8_t **outp); OPENSSL_EXPORT EC_KEY *o2i_ECPublicKey(EC_KEY **out_key, const uint8_t **inp, long len); -// i2o_ECPublicKey marshals an EC point from |key|. If |outp| is not NULL then -// the result is written to |*outp| and |*outp| is advanced just past the -// output. It returns the number of bytes in the result, whether written or -// not, or a negative value on error. +// i2o_ECPublicKey marshals an EC point from |key|, as described in +// |i2d_SAMPLE|. // // Use |EC_POINT_point2cbb| instead. OPENSSL_EXPORT int i2o_ECPublicKey(const EC_KEY *key, unsigned char **outp); diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_ecdsa.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_ecdsa.h index b3780835..bbd7dd0a 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_ecdsa.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_ecdsa.h @@ -197,19 +197,17 @@ ECDSA_sign_with_nonce_and_leak_private_key_for_testing(const uint8_t *digest, // Deprecated functions. -// d2i_ECDSA_SIG parses an ASN.1, DER-encoded, signature from |len| bytes at -// |*inp|. If |out| is not NULL then, on exit, a pointer to the result is in -// |*out|. Note that, even if |*out| is already non-NULL on entry, it will not -// be written to. Rather, a fresh |ECDSA_SIG| is allocated and the previous one -// is freed. On successful exit, |*inp| is advanced past the DER structure. It -// returns the result or NULL on error. +// d2i_ECDSA_SIG parses aa DER-encoded ECDSA-Sig-Value structure from |len| +// bytes at |*inp|, as described in |d2i_SAMPLE|. +// +// Use |ECDSA_SIG_parse| instead. OPENSSL_EXPORT ECDSA_SIG *d2i_ECDSA_SIG(ECDSA_SIG **out, const uint8_t **inp, long len); -// i2d_ECDSA_SIG marshals a signature from |sig| to an ASN.1, DER -// structure. If |outp| is not NULL then the result is written to |*outp| and -// |*outp| is advanced just past the output. It returns the number of bytes in -// the result, whether written or not, or a negative value on error. +// i2d_ECDSA_SIG marshals |sig| as a DER-encoded ECDSA-Sig-Value, as described +// in |i2d_SAMPLE|. +// +// Use |ECDSA_SIG_marshal| instead. OPENSSL_EXPORT int i2d_ECDSA_SIG(const ECDSA_SIG *sig, uint8_t **outp); diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_evp.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_evp.h index b8d44bd1..a139ef92 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_evp.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_evp.h @@ -873,34 +873,27 @@ OPENSSL_EXPORT void EVP_MD_do_all(void (*callback)(const EVP_MD *cipher, void *arg), void *arg); -// i2d_PrivateKey marshals a private key from |key| to an ASN.1, DER -// structure. If |outp| is not NULL then the result is written to |*outp| and -// |*outp| is advanced just past the output. It returns the number of bytes in -// the result, whether written or not, or a negative value on error. +// i2d_PrivateKey marshals a private key from |key| to type-specific format, as +// described in |i2d_SAMPLE|. // -// RSA keys are serialized as a DER-encoded RSAPublicKey (RFC 3447) structure. +// RSA keys are serialized as a DER-encoded RSAPublicKey (RFC 8017) structure. // EC keys are serialized as a DER-encoded ECPrivateKey (RFC 5915) structure. // // Use |RSA_marshal_private_key| or |EC_KEY_marshal_private_key| instead. OPENSSL_EXPORT int i2d_PrivateKey(const EVP_PKEY *key, uint8_t **outp); -// i2d_PublicKey marshals a public key from |key| to a type-specific format. -// If |outp| is not NULL then the result is written to |*outp| and -// |*outp| is advanced just past the output. It returns the number of bytes in -// the result, whether written or not, or a negative value on error. +// i2d_PublicKey marshals a public key from |key| to a type-specific format, as +// described in |i2d_SAMPLE|. // -// RSA keys are serialized as a DER-encoded RSAPublicKey (RFC 3447) structure. +// RSA keys are serialized as a DER-encoded RSAPublicKey (RFC 8017) structure. // EC keys are serialized as an EC point per SEC 1. // // Use |RSA_marshal_public_key| or |EC_POINT_point2cbb| instead. OPENSSL_EXPORT int i2d_PublicKey(const EVP_PKEY *key, uint8_t **outp); -// d2i_PrivateKey parses an ASN.1, DER-encoded, private key from |len| bytes at -// |*inp|. If |out| is not NULL then, on exit, a pointer to the result is in -// |*out|. Note that, even if |*out| is already non-NULL on entry, it will not -// be written to. Rather, a fresh |EVP_PKEY| is allocated and the previous one -// is freed. On successful exit, |*inp| is advanced past the DER structure. It -// returns the result or NULL on error. +// d2i_PrivateKey parses a DER-encoded private key from |len| bytes at |*inp|, +// as described in |d2i_SAMPLE|. The private key must have type |type|, +// otherwise it will be rejected. // // This function tries to detect one of several formats. Instead, use // |EVP_parse_private_key| for a PrivateKeyInfo, |RSA_parse_private_key| for an @@ -917,15 +910,12 @@ OPENSSL_EXPORT EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **out, OPENSSL_EXPORT EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **out, const uint8_t **inp, long len); -// d2i_PublicKey parse a public key from |len| bytes at |*inp| in a type- -// specific format specified by |type|. If |out| is not NULL then, on exit, a -// pointer to the result is in |*out|. Note that, even if |*out| is already non- -// NULL on entry, it will not be written to. Rather, a fresh |EVP_PKEY| is -// allocated and the previous one is freed. On successful exit, |*inp| is -// advanced past the decoded key. It returns the result or NULL on error. +// d2i_PublicKey parses a public key from |len| bytes at |*inp| in a type- +// specific format specified by |type|, as described in |d2i_SAMPLE|. // -// RSA keys are parsed as a DER-encoded RSAPublicKey (RFC 3447) structure. -// Parsing EC keys is not supported by this function. +// The only supported value for |type| is |EVP_PKEY_RSA|, which parses a +// DER-encoded RSAPublicKey (RFC 8017) structure. Parsing EC keys is not +// supported by this function. // // Use |RSA_parse_public_key| instead. OPENSSL_EXPORT EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **out, @@ -974,70 +964,54 @@ OPENSSL_EXPORT int EVP_PKEY_CTX_set_rsa_pss_keygen_saltlen(EVP_PKEY_CTX *ctx, OPENSSL_EXPORT int EVP_PKEY_CTX_set_rsa_pss_keygen_mgf1_md(EVP_PKEY_CTX *ctx, const EVP_MD *md); -// i2d_PUBKEY marshals a public key from |pkey| as a DER-encoded -// SubjectPublicKeyInfo. If |outp| is not NULL, the result is written to |*outp| -// and |*outp| is advanced just past the output. It returns the number of bytes -// in the result, whether written or not, or a negative value on error. +// i2d_PUBKEY marshals |pkey| as a DER-encoded SubjectPublicKeyInfo, as +// described in |i2d_SAMPLE|. // // Use |EVP_marshal_public_key| instead. OPENSSL_EXPORT int i2d_PUBKEY(const EVP_PKEY *pkey, uint8_t **outp); // d2i_PUBKEY parses a DER-encoded SubjectPublicKeyInfo from |len| bytes at -// |*inp|. It returns a newly-allocated result, or NULL on error. On success, -// |*inp| is advanced past the DER structure. If |out| is not NULL, it also -// frees any existing object pointed by |*out| and writes the result. +// |*inp|, as described in |d2i_SAMPLE|. // // Use |EVP_parse_public_key| instead. OPENSSL_EXPORT EVP_PKEY *d2i_PUBKEY(EVP_PKEY **out, const uint8_t **inp, long len); -// i2d_RSA_PUBKEY marshals |rsa| as a DER-encoded SubjectPublicKeyInfo. If -// |outp| is not NULL, the result is written to |*outp| and -// |*outp| is advanced just past the output. It returns the number of bytes in -// the result, whether written or not, or a negative value on error. +// i2d_RSA_PUBKEY marshals |rsa| as a DER-encoded SubjectPublicKeyInfo +// structure, as described in |i2d_SAMPLE|. // // Use |EVP_marshal_public_key| instead. OPENSSL_EXPORT int i2d_RSA_PUBKEY(const RSA *rsa, uint8_t **outp); // d2i_RSA_PUBKEY parses an RSA public key as a DER-encoded SubjectPublicKeyInfo -// from |len| bytes at |*inp|. It returns a newly-allocated result, or NULL on -// error. On success, |*inp| is advanced past the DER structure. If |out| is not -// NULL, it also frees any existing object pointed by |*out| and writes the -// result. +// from |len| bytes at |*inp|, as described in |d2i_SAMPLE|. +// SubjectPublicKeyInfo structures containing other key types are rejected. // // Use |EVP_parse_public_key| instead. OPENSSL_EXPORT RSA *d2i_RSA_PUBKEY(RSA **out, const uint8_t **inp, long len); -// i2d_DSA_PUBKEY marshals |dsa| as a DER-encoded SubjectPublicKeyInfo. If -// |outp| is not NULL, the result is written to |*outp| and |*outp| is advanced -// just past the output. It returns the number of bytes in the result, whether -// written or not, or a negative value on error. +// i2d_DSA_PUBKEY marshals |dsa| as a DER-encoded SubjectPublicKeyInfo, as +// described in |i2d_SAMPLE|. // // Use |EVP_marshal_public_key| instead. OPENSSL_EXPORT int i2d_DSA_PUBKEY(const DSA *dsa, uint8_t **outp); // d2i_DSA_PUBKEY parses a DSA public key as a DER-encoded SubjectPublicKeyInfo -// from |len| bytes at |*inp|. It returns a newly-allocated result, or NULL on -// error. On success, |*inp| is advanced past the DER structure. If |out| is not -// NULL, it also frees any existing object pointed by |*out| and writes the -// result. +// from |len| bytes at |*inp|, as described in |d2i_SAMPLE|. +// SubjectPublicKeyInfo structures containing other key types are rejected. // // Use |EVP_parse_public_key| instead. OPENSSL_EXPORT DSA *d2i_DSA_PUBKEY(DSA **out, const uint8_t **inp, long len); -// i2d_EC_PUBKEY marshals |ec_key| as a DER-encoded SubjectPublicKeyInfo. If -// |outp| is not NULL, the result is written to |*outp| and |*outp| is advanced -// just past the output. It returns the number of bytes in the result, whether -// written or not, or a negative value on error. +// i2d_EC_PUBKEY marshals |ec_key| as a DER-encoded SubjectPublicKeyInfo, as +// described in |i2d_SAMPLE|. // // Use |EVP_marshal_public_key| instead. OPENSSL_EXPORT int i2d_EC_PUBKEY(const EC_KEY *ec_key, uint8_t **outp); // d2i_EC_PUBKEY parses an EC public key as a DER-encoded SubjectPublicKeyInfo -// from |len| bytes at |*inp|. It returns a newly-allocated result, or NULL on -// error. On success, |*inp| is advanced past the DER structure. If |out| is not -// NULL, it also frees any existing object pointed by |*out| and writes the -// result. +// from |len| bytes at |*inp|, as described in |d2i_SAMPLE|. +// SubjectPublicKeyInfo structures containing other key types are rejected. // // Use |EVP_parse_public_key| instead. OPENSSL_EXPORT EC_KEY *d2i_EC_PUBKEY(EC_KEY **out, const uint8_t **inp, diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_mem.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_mem.h index 94d46027..5e7ec073 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_mem.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_mem.h @@ -150,9 +150,15 @@ OPENSSL_EXPORT size_t OPENSSL_strlcat(char *dst, const char *src, // Deprecated functions. -#define CRYPTO_malloc OPENSSL_malloc -#define CRYPTO_realloc OPENSSL_realloc -#define CRYPTO_free OPENSSL_free +// CRYPTO_malloc calls |OPENSSL_malloc|. |file| and |line| are ignored. +OPENSSL_EXPORT void *CRYPTO_malloc(size_t size, const char *file, int line); + +// CRYPTO_realloc calls |OPENSSL_realloc|. |file| and |line| are ignored. +OPENSSL_EXPORT void *CRYPTO_realloc(void *ptr, size_t new_size, + const char *file, int line); + +// CRYPTO_free calls |OPENSSL_free|. |file| and |line| are ignored. +OPENSSL_EXPORT void CRYPTO_free(void *ptr, const char *file, int line); // OPENSSL_clear_free calls |OPENSSL_free|. BoringSSL automatically clears all // allocations on free, but we define |OPENSSL_clear_free| for compatibility. diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_pkcs7.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_pkcs7.h index 1074d6f6..f467e173 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_pkcs7.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_pkcs7.h @@ -137,11 +137,7 @@ typedef struct { } PKCS7; // d2i_PKCS7 parses a BER-encoded, PKCS#7 signed data ContentInfo structure from -// |len| bytes at |*inp|. If |out| is not NULL then, on exit, a pointer to the -// result is in |*out|. Note that, even if |*out| is already non-NULL on entry, -// it will not be written to. Rather, a fresh |PKCS7| is allocated and the -// previous one is freed. On successful exit, |*inp| is advanced past the BER -// structure. It returns the result or NULL on error. +// |len| bytes at |*inp|, as described in |d2i_SAMPLE|. OPENSSL_EXPORT PKCS7 *d2i_PKCS7(PKCS7 **out, const uint8_t **inp, size_t len); @@ -152,10 +148,8 @@ OPENSSL_EXPORT PKCS7 *d2i_PKCS7(PKCS7 **out, const uint8_t **inp, // from |bio|. OPENSSL_EXPORT PKCS7 *d2i_PKCS7_bio(BIO *bio, PKCS7 **out); -// i2d_PKCS7 is a dummy function which copies the contents of |p7|. If |out| is -// not NULL then the result is written to |*out| and |*out| is advanced just -// past the output. It returns the number of bytes in the result, whether -// written or not, or a negative value on error. +// i2d_PKCS7 marshals |p7| as a DER-encoded PKCS#7 ContentInfo structure, as +// described in |i2d_SAMPLE|. OPENSSL_EXPORT int i2d_PKCS7(const PKCS7 *p7, uint8_t **out); // i2d_PKCS7_bio writes |p7| to |bio|. It returns one on success and zero on @@ -200,15 +194,22 @@ OPENSSL_EXPORT int PKCS7_type_is_signedAndEnveloped(const PKCS7 *p7); #define PKCS7_STREAM 0x1000 #define PKCS7_PARTIAL 0x4000 -// PKCS7_sign assembles |certs| into a PKCS#7 signed data ContentInfo with +// PKCS7_sign can operate in two modes to provide some backwards compatibility: +// +// The first mode assembles |certs| into a PKCS#7 signed data ContentInfo with // external data and no signatures. It returns a newly-allocated |PKCS7| on // success or NULL on error. |sign_cert| and |pkey| must be NULL. |data| is -// ignored. |flags| must be equal to |PKCS7_DETACHED|. -// -// Note this function only implements a subset of the corresponding OpenSSL -// function. It is provided for backwards compatibility only. Additionally, +// ignored. |flags| must be equal to |PKCS7_DETACHED|. Additionally, // certificates in SignedData structures are unordered. The order of |certs| // will not be preserved. +// +// The second mode generates a detached RSA SHA-256 signature of |data| using +// |pkey| and produces a PKCS#7 SignedData structure containing it. |certs| +// must be NULL and |flags| must be exactly |PKCS7_NOATTR | PKCS7_BINARY | +// PKCS7_NOCERTS | PKCS7_DETACHED|. +// +// Note this function only implements a subset of the corresponding OpenSSL +// function. It is provided for backwards compatibility only. OPENSSL_EXPORT PKCS7 *PKCS7_sign(X509 *sign_cert, EVP_PKEY *pkey, STACK_OF(X509) *certs, BIO *data, int flags); diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_pool.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_pool.h index 389f61b6..de07f858 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_pool.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_pool.h @@ -60,7 +60,13 @@ OPENSSL_EXPORT CRYPTO_BUFFER *CRYPTO_BUFFER_alloc(uint8_t **out_data, // CRYPTO_BUFFER_new_from_CBS acts the same as |CRYPTO_BUFFER_new|. OPENSSL_EXPORT CRYPTO_BUFFER *CRYPTO_BUFFER_new_from_CBS( - CBS *cbs, CRYPTO_BUFFER_POOL *pool); + const CBS *cbs, CRYPTO_BUFFER_POOL *pool); + +// CRYPTO_BUFFER_new_from_static_data_unsafe behaves like |CRYPTO_BUFFER_new| +// but does not copy |data|. |data| must be immutable and last for the lifetime +// of the address space. +OPENSSL_EXPORT CRYPTO_BUFFER *CRYPTO_BUFFER_new_from_static_data_unsafe( + const uint8_t *data, size_t len, CRYPTO_BUFFER_POOL *pool); // CRYPTO_BUFFER_free decrements the reference count of |buf|. If there are no // other references, or if the only remaining reference is from a pool, then diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_rsa.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_rsa.h index 534f6303..be70fe56 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_rsa.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_rsa.h @@ -526,44 +526,44 @@ OPENSSL_EXPORT int RSA_add_pkcs1_prefix(uint8_t **out_msg, size_t *out_msg_len, // ASN.1 functions. -// RSA_parse_public_key parses a DER-encoded RSAPublicKey structure (RFC 3447) +// RSA_parse_public_key parses a DER-encoded RSAPublicKey structure (RFC 8017) // from |cbs| and advances |cbs|. It returns a newly-allocated |RSA| or NULL on // error. OPENSSL_EXPORT RSA *RSA_parse_public_key(CBS *cbs); // RSA_public_key_from_bytes parses |in| as a DER-encoded RSAPublicKey structure -// (RFC 3447). It returns a newly-allocated |RSA| or NULL on error. +// (RFC 8017). It returns a newly-allocated |RSA| or NULL on error. OPENSSL_EXPORT RSA *RSA_public_key_from_bytes(const uint8_t *in, size_t in_len); // RSA_marshal_public_key marshals |rsa| as a DER-encoded RSAPublicKey structure -// (RFC 3447) and appends the result to |cbb|. It returns one on success and +// (RFC 8017) and appends the result to |cbb|. It returns one on success and // zero on failure. OPENSSL_EXPORT int RSA_marshal_public_key(CBB *cbb, const RSA *rsa); // RSA_public_key_to_bytes marshals |rsa| as a DER-encoded RSAPublicKey -// structure (RFC 3447) and, on success, sets |*out_bytes| to a newly allocated +// structure (RFC 8017) and, on success, sets |*out_bytes| to a newly allocated // buffer containing the result and returns one. Otherwise, it returns zero. The // result should be freed with |OPENSSL_free|. OPENSSL_EXPORT int RSA_public_key_to_bytes(uint8_t **out_bytes, size_t *out_len, const RSA *rsa); -// RSA_parse_private_key parses a DER-encoded RSAPrivateKey structure (RFC 3447) +// RSA_parse_private_key parses a DER-encoded RSAPrivateKey structure (RFC 8017) // from |cbs| and advances |cbs|. It returns a newly-allocated |RSA| or NULL on // error. OPENSSL_EXPORT RSA *RSA_parse_private_key(CBS *cbs); // RSA_private_key_from_bytes parses |in| as a DER-encoded RSAPrivateKey -// structure (RFC 3447). It returns a newly-allocated |RSA| or NULL on error. +// structure (RFC 8017). It returns a newly-allocated |RSA| or NULL on error. OPENSSL_EXPORT RSA *RSA_private_key_from_bytes(const uint8_t *in, size_t in_len); // RSA_marshal_private_key marshals |rsa| as a DER-encoded RSAPrivateKey -// structure (RFC 3447) and appends the result to |cbb|. It returns one on +// structure (RFC 8017) and appends the result to |cbb|. It returns one on // success and zero on failure. OPENSSL_EXPORT int RSA_marshal_private_key(CBB *cbb, const RSA *rsa); // RSA_private_key_to_bytes marshals |rsa| as a DER-encoded RSAPrivateKey -// structure (RFC 3447) and, on success, sets |*out_bytes| to a newly allocated +// structure (RFC 8017) and, on success, sets |*out_bytes| to a newly allocated // buffer containing the result and returns one. Otherwise, it returns zero. The // result should be freed with |OPENSSL_free|. OPENSSL_EXPORT int RSA_private_key_to_bytes(uint8_t **out_bytes, @@ -625,32 +625,28 @@ OPENSSL_EXPORT int RSA_blinding_on(RSA *rsa, BN_CTX *ctx); OPENSSL_EXPORT RSA *RSA_generate_key(int bits, unsigned long e, void *callback, void *cb_arg); -// d2i_RSAPublicKey parses an ASN.1, DER-encoded, RSA public key from |len| -// bytes at |*inp|. If |out| is not NULL then, on exit, a pointer to the result -// is in |*out|. Note that, even if |*out| is already non-NULL on entry, it -// will not be written to. Rather, a fresh |RSA| is allocated and the previous -// one is freed. On successful exit, |*inp| is advanced past the DER structure. -// It returns the result or NULL on error. +// d2i_RSAPublicKey parses a DER-encoded RSAPublicKey structure (RFC 8017) from +// |len| bytes at |*inp|, as described in |d2i_SAMPLE|. +// +// Use |RSA_parse_public_key| instead. OPENSSL_EXPORT RSA *d2i_RSAPublicKey(RSA **out, const uint8_t **inp, long len); -// i2d_RSAPublicKey marshals |in| to an ASN.1, DER structure. If |outp| is not -// NULL then the result is written to |*outp| and |*outp| is advanced just past -// the output. It returns the number of bytes in the result, whether written or -// not, or a negative value on error. +// i2d_RSAPublicKey marshals |in| to a DER-encoded RSAPublicKey structure (RFC +// 8017), as described in |i2d_SAMPLE|. +// +// Use |RSA_marshal_public_key| instead. OPENSSL_EXPORT int i2d_RSAPublicKey(const RSA *in, uint8_t **outp); -// d2i_RSAPrivateKey parses an ASN.1, DER-encoded, RSA private key from |len| -// bytes at |*inp|. If |out| is not NULL then, on exit, a pointer to the result -// is in |*out|. Note that, even if |*out| is already non-NULL on entry, it -// will not be written to. Rather, a fresh |RSA| is allocated and the previous -// one is freed. On successful exit, |*inp| is advanced past the DER structure. -// It returns the result or NULL on error. +// d2i_RSAPrivateKey parses a DER-encoded RSAPrivateKey structure (RFC 8017) +// from |len| bytes at |*inp|, as described in |d2i_SAMPLE|. +// +// Use |RSA_parse_private_key| instead. OPENSSL_EXPORT RSA *d2i_RSAPrivateKey(RSA **out, const uint8_t **inp, long len); -// i2d_RSAPrivateKey marshals |in| to an ASN.1, DER structure. If |outp| is not -// NULL then the result is written to |*outp| and |*outp| is advanced just past -// the output. It returns the number of bytes in the result, whether written or -// not, or a negative value on error. +// i2d_RSAPrivateKey marshals |in| to a DER-encoded RSAPrivateKey structure (RFC +// 8017), as described in |i2d_SAMPLE|. +// +// Use |RSA_marshal_private_key| instead. OPENSSL_EXPORT int i2d_RSAPrivateKey(const RSA *in, uint8_t **outp); // RSA_padding_add_PKCS1_PSS acts like |RSA_padding_add_PKCS1_PSS_mgf1| but the @@ -684,6 +680,11 @@ OPENSSL_EXPORT int RSA_padding_add_PKCS1_OAEP(uint8_t *to, size_t to_len, // on success or zero otherwise. OPENSSL_EXPORT int RSA_print(BIO *bio, const RSA *rsa, int indent); +// RSA_get0_pss_params returns NULL. In OpenSSL, this function retries RSA-PSS +// parameters associated with |RSA| objects, but BoringSSL does not support +// the id-RSASSA-PSS key encoding. +OPENSSL_EXPORT const RSA_PSS_PARAMS *RSA_get0_pss_params(const RSA *rsa); + struct rsa_meth_st { struct openssl_method_common_st common; diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_x509.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_x509.h index 064e8a2f..d287cd0f 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_x509.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_x509.h @@ -82,7 +82,7 @@ #include "CCryptoBoringSSL_thread.h" #include -#ifdef __cplusplus +#if defined(__cplusplus) extern "C" { #endif @@ -284,7 +284,6 @@ struct private_key_st { EVP_CIPHER_INFO cipher; } /* X509_PKEY */; -#ifndef OPENSSL_NO_EVP struct X509_info_st { X509 *x509; X509_CRL *crl; @@ -297,7 +296,6 @@ struct X509_info_st { } /* X509_INFO */; DEFINE_STACK_OF(X509_INFO) -#endif // The next 2 structures and their 8 routines were sent to me by // Pat Richard and are used to manipulate @@ -313,16 +311,6 @@ struct Netscape_spki_st { ASN1_BIT_STRING *signature; } /* NETSCAPE_SPKI */; -#ifdef __cplusplus -} -#endif - -#include "CCryptoBoringSSL_x509_vfy.h" - -#ifdef __cplusplus -extern "C" { -#endif - // TODO(davidben): Document remaining functions, reorganize them, and define // supported patterns for using |X509| objects in general. In particular, when // it is safe to call mutating functions is a little tricky due to various @@ -522,9 +510,6 @@ OPENSSL_EXPORT X509_PUBKEY *X509_get_X509_PUBKEY(const X509 *x509); // X509_verify_cert_error_string returns |err| as a human-readable string, where // |err| should be one of the |X509_V_*| values. If |err| is unknown, it returns // a default description. -// -// TODO(davidben): Move this function to x509_vfy.h, with the |X509_V_*| -// definitions, or fold x509_vfy.h into this function. OPENSSL_EXPORT const char *X509_verify_cert_error_string(long err); // X509_verify checks that |x509| has a valid signature by |pkey|. It returns @@ -846,7 +831,6 @@ OPENSSL_EXPORT X509_REQ *X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, const EVP_MD *md); DECLARE_ASN1_ENCODE_FUNCTIONS(X509_ALGORS, X509_ALGORS, X509_ALGORS) -DECLARE_ASN1_FUNCTIONS(X509_VAL) DECLARE_ASN1_FUNCTIONS(X509_PUBKEY) @@ -900,28 +884,16 @@ OPENSSL_EXPORT int i2d_X509_AUX(X509 *a, unsigned char **pp); OPENSSL_EXPORT X509 *d2i_X509_AUX(X509 **a, const unsigned char **pp, long length); -// i2d_re_X509_tbs serializes the TBSCertificate portion of |x509|. If |outp| is -// NULL, nothing is written. Otherwise, if |*outp| is not NULL, the result is -// written to |*outp|, which must have enough space available, and |*outp| is -// advanced just past the output. If |outp| is non-NULL and |*outp| is NULL, it -// sets |*outp| to a newly-allocated buffer containing the result. The caller is -// responsible for releasing the buffer with |OPENSSL_free|. In all cases, this -// function returns the number of bytes in the result, whether written or not, -// or a negative value on error. +// i2d_re_X509_tbs serializes the TBSCertificate portion of |x509|, as described +// in |i2d_SAMPLE|. // // This function re-encodes the TBSCertificate and may not reflect |x509|'s // original encoding. It may be used to manually generate a signature for a new // certificate. To verify certificates, use |i2d_X509_tbs| instead. OPENSSL_EXPORT int i2d_re_X509_tbs(X509 *x509, unsigned char **outp); -// i2d_X509_tbs serializes the TBSCertificate portion of |x509|. If |outp| is -// NULL, nothing is written. Otherwise, if |*outp| is not NULL, the result is -// written to |*outp|, which must have enough space available, and |*outp| is -// advanced just past the output. If |outp| is non-NULL and |*outp| is NULL, it -// sets |*outp| to a newly-allocated buffer containing the result. The caller is -// responsible for releasing the buffer with |OPENSSL_free|. In all cases, this -// function returns the number of bytes in the result, whether written or not, -// or a negative value on error. +// i2d_X509_tbs serializes the TBSCertificate portion of |x509|, as described in +// |i2d_SAMPLE|. // // This function preserves the original encoding of the TBSCertificate and may // not reflect modifications made to |x509|. It may be used to manually verify @@ -1088,13 +1060,7 @@ OPENSSL_EXPORT void X509_REQ_get0_signature(const X509_REQ *req, OPENSSL_EXPORT int X509_REQ_get_signature_nid(const X509_REQ *req); // i2d_re_X509_REQ_tbs serializes the CertificationRequestInfo (see RFC 2986) -// portion of |req|. If |outp| is NULL, nothing is written. Otherwise, if -// |*outp| is not NULL, the result is written to |*outp|, which must have enough -// space available, and |*outp| is advanced just past the output. If |outp| is -// non-NULL and |*outp| is NULL, it sets |*outp| to a newly-allocated buffer -// containing the result. The caller is responsible for releasing the buffer -// with |OPENSSL_free|. In all cases, this function returns the number of bytes -// in the result, whether written or not, or a negative value on error. +// portion of |req|, as described in |i2d_SAMPLE|. // // This function re-encodes the CertificationRequestInfo and may not reflect // |req|'s original encoding. It may be used to manually generate a signature @@ -1232,28 +1198,16 @@ OPENSSL_EXPORT void X509_CRL_get0_signature(const X509_CRL *crl, // a known NID. OPENSSL_EXPORT int X509_CRL_get_signature_nid(const X509_CRL *crl); -// i2d_re_X509_CRL_tbs serializes the TBSCertList portion of |crl|. If |outp| is -// NULL, nothing is written. Otherwise, if |*outp| is not NULL, the result is -// written to |*outp|, which must have enough space available, and |*outp| is -// advanced just past the output. If |outp| is non-NULL and |*outp| is NULL, it -// sets |*outp| to a newly-allocated buffer containing the result. The caller is -// responsible for releasing the buffer with |OPENSSL_free|. In all cases, this -// function returns the number of bytes in the result, whether written or not, -// or a negative value on error. +// i2d_re_X509_CRL_tbs serializes the TBSCertList portion of |crl|, as described +// in |i2d_SAMPLE|. // // This function re-encodes the TBSCertList and may not reflect |crl|'s original // encoding. It may be used to manually generate a signature for a new CRL. To // verify CRLs, use |i2d_X509_CRL_tbs| instead. OPENSSL_EXPORT int i2d_re_X509_CRL_tbs(X509_CRL *crl, unsigned char **outp); -// i2d_X509_CRL_tbs serializes the TBSCertList portion of |crl|. If |outp| is -// NULL, nothing is written. Otherwise, if |*outp| is not NULL, the result is -// written to |*outp|, which must have enough space available, and |*outp| is -// advanced just past the output. If |outp| is non-NULL and |*outp| is NULL, it -// sets |*outp| to a newly-allocated buffer containing the result. The caller is -// responsible for releasing the buffer with |OPENSSL_free|. In all cases, this -// function returns the number of bytes in the result, whether written or not, -// or a negative value on error. +// i2d_X509_CRL_tbs serializes the TBSCertList portion of |crl|, as described in +// |i2d_SAMPLE|. // // This function preserves the original encoding of the TBSCertList and may not // reflect modifications made to |crl|. It may be used to manually verify the @@ -1887,19 +1841,502 @@ OPENSSL_EXPORT char *X509_TRUST_get0_name(const X509_TRUST *xp); OPENSSL_EXPORT int X509_TRUST_get_trust(const X509_TRUST *xp); -typedef struct rsa_pss_params_st { +struct rsa_pss_params_st { X509_ALGOR *hashAlgorithm; X509_ALGOR *maskGenAlgorithm; ASN1_INTEGER *saltLength; ASN1_INTEGER *trailerField; -} RSA_PSS_PARAMS; + // OpenSSL caches the MGF hash on |RSA_PSS_PARAMS| in some cases. None of the + // cases apply to BoringSSL, so this is always NULL, but Node expects the + // field to be present. + X509_ALGOR *maskHash; +} /* RSA_PSS_PARAMS */; DECLARE_ASN1_FUNCTIONS(RSA_PSS_PARAMS) +/* +SSL_CTX -> X509_STORE + -> X509_LOOKUP + ->X509_LOOKUP_METHOD + -> X509_LOOKUP + ->X509_LOOKUP_METHOD + +SSL -> X509_STORE_CTX + ->X509_STORE + +The X509_STORE holds the tables etc for verification stuff. +A X509_STORE_CTX is used while validating a single certificate. +The X509_STORE has X509_LOOKUPs for looking up certs. +The X509_STORE then calls a function to actually verify the +certificate chain. +*/ + +#define X509_LU_X509 1 +#define X509_LU_CRL 2 +#define X509_LU_PKEY 3 + +DEFINE_STACK_OF(X509_LOOKUP) +DEFINE_STACK_OF(X509_OBJECT) +DEFINE_STACK_OF(X509_VERIFY_PARAM) + +typedef int (*X509_STORE_CTX_verify_cb)(int, X509_STORE_CTX *); +typedef int (*X509_STORE_CTX_verify_fn)(X509_STORE_CTX *); +typedef int (*X509_STORE_CTX_get_issuer_fn)(X509 **issuer, X509_STORE_CTX *ctx, + X509 *x); +typedef int (*X509_STORE_CTX_check_issued_fn)(X509_STORE_CTX *ctx, X509 *x, + X509 *issuer); +typedef int (*X509_STORE_CTX_check_revocation_fn)(X509_STORE_CTX *ctx); +typedef int (*X509_STORE_CTX_get_crl_fn)(X509_STORE_CTX *ctx, X509_CRL **crl, + X509 *x); +typedef int (*X509_STORE_CTX_check_crl_fn)(X509_STORE_CTX *ctx, X509_CRL *crl); +typedef int (*X509_STORE_CTX_cert_crl_fn)(X509_STORE_CTX *ctx, X509_CRL *crl, + X509 *x); +typedef int (*X509_STORE_CTX_check_policy_fn)(X509_STORE_CTX *ctx); +typedef STACK_OF(X509) *(*X509_STORE_CTX_lookup_certs_fn)(X509_STORE_CTX *ctx, + X509_NAME *nm); +typedef STACK_OF(X509_CRL) *(*X509_STORE_CTX_lookup_crls_fn)( + X509_STORE_CTX *ctx, X509_NAME *nm); +typedef int (*X509_STORE_CTX_cleanup_fn)(X509_STORE_CTX *ctx); + +OPENSSL_EXPORT int X509_STORE_set_depth(X509_STORE *store, int depth); + +OPENSSL_EXPORT void X509_STORE_CTX_set_depth(X509_STORE_CTX *ctx, int depth); + +#define X509_STORE_CTX_set_app_data(ctx, data) \ + X509_STORE_CTX_set_ex_data(ctx, 0, data) +#define X509_STORE_CTX_get_app_data(ctx) X509_STORE_CTX_get_ex_data(ctx, 0) + +#define X509_L_FILE_LOAD 1 +#define X509_L_ADD_DIR 2 + +#define X509_LOOKUP_load_file(x, name, type) \ + X509_LOOKUP_ctrl((x), X509_L_FILE_LOAD, (name), (long)(type), NULL) + +#define X509_LOOKUP_add_dir(x, name, type) \ + X509_LOOKUP_ctrl((x), X509_L_ADD_DIR, (name), (long)(type), NULL) + +#define X509_V_OK 0 +#define X509_V_ERR_UNSPECIFIED 1 + +#define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT 2 +#define X509_V_ERR_UNABLE_TO_GET_CRL 3 +#define X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE 4 +#define X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE 5 +#define X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY 6 +#define X509_V_ERR_CERT_SIGNATURE_FAILURE 7 +#define X509_V_ERR_CRL_SIGNATURE_FAILURE 8 +#define X509_V_ERR_CERT_NOT_YET_VALID 9 +#define X509_V_ERR_CERT_HAS_EXPIRED 10 +#define X509_V_ERR_CRL_NOT_YET_VALID 11 +#define X509_V_ERR_CRL_HAS_EXPIRED 12 +#define X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD 13 +#define X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD 14 +#define X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD 15 +#define X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD 16 +#define X509_V_ERR_OUT_OF_MEM 17 +#define X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT 18 +#define X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN 19 +#define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY 20 +#define X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE 21 +#define X509_V_ERR_CERT_CHAIN_TOO_LONG 22 +#define X509_V_ERR_CERT_REVOKED 23 +#define X509_V_ERR_INVALID_CA 24 +#define X509_V_ERR_PATH_LENGTH_EXCEEDED 25 +#define X509_V_ERR_INVALID_PURPOSE 26 +#define X509_V_ERR_CERT_UNTRUSTED 27 +#define X509_V_ERR_CERT_REJECTED 28 +// These are 'informational' when looking for issuer cert +#define X509_V_ERR_SUBJECT_ISSUER_MISMATCH 29 +#define X509_V_ERR_AKID_SKID_MISMATCH 30 +#define X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH 31 +#define X509_V_ERR_KEYUSAGE_NO_CERTSIGN 32 + +#define X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER 33 +#define X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION 34 +#define X509_V_ERR_KEYUSAGE_NO_CRL_SIGN 35 +#define X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION 36 +#define X509_V_ERR_INVALID_NON_CA 37 +#define X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED 38 +#define X509_V_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE 39 +#define X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED 40 + +#define X509_V_ERR_INVALID_EXTENSION 41 +#define X509_V_ERR_INVALID_POLICY_EXTENSION 42 +#define X509_V_ERR_NO_EXPLICIT_POLICY 43 +#define X509_V_ERR_DIFFERENT_CRL_SCOPE 44 +#define X509_V_ERR_UNSUPPORTED_EXTENSION_FEATURE 45 + +#define X509_V_ERR_UNNESTED_RESOURCE 46 + +#define X509_V_ERR_PERMITTED_VIOLATION 47 +#define X509_V_ERR_EXCLUDED_VIOLATION 48 +#define X509_V_ERR_SUBTREE_MINMAX 49 +#define X509_V_ERR_APPLICATION_VERIFICATION 50 +#define X509_V_ERR_UNSUPPORTED_CONSTRAINT_TYPE 51 +#define X509_V_ERR_UNSUPPORTED_CONSTRAINT_SYNTAX 52 +#define X509_V_ERR_UNSUPPORTED_NAME_SYNTAX 53 +#define X509_V_ERR_CRL_PATH_VALIDATION_ERROR 54 + +// Suite B mode algorithm violation +#define X509_V_ERR_SUITE_B_INVALID_VERSION 56 +#define X509_V_ERR_SUITE_B_INVALID_ALGORITHM 57 +#define X509_V_ERR_SUITE_B_INVALID_CURVE 58 +#define X509_V_ERR_SUITE_B_INVALID_SIGNATURE_ALGORITHM 59 +#define X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED 60 +#define X509_V_ERR_SUITE_B_CANNOT_SIGN_P_384_WITH_P_256 61 + +// Host, email and IP check errors +#define X509_V_ERR_HOSTNAME_MISMATCH 62 +#define X509_V_ERR_EMAIL_MISMATCH 63 +#define X509_V_ERR_IP_ADDRESS_MISMATCH 64 + +// Caller error +#define X509_V_ERR_INVALID_CALL 65 +// Issuer lookup error +#define X509_V_ERR_STORE_LOOKUP 66 + +#define X509_V_ERR_NAME_CONSTRAINTS_WITHOUT_SANS 67 + +// Certificate verify flags + +// Send issuer+subject checks to verify_cb +#define X509_V_FLAG_CB_ISSUER_CHECK 0x1 +// Use check time instead of current time +#define X509_V_FLAG_USE_CHECK_TIME 0x2 +// Lookup CRLs +#define X509_V_FLAG_CRL_CHECK 0x4 +// Lookup CRLs for whole chain +#define X509_V_FLAG_CRL_CHECK_ALL 0x8 +// Ignore unhandled critical extensions +#define X509_V_FLAG_IGNORE_CRITICAL 0x10 +// Does nothing as its functionality has been enabled by default. +#define X509_V_FLAG_X509_STRICT 0x00 +// Enable proxy certificate validation +#define X509_V_FLAG_ALLOW_PROXY_CERTS 0x40 +// Enable policy checking +#define X509_V_FLAG_POLICY_CHECK 0x80 +// Policy variable require-explicit-policy +#define X509_V_FLAG_EXPLICIT_POLICY 0x100 +// Policy variable inhibit-any-policy +#define X509_V_FLAG_INHIBIT_ANY 0x200 +// Policy variable inhibit-policy-mapping +#define X509_V_FLAG_INHIBIT_MAP 0x400 +// Notify callback that policy is OK +#define X509_V_FLAG_NOTIFY_POLICY 0x800 +// Extended CRL features such as indirect CRLs, alternate CRL signing keys +#define X509_V_FLAG_EXTENDED_CRL_SUPPORT 0x1000 +// Delta CRL support +#define X509_V_FLAG_USE_DELTAS 0x2000 +// Check selfsigned CA signature +#define X509_V_FLAG_CHECK_SS_SIGNATURE 0x4000 +// Use trusted store first +#define X509_V_FLAG_TRUSTED_FIRST 0x8000 +// Suite B 128 bit only mode: not normally used +#define X509_V_FLAG_SUITEB_128_LOS_ONLY 0x10000 +// Suite B 192 bit only mode +#define X509_V_FLAG_SUITEB_192_LOS 0x20000 +// Suite B 128 bit mode allowing 192 bit algorithms +#define X509_V_FLAG_SUITEB_128_LOS 0x30000 + +// Allow partial chains if at least one certificate is in trusted store +#define X509_V_FLAG_PARTIAL_CHAIN 0x80000 + +// If the initial chain is not trusted, do not attempt to build an alternative +// chain. Alternate chain checking was introduced in 1.0.2b. Setting this flag +// will force the behaviour to match that of previous versions. +#define X509_V_FLAG_NO_ALT_CHAINS 0x100000 + +#define X509_VP_FLAG_DEFAULT 0x1 +#define X509_VP_FLAG_OVERWRITE 0x2 +#define X509_VP_FLAG_RESET_FLAGS 0x4 +#define X509_VP_FLAG_LOCKED 0x8 +#define X509_VP_FLAG_ONCE 0x10 + +// Internal use: mask of policy related options +#define X509_V_FLAG_POLICY_MASK \ + (X509_V_FLAG_POLICY_CHECK | X509_V_FLAG_EXPLICIT_POLICY | \ + X509_V_FLAG_INHIBIT_ANY | X509_V_FLAG_INHIBIT_MAP) + +OPENSSL_EXPORT int X509_OBJECT_idx_by_subject(STACK_OF(X509_OBJECT) *h, + int type, X509_NAME *name); +OPENSSL_EXPORT X509_OBJECT *X509_OBJECT_retrieve_by_subject( + STACK_OF(X509_OBJECT) *h, int type, X509_NAME *name); +OPENSSL_EXPORT X509_OBJECT *X509_OBJECT_retrieve_match(STACK_OF(X509_OBJECT) *h, + X509_OBJECT *x); +OPENSSL_EXPORT int X509_OBJECT_up_ref_count(X509_OBJECT *a); +OPENSSL_EXPORT void X509_OBJECT_free_contents(X509_OBJECT *a); +OPENSSL_EXPORT int X509_OBJECT_get_type(const X509_OBJECT *a); +OPENSSL_EXPORT X509 *X509_OBJECT_get0_X509(const X509_OBJECT *a); +OPENSSL_EXPORT X509_STORE *X509_STORE_new(void); +OPENSSL_EXPORT int X509_STORE_up_ref(X509_STORE *store); +OPENSSL_EXPORT void X509_STORE_free(X509_STORE *v); + +OPENSSL_EXPORT STACK_OF(X509_OBJECT) *X509_STORE_get0_objects(X509_STORE *st); +OPENSSL_EXPORT STACK_OF(X509) *X509_STORE_get1_certs(X509_STORE_CTX *st, + X509_NAME *nm); +OPENSSL_EXPORT STACK_OF(X509_CRL) *X509_STORE_get1_crls(X509_STORE_CTX *st, + X509_NAME *nm); +OPENSSL_EXPORT int X509_STORE_set_flags(X509_STORE *ctx, unsigned long flags); +OPENSSL_EXPORT int X509_STORE_set_purpose(X509_STORE *ctx, int purpose); +OPENSSL_EXPORT int X509_STORE_set_trust(X509_STORE *ctx, int trust); +OPENSSL_EXPORT int X509_STORE_set1_param(X509_STORE *ctx, + X509_VERIFY_PARAM *pm); +OPENSSL_EXPORT X509_VERIFY_PARAM *X509_STORE_get0_param(X509_STORE *ctx); + +OPENSSL_EXPORT void X509_STORE_set_verify(X509_STORE *ctx, + X509_STORE_CTX_verify_fn verify); +#define X509_STORE_set_verify_func(ctx, func) \ + X509_STORE_set_verify((ctx), (func)) +OPENSSL_EXPORT void X509_STORE_CTX_set_verify(X509_STORE_CTX *ctx, + X509_STORE_CTX_verify_fn verify); +OPENSSL_EXPORT X509_STORE_CTX_verify_fn X509_STORE_get_verify(X509_STORE *ctx); +OPENSSL_EXPORT void X509_STORE_set_verify_cb( + X509_STORE *ctx, X509_STORE_CTX_verify_cb verify_cb); +#define X509_STORE_set_verify_cb_func(ctx, func) \ + X509_STORE_set_verify_cb((ctx), (func)) +OPENSSL_EXPORT X509_STORE_CTX_verify_cb +X509_STORE_get_verify_cb(X509_STORE *ctx); +OPENSSL_EXPORT void X509_STORE_set_get_issuer( + X509_STORE *ctx, X509_STORE_CTX_get_issuer_fn get_issuer); +OPENSSL_EXPORT X509_STORE_CTX_get_issuer_fn +X509_STORE_get_get_issuer(X509_STORE *ctx); +OPENSSL_EXPORT void X509_STORE_set_check_issued( + X509_STORE *ctx, X509_STORE_CTX_check_issued_fn check_issued); +OPENSSL_EXPORT X509_STORE_CTX_check_issued_fn +X509_STORE_get_check_issued(X509_STORE *ctx); +OPENSSL_EXPORT void X509_STORE_set_check_revocation( + X509_STORE *ctx, X509_STORE_CTX_check_revocation_fn check_revocation); +OPENSSL_EXPORT X509_STORE_CTX_check_revocation_fn +X509_STORE_get_check_revocation(X509_STORE *ctx); +OPENSSL_EXPORT void X509_STORE_set_get_crl(X509_STORE *ctx, + X509_STORE_CTX_get_crl_fn get_crl); +OPENSSL_EXPORT X509_STORE_CTX_get_crl_fn +X509_STORE_get_get_crl(X509_STORE *ctx); +OPENSSL_EXPORT void X509_STORE_set_check_crl( + X509_STORE *ctx, X509_STORE_CTX_check_crl_fn check_crl); +OPENSSL_EXPORT X509_STORE_CTX_check_crl_fn +X509_STORE_get_check_crl(X509_STORE *ctx); +OPENSSL_EXPORT void X509_STORE_set_cert_crl( + X509_STORE *ctx, X509_STORE_CTX_cert_crl_fn cert_crl); +OPENSSL_EXPORT X509_STORE_CTX_cert_crl_fn +X509_STORE_get_cert_crl(X509_STORE *ctx); +OPENSSL_EXPORT void X509_STORE_set_lookup_certs( + X509_STORE *ctx, X509_STORE_CTX_lookup_certs_fn lookup_certs); +OPENSSL_EXPORT X509_STORE_CTX_lookup_certs_fn +X509_STORE_get_lookup_certs(X509_STORE *ctx); +OPENSSL_EXPORT void X509_STORE_set_lookup_crls( + X509_STORE *ctx, X509_STORE_CTX_lookup_crls_fn lookup_crls); +#define X509_STORE_set_lookup_crls_cb(ctx, func) \ + X509_STORE_set_lookup_crls((ctx), (func)) +OPENSSL_EXPORT X509_STORE_CTX_lookup_crls_fn +X509_STORE_get_lookup_crls(X509_STORE *ctx); +OPENSSL_EXPORT void X509_STORE_set_cleanup(X509_STORE *ctx, + X509_STORE_CTX_cleanup_fn cleanup); +OPENSSL_EXPORT X509_STORE_CTX_cleanup_fn +X509_STORE_get_cleanup(X509_STORE *ctx); + +OPENSSL_EXPORT X509_STORE_CTX *X509_STORE_CTX_new(void); + +OPENSSL_EXPORT int X509_STORE_CTX_get1_issuer(X509 **issuer, + X509_STORE_CTX *ctx, X509 *x); + +OPENSSL_EXPORT void X509_STORE_CTX_zero(X509_STORE_CTX *ctx); +OPENSSL_EXPORT void X509_STORE_CTX_free(X509_STORE_CTX *ctx); +OPENSSL_EXPORT int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, + X509 *x509, STACK_OF(X509) *chain); +OPENSSL_EXPORT void X509_STORE_CTX_trusted_stack(X509_STORE_CTX *ctx, + STACK_OF(X509) *sk); +OPENSSL_EXPORT void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx); + +OPENSSL_EXPORT X509_STORE *X509_STORE_CTX_get0_store(X509_STORE_CTX *ctx); +OPENSSL_EXPORT X509 *X509_STORE_CTX_get0_cert(X509_STORE_CTX *ctx); + +OPENSSL_EXPORT X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *v, + X509_LOOKUP_METHOD *m); + +OPENSSL_EXPORT X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir(void); +OPENSSL_EXPORT X509_LOOKUP_METHOD *X509_LOOKUP_file(void); + +OPENSSL_EXPORT int X509_STORE_add_cert(X509_STORE *ctx, X509 *x); +OPENSSL_EXPORT int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x); + +OPENSSL_EXPORT int X509_STORE_get_by_subject(X509_STORE_CTX *vs, int type, + X509_NAME *name, X509_OBJECT *ret); + +OPENSSL_EXPORT int X509_LOOKUP_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc, + long argl, char **ret); + +#ifndef OPENSSL_NO_STDIO +OPENSSL_EXPORT int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, + int type); +OPENSSL_EXPORT int X509_load_crl_file(X509_LOOKUP *ctx, const char *file, + int type); +OPENSSL_EXPORT int X509_load_cert_crl_file(X509_LOOKUP *ctx, const char *file, + int type); +#endif + +OPENSSL_EXPORT X509_LOOKUP *X509_LOOKUP_new(X509_LOOKUP_METHOD *method); +OPENSSL_EXPORT void X509_LOOKUP_free(X509_LOOKUP *ctx); +OPENSSL_EXPORT int X509_LOOKUP_init(X509_LOOKUP *ctx); +OPENSSL_EXPORT int X509_LOOKUP_by_subject(X509_LOOKUP *ctx, int type, + X509_NAME *name, X509_OBJECT *ret); +OPENSSL_EXPORT int X509_LOOKUP_by_issuer_serial(X509_LOOKUP *ctx, int type, + X509_NAME *name, + ASN1_INTEGER *serial, + X509_OBJECT *ret); +OPENSSL_EXPORT int X509_LOOKUP_by_fingerprint(X509_LOOKUP *ctx, int type, + unsigned char *bytes, int len, + X509_OBJECT *ret); +OPENSSL_EXPORT int X509_LOOKUP_by_alias(X509_LOOKUP *ctx, int type, char *str, + int len, X509_OBJECT *ret); +OPENSSL_EXPORT int X509_LOOKUP_shutdown(X509_LOOKUP *ctx); + +#ifndef OPENSSL_NO_STDIO +OPENSSL_EXPORT int X509_STORE_load_locations(X509_STORE *ctx, const char *file, + const char *dir); +OPENSSL_EXPORT int X509_STORE_set_default_paths(X509_STORE *ctx); +#endif + +OPENSSL_EXPORT int X509_STORE_CTX_get_ex_new_index(long argl, void *argp, + CRYPTO_EX_unused *unused, + CRYPTO_EX_dup *dup_unused, + CRYPTO_EX_free *free_func); +OPENSSL_EXPORT int X509_STORE_CTX_set_ex_data(X509_STORE_CTX *ctx, int idx, + void *data); +OPENSSL_EXPORT void *X509_STORE_CTX_get_ex_data(X509_STORE_CTX *ctx, int idx); +OPENSSL_EXPORT int X509_STORE_CTX_get_error(X509_STORE_CTX *ctx); +OPENSSL_EXPORT void X509_STORE_CTX_set_error(X509_STORE_CTX *ctx, int s); +OPENSSL_EXPORT int X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx); +OPENSSL_EXPORT X509 *X509_STORE_CTX_get_current_cert(X509_STORE_CTX *ctx); +OPENSSL_EXPORT X509 *X509_STORE_CTX_get0_current_issuer(X509_STORE_CTX *ctx); +OPENSSL_EXPORT X509_CRL *X509_STORE_CTX_get0_current_crl(X509_STORE_CTX *ctx); +OPENSSL_EXPORT X509_STORE_CTX *X509_STORE_CTX_get0_parent_ctx( + X509_STORE_CTX *ctx); +OPENSSL_EXPORT STACK_OF(X509) *X509_STORE_CTX_get_chain(X509_STORE_CTX *ctx); +OPENSSL_EXPORT STACK_OF(X509) *X509_STORE_CTX_get0_chain(X509_STORE_CTX *ctx); +OPENSSL_EXPORT STACK_OF(X509) *X509_STORE_CTX_get1_chain(X509_STORE_CTX *ctx); +OPENSSL_EXPORT void X509_STORE_CTX_set_cert(X509_STORE_CTX *c, X509 *x); +OPENSSL_EXPORT void X509_STORE_CTX_set_chain(X509_STORE_CTX *c, + STACK_OF(X509) *sk); +OPENSSL_EXPORT STACK_OF(X509) *X509_STORE_CTX_get0_untrusted( + X509_STORE_CTX *ctx); +OPENSSL_EXPORT void X509_STORE_CTX_set0_crls(X509_STORE_CTX *c, + STACK_OF(X509_CRL) *sk); +OPENSSL_EXPORT int X509_STORE_CTX_set_purpose(X509_STORE_CTX *ctx, int purpose); +OPENSSL_EXPORT int X509_STORE_CTX_set_trust(X509_STORE_CTX *ctx, int trust); +OPENSSL_EXPORT int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, + int def_purpose, int purpose, + int trust); +OPENSSL_EXPORT void X509_STORE_CTX_set_flags(X509_STORE_CTX *ctx, + unsigned long flags); +OPENSSL_EXPORT void X509_STORE_CTX_set_time(X509_STORE_CTX *ctx, + unsigned long flags, time_t t); +OPENSSL_EXPORT void X509_STORE_CTX_set_verify_cb( + X509_STORE_CTX *ctx, int (*verify_cb)(int, X509_STORE_CTX *)); + +OPENSSL_EXPORT X509_POLICY_TREE *X509_STORE_CTX_get0_policy_tree( + X509_STORE_CTX *ctx); +OPENSSL_EXPORT int X509_STORE_CTX_get_explicit_policy(X509_STORE_CTX *ctx); + +OPENSSL_EXPORT X509_VERIFY_PARAM *X509_STORE_CTX_get0_param( + X509_STORE_CTX *ctx); +OPENSSL_EXPORT void X509_STORE_CTX_set0_param(X509_STORE_CTX *ctx, + X509_VERIFY_PARAM *param); +OPENSSL_EXPORT int X509_STORE_CTX_set_default(X509_STORE_CTX *ctx, + const char *name); + +// X509_VERIFY_PARAM functions + +OPENSSL_EXPORT X509_VERIFY_PARAM *X509_VERIFY_PARAM_new(void); +OPENSSL_EXPORT void X509_VERIFY_PARAM_free(X509_VERIFY_PARAM *param); +OPENSSL_EXPORT int X509_VERIFY_PARAM_inherit(X509_VERIFY_PARAM *to, + const X509_VERIFY_PARAM *from); +OPENSSL_EXPORT int X509_VERIFY_PARAM_set1(X509_VERIFY_PARAM *to, + const X509_VERIFY_PARAM *from); +OPENSSL_EXPORT int X509_VERIFY_PARAM_set1_name(X509_VERIFY_PARAM *param, + const char *name); +OPENSSL_EXPORT int X509_VERIFY_PARAM_set_flags(X509_VERIFY_PARAM *param, + unsigned long flags); +OPENSSL_EXPORT int X509_VERIFY_PARAM_clear_flags(X509_VERIFY_PARAM *param, + unsigned long flags); +OPENSSL_EXPORT unsigned long X509_VERIFY_PARAM_get_flags( + X509_VERIFY_PARAM *param); +OPENSSL_EXPORT int X509_VERIFY_PARAM_set_purpose(X509_VERIFY_PARAM *param, + int purpose); +OPENSSL_EXPORT int X509_VERIFY_PARAM_set_trust(X509_VERIFY_PARAM *param, + int trust); +OPENSSL_EXPORT void X509_VERIFY_PARAM_set_depth(X509_VERIFY_PARAM *param, + int depth); +OPENSSL_EXPORT void X509_VERIFY_PARAM_set_time(X509_VERIFY_PARAM *param, + time_t t); +OPENSSL_EXPORT int X509_VERIFY_PARAM_add0_policy(X509_VERIFY_PARAM *param, + ASN1_OBJECT *policy); +OPENSSL_EXPORT int X509_VERIFY_PARAM_set1_policies( + X509_VERIFY_PARAM *param, STACK_OF(ASN1_OBJECT) *policies); + +OPENSSL_EXPORT int X509_VERIFY_PARAM_set1_host(X509_VERIFY_PARAM *param, + const char *name, + size_t namelen); +OPENSSL_EXPORT int X509_VERIFY_PARAM_add1_host(X509_VERIFY_PARAM *param, + const char *name, + size_t namelen); +OPENSSL_EXPORT void X509_VERIFY_PARAM_set_hostflags(X509_VERIFY_PARAM *param, + unsigned int flags); +OPENSSL_EXPORT char *X509_VERIFY_PARAM_get0_peername(X509_VERIFY_PARAM *); +OPENSSL_EXPORT int X509_VERIFY_PARAM_set1_email(X509_VERIFY_PARAM *param, + const char *email, + size_t emaillen); +OPENSSL_EXPORT int X509_VERIFY_PARAM_set1_ip(X509_VERIFY_PARAM *param, + const unsigned char *ip, + size_t iplen); +OPENSSL_EXPORT int X509_VERIFY_PARAM_set1_ip_asc(X509_VERIFY_PARAM *param, + const char *ipasc); + +OPENSSL_EXPORT int X509_VERIFY_PARAM_get_depth(const X509_VERIFY_PARAM *param); +OPENSSL_EXPORT const char *X509_VERIFY_PARAM_get0_name( + const X509_VERIFY_PARAM *param); + +OPENSSL_EXPORT int X509_VERIFY_PARAM_add0_table(X509_VERIFY_PARAM *param); +OPENSSL_EXPORT int X509_VERIFY_PARAM_get_count(void); +OPENSSL_EXPORT const X509_VERIFY_PARAM *X509_VERIFY_PARAM_get0(int id); +OPENSSL_EXPORT const X509_VERIFY_PARAM *X509_VERIFY_PARAM_lookup( + const char *name); +OPENSSL_EXPORT void X509_VERIFY_PARAM_table_cleanup(void); + +OPENSSL_EXPORT int X509_policy_check(X509_POLICY_TREE **ptree, + int *pexplicit_policy, + STACK_OF(X509) *certs, + STACK_OF(ASN1_OBJECT) *policy_oids, + unsigned int flags); + +OPENSSL_EXPORT void X509_policy_tree_free(X509_POLICY_TREE *tree); + +OPENSSL_EXPORT int X509_policy_tree_level_count(const X509_POLICY_TREE *tree); +OPENSSL_EXPORT X509_POLICY_LEVEL *X509_policy_tree_get0_level( + const X509_POLICY_TREE *tree, int i); + +OPENSSL_EXPORT STACK_OF(X509_POLICY_NODE) *X509_policy_tree_get0_policies( + const X509_POLICY_TREE *tree); + +OPENSSL_EXPORT STACK_OF(X509_POLICY_NODE) *X509_policy_tree_get0_user_policies( + const X509_POLICY_TREE *tree); + +OPENSSL_EXPORT int X509_policy_level_node_count(X509_POLICY_LEVEL *level); + +OPENSSL_EXPORT X509_POLICY_NODE *X509_policy_level_get0_node( + X509_POLICY_LEVEL *level, int i); + +OPENSSL_EXPORT const ASN1_OBJECT *X509_policy_node_get0_policy( + const X509_POLICY_NODE *node); + +OPENSSL_EXPORT STACK_OF(POLICYQUALINFO) *X509_policy_node_get0_qualifiers( + const X509_POLICY_NODE *node); +OPENSSL_EXPORT const X509_POLICY_NODE *X509_policy_node_get0_parent( + const X509_POLICY_NODE *node); -#ifdef __cplusplus -} +#if defined(__cplusplus) +} // extern C #endif #if !defined(BORINGSSL_NO_CXX) diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_x509_vfy.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_x509_vfy.h index 5f692b39..65ce4829 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_x509_vfy.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_x509_vfy.h @@ -1,571 +1,18 @@ -/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) - * All rights reserved. +/* Copyright (c) 2021, Google Inc. * - * This package is an SSL implementation written - * by Eric Young (eay@cryptsoft.com). - * The implementation was written so as to conform with Netscapes SSL. + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. * - * This library is free for commercial and non-commercial use as long as - * the following conditions are aheared to. The following conditions - * apply to all code found in this distribution, be it the RC4, RSA, - * lhash, DES, etc., code; not just the SSL code. The SSL documentation - * included with this distribution is covered by the same copyright terms - * except that the holder is Tim Hudson (tjh@cryptsoft.com). - * - * Copyright remains Eric Young's, and as such any Copyright notices in - * the code are not to be removed. - * If this package is used in a product, Eric Young should be given attribution - * as the author of the parts of the library used. - * This can be in the form of a textual message at program startup or - * in documentation (online or textual) provided with the package. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * "This product includes cryptographic software written by - * Eric Young (eay@cryptsoft.com)" - * The word 'cryptographic' can be left out if the rouines from the library - * being used are not cryptographic related :-). - * 4. If you include any Windows specific code (or a derivative thereof) from - * the apps directory (application code) you must include an acknowledgement: - * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" - * - * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * The licence and distribution terms for any publically available version or - * derivative of this code cannot be changed. i.e. this code cannot simply be - * copied and put under another distribution licence - * [including the GNU Public Licence.] - */ + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ + +/* This header is provided in order to make compiling against code that expects + OpenSSL easier. */ -#ifndef HEADER_X509_H #include "CCryptoBoringSSL_x509.h" -// openssl/x509.h ends up #include-ing this file at about the only -// appropriate moment. -#endif - -#ifndef HEADER_X509_VFY_H -#define HEADER_X509_VFY_H - -#include "CCryptoBoringSSL_thread.h" - -#ifdef __cplusplus -extern "C" { -#endif - -// Legacy X.509 library. -// -// This header is part of OpenSSL's X.509 implementation. It is retained for -// compatibility but otherwise underdocumented and not actively maintained. In -// the future, a replacement library will be available. Meanwhile, minimize -// dependencies on this header where possible. - - -/* -SSL_CTX -> X509_STORE - -> X509_LOOKUP - ->X509_LOOKUP_METHOD - -> X509_LOOKUP - ->X509_LOOKUP_METHOD - -SSL -> X509_STORE_CTX - ->X509_STORE - -The X509_STORE holds the tables etc for verification stuff. -A X509_STORE_CTX is used while validating a single certificate. -The X509_STORE has X509_LOOKUPs for looking up certs. -The X509_STORE then calls a function to actually verify the -certificate chain. -*/ - -#define X509_LU_X509 1 -#define X509_LU_CRL 2 -#define X509_LU_PKEY 3 - -DEFINE_STACK_OF(X509_LOOKUP) -DEFINE_STACK_OF(X509_OBJECT) -DEFINE_STACK_OF(X509_VERIFY_PARAM) - -typedef int (*X509_STORE_CTX_verify_cb)(int, X509_STORE_CTX *); -typedef int (*X509_STORE_CTX_verify_fn)(X509_STORE_CTX *); -typedef int (*X509_STORE_CTX_get_issuer_fn)(X509 **issuer, X509_STORE_CTX *ctx, - X509 *x); -typedef int (*X509_STORE_CTX_check_issued_fn)(X509_STORE_CTX *ctx, X509 *x, - X509 *issuer); -typedef int (*X509_STORE_CTX_check_revocation_fn)(X509_STORE_CTX *ctx); -typedef int (*X509_STORE_CTX_get_crl_fn)(X509_STORE_CTX *ctx, X509_CRL **crl, - X509 *x); -typedef int (*X509_STORE_CTX_check_crl_fn)(X509_STORE_CTX *ctx, X509_CRL *crl); -typedef int (*X509_STORE_CTX_cert_crl_fn)(X509_STORE_CTX *ctx, X509_CRL *crl, - X509 *x); -typedef int (*X509_STORE_CTX_check_policy_fn)(X509_STORE_CTX *ctx); -typedef STACK_OF(X509) *(*X509_STORE_CTX_lookup_certs_fn)(X509_STORE_CTX *ctx, - X509_NAME *nm); -typedef STACK_OF(X509_CRL) *(*X509_STORE_CTX_lookup_crls_fn)( - X509_STORE_CTX *ctx, X509_NAME *nm); -typedef int (*X509_STORE_CTX_cleanup_fn)(X509_STORE_CTX *ctx); - -OPENSSL_EXPORT int X509_STORE_set_depth(X509_STORE *store, int depth); - -OPENSSL_EXPORT void X509_STORE_CTX_set_depth(X509_STORE_CTX *ctx, int depth); - -#define X509_STORE_CTX_set_app_data(ctx, data) \ - X509_STORE_CTX_set_ex_data(ctx, 0, data) -#define X509_STORE_CTX_get_app_data(ctx) X509_STORE_CTX_get_ex_data(ctx, 0) - -#define X509_L_FILE_LOAD 1 -#define X509_L_ADD_DIR 2 - -#define X509_LOOKUP_load_file(x, name, type) \ - X509_LOOKUP_ctrl((x), X509_L_FILE_LOAD, (name), (long)(type), NULL) - -#define X509_LOOKUP_add_dir(x, name, type) \ - X509_LOOKUP_ctrl((x), X509_L_ADD_DIR, (name), (long)(type), NULL) - -#define X509_V_OK 0 -#define X509_V_ERR_UNSPECIFIED 1 - -#define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT 2 -#define X509_V_ERR_UNABLE_TO_GET_CRL 3 -#define X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE 4 -#define X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE 5 -#define X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY 6 -#define X509_V_ERR_CERT_SIGNATURE_FAILURE 7 -#define X509_V_ERR_CRL_SIGNATURE_FAILURE 8 -#define X509_V_ERR_CERT_NOT_YET_VALID 9 -#define X509_V_ERR_CERT_HAS_EXPIRED 10 -#define X509_V_ERR_CRL_NOT_YET_VALID 11 -#define X509_V_ERR_CRL_HAS_EXPIRED 12 -#define X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD 13 -#define X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD 14 -#define X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD 15 -#define X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD 16 -#define X509_V_ERR_OUT_OF_MEM 17 -#define X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT 18 -#define X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN 19 -#define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY 20 -#define X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE 21 -#define X509_V_ERR_CERT_CHAIN_TOO_LONG 22 -#define X509_V_ERR_CERT_REVOKED 23 -#define X509_V_ERR_INVALID_CA 24 -#define X509_V_ERR_PATH_LENGTH_EXCEEDED 25 -#define X509_V_ERR_INVALID_PURPOSE 26 -#define X509_V_ERR_CERT_UNTRUSTED 27 -#define X509_V_ERR_CERT_REJECTED 28 -// These are 'informational' when looking for issuer cert -#define X509_V_ERR_SUBJECT_ISSUER_MISMATCH 29 -#define X509_V_ERR_AKID_SKID_MISMATCH 30 -#define X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH 31 -#define X509_V_ERR_KEYUSAGE_NO_CERTSIGN 32 - -#define X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER 33 -#define X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION 34 -#define X509_V_ERR_KEYUSAGE_NO_CRL_SIGN 35 -#define X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION 36 -#define X509_V_ERR_INVALID_NON_CA 37 -#define X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED 38 -#define X509_V_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE 39 -#define X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED 40 - -#define X509_V_ERR_INVALID_EXTENSION 41 -#define X509_V_ERR_INVALID_POLICY_EXTENSION 42 -#define X509_V_ERR_NO_EXPLICIT_POLICY 43 -#define X509_V_ERR_DIFFERENT_CRL_SCOPE 44 -#define X509_V_ERR_UNSUPPORTED_EXTENSION_FEATURE 45 - -#define X509_V_ERR_UNNESTED_RESOURCE 46 - -#define X509_V_ERR_PERMITTED_VIOLATION 47 -#define X509_V_ERR_EXCLUDED_VIOLATION 48 -#define X509_V_ERR_SUBTREE_MINMAX 49 -#define X509_V_ERR_APPLICATION_VERIFICATION 50 -#define X509_V_ERR_UNSUPPORTED_CONSTRAINT_TYPE 51 -#define X509_V_ERR_UNSUPPORTED_CONSTRAINT_SYNTAX 52 -#define X509_V_ERR_UNSUPPORTED_NAME_SYNTAX 53 -#define X509_V_ERR_CRL_PATH_VALIDATION_ERROR 54 - -// Suite B mode algorithm violation -#define X509_V_ERR_SUITE_B_INVALID_VERSION 56 -#define X509_V_ERR_SUITE_B_INVALID_ALGORITHM 57 -#define X509_V_ERR_SUITE_B_INVALID_CURVE 58 -#define X509_V_ERR_SUITE_B_INVALID_SIGNATURE_ALGORITHM 59 -#define X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED 60 -#define X509_V_ERR_SUITE_B_CANNOT_SIGN_P_384_WITH_P_256 61 - -// Host, email and IP check errors -#define X509_V_ERR_HOSTNAME_MISMATCH 62 -#define X509_V_ERR_EMAIL_MISMATCH 63 -#define X509_V_ERR_IP_ADDRESS_MISMATCH 64 - -// Caller error -#define X509_V_ERR_INVALID_CALL 65 -// Issuer lookup error -#define X509_V_ERR_STORE_LOOKUP 66 - -#define X509_V_ERR_NAME_CONSTRAINTS_WITHOUT_SANS 67 - -// Certificate verify flags - -// Send issuer+subject checks to verify_cb -#define X509_V_FLAG_CB_ISSUER_CHECK 0x1 -// Use check time instead of current time -#define X509_V_FLAG_USE_CHECK_TIME 0x2 -// Lookup CRLs -#define X509_V_FLAG_CRL_CHECK 0x4 -// Lookup CRLs for whole chain -#define X509_V_FLAG_CRL_CHECK_ALL 0x8 -// Ignore unhandled critical extensions -#define X509_V_FLAG_IGNORE_CRITICAL 0x10 -// Does nothing as its functionality has been enabled by default. -#define X509_V_FLAG_X509_STRICT 0x00 -// Enable proxy certificate validation -#define X509_V_FLAG_ALLOW_PROXY_CERTS 0x40 -// Enable policy checking -#define X509_V_FLAG_POLICY_CHECK 0x80 -// Policy variable require-explicit-policy -#define X509_V_FLAG_EXPLICIT_POLICY 0x100 -// Policy variable inhibit-any-policy -#define X509_V_FLAG_INHIBIT_ANY 0x200 -// Policy variable inhibit-policy-mapping -#define X509_V_FLAG_INHIBIT_MAP 0x400 -// Notify callback that policy is OK -#define X509_V_FLAG_NOTIFY_POLICY 0x800 -// Extended CRL features such as indirect CRLs, alternate CRL signing keys -#define X509_V_FLAG_EXTENDED_CRL_SUPPORT 0x1000 -// Delta CRL support -#define X509_V_FLAG_USE_DELTAS 0x2000 -// Check selfsigned CA signature -#define X509_V_FLAG_CHECK_SS_SIGNATURE 0x4000 -// Use trusted store first -#define X509_V_FLAG_TRUSTED_FIRST 0x8000 -// Suite B 128 bit only mode: not normally used -#define X509_V_FLAG_SUITEB_128_LOS_ONLY 0x10000 -// Suite B 192 bit only mode -#define X509_V_FLAG_SUITEB_192_LOS 0x20000 -// Suite B 128 bit mode allowing 192 bit algorithms -#define X509_V_FLAG_SUITEB_128_LOS 0x30000 - -// Allow partial chains if at least one certificate is in trusted store -#define X509_V_FLAG_PARTIAL_CHAIN 0x80000 - -// If the initial chain is not trusted, do not attempt to build an alternative -// chain. Alternate chain checking was introduced in 1.0.2b. Setting this flag -// will force the behaviour to match that of previous versions. -#define X509_V_FLAG_NO_ALT_CHAINS 0x100000 - -#define X509_VP_FLAG_DEFAULT 0x1 -#define X509_VP_FLAG_OVERWRITE 0x2 -#define X509_VP_FLAG_RESET_FLAGS 0x4 -#define X509_VP_FLAG_LOCKED 0x8 -#define X509_VP_FLAG_ONCE 0x10 - -// Internal use: mask of policy related options -#define X509_V_FLAG_POLICY_MASK \ - (X509_V_FLAG_POLICY_CHECK | X509_V_FLAG_EXPLICIT_POLICY | \ - X509_V_FLAG_INHIBIT_ANY | X509_V_FLAG_INHIBIT_MAP) - -OPENSSL_EXPORT int X509_OBJECT_idx_by_subject(STACK_OF(X509_OBJECT) *h, - int type, X509_NAME *name); -OPENSSL_EXPORT X509_OBJECT *X509_OBJECT_retrieve_by_subject( - STACK_OF(X509_OBJECT) *h, int type, X509_NAME *name); -OPENSSL_EXPORT X509_OBJECT *X509_OBJECT_retrieve_match(STACK_OF(X509_OBJECT) *h, - X509_OBJECT *x); -OPENSSL_EXPORT int X509_OBJECT_up_ref_count(X509_OBJECT *a); -OPENSSL_EXPORT void X509_OBJECT_free_contents(X509_OBJECT *a); -OPENSSL_EXPORT int X509_OBJECT_get_type(const X509_OBJECT *a); -OPENSSL_EXPORT X509 *X509_OBJECT_get0_X509(const X509_OBJECT *a); -OPENSSL_EXPORT X509_STORE *X509_STORE_new(void); -OPENSSL_EXPORT int X509_STORE_up_ref(X509_STORE *store); -OPENSSL_EXPORT void X509_STORE_free(X509_STORE *v); - -OPENSSL_EXPORT STACK_OF(X509_OBJECT) *X509_STORE_get0_objects(X509_STORE *st); -OPENSSL_EXPORT STACK_OF(X509) *X509_STORE_get1_certs(X509_STORE_CTX *st, - X509_NAME *nm); -OPENSSL_EXPORT STACK_OF(X509_CRL) *X509_STORE_get1_crls(X509_STORE_CTX *st, - X509_NAME *nm); -OPENSSL_EXPORT int X509_STORE_set_flags(X509_STORE *ctx, unsigned long flags); -OPENSSL_EXPORT int X509_STORE_set_purpose(X509_STORE *ctx, int purpose); -OPENSSL_EXPORT int X509_STORE_set_trust(X509_STORE *ctx, int trust); -OPENSSL_EXPORT int X509_STORE_set1_param(X509_STORE *ctx, - X509_VERIFY_PARAM *pm); -OPENSSL_EXPORT X509_VERIFY_PARAM *X509_STORE_get0_param(X509_STORE *ctx); -// X509_STORE_set0_additional_untrusted sets a stack of additional, untrusted -// certificates that are available for chain building. This function does not -// take ownership of the stack. -OPENSSL_EXPORT void X509_STORE_set0_additional_untrusted( - X509_STORE *ctx, STACK_OF(X509) *untrusted); - -OPENSSL_EXPORT void X509_STORE_set_verify(X509_STORE *ctx, - X509_STORE_CTX_verify_fn verify); -#define X509_STORE_set_verify_func(ctx, func) \ - X509_STORE_set_verify((ctx), (func)) -OPENSSL_EXPORT void X509_STORE_CTX_set_verify(X509_STORE_CTX *ctx, - X509_STORE_CTX_verify_fn verify); -OPENSSL_EXPORT X509_STORE_CTX_verify_fn X509_STORE_get_verify(X509_STORE *ctx); -OPENSSL_EXPORT void X509_STORE_set_verify_cb( - X509_STORE *ctx, X509_STORE_CTX_verify_cb verify_cb); -#define X509_STORE_set_verify_cb_func(ctx, func) \ - X509_STORE_set_verify_cb((ctx), (func)) -OPENSSL_EXPORT X509_STORE_CTX_verify_cb -X509_STORE_get_verify_cb(X509_STORE *ctx); -OPENSSL_EXPORT void X509_STORE_set_get_issuer( - X509_STORE *ctx, X509_STORE_CTX_get_issuer_fn get_issuer); -OPENSSL_EXPORT X509_STORE_CTX_get_issuer_fn -X509_STORE_get_get_issuer(X509_STORE *ctx); -OPENSSL_EXPORT void X509_STORE_set_check_issued( - X509_STORE *ctx, X509_STORE_CTX_check_issued_fn check_issued); -OPENSSL_EXPORT X509_STORE_CTX_check_issued_fn -X509_STORE_get_check_issued(X509_STORE *ctx); -OPENSSL_EXPORT void X509_STORE_set_check_revocation( - X509_STORE *ctx, X509_STORE_CTX_check_revocation_fn check_revocation); -OPENSSL_EXPORT X509_STORE_CTX_check_revocation_fn -X509_STORE_get_check_revocation(X509_STORE *ctx); -OPENSSL_EXPORT void X509_STORE_set_get_crl(X509_STORE *ctx, - X509_STORE_CTX_get_crl_fn get_crl); -OPENSSL_EXPORT X509_STORE_CTX_get_crl_fn -X509_STORE_get_get_crl(X509_STORE *ctx); -OPENSSL_EXPORT void X509_STORE_set_check_crl( - X509_STORE *ctx, X509_STORE_CTX_check_crl_fn check_crl); -OPENSSL_EXPORT X509_STORE_CTX_check_crl_fn -X509_STORE_get_check_crl(X509_STORE *ctx); -OPENSSL_EXPORT void X509_STORE_set_cert_crl( - X509_STORE *ctx, X509_STORE_CTX_cert_crl_fn cert_crl); -OPENSSL_EXPORT X509_STORE_CTX_cert_crl_fn -X509_STORE_get_cert_crl(X509_STORE *ctx); -OPENSSL_EXPORT void X509_STORE_set_lookup_certs( - X509_STORE *ctx, X509_STORE_CTX_lookup_certs_fn lookup_certs); -OPENSSL_EXPORT X509_STORE_CTX_lookup_certs_fn -X509_STORE_get_lookup_certs(X509_STORE *ctx); -OPENSSL_EXPORT void X509_STORE_set_lookup_crls( - X509_STORE *ctx, X509_STORE_CTX_lookup_crls_fn lookup_crls); -#define X509_STORE_set_lookup_crls_cb(ctx, func) \ - X509_STORE_set_lookup_crls((ctx), (func)) -OPENSSL_EXPORT X509_STORE_CTX_lookup_crls_fn -X509_STORE_get_lookup_crls(X509_STORE *ctx); -OPENSSL_EXPORT void X509_STORE_set_cleanup(X509_STORE *ctx, - X509_STORE_CTX_cleanup_fn cleanup); -OPENSSL_EXPORT X509_STORE_CTX_cleanup_fn -X509_STORE_get_cleanup(X509_STORE *ctx); - - -OPENSSL_EXPORT X509_STORE_CTX *X509_STORE_CTX_new(void); - -OPENSSL_EXPORT int X509_STORE_CTX_get1_issuer(X509 **issuer, - X509_STORE_CTX *ctx, X509 *x); - -OPENSSL_EXPORT void X509_STORE_CTX_zero(X509_STORE_CTX *ctx); -OPENSSL_EXPORT void X509_STORE_CTX_free(X509_STORE_CTX *ctx); -OPENSSL_EXPORT int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, - X509 *x509, STACK_OF(X509) *chain); -OPENSSL_EXPORT void X509_STORE_CTX_trusted_stack(X509_STORE_CTX *ctx, - STACK_OF(X509) *sk); -OPENSSL_EXPORT void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx); - -OPENSSL_EXPORT X509_STORE *X509_STORE_CTX_get0_store(X509_STORE_CTX *ctx); -OPENSSL_EXPORT X509 *X509_STORE_CTX_get0_cert(X509_STORE_CTX *ctx); - -OPENSSL_EXPORT X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *v, - X509_LOOKUP_METHOD *m); - -OPENSSL_EXPORT X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir(void); -OPENSSL_EXPORT X509_LOOKUP_METHOD *X509_LOOKUP_file(void); - -OPENSSL_EXPORT int X509_STORE_add_cert(X509_STORE *ctx, X509 *x); -OPENSSL_EXPORT int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x); - -OPENSSL_EXPORT int X509_STORE_get_by_subject(X509_STORE_CTX *vs, int type, - X509_NAME *name, X509_OBJECT *ret); - -OPENSSL_EXPORT int X509_LOOKUP_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc, - long argl, char **ret); - -#ifndef OPENSSL_NO_STDIO -OPENSSL_EXPORT int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, - int type); -OPENSSL_EXPORT int X509_load_crl_file(X509_LOOKUP *ctx, const char *file, - int type); -OPENSSL_EXPORT int X509_load_cert_crl_file(X509_LOOKUP *ctx, const char *file, - int type); -#endif - - -OPENSSL_EXPORT X509_LOOKUP *X509_LOOKUP_new(X509_LOOKUP_METHOD *method); -OPENSSL_EXPORT void X509_LOOKUP_free(X509_LOOKUP *ctx); -OPENSSL_EXPORT int X509_LOOKUP_init(X509_LOOKUP *ctx); -OPENSSL_EXPORT int X509_LOOKUP_by_subject(X509_LOOKUP *ctx, int type, - X509_NAME *name, X509_OBJECT *ret); -OPENSSL_EXPORT int X509_LOOKUP_by_issuer_serial(X509_LOOKUP *ctx, int type, - X509_NAME *name, - ASN1_INTEGER *serial, - X509_OBJECT *ret); -OPENSSL_EXPORT int X509_LOOKUP_by_fingerprint(X509_LOOKUP *ctx, int type, - unsigned char *bytes, int len, - X509_OBJECT *ret); -OPENSSL_EXPORT int X509_LOOKUP_by_alias(X509_LOOKUP *ctx, int type, char *str, - int len, X509_OBJECT *ret); -OPENSSL_EXPORT int X509_LOOKUP_shutdown(X509_LOOKUP *ctx); - -#ifndef OPENSSL_NO_STDIO -OPENSSL_EXPORT int X509_STORE_load_locations(X509_STORE *ctx, const char *file, - const char *dir); -OPENSSL_EXPORT int X509_STORE_set_default_paths(X509_STORE *ctx); -#endif - -OPENSSL_EXPORT int X509_STORE_CTX_get_ex_new_index(long argl, void *argp, - CRYPTO_EX_unused *unused, - CRYPTO_EX_dup *dup_unused, - CRYPTO_EX_free *free_func); -OPENSSL_EXPORT int X509_STORE_CTX_set_ex_data(X509_STORE_CTX *ctx, int idx, - void *data); -OPENSSL_EXPORT void *X509_STORE_CTX_get_ex_data(X509_STORE_CTX *ctx, int idx); -OPENSSL_EXPORT int X509_STORE_CTX_get_error(X509_STORE_CTX *ctx); -OPENSSL_EXPORT void X509_STORE_CTX_set_error(X509_STORE_CTX *ctx, int s); -OPENSSL_EXPORT int X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx); -OPENSSL_EXPORT X509 *X509_STORE_CTX_get_current_cert(X509_STORE_CTX *ctx); -OPENSSL_EXPORT X509 *X509_STORE_CTX_get0_current_issuer(X509_STORE_CTX *ctx); -OPENSSL_EXPORT X509_CRL *X509_STORE_CTX_get0_current_crl(X509_STORE_CTX *ctx); -OPENSSL_EXPORT X509_STORE_CTX *X509_STORE_CTX_get0_parent_ctx( - X509_STORE_CTX *ctx); -OPENSSL_EXPORT STACK_OF(X509) *X509_STORE_CTX_get_chain(X509_STORE_CTX *ctx); -OPENSSL_EXPORT STACK_OF(X509) *X509_STORE_CTX_get0_chain(X509_STORE_CTX *ctx); -OPENSSL_EXPORT STACK_OF(X509) *X509_STORE_CTX_get1_chain(X509_STORE_CTX *ctx); -OPENSSL_EXPORT void X509_STORE_CTX_set_cert(X509_STORE_CTX *c, X509 *x); -OPENSSL_EXPORT void X509_STORE_CTX_set_chain(X509_STORE_CTX *c, - STACK_OF(X509) *sk); -OPENSSL_EXPORT STACK_OF(X509) *X509_STORE_CTX_get0_untrusted( - X509_STORE_CTX *ctx); -OPENSSL_EXPORT void X509_STORE_CTX_set0_crls(X509_STORE_CTX *c, - STACK_OF(X509_CRL) *sk); -OPENSSL_EXPORT int X509_STORE_CTX_set_purpose(X509_STORE_CTX *ctx, int purpose); -OPENSSL_EXPORT int X509_STORE_CTX_set_trust(X509_STORE_CTX *ctx, int trust); -OPENSSL_EXPORT int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, - int def_purpose, int purpose, - int trust); -OPENSSL_EXPORT void X509_STORE_CTX_set_flags(X509_STORE_CTX *ctx, - unsigned long flags); -OPENSSL_EXPORT void X509_STORE_CTX_set_time(X509_STORE_CTX *ctx, - unsigned long flags, time_t t); -OPENSSL_EXPORT void X509_STORE_CTX_set_verify_cb( - X509_STORE_CTX *ctx, int (*verify_cb)(int, X509_STORE_CTX *)); - -OPENSSL_EXPORT X509_POLICY_TREE *X509_STORE_CTX_get0_policy_tree( - X509_STORE_CTX *ctx); -OPENSSL_EXPORT int X509_STORE_CTX_get_explicit_policy(X509_STORE_CTX *ctx); - -OPENSSL_EXPORT X509_VERIFY_PARAM *X509_STORE_CTX_get0_param( - X509_STORE_CTX *ctx); -OPENSSL_EXPORT void X509_STORE_CTX_set0_param(X509_STORE_CTX *ctx, - X509_VERIFY_PARAM *param); -OPENSSL_EXPORT int X509_STORE_CTX_set_default(X509_STORE_CTX *ctx, - const char *name); - -// X509_VERIFY_PARAM functions - -OPENSSL_EXPORT X509_VERIFY_PARAM *X509_VERIFY_PARAM_new(void); -OPENSSL_EXPORT void X509_VERIFY_PARAM_free(X509_VERIFY_PARAM *param); -OPENSSL_EXPORT int X509_VERIFY_PARAM_inherit(X509_VERIFY_PARAM *to, - const X509_VERIFY_PARAM *from); -OPENSSL_EXPORT int X509_VERIFY_PARAM_set1(X509_VERIFY_PARAM *to, - const X509_VERIFY_PARAM *from); -OPENSSL_EXPORT int X509_VERIFY_PARAM_set1_name(X509_VERIFY_PARAM *param, - const char *name); -OPENSSL_EXPORT int X509_VERIFY_PARAM_set_flags(X509_VERIFY_PARAM *param, - unsigned long flags); -OPENSSL_EXPORT int X509_VERIFY_PARAM_clear_flags(X509_VERIFY_PARAM *param, - unsigned long flags); -OPENSSL_EXPORT unsigned long X509_VERIFY_PARAM_get_flags( - X509_VERIFY_PARAM *param); -OPENSSL_EXPORT int X509_VERIFY_PARAM_set_purpose(X509_VERIFY_PARAM *param, - int purpose); -OPENSSL_EXPORT int X509_VERIFY_PARAM_set_trust(X509_VERIFY_PARAM *param, - int trust); -OPENSSL_EXPORT void X509_VERIFY_PARAM_set_depth(X509_VERIFY_PARAM *param, - int depth); -OPENSSL_EXPORT void X509_VERIFY_PARAM_set_time(X509_VERIFY_PARAM *param, - time_t t); -OPENSSL_EXPORT int X509_VERIFY_PARAM_add0_policy(X509_VERIFY_PARAM *param, - ASN1_OBJECT *policy); -OPENSSL_EXPORT int X509_VERIFY_PARAM_set1_policies( - X509_VERIFY_PARAM *param, STACK_OF(ASN1_OBJECT) *policies); - -OPENSSL_EXPORT int X509_VERIFY_PARAM_set1_host(X509_VERIFY_PARAM *param, - const char *name, - size_t namelen); -OPENSSL_EXPORT int X509_VERIFY_PARAM_add1_host(X509_VERIFY_PARAM *param, - const char *name, - size_t namelen); -OPENSSL_EXPORT void X509_VERIFY_PARAM_set_hostflags(X509_VERIFY_PARAM *param, - unsigned int flags); -OPENSSL_EXPORT char *X509_VERIFY_PARAM_get0_peername(X509_VERIFY_PARAM *); -OPENSSL_EXPORT int X509_VERIFY_PARAM_set1_email(X509_VERIFY_PARAM *param, - const char *email, - size_t emaillen); -OPENSSL_EXPORT int X509_VERIFY_PARAM_set1_ip(X509_VERIFY_PARAM *param, - const unsigned char *ip, - size_t iplen); -OPENSSL_EXPORT int X509_VERIFY_PARAM_set1_ip_asc(X509_VERIFY_PARAM *param, - const char *ipasc); - -OPENSSL_EXPORT int X509_VERIFY_PARAM_get_depth(const X509_VERIFY_PARAM *param); -OPENSSL_EXPORT const char *X509_VERIFY_PARAM_get0_name( - const X509_VERIFY_PARAM *param); - -OPENSSL_EXPORT int X509_VERIFY_PARAM_add0_table(X509_VERIFY_PARAM *param); -OPENSSL_EXPORT int X509_VERIFY_PARAM_get_count(void); -OPENSSL_EXPORT const X509_VERIFY_PARAM *X509_VERIFY_PARAM_get0(int id); -OPENSSL_EXPORT const X509_VERIFY_PARAM *X509_VERIFY_PARAM_lookup( - const char *name); -OPENSSL_EXPORT void X509_VERIFY_PARAM_table_cleanup(void); - -OPENSSL_EXPORT int X509_policy_check(X509_POLICY_TREE **ptree, - int *pexplicit_policy, - STACK_OF(X509) *certs, - STACK_OF(ASN1_OBJECT) *policy_oids, - unsigned int flags); - -OPENSSL_EXPORT void X509_policy_tree_free(X509_POLICY_TREE *tree); - -OPENSSL_EXPORT int X509_policy_tree_level_count(const X509_POLICY_TREE *tree); -OPENSSL_EXPORT X509_POLICY_LEVEL *X509_policy_tree_get0_level( - const X509_POLICY_TREE *tree, int i); - -OPENSSL_EXPORT STACK_OF(X509_POLICY_NODE) *X509_policy_tree_get0_policies( - const X509_POLICY_TREE *tree); - -OPENSSL_EXPORT STACK_OF(X509_POLICY_NODE) *X509_policy_tree_get0_user_policies( - const X509_POLICY_TREE *tree); - -OPENSSL_EXPORT int X509_policy_level_node_count(X509_POLICY_LEVEL *level); - -OPENSSL_EXPORT X509_POLICY_NODE *X509_policy_level_get0_node( - X509_POLICY_LEVEL *level, int i); - -OPENSSL_EXPORT const ASN1_OBJECT *X509_policy_node_get0_policy( - const X509_POLICY_NODE *node); - -OPENSSL_EXPORT STACK_OF(POLICYQUALINFO) *X509_policy_node_get0_qualifiers( - const X509_POLICY_NODE *node); -OPENSSL_EXPORT const X509_POLICY_NODE *X509_policy_node_get0_parent( - const X509_POLICY_NODE *node); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_x509v3.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_x509v3.h index d08da56c..daf30b13 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_x509v3.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_x509v3.h @@ -60,7 +60,7 @@ #include "CCryptoBoringSSL_lhash.h" #include "CCryptoBoringSSL_x509.h" -#ifdef __cplusplus +#if defined(__cplusplus) extern "C" { #endif @@ -928,8 +928,8 @@ DEFINE_STACK_OF(X509_POLICY_NODE) // made after this point may be overwritten when the script is next run. -#ifdef __cplusplus -} +#if defined(__cplusplus) +} // extern C extern "C++" { @@ -1016,5 +1016,6 @@ BSSL_NAMESPACE_END #define X509V3_R_UNSUPPORTED_TYPE 161 #define X509V3_R_USER_TOO_LONG 162 #define X509V3_R_INVALID_VALUE 163 +#define X509V3_R_TRAILING_DATA_IN_EXTENSION 164 #endif diff --git a/Sources/CCryptoBoringSSL/include/boringssl_prefix_symbols_nasm.inc b/Sources/CCryptoBoringSSL/include/boringssl_prefix_symbols_nasm.inc index fc8499d7..0fdbbd47 100644 --- a/Sources/CCryptoBoringSSL/include/boringssl_prefix_symbols_nasm.inc +++ b/Sources/CCryptoBoringSSL/include/boringssl_prefix_symbols_nasm.inc @@ -99,7 +99,6 @@ %xdefine _ASN1_SET_ANY_it _ %+ BORINGSSL_PREFIX %+ _ASN1_SET_ANY_it %xdefine _ASN1_STRING_TABLE_add _ %+ BORINGSSL_PREFIX %+ _ASN1_STRING_TABLE_add %xdefine _ASN1_STRING_TABLE_cleanup _ %+ BORINGSSL_PREFIX %+ _ASN1_STRING_TABLE_cleanup -%xdefine _ASN1_STRING_TABLE_get _ %+ BORINGSSL_PREFIX %+ _ASN1_STRING_TABLE_get %xdefine _ASN1_STRING_cmp _ %+ BORINGSSL_PREFIX %+ _ASN1_STRING_cmp %xdefine _ASN1_STRING_copy _ %+ BORINGSSL_PREFIX %+ _ASN1_STRING_copy %xdefine _ASN1_STRING_data _ %+ BORINGSSL_PREFIX %+ _ASN1_STRING_data @@ -159,7 +158,6 @@ %xdefine _ASN1_VISIBLESTRING_it _ %+ BORINGSSL_PREFIX %+ _ASN1_VISIBLESTRING_it %xdefine _ASN1_VISIBLESTRING_new _ %+ BORINGSSL_PREFIX %+ _ASN1_VISIBLESTRING_new %xdefine _ASN1_digest _ %+ BORINGSSL_PREFIX %+ _ASN1_digest -%xdefine _ASN1_generate_nconf _ %+ BORINGSSL_PREFIX %+ _ASN1_generate_nconf %xdefine _ASN1_generate_v3 _ %+ BORINGSSL_PREFIX %+ _ASN1_generate_v3 %xdefine _ASN1_get_object _ %+ BORINGSSL_PREFIX %+ _ASN1_get_object %xdefine _ASN1_item_d2i _ %+ BORINGSSL_PREFIX %+ _ASN1_item_d2i @@ -545,6 +543,7 @@ %xdefine _CRYPTO_BUFFER_len _ %+ BORINGSSL_PREFIX %+ _CRYPTO_BUFFER_len %xdefine _CRYPTO_BUFFER_new _ %+ BORINGSSL_PREFIX %+ _CRYPTO_BUFFER_new %xdefine _CRYPTO_BUFFER_new_from_CBS _ %+ BORINGSSL_PREFIX %+ _CRYPTO_BUFFER_new_from_CBS +%xdefine _CRYPTO_BUFFER_new_from_static_data_unsafe _ %+ BORINGSSL_PREFIX %+ _CRYPTO_BUFFER_new_from_static_data_unsafe %xdefine _CRYPTO_BUFFER_up_ref _ %+ BORINGSSL_PREFIX %+ _CRYPTO_BUFFER_up_ref %xdefine _CRYPTO_MUTEX_cleanup _ %+ BORINGSSL_PREFIX %+ _CRYPTO_MUTEX_cleanup %xdefine _CRYPTO_MUTEX_init _ %+ BORINGSSL_PREFIX %+ _CRYPTO_MUTEX_init @@ -573,6 +572,7 @@ %xdefine _CRYPTO_ctr128_encrypt _ %+ BORINGSSL_PREFIX %+ _CRYPTO_ctr128_encrypt %xdefine _CRYPTO_ctr128_encrypt_ctr32 _ %+ BORINGSSL_PREFIX %+ _CRYPTO_ctr128_encrypt_ctr32 %xdefine _CRYPTO_fork_detect_ignore_madv_wipeonfork_for_testing _ %+ BORINGSSL_PREFIX %+ _CRYPTO_fork_detect_ignore_madv_wipeonfork_for_testing +%xdefine _CRYPTO_free _ %+ BORINGSSL_PREFIX %+ _CRYPTO_free %xdefine _CRYPTO_free_ex_data _ %+ BORINGSSL_PREFIX %+ _CRYPTO_free_ex_data %xdefine _CRYPTO_gcm128_aad _ %+ BORINGSSL_PREFIX %+ _CRYPTO_gcm128_aad %xdefine _CRYPTO_gcm128_decrypt _ %+ BORINGSSL_PREFIX %+ _CRYPTO_gcm128_decrypt @@ -601,6 +601,7 @@ %xdefine _CRYPTO_is_NEON_capable_at_runtime _ %+ BORINGSSL_PREFIX %+ _CRYPTO_is_NEON_capable_at_runtime %xdefine _CRYPTO_is_confidential_build _ %+ BORINGSSL_PREFIX %+ _CRYPTO_is_confidential_build %xdefine _CRYPTO_library_init _ %+ BORINGSSL_PREFIX %+ _CRYPTO_library_init +%xdefine _CRYPTO_malloc _ %+ BORINGSSL_PREFIX %+ _CRYPTO_malloc %xdefine _CRYPTO_malloc_init _ %+ BORINGSSL_PREFIX %+ _CRYPTO_malloc_init %xdefine _CRYPTO_memcmp _ %+ BORINGSSL_PREFIX %+ _CRYPTO_memcmp %xdefine _CRYPTO_new_ex_data _ %+ BORINGSSL_PREFIX %+ _CRYPTO_new_ex_data @@ -613,6 +614,7 @@ %xdefine _CRYPTO_pre_sandbox_init _ %+ BORINGSSL_PREFIX %+ _CRYPTO_pre_sandbox_init %xdefine _CRYPTO_rdrand _ %+ BORINGSSL_PREFIX %+ _CRYPTO_rdrand %xdefine _CRYPTO_rdrand_multiple8_buf _ %+ BORINGSSL_PREFIX %+ _CRYPTO_rdrand_multiple8_buf +%xdefine _CRYPTO_realloc _ %+ BORINGSSL_PREFIX %+ _CRYPTO_realloc %xdefine _CRYPTO_refcount_dec_and_test_zero _ %+ BORINGSSL_PREFIX %+ _CRYPTO_refcount_dec_and_test_zero %xdefine _CRYPTO_refcount_inc _ %+ BORINGSSL_PREFIX %+ _CRYPTO_refcount_inc %xdefine _CRYPTO_set_add_lock_callback _ %+ BORINGSSL_PREFIX %+ _CRYPTO_set_add_lock_callback @@ -1520,6 +1522,7 @@ %xdefine _RSA_get0_key _ %+ BORINGSSL_PREFIX %+ _RSA_get0_key %xdefine _RSA_get0_n _ %+ BORINGSSL_PREFIX %+ _RSA_get0_n %xdefine _RSA_get0_p _ %+ BORINGSSL_PREFIX %+ _RSA_get0_p +%xdefine _RSA_get0_pss_params _ %+ BORINGSSL_PREFIX %+ _RSA_get0_pss_params %xdefine _RSA_get0_q _ %+ BORINGSSL_PREFIX %+ _RSA_get0_q %xdefine _RSA_get_ex_data _ %+ BORINGSSL_PREFIX %+ _RSA_get_ex_data %xdefine _RSA_get_ex_new_index _ %+ BORINGSSL_PREFIX %+ _RSA_get_ex_new_index @@ -1962,7 +1965,6 @@ %xdefine _X509_STORE_get_verify_cb _ %+ BORINGSSL_PREFIX %+ _X509_STORE_get_verify_cb %xdefine _X509_STORE_load_locations _ %+ BORINGSSL_PREFIX %+ _X509_STORE_load_locations %xdefine _X509_STORE_new _ %+ BORINGSSL_PREFIX %+ _X509_STORE_new -%xdefine _X509_STORE_set0_additional_untrusted _ %+ BORINGSSL_PREFIX %+ _X509_STORE_set0_additional_untrusted %xdefine _X509_STORE_set1_param _ %+ BORINGSSL_PREFIX %+ _X509_STORE_set1_param %xdefine _X509_STORE_set_cert_crl _ %+ BORINGSSL_PREFIX %+ _X509_STORE_set_cert_crl %xdefine _X509_STORE_set_check_crl _ %+ BORINGSSL_PREFIX %+ _X509_STORE_set_check_crl @@ -2205,6 +2207,7 @@ %xdefine _aesgcmsiv_polyval_horner _ %+ BORINGSSL_PREFIX %+ _aesgcmsiv_polyval_horner %xdefine _aesni_gcm_decrypt _ %+ BORINGSSL_PREFIX %+ _aesni_gcm_decrypt %xdefine _aesni_gcm_encrypt _ %+ BORINGSSL_PREFIX %+ _aesni_gcm_encrypt +%xdefine _asn1_bit_string_length _ %+ BORINGSSL_PREFIX %+ _asn1_bit_string_length %xdefine _asn1_do_adb _ %+ BORINGSSL_PREFIX %+ _asn1_do_adb %xdefine _asn1_enc_free _ %+ BORINGSSL_PREFIX %+ _asn1_enc_free %xdefine _asn1_enc_init _ %+ BORINGSSL_PREFIX %+ _asn1_enc_init @@ -2213,6 +2216,7 @@ %xdefine _asn1_generalizedtime_to_tm _ %+ BORINGSSL_PREFIX %+ _asn1_generalizedtime_to_tm %xdefine _asn1_get_choice_selector _ %+ BORINGSSL_PREFIX %+ _asn1_get_choice_selector %xdefine _asn1_get_field_ptr _ %+ BORINGSSL_PREFIX %+ _asn1_get_field_ptr +%xdefine _asn1_get_string_table_for_testing _ %+ BORINGSSL_PREFIX %+ _asn1_get_string_table_for_testing %xdefine _asn1_is_printable _ %+ BORINGSSL_PREFIX %+ _asn1_is_printable %xdefine _asn1_item_combine_free _ %+ BORINGSSL_PREFIX %+ _asn1_item_combine_free %xdefine _asn1_refcount_dec_and_test_zero _ %+ BORINGSSL_PREFIX %+ _asn1_refcount_dec_and_test_zero @@ -2708,7 +2712,7 @@ %xdefine _pkcs12_iterations_acceptable _ %+ BORINGSSL_PREFIX %+ _pkcs12_iterations_acceptable %xdefine _pkcs12_key_gen _ %+ BORINGSSL_PREFIX %+ _pkcs12_key_gen %xdefine _pkcs12_pbe_encrypt_init _ %+ BORINGSSL_PREFIX %+ _pkcs12_pbe_encrypt_init -%xdefine _pkcs7_bundle _ %+ BORINGSSL_PREFIX %+ _pkcs7_bundle +%xdefine _pkcs7_add_signed_data _ %+ BORINGSSL_PREFIX %+ _pkcs7_add_signed_data %xdefine _pkcs7_parse_header _ %+ BORINGSSL_PREFIX %+ _pkcs7_parse_header %xdefine _pkcs8_pbe_decrypt _ %+ BORINGSSL_PREFIX %+ _pkcs8_pbe_decrypt %xdefine _pmbtoken_exp1_blind _ %+ BORINGSSL_PREFIX %+ _pmbtoken_exp1_blind @@ -2931,7 +2935,6 @@ %xdefine ASN1_SET_ANY_it BORINGSSL_PREFIX %+ _ASN1_SET_ANY_it %xdefine ASN1_STRING_TABLE_add BORINGSSL_PREFIX %+ _ASN1_STRING_TABLE_add %xdefine ASN1_STRING_TABLE_cleanup BORINGSSL_PREFIX %+ _ASN1_STRING_TABLE_cleanup -%xdefine ASN1_STRING_TABLE_get BORINGSSL_PREFIX %+ _ASN1_STRING_TABLE_get %xdefine ASN1_STRING_cmp BORINGSSL_PREFIX %+ _ASN1_STRING_cmp %xdefine ASN1_STRING_copy BORINGSSL_PREFIX %+ _ASN1_STRING_copy %xdefine ASN1_STRING_data BORINGSSL_PREFIX %+ _ASN1_STRING_data @@ -2991,7 +2994,6 @@ %xdefine ASN1_VISIBLESTRING_it BORINGSSL_PREFIX %+ _ASN1_VISIBLESTRING_it %xdefine ASN1_VISIBLESTRING_new BORINGSSL_PREFIX %+ _ASN1_VISIBLESTRING_new %xdefine ASN1_digest BORINGSSL_PREFIX %+ _ASN1_digest -%xdefine ASN1_generate_nconf BORINGSSL_PREFIX %+ _ASN1_generate_nconf %xdefine ASN1_generate_v3 BORINGSSL_PREFIX %+ _ASN1_generate_v3 %xdefine ASN1_get_object BORINGSSL_PREFIX %+ _ASN1_get_object %xdefine ASN1_item_d2i BORINGSSL_PREFIX %+ _ASN1_item_d2i @@ -3377,6 +3379,7 @@ %xdefine CRYPTO_BUFFER_len BORINGSSL_PREFIX %+ _CRYPTO_BUFFER_len %xdefine CRYPTO_BUFFER_new BORINGSSL_PREFIX %+ _CRYPTO_BUFFER_new %xdefine CRYPTO_BUFFER_new_from_CBS BORINGSSL_PREFIX %+ _CRYPTO_BUFFER_new_from_CBS +%xdefine CRYPTO_BUFFER_new_from_static_data_unsafe BORINGSSL_PREFIX %+ _CRYPTO_BUFFER_new_from_static_data_unsafe %xdefine CRYPTO_BUFFER_up_ref BORINGSSL_PREFIX %+ _CRYPTO_BUFFER_up_ref %xdefine CRYPTO_MUTEX_cleanup BORINGSSL_PREFIX %+ _CRYPTO_MUTEX_cleanup %xdefine CRYPTO_MUTEX_init BORINGSSL_PREFIX %+ _CRYPTO_MUTEX_init @@ -3405,6 +3408,7 @@ %xdefine CRYPTO_ctr128_encrypt BORINGSSL_PREFIX %+ _CRYPTO_ctr128_encrypt %xdefine CRYPTO_ctr128_encrypt_ctr32 BORINGSSL_PREFIX %+ _CRYPTO_ctr128_encrypt_ctr32 %xdefine CRYPTO_fork_detect_ignore_madv_wipeonfork_for_testing BORINGSSL_PREFIX %+ _CRYPTO_fork_detect_ignore_madv_wipeonfork_for_testing +%xdefine CRYPTO_free BORINGSSL_PREFIX %+ _CRYPTO_free %xdefine CRYPTO_free_ex_data BORINGSSL_PREFIX %+ _CRYPTO_free_ex_data %xdefine CRYPTO_gcm128_aad BORINGSSL_PREFIX %+ _CRYPTO_gcm128_aad %xdefine CRYPTO_gcm128_decrypt BORINGSSL_PREFIX %+ _CRYPTO_gcm128_decrypt @@ -3433,6 +3437,7 @@ %xdefine CRYPTO_is_NEON_capable_at_runtime BORINGSSL_PREFIX %+ _CRYPTO_is_NEON_capable_at_runtime %xdefine CRYPTO_is_confidential_build BORINGSSL_PREFIX %+ _CRYPTO_is_confidential_build %xdefine CRYPTO_library_init BORINGSSL_PREFIX %+ _CRYPTO_library_init +%xdefine CRYPTO_malloc BORINGSSL_PREFIX %+ _CRYPTO_malloc %xdefine CRYPTO_malloc_init BORINGSSL_PREFIX %+ _CRYPTO_malloc_init %xdefine CRYPTO_memcmp BORINGSSL_PREFIX %+ _CRYPTO_memcmp %xdefine CRYPTO_new_ex_data BORINGSSL_PREFIX %+ _CRYPTO_new_ex_data @@ -3445,6 +3450,7 @@ %xdefine CRYPTO_pre_sandbox_init BORINGSSL_PREFIX %+ _CRYPTO_pre_sandbox_init %xdefine CRYPTO_rdrand BORINGSSL_PREFIX %+ _CRYPTO_rdrand %xdefine CRYPTO_rdrand_multiple8_buf BORINGSSL_PREFIX %+ _CRYPTO_rdrand_multiple8_buf +%xdefine CRYPTO_realloc BORINGSSL_PREFIX %+ _CRYPTO_realloc %xdefine CRYPTO_refcount_dec_and_test_zero BORINGSSL_PREFIX %+ _CRYPTO_refcount_dec_and_test_zero %xdefine CRYPTO_refcount_inc BORINGSSL_PREFIX %+ _CRYPTO_refcount_inc %xdefine CRYPTO_set_add_lock_callback BORINGSSL_PREFIX %+ _CRYPTO_set_add_lock_callback @@ -4352,6 +4358,7 @@ %xdefine RSA_get0_key BORINGSSL_PREFIX %+ _RSA_get0_key %xdefine RSA_get0_n BORINGSSL_PREFIX %+ _RSA_get0_n %xdefine RSA_get0_p BORINGSSL_PREFIX %+ _RSA_get0_p +%xdefine RSA_get0_pss_params BORINGSSL_PREFIX %+ _RSA_get0_pss_params %xdefine RSA_get0_q BORINGSSL_PREFIX %+ _RSA_get0_q %xdefine RSA_get_ex_data BORINGSSL_PREFIX %+ _RSA_get_ex_data %xdefine RSA_get_ex_new_index BORINGSSL_PREFIX %+ _RSA_get_ex_new_index @@ -4794,7 +4801,6 @@ %xdefine X509_STORE_get_verify_cb BORINGSSL_PREFIX %+ _X509_STORE_get_verify_cb %xdefine X509_STORE_load_locations BORINGSSL_PREFIX %+ _X509_STORE_load_locations %xdefine X509_STORE_new BORINGSSL_PREFIX %+ _X509_STORE_new -%xdefine X509_STORE_set0_additional_untrusted BORINGSSL_PREFIX %+ _X509_STORE_set0_additional_untrusted %xdefine X509_STORE_set1_param BORINGSSL_PREFIX %+ _X509_STORE_set1_param %xdefine X509_STORE_set_cert_crl BORINGSSL_PREFIX %+ _X509_STORE_set_cert_crl %xdefine X509_STORE_set_check_crl BORINGSSL_PREFIX %+ _X509_STORE_set_check_crl @@ -5037,6 +5043,7 @@ %xdefine aesgcmsiv_polyval_horner BORINGSSL_PREFIX %+ _aesgcmsiv_polyval_horner %xdefine aesni_gcm_decrypt BORINGSSL_PREFIX %+ _aesni_gcm_decrypt %xdefine aesni_gcm_encrypt BORINGSSL_PREFIX %+ _aesni_gcm_encrypt +%xdefine asn1_bit_string_length BORINGSSL_PREFIX %+ _asn1_bit_string_length %xdefine asn1_do_adb BORINGSSL_PREFIX %+ _asn1_do_adb %xdefine asn1_enc_free BORINGSSL_PREFIX %+ _asn1_enc_free %xdefine asn1_enc_init BORINGSSL_PREFIX %+ _asn1_enc_init @@ -5045,6 +5052,7 @@ %xdefine asn1_generalizedtime_to_tm BORINGSSL_PREFIX %+ _asn1_generalizedtime_to_tm %xdefine asn1_get_choice_selector BORINGSSL_PREFIX %+ _asn1_get_choice_selector %xdefine asn1_get_field_ptr BORINGSSL_PREFIX %+ _asn1_get_field_ptr +%xdefine asn1_get_string_table_for_testing BORINGSSL_PREFIX %+ _asn1_get_string_table_for_testing %xdefine asn1_is_printable BORINGSSL_PREFIX %+ _asn1_is_printable %xdefine asn1_item_combine_free BORINGSSL_PREFIX %+ _asn1_item_combine_free %xdefine asn1_refcount_dec_and_test_zero BORINGSSL_PREFIX %+ _asn1_refcount_dec_and_test_zero @@ -5540,7 +5548,7 @@ %xdefine pkcs12_iterations_acceptable BORINGSSL_PREFIX %+ _pkcs12_iterations_acceptable %xdefine pkcs12_key_gen BORINGSSL_PREFIX %+ _pkcs12_key_gen %xdefine pkcs12_pbe_encrypt_init BORINGSSL_PREFIX %+ _pkcs12_pbe_encrypt_init -%xdefine pkcs7_bundle BORINGSSL_PREFIX %+ _pkcs7_bundle +%xdefine pkcs7_add_signed_data BORINGSSL_PREFIX %+ _pkcs7_add_signed_data %xdefine pkcs7_parse_header BORINGSSL_PREFIX %+ _pkcs7_parse_header %xdefine pkcs8_pbe_decrypt BORINGSSL_PREFIX %+ _pkcs8_pbe_decrypt %xdefine pmbtoken_exp1_blind BORINGSSL_PREFIX %+ _pmbtoken_exp1_blind