diff --git a/Package.swift b/Package.swift index 5b0a5b64..03f3cad2 100644 --- a/Package.swift +++ b/Package.swift @@ -26,7 +26,7 @@ import class Foundation.ProcessInfo // Sources/CNIOBoringSSL directory. The source repository is at // https://boringssl.googlesource.com/boringssl. // -// BoringSSL Commit: c239ffd0552179f358de31517391679e9b62ccd3 +// BoringSSL Commit: 8462a367bb57e9524c3d8eca9c62733c63a63cf4 /// This function generates the dependencies we want to express. /// diff --git a/Sources/CNIOBoringSSL/crypto/asn1/a_gentm.c b/Sources/CNIOBoringSSL/crypto/asn1/a_gentm.c index fb90351c..c209995a 100644 --- a/Sources/CNIOBoringSSL/crypto/asn1/a_gentm.c +++ b/Sources/CNIOBoringSSL/crypto/asn1/a_gentm.c @@ -107,57 +107,42 @@ ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s, ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s, time_t t, int offset_day, long offset_sec) { - char *p; - struct tm *ts; struct tm data; - size_t len = 20; - ASN1_GENERALIZEDTIME *tmps = NULL; - - if (s == NULL) { - tmps = ASN1_GENERALIZEDTIME_new(); - } else { - tmps = s; - } - if (tmps == NULL) { + if (!OPENSSL_gmtime(&t, &data)) { return NULL; } - ts = OPENSSL_gmtime(&t, &data); - if (ts == NULL) { - goto err; - } - if (offset_day || offset_sec) { - if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) { - goto err; + if (!OPENSSL_gmtime_adj(&data, offset_day, offset_sec)) { + return NULL; } } - if (ts->tm_year < 0 - 1900 || ts->tm_year > 9999 - 1900) { + if (data.tm_year < 0 - 1900 || data.tm_year > 9999 - 1900) { OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_TIME_VALUE); - goto err; + return NULL; } - p = (char *)tmps->data; - if ((p == NULL) || ((size_t)tmps->length < len)) { - p = OPENSSL_malloc(len); - if (p == NULL) { - OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE); - goto err; - } - OPENSSL_free(tmps->data); - tmps->data = (unsigned char *)p; - } + char buf[16]; + BIO_snprintf(buf, sizeof(buf), "%04d%02d%02d%02d%02d%02dZ", + data.tm_year + 1900, data.tm_mon + 1, data.tm_mday, data.tm_hour, + data.tm_min, data.tm_sec); - BIO_snprintf(p, len, "%04d%02d%02d%02d%02d%02dZ", ts->tm_year + 1900, - ts->tm_mon + 1, ts->tm_mday, ts->tm_hour, ts->tm_min, - ts->tm_sec); - tmps->length = strlen(p); - tmps->type = V_ASN1_GENERALIZEDTIME; - return tmps; -err: + int free_s = 0; if (s == NULL) { - ASN1_GENERALIZEDTIME_free(tmps); + free_s = 1; + s = ASN1_UTCTIME_new(); + if (s == NULL) { + return NULL; + } } - return NULL; + + if (!ASN1_STRING_set(s, buf, strlen(buf))) { + if (free_s) { + ASN1_UTCTIME_free(s); + } + return NULL; + } + s->type = V_ASN1_GENERALIZEDTIME; + return s; } diff --git a/Sources/CNIOBoringSSL/crypto/asn1/a_int.c b/Sources/CNIOBoringSSL/crypto/asn1/a_int.c index a9549a49..22338e08 100644 --- a/Sources/CNIOBoringSSL/crypto/asn1/a_int.c +++ b/Sources/CNIOBoringSSL/crypto/asn1/a_int.c @@ -56,13 +56,13 @@ #include +#include #include #include #include #include #include -#include #include "../internal.h" @@ -353,7 +353,7 @@ static long asn1_string_get_long(const ASN1_STRING *a, int type) { i64 = (int64_t)v; fits_in_i64 = i64 >= 0; } - OPENSSL_STATIC_ASSERT(sizeof(long) <= sizeof(int64_t), "long is too big"); + static_assert(sizeof(long) <= sizeof(int64_t), "long is too big"); if (fits_in_i64 && LONG_MIN <= i64 && i64 <= LONG_MAX) { return (long)i64; diff --git a/Sources/CNIOBoringSSL/crypto/asn1/a_strex.c b/Sources/CNIOBoringSSL/crypto/asn1/a_strex.c index 3ce6fb7b..627d216c 100644 --- a/Sources/CNIOBoringSSL/crypto/asn1/a_strex.c +++ b/Sources/CNIOBoringSSL/crypto/asn1/a_strex.c @@ -66,6 +66,7 @@ #include #include +#include "../bytestring/internal.h" #include "internal.h" @@ -129,70 +130,46 @@ static int do_esc_char(uint32_t c, unsigned long flags, char *do_quotes, // appropriate. static int do_buf(const unsigned char *buf, int buflen, int encoding, - int utf8_convert, unsigned long flags, char *quotes, - BIO *out) { - // Reject invalid UCS-4 and UCS-2 lengths without parsing. + unsigned long flags, char *quotes, BIO *out) { + int (*get_char)(CBS *cbs, uint32_t *out); + int get_char_error; switch (encoding) { case MBSTRING_UNIV: - if (buflen & 3) { - OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_UNIVERSALSTRING); - return -1; - } + get_char = cbs_get_utf32_be; + get_char_error = ASN1_R_INVALID_UNIVERSALSTRING; break; case MBSTRING_BMP: - if (buflen & 1) { - OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_BMPSTRING); - return -1; - } + get_char = cbs_get_ucs2_be; + get_char_error = ASN1_R_INVALID_BMPSTRING; break; + case MBSTRING_ASC: + get_char = cbs_get_latin1; + get_char_error = ERR_R_INTERNAL_ERROR; // Should not be possible. + break; + case MBSTRING_UTF8: + get_char = cbs_get_utf8; + get_char_error = ASN1_R_INVALID_UTF8STRING; + break; + default: + assert(0); + return -1; } - const unsigned char *p = buf; - const unsigned char *q = buf + buflen; + CBS cbs; + CBS_init(&cbs, buf, buflen); int outlen = 0; - while (p != q) { - const int is_first = p == buf; - // TODO(davidben): Replace this with |cbs_get_ucs2_be|, etc., to check - // for invalid codepoints. Before doing that, enforce it in the parser, - // https://crbug.com/boringssl/427, so these error cases are not - // reachable from parsed objects. + while (CBS_len(&cbs) != 0) { + const int is_first = CBS_data(&cbs) == buf; uint32_t c; - switch (encoding) { - case MBSTRING_UNIV: - c = ((uint32_t)*p++) << 24; - c |= ((uint32_t)*p++) << 16; - c |= ((uint32_t)*p++) << 8; - c |= *p++; - break; - - case MBSTRING_BMP: - c = ((uint32_t)*p++) << 8; - c |= *p++; - break; - - case MBSTRING_ASC: - c = *p++; - break; - - case MBSTRING_UTF8: { - int consumed = UTF8_getc(p, buflen, &c); - if (consumed < 0) { - return -1; // Invalid UTF8String - } - buflen -= consumed; - p += consumed; - break; - } - - default: - assert(0); - return -1; + if (!get_char(&cbs, &c)) { + OPENSSL_PUT_ERROR(ASN1, get_char_error); + return -1; } - const int is_last = p == q; - if (utf8_convert) { + const int is_last = CBS_len(&cbs) == 0; + if (flags & ASN1_STRFLGS_UTF8_CONVERT) { unsigned char utfbuf[6]; int utflen; - utflen = UTF8_putc(utfbuf, sizeof utfbuf, c); + utflen = UTF8_putc(utfbuf, sizeof(utfbuf), c); for (int i = 0; i < utflen; i++) { int len = do_esc_char(utfbuf[i], flags, quotes, out, is_first && i == 0, is_last && i == utflen - 1); @@ -350,24 +327,9 @@ int ASN1_STRING_print_ex(BIO *out, const ASN1_STRING *str, return outlen; } - int utf8_convert = 0; - if (flags & ASN1_STRFLGS_UTF8_CONVERT) { - // If the string is UTF-8, skip decoding and just interpret it as 1 byte - // per character to avoid converting twice. - // - // TODO(davidben): This is not quite a valid optimization if the input - // was invalid UTF-8. - if (encoding == MBSTRING_UTF8) { - encoding = MBSTRING_ASC; - } else { - utf8_convert = 1; - } - } - // Measure the length. char quotes = 0; - int len = do_buf(str->data, str->length, encoding, utf8_convert, flags, - "es, NULL); + int len = do_buf(str->data, str->length, encoding, flags, "es, NULL); if (len < 0) { return -1; } @@ -381,8 +343,7 @@ int ASN1_STRING_print_ex(BIO *out, const ASN1_STRING *str, // Encode the value. if ((quotes && !maybe_write(out, "\"", 1)) || - do_buf(str->data, str->length, encoding, utf8_convert, flags, NULL, out) < - 0 || + do_buf(str->data, str->length, encoding, flags, NULL, out) < 0 || (quotes && !maybe_write(out, "\"", 1))) { return -1; } diff --git a/Sources/CNIOBoringSSL/crypto/asn1/a_time.c b/Sources/CNIOBoringSSL/crypto/asn1/a_time.c index 4767298f..ed645acd 100644 --- a/Sources/CNIOBoringSSL/crypto/asn1/a_time.c +++ b/Sources/CNIOBoringSSL/crypto/asn1/a_time.c @@ -187,7 +187,8 @@ int ASN1_TIME_set_string(ASN1_TIME *s, const char *str) { return 1; } -static int asn1_time_to_tm(struct tm *tm, const ASN1_TIME *t) { +static int asn1_time_to_tm(struct tm *tm, const ASN1_TIME *t, + int allow_timezone_offset) { if (t == NULL) { time_t now_t; time(&now_t); @@ -198,7 +199,7 @@ static int asn1_time_to_tm(struct tm *tm, const ASN1_TIME *t) { } if (t->type == V_ASN1_UTCTIME) { - return asn1_utctime_to_tm(tm, t); + return asn1_utctime_to_tm(tm, t, allow_timezone_offset); } else if (t->type == V_ASN1_GENERALIZEDTIME) { return asn1_generalizedtime_to_tm(tm, t); } @@ -209,11 +210,35 @@ static int asn1_time_to_tm(struct tm *tm, const ASN1_TIME *t) { int ASN1_TIME_diff(int *out_days, int *out_seconds, const ASN1_TIME *from, const ASN1_TIME *to) { struct tm tm_from, tm_to; - if (!asn1_time_to_tm(&tm_from, from)) { + if (!asn1_time_to_tm(&tm_from, from, /*allow_timezone_offset=*/1)) { return 0; } - if (!asn1_time_to_tm(&tm_to, to)) { + if (!asn1_time_to_tm(&tm_to, to, /*allow_timezone_offset=*/1)) { return 0; } return OPENSSL_gmtime_diff(out_days, out_seconds, &tm_from, &tm_to); } + +// The functions below do *not* permissively allow the use of four digit +// timezone offsets in UTC times, as is done elsewhere in the code. They are +// both new API, and used internally to X509_cmp_time. This is to discourage the +// use of nonstandard times in new code, and to ensure that this code behaves +// correctly in X509_cmp_time which historically did its own time validations +// slightly different than the many other copies of X.509 time validation +// sprinkled through the codebase. The custom checks in X509_cmp_time meant that +// it did not allow four digit timezone offsets in UTC times. +int ASN1_TIME_to_time_t(const ASN1_TIME *t, time_t *out_time) { + struct tm tm; + if (!asn1_time_to_tm(&tm, t, /*allow_timezone_offset=*/0)) { + return 0; + } + return OPENSSL_timegm(&tm, out_time); +} + +int ASN1_TIME_to_posix(const ASN1_TIME *t, int64_t *out_time) { + struct tm tm; + if (!asn1_time_to_tm(&tm, t, /*allow_timezone_offset=*/0)) { + return 0; + } + return OPENSSL_tm_to_posix(&tm, out_time); +} diff --git a/Sources/CNIOBoringSSL/crypto/asn1/a_utctm.c b/Sources/CNIOBoringSSL/crypto/asn1/a_utctm.c index 4f7178cf..784657f8 100644 --- a/Sources/CNIOBoringSSL/crypto/asn1/a_utctm.c +++ b/Sources/CNIOBoringSSL/crypto/asn1/a_utctm.c @@ -64,20 +64,21 @@ #include "internal.h" -int asn1_utctime_to_tm(struct tm *tm, const ASN1_UTCTIME *d) { +int asn1_utctime_to_tm(struct tm *tm, const ASN1_UTCTIME *d, + int allow_timezone_offset) { if (d->type != V_ASN1_UTCTIME) { return 0; } CBS cbs; CBS_init(&cbs, d->data, (size_t)d->length); - if (!CBS_parse_utc_time(&cbs, tm, /*allow_timezone_offset=*/1)) { + if (!CBS_parse_utc_time(&cbs, tm, allow_timezone_offset)) { return 0; } return 1; } int ASN1_UTCTIME_check(const ASN1_UTCTIME *d) { - return asn1_utctime_to_tm(NULL, d); + return asn1_utctime_to_tm(NULL, d, /*allow_timezone_offset=*/1); } int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str) { @@ -105,66 +106,50 @@ ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t) { ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, time_t t, int offset_day, long offset_sec) { - char *p; - struct tm *ts; struct tm data; - size_t len = 20; - int free_s = 0; - - if (s == NULL) { - free_s = 1; - s = ASN1_UTCTIME_new(); - } - if (s == NULL) { - goto err; - } - - ts = OPENSSL_gmtime(&t, &data); - if (ts == NULL) { - goto err; + if (!OPENSSL_gmtime(&t, &data)) { + return NULL; } if (offset_day || offset_sec) { - if (!OPENSSL_gmtime_adj(ts, offset_day, offset_sec)) { - goto err; + if (!OPENSSL_gmtime_adj(&data, offset_day, offset_sec)) { + return NULL; } } - if ((ts->tm_year < 50) || (ts->tm_year >= 150)) { - goto err; + if (data.tm_year < 50 || data.tm_year >= 150) { + return NULL; } - p = (char *)s->data; - if ((p == NULL) || ((size_t)s->length < len)) { - p = OPENSSL_malloc(len); - if (p == NULL) { - OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE); - goto err; + char buf[14]; + BIO_snprintf(buf, sizeof(buf), "%02d%02d%02d%02d%02d%02dZ", + data.tm_year % 100, data.tm_mon + 1, data.tm_mday, data.tm_hour, + data.tm_min, data.tm_sec); + + int free_s = 0; + if (s == NULL) { + free_s = 1; + s = ASN1_UTCTIME_new(); + if (s == NULL) { + return NULL; } - if (s->data != NULL) { - OPENSSL_free(s->data); - } - s->data = (unsigned char *)p; } - BIO_snprintf(p, len, "%02d%02d%02d%02d%02d%02dZ", ts->tm_year % 100, - ts->tm_mon + 1, ts->tm_mday, ts->tm_hour, ts->tm_min, - ts->tm_sec); - s->length = strlen(p); + if (!ASN1_STRING_set(s, buf, strlen(buf))) { + if (free_s) { + ASN1_UTCTIME_free(s); + } + return NULL; + } s->type = V_ASN1_UTCTIME; return s; -err: - if (free_s) { - ASN1_UTCTIME_free(s); - } - return NULL; } int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t) { struct tm stm, ttm; int day, sec; - if (!asn1_utctime_to_tm(&stm, s)) { + if (!asn1_utctime_to_tm(&stm, s, /*allow_timezone_offset=*/1)) { return -2; } diff --git a/Sources/CNIOBoringSSL/crypto/asn1/a_utf8.c b/Sources/CNIOBoringSSL/crypto/asn1/a_utf8.c index 5ea92866..46868809 100644 --- a/Sources/CNIOBoringSSL/crypto/asn1/a_utf8.c +++ b/Sources/CNIOBoringSSL/crypto/asn1/a_utf8.c @@ -63,112 +63,6 @@ // UTF8 utilities -// This parses a UTF8 string one character at a time. It is passed a pointer -// to the string and the length of the string. It sets 'value' to the value -// of the current character. It returns the number of characters read or a -// negative error code: -1 = string too short -2 = illegal character -3 = -// subsequent characters not of the form 10xxxxxx -4 = character encoded -// incorrectly (not minimal length). - -int UTF8_getc(const unsigned char *str, int len, uint32_t *val) { - const unsigned char *p; - uint32_t value; - int ret; - if (len <= 0) { - return 0; - } - p = str; - - // Check syntax and work out the encoded value (if correct) - if ((*p & 0x80) == 0) { - value = *p++ & 0x7f; - ret = 1; - } else if ((*p & 0xe0) == 0xc0) { - if (len < 2) { - return -1; - } - if ((p[1] & 0xc0) != 0x80) { - return -3; - } - value = (*p++ & 0x1f) << 6; - value |= *p++ & 0x3f; - if (value < 0x80) { - return -4; - } - ret = 2; - } else if ((*p & 0xf0) == 0xe0) { - if (len < 3) { - return -1; - } - if (((p[1] & 0xc0) != 0x80) || ((p[2] & 0xc0) != 0x80)) { - return -3; - } - value = (*p++ & 0xf) << 12; - value |= (*p++ & 0x3f) << 6; - value |= *p++ & 0x3f; - if (value < 0x800) { - return -4; - } - ret = 3; - } else if ((*p & 0xf8) == 0xf0) { - if (len < 4) { - return -1; - } - if (((p[1] & 0xc0) != 0x80) || ((p[2] & 0xc0) != 0x80) || - ((p[3] & 0xc0) != 0x80)) { - return -3; - } - value = ((uint32_t)(*p++ & 0x7)) << 18; - value |= (*p++ & 0x3f) << 12; - value |= (*p++ & 0x3f) << 6; - value |= *p++ & 0x3f; - if (value < 0x10000) { - return -4; - } - ret = 4; - } else if ((*p & 0xfc) == 0xf8) { - if (len < 5) { - return -1; - } - if (((p[1] & 0xc0) != 0x80) || ((p[2] & 0xc0) != 0x80) || - ((p[3] & 0xc0) != 0x80) || ((p[4] & 0xc0) != 0x80)) { - return -3; - } - value = ((uint32_t)(*p++ & 0x3)) << 24; - value |= ((uint32_t)(*p++ & 0x3f)) << 18; - value |= ((uint32_t)(*p++ & 0x3f)) << 12; - value |= (*p++ & 0x3f) << 6; - value |= *p++ & 0x3f; - if (value < 0x200000) { - return -4; - } - ret = 5; - } else if ((*p & 0xfe) == 0xfc) { - if (len < 6) { - return -1; - } - if (((p[1] & 0xc0) != 0x80) || ((p[2] & 0xc0) != 0x80) || - ((p[3] & 0xc0) != 0x80) || ((p[4] & 0xc0) != 0x80) || - ((p[5] & 0xc0) != 0x80)) { - return -3; - } - value = ((uint32_t)(*p++ & 0x1)) << 30; - value |= ((uint32_t)(*p++ & 0x3f)) << 24; - value |= ((uint32_t)(*p++ & 0x3f)) << 18; - value |= ((uint32_t)(*p++ & 0x3f)) << 12; - value |= (*p++ & 0x3f) << 6; - value |= *p++ & 0x3f; - if (value < 0x4000000) { - return -4; - } - ret = 6; - } else { - return -2; - } - *val = value; - return ret; -} - // This takes a character 'value' and writes the UTF8 encoded value in 'str' // where 'str' is a buffer containing 'len' characters. Returns the number of // characters written or -1 if 'len' is too small. 'str' can be set to NULL diff --git a/Sources/CNIOBoringSSL/crypto/asn1/internal.h b/Sources/CNIOBoringSSL/crypto/asn1/internal.h index f0a40d9a..486f95a3 100644 --- a/Sources/CNIOBoringSSL/crypto/asn1/internal.h +++ b/Sources/CNIOBoringSSL/crypto/asn1/internal.h @@ -71,16 +71,38 @@ extern "C" { // Wrapper functions for time functions. -// OPENSSL_gmtime wraps |gmtime_r|. See the manual page for that function. +// OPENSSL_posix_to_tm converts a int64_t POSIX time value in |time| whuch must +// be in the range of year 0000 to 9999 to a broken out time value in |tm|. It +// returns one on success and zero on error. +OPENSSL_EXPORT int OPENSSL_posix_to_tm(int64_t time, struct tm *out_tm); + +// OPENSSL_tm_to_posix converts a time value between the years 0 and 9999 in +// |tm| to a POSIX time value in |out|. One is returned on success, zero is +// returned on failure. It is a failure if the tm contains out of range values. +OPENSSL_EXPORT int OPENSSL_tm_to_posix(const struct tm *tm, int64_t *out); + +// OPENSSL_gmtime converts a time_t value in |time| which must be in the range +// of year 0000 to 9999 to a broken out time value in |tm|. On success |tm| is +// returned. On failure NULL is returned. OPENSSL_EXPORT struct tm *OPENSSL_gmtime(const time_t *time, struct tm *result); -// OPENSSL_gmtime_adj updates |tm| by adding |offset_day| days and |offset_sec| -// seconds. +// OPENSSL_timegm converts a time value between the years 0 and 9999 in |tm| to +// a time_t value in |out|. One is returned on success, zero is returned on +// failure. It is a failure if the converted time can not be represented in a +// time_t, or if the tm contains out of range values. +OPENSSL_EXPORT int OPENSSL_timegm(const struct tm *tm, time_t *out); + +// OPENSSL_gmtime_adj returns one on success, and updates |tm| by adding +// |offset_day| days and |offset_sec| seconds. It returns zero on failure. |tm| +// must be in the range of year 0000 to 9999 both before and after the update or +// a failure will be returned. int OPENSSL_gmtime_adj(struct tm *tm, int offset_day, long offset_sec); -// OPENSSL_gmtime_diff calculates the difference between |from| and |to| and -// outputs the difference as a number of days and seconds in |*out_days| and -// |*out_secs|. +// OPENSSL_gmtime_diff calculates the difference between |from| and |to|. It +// returns one, and outputs the difference as a number of days and seconds in +// |*out_days| and |*out_secs| on success. It returns zero on failure. Both +// |from| and |to| must be in the range of year 0000 to 9999 or a failure will +// be returned. OPENSSL_EXPORT int OPENSSL_gmtime_diff(int *out_days, int *out_secs, const struct tm *from, const struct tm *to); @@ -126,14 +148,14 @@ typedef struct ASN1_ENCODING_st { unsigned alias_only_on_next_parse : 1; } ASN1_ENCODING; -OPENSSL_EXPORT int asn1_utctime_to_tm(struct tm *tm, const ASN1_UTCTIME *d); +OPENSSL_EXPORT int asn1_utctime_to_tm(struct tm *tm, const ASN1_UTCTIME *d, + int allow_timezone_offset); OPENSSL_EXPORT int asn1_generalizedtime_to_tm(struct tm *tm, const ASN1_GENERALIZEDTIME *d); void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine); -int UTF8_getc(const unsigned char *str, int len, uint32_t *val); int UTF8_putc(unsigned char *str, int len, uint32_t value); int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it); diff --git a/Sources/CNIOBoringSSL/crypto/asn1/posix_time.c b/Sources/CNIOBoringSSL/crypto/asn1/posix_time.c new file mode 100644 index 00000000..81fbe833 --- /dev/null +++ b/Sources/CNIOBoringSSL/crypto/asn1/posix_time.c @@ -0,0 +1,227 @@ +/* Copyright (c) 2022, Google Inc. + * + * 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. + * + * 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. */ + +// Time conversion to/from POSIX time_t and struct tm, with no support +// for time zones other than UTC + +#include +#include +#include +#include +#include + +#include "internal.h" + +#define SECS_PER_HOUR (60 * 60) +#define SECS_PER_DAY (24 * SECS_PER_HOUR) + + +// Is a year/month/day combination valid, in the range from year 0000 +// to 9999? +static int is_valid_date(int year, int month, int day) { + if (day < 1 || month < 1 || year < 0 || year > 9999) { + return 0; + } + switch (month) { + case 1: + case 3: + case 5: + case 7: + case 8: + case 10: + case 12: + return day > 0 && day <= 31; + case 4: + case 6: + case 9: + case 11: + return day > 0 && day <= 30; + case 2: + if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) { + return day > 0 && day <= 29; + } else { + return day > 0 && day <= 28; + } + default: + return 0; + } +} + +// Is a time valid? Leap seconds of 60 are not considered valid, as +// the POSIX time in seconds does not include them. +static int is_valid_time(int hours, int minutes, int seconds) { + if (hours < 0 || minutes < 0 || seconds < 0 || hours > 23 || minutes > 59 || + seconds > 59) { + return 0; + } + return 1; +} + +// Is a int64 time representing a time within our expected range? +static int is_valid_epoch_time(int64_t time) { + // 0000-01-01 00:00:00 UTC to 9999-12-31 23:59:59 UTC + return (int64_t)-62167219200 <= time && time <= (int64_t)253402300799; +} + +// Inspired by algorithms presented in +// https://howardhinnant.github.io/date_algorithms.html +// (Public Domain) +static int posix_time_from_utc(int year, int month, int day, int hours, + int minutes, int seconds, int64_t *out_time) { + if (!is_valid_date(year, month, day) || + !is_valid_time(hours, minutes, seconds)) { + return 0; + } + if (month <= 2) { + year--; // Start years on Mar 1, so leap days always finish a year. + } + // At this point year will be in the range -1 and 9999. + assert(-1 <= year && year <= 9999); + int64_t era = (year >= 0 ? year : year - 399) / 400; + int64_t year_of_era = year - era * 400; + int64_t day_of_year = + (153 * (month > 2 ? month - 3 : month + 9) + 2) / 5 + day - 1; + int64_t day_of_era = + year_of_era * 365 + year_of_era / 4 - year_of_era / 100 + day_of_year; + int64_t posix_days = era * 146097 + day_of_era - 719468; + *out_time = posix_days * SECS_PER_DAY + hours * SECS_PER_HOUR + minutes * 60 + + seconds; + return 1; +} + +// Inspired by algorithms presented in +// https://howardhinnant.github.io/date_algorithms.html +// (Public Domain) +static int utc_from_posix_time(int64_t time, int *out_year, int *out_month, + int *out_day, int *out_hours, int *out_minutes, + int *out_seconds) { + if (!is_valid_epoch_time(time)) { + return 0; + } + int64_t days = time / SECS_PER_DAY; + int64_t leftover_seconds = time % SECS_PER_DAY; + if (leftover_seconds < 0) { + days--; + leftover_seconds += SECS_PER_DAY; + } + days += 719468; // Shift to starting epoch of Mar 1 0000. + // At this point, days will be in the range -61 and 3652364. + assert(-61 <= days && days <= 3652364); + int64_t era = (days > 0 ? days : days - 146096) / 146097; + int64_t day_of_era = days - era * 146097; + int64_t year_of_era = (day_of_era - day_of_era / 1460 + day_of_era / 36524 - + day_of_era / 146096) / + 365; + *out_year = (int)(year_of_era + era * 400); // Year starting on Mar 1. + int64_t day_of_year = + day_of_era - (365 * year_of_era + year_of_era / 4 - year_of_era / 100); + int64_t month_of_year = (5 * day_of_year + 2) / 153; + *out_month = + (int)(month_of_year < 10 ? month_of_year + 3 : month_of_year - 9); + if (*out_month <= 2) { + (*out_year)++; // Adjust year back to Jan 1 start of year. + } + *out_day = (int)(day_of_year - (153 * month_of_year + 2) / 5 + 1); + *out_hours = (int)(leftover_seconds / SECS_PER_HOUR); + leftover_seconds %= SECS_PER_HOUR; + *out_minutes = (int)(leftover_seconds / 60); + *out_seconds = (int)(leftover_seconds % 60); + return 1; +} + +int OPENSSL_tm_to_posix(const struct tm *tm, int64_t *out) { + return posix_time_from_utc(tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, + tm->tm_hour, tm->tm_min, tm->tm_sec, out); +} + +int OPENSSL_posix_to_tm(int64_t time, struct tm *out_tm) { + memset(out_tm, 0, sizeof(struct tm)); + if (!utc_from_posix_time(time, &out_tm->tm_year, &out_tm->tm_mon, + &out_tm->tm_mday, &out_tm->tm_hour, &out_tm->tm_min, + &out_tm->tm_sec)) { + return 0; + } + out_tm->tm_year -= 1900; + out_tm->tm_mon -= 1; + + return 1; +} + +int OPENSSL_timegm(const struct tm *tm, time_t *out) { + static_assert( + sizeof(time_t) == sizeof(int32_t) || sizeof(time_t) == sizeof(int64_t), + "time_t is broken"); + int64_t posix_time; + if (!OPENSSL_tm_to_posix(tm, &posix_time)) { + return 0; + } + if (sizeof(time_t) == sizeof(int32_t) && + (posix_time > INT32_MAX || posix_time < INT32_MIN)) { + return 0; + } + *out = (time_t)posix_time; + return 1; +} + +struct tm *OPENSSL_gmtime(const time_t *time, struct tm *out_tm) { + static_assert( + sizeof(time_t) == sizeof(int32_t) || sizeof(time_t) == sizeof(int64_t), + "time_t is broken"); + int64_t posix_time = *time; + if (!OPENSSL_posix_to_tm(posix_time, out_tm)) { + return NULL; + } + return out_tm; +} + +int OPENSSL_gmtime_adj(struct tm *tm, int off_day, long offset_sec) { + int64_t posix_time; + if (!posix_time_from_utc(tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, + tm->tm_hour, tm->tm_min, tm->tm_sec, &posix_time)) { + return 0; + } + if (!utc_from_posix_time(posix_time + off_day * SECS_PER_DAY + offset_sec, + &tm->tm_year, &tm->tm_mon, &tm->tm_mday, + &tm->tm_hour, &tm->tm_min, &tm->tm_sec)) { + return 0; + } + tm->tm_year -= 1900; + tm->tm_mon -= 1; + + return 1; +} + +int OPENSSL_gmtime_diff(int *out_days, int *out_secs, const struct tm *from, + const struct tm *to) { + int64_t time_to; + if (!posix_time_from_utc(to->tm_year + 1900, to->tm_mon + 1, to->tm_mday, + to->tm_hour, to->tm_min, to->tm_sec, &time_to)) { + return 0; + } + int64_t time_from; + if (!posix_time_from_utc(from->tm_year + 1900, from->tm_mon + 1, + from->tm_mday, from->tm_hour, from->tm_min, + from->tm_sec, &time_from)) { + return 0; + } + int64_t timediff = time_to - time_from; + int64_t daydiff = timediff / SECS_PER_DAY; + timediff %= SECS_PER_DAY; + if (daydiff > INT_MAX || daydiff < INT_MIN) { + return 0; + } + *out_secs = (int)timediff; + *out_days = (int)daydiff; + return 1; +} diff --git a/Sources/CNIOBoringSSL/crypto/asn1/tasn_dec.c b/Sources/CNIOBoringSSL/crypto/asn1/tasn_dec.c index 101de426..f8a594c6 100644 --- a/Sources/CNIOBoringSSL/crypto/asn1/tasn_dec.c +++ b/Sources/CNIOBoringSSL/crypto/asn1/tasn_dec.c @@ -63,6 +63,7 @@ #include #include +#include "../bytestring/internal.h" #include "../internal.h" #include "internal.h" @@ -797,32 +798,51 @@ static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, case V_ASN1_OTHER: case V_ASN1_SET: case V_ASN1_SEQUENCE: - default: - if (utype == V_ASN1_BMPSTRING && (len & 1)) { - OPENSSL_PUT_ERROR(ASN1, ASN1_R_BMPSTRING_IS_WRONG_LENGTH); - goto err; + default: { + CBS cbs; + CBS_init(&cbs, cont, (size_t)len); + if (utype == V_ASN1_BMPSTRING) { + while (CBS_len(&cbs) != 0) { + uint32_t c; + if (!cbs_get_ucs2_be(&cbs, &c)) { + OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_BMPSTRING); + goto err; + } + } } - if (utype == V_ASN1_UNIVERSALSTRING && (len & 3)) { - OPENSSL_PUT_ERROR(ASN1, ASN1_R_UNIVERSALSTRING_IS_WRONG_LENGTH); - goto err; + if (utype == V_ASN1_UNIVERSALSTRING) { + while (CBS_len(&cbs) != 0) { + uint32_t c; + if (!cbs_get_utf32_be(&cbs, &c)) { + OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_UNIVERSALSTRING); + goto err; + } + } + } + if (utype == V_ASN1_UTF8STRING) { + while (CBS_len(&cbs) != 0) { + uint32_t c; + if (!cbs_get_utf8(&cbs, &c)) { + OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_UTF8STRING); + goto err; + } + } } if (utype == V_ASN1_UTCTIME) { - CBS cbs; - CBS_init(&cbs, cont, (size_t)len); if (!CBS_parse_utc_time(&cbs, NULL, /*allow_timezone_offset=*/1)) { OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_TIME_FORMAT); goto err; } } if (utype == V_ASN1_GENERALIZEDTIME) { - CBS cbs; - CBS_init(&cbs, cont, (size_t)len); if (!CBS_parse_generalized_time(&cbs, NULL, /*allow_timezone_offset=*/0)) { OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_TIME_FORMAT); goto err; } } + // TODO(https://crbug.com/boringssl/427): Check other string types. + // All based on ASN1_STRING and handled the same if (!*pval) { stmp = ASN1_STRING_type_new(utype); @@ -842,6 +862,7 @@ static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, goto err; } break; + } } // If ASN1_ANY and NULL type fix up value if (typ && (utype == V_ASN1_NULL)) { diff --git a/Sources/CNIOBoringSSL/crypto/asn1/tasn_typ.c b/Sources/CNIOBoringSSL/crypto/asn1/tasn_typ.c index afb490c7..801ec904 100644 --- a/Sources/CNIOBoringSSL/crypto/asn1/tasn_typ.c +++ b/Sources/CNIOBoringSSL/crypto/asn1/tasn_typ.c @@ -111,8 +111,6 @@ IMPLEMENT_ASN1_TYPE_ex(ASN1_BOOLEAN, ASN1_BOOLEAN, -1) IMPLEMENT_ASN1_TYPE_ex(ASN1_TBOOLEAN, ASN1_BOOLEAN, 1) IMPLEMENT_ASN1_TYPE_ex(ASN1_FBOOLEAN, ASN1_BOOLEAN, 0) -// Special, OCTET STRING with indefinite length constructed support - ASN1_ITEM_TEMPLATE(ASN1_SEQUENCE_ANY) = ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, ASN1_SEQUENCE_ANY, ASN1_ANY) ASN1_ITEM_TEMPLATE_END(ASN1_SEQUENCE_ANY) diff --git a/Sources/CNIOBoringSSL/crypto/asn1/time_support.c b/Sources/CNIOBoringSSL/crypto/asn1/time_support.c deleted file mode 100644 index 7929970b..00000000 --- a/Sources/CNIOBoringSSL/crypto/asn1/time_support.c +++ /dev/null @@ -1,206 +0,0 @@ -/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL - * project 2001. - * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL - * project 2008. - */ -/* ==================================================================== - * Copyright (c) 2001 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). */ - -#if defined(__linux__) && !defined(_POSIX_C_SOURCE) -#define _POSIX_C_SOURCE 201410L // for gmtime_r -#endif - -#include "internal.h" - -#include - - -#define SECS_PER_DAY (24 * 60 * 60) - -struct tm *OPENSSL_gmtime(const time_t *time, struct tm *result) { -#if defined(OPENSSL_WINDOWS) - if (gmtime_s(result, time)) { - return NULL; - } - return result; -#else - return gmtime_r(time, result); -#endif -} - -// Convert date to and from julian day Uses Fliegel & Van Flandern algorithm -static long date_to_julian(int y, int m, int d) { - return (1461 * (y + 4800 + (m - 14) / 12)) / 4 + - (367 * (m - 2 - 12 * ((m - 14) / 12))) / 12 - - (3 * ((y + 4900 + (m - 14) / 12) / 100)) / 4 + d - 32075; -} - -static void julian_to_date(long jd, int *y, int *m, int *d) { - long L = jd + 68569; - long n = (4 * L) / 146097; - long i, j; - - L = L - (146097 * n + 3) / 4; - i = (4000 * (L + 1)) / 1461001; - L = L - (1461 * i) / 4 + 31; - j = (80 * L) / 2447; - *d = L - (2447 * j) / 80; - L = j / 11; - *m = j + 2 - (12 * L); - *y = 100 * (n - 49) + i + L; -} - -// Convert tm structure and offset into julian day and seconds -static int julian_adj(const struct tm *tm, int off_day, long offset_sec, - long *pday, int *psec) { - int offset_hms, offset_day; - long time_jd; - int time_year, time_month, time_day; - // split offset into days and day seconds - offset_day = offset_sec / SECS_PER_DAY; - // Avoid sign issues with % operator - offset_hms = offset_sec - (offset_day * SECS_PER_DAY); - offset_day += off_day; - // Add current time seconds to offset - offset_hms += tm->tm_hour * 3600 + tm->tm_min * 60 + tm->tm_sec; - // Adjust day seconds if overflow - if (offset_hms >= SECS_PER_DAY) { - offset_day++; - offset_hms -= SECS_PER_DAY; - } else if (offset_hms < 0) { - offset_day--; - offset_hms += SECS_PER_DAY; - } - - // Convert date of time structure into a Julian day number. - - time_year = tm->tm_year + 1900; - time_month = tm->tm_mon + 1; - time_day = tm->tm_mday; - - time_jd = date_to_julian(time_year, time_month, time_day); - - // Work out Julian day of new date - time_jd += offset_day; - - if (time_jd < 0) { - return 0; - } - - *pday = time_jd; - *psec = offset_hms; - return 1; -} - -int OPENSSL_gmtime_adj(struct tm *tm, int off_day, long offset_sec) { - int time_sec, time_year, time_month, time_day; - long time_jd; - - // Convert time and offset into julian day and seconds - if (!julian_adj(tm, off_day, offset_sec, &time_jd, &time_sec)) { - return 0; - } - - // Convert Julian day back to date - - julian_to_date(time_jd, &time_year, &time_month, &time_day); - - if (time_year < 1900 || time_year > 9999) { - return 0; - } - - // Update tm structure - - tm->tm_year = time_year - 1900; - tm->tm_mon = time_month - 1; - tm->tm_mday = time_day; - - tm->tm_hour = time_sec / 3600; - tm->tm_min = (time_sec / 60) % 60; - tm->tm_sec = time_sec % 60; - - return 1; -} - -int OPENSSL_gmtime_diff(int *out_days, int *out_secs, const struct tm *from, - const struct tm *to) { - int from_sec, to_sec, diff_sec; - long from_jd, to_jd, diff_day; - - if (!julian_adj(from, 0, 0, &from_jd, &from_sec)) { - return 0; - } - if (!julian_adj(to, 0, 0, &to_jd, &to_sec)) { - return 0; - } - - diff_day = to_jd - from_jd; - diff_sec = to_sec - from_sec; - // Adjust differences so both positive or both negative - if (diff_day > 0 && diff_sec < 0) { - diff_day--; - diff_sec += SECS_PER_DAY; - } - if (diff_day < 0 && diff_sec > 0) { - diff_day++; - diff_sec -= SECS_PER_DAY; - } - - if (out_days) { - *out_days = (int)diff_day; - } - if (out_secs) { - *out_secs = diff_sec; - } - - return 1; -} diff --git a/Sources/CNIOBoringSSL/crypto/base64/base64.c b/Sources/CNIOBoringSSL/crypto/base64/base64.c index 79e5e053..a1cd66b0 100644 --- a/Sources/CNIOBoringSSL/crypto/base64/base64.c +++ b/Sources/CNIOBoringSSL/crypto/base64/base64.c @@ -60,8 +60,6 @@ #include #include -#include - #include "../internal.h" @@ -98,8 +96,8 @@ static uint8_t conv_bin2ascii(uint8_t a) { return ret; } -OPENSSL_STATIC_ASSERT(sizeof(((EVP_ENCODE_CTX *)(NULL))->data) % 3 == 0, - "data length must be a multiple of base64 chunk size"); +static_assert(sizeof(((EVP_ENCODE_CTX *)(NULL))->data) % 3 == 0, + "data length must be a multiple of base64 chunk size"); int EVP_EncodedLength(size_t *out_len, size_t len) { if (len + 2 < len) { diff --git a/Sources/CNIOBoringSSL/crypto/blake2/blake2.c b/Sources/CNIOBoringSSL/crypto/blake2/blake2.c index 87dba54b..c4c0dc30 100644 --- a/Sources/CNIOBoringSSL/crypto/blake2/blake2.c +++ b/Sources/CNIOBoringSSL/crypto/blake2/blake2.c @@ -14,7 +14,7 @@ #include -#include +#include #include "../internal.h" @@ -61,7 +61,7 @@ static void blake2b_transform( size_t num_bytes, int is_final_block) { // https://tools.ietf.org/html/rfc7693#section-3.2 uint64_t v[16]; - OPENSSL_STATIC_ASSERT(sizeof(v) == sizeof(b2b->h) + sizeof(kIV), ""); + static_assert(sizeof(v) == sizeof(b2b->h) + sizeof(kIV), ""); OPENSSL_memcpy(v, b2b->h, sizeof(b2b->h)); OPENSSL_memcpy(&v[8], kIV, sizeof(kIV)); @@ -97,7 +97,7 @@ static void blake2b_transform( void BLAKE2B256_Init(BLAKE2B_CTX *b2b) { OPENSSL_memset(b2b, 0, sizeof(BLAKE2B_CTX)); - OPENSSL_STATIC_ASSERT(sizeof(kIV) == sizeof(b2b->h), ""); + static_assert(sizeof(kIV) == sizeof(b2b->h), ""); OPENSSL_memcpy(&b2b->h, kIV, sizeof(kIV)); // https://tools.ietf.org/html/rfc7693#section-2.5 @@ -143,7 +143,7 @@ void BLAKE2B256_Final(uint8_t out[BLAKE2B256_DIGEST_LENGTH], BLAKE2B_CTX *b2b) { sizeof(b2b->block.bytes) - b2b->block_used); blake2b_transform(b2b, b2b->block.words, b2b->block_used, /*is_final_block=*/1); - OPENSSL_STATIC_ASSERT(BLAKE2B256_DIGEST_LENGTH <= sizeof(b2b->h), ""); + static_assert(BLAKE2B256_DIGEST_LENGTH <= sizeof(b2b->h), ""); memcpy(out, b2b->h, BLAKE2B256_DIGEST_LENGTH); } diff --git a/Sources/CNIOBoringSSL/crypto/cipher_extra/e_aesctrhmac.c b/Sources/CNIOBoringSSL/crypto/cipher_extra/e_aesctrhmac.c index 6bba7620..57f54e2b 100644 --- a/Sources/CNIOBoringSSL/crypto/cipher_extra/e_aesctrhmac.c +++ b/Sources/CNIOBoringSSL/crypto/cipher_extra/e_aesctrhmac.c @@ -13,6 +13,9 @@ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include + +#include + #include #include #include @@ -35,12 +38,12 @@ struct aead_aes_ctr_hmac_sha256_ctx { SHA256_CTX outer_init_state; }; -OPENSSL_STATIC_ASSERT(sizeof(((EVP_AEAD_CTX *)NULL)->state) >= - sizeof(struct aead_aes_ctr_hmac_sha256_ctx), - "AEAD state is too small"); -OPENSSL_STATIC_ASSERT(alignof(union evp_aead_ctx_st_state) >= - alignof(struct aead_aes_ctr_hmac_sha256_ctx), - "AEAD state has insufficient alignment"); +static_assert(sizeof(((EVP_AEAD_CTX *)NULL)->state) >= + sizeof(struct aead_aes_ctr_hmac_sha256_ctx), + "AEAD state is too small"); +static_assert(alignof(union evp_aead_ctx_st_state) >= + alignof(struct aead_aes_ctr_hmac_sha256_ctx), + "AEAD state has insufficient alignment"); static void hmac_init(SHA256_CTX *out_inner, SHA256_CTX *out_outer, const uint8_t hmac_key[32]) { diff --git a/Sources/CNIOBoringSSL/crypto/cipher_extra/e_aesgcmsiv.c b/Sources/CNIOBoringSSL/crypto/cipher_extra/e_aesgcmsiv.c index c09893cc..9e9e07f2 100644 --- a/Sources/CNIOBoringSSL/crypto/cipher_extra/e_aesgcmsiv.c +++ b/Sources/CNIOBoringSSL/crypto/cipher_extra/e_aesgcmsiv.c @@ -42,11 +42,11 @@ struct aead_aes_gcm_siv_asm_ctx { // The assembly code assumes 8-byte alignment of the EVP_AEAD_CTX's state, and // aligns to 16 bytes itself. -OPENSSL_STATIC_ASSERT(sizeof(((EVP_AEAD_CTX *)NULL)->state) + 8 >= - sizeof(struct aead_aes_gcm_siv_asm_ctx), - "AEAD state is too small"); -OPENSSL_STATIC_ASSERT(alignof(union evp_aead_ctx_st_state) >= 8, - "AEAD state has insufficient alignment"); +static_assert(sizeof(((EVP_AEAD_CTX *)NULL)->state) + 8 >= + sizeof(struct aead_aes_gcm_siv_asm_ctx), + "AEAD state is too small"); +static_assert(alignof(union evp_aead_ctx_st_state) >= 8, + "AEAD state has insufficient alignment"); // asm_ctx_from_ctx returns a 16-byte aligned context pointer from |ctx|. static struct aead_aes_gcm_siv_asm_ctx *asm_ctx_from_ctx( @@ -550,12 +550,12 @@ struct aead_aes_gcm_siv_ctx { unsigned is_256:1; }; -OPENSSL_STATIC_ASSERT(sizeof(((EVP_AEAD_CTX *)NULL)->state) >= - sizeof(struct aead_aes_gcm_siv_ctx), - "AEAD state is too small"); -OPENSSL_STATIC_ASSERT(alignof(union evp_aead_ctx_st_state) >= - alignof(struct aead_aes_gcm_siv_ctx), - "AEAD state has insufficient alignment"); +static_assert(sizeof(((EVP_AEAD_CTX *)NULL)->state) >= + sizeof(struct aead_aes_gcm_siv_ctx), + "AEAD state is too small"); +static_assert(alignof(union evp_aead_ctx_st_state) >= + alignof(struct aead_aes_gcm_siv_ctx), + "AEAD state has insufficient alignment"); static int aead_aes_gcm_siv_init(EVP_AEAD_CTX *ctx, const uint8_t *key, size_t key_len, size_t tag_len) { diff --git a/Sources/CNIOBoringSSL/crypto/cipher_extra/e_chacha20poly1305.c b/Sources/CNIOBoringSSL/crypto/cipher_extra/e_chacha20poly1305.c index db729967..463bb222 100644 --- a/Sources/CNIOBoringSSL/crypto/cipher_extra/e_chacha20poly1305.c +++ b/Sources/CNIOBoringSSL/crypto/cipher_extra/e_chacha20poly1305.c @@ -14,6 +14,7 @@ #include +#include #include #include @@ -21,7 +22,6 @@ #include #include #include -#include #include "internal.h" #include "../chacha/internal.h" @@ -32,12 +32,12 @@ struct aead_chacha20_poly1305_ctx { uint8_t key[32]; }; -OPENSSL_STATIC_ASSERT(sizeof(((EVP_AEAD_CTX *)NULL)->state) >= - sizeof(struct aead_chacha20_poly1305_ctx), - "AEAD state is too small"); -OPENSSL_STATIC_ASSERT(alignof(union evp_aead_ctx_st_state) >= - alignof(struct aead_chacha20_poly1305_ctx), - "AEAD state has insufficient alignment"); +static_assert(sizeof(((EVP_AEAD_CTX *)NULL)->state) >= + sizeof(struct aead_chacha20_poly1305_ctx), + "AEAD state is too small"); +static_assert(alignof(union evp_aead_ctx_st_state) >= + alignof(struct aead_chacha20_poly1305_ctx), + "AEAD state has insufficient alignment"); static int aead_chacha20_poly1305_init(EVP_AEAD_CTX *ctx, const uint8_t *key, size_t key_len, size_t tag_len) { diff --git a/Sources/CNIOBoringSSL/crypto/cipher_extra/e_tls.c b/Sources/CNIOBoringSSL/crypto/cipher_extra/e_tls.c index 6a0b6914..14f31fc2 100644 --- a/Sources/CNIOBoringSSL/crypto/cipher_extra/e_tls.c +++ b/Sources/CNIOBoringSSL/crypto/cipher_extra/e_tls.c @@ -23,7 +23,6 @@ #include #include #include -#include #include "../fipsmodule/cipher/internal.h" #include "../internal.h" @@ -42,15 +41,12 @@ typedef struct { char implicit_iv; } AEAD_TLS_CTX; -OPENSSL_STATIC_ASSERT(EVP_MAX_MD_SIZE < 256, - "mac_key_len does not fit in uint8_t"); +static_assert(EVP_MAX_MD_SIZE < 256, "mac_key_len does not fit in uint8_t"); -OPENSSL_STATIC_ASSERT(sizeof(((EVP_AEAD_CTX *)NULL)->state) >= - sizeof(AEAD_TLS_CTX), - "AEAD state is too small"); -OPENSSL_STATIC_ASSERT(alignof(union evp_aead_ctx_st_state) >= - alignof(AEAD_TLS_CTX), - "AEAD state has insufficient alignment"); +static_assert(sizeof(((EVP_AEAD_CTX *)NULL)->state) >= sizeof(AEAD_TLS_CTX), + "AEAD state is too small"); +static_assert(alignof(union evp_aead_ctx_st_state) >= alignof(AEAD_TLS_CTX), + "AEAD state has insufficient alignment"); static void aead_tls_cleanup(EVP_AEAD_CTX *ctx) { AEAD_TLS_CTX *tls_ctx = (AEAD_TLS_CTX *)&ctx->state; diff --git a/Sources/CNIOBoringSSL/crypto/cipher_extra/internal.h b/Sources/CNIOBoringSSL/crypto/cipher_extra/internal.h index 3adeb046..443b10aa 100644 --- a/Sources/CNIOBoringSSL/crypto/cipher_extra/internal.h +++ b/Sources/CNIOBoringSSL/crypto/cipher_extra/internal.h @@ -57,10 +57,10 @@ #ifndef OPENSSL_HEADER_CIPHER_EXTRA_INTERNAL_H #define OPENSSL_HEADER_CIPHER_EXTRA_INTERNAL_H +#include #include #include -#include #include "../internal.h" @@ -166,10 +166,10 @@ union chacha20_poly1305_seal_data { #if (defined(OPENSSL_X86_64) || defined(OPENSSL_AARCH64)) && \ !defined(OPENSSL_NO_ASM) -OPENSSL_STATIC_ASSERT(sizeof(union chacha20_poly1305_open_data) == 48, - "wrong chacha20_poly1305_open_data size"); -OPENSSL_STATIC_ASSERT(sizeof(union chacha20_poly1305_seal_data) == 48 + 8 + 8, - "wrong chacha20_poly1305_seal_data size"); +static_assert(sizeof(union chacha20_poly1305_open_data) == 48, + "wrong chacha20_poly1305_open_data size"); +static_assert(sizeof(union chacha20_poly1305_seal_data) == 48 + 8 + 8, + "wrong chacha20_poly1305_seal_data size"); OPENSSL_INLINE int chacha20_poly1305_asm_capable(void) { #if defined(OPENSSL_X86_64) diff --git a/Sources/CNIOBoringSSL/crypto/curve25519/curve25519.c b/Sources/CNIOBoringSSL/crypto/curve25519/curve25519.c index 95c3113a..b3e8bad8 100644 --- a/Sources/CNIOBoringSSL/crypto/curve25519/curve25519.c +++ b/Sources/CNIOBoringSSL/crypto/curve25519/curve25519.c @@ -27,7 +27,6 @@ #include #include #include -#include #include "internal.h" #include "../internal.h" @@ -151,8 +150,8 @@ typedef uint32_t fe_limb_t; #endif // BORINGSSL_CURVE25519_64BIT -OPENSSL_STATIC_ASSERT(sizeof(fe) == sizeof(fe_limb_t) * FE_NUM_LIMBS, - "fe_limb_t[FE_NUM_LIMBS] is inconsistent with fe"); +static_assert(sizeof(fe) == sizeof(fe_limb_t) * FE_NUM_LIMBS, + "fe_limb_t[FE_NUM_LIMBS] is inconsistent with fe"); static void fe_frombytes_strict(fe *h, const uint8_t s[32]) { // |fiat_25519_from_bytes| requires the top-most bit be clear. @@ -315,8 +314,7 @@ static void fe_copy(fe *h, const fe *f) { } static void fe_copy_lt(fe_loose *h, const fe *f) { - OPENSSL_STATIC_ASSERT(sizeof(fe_loose) == sizeof(fe), - "fe and fe_loose mismatch"); + static_assert(sizeof(fe_loose) == sizeof(fe), "fe and fe_loose mismatch"); OPENSSL_memmove(h, f, sizeof(fe)); } #if !defined(OPENSSL_SMALL) diff --git a/Sources/CNIOBoringSSL/crypto/curve25519/spake25519.c b/Sources/CNIOBoringSSL/crypto/curve25519/spake25519.c index d7de55b8..4c290e25 100644 --- a/Sources/CNIOBoringSSL/crypto/curve25519/spake25519.c +++ b/Sources/CNIOBoringSSL/crypto/curve25519/spake25519.c @@ -22,6 +22,7 @@ #include #include +#include "../fipsmodule/bn/internal.h" #include "../internal.h" #include "./internal.h" @@ -314,46 +315,30 @@ static void left_shift_3(uint8_t n[32]) { } } -typedef union { - uint8_t bytes[32]; - uint32_t words[8]; +typedef struct { + BN_ULONG words[32 / sizeof(BN_ULONG)]; } scalar; -// kOrder is the order of the prime-order subgroup of curve25519 in -// little-endian order. -static const scalar kOrder = {{0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, - 0xd6, 0x9c, 0xf7, 0xa2, 0xde, 0xf9, 0xde, 0x14, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10}}; +// kOrder is the order of the prime-order subgroup of curve25519. +static const scalar kOrder = { + {TOBN(0x5812631a, 0x5cf5d3ed), TOBN(0x14def9de, 0xa2f79cd6), + TOBN(0x00000000, 0x00000000), TOBN(0x10000000, 0x00000000)}}; // scalar_cmov copies |src| to |dest| if |mask| is all ones. static void scalar_cmov(scalar *dest, const scalar *src, crypto_word_t mask) { - for (size_t i = 0; i < 8; i++) { - dest->words[i] = - constant_time_select_w(mask, src->words[i], dest->words[i]); - } + bn_select_words(dest->words, mask, src->words, dest->words, + OPENSSL_ARRAY_SIZE(dest->words)); } // scalar_double sets |s| to |2×s|. static void scalar_double(scalar *s) { - uint32_t carry = 0; - - for (size_t i = 0; i < 8; i++) { - const uint32_t carry_out = s->words[i] >> 31; - s->words[i] = (s->words[i] << 1) | carry; - carry = carry_out; - } + bn_add_words(s->words, s->words, s->words, OPENSSL_ARRAY_SIZE(s->words)); } // scalar_add sets |dest| to |dest| plus |src|. static void scalar_add(scalar *dest, const scalar *src) { - uint32_t carry = 0; - - for (size_t i = 0; i < 8; i++) { - uint64_t tmp = ((uint64_t)dest->words[i] + src->words[i]) + carry; - dest->words[i] = (uint32_t)tmp; - carry = (uint32_t)(tmp >> 32); - } + bn_add_words(dest->words, dest->words, src->words, + OPENSSL_ARRAY_SIZE(dest->words)); } int SPAKE2_generate_msg(SPAKE2_CTX *ctx, uint8_t *out, size_t *out_len, @@ -412,25 +397,25 @@ int SPAKE2_generate_msg(SPAKE2_CTX *ctx, uint8_t *out, size_t *out_len, OPENSSL_memset(&tmp, 0, sizeof(tmp)); scalar_cmov(&tmp, &order, - constant_time_eq_w(password_scalar.bytes[0] & 1, 1)); + constant_time_eq_w(password_scalar.words[0] & 1, 1)); scalar_add(&password_scalar, &tmp); scalar_double(&order); OPENSSL_memset(&tmp, 0, sizeof(tmp)); scalar_cmov(&tmp, &order, - constant_time_eq_w(password_scalar.bytes[0] & 2, 2)); + constant_time_eq_w(password_scalar.words[0] & 2, 2)); scalar_add(&password_scalar, &tmp); scalar_double(&order); OPENSSL_memset(&tmp, 0, sizeof(tmp)); scalar_cmov(&tmp, &order, - constant_time_eq_w(password_scalar.bytes[0] & 4, 4)); + constant_time_eq_w(password_scalar.words[0] & 4, 4)); scalar_add(&password_scalar, &tmp); - assert((password_scalar.bytes[0] & 7) == 0); + assert((password_scalar.words[0] & 7) == 0); } - OPENSSL_memcpy(ctx->password_scalar, password_scalar.bytes, + OPENSSL_memcpy(ctx->password_scalar, password_scalar.words, sizeof(ctx->password_scalar)); ge_p3 mask; diff --git a/Sources/CNIOBoringSSL/crypto/dsa/dsa.c b/Sources/CNIOBoringSSL/crypto/dsa/dsa.c index 303692b2..2503aaba 100644 --- a/Sources/CNIOBoringSSL/crypto/dsa/dsa.c +++ b/Sources/CNIOBoringSSL/crypto/dsa/dsa.c @@ -130,6 +130,8 @@ int DSA_up_ref(DSA *dsa) { return 1; } +unsigned DSA_bits(const DSA *dsa) { return BN_num_bits(dsa->p); } + const BIGNUM *DSA_get0_pub_key(const DSA *dsa) { return dsa->pub_key; } const BIGNUM *DSA_get0_priv_key(const DSA *dsa) { return dsa->priv_key; } diff --git a/Sources/CNIOBoringSSL/crypto/ec_extra/hash_to_curve.c b/Sources/CNIOBoringSSL/crypto/ec_extra/hash_to_curve.c index 6f1e388c..4e22e822 100644 --- a/Sources/CNIOBoringSSL/crypto/ec_extra/hash_to_curve.c +++ b/Sources/CNIOBoringSSL/crypto/ec_extra/hash_to_curve.c @@ -17,7 +17,6 @@ #include #include #include -#include #include @@ -61,7 +60,7 @@ static int expand_message_xmd(const EVP_MD *md, uint8_t *out, size_t out_len, EVP_MD_CTX_init(&ctx); // Long DSTs are hashed down to size. See section 5.3.3. - OPENSSL_STATIC_ASSERT(EVP_MAX_MD_SIZE < 256, "hashed DST still too large"); + static_assert(EVP_MAX_MD_SIZE < 256, "hashed DST still too large"); uint8_t dst_buf[EVP_MAX_MD_SIZE]; if (dst_len >= 256) { static const char kPrefix[] = "H2C-OVERSIZE-DST-"; diff --git a/Sources/CNIOBoringSSL/crypto/err/err_data.c b/Sources/CNIOBoringSSL/crypto/err/err_data.c index 4feb6789..a7f85ca9 100644 --- a/Sources/CNIOBoringSSL/crypto/err/err_data.c +++ b/Sources/CNIOBoringSSL/crypto/err/err_data.c @@ -16,43 +16,43 @@ #include #include -#include +#include -OPENSSL_STATIC_ASSERT(ERR_LIB_NONE == 1, "library value changed"); -OPENSSL_STATIC_ASSERT(ERR_LIB_SYS == 2, "library value changed"); -OPENSSL_STATIC_ASSERT(ERR_LIB_BN == 3, "library value changed"); -OPENSSL_STATIC_ASSERT(ERR_LIB_RSA == 4, "library value changed"); -OPENSSL_STATIC_ASSERT(ERR_LIB_DH == 5, "library value changed"); -OPENSSL_STATIC_ASSERT(ERR_LIB_EVP == 6, "library value changed"); -OPENSSL_STATIC_ASSERT(ERR_LIB_BUF == 7, "library value changed"); -OPENSSL_STATIC_ASSERT(ERR_LIB_OBJ == 8, "library value changed"); -OPENSSL_STATIC_ASSERT(ERR_LIB_PEM == 9, "library value changed"); -OPENSSL_STATIC_ASSERT(ERR_LIB_DSA == 10, "library value changed"); -OPENSSL_STATIC_ASSERT(ERR_LIB_X509 == 11, "library value changed"); -OPENSSL_STATIC_ASSERT(ERR_LIB_ASN1 == 12, "library value changed"); -OPENSSL_STATIC_ASSERT(ERR_LIB_CONF == 13, "library value changed"); -OPENSSL_STATIC_ASSERT(ERR_LIB_CRYPTO == 14, "library value changed"); -OPENSSL_STATIC_ASSERT(ERR_LIB_EC == 15, "library value changed"); -OPENSSL_STATIC_ASSERT(ERR_LIB_SSL == 16, "library value changed"); -OPENSSL_STATIC_ASSERT(ERR_LIB_BIO == 17, "library value changed"); -OPENSSL_STATIC_ASSERT(ERR_LIB_PKCS7 == 18, "library value changed"); -OPENSSL_STATIC_ASSERT(ERR_LIB_PKCS8 == 19, "library value changed"); -OPENSSL_STATIC_ASSERT(ERR_LIB_X509V3 == 20, "library value changed"); -OPENSSL_STATIC_ASSERT(ERR_LIB_RAND == 21, "library value changed"); -OPENSSL_STATIC_ASSERT(ERR_LIB_ENGINE == 22, "library value changed"); -OPENSSL_STATIC_ASSERT(ERR_LIB_OCSP == 23, "library value changed"); -OPENSSL_STATIC_ASSERT(ERR_LIB_UI == 24, "library value changed"); -OPENSSL_STATIC_ASSERT(ERR_LIB_COMP == 25, "library value changed"); -OPENSSL_STATIC_ASSERT(ERR_LIB_ECDSA == 26, "library value changed"); -OPENSSL_STATIC_ASSERT(ERR_LIB_ECDH == 27, "library value changed"); -OPENSSL_STATIC_ASSERT(ERR_LIB_HMAC == 28, "library value changed"); -OPENSSL_STATIC_ASSERT(ERR_LIB_DIGEST == 29, "library value changed"); -OPENSSL_STATIC_ASSERT(ERR_LIB_CIPHER == 30, "library value changed"); -OPENSSL_STATIC_ASSERT(ERR_LIB_HKDF == 31, "library value changed"); -OPENSSL_STATIC_ASSERT(ERR_LIB_TRUST_TOKEN == 32, "library value changed"); -OPENSSL_STATIC_ASSERT(ERR_LIB_USER == 33, "library value changed"); -OPENSSL_STATIC_ASSERT(ERR_NUM_LIBS == 34, "number of libraries changed"); +static_assert(ERR_LIB_NONE == 1, "library value changed"); +static_assert(ERR_LIB_SYS == 2, "library value changed"); +static_assert(ERR_LIB_BN == 3, "library value changed"); +static_assert(ERR_LIB_RSA == 4, "library value changed"); +static_assert(ERR_LIB_DH == 5, "library value changed"); +static_assert(ERR_LIB_EVP == 6, "library value changed"); +static_assert(ERR_LIB_BUF == 7, "library value changed"); +static_assert(ERR_LIB_OBJ == 8, "library value changed"); +static_assert(ERR_LIB_PEM == 9, "library value changed"); +static_assert(ERR_LIB_DSA == 10, "library value changed"); +static_assert(ERR_LIB_X509 == 11, "library value changed"); +static_assert(ERR_LIB_ASN1 == 12, "library value changed"); +static_assert(ERR_LIB_CONF == 13, "library value changed"); +static_assert(ERR_LIB_CRYPTO == 14, "library value changed"); +static_assert(ERR_LIB_EC == 15, "library value changed"); +static_assert(ERR_LIB_SSL == 16, "library value changed"); +static_assert(ERR_LIB_BIO == 17, "library value changed"); +static_assert(ERR_LIB_PKCS7 == 18, "library value changed"); +static_assert(ERR_LIB_PKCS8 == 19, "library value changed"); +static_assert(ERR_LIB_X509V3 == 20, "library value changed"); +static_assert(ERR_LIB_RAND == 21, "library value changed"); +static_assert(ERR_LIB_ENGINE == 22, "library value changed"); +static_assert(ERR_LIB_OCSP == 23, "library value changed"); +static_assert(ERR_LIB_UI == 24, "library value changed"); +static_assert(ERR_LIB_COMP == 25, "library value changed"); +static_assert(ERR_LIB_ECDSA == 26, "library value changed"); +static_assert(ERR_LIB_ECDH == 27, "library value changed"); +static_assert(ERR_LIB_HMAC == 28, "library value changed"); +static_assert(ERR_LIB_DIGEST == 29, "library value changed"); +static_assert(ERR_LIB_CIPHER == 30, "library value changed"); +static_assert(ERR_LIB_HKDF == 31, "library value changed"); +static_assert(ERR_LIB_TRUST_TOKEN == 32, "library value changed"); +static_assert(ERR_LIB_USER == 33, "library value changed"); +static_assert(ERR_NUM_LIBS == 34, "number of libraries changed"); const uint32_t kOpenSSLReasonValues[] = { 0xc320885, diff --git a/Sources/CNIOBoringSSL/crypto/evp/scrypt.c b/Sources/CNIOBoringSSL/crypto/evp/scrypt.c index 54bee65e..50ac7a96 100644 --- a/Sources/CNIOBoringSSL/crypto/evp/scrypt.c +++ b/Sources/CNIOBoringSSL/crypto/evp/scrypt.c @@ -13,7 +13,6 @@ #include #include -#include #include "../internal.h" @@ -30,7 +29,7 @@ // A block_t is a Salsa20 block. typedef struct { uint32_t words[16]; } block_t; -OPENSSL_STATIC_ASSERT(sizeof(block_t) == 64, "block_t has padding"); +static_assert(sizeof(block_t) == 64, "block_t has padding"); // salsa208_word_specification implements the Salsa20/8 core function, also // described in RFC 7914, section 3. It modifies the block at |inout| @@ -171,7 +170,7 @@ int EVP_PBE_scrypt(const char *password, size_t password_len, // Allocate and divide up the scratch space. |max_mem| fits in a size_t, which // is no bigger than uint64_t, so none of these operations may overflow. - OPENSSL_STATIC_ASSERT(UINT64_MAX >= ((size_t)-1), "size_t exceeds uint64_t"); + static_assert(UINT64_MAX >= ((size_t)-1), "size_t exceeds uint64_t"); size_t B_blocks = p * 2 * r; size_t B_bytes = B_blocks * sizeof(block_t); size_t T_blocks = 2 * r; diff --git a/Sources/CNIOBoringSSL/crypto/fipsmodule/aes/aes_nohw.c b/Sources/CNIOBoringSSL/crypto/fipsmodule/aes/aes_nohw.c index 46600868..4f9c3d7d 100644 --- a/Sources/CNIOBoringSSL/crypto/fipsmodule/aes/aes_nohw.c +++ b/Sources/CNIOBoringSSL/crypto/fipsmodule/aes/aes_nohw.c @@ -152,10 +152,10 @@ static inline aes_word_t aes_nohw_shift_right(aes_word_t a, aes_word_t i) { } #endif // OPENSSL_SSE2 -OPENSSL_STATIC_ASSERT(AES_NOHW_BATCH_SIZE * 128 == 8 * 8 * sizeof(aes_word_t), - "batch size does not match word size"); -OPENSSL_STATIC_ASSERT(AES_NOHW_WORD_SIZE == sizeof(aes_word_t), - "AES_NOHW_WORD_SIZE is incorrect"); +static_assert(AES_NOHW_BATCH_SIZE * 128 == 8 * 8 * sizeof(aes_word_t), + "batch size does not match word size"); +static_assert(AES_NOHW_WORD_SIZE == sizeof(aes_word_t), + "AES_NOHW_WORD_SIZE is incorrect"); // Block representations. diff --git a/Sources/CNIOBoringSSL/crypto/fipsmodule/bn/bn.c b/Sources/CNIOBoringSSL/crypto/fipsmodule/bn/bn.c index ae07fd35..6f29ee37 100644 --- a/Sources/CNIOBoringSSL/crypto/fipsmodule/bn/bn.c +++ b/Sources/CNIOBoringSSL/crypto/fipsmodule/bn/bn.c @@ -56,6 +56,7 @@ #include +#include #include #include @@ -416,8 +417,8 @@ int bn_resize_words(BIGNUM *bn, size_t words) { void bn_select_words(BN_ULONG *r, BN_ULONG mask, const BN_ULONG *a, const BN_ULONG *b, size_t num) { for (size_t i = 0; i < num; i++) { - OPENSSL_STATIC_ASSERT(sizeof(BN_ULONG) <= sizeof(crypto_word_t), - "crypto_word_t is too small"); + static_assert(sizeof(BN_ULONG) <= sizeof(crypto_word_t), + "crypto_word_t is too small"); r[i] = constant_time_select_w(mask, a[i], b[i]); } } diff --git a/Sources/CNIOBoringSSL/crypto/fipsmodule/bn/cmp.c b/Sources/CNIOBoringSSL/crypto/fipsmodule/bn/cmp.c index 18b2b658..c6e896f3 100644 --- a/Sources/CNIOBoringSSL/crypto/fipsmodule/bn/cmp.c +++ b/Sources/CNIOBoringSSL/crypto/fipsmodule/bn/cmp.c @@ -56,8 +56,9 @@ #include +#include + #include -#include #include "internal.h" #include "../../internal.h" @@ -65,8 +66,8 @@ static int bn_cmp_words_consttime(const BN_ULONG *a, size_t a_len, const BN_ULONG *b, size_t b_len) { - OPENSSL_STATIC_ASSERT(sizeof(BN_ULONG) <= sizeof(crypto_word_t), - "crypto_word_t is too small"); + static_assert(sizeof(BN_ULONG) <= sizeof(crypto_word_t), + "crypto_word_t is too small"); int ret = 0; // Process the common words in little-endian order. size_t min = a_len < b_len ? a_len : b_len; diff --git a/Sources/CNIOBoringSSL/crypto/fipsmodule/bn/montgomery.c b/Sources/CNIOBoringSSL/crypto/fipsmodule/bn/montgomery.c index f3d00517..c77af161 100644 --- a/Sources/CNIOBoringSSL/crypto/fipsmodule/bn/montgomery.c +++ b/Sources/CNIOBoringSSL/crypto/fipsmodule/bn/montgomery.c @@ -116,7 +116,6 @@ #include #include #include -#include #include "internal.h" #include "../../internal.h" @@ -190,11 +189,10 @@ static int bn_mont_ctx_set_N_and_n0(BN_MONT_CTX *mont, const BIGNUM *mod) { // others, we could use a shorter R value and use faster |BN_ULONG|-based // math instead of |uint64_t|-based math, which would be double-precision. // However, currently only the assembler files know which is which. - OPENSSL_STATIC_ASSERT(BN_MONT_CTX_N0_LIMBS == 1 || BN_MONT_CTX_N0_LIMBS == 2, - "BN_MONT_CTX_N0_LIMBS value is invalid"); - OPENSSL_STATIC_ASSERT( - sizeof(BN_ULONG) * BN_MONT_CTX_N0_LIMBS == sizeof(uint64_t), - "uint64_t is insufficient precision for n0"); + static_assert(BN_MONT_CTX_N0_LIMBS == 1 || BN_MONT_CTX_N0_LIMBS == 2, + "BN_MONT_CTX_N0_LIMBS value is invalid"); + static_assert(sizeof(BN_ULONG) * BN_MONT_CTX_N0_LIMBS == sizeof(uint64_t), + "uint64_t is insufficient precision for n0"); uint64_t n0 = bn_mont_n0(&mont->N); mont->n0[0] = (BN_ULONG)n0; #if BN_MONT_CTX_N0_LIMBS == 2 diff --git a/Sources/CNIOBoringSSL/crypto/fipsmodule/bn/montgomery_inv.c b/Sources/CNIOBoringSSL/crypto/fipsmodule/bn/montgomery_inv.c index c9e8106d..102115ec 100644 --- a/Sources/CNIOBoringSSL/crypto/fipsmodule/bn/montgomery_inv.c +++ b/Sources/CNIOBoringSSL/crypto/fipsmodule/bn/montgomery_inv.c @@ -22,11 +22,10 @@ static uint64_t bn_neg_inv_mod_r_u64(uint64_t n); -OPENSSL_STATIC_ASSERT(BN_MONT_CTX_N0_LIMBS == 1 || BN_MONT_CTX_N0_LIMBS == 2, - "BN_MONT_CTX_N0_LIMBS value is invalid"); -OPENSSL_STATIC_ASSERT(sizeof(BN_ULONG) * BN_MONT_CTX_N0_LIMBS == - sizeof(uint64_t), - "uint64_t is insufficient precision for n0"); +static_assert(BN_MONT_CTX_N0_LIMBS == 1 || BN_MONT_CTX_N0_LIMBS == 2, + "BN_MONT_CTX_N0_LIMBS value is invalid"); +static_assert(sizeof(BN_ULONG) * BN_MONT_CTX_N0_LIMBS == sizeof(uint64_t), + "uint64_t is insufficient precision for n0"); // LG_LITTLE_R is log_2(r). #define LG_LITTLE_R (BN_MONT_CTX_N0_LIMBS * BN_BITS2) diff --git a/Sources/CNIOBoringSSL/crypto/fipsmodule/bn/mul.c b/Sources/CNIOBoringSSL/crypto/fipsmodule/bn/mul.c index 7895035c..4896c464 100644 --- a/Sources/CNIOBoringSSL/crypto/fipsmodule/bn/mul.c +++ b/Sources/CNIOBoringSSL/crypto/fipsmodule/bn/mul.c @@ -62,7 +62,6 @@ #include #include -#include #include "internal.h" #include "../../internal.h" @@ -281,8 +280,8 @@ static void bn_mul_recursive(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, BN_ULONG c_neg = c - bn_sub_words(&t[n2 * 2], t, &t[n2], n2); BN_ULONG c_pos = c + bn_add_words(&t[n2], t, &t[n2], n2); bn_select_words(&t[n2], neg, &t[n2 * 2], &t[n2], n2); - OPENSSL_STATIC_ASSERT(sizeof(BN_ULONG) <= sizeof(crypto_word_t), - "crypto_word_t is too small"); + static_assert(sizeof(BN_ULONG) <= sizeof(crypto_word_t), + "crypto_word_t is too small"); c = constant_time_select_w(neg, c_neg, c_pos); // We now have our three components. Add them together. @@ -395,8 +394,8 @@ static void bn_mul_part_recursive(BN_ULONG *r, const BN_ULONG *a, BN_ULONG c_neg = c - bn_sub_words(&t[n2 * 2], t, &t[n2], n2); BN_ULONG c_pos = c + bn_add_words(&t[n2], t, &t[n2], n2); bn_select_words(&t[n2], neg, &t[n2 * 2], &t[n2], n2); - OPENSSL_STATIC_ASSERT(sizeof(BN_ULONG) <= sizeof(crypto_word_t), - "crypto_word_t is too small"); + static_assert(sizeof(BN_ULONG) <= sizeof(crypto_word_t), + "crypto_word_t is too small"); c = constant_time_select_w(neg, c_neg, c_pos); // We now have our three components. Add them together. diff --git a/Sources/CNIOBoringSSL/crypto/fipsmodule/bn/random.c b/Sources/CNIOBoringSSL/crypto/fipsmodule/bn/random.c index d272ceea..a26b703e 100644 --- a/Sources/CNIOBoringSSL/crypto/fipsmodule/bn/random.c +++ b/Sources/CNIOBoringSSL/crypto/fipsmodule/bn/random.c @@ -108,12 +108,12 @@ #include +#include #include #include #include #include -#include #include "../../internal.h" #include "../rand/internal.h" @@ -199,8 +199,8 @@ static crypto_word_t bn_less_than_word_mask(const BN_ULONG *a, size_t len, } // |a| < |b| iff a[1..len-1] are all zero and a[0] < b. - OPENSSL_STATIC_ASSERT(sizeof(BN_ULONG) <= sizeof(crypto_word_t), - "crypto_word_t is too small"); + static_assert(sizeof(BN_ULONG) <= sizeof(crypto_word_t), + "crypto_word_t is too small"); crypto_word_t mask = 0; for (size_t i = 1; i < len; i++) { mask |= a[i]; diff --git a/Sources/CNIOBoringSSL/crypto/fipsmodule/bn/rsaz_exp.c b/Sources/CNIOBoringSSL/crypto/fipsmodule/bn/rsaz_exp.c index 08268fb3..ab379f18 100644 --- a/Sources/CNIOBoringSSL/crypto/fipsmodule/bn/rsaz_exp.c +++ b/Sources/CNIOBoringSSL/crypto/fipsmodule/bn/rsaz_exp.c @@ -18,6 +18,8 @@ #include +#include + #include "internal.h" #include "../../internal.h" @@ -38,8 +40,8 @@ void RSAZ_1024_mod_exp_avx2(BN_ULONG result_norm[16], const BN_ULONG m_norm[16], const BN_ULONG RR[16], BN_ULONG k0, BN_ULONG storage[MOD_EXP_CTIME_STORAGE_LEN]) { - OPENSSL_STATIC_ASSERT(MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH % 64 == 0, - "MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH is too small"); + static_assert(MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH % 64 == 0, + "MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH is too small"); assert((uintptr_t)storage % 64 == 0); BN_ULONG *a_inv, *m, *result, *table_s = storage + 40 * 3, *R2 = table_s; diff --git a/Sources/CNIOBoringSSL/crypto/fipsmodule/bn/shift.c b/Sources/CNIOBoringSSL/crypto/fipsmodule/bn/shift.c index 364b5261..70443e24 100644 --- a/Sources/CNIOBoringSSL/crypto/fipsmodule/bn/shift.c +++ b/Sources/CNIOBoringSSL/crypto/fipsmodule/bn/shift.c @@ -56,10 +56,10 @@ #include +#include #include #include -#include #include "internal.h" @@ -296,15 +296,14 @@ int BN_mask_bits(BIGNUM *a, int n) { } static int bn_count_low_zero_bits_word(BN_ULONG l) { - OPENSSL_STATIC_ASSERT(sizeof(BN_ULONG) <= sizeof(crypto_word_t), - "crypto_word_t is too small"); - OPENSSL_STATIC_ASSERT(sizeof(int) <= sizeof(crypto_word_t), - "crypto_word_t is too small"); - OPENSSL_STATIC_ASSERT(BN_BITS2 == sizeof(BN_ULONG) * 8, - "BN_ULONG has padding bits"); + static_assert(sizeof(BN_ULONG) <= sizeof(crypto_word_t), + "crypto_word_t is too small"); + static_assert(sizeof(int) <= sizeof(crypto_word_t), + "crypto_word_t is too small"); + static_assert(BN_BITS2 == sizeof(BN_ULONG) * 8, "BN_ULONG has padding bits"); // C has very bizarre rules for types smaller than an int. - OPENSSL_STATIC_ASSERT(sizeof(BN_ULONG) >= sizeof(int), - "BN_ULONG gets promoted to int"); + static_assert(sizeof(BN_ULONG) >= sizeof(int), + "BN_ULONG gets promoted to int"); crypto_word_t mask; int bits = 0; @@ -342,10 +341,10 @@ static int bn_count_low_zero_bits_word(BN_ULONG l) { } int BN_count_low_zero_bits(const BIGNUM *bn) { - OPENSSL_STATIC_ASSERT(sizeof(BN_ULONG) <= sizeof(crypto_word_t), - "crypto_word_t is too small"); - OPENSSL_STATIC_ASSERT(sizeof(int) <= sizeof(crypto_word_t), - "crypto_word_t is too small"); + static_assert(sizeof(BN_ULONG) <= sizeof(crypto_word_t), + "crypto_word_t is too small"); + static_assert(sizeof(int) <= sizeof(crypto_word_t), + "crypto_word_t is too small"); int ret = 0; crypto_word_t saw_nonzero = 0; diff --git a/Sources/CNIOBoringSSL/crypto/fipsmodule/cipher/e_aes.c b/Sources/CNIOBoringSSL/crypto/fipsmodule/cipher/e_aes.c index 14d55d42..1d7053f2 100644 --- a/Sources/CNIOBoringSSL/crypto/fipsmodule/cipher/e_aes.c +++ b/Sources/CNIOBoringSSL/crypto/fipsmodule/cipher/e_aes.c @@ -335,7 +335,7 @@ ctr128_f aes_ctr_set_key(AES_KEY *aes_key, GCM128_KEY *gcm_key, #endif static EVP_AES_GCM_CTX *aes_gcm_from_cipher_ctx(EVP_CIPHER_CTX *ctx) { - OPENSSL_STATIC_ASSERT( + static_assert( alignof(EVP_AES_GCM_CTX) <= 16, "EVP_AES_GCM_CTX needs more alignment than this function provides"); @@ -921,12 +921,12 @@ static int aead_aes_gcm_init_impl(struct aead_aes_gcm_ctx *gcm_ctx, return 1; } -OPENSSL_STATIC_ASSERT(sizeof(((EVP_AEAD_CTX *)NULL)->state) >= - sizeof(struct aead_aes_gcm_ctx), - "AEAD state is too small"); -OPENSSL_STATIC_ASSERT(alignof(union evp_aead_ctx_st_state) >= - alignof(struct aead_aes_gcm_ctx), - "AEAD state has insufficient alignment"); +static_assert(sizeof(((EVP_AEAD_CTX *)NULL)->state) >= + sizeof(struct aead_aes_gcm_ctx), + "AEAD state is too small"); +static_assert(alignof(union evp_aead_ctx_st_state) >= + alignof(struct aead_aes_gcm_ctx), + "AEAD state has insufficient alignment"); static int aead_aes_gcm_init(EVP_AEAD_CTX *ctx, const uint8_t *key, size_t key_len, size_t requested_tag_len) { @@ -1259,12 +1259,12 @@ struct aead_aes_gcm_tls12_ctx { uint64_t min_next_nonce; }; -OPENSSL_STATIC_ASSERT(sizeof(((EVP_AEAD_CTX *)NULL)->state) >= - sizeof(struct aead_aes_gcm_tls12_ctx), - "AEAD state is too small"); -OPENSSL_STATIC_ASSERT(alignof(union evp_aead_ctx_st_state) >= - alignof(struct aead_aes_gcm_tls12_ctx), - "AEAD state has insufficient alignment"); +static_assert(sizeof(((EVP_AEAD_CTX *)NULL)->state) >= + sizeof(struct aead_aes_gcm_tls12_ctx), + "AEAD state is too small"); +static_assert(alignof(union evp_aead_ctx_st_state) >= + alignof(struct aead_aes_gcm_tls12_ctx), + "AEAD state has insufficient alignment"); static int aead_aes_gcm_tls12_init(EVP_AEAD_CTX *ctx, const uint8_t *key, size_t key_len, size_t requested_tag_len) { @@ -1353,12 +1353,12 @@ struct aead_aes_gcm_tls13_ctx { uint8_t first; }; -OPENSSL_STATIC_ASSERT(sizeof(((EVP_AEAD_CTX *)NULL)->state) >= - sizeof(struct aead_aes_gcm_tls13_ctx), - "AEAD state is too small"); -OPENSSL_STATIC_ASSERT(alignof(union evp_aead_ctx_st_state) >= - alignof(struct aead_aes_gcm_tls13_ctx), - "AEAD state has insufficient alignment"); +static_assert(sizeof(((EVP_AEAD_CTX *)NULL)->state) >= + sizeof(struct aead_aes_gcm_tls13_ctx), + "AEAD state is too small"); +static_assert(alignof(union evp_aead_ctx_st_state) >= + alignof(struct aead_aes_gcm_tls13_ctx), + "AEAD state has insufficient alignment"); static int aead_aes_gcm_tls13_init(EVP_AEAD_CTX *ctx, const uint8_t *key, size_t key_len, size_t requested_tag_len) { diff --git a/Sources/CNIOBoringSSL/crypto/fipsmodule/cipher/e_aesccm.c b/Sources/CNIOBoringSSL/crypto/fipsmodule/cipher/e_aesccm.c index ad35f086..5e8f789e 100644 --- a/Sources/CNIOBoringSSL/crypto/fipsmodule/cipher/e_aesccm.c +++ b/Sources/CNIOBoringSSL/crypto/fipsmodule/cipher/e_aesccm.c @@ -276,12 +276,12 @@ struct aead_aes_ccm_ctx { struct ccm128_context ccm; }; -OPENSSL_STATIC_ASSERT(sizeof(((EVP_AEAD_CTX *)NULL)->state) >= - sizeof(struct aead_aes_ccm_ctx), - "AEAD state is too small"); -OPENSSL_STATIC_ASSERT(alignof(union evp_aead_ctx_st_state) >= - alignof(struct aead_aes_ccm_ctx), - "AEAD state has insufficient alignment"); +static_assert(sizeof(((EVP_AEAD_CTX *)NULL)->state) >= + sizeof(struct aead_aes_ccm_ctx), + "AEAD state is too small"); +static_assert(alignof(union evp_aead_ctx_st_state) >= + alignof(struct aead_aes_ccm_ctx), + "AEAD state has insufficient alignment"); static int aead_aes_ccm_init(EVP_AEAD_CTX *ctx, const uint8_t *key, size_t key_len, size_t tag_len, unsigned M, @@ -432,3 +432,22 @@ DEFINE_METHOD_FUNCTION(EVP_AEAD, EVP_aead_aes_128_ccm_bluetooth_8) { out->seal_scatter = aead_aes_ccm_seal_scatter; out->open_gather = aead_aes_ccm_open_gather; } + +static int aead_aes_ccm_matter_init(EVP_AEAD_CTX *ctx, const uint8_t *key, + size_t key_len, size_t tag_len) { + return aead_aes_ccm_init(ctx, key, key_len, tag_len, 16, 2); +} + +DEFINE_METHOD_FUNCTION(EVP_AEAD, EVP_aead_aes_128_ccm_matter) { + memset(out, 0, sizeof(EVP_AEAD)); + + out->key_len = 16; + out->nonce_len = 13; + out->overhead = 16; + out->max_tag_len = 16; + + out->init = aead_aes_ccm_matter_init; + out->cleanup = aead_aes_ccm_cleanup; + out->seal_scatter = aead_aes_ccm_seal_scatter; + out->open_gather = aead_aes_ccm_open_gather; +} diff --git a/Sources/CNIOBoringSSL/crypto/fipsmodule/dh/dh.c b/Sources/CNIOBoringSSL/crypto/fipsmodule/dh/dh.c index b20fac3b..de51e7f2 100644 --- a/Sources/CNIOBoringSSL/crypto/fipsmodule/dh/dh.c +++ b/Sources/CNIOBoringSSL/crypto/fipsmodule/dh/dh.c @@ -111,6 +111,8 @@ void DH_free(DH *dh) { OPENSSL_free(dh); } +unsigned DH_bits(const DH *dh) { return BN_num_bits(dh->p); } + const BIGNUM *DH_get0_pub_key(const DH *dh) { return dh->pub_key; } const BIGNUM *DH_get0_priv_key(const DH *dh) { return dh->priv_key; } diff --git a/Sources/CNIOBoringSSL/crypto/fipsmodule/ec/ec.c b/Sources/CNIOBoringSSL/crypto/fipsmodule/ec/ec.c index b1cd712c..07be46d2 100644 --- a/Sources/CNIOBoringSSL/crypto/fipsmodule/ec/ec.c +++ b/Sources/CNIOBoringSSL/crypto/fipsmodule/ec/ec.c @@ -1155,8 +1155,8 @@ void ec_affine_select(const EC_GROUP *group, EC_AFFINE *out, BN_ULONG mask, void ec_precomp_select(const EC_GROUP *group, EC_PRECOMP *out, BN_ULONG mask, const EC_PRECOMP *a, const EC_PRECOMP *b) { - OPENSSL_STATIC_ASSERT(sizeof(out->comb) == sizeof(*out), - "out->comb does not span the entire structure"); + static_assert(sizeof(out->comb) == sizeof(*out), + "out->comb does not span the entire structure"); for (size_t i = 0; i < OPENSSL_ARRAY_SIZE(out->comb); i++) { ec_affine_select(group, &out->comb[i], mask, &a->comb[i], &b->comb[i]); } diff --git a/Sources/CNIOBoringSSL/crypto/fipsmodule/ec/internal.h b/Sources/CNIOBoringSSL/crypto/fipsmodule/ec/internal.h index e1016789..3062909b 100644 --- a/Sources/CNIOBoringSSL/crypto/fipsmodule/ec/internal.h +++ b/Sources/CNIOBoringSSL/crypto/fipsmodule/ec/internal.h @@ -70,10 +70,11 @@ #include +#include + #include #include #include -#include #include "../bn/internal.h" @@ -91,8 +92,8 @@ extern "C" { #define EC_MAX_BYTES 66 #define EC_MAX_WORDS ((EC_MAX_BYTES + BN_BYTES - 1) / BN_BYTES) -OPENSSL_STATIC_ASSERT(EC_MAX_WORDS <= BN_SMALL_MAX_WORDS, - "bn_*_small functions not usable"); +static_assert(EC_MAX_WORDS <= BN_SMALL_MAX_WORDS, + "bn_*_small functions not usable"); // Scalars. diff --git a/Sources/CNIOBoringSSL/crypto/fipsmodule/ec/p256-nistz.h b/Sources/CNIOBoringSSL/crypto/fipsmodule/ec/p256-nistz.h index 3ca41151..e61d18fe 100644 --- a/Sources/CNIOBoringSSL/crypto/fipsmodule/ec/p256-nistz.h +++ b/Sources/CNIOBoringSSL/crypto/fipsmodule/ec/p256-nistz.h @@ -64,16 +64,6 @@ static inline void ecp_nistz256_from_mont(BN_ULONG res[P256_LIMBS], ecp_nistz256_mul_mont(res, in, ONE); } -// ecp_nistz256_to_mont sets |res| to |in|, converted to Montgomery domain -// by multiplying with RR = 2^512 mod P precomputed for NIST P256 curve. -static inline void ecp_nistz256_to_mont(BN_ULONG res[P256_LIMBS], - const BN_ULONG in[P256_LIMBS]) { - static const BN_ULONG RR[P256_LIMBS] = { - TOBN(0x00000000, 0x00000003), TOBN(0xfffffffb, 0xffffffff), - TOBN(0xffffffff, 0xfffffffe), TOBN(0x00000004, 0xfffffffd)}; - ecp_nistz256_mul_mont(res, in, RR); -} - // P-256 scalar operations. // diff --git a/Sources/CNIOBoringSSL/crypto/fipsmodule/ec/p256.c b/Sources/CNIOBoringSSL/crypto/fipsmodule/ec/p256.c index 6b0c976d..b75181b1 100644 --- a/Sources/CNIOBoringSSL/crypto/fipsmodule/ec/p256.c +++ b/Sources/CNIOBoringSSL/crypto/fipsmodule/ec/p256.c @@ -22,7 +22,6 @@ #include #include #include -#include #include #include diff --git a/Sources/CNIOBoringSSL/crypto/fipsmodule/ec/simple_mul.c b/Sources/CNIOBoringSSL/crypto/fipsmodule/ec/simple_mul.c index 9675625c..9a3d77f2 100644 --- a/Sources/CNIOBoringSSL/crypto/fipsmodule/ec/simple_mul.c +++ b/Sources/CNIOBoringSSL/crypto/fipsmodule/ec/simple_mul.c @@ -202,9 +202,8 @@ int ec_GFp_mont_init_precomp(const EC_GROUP *group, EC_PRECOMP *out, // Store the comb in affine coordinates to shrink the table. (This reduces // cache pressure and makes the constant-time selects faster.) - OPENSSL_STATIC_ASSERT( - OPENSSL_ARRAY_SIZE(comb) == OPENSSL_ARRAY_SIZE(out->comb), - "comb sizes did not match"); + static_assert(OPENSSL_ARRAY_SIZE(comb) == OPENSSL_ARRAY_SIZE(out->comb), + "comb sizes did not match"); return ec_jacobian_to_affine_batch(group, out->comb, comb, OPENSSL_ARRAY_SIZE(comb)); } diff --git a/Sources/CNIOBoringSSL/crypto/fipsmodule/ecdsa/ecdsa.c b/Sources/CNIOBoringSSL/crypto/fipsmodule/ecdsa/ecdsa.c index 7dbc3d61..5aedb63c 100644 --- a/Sources/CNIOBoringSSL/crypto/fipsmodule/ecdsa/ecdsa.c +++ b/Sources/CNIOBoringSSL/crypto/fipsmodule/ecdsa/ecdsa.c @@ -59,7 +59,6 @@ #include #include #include -#include #include "../../internal.h" #include "../bn/internal.h" @@ -322,8 +321,8 @@ ECDSA_SIG *ECDSA_do_sign(const uint8_t *digest, size_t digest_len, // Pass a SHA512 hash of the private key and digest as additional data // into the RBG. This is a hardening measure against entropy failure. - OPENSSL_STATIC_ASSERT(SHA512_DIGEST_LENGTH >= 32, - "additional_data is too large for SHA-512"); + static_assert(SHA512_DIGEST_LENGTH >= 32, + "additional_data is too large for SHA-512"); FIPS_service_indicator_lock_state(); diff --git a/Sources/CNIOBoringSSL/crypto/fipsmodule/hmac/hmac.c b/Sources/CNIOBoringSSL/crypto/fipsmodule/hmac/hmac.c index b0ea782f..77f62adc 100644 --- a/Sources/CNIOBoringSSL/crypto/fipsmodule/hmac/hmac.c +++ b/Sources/CNIOBoringSSL/crypto/fipsmodule/hmac/hmac.c @@ -224,9 +224,9 @@ int HMAC_Final(HMAC_CTX *ctx, uint8_t *out, unsigned int *out_len) { return ret; } -size_t HMAC_size(const HMAC_CTX *ctx) { - return EVP_MD_size(ctx->md); -} +size_t HMAC_size(const HMAC_CTX *ctx) { return EVP_MD_size(ctx->md); } + +const EVP_MD *HMAC_CTX_get_md(const HMAC_CTX *ctx) { return ctx->md; } int HMAC_CTX_copy_ex(HMAC_CTX *dest, const HMAC_CTX *src) { if (!EVP_MD_CTX_copy_ex(&dest->i_ctx, &src->i_ctx) || diff --git a/Sources/CNIOBoringSSL/crypto/fipsmodule/modes/cbc.c b/Sources/CNIOBoringSSL/crypto/fipsmodule/modes/cbc.c index 08a4c24a..df8f9ce8 100644 --- a/Sources/CNIOBoringSSL/crypto/fipsmodule/modes/cbc.c +++ b/Sources/CNIOBoringSSL/crypto/fipsmodule/modes/cbc.c @@ -49,8 +49,6 @@ #include #include -#include - #include "internal.h" #include "../../internal.h" @@ -120,8 +118,8 @@ void CRYPTO_cbc128_decrypt(const uint8_t *in, uint8_t *out, size_t len, if ((inptr >= 32 && outptr <= inptr - 32) || inptr < outptr) { // If |out| is at least two blocks behind |in| or completely disjoint, there // is no need to decrypt to a temporary block. - OPENSSL_STATIC_ASSERT(16 % sizeof(crypto_word_t) == 0, - "block cannot be evenly divided into words"); + static_assert(16 % sizeof(crypto_word_t) == 0, + "block cannot be evenly divided into words"); const uint8_t *iv = ivec; while (len >= 16) { (*block)(in, out, key); @@ -136,8 +134,8 @@ void CRYPTO_cbc128_decrypt(const uint8_t *in, uint8_t *out, size_t len, } OPENSSL_memcpy(ivec, iv, 16); } else { - OPENSSL_STATIC_ASSERT(16 % sizeof(crypto_word_t) == 0, - "block cannot be evenly divided into words"); + static_assert(16 % sizeof(crypto_word_t) == 0, + "block cannot be evenly divided into words"); while (len >= 16) { (*block)(in, tmp, key); diff --git a/Sources/CNIOBoringSSL/crypto/fipsmodule/modes/cfb.c b/Sources/CNIOBoringSSL/crypto/fipsmodule/modes/cfb.c index 9cb9c6ad..37a81843 100644 --- a/Sources/CNIOBoringSSL/crypto/fipsmodule/modes/cfb.c +++ b/Sources/CNIOBoringSSL/crypto/fipsmodule/modes/cfb.c @@ -46,16 +46,13 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. * ==================================================================== */ -#include - #include #include #include "internal.h" -OPENSSL_STATIC_ASSERT(16 % sizeof(size_t) == 0, - "block cannot be divided into size_t"); +static_assert(16 % sizeof(size_t) == 0, "block cannot be divided into size_t"); void CRYPTO_cfb128_encrypt(const uint8_t *in, uint8_t *out, size_t len, const AES_KEY *key, uint8_t ivec[16], unsigned *num, diff --git a/Sources/CNIOBoringSSL/crypto/fipsmodule/modes/ctr.c b/Sources/CNIOBoringSSL/crypto/fipsmodule/modes/ctr.c index 893a58d0..1688f823 100644 --- a/Sources/CNIOBoringSSL/crypto/fipsmodule/modes/ctr.c +++ b/Sources/CNIOBoringSSL/crypto/fipsmodule/modes/ctr.c @@ -46,8 +46,6 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. * ==================================================================== */ -#include - #include #include @@ -70,8 +68,8 @@ static void ctr128_inc(uint8_t *counter) { } while (n); } -OPENSSL_STATIC_ASSERT(16 % sizeof(crypto_word_t) == 0, - "block cannot be divided into crypto_word_t"); +static_assert(16 % sizeof(crypto_word_t) == 0, + "block cannot be divided into crypto_word_t"); // The input encrypted as though 128bit counter mode is being used. The extra // state information to record how much of the 128bit block we have used is diff --git a/Sources/CNIOBoringSSL/crypto/fipsmodule/modes/ofb.c b/Sources/CNIOBoringSSL/crypto/fipsmodule/modes/ofb.c index fd4078ff..5effba66 100644 --- a/Sources/CNIOBoringSSL/crypto/fipsmodule/modes/ofb.c +++ b/Sources/CNIOBoringSSL/crypto/fipsmodule/modes/ofb.c @@ -46,16 +46,13 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. * ==================================================================== */ -#include - #include #include #include "internal.h" -OPENSSL_STATIC_ASSERT(16 % sizeof(size_t) == 0, - "block cannot be divided into size_t"); +static_assert(16 % sizeof(size_t) == 0, "block cannot be divided into size_t"); void CRYPTO_ofb128_encrypt(const uint8_t *in, uint8_t *out, size_t len, const AES_KEY *key, uint8_t ivec[16], unsigned *num, diff --git a/Sources/CNIOBoringSSL/crypto/fipsmodule/p256-armv8-asm.ios.aarch64.S b/Sources/CNIOBoringSSL/crypto/fipsmodule/p256-armv8-asm.ios.aarch64.S index 2dd3dcd2..8bd50ec2 100644 --- a/Sources/CNIOBoringSSL/crypto/fipsmodule/p256-armv8-asm.ios.aarch64.S +++ b/Sources/CNIOBoringSSL/crypto/fipsmodule/p256-armv8-asm.ios.aarch64.S @@ -33,58 +33,6 @@ LordK: .byte 69,67,80,95,78,73,83,84,90,50,53,54,32,102,111,114,32,65,82,77,118,56,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0 .align 2 -// void ecp_nistz256_to_mont(BN_ULONG x0[4],const BN_ULONG x1[4]); -.globl _ecp_nistz256_to_mont -.private_extern _ecp_nistz256_to_mont - -.align 6 -_ecp_nistz256_to_mont: - AARCH64_SIGN_LINK_REGISTER - stp x29,x30,[sp,#-32]! - add x29,sp,#0 - stp x19,x20,[sp,#16] - - ldr x3,LRR // bp[0] - ldp x4,x5,[x1] - ldp x6,x7,[x1,#16] - ldr x12,Lpoly+8 - ldr x13,Lpoly+24 - adr x2,LRR // &bp[0] - - bl __ecp_nistz256_mul_mont - - ldp x19,x20,[sp,#16] - ldp x29,x30,[sp],#32 - AARCH64_VALIDATE_LINK_REGISTER - ret - - -// void ecp_nistz256_from_mont(BN_ULONG x0[4],const BN_ULONG x1[4]); -.globl _ecp_nistz256_from_mont -.private_extern _ecp_nistz256_from_mont - -.align 4 -_ecp_nistz256_from_mont: - AARCH64_SIGN_LINK_REGISTER - stp x29,x30,[sp,#-32]! - add x29,sp,#0 - stp x19,x20,[sp,#16] - - mov x3,#1 // bp[0] - ldp x4,x5,[x1] - ldp x6,x7,[x1,#16] - ldr x12,Lpoly+8 - ldr x13,Lpoly+24 - adr x2,Lone // &bp[0] - - bl __ecp_nistz256_mul_mont - - ldp x19,x20,[sp,#16] - ldp x29,x30,[sp],#32 - AARCH64_VALIDATE_LINK_REGISTER - ret - - // void ecp_nistz256_mul_mont(BN_ULONG x0[4],const BN_ULONG x1[4], // const BN_ULONG x2[4]); .globl _ecp_nistz256_mul_mont diff --git a/Sources/CNIOBoringSSL/crypto/fipsmodule/p256-armv8-asm.linux.aarch64.S b/Sources/CNIOBoringSSL/crypto/fipsmodule/p256-armv8-asm.linux.aarch64.S index d1b5e20f..1cea49f5 100644 --- a/Sources/CNIOBoringSSL/crypto/fipsmodule/p256-armv8-asm.linux.aarch64.S +++ b/Sources/CNIOBoringSSL/crypto/fipsmodule/p256-armv8-asm.linux.aarch64.S @@ -34,58 +34,6 @@ .byte 69,67,80,95,78,73,83,84,90,50,53,54,32,102,111,114,32,65,82,77,118,56,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0 .align 2 -// void ecp_nistz256_to_mont(BN_ULONG x0[4],const BN_ULONG x1[4]); -.globl ecp_nistz256_to_mont -.hidden ecp_nistz256_to_mont -.type ecp_nistz256_to_mont,%function -.align 6 -ecp_nistz256_to_mont: - AARCH64_SIGN_LINK_REGISTER - stp x29,x30,[sp,#-32]! - add x29,sp,#0 - stp x19,x20,[sp,#16] - - ldr x3,.LRR // bp[0] - ldp x4,x5,[x1] - ldp x6,x7,[x1,#16] - ldr x12,.Lpoly+8 - ldr x13,.Lpoly+24 - adr x2,.LRR // &bp[0] - - bl __ecp_nistz256_mul_mont - - ldp x19,x20,[sp,#16] - ldp x29,x30,[sp],#32 - AARCH64_VALIDATE_LINK_REGISTER - ret -.size ecp_nistz256_to_mont,.-ecp_nistz256_to_mont - -// void ecp_nistz256_from_mont(BN_ULONG x0[4],const BN_ULONG x1[4]); -.globl ecp_nistz256_from_mont -.hidden ecp_nistz256_from_mont -.type ecp_nistz256_from_mont,%function -.align 4 -ecp_nistz256_from_mont: - AARCH64_SIGN_LINK_REGISTER - stp x29,x30,[sp,#-32]! - add x29,sp,#0 - stp x19,x20,[sp,#16] - - mov x3,#1 // bp[0] - ldp x4,x5,[x1] - ldp x6,x7,[x1,#16] - ldr x12,.Lpoly+8 - ldr x13,.Lpoly+24 - adr x2,.Lone // &bp[0] - - bl __ecp_nistz256_mul_mont - - ldp x19,x20,[sp,#16] - ldp x29,x30,[sp],#32 - AARCH64_VALIDATE_LINK_REGISTER - ret -.size ecp_nistz256_from_mont,.-ecp_nistz256_from_mont - // void ecp_nistz256_mul_mont(BN_ULONG x0[4],const BN_ULONG x1[4], // const BN_ULONG x2[4]); .globl ecp_nistz256_mul_mont diff --git a/Sources/CNIOBoringSSL/crypto/fipsmodule/rand/ctrdrbg.c b/Sources/CNIOBoringSSL/crypto/fipsmodule/rand/ctrdrbg.c index 42157925..4cd6e075 100644 --- a/Sources/CNIOBoringSSL/crypto/fipsmodule/rand/ctrdrbg.c +++ b/Sources/CNIOBoringSSL/crypto/fipsmodule/rand/ctrdrbg.c @@ -12,9 +12,10 @@ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include +#include + +#include -#include #include #include "internal.h" @@ -28,6 +29,21 @@ // See table 3. static const uint64_t kMaxReseedCount = UINT64_C(1) << 48; +CTR_DRBG_STATE *CTR_DRBG_new(const uint8_t entropy[CTR_DRBG_ENTROPY_LEN], + const uint8_t *personalization, + size_t personalization_len) { + CTR_DRBG_STATE *drbg = OPENSSL_malloc(sizeof(CTR_DRBG_STATE)); + if (drbg == NULL || + !CTR_DRBG_init(drbg, entropy, personalization, personalization_len)) { + CTR_DRBG_free(drbg); + return NULL; + } + + return drbg; +} + +void CTR_DRBG_free(CTR_DRBG_STATE *state) { OPENSSL_free(state); } + int CTR_DRBG_init(CTR_DRBG_STATE *drbg, const uint8_t entropy[CTR_DRBG_ENTROPY_LEN], const uint8_t *personalization, size_t personalization_len) { @@ -65,8 +81,8 @@ int CTR_DRBG_init(CTR_DRBG_STATE *drbg, return 1; } -OPENSSL_STATIC_ASSERT(CTR_DRBG_ENTROPY_LEN % AES_BLOCK_SIZE == 0, - "not a multiple of AES block size"); +static_assert(CTR_DRBG_ENTROPY_LEN % AES_BLOCK_SIZE == 0, + "not a multiple of AES block size"); // ctr_inc adds |n| to the last four bytes of |drbg->counter|, treated as a // big-endian number. diff --git a/Sources/CNIOBoringSSL/crypto/fipsmodule/rand/fork_detect.c b/Sources/CNIOBoringSSL/crypto/fipsmodule/rand/fork_detect.c index fd7c1069..18ca0bb1 100644 --- a/Sources/CNIOBoringSSL/crypto/fipsmodule/rand/fork_detect.c +++ b/Sources/CNIOBoringSSL/crypto/fipsmodule/rand/fork_detect.c @@ -21,18 +21,17 @@ #include "fork_detect.h" #if defined(OPENSSL_LINUX) +#include #include #include #include -#include - #include "../delocate.h" #include "../../internal.h" #if defined(MADV_WIPEONFORK) -OPENSSL_STATIC_ASSERT(MADV_WIPEONFORK == 18, "MADV_WIPEONFORK is not 18"); +static_assert(MADV_WIPEONFORK == 18, "MADV_WIPEONFORK is not 18"); #else #define MADV_WIPEONFORK 18 #endif diff --git a/Sources/CNIOBoringSSL/crypto/fipsmodule/rand/getrandom_fillin.h b/Sources/CNIOBoringSSL/crypto/fipsmodule/rand/getrandom_fillin.h index cac718df..272e03b6 100644 --- a/Sources/CNIOBoringSSL/crypto/fipsmodule/rand/getrandom_fillin.h +++ b/Sources/CNIOBoringSSL/crypto/fipsmodule/rand/getrandom_fillin.h @@ -32,6 +32,8 @@ #define EXPECTED_NR_getrandom 384 #elif defined(OPENSSL_PPC64LE) #define EXPECTED_NR_getrandom 359 +#elif defined(OPENSSL_RISCV64) +#define EXPECTED_NR_getrandom 278 #endif #if defined(EXPECTED_NR_getrandom) diff --git a/Sources/CNIOBoringSSL/crypto/fipsmodule/rand/internal.h b/Sources/CNIOBoringSSL/crypto/fipsmodule/rand/internal.h index ecc7729a..aa4fa775 100644 --- a/Sources/CNIOBoringSSL/crypto/fipsmodule/rand/internal.h +++ b/Sources/CNIOBoringSSL/crypto/fipsmodule/rand/internal.h @@ -16,6 +16,7 @@ #define OPENSSL_HEADER_CRYPTO_RAND_INTERNAL_H #include +#include #include "../../internal.h" #include "../modes/internal.h" @@ -49,10 +50,10 @@ void CRYPTO_get_seed_entropy(uint8_t *out_entropy, size_t out_entropy_len, int *out_used_cpu); // RAND_load_entropy supplies |entropy_len| bytes of entropy to the module. The -// |from_cpu| parameter is true iff the entropy was obtained directly from the -// CPU. +// |want_additional_input| parameter is true iff the entropy was obtained from +// a source other than the system, e.g. directly from the CPU. void RAND_load_entropy(const uint8_t *entropy, size_t entropy_len, - int from_cpu); + int want_additional_input); // RAND_need_entropy is implemented outside of the FIPS module and is called // when the module has stopped because it has run out of entropy. @@ -95,17 +96,13 @@ int rand_fork_unsafe_buffering_enabled(void); // CTR_DRBG_STATE contains the state of a CTR_DRBG based on AES-256. See SP // 800-90Ar1. -typedef struct { +struct ctr_drbg_state_st { AES_KEY ks; block128_f block; ctr128_f ctr; uint8_t counter[16]; uint64_t reseed_counter; -} CTR_DRBG_STATE; - -// See SP 800-90Ar1, table 3. -#define CTR_DRBG_ENTROPY_LEN 48 -#define CTR_DRBG_MAX_GENERATE_LENGTH 65536 +}; // CTR_DRBG_init initialises |*drbg| given |CTR_DRBG_ENTROPY_LEN| bytes of // entropy in |entropy| and, optionally, a personalization string up to @@ -116,27 +113,6 @@ OPENSSL_EXPORT int CTR_DRBG_init(CTR_DRBG_STATE *drbg, const uint8_t *personalization, size_t personalization_len); -// CTR_DRBG_reseed reseeds |drbg| given |CTR_DRBG_ENTROPY_LEN| bytes of entropy -// in |entropy| and, optionally, up to |CTR_DRBG_ENTROPY_LEN| bytes of -// additional data. It returns one on success or zero on error. -OPENSSL_EXPORT int CTR_DRBG_reseed(CTR_DRBG_STATE *drbg, - const uint8_t entropy[CTR_DRBG_ENTROPY_LEN], - const uint8_t *additional_data, - size_t additional_data_len); - -// CTR_DRBG_generate processes to up |CTR_DRBG_ENTROPY_LEN| bytes of additional -// data (if any) and then writes |out_len| random bytes to |out|, where -// |out_len| <= |CTR_DRBG_MAX_GENERATE_LENGTH|. It returns one on success or -// zero on error. -OPENSSL_EXPORT int CTR_DRBG_generate(CTR_DRBG_STATE *drbg, uint8_t *out, - size_t out_len, - const uint8_t *additional_data, - size_t additional_data_len); - -// CTR_DRBG_clear zeroises the state of |drbg|. -OPENSSL_EXPORT void CTR_DRBG_clear(CTR_DRBG_STATE *drbg); - - #if defined(OPENSSL_X86_64) && !defined(OPENSSL_NO_ASM) OPENSSL_INLINE int have_rdrand(void) { diff --git a/Sources/CNIOBoringSSL/crypto/fipsmodule/rand/rand.c b/Sources/CNIOBoringSSL/crypto/fipsmodule/rand/rand.c index b204ea53..de5270a0 100644 --- a/Sources/CNIOBoringSSL/crypto/fipsmodule/rand/rand.c +++ b/Sources/CNIOBoringSSL/crypto/fipsmodule/rand/rand.c @@ -23,8 +23,8 @@ #endif #include +#include #include -#include #include "internal.h" #include "fork_detect.h" @@ -162,10 +162,10 @@ static int rdrand(uint8_t *buf, size_t len) { #if defined(BORINGSSL_FIPS) void CRYPTO_get_seed_entropy(uint8_t *out_entropy, size_t out_entropy_len, - int *out_used_cpu) { - *out_used_cpu = 0; + int *out_want_additional_input) { + *out_want_additional_input = 0; if (have_rdrand() && rdrand(out_entropy, out_entropy_len)) { - *out_used_cpu = 1; + *out_want_additional_input = 1; } else { CRYPTO_sysrand_for_seed(out_entropy, out_entropy_len); } @@ -183,20 +183,22 @@ void CRYPTO_get_seed_entropy(uint8_t *out_entropy, size_t out_entropy_len, struct entropy_buffer { // bytes contains entropy suitable for seeding a DRBG. - uint8_t bytes[CTR_DRBG_ENTROPY_LEN * BORINGSSL_FIPS_OVERREAD]; + uint8_t + bytes[CRNGT_BLOCK_SIZE + CTR_DRBG_ENTROPY_LEN * BORINGSSL_FIPS_OVERREAD]; // bytes_valid indicates the number of bytes of |bytes| that contain valid // data. size_t bytes_valid; - // from_cpu is true if any of the contents of |bytes| were obtained directly - // from the CPU. - int from_cpu; + // want_additional_input is true if any of the contents of |bytes| were + // obtained via a method other than from the kernel. In these cases entropy + // from the kernel is also provided via an additional input to the DRBG. + int want_additional_input; }; DEFINE_BSS_GET(struct entropy_buffer, entropy_buffer); DEFINE_STATIC_MUTEX(entropy_buffer_lock); void RAND_load_entropy(const uint8_t *entropy, size_t entropy_len, - int from_cpu) { + int want_additional_input) { struct entropy_buffer *const buffer = entropy_buffer_bss_get(); CRYPTO_STATIC_MUTEX_lock_write(entropy_buffer_lock_bss_get()); @@ -207,14 +209,15 @@ void RAND_load_entropy(const uint8_t *entropy, size_t entropy_len, OPENSSL_memcpy(&buffer->bytes[buffer->bytes_valid], entropy, entropy_len); buffer->bytes_valid += entropy_len; - buffer->from_cpu |= from_cpu && (entropy_len != 0); + buffer->want_additional_input |= + want_additional_input && (entropy_len != 0); CRYPTO_STATIC_MUTEX_unlock_write(entropy_buffer_lock_bss_get()); } // get_seed_entropy fills |out_entropy_len| bytes of |out_entropy| from the // global |entropy_buffer|. static void get_seed_entropy(uint8_t *out_entropy, size_t out_entropy_len, - int *out_used_cpu) { + int *out_want_additional_input) { struct entropy_buffer *const buffer = entropy_buffer_bss_get(); if (out_entropy_len > sizeof(buffer->bytes)) { abort(); @@ -227,53 +230,66 @@ static void get_seed_entropy(uint8_t *out_entropy, size_t out_entropy_len, CRYPTO_STATIC_MUTEX_lock_write(entropy_buffer_lock_bss_get()); } - *out_used_cpu = buffer->from_cpu; + *out_want_additional_input = buffer->want_additional_input; OPENSSL_memcpy(out_entropy, buffer->bytes, out_entropy_len); OPENSSL_memmove(buffer->bytes, &buffer->bytes[out_entropy_len], buffer->bytes_valid - out_entropy_len); buffer->bytes_valid -= out_entropy_len; if (buffer->bytes_valid == 0) { - buffer->from_cpu = 0; + buffer->want_additional_input = 0; } CRYPTO_STATIC_MUTEX_unlock_write(entropy_buffer_lock_bss_get()); } -// rand_get_seed fills |seed| with entropy and sets |*out_used_cpu| to one if -// that entropy came directly from the CPU and zero otherwise. +// rand_get_seed fills |seed| with entropy. In some cases, it will additionally +// fill |additional_input| with entropy to supplement |seed|. It sets +// |*out_additional_input_len| to the number of extra bytes. static void rand_get_seed(struct rand_thread_state *state, uint8_t seed[CTR_DRBG_ENTROPY_LEN], - int *out_used_cpu) { - if (!state->last_block_valid) { - int unused; - get_seed_entropy(state->last_block, sizeof(state->last_block), &unused); - state->last_block_valid = 1; + uint8_t additional_input[CTR_DRBG_ENTROPY_LEN], + size_t *out_additional_input_len) { + uint8_t entropy_bytes[sizeof(state->last_block) + + CTR_DRBG_ENTROPY_LEN * BORINGSSL_FIPS_OVERREAD]; + uint8_t *entropy = entropy_bytes; + size_t entropy_len = sizeof(entropy_bytes); + + if (state->last_block_valid) { + // No need to fill |state->last_block| with entropy from the read. + entropy += sizeof(state->last_block); + entropy_len -= sizeof(state->last_block); } - uint8_t entropy[CTR_DRBG_ENTROPY_LEN * BORINGSSL_FIPS_OVERREAD]; - get_seed_entropy(entropy, sizeof(entropy), out_used_cpu); + int want_additional_input; + get_seed_entropy(entropy, entropy_len, &want_additional_input); + + if (!state->last_block_valid) { + OPENSSL_memcpy(state->last_block, entropy, sizeof(state->last_block)); + entropy += sizeof(state->last_block); + entropy_len -= sizeof(state->last_block); + } // See FIPS 140-2, section 4.9.2. This is the “continuous random number // generator test” which causes the program to randomly abort. Hopefully the // rate of failure is small enough not to be a problem in practice. - if (CRYPTO_memcmp(state->last_block, entropy, CRNGT_BLOCK_SIZE) == 0) { + if (CRYPTO_memcmp(state->last_block, entropy, sizeof(state->last_block)) == + 0) { fprintf(stderr, "CRNGT failed.\n"); BORINGSSL_FIPS_abort(); } - OPENSSL_STATIC_ASSERT(sizeof(entropy) % CRNGT_BLOCK_SIZE == 0, ""); - for (size_t i = CRNGT_BLOCK_SIZE; i < sizeof(entropy); - i += CRNGT_BLOCK_SIZE) { + assert(entropy_len % CRNGT_BLOCK_SIZE == 0); + for (size_t i = CRNGT_BLOCK_SIZE; i < entropy_len; i += CRNGT_BLOCK_SIZE) { if (CRYPTO_memcmp(entropy + i - CRNGT_BLOCK_SIZE, entropy + i, CRNGT_BLOCK_SIZE) == 0) { fprintf(stderr, "CRNGT failed.\n"); BORINGSSL_FIPS_abort(); } } - OPENSSL_memcpy(state->last_block, - entropy + sizeof(entropy) - CRNGT_BLOCK_SIZE, + OPENSSL_memcpy(state->last_block, entropy + entropy_len - CRNGT_BLOCK_SIZE, CRNGT_BLOCK_SIZE); + assert(entropy_len == BORINGSSL_FIPS_OVERREAD * CTR_DRBG_ENTROPY_LEN); OPENSSL_memcpy(seed, entropy, CTR_DRBG_ENTROPY_LEN); for (size_t i = 1; i < BORINGSSL_FIPS_OVERREAD; i++) { @@ -281,19 +297,30 @@ static void rand_get_seed(struct rand_thread_state *state, seed[j] ^= entropy[CTR_DRBG_ENTROPY_LEN * i + j]; } } + + // If we used something other than system entropy then also + // opportunistically read from the system. This avoids solely relying on the + // hardware once the entropy pool has been initialized. + *out_additional_input_len = 0; + if (want_additional_input && + CRYPTO_sysrand_if_available(additional_input, CTR_DRBG_ENTROPY_LEN)) { + *out_additional_input_len = CTR_DRBG_ENTROPY_LEN; + } } #else -// rand_get_seed fills |seed| with entropy and sets |*out_used_cpu| to one if -// that entropy came directly from the CPU and zero otherwise. +// rand_get_seed fills |seed| with entropy. In some cases, it will additionally +// fill |additional_input| with entropy to supplement |seed|. It sets +// |*out_additional_input_len| to the number of extra bytes. static void rand_get_seed(struct rand_thread_state *state, uint8_t seed[CTR_DRBG_ENTROPY_LEN], - int *out_used_cpu) { + uint8_t additional_input[CTR_DRBG_ENTROPY_LEN], + size_t *out_additional_input_len) { // If not in FIPS mode, we don't overread from the system entropy source and // we don't depend only on the hardware RDRAND. CRYPTO_sysrand_for_seed(seed, CTR_DRBG_ENTROPY_LEN); - *out_used_cpu = 0; + *out_additional_input_len = 0; } #endif @@ -352,20 +379,9 @@ void RAND_bytes_with_additional_data(uint8_t *out, size_t out_len, state->last_block_valid = 0; uint8_t seed[CTR_DRBG_ENTROPY_LEN]; - int used_cpu; - rand_get_seed(state, seed, &used_cpu); - uint8_t personalization[CTR_DRBG_ENTROPY_LEN] = {0}; size_t personalization_len = 0; -#if defined(OPENSSL_URANDOM) - // If we used RDRAND, also opportunistically read from the system. This - // avoids solely relying on the hardware once the entropy pool has been - // initialized. - if (used_cpu && - CRYPTO_sysrand_if_available(personalization, sizeof(personalization))) { - personalization_len = sizeof(personalization); - } -#endif + rand_get_seed(state, seed, personalization, &personalization_len); if (!CTR_DRBG_init(&state->drbg, seed, personalization, personalization_len)) { @@ -392,8 +408,10 @@ void RAND_bytes_with_additional_data(uint8_t *out, size_t out_len, if (state->calls >= kReseedInterval || state->fork_generation != fork_generation) { uint8_t seed[CTR_DRBG_ENTROPY_LEN]; - int used_cpu; - rand_get_seed(state, seed, &used_cpu); + uint8_t reseed_additional_data[CTR_DRBG_ENTROPY_LEN] = {0}; + size_t reseed_additional_data_len = 0; + rand_get_seed(state, seed, reseed_additional_data, + &reseed_additional_data_len); #if defined(BORINGSSL_FIPS) // Take a read lock around accesses to |state->drbg|. This is needed to // avoid returning bad entropy if we race with @@ -405,7 +423,8 @@ void RAND_bytes_with_additional_data(uint8_t *out, size_t out_len, // kernel, syscalls made with |syscall| did not abort the transaction. CRYPTO_STATIC_MUTEX_lock_read(state_clear_all_lock_bss_get()); #endif - if (!CTR_DRBG_reseed(&state->drbg, seed, NULL, 0)) { + if (!CTR_DRBG_reseed(&state->drbg, seed, reseed_additional_data, + reseed_additional_data_len)) { abort(); } state->calls = 0; @@ -454,3 +473,10 @@ int RAND_bytes(uint8_t *out, size_t out_len) { int RAND_pseudo_bytes(uint8_t *buf, size_t len) { return RAND_bytes(buf, len); } + +void RAND_get_system_entropy_for_custom_prng(uint8_t *buf, size_t len) { + if (len > 256) { + abort(); + } + CRYPTO_sysrand_for_seed(buf, len); +} diff --git a/Sources/CNIOBoringSSL/crypto/fipsmodule/rand/urandom.c b/Sources/CNIOBoringSSL/crypto/fipsmodule/rand/urandom.c index 3035ec96..60426dbb 100644 --- a/Sources/CNIOBoringSSL/crypto/fipsmodule/rand/urandom.c +++ b/Sources/CNIOBoringSSL/crypto/fipsmodule/rand/urandom.c @@ -62,14 +62,11 @@ #include #endif -#if defined(OPENSSL_FREEBSD) -#define URANDOM_BLOCKS_FOR_ENTROPY -#if __FreeBSD__ >= 12 +#if defined(OPENSSL_FREEBSD) && __FreeBSD__ >= 12 // getrandom is supported in FreeBSD 12 and up. #define FREEBSD_GETRANDOM #include #endif -#endif #include #include @@ -190,15 +187,21 @@ static void init_once(void) { return; #endif - // Android FIPS builds must support getrandom. -#if defined(BORINGSSL_FIPS) && defined(OPENSSL_ANDROID) + // FIPS builds must support getrandom. + // + // Historically, only Android FIPS builds required getrandom, while Linux FIPS + // builds had a /dev/urandom fallback which used RNDGETENTCNT as a poor + // approximation for getrandom's blocking behavior. This is now removed, but + // avoid making assumptions on this removal until March 2023, in case it needs + // to be restored. This comment can be deleted after March 2023. +#if defined(BORINGSSL_FIPS) perror("getrandom not found"); abort(); #endif int fd; do { - fd = open("/dev/urandom", O_RDONLY); + fd = open("/dev/urandom", O_RDONLY | O_CLOEXEC); } while (fd == -1 && errno == EINTR); if (fd < 0) { @@ -206,20 +209,6 @@ static void init_once(void) { abort(); } - int flags = fcntl(fd, F_GETFD); - if (flags == -1) { - // Native Client doesn't implement |fcntl|. - if (errno != ENOSYS) { - perror("failed to get flags from urandom fd"); - abort(); - } - } else { - flags |= FD_CLOEXEC; - if (fcntl(fd, F_SETFD, flags) == -1) { - perror("failed to set FD_CLOEXEC on urandom fd"); - abort(); - } - } *urandom_fd_bss_get() = fd; } @@ -269,29 +258,6 @@ static void wait_for_entropy(void) { #endif // USE_NR_getrandom return; } - -#if defined(BORINGSSL_FIPS) && !defined(URANDOM_BLOCKS_FOR_ENTROPY) - // In FIPS mode on platforms where urandom doesn't block at startup, we ensure - // that the kernel has sufficient entropy before continuing. This is - // automatically handled by getrandom, which requires that the entropy pool - // has been initialised, but for urandom we have to poll. - for (;;) { - int entropy_bits; - if (ioctl(fd, RNDGETENTCNT, &entropy_bits)) { - fprintf(stderr, - "RNDGETENTCNT on /dev/urandom failed. We cannot continue in this " - "case when in FIPS mode.\n"); - abort(); - } - - static const int kBitsNeeded = 256; - if (entropy_bits >= kBitsNeeded) { - break; - } - - usleep(250000); - } -#endif // BORINGSSL_FIPS && !URANDOM_BLOCKS_FOR_ENTROPY } // fill_with_entropy writes |len| bytes of entropy into |out|. It returns one diff --git a/Sources/CNIOBoringSSL/crypto/fipsmodule/rsa/padding.c b/Sources/CNIOBoringSSL/crypto/fipsmodule/rsa/padding.c index 445fcc27..dd38831d 100644 --- a/Sources/CNIOBoringSSL/crypto/fipsmodule/rsa/padding.c +++ b/Sources/CNIOBoringSSL/crypto/fipsmodule/rsa/padding.c @@ -489,29 +489,23 @@ static const uint8_t kPSSZeroes[] = {0, 0, 0, 0, 0, 0, 0, 0}; int RSA_verify_PKCS1_PSS_mgf1(const RSA *rsa, const uint8_t *mHash, const EVP_MD *Hash, const EVP_MD *mgf1Hash, const uint8_t *EM, int sLen) { - int i; - int ret = 0; - int maskedDBLen, MSBits, emLen; - size_t hLen; - const uint8_t *H; - uint8_t *DB = NULL; - EVP_MD_CTX ctx; - uint8_t H_[EVP_MAX_MD_SIZE]; - EVP_MD_CTX_init(&ctx); - if (mgf1Hash == NULL) { mgf1Hash = Hash; } - hLen = EVP_MD_size(Hash); + int ret = 0; + uint8_t *DB = NULL; + EVP_MD_CTX ctx; + EVP_MD_CTX_init(&ctx); FIPS_service_indicator_lock_state(); // Negative sLen has special meanings: // -1 sLen == hLen // -2 salt length is autorecovered from signature // -N reserved + size_t hLen = EVP_MD_size(Hash); if (sLen == -1) { - sLen = hLen; + sLen = (int)hLen; } else if (sLen == -2) { sLen = -2; } else if (sLen < -2) { @@ -519,8 +513,8 @@ int RSA_verify_PKCS1_PSS_mgf1(const RSA *rsa, const uint8_t *mHash, goto err; } - MSBits = (BN_num_bits(rsa->n) - 1) & 0x7; - emLen = RSA_size(rsa); + unsigned MSBits = (BN_num_bits(rsa->n) - 1) & 0x7; + size_t emLen = RSA_size(rsa); if (EM[0] & (0xFF << MSBits)) { OPENSSL_PUT_ERROR(RSA, RSA_R_FIRST_OCTET_INVALID); goto err; @@ -529,8 +523,9 @@ int RSA_verify_PKCS1_PSS_mgf1(const RSA *rsa, const uint8_t *mHash, EM++; emLen--; } - if (emLen < (int)hLen + 2 || emLen < ((int)hLen + sLen + 2)) { - // sLen can be small negative + // |sLen| may be -2 for the non-standard salt length recovery mode. + if (emLen < hLen + 2 || + (sLen >= 0 && emLen < hLen + (size_t)sLen + 2)) { OPENSSL_PUT_ERROR(RSA, RSA_R_DATA_TOO_LARGE); goto err; } @@ -538,8 +533,8 @@ int RSA_verify_PKCS1_PSS_mgf1(const RSA *rsa, const uint8_t *mHash, OPENSSL_PUT_ERROR(RSA, RSA_R_LAST_OCTET_INVALID); goto err; } - maskedDBLen = emLen - hLen - 1; - H = EM + maskedDBLen; + size_t maskedDBLen = emLen - hLen - 1; + const uint8_t *H = EM + maskedDBLen; DB = OPENSSL_malloc(maskedDBLen); if (!DB) { OPENSSL_PUT_ERROR(RSA, ERR_R_MALLOC_FAILURE); @@ -548,42 +543,49 @@ int RSA_verify_PKCS1_PSS_mgf1(const RSA *rsa, const uint8_t *mHash, if (!PKCS1_MGF1(DB, maskedDBLen, H, hLen, mgf1Hash)) { goto err; } - for (i = 0; i < maskedDBLen; i++) { + for (size_t i = 0; i < maskedDBLen; i++) { DB[i] ^= EM[i]; } if (MSBits) { DB[0] &= 0xFF >> (8 - MSBits); } - for (i = 0; DB[i] == 0 && i < (maskedDBLen - 1); i++) { + // This step differs slightly from EMSA-PSS-VERIFY (RFC 8017) step 10 because + // it accepts a non-standard salt recovery flow. DB should be some number of + // zeros, a one, then the salt. + size_t salt_start; + for (salt_start = 0; DB[salt_start] == 0 && salt_start < maskedDBLen - 1; + salt_start++) { ; } - if (DB[i++] != 0x1) { + if (DB[salt_start] != 0x1) { OPENSSL_PUT_ERROR(RSA, RSA_R_SLEN_RECOVERY_FAILED); goto err; } - if (sLen >= 0 && (maskedDBLen - i) != sLen) { + salt_start++; + // If a salt length was specified, check it matches. + if (sLen >= 0 && maskedDBLen - salt_start != (size_t)sLen) { OPENSSL_PUT_ERROR(RSA, RSA_R_SLEN_CHECK_FAILED); goto err; } + uint8_t H_[EVP_MAX_MD_SIZE]; if (!EVP_DigestInit_ex(&ctx, Hash, NULL) || !EVP_DigestUpdate(&ctx, kPSSZeroes, sizeof(kPSSZeroes)) || !EVP_DigestUpdate(&ctx, mHash, hLen) || - !EVP_DigestUpdate(&ctx, DB + i, maskedDBLen - i) || + !EVP_DigestUpdate(&ctx, DB + salt_start, maskedDBLen - salt_start) || !EVP_DigestFinal_ex(&ctx, H_, NULL)) { goto err; } - if (OPENSSL_memcmp(H_, H, hLen)) { + if (OPENSSL_memcmp(H_, H, hLen) != 0) { OPENSSL_PUT_ERROR(RSA, RSA_R_BAD_SIGNATURE); - ret = 0; - } else { - ret = 1; + goto err; } + ret = 1; + err: OPENSSL_free(DB); EVP_MD_CTX_cleanup(&ctx); FIPS_service_indicator_unlock_state(); - return ret; } diff --git a/Sources/CNIOBoringSSL/crypto/fipsmodule/rsa/rsa_impl.c b/Sources/CNIOBoringSSL/crypto/fipsmodule/rsa/rsa_impl.c index 98b5ce8c..19947ef5 100644 --- a/Sources/CNIOBoringSSL/crypto/fipsmodule/rsa/rsa_impl.c +++ b/Sources/CNIOBoringSSL/crypto/fipsmodule/rsa/rsa_impl.c @@ -64,7 +64,6 @@ #include #include #include -#include #include "../../internal.h" #include "../bn/internal.h" @@ -406,8 +405,8 @@ static BN_BLINDING *rsa_blinding_get(RSA *rsa, unsigned *index_used, } // Double the length of the cache. - OPENSSL_STATIC_ASSERT(MAX_BLINDINGS_PER_RSA < UINT_MAX / 2, - "MAX_BLINDINGS_PER_RSA too large"); + static_assert(MAX_BLINDINGS_PER_RSA < UINT_MAX / 2, + "MAX_BLINDINGS_PER_RSA too large"); unsigned new_num_blindings = rsa->num_blindings * 2; if (new_num_blindings == 0) { new_num_blindings = 1; @@ -417,9 +416,8 @@ static BN_BLINDING *rsa_blinding_get(RSA *rsa, unsigned *index_used, } assert(new_num_blindings > rsa->num_blindings); - OPENSSL_STATIC_ASSERT( - MAX_BLINDINGS_PER_RSA < UINT_MAX / sizeof(BN_BLINDING *), - "MAX_BLINDINGS_PER_RSA too large"); + static_assert(MAX_BLINDINGS_PER_RSA < UINT_MAX / sizeof(BN_BLINDING *), + "MAX_BLINDINGS_PER_RSA too large"); BN_BLINDING **new_blindings = OPENSSL_malloc(sizeof(BN_BLINDING *) * new_num_blindings); uint8_t *new_blindings_inuse = OPENSSL_malloc(new_num_blindings); diff --git a/Sources/CNIOBoringSSL/crypto/fipsmodule/self_check/self_check.c b/Sources/CNIOBoringSSL/crypto/fipsmodule/self_check/self_check.c index 6cfdbe31..e26bb121 100644 --- a/Sources/CNIOBoringSSL/crypto/fipsmodule/self_check/self_check.c +++ b/Sources/CNIOBoringSSL/crypto/fipsmodule/self_check/self_check.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include diff --git a/Sources/CNIOBoringSSL/crypto/fipsmodule/sha/sha256.c b/Sources/CNIOBoringSSL/crypto/fipsmodule/sha/sha256.c index 3f4de729..31e7f9ab 100644 --- a/Sources/CNIOBoringSSL/crypto/fipsmodule/sha/sha256.c +++ b/Sources/CNIOBoringSSL/crypto/fipsmodule/sha/sha256.c @@ -133,7 +133,7 @@ int SHA224_Update(SHA256_CTX *ctx, const void *data, size_t len) { return SHA256_Update(ctx, data, len); } -static int sha256_final_impl(uint8_t *out, SHA256_CTX *c) { +static int sha256_final_impl(uint8_t *out, size_t md_len, SHA256_CTX *c) { crypto_md32_final(&sha256_block_data_order, c->h, c->data, SHA256_CBLOCK, &c->num, c->Nh, c->Nl, /*is_big_endian=*/1); @@ -141,12 +141,12 @@ static int sha256_final_impl(uint8_t *out, SHA256_CTX *c) { // 'final' function can fail. SHA-512 does not have a corresponding check. // These functions already misbehave if the caller arbitrarily mutates |c|, so // can we assume one of |SHA256_Init| or |SHA224_Init| was used? - if (c->md_len > SHA256_DIGEST_LENGTH) { + if (md_len > SHA256_DIGEST_LENGTH) { return 0; } - assert(c->md_len % 4 == 0); - const size_t out_words = c->md_len / 4; + assert(md_len % 4 == 0); + const size_t out_words = md_len / 4; for (size_t i = 0; i < out_words; i++) { CRYPTO_store_u32_be(out, c->h[i]); out += 4; @@ -162,14 +162,14 @@ int SHA256_Final(uint8_t out[SHA256_DIGEST_LENGTH], SHA256_CTX *c) { // |SHA256_Final| and expects |sha->md_len| to carry the size over. // // TODO(davidben): Add an assert and fix code to match them up. - return sha256_final_impl(out, c); + return sha256_final_impl(out, c->md_len, c); } int SHA224_Final(uint8_t out[SHA224_DIGEST_LENGTH], SHA256_CTX *ctx) { - // SHA224_Init sets |ctx->md_len| to |SHA224_DIGEST_LENGTH|, so this has a - // smaller output. + // This function must be paired with |SHA224_Init|, which sets |ctx->md_len| + // to |SHA224_DIGEST_LENGTH|. assert(ctx->md_len == SHA224_DIGEST_LENGTH); - return sha256_final_impl(out, ctx); + return sha256_final_impl(out, SHA224_DIGEST_LENGTH, ctx); } #ifndef SHA256_ASM diff --git a/Sources/CNIOBoringSSL/crypto/fipsmodule/sha/sha512.c b/Sources/CNIOBoringSSL/crypto/fipsmodule/sha/sha512.c index c639f1f7..a42915df 100644 --- a/Sources/CNIOBoringSSL/crypto/fipsmodule/sha/sha512.c +++ b/Sources/CNIOBoringSSL/crypto/fipsmodule/sha/sha512.c @@ -71,7 +71,7 @@ // this writing, so there is no need for a common collector/padding // implementation yet. -static int sha512_final_impl(uint8_t *out, SHA512_CTX *sha); +static int sha512_final_impl(uint8_t *out, size_t md_len, SHA512_CTX *sha); int SHA384_Init(SHA512_CTX *sha) { sha->h[0] = UINT64_C(0xcbbb9d5dc1059ed8); @@ -162,10 +162,10 @@ static void sha512_block_data_order(uint64_t *state, const uint8_t *in, int SHA384_Final(uint8_t out[SHA384_DIGEST_LENGTH], SHA512_CTX *sha) { - // |SHA384_Init| sets |sha->md_len| to |SHA384_DIGEST_LENGTH|, so this has a - // smaller output. + // This function must be paired with |SHA384_Init|, which sets |sha->md_len| + // to |SHA384_DIGEST_LENGTH|. assert(sha->md_len == SHA384_DIGEST_LENGTH); - return sha512_final_impl(out, sha); + return sha512_final_impl(out, SHA384_DIGEST_LENGTH, sha); } int SHA384_Update(SHA512_CTX *sha, const void *data, size_t len) { @@ -177,10 +177,10 @@ int SHA512_256_Update(SHA512_CTX *sha, const void *data, size_t len) { } int SHA512_256_Final(uint8_t out[SHA512_256_DIGEST_LENGTH], SHA512_CTX *sha) { - // |SHA512_256_Init| sets |sha->md_len| to |SHA512_256_DIGEST_LENGTH|, so this - // has a |smaller output. + // This function must be paired with |SHA512_256_Init|, which sets + // |sha->md_len| to |SHA512_256_DIGEST_LENGTH|. assert(sha->md_len == SHA512_256_DIGEST_LENGTH); - return sha512_final_impl(out, sha); + return sha512_final_impl(out, SHA512_256_DIGEST_LENGTH, sha); } void SHA512_Transform(SHA512_CTX *c, const uint8_t block[SHA512_CBLOCK]) { @@ -241,10 +241,10 @@ int SHA512_Final(uint8_t out[SHA512_DIGEST_LENGTH], SHA512_CTX *sha) { // |SHA512_Final| and expects |sha->md_len| to carry the size over. // // TODO(davidben): Add an assert and fix code to match them up. - return sha512_final_impl(out, sha); + return sha512_final_impl(out, sha->md_len, sha); } -static int sha512_final_impl(uint8_t *out, SHA512_CTX *sha) { +static int sha512_final_impl(uint8_t *out, size_t md_len, SHA512_CTX *sha) { uint8_t *p = sha->p; size_t n = sha->num; @@ -268,8 +268,8 @@ static int sha512_final_impl(uint8_t *out, SHA512_CTX *sha) { return 0; } - assert(sha->md_len % 8 == 0); - const size_t out_words = sha->md_len / 8; + assert(md_len % 8 == 0); + const size_t out_words = md_len / 8; for (size_t i = 0; i < out_words; i++) { CRYPTO_store_u64_be(out, sha->h[i]); out += 8; diff --git a/Sources/CNIOBoringSSL/crypto/hpke/hpke.c b/Sources/CNIOBoringSSL/crypto/hpke/hpke.c index a0eec3ae..ef7e2ac2 100644 --- a/Sources/CNIOBoringSSL/crypto/hpke/hpke.c +++ b/Sources/CNIOBoringSSL/crypto/hpke/hpke.c @@ -40,6 +40,7 @@ struct evp_hpke_kem_st { size_t public_key_len; size_t private_key_len; size_t seed_len; + size_t enc_len; int (*init_key)(EVP_HPKE_KEY *key, const uint8_t *priv_key, size_t priv_key_len); int (*generate_key)(EVP_HPKE_KEY *key); @@ -216,6 +217,7 @@ const EVP_HPKE_KEM *EVP_hpke_x25519_hkdf_sha256(void) { /*public_key_len=*/X25519_PUBLIC_VALUE_LEN, /*private_key_len=*/X25519_PRIVATE_KEY_LEN, /*seed_len=*/X25519_PRIVATE_KEY_LEN, + /*enc_len=*/X25519_PUBLIC_VALUE_LEN, x25519_init_key, x25519_generate_key, x25519_encap_with_seed, @@ -226,6 +228,8 @@ const EVP_HPKE_KEM *EVP_hpke_x25519_hkdf_sha256(void) { uint16_t EVP_HPKE_KEM_id(const EVP_HPKE_KEM *kem) { return kem->id; } +size_t EVP_HPKE_KEM_enc_len(const EVP_HPKE_KEM *kem) { return kem->enc_len; } + void EVP_HPKE_KEY_zero(EVP_HPKE_KEY *key) { OPENSSL_memset(key, 0, sizeof(EVP_HPKE_KEY)); } @@ -315,6 +319,10 @@ const EVP_HPKE_KDF *EVP_hpke_hkdf_sha256(void) { uint16_t EVP_HPKE_KDF_id(const EVP_HPKE_KDF *kdf) { return kdf->id; } +const EVP_MD *EVP_HPKE_KDF_hkdf_md(const EVP_HPKE_KDF *kdf) { + return kdf->hkdf_md_func(); +} + const EVP_HPKE_AEAD *EVP_hpke_aes_128_gcm(void) { static const EVP_HPKE_AEAD kAEAD = {EVP_HPKE_AES_128_GCM, &EVP_aead_aes_128_gcm}; @@ -351,9 +359,9 @@ static int hpke_build_suite_id(const EVP_HPKE_CTX *ctx, uint8_t out[HPKE_SUITE_ID_LEN]) { CBB cbb; int ret = CBB_init_fixed(&cbb, out, HPKE_SUITE_ID_LEN) && - add_label_string(&cbb, "HPKE") && - CBB_add_u16(&cbb, EVP_HPKE_DHKEM_X25519_HKDF_SHA256) && - CBB_add_u16(&cbb, ctx->kdf->id) && + add_label_string(&cbb, "HPKE") && // + CBB_add_u16(&cbb, ctx->kem->id) && // + CBB_add_u16(&cbb, ctx->kdf->id) && // CBB_add_u16(&cbb, ctx->aead->id); CBB_cleanup(&cbb); return ret; @@ -487,6 +495,7 @@ int EVP_HPKE_CTX_setup_sender_with_seed_for_testing( size_t seed_len) { EVP_HPKE_CTX_zero(ctx); ctx->is_sender = 1; + ctx->kem = kem; ctx->kdf = kdf; ctx->aead = aead; uint8_t shared_secret[MAX_SHARED_SECRET_LEN]; @@ -509,12 +518,13 @@ int EVP_HPKE_CTX_setup_recipient(EVP_HPKE_CTX *ctx, const EVP_HPKE_KEY *key, size_t info_len) { EVP_HPKE_CTX_zero(ctx); ctx->is_sender = 0; + ctx->kem = key->kem; ctx->kdf = kdf; ctx->aead = aead; uint8_t shared_secret[MAX_SHARED_SECRET_LEN]; size_t shared_secret_len; if (!key->kem->decap(key, shared_secret, &shared_secret_len, enc, enc_len) || - !hpke_key_schedule(ctx, shared_secret, sizeof(shared_secret), info, + !hpke_key_schedule(ctx, shared_secret, shared_secret_len, info, info_len)) { EVP_HPKE_CTX_cleanup(ctx); return 0; @@ -609,6 +619,10 @@ size_t EVP_HPKE_CTX_max_overhead(const EVP_HPKE_CTX *ctx) { return EVP_AEAD_max_overhead(EVP_AEAD_CTX_aead(&ctx->aead_ctx)); } +const EVP_HPKE_KEM *EVP_HPKE_CTX_kem(const EVP_HPKE_CTX *ctx) { + return ctx->kem; +} + const EVP_HPKE_AEAD *EVP_HPKE_CTX_aead(const EVP_HPKE_CTX *ctx) { return ctx->aead; } diff --git a/Sources/CNIOBoringSSL/crypto/hrss/hrss.c b/Sources/CNIOBoringSSL/crypto/hrss/hrss.c index 2f8de3a5..c99d9046 100644 --- a/Sources/CNIOBoringSSL/crypto/hrss/hrss.c +++ b/Sources/CNIOBoringSSL/crypto/hrss/hrss.c @@ -1227,10 +1227,10 @@ static void poly_mul_vec_aux(vec_t *restrict out, vec_t *restrict scratch, // poly_mul_vec sets |*out| to |x|×|y| mod (𝑥^n - 1). static void poly_mul_vec(struct POLY_MUL_SCRATCH *scratch, struct poly *out, const struct poly *x, const struct poly *y) { - OPENSSL_STATIC_ASSERT(sizeof(out->v) == sizeof(vec_t) * VECS_PER_POLY, - "struct poly is the wrong size"); - OPENSSL_STATIC_ASSERT(alignof(struct poly) == alignof(vec_t), - "struct poly has incorrect alignment"); + static_assert(sizeof(out->v) == sizeof(vec_t) * VECS_PER_POLY, + "struct poly is the wrong size"); + static_assert(alignof(struct poly) == alignof(vec_t), + "struct poly has incorrect alignment"); poly_assert_normalized(x); poly_assert_normalized(y); @@ -1752,8 +1752,7 @@ static void poly_marshal_mod3(uint8_t out[HRSS_POLY3_BYTES], // function uses that freedom to implement a flatter distribution of values. static void poly_short_sample(struct poly *out, const uint8_t in[HRSS_SAMPLE_BYTES]) { - OPENSSL_STATIC_ASSERT(HRSS_SAMPLE_BYTES == N - 1, - "HRSS_SAMPLE_BYTES incorrect"); + static_assert(HRSS_SAMPLE_BYTES == N - 1, "HRSS_SAMPLE_BYTES incorrect"); for (size_t i = 0; i < N - 1; i++) { uint16_t v = mod3(in[i]); // Map {0, 1, 2} -> {0, 1, 0xffff} @@ -1922,7 +1921,7 @@ struct private_key { // that up.) static struct public_key *public_key_from_external( struct HRSS_public_key *ext) { - OPENSSL_STATIC_ASSERT( + static_assert( sizeof(struct HRSS_public_key) >= sizeof(struct public_key) + 15, "HRSS public key too small"); @@ -1934,7 +1933,7 @@ static struct public_key *public_key_from_external( // issues. static struct private_key *private_key_from_external( struct HRSS_private_key *ext) { - OPENSSL_STATIC_ASSERT( + static_assert( sizeof(struct HRSS_private_key) >= sizeof(struct private_key) + 15, "HRSS private key too small"); @@ -2111,8 +2110,8 @@ int HRSS_decap(uint8_t out_shared_key[HRSS_KEY_BYTES], // This is HMAC, expanded inline rather than using the |HMAC| function so that // we can avoid dealing with possible allocation failures and so keep this // function infallible. - OPENSSL_STATIC_ASSERT(sizeof(priv->hmac_key) <= sizeof(vars->masked_key), - "HRSS HMAC key larger than SHA-256 block size"); + static_assert(sizeof(priv->hmac_key) <= sizeof(vars->masked_key), + "HRSS HMAC key larger than SHA-256 block size"); for (size_t i = 0; i < sizeof(priv->hmac_key); i++) { vars->masked_key[i] = priv->hmac_key[i] ^ 0x36; } @@ -2134,8 +2133,8 @@ int HRSS_decap(uint8_t out_shared_key[HRSS_KEY_BYTES], SHA256_Init(&vars->hash_ctx); SHA256_Update(&vars->hash_ctx, vars->masked_key, sizeof(vars->masked_key)); SHA256_Update(&vars->hash_ctx, inner_digest, sizeof(inner_digest)); - OPENSSL_STATIC_ASSERT(HRSS_KEY_BYTES == SHA256_DIGEST_LENGTH, - "HRSS shared key length incorrect"); + static_assert(HRSS_KEY_BYTES == SHA256_DIGEST_LENGTH, + "HRSS shared key length incorrect"); SHA256_Final(out_shared_key, &vars->hash_ctx); // If the ciphertext is publicly invalid then a random shared key is still @@ -2188,8 +2187,8 @@ int HRSS_decap(uint8_t out_shared_key[HRSS_KEY_BYTES], // The |poly_marshal| here then is just confirming that |poly_unmarshal| is // strict and could be omitted. - OPENSSL_STATIC_ASSERT(HRSS_CIPHERTEXT_BYTES == POLY_BYTES, - "ciphertext is the wrong size"); + static_assert(HRSS_CIPHERTEXT_BYTES == POLY_BYTES, + "ciphertext is the wrong size"); assert(ciphertext_len == sizeof(vars->expected_ciphertext)); poly_marshal(vars->expected_ciphertext, &vars->c); diff --git a/Sources/CNIOBoringSSL/crypto/mem.c b/Sources/CNIOBoringSSL/crypto/mem.c index b7e51a88..cb63de8b 100644 --- a/Sources/CNIOBoringSSL/crypto/mem.c +++ b/Sources/CNIOBoringSSL/crypto/mem.c @@ -72,8 +72,7 @@ OPENSSL_MSVC_PRAGMA(warning(pop)) #define OPENSSL_MALLOC_PREFIX 8 -OPENSSL_STATIC_ASSERT(OPENSSL_MALLOC_PREFIX >= sizeof(size_t), - "size_t too large"); +static_assert(OPENSSL_MALLOC_PREFIX >= sizeof(size_t), "size_t too large"); #if defined(OPENSSL_ASAN) void __asan_poison_memory_region(const volatile void *addr, size_t size); @@ -183,6 +182,7 @@ void OPENSSL_free(void *orig_ptr) { // ASan knows to intercept malloc and free, but not sdallocx. #if defined(OPENSSL_ASAN) + (void)sdallocx; free(ptr); #else if (sdallocx) { diff --git a/Sources/CNIOBoringSSL/crypto/pem/pem_info.c b/Sources/CNIOBoringSSL/crypto/pem/pem_info.c index 4999cbc1..1e4ae964 100644 --- a/Sources/CNIOBoringSSL/crypto/pem/pem_info.c +++ b/Sources/CNIOBoringSSL/crypto/pem/pem_info.c @@ -263,84 +263,3 @@ err: OPENSSL_free(data); return ret; } - -// A TJH addition -int PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi, EVP_CIPHER *enc, - unsigned char *kstr, int klen, pem_password_cb *cb, - void *u) { - int i, ret = 0; - unsigned char *data = NULL; - const char *objstr = NULL; - char buf[PEM_BUFSIZE]; - unsigned char *iv = NULL; - unsigned iv_len = 0; - - if (enc != NULL) { - iv_len = EVP_CIPHER_iv_length(enc); - objstr = OBJ_nid2sn(EVP_CIPHER_nid(enc)); - if (objstr == NULL) { - OPENSSL_PUT_ERROR(PEM, PEM_R_UNSUPPORTED_CIPHER); - goto err; - } - } - - // now for the fun part ... if we have a private key then we have to be - // able to handle a not-yet-decrypted key being written out correctly ... - // if it is decrypted or it is non-encrypted then we use the base code - if (xi->x_pkey != NULL) { - if ((xi->enc_data != NULL) && (xi->enc_len > 0)) { - if (enc == NULL) { - OPENSSL_PUT_ERROR(PEM, PEM_R_CIPHER_IS_NULL); - goto err; - } - - // copy from weirdo names into more normal things - iv = xi->enc_cipher.iv; - data = (unsigned char *)xi->enc_data; - i = xi->enc_len; - - // we take the encryption data from the internal stuff rather - // than what the user has passed us ... as we have to match - // exactly for some strange reason - objstr = OBJ_nid2sn(EVP_CIPHER_nid(xi->enc_cipher.cipher)); - if (objstr == NULL) { - OPENSSL_PUT_ERROR(PEM, PEM_R_UNSUPPORTED_CIPHER); - goto err; - } - - // create the right magic header stuff - assert(strlen(objstr) + 23 + 2 * iv_len + 13 <= sizeof buf); - buf[0] = '\0'; - PEM_proc_type(buf, PEM_TYPE_ENCRYPTED); - PEM_dek_info(buf, objstr, iv_len, (char *)iv); - - // use the normal code to write things out - i = PEM_write_bio(bp, PEM_STRING_RSA, buf, data, i); - if (i <= 0) { - goto err; - } - } else { - // Add DSA/DH - // normal optionally encrypted stuff - if (PEM_write_bio_RSAPrivateKey(bp, xi->x_pkey->dec_pkey->pkey.rsa, enc, - kstr, klen, cb, u) <= 0) { - goto err; - } - } - } - - // if we have a certificate then write it out now - if ((xi->x509 != NULL) && (PEM_write_bio_X509(bp, xi->x509) <= 0)) { - goto err; - } - - // we are ignoring anything else that is loaded into the X509_INFO - // structure for the moment ... as I don't need it so I'm not coding it - // here and Eric can do it when this makes it into the base library --tjh - - ret = 1; - -err: - OPENSSL_cleanse(buf, PEM_BUFSIZE); - return ret; -} diff --git a/Sources/CNIOBoringSSL/crypto/pkcs8/pkcs8_x509.c b/Sources/CNIOBoringSSL/crypto/pkcs8/pkcs8_x509.c index aef8e404..433dfa6d 100644 --- a/Sources/CNIOBoringSSL/crypto/pkcs8/pkcs8_x509.c +++ b/Sources/CNIOBoringSSL/crypto/pkcs8/pkcs8_x509.c @@ -90,62 +90,16 @@ int pkcs12_iterations_acceptable(uint64_t iterations) { return 0 < iterations && iterations <= kIterationsLimit; } -// Minor tweak to operation: zero private key data -static int pkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, - void *exarg) { - // Since the structure must still be valid use ASN1_OP_FREE_PRE - if (operation == ASN1_OP_FREE_PRE) { - PKCS8_PRIV_KEY_INFO *key = (PKCS8_PRIV_KEY_INFO *)*pval; - if (key->pkey) { - OPENSSL_cleanse(key->pkey->data, key->pkey->length); - } - } - return 1; -} - -ASN1_SEQUENCE_cb(PKCS8_PRIV_KEY_INFO, pkey_cb) = { +ASN1_SEQUENCE(PKCS8_PRIV_KEY_INFO) = { ASN1_SIMPLE(PKCS8_PRIV_KEY_INFO, version, ASN1_INTEGER), ASN1_SIMPLE(PKCS8_PRIV_KEY_INFO, pkeyalg, X509_ALGOR), ASN1_SIMPLE(PKCS8_PRIV_KEY_INFO, pkey, ASN1_OCTET_STRING), ASN1_IMP_SET_OF_OPT(PKCS8_PRIV_KEY_INFO, attributes, X509_ATTRIBUTE, 0), -} ASN1_SEQUENCE_END_cb(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO) +} ASN1_SEQUENCE_END(PKCS8_PRIV_KEY_INFO) -IMPLEMENT_ASN1_FUNCTIONS(PKCS8_PRIV_KEY_INFO) +IMPLEMENT_ASN1_FUNCTIONS_const(PKCS8_PRIV_KEY_INFO) -int PKCS8_pkey_set0(PKCS8_PRIV_KEY_INFO *priv, ASN1_OBJECT *aobj, int version, - int ptype, void *pval, uint8_t *penc, int penclen) { - if (version >= 0 && - !ASN1_INTEGER_set(priv->version, version)) { - return 0; - } - - if (!X509_ALGOR_set0(priv->pkeyalg, aobj, ptype, pval)) { - return 0; - } - - if (penc != NULL) { - ASN1_STRING_set0(priv->pkey, penc, penclen); - } - - return 1; -} - -int PKCS8_pkey_get0(ASN1_OBJECT **ppkalg, const uint8_t **pk, int *ppklen, - X509_ALGOR **pa, PKCS8_PRIV_KEY_INFO *p8) { - if (ppkalg) { - *ppkalg = p8->pkeyalg->algorithm; - } - if (pk) { - *pk = ASN1_STRING_data(p8->pkey); - *ppklen = ASN1_STRING_length(p8->pkey); - } - if (pa) { - *pa = p8->pkeyalg; - } - return 1; -} - -EVP_PKEY *EVP_PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8) { +EVP_PKEY *EVP_PKCS82PKEY(const PKCS8_PRIV_KEY_INFO *p8) { uint8_t *der = NULL; int der_len = i2d_PKCS8_PRIV_KEY_INFO(p8, &der); if (der_len < 0) { @@ -166,7 +120,7 @@ EVP_PKEY *EVP_PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8) { return ret; } -PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey) { +PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(const EVP_PKEY *pkey) { CBB cbb; uint8_t *der = NULL; size_t der_len; diff --git a/Sources/CNIOBoringSSL/crypto/poly1305/poly1305.c b/Sources/CNIOBoringSSL/crypto/poly1305/poly1305.c index fd8a83b4..35f043cd 100644 --- a/Sources/CNIOBoringSSL/crypto/poly1305/poly1305.c +++ b/Sources/CNIOBoringSSL/crypto/poly1305/poly1305.c @@ -18,6 +18,7 @@ #include +#include #include #include "internal.h" @@ -48,7 +49,7 @@ struct poly1305_state_st { uint8_t key[16]; }; -OPENSSL_STATIC_ASSERT( +static_assert( sizeof(struct poly1305_state_st) + 63 <= sizeof(poly1305_state), "poly1305_state isn't large enough to hold aligned poly1305_state_st"); diff --git a/Sources/CNIOBoringSSL/crypto/poly1305/poly1305_arm.c b/Sources/CNIOBoringSSL/crypto/poly1305/poly1305_arm.c index a74a9ad3..a6cb71c0 100644 --- a/Sources/CNIOBoringSSL/crypto/poly1305/poly1305_arm.c +++ b/Sources/CNIOBoringSSL/crypto/poly1305/poly1305_arm.c @@ -17,6 +17,7 @@ #include +#include #include #include "../internal.h" @@ -183,7 +184,7 @@ struct poly1305_state_st { uint8_t key[16]; }; -OPENSSL_STATIC_ASSERT( +static_assert( sizeof(struct poly1305_state_st) + 63 <= sizeof(poly1305_state), "poly1305_state isn't large enough to hold aligned poly1305_state_st."); diff --git a/Sources/CNIOBoringSSL/crypto/poly1305/poly1305_vec.c b/Sources/CNIOBoringSSL/crypto/poly1305/poly1305_vec.c index 1fbad14b..62c082bd 100644 --- a/Sources/CNIOBoringSSL/crypto/poly1305/poly1305_vec.c +++ b/Sources/CNIOBoringSSL/crypto/poly1305/poly1305_vec.c @@ -20,6 +20,8 @@ #include +#include + #include "../internal.h" @@ -76,9 +78,10 @@ typedef struct poly1305_state_internal_t { } poly1305_state_internal; /* 448 bytes total + 63 bytes for alignment = 511 bytes raw */ -OPENSSL_STATIC_ASSERT( - sizeof(struct poly1305_state_internal_t) + 63 <= sizeof(poly1305_state), - "poly1305_state isn't large enough to hold aligned poly1305_state_internal_t"); +static_assert(sizeof(struct poly1305_state_internal_t) + 63 <= + sizeof(poly1305_state), + "poly1305_state isn't large enough to hold aligned " + "poly1305_state_internal_t"); static inline poly1305_state_internal *poly1305_aligned_state( poly1305_state *state) { diff --git a/Sources/CNIOBoringSSL/crypto/rand_extra/passive.c b/Sources/CNIOBoringSSL/crypto/rand_extra/passive.c index 9199e200..e1ce9293 100644 --- a/Sources/CNIOBoringSSL/crypto/rand_extra/passive.c +++ b/Sources/CNIOBoringSSL/crypto/rand_extra/passive.c @@ -12,7 +12,8 @@ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include +#include + #include "../fipsmodule/rand/internal.h" #if defined(BORINGSSL_FIPS) @@ -20,15 +21,16 @@ // RAND_need_entropy is called by the FIPS module when it has blocked because of // a lack of entropy. This signal is used as an indication to feed it more. void RAND_need_entropy(size_t bytes_needed) { - uint8_t buf[CTR_DRBG_ENTROPY_LEN * BORINGSSL_FIPS_OVERREAD]; + uint8_t buf[/* last_block size */ 16 + + CTR_DRBG_ENTROPY_LEN * BORINGSSL_FIPS_OVERREAD]; size_t todo = sizeof(buf); if (todo > bytes_needed) { todo = bytes_needed; } - int used_cpu; - CRYPTO_get_seed_entropy(buf, todo, &used_cpu); - RAND_load_entropy(buf, todo, used_cpu); + int want_additional_input; + CRYPTO_get_seed_entropy(buf, todo, &want_additional_input); + RAND_load_entropy(buf, todo, want_additional_input); } #endif // FIPS diff --git a/Sources/CNIOBoringSSL/crypto/refcount_c11.c b/Sources/CNIOBoringSSL/crypto/refcount_c11.c index 2ca5269d..a1781c66 100644 --- a/Sources/CNIOBoringSSL/crypto/refcount_c11.c +++ b/Sources/CNIOBoringSSL/crypto/refcount_c11.c @@ -22,8 +22,6 @@ #include #include -#include - // See comment above the typedef of CRYPTO_refcount_t about these tests. static_assert(alignof(CRYPTO_refcount_t) == alignof(_Atomic CRYPTO_refcount_t), diff --git a/Sources/CNIOBoringSSL/crypto/refcount_lock.c b/Sources/CNIOBoringSSL/crypto/refcount_lock.c index 8888d035..173267e3 100644 --- a/Sources/CNIOBoringSSL/crypto/refcount_lock.c +++ b/Sources/CNIOBoringSSL/crypto/refcount_lock.c @@ -14,15 +14,14 @@ #include "internal.h" +#include #include -#include - #if !defined(OPENSSL_C11_ATOMIC) -OPENSSL_STATIC_ASSERT((CRYPTO_refcount_t)-1 == CRYPTO_REFCOUNT_MAX, - "CRYPTO_REFCOUNT_MAX is incorrect"); +static_assert((CRYPTO_refcount_t)-1 == CRYPTO_REFCOUNT_MAX, + "CRYPTO_REFCOUNT_MAX is incorrect"); static struct CRYPTO_STATIC_MUTEX g_refcount_lock = CRYPTO_STATIC_MUTEX_INIT; diff --git a/Sources/CNIOBoringSSL/crypto/stack/stack.c b/Sources/CNIOBoringSSL/crypto/stack/stack.c index 061b8f93..89887a69 100644 --- a/Sources/CNIOBoringSSL/crypto/stack/stack.c +++ b/Sources/CNIOBoringSSL/crypto/stack/stack.c @@ -67,7 +67,7 @@ // stack. static const size_t kMinSize = 4; -_STACK *sk_new(stack_cmp_func comp) { +_STACK *sk_new(OPENSSL_sk_cmp_func comp) { _STACK *ret = OPENSSL_malloc(sizeof(_STACK)); if (ret == NULL) { return NULL; @@ -131,8 +131,8 @@ void sk_free(_STACK *sk) { OPENSSL_free(sk); } -void sk_pop_free_ex(_STACK *sk, stack_call_free_func call_free_func, - stack_free_func free_func) { +void sk_pop_free_ex(_STACK *sk, OPENSSL_sk_call_free_func call_free_func, + OPENSSL_sk_free_func free_func) { if (sk == NULL) { return; } @@ -145,14 +145,14 @@ void sk_pop_free_ex(_STACK *sk, stack_call_free_func call_free_func, sk_free(sk); } -// Historically, |sk_pop_free| called the function as |stack_free_func| +// Historically, |sk_pop_free| called the function as |OPENSSL_sk_free_func| // directly. This is undefined in C. Some callers called |sk_pop_free| directly, // so we must maintain a compatibility version for now. -static void call_free_func_legacy(stack_free_func func, void *ptr) { +static void call_free_func_legacy(OPENSSL_sk_free_func func, void *ptr) { func(ptr); } -void sk_pop_free(_STACK *sk, stack_free_func free_func) { +void sk_pop_free(_STACK *sk, OPENSSL_sk_free_func free_func) { sk_pop_free_ex(sk, call_free_func_legacy, free_func); } @@ -234,7 +234,7 @@ void *sk_delete_ptr(_STACK *sk, const void *p) { } int sk_find(const _STACK *sk, size_t *out_index, const void *p, - stack_call_cmp_func call_cmp_func) { + OPENSSL_sk_call_cmp_func call_cmp_func) { if (sk == NULL) { return 0; } @@ -356,8 +356,8 @@ err: #if defined(_MSC_VER) struct sort_compare_ctx { - stack_call_cmp_func call_cmp_func; - stack_cmp_func cmp_func; + OPENSSL_sk_call_cmp_func call_cmp_func; + OPENSSL_sk_cmp_func cmp_func; }; static int sort_compare(void *ctx_v, const void *a, const void *b) { @@ -366,7 +366,7 @@ static int sort_compare(void *ctx_v, const void *a, const void *b) { } #endif -void sk_sort(_STACK *sk, stack_call_cmp_func call_cmp_func) { +void sk_sort(_STACK *sk, OPENSSL_sk_call_cmp_func call_cmp_func) { if (sk == NULL || sk->comp == NULL || sk->sorted) { return; } @@ -402,8 +402,8 @@ int sk_is_sorted(const _STACK *sk) { return sk->sorted; } -stack_cmp_func sk_set_cmp_func(_STACK *sk, stack_cmp_func comp) { - stack_cmp_func old = sk->comp; +OPENSSL_sk_cmp_func sk_set_cmp_func(_STACK *sk, OPENSSL_sk_cmp_func comp) { + OPENSSL_sk_cmp_func old = sk->comp; if (sk->comp != comp) { sk->sorted = 0; @@ -413,10 +413,10 @@ stack_cmp_func sk_set_cmp_func(_STACK *sk, stack_cmp_func comp) { return old; } -_STACK *sk_deep_copy(const _STACK *sk, stack_call_copy_func call_copy_func, - stack_copy_func copy_func, - stack_call_free_func call_free_func, - stack_free_func free_func) { +_STACK *sk_deep_copy(const _STACK *sk, OPENSSL_sk_call_copy_func call_copy_func, + OPENSSL_sk_copy_func copy_func, + OPENSSL_sk_call_free_func call_free_func, + OPENSSL_sk_free_func free_func) { _STACK *ret = sk_dup(sk); if (ret == NULL) { return NULL; diff --git a/Sources/CNIOBoringSSL/crypto/thread_pthread.c b/Sources/CNIOBoringSSL/crypto/thread_pthread.c index 41182ee9..8bba3673 100644 --- a/Sources/CNIOBoringSSL/crypto/thread_pthread.c +++ b/Sources/CNIOBoringSSL/crypto/thread_pthread.c @@ -16,18 +16,18 @@ #if defined(OPENSSL_PTHREADS) +#include #include #include #include #include -#include -OPENSSL_STATIC_ASSERT(sizeof(CRYPTO_MUTEX) >= sizeof(pthread_rwlock_t), - "CRYPTO_MUTEX is too small"); -OPENSSL_STATIC_ASSERT(alignof(CRYPTO_MUTEX) >= alignof(pthread_rwlock_t), - "CRYPTO_MUTEX has insufficient alignment"); +static_assert(sizeof(CRYPTO_MUTEX) >= sizeof(pthread_rwlock_t), + "CRYPTO_MUTEX is too small"); +static_assert(alignof(CRYPTO_MUTEX) >= alignof(pthread_rwlock_t), + "CRYPTO_MUTEX has insufficient alignment"); void CRYPTO_MUTEX_init(CRYPTO_MUTEX *lock) { if (pthread_rwlock_init((pthread_rwlock_t *) lock, NULL) != 0) { diff --git a/Sources/CNIOBoringSSL/crypto/thread_win.c b/Sources/CNIOBoringSSL/crypto/thread_win.c index 35b3e848..dc874409 100644 --- a/Sources/CNIOBoringSSL/crypto/thread_win.c +++ b/Sources/CNIOBoringSSL/crypto/thread_win.c @@ -20,17 +20,17 @@ OPENSSL_MSVC_PRAGMA(warning(push, 3)) #include OPENSSL_MSVC_PRAGMA(warning(pop)) +#include #include #include #include -#include -OPENSSL_STATIC_ASSERT(sizeof(CRYPTO_MUTEX) >= sizeof(SRWLOCK), - "CRYPTO_MUTEX is too small"); -OPENSSL_STATIC_ASSERT(alignof(CRYPTO_MUTEX) >= alignof(SRWLOCK), - "CRYPTO_MUTEX has insufficient alignment"); +static_assert(sizeof(CRYPTO_MUTEX) >= sizeof(SRWLOCK), + "CRYPTO_MUTEX is too small"); +static_assert(alignof(CRYPTO_MUTEX) >= alignof(SRWLOCK), + "CRYPTO_MUTEX has insufficient alignment"); static BOOL CALLBACK call_once_init(INIT_ONCE *once, void *arg, void **out) { void (**init)(void) = (void (**)(void))arg; diff --git a/Sources/CNIOBoringSSL/crypto/x509/internal.h b/Sources/CNIOBoringSSL/crypto/x509/internal.h index 4cf095cf..f9a34c0f 100644 --- a/Sources/CNIOBoringSSL/crypto/x509/internal.h +++ b/Sources/CNIOBoringSSL/crypto/x509/internal.h @@ -72,12 +72,15 @@ extern "C" { // Internal structures. +typedef struct X509_POLICY_CACHE_st X509_POLICY_CACHE; +typedef struct X509_POLICY_TREE_st X509_POLICY_TREE; + typedef struct X509_val_st { ASN1_TIME *notBefore; ASN1_TIME *notAfter; } X509_VAL; -DECLARE_ASN1_FUNCTIONS(X509_VAL) +DECLARE_ASN1_FUNCTIONS_const(X509_VAL) struct X509_pubkey_st { X509_ALGOR *algor; @@ -113,7 +116,7 @@ typedef struct x509_cert_aux_st { ASN1_OCTET_STRING *keyid; // key id of private key } X509_CERT_AUX; -DECLARE_ASN1_FUNCTIONS(X509_CERT_AUX) +DECLARE_ASN1_FUNCTIONS_const(X509_CERT_AUX) struct X509_extension_st { ASN1_OBJECT *object; @@ -135,6 +138,8 @@ typedef struct { ASN1_ENCODING enc; } X509_CINF; +// TODO(https://crbug.com/boringssl/407): This is not const because it contains +// an |X509_NAME|. DECLARE_ASN1_FUNCTIONS(X509_CINF) struct x509_st { @@ -171,13 +176,14 @@ typedef struct { STACK_OF(X509_ATTRIBUTE) *attributes; // [ 0 ] } X509_REQ_INFO; +// TODO(https://crbug.com/boringssl/407): This is not const because it contains +// an |X509_NAME|. DECLARE_ASN1_FUNCTIONS(X509_REQ_INFO) struct X509_req_st { X509_REQ_INFO *req_info; X509_ALGOR *sig_alg; ASN1_BIT_STRING *signature; - CRYPTO_refcount_t references; } /* X509_REQ */; struct x509_revoked_st { @@ -201,6 +207,8 @@ typedef struct { ASN1_ENCODING enc; } X509_CRL_INFO; +// TODO(https://crbug.com/boringssl/407): This is not const because it contains +// an |X509_NAME|. DECLARE_ASN1_FUNCTIONS(X509_CRL_INFO) struct X509_crl_st { diff --git a/Sources/CNIOBoringSSL/crypto/x509/name_print.c b/Sources/CNIOBoringSSL/crypto/x509/name_print.c index 25609a30..ae0d4599 100644 --- a/Sources/CNIOBoringSSL/crypto/x509/name_print.c +++ b/Sources/CNIOBoringSSL/crypto/x509/name_print.c @@ -86,9 +86,6 @@ static int do_name_ex(BIO *out, const X509_NAME *n, int indent, unsigned long flags) { int i, prev = -1, orflags, cnt; int fn_opt, fn_nid; - ASN1_OBJECT *fn; - ASN1_STRING *val; - X509_NAME_ENTRY *ent; char objtmp[80]; const char *objbuf; int outlen, len; @@ -149,6 +146,7 @@ static int do_name_ex(BIO *out, const X509_NAME *n, int indent, cnt = X509_NAME_entry_count(n); for (i = 0; i < cnt; i++) { + const X509_NAME_ENTRY *ent; if (flags & XN_FLAG_DN_REV) { ent = X509_NAME_get_entry(n, cnt - i - 1); } else { @@ -172,8 +170,8 @@ static int do_name_ex(BIO *out, const X509_NAME *n, int indent, } } prev = X509_NAME_ENTRY_set(ent); - fn = X509_NAME_ENTRY_get_object(ent); - val = X509_NAME_ENTRY_get_data(ent); + const ASN1_OBJECT *fn = X509_NAME_ENTRY_get_object(ent); + const ASN1_STRING *val = X509_NAME_ENTRY_get_data(ent); fn_nid = OBJ_obj2nid(fn); if (fn_opt != XN_FLAG_FN_NONE) { int objlen, fld_len; diff --git a/Sources/CNIOBoringSSL/crypto/x509/rsa_pss.c b/Sources/CNIOBoringSSL/crypto/x509/rsa_pss.c index f8bd94b7..a611a6b4 100644 --- a/Sources/CNIOBoringSSL/crypto/x509/rsa_pss.c +++ b/Sources/CNIOBoringSSL/crypto/x509/rsa_pss.c @@ -56,6 +56,7 @@ #include #include +#include #include #include @@ -83,13 +84,13 @@ ASN1_SEQUENCE_cb(RSA_PSS_PARAMS, rsa_pss_cb) = { ASN1_EXP_OPT(RSA_PSS_PARAMS, trailerField, ASN1_INTEGER, 3), } ASN1_SEQUENCE_END_cb(RSA_PSS_PARAMS, RSA_PSS_PARAMS) -IMPLEMENT_ASN1_FUNCTIONS(RSA_PSS_PARAMS) +IMPLEMENT_ASN1_FUNCTIONS_const(RSA_PSS_PARAMS) // Given an MGF1 Algorithm ID decode to an Algorithm Identifier -static X509_ALGOR *rsa_mgf1_decode(X509_ALGOR *alg) { - if (alg == NULL || alg->parameter == NULL || - OBJ_obj2nid(alg->algorithm) != NID_mgf1 || +static X509_ALGOR *rsa_mgf1_decode(const X509_ALGOR *alg) { + if (OBJ_obj2nid(alg->algorithm) != NID_mgf1 || + alg->parameter == NULL || alg->parameter->type != V_ASN1_SEQUENCE) { return NULL; } @@ -99,30 +100,27 @@ static X509_ALGOR *rsa_mgf1_decode(X509_ALGOR *alg) { return d2i_X509_ALGOR(NULL, &p, plen); } -static RSA_PSS_PARAMS *rsa_pss_decode(const X509_ALGOR *alg, - X509_ALGOR **pmaskHash) { - *pmaskHash = NULL; - +static RSA_PSS_PARAMS *rsa_pss_decode(const X509_ALGOR *alg) { if (alg->parameter == NULL || alg->parameter->type != V_ASN1_SEQUENCE) { return NULL; } const uint8_t *p = alg->parameter->value.sequence->data; int plen = alg->parameter->value.sequence->length; - RSA_PSS_PARAMS *pss = d2i_RSA_PSS_PARAMS(NULL, &p, plen); - if (pss == NULL) { - return NULL; - } - - *pmaskHash = rsa_mgf1_decode(pss->maskGenAlgorithm); - return pss; + return d2i_RSA_PSS_PARAMS(NULL, &p, plen); } -// allocate and set algorithm ID from EVP_MD, default SHA1 +static int is_allowed_pss_md(const EVP_MD *md) { + int md_type = EVP_MD_type(md); + return md_type == NID_sha256 || md_type == NID_sha384 || + md_type == NID_sha512; +} + +// rsa_md_to_algor sets |*palg| to an |X509_ALGOR| describing the digest |md|, +// which must be an allowed PSS digest. static int rsa_md_to_algor(X509_ALGOR **palg, const EVP_MD *md) { - if (EVP_MD_type(md) == NID_sha1) { - return 1; - } + // SHA-1 should be omitted (DEFAULT), but we do not allow SHA-1. + assert(is_allowed_pss_md(md)); *palg = X509_ALGOR_new(); if (*palg == NULL) { return 0; @@ -131,15 +129,13 @@ static int rsa_md_to_algor(X509_ALGOR **palg, const EVP_MD *md) { return 1; } -// Allocate and set MGF1 algorithm ID from EVP_MD +// rsa_md_to_mgf1 sets |*palg| to an |X509_ALGOR| describing MGF-1 with the +// digest |mgf1md|, which must be an allowed PSS digest. static int rsa_md_to_mgf1(X509_ALGOR **palg, const EVP_MD *mgf1md) { + // SHA-1 should be omitted (DEFAULT), but we do not allow SHA-1. + assert(is_allowed_pss_md(mgf1md)); X509_ALGOR *algtmp = NULL; ASN1_STRING *stmp = NULL; - *palg = NULL; - - if (EVP_MD_type(mgf1md) == NID_sha1) { - return 1; - } // need to embed algorithm ID inside another if (!rsa_md_to_algor(&algtmp, mgf1md) || !ASN1_item_pack(algtmp, ASN1_ITEM_rptr(X509_ALGOR), &stmp)) { @@ -162,37 +158,35 @@ err: return 0; } -// convert algorithm ID to EVP_MD, default SHA1 -static const EVP_MD *rsa_algor_to_md(X509_ALGOR *alg) { - const EVP_MD *md; +static const EVP_MD *rsa_algor_to_md(const X509_ALGOR *alg) { if (!alg) { - return EVP_sha1(); - } - md = EVP_get_digestbyobj(alg->algorithm); - if (md == NULL) { + // If omitted, PSS defaults to SHA-1, which we do not allow. OPENSSL_PUT_ERROR(X509, X509_R_INVALID_PSS_PARAMETERS); + return NULL; + } + const EVP_MD *md = EVP_get_digestbyobj(alg->algorithm); + if (md == NULL || !is_allowed_pss_md(md)) { + OPENSSL_PUT_ERROR(X509, X509_R_INVALID_PSS_PARAMETERS); + return NULL; } return md; } -// convert MGF1 algorithm ID to EVP_MD, default SHA1 -static const EVP_MD *rsa_mgf1_to_md(const X509_ALGOR *alg, - X509_ALGOR *maskHash) { - const EVP_MD *md; +static const EVP_MD *rsa_mgf1_to_md(const X509_ALGOR *alg) { if (!alg) { - return EVP_sha1(); - } - // Check mask and lookup mask hash algorithm - if (OBJ_obj2nid(alg->algorithm) != NID_mgf1 || maskHash == NULL) { + // If omitted, PSS defaults to MGF-1 with SHA-1, which we do not allow. OPENSSL_PUT_ERROR(X509, X509_R_INVALID_PSS_PARAMETERS); return NULL; } - md = EVP_get_digestbyobj(maskHash->algorithm); - if (md == NULL) { + // Check mask and lookup mask hash algorithm. + X509_ALGOR *maskHash = rsa_mgf1_decode(alg); + if (maskHash == NULL) { OPENSSL_PUT_ERROR(X509, X509_R_INVALID_PSS_PARAMETERS); return NULL; } - return md; + const EVP_MD *ret = rsa_algor_to_md(maskHash); + X509_ALGOR_free(maskHash); + return ret; } int x509_rsa_ctx_to_pss(EVP_MD_CTX *ctx, X509_ALGOR *algor) { @@ -204,18 +198,14 @@ int x509_rsa_ctx_to_pss(EVP_MD_CTX *ctx, X509_ALGOR *algor) { return 0; } - EVP_PKEY *pk = EVP_PKEY_CTX_get0_pkey(ctx->pctx); + if (sigmd != mgf1md || !is_allowed_pss_md(sigmd)) { + OPENSSL_PUT_ERROR(X509, X509_R_INVALID_PSS_PARAMETERS); + return 0; + } + int md_len = EVP_MD_size(sigmd); if (saltlen == -1) { - saltlen = EVP_MD_size(sigmd); - } else if (saltlen == -2) { - // TODO(davidben): Forbid this mode. The world has largely standardized on - // salt length matching hash length. - saltlen = EVP_PKEY_size(pk) - EVP_MD_size(sigmd) - 2; - if (((EVP_PKEY_bits(pk) - 1) & 0x7) == 0) { - saltlen--; - } - } else if (saltlen != (int)EVP_MD_size(sigmd)) { - // We only allow salt length matching hash length and, for now, the -2 case. + saltlen = md_len; + } else if (saltlen != md_len) { OPENSSL_PUT_ERROR(X509, X509_R_INVALID_PSS_PARAMETERS); return 0; } @@ -227,11 +217,12 @@ int x509_rsa_ctx_to_pss(EVP_MD_CTX *ctx, X509_ALGOR *algor) { goto err; } - if (saltlen != 20) { - pss->saltLength = ASN1_INTEGER_new(); - if (!pss->saltLength || !ASN1_INTEGER_set(pss->saltLength, saltlen)) { - goto err; - } + // The DEFAULT value is 20, but this does not match any supported digest. + assert(saltlen != 20); + pss->saltLength = ASN1_INTEGER_new(); + if (!pss->saltLength || // + !ASN1_INTEGER_set(pss->saltLength, saltlen)) { + goto err; } if (!rsa_md_to_algor(&pss->hashAlgorithm, sigmd) || @@ -260,33 +251,38 @@ int x509_rsa_pss_to_ctx(EVP_MD_CTX *ctx, const X509_ALGOR *sigalg, // Decode PSS parameters int ret = 0; - X509_ALGOR *maskHash; - RSA_PSS_PARAMS *pss = rsa_pss_decode(sigalg, &maskHash); + RSA_PSS_PARAMS *pss = rsa_pss_decode(sigalg); if (pss == NULL) { OPENSSL_PUT_ERROR(X509, X509_R_INVALID_PSS_PARAMETERS); goto err; } - const EVP_MD *mgf1md = rsa_mgf1_to_md(pss->maskGenAlgorithm, maskHash); + const EVP_MD *mgf1md = rsa_mgf1_to_md(pss->maskGenAlgorithm); const EVP_MD *md = rsa_algor_to_md(pss->hashAlgorithm); if (mgf1md == NULL || md == NULL) { goto err; } - int saltlen = 20; - if (pss->saltLength != NULL) { - saltlen = ASN1_INTEGER_get(pss->saltLength); - - // Could perform more salt length sanity checks but the main - // RSA routines will trap other invalid values anyway. - if (saltlen < 0) { - OPENSSL_PUT_ERROR(X509, X509_R_INVALID_PSS_PARAMETERS); - goto err; - } + // We require the MGF-1 and signing hashes to match. + if (mgf1md != md) { + OPENSSL_PUT_ERROR(X509, X509_R_INVALID_PSS_PARAMETERS); + goto err; } - // low-level routines support only trailer field 0xbc (value 1) - // and PKCS#1 says we should reject any other value anyway. + // We require the salt length be the hash length. The DEFAULT value is 20, but + // this does not match any supported salt length. + uint64_t salt_len = 0; + if (pss->saltLength == NULL || + !ASN1_INTEGER_get_uint64(&salt_len, pss->saltLength) || + salt_len != EVP_MD_size(md)) { + OPENSSL_PUT_ERROR(X509, X509_R_INVALID_PSS_PARAMETERS); + goto err; + } + assert(salt_len <= INT_MAX); + + // The trailer field must be 1 (0xbc). This value is DEFAULT, so the structure + // is required to omit it in DER. Although a syntax error, we also tolerate an + // explicitly-encoded value. See the certificates in cl/362617931. if (pss->trailerField != NULL && ASN1_INTEGER_get(pss->trailerField) != 1) { OPENSSL_PUT_ERROR(X509, X509_R_INVALID_PSS_PARAMETERS); goto err; @@ -295,7 +291,7 @@ int x509_rsa_pss_to_ctx(EVP_MD_CTX *ctx, const X509_ALGOR *sigalg, EVP_PKEY_CTX *pctx; if (!EVP_DigestVerifyInit(ctx, &pctx, md, NULL, pkey) || !EVP_PKEY_CTX_set_rsa_padding(pctx, RSA_PKCS1_PSS_PADDING) || - !EVP_PKEY_CTX_set_rsa_pss_saltlen(pctx, saltlen) || + !EVP_PKEY_CTX_set_rsa_pss_saltlen(pctx, (int)salt_len) || !EVP_PKEY_CTX_set_rsa_mgf1_md(pctx, mgf1md)) { goto err; } @@ -304,7 +300,6 @@ int x509_rsa_pss_to_ctx(EVP_MD_CTX *ctx, const X509_ALGOR *sigalg, err: RSA_PSS_PARAMS_free(pss); - X509_ALGOR_free(maskHash); return ret; } @@ -313,8 +308,8 @@ int x509_print_rsa_pss_params(BIO *bp, const X509_ALGOR *sigalg, int indent, assert(OBJ_obj2nid(sigalg->algorithm) == NID_rsassaPss); int rv = 0; - X509_ALGOR *maskHash; - RSA_PSS_PARAMS *pss = rsa_pss_decode(sigalg, &maskHash); + X509_ALGOR *maskHash = NULL; + RSA_PSS_PARAMS *pss = rsa_pss_decode(sigalg); if (!pss) { if (BIO_puts(bp, " (INVALID PSS PARAMETERS)\n") <= 0) { goto err; @@ -344,17 +339,17 @@ int x509_print_rsa_pss_params(BIO *bp, const X509_ALGOR *sigalg, int indent, } if (pss->maskGenAlgorithm) { - if (i2a_ASN1_OBJECT(bp, pss->maskGenAlgorithm->algorithm) <= 0 || - BIO_puts(bp, " with ") <= 0) { - goto err; - } - - if (maskHash) { - if (i2a_ASN1_OBJECT(bp, maskHash->algorithm) <= 0) { + maskHash = rsa_mgf1_decode(pss->maskGenAlgorithm); + if (maskHash == NULL) { + if (BIO_puts(bp, "INVALID") <= 0) { + goto err; + } + } else { + if (i2a_ASN1_OBJECT(bp, pss->maskGenAlgorithm->algorithm) <= 0 || + BIO_puts(bp, " with ") <= 0 || + i2a_ASN1_OBJECT(bp, maskHash->algorithm) <= 0) { goto err; } - } else if (BIO_puts(bp, "INVALID") <= 0) { - goto err; } } else if (BIO_puts(bp, "mgf1 with sha1 (default)") <= 0) { goto err; diff --git a/Sources/CNIOBoringSSL/crypto/x509/t_req.c b/Sources/CNIOBoringSSL/crypto/x509/t_req.c index 6816350f..e29455f6 100644 --- a/Sources/CNIOBoringSSL/crypto/x509/t_req.c +++ b/Sources/CNIOBoringSSL/crypto/x509/t_req.c @@ -105,7 +105,9 @@ int X509_REQ_print_ex(BIO *bio, X509_REQ *x, unsigned long nmflags, } if (!(cflag & X509_FLAG_NO_VERSION)) { l = X509_REQ_get_version(x); - assert(l == X509_REQ_VERSION_1); + // Only zero, |X509_REQ_VERSION_1|, is valid but our parser accepts some + // invalid values for compatibility. + assert(0 <= l && l <= 2); if (BIO_printf(bio, "%8sVersion: %ld (0x%lx)\n", "", l + 1, (unsigned long)l) <= 0) { goto err; @@ -206,13 +208,12 @@ int X509_REQ_print_ex(BIO *bio, X509_REQ *x, unsigned long nmflags, if (exts) { BIO_printf(bio, "%8sRequested Extensions:\n", ""); - size_t i; - for (i = 0; i < sk_X509_EXTENSION_num(exts); i++) { - X509_EXTENSION *ex = sk_X509_EXTENSION_value(exts, i); + for (size_t i = 0; i < sk_X509_EXTENSION_num(exts); i++) { + const X509_EXTENSION *ex = sk_X509_EXTENSION_value(exts, i); if (BIO_printf(bio, "%12s", "") <= 0) { goto err; } - ASN1_OBJECT *obj = X509_EXTENSION_get_object(ex); + const ASN1_OBJECT *obj = X509_EXTENSION_get_object(ex); i2a_ASN1_OBJECT(bio, obj); const int is_critical = X509_EXTENSION_get_critical(ex); if (BIO_printf(bio, ": %s\n", is_critical ? "critical" : "") <= 0) { diff --git a/Sources/CNIOBoringSSL/crypto/x509/t_x509.c b/Sources/CNIOBoringSSL/crypto/x509/t_x509.c index c0bc1c51..48fea41a 100644 --- a/Sources/CNIOBoringSSL/crypto/x509/t_x509.c +++ b/Sources/CNIOBoringSSL/crypto/x509/t_x509.c @@ -270,59 +270,6 @@ err: return ret; } -int X509_ocspid_print(BIO *bp, X509 *x) { - unsigned char *der = NULL; - unsigned char *dertmp; - int derlen; - int i; - unsigned char SHA1md[SHA_DIGEST_LENGTH]; - - // display the hash of the subject as it would appear in OCSP requests - if (BIO_printf(bp, " Subject OCSP hash: ") <= 0) { - goto err; - } - derlen = i2d_X509_NAME(x->cert_info->subject, NULL); - if ((der = dertmp = (unsigned char *)OPENSSL_malloc(derlen)) == NULL) { - goto err; - } - i2d_X509_NAME(x->cert_info->subject, &dertmp); - - if (!EVP_Digest(der, derlen, SHA1md, NULL, EVP_sha1(), NULL)) { - goto err; - } - for (i = 0; i < SHA_DIGEST_LENGTH; i++) { - if (BIO_printf(bp, "%02X", SHA1md[i]) <= 0) { - goto err; - } - } - OPENSSL_free(der); - der = NULL; - - // display the hash of the public key as it would appear in OCSP requests - if (BIO_printf(bp, "\n Public key OCSP hash: ") <= 0) { - goto err; - } - - if (!EVP_Digest(x->cert_info->key->public_key->data, - x->cert_info->key->public_key->length, SHA1md, NULL, - EVP_sha1(), NULL)) { - goto err; - } - for (i = 0; i < SHA_DIGEST_LENGTH; i++) { - if (BIO_printf(bp, "%02X", SHA1md[i]) <= 0) { - goto err; - } - } - BIO_printf(bp, "\n"); - - return 1; -err: - if (der != NULL) { - OPENSSL_free(der); - } - return 0; -} - int X509_signature_print(BIO *bp, const X509_ALGOR *sigalg, const ASN1_STRING *sig) { if (BIO_puts(bp, " Signature Algorithm: ") <= 0) { diff --git a/Sources/CNIOBoringSSL/crypto/x509/x509_cmp.c b/Sources/CNIOBoringSSL/crypto/x509/x509_cmp.c index 548ca256..3a68fb9b 100644 --- a/Sources/CNIOBoringSSL/crypto/x509/x509_cmp.c +++ b/Sources/CNIOBoringSSL/crypto/x509/x509_cmp.c @@ -305,127 +305,6 @@ int X509_check_private_key(X509 *x, const EVP_PKEY *k) { return 0; } -// Check a suite B algorithm is permitted: pass in a public key and the NID -// of its signature (or 0 if no signature). The pflags is a pointer to a -// flags field which must contain the suite B verification flags. - -static int check_suite_b(EVP_PKEY *pkey, int sign_nid, unsigned long *pflags) { - const EC_GROUP *grp = NULL; - int curve_nid; - if (pkey && pkey->type == EVP_PKEY_EC) { - grp = EC_KEY_get0_group(pkey->pkey.ec); - } - if (!grp) { - return X509_V_ERR_SUITE_B_INVALID_ALGORITHM; - } - curve_nid = EC_GROUP_get_curve_name(grp); - // Check curve is consistent with LOS - if (curve_nid == NID_secp384r1) { // P-384 - // Check signature algorithm is consistent with curve. - if (sign_nid != -1 && sign_nid != NID_ecdsa_with_SHA384) { - return X509_V_ERR_SUITE_B_INVALID_SIGNATURE_ALGORITHM; - } - if (!(*pflags & X509_V_FLAG_SUITEB_192_LOS)) { - return X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED; - } - // If we encounter P-384 we cannot use P-256 later - *pflags &= ~X509_V_FLAG_SUITEB_128_LOS_ONLY; - } else if (curve_nid == NID_X9_62_prime256v1) { // P-256 - if (sign_nid != -1 && sign_nid != NID_ecdsa_with_SHA256) { - return X509_V_ERR_SUITE_B_INVALID_SIGNATURE_ALGORITHM; - } - if (!(*pflags & X509_V_FLAG_SUITEB_128_LOS_ONLY)) { - return X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED; - } - } else { - return X509_V_ERR_SUITE_B_INVALID_CURVE; - } - - return X509_V_OK; -} - -int X509_chain_check_suiteb(int *perror_depth, X509 *x, STACK_OF(X509) *chain, - unsigned long flags) { - int rv, sign_nid; - size_t i; - EVP_PKEY *pk = NULL; - unsigned long tflags; - if (!(flags & X509_V_FLAG_SUITEB_128_LOS)) { - return X509_V_OK; - } - tflags = flags; - // If no EE certificate passed in must be first in chain - if (x == NULL) { - x = sk_X509_value(chain, 0); - i = 1; - } else { - i = 0; - } - - if (X509_get_version(x) != X509_VERSION_3) { - rv = X509_V_ERR_SUITE_B_INVALID_VERSION; - // Correct error depth - i = 0; - goto end; - } - - pk = X509_get_pubkey(x); - // Check EE key only - rv = check_suite_b(pk, -1, &tflags); - if (rv != X509_V_OK) { - // Correct error depth - i = 0; - goto end; - } - for (; i < sk_X509_num(chain); i++) { - sign_nid = X509_get_signature_nid(x); - x = sk_X509_value(chain, i); - if (X509_get_version(x) != X509_VERSION_3) { - rv = X509_V_ERR_SUITE_B_INVALID_VERSION; - goto end; - } - EVP_PKEY_free(pk); - pk = X509_get_pubkey(x); - rv = check_suite_b(pk, sign_nid, &tflags); - if (rv != X509_V_OK) { - goto end; - } - } - - // Final check: root CA signature - rv = check_suite_b(pk, X509_get_signature_nid(x), &tflags); -end: - if (pk) { - EVP_PKEY_free(pk); - } - if (rv != X509_V_OK) { - // Invalid signature or LOS errors are for previous cert - if ((rv == X509_V_ERR_SUITE_B_INVALID_SIGNATURE_ALGORITHM || - rv == X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED) && - i) { - i--; - } - // If we have LOS error and flags changed then we are signing P-384 - // with P-256. Use more meaninggul error. - if (rv == X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED && flags != tflags) { - rv = X509_V_ERR_SUITE_B_CANNOT_SIGN_P_384_WITH_P_256; - } - if (perror_depth) { - *perror_depth = i; - } - } - return rv; -} - -int X509_CRL_check_suiteb(X509_CRL *crl, EVP_PKEY *pk, unsigned long flags) { - int sign_nid; - if (!(flags & X509_V_FLAG_SUITEB_128_LOS)) { - return X509_V_OK; - } - sign_nid = OBJ_obj2nid(crl->crl->sig_alg->algorithm); - return check_suite_b(pk, sign_nid, &flags); -} - // Not strictly speaking an "up_ref" as a STACK doesn't have a reference // count but it has the same effect by duping the STACK and upping the ref of // each X509 structure. diff --git a/Sources/CNIOBoringSSL/crypto/x509/x509_ext.c b/Sources/CNIOBoringSSL/crypto/x509/x509_ext.c index faa11ce4..16c7ca5e 100644 --- a/Sources/CNIOBoringSSL/crypto/x509/x509_ext.c +++ b/Sources/CNIOBoringSSL/crypto/x509/x509_ext.c @@ -99,7 +99,7 @@ int X509_CRL_add1_ext_i2d(X509_CRL *x, int nid, void *value, int crit, return X509V3_add1_i2d(&x->crl->extensions, nid, value, crit, flags); } -int X509_CRL_add_ext(X509_CRL *x, X509_EXTENSION *ex, int loc) { +int X509_CRL_add_ext(X509_CRL *x, const X509_EXTENSION *ex, int loc) { return (X509v3_add_ext(&(x->crl->extensions), ex, loc) != NULL); } @@ -127,7 +127,7 @@ X509_EXTENSION *X509_delete_ext(X509 *x, int loc) { return (X509v3_delete_ext(x->cert_info->extensions, loc)); } -int X509_add_ext(X509 *x, X509_EXTENSION *ex, int loc) { +int X509_add_ext(X509 *x, const X509_EXTENSION *ex, int loc) { return (X509v3_add_ext(&(x->cert_info->extensions), ex, loc) != NULL); } @@ -168,7 +168,7 @@ X509_EXTENSION *X509_REVOKED_delete_ext(X509_REVOKED *x, int loc) { return (X509v3_delete_ext(x->extensions, loc)); } -int X509_REVOKED_add_ext(X509_REVOKED *x, X509_EXTENSION *ex, int loc) { +int X509_REVOKED_add_ext(X509_REVOKED *x, const X509_EXTENSION *ex, int loc) { return (X509v3_add_ext(&(x->extensions), ex, loc) != NULL); } diff --git a/Sources/CNIOBoringSSL/crypto/x509/x509_txt.c b/Sources/CNIOBoringSSL/crypto/x509/x509_txt.c index 5429552f..e4823859 100644 --- a/Sources/CNIOBoringSSL/crypto/x509/x509_txt.c +++ b/Sources/CNIOBoringSSL/crypto/x509/x509_txt.c @@ -168,19 +168,6 @@ const char *X509_verify_cert_error_string(long err) { case X509_V_ERR_CRL_PATH_VALIDATION_ERROR: return "CRL path validation error"; - case X509_V_ERR_SUITE_B_INVALID_VERSION: - return "Suite B: certificate version invalid"; - case X509_V_ERR_SUITE_B_INVALID_ALGORITHM: - return "Suite B: invalid public key algorithm"; - case X509_V_ERR_SUITE_B_INVALID_CURVE: - return "Suite B: invalid ECC curve"; - case X509_V_ERR_SUITE_B_INVALID_SIGNATURE_ALGORITHM: - return "Suite B: invalid signature algorithm"; - case X509_V_ERR_SUITE_B_LOS_NOT_ALLOWED: - return "Suite B: curve not allowed for this LOS"; - case X509_V_ERR_SUITE_B_CANNOT_SIGN_P_384_WITH_P_256: - return "Suite B: cannot sign P-384 with P-256"; - case X509_V_ERR_HOSTNAME_MISMATCH: return "Hostname mismatch"; case X509_V_ERR_EMAIL_MISMATCH: diff --git a/Sources/CNIOBoringSSL/crypto/x509/x509_v3.c b/Sources/CNIOBoringSSL/crypto/x509/x509_v3.c index d6bebe28..72b96b0f 100644 --- a/Sources/CNIOBoringSSL/crypto/x509/x509_v3.c +++ b/Sources/CNIOBoringSSL/crypto/x509/x509_v3.c @@ -144,7 +144,7 @@ X509_EXTENSION *X509v3_delete_ext(STACK_OF(X509_EXTENSION) *x, int loc) { } STACK_OF(X509_EXTENSION) *X509v3_add_ext(STACK_OF(X509_EXTENSION) **x, - X509_EXTENSION *ex, int loc) { + const X509_EXTENSION *ex, int loc) { X509_EXTENSION *new_ex = NULL; int n; STACK_OF(X509_EXTENSION) *sk = NULL; @@ -267,14 +267,14 @@ int X509_EXTENSION_set_data(X509_EXTENSION *ex, const ASN1_OCTET_STRING *data) { return 1; } -ASN1_OBJECT *X509_EXTENSION_get_object(X509_EXTENSION *ex) { +ASN1_OBJECT *X509_EXTENSION_get_object(const X509_EXTENSION *ex) { if (ex == NULL) { return NULL; } return ex->object; } -ASN1_OCTET_STRING *X509_EXTENSION_get_data(X509_EXTENSION *ex) { +ASN1_OCTET_STRING *X509_EXTENSION_get_data(const X509_EXTENSION *ex) { if (ex == NULL) { return NULL; } diff --git a/Sources/CNIOBoringSSL/crypto/x509/x509_vfy.c b/Sources/CNIOBoringSSL/crypto/x509/x509_vfy.c index c8eb4e8b..00f22e69 100644 --- a/Sources/CNIOBoringSSL/crypto/x509/x509_vfy.c +++ b/Sources/CNIOBoringSSL/crypto/x509/x509_vfy.c @@ -457,17 +457,6 @@ int X509_verify_cert(X509_STORE_CTX *ctx) { goto end; } - int err = X509_chain_check_suiteb(&ctx->error_depth, NULL, ctx->chain, - ctx->param->flags); - if (err != X509_V_OK) { - ctx->error = err; - ctx->current_cert = sk_X509_value(ctx->chain, ctx->error_depth); - ok = ctx->verify_cb(0, ctx); - if (!ok) { - goto end; - } - } - // At this point, we have a chain and need to verify it if (ctx->verify != NULL) { ok = ctx->verify(ctx); @@ -689,7 +678,7 @@ end: } static int reject_dns_name_in_common_name(X509 *x509) { - X509_NAME *name = X509_get_subject_name(x509); + const X509_NAME *name = X509_get_subject_name(x509); int i = -1; for (;;) { i = X509_NAME_get_index_by_NID(name, NID_commonName, i); @@ -697,8 +686,8 @@ static int reject_dns_name_in_common_name(X509 *x509) { return X509_V_OK; } - X509_NAME_ENTRY *entry = X509_NAME_get_entry(name, i); - ASN1_STRING *common_name = X509_NAME_ENTRY_get_data(entry); + const X509_NAME_ENTRY *entry = X509_NAME_get_entry(name, i); + const ASN1_STRING *common_name = X509_NAME_ENTRY_get_data(entry); unsigned char *idval; int idlen = ASN1_STRING_to_UTF8(&idval, common_name); if (idlen < 0) { @@ -982,18 +971,21 @@ err: // Check CRL times against values in X509_STORE_CTX static int check_crl_time(X509_STORE_CTX *ctx, X509_CRL *crl, int notify) { - time_t *ptime; - int i; + if (ctx->param->flags & X509_V_FLAG_NO_CHECK_TIME) { + return 1; + } + if (notify) { ctx->current_crl = crl; } + time_t *ptime; if (ctx->param->flags & X509_V_FLAG_USE_CHECK_TIME) { ptime = &ctx->param->check_time; } else { ptime = NULL; } - i = X509_cmp_time(X509_CRL_get0_lastUpdate(crl), ptime); + int i = X509_cmp_time(X509_CRL_get0_lastUpdate(crl), ptime); if (i == 0) { if (!notify) { return 0; @@ -1108,7 +1100,7 @@ static int get_crl_sk(X509_STORE_CTX *ctx, X509_CRL **pcrl, X509_CRL **pdcrl, // both present or both absent. If both present all fields must be identical. static int crl_extension_match(X509_CRL *a, X509_CRL *b, int nid) { - ASN1_OCTET_STRING *exta, *extb; + const ASN1_OCTET_STRING *exta, *extb; int i; i = X509_CRL_get_ext_by_NID(a, nid, -1); if (i >= 0) { @@ -1646,15 +1638,6 @@ static int check_crl(X509_STORE_CTX *ctx, X509_CRL *crl) { goto err; } } else { - int rv; - rv = X509_CRL_check_suiteb(crl, ikey, ctx->param->flags); - if (rv != X509_V_OK) { - ctx->error = rv; - ok = ctx->verify_cb(0, ctx); - if (!ok) { - goto err; - } - } // Verify CRL signature if (X509_CRL_verify(crl, ikey) <= 0) { ctx->error = X509_V_ERR_CRL_SIGNATURE_FAILURE; @@ -1710,6 +1693,9 @@ static int check_policy(X509_STORE_CTX *ctx) { if (ctx->parent) { return 1; } + // TODO(davidben): Historically, outputs of the |X509_policy_check| were saved + // on |ctx| and accessible via the public API. This has since been removed, so + // remove the fields from |X509_STORE_CTX|. ret = X509_policy_check(&ctx->tree, &ctx->explicit_policy, ctx->chain, ctx->param->policies, ctx->param->flags); if (ret == 0) { @@ -1756,16 +1742,18 @@ static int check_policy(X509_STORE_CTX *ctx) { } static int check_cert_time(X509_STORE_CTX *ctx, X509 *x) { - time_t *ptime; - int i; + if (ctx->param->flags & X509_V_FLAG_NO_CHECK_TIME) { + return 1; + } + time_t *ptime; if (ctx->param->flags & X509_V_FLAG_USE_CHECK_TIME) { ptime = &ctx->param->check_time; } else { ptime = NULL; } - i = X509_cmp_time(X509_get_notBefore(x), ptime); + int i = X509_cmp_time(X509_get_notBefore(x), ptime); if (i == 0) { ctx->error = X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD; ctx->current_cert = x; @@ -1889,66 +1877,13 @@ int X509_cmp_current_time(const ASN1_TIME *ctm) { } int X509_cmp_time(const ASN1_TIME *ctm, time_t *cmp_time) { - static const size_t utctime_length = sizeof("YYMMDDHHMMSSZ") - 1; - static const size_t generalizedtime_length = sizeof("YYYYMMDDHHMMSSZ") - 1; - ASN1_TIME *asn1_cmp_time = NULL; - int i, day, sec, ret = 0; - - // Note that ASN.1 allows much more slack in the time format than RFC 5280. - // In RFC 5280, the representation is fixed: - // UTCTime: YYMMDDHHMMSSZ - // GeneralizedTime: YYYYMMDDHHMMSSZ - // - // We do NOT currently enforce the following RFC 5280 requirement: - // "CAs conforming to this profile MUST always encode certificate - // validity dates through the year 2049 as UTCTime; certificate validity - // dates in 2050 or later MUST be encoded as GeneralizedTime." - switch (ctm->type) { - case V_ASN1_UTCTIME: - if (ctm->length != (int)(utctime_length)) { - return 0; - } - break; - case V_ASN1_GENERALIZEDTIME: - if (ctm->length != (int)(generalizedtime_length)) { - return 0; - } - break; - default: - return 0; - } - - //* - // Verify the format: the ASN.1 functions we use below allow a more - // flexible format than what's mandated by RFC 5280. - // Digit and date ranges will be verified in the conversion methods. - for (i = 0; i < ctm->length - 1; i++) { - if (!isdigit(ctm->data[i])) { - return 0; - } - } - if (ctm->data[ctm->length - 1] != 'Z') { + int64_t ctm_time; + if (!ASN1_TIME_to_posix(ctm, &ctm_time)) { return 0; } - - // There is ASN1_UTCTIME_cmp_time_t but no - // ASN1_GENERALIZEDTIME_cmp_time_t or ASN1_TIME_cmp_time_t, - // so we go through ASN.1 - asn1_cmp_time = X509_time_adj(NULL, 0, cmp_time); - if (asn1_cmp_time == NULL) { - goto err; - } - if (!ASN1_TIME_diff(&day, &sec, ctm, asn1_cmp_time)) { - goto err; - } - - // X509_cmp_time comparison is <=. + int64_t compare_time = (cmp_time == NULL) ? time(NULL) : *cmp_time; // The return value 0 is reserved for errors. - ret = (day >= 0 && sec >= 0) ? -1 : 1; - -err: - ASN1_TIME_free(asn1_cmp_time); - return ret; + return (ctm_time - compare_time <= 0) ? -1 : 1; } ASN1_TIME *X509_gmtime_adj(ASN1_TIME *s, long offset_sec) { @@ -2042,8 +1977,7 @@ X509_CRL *X509_CRL_diff(X509_CRL *base, X509_CRL *newer, EVP_PKEY *skey, // number to correct value too. for (i = 0; i < X509_CRL_get_ext_count(newer); i++) { - X509_EXTENSION *ext; - ext = X509_CRL_get_ext(newer, i); + const X509_EXTENSION *ext = X509_CRL_get_ext(newer, i); if (!X509_CRL_add_ext(crl, ext, -1)) { goto memerr; } @@ -2356,11 +2290,16 @@ err: // Set alternative lookup method: just a STACK of trusted certificates. This // avoids X509_STORE nastiness where it isn't needed. -void X509_STORE_CTX_trusted_stack(X509_STORE_CTX *ctx, STACK_OF(X509) *sk) { +void X509_STORE_CTX_set0_trusted_stack(X509_STORE_CTX *ctx, + STACK_OF(X509) *sk) { ctx->other_ctx = sk; ctx->get_issuer = get_issuer_sk; } +void X509_STORE_CTX_trusted_stack(X509_STORE_CTX *ctx, STACK_OF(X509) *sk) { + X509_STORE_CTX_set0_trusted_stack(ctx, sk); +} + void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx) { // We need to be idempotent because, unfortunately, |X509_STORE_CTX_free| // also calls this function. @@ -2406,14 +2345,6 @@ void X509_STORE_CTX_set_verify_cb(X509_STORE_CTX *ctx, ctx->verify_cb = verify_cb; } -X509_POLICY_TREE *X509_STORE_CTX_get0_policy_tree(X509_STORE_CTX *ctx) { - return ctx->tree; -} - -int X509_STORE_CTX_get_explicit_policy(X509_STORE_CTX *ctx) { - return ctx->explicit_policy; -} - int X509_STORE_CTX_set_default(X509_STORE_CTX *ctx, const char *name) { const X509_VERIFY_PARAM *param; param = X509_VERIFY_PARAM_lookup(name); diff --git a/Sources/CNIOBoringSSL/crypto/x509/x509cset.c b/Sources/CNIOBoringSSL/crypto/x509/x509cset.c index c330610f..8b0c0ba5 100644 --- a/Sources/CNIOBoringSSL/crypto/x509/x509cset.c +++ b/Sources/CNIOBoringSSL/crypto/x509/x509cset.c @@ -245,11 +245,8 @@ int i2d_X509_CRL_tbs(X509_CRL *crl, unsigned char **outp) { } int X509_CRL_set1_signature_algo(X509_CRL *crl, const X509_ALGOR *algo) { - // TODO(https://crbug.com/boringssl/407): Generated ASN.1 dup functions - // should be const. Alternatively, when we can embed required fields - // directly in structs, import |X509_ALGOR_copy| from upstream. - X509_ALGOR *copy1 = X509_ALGOR_dup((X509_ALGOR *)algo); - X509_ALGOR *copy2 = X509_ALGOR_dup((X509_ALGOR *)algo); + X509_ALGOR *copy1 = X509_ALGOR_dup(algo); + X509_ALGOR *copy2 = X509_ALGOR_dup(algo); if (copy1 == NULL || copy2 == NULL) { X509_ALGOR_free(copy1); X509_ALGOR_free(copy2); diff --git a/Sources/CNIOBoringSSL/crypto/x509/x509name.c b/Sources/CNIOBoringSSL/crypto/x509/x509name.c index acbc66af..80cd3c82 100644 --- a/Sources/CNIOBoringSSL/crypto/x509/x509name.c +++ b/Sources/CNIOBoringSSL/crypto/x509/x509name.c @@ -80,14 +80,12 @@ int X509_NAME_get_text_by_NID(const X509_NAME *name, int nid, char *buf, int X509_NAME_get_text_by_OBJ(const X509_NAME *name, const ASN1_OBJECT *obj, char *buf, int len) { - int i; - ASN1_STRING *data; - - i = X509_NAME_get_index_by_OBJ(name, obj, -1); + int i = X509_NAME_get_index_by_OBJ(name, obj, -1); if (i < 0) { return -1; } - data = X509_NAME_ENTRY_get_data(X509_NAME_get_entry(name, i)); + const ASN1_STRING *data = + X509_NAME_ENTRY_get_data(X509_NAME_get_entry(name, i)); i = (data->length > (len - 1)) ? (len - 1) : data->length; if (buf == NULL) { return data->length; @@ -148,51 +146,46 @@ X509_NAME_ENTRY *X509_NAME_get_entry(const X509_NAME *name, int loc) { } X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, int loc) { - X509_NAME_ENTRY *ret; - int i, n, set_prev, set_next; - STACK_OF(X509_NAME_ENTRY) *sk; - if (name == NULL || loc < 0 || sk_X509_NAME_ENTRY_num(name->entries) <= (size_t)loc) { return NULL; } - sk = name->entries; - ret = sk_X509_NAME_ENTRY_delete(sk, loc); - n = sk_X509_NAME_ENTRY_num(sk); + + STACK_OF(X509_NAME_ENTRY) *sk = name->entries; + X509_NAME_ENTRY *ret = sk_X509_NAME_ENTRY_delete(sk, loc); + int n = sk_X509_NAME_ENTRY_num(sk); name->modified = 1; if (loc == n) { return ret; } - // else we need to fixup the set field + int set_prev; if (loc != 0) { - set_prev = (sk_X509_NAME_ENTRY_value(sk, loc - 1))->set; + set_prev = sk_X509_NAME_ENTRY_value(sk, loc - 1)->set; } else { set_prev = ret->set - 1; } - set_next = sk_X509_NAME_ENTRY_value(sk, loc)->set; + int set_next = sk_X509_NAME_ENTRY_value(sk, loc)->set; - // set_prev is the previous set set is the current set set_next is the - // following prev 1 1 1 1 1 1 1 1 set 1 1 2 2 next 1 1 2 2 2 2 3 2 so - // basically only if prev and next differ by 2, then re-number down by 1 + // If we removed a singleton RDN, update the RDN indices so they are + // consecutive again. if (set_prev + 1 < set_next) { - for (i = loc; i < n; i++) { + for (int i = loc; i < n; i++) { sk_X509_NAME_ENTRY_value(sk, i)->set--; } } return ret; } -int X509_NAME_add_entry_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, int type, - const unsigned char *bytes, int len, int loc, - int set) { - X509_NAME_ENTRY *ne; - int ret; - ne = X509_NAME_ENTRY_create_by_OBJ(NULL, obj, type, bytes, len); +int X509_NAME_add_entry_by_OBJ(X509_NAME *name, const ASN1_OBJECT *obj, + int type, const unsigned char *bytes, int len, + int loc, int set) { + X509_NAME_ENTRY *ne = + X509_NAME_ENTRY_create_by_OBJ(NULL, obj, type, bytes, len); if (!ne) { return 0; } - ret = X509_NAME_add_entry(name, ne, loc, set); + int ret = X509_NAME_add_entry(name, ne, loc, set); X509_NAME_ENTRY_free(ne); return ret; } @@ -200,13 +193,12 @@ int X509_NAME_add_entry_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, int type, int X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, int type, const unsigned char *bytes, int len, int loc, int set) { - X509_NAME_ENTRY *ne; - int ret; - ne = X509_NAME_ENTRY_create_by_NID(NULL, nid, type, bytes, len); + X509_NAME_ENTRY *ne = + X509_NAME_ENTRY_create_by_NID(NULL, nid, type, bytes, len); if (!ne) { return 0; } - ret = X509_NAME_add_entry(name, ne, loc, set); + int ret = X509_NAME_add_entry(name, ne, loc, set); X509_NAME_ENTRY_free(ne); return ret; } @@ -214,20 +206,19 @@ int X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, int type, int X509_NAME_add_entry_by_txt(X509_NAME *name, const char *field, int type, const unsigned char *bytes, int len, int loc, int set) { - X509_NAME_ENTRY *ne; - int ret; - ne = X509_NAME_ENTRY_create_by_txt(NULL, field, type, bytes, len); + X509_NAME_ENTRY *ne = + X509_NAME_ENTRY_create_by_txt(NULL, field, type, bytes, len); if (!ne) { return 0; } - ret = X509_NAME_add_entry(name, ne, loc, set); + int ret = X509_NAME_add_entry(name, ne, loc, set); X509_NAME_ENTRY_free(ne); return ret; } // if set is -1, append to previous set, 0 'a new one', and 1, prepend to the // guy we are about to stomp on. -int X509_NAME_add_entry(X509_NAME *name, X509_NAME_ENTRY *ne, int loc, +int X509_NAME_add_entry(X509_NAME *name, const X509_NAME_ENTRY *entry, int loc, int set) { X509_NAME_ENTRY *new_name = NULL; int n, i, inc; @@ -267,7 +258,7 @@ int X509_NAME_add_entry(X509_NAME *name, X509_NAME_ENTRY *ne, int loc, } } - if ((new_name = X509_NAME_ENTRY_dup(ne)) == NULL) { + if ((new_name = X509_NAME_ENTRY_dup(entry)) == NULL) { goto err; } new_name->set = set; diff --git a/Sources/CNIOBoringSSL/crypto/x509/x509rset.c b/Sources/CNIOBoringSSL/crypto/x509/x509rset.c index 3bcfb5f7..d5b8969e 100644 --- a/Sources/CNIOBoringSSL/crypto/x509/x509rset.c +++ b/Sources/CNIOBoringSSL/crypto/x509/x509rset.c @@ -88,10 +88,7 @@ int X509_REQ_set_pubkey(X509_REQ *x, EVP_PKEY *pkey) { } int X509_REQ_set1_signature_algo(X509_REQ *req, const X509_ALGOR *algo) { - // TODO(https://crbug.com/boringssl/407): Generated ASN.1 dup functions - // should be const. Alternatively, when we can embed required fields - // directly in structs, import |X509_ALGOR_copy| from upstream. - X509_ALGOR *copy = X509_ALGOR_dup((X509_ALGOR *)algo); + X509_ALGOR *copy = X509_ALGOR_dup(algo); if (copy == NULL) { return 0; } diff --git a/Sources/CNIOBoringSSL/crypto/x509/x_algor.c b/Sources/CNIOBoringSSL/crypto/x509/x_algor.c index cc3ffe78..1c3eeeab 100644 --- a/Sources/CNIOBoringSSL/crypto/x509/x_algor.c +++ b/Sources/CNIOBoringSSL/crypto/x509/x_algor.c @@ -69,14 +69,8 @@ ASN1_SEQUENCE(X509_ALGOR) = { ASN1_OPT(X509_ALGOR, parameter, ASN1_ANY), } ASN1_SEQUENCE_END(X509_ALGOR) -ASN1_ITEM_TEMPLATE(X509_ALGORS) = ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, - 0, algorithms, - X509_ALGOR) -ASN1_ITEM_TEMPLATE_END(X509_ALGORS) - -IMPLEMENT_ASN1_FUNCTIONS(X509_ALGOR) -IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(X509_ALGORS, X509_ALGORS, X509_ALGORS) -IMPLEMENT_ASN1_DUP_FUNCTION(X509_ALGOR) +IMPLEMENT_ASN1_FUNCTIONS_const(X509_ALGOR) +IMPLEMENT_ASN1_DUP_FUNCTION_const(X509_ALGOR) int X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int ptype, void *pval) { if (!alg) { diff --git a/Sources/CNIOBoringSSL/crypto/x509/x_all.c b/Sources/CNIOBoringSSL/crypto/x509/x_all.c index e1267e7b..b9238726 100644 --- a/Sources/CNIOBoringSSL/crypto/x509/x_all.c +++ b/Sources/CNIOBoringSSL/crypto/x509/x_all.c @@ -241,7 +241,6 @@ IMPLEMENT_I2D_BIO(RSA, i2d_RSAPublicKey_bio, i2d_RSAPublicKey) IMPLEMENT_D2I_BIO(RSA, d2i_RSA_PUBKEY_bio, d2i_RSA_PUBKEY) IMPLEMENT_I2D_BIO(RSA, i2d_RSA_PUBKEY_bio, i2d_RSA_PUBKEY) -#ifndef OPENSSL_NO_DSA IMPLEMENT_D2I_FP(DSA, d2i_DSAPrivateKey_fp, d2i_DSAPrivateKey_bio) IMPLEMENT_I2D_FP(DSA, i2d_DSAPrivateKey_fp, i2d_DSAPrivateKey_bio) @@ -253,7 +252,6 @@ IMPLEMENT_I2D_BIO(DSA, i2d_DSAPrivateKey_bio, i2d_DSAPrivateKey) IMPLEMENT_D2I_BIO(DSA, d2i_DSA_PUBKEY_bio, d2i_DSA_PUBKEY) IMPLEMENT_I2D_BIO(DSA, i2d_DSA_PUBKEY_bio, i2d_DSA_PUBKEY) -#endif IMPLEMENT_D2I_FP(EC_KEY, d2i_ECPrivateKey_fp, d2i_ECPrivateKey_bio) IMPLEMENT_I2D_FP(EC_KEY, i2d_ECPrivateKey_fp, i2d_ECPrivateKey_bio) diff --git a/Sources/CNIOBoringSSL/crypto/x509/x_attrib.c b/Sources/CNIOBoringSSL/crypto/x509/x_attrib.c index 435dd2dc..69d26c61 100644 --- a/Sources/CNIOBoringSSL/crypto/x509/x_attrib.c +++ b/Sources/CNIOBoringSSL/crypto/x509/x_attrib.c @@ -67,8 +67,8 @@ ASN1_SEQUENCE(X509_ATTRIBUTE) = { ASN1_SET_OF(X509_ATTRIBUTE, set, ASN1_ANY), } ASN1_SEQUENCE_END(X509_ATTRIBUTE) -IMPLEMENT_ASN1_FUNCTIONS(X509_ATTRIBUTE) -IMPLEMENT_ASN1_DUP_FUNCTION(X509_ATTRIBUTE) +IMPLEMENT_ASN1_FUNCTIONS_const(X509_ATTRIBUTE) +IMPLEMENT_ASN1_DUP_FUNCTION_const(X509_ATTRIBUTE) X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int attrtype, void *value) { ASN1_OBJECT *obj = OBJ_nid2obj(nid); diff --git a/Sources/CNIOBoringSSL/crypto/x509/x_crl.c b/Sources/CNIOBoringSSL/crypto/x509/x_crl.c index 4bc3b5bc..9ed3c2ad 100644 --- a/Sources/CNIOBoringSSL/crypto/x509/x_crl.c +++ b/Sources/CNIOBoringSSL/crypto/x509/x_crl.c @@ -348,9 +348,11 @@ ASN1_SEQUENCE_ref(X509_CRL, crl_cb) = { ASN1_SIMPLE(X509_CRL, signature, ASN1_BIT_STRING), } ASN1_SEQUENCE_END_ref(X509_CRL, X509_CRL) -IMPLEMENT_ASN1_FUNCTIONS(X509_REVOKED) - -IMPLEMENT_ASN1_DUP_FUNCTION(X509_REVOKED) +// Although |X509_REVOKED| contains an |X509_NAME|, it can be const. It is not +// affected by https://crbug.com/boringssl/407 because the |X509_NAME| does +// not participate in serialization. +IMPLEMENT_ASN1_FUNCTIONS_const(X509_REVOKED) +IMPLEMENT_ASN1_DUP_FUNCTION_const(X509_REVOKED) IMPLEMENT_ASN1_FUNCTIONS(X509_CRL_INFO) IMPLEMENT_ASN1_FUNCTIONS(X509_CRL) diff --git a/Sources/CNIOBoringSSL/crypto/x509/x_exten.c b/Sources/CNIOBoringSSL/crypto/x509/x_exten.c index f22ef878..e99397a5 100644 --- a/Sources/CNIOBoringSSL/crypto/x509/x_exten.c +++ b/Sources/CNIOBoringSSL/crypto/x509/x_exten.c @@ -72,7 +72,7 @@ ASN1_ITEM_TEMPLATE(X509_EXTENSIONS) = ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, Extension, X509_EXTENSION) ASN1_ITEM_TEMPLATE_END(X509_EXTENSIONS) -IMPLEMENT_ASN1_FUNCTIONS(X509_EXTENSION) -IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(X509_EXTENSIONS, X509_EXTENSIONS, - X509_EXTENSIONS) -IMPLEMENT_ASN1_DUP_FUNCTION(X509_EXTENSION) +IMPLEMENT_ASN1_FUNCTIONS_const(X509_EXTENSION) +IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(X509_EXTENSIONS, X509_EXTENSIONS, + X509_EXTENSIONS) +IMPLEMENT_ASN1_DUP_FUNCTION_const(X509_EXTENSION) diff --git a/Sources/CNIOBoringSSL/crypto/x509/x_name.c b/Sources/CNIOBoringSSL/crypto/x509/x_name.c index 6ffe4e0c..a6981d02 100644 --- a/Sources/CNIOBoringSSL/crypto/x509/x_name.c +++ b/Sources/CNIOBoringSSL/crypto/x509/x_name.c @@ -99,8 +99,8 @@ ASN1_SEQUENCE(X509_NAME_ENTRY) = { ASN1_SIMPLE(X509_NAME_ENTRY, value, ASN1_PRINTABLE), } ASN1_SEQUENCE_END(X509_NAME_ENTRY) -IMPLEMENT_ASN1_FUNCTIONS(X509_NAME_ENTRY) -IMPLEMENT_ASN1_DUP_FUNCTION(X509_NAME_ENTRY) +IMPLEMENT_ASN1_FUNCTIONS_const(X509_NAME_ENTRY) +IMPLEMENT_ASN1_DUP_FUNCTION_const(X509_NAME_ENTRY) // For the "Name" type we need a SEQUENCE OF { SET OF X509_NAME_ENTRY } so // declare two template wrappers for this diff --git a/Sources/CNIOBoringSSL/crypto/x509/x_pubkey.c b/Sources/CNIOBoringSSL/crypto/x509/x_pubkey.c index 06648a98..2b99be48 100644 --- a/Sources/CNIOBoringSSL/crypto/x509/x_pubkey.c +++ b/Sources/CNIOBoringSSL/crypto/x509/x_pubkey.c @@ -85,7 +85,7 @@ ASN1_SEQUENCE_cb(X509_PUBKEY, pubkey_cb) = { ASN1_SIMPLE(X509_PUBKEY, public_key, ASN1_BIT_STRING), } ASN1_SEQUENCE_END_cb(X509_PUBKEY, X509_PUBKEY) -IMPLEMENT_ASN1_FUNCTIONS(X509_PUBKEY) +IMPLEMENT_ASN1_FUNCTIONS_const(X509_PUBKEY) int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey) { X509_PUBKEY *pk = NULL; diff --git a/Sources/CNIOBoringSSL/crypto/x509/x_req.c b/Sources/CNIOBoringSSL/crypto/x509/x_req.c index adba0e9a..6fbe6a5c 100644 --- a/Sources/CNIOBoringSSL/crypto/x509/x_req.c +++ b/Sources/CNIOBoringSSL/crypto/x509/x_req.c @@ -82,7 +82,11 @@ static int rinf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, } if (operation == ASN1_OP_D2I_POST) { - if (ASN1_INTEGER_get(rinf->version) != X509_REQ_VERSION_1) { + // The only defined CSR version is v1(0). For compatibility, we also accept + // a hypothetical v3(2). Although not defined, older versions of certbot + // use it. See https://github.com/certbot/certbot/pull/9334. + long version = ASN1_INTEGER_get(rinf->version); + if (version != X509_REQ_VERSION_1 && version != 2) { OPENSSL_PUT_ERROR(X509, X509_R_INVALID_VERSION); return 0; } @@ -101,11 +105,11 @@ ASN1_SEQUENCE_enc(X509_REQ_INFO, enc, rinf_cb) = { IMPLEMENT_ASN1_FUNCTIONS(X509_REQ_INFO) -ASN1_SEQUENCE_ref(X509_REQ, 0) = { +ASN1_SEQUENCE(X509_REQ) = { ASN1_SIMPLE(X509_REQ, req_info, X509_REQ_INFO), ASN1_SIMPLE(X509_REQ, sig_alg, X509_ALGOR), ASN1_SIMPLE(X509_REQ, signature, ASN1_BIT_STRING), -} ASN1_SEQUENCE_END_ref(X509_REQ, X509_REQ) +} ASN1_SEQUENCE_END(X509_REQ) IMPLEMENT_ASN1_FUNCTIONS(X509_REQ) diff --git a/Sources/CNIOBoringSSL/crypto/x509/x_sig.c b/Sources/CNIOBoringSSL/crypto/x509/x_sig.c index 795434b7..91c6cfba 100644 --- a/Sources/CNIOBoringSSL/crypto/x509/x_sig.c +++ b/Sources/CNIOBoringSSL/crypto/x509/x_sig.c @@ -71,7 +71,7 @@ ASN1_SEQUENCE(X509_SIG) = { ASN1_SIMPLE(X509_SIG, digest, ASN1_OCTET_STRING), } ASN1_SEQUENCE_END(X509_SIG) -IMPLEMENT_ASN1_FUNCTIONS(X509_SIG) +IMPLEMENT_ASN1_FUNCTIONS_const(X509_SIG) void X509_SIG_get0(const X509_SIG *sig, const X509_ALGOR **out_alg, const ASN1_OCTET_STRING **out_digest) { diff --git a/Sources/CNIOBoringSSL/crypto/x509/x_spki.c b/Sources/CNIOBoringSSL/crypto/x509/x_spki.c index f0ce02c7..2f69ef81 100644 --- a/Sources/CNIOBoringSSL/crypto/x509/x_spki.c +++ b/Sources/CNIOBoringSSL/crypto/x509/x_spki.c @@ -67,7 +67,7 @@ ASN1_SEQUENCE(NETSCAPE_SPKAC) = { ASN1_SIMPLE(NETSCAPE_SPKAC, challenge, ASN1_IA5STRING), } ASN1_SEQUENCE_END(NETSCAPE_SPKAC) -IMPLEMENT_ASN1_FUNCTIONS(NETSCAPE_SPKAC) +IMPLEMENT_ASN1_FUNCTIONS_const(NETSCAPE_SPKAC) ASN1_SEQUENCE(NETSCAPE_SPKI) = { ASN1_SIMPLE(NETSCAPE_SPKI, spkac, NETSCAPE_SPKAC), @@ -75,4 +75,4 @@ ASN1_SEQUENCE(NETSCAPE_SPKI) = { ASN1_SIMPLE(NETSCAPE_SPKI, signature, ASN1_BIT_STRING), } ASN1_SEQUENCE_END(NETSCAPE_SPKI) -IMPLEMENT_ASN1_FUNCTIONS(NETSCAPE_SPKI) +IMPLEMENT_ASN1_FUNCTIONS_const(NETSCAPE_SPKI) diff --git a/Sources/CNIOBoringSSL/crypto/x509/x_val.c b/Sources/CNIOBoringSSL/crypto/x509/x_val.c index 2c617947..06f3799e 100644 --- a/Sources/CNIOBoringSSL/crypto/x509/x_val.c +++ b/Sources/CNIOBoringSSL/crypto/x509/x_val.c @@ -68,4 +68,4 @@ ASN1_SEQUENCE(X509_VAL) = { ASN1_SIMPLE(X509_VAL, notAfter, ASN1_TIME), } ASN1_SEQUENCE_END(X509_VAL) -IMPLEMENT_ASN1_FUNCTIONS(X509_VAL) +IMPLEMENT_ASN1_FUNCTIONS_const(X509_VAL) diff --git a/Sources/CNIOBoringSSL/crypto/x509/x_x509.c b/Sources/CNIOBoringSSL/crypto/x509/x_x509.c index ef9d2ae1..a74bc977 100644 --- a/Sources/CNIOBoringSSL/crypto/x509/x_x509.c +++ b/Sources/CNIOBoringSSL/crypto/x509/x_x509.c @@ -338,11 +338,8 @@ int i2d_X509_tbs(X509 *x509, unsigned char **outp) { } int X509_set1_signature_algo(X509 *x509, const X509_ALGOR *algo) { - // TODO(https://crbug.com/boringssl/407): Generated ASN.1 dup functions - // should be const. Alternatively, when we can embed required fields - // directly in structs, import |X509_ALGOR_copy| from upstream. - X509_ALGOR *copy1 = X509_ALGOR_dup((X509_ALGOR *)algo); - X509_ALGOR *copy2 = X509_ALGOR_dup((X509_ALGOR *)algo); + X509_ALGOR *copy1 = X509_ALGOR_dup(algo); + X509_ALGOR *copy2 = X509_ALGOR_dup(algo); if (copy1 == NULL || copy2 == NULL) { X509_ALGOR_free(copy1); X509_ALGOR_free(copy2); diff --git a/Sources/CNIOBoringSSL/crypto/x509/x_x509a.c b/Sources/CNIOBoringSSL/crypto/x509/x_x509a.c index 0a72f9ed..13f71754 100644 --- a/Sources/CNIOBoringSSL/crypto/x509/x_x509a.c +++ b/Sources/CNIOBoringSSL/crypto/x509/x_x509a.c @@ -78,7 +78,7 @@ ASN1_SEQUENCE(X509_CERT_AUX) = { ASN1_OPT(X509_CERT_AUX, keyid, ASN1_OCTET_STRING), } ASN1_SEQUENCE_END(X509_CERT_AUX) -IMPLEMENT_ASN1_FUNCTIONS(X509_CERT_AUX) +IMPLEMENT_ASN1_FUNCTIONS_const(X509_CERT_AUX) static X509_CERT_AUX *aux_get(X509 *x) { if (!x) { diff --git a/Sources/CNIOBoringSSL/crypto/x509v3/internal.h b/Sources/CNIOBoringSSL/crypto/x509v3/internal.h index 6e6d1a7c..ce909dad 100644 --- a/Sources/CNIOBoringSSL/crypto/x509v3/internal.h +++ b/Sources/CNIOBoringSSL/crypto/x509v3/internal.h @@ -65,6 +65,11 @@ #include #include +// TODO(davidben): Merge x509 and x509v3. This include is needed because some +// internal typedefs are shared between the two, but the two modules depend on +// each other circularly. +#include "../x509/internal.h" + #if defined(__cplusplus) extern "C" { #endif @@ -122,9 +127,6 @@ 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 @@ -133,6 +135,12 @@ DEFINE_STACK_OF(X509_POLICY_DATA) // X509_POLICY_NODE contains that. This means that the main policy data can // be kept static and cached with the certificate. +typedef struct X509_POLICY_DATA_st X509_POLICY_DATA; +typedef struct X509_POLICY_LEVEL_st X509_POLICY_LEVEL; +typedef struct X509_POLICY_NODE_st X509_POLICY_NODE; + +DEFINE_STACK_OF(X509_POLICY_DATA) + struct X509_POLICY_DATA_st { unsigned int flags; // Policy OID and qualifiers for this data @@ -199,6 +207,8 @@ struct X509_POLICY_NODE_st { int nchild; }; +DEFINE_STACK_OF(X509_POLICY_NODE) + struct X509_POLICY_LEVEL_st { // Cert for this level X509 *cert; @@ -235,6 +245,14 @@ struct X509_POLICY_TREE_st { // Internal functions +void X509_POLICY_NODE_print(BIO *out, X509_POLICY_NODE *node, int indent); + +int X509_policy_check(X509_POLICY_TREE **ptree, int *pexplicit_policy, + STACK_OF(X509) *certs, STACK_OF(ASN1_OBJECT) *policy_oids, + unsigned int flags); + +void X509_policy_tree_free(X509_POLICY_TREE *tree); + X509_POLICY_DATA *policy_data_new(POLICYINFO *policy, const ASN1_OBJECT *id, int crit); void policy_data_free(X509_POLICY_DATA *data); diff --git a/Sources/CNIOBoringSSL/crypto/x509v3/pcy_lib.c b/Sources/CNIOBoringSSL/crypto/x509v3/pcy_lib.c deleted file mode 100644 index a2d747ed..00000000 --- a/Sources/CNIOBoringSSL/crypto/x509v3/pcy_lib.c +++ /dev/null @@ -1,156 +0,0 @@ -/* pcy_lib.c */ -/* - * 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). */ - -#include -#include - -#include "internal.h" - -// accessor functions - -// X509_POLICY_TREE stuff - -int X509_policy_tree_level_count(const X509_POLICY_TREE *tree) { - if (!tree) { - return 0; - } - return tree->nlevel; -} - -X509_POLICY_LEVEL *X509_policy_tree_get0_level(const X509_POLICY_TREE *tree, - int i) { - if (!tree || (i < 0) || (i >= tree->nlevel)) { - return NULL; - } - return tree->levels + i; -} - -STACK_OF(X509_POLICY_NODE) *X509_policy_tree_get0_policies( - const X509_POLICY_TREE *tree) { - if (!tree) { - return NULL; - } - return tree->auth_policies; -} - -STACK_OF(X509_POLICY_NODE) *X509_policy_tree_get0_user_policies( - const X509_POLICY_TREE *tree) { - if (!tree) { - return NULL; - } - if (tree->flags & POLICY_FLAG_ANY_POLICY) { - return tree->auth_policies; - } else { - return tree->user_policies; - } -} - -// X509_POLICY_LEVEL stuff - -int X509_policy_level_node_count(X509_POLICY_LEVEL *level) { - int n; - if (!level) { - return 0; - } - if (level->anyPolicy) { - n = 1; - } else { - n = 0; - } - if (level->nodes) { - n += sk_X509_POLICY_NODE_num(level->nodes); - } - return n; -} - -X509_POLICY_NODE *X509_policy_level_get0_node(X509_POLICY_LEVEL *level, int i) { - if (!level) { - return NULL; - } - if (level->anyPolicy) { - if (i == 0) { - return level->anyPolicy; - } - i--; - } - return sk_X509_POLICY_NODE_value(level->nodes, i); -} - -// X509_POLICY_NODE stuff - -const ASN1_OBJECT *X509_policy_node_get0_policy(const X509_POLICY_NODE *node) { - if (!node) { - return NULL; - } - return node->data->valid_policy; -} - -STACK_OF(POLICYQUALINFO) *X509_policy_node_get0_qualifiers( - const X509_POLICY_NODE *node) { - if (!node) { - return NULL; - } - return node->data->qualifier_set; -} - -const X509_POLICY_NODE *X509_policy_node_get0_parent( - const X509_POLICY_NODE *node) { - if (!node) { - return NULL; - } - return node->parent; -} diff --git a/Sources/CNIOBoringSSL/crypto/x509v3/pcy_tree.c b/Sources/CNIOBoringSSL/crypto/x509v3/pcy_tree.c index 7a807004..2c7a05c2 100644 --- a/Sources/CNIOBoringSSL/crypto/x509v3/pcy_tree.c +++ b/Sources/CNIOBoringSSL/crypto/x509v3/pcy_tree.c @@ -811,7 +811,11 @@ int X509_policy_check(X509_POLICY_TREE **ptree, int *pexplicit_policy, } if (*pexplicit_policy) { - nodes = X509_policy_tree_get0_user_policies(tree); + if (tree->flags & POLICY_FLAG_ANY_POLICY) { + nodes = tree->auth_policies; + } else { + nodes = tree->user_policies; + } if (sk_X509_POLICY_NODE_num(nodes) <= 0) { return -2; } @@ -820,8 +824,6 @@ int X509_policy_check(X509_POLICY_TREE **ptree, int *pexplicit_policy, return 1; error: - X509_policy_tree_free(tree); - return 0; } diff --git a/Sources/CNIOBoringSSL/crypto/x509v3/v3_akey.c b/Sources/CNIOBoringSSL/crypto/x509v3/v3_akey.c index 6a6d7f22..6c31715e 100644 --- a/Sources/CNIOBoringSSL/crypto/x509v3/v3_akey.c +++ b/Sources/CNIOBoringSSL/crypto/x509v3/v3_akey.c @@ -143,7 +143,6 @@ static void *v2i_AUTHORITY_KEYID(const X509V3_EXT_METHOD *method, GENERAL_NAMES *gens = NULL; GENERAL_NAME *gen = NULL; ASN1_INTEGER *serial = NULL; - X509_EXTENSION *ext; X509 *cert; AUTHORITY_KEYID *akeyid; @@ -178,6 +177,7 @@ static void *v2i_AUTHORITY_KEYID(const X509V3_EXT_METHOD *method, if (keyid) { j = X509_get_ext_by_NID(cert, NID_subject_key_identifier, -1); + const X509_EXTENSION *ext; if ((j >= 0) && (ext = X509_get_ext(cert, j))) { ikeyid = X509V3_EXT_d2i(ext); } diff --git a/Sources/CNIOBoringSSL/crypto/x509v3/v3_bcons.c b/Sources/CNIOBoringSSL/crypto/x509v3/v3_bcons.c index fef8f157..2415d4ba 100644 --- a/Sources/CNIOBoringSSL/crypto/x509v3/v3_bcons.c +++ b/Sources/CNIOBoringSSL/crypto/x509v3/v3_bcons.c @@ -93,7 +93,7 @@ ASN1_SEQUENCE(BASIC_CONSTRAINTS) = { ASN1_OPT(BASIC_CONSTRAINTS, pathlen, ASN1_INTEGER), } ASN1_SEQUENCE_END(BASIC_CONSTRAINTS) -IMPLEMENT_ASN1_FUNCTIONS(BASIC_CONSTRAINTS) +IMPLEMENT_ASN1_FUNCTIONS_const(BASIC_CONSTRAINTS) static STACK_OF(CONF_VALUE) *i2v_BASIC_CONSTRAINTS( const X509V3_EXT_METHOD *method, void *ext, STACK_OF(CONF_VALUE) *extlist) { diff --git a/Sources/CNIOBoringSSL/crypto/x509v3/v3_cpols.c b/Sources/CNIOBoringSSL/crypto/x509v3/v3_cpols.c index 3cdf2c25..d7a6746c 100644 --- a/Sources/CNIOBoringSSL/crypto/x509v3/v3_cpols.c +++ b/Sources/CNIOBoringSSL/crypto/x509v3/v3_cpols.c @@ -107,14 +107,14 @@ ASN1_ITEM_TEMPLATE(CERTIFICATEPOLICIES) = ASN1_EX_TEMPLATE_TYPE( ASN1_TFLG_SEQUENCE_OF, 0, CERTIFICATEPOLICIES, POLICYINFO) ASN1_ITEM_TEMPLATE_END(CERTIFICATEPOLICIES) -IMPLEMENT_ASN1_FUNCTIONS(CERTIFICATEPOLICIES) +IMPLEMENT_ASN1_FUNCTIONS_const(CERTIFICATEPOLICIES) ASN1_SEQUENCE(POLICYINFO) = { ASN1_SIMPLE(POLICYINFO, policyid, ASN1_OBJECT), ASN1_SEQUENCE_OF_OPT(POLICYINFO, qualifiers, POLICYQUALINFO), } ASN1_SEQUENCE_END(POLICYINFO) -IMPLEMENT_ASN1_FUNCTIONS(POLICYINFO) +IMPLEMENT_ASN1_FUNCTIONS_const(POLICYINFO) ASN1_ADB_TEMPLATE(policydefault) = ASN1_SIMPLE(POLICYQUALINFO, d.other, ASN1_ANY); @@ -131,21 +131,21 @@ ASN1_SEQUENCE(POLICYQUALINFO) = { ASN1_ADB_OBJECT(POLICYQUALINFO), } ASN1_SEQUENCE_END(POLICYQUALINFO) -IMPLEMENT_ASN1_FUNCTIONS(POLICYQUALINFO) +IMPLEMENT_ASN1_FUNCTIONS_const(POLICYQUALINFO) ASN1_SEQUENCE(USERNOTICE) = { ASN1_OPT(USERNOTICE, noticeref, NOTICEREF), ASN1_OPT(USERNOTICE, exptext, DISPLAYTEXT), } ASN1_SEQUENCE_END(USERNOTICE) -IMPLEMENT_ASN1_FUNCTIONS(USERNOTICE) +IMPLEMENT_ASN1_FUNCTIONS_const(USERNOTICE) ASN1_SEQUENCE(NOTICEREF) = { ASN1_SIMPLE(NOTICEREF, organization, DISPLAYTEXT), ASN1_SEQUENCE_OF(NOTICEREF, noticenos, ASN1_INTEGER), } ASN1_SEQUENCE_END(NOTICEREF) -IMPLEMENT_ASN1_FUNCTIONS(NOTICEREF) +IMPLEMENT_ASN1_FUNCTIONS_const(NOTICEREF) static void *r2i_certpol(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx, const char *value) { diff --git a/Sources/CNIOBoringSSL/crypto/x509v3/v3_extku.c b/Sources/CNIOBoringSSL/crypto/x509v3/v3_extku.c index df3d1353..6ead258f 100644 --- a/Sources/CNIOBoringSSL/crypto/x509v3/v3_extku.c +++ b/Sources/CNIOBoringSSL/crypto/x509v3/v3_extku.c @@ -108,7 +108,7 @@ ASN1_ITEM_TEMPLATE(EXTENDED_KEY_USAGE) = ASN1_EX_TEMPLATE_TYPE( ASN1_TFLG_SEQUENCE_OF, 0, EXTENDED_KEY_USAGE, ASN1_OBJECT) ASN1_ITEM_TEMPLATE_END(EXTENDED_KEY_USAGE) -IMPLEMENT_ASN1_FUNCTIONS(EXTENDED_KEY_USAGE) +IMPLEMENT_ASN1_FUNCTIONS_const(EXTENDED_KEY_USAGE) static STACK_OF(CONF_VALUE) *i2v_EXTENDED_KEY_USAGE( const X509V3_EXT_METHOD *method, void *a, STACK_OF(CONF_VALUE) *ext_list) { diff --git a/Sources/CNIOBoringSSL/crypto/x509v3/v3_genn.c b/Sources/CNIOBoringSSL/crypto/x509v3/v3_genn.c index 7f7e2320..581356c9 100644 --- a/Sources/CNIOBoringSSL/crypto/x509v3/v3_genn.c +++ b/Sources/CNIOBoringSSL/crypto/x509v3/v3_genn.c @@ -69,7 +69,7 @@ ASN1_SEQUENCE(OTHERNAME) = { ASN1_EXP(OTHERNAME, value, ASN1_ANY, 0), } ASN1_SEQUENCE_END(OTHERNAME) -IMPLEMENT_ASN1_FUNCTIONS(OTHERNAME) +IMPLEMENT_ASN1_FUNCTIONS_const(OTHERNAME) ASN1_SEQUENCE(EDIPARTYNAME) = { // DirectoryString is a CHOICE type, so use explicit tagging. @@ -77,7 +77,7 @@ ASN1_SEQUENCE(EDIPARTYNAME) = { ASN1_EXP(EDIPARTYNAME, partyName, DIRECTORYSTRING, 1), } ASN1_SEQUENCE_END(EDIPARTYNAME) -IMPLEMENT_ASN1_FUNCTIONS(EDIPARTYNAME) +IMPLEMENT_ASN1_FUNCTIONS_const(EDIPARTYNAME) ASN1_CHOICE(GENERAL_NAME) = { ASN1_IMP(GENERAL_NAME, d.otherName, OTHERNAME, GEN_OTHERNAME), diff --git a/Sources/CNIOBoringSSL/crypto/x509v3/v3_lib.c b/Sources/CNIOBoringSSL/crypto/x509v3/v3_lib.c index 921d5c70..8df23e06 100644 --- a/Sources/CNIOBoringSSL/crypto/x509v3/v3_lib.c +++ b/Sources/CNIOBoringSSL/crypto/x509v3/v3_lib.c @@ -316,9 +316,11 @@ int X509V3_add1_i2d(STACK_OF(X509_EXTENSION) **x, int nid, void *value, } // If delete, just delete it if (ext_op == X509V3_ADD_DELETE) { - if (!sk_X509_EXTENSION_delete(*x, extidx)) { + X509_EXTENSION *prev_ext = sk_X509_EXTENSION_delete(*x, extidx); + if (prev_ext == NULL) { return -1; } + X509_EXTENSION_free(prev_ext); return 1; } } else { diff --git a/Sources/CNIOBoringSSL/crypto/x509v3/v3_ncons.c b/Sources/CNIOBoringSSL/crypto/x509v3/v3_ncons.c index a07a5710..9683785d 100644 --- a/Sources/CNIOBoringSSL/crypto/x509v3/v3_ncons.c +++ b/Sources/CNIOBoringSSL/crypto/x509v3/v3_ncons.c @@ -76,14 +76,14 @@ static int i2r_NAME_CONSTRAINTS(const X509V3_EXT_METHOD *method, void *a, static int do_i2r_name_constraints(const X509V3_EXT_METHOD *method, STACK_OF(GENERAL_SUBTREE) *trees, BIO *bp, int ind, const char *name); -static int print_nc_ipadd(BIO *bp, ASN1_OCTET_STRING *ip); +static int print_nc_ipadd(BIO *bp, const ASN1_OCTET_STRING *ip); static int nc_match(GENERAL_NAME *gen, NAME_CONSTRAINTS *nc); static int nc_match_single(GENERAL_NAME *sub, GENERAL_NAME *gen); static int nc_dn(X509_NAME *sub, X509_NAME *nm); -static int nc_dns(ASN1_IA5STRING *sub, ASN1_IA5STRING *dns); -static int nc_email(ASN1_IA5STRING *sub, ASN1_IA5STRING *eml); -static int nc_uri(ASN1_IA5STRING *uri, ASN1_IA5STRING *base); +static int nc_dns(const ASN1_IA5STRING *sub, const ASN1_IA5STRING *dns); +static int nc_email(const ASN1_IA5STRING *sub, const ASN1_IA5STRING *eml); +static int nc_uri(const ASN1_IA5STRING *uri, const ASN1_IA5STRING *base); const X509V3_EXT_METHOD v3_name_constraints = { NID_name_constraints, @@ -196,7 +196,7 @@ static int do_i2r_name_constraints(const X509V3_EXT_METHOD *method, return 1; } -static int print_nc_ipadd(BIO *bp, ASN1_OCTET_STRING *ip) { +static int print_nc_ipadd(BIO *bp, const ASN1_OCTET_STRING *ip) { int i, len; unsigned char *p; p = ip->data; @@ -273,12 +273,11 @@ int NAME_CONSTRAINTS_check(X509 *x, NAME_CONSTRAINTS *nc) { // Process any email address attributes in subject name for (i = -1;;) { - X509_NAME_ENTRY *ne; i = X509_NAME_get_index_by_NID(nm, NID_pkcs9_emailAddress, i); if (i == -1) { break; } - ne = X509_NAME_get_entry(nm, i); + const X509_NAME_ENTRY *ne = X509_NAME_get_entry(nm, i); gntmp.d.rfc822Name = X509_NAME_ENTRY_get_data(ne); if (gntmp.d.rfc822Name->type != V_ASN1_IA5STRING) { return X509_V_ERR_UNSUPPORTED_NAME_SYNTAX; @@ -429,7 +428,7 @@ static int has_suffix_case(const CBS *a, const CBS *b) { return equal_case(©, b); } -static int nc_dns(ASN1_IA5STRING *dns, ASN1_IA5STRING *base) { +static int nc_dns(const ASN1_IA5STRING *dns, const ASN1_IA5STRING *base) { CBS dns_cbs, base_cbs; CBS_init(&dns_cbs, dns->data, dns->length); CBS_init(&base_cbs, base->data, base->length); @@ -465,7 +464,7 @@ static int nc_dns(ASN1_IA5STRING *dns, ASN1_IA5STRING *base) { return X509_V_OK; } -static int nc_email(ASN1_IA5STRING *eml, ASN1_IA5STRING *base) { +static int nc_email(const ASN1_IA5STRING *eml, const ASN1_IA5STRING *base) { CBS eml_cbs, base_cbs; CBS_init(&eml_cbs, eml->data, eml->length); CBS_init(&base_cbs, base->data, base->length); @@ -479,7 +478,7 @@ static int nc_email(ASN1_IA5STRING *eml, ASN1_IA5STRING *base) { } int base_has_at = CBS_get_until_first(&base_cbs, &base_local, '@'); - // Special case: inital '.' is RHS match + // Special case: initial '.' is RHS match if (!base_has_at && starts_with(&base_cbs, '.')) { if (has_suffix_case(&eml_cbs, &base_cbs)) { return X509_V_OK; @@ -513,7 +512,7 @@ static int nc_email(ASN1_IA5STRING *eml, ASN1_IA5STRING *base) { return X509_V_OK; } -static int nc_uri(ASN1_IA5STRING *uri, ASN1_IA5STRING *base) { +static int nc_uri(const ASN1_IA5STRING *uri, const ASN1_IA5STRING *base) { CBS uri_cbs, base_cbs; CBS_init(&uri_cbs, uri->data, uri->length); CBS_init(&base_cbs, base->data, base->length); @@ -542,7 +541,7 @@ static int nc_uri(ASN1_IA5STRING *uri, ASN1_IA5STRING *base) { return X509_V_ERR_UNSUPPORTED_NAME_SYNTAX; } - // Special case: inital '.' is RHS match + // Special case: initial '.' is RHS match if (starts_with(&base_cbs, '.')) { if (has_suffix_case(&host, &base_cbs)) { return X509_V_OK; diff --git a/Sources/CNIOBoringSSL/crypto/x509v3/v3_pcia.c b/Sources/CNIOBoringSSL/crypto/x509v3/v3_pcia.c index 3d0a15ff..57762a3f 100644 --- a/Sources/CNIOBoringSSL/crypto/x509v3/v3_pcia.c +++ b/Sources/CNIOBoringSSL/crypto/x509v3/v3_pcia.c @@ -45,11 +45,11 @@ ASN1_SEQUENCE(PROXY_POLICY) = { ASN1_OPT(PROXY_POLICY, policy, ASN1_OCTET_STRING), } ASN1_SEQUENCE_END(PROXY_POLICY) -IMPLEMENT_ASN1_FUNCTIONS(PROXY_POLICY) +IMPLEMENT_ASN1_FUNCTIONS_const(PROXY_POLICY) ASN1_SEQUENCE(PROXY_CERT_INFO_EXTENSION) = { ASN1_OPT(PROXY_CERT_INFO_EXTENSION, pcPathLengthConstraint, ASN1_INTEGER), ASN1_SIMPLE(PROXY_CERT_INFO_EXTENSION, proxyPolicy, PROXY_POLICY), } ASN1_SEQUENCE_END(PROXY_CERT_INFO_EXTENSION) -IMPLEMENT_ASN1_FUNCTIONS(PROXY_CERT_INFO_EXTENSION) +IMPLEMENT_ASN1_FUNCTIONS_const(PROXY_CERT_INFO_EXTENSION) diff --git a/Sources/CNIOBoringSSL/crypto/x509v3/v3_prn.c b/Sources/CNIOBoringSSL/crypto/x509v3/v3_prn.c index f08b233f..13f91d06 100644 --- a/Sources/CNIOBoringSSL/crypto/x509v3/v3_prn.c +++ b/Sources/CNIOBoringSSL/crypto/x509v3/v3_prn.c @@ -66,15 +66,13 @@ // Extension printing routines -static int unknown_ext_print(BIO *out, X509_EXTENSION *ext, unsigned long flag, - int indent, int supported); +static int unknown_ext_print(BIO *out, const X509_EXTENSION *ext, + unsigned long flag, int indent, int supported); // Print out a name+value stack -void X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, int indent, +void X509V3_EXT_val_prn(BIO *out, const STACK_OF(CONF_VALUE) *val, int indent, int ml) { - size_t i; - CONF_VALUE *nval; if (!val) { return; } @@ -84,13 +82,13 @@ void X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, int indent, BIO_puts(out, "\n"); } } - for (i = 0; i < sk_CONF_VALUE_num(val); i++) { + for (size_t i = 0; i < sk_CONF_VALUE_num(val); i++) { if (ml) { BIO_printf(out, "%*s", indent, ""); } else if (i > 0) { BIO_printf(out, ", "); } - nval = sk_CONF_VALUE_value(val, i); + const CONF_VALUE *nval = sk_CONF_VALUE_value(val, i); if (!nval->name) { BIO_puts(out, nval->value); } else if (!nval->value) { @@ -106,7 +104,7 @@ void X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, int indent, // Main routine: print out a general extension -int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, unsigned long flag, +int X509V3_EXT_print(BIO *out, const X509_EXTENSION *ext, unsigned long flag, int indent) { void *ext_str = NULL; char *value = NULL; @@ -180,13 +178,11 @@ int X509V3_extensions_print(BIO *bp, const char *title, } for (i = 0; i < sk_X509_EXTENSION_num(exts); i++) { - ASN1_OBJECT *obj; - X509_EXTENSION *ex; - ex = sk_X509_EXTENSION_value(exts, i); + const X509_EXTENSION *ex = sk_X509_EXTENSION_value(exts, i); if (indent && BIO_printf(bp, "%*s", indent, "") <= 0) { return 0; } - obj = X509_EXTENSION_get_object(ex); + const ASN1_OBJECT *obj = X509_EXTENSION_get_object(ex); i2a_ASN1_OBJECT(bp, obj); j = X509_EXTENSION_get_critical(ex); if (BIO_printf(bp, ": %s\n", j ? "critical" : "") <= 0) { @@ -203,8 +199,8 @@ int X509V3_extensions_print(BIO *bp, const char *title, return 1; } -static int unknown_ext_print(BIO *out, X509_EXTENSION *ext, unsigned long flag, - int indent, int supported) { +static int unknown_ext_print(BIO *out, const X509_EXTENSION *ext, + unsigned long flag, int indent, int supported) { switch (flag & X509V3_EXT_UNKNOWN_MASK) { case X509V3_EXT_DEFAULT: return 0; @@ -229,7 +225,8 @@ static int unknown_ext_print(BIO *out, X509_EXTENSION *ext, unsigned long flag, } } -int X509V3_EXT_print_fp(FILE *fp, X509_EXTENSION *ext, int flag, int indent) { +int X509V3_EXT_print_fp(FILE *fp, const X509_EXTENSION *ext, int flag, + int indent) { BIO *bio_tmp; int ret; if (!(bio_tmp = BIO_new_fp(fp, BIO_NOCLOSE))) { diff --git a/Sources/CNIOBoringSSL/crypto/x509v3/v3_purp.c b/Sources/CNIOBoringSSL/crypto/x509v3/v3_purp.c index 1c23a1dd..e4b8e816 100644 --- a/Sources/CNIOBoringSSL/crypto/x509v3/v3_purp.c +++ b/Sources/CNIOBoringSSL/crypto/x509v3/v3_purp.c @@ -320,7 +320,7 @@ static int nid_cmp(const void *void_a, const void *void_b) { return *a - *b; } -int X509_supported_extension(X509_EXTENSION *ex) { +int X509_supported_extension(const X509_EXTENSION *ex) { // This table is a list of the NIDs of supported extensions: that is // those which are used by the verify process. If an extension is // critical and doesn't appear in this list then the verify process will @@ -405,7 +405,6 @@ int x509v3_cache_extensions(X509 *x) { ASN1_BIT_STRING *usage; ASN1_BIT_STRING *ns; EXTENDED_KEY_USAGE *extusage; - X509_EXTENSION *ex; size_t i; int j; @@ -576,7 +575,7 @@ int x509v3_cache_extensions(X509 *x) { } for (j = 0; j < X509_get_ext_count(x); j++) { - ex = X509_get_ext(x, j); + const X509_EXTENSION *ex = X509_get_ext(x, j); if (OBJ_obj2nid(X509_EXTENSION_get_object(ex)) == NID_freshest_crl) { x->ex_flags |= EXFLAG_FRESHEST; } @@ -768,7 +767,7 @@ static int check_purpose_timestamp_sign(const X509_PURPOSE *xp, const X509 *x, // Extended Key Usage MUST be critical i_ext = X509_get_ext_by_NID((X509 *)x, NID_ext_key_usage, -1); if (i_ext >= 0) { - X509_EXTENSION *ext = X509_get_ext((X509 *)x, i_ext); + const X509_EXTENSION *ext = X509_get_ext((X509 *)x, i_ext); if (!X509_EXTENSION_get_critical(ext)) { return 0; } diff --git a/Sources/CNIOBoringSSL/crypto/x509v3/v3_utl.c b/Sources/CNIOBoringSSL/crypto/x509v3/v3_utl.c index 24eb863f..57c2c60b 100644 --- a/Sources/CNIOBoringSSL/crypto/x509v3/v3_utl.c +++ b/Sources/CNIOBoringSSL/crypto/x509v3/v3_utl.c @@ -77,10 +77,11 @@ static char *strip_spaces(char *name); static int sk_strcmp(const char **a, const char **b); -static STACK_OF(OPENSSL_STRING) *get_email(X509_NAME *name, - GENERAL_NAMES *gens); +static STACK_OF(OPENSSL_STRING) *get_email(const X509_NAME *name, + const GENERAL_NAMES *gens); static void str_free(OPENSSL_STRING str); -static int append_ia5(STACK_OF(OPENSSL_STRING) **sk, ASN1_IA5STRING *email); +static int append_ia5(STACK_OF(OPENSSL_STRING) **sk, + const ASN1_IA5STRING *email); static int ipv4_from_asc(unsigned char v4[4], const char *in); static int ipv6_from_asc(unsigned char v6[16], const char *in); @@ -617,27 +618,22 @@ STACK_OF(OPENSSL_STRING) *X509_REQ_get1_email(X509_REQ *x) { return ret; } -static STACK_OF(OPENSSL_STRING) *get_email(X509_NAME *name, - GENERAL_NAMES *gens) { +static STACK_OF(OPENSSL_STRING) *get_email(const X509_NAME *name, + const GENERAL_NAMES *gens) { STACK_OF(OPENSSL_STRING) *ret = NULL; - X509_NAME_ENTRY *ne; - ASN1_IA5STRING *email; - GENERAL_NAME *gen; - int i; - size_t j; // Now add any email address(es) to STACK - i = -1; + int i = -1; // First supplied X509_NAME while ((i = X509_NAME_get_index_by_NID(name, NID_pkcs9_emailAddress, i)) >= 0) { - ne = X509_NAME_get_entry(name, i); - email = X509_NAME_ENTRY_get_data(ne); + const X509_NAME_ENTRY *ne = X509_NAME_get_entry(name, i); + const ASN1_IA5STRING *email = X509_NAME_ENTRY_get_data(ne); if (!append_ia5(&ret, email)) { return NULL; } } - for (j = 0; j < sk_GENERAL_NAME_num(gens); j++) { - gen = sk_GENERAL_NAME_value(gens, j); + for (size_t j = 0; j < sk_GENERAL_NAME_num(gens); j++) { + const GENERAL_NAME *gen = sk_GENERAL_NAME_value(gens, j); if (gen->type != GEN_EMAIL) { continue; } @@ -650,7 +646,8 @@ static STACK_OF(OPENSSL_STRING) *get_email(X509_NAME *name, static void str_free(OPENSSL_STRING str) { OPENSSL_free(str); } -static int append_ia5(STACK_OF(OPENSSL_STRING) **sk, ASN1_IA5STRING *email) { +static int append_ia5(STACK_OF(OPENSSL_STRING) **sk, + const ASN1_IA5STRING *email) { // First some sanity checks if (email->type != V_ASN1_IA5STRING) { return 1; @@ -952,7 +949,7 @@ int x509v3_looks_like_dns_name(const unsigned char *in, size_t len) { // cmp_type > 0 only compare if string matches the type, otherwise convert it // to UTF8. -static int do_check_string(ASN1_STRING *a, int cmp_type, equal_fn equal, +static int do_check_string(const ASN1_STRING *a, int cmp_type, equal_fn equal, unsigned int flags, int check_type, const char *b, size_t blen, char **peername) { int rv = 0; @@ -997,15 +994,10 @@ static int do_check_string(ASN1_STRING *a, int cmp_type, equal_fn equal, static int do_x509_check(X509 *x, const char *chk, size_t chklen, unsigned int flags, int check_type, char **peername) { - GENERAL_NAMES *gens = NULL; - X509_NAME *name = NULL; - size_t i; - int j; int cnid = NID_undef; int alt_type; int rv = 0; equal_fn equal; - if (check_type == GEN_EMAIL) { cnid = NID_pkcs9_emailAddress; alt_type = V_ASN1_IA5STRING; @@ -1023,15 +1015,14 @@ static int do_x509_check(X509 *x, const char *chk, size_t chklen, equal = equal_case; } - gens = X509_get_ext_d2i(x, NID_subject_alt_name, NULL, NULL); + GENERAL_NAMES *gens = X509_get_ext_d2i(x, NID_subject_alt_name, NULL, NULL); if (gens) { - for (i = 0; i < sk_GENERAL_NAME_num(gens); i++) { - GENERAL_NAME *gen; - ASN1_STRING *cstr; - gen = sk_GENERAL_NAME_value(gens, i); + for (size_t i = 0; i < sk_GENERAL_NAME_num(gens); i++) { + const GENERAL_NAME *gen = sk_GENERAL_NAME_value(gens, i); if (gen->type != check_type) { continue; } + const ASN1_STRING *cstr; if (check_type == GEN_EMAIL) { cstr = gen->d.rfc822Name; } else if (check_type == GEN_DNS) { @@ -1054,13 +1045,11 @@ static int do_x509_check(X509 *x, const char *chk, size_t chklen, return 0; } - j = -1; - name = X509_get_subject_name(x); + int j = -1; + const X509_NAME *name = X509_get_subject_name(x); while ((j = X509_NAME_get_index_by_NID(name, cnid, j)) >= 0) { - X509_NAME_ENTRY *ne; - ASN1_STRING *str; - ne = X509_NAME_get_entry(name, j); - str = X509_NAME_ENTRY_get_data(ne); + const X509_NAME_ENTRY *ne = X509_NAME_get_entry(name, j); + const ASN1_STRING *str = X509_NAME_ENTRY_get_data(ne); // Positive on success, negative on error! if ((rv = do_check_string(str, -1, equal, flags, check_type, chk, chklen, peername)) != 0) { @@ -1244,8 +1233,6 @@ static int ipv6_from_asc(unsigned char v6[16], const char *in) { return 0; } - // Now for some sanity checks - if (v6stat.zero_pos == -1) { // If no '::' must have exactly 16 bytes if (v6stat.total != 16) { @@ -1253,35 +1240,31 @@ static int ipv6_from_asc(unsigned char v6[16], const char *in) { } } else { // If '::' must have less than 16 bytes - if (v6stat.total == 16) { + if (v6stat.total >= 16) { return 0; } - // More than three zeroes is an error if (v6stat.zero_cnt > 3) { + // More than three zeroes is an error return 0; - } - // Can only have three zeroes if nothing else present - else if (v6stat.zero_cnt == 3) { + } else if (v6stat.zero_cnt == 3) { + // Can only have three zeroes if nothing else present if (v6stat.total > 0) { return 0; } - } - // Can only have two zeroes if at start or end - else if (v6stat.zero_cnt == 2) { - if ((v6stat.zero_pos != 0) && (v6stat.zero_pos != v6stat.total)) { + } else if (v6stat.zero_cnt == 2) { + // Can only have two zeroes if at start or end + if (v6stat.zero_pos != 0 && v6stat.zero_pos != v6stat.total) { return 0; } - } else - // Can only have one zero if *not* start or end - { - if ((v6stat.zero_pos == 0) || (v6stat.zero_pos == v6stat.total)) { + } else { + // Can only have one zero if *not* start or end + if (v6stat.zero_pos == 0 || v6stat.zero_pos == v6stat.total) { return 0; } } } - // Format result - + // Format the result. if (v6stat.zero_pos >= 0) { // Copy initial part OPENSSL_memcpy(v6, v6stat.tmp, v6stat.zero_pos); @@ -1310,9 +1293,12 @@ static int ipv6_cb(const char *elem, int len, void *usr) { // Zero length element, corresponds to '::' if (s->zero_pos == -1) { s->zero_pos = s->total; + } else if (s->zero_pos != s->total) { + // If we've already got a :: its an error + return 0; } - // If we've already got a :: its an error - else if (s->zero_pos != s->total) { + if (s->zero_cnt >= 3) { + // More than three zeros is an error. return 0; } s->zero_cnt++; diff --git a/Sources/CNIOBoringSSL/hash.txt b/Sources/CNIOBoringSSL/hash.txt index 98dba952..ac7c6f97 100644 --- a/Sources/CNIOBoringSSL/hash.txt +++ b/Sources/CNIOBoringSSL/hash.txt @@ -1 +1 @@ -This directory is derived from BoringSSL cloned from https://boringssl.googlesource.com/boringssl at revision c239ffd0552179f358de31517391679e9b62ccd3 +This directory is derived from BoringSSL cloned from https://boringssl.googlesource.com/boringssl at revision 8462a367bb57e9524c3d8eca9c62733c63a63cf4 diff --git a/Sources/CNIOBoringSSL/include/CNIOBoringSSL.h b/Sources/CNIOBoringSSL/include/CNIOBoringSSL.h index 848ca7aa..a81cb690 100644 --- a/Sources/CNIOBoringSSL/include/CNIOBoringSSL.h +++ b/Sources/CNIOBoringSSL/include/CNIOBoringSSL.h @@ -26,6 +26,7 @@ #include "CNIOBoringSSL_boringssl_prefix_symbols_asm.h" #include "CNIOBoringSSL_cast.h" #include "CNIOBoringSSL_chacha.h" +#include "CNIOBoringSSL_ctrdrbg.h" #include "CNIOBoringSSL_cmac.h" #include "CNIOBoringSSL_conf.h" #include "CNIOBoringSSL_cpu.h" @@ -62,6 +63,7 @@ #include "CNIOBoringSSL_srtp.h" #include "CNIOBoringSSL_ssl.h" #include "CNIOBoringSSL_trust_token.h" +#include "CNIOBoringSSL_type_check.h" #include "CNIOBoringSSL_x509_vfy.h" #include "CNIOBoringSSL_x509v3.h" diff --git a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_aead.h b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_aead.h index 71631212..4e5cd9dc 100644 --- a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_aead.h +++ b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_aead.h @@ -180,6 +180,10 @@ OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_ccm_bluetooth(void); // v1.0. OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_ccm_bluetooth_8(void); +// EVP_aead_aes_128_ccm_matter is AES-128-CCM with M=16 and L=2 (16-byte tags +// and 13-byte nonces), as used in the Matter specification. +OPENSSL_EXPORT const EVP_AEAD *EVP_aead_aes_128_ccm_matter(void); + // EVP_has_aes_hardware returns one if we enable hardware support for fast and // constant-time AES-GCM. OPENSSL_EXPORT int EVP_has_aes_hardware(void); diff --git a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_asn1.h b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_asn1.h index d5f9f34c..64b13aba 100644 --- a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_asn1.h +++ b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_asn1.h @@ -1379,6 +1379,15 @@ OPENSSL_EXPORT ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime( // GeneralizedTime. If |str| is neither, it returns zero. OPENSSL_EXPORT int ASN1_TIME_set_string(ASN1_TIME *s, const char *str); +// ASN1_TIME_to_time_t converts |t| to a time_t value in |out|. On +// success, one is returned. On failure zero is returned. This function +// will fail if the time can not be represented in a time_t. +OPENSSL_EXPORT int ASN1_TIME_to_time_t(const ASN1_TIME *t, time_t *out); + +// ASN1_TIME_to_posix converts |t| to a POSIX time value in |out|. On +// success, one is returned. On failure zero is returned. +OPENSSL_EXPORT int ASN1_TIME_to_posix(const ASN1_TIME *t, int64_t *out); + // TODO(davidben): Expand and document function prototypes generated in macros. diff --git a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_asn1t.h b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_asn1t.h index 4a1b5fbe..f391f7de 100644 --- a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_asn1t.h +++ b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_asn1t.h @@ -677,13 +677,17 @@ typedef struct ASN1_AUX_st { int i2d_##fname(const stname *a, unsigned char **out) \ { \ return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\ - } + } -#define IMPLEMENT_ASN1_DUP_FUNCTION(stname) \ - stname * stname##_dup(stname *x) \ - { \ - return ASN1_item_dup(ASN1_ITEM_rptr(stname), x); \ - } +#define IMPLEMENT_ASN1_DUP_FUNCTION(stname) \ + stname *stname##_dup(stname *x) { \ + return ASN1_item_dup(ASN1_ITEM_rptr(stname), x); \ + } + +#define IMPLEMENT_ASN1_DUP_FUNCTION_const(stname) \ + stname *stname##_dup(const stname *x) { \ + return ASN1_item_dup(ASN1_ITEM_rptr(stname), (void *)x); \ + } #define IMPLEMENT_ASN1_FUNCTIONS_const(name) \ IMPLEMENT_ASN1_FUNCTIONS_const_fname(name, name, name) diff --git a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_base.h b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_base.h index 15bccce7..9ec2bf53 100644 --- a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_base.h +++ b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_base.h @@ -112,6 +112,7 @@ extern "C" { #define OPENSSL_MIPS64 #elif defined(__riscv) && __SIZEOF_POINTER__ == 8 #define OPENSSL_64_BIT +#define OPENSSL_RISCV64 #elif defined(__riscv) && __SIZEOF_POINTER__ == 4 #define OPENSSL_32_BIT #elif defined(__pnacl__) @@ -123,8 +124,6 @@ extern "C" { #define OPENSSL_32_BIT #elif defined(__myriad2__) #define OPENSSL_32_BIT -#elif defined(__riscv) && __riscv_xlen == 64 -#define OPENSSL_64_BIT #else // Note BoringSSL only supports standard 32-bit and 64-bit two's-complement, // little-endian architectures. Functions will not produce the correct answer @@ -369,10 +368,6 @@ typedef struct NAME_CONSTRAINTS_st NAME_CONSTRAINTS; typedef struct Netscape_spkac_st NETSCAPE_SPKAC; typedef struct Netscape_spki_st NETSCAPE_SPKI; typedef struct RIPEMD160state_st RIPEMD160_CTX; -typedef struct X509_POLICY_CACHE_st X509_POLICY_CACHE; -typedef struct X509_POLICY_LEVEL_st X509_POLICY_LEVEL; -typedef struct X509_POLICY_NODE_st X509_POLICY_NODE; -typedef struct X509_POLICY_TREE_st X509_POLICY_TREE; typedef struct X509_VERIFY_PARAM_st X509_VERIFY_PARAM; typedef struct X509_algor_st X509_ALGOR; typedef struct X509_crl_st X509_CRL; @@ -398,6 +393,7 @@ typedef struct conf_st CONF; typedef struct conf_value_st CONF_VALUE; typedef struct crypto_buffer_pool_st CRYPTO_BUFFER_POOL; typedef struct crypto_buffer_st CRYPTO_BUFFER; +typedef struct ctr_drbg_state_st CTR_DRBG_STATE; typedef struct dh_st DH; typedef struct dsa_st DSA; typedef struct ec_group_st EC_GROUP; diff --git a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_boringssl_prefix_symbols.h b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_boringssl_prefix_symbols.h index 1bcb0618..41e3f021 100644 --- a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_boringssl_prefix_symbols.h +++ b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_boringssl_prefix_symbols.h @@ -139,6 +139,8 @@ #define ASN1_TIME_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_TIME_set) #define ASN1_TIME_set_string BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_TIME_set_string) #define ASN1_TIME_to_generalizedtime BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_TIME_to_generalizedtime) +#define ASN1_TIME_to_posix BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_TIME_to_posix) +#define ASN1_TIME_to_time_t BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_TIME_to_time_t) #define ASN1_TYPE_cmp BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_TYPE_cmp) #define ASN1_TYPE_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_TYPE_free) #define ASN1_TYPE_get BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_TYPE_get) @@ -645,8 +647,10 @@ #define CRYPTO_sysrand_if_available BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_sysrand_if_available) #define CRYPTO_tls1_prf BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_tls1_prf) #define CTR_DRBG_clear BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CTR_DRBG_clear) +#define CTR_DRBG_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CTR_DRBG_free) #define CTR_DRBG_generate BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CTR_DRBG_generate) #define CTR_DRBG_init BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CTR_DRBG_init) +#define CTR_DRBG_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CTR_DRBG_new) #define CTR_DRBG_reseed BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CTR_DRBG_reseed) #define ChaCha20_ctr32 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ChaCha20_ctr32) #define DES_decrypt3 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DES_decrypt3) @@ -659,6 +663,7 @@ #define DES_set_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DES_set_key) #define DES_set_key_unchecked BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DES_set_key_unchecked) #define DES_set_odd_parity BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DES_set_odd_parity) +#define DH_bits BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_bits) #define DH_check BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_check) #define DH_check_pub_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_check_pub_key) #define DH_compute_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_compute_key) @@ -704,6 +709,7 @@ #define DSA_SIG_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DSA_SIG_new) #define DSA_SIG_parse BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DSA_SIG_parse) #define DSA_SIG_set0 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DSA_SIG_set0) +#define DSA_bits BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DSA_bits) #define DSA_check_signature BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DSA_check_signature) #define DSA_do_check_signature BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DSA_do_check_signature) #define DSA_do_sign BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DSA_do_sign) @@ -995,6 +1001,7 @@ #define EVP_HPKE_CTX_export BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_HPKE_CTX_export) #define EVP_HPKE_CTX_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_HPKE_CTX_free) #define EVP_HPKE_CTX_kdf BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_HPKE_CTX_kdf) +#define EVP_HPKE_CTX_kem BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_HPKE_CTX_kem) #define EVP_HPKE_CTX_max_overhead BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_HPKE_CTX_max_overhead) #define EVP_HPKE_CTX_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_HPKE_CTX_new) #define EVP_HPKE_CTX_open BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_HPKE_CTX_open) @@ -1003,7 +1010,9 @@ #define EVP_HPKE_CTX_setup_sender BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_HPKE_CTX_setup_sender) #define EVP_HPKE_CTX_setup_sender_with_seed_for_testing BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_HPKE_CTX_setup_sender_with_seed_for_testing) #define EVP_HPKE_CTX_zero BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_HPKE_CTX_zero) +#define EVP_HPKE_KDF_hkdf_md BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_HPKE_KDF_hkdf_md) #define EVP_HPKE_KDF_id BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_HPKE_KDF_id) +#define EVP_HPKE_KEM_enc_len BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_HPKE_KEM_enc_len) #define EVP_HPKE_KEM_id BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_HPKE_KEM_id) #define EVP_HPKE_KEY_cleanup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_HPKE_KEY_cleanup) #define EVP_HPKE_KEY_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_HPKE_KEY_copy) @@ -1140,6 +1149,7 @@ #define EVP_aead_aes_128_cbc_sha1_tls_implicit_iv BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_aead_aes_128_cbc_sha1_tls_implicit_iv) #define EVP_aead_aes_128_ccm_bluetooth BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_aead_aes_128_ccm_bluetooth) #define EVP_aead_aes_128_ccm_bluetooth_8 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_aead_aes_128_ccm_bluetooth_8) +#define EVP_aead_aes_128_ccm_matter BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_aead_aes_128_ccm_matter) #define EVP_aead_aes_128_ctr_hmac_sha256 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_aead_aes_128_ctr_hmac_sha256) #define EVP_aead_aes_128_gcm BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_aead_aes_128_gcm) #define EVP_aead_aes_128_gcm_randnonce BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_aead_aes_128_gcm_randnonce) @@ -1255,6 +1265,7 @@ #define HMAC_CTX_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, HMAC_CTX_copy) #define HMAC_CTX_copy_ex BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, HMAC_CTX_copy_ex) #define HMAC_CTX_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, HMAC_CTX_free) +#define HMAC_CTX_get_md BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, HMAC_CTX_get_md) #define HMAC_CTX_init BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, HMAC_CTX_init) #define HMAC_CTX_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, HMAC_CTX_new) #define HMAC_CTX_reset BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, HMAC_CTX_reset) @@ -1359,6 +1370,7 @@ #define OPENSSL_malloc_init BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, OPENSSL_malloc_init) #define OPENSSL_memdup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, OPENSSL_memdup) #define OPENSSL_no_config BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, OPENSSL_no_config) +#define OPENSSL_posix_to_tm BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, OPENSSL_posix_to_tm) #define OPENSSL_realloc BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, OPENSSL_realloc) #define OPENSSL_strcasecmp BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, OPENSSL_strcasecmp) #define OPENSSL_strdup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, OPENSSL_strdup) @@ -1368,6 +1380,8 @@ #define OPENSSL_strncasecmp BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, OPENSSL_strncasecmp) #define OPENSSL_strndup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, OPENSSL_strndup) #define OPENSSL_strnlen BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, OPENSSL_strnlen) +#define OPENSSL_timegm BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, OPENSSL_timegm) +#define OPENSSL_tm_to_posix BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, OPENSSL_tm_to_posix) #define OPENSSL_tolower BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, OPENSSL_tolower) #define OTHERNAME_cmp BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, OTHERNAME_cmp) #define OTHERNAME_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, OTHERNAME_free) @@ -1384,7 +1398,6 @@ #define PEM_ASN1_write_bio BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, PEM_ASN1_write_bio) #define PEM_X509_INFO_read BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, PEM_X509_INFO_read) #define PEM_X509_INFO_read_bio BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, PEM_X509_INFO_read_bio) -#define PEM_X509_INFO_write_bio BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, PEM_X509_INFO_write_bio) #define PEM_bytes_read_bio BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, PEM_bytes_read_bio) #define PEM_def_callback BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, PEM_def_callback) #define PEM_dek_info BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, PEM_dek_info) @@ -1510,8 +1523,6 @@ #define PKCS8_encrypt BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, PKCS8_encrypt) #define PKCS8_marshal_encrypted_private_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, PKCS8_marshal_encrypted_private_key) #define PKCS8_parse_encrypted_private_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, PKCS8_parse_encrypted_private_key) -#define PKCS8_pkey_get0 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, PKCS8_pkey_get0) -#define PKCS8_pkey_set0 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, PKCS8_pkey_set0) #define POLICYINFO_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, POLICYINFO_free) #define POLICYINFO_it BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, POLICYINFO_it) #define POLICYINFO_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, POLICYINFO_new) @@ -1541,6 +1552,7 @@ #define RAND_enable_fork_unsafe_buffering BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RAND_enable_fork_unsafe_buffering) #define RAND_file_name BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RAND_file_name) #define RAND_get_rand_method BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RAND_get_rand_method) +#define RAND_get_system_entropy_for_custom_prng BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RAND_get_system_entropy_for_custom_prng) #define RAND_load_file BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RAND_load_file) #define RAND_poll BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RAND_poll) #define RAND_pseudo_bytes BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, RAND_pseudo_bytes) @@ -1714,6 +1726,7 @@ #define SSL_CTX_get_max_proto_version BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, SSL_CTX_get_max_proto_version) #define SSL_CTX_get_min_proto_version BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, SSL_CTX_get_min_proto_version) #define SSL_CTX_get_mode BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, SSL_CTX_get_mode) +#define SSL_CTX_get_num_tickets BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, SSL_CTX_get_num_tickets) #define SSL_CTX_get_options BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, SSL_CTX_get_options) #define SSL_CTX_get_quiet_shutdown BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, SSL_CTX_get_quiet_shutdown) #define SSL_CTX_get_read_ahead BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, SSL_CTX_get_read_ahead) @@ -2196,7 +2209,6 @@ #define USERNOTICE_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, USERNOTICE_free) #define USERNOTICE_it BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, USERNOTICE_it) #define USERNOTICE_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, USERNOTICE_new) -#define UTF8_getc BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, UTF8_getc) #define UTF8_putc BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, UTF8_putc) #define X25519 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X25519) #define X25519_keypair BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X25519_keypair) @@ -2239,7 +2251,6 @@ #define X509V3_set_ctx BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509V3_set_ctx) #define X509V3_set_nconf BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509V3_set_nconf) #define X509V3_string_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509V3_string_free) -#define X509_ALGORS_it BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_ALGORS_it) #define X509_ALGOR_cmp BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_ALGOR_cmp) #define X509_ALGOR_dup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_ALGOR_dup) #define X509_ALGOR_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_ALGOR_free) @@ -2275,7 +2286,6 @@ #define X509_CRL_add0_revoked BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_CRL_add0_revoked) #define X509_CRL_add1_ext_i2d BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_CRL_add1_ext_i2d) #define X509_CRL_add_ext BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_CRL_add_ext) -#define X509_CRL_check_suiteb BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_CRL_check_suiteb) #define X509_CRL_cmp BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_CRL_cmp) #define X509_CRL_delete_ext BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_CRL_delete_ext) #define X509_CRL_diff BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_CRL_diff) @@ -2480,7 +2490,6 @@ #define X509_STORE_CTX_get0_current_issuer BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_CTX_get0_current_issuer) #define X509_STORE_CTX_get0_param BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_CTX_get0_param) #define X509_STORE_CTX_get0_parent_ctx BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_CTX_get0_parent_ctx) -#define X509_STORE_CTX_get0_policy_tree BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_CTX_get0_policy_tree) #define X509_STORE_CTX_get0_store BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_CTX_get0_store) #define X509_STORE_CTX_get0_untrusted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_CTX_get0_untrusted) #define X509_STORE_CTX_get1_chain BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_CTX_get1_chain) @@ -2491,12 +2500,12 @@ #define X509_STORE_CTX_get_error_depth BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_CTX_get_error_depth) #define X509_STORE_CTX_get_ex_data BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_CTX_get_ex_data) #define X509_STORE_CTX_get_ex_new_index BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_CTX_get_ex_new_index) -#define X509_STORE_CTX_get_explicit_policy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_CTX_get_explicit_policy) #define X509_STORE_CTX_init BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_CTX_init) #define X509_STORE_CTX_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_CTX_new) #define X509_STORE_CTX_purpose_inherit BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_CTX_purpose_inherit) #define X509_STORE_CTX_set0_crls BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_CTX_set0_crls) #define X509_STORE_CTX_set0_param BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_CTX_set0_param) +#define X509_STORE_CTX_set0_trusted_stack BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_CTX_set0_trusted_stack) #define X509_STORE_CTX_set_cert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_CTX_set_cert) #define X509_STORE_CTX_set_chain BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_CTX_set_chain) #define X509_STORE_CTX_set_default BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_CTX_set_default) @@ -2596,7 +2605,6 @@ #define X509_add_ext BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_add_ext) #define X509_alias_get0 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_alias_get0) #define X509_alias_set1 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_alias_set1) -#define X509_chain_check_suiteb BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_chain_check_suiteb) #define X509_chain_up_ref BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_chain_up_ref) #define X509_check_akid BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_check_akid) #define X509_check_ca BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_check_ca) @@ -2673,19 +2681,9 @@ #define X509_load_cert_file BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_load_cert_file) #define X509_load_crl_file BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_load_crl_file) #define X509_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_new) -#define X509_ocspid_print BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_ocspid_print) #define X509_parse_from_buffer BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_parse_from_buffer) #define X509_policy_check BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_policy_check) -#define X509_policy_level_get0_node BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_policy_level_get0_node) -#define X509_policy_level_node_count BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_policy_level_node_count) -#define X509_policy_node_get0_parent BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_policy_node_get0_parent) -#define X509_policy_node_get0_policy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_policy_node_get0_policy) -#define X509_policy_node_get0_qualifiers BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_policy_node_get0_qualifiers) #define X509_policy_tree_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_policy_tree_free) -#define X509_policy_tree_get0_level BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_policy_tree_get0_level) -#define X509_policy_tree_get0_policies BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_policy_tree_get0_policies) -#define X509_policy_tree_get0_user_policies BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_policy_tree_get0_user_policies) -#define X509_policy_tree_level_count BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_policy_tree_level_count) #define X509_print BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_print) #define X509_print_ex BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_print_ex) #define X509_print_ex_fp BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_print_ex_fp) @@ -2984,7 +2982,6 @@ #define d2i_USERNOTICE BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_USERNOTICE) #define d2i_X509 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_X509) #define d2i_X509_ALGOR BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_X509_ALGOR) -#define d2i_X509_ALGORS BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_X509_ALGORS) #define d2i_X509_ATTRIBUTE BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_X509_ATTRIBUTE) #define d2i_X509_AUX BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_X509_AUX) #define d2i_X509_CERT_AUX BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_X509_CERT_AUX) @@ -3100,7 +3097,6 @@ #define ecdsa_sign_with_nonce_for_known_answer_test BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ecdsa_sign_with_nonce_for_known_answer_test) #define ecp_nistz256_avx2_select_w7 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ecp_nistz256_avx2_select_w7) #define ecp_nistz256_div_by_2 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ecp_nistz256_div_by_2) -#define ecp_nistz256_from_mont BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ecp_nistz256_from_mont) #define ecp_nistz256_mul_by_2 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ecp_nistz256_mul_by_2) #define ecp_nistz256_mul_by_3 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ecp_nistz256_mul_by_3) #define ecp_nistz256_mul_mont BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ecp_nistz256_mul_mont) @@ -3114,7 +3110,6 @@ #define ecp_nistz256_select_w7 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ecp_nistz256_select_w7) #define ecp_nistz256_sqr_mont BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ecp_nistz256_sqr_mont) #define ecp_nistz256_sub BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ecp_nistz256_sub) -#define ecp_nistz256_to_mont BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ecp_nistz256_to_mont) #define ed25519_asn1_meth BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ed25519_asn1_meth) #define ed25519_pkey_meth BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ed25519_pkey_meth) #define gcm_ghash_avx BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, gcm_ghash_avx) @@ -3245,7 +3240,6 @@ #define i2d_USERNOTICE BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_USERNOTICE) #define i2d_X509 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_X509) #define i2d_X509_ALGOR BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_X509_ALGOR) -#define i2d_X509_ALGORS BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_X509_ALGORS) #define i2d_X509_ATTRIBUTE BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_X509_ATTRIBUTE) #define i2d_X509_AUX BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_X509_AUX) #define i2d_X509_CERT_AUX BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_X509_CERT_AUX) @@ -3565,6 +3559,29 @@ #define sk_X509_POLICY_DATA_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_DATA_is_sorted) #define sk_X509_POLICY_DATA_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_DATA_set_cmp_func) #define sk_X509_POLICY_DATA_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_DATA_deep_copy) +#define sk_X509_POLICY_NODE_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_call_free_func) +#define sk_X509_POLICY_NODE_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_call_copy_func) +#define sk_X509_POLICY_NODE_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_call_cmp_func) +#define sk_X509_POLICY_NODE_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_new) +#define sk_X509_POLICY_NODE_new_null BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_new_null) +#define sk_X509_POLICY_NODE_num BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_num) +#define sk_X509_POLICY_NODE_zero BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_zero) +#define sk_X509_POLICY_NODE_value BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_value) +#define sk_X509_POLICY_NODE_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_set) +#define sk_X509_POLICY_NODE_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_free) +#define sk_X509_POLICY_NODE_pop_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_pop_free) +#define sk_X509_POLICY_NODE_insert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_insert) +#define sk_X509_POLICY_NODE_delete BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_delete) +#define sk_X509_POLICY_NODE_delete_ptr BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_delete_ptr) +#define sk_X509_POLICY_NODE_find BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_find) +#define sk_X509_POLICY_NODE_shift BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_shift) +#define sk_X509_POLICY_NODE_push BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_push) +#define sk_X509_POLICY_NODE_pop BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_pop) +#define sk_X509_POLICY_NODE_dup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_dup) +#define sk_X509_POLICY_NODE_sort BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_sort) +#define sk_X509_POLICY_NODE_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_is_sorted) +#define sk_X509_POLICY_NODE_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_set_cmp_func) +#define sk_X509_POLICY_NODE_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_deep_copy) #define sk_STACK_OF_X509_NAME_ENTRY_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_STACK_OF_X509_NAME_ENTRY_call_free_func) #define sk_STACK_OF_X509_NAME_ENTRY_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_STACK_OF_X509_NAME_ENTRY_call_copy_func) #define sk_STACK_OF_X509_NAME_ENTRY_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_STACK_OF_X509_NAME_ENTRY_call_cmp_func) @@ -3634,29 +3651,52 @@ #define sk_BY_DIR_ENTRY_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_BY_DIR_ENTRY_is_sorted) #define sk_BY_DIR_ENTRY_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_BY_DIR_ENTRY_set_cmp_func) #define sk_BY_DIR_ENTRY_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_BY_DIR_ENTRY_deep_copy) -#define sk_X509_ALGOR_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_call_free_func) -#define sk_X509_ALGOR_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_call_copy_func) -#define sk_X509_ALGOR_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_call_cmp_func) -#define sk_X509_ALGOR_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_new) -#define sk_X509_ALGOR_new_null BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_new_null) -#define sk_X509_ALGOR_num BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_num) -#define sk_X509_ALGOR_zero BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_zero) -#define sk_X509_ALGOR_value BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_value) -#define sk_X509_ALGOR_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_set) -#define sk_X509_ALGOR_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_free) -#define sk_X509_ALGOR_pop_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_pop_free) -#define sk_X509_ALGOR_insert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_insert) -#define sk_X509_ALGOR_delete BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_delete) -#define sk_X509_ALGOR_delete_ptr BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_delete_ptr) -#define sk_X509_ALGOR_find BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_find) -#define sk_X509_ALGOR_shift BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_shift) -#define sk_X509_ALGOR_push BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_push) -#define sk_X509_ALGOR_pop BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_pop) -#define sk_X509_ALGOR_dup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_dup) -#define sk_X509_ALGOR_sort BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_sort) -#define sk_X509_ALGOR_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_is_sorted) -#define sk_X509_ALGOR_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_set_cmp_func) -#define sk_X509_ALGOR_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_deep_copy) +#define sk_X509_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_call_free_func) +#define sk_X509_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_call_copy_func) +#define sk_X509_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_call_cmp_func) +#define sk_X509_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_new) +#define sk_X509_new_null BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_new_null) +#define sk_X509_num BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_num) +#define sk_X509_zero BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_zero) +#define sk_X509_value BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_value) +#define sk_X509_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_set) +#define sk_X509_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_free) +#define sk_X509_pop_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_pop_free) +#define sk_X509_insert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_insert) +#define sk_X509_delete BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_delete) +#define sk_X509_delete_ptr BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_delete_ptr) +#define sk_X509_find BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_find) +#define sk_X509_shift BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_shift) +#define sk_X509_push BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_push) +#define sk_X509_pop BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_pop) +#define sk_X509_dup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_dup) +#define sk_X509_sort BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_sort) +#define sk_X509_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_is_sorted) +#define sk_X509_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_set_cmp_func) +#define sk_X509_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_deep_copy) +#define sk_X509_CRL_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_call_free_func) +#define sk_X509_CRL_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_call_copy_func) +#define sk_X509_CRL_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_call_cmp_func) +#define sk_X509_CRL_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_new) +#define sk_X509_CRL_new_null BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_new_null) +#define sk_X509_CRL_num BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_num) +#define sk_X509_CRL_zero BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_zero) +#define sk_X509_CRL_value BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_value) +#define sk_X509_CRL_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_set) +#define sk_X509_CRL_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_free) +#define sk_X509_CRL_pop_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_pop_free) +#define sk_X509_CRL_insert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_insert) +#define sk_X509_CRL_delete BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_delete) +#define sk_X509_CRL_delete_ptr BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_delete_ptr) +#define sk_X509_CRL_find BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_find) +#define sk_X509_CRL_shift BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_shift) +#define sk_X509_CRL_push BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_push) +#define sk_X509_CRL_pop BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_pop) +#define sk_X509_CRL_dup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_dup) +#define sk_X509_CRL_sort BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_sort) +#define sk_X509_CRL_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_is_sorted) +#define sk_X509_CRL_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_set_cmp_func) +#define sk_X509_CRL_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_deep_copy) #define sk_X509_NAME_ENTRY_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_NAME_ENTRY_call_free_func) #define sk_X509_NAME_ENTRY_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_NAME_ENTRY_call_copy_func) #define sk_X509_NAME_ENTRY_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_NAME_ENTRY_call_cmp_func) @@ -3726,6 +3766,29 @@ #define sk_X509_EXTENSION_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_EXTENSION_is_sorted) #define sk_X509_EXTENSION_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_EXTENSION_set_cmp_func) #define sk_X509_EXTENSION_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_EXTENSION_deep_copy) +#define sk_X509_ALGOR_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_call_free_func) +#define sk_X509_ALGOR_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_call_copy_func) +#define sk_X509_ALGOR_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_call_cmp_func) +#define sk_X509_ALGOR_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_new) +#define sk_X509_ALGOR_new_null BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_new_null) +#define sk_X509_ALGOR_num BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_num) +#define sk_X509_ALGOR_zero BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_zero) +#define sk_X509_ALGOR_value BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_value) +#define sk_X509_ALGOR_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_set) +#define sk_X509_ALGOR_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_free) +#define sk_X509_ALGOR_pop_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_pop_free) +#define sk_X509_ALGOR_insert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_insert) +#define sk_X509_ALGOR_delete BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_delete) +#define sk_X509_ALGOR_delete_ptr BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_delete_ptr) +#define sk_X509_ALGOR_find BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_find) +#define sk_X509_ALGOR_shift BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_shift) +#define sk_X509_ALGOR_push BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_push) +#define sk_X509_ALGOR_pop BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_pop) +#define sk_X509_ALGOR_dup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_dup) +#define sk_X509_ALGOR_sort BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_sort) +#define sk_X509_ALGOR_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_is_sorted) +#define sk_X509_ALGOR_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_set_cmp_func) +#define sk_X509_ALGOR_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ALGOR_deep_copy) #define sk_X509_ATTRIBUTE_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_call_free_func) #define sk_X509_ATTRIBUTE_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_call_copy_func) #define sk_X509_ATTRIBUTE_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_call_cmp_func) @@ -3749,29 +3812,6 @@ #define sk_X509_ATTRIBUTE_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_is_sorted) #define sk_X509_ATTRIBUTE_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_set_cmp_func) #define sk_X509_ATTRIBUTE_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_deep_copy) -#define sk_X509_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_call_free_func) -#define sk_X509_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_call_copy_func) -#define sk_X509_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_call_cmp_func) -#define sk_X509_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_new) -#define sk_X509_new_null BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_new_null) -#define sk_X509_num BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_num) -#define sk_X509_zero BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_zero) -#define sk_X509_value BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_value) -#define sk_X509_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_set) -#define sk_X509_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_free) -#define sk_X509_pop_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_pop_free) -#define sk_X509_insert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_insert) -#define sk_X509_delete BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_delete) -#define sk_X509_delete_ptr BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_delete_ptr) -#define sk_X509_find BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_find) -#define sk_X509_shift BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_shift) -#define sk_X509_push BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_push) -#define sk_X509_pop BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_pop) -#define sk_X509_dup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_dup) -#define sk_X509_sort BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_sort) -#define sk_X509_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_is_sorted) -#define sk_X509_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_set_cmp_func) -#define sk_X509_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_deep_copy) #define sk_X509_TRUST_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_TRUST_call_free_func) #define sk_X509_TRUST_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_TRUST_call_copy_func) #define sk_X509_TRUST_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_TRUST_call_cmp_func) @@ -3818,29 +3858,6 @@ #define sk_X509_REVOKED_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_REVOKED_is_sorted) #define sk_X509_REVOKED_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_REVOKED_set_cmp_func) #define sk_X509_REVOKED_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_REVOKED_deep_copy) -#define sk_X509_CRL_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_call_free_func) -#define sk_X509_CRL_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_call_copy_func) -#define sk_X509_CRL_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_call_cmp_func) -#define sk_X509_CRL_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_new) -#define sk_X509_CRL_new_null BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_new_null) -#define sk_X509_CRL_num BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_num) -#define sk_X509_CRL_zero BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_zero) -#define sk_X509_CRL_value BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_value) -#define sk_X509_CRL_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_set) -#define sk_X509_CRL_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_free) -#define sk_X509_CRL_pop_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_pop_free) -#define sk_X509_CRL_insert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_insert) -#define sk_X509_CRL_delete BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_delete) -#define sk_X509_CRL_delete_ptr BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_delete_ptr) -#define sk_X509_CRL_find BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_find) -#define sk_X509_CRL_shift BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_shift) -#define sk_X509_CRL_push BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_push) -#define sk_X509_CRL_pop BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_pop) -#define sk_X509_CRL_dup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_dup) -#define sk_X509_CRL_sort BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_sort) -#define sk_X509_CRL_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_is_sorted) -#define sk_X509_CRL_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_set_cmp_func) -#define sk_X509_CRL_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_CRL_deep_copy) #define sk_X509_INFO_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_call_free_func) #define sk_X509_INFO_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_call_copy_func) #define sk_X509_INFO_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_call_cmp_func) @@ -4278,29 +4295,6 @@ #define sk_X509_PURPOSE_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_PURPOSE_is_sorted) #define sk_X509_PURPOSE_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_PURPOSE_set_cmp_func) #define sk_X509_PURPOSE_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_PURPOSE_deep_copy) -#define sk_X509_POLICY_NODE_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_call_free_func) -#define sk_X509_POLICY_NODE_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_call_copy_func) -#define sk_X509_POLICY_NODE_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_call_cmp_func) -#define sk_X509_POLICY_NODE_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_new) -#define sk_X509_POLICY_NODE_new_null BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_new_null) -#define sk_X509_POLICY_NODE_num BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_num) -#define sk_X509_POLICY_NODE_zero BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_zero) -#define sk_X509_POLICY_NODE_value BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_value) -#define sk_X509_POLICY_NODE_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_set) -#define sk_X509_POLICY_NODE_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_free) -#define sk_X509_POLICY_NODE_pop_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_pop_free) -#define sk_X509_POLICY_NODE_insert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_insert) -#define sk_X509_POLICY_NODE_delete BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_delete) -#define sk_X509_POLICY_NODE_delete_ptr BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_delete_ptr) -#define sk_X509_POLICY_NODE_find BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_find) -#define sk_X509_POLICY_NODE_shift BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_shift) -#define sk_X509_POLICY_NODE_push BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_push) -#define sk_X509_POLICY_NODE_pop BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_pop) -#define sk_X509_POLICY_NODE_dup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_dup) -#define sk_X509_POLICY_NODE_sort BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_sort) -#define sk_X509_POLICY_NODE_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_is_sorted) -#define sk_X509_POLICY_NODE_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_set_cmp_func) -#define sk_X509_POLICY_NODE_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_POLICY_NODE_deep_copy) #define sk_CONF_VALUE_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_CONF_VALUE_call_free_func) #define sk_CONF_VALUE_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_CONF_VALUE_call_copy_func) #define sk_CONF_VALUE_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_CONF_VALUE_call_cmp_func) diff --git a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_boringssl_prefix_symbols_asm.h b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_boringssl_prefix_symbols_asm.h index 0182c495..8901e214 100644 --- a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_boringssl_prefix_symbols_asm.h +++ b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_boringssl_prefix_symbols_asm.h @@ -144,6 +144,8 @@ #define _ASN1_TIME_set BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_TIME_set) #define _ASN1_TIME_set_string BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_TIME_set_string) #define _ASN1_TIME_to_generalizedtime BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_TIME_to_generalizedtime) +#define _ASN1_TIME_to_posix BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_TIME_to_posix) +#define _ASN1_TIME_to_time_t BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_TIME_to_time_t) #define _ASN1_TYPE_cmp BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_TYPE_cmp) #define _ASN1_TYPE_free BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_TYPE_free) #define _ASN1_TYPE_get BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_TYPE_get) @@ -650,8 +652,10 @@ #define _CRYPTO_sysrand_if_available BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_sysrand_if_available) #define _CRYPTO_tls1_prf BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_tls1_prf) #define _CTR_DRBG_clear BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CTR_DRBG_clear) +#define _CTR_DRBG_free BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CTR_DRBG_free) #define _CTR_DRBG_generate BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CTR_DRBG_generate) #define _CTR_DRBG_init BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CTR_DRBG_init) +#define _CTR_DRBG_new BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CTR_DRBG_new) #define _CTR_DRBG_reseed BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CTR_DRBG_reseed) #define _ChaCha20_ctr32 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ChaCha20_ctr32) #define _DES_decrypt3 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DES_decrypt3) @@ -664,6 +668,7 @@ #define _DES_set_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DES_set_key) #define _DES_set_key_unchecked BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DES_set_key_unchecked) #define _DES_set_odd_parity BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DES_set_odd_parity) +#define _DH_bits BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_bits) #define _DH_check BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_check) #define _DH_check_pub_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_check_pub_key) #define _DH_compute_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_compute_key) @@ -709,6 +714,7 @@ #define _DSA_SIG_new BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DSA_SIG_new) #define _DSA_SIG_parse BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DSA_SIG_parse) #define _DSA_SIG_set0 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DSA_SIG_set0) +#define _DSA_bits BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DSA_bits) #define _DSA_check_signature BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DSA_check_signature) #define _DSA_do_check_signature BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DSA_do_check_signature) #define _DSA_do_sign BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DSA_do_sign) @@ -1000,6 +1006,7 @@ #define _EVP_HPKE_CTX_export BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_HPKE_CTX_export) #define _EVP_HPKE_CTX_free BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_HPKE_CTX_free) #define _EVP_HPKE_CTX_kdf BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_HPKE_CTX_kdf) +#define _EVP_HPKE_CTX_kem BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_HPKE_CTX_kem) #define _EVP_HPKE_CTX_max_overhead BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_HPKE_CTX_max_overhead) #define _EVP_HPKE_CTX_new BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_HPKE_CTX_new) #define _EVP_HPKE_CTX_open BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_HPKE_CTX_open) @@ -1008,7 +1015,9 @@ #define _EVP_HPKE_CTX_setup_sender BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_HPKE_CTX_setup_sender) #define _EVP_HPKE_CTX_setup_sender_with_seed_for_testing BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_HPKE_CTX_setup_sender_with_seed_for_testing) #define _EVP_HPKE_CTX_zero BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_HPKE_CTX_zero) +#define _EVP_HPKE_KDF_hkdf_md BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_HPKE_KDF_hkdf_md) #define _EVP_HPKE_KDF_id BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_HPKE_KDF_id) +#define _EVP_HPKE_KEM_enc_len BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_HPKE_KEM_enc_len) #define _EVP_HPKE_KEM_id BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_HPKE_KEM_id) #define _EVP_HPKE_KEY_cleanup BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_HPKE_KEY_cleanup) #define _EVP_HPKE_KEY_copy BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_HPKE_KEY_copy) @@ -1145,6 +1154,7 @@ #define _EVP_aead_aes_128_cbc_sha1_tls_implicit_iv BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_aead_aes_128_cbc_sha1_tls_implicit_iv) #define _EVP_aead_aes_128_ccm_bluetooth BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_aead_aes_128_ccm_bluetooth) #define _EVP_aead_aes_128_ccm_bluetooth_8 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_aead_aes_128_ccm_bluetooth_8) +#define _EVP_aead_aes_128_ccm_matter BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_aead_aes_128_ccm_matter) #define _EVP_aead_aes_128_ctr_hmac_sha256 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_aead_aes_128_ctr_hmac_sha256) #define _EVP_aead_aes_128_gcm BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_aead_aes_128_gcm) #define _EVP_aead_aes_128_gcm_randnonce BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_aead_aes_128_gcm_randnonce) @@ -1260,6 +1270,7 @@ #define _HMAC_CTX_copy BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, HMAC_CTX_copy) #define _HMAC_CTX_copy_ex BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, HMAC_CTX_copy_ex) #define _HMAC_CTX_free BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, HMAC_CTX_free) +#define _HMAC_CTX_get_md BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, HMAC_CTX_get_md) #define _HMAC_CTX_init BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, HMAC_CTX_init) #define _HMAC_CTX_new BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, HMAC_CTX_new) #define _HMAC_CTX_reset BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, HMAC_CTX_reset) @@ -1364,6 +1375,7 @@ #define _OPENSSL_malloc_init BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, OPENSSL_malloc_init) #define _OPENSSL_memdup BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, OPENSSL_memdup) #define _OPENSSL_no_config BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, OPENSSL_no_config) +#define _OPENSSL_posix_to_tm BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, OPENSSL_posix_to_tm) #define _OPENSSL_realloc BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, OPENSSL_realloc) #define _OPENSSL_strcasecmp BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, OPENSSL_strcasecmp) #define _OPENSSL_strdup BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, OPENSSL_strdup) @@ -1373,6 +1385,8 @@ #define _OPENSSL_strncasecmp BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, OPENSSL_strncasecmp) #define _OPENSSL_strndup BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, OPENSSL_strndup) #define _OPENSSL_strnlen BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, OPENSSL_strnlen) +#define _OPENSSL_timegm BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, OPENSSL_timegm) +#define _OPENSSL_tm_to_posix BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, OPENSSL_tm_to_posix) #define _OPENSSL_tolower BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, OPENSSL_tolower) #define _OTHERNAME_cmp BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, OTHERNAME_cmp) #define _OTHERNAME_free BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, OTHERNAME_free) @@ -1389,7 +1403,6 @@ #define _PEM_ASN1_write_bio BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, PEM_ASN1_write_bio) #define _PEM_X509_INFO_read BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, PEM_X509_INFO_read) #define _PEM_X509_INFO_read_bio BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, PEM_X509_INFO_read_bio) -#define _PEM_X509_INFO_write_bio BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, PEM_X509_INFO_write_bio) #define _PEM_bytes_read_bio BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, PEM_bytes_read_bio) #define _PEM_def_callback BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, PEM_def_callback) #define _PEM_dek_info BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, PEM_dek_info) @@ -1515,8 +1528,6 @@ #define _PKCS8_encrypt BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, PKCS8_encrypt) #define _PKCS8_marshal_encrypted_private_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, PKCS8_marshal_encrypted_private_key) #define _PKCS8_parse_encrypted_private_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, PKCS8_parse_encrypted_private_key) -#define _PKCS8_pkey_get0 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, PKCS8_pkey_get0) -#define _PKCS8_pkey_set0 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, PKCS8_pkey_set0) #define _POLICYINFO_free BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, POLICYINFO_free) #define _POLICYINFO_it BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, POLICYINFO_it) #define _POLICYINFO_new BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, POLICYINFO_new) @@ -1546,6 +1557,7 @@ #define _RAND_enable_fork_unsafe_buffering BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RAND_enable_fork_unsafe_buffering) #define _RAND_file_name BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RAND_file_name) #define _RAND_get_rand_method BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RAND_get_rand_method) +#define _RAND_get_system_entropy_for_custom_prng BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RAND_get_system_entropy_for_custom_prng) #define _RAND_load_file BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RAND_load_file) #define _RAND_poll BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RAND_poll) #define _RAND_pseudo_bytes BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, RAND_pseudo_bytes) @@ -1719,6 +1731,7 @@ #define _SSL_CTX_get_max_proto_version BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, SSL_CTX_get_max_proto_version) #define _SSL_CTX_get_min_proto_version BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, SSL_CTX_get_min_proto_version) #define _SSL_CTX_get_mode BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, SSL_CTX_get_mode) +#define _SSL_CTX_get_num_tickets BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, SSL_CTX_get_num_tickets) #define _SSL_CTX_get_options BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, SSL_CTX_get_options) #define _SSL_CTX_get_quiet_shutdown BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, SSL_CTX_get_quiet_shutdown) #define _SSL_CTX_get_read_ahead BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, SSL_CTX_get_read_ahead) @@ -2201,7 +2214,6 @@ #define _USERNOTICE_free BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, USERNOTICE_free) #define _USERNOTICE_it BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, USERNOTICE_it) #define _USERNOTICE_new BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, USERNOTICE_new) -#define _UTF8_getc BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, UTF8_getc) #define _UTF8_putc BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, UTF8_putc) #define _X25519 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X25519) #define _X25519_keypair BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X25519_keypair) @@ -2244,7 +2256,6 @@ #define _X509V3_set_ctx BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509V3_set_ctx) #define _X509V3_set_nconf BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509V3_set_nconf) #define _X509V3_string_free BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509V3_string_free) -#define _X509_ALGORS_it BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_ALGORS_it) #define _X509_ALGOR_cmp BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_ALGOR_cmp) #define _X509_ALGOR_dup BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_ALGOR_dup) #define _X509_ALGOR_free BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_ALGOR_free) @@ -2280,7 +2291,6 @@ #define _X509_CRL_add0_revoked BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_CRL_add0_revoked) #define _X509_CRL_add1_ext_i2d BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_CRL_add1_ext_i2d) #define _X509_CRL_add_ext BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_CRL_add_ext) -#define _X509_CRL_check_suiteb BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_CRL_check_suiteb) #define _X509_CRL_cmp BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_CRL_cmp) #define _X509_CRL_delete_ext BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_CRL_delete_ext) #define _X509_CRL_diff BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_CRL_diff) @@ -2485,7 +2495,6 @@ #define _X509_STORE_CTX_get0_current_issuer BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_CTX_get0_current_issuer) #define _X509_STORE_CTX_get0_param BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_CTX_get0_param) #define _X509_STORE_CTX_get0_parent_ctx BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_CTX_get0_parent_ctx) -#define _X509_STORE_CTX_get0_policy_tree BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_CTX_get0_policy_tree) #define _X509_STORE_CTX_get0_store BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_CTX_get0_store) #define _X509_STORE_CTX_get0_untrusted BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_CTX_get0_untrusted) #define _X509_STORE_CTX_get1_chain BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_CTX_get1_chain) @@ -2496,12 +2505,12 @@ #define _X509_STORE_CTX_get_error_depth BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_CTX_get_error_depth) #define _X509_STORE_CTX_get_ex_data BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_CTX_get_ex_data) #define _X509_STORE_CTX_get_ex_new_index BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_CTX_get_ex_new_index) -#define _X509_STORE_CTX_get_explicit_policy BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_CTX_get_explicit_policy) #define _X509_STORE_CTX_init BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_CTX_init) #define _X509_STORE_CTX_new BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_CTX_new) #define _X509_STORE_CTX_purpose_inherit BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_CTX_purpose_inherit) #define _X509_STORE_CTX_set0_crls BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_CTX_set0_crls) #define _X509_STORE_CTX_set0_param BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_CTX_set0_param) +#define _X509_STORE_CTX_set0_trusted_stack BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_CTX_set0_trusted_stack) #define _X509_STORE_CTX_set_cert BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_CTX_set_cert) #define _X509_STORE_CTX_set_chain BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_CTX_set_chain) #define _X509_STORE_CTX_set_default BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_CTX_set_default) @@ -2601,7 +2610,6 @@ #define _X509_add_ext BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_add_ext) #define _X509_alias_get0 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_alias_get0) #define _X509_alias_set1 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_alias_set1) -#define _X509_chain_check_suiteb BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_chain_check_suiteb) #define _X509_chain_up_ref BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_chain_up_ref) #define _X509_check_akid BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_check_akid) #define _X509_check_ca BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_check_ca) @@ -2678,19 +2686,9 @@ #define _X509_load_cert_file BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_load_cert_file) #define _X509_load_crl_file BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_load_crl_file) #define _X509_new BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_new) -#define _X509_ocspid_print BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_ocspid_print) #define _X509_parse_from_buffer BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_parse_from_buffer) #define _X509_policy_check BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_policy_check) -#define _X509_policy_level_get0_node BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_policy_level_get0_node) -#define _X509_policy_level_node_count BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_policy_level_node_count) -#define _X509_policy_node_get0_parent BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_policy_node_get0_parent) -#define _X509_policy_node_get0_policy BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_policy_node_get0_policy) -#define _X509_policy_node_get0_qualifiers BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_policy_node_get0_qualifiers) #define _X509_policy_tree_free BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_policy_tree_free) -#define _X509_policy_tree_get0_level BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_policy_tree_get0_level) -#define _X509_policy_tree_get0_policies BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_policy_tree_get0_policies) -#define _X509_policy_tree_get0_user_policies BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_policy_tree_get0_user_policies) -#define _X509_policy_tree_level_count BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_policy_tree_level_count) #define _X509_print BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_print) #define _X509_print_ex BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_print_ex) #define _X509_print_ex_fp BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_print_ex_fp) @@ -2989,7 +2987,6 @@ #define _d2i_USERNOTICE BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_USERNOTICE) #define _d2i_X509 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_X509) #define _d2i_X509_ALGOR BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_X509_ALGOR) -#define _d2i_X509_ALGORS BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_X509_ALGORS) #define _d2i_X509_ATTRIBUTE BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_X509_ATTRIBUTE) #define _d2i_X509_AUX BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_X509_AUX) #define _d2i_X509_CERT_AUX BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_X509_CERT_AUX) @@ -3105,7 +3102,6 @@ #define _ecdsa_sign_with_nonce_for_known_answer_test BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ecdsa_sign_with_nonce_for_known_answer_test) #define _ecp_nistz256_avx2_select_w7 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ecp_nistz256_avx2_select_w7) #define _ecp_nistz256_div_by_2 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ecp_nistz256_div_by_2) -#define _ecp_nistz256_from_mont BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ecp_nistz256_from_mont) #define _ecp_nistz256_mul_by_2 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ecp_nistz256_mul_by_2) #define _ecp_nistz256_mul_by_3 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ecp_nistz256_mul_by_3) #define _ecp_nistz256_mul_mont BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ecp_nistz256_mul_mont) @@ -3119,7 +3115,6 @@ #define _ecp_nistz256_select_w7 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ecp_nistz256_select_w7) #define _ecp_nistz256_sqr_mont BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ecp_nistz256_sqr_mont) #define _ecp_nistz256_sub BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ecp_nistz256_sub) -#define _ecp_nistz256_to_mont BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ecp_nistz256_to_mont) #define _ed25519_asn1_meth BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ed25519_asn1_meth) #define _ed25519_pkey_meth BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ed25519_pkey_meth) #define _gcm_ghash_avx BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, gcm_ghash_avx) @@ -3250,7 +3245,6 @@ #define _i2d_USERNOTICE BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_USERNOTICE) #define _i2d_X509 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_X509) #define _i2d_X509_ALGOR BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_X509_ALGOR) -#define _i2d_X509_ALGORS BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_X509_ALGORS) #define _i2d_X509_ATTRIBUTE BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_X509_ATTRIBUTE) #define _i2d_X509_AUX BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_X509_AUX) #define _i2d_X509_CERT_AUX BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_X509_CERT_AUX) diff --git a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_ctrdrbg.h b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_ctrdrbg.h new file mode 100644 index 00000000..3cfdc8e9 --- /dev/null +++ b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_ctrdrbg.h @@ -0,0 +1,76 @@ +/* Copyright (c) 2022, Google Inc. + * + * 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. + * + * 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. */ + +#ifndef OPENSSL_HEADER_CTRDRBG_H +#define OPENSSL_HEADER_CTRDRBG_H + +#include "CNIOBoringSSL_base.h" + +#if defined(__cplusplus) +extern "C" { +#endif + + +// FIPS pseudo-random number generator. + + +// CTR-DRBG state objects. +// +// CTR_DRBG_STATE contains the state of a FIPS AES-CTR-based pseudo-random +// number generator. If BoringSSL was built in FIPS mode then this is a FIPS +// Approved algorithm. + +// CTR_DRBG_ENTROPY_LEN is the number of bytes of input entropy. See SP +// 800-90Ar1, table 3. +#define CTR_DRBG_ENTROPY_LEN 48 + +// CTR_DRBG_MAX_GENERATE_LENGTH is the maximum number of bytes that can be +// generated in a single call to |CTR_DRBG_generate|. +#define CTR_DRBG_MAX_GENERATE_LENGTH 65536 + +// CTR_DRBG_new returns an initialized |CTR_DRBG_STATE|, or NULL if either +// allocation failed or if |personalization_len| is invalid. +OPENSSL_EXPORT CTR_DRBG_STATE *CTR_DRBG_new( + const uint8_t entropy[CTR_DRBG_ENTROPY_LEN], const uint8_t *personalization, + size_t personalization_len); + +// CTR_DRBG_free frees |state| if non-NULL, or else does nothing. +OPENSSL_EXPORT void CTR_DRBG_free(CTR_DRBG_STATE* state); + +// CTR_DRBG_reseed reseeds |drbg| given |CTR_DRBG_ENTROPY_LEN| bytes of entropy +// in |entropy| and, optionally, up to |CTR_DRBG_ENTROPY_LEN| bytes of +// additional data. It returns one on success or zero on error. +OPENSSL_EXPORT int CTR_DRBG_reseed(CTR_DRBG_STATE *drbg, + const uint8_t entropy[CTR_DRBG_ENTROPY_LEN], + const uint8_t *additional_data, + size_t additional_data_len); + +// CTR_DRBG_generate processes to up |CTR_DRBG_ENTROPY_LEN| bytes of additional +// data (if any) and then writes |out_len| random bytes to |out|, where +// |out_len| <= |CTR_DRBG_MAX_GENERATE_LENGTH|. It returns one on success or +// zero on error. +OPENSSL_EXPORT int CTR_DRBG_generate(CTR_DRBG_STATE *drbg, uint8_t *out, + size_t out_len, + const uint8_t *additional_data, + size_t additional_data_len); + +// CTR_DRBG_clear zeroises the state of |drbg|. +OPENSSL_EXPORT void CTR_DRBG_clear(CTR_DRBG_STATE *drbg); + + +#if defined(__cplusplus) +} // extern C +#endif + +#endif // OPENSSL_HEADER_CTRDRBG_H diff --git a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_dh.h b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_dh.h index d08cf588..0b58b41f 100644 --- a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_dh.h +++ b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_dh.h @@ -89,6 +89,9 @@ OPENSSL_EXPORT int DH_up_ref(DH *dh); // Properties. +// DH_bits returns the size of |dh|'s group modulus, in bits. +OPENSSL_EXPORT unsigned DH_bits(const DH *dh); + // DH_get0_pub_key returns |dh|'s public key. OPENSSL_EXPORT const BIGNUM *DH_get0_pub_key(const DH *dh); diff --git a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_dsa.h b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_dsa.h index 2fd7cc7d..c6eb7405 100644 --- a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_dsa.h +++ b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_dsa.h @@ -94,6 +94,9 @@ OPENSSL_EXPORT int DSA_up_ref(DSA *dsa); // Properties. +// DSA_bits returns the size of |dsa|'s group modulus, in bits. +OPENSSL_EXPORT unsigned DSA_bits(const DSA *dsa); + // DSA_get0_pub_key returns |dsa|'s public key. OPENSSL_EXPORT const BIGNUM *DSA_get0_pub_key(const DSA *dsa); diff --git a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_hmac.h b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_hmac.h index e10e6013..df2d3032 100644 --- a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_hmac.h +++ b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_hmac.h @@ -137,6 +137,9 @@ OPENSSL_EXPORT int HMAC_Final(HMAC_CTX *ctx, uint8_t *out, // |ctx|. On entry, |ctx| must have been setup with |HMAC_Init_ex|. OPENSSL_EXPORT size_t HMAC_size(const HMAC_CTX *ctx); +// HMAC_CTX_get_md returns |ctx|'s hash function. +OPENSSL_EXPORT const EVP_MD *HMAC_CTX_get_md(const HMAC_CTX *ctx); + // HMAC_CTX_copy_ex sets |dest| equal to |src|. On entry, |dest| must have been // initialised by calling |HMAC_CTX_init|. It returns one on success and zero // on error. diff --git a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_hpke.h b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_hpke.h index 915e961f..7bcfeab5 100644 --- a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_hpke.h +++ b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_hpke.h @@ -51,6 +51,14 @@ OPENSSL_EXPORT const EVP_HPKE_KEM *EVP_hpke_x25519_hkdf_sha256(void); // will be one of the |EVP_HPKE_KEM_*| constants. OPENSSL_EXPORT uint16_t EVP_HPKE_KEM_id(const EVP_HPKE_KEM *kem); +// EVP_HPKE_MAX_ENC_LENGTH is the maximum length of "enc", the encapsulated +// shared secret, for all supported KEMs in this library. +#define EVP_HPKE_MAX_ENC_LENGTH 32 + +// EVP_HPKE_KEM_enc_len returns the length of the "enc", the encapsulated shared +// secret, for |kem|. This value will be at most |EVP_HPKE_MAX_ENC_LENGTH|. +OPENSSL_EXPORT size_t EVP_HPKE_KEM_enc_len(const EVP_HPKE_KEM *kem); + // The following constants are KDF identifiers. #define EVP_HPKE_HKDF_SHA256 0x0001 @@ -60,6 +68,11 @@ OPENSSL_EXPORT const EVP_HPKE_KDF *EVP_hpke_hkdf_sha256(void); // EVP_HPKE_KDF_id returns the HPKE KDF identifier for |kdf|. OPENSSL_EXPORT uint16_t EVP_HPKE_KDF_id(const EVP_HPKE_KDF *kdf); +// EVP_HPKE_KDF_hkdf_md returns the HKDF hash function corresponding to |kdf|, +// or NULL if |kdf| is not an HKDF-based KDF. All currently supported KDFs are +// HKDF-based. +OPENSSL_EXPORT const EVP_MD *EVP_HPKE_KDF_hkdf_md(const EVP_HPKE_KDF *kdf); + // The following constants are AEAD identifiers. #define EVP_HPKE_AES_128_GCM 0x0001 #define EVP_HPKE_AES_256_GCM 0x0002 @@ -182,16 +195,13 @@ OPENSSL_EXPORT EVP_HPKE_CTX *EVP_HPKE_CTX_new(void); // created with |EVP_HPKE_CTX_new|. OPENSSL_EXPORT void EVP_HPKE_CTX_free(EVP_HPKE_CTX *ctx); -// EVP_HPKE_MAX_ENC_LENGTH is the maximum length of "enc", the encapsulated -// shared secret, for all supported KEMs in this library. -#define EVP_HPKE_MAX_ENC_LENGTH 32 - // EVP_HPKE_CTX_setup_sender implements the SetupBaseS HPKE operation. It // encapsulates a shared secret for |peer_public_key| and sets up |ctx| as a // sender context. It writes the encapsulated shared secret to |out_enc| and // sets |*out_enc_len| to the number of bytes written. It writes at most // |max_enc| bytes and fails if the buffer is too small. Setting |max_enc| to at -// least |EVP_HPKE_MAX_ENC_LENGTH| will ensure the buffer is large enough. +// least |EVP_HPKE_MAX_ENC_LENGTH| will ensure the buffer is large enough. An +// exact size may also be determined by |EVP_PKEY_KEM_enc_len|. // // This function returns one on success and zero on error. Note that // |peer_public_key| may be invalid, in which case this function will return an @@ -292,6 +302,10 @@ OPENSSL_EXPORT int EVP_HPKE_CTX_export(const EVP_HPKE_CTX *ctx, uint8_t *out, // up as a sender. OPENSSL_EXPORT size_t EVP_HPKE_CTX_max_overhead(const EVP_HPKE_CTX *ctx); +// EVP_HPKE_CTX_kem returns |ctx|'s configured KEM, or NULL if the context has +// not been set up. +OPENSSL_EXPORT const EVP_HPKE_KEM *EVP_HPKE_CTX_kem(const EVP_HPKE_CTX *ctx); + // EVP_HPKE_CTX_aead returns |ctx|'s configured AEAD, or NULL if the context has // not been set up. OPENSSL_EXPORT const EVP_HPKE_AEAD *EVP_HPKE_CTX_aead(const EVP_HPKE_CTX *ctx); @@ -307,6 +321,7 @@ OPENSSL_EXPORT const EVP_HPKE_KDF *EVP_HPKE_CTX_kdf(const EVP_HPKE_CTX *ctx); // but accessing or modifying their fields is forbidden. struct evp_hpke_ctx_st { + const EVP_HPKE_KEM *kem; const EVP_HPKE_AEAD *aead; const EVP_HPKE_KDF *kdf; EVP_AEAD_CTX aead_ctx; diff --git a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_pem.h b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_pem.h index 8054f5eb..ecd2b89b 100644 --- a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_pem.h +++ b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_pem.h @@ -349,10 +349,6 @@ OPENSSL_EXPORT int PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, OPENSSL_EXPORT STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio( BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u); -OPENSSL_EXPORT int PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi, - EVP_CIPHER *enc, unsigned char *kstr, - int klen, pem_password_cb *cd, - void *u); OPENSSL_EXPORT int PEM_read(FILE *fp, char **name, char **header, unsigned char **data, long *len); diff --git a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_rand.h b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_rand.h index 9cba8649..81ec5243 100644 --- a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_rand.h +++ b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_rand.h @@ -25,9 +25,20 @@ extern "C" { // Random number generation. -// RAND_bytes writes |len| bytes of random data to |buf| and returns one. +// RAND_bytes writes |len| bytes of random data to |buf| and returns one. In the +// event that sufficient random data can not be obtained, |abort| is called. OPENSSL_EXPORT int RAND_bytes(uint8_t *buf, size_t len); +// RAND_get_system_entropy_for_custom_prng writes |len| bytes of random data +// from a system entropy source to |buf|. The maximum length of entropy which +// may be requested is 256 bytes. If more than 256 bytes of data is requested, +// or if sufficient random data can not be obtained, |abort| is called. +// |RAND_bytes| should normally be used instead of this function. This function +// should only be used for seed values or where |malloc| should not be called +// from BoringSSL. This function is not FIPS compliant. +OPENSSL_EXPORT void RAND_get_system_entropy_for_custom_prng(uint8_t *buf, + size_t len); + // RAND_cleanup frees any resources used by the RNG. This is not safe if other // threads might still be calling |RAND_bytes|. OPENSSL_EXPORT void RAND_cleanup(void); diff --git a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_ssl.h b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_ssl.h index fd13f87c..f095aa98 100644 --- a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_ssl.h +++ b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_ssl.h @@ -2288,6 +2288,10 @@ OPENSSL_EXPORT SSL_SESSION *SSL_process_tls13_new_session_ticket( // By default, BoringSSL sends two tickets. OPENSSL_EXPORT int SSL_CTX_set_num_tickets(SSL_CTX *ctx, size_t num_tickets); +// SSL_CTX_get_num_tickets returns the number of tickets |ctx| will send +// immediately after a successful TLS 1.3 handshake as a server. +OPENSSL_EXPORT size_t SSL_CTX_get_num_tickets(const SSL_CTX *ctx); + // Elliptic curve Diffie-Hellman. // @@ -3973,8 +3977,9 @@ OPENSSL_EXPORT int SSL_CTX_set_record_protocol_version(SSL_CTX *ctx, // those cases, BoringSSL will not predict a signature as there is no benefit. // Callers must allow for handshakes to complete without a predicted signature. // -// For now, only TLS 1.3 is hinted. TLS 1.2 will work, but the hints will be -// empty. +// Handshake hints are supported for TLS 1.3 and partially supported for +// TLS 1.2. TLS 1.2 resumption handshakes are not yet fully hinted. They will +// still work, but may not be as efficient. // SSL_serialize_capabilities writes an opaque byte string to |out| describing // some of |ssl|'s capabilities. It returns one on success and zero on error. @@ -4130,6 +4135,13 @@ enum ssl_renegotiate_mode_t BORINGSSL_ENUM_INT { // renegotiation attempts by a server. If |ssl| is a server, peer-initiated // renegotiations are *always* rejected and this function does nothing. // +// WARNING: Renegotiation is error-prone, complicates TLS's security properties, +// and increases its attack surface. When enabled, many common assumptions about +// BoringSSL's behavior no longer hold, and the calling application must handle +// more cases. Renegotiation is also incompatible with many application +// protocols, e.g. section 9.2.1 of RFC 7540. Many functions behave in ambiguous +// or undefined ways during a renegotiation. +// // The renegotiation mode defaults to |ssl_renegotiate_never|, but may be set // at any point in a connection's lifetime. Set it to |ssl_renegotiate_once| to // allow one renegotiation, |ssl_renegotiate_freely| to allow all @@ -4151,6 +4163,20 @@ enum ssl_renegotiate_mode_t BORINGSSL_ENUM_INT { // e.g., ALPN must enable renegotiation before the handshake and conditionally // disable it afterwards. // +// When enabled, renegotiation can cause properties of |ssl|, such as the cipher +// suite, to change during the lifetime of the connection. More over, during a +// renegotiation, not all properties of the new handshake are available or fully +// established. In BoringSSL, most functions, such as |SSL_get_current_cipher|, +// report information from the most recently completed handshake, not the +// pending one. However, renegotiation may rerun handshake callbacks, such as +// |SSL_CTX_set_cert_cb|. Such callbacks must ensure they are acting on the +// desired versions of each property. +// +// BoringSSL does not reverify peer certificates on renegotiation and instead +// requires they match between handshakes, so certificate verification callbacks +// (see |SSL_CTX_set_custom_verify|) may assume |ssl| is in the initial +// handshake and use |SSL_get0_peer_certificates|, etc. +// // There is no support in BoringSSL for initiating renegotiations as a client // or server. OPENSSL_EXPORT void SSL_set_renegotiate_mode(SSL *ssl, diff --git a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_ssl3.h b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_ssl3.h index 4d1017dd..a45da07b 100644 --- a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_ssl3.h +++ b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_ssl3.h @@ -118,7 +118,6 @@ #define OPENSSL_HEADER_SSL3_H #include "CNIOBoringSSL_aead.h" -#include "CNIOBoringSSL_type_check.h" #ifdef __cplusplus extern "C" { @@ -251,10 +250,6 @@ extern "C" { #define SSL3_RT_SEND_MAX_ENCRYPTED_OVERHEAD \ (EVP_AEAD_MAX_OVERHEAD + EVP_AEAD_MAX_NONCE_LENGTH) -OPENSSL_STATIC_ASSERT(SSL3_RT_MAX_ENCRYPTED_OVERHEAD >= - SSL3_RT_SEND_MAX_ENCRYPTED_OVERHEAD, - "max overheads are inconsistent"); - // SSL3_RT_MAX_COMPRESSED_LENGTH is an alias for // |SSL3_RT_MAX_PLAIN_LENGTH|. Compression is gone, so don't include the // compression overhead. diff --git a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_stack.h b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_stack.h index 9cac45c4..935e6f48 100644 --- a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_stack.h +++ b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_stack.h @@ -59,8 +59,6 @@ #include "CNIOBoringSSL_base.h" -#include "CNIOBoringSSL_type_check.h" - #if defined(__cplusplus) extern "C" { #endif @@ -69,36 +67,190 @@ extern "C" { // A stack, in OpenSSL, is an array of pointers. They are the most commonly // used collection object. // -// This file defines macros for type safe use of the stack functions. A stack -// of a specific type of object has type |STACK_OF(type)|. This can be defined -// (once) with |DEFINE_STACK_OF(type)| and declared where needed with -// |DECLARE_STACK_OF(type)|. For example: +// This file defines macros for type-safe use of the stack functions. A stack +// type is named like |STACK_OF(FOO)| and is accessed with functions named +// like |sk_FOO_*|. Note the stack will typically contain /pointers/ to |FOO|. // -// typedef struct foo_st { -// int bar; -// } FOO; -// -// DEFINE_STACK_OF(FOO) -// -// Although note that the stack will contain /pointers/ to |FOO|. -// -// A macro will be defined for each of the sk_* functions below. For -// STACK_OF(FOO), the macros would be sk_FOO_new, sk_FOO_pop etc. +// The |DECLARE_STACK_OF| macro makes |STACK_OF(FOO)| available, and +// |DEFINE_STACK_OF| makes the corresponding functions available. -// stack_free_func is a function that frees an element in a stack. Note its +// Defining stacks. + +// STACK_OF expands to the stack type for |type|. +#define STACK_OF(type) struct stack_st_##type + +// DECLARE_STACK_OF declares the |STACK_OF(type)| type. It does not make the +// corresponding |sk_type_*| functions available. This macro should be used in +// files which only need the type. +#define DECLARE_STACK_OF(type) STACK_OF(type); + +// DEFINE_NAMED_STACK_OF defines |STACK_OF(name)| to be a stack whose elements +// are |type| *. This macro makes the |sk_name_*| functions available. +// +// It is not necessary to use |DECLARE_STACK_OF| in files which use this macro. +#define DEFINE_NAMED_STACK_OF(name, type) \ + BORINGSSL_DEFINE_STACK_OF_IMPL(name, type *, const type *) \ + BORINGSSL_DEFINE_STACK_TRAITS(name, type, false) + +// DEFINE_STACK_OF defines |STACK_OF(type)| to be a stack whose elements are +// |type| *. This macro makes the |sk_type_*| functions available. +// +// It is not necessary to use |DECLARE_STACK_OF| in files which use this macro. +#define DEFINE_STACK_OF(type) DEFINE_NAMED_STACK_OF(type, type) + +// DEFINE_CONST_STACK_OF defines |STACK_OF(type)| to be a stack whose elements +// are const |type| *. This macro makes the |sk_type_*| functions available. +// +// It is not necessary to use |DECLARE_STACK_OF| in files which use this macro. +#define DEFINE_CONST_STACK_OF(type) \ + BORINGSSL_DEFINE_STACK_OF_IMPL(type, const type *, const type *) \ + BORINGSSL_DEFINE_STACK_TRAITS(type, const type, true) + + +// Using stacks. +// +// After the |DEFINE_STACK_OF| macro is used, the following functions are +// available. + +#if 0 // Sample + +// sk_SAMPLE_free_func is a callback to free an element in a stack. +typedef void (*sk_SAMPLE_free_func)(SAMPLE *); + +// sk_SAMPLE_copy_func is a callback to copy an element in a stack. It should +// return the copy or NULL on error. +typedef SAMPLE *(*sk_SAMPLE_copy_func)(SAMPLE *); + +// sk_SAMPLE_cmp_func is a callback to compare |*a| to |*b|. It should return a +// value < 0, 0, or > 0 if |*a| is less than, equal to, or greater than |*b|, +// respectively. Note the extra indirection - the function is given a pointer +// to a pointer to the element. This is the |qsort|/|bsearch| comparison +// function applied to an array of |SAMPLE*|. +// +// TODO(https://crbug.com/boringssl/498): The parameters should be +// |const SAMPLE *const *|. +typedef int (*sk_SAMPLE_cmp_func)(const SAMPLE **a, const SAMPLE **b); + +// sk_SAMPLE_new creates a new, empty stack with the given comparison function, +// which may be NULL. It returns the new stack or NULL on allocation failure. +STACK_OF(SAMPLE) *sk_SAMPLE_new(sk_SAMPLE_cmp_func comp); + +// sk_SAMPLE_new_null creates a new, empty stack. It returns the new stack or +// NULL on allocation failure. +STACK_OF(SAMPLE) *sk_SAMPLE_new_null(void); + +// sk_SAMPLE_num returns the number of elements in |sk|. +size_t sk_SAMPLE_num(const STACK_OF(SAMPLE) *sk); + +// sk_SAMPLE_zero resets |sk| to the empty state but does nothing to free the +// individual elements themselves. +void sk_SAMPLE_zero(STACK_OF(SAMPLE) *sk); + +// sk_SAMPLE_value returns the |i|th pointer in |sk|, or NULL if |i| is out of +// range. +SAMPLE *sk_SAMPLE_value(const STACK_OF(SAMPLE) *sk, size_t i); + +// sk_SAMPLE_set sets the |i|th pointer in |sk| to |p| and returns |p|. If |i| +// is out of range, it returns NULL. +SAMPLE *sk_SAMPLE_set(STACK_OF(SAMPLE) *sk, size_t i, SAMPLE *p); + +// sk_SAMPLE_free frees |sk|, but does nothing to free the individual elements. +// Use |sk_SAMPLE_pop_free| to also free the elements. +void sk_SAMPLE_free(STACK_OF(SAMPLE) *sk); + +// sk_SAMPLE_pop_free calls |free_func| on each element in |sk| and then +// frees the stack itself. +void sk_SAMPLE_pop_free(STACK_OF(SAMPLE) *sk, sk_SAMPLE_free_func free_func); + +// sk_SAMPLE_insert inserts |p| into the stack at index |where|, moving existing +// elements if needed. It returns the length of the new stack, or zero on +// error. +size_t sk_SAMPLE_insert(STACK_OF(SAMPLE) *sk, SAMPLE *p, size_t where); + +// sk_SAMPLE_delete removes the pointer at index |where|, moving other elements +// down if needed. It returns the removed pointer, or NULL if |where| is out of +// range. +SAMPLE *sk_SAMPLE_delete(STACK_OF(SAMPLE) *sk, size_t where); + +// sk_SAMPLE_delete_ptr removes, at most, one instance of |p| from |sk| based on +// pointer equality. If an instance of |p| is found then |p| is returned, +// otherwise it returns NULL. +SAMPLE *sk_SAMPLE_delete_ptr(STACK_OF(SAMPLE) *sk, const SAMPLE *p); + +// sk_SAMPLE_find find the first value in |sk| equal to |p|. |sk|'s comparison +// function determines equality, or pointer equality if |sk| has no comparison +// function. +// +// If the stack is sorted (see |sk_SAMPLE_sort|), this function uses a binary +// search. Otherwise it performs a linear search. If it finds a matching +// element, it writes the index to |*out_index| (if |out_index| is not NULL) and +// returns one. Otherwise, it returns zero. +// +// Note this differs from OpenSSL. The type signature is slightly different, and +// OpenSSL's version will implicitly sort |sk| if it has a comparison function +// defined. +int sk_SAMPLE_find(const STACK_OF(SAMPLE) *sk, size_t *out_index, + const SAMPLE *p); + +// sk_SAMPLE_shift removes and returns the first element in |sk|, or NULL if +// |sk| is empty. +SAMPLE *sk_SAMPLE_shift(STACK_OF(SAMPLE) *sk); + +// sk_SAMPLE_push appends |p| to |sk| and returns the length of the new stack, +// or 0 on allocation failure. +size_t sk_SAMPLE_push(STACK_OF(SAMPLE) *sk, SAMPLE *p); + +// sk_SAMPLE_pop removes and returns the last element of |sk|, or NULL if |sk| +// is empty. +SAMPLE *sk_SAMPLE_pop(STACK_OF(SAMPLE) *sk); + +// sk_SAMPLE_dup performs a shallow copy of a stack and returns the new stack, +// or NULL on error. Use |sk_SAMPLE_deep_copy| to also copy the elements. +STACK_OF(SAMPLE) *sk_SAMPLE_dup(const STACK_OF(SAMPLE) *sk); + +// sk_SAMPLE_sort sorts the elements of |sk| into ascending order based on the +// comparison function. The stack maintains a "sorted" flag and sorting an +// already sorted stack is a no-op. +void sk_SAMPLE_sort(STACK_OF(SAMPLE) *sk); + +// sk_SAMPLE_is_sorted returns one if |sk| is known to be sorted and zero +// otherwise. +int sk_SAMPLE_is_sorted(const STACK_OF(SAMPLE) *sk); + +// sk_SAMPLE_set_cmp_func sets the comparison function to be used by |sk| and +// returns the previous one. +sk_SAMPLE_cmp_func sk_SAMPLE_set_cmp_func(STACK_OF(SAMPLE) *sk, + sk_SAMPLE_cmp_func comp); + +// sk_SAMPLE_deep_copy performs a copy of |sk| and of each of the non-NULL +// elements in |sk| by using |copy_func|. If an error occurs, it calls +// |free_func| to free any copies already made and returns NULL. +STACK_OF(SAMPLE) *sk_SAMPLE_deep_copy(const STACK_OF(SAMPLE) *sk, + sk_SAMPLE_copy_func copy_func, + sk_SAMPLE_free_func free_func); + +#endif // Sample + + +// Private functions. +// +// TODO(https://crbug.com/boringssl/499): Rename to |OPENSSL_sk_foo|, after +// external code that calls them is fixed. + +// OPENSSL_sk_free_func is a function that frees an element in a stack. Note its // actual type is void (*)(T *) for some T. Low-level |sk_*| functions will be // passed a type-specific wrapper to call it correctly. -typedef void (*stack_free_func)(void *ptr); +typedef void (*OPENSSL_sk_free_func)(void *ptr); -// stack_copy_func is a function that copies an element in a stack. Note its -// actual type is T *(*)(T *) for some T. Low-level |sk_*| functions will be +// OPENSSL_sk_copy_func is a function that copies an element in a stack. Note +// its actual type is T *(*)(T *) for some T. Low-level |sk_*| functions will be // passed a type-specific wrapper to call it correctly. -typedef void *(*stack_copy_func)(void *ptr); +typedef void *(*OPENSSL_sk_copy_func)(void *ptr); -// stack_cmp_func is a comparison function that returns a value < 0, 0 or > 0 -// if |*a| is less than, equal to or greater than |*b|, respectively. Note the -// extra indirection - the function is given a pointer to a pointer to the +// OPENSSL_sk_cmp_func is a comparison function that returns a value < 0, 0 or > +// 0 if |*a| is less than, equal to or greater than |*b|, respectively. Note +// the extra indirection - the function is given a pointer to a pointer to the // element. This differs from the usual qsort/bsearch comparison function. // // Note its actual type is |int (*)(const T **a, const T **b)|. Low-level |sk_*| @@ -106,14 +258,15 @@ typedef void *(*stack_copy_func)(void *ptr); // // TODO(davidben): This type should be |const T *const *|. It is already fixed // in OpenSSL 1.1.1, so hopefully we can fix this compatibly. -typedef int (*stack_cmp_func)(const void **a, const void **b); +typedef int (*OPENSSL_sk_cmp_func)(const void **a, const void **b); // The following function types call the above type-erased signatures with the // true types. -typedef void (*stack_call_free_func)(stack_free_func, void *); -typedef void *(*stack_call_copy_func)(stack_copy_func, void *); -typedef int (*stack_call_cmp_func)(stack_cmp_func, const void *const *, - const void *const *); +typedef void (*OPENSSL_sk_call_free_func)(OPENSSL_sk_free_func, void *); +typedef void *(*OPENSSL_sk_call_copy_func)(OPENSSL_sk_copy_func, void *); +typedef int (*OPENSSL_sk_call_cmp_func)(OPENSSL_sk_cmp_func, + const void *const *, + const void *const *); // stack_st contains an array of pointers. It is not designed to be used // directly, rather the wrapper macros should be used. @@ -128,134 +281,47 @@ typedef struct stack_st { // to by |data|, which may be larger than |num|. size_t num_alloc; // comp is an optional comparison function. - stack_cmp_func comp; + OPENSSL_sk_cmp_func comp; } _STACK; - -#define STACK_OF(type) struct stack_st_##type - -#define DECLARE_STACK_OF(type) STACK_OF(type); - -// These are the raw stack functions, you shouldn't be using them. Rather you -// should be using the type stack macros implemented above. - -// sk_new creates a new, empty stack with the given comparison function, which -// may be zero. It returns the new stack or NULL on allocation failure. -OPENSSL_EXPORT _STACK *sk_new(stack_cmp_func comp); - -// sk_new_null creates a new, empty stack. It returns the new stack or NULL on -// allocation failure. +// The following are raw stack functions. They implement the corresponding typed +// |sk_SAMPLE_*| functions generated by |DEFINE_STACK_OF|. Callers shouldn't be +// using them. Rather, callers should use the typed functions. +OPENSSL_EXPORT _STACK *sk_new(OPENSSL_sk_cmp_func comp); OPENSSL_EXPORT _STACK *sk_new_null(void); - -// sk_num returns the number of elements in |s|. OPENSSL_EXPORT size_t sk_num(const _STACK *sk); - -// sk_zero resets |sk| to the empty state but does nothing to free the -// individual elements themselves. OPENSSL_EXPORT void sk_zero(_STACK *sk); - -// sk_value returns the |i|th pointer in |sk|, or NULL if |i| is out of -// range. OPENSSL_EXPORT void *sk_value(const _STACK *sk, size_t i); - -// sk_set sets the |i|th pointer in |sk| to |p| and returns |p|. If |i| is out -// of range, it returns NULL. OPENSSL_EXPORT void *sk_set(_STACK *sk, size_t i, void *p); - -// sk_free frees the given stack and array of pointers, but does nothing to -// free the individual elements. Also see |sk_pop_free_ex|. OPENSSL_EXPORT void sk_free(_STACK *sk); - -// sk_pop_free_ex calls |free_func| on each element in the stack and then frees -// the stack itself. Note this corresponds to |sk_FOO_pop_free|. It is named -// |sk_pop_free_ex| as a workaround for existing code calling an older version -// of |sk_pop_free|. OPENSSL_EXPORT void sk_pop_free_ex(_STACK *sk, - stack_call_free_func call_free_func, - stack_free_func free_func); - -// sk_insert inserts |p| into the stack at index |where|, moving existing -// elements if needed. It returns the length of the new stack, or zero on -// error. + OPENSSL_sk_call_free_func call_free_func, + OPENSSL_sk_free_func free_func); OPENSSL_EXPORT size_t sk_insert(_STACK *sk, void *p, size_t where); - -// sk_delete removes the pointer at index |where|, moving other elements down -// if needed. It returns the removed pointer, or NULL if |where| is out of -// range. OPENSSL_EXPORT void *sk_delete(_STACK *sk, size_t where); - -// sk_delete_ptr removes, at most, one instance of |p| from the stack based on -// pointer equality. If an instance of |p| is found then |p| is returned, -// otherwise it returns NULL. OPENSSL_EXPORT void *sk_delete_ptr(_STACK *sk, const void *p); - -// sk_find returns the first value in the stack equal to |p|. If a comparison -// function has been set on the stack, equality is defined by it, otherwise -// pointer equality is used. If the stack is sorted, then a binary search is -// used, otherwise a linear search is performed. If a matching element is found, -// its index is written to -// |*out_index| (if |out_index| is not NULL) and one is returned. Otherwise zero -// is returned. -// -// Note this differs from OpenSSL. The type signature is slightly different, and -// OpenSSL's sk_find will implicitly sort |sk| if it has a comparison function -// defined. OPENSSL_EXPORT int sk_find(const _STACK *sk, size_t *out_index, const void *p, - stack_call_cmp_func call_cmp_func); - -// sk_shift removes and returns the first element in the stack, or returns NULL -// if the stack is empty. + OPENSSL_sk_call_cmp_func call_cmp_func); OPENSSL_EXPORT void *sk_shift(_STACK *sk); - -// sk_push appends |p| to the stack and returns the length of the new stack, or -// 0 on allocation failure. OPENSSL_EXPORT size_t sk_push(_STACK *sk, void *p); - -// sk_pop returns and removes the last element on the stack, or NULL if the -// stack is empty. OPENSSL_EXPORT void *sk_pop(_STACK *sk); - -// sk_dup performs a shallow copy of a stack and returns the new stack, or NULL -// on error. OPENSSL_EXPORT _STACK *sk_dup(const _STACK *sk); - -// sk_sort sorts the elements of |sk| into ascending order based on the -// comparison function. The stack maintains a |sorted| flag and sorting an -// already sorted stack is a no-op. -OPENSSL_EXPORT void sk_sort(_STACK *sk, stack_call_cmp_func call_cmp_func); - -// sk_is_sorted returns one if |sk| is known to be sorted and zero -// otherwise. +OPENSSL_EXPORT void sk_sort(_STACK *sk, OPENSSL_sk_call_cmp_func call_cmp_func); OPENSSL_EXPORT int sk_is_sorted(const _STACK *sk); - -// sk_set_cmp_func sets the comparison function to be used by |sk| and returns -// the previous one. -OPENSSL_EXPORT stack_cmp_func sk_set_cmp_func(_STACK *sk, stack_cmp_func comp); - -// sk_deep_copy performs a copy of |sk| and of each of the non-NULL elements in -// |sk| by using |copy_func|. If an error occurs, |free_func| is used to free -// any copies already made and NULL is returned. +OPENSSL_EXPORT OPENSSL_sk_cmp_func sk_set_cmp_func(_STACK *sk, + OPENSSL_sk_cmp_func comp); OPENSSL_EXPORT _STACK *sk_deep_copy(const _STACK *sk, - stack_call_copy_func call_copy_func, - stack_copy_func copy_func, - stack_call_free_func call_free_func, - stack_free_func free_func); - - -// Deprecated functions. + OPENSSL_sk_call_copy_func call_copy_func, + OPENSSL_sk_copy_func copy_func, + OPENSSL_sk_call_free_func call_free_func, + OPENSSL_sk_free_func free_func); // sk_pop_free behaves like |sk_pop_free_ex| but performs an invalid function // pointer cast. It exists because some existing callers called |sk_pop_free| // directly. // // TODO(davidben): Migrate callers to bssl::UniquePtr and remove this. -OPENSSL_EXPORT void sk_pop_free(_STACK *sk, stack_free_func free_func); - - -// Defining stack types. -// -// This set of macros is used to emit the typed functions that act on a -// |STACK_OF(T)|. +OPENSSL_EXPORT void sk_pop_free(_STACK *sk, OPENSSL_sk_free_func free_func); #if !defined(BORINGSSL_NO_CXX) extern "C++" { @@ -285,157 +351,144 @@ BSSL_NAMESPACE_END #define BORINGSSL_DEFINE_STACK_TRAITS(name, type, is_const) #endif -#define BORINGSSL_DEFINE_STACK_OF_IMPL(name, ptrtype, constptrtype) \ - /* We disable MSVC C4191 in this macro, which warns when pointers are cast \ - * to the wrong type. While the cast itself is valid, it is often a bug \ - * because calling it through the cast is UB. However, we never actually \ - * call functions as |stack_cmp_func|. The type is just a type-erased \ - * function pointer. (C does not guarantee function pointers fit in \ - * |void*|, and GCC will warn on this.) Thus we just disable the false \ - * positive warning. */ \ - OPENSSL_MSVC_PRAGMA(warning(push)) \ - OPENSSL_MSVC_PRAGMA(warning(disable : 4191)) \ - \ - DECLARE_STACK_OF(name) \ - \ - typedef void (*stack_##name##_free_func)(ptrtype); \ - typedef ptrtype (*stack_##name##_copy_func)(ptrtype); \ - typedef int (*stack_##name##_cmp_func)(constptrtype *a, constptrtype *b); \ - \ - OPENSSL_INLINE void sk_##name##_call_free_func(stack_free_func free_func, \ - void *ptr) { \ - ((stack_##name##_free_func)free_func)((ptrtype)ptr); \ - } \ - \ - OPENSSL_INLINE void *sk_##name##_call_copy_func(stack_copy_func copy_func, \ - void *ptr) { \ - return (void *)((stack_##name##_copy_func)copy_func)((ptrtype)ptr); \ - } \ - \ - OPENSSL_INLINE int sk_##name##_call_cmp_func( \ - stack_cmp_func cmp_func, const void *const *a, const void *const *b) { \ - /* The data is actually stored as |void*| pointers, so read the pointer \ - * as |void*| and then pass the corrected type into the caller-supplied \ - * function, which expects |constptrtype*|. */ \ - constptrtype a_ptr = (constptrtype)*a; \ - constptrtype b_ptr = (constptrtype)*b; \ - return ((stack_##name##_cmp_func)cmp_func)(&a_ptr, &b_ptr); \ - } \ - \ - OPENSSL_INLINE STACK_OF(name) *sk_##name##_new( \ - stack_##name##_cmp_func comp) { \ - return (STACK_OF(name) *)sk_new((stack_cmp_func)comp); \ - } \ - \ - OPENSSL_INLINE STACK_OF(name) *sk_##name##_new_null(void) { \ - return (STACK_OF(name) *)sk_new_null(); \ - } \ - \ - OPENSSL_INLINE size_t sk_##name##_num(const STACK_OF(name) *sk) { \ - return sk_num((const _STACK *)sk); \ - } \ - \ - OPENSSL_INLINE void sk_##name##_zero(STACK_OF(name) *sk) { \ - sk_zero((_STACK *)sk); \ - } \ - \ - OPENSSL_INLINE ptrtype sk_##name##_value(const STACK_OF(name) *sk, \ - size_t i) { \ - return (ptrtype)sk_value((const _STACK *)sk, i); \ - } \ - \ - OPENSSL_INLINE ptrtype sk_##name##_set(STACK_OF(name) *sk, size_t i, \ - ptrtype p) { \ - return (ptrtype)sk_set((_STACK *)sk, i, (void *)p); \ - } \ - \ - OPENSSL_INLINE void sk_##name##_free(STACK_OF(name) *sk) { \ - sk_free((_STACK *)sk); \ - } \ - \ - OPENSSL_INLINE void sk_##name##_pop_free( \ - STACK_OF(name) *sk, stack_##name##_free_func free_func) { \ - sk_pop_free_ex((_STACK *)sk, sk_##name##_call_free_func, \ - (stack_free_func)free_func); \ - } \ - \ - OPENSSL_INLINE size_t sk_##name##_insert(STACK_OF(name) *sk, ptrtype p, \ - size_t where) { \ - return sk_insert((_STACK *)sk, (void *)p, where); \ - } \ - \ - OPENSSL_INLINE ptrtype sk_##name##_delete(STACK_OF(name) *sk, \ - size_t where) { \ - return (ptrtype)sk_delete((_STACK *)sk, where); \ - } \ - \ - OPENSSL_INLINE ptrtype sk_##name##_delete_ptr(STACK_OF(name) *sk, \ - constptrtype p) { \ - return (ptrtype)sk_delete_ptr((_STACK *)sk, (const void *)p); \ - } \ - \ - OPENSSL_INLINE int sk_##name##_find(const STACK_OF(name) *sk, \ - size_t *out_index, constptrtype p) { \ - return sk_find((const _STACK *)sk, out_index, (const void *)p, \ - sk_##name##_call_cmp_func); \ - } \ - \ - OPENSSL_INLINE ptrtype sk_##name##_shift(STACK_OF(name) *sk) { \ - return (ptrtype)sk_shift((_STACK *)sk); \ - } \ - \ - OPENSSL_INLINE size_t sk_##name##_push(STACK_OF(name) *sk, ptrtype p) { \ - return sk_push((_STACK *)sk, (void *)p); \ - } \ - \ - OPENSSL_INLINE ptrtype sk_##name##_pop(STACK_OF(name) *sk) { \ - return (ptrtype)sk_pop((_STACK *)sk); \ - } \ - \ - OPENSSL_INLINE STACK_OF(name) *sk_##name##_dup(const STACK_OF(name) *sk) { \ - return (STACK_OF(name) *)sk_dup((const _STACK *)sk); \ - } \ - \ - OPENSSL_INLINE void sk_##name##_sort(STACK_OF(name) *sk) { \ - sk_sort((_STACK *)sk, sk_##name##_call_cmp_func); \ - } \ - \ - OPENSSL_INLINE int sk_##name##_is_sorted(const STACK_OF(name) *sk) { \ - return sk_is_sorted((const _STACK *)sk); \ - } \ - \ - OPENSSL_INLINE stack_##name##_cmp_func sk_##name##_set_cmp_func( \ - STACK_OF(name) *sk, stack_##name##_cmp_func comp) { \ - return (stack_##name##_cmp_func)sk_set_cmp_func((_STACK *)sk, \ - (stack_cmp_func)comp); \ - } \ - \ - OPENSSL_INLINE STACK_OF(name) *sk_##name##_deep_copy( \ - const STACK_OF(name) *sk, ptrtype (*copy_func)(ptrtype), \ - void (*free_func)(ptrtype)) { \ - return (STACK_OF(name) *)sk_deep_copy( \ - (const _STACK *)sk, sk_##name##_call_copy_func, \ - (stack_copy_func)copy_func, sk_##name##_call_free_func, \ - (stack_free_func)free_func); \ - } \ - \ +#define BORINGSSL_DEFINE_STACK_OF_IMPL(name, ptrtype, constptrtype) \ + /* We disable MSVC C4191 in this macro, which warns when pointers are cast \ + * to the wrong type. While the cast itself is valid, it is often a bug \ + * because calling it through the cast is UB. However, we never actually \ + * call functions as |OPENSSL_sk_cmp_func|. The type is just a type-erased \ + * function pointer. (C does not guarantee function pointers fit in \ + * |void*|, and GCC will warn on this.) Thus we just disable the false \ + * positive warning. */ \ + OPENSSL_MSVC_PRAGMA(warning(push)) \ + OPENSSL_MSVC_PRAGMA(warning(disable : 4191)) \ + \ + DECLARE_STACK_OF(name) \ + \ + typedef void (*sk_##name##_free_func)(ptrtype); \ + typedef ptrtype (*sk_##name##_copy_func)(ptrtype); \ + typedef int (*sk_##name##_cmp_func)(constptrtype *a, constptrtype *b); \ + \ + OPENSSL_INLINE void sk_##name##_call_free_func( \ + OPENSSL_sk_free_func free_func, void *ptr) { \ + ((sk_##name##_free_func)free_func)((ptrtype)ptr); \ + } \ + \ + OPENSSL_INLINE void *sk_##name##_call_copy_func( \ + OPENSSL_sk_copy_func copy_func, void *ptr) { \ + return (void *)((sk_##name##_copy_func)copy_func)((ptrtype)ptr); \ + } \ + \ + OPENSSL_INLINE int sk_##name##_call_cmp_func(OPENSSL_sk_cmp_func cmp_func, \ + const void *const *a, \ + const void *const *b) { \ + /* The data is actually stored as |void*| pointers, so read the pointer \ + * as |void*| and then pass the corrected type into the caller-supplied \ + * function, which expects |constptrtype*|. */ \ + constptrtype a_ptr = (constptrtype)*a; \ + constptrtype b_ptr = (constptrtype)*b; \ + return ((sk_##name##_cmp_func)cmp_func)(&a_ptr, &b_ptr); \ + } \ + \ + OPENSSL_INLINE STACK_OF(name) *sk_##name##_new(sk_##name##_cmp_func comp) { \ + return (STACK_OF(name) *)sk_new((OPENSSL_sk_cmp_func)comp); \ + } \ + \ + OPENSSL_INLINE STACK_OF(name) *sk_##name##_new_null(void) { \ + return (STACK_OF(name) *)sk_new_null(); \ + } \ + \ + OPENSSL_INLINE size_t sk_##name##_num(const STACK_OF(name) *sk) { \ + return sk_num((const _STACK *)sk); \ + } \ + \ + OPENSSL_INLINE void sk_##name##_zero(STACK_OF(name) *sk) { \ + sk_zero((_STACK *)sk); \ + } \ + \ + OPENSSL_INLINE ptrtype sk_##name##_value(const STACK_OF(name) *sk, \ + size_t i) { \ + return (ptrtype)sk_value((const _STACK *)sk, i); \ + } \ + \ + OPENSSL_INLINE ptrtype sk_##name##_set(STACK_OF(name) *sk, size_t i, \ + ptrtype p) { \ + return (ptrtype)sk_set((_STACK *)sk, i, (void *)p); \ + } \ + \ + OPENSSL_INLINE void sk_##name##_free(STACK_OF(name) *sk) { \ + sk_free((_STACK *)sk); \ + } \ + \ + OPENSSL_INLINE void sk_##name##_pop_free(STACK_OF(name) *sk, \ + sk_##name##_free_func free_func) { \ + sk_pop_free_ex((_STACK *)sk, sk_##name##_call_free_func, \ + (OPENSSL_sk_free_func)free_func); \ + } \ + \ + OPENSSL_INLINE size_t sk_##name##_insert(STACK_OF(name) *sk, ptrtype p, \ + size_t where) { \ + return sk_insert((_STACK *)sk, (void *)p, where); \ + } \ + \ + OPENSSL_INLINE ptrtype sk_##name##_delete(STACK_OF(name) *sk, \ + size_t where) { \ + return (ptrtype)sk_delete((_STACK *)sk, where); \ + } \ + \ + OPENSSL_INLINE ptrtype sk_##name##_delete_ptr(STACK_OF(name) *sk, \ + constptrtype p) { \ + return (ptrtype)sk_delete_ptr((_STACK *)sk, (const void *)p); \ + } \ + \ + OPENSSL_INLINE int sk_##name##_find(const STACK_OF(name) *sk, \ + size_t *out_index, constptrtype p) { \ + return sk_find((const _STACK *)sk, out_index, (const void *)p, \ + sk_##name##_call_cmp_func); \ + } \ + \ + OPENSSL_INLINE ptrtype sk_##name##_shift(STACK_OF(name) *sk) { \ + return (ptrtype)sk_shift((_STACK *)sk); \ + } \ + \ + OPENSSL_INLINE size_t sk_##name##_push(STACK_OF(name) *sk, ptrtype p) { \ + return sk_push((_STACK *)sk, (void *)p); \ + } \ + \ + OPENSSL_INLINE ptrtype sk_##name##_pop(STACK_OF(name) *sk) { \ + return (ptrtype)sk_pop((_STACK *)sk); \ + } \ + \ + OPENSSL_INLINE STACK_OF(name) *sk_##name##_dup(const STACK_OF(name) *sk) { \ + return (STACK_OF(name) *)sk_dup((const _STACK *)sk); \ + } \ + \ + OPENSSL_INLINE void sk_##name##_sort(STACK_OF(name) *sk) { \ + sk_sort((_STACK *)sk, sk_##name##_call_cmp_func); \ + } \ + \ + OPENSSL_INLINE int sk_##name##_is_sorted(const STACK_OF(name) *sk) { \ + return sk_is_sorted((const _STACK *)sk); \ + } \ + \ + OPENSSL_INLINE sk_##name##_cmp_func sk_##name##_set_cmp_func( \ + STACK_OF(name) *sk, sk_##name##_cmp_func comp) { \ + return (sk_##name##_cmp_func)sk_set_cmp_func((_STACK *)sk, \ + (OPENSSL_sk_cmp_func)comp); \ + } \ + \ + OPENSSL_INLINE STACK_OF(name) *sk_##name##_deep_copy( \ + const STACK_OF(name) *sk, sk_##name##_copy_func copy_func, \ + sk_##name##_free_func free_func) { \ + return (STACK_OF(name) *)sk_deep_copy( \ + (const _STACK *)sk, sk_##name##_call_copy_func, \ + (OPENSSL_sk_copy_func)copy_func, sk_##name##_call_free_func, \ + (OPENSSL_sk_free_func)free_func); \ + } \ + \ OPENSSL_MSVC_PRAGMA(warning(pop)) -// DEFINE_NAMED_STACK_OF defines |STACK_OF(name)| to be a stack whose elements -// are |type| *. -#define DEFINE_NAMED_STACK_OF(name, type) \ - BORINGSSL_DEFINE_STACK_OF_IMPL(name, type *, const type *) \ - BORINGSSL_DEFINE_STACK_TRAITS(name, type, false) -// DEFINE_STACK_OF defines |STACK_OF(type)| to be a stack whose elements are -// |type| *. -#define DEFINE_STACK_OF(type) DEFINE_NAMED_STACK_OF(type, type) - -// DEFINE_CONST_STACK_OF defines |STACK_OF(type)| to be a stack whose elements -// are const |type| *. -#define DEFINE_CONST_STACK_OF(type) \ - BORINGSSL_DEFINE_STACK_OF_IMPL(type, const type *, const type *) \ - BORINGSSL_DEFINE_STACK_TRAITS(type, const type, true) +// Built-in stacks. typedef char *OPENSSL_STRING; @@ -471,7 +524,7 @@ struct DeleterImpl::kIsConst>> { // access it from C++ here. using Type = typename StackTraits::Type; sk_pop_free_ex(reinterpret_cast<_STACK *>(sk), - [](stack_free_func /* unused */, void *ptr) { + [](OPENSSL_sk_free_func /* unused */, void *ptr) { DeleterImpl::Free(reinterpret_cast(ptr)); }, nullptr); diff --git a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_tls1.h b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_tls1.h index 8eda2b64..998eaa76 100644 --- a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_tls1.h +++ b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_tls1.h @@ -452,9 +452,15 @@ extern "C" { #define TLS1_CK_ECDHE_PSK_WITH_CHACHA20_POLY1305_SHA256 0x0300CCAC // TLS 1.3 ciphersuites from RFC 8446. -#define TLS1_CK_AES_128_GCM_SHA256 0x03001301 -#define TLS1_CK_AES_256_GCM_SHA384 0x03001302 -#define TLS1_CK_CHACHA20_POLY1305_SHA256 0x03001303 +#define TLS1_3_CK_AES_128_GCM_SHA256 0x03001301 +#define TLS1_3_CK_AES_256_GCM_SHA384 0x03001302 +#define TLS1_3_CK_CHACHA20_POLY1305_SHA256 0x03001303 + +// The following constants are legacy aliases of |TLS1_3_CK_*|. +// TODO(davidben): Migrate callers to the new name and remove these. +#define TLS1_CK_AES_128_GCM_SHA256 TLS1_3_CK_AES_128_GCM_SHA256 +#define TLS1_CK_AES_256_GCM_SHA384 TLS1_3_CK_AES_256_GCM_SHA384 +#define TLS1_CK_CHACHA20_POLY1305_SHA256 TLS1_3_CK_CHACHA20_POLY1305_SHA256 // XXX // Inconsistency alert: @@ -624,10 +630,15 @@ extern "C" { "ECDHE-PSK-CHACHA20-POLY1305" // TLS 1.3 ciphersuites from RFC 8446. -#define TLS1_TXT_AES_128_GCM_SHA256 "TLS_AES_128_GCM_SHA256" -#define TLS1_TXT_AES_256_GCM_SHA384 "TLS_AES_256_GCM_SHA384" -#define TLS1_TXT_CHACHA20_POLY1305_SHA256 "TLS_CHACHA20_POLY1305_SHA256" +#define TLS1_3_RFC_AES_128_GCM_SHA256 "TLS_AES_128_GCM_SHA256" +#define TLS1_3_RFC_AES_256_GCM_SHA384 "TLS_AES_256_GCM_SHA384" +#define TLS1_3_RFC_CHACHA20_POLY1305_SHA256 "TLS_CHACHA20_POLY1305_SHA256" +// The following constants are legacy aliases of |TLS1_3_CK_*|. +// TODO(bbe): Migrate callers to the new name and remove these. +#define TLS1_TXT_AES_128_GCM_SHA256 TLS1_3_RFC_AES_128_GCM_SHA256 +#define TLS1_TXT_AES_256_GCM_SHA384 TLS1_3_RFC_AES_256_GCM_SHA384 +#define TLS1_TXT_CHACHA20_POLY1305_SHA256 TLS1_3_RFC_CHACHA20_POLY1305_SHA256 #define TLS_CT_RSA_SIGN 1 #define TLS_CT_DSS_SIGN 2 diff --git a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_type_check.h b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_type_check.h index 014217b3..a19aea85 100644 --- a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_type_check.h +++ b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_type_check.h @@ -64,22 +64,6 @@ extern "C" { #endif -#if defined(__cplusplus) || (defined(_MSC_VER) && !defined(__clang__)) -// In C++ and non-clang MSVC, |static_assert| is a keyword. -#define OPENSSL_STATIC_ASSERT(cond, msg) static_assert(cond, msg) -#else -// C11 defines the |_Static_assert| keyword and the |static_assert| macro in -// assert.h. While the former is available at all versions in Clang and GCC, the -// later depends on libc and, in glibc, depends on being built in C11 mode. We -// require C11 mode to build the library but, for now, do not require it in -// public headers. Use |_Static_assert| directly. -// -// TODO(davidben): In July 2022, if the C11 change has not been reverted, switch -// all uses of this macro within the library to C11 |static_assert|. This macro -// will only be necessary in public headers. -#define OPENSSL_STATIC_ASSERT(cond, msg) _Static_assert(cond, msg) -#endif - // CHECKED_CAST casts |p| from type |from| to type |to|. // // TODO(davidben): Although this macro is not public API and is unused in diff --git a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_x509.h b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_x509.h index 5993a328..b125ed4d 100644 --- a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_x509.h +++ b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_x509.h @@ -90,11 +90,1466 @@ extern "C" { // 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 +// 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. +// +// In the future, a replacement library will be available. Meanwhile, minimize // dependencies on this header where possible. +// +// TODO(https://crbug.com/boringssl/426): Documentation for this library is +// still in progress. Some functions have not yet been documented, and some +// functions have not yet been grouped into sections. +// Certificates. +// +// An |X509| object represents an X.509 certificate, defined in RFC 5280. +// +// Although an |X509| is a mutable object, mutating an |X509| can give incorrect +// results. Callers typically obtain |X509|s by parsing some input with +// |d2i_X509|, etc. Such objects carry information such as the serialized +// TBSCertificate and decoded extensions, which will become inconsistent when +// mutated. +// +// Instead, mutation functions should only be used when issuing new +// certificates, as described in a later section. + +DEFINE_STACK_OF(X509) + +// X509 is an |ASN1_ITEM| whose ASN.1 type is X.509 Certificate (RFC 5280) and C +// type is |X509*|. +DECLARE_ASN1_ITEM(X509) + +// X509_up_ref adds one to the reference count of |x509| and returns one. +OPENSSL_EXPORT int X509_up_ref(X509 *x509); + +// X509_chain_up_ref returns a newly-allocated |STACK_OF(X509)| containing a +// shallow copy of |chain|, or NULL on error. That is, the return value has the +// same contents as |chain|, and each |X509|'s reference count is incremented by +// one. +OPENSSL_EXPORT STACK_OF(X509) *X509_chain_up_ref(STACK_OF(X509) *chain); + +// X509_dup returns a newly-allocated copy of |x509|, or NULL on error. This +// function works by serializing the structure, so auxiliary properties (see +// |i2d_X509_AUX|) are not preserved. Additionally, if |x509| is incomplete, +// this function may fail. +// +// TODO(https://crbug.com/boringssl/407): This function should be const and +// thread-safe but is currently neither in some cases, notably if |crl| was +// mutated. +OPENSSL_EXPORT X509 *X509_dup(X509 *x509); + +// X509_free decrements |x509|'s reference count and, if zero, releases memory +// associated with |x509|. +OPENSSL_EXPORT void X509_free(X509 *x509); + +// d2i_X509 parses up to |len| bytes from |*inp| as a DER-encoded X.509 +// Certificate (RFC 5280), as described in |d2i_SAMPLE_with_reuse|. +OPENSSL_EXPORT X509 *d2i_X509(X509 **out, const uint8_t **inp, long len); + +// X509_parse_from_buffer parses an X.509 structure from |buf| and returns a +// fresh X509 or NULL on error. There must not be any trailing data in |buf|. +// The returned structure (if any) holds a reference to |buf| rather than +// copying parts of it as a normal |d2i_X509| call would do. +OPENSSL_EXPORT X509 *X509_parse_from_buffer(CRYPTO_BUFFER *buf); + +// i2d_X509 marshals |x509| as a DER-encoded X.509 Certificate (RFC 5280), as +// described in |i2d_SAMPLE|. +// +// TODO(https://crbug.com/boringssl/407): This function should be const and +// thread-safe but is currently neither in some cases, notably if |x509| was +// mutated. +OPENSSL_EXPORT int i2d_X509(X509 *x509, uint8_t **outp); + +// X509_VERSION_* are X.509 version numbers. Note the numerical values of all +// defined X.509 versions are one less than the named version. +#define X509_VERSION_1 0 +#define X509_VERSION_2 1 +#define X509_VERSION_3 2 + +// X509_get_version returns the numerical value of |x509|'s version, which will +// be one of the |X509_VERSION_*| constants. +OPENSSL_EXPORT long X509_get_version(const X509 *x509); + +// X509_get0_serialNumber returns |x509|'s serial number. +OPENSSL_EXPORT const ASN1_INTEGER *X509_get0_serialNumber(const X509 *x509); + +// X509_get0_notBefore returns |x509|'s notBefore time. +OPENSSL_EXPORT const ASN1_TIME *X509_get0_notBefore(const X509 *x509); + +// X509_get0_notAfter returns |x509|'s notAfter time. +OPENSSL_EXPORT const ASN1_TIME *X509_get0_notAfter(const X509 *x509); + +// X509_get_issuer_name returns |x509|'s issuer. +OPENSSL_EXPORT X509_NAME *X509_get_issuer_name(const X509 *x509); + +// X509_get_subject_name returns |x509|'s subject. +OPENSSL_EXPORT X509_NAME *X509_get_subject_name(const X509 *x509); + +// X509_get_X509_PUBKEY returns the public key of |x509|. Note this function is +// not const-correct for legacy reasons. Callers should not modify the returned +// object. +OPENSSL_EXPORT X509_PUBKEY *X509_get_X509_PUBKEY(const X509 *x509); + +// X509_get_pubkey returns |x509|'s public key as an |EVP_PKEY|, or NULL if the +// public key was unsupported or could not be decoded. This function returns a +// reference to the |EVP_PKEY|. The caller must release the result with +// |EVP_PKEY_free| when done. +OPENSSL_EXPORT EVP_PKEY *X509_get_pubkey(X509 *x509); + +// X509_get0_pubkey_bitstr returns the BIT STRING portion of |x509|'s public +// key. Note this does not contain the AlgorithmIdentifier portion. +// +// WARNING: This function returns a non-const pointer for OpenSSL compatibility, +// but the caller must not modify the resulting object. Doing so will break +// internal invariants in |x509|. +OPENSSL_EXPORT ASN1_BIT_STRING *X509_get0_pubkey_bitstr(const X509 *x509); + +// X509_get0_uids sets |*out_issuer_uid| to a non-owning pointer to the +// issuerUID field of |x509|, or NULL if |x509| has no issuerUID. It similarly +// outputs |x509|'s subjectUID field to |*out_subject_uid|. +// +// Callers may pass NULL to either |out_issuer_uid| or |out_subject_uid| to +// ignore the corresponding field. +OPENSSL_EXPORT void X509_get0_uids(const X509 *x509, + const ASN1_BIT_STRING **out_issuer_uid, + const ASN1_BIT_STRING **out_subject_uid); + +// X509_get0_extensions returns |x509|'s extension list, or NULL if |x509| omits +// it. +OPENSSL_EXPORT const STACK_OF(X509_EXTENSION) *X509_get0_extensions( + const X509 *x509); + +// X509_get_ext_count returns the number of extensions in |x|. +OPENSSL_EXPORT int X509_get_ext_count(const X509 *x); + +// X509_get_ext_by_NID behaves like |X509v3_get_ext_by_NID| but searches for +// extensions in |x|. +OPENSSL_EXPORT int X509_get_ext_by_NID(const X509 *x, int nid, int lastpos); + +// X509_get_ext_by_OBJ behaves like |X509v3_get_ext_by_OBJ| but searches for +// extensions in |x|. +OPENSSL_EXPORT int X509_get_ext_by_OBJ(const X509 *x, const ASN1_OBJECT *obj, + int lastpos); + +// X509_get_ext_by_critical behaves like |X509v3_get_ext_by_critical| but +// searches for extensions in |x|. +OPENSSL_EXPORT int X509_get_ext_by_critical(const X509 *x, int crit, + int lastpos); + +// X509_get_ext returns the extension in |x| at index |loc|, or NULL if |loc| is +// out of bounds. This function returns a non-const pointer for OpenSSL +// compatibility, but callers should not mutate the result. +OPENSSL_EXPORT X509_EXTENSION *X509_get_ext(const X509 *x, int loc); + +// X509_get0_tbs_sigalg returns the signature algorithm in |x509|'s +// TBSCertificate. For the outer signature algorithm, see |X509_get0_signature|. +// +// Certificates with mismatched signature algorithms will successfully parse, +// but they will be rejected when verifying. +OPENSSL_EXPORT const X509_ALGOR *X509_get0_tbs_sigalg(const X509 *x509); + +// X509_get0_signature sets |*out_sig| and |*out_alg| to the signature and +// signature algorithm of |x509|, respectively. Either output pointer may be +// NULL to ignore the value. +// +// This function outputs the outer signature algorithm. For the one in the +// TBSCertificate, see |X509_get0_tbs_sigalg|. Certificates with mismatched +// signature algorithms will successfully parse, but they will be rejected when +// verifying. +OPENSSL_EXPORT void X509_get0_signature(const ASN1_BIT_STRING **out_sig, + const X509_ALGOR **out_alg, + const X509 *x509); + +// X509_get_signature_nid returns the NID corresponding to |x509|'s signature +// algorithm, or |NID_undef| if the signature algorithm does not correspond to +// a known NID. +OPENSSL_EXPORT int X509_get_signature_nid(const X509 *x509); + +// 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 +// the signature of an existing certificate. To generate certificates, use +// |i2d_re_X509_tbs| instead. +OPENSSL_EXPORT int i2d_X509_tbs(X509 *x509, unsigned char **outp); + + +// Issuing certificates. +// +// An |X509| object may also represent an incomplete certificate. Callers may +// construct empty |X509| objects, fill in fields individually, and finally sign +// the result. The following functions may be used for this purpose. + +// X509_new returns a newly-allocated, empty |X509| object, or NULL on error. +// This produces an incomplete certificate which may be filled in to issue a new +// certificate. +OPENSSL_EXPORT X509 *X509_new(void); + +// X509_set_version sets |x509|'s version to |version|, which should be one of +// the |X509V_VERSION_*| constants. It returns one on success and zero on error. +// +// If unsure, use |X509_VERSION_3|. +OPENSSL_EXPORT int X509_set_version(X509 *x509, long version); + +// X509_set_serialNumber sets |x509|'s serial number to |serial|. It returns one +// on success and zero on error. +OPENSSL_EXPORT int X509_set_serialNumber(X509 *x509, + const ASN1_INTEGER *serial); + +// X509_set1_notBefore sets |x509|'s notBefore time to |tm|. It returns one on +// success and zero on error. +OPENSSL_EXPORT int X509_set1_notBefore(X509 *x509, const ASN1_TIME *tm); + +// X509_set1_notAfter sets |x509|'s notAfter time to |tm|. it returns one on +// success and zero on error. +OPENSSL_EXPORT int X509_set1_notAfter(X509 *x509, const ASN1_TIME *tm); + +// X509_getm_notBefore returns a mutable pointer to |x509|'s notBefore time. +OPENSSL_EXPORT ASN1_TIME *X509_getm_notBefore(X509 *x509); + +// X509_getm_notAfter returns a mutable pointer to |x509|'s notAfter time. +OPENSSL_EXPORT ASN1_TIME *X509_getm_notAfter(X509 *x); + +// X509_set_issuer_name sets |x509|'s issuer to a copy of |name|. It returns one +// on success and zero on error. +OPENSSL_EXPORT int X509_set_issuer_name(X509 *x509, X509_NAME *name); + +// X509_set_subject_name sets |x509|'s subject to a copy of |name|. It returns +// one on success and zero on error. +OPENSSL_EXPORT int X509_set_subject_name(X509 *x509, X509_NAME *name); + +// X509_set_pubkey sets |x509|'s public key to |pkey|. It returns one on success +// and zero on error. This function does not take ownership of |pkey| and +// internally copies and updates reference counts as needed. +OPENSSL_EXPORT int X509_set_pubkey(X509 *x509, EVP_PKEY *pkey); + +// X509_delete_ext removes the extension in |x| at index |loc| and returns the +// removed extension, or NULL if |loc| was out of bounds. If non-NULL, the +// caller must release the result with |X509_EXTENSION_free|. +OPENSSL_EXPORT X509_EXTENSION *X509_delete_ext(X509 *x, int loc); + +// X509_add_ext adds a copy of |ex| to |x|. It returns one on success and zero +// on failure. The caller retains ownership of |ex| and can release it +// independently of |x|. +// +// The new extension is inserted at index |loc|, shifting extensions to the +// right. If |loc| is -1 or out of bounds, the new extension is appended to the +// list. +OPENSSL_EXPORT int X509_add_ext(X509 *x, const X509_EXTENSION *ex, int loc); + +// X509_sign signs |x509| with |pkey| and replaces the signature algorithm and +// signature fields. It returns one on success and zero on error. This function +// uses digest algorithm |md|, or |pkey|'s default if NULL. Other signing +// parameters use |pkey|'s defaults. To customize them, use |X509_sign_ctx|. +OPENSSL_EXPORT int X509_sign(X509 *x509, EVP_PKEY *pkey, const EVP_MD *md); + +// X509_sign_ctx signs |x509| with |ctx| and replaces the signature algorithm +// and signature fields. It returns one on success and zero on error. The +// signature algorithm and parameters come from |ctx|, which must have been +// initialized with |EVP_DigestSignInit|. The caller should configure the +// corresponding |EVP_PKEY_CTX| before calling this function. +OPENSSL_EXPORT int X509_sign_ctx(X509 *x509, EVP_MD_CTX *ctx); + +// 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); + +// X509_set1_signature_algo sets |x509|'s signature algorithm to |algo| and +// returns one on success or zero on error. It updates both the signature field +// of the TBSCertificate structure, and the signatureAlgorithm field of the +// Certificate. +OPENSSL_EXPORT int X509_set1_signature_algo(X509 *x509, const X509_ALGOR *algo); + +// X509_set1_signature_value sets |x509|'s signature to a copy of the |sig_len| +// bytes pointed by |sig|. It returns one on success and zero on error. +// +// Due to a specification error, X.509 certificates store signatures in ASN.1 +// BIT STRINGs, but signature algorithms return byte strings rather than bit +// strings. This function creates a BIT STRING containing a whole number of +// bytes, with the bit order matching the DER encoding. This matches the +// encoding used by all X.509 signature algorithms. +OPENSSL_EXPORT int X509_set1_signature_value(X509 *x509, const uint8_t *sig, + size_t sig_len); + + +// Auxiliary certificate properties. +// +// |X509| objects optionally maintain auxiliary properties. These are not part +// of the certificates themselves, and thus are not covered by signatures or +// preserved by the standard serialization. They are used as inputs or outputs +// to other functions in this library. + +// i2d_X509_AUX marshals |x509| as a DER-encoded X.509 Certificate (RFC 5280), +// followed optionally by a separate, OpenSSL-specific structure with auxiliary +// properties. It behaves as described in |i2d_SAMPLE|. +// +// Unlike similarly-named functions, this function does not output a single +// ASN.1 element. Directly embedding the output in a larger ASN.1 structure will +// not behave correctly. +OPENSSL_EXPORT int i2d_X509_AUX(X509 *x509, unsigned char **outp); + +// d2i_X509_AUX parses up to |length| bytes from |*inp| as a DER-encoded X.509 +// Certificate (RFC 5280), followed optionally by a separate, OpenSSL-specific +// structure with auxiliary properties. It behaves as described in +// |d2i_SAMPLE_with_reuse|. +// +// Some auxiliary properties affect trust decisions, so this function should not +// be used with untrusted input. +// +// Unlike similarly-named functions, this function does not parse a single +// ASN.1 element. Trying to parse data directly embedded in a larger ASN.1 +// structure will not behave correctly. +OPENSSL_EXPORT X509 *d2i_X509_AUX(X509 **x509, const unsigned char **inp, + long length); + +// X509_alias_set1 sets |x509|'s alias to |len| bytes from |name|. If |name| is +// NULL, the alias is cleared instead. Aliases are not part of the certificate +// itself and will not be serialized by |i2d_X509|. +OPENSSL_EXPORT int X509_alias_set1(X509 *x509, const unsigned char *name, + int len); + +// X509_keyid_set1 sets |x509|'s key ID to |len| bytes from |id|. If |id| is +// NULL, the key ID is cleared instead. Key IDs are not part of the certificate +// itself and will not be serialized by |i2d_X509|. +OPENSSL_EXPORT int X509_keyid_set1(X509 *x509, const unsigned char *id, + int len); + +// X509_alias_get0 looks up |x509|'s alias. If found, it sets |*out_len| to the +// alias's length and returns a pointer to a buffer containing the contents. If +// not found, it outputs the empty string by returning NULL and setting +// |*out_len| to zero. +// +// If |x509| was parsed from a PKCS#12 structure (see +// |PKCS12_get_key_and_certs|), the alias will reflect the friendlyName +// attribute (RFC 2985). +// +// WARNING: In OpenSSL, this function did not set |*out_len| when the alias was +// missing. Callers that target both OpenSSL and BoringSSL should set the value +// to zero before calling this function. +OPENSSL_EXPORT unsigned char *X509_alias_get0(X509 *x509, int *out_len); + +// X509_keyid_get0 looks up |x509|'s key ID. If found, it sets |*out_len| to the +// key ID's length and returns a pointer to a buffer containing the contents. If +// not found, it outputs the empty string by returning NULL and setting +// |*out_len| to zero. +// +// WARNING: In OpenSSL, this function did not set |*out_len| when the alias was +// missing. Callers that target both OpenSSL and BoringSSL should set the value +// to zero before calling this function. +OPENSSL_EXPORT unsigned char *X509_keyid_get0(X509 *x509, int *out_len); + + +// Certificate revocation lists. +// +// An |X509_CRL| object represents an X.509 certificate revocation list (CRL), +// defined in RFC 5280. A CRL is a signed list of certificates which are no +// longer considered valid. +// +// Although an |X509_CRL| is a mutable object, mutating an |X509_CRL| can give +// incorrect results. Callers typically obtain |X509_CRL|s by parsing some input +// with |d2i_X509_CRL|, etc. Such objects carry information such as the +// serialized TBSCertList and decoded extensions, which will become inconsistent +// when mutated. +// +// Instead, mutation functions should only be used when issuing new CRLs, as +// described in a later section. + +DEFINE_STACK_OF(X509_CRL) + +// X509_CRL is an |ASN1_ITEM| whose ASN.1 type is X.509 CertificateList (RFC +// 5280) and C type is |X509_CRL*|. +DECLARE_ASN1_ITEM(X509_CRL) + +// X509_CRL_up_ref adds one to the reference count of |crl| and returns one. +OPENSSL_EXPORT int X509_CRL_up_ref(X509_CRL *crl); + +// X509_CRL_dup returns a newly-allocated copy of |crl|, or NULL on error. This +// function works by serializing the structure, so if |crl| is incomplete, it +// may fail. +// +// TODO(https://crbug.com/boringssl/407): This function should be const and +// thread-safe but is currently neither in some cases, notably if |crl| was +// mutated. +OPENSSL_EXPORT X509_CRL *X509_CRL_dup(X509_CRL *crl); + +// X509_CRL_free decrements |crl|'s reference count and, if zero, releases +// memory associated with |crl|. +OPENSSL_EXPORT void X509_CRL_free(X509_CRL *crl); + +// d2i_X509_CRL parses up to |len| bytes from |*inp| as a DER-encoded X.509 +// CertificateList (RFC 5280), as described in |d2i_SAMPLE_with_reuse|. +OPENSSL_EXPORT X509_CRL *d2i_X509_CRL(X509_CRL **out, const uint8_t **inp, + long len); + +// i2d_X509_CRL marshals |crl| as a X.509 CertificateList (RFC 5280), as +// described in |i2d_SAMPLE|. +// +// TODO(https://crbug.com/boringssl/407): This function should be const and +// thread-safe but is currently neither in some cases, notably if |crl| was +// mutated. +OPENSSL_EXPORT int i2d_X509_CRL(X509_CRL *crl, uint8_t **outp); + +#define X509_CRL_VERSION_1 0 +#define X509_CRL_VERSION_2 1 + +// X509_CRL_get_version returns the numerical value of |crl|'s version, which +// will be one of the |X509_CRL_VERSION_*| constants. +OPENSSL_EXPORT long X509_CRL_get_version(const X509_CRL *crl); + +// X509_CRL_get0_lastUpdate returns |crl|'s thisUpdate time. The OpenSSL API +// refers to this field as lastUpdate. +OPENSSL_EXPORT const ASN1_TIME *X509_CRL_get0_lastUpdate(const X509_CRL *crl); + +// X509_CRL_get0_nextUpdate returns |crl|'s nextUpdate time, or NULL if |crl| +// has none. +OPENSSL_EXPORT const ASN1_TIME *X509_CRL_get0_nextUpdate(const X509_CRL *crl); + +// X509_CRL_get_issuer returns |crl|'s issuer name. Note this function is not +// const-correct for legacy reasons. +OPENSSL_EXPORT X509_NAME *X509_CRL_get_issuer(const X509_CRL *crl); + +// X509_CRL_get_REVOKED returns the list of revoked certificates in |crl|, or +// NULL if |crl| omits it. +// +// TOOD(davidben): This function was originally a macro, without clear const +// semantics. It should take a const input and give const output, but the latter +// would break existing callers. For now, we match upstream. +OPENSSL_EXPORT STACK_OF(X509_REVOKED) *X509_CRL_get_REVOKED(X509_CRL *crl); + +// X509_CRL_get0_extensions returns |crl|'s extension list, or NULL if |crl| +// omits it. +OPENSSL_EXPORT const STACK_OF(X509_EXTENSION) *X509_CRL_get0_extensions( + const X509_CRL *crl); + +// X509_CRL_get_ext_count returns the number of extensions in |x|. +OPENSSL_EXPORT int X509_CRL_get_ext_count(const X509_CRL *x); + +// X509_CRL_get_ext_by_NID behaves like |X509v3_get_ext_by_NID| but searches for +// extensions in |x|. +OPENSSL_EXPORT int X509_CRL_get_ext_by_NID(const X509_CRL *x, int nid, + int lastpos); + +// X509_CRL_get_ext_by_OBJ behaves like |X509v3_get_ext_by_OBJ| but searches for +// extensions in |x|. +OPENSSL_EXPORT int X509_CRL_get_ext_by_OBJ(const X509_CRL *x, + const ASN1_OBJECT *obj, int lastpos); + +// X509_CRL_get_ext_by_critical behaves like |X509v3_get_ext_by_critical| but +// searches for extensions in |x|. +OPENSSL_EXPORT int X509_CRL_get_ext_by_critical(const X509_CRL *x, int crit, + int lastpos); + +// X509_CRL_get_ext returns the extension in |x| at index |loc|, or NULL if +// |loc| is out of bounds. This function returns a non-const pointer for OpenSSL +// compatibility, but callers should not mutate the result. +OPENSSL_EXPORT X509_EXTENSION *X509_CRL_get_ext(const X509_CRL *x, int loc); + +// X509_CRL_get0_signature sets |*out_sig| and |*out_alg| to the signature and +// signature algorithm of |crl|, respectively. Either output pointer may be NULL +// to ignore the value. +// +// This function outputs the outer signature algorithm, not the one in the +// TBSCertList. CRLs with mismatched signature algorithms will successfully +// parse, but they will be rejected when verifying. +OPENSSL_EXPORT void X509_CRL_get0_signature(const X509_CRL *crl, + const ASN1_BIT_STRING **out_sig, + const X509_ALGOR **out_alg); + +// X509_CRL_get_signature_nid returns the NID corresponding to |crl|'s signature +// algorithm, or |NID_undef| if the signature algorithm does not correspond to +// a known NID. +OPENSSL_EXPORT int X509_CRL_get_signature_nid(const X509_CRL *crl); + +// 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 +// signature of an existing CRL. To generate CRLs, use |i2d_re_X509_CRL_tbs| +// instead. +OPENSSL_EXPORT int i2d_X509_CRL_tbs(X509_CRL *crl, unsigned char **outp); + + +// Issuing certificate revocation lists. +// +// An |X509_CRL| object may also represent an incomplete CRL. Callers may +// construct empty |X509_CRL| objects, fill in fields individually, and finally +// sign the result. The following functions may be used for this purpose. + +// X509_CRL_new returns a newly-allocated, empty |X509_CRL| object, or NULL on +// error. This object may be filled in and then signed to construct a CRL. +OPENSSL_EXPORT X509_CRL *X509_CRL_new(void); + +// X509_CRL_set_version sets |crl|'s version to |version|, which should be one +// of the |X509_CRL_VERSION_*| constants. It returns one on success and zero on +// error. +// +// If unsure, use |X509_CRL_VERSION_2|. Note that, unlike certificates, CRL +// versions are only defined up to v2. Callers should not use |X509_VERSION_3|. +OPENSSL_EXPORT int X509_CRL_set_version(X509_CRL *crl, long version); + +// X509_CRL_set_issuer_name sets |crl|'s issuer to a copy of |name|. It returns +// one on success and zero on error. +OPENSSL_EXPORT int X509_CRL_set_issuer_name(X509_CRL *crl, X509_NAME *name); + +// X509_CRL_set1_lastUpdate sets |crl|'s thisUpdate time to |tm|. It returns one +// on success and zero on error. The OpenSSL API refers to this field as +// lastUpdate. +OPENSSL_EXPORT int X509_CRL_set1_lastUpdate(X509_CRL *crl, const ASN1_TIME *tm); + +// X509_CRL_set1_nextUpdate sets |crl|'s nextUpdate time to |tm|. It returns one +// on success and zero on error. +OPENSSL_EXPORT int X509_CRL_set1_nextUpdate(X509_CRL *crl, const ASN1_TIME *tm); + +// X509_CRL_delete_ext removes the extension in |x| at index |loc| and returns +// the removed extension, or NULL if |loc| was out of bounds. If non-NULL, the +// caller must release the result with |X509_EXTENSION_free|. +OPENSSL_EXPORT X509_EXTENSION *X509_CRL_delete_ext(X509_CRL *x, int loc); + +// X509_CRL_add_ext adds a copy of |ex| to |x|. It returns one on success and +// zero on failure. The caller retains ownership of |ex| and can release it +// independently of |x|. +// +// The new extension is inserted at index |loc|, shifting extensions to the +// right. If |loc| is -1 or out of bounds, the new extension is appended to the +// list. +OPENSSL_EXPORT int X509_CRL_add_ext(X509_CRL *x, const X509_EXTENSION *ex, + int loc); + +// X509_CRL_sign signs |crl| with |pkey| and replaces the signature algorithm +// and signature fields. It returns one on success and zero on error. This +// function uses digest algorithm |md|, or |pkey|'s default if NULL. Other +// signing parameters use |pkey|'s defaults. To customize them, use +// |X509_CRL_sign_ctx|. +OPENSSL_EXPORT int X509_CRL_sign(X509_CRL *crl, EVP_PKEY *pkey, + const EVP_MD *md); + +// X509_CRL_sign_ctx signs |crl| with |ctx| and replaces the signature algorithm +// and signature fields. It returns one on success and zero on error. The +// signature algorithm and parameters come from |ctx|, which must have been +// initialized with |EVP_DigestSignInit|. The caller should configure the +// corresponding |EVP_PKEY_CTX| before calling this function. +OPENSSL_EXPORT int X509_CRL_sign_ctx(X509_CRL *crl, EVP_MD_CTX *ctx); + +// 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); + +// X509_CRL_set1_signature_algo sets |crl|'s signature algorithm to |algo| and +// returns one on success or zero on error. It updates both the signature field +// of the TBSCertList structure, and the signatureAlgorithm field of the CRL. +OPENSSL_EXPORT int X509_CRL_set1_signature_algo(X509_CRL *crl, + const X509_ALGOR *algo); + +// X509_CRL_set1_signature_value sets |crl|'s signature to a copy of the +// |sig_len| bytes pointed by |sig|. It returns one on success and zero on +// error. +// +// Due to a specification error, X.509 CRLs store signatures in ASN.1 BIT +// STRINGs, but signature algorithms return byte strings rather than bit +// strings. This function creates a BIT STRING containing a whole number of +// bytes, with the bit order matching the DER encoding. This matches the +// encoding used by all X.509 signature algorithms. +OPENSSL_EXPORT int X509_CRL_set1_signature_value(X509_CRL *crl, + const uint8_t *sig, + size_t sig_len); + + +// Certificate requests. +// +// An |X509_REQ| represents a PKCS #10 certificate request (RFC 2986). These are +// also referred to as certificate signing requests or CSRs. CSRs are a common +// format used to request a certificate from a CA. +// +// Although an |X509_REQ| is a mutable object, mutating an |X509_REQ| can give +// incorrect results. Callers typically obtain |X509_REQ|s by parsing some input +// with |d2i_X509_REQ|, etc. Such objects carry information such as the +// serialized CertificationRequestInfo, which will become inconsistent when +// mutated. +// +// Instead, mutation functions should only be used when issuing new CRLs, as +// described in a later section. + +// X509_REQ is an |ASN1_ITEM| whose ASN.1 type is CertificateRequest (RFC 2986) +// and C type is |X509_REQ*|. +DECLARE_ASN1_ITEM(X509_REQ) + +// X509_REQ_dup returns a newly-allocated copy of |req|, or NULL on error. This +// function works by serializing the structure, so if |req| is incomplete, it +// may fail. +// +// TODO(https://crbug.com/boringssl/407): This function should be const and +// thread-safe but is currently neither in some cases, notably if |req| was +// mutated. +OPENSSL_EXPORT X509_REQ *X509_REQ_dup(X509_REQ *req); + +// X509_REQ_free releases memory associated with |req|. +OPENSSL_EXPORT void X509_REQ_free(X509_REQ *req); + +// d2i_X509_REQ parses up to |len| bytes from |*inp| as a DER-encoded +// CertificateRequest (RFC 2986), as described in |d2i_SAMPLE_with_reuse|. +OPENSSL_EXPORT X509_REQ *d2i_X509_REQ(X509_REQ **out, const uint8_t **inp, + long len); + +// i2d_X509_REQ marshals |req| as a CertificateRequest (RFC 2986), as described +// in |i2d_SAMPLE|. +// +// TODO(https://crbug.com/boringssl/407): This function should be const and +// thread-safe but is currently neither in some cases, notably if |req| was +// mutated. +OPENSSL_EXPORT int i2d_X509_REQ(X509_REQ *req, uint8_t **outp); + + +// X509_REQ_VERSION_1 is the version constant for |X509_REQ| objects. No other +// versions are defined. +#define X509_REQ_VERSION_1 0 + +// X509_REQ_get_version returns the numerical value of |req|'s version. This +// will always be |X509_REQ_VERSION_1| for valid CSRs. For compatibility, +// |d2i_X509_REQ| also accepts some invalid version numbers, in which case this +// function may return other values. +OPENSSL_EXPORT long X509_REQ_get_version(const X509_REQ *req); + +// X509_REQ_get_subject_name returns |req|'s subject name. Note this function is +// not const-correct for legacy reasons. +OPENSSL_EXPORT X509_NAME *X509_REQ_get_subject_name(const X509_REQ *req); + +// X509_REQ_get_pubkey returns |req|'s public key as an |EVP_PKEY|, or NULL if +// the public key was unsupported or could not be decoded. This function returns +// a reference to the |EVP_PKEY|. The caller must release the result with +// |EVP_PKEY_free| when done. +OPENSSL_EXPORT EVP_PKEY *X509_REQ_get_pubkey(X509_REQ *req); + +// X509_REQ_get0_signature sets |*out_sig| and |*out_alg| to the signature and +// signature algorithm of |req|, respectively. Either output pointer may be NULL +// to ignore the value. +OPENSSL_EXPORT void X509_REQ_get0_signature(const X509_REQ *req, + const ASN1_BIT_STRING **out_sig, + const X509_ALGOR **out_alg); + +// X509_REQ_get_signature_nid returns the NID corresponding to |req|'s signature +// algorithm, or |NID_undef| if the signature algorithm does not correspond to +// a known NID. +OPENSSL_EXPORT int X509_REQ_get_signature_nid(const X509_REQ *req); + + +// Issuing certificate requests. +// +// An |X509_REQ| object may also represent an incomplete CSR. Callers may +// construct empty |X509_REQ| objects, fill in fields individually, and finally +// sign the result. The following functions may be used for this purpose. + +// X509_REQ_new returns a newly-allocated, empty |X509_REQ| object, or NULL on +// error. This object may be filled in and then signed to construct a CSR. +OPENSSL_EXPORT X509_REQ *X509_REQ_new(void); + +// X509_REQ_set_version sets |req|'s version to |version|, which should be +// |X509_REQ_VERSION_1|. It returns one on success and zero on error. +// +// The only defined CSR version is |X509_REQ_VERSION_1|, so there is no need to +// call this function. +OPENSSL_EXPORT int X509_REQ_set_version(X509_REQ *req, long version); + +// X509_REQ_set_subject_name sets |req|'s subject to a copy of |name|. It +// returns one on success and zero on error. +OPENSSL_EXPORT int X509_REQ_set_subject_name(X509_REQ *req, X509_NAME *name); + +// X509_REQ_set_pubkey sets |req|'s public key to |pkey|. It returns one on +// success and zero on error. This function does not take ownership of |pkey| +// and internally copies and updates reference counts as needed. +OPENSSL_EXPORT int X509_REQ_set_pubkey(X509_REQ *req, EVP_PKEY *pkey); + +// X509_REQ_sign signs |req| with |pkey| and replaces the signature algorithm +// and signature fields. It returns one on success and zero on error. This +// function uses digest algorithm |md|, or |pkey|'s default if NULL. Other +// signing parameters use |pkey|'s defaults. To customize them, use +// |X509_REQ_sign_ctx|. +OPENSSL_EXPORT int X509_REQ_sign(X509_REQ *req, EVP_PKEY *pkey, + const EVP_MD *md); + +// X509_REQ_sign_ctx signs |req| with |ctx| and replaces the signature algorithm +// and signature fields. It returns one on success and zero on error. The +// signature algorithm and parameters come from |ctx|, which must have been +// initialized with |EVP_DigestSignInit|. The caller should configure the +// corresponding |EVP_PKEY_CTX| before calling this function. +OPENSSL_EXPORT int X509_REQ_sign_ctx(X509_REQ *req, EVP_MD_CTX *ctx); + +// i2d_re_X509_REQ_tbs serializes the CertificationRequestInfo (see RFC 2986) +// 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 +// for a new certificate request. +OPENSSL_EXPORT int i2d_re_X509_REQ_tbs(X509_REQ *req, uint8_t **outp); + +// X509_REQ_set1_signature_algo sets |req|'s signature algorithm to |algo| and +// returns one on success or zero on error. +OPENSSL_EXPORT int X509_REQ_set1_signature_algo(X509_REQ *req, + const X509_ALGOR *algo); + +// X509_REQ_set1_signature_value sets |req|'s signature to a copy of the +// |sig_len| bytes pointed by |sig|. It returns one on success and zero on +// error. +// +// Due to a specification error, PKCS#10 certificate requests store signatures +// in ASN.1 BIT STRINGs, but signature algorithms return byte strings rather +// than bit strings. This function creates a BIT STRING containing a whole +// number of bytes, with the bit order matching the DER encoding. This matches +// the encoding used by all X.509 signature algorithms. +OPENSSL_EXPORT int X509_REQ_set1_signature_value(X509_REQ *req, + const uint8_t *sig, + size_t sig_len); + + +// Names. +// +// An |X509_NAME| represents an X.509 Name structure (RFC 5280). X.509 names are +// a complex, hierarchical structure over a collection of attributes. Each name +// is sequence of relative distinguished names (RDNs), decreasing in +// specificity. For example, the first RDN may specify the country, while the +// next RDN may specify a locality. Each RDN is, itself, a set of attributes. +// Having more than one attribute in an RDN is uncommon, but possible. Within an +// RDN, attributes have the same level in specificity. Attribute types are +// OBJECT IDENTIFIERs. This determines the ASN.1 type of the value, which is +// commonly a string but may be other types. +// +// The |X509_NAME| representation flattens this two-level structure into a +// single list of attributes. Each attribute is stored in an |X509_NAME_ENTRY|, +// with also maintains the index of the RDN it is part of, accessible via +// |X509_NAME_ENTRY_set|. This can be used to recover the two-level structure. +// +// X.509 names are largely vestigial. Historically, DNS names were parsed out of +// the subject's common name attribute, but this is deprecated and has since +// moved to the subject alternative name extension. In modern usage, X.509 names +// are primarily opaque identifiers to link a certificate with its issuer. + +DEFINE_STACK_OF(X509_NAME_ENTRY) +DEFINE_STACK_OF(X509_NAME) + +// X509_NAME is an |ASN1_ITEM| whose ASN.1 type is X.509 Name (RFC 5280) and C +// type is |X509_NAME*|. +DECLARE_ASN1_ITEM(X509_NAME) + +// X509_NAME_new returns a new, empty |X509_NAME_new|, or NULL on +// error. +OPENSSL_EXPORT X509_NAME *X509_NAME_new(void); + +// X509_NAME_free releases memory associated with |name|. +OPENSSL_EXPORT void X509_NAME_free(X509_NAME *name); + +// d2i_X509_NAME parses up to |len| bytes from |*inp| as a DER-encoded X.509 +// Name (RFC 5280), as described in |d2i_SAMPLE_with_reuse|. +OPENSSL_EXPORT X509_NAME *d2i_X509_NAME(X509_NAME **out, const uint8_t **inp, + long len); + +// i2d_X509_NAME marshals |in| as a DER-encoded X.509 Name (RFC 5280), as +// described in |i2d_SAMPLE|. +// +// TODO(https://crbug.com/boringssl/407): This function should be const and +// thread-safe but is currently neither in some cases, notably if |in| was +// mutated. +OPENSSL_EXPORT int i2d_X509_NAME(X509_NAME *in, uint8_t **outp); + +// X509_NAME_dup returns a newly-allocated copy of |name|, or NULL on error. +// +// TODO(https://crbug.com/boringssl/407): This function should be const and +// thread-safe but is currently neither in some cases, notably if |name| was +// mutated. +OPENSSL_EXPORT X509_NAME *X509_NAME_dup(X509_NAME *name); + +// X509_NAME_get0_der sets |*out_der| and |*out_der_len| +// +// Avoid this function and prefer |i2d_X509_NAME|. It is one of the reasons +// these functions are not consistently thread-safe or const-correct. Depending +// on the resolution of https://crbug.com/boringssl/407, this function may be +// removed or cause poor performance. +OPENSSL_EXPORT int X509_NAME_get0_der(X509_NAME *name, const uint8_t **out_der, + size_t *out_der_len); + +// X509_NAME_set makes a copy of |name|. On success, it frees |*xn|, sets |*xn| +// to the copy, and returns one. Otherwise, it returns zero. +// +// TODO(https://crbug.com/boringssl/407): This function should be const and +// thread-safe but is currently neither in some cases, notably if |name| was +// mutated. +OPENSSL_EXPORT int X509_NAME_set(X509_NAME **xn, X509_NAME *name); + +// X509_NAME_entry_count returns the number of entries in |name|. +OPENSSL_EXPORT int X509_NAME_entry_count(const X509_NAME *name); + +// X509_NAME_get_index_by_NID returns the zero-based index of the first +// attribute in |name| with type |nid|, or -1 if there is none. |nid| should be +// one of the |NID_*| constants. If |lastpos| is non-negative, it begins +// searching at |lastpos+1|. To search all attributes, pass in -1, not zero. +// +// Indices from this function refer to |X509_NAME|'s flattened representation. +OPENSSL_EXPORT int X509_NAME_get_index_by_NID(const X509_NAME *name, int nid, + int lastpos); + +// X509_NAME_get_index_by_OBJ behaves like |X509_NAME_get_index_by_NID| but +// looks for attributes with type |obj|. +OPENSSL_EXPORT int X509_NAME_get_index_by_OBJ(const X509_NAME *name, + const ASN1_OBJECT *obj, + int lastpos); + +// X509_NAME_get_entry returns the attribute in |name| at index |loc|, or NULL +// if |loc| is out of range. |loc| is interpreted using |X509_NAME|'s flattened +// representation. This function returns a non-const pointer for OpenSSL +// compatibility, but callers should not mutate the result. Doing so will break +// internal invariants in the library. +OPENSSL_EXPORT X509_NAME_ENTRY *X509_NAME_get_entry(const X509_NAME *name, + int loc); + +// X509_NAME_delete_entry removes and returns the attribute in |name| at index +// |loc|, or NULL if |loc| is out of range. |loc| is interpreted using +// |X509_NAME|'s flattened representation. If the attribute is found, the caller +// is responsible for releasing the result with |X509_NAME_ENTRY_free|. +// +// This function will internally update RDN indices (see |X509_NAME_ENTRY_set|) +// so they continue to be consecutive. +OPENSSL_EXPORT X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, + int loc); + +// X509_NAME_add_entry adds a copy of |entry| to |name| and returns one on +// success or zero on error. If |loc| is -1, the entry is appended to |name|. +// Otherwise, it is inserted at index |loc|. If |set| is -1, the entry is added +// to the previous entry's RDN. If it is 0, the entry becomes a singleton RDN. +// If 1, it is added to next entry's RDN. +// +// This function will internally update RDN indices (see |X509_NAME_ENTRY_set|) +// so they continue to be consecutive. +OPENSSL_EXPORT int X509_NAME_add_entry(X509_NAME *name, + const X509_NAME_ENTRY *entry, int loc, + int set); + +// X509_NAME_add_entry_by_OBJ adds a new entry to |name| and returns one on +// success or zero on error. The entry's attribute type is |obj|. The entry's +// attribute value is determined by |type|, |bytes|, and |len|, as in +// |X509_NAME_ENTRY_set_data|. The entry's position is determined by |loc| and +// |set| as in |X509_NAME_entry|. +OPENSSL_EXPORT int X509_NAME_add_entry_by_OBJ(X509_NAME *name, + const ASN1_OBJECT *obj, int type, + const uint8_t *bytes, int len, + int loc, int set); + +// X509_NAME_add_entry_by_NID behaves like |X509_NAME_add_entry_by_OBJ| but sets +// the entry's attribute type to |nid|, which should be one of the |NID_*| +// constants. +OPENSSL_EXPORT int X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, + int type, const uint8_t *bytes, + int len, int loc, int set); + +// X509_NAME_add_entry_by_txt behaves like |X509_NAME_add_entry_by_OBJ| but sets +// the entry's attribute type to |field|, which is passed to |OBJ_txt2obj|. +OPENSSL_EXPORT int X509_NAME_add_entry_by_txt(X509_NAME *name, + const char *field, int type, + const uint8_t *bytes, int len, + int loc, int set); + +// X509_NAME_ENTRY is an |ASN1_ITEM| whose ASN.1 type is AttributeTypeAndValue +// (RFC 5280) and C type is |X509_NAME_ENTRY*|. +DECLARE_ASN1_ITEM(X509_NAME_ENTRY) + +// X509_NAME_ENTRY_new returns a new, empty |X509_NAME_ENTRY_new|, or NULL on +// error. +OPENSSL_EXPORT X509_NAME_ENTRY *X509_NAME_ENTRY_new(void); + +// X509_NAME_ENTRY_free releases memory associated with |entry|. +OPENSSL_EXPORT void X509_NAME_ENTRY_free(X509_NAME_ENTRY *entry); + +// d2i_X509_NAME_ENTRY parses up to |len| bytes from |*inp| as a DER-encoded +// AttributeTypeAndValue (RFC 5280), as described in |d2i_SAMPLE_with_reuse|. +OPENSSL_EXPORT X509_NAME_ENTRY *d2i_X509_NAME_ENTRY(X509_NAME_ENTRY **out, + const uint8_t **inp, + long len); + +// i2d_X509_NAME_ENTRY marshals |in| as a DER-encoded AttributeTypeAndValue (RFC +// 5280), as described in |i2d_SAMPLE|. +OPENSSL_EXPORT int i2d_X509_NAME_ENTRY(const X509_NAME_ENTRY *in, + uint8_t **outp); + +// X509_NAME_ENTRY_dup returns a newly-allocated copy of |entry|, or NULL on +// error. +OPENSSL_EXPORT X509_NAME_ENTRY *X509_NAME_ENTRY_dup( + const X509_NAME_ENTRY *entry); + +// X509_NAME_ENTRY_get_object returns |entry|'s attribute type. This function +// returns a non-const pointer for OpenSSL compatibility, but callers should not +// mutate the result. Doing so will break internal invariants in the library. +OPENSSL_EXPORT ASN1_OBJECT *X509_NAME_ENTRY_get_object( + const X509_NAME_ENTRY *entry); + +// X509_NAME_ENTRY_set_object sets |entry|'s attribute type to |obj|. It returns +// one on success and zero on error. +OPENSSL_EXPORT int X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *entry, + const ASN1_OBJECT *obj); + +// X509_NAME_ENTRY_get_data returns |entry|'s attribute value, represented as an +// |ASN1_STRING|. This value may have any ASN.1 type, so callers must check the +// type before interpreting the contents. This function returns a non-const +// pointer for OpenSSL compatibility, but callers should not mutate the result. +// Doing so will break internal invariants in the library. +// +// TODO(https://crbug.com/boringssl/412): Although the spec says any ASN.1 type +// is allowed, we currently only allow an ad-hoc set of types. Additionally, it +// is unclear if some types can even be represented by this function. +OPENSSL_EXPORT ASN1_STRING *X509_NAME_ENTRY_get_data( + const X509_NAME_ENTRY *entry); + +// X509_NAME_ENTRY_set_data sets |entry|'s value to |len| bytes from |bytes|. It +// returns one on success and zero on error. If |len| is -1, |bytes| must be a +// NUL-terminated C string and the length is determined by |strlen|. |bytes| is +// converted to an ASN.1 type as follows: +// +// If |type| is a |MBSTRING_*| constant, the value is an ASN.1 string. The +// string is determined by decoding |bytes| in the encoding specified by |type|, +// and then re-encoding it in a form appropriate for |entry|'s attribute type. +// See |ASN1_STRING_set_by_NID| for details. +// +// Otherwise, the value is an |ASN1_STRING| with type |type| and value |bytes|. +// See |ASN1_STRING| for how to format ASN.1 types as an |ASN1_STRING|. If +// |type| is |V_ASN1_UNDEF| the previous |ASN1_STRING| type is reused. +OPENSSL_EXPORT int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *entry, int type, + const uint8_t *bytes, int len); + +// X509_NAME_ENTRY_set returns the zero-based index of the RDN which contains +// |entry|. Consecutive entries with the same index are part of the same RDN. +OPENSSL_EXPORT int X509_NAME_ENTRY_set(const X509_NAME_ENTRY *entry); + +// X509_NAME_ENTRY_create_by_OBJ creates a new |X509_NAME_ENTRY| with attribute +// type |obj|. The attribute value is determined from |type|, |bytes|, and |len| +// as in |X509_NAME_ENTRY_set_data|. It returns the |X509_NAME_ENTRY| on success +// and NULL on error. +// +// If |out| is non-NULL and |*out| is NULL, it additionally sets |*out| to the +// result on success. If both |out| and |*out| are non-NULL, it updates the +// object at |*out| instead of allocating a new one. +OPENSSL_EXPORT X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ( + X509_NAME_ENTRY **out, const ASN1_OBJECT *obj, int type, + const uint8_t *bytes, int len); + +// X509_NAME_ENTRY_create_by_NID behaves like |X509_NAME_ENTRY_create_by_OBJ| +// except the attribute type is |nid|, which should be one of the |NID_*| +// constants. +OPENSSL_EXPORT X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID( + X509_NAME_ENTRY **out, int nid, int type, const uint8_t *bytes, int len); + +// X509_NAME_ENTRY_create_by_txt behaves like |X509_NAME_ENTRY_create_by_OBJ| +// except the attribute type is |field|, which is passed to |OBJ_txt2obj|. +OPENSSL_EXPORT X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_txt( + X509_NAME_ENTRY **out, const char *field, int type, const uint8_t *bytes, + int len); + + +// Extensions. +// +// X.509 certificates and CRLs may contain a list of extensions (RFC 5280). +// Extensions have a type, specified by an object identifier (|ASN1_OBJECT|) and +// a byte string value, which should a DER-encoded structure whose type is +// determined by the extension type. This library represents extensions with the +// |X509_EXTENSION| type. + +// X509_EXTENSION is an |ASN1_ITEM| whose ASN.1 type is X.509 Extension (RFC +// 5280) and C type is |X509_EXTENSION*|. +DECLARE_ASN1_ITEM(X509_EXTENSION) + +// X509_EXTENSION_new returns a newly-allocated, empty |X509_EXTENSION| object +// or NULL on error. +OPENSSL_EXPORT X509_EXTENSION *X509_EXTENSION_new(void); + +// X509_EXTENSION_free releases memory associated with |ex|. +OPENSSL_EXPORT void X509_EXTENSION_free(X509_EXTENSION *ex); + +// d2i_X509_EXTENSION parses up to |len| bytes from |*inp| as a DER-encoded +// X.509 Extension (RFC 5280), as described in |d2i_SAMPLE_with_reuse|. +OPENSSL_EXPORT X509_EXTENSION *d2i_X509_EXTENSION(X509_EXTENSION **out, + const uint8_t **inp, + long len); + +// i2d_X509_EXTENSION marshals |alg| as a DER-encoded X.509 Extension (RFC +// 5280), as described in |i2d_SAMPLE|. +OPENSSL_EXPORT int i2d_X509_EXTENSION(const X509_EXTENSION *alg, + uint8_t **outp); + +// X509_EXTENSION_dup returns a newly-allocated copy of |ex|, or NULL on error. +// This function works by serializing the structure, so if |ex| is incomplete, +// it may fail. +OPENSSL_EXPORT X509_EXTENSION *X509_EXTENSION_dup(const X509_EXTENSION *ex); + +// X509_EXTENSION_create_by_NID creates a new |X509_EXTENSION| with type |nid|, +// value |data|, and critical bit |crit|. It returns an |X509_EXTENSION| on +// success, and NULL on error. |nid| should be a |NID_*| constant. +// +// If |ex| and |*ex| are both non-NULL, |*ex| is used to hold the result, +// otherwise a new object is allocated. If |ex| is non-NULL and |*ex| is NULL, +// the function sets |*ex| to point to the newly allocated result, in addition +// to returning the result. +OPENSSL_EXPORT X509_EXTENSION *X509_EXTENSION_create_by_NID( + X509_EXTENSION **ex, int nid, int crit, const ASN1_OCTET_STRING *data); + +// X509_EXTENSION_create_by_OBJ behaves like |X509_EXTENSION_create_by_NID|, but +// the extension type is determined by an |ASN1_OBJECT|. +OPENSSL_EXPORT X509_EXTENSION *X509_EXTENSION_create_by_OBJ( + X509_EXTENSION **ex, const ASN1_OBJECT *obj, int crit, + const ASN1_OCTET_STRING *data); + +// X509_EXTENSION_get_object returns |ex|'s extension type. This function +// returns a non-const pointer for OpenSSL compatibility, but callers should not +// mutate the result. +OPENSSL_EXPORT ASN1_OBJECT *X509_EXTENSION_get_object(const X509_EXTENSION *ex); + +// X509_EXTENSION_get_data returns |ne|'s extension value. This function returns +// a non-const pointer for OpenSSL compatibility, but callers should not mutate +// the result. +OPENSSL_EXPORT ASN1_OCTET_STRING *X509_EXTENSION_get_data( + const X509_EXTENSION *ne); + +// X509_EXTENSION_get_critical returns one if |ex| is critical and zero +// otherwise. +OPENSSL_EXPORT int X509_EXTENSION_get_critical(const X509_EXTENSION *ex); + +// X509_EXTENSION_set_object sets |ex|'s extension type to |obj|. It returns one +// on success and zero on error. +OPENSSL_EXPORT int X509_EXTENSION_set_object(X509_EXTENSION *ex, + const ASN1_OBJECT *obj); + +// X509_EXTENSION_set_critical sets |ex| to critical if |crit| is non-zero and +// to non-critical if |crit| is zero. +OPENSSL_EXPORT int X509_EXTENSION_set_critical(X509_EXTENSION *ex, int crit); + +// X509_EXTENSION_set_data set's |ex|'s extension value to a copy of |data|. It +// returns one on success and zero on error. +OPENSSL_EXPORT int X509_EXTENSION_set_data(X509_EXTENSION *ex, + const ASN1_OCTET_STRING *data); + + +// Extension lists. +// +// The following functions manipulate lists of extensions. Most of them have +// corresponding functions on the containing |X509|, |X509_CRL|, or +// |X509_REVOKED|. + +DEFINE_STACK_OF(X509_EXTENSION) +typedef STACK_OF(X509_EXTENSION) X509_EXTENSIONS; + +// X509_EXTENSIONS is an |ASN1_ITEM| whose ASN.1 type is SEQUENCE of Extension +// (RFC 5280) and C type is |STACK_OF(X509_EXTENSION)*|. +DECLARE_ASN1_ITEM(X509_EXTENSIONS) + +// d2i_X509_EXTENSIONS parses up to |len| bytes from |*inp| as a DER-encoded +// SEQUENCE OF Extension (RFC 5280), as described in |d2i_SAMPLE_with_reuse|. +OPENSSL_EXPORT X509_EXTENSIONS *d2i_X509_EXTENSIONS(X509_EXTENSIONS **out, + const uint8_t **inp, + long len); + +// i2d_X509_EXTENSIONS marshals |alg| as a DER-encoded SEQUENCE OF Extension +// (RFC 5280), as described in |i2d_SAMPLE|. +OPENSSL_EXPORT int i2d_X509_EXTENSIONS(const X509_EXTENSIONS *alg, + uint8_t **outp); + +// X509v3_get_ext_count returns the number of extensions in |x|. +OPENSSL_EXPORT int X509v3_get_ext_count(const STACK_OF(X509_EXTENSION) *x); + +// X509v3_get_ext_by_NID returns the index of the first extension in |x| with +// type |nid|, or a negative number if not found. If found, callers can use +// |X509v3_get_ext| to look up the extension by index. +// +// If |lastpos| is non-negative, it begins searching at |lastpos| + 1. Callers +// can thus loop over all matching extensions by first passing -1 and then +// passing the previously-returned value until no match is returned. +OPENSSL_EXPORT int X509v3_get_ext_by_NID(const STACK_OF(X509_EXTENSION) *x, + int nid, int lastpos); + +// X509v3_get_ext_by_OBJ behaves like |X509v3_get_ext_by_NID| but looks for +// extensions matching |obj|. +OPENSSL_EXPORT int X509v3_get_ext_by_OBJ(const STACK_OF(X509_EXTENSION) *x, + const ASN1_OBJECT *obj, int lastpos); + +// X509v3_get_ext_by_critical returns the index of the first extension in |x| +// whose critical bit matches |crit|, or a negative number if no such extension +// was found. +// +// If |lastpos| is non-negative, it begins searching at |lastpos| + 1. Callers +// can thus loop over all matching extensions by first passing -1 and then +// passing the previously-returned value until no match is returned. +OPENSSL_EXPORT int X509v3_get_ext_by_critical(const STACK_OF(X509_EXTENSION) *x, + int crit, int lastpos); + +// X509v3_get_ext returns the extension in |x| at index |loc|, or NULL if |loc| +// is out of bounds. This function returns a non-const pointer for OpenSSL +// compatibility, but callers should not mutate the result. +OPENSSL_EXPORT X509_EXTENSION *X509v3_get_ext(const STACK_OF(X509_EXTENSION) *x, + int loc); + +// X509v3_delete_ext removes the extension in |x| at index |loc| and returns the +// removed extension, or NULL if |loc| was out of bounds. If an extension was +// returned, the caller must release it with |X509_EXTENSION_free|. +OPENSSL_EXPORT X509_EXTENSION *X509v3_delete_ext(STACK_OF(X509_EXTENSION) *x, + int loc); + +// X509v3_add_ext adds a copy of |ex| to the extension list in |*x|. If |*x| is +// NULL, it allocates a new |STACK_OF(X509_EXTENSION)| to hold the copy and sets +// |*x| to the new list. It returns |*x| on success and NULL on error. The +// caller retains ownership of |ex| and can release it independently of |*x|. +// +// The new extension is inserted at index |loc|, shifting extensions to the +// right. If |loc| is -1 or out of bounds, the new extension is appended to the +// list. +OPENSSL_EXPORT STACK_OF(X509_EXTENSION) *X509v3_add_ext( + STACK_OF(X509_EXTENSION) **x, const X509_EXTENSION *ex, int loc); + + +// Algorithm identifiers. +// +// An |X509_ALGOR| represents an AlgorithmIdentifier structure, used in X.509 +// to represent signature algorithms and public key algorithms. + +DEFINE_STACK_OF(X509_ALGOR) + +// X509_ALGOR is an |ASN1_ITEM| whose ASN.1 type is AlgorithmIdentifier and C +// type is |X509_ALGOR*|. +DECLARE_ASN1_ITEM(X509_ALGOR) + +// X509_ALGOR_new returns a newly-allocated, empty |X509_ALGOR| object, or NULL +// on error. +OPENSSL_EXPORT X509_ALGOR *X509_ALGOR_new(void); + +// X509_ALGOR_dup returns a newly-allocated copy of |alg|, or NULL on error. +// This function works by serializing the structure, so if |alg| is incomplete, +// it may fail. +OPENSSL_EXPORT X509_ALGOR *X509_ALGOR_dup(const X509_ALGOR *alg); + +// X509_ALGOR_free releases memory associated with |alg|. +OPENSSL_EXPORT void X509_ALGOR_free(X509_ALGOR *alg); + +// d2i_X509_ALGOR parses up to |len| bytes from |*inp| as a DER-encoded +// AlgorithmIdentifier, as described in |d2i_SAMPLE_with_reuse|. +OPENSSL_EXPORT X509_ALGOR *d2i_X509_ALGOR(X509_ALGOR **out, const uint8_t **inp, + long len); + +// i2d_X509_ALGOR marshals |alg| as a DER-encoded AlgorithmIdentifier, as +// described in |i2d_SAMPLE|. +OPENSSL_EXPORT int i2d_X509_ALGOR(const X509_ALGOR *alg, uint8_t **outp); + +// X509_ALGOR_set0 sets |alg| to an AlgorithmIdentifier with algorithm |obj| and +// parameter determined by |param_type| and |param_value|. It returns one on +// success and zero on error. This function takes ownership of |obj| and +// |param_value| on success. +// +// If |param_type| is |V_ASN1_UNDEF|, the parameter is omitted. If |param_type| +// is zero, the parameter is left unchanged. Otherwise, |param_type| and +// |param_value| are interpreted as in |ASN1_TYPE_set|. +// +// Note omitting the parameter (|V_ASN1_UNDEF|) and encoding an explicit NULL +// value (|V_ASN1_NULL|) are different. Some algorithms require one and some the +// other. Consult the relevant specification before calling this function. The +// correct parameter for an RSASSA-PKCS1-v1_5 signature is |V_ASN1_NULL|. The +// correct one for an ECDSA or Ed25519 signature is |V_ASN1_UNDEF|. +OPENSSL_EXPORT int X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *obj, + int param_type, void *param_value); + +// X509_ALGOR_get0 sets |*out_obj| to the |alg|'s algorithm. If |alg|'s +// parameter is omitted, it sets |*out_param_type| and |*out_param_value| to +// |V_ASN1_UNDEF| and NULL. Otherwise, it sets |*out_param_type| and +// |*out_param_value| to the parameter, using the same representation as +// |ASN1_TYPE_set0|. See |ASN1_TYPE_set0| and |ASN1_TYPE| for details. +// +// Callers that require the parameter in serialized form should, after checking +// for |V_ASN1_UNDEF|, use |ASN1_TYPE_set1| and |d2i_ASN1_TYPE|, rather than +// inspecting |*out_param_value|. +// +// Each of |out_obj|, |out_param_type|, and |out_param_value| may be NULL to +// ignore the output. If |out_param_type| is NULL, |out_param_value| is ignored. +// +// WARNING: If |*out_param_type| is set to |V_ASN1_UNDEF|, OpenSSL and older +// revisions of BoringSSL leave |*out_param_value| unset rather than setting it +// to NULL. Callers that support both OpenSSL and BoringSSL should not assume +// |*out_param_value| is uniformly initialized. +OPENSSL_EXPORT void X509_ALGOR_get0(const ASN1_OBJECT **out_obj, + int *out_param_type, + const void **out_param_value, + const X509_ALGOR *alg); + +// X509_ALGOR_set_md sets |alg| to the hash function |md|. Note this +// AlgorithmIdentifier represents the hash function itself, not a signature +// algorithm that uses |md|. +OPENSSL_EXPORT void X509_ALGOR_set_md(X509_ALGOR *alg, const EVP_MD *md); + +// X509_ALGOR_cmp returns zero if |a| and |b| are equal, and some non-zero value +// otherwise. Note this function can only be used for equality checks, not an +// ordering. +OPENSSL_EXPORT int X509_ALGOR_cmp(const X509_ALGOR *a, const X509_ALGOR *b); + + +// Printing functions. +// +// The following functions output human-readable representations of +// X.509-related structures. They should only be used for debugging or logging +// and not parsed programmatically. + +// X509_signature_dump writes a human-readable representation of |sig| to |bio|, +// indented with |indent| spaces. It returns one on success and zero on error. +OPENSSL_EXPORT int X509_signature_dump(BIO *bio, const ASN1_STRING *sig, + int indent); + +// X509_signature_print writes a human-readable representation of |alg| and +// |sig| to |bio|. It returns one on success and zero on error. +OPENSSL_EXPORT int X509_signature_print(BIO *bio, const X509_ALGOR *alg, + const ASN1_STRING *sig); + + +// Convenience functions. + +// X509_pubkey_digest hashes the contents of the BIT STRING in |x509|'s +// subjectPublicKeyInfo field with |md| and writes the result to |out|. +// |EVP_MD_CTX_size| bytes are written, which is at most |EVP_MAX_MD_SIZE|. If +// |out_len| is not NULL, |*out_len| is set to the number of bytes written. This +// function returns one on success and zero on error. +// +// This hash omits the BIT STRING tag, length, and number of unused bits. It +// also omits the AlgorithmIdentifier which describes the key type. It +// corresponds to the OCSP KeyHash definition and is not suitable for other +// purposes. +OPENSSL_EXPORT int X509_pubkey_digest(const X509 *x509, const EVP_MD *md, + uint8_t *out, unsigned *out_len); + +// X509_digest hashes |x509|'s DER encoding with |md| and writes the result to +// |out|. |EVP_MD_CTX_size| bytes are written, which is at most +// |EVP_MAX_MD_SIZE|. If |out_len| is not NULL, |*out_len| is set to the number +// of bytes written. This function returns one on success and zero on error. +// Note this digest covers the entire certificate, not just the signed portion. +OPENSSL_EXPORT int X509_digest(const X509 *x509, const EVP_MD *md, uint8_t *out, + unsigned *out_len); + +// X509_CRL_digest hashes |crl|'s DER encoding with |md| and writes the result +// to |out|. |EVP_MD_CTX_size| bytes are written, which is at most +// |EVP_MAX_MD_SIZE|. If |out_len| is not NULL, |*out_len| is set to the number +// of bytes written. This function returns one on success and zero on error. +// Note this digest covers the entire CRL, not just the signed portion. +OPENSSL_EXPORT int X509_CRL_digest(const X509_CRL *crl, const EVP_MD *md, + uint8_t *out, unsigned *out_len); + +// X509_REQ_digest hashes |req|'s DER encoding with |md| and writes the result +// to |out|. |EVP_MD_CTX_size| bytes are written, which is at most +// |EVP_MAX_MD_SIZE|. If |out_len| is not NULL, |*out_len| is set to the number +// of bytes written. This function returns one on success and zero on error. +// Note this digest covers the entire certificate request, not just the signed +// portion. +OPENSSL_EXPORT int X509_REQ_digest(const X509_REQ *req, const EVP_MD *md, + uint8_t *out, unsigned *out_len); + +// X509_NAME_digest hashes |name|'s DER encoding with |md| and writes the result +// to |out|. |EVP_MD_CTX_size| bytes are written, which is at most +// |EVP_MAX_MD_SIZE|. If |out_len| is not NULL, |*out_len| is set to the number +// of bytes written. This function returns one on success and zero on error. +OPENSSL_EXPORT int X509_NAME_digest(const X509_NAME *name, const EVP_MD *md, + uint8_t *out, unsigned *out_len); + +// The following functions behave like the corresponding unsuffixed |d2i_*| +// functions, but read the result from |bp| instead. Callers using these +// functions with memory |BIO|s to parse structures already in memory should use +// |d2i_*| instead. +OPENSSL_EXPORT X509 *d2i_X509_bio(BIO *bp, X509 **x509); +OPENSSL_EXPORT X509_CRL *d2i_X509_CRL_bio(BIO *bp, X509_CRL **crl); +OPENSSL_EXPORT X509_REQ *d2i_X509_REQ_bio(BIO *bp, X509_REQ **req); +OPENSSL_EXPORT RSA *d2i_RSAPrivateKey_bio(BIO *bp, RSA **rsa); +OPENSSL_EXPORT RSA *d2i_RSAPublicKey_bio(BIO *bp, RSA **rsa); +OPENSSL_EXPORT RSA *d2i_RSA_PUBKEY_bio(BIO *bp, RSA **rsa); +OPENSSL_EXPORT DSA *d2i_DSA_PUBKEY_bio(BIO *bp, DSA **dsa); +OPENSSL_EXPORT DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa); +OPENSSL_EXPORT EC_KEY *d2i_EC_PUBKEY_bio(BIO *bp, EC_KEY **eckey); +OPENSSL_EXPORT EC_KEY *d2i_ECPrivateKey_bio(BIO *bp, EC_KEY **eckey); +OPENSSL_EXPORT X509_SIG *d2i_PKCS8_bio(BIO *bp, X509_SIG **p8); +OPENSSL_EXPORT PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio( + BIO *bp, PKCS8_PRIV_KEY_INFO **p8inf); +OPENSSL_EXPORT EVP_PKEY *d2i_PUBKEY_bio(BIO *bp, EVP_PKEY **a); +OPENSSL_EXPORT DH *d2i_DHparams_bio(BIO *bp, DH **dh); + +// d2i_PrivateKey_bio behaves like |d2i_AutoPrivateKey|, but reads from |bp| +// instead. +OPENSSL_EXPORT EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a); + +// The following functions behave like the corresponding unsuffixed |i2d_*| +// functions, but write the result to |bp|. They return one on success and zero +// on error. Callers using them with memory |BIO|s to encode structures to +// memory should use |i2d_*| directly instead. +OPENSSL_EXPORT int i2d_X509_bio(BIO *bp, X509 *x509); +OPENSSL_EXPORT int i2d_X509_CRL_bio(BIO *bp, X509_CRL *crl); +OPENSSL_EXPORT int i2d_X509_REQ_bio(BIO *bp, X509_REQ *req); +OPENSSL_EXPORT int i2d_RSAPrivateKey_bio(BIO *bp, RSA *rsa); +OPENSSL_EXPORT int i2d_RSAPublicKey_bio(BIO *bp, RSA *rsa); +OPENSSL_EXPORT int i2d_RSA_PUBKEY_bio(BIO *bp, RSA *rsa); +OPENSSL_EXPORT int i2d_DSA_PUBKEY_bio(BIO *bp, DSA *dsa); +OPENSSL_EXPORT int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa); +OPENSSL_EXPORT int i2d_EC_PUBKEY_bio(BIO *bp, EC_KEY *eckey); +OPENSSL_EXPORT int i2d_ECPrivateKey_bio(BIO *bp, EC_KEY *eckey); +OPENSSL_EXPORT int i2d_PKCS8_bio(BIO *bp, X509_SIG *p8); +OPENSSL_EXPORT int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, + PKCS8_PRIV_KEY_INFO *p8inf); +OPENSSL_EXPORT int i2d_PrivateKey_bio(BIO *bp, EVP_PKEY *pkey); +OPENSSL_EXPORT int i2d_PUBKEY_bio(BIO *bp, EVP_PKEY *pkey); +OPENSSL_EXPORT int i2d_DHparams_bio(BIO *bp, const DH *dh); + +// i2d_PKCS8PrivateKeyInfo_bio encodes |key| as a PKCS#8 PrivateKeyInfo +// structure (see |EVP_marshal_private_key|) and writes the result to |bp|. It +// returns one on success and zero on error. +OPENSSL_EXPORT int i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key); + +// The following functions behave like the corresponding |d2i_*_bio| functions, +// but read from |fp| instead. +OPENSSL_EXPORT X509 *d2i_X509_fp(FILE *fp, X509 **x509); +OPENSSL_EXPORT X509_CRL *d2i_X509_CRL_fp(FILE *fp, X509_CRL **crl); +OPENSSL_EXPORT X509_REQ *d2i_X509_REQ_fp(FILE *fp, X509_REQ **req); +OPENSSL_EXPORT RSA *d2i_RSAPrivateKey_fp(FILE *fp, RSA **rsa); +OPENSSL_EXPORT RSA *d2i_RSAPublicKey_fp(FILE *fp, RSA **rsa); +OPENSSL_EXPORT RSA *d2i_RSA_PUBKEY_fp(FILE *fp, RSA **rsa); +OPENSSL_EXPORT DSA *d2i_DSA_PUBKEY_fp(FILE *fp, DSA **dsa); +OPENSSL_EXPORT DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa); +OPENSSL_EXPORT EC_KEY *d2i_EC_PUBKEY_fp(FILE *fp, EC_KEY **eckey); +OPENSSL_EXPORT EC_KEY *d2i_ECPrivateKey_fp(FILE *fp, EC_KEY **eckey); +OPENSSL_EXPORT X509_SIG *d2i_PKCS8_fp(FILE *fp, X509_SIG **p8); +OPENSSL_EXPORT PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp( + FILE *fp, PKCS8_PRIV_KEY_INFO **p8inf); +OPENSSL_EXPORT EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a); +OPENSSL_EXPORT EVP_PKEY *d2i_PUBKEY_fp(FILE *fp, EVP_PKEY **a); + +// The following functions behave like the corresponding |i2d_*_bio| functions, +// but write to |fp| instead. +OPENSSL_EXPORT int i2d_X509_fp(FILE *fp, X509 *x509); +OPENSSL_EXPORT int i2d_X509_CRL_fp(FILE *fp, X509_CRL *crl); +OPENSSL_EXPORT int i2d_X509_REQ_fp(FILE *fp, X509_REQ *req); +OPENSSL_EXPORT int i2d_RSAPrivateKey_fp(FILE *fp, RSA *rsa); +OPENSSL_EXPORT int i2d_RSAPublicKey_fp(FILE *fp, RSA *rsa); +OPENSSL_EXPORT int i2d_RSA_PUBKEY_fp(FILE *fp, RSA *rsa); +OPENSSL_EXPORT int i2d_DSA_PUBKEY_fp(FILE *fp, DSA *dsa); +OPENSSL_EXPORT int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa); +OPENSSL_EXPORT int i2d_EC_PUBKEY_fp(FILE *fp, EC_KEY *eckey); +OPENSSL_EXPORT int i2d_ECPrivateKey_fp(FILE *fp, EC_KEY *eckey); +OPENSSL_EXPORT int i2d_PKCS8_fp(FILE *fp, X509_SIG *p8); +OPENSSL_EXPORT int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, + PKCS8_PRIV_KEY_INFO *p8inf); +OPENSSL_EXPORT int i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, EVP_PKEY *key); +OPENSSL_EXPORT int i2d_PrivateKey_fp(FILE *fp, EVP_PKEY *pkey); +OPENSSL_EXPORT int i2d_PUBKEY_fp(FILE *fp, EVP_PKEY *pkey); + + +// ex_data functions. +// +// See |ex_data.h| for details. + +OPENSSL_EXPORT int X509_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_set_ex_data(X509 *r, int idx, void *arg); +OPENSSL_EXPORT void *X509_get_ex_data(X509 *r, int idx); + +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); + + +// Deprecated functions. + +// X509_get_notBefore returns |x509|'s notBefore time. Note this function is not +// const-correct for legacy reasons. Use |X509_get0_notBefore| or +// |X509_getm_notBefore| instead. +OPENSSL_EXPORT ASN1_TIME *X509_get_notBefore(const X509 *x509); + +// X509_get_notAfter returns |x509|'s notAfter time. Note this function is not +// const-correct for legacy reasons. Use |X509_get0_notAfter| or +// |X509_getm_notAfter| instead. +OPENSSL_EXPORT ASN1_TIME *X509_get_notAfter(const X509 *x509); + +// X509_set_notBefore calls |X509_set1_notBefore|. Use |X509_set1_notBefore| +// instead. +OPENSSL_EXPORT int X509_set_notBefore(X509 *x509, const ASN1_TIME *tm); + +// X509_set_notAfter calls |X509_set1_notAfter|. Use |X509_set1_notAfter| +// instead. +OPENSSL_EXPORT int X509_set_notAfter(X509 *x509, const ASN1_TIME *tm); + +// X509_CRL_get_lastUpdate returns a mutable pointer to |crl|'s thisUpdate time. +// The OpenSSL API refers to this field as lastUpdate. +// +// Use |X509_CRL_get0_lastUpdate| or |X509_CRL_set1_lastUpdate| instead. +OPENSSL_EXPORT ASN1_TIME *X509_CRL_get_lastUpdate(X509_CRL *crl); + +// X509_CRL_get_nextUpdate returns a mutable pointer to |crl|'s nextUpdate time, +// or NULL if |crl| has none. Use |X509_CRL_get0_nextUpdate| or +// |X509_CRL_set1_nextUpdate| instead. +OPENSSL_EXPORT ASN1_TIME *X509_CRL_get_nextUpdate(X509_CRL *crl); + +// X509_extract_key is a legacy alias to |X509_get_pubkey|. Use +// |X509_get_pubkey| instead. +#define X509_extract_key(x) X509_get_pubkey(x) + +// X509_REQ_extract_key is a legacy alias for |X509_REQ_get_pubkey|. +#define X509_REQ_extract_key(a) X509_REQ_get_pubkey(a) + +// X509_name_cmp is a legacy alias for |X509_NAME_cmp|. +#define X509_name_cmp(a, b) X509_NAME_cmp((a), (b)) + +// The following symbols are deprecated aliases to |X509_CRL_set1_*|. +#define X509_CRL_set_lastUpdate X509_CRL_set1_lastUpdate +#define X509_CRL_set_nextUpdate X509_CRL_set1_nextUpdate + +// X509_get_serialNumber returns a mutable pointer to |x509|'s serial number. +// Prefer |X509_get0_serialNumber|. +OPENSSL_EXPORT ASN1_INTEGER *X509_get_serialNumber(X509 *x509); + +// X509_NAME_get_text_by_OBJ finds the first attribute with type |obj| in +// |name|. If found, it ignores the value's ASN.1 type, writes the raw +// |ASN1_STRING| representation to |buf|, followed by a NUL byte, and +// returns the number of bytes in output, excluding the NUL byte. +// +// This function writes at most |len| bytes, including the NUL byte. If |len| is +// not large enough, it silently truncates the output to fit. If |buf| is NULL, +// it instead writes enough and returns the number of bytes in the output, +// excluding the NUL byte. +// +// WARNING: Do not use this function. It does not return enough information for +// the caller to correctly interpret its output. The attribute value may be of +// any type, including one of several ASN.1 string encodings, but this function +// only outputs the raw |ASN1_STRING| representation. See +// https://crbug.com/boringssl/436. +OPENSSL_EXPORT int X509_NAME_get_text_by_OBJ(const X509_NAME *name, + const ASN1_OBJECT *obj, char *buf, + int len); + +// X509_NAME_get_text_by_NID behaves like |X509_NAME_get_text_by_OBJ| except it +// finds an attribute of type |nid|, which should be one of the |NID_*| +// constants. +OPENSSL_EXPORT int X509_NAME_get_text_by_NID(const X509_NAME *name, int nid, + char *buf, int len); + + +// Private structures. + +struct X509_algor_st { + ASN1_OBJECT *algorithm; + ASN1_TYPE *parameter; +} /* X509_ALGOR */; + + +// Functions below this point have not yet been organized into sections. + #define X509_FILETYPE_PEM 1 #define X509_FILETYPE_ASN1 2 #define X509_FILETYPE_DEFAULT 3 @@ -110,25 +1565,6 @@ extern "C" { #define X509v3_KU_DECIPHER_ONLY 0x8000 #define X509v3_KU_UNDEF 0xffff -struct X509_algor_st { - ASN1_OBJECT *algorithm; - ASN1_TYPE *parameter; -} /* X509_ALGOR */; - -DECLARE_ASN1_FUNCTIONS(X509_ALGOR) - -DEFINE_STACK_OF(X509_ALGOR) - -typedef STACK_OF(X509_ALGOR) X509_ALGORS; - -DEFINE_STACK_OF(X509_NAME_ENTRY) - -DEFINE_STACK_OF(X509_NAME) - -typedef STACK_OF(X509_EXTENSION) X509_EXTENSIONS; - -DEFINE_STACK_OF(X509_EXTENSION) - DEFINE_STACK_OF(X509_ATTRIBUTE) // This stuff is certificate "auxiliary info" @@ -139,8 +1575,6 @@ DEFINE_STACK_OF(X509_ATTRIBUTE) DECLARE_STACK_OF(DIST_POINT) DECLARE_STACK_OF(GENERAL_NAME) -DEFINE_STACK_OF(X509) - // This is used for a table of trust checking functions struct x509_trust_st { @@ -254,8 +1688,6 @@ DEFINE_STACK_OF(X509_REVOKED) DECLARE_STACK_OF(GENERAL_NAMES) -DEFINE_STACK_OF(X509_CRL) - struct private_key_st { int version; // The PKCS#8 data types @@ -301,87 +1733,6 @@ struct Netscape_spki_st { ASN1_BIT_STRING *signature; } /* NETSCAPE_SPKI */; -// 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 -// internal caches. - -// X509_VERSION_* are X.509 version numbers. Note the numerical values of all -// defined X.509 versions are one less than the named version. -#define X509_VERSION_1 0 -#define X509_VERSION_2 1 -#define X509_VERSION_3 2 - -// X509_get_version returns the numerical value of |x509|'s version, which will -// be one of the |X509_VERSION_*| constants. -OPENSSL_EXPORT long X509_get_version(const X509 *x509); - -// X509_set_version sets |x509|'s version to |version|, which should be one of -// the |X509V_VERSION_*| constants. It returns one on success and zero on error. -// -// If unsure, use |X509_VERSION_3|. -OPENSSL_EXPORT int X509_set_version(X509 *x509, long version); - -// X509_get0_serialNumber returns |x509|'s serial number. -OPENSSL_EXPORT const ASN1_INTEGER *X509_get0_serialNumber(const X509 *x509); - -// X509_set_serialNumber sets |x509|'s serial number to |serial|. It returns one -// on success and zero on error. -OPENSSL_EXPORT int X509_set_serialNumber(X509 *x509, - const ASN1_INTEGER *serial); - -// X509_get0_notBefore returns |x509|'s notBefore time. -OPENSSL_EXPORT const ASN1_TIME *X509_get0_notBefore(const X509 *x509); - -// X509_get0_notAfter returns |x509|'s notAfter time. -OPENSSL_EXPORT const ASN1_TIME *X509_get0_notAfter(const X509 *x509); - -// X509_set1_notBefore sets |x509|'s notBefore time to |tm|. It returns one on -// success and zero on error. -OPENSSL_EXPORT int X509_set1_notBefore(X509 *x509, const ASN1_TIME *tm); - -// X509_set1_notAfter sets |x509|'s notAfter time to |tm|. it returns one on -// success and zero on error. -OPENSSL_EXPORT int X509_set1_notAfter(X509 *x509, const ASN1_TIME *tm); - -// X509_getm_notBefore returns a mutable pointer to |x509|'s notBefore time. -OPENSSL_EXPORT ASN1_TIME *X509_getm_notBefore(X509 *x509); - -// X509_getm_notAfter returns a mutable pointer to |x509|'s notAfter time. -OPENSSL_EXPORT ASN1_TIME *X509_getm_notAfter(X509 *x); - -// X509_get_notBefore returns |x509|'s notBefore time. Note this function is not -// const-correct for legacy reasons. Use |X509_get0_notBefore| or -// |X509_getm_notBefore| instead. -OPENSSL_EXPORT ASN1_TIME *X509_get_notBefore(const X509 *x509); - -// X509_get_notAfter returns |x509|'s notAfter time. Note this function is not -// const-correct for legacy reasons. Use |X509_get0_notAfter| or -// |X509_getm_notAfter| instead. -OPENSSL_EXPORT ASN1_TIME *X509_get_notAfter(const X509 *x509); - -// X509_set_notBefore calls |X509_set1_notBefore|. Use |X509_set1_notBefore| -// instead. -OPENSSL_EXPORT int X509_set_notBefore(X509 *x509, const ASN1_TIME *tm); - -// X509_set_notAfter calls |X509_set1_notAfter|. Use |X509_set1_notAfter| -// instead. -OPENSSL_EXPORT int X509_set_notAfter(X509 *x509, const ASN1_TIME *tm); - -// X509_get0_uids sets |*out_issuer_uid| to a non-owning pointer to the -// issuerUID field of |x509|, or NULL if |x509| has no issuerUID. It similarly -// outputs |x509|'s subjectUID field to |*out_subject_uid|. -// -// Callers may pass NULL to either |out_issuer_uid| or |out_subject_uid| to -// ignore the corresponding field. -OPENSSL_EXPORT void X509_get0_uids(const X509 *x509, - const ASN1_BIT_STRING **out_issuer_uid, - const ASN1_BIT_STRING **out_subject_uid); - -// X509_extract_key is a legacy alias to |X509_get_pubkey|. Use -// |X509_get_pubkey| instead. -#define X509_extract_key(x) X509_get_pubkey(x) - // X509_get_pathlen returns path length constraint from the basic constraints // extension in |x509|. (See RFC 5280, section 4.2.1.9.) It returns -1 if the // constraint is not present, or if some extension in |x509| was invalid. @@ -391,76 +1742,6 @@ OPENSSL_EXPORT void X509_get0_uids(const X509 *x509, // |EXFLAG_INVALID| bit. OPENSSL_EXPORT long X509_get_pathlen(X509 *x509); -// X509_REQ_VERSION_1 is the version constant for |X509_REQ| objects. No other -// versions are defined. -#define X509_REQ_VERSION_1 0 - -// X509_REQ_get_version returns the numerical value of |req|'s version. This -// will always be |X509_REQ_VERSION_1|. -OPENSSL_EXPORT long X509_REQ_get_version(const X509_REQ *req); - -// X509_REQ_get_subject_name returns |req|'s subject name. Note this function is -// not const-correct for legacy reasons. -OPENSSL_EXPORT X509_NAME *X509_REQ_get_subject_name(const X509_REQ *req); - -// X509_REQ_extract_key is a legacy alias for |X509_REQ_get_pubkey|. -#define X509_REQ_extract_key(a) X509_REQ_get_pubkey(a) - -// X509_name_cmp is a legacy alias for |X509_NAME_cmp|. -#define X509_name_cmp(a, b) X509_NAME_cmp((a), (b)) - -#define X509_CRL_VERSION_1 0 -#define X509_CRL_VERSION_2 1 - -// X509_CRL_get_version returns the numerical value of |crl|'s version, which -// will be one of the |X509_CRL_VERSION_*| constants. -OPENSSL_EXPORT long X509_CRL_get_version(const X509_CRL *crl); - -// X509_CRL_get0_lastUpdate returns |crl|'s lastUpdate time. -OPENSSL_EXPORT const ASN1_TIME *X509_CRL_get0_lastUpdate(const X509_CRL *crl); - -// X509_CRL_get0_nextUpdate returns |crl|'s nextUpdate time, or NULL if |crl| -// has none. -OPENSSL_EXPORT const ASN1_TIME *X509_CRL_get0_nextUpdate(const X509_CRL *crl); - -// X509_CRL_set1_lastUpdate sets |crl|'s lastUpdate time to |tm|. It returns one -// on success and zero on error. -OPENSSL_EXPORT int X509_CRL_set1_lastUpdate(X509_CRL *crl, const ASN1_TIME *tm); - -// X509_CRL_set1_nextUpdate sets |crl|'s nextUpdate time to |tm|. It returns one -// on success and zero on error. -OPENSSL_EXPORT int X509_CRL_set1_nextUpdate(X509_CRL *crl, const ASN1_TIME *tm); - -// The following symbols are deprecated aliases to |X509_CRL_set1_*|. -#define X509_CRL_set_lastUpdate X509_CRL_set1_lastUpdate -#define X509_CRL_set_nextUpdate X509_CRL_set1_nextUpdate - -// X509_CRL_get_lastUpdate returns a mutable pointer to |crl|'s lastUpdate time. -// Use |X509_CRL_get0_lastUpdate| or |X509_CRL_set1_lastUpdate| instead. -OPENSSL_EXPORT ASN1_TIME *X509_CRL_get_lastUpdate(X509_CRL *crl); - -// X509_CRL_get_nextUpdate returns a mutable pointer to |crl|'s nextUpdate time, -// or NULL if |crl| has none. Use |X509_CRL_get0_nextUpdate| or -// |X509_CRL_set1_nextUpdate| instead. -OPENSSL_EXPORT ASN1_TIME *X509_CRL_get_nextUpdate(X509_CRL *crl); - -// X509_CRL_get_issuer returns |crl|'s issuer name. Note this function is not -// const-correct for legacy reasons. -OPENSSL_EXPORT X509_NAME *X509_CRL_get_issuer(const X509_CRL *crl); - -// X509_CRL_get_REVOKED returns the list of revoked certificates in |crl|, or -// NULL if |crl| omits it. -// -// TOOD(davidben): This function was originally a macro, without clear const -// semantics. It should take a const input and give const output, but the latter -// would break existing callers. For now, we match upstream. -OPENSSL_EXPORT STACK_OF(X509_REVOKED) *X509_CRL_get_REVOKED(X509_CRL *crl); - -// X509_CRL_get0_extensions returns |crl|'s extension list, or NULL if |crl| -// omits it. -OPENSSL_EXPORT const STACK_OF(X509_EXTENSION) *X509_CRL_get0_extensions( - const X509_CRL *crl); - // X509_SIG_get0 sets |*out_alg| and |*out_digest| to non-owning pointers to // |sig|'s algorithm and digest fields, respectively. Either |out_alg| and // |out_digest| may be NULL to skip those fields. @@ -472,11 +1753,6 @@ OPENSSL_EXPORT void X509_SIG_get0(const X509_SIG *sig, OPENSSL_EXPORT void X509_SIG_getm(X509_SIG *sig, X509_ALGOR **out_alg, ASN1_OCTET_STRING **out_digest); -// X509_get_X509_PUBKEY returns the public key of |x509|. Note this function is -// not const-correct for legacy reasons. Callers should not modify the returned -// object. -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. @@ -525,59 +1801,6 @@ OPENSSL_EXPORT EVP_PKEY *NETSCAPE_SPKI_get_pubkey(NETSCAPE_SPKI *spki); OPENSSL_EXPORT int NETSCAPE_SPKI_set_pubkey(NETSCAPE_SPKI *spki, EVP_PKEY *pkey); -// X509_signature_dump writes a human-readable representation of |sig| to |bio|, -// indented with |indent| spaces. It returns one on success and zero on error. -OPENSSL_EXPORT int X509_signature_dump(BIO *bio, const ASN1_STRING *sig, - int indent); - -// X509_signature_print writes a human-readable representation of |alg| and -// |sig| to |bio|. It returns one on success and zero on error. -OPENSSL_EXPORT int X509_signature_print(BIO *bio, const X509_ALGOR *alg, - const ASN1_STRING *sig); - -// X509_sign signs |x509| with |pkey| and replaces the signature algorithm and -// signature fields. It returns one on success and zero on error. This function -// uses digest algorithm |md|, or |pkey|'s default if NULL. Other signing -// parameters use |pkey|'s defaults. To customize them, use |X509_sign_ctx|. -OPENSSL_EXPORT int X509_sign(X509 *x509, EVP_PKEY *pkey, const EVP_MD *md); - -// X509_sign_ctx signs |x509| with |ctx| and replaces the signature algorithm -// and signature fields. It returns one on success and zero on error. The -// signature algorithm and parameters come from |ctx|, which must have been -// initialized with |EVP_DigestSignInit|. The caller should configure the -// corresponding |EVP_PKEY_CTX| before calling this function. -OPENSSL_EXPORT int X509_sign_ctx(X509 *x509, EVP_MD_CTX *ctx); - -// X509_REQ_sign signs |req| with |pkey| and replaces the signature algorithm -// and signature fields. It returns one on success and zero on error. This -// function uses digest algorithm |md|, or |pkey|'s default if NULL. Other -// signing parameters use |pkey|'s defaults. To customize them, use -// |X509_REQ_sign_ctx|. -OPENSSL_EXPORT int X509_REQ_sign(X509_REQ *req, EVP_PKEY *pkey, - const EVP_MD *md); - -// X509_REQ_sign_ctx signs |req| with |ctx| and replaces the signature algorithm -// and signature fields. It returns one on success and zero on error. The -// signature algorithm and parameters come from |ctx|, which must have been -// initialized with |EVP_DigestSignInit|. The caller should configure the -// corresponding |EVP_PKEY_CTX| before calling this function. -OPENSSL_EXPORT int X509_REQ_sign_ctx(X509_REQ *req, EVP_MD_CTX *ctx); - -// X509_CRL_sign signs |crl| with |pkey| and replaces the signature algorithm -// and signature fields. It returns one on success and zero on error. This -// function uses digest algorithm |md|, or |pkey|'s default if NULL. Other -// signing parameters use |pkey|'s defaults. To customize them, use -// |X509_CRL_sign_ctx|. -OPENSSL_EXPORT int X509_CRL_sign(X509_CRL *crl, EVP_PKEY *pkey, - const EVP_MD *md); - -// X509_CRL_sign_ctx signs |crl| with |ctx| and replaces the signature algorithm -// and signature fields. It returns one on success and zero on error. The -// signature algorithm and parameters come from |ctx|, which must have been -// initialized with |EVP_DigestSignInit|. The caller should configure the -// corresponding |EVP_PKEY_CTX| before calling this function. -OPENSSL_EXPORT int X509_CRL_sign_ctx(X509_CRL *crl, EVP_MD_CTX *ctx); - // NETSCAPE_SPKI_sign signs |spki| with |pkey| and replaces the signature // algorithm and signature fields. It returns one on success and zero on error. // This function uses digest algorithm |md|, or |pkey|'s default if NULL. Other @@ -585,185 +1808,15 @@ OPENSSL_EXPORT int X509_CRL_sign_ctx(X509_CRL *crl, EVP_MD_CTX *ctx); OPENSSL_EXPORT int NETSCAPE_SPKI_sign(NETSCAPE_SPKI *spki, EVP_PKEY *pkey, const EVP_MD *md); -// X509_pubkey_digest hashes the DER encoding of |x509|'s subjectPublicKeyInfo -// field with |md| and writes the result to |out|. |EVP_MD_CTX_size| bytes are -// written, which is at most |EVP_MAX_MD_SIZE|. If |out_len| is not NULL, -// |*out_len| is set to the number of bytes written. This function returns one -// on success and zero on error. -OPENSSL_EXPORT int X509_pubkey_digest(const X509 *x509, const EVP_MD *md, - uint8_t *out, unsigned *out_len); +// X509_ATTRIBUTE_dup returns a newly-allocated copy of |xa|, or NULL on error. +// This function works by serializing the structure, so if |xa| is incomplete, +// it may fail. +OPENSSL_EXPORT X509_ATTRIBUTE *X509_ATTRIBUTE_dup(const X509_ATTRIBUTE *xa); -// X509_digest hashes |x509|'s DER encoding with |md| and writes the result to -// |out|. |EVP_MD_CTX_size| bytes are written, which is at most -// |EVP_MAX_MD_SIZE|. If |out_len| is not NULL, |*out_len| is set to the number -// of bytes written. This function returns one on success and zero on error. -// Note this digest covers the entire certificate, not just the signed portion. -OPENSSL_EXPORT int X509_digest(const X509 *x509, const EVP_MD *md, uint8_t *out, - unsigned *out_len); - -// X509_CRL_digest hashes |crl|'s DER encoding with |md| and writes the result -// to |out|. |EVP_MD_CTX_size| bytes are written, which is at most -// |EVP_MAX_MD_SIZE|. If |out_len| is not NULL, |*out_len| is set to the number -// of bytes written. This function returns one on success and zero on error. -// Note this digest covers the entire CRL, not just the signed portion. -OPENSSL_EXPORT int X509_CRL_digest(const X509_CRL *crl, const EVP_MD *md, - uint8_t *out, unsigned *out_len); - -// X509_REQ_digest hashes |req|'s DER encoding with |md| and writes the result -// to |out|. |EVP_MD_CTX_size| bytes are written, which is at most -// |EVP_MAX_MD_SIZE|. If |out_len| is not NULL, |*out_len| is set to the number -// of bytes written. This function returns one on success and zero on error. -// Note this digest covers the entire certificate request, not just the signed -// portion. -OPENSSL_EXPORT int X509_REQ_digest(const X509_REQ *req, const EVP_MD *md, - uint8_t *out, unsigned *out_len); - -// X509_NAME_digest hashes |name|'s DER encoding with |md| and writes the result -// to |out|. |EVP_MD_CTX_size| bytes are written, which is at most -// |EVP_MAX_MD_SIZE|. If |out_len| is not NULL, |*out_len| is set to the number -// of bytes written. This function returns one on success and zero on error. -OPENSSL_EXPORT int X509_NAME_digest(const X509_NAME *name, const EVP_MD *md, - uint8_t *out, unsigned *out_len); - -// X509_parse_from_buffer parses an X.509 structure from |buf| and returns a -// fresh X509 or NULL on error. There must not be any trailing data in |buf|. -// The returned structure (if any) holds a reference to |buf| rather than -// copying parts of it as a normal |d2i_X509| call would do. -OPENSSL_EXPORT X509 *X509_parse_from_buffer(CRYPTO_BUFFER *buf); - -OPENSSL_EXPORT X509 *d2i_X509_fp(FILE *fp, X509 **x509); -OPENSSL_EXPORT int i2d_X509_fp(FILE *fp, X509 *x509); -OPENSSL_EXPORT X509_CRL *d2i_X509_CRL_fp(FILE *fp, X509_CRL **crl); -OPENSSL_EXPORT int i2d_X509_CRL_fp(FILE *fp, X509_CRL *crl); -OPENSSL_EXPORT X509_REQ *d2i_X509_REQ_fp(FILE *fp, X509_REQ **req); -OPENSSL_EXPORT int i2d_X509_REQ_fp(FILE *fp, X509_REQ *req); -OPENSSL_EXPORT RSA *d2i_RSAPrivateKey_fp(FILE *fp, RSA **rsa); -OPENSSL_EXPORT int i2d_RSAPrivateKey_fp(FILE *fp, RSA *rsa); -OPENSSL_EXPORT RSA *d2i_RSAPublicKey_fp(FILE *fp, RSA **rsa); -OPENSSL_EXPORT int i2d_RSAPublicKey_fp(FILE *fp, RSA *rsa); -OPENSSL_EXPORT RSA *d2i_RSA_PUBKEY_fp(FILE *fp, RSA **rsa); -OPENSSL_EXPORT int i2d_RSA_PUBKEY_fp(FILE *fp, RSA *rsa); -#ifndef OPENSSL_NO_DSA -OPENSSL_EXPORT DSA *d2i_DSA_PUBKEY_fp(FILE *fp, DSA **dsa); -OPENSSL_EXPORT int i2d_DSA_PUBKEY_fp(FILE *fp, DSA *dsa); -OPENSSL_EXPORT DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa); -OPENSSL_EXPORT int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa); -#endif -OPENSSL_EXPORT EC_KEY *d2i_EC_PUBKEY_fp(FILE *fp, EC_KEY **eckey); -OPENSSL_EXPORT int i2d_EC_PUBKEY_fp(FILE *fp, EC_KEY *eckey); -OPENSSL_EXPORT EC_KEY *d2i_ECPrivateKey_fp(FILE *fp, EC_KEY **eckey); -OPENSSL_EXPORT int i2d_ECPrivateKey_fp(FILE *fp, EC_KEY *eckey); -OPENSSL_EXPORT X509_SIG *d2i_PKCS8_fp(FILE *fp, X509_SIG **p8); -OPENSSL_EXPORT int i2d_PKCS8_fp(FILE *fp, X509_SIG *p8); -OPENSSL_EXPORT PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp( - FILE *fp, PKCS8_PRIV_KEY_INFO **p8inf); -OPENSSL_EXPORT int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, - PKCS8_PRIV_KEY_INFO *p8inf); -OPENSSL_EXPORT int i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, EVP_PKEY *key); -OPENSSL_EXPORT int i2d_PrivateKey_fp(FILE *fp, EVP_PKEY *pkey); -OPENSSL_EXPORT EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a); -OPENSSL_EXPORT int i2d_PUBKEY_fp(FILE *fp, EVP_PKEY *pkey); -OPENSSL_EXPORT EVP_PKEY *d2i_PUBKEY_fp(FILE *fp, EVP_PKEY **a); - -OPENSSL_EXPORT X509 *d2i_X509_bio(BIO *bp, X509 **x509); -OPENSSL_EXPORT int i2d_X509_bio(BIO *bp, X509 *x509); -OPENSSL_EXPORT X509_CRL *d2i_X509_CRL_bio(BIO *bp, X509_CRL **crl); -OPENSSL_EXPORT int i2d_X509_CRL_bio(BIO *bp, X509_CRL *crl); -OPENSSL_EXPORT X509_REQ *d2i_X509_REQ_bio(BIO *bp, X509_REQ **req); -OPENSSL_EXPORT int i2d_X509_REQ_bio(BIO *bp, X509_REQ *req); -OPENSSL_EXPORT RSA *d2i_RSAPrivateKey_bio(BIO *bp, RSA **rsa); -OPENSSL_EXPORT int i2d_RSAPrivateKey_bio(BIO *bp, RSA *rsa); -OPENSSL_EXPORT RSA *d2i_RSAPublicKey_bio(BIO *bp, RSA **rsa); -OPENSSL_EXPORT int i2d_RSAPublicKey_bio(BIO *bp, RSA *rsa); -OPENSSL_EXPORT RSA *d2i_RSA_PUBKEY_bio(BIO *bp, RSA **rsa); -OPENSSL_EXPORT int i2d_RSA_PUBKEY_bio(BIO *bp, RSA *rsa); -#ifndef OPENSSL_NO_DSA -OPENSSL_EXPORT DSA *d2i_DSA_PUBKEY_bio(BIO *bp, DSA **dsa); -OPENSSL_EXPORT int i2d_DSA_PUBKEY_bio(BIO *bp, DSA *dsa); -OPENSSL_EXPORT DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa); -OPENSSL_EXPORT int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa); -#endif -OPENSSL_EXPORT EC_KEY *d2i_EC_PUBKEY_bio(BIO *bp, EC_KEY **eckey); -OPENSSL_EXPORT int i2d_EC_PUBKEY_bio(BIO *bp, EC_KEY *eckey); -OPENSSL_EXPORT EC_KEY *d2i_ECPrivateKey_bio(BIO *bp, EC_KEY **eckey); -OPENSSL_EXPORT int i2d_ECPrivateKey_bio(BIO *bp, EC_KEY *eckey); -OPENSSL_EXPORT X509_SIG *d2i_PKCS8_bio(BIO *bp, X509_SIG **p8); -OPENSSL_EXPORT int i2d_PKCS8_bio(BIO *bp, X509_SIG *p8); -OPENSSL_EXPORT PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio( - BIO *bp, PKCS8_PRIV_KEY_INFO **p8inf); -OPENSSL_EXPORT int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, - PKCS8_PRIV_KEY_INFO *p8inf); -OPENSSL_EXPORT int i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key); -OPENSSL_EXPORT int i2d_PrivateKey_bio(BIO *bp, EVP_PKEY *pkey); -OPENSSL_EXPORT EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a); -OPENSSL_EXPORT int i2d_PUBKEY_bio(BIO *bp, EVP_PKEY *pkey); -OPENSSL_EXPORT EVP_PKEY *d2i_PUBKEY_bio(BIO *bp, EVP_PKEY **a); -OPENSSL_EXPORT DH *d2i_DHparams_bio(BIO *bp, DH **dh); -OPENSSL_EXPORT int i2d_DHparams_bio(BIO *bp, const DH *dh); - -OPENSSL_EXPORT X509 *X509_dup(X509 *x509); -OPENSSL_EXPORT X509_ATTRIBUTE *X509_ATTRIBUTE_dup(X509_ATTRIBUTE *xa); -OPENSSL_EXPORT X509_EXTENSION *X509_EXTENSION_dup(X509_EXTENSION *ex); -OPENSSL_EXPORT X509_CRL *X509_CRL_dup(X509_CRL *crl); -OPENSSL_EXPORT X509_REVOKED *X509_REVOKED_dup(X509_REVOKED *rev); -OPENSSL_EXPORT X509_REQ *X509_REQ_dup(X509_REQ *req); -OPENSSL_EXPORT X509_ALGOR *X509_ALGOR_dup(X509_ALGOR *xn); - -// X509_ALGOR_set0 sets |alg| to an AlgorithmIdentifier with algorithm |obj| and -// parameter determined by |param_type| and |param_value|. It returns one on -// success and zero on error. This function takes ownership of |obj| and -// |param_value| on success. -// -// If |param_type| is |V_ASN1_UNDEF|, the parameter is omitted. If |param_type| -// is zero, the parameter is left unchanged. Otherwise, |param_type| and -// |param_value| are interpreted as in |ASN1_TYPE_set|. -// -// Note omitting the parameter (|V_ASN1_UNDEF|) and encoding an explicit NULL -// value (|V_ASN1_NULL|) are different. Some algorithms require one and some the -// other. Consult the relevant specification before calling this function. The -// correct parameter for an RSASSA-PKCS1-v1_5 signature is |V_ASN1_NULL|. The -// correct one for an ECDSA or Ed25519 signature is |V_ASN1_UNDEF|. -OPENSSL_EXPORT int X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *obj, - int param_type, void *param_value); - -// X509_ALGOR_get0 sets |*out_obj| to the |alg|'s algorithm. If |alg|'s -// parameter is omitted, it sets |*out_param_type| and |*out_param_value| to -// |V_ASN1_UNDEF| and NULL. Otherwise, it sets |*out_param_type| and -// |*out_param_value| to the parameter, using the same representation as -// |ASN1_TYPE_set0|. See |ASN1_TYPE_set0| and |ASN1_TYPE| for details. -// -// Callers that require the parameter in serialized form should, after checking -// for |V_ASN1_UNDEF|, use |ASN1_TYPE_set1| and |d2i_ASN1_TYPE|, rather than -// inspecting |*out_param_value|. -// -// Each of |out_obj|, |out_param_type|, and |out_param_value| may be NULL to -// ignore the output. If |out_param_type| is NULL, |out_param_value| is ignored. -// -// WARNING: If |*out_param_type| is set to |V_ASN1_UNDEF|, OpenSSL and older -// revisions of BoringSSL leave |*out_param_value| unset rather than setting it -// to NULL. Callers that support both OpenSSL and BoringSSL should not assume -// |*out_param_value| is uniformly initialized. -OPENSSL_EXPORT void X509_ALGOR_get0(const ASN1_OBJECT **out_obj, - int *out_param_type, - const void **out_param_value, - const X509_ALGOR *alg); - -// X509_ALGOR_set_md sets |alg| to the hash function |md|. Note this -// AlgorithmIdentifier represents the hash function itself, not a signature -// algorithm that uses |md|. -OPENSSL_EXPORT void X509_ALGOR_set_md(X509_ALGOR *alg, const EVP_MD *md); - -// X509_ALGOR_cmp returns zero if |a| and |b| are equal, and some non-zero value -// otherwise. Note this function can only be used for equality checks, not an -// ordering. -OPENSSL_EXPORT int X509_ALGOR_cmp(const X509_ALGOR *a, const X509_ALGOR *b); - -OPENSSL_EXPORT X509_NAME *X509_NAME_dup(X509_NAME *xn); -OPENSSL_EXPORT X509_NAME_ENTRY *X509_NAME_ENTRY_dup(X509_NAME_ENTRY *ne); -OPENSSL_EXPORT int X509_NAME_ENTRY_set(const X509_NAME_ENTRY *ne); - -OPENSSL_EXPORT int X509_NAME_get0_der(X509_NAME *nm, const unsigned char **pder, - size_t *pderlen); +// X509_REVOKED_dup returns a newly-allocated copy of |rev|, or NULL on error. +// This function works by serializing the structure, so if |rev| is incomplete, +// it may fail. +OPENSSL_EXPORT X509_REVOKED *X509_REVOKED_dup(const X509_REVOKED *rev); // X509_cmp_time compares |s| against |*t|. On success, it returns a negative // number if |s| <= |*t| and a positive number if |s| > |*t|. On error, it @@ -797,9 +1850,7 @@ OPENSSL_EXPORT const char *X509_get_default_cert_dir_env(void); OPENSSL_EXPORT const char *X509_get_default_cert_file_env(void); OPENSSL_EXPORT const char *X509_get_default_private_dir(void); -DECLARE_ASN1_ENCODE_FUNCTIONS(X509_ALGORS, X509_ALGORS, X509_ALGORS) - -DECLARE_ASN1_FUNCTIONS(X509_PUBKEY) +DECLARE_ASN1_FUNCTIONS_const(X509_PUBKEY) // X509_PUBKEY_set serializes |pkey| into a newly-allocated |X509_PUBKEY| // structure. On success, it frees |*x|, sets |*x| to the new object, and @@ -812,10 +1863,9 @@ OPENSSL_EXPORT int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey); // not mutate the result. OPENSSL_EXPORT EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key); -DECLARE_ASN1_FUNCTIONS(X509_SIG) -DECLARE_ASN1_FUNCTIONS(X509_REQ) +DECLARE_ASN1_FUNCTIONS_const(X509_SIG) -DECLARE_ASN1_FUNCTIONS(X509_ATTRIBUTE) +DECLARE_ASN1_FUNCTIONS_const(X509_ATTRIBUTE) // X509_ATTRIBUTE_create returns a newly-allocated |X509_ATTRIBUTE|, or NULL on // error. The attribute has type |nid| and contains a single value determined by @@ -824,147 +1874,6 @@ DECLARE_ASN1_FUNCTIONS(X509_ATTRIBUTE) OPENSSL_EXPORT X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int attrtype, void *value); -DECLARE_ASN1_FUNCTIONS(X509_EXTENSION) -DECLARE_ASN1_ENCODE_FUNCTIONS(X509_EXTENSIONS, X509_EXTENSIONS, X509_EXTENSIONS) - -DECLARE_ASN1_FUNCTIONS(X509_NAME_ENTRY) - -DECLARE_ASN1_FUNCTIONS(X509_NAME) - -// X509_NAME_set makes a copy of |name|. On success, it frees |*xn|, sets |*xn| -// to the copy, and returns one. Otherwise, it returns zero. -OPENSSL_EXPORT int X509_NAME_set(X509_NAME **xn, X509_NAME *name); - -DECLARE_ASN1_FUNCTIONS(X509) - -// X509_up_ref adds one to the reference count of |x509| and returns one. -OPENSSL_EXPORT int X509_up_ref(X509 *x509); - -OPENSSL_EXPORT int X509_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_set_ex_data(X509 *r, int idx, void *arg); -OPENSSL_EXPORT void *X509_get_ex_data(X509 *r, int idx); - -// 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|, 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 -// the signature of an existing certificate. To generate certificates, use -// |i2d_re_X509_tbs| instead. -OPENSSL_EXPORT int i2d_X509_tbs(X509 *x509, unsigned char **outp); - -// X509_set1_signature_algo sets |x509|'s signature algorithm to |algo| and -// returns one on success or zero on error. It updates both the signature field -// of the TBSCertificate structure, and the signatureAlgorithm field of the -// Certificate. -OPENSSL_EXPORT int X509_set1_signature_algo(X509 *x509, const X509_ALGOR *algo); - -// X509_set1_signature_value sets |x509|'s signature to a copy of the |sig_len| -// bytes pointed by |sig|. It returns one on success and zero on error. -// -// Due to a specification error, X.509 certificates store signatures in ASN.1 -// BIT STRINGs, but signature algorithms return byte strings rather than bit -// strings. This function creates a BIT STRING containing a whole number of -// bytes, with the bit order matching the DER encoding. This matches the -// encoding used by all X.509 signature algorithms. -OPENSSL_EXPORT int X509_set1_signature_value(X509 *x509, const uint8_t *sig, - size_t sig_len); - -// X509_get0_signature sets |*out_sig| and |*out_alg| to the signature and -// signature algorithm of |x509|, respectively. Either output pointer may be -// NULL to ignore the value. -// -// This function outputs the outer signature algorithm. For the one in the -// TBSCertificate, see |X509_get0_tbs_sigalg|. Certificates with mismatched -// signature algorithms will successfully parse, but they will be rejected when -// verifying. -OPENSSL_EXPORT void X509_get0_signature(const ASN1_BIT_STRING **out_sig, - const X509_ALGOR **out_alg, - const X509 *x509); - -// X509_get_signature_nid returns the NID corresponding to |x509|'s signature -// algorithm, or |NID_undef| if the signature algorithm does not correspond to -// a known NID. -OPENSSL_EXPORT int X509_get_signature_nid(const X509 *x509); - - -// Auxiliary properties. -// -// |X509| objects optionally maintain auxiliary properties. These are not part -// of the certificates themselves, and thus are not covered by signatures or -// preserved by the standard serialization. They are used as inputs or outputs -// to other functions in this library. - -// i2d_X509_AUX marshals |x509| as a DER-encoded X.509 Certificate (RFC 5280), -// followed optionally by a separate, OpenSSL-specific structure with auxiliary -// properties. It behaves as described in |i2d_SAMPLE|. -// -// Unlike similarly-named functions, this function does not output a single -// ASN.1 element. Directly embedding the output in a larger ASN.1 structure will -// not behave correctly. -OPENSSL_EXPORT int i2d_X509_AUX(X509 *x509, unsigned char **outp); - -// d2i_X509_AUX parses up to |length| bytes from |*inp| as a DER-encoded X.509 -// Certificate (RFC 5280), followed optionally by a separate, OpenSSL-specific -// structure with auxiliary properties. It behaves as described in -// |d2i_SAMPLE_with_reuse|. -// -// Some auxiliary properties affect trust decisions, so this function should not -// be used with untrusted input. -// -// Unlike similarly-named functions, this function does not parse a single -// ASN.1 element. Trying to parse data directly embedded in a larger ASN.1 -// structure will not behave correctly. -OPENSSL_EXPORT X509 *d2i_X509_AUX(X509 **x509, const unsigned char **inp, - long length); - -// X509_alias_set1 sets |x509|'s alias to |len| bytes from |name|. If |name| is -// NULL, the alias is cleared instead. Aliases are not part of the certificate -// itself and will not be serialized by |i2d_X509|. -OPENSSL_EXPORT int X509_alias_set1(X509 *x509, const unsigned char *name, - int len); - -// X509_keyid_set1 sets |x509|'s key ID to |len| bytes from |id|. If |id| is -// NULL, the key ID is cleared instead. Key IDs are not part of the certificate -// itself and will not be serialized by |i2d_X509|. -OPENSSL_EXPORT int X509_keyid_set1(X509 *x509, const unsigned char *id, - int len); - -// X509_alias_get0 looks up |x509|'s alias. If found, it sets |*out_len| to the -// alias's length and returns a pointer to a buffer containing the contents. If -// not found, it outputs the empty string by returning NULL and setting -// |*out_len| to zero. -// -// If |x509| was parsed from a PKCS#12 structure (see -// |PKCS12_get_key_and_certs|), the alias will reflect the friendlyName -// attribute (RFC 2985). -// -// WARNING: In OpenSSL, this function did not set |*out_len| when the alias was -// missing. Callers that target both OpenSSL and BoringSSL should set the value -// to zero before calling this function. -OPENSSL_EXPORT unsigned char *X509_alias_get0(X509 *x509, int *out_len); - -// X509_keyid_get0 looks up |x509|'s key ID. If found, it sets |*out_len| to the -// key ID's length and returns a pointer to a buffer containing the contents. If -// not found, it outputs the empty string by returning NULL and setting -// |*out_len| to zero. -// -// WARNING: In OpenSSL, this function did not set |*out_len| when the alias was -// missing. Callers that target both OpenSSL and BoringSSL should set the value -// to zero before calling this function. -OPENSSL_EXPORT unsigned char *X509_keyid_get0(X509 *x509, int *out_len); - OPENSSL_EXPORT int X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj); OPENSSL_EXPORT int X509_add1_reject_object(X509 *x, ASN1_OBJECT *obj); OPENSSL_EXPORT void X509_trust_clear(X509 *x); @@ -973,8 +1882,7 @@ OPENSSL_EXPORT void X509_reject_clear(X509 *x); OPENSSL_EXPORT int X509_TRUST_set(int *t, int trust); -DECLARE_ASN1_FUNCTIONS(X509_REVOKED) -DECLARE_ASN1_FUNCTIONS(X509_CRL) +DECLARE_ASN1_FUNCTIONS_const(X509_REVOKED) OPENSSL_EXPORT int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev); OPENSSL_EXPORT int X509_CRL_get0_by_serial(X509_CRL *crl, X509_REVOKED **ret, @@ -985,8 +1893,8 @@ OPENSSL_EXPORT int X509_CRL_get0_by_cert(X509_CRL *crl, X509_REVOKED **ret, OPENSSL_EXPORT X509_PKEY *X509_PKEY_new(void); OPENSSL_EXPORT void X509_PKEY_free(X509_PKEY *a); -DECLARE_ASN1_FUNCTIONS(NETSCAPE_SPKI) -DECLARE_ASN1_FUNCTIONS(NETSCAPE_SPKAC) +DECLARE_ASN1_FUNCTIONS_const(NETSCAPE_SPKI) +DECLARE_ASN1_FUNCTIONS_const(NETSCAPE_SPKAC) OPENSSL_EXPORT X509_INFO *X509_INFO_new(void); OPENSSL_EXPORT void X509_INFO_free(X509_INFO *a); @@ -1013,97 +1921,6 @@ OPENSSL_EXPORT int ASN1_item_sign_ctx(const ASN1_ITEM *it, X509_ALGOR *algor1, ASN1_BIT_STRING *signature, void *asn, EVP_MD_CTX *ctx); -// X509_get_serialNumber returns a mutable pointer to |x509|'s serial number. -// Prefer |X509_get0_serialNumber|. -OPENSSL_EXPORT ASN1_INTEGER *X509_get_serialNumber(X509 *x509); - -// X509_set_issuer_name sets |x509|'s issuer to a copy of |name|. It returns one -// on success and zero on error. -OPENSSL_EXPORT int X509_set_issuer_name(X509 *x509, X509_NAME *name); - -// X509_get_issuer_name returns |x509|'s issuer. -OPENSSL_EXPORT X509_NAME *X509_get_issuer_name(const X509 *x509); - -// X509_set_subject_name sets |x509|'s subject to a copy of |name|. It returns -// one on success and zero on error. -OPENSSL_EXPORT int X509_set_subject_name(X509 *x509, X509_NAME *name); - -// X509_get_issuer_name returns |x509|'s subject. -OPENSSL_EXPORT X509_NAME *X509_get_subject_name(const X509 *x509); - -// X509_set_pubkey sets |x509|'s public key to |pkey|. It returns one on success -// and zero on error. This function does not take ownership of |pkey| and -// internally copies and updates reference counts as needed. -OPENSSL_EXPORT int X509_set_pubkey(X509 *x509, EVP_PKEY *pkey); - -// X509_get_pubkey returns |x509|'s public key as an |EVP_PKEY|, or NULL if the -// public key was unsupported or could not be decoded. This function returns a -// reference to the |EVP_PKEY|. The caller must release the result with -// |EVP_PKEY_free| when done. -OPENSSL_EXPORT EVP_PKEY *X509_get_pubkey(X509 *x509); - -// X509_get0_pubkey_bitstr returns the BIT STRING portion of |x509|'s public -// key. Note this does not contain the AlgorithmIdentifier portion. -// -// WARNING: This function returns a non-const pointer for OpenSSL compatibility, -// but the caller must not modify the resulting object. Doing so will break -// internal invariants in |x509|. -OPENSSL_EXPORT ASN1_BIT_STRING *X509_get0_pubkey_bitstr(const X509 *x509); - -// X509_get0_extensions returns |x509|'s extension list, or NULL if |x509| omits -// it. -OPENSSL_EXPORT const STACK_OF(X509_EXTENSION) *X509_get0_extensions( - const X509 *x509); - -// X509_get0_tbs_sigalg returns the signature algorithm in |x509|'s -// TBSCertificate. For the outer signature algorithm, see |X509_get0_signature|. -// -// Certificates with mismatched signature algorithms will successfully parse, -// but they will be rejected when verifying. -OPENSSL_EXPORT const X509_ALGOR *X509_get0_tbs_sigalg(const X509 *x509); - -// X509_REQ_set_version sets |req|'s version to |version|, which should be -// |X509_REQ_VERSION_1|. It returns one on success and zero on error. -// -// The only defined CSR version is |X509_REQ_VERSION_1|, so there is no need to -// call this function. -OPENSSL_EXPORT int X509_REQ_set_version(X509_REQ *req, long version); - -// X509_REQ_set_subject_name sets |req|'s subject to a copy of |name|. It -// returns one on success and zero on error. -OPENSSL_EXPORT int X509_REQ_set_subject_name(X509_REQ *req, X509_NAME *name); - -// X509_REQ_get0_signature sets |*out_sig| and |*out_alg| to the signature and -// signature algorithm of |req|, respectively. Either output pointer may be NULL -// to ignore the value. -OPENSSL_EXPORT void X509_REQ_get0_signature(const X509_REQ *req, - const ASN1_BIT_STRING **out_sig, - const X509_ALGOR **out_alg); - -// X509_REQ_get_signature_nid returns the NID corresponding to |req|'s signature -// algorithm, or |NID_undef| if the signature algorithm does not correspond to -// a known NID. -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|, 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 -// for a new certificate request. -OPENSSL_EXPORT int i2d_re_X509_REQ_tbs(X509_REQ *req, uint8_t **outp); - -// X509_REQ_set_pubkey sets |req|'s public key to |pkey|. It returns one on -// success and zero on error. This function does not take ownership of |pkey| -// and internally copies and updates reference counts as needed. -OPENSSL_EXPORT int X509_REQ_set_pubkey(X509_REQ *req, EVP_PKEY *pkey); - -// X509_REQ_get_pubkey returns |req|'s public key as an |EVP_PKEY|, or NULL if -// the public key was unsupported or could not be decoded. This function returns -// a reference to the |EVP_PKEY|. The caller must release the result with -// |EVP_PKEY_free| when done. -OPENSSL_EXPORT EVP_PKEY *X509_REQ_get_pubkey(X509_REQ *req); - // X509_REQ_extension_nid returns one if |nid| is a supported CSR attribute type // for carrying extensions and zero otherwise. The supported types are // |NID_ext_req| (pkcs-9-at-extensionRequest from RFC 2985) and |NID_ms_ext_req| @@ -1191,93 +2008,8 @@ OPENSSL_EXPORT int X509_REQ_add1_attr_by_txt(X509_REQ *req, const unsigned char *data, int len); -// X509_REQ_set1_signature_algo sets |req|'s signature algorithm to |algo| and -// returns one on success or zero on error. -OPENSSL_EXPORT int X509_REQ_set1_signature_algo(X509_REQ *req, - const X509_ALGOR *algo); - -// X509_REQ_set1_signature_value sets |req|'s signature to a copy of the -// |sig_len| bytes pointed by |sig|. It returns one on success and zero on -// error. -// -// Due to a specification error, PKCS#10 certificate requests store signatures -// in ASN.1 BIT STRINGs, but signature algorithms return byte strings rather -// than bit strings. This function creates a BIT STRING containing a whole -// number of bytes, with the bit order matching the DER encoding. This matches -// the encoding used by all X.509 signature algorithms. -OPENSSL_EXPORT int X509_REQ_set1_signature_value(X509_REQ *req, - const uint8_t *sig, - size_t sig_len); - -// X509_CRL_set_version sets |crl|'s version to |version|, which should be one -// of the |X509_CRL_VERSION_*| constants. It returns one on success and zero on -// error. -// -// If unsure, use |X509_CRL_VERSION_2|. Note that, unlike certificates, CRL -// versions are only defined up to v2. Callers should not use |X509_VERSION_3|. -OPENSSL_EXPORT int X509_CRL_set_version(X509_CRL *crl, long version); - -// X509_CRL_set_issuer_name sets |crl|'s issuer to a copy of |name|. It returns -// one on success and zero on error. -OPENSSL_EXPORT int X509_CRL_set_issuer_name(X509_CRL *crl, X509_NAME *name); - OPENSSL_EXPORT int X509_CRL_sort(X509_CRL *crl); -// X509_CRL_up_ref adds one to the reference count of |crl| and returns one. -OPENSSL_EXPORT int X509_CRL_up_ref(X509_CRL *crl); - -// X509_CRL_get0_signature sets |*out_sig| and |*out_alg| to the signature and -// signature algorithm of |crl|, respectively. Either output pointer may be NULL -// to ignore the value. -// -// This function outputs the outer signature algorithm, not the one in the -// TBSCertList. CRLs with mismatched signature algorithms will successfully -// parse, but they will be rejected when verifying. -OPENSSL_EXPORT void X509_CRL_get0_signature(const X509_CRL *crl, - const ASN1_BIT_STRING **out_sig, - const X509_ALGOR **out_alg); - -// X509_CRL_get_signature_nid returns the NID corresponding to |crl|'s signature -// algorithm, or |NID_undef| if the signature algorithm does not correspond to -// 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|, 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|, 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 -// signature of an existing CRL. To generate CRLs, use |i2d_re_X509_CRL_tbs| -// instead. -OPENSSL_EXPORT int i2d_X509_CRL_tbs(X509_CRL *crl, unsigned char **outp); - -// X509_CRL_set1_signature_algo sets |crl|'s signature algorithm to |algo| and -// returns one on success or zero on error. It updates both the signature field -// of the TBSCertList structure, and the signatureAlgorithm field of the CRL. -OPENSSL_EXPORT int X509_CRL_set1_signature_algo(X509_CRL *crl, - const X509_ALGOR *algo); - -// X509_CRL_set1_signature_value sets |crl|'s signature to a copy of the -// |sig_len| bytes pointed by |sig|. It returns one on success and zero on -// error. -// -// Due to a specification error, X.509 CRLs store signatures in ASN.1 BIT -// STRINGs, but signature algorithms return byte strings rather than bit -// strings. This function creates a BIT STRING containing a whole number of -// bytes, with the bit order matching the DER encoding. This matches the -// encoding used by all X.509 signature algorithms. -OPENSSL_EXPORT int X509_CRL_set1_signature_value(X509_CRL *crl, - const uint8_t *sig, - size_t sig_len); - // X509_REVOKED_get0_serialNumber returns the serial number of the certificate // revoked by |revoked|. OPENSSL_EXPORT const ASN1_INTEGER *X509_REVOKED_get0_serialNumber( @@ -1310,17 +2042,6 @@ OPENSSL_EXPORT X509_CRL *X509_CRL_diff(X509_CRL *base, X509_CRL *newer, OPENSSL_EXPORT int X509_REQ_check_private_key(X509_REQ *x509, EVP_PKEY *pkey); OPENSSL_EXPORT int X509_check_private_key(X509 *x509, const EVP_PKEY *pkey); -OPENSSL_EXPORT int X509_chain_check_suiteb(int *perror_depth, X509 *x, - STACK_OF(X509) *chain, - unsigned long flags); -OPENSSL_EXPORT int X509_CRL_check_suiteb(X509_CRL *crl, EVP_PKEY *pk, - unsigned long flags); - -// X509_chain_up_ref returns a newly-allocated |STACK_OF(X509)| containing a -// shallow copy of |chain|, or NULL on error. That is, the return value has the -// same contents as |chain|, and each |X509|'s reference count is incremented by -// one. -OPENSSL_EXPORT STACK_OF(X509) *X509_chain_up_ref(STACK_OF(X509) *chain); OPENSSL_EXPORT int X509_issuer_and_serial_cmp(const X509 *a, const X509 *b); @@ -1354,148 +2075,11 @@ OPENSSL_EXPORT int X509_NAME_print_ex(BIO *out, const X509_NAME *nm, int indent, OPENSSL_EXPORT int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflag, unsigned long cflag); OPENSSL_EXPORT int X509_print(BIO *bp, X509 *x); -OPENSSL_EXPORT int X509_ocspid_print(BIO *bp, X509 *x); OPENSSL_EXPORT int X509_CRL_print(BIO *bp, X509_CRL *x); OPENSSL_EXPORT int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflag, unsigned long cflag); OPENSSL_EXPORT int X509_REQ_print(BIO *bp, X509_REQ *req); -OPENSSL_EXPORT int X509_NAME_entry_count(const X509_NAME *name); -OPENSSL_EXPORT int X509_NAME_get_text_by_NID(const X509_NAME *name, int nid, - char *buf, int len); -OPENSSL_EXPORT int X509_NAME_get_text_by_OBJ(const X509_NAME *name, - const ASN1_OBJECT *obj, char *buf, - int len); - -// NOTE: you should be passsing -1, not 0 as lastpos. The functions that use -// lastpos, search after that position on. -OPENSSL_EXPORT int X509_NAME_get_index_by_NID(const X509_NAME *name, int nid, - int lastpos); -OPENSSL_EXPORT int X509_NAME_get_index_by_OBJ(const X509_NAME *name, - const ASN1_OBJECT *obj, - int lastpos); -OPENSSL_EXPORT X509_NAME_ENTRY *X509_NAME_get_entry(const X509_NAME *name, - int loc); -OPENSSL_EXPORT X509_NAME_ENTRY *X509_NAME_delete_entry(X509_NAME *name, - int loc); -OPENSSL_EXPORT int X509_NAME_add_entry(X509_NAME *name, X509_NAME_ENTRY *ne, - int loc, int set); -OPENSSL_EXPORT int X509_NAME_add_entry_by_OBJ(X509_NAME *name, ASN1_OBJECT *obj, - int type, - const unsigned char *bytes, - int len, int loc, int set); -OPENSSL_EXPORT int X509_NAME_add_entry_by_NID(X509_NAME *name, int nid, - int type, - const unsigned char *bytes, - int len, int loc, int set); -OPENSSL_EXPORT X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_txt( - X509_NAME_ENTRY **ne, const char *field, int type, - const unsigned char *bytes, int len); -OPENSSL_EXPORT X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_NID( - X509_NAME_ENTRY **ne, int nid, int type, const unsigned char *bytes, - int len); -OPENSSL_EXPORT int X509_NAME_add_entry_by_txt(X509_NAME *name, - const char *field, int type, - const unsigned char *bytes, - int len, int loc, int set); -OPENSSL_EXPORT X509_NAME_ENTRY *X509_NAME_ENTRY_create_by_OBJ( - X509_NAME_ENTRY **ne, const ASN1_OBJECT *obj, int type, - const unsigned char *bytes, int len); -OPENSSL_EXPORT int X509_NAME_ENTRY_set_object(X509_NAME_ENTRY *ne, - const ASN1_OBJECT *obj); -OPENSSL_EXPORT int X509_NAME_ENTRY_set_data(X509_NAME_ENTRY *ne, int type, - const unsigned char *bytes, - int len); -OPENSSL_EXPORT ASN1_OBJECT *X509_NAME_ENTRY_get_object( - const X509_NAME_ENTRY *ne); -OPENSSL_EXPORT ASN1_STRING *X509_NAME_ENTRY_get_data(const X509_NAME_ENTRY *ne); - -// X509v3_get_ext_count returns the number of extensions in |x|. -OPENSSL_EXPORT int X509v3_get_ext_count(const STACK_OF(X509_EXTENSION) *x); - -// X509v3_get_ext_by_NID returns the index of the first extension in |x| with -// type |nid|, or a negative number if not found. If found, callers can use -// |X509v3_get_ext| to look up the extension by index. -// -// If |lastpos| is non-negative, it begins searching at |lastpos| + 1. Callers -// can thus loop over all matching extensions by first passing -1 and then -// passing the previously-returned value until no match is returned. -OPENSSL_EXPORT int X509v3_get_ext_by_NID(const STACK_OF(X509_EXTENSION) *x, - int nid, int lastpos); - -// X509v3_get_ext_by_OBJ behaves like |X509v3_get_ext_by_NID| but looks for -// extensions matching |obj|. -OPENSSL_EXPORT int X509v3_get_ext_by_OBJ(const STACK_OF(X509_EXTENSION) *x, - const ASN1_OBJECT *obj, int lastpos); - -// X509v3_get_ext_by_critical returns the index of the first extension in |x| -// whose critical bit matches |crit|, or a negative number if no such extension -// was found. -// -// If |lastpos| is non-negative, it begins searching at |lastpos| + 1. Callers -// can thus loop over all matching extensions by first passing -1 and then -// passing the previously-returned value until no match is returned. -OPENSSL_EXPORT int X509v3_get_ext_by_critical(const STACK_OF(X509_EXTENSION) *x, - int crit, int lastpos); - -// X509v3_get_ext returns the extension in |x| at index |loc|, or NULL if |loc| -// is out of bounds. -OPENSSL_EXPORT X509_EXTENSION *X509v3_get_ext(const STACK_OF(X509_EXTENSION) *x, - int loc); - -// X509v3_delete_ext removes the extension in |x| at index |loc| and returns the -// removed extension, or NULL if |loc| was out of bounds. If an extension was -// returned, the caller must release it with |X509_EXTENSION_free|. -OPENSSL_EXPORT X509_EXTENSION *X509v3_delete_ext(STACK_OF(X509_EXTENSION) *x, - int loc); - -// X509v3_add_ext adds a copy of |ex| to the extension list in |*x|. If |*x| is -// NULL, it allocates a new |STACK_OF(X509_EXTENSION)| to hold the copy and sets -// |*x| to the new list. It returns |*x| on success and NULL on error. The -// caller retains ownership of |ex| and can release it independently of |*x|. -// -// The new extension is inserted at index |loc|, shifting extensions to the -// right. If |loc| is -1 or out of bounds, the new extension is appended to the -// list. -OPENSSL_EXPORT STACK_OF(X509_EXTENSION) *X509v3_add_ext( - STACK_OF(X509_EXTENSION) **x, X509_EXTENSION *ex, int loc); - -// X509_get_ext_count returns the number of extensions in |x|. -OPENSSL_EXPORT int X509_get_ext_count(const X509 *x); - -// X509_get_ext_by_NID behaves like |X509v3_get_ext_by_NID| but searches for -// extensions in |x|. -OPENSSL_EXPORT int X509_get_ext_by_NID(const X509 *x, int nid, int lastpos); - -// X509_get_ext_by_OBJ behaves like |X509v3_get_ext_by_OBJ| but searches for -// extensions in |x|. -OPENSSL_EXPORT int X509_get_ext_by_OBJ(const X509 *x, const ASN1_OBJECT *obj, - int lastpos); - -// X509_get_ext_by_critical behaves like |X509v3_get_ext_by_critical| but -// searches for extensions in |x|. -OPENSSL_EXPORT int X509_get_ext_by_critical(const X509 *x, int crit, - int lastpos); - -// X509_get_ext returns the extension in |x| at index |loc|, or NULL if |loc| is -// out of bounds. -OPENSSL_EXPORT X509_EXTENSION *X509_get_ext(const X509 *x, int loc); - -// X509_delete_ext removes the extension in |x| at index |loc| and returns the -// removed extension, or NULL if |loc| was out of bounds. If non-NULL, the -// caller must release the result with |X509_EXTENSION_free|. It is also safe, -// but not necessary, to call |X509_EXTENSION_free| if the result is NULL. -OPENSSL_EXPORT X509_EXTENSION *X509_delete_ext(X509 *x, int loc); - -// X509_add_ext adds a copy of |ex| to |x|. It returns one on success and zero -// on failure. The caller retains ownership of |ex| and can release it -// independently of |x|. -// -// The new extension is inserted at index |loc|, shifting extensions to the -// right. If |loc| is -1 or out of bounds, the new extension is appended to the -// list. -OPENSSL_EXPORT int X509_add_ext(X509 *x, X509_EXTENSION *ex, int loc); - // X509_get_ext_d2i behaves like |X509V3_get_d2i| but looks for the extension in // |x509|'s extension list. // @@ -1513,43 +2097,6 @@ OPENSSL_EXPORT void *X509_get_ext_d2i(const X509 *x509, int nid, OPENSSL_EXPORT int X509_add1_ext_i2d(X509 *x, int nid, void *value, int crit, unsigned long flags); -// X509_CRL_get_ext_count returns the number of extensions in |x|. -OPENSSL_EXPORT int X509_CRL_get_ext_count(const X509_CRL *x); - -// X509_CRL_get_ext_by_NID behaves like |X509v3_get_ext_by_NID| but searches for -// extensions in |x|. -OPENSSL_EXPORT int X509_CRL_get_ext_by_NID(const X509_CRL *x, int nid, - int lastpos); - -// X509_CRL_get_ext_by_OBJ behaves like |X509v3_get_ext_by_OBJ| but searches for -// extensions in |x|. -OPENSSL_EXPORT int X509_CRL_get_ext_by_OBJ(const X509_CRL *x, - const ASN1_OBJECT *obj, int lastpos); - -// X509_CRL_get_ext_by_critical behaves like |X509v3_get_ext_by_critical| but -// searches for extensions in |x|. -OPENSSL_EXPORT int X509_CRL_get_ext_by_critical(const X509_CRL *x, int crit, - int lastpos); - -// X509_CRL_get_ext returns the extension in |x| at index |loc|, or NULL if -// |loc| is out of bounds. -OPENSSL_EXPORT X509_EXTENSION *X509_CRL_get_ext(const X509_CRL *x, int loc); - -// X509_CRL_delete_ext removes the extension in |x| at index |loc| and returns -// the removed extension, or NULL if |loc| was out of bounds. If non-NULL, the -// caller must release the result with |X509_EXTENSION_free|. It is also safe, -// but not necessary, to call |X509_EXTENSION_free| if the result is NULL. -OPENSSL_EXPORT X509_EXTENSION *X509_CRL_delete_ext(X509_CRL *x, int loc); - -// X509_CRL_add_ext adds a copy of |ex| to |x|. It returns one on success and -// zero on failure. The caller retains ownership of |ex| and can release it -// independently of |x|. -// -// The new extension is inserted at index |loc|, shifting extensions to the -// right. If |loc| is -1 or out of bounds, the new extension is appended to the -// list. -OPENSSL_EXPORT int X509_CRL_add_ext(X509_CRL *x, X509_EXTENSION *ex, int loc); - // X509_CRL_get_ext_d2i behaves like |X509V3_get_d2i| but looks for the // extension in |crl|'s extension list. // @@ -1587,15 +2134,14 @@ OPENSSL_EXPORT int X509_REVOKED_get_ext_by_critical(const X509_REVOKED *x, int crit, int lastpos); // X509_REVOKED_get_ext returns the extension in |x| at index |loc|, or NULL if -// |loc| is out of bounds. +// |loc| is out of bounds. This function returns a non-const pointer for OpenSSL +// compatibility, but callers should not mutate the result. OPENSSL_EXPORT X509_EXTENSION *X509_REVOKED_get_ext(const X509_REVOKED *x, int loc); // X509_REVOKED_delete_ext removes the extension in |x| at index |loc| and // returns the removed extension, or NULL if |loc| was out of bounds. If -// non-NULL, the caller must release the result with |X509_EXTENSION_free|. It -// is also safe, but not necessary, to call |X509_EXTENSION_free| if the result -// is NULL. +// non-NULL, the caller must release the result with |X509_EXTENSION_free|. OPENSSL_EXPORT X509_EXTENSION *X509_REVOKED_delete_ext(X509_REVOKED *x, int loc); @@ -1606,8 +2152,8 @@ OPENSSL_EXPORT X509_EXTENSION *X509_REVOKED_delete_ext(X509_REVOKED *x, // The new extension is inserted at index |loc|, shifting extensions to the // right. If |loc| is -1 or out of bounds, the new extension is appended to the // list. -OPENSSL_EXPORT int X509_REVOKED_add_ext(X509_REVOKED *x, X509_EXTENSION *ex, - int loc); +OPENSSL_EXPORT int X509_REVOKED_add_ext(X509_REVOKED *x, + const X509_EXTENSION *ex, int loc); // X509_REVOKED_get_ext_d2i behaves like |X509V3_get_d2i| but looks for the // extension in |revoked|'s extension list. @@ -1628,47 +2174,6 @@ OPENSSL_EXPORT int X509_REVOKED_add1_ext_i2d(X509_REVOKED *x, int nid, void *value, int crit, unsigned long flags); -// X509_EXTENSION_create_by_NID creates a new |X509_EXTENSION| with type |nid|, -// value |data|, and critical bit |crit|. It returns the newly-allocated -// |X509_EXTENSION| on success, and false on error. |nid| should be a |NID_*| -// constant. -// -// If |ex| and |*ex| are both non-NULL, it modifies and returns |*ex| instead of -// creating a new object. If |ex| is non-NULL, but |*ex| is NULL, it sets |*ex| -// to the new |X509_EXTENSION|, in addition to returning the result. -OPENSSL_EXPORT X509_EXTENSION *X509_EXTENSION_create_by_NID( - X509_EXTENSION **ex, int nid, int crit, const ASN1_OCTET_STRING *data); - -// X509_EXTENSION_create_by_OBJ behaves like |X509_EXTENSION_create_by_NID|, but -// the extension type is determined by an |ASN1_OBJECT|. -OPENSSL_EXPORT X509_EXTENSION *X509_EXTENSION_create_by_OBJ( - X509_EXTENSION **ex, const ASN1_OBJECT *obj, int crit, - const ASN1_OCTET_STRING *data); - -// X509_EXTENSION_set_object sets |ex|'s extension type to |obj|. It returns one -// on success and zero on error. -OPENSSL_EXPORT int X509_EXTENSION_set_object(X509_EXTENSION *ex, - const ASN1_OBJECT *obj); - -// X509_EXTENSION_set_critical sets |ex| to critical if |crit| is non-zero and -// to non-critical if |crit| is zero. -OPENSSL_EXPORT int X509_EXTENSION_set_critical(X509_EXTENSION *ex, int crit); - -// X509_EXTENSION_set_data set's |ex|'s extension value to a copy of |data|. It -// returns one on success and zero on error. -OPENSSL_EXPORT int X509_EXTENSION_set_data(X509_EXTENSION *ex, - const ASN1_OCTET_STRING *data); - -// X509_EXTENSION_get_object returns |ex|'s extension type. -OPENSSL_EXPORT ASN1_OBJECT *X509_EXTENSION_get_object(X509_EXTENSION *ex); - -// X509_EXTENSION_get_data returns |ne|'s extension value. -OPENSSL_EXPORT ASN1_OCTET_STRING *X509_EXTENSION_get_data(X509_EXTENSION *ne); - -// X509_EXTENSION_get_critical returns one if |ex| is critical and zero -// otherwise. -OPENSSL_EXPORT int X509_EXTENSION_get_critical(const X509_EXTENSION *ex); - // X509at_get_attr_count returns the number of attributes in |x|. OPENSSL_EXPORT int X509at_get_attr_count(const STACK_OF(X509_ATTRIBUTE) *x); @@ -1770,8 +2275,6 @@ OPENSSL_EXPORT int X509_ATTRIBUTE_set1_object(X509_ATTRIBUTE *attr, // |attr|'s type. If |len| is -1, |strlen(data)| is used instead. See // |ASN1_STRING_set_by_NID| for details. // -// TODO(davidben): Document |ASN1_STRING_set_by_NID| so the reference is useful. -// // Otherwise, if |len| is not -1, the value is an ASN.1 string. |attrtype| is an // |ASN1_STRING| type value and the |len| bytes from |data| are copied as the // type-specific representation of |ASN1_STRING|. See |ASN1_STRING| for details. @@ -1828,17 +2331,21 @@ OPENSSL_EXPORT X509 *X509_find_by_subject(STACK_OF(X509) *sk, X509_NAME *name); // PKCS#8 utilities -DECLARE_ASN1_FUNCTIONS(PKCS8_PRIV_KEY_INFO) +DECLARE_ASN1_FUNCTIONS_const(PKCS8_PRIV_KEY_INFO) -OPENSSL_EXPORT EVP_PKEY *EVP_PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8); -OPENSSL_EXPORT PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(EVP_PKEY *pkey); +// EVP_PKCS82PKEY returns |p8| as a newly-allocated |EVP_PKEY|, or NULL if the +// key was unsupported or could not be decoded. If non-NULL, the caller must +// release the result with |EVP_PKEY_free| when done. +// +// Use |EVP_parse_private_key| instead. +OPENSSL_EXPORT EVP_PKEY *EVP_PKCS82PKEY(const PKCS8_PRIV_KEY_INFO *p8); -OPENSSL_EXPORT int PKCS8_pkey_set0(PKCS8_PRIV_KEY_INFO *priv, ASN1_OBJECT *aobj, - int version, int ptype, void *pval, - unsigned char *penc, int penclen); -OPENSSL_EXPORT int PKCS8_pkey_get0(ASN1_OBJECT **ppkalg, - const unsigned char **pk, int *ppklen, - X509_ALGOR **pa, PKCS8_PRIV_KEY_INFO *p8); +// EVP_PKEY2PKCS8 encodes |pkey| as a PKCS#8 PrivateKeyInfo (RFC 5208), +// represented as a newly-allocated |PKCS8_PRIV_KEY_INFO|, or NULL on error. The +// caller must release the result with |PKCS8_PRIV_KEY_INFO_free| when done. +// +// Use |EVP_marshal_private_key| instead. +OPENSSL_EXPORT PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(const EVP_PKEY *pkey); // X509_PUBKEY_set0_param sets |pub| to a key with AlgorithmIdentifier // determined by |obj|, |param_type|, and |param_value|, and an encoded @@ -1895,7 +2402,7 @@ struct rsa_pss_params_st { X509_ALGOR *maskHash; } /* RSA_PSS_PARAMS */; -DECLARE_ASN1_FUNCTIONS(RSA_PSS_PARAMS) +DECLARE_ASN1_FUNCTIONS_const(RSA_PSS_PARAMS) /* SSL_CTX -> X509_STORE @@ -2020,14 +2527,6 @@ OPENSSL_EXPORT void X509_STORE_CTX_set_depth(X509_STORE_CTX *ctx, int depth); #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 @@ -2074,12 +2573,6 @@ OPENSSL_EXPORT void X509_STORE_CTX_set_depth(X509_STORE_CTX *ctx, int depth); #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 @@ -2089,6 +2582,10 @@ OPENSSL_EXPORT void X509_STORE_CTX_set_depth(X509_STORE_CTX *ctx, int depth); // will force the behaviour to match that of previous versions. #define X509_V_FLAG_NO_ALT_CHAINS 0x100000 +// X509_V_FLAG_NO_CHECK_TIME disables all time checks in certificate +// verification. +#define X509_V_FLAG_NO_CHECK_TIME 0x200000 + #define X509_VP_FLAG_DEFAULT 0x1 #define X509_VP_FLAG_OVERWRITE 0x2 #define X509_VP_FLAG_RESET_FLAGS 0x4 @@ -2187,8 +2684,21 @@ 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); + +// X509_STORE_CTX_set0_trusted_stack configures |ctx| to trust the certificates +// in |sk|. |sk| must remain valid for the duration of |ctx|. +// +// WARNING: This function differs from most |set0| functions in that it does not +// take ownership of its input. The caller is required to ensure the lifetimes +// are consistent. +OPENSSL_EXPORT void X509_STORE_CTX_set0_trusted_stack(X509_STORE_CTX *ctx, + STACK_OF(X509) *sk); + +// X509_STORE_CTX_trusted_stack is a deprecated alias for +// |X509_STORE_CTX_set0_trusted_stack|. 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); @@ -2239,14 +2749,6 @@ 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); @@ -2277,10 +2779,6 @@ OPENSSL_EXPORT void X509_STORE_CTX_set_time(X509_STORE_CTX *ctx, 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, @@ -2346,37 +2844,6 @@ 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); - #if defined(__cplusplus) } // extern C @@ -2401,7 +2868,6 @@ BORINGSSL_MAKE_DELETER(X509_LOOKUP, X509_LOOKUP_free) BORINGSSL_MAKE_DELETER(X509_NAME, X509_NAME_free) BORINGSSL_MAKE_DELETER(X509_NAME_ENTRY, X509_NAME_ENTRY_free) BORINGSSL_MAKE_DELETER(X509_PKEY, X509_PKEY_free) -BORINGSSL_MAKE_DELETER(X509_POLICY_TREE, X509_policy_tree_free) BORINGSSL_MAKE_DELETER(X509_PUBKEY, X509_PUBKEY_free) BORINGSSL_MAKE_DELETER(X509_REQ, X509_REQ_free) BORINGSSL_MAKE_DELETER(X509_REVOKED, X509_REVOKED_free) diff --git a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_x509v3.h b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_x509v3.h index b9a6ef13..7a6c6f14 100644 --- a/Sources/CNIOBoringSSL/include/CNIOBoringSSL_x509v3.h +++ b/Sources/CNIOBoringSSL/include/CNIOBoringSSL_x509v3.h @@ -328,8 +328,8 @@ typedef struct PROXY_CERT_INFO_EXTENSION_st { PROXY_POLICY *proxyPolicy; } PROXY_CERT_INFO_EXTENSION; -DECLARE_ASN1_FUNCTIONS(PROXY_POLICY) -DECLARE_ASN1_FUNCTIONS(PROXY_CERT_INFO_EXTENSION) +DECLARE_ASN1_FUNCTIONS_const(PROXY_POLICY) +DECLARE_ASN1_FUNCTIONS_const(PROXY_CERT_INFO_EXTENSION) struct ISSUING_DIST_POINT_st { DIST_POINT_NAME *distpoint; @@ -443,10 +443,14 @@ typedef struct x509_purpose_st { DEFINE_STACK_OF(X509_PURPOSE) -DECLARE_ASN1_FUNCTIONS(BASIC_CONSTRAINTS) +DECLARE_ASN1_FUNCTIONS_const(BASIC_CONSTRAINTS) +// TODO(https://crbug.com/boringssl/407): This is not const because it contains +// an |X509_NAME|. DECLARE_ASN1_FUNCTIONS(AUTHORITY_KEYID) +// TODO(https://crbug.com/boringssl/407): This is not const because it contains +// an |X509_NAME|. DECLARE_ASN1_FUNCTIONS(GENERAL_NAME) OPENSSL_EXPORT GENERAL_NAME *GENERAL_NAME_dup(GENERAL_NAME *a); @@ -470,6 +474,8 @@ OPENSSL_EXPORT STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME( STACK_OF(CONF_VALUE) *ret); OPENSSL_EXPORT int GENERAL_NAME_print(BIO *out, GENERAL_NAME *gen); +// TODO(https://crbug.com/boringssl/407): This is not const because it contains +// an |X509_NAME|. DECLARE_ASN1_FUNCTIONS(GENERAL_NAMES) // i2v_GENERAL_NAMES serializes |gen| as a list of |CONF_VALUE|s. If |ret| is @@ -488,8 +494,8 @@ OPENSSL_EXPORT GENERAL_NAMES *v2i_GENERAL_NAMES(const X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval); -DECLARE_ASN1_FUNCTIONS(OTHERNAME) -DECLARE_ASN1_FUNCTIONS(EDIPARTYNAME) +DECLARE_ASN1_FUNCTIONS_const(OTHERNAME) +DECLARE_ASN1_FUNCTIONS_const(EDIPARTYNAME) OPENSSL_EXPORT int OTHERNAME_cmp(OTHERNAME *a, OTHERNAME *b); OPENSSL_EXPORT void GENERAL_NAME_set0_value(GENERAL_NAME *a, int type, void *value); @@ -506,18 +512,26 @@ OPENSSL_EXPORT char *i2s_ASN1_OCTET_STRING(const X509V3_EXT_METHOD *method, OPENSSL_EXPORT ASN1_OCTET_STRING *s2i_ASN1_OCTET_STRING( const X509V3_EXT_METHOD *method, X509V3_CTX *ctx, const char *str); -DECLARE_ASN1_FUNCTIONS(EXTENDED_KEY_USAGE) +DECLARE_ASN1_FUNCTIONS_const(EXTENDED_KEY_USAGE) OPENSSL_EXPORT int i2a_ACCESS_DESCRIPTION(BIO *bp, const ACCESS_DESCRIPTION *a); -DECLARE_ASN1_FUNCTIONS(CERTIFICATEPOLICIES) -DECLARE_ASN1_FUNCTIONS(POLICYINFO) -DECLARE_ASN1_FUNCTIONS(POLICYQUALINFO) -DECLARE_ASN1_FUNCTIONS(USERNOTICE) -DECLARE_ASN1_FUNCTIONS(NOTICEREF) +DECLARE_ASN1_FUNCTIONS_const(CERTIFICATEPOLICIES) +DECLARE_ASN1_FUNCTIONS_const(POLICYINFO) +DECLARE_ASN1_FUNCTIONS_const(POLICYQUALINFO) +DECLARE_ASN1_FUNCTIONS_const(USERNOTICE) +DECLARE_ASN1_FUNCTIONS_const(NOTICEREF) +// TODO(https://crbug.com/boringssl/407): This is not const because it contains +// an |X509_NAME|. DECLARE_ASN1_FUNCTIONS(CRL_DIST_POINTS) +// TODO(https://crbug.com/boringssl/407): This is not const because it contains +// an |X509_NAME|. DECLARE_ASN1_FUNCTIONS(DIST_POINT) +// TODO(https://crbug.com/boringssl/407): This is not const because it contains +// an |X509_NAME|. DECLARE_ASN1_FUNCTIONS(DIST_POINT_NAME) +// TODO(https://crbug.com/boringssl/407): This is not const because it contains +// an |X509_NAME|. DECLARE_ASN1_FUNCTIONS(ISSUING_DIST_POINT) OPENSSL_EXPORT int DIST_POINT_set_dpname(DIST_POINT_NAME *dpn, @@ -525,7 +539,11 @@ OPENSSL_EXPORT int DIST_POINT_set_dpname(DIST_POINT_NAME *dpn, OPENSSL_EXPORT int NAME_CONSTRAINTS_check(X509 *x, NAME_CONSTRAINTS *nc); +// TODO(https://crbug.com/boringssl/407): This is not const because it contains +// an |X509_NAME|. DECLARE_ASN1_FUNCTIONS(ACCESS_DESCRIPTION) +// TODO(https://crbug.com/boringssl/407): This is not const because it contains +// an |X509_NAME|. DECLARE_ASN1_FUNCTIONS(AUTHORITY_INFO_ACCESS) DECLARE_ASN1_ITEM(POLICY_MAPPING) @@ -769,12 +787,13 @@ OPENSSL_EXPORT int X509V3_add1_i2d(STACK_OF(X509_EXTENSION) **x, int nid, // hexdump. #define X509V3_EXT_DUMP_UNKNOWN (3L << 16) -OPENSSL_EXPORT void X509V3_EXT_val_prn(BIO *out, STACK_OF(CONF_VALUE) *val, +OPENSSL_EXPORT void X509V3_EXT_val_prn(BIO *out, + const STACK_OF(CONF_VALUE) *val, int indent, int ml); -OPENSSL_EXPORT int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, +OPENSSL_EXPORT int X509V3_EXT_print(BIO *out, const X509_EXTENSION *ext, unsigned long flag, int indent); -OPENSSL_EXPORT int X509V3_EXT_print_fp(FILE *out, X509_EXTENSION *ext, int flag, - int indent); +OPENSSL_EXPORT int X509V3_EXT_print_fp(FILE *out, const X509_EXTENSION *ext, + int flag, int indent); // X509V3_extensions_print prints |title|, followed by a human-readable // representation of |exts| to |out|. It returns one on success and zero on @@ -787,7 +806,7 @@ OPENSSL_EXPORT int X509V3_extensions_print(BIO *out, const char *title, OPENSSL_EXPORT int X509_check_ca(X509 *x); OPENSSL_EXPORT int X509_check_purpose(X509 *x, int id, int ca); -OPENSSL_EXPORT int X509_supported_extension(X509_EXTENSION *ex); +OPENSSL_EXPORT int X509_supported_extension(const X509_EXTENSION *ex); OPENSSL_EXPORT int X509_PURPOSE_set(int *p, int purpose); OPENSSL_EXPORT int X509_check_issued(X509 *issuer, X509 *subject); OPENSSL_EXPORT int X509_check_akid(X509 *issuer, AUTHORITY_KEYID *akid); @@ -888,10 +907,6 @@ OPENSSL_EXPORT int X509V3_NAME_from_section(X509_NAME *nm, STACK_OF(CONF_VALUE) *dn_sk, unsigned long chtype); -OPENSSL_EXPORT void X509_POLICY_NODE_print(BIO *out, X509_POLICY_NODE *node, - int indent); -DEFINE_STACK_OF(X509_POLICY_NODE) - // BEGIN ERROR CODES // The following lines are auto generated by the script mkerr.pl. Any changes // made after this point may be overwritten when the script is next run. diff --git a/Sources/CNIOBoringSSL/include/boringssl_prefix_symbols_nasm.inc b/Sources/CNIOBoringSSL/include/boringssl_prefix_symbols_nasm.inc index fccaa9d1..a34b32de 100644 --- a/Sources/CNIOBoringSSL/include/boringssl_prefix_symbols_nasm.inc +++ b/Sources/CNIOBoringSSL/include/boringssl_prefix_symbols_nasm.inc @@ -136,6 +136,8 @@ %xdefine _ASN1_TIME_set _ %+ BORINGSSL_PREFIX %+ _ASN1_TIME_set %xdefine _ASN1_TIME_set_string _ %+ BORINGSSL_PREFIX %+ _ASN1_TIME_set_string %xdefine _ASN1_TIME_to_generalizedtime _ %+ BORINGSSL_PREFIX %+ _ASN1_TIME_to_generalizedtime +%xdefine _ASN1_TIME_to_posix _ %+ BORINGSSL_PREFIX %+ _ASN1_TIME_to_posix +%xdefine _ASN1_TIME_to_time_t _ %+ BORINGSSL_PREFIX %+ _ASN1_TIME_to_time_t %xdefine _ASN1_TYPE_cmp _ %+ BORINGSSL_PREFIX %+ _ASN1_TYPE_cmp %xdefine _ASN1_TYPE_free _ %+ BORINGSSL_PREFIX %+ _ASN1_TYPE_free %xdefine _ASN1_TYPE_get _ %+ BORINGSSL_PREFIX %+ _ASN1_TYPE_get @@ -642,8 +644,10 @@ %xdefine _CRYPTO_sysrand_if_available _ %+ BORINGSSL_PREFIX %+ _CRYPTO_sysrand_if_available %xdefine _CRYPTO_tls1_prf _ %+ BORINGSSL_PREFIX %+ _CRYPTO_tls1_prf %xdefine _CTR_DRBG_clear _ %+ BORINGSSL_PREFIX %+ _CTR_DRBG_clear +%xdefine _CTR_DRBG_free _ %+ BORINGSSL_PREFIX %+ _CTR_DRBG_free %xdefine _CTR_DRBG_generate _ %+ BORINGSSL_PREFIX %+ _CTR_DRBG_generate %xdefine _CTR_DRBG_init _ %+ BORINGSSL_PREFIX %+ _CTR_DRBG_init +%xdefine _CTR_DRBG_new _ %+ BORINGSSL_PREFIX %+ _CTR_DRBG_new %xdefine _CTR_DRBG_reseed _ %+ BORINGSSL_PREFIX %+ _CTR_DRBG_reseed %xdefine _ChaCha20_ctr32 _ %+ BORINGSSL_PREFIX %+ _ChaCha20_ctr32 %xdefine _DES_decrypt3 _ %+ BORINGSSL_PREFIX %+ _DES_decrypt3 @@ -656,6 +660,7 @@ %xdefine _DES_set_key _ %+ BORINGSSL_PREFIX %+ _DES_set_key %xdefine _DES_set_key_unchecked _ %+ BORINGSSL_PREFIX %+ _DES_set_key_unchecked %xdefine _DES_set_odd_parity _ %+ BORINGSSL_PREFIX %+ _DES_set_odd_parity +%xdefine _DH_bits _ %+ BORINGSSL_PREFIX %+ _DH_bits %xdefine _DH_check _ %+ BORINGSSL_PREFIX %+ _DH_check %xdefine _DH_check_pub_key _ %+ BORINGSSL_PREFIX %+ _DH_check_pub_key %xdefine _DH_compute_key _ %+ BORINGSSL_PREFIX %+ _DH_compute_key @@ -701,6 +706,7 @@ %xdefine _DSA_SIG_new _ %+ BORINGSSL_PREFIX %+ _DSA_SIG_new %xdefine _DSA_SIG_parse _ %+ BORINGSSL_PREFIX %+ _DSA_SIG_parse %xdefine _DSA_SIG_set0 _ %+ BORINGSSL_PREFIX %+ _DSA_SIG_set0 +%xdefine _DSA_bits _ %+ BORINGSSL_PREFIX %+ _DSA_bits %xdefine _DSA_check_signature _ %+ BORINGSSL_PREFIX %+ _DSA_check_signature %xdefine _DSA_do_check_signature _ %+ BORINGSSL_PREFIX %+ _DSA_do_check_signature %xdefine _DSA_do_sign _ %+ BORINGSSL_PREFIX %+ _DSA_do_sign @@ -993,6 +999,7 @@ %xdefine _EVP_HPKE_CTX_export _ %+ BORINGSSL_PREFIX %+ _EVP_HPKE_CTX_export %xdefine _EVP_HPKE_CTX_free _ %+ BORINGSSL_PREFIX %+ _EVP_HPKE_CTX_free %xdefine _EVP_HPKE_CTX_kdf _ %+ BORINGSSL_PREFIX %+ _EVP_HPKE_CTX_kdf +%xdefine _EVP_HPKE_CTX_kem _ %+ BORINGSSL_PREFIX %+ _EVP_HPKE_CTX_kem %xdefine _EVP_HPKE_CTX_max_overhead _ %+ BORINGSSL_PREFIX %+ _EVP_HPKE_CTX_max_overhead %xdefine _EVP_HPKE_CTX_new _ %+ BORINGSSL_PREFIX %+ _EVP_HPKE_CTX_new %xdefine _EVP_HPKE_CTX_open _ %+ BORINGSSL_PREFIX %+ _EVP_HPKE_CTX_open @@ -1001,7 +1008,9 @@ %xdefine _EVP_HPKE_CTX_setup_sender _ %+ BORINGSSL_PREFIX %+ _EVP_HPKE_CTX_setup_sender %xdefine _EVP_HPKE_CTX_setup_sender_with_seed_for_testing _ %+ BORINGSSL_PREFIX %+ _EVP_HPKE_CTX_setup_sender_with_seed_for_testing %xdefine _EVP_HPKE_CTX_zero _ %+ BORINGSSL_PREFIX %+ _EVP_HPKE_CTX_zero +%xdefine _EVP_HPKE_KDF_hkdf_md _ %+ BORINGSSL_PREFIX %+ _EVP_HPKE_KDF_hkdf_md %xdefine _EVP_HPKE_KDF_id _ %+ BORINGSSL_PREFIX %+ _EVP_HPKE_KDF_id +%xdefine _EVP_HPKE_KEM_enc_len _ %+ BORINGSSL_PREFIX %+ _EVP_HPKE_KEM_enc_len %xdefine _EVP_HPKE_KEM_id _ %+ BORINGSSL_PREFIX %+ _EVP_HPKE_KEM_id %xdefine _EVP_HPKE_KEY_cleanup _ %+ BORINGSSL_PREFIX %+ _EVP_HPKE_KEY_cleanup %xdefine _EVP_HPKE_KEY_copy _ %+ BORINGSSL_PREFIX %+ _EVP_HPKE_KEY_copy @@ -1138,6 +1147,7 @@ %xdefine _EVP_aead_aes_128_cbc_sha1_tls_implicit_iv _ %+ BORINGSSL_PREFIX %+ _EVP_aead_aes_128_cbc_sha1_tls_implicit_iv %xdefine _EVP_aead_aes_128_ccm_bluetooth _ %+ BORINGSSL_PREFIX %+ _EVP_aead_aes_128_ccm_bluetooth %xdefine _EVP_aead_aes_128_ccm_bluetooth_8 _ %+ BORINGSSL_PREFIX %+ _EVP_aead_aes_128_ccm_bluetooth_8 +%xdefine _EVP_aead_aes_128_ccm_matter _ %+ BORINGSSL_PREFIX %+ _EVP_aead_aes_128_ccm_matter %xdefine _EVP_aead_aes_128_ctr_hmac_sha256 _ %+ BORINGSSL_PREFIX %+ _EVP_aead_aes_128_ctr_hmac_sha256 %xdefine _EVP_aead_aes_128_gcm _ %+ BORINGSSL_PREFIX %+ _EVP_aead_aes_128_gcm %xdefine _EVP_aead_aes_128_gcm_randnonce _ %+ BORINGSSL_PREFIX %+ _EVP_aead_aes_128_gcm_randnonce @@ -1253,6 +1263,7 @@ %xdefine _HMAC_CTX_copy _ %+ BORINGSSL_PREFIX %+ _HMAC_CTX_copy %xdefine _HMAC_CTX_copy_ex _ %+ BORINGSSL_PREFIX %+ _HMAC_CTX_copy_ex %xdefine _HMAC_CTX_free _ %+ BORINGSSL_PREFIX %+ _HMAC_CTX_free +%xdefine _HMAC_CTX_get_md _ %+ BORINGSSL_PREFIX %+ _HMAC_CTX_get_md %xdefine _HMAC_CTX_init _ %+ BORINGSSL_PREFIX %+ _HMAC_CTX_init %xdefine _HMAC_CTX_new _ %+ BORINGSSL_PREFIX %+ _HMAC_CTX_new %xdefine _HMAC_CTX_reset _ %+ BORINGSSL_PREFIX %+ _HMAC_CTX_reset @@ -1357,6 +1368,7 @@ %xdefine _OPENSSL_malloc_init _ %+ BORINGSSL_PREFIX %+ _OPENSSL_malloc_init %xdefine _OPENSSL_memdup _ %+ BORINGSSL_PREFIX %+ _OPENSSL_memdup %xdefine _OPENSSL_no_config _ %+ BORINGSSL_PREFIX %+ _OPENSSL_no_config +%xdefine _OPENSSL_posix_to_tm _ %+ BORINGSSL_PREFIX %+ _OPENSSL_posix_to_tm %xdefine _OPENSSL_realloc _ %+ BORINGSSL_PREFIX %+ _OPENSSL_realloc %xdefine _OPENSSL_strcasecmp _ %+ BORINGSSL_PREFIX %+ _OPENSSL_strcasecmp %xdefine _OPENSSL_strdup _ %+ BORINGSSL_PREFIX %+ _OPENSSL_strdup @@ -1366,6 +1378,8 @@ %xdefine _OPENSSL_strncasecmp _ %+ BORINGSSL_PREFIX %+ _OPENSSL_strncasecmp %xdefine _OPENSSL_strndup _ %+ BORINGSSL_PREFIX %+ _OPENSSL_strndup %xdefine _OPENSSL_strnlen _ %+ BORINGSSL_PREFIX %+ _OPENSSL_strnlen +%xdefine _OPENSSL_timegm _ %+ BORINGSSL_PREFIX %+ _OPENSSL_timegm +%xdefine _OPENSSL_tm_to_posix _ %+ BORINGSSL_PREFIX %+ _OPENSSL_tm_to_posix %xdefine _OPENSSL_tolower _ %+ BORINGSSL_PREFIX %+ _OPENSSL_tolower %xdefine _OTHERNAME_cmp _ %+ BORINGSSL_PREFIX %+ _OTHERNAME_cmp %xdefine _OTHERNAME_free _ %+ BORINGSSL_PREFIX %+ _OTHERNAME_free @@ -1382,7 +1396,6 @@ %xdefine _PEM_ASN1_write_bio _ %+ BORINGSSL_PREFIX %+ _PEM_ASN1_write_bio %xdefine _PEM_X509_INFO_read _ %+ BORINGSSL_PREFIX %+ _PEM_X509_INFO_read %xdefine _PEM_X509_INFO_read_bio _ %+ BORINGSSL_PREFIX %+ _PEM_X509_INFO_read_bio -%xdefine _PEM_X509_INFO_write_bio _ %+ BORINGSSL_PREFIX %+ _PEM_X509_INFO_write_bio %xdefine _PEM_bytes_read_bio _ %+ BORINGSSL_PREFIX %+ _PEM_bytes_read_bio %xdefine _PEM_def_callback _ %+ BORINGSSL_PREFIX %+ _PEM_def_callback %xdefine _PEM_dek_info _ %+ BORINGSSL_PREFIX %+ _PEM_dek_info @@ -1508,8 +1521,6 @@ %xdefine _PKCS8_encrypt _ %+ BORINGSSL_PREFIX %+ _PKCS8_encrypt %xdefine _PKCS8_marshal_encrypted_private_key _ %+ BORINGSSL_PREFIX %+ _PKCS8_marshal_encrypted_private_key %xdefine _PKCS8_parse_encrypted_private_key _ %+ BORINGSSL_PREFIX %+ _PKCS8_parse_encrypted_private_key -%xdefine _PKCS8_pkey_get0 _ %+ BORINGSSL_PREFIX %+ _PKCS8_pkey_get0 -%xdefine _PKCS8_pkey_set0 _ %+ BORINGSSL_PREFIX %+ _PKCS8_pkey_set0 %xdefine _POLICYINFO_free _ %+ BORINGSSL_PREFIX %+ _POLICYINFO_free %xdefine _POLICYINFO_it _ %+ BORINGSSL_PREFIX %+ _POLICYINFO_it %xdefine _POLICYINFO_new _ %+ BORINGSSL_PREFIX %+ _POLICYINFO_new @@ -1539,6 +1550,7 @@ %xdefine _RAND_enable_fork_unsafe_buffering _ %+ BORINGSSL_PREFIX %+ _RAND_enable_fork_unsafe_buffering %xdefine _RAND_file_name _ %+ BORINGSSL_PREFIX %+ _RAND_file_name %xdefine _RAND_get_rand_method _ %+ BORINGSSL_PREFIX %+ _RAND_get_rand_method +%xdefine _RAND_get_system_entropy_for_custom_prng _ %+ BORINGSSL_PREFIX %+ _RAND_get_system_entropy_for_custom_prng %xdefine _RAND_load_file _ %+ BORINGSSL_PREFIX %+ _RAND_load_file %xdefine _RAND_poll _ %+ BORINGSSL_PREFIX %+ _RAND_poll %xdefine _RAND_pseudo_bytes _ %+ BORINGSSL_PREFIX %+ _RAND_pseudo_bytes @@ -1712,6 +1724,7 @@ %xdefine _SSL_CTX_get_max_proto_version _ %+ BORINGSSL_PREFIX %+ _SSL_CTX_get_max_proto_version %xdefine _SSL_CTX_get_min_proto_version _ %+ BORINGSSL_PREFIX %+ _SSL_CTX_get_min_proto_version %xdefine _SSL_CTX_get_mode _ %+ BORINGSSL_PREFIX %+ _SSL_CTX_get_mode +%xdefine _SSL_CTX_get_num_tickets _ %+ BORINGSSL_PREFIX %+ _SSL_CTX_get_num_tickets %xdefine _SSL_CTX_get_options _ %+ BORINGSSL_PREFIX %+ _SSL_CTX_get_options %xdefine _SSL_CTX_get_quiet_shutdown _ %+ BORINGSSL_PREFIX %+ _SSL_CTX_get_quiet_shutdown %xdefine _SSL_CTX_get_read_ahead _ %+ BORINGSSL_PREFIX %+ _SSL_CTX_get_read_ahead @@ -2194,7 +2207,6 @@ %xdefine _USERNOTICE_free _ %+ BORINGSSL_PREFIX %+ _USERNOTICE_free %xdefine _USERNOTICE_it _ %+ BORINGSSL_PREFIX %+ _USERNOTICE_it %xdefine _USERNOTICE_new _ %+ BORINGSSL_PREFIX %+ _USERNOTICE_new -%xdefine _UTF8_getc _ %+ BORINGSSL_PREFIX %+ _UTF8_getc %xdefine _UTF8_putc _ %+ BORINGSSL_PREFIX %+ _UTF8_putc %xdefine _X25519 _ %+ BORINGSSL_PREFIX %+ _X25519 %xdefine _X25519_keypair _ %+ BORINGSSL_PREFIX %+ _X25519_keypair @@ -2237,7 +2249,6 @@ %xdefine _X509V3_set_ctx _ %+ BORINGSSL_PREFIX %+ _X509V3_set_ctx %xdefine _X509V3_set_nconf _ %+ BORINGSSL_PREFIX %+ _X509V3_set_nconf %xdefine _X509V3_string_free _ %+ BORINGSSL_PREFIX %+ _X509V3_string_free -%xdefine _X509_ALGORS_it _ %+ BORINGSSL_PREFIX %+ _X509_ALGORS_it %xdefine _X509_ALGOR_cmp _ %+ BORINGSSL_PREFIX %+ _X509_ALGOR_cmp %xdefine _X509_ALGOR_dup _ %+ BORINGSSL_PREFIX %+ _X509_ALGOR_dup %xdefine _X509_ALGOR_free _ %+ BORINGSSL_PREFIX %+ _X509_ALGOR_free @@ -2273,7 +2284,6 @@ %xdefine _X509_CRL_add0_revoked _ %+ BORINGSSL_PREFIX %+ _X509_CRL_add0_revoked %xdefine _X509_CRL_add1_ext_i2d _ %+ BORINGSSL_PREFIX %+ _X509_CRL_add1_ext_i2d %xdefine _X509_CRL_add_ext _ %+ BORINGSSL_PREFIX %+ _X509_CRL_add_ext -%xdefine _X509_CRL_check_suiteb _ %+ BORINGSSL_PREFIX %+ _X509_CRL_check_suiteb %xdefine _X509_CRL_cmp _ %+ BORINGSSL_PREFIX %+ _X509_CRL_cmp %xdefine _X509_CRL_delete_ext _ %+ BORINGSSL_PREFIX %+ _X509_CRL_delete_ext %xdefine _X509_CRL_diff _ %+ BORINGSSL_PREFIX %+ _X509_CRL_diff @@ -2478,7 +2488,6 @@ %xdefine _X509_STORE_CTX_get0_current_issuer _ %+ BORINGSSL_PREFIX %+ _X509_STORE_CTX_get0_current_issuer %xdefine _X509_STORE_CTX_get0_param _ %+ BORINGSSL_PREFIX %+ _X509_STORE_CTX_get0_param %xdefine _X509_STORE_CTX_get0_parent_ctx _ %+ BORINGSSL_PREFIX %+ _X509_STORE_CTX_get0_parent_ctx -%xdefine _X509_STORE_CTX_get0_policy_tree _ %+ BORINGSSL_PREFIX %+ _X509_STORE_CTX_get0_policy_tree %xdefine _X509_STORE_CTX_get0_store _ %+ BORINGSSL_PREFIX %+ _X509_STORE_CTX_get0_store %xdefine _X509_STORE_CTX_get0_untrusted _ %+ BORINGSSL_PREFIX %+ _X509_STORE_CTX_get0_untrusted %xdefine _X509_STORE_CTX_get1_chain _ %+ BORINGSSL_PREFIX %+ _X509_STORE_CTX_get1_chain @@ -2489,12 +2498,12 @@ %xdefine _X509_STORE_CTX_get_error_depth _ %+ BORINGSSL_PREFIX %+ _X509_STORE_CTX_get_error_depth %xdefine _X509_STORE_CTX_get_ex_data _ %+ BORINGSSL_PREFIX %+ _X509_STORE_CTX_get_ex_data %xdefine _X509_STORE_CTX_get_ex_new_index _ %+ BORINGSSL_PREFIX %+ _X509_STORE_CTX_get_ex_new_index -%xdefine _X509_STORE_CTX_get_explicit_policy _ %+ BORINGSSL_PREFIX %+ _X509_STORE_CTX_get_explicit_policy %xdefine _X509_STORE_CTX_init _ %+ BORINGSSL_PREFIX %+ _X509_STORE_CTX_init %xdefine _X509_STORE_CTX_new _ %+ BORINGSSL_PREFIX %+ _X509_STORE_CTX_new %xdefine _X509_STORE_CTX_purpose_inherit _ %+ BORINGSSL_PREFIX %+ _X509_STORE_CTX_purpose_inherit %xdefine _X509_STORE_CTX_set0_crls _ %+ BORINGSSL_PREFIX %+ _X509_STORE_CTX_set0_crls %xdefine _X509_STORE_CTX_set0_param _ %+ BORINGSSL_PREFIX %+ _X509_STORE_CTX_set0_param +%xdefine _X509_STORE_CTX_set0_trusted_stack _ %+ BORINGSSL_PREFIX %+ _X509_STORE_CTX_set0_trusted_stack %xdefine _X509_STORE_CTX_set_cert _ %+ BORINGSSL_PREFIX %+ _X509_STORE_CTX_set_cert %xdefine _X509_STORE_CTX_set_chain _ %+ BORINGSSL_PREFIX %+ _X509_STORE_CTX_set_chain %xdefine _X509_STORE_CTX_set_default _ %+ BORINGSSL_PREFIX %+ _X509_STORE_CTX_set_default @@ -2594,7 +2603,6 @@ %xdefine _X509_add_ext _ %+ BORINGSSL_PREFIX %+ _X509_add_ext %xdefine _X509_alias_get0 _ %+ BORINGSSL_PREFIX %+ _X509_alias_get0 %xdefine _X509_alias_set1 _ %+ BORINGSSL_PREFIX %+ _X509_alias_set1 -%xdefine _X509_chain_check_suiteb _ %+ BORINGSSL_PREFIX %+ _X509_chain_check_suiteb %xdefine _X509_chain_up_ref _ %+ BORINGSSL_PREFIX %+ _X509_chain_up_ref %xdefine _X509_check_akid _ %+ BORINGSSL_PREFIX %+ _X509_check_akid %xdefine _X509_check_ca _ %+ BORINGSSL_PREFIX %+ _X509_check_ca @@ -2671,19 +2679,9 @@ %xdefine _X509_load_cert_file _ %+ BORINGSSL_PREFIX %+ _X509_load_cert_file %xdefine _X509_load_crl_file _ %+ BORINGSSL_PREFIX %+ _X509_load_crl_file %xdefine _X509_new _ %+ BORINGSSL_PREFIX %+ _X509_new -%xdefine _X509_ocspid_print _ %+ BORINGSSL_PREFIX %+ _X509_ocspid_print %xdefine _X509_parse_from_buffer _ %+ BORINGSSL_PREFIX %+ _X509_parse_from_buffer %xdefine _X509_policy_check _ %+ BORINGSSL_PREFIX %+ _X509_policy_check -%xdefine _X509_policy_level_get0_node _ %+ BORINGSSL_PREFIX %+ _X509_policy_level_get0_node -%xdefine _X509_policy_level_node_count _ %+ BORINGSSL_PREFIX %+ _X509_policy_level_node_count -%xdefine _X509_policy_node_get0_parent _ %+ BORINGSSL_PREFIX %+ _X509_policy_node_get0_parent -%xdefine _X509_policy_node_get0_policy _ %+ BORINGSSL_PREFIX %+ _X509_policy_node_get0_policy -%xdefine _X509_policy_node_get0_qualifiers _ %+ BORINGSSL_PREFIX %+ _X509_policy_node_get0_qualifiers %xdefine _X509_policy_tree_free _ %+ BORINGSSL_PREFIX %+ _X509_policy_tree_free -%xdefine _X509_policy_tree_get0_level _ %+ BORINGSSL_PREFIX %+ _X509_policy_tree_get0_level -%xdefine _X509_policy_tree_get0_policies _ %+ BORINGSSL_PREFIX %+ _X509_policy_tree_get0_policies -%xdefine _X509_policy_tree_get0_user_policies _ %+ BORINGSSL_PREFIX %+ _X509_policy_tree_get0_user_policies -%xdefine _X509_policy_tree_level_count _ %+ BORINGSSL_PREFIX %+ _X509_policy_tree_level_count %xdefine _X509_print _ %+ BORINGSSL_PREFIX %+ _X509_print %xdefine _X509_print_ex _ %+ BORINGSSL_PREFIX %+ _X509_print_ex %xdefine _X509_print_ex_fp _ %+ BORINGSSL_PREFIX %+ _X509_print_ex_fp @@ -2982,7 +2980,6 @@ %xdefine _d2i_USERNOTICE _ %+ BORINGSSL_PREFIX %+ _d2i_USERNOTICE %xdefine _d2i_X509 _ %+ BORINGSSL_PREFIX %+ _d2i_X509 %xdefine _d2i_X509_ALGOR _ %+ BORINGSSL_PREFIX %+ _d2i_X509_ALGOR -%xdefine _d2i_X509_ALGORS _ %+ BORINGSSL_PREFIX %+ _d2i_X509_ALGORS %xdefine _d2i_X509_ATTRIBUTE _ %+ BORINGSSL_PREFIX %+ _d2i_X509_ATTRIBUTE %xdefine _d2i_X509_AUX _ %+ BORINGSSL_PREFIX %+ _d2i_X509_AUX %xdefine _d2i_X509_CERT_AUX _ %+ BORINGSSL_PREFIX %+ _d2i_X509_CERT_AUX @@ -3098,7 +3095,6 @@ %xdefine _ecdsa_sign_with_nonce_for_known_answer_test _ %+ BORINGSSL_PREFIX %+ _ecdsa_sign_with_nonce_for_known_answer_test %xdefine _ecp_nistz256_avx2_select_w7 _ %+ BORINGSSL_PREFIX %+ _ecp_nistz256_avx2_select_w7 %xdefine _ecp_nistz256_div_by_2 _ %+ BORINGSSL_PREFIX %+ _ecp_nistz256_div_by_2 -%xdefine _ecp_nistz256_from_mont _ %+ BORINGSSL_PREFIX %+ _ecp_nistz256_from_mont %xdefine _ecp_nistz256_mul_by_2 _ %+ BORINGSSL_PREFIX %+ _ecp_nistz256_mul_by_2 %xdefine _ecp_nistz256_mul_by_3 _ %+ BORINGSSL_PREFIX %+ _ecp_nistz256_mul_by_3 %xdefine _ecp_nistz256_mul_mont _ %+ BORINGSSL_PREFIX %+ _ecp_nistz256_mul_mont @@ -3112,7 +3108,6 @@ %xdefine _ecp_nistz256_select_w7 _ %+ BORINGSSL_PREFIX %+ _ecp_nistz256_select_w7 %xdefine _ecp_nistz256_sqr_mont _ %+ BORINGSSL_PREFIX %+ _ecp_nistz256_sqr_mont %xdefine _ecp_nistz256_sub _ %+ BORINGSSL_PREFIX %+ _ecp_nistz256_sub -%xdefine _ecp_nistz256_to_mont _ %+ BORINGSSL_PREFIX %+ _ecp_nistz256_to_mont %xdefine _ed25519_asn1_meth _ %+ BORINGSSL_PREFIX %+ _ed25519_asn1_meth %xdefine _ed25519_pkey_meth _ %+ BORINGSSL_PREFIX %+ _ed25519_pkey_meth %xdefine _gcm_ghash_avx _ %+ BORINGSSL_PREFIX %+ _gcm_ghash_avx @@ -3243,7 +3238,6 @@ %xdefine _i2d_USERNOTICE _ %+ BORINGSSL_PREFIX %+ _i2d_USERNOTICE %xdefine _i2d_X509 _ %+ BORINGSSL_PREFIX %+ _i2d_X509 %xdefine _i2d_X509_ALGOR _ %+ BORINGSSL_PREFIX %+ _i2d_X509_ALGOR -%xdefine _i2d_X509_ALGORS _ %+ BORINGSSL_PREFIX %+ _i2d_X509_ALGORS %xdefine _i2d_X509_ATTRIBUTE _ %+ BORINGSSL_PREFIX %+ _i2d_X509_ATTRIBUTE %xdefine _i2d_X509_AUX _ %+ BORINGSSL_PREFIX %+ _i2d_X509_AUX %xdefine _i2d_X509_CERT_AUX _ %+ BORINGSSL_PREFIX %+ _i2d_X509_CERT_AUX @@ -3594,6 +3588,8 @@ %xdefine ASN1_TIME_set BORINGSSL_PREFIX %+ _ASN1_TIME_set %xdefine ASN1_TIME_set_string BORINGSSL_PREFIX %+ _ASN1_TIME_set_string %xdefine ASN1_TIME_to_generalizedtime BORINGSSL_PREFIX %+ _ASN1_TIME_to_generalizedtime +%xdefine ASN1_TIME_to_posix BORINGSSL_PREFIX %+ _ASN1_TIME_to_posix +%xdefine ASN1_TIME_to_time_t BORINGSSL_PREFIX %+ _ASN1_TIME_to_time_t %xdefine ASN1_TYPE_cmp BORINGSSL_PREFIX %+ _ASN1_TYPE_cmp %xdefine ASN1_TYPE_free BORINGSSL_PREFIX %+ _ASN1_TYPE_free %xdefine ASN1_TYPE_get BORINGSSL_PREFIX %+ _ASN1_TYPE_get @@ -4100,8 +4096,10 @@ %xdefine CRYPTO_sysrand_if_available BORINGSSL_PREFIX %+ _CRYPTO_sysrand_if_available %xdefine CRYPTO_tls1_prf BORINGSSL_PREFIX %+ _CRYPTO_tls1_prf %xdefine CTR_DRBG_clear BORINGSSL_PREFIX %+ _CTR_DRBG_clear +%xdefine CTR_DRBG_free BORINGSSL_PREFIX %+ _CTR_DRBG_free %xdefine CTR_DRBG_generate BORINGSSL_PREFIX %+ _CTR_DRBG_generate %xdefine CTR_DRBG_init BORINGSSL_PREFIX %+ _CTR_DRBG_init +%xdefine CTR_DRBG_new BORINGSSL_PREFIX %+ _CTR_DRBG_new %xdefine CTR_DRBG_reseed BORINGSSL_PREFIX %+ _CTR_DRBG_reseed %xdefine ChaCha20_ctr32 BORINGSSL_PREFIX %+ _ChaCha20_ctr32 %xdefine DES_decrypt3 BORINGSSL_PREFIX %+ _DES_decrypt3 @@ -4114,6 +4112,7 @@ %xdefine DES_set_key BORINGSSL_PREFIX %+ _DES_set_key %xdefine DES_set_key_unchecked BORINGSSL_PREFIX %+ _DES_set_key_unchecked %xdefine DES_set_odd_parity BORINGSSL_PREFIX %+ _DES_set_odd_parity +%xdefine DH_bits BORINGSSL_PREFIX %+ _DH_bits %xdefine DH_check BORINGSSL_PREFIX %+ _DH_check %xdefine DH_check_pub_key BORINGSSL_PREFIX %+ _DH_check_pub_key %xdefine DH_compute_key BORINGSSL_PREFIX %+ _DH_compute_key @@ -4159,6 +4158,7 @@ %xdefine DSA_SIG_new BORINGSSL_PREFIX %+ _DSA_SIG_new %xdefine DSA_SIG_parse BORINGSSL_PREFIX %+ _DSA_SIG_parse %xdefine DSA_SIG_set0 BORINGSSL_PREFIX %+ _DSA_SIG_set0 +%xdefine DSA_bits BORINGSSL_PREFIX %+ _DSA_bits %xdefine DSA_check_signature BORINGSSL_PREFIX %+ _DSA_check_signature %xdefine DSA_do_check_signature BORINGSSL_PREFIX %+ _DSA_do_check_signature %xdefine DSA_do_sign BORINGSSL_PREFIX %+ _DSA_do_sign @@ -4451,6 +4451,7 @@ %xdefine EVP_HPKE_CTX_export BORINGSSL_PREFIX %+ _EVP_HPKE_CTX_export %xdefine EVP_HPKE_CTX_free BORINGSSL_PREFIX %+ _EVP_HPKE_CTX_free %xdefine EVP_HPKE_CTX_kdf BORINGSSL_PREFIX %+ _EVP_HPKE_CTX_kdf +%xdefine EVP_HPKE_CTX_kem BORINGSSL_PREFIX %+ _EVP_HPKE_CTX_kem %xdefine EVP_HPKE_CTX_max_overhead BORINGSSL_PREFIX %+ _EVP_HPKE_CTX_max_overhead %xdefine EVP_HPKE_CTX_new BORINGSSL_PREFIX %+ _EVP_HPKE_CTX_new %xdefine EVP_HPKE_CTX_open BORINGSSL_PREFIX %+ _EVP_HPKE_CTX_open @@ -4459,7 +4460,9 @@ %xdefine EVP_HPKE_CTX_setup_sender BORINGSSL_PREFIX %+ _EVP_HPKE_CTX_setup_sender %xdefine EVP_HPKE_CTX_setup_sender_with_seed_for_testing BORINGSSL_PREFIX %+ _EVP_HPKE_CTX_setup_sender_with_seed_for_testing %xdefine EVP_HPKE_CTX_zero BORINGSSL_PREFIX %+ _EVP_HPKE_CTX_zero +%xdefine EVP_HPKE_KDF_hkdf_md BORINGSSL_PREFIX %+ _EVP_HPKE_KDF_hkdf_md %xdefine EVP_HPKE_KDF_id BORINGSSL_PREFIX %+ _EVP_HPKE_KDF_id +%xdefine EVP_HPKE_KEM_enc_len BORINGSSL_PREFIX %+ _EVP_HPKE_KEM_enc_len %xdefine EVP_HPKE_KEM_id BORINGSSL_PREFIX %+ _EVP_HPKE_KEM_id %xdefine EVP_HPKE_KEY_cleanup BORINGSSL_PREFIX %+ _EVP_HPKE_KEY_cleanup %xdefine EVP_HPKE_KEY_copy BORINGSSL_PREFIX %+ _EVP_HPKE_KEY_copy @@ -4596,6 +4599,7 @@ %xdefine EVP_aead_aes_128_cbc_sha1_tls_implicit_iv BORINGSSL_PREFIX %+ _EVP_aead_aes_128_cbc_sha1_tls_implicit_iv %xdefine EVP_aead_aes_128_ccm_bluetooth BORINGSSL_PREFIX %+ _EVP_aead_aes_128_ccm_bluetooth %xdefine EVP_aead_aes_128_ccm_bluetooth_8 BORINGSSL_PREFIX %+ _EVP_aead_aes_128_ccm_bluetooth_8 +%xdefine EVP_aead_aes_128_ccm_matter BORINGSSL_PREFIX %+ _EVP_aead_aes_128_ccm_matter %xdefine EVP_aead_aes_128_ctr_hmac_sha256 BORINGSSL_PREFIX %+ _EVP_aead_aes_128_ctr_hmac_sha256 %xdefine EVP_aead_aes_128_gcm BORINGSSL_PREFIX %+ _EVP_aead_aes_128_gcm %xdefine EVP_aead_aes_128_gcm_randnonce BORINGSSL_PREFIX %+ _EVP_aead_aes_128_gcm_randnonce @@ -4711,6 +4715,7 @@ %xdefine HMAC_CTX_copy BORINGSSL_PREFIX %+ _HMAC_CTX_copy %xdefine HMAC_CTX_copy_ex BORINGSSL_PREFIX %+ _HMAC_CTX_copy_ex %xdefine HMAC_CTX_free BORINGSSL_PREFIX %+ _HMAC_CTX_free +%xdefine HMAC_CTX_get_md BORINGSSL_PREFIX %+ _HMAC_CTX_get_md %xdefine HMAC_CTX_init BORINGSSL_PREFIX %+ _HMAC_CTX_init %xdefine HMAC_CTX_new BORINGSSL_PREFIX %+ _HMAC_CTX_new %xdefine HMAC_CTX_reset BORINGSSL_PREFIX %+ _HMAC_CTX_reset @@ -4815,6 +4820,7 @@ %xdefine OPENSSL_malloc_init BORINGSSL_PREFIX %+ _OPENSSL_malloc_init %xdefine OPENSSL_memdup BORINGSSL_PREFIX %+ _OPENSSL_memdup %xdefine OPENSSL_no_config BORINGSSL_PREFIX %+ _OPENSSL_no_config +%xdefine OPENSSL_posix_to_tm BORINGSSL_PREFIX %+ _OPENSSL_posix_to_tm %xdefine OPENSSL_realloc BORINGSSL_PREFIX %+ _OPENSSL_realloc %xdefine OPENSSL_strcasecmp BORINGSSL_PREFIX %+ _OPENSSL_strcasecmp %xdefine OPENSSL_strdup BORINGSSL_PREFIX %+ _OPENSSL_strdup @@ -4824,6 +4830,8 @@ %xdefine OPENSSL_strncasecmp BORINGSSL_PREFIX %+ _OPENSSL_strncasecmp %xdefine OPENSSL_strndup BORINGSSL_PREFIX %+ _OPENSSL_strndup %xdefine OPENSSL_strnlen BORINGSSL_PREFIX %+ _OPENSSL_strnlen +%xdefine OPENSSL_timegm BORINGSSL_PREFIX %+ _OPENSSL_timegm +%xdefine OPENSSL_tm_to_posix BORINGSSL_PREFIX %+ _OPENSSL_tm_to_posix %xdefine OPENSSL_tolower BORINGSSL_PREFIX %+ _OPENSSL_tolower %xdefine OTHERNAME_cmp BORINGSSL_PREFIX %+ _OTHERNAME_cmp %xdefine OTHERNAME_free BORINGSSL_PREFIX %+ _OTHERNAME_free @@ -4840,7 +4848,6 @@ %xdefine PEM_ASN1_write_bio BORINGSSL_PREFIX %+ _PEM_ASN1_write_bio %xdefine PEM_X509_INFO_read BORINGSSL_PREFIX %+ _PEM_X509_INFO_read %xdefine PEM_X509_INFO_read_bio BORINGSSL_PREFIX %+ _PEM_X509_INFO_read_bio -%xdefine PEM_X509_INFO_write_bio BORINGSSL_PREFIX %+ _PEM_X509_INFO_write_bio %xdefine PEM_bytes_read_bio BORINGSSL_PREFIX %+ _PEM_bytes_read_bio %xdefine PEM_def_callback BORINGSSL_PREFIX %+ _PEM_def_callback %xdefine PEM_dek_info BORINGSSL_PREFIX %+ _PEM_dek_info @@ -4966,8 +4973,6 @@ %xdefine PKCS8_encrypt BORINGSSL_PREFIX %+ _PKCS8_encrypt %xdefine PKCS8_marshal_encrypted_private_key BORINGSSL_PREFIX %+ _PKCS8_marshal_encrypted_private_key %xdefine PKCS8_parse_encrypted_private_key BORINGSSL_PREFIX %+ _PKCS8_parse_encrypted_private_key -%xdefine PKCS8_pkey_get0 BORINGSSL_PREFIX %+ _PKCS8_pkey_get0 -%xdefine PKCS8_pkey_set0 BORINGSSL_PREFIX %+ _PKCS8_pkey_set0 %xdefine POLICYINFO_free BORINGSSL_PREFIX %+ _POLICYINFO_free %xdefine POLICYINFO_it BORINGSSL_PREFIX %+ _POLICYINFO_it %xdefine POLICYINFO_new BORINGSSL_PREFIX %+ _POLICYINFO_new @@ -4997,6 +5002,7 @@ %xdefine RAND_enable_fork_unsafe_buffering BORINGSSL_PREFIX %+ _RAND_enable_fork_unsafe_buffering %xdefine RAND_file_name BORINGSSL_PREFIX %+ _RAND_file_name %xdefine RAND_get_rand_method BORINGSSL_PREFIX %+ _RAND_get_rand_method +%xdefine RAND_get_system_entropy_for_custom_prng BORINGSSL_PREFIX %+ _RAND_get_system_entropy_for_custom_prng %xdefine RAND_load_file BORINGSSL_PREFIX %+ _RAND_load_file %xdefine RAND_poll BORINGSSL_PREFIX %+ _RAND_poll %xdefine RAND_pseudo_bytes BORINGSSL_PREFIX %+ _RAND_pseudo_bytes @@ -5170,6 +5176,7 @@ %xdefine SSL_CTX_get_max_proto_version BORINGSSL_PREFIX %+ _SSL_CTX_get_max_proto_version %xdefine SSL_CTX_get_min_proto_version BORINGSSL_PREFIX %+ _SSL_CTX_get_min_proto_version %xdefine SSL_CTX_get_mode BORINGSSL_PREFIX %+ _SSL_CTX_get_mode +%xdefine SSL_CTX_get_num_tickets BORINGSSL_PREFIX %+ _SSL_CTX_get_num_tickets %xdefine SSL_CTX_get_options BORINGSSL_PREFIX %+ _SSL_CTX_get_options %xdefine SSL_CTX_get_quiet_shutdown BORINGSSL_PREFIX %+ _SSL_CTX_get_quiet_shutdown %xdefine SSL_CTX_get_read_ahead BORINGSSL_PREFIX %+ _SSL_CTX_get_read_ahead @@ -5652,7 +5659,6 @@ %xdefine USERNOTICE_free BORINGSSL_PREFIX %+ _USERNOTICE_free %xdefine USERNOTICE_it BORINGSSL_PREFIX %+ _USERNOTICE_it %xdefine USERNOTICE_new BORINGSSL_PREFIX %+ _USERNOTICE_new -%xdefine UTF8_getc BORINGSSL_PREFIX %+ _UTF8_getc %xdefine UTF8_putc BORINGSSL_PREFIX %+ _UTF8_putc %xdefine X25519 BORINGSSL_PREFIX %+ _X25519 %xdefine X25519_keypair BORINGSSL_PREFIX %+ _X25519_keypair @@ -5695,7 +5701,6 @@ %xdefine X509V3_set_ctx BORINGSSL_PREFIX %+ _X509V3_set_ctx %xdefine X509V3_set_nconf BORINGSSL_PREFIX %+ _X509V3_set_nconf %xdefine X509V3_string_free BORINGSSL_PREFIX %+ _X509V3_string_free -%xdefine X509_ALGORS_it BORINGSSL_PREFIX %+ _X509_ALGORS_it %xdefine X509_ALGOR_cmp BORINGSSL_PREFIX %+ _X509_ALGOR_cmp %xdefine X509_ALGOR_dup BORINGSSL_PREFIX %+ _X509_ALGOR_dup %xdefine X509_ALGOR_free BORINGSSL_PREFIX %+ _X509_ALGOR_free @@ -5731,7 +5736,6 @@ %xdefine X509_CRL_add0_revoked BORINGSSL_PREFIX %+ _X509_CRL_add0_revoked %xdefine X509_CRL_add1_ext_i2d BORINGSSL_PREFIX %+ _X509_CRL_add1_ext_i2d %xdefine X509_CRL_add_ext BORINGSSL_PREFIX %+ _X509_CRL_add_ext -%xdefine X509_CRL_check_suiteb BORINGSSL_PREFIX %+ _X509_CRL_check_suiteb %xdefine X509_CRL_cmp BORINGSSL_PREFIX %+ _X509_CRL_cmp %xdefine X509_CRL_delete_ext BORINGSSL_PREFIX %+ _X509_CRL_delete_ext %xdefine X509_CRL_diff BORINGSSL_PREFIX %+ _X509_CRL_diff @@ -5936,7 +5940,6 @@ %xdefine X509_STORE_CTX_get0_current_issuer BORINGSSL_PREFIX %+ _X509_STORE_CTX_get0_current_issuer %xdefine X509_STORE_CTX_get0_param BORINGSSL_PREFIX %+ _X509_STORE_CTX_get0_param %xdefine X509_STORE_CTX_get0_parent_ctx BORINGSSL_PREFIX %+ _X509_STORE_CTX_get0_parent_ctx -%xdefine X509_STORE_CTX_get0_policy_tree BORINGSSL_PREFIX %+ _X509_STORE_CTX_get0_policy_tree %xdefine X509_STORE_CTX_get0_store BORINGSSL_PREFIX %+ _X509_STORE_CTX_get0_store %xdefine X509_STORE_CTX_get0_untrusted BORINGSSL_PREFIX %+ _X509_STORE_CTX_get0_untrusted %xdefine X509_STORE_CTX_get1_chain BORINGSSL_PREFIX %+ _X509_STORE_CTX_get1_chain @@ -5947,12 +5950,12 @@ %xdefine X509_STORE_CTX_get_error_depth BORINGSSL_PREFIX %+ _X509_STORE_CTX_get_error_depth %xdefine X509_STORE_CTX_get_ex_data BORINGSSL_PREFIX %+ _X509_STORE_CTX_get_ex_data %xdefine X509_STORE_CTX_get_ex_new_index BORINGSSL_PREFIX %+ _X509_STORE_CTX_get_ex_new_index -%xdefine X509_STORE_CTX_get_explicit_policy BORINGSSL_PREFIX %+ _X509_STORE_CTX_get_explicit_policy %xdefine X509_STORE_CTX_init BORINGSSL_PREFIX %+ _X509_STORE_CTX_init %xdefine X509_STORE_CTX_new BORINGSSL_PREFIX %+ _X509_STORE_CTX_new %xdefine X509_STORE_CTX_purpose_inherit BORINGSSL_PREFIX %+ _X509_STORE_CTX_purpose_inherit %xdefine X509_STORE_CTX_set0_crls BORINGSSL_PREFIX %+ _X509_STORE_CTX_set0_crls %xdefine X509_STORE_CTX_set0_param BORINGSSL_PREFIX %+ _X509_STORE_CTX_set0_param +%xdefine X509_STORE_CTX_set0_trusted_stack BORINGSSL_PREFIX %+ _X509_STORE_CTX_set0_trusted_stack %xdefine X509_STORE_CTX_set_cert BORINGSSL_PREFIX %+ _X509_STORE_CTX_set_cert %xdefine X509_STORE_CTX_set_chain BORINGSSL_PREFIX %+ _X509_STORE_CTX_set_chain %xdefine X509_STORE_CTX_set_default BORINGSSL_PREFIX %+ _X509_STORE_CTX_set_default @@ -6052,7 +6055,6 @@ %xdefine X509_add_ext BORINGSSL_PREFIX %+ _X509_add_ext %xdefine X509_alias_get0 BORINGSSL_PREFIX %+ _X509_alias_get0 %xdefine X509_alias_set1 BORINGSSL_PREFIX %+ _X509_alias_set1 -%xdefine X509_chain_check_suiteb BORINGSSL_PREFIX %+ _X509_chain_check_suiteb %xdefine X509_chain_up_ref BORINGSSL_PREFIX %+ _X509_chain_up_ref %xdefine X509_check_akid BORINGSSL_PREFIX %+ _X509_check_akid %xdefine X509_check_ca BORINGSSL_PREFIX %+ _X509_check_ca @@ -6129,19 +6131,9 @@ %xdefine X509_load_cert_file BORINGSSL_PREFIX %+ _X509_load_cert_file %xdefine X509_load_crl_file BORINGSSL_PREFIX %+ _X509_load_crl_file %xdefine X509_new BORINGSSL_PREFIX %+ _X509_new -%xdefine X509_ocspid_print BORINGSSL_PREFIX %+ _X509_ocspid_print %xdefine X509_parse_from_buffer BORINGSSL_PREFIX %+ _X509_parse_from_buffer %xdefine X509_policy_check BORINGSSL_PREFIX %+ _X509_policy_check -%xdefine X509_policy_level_get0_node BORINGSSL_PREFIX %+ _X509_policy_level_get0_node -%xdefine X509_policy_level_node_count BORINGSSL_PREFIX %+ _X509_policy_level_node_count -%xdefine X509_policy_node_get0_parent BORINGSSL_PREFIX %+ _X509_policy_node_get0_parent -%xdefine X509_policy_node_get0_policy BORINGSSL_PREFIX %+ _X509_policy_node_get0_policy -%xdefine X509_policy_node_get0_qualifiers BORINGSSL_PREFIX %+ _X509_policy_node_get0_qualifiers %xdefine X509_policy_tree_free BORINGSSL_PREFIX %+ _X509_policy_tree_free -%xdefine X509_policy_tree_get0_level BORINGSSL_PREFIX %+ _X509_policy_tree_get0_level -%xdefine X509_policy_tree_get0_policies BORINGSSL_PREFIX %+ _X509_policy_tree_get0_policies -%xdefine X509_policy_tree_get0_user_policies BORINGSSL_PREFIX %+ _X509_policy_tree_get0_user_policies -%xdefine X509_policy_tree_level_count BORINGSSL_PREFIX %+ _X509_policy_tree_level_count %xdefine X509_print BORINGSSL_PREFIX %+ _X509_print %xdefine X509_print_ex BORINGSSL_PREFIX %+ _X509_print_ex %xdefine X509_print_ex_fp BORINGSSL_PREFIX %+ _X509_print_ex_fp @@ -6440,7 +6432,6 @@ %xdefine d2i_USERNOTICE BORINGSSL_PREFIX %+ _d2i_USERNOTICE %xdefine d2i_X509 BORINGSSL_PREFIX %+ _d2i_X509 %xdefine d2i_X509_ALGOR BORINGSSL_PREFIX %+ _d2i_X509_ALGOR -%xdefine d2i_X509_ALGORS BORINGSSL_PREFIX %+ _d2i_X509_ALGORS %xdefine d2i_X509_ATTRIBUTE BORINGSSL_PREFIX %+ _d2i_X509_ATTRIBUTE %xdefine d2i_X509_AUX BORINGSSL_PREFIX %+ _d2i_X509_AUX %xdefine d2i_X509_CERT_AUX BORINGSSL_PREFIX %+ _d2i_X509_CERT_AUX @@ -6556,7 +6547,6 @@ %xdefine ecdsa_sign_with_nonce_for_known_answer_test BORINGSSL_PREFIX %+ _ecdsa_sign_with_nonce_for_known_answer_test %xdefine ecp_nistz256_avx2_select_w7 BORINGSSL_PREFIX %+ _ecp_nistz256_avx2_select_w7 %xdefine ecp_nistz256_div_by_2 BORINGSSL_PREFIX %+ _ecp_nistz256_div_by_2 -%xdefine ecp_nistz256_from_mont BORINGSSL_PREFIX %+ _ecp_nistz256_from_mont %xdefine ecp_nistz256_mul_by_2 BORINGSSL_PREFIX %+ _ecp_nistz256_mul_by_2 %xdefine ecp_nistz256_mul_by_3 BORINGSSL_PREFIX %+ _ecp_nistz256_mul_by_3 %xdefine ecp_nistz256_mul_mont BORINGSSL_PREFIX %+ _ecp_nistz256_mul_mont @@ -6570,7 +6560,6 @@ %xdefine ecp_nistz256_select_w7 BORINGSSL_PREFIX %+ _ecp_nistz256_select_w7 %xdefine ecp_nistz256_sqr_mont BORINGSSL_PREFIX %+ _ecp_nistz256_sqr_mont %xdefine ecp_nistz256_sub BORINGSSL_PREFIX %+ _ecp_nistz256_sub -%xdefine ecp_nistz256_to_mont BORINGSSL_PREFIX %+ _ecp_nistz256_to_mont %xdefine ed25519_asn1_meth BORINGSSL_PREFIX %+ _ed25519_asn1_meth %xdefine ed25519_pkey_meth BORINGSSL_PREFIX %+ _ed25519_pkey_meth %xdefine gcm_ghash_avx BORINGSSL_PREFIX %+ _gcm_ghash_avx @@ -6701,7 +6690,6 @@ %xdefine i2d_USERNOTICE BORINGSSL_PREFIX %+ _i2d_USERNOTICE %xdefine i2d_X509 BORINGSSL_PREFIX %+ _i2d_X509 %xdefine i2d_X509_ALGOR BORINGSSL_PREFIX %+ _i2d_X509_ALGOR -%xdefine i2d_X509_ALGORS BORINGSSL_PREFIX %+ _i2d_X509_ALGORS %xdefine i2d_X509_ATTRIBUTE BORINGSSL_PREFIX %+ _i2d_X509_ATTRIBUTE %xdefine i2d_X509_AUX BORINGSSL_PREFIX %+ _i2d_X509_AUX %xdefine i2d_X509_CERT_AUX BORINGSSL_PREFIX %+ _i2d_X509_CERT_AUX diff --git a/Sources/CNIOBoringSSL/ssl/d1_pkt.cc b/Sources/CNIOBoringSSL/ssl/d1_pkt.cc index 8a97ecdb..a3e871b4 100644 --- a/Sources/CNIOBoringSSL/ssl/d1_pkt.cc +++ b/Sources/CNIOBoringSSL/ssl/d1_pkt.cc @@ -186,8 +186,8 @@ ssl_open_record_t dtls1_open_app_data(SSL *ssl, Span *out, return ssl_open_record_success; } -int dtls1_write_app_data(SSL *ssl, bool *out_needs_handshake, const uint8_t *in, - int len) { +int dtls1_write_app_data(SSL *ssl, bool *out_needs_handshake, + size_t *out_bytes_written, Span in) { assert(!SSL_in_init(ssl)); *out_needs_handshake = false; @@ -196,47 +196,46 @@ int dtls1_write_app_data(SSL *ssl, bool *out_needs_handshake, const uint8_t *in, return -1; } - if (len > SSL3_RT_MAX_PLAIN_LENGTH) { + // DTLS does not split the input across records. + if (in.size() > SSL3_RT_MAX_PLAIN_LENGTH) { OPENSSL_PUT_ERROR(SSL, SSL_R_DTLS_MESSAGE_TOO_BIG); return -1; } - if (len < 0) { - OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_LENGTH); - return -1; + if (in.empty()) { + *out_bytes_written = 0; + return 1; } - if (len == 0) { - return 0; - } - - int ret = dtls1_write_record(ssl, SSL3_RT_APPLICATION_DATA, in, (size_t)len, + int ret = dtls1_write_record(ssl, SSL3_RT_APPLICATION_DATA, in, dtls1_use_current_epoch); if (ret <= 0) { return ret; } - return len; + *out_bytes_written = in.size(); + return 1; } -int dtls1_write_record(SSL *ssl, int type, const uint8_t *in, size_t len, +int dtls1_write_record(SSL *ssl, int type, Span in, enum dtls1_use_epoch_t use_epoch) { SSLBuffer *buf = &ssl->s3->write_buffer; - assert(len <= SSL3_RT_MAX_PLAIN_LENGTH); + assert(in.size() <= SSL3_RT_MAX_PLAIN_LENGTH); // There should never be a pending write buffer in DTLS. One can't write half // a datagram, so the write buffer is always dropped in // |ssl_write_buffer_flush|. assert(buf->empty()); - if (len > SSL3_RT_MAX_PLAIN_LENGTH) { + if (in.size() > SSL3_RT_MAX_PLAIN_LENGTH) { OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR); return -1; } size_t ciphertext_len; if (!buf->EnsureCap(ssl_seal_align_prefix_len(ssl), - len + SSL_max_seal_overhead(ssl)) || + in.size() + SSL_max_seal_overhead(ssl)) || !dtls_seal_record(ssl, buf->remaining().data(), &ciphertext_len, - buf->remaining().size(), type, in, len, use_epoch)) { + buf->remaining().size(), type, in.data(), in.size(), + use_epoch)) { buf->Clear(); return -1; } @@ -250,7 +249,7 @@ int dtls1_write_record(SSL *ssl, int type, const uint8_t *in, size_t len, } int dtls1_dispatch_alert(SSL *ssl) { - int ret = dtls1_write_record(ssl, SSL3_RT_ALERT, &ssl->s3->send_alert[0], 2, + int ret = dtls1_write_record(ssl, SSL3_RT_ALERT, ssl->s3->send_alert, dtls1_use_current_epoch); if (ret <= 0) { return ret; diff --git a/Sources/CNIOBoringSSL/ssl/extensions.cc b/Sources/CNIOBoringSSL/ssl/extensions.cc index 45bc70e9..cf7e2d59 100644 --- a/Sources/CNIOBoringSSL/ssl/extensions.cc +++ b/Sources/CNIOBoringSSL/ssl/extensions.cc @@ -3976,6 +3976,16 @@ enum ssl_ticket_aead_result_t ssl_process_ticket( : ssl_ticket_aead_error; } else if (is_psk && hints && !hs->hints_requested && hints->ignore_psk) { result = ssl_ticket_aead_ignore_ticket; + } else if (!is_psk && hints && !hs->hints_requested && + !hints->decrypted_ticket.empty()) { + if (plaintext.CopyFrom(hints->decrypted_ticket)) { + result = ssl_ticket_aead_success; + *out_renew_ticket = hints->renew_ticket; + } else { + result = ssl_ticket_aead_error; + } + } else if (!is_psk && hints && !hs->hints_requested && hints->ignore_ticket) { + result = ssl_ticket_aead_ignore_ticket; } else if (ssl->session_ctx->ticket_aead_method != NULL) { result = ssl_decrypt_ticket_with_method(hs, &plaintext, out_renew_ticket, ticket); @@ -3994,12 +4004,24 @@ enum ssl_ticket_aead_result_t ssl_process_ticket( } } - if (is_psk && hints && hs->hints_requested) { + if (hints && hs->hints_requested) { if (result == ssl_ticket_aead_ignore_ticket) { - hints->ignore_psk = true; - } else if (result == ssl_ticket_aead_success && - !hints->decrypted_psk.CopyFrom(plaintext)) { - return ssl_ticket_aead_error; + if (is_psk) { + hints->ignore_psk = true; + } else { + hints->ignore_ticket = true; + } + } else if (result == ssl_ticket_aead_success) { + if (is_psk) { + if (!hints->decrypted_psk.CopyFrom(plaintext)) { + return ssl_ticket_aead_error; + } + } else { + if (!hints->decrypted_ticket.CopyFrom(plaintext)) { + return ssl_ticket_aead_error; + } + hints->renew_ticket = *out_renew_ticket; + } } } diff --git a/Sources/CNIOBoringSSL/ssl/handoff.cc b/Sources/CNIOBoringSSL/ssl/handoff.cc index f7d62bfe..9b9650c4 100644 --- a/Sources/CNIOBoringSSL/ssl/handoff.cc +++ b/Sources/CNIOBoringSSL/ssl/handoff.cc @@ -769,16 +769,27 @@ int SSL_request_handshake_hints(SSL *ssl, const uint8_t *client_hello, // implicit tagging to make it a little more compact. // // HandshakeHints ::= SEQUENCE { -// serverRandom [0] IMPLICIT OCTET STRING OPTIONAL, +// serverRandomTLS13 [0] IMPLICIT OCTET STRING OPTIONAL, // keyShareHint [1] IMPLICIT KeyShareHint OPTIONAL, // signatureHint [2] IMPLICIT SignatureHint OPTIONAL, // -- At most one of decryptedPSKHint or ignorePSKHint may be present. It // -- corresponds to the first entry in pre_shared_keys. TLS 1.2 session -// -- tickets will use a separate hint, to ensure the caller does not mix -// -- them up. +// -- tickets use a separate hint, to ensure the caller does not apply the +// -- hint to the wrong field. // decryptedPSKHint [3] IMPLICIT OCTET STRING OPTIONAL, // ignorePSKHint [4] IMPLICIT NULL OPTIONAL, // compressCertificateHint [5] IMPLICIT CompressCertificateHint OPTIONAL, +// -- TLS 1.2 and 1.3 use different server random hints because one contains +// -- a timestamp while the other doesn't. If the hint was generated +// -- assuming TLS 1.3 but we actually negotiate TLS 1.2, mixing the two +// -- will break this. +// serverRandomTLS12 [6] IMPLICIT OCTET STRING OPTIONAL, +// ecdheHint [7] IMPLICIT ECDHEHint OPTIONAL +// -- At most one of decryptedTicketHint or ignoreTicketHint may be present. +// -- renewTicketHint requires decryptedTicketHint. +// decryptedTicketHint [8] IMPLICIT OCTET STRING OPTIONAL, +// renewTicketHint [9] IMPLICIT NULL OPTIONAL, +// ignoreTicketHint [10] IMPLICIT NULL OPTIONAL, // } // // KeyShareHint ::= SEQUENCE { @@ -799,9 +810,15 @@ int SSL_request_handshake_hints(SSL *ssl, const uint8_t *client_hello, // input OCTET STRING, // compressed OCTET STRING, // } +// +// ECDHEHint ::= SEQUENCE { +// groupId INTEGER, +// publicKey OCTET STRING, +// privateKey OCTET STRING, +// } // HandshakeHints tags. -static const unsigned kServerRandomTag = CBS_ASN1_CONTEXT_SPECIFIC | 0; +static const unsigned kServerRandomTLS13Tag = CBS_ASN1_CONTEXT_SPECIFIC | 0; static const unsigned kKeyShareHintTag = CBS_ASN1_CONSTRUCTED | CBS_ASN1_CONTEXT_SPECIFIC | 1; static const unsigned kSignatureHintTag = @@ -809,6 +826,11 @@ static const unsigned kSignatureHintTag = static const unsigned kDecryptedPSKTag = CBS_ASN1_CONTEXT_SPECIFIC | 3; static const unsigned kIgnorePSKTag = CBS_ASN1_CONTEXT_SPECIFIC | 4; static const unsigned kCompressCertificateTag = CBS_ASN1_CONTEXT_SPECIFIC | 5; +static const unsigned kServerRandomTLS12Tag = CBS_ASN1_CONTEXT_SPECIFIC | 6; +static const unsigned kECDHEHintTag = CBS_ASN1_CONSTRUCTED | 7; +static const unsigned kDecryptedTicketTag = CBS_ASN1_CONTEXT_SPECIFIC | 8; +static const unsigned kRenewTicketTag = CBS_ASN1_CONTEXT_SPECIFIC | 9; +static const unsigned kIgnoreTicketTag = CBS_ASN1_CONTEXT_SPECIFIC | 10; int SSL_serialize_handshake_hints(const SSL *ssl, CBB *out) { const SSL_HANDSHAKE *hs = ssl->s3->hs.get(); @@ -823,10 +845,10 @@ int SSL_serialize_handshake_hints(const SSL *ssl, CBB *out) { return 0; } - if (!hints->server_random.empty()) { - if (!CBB_add_asn1(&seq, &child, kServerRandomTag) || - !CBB_add_bytes(&child, hints->server_random.data(), - hints->server_random.size())) { + if (!hints->server_random_tls13.empty()) { + if (!CBB_add_asn1(&seq, &child, kServerRandomTLS13Tag) || + !CBB_add_bytes(&child, hints->server_random_tls13.data(), + hints->server_random_tls13.size())) { return 0; } } @@ -884,9 +906,60 @@ int SSL_serialize_handshake_hints(const SSL *ssl, CBB *out) { } } + if (!hints->server_random_tls12.empty()) { + if (!CBB_add_asn1(&seq, &child, kServerRandomTLS12Tag) || + !CBB_add_bytes(&child, hints->server_random_tls12.data(), + hints->server_random_tls12.size())) { + return 0; + } + } + + if (hints->ecdhe_group_id != 0 && !hints->ecdhe_public_key.empty() && + !hints->ecdhe_private_key.empty()) { + if (!CBB_add_asn1(&seq, &child, kECDHEHintTag) || + !CBB_add_asn1_uint64(&child, hints->ecdhe_group_id) || + !CBB_add_asn1_octet_string(&child, hints->ecdhe_public_key.data(), + hints->ecdhe_public_key.size()) || + !CBB_add_asn1_octet_string(&child, hints->ecdhe_private_key.data(), + hints->ecdhe_private_key.size())) { + return 0; + } + } + + + if (!hints->decrypted_ticket.empty()) { + if (!CBB_add_asn1(&seq, &child, kDecryptedTicketTag) || + !CBB_add_bytes(&child, hints->decrypted_ticket.data(), + hints->decrypted_ticket.size())) { + return 0; + } + } + + if (hints->renew_ticket && // + !CBB_add_asn1(&seq, &child, kRenewTicketTag)) { + return 0; + } + + if (hints->ignore_ticket && // + !CBB_add_asn1(&seq, &child, kIgnoreTicketTag)) { + return 0; + } + return CBB_flush(out); } +static bool get_optional_implicit_null(CBS *cbs, bool *out_present, + unsigned tag) { + CBS value; + int present; + if (!CBS_get_optional_asn1(cbs, &value, &present, tag) || + (present && CBS_len(&value) != 0)) { + return false; + } + *out_present = present; + return true; +} + int SSL_set_handshake_hints(SSL *ssl, const uint8_t *hints, size_t hints_len) { if (SSL_is_dtls(ssl)) { OPENSSL_PUT_ERROR(SSL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); @@ -898,28 +971,37 @@ int SSL_set_handshake_hints(SSL *ssl, const uint8_t *hints, size_t hints_len) { return 0; } - CBS cbs, seq, server_random, key_share, signature_hint, ticket, ignore_psk, - cert_compression; - int has_server_random, has_key_share, has_signature_hint, has_ticket, - has_ignore_psk, has_cert_compression; + CBS cbs, seq, server_random_tls13, key_share, signature_hint, psk, + cert_compression, server_random_tls12, ecdhe, ticket; + int has_server_random_tls13, has_key_share, has_signature_hint, has_psk, + has_cert_compression, has_server_random_tls12, has_ecdhe, has_ticket; CBS_init(&cbs, hints, hints_len); if (!CBS_get_asn1(&cbs, &seq, CBS_ASN1_SEQUENCE) || - !CBS_get_optional_asn1(&seq, &server_random, &has_server_random, - kServerRandomTag) || + !CBS_get_optional_asn1(&seq, &server_random_tls13, + &has_server_random_tls13, kServerRandomTLS13Tag) || !CBS_get_optional_asn1(&seq, &key_share, &has_key_share, kKeyShareHintTag) || !CBS_get_optional_asn1(&seq, &signature_hint, &has_signature_hint, kSignatureHintTag) || - !CBS_get_optional_asn1(&seq, &ticket, &has_ticket, kDecryptedPSKTag) || - !CBS_get_optional_asn1(&seq, &ignore_psk, &has_ignore_psk, - kIgnorePSKTag) || + !CBS_get_optional_asn1(&seq, &psk, &has_psk, kDecryptedPSKTag) || + !get_optional_implicit_null(&seq, &hints_obj->ignore_psk, + kIgnorePSKTag) || !CBS_get_optional_asn1(&seq, &cert_compression, &has_cert_compression, - kCompressCertificateTag)) { + kCompressCertificateTag) || + !CBS_get_optional_asn1(&seq, &server_random_tls12, + &has_server_random_tls12, kServerRandomTLS12Tag) || + !CBS_get_optional_asn1(&seq, &ecdhe, &has_ecdhe, kECDHEHintTag) || + !CBS_get_optional_asn1(&seq, &ticket, &has_ticket, kDecryptedTicketTag) || + !get_optional_implicit_null(&seq, &hints_obj->renew_ticket, + kRenewTicketTag) || + !get_optional_implicit_null(&seq, &hints_obj->ignore_ticket, + kIgnoreTicketTag)) { OPENSSL_PUT_ERROR(SSL, SSL_R_COULD_NOT_PARSE_HINTS); return 0; } - if (has_server_random && !hints_obj->server_random.CopyFrom(server_random)) { + if (has_server_random_tls13 && + !hints_obj->server_random_tls13.CopyFrom(server_random_tls13)) { return 0; } @@ -955,15 +1037,12 @@ int SSL_set_handshake_hints(SSL *ssl, const uint8_t *hints, size_t hints_len) { hints_obj->signature_algorithm = static_cast(sig_alg); } - if (has_ticket && !hints_obj->decrypted_psk.CopyFrom(ticket)) { + if (has_psk && !hints_obj->decrypted_psk.CopyFrom(psk)) { return 0; } - - if (has_ignore_psk) { - if (CBS_len(&ignore_psk) != 0) { - return 0; - } - hints_obj->ignore_psk = true; + if (has_psk && hints_obj->ignore_psk) { + OPENSSL_PUT_ERROR(SSL, SSL_R_COULD_NOT_PARSE_HINTS); + return 0; } if (has_cert_compression) { @@ -981,6 +1060,38 @@ int SSL_set_handshake_hints(SSL *ssl, const uint8_t *hints, size_t hints_len) { hints_obj->cert_compression_alg_id = static_cast(alg); } + if (has_server_random_tls12 && + !hints_obj->server_random_tls12.CopyFrom(server_random_tls12)) { + return 0; + } + + if (has_ecdhe) { + uint64_t group_id; + CBS public_key, private_key; + if (!CBS_get_asn1_uint64(&ecdhe, &group_id) || // + group_id == 0 || group_id > 0xffff || + !CBS_get_asn1(&ecdhe, &public_key, CBS_ASN1_OCTETSTRING) || + !hints_obj->ecdhe_public_key.CopyFrom(public_key) || + !CBS_get_asn1(&ecdhe, &private_key, CBS_ASN1_OCTETSTRING) || + !hints_obj->ecdhe_private_key.CopyFrom(private_key)) { + OPENSSL_PUT_ERROR(SSL, SSL_R_COULD_NOT_PARSE_HINTS); + return 0; + } + hints_obj->ecdhe_group_id = static_cast(group_id); + } + + if (has_ticket && !hints_obj->decrypted_ticket.CopyFrom(ticket)) { + return 0; + } + if (has_ticket && hints_obj->ignore_ticket) { + OPENSSL_PUT_ERROR(SSL, SSL_R_COULD_NOT_PARSE_HINTS); + return 0; + } + if (!has_ticket && hints_obj->renew_ticket) { + OPENSSL_PUT_ERROR(SSL, SSL_R_COULD_NOT_PARSE_HINTS); + return 0; + } + ssl->s3->hs->hints = std::move(hints_obj); return 1; } diff --git a/Sources/CNIOBoringSSL/ssl/handshake_client.cc b/Sources/CNIOBoringSSL/ssl/handshake_client.cc index 3b0572ec..b5f3511b 100644 --- a/Sources/CNIOBoringSSL/ssl/handshake_client.cc +++ b/Sources/CNIOBoringSSL/ssl/handshake_client.cc @@ -236,21 +236,21 @@ static bool ssl_write_client_cipher_list(const SSL_HANDSHAKE *hs, CBB *out, // hardware support. if (hs->max_version >= TLS1_3_VERSION) { const bool include_chacha20 = ssl_tls13_cipher_meets_policy( - TLS1_CK_CHACHA20_POLY1305_SHA256 & 0xffff, + TLS1_3_CK_CHACHA20_POLY1305_SHA256 & 0xffff, ssl->config->only_fips_cipher_suites_in_tls13); if (!EVP_has_aes_hardware() && // include_chacha20 && // - !CBB_add_u16(&child, TLS1_CK_CHACHA20_POLY1305_SHA256 & 0xffff)) { + !CBB_add_u16(&child, TLS1_3_CK_CHACHA20_POLY1305_SHA256 & 0xffff)) { return false; } - if (!CBB_add_u16(&child, TLS1_CK_AES_128_GCM_SHA256 & 0xffff) || - !CBB_add_u16(&child, TLS1_CK_AES_256_GCM_SHA384 & 0xffff)) { + if (!CBB_add_u16(&child, TLS1_3_CK_AES_128_GCM_SHA256 & 0xffff) || + !CBB_add_u16(&child, TLS1_3_CK_AES_256_GCM_SHA384 & 0xffff)) { return false; } if (EVP_has_aes_hardware() && // include_chacha20 && // - !CBB_add_u16(&child, TLS1_CK_CHACHA20_POLY1305_SHA256 & 0xffff)) { + !CBB_add_u16(&child, TLS1_3_CK_CHACHA20_POLY1305_SHA256 & 0xffff)) { return false; } } diff --git a/Sources/CNIOBoringSSL/ssl/handshake_server.cc b/Sources/CNIOBoringSSL/ssl/handshake_server.cc index 365e89d2..3eb65916 100644 --- a/Sources/CNIOBoringSSL/ssl/handshake_server.cc +++ b/Sources/CNIOBoringSSL/ssl/handshake_server.cc @@ -411,7 +411,7 @@ static bool is_probably_jdk11_with_tls13(const SSL_CLIENT_HELLO *client_hello) { // JDK 11 does not support ChaCha20-Poly1305. This is unusual: many modern // clients implement ChaCha20-Poly1305. if (ssl_client_cipher_list_contains_cipher( - client_hello, TLS1_CK_CHACHA20_POLY1305_SHA256 & 0xffff)) { + client_hello, TLS1_3_CK_CHACHA20_POLY1305_SHA256 & 0xffff)) { return false; } @@ -801,12 +801,6 @@ static enum ssl_hs_wait_t do_select_certificate(SSL_HANDSHAKE *hs) { // or below. assert(ssl->s3->ech_status != ssl_ech_accepted); - // TODO(davidben): Also compute hints for TLS 1.2. When doing so, update the - // check in bssl_shim.cc to test this. - if (hs->hints_requested) { - return ssl_hs_hints_ready; - } - ssl->s3->early_data_reason = ssl_early_data_protocol_version; SSLMessage msg_unused; @@ -988,14 +982,23 @@ static enum ssl_hs_wait_t do_send_server_hello(SSL_HANDSHAKE *hs) { hs->channel_id_negotiated = false; } - struct OPENSSL_timeval now; - ssl_get_current_time(ssl, &now); - ssl->s3->server_random[0] = now.tv_sec >> 24; - ssl->s3->server_random[1] = now.tv_sec >> 16; - ssl->s3->server_random[2] = now.tv_sec >> 8; - ssl->s3->server_random[3] = now.tv_sec; - if (!RAND_bytes(ssl->s3->server_random + 4, SSL3_RANDOM_SIZE - 4)) { - return ssl_hs_error; + SSL_HANDSHAKE_HINTS *const hints = hs->hints.get(); + if (hints && !hs->hints_requested && + hints->server_random_tls12.size() == SSL3_RANDOM_SIZE) { + OPENSSL_memcpy(ssl->s3->server_random, hints->server_random_tls12.data(), + SSL3_RANDOM_SIZE); + } else { + struct OPENSSL_timeval now; + ssl_get_current_time(ssl, &now); + CRYPTO_store_u32_be(ssl->s3->server_random, + static_cast(now.tv_sec)); + if (!RAND_bytes(ssl->s3->server_random + 4, SSL3_RANDOM_SIZE - 4)) { + return ssl_hs_error; + } + if (hints && hs->hints_requested && + !hints->server_random_tls12.CopyFrom(ssl->s3->server_random)) { + return ssl_hs_error; + } } // Implement the TLS 1.3 anti-downgrade feature. @@ -1040,7 +1043,11 @@ static enum ssl_hs_wait_t do_send_server_hello(SSL_HANDSHAKE *hs) { return ssl_hs_error; } - if (ssl->session != NULL) { + if (ssl->session != nullptr) { + // No additional hints to generate in resumption. + if (hs->hints_requested) { + return ssl_hs_hints_ready; + } hs->state = state12_send_server_finished; } else { hs->state = state12_send_server_certificate; @@ -1113,18 +1120,51 @@ static enum ssl_hs_wait_t do_send_server_certificate(SSL_HANDSHAKE *hs) { OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR); ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_HANDSHAKE_FAILURE); return ssl_hs_error; - } + } hs->new_session->group_id = group_id; - // Set up ECDH, generate a key, and emit the public half. hs->key_shares[0] = SSLKeyShare::Create(group_id); if (!hs->key_shares[0] || !CBB_add_u8(cbb.get(), NAMED_CURVE_TYPE) || !CBB_add_u16(cbb.get(), group_id) || - !CBB_add_u8_length_prefixed(cbb.get(), &child) || - !hs->key_shares[0]->Offer(&child)) { + !CBB_add_u8_length_prefixed(cbb.get(), &child)) { return ssl_hs_error; } + + SSL_HANDSHAKE_HINTS *const hints = hs->hints.get(); + bool hint_ok = false; + if (hints && !hs->hints_requested && + hints->ecdhe_group_id == group_id && + !hints->ecdhe_public_key.empty() && + !hints->ecdhe_private_key.empty()) { + CBS cbs = MakeConstSpan(hints->ecdhe_private_key); + hint_ok = hs->key_shares[0]->DeserializePrivateKey(&cbs); + } + if (hint_ok) { + // Reuse the ECDH key from handshake hints. + if (!CBB_add_bytes(&child, hints->ecdhe_public_key.data(), + hints->ecdhe_public_key.size())) { + return ssl_hs_error; + } + } else { + // Generate a key, and emit the public half. + if (!hs->key_shares[0]->Offer(&child)) { + return ssl_hs_error; + } + // If generating hints, save the ECDHE key. + if (hints && hs->hints_requested) { + bssl::ScopedCBB private_key_cbb; + if (!hints->ecdhe_public_key.CopyFrom( + MakeConstSpan(CBB_data(&child), CBB_len(&child))) || + !CBB_init(private_key_cbb.get(), 32) || + !hs->key_shares[0]->SerializePrivateKey(private_key_cbb.get()) || + !CBBFinishArray(private_key_cbb.get(), + &hints->ecdhe_private_key)) { + return ssl_hs_error; + } + hints->ecdhe_group_id = group_id; + } + } } else { assert(alg_k & SSL_kPSK); } @@ -1214,6 +1254,9 @@ static enum ssl_hs_wait_t do_send_server_key_exchange(SSL_HANDSHAKE *hs) { static enum ssl_hs_wait_t do_send_server_hello_done(SSL_HANDSHAKE *hs) { SSL *const ssl = hs->ssl; + if (hs->hints_requested) { + return ssl_hs_hints_ready; + } ScopedCBB cbb; CBB body; diff --git a/Sources/CNIOBoringSSL/ssl/internal.h b/Sources/CNIOBoringSSL/ssl/internal.h index 72e5a89d..effdc4e1 100644 --- a/Sources/CNIOBoringSSL/ssl/internal.h +++ b/Sources/CNIOBoringSSL/ssl/internal.h @@ -1697,7 +1697,8 @@ enum handback_t { struct SSL_HANDSHAKE_HINTS { static constexpr bool kAllowUniquePtr = true; - Array server_random; + Array server_random_tls12; + Array server_random_tls13; uint16_t key_share_group_id = 0; Array key_share_public_key; @@ -1714,6 +1715,14 @@ struct SSL_HANDSHAKE_HINTS { uint16_t cert_compression_alg_id = 0; Array cert_compression_input; Array cert_compression_output; + + uint16_t ecdhe_group_id = 0; + Array ecdhe_public_key; + Array ecdhe_private_key; + + Array decrypted_ticket; + bool renew_ticket = false; + bool ignore_ticket = false; }; struct SSL_HANDSHAKE { @@ -2451,8 +2460,13 @@ struct SSL_PROTOCOL_METHOD { ssl_open_record_t (*open_app_data)(SSL *ssl, Span *out, size_t *out_consumed, uint8_t *out_alert, Span in); - int (*write_app_data)(SSL *ssl, bool *out_needs_handshake, const uint8_t *buf, - int len); + // write_app_data encrypts and writes |in| as application data. On success, it + // returns one and sets |*out_bytes_written| to the number of bytes of |in| + // written. Otherwise, it returns <= 0 and sets |*out_needs_handshake| to + // whether the operation failed because the caller needs to drive the + // handshake. + int (*write_app_data)(SSL *ssl, bool *out_needs_handshake, + size_t *out_bytes_written, Span in); int (*dispatch_alert)(SSL *ssl); // init_message begins a new handshake message of type |type|. |cbb| is the // root CBB to be passed into |finish_message|. |*body| is set to a child CBB @@ -2641,12 +2655,23 @@ struct SSL3_STATE { // |read_buffer|. Span pending_app_data; - // partial write - check the numbers match - unsigned int wnum = 0; // number of bytes sent so far - int wpend_tot = 0; // number bytes written - int wpend_type = 0; - int wpend_ret = 0; // number of bytes submitted - const uint8_t *wpend_buf = nullptr; + // unreported_bytes_written is the number of bytes successfully written to the + // transport, but not yet reported to the caller. The next |SSL_write| will + // skip this many bytes from the input. This is used if + // |SSL_MODE_ENABLE_PARTIAL_WRITE| is disabled, in which case |SSL_write| only + // reports bytes written when the full caller input is written. + size_t unreported_bytes_written = 0; + + // pending_write, if |has_pending_write| is true, is the caller-supplied data + // corresponding to the current pending write. This is used to check the + // caller retried with a compatible buffer. + Span pending_write; + + // pending_write_type, if |has_pending_write| is true, is the record type + // for the current pending write. + // + // TODO(davidben): Remove this when alerts are moved out of this write path. + uint8_t pending_write_type = 0; // read_shutdown is the shutdown state for the read half of the connection. enum ssl_shutdown_t read_shutdown = ssl_shutdown_none; @@ -2726,9 +2751,6 @@ struct SSL3_STATE { // outstanding. bool key_update_pending : 1; - // wpend_pending is true if we have a pending write outstanding. - bool wpend_pending : 1; - // early_data_accepted is true if early data was accepted by the server. bool early_data_accepted : 1; @@ -3213,8 +3235,8 @@ ssl_open_record_t tls_open_app_data(SSL *ssl, Span *out, ssl_open_record_t tls_open_change_cipher_spec(SSL *ssl, size_t *out_consumed, uint8_t *out_alert, Span in); -int tls_write_app_data(SSL *ssl, bool *out_needs_handshake, const uint8_t *buf, - int len); +int tls_write_app_data(SSL *ssl, bool *out_needs_handshake, + size_t *out_bytes_written, Span in); bool tls_new(SSL *ssl); void tls_free(SSL *ssl); @@ -3247,11 +3269,11 @@ ssl_open_record_t dtls1_open_change_cipher_spec(SSL *ssl, size_t *out_consumed, Span in); int dtls1_write_app_data(SSL *ssl, bool *out_needs_handshake, - const uint8_t *buf, int len); + size_t *out_bytes_written, Span in); // dtls1_write_record sends a record. It returns one on success and <= 0 on // error. -int dtls1_write_record(SSL *ssl, int type, const uint8_t *buf, size_t len, +int dtls1_write_record(SSL *ssl, int type, Span in, enum dtls1_use_epoch_t use_epoch); int dtls1_retransmit_outgoing_messages(SSL *ssl); diff --git a/Sources/CNIOBoringSSL/ssl/s3_both.cc b/Sources/CNIOBoringSSL/ssl/s3_both.cc index 71d68b14..2afb09bd 100644 --- a/Sources/CNIOBoringSSL/ssl/s3_both.cc +++ b/Sources/CNIOBoringSSL/ssl/s3_both.cc @@ -697,10 +697,10 @@ bool ssl_tls13_cipher_meets_policy(uint16_t cipher_id, bool only_fips) { } switch (cipher_id) { - case TLS1_CK_AES_128_GCM_SHA256 & 0xffff: - case TLS1_CK_AES_256_GCM_SHA384 & 0xffff: + case TLS1_3_CK_AES_128_GCM_SHA256 & 0xffff: + case TLS1_3_CK_AES_256_GCM_SHA384 & 0xffff: return true; - case TLS1_CK_CHACHA20_POLY1305_SHA256 & 0xffff: + case TLS1_3_CK_CHACHA20_POLY1305_SHA256 & 0xffff: return false; default: assert(false); diff --git a/Sources/CNIOBoringSSL/ssl/s3_lib.cc b/Sources/CNIOBoringSSL/ssl/s3_lib.cc index aff9fb49..9ef0b38f 100644 --- a/Sources/CNIOBoringSSL/ssl/s3_lib.cc +++ b/Sources/CNIOBoringSSL/ssl/s3_lib.cc @@ -175,7 +175,6 @@ SSL3_STATE::SSL3_STATE() send_connection_binding(false), channel_id_valid(false), key_update_pending(false), - wpend_pending(false), early_data_accepted(false), alert_dispatch(false), renegotiate_pending(false), diff --git a/Sources/CNIOBoringSSL/ssl/s3_pkt.cc b/Sources/CNIOBoringSSL/ssl/s3_pkt.cc index f3d63f18..b2f1c087 100644 --- a/Sources/CNIOBoringSSL/ssl/s3_pkt.cc +++ b/Sources/CNIOBoringSSL/ssl/s3_pkt.cc @@ -126,10 +126,11 @@ BSSL_NAMESPACE_BEGIN -static int do_tls_write(SSL *ssl, int type, const uint8_t *in, unsigned len); +static int do_tls_write(SSL *ssl, size_t *out_bytes_written, uint8_t type, + Span in); -int tls_write_app_data(SSL *ssl, bool *out_needs_handshake, const uint8_t *in, - int len) { +int tls_write_app_data(SSL *ssl, bool *out_needs_handshake, + size_t *out_bytes_written, Span in) { assert(ssl_can_write(ssl)); assert(!ssl->s3->aead_write_ctx->is_null_cipher()); @@ -140,33 +141,28 @@ int tls_write_app_data(SSL *ssl, bool *out_needs_handshake, const uint8_t *in, return -1; } - // TODO(davidben): Switch this logic to |size_t| and |bssl::Span|. - assert(ssl->s3->wnum <= INT_MAX); - unsigned tot = ssl->s3->wnum; - ssl->s3->wnum = 0; - - // Ensure that if we end up with a smaller value of data to write out than - // the the original len from a write which didn't complete for non-blocking - // I/O and also somehow ended up avoiding the check for this in - // tls_write_pending/SSL_R_BAD_WRITE_RETRY as it must never be possible to - // end up with (len-tot) as a large number that will then promptly send - // beyond the end of the users buffer ... so we trap and report the error in - // a way the user will notice. - if (len < 0 || (size_t)len < tot) { + size_t total_bytes_written = ssl->s3->unreported_bytes_written; + if (in.size() < total_bytes_written) { + // This can happen if the caller disables |SSL_MODE_ENABLE_PARTIAL_WRITE|, + // asks us to write some input of length N, we successfully encrypt M bytes + // and write it, but fail to write the rest. We will report + // |SSL_ERROR_WANT_WRITE|. If the caller then retries with fewer than M + // bytes, we cannot satisfy that request. The caller is required to always + // retry with at least as many bytes as the previous attempt. OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_LENGTH); return -1; } - const int is_early_data_write = - !ssl->server && SSL_in_early_data(ssl) && ssl->s3->hs->can_early_write; + in = in.subspan(total_bytes_written); - unsigned n = len - tot; + const bool is_early_data_write = + !ssl->server && SSL_in_early_data(ssl) && ssl->s3->hs->can_early_write; for (;;) { size_t max_send_fragment = ssl->max_send_fragment; if (is_early_data_write) { SSL_HANDSHAKE *hs = ssl->s3->hs.get(); if (hs->early_data_written >= hs->early_session->ticket_max_early_data) { - ssl->s3->wnum = tot; + ssl->s3->unreported_bytes_written = total_bytes_written; hs->can_early_write = false; *out_needs_handshake = true; return -1; @@ -176,53 +172,63 @@ int tls_write_app_data(SSL *ssl, bool *out_needs_handshake, const uint8_t *in, hs->early_data_written}); } - const size_t nw = std::min(max_send_fragment, size_t{n}); - int ret = do_tls_write(ssl, SSL3_RT_APPLICATION_DATA, &in[tot], nw); + const size_t to_write = std::min(max_send_fragment, in.size()); + size_t bytes_written; + int ret = do_tls_write(ssl, &bytes_written, SSL3_RT_APPLICATION_DATA, + in.subspan(0, to_write)); if (ret <= 0) { - ssl->s3->wnum = tot; + ssl->s3->unreported_bytes_written = total_bytes_written; return ret; } + // Note |bytes_written| may be less than |to_write| if there was a pending + // record from a smaller write attempt. + assert(bytes_written <= to_write); + total_bytes_written += bytes_written; + in = in.subspan(bytes_written); if (is_early_data_write) { - ssl->s3->hs->early_data_written += ret; + ssl->s3->hs->early_data_written += bytes_written; } - if (ret == (int)n || (ssl->mode & SSL_MODE_ENABLE_PARTIAL_WRITE)) { - return tot + ret; + if (in.empty() || (ssl->mode & SSL_MODE_ENABLE_PARTIAL_WRITE)) { + ssl->s3->unreported_bytes_written = 0; + *out_bytes_written = total_bytes_written; + return 1; } - - n -= ret; - tot += ret; } } -static int tls_write_pending(SSL *ssl, int type, const uint8_t *in, - unsigned int len) { - if (ssl->s3->wpend_tot > (int)len || - (!(ssl->mode & SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER) && - ssl->s3->wpend_buf != in) || - ssl->s3->wpend_type != type) { +// do_tls_write writes an SSL record of the given type. On success, it sets +// |*out_bytes_written| to number of bytes successfully written and returns one. +// On error, it returns a value <= 0 from the underlying |BIO|. +static int do_tls_write(SSL *ssl, size_t *out_bytes_written, uint8_t type, + Span in) { + // If there is a pending write, the retry must be consistent. + if (!ssl->s3->pending_write.empty() && + (ssl->s3->pending_write.size() > in.size() || + (!(ssl->mode & SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER) && + ssl->s3->pending_write.data() != in.data()) || + ssl->s3->pending_write_type != type)) { OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_WRITE_RETRY); return -1; } + // Flush any unwritten data to the transport. There may be data to flush even + // if |wpend_tot| is zero. int ret = ssl_write_buffer_flush(ssl); if (ret <= 0) { return ret; } - ssl->s3->wpend_pending = false; - return ssl->s3->wpend_ret; -} -// do_tls_write writes an SSL record of the given type. -static int do_tls_write(SSL *ssl, int type, const uint8_t *in, unsigned len) { - // If there is still data from the previous record, flush it. - if (ssl->s3->wpend_pending) { - return tls_write_pending(ssl, type, in, len); + // If there is a pending write, we just completed it. Report it to the caller. + if (!ssl->s3->pending_write.empty()) { + *out_bytes_written = ssl->s3->pending_write.size(); + ssl->s3->pending_write = {}; + return 1; } SSLBuffer *buf = &ssl->s3->write_buffer; - if (len > SSL3_RT_MAX_PLAIN_LENGTH || buf->size() > 0) { + if (in.size() > SSL3_RT_MAX_PLAIN_LENGTH || buf->size() > 0) { OPENSSL_PUT_ERROR(SSL, ERR_R_INTERNAL_ERROR); return -1; } @@ -231,16 +237,22 @@ static int do_tls_write(SSL *ssl, int type, const uint8_t *in, unsigned len) { return -1; } - size_t flight_len = 0; + // We may have unflushed handshake data that must be written before |in|. This + // may be a KeyUpdate acknowledgment, 0-RTT key change messages, or a + // NewSessionTicket. + Span pending_flight; if (ssl->s3->pending_flight != nullptr) { - flight_len = - ssl->s3->pending_flight->length - ssl->s3->pending_flight_offset; + pending_flight = MakeConstSpan( + reinterpret_cast(ssl->s3->pending_flight->data), + ssl->s3->pending_flight->length); + pending_flight = pending_flight.subspan(ssl->s3->pending_flight_offset); } - size_t max_out = flight_len; - if (len > 0) { - const size_t max_ciphertext_len = len + SSL_max_seal_overhead(ssl); - if (max_ciphertext_len < len || max_out + max_ciphertext_len < max_out) { + size_t max_out = pending_flight.size(); + if (!in.empty()) { + const size_t max_ciphertext_len = in.size() + SSL_max_seal_overhead(ssl); + if (max_ciphertext_len < in.size() || + max_out + max_ciphertext_len < max_out) { OPENSSL_PUT_ERROR(SSL, ERR_R_OVERFLOW); return -1; } @@ -248,31 +260,29 @@ static int do_tls_write(SSL *ssl, int type, const uint8_t *in, unsigned len) { } if (max_out == 0) { - return 0; + // Nothing to write. + *out_bytes_written = 0; + return 1; } - if (!buf->EnsureCap(flight_len + ssl_seal_align_prefix_len(ssl), max_out)) { + if (!buf->EnsureCap(pending_flight.size() + ssl_seal_align_prefix_len(ssl), + max_out)) { return -1; } - // Add any unflushed handshake data as a prefix. This may be a KeyUpdate - // acknowledgment or 0-RTT key change messages. |pending_flight| must be clear - // when data is added to |write_buffer| or it will be written in the wrong - // order. - if (ssl->s3->pending_flight != nullptr) { - OPENSSL_memcpy( - buf->remaining().data(), - ssl->s3->pending_flight->data + ssl->s3->pending_flight_offset, - flight_len); + // Copy |pending_flight| to the output. + if (!pending_flight.empty()) { + OPENSSL_memcpy(buf->remaining().data(), pending_flight.data(), + pending_flight.size()); ssl->s3->pending_flight.reset(); ssl->s3->pending_flight_offset = 0; - buf->DidWrite(flight_len); + buf->DidWrite(pending_flight.size()); } - if (len > 0) { + if (!in.empty()) { size_t ciphertext_len; if (!tls_seal_record(ssl, buf->remaining().data(), &ciphertext_len, - buf->remaining().size(), type, in, len)) { + buf->remaining().size(), type, in.data(), in.size())) { return -1; } buf->DidWrite(ciphertext_len); @@ -282,16 +292,19 @@ static int do_tls_write(SSL *ssl, int type, const uint8_t *in, unsigned len) { // acknowledgments. ssl->s3->key_update_pending = false; - // Memorize arguments so that tls_write_pending can detect bad write retries - // later. - ssl->s3->wpend_tot = len; - ssl->s3->wpend_buf = in; - ssl->s3->wpend_type = type; - ssl->s3->wpend_ret = len; - ssl->s3->wpend_pending = true; + // Flush the write buffer. + ret = ssl_write_buffer_flush(ssl); + if (ret <= 0) { + // Track the unfinished write. + if (!in.empty()) { + ssl->s3->pending_write = in; + ssl->s3->pending_write_type = type; + } + return ret; + } - // We now just need to write the buffer. - return tls_write_pending(ssl, type, in, len); + *out_bytes_written = in.size(); + return 1; } ssl_open_record_t tls_open_app_data(SSL *ssl, Span *out, @@ -429,10 +442,13 @@ int tls_dispatch_alert(SSL *ssl) { return 0; } } else { - int ret = do_tls_write(ssl, SSL3_RT_ALERT, &ssl->s3->send_alert[0], 2); + size_t bytes_written; + int ret = + do_tls_write(ssl, &bytes_written, SSL3_RT_ALERT, ssl->s3->send_alert); if (ret <= 0) { return ret; } + assert(bytes_written == 2); } ssl->s3->alert_dispatch = false; diff --git a/Sources/CNIOBoringSSL/ssl/ssl_buffer.cc b/Sources/CNIOBoringSSL/ssl/ssl_buffer.cc index f321241a..7da92247 100644 --- a/Sources/CNIOBoringSSL/ssl/ssl_buffer.cc +++ b/Sources/CNIOBoringSSL/ssl/ssl_buffer.cc @@ -232,6 +232,7 @@ int ssl_handle_open_record(SSL *ssl, bool *out_retry, ssl_open_record_t ret, return 1; case ssl_open_record_close_notify: + ssl->s3->rwstate = SSL_ERROR_ZERO_RETURN; return 0; case ssl_open_record_error: diff --git a/Sources/CNIOBoringSSL/ssl/ssl_cipher.cc b/Sources/CNIOBoringSSL/ssl/ssl_cipher.cc index 8057042c..a8dd7f57 100644 --- a/Sources/CNIOBoringSSL/ssl/ssl_cipher.cc +++ b/Sources/CNIOBoringSSL/ssl/ssl_cipher.cc @@ -264,9 +264,9 @@ static constexpr SSL_CIPHER kCiphers[] = { // Cipher 1301 { - TLS1_TXT_AES_128_GCM_SHA256, + TLS1_3_RFC_AES_128_GCM_SHA256, "TLS_AES_128_GCM_SHA256", - TLS1_CK_AES_128_GCM_SHA256, + TLS1_3_CK_AES_128_GCM_SHA256, SSL_kGENERIC, SSL_aGENERIC, SSL_AES128GCM, @@ -276,9 +276,9 @@ static constexpr SSL_CIPHER kCiphers[] = { // Cipher 1302 { - TLS1_TXT_AES_256_GCM_SHA384, + TLS1_3_RFC_AES_256_GCM_SHA384, "TLS_AES_256_GCM_SHA384", - TLS1_CK_AES_256_GCM_SHA384, + TLS1_3_CK_AES_256_GCM_SHA384, SSL_kGENERIC, SSL_aGENERIC, SSL_AES256GCM, @@ -288,9 +288,9 @@ static constexpr SSL_CIPHER kCiphers[] = { // Cipher 1303 { - TLS1_TXT_CHACHA20_POLY1305_SHA256, + TLS1_3_RFC_CHACHA20_POLY1305_SHA256, "TLS_CHACHA20_POLY1305_SHA256", - TLS1_CK_CHACHA20_POLY1305_SHA256, + TLS1_3_CK_CHACHA20_POLY1305_SHA256, SSL_kGENERIC, SSL_aGENERIC, SSL_CHACHA20POLY1305, diff --git a/Sources/CNIOBoringSSL/ssl/ssl_file.cc b/Sources/CNIOBoringSSL/ssl/ssl_file.cc index f241870f..5b2448f1 100644 --- a/Sources/CNIOBoringSSL/ssl/ssl_file.cc +++ b/Sources/CNIOBoringSSL/ssl/ssl_file.cc @@ -128,25 +128,8 @@ static int xname_cmp(const X509_NAME **a, const X509_NAME **b) { return X509_NAME_cmp(*a, *b); } -STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file) { - bssl::UniquePtr ret(sk_X509_NAME_new_null()); - if (ret == nullptr || - !SSL_add_file_cert_subjects_to_stack(ret.get(), file)) { - return nullptr; - } - return ret.release(); -} - -int SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *out, - const char *file) { - bssl::UniquePtr in(BIO_new_file(file, "r")); - if (in == nullptr) { - return 0; - } - return SSL_add_bio_cert_subjects_to_stack(out, in.get()); -} - -int SSL_add_bio_cert_subjects_to_stack(STACK_OF(X509_NAME) *out, BIO *bio) { +static int add_bio_cert_subjects_to_stack(STACK_OF(X509_NAME) *out, BIO *bio, + bool allow_empty) { // This function historically sorted |out| after every addition and skipped // duplicates. This implementation preserves that behavior, but only sorts at // the end, to avoid a quadratic running time. Existing duplicates in |out| @@ -165,15 +148,20 @@ int SSL_add_bio_cert_subjects_to_stack(STACK_OF(X509_NAME) *out, BIO *bio) { RestoreCmpFunc restore = {out, sk_X509_NAME_set_cmp_func(out, xname_cmp)}; sk_X509_NAME_sort(out); + bool first = true; for (;;) { bssl::UniquePtr x509( PEM_read_bio_X509(bio, nullptr, nullptr, nullptr)); if (x509 == nullptr) { + if (first && !allow_empty) { + return 0; + } // TODO(davidben): This ignores PEM syntax errors. It should only succeed // on |PEM_R_NO_START_LINE|. ERR_clear_error(); break; } + first = false; X509_NAME *subject = X509_get_subject_name(x509.get()); // Skip if already present in |out|. Duplicates in |to_append| will be @@ -211,6 +199,33 @@ int SSL_add_bio_cert_subjects_to_stack(STACK_OF(X509_NAME) *out, BIO *bio) { return 1; } +STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file) { + bssl::UniquePtr in(BIO_new_file(file, "r")); + if (in == nullptr) { + return nullptr; + } + bssl::UniquePtr ret(sk_X509_NAME_new_null()); + if (ret == nullptr || // + !add_bio_cert_subjects_to_stack(ret.get(), in.get(), + /*allow_empty=*/false)) { + return nullptr; + } + return ret.release(); +} + +int SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *out, + const char *file) { + bssl::UniquePtr in(BIO_new_file(file, "r")); + if (in == nullptr) { + return 0; + } + return SSL_add_bio_cert_subjects_to_stack(out, in.get()); +} + +int SSL_add_bio_cert_subjects_to_stack(STACK_OF(X509_NAME) *out, BIO *bio) { + return add_bio_cert_subjects_to_stack(out, bio, /*allow_empty=*/true); +} + int SSL_use_certificate_file(SSL *ssl, const char *file, int type) { int reason_code; BIO *in; diff --git a/Sources/CNIOBoringSSL/ssl/ssl_lib.cc b/Sources/CNIOBoringSSL/ssl/ssl_lib.cc index 5d04b287..90c6186f 100644 --- a/Sources/CNIOBoringSSL/ssl/ssl_lib.cc +++ b/Sources/CNIOBoringSSL/ssl/ssl_lib.cc @@ -166,6 +166,10 @@ BSSL_NAMESPACE_BEGIN +static_assert(SSL3_RT_MAX_ENCRYPTED_OVERHEAD >= + SSL3_RT_SEND_MAX_ENCRYPTED_OVERHEAD, + "max overheads are inconsistent"); + // |SSL_R_UNKNOWN_PROTOCOL| is no longer emitted, but continue to define it // to avoid downstream churn. OPENSSL_DECLARE_ERROR_REASON(SSL, UNKNOWN_PROTOCOL) @@ -1058,6 +1062,7 @@ int SSL_write(SSL *ssl, const void *buf, int num) { } int ret = 0; + size_t bytes_written = 0; bool needs_handshake = false; do { // If necessary, complete the handshake implicitly. @@ -1072,10 +1077,16 @@ int SSL_write(SSL *ssl, const void *buf, int num) { } } - ret = ssl->method->write_app_data(ssl, &needs_handshake, - (const uint8_t *)buf, num); + if (num < 0) { + OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_LENGTH); + return -1; + } + ret = ssl->method->write_app_data( + ssl, &needs_handshake, &bytes_written, + MakeConstSpan(static_cast(buf), + static_cast(num))); } while (needs_handshake); - return ret; + return ret <= 0 ? ret : static_cast(bytes_written); } int SSL_key_update(SSL *ssl, int request_type) { @@ -1239,7 +1250,7 @@ void SSL_reset_early_data_reject(SSL *ssl) { // Discard any unfinished writes from the perspective of |SSL_write|'s // retry. The handshake will transparently flush out the pending record // (discarded by the server) to keep the framing correct. - ssl->s3->wpend_pending = false; + ssl->s3->pending_write = {}; } enum ssl_early_data_reason_t SSL_get_early_data_reason(const SSL *ssl) { @@ -1308,7 +1319,7 @@ int SSL_get_error(const SSL *ssl, int ret_code) { } if (ret_code == 0) { - if (ssl->s3->read_shutdown == ssl_shutdown_close_notify) { + if (ssl->s3->rwstate == SSL_ERROR_ZERO_RETURN) { return SSL_ERROR_ZERO_RETURN; } // An EOF was observed which violates the protocol, and the underlying @@ -1939,8 +1950,6 @@ int SSL_set1_curves_list(SSL *ssl, const char *curves) { } uint16_t SSL_get_curve_id(const SSL *ssl) { - // TODO(davidben): This checks the wrong session if there is a renegotiation - // in progress. SSL_SESSION *session = SSL_get_session(ssl); if (session == NULL) { return 0; @@ -2567,7 +2576,13 @@ void *SSL_CTX_get_ex_data(const SSL_CTX *ctx, int idx) { return CRYPTO_get_ex_data(&ctx->ex_data, idx); } -int SSL_want(const SSL *ssl) { return ssl->s3->rwstate; } +int SSL_want(const SSL *ssl) { + // Historically, OpenSSL did not track |SSL_ERROR_ZERO_RETURN| as an |rwstate| + // value. We do, but map it back to |SSL_ERROR_NONE| to preserve the original + // behavior. + return ssl->s3->rwstate == SSL_ERROR_ZERO_RETURN ? SSL_ERROR_NONE + : ssl->s3->rwstate; +} void SSL_CTX_set_tmp_rsa_callback(SSL_CTX *ctx, RSA *(*cb)(SSL *ssl, int is_export, @@ -2818,8 +2833,6 @@ uint64_t SSL_get_write_sequence(const SSL *ssl) { } uint16_t SSL_get_peer_signature_algorithm(const SSL *ssl) { - // TODO(davidben): This checks the wrong session if there is a renegotiation - // in progress. SSL_SESSION *session = SSL_get_session(ssl); if (session == NULL) { return 0; @@ -3037,6 +3050,8 @@ int SSL_CTX_set_num_tickets(SSL_CTX *ctx, size_t num_tickets) { return 1; } +size_t SSL_CTX_get_num_tickets(const SSL_CTX *ctx) { return ctx->num_tickets; } + int SSL_set_tlsext_status_type(SSL *ssl, int type) { if (!ssl->config) { return 0; diff --git a/Sources/CNIOBoringSSL/ssl/ssl_privkey.cc b/Sources/CNIOBoringSSL/ssl/ssl_privkey.cc index 3b87f722..516e768d 100644 --- a/Sources/CNIOBoringSSL/ssl/ssl_privkey.cc +++ b/Sources/CNIOBoringSSL/ssl/ssl_privkey.cc @@ -201,6 +201,31 @@ enum ssl_private_key_result_t ssl_private_key_sign( SSL_HANDSHAKE *hs, uint8_t *out, size_t *out_len, size_t max_out, uint16_t sigalg, Span in) { SSL *const ssl = hs->ssl; + SSL_HANDSHAKE_HINTS *const hints = hs->hints.get(); + Array spki; + if (hints) { + ScopedCBB spki_cbb; + if (!CBB_init(spki_cbb.get(), 64) || + !EVP_marshal_public_key(spki_cbb.get(), hs->local_pubkey.get()) || + !CBBFinishArray(spki_cbb.get(), &spki)) { + ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); + return ssl_private_key_failure; + } + } + + // Replay the signature from handshake hints if available. + if (hints && !hs->hints_requested && // + sigalg == hints->signature_algorithm && // + in == hints->signature_input && + MakeConstSpan(spki) == hints->signature_spki && + !hints->signature.empty() && // + hints->signature.size() <= max_out) { + // Signature algorithm and input both match. Reuse the signature from hints. + *out_len = hints->signature.size(); + OPENSSL_memcpy(out, hints->signature.data(), hints->signature.size()); + return ssl_private_key_success; + } + const SSL_PRIVATE_KEY_METHOD *key_method = hs->config->cert->key_method; EVP_PKEY *privatekey = hs->config->cert->privatekey.get(); assert(!hs->can_release_private_key); @@ -214,21 +239,33 @@ enum ssl_private_key_result_t ssl_private_key_sign( if (hs->pending_private_key_op) { ret = key_method->complete(ssl, out, out_len, max_out); } else { - ret = key_method->sign(ssl, out, out_len, max_out, - sigalg, in.data(), in.size()); + ret = key_method->sign(ssl, out, out_len, max_out, sigalg, in.data(), + in.size()); } if (ret == ssl_private_key_failure) { OPENSSL_PUT_ERROR(SSL, SSL_R_PRIVATE_KEY_OPERATION_FAILED); } hs->pending_private_key_op = ret == ssl_private_key_retry; - return ret; + if (ret != ssl_private_key_success) { + return ret; + } + } else { + *out_len = max_out; + ScopedEVP_MD_CTX ctx; + if (!setup_ctx(ssl, ctx.get(), privatekey, sigalg, false /* sign */) || + !EVP_DigestSign(ctx.get(), out, out_len, in.data(), in.size())) { + return ssl_private_key_failure; + } } - *out_len = max_out; - ScopedEVP_MD_CTX ctx; - if (!setup_ctx(ssl, ctx.get(), privatekey, sigalg, false /* sign */) || - !EVP_DigestSign(ctx.get(), out, out_len, in.data(), in.size())) { - return ssl_private_key_failure; + // Save the hint if applicable. + if (hints && hs->hints_requested) { + hints->signature_algorithm = sigalg; + hints->signature_spki = std::move(spki); + if (!hints->signature_input.CopyFrom(in) || + !hints->signature.CopyFrom(MakeConstSpan(out, *out_len))) { + return ssl_private_key_failure; + } } return ssl_private_key_success; } diff --git a/Sources/CNIOBoringSSL/ssl/ssl_session.cc b/Sources/CNIOBoringSSL/ssl/ssl_session.cc index 4677166a..9c73441a 100644 --- a/Sources/CNIOBoringSSL/ssl/ssl_session.cc +++ b/Sources/CNIOBoringSSL/ssl/ssl_session.cc @@ -1169,20 +1169,31 @@ SSL_SESSION *SSL_magic_pending_session_ptr(void) { } SSL_SESSION *SSL_get_session(const SSL *ssl) { - // Once the handshake completes we return the established session. Otherwise - // we return the intermediate session, either |session| (for resumption) or - // |new_session| if doing a full handshake. - if (!SSL_in_init(ssl)) { + // Once the initially handshake completes, we return the most recently + // established session. In particular, if there is a pending renegotiation, we + // do not return information about it until it completes. + // + // Code in the handshake must either use |hs->new_session| (if updating a + // partial session) or |ssl_handshake_session| (if trying to query properties + // consistently across TLS 1.2 resumption and other handshakes). + if (ssl->s3->established_session != nullptr) { return ssl->s3->established_session.get(); } + + // Otherwise, we must be in the initial handshake. SSL_HANDSHAKE *hs = ssl->s3->hs.get(); + assert(hs != nullptr); + assert(!ssl->s3->initial_handshake_complete); + + // Return the 0-RTT session, if in the 0-RTT state. While the handshake has + // not actually completed, the public accessors all report properties as if + // it has. if (hs->early_session) { return hs->early_session.get(); } - if (hs->new_session) { - return hs->new_session.get(); - } - return ssl->session.get(); + + // Otherwise, return the partial session. + return (SSL_SESSION *)ssl_handshake_session(hs); } SSL_SESSION *SSL_get1_session(SSL *ssl) { diff --git a/Sources/CNIOBoringSSL/ssl/tls13_both.cc b/Sources/CNIOBoringSSL/ssl/tls13_both.cc index 759ca64d..cfffae39 100644 --- a/Sources/CNIOBoringSSL/ssl/tls13_both.cc +++ b/Sources/CNIOBoringSSL/ssl/tls13_both.cc @@ -576,7 +576,6 @@ enum ssl_private_key_result_t tls13_add_certificate_verify(SSL_HANDSHAKE *hs) { return ssl_private_key_failure; } - // Sign the digest. CBB child; const size_t max_sig_len = EVP_PKEY_size(hs->local_pubkey.get()); uint8_t *sig; @@ -595,40 +594,10 @@ enum ssl_private_key_result_t tls13_add_certificate_verify(SSL_HANDSHAKE *hs) { return ssl_private_key_failure; } - SSL_HANDSHAKE_HINTS *const hints = hs->hints.get(); - Array spki; - if (hints) { - ScopedCBB spki_cbb; - if (!CBB_init(spki_cbb.get(), 64) || - !EVP_marshal_public_key(spki_cbb.get(), hs->local_pubkey.get()) || - !CBBFinishArray(spki_cbb.get(), &spki)) { - ssl_send_alert(ssl, SSL3_AL_FATAL, SSL_AD_INTERNAL_ERROR); - return ssl_private_key_failure; - } - } - - if (hints && !hs->hints_requested && - signature_algorithm == hints->signature_algorithm && - MakeConstSpan(msg) == hints->signature_input && - MakeConstSpan(spki) == hints->signature_spki && - !hints->signature.empty() && hints->signature.size() <= max_sig_len) { - // Signature algorithm and input both match. Reuse the signature from hints. - sig_len = hints->signature.size(); - OPENSSL_memcpy(sig, hints->signature.data(), sig_len); - } else { - enum ssl_private_key_result_t sign_result = ssl_private_key_sign( - hs, sig, &sig_len, max_sig_len, signature_algorithm, msg); - if (sign_result != ssl_private_key_success) { - return sign_result; - } - if (hints && hs->hints_requested) { - hints->signature_algorithm = signature_algorithm; - hints->signature_input = std::move(msg); - hints->signature_spki = std::move(spki); - if (!hints->signature.CopyFrom(MakeSpan(sig, sig_len))) { - return ssl_private_key_failure; - } - } + enum ssl_private_key_result_t sign_result = ssl_private_key_sign( + hs, sig, &sig_len, max_sig_len, signature_algorithm, msg); + if (sign_result != ssl_private_key_success) { + return sign_result; } if (!CBB_did_write(&child, sig_len) || diff --git a/Sources/CNIOBoringSSL/ssl/tls13_server.cc b/Sources/CNIOBoringSSL/ssl/tls13_server.cc index a26f2e9c..ad955dc0 100644 --- a/Sources/CNIOBoringSSL/ssl/tls13_server.cc +++ b/Sources/CNIOBoringSSL/ssl/tls13_server.cc @@ -738,12 +738,13 @@ static enum ssl_hs_wait_t do_send_server_hello(SSL_HANDSHAKE *hs) { SSL_HANDSHAKE_HINTS *const hints = hs->hints.get(); if (hints && !hs->hints_requested && - hints->server_random.size() == random.size()) { - OPENSSL_memcpy(random.data(), hints->server_random.data(), random.size()); + hints->server_random_tls13.size() == random.size()) { + OPENSSL_memcpy(random.data(), hints->server_random_tls13.data(), + random.size()); } else { RAND_bytes(random.data(), random.size()); if (hints && hs->hints_requested && - !hints->server_random.CopyFrom(random)) { + !hints->server_random_tls13.CopyFrom(random)) { return ssl_hs_error; } } diff --git a/scripts/vendor-boringssl.sh b/scripts/vendor-boringssl.sh index e089b7c3..984395d1 100755 --- a/scripts/vendor-boringssl.sh +++ b/scripts/vendor-boringssl.sh @@ -356,6 +356,7 @@ cat << EOF > "$DSTROOT/include/CNIOBoringSSL.h" #include "CNIOBoringSSL_boringssl_prefix_symbols_asm.h" #include "CNIOBoringSSL_cast.h" #include "CNIOBoringSSL_chacha.h" +#include "CNIOBoringSSL_ctrdrbg.h" #include "CNIOBoringSSL_cmac.h" #include "CNIOBoringSSL_conf.h" #include "CNIOBoringSSL_cpu.h" @@ -392,6 +393,7 @@ cat << EOF > "$DSTROOT/include/CNIOBoringSSL.h" #include "CNIOBoringSSL_srtp.h" #include "CNIOBoringSSL_ssl.h" #include "CNIOBoringSSL_trust_token.h" +#include "CNIOBoringSSL_type_check.h" #include "CNIOBoringSSL_x509_vfy.h" #include "CNIOBoringSSL_x509v3.h"