From f0525da24dc3c6cbb2b6b338b65042bc91cbc4bb Mon Sep 17 00:00:00 2001 From: Cory Benfield Date: Tue, 12 Mar 2024 10:50:25 +0000 Subject: [PATCH] Update BoringSSL to dbad745811195c00b729efd0ee0a09b7d9fce1d2 (#222) * Update vendoring script for changed layout * Update BoringSSL to dbad745811195c00b729efd0ee0a09b7d9fce1d2 --- Package.swift | 2 +- .../CCryptoBoringSSL/crypto/asn1/a_gentm.c | 2 +- Sources/CCryptoBoringSSL/crypto/asn1/a_time.c | 2 +- .../CCryptoBoringSSL/crypto/asn1/a_utctm.c | 2 +- .../CCryptoBoringSSL/crypto/asn1/internal.h | 8 +- .../CCryptoBoringSSL/crypto/asn1/posix_time.c | 91 +- Sources/CCryptoBoringSSL/crypto/bio/bio.c | 11 +- Sources/CCryptoBoringSSL/crypto/bio/file.c | 35 +- .../CCryptoBoringSSL/crypto/bytestring/ber.c | 15 +- .../CCryptoBoringSSL/crypto/bytestring/cbs.c | 13 - .../chacha/chacha-x86-linux.linux.x86.S | 108 +- .../chacha/chacha-x86-windows.windows.x86.S | 98 +- .../chacha/chacha-x86_64-linux.linux.x86_64.S | 64 +- .../chacha/chacha-x86_64-mac.mac.x86_64.S | 47 +- .../CCryptoBoringSSL/crypto/chacha/chacha.c | 20 +- .../CCryptoBoringSSL/crypto/chacha/internal.h | 54 +- .../aes128gcmsiv-x86_64-linux.linux.x86_64.S | 14 +- .../aes128gcmsiv-x86_64-mac.mac.x86_64.S | 14 +- .../crypto/cipher_extra/e_aesgcmsiv.c | 72 +- .../crypto/cipher_extra/e_des.c | 43 +- Sources/CCryptoBoringSSL/crypto/conf/conf.c | 176 +- .../CCryptoBoringSSL/crypto/conf/internal.h | 6 +- Sources/CCryptoBoringSSL/crypto/cpu_intel.c | 6 +- .../crypto/curve25519/curve25519.c | 4 + .../crypto/curve25519/internal.h | 2 +- Sources/CCryptoBoringSSL/crypto/des/des.c | 213 +- .../CCryptoBoringSSL/crypto/des/internal.h | 109 +- Sources/CCryptoBoringSSL/crypto/dsa/dsa.c | 7 +- Sources/CCryptoBoringSSL/crypto/err/err.c | 118 +- Sources/CCryptoBoringSSL/crypto/ex_data.c | 13 +- .../aesni-x86_64-linux.linux.x86_64.S | 152 +- .../fipsmodule/aesni-x86_64-mac.mac.x86_64.S | 152 +- .../fipsmodule/armv4-mont-ios.ios.arm.S | 47 +- .../fipsmodule/armv4-mont-linux.linux.arm.S | 41 +- .../fipsmodule/bn-586-windows.windows.x86.S | 269 +- .../crypto/fipsmodule/bn/bytes.c | 37 +- .../crypto/fipsmodule/bn/exponentiation.c | 4 +- .../crypto/fipsmodule/bn/gcd.c | 31 +- .../crypto/fipsmodule/bn/internal.h | 51 +- .../crypto/fipsmodule/bn/montgomery.c | 26 + .../crypto/fipsmodule/bn/montgomery_inv.c | 51 +- .../crypto/fipsmodule/bn/random.c | 10 +- .../crypto/fipsmodule/cipher/e_aesccm.c | 91 +- .../crypto/fipsmodule/digest/digest.c | 4 + .../crypto/fipsmodule/ec/ec_key.c | 22 +- .../ghash-x86-windows.windows.x86.S | 307 ++ .../ghash-x86_64-linux.linux.x86_64.S | 8 - .../fipsmodule/ghash-x86_64-mac.mac.x86_64.S | 7 - .../crypto/fipsmodule/rand/rand.c | 7 +- .../crypto/fipsmodule/rsa/rsa.c | 8 +- .../crypto/fipsmodule/rsa/rsa_impl.c | 9 +- .../crypto/fipsmodule/sha/internal.h | 102 +- .../crypto/fipsmodule/sha/sha1.c | 8 +- .../crypto/fipsmodule/sha/sha256.c | 6 +- .../crypto/fipsmodule/sha/sha512.c | 8 +- .../fipsmodule/sha1-586-linux.linux.x86.S | 92 +- .../fipsmodule/sha1-586-windows.windows.x86.S | 2401 ++++++++++++- .../fipsmodule/sha256-586-linux.linux.x86.S | 142 +- .../sha256-586-windows.windows.x86.S | 2678 +++++++++++++-- .../fipsmodule/sha256-armv4-ios.ios.arm.S | 39 +- .../fipsmodule/sha256-armv4-linux.linux.arm.S | 39 +- .../sha512-586-windows.windows.x86.S | 2274 +++++++++++- .../fipsmodule/x86-mont-windows.windows.x86.S | 168 +- .../x86_64-mont-linux.linux.x86_64.S | 50 +- .../fipsmodule/x86_64-mont-mac.mac.x86_64.S | 51 +- Sources/CCryptoBoringSSL/crypto/hpke/hpke.c | 2 + Sources/CCryptoBoringSSL/crypto/internal.h | 117 +- .../CCryptoBoringSSL/crypto/kyber/internal.h | 2 +- Sources/CCryptoBoringSSL/crypto/kyber/kyber.c | 2 +- Sources/CCryptoBoringSSL/crypto/mem.c | 18 +- Sources/CCryptoBoringSSL/crypto/pem/pem_lib.c | 35 +- Sources/CCryptoBoringSSL/crypto/pem/pem_pk8.c | 85 +- .../CCryptoBoringSSL/crypto/pem/pem_pkey.c | 25 +- .../crypto/rsa_extra/rsa_crypt.c | 4 +- Sources/CCryptoBoringSSL/crypto/spx/spx.c | 2 +- Sources/CCryptoBoringSSL/crypto/x509/by_dir.c | 51 +- .../CCryptoBoringSSL/crypto/x509/by_file.c | 2 +- .../CCryptoBoringSSL/crypto/x509/internal.h | 8 +- .../CCryptoBoringSSL/crypto/x509/v3_cpols.c | 13 +- .../CCryptoBoringSSL/crypto/x509/v3_crld.c | 4 +- .../CCryptoBoringSSL/crypto/x509/v3_enum.c | 1 + .../CCryptoBoringSSL/crypto/x509/v3_info.c | 2 +- Sources/CCryptoBoringSSL/crypto/x509/v3_lib.c | 2 + .../CCryptoBoringSSL/crypto/x509/v3_purp.c | 271 +- .../CCryptoBoringSSL/crypto/x509/x509_lu.c | 35 +- .../CCryptoBoringSSL/crypto/x509/x509_trs.c | 110 +- .../CCryptoBoringSSL/crypto/x509/x509_vfy.c | 311 +- .../CCryptoBoringSSL/crypto/x509/x509_vpm.c | 15 +- Sources/CCryptoBoringSSL/crypto/x509/x_crl.c | 1 + Sources/CCryptoBoringSSL/crypto/x509/x_name.c | 12 +- Sources/CCryptoBoringSSL/crypto/x509/x_x509.c | 7 +- .../CCryptoBoringSSL/crypto/x509/x_x509a.c | 8 +- Sources/CCryptoBoringSSL/hash.txt | 2 +- .../include/CCryptoBoringSSL_asn1.h | 20 +- .../include/CCryptoBoringSSL_base.h | 5 +- .../include/CCryptoBoringSSL_bio.h | 119 +- ...CryptoBoringSSL_boringssl_prefix_symbols.h | 386 +-- ...toBoringSSL_boringssl_prefix_symbols_asm.h | 50 +- .../include/CCryptoBoringSSL_bytestring.h | 9 +- .../include/CCryptoBoringSSL_crypto.h | 1 + .../include/CCryptoBoringSSL_des.h | 13 - .../include/CCryptoBoringSSL_ec.h | 36 +- .../include/CCryptoBoringSSL_err.h | 13 + .../include/CCryptoBoringSSL_ex_data.h | 18 +- .../include/CCryptoBoringSSL_obj.h | 4 +- .../include/CCryptoBoringSSL_pem.h | 116 +- .../include/CCryptoBoringSSL_posix_time.h | 51 + .../include/CCryptoBoringSSL_rsa.h | 29 +- .../include/CCryptoBoringSSL_span.h | 52 +- .../include/CCryptoBoringSSL_target.h | 6 +- .../include/CCryptoBoringSSL_time.h | 29 +- .../include/CCryptoBoringSSL_x509.h | 3043 +++++++++++------ .../include/CCryptoBoringSSL_x509v3.h | 24 + .../include/boringssl_prefix_symbols_nasm.inc | 100 +- .../CCryptoBoringSSL_kyber.h | 0 .../experimental/CCryptoBoringSSL_spx.h} | 2 +- scripts/vendor-boringssl.sh | 12 +- 117 files changed, 12098 insertions(+), 3948 deletions(-) create mode 100644 Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_posix_time.h rename Sources/CCryptoBoringSSL/include/{ => experimental}/CCryptoBoringSSL_kyber.h (100%) rename Sources/CCryptoBoringSSL/{crypto/spx/internal.h => include/experimental/CCryptoBoringSSL_spx.h} (98%) diff --git a/Package.swift b/Package.swift index 16b36d8f..2ee6769a 100644 --- a/Package.swift +++ b/Package.swift @@ -20,7 +20,7 @@ // Sources/CCryptoBoringSSL directory. The source repository is at // https://boringssl.googlesource.com/boringssl. // -// BoringSSL Commit: 7a813621dac6878ab53b6ed7392939a8982226e8 +// BoringSSL Commit: dbad745811195c00b729efd0ee0a09b7d9fce1d2 import PackageDescription diff --git a/Sources/CCryptoBoringSSL/crypto/asn1/a_gentm.c b/Sources/CCryptoBoringSSL/crypto/asn1/a_gentm.c index d6bc8259..2f8e4c21 100644 --- a/Sources/CCryptoBoringSSL/crypto/asn1/a_gentm.c +++ b/Sources/CCryptoBoringSSL/crypto/asn1/a_gentm.c @@ -58,7 +58,7 @@ #include #include #include -#include +#include #include #include diff --git a/Sources/CCryptoBoringSSL/crypto/asn1/a_time.c b/Sources/CCryptoBoringSSL/crypto/asn1/a_time.c index 76aa5704..60ecd2af 100644 --- a/Sources/CCryptoBoringSSL/crypto/asn1/a_time.c +++ b/Sources/CCryptoBoringSSL/crypto/asn1/a_time.c @@ -55,7 +55,7 @@ * [including the GNU Public Licence.] */ #include -#include +#include #include #include diff --git a/Sources/CCryptoBoringSSL/crypto/asn1/a_utctm.c b/Sources/CCryptoBoringSSL/crypto/asn1/a_utctm.c index 8bb97463..02f784db 100644 --- a/Sources/CCryptoBoringSSL/crypto/asn1/a_utctm.c +++ b/Sources/CCryptoBoringSSL/crypto/asn1/a_utctm.c @@ -58,7 +58,7 @@ #include #include #include -#include +#include #include #include diff --git a/Sources/CCryptoBoringSSL/crypto/asn1/internal.h b/Sources/CCryptoBoringSSL/crypto/asn1/internal.h index 8c73dbd7..71244051 100644 --- a/Sources/CCryptoBoringSSL/crypto/asn1/internal.h +++ b/Sources/CCryptoBoringSSL/crypto/asn1/internal.h @@ -76,18 +76,12 @@ extern "C" { // returned. On failure NULL is returned. OPENSSL_EXPORT struct tm *OPENSSL_gmtime(const time_t *time, struct tm *result); -// 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. OPENSSL_EXPORT int OPENSSL_gmtime_adj(struct tm *tm, int offset_day, - long offset_sec); + int64_t offset_sec); // 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 diff --git a/Sources/CCryptoBoringSSL/crypto/asn1/posix_time.c b/Sources/CCryptoBoringSSL/crypto/asn1/posix_time.c index c997d34e..0dc8f428 100644 --- a/Sources/CCryptoBoringSSL/crypto/asn1/posix_time.c +++ b/Sources/CCryptoBoringSSL/crypto/asn1/posix_time.c @@ -15,7 +15,7 @@ // Time conversion to/from POSIX time_t and struct tm, with no support // for time zones other than UTC -#include +#include #include #include @@ -26,12 +26,12 @@ #include "internal.h" #define SECS_PER_HOUR (60 * 60) -#define SECS_PER_DAY (24 * SECS_PER_HOUR) +#define SECS_PER_DAY (INT64_C(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) { +static int is_valid_date(int64_t year, int64_t month, int64_t day) { if (day < 1 || month < 1 || year < 0 || year > 9999) { return 0; } @@ -62,7 +62,7 @@ static int is_valid_date(int year, int month, int day) { // 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) { +static int is_valid_time(int64_t hours, int64_t minutes, int64_t seconds) { if (hours < 0 || minutes < 0 || seconds < 0 || hours > 23 || minutes > 59 || seconds > 59) { return 0; @@ -70,17 +70,22 @@ static int is_valid_time(int hours, int minutes, int seconds) { 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; +// 0000-01-01 00:00:00 UTC +#define MIN_POSIX_TIME INT64_C(-62167219200) +// 9999-12-31 23:59:59 UTC +#define MAX_POSIX_TIME INT64_C(253402300799) + +// Is an int64 time within our expected range? +static int is_valid_posix_time(int64_t time) { + return MIN_POSIX_TIME <= time && time <= MAX_POSIX_TIME; } // 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) { +static int posix_time_from_utc(int64_t year, int64_t month, int64_t day, + int64_t hours, int64_t minutes, int64_t seconds, + int64_t *out_time) { if (!is_valid_date(year, month, day) || !is_valid_time(hours, minutes, seconds)) { return 0; @@ -108,7 +113,7 @@ static int posix_time_from_utc(int year, int month, int day, int hours, 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)) { + if (!is_valid_posix_time(time)) { return 0; } int64_t days = time / SECS_PER_DAY; @@ -143,19 +148,21 @@ static int utc_from_posix_time(int64_t time, int *out_year, int *out_month, } 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); + return posix_time_from_utc(tm->tm_year + INT64_C(1900), + tm->tm_mon + INT64_C(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)) { + struct tm tmp_tm = {0}; + if (!utc_from_posix_time(time, &tmp_tm.tm_year, &tmp_tm.tm_mon, + &tmp_tm.tm_mday, &tmp_tm.tm_hour, &tmp_tm.tm_min, + &tmp_tm.tm_sec)) { return 0; } - out_tm->tm_year -= 1900; - out_tm->tm_mon -= 1; + tmp_tm.tm_year -= 1900; + tmp_tm.tm_mon -= 1; + *out_tm = tmp_tm; return 1; } @@ -187,43 +194,47 @@ struct tm *OPENSSL_gmtime(const time_t *time, struct tm *out_tm) { return out_tm; } -int OPENSSL_gmtime_adj(struct tm *tm, int off_day, long offset_sec) { +int OPENSSL_gmtime_adj(struct tm *tm, int offset_day, int64_t 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)) { + if (!OPENSSL_tm_to_posix(tm, &posix_time)) { return 0; } - if (!utc_from_posix_time( - posix_time + (int64_t)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)) { + static_assert(INT_MAX <= INT64_MAX / SECS_PER_DAY, + "day offset in seconds cannot overflow"); + static_assert(MAX_POSIX_TIME <= INT64_MAX - INT_MAX * SECS_PER_DAY, + "addition cannot overflow"); + static_assert(MIN_POSIX_TIME >= INT64_MIN - INT_MIN * SECS_PER_DAY, + "addition cannot underflow"); + posix_time += offset_day * SECS_PER_DAY; + if (posix_time > 0 && offset_sec > INT64_MAX - posix_time) { + return 0; + } + if (posix_time < 0 && offset_sec < INT64_MIN - posix_time) { + return 0; + } + posix_time += offset_sec; + + if (!OPENSSL_posix_to_tm(posix_time, tm)) { 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)) { + int64_t time_to, time_from; + if (!OPENSSL_tm_to_posix(to, &time_to) || + !OPENSSL_tm_to_posix(from, &time_from)) { return 0; } + // Times are in range, so these calculations can not overflow. + static_assert(SECS_PER_DAY <= INT_MAX, "seconds per day does not fit in int"); + static_assert((MAX_POSIX_TIME - MIN_POSIX_TIME) / SECS_PER_DAY <= INT_MAX, + "range of valid POSIX times, in days, does not fit in int"); 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/CCryptoBoringSSL/crypto/bio/bio.c b/Sources/CCryptoBoringSSL/crypto/bio/bio.c index bcf659d2..77181653 100644 --- a/Sources/CCryptoBoringSSL/crypto/bio/bio.c +++ b/Sources/CCryptoBoringSSL/crypto/bio/bio.c @@ -345,11 +345,11 @@ int BIO_set_close(BIO *bio, int close_flag) { return (int)BIO_ctrl(bio, BIO_CTRL_SET_CLOSE, close_flag, NULL); } -OPENSSL_EXPORT size_t BIO_number_read(const BIO *bio) { +OPENSSL_EXPORT uint64_t BIO_number_read(const BIO *bio) { return bio->num_read; } -OPENSSL_EXPORT size_t BIO_number_written(const BIO *bio) { +OPENSSL_EXPORT uint64_t BIO_number_written(const BIO *bio) { return bio->num_write; } @@ -714,12 +714,7 @@ int BIO_get_ex_new_index(long argl, void *argp, CRYPTO_EX_unused *unused, CRYPTO_EX_dup *dup_unused, CRYPTO_EX_free *free_func) { - int index; - if (!CRYPTO_get_ex_new_index(&g_ex_data_class, &index, argl, argp, - free_func)) { - return -1; - } - return index; + return CRYPTO_get_ex_new_index_ex(&g_ex_data_class, argl, argp, free_func); } int BIO_set_ex_data(BIO *bio, int idx, void *data) { diff --git a/Sources/CCryptoBoringSSL/crypto/bio/file.c b/Sources/CCryptoBoringSSL/crypto/bio/file.c index 454e1e94..f682c03f 100644 --- a/Sources/CCryptoBoringSSL/crypto/bio/file.c +++ b/Sources/CCryptoBoringSSL/crypto/bio/file.c @@ -73,6 +73,7 @@ #include +#include #include #include #include @@ -82,6 +83,10 @@ #include "../internal.h" +#if defined(OPENSSL_WINDOWS) +#include +#include +#endif #define BIO_FP_READ 0x02 #define BIO_FP_WRITE 0x04 @@ -122,14 +127,13 @@ BIO *BIO_new_file(const char *filename, const char *mode) { return ret; } -BIO *BIO_new_fp(FILE *stream, int close_flag) { +BIO *BIO_new_fp(FILE *stream, int flags) { BIO *ret = BIO_new(BIO_s_file()); - if (ret == NULL) { return NULL; } - BIO_set_fp(ret, stream, close_flag); + BIO_set_fp(ret, stream, flags); return ret; } @@ -196,6 +200,17 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr) { break; case BIO_C_SET_FILE_PTR: file_free(b); + static_assert((BIO_CLOSE & BIO_FP_TEXT) == 0, + "BIO_CLOSE and BIO_FP_TEXT must not collide"); +#if defined(OPENSSL_WINDOWS) + // If |BIO_FP_TEXT| is not set, OpenSSL will switch the file to binary + // mode. BoringSSL intentionally diverges here because it means code + // tested under POSIX will inadvertently change the state of |FILE| + // objects when wrapping them in a |BIO|. + if (num & BIO_FP_TEXT) { + _setmode(_fileno(ptr), _O_TEXT); + } +#endif b->shutdown = (int)num & BIO_CLOSE; b->ptr = ptr; b->init = 1; @@ -206,16 +221,16 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr) { const char *mode; if (num & BIO_FP_APPEND) { if (num & BIO_FP_READ) { - mode = "a+"; + mode = "ab+"; } else { - mode = "a"; + mode = "ab"; } } else if ((num & BIO_FP_READ) && (num & BIO_FP_WRITE)) { - mode = "r+"; + mode = "rb+"; } else if (num & BIO_FP_WRITE) { - mode = "w"; + mode = "wb"; } else if (num & BIO_FP_READ) { - mode = "r"; + mode = "rb"; } else { OPENSSL_PUT_ERROR(BIO, BIO_R_BAD_FOPEN_MODE); ret = 0; @@ -287,8 +302,8 @@ int BIO_get_fp(BIO *bio, FILE **out_file) { return (int)BIO_ctrl(bio, BIO_C_GET_FILE_PTR, 0, (char *)out_file); } -int BIO_set_fp(BIO *bio, FILE *file, int close_flag) { - return (int)BIO_ctrl(bio, BIO_C_SET_FILE_PTR, close_flag, (char *)file); +int BIO_set_fp(BIO *bio, FILE *file, int flags) { + return (int)BIO_ctrl(bio, BIO_C_SET_FILE_PTR, flags, (char *)file); } int BIO_read_filename(BIO *bio, const char *filename) { diff --git a/Sources/CCryptoBoringSSL/crypto/bytestring/ber.c b/Sources/CCryptoBoringSSL/crypto/bytestring/ber.c index 11108654..35f88131 100644 --- a/Sources/CCryptoBoringSSL/crypto/bytestring/ber.c +++ b/Sources/CCryptoBoringSSL/crypto/bytestring/ber.c @@ -18,13 +18,10 @@ #include #include "internal.h" -#include "../internal.h" -// kMaxDepth is a just a sanity limit. The code should be such that the length -// of the input being processes always decreases. None the less, a very large -// input could otherwise cause the stack to overflow. -static const uint32_t kMaxDepth = 2048; +// kMaxDepth limits the recursion depth to avoid overflowing the stack. +static const uint32_t kMaxDepth = 128; // is_string_type returns one if |tag| is a string type and zero otherwise. It // ignores the constructed bit. @@ -56,13 +53,11 @@ static int is_string_type(CBS_ASN1_TAG tag) { // found. The value of |orig_in| is not changed. It returns one on success (i.e. // |*ber_found| was set) and zero on error. static int cbs_find_ber(const CBS *orig_in, int *ber_found, uint32_t depth) { - CBS in; - if (depth > kMaxDepth) { return 0; } - CBS_init(&in, CBS_data(orig_in), CBS_len(orig_in)); + CBS in = *orig_in; *ber_found = 0; while (CBS_len(&in) > 0) { @@ -87,6 +82,10 @@ static int cbs_find_ber(const CBS *orig_in, int *ber_found, uint32_t depth) { !cbs_find_ber(&contents, ber_found, depth + 1)) { return 0; } + if (*ber_found) { + // We already found BER. No need to continue parsing. + return 1; + } } } diff --git a/Sources/CCryptoBoringSSL/crypto/bytestring/cbs.c b/Sources/CCryptoBoringSSL/crypto/bytestring/cbs.c index e9d31ba7..ee5a41b2 100644 --- a/Sources/CCryptoBoringSSL/crypto/bytestring/cbs.c +++ b/Sources/CCryptoBoringSSL/crypto/bytestring/cbs.c @@ -26,11 +26,6 @@ #include "internal.h" -void CBS_init(CBS *cbs, const uint8_t *data, size_t len) { - cbs->data = data; - cbs->len = len; -} - static int cbs_get(CBS *cbs, const uint8_t **p, size_t n) { if (cbs->len < n) { return 0; @@ -47,14 +42,6 @@ int CBS_skip(CBS *cbs, size_t len) { return cbs_get(cbs, &dummy, len); } -const uint8_t *CBS_data(const CBS *cbs) { - return cbs->data; -} - -size_t CBS_len(const CBS *cbs) { - return cbs->len; -} - int CBS_stow(const CBS *cbs, uint8_t **out_ptr, size_t *out_len) { OPENSSL_free(*out_ptr); *out_ptr = NULL; diff --git a/Sources/CCryptoBoringSSL/crypto/chacha/chacha-x86-linux.linux.x86.S b/Sources/CCryptoBoringSSL/crypto/chacha/chacha-x86-linux.linux.x86.S index f2793520..eb940347 100644 --- a/Sources/CCryptoBoringSSL/crypto/chacha/chacha-x86-linux.linux.x86.S +++ b/Sources/CCryptoBoringSSL/crypto/chacha/chacha-x86-linux.linux.x86.S @@ -7,29 +7,16 @@ #if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86) && defined(__ELF__) .text -.globl ChaCha20_ctr32 -.hidden ChaCha20_ctr32 -.type ChaCha20_ctr32,@function +.globl ChaCha20_ctr32_nohw +.hidden ChaCha20_ctr32_nohw +.type ChaCha20_ctr32_nohw,@function .align 16 -ChaCha20_ctr32: -.L_ChaCha20_ctr32_begin: +ChaCha20_ctr32_nohw: +.L_ChaCha20_ctr32_nohw_begin: pushl %ebp pushl %ebx pushl %esi pushl %edi - xorl %eax,%eax - cmpl 28(%esp),%eax - je .L000no_data - call .Lpic_point -.Lpic_point: - popl %eax - leal OPENSSL_ia32cap_P-.Lpic_point(%eax),%ebp - testl $16777216,(%ebp) - jz .L001x86 - testl $512,4(%ebp) - jz .L001x86 - jmp .Lssse3_shortcut -.L001x86: movl 32(%esp),%esi movl 36(%esp),%edi subl $132,%esp @@ -58,13 +45,13 @@ ChaCha20_ctr32: movl %ebx,116(%esp) movl %ecx,120(%esp) movl %edx,124(%esp) - jmp .L002entry + jmp .L000entry .align 16 -.L003outer_loop: +.L001outer_loop: movl %ebx,156(%esp) movl %eax,152(%esp) movl %ecx,160(%esp) -.L002entry: +.L000entry: movl $1634760805,%eax movl $857760878,4(%esp) movl $2036477234,8(%esp) @@ -92,9 +79,9 @@ ChaCha20_ctr32: movl %edi,60(%esp) movl %edx,112(%esp) movl $10,%ebx - jmp .L004loop + jmp .L002loop .align 16 -.L004loop: +.L002loop: addl %ebp,%eax movl %ebx,128(%esp) movl %ebp,%ebx @@ -248,14 +235,14 @@ ChaCha20_ctr32: xorl %esi,%ebp roll $7,%ebp decl %ebx - jnz .L004loop + jnz .L002loop movl 160(%esp),%ebx addl $1634760805,%eax addl 80(%esp),%ebp addl 96(%esp),%ecx addl 100(%esp),%esi cmpl $64,%ebx - jb .L005tail + jb .L003tail movl 156(%esp),%ebx addl 112(%esp),%edx addl 120(%esp),%edi @@ -318,9 +305,9 @@ ChaCha20_ctr32: movl %ebp,(%eax) leal 64(%eax),%eax subl $64,%ecx - jnz .L003outer_loop - jmp .L006done -.L005tail: + jnz .L001outer_loop + jmp .L004done +.L003tail: addl 112(%esp),%edx addl 120(%esp),%edi movl %eax,(%esp) @@ -364,34 +351,35 @@ ChaCha20_ctr32: movl %edi,60(%esp) xorl %eax,%eax xorl %edx,%edx -.L007tail_loop: +.L005tail_loop: movb (%esi,%ebp,1),%al movb (%esp,%esi,1),%dl leal 1(%esi),%esi xorb %dl,%al movb %al,-1(%ecx,%esi,1) decl %ebx - jnz .L007tail_loop -.L006done: + jnz .L005tail_loop +.L004done: addl $132,%esp -.L000no_data: popl %edi popl %esi popl %ebx popl %ebp ret -.size ChaCha20_ctr32,.-.L_ChaCha20_ctr32_begin -.globl ChaCha20_ssse3 -.hidden ChaCha20_ssse3 -.type ChaCha20_ssse3,@function +.size ChaCha20_ctr32_nohw,.-.L_ChaCha20_ctr32_nohw_begin +.globl ChaCha20_ctr32_ssse3 +.hidden ChaCha20_ctr32_ssse3 +.type ChaCha20_ctr32_ssse3,@function .align 16 -ChaCha20_ssse3: -.L_ChaCha20_ssse3_begin: +ChaCha20_ctr32_ssse3: +.L_ChaCha20_ctr32_ssse3_begin: pushl %ebp pushl %ebx pushl %esi pushl %edi -.Lssse3_shortcut: + call .Lpic_point +.Lpic_point: + popl %eax movl 20(%esp),%edi movl 24(%esp),%esi movl 28(%esp),%ecx @@ -404,7 +392,7 @@ ChaCha20_ssse3: leal .Lssse3_data-.Lpic_point(%eax),%eax movdqu (%ebx),%xmm3 cmpl $256,%ecx - jb .L0081x + jb .L0061x movl %edx,516(%esp) movl %ebx,520(%esp) subl $256,%ecx @@ -449,9 +437,9 @@ ChaCha20_ssse3: movdqa %xmm7,-80(%ebp) leal 128(%esi),%esi leal 128(%edi),%edi - jmp .L009outer_loop + jmp .L007outer_loop .align 16 -.L009outer_loop: +.L007outer_loop: movdqa -112(%ebp),%xmm1 movdqa -96(%ebp),%xmm2 movdqa -80(%ebp),%xmm3 @@ -486,7 +474,7 @@ ChaCha20_ssse3: movl $10,%edx nop .align 16 -.L010loop: +.L008loop: paddd %xmm3,%xmm0 movdqa %xmm3,%xmm2 pxor %xmm0,%xmm6 @@ -686,7 +674,7 @@ ChaCha20_ssse3: psrld $25,%xmm1 por %xmm1,%xmm3 decl %edx - jnz .L010loop + jnz .L008loop movdqa %xmm3,-64(%ebx) movdqa %xmm4,(%ebx) movdqa %xmm5,16(%ebx) @@ -828,9 +816,9 @@ ChaCha20_ssse3: movdqu %xmm7,64(%edi) leal 208(%edi),%edi subl $256,%ecx - jnc .L009outer_loop + jnc .L007outer_loop addl $256,%ecx - jz .L011done + jz .L009done movl 520(%esp),%ebx leal -128(%esi),%esi movl 516(%esp),%edx @@ -840,7 +828,7 @@ ChaCha20_ssse3: paddd 96(%eax),%xmm2 pand 112(%eax),%xmm3 por %xmm2,%xmm3 -.L0081x: +.L0061x: movdqa 32(%eax),%xmm0 movdqu (%edx),%xmm1 movdqu 16(%edx),%xmm2 @@ -852,9 +840,9 @@ ChaCha20_ssse3: movdqa %xmm2,32(%esp) movdqa %xmm3,48(%esp) movl $10,%edx - jmp .L012loop1x + jmp .L010loop1x .align 16 -.L013outer1x: +.L011outer1x: movdqa 80(%eax),%xmm3 movdqa (%esp),%xmm0 movdqa 16(%esp),%xmm1 @@ -862,9 +850,9 @@ ChaCha20_ssse3: paddd 48(%esp),%xmm3 movl $10,%edx movdqa %xmm3,48(%esp) - jmp .L012loop1x + jmp .L010loop1x .align 16 -.L012loop1x: +.L010loop1x: paddd %xmm1,%xmm0 pxor %xmm0,%xmm3 .byte 102,15,56,0,222 @@ -909,13 +897,13 @@ ChaCha20_ssse3: pshufd $147,%xmm1,%xmm1 pshufd $57,%xmm3,%xmm3 decl %edx - jnz .L012loop1x + jnz .L010loop1x paddd (%esp),%xmm0 paddd 16(%esp),%xmm1 paddd 32(%esp),%xmm2 paddd 48(%esp),%xmm3 cmpl $64,%ecx - jb .L014tail + jb .L012tail movdqu (%esi),%xmm4 movdqu 16(%esi),%xmm5 pxor %xmm4,%xmm0 @@ -931,9 +919,9 @@ ChaCha20_ssse3: movdqu %xmm3,48(%edi) leal 64(%edi),%edi subl $64,%ecx - jnz .L013outer1x - jmp .L011done -.L014tail: + jnz .L011outer1x + jmp .L009done +.L012tail: movdqa %xmm0,(%esp) movdqa %xmm1,16(%esp) movdqa %xmm2,32(%esp) @@ -941,22 +929,22 @@ ChaCha20_ssse3: xorl %eax,%eax xorl %edx,%edx xorl %ebp,%ebp -.L015tail_loop: +.L013tail_loop: movb (%esp,%ebp,1),%al movb (%esi,%ebp,1),%dl leal 1(%ebp),%ebp xorb %dl,%al movb %al,-1(%edi,%ebp,1) decl %ecx - jnz .L015tail_loop -.L011done: + jnz .L013tail_loop +.L009done: movl 512(%esp),%esp popl %edi popl %esi popl %ebx popl %ebp ret -.size ChaCha20_ssse3,.-.L_ChaCha20_ssse3_begin +.size ChaCha20_ctr32_ssse3,.-.L_ChaCha20_ctr32_ssse3_begin .align 64 .Lssse3_data: .byte 2,3,0,1,6,7,4,5,10,11,8,9,14,15,12,13 diff --git a/Sources/CCryptoBoringSSL/crypto/chacha/chacha-x86-windows.windows.x86.S b/Sources/CCryptoBoringSSL/crypto/chacha/chacha-x86-windows.windows.x86.S index 91409705..ef88da19 100644 --- a/Sources/CCryptoBoringSSL/crypto/chacha/chacha-x86-windows.windows.x86.S +++ b/Sources/CCryptoBoringSSL/crypto/chacha/chacha-x86-windows.windows.x86.S @@ -15,27 +15,14 @@ section .text code align=64 %else section .text code %endif -global _ChaCha20_ctr32 +global _ChaCha20_ctr32_nohw align 16 -_ChaCha20_ctr32: -L$_ChaCha20_ctr32_begin: +_ChaCha20_ctr32_nohw: +L$_ChaCha20_ctr32_nohw_begin: push ebp push ebx push esi push edi - xor eax,eax - cmp eax,DWORD [28+esp] - je NEAR L$000no_data - call L$pic_point -L$pic_point: - pop eax - lea ebp,[_OPENSSL_ia32cap_P] - test DWORD [ebp],16777216 - jz NEAR L$001x86 - test DWORD [4+ebp],512 - jz NEAR L$001x86 - jmp NEAR L$ssse3_shortcut -L$001x86: mov esi,DWORD [32+esp] mov edi,DWORD [36+esp] sub esp,132 @@ -64,13 +51,13 @@ L$001x86: mov DWORD [116+esp],ebx mov DWORD [120+esp],ecx mov DWORD [124+esp],edx - jmp NEAR L$002entry + jmp NEAR L$000entry align 16 -L$003outer_loop: +L$001outer_loop: mov DWORD [156+esp],ebx mov DWORD [152+esp],eax mov DWORD [160+esp],ecx -L$002entry: +L$000entry: mov eax,1634760805 mov DWORD [4+esp],857760878 mov DWORD [8+esp],2036477234 @@ -98,9 +85,9 @@ L$002entry: mov DWORD [60+esp],edi mov DWORD [112+esp],edx mov ebx,10 - jmp NEAR L$004loop + jmp NEAR L$002loop align 16 -L$004loop: +L$002loop: add eax,ebp mov DWORD [128+esp],ebx mov ebx,ebp @@ -254,14 +241,14 @@ L$004loop: xor ebp,esi rol ebp,7 dec ebx - jnz NEAR L$004loop + jnz NEAR L$002loop mov ebx,DWORD [160+esp] add eax,1634760805 add ebp,DWORD [80+esp] add ecx,DWORD [96+esp] add esi,DWORD [100+esp] cmp ebx,64 - jb NEAR L$005tail + jb NEAR L$003tail mov ebx,DWORD [156+esp] add edx,DWORD [112+esp] add edi,DWORD [120+esp] @@ -324,9 +311,9 @@ L$004loop: mov DWORD [eax],ebp lea eax,[64+eax] sub ecx,64 - jnz NEAR L$003outer_loop - jmp NEAR L$006done -L$005tail: + jnz NEAR L$001outer_loop + jmp NEAR L$004done +L$003tail: add edx,DWORD [112+esp] add edi,DWORD [120+esp] mov DWORD [esp],eax @@ -370,31 +357,32 @@ L$005tail: mov DWORD [60+esp],edi xor eax,eax xor edx,edx -L$007tail_loop: +L$005tail_loop: mov al,BYTE [ebp*1+esi] mov dl,BYTE [esi*1+esp] lea esi,[1+esi] xor al,dl mov BYTE [esi*1+ecx-1],al dec ebx - jnz NEAR L$007tail_loop -L$006done: + jnz NEAR L$005tail_loop +L$004done: add esp,132 -L$000no_data: pop edi pop esi pop ebx pop ebp ret -global _ChaCha20_ssse3 +global _ChaCha20_ctr32_ssse3 align 16 -_ChaCha20_ssse3: -L$_ChaCha20_ssse3_begin: +_ChaCha20_ctr32_ssse3: +L$_ChaCha20_ctr32_ssse3_begin: push ebp push ebx push esi push edi -L$ssse3_shortcut: + call L$pic_point +L$pic_point: + pop eax mov edi,DWORD [20+esp] mov esi,DWORD [24+esp] mov ecx,DWORD [28+esp] @@ -407,7 +395,7 @@ L$ssse3_shortcut: lea eax,[(L$ssse3_data-L$pic_point)+eax] movdqu xmm3,[ebx] cmp ecx,256 - jb NEAR L$0081x + jb NEAR L$0061x mov DWORD [516+esp],edx mov DWORD [520+esp],ebx sub ecx,256 @@ -452,9 +440,9 @@ L$ssse3_shortcut: movdqa [ebp-80],xmm7 lea esi,[128+esi] lea edi,[128+edi] - jmp NEAR L$009outer_loop + jmp NEAR L$007outer_loop align 16 -L$009outer_loop: +L$007outer_loop: movdqa xmm1,[ebp-112] movdqa xmm2,[ebp-96] movdqa xmm3,[ebp-80] @@ -489,7 +477,7 @@ L$009outer_loop: mov edx,10 nop align 16 -L$010loop: +L$008loop: paddd xmm0,xmm3 movdqa xmm2,xmm3 pxor xmm6,xmm0 @@ -689,7 +677,7 @@ L$010loop: psrld xmm1,25 por xmm3,xmm1 dec edx - jnz NEAR L$010loop + jnz NEAR L$008loop movdqa [ebx-64],xmm3 movdqa [ebx],xmm4 movdqa [16+ebx],xmm5 @@ -831,9 +819,9 @@ L$010loop: movdqu [64+edi],xmm7 lea edi,[208+edi] sub ecx,256 - jnc NEAR L$009outer_loop + jnc NEAR L$007outer_loop add ecx,256 - jz NEAR L$011done + jz NEAR L$009done mov ebx,DWORD [520+esp] lea esi,[esi-128] mov edx,DWORD [516+esp] @@ -843,7 +831,7 @@ L$010loop: paddd xmm2,[96+eax] pand xmm3,[112+eax] por xmm3,xmm2 -L$0081x: +L$0061x: movdqa xmm0,[32+eax] movdqu xmm1,[edx] movdqu xmm2,[16+edx] @@ -855,9 +843,9 @@ L$0081x: movdqa [32+esp],xmm2 movdqa [48+esp],xmm3 mov edx,10 - jmp NEAR L$012loop1x + jmp NEAR L$010loop1x align 16 -L$013outer1x: +L$011outer1x: movdqa xmm3,[80+eax] movdqa xmm0,[esp] movdqa xmm1,[16+esp] @@ -865,9 +853,9 @@ L$013outer1x: paddd xmm3,[48+esp] mov edx,10 movdqa [48+esp],xmm3 - jmp NEAR L$012loop1x + jmp NEAR L$010loop1x align 16 -L$012loop1x: +L$010loop1x: paddd xmm0,xmm1 pxor xmm3,xmm0 db 102,15,56,0,222 @@ -912,13 +900,13 @@ db 102,15,56,0,223 pshufd xmm1,xmm1,147 pshufd xmm3,xmm3,57 dec edx - jnz NEAR L$012loop1x + jnz NEAR L$010loop1x paddd xmm0,[esp] paddd xmm1,[16+esp] paddd xmm2,[32+esp] paddd xmm3,[48+esp] cmp ecx,64 - jb NEAR L$014tail + jb NEAR L$012tail movdqu xmm4,[esi] movdqu xmm5,[16+esi] pxor xmm0,xmm4 @@ -934,9 +922,9 @@ db 102,15,56,0,223 movdqu [48+edi],xmm3 lea edi,[64+edi] sub ecx,64 - jnz NEAR L$013outer1x - jmp NEAR L$011done -L$014tail: + jnz NEAR L$011outer1x + jmp NEAR L$009done +L$012tail: movdqa [esp],xmm0 movdqa [16+esp],xmm1 movdqa [32+esp],xmm2 @@ -944,15 +932,15 @@ L$014tail: xor eax,eax xor edx,edx xor ebp,ebp -L$015tail_loop: +L$013tail_loop: mov al,BYTE [ebp*1+esp] mov dl,BYTE [ebp*1+esi] lea ebp,[1+ebp] xor al,dl mov BYTE [ebp*1+edi-1],al dec ecx - jnz NEAR L$015tail_loop -L$011done: + jnz NEAR L$013tail_loop +L$009done: mov esp,DWORD [512+esp] pop edi pop esi @@ -974,8 +962,6 @@ db 67,104,97,67,104,97,50,48,32,102,111,114,32,120,56,54 db 44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32 db 60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111 db 114,103,62,0 -segment .bss -common _OPENSSL_ia32cap_P 16 %else ; Work around https://bugzilla.nasm.us/show_bug.cgi?id=3392738 ret diff --git a/Sources/CCryptoBoringSSL/crypto/chacha/chacha-x86_64-linux.linux.x86_64.S b/Sources/CCryptoBoringSSL/crypto/chacha/chacha-x86_64-linux.linux.x86_64.S index 4e1c1d84..7a4759c5 100644 --- a/Sources/CCryptoBoringSSL/crypto/chacha/chacha-x86_64-linux.linux.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/chacha/chacha-x86_64-linux.linux.x86_64.S @@ -8,9 +8,6 @@ #if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64) && defined(__ELF__) .text -.extern OPENSSL_ia32cap_P -.hidden OPENSSL_ia32cap_P - .section .rodata .align 64 .Lzero: @@ -42,19 +39,13 @@ .long 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16 .byte 67,104,97,67,104,97,50,48,32,102,111,114,32,120,56,54,95,54,52,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 .text -.globl ChaCha20_ctr32 -.hidden ChaCha20_ctr32 -.type ChaCha20_ctr32,@function +.globl ChaCha20_ctr32_nohw +.hidden ChaCha20_ctr32_nohw +.type ChaCha20_ctr32_nohw,@function .align 64 -ChaCha20_ctr32: +ChaCha20_ctr32_nohw: .cfi_startproc _CET_ENDBR - cmpq $0,%rdx - je .Lno_data - movq OPENSSL_ia32cap_P+4(%rip),%r10 - testl $512,%r10d - jnz .LChaCha20_ssse3 - pushq %rbx .cfi_adjust_cfa_offset 8 .cfi_offset rbx,-16 @@ -331,18 +322,16 @@ _CET_ENDBR .Lno_data: ret .cfi_endproc -.size ChaCha20_ctr32,.-ChaCha20_ctr32 -.type ChaCha20_ssse3,@function +.size ChaCha20_ctr32_nohw,.-ChaCha20_ctr32_nohw +.globl ChaCha20_ctr32_ssse3 +.hidden ChaCha20_ctr32_ssse3 +.type ChaCha20_ctr32_ssse3,@function .align 32 -ChaCha20_ssse3: -.LChaCha20_ssse3: +ChaCha20_ctr32_ssse3: .cfi_startproc +_CET_ENDBR movq %rsp,%r9 .cfi_def_cfa_register r9 - cmpq $128,%rdx - ja .LChaCha20_4x - -.Ldo_sse3_after_all: subq $64+8,%rsp movdqa .Lsigma(%rip),%xmm0 movdqu (%rcx),%xmm1 @@ -468,26 +457,17 @@ ChaCha20_ssse3: .Lssse3_epilogue: ret .cfi_endproc -.size ChaCha20_ssse3,.-ChaCha20_ssse3 -.type ChaCha20_4x,@function +.size ChaCha20_ctr32_ssse3,.-ChaCha20_ctr32_ssse3 +.globl ChaCha20_ctr32_ssse3_4x +.hidden ChaCha20_ctr32_ssse3_4x +.type ChaCha20_ctr32_ssse3_4x,@function .align 32 -ChaCha20_4x: -.LChaCha20_4x: +ChaCha20_ctr32_ssse3_4x: .cfi_startproc +_CET_ENDBR movq %rsp,%r9 .cfi_def_cfa_register r9 movq %r10,%r11 - shrq $32,%r10 - testq $32,%r10 - jnz .LChaCha20_8x - cmpq $192,%rdx - ja .Lproceed4x - - andq $71303168,%r11 - cmpq $4194304,%r11 - je .Ldo_sse3_after_all - -.Lproceed4x: subq $0x140+8,%rsp movdqa .Lsigma(%rip),%xmm11 movdqu (%rcx),%xmm15 @@ -1020,12 +1000,14 @@ ChaCha20_4x: .L4x_epilogue: ret .cfi_endproc -.size ChaCha20_4x,.-ChaCha20_4x -.type ChaCha20_8x,@function +.size ChaCha20_ctr32_ssse3_4x,.-ChaCha20_ctr32_ssse3_4x +.globl ChaCha20_ctr32_avx2 +.hidden ChaCha20_ctr32_avx2 +.type ChaCha20_ctr32_avx2,@function .align 32 -ChaCha20_8x: -.LChaCha20_8x: +ChaCha20_ctr32_avx2: .cfi_startproc +_CET_ENDBR movq %rsp,%r9 .cfi_def_cfa_register r9 subq $0x280+8,%rsp @@ -1626,7 +1608,7 @@ ChaCha20_8x: .L8x_epilogue: ret .cfi_endproc -.size ChaCha20_8x,.-ChaCha20_8x +.size ChaCha20_ctr32_avx2,.-ChaCha20_ctr32_avx2 #endif #endif // defined(__x86_64__) && defined(__linux__) #if defined(__linux__) && defined(__ELF__) diff --git a/Sources/CCryptoBoringSSL/crypto/chacha/chacha-x86_64-mac.mac.x86_64.S b/Sources/CCryptoBoringSSL/crypto/chacha/chacha-x86_64-mac.mac.x86_64.S index cca4b5f8..6a51e976 100644 --- a/Sources/CCryptoBoringSSL/crypto/chacha/chacha-x86_64-mac.mac.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/chacha/chacha-x86_64-mac.mac.x86_64.S @@ -8,8 +8,6 @@ #if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64) && defined(__APPLE__) .text - - .section __DATA,__const .p2align 6 L$zero: @@ -41,19 +39,13 @@ L$sixteen: .long 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16 .byte 67,104,97,67,104,97,50,48,32,102,111,114,32,120,56,54,95,54,52,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 .text -.globl _ChaCha20_ctr32 -.private_extern _ChaCha20_ctr32 +.globl _ChaCha20_ctr32_nohw +.private_extern _ChaCha20_ctr32_nohw .p2align 6 -_ChaCha20_ctr32: +_ChaCha20_ctr32_nohw: _CET_ENDBR - cmpq $0,%rdx - je L$no_data - movq _OPENSSL_ia32cap_P+4(%rip),%r10 - testl $512,%r10d - jnz L$ChaCha20_ssse3 - pushq %rbx pushq %rbp @@ -325,17 +317,15 @@ L$no_data: ret +.globl _ChaCha20_ctr32_ssse3 +.private_extern _ChaCha20_ctr32_ssse3 .p2align 5 -ChaCha20_ssse3: -L$ChaCha20_ssse3: +_ChaCha20_ctr32_ssse3: +_CET_ENDBR movq %rsp,%r9 - cmpq $128,%rdx - ja L$ChaCha20_4x - -L$do_sse3_after_all: subq $64+8,%rsp movdqa L$sigma(%rip),%xmm0 movdqu (%rcx),%xmm1 @@ -462,25 +452,16 @@ L$ssse3_epilogue: ret +.globl _ChaCha20_ctr32_ssse3_4x +.private_extern _ChaCha20_ctr32_ssse3_4x .p2align 5 -ChaCha20_4x: -L$ChaCha20_4x: +_ChaCha20_ctr32_ssse3_4x: +_CET_ENDBR movq %rsp,%r9 movq %r10,%r11 - shrq $32,%r10 - testq $32,%r10 - jnz L$ChaCha20_8x - cmpq $192,%rdx - ja L$proceed4x - - andq $71303168,%r11 - cmpq $4194304,%r11 - je L$do_sse3_after_all - -L$proceed4x: subq $0x140+8,%rsp movdqa L$sigma(%rip),%xmm11 movdqu (%rcx),%xmm15 @@ -1014,11 +995,13 @@ L$4x_epilogue: ret +.globl _ChaCha20_ctr32_avx2 +.private_extern _ChaCha20_ctr32_avx2 .p2align 5 -ChaCha20_8x: -L$ChaCha20_8x: +_ChaCha20_ctr32_avx2: +_CET_ENDBR movq %rsp,%r9 subq $0x280+8,%rsp diff --git a/Sources/CCryptoBoringSSL/crypto/chacha/chacha.c b/Sources/CCryptoBoringSSL/crypto/chacha/chacha.c index b559e3a2..f60b91b1 100644 --- a/Sources/CCryptoBoringSSL/crypto/chacha/chacha.c +++ b/Sources/CCryptoBoringSSL/crypto/chacha/chacha.c @@ -68,6 +68,24 @@ static void ChaCha20_ctr32(uint8_t *out, const uint8_t *in, size_t in_len, ChaCha20_ctr32_neon(out, in, in_len, key, counter); return; } +#endif +#if defined(CHACHA20_ASM_AVX2) + if (ChaCha20_ctr32_avx2_capable(in_len)) { + ChaCha20_ctr32_avx2(out, in, in_len, key, counter); + return; + } +#endif +#if defined(CHACHA20_ASM_SSSE3_4X) + if (ChaCha20_ctr32_ssse3_4x_capable(in_len)) { + ChaCha20_ctr32_ssse3_4x(out, in, in_len, key, counter); + return; + } +#endif +#if defined(CHACHA20_ASM_SSSE3) + if (ChaCha20_ctr32_ssse3_capable(in_len)) { + ChaCha20_ctr32_ssse3(out, in, in_len, key, counter); + return; + } #endif if (in_len > 0) { ChaCha20_ctr32_nohw(out, in, in_len, key, counter); @@ -75,7 +93,7 @@ static void ChaCha20_ctr32(uint8_t *out, const uint8_t *in, size_t in_len, } #endif -#if defined(CHACHA20_ASM) || defined(CHACHA20_ASM_NOHW) +#if defined(CHACHA20_ASM_NOHW) void CRYPTO_chacha_20(uint8_t *out, const uint8_t *in, size_t in_len, const uint8_t key[32], const uint8_t nonce[12], diff --git a/Sources/CCryptoBoringSSL/crypto/chacha/internal.h b/Sources/CCryptoBoringSSL/crypto/chacha/internal.h index e490cf3f..e5626474 100644 --- a/Sources/CCryptoBoringSSL/crypto/chacha/internal.h +++ b/Sources/CCryptoBoringSSL/crypto/chacha/internal.h @@ -29,10 +29,18 @@ extern "C" { void CRYPTO_hchacha20(uint8_t out[32], const uint8_t key[32], const uint8_t nonce[16]); -#if !defined(OPENSSL_NO_ASM) && \ - (defined(OPENSSL_X86) || defined(OPENSSL_X86_64)) +#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86) -#define CHACHA20_ASM +#define CHACHA20_ASM_NOHW + +#define CHACHA20_ASM_SSSE3 +OPENSSL_INLINE int ChaCha20_ctr32_ssse3_capable(size_t len) { + // Unlike the x86_64 version, the x86 SSSE3 routine runs for all non-zero + // lengths. + return len > 0 && CRYPTO_is_SSSE3_capable() && CRYPTO_is_FXSR_capable(); +} +void ChaCha20_ctr32_ssse3(uint8_t *out, const uint8_t *in, size_t in_len, + const uint32_t key[8], const uint32_t counter[4]); #elif !defined(OPENSSL_NO_ASM) && \ (defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)) @@ -41,27 +49,47 @@ void CRYPTO_hchacha20(uint8_t out[32], const uint8_t key[32], #define CHACHA20_ASM_NEON OPENSSL_INLINE int ChaCha20_ctr32_neon_capable(size_t len) { - return (len >= 192) && CRYPTO_is_NEON_capable(); + return len >= 192 && CRYPTO_is_NEON_capable(); } void ChaCha20_ctr32_neon(uint8_t *out, const uint8_t *in, size_t in_len, const uint32_t key[8], const uint32_t counter[4]); +#elif !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64) +#define CHACHA20_ASM_NOHW + +#define CHACHA20_ASM_AVX2 +OPENSSL_INLINE int ChaCha20_ctr32_avx2_capable(size_t len) { + return len > 128 && CRYPTO_is_AVX2_capable(); +} +void ChaCha20_ctr32_avx2(uint8_t *out, const uint8_t *in, size_t in_len, + const uint32_t key[8], const uint32_t counter[4]); + +#define CHACHA20_ASM_SSSE3_4X +OPENSSL_INLINE int ChaCha20_ctr32_ssse3_4x_capable(size_t len) { + int capable = len > 128 && CRYPTO_is_SSSE3_capable(); + int faster = len > 192 || !CRYPTO_cpu_perf_is_like_silvermont(); + return capable && faster; +} +void ChaCha20_ctr32_ssse3_4x(uint8_t *out, const uint8_t *in, size_t in_len, + const uint32_t key[8], const uint32_t counter[4]); + +#define CHACHA20_ASM_SSSE3 +OPENSSL_INLINE int ChaCha20_ctr32_ssse3_capable(size_t len) { + return len > 128 && CRYPTO_is_SSSE3_capable(); +} +void ChaCha20_ctr32_ssse3(uint8_t *out, const uint8_t *in, size_t in_len, + const uint32_t key[8], const uint32_t counter[4]); #endif -#if defined(CHACHA20_ASM) -// ChaCha20_ctr32 encrypts |in_len| bytes from |in| and writes the result to -// |out|. If |in| and |out| alias, they must be equal. +#if defined(CHACHA20_ASM_NOHW) +// ChaCha20_ctr32_nohw encrypts |in_len| bytes from |in| and writes the result +// to |out|. If |in| and |out| alias, they must be equal. |in_len| may not be +// zero. // // |counter[0]| is the initial 32-bit block counter, and the remainder is the // 96-bit nonce. If the counter overflows, the output is undefined. The function // will produce output, but the output may vary by machine and may not be // self-consistent. (On some architectures, the assembly implements a mix of // 64-bit and 32-bit counters.) -void ChaCha20_ctr32(uint8_t *out, const uint8_t *in, size_t in_len, - const uint32_t key[8], const uint32_t counter[4]); -#endif - -#if defined(CHACHA20_ASM_NOHW) -// ChaCha20_ctr32_nohw is like |ChaCha20_ctr32| except |in_len| must be nonzero. void ChaCha20_ctr32_nohw(uint8_t *out, const uint8_t *in, size_t in_len, const uint32_t key[8], const uint32_t counter[4]); #endif diff --git a/Sources/CCryptoBoringSSL/crypto/cipher_extra/aes128gcmsiv-x86_64-linux.linux.x86_64.S b/Sources/CCryptoBoringSSL/crypto/cipher_extra/aes128gcmsiv-x86_64-linux.linux.x86_64.S index 1e95ef34..67d9f8ab 100644 --- a/Sources/CCryptoBoringSSL/crypto/cipher_extra/aes128gcmsiv-x86_64-linux.linux.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/cipher_extra/aes128gcmsiv-x86_64-linux.linux.x86_64.S @@ -1167,14 +1167,15 @@ _CET_ENDBR .L128_dec_start: vzeroupper vmovdqa (%rdx),%xmm0 + + + vmovdqu 16(%rdx),%xmm15 + vpor OR_MASK(%rip),%xmm15,%xmm15 movq %rdx,%rax leaq 32(%rax),%rax leaq 32(%rcx),%rcx - - vmovdqu (%rdi,%r9,1),%xmm15 - vpor OR_MASK(%rip),%xmm15,%xmm15 andq $~15,%r9 @@ -2389,14 +2390,15 @@ _CET_ENDBR .L256_dec_start: vzeroupper vmovdqa (%rdx),%xmm0 + + + vmovdqu 16(%rdx),%xmm15 + vpor OR_MASK(%rip),%xmm15,%xmm15 movq %rdx,%rax leaq 32(%rax),%rax leaq 32(%rcx),%rcx - - vmovdqu (%rdi,%r9,1),%xmm15 - vpor OR_MASK(%rip),%xmm15,%xmm15 andq $~15,%r9 diff --git a/Sources/CCryptoBoringSSL/crypto/cipher_extra/aes128gcmsiv-x86_64-mac.mac.x86_64.S b/Sources/CCryptoBoringSSL/crypto/cipher_extra/aes128gcmsiv-x86_64-mac.mac.x86_64.S index 50c64477..9b474516 100644 --- a/Sources/CCryptoBoringSSL/crypto/cipher_extra/aes128gcmsiv-x86_64-mac.mac.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/cipher_extra/aes128gcmsiv-x86_64-mac.mac.x86_64.S @@ -1157,14 +1157,15 @@ _CET_ENDBR L$128_dec_start: vzeroupper vmovdqa (%rdx),%xmm0 + + + vmovdqu 16(%rdx),%xmm15 + vpor OR_MASK(%rip),%xmm15,%xmm15 movq %rdx,%rax leaq 32(%rax),%rax leaq 32(%rcx),%rcx - - vmovdqu (%rdi,%r9,1),%xmm15 - vpor OR_MASK(%rip),%xmm15,%xmm15 andq $~15,%r9 @@ -2379,14 +2380,15 @@ _CET_ENDBR L$256_dec_start: vzeroupper vmovdqa (%rdx),%xmm0 + + + vmovdqu 16(%rdx),%xmm15 + vpor OR_MASK(%rip),%xmm15,%xmm15 movq %rdx,%rax leaq 32(%rax),%rax leaq 32(%rcx),%rcx - - vmovdqu (%rdi,%r9,1),%xmm15 - vpor OR_MASK(%rip),%xmm15,%xmm15 andq $~15,%r9 diff --git a/Sources/CCryptoBoringSSL/crypto/cipher_extra/e_aesgcmsiv.c b/Sources/CCryptoBoringSSL/crypto/cipher_extra/e_aesgcmsiv.c index 30b12349..63f2d710 100644 --- a/Sources/CCryptoBoringSSL/crypto/cipher_extra/e_aesgcmsiv.c +++ b/Sources/CCryptoBoringSSL/crypto/cipher_extra/e_aesgcmsiv.c @@ -126,16 +126,16 @@ extern void aesgcmsiv_htable_polyval(const uint8_t htable[16 * 8], uint8_t in_out_poly[16]); // aes128gcmsiv_dec decrypts |in_len| & ~15 bytes from |out| and writes them to -// |in|. (The full value of |in_len| is still used to find the authentication -// tag appended to the ciphertext, however, so must not be pre-masked.) +// |in|. |in| and |out| may be equal, but must not otherwise alias. // -// |in| and |out| may be equal, but must not otherwise overlap. +// |in_out_calculated_tag_and_scratch|, on entry, must contain: +// 1. The current value of the calculated tag, which will be updated during +// decryption and written back to the beginning of this buffer on exit. +// 2. The claimed tag, which is needed to derive counter values. // -// While decrypting, it updates the POLYVAL value found at the beginning of -// |in_out_calculated_tag_and_scratch| and writes the updated value back before -// return. During executation, it may use the whole of this space for other -// purposes. In order to decrypt and update the POLYVAL value, it uses the -// expanded key from |key| and the table of powers in |htable|. +// While decrypting, the whole of |in_out_calculated_tag_and_scratch| may be +// used for other purposes. In order to decrypt and update the POLYVAL value, it +// uses the expanded key from |key| and the table of powers in |htable|. extern void aes128gcmsiv_dec(const uint8_t *in, uint8_t *out, uint8_t in_out_calculated_tag_and_scratch[16 * 8], const uint8_t htable[16 * 6], @@ -393,14 +393,10 @@ static int aead_aes_gcm_siv_asm_seal_scatter( return 1; } -// TODO(martinkr): Add aead_aes_gcm_siv_asm_open_gather. N.B. aes128gcmsiv_dec -// expects ciphertext and tag in a contiguous buffer. - -static int aead_aes_gcm_siv_asm_open(const EVP_AEAD_CTX *ctx, uint8_t *out, - size_t *out_len, size_t max_out_len, - const uint8_t *nonce, size_t nonce_len, - const uint8_t *in, size_t in_len, - const uint8_t *ad, size_t ad_len) { +static int aead_aes_gcm_siv_asm_open_gather( + const EVP_AEAD_CTX *ctx, uint8_t *out, const uint8_t *nonce, + size_t nonce_len, const uint8_t *in, size_t in_len, const uint8_t *in_tag, + size_t in_tag_len, const uint8_t *ad, size_t ad_len) { const uint64_t ad_len_64 = ad_len; if (ad_len_64 >= (UINT64_C(1) << 61)) { OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_TOO_LARGE); @@ -408,8 +404,8 @@ static int aead_aes_gcm_siv_asm_open(const EVP_AEAD_CTX *ctx, uint8_t *out, } const uint64_t in_len_64 = in_len; - if (in_len < EVP_AEAD_AES_GCM_SIV_TAG_LEN || - in_len_64 > (UINT64_C(1) << 36) + AES_BLOCK_SIZE) { + if (in_len_64 > UINT64_C(1) << 36 || + in_tag_len != EVP_AEAD_AES_GCM_SIV_TAG_LEN) { OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_BAD_DECRYPT); return 0; } @@ -420,13 +416,6 @@ static int aead_aes_gcm_siv_asm_open(const EVP_AEAD_CTX *ctx, uint8_t *out, } const struct aead_aes_gcm_siv_asm_ctx *gcm_siv_ctx = asm_ctx_from_ctx(ctx); - const size_t plaintext_len = in_len - EVP_AEAD_AES_GCM_SIV_TAG_LEN; - const uint8_t *const given_tag = in + plaintext_len; - - if (max_out_len < plaintext_len) { - OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_BUFFER_TOO_SMALL); - return 0; - } alignas(16) uint64_t record_auth_key[2]; alignas(16) uint64_t record_enc_key[4]; @@ -459,27 +448,27 @@ static int aead_aes_gcm_siv_asm_open(const EVP_AEAD_CTX *ctx, uint8_t *out, alignas(16) uint8_t htable[16 * 6]; aesgcmsiv_htable6_init(htable, (const uint8_t *)record_auth_key); + // aes[128|256]gcmsiv_dec needs access to the claimed tag. So it's put into + // its scratch space. + memcpy(calculated_tag + 16, in_tag, EVP_AEAD_AES_GCM_SIV_TAG_LEN); if (gcm_siv_ctx->is_128_bit) { - aes128gcmsiv_dec(in, out, calculated_tag, htable, &expanded_key, - plaintext_len); + aes128gcmsiv_dec(in, out, calculated_tag, htable, &expanded_key, in_len); } else { - aes256gcmsiv_dec(in, out, calculated_tag, htable, &expanded_key, - plaintext_len); + aes256gcmsiv_dec(in, out, calculated_tag, htable, &expanded_key, in_len); } - if (plaintext_len & 15) { + if (in_len & 15) { aead_aes_gcm_siv_asm_crypt_last_block(gcm_siv_ctx->is_128_bit, out, in, - plaintext_len, given_tag, - &expanded_key); + in_len, in_tag, &expanded_key); OPENSSL_memset(scratch, 0, sizeof(scratch)); - OPENSSL_memcpy(scratch, out + (plaintext_len & ~15), plaintext_len & 15); + OPENSSL_memcpy(scratch, out + (in_len & ~15), in_len & 15); aesgcmsiv_polyval_horner(calculated_tag, (const uint8_t *)record_auth_key, scratch, 1); } uint8_t length_block[16]; CRYPTO_store_u64_le(length_block, ad_len * 8); - CRYPTO_store_u64_le(length_block + 8, plaintext_len * 8); + CRYPTO_store_u64_le(length_block + 8, in_len * 8); aesgcmsiv_polyval_horner(calculated_tag, (const uint8_t *)record_auth_key, length_block, 1); @@ -495,13 +484,12 @@ static int aead_aes_gcm_siv_asm_open(const EVP_AEAD_CTX *ctx, uint8_t *out, aes256gcmsiv_ecb_enc_block(calculated_tag, calculated_tag, &expanded_key); } - if (CRYPTO_memcmp(calculated_tag, given_tag, EVP_AEAD_AES_GCM_SIV_TAG_LEN) != + if (CRYPTO_memcmp(calculated_tag, in_tag, EVP_AEAD_AES_GCM_SIV_TAG_LEN) != 0) { OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_BAD_DECRYPT); return 0; } - *out_len = in_len - EVP_AEAD_AES_GCM_SIV_TAG_LEN; return 1; } @@ -515,9 +503,9 @@ static const EVP_AEAD aead_aes_128_gcm_siv_asm = { aead_aes_gcm_siv_asm_init, NULL /* init_with_direction */, aead_aes_gcm_siv_asm_cleanup, - aead_aes_gcm_siv_asm_open, + NULL /* open */, aead_aes_gcm_siv_asm_seal_scatter, - NULL /* open_gather */, + aead_aes_gcm_siv_asm_open_gather, NULL /* get_iv */, NULL /* tag_len */, }; @@ -532,9 +520,9 @@ static const EVP_AEAD aead_aes_256_gcm_siv_asm = { aead_aes_gcm_siv_asm_init, NULL /* init_with_direction */, aead_aes_gcm_siv_asm_cleanup, - aead_aes_gcm_siv_asm_open, + NULL /* open */, aead_aes_gcm_siv_asm_seal_scatter, - NULL /* open_gather */, + aead_aes_gcm_siv_asm_open_gather, NULL /* get_iv */, NULL /* tag_len */, }; @@ -647,8 +635,8 @@ static void gcm_siv_polyval( } uint8_t length_block[16]; - CRYPTO_store_u64_le(length_block, ad_len * 8); - CRYPTO_store_u64_le(length_block + 8, in_len * 8); + CRYPTO_store_u64_le(length_block, ((uint64_t) ad_len) * 8); + CRYPTO_store_u64_le(length_block + 8, ((uint64_t) in_len) * 8); CRYPTO_POLYVAL_update_blocks(&polyval_ctx, length_block, sizeof(length_block)); diff --git a/Sources/CCryptoBoringSSL/crypto/cipher_extra/e_des.c b/Sources/CCryptoBoringSSL/crypto/cipher_extra/e_des.c index 2ad0a9b8..3fabb19a 100644 --- a/Sources/CCryptoBoringSSL/crypto/cipher_extra/e_des.c +++ b/Sources/CCryptoBoringSSL/crypto/cipher_extra/e_des.c @@ -58,6 +58,7 @@ #include #include +#include "../des/internal.h" #include "../fipsmodule/cipher/internal.h" #include "internal.h" @@ -71,20 +72,15 @@ typedef struct { static int des_init_key(EVP_CIPHER_CTX *ctx, const uint8_t *key, const uint8_t *iv, int enc) { - DES_cblock *deskey = (DES_cblock *)key; EVP_DES_KEY *dat = (EVP_DES_KEY *)ctx->cipher_data; - - DES_set_key(deskey, &dat->ks.ks); + DES_set_key_ex(key, &dat->ks.ks); return 1; } static int des_cbc_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in, size_t in_len) { EVP_DES_KEY *dat = (EVP_DES_KEY *)ctx->cipher_data; - - DES_ncbc_encrypt(in, out, in_len, &dat->ks.ks, (DES_cblock *)ctx->iv, - ctx->encrypt); - + DES_ncbc_encrypt_ex(in, out, in_len, &dat->ks.ks, ctx->iv, ctx->encrypt); return 1; } @@ -113,8 +109,7 @@ static int des_ecb_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in, EVP_DES_KEY *dat = (EVP_DES_KEY *)ctx->cipher_data; for (size_t i = 0; i <= in_len; i += ctx->cipher->block_size) { - DES_ecb_encrypt((DES_cblock *)(in + i), (DES_cblock *)(out + i), - &dat->ks.ks, ctx->encrypt); + DES_ecb_encrypt_ex(in + i, out + i, &dat->ks.ks, ctx->encrypt); } return 1; } @@ -144,23 +139,18 @@ typedef struct { static int des_ede3_init_key(EVP_CIPHER_CTX *ctx, const uint8_t *key, const uint8_t *iv, int enc) { - DES_cblock *deskey = (DES_cblock *)key; DES_EDE_KEY *dat = (DES_EDE_KEY *)ctx->cipher_data; - - DES_set_key(&deskey[0], &dat->ks.ks[0]); - DES_set_key(&deskey[1], &dat->ks.ks[1]); - DES_set_key(&deskey[2], &dat->ks.ks[2]); - + DES_set_key_ex(key, &dat->ks.ks[0]); + DES_set_key_ex(key + 8, &dat->ks.ks[1]); + DES_set_key_ex(key + 16, &dat->ks.ks[2]); return 1; } static int des_ede3_cbc_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in, size_t in_len) { DES_EDE_KEY *dat = (DES_EDE_KEY *)ctx->cipher_data; - - DES_ede3_cbc_encrypt(in, out, in_len, &dat->ks.ks[0], &dat->ks.ks[1], - &dat->ks.ks[2], (DES_cblock *)ctx->iv, ctx->encrypt); - + DES_ede3_cbc_encrypt_ex(in, out, in_len, &dat->ks.ks[0], &dat->ks.ks[1], + &dat->ks.ks[2], ctx->iv, ctx->encrypt); return 1; } @@ -182,13 +172,11 @@ const EVP_CIPHER *EVP_des_ede3_cbc(void) { return &evp_des_ede3_cbc; } static int des_ede_init_key(EVP_CIPHER_CTX *ctx, const uint8_t *key, const uint8_t *iv, int enc) { - DES_cblock *deskey = (DES_cblock *)key; DES_EDE_KEY *dat = (DES_EDE_KEY *)ctx->cipher_data; - - DES_set_key(&deskey[0], &dat->ks.ks[0]); - DES_set_key(&deskey[1], &dat->ks.ks[1]); - DES_set_key(&deskey[0], &dat->ks.ks[2]); - + // 2-DES is 3-DES with the first key used twice. + DES_set_key_ex(key, &dat->ks.ks[0]); + DES_set_key_ex(key + 8, &dat->ks.ks[1]); + DES_set_key_ex(key, &dat->ks.ks[2]); return 1; } @@ -217,9 +205,8 @@ static int des_ede_ecb_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, DES_EDE_KEY *dat = (DES_EDE_KEY *) ctx->cipher_data; for (size_t i = 0; i <= in_len; i += ctx->cipher->block_size) { - DES_ecb3_encrypt((DES_cblock *) (in + i), (DES_cblock *) (out + i), - &dat->ks.ks[0], &dat->ks.ks[1], &dat->ks.ks[2], - ctx->encrypt); + DES_ecb3_encrypt_ex(in + i, out + i, &dat->ks.ks[0], &dat->ks.ks[1], + &dat->ks.ks[2], ctx->encrypt); } return 1; } diff --git a/Sources/CCryptoBoringSSL/crypto/conf/conf.c b/Sources/CCryptoBoringSSL/crypto/conf/conf.c index cd010151..4b1b6fbe 100644 --- a/Sources/CCryptoBoringSSL/crypto/conf/conf.c +++ b/Sources/CCryptoBoringSSL/crypto/conf/conf.c @@ -70,48 +70,51 @@ #include "../internal.h" +struct conf_section_st { + char *name; + // values contains non-owning pointers to the values in the section. + STACK_OF(CONF_VALUE) *values; +}; + static const char kDefaultSectionName[] = "default"; +static uint32_t conf_section_hash(const CONF_SECTION *s) { + return OPENSSL_strhash(s->name); +} + +static int conf_section_cmp(const CONF_SECTION *a, const CONF_SECTION *b) { + return strcmp(a->name, b->name); +} + static uint32_t conf_value_hash(const CONF_VALUE *v) { - const uint32_t section_hash = v->section ? OPENSSL_strhash(v->section) : 0; - const uint32_t name_hash = v->name ? OPENSSL_strhash(v->name) : 0; + const uint32_t section_hash = OPENSSL_strhash(v->section); + const uint32_t name_hash = OPENSSL_strhash(v->name); return (section_hash << 2) ^ name_hash; } static int conf_value_cmp(const CONF_VALUE *a, const CONF_VALUE *b) { - int i; - - if (a->section != b->section) { - i = strcmp(a->section, b->section); - if (i) { - return i; - } + int cmp = strcmp(a->section, b->section); + if (cmp != 0) { + return cmp; } - if (a->name != NULL && b->name != NULL) { - return strcmp(a->name, b->name); - } else if (a->name == b->name) { - return 0; - } else { - return (a->name == NULL) ? -1 : 1; - } + return strcmp(a->name, b->name); } CONF *NCONF_new(void *method) { - CONF *conf; - if (method != NULL) { return NULL; } - conf = OPENSSL_malloc(sizeof(CONF)); + CONF *conf = OPENSSL_malloc(sizeof(CONF)); if (conf == NULL) { return NULL; } - conf->data = lh_CONF_VALUE_new(conf_value_hash, conf_value_cmp); - if (conf->data == NULL) { - OPENSSL_free(conf); + conf->sections = lh_CONF_SECTION_new(conf_section_hash, conf_section_cmp); + conf->values = lh_CONF_VALUE_new(conf_value_hash, conf_value_cmp); + if (conf->sections == NULL || conf->values == NULL) { + NCONF_free(conf); return NULL; } @@ -120,69 +123,64 @@ CONF *NCONF_new(void *method) { CONF_VALUE *CONF_VALUE_new(void) { return OPENSSL_zalloc(sizeof(CONF_VALUE)); } -static void value_free_contents(CONF_VALUE *value) { - OPENSSL_free(value->section); - if (value->name) { - OPENSSL_free(value->name); - OPENSSL_free(value->value); - } else { - // TODO(davidben): When |value->name| is NULL, |CONF_VALUE| is actually an - // entirely different structure. This is fragile and confusing. Make a - // proper |CONF_SECTION| type that doesn't require this. - sk_CONF_VALUE_free((STACK_OF(CONF_VALUE) *)value->value); +static void value_free(CONF_VALUE *value) { + if (value == NULL) { + return; } + OPENSSL_free(value->section); + OPENSSL_free(value->name); + OPENSSL_free(value->value); + OPENSSL_free(value); } -static void value_free(CONF_VALUE *value) { - if (value != NULL) { - value_free_contents(value); - OPENSSL_free(value); +static void section_free(CONF_SECTION *section) { + if (section == NULL) { + return; } + OPENSSL_free(section->name); + sk_CONF_VALUE_free(section->values); + OPENSSL_free(section); } static void value_free_arg(CONF_VALUE *value, void *arg) { value_free(value); } +static void section_free_arg(CONF_SECTION *section, void *arg) { + section_free(section); +} + void NCONF_free(CONF *conf) { - if (conf == NULL || conf->data == NULL) { + if (conf == NULL) { return; } - lh_CONF_VALUE_doall_arg(conf->data, value_free_arg, NULL); - lh_CONF_VALUE_free(conf->data); + lh_CONF_SECTION_doall_arg(conf->sections, section_free_arg, NULL); + lh_CONF_SECTION_free(conf->sections); + lh_CONF_VALUE_doall_arg(conf->values, value_free_arg, NULL); + lh_CONF_VALUE_free(conf->values); OPENSSL_free(conf); } -static CONF_VALUE *NCONF_new_section(const CONF *conf, const char *section) { - STACK_OF(CONF_VALUE) *sk = NULL; - int ok = 0; - CONF_VALUE *v = NULL, *old_value; - - sk = sk_CONF_VALUE_new_null(); - v = CONF_VALUE_new(); - if (sk == NULL || v == NULL) { - goto err; +static CONF_SECTION *NCONF_new_section(const CONF *conf, const char *section) { + CONF_SECTION *s = OPENSSL_malloc(sizeof(CONF_SECTION)); + if (!s) { + return NULL; } - v->section = OPENSSL_strdup(section); - if (v->section == NULL) { + s->name = OPENSSL_strdup(section); + s->values = sk_CONF_VALUE_new_null(); + if (s->name == NULL || s->values == NULL) { goto err; } - v->name = NULL; - v->value = (char *)sk; - - if (!lh_CONF_VALUE_insert(conf->data, &old_value, v)) { + CONF_SECTION *old_section; + if (!lh_CONF_SECTION_insert(conf->sections, &old_section, s)) { goto err; } - value_free(old_value); - ok = 1; + section_free(old_section); + return s; err: - if (!ok) { - sk_CONF_VALUE_free(sk); - OPENSSL_free(v); - v = NULL; - } - return v; + section_free(s); + return NULL; } static int str_copy(CONF *conf, char *section, char **pto, char *from) { @@ -254,21 +252,20 @@ err: return 0; } -static CONF_VALUE *get_section(const CONF *conf, const char *section) { - CONF_VALUE template; - +static CONF_SECTION *get_section(const CONF *conf, const char *section) { + CONF_SECTION template; OPENSSL_memset(&template, 0, sizeof(template)); - template.section = (char *) section; - return lh_CONF_VALUE_retrieve(conf->data, &template); + template.name = (char *) section; + return lh_CONF_SECTION_retrieve(conf->sections, &template); } const STACK_OF(CONF_VALUE) *NCONF_get_section(const CONF *conf, const char *section) { - const CONF_VALUE *section_value = get_section(conf, section); - if (section_value == NULL) { + const CONF_SECTION *section_obj = get_section(conf, section); + if (section_obj == NULL) { return NULL; } - return (STACK_OF(CONF_VALUE)*) section_value->value; + return section_obj->values; } const char *NCONF_get_string(const CONF *conf, const char *section, @@ -280,30 +277,35 @@ const char *NCONF_get_string(const CONF *conf, const char *section, } OPENSSL_memset(&template, 0, sizeof(template)); - template.section = (char *) section; - template.name = (char *) name; - value = lh_CONF_VALUE_retrieve(conf->data, &template); + template.section = (char *)section; + template.name = (char *)name; + value = lh_CONF_VALUE_retrieve(conf->values, &template); if (value == NULL) { return NULL; } return value->value; } -static int add_string(const CONF *conf, CONF_VALUE *section, +static int add_string(const CONF *conf, CONF_SECTION *section, CONF_VALUE *value) { - STACK_OF(CONF_VALUE) *section_stack = (STACK_OF(CONF_VALUE)*) section->value; - CONF_VALUE *old_value; - - value->section = OPENSSL_strdup(section->section); - if (!sk_CONF_VALUE_push(section_stack, value)) { + value->section = OPENSSL_strdup(section->name); + if (value->section == NULL) { return 0; } - if (!lh_CONF_VALUE_insert(conf->data, &old_value, value)) { + if (!sk_CONF_VALUE_push(section->values, value)) { + return 0; + } + + CONF_VALUE *old_value; + if (!lh_CONF_VALUE_insert(conf->values, &old_value, value)) { + // Remove |value| from |section->values|, so we do not leave a dangling + // pointer. + sk_CONF_VALUE_pop(section->values); return 0; } if (old_value != NULL) { - (void)sk_CONF_VALUE_delete_ptr(section_stack, old_value); + (void)sk_CONF_VALUE_delete_ptr(section->values, old_value); value_free(old_value); } @@ -388,8 +390,8 @@ int NCONF_load_bio(CONF *conf, BIO *in, long *out_error_line) { int again; long eline = 0; char btmp[DECIMAL_SIZE(eline) + 1]; - CONF_VALUE *v = NULL, *tv; - CONF_VALUE *sv = NULL; + CONF_VALUE *v = NULL; + CONF_SECTION *sv = NULL; char *section = NULL, *buf; char *start, *psection, *pname; @@ -540,6 +542,7 @@ int NCONF_load_bio(CONF *conf, BIO *in, long *out_error_line) { goto err; } + CONF_SECTION *tv; if (strcmp(psection, section) != 0) { if ((tv = get_section(conf, psection)) == NULL) { tv = NCONF_new_section(conf, psection); @@ -569,12 +572,7 @@ err: } snprintf(btmp, sizeof btmp, "%ld", eline); ERR_add_error_data(2, "line ", btmp); - - if (v != NULL) { - OPENSSL_free(v->name); - OPENSSL_free(v->value); - OPENSSL_free(v); - } + value_free(v); return 0; } diff --git a/Sources/CCryptoBoringSSL/crypto/conf/internal.h b/Sources/CCryptoBoringSSL/crypto/conf/internal.h index 750857f2..5eeab683 100644 --- a/Sources/CCryptoBoringSSL/crypto/conf/internal.h +++ b/Sources/CCryptoBoringSSL/crypto/conf/internal.h @@ -24,10 +24,14 @@ extern "C" { #endif +typedef struct conf_section_st CONF_SECTION; + +DEFINE_LHASH_OF(CONF_SECTION) DEFINE_LHASH_OF(CONF_VALUE) struct conf_st { - LHASH_OF(CONF_VALUE) *data; + LHASH_OF(CONF_VALUE) *values; + LHASH_OF(CONF_SECTION) *sections; }; // CONF_VALUE_new returns a freshly allocated and zeroed |CONF_VALUE|. diff --git a/Sources/CCryptoBoringSSL/crypto/cpu_intel.c b/Sources/CCryptoBoringSSL/crypto/cpu_intel.c index 4bb9a720..b34c483c 100644 --- a/Sources/CCryptoBoringSSL/crypto/cpu_intel.c +++ b/Sources/CCryptoBoringSSL/crypto/cpu_intel.c @@ -211,7 +211,8 @@ void OPENSSL_cpuid_setup(void) { // Clear the XSAVE bit on Knights Landing to mimic Silvermont. This enables // some Silvermont-specific codepaths which perform better. See OpenSSL - // commit 64d92d74985ebb3d0be58a9718f9e080a14a8e7f. + // commit 64d92d74985ebb3d0be58a9718f9e080a14a8e7f and + // |CRYPTO_cpu_perf_is_like_silvermont|. if ((eax & 0x0fff0ff0) == 0x00050670 /* Knights Landing */ || (eax & 0x0fff0ff0) == 0x00080650 /* Knights Mill (per SDE) */) { ecx &= ~(1u << 26); @@ -238,7 +239,8 @@ void OPENSSL_cpuid_setup(void) { // Clear AVX2 and AVX512* bits. // // TODO(davidben): Should bits 17 and 26-28 also be cleared? Upstream - // doesn't clear those. + // doesn't clear those. See the comments in + // |CRYPTO_hardware_supports_XSAVE|. extended_features[0] &= ~((1u << 5) | (1u << 16) | (1u << 21) | (1u << 30) | (1u << 31)); } diff --git a/Sources/CCryptoBoringSSL/crypto/curve25519/curve25519.c b/Sources/CCryptoBoringSSL/crypto/curve25519/curve25519.c index 928592f7..03894479 100644 --- a/Sources/CCryptoBoringSSL/crypto/curve25519/curve25519.c +++ b/Sources/CCryptoBoringSSL/crypto/curve25519/curve25519.c @@ -1906,6 +1906,8 @@ int ED25519_sign(uint8_t out_sig[64], const uint8_t *message, x25519_sc_reduce(hram); sc_muladd(out_sig + 32, hram, az, nonce); + // The signature is computed from the private key, but is public. + CONSTTIME_DECLASSIFY(out_sig, 64); return 1; } @@ -1983,6 +1985,8 @@ void ED25519_keypair_from_seed(uint8_t out_public_key[32], ge_p3 A; x25519_ge_scalarmult_base(&A, az); ge_p3_tobytes(out_public_key, &A); + // The public key is derived from the private key, but it is public. + CONSTTIME_DECLASSIFY(out_public_key, 32); OPENSSL_memcpy(out_private_key, seed, 32); OPENSSL_memcpy(out_private_key + 32, out_public_key, 32); diff --git a/Sources/CCryptoBoringSSL/crypto/curve25519/internal.h b/Sources/CCryptoBoringSSL/crypto/curve25519/internal.h index 085894da..6893c22b 100644 --- a/Sources/CCryptoBoringSSL/crypto/curve25519/internal.h +++ b/Sources/CCryptoBoringSSL/crypto/curve25519/internal.h @@ -32,7 +32,7 @@ void x25519_NEON(uint8_t out[32], const uint8_t scalar[32], #endif #if !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_SMALL) && \ - defined(__GNUC__) && defined(__x86_64__) + defined(__GNUC__) && defined(__x86_64__) && !defined(OPENSSL_WINDOWS) #define BORINGSSL_FE25519_ADX // fiat_curve25519_adx_mul is defined in diff --git a/Sources/CCryptoBoringSSL/crypto/des/des.c b/Sources/CCryptoBoringSSL/crypto/des/des.c index a028f515..12bc76ef 100644 --- a/Sources/CCryptoBoringSSL/crypto/des/des.c +++ b/Sources/CCryptoBoringSSL/crypto/des/des.c @@ -61,6 +61,91 @@ #include "internal.h" +/* IP and FP + * The problem is more of a geometric problem that random bit fiddling. + 0 1 2 3 4 5 6 7 62 54 46 38 30 22 14 6 + 8 9 10 11 12 13 14 15 60 52 44 36 28 20 12 4 +16 17 18 19 20 21 22 23 58 50 42 34 26 18 10 2 +24 25 26 27 28 29 30 31 to 56 48 40 32 24 16 8 0 + +32 33 34 35 36 37 38 39 63 55 47 39 31 23 15 7 +40 41 42 43 44 45 46 47 61 53 45 37 29 21 13 5 +48 49 50 51 52 53 54 55 59 51 43 35 27 19 11 3 +56 57 58 59 60 61 62 63 57 49 41 33 25 17 9 1 + +The output has been subject to swaps of the form +0 1 -> 3 1 but the odd and even bits have been put into +2 3 2 0 +different words. The main trick is to remember that +t=((l>>size)^r)&(mask); +r^=t; +l^=(t<> (n)) ^ (b)) & (m)); \ + (b) ^= (t); \ + (a) ^= ((t) << (n)); \ + } while (0) + +#define IP(l, r) \ + do { \ + uint32_t tt; \ + PERM_OP(r, l, tt, 4, 0x0f0f0f0fL); \ + PERM_OP(l, r, tt, 16, 0x0000ffffL); \ + PERM_OP(r, l, tt, 2, 0x33333333L); \ + PERM_OP(l, r, tt, 8, 0x00ff00ffL); \ + PERM_OP(r, l, tt, 1, 0x55555555L); \ + } while (0) + +#define FP(l, r) \ + do { \ + uint32_t tt; \ + PERM_OP(l, r, tt, 1, 0x55555555L); \ + PERM_OP(r, l, tt, 8, 0x00ff00ffL); \ + PERM_OP(l, r, tt, 2, 0x33333333L); \ + PERM_OP(r, l, tt, 16, 0x0000ffffL); \ + PERM_OP(l, r, tt, 4, 0x0f0f0f0fL); \ + } while (0) + +#define LOAD_DATA(ks, R, S, u, t, E0, E1) \ + do { \ + (u) = (R) ^ (ks)->subkeys[S][0]; \ + (t) = (R) ^ (ks)->subkeys[S][1]; \ + } while (0) + +#define D_ENCRYPT(ks, LL, R, S) \ + do { \ + LOAD_DATA(ks, R, S, u, t, E0, E1); \ + t = CRYPTO_rotr_u32(t, 4); \ + (LL) ^= \ + DES_SPtrans[0][(u >> 2L) & 0x3f] ^ DES_SPtrans[2][(u >> 10L) & 0x3f] ^ \ + DES_SPtrans[4][(u >> 18L) & 0x3f] ^ \ + DES_SPtrans[6][(u >> 26L) & 0x3f] ^ DES_SPtrans[1][(t >> 2L) & 0x3f] ^ \ + DES_SPtrans[3][(t >> 10L) & 0x3f] ^ \ + DES_SPtrans[5][(t >> 18L) & 0x3f] ^ DES_SPtrans[7][(t >> 26L) & 0x3f]; \ + } while (0) + +#define ITERATIONS 16 +#define HALF_ITERATIONS 8 + static const uint32_t des_skb[8][64] = { { // for C bits (numbered as per FIPS 46) 1 2 3 4 5 6 0x00000000, 0x00000010, 0x20000000, 0x20000010, 0x00010000, @@ -294,13 +379,17 @@ static const uint32_t DES_SPtrans[8][64] = { (a) = (a) ^ (t) ^ ((t) >> (16 - (n)))) void DES_set_key(const DES_cblock *key, DES_key_schedule *schedule) { + DES_set_key_ex(key->bytes, schedule); +} + +void DES_set_key_ex(const uint8_t key[8], DES_key_schedule *schedule) { static const int shifts2[16] = {0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0}; uint32_t c, d, t, s, t2; const uint8_t *in; int i; - in = key->bytes; + in = key; c2l(in, c); c2l(in, d); @@ -378,7 +467,8 @@ void DES_set_odd_parity(DES_cblock *key) { } } -static void DES_encrypt1(uint32_t *data, const DES_key_schedule *ks, int enc) { +static void DES_encrypt1(uint32_t data[2], const DES_key_schedule *ks, + int enc) { uint32_t l, r, t, u; r = data[0]; @@ -442,7 +532,8 @@ static void DES_encrypt1(uint32_t *data, const DES_key_schedule *ks, int enc) { data[1] = r; } -static void DES_encrypt2(uint32_t *data, const DES_key_schedule *ks, int enc) { +static void DES_encrypt2(uint32_t data[2], const DES_key_schedule *ks, + int enc) { uint32_t l, r, t, u; r = data[0]; @@ -499,7 +590,7 @@ static void DES_encrypt2(uint32_t *data, const DES_key_schedule *ks, int enc) { data[1] = CRYPTO_rotr_u32(r, 3); } -void DES_encrypt3(uint32_t *data, const DES_key_schedule *ks1, +void DES_encrypt3(uint32_t data[2], const DES_key_schedule *ks1, const DES_key_schedule *ks2, const DES_key_schedule *ks3) { uint32_t l, r; @@ -508,9 +599,9 @@ void DES_encrypt3(uint32_t *data, const DES_key_schedule *ks1, IP(l, r); data[0] = l; data[1] = r; - DES_encrypt2((uint32_t *)data, ks1, DES_ENCRYPT); - DES_encrypt2((uint32_t *)data, ks2, DES_DECRYPT); - DES_encrypt2((uint32_t *)data, ks3, DES_ENCRYPT); + DES_encrypt2(data, ks1, DES_ENCRYPT); + DES_encrypt2(data, ks2, DES_DECRYPT); + DES_encrypt2(data, ks3, DES_ENCRYPT); l = data[0]; r = data[1]; FP(r, l); @@ -518,7 +609,7 @@ void DES_encrypt3(uint32_t *data, const DES_key_schedule *ks1, data[1] = r; } -void DES_decrypt3(uint32_t *data, const DES_key_schedule *ks1, +void DES_decrypt3(uint32_t data[2], const DES_key_schedule *ks1, const DES_key_schedule *ks2, const DES_key_schedule *ks3) { uint32_t l, r; @@ -527,9 +618,9 @@ void DES_decrypt3(uint32_t *data, const DES_key_schedule *ks1, IP(l, r); data[0] = l; data[1] = r; - DES_encrypt2((uint32_t *)data, ks3, DES_DECRYPT); - DES_encrypt2((uint32_t *)data, ks2, DES_ENCRYPT); - DES_encrypt2((uint32_t *)data, ks1, DES_DECRYPT); + DES_encrypt2(data, ks3, DES_DECRYPT); + DES_encrypt2(data, ks2, DES_ENCRYPT); + DES_encrypt2(data, ks1, DES_DECRYPT); l = data[0]; r = data[1]; FP(r, l); @@ -539,32 +630,34 @@ void DES_decrypt3(uint32_t *data, const DES_key_schedule *ks1, void DES_ecb_encrypt(const DES_cblock *in_block, DES_cblock *out_block, const DES_key_schedule *schedule, int is_encrypt) { - uint32_t l; - uint32_t ll[2]; - const uint8_t *in = in_block->bytes; - uint8_t *out = out_block->bytes; + DES_ecb_encrypt_ex(in_block->bytes, out_block->bytes, schedule, is_encrypt); +} - c2l(in, l); - ll[0] = l; - c2l(in, l); - ll[1] = l; +void DES_ecb_encrypt_ex(const uint8_t in[8], uint8_t out[8], + const DES_key_schedule *schedule, int is_encrypt) { + uint32_t ll[2]; + ll[0] = CRYPTO_load_u32_le(in); + ll[1] = CRYPTO_load_u32_le(in + 4); DES_encrypt1(ll, schedule, is_encrypt); - l = ll[0]; - l2c(l, out); - l = ll[1]; - l2c(l, out); - ll[0] = ll[1] = 0; + CRYPTO_store_u32_le(out, ll[0]); + CRYPTO_store_u32_le(out + 4, ll[1]); } void DES_ncbc_encrypt(const uint8_t *in, uint8_t *out, size_t len, const DES_key_schedule *schedule, DES_cblock *ivec, int enc) { + DES_ncbc_encrypt_ex(in, out, len, schedule, ivec->bytes, enc); +} + +void DES_ncbc_encrypt_ex(const uint8_t *in, uint8_t *out, size_t len, + const DES_key_schedule *schedule, uint8_t ivec[8], + int enc) { uint32_t tin0, tin1; uint32_t tout0, tout1, xor0, xor1; uint32_t tin[2]; unsigned char *iv; - iv = ivec->bytes; + iv = ivec; if (enc) { c2l(iv, tout0); @@ -576,7 +669,7 @@ void DES_ncbc_encrypt(const uint8_t *in, uint8_t *out, size_t len, tin[0] = tin0; tin1 ^= tout1; tin[1] = tin1; - DES_encrypt1((uint32_t *)tin, schedule, DES_ENCRYPT); + DES_encrypt1(tin, schedule, DES_ENCRYPT); tout0 = tin[0]; l2c(tout0, out); tout1 = tin[1]; @@ -588,13 +681,13 @@ void DES_ncbc_encrypt(const uint8_t *in, uint8_t *out, size_t len, tin[0] = tin0; tin1 ^= tout1; tin[1] = tin1; - DES_encrypt1((uint32_t *)tin, schedule, DES_ENCRYPT); + DES_encrypt1(tin, schedule, DES_ENCRYPT); tout0 = tin[0]; l2c(tout0, out); tout1 = tin[1]; l2c(tout1, out); } - iv = ivec->bytes; + iv = ivec; l2c(tout0, iv); l2c(tout1, iv); } else { @@ -605,7 +698,7 @@ void DES_ncbc_encrypt(const uint8_t *in, uint8_t *out, size_t len, tin[0] = tin0; c2l(in, tin1); tin[1] = tin1; - DES_encrypt1((uint32_t *)tin, schedule, DES_DECRYPT); + DES_encrypt1(tin, schedule, DES_DECRYPT); tout0 = tin[0] ^ xor0; tout1 = tin[1] ^ xor1; l2c(tout0, out); @@ -618,14 +711,14 @@ void DES_ncbc_encrypt(const uint8_t *in, uint8_t *out, size_t len, tin[0] = tin0; c2l(in, tin1); tin[1] = tin1; - DES_encrypt1((uint32_t *)tin, schedule, DES_DECRYPT); + DES_encrypt1(tin, schedule, DES_DECRYPT); tout0 = tin[0] ^ xor0; tout1 = tin[1] ^ xor1; l2cn(tout0, tout1, out, len); xor0 = tin0; xor1 = tin1; } - iv = ivec->bytes; + iv = ivec; l2c(xor0, iv); l2c(xor1, iv); } @@ -635,24 +728,23 @@ void DES_ncbc_encrypt(const uint8_t *in, uint8_t *out, size_t len, void DES_ecb3_encrypt(const DES_cblock *input, DES_cblock *output, const DES_key_schedule *ks1, const DES_key_schedule *ks2, const DES_key_schedule *ks3, int enc) { - uint32_t l0, l1; - uint32_t ll[2]; - const uint8_t *in = input->bytes; - uint8_t *out = output->bytes; + DES_ecb3_encrypt_ex(input->bytes, output->bytes, ks1, ks2, ks3, enc); +} - c2l(in, l0); - c2l(in, l1); - ll[0] = l0; - ll[1] = l1; +void DES_ecb3_encrypt_ex(const uint8_t in[8], uint8_t out[8], + const DES_key_schedule *ks1, + const DES_key_schedule *ks2, + const DES_key_schedule *ks3, int enc) { + uint32_t ll[2]; + ll[0] = CRYPTO_load_u32_le(in); + ll[1] = CRYPTO_load_u32_le(in + 4); if (enc) { DES_encrypt3(ll, ks1, ks2, ks3); } else { DES_decrypt3(ll, ks1, ks2, ks3); } - l0 = ll[0]; - l1 = ll[1]; - l2c(l0, out); - l2c(l1, out); + CRYPTO_store_u32_le(out, ll[0]); + CRYPTO_store_u32_le(out + 4, ll[1]); } void DES_ede3_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t len, @@ -660,12 +752,20 @@ void DES_ede3_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t len, const DES_key_schedule *ks2, const DES_key_schedule *ks3, DES_cblock *ivec, int enc) { + DES_ede3_cbc_encrypt_ex(in, out, len, ks1, ks2, ks3, ivec->bytes, enc); +} + +void DES_ede3_cbc_encrypt_ex(const uint8_t *in, uint8_t *out, size_t len, + const DES_key_schedule *ks1, + const DES_key_schedule *ks2, + const DES_key_schedule *ks3, uint8_t ivec[8], + int enc) { uint32_t tin0, tin1; uint32_t tout0, tout1, xor0, xor1; uint32_t tin[2]; uint8_t *iv; - iv = ivec->bytes; + iv = ivec; if (enc) { c2l(iv, tout0); @@ -678,7 +778,7 @@ void DES_ede3_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t len, tin[0] = tin0; tin[1] = tin1; - DES_encrypt3((uint32_t *)tin, ks1, ks2, ks3); + DES_encrypt3(tin, ks1, ks2, ks3); tout0 = tin[0]; tout1 = tin[1]; @@ -692,14 +792,14 @@ void DES_ede3_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t len, tin[0] = tin0; tin[1] = tin1; - DES_encrypt3((uint32_t *)tin, ks1, ks2, ks3); + DES_encrypt3(tin, ks1, ks2, ks3); tout0 = tin[0]; tout1 = tin[1]; l2c(tout0, out); l2c(tout1, out); } - iv = ivec->bytes; + iv = ivec; l2c(tout0, iv); l2c(tout1, iv); } else { @@ -716,7 +816,7 @@ void DES_ede3_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t len, tin[0] = tin0; tin[1] = tin1; - DES_decrypt3((uint32_t *)tin, ks1, ks2, ks3); + DES_decrypt3(tin, ks1, ks2, ks3); tout0 = tin[0]; tout1 = tin[1]; @@ -736,7 +836,7 @@ void DES_ede3_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t len, tin[0] = tin0; tin[1] = tin1; - DES_decrypt3((uint32_t *)tin, ks1, ks2, ks3); + DES_decrypt3(tin, ks1, ks2, ks3); tout0 = tin[0]; tout1 = tin[1]; @@ -747,7 +847,7 @@ void DES_ede3_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t len, xor1 = t1; } - iv = ivec->bytes; + iv = ivec; l2c(xor0, iv); l2c(xor1, iv); } @@ -769,16 +869,3 @@ void DES_ede2_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t len, void DES_set_key_unchecked(const DES_cblock *key, DES_key_schedule *schedule) { DES_set_key(key, schedule); } - -#undef HPERM_OP -#undef c2l -#undef l2c -#undef c2ln -#undef l2cn -#undef PERM_OP -#undef IP -#undef FP -#undef LOAD_DATA -#undef D_ENCRYPT -#undef ITERATIONS -#undef HALF_ITERATIONS diff --git a/Sources/CCryptoBoringSSL/crypto/des/internal.h b/Sources/CCryptoBoringSSL/crypto/des/internal.h index 639d7e8c..10c240c9 100644 --- a/Sources/CCryptoBoringSSL/crypto/des/internal.h +++ b/Sources/CCryptoBoringSSL/crypto/des/internal.h @@ -58,6 +58,7 @@ #define OPENSSL_HEADER_DES_INTERNAL_H #include +#include #include "../internal.h" @@ -66,6 +67,9 @@ extern "C" { #endif +// TODO(davidben): Ideally these macros would be replaced with +// |CRYPTO_load_u32_le| and |CRYPTO_store_u32_le|. + #define c2l(c, l) \ do { \ (l) = ((uint32_t)(*((c)++))); \ @@ -145,90 +149,39 @@ extern "C" { } \ } while (0) -/* IP and FP - * The problem is more of a geometric problem that random bit fiddling. - 0 1 2 3 4 5 6 7 62 54 46 38 30 22 14 6 - 8 9 10 11 12 13 14 15 60 52 44 36 28 20 12 4 -16 17 18 19 20 21 22 23 58 50 42 34 26 18 10 2 -24 25 26 27 28 29 30 31 to 56 48 40 32 24 16 8 0 -32 33 34 35 36 37 38 39 63 55 47 39 31 23 15 7 -40 41 42 43 44 45 46 47 61 53 45 37 29 21 13 5 -48 49 50 51 52 53 54 55 59 51 43 35 27 19 11 3 -56 57 58 59 60 61 62 63 57 49 41 33 25 17 9 1 +// Correctly-typed versions of DES functions. +// +// See https://crbug.com/boringssl/683. -The output has been subject to swaps of the form -0 1 -> 3 1 but the odd and even bits have been put into -2 3 2 0 -different words. The main trick is to remember that -t=((l>>size)^r)&(mask); -r^=t; -l^=(t<> (n)) ^ (b)) & (m)); \ - (b) ^= (t); \ - (a) ^= ((t) << (n)); \ - } while (0) +// Private functions. +// +// These functions are only exported for use in |decrepit|. -#define IP(l, r) \ - do { \ - uint32_t tt; \ - PERM_OP(r, l, tt, 4, 0x0f0f0f0fL); \ - PERM_OP(l, r, tt, 16, 0x0000ffffL); \ - PERM_OP(r, l, tt, 2, 0x33333333L); \ - PERM_OP(l, r, tt, 8, 0x00ff00ffL); \ - PERM_OP(r, l, tt, 1, 0x55555555L); \ - } while (0) +OPENSSL_EXPORT void DES_decrypt3(uint32_t data[2], const DES_key_schedule *ks1, + const DES_key_schedule *ks2, + const DES_key_schedule *ks3); -#define FP(l, r) \ - do { \ - uint32_t tt; \ - PERM_OP(l, r, tt, 1, 0x55555555L); \ - PERM_OP(r, l, tt, 8, 0x00ff00ffL); \ - PERM_OP(l, r, tt, 2, 0x33333333L); \ - PERM_OP(r, l, tt, 16, 0x0000ffffL); \ - PERM_OP(l, r, tt, 4, 0x0f0f0f0fL); \ - } while (0) - -#define LOAD_DATA(ks, R, S, u, t, E0, E1) \ - do { \ - (u) = (R) ^ (ks)->subkeys[S][0]; \ - (t) = (R) ^ (ks)->subkeys[S][1]; \ - } while (0) - -#define D_ENCRYPT(ks, LL, R, S) \ - do { \ - LOAD_DATA(ks, R, S, u, t, E0, E1); \ - t = CRYPTO_rotr_u32(t, 4); \ - (LL) ^= \ - DES_SPtrans[0][(u >> 2L) & 0x3f] ^ DES_SPtrans[2][(u >> 10L) & 0x3f] ^ \ - DES_SPtrans[4][(u >> 18L) & 0x3f] ^ \ - DES_SPtrans[6][(u >> 26L) & 0x3f] ^ DES_SPtrans[1][(t >> 2L) & 0x3f] ^ \ - DES_SPtrans[3][(t >> 10L) & 0x3f] ^ \ - DES_SPtrans[5][(t >> 18L) & 0x3f] ^ DES_SPtrans[7][(t >> 26L) & 0x3f]; \ - } while (0) - -#define ITERATIONS 16 -#define HALF_ITERATIONS 8 +OPENSSL_EXPORT void DES_encrypt3(uint32_t data[2], const DES_key_schedule *ks1, + const DES_key_schedule *ks2, + const DES_key_schedule *ks3); #if defined(__cplusplus) diff --git a/Sources/CCryptoBoringSSL/crypto/dsa/dsa.c b/Sources/CCryptoBoringSSL/crypto/dsa/dsa.c index 05302b9d..269fe6fb 100644 --- a/Sources/CCryptoBoringSSL/crypto/dsa/dsa.c +++ b/Sources/CCryptoBoringSSL/crypto/dsa/dsa.c @@ -934,12 +934,7 @@ err: int DSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_unused *unused, CRYPTO_EX_dup *dup_unused, CRYPTO_EX_free *free_func) { - int index; - if (!CRYPTO_get_ex_new_index(&g_ex_data_class, &index, argl, argp, - free_func)) { - return -1; - } - return index; + return CRYPTO_get_ex_new_index_ex(&g_ex_data_class, argl, argp, free_func); } int DSA_set_ex_data(DSA *dsa, int idx, void *arg) { diff --git a/Sources/CCryptoBoringSSL/crypto/err/err.c b/Sources/CCryptoBoringSSL/crypto/err/err.c index 747f336d..5504c6a2 100644 --- a/Sources/CCryptoBoringSSL/crypto/err/err.c +++ b/Sources/CCryptoBoringSSL/crypto/err/err.c @@ -428,50 +428,52 @@ static const char *err_string_lookup(uint32_t lib, uint32_t key, return &string_data[(*result) & 0x7fff]; } -static const char *const kLibraryNames[ERR_NUM_LIBS] = { - "invalid library (0)", - "unknown library", // ERR_LIB_NONE - "system library", // ERR_LIB_SYS - "bignum routines", // ERR_LIB_BN - "RSA routines", // ERR_LIB_RSA - "Diffie-Hellman routines", // ERR_LIB_DH - "public key routines", // ERR_LIB_EVP - "memory buffer routines", // ERR_LIB_BUF - "object identifier routines", // ERR_LIB_OBJ - "PEM routines", // ERR_LIB_PEM - "DSA routines", // ERR_LIB_DSA - "X.509 certificate routines", // ERR_LIB_X509 - "ASN.1 encoding routines", // ERR_LIB_ASN1 - "configuration file routines", // ERR_LIB_CONF - "common libcrypto routines", // ERR_LIB_CRYPTO - "elliptic curve routines", // ERR_LIB_EC - "SSL routines", // ERR_LIB_SSL - "BIO routines", // ERR_LIB_BIO - "PKCS7 routines", // ERR_LIB_PKCS7 - "PKCS8 routines", // ERR_LIB_PKCS8 - "X509 V3 routines", // ERR_LIB_X509V3 - "random number generator", // ERR_LIB_RAND - "ENGINE routines", // ERR_LIB_ENGINE - "OCSP routines", // ERR_LIB_OCSP - "UI routines", // ERR_LIB_UI - "COMP routines", // ERR_LIB_COMP - "ECDSA routines", // ERR_LIB_ECDSA - "ECDH routines", // ERR_LIB_ECDH - "HMAC routines", // ERR_LIB_HMAC - "Digest functions", // ERR_LIB_DIGEST - "Cipher functions", // ERR_LIB_CIPHER - "HKDF functions", // ERR_LIB_HKDF - "Trust Token functions", // ERR_LIB_TRUST_TOKEN - "User defined functions", // ERR_LIB_USER +typedef struct library_name_st { + const char *str; + const char *symbol; + const char *reason_symbol; +} LIBRARY_NAME; + +static const LIBRARY_NAME kLibraryNames[ERR_NUM_LIBS] = { + {"invalid library (0)", NULL, NULL}, + {"unknown library", "NONE", "NONE_LIB"}, + {"system library", "SYS", "SYS_LIB"}, + {"bignum routines", "BN", "BN_LIB"}, + {"RSA routines", "RSA", "RSA_LIB"}, + {"Diffie-Hellman routines", "DH", "DH_LIB"}, + {"public key routines", "EVP", "EVP_LIB"}, + {"memory buffer routines", "BUF", "BUF_LIB"}, + {"object identifier routines", "OBJ", "OBJ_LIB"}, + {"PEM routines", "PEM", "PEM_LIB"}, + {"DSA routines", "DSA", "DSA_LIB"}, + {"X.509 certificate routines", "X509", "X509_LIB"}, + {"ASN.1 encoding routines", "ASN1", "ASN1_LIB"}, + {"configuration file routines", "CONF", "CONF_LIB"}, + {"common libcrypto routines", "CRYPTO", "CRYPTO_LIB"}, + {"elliptic curve routines", "EC", "EC_LIB"}, + {"SSL routines", "SSL", "SSL_LIB"}, + {"BIO routines", "BIO", "BIO_LIB"}, + {"PKCS7 routines", "PKCS7", "PKCS7_LIB"}, + {"PKCS8 routines", "PKCS8", "PKCS8_LIB"}, + {"X509 V3 routines", "X509V3", "X509V3_LIB"}, + {"random number generator", "RAND", "RAND_LIB"}, + {"ENGINE routines", "ENGINE", "ENGINE_LIB"}, + {"OCSP routines", "OCSP", "OCSP_LIB"}, + {"UI routines", "UI", "UI_LIB"}, + {"COMP routines", "COMP", "COMP_LIB"}, + {"ECDSA routines", "ECDSA", "ECDSA_LIB"}, + {"ECDH routines", "ECDH", "ECDH_LIB"}, + {"HMAC routines", "HMAC", "HMAC_LIB"}, + {"Digest functions", "DIGEST", "DIGEST_LIB"}, + {"Cipher functions", "CIPHER", "CIPHER_LIB"}, + {"HKDF functions", "HKDF", "HKDF_LIB"}, + {"Trust Token functions", "TRUST_TOKEN", "TRUST_TOKEN_LIB"}, + {"User defined functions", "USER", "USER_LIB"}, }; static const char *err_lib_error_string(uint32_t packed_error) { const uint32_t lib = ERR_GET_LIB(packed_error); - - if (lib >= ERR_NUM_LIBS) { - return NULL; - } - return kLibraryNames[lib]; + return lib >= ERR_NUM_LIBS ? NULL : kLibraryNames[lib].str; } const char *ERR_lib_error_string(uint32_t packed_error) { @@ -479,51 +481,67 @@ const char *ERR_lib_error_string(uint32_t packed_error) { return ret == NULL ? "unknown library" : ret; } +const char *ERR_lib_symbol_name(uint32_t packed_error) { + const uint32_t lib = ERR_GET_LIB(packed_error); + return lib >= ERR_NUM_LIBS ? NULL : kLibraryNames[lib].symbol; +} + const char *ERR_func_error_string(uint32_t packed_error) { return "OPENSSL_internal"; } -static const char *err_reason_error_string(uint32_t packed_error) { +static const char *err_reason_error_string(uint32_t packed_error, int symbol) { const uint32_t lib = ERR_GET_LIB(packed_error); const uint32_t reason = ERR_GET_REASON(packed_error); if (lib == ERR_LIB_SYS) { - if (reason < 127) { + if (!symbol && reason < 127) { return strerror(reason); } return NULL; } if (reason < ERR_NUM_LIBS) { - return kLibraryNames[reason]; + return symbol ? kLibraryNames[reason].reason_symbol + : kLibraryNames[reason].str; } if (reason < 100) { + // TODO(davidben): All our other reason strings match the symbol name. Only + // the common ones differ. Should we just consistently return the symbol + // name? switch (reason) { case ERR_R_MALLOC_FAILURE: - return "malloc failure"; + return symbol ? "MALLOC_FAILURE" : "malloc failure"; case ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED: - return "function should not have been called"; + return symbol ? "SHOULD_NOT_HAVE_BEEN_CALLED" + : "function should not have been called"; case ERR_R_PASSED_NULL_PARAMETER: - return "passed a null parameter"; + return symbol ? "PASSED_NULL_PARAMETER" : "passed a null parameter"; case ERR_R_INTERNAL_ERROR: - return "internal error"; + return symbol ? "INTERNAL_ERROR" : "internal error"; case ERR_R_OVERFLOW: - return "overflow"; + return symbol ? "OVERFLOW" : "overflow"; default: return NULL; } } + // Unlike OpenSSL, BoringSSL's reason strings already match symbol name, so we + // do not need to check |symbol|. return err_string_lookup(lib, reason, kOpenSSLReasonValues, kOpenSSLReasonValuesLen, kOpenSSLReasonStringData); } const char *ERR_reason_error_string(uint32_t packed_error) { - const char *ret = err_reason_error_string(packed_error); + const char *ret = err_reason_error_string(packed_error, /*symbol=*/0); return ret == NULL ? "unknown error" : ret; } +const char *ERR_reason_symbol_name(uint32_t packed_error) { + return err_reason_error_string(packed_error, /*symbol=*/1); +} + char *ERR_error_string(uint32_t packed_error, char *ret) { static char buf[ERR_ERROR_STRING_BUF_LEN]; @@ -550,7 +568,7 @@ char *ERR_error_string_n(uint32_t packed_error, char *buf, size_t len) { unsigned reason = ERR_GET_REASON(packed_error); const char *lib_str = err_lib_error_string(packed_error); - const char *reason_str = err_reason_error_string(packed_error); + const char *reason_str = err_reason_error_string(packed_error, /*symbol=*/0); char lib_buf[32], reason_buf[32]; if (lib_str == NULL) { diff --git a/Sources/CCryptoBoringSSL/crypto/ex_data.c b/Sources/CCryptoBoringSSL/crypto/ex_data.c index e37bb6e1..ee3cba51 100644 --- a/Sources/CCryptoBoringSSL/crypto/ex_data.c +++ b/Sources/CCryptoBoringSSL/crypto/ex_data.c @@ -132,11 +132,11 @@ struct crypto_ex_data_func_st { CRYPTO_EX_DATA_FUNCS *next; }; -int CRYPTO_get_ex_new_index(CRYPTO_EX_DATA_CLASS *ex_data_class, int *out_index, - long argl, void *argp, CRYPTO_EX_free *free_func) { +int CRYPTO_get_ex_new_index_ex(CRYPTO_EX_DATA_CLASS *ex_data_class, long argl, + void *argp, CRYPTO_EX_free *free_func) { CRYPTO_EX_DATA_FUNCS *funcs = OPENSSL_malloc(sizeof(CRYPTO_EX_DATA_FUNCS)); if (funcs == NULL) { - return 0; + return -1; } funcs->argl = argl; @@ -151,7 +151,7 @@ int CRYPTO_get_ex_new_index(CRYPTO_EX_DATA_CLASS *ex_data_class, int *out_index, if (num_funcs > (size_t)(INT_MAX - ex_data_class->num_reserved)) { OPENSSL_PUT_ERROR(CRYPTO, ERR_R_OVERFLOW); CRYPTO_MUTEX_unlock_write(&ex_data_class->lock); - return 0; + return -1; } // Append |funcs| to the linked list. @@ -166,8 +166,7 @@ int CRYPTO_get_ex_new_index(CRYPTO_EX_DATA_CLASS *ex_data_class, int *out_index, CRYPTO_atomic_store_u32(&ex_data_class->num_funcs, num_funcs + 1); CRYPTO_MUTEX_unlock_write(&ex_data_class->lock); - *out_index = (int)num_funcs + ex_data_class->num_reserved; - return 1; + return (int)num_funcs + ex_data_class->num_reserved; } int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int index, void *val) { @@ -215,7 +214,7 @@ void CRYPTO_free_ex_data(CRYPTO_EX_DATA_CLASS *ex_data_class, void *obj, } uint32_t num_funcs = CRYPTO_atomic_load_u32(&ex_data_class->num_funcs); - // |CRYPTO_get_ex_new_index| will not allocate indices beyond |INT_MAX|. + // |CRYPTO_get_ex_new_index_ex| will not allocate indices beyond |INT_MAX|. assert(num_funcs <= (size_t)(INT_MAX - ex_data_class->num_reserved)); // Defer dereferencing |ex_data_class->funcs| and |funcs->next|. It must come diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/aesni-x86_64-linux.linux.x86_64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/aesni-x86_64-linux.linux.x86_64.S index 4e3e1a96..e86b7b84 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/aesni-x86_64-linux.linux.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/aesni-x86_64-linux.linux.x86_64.S @@ -973,10 +973,7 @@ _CET_ENDBR leaq 7(%r8),%r9 movl %r10d,96+12(%rsp) bswapl %r9d - leaq OPENSSL_ia32cap_P(%rip),%r10 - movl 4(%r10),%r10d xorl %ebp,%r9d - andl $71303168,%r10d movl %r9d,112+12(%rsp) movups 16(%rcx),%xmm1 @@ -987,104 +984,10 @@ _CET_ENDBR cmpq $8,%rdx jb .Lctr32_tail - subq $6,%rdx - cmpl $4194304,%r10d - je .Lctr32_6x - leaq 128(%rcx),%rcx - subq $2,%rdx + subq $8,%rdx jmp .Lctr32_loop8 -.align 16 -.Lctr32_6x: - shll $4,%eax - movl $48,%r10d - bswapl %ebp - leaq 32(%rcx,%rax,1),%rcx - subq %rax,%r10 - jmp .Lctr32_loop6 - -.align 16 -.Lctr32_loop6: - addl $6,%r8d - movups -48(%rcx,%r10,1),%xmm0 -.byte 102,15,56,220,209 - movl %r8d,%eax - xorl %ebp,%eax -.byte 102,15,56,220,217 -.byte 0x0f,0x38,0xf1,0x44,0x24,12 - leal 1(%r8),%eax -.byte 102,15,56,220,225 - xorl %ebp,%eax -.byte 0x0f,0x38,0xf1,0x44,0x24,28 -.byte 102,15,56,220,233 - leal 2(%r8),%eax - xorl %ebp,%eax -.byte 102,15,56,220,241 -.byte 0x0f,0x38,0xf1,0x44,0x24,44 - leal 3(%r8),%eax -.byte 102,15,56,220,249 - movups -32(%rcx,%r10,1),%xmm1 - xorl %ebp,%eax - -.byte 102,15,56,220,208 -.byte 0x0f,0x38,0xf1,0x44,0x24,60 - leal 4(%r8),%eax -.byte 102,15,56,220,216 - xorl %ebp,%eax -.byte 0x0f,0x38,0xf1,0x44,0x24,76 -.byte 102,15,56,220,224 - leal 5(%r8),%eax - xorl %ebp,%eax -.byte 102,15,56,220,232 -.byte 0x0f,0x38,0xf1,0x44,0x24,92 - movq %r10,%rax -.byte 102,15,56,220,240 -.byte 102,15,56,220,248 - movups -16(%rcx,%r10,1),%xmm0 - - call .Lenc_loop6 - - movdqu (%rdi),%xmm8 - movdqu 16(%rdi),%xmm9 - movdqu 32(%rdi),%xmm10 - movdqu 48(%rdi),%xmm11 - movdqu 64(%rdi),%xmm12 - movdqu 80(%rdi),%xmm13 - leaq 96(%rdi),%rdi - movups -64(%rcx,%r10,1),%xmm1 - pxor %xmm2,%xmm8 - movaps 0(%rsp),%xmm2 - pxor %xmm3,%xmm9 - movaps 16(%rsp),%xmm3 - pxor %xmm4,%xmm10 - movaps 32(%rsp),%xmm4 - pxor %xmm5,%xmm11 - movaps 48(%rsp),%xmm5 - pxor %xmm6,%xmm12 - movaps 64(%rsp),%xmm6 - pxor %xmm7,%xmm13 - movaps 80(%rsp),%xmm7 - movdqu %xmm8,(%rsi) - movdqu %xmm9,16(%rsi) - movdqu %xmm10,32(%rsi) - movdqu %xmm11,48(%rsi) - movdqu %xmm12,64(%rsi) - movdqu %xmm13,80(%rsi) - leaq 96(%rsi),%rsi - - subq $6,%rdx - jnc .Lctr32_loop6 - - addq $6,%rdx - jz .Lctr32_done - - leal -48(%r10),%eax - leaq -80(%rcx,%r10,1),%rcx - negl %eax - shrl $4,%eax - jmp .Lctr32_tail - .align 32 .Lctr32_loop8: addl $8,%r8d @@ -1586,16 +1489,10 @@ _CET_ENDBR movdqa %xmm5,%xmm14 movdqu 80(%rdi),%xmm7 movdqa %xmm6,%xmm15 - leaq OPENSSL_ia32cap_P(%rip),%r9 - movl 4(%r9),%r9d cmpq $0x70,%rdx jbe .Lcbc_dec_six_or_seven - andl $71303168,%r9d - subq $0x50,%rdx - cmpl $4194304,%r9d - je .Lcbc_dec_loop6_enter - subq $0x20,%rdx + subq $0x70,%rdx leaq 112(%rcx),%rcx jmp .Lcbc_dec_loop8_enter .align 16 @@ -1866,51 +1763,6 @@ _CET_ENDBR pxor %xmm9,%xmm9 jmp .Lcbc_dec_tail_collected -.align 16 -.Lcbc_dec_loop6: - movups %xmm7,(%rsi) - leaq 16(%rsi),%rsi - movdqu 0(%rdi),%xmm2 - movdqu 16(%rdi),%xmm3 - movdqa %xmm2,%xmm11 - movdqu 32(%rdi),%xmm4 - movdqa %xmm3,%xmm12 - movdqu 48(%rdi),%xmm5 - movdqa %xmm4,%xmm13 - movdqu 64(%rdi),%xmm6 - movdqa %xmm5,%xmm14 - movdqu 80(%rdi),%xmm7 - movdqa %xmm6,%xmm15 -.Lcbc_dec_loop6_enter: - leaq 96(%rdi),%rdi - movdqa %xmm7,%xmm8 - - call _aesni_decrypt6 - - pxor %xmm10,%xmm2 - movdqa %xmm8,%xmm10 - pxor %xmm11,%xmm3 - movdqu %xmm2,(%rsi) - pxor %xmm12,%xmm4 - movdqu %xmm3,16(%rsi) - pxor %xmm13,%xmm5 - movdqu %xmm4,32(%rsi) - pxor %xmm14,%xmm6 - movq %rbp,%rcx - movdqu %xmm5,48(%rsi) - pxor %xmm15,%xmm7 - movl %r10d,%eax - movdqu %xmm6,64(%rsi) - leaq 80(%rsi),%rsi - subq $0x60,%rdx - ja .Lcbc_dec_loop6 - - movdqa %xmm7,%xmm2 - addq $0x50,%rdx - jle .Lcbc_dec_clear_tail_collected - movups %xmm7,(%rsi) - leaq 16(%rsi),%rsi - .Lcbc_dec_tail: movups (%rdi),%xmm2 subq $0x10,%rdx diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/aesni-x86_64-mac.mac.x86_64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/aesni-x86_64-mac.mac.x86_64.S index ba7962e4..dfe7d257 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/aesni-x86_64-mac.mac.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/aesni-x86_64-mac.mac.x86_64.S @@ -971,10 +971,7 @@ L$ctr32_bulk: leaq 7(%r8),%r9 movl %r10d,96+12(%rsp) bswapl %r9d - leaq _OPENSSL_ia32cap_P(%rip),%r10 - movl 4(%r10),%r10d xorl %ebp,%r9d - andl $71303168,%r10d movl %r9d,112+12(%rsp) movups 16(%rcx),%xmm1 @@ -985,104 +982,10 @@ L$ctr32_bulk: cmpq $8,%rdx jb L$ctr32_tail - subq $6,%rdx - cmpl $4194304,%r10d - je L$ctr32_6x - leaq 128(%rcx),%rcx - subq $2,%rdx + subq $8,%rdx jmp L$ctr32_loop8 -.p2align 4 -L$ctr32_6x: - shll $4,%eax - movl $48,%r10d - bswapl %ebp - leaq 32(%rcx,%rax,1),%rcx - subq %rax,%r10 - jmp L$ctr32_loop6 - -.p2align 4 -L$ctr32_loop6: - addl $6,%r8d - movups -48(%rcx,%r10,1),%xmm0 -.byte 102,15,56,220,209 - movl %r8d,%eax - xorl %ebp,%eax -.byte 102,15,56,220,217 -.byte 0x0f,0x38,0xf1,0x44,0x24,12 - leal 1(%r8),%eax -.byte 102,15,56,220,225 - xorl %ebp,%eax -.byte 0x0f,0x38,0xf1,0x44,0x24,28 -.byte 102,15,56,220,233 - leal 2(%r8),%eax - xorl %ebp,%eax -.byte 102,15,56,220,241 -.byte 0x0f,0x38,0xf1,0x44,0x24,44 - leal 3(%r8),%eax -.byte 102,15,56,220,249 - movups -32(%rcx,%r10,1),%xmm1 - xorl %ebp,%eax - -.byte 102,15,56,220,208 -.byte 0x0f,0x38,0xf1,0x44,0x24,60 - leal 4(%r8),%eax -.byte 102,15,56,220,216 - xorl %ebp,%eax -.byte 0x0f,0x38,0xf1,0x44,0x24,76 -.byte 102,15,56,220,224 - leal 5(%r8),%eax - xorl %ebp,%eax -.byte 102,15,56,220,232 -.byte 0x0f,0x38,0xf1,0x44,0x24,92 - movq %r10,%rax -.byte 102,15,56,220,240 -.byte 102,15,56,220,248 - movups -16(%rcx,%r10,1),%xmm0 - - call L$enc_loop6 - - movdqu (%rdi),%xmm8 - movdqu 16(%rdi),%xmm9 - movdqu 32(%rdi),%xmm10 - movdqu 48(%rdi),%xmm11 - movdqu 64(%rdi),%xmm12 - movdqu 80(%rdi),%xmm13 - leaq 96(%rdi),%rdi - movups -64(%rcx,%r10,1),%xmm1 - pxor %xmm2,%xmm8 - movaps 0(%rsp),%xmm2 - pxor %xmm3,%xmm9 - movaps 16(%rsp),%xmm3 - pxor %xmm4,%xmm10 - movaps 32(%rsp),%xmm4 - pxor %xmm5,%xmm11 - movaps 48(%rsp),%xmm5 - pxor %xmm6,%xmm12 - movaps 64(%rsp),%xmm6 - pxor %xmm7,%xmm13 - movaps 80(%rsp),%xmm7 - movdqu %xmm8,(%rsi) - movdqu %xmm9,16(%rsi) - movdqu %xmm10,32(%rsi) - movdqu %xmm11,48(%rsi) - movdqu %xmm12,64(%rsi) - movdqu %xmm13,80(%rsi) - leaq 96(%rsi),%rsi - - subq $6,%rdx - jnc L$ctr32_loop6 - - addq $6,%rdx - jz L$ctr32_done - - leal -48(%r10),%eax - leaq -80(%rcx,%r10,1),%rcx - negl %eax - shrl $4,%eax - jmp L$ctr32_tail - .p2align 5 L$ctr32_loop8: addl $8,%r8d @@ -1584,16 +1487,10 @@ L$cbc_decrypt_bulk: movdqa %xmm5,%xmm14 movdqu 80(%rdi),%xmm7 movdqa %xmm6,%xmm15 - leaq _OPENSSL_ia32cap_P(%rip),%r9 - movl 4(%r9),%r9d cmpq $0x70,%rdx jbe L$cbc_dec_six_or_seven - andl $71303168,%r9d - subq $0x50,%rdx - cmpl $4194304,%r9d - je L$cbc_dec_loop6_enter - subq $0x20,%rdx + subq $0x70,%rdx leaq 112(%rcx),%rcx jmp L$cbc_dec_loop8_enter .p2align 4 @@ -1864,51 +1761,6 @@ L$cbc_dec_seven: pxor %xmm9,%xmm9 jmp L$cbc_dec_tail_collected -.p2align 4 -L$cbc_dec_loop6: - movups %xmm7,(%rsi) - leaq 16(%rsi),%rsi - movdqu 0(%rdi),%xmm2 - movdqu 16(%rdi),%xmm3 - movdqa %xmm2,%xmm11 - movdqu 32(%rdi),%xmm4 - movdqa %xmm3,%xmm12 - movdqu 48(%rdi),%xmm5 - movdqa %xmm4,%xmm13 - movdqu 64(%rdi),%xmm6 - movdqa %xmm5,%xmm14 - movdqu 80(%rdi),%xmm7 - movdqa %xmm6,%xmm15 -L$cbc_dec_loop6_enter: - leaq 96(%rdi),%rdi - movdqa %xmm7,%xmm8 - - call _aesni_decrypt6 - - pxor %xmm10,%xmm2 - movdqa %xmm8,%xmm10 - pxor %xmm11,%xmm3 - movdqu %xmm2,(%rsi) - pxor %xmm12,%xmm4 - movdqu %xmm3,16(%rsi) - pxor %xmm13,%xmm5 - movdqu %xmm4,32(%rsi) - pxor %xmm14,%xmm6 - movq %rbp,%rcx - movdqu %xmm5,48(%rsi) - pxor %xmm15,%xmm7 - movl %r10d,%eax - movdqu %xmm6,64(%rsi) - leaq 80(%rsi),%rsi - subq $0x60,%rdx - ja L$cbc_dec_loop6 - - movdqa %xmm7,%xmm2 - addq $0x50,%rdx - jle L$cbc_dec_clear_tail_collected - movups %xmm7,(%rsi) - leaq 16(%rsi),%rsi - L$cbc_dec_tail: movups (%rdi),%xmm2 subq $0x10,%rdx diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/armv4-mont-ios.ios.arm.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/armv4-mont-ios.ios.arm.S index 3a20942e..be0d2bb9 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/armv4-mont-ios.ios.arm.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/armv4-mont-ios.ios.arm.S @@ -20,40 +20,16 @@ .code 32 #endif -#if __ARM_MAX_ARCH__>=7 -.align 5 -LOPENSSL_armcap: -.word OPENSSL_armcap_P-Lbn_mul_mont -#endif - -.globl _bn_mul_mont -.private_extern _bn_mul_mont +.globl _bn_mul_mont_nohw +.private_extern _bn_mul_mont_nohw #ifdef __thumb2__ -.thumb_func _bn_mul_mont +.thumb_func _bn_mul_mont_nohw #endif .align 5 -_bn_mul_mont: -Lbn_mul_mont: +_bn_mul_mont_nohw: ldr ip,[sp,#4] @ load num stmdb sp!,{r0,r2} @ sp points at argument block -#if __ARM_MAX_ARCH__>=7 - tst ip,#7 - bne Lialu - adr r0,Lbn_mul_mont - ldr r2,LOPENSSL_armcap - ldr r0,[r0,r2] -#ifdef __APPLE__ - ldr r0,[r0] -#endif - tst r0,#ARMV7_NEON @ NEON available? - ldmia sp, {r0,r2} - beq Lialu - add sp,sp,#8 - b bn_mul8x_mont_neon -.align 4 -Lialu: -#endif cmp ip,#2 mov r0,ip @ load num #ifdef __thumb2__ @@ -209,11 +185,13 @@ Labrt: +.globl _bn_mul8x_mont_neon +.private_extern _bn_mul8x_mont_neon #ifdef __thumb2__ -.thumb_func bn_mul8x_mont_neon +.thumb_func _bn_mul8x_mont_neon #endif .align 5 -bn_mul8x_mont_neon: +_bn_mul8x_mont_neon: mov ip,sp stmdb sp!,{r4,r5,r6,r7,r8,r9,r10,r11} vstmdb sp!,{d8,d9,d10,d11,d12,d13,d14,d15} @ ABI specification says so @@ -964,15 +942,6 @@ LNEON_copy_n_zap: #endif .byte 77,111,110,116,103,111,109,101,114,121,32,109,117,108,116,105,112,108,105,99,97,116,105,111,110,32,102,111,114,32,65,82,77,118,52,47,78,69,79,78,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 -.align 2 -#if __ARM_MAX_ARCH__>=7 -.comm _OPENSSL_armcap_P,4 -.non_lazy_symbol_pointer -OPENSSL_armcap_P: -.indirect_symbol _OPENSSL_armcap_P -.long 0 -.private_extern _OPENSSL_armcap_P -#endif #endif // !OPENSSL_NO_ASM && defined(OPENSSL_ARM) && defined(__APPLE__) #endif // defined(__arm__) && defined(__APPLE__) #if defined(__linux__) && defined(__ELF__) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/armv4-mont-linux.linux.arm.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/armv4-mont-linux.linux.arm.S index eb8b27ca..bbec47b3 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/armv4-mont-linux.linux.arm.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/armv4-mont-linux.linux.arm.S @@ -20,38 +20,14 @@ .code 32 #endif -#if __ARM_MAX_ARCH__>=7 -.align 5 -.LOPENSSL_armcap: -.word OPENSSL_armcap_P-.Lbn_mul_mont -#endif - -.globl bn_mul_mont -.hidden bn_mul_mont -.type bn_mul_mont,%function +.globl bn_mul_mont_nohw +.hidden bn_mul_mont_nohw +.type bn_mul_mont_nohw,%function .align 5 -bn_mul_mont: -.Lbn_mul_mont: +bn_mul_mont_nohw: ldr ip,[sp,#4] @ load num stmdb sp!,{r0,r2} @ sp points at argument block -#if __ARM_MAX_ARCH__>=7 - tst ip,#7 - bne .Lialu - adr r0,.Lbn_mul_mont - ldr r2,.LOPENSSL_armcap - ldr r0,[r0,r2] -#ifdef __APPLE__ - ldr r0,[r0] -#endif - tst r0,#ARMV7_NEON @ NEON available? - ldmia sp, {r0,r2} - beq .Lialu - add sp,sp,#8 - b bn_mul8x_mont_neon -.align 4 -.Lialu: -#endif cmp ip,#2 mov r0,ip @ load num #ifdef __thumb2__ @@ -202,11 +178,13 @@ bn_mul_mont: moveq pc,lr @ be binary compatible with V4, yet .word 0xe12fff1e @ interoperable with Thumb ISA:-) #endif -.size bn_mul_mont,.-bn_mul_mont +.size bn_mul_mont_nohw,.-bn_mul_mont_nohw #if __ARM_MAX_ARCH__>=7 .arch armv7-a .fpu neon +.globl bn_mul8x_mont_neon +.hidden bn_mul8x_mont_neon .type bn_mul8x_mont_neon,%function .align 5 bn_mul8x_mont_neon: @@ -960,11 +938,6 @@ bn_mul8x_mont_neon: #endif .byte 77,111,110,116,103,111,109,101,114,121,32,109,117,108,116,105,112,108,105,99,97,116,105,111,110,32,102,111,114,32,65,82,77,118,52,47,78,69,79,78,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 -.align 2 -#if __ARM_MAX_ARCH__>=7 -.comm OPENSSL_armcap_P,4,4 -.hidden OPENSSL_armcap_P -#endif #endif // !OPENSSL_NO_ASM && defined(OPENSSL_ARM) && defined(__ELF__) #endif // defined(__arm__) && defined(__linux__) #if defined(__linux__) && defined(__ELF__) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn-586-windows.windows.x86.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn-586-windows.windows.x86.S index 96f2c132..d700276e 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn-586-windows.windows.x86.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn-586-windows.windows.x86.S @@ -15,10 +15,104 @@ section .text code align=64 %else section .text code %endif +;extern _OPENSSL_ia32cap_P global _bn_mul_add_words align 16 _bn_mul_add_words: L$_bn_mul_add_words_begin: + lea eax,[_OPENSSL_ia32cap_P] + bt DWORD [eax],26 + jnc NEAR L$000maw_non_sse2 + mov eax,DWORD [4+esp] + mov edx,DWORD [8+esp] + mov ecx,DWORD [12+esp] + movd mm0,DWORD [16+esp] + pxor mm1,mm1 + jmp NEAR L$001maw_sse2_entry +align 16 +L$002maw_sse2_unrolled: + movd mm3,DWORD [eax] + paddq mm1,mm3 + movd mm2,DWORD [edx] + pmuludq mm2,mm0 + movd mm4,DWORD [4+edx] + pmuludq mm4,mm0 + movd mm6,DWORD [8+edx] + pmuludq mm6,mm0 + movd mm7,DWORD [12+edx] + pmuludq mm7,mm0 + paddq mm1,mm2 + movd mm3,DWORD [4+eax] + paddq mm3,mm4 + movd mm5,DWORD [8+eax] + paddq mm5,mm6 + movd mm4,DWORD [12+eax] + paddq mm7,mm4 + movd DWORD [eax],mm1 + movd mm2,DWORD [16+edx] + pmuludq mm2,mm0 + psrlq mm1,32 + movd mm4,DWORD [20+edx] + pmuludq mm4,mm0 + paddq mm1,mm3 + movd mm6,DWORD [24+edx] + pmuludq mm6,mm0 + movd DWORD [4+eax],mm1 + psrlq mm1,32 + movd mm3,DWORD [28+edx] + add edx,32 + pmuludq mm3,mm0 + paddq mm1,mm5 + movd mm5,DWORD [16+eax] + paddq mm2,mm5 + movd DWORD [8+eax],mm1 + psrlq mm1,32 + paddq mm1,mm7 + movd mm5,DWORD [20+eax] + paddq mm4,mm5 + movd DWORD [12+eax],mm1 + psrlq mm1,32 + paddq mm1,mm2 + movd mm5,DWORD [24+eax] + paddq mm6,mm5 + movd DWORD [16+eax],mm1 + psrlq mm1,32 + paddq mm1,mm4 + movd mm5,DWORD [28+eax] + paddq mm3,mm5 + movd DWORD [20+eax],mm1 + psrlq mm1,32 + paddq mm1,mm6 + movd DWORD [24+eax],mm1 + psrlq mm1,32 + paddq mm1,mm3 + movd DWORD [28+eax],mm1 + lea eax,[32+eax] + psrlq mm1,32 + sub ecx,8 + jz NEAR L$003maw_sse2_exit +L$001maw_sse2_entry: + test ecx,4294967288 + jnz NEAR L$002maw_sse2_unrolled +align 4 +L$004maw_sse2_loop: + movd mm2,DWORD [edx] + movd mm3,DWORD [eax] + pmuludq mm2,mm0 + lea edx,[4+edx] + paddq mm1,mm3 + paddq mm1,mm2 + movd DWORD [eax],mm1 + sub ecx,1 + psrlq mm1,32 + lea eax,[4+eax] + jnz NEAR L$004maw_sse2_loop +L$003maw_sse2_exit: + movd eax,mm1 + emms + ret +align 16 +L$000maw_non_sse2: push ebp push ebx push esi @@ -31,9 +125,9 @@ L$_bn_mul_add_words_begin: and ecx,4294967288 mov ebp,DWORD [32+esp] push ecx - jz NEAR L$000maw_finish + jz NEAR L$005maw_finish align 16 -L$001maw_loop: +L$006maw_loop: ; Round 0 mov eax,DWORD [ebx] mul ebp @@ -110,13 +204,13 @@ L$001maw_loop: sub ecx,8 lea ebx,[32+ebx] lea edi,[32+edi] - jnz NEAR L$001maw_loop -L$000maw_finish: + jnz NEAR L$006maw_loop +L$005maw_finish: mov ecx,DWORD [32+esp] and ecx,7 - jnz NEAR L$002maw_finish2 - jmp NEAR L$003maw_end -L$002maw_finish2: + jnz NEAR L$007maw_finish2 + jmp NEAR L$008maw_end +L$007maw_finish2: ; Tail Round 0 mov eax,DWORD [ebx] mul ebp @@ -127,7 +221,7 @@ L$002maw_finish2: dec ecx mov DWORD [edi],eax mov esi,edx - jz NEAR L$003maw_end + jz NEAR L$008maw_end ; Tail Round 1 mov eax,DWORD [4+ebx] mul ebp @@ -138,7 +232,7 @@ L$002maw_finish2: dec ecx mov DWORD [4+edi],eax mov esi,edx - jz NEAR L$003maw_end + jz NEAR L$008maw_end ; Tail Round 2 mov eax,DWORD [8+ebx] mul ebp @@ -149,7 +243,7 @@ L$002maw_finish2: dec ecx mov DWORD [8+edi],eax mov esi,edx - jz NEAR L$003maw_end + jz NEAR L$008maw_end ; Tail Round 3 mov eax,DWORD [12+ebx] mul ebp @@ -160,7 +254,7 @@ L$002maw_finish2: dec ecx mov DWORD [12+edi],eax mov esi,edx - jz NEAR L$003maw_end + jz NEAR L$008maw_end ; Tail Round 4 mov eax,DWORD [16+ebx] mul ebp @@ -171,7 +265,7 @@ L$002maw_finish2: dec ecx mov DWORD [16+edi],eax mov esi,edx - jz NEAR L$003maw_end + jz NEAR L$008maw_end ; Tail Round 5 mov eax,DWORD [20+ebx] mul ebp @@ -182,7 +276,7 @@ L$002maw_finish2: dec ecx mov DWORD [20+edi],eax mov esi,edx - jz NEAR L$003maw_end + jz NEAR L$008maw_end ; Tail Round 6 mov eax,DWORD [24+ebx] mul ebp @@ -192,7 +286,7 @@ L$002maw_finish2: adc edx,0 mov DWORD [24+edi],eax mov esi,edx -L$003maw_end: +L$008maw_end: mov eax,esi pop ecx pop edi @@ -204,6 +298,30 @@ global _bn_mul_words align 16 _bn_mul_words: L$_bn_mul_words_begin: + lea eax,[_OPENSSL_ia32cap_P] + bt DWORD [eax],26 + jnc NEAR L$009mw_non_sse2 + mov eax,DWORD [4+esp] + mov edx,DWORD [8+esp] + mov ecx,DWORD [12+esp] + movd mm0,DWORD [16+esp] + pxor mm1,mm1 +align 16 +L$010mw_sse2_loop: + movd mm2,DWORD [edx] + pmuludq mm2,mm0 + lea edx,[4+edx] + paddq mm1,mm2 + movd DWORD [eax],mm1 + sub ecx,1 + psrlq mm1,32 + lea eax,[4+eax] + jnz NEAR L$010mw_sse2_loop + movd eax,mm1 + emms + ret +align 16 +L$009mw_non_sse2: push ebp push ebx push esi @@ -215,8 +333,8 @@ L$_bn_mul_words_begin: mov ebp,DWORD [28+esp] mov ecx,DWORD [32+esp] and ebp,4294967288 - jz NEAR L$004mw_finish -L$005mw_loop: + jz NEAR L$011mw_finish +L$012mw_loop: ; Round 0 mov eax,DWORD [ebx] mul ecx @@ -277,14 +395,14 @@ L$005mw_loop: add ebx,32 add edi,32 sub ebp,8 - jz NEAR L$004mw_finish - jmp NEAR L$005mw_loop -L$004mw_finish: + jz NEAR L$011mw_finish + jmp NEAR L$012mw_loop +L$011mw_finish: mov ebp,DWORD [28+esp] and ebp,7 - jnz NEAR L$006mw_finish2 - jmp NEAR L$007mw_end -L$006mw_finish2: + jnz NEAR L$013mw_finish2 + jmp NEAR L$014mw_end +L$013mw_finish2: ; Tail Round 0 mov eax,DWORD [ebx] mul ecx @@ -293,7 +411,7 @@ L$006mw_finish2: mov DWORD [edi],eax mov esi,edx dec ebp - jz NEAR L$007mw_end + jz NEAR L$014mw_end ; Tail Round 1 mov eax,DWORD [4+ebx] mul ecx @@ -302,7 +420,7 @@ L$006mw_finish2: mov DWORD [4+edi],eax mov esi,edx dec ebp - jz NEAR L$007mw_end + jz NEAR L$014mw_end ; Tail Round 2 mov eax,DWORD [8+ebx] mul ecx @@ -311,7 +429,7 @@ L$006mw_finish2: mov DWORD [8+edi],eax mov esi,edx dec ebp - jz NEAR L$007mw_end + jz NEAR L$014mw_end ; Tail Round 3 mov eax,DWORD [12+ebx] mul ecx @@ -320,7 +438,7 @@ L$006mw_finish2: mov DWORD [12+edi],eax mov esi,edx dec ebp - jz NEAR L$007mw_end + jz NEAR L$014mw_end ; Tail Round 4 mov eax,DWORD [16+ebx] mul ecx @@ -329,7 +447,7 @@ L$006mw_finish2: mov DWORD [16+edi],eax mov esi,edx dec ebp - jz NEAR L$007mw_end + jz NEAR L$014mw_end ; Tail Round 5 mov eax,DWORD [20+ebx] mul ecx @@ -338,7 +456,7 @@ L$006mw_finish2: mov DWORD [20+edi],eax mov esi,edx dec ebp - jz NEAR L$007mw_end + jz NEAR L$014mw_end ; Tail Round 6 mov eax,DWORD [24+ebx] mul ecx @@ -346,7 +464,7 @@ L$006mw_finish2: adc edx,0 mov DWORD [24+edi],eax mov esi,edx -L$007mw_end: +L$014mw_end: mov eax,esi pop edi pop esi @@ -357,6 +475,25 @@ global _bn_sqr_words align 16 _bn_sqr_words: L$_bn_sqr_words_begin: + lea eax,[_OPENSSL_ia32cap_P] + bt DWORD [eax],26 + jnc NEAR L$015sqr_non_sse2 + mov eax,DWORD [4+esp] + mov edx,DWORD [8+esp] + mov ecx,DWORD [12+esp] +align 16 +L$016sqr_sse2_loop: + movd mm0,DWORD [edx] + pmuludq mm0,mm0 + lea edx,[4+edx] + movq [eax],mm0 + sub ecx,1 + lea eax,[8+eax] + jnz NEAR L$016sqr_sse2_loop + emms + ret +align 16 +L$015sqr_non_sse2: push ebp push ebx push esi @@ -366,8 +503,8 @@ L$_bn_sqr_words_begin: mov edi,DWORD [24+esp] mov ebx,DWORD [28+esp] and ebx,4294967288 - jz NEAR L$008sw_finish -L$009sw_loop: + jz NEAR L$017sw_finish +L$018sw_loop: ; Round 0 mov eax,DWORD [edi] mul eax @@ -412,59 +549,59 @@ L$009sw_loop: add edi,32 add esi,64 sub ebx,8 - jnz NEAR L$009sw_loop -L$008sw_finish: + jnz NEAR L$018sw_loop +L$017sw_finish: mov ebx,DWORD [28+esp] and ebx,7 - jz NEAR L$010sw_end + jz NEAR L$019sw_end ; Tail Round 0 mov eax,DWORD [edi] mul eax mov DWORD [esi],eax dec ebx mov DWORD [4+esi],edx - jz NEAR L$010sw_end + jz NEAR L$019sw_end ; Tail Round 1 mov eax,DWORD [4+edi] mul eax mov DWORD [8+esi],eax dec ebx mov DWORD [12+esi],edx - jz NEAR L$010sw_end + jz NEAR L$019sw_end ; Tail Round 2 mov eax,DWORD [8+edi] mul eax mov DWORD [16+esi],eax dec ebx mov DWORD [20+esi],edx - jz NEAR L$010sw_end + jz NEAR L$019sw_end ; Tail Round 3 mov eax,DWORD [12+edi] mul eax mov DWORD [24+esi],eax dec ebx mov DWORD [28+esi],edx - jz NEAR L$010sw_end + jz NEAR L$019sw_end ; Tail Round 4 mov eax,DWORD [16+edi] mul eax mov DWORD [32+esi],eax dec ebx mov DWORD [36+esi],edx - jz NEAR L$010sw_end + jz NEAR L$019sw_end ; Tail Round 5 mov eax,DWORD [20+edi] mul eax mov DWORD [40+esi],eax dec ebx mov DWORD [44+esi],edx - jz NEAR L$010sw_end + jz NEAR L$019sw_end ; Tail Round 6 mov eax,DWORD [24+edi] mul eax mov DWORD [48+esi],eax mov DWORD [52+esi],edx -L$010sw_end: +L$019sw_end: pop edi pop esi pop ebx @@ -494,8 +631,8 @@ L$_bn_add_words_begin: mov ebp,DWORD [32+esp] xor eax,eax and ebp,4294967288 - jz NEAR L$011aw_finish -L$012aw_loop: + jz NEAR L$020aw_finish +L$021aw_loop: ; Round 0 mov ecx,DWORD [esi] mov edx,DWORD [edi] @@ -573,11 +710,11 @@ L$012aw_loop: add edi,32 add ebx,32 sub ebp,8 - jnz NEAR L$012aw_loop -L$011aw_finish: + jnz NEAR L$021aw_loop +L$020aw_finish: mov ebp,DWORD [32+esp] and ebp,7 - jz NEAR L$013aw_end + jz NEAR L$022aw_end ; Tail Round 0 mov ecx,DWORD [esi] mov edx,DWORD [edi] @@ -588,7 +725,7 @@ L$011aw_finish: adc eax,0 dec ebp mov DWORD [ebx],ecx - jz NEAR L$013aw_end + jz NEAR L$022aw_end ; Tail Round 1 mov ecx,DWORD [4+esi] mov edx,DWORD [4+edi] @@ -599,7 +736,7 @@ L$011aw_finish: adc eax,0 dec ebp mov DWORD [4+ebx],ecx - jz NEAR L$013aw_end + jz NEAR L$022aw_end ; Tail Round 2 mov ecx,DWORD [8+esi] mov edx,DWORD [8+edi] @@ -610,7 +747,7 @@ L$011aw_finish: adc eax,0 dec ebp mov DWORD [8+ebx],ecx - jz NEAR L$013aw_end + jz NEAR L$022aw_end ; Tail Round 3 mov ecx,DWORD [12+esi] mov edx,DWORD [12+edi] @@ -621,7 +758,7 @@ L$011aw_finish: adc eax,0 dec ebp mov DWORD [12+ebx],ecx - jz NEAR L$013aw_end + jz NEAR L$022aw_end ; Tail Round 4 mov ecx,DWORD [16+esi] mov edx,DWORD [16+edi] @@ -632,7 +769,7 @@ L$011aw_finish: adc eax,0 dec ebp mov DWORD [16+ebx],ecx - jz NEAR L$013aw_end + jz NEAR L$022aw_end ; Tail Round 5 mov ecx,DWORD [20+esi] mov edx,DWORD [20+edi] @@ -643,7 +780,7 @@ L$011aw_finish: adc eax,0 dec ebp mov DWORD [20+ebx],ecx - jz NEAR L$013aw_end + jz NEAR L$022aw_end ; Tail Round 6 mov ecx,DWORD [24+esi] mov edx,DWORD [24+edi] @@ -653,7 +790,7 @@ L$011aw_finish: add ecx,edx adc eax,0 mov DWORD [24+ebx],ecx -L$013aw_end: +L$022aw_end: pop edi pop esi pop ebx @@ -674,8 +811,8 @@ L$_bn_sub_words_begin: mov ebp,DWORD [32+esp] xor eax,eax and ebp,4294967288 - jz NEAR L$014aw_finish -L$015aw_loop: + jz NEAR L$023aw_finish +L$024aw_loop: ; Round 0 mov ecx,DWORD [esi] mov edx,DWORD [edi] @@ -753,11 +890,11 @@ L$015aw_loop: add edi,32 add ebx,32 sub ebp,8 - jnz NEAR L$015aw_loop -L$014aw_finish: + jnz NEAR L$024aw_loop +L$023aw_finish: mov ebp,DWORD [32+esp] and ebp,7 - jz NEAR L$016aw_end + jz NEAR L$025aw_end ; Tail Round 0 mov ecx,DWORD [esi] mov edx,DWORD [edi] @@ -768,7 +905,7 @@ L$014aw_finish: adc eax,0 dec ebp mov DWORD [ebx],ecx - jz NEAR L$016aw_end + jz NEAR L$025aw_end ; Tail Round 1 mov ecx,DWORD [4+esi] mov edx,DWORD [4+edi] @@ -779,7 +916,7 @@ L$014aw_finish: adc eax,0 dec ebp mov DWORD [4+ebx],ecx - jz NEAR L$016aw_end + jz NEAR L$025aw_end ; Tail Round 2 mov ecx,DWORD [8+esi] mov edx,DWORD [8+edi] @@ -790,7 +927,7 @@ L$014aw_finish: adc eax,0 dec ebp mov DWORD [8+ebx],ecx - jz NEAR L$016aw_end + jz NEAR L$025aw_end ; Tail Round 3 mov ecx,DWORD [12+esi] mov edx,DWORD [12+edi] @@ -801,7 +938,7 @@ L$014aw_finish: adc eax,0 dec ebp mov DWORD [12+ebx],ecx - jz NEAR L$016aw_end + jz NEAR L$025aw_end ; Tail Round 4 mov ecx,DWORD [16+esi] mov edx,DWORD [16+edi] @@ -812,7 +949,7 @@ L$014aw_finish: adc eax,0 dec ebp mov DWORD [16+ebx],ecx - jz NEAR L$016aw_end + jz NEAR L$025aw_end ; Tail Round 5 mov ecx,DWORD [20+esi] mov edx,DWORD [20+edi] @@ -823,7 +960,7 @@ L$014aw_finish: adc eax,0 dec ebp mov DWORD [20+ebx],ecx - jz NEAR L$016aw_end + jz NEAR L$025aw_end ; Tail Round 6 mov ecx,DWORD [24+esi] mov edx,DWORD [24+edi] @@ -833,12 +970,14 @@ L$014aw_finish: sub ecx,edx adc eax,0 mov DWORD [24+ebx],ecx -L$016aw_end: +L$025aw_end: pop edi pop esi pop ebx pop ebp ret +segment .bss +common _OPENSSL_ia32cap_P 16 %else ; Work around https://bugzilla.nasm.us/show_bug.cgi?id=3392738 ret diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn/bytes.c b/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn/bytes.c index 83f13576..e3475518 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn/bytes.c +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn/bytes.c @@ -63,26 +63,31 @@ void bn_big_endian_to_words(BN_ULONG *out, size_t out_len, const uint8_t *in, size_t in_len) { - for (size_t i = 0; i < out_len; i++) { - if (in_len < sizeof(BN_ULONG)) { - // Load the last partial word. - BN_ULONG word = 0; - for (size_t j = 0; j < in_len; j++) { - word = (word << 8) | in[j]; - } - in_len = 0; - out[i] = word; - // Fill the remainder with zeros. - OPENSSL_memset(out + i + 1, 0, (out_len - i - 1) * sizeof(BN_ULONG)); - break; - } + // The caller should have sized |out| to fit |in| without truncating. This + // condition ensures we do not overflow |out|, so use a runtime check. + BSSL_CHECK(in_len <= out_len * sizeof(BN_ULONG)); + // Load whole words. + while (in_len >= sizeof(BN_ULONG)) { in_len -= sizeof(BN_ULONG); - out[i] = CRYPTO_load_word_be(in + in_len); + out[0] = CRYPTO_load_word_be(in + in_len); + out++; + out_len--; } - // The caller should have sized the output to avoid truncation. - assert(in_len == 0); + // Load the last partial word. + if (in_len != 0) { + BN_ULONG word = 0; + for (size_t i = 0; i < in_len; i++) { + word = (word << 8) | in[i]; + } + out[0] = word; + out++; + out_len--; + } + + // Fill the remainder with zeros. + OPENSSL_memset(out, 0, out_len * sizeof(BN_ULONG)); } BIGNUM *BN_bin2bn(const uint8_t *in, size_t len, BIGNUM *ret) { diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn/exponentiation.c b/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn/exponentiation.c index 7494fd37..64b52572 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn/exponentiation.c +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn/exponentiation.c @@ -898,7 +898,9 @@ int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p, OPENSSL_PUT_ERROR(BN, BN_R_NEGATIVE_NUMBER); return 0; } - if (a->neg || BN_ucmp(a, m) >= 0) { + // |a| is secret, but it is required to be in range, so these comparisons may + // be leaked. + if (a->neg || constant_time_declassify_int(BN_ucmp(a, m) >= 0)) { OPENSSL_PUT_ERROR(BN, BN_R_INPUT_NOT_REDUCED); return 0; } diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn/gcd.c b/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn/gcd.c index cfdb84d3..fd2515f9 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn/gcd.c +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn/gcd.c @@ -327,7 +327,10 @@ int BN_mod_inverse_blinded(BIGNUM *out, int *out_no_inverse, const BIGNUM *a, const BN_MONT_CTX *mont, BN_CTX *ctx) { *out_no_inverse = 0; - if (BN_is_negative(a) || BN_cmp(a, &mont->N) >= 0) { + // |a| is secret, but it is required to be in range, so these comparisons may + // be leaked. + if (BN_is_negative(a) || + constant_time_declassify_int(BN_cmp(a, &mont->N) >= 0)) { OPENSSL_PUT_ERROR(BN, BN_R_INPUT_NOT_REDUCED); return 0; } @@ -336,11 +339,29 @@ int BN_mod_inverse_blinded(BIGNUM *out, int *out_no_inverse, const BIGNUM *a, BIGNUM blinding_factor; BN_init(&blinding_factor); - if (!BN_rand_range_ex(&blinding_factor, 1, &mont->N) || - !BN_mod_mul_montgomery(out, &blinding_factor, a, mont, ctx) || - !BN_mod_inverse_odd(out, out_no_inverse, out, &mont->N, ctx) || + // |BN_mod_inverse_odd| is leaky, so generate a secret blinding factor and + // blind |a|. This works because (ar)^-1 * r = a^-1, supposing r is + // invertible. If r is not invertible, this function will fail. However, we + // only use this in RSA, where stumbling on an uninvertible element means + // stumbling on the key's factorization. That is, if this function fails, the + // RSA key was not actually a product of two large primes. + // + // TODO(crbug.com/boringssl/677): When the PRNG output is marked secret by + // default, the explicit |bn_secret| call can be removed. + if (!BN_rand_range_ex(&blinding_factor, 1, &mont->N)) { + goto err; + } + bn_secret(&blinding_factor); + if (!BN_mod_mul_montgomery(out, &blinding_factor, a, mont, ctx)) { + goto err; + } + + // Once blinded, |out| is no longer secret, so it may be passed to a leaky + // mod inverse function. Note |blinding_factor| is secret, so |out| will be + // secret again after multiplying. + bn_declassify(out); + if (!BN_mod_inverse_odd(out, out_no_inverse, out, &mont->N, ctx) || !BN_mod_mul_montgomery(out, &blinding_factor, out, mont, ctx)) { - OPENSSL_PUT_ERROR(BN, ERR_R_BN_LIB); goto err; } diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn/internal.h b/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn/internal.h index e372412b..dd3ee9fc 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn/internal.h +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn/internal.h @@ -149,6 +149,7 @@ extern "C" { #endif #define BN_BITS2 64 +#define BN_BITS2_LG 6 #define BN_BYTES 8 #define BN_BITS4 32 #define BN_MASK2 (0xffffffffffffffffUL) @@ -165,6 +166,7 @@ extern "C" { #define BN_ULLONG uint64_t #define BN_CAN_DIVIDE_ULLONG #define BN_BITS2 32 +#define BN_BITS2_LG 5 #define BN_BYTES 4 #define BN_BITS4 16 #define BN_MASK2 (0xffffffffUL) @@ -269,6 +271,18 @@ int bn_copy_words(BN_ULONG *out, size_t num, const BIGNUM *bn); // validation. void bn_assert_fits_in_bytes(const BIGNUM *bn, size_t num); +// bn_secret marks |bn|'s contents, but not its width or sign, as secret. See +// |CONSTTIME_SECRET| for details. +OPENSSL_INLINE void bn_secret(BIGNUM *bn) { + CONSTTIME_SECRET(bn->d, bn->width * sizeof(BN_ULONG)); +} + +// bn_declassify marks |bn|'s value as public. See |CONSTTIME_DECLASSIFY| for +// details. +OPENSSL_INLINE void bn_declassify(BIGNUM *bn) { + CONSTTIME_DECLASSIFY(bn->d, bn->width * sizeof(BN_ULONG)); +} + // bn_mul_add_words multiples |ap| by |w|, adds the result to |rp|, and places // the result in |rp|. |ap| and |rp| must both be |num| words long. It returns // the carry word of the operation. |ap| and |rp| may be equal but otherwise may @@ -386,8 +400,41 @@ int bn_rand_secret_range(BIGNUM *r, int *out_is_uniform, BN_ULONG min_inclusive, // inputs. int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, const BN_ULONG *np, const BN_ULONG *n0, size_t num); + +#if defined(OPENSSL_X86_64) +OPENSSL_INLINE int bn_mulx_adx_capable(void) { + // MULX is in BMI2. + return CRYPTO_is_BMI2_capable() && CRYPTO_is_ADX_capable(); +} +int bn_mul_mont_nohw(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, + const BN_ULONG *np, const BN_ULONG *n0, size_t num); +OPENSSL_INLINE int bn_mul4x_mont_capable(size_t num) { + return num >= 8 && (num & 3) == 0; +} +int bn_mul4x_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, + const BN_ULONG *np, const BN_ULONG *n0, size_t num); +OPENSSL_INLINE int bn_mulx4x_mont_capable(size_t num) { + return bn_mul4x_mont_capable(num) && bn_mulx_adx_capable(); +} +int bn_mulx4x_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, + const BN_ULONG *np, const BN_ULONG *n0, size_t num); +OPENSSL_INLINE int bn_sqr8x_mont_capable(size_t num) { + return num >= 8 && (num & 7) == 0; +} +int bn_sqr8x_mont(BN_ULONG *rp, const BN_ULONG *ap, BN_ULONG mulx_adx_capable, + const BN_ULONG *np, const BN_ULONG *n0, size_t num); +#elif defined(OPENSSL_ARM) +OPENSSL_INLINE int bn_mul8x_mont_neon_capable(size_t num) { + return (num & 7) == 0 && CRYPTO_is_NEON_capable(); +} +int bn_mul8x_mont_neon(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, + const BN_ULONG *np, const BN_ULONG *n0, size_t num); +int bn_mul_mont_nohw(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, + const BN_ULONG *np, const BN_ULONG *n0, size_t num); #endif +#endif // OPENSSL_BN_ASM_MONT + #if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64) #define OPENSSL_BN_ASM_MONT5 @@ -754,8 +801,8 @@ void bn_mod_inverse0_prime_mont_small(BN_ULONG *r, const BN_ULONG *a, // bn_big_endian_to_words interprets |in_len| bytes from |in| as a big-endian, // unsigned integer and writes the result to |out_len| words in |out|. |out_len| -// must be large enough to represent any |in_len|-byte value. That is, |out_len| -// must be at least |BN_BYTES * in_len|. +// must be large enough to represent any |in_len|-byte value. That is, |in_len| +// must be at most |BN_BYTES * out_len|. void bn_big_endian_to_words(BN_ULONG *out, size_t out_len, const uint8_t *in, size_t in_len); diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn/montgomery.c b/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn/montgomery.c index 530875f5..56474234 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn/montgomery.c +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn/montgomery.c @@ -504,3 +504,29 @@ void bn_mod_mul_montgomery_small(BN_ULONG *r, const BN_ULONG *a, } OPENSSL_cleanse(tmp, 2 * num * sizeof(BN_ULONG)); } + +#if defined(OPENSSL_BN_ASM_MONT) && defined(OPENSSL_X86_64) +int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, + const BN_ULONG *np, const BN_ULONG *n0, size_t num) { + if (ap == bp && bn_sqr8x_mont_capable(num)) { + return bn_sqr8x_mont(rp, ap, bn_mulx_adx_capable(), np, n0, num); + } + if (bn_mulx4x_mont_capable(num)) { + return bn_mulx4x_mont(rp, ap, bp, np, n0, num); + } + if (bn_mul4x_mont_capable(num)) { + return bn_mul4x_mont(rp, ap, bp, np, n0, num); + } + return bn_mul_mont_nohw(rp, ap, bp, np, n0, num); +} +#endif + +#if defined(OPENSSL_BN_ASM_MONT) && defined(OPENSSL_ARM) +int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, + const BN_ULONG *np, const BN_ULONG *n0, size_t num) { + if (bn_mul8x_mont_neon_capable(num)) { + return bn_mul8x_mont_neon(rp, ap, bp, np, n0, num); + } + return bn_mul_mont_nohw(rp, ap, bp, np, n0, num); +} +#endif diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn/montgomery_inv.c b/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn/montgomery_inv.c index 1929dbdb..1f71dd44 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn/montgomery_inv.c +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn/montgomery_inv.c @@ -179,42 +179,43 @@ int bn_mont_ctx_set_RR_consttime(BN_MONT_CTX *mont, BN_CTX *ctx) { // Montgomery domain, 2R or 2^(lgBigR+1), and then use Montgomery // square-and-multiply to exponentiate. // - // The multiply steps take 2^n R to 2^(n+1) R. It is faster to double - // the value instead. The square steps take 2^n R to 2^(2n) R. This is - // equivalent to doubling n times. When n is below some threshold, doubling is - // faster. When above, squaring is faster. + // The square steps take 2^n R to (2^n)*(2^n) R = 2^2n R. This is the same as + // doubling 2^n R, n times (doubling any x, n times, computes 2^n * x). When n + // is below some threshold, doubling is faster; when above, squaring is + // faster. From benchmarking various 32-bit and 64-bit architectures, the word + // count seems to work well as a threshold. (Doubling scales linearly and + // Montgomery reduction scales quadratically, so the threshold should scale + // roughly linearly.) // - // We double to this threshold, then switch to Montgomery squaring. From - // benchmarking various 32-bit and 64-bit architectures, the word count seems - // to work well as a threshold. (Doubling scales linearly and Montgomery - // reduction scales quadratically, so the threshold should scale roughly - // linearly.) - unsigned threshold = mont->N.width; - unsigned iters; - for (iters = 0; iters < sizeof(lgBigR) * 8; iters++) { - if ((lgBigR >> iters) <= threshold) { - break; - } - } + // The multiply steps take 2^n R to 2*2^n R = 2^(n+1) R. It is faster to + // double the value instead, so the square-and-multiply exponentiation would + // become square-and-double. However, when using the word count as the + // threshold, it turns out that no multiply/double steps will be needed at + // all, because squaring any x, i times, computes x^(2^i): + // + // (2^threshold)^(2^BN_BITS2_LG) R + // (2^mont->N.width)^BN_BITS2 R + // = 2^(mont->N.width*BN_BITS2) R + // = 2^lgBigR R + // = RR + int threshold = mont->N.width; - // Compute 2^(lgBigR >> iters) R, or 2^((lgBigR >> iters) + lgBigR), by - // doubling. The first n_bits - 1 doubles can be skipped because we don't need - // to reduce. + // Calculate 2^threshold R = 2^(threshold + lgBigR) by doubling. The + // first n_bits - 1 doubles can be skipped because we don't need to reduce. if (!BN_set_bit(&mont->RR, n_bits - 1) || !bn_mod_lshift_consttime(&mont->RR, &mont->RR, - (lgBigR >> iters) + lgBigR - (n_bits - 1), + threshold + (lgBigR - (n_bits - 1)), &mont->N, ctx)) { return 0; } - for (unsigned i = iters - 1; i < iters; i--) { + // The above steps are the same regardless of the threshold. The steps below + // need to be modified if the threshold changes. + assert(threshold == mont->N.width); + for (unsigned i = 0; i < BN_BITS2_LG; i++) { if (!BN_mod_mul_montgomery(&mont->RR, &mont->RR, &mont->RR, mont, ctx)) { return 0; } - if ((lgBigR & (1u << i)) != 0 && - !bn_mod_lshift1_consttime(&mont->RR, &mont->RR, &mont->N, ctx)) { - return 0; - } } return bn_resize_words(&mont->RR, mont->N.width); diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn/random.c b/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn/random.c index 8301986a..91d337fd 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn/random.c +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/bn/random.c @@ -281,8 +281,14 @@ int bn_rand_range_words(BN_ULONG *out, BN_ULONG min_inclusive, out[words - 1] &= mask; // If out >= max_exclusive or out < min_inclusive, retry. This implements - // the equivalent of steps 6 and 7 without leaking the value of |out|. - } while (!bn_in_range_words(out, min_inclusive, max_exclusive, words)); + // the equivalent of steps 6 and 7 without leaking the value of |out|. The + // result of this comparison may be treated as public. It only reveals how + // many attempts were needed before we found a value in range. This is + // independent of the final secret output, and has a distribution that + // depends only on |min_inclusive| and |max_exclusive|, both of which are + // public. + } while (!constant_time_declassify_int( + bn_in_range_words(out, min_inclusive, max_exclusive, words))); return 1; } diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/cipher/e_aesccm.c b/Sources/CCryptoBoringSSL/crypto/fipsmodule/cipher/e_aesccm.c index cc8736db..01d6fce7 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/cipher/e_aesccm.c +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/cipher/e_aesccm.c @@ -55,6 +55,7 @@ #include #include "../delocate.h" +#include "../modes/internal.h" #include "../service_indicator/internal.h" #include "internal.h" @@ -66,10 +67,8 @@ struct ccm128_context { }; struct ccm128_state { - union { - uint64_t u[2]; - uint8_t c[16]; - } nonce, cmac; + alignas(16) uint8_t nonce[16]; + alignas(16) uint8_t cmac[16]; }; static int CRYPTO_ccm128_init(struct ccm128_context *ctx, const AES_KEY *key, @@ -107,16 +106,16 @@ static int ccm128_init_state(const struct ccm128_context *ctx, // Assemble the first block for computing the MAC. OPENSSL_memset(state, 0, sizeof(*state)); - state->nonce.c[0] = (uint8_t)((L - 1) | ((M - 2) / 2) << 3); + state->nonce[0] = (uint8_t)((L - 1) | ((M - 2) / 2) << 3); if (aad_len != 0) { - state->nonce.c[0] |= 0x40; // Set AAD Flag + state->nonce[0] |= 0x40; // Set AAD Flag } - OPENSSL_memcpy(&state->nonce.c[1], nonce, nonce_len); + OPENSSL_memcpy(&state->nonce[1], nonce, nonce_len); for (unsigned i = 0; i < L; i++) { - state->nonce.c[15 - i] = (uint8_t)(plaintext_len >> (8 * i)); + state->nonce[15 - i] = (uint8_t)(plaintext_len >> (8 * i)); } - (*block)(state->nonce.c, state->cmac.c, key); + (*block)(state->nonce, state->cmac, key); size_t blocks = 1; if (aad_len != 0) { @@ -124,38 +123,38 @@ static int ccm128_init_state(const struct ccm128_context *ctx, // Cast to u64 to avoid the compiler complaining about invalid shifts. uint64_t aad_len_u64 = aad_len; if (aad_len_u64 < 0x10000 - 0x100) { - state->cmac.c[0] ^= (uint8_t)(aad_len_u64 >> 8); - state->cmac.c[1] ^= (uint8_t)aad_len_u64; + state->cmac[0] ^= (uint8_t)(aad_len_u64 >> 8); + state->cmac[1] ^= (uint8_t)aad_len_u64; i = 2; } else if (aad_len_u64 <= 0xffffffff) { - state->cmac.c[0] ^= 0xff; - state->cmac.c[1] ^= 0xfe; - state->cmac.c[2] ^= (uint8_t)(aad_len_u64 >> 24); - state->cmac.c[3] ^= (uint8_t)(aad_len_u64 >> 16); - state->cmac.c[4] ^= (uint8_t)(aad_len_u64 >> 8); - state->cmac.c[5] ^= (uint8_t)aad_len_u64; + state->cmac[0] ^= 0xff; + state->cmac[1] ^= 0xfe; + state->cmac[2] ^= (uint8_t)(aad_len_u64 >> 24); + state->cmac[3] ^= (uint8_t)(aad_len_u64 >> 16); + state->cmac[4] ^= (uint8_t)(aad_len_u64 >> 8); + state->cmac[5] ^= (uint8_t)aad_len_u64; i = 6; } else { - state->cmac.c[0] ^= 0xff; - state->cmac.c[1] ^= 0xff; - state->cmac.c[2] ^= (uint8_t)(aad_len_u64 >> 56); - state->cmac.c[3] ^= (uint8_t)(aad_len_u64 >> 48); - state->cmac.c[4] ^= (uint8_t)(aad_len_u64 >> 40); - state->cmac.c[5] ^= (uint8_t)(aad_len_u64 >> 32); - state->cmac.c[6] ^= (uint8_t)(aad_len_u64 >> 24); - state->cmac.c[7] ^= (uint8_t)(aad_len_u64 >> 16); - state->cmac.c[8] ^= (uint8_t)(aad_len_u64 >> 8); - state->cmac.c[9] ^= (uint8_t)aad_len_u64; + state->cmac[0] ^= 0xff; + state->cmac[1] ^= 0xff; + state->cmac[2] ^= (uint8_t)(aad_len_u64 >> 56); + state->cmac[3] ^= (uint8_t)(aad_len_u64 >> 48); + state->cmac[4] ^= (uint8_t)(aad_len_u64 >> 40); + state->cmac[5] ^= (uint8_t)(aad_len_u64 >> 32); + state->cmac[6] ^= (uint8_t)(aad_len_u64 >> 24); + state->cmac[7] ^= (uint8_t)(aad_len_u64 >> 16); + state->cmac[8] ^= (uint8_t)(aad_len_u64 >> 8); + state->cmac[9] ^= (uint8_t)aad_len_u64; i = 10; } do { for (; i < 16 && aad_len != 0; i++) { - state->cmac.c[i] ^= *aad; + state->cmac[i] ^= *aad; aad++; aad_len--; } - (*block)(state->cmac.c, state->cmac.c, key); + (*block)(state->cmac, state->cmac, key); blocks++; i = 0; } while (aad_len != 0); @@ -174,7 +173,7 @@ static int ccm128_init_state(const struct ccm128_context *ctx, // Assemble the first block for encrypting and decrypting. The bottom |L| // bytes are replaced with a counter and all bit the encoding of |L| is // cleared in the first byte. - state->nonce.c[0] &= 7; + state->nonce[0] &= 7; return 1; } @@ -183,17 +182,17 @@ static int ccm128_encrypt(const struct ccm128_context *ctx, uint8_t *out, const uint8_t *in, size_t len) { // The counter for encryption begins at one. for (unsigned i = 0; i < ctx->L; i++) { - state->nonce.c[15 - i] = 0; + state->nonce[15 - i] = 0; } - state->nonce.c[15] = 1; + state->nonce[15] = 1; uint8_t partial_buf[16]; unsigned num = 0; if (ctx->ctr != NULL) { - CRYPTO_ctr128_encrypt_ctr32(in, out, len, key, state->nonce.c, partial_buf, + CRYPTO_ctr128_encrypt_ctr32(in, out, len, key, state->nonce, partial_buf, &num, ctx->ctr); } else { - CRYPTO_ctr128_encrypt(in, out, len, key, state->nonce.c, partial_buf, &num, + CRYPTO_ctr128_encrypt(in, out, len, key, state->nonce, partial_buf, &num, ctx->block); } return 1; @@ -209,34 +208,28 @@ static int ccm128_compute_mac(const struct ccm128_context *ctx, } // Incorporate |in| into the MAC. - union { - uint64_t u[2]; - uint8_t c[16]; - } tmp; while (len >= 16) { - OPENSSL_memcpy(tmp.c, in, 16); - state->cmac.u[0] ^= tmp.u[0]; - state->cmac.u[1] ^= tmp.u[1]; - (*block)(state->cmac.c, state->cmac.c, key); + CRYPTO_xor16(state->cmac, state->cmac, in); + (*block)(state->cmac, state->cmac, key); in += 16; len -= 16; } if (len > 0) { for (size_t i = 0; i < len; i++) { - state->cmac.c[i] ^= in[i]; + state->cmac[i] ^= in[i]; } - (*block)(state->cmac.c, state->cmac.c, key); + (*block)(state->cmac, state->cmac, key); } // Encrypt the MAC with counter zero. for (unsigned i = 0; i < ctx->L; i++) { - state->nonce.c[15 - i] = 0; + state->nonce[15 - i] = 0; } - (*block)(state->nonce.c, tmp.c, key); - state->cmac.u[0] ^= tmp.u[0]; - state->cmac.u[1] ^= tmp.u[1]; + alignas(16) uint8_t tmp[16]; + (*block)(state->nonce, tmp, key); + CRYPTO_xor16(state->cmac, state->cmac, tmp); - OPENSSL_memcpy(out_tag, state->cmac.c, tag_len); + OPENSSL_memcpy(out_tag, state->cmac, tag_len); return 1; } diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/digest/digest.c b/Sources/CCryptoBoringSSL/crypto/fipsmodule/digest/digest.c index 75da8ddc..d721a99b 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/digest/digest.c +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/digest/digest.c @@ -185,6 +185,10 @@ int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in) { void EVP_MD_CTX_move(EVP_MD_CTX *out, EVP_MD_CTX *in) { EVP_MD_CTX_cleanup(out); // While not guaranteed, |EVP_MD_CTX| is currently safe to move with |memcpy|. + // bssl-crypto currently relies on this, however, so if we change this, we + // need to box the |HMAC_CTX|. (Relying on this is only fine because we assume + // BoringSSL and bssl-crypto will always be updated atomically. We do not + // allow any version skew between the two.) OPENSSL_memcpy(out, in, sizeof(EVP_MD_CTX)); EVP_MD_CTX_init(in); } diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/ec/ec_key.c b/Sources/CCryptoBoringSSL/crypto/fipsmodule/ec/ec_key.c index 8fe478a4..57306177 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/ec/ec_key.c +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/ec/ec_key.c @@ -314,8 +314,10 @@ int EC_KEY_check_key(const EC_KEY *eckey) { OPENSSL_PUT_ERROR(EC, ERR_R_EC_LIB); return 0; } - if (!ec_GFp_simple_points_equal(eckey->group, &point, - &eckey->pub_key->raw)) { + // Leaking this comparison only leaks whether |eckey|'s public key was + // correct. + if (!constant_time_declassify_int(ec_GFp_simple_points_equal( + eckey->group, &point, &eckey->pub_key->raw))) { OPENSSL_PUT_ERROR(EC, EC_R_INVALID_PRIVATE_KEY); return 0; } @@ -500,6 +502,14 @@ int EC_KEY_generate_key(EC_KEY *key) { return 0; } + // The public key is derived from the private key, but it is public. + // + // TODO(crbug.com/boringssl/677): This isn't quite right. While |pub_key| + // represents a public point, it is still in Jacobian form and the exact + // Jacobian representation is secret. We need to make it affine first. See + // discussion in the bug. + CONSTTIME_DECLASSIFY(&pub_key->raw, sizeof(pub_key->raw)); + ec_wrapped_scalar_free(key->priv_key); key->priv_key = priv_key; EC_POINT_free(key->pub_key); @@ -524,12 +534,8 @@ int EC_KEY_generate_key_fips(EC_KEY *eckey) { int EC_KEY_get_ex_new_index(long argl, void *argp, CRYPTO_EX_unused *unused, CRYPTO_EX_dup *dup_unused, CRYPTO_EX_free *free_func) { - int index; - if (!CRYPTO_get_ex_new_index(g_ec_ex_data_class_bss_get(), &index, argl, argp, - free_func)) { - return -1; - } - return index; + return CRYPTO_get_ex_new_index_ex(g_ec_ex_data_class_bss_get(), argl, argp, + free_func); } int EC_KEY_set_ex_data(EC_KEY *d, int idx, void *arg) { diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-x86-windows.windows.x86.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-x86-windows.windows.x86.S index 8c5da15a..a47ab266 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-x86-windows.windows.x86.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-x86-windows.windows.x86.S @@ -15,6 +15,313 @@ section .text code align=64 %else section .text code %endif +global _gcm_init_clmul +align 16 +_gcm_init_clmul: +L$_gcm_init_clmul_begin: + mov edx,DWORD [4+esp] + mov eax,DWORD [8+esp] + call L$000pic +L$000pic: + pop ecx + lea ecx,[(L$bswap-L$000pic)+ecx] + movdqu xmm2,[eax] + pshufd xmm2,xmm2,78 + pshufd xmm4,xmm2,255 + movdqa xmm3,xmm2 + psllq xmm2,1 + pxor xmm5,xmm5 + psrlq xmm3,63 + pcmpgtd xmm5,xmm4 + pslldq xmm3,8 + por xmm2,xmm3 + pand xmm5,[16+ecx] + pxor xmm2,xmm5 + movdqa xmm0,xmm2 + movdqa xmm1,xmm0 + pshufd xmm3,xmm0,78 + pshufd xmm4,xmm2,78 + pxor xmm3,xmm0 + pxor xmm4,xmm2 +db 102,15,58,68,194,0 +db 102,15,58,68,202,17 +db 102,15,58,68,220,0 + xorps xmm3,xmm0 + xorps xmm3,xmm1 + movdqa xmm4,xmm3 + psrldq xmm3,8 + pslldq xmm4,8 + pxor xmm1,xmm3 + pxor xmm0,xmm4 + movdqa xmm4,xmm0 + movdqa xmm3,xmm0 + psllq xmm0,5 + pxor xmm3,xmm0 + psllq xmm0,1 + pxor xmm0,xmm3 + psllq xmm0,57 + movdqa xmm3,xmm0 + pslldq xmm0,8 + psrldq xmm3,8 + pxor xmm0,xmm4 + pxor xmm1,xmm3 + movdqa xmm4,xmm0 + psrlq xmm0,1 + pxor xmm1,xmm4 + pxor xmm4,xmm0 + psrlq xmm0,5 + pxor xmm0,xmm4 + psrlq xmm0,1 + pxor xmm0,xmm1 + pshufd xmm3,xmm2,78 + pshufd xmm4,xmm0,78 + pxor xmm3,xmm2 + movdqu [edx],xmm2 + pxor xmm4,xmm0 + movdqu [16+edx],xmm0 +db 102,15,58,15,227,8 + movdqu [32+edx],xmm4 + ret +global _gcm_gmult_clmul +align 16 +_gcm_gmult_clmul: +L$_gcm_gmult_clmul_begin: + mov eax,DWORD [4+esp] + mov edx,DWORD [8+esp] + call L$001pic +L$001pic: + pop ecx + lea ecx,[(L$bswap-L$001pic)+ecx] + movdqu xmm0,[eax] + movdqa xmm5,[ecx] + movups xmm2,[edx] +db 102,15,56,0,197 + movups xmm4,[32+edx] + movdqa xmm1,xmm0 + pshufd xmm3,xmm0,78 + pxor xmm3,xmm0 +db 102,15,58,68,194,0 +db 102,15,58,68,202,17 +db 102,15,58,68,220,0 + xorps xmm3,xmm0 + xorps xmm3,xmm1 + movdqa xmm4,xmm3 + psrldq xmm3,8 + pslldq xmm4,8 + pxor xmm1,xmm3 + pxor xmm0,xmm4 + movdqa xmm4,xmm0 + movdqa xmm3,xmm0 + psllq xmm0,5 + pxor xmm3,xmm0 + psllq xmm0,1 + pxor xmm0,xmm3 + psllq xmm0,57 + movdqa xmm3,xmm0 + pslldq xmm0,8 + psrldq xmm3,8 + pxor xmm0,xmm4 + pxor xmm1,xmm3 + movdqa xmm4,xmm0 + psrlq xmm0,1 + pxor xmm1,xmm4 + pxor xmm4,xmm0 + psrlq xmm0,5 + pxor xmm0,xmm4 + psrlq xmm0,1 + pxor xmm0,xmm1 +db 102,15,56,0,197 + movdqu [eax],xmm0 + ret +global _gcm_ghash_clmul +align 16 +_gcm_ghash_clmul: +L$_gcm_ghash_clmul_begin: + push ebp + push ebx + push esi + push edi + mov eax,DWORD [20+esp] + mov edx,DWORD [24+esp] + mov esi,DWORD [28+esp] + mov ebx,DWORD [32+esp] + call L$002pic +L$002pic: + pop ecx + lea ecx,[(L$bswap-L$002pic)+ecx] + movdqu xmm0,[eax] + movdqa xmm5,[ecx] + movdqu xmm2,[edx] +db 102,15,56,0,197 + sub ebx,16 + jz NEAR L$003odd_tail + movdqu xmm3,[esi] + movdqu xmm6,[16+esi] +db 102,15,56,0,221 +db 102,15,56,0,245 + movdqu xmm5,[32+edx] + pxor xmm0,xmm3 + pshufd xmm3,xmm6,78 + movdqa xmm7,xmm6 + pxor xmm3,xmm6 + lea esi,[32+esi] +db 102,15,58,68,242,0 +db 102,15,58,68,250,17 +db 102,15,58,68,221,0 + movups xmm2,[16+edx] + nop + sub ebx,32 + jbe NEAR L$004even_tail + jmp NEAR L$005mod_loop +align 32 +L$005mod_loop: + pshufd xmm4,xmm0,78 + movdqa xmm1,xmm0 + pxor xmm4,xmm0 + nop +db 102,15,58,68,194,0 +db 102,15,58,68,202,17 +db 102,15,58,68,229,16 + movups xmm2,[edx] + xorps xmm0,xmm6 + movdqa xmm5,[ecx] + xorps xmm1,xmm7 + movdqu xmm7,[esi] + pxor xmm3,xmm0 + movdqu xmm6,[16+esi] + pxor xmm3,xmm1 +db 102,15,56,0,253 + pxor xmm4,xmm3 + movdqa xmm3,xmm4 + psrldq xmm4,8 + pslldq xmm3,8 + pxor xmm1,xmm4 + pxor xmm0,xmm3 +db 102,15,56,0,245 + pxor xmm1,xmm7 + movdqa xmm7,xmm6 + movdqa xmm4,xmm0 + movdqa xmm3,xmm0 + psllq xmm0,5 + pxor xmm3,xmm0 + psllq xmm0,1 + pxor xmm0,xmm3 +db 102,15,58,68,242,0 + movups xmm5,[32+edx] + psllq xmm0,57 + movdqa xmm3,xmm0 + pslldq xmm0,8 + psrldq xmm3,8 + pxor xmm0,xmm4 + pxor xmm1,xmm3 + pshufd xmm3,xmm7,78 + movdqa xmm4,xmm0 + psrlq xmm0,1 + pxor xmm3,xmm7 + pxor xmm1,xmm4 +db 102,15,58,68,250,17 + movups xmm2,[16+edx] + pxor xmm4,xmm0 + psrlq xmm0,5 + pxor xmm0,xmm4 + psrlq xmm0,1 + pxor xmm0,xmm1 +db 102,15,58,68,221,0 + lea esi,[32+esi] + sub ebx,32 + ja NEAR L$005mod_loop +L$004even_tail: + pshufd xmm4,xmm0,78 + movdqa xmm1,xmm0 + pxor xmm4,xmm0 +db 102,15,58,68,194,0 +db 102,15,58,68,202,17 +db 102,15,58,68,229,16 + movdqa xmm5,[ecx] + xorps xmm0,xmm6 + xorps xmm1,xmm7 + pxor xmm3,xmm0 + pxor xmm3,xmm1 + pxor xmm4,xmm3 + movdqa xmm3,xmm4 + psrldq xmm4,8 + pslldq xmm3,8 + pxor xmm1,xmm4 + pxor xmm0,xmm3 + movdqa xmm4,xmm0 + movdqa xmm3,xmm0 + psllq xmm0,5 + pxor xmm3,xmm0 + psllq xmm0,1 + pxor xmm0,xmm3 + psllq xmm0,57 + movdqa xmm3,xmm0 + pslldq xmm0,8 + psrldq xmm3,8 + pxor xmm0,xmm4 + pxor xmm1,xmm3 + movdqa xmm4,xmm0 + psrlq xmm0,1 + pxor xmm1,xmm4 + pxor xmm4,xmm0 + psrlq xmm0,5 + pxor xmm0,xmm4 + psrlq xmm0,1 + pxor xmm0,xmm1 + test ebx,ebx + jnz NEAR L$006done + movups xmm2,[edx] +L$003odd_tail: + movdqu xmm3,[esi] +db 102,15,56,0,221 + pxor xmm0,xmm3 + movdqa xmm1,xmm0 + pshufd xmm3,xmm0,78 + pshufd xmm4,xmm2,78 + pxor xmm3,xmm0 + pxor xmm4,xmm2 +db 102,15,58,68,194,0 +db 102,15,58,68,202,17 +db 102,15,58,68,220,0 + xorps xmm3,xmm0 + xorps xmm3,xmm1 + movdqa xmm4,xmm3 + psrldq xmm3,8 + pslldq xmm4,8 + pxor xmm1,xmm3 + pxor xmm0,xmm4 + movdqa xmm4,xmm0 + movdqa xmm3,xmm0 + psllq xmm0,5 + pxor xmm3,xmm0 + psllq xmm0,1 + pxor xmm0,xmm3 + psllq xmm0,57 + movdqa xmm3,xmm0 + pslldq xmm0,8 + psrldq xmm3,8 + pxor xmm0,xmm4 + pxor xmm1,xmm3 + movdqa xmm4,xmm0 + psrlq xmm0,1 + pxor xmm1,xmm4 + pxor xmm4,xmm0 + psrlq xmm0,5 + pxor xmm0,xmm4 + psrlq xmm0,1 + pxor xmm0,xmm1 +L$006done: +db 102,15,56,0,197 + movdqu [eax],xmm0 + pop edi + pop esi + pop ebx + pop ebp + ret +align 64 +L$bswap: +db 15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0 +db 1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,194 db 71,72,65,83,72,32,102,111,114,32,120,56,54,44,32,67 db 82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112 db 112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62 diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-x86_64-linux.linux.x86_64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-x86_64-linux.linux.x86_64.S index 492d6622..8f473262 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-x86_64-linux.linux.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-x86_64-linux.linux.x86_64.S @@ -7,8 +7,6 @@ #if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64) && defined(__ELF__) .text -.extern OPENSSL_ia32cap_P -.hidden OPENSSL_ia32cap_P .globl gcm_init_clmul .hidden gcm_init_clmul .type gcm_init_clmul,@function @@ -246,15 +244,9 @@ _CET_ENDBR jz .Lodd_tail movdqu 16(%rsi),%xmm6 - leaq OPENSSL_ia32cap_P(%rip),%rax - movl 4(%rax),%eax cmpq $0x30,%rcx jb .Lskip4x - andl $71303168,%eax - cmpl $4194304,%eax - je .Lskip4x - subq $0x30,%rcx movq $0xA040608020C0E000,%rax movdqu 48(%rsi),%xmm14 diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-x86_64-mac.mac.x86_64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-x86_64-mac.mac.x86_64.S index 60b9f1dd..bd76e53b 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-x86_64-mac.mac.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/ghash-x86_64-mac.mac.x86_64.S @@ -7,7 +7,6 @@ #if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64) && defined(__APPLE__) .text - .globl _gcm_init_clmul .private_extern _gcm_init_clmul @@ -245,15 +244,9 @@ L$_ghash_clmul: jz L$odd_tail movdqu 16(%rsi),%xmm6 - leaq _OPENSSL_ia32cap_P(%rip),%rax - movl 4(%rax),%eax cmpq $0x30,%rcx jb L$skip4x - andl $71303168,%eax - cmpl $4194304,%eax - je L$skip4x - subq $0x30,%rcx movq $0xA040608020C0E000,%rax movdqu 48(%rsi),%xmm14 diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/rand/rand.c b/Sources/CCryptoBoringSSL/crypto/fipsmodule/rand/rand.c index 268dece4..1a8b198f 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/rand/rand.c +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/rand/rand.c @@ -119,7 +119,10 @@ static void rand_thread_state_free(void *state_in) { if (state->prev != NULL) { state->prev->next = state->next; - } else { + } else if (*thread_states_list_bss_get() == state) { + // |state->prev| may be NULL either if it is the head of the list, + // or if |state| is freed before it was added to the list at all. + // Compare against the head of the list to distinguish these cases. *thread_states_list_bss_get() = state->next; } @@ -371,7 +374,7 @@ void RAND_bytes_with_additional_data(uint8_t *out, size_t out_len, CRYPTO_get_thread_local(OPENSSL_THREAD_LOCAL_RAND); if (state == NULL) { - state = OPENSSL_malloc(sizeof(struct rand_thread_state)); + state = OPENSSL_zalloc(sizeof(struct rand_thread_state)); if (state == NULL || !CRYPTO_set_thread_local(OPENSSL_THREAD_LOCAL_RAND, state, rand_thread_state_free)) { diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/rsa/rsa.c b/Sources/CCryptoBoringSSL/crypto/fipsmodule/rsa/rsa.c index 8a30d2c9..fc2d5b2a 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/rsa/rsa.c +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/rsa/rsa.c @@ -439,12 +439,8 @@ int RSA_is_opaque(const RSA *rsa) { int RSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_unused *unused, CRYPTO_EX_dup *dup_unused, CRYPTO_EX_free *free_func) { - int index; - if (!CRYPTO_get_ex_new_index(g_rsa_ex_data_class_bss_get(), &index, argl, - argp, free_func)) { - return -1; - } - return index; + return CRYPTO_get_ex_new_index_ex(g_rsa_ex_data_class_bss_get(), argl, argp, + free_func); } int RSA_set_ex_data(RSA *rsa, int idx, void *arg) { diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/rsa/rsa_impl.c b/Sources/CCryptoBoringSSL/crypto/fipsmodule/rsa/rsa_impl.c index fed80caf..50dc1f32 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/rsa/rsa_impl.c +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/rsa/rsa_impl.c @@ -155,7 +155,7 @@ static int ensure_fixed_copy(BIGNUM **out, const BIGNUM *in, int width) { return 0; } *out = copy; - CONSTTIME_SECRET(copy->d, sizeof(BN_ULONG) * width); + bn_secret(copy); return 1; } @@ -259,8 +259,7 @@ static int freeze_private_key(RSA *rsa, BN_CTX *ctx) { goto err; } rsa->iqmp_mont = iqmp_mont; - CONSTTIME_SECRET(rsa->iqmp_mont->d, - sizeof(BN_ULONG) * rsa->iqmp_mont->width); + bn_secret(rsa->iqmp_mont); } } } @@ -622,7 +621,9 @@ int rsa_default_private_transform(RSA *rsa, uint8_t *out, const uint8_t *in, goto err; } - if (BN_ucmp(f, rsa->n) >= 0) { + // The input to the RSA private transform may be secret, but padding is + // expected to construct a value within range, so we can leak this comparison. + if (constant_time_declassify_int(BN_ucmp(f, rsa->n) >= 0)) { // Usually the padding functions would catch this. OPENSSL_PUT_ERROR(RSA, RSA_R_DATA_TOO_LARGE_FOR_MODULUS); goto err; diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha/internal.h b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha/internal.h index 0fe9039d..6ac869cb 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha/internal.h +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha/internal.h @@ -26,20 +26,7 @@ extern "C" { // Define SHA{n}[_{variant}]_ASM if sha{n}_block_data_order[_{variant}] is // defined in assembly. -#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86) - -#define SHA1_ASM -#define SHA256_ASM -#define SHA512_ASM - -void sha1_block_data_order(uint32_t *state, const uint8_t *data, - size_t num_blocks); -void sha256_block_data_order(uint32_t *state, const uint8_t *data, - size_t num_blocks); -void sha512_block_data_order(uint64_t *state, const uint8_t *data, - size_t num_blocks); - -#elif !defined(OPENSSL_NO_ASM) && defined(OPENSSL_ARM) +#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_ARM) #define SHA1_ASM_NOHW #define SHA256_ASM_NOHW @@ -51,7 +38,7 @@ OPENSSL_INLINE int sha1_hw_capable(void) { } #define SHA1_ASM_NEON -void sha1_block_data_order_neon(uint32_t *state, const uint8_t *data, +void sha1_block_data_order_neon(uint32_t state[5], const uint8_t *data, size_t num); #define SHA256_ASM_HW @@ -60,12 +47,12 @@ OPENSSL_INLINE int sha256_hw_capable(void) { } #define SHA256_ASM_NEON -void sha256_block_data_order_neon(uint32_t *state, const uint8_t *data, +void sha256_block_data_order_neon(uint32_t state[8], const uint8_t *data, size_t num); // Armv8.2 SHA-512 instructions are not available in 32-bit. #define SHA512_ASM_NEON -void sha512_block_data_order_neon(uint64_t *state, const uint8_t *data, +void sha512_block_data_order_neon(uint64_t state[8], const uint8_t *data, size_t num); #elif !defined(OPENSSL_NO_ASM) && defined(OPENSSL_AARCH64) @@ -89,6 +76,62 @@ OPENSSL_INLINE int sha512_hw_capable(void) { return CRYPTO_is_ARMv8_SHA512_capable(); } +#elif !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86) + +#define SHA1_ASM_NOHW +#define SHA256_ASM_NOHW + +#define SHA1_ASM_SSSE3 +OPENSSL_INLINE int sha1_ssse3_capable(void) { + // TODO(davidben): Do we need to check the FXSR bit? The Intel manual does not + // say to. + return CRYPTO_is_SSSE3_capable() && CRYPTO_is_FXSR_capable(); +} +void sha1_block_data_order_ssse3(uint32_t state[5], const uint8_t *data, + size_t num); + +#define SHA1_ASM_AVX +OPENSSL_INLINE int sha1_avx_capable(void) { + // Pre-Zen AMD CPUs had slow SHLD/SHRD; Zen added the SHA extension; see the + // discussion in sha1-586.pl. + // + // TODO(davidben): Should we enable SHAEXT on 32-bit x86? + // TODO(davidben): Do we need to check the FXSR bit? The Intel manual does not + // say to. + return CRYPTO_is_AVX_capable() && CRYPTO_is_intel_cpu() && + CRYPTO_is_FXSR_capable(); +} +void sha1_block_data_order_avx(uint32_t state[5], const uint8_t *data, + size_t num); + +#define SHA256_ASM_SSSE3 +OPENSSL_INLINE int sha256_ssse3_capable(void) { + // TODO(davidben): Do we need to check the FXSR bit? The Intel manual does not + // say to. + return CRYPTO_is_SSSE3_capable() && CRYPTO_is_FXSR_capable(); +} +void sha256_block_data_order_ssse3(uint32_t state[8], const uint8_t *data, + size_t num); + +#define SHA256_ASM_AVX +OPENSSL_INLINE int sha256_avx_capable(void) { + // Pre-Zen AMD CPUs had slow SHLD/SHRD; Zen added the SHA extension; see the + // discussion in sha1-586.pl. + // + // TODO(davidben): Should we enable SHAEXT on 32-bit x86? + // TODO(davidben): Do we need to check the FXSR bit? The Intel manual does not + // say to. + return CRYPTO_is_AVX_capable() && CRYPTO_is_intel_cpu() && + CRYPTO_is_FXSR_capable(); +} +void sha256_block_data_order_avx(uint32_t state[8], const uint8_t *data, + size_t num); + +// TODO(crbug.com/boringssl/673): Move the remaining CPU dispatch to C. +#define SHA512_ASM +void sha512_block_data_order(uint64_t state[8], const uint8_t *data, + size_t num_blocks); + #elif !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64) #define SHA1_ASM_NOHW @@ -105,7 +148,7 @@ OPENSSL_INLINE int sha1_avx2_capable(void) { return CRYPTO_is_AVX2_capable() && CRYPTO_is_BMI2_capable() && CRYPTO_is_BMI1_capable(); } -void sha1_block_data_order_avx2(uint32_t *state, const uint8_t *data, +void sha1_block_data_order_avx2(uint32_t state[5], const uint8_t *data, size_t num); #define SHA1_ASM_AVX @@ -114,14 +157,14 @@ OPENSSL_INLINE int sha1_avx_capable(void) { // discussion in sha1-586.pl. return CRYPTO_is_AVX_capable() && CRYPTO_is_intel_cpu(); } -void sha1_block_data_order_avx(uint32_t *state, const uint8_t *data, +void sha1_block_data_order_avx(uint32_t state[5], const uint8_t *data, size_t num); #define SHA1_ASM_SSSE3 OPENSSL_INLINE int sha1_ssse3_capable(void) { return CRYPTO_is_SSSE3_capable(); } -void sha1_block_data_order_ssse3(uint32_t *state, const uint8_t *data, +void sha1_block_data_order_ssse3(uint32_t state[5], const uint8_t *data, size_t num); #define SHA256_ASM_HW @@ -136,14 +179,14 @@ OPENSSL_INLINE int sha256_avx_capable(void) { // discussion in sha1-586.pl. return CRYPTO_is_AVX_capable() && CRYPTO_is_intel_cpu(); } -void sha256_block_data_order_avx(uint32_t *state, const uint8_t *data, +void sha256_block_data_order_avx(uint32_t state[8], const uint8_t *data, size_t num); #define SHA256_ASM_SSSE3 OPENSSL_INLINE int sha256_ssse3_capable(void) { return CRYPTO_is_SSSE3_capable(); } -void sha256_block_data_order_ssse3(uint32_t *state, const uint8_t *data, +void sha256_block_data_order_ssse3(uint32_t state[8], const uint8_t *data, size_t num); #define SHA512_ASM_AVX @@ -152,35 +195,36 @@ OPENSSL_INLINE int sha512_avx_capable(void) { // discussion in sha1-586.pl. return CRYPTO_is_AVX_capable() && CRYPTO_is_intel_cpu(); } -void sha512_block_data_order_avx(uint64_t *state, const uint8_t *data, +void sha512_block_data_order_avx(uint64_t state[8], const uint8_t *data, size_t num); #endif #if defined(SHA1_ASM_HW) -void sha1_block_data_order_hw(uint32_t *state, const uint8_t *data, size_t num); +void sha1_block_data_order_hw(uint32_t state[5], const uint8_t *data, + size_t num); #endif #if defined(SHA1_ASM_NOHW) -void sha1_block_data_order_nohw(uint32_t *state, const uint8_t *data, +void sha1_block_data_order_nohw(uint32_t state[5], const uint8_t *data, size_t num); #endif #if defined(SHA256_ASM_HW) -void sha256_block_data_order_hw(uint32_t *state, const uint8_t *data, +void sha256_block_data_order_hw(uint32_t state[8], const uint8_t *data, size_t num); #endif #if defined(SHA256_ASM_NOHW) -void sha256_block_data_order_nohw(uint32_t *state, const uint8_t *data, +void sha256_block_data_order_nohw(uint32_t state[8], const uint8_t *data, size_t num); #endif #if defined(SHA512_ASM_HW) -void sha512_block_data_order_hw(uint64_t *state, const uint8_t *data, +void sha512_block_data_order_hw(uint64_t state[8], const uint8_t *data, size_t num); #endif #if defined(SHA512_ASM_NOHW) -void sha512_block_data_order_nohw(uint64_t *state, const uint8_t *data, +void sha512_block_data_order_nohw(uint64_t state[8], const uint8_t *data, size_t num); #endif diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha/sha1.c b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha/sha1.c index 3d674096..14d9390f 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha/sha1.c +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha/sha1.c @@ -86,7 +86,7 @@ uint8_t *SHA1(const uint8_t *data, size_t len, uint8_t out[SHA_DIGEST_LENGTH]) { } #if !defined(SHA1_ASM) -static void sha1_block_data_order(uint32_t *state, const uint8_t *data, +static void sha1_block_data_order(uint32_t state[5], const uint8_t *data, size_t num); #endif @@ -234,7 +234,7 @@ void CRYPTO_fips_186_2_prf(uint8_t *out, size_t out_len, #if !defined(SHA1_ASM) #if !defined(SHA1_ASM_NOHW) -static void sha1_block_data_order_nohw(uint32_t *state, const uint8_t *data, +static void sha1_block_data_order_nohw(uint32_t state[5], const uint8_t *data, size_t num) { register uint32_t A, B, C, D, E, T; uint32_t XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7, XX8, XX9, XX10, @@ -384,7 +384,7 @@ static void sha1_block_data_order_nohw(uint32_t *state, const uint8_t *data, } #endif // !SHA1_ASM_NOHW -static void sha1_block_data_order(uint32_t *state, const uint8_t *data, +static void sha1_block_data_order(uint32_t state[5], const uint8_t *data, size_t num) { #if defined(SHA1_ASM_HW) if (sha1_hw_capable()) { @@ -394,7 +394,7 @@ static void sha1_block_data_order(uint32_t *state, const uint8_t *data, #endif #if defined(SHA1_ASM_AVX2) if (sha1_avx2_capable()) { - sha1_block_data_order_avx(state, data, num); + sha1_block_data_order_avx2(state, data, num); return; } #endif diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha/sha256.c b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha/sha256.c index d1ef5c3c..25bf3c11 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha/sha256.c +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha/sha256.c @@ -115,7 +115,7 @@ uint8_t *SHA256(const uint8_t *data, size_t len, } #if !defined(SHA256_ASM) -static void sha256_block_data_order(uint32_t *state, const uint8_t *in, +static void sha256_block_data_order(uint32_t state[8], const uint8_t *in, size_t num); #endif @@ -223,7 +223,7 @@ static const uint32_t K256[64] = { ROUND_00_15(i, a, b, c, d, e, f, g, h); \ } while (0) -static void sha256_block_data_order_nohw(uint32_t *state, const uint8_t *data, +static void sha256_block_data_order_nohw(uint32_t state[8], const uint8_t *data, size_t num) { uint32_t a, b, c, d, e, f, g, h, s0, s1, T1; uint32_t X[16]; @@ -312,7 +312,7 @@ static void sha256_block_data_order_nohw(uint32_t *state, const uint8_t *data, #endif // !defined(SHA256_ASM_NOHW) -static void sha256_block_data_order(uint32_t *state, const uint8_t *data, +static void sha256_block_data_order(uint32_t state[8], const uint8_t *data, size_t num) { #if defined(SHA256_ASM_HW) if (sha256_hw_capable()) { diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha/sha512.c b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha/sha512.c index a773cd60..8135457a 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha/sha512.c +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha/sha512.c @@ -156,7 +156,7 @@ uint8_t *SHA512_256(const uint8_t *data, size_t len, } #if !defined(SHA512_ASM) -static void sha512_block_data_order(uint64_t *state, const uint8_t *in, +static void sha512_block_data_order(uint64_t state[8], const uint8_t *in, size_t num_blocks); #endif @@ -343,7 +343,7 @@ static const uint64_t K512[80] = { #if defined(__i386) || defined(__i386__) || defined(_M_IX86) // This code should give better results on 32-bit CPU with less than // ~24 registers, both size and performance wise... -static void sha512_block_data_order_nohw(uint64_t *state, const uint8_t *in, +static void sha512_block_data_order_nohw(uint64_t state[8], const uint8_t *in, size_t num) { uint64_t A, E, T; uint64_t X[9 + 80], *F; @@ -416,7 +416,7 @@ static void sha512_block_data_order_nohw(uint64_t *state, const uint8_t *in, ROUND_00_15(i + j, a, b, c, d, e, f, g, h); \ } while (0) -static void sha512_block_data_order_nohw(uint64_t *state, const uint8_t *in, +static void sha512_block_data_order_nohw(uint64_t state[8], const uint8_t *in, size_t num) { uint64_t a, b, c, d, e, f, g, h, s0, s1, T1; uint64_t X[16]; @@ -502,7 +502,7 @@ static void sha512_block_data_order_nohw(uint64_t *state, const uint8_t *in, #endif // !SHA512_ASM_NOHW -static void sha512_block_data_order(uint64_t *state, const uint8_t *data, +static void sha512_block_data_order(uint64_t state[8], const uint8_t *data, size_t num) { #if defined(SHA512_ASM_HW) if (sha512_hw_capable()) { diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha1-586-linux.linux.x86.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha1-586-linux.linux.x86.S index 65355878..11b6cb2f 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha1-586-linux.linux.x86.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha1-586-linux.linux.x86.S @@ -7,36 +7,16 @@ #if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86) && defined(__ELF__) .text -.globl sha1_block_data_order -.hidden sha1_block_data_order -.type sha1_block_data_order,@function +.globl sha1_block_data_order_nohw +.hidden sha1_block_data_order_nohw +.type sha1_block_data_order_nohw,@function .align 16 -sha1_block_data_order: -.L_sha1_block_data_order_begin: +sha1_block_data_order_nohw: +.L_sha1_block_data_order_nohw_begin: pushl %ebp pushl %ebx pushl %esi pushl %edi - call .L000pic_point -.L000pic_point: - popl %ebp - leal OPENSSL_ia32cap_P-.L000pic_point(%ebp),%esi - leal .LK_XX_XX-.L000pic_point(%ebp),%ebp - movl (%esi),%eax - movl 4(%esi),%edx - testl $512,%edx - jz .L001x86 - movl 8(%esi),%ecx - testl $16777216,%eax - jz .L001x86 - andl $268435456,%edx - andl $1073741824,%eax - orl %edx,%eax - cmpl $1342177280,%eax - je .Lavx_shortcut - jmp .Lssse3_shortcut -.align 16 -.L001x86: movl 20(%esp),%ebp movl 24(%esp),%esi movl 28(%esp),%eax @@ -45,9 +25,9 @@ sha1_block_data_order: addl %esi,%eax movl %eax,104(%esp) movl 16(%ebp),%edi - jmp .L002loop + jmp .L000loop .align 16 -.L002loop: +.L000loop: movl (%esi),%eax movl 4(%esi),%ebx movl 8(%esi),%ecx @@ -1394,27 +1374,28 @@ sha1_block_data_order: movl %ebx,12(%ebp) movl %edx,%esi movl %ecx,16(%ebp) - jb .L002loop + jb .L000loop addl $76,%esp popl %edi popl %esi popl %ebx popl %ebp ret -.size sha1_block_data_order,.-.L_sha1_block_data_order_begin -.hidden _sha1_block_data_order_ssse3 -.type _sha1_block_data_order_ssse3,@function +.size sha1_block_data_order_nohw,.-.L_sha1_block_data_order_nohw_begin +.globl sha1_block_data_order_ssse3 +.hidden sha1_block_data_order_ssse3 +.type sha1_block_data_order_ssse3,@function .align 16 -_sha1_block_data_order_ssse3: +sha1_block_data_order_ssse3: +.L_sha1_block_data_order_ssse3_begin: pushl %ebp pushl %ebx pushl %esi pushl %edi - call .L003pic_point -.L003pic_point: + call .L001pic_point +.L001pic_point: popl %ebp - leal .LK_XX_XX-.L003pic_point(%ebp),%ebp -.Lssse3_shortcut: + leal .LK_XX_XX-.L001pic_point(%ebp),%ebp movdqa (%ebp),%xmm7 movdqa 16(%ebp),%xmm0 movdqa 32(%ebp),%xmm1 @@ -1466,9 +1447,9 @@ _sha1_block_data_order_ssse3: xorl %edx,%ebp pshufd $238,%xmm0,%xmm4 andl %ebp,%esi - jmp .L004loop + jmp .L002loop .align 16 -.L004loop: +.L002loop: rorl $2,%ebx xorl %edx,%esi movl %eax,%ebp @@ -2371,7 +2352,7 @@ _sha1_block_data_order_ssse3: addl %edx,%ecx movl 196(%esp),%ebp cmpl 200(%esp),%ebp - je .L005done + je .L003done movdqa 160(%esp),%xmm7 movdqa 176(%esp),%xmm6 movdqu (%ebp),%xmm0 @@ -2506,9 +2487,9 @@ _sha1_block_data_order_ssse3: pshufd $238,%xmm0,%xmm4 andl %ebx,%esi movl %ebp,%ebx - jmp .L004loop + jmp .L002loop .align 16 -.L005done: +.L003done: addl 16(%esp),%ebx xorl %edi,%esi movl %ecx,%ebp @@ -2621,20 +2602,21 @@ _sha1_block_data_order_ssse3: popl %ebx popl %ebp ret -.size _sha1_block_data_order_ssse3,.-_sha1_block_data_order_ssse3 -.hidden _sha1_block_data_order_avx -.type _sha1_block_data_order_avx,@function +.size sha1_block_data_order_ssse3,.-.L_sha1_block_data_order_ssse3_begin +.globl sha1_block_data_order_avx +.hidden sha1_block_data_order_avx +.type sha1_block_data_order_avx,@function .align 16 -_sha1_block_data_order_avx: +sha1_block_data_order_avx: +.L_sha1_block_data_order_avx_begin: pushl %ebp pushl %ebx pushl %esi pushl %edi - call .L006pic_point -.L006pic_point: + call .L004pic_point +.L004pic_point: popl %ebp - leal .LK_XX_XX-.L006pic_point(%ebp),%ebp -.Lavx_shortcut: + leal .LK_XX_XX-.L004pic_point(%ebp),%ebp vzeroall vmovdqa (%ebp),%xmm7 vmovdqa 16(%ebp),%xmm0 @@ -2683,9 +2665,9 @@ _sha1_block_data_order_avx: xorl %edx,%ebp vmovdqa %xmm6,32(%esp) andl %ebp,%esi - jmp .L007loop + jmp .L005loop .align 16 -.L007loop: +.L005loop: shrdl $2,%ebx,%ebx xorl %edx,%esi vpalignr $8,%xmm0,%xmm1,%xmm4 @@ -3545,7 +3527,7 @@ _sha1_block_data_order_avx: addl %edx,%ecx movl 196(%esp),%ebp cmpl 200(%esp),%ebp - je .L008done + je .L006done vmovdqa 160(%esp),%xmm7 vmovdqa 176(%esp),%xmm6 vmovdqu (%ebp),%xmm0 @@ -3676,9 +3658,9 @@ _sha1_block_data_order_avx: movl %esi,%ebp andl %ebx,%esi movl %ebp,%ebx - jmp .L007loop + jmp .L005loop .align 16 -.L008done: +.L006done: addl 16(%esp),%ebx xorl %edi,%esi movl %ecx,%ebp @@ -3792,7 +3774,7 @@ _sha1_block_data_order_avx: popl %ebx popl %ebp ret -.size _sha1_block_data_order_avx,.-_sha1_block_data_order_avx +.size sha1_block_data_order_avx,.-.L_sha1_block_data_order_avx_begin .align 64 .LK_XX_XX: .long 1518500249,1518500249,1518500249,1518500249 diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha1-586-windows.windows.x86.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha1-586-windows.windows.x86.S index 8ccfc64d..3622e531 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha1-586-windows.windows.x86.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha1-586-windows.windows.x86.S @@ -15,10 +15,10 @@ section .text code align=64 %else section .text code %endif -global _sha1_block_data_order +global _sha1_block_data_order_nohw align 16 -_sha1_block_data_order: -L$_sha1_block_data_order_begin: +_sha1_block_data_order_nohw: +L$_sha1_block_data_order_nohw_begin: push ebp push ebx push esi @@ -1387,6 +1387,2401 @@ L$000loop: pop ebx pop ebp ret +global _sha1_block_data_order_ssse3 +align 16 +_sha1_block_data_order_ssse3: +L$_sha1_block_data_order_ssse3_begin: + push ebp + push ebx + push esi + push edi + call L$001pic_point +L$001pic_point: + pop ebp + lea ebp,[(L$K_XX_XX-L$001pic_point)+ebp] + movdqa xmm7,[ebp] + movdqa xmm0,[16+ebp] + movdqa xmm1,[32+ebp] + movdqa xmm2,[48+ebp] + movdqa xmm6,[64+ebp] + mov edi,DWORD [20+esp] + mov ebp,DWORD [24+esp] + mov edx,DWORD [28+esp] + mov esi,esp + sub esp,208 + and esp,-64 + movdqa [112+esp],xmm0 + movdqa [128+esp],xmm1 + movdqa [144+esp],xmm2 + shl edx,6 + movdqa [160+esp],xmm7 + add edx,ebp + movdqa [176+esp],xmm6 + add ebp,64 + mov DWORD [192+esp],edi + mov DWORD [196+esp],ebp + mov DWORD [200+esp],edx + mov DWORD [204+esp],esi + mov eax,DWORD [edi] + mov ebx,DWORD [4+edi] + mov ecx,DWORD [8+edi] + mov edx,DWORD [12+edi] + mov edi,DWORD [16+edi] + mov esi,ebx + movdqu xmm0,[ebp-64] + movdqu xmm1,[ebp-48] + movdqu xmm2,[ebp-32] + movdqu xmm3,[ebp-16] +db 102,15,56,0,198 +db 102,15,56,0,206 +db 102,15,56,0,214 + movdqa [96+esp],xmm7 +db 102,15,56,0,222 + paddd xmm0,xmm7 + paddd xmm1,xmm7 + paddd xmm2,xmm7 + movdqa [esp],xmm0 + psubd xmm0,xmm7 + movdqa [16+esp],xmm1 + psubd xmm1,xmm7 + movdqa [32+esp],xmm2 + mov ebp,ecx + psubd xmm2,xmm7 + xor ebp,edx + pshufd xmm4,xmm0,238 + and esi,ebp + jmp NEAR L$002loop +align 16 +L$002loop: + ror ebx,2 + xor esi,edx + mov ebp,eax + punpcklqdq xmm4,xmm1 + movdqa xmm6,xmm3 + add edi,DWORD [esp] + xor ebx,ecx + paddd xmm7,xmm3 + movdqa [64+esp],xmm0 + rol eax,5 + add edi,esi + psrldq xmm6,4 + and ebp,ebx + xor ebx,ecx + pxor xmm4,xmm0 + add edi,eax + ror eax,7 + pxor xmm6,xmm2 + xor ebp,ecx + mov esi,edi + add edx,DWORD [4+esp] + pxor xmm4,xmm6 + xor eax,ebx + rol edi,5 + movdqa [48+esp],xmm7 + add edx,ebp + and esi,eax + movdqa xmm0,xmm4 + xor eax,ebx + add edx,edi + ror edi,7 + movdqa xmm6,xmm4 + xor esi,ebx + pslldq xmm0,12 + paddd xmm4,xmm4 + mov ebp,edx + add ecx,DWORD [8+esp] + psrld xmm6,31 + xor edi,eax + rol edx,5 + movdqa xmm7,xmm0 + add ecx,esi + and ebp,edi + xor edi,eax + psrld xmm0,30 + add ecx,edx + ror edx,7 + por xmm4,xmm6 + xor ebp,eax + mov esi,ecx + add ebx,DWORD [12+esp] + pslld xmm7,2 + xor edx,edi + rol ecx,5 + pxor xmm4,xmm0 + movdqa xmm0,[96+esp] + add ebx,ebp + and esi,edx + pxor xmm4,xmm7 + pshufd xmm5,xmm1,238 + xor edx,edi + add ebx,ecx + ror ecx,7 + xor esi,edi + mov ebp,ebx + punpcklqdq xmm5,xmm2 + movdqa xmm7,xmm4 + add eax,DWORD [16+esp] + xor ecx,edx + paddd xmm0,xmm4 + movdqa [80+esp],xmm1 + rol ebx,5 + add eax,esi + psrldq xmm7,4 + and ebp,ecx + xor ecx,edx + pxor xmm5,xmm1 + add eax,ebx + ror ebx,7 + pxor xmm7,xmm3 + xor ebp,edx + mov esi,eax + add edi,DWORD [20+esp] + pxor xmm5,xmm7 + xor ebx,ecx + rol eax,5 + movdqa [esp],xmm0 + add edi,ebp + and esi,ebx + movdqa xmm1,xmm5 + xor ebx,ecx + add edi,eax + ror eax,7 + movdqa xmm7,xmm5 + xor esi,ecx + pslldq xmm1,12 + paddd xmm5,xmm5 + mov ebp,edi + add edx,DWORD [24+esp] + psrld xmm7,31 + xor eax,ebx + rol edi,5 + movdqa xmm0,xmm1 + add edx,esi + and ebp,eax + xor eax,ebx + psrld xmm1,30 + add edx,edi + ror edi,7 + por xmm5,xmm7 + xor ebp,ebx + mov esi,edx + add ecx,DWORD [28+esp] + pslld xmm0,2 + xor edi,eax + rol edx,5 + pxor xmm5,xmm1 + movdqa xmm1,[112+esp] + add ecx,ebp + and esi,edi + pxor xmm5,xmm0 + pshufd xmm6,xmm2,238 + xor edi,eax + add ecx,edx + ror edx,7 + xor esi,eax + mov ebp,ecx + punpcklqdq xmm6,xmm3 + movdqa xmm0,xmm5 + add ebx,DWORD [32+esp] + xor edx,edi + paddd xmm1,xmm5 + movdqa [96+esp],xmm2 + rol ecx,5 + add ebx,esi + psrldq xmm0,4 + and ebp,edx + xor edx,edi + pxor xmm6,xmm2 + add ebx,ecx + ror ecx,7 + pxor xmm0,xmm4 + xor ebp,edi + mov esi,ebx + add eax,DWORD [36+esp] + pxor xmm6,xmm0 + xor ecx,edx + rol ebx,5 + movdqa [16+esp],xmm1 + add eax,ebp + and esi,ecx + movdqa xmm2,xmm6 + xor ecx,edx + add eax,ebx + ror ebx,7 + movdqa xmm0,xmm6 + xor esi,edx + pslldq xmm2,12 + paddd xmm6,xmm6 + mov ebp,eax + add edi,DWORD [40+esp] + psrld xmm0,31 + xor ebx,ecx + rol eax,5 + movdqa xmm1,xmm2 + add edi,esi + and ebp,ebx + xor ebx,ecx + psrld xmm2,30 + add edi,eax + ror eax,7 + por xmm6,xmm0 + xor ebp,ecx + movdqa xmm0,[64+esp] + mov esi,edi + add edx,DWORD [44+esp] + pslld xmm1,2 + xor eax,ebx + rol edi,5 + pxor xmm6,xmm2 + movdqa xmm2,[112+esp] + add edx,ebp + and esi,eax + pxor xmm6,xmm1 + pshufd xmm7,xmm3,238 + xor eax,ebx + add edx,edi + ror edi,7 + xor esi,ebx + mov ebp,edx + punpcklqdq xmm7,xmm4 + movdqa xmm1,xmm6 + add ecx,DWORD [48+esp] + xor edi,eax + paddd xmm2,xmm6 + movdqa [64+esp],xmm3 + rol edx,5 + add ecx,esi + psrldq xmm1,4 + and ebp,edi + xor edi,eax + pxor xmm7,xmm3 + add ecx,edx + ror edx,7 + pxor xmm1,xmm5 + xor ebp,eax + mov esi,ecx + add ebx,DWORD [52+esp] + pxor xmm7,xmm1 + xor edx,edi + rol ecx,5 + movdqa [32+esp],xmm2 + add ebx,ebp + and esi,edx + movdqa xmm3,xmm7 + xor edx,edi + add ebx,ecx + ror ecx,7 + movdqa xmm1,xmm7 + xor esi,edi + pslldq xmm3,12 + paddd xmm7,xmm7 + mov ebp,ebx + add eax,DWORD [56+esp] + psrld xmm1,31 + xor ecx,edx + rol ebx,5 + movdqa xmm2,xmm3 + add eax,esi + and ebp,ecx + xor ecx,edx + psrld xmm3,30 + add eax,ebx + ror ebx,7 + por xmm7,xmm1 + xor ebp,edx + movdqa xmm1,[80+esp] + mov esi,eax + add edi,DWORD [60+esp] + pslld xmm2,2 + xor ebx,ecx + rol eax,5 + pxor xmm7,xmm3 + movdqa xmm3,[112+esp] + add edi,ebp + and esi,ebx + pxor xmm7,xmm2 + pshufd xmm2,xmm6,238 + xor ebx,ecx + add edi,eax + ror eax,7 + pxor xmm0,xmm4 + punpcklqdq xmm2,xmm7 + xor esi,ecx + mov ebp,edi + add edx,DWORD [esp] + pxor xmm0,xmm1 + movdqa [80+esp],xmm4 + xor eax,ebx + rol edi,5 + movdqa xmm4,xmm3 + add edx,esi + paddd xmm3,xmm7 + and ebp,eax + pxor xmm0,xmm2 + xor eax,ebx + add edx,edi + ror edi,7 + xor ebp,ebx + movdqa xmm2,xmm0 + movdqa [48+esp],xmm3 + mov esi,edx + add ecx,DWORD [4+esp] + xor edi,eax + rol edx,5 + pslld xmm0,2 + add ecx,ebp + and esi,edi + psrld xmm2,30 + xor edi,eax + add ecx,edx + ror edx,7 + xor esi,eax + mov ebp,ecx + add ebx,DWORD [8+esp] + xor edx,edi + rol ecx,5 + por xmm0,xmm2 + add ebx,esi + and ebp,edx + movdqa xmm2,[96+esp] + xor edx,edi + add ebx,ecx + add eax,DWORD [12+esp] + xor ebp,edi + mov esi,ebx + pshufd xmm3,xmm7,238 + rol ebx,5 + add eax,ebp + xor esi,edx + ror ecx,7 + add eax,ebx + add edi,DWORD [16+esp] + pxor xmm1,xmm5 + punpcklqdq xmm3,xmm0 + xor esi,ecx + mov ebp,eax + rol eax,5 + pxor xmm1,xmm2 + movdqa [96+esp],xmm5 + add edi,esi + xor ebp,ecx + movdqa xmm5,xmm4 + ror ebx,7 + paddd xmm4,xmm0 + add edi,eax + pxor xmm1,xmm3 + add edx,DWORD [20+esp] + xor ebp,ebx + mov esi,edi + rol edi,5 + movdqa xmm3,xmm1 + movdqa [esp],xmm4 + add edx,ebp + xor esi,ebx + ror eax,7 + add edx,edi + pslld xmm1,2 + add ecx,DWORD [24+esp] + xor esi,eax + psrld xmm3,30 + mov ebp,edx + rol edx,5 + add ecx,esi + xor ebp,eax + ror edi,7 + add ecx,edx + por xmm1,xmm3 + add ebx,DWORD [28+esp] + xor ebp,edi + movdqa xmm3,[64+esp] + mov esi,ecx + rol ecx,5 + add ebx,ebp + xor esi,edi + ror edx,7 + pshufd xmm4,xmm0,238 + add ebx,ecx + add eax,DWORD [32+esp] + pxor xmm2,xmm6 + punpcklqdq xmm4,xmm1 + xor esi,edx + mov ebp,ebx + rol ebx,5 + pxor xmm2,xmm3 + movdqa [64+esp],xmm6 + add eax,esi + xor ebp,edx + movdqa xmm6,[128+esp] + ror ecx,7 + paddd xmm5,xmm1 + add eax,ebx + pxor xmm2,xmm4 + add edi,DWORD [36+esp] + xor ebp,ecx + mov esi,eax + rol eax,5 + movdqa xmm4,xmm2 + movdqa [16+esp],xmm5 + add edi,ebp + xor esi,ecx + ror ebx,7 + add edi,eax + pslld xmm2,2 + add edx,DWORD [40+esp] + xor esi,ebx + psrld xmm4,30 + mov ebp,edi + rol edi,5 + add edx,esi + xor ebp,ebx + ror eax,7 + add edx,edi + por xmm2,xmm4 + add ecx,DWORD [44+esp] + xor ebp,eax + movdqa xmm4,[80+esp] + mov esi,edx + rol edx,5 + add ecx,ebp + xor esi,eax + ror edi,7 + pshufd xmm5,xmm1,238 + add ecx,edx + add ebx,DWORD [48+esp] + pxor xmm3,xmm7 + punpcklqdq xmm5,xmm2 + xor esi,edi + mov ebp,ecx + rol ecx,5 + pxor xmm3,xmm4 + movdqa [80+esp],xmm7 + add ebx,esi + xor ebp,edi + movdqa xmm7,xmm6 + ror edx,7 + paddd xmm6,xmm2 + add ebx,ecx + pxor xmm3,xmm5 + add eax,DWORD [52+esp] + xor ebp,edx + mov esi,ebx + rol ebx,5 + movdqa xmm5,xmm3 + movdqa [32+esp],xmm6 + add eax,ebp + xor esi,edx + ror ecx,7 + add eax,ebx + pslld xmm3,2 + add edi,DWORD [56+esp] + xor esi,ecx + psrld xmm5,30 + mov ebp,eax + rol eax,5 + add edi,esi + xor ebp,ecx + ror ebx,7 + add edi,eax + por xmm3,xmm5 + add edx,DWORD [60+esp] + xor ebp,ebx + movdqa xmm5,[96+esp] + mov esi,edi + rol edi,5 + add edx,ebp + xor esi,ebx + ror eax,7 + pshufd xmm6,xmm2,238 + add edx,edi + add ecx,DWORD [esp] + pxor xmm4,xmm0 + punpcklqdq xmm6,xmm3 + xor esi,eax + mov ebp,edx + rol edx,5 + pxor xmm4,xmm5 + movdqa [96+esp],xmm0 + add ecx,esi + xor ebp,eax + movdqa xmm0,xmm7 + ror edi,7 + paddd xmm7,xmm3 + add ecx,edx + pxor xmm4,xmm6 + add ebx,DWORD [4+esp] + xor ebp,edi + mov esi,ecx + rol ecx,5 + movdqa xmm6,xmm4 + movdqa [48+esp],xmm7 + add ebx,ebp + xor esi,edi + ror edx,7 + add ebx,ecx + pslld xmm4,2 + add eax,DWORD [8+esp] + xor esi,edx + psrld xmm6,30 + mov ebp,ebx + rol ebx,5 + add eax,esi + xor ebp,edx + ror ecx,7 + add eax,ebx + por xmm4,xmm6 + add edi,DWORD [12+esp] + xor ebp,ecx + movdqa xmm6,[64+esp] + mov esi,eax + rol eax,5 + add edi,ebp + xor esi,ecx + ror ebx,7 + pshufd xmm7,xmm3,238 + add edi,eax + add edx,DWORD [16+esp] + pxor xmm5,xmm1 + punpcklqdq xmm7,xmm4 + xor esi,ebx + mov ebp,edi + rol edi,5 + pxor xmm5,xmm6 + movdqa [64+esp],xmm1 + add edx,esi + xor ebp,ebx + movdqa xmm1,xmm0 + ror eax,7 + paddd xmm0,xmm4 + add edx,edi + pxor xmm5,xmm7 + add ecx,DWORD [20+esp] + xor ebp,eax + mov esi,edx + rol edx,5 + movdqa xmm7,xmm5 + movdqa [esp],xmm0 + add ecx,ebp + xor esi,eax + ror edi,7 + add ecx,edx + pslld xmm5,2 + add ebx,DWORD [24+esp] + xor esi,edi + psrld xmm7,30 + mov ebp,ecx + rol ecx,5 + add ebx,esi + xor ebp,edi + ror edx,7 + add ebx,ecx + por xmm5,xmm7 + add eax,DWORD [28+esp] + movdqa xmm7,[80+esp] + ror ecx,7 + mov esi,ebx + xor ebp,edx + rol ebx,5 + pshufd xmm0,xmm4,238 + add eax,ebp + xor esi,ecx + xor ecx,edx + add eax,ebx + add edi,DWORD [32+esp] + pxor xmm6,xmm2 + punpcklqdq xmm0,xmm5 + and esi,ecx + xor ecx,edx + ror ebx,7 + pxor xmm6,xmm7 + movdqa [80+esp],xmm2 + mov ebp,eax + xor esi,ecx + rol eax,5 + movdqa xmm2,xmm1 + add edi,esi + paddd xmm1,xmm5 + xor ebp,ebx + pxor xmm6,xmm0 + xor ebx,ecx + add edi,eax + add edx,DWORD [36+esp] + and ebp,ebx + movdqa xmm0,xmm6 + movdqa [16+esp],xmm1 + xor ebx,ecx + ror eax,7 + mov esi,edi + xor ebp,ebx + rol edi,5 + pslld xmm6,2 + add edx,ebp + xor esi,eax + psrld xmm0,30 + xor eax,ebx + add edx,edi + add ecx,DWORD [40+esp] + and esi,eax + xor eax,ebx + ror edi,7 + por xmm6,xmm0 + mov ebp,edx + xor esi,eax + movdqa xmm0,[96+esp] + rol edx,5 + add ecx,esi + xor ebp,edi + xor edi,eax + add ecx,edx + pshufd xmm1,xmm5,238 + add ebx,DWORD [44+esp] + and ebp,edi + xor edi,eax + ror edx,7 + mov esi,ecx + xor ebp,edi + rol ecx,5 + add ebx,ebp + xor esi,edx + xor edx,edi + add ebx,ecx + add eax,DWORD [48+esp] + pxor xmm7,xmm3 + punpcklqdq xmm1,xmm6 + and esi,edx + xor edx,edi + ror ecx,7 + pxor xmm7,xmm0 + movdqa [96+esp],xmm3 + mov ebp,ebx + xor esi,edx + rol ebx,5 + movdqa xmm3,[144+esp] + add eax,esi + paddd xmm2,xmm6 + xor ebp,ecx + pxor xmm7,xmm1 + xor ecx,edx + add eax,ebx + add edi,DWORD [52+esp] + and ebp,ecx + movdqa xmm1,xmm7 + movdqa [32+esp],xmm2 + xor ecx,edx + ror ebx,7 + mov esi,eax + xor ebp,ecx + rol eax,5 + pslld xmm7,2 + add edi,ebp + xor esi,ebx + psrld xmm1,30 + xor ebx,ecx + add edi,eax + add edx,DWORD [56+esp] + and esi,ebx + xor ebx,ecx + ror eax,7 + por xmm7,xmm1 + mov ebp,edi + xor esi,ebx + movdqa xmm1,[64+esp] + rol edi,5 + add edx,esi + xor ebp,eax + xor eax,ebx + add edx,edi + pshufd xmm2,xmm6,238 + add ecx,DWORD [60+esp] + and ebp,eax + xor eax,ebx + ror edi,7 + mov esi,edx + xor ebp,eax + rol edx,5 + add ecx,ebp + xor esi,edi + xor edi,eax + add ecx,edx + add ebx,DWORD [esp] + pxor xmm0,xmm4 + punpcklqdq xmm2,xmm7 + and esi,edi + xor edi,eax + ror edx,7 + pxor xmm0,xmm1 + movdqa [64+esp],xmm4 + mov ebp,ecx + xor esi,edi + rol ecx,5 + movdqa xmm4,xmm3 + add ebx,esi + paddd xmm3,xmm7 + xor ebp,edx + pxor xmm0,xmm2 + xor edx,edi + add ebx,ecx + add eax,DWORD [4+esp] + and ebp,edx + movdqa xmm2,xmm0 + movdqa [48+esp],xmm3 + xor edx,edi + ror ecx,7 + mov esi,ebx + xor ebp,edx + rol ebx,5 + pslld xmm0,2 + add eax,ebp + xor esi,ecx + psrld xmm2,30 + xor ecx,edx + add eax,ebx + add edi,DWORD [8+esp] + and esi,ecx + xor ecx,edx + ror ebx,7 + por xmm0,xmm2 + mov ebp,eax + xor esi,ecx + movdqa xmm2,[80+esp] + rol eax,5 + add edi,esi + xor ebp,ebx + xor ebx,ecx + add edi,eax + pshufd xmm3,xmm7,238 + add edx,DWORD [12+esp] + and ebp,ebx + xor ebx,ecx + ror eax,7 + mov esi,edi + xor ebp,ebx + rol edi,5 + add edx,ebp + xor esi,eax + xor eax,ebx + add edx,edi + add ecx,DWORD [16+esp] + pxor xmm1,xmm5 + punpcklqdq xmm3,xmm0 + and esi,eax + xor eax,ebx + ror edi,7 + pxor xmm1,xmm2 + movdqa [80+esp],xmm5 + mov ebp,edx + xor esi,eax + rol edx,5 + movdqa xmm5,xmm4 + add ecx,esi + paddd xmm4,xmm0 + xor ebp,edi + pxor xmm1,xmm3 + xor edi,eax + add ecx,edx + add ebx,DWORD [20+esp] + and ebp,edi + movdqa xmm3,xmm1 + movdqa [esp],xmm4 + xor edi,eax + ror edx,7 + mov esi,ecx + xor ebp,edi + rol ecx,5 + pslld xmm1,2 + add ebx,ebp + xor esi,edx + psrld xmm3,30 + xor edx,edi + add ebx,ecx + add eax,DWORD [24+esp] + and esi,edx + xor edx,edi + ror ecx,7 + por xmm1,xmm3 + mov ebp,ebx + xor esi,edx + movdqa xmm3,[96+esp] + rol ebx,5 + add eax,esi + xor ebp,ecx + xor ecx,edx + add eax,ebx + pshufd xmm4,xmm0,238 + add edi,DWORD [28+esp] + and ebp,ecx + xor ecx,edx + ror ebx,7 + mov esi,eax + xor ebp,ecx + rol eax,5 + add edi,ebp + xor esi,ebx + xor ebx,ecx + add edi,eax + add edx,DWORD [32+esp] + pxor xmm2,xmm6 + punpcklqdq xmm4,xmm1 + and esi,ebx + xor ebx,ecx + ror eax,7 + pxor xmm2,xmm3 + movdqa [96+esp],xmm6 + mov ebp,edi + xor esi,ebx + rol edi,5 + movdqa xmm6,xmm5 + add edx,esi + paddd xmm5,xmm1 + xor ebp,eax + pxor xmm2,xmm4 + xor eax,ebx + add edx,edi + add ecx,DWORD [36+esp] + and ebp,eax + movdqa xmm4,xmm2 + movdqa [16+esp],xmm5 + xor eax,ebx + ror edi,7 + mov esi,edx + xor ebp,eax + rol edx,5 + pslld xmm2,2 + add ecx,ebp + xor esi,edi + psrld xmm4,30 + xor edi,eax + add ecx,edx + add ebx,DWORD [40+esp] + and esi,edi + xor edi,eax + ror edx,7 + por xmm2,xmm4 + mov ebp,ecx + xor esi,edi + movdqa xmm4,[64+esp] + rol ecx,5 + add ebx,esi + xor ebp,edx + xor edx,edi + add ebx,ecx + pshufd xmm5,xmm1,238 + add eax,DWORD [44+esp] + and ebp,edx + xor edx,edi + ror ecx,7 + mov esi,ebx + xor ebp,edx + rol ebx,5 + add eax,ebp + xor esi,edx + add eax,ebx + add edi,DWORD [48+esp] + pxor xmm3,xmm7 + punpcklqdq xmm5,xmm2 + xor esi,ecx + mov ebp,eax + rol eax,5 + pxor xmm3,xmm4 + movdqa [64+esp],xmm7 + add edi,esi + xor ebp,ecx + movdqa xmm7,xmm6 + ror ebx,7 + paddd xmm6,xmm2 + add edi,eax + pxor xmm3,xmm5 + add edx,DWORD [52+esp] + xor ebp,ebx + mov esi,edi + rol edi,5 + movdqa xmm5,xmm3 + movdqa [32+esp],xmm6 + add edx,ebp + xor esi,ebx + ror eax,7 + add edx,edi + pslld xmm3,2 + add ecx,DWORD [56+esp] + xor esi,eax + psrld xmm5,30 + mov ebp,edx + rol edx,5 + add ecx,esi + xor ebp,eax + ror edi,7 + add ecx,edx + por xmm3,xmm5 + add ebx,DWORD [60+esp] + xor ebp,edi + mov esi,ecx + rol ecx,5 + add ebx,ebp + xor esi,edi + ror edx,7 + add ebx,ecx + add eax,DWORD [esp] + xor esi,edx + mov ebp,ebx + rol ebx,5 + add eax,esi + xor ebp,edx + ror ecx,7 + paddd xmm7,xmm3 + add eax,ebx + add edi,DWORD [4+esp] + xor ebp,ecx + mov esi,eax + movdqa [48+esp],xmm7 + rol eax,5 + add edi,ebp + xor esi,ecx + ror ebx,7 + add edi,eax + add edx,DWORD [8+esp] + xor esi,ebx + mov ebp,edi + rol edi,5 + add edx,esi + xor ebp,ebx + ror eax,7 + add edx,edi + add ecx,DWORD [12+esp] + xor ebp,eax + mov esi,edx + rol edx,5 + add ecx,ebp + xor esi,eax + ror edi,7 + add ecx,edx + mov ebp,DWORD [196+esp] + cmp ebp,DWORD [200+esp] + je NEAR L$003done + movdqa xmm7,[160+esp] + movdqa xmm6,[176+esp] + movdqu xmm0,[ebp] + movdqu xmm1,[16+ebp] + movdqu xmm2,[32+ebp] + movdqu xmm3,[48+ebp] + add ebp,64 +db 102,15,56,0,198 + mov DWORD [196+esp],ebp + movdqa [96+esp],xmm7 + add ebx,DWORD [16+esp] + xor esi,edi + mov ebp,ecx + rol ecx,5 + add ebx,esi + xor ebp,edi + ror edx,7 +db 102,15,56,0,206 + add ebx,ecx + add eax,DWORD [20+esp] + xor ebp,edx + mov esi,ebx + paddd xmm0,xmm7 + rol ebx,5 + add eax,ebp + xor esi,edx + ror ecx,7 + movdqa [esp],xmm0 + add eax,ebx + add edi,DWORD [24+esp] + xor esi,ecx + mov ebp,eax + psubd xmm0,xmm7 + rol eax,5 + add edi,esi + xor ebp,ecx + ror ebx,7 + add edi,eax + add edx,DWORD [28+esp] + xor ebp,ebx + mov esi,edi + rol edi,5 + add edx,ebp + xor esi,ebx + ror eax,7 + add edx,edi + add ecx,DWORD [32+esp] + xor esi,eax + mov ebp,edx + rol edx,5 + add ecx,esi + xor ebp,eax + ror edi,7 +db 102,15,56,0,214 + add ecx,edx + add ebx,DWORD [36+esp] + xor ebp,edi + mov esi,ecx + paddd xmm1,xmm7 + rol ecx,5 + add ebx,ebp + xor esi,edi + ror edx,7 + movdqa [16+esp],xmm1 + add ebx,ecx + add eax,DWORD [40+esp] + xor esi,edx + mov ebp,ebx + psubd xmm1,xmm7 + rol ebx,5 + add eax,esi + xor ebp,edx + ror ecx,7 + add eax,ebx + add edi,DWORD [44+esp] + xor ebp,ecx + mov esi,eax + rol eax,5 + add edi,ebp + xor esi,ecx + ror ebx,7 + add edi,eax + add edx,DWORD [48+esp] + xor esi,ebx + mov ebp,edi + rol edi,5 + add edx,esi + xor ebp,ebx + ror eax,7 +db 102,15,56,0,222 + add edx,edi + add ecx,DWORD [52+esp] + xor ebp,eax + mov esi,edx + paddd xmm2,xmm7 + rol edx,5 + add ecx,ebp + xor esi,eax + ror edi,7 + movdqa [32+esp],xmm2 + add ecx,edx + add ebx,DWORD [56+esp] + xor esi,edi + mov ebp,ecx + psubd xmm2,xmm7 + rol ecx,5 + add ebx,esi + xor ebp,edi + ror edx,7 + add ebx,ecx + add eax,DWORD [60+esp] + xor ebp,edx + mov esi,ebx + rol ebx,5 + add eax,ebp + ror ecx,7 + add eax,ebx + mov ebp,DWORD [192+esp] + add eax,DWORD [ebp] + add esi,DWORD [4+ebp] + add ecx,DWORD [8+ebp] + mov DWORD [ebp],eax + add edx,DWORD [12+ebp] + mov DWORD [4+ebp],esi + add edi,DWORD [16+ebp] + mov DWORD [8+ebp],ecx + mov ebx,ecx + mov DWORD [12+ebp],edx + xor ebx,edx + mov DWORD [16+ebp],edi + mov ebp,esi + pshufd xmm4,xmm0,238 + and esi,ebx + mov ebx,ebp + jmp NEAR L$002loop +align 16 +L$003done: + add ebx,DWORD [16+esp] + xor esi,edi + mov ebp,ecx + rol ecx,5 + add ebx,esi + xor ebp,edi + ror edx,7 + add ebx,ecx + add eax,DWORD [20+esp] + xor ebp,edx + mov esi,ebx + rol ebx,5 + add eax,ebp + xor esi,edx + ror ecx,7 + add eax,ebx + add edi,DWORD [24+esp] + xor esi,ecx + mov ebp,eax + rol eax,5 + add edi,esi + xor ebp,ecx + ror ebx,7 + add edi,eax + add edx,DWORD [28+esp] + xor ebp,ebx + mov esi,edi + rol edi,5 + add edx,ebp + xor esi,ebx + ror eax,7 + add edx,edi + add ecx,DWORD [32+esp] + xor esi,eax + mov ebp,edx + rol edx,5 + add ecx,esi + xor ebp,eax + ror edi,7 + add ecx,edx + add ebx,DWORD [36+esp] + xor ebp,edi + mov esi,ecx + rol ecx,5 + add ebx,ebp + xor esi,edi + ror edx,7 + add ebx,ecx + add eax,DWORD [40+esp] + xor esi,edx + mov ebp,ebx + rol ebx,5 + add eax,esi + xor ebp,edx + ror ecx,7 + add eax,ebx + add edi,DWORD [44+esp] + xor ebp,ecx + mov esi,eax + rol eax,5 + add edi,ebp + xor esi,ecx + ror ebx,7 + add edi,eax + add edx,DWORD [48+esp] + xor esi,ebx + mov ebp,edi + rol edi,5 + add edx,esi + xor ebp,ebx + ror eax,7 + add edx,edi + add ecx,DWORD [52+esp] + xor ebp,eax + mov esi,edx + rol edx,5 + add ecx,ebp + xor esi,eax + ror edi,7 + add ecx,edx + add ebx,DWORD [56+esp] + xor esi,edi + mov ebp,ecx + rol ecx,5 + add ebx,esi + xor ebp,edi + ror edx,7 + add ebx,ecx + add eax,DWORD [60+esp] + xor ebp,edx + mov esi,ebx + rol ebx,5 + add eax,ebp + ror ecx,7 + add eax,ebx + mov ebp,DWORD [192+esp] + add eax,DWORD [ebp] + mov esp,DWORD [204+esp] + add esi,DWORD [4+ebp] + add ecx,DWORD [8+ebp] + mov DWORD [ebp],eax + add edx,DWORD [12+ebp] + mov DWORD [4+ebp],esi + add edi,DWORD [16+ebp] + mov DWORD [8+ebp],ecx + mov DWORD [12+ebp],edx + mov DWORD [16+ebp],edi + pop edi + pop esi + pop ebx + pop ebp + ret +global _sha1_block_data_order_avx +align 16 +_sha1_block_data_order_avx: +L$_sha1_block_data_order_avx_begin: + push ebp + push ebx + push esi + push edi + call L$004pic_point +L$004pic_point: + pop ebp + lea ebp,[(L$K_XX_XX-L$004pic_point)+ebp] + vzeroall + vmovdqa xmm7,[ebp] + vmovdqa xmm0,[16+ebp] + vmovdqa xmm1,[32+ebp] + vmovdqa xmm2,[48+ebp] + vmovdqa xmm6,[64+ebp] + mov edi,DWORD [20+esp] + mov ebp,DWORD [24+esp] + mov edx,DWORD [28+esp] + mov esi,esp + sub esp,208 + and esp,-64 + vmovdqa [112+esp],xmm0 + vmovdqa [128+esp],xmm1 + vmovdqa [144+esp],xmm2 + shl edx,6 + vmovdqa [160+esp],xmm7 + add edx,ebp + vmovdqa [176+esp],xmm6 + add ebp,64 + mov DWORD [192+esp],edi + mov DWORD [196+esp],ebp + mov DWORD [200+esp],edx + mov DWORD [204+esp],esi + mov eax,DWORD [edi] + mov ebx,DWORD [4+edi] + mov ecx,DWORD [8+edi] + mov edx,DWORD [12+edi] + mov edi,DWORD [16+edi] + mov esi,ebx + vmovdqu xmm0,[ebp-64] + vmovdqu xmm1,[ebp-48] + vmovdqu xmm2,[ebp-32] + vmovdqu xmm3,[ebp-16] + vpshufb xmm0,xmm0,xmm6 + vpshufb xmm1,xmm1,xmm6 + vpshufb xmm2,xmm2,xmm6 + vmovdqa [96+esp],xmm7 + vpshufb xmm3,xmm3,xmm6 + vpaddd xmm4,xmm0,xmm7 + vpaddd xmm5,xmm1,xmm7 + vpaddd xmm6,xmm2,xmm7 + vmovdqa [esp],xmm4 + mov ebp,ecx + vmovdqa [16+esp],xmm5 + xor ebp,edx + vmovdqa [32+esp],xmm6 + and esi,ebp + jmp NEAR L$005loop +align 16 +L$005loop: + shrd ebx,ebx,2 + xor esi,edx + vpalignr xmm4,xmm1,xmm0,8 + mov ebp,eax + add edi,DWORD [esp] + vpaddd xmm7,xmm7,xmm3 + vmovdqa [64+esp],xmm0 + xor ebx,ecx + shld eax,eax,5 + vpsrldq xmm6,xmm3,4 + add edi,esi + and ebp,ebx + vpxor xmm4,xmm4,xmm0 + xor ebx,ecx + add edi,eax + vpxor xmm6,xmm6,xmm2 + shrd eax,eax,7 + xor ebp,ecx + vmovdqa [48+esp],xmm7 + mov esi,edi + add edx,DWORD [4+esp] + vpxor xmm4,xmm4,xmm6 + xor eax,ebx + shld edi,edi,5 + add edx,ebp + and esi,eax + vpsrld xmm6,xmm4,31 + xor eax,ebx + add edx,edi + shrd edi,edi,7 + xor esi,ebx + vpslldq xmm0,xmm4,12 + vpaddd xmm4,xmm4,xmm4 + mov ebp,edx + add ecx,DWORD [8+esp] + xor edi,eax + shld edx,edx,5 + vpsrld xmm7,xmm0,30 + vpor xmm4,xmm4,xmm6 + add ecx,esi + and ebp,edi + xor edi,eax + add ecx,edx + vpslld xmm0,xmm0,2 + shrd edx,edx,7 + xor ebp,eax + vpxor xmm4,xmm4,xmm7 + mov esi,ecx + add ebx,DWORD [12+esp] + xor edx,edi + shld ecx,ecx,5 + vpxor xmm4,xmm4,xmm0 + add ebx,ebp + and esi,edx + vmovdqa xmm0,[96+esp] + xor edx,edi + add ebx,ecx + shrd ecx,ecx,7 + xor esi,edi + vpalignr xmm5,xmm2,xmm1,8 + mov ebp,ebx + add eax,DWORD [16+esp] + vpaddd xmm0,xmm0,xmm4 + vmovdqa [80+esp],xmm1 + xor ecx,edx + shld ebx,ebx,5 + vpsrldq xmm7,xmm4,4 + add eax,esi + and ebp,ecx + vpxor xmm5,xmm5,xmm1 + xor ecx,edx + add eax,ebx + vpxor xmm7,xmm7,xmm3 + shrd ebx,ebx,7 + xor ebp,edx + vmovdqa [esp],xmm0 + mov esi,eax + add edi,DWORD [20+esp] + vpxor xmm5,xmm5,xmm7 + xor ebx,ecx + shld eax,eax,5 + add edi,ebp + and esi,ebx + vpsrld xmm7,xmm5,31 + xor ebx,ecx + add edi,eax + shrd eax,eax,7 + xor esi,ecx + vpslldq xmm1,xmm5,12 + vpaddd xmm5,xmm5,xmm5 + mov ebp,edi + add edx,DWORD [24+esp] + xor eax,ebx + shld edi,edi,5 + vpsrld xmm0,xmm1,30 + vpor xmm5,xmm5,xmm7 + add edx,esi + and ebp,eax + xor eax,ebx + add edx,edi + vpslld xmm1,xmm1,2 + shrd edi,edi,7 + xor ebp,ebx + vpxor xmm5,xmm5,xmm0 + mov esi,edx + add ecx,DWORD [28+esp] + xor edi,eax + shld edx,edx,5 + vpxor xmm5,xmm5,xmm1 + add ecx,ebp + and esi,edi + vmovdqa xmm1,[112+esp] + xor edi,eax + add ecx,edx + shrd edx,edx,7 + xor esi,eax + vpalignr xmm6,xmm3,xmm2,8 + mov ebp,ecx + add ebx,DWORD [32+esp] + vpaddd xmm1,xmm1,xmm5 + vmovdqa [96+esp],xmm2 + xor edx,edi + shld ecx,ecx,5 + vpsrldq xmm0,xmm5,4 + add ebx,esi + and ebp,edx + vpxor xmm6,xmm6,xmm2 + xor edx,edi + add ebx,ecx + vpxor xmm0,xmm0,xmm4 + shrd ecx,ecx,7 + xor ebp,edi + vmovdqa [16+esp],xmm1 + mov esi,ebx + add eax,DWORD [36+esp] + vpxor xmm6,xmm6,xmm0 + xor ecx,edx + shld ebx,ebx,5 + add eax,ebp + and esi,ecx + vpsrld xmm0,xmm6,31 + xor ecx,edx + add eax,ebx + shrd ebx,ebx,7 + xor esi,edx + vpslldq xmm2,xmm6,12 + vpaddd xmm6,xmm6,xmm6 + mov ebp,eax + add edi,DWORD [40+esp] + xor ebx,ecx + shld eax,eax,5 + vpsrld xmm1,xmm2,30 + vpor xmm6,xmm6,xmm0 + add edi,esi + and ebp,ebx + xor ebx,ecx + add edi,eax + vpslld xmm2,xmm2,2 + vmovdqa xmm0,[64+esp] + shrd eax,eax,7 + xor ebp,ecx + vpxor xmm6,xmm6,xmm1 + mov esi,edi + add edx,DWORD [44+esp] + xor eax,ebx + shld edi,edi,5 + vpxor xmm6,xmm6,xmm2 + add edx,ebp + and esi,eax + vmovdqa xmm2,[112+esp] + xor eax,ebx + add edx,edi + shrd edi,edi,7 + xor esi,ebx + vpalignr xmm7,xmm4,xmm3,8 + mov ebp,edx + add ecx,DWORD [48+esp] + vpaddd xmm2,xmm2,xmm6 + vmovdqa [64+esp],xmm3 + xor edi,eax + shld edx,edx,5 + vpsrldq xmm1,xmm6,4 + add ecx,esi + and ebp,edi + vpxor xmm7,xmm7,xmm3 + xor edi,eax + add ecx,edx + vpxor xmm1,xmm1,xmm5 + shrd edx,edx,7 + xor ebp,eax + vmovdqa [32+esp],xmm2 + mov esi,ecx + add ebx,DWORD [52+esp] + vpxor xmm7,xmm7,xmm1 + xor edx,edi + shld ecx,ecx,5 + add ebx,ebp + and esi,edx + vpsrld xmm1,xmm7,31 + xor edx,edi + add ebx,ecx + shrd ecx,ecx,7 + xor esi,edi + vpslldq xmm3,xmm7,12 + vpaddd xmm7,xmm7,xmm7 + mov ebp,ebx + add eax,DWORD [56+esp] + xor ecx,edx + shld ebx,ebx,5 + vpsrld xmm2,xmm3,30 + vpor xmm7,xmm7,xmm1 + add eax,esi + and ebp,ecx + xor ecx,edx + add eax,ebx + vpslld xmm3,xmm3,2 + vmovdqa xmm1,[80+esp] + shrd ebx,ebx,7 + xor ebp,edx + vpxor xmm7,xmm7,xmm2 + mov esi,eax + add edi,DWORD [60+esp] + xor ebx,ecx + shld eax,eax,5 + vpxor xmm7,xmm7,xmm3 + add edi,ebp + and esi,ebx + vmovdqa xmm3,[112+esp] + xor ebx,ecx + add edi,eax + vpalignr xmm2,xmm7,xmm6,8 + vpxor xmm0,xmm0,xmm4 + shrd eax,eax,7 + xor esi,ecx + mov ebp,edi + add edx,DWORD [esp] + vpxor xmm0,xmm0,xmm1 + vmovdqa [80+esp],xmm4 + xor eax,ebx + shld edi,edi,5 + vmovdqa xmm4,xmm3 + vpaddd xmm3,xmm3,xmm7 + add edx,esi + and ebp,eax + vpxor xmm0,xmm0,xmm2 + xor eax,ebx + add edx,edi + shrd edi,edi,7 + xor ebp,ebx + vpsrld xmm2,xmm0,30 + vmovdqa [48+esp],xmm3 + mov esi,edx + add ecx,DWORD [4+esp] + xor edi,eax + shld edx,edx,5 + vpslld xmm0,xmm0,2 + add ecx,ebp + and esi,edi + xor edi,eax + add ecx,edx + shrd edx,edx,7 + xor esi,eax + mov ebp,ecx + add ebx,DWORD [8+esp] + vpor xmm0,xmm0,xmm2 + xor edx,edi + shld ecx,ecx,5 + vmovdqa xmm2,[96+esp] + add ebx,esi + and ebp,edx + xor edx,edi + add ebx,ecx + add eax,DWORD [12+esp] + xor ebp,edi + mov esi,ebx + shld ebx,ebx,5 + add eax,ebp + xor esi,edx + shrd ecx,ecx,7 + add eax,ebx + vpalignr xmm3,xmm0,xmm7,8 + vpxor xmm1,xmm1,xmm5 + add edi,DWORD [16+esp] + xor esi,ecx + mov ebp,eax + shld eax,eax,5 + vpxor xmm1,xmm1,xmm2 + vmovdqa [96+esp],xmm5 + add edi,esi + xor ebp,ecx + vmovdqa xmm5,xmm4 + vpaddd xmm4,xmm4,xmm0 + shrd ebx,ebx,7 + add edi,eax + vpxor xmm1,xmm1,xmm3 + add edx,DWORD [20+esp] + xor ebp,ebx + mov esi,edi + shld edi,edi,5 + vpsrld xmm3,xmm1,30 + vmovdqa [esp],xmm4 + add edx,ebp + xor esi,ebx + shrd eax,eax,7 + add edx,edi + vpslld xmm1,xmm1,2 + add ecx,DWORD [24+esp] + xor esi,eax + mov ebp,edx + shld edx,edx,5 + add ecx,esi + xor ebp,eax + shrd edi,edi,7 + add ecx,edx + vpor xmm1,xmm1,xmm3 + add ebx,DWORD [28+esp] + xor ebp,edi + vmovdqa xmm3,[64+esp] + mov esi,ecx + shld ecx,ecx,5 + add ebx,ebp + xor esi,edi + shrd edx,edx,7 + add ebx,ecx + vpalignr xmm4,xmm1,xmm0,8 + vpxor xmm2,xmm2,xmm6 + add eax,DWORD [32+esp] + xor esi,edx + mov ebp,ebx + shld ebx,ebx,5 + vpxor xmm2,xmm2,xmm3 + vmovdqa [64+esp],xmm6 + add eax,esi + xor ebp,edx + vmovdqa xmm6,[128+esp] + vpaddd xmm5,xmm5,xmm1 + shrd ecx,ecx,7 + add eax,ebx + vpxor xmm2,xmm2,xmm4 + add edi,DWORD [36+esp] + xor ebp,ecx + mov esi,eax + shld eax,eax,5 + vpsrld xmm4,xmm2,30 + vmovdqa [16+esp],xmm5 + add edi,ebp + xor esi,ecx + shrd ebx,ebx,7 + add edi,eax + vpslld xmm2,xmm2,2 + add edx,DWORD [40+esp] + xor esi,ebx + mov ebp,edi + shld edi,edi,5 + add edx,esi + xor ebp,ebx + shrd eax,eax,7 + add edx,edi + vpor xmm2,xmm2,xmm4 + add ecx,DWORD [44+esp] + xor ebp,eax + vmovdqa xmm4,[80+esp] + mov esi,edx + shld edx,edx,5 + add ecx,ebp + xor esi,eax + shrd edi,edi,7 + add ecx,edx + vpalignr xmm5,xmm2,xmm1,8 + vpxor xmm3,xmm3,xmm7 + add ebx,DWORD [48+esp] + xor esi,edi + mov ebp,ecx + shld ecx,ecx,5 + vpxor xmm3,xmm3,xmm4 + vmovdqa [80+esp],xmm7 + add ebx,esi + xor ebp,edi + vmovdqa xmm7,xmm6 + vpaddd xmm6,xmm6,xmm2 + shrd edx,edx,7 + add ebx,ecx + vpxor xmm3,xmm3,xmm5 + add eax,DWORD [52+esp] + xor ebp,edx + mov esi,ebx + shld ebx,ebx,5 + vpsrld xmm5,xmm3,30 + vmovdqa [32+esp],xmm6 + add eax,ebp + xor esi,edx + shrd ecx,ecx,7 + add eax,ebx + vpslld xmm3,xmm3,2 + add edi,DWORD [56+esp] + xor esi,ecx + mov ebp,eax + shld eax,eax,5 + add edi,esi + xor ebp,ecx + shrd ebx,ebx,7 + add edi,eax + vpor xmm3,xmm3,xmm5 + add edx,DWORD [60+esp] + xor ebp,ebx + vmovdqa xmm5,[96+esp] + mov esi,edi + shld edi,edi,5 + add edx,ebp + xor esi,ebx + shrd eax,eax,7 + add edx,edi + vpalignr xmm6,xmm3,xmm2,8 + vpxor xmm4,xmm4,xmm0 + add ecx,DWORD [esp] + xor esi,eax + mov ebp,edx + shld edx,edx,5 + vpxor xmm4,xmm4,xmm5 + vmovdqa [96+esp],xmm0 + add ecx,esi + xor ebp,eax + vmovdqa xmm0,xmm7 + vpaddd xmm7,xmm7,xmm3 + shrd edi,edi,7 + add ecx,edx + vpxor xmm4,xmm4,xmm6 + add ebx,DWORD [4+esp] + xor ebp,edi + mov esi,ecx + shld ecx,ecx,5 + vpsrld xmm6,xmm4,30 + vmovdqa [48+esp],xmm7 + add ebx,ebp + xor esi,edi + shrd edx,edx,7 + add ebx,ecx + vpslld xmm4,xmm4,2 + add eax,DWORD [8+esp] + xor esi,edx + mov ebp,ebx + shld ebx,ebx,5 + add eax,esi + xor ebp,edx + shrd ecx,ecx,7 + add eax,ebx + vpor xmm4,xmm4,xmm6 + add edi,DWORD [12+esp] + xor ebp,ecx + vmovdqa xmm6,[64+esp] + mov esi,eax + shld eax,eax,5 + add edi,ebp + xor esi,ecx + shrd ebx,ebx,7 + add edi,eax + vpalignr xmm7,xmm4,xmm3,8 + vpxor xmm5,xmm5,xmm1 + add edx,DWORD [16+esp] + xor esi,ebx + mov ebp,edi + shld edi,edi,5 + vpxor xmm5,xmm5,xmm6 + vmovdqa [64+esp],xmm1 + add edx,esi + xor ebp,ebx + vmovdqa xmm1,xmm0 + vpaddd xmm0,xmm0,xmm4 + shrd eax,eax,7 + add edx,edi + vpxor xmm5,xmm5,xmm7 + add ecx,DWORD [20+esp] + xor ebp,eax + mov esi,edx + shld edx,edx,5 + vpsrld xmm7,xmm5,30 + vmovdqa [esp],xmm0 + add ecx,ebp + xor esi,eax + shrd edi,edi,7 + add ecx,edx + vpslld xmm5,xmm5,2 + add ebx,DWORD [24+esp] + xor esi,edi + mov ebp,ecx + shld ecx,ecx,5 + add ebx,esi + xor ebp,edi + shrd edx,edx,7 + add ebx,ecx + vpor xmm5,xmm5,xmm7 + add eax,DWORD [28+esp] + vmovdqa xmm7,[80+esp] + shrd ecx,ecx,7 + mov esi,ebx + xor ebp,edx + shld ebx,ebx,5 + add eax,ebp + xor esi,ecx + xor ecx,edx + add eax,ebx + vpalignr xmm0,xmm5,xmm4,8 + vpxor xmm6,xmm6,xmm2 + add edi,DWORD [32+esp] + and esi,ecx + xor ecx,edx + shrd ebx,ebx,7 + vpxor xmm6,xmm6,xmm7 + vmovdqa [80+esp],xmm2 + mov ebp,eax + xor esi,ecx + vmovdqa xmm2,xmm1 + vpaddd xmm1,xmm1,xmm5 + shld eax,eax,5 + add edi,esi + vpxor xmm6,xmm6,xmm0 + xor ebp,ebx + xor ebx,ecx + add edi,eax + add edx,DWORD [36+esp] + vpsrld xmm0,xmm6,30 + vmovdqa [16+esp],xmm1 + and ebp,ebx + xor ebx,ecx + shrd eax,eax,7 + mov esi,edi + vpslld xmm6,xmm6,2 + xor ebp,ebx + shld edi,edi,5 + add edx,ebp + xor esi,eax + xor eax,ebx + add edx,edi + add ecx,DWORD [40+esp] + and esi,eax + vpor xmm6,xmm6,xmm0 + xor eax,ebx + shrd edi,edi,7 + vmovdqa xmm0,[96+esp] + mov ebp,edx + xor esi,eax + shld edx,edx,5 + add ecx,esi + xor ebp,edi + xor edi,eax + add ecx,edx + add ebx,DWORD [44+esp] + and ebp,edi + xor edi,eax + shrd edx,edx,7 + mov esi,ecx + xor ebp,edi + shld ecx,ecx,5 + add ebx,ebp + xor esi,edx + xor edx,edi + add ebx,ecx + vpalignr xmm1,xmm6,xmm5,8 + vpxor xmm7,xmm7,xmm3 + add eax,DWORD [48+esp] + and esi,edx + xor edx,edi + shrd ecx,ecx,7 + vpxor xmm7,xmm7,xmm0 + vmovdqa [96+esp],xmm3 + mov ebp,ebx + xor esi,edx + vmovdqa xmm3,[144+esp] + vpaddd xmm2,xmm2,xmm6 + shld ebx,ebx,5 + add eax,esi + vpxor xmm7,xmm7,xmm1 + xor ebp,ecx + xor ecx,edx + add eax,ebx + add edi,DWORD [52+esp] + vpsrld xmm1,xmm7,30 + vmovdqa [32+esp],xmm2 + and ebp,ecx + xor ecx,edx + shrd ebx,ebx,7 + mov esi,eax + vpslld xmm7,xmm7,2 + xor ebp,ecx + shld eax,eax,5 + add edi,ebp + xor esi,ebx + xor ebx,ecx + add edi,eax + add edx,DWORD [56+esp] + and esi,ebx + vpor xmm7,xmm7,xmm1 + xor ebx,ecx + shrd eax,eax,7 + vmovdqa xmm1,[64+esp] + mov ebp,edi + xor esi,ebx + shld edi,edi,5 + add edx,esi + xor ebp,eax + xor eax,ebx + add edx,edi + add ecx,DWORD [60+esp] + and ebp,eax + xor eax,ebx + shrd edi,edi,7 + mov esi,edx + xor ebp,eax + shld edx,edx,5 + add ecx,ebp + xor esi,edi + xor edi,eax + add ecx,edx + vpalignr xmm2,xmm7,xmm6,8 + vpxor xmm0,xmm0,xmm4 + add ebx,DWORD [esp] + and esi,edi + xor edi,eax + shrd edx,edx,7 + vpxor xmm0,xmm0,xmm1 + vmovdqa [64+esp],xmm4 + mov ebp,ecx + xor esi,edi + vmovdqa xmm4,xmm3 + vpaddd xmm3,xmm3,xmm7 + shld ecx,ecx,5 + add ebx,esi + vpxor xmm0,xmm0,xmm2 + xor ebp,edx + xor edx,edi + add ebx,ecx + add eax,DWORD [4+esp] + vpsrld xmm2,xmm0,30 + vmovdqa [48+esp],xmm3 + and ebp,edx + xor edx,edi + shrd ecx,ecx,7 + mov esi,ebx + vpslld xmm0,xmm0,2 + xor ebp,edx + shld ebx,ebx,5 + add eax,ebp + xor esi,ecx + xor ecx,edx + add eax,ebx + add edi,DWORD [8+esp] + and esi,ecx + vpor xmm0,xmm0,xmm2 + xor ecx,edx + shrd ebx,ebx,7 + vmovdqa xmm2,[80+esp] + mov ebp,eax + xor esi,ecx + shld eax,eax,5 + add edi,esi + xor ebp,ebx + xor ebx,ecx + add edi,eax + add edx,DWORD [12+esp] + and ebp,ebx + xor ebx,ecx + shrd eax,eax,7 + mov esi,edi + xor ebp,ebx + shld edi,edi,5 + add edx,ebp + xor esi,eax + xor eax,ebx + add edx,edi + vpalignr xmm3,xmm0,xmm7,8 + vpxor xmm1,xmm1,xmm5 + add ecx,DWORD [16+esp] + and esi,eax + xor eax,ebx + shrd edi,edi,7 + vpxor xmm1,xmm1,xmm2 + vmovdqa [80+esp],xmm5 + mov ebp,edx + xor esi,eax + vmovdqa xmm5,xmm4 + vpaddd xmm4,xmm4,xmm0 + shld edx,edx,5 + add ecx,esi + vpxor xmm1,xmm1,xmm3 + xor ebp,edi + xor edi,eax + add ecx,edx + add ebx,DWORD [20+esp] + vpsrld xmm3,xmm1,30 + vmovdqa [esp],xmm4 + and ebp,edi + xor edi,eax + shrd edx,edx,7 + mov esi,ecx + vpslld xmm1,xmm1,2 + xor ebp,edi + shld ecx,ecx,5 + add ebx,ebp + xor esi,edx + xor edx,edi + add ebx,ecx + add eax,DWORD [24+esp] + and esi,edx + vpor xmm1,xmm1,xmm3 + xor edx,edi + shrd ecx,ecx,7 + vmovdqa xmm3,[96+esp] + mov ebp,ebx + xor esi,edx + shld ebx,ebx,5 + add eax,esi + xor ebp,ecx + xor ecx,edx + add eax,ebx + add edi,DWORD [28+esp] + and ebp,ecx + xor ecx,edx + shrd ebx,ebx,7 + mov esi,eax + xor ebp,ecx + shld eax,eax,5 + add edi,ebp + xor esi,ebx + xor ebx,ecx + add edi,eax + vpalignr xmm4,xmm1,xmm0,8 + vpxor xmm2,xmm2,xmm6 + add edx,DWORD [32+esp] + and esi,ebx + xor ebx,ecx + shrd eax,eax,7 + vpxor xmm2,xmm2,xmm3 + vmovdqa [96+esp],xmm6 + mov ebp,edi + xor esi,ebx + vmovdqa xmm6,xmm5 + vpaddd xmm5,xmm5,xmm1 + shld edi,edi,5 + add edx,esi + vpxor xmm2,xmm2,xmm4 + xor ebp,eax + xor eax,ebx + add edx,edi + add ecx,DWORD [36+esp] + vpsrld xmm4,xmm2,30 + vmovdqa [16+esp],xmm5 + and ebp,eax + xor eax,ebx + shrd edi,edi,7 + mov esi,edx + vpslld xmm2,xmm2,2 + xor ebp,eax + shld edx,edx,5 + add ecx,ebp + xor esi,edi + xor edi,eax + add ecx,edx + add ebx,DWORD [40+esp] + and esi,edi + vpor xmm2,xmm2,xmm4 + xor edi,eax + shrd edx,edx,7 + vmovdqa xmm4,[64+esp] + mov ebp,ecx + xor esi,edi + shld ecx,ecx,5 + add ebx,esi + xor ebp,edx + xor edx,edi + add ebx,ecx + add eax,DWORD [44+esp] + and ebp,edx + xor edx,edi + shrd ecx,ecx,7 + mov esi,ebx + xor ebp,edx + shld ebx,ebx,5 + add eax,ebp + xor esi,edx + add eax,ebx + vpalignr xmm5,xmm2,xmm1,8 + vpxor xmm3,xmm3,xmm7 + add edi,DWORD [48+esp] + xor esi,ecx + mov ebp,eax + shld eax,eax,5 + vpxor xmm3,xmm3,xmm4 + vmovdqa [64+esp],xmm7 + add edi,esi + xor ebp,ecx + vmovdqa xmm7,xmm6 + vpaddd xmm6,xmm6,xmm2 + shrd ebx,ebx,7 + add edi,eax + vpxor xmm3,xmm3,xmm5 + add edx,DWORD [52+esp] + xor ebp,ebx + mov esi,edi + shld edi,edi,5 + vpsrld xmm5,xmm3,30 + vmovdqa [32+esp],xmm6 + add edx,ebp + xor esi,ebx + shrd eax,eax,7 + add edx,edi + vpslld xmm3,xmm3,2 + add ecx,DWORD [56+esp] + xor esi,eax + mov ebp,edx + shld edx,edx,5 + add ecx,esi + xor ebp,eax + shrd edi,edi,7 + add ecx,edx + vpor xmm3,xmm3,xmm5 + add ebx,DWORD [60+esp] + xor ebp,edi + mov esi,ecx + shld ecx,ecx,5 + add ebx,ebp + xor esi,edi + shrd edx,edx,7 + add ebx,ecx + add eax,DWORD [esp] + vpaddd xmm7,xmm7,xmm3 + xor esi,edx + mov ebp,ebx + shld ebx,ebx,5 + add eax,esi + vmovdqa [48+esp],xmm7 + xor ebp,edx + shrd ecx,ecx,7 + add eax,ebx + add edi,DWORD [4+esp] + xor ebp,ecx + mov esi,eax + shld eax,eax,5 + add edi,ebp + xor esi,ecx + shrd ebx,ebx,7 + add edi,eax + add edx,DWORD [8+esp] + xor esi,ebx + mov ebp,edi + shld edi,edi,5 + add edx,esi + xor ebp,ebx + shrd eax,eax,7 + add edx,edi + add ecx,DWORD [12+esp] + xor ebp,eax + mov esi,edx + shld edx,edx,5 + add ecx,ebp + xor esi,eax + shrd edi,edi,7 + add ecx,edx + mov ebp,DWORD [196+esp] + cmp ebp,DWORD [200+esp] + je NEAR L$006done + vmovdqa xmm7,[160+esp] + vmovdqa xmm6,[176+esp] + vmovdqu xmm0,[ebp] + vmovdqu xmm1,[16+ebp] + vmovdqu xmm2,[32+ebp] + vmovdqu xmm3,[48+ebp] + add ebp,64 + vpshufb xmm0,xmm0,xmm6 + mov DWORD [196+esp],ebp + vmovdqa [96+esp],xmm7 + add ebx,DWORD [16+esp] + xor esi,edi + vpshufb xmm1,xmm1,xmm6 + mov ebp,ecx + shld ecx,ecx,5 + vpaddd xmm4,xmm0,xmm7 + add ebx,esi + xor ebp,edi + shrd edx,edx,7 + add ebx,ecx + vmovdqa [esp],xmm4 + add eax,DWORD [20+esp] + xor ebp,edx + mov esi,ebx + shld ebx,ebx,5 + add eax,ebp + xor esi,edx + shrd ecx,ecx,7 + add eax,ebx + add edi,DWORD [24+esp] + xor esi,ecx + mov ebp,eax + shld eax,eax,5 + add edi,esi + xor ebp,ecx + shrd ebx,ebx,7 + add edi,eax + add edx,DWORD [28+esp] + xor ebp,ebx + mov esi,edi + shld edi,edi,5 + add edx,ebp + xor esi,ebx + shrd eax,eax,7 + add edx,edi + add ecx,DWORD [32+esp] + xor esi,eax + vpshufb xmm2,xmm2,xmm6 + mov ebp,edx + shld edx,edx,5 + vpaddd xmm5,xmm1,xmm7 + add ecx,esi + xor ebp,eax + shrd edi,edi,7 + add ecx,edx + vmovdqa [16+esp],xmm5 + add ebx,DWORD [36+esp] + xor ebp,edi + mov esi,ecx + shld ecx,ecx,5 + add ebx,ebp + xor esi,edi + shrd edx,edx,7 + add ebx,ecx + add eax,DWORD [40+esp] + xor esi,edx + mov ebp,ebx + shld ebx,ebx,5 + add eax,esi + xor ebp,edx + shrd ecx,ecx,7 + add eax,ebx + add edi,DWORD [44+esp] + xor ebp,ecx + mov esi,eax + shld eax,eax,5 + add edi,ebp + xor esi,ecx + shrd ebx,ebx,7 + add edi,eax + add edx,DWORD [48+esp] + xor esi,ebx + vpshufb xmm3,xmm3,xmm6 + mov ebp,edi + shld edi,edi,5 + vpaddd xmm6,xmm2,xmm7 + add edx,esi + xor ebp,ebx + shrd eax,eax,7 + add edx,edi + vmovdqa [32+esp],xmm6 + add ecx,DWORD [52+esp] + xor ebp,eax + mov esi,edx + shld edx,edx,5 + add ecx,ebp + xor esi,eax + shrd edi,edi,7 + add ecx,edx + add ebx,DWORD [56+esp] + xor esi,edi + mov ebp,ecx + shld ecx,ecx,5 + add ebx,esi + xor ebp,edi + shrd edx,edx,7 + add ebx,ecx + add eax,DWORD [60+esp] + xor ebp,edx + mov esi,ebx + shld ebx,ebx,5 + add eax,ebp + shrd ecx,ecx,7 + add eax,ebx + mov ebp,DWORD [192+esp] + add eax,DWORD [ebp] + add esi,DWORD [4+ebp] + add ecx,DWORD [8+ebp] + mov DWORD [ebp],eax + add edx,DWORD [12+ebp] + mov DWORD [4+ebp],esi + add edi,DWORD [16+ebp] + mov ebx,ecx + mov DWORD [8+ebp],ecx + xor ebx,edx + mov DWORD [12+ebp],edx + mov DWORD [16+ebp],edi + mov ebp,esi + and esi,ebx + mov ebx,ebp + jmp NEAR L$005loop +align 16 +L$006done: + add ebx,DWORD [16+esp] + xor esi,edi + mov ebp,ecx + shld ecx,ecx,5 + add ebx,esi + xor ebp,edi + shrd edx,edx,7 + add ebx,ecx + add eax,DWORD [20+esp] + xor ebp,edx + mov esi,ebx + shld ebx,ebx,5 + add eax,ebp + xor esi,edx + shrd ecx,ecx,7 + add eax,ebx + add edi,DWORD [24+esp] + xor esi,ecx + mov ebp,eax + shld eax,eax,5 + add edi,esi + xor ebp,ecx + shrd ebx,ebx,7 + add edi,eax + add edx,DWORD [28+esp] + xor ebp,ebx + mov esi,edi + shld edi,edi,5 + add edx,ebp + xor esi,ebx + shrd eax,eax,7 + add edx,edi + add ecx,DWORD [32+esp] + xor esi,eax + mov ebp,edx + shld edx,edx,5 + add ecx,esi + xor ebp,eax + shrd edi,edi,7 + add ecx,edx + add ebx,DWORD [36+esp] + xor ebp,edi + mov esi,ecx + shld ecx,ecx,5 + add ebx,ebp + xor esi,edi + shrd edx,edx,7 + add ebx,ecx + add eax,DWORD [40+esp] + xor esi,edx + mov ebp,ebx + shld ebx,ebx,5 + add eax,esi + xor ebp,edx + shrd ecx,ecx,7 + add eax,ebx + add edi,DWORD [44+esp] + xor ebp,ecx + mov esi,eax + shld eax,eax,5 + add edi,ebp + xor esi,ecx + shrd ebx,ebx,7 + add edi,eax + add edx,DWORD [48+esp] + xor esi,ebx + mov ebp,edi + shld edi,edi,5 + add edx,esi + xor ebp,ebx + shrd eax,eax,7 + add edx,edi + add ecx,DWORD [52+esp] + xor ebp,eax + mov esi,edx + shld edx,edx,5 + add ecx,ebp + xor esi,eax + shrd edi,edi,7 + add ecx,edx + add ebx,DWORD [56+esp] + xor esi,edi + mov ebp,ecx + shld ecx,ecx,5 + add ebx,esi + xor ebp,edi + shrd edx,edx,7 + add ebx,ecx + add eax,DWORD [60+esp] + xor ebp,edx + mov esi,ebx + shld ebx,ebx,5 + add eax,ebp + shrd ecx,ecx,7 + add eax,ebx + vzeroall + mov ebp,DWORD [192+esp] + add eax,DWORD [ebp] + mov esp,DWORD [204+esp] + add esi,DWORD [4+ebp] + add ecx,DWORD [8+ebp] + mov DWORD [ebp],eax + add edx,DWORD [12+ebp] + mov DWORD [4+ebp],esi + add edi,DWORD [16+ebp] + mov DWORD [8+ebp],ecx + mov DWORD [12+ebp],edx + mov DWORD [16+ebp],edi + pop edi + pop esi + pop ebx + pop ebp + ret +align 64 +L$K_XX_XX: +dd 1518500249,1518500249,1518500249,1518500249 +dd 1859775393,1859775393,1859775393,1859775393 +dd 2400959708,2400959708,2400959708,2400959708 +dd 3395469782,3395469782,3395469782,3395469782 +dd 66051,67438087,134810123,202182159 +db 15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0 db 83,72,65,49,32,98,108,111,99,107,32,116,114,97,110,115 db 102,111,114,109,32,102,111,114,32,120,56,54,44,32,67,82 db 89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112 diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha256-586-linux.linux.x86.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha256-586-linux.linux.x86.S index 1b2913b2..79af683c 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha256-586-linux.linux.x86.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha256-586-linux.linux.x86.S @@ -7,12 +7,12 @@ #if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86) && defined(__ELF__) .text -.globl sha256_block_data_order -.hidden sha256_block_data_order -.type sha256_block_data_order,@function +.globl sha256_block_data_order_nohw +.hidden sha256_block_data_order_nohw +.type sha256_block_data_order_nohw,@function .align 16 -sha256_block_data_order: -.L_sha256_block_data_order_begin: +sha256_block_data_order_nohw: +.L_sha256_block_data_order_nohw_begin: pushl %ebp pushl %ebx pushl %esi @@ -24,7 +24,7 @@ sha256_block_data_order: call .L000pic_point .L000pic_point: popl %ebp - leal .L001K256-.L000pic_point(%ebp),%ebp + leal .LK256-.L000pic_point(%ebp),%ebp subl $16,%esp andl $-64,%esp shll $6,%eax @@ -33,29 +33,13 @@ sha256_block_data_order: movl %edi,4(%esp) movl %eax,8(%esp) movl %ebx,12(%esp) - leal OPENSSL_ia32cap_P-.L001K256(%ebp),%edx - movl (%edx),%ecx - movl 4(%edx),%ebx - testl $1048576,%ecx - jnz .L002loop - movl 8(%edx),%edx - testl $16777216,%ecx - jz .L003no_xmm - andl $1073741824,%ecx - andl $268435968,%ebx - orl %ebx,%ecx - andl $1342177280,%ecx - cmpl $1342177280,%ecx - je .L004AVX - testl $512,%ebx - jnz .L005SSSE3 -.L003no_xmm: +.L001no_xmm: subl %edi,%eax cmpl $256,%eax - jae .L006unrolled - jmp .L002loop + jae .L002unrolled + jmp .L003loop .align 16 -.L002loop: +.L003loop: movl (%edi),%eax movl 4(%edi),%ebx movl 8(%edi),%ecx @@ -124,7 +108,7 @@ sha256_block_data_order: movl %ecx,28(%esp) movl %edi,32(%esp) .align 16 -.L00700_15: +.L00400_15: movl %edx,%ecx movl 24(%esp),%esi rorl $14,%ecx @@ -162,11 +146,11 @@ sha256_block_data_order: addl $4,%ebp addl %ebx,%eax cmpl $3248222580,%esi - jne .L00700_15 + jne .L00400_15 movl 156(%esp),%ecx - jmp .L00816_63 + jmp .L00516_63 .align 16 -.L00816_63: +.L00516_63: movl %ecx,%ebx movl 104(%esp),%esi rorl $11,%ecx @@ -221,7 +205,7 @@ sha256_block_data_order: addl $4,%ebp addl %ebx,%eax cmpl $3329325298,%esi - jne .L00816_63 + jne .L00516_63 movl 356(%esp),%esi movl 8(%esp),%ebx movl 16(%esp),%ecx @@ -248,7 +232,7 @@ sha256_block_data_order: leal 356(%esp),%esp subl $256,%ebp cmpl 8(%esp),%edi - jb .L002loop + jb .L003loop movl 12(%esp),%esp popl %edi popl %esi @@ -256,7 +240,7 @@ sha256_block_data_order: popl %ebp ret .align 64 -.L001K256: +.LK256: .long 1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298 .long 66051,67438087,134810123,202182159 .byte 83,72,65,50,53,54,32,98,108,111,99,107,32,116,114,97 @@ -265,7 +249,7 @@ sha256_block_data_order: .byte 112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103 .byte 62,0 .align 16 -.L006unrolled: +.L002unrolled: leal -96(%esp),%esp movl (%esi),%eax movl 4(%esi),%ebp @@ -282,9 +266,9 @@ sha256_block_data_order: movl %ebx,20(%esp) movl %ecx,24(%esp) movl %esi,28(%esp) - jmp .L009grand_loop + jmp .L006grand_loop .align 16 -.L009grand_loop: +.L006grand_loop: movl (%edi),%ebx movl 4(%edi),%ecx bswap %ebx @@ -3164,15 +3148,40 @@ sha256_block_data_order: movl %ebx,24(%esp) movl %ecx,28(%esp) cmpl 104(%esp),%edi - jb .L009grand_loop + jb .L006grand_loop movl 108(%esp),%esp popl %edi popl %esi popl %ebx popl %ebp ret -.align 32 -.L005SSSE3: +.size sha256_block_data_order_nohw,.-.L_sha256_block_data_order_nohw_begin +.globl sha256_block_data_order_ssse3 +.hidden sha256_block_data_order_ssse3 +.type sha256_block_data_order_ssse3,@function +.align 16 +sha256_block_data_order_ssse3: +.L_sha256_block_data_order_ssse3_begin: + pushl %ebp + pushl %ebx + pushl %esi + pushl %edi + movl 20(%esp),%esi + movl 24(%esp),%edi + movl 28(%esp),%eax + movl %esp,%ebx + call .L007pic_point +.L007pic_point: + popl %ebp + leal .LK256-.L007pic_point(%ebp),%ebp + subl $16,%esp + andl $-64,%esp + shll $6,%eax + addl %edi,%eax + movl %esi,(%esp) + movl %edi,4(%esp) + movl %eax,8(%esp) + movl %ebx,12(%esp) leal -96(%esp),%esp movl (%esi),%eax movl 4(%esi),%ebx @@ -3191,9 +3200,9 @@ sha256_block_data_order: movl %ecx,24(%esp) movl %esi,28(%esp) movdqa 256(%ebp),%xmm7 - jmp .L010grand_ssse3 + jmp .L008grand_ssse3 .align 16 -.L010grand_ssse3: +.L008grand_ssse3: movdqu (%edi),%xmm0 movdqu 16(%edi),%xmm1 movdqu 32(%edi),%xmm2 @@ -3216,9 +3225,9 @@ sha256_block_data_order: paddd %xmm3,%xmm7 movdqa %xmm6,64(%esp) movdqa %xmm7,80(%esp) - jmp .L011ssse3_00_47 + jmp .L009ssse3_00_47 .align 16 -.L011ssse3_00_47: +.L009ssse3_00_47: addl $64,%ebp movl %edx,%ecx movdqa %xmm1,%xmm4 @@ -3861,7 +3870,7 @@ sha256_block_data_order: addl %ecx,%eax movdqa %xmm6,80(%esp) cmpl $66051,64(%ebp) - jne .L011ssse3_00_47 + jne .L009ssse3_00_47 movl %edx,%ecx rorl $14,%edx movl 20(%esp),%esi @@ -4375,15 +4384,40 @@ sha256_block_data_order: movdqa 64(%ebp),%xmm7 subl $192,%ebp cmpl 104(%esp),%edi - jb .L010grand_ssse3 + jb .L008grand_ssse3 movl 108(%esp),%esp popl %edi popl %esi popl %ebx popl %ebp ret -.align 32 -.L004AVX: +.size sha256_block_data_order_ssse3,.-.L_sha256_block_data_order_ssse3_begin +.globl sha256_block_data_order_avx +.hidden sha256_block_data_order_avx +.type sha256_block_data_order_avx,@function +.align 16 +sha256_block_data_order_avx: +.L_sha256_block_data_order_avx_begin: + pushl %ebp + pushl %ebx + pushl %esi + pushl %edi + movl 20(%esp),%esi + movl 24(%esp),%edi + movl 28(%esp),%eax + movl %esp,%ebx + call .L010pic_point +.L010pic_point: + popl %ebp + leal .LK256-.L010pic_point(%ebp),%ebp + subl $16,%esp + andl $-64,%esp + shll $6,%eax + addl %edi,%eax + movl %esi,(%esp) + movl %edi,4(%esp) + movl %eax,8(%esp) + movl %ebx,12(%esp) leal -96(%esp),%esp vzeroall movl (%esi),%eax @@ -4403,9 +4437,9 @@ sha256_block_data_order: movl %ecx,24(%esp) movl %esi,28(%esp) vmovdqa 256(%ebp),%xmm7 - jmp .L012grand_avx + jmp .L011grand_avx .align 32 -.L012grand_avx: +.L011grand_avx: vmovdqu (%edi),%xmm0 vmovdqu 16(%edi),%xmm1 vmovdqu 32(%edi),%xmm2 @@ -4424,9 +4458,9 @@ sha256_block_data_order: vmovdqa %xmm5,48(%esp) vmovdqa %xmm6,64(%esp) vmovdqa %xmm7,80(%esp) - jmp .L013avx_00_47 + jmp .L012avx_00_47 .align 16 -.L013avx_00_47: +.L012avx_00_47: addl $64,%ebp vpalignr $4,%xmm0,%xmm1,%xmm4 movl %edx,%ecx @@ -5041,7 +5075,7 @@ sha256_block_data_order: addl %ecx,%eax vmovdqa %xmm6,80(%esp) cmpl $66051,64(%ebp) - jne .L013avx_00_47 + jne .L012avx_00_47 movl %edx,%ecx shrdl $14,%edx,%edx movl 20(%esp),%esi @@ -5555,7 +5589,7 @@ sha256_block_data_order: vmovdqa 64(%ebp),%xmm7 subl $192,%ebp cmpl 104(%esp),%edi - jb .L012grand_avx + jb .L011grand_avx movl 108(%esp),%esp vzeroall popl %edi @@ -5563,7 +5597,7 @@ sha256_block_data_order: popl %ebx popl %ebp ret -.size sha256_block_data_order,.-.L_sha256_block_data_order_begin +.size sha256_block_data_order_avx,.-.L_sha256_block_data_order_avx_begin #endif // !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86) && defined(__ELF__) #endif // defined(__i386__) && defined(__linux__) #if defined(__linux__) && defined(__ELF__) diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha256-586-windows.windows.x86.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha256-586-windows.windows.x86.S index b0f5cd81..d00f36c7 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha256-586-windows.windows.x86.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha256-586-windows.windows.x86.S @@ -15,11 +15,10 @@ section .text code align=64 %else section .text code %endif -;extern _OPENSSL_ia32cap_P -global _sha256_block_data_order +global _sha256_block_data_order_nohw align 16 -_sha256_block_data_order: -L$_sha256_block_data_order_begin: +_sha256_block_data_order_nohw: +L$_sha256_block_data_order_nohw_begin: push ebp push ebx push esi @@ -31,7 +30,7 @@ L$_sha256_block_data_order_begin: call L$000pic_point L$000pic_point: pop ebp - lea ebp,[(L$001K256-L$000pic_point)+ebp] + lea ebp,[(L$K256-L$000pic_point)+ebp] sub esp,16 and esp,-64 shl eax,6 @@ -40,9 +39,13 @@ L$000pic_point: mov DWORD [4+esp],edi mov DWORD [8+esp],eax mov DWORD [12+esp],ebx - jmp NEAR L$002loop +L$001no_xmm: + sub eax,edi + cmp eax,256 + jae NEAR L$002unrolled + jmp NEAR L$003loop align 16 -L$002loop: +L$003loop: mov eax,DWORD [edi] mov ebx,DWORD [4+edi] mov ecx,DWORD [8+edi] @@ -111,7 +114,7 @@ L$002loop: mov DWORD [28+esp],ecx mov DWORD [32+esp],edi align 16 -L$00300_15: +L$00400_15: mov ecx,edx mov esi,DWORD [24+esp] ror ecx,14 @@ -149,11 +152,11 @@ L$00300_15: add ebp,4 add eax,ebx cmp esi,3248222580 - jne NEAR L$00300_15 + jne NEAR L$00400_15 mov ecx,DWORD [156+esp] - jmp NEAR L$00416_63 + jmp NEAR L$00516_63 align 16 -L$00416_63: +L$00516_63: mov ebx,ecx mov esi,DWORD [104+esp] ror ecx,11 @@ -208,7 +211,7 @@ L$00416_63: add ebp,4 add eax,ebx cmp esi,3329325298 - jne NEAR L$00416_63 + jne NEAR L$00516_63 mov esi,DWORD [356+esp] mov ebx,DWORD [8+esp] mov ecx,DWORD [16+esp] @@ -235,208 +238,7 @@ L$00416_63: lea esp,[356+esp] sub ebp,256 cmp edi,DWORD [8+esp] - jb NEAR L$002loop - mov esp,DWORD [12+esp] - pop edi - pop esi - pop ebx - pop ebp - ret -align 32 -L$005loop_shrd: - mov eax,DWORD [edi] - mov ebx,DWORD [4+edi] - mov ecx,DWORD [8+edi] - bswap eax - mov edx,DWORD [12+edi] - bswap ebx - push eax - bswap ecx - push ebx - bswap edx - push ecx - push edx - mov eax,DWORD [16+edi] - mov ebx,DWORD [20+edi] - mov ecx,DWORD [24+edi] - bswap eax - mov edx,DWORD [28+edi] - bswap ebx - push eax - bswap ecx - push ebx - bswap edx - push ecx - push edx - mov eax,DWORD [32+edi] - mov ebx,DWORD [36+edi] - mov ecx,DWORD [40+edi] - bswap eax - mov edx,DWORD [44+edi] - bswap ebx - push eax - bswap ecx - push ebx - bswap edx - push ecx - push edx - mov eax,DWORD [48+edi] - mov ebx,DWORD [52+edi] - mov ecx,DWORD [56+edi] - bswap eax - mov edx,DWORD [60+edi] - bswap ebx - push eax - bswap ecx - push ebx - bswap edx - push ecx - push edx - add edi,64 - lea esp,[esp-36] - mov DWORD [104+esp],edi - mov eax,DWORD [esi] - mov ebx,DWORD [4+esi] - mov ecx,DWORD [8+esi] - mov edi,DWORD [12+esi] - mov DWORD [8+esp],ebx - xor ebx,ecx - mov DWORD [12+esp],ecx - mov DWORD [16+esp],edi - mov DWORD [esp],ebx - mov edx,DWORD [16+esi] - mov ebx,DWORD [20+esi] - mov ecx,DWORD [24+esi] - mov edi,DWORD [28+esi] - mov DWORD [24+esp],ebx - mov DWORD [28+esp],ecx - mov DWORD [32+esp],edi -align 16 -L$00600_15_shrd: - mov ecx,edx - mov esi,DWORD [24+esp] - shrd ecx,ecx,14 - mov edi,DWORD [28+esp] - xor ecx,edx - xor esi,edi - mov ebx,DWORD [96+esp] - shrd ecx,ecx,5 - and esi,edx - mov DWORD [20+esp],edx - xor edx,ecx - add ebx,DWORD [32+esp] - xor esi,edi - shrd edx,edx,6 - mov ecx,eax - add ebx,esi - shrd ecx,ecx,9 - add ebx,edx - mov edi,DWORD [8+esp] - xor ecx,eax - mov DWORD [4+esp],eax - lea esp,[esp-4] - shrd ecx,ecx,11 - mov esi,DWORD [ebp] - xor ecx,eax - mov edx,DWORD [20+esp] - xor eax,edi - shrd ecx,ecx,2 - add ebx,esi - mov DWORD [esp],eax - add edx,ebx - and eax,DWORD [4+esp] - add ebx,ecx - xor eax,edi - add ebp,4 - add eax,ebx - cmp esi,3248222580 - jne NEAR L$00600_15_shrd - mov ecx,DWORD [156+esp] - jmp NEAR L$00716_63_shrd -align 16 -L$00716_63_shrd: - mov ebx,ecx - mov esi,DWORD [104+esp] - shrd ecx,ecx,11 - mov edi,esi - shrd esi,esi,2 - xor ecx,ebx - shr ebx,3 - shrd ecx,ecx,7 - xor esi,edi - xor ebx,ecx - shrd esi,esi,17 - add ebx,DWORD [160+esp] - shr edi,10 - add ebx,DWORD [124+esp] - mov ecx,edx - xor edi,esi - mov esi,DWORD [24+esp] - shrd ecx,ecx,14 - add ebx,edi - mov edi,DWORD [28+esp] - xor ecx,edx - xor esi,edi - mov DWORD [96+esp],ebx - shrd ecx,ecx,5 - and esi,edx - mov DWORD [20+esp],edx - xor edx,ecx - add ebx,DWORD [32+esp] - xor esi,edi - shrd edx,edx,6 - mov ecx,eax - add ebx,esi - shrd ecx,ecx,9 - add ebx,edx - mov edi,DWORD [8+esp] - xor ecx,eax - mov DWORD [4+esp],eax - lea esp,[esp-4] - shrd ecx,ecx,11 - mov esi,DWORD [ebp] - xor ecx,eax - mov edx,DWORD [20+esp] - xor eax,edi - shrd ecx,ecx,2 - add ebx,esi - mov DWORD [esp],eax - add edx,ebx - and eax,DWORD [4+esp] - add ebx,ecx - xor eax,edi - mov ecx,DWORD [156+esp] - add ebp,4 - add eax,ebx - cmp esi,3329325298 - jne NEAR L$00716_63_shrd - mov esi,DWORD [356+esp] - mov ebx,DWORD [8+esp] - mov ecx,DWORD [16+esp] - add eax,DWORD [esi] - add ebx,DWORD [4+esi] - add edi,DWORD [8+esi] - add ecx,DWORD [12+esi] - mov DWORD [esi],eax - mov DWORD [4+esi],ebx - mov DWORD [8+esi],edi - mov DWORD [12+esi],ecx - mov eax,DWORD [24+esp] - mov ebx,DWORD [28+esp] - mov ecx,DWORD [32+esp] - mov edi,DWORD [360+esp] - add edx,DWORD [16+esi] - add eax,DWORD [20+esi] - add ebx,DWORD [24+esi] - add ecx,DWORD [28+esi] - mov DWORD [16+esi],edx - mov DWORD [20+esi],eax - mov DWORD [24+esi],ebx - mov DWORD [28+esi],ecx - lea esp,[356+esp] - sub ebp,256 - cmp edi,DWORD [8+esp] - jb NEAR L$005loop_shrd + jb NEAR L$003loop mov esp,DWORD [12+esp] pop edi pop esi @@ -444,7 +246,7 @@ L$00716_63_shrd: pop ebp ret align 64 -L$001K256: +L$K256: dd 1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298 dd 66051,67438087,134810123,202182159 db 83,72,65,50,53,54,32,98,108,111,99,107,32,116,114,97 @@ -453,7 +255,7 @@ db 67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97 db 112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103 db 62,0 align 16 -L$008unrolled: +L$002unrolled: lea esp,[esp-96] mov eax,DWORD [esi] mov ebp,DWORD [4+esi] @@ -470,9 +272,9 @@ L$008unrolled: mov DWORD [20+esp],ebx mov DWORD [24+esp],ecx mov DWORD [28+esp],esi - jmp NEAR L$009grand_loop + jmp NEAR L$006grand_loop align 16 -L$009grand_loop: +L$006grand_loop: mov ebx,DWORD [edi] mov ecx,DWORD [4+edi] bswap ebx @@ -3352,15 +3154,2449 @@ L$009grand_loop: mov DWORD [24+esp],ebx mov DWORD [28+esp],ecx cmp edi,DWORD [104+esp] - jb NEAR L$009grand_loop + jb NEAR L$006grand_loop mov esp,DWORD [108+esp] pop edi pop esi pop ebx pop ebp ret -segment .bss -common _OPENSSL_ia32cap_P 16 +global _sha256_block_data_order_ssse3 +align 16 +_sha256_block_data_order_ssse3: +L$_sha256_block_data_order_ssse3_begin: + push ebp + push ebx + push esi + push edi + mov esi,DWORD [20+esp] + mov edi,DWORD [24+esp] + mov eax,DWORD [28+esp] + mov ebx,esp + call L$007pic_point +L$007pic_point: + pop ebp + lea ebp,[(L$K256-L$007pic_point)+ebp] + sub esp,16 + and esp,-64 + shl eax,6 + add eax,edi + mov DWORD [esp],esi + mov DWORD [4+esp],edi + mov DWORD [8+esp],eax + mov DWORD [12+esp],ebx + lea esp,[esp-96] + mov eax,DWORD [esi] + mov ebx,DWORD [4+esi] + mov ecx,DWORD [8+esi] + mov edi,DWORD [12+esi] + mov DWORD [4+esp],ebx + xor ebx,ecx + mov DWORD [8+esp],ecx + mov DWORD [12+esp],edi + mov edx,DWORD [16+esi] + mov edi,DWORD [20+esi] + mov ecx,DWORD [24+esi] + mov esi,DWORD [28+esi] + mov DWORD [20+esp],edi + mov edi,DWORD [100+esp] + mov DWORD [24+esp],ecx + mov DWORD [28+esp],esi + movdqa xmm7,[256+ebp] + jmp NEAR L$008grand_ssse3 +align 16 +L$008grand_ssse3: + movdqu xmm0,[edi] + movdqu xmm1,[16+edi] + movdqu xmm2,[32+edi] + movdqu xmm3,[48+edi] + add edi,64 +db 102,15,56,0,199 + mov DWORD [100+esp],edi +db 102,15,56,0,207 + movdqa xmm4,[ebp] +db 102,15,56,0,215 + movdqa xmm5,[16+ebp] + paddd xmm4,xmm0 +db 102,15,56,0,223 + movdqa xmm6,[32+ebp] + paddd xmm5,xmm1 + movdqa xmm7,[48+ebp] + movdqa [32+esp],xmm4 + paddd xmm6,xmm2 + movdqa [48+esp],xmm5 + paddd xmm7,xmm3 + movdqa [64+esp],xmm6 + movdqa [80+esp],xmm7 + jmp NEAR L$009ssse3_00_47 +align 16 +L$009ssse3_00_47: + add ebp,64 + mov ecx,edx + movdqa xmm4,xmm1 + ror edx,14 + mov esi,DWORD [20+esp] + movdqa xmm7,xmm3 + xor edx,ecx + mov edi,DWORD [24+esp] +db 102,15,58,15,224,4 + xor esi,edi + ror edx,5 + and esi,ecx +db 102,15,58,15,250,4 + mov DWORD [16+esp],ecx + xor edx,ecx + xor edi,esi + movdqa xmm5,xmm4 + ror edx,6 + mov ecx,eax + movdqa xmm6,xmm4 + add edx,edi + mov edi,DWORD [4+esp] + psrld xmm4,3 + mov esi,eax + ror ecx,9 + paddd xmm0,xmm7 + mov DWORD [esp],eax + xor ecx,eax + psrld xmm6,7 + xor eax,edi + add edx,DWORD [28+esp] + ror ecx,11 + and ebx,eax + pshufd xmm7,xmm3,250 + xor ecx,esi + add edx,DWORD [32+esp] + pslld xmm5,14 + xor ebx,edi + ror ecx,2 + pxor xmm4,xmm6 + add ebx,edx + add edx,DWORD [12+esp] + psrld xmm6,11 + add ebx,ecx + mov ecx,edx + ror edx,14 + pxor xmm4,xmm5 + mov esi,DWORD [16+esp] + xor edx,ecx + pslld xmm5,11 + mov edi,DWORD [20+esp] + xor esi,edi + ror edx,5 + pxor xmm4,xmm6 + and esi,ecx + mov DWORD [12+esp],ecx + movdqa xmm6,xmm7 + xor edx,ecx + xor edi,esi + ror edx,6 + pxor xmm4,xmm5 + mov ecx,ebx + add edx,edi + psrld xmm7,10 + mov edi,DWORD [esp] + mov esi,ebx + ror ecx,9 + paddd xmm0,xmm4 + mov DWORD [28+esp],ebx + xor ecx,ebx + psrlq xmm6,17 + xor ebx,edi + add edx,DWORD [24+esp] + ror ecx,11 + pxor xmm7,xmm6 + and eax,ebx + xor ecx,esi + psrlq xmm6,2 + add edx,DWORD [36+esp] + xor eax,edi + ror ecx,2 + pxor xmm7,xmm6 + add eax,edx + add edx,DWORD [8+esp] + pshufd xmm7,xmm7,128 + add eax,ecx + mov ecx,edx + ror edx,14 + mov esi,DWORD [12+esp] + xor edx,ecx + mov edi,DWORD [16+esp] + xor esi,edi + ror edx,5 + and esi,ecx + psrldq xmm7,8 + mov DWORD [8+esp],ecx + xor edx,ecx + xor edi,esi + paddd xmm0,xmm7 + ror edx,6 + mov ecx,eax + add edx,edi + mov edi,DWORD [28+esp] + mov esi,eax + ror ecx,9 + mov DWORD [24+esp],eax + pshufd xmm7,xmm0,80 + xor ecx,eax + xor eax,edi + add edx,DWORD [20+esp] + movdqa xmm6,xmm7 + ror ecx,11 + psrld xmm7,10 + and ebx,eax + psrlq xmm6,17 + xor ecx,esi + add edx,DWORD [40+esp] + xor ebx,edi + ror ecx,2 + pxor xmm7,xmm6 + add ebx,edx + add edx,DWORD [4+esp] + psrlq xmm6,2 + add ebx,ecx + mov ecx,edx + ror edx,14 + pxor xmm7,xmm6 + mov esi,DWORD [8+esp] + xor edx,ecx + mov edi,DWORD [12+esp] + pshufd xmm7,xmm7,8 + xor esi,edi + ror edx,5 + movdqa xmm6,[ebp] + and esi,ecx + mov DWORD [4+esp],ecx + pslldq xmm7,8 + xor edx,ecx + xor edi,esi + ror edx,6 + mov ecx,ebx + add edx,edi + mov edi,DWORD [24+esp] + mov esi,ebx + ror ecx,9 + paddd xmm0,xmm7 + mov DWORD [20+esp],ebx + xor ecx,ebx + xor ebx,edi + add edx,DWORD [16+esp] + paddd xmm6,xmm0 + ror ecx,11 + and eax,ebx + xor ecx,esi + add edx,DWORD [44+esp] + xor eax,edi + ror ecx,2 + add eax,edx + add edx,DWORD [esp] + add eax,ecx + movdqa [32+esp],xmm6 + mov ecx,edx + movdqa xmm4,xmm2 + ror edx,14 + mov esi,DWORD [4+esp] + movdqa xmm7,xmm0 + xor edx,ecx + mov edi,DWORD [8+esp] +db 102,15,58,15,225,4 + xor esi,edi + ror edx,5 + and esi,ecx +db 102,15,58,15,251,4 + mov DWORD [esp],ecx + xor edx,ecx + xor edi,esi + movdqa xmm5,xmm4 + ror edx,6 + mov ecx,eax + movdqa xmm6,xmm4 + add edx,edi + mov edi,DWORD [20+esp] + psrld xmm4,3 + mov esi,eax + ror ecx,9 + paddd xmm1,xmm7 + mov DWORD [16+esp],eax + xor ecx,eax + psrld xmm6,7 + xor eax,edi + add edx,DWORD [12+esp] + ror ecx,11 + and ebx,eax + pshufd xmm7,xmm0,250 + xor ecx,esi + add edx,DWORD [48+esp] + pslld xmm5,14 + xor ebx,edi + ror ecx,2 + pxor xmm4,xmm6 + add ebx,edx + add edx,DWORD [28+esp] + psrld xmm6,11 + add ebx,ecx + mov ecx,edx + ror edx,14 + pxor xmm4,xmm5 + mov esi,DWORD [esp] + xor edx,ecx + pslld xmm5,11 + mov edi,DWORD [4+esp] + xor esi,edi + ror edx,5 + pxor xmm4,xmm6 + and esi,ecx + mov DWORD [28+esp],ecx + movdqa xmm6,xmm7 + xor edx,ecx + xor edi,esi + ror edx,6 + pxor xmm4,xmm5 + mov ecx,ebx + add edx,edi + psrld xmm7,10 + mov edi,DWORD [16+esp] + mov esi,ebx + ror ecx,9 + paddd xmm1,xmm4 + mov DWORD [12+esp],ebx + xor ecx,ebx + psrlq xmm6,17 + xor ebx,edi + add edx,DWORD [8+esp] + ror ecx,11 + pxor xmm7,xmm6 + and eax,ebx + xor ecx,esi + psrlq xmm6,2 + add edx,DWORD [52+esp] + xor eax,edi + ror ecx,2 + pxor xmm7,xmm6 + add eax,edx + add edx,DWORD [24+esp] + pshufd xmm7,xmm7,128 + add eax,ecx + mov ecx,edx + ror edx,14 + mov esi,DWORD [28+esp] + xor edx,ecx + mov edi,DWORD [esp] + xor esi,edi + ror edx,5 + and esi,ecx + psrldq xmm7,8 + mov DWORD [24+esp],ecx + xor edx,ecx + xor edi,esi + paddd xmm1,xmm7 + ror edx,6 + mov ecx,eax + add edx,edi + mov edi,DWORD [12+esp] + mov esi,eax + ror ecx,9 + mov DWORD [8+esp],eax + pshufd xmm7,xmm1,80 + xor ecx,eax + xor eax,edi + add edx,DWORD [4+esp] + movdqa xmm6,xmm7 + ror ecx,11 + psrld xmm7,10 + and ebx,eax + psrlq xmm6,17 + xor ecx,esi + add edx,DWORD [56+esp] + xor ebx,edi + ror ecx,2 + pxor xmm7,xmm6 + add ebx,edx + add edx,DWORD [20+esp] + psrlq xmm6,2 + add ebx,ecx + mov ecx,edx + ror edx,14 + pxor xmm7,xmm6 + mov esi,DWORD [24+esp] + xor edx,ecx + mov edi,DWORD [28+esp] + pshufd xmm7,xmm7,8 + xor esi,edi + ror edx,5 + movdqa xmm6,[16+ebp] + and esi,ecx + mov DWORD [20+esp],ecx + pslldq xmm7,8 + xor edx,ecx + xor edi,esi + ror edx,6 + mov ecx,ebx + add edx,edi + mov edi,DWORD [8+esp] + mov esi,ebx + ror ecx,9 + paddd xmm1,xmm7 + mov DWORD [4+esp],ebx + xor ecx,ebx + xor ebx,edi + add edx,DWORD [esp] + paddd xmm6,xmm1 + ror ecx,11 + and eax,ebx + xor ecx,esi + add edx,DWORD [60+esp] + xor eax,edi + ror ecx,2 + add eax,edx + add edx,DWORD [16+esp] + add eax,ecx + movdqa [48+esp],xmm6 + mov ecx,edx + movdqa xmm4,xmm3 + ror edx,14 + mov esi,DWORD [20+esp] + movdqa xmm7,xmm1 + xor edx,ecx + mov edi,DWORD [24+esp] +db 102,15,58,15,226,4 + xor esi,edi + ror edx,5 + and esi,ecx +db 102,15,58,15,248,4 + mov DWORD [16+esp],ecx + xor edx,ecx + xor edi,esi + movdqa xmm5,xmm4 + ror edx,6 + mov ecx,eax + movdqa xmm6,xmm4 + add edx,edi + mov edi,DWORD [4+esp] + psrld xmm4,3 + mov esi,eax + ror ecx,9 + paddd xmm2,xmm7 + mov DWORD [esp],eax + xor ecx,eax + psrld xmm6,7 + xor eax,edi + add edx,DWORD [28+esp] + ror ecx,11 + and ebx,eax + pshufd xmm7,xmm1,250 + xor ecx,esi + add edx,DWORD [64+esp] + pslld xmm5,14 + xor ebx,edi + ror ecx,2 + pxor xmm4,xmm6 + add ebx,edx + add edx,DWORD [12+esp] + psrld xmm6,11 + add ebx,ecx + mov ecx,edx + ror edx,14 + pxor xmm4,xmm5 + mov esi,DWORD [16+esp] + xor edx,ecx + pslld xmm5,11 + mov edi,DWORD [20+esp] + xor esi,edi + ror edx,5 + pxor xmm4,xmm6 + and esi,ecx + mov DWORD [12+esp],ecx + movdqa xmm6,xmm7 + xor edx,ecx + xor edi,esi + ror edx,6 + pxor xmm4,xmm5 + mov ecx,ebx + add edx,edi + psrld xmm7,10 + mov edi,DWORD [esp] + mov esi,ebx + ror ecx,9 + paddd xmm2,xmm4 + mov DWORD [28+esp],ebx + xor ecx,ebx + psrlq xmm6,17 + xor ebx,edi + add edx,DWORD [24+esp] + ror ecx,11 + pxor xmm7,xmm6 + and eax,ebx + xor ecx,esi + psrlq xmm6,2 + add edx,DWORD [68+esp] + xor eax,edi + ror ecx,2 + pxor xmm7,xmm6 + add eax,edx + add edx,DWORD [8+esp] + pshufd xmm7,xmm7,128 + add eax,ecx + mov ecx,edx + ror edx,14 + mov esi,DWORD [12+esp] + xor edx,ecx + mov edi,DWORD [16+esp] + xor esi,edi + ror edx,5 + and esi,ecx + psrldq xmm7,8 + mov DWORD [8+esp],ecx + xor edx,ecx + xor edi,esi + paddd xmm2,xmm7 + ror edx,6 + mov ecx,eax + add edx,edi + mov edi,DWORD [28+esp] + mov esi,eax + ror ecx,9 + mov DWORD [24+esp],eax + pshufd xmm7,xmm2,80 + xor ecx,eax + xor eax,edi + add edx,DWORD [20+esp] + movdqa xmm6,xmm7 + ror ecx,11 + psrld xmm7,10 + and ebx,eax + psrlq xmm6,17 + xor ecx,esi + add edx,DWORD [72+esp] + xor ebx,edi + ror ecx,2 + pxor xmm7,xmm6 + add ebx,edx + add edx,DWORD [4+esp] + psrlq xmm6,2 + add ebx,ecx + mov ecx,edx + ror edx,14 + pxor xmm7,xmm6 + mov esi,DWORD [8+esp] + xor edx,ecx + mov edi,DWORD [12+esp] + pshufd xmm7,xmm7,8 + xor esi,edi + ror edx,5 + movdqa xmm6,[32+ebp] + and esi,ecx + mov DWORD [4+esp],ecx + pslldq xmm7,8 + xor edx,ecx + xor edi,esi + ror edx,6 + mov ecx,ebx + add edx,edi + mov edi,DWORD [24+esp] + mov esi,ebx + ror ecx,9 + paddd xmm2,xmm7 + mov DWORD [20+esp],ebx + xor ecx,ebx + xor ebx,edi + add edx,DWORD [16+esp] + paddd xmm6,xmm2 + ror ecx,11 + and eax,ebx + xor ecx,esi + add edx,DWORD [76+esp] + xor eax,edi + ror ecx,2 + add eax,edx + add edx,DWORD [esp] + add eax,ecx + movdqa [64+esp],xmm6 + mov ecx,edx + movdqa xmm4,xmm0 + ror edx,14 + mov esi,DWORD [4+esp] + movdqa xmm7,xmm2 + xor edx,ecx + mov edi,DWORD [8+esp] +db 102,15,58,15,227,4 + xor esi,edi + ror edx,5 + and esi,ecx +db 102,15,58,15,249,4 + mov DWORD [esp],ecx + xor edx,ecx + xor edi,esi + movdqa xmm5,xmm4 + ror edx,6 + mov ecx,eax + movdqa xmm6,xmm4 + add edx,edi + mov edi,DWORD [20+esp] + psrld xmm4,3 + mov esi,eax + ror ecx,9 + paddd xmm3,xmm7 + mov DWORD [16+esp],eax + xor ecx,eax + psrld xmm6,7 + xor eax,edi + add edx,DWORD [12+esp] + ror ecx,11 + and ebx,eax + pshufd xmm7,xmm2,250 + xor ecx,esi + add edx,DWORD [80+esp] + pslld xmm5,14 + xor ebx,edi + ror ecx,2 + pxor xmm4,xmm6 + add ebx,edx + add edx,DWORD [28+esp] + psrld xmm6,11 + add ebx,ecx + mov ecx,edx + ror edx,14 + pxor xmm4,xmm5 + mov esi,DWORD [esp] + xor edx,ecx + pslld xmm5,11 + mov edi,DWORD [4+esp] + xor esi,edi + ror edx,5 + pxor xmm4,xmm6 + and esi,ecx + mov DWORD [28+esp],ecx + movdqa xmm6,xmm7 + xor edx,ecx + xor edi,esi + ror edx,6 + pxor xmm4,xmm5 + mov ecx,ebx + add edx,edi + psrld xmm7,10 + mov edi,DWORD [16+esp] + mov esi,ebx + ror ecx,9 + paddd xmm3,xmm4 + mov DWORD [12+esp],ebx + xor ecx,ebx + psrlq xmm6,17 + xor ebx,edi + add edx,DWORD [8+esp] + ror ecx,11 + pxor xmm7,xmm6 + and eax,ebx + xor ecx,esi + psrlq xmm6,2 + add edx,DWORD [84+esp] + xor eax,edi + ror ecx,2 + pxor xmm7,xmm6 + add eax,edx + add edx,DWORD [24+esp] + pshufd xmm7,xmm7,128 + add eax,ecx + mov ecx,edx + ror edx,14 + mov esi,DWORD [28+esp] + xor edx,ecx + mov edi,DWORD [esp] + xor esi,edi + ror edx,5 + and esi,ecx + psrldq xmm7,8 + mov DWORD [24+esp],ecx + xor edx,ecx + xor edi,esi + paddd xmm3,xmm7 + ror edx,6 + mov ecx,eax + add edx,edi + mov edi,DWORD [12+esp] + mov esi,eax + ror ecx,9 + mov DWORD [8+esp],eax + pshufd xmm7,xmm3,80 + xor ecx,eax + xor eax,edi + add edx,DWORD [4+esp] + movdqa xmm6,xmm7 + ror ecx,11 + psrld xmm7,10 + and ebx,eax + psrlq xmm6,17 + xor ecx,esi + add edx,DWORD [88+esp] + xor ebx,edi + ror ecx,2 + pxor xmm7,xmm6 + add ebx,edx + add edx,DWORD [20+esp] + psrlq xmm6,2 + add ebx,ecx + mov ecx,edx + ror edx,14 + pxor xmm7,xmm6 + mov esi,DWORD [24+esp] + xor edx,ecx + mov edi,DWORD [28+esp] + pshufd xmm7,xmm7,8 + xor esi,edi + ror edx,5 + movdqa xmm6,[48+ebp] + and esi,ecx + mov DWORD [20+esp],ecx + pslldq xmm7,8 + xor edx,ecx + xor edi,esi + ror edx,6 + mov ecx,ebx + add edx,edi + mov edi,DWORD [8+esp] + mov esi,ebx + ror ecx,9 + paddd xmm3,xmm7 + mov DWORD [4+esp],ebx + xor ecx,ebx + xor ebx,edi + add edx,DWORD [esp] + paddd xmm6,xmm3 + ror ecx,11 + and eax,ebx + xor ecx,esi + add edx,DWORD [92+esp] + xor eax,edi + ror ecx,2 + add eax,edx + add edx,DWORD [16+esp] + add eax,ecx + movdqa [80+esp],xmm6 + cmp DWORD [64+ebp],66051 + jne NEAR L$009ssse3_00_47 + mov ecx,edx + ror edx,14 + mov esi,DWORD [20+esp] + xor edx,ecx + mov edi,DWORD [24+esp] + xor esi,edi + ror edx,5 + and esi,ecx + mov DWORD [16+esp],ecx + xor edx,ecx + xor edi,esi + ror edx,6 + mov ecx,eax + add edx,edi + mov edi,DWORD [4+esp] + mov esi,eax + ror ecx,9 + mov DWORD [esp],eax + xor ecx,eax + xor eax,edi + add edx,DWORD [28+esp] + ror ecx,11 + and ebx,eax + xor ecx,esi + add edx,DWORD [32+esp] + xor ebx,edi + ror ecx,2 + add ebx,edx + add edx,DWORD [12+esp] + add ebx,ecx + mov ecx,edx + ror edx,14 + mov esi,DWORD [16+esp] + xor edx,ecx + mov edi,DWORD [20+esp] + xor esi,edi + ror edx,5 + and esi,ecx + mov DWORD [12+esp],ecx + xor edx,ecx + xor edi,esi + ror edx,6 + mov ecx,ebx + add edx,edi + mov edi,DWORD [esp] + mov esi,ebx + ror ecx,9 + mov DWORD [28+esp],ebx + xor ecx,ebx + xor ebx,edi + add edx,DWORD [24+esp] + ror ecx,11 + and eax,ebx + xor ecx,esi + add edx,DWORD [36+esp] + xor eax,edi + ror ecx,2 + add eax,edx + add edx,DWORD [8+esp] + add eax,ecx + mov ecx,edx + ror edx,14 + mov esi,DWORD [12+esp] + xor edx,ecx + mov edi,DWORD [16+esp] + xor esi,edi + ror edx,5 + and esi,ecx + mov DWORD [8+esp],ecx + xor edx,ecx + xor edi,esi + ror edx,6 + mov ecx,eax + add edx,edi + mov edi,DWORD [28+esp] + mov esi,eax + ror ecx,9 + mov DWORD [24+esp],eax + xor ecx,eax + xor eax,edi + add edx,DWORD [20+esp] + ror ecx,11 + and ebx,eax + xor ecx,esi + add edx,DWORD [40+esp] + xor ebx,edi + ror ecx,2 + add ebx,edx + add edx,DWORD [4+esp] + add ebx,ecx + mov ecx,edx + ror edx,14 + mov esi,DWORD [8+esp] + xor edx,ecx + mov edi,DWORD [12+esp] + xor esi,edi + ror edx,5 + and esi,ecx + mov DWORD [4+esp],ecx + xor edx,ecx + xor edi,esi + ror edx,6 + mov ecx,ebx + add edx,edi + mov edi,DWORD [24+esp] + mov esi,ebx + ror ecx,9 + mov DWORD [20+esp],ebx + xor ecx,ebx + xor ebx,edi + add edx,DWORD [16+esp] + ror ecx,11 + and eax,ebx + xor ecx,esi + add edx,DWORD [44+esp] + xor eax,edi + ror ecx,2 + add eax,edx + add edx,DWORD [esp] + add eax,ecx + mov ecx,edx + ror edx,14 + mov esi,DWORD [4+esp] + xor edx,ecx + mov edi,DWORD [8+esp] + xor esi,edi + ror edx,5 + and esi,ecx + mov DWORD [esp],ecx + xor edx,ecx + xor edi,esi + ror edx,6 + mov ecx,eax + add edx,edi + mov edi,DWORD [20+esp] + mov esi,eax + ror ecx,9 + mov DWORD [16+esp],eax + xor ecx,eax + xor eax,edi + add edx,DWORD [12+esp] + ror ecx,11 + and ebx,eax + xor ecx,esi + add edx,DWORD [48+esp] + xor ebx,edi + ror ecx,2 + add ebx,edx + add edx,DWORD [28+esp] + add ebx,ecx + mov ecx,edx + ror edx,14 + mov esi,DWORD [esp] + xor edx,ecx + mov edi,DWORD [4+esp] + xor esi,edi + ror edx,5 + and esi,ecx + mov DWORD [28+esp],ecx + xor edx,ecx + xor edi,esi + ror edx,6 + mov ecx,ebx + add edx,edi + mov edi,DWORD [16+esp] + mov esi,ebx + ror ecx,9 + mov DWORD [12+esp],ebx + xor ecx,ebx + xor ebx,edi + add edx,DWORD [8+esp] + ror ecx,11 + and eax,ebx + xor ecx,esi + add edx,DWORD [52+esp] + xor eax,edi + ror ecx,2 + add eax,edx + add edx,DWORD [24+esp] + add eax,ecx + mov ecx,edx + ror edx,14 + mov esi,DWORD [28+esp] + xor edx,ecx + mov edi,DWORD [esp] + xor esi,edi + ror edx,5 + and esi,ecx + mov DWORD [24+esp],ecx + xor edx,ecx + xor edi,esi + ror edx,6 + mov ecx,eax + add edx,edi + mov edi,DWORD [12+esp] + mov esi,eax + ror ecx,9 + mov DWORD [8+esp],eax + xor ecx,eax + xor eax,edi + add edx,DWORD [4+esp] + ror ecx,11 + and ebx,eax + xor ecx,esi + add edx,DWORD [56+esp] + xor ebx,edi + ror ecx,2 + add ebx,edx + add edx,DWORD [20+esp] + add ebx,ecx + mov ecx,edx + ror edx,14 + mov esi,DWORD [24+esp] + xor edx,ecx + mov edi,DWORD [28+esp] + xor esi,edi + ror edx,5 + and esi,ecx + mov DWORD [20+esp],ecx + xor edx,ecx + xor edi,esi + ror edx,6 + mov ecx,ebx + add edx,edi + mov edi,DWORD [8+esp] + mov esi,ebx + ror ecx,9 + mov DWORD [4+esp],ebx + xor ecx,ebx + xor ebx,edi + add edx,DWORD [esp] + ror ecx,11 + and eax,ebx + xor ecx,esi + add edx,DWORD [60+esp] + xor eax,edi + ror ecx,2 + add eax,edx + add edx,DWORD [16+esp] + add eax,ecx + mov ecx,edx + ror edx,14 + mov esi,DWORD [20+esp] + xor edx,ecx + mov edi,DWORD [24+esp] + xor esi,edi + ror edx,5 + and esi,ecx + mov DWORD [16+esp],ecx + xor edx,ecx + xor edi,esi + ror edx,6 + mov ecx,eax + add edx,edi + mov edi,DWORD [4+esp] + mov esi,eax + ror ecx,9 + mov DWORD [esp],eax + xor ecx,eax + xor eax,edi + add edx,DWORD [28+esp] + ror ecx,11 + and ebx,eax + xor ecx,esi + add edx,DWORD [64+esp] + xor ebx,edi + ror ecx,2 + add ebx,edx + add edx,DWORD [12+esp] + add ebx,ecx + mov ecx,edx + ror edx,14 + mov esi,DWORD [16+esp] + xor edx,ecx + mov edi,DWORD [20+esp] + xor esi,edi + ror edx,5 + and esi,ecx + mov DWORD [12+esp],ecx + xor edx,ecx + xor edi,esi + ror edx,6 + mov ecx,ebx + add edx,edi + mov edi,DWORD [esp] + mov esi,ebx + ror ecx,9 + mov DWORD [28+esp],ebx + xor ecx,ebx + xor ebx,edi + add edx,DWORD [24+esp] + ror ecx,11 + and eax,ebx + xor ecx,esi + add edx,DWORD [68+esp] + xor eax,edi + ror ecx,2 + add eax,edx + add edx,DWORD [8+esp] + add eax,ecx + mov ecx,edx + ror edx,14 + mov esi,DWORD [12+esp] + xor edx,ecx + mov edi,DWORD [16+esp] + xor esi,edi + ror edx,5 + and esi,ecx + mov DWORD [8+esp],ecx + xor edx,ecx + xor edi,esi + ror edx,6 + mov ecx,eax + add edx,edi + mov edi,DWORD [28+esp] + mov esi,eax + ror ecx,9 + mov DWORD [24+esp],eax + xor ecx,eax + xor eax,edi + add edx,DWORD [20+esp] + ror ecx,11 + and ebx,eax + xor ecx,esi + add edx,DWORD [72+esp] + xor ebx,edi + ror ecx,2 + add ebx,edx + add edx,DWORD [4+esp] + add ebx,ecx + mov ecx,edx + ror edx,14 + mov esi,DWORD [8+esp] + xor edx,ecx + mov edi,DWORD [12+esp] + xor esi,edi + ror edx,5 + and esi,ecx + mov DWORD [4+esp],ecx + xor edx,ecx + xor edi,esi + ror edx,6 + mov ecx,ebx + add edx,edi + mov edi,DWORD [24+esp] + mov esi,ebx + ror ecx,9 + mov DWORD [20+esp],ebx + xor ecx,ebx + xor ebx,edi + add edx,DWORD [16+esp] + ror ecx,11 + and eax,ebx + xor ecx,esi + add edx,DWORD [76+esp] + xor eax,edi + ror ecx,2 + add eax,edx + add edx,DWORD [esp] + add eax,ecx + mov ecx,edx + ror edx,14 + mov esi,DWORD [4+esp] + xor edx,ecx + mov edi,DWORD [8+esp] + xor esi,edi + ror edx,5 + and esi,ecx + mov DWORD [esp],ecx + xor edx,ecx + xor edi,esi + ror edx,6 + mov ecx,eax + add edx,edi + mov edi,DWORD [20+esp] + mov esi,eax + ror ecx,9 + mov DWORD [16+esp],eax + xor ecx,eax + xor eax,edi + add edx,DWORD [12+esp] + ror ecx,11 + and ebx,eax + xor ecx,esi + add edx,DWORD [80+esp] + xor ebx,edi + ror ecx,2 + add ebx,edx + add edx,DWORD [28+esp] + add ebx,ecx + mov ecx,edx + ror edx,14 + mov esi,DWORD [esp] + xor edx,ecx + mov edi,DWORD [4+esp] + xor esi,edi + ror edx,5 + and esi,ecx + mov DWORD [28+esp],ecx + xor edx,ecx + xor edi,esi + ror edx,6 + mov ecx,ebx + add edx,edi + mov edi,DWORD [16+esp] + mov esi,ebx + ror ecx,9 + mov DWORD [12+esp],ebx + xor ecx,ebx + xor ebx,edi + add edx,DWORD [8+esp] + ror ecx,11 + and eax,ebx + xor ecx,esi + add edx,DWORD [84+esp] + xor eax,edi + ror ecx,2 + add eax,edx + add edx,DWORD [24+esp] + add eax,ecx + mov ecx,edx + ror edx,14 + mov esi,DWORD [28+esp] + xor edx,ecx + mov edi,DWORD [esp] + xor esi,edi + ror edx,5 + and esi,ecx + mov DWORD [24+esp],ecx + xor edx,ecx + xor edi,esi + ror edx,6 + mov ecx,eax + add edx,edi + mov edi,DWORD [12+esp] + mov esi,eax + ror ecx,9 + mov DWORD [8+esp],eax + xor ecx,eax + xor eax,edi + add edx,DWORD [4+esp] + ror ecx,11 + and ebx,eax + xor ecx,esi + add edx,DWORD [88+esp] + xor ebx,edi + ror ecx,2 + add ebx,edx + add edx,DWORD [20+esp] + add ebx,ecx + mov ecx,edx + ror edx,14 + mov esi,DWORD [24+esp] + xor edx,ecx + mov edi,DWORD [28+esp] + xor esi,edi + ror edx,5 + and esi,ecx + mov DWORD [20+esp],ecx + xor edx,ecx + xor edi,esi + ror edx,6 + mov ecx,ebx + add edx,edi + mov edi,DWORD [8+esp] + mov esi,ebx + ror ecx,9 + mov DWORD [4+esp],ebx + xor ecx,ebx + xor ebx,edi + add edx,DWORD [esp] + ror ecx,11 + and eax,ebx + xor ecx,esi + add edx,DWORD [92+esp] + xor eax,edi + ror ecx,2 + add eax,edx + add edx,DWORD [16+esp] + add eax,ecx + mov esi,DWORD [96+esp] + xor ebx,edi + mov ecx,DWORD [12+esp] + add eax,DWORD [esi] + add ebx,DWORD [4+esi] + add edi,DWORD [8+esi] + add ecx,DWORD [12+esi] + mov DWORD [esi],eax + mov DWORD [4+esi],ebx + mov DWORD [8+esi],edi + mov DWORD [12+esi],ecx + mov DWORD [4+esp],ebx + xor ebx,edi + mov DWORD [8+esp],edi + mov DWORD [12+esp],ecx + mov edi,DWORD [20+esp] + mov ecx,DWORD [24+esp] + add edx,DWORD [16+esi] + add edi,DWORD [20+esi] + add ecx,DWORD [24+esi] + mov DWORD [16+esi],edx + mov DWORD [20+esi],edi + mov DWORD [20+esp],edi + mov edi,DWORD [28+esp] + mov DWORD [24+esi],ecx + add edi,DWORD [28+esi] + mov DWORD [24+esp],ecx + mov DWORD [28+esi],edi + mov DWORD [28+esp],edi + mov edi,DWORD [100+esp] + movdqa xmm7,[64+ebp] + sub ebp,192 + cmp edi,DWORD [104+esp] + jb NEAR L$008grand_ssse3 + mov esp,DWORD [108+esp] + pop edi + pop esi + pop ebx + pop ebp + ret +global _sha256_block_data_order_avx +align 16 +_sha256_block_data_order_avx: +L$_sha256_block_data_order_avx_begin: + push ebp + push ebx + push esi + push edi + mov esi,DWORD [20+esp] + mov edi,DWORD [24+esp] + mov eax,DWORD [28+esp] + mov ebx,esp + call L$010pic_point +L$010pic_point: + pop ebp + lea ebp,[(L$K256-L$010pic_point)+ebp] + sub esp,16 + and esp,-64 + shl eax,6 + add eax,edi + mov DWORD [esp],esi + mov DWORD [4+esp],edi + mov DWORD [8+esp],eax + mov DWORD [12+esp],ebx + lea esp,[esp-96] + vzeroall + mov eax,DWORD [esi] + mov ebx,DWORD [4+esi] + mov ecx,DWORD [8+esi] + mov edi,DWORD [12+esi] + mov DWORD [4+esp],ebx + xor ebx,ecx + mov DWORD [8+esp],ecx + mov DWORD [12+esp],edi + mov edx,DWORD [16+esi] + mov edi,DWORD [20+esi] + mov ecx,DWORD [24+esi] + mov esi,DWORD [28+esi] + mov DWORD [20+esp],edi + mov edi,DWORD [100+esp] + mov DWORD [24+esp],ecx + mov DWORD [28+esp],esi + vmovdqa xmm7,[256+ebp] + jmp NEAR L$011grand_avx +align 32 +L$011grand_avx: + vmovdqu xmm0,[edi] + vmovdqu xmm1,[16+edi] + vmovdqu xmm2,[32+edi] + vmovdqu xmm3,[48+edi] + add edi,64 + vpshufb xmm0,xmm0,xmm7 + mov DWORD [100+esp],edi + vpshufb xmm1,xmm1,xmm7 + vpshufb xmm2,xmm2,xmm7 + vpaddd xmm4,xmm0,[ebp] + vpshufb xmm3,xmm3,xmm7 + vpaddd xmm5,xmm1,[16+ebp] + vpaddd xmm6,xmm2,[32+ebp] + vpaddd xmm7,xmm3,[48+ebp] + vmovdqa [32+esp],xmm4 + vmovdqa [48+esp],xmm5 + vmovdqa [64+esp],xmm6 + vmovdqa [80+esp],xmm7 + jmp NEAR L$012avx_00_47 +align 16 +L$012avx_00_47: + add ebp,64 + vpalignr xmm4,xmm1,xmm0,4 + mov ecx,edx + shrd edx,edx,14 + mov esi,DWORD [20+esp] + vpalignr xmm7,xmm3,xmm2,4 + xor edx,ecx + mov edi,DWORD [24+esp] + xor esi,edi + vpsrld xmm6,xmm4,7 + shrd edx,edx,5 + and esi,ecx + mov DWORD [16+esp],ecx + vpaddd xmm0,xmm0,xmm7 + xor edx,ecx + xor edi,esi + shrd edx,edx,6 + vpsrld xmm7,xmm4,3 + mov ecx,eax + add edx,edi + mov edi,DWORD [4+esp] + vpslld xmm5,xmm4,14 + mov esi,eax + shrd ecx,ecx,9 + mov DWORD [esp],eax + vpxor xmm4,xmm7,xmm6 + xor ecx,eax + xor eax,edi + add edx,DWORD [28+esp] + vpshufd xmm7,xmm3,250 + shrd ecx,ecx,11 + and ebx,eax + xor ecx,esi + vpsrld xmm6,xmm6,11 + add edx,DWORD [32+esp] + xor ebx,edi + shrd ecx,ecx,2 + vpxor xmm4,xmm4,xmm5 + add ebx,edx + add edx,DWORD [12+esp] + add ebx,ecx + vpslld xmm5,xmm5,11 + mov ecx,edx + shrd edx,edx,14 + mov esi,DWORD [16+esp] + vpxor xmm4,xmm4,xmm6 + xor edx,ecx + mov edi,DWORD [20+esp] + xor esi,edi + vpsrld xmm6,xmm7,10 + shrd edx,edx,5 + and esi,ecx + mov DWORD [12+esp],ecx + vpxor xmm4,xmm4,xmm5 + xor edx,ecx + xor edi,esi + shrd edx,edx,6 + vpsrlq xmm5,xmm7,17 + mov ecx,ebx + add edx,edi + mov edi,DWORD [esp] + vpaddd xmm0,xmm0,xmm4 + mov esi,ebx + shrd ecx,ecx,9 + mov DWORD [28+esp],ebx + vpxor xmm6,xmm6,xmm5 + xor ecx,ebx + xor ebx,edi + add edx,DWORD [24+esp] + vpsrlq xmm7,xmm7,19 + shrd ecx,ecx,11 + and eax,ebx + xor ecx,esi + vpxor xmm6,xmm6,xmm7 + add edx,DWORD [36+esp] + xor eax,edi + shrd ecx,ecx,2 + vpshufd xmm7,xmm6,132 + add eax,edx + add edx,DWORD [8+esp] + add eax,ecx + vpsrldq xmm7,xmm7,8 + mov ecx,edx + shrd edx,edx,14 + mov esi,DWORD [12+esp] + vpaddd xmm0,xmm0,xmm7 + xor edx,ecx + mov edi,DWORD [16+esp] + xor esi,edi + vpshufd xmm7,xmm0,80 + shrd edx,edx,5 + and esi,ecx + mov DWORD [8+esp],ecx + vpsrld xmm6,xmm7,10 + xor edx,ecx + xor edi,esi + shrd edx,edx,6 + vpsrlq xmm5,xmm7,17 + mov ecx,eax + add edx,edi + mov edi,DWORD [28+esp] + vpxor xmm6,xmm6,xmm5 + mov esi,eax + shrd ecx,ecx,9 + mov DWORD [24+esp],eax + vpsrlq xmm7,xmm7,19 + xor ecx,eax + xor eax,edi + add edx,DWORD [20+esp] + vpxor xmm6,xmm6,xmm7 + shrd ecx,ecx,11 + and ebx,eax + xor ecx,esi + vpshufd xmm7,xmm6,232 + add edx,DWORD [40+esp] + xor ebx,edi + shrd ecx,ecx,2 + vpslldq xmm7,xmm7,8 + add ebx,edx + add edx,DWORD [4+esp] + add ebx,ecx + vpaddd xmm0,xmm0,xmm7 + mov ecx,edx + shrd edx,edx,14 + mov esi,DWORD [8+esp] + vpaddd xmm6,xmm0,[ebp] + xor edx,ecx + mov edi,DWORD [12+esp] + xor esi,edi + shrd edx,edx,5 + and esi,ecx + mov DWORD [4+esp],ecx + xor edx,ecx + xor edi,esi + shrd edx,edx,6 + mov ecx,ebx + add edx,edi + mov edi,DWORD [24+esp] + mov esi,ebx + shrd ecx,ecx,9 + mov DWORD [20+esp],ebx + xor ecx,ebx + xor ebx,edi + add edx,DWORD [16+esp] + shrd ecx,ecx,11 + and eax,ebx + xor ecx,esi + add edx,DWORD [44+esp] + xor eax,edi + shrd ecx,ecx,2 + add eax,edx + add edx,DWORD [esp] + add eax,ecx + vmovdqa [32+esp],xmm6 + vpalignr xmm4,xmm2,xmm1,4 + mov ecx,edx + shrd edx,edx,14 + mov esi,DWORD [4+esp] + vpalignr xmm7,xmm0,xmm3,4 + xor edx,ecx + mov edi,DWORD [8+esp] + xor esi,edi + vpsrld xmm6,xmm4,7 + shrd edx,edx,5 + and esi,ecx + mov DWORD [esp],ecx + vpaddd xmm1,xmm1,xmm7 + xor edx,ecx + xor edi,esi + shrd edx,edx,6 + vpsrld xmm7,xmm4,3 + mov ecx,eax + add edx,edi + mov edi,DWORD [20+esp] + vpslld xmm5,xmm4,14 + mov esi,eax + shrd ecx,ecx,9 + mov DWORD [16+esp],eax + vpxor xmm4,xmm7,xmm6 + xor ecx,eax + xor eax,edi + add edx,DWORD [12+esp] + vpshufd xmm7,xmm0,250 + shrd ecx,ecx,11 + and ebx,eax + xor ecx,esi + vpsrld xmm6,xmm6,11 + add edx,DWORD [48+esp] + xor ebx,edi + shrd ecx,ecx,2 + vpxor xmm4,xmm4,xmm5 + add ebx,edx + add edx,DWORD [28+esp] + add ebx,ecx + vpslld xmm5,xmm5,11 + mov ecx,edx + shrd edx,edx,14 + mov esi,DWORD [esp] + vpxor xmm4,xmm4,xmm6 + xor edx,ecx + mov edi,DWORD [4+esp] + xor esi,edi + vpsrld xmm6,xmm7,10 + shrd edx,edx,5 + and esi,ecx + mov DWORD [28+esp],ecx + vpxor xmm4,xmm4,xmm5 + xor edx,ecx + xor edi,esi + shrd edx,edx,6 + vpsrlq xmm5,xmm7,17 + mov ecx,ebx + add edx,edi + mov edi,DWORD [16+esp] + vpaddd xmm1,xmm1,xmm4 + mov esi,ebx + shrd ecx,ecx,9 + mov DWORD [12+esp],ebx + vpxor xmm6,xmm6,xmm5 + xor ecx,ebx + xor ebx,edi + add edx,DWORD [8+esp] + vpsrlq xmm7,xmm7,19 + shrd ecx,ecx,11 + and eax,ebx + xor ecx,esi + vpxor xmm6,xmm6,xmm7 + add edx,DWORD [52+esp] + xor eax,edi + shrd ecx,ecx,2 + vpshufd xmm7,xmm6,132 + add eax,edx + add edx,DWORD [24+esp] + add eax,ecx + vpsrldq xmm7,xmm7,8 + mov ecx,edx + shrd edx,edx,14 + mov esi,DWORD [28+esp] + vpaddd xmm1,xmm1,xmm7 + xor edx,ecx + mov edi,DWORD [esp] + xor esi,edi + vpshufd xmm7,xmm1,80 + shrd edx,edx,5 + and esi,ecx + mov DWORD [24+esp],ecx + vpsrld xmm6,xmm7,10 + xor edx,ecx + xor edi,esi + shrd edx,edx,6 + vpsrlq xmm5,xmm7,17 + mov ecx,eax + add edx,edi + mov edi,DWORD [12+esp] + vpxor xmm6,xmm6,xmm5 + mov esi,eax + shrd ecx,ecx,9 + mov DWORD [8+esp],eax + vpsrlq xmm7,xmm7,19 + xor ecx,eax + xor eax,edi + add edx,DWORD [4+esp] + vpxor xmm6,xmm6,xmm7 + shrd ecx,ecx,11 + and ebx,eax + xor ecx,esi + vpshufd xmm7,xmm6,232 + add edx,DWORD [56+esp] + xor ebx,edi + shrd ecx,ecx,2 + vpslldq xmm7,xmm7,8 + add ebx,edx + add edx,DWORD [20+esp] + add ebx,ecx + vpaddd xmm1,xmm1,xmm7 + mov ecx,edx + shrd edx,edx,14 + mov esi,DWORD [24+esp] + vpaddd xmm6,xmm1,[16+ebp] + xor edx,ecx + mov edi,DWORD [28+esp] + xor esi,edi + shrd edx,edx,5 + and esi,ecx + mov DWORD [20+esp],ecx + xor edx,ecx + xor edi,esi + shrd edx,edx,6 + mov ecx,ebx + add edx,edi + mov edi,DWORD [8+esp] + mov esi,ebx + shrd ecx,ecx,9 + mov DWORD [4+esp],ebx + xor ecx,ebx + xor ebx,edi + add edx,DWORD [esp] + shrd ecx,ecx,11 + and eax,ebx + xor ecx,esi + add edx,DWORD [60+esp] + xor eax,edi + shrd ecx,ecx,2 + add eax,edx + add edx,DWORD [16+esp] + add eax,ecx + vmovdqa [48+esp],xmm6 + vpalignr xmm4,xmm3,xmm2,4 + mov ecx,edx + shrd edx,edx,14 + mov esi,DWORD [20+esp] + vpalignr xmm7,xmm1,xmm0,4 + xor edx,ecx + mov edi,DWORD [24+esp] + xor esi,edi + vpsrld xmm6,xmm4,7 + shrd edx,edx,5 + and esi,ecx + mov DWORD [16+esp],ecx + vpaddd xmm2,xmm2,xmm7 + xor edx,ecx + xor edi,esi + shrd edx,edx,6 + vpsrld xmm7,xmm4,3 + mov ecx,eax + add edx,edi + mov edi,DWORD [4+esp] + vpslld xmm5,xmm4,14 + mov esi,eax + shrd ecx,ecx,9 + mov DWORD [esp],eax + vpxor xmm4,xmm7,xmm6 + xor ecx,eax + xor eax,edi + add edx,DWORD [28+esp] + vpshufd xmm7,xmm1,250 + shrd ecx,ecx,11 + and ebx,eax + xor ecx,esi + vpsrld xmm6,xmm6,11 + add edx,DWORD [64+esp] + xor ebx,edi + shrd ecx,ecx,2 + vpxor xmm4,xmm4,xmm5 + add ebx,edx + add edx,DWORD [12+esp] + add ebx,ecx + vpslld xmm5,xmm5,11 + mov ecx,edx + shrd edx,edx,14 + mov esi,DWORD [16+esp] + vpxor xmm4,xmm4,xmm6 + xor edx,ecx + mov edi,DWORD [20+esp] + xor esi,edi + vpsrld xmm6,xmm7,10 + shrd edx,edx,5 + and esi,ecx + mov DWORD [12+esp],ecx + vpxor xmm4,xmm4,xmm5 + xor edx,ecx + xor edi,esi + shrd edx,edx,6 + vpsrlq xmm5,xmm7,17 + mov ecx,ebx + add edx,edi + mov edi,DWORD [esp] + vpaddd xmm2,xmm2,xmm4 + mov esi,ebx + shrd ecx,ecx,9 + mov DWORD [28+esp],ebx + vpxor xmm6,xmm6,xmm5 + xor ecx,ebx + xor ebx,edi + add edx,DWORD [24+esp] + vpsrlq xmm7,xmm7,19 + shrd ecx,ecx,11 + and eax,ebx + xor ecx,esi + vpxor xmm6,xmm6,xmm7 + add edx,DWORD [68+esp] + xor eax,edi + shrd ecx,ecx,2 + vpshufd xmm7,xmm6,132 + add eax,edx + add edx,DWORD [8+esp] + add eax,ecx + vpsrldq xmm7,xmm7,8 + mov ecx,edx + shrd edx,edx,14 + mov esi,DWORD [12+esp] + vpaddd xmm2,xmm2,xmm7 + xor edx,ecx + mov edi,DWORD [16+esp] + xor esi,edi + vpshufd xmm7,xmm2,80 + shrd edx,edx,5 + and esi,ecx + mov DWORD [8+esp],ecx + vpsrld xmm6,xmm7,10 + xor edx,ecx + xor edi,esi + shrd edx,edx,6 + vpsrlq xmm5,xmm7,17 + mov ecx,eax + add edx,edi + mov edi,DWORD [28+esp] + vpxor xmm6,xmm6,xmm5 + mov esi,eax + shrd ecx,ecx,9 + mov DWORD [24+esp],eax + vpsrlq xmm7,xmm7,19 + xor ecx,eax + xor eax,edi + add edx,DWORD [20+esp] + vpxor xmm6,xmm6,xmm7 + shrd ecx,ecx,11 + and ebx,eax + xor ecx,esi + vpshufd xmm7,xmm6,232 + add edx,DWORD [72+esp] + xor ebx,edi + shrd ecx,ecx,2 + vpslldq xmm7,xmm7,8 + add ebx,edx + add edx,DWORD [4+esp] + add ebx,ecx + vpaddd xmm2,xmm2,xmm7 + mov ecx,edx + shrd edx,edx,14 + mov esi,DWORD [8+esp] + vpaddd xmm6,xmm2,[32+ebp] + xor edx,ecx + mov edi,DWORD [12+esp] + xor esi,edi + shrd edx,edx,5 + and esi,ecx + mov DWORD [4+esp],ecx + xor edx,ecx + xor edi,esi + shrd edx,edx,6 + mov ecx,ebx + add edx,edi + mov edi,DWORD [24+esp] + mov esi,ebx + shrd ecx,ecx,9 + mov DWORD [20+esp],ebx + xor ecx,ebx + xor ebx,edi + add edx,DWORD [16+esp] + shrd ecx,ecx,11 + and eax,ebx + xor ecx,esi + add edx,DWORD [76+esp] + xor eax,edi + shrd ecx,ecx,2 + add eax,edx + add edx,DWORD [esp] + add eax,ecx + vmovdqa [64+esp],xmm6 + vpalignr xmm4,xmm0,xmm3,4 + mov ecx,edx + shrd edx,edx,14 + mov esi,DWORD [4+esp] + vpalignr xmm7,xmm2,xmm1,4 + xor edx,ecx + mov edi,DWORD [8+esp] + xor esi,edi + vpsrld xmm6,xmm4,7 + shrd edx,edx,5 + and esi,ecx + mov DWORD [esp],ecx + vpaddd xmm3,xmm3,xmm7 + xor edx,ecx + xor edi,esi + shrd edx,edx,6 + vpsrld xmm7,xmm4,3 + mov ecx,eax + add edx,edi + mov edi,DWORD [20+esp] + vpslld xmm5,xmm4,14 + mov esi,eax + shrd ecx,ecx,9 + mov DWORD [16+esp],eax + vpxor xmm4,xmm7,xmm6 + xor ecx,eax + xor eax,edi + add edx,DWORD [12+esp] + vpshufd xmm7,xmm2,250 + shrd ecx,ecx,11 + and ebx,eax + xor ecx,esi + vpsrld xmm6,xmm6,11 + add edx,DWORD [80+esp] + xor ebx,edi + shrd ecx,ecx,2 + vpxor xmm4,xmm4,xmm5 + add ebx,edx + add edx,DWORD [28+esp] + add ebx,ecx + vpslld xmm5,xmm5,11 + mov ecx,edx + shrd edx,edx,14 + mov esi,DWORD [esp] + vpxor xmm4,xmm4,xmm6 + xor edx,ecx + mov edi,DWORD [4+esp] + xor esi,edi + vpsrld xmm6,xmm7,10 + shrd edx,edx,5 + and esi,ecx + mov DWORD [28+esp],ecx + vpxor xmm4,xmm4,xmm5 + xor edx,ecx + xor edi,esi + shrd edx,edx,6 + vpsrlq xmm5,xmm7,17 + mov ecx,ebx + add edx,edi + mov edi,DWORD [16+esp] + vpaddd xmm3,xmm3,xmm4 + mov esi,ebx + shrd ecx,ecx,9 + mov DWORD [12+esp],ebx + vpxor xmm6,xmm6,xmm5 + xor ecx,ebx + xor ebx,edi + add edx,DWORD [8+esp] + vpsrlq xmm7,xmm7,19 + shrd ecx,ecx,11 + and eax,ebx + xor ecx,esi + vpxor xmm6,xmm6,xmm7 + add edx,DWORD [84+esp] + xor eax,edi + shrd ecx,ecx,2 + vpshufd xmm7,xmm6,132 + add eax,edx + add edx,DWORD [24+esp] + add eax,ecx + vpsrldq xmm7,xmm7,8 + mov ecx,edx + shrd edx,edx,14 + mov esi,DWORD [28+esp] + vpaddd xmm3,xmm3,xmm7 + xor edx,ecx + mov edi,DWORD [esp] + xor esi,edi + vpshufd xmm7,xmm3,80 + shrd edx,edx,5 + and esi,ecx + mov DWORD [24+esp],ecx + vpsrld xmm6,xmm7,10 + xor edx,ecx + xor edi,esi + shrd edx,edx,6 + vpsrlq xmm5,xmm7,17 + mov ecx,eax + add edx,edi + mov edi,DWORD [12+esp] + vpxor xmm6,xmm6,xmm5 + mov esi,eax + shrd ecx,ecx,9 + mov DWORD [8+esp],eax + vpsrlq xmm7,xmm7,19 + xor ecx,eax + xor eax,edi + add edx,DWORD [4+esp] + vpxor xmm6,xmm6,xmm7 + shrd ecx,ecx,11 + and ebx,eax + xor ecx,esi + vpshufd xmm7,xmm6,232 + add edx,DWORD [88+esp] + xor ebx,edi + shrd ecx,ecx,2 + vpslldq xmm7,xmm7,8 + add ebx,edx + add edx,DWORD [20+esp] + add ebx,ecx + vpaddd xmm3,xmm3,xmm7 + mov ecx,edx + shrd edx,edx,14 + mov esi,DWORD [24+esp] + vpaddd xmm6,xmm3,[48+ebp] + xor edx,ecx + mov edi,DWORD [28+esp] + xor esi,edi + shrd edx,edx,5 + and esi,ecx + mov DWORD [20+esp],ecx + xor edx,ecx + xor edi,esi + shrd edx,edx,6 + mov ecx,ebx + add edx,edi + mov edi,DWORD [8+esp] + mov esi,ebx + shrd ecx,ecx,9 + mov DWORD [4+esp],ebx + xor ecx,ebx + xor ebx,edi + add edx,DWORD [esp] + shrd ecx,ecx,11 + and eax,ebx + xor ecx,esi + add edx,DWORD [92+esp] + xor eax,edi + shrd ecx,ecx,2 + add eax,edx + add edx,DWORD [16+esp] + add eax,ecx + vmovdqa [80+esp],xmm6 + cmp DWORD [64+ebp],66051 + jne NEAR L$012avx_00_47 + mov ecx,edx + shrd edx,edx,14 + mov esi,DWORD [20+esp] + xor edx,ecx + mov edi,DWORD [24+esp] + xor esi,edi + shrd edx,edx,5 + and esi,ecx + mov DWORD [16+esp],ecx + xor edx,ecx + xor edi,esi + shrd edx,edx,6 + mov ecx,eax + add edx,edi + mov edi,DWORD [4+esp] + mov esi,eax + shrd ecx,ecx,9 + mov DWORD [esp],eax + xor ecx,eax + xor eax,edi + add edx,DWORD [28+esp] + shrd ecx,ecx,11 + and ebx,eax + xor ecx,esi + add edx,DWORD [32+esp] + xor ebx,edi + shrd ecx,ecx,2 + add ebx,edx + add edx,DWORD [12+esp] + add ebx,ecx + mov ecx,edx + shrd edx,edx,14 + mov esi,DWORD [16+esp] + xor edx,ecx + mov edi,DWORD [20+esp] + xor esi,edi + shrd edx,edx,5 + and esi,ecx + mov DWORD [12+esp],ecx + xor edx,ecx + xor edi,esi + shrd edx,edx,6 + mov ecx,ebx + add edx,edi + mov edi,DWORD [esp] + mov esi,ebx + shrd ecx,ecx,9 + mov DWORD [28+esp],ebx + xor ecx,ebx + xor ebx,edi + add edx,DWORD [24+esp] + shrd ecx,ecx,11 + and eax,ebx + xor ecx,esi + add edx,DWORD [36+esp] + xor eax,edi + shrd ecx,ecx,2 + add eax,edx + add edx,DWORD [8+esp] + add eax,ecx + mov ecx,edx + shrd edx,edx,14 + mov esi,DWORD [12+esp] + xor edx,ecx + mov edi,DWORD [16+esp] + xor esi,edi + shrd edx,edx,5 + and esi,ecx + mov DWORD [8+esp],ecx + xor edx,ecx + xor edi,esi + shrd edx,edx,6 + mov ecx,eax + add edx,edi + mov edi,DWORD [28+esp] + mov esi,eax + shrd ecx,ecx,9 + mov DWORD [24+esp],eax + xor ecx,eax + xor eax,edi + add edx,DWORD [20+esp] + shrd ecx,ecx,11 + and ebx,eax + xor ecx,esi + add edx,DWORD [40+esp] + xor ebx,edi + shrd ecx,ecx,2 + add ebx,edx + add edx,DWORD [4+esp] + add ebx,ecx + mov ecx,edx + shrd edx,edx,14 + mov esi,DWORD [8+esp] + xor edx,ecx + mov edi,DWORD [12+esp] + xor esi,edi + shrd edx,edx,5 + and esi,ecx + mov DWORD [4+esp],ecx + xor edx,ecx + xor edi,esi + shrd edx,edx,6 + mov ecx,ebx + add edx,edi + mov edi,DWORD [24+esp] + mov esi,ebx + shrd ecx,ecx,9 + mov DWORD [20+esp],ebx + xor ecx,ebx + xor ebx,edi + add edx,DWORD [16+esp] + shrd ecx,ecx,11 + and eax,ebx + xor ecx,esi + add edx,DWORD [44+esp] + xor eax,edi + shrd ecx,ecx,2 + add eax,edx + add edx,DWORD [esp] + add eax,ecx + mov ecx,edx + shrd edx,edx,14 + mov esi,DWORD [4+esp] + xor edx,ecx + mov edi,DWORD [8+esp] + xor esi,edi + shrd edx,edx,5 + and esi,ecx + mov DWORD [esp],ecx + xor edx,ecx + xor edi,esi + shrd edx,edx,6 + mov ecx,eax + add edx,edi + mov edi,DWORD [20+esp] + mov esi,eax + shrd ecx,ecx,9 + mov DWORD [16+esp],eax + xor ecx,eax + xor eax,edi + add edx,DWORD [12+esp] + shrd ecx,ecx,11 + and ebx,eax + xor ecx,esi + add edx,DWORD [48+esp] + xor ebx,edi + shrd ecx,ecx,2 + add ebx,edx + add edx,DWORD [28+esp] + add ebx,ecx + mov ecx,edx + shrd edx,edx,14 + mov esi,DWORD [esp] + xor edx,ecx + mov edi,DWORD [4+esp] + xor esi,edi + shrd edx,edx,5 + and esi,ecx + mov DWORD [28+esp],ecx + xor edx,ecx + xor edi,esi + shrd edx,edx,6 + mov ecx,ebx + add edx,edi + mov edi,DWORD [16+esp] + mov esi,ebx + shrd ecx,ecx,9 + mov DWORD [12+esp],ebx + xor ecx,ebx + xor ebx,edi + add edx,DWORD [8+esp] + shrd ecx,ecx,11 + and eax,ebx + xor ecx,esi + add edx,DWORD [52+esp] + xor eax,edi + shrd ecx,ecx,2 + add eax,edx + add edx,DWORD [24+esp] + add eax,ecx + mov ecx,edx + shrd edx,edx,14 + mov esi,DWORD [28+esp] + xor edx,ecx + mov edi,DWORD [esp] + xor esi,edi + shrd edx,edx,5 + and esi,ecx + mov DWORD [24+esp],ecx + xor edx,ecx + xor edi,esi + shrd edx,edx,6 + mov ecx,eax + add edx,edi + mov edi,DWORD [12+esp] + mov esi,eax + shrd ecx,ecx,9 + mov DWORD [8+esp],eax + xor ecx,eax + xor eax,edi + add edx,DWORD [4+esp] + shrd ecx,ecx,11 + and ebx,eax + xor ecx,esi + add edx,DWORD [56+esp] + xor ebx,edi + shrd ecx,ecx,2 + add ebx,edx + add edx,DWORD [20+esp] + add ebx,ecx + mov ecx,edx + shrd edx,edx,14 + mov esi,DWORD [24+esp] + xor edx,ecx + mov edi,DWORD [28+esp] + xor esi,edi + shrd edx,edx,5 + and esi,ecx + mov DWORD [20+esp],ecx + xor edx,ecx + xor edi,esi + shrd edx,edx,6 + mov ecx,ebx + add edx,edi + mov edi,DWORD [8+esp] + mov esi,ebx + shrd ecx,ecx,9 + mov DWORD [4+esp],ebx + xor ecx,ebx + xor ebx,edi + add edx,DWORD [esp] + shrd ecx,ecx,11 + and eax,ebx + xor ecx,esi + add edx,DWORD [60+esp] + xor eax,edi + shrd ecx,ecx,2 + add eax,edx + add edx,DWORD [16+esp] + add eax,ecx + mov ecx,edx + shrd edx,edx,14 + mov esi,DWORD [20+esp] + xor edx,ecx + mov edi,DWORD [24+esp] + xor esi,edi + shrd edx,edx,5 + and esi,ecx + mov DWORD [16+esp],ecx + xor edx,ecx + xor edi,esi + shrd edx,edx,6 + mov ecx,eax + add edx,edi + mov edi,DWORD [4+esp] + mov esi,eax + shrd ecx,ecx,9 + mov DWORD [esp],eax + xor ecx,eax + xor eax,edi + add edx,DWORD [28+esp] + shrd ecx,ecx,11 + and ebx,eax + xor ecx,esi + add edx,DWORD [64+esp] + xor ebx,edi + shrd ecx,ecx,2 + add ebx,edx + add edx,DWORD [12+esp] + add ebx,ecx + mov ecx,edx + shrd edx,edx,14 + mov esi,DWORD [16+esp] + xor edx,ecx + mov edi,DWORD [20+esp] + xor esi,edi + shrd edx,edx,5 + and esi,ecx + mov DWORD [12+esp],ecx + xor edx,ecx + xor edi,esi + shrd edx,edx,6 + mov ecx,ebx + add edx,edi + mov edi,DWORD [esp] + mov esi,ebx + shrd ecx,ecx,9 + mov DWORD [28+esp],ebx + xor ecx,ebx + xor ebx,edi + add edx,DWORD [24+esp] + shrd ecx,ecx,11 + and eax,ebx + xor ecx,esi + add edx,DWORD [68+esp] + xor eax,edi + shrd ecx,ecx,2 + add eax,edx + add edx,DWORD [8+esp] + add eax,ecx + mov ecx,edx + shrd edx,edx,14 + mov esi,DWORD [12+esp] + xor edx,ecx + mov edi,DWORD [16+esp] + xor esi,edi + shrd edx,edx,5 + and esi,ecx + mov DWORD [8+esp],ecx + xor edx,ecx + xor edi,esi + shrd edx,edx,6 + mov ecx,eax + add edx,edi + mov edi,DWORD [28+esp] + mov esi,eax + shrd ecx,ecx,9 + mov DWORD [24+esp],eax + xor ecx,eax + xor eax,edi + add edx,DWORD [20+esp] + shrd ecx,ecx,11 + and ebx,eax + xor ecx,esi + add edx,DWORD [72+esp] + xor ebx,edi + shrd ecx,ecx,2 + add ebx,edx + add edx,DWORD [4+esp] + add ebx,ecx + mov ecx,edx + shrd edx,edx,14 + mov esi,DWORD [8+esp] + xor edx,ecx + mov edi,DWORD [12+esp] + xor esi,edi + shrd edx,edx,5 + and esi,ecx + mov DWORD [4+esp],ecx + xor edx,ecx + xor edi,esi + shrd edx,edx,6 + mov ecx,ebx + add edx,edi + mov edi,DWORD [24+esp] + mov esi,ebx + shrd ecx,ecx,9 + mov DWORD [20+esp],ebx + xor ecx,ebx + xor ebx,edi + add edx,DWORD [16+esp] + shrd ecx,ecx,11 + and eax,ebx + xor ecx,esi + add edx,DWORD [76+esp] + xor eax,edi + shrd ecx,ecx,2 + add eax,edx + add edx,DWORD [esp] + add eax,ecx + mov ecx,edx + shrd edx,edx,14 + mov esi,DWORD [4+esp] + xor edx,ecx + mov edi,DWORD [8+esp] + xor esi,edi + shrd edx,edx,5 + and esi,ecx + mov DWORD [esp],ecx + xor edx,ecx + xor edi,esi + shrd edx,edx,6 + mov ecx,eax + add edx,edi + mov edi,DWORD [20+esp] + mov esi,eax + shrd ecx,ecx,9 + mov DWORD [16+esp],eax + xor ecx,eax + xor eax,edi + add edx,DWORD [12+esp] + shrd ecx,ecx,11 + and ebx,eax + xor ecx,esi + add edx,DWORD [80+esp] + xor ebx,edi + shrd ecx,ecx,2 + add ebx,edx + add edx,DWORD [28+esp] + add ebx,ecx + mov ecx,edx + shrd edx,edx,14 + mov esi,DWORD [esp] + xor edx,ecx + mov edi,DWORD [4+esp] + xor esi,edi + shrd edx,edx,5 + and esi,ecx + mov DWORD [28+esp],ecx + xor edx,ecx + xor edi,esi + shrd edx,edx,6 + mov ecx,ebx + add edx,edi + mov edi,DWORD [16+esp] + mov esi,ebx + shrd ecx,ecx,9 + mov DWORD [12+esp],ebx + xor ecx,ebx + xor ebx,edi + add edx,DWORD [8+esp] + shrd ecx,ecx,11 + and eax,ebx + xor ecx,esi + add edx,DWORD [84+esp] + xor eax,edi + shrd ecx,ecx,2 + add eax,edx + add edx,DWORD [24+esp] + add eax,ecx + mov ecx,edx + shrd edx,edx,14 + mov esi,DWORD [28+esp] + xor edx,ecx + mov edi,DWORD [esp] + xor esi,edi + shrd edx,edx,5 + and esi,ecx + mov DWORD [24+esp],ecx + xor edx,ecx + xor edi,esi + shrd edx,edx,6 + mov ecx,eax + add edx,edi + mov edi,DWORD [12+esp] + mov esi,eax + shrd ecx,ecx,9 + mov DWORD [8+esp],eax + xor ecx,eax + xor eax,edi + add edx,DWORD [4+esp] + shrd ecx,ecx,11 + and ebx,eax + xor ecx,esi + add edx,DWORD [88+esp] + xor ebx,edi + shrd ecx,ecx,2 + add ebx,edx + add edx,DWORD [20+esp] + add ebx,ecx + mov ecx,edx + shrd edx,edx,14 + mov esi,DWORD [24+esp] + xor edx,ecx + mov edi,DWORD [28+esp] + xor esi,edi + shrd edx,edx,5 + and esi,ecx + mov DWORD [20+esp],ecx + xor edx,ecx + xor edi,esi + shrd edx,edx,6 + mov ecx,ebx + add edx,edi + mov edi,DWORD [8+esp] + mov esi,ebx + shrd ecx,ecx,9 + mov DWORD [4+esp],ebx + xor ecx,ebx + xor ebx,edi + add edx,DWORD [esp] + shrd ecx,ecx,11 + and eax,ebx + xor ecx,esi + add edx,DWORD [92+esp] + xor eax,edi + shrd ecx,ecx,2 + add eax,edx + add edx,DWORD [16+esp] + add eax,ecx + mov esi,DWORD [96+esp] + xor ebx,edi + mov ecx,DWORD [12+esp] + add eax,DWORD [esi] + add ebx,DWORD [4+esi] + add edi,DWORD [8+esi] + add ecx,DWORD [12+esi] + mov DWORD [esi],eax + mov DWORD [4+esi],ebx + mov DWORD [8+esi],edi + mov DWORD [12+esi],ecx + mov DWORD [4+esp],ebx + xor ebx,edi + mov DWORD [8+esp],edi + mov DWORD [12+esp],ecx + mov edi,DWORD [20+esp] + mov ecx,DWORD [24+esp] + add edx,DWORD [16+esi] + add edi,DWORD [20+esi] + add ecx,DWORD [24+esi] + mov DWORD [16+esi],edx + mov DWORD [20+esi],edi + mov DWORD [20+esp],edi + mov edi,DWORD [28+esp] + mov DWORD [24+esi],ecx + add edi,DWORD [28+esi] + mov DWORD [24+esp],ecx + mov DWORD [28+esi],edi + mov DWORD [28+esp],edi + mov edi,DWORD [100+esp] + vmovdqa xmm7,[64+ebp] + sub ebp,192 + cmp edi,DWORD [104+esp] + jb NEAR L$011grand_avx + mov esp,DWORD [108+esp] + vzeroall + pop edi + pop esi + pop ebx + pop ebp + ret %else ; Work around https://bugzilla.nasm.us/show_bug.cgi?id=3392738 ret diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha256-armv4-ios.ios.arm.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha256-armv4-ios.ios.arm.S index 03bbf390..b82984e3 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha256-armv4-ios.ios.arm.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha256-armv4-ios.ios.arm.S @@ -1870,6 +1870,14 @@ Lrounds_16_xx: +LK256_shortcut_neon: +@ PC is 8 bytes ahead in Arm mode and 4 bytes ahead in Thumb mode. +#if defined(__thumb2__) +.word K256-(LK256_add_neon+4) +#else +.word K256-(LK256_add_neon+8) +#endif + .globl _sha256_block_data_order_neon .private_extern _sha256_block_data_order_neon #ifdef __thumb2__ @@ -1881,10 +1889,21 @@ _sha256_block_data_order_neon: stmdb sp!,{r4,r5,r6,r7,r8,r9,r10,r11,r12,lr} sub r11,sp,#16*4+16 - @ In Arm mode, the following ADR runs up against the limits of encodable - @ offsets. It only fits because the offset, when the ADR is placed here, - @ is a multiple of 16. - adr r14,K256 + + @ K256 is just at the boundary of being easily referenced by an ADR from + @ this function. In Arm mode, when building with __ARM_ARCH=6, it does + @ not fit. By moving code around, we could make it fit, but this is too + @ fragile. For simplicity, just load the offset from + @ .LK256_shortcut_neon. + @ + @ TODO(davidben): adrl would avoid a load, but clang-assembler does not + @ support it. We might be able to emulate it with a macro, but Android's + @ did not work when I tried it. + @ https://android.googlesource.com/platform/ndk/+/refs/heads/master/docs/ClangMigration.md#arm + ldr r14,LK256_shortcut_neon +LK256_add_neon: + add r14,pc,r14 + bic r11,r11,#15 @ align for 128-bit stores mov r12,sp mov sp,r11 @ alloca @@ -2666,12 +2685,12 @@ L_00_48: # define INST(a,b,c,d) .byte a,b,c,d # endif -LK256_shortcut: +LK256_shortcut_hw: @ PC is 8 bytes ahead in Arm mode and 4 bytes ahead in Thumb mode. #if defined(__thumb2__) -.word K256-(LK256_add+4) +.word K256-(LK256_add_hw+4) #else -.word K256-(LK256_add+8) +.word K256-(LK256_add_hw+8) #endif .globl _sha256_block_data_order_hw @@ -2683,9 +2702,9 @@ LK256_shortcut: _sha256_block_data_order_hw: @ K256 is too far to reference from one ADR command in Thumb mode. In @ Arm mode, we could make it fit by aligning the ADR offset to a 64-byte - @ boundary. For simplicity, just load the offset from .LK256_shortcut. - ldr r3,LK256_shortcut -LK256_add: + @ boundary. For simplicity, just load the offset from .LK256_shortcut_hw. + ldr r3,LK256_shortcut_hw +LK256_add_hw: add r3,pc,r3 vld1.32 {q0,q1},[r0] diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha256-armv4-linux.linux.arm.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha256-armv4-linux.linux.arm.S index d8344262..8e9f5522 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha256-armv4-linux.linux.arm.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha256-armv4-linux.linux.arm.S @@ -1868,6 +1868,14 @@ sha256_block_data_order_nohw: .arch armv7-a .fpu neon +.LK256_shortcut_neon: +@ PC is 8 bytes ahead in Arm mode and 4 bytes ahead in Thumb mode. +#if defined(__thumb2__) +.word K256-(.LK256_add_neon+4) +#else +.word K256-(.LK256_add_neon+8) +#endif + .globl sha256_block_data_order_neon .hidden sha256_block_data_order_neon .type sha256_block_data_order_neon,%function @@ -1877,10 +1885,21 @@ sha256_block_data_order_neon: stmdb sp!,{r4,r5,r6,r7,r8,r9,r10,r11,r12,lr} sub r11,sp,#16*4+16 - @ In Arm mode, the following ADR runs up against the limits of encodable - @ offsets. It only fits because the offset, when the ADR is placed here, - @ is a multiple of 16. - adr r14,K256 + + @ K256 is just at the boundary of being easily referenced by an ADR from + @ this function. In Arm mode, when building with __ARM_ARCH=6, it does + @ not fit. By moving code around, we could make it fit, but this is too + @ fragile. For simplicity, just load the offset from + @ .LK256_shortcut_neon. + @ + @ TODO(davidben): adrl would avoid a load, but clang-assembler does not + @ support it. We might be able to emulate it with a macro, but Android's + @ did not work when I tried it. + @ https://android.googlesource.com/platform/ndk/+/refs/heads/master/docs/ClangMigration.md#arm + ldr r14,.LK256_shortcut_neon +.LK256_add_neon: + add r14,pc,r14 + bic r11,r11,#15 @ align for 128-bit stores mov r12,sp mov sp,r11 @ alloca @@ -2662,12 +2681,12 @@ sha256_block_data_order_neon: # define INST(a,b,c,d) .byte a,b,c,d # endif -.LK256_shortcut: +.LK256_shortcut_hw: @ PC is 8 bytes ahead in Arm mode and 4 bytes ahead in Thumb mode. #if defined(__thumb2__) -.word K256-(.LK256_add+4) +.word K256-(.LK256_add_hw+4) #else -.word K256-(.LK256_add+8) +.word K256-(.LK256_add_hw+8) #endif .globl sha256_block_data_order_hw @@ -2677,9 +2696,9 @@ sha256_block_data_order_neon: sha256_block_data_order_hw: @ K256 is too far to reference from one ADR command in Thumb mode. In @ Arm mode, we could make it fit by aligning the ADR offset to a 64-byte - @ boundary. For simplicity, just load the offset from .LK256_shortcut. - ldr r3,.LK256_shortcut -.LK256_add: + @ boundary. For simplicity, just load the offset from .LK256_shortcut_hw. + ldr r3,.LK256_shortcut_hw +.LK256_add_hw: add r3,pc,r3 vld1.32 {q0,q1},[r0] diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha512-586-windows.windows.x86.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha512-586-windows.windows.x86.S index 7cbf0cb6..8e1da2bb 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha512-586-windows.windows.x86.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/sha512-586-windows.windows.x86.S @@ -15,6 +15,7 @@ section .text code align=64 %else section .text code %endif +;extern _OPENSSL_ia32cap_P global _sha512_block_data_order align 16 _sha512_block_data_order: @@ -39,6 +40,2269 @@ L$000pic_point: mov DWORD [4+esp],edi mov DWORD [8+esp],eax mov DWORD [12+esp],ebx + lea edx,[_OPENSSL_ia32cap_P] + mov ecx,DWORD [edx] + test ecx,67108864 + jz NEAR L$002loop_x86 + mov edx,DWORD [4+edx] + movq mm0,[esi] + and ecx,16777216 + movq mm1,[8+esi] + and edx,512 + movq mm2,[16+esi] + or ecx,edx + movq mm3,[24+esi] + movq mm4,[32+esi] + movq mm5,[40+esi] + movq mm6,[48+esi] + movq mm7,[56+esi] + cmp ecx,16777728 + je NEAR L$003SSSE3 + sub esp,80 + jmp NEAR L$004loop_sse2 +align 16 +L$004loop_sse2: + movq [8+esp],mm1 + movq [16+esp],mm2 + movq [24+esp],mm3 + movq [40+esp],mm5 + movq [48+esp],mm6 + pxor mm2,mm1 + movq [56+esp],mm7 + movq mm3,mm0 + mov eax,DWORD [edi] + mov ebx,DWORD [4+edi] + add edi,8 + mov edx,15 + bswap eax + bswap ebx + jmp NEAR L$00500_14_sse2 +align 16 +L$00500_14_sse2: + movd mm1,eax + mov eax,DWORD [edi] + movd mm7,ebx + mov ebx,DWORD [4+edi] + add edi,8 + bswap eax + bswap ebx + punpckldq mm7,mm1 + movq mm1,mm4 + pxor mm5,mm6 + psrlq mm1,14 + movq [32+esp],mm4 + pand mm5,mm4 + psllq mm4,23 + movq mm0,mm3 + movq [72+esp],mm7 + movq mm3,mm1 + psrlq mm1,4 + pxor mm5,mm6 + pxor mm3,mm4 + psllq mm4,23 + pxor mm3,mm1 + movq [esp],mm0 + paddq mm7,mm5 + pxor mm3,mm4 + psrlq mm1,23 + paddq mm7,[56+esp] + pxor mm3,mm1 + psllq mm4,4 + paddq mm7,[ebp] + pxor mm3,mm4 + movq mm4,[24+esp] + paddq mm3,mm7 + movq mm5,mm0 + psrlq mm5,28 + paddq mm4,mm3 + movq mm6,mm0 + movq mm7,mm5 + psllq mm6,25 + movq mm1,[8+esp] + psrlq mm5,6 + pxor mm7,mm6 + sub esp,8 + psllq mm6,5 + pxor mm7,mm5 + pxor mm0,mm1 + psrlq mm5,5 + pxor mm7,mm6 + pand mm2,mm0 + psllq mm6,6 + pxor mm7,mm5 + pxor mm2,mm1 + pxor mm6,mm7 + movq mm5,[40+esp] + paddq mm3,mm2 + movq mm2,mm0 + add ebp,8 + paddq mm3,mm6 + movq mm6,[48+esp] + dec edx + jnz NEAR L$00500_14_sse2 + movd mm1,eax + movd mm7,ebx + punpckldq mm7,mm1 + movq mm1,mm4 + pxor mm5,mm6 + psrlq mm1,14 + movq [32+esp],mm4 + pand mm5,mm4 + psllq mm4,23 + movq mm0,mm3 + movq [72+esp],mm7 + movq mm3,mm1 + psrlq mm1,4 + pxor mm5,mm6 + pxor mm3,mm4 + psllq mm4,23 + pxor mm3,mm1 + movq [esp],mm0 + paddq mm7,mm5 + pxor mm3,mm4 + psrlq mm1,23 + paddq mm7,[56+esp] + pxor mm3,mm1 + psllq mm4,4 + paddq mm7,[ebp] + pxor mm3,mm4 + movq mm4,[24+esp] + paddq mm3,mm7 + movq mm5,mm0 + psrlq mm5,28 + paddq mm4,mm3 + movq mm6,mm0 + movq mm7,mm5 + psllq mm6,25 + movq mm1,[8+esp] + psrlq mm5,6 + pxor mm7,mm6 + sub esp,8 + psllq mm6,5 + pxor mm7,mm5 + pxor mm0,mm1 + psrlq mm5,5 + pxor mm7,mm6 + pand mm2,mm0 + psllq mm6,6 + pxor mm7,mm5 + pxor mm2,mm1 + pxor mm6,mm7 + movq mm7,[192+esp] + paddq mm3,mm2 + movq mm2,mm0 + add ebp,8 + paddq mm3,mm6 + pxor mm0,mm0 + mov edx,32 + jmp NEAR L$00616_79_sse2 +align 16 +L$00616_79_sse2: + movq mm5,[88+esp] + movq mm1,mm7 + psrlq mm7,1 + movq mm6,mm5 + psrlq mm5,6 + psllq mm1,56 + paddq mm0,mm3 + movq mm3,mm7 + psrlq mm7,6 + pxor mm3,mm1 + psllq mm1,7 + pxor mm3,mm7 + psrlq mm7,1 + pxor mm3,mm1 + movq mm1,mm5 + psrlq mm5,13 + pxor mm7,mm3 + psllq mm6,3 + pxor mm1,mm5 + paddq mm7,[200+esp] + pxor mm1,mm6 + psrlq mm5,42 + paddq mm7,[128+esp] + pxor mm1,mm5 + psllq mm6,42 + movq mm5,[40+esp] + pxor mm1,mm6 + movq mm6,[48+esp] + paddq mm7,mm1 + movq mm1,mm4 + pxor mm5,mm6 + psrlq mm1,14 + movq [32+esp],mm4 + pand mm5,mm4 + psllq mm4,23 + movq [72+esp],mm7 + movq mm3,mm1 + psrlq mm1,4 + pxor mm5,mm6 + pxor mm3,mm4 + psllq mm4,23 + pxor mm3,mm1 + movq [esp],mm0 + paddq mm7,mm5 + pxor mm3,mm4 + psrlq mm1,23 + paddq mm7,[56+esp] + pxor mm3,mm1 + psllq mm4,4 + paddq mm7,[ebp] + pxor mm3,mm4 + movq mm4,[24+esp] + paddq mm3,mm7 + movq mm5,mm0 + psrlq mm5,28 + paddq mm4,mm3 + movq mm6,mm0 + movq mm7,mm5 + psllq mm6,25 + movq mm1,[8+esp] + psrlq mm5,6 + pxor mm7,mm6 + sub esp,8 + psllq mm6,5 + pxor mm7,mm5 + pxor mm0,mm1 + psrlq mm5,5 + pxor mm7,mm6 + pand mm2,mm0 + psllq mm6,6 + pxor mm7,mm5 + pxor mm2,mm1 + pxor mm6,mm7 + movq mm7,[192+esp] + paddq mm2,mm6 + add ebp,8 + movq mm5,[88+esp] + movq mm1,mm7 + psrlq mm7,1 + movq mm6,mm5 + psrlq mm5,6 + psllq mm1,56 + paddq mm2,mm3 + movq mm3,mm7 + psrlq mm7,6 + pxor mm3,mm1 + psllq mm1,7 + pxor mm3,mm7 + psrlq mm7,1 + pxor mm3,mm1 + movq mm1,mm5 + psrlq mm5,13 + pxor mm7,mm3 + psllq mm6,3 + pxor mm1,mm5 + paddq mm7,[200+esp] + pxor mm1,mm6 + psrlq mm5,42 + paddq mm7,[128+esp] + pxor mm1,mm5 + psllq mm6,42 + movq mm5,[40+esp] + pxor mm1,mm6 + movq mm6,[48+esp] + paddq mm7,mm1 + movq mm1,mm4 + pxor mm5,mm6 + psrlq mm1,14 + movq [32+esp],mm4 + pand mm5,mm4 + psllq mm4,23 + movq [72+esp],mm7 + movq mm3,mm1 + psrlq mm1,4 + pxor mm5,mm6 + pxor mm3,mm4 + psllq mm4,23 + pxor mm3,mm1 + movq [esp],mm2 + paddq mm7,mm5 + pxor mm3,mm4 + psrlq mm1,23 + paddq mm7,[56+esp] + pxor mm3,mm1 + psllq mm4,4 + paddq mm7,[ebp] + pxor mm3,mm4 + movq mm4,[24+esp] + paddq mm3,mm7 + movq mm5,mm2 + psrlq mm5,28 + paddq mm4,mm3 + movq mm6,mm2 + movq mm7,mm5 + psllq mm6,25 + movq mm1,[8+esp] + psrlq mm5,6 + pxor mm7,mm6 + sub esp,8 + psllq mm6,5 + pxor mm7,mm5 + pxor mm2,mm1 + psrlq mm5,5 + pxor mm7,mm6 + pand mm0,mm2 + psllq mm6,6 + pxor mm7,mm5 + pxor mm0,mm1 + pxor mm6,mm7 + movq mm7,[192+esp] + paddq mm0,mm6 + add ebp,8 + dec edx + jnz NEAR L$00616_79_sse2 + paddq mm0,mm3 + movq mm1,[8+esp] + movq mm3,[24+esp] + movq mm5,[40+esp] + movq mm6,[48+esp] + movq mm7,[56+esp] + pxor mm2,mm1 + paddq mm0,[esi] + paddq mm1,[8+esi] + paddq mm2,[16+esi] + paddq mm3,[24+esi] + paddq mm4,[32+esi] + paddq mm5,[40+esi] + paddq mm6,[48+esi] + paddq mm7,[56+esi] + mov eax,640 + movq [esi],mm0 + movq [8+esi],mm1 + movq [16+esi],mm2 + movq [24+esi],mm3 + movq [32+esi],mm4 + movq [40+esi],mm5 + movq [48+esi],mm6 + movq [56+esi],mm7 + lea esp,[eax*1+esp] + sub ebp,eax + cmp edi,DWORD [88+esp] + jb NEAR L$004loop_sse2 + mov esp,DWORD [92+esp] + emms + pop edi + pop esi + pop ebx + pop ebp + ret +align 32 +L$003SSSE3: + lea edx,[esp-64] + sub esp,256 + movdqa xmm1,[640+ebp] + movdqu xmm0,[edi] +db 102,15,56,0,193 + movdqa xmm3,[ebp] + movdqa xmm2,xmm1 + movdqu xmm1,[16+edi] + paddq xmm3,xmm0 +db 102,15,56,0,202 + movdqa [edx-128],xmm3 + movdqa xmm4,[16+ebp] + movdqa xmm3,xmm2 + movdqu xmm2,[32+edi] + paddq xmm4,xmm1 +db 102,15,56,0,211 + movdqa [edx-112],xmm4 + movdqa xmm5,[32+ebp] + movdqa xmm4,xmm3 + movdqu xmm3,[48+edi] + paddq xmm5,xmm2 +db 102,15,56,0,220 + movdqa [edx-96],xmm5 + movdqa xmm6,[48+ebp] + movdqa xmm5,xmm4 + movdqu xmm4,[64+edi] + paddq xmm6,xmm3 +db 102,15,56,0,229 + movdqa [edx-80],xmm6 + movdqa xmm7,[64+ebp] + movdqa xmm6,xmm5 + movdqu xmm5,[80+edi] + paddq xmm7,xmm4 +db 102,15,56,0,238 + movdqa [edx-64],xmm7 + movdqa [edx],xmm0 + movdqa xmm0,[80+ebp] + movdqa xmm7,xmm6 + movdqu xmm6,[96+edi] + paddq xmm0,xmm5 +db 102,15,56,0,247 + movdqa [edx-48],xmm0 + movdqa [16+edx],xmm1 + movdqa xmm1,[96+ebp] + movdqa xmm0,xmm7 + movdqu xmm7,[112+edi] + paddq xmm1,xmm6 +db 102,15,56,0,248 + movdqa [edx-32],xmm1 + movdqa [32+edx],xmm2 + movdqa xmm2,[112+ebp] + movdqa xmm0,[edx] + paddq xmm2,xmm7 + movdqa [edx-16],xmm2 + nop +align 32 +L$007loop_ssse3: + movdqa xmm2,[16+edx] + movdqa [48+edx],xmm3 + lea ebp,[128+ebp] + movq [8+esp],mm1 + mov ebx,edi + movq [16+esp],mm2 + lea edi,[128+edi] + movq [24+esp],mm3 + cmp edi,eax + movq [40+esp],mm5 + cmovb ebx,edi + movq [48+esp],mm6 + mov ecx,4 + pxor mm2,mm1 + movq [56+esp],mm7 + pxor mm3,mm3 + jmp NEAR L$00800_47_ssse3 +align 32 +L$00800_47_ssse3: + movdqa xmm3,xmm5 + movdqa xmm1,xmm2 +db 102,15,58,15,208,8 + movdqa [edx],xmm4 +db 102,15,58,15,220,8 + movdqa xmm4,xmm2 + psrlq xmm2,7 + paddq xmm0,xmm3 + movdqa xmm3,xmm4 + psrlq xmm4,1 + psllq xmm3,56 + pxor xmm2,xmm4 + psrlq xmm4,7 + pxor xmm2,xmm3 + psllq xmm3,7 + pxor xmm2,xmm4 + movdqa xmm4,xmm7 + pxor xmm2,xmm3 + movdqa xmm3,xmm7 + psrlq xmm4,6 + paddq xmm0,xmm2 + movdqa xmm2,xmm7 + psrlq xmm3,19 + psllq xmm2,3 + pxor xmm4,xmm3 + psrlq xmm3,42 + pxor xmm4,xmm2 + psllq xmm2,42 + pxor xmm4,xmm3 + movdqa xmm3,[32+edx] + pxor xmm4,xmm2 + movdqa xmm2,[ebp] + movq mm1,mm4 + paddq xmm0,xmm4 + movq mm7,[edx-128] + pxor mm5,mm6 + psrlq mm1,14 + movq [32+esp],mm4 + paddq xmm2,xmm0 + pand mm5,mm4 + psllq mm4,23 + paddq mm0,mm3 + movq mm3,mm1 + psrlq mm1,4 + pxor mm5,mm6 + pxor mm3,mm4 + psllq mm4,23 + pxor mm3,mm1 + movq [esp],mm0 + paddq mm7,mm5 + pxor mm3,mm4 + psrlq mm1,23 + paddq mm7,[56+esp] + pxor mm3,mm1 + psllq mm4,4 + pxor mm3,mm4 + movq mm4,[24+esp] + paddq mm3,mm7 + movq mm5,mm0 + psrlq mm5,28 + paddq mm4,mm3 + movq mm6,mm0 + movq mm7,mm5 + psllq mm6,25 + movq mm1,[8+esp] + psrlq mm5,6 + pxor mm7,mm6 + psllq mm6,5 + pxor mm7,mm5 + pxor mm0,mm1 + psrlq mm5,5 + pxor mm7,mm6 + pand mm2,mm0 + psllq mm6,6 + pxor mm7,mm5 + pxor mm2,mm1 + pxor mm6,mm7 + movq mm5,[32+esp] + paddq mm2,mm6 + movq mm6,[40+esp] + movq mm1,mm4 + movq mm7,[edx-120] + pxor mm5,mm6 + psrlq mm1,14 + movq [24+esp],mm4 + pand mm5,mm4 + psllq mm4,23 + paddq mm2,mm3 + movq mm3,mm1 + psrlq mm1,4 + pxor mm5,mm6 + pxor mm3,mm4 + psllq mm4,23 + pxor mm3,mm1 + movq [56+esp],mm2 + paddq mm7,mm5 + pxor mm3,mm4 + psrlq mm1,23 + paddq mm7,[48+esp] + pxor mm3,mm1 + psllq mm4,4 + pxor mm3,mm4 + movq mm4,[16+esp] + paddq mm3,mm7 + movq mm5,mm2 + psrlq mm5,28 + paddq mm4,mm3 + movq mm6,mm2 + movq mm7,mm5 + psllq mm6,25 + movq mm1,[esp] + psrlq mm5,6 + pxor mm7,mm6 + psllq mm6,5 + pxor mm7,mm5 + pxor mm2,mm1 + psrlq mm5,5 + pxor mm7,mm6 + pand mm0,mm2 + psllq mm6,6 + pxor mm7,mm5 + pxor mm0,mm1 + pxor mm6,mm7 + movq mm5,[24+esp] + paddq mm0,mm6 + movq mm6,[32+esp] + movdqa [edx-128],xmm2 + movdqa xmm4,xmm6 + movdqa xmm2,xmm3 +db 102,15,58,15,217,8 + movdqa [16+edx],xmm5 +db 102,15,58,15,229,8 + movdqa xmm5,xmm3 + psrlq xmm3,7 + paddq xmm1,xmm4 + movdqa xmm4,xmm5 + psrlq xmm5,1 + psllq xmm4,56 + pxor xmm3,xmm5 + psrlq xmm5,7 + pxor xmm3,xmm4 + psllq xmm4,7 + pxor xmm3,xmm5 + movdqa xmm5,xmm0 + pxor xmm3,xmm4 + movdqa xmm4,xmm0 + psrlq xmm5,6 + paddq xmm1,xmm3 + movdqa xmm3,xmm0 + psrlq xmm4,19 + psllq xmm3,3 + pxor xmm5,xmm4 + psrlq xmm4,42 + pxor xmm5,xmm3 + psllq xmm3,42 + pxor xmm5,xmm4 + movdqa xmm4,[48+edx] + pxor xmm5,xmm3 + movdqa xmm3,[16+ebp] + movq mm1,mm4 + paddq xmm1,xmm5 + movq mm7,[edx-112] + pxor mm5,mm6 + psrlq mm1,14 + movq [16+esp],mm4 + paddq xmm3,xmm1 + pand mm5,mm4 + psllq mm4,23 + paddq mm0,mm3 + movq mm3,mm1 + psrlq mm1,4 + pxor mm5,mm6 + pxor mm3,mm4 + psllq mm4,23 + pxor mm3,mm1 + movq [48+esp],mm0 + paddq mm7,mm5 + pxor mm3,mm4 + psrlq mm1,23 + paddq mm7,[40+esp] + pxor mm3,mm1 + psllq mm4,4 + pxor mm3,mm4 + movq mm4,[8+esp] + paddq mm3,mm7 + movq mm5,mm0 + psrlq mm5,28 + paddq mm4,mm3 + movq mm6,mm0 + movq mm7,mm5 + psllq mm6,25 + movq mm1,[56+esp] + psrlq mm5,6 + pxor mm7,mm6 + psllq mm6,5 + pxor mm7,mm5 + pxor mm0,mm1 + psrlq mm5,5 + pxor mm7,mm6 + pand mm2,mm0 + psllq mm6,6 + pxor mm7,mm5 + pxor mm2,mm1 + pxor mm6,mm7 + movq mm5,[16+esp] + paddq mm2,mm6 + movq mm6,[24+esp] + movq mm1,mm4 + movq mm7,[edx-104] + pxor mm5,mm6 + psrlq mm1,14 + movq [8+esp],mm4 + pand mm5,mm4 + psllq mm4,23 + paddq mm2,mm3 + movq mm3,mm1 + psrlq mm1,4 + pxor mm5,mm6 + pxor mm3,mm4 + psllq mm4,23 + pxor mm3,mm1 + movq [40+esp],mm2 + paddq mm7,mm5 + pxor mm3,mm4 + psrlq mm1,23 + paddq mm7,[32+esp] + pxor mm3,mm1 + psllq mm4,4 + pxor mm3,mm4 + movq mm4,[esp] + paddq mm3,mm7 + movq mm5,mm2 + psrlq mm5,28 + paddq mm4,mm3 + movq mm6,mm2 + movq mm7,mm5 + psllq mm6,25 + movq mm1,[48+esp] + psrlq mm5,6 + pxor mm7,mm6 + psllq mm6,5 + pxor mm7,mm5 + pxor mm2,mm1 + psrlq mm5,5 + pxor mm7,mm6 + pand mm0,mm2 + psllq mm6,6 + pxor mm7,mm5 + pxor mm0,mm1 + pxor mm6,mm7 + movq mm5,[8+esp] + paddq mm0,mm6 + movq mm6,[16+esp] + movdqa [edx-112],xmm3 + movdqa xmm5,xmm7 + movdqa xmm3,xmm4 +db 102,15,58,15,226,8 + movdqa [32+edx],xmm6 +db 102,15,58,15,238,8 + movdqa xmm6,xmm4 + psrlq xmm4,7 + paddq xmm2,xmm5 + movdqa xmm5,xmm6 + psrlq xmm6,1 + psllq xmm5,56 + pxor xmm4,xmm6 + psrlq xmm6,7 + pxor xmm4,xmm5 + psllq xmm5,7 + pxor xmm4,xmm6 + movdqa xmm6,xmm1 + pxor xmm4,xmm5 + movdqa xmm5,xmm1 + psrlq xmm6,6 + paddq xmm2,xmm4 + movdqa xmm4,xmm1 + psrlq xmm5,19 + psllq xmm4,3 + pxor xmm6,xmm5 + psrlq xmm5,42 + pxor xmm6,xmm4 + psllq xmm4,42 + pxor xmm6,xmm5 + movdqa xmm5,[edx] + pxor xmm6,xmm4 + movdqa xmm4,[32+ebp] + movq mm1,mm4 + paddq xmm2,xmm6 + movq mm7,[edx-96] + pxor mm5,mm6 + psrlq mm1,14 + movq [esp],mm4 + paddq xmm4,xmm2 + pand mm5,mm4 + psllq mm4,23 + paddq mm0,mm3 + movq mm3,mm1 + psrlq mm1,4 + pxor mm5,mm6 + pxor mm3,mm4 + psllq mm4,23 + pxor mm3,mm1 + movq [32+esp],mm0 + paddq mm7,mm5 + pxor mm3,mm4 + psrlq mm1,23 + paddq mm7,[24+esp] + pxor mm3,mm1 + psllq mm4,4 + pxor mm3,mm4 + movq mm4,[56+esp] + paddq mm3,mm7 + movq mm5,mm0 + psrlq mm5,28 + paddq mm4,mm3 + movq mm6,mm0 + movq mm7,mm5 + psllq mm6,25 + movq mm1,[40+esp] + psrlq mm5,6 + pxor mm7,mm6 + psllq mm6,5 + pxor mm7,mm5 + pxor mm0,mm1 + psrlq mm5,5 + pxor mm7,mm6 + pand mm2,mm0 + psllq mm6,6 + pxor mm7,mm5 + pxor mm2,mm1 + pxor mm6,mm7 + movq mm5,[esp] + paddq mm2,mm6 + movq mm6,[8+esp] + movq mm1,mm4 + movq mm7,[edx-88] + pxor mm5,mm6 + psrlq mm1,14 + movq [56+esp],mm4 + pand mm5,mm4 + psllq mm4,23 + paddq mm2,mm3 + movq mm3,mm1 + psrlq mm1,4 + pxor mm5,mm6 + pxor mm3,mm4 + psllq mm4,23 + pxor mm3,mm1 + movq [24+esp],mm2 + paddq mm7,mm5 + pxor mm3,mm4 + psrlq mm1,23 + paddq mm7,[16+esp] + pxor mm3,mm1 + psllq mm4,4 + pxor mm3,mm4 + movq mm4,[48+esp] + paddq mm3,mm7 + movq mm5,mm2 + psrlq mm5,28 + paddq mm4,mm3 + movq mm6,mm2 + movq mm7,mm5 + psllq mm6,25 + movq mm1,[32+esp] + psrlq mm5,6 + pxor mm7,mm6 + psllq mm6,5 + pxor mm7,mm5 + pxor mm2,mm1 + psrlq mm5,5 + pxor mm7,mm6 + pand mm0,mm2 + psllq mm6,6 + pxor mm7,mm5 + pxor mm0,mm1 + pxor mm6,mm7 + movq mm5,[56+esp] + paddq mm0,mm6 + movq mm6,[esp] + movdqa [edx-96],xmm4 + movdqa xmm6,xmm0 + movdqa xmm4,xmm5 +db 102,15,58,15,235,8 + movdqa [48+edx],xmm7 +db 102,15,58,15,247,8 + movdqa xmm7,xmm5 + psrlq xmm5,7 + paddq xmm3,xmm6 + movdqa xmm6,xmm7 + psrlq xmm7,1 + psllq xmm6,56 + pxor xmm5,xmm7 + psrlq xmm7,7 + pxor xmm5,xmm6 + psllq xmm6,7 + pxor xmm5,xmm7 + movdqa xmm7,xmm2 + pxor xmm5,xmm6 + movdqa xmm6,xmm2 + psrlq xmm7,6 + paddq xmm3,xmm5 + movdqa xmm5,xmm2 + psrlq xmm6,19 + psllq xmm5,3 + pxor xmm7,xmm6 + psrlq xmm6,42 + pxor xmm7,xmm5 + psllq xmm5,42 + pxor xmm7,xmm6 + movdqa xmm6,[16+edx] + pxor xmm7,xmm5 + movdqa xmm5,[48+ebp] + movq mm1,mm4 + paddq xmm3,xmm7 + movq mm7,[edx-80] + pxor mm5,mm6 + psrlq mm1,14 + movq [48+esp],mm4 + paddq xmm5,xmm3 + pand mm5,mm4 + psllq mm4,23 + paddq mm0,mm3 + movq mm3,mm1 + psrlq mm1,4 + pxor mm5,mm6 + pxor mm3,mm4 + psllq mm4,23 + pxor mm3,mm1 + movq [16+esp],mm0 + paddq mm7,mm5 + pxor mm3,mm4 + psrlq mm1,23 + paddq mm7,[8+esp] + pxor mm3,mm1 + psllq mm4,4 + pxor mm3,mm4 + movq mm4,[40+esp] + paddq mm3,mm7 + movq mm5,mm0 + psrlq mm5,28 + paddq mm4,mm3 + movq mm6,mm0 + movq mm7,mm5 + psllq mm6,25 + movq mm1,[24+esp] + psrlq mm5,6 + pxor mm7,mm6 + psllq mm6,5 + pxor mm7,mm5 + pxor mm0,mm1 + psrlq mm5,5 + pxor mm7,mm6 + pand mm2,mm0 + psllq mm6,6 + pxor mm7,mm5 + pxor mm2,mm1 + pxor mm6,mm7 + movq mm5,[48+esp] + paddq mm2,mm6 + movq mm6,[56+esp] + movq mm1,mm4 + movq mm7,[edx-72] + pxor mm5,mm6 + psrlq mm1,14 + movq [40+esp],mm4 + pand mm5,mm4 + psllq mm4,23 + paddq mm2,mm3 + movq mm3,mm1 + psrlq mm1,4 + pxor mm5,mm6 + pxor mm3,mm4 + psllq mm4,23 + pxor mm3,mm1 + movq [8+esp],mm2 + paddq mm7,mm5 + pxor mm3,mm4 + psrlq mm1,23 + paddq mm7,[esp] + pxor mm3,mm1 + psllq mm4,4 + pxor mm3,mm4 + movq mm4,[32+esp] + paddq mm3,mm7 + movq mm5,mm2 + psrlq mm5,28 + paddq mm4,mm3 + movq mm6,mm2 + movq mm7,mm5 + psllq mm6,25 + movq mm1,[16+esp] + psrlq mm5,6 + pxor mm7,mm6 + psllq mm6,5 + pxor mm7,mm5 + pxor mm2,mm1 + psrlq mm5,5 + pxor mm7,mm6 + pand mm0,mm2 + psllq mm6,6 + pxor mm7,mm5 + pxor mm0,mm1 + pxor mm6,mm7 + movq mm5,[40+esp] + paddq mm0,mm6 + movq mm6,[48+esp] + movdqa [edx-80],xmm5 + movdqa xmm7,xmm1 + movdqa xmm5,xmm6 +db 102,15,58,15,244,8 + movdqa [edx],xmm0 +db 102,15,58,15,248,8 + movdqa xmm0,xmm6 + psrlq xmm6,7 + paddq xmm4,xmm7 + movdqa xmm7,xmm0 + psrlq xmm0,1 + psllq xmm7,56 + pxor xmm6,xmm0 + psrlq xmm0,7 + pxor xmm6,xmm7 + psllq xmm7,7 + pxor xmm6,xmm0 + movdqa xmm0,xmm3 + pxor xmm6,xmm7 + movdqa xmm7,xmm3 + psrlq xmm0,6 + paddq xmm4,xmm6 + movdqa xmm6,xmm3 + psrlq xmm7,19 + psllq xmm6,3 + pxor xmm0,xmm7 + psrlq xmm7,42 + pxor xmm0,xmm6 + psllq xmm6,42 + pxor xmm0,xmm7 + movdqa xmm7,[32+edx] + pxor xmm0,xmm6 + movdqa xmm6,[64+ebp] + movq mm1,mm4 + paddq xmm4,xmm0 + movq mm7,[edx-64] + pxor mm5,mm6 + psrlq mm1,14 + movq [32+esp],mm4 + paddq xmm6,xmm4 + pand mm5,mm4 + psllq mm4,23 + paddq mm0,mm3 + movq mm3,mm1 + psrlq mm1,4 + pxor mm5,mm6 + pxor mm3,mm4 + psllq mm4,23 + pxor mm3,mm1 + movq [esp],mm0 + paddq mm7,mm5 + pxor mm3,mm4 + psrlq mm1,23 + paddq mm7,[56+esp] + pxor mm3,mm1 + psllq mm4,4 + pxor mm3,mm4 + movq mm4,[24+esp] + paddq mm3,mm7 + movq mm5,mm0 + psrlq mm5,28 + paddq mm4,mm3 + movq mm6,mm0 + movq mm7,mm5 + psllq mm6,25 + movq mm1,[8+esp] + psrlq mm5,6 + pxor mm7,mm6 + psllq mm6,5 + pxor mm7,mm5 + pxor mm0,mm1 + psrlq mm5,5 + pxor mm7,mm6 + pand mm2,mm0 + psllq mm6,6 + pxor mm7,mm5 + pxor mm2,mm1 + pxor mm6,mm7 + movq mm5,[32+esp] + paddq mm2,mm6 + movq mm6,[40+esp] + movq mm1,mm4 + movq mm7,[edx-56] + pxor mm5,mm6 + psrlq mm1,14 + movq [24+esp],mm4 + pand mm5,mm4 + psllq mm4,23 + paddq mm2,mm3 + movq mm3,mm1 + psrlq mm1,4 + pxor mm5,mm6 + pxor mm3,mm4 + psllq mm4,23 + pxor mm3,mm1 + movq [56+esp],mm2 + paddq mm7,mm5 + pxor mm3,mm4 + psrlq mm1,23 + paddq mm7,[48+esp] + pxor mm3,mm1 + psllq mm4,4 + pxor mm3,mm4 + movq mm4,[16+esp] + paddq mm3,mm7 + movq mm5,mm2 + psrlq mm5,28 + paddq mm4,mm3 + movq mm6,mm2 + movq mm7,mm5 + psllq mm6,25 + movq mm1,[esp] + psrlq mm5,6 + pxor mm7,mm6 + psllq mm6,5 + pxor mm7,mm5 + pxor mm2,mm1 + psrlq mm5,5 + pxor mm7,mm6 + pand mm0,mm2 + psllq mm6,6 + pxor mm7,mm5 + pxor mm0,mm1 + pxor mm6,mm7 + movq mm5,[24+esp] + paddq mm0,mm6 + movq mm6,[32+esp] + movdqa [edx-64],xmm6 + movdqa xmm0,xmm2 + movdqa xmm6,xmm7 +db 102,15,58,15,253,8 + movdqa [16+edx],xmm1 +db 102,15,58,15,193,8 + movdqa xmm1,xmm7 + psrlq xmm7,7 + paddq xmm5,xmm0 + movdqa xmm0,xmm1 + psrlq xmm1,1 + psllq xmm0,56 + pxor xmm7,xmm1 + psrlq xmm1,7 + pxor xmm7,xmm0 + psllq xmm0,7 + pxor xmm7,xmm1 + movdqa xmm1,xmm4 + pxor xmm7,xmm0 + movdqa xmm0,xmm4 + psrlq xmm1,6 + paddq xmm5,xmm7 + movdqa xmm7,xmm4 + psrlq xmm0,19 + psllq xmm7,3 + pxor xmm1,xmm0 + psrlq xmm0,42 + pxor xmm1,xmm7 + psllq xmm7,42 + pxor xmm1,xmm0 + movdqa xmm0,[48+edx] + pxor xmm1,xmm7 + movdqa xmm7,[80+ebp] + movq mm1,mm4 + paddq xmm5,xmm1 + movq mm7,[edx-48] + pxor mm5,mm6 + psrlq mm1,14 + movq [16+esp],mm4 + paddq xmm7,xmm5 + pand mm5,mm4 + psllq mm4,23 + paddq mm0,mm3 + movq mm3,mm1 + psrlq mm1,4 + pxor mm5,mm6 + pxor mm3,mm4 + psllq mm4,23 + pxor mm3,mm1 + movq [48+esp],mm0 + paddq mm7,mm5 + pxor mm3,mm4 + psrlq mm1,23 + paddq mm7,[40+esp] + pxor mm3,mm1 + psllq mm4,4 + pxor mm3,mm4 + movq mm4,[8+esp] + paddq mm3,mm7 + movq mm5,mm0 + psrlq mm5,28 + paddq mm4,mm3 + movq mm6,mm0 + movq mm7,mm5 + psllq mm6,25 + movq mm1,[56+esp] + psrlq mm5,6 + pxor mm7,mm6 + psllq mm6,5 + pxor mm7,mm5 + pxor mm0,mm1 + psrlq mm5,5 + pxor mm7,mm6 + pand mm2,mm0 + psllq mm6,6 + pxor mm7,mm5 + pxor mm2,mm1 + pxor mm6,mm7 + movq mm5,[16+esp] + paddq mm2,mm6 + movq mm6,[24+esp] + movq mm1,mm4 + movq mm7,[edx-40] + pxor mm5,mm6 + psrlq mm1,14 + movq [8+esp],mm4 + pand mm5,mm4 + psllq mm4,23 + paddq mm2,mm3 + movq mm3,mm1 + psrlq mm1,4 + pxor mm5,mm6 + pxor mm3,mm4 + psllq mm4,23 + pxor mm3,mm1 + movq [40+esp],mm2 + paddq mm7,mm5 + pxor mm3,mm4 + psrlq mm1,23 + paddq mm7,[32+esp] + pxor mm3,mm1 + psllq mm4,4 + pxor mm3,mm4 + movq mm4,[esp] + paddq mm3,mm7 + movq mm5,mm2 + psrlq mm5,28 + paddq mm4,mm3 + movq mm6,mm2 + movq mm7,mm5 + psllq mm6,25 + movq mm1,[48+esp] + psrlq mm5,6 + pxor mm7,mm6 + psllq mm6,5 + pxor mm7,mm5 + pxor mm2,mm1 + psrlq mm5,5 + pxor mm7,mm6 + pand mm0,mm2 + psllq mm6,6 + pxor mm7,mm5 + pxor mm0,mm1 + pxor mm6,mm7 + movq mm5,[8+esp] + paddq mm0,mm6 + movq mm6,[16+esp] + movdqa [edx-48],xmm7 + movdqa xmm1,xmm3 + movdqa xmm7,xmm0 +db 102,15,58,15,198,8 + movdqa [32+edx],xmm2 +db 102,15,58,15,202,8 + movdqa xmm2,xmm0 + psrlq xmm0,7 + paddq xmm6,xmm1 + movdqa xmm1,xmm2 + psrlq xmm2,1 + psllq xmm1,56 + pxor xmm0,xmm2 + psrlq xmm2,7 + pxor xmm0,xmm1 + psllq xmm1,7 + pxor xmm0,xmm2 + movdqa xmm2,xmm5 + pxor xmm0,xmm1 + movdqa xmm1,xmm5 + psrlq xmm2,6 + paddq xmm6,xmm0 + movdqa xmm0,xmm5 + psrlq xmm1,19 + psllq xmm0,3 + pxor xmm2,xmm1 + psrlq xmm1,42 + pxor xmm2,xmm0 + psllq xmm0,42 + pxor xmm2,xmm1 + movdqa xmm1,[edx] + pxor xmm2,xmm0 + movdqa xmm0,[96+ebp] + movq mm1,mm4 + paddq xmm6,xmm2 + movq mm7,[edx-32] + pxor mm5,mm6 + psrlq mm1,14 + movq [esp],mm4 + paddq xmm0,xmm6 + pand mm5,mm4 + psllq mm4,23 + paddq mm0,mm3 + movq mm3,mm1 + psrlq mm1,4 + pxor mm5,mm6 + pxor mm3,mm4 + psllq mm4,23 + pxor mm3,mm1 + movq [32+esp],mm0 + paddq mm7,mm5 + pxor mm3,mm4 + psrlq mm1,23 + paddq mm7,[24+esp] + pxor mm3,mm1 + psllq mm4,4 + pxor mm3,mm4 + movq mm4,[56+esp] + paddq mm3,mm7 + movq mm5,mm0 + psrlq mm5,28 + paddq mm4,mm3 + movq mm6,mm0 + movq mm7,mm5 + psllq mm6,25 + movq mm1,[40+esp] + psrlq mm5,6 + pxor mm7,mm6 + psllq mm6,5 + pxor mm7,mm5 + pxor mm0,mm1 + psrlq mm5,5 + pxor mm7,mm6 + pand mm2,mm0 + psllq mm6,6 + pxor mm7,mm5 + pxor mm2,mm1 + pxor mm6,mm7 + movq mm5,[esp] + paddq mm2,mm6 + movq mm6,[8+esp] + movq mm1,mm4 + movq mm7,[edx-24] + pxor mm5,mm6 + psrlq mm1,14 + movq [56+esp],mm4 + pand mm5,mm4 + psllq mm4,23 + paddq mm2,mm3 + movq mm3,mm1 + psrlq mm1,4 + pxor mm5,mm6 + pxor mm3,mm4 + psllq mm4,23 + pxor mm3,mm1 + movq [24+esp],mm2 + paddq mm7,mm5 + pxor mm3,mm4 + psrlq mm1,23 + paddq mm7,[16+esp] + pxor mm3,mm1 + psllq mm4,4 + pxor mm3,mm4 + movq mm4,[48+esp] + paddq mm3,mm7 + movq mm5,mm2 + psrlq mm5,28 + paddq mm4,mm3 + movq mm6,mm2 + movq mm7,mm5 + psllq mm6,25 + movq mm1,[32+esp] + psrlq mm5,6 + pxor mm7,mm6 + psllq mm6,5 + pxor mm7,mm5 + pxor mm2,mm1 + psrlq mm5,5 + pxor mm7,mm6 + pand mm0,mm2 + psllq mm6,6 + pxor mm7,mm5 + pxor mm0,mm1 + pxor mm6,mm7 + movq mm5,[56+esp] + paddq mm0,mm6 + movq mm6,[esp] + movdqa [edx-32],xmm0 + movdqa xmm2,xmm4 + movdqa xmm0,xmm1 +db 102,15,58,15,207,8 + movdqa [48+edx],xmm3 +db 102,15,58,15,211,8 + movdqa xmm3,xmm1 + psrlq xmm1,7 + paddq xmm7,xmm2 + movdqa xmm2,xmm3 + psrlq xmm3,1 + psllq xmm2,56 + pxor xmm1,xmm3 + psrlq xmm3,7 + pxor xmm1,xmm2 + psllq xmm2,7 + pxor xmm1,xmm3 + movdqa xmm3,xmm6 + pxor xmm1,xmm2 + movdqa xmm2,xmm6 + psrlq xmm3,6 + paddq xmm7,xmm1 + movdqa xmm1,xmm6 + psrlq xmm2,19 + psllq xmm1,3 + pxor xmm3,xmm2 + psrlq xmm2,42 + pxor xmm3,xmm1 + psllq xmm1,42 + pxor xmm3,xmm2 + movdqa xmm2,[16+edx] + pxor xmm3,xmm1 + movdqa xmm1,[112+ebp] + movq mm1,mm4 + paddq xmm7,xmm3 + movq mm7,[edx-16] + pxor mm5,mm6 + psrlq mm1,14 + movq [48+esp],mm4 + paddq xmm1,xmm7 + pand mm5,mm4 + psllq mm4,23 + paddq mm0,mm3 + movq mm3,mm1 + psrlq mm1,4 + pxor mm5,mm6 + pxor mm3,mm4 + psllq mm4,23 + pxor mm3,mm1 + movq [16+esp],mm0 + paddq mm7,mm5 + pxor mm3,mm4 + psrlq mm1,23 + paddq mm7,[8+esp] + pxor mm3,mm1 + psllq mm4,4 + pxor mm3,mm4 + movq mm4,[40+esp] + paddq mm3,mm7 + movq mm5,mm0 + psrlq mm5,28 + paddq mm4,mm3 + movq mm6,mm0 + movq mm7,mm5 + psllq mm6,25 + movq mm1,[24+esp] + psrlq mm5,6 + pxor mm7,mm6 + psllq mm6,5 + pxor mm7,mm5 + pxor mm0,mm1 + psrlq mm5,5 + pxor mm7,mm6 + pand mm2,mm0 + psllq mm6,6 + pxor mm7,mm5 + pxor mm2,mm1 + pxor mm6,mm7 + movq mm5,[48+esp] + paddq mm2,mm6 + movq mm6,[56+esp] + movq mm1,mm4 + movq mm7,[edx-8] + pxor mm5,mm6 + psrlq mm1,14 + movq [40+esp],mm4 + pand mm5,mm4 + psllq mm4,23 + paddq mm2,mm3 + movq mm3,mm1 + psrlq mm1,4 + pxor mm5,mm6 + pxor mm3,mm4 + psllq mm4,23 + pxor mm3,mm1 + movq [8+esp],mm2 + paddq mm7,mm5 + pxor mm3,mm4 + psrlq mm1,23 + paddq mm7,[esp] + pxor mm3,mm1 + psllq mm4,4 + pxor mm3,mm4 + movq mm4,[32+esp] + paddq mm3,mm7 + movq mm5,mm2 + psrlq mm5,28 + paddq mm4,mm3 + movq mm6,mm2 + movq mm7,mm5 + psllq mm6,25 + movq mm1,[16+esp] + psrlq mm5,6 + pxor mm7,mm6 + psllq mm6,5 + pxor mm7,mm5 + pxor mm2,mm1 + psrlq mm5,5 + pxor mm7,mm6 + pand mm0,mm2 + psllq mm6,6 + pxor mm7,mm5 + pxor mm0,mm1 + pxor mm6,mm7 + movq mm5,[40+esp] + paddq mm0,mm6 + movq mm6,[48+esp] + movdqa [edx-16],xmm1 + lea ebp,[128+ebp] + dec ecx + jnz NEAR L$00800_47_ssse3 + movdqa xmm1,[ebp] + lea ebp,[ebp-640] + movdqu xmm0,[ebx] +db 102,15,56,0,193 + movdqa xmm3,[ebp] + movdqa xmm2,xmm1 + movdqu xmm1,[16+ebx] + paddq xmm3,xmm0 +db 102,15,56,0,202 + movq mm1,mm4 + movq mm7,[edx-128] + pxor mm5,mm6 + psrlq mm1,14 + movq [32+esp],mm4 + pand mm5,mm4 + psllq mm4,23 + paddq mm0,mm3 + movq mm3,mm1 + psrlq mm1,4 + pxor mm5,mm6 + pxor mm3,mm4 + psllq mm4,23 + pxor mm3,mm1 + movq [esp],mm0 + paddq mm7,mm5 + pxor mm3,mm4 + psrlq mm1,23 + paddq mm7,[56+esp] + pxor mm3,mm1 + psllq mm4,4 + pxor mm3,mm4 + movq mm4,[24+esp] + paddq mm3,mm7 + movq mm5,mm0 + psrlq mm5,28 + paddq mm4,mm3 + movq mm6,mm0 + movq mm7,mm5 + psllq mm6,25 + movq mm1,[8+esp] + psrlq mm5,6 + pxor mm7,mm6 + psllq mm6,5 + pxor mm7,mm5 + pxor mm0,mm1 + psrlq mm5,5 + pxor mm7,mm6 + pand mm2,mm0 + psllq mm6,6 + pxor mm7,mm5 + pxor mm2,mm1 + pxor mm6,mm7 + movq mm5,[32+esp] + paddq mm2,mm6 + movq mm6,[40+esp] + movq mm1,mm4 + movq mm7,[edx-120] + pxor mm5,mm6 + psrlq mm1,14 + movq [24+esp],mm4 + pand mm5,mm4 + psllq mm4,23 + paddq mm2,mm3 + movq mm3,mm1 + psrlq mm1,4 + pxor mm5,mm6 + pxor mm3,mm4 + psllq mm4,23 + pxor mm3,mm1 + movq [56+esp],mm2 + paddq mm7,mm5 + pxor mm3,mm4 + psrlq mm1,23 + paddq mm7,[48+esp] + pxor mm3,mm1 + psllq mm4,4 + pxor mm3,mm4 + movq mm4,[16+esp] + paddq mm3,mm7 + movq mm5,mm2 + psrlq mm5,28 + paddq mm4,mm3 + movq mm6,mm2 + movq mm7,mm5 + psllq mm6,25 + movq mm1,[esp] + psrlq mm5,6 + pxor mm7,mm6 + psllq mm6,5 + pxor mm7,mm5 + pxor mm2,mm1 + psrlq mm5,5 + pxor mm7,mm6 + pand mm0,mm2 + psllq mm6,6 + pxor mm7,mm5 + pxor mm0,mm1 + pxor mm6,mm7 + movq mm5,[24+esp] + paddq mm0,mm6 + movq mm6,[32+esp] + movdqa [edx-128],xmm3 + movdqa xmm4,[16+ebp] + movdqa xmm3,xmm2 + movdqu xmm2,[32+ebx] + paddq xmm4,xmm1 +db 102,15,56,0,211 + movq mm1,mm4 + movq mm7,[edx-112] + pxor mm5,mm6 + psrlq mm1,14 + movq [16+esp],mm4 + pand mm5,mm4 + psllq mm4,23 + paddq mm0,mm3 + movq mm3,mm1 + psrlq mm1,4 + pxor mm5,mm6 + pxor mm3,mm4 + psllq mm4,23 + pxor mm3,mm1 + movq [48+esp],mm0 + paddq mm7,mm5 + pxor mm3,mm4 + psrlq mm1,23 + paddq mm7,[40+esp] + pxor mm3,mm1 + psllq mm4,4 + pxor mm3,mm4 + movq mm4,[8+esp] + paddq mm3,mm7 + movq mm5,mm0 + psrlq mm5,28 + paddq mm4,mm3 + movq mm6,mm0 + movq mm7,mm5 + psllq mm6,25 + movq mm1,[56+esp] + psrlq mm5,6 + pxor mm7,mm6 + psllq mm6,5 + pxor mm7,mm5 + pxor mm0,mm1 + psrlq mm5,5 + pxor mm7,mm6 + pand mm2,mm0 + psllq mm6,6 + pxor mm7,mm5 + pxor mm2,mm1 + pxor mm6,mm7 + movq mm5,[16+esp] + paddq mm2,mm6 + movq mm6,[24+esp] + movq mm1,mm4 + movq mm7,[edx-104] + pxor mm5,mm6 + psrlq mm1,14 + movq [8+esp],mm4 + pand mm5,mm4 + psllq mm4,23 + paddq mm2,mm3 + movq mm3,mm1 + psrlq mm1,4 + pxor mm5,mm6 + pxor mm3,mm4 + psllq mm4,23 + pxor mm3,mm1 + movq [40+esp],mm2 + paddq mm7,mm5 + pxor mm3,mm4 + psrlq mm1,23 + paddq mm7,[32+esp] + pxor mm3,mm1 + psllq mm4,4 + pxor mm3,mm4 + movq mm4,[esp] + paddq mm3,mm7 + movq mm5,mm2 + psrlq mm5,28 + paddq mm4,mm3 + movq mm6,mm2 + movq mm7,mm5 + psllq mm6,25 + movq mm1,[48+esp] + psrlq mm5,6 + pxor mm7,mm6 + psllq mm6,5 + pxor mm7,mm5 + pxor mm2,mm1 + psrlq mm5,5 + pxor mm7,mm6 + pand mm0,mm2 + psllq mm6,6 + pxor mm7,mm5 + pxor mm0,mm1 + pxor mm6,mm7 + movq mm5,[8+esp] + paddq mm0,mm6 + movq mm6,[16+esp] + movdqa [edx-112],xmm4 + movdqa xmm5,[32+ebp] + movdqa xmm4,xmm3 + movdqu xmm3,[48+ebx] + paddq xmm5,xmm2 +db 102,15,56,0,220 + movq mm1,mm4 + movq mm7,[edx-96] + pxor mm5,mm6 + psrlq mm1,14 + movq [esp],mm4 + pand mm5,mm4 + psllq mm4,23 + paddq mm0,mm3 + movq mm3,mm1 + psrlq mm1,4 + pxor mm5,mm6 + pxor mm3,mm4 + psllq mm4,23 + pxor mm3,mm1 + movq [32+esp],mm0 + paddq mm7,mm5 + pxor mm3,mm4 + psrlq mm1,23 + paddq mm7,[24+esp] + pxor mm3,mm1 + psllq mm4,4 + pxor mm3,mm4 + movq mm4,[56+esp] + paddq mm3,mm7 + movq mm5,mm0 + psrlq mm5,28 + paddq mm4,mm3 + movq mm6,mm0 + movq mm7,mm5 + psllq mm6,25 + movq mm1,[40+esp] + psrlq mm5,6 + pxor mm7,mm6 + psllq mm6,5 + pxor mm7,mm5 + pxor mm0,mm1 + psrlq mm5,5 + pxor mm7,mm6 + pand mm2,mm0 + psllq mm6,6 + pxor mm7,mm5 + pxor mm2,mm1 + pxor mm6,mm7 + movq mm5,[esp] + paddq mm2,mm6 + movq mm6,[8+esp] + movq mm1,mm4 + movq mm7,[edx-88] + pxor mm5,mm6 + psrlq mm1,14 + movq [56+esp],mm4 + pand mm5,mm4 + psllq mm4,23 + paddq mm2,mm3 + movq mm3,mm1 + psrlq mm1,4 + pxor mm5,mm6 + pxor mm3,mm4 + psllq mm4,23 + pxor mm3,mm1 + movq [24+esp],mm2 + paddq mm7,mm5 + pxor mm3,mm4 + psrlq mm1,23 + paddq mm7,[16+esp] + pxor mm3,mm1 + psllq mm4,4 + pxor mm3,mm4 + movq mm4,[48+esp] + paddq mm3,mm7 + movq mm5,mm2 + psrlq mm5,28 + paddq mm4,mm3 + movq mm6,mm2 + movq mm7,mm5 + psllq mm6,25 + movq mm1,[32+esp] + psrlq mm5,6 + pxor mm7,mm6 + psllq mm6,5 + pxor mm7,mm5 + pxor mm2,mm1 + psrlq mm5,5 + pxor mm7,mm6 + pand mm0,mm2 + psllq mm6,6 + pxor mm7,mm5 + pxor mm0,mm1 + pxor mm6,mm7 + movq mm5,[56+esp] + paddq mm0,mm6 + movq mm6,[esp] + movdqa [edx-96],xmm5 + movdqa xmm6,[48+ebp] + movdqa xmm5,xmm4 + movdqu xmm4,[64+ebx] + paddq xmm6,xmm3 +db 102,15,56,0,229 + movq mm1,mm4 + movq mm7,[edx-80] + pxor mm5,mm6 + psrlq mm1,14 + movq [48+esp],mm4 + pand mm5,mm4 + psllq mm4,23 + paddq mm0,mm3 + movq mm3,mm1 + psrlq mm1,4 + pxor mm5,mm6 + pxor mm3,mm4 + psllq mm4,23 + pxor mm3,mm1 + movq [16+esp],mm0 + paddq mm7,mm5 + pxor mm3,mm4 + psrlq mm1,23 + paddq mm7,[8+esp] + pxor mm3,mm1 + psllq mm4,4 + pxor mm3,mm4 + movq mm4,[40+esp] + paddq mm3,mm7 + movq mm5,mm0 + psrlq mm5,28 + paddq mm4,mm3 + movq mm6,mm0 + movq mm7,mm5 + psllq mm6,25 + movq mm1,[24+esp] + psrlq mm5,6 + pxor mm7,mm6 + psllq mm6,5 + pxor mm7,mm5 + pxor mm0,mm1 + psrlq mm5,5 + pxor mm7,mm6 + pand mm2,mm0 + psllq mm6,6 + pxor mm7,mm5 + pxor mm2,mm1 + pxor mm6,mm7 + movq mm5,[48+esp] + paddq mm2,mm6 + movq mm6,[56+esp] + movq mm1,mm4 + movq mm7,[edx-72] + pxor mm5,mm6 + psrlq mm1,14 + movq [40+esp],mm4 + pand mm5,mm4 + psllq mm4,23 + paddq mm2,mm3 + movq mm3,mm1 + psrlq mm1,4 + pxor mm5,mm6 + pxor mm3,mm4 + psllq mm4,23 + pxor mm3,mm1 + movq [8+esp],mm2 + paddq mm7,mm5 + pxor mm3,mm4 + psrlq mm1,23 + paddq mm7,[esp] + pxor mm3,mm1 + psllq mm4,4 + pxor mm3,mm4 + movq mm4,[32+esp] + paddq mm3,mm7 + movq mm5,mm2 + psrlq mm5,28 + paddq mm4,mm3 + movq mm6,mm2 + movq mm7,mm5 + psllq mm6,25 + movq mm1,[16+esp] + psrlq mm5,6 + pxor mm7,mm6 + psllq mm6,5 + pxor mm7,mm5 + pxor mm2,mm1 + psrlq mm5,5 + pxor mm7,mm6 + pand mm0,mm2 + psllq mm6,6 + pxor mm7,mm5 + pxor mm0,mm1 + pxor mm6,mm7 + movq mm5,[40+esp] + paddq mm0,mm6 + movq mm6,[48+esp] + movdqa [edx-80],xmm6 + movdqa xmm7,[64+ebp] + movdqa xmm6,xmm5 + movdqu xmm5,[80+ebx] + paddq xmm7,xmm4 +db 102,15,56,0,238 + movq mm1,mm4 + movq mm7,[edx-64] + pxor mm5,mm6 + psrlq mm1,14 + movq [32+esp],mm4 + pand mm5,mm4 + psllq mm4,23 + paddq mm0,mm3 + movq mm3,mm1 + psrlq mm1,4 + pxor mm5,mm6 + pxor mm3,mm4 + psllq mm4,23 + pxor mm3,mm1 + movq [esp],mm0 + paddq mm7,mm5 + pxor mm3,mm4 + psrlq mm1,23 + paddq mm7,[56+esp] + pxor mm3,mm1 + psllq mm4,4 + pxor mm3,mm4 + movq mm4,[24+esp] + paddq mm3,mm7 + movq mm5,mm0 + psrlq mm5,28 + paddq mm4,mm3 + movq mm6,mm0 + movq mm7,mm5 + psllq mm6,25 + movq mm1,[8+esp] + psrlq mm5,6 + pxor mm7,mm6 + psllq mm6,5 + pxor mm7,mm5 + pxor mm0,mm1 + psrlq mm5,5 + pxor mm7,mm6 + pand mm2,mm0 + psllq mm6,6 + pxor mm7,mm5 + pxor mm2,mm1 + pxor mm6,mm7 + movq mm5,[32+esp] + paddq mm2,mm6 + movq mm6,[40+esp] + movq mm1,mm4 + movq mm7,[edx-56] + pxor mm5,mm6 + psrlq mm1,14 + movq [24+esp],mm4 + pand mm5,mm4 + psllq mm4,23 + paddq mm2,mm3 + movq mm3,mm1 + psrlq mm1,4 + pxor mm5,mm6 + pxor mm3,mm4 + psllq mm4,23 + pxor mm3,mm1 + movq [56+esp],mm2 + paddq mm7,mm5 + pxor mm3,mm4 + psrlq mm1,23 + paddq mm7,[48+esp] + pxor mm3,mm1 + psllq mm4,4 + pxor mm3,mm4 + movq mm4,[16+esp] + paddq mm3,mm7 + movq mm5,mm2 + psrlq mm5,28 + paddq mm4,mm3 + movq mm6,mm2 + movq mm7,mm5 + psllq mm6,25 + movq mm1,[esp] + psrlq mm5,6 + pxor mm7,mm6 + psllq mm6,5 + pxor mm7,mm5 + pxor mm2,mm1 + psrlq mm5,5 + pxor mm7,mm6 + pand mm0,mm2 + psllq mm6,6 + pxor mm7,mm5 + pxor mm0,mm1 + pxor mm6,mm7 + movq mm5,[24+esp] + paddq mm0,mm6 + movq mm6,[32+esp] + movdqa [edx-64],xmm7 + movdqa [edx],xmm0 + movdqa xmm0,[80+ebp] + movdqa xmm7,xmm6 + movdqu xmm6,[96+ebx] + paddq xmm0,xmm5 +db 102,15,56,0,247 + movq mm1,mm4 + movq mm7,[edx-48] + pxor mm5,mm6 + psrlq mm1,14 + movq [16+esp],mm4 + pand mm5,mm4 + psllq mm4,23 + paddq mm0,mm3 + movq mm3,mm1 + psrlq mm1,4 + pxor mm5,mm6 + pxor mm3,mm4 + psllq mm4,23 + pxor mm3,mm1 + movq [48+esp],mm0 + paddq mm7,mm5 + pxor mm3,mm4 + psrlq mm1,23 + paddq mm7,[40+esp] + pxor mm3,mm1 + psllq mm4,4 + pxor mm3,mm4 + movq mm4,[8+esp] + paddq mm3,mm7 + movq mm5,mm0 + psrlq mm5,28 + paddq mm4,mm3 + movq mm6,mm0 + movq mm7,mm5 + psllq mm6,25 + movq mm1,[56+esp] + psrlq mm5,6 + pxor mm7,mm6 + psllq mm6,5 + pxor mm7,mm5 + pxor mm0,mm1 + psrlq mm5,5 + pxor mm7,mm6 + pand mm2,mm0 + psllq mm6,6 + pxor mm7,mm5 + pxor mm2,mm1 + pxor mm6,mm7 + movq mm5,[16+esp] + paddq mm2,mm6 + movq mm6,[24+esp] + movq mm1,mm4 + movq mm7,[edx-40] + pxor mm5,mm6 + psrlq mm1,14 + movq [8+esp],mm4 + pand mm5,mm4 + psllq mm4,23 + paddq mm2,mm3 + movq mm3,mm1 + psrlq mm1,4 + pxor mm5,mm6 + pxor mm3,mm4 + psllq mm4,23 + pxor mm3,mm1 + movq [40+esp],mm2 + paddq mm7,mm5 + pxor mm3,mm4 + psrlq mm1,23 + paddq mm7,[32+esp] + pxor mm3,mm1 + psllq mm4,4 + pxor mm3,mm4 + movq mm4,[esp] + paddq mm3,mm7 + movq mm5,mm2 + psrlq mm5,28 + paddq mm4,mm3 + movq mm6,mm2 + movq mm7,mm5 + psllq mm6,25 + movq mm1,[48+esp] + psrlq mm5,6 + pxor mm7,mm6 + psllq mm6,5 + pxor mm7,mm5 + pxor mm2,mm1 + psrlq mm5,5 + pxor mm7,mm6 + pand mm0,mm2 + psllq mm6,6 + pxor mm7,mm5 + pxor mm0,mm1 + pxor mm6,mm7 + movq mm5,[8+esp] + paddq mm0,mm6 + movq mm6,[16+esp] + movdqa [edx-48],xmm0 + movdqa [16+edx],xmm1 + movdqa xmm1,[96+ebp] + movdqa xmm0,xmm7 + movdqu xmm7,[112+ebx] + paddq xmm1,xmm6 +db 102,15,56,0,248 + movq mm1,mm4 + movq mm7,[edx-32] + pxor mm5,mm6 + psrlq mm1,14 + movq [esp],mm4 + pand mm5,mm4 + psllq mm4,23 + paddq mm0,mm3 + movq mm3,mm1 + psrlq mm1,4 + pxor mm5,mm6 + pxor mm3,mm4 + psllq mm4,23 + pxor mm3,mm1 + movq [32+esp],mm0 + paddq mm7,mm5 + pxor mm3,mm4 + psrlq mm1,23 + paddq mm7,[24+esp] + pxor mm3,mm1 + psllq mm4,4 + pxor mm3,mm4 + movq mm4,[56+esp] + paddq mm3,mm7 + movq mm5,mm0 + psrlq mm5,28 + paddq mm4,mm3 + movq mm6,mm0 + movq mm7,mm5 + psllq mm6,25 + movq mm1,[40+esp] + psrlq mm5,6 + pxor mm7,mm6 + psllq mm6,5 + pxor mm7,mm5 + pxor mm0,mm1 + psrlq mm5,5 + pxor mm7,mm6 + pand mm2,mm0 + psllq mm6,6 + pxor mm7,mm5 + pxor mm2,mm1 + pxor mm6,mm7 + movq mm5,[esp] + paddq mm2,mm6 + movq mm6,[8+esp] + movq mm1,mm4 + movq mm7,[edx-24] + pxor mm5,mm6 + psrlq mm1,14 + movq [56+esp],mm4 + pand mm5,mm4 + psllq mm4,23 + paddq mm2,mm3 + movq mm3,mm1 + psrlq mm1,4 + pxor mm5,mm6 + pxor mm3,mm4 + psllq mm4,23 + pxor mm3,mm1 + movq [24+esp],mm2 + paddq mm7,mm5 + pxor mm3,mm4 + psrlq mm1,23 + paddq mm7,[16+esp] + pxor mm3,mm1 + psllq mm4,4 + pxor mm3,mm4 + movq mm4,[48+esp] + paddq mm3,mm7 + movq mm5,mm2 + psrlq mm5,28 + paddq mm4,mm3 + movq mm6,mm2 + movq mm7,mm5 + psllq mm6,25 + movq mm1,[32+esp] + psrlq mm5,6 + pxor mm7,mm6 + psllq mm6,5 + pxor mm7,mm5 + pxor mm2,mm1 + psrlq mm5,5 + pxor mm7,mm6 + pand mm0,mm2 + psllq mm6,6 + pxor mm7,mm5 + pxor mm0,mm1 + pxor mm6,mm7 + movq mm5,[56+esp] + paddq mm0,mm6 + movq mm6,[esp] + movdqa [edx-32],xmm1 + movdqa [32+edx],xmm2 + movdqa xmm2,[112+ebp] + movdqa xmm0,[edx] + paddq xmm2,xmm7 + movq mm1,mm4 + movq mm7,[edx-16] + pxor mm5,mm6 + psrlq mm1,14 + movq [48+esp],mm4 + pand mm5,mm4 + psllq mm4,23 + paddq mm0,mm3 + movq mm3,mm1 + psrlq mm1,4 + pxor mm5,mm6 + pxor mm3,mm4 + psllq mm4,23 + pxor mm3,mm1 + movq [16+esp],mm0 + paddq mm7,mm5 + pxor mm3,mm4 + psrlq mm1,23 + paddq mm7,[8+esp] + pxor mm3,mm1 + psllq mm4,4 + pxor mm3,mm4 + movq mm4,[40+esp] + paddq mm3,mm7 + movq mm5,mm0 + psrlq mm5,28 + paddq mm4,mm3 + movq mm6,mm0 + movq mm7,mm5 + psllq mm6,25 + movq mm1,[24+esp] + psrlq mm5,6 + pxor mm7,mm6 + psllq mm6,5 + pxor mm7,mm5 + pxor mm0,mm1 + psrlq mm5,5 + pxor mm7,mm6 + pand mm2,mm0 + psllq mm6,6 + pxor mm7,mm5 + pxor mm2,mm1 + pxor mm6,mm7 + movq mm5,[48+esp] + paddq mm2,mm6 + movq mm6,[56+esp] + movq mm1,mm4 + movq mm7,[edx-8] + pxor mm5,mm6 + psrlq mm1,14 + movq [40+esp],mm4 + pand mm5,mm4 + psllq mm4,23 + paddq mm2,mm3 + movq mm3,mm1 + psrlq mm1,4 + pxor mm5,mm6 + pxor mm3,mm4 + psllq mm4,23 + pxor mm3,mm1 + movq [8+esp],mm2 + paddq mm7,mm5 + pxor mm3,mm4 + psrlq mm1,23 + paddq mm7,[esp] + pxor mm3,mm1 + psllq mm4,4 + pxor mm3,mm4 + movq mm4,[32+esp] + paddq mm3,mm7 + movq mm5,mm2 + psrlq mm5,28 + paddq mm4,mm3 + movq mm6,mm2 + movq mm7,mm5 + psllq mm6,25 + movq mm1,[16+esp] + psrlq mm5,6 + pxor mm7,mm6 + psllq mm6,5 + pxor mm7,mm5 + pxor mm2,mm1 + psrlq mm5,5 + pxor mm7,mm6 + pand mm0,mm2 + psllq mm6,6 + pxor mm7,mm5 + pxor mm0,mm1 + pxor mm6,mm7 + movq mm5,[40+esp] + paddq mm0,mm6 + movq mm6,[48+esp] + movdqa [edx-16],xmm2 + movq mm1,[8+esp] + paddq mm0,mm3 + movq mm3,[24+esp] + movq mm7,[56+esp] + pxor mm2,mm1 + paddq mm0,[esi] + paddq mm1,[8+esi] + paddq mm2,[16+esi] + paddq mm3,[24+esi] + paddq mm4,[32+esi] + paddq mm5,[40+esi] + paddq mm6,[48+esi] + paddq mm7,[56+esi] + movq [esi],mm0 + movq [8+esi],mm1 + movq [16+esi],mm2 + movq [24+esi],mm3 + movq [32+esi],mm4 + movq [40+esi],mm5 + movq [48+esi],mm6 + movq [56+esi],mm7 + cmp edi,eax + jb NEAR L$007loop_ssse3 + mov esp,DWORD [76+edx] + emms + pop edi + pop esi + pop ebx + pop ebp + ret align 16 L$002loop_x86: mov eax,DWORD [edi] @@ -144,7 +2408,7 @@ L$002loop_x86: mov ecx,16 dd 2784229001 align 16 -L$00300_15_x86: +L$00900_15_x86: mov ecx,DWORD [40+esp] mov edx,DWORD [44+esp] mov esi,ecx @@ -251,9 +2515,9 @@ L$00300_15_x86: sub esp,8 lea ebp,[8+ebp] cmp dl,148 - jne NEAR L$00300_15_x86 + jne NEAR L$00900_15_x86 align 16 -L$00416_79_x86: +L$01016_79_x86: mov ecx,DWORD [312+esp] mov edx,DWORD [316+esp] mov esi,ecx @@ -426,7 +2690,7 @@ L$00416_79_x86: sub esp,8 lea ebp,[8+ebp] cmp dl,23 - jne NEAR L$00416_79_x86 + jne NEAR L$01016_79_x86 mov esi,DWORD [840+esp] mov edi,DWORD [844+esp] mov eax,DWORD [esi] @@ -576,6 +2840,8 @@ db 110,115,102,111,114,109,32,102,111,114,32,120,56,54,44,32 db 67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97 db 112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103 db 62,0 +segment .bss +common _OPENSSL_ia32cap_P 16 %else ; Work around https://bugzilla.nasm.us/show_bug.cgi?id=3392738 ret diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/x86-mont-windows.windows.x86.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/x86-mont-windows.windows.x86.S index 20072abd..c6eba63c 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/x86-mont-windows.windows.x86.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/x86-mont-windows.windows.x86.S @@ -15,6 +15,7 @@ section .text code align=64 %else section .text code %endif +;extern _OPENSSL_ia32cap_P global _bn_mul_mont align 16 _bn_mul_mont: @@ -71,6 +72,123 @@ L$002page_walk_done: mov DWORD [20+esp],esi lea ebx,[edi-3] mov DWORD [24+esp],edx + lea eax,[_OPENSSL_ia32cap_P] + bt DWORD [eax],26 + jnc NEAR L$003non_sse2 + mov eax,-1 + movd mm7,eax + mov esi,DWORD [8+esp] + mov edi,DWORD [12+esp] + mov ebp,DWORD [16+esp] + xor edx,edx + xor ecx,ecx + movd mm4,DWORD [edi] + movd mm5,DWORD [esi] + movd mm3,DWORD [ebp] + pmuludq mm5,mm4 + movq mm2,mm5 + movq mm0,mm5 + pand mm0,mm7 + pmuludq mm5,[20+esp] + pmuludq mm3,mm5 + paddq mm3,mm0 + movd mm1,DWORD [4+ebp] + movd mm0,DWORD [4+esi] + psrlq mm2,32 + psrlq mm3,32 + inc ecx +align 16 +L$0041st: + pmuludq mm0,mm4 + pmuludq mm1,mm5 + paddq mm2,mm0 + paddq mm3,mm1 + movq mm0,mm2 + pand mm0,mm7 + movd mm1,DWORD [4+ecx*4+ebp] + paddq mm3,mm0 + movd mm0,DWORD [4+ecx*4+esi] + psrlq mm2,32 + movd DWORD [28+ecx*4+esp],mm3 + psrlq mm3,32 + lea ecx,[1+ecx] + cmp ecx,ebx + jl NEAR L$0041st + pmuludq mm0,mm4 + pmuludq mm1,mm5 + paddq mm2,mm0 + paddq mm3,mm1 + movq mm0,mm2 + pand mm0,mm7 + paddq mm3,mm0 + movd DWORD [28+ecx*4+esp],mm3 + psrlq mm2,32 + psrlq mm3,32 + paddq mm3,mm2 + movq [32+ebx*4+esp],mm3 + inc edx +L$005outer: + xor ecx,ecx + movd mm4,DWORD [edx*4+edi] + movd mm5,DWORD [esi] + movd mm6,DWORD [32+esp] + movd mm3,DWORD [ebp] + pmuludq mm5,mm4 + paddq mm5,mm6 + movq mm0,mm5 + movq mm2,mm5 + pand mm0,mm7 + pmuludq mm5,[20+esp] + pmuludq mm3,mm5 + paddq mm3,mm0 + movd mm6,DWORD [36+esp] + movd mm1,DWORD [4+ebp] + movd mm0,DWORD [4+esi] + psrlq mm2,32 + psrlq mm3,32 + paddq mm2,mm6 + inc ecx + dec ebx +L$006inner: + pmuludq mm0,mm4 + pmuludq mm1,mm5 + paddq mm2,mm0 + paddq mm3,mm1 + movq mm0,mm2 + movd mm6,DWORD [36+ecx*4+esp] + pand mm0,mm7 + movd mm1,DWORD [4+ecx*4+ebp] + paddq mm3,mm0 + movd mm0,DWORD [4+ecx*4+esi] + psrlq mm2,32 + movd DWORD [28+ecx*4+esp],mm3 + psrlq mm3,32 + paddq mm2,mm6 + dec ebx + lea ecx,[1+ecx] + jnz NEAR L$006inner + mov ebx,ecx + pmuludq mm0,mm4 + pmuludq mm1,mm5 + paddq mm2,mm0 + paddq mm3,mm1 + movq mm0,mm2 + pand mm0,mm7 + paddq mm3,mm0 + movd DWORD [28+ecx*4+esp],mm3 + psrlq mm2,32 + psrlq mm3,32 + movd mm6,DWORD [36+ebx*4+esp] + paddq mm3,mm2 + paddq mm3,mm6 + movq [32+ebx*4+esp],mm3 + lea edx,[1+edx] + cmp edx,ebx + jle NEAR L$005outer + emms + jmp NEAR L$007common_tail +align 16 +L$003non_sse2: mov esi,DWORD [8+esp] lea ebp,[1+ebx] mov edi,DWORD [12+esp] @@ -81,12 +199,12 @@ L$002page_walk_done: lea eax,[4+ebx*4+edi] or ebp,edx mov edi,DWORD [edi] - jz NEAR L$003bn_sqr_mont + jz NEAR L$008bn_sqr_mont mov DWORD [28+esp],eax mov eax,DWORD [esi] xor edx,edx align 16 -L$004mull: +L$009mull: mov ebp,edx mul edi add ebp,eax @@ -95,7 +213,7 @@ L$004mull: mov eax,DWORD [ecx*4+esi] cmp ecx,ebx mov DWORD [28+ecx*4+esp],ebp - jl NEAR L$004mull + jl NEAR L$009mull mov ebp,edx mul edi mov edi,DWORD [20+esp] @@ -113,9 +231,9 @@ L$004mull: mov eax,DWORD [4+esi] adc edx,0 inc ecx - jmp NEAR L$0052ndmadd + jmp NEAR L$0102ndmadd align 16 -L$0061stmadd: +L$0111stmadd: mov ebp,edx mul edi add ebp,DWORD [32+ecx*4+esp] @@ -126,7 +244,7 @@ L$0061stmadd: adc edx,0 cmp ecx,ebx mov DWORD [28+ecx*4+esp],ebp - jl NEAR L$0061stmadd + jl NEAR L$0111stmadd mov ebp,edx mul edi add eax,DWORD [32+ebx*4+esp] @@ -149,7 +267,7 @@ L$0061stmadd: adc edx,0 mov ecx,1 align 16 -L$0052ndmadd: +L$0102ndmadd: mov ebp,edx mul edi add ebp,DWORD [32+ecx*4+esp] @@ -160,7 +278,7 @@ L$0052ndmadd: adc edx,0 cmp ecx,ebx mov DWORD [24+ecx*4+esp],ebp - jl NEAR L$0052ndmadd + jl NEAR L$0102ndmadd mov ebp,edx mul edi add ebp,DWORD [32+ebx*4+esp] @@ -183,9 +301,9 @@ L$0052ndmadd: xor ecx,ecx xor edx,edx mov eax,DWORD [esi] - jmp NEAR L$0061stmadd + jmp NEAR L$0111stmadd align 16 -L$003bn_sqr_mont: +L$008bn_sqr_mont: mov DWORD [esp],ebx mov DWORD [12+esp],ecx mov eax,edi @@ -196,7 +314,7 @@ L$003bn_sqr_mont: and ebx,1 inc ecx align 16 -L$008sqr: +L$012sqr: mov eax,DWORD [ecx*4+esi] mov ebp,edx mul edi @@ -208,7 +326,7 @@ L$008sqr: cmp ecx,DWORD [esp] mov ebx,eax mov DWORD [28+ecx*4+esp],ebp - jl NEAR L$008sqr + jl NEAR L$012sqr mov eax,DWORD [ecx*4+esi] mov ebp,edx mul edi @@ -232,7 +350,7 @@ L$008sqr: mov eax,DWORD [4+esi] mov ecx,1 align 16 -L$0093rdmadd: +L$0133rdmadd: mov ebp,edx mul edi add ebp,DWORD [32+ecx*4+esp] @@ -251,7 +369,7 @@ L$0093rdmadd: adc edx,0 cmp ecx,ebx mov DWORD [24+ecx*4+esp],ebp - jl NEAR L$0093rdmadd + jl NEAR L$0133rdmadd mov ebp,edx mul edi add ebp,DWORD [32+ebx*4+esp] @@ -279,12 +397,12 @@ L$0093rdmadd: xor ebp,ebp cmp ecx,ebx lea ecx,[1+ecx] - je NEAR L$010sqrlast + je NEAR L$014sqrlast mov ebx,edx shr edx,1 and ebx,1 align 16 -L$011sqradd: +L$015sqradd: mov eax,DWORD [ecx*4+esi] mov ebp,edx mul edi @@ -300,13 +418,13 @@ L$011sqradd: cmp ecx,DWORD [esp] mov DWORD [28+ecx*4+esp],ebp mov ebx,eax - jle NEAR L$011sqradd + jle NEAR L$015sqradd mov ebp,edx add edx,edx shr ebp,31 add edx,ebx adc ebp,0 -L$010sqrlast: +L$014sqrlast: mov edi,DWORD [20+esp] mov esi,DWORD [16+esp] imul edi,DWORD [32+esp] @@ -321,7 +439,7 @@ L$010sqrlast: adc edx,0 mov ecx,1 mov eax,DWORD [4+esi] - jmp NEAR L$0093rdmadd + jmp NEAR L$0133rdmadd align 16 L$007common_tail: mov ebp,DWORD [16+esp] @@ -331,19 +449,19 @@ L$007common_tail: mov ecx,ebx xor edx,edx align 16 -L$012sub: +L$016sub: sbb eax,DWORD [edx*4+ebp] mov DWORD [edx*4+edi],eax dec ecx mov eax,DWORD [4+edx*4+esi] lea edx,[1+edx] - jge NEAR L$012sub + jge NEAR L$016sub sbb eax,0 mov edx,-1 xor edx,eax - jmp NEAR L$013copy + jmp NEAR L$017copy align 16 -L$013copy: +L$017copy: mov esi,DWORD [32+ebx*4+esp] mov ebp,DWORD [ebx*4+edi] mov DWORD [32+ebx*4+esp],ecx @@ -352,7 +470,7 @@ L$013copy: or ebp,esi mov DWORD [ebx*4+edi],ebp dec ebx - jge NEAR L$013copy + jge NEAR L$017copy mov esp,DWORD [24+esp] mov eax,1 L$000just_leave: @@ -366,6 +484,8 @@ db 112,108,105,99,97,116,105,111,110,32,102,111,114,32,120,56 db 54,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121 db 32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46 db 111,114,103,62,0 +segment .bss +common _OPENSSL_ia32cap_P 16 %else ; Work around https://bugzilla.nasm.us/show_bug.cgi?id=3392738 ret diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/x86_64-mont-linux.linux.x86_64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/x86_64-mont-linux.linux.x86_64.S index 3c5324e6..22565fe1 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/x86_64-mont-linux.linux.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/x86_64-mont-linux.linux.x86_64.S @@ -8,33 +8,16 @@ #if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64) && defined(__ELF__) .text -.extern OPENSSL_ia32cap_P -.hidden OPENSSL_ia32cap_P - -.globl bn_mul_mont -.hidden bn_mul_mont -.type bn_mul_mont,@function +.globl bn_mul_mont_nohw +.hidden bn_mul_mont_nohw +.type bn_mul_mont_nohw,@function .align 16 -bn_mul_mont: +bn_mul_mont_nohw: .cfi_startproc _CET_ENDBR movl %r9d,%r9d movq %rsp,%rax .cfi_def_cfa_register %rax - testl $3,%r9d - jnz .Lmul_enter - cmpl $8,%r9d - jb .Lmul_enter - leaq OPENSSL_ia32cap_P(%rip),%r11 - movl 8(%r11),%r11d - cmpq %rsi,%rdx - jne .Lmul4x_enter - testl $7,%r9d - jz .Lsqr8x_enter - jmp .Lmul4x_enter - -.align 16 -.Lmul_enter: pushq %rbx .cfi_offset %rbx,-16 pushq %rbp @@ -266,18 +249,17 @@ _CET_ENDBR .Lmul_epilogue: ret .cfi_endproc -.size bn_mul_mont,.-bn_mul_mont +.size bn_mul_mont_nohw,.-bn_mul_mont_nohw +.globl bn_mul4x_mont +.hidden bn_mul4x_mont .type bn_mul4x_mont,@function .align 16 bn_mul4x_mont: .cfi_startproc +_CET_ENDBR movl %r9d,%r9d movq %rsp,%rax .cfi_def_cfa_register %rax -.Lmul4x_enter: - andl $0x80100,%r11d - cmpl $0x80100,%r11d - je .Lmulx4x_enter pushq %rbx .cfi_offset %rbx,-16 pushq %rbp @@ -706,13 +688,16 @@ bn_mul4x_mont: .extern bn_sqr8x_internal .hidden bn_sqr8x_internal +.globl bn_sqr8x_mont +.hidden bn_sqr8x_mont .type bn_sqr8x_mont,@function .align 32 bn_sqr8x_mont: .cfi_startproc +_CET_ENDBR + movl %r9d,%r9d movq %rsp,%rax .cfi_def_cfa_register %rax -.Lsqr8x_enter: pushq %rbx .cfi_offset %rbx,-16 pushq %rbp @@ -787,11 +772,8 @@ bn_sqr8x_mont: pxor %xmm0,%xmm0 .byte 102,72,15,110,207 .byte 102,73,15,110,218 - leaq OPENSSL_ia32cap_P(%rip),%rax - movl 8(%rax),%eax - andl $0x80100,%eax - cmpl $0x80100,%eax - jne .Lsqr8x_nox + testq %rdx,%rdx + jz .Lsqr8x_nox call bn_sqrx8x_internal @@ -894,13 +876,15 @@ bn_sqr8x_mont: ret .cfi_endproc .size bn_sqr8x_mont,.-bn_sqr8x_mont +.globl bn_mulx4x_mont +.hidden bn_mulx4x_mont .type bn_mulx4x_mont,@function .align 32 bn_mulx4x_mont: .cfi_startproc +_CET_ENDBR movq %rsp,%rax .cfi_def_cfa_register %rax -.Lmulx4x_enter: pushq %rbx .cfi_offset %rbx,-16 pushq %rbp diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/x86_64-mont-mac.mac.x86_64.S b/Sources/CCryptoBoringSSL/crypto/fipsmodule/x86_64-mont-mac.mac.x86_64.S index 8adc027e..eb39df37 100644 --- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/x86_64-mont-mac.mac.x86_64.S +++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/x86_64-mont-mac.mac.x86_64.S @@ -8,32 +8,16 @@ #if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64) && defined(__APPLE__) .text - - -.globl _bn_mul_mont -.private_extern _bn_mul_mont +.globl _bn_mul_mont_nohw +.private_extern _bn_mul_mont_nohw .p2align 4 -_bn_mul_mont: +_bn_mul_mont_nohw: _CET_ENDBR movl %r9d,%r9d movq %rsp,%rax - testl $3,%r9d - jnz L$mul_enter - cmpl $8,%r9d - jb L$mul_enter - leaq _OPENSSL_ia32cap_P(%rip),%r11 - movl 8(%r11),%r11d - cmpq %rsi,%rdx - jne L$mul4x_enter - testl $7,%r9d - jz L$sqr8x_enter - jmp L$mul4x_enter - -.p2align 4 -L$mul_enter: pushq %rbx pushq %rbp @@ -266,17 +250,16 @@ L$mul_epilogue: ret +.globl _bn_mul4x_mont +.private_extern _bn_mul4x_mont .p2align 4 -bn_mul4x_mont: +_bn_mul4x_mont: +_CET_ENDBR movl %r9d,%r9d movq %rsp,%rax -L$mul4x_enter: - andl $0x80100,%r11d - cmpl $0x80100,%r11d - je L$mulx4x_enter pushq %rbx pushq %rbp @@ -703,13 +686,16 @@ L$mul4x_epilogue: +.globl _bn_sqr8x_mont +.private_extern _bn_sqr8x_mont .p2align 5 -bn_sqr8x_mont: +_bn_sqr8x_mont: +_CET_ENDBR + movl %r9d,%r9d movq %rsp,%rax -L$sqr8x_enter: pushq %rbx pushq %rbp @@ -784,11 +770,8 @@ L$sqr8x_body: pxor %xmm0,%xmm0 .byte 102,72,15,110,207 .byte 102,73,15,110,218 - leaq _OPENSSL_ia32cap_P(%rip),%rax - movl 8(%rax),%eax - andl $0x80100,%eax - cmpl $0x80100,%eax - jne L$sqr8x_nox + testq %rdx,%rdx + jz L$sqr8x_nox call _bn_sqrx8x_internal @@ -891,13 +874,15 @@ L$sqr8x_epilogue: ret +.globl _bn_mulx4x_mont +.private_extern _bn_mulx4x_mont .p2align 5 -bn_mulx4x_mont: +_bn_mulx4x_mont: +_CET_ENDBR movq %rsp,%rax -L$mulx4x_enter: pushq %rbx pushq %rbp diff --git a/Sources/CCryptoBoringSSL/crypto/hpke/hpke.c b/Sources/CCryptoBoringSSL/crypto/hpke/hpke.c index caf09f19..67ff51bb 100644 --- a/Sources/CCryptoBoringSSL/crypto/hpke/hpke.c +++ b/Sources/CCryptoBoringSSL/crypto/hpke/hpke.c @@ -355,6 +355,8 @@ int EVP_HPKE_KEY_copy(EVP_HPKE_KEY *dst, const EVP_HPKE_KEY *src) { void EVP_HPKE_KEY_move(EVP_HPKE_KEY *out, EVP_HPKE_KEY *in) { EVP_HPKE_KEY_cleanup(out); // For now, |EVP_HPKE_KEY| is trivially movable. + // Note that Rust may move this structure. See + // bssl-crypto/src/scoped.rs:EvpHpkeKey. OPENSSL_memcpy(out, in, sizeof(EVP_HPKE_KEY)); EVP_HPKE_KEY_zero(in); } diff --git a/Sources/CCryptoBoringSSL/crypto/internal.h b/Sources/CCryptoBoringSSL/crypto/internal.h index f8c64f90..c1882f26 100644 --- a/Sources/CCryptoBoringSSL/crypto/internal.h +++ b/Sources/CCryptoBoringSSL/crypto/internal.h @@ -235,14 +235,30 @@ typedef __uint128_t uint128_t; #define OPENSSL_FALLTHROUGH #endif -// For convenience in testing 64-bit generic code, we allow disabling SSE2 -// intrinsics via |OPENSSL_NO_SSE2_FOR_TESTING|. x86_64 always has SSE2 -// available, so we would otherwise need to test such code on a non-x86_64 -// platform. -#if defined(__SSE2__) && !defined(OPENSSL_NO_SSE2_FOR_TESTING) +// GCC-like compilers indicate SSE2 with |__SSE2__|. MSVC leaves the caller to +// know that x86_64 has SSE2, and uses _M_IX86_FP to indicate SSE2 on x86. +// https://learn.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=msvc-170 +#if defined(__SSE2__) || defined(_M_AMD64) || defined(_M_X64) || \ + (defined(_M_IX86_FP) && _M_IX86_FP >= 2) #define OPENSSL_SSE2 #endif +#if defined(OPENSSL_X86) && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_SSE2) +#error \ + "x86 assembly requires SSE2. Build with -msse2 (recommended), or disable assembly optimizations with -DOPENSSL_NO_ASM." +#endif + +// For convenience in testing the fallback code, we allow disabling SSE2 +// intrinsics via |OPENSSL_NO_SSE2_FOR_TESTING|. We require SSE2 on x86 and +// x86_64, so we would otherwise need to test such code on a non-x86 platform. +// +// This does not remove the above requirement for SSE2 support with assembly +// optimizations. It only disables some intrinsics-based optimizations so that +// we can test the fallback code on CI. +#if defined(OPENSSL_SSE2) && defined(OPENSSL_NO_SSE2_FOR_TESTING) +#undef OPENSSL_SSE2 +#endif + #if defined(__GNUC__) || defined(__clang__) #define OPENSSL_ATTR_PURE __attribute__((pure)) #else @@ -255,8 +271,20 @@ typedef __uint128_t uint128_t; // should be called in between independent tests, at a point where failure from // a previous test will not impact subsequent ones. OPENSSL_EXPORT void OPENSSL_reset_malloc_counter_for_testing(void); + +// OPENSSL_disable_malloc_failures_for_testing, when malloc testing is enabled, +// disables simulated malloc failures. Calls to |OPENSSL_malloc| will not +// increment the malloc counter or synthesize failures. This may be used to skip +// simulating malloc failures in some region of code. +OPENSSL_EXPORT void OPENSSL_disable_malloc_failures_for_testing(void); + +// OPENSSL_enable_malloc_failures_for_testing, when malloc testing is enabled, +// re-enables simulated malloc failures. +OPENSSL_EXPORT void OPENSSL_enable_malloc_failures_for_testing(void); #else OPENSSL_INLINE void OPENSSL_reset_malloc_counter_for_testing(void) {} +OPENSSL_INLINE void OPENSSL_disable_malloc_failures_for_testing(void) {} +OPENSSL_INLINE void OPENSSL_enable_malloc_failures_for_testing(void) {} #endif #if defined(__has_builtin) @@ -877,14 +905,12 @@ typedef struct { #define CRYPTO_EX_DATA_CLASS_INIT_WITH_APP_DATA \ {CRYPTO_MUTEX_INIT, NULL, NULL, 0, 1} -// CRYPTO_get_ex_new_index allocates a new index for |ex_data_class| and writes -// it to |*out_index|. Each class of object should provide a wrapper function -// that uses the correct |CRYPTO_EX_DATA_CLASS|. It returns one on success and -// zero otherwise. -OPENSSL_EXPORT int CRYPTO_get_ex_new_index(CRYPTO_EX_DATA_CLASS *ex_data_class, - int *out_index, long argl, - void *argp, - CRYPTO_EX_free *free_func); +// CRYPTO_get_ex_new_index_ex allocates a new index for |ex_data_class|. Each +// class of object should provide a wrapper function that uses the correct +// |CRYPTO_EX_DATA_CLASS|. It returns the new index on success and -1 on error. +OPENSSL_EXPORT int CRYPTO_get_ex_new_index_ex( + CRYPTO_EX_DATA_CLASS *ex_data_class, long argl, void *argp, + CRYPTO_EX_free *free_func); // CRYPTO_set_ex_data sets an extra data pointer on a given object. Each class // of object should provide a wrapper function. @@ -1331,7 +1357,8 @@ OPENSSL_INLINE int boringssl_fips_break_test(const char *test) { // ECX for CPUID where EAX = 7 // // Note: the CPUID bits are pre-adjusted for the OSXSAVE bit and the YMM and XMM -// bits in XCR0, so it is not necessary to check those. +// bits in XCR0, so it is not necessary to check those. (WARNING: See caveats +// in cpu_intel.c.) // // From C, this symbol should only be accessed with |OPENSSL_get_ia32cap|. extern uint32_t OPENSSL_ia32cap_P[4]; @@ -1398,6 +1425,9 @@ OPENSSL_INLINE int CRYPTO_is_AESNI_capable(void) { #endif } +// We intentionally avoid defining a |CRYPTO_is_XSAVE_capable| function. See +// |CRYPTO_cpu_perf_is_like_silvermont|. + OPENSSL_INLINE int CRYPTO_is_AVX_capable(void) { #if defined(__AVX__) return 1; @@ -1407,19 +1437,16 @@ OPENSSL_INLINE int CRYPTO_is_AVX_capable(void) { } OPENSSL_INLINE int CRYPTO_is_RDRAND_capable(void) { - // The GCC/Clang feature name and preprocessor symbol for RDRAND are "rdrnd" - // and |__RDRND__|, respectively. -#if defined(__RDRND__) - return 1; -#else + // We intentionally do not check |__RDRND__| here. On some AMD processors, we + // will act as if the hardware is RDRAND-incapable, even it actually supports + // it. See cpu_intel.c. return (OPENSSL_get_ia32cap(1) & (1u << 30)) != 0; -#endif } // See Intel manual, volume 2A, table 3-8. OPENSSL_INLINE int CRYPTO_is_BMI1_capable(void) { -#if defined(__BMI1__) +#if defined(__BMI__) return 1; #else return (OPENSSL_get_ia32cap(2) & (1u << 3)) != 0; @@ -1452,11 +1479,51 @@ OPENSSL_INLINE int CRYPTO_is_ADX_capable(void) { // SHA-1 and SHA-256 are defined as a single extension. OPENSSL_INLINE int CRYPTO_is_x86_SHA_capable(void) { -#if defined(__SHA__) - return 1; -#else + // We should check __SHA__ here, but for now we ignore it. We've run into a + // few places where projects build with -march=goldmont, but need a build that + // does not require SHA extensions: + // + // - Some CrOS toolchain definitions are incorrect and build with + // -march=goldmont when targetting boards that are not Goldmont. b/320482539 + // tracks fixing this. + // + // - Sometimes projects build with -march=goldmont as a rough optimized + // baseline. However, Intel CPU capabilities are not strictly linear, so + // this does not quite work. Some combination of -mtune and + // -march=x86-64-v{1,2,3,4} would be a better strategy here. + // + // - QEMU versions before 8.2 do not support SHA extensions and disable it + // with a warning. Projects that target Goldmont and test on QEMU will + // break. The long-term fix is to update to 8.2. A principled short-term fix + // would be -march=goldmont -mno-sha, to reflect that the binary needs to + // run on both QEMU-8.1-Goldmont and actual-Goldmont. + // + // TODO(b/320482539): Once the CrOS toolchain is fixed, try this again. return (OPENSSL_get_ia32cap(2) & (1u << 29)) != 0; -#endif +} + +// CRYPTO_cpu_perf_is_like_silvermont returns one if, based on a heuristic, the +// CPU has Silvermont-like performance characteristics. It is often faster to +// run different codepaths on these CPUs than the available instructions would +// otherwise select. See chacha-x86_64.pl. +// +// Bonnell, Silvermont's predecessor in the Atom lineup, will also be matched by +// this. |OPENSSL_cpuid_setup| forces Knights Landing to also be matched by +// this. Goldmont (Silvermont's successor in the Atom lineup) added XSAVE so it +// isn't matched by this. Various sources indicate AMD first implemented MOVBE +// and XSAVE at the same time in Jaguar, so it seems like AMD chips will not be +// matched by this. That seems to be the case for other x86(-64) CPUs. +OPENSSL_INLINE int CRYPTO_cpu_perf_is_like_silvermont(void) { + // WARNING: This MUST NOT be used to guard the execution of the XSAVE + // instruction. This is the "hardware supports XSAVE" bit, not the OSXSAVE bit + // that indicates whether we can safely execute XSAVE. This bit may be set + // even when XSAVE is disabled (by the operating system). See the comment in + // cpu_intel.c and check how the users of this bit use it. + // + // We do not use |__XSAVE__| for static detection because the hack in + // |OPENSSL_cpuid_setup| for Knights Landing CPUs needs to override it. + int hardware_supports_xsave = (OPENSSL_get_ia32cap(1) & (1u << 26)) != 0; + return !hardware_supports_xsave && CRYPTO_is_MOVBE_capable(); } #endif // OPENSSL_X86 || OPENSSL_X86_64 diff --git a/Sources/CCryptoBoringSSL/crypto/kyber/internal.h b/Sources/CCryptoBoringSSL/crypto/kyber/internal.h index b90e9096..bb95cfe4 100644 --- a/Sources/CCryptoBoringSSL/crypto/kyber/internal.h +++ b/Sources/CCryptoBoringSSL/crypto/kyber/internal.h @@ -16,7 +16,7 @@ #define OPENSSL_HEADER_CRYPTO_KYBER_INTERNAL_H #include -#include +#include #if defined(__cplusplus) extern "C" { diff --git a/Sources/CCryptoBoringSSL/crypto/kyber/kyber.c b/Sources/CCryptoBoringSSL/crypto/kyber/kyber.c index 33e22ccd..c84c4ed8 100644 --- a/Sources/CCryptoBoringSSL/crypto/kyber/kyber.c +++ b/Sources/CCryptoBoringSSL/crypto/kyber/kyber.c @@ -12,7 +12,7 @@ * 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 diff --git a/Sources/CCryptoBoringSSL/crypto/mem.c b/Sources/CCryptoBoringSSL/crypto/mem.c index 3a92895c..5b6298c1 100644 --- a/Sources/CCryptoBoringSSL/crypto/mem.c +++ b/Sources/CCryptoBoringSSL/crypto/mem.c @@ -138,7 +138,7 @@ static CRYPTO_MUTEX malloc_failure_lock = CRYPTO_MUTEX_INIT; static uint64_t current_malloc_count = 0; static uint64_t malloc_number_to_fail = 0; static int malloc_failure_enabled = 0, break_on_malloc_fail = 0, - any_malloc_failed = 0; + any_malloc_failed = 0, disable_malloc_failures = 0; static void malloc_exit_handler(void) { CRYPTO_MUTEX_lock_read(&malloc_failure_lock); @@ -168,7 +168,7 @@ static void init_malloc_failure(void) { static int should_fail_allocation() { static CRYPTO_once_t once = CRYPTO_ONCE_INIT; CRYPTO_once(&once, init_malloc_failure); - if (!malloc_failure_enabled) { + if (!malloc_failure_enabled || disable_malloc_failures) { return 0; } @@ -195,6 +195,20 @@ void OPENSSL_reset_malloc_counter_for_testing(void) { CRYPTO_MUTEX_unlock_write(&malloc_failure_lock); } +void OPENSSL_disable_malloc_failures_for_testing(void) { + CRYPTO_MUTEX_lock_write(&malloc_failure_lock); + BSSL_CHECK(!disable_malloc_failures); + disable_malloc_failures = 1; + CRYPTO_MUTEX_unlock_write(&malloc_failure_lock); +} + +void OPENSSL_enable_malloc_failures_for_testing(void) { + CRYPTO_MUTEX_lock_write(&malloc_failure_lock); + BSSL_CHECK(disable_malloc_failures); + disable_malloc_failures = 0; + CRYPTO_MUTEX_unlock_write(&malloc_failure_lock); +} + #else static int should_fail_allocation(void) { return 0; } #endif diff --git a/Sources/CCryptoBoringSSL/crypto/pem/pem_lib.c b/Sources/CCryptoBoringSSL/crypto/pem/pem_lib.c index ac0672db..34806378 100644 --- a/Sources/CCryptoBoringSSL/crypto/pem/pem_lib.c +++ b/Sources/CCryptoBoringSSL/crypto/pem/pem_lib.c @@ -261,21 +261,22 @@ err: } int PEM_ASN1_write(i2d_of_void *i2d, const char *name, FILE *fp, void *x, - const EVP_CIPHER *enc, unsigned char *kstr, int klen, - pem_password_cb *callback, void *u) { + const EVP_CIPHER *enc, const unsigned char *pass, + int pass_len, pem_password_cb *callback, void *u) { BIO *b = BIO_new_fp(fp, BIO_NOCLOSE); if (b == NULL) { OPENSSL_PUT_ERROR(PEM, ERR_R_BUF_LIB); return 0; } - int ret = PEM_ASN1_write_bio(i2d, name, b, x, enc, kstr, klen, callback, u); + int ret = + PEM_ASN1_write_bio(i2d, name, b, x, enc, pass, pass_len, callback, u); BIO_free(b); return ret; } int PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp, void *x, - const EVP_CIPHER *enc, unsigned char *kstr, int klen, - pem_password_cb *callback, void *u) { + const EVP_CIPHER *enc, const unsigned char *pass, + int pass_len, pem_password_cb *callback, void *u) { EVP_CIPHER_CTX ctx; int dsize = 0, i, j, ret = 0; unsigned char *p, *data = NULL; @@ -310,17 +311,17 @@ int PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp, void *x, if (enc != NULL) { const unsigned iv_len = EVP_CIPHER_iv_length(enc); - if (kstr == NULL) { - klen = 0; + if (pass == NULL) { + pass_len = 0; if (!callback) { callback = PEM_def_callback; } - klen = (*callback)(buf, PEM_BUFSIZE, 1, u); - if (klen <= 0) { + pass_len = (*callback)(buf, PEM_BUFSIZE, 1, u); + if (pass_len <= 0) { OPENSSL_PUT_ERROR(PEM, PEM_R_READ_KEY); goto err; } - kstr = (unsigned char *)buf; + pass = (const unsigned char *)buf; } assert(iv_len <= sizeof(iv)); if (!RAND_bytes(iv, iv_len)) { // Generate a salt @@ -328,11 +329,11 @@ int PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp, void *x, } // The 'iv' is used as the iv and as a salt. It is NOT taken from // the BytesToKey function - if (!EVP_BytesToKey(enc, EVP_md5(), iv, kstr, klen, 1, key, NULL)) { + if (!EVP_BytesToKey(enc, EVP_md5(), iv, pass, pass_len, 1, key, NULL)) { goto err; } - if (kstr == (unsigned char *)buf) { + if (pass == (const unsigned char *)buf) { OPENSSL_cleanse(buf, PEM_BUFSIZE); } @@ -375,7 +376,7 @@ err: int PEM_do_header(EVP_CIPHER_INFO *cipher, unsigned char *data, long *plen, pem_password_cb *callback, void *u) { - int i = 0, j, o, klen; + int i = 0, j, o, pass_len; long len; EVP_CIPHER_CTX ctx; unsigned char key[EVP_MAX_KEY_LENGTH]; @@ -387,18 +388,18 @@ int PEM_do_header(EVP_CIPHER_INFO *cipher, unsigned char *data, long *plen, return 1; } - klen = 0; + pass_len = 0; if (!callback) { callback = PEM_def_callback; } - klen = callback(buf, PEM_BUFSIZE, 0, u); - if (klen <= 0) { + pass_len = callback(buf, PEM_BUFSIZE, 0, u); + if (pass_len <= 0) { OPENSSL_PUT_ERROR(PEM, PEM_R_BAD_PASSWORD_READ); return 0; } if (!EVP_BytesToKey(cipher->cipher, EVP_md5(), &(cipher->iv[0]), - (unsigned char *)buf, klen, 1, key, NULL)) { + (unsigned char *)buf, pass_len, 1, key, NULL)) { return 0; } diff --git a/Sources/CCryptoBoringSSL/crypto/pem/pem_pk8.c b/Sources/CCryptoBoringSSL/crypto/pem/pem_pk8.c index 4e2a602b..aed4905f 100644 --- a/Sources/CCryptoBoringSSL/crypto/pem/pem_pk8.c +++ b/Sources/CCryptoBoringSSL/crypto/pem/pem_pk8.c @@ -65,10 +65,10 @@ #include static int do_pk8pkey(BIO *bp, const EVP_PKEY *x, int isder, int nid, - const EVP_CIPHER *enc, char *kstr, int klen, + const EVP_CIPHER *enc, const char *pass, int pass_len, pem_password_cb *cb, void *u); static int do_pk8pkey_fp(FILE *bp, const EVP_PKEY *x, int isder, int nid, - const EVP_CIPHER *enc, char *kstr, int klen, + const EVP_CIPHER *enc, const char *pass, int pass_len, pem_password_cb *cb, void *u); // These functions write a private key in PKCS#8 format: it is a "drop in" @@ -77,30 +77,31 @@ static int do_pk8pkey_fp(FILE *bp, const EVP_PKEY *x, int isder, int nid, // uses PKCS#5 v1.5 PBE algorithms whereas the others use PKCS#5 v2.0. int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, const EVP_PKEY *x, int nid, - char *kstr, int klen, pem_password_cb *cb, - void *u) { - return do_pk8pkey(bp, x, 0, nid, NULL, kstr, klen, cb, u); + const char *pass, int pass_len, + pem_password_cb *cb, void *u) { + return do_pk8pkey(bp, x, 0, nid, NULL, pass, pass_len, cb, u); } int PEM_write_bio_PKCS8PrivateKey(BIO *bp, const EVP_PKEY *x, - const EVP_CIPHER *enc, char *kstr, int klen, - pem_password_cb *cb, void *u) { - return do_pk8pkey(bp, x, 0, -1, enc, kstr, klen, cb, u); + const EVP_CIPHER *enc, const char *pass, + int pass_len, pem_password_cb *cb, void *u) { + return do_pk8pkey(bp, x, 0, -1, enc, pass, pass_len, cb, u); } int i2d_PKCS8PrivateKey_bio(BIO *bp, const EVP_PKEY *x, const EVP_CIPHER *enc, - char *kstr, int klen, pem_password_cb *cb, + const char *pass, int pass_len, pem_password_cb *cb, void *u) { - return do_pk8pkey(bp, x, 1, -1, enc, kstr, klen, cb, u); + return do_pk8pkey(bp, x, 1, -1, enc, pass, pass_len, cb, u); } -int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, const EVP_PKEY *x, int nid, char *kstr, - int klen, pem_password_cb *cb, void *u) { - return do_pk8pkey(bp, x, 1, nid, NULL, kstr, klen, cb, u); +int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, const EVP_PKEY *x, int nid, + const char *pass, int pass_len, + pem_password_cb *cb, void *u) { + return do_pk8pkey(bp, x, 1, nid, NULL, pass, pass_len, cb, u); } static int do_pk8pkey(BIO *bp, const EVP_PKEY *x, int isder, int nid, - const EVP_CIPHER *enc, char *kstr, int klen, + const EVP_CIPHER *enc, const char *pass, int pass_len, pem_password_cb *cb, void *u) { X509_SIG *p8; PKCS8_PRIV_KEY_INFO *p8inf; @@ -111,23 +112,23 @@ static int do_pk8pkey(BIO *bp, const EVP_PKEY *x, int isder, int nid, return 0; } if (enc || (nid != -1)) { - if (!kstr) { - klen = 0; + if (!pass) { + pass_len = 0; if (!cb) { cb = PEM_def_callback; } - klen = cb(buf, PEM_BUFSIZE, 1, u); - if (klen <= 0) { + pass_len = cb(buf, PEM_BUFSIZE, 1, u); + if (pass_len <= 0) { OPENSSL_PUT_ERROR(PEM, PEM_R_READ_KEY); PKCS8_PRIV_KEY_INFO_free(p8inf); return 0; } - kstr = buf; + pass = buf; } - p8 = PKCS8_encrypt(nid, enc, kstr, klen, NULL, 0, 0, p8inf); - if (kstr == buf) { - OPENSSL_cleanse(buf, klen); + p8 = PKCS8_encrypt(nid, enc, pass, pass_len, NULL, 0, 0, p8inf); + if (pass == buf) { + OPENSSL_cleanse(buf, pass_len); } PKCS8_PRIV_KEY_INFO_free(p8inf); if (isder) { @@ -152,7 +153,7 @@ EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u) { PKCS8_PRIV_KEY_INFO *p8inf = NULL; X509_SIG *p8 = NULL; - int klen; + int pass_len; EVP_PKEY *ret; char psbuf[PEM_BUFSIZE]; p8 = d2i_PKCS8_bio(bp, NULL); @@ -160,19 +161,19 @@ EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, return NULL; } - klen = 0; + pass_len = 0; if (!cb) { cb = PEM_def_callback; } - klen = cb(psbuf, PEM_BUFSIZE, 0, u); - if (klen <= 0) { + pass_len = cb(psbuf, PEM_BUFSIZE, 0, u); + if (pass_len <= 0) { OPENSSL_PUT_ERROR(PEM, PEM_R_BAD_PASSWORD_READ); X509_SIG_free(p8); return NULL; } - p8inf = PKCS8_decrypt(p8, psbuf, klen); + p8inf = PKCS8_decrypt(p8, psbuf, pass_len); X509_SIG_free(p8); - OPENSSL_cleanse(psbuf, klen); + OPENSSL_cleanse(psbuf, pass_len); if (!p8inf) { return NULL; } @@ -192,29 +193,31 @@ EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, int i2d_PKCS8PrivateKey_fp(FILE *fp, const EVP_PKEY *x, const EVP_CIPHER *enc, - char *kstr, int klen, pem_password_cb *cb, void *u) { - return do_pk8pkey_fp(fp, x, 1, -1, enc, kstr, klen, cb, u); + const char *pass, int pass_len, pem_password_cb *cb, + void *u) { + return do_pk8pkey_fp(fp, x, 1, -1, enc, pass, pass_len, cb, u); } -int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, const EVP_PKEY *x, int nid, char *kstr, - int klen, pem_password_cb *cb, void *u) { - return do_pk8pkey_fp(fp, x, 1, nid, NULL, kstr, klen, cb, u); +int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, const EVP_PKEY *x, int nid, + const char *pass, int pass_len, + pem_password_cb *cb, void *u) { + return do_pk8pkey_fp(fp, x, 1, nid, NULL, pass, pass_len, cb, u); } int PEM_write_PKCS8PrivateKey_nid(FILE *fp, const EVP_PKEY *x, int nid, - char *kstr, int klen, pem_password_cb *cb, - void *u) { - return do_pk8pkey_fp(fp, x, 0, nid, NULL, kstr, klen, cb, u); + const char *pass, int pass_len, + pem_password_cb *cb, void *u) { + return do_pk8pkey_fp(fp, x, 0, nid, NULL, pass, pass_len, cb, u); } int PEM_write_PKCS8PrivateKey(FILE *fp, const EVP_PKEY *x, - const EVP_CIPHER *enc, char *kstr, int klen, - pem_password_cb *cb, void *u) { - return do_pk8pkey_fp(fp, x, 0, -1, enc, kstr, klen, cb, u); + const EVP_CIPHER *enc, const char *pass, + int pass_len, pem_password_cb *cb, void *u) { + return do_pk8pkey_fp(fp, x, 0, -1, enc, pass, pass_len, cb, u); } static int do_pk8pkey_fp(FILE *fp, const EVP_PKEY *x, int isder, int nid, - const EVP_CIPHER *enc, char *kstr, int klen, + const EVP_CIPHER *enc, const char *pass, int pass_len, pem_password_cb *cb, void *u) { BIO *bp; int ret; @@ -222,7 +225,7 @@ static int do_pk8pkey_fp(FILE *fp, const EVP_PKEY *x, int isder, int nid, OPENSSL_PUT_ERROR(PEM, ERR_R_BUF_LIB); return 0; } - ret = do_pk8pkey(bp, x, isder, nid, enc, kstr, klen, cb, u); + ret = do_pk8pkey(bp, x, isder, nid, enc, pass, pass_len, cb, u); BIO_free(bp); return ret; } diff --git a/Sources/CCryptoBoringSSL/crypto/pem/pem_pkey.c b/Sources/CCryptoBoringSSL/crypto/pem/pem_pkey.c index 5066391c..225a9e0d 100644 --- a/Sources/CCryptoBoringSSL/crypto/pem/pem_pkey.c +++ b/Sources/CCryptoBoringSSL/crypto/pem/pem_pkey.c @@ -98,26 +98,26 @@ EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, } else if (strcmp(nm, PEM_STRING_PKCS8) == 0) { PKCS8_PRIV_KEY_INFO *p8inf; X509_SIG *p8; - int klen; + int pass_len; char psbuf[PEM_BUFSIZE]; p8 = d2i_X509_SIG(NULL, &p, len); if (!p8) { goto p8err; } - klen = 0; + pass_len = 0; if (!cb) { cb = PEM_def_callback; } - klen = cb(psbuf, PEM_BUFSIZE, 0, u); - if (klen <= 0) { + pass_len = cb(psbuf, PEM_BUFSIZE, 0, u); + if (pass_len <= 0) { OPENSSL_PUT_ERROR(PEM, PEM_R_BAD_PASSWORD_READ); X509_SIG_free(p8); goto err; } - p8inf = PKCS8_decrypt(p8, psbuf, klen); + p8inf = PKCS8_decrypt(p8, psbuf, pass_len); X509_SIG_free(p8); - OPENSSL_cleanse(psbuf, klen); + OPENSSL_cleanse(psbuf, pass_len); if (!p8inf) { goto p8err; } @@ -151,9 +151,10 @@ err: } int PEM_write_bio_PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc, - unsigned char *kstr, int klen, pem_password_cb *cb, - void *u) { - return PEM_write_bio_PKCS8PrivateKey(bp, x, enc, (char *)kstr, klen, cb, u); + const unsigned char *pass, int pass_len, + pem_password_cb *cb, void *u) { + return PEM_write_bio_PKCS8PrivateKey(bp, x, enc, (const char *)pass, pass_len, + cb, u); } EVP_PKEY *PEM_read_PrivateKey(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, @@ -169,14 +170,14 @@ EVP_PKEY *PEM_read_PrivateKey(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, } int PEM_write_PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc, - unsigned char *kstr, int klen, pem_password_cb *cb, - void *u) { + const unsigned char *pass, int pass_len, + pem_password_cb *cb, void *u) { BIO *b = BIO_new_fp(fp, BIO_NOCLOSE); if (b == NULL) { OPENSSL_PUT_ERROR(PEM, ERR_R_BUF_LIB); return 0; } - int ret = PEM_write_bio_PrivateKey(b, x, enc, kstr, klen, cb, u); + int ret = PEM_write_bio_PrivateKey(b, x, enc, pass, pass_len, cb, u); BIO_free(b); return ret; } diff --git a/Sources/CCryptoBoringSSL/crypto/rsa_extra/rsa_crypt.c b/Sources/CCryptoBoringSSL/crypto/rsa_extra/rsa_crypt.c index ebae0c37..cbb25013 100644 --- a/Sources/CCryptoBoringSSL/crypto/rsa_extra/rsa_crypt.c +++ b/Sources/CCryptoBoringSSL/crypto/rsa_extra/rsa_crypt.c @@ -75,7 +75,9 @@ static void rand_nonzero(uint8_t *out, size_t len) { RAND_bytes(out, len); for (size_t i = 0; i < len; i++) { - while (out[i] == 0) { + // Zero values are replaced, and the distribution of zero and non-zero bytes + // is public, so leaking this is safe. + while (constant_time_declassify_int(out[i] == 0)) { RAND_bytes(out + i, 1); } } diff --git a/Sources/CCryptoBoringSSL/crypto/spx/spx.c b/Sources/CCryptoBoringSSL/crypto/spx/spx.c index c83e6b30..bc2b3d22 100644 --- a/Sources/CCryptoBoringSSL/crypto/spx/spx.c +++ b/Sources/CCryptoBoringSSL/crypto/spx/spx.c @@ -16,11 +16,11 @@ #include +#include #include #include "./address.h" #include "./fors.h" -#include "./internal.h" #include "./merkle.h" #include "./params.h" #include "./spx_util.h" diff --git a/Sources/CCryptoBoringSSL/crypto/x509/by_dir.c b/Sources/CCryptoBoringSSL/crypto/x509/by_dir.c index 7df4b86a..d7cd8048 100644 --- a/Sources/CCryptoBoringSSL/crypto/x509/by_dir.c +++ b/Sources/CCryptoBoringSSL/crypto/x509/by_dir.c @@ -56,8 +56,6 @@ #include #include -#include -#include #include #include @@ -74,6 +72,7 @@ typedef struct lookup_dir_hashes_st { } BY_DIR_HASH; typedef struct lookup_dir_entry_st { + CRYPTO_MUTEX lock; char *dir; int dir_type; STACK_OF(BY_DIR_HASH) *hashes; @@ -158,6 +157,7 @@ static int by_dir_hash_cmp(const BY_DIR_HASH *const *a, static void by_dir_entry_free(BY_DIR_ENTRY *ent) { if (ent != NULL) { + CRYPTO_MUTEX_cleanup(&ent->lock); OPENSSL_free(ent->dir); sk_BY_DIR_HASH_pop_free(ent->hashes, by_dir_hash_free); OPENSSL_free(ent); @@ -172,6 +172,12 @@ static void free_dir(X509_LOOKUP *lu) { } } +#if defined(OPENSSL_WINDOWS) +#define DIR_HASH_SEPARATOR ';' +#else +#define DIR_HASH_SEPARATOR ':' +#endif + static int add_cert_dir(BY_DIR *ctx, const char *dir, int type) { size_t j, len; const char *s, *ss, *p; @@ -184,7 +190,7 @@ static int add_cert_dir(BY_DIR *ctx, const char *dir, int type) { s = dir; p = s; do { - if ((*p == ':') || (*p == '\0')) { + if (*p == DIR_HASH_SEPARATOR || *p == '\0') { BY_DIR_ENTRY *ent; ss = s; s = p + 1; @@ -211,15 +217,12 @@ static int add_cert_dir(BY_DIR *ctx, const char *dir, int type) { if (!ent) { return 0; } + CRYPTO_MUTEX_init(&ent->lock); ent->dir_type = type; ent->hashes = sk_BY_DIR_HASH_new(by_dir_hash_cmp); - ent->dir = OPENSSL_malloc(len + 1); - if (!ent->dir || !ent->hashes) { - by_dir_entry_free(ent); - return 0; - } - OPENSSL_strlcpy(ent->dir, ss, len + 1); - if (!sk_BY_DIR_ENTRY_push(ctx->dirs, ent)) { + ent->dir = OPENSSL_strndup(ss, len); + if (ent->dir == NULL || ent->hashes == NULL || + !sk_BY_DIR_ENTRY_push(ctx->dirs, ent)) { by_dir_entry_free(ent); return 0; } @@ -228,10 +231,6 @@ static int add_cert_dir(BY_DIR *ctx, const char *dir, int type) { return 1; } -// g_ent_hashes_lock protects the |hashes| member of all |BY_DIR_ENTRY| -// objects. -static CRYPTO_MUTEX g_ent_hashes_lock = CRYPTO_MUTEX_INIT; - static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name, X509_OBJECT *ret) { union { @@ -296,7 +295,7 @@ static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name, } if (type == X509_LU_CRL && ent->hashes) { htmp.hash = h; - CRYPTO_MUTEX_lock_read(&g_ent_hashes_lock); + CRYPTO_MUTEX_lock_read(&ent->lock); if (sk_BY_DIR_HASH_find(ent->hashes, &idx, &htmp)) { hent = sk_BY_DIR_HASH_value(ent->hashes, idx); k = hent->suffix; @@ -304,7 +303,7 @@ static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name, hent = NULL; k = 0; } - CRYPTO_MUTEX_unlock_read(&g_ent_hashes_lock); + CRYPTO_MUTEX_unlock_read(&ent->lock); } else { k = 0; hent = NULL; @@ -312,18 +311,6 @@ static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name, for (;;) { snprintf(b->data, b->max, "%s/%08" PRIx32 ".%s%d", ent->dir, h, postfix, k); -#ifndef OPENSSL_NO_POSIX_IO -#if defined(_WIN32) && !defined(stat) -#define stat _stat -#endif - { - struct stat st; - if (stat(b->data, &st) < 0) { - break; - } - } -#endif - // found one. if (type == X509_LU_X509) { if ((X509_load_cert_file(xl, b->data, ent->dir_type)) == 0) { break; @@ -349,7 +336,7 @@ static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name, // If a CRL, update the last file suffix added for this if (type == X509_LU_CRL) { - CRYPTO_MUTEX_lock_write(&g_ent_hashes_lock); + CRYPTO_MUTEX_lock_write(&ent->lock); // Look for entry again in case another thread added an entry // first. if (!hent) { @@ -362,14 +349,14 @@ static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name, if (!hent) { hent = OPENSSL_malloc(sizeof(BY_DIR_HASH)); if (hent == NULL) { - CRYPTO_MUTEX_unlock_write(&g_ent_hashes_lock); + CRYPTO_MUTEX_unlock_write(&ent->lock); ok = 0; goto finish; } hent->hash = h; hent->suffix = k; if (!sk_BY_DIR_HASH_push(ent->hashes, hent)) { - CRYPTO_MUTEX_unlock_write(&g_ent_hashes_lock); + CRYPTO_MUTEX_unlock_write(&ent->lock); OPENSSL_free(hent); ok = 0; goto finish; @@ -379,7 +366,7 @@ static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name, hent->suffix = k; } - CRYPTO_MUTEX_unlock_write(&g_ent_hashes_lock); + CRYPTO_MUTEX_unlock_write(&ent->lock); } if (tmp != NULL) { diff --git a/Sources/CCryptoBoringSSL/crypto/x509/by_file.c b/Sources/CCryptoBoringSSL/crypto/x509/by_file.c index 6fe702f6..5893bdec 100644 --- a/Sources/CCryptoBoringSSL/crypto/x509/by_file.c +++ b/Sources/CCryptoBoringSSL/crypto/x509/by_file.c @@ -228,7 +228,7 @@ int X509_load_cert_crl_file(X509_LOOKUP *ctx, const char *file, int type) { if (type != X509_FILETYPE_PEM) { return X509_load_cert_file(ctx, file, type); } - in = BIO_new_file(file, "r"); + in = BIO_new_file(file, "rb"); if (!in) { OPENSSL_PUT_ERROR(X509, ERR_R_SYS_LIB); return 0; diff --git a/Sources/CCryptoBoringSSL/crypto/x509/internal.h b/Sources/CCryptoBoringSSL/crypto/x509/internal.h index 7cc7ebfd..6a1beefc 100644 --- a/Sources/CCryptoBoringSSL/crypto/x509/internal.h +++ b/Sources/CCryptoBoringSSL/crypto/x509/internal.h @@ -170,7 +170,6 @@ struct x509_st { uint32_t ex_flags; uint32_t ex_kusage; uint32_t ex_xkusage; - uint32_t ex_nscert; ASN1_OCTET_STRING *skid; AUTHORITY_KEYID *akid; STACK_OF(DIST_POINT) *crldp; @@ -589,6 +588,13 @@ GENERAL_NAMES *v2i_GENERAL_NAMES(const X509V3_EXT_METHOD *method, // |X509_NAME| issue is resolved. int X509_check_akid(X509 *issuer, const AUTHORITY_KEYID *akid); +int X509_is_valid_trust_id(int trust); + +int X509_PURPOSE_get_trust(const X509_PURPOSE *xp); + +// TODO(https://crbug.com/boringssl/695): Remove this. +int DIST_POINT_set_dpname(DIST_POINT_NAME *dpn, X509_NAME *iname); + #if defined(__cplusplus) } // extern C diff --git a/Sources/CCryptoBoringSSL/crypto/x509/v3_cpols.c b/Sources/CCryptoBoringSSL/crypto/x509/v3_cpols.c index c703ff97..ffc8a697 100644 --- a/Sources/CCryptoBoringSSL/crypto/x509/v3_cpols.c +++ b/Sources/CCryptoBoringSSL/crypto/x509/v3_cpols.c @@ -105,6 +105,11 @@ const X509V3_EXT_METHOD v3_cpols = { NULL, }; +DECLARE_ASN1_ITEM(POLICYINFO) +DECLARE_ASN1_ITEM(POLICYQUALINFO) +DECLARE_ASN1_ITEM(USERNOTICE) +DECLARE_ASN1_ITEM(NOTICEREF) + ASN1_ITEM_TEMPLATE(CERTIFICATEPOLICIES) = ASN1_EX_TEMPLATE_TYPE( ASN1_TFLG_SEQUENCE_OF, 0, CERTIFICATEPOLICIES, POLICYINFO) ASN1_ITEM_TEMPLATE_END(CERTIFICATEPOLICIES) @@ -116,7 +121,7 @@ ASN1_SEQUENCE(POLICYINFO) = { ASN1_SEQUENCE_OF_OPT(POLICYINFO, qualifiers, POLICYQUALINFO), } ASN1_SEQUENCE_END(POLICYINFO) -IMPLEMENT_ASN1_FUNCTIONS_const(POLICYINFO) +IMPLEMENT_ASN1_ALLOC_FUNCTIONS(POLICYINFO) ASN1_ADB_TEMPLATE(policydefault) = ASN1_SIMPLE(POLICYQUALINFO, d.other, ASN1_ANY); @@ -133,21 +138,21 @@ ASN1_SEQUENCE(POLICYQUALINFO) = { ASN1_ADB_OBJECT(POLICYQUALINFO), } ASN1_SEQUENCE_END(POLICYQUALINFO) -IMPLEMENT_ASN1_FUNCTIONS_const(POLICYQUALINFO) +IMPLEMENT_ASN1_ALLOC_FUNCTIONS(POLICYQUALINFO) ASN1_SEQUENCE(USERNOTICE) = { ASN1_OPT(USERNOTICE, noticeref, NOTICEREF), ASN1_OPT(USERNOTICE, exptext, DISPLAYTEXT), } ASN1_SEQUENCE_END(USERNOTICE) -IMPLEMENT_ASN1_FUNCTIONS_const(USERNOTICE) +IMPLEMENT_ASN1_ALLOC_FUNCTIONS(USERNOTICE) ASN1_SEQUENCE(NOTICEREF) = { ASN1_SIMPLE(NOTICEREF, organization, DISPLAYTEXT), ASN1_SEQUENCE_OF(NOTICEREF, noticenos, ASN1_INTEGER), } ASN1_SEQUENCE_END(NOTICEREF) -IMPLEMENT_ASN1_FUNCTIONS_const(NOTICEREF) +IMPLEMENT_ASN1_ALLOC_FUNCTIONS(NOTICEREF) static void *r2i_certpol(const X509V3_EXT_METHOD *method, const X509V3_CTX *ctx, const char *value) { diff --git a/Sources/CCryptoBoringSSL/crypto/x509/v3_crld.c b/Sources/CCryptoBoringSSL/crypto/x509/v3_crld.c index d5fcec8f..e9d5e8cc 100644 --- a/Sources/CCryptoBoringSSL/crypto/x509/v3_crld.c +++ b/Sources/CCryptoBoringSSL/crypto/x509/v3_crld.c @@ -393,7 +393,7 @@ ASN1_CHOICE_cb(DIST_POINT_NAME, dpn_cb) = { ASN1_IMP_SET_OF(DIST_POINT_NAME, name.relativename, X509_NAME_ENTRY, 1), } ASN1_CHOICE_END_cb(DIST_POINT_NAME, DIST_POINT_NAME, type) -IMPLEMENT_ASN1_FUNCTIONS(DIST_POINT_NAME) +IMPLEMENT_ASN1_ALLOC_FUNCTIONS(DIST_POINT_NAME) ASN1_SEQUENCE(DIST_POINT) = { ASN1_EXP_OPT(DIST_POINT, distpoint, DIST_POINT_NAME, 0), @@ -401,7 +401,7 @@ ASN1_SEQUENCE(DIST_POINT) = { ASN1_IMP_SEQUENCE_OF_OPT(DIST_POINT, CRLissuer, GENERAL_NAME, 2), } ASN1_SEQUENCE_END(DIST_POINT) -IMPLEMENT_ASN1_FUNCTIONS(DIST_POINT) +IMPLEMENT_ASN1_ALLOC_FUNCTIONS(DIST_POINT) ASN1_ITEM_TEMPLATE(CRL_DIST_POINTS) = ASN1_EX_TEMPLATE_TYPE( ASN1_TFLG_SEQUENCE_OF, 0, CRLDistributionPoints, DIST_POINT) diff --git a/Sources/CCryptoBoringSSL/crypto/x509/v3_enum.c b/Sources/CCryptoBoringSSL/crypto/x509/v3_enum.c index 14540332..b34ce83d 100644 --- a/Sources/CCryptoBoringSSL/crypto/x509/v3_enum.c +++ b/Sources/CCryptoBoringSSL/crypto/x509/v3_enum.c @@ -59,6 +59,7 @@ #include #include #include +#include #include "internal.h" diff --git a/Sources/CCryptoBoringSSL/crypto/x509/v3_info.c b/Sources/CCryptoBoringSSL/crypto/x509/v3_info.c index 39bb57e3..adbb5693 100644 --- a/Sources/CCryptoBoringSSL/crypto/x509/v3_info.c +++ b/Sources/CCryptoBoringSSL/crypto/x509/v3_info.c @@ -115,7 +115,7 @@ ASN1_SEQUENCE(ACCESS_DESCRIPTION) = { ASN1_SIMPLE(ACCESS_DESCRIPTION, location, GENERAL_NAME), } ASN1_SEQUENCE_END(ACCESS_DESCRIPTION) -IMPLEMENT_ASN1_FUNCTIONS(ACCESS_DESCRIPTION) +IMPLEMENT_ASN1_ALLOC_FUNCTIONS(ACCESS_DESCRIPTION) ASN1_ITEM_TEMPLATE(AUTHORITY_INFO_ACCESS) = ASN1_EX_TEMPLATE_TYPE( ASN1_TFLG_SEQUENCE_OF, 0, GeneralNames, ACCESS_DESCRIPTION) diff --git a/Sources/CCryptoBoringSSL/crypto/x509/v3_lib.c b/Sources/CCryptoBoringSSL/crypto/x509/v3_lib.c index 4e3721d3..f63b2379 100644 --- a/Sources/CCryptoBoringSSL/crypto/x509/v3_lib.c +++ b/Sources/CCryptoBoringSSL/crypto/x509/v3_lib.c @@ -70,6 +70,8 @@ #include "ext_dat.h" +DEFINE_STACK_OF(X509V3_EXT_METHOD) + static STACK_OF(X509V3_EXT_METHOD) *ext_list = NULL; static int ext_stack_cmp(const X509V3_EXT_METHOD *const *a, diff --git a/Sources/CCryptoBoringSSL/crypto/x509/v3_purp.c b/Sources/CCryptoBoringSSL/crypto/x509/v3_purp.c index 5a8fcb5a..90317e10 100644 --- a/Sources/CCryptoBoringSSL/crypto/x509/v3_purp.c +++ b/Sources/CCryptoBoringSSL/crypto/x509/v3_purp.c @@ -54,8 +54,6 @@ * (eay@cryptsoft.com). This product includes software written by Tim * Hudson (tjh@cryptsoft.com). */ -#include - #include #include @@ -68,21 +66,27 @@ #include "../internal.h" #include "internal.h" + +struct x509_purpose_st { + int purpose; + int trust; // Default trust ID + int (*check_purpose)(const struct x509_purpose_st *, const X509 *, int); + const char *sname; +} /* X509_PURPOSE */; + #define V1_ROOT (EXFLAG_V1 | EXFLAG_SS) #define ku_reject(x, usage) \ (((x)->ex_flags & EXFLAG_KUSAGE) && !((x)->ex_kusage & (usage))) #define xku_reject(x, usage) \ (((x)->ex_flags & EXFLAG_XKUSAGE) && !((x)->ex_xkusage & (usage))) -#define ns_reject(x, usage) \ - (((x)->ex_flags & EXFLAG_NSCERT) && !((x)->ex_nscert & (usage))) +static int check_ca(const X509 *x); static int check_purpose_ssl_client(const X509_PURPOSE *xp, const X509 *x, int ca); static int check_purpose_ssl_server(const X509_PURPOSE *xp, const X509 *x, int ca); static int check_purpose_ns_ssl_server(const X509_PURPOSE *xp, const X509 *x, int ca); -static int purpose_smime(const X509 *x, int ca); static int check_purpose_smime_sign(const X509_PURPOSE *xp, const X509 *x, int ca); static int check_purpose_smime_encrypt(const X509_PURPOSE *xp, const X509 *x, @@ -92,101 +96,82 @@ static int check_purpose_crl_sign(const X509_PURPOSE *xp, const X509 *x, static int check_purpose_timestamp_sign(const X509_PURPOSE *xp, const X509 *x, int ca); static int no_check(const X509_PURPOSE *xp, const X509 *x, int ca); -static int ocsp_helper(const X509_PURPOSE *xp, const X509 *x, int ca); + +// X509_TRUST_NONE is not a valid |X509_TRUST_*| constant. It is used by +// |X509_PURPOSE_ANY| to indicate that it has no corresponding trust type and +// cannot be used with |X509_STORE_CTX_set_purpose|. +#define X509_TRUST_NONE (-1) static const X509_PURPOSE xstandard[] = { - {X509_PURPOSE_SSL_CLIENT, X509_TRUST_SSL_CLIENT, 0, - check_purpose_ssl_client, (char *)"SSL client", (char *)"sslclient", NULL}, - {X509_PURPOSE_SSL_SERVER, X509_TRUST_SSL_SERVER, 0, - check_purpose_ssl_server, (char *)"SSL server", (char *)"sslserver", NULL}, - {X509_PURPOSE_NS_SSL_SERVER, X509_TRUST_SSL_SERVER, 0, - check_purpose_ns_ssl_server, (char *)"Netscape SSL server", - (char *)"nssslserver", NULL}, - {X509_PURPOSE_SMIME_SIGN, X509_TRUST_EMAIL, 0, check_purpose_smime_sign, - (char *)"S/MIME signing", (char *)"smimesign", NULL}, - {X509_PURPOSE_SMIME_ENCRYPT, X509_TRUST_EMAIL, 0, - check_purpose_smime_encrypt, (char *)"S/MIME encryption", - (char *)"smimeencrypt", NULL}, - {X509_PURPOSE_CRL_SIGN, X509_TRUST_COMPAT, 0, check_purpose_crl_sign, - (char *)"CRL signing", (char *)"crlsign", NULL}, - {X509_PURPOSE_ANY, X509_TRUST_DEFAULT, 0, no_check, (char *)"Any Purpose", - (char *)"any", NULL}, - {X509_PURPOSE_OCSP_HELPER, X509_TRUST_COMPAT, 0, ocsp_helper, - (char *)"OCSP helper", (char *)"ocsphelper", NULL}, - {X509_PURPOSE_TIMESTAMP_SIGN, X509_TRUST_TSA, 0, - check_purpose_timestamp_sign, (char *)"Time Stamp signing", - (char *)"timestampsign", NULL}, + {X509_PURPOSE_SSL_CLIENT, X509_TRUST_SSL_CLIENT, check_purpose_ssl_client, + "sslclient"}, + {X509_PURPOSE_SSL_SERVER, X509_TRUST_SSL_SERVER, check_purpose_ssl_server, + "sslserver"}, + {X509_PURPOSE_NS_SSL_SERVER, X509_TRUST_SSL_SERVER, + check_purpose_ns_ssl_server, "nssslserver"}, + {X509_PURPOSE_SMIME_SIGN, X509_TRUST_EMAIL, check_purpose_smime_sign, + "smimesign"}, + {X509_PURPOSE_SMIME_ENCRYPT, X509_TRUST_EMAIL, check_purpose_smime_encrypt, + "smimeencrypt"}, + {X509_PURPOSE_CRL_SIGN, X509_TRUST_COMPAT, check_purpose_crl_sign, + "crlsign"}, + {X509_PURPOSE_ANY, X509_TRUST_NONE, no_check, "any"}, + // |X509_PURPOSE_OCSP_HELPER| performs no actual checks. OpenSSL's OCSP + // implementation relied on the caller performing EKU and KU checks. + {X509_PURPOSE_OCSP_HELPER, X509_TRUST_COMPAT, no_check, "ocsphelper"}, + {X509_PURPOSE_TIMESTAMP_SIGN, X509_TRUST_TSA, check_purpose_timestamp_sign, + "timestampsign"}, }; -// As much as I'd like to make X509_check_purpose use a "const" X509* I -// really can't because it does recalculate hashes and do other non-const -// things. int X509_check_purpose(X509 *x, int id, int ca) { - int idx; - const X509_PURPOSE *pt; + // This differs from OpenSSL, which uses -1 to indicate a fatal error and 0 to + // indicate an invalid certificate. BoringSSL uses 0 for both. if (!x509v3_cache_extensions(x)) { - return -1; + return 0; } if (id == -1) { return 1; } - idx = X509_PURPOSE_get_by_id(id); - if (idx == -1) { - return -1; + const X509_PURPOSE *pt = X509_PURPOSE_get0(id); + if (pt == NULL) { + return 0; + } + // Historically, |check_purpose| implementations other than |X509_PURPOSE_ANY| + // called |check_ca|. This is redundant with the |X509_V_ERR_INVALID_CA| + // logic, but |X509_check_purpose| is public API, so we preserve this + // behavior. + if (ca && id != X509_PURPOSE_ANY && !check_ca(x)) { + return 0; } - pt = X509_PURPOSE_get0(idx); return pt->check_purpose(pt, x, ca); } -int X509_PURPOSE_set(int *p, int purpose) { - if (X509_PURPOSE_get_by_id(purpose) == -1) { - OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_PURPOSE); - return 0; +const X509_PURPOSE *X509_PURPOSE_get0(int id) { + for (size_t i = 0; i < OPENSSL_ARRAY_SIZE(xstandard); i++) { + if (xstandard[i].purpose == id) { + return &xstandard[i]; + } } - *p = purpose; - return 1; -} - -int X509_PURPOSE_get_count(void) { return OPENSSL_ARRAY_SIZE(xstandard); } - -const X509_PURPOSE *X509_PURPOSE_get0(int idx) { - if (idx < 0 || (size_t)idx >= OPENSSL_ARRAY_SIZE(xstandard)) { - return NULL; - } - return xstandard + idx; + return NULL; } int X509_PURPOSE_get_by_sname(const char *sname) { - const X509_PURPOSE *xptmp; - for (int i = 0; i < X509_PURPOSE_get_count(); i++) { - xptmp = X509_PURPOSE_get0(i); - if (!strcmp(xptmp->sname, sname)) { - return i; + for (size_t i = 0; i < OPENSSL_ARRAY_SIZE(xstandard); i++) { + if (strcmp(xstandard[i].sname, sname) == 0) { + return xstandard[i].purpose; } } return -1; } -int X509_PURPOSE_get_by_id(int purpose) { - if (purpose >= X509_PURPOSE_MIN && purpose <= X509_PURPOSE_MAX) { - return purpose - X509_PURPOSE_MIN; - } - return -1; -} - int X509_PURPOSE_get_id(const X509_PURPOSE *xp) { return xp->purpose; } -char *X509_PURPOSE_get0_name(const X509_PURPOSE *xp) { return xp->name; } - -char *X509_PURPOSE_get0_sname(const X509_PURPOSE *xp) { return xp->sname; } - int X509_PURPOSE_get_trust(const X509_PURPOSE *xp) { return xp->trust; } int X509_supported_extension(const X509_EXTENSION *ex) { int nid = OBJ_obj2nid(X509_EXTENSION_get_object(ex)); - return nid == NID_netscape_cert_type || // - nid == NID_key_usage || // + return nid == NID_key_usage || // nid == NID_subject_alt_name || // nid == NID_basic_constraints || // nid == NID_certificate_policies || // @@ -233,7 +218,6 @@ static int setup_crldp(X509 *x) { int x509v3_cache_extensions(X509 *x) { BASIC_CONSTRAINTS *bs; ASN1_BIT_STRING *usage; - ASN1_BIT_STRING *ns; EXTENDED_KEY_USAGE *extusage; size_t i; int j; @@ -347,17 +331,6 @@ int x509v3_cache_extensions(X509 *x) { x->ex_flags |= EXFLAG_INVALID; } - if ((ns = X509_get_ext_d2i(x, NID_netscape_cert_type, &j, NULL))) { - if (ns->length > 0) { - x->ex_nscert = ns->data[0]; - } else { - x->ex_nscert = 0; - } - x->ex_flags |= EXFLAG_NSCERT; - ASN1_BIT_STRING_free(ns); - } else if (j != -1) { - x->ex_flags |= EXFLAG_INVALID; - } x->skid = X509_get_ext_d2i(x, NID_subject_key_identifier, &j, NULL); if (x->skid == NULL && j != -1) { x->ex_flags |= EXFLAG_INVALID; @@ -425,23 +398,28 @@ int X509_check_ca(X509 *x) { return check_ca(x); } +// check_purpose returns one if |x| is a valid part of a certificate path for +// extended key usage |required_xku| and at least one of key usages in +// |required_kus|. |ca| indicates whether |x| is a CA or end-entity certificate. +static int check_purpose(const X509 *x, int ca, int required_xku, + int required_kus) { + // Check extended key usage on the entire chain. + if (required_xku != 0 && xku_reject(x, required_xku)) { + return 0; + } + + // Check key usages only on the end-entity certificate. + return ca || !ku_reject(x, required_kus); +} + static int check_purpose_ssl_client(const X509_PURPOSE *xp, const X509 *x, int ca) { - if (xku_reject(x, XKU_SSL_CLIENT)) { - return 0; - } - if (ca) { - return check_ca(x); - } - // We need to do digital signatures or key agreement - if (ku_reject(x, X509v3_KU_DIGITAL_SIGNATURE | X509v3_KU_KEY_AGREEMENT)) { - return 0; - } - // nsCertType if present should allow SSL client use - if (ns_reject(x, NS_SSL_CLIENT)) { - return 0; - } - return 1; + // We need to do digital signatures or key agreement. + // + // TODO(davidben): We do not implement any TLS client certificate modes based + // on key agreement. + return check_purpose(x, ca, XKU_SSL_CLIENT, + X509v3_KU_DIGITAL_SIGNATURE | X509v3_KU_KEY_AGREEMENT); } // Key usage needed for TLS/SSL server: digital signature, encipherment or @@ -453,112 +431,35 @@ static int check_purpose_ssl_client(const X509_PURPOSE *xp, const X509 *x, static int check_purpose_ssl_server(const X509_PURPOSE *xp, const X509 *x, int ca) { - if (xku_reject(x, XKU_SSL_SERVER)) { - return 0; - } - if (ca) { - return check_ca(x); - } - - if (ns_reject(x, NS_SSL_SERVER)) { - return 0; - } - if (ku_reject(x, X509v3_KU_TLS)) { - return 0; - } - - return 1; + return check_purpose(x, ca, XKU_SSL_SERVER, X509v3_KU_TLS); } static int check_purpose_ns_ssl_server(const X509_PURPOSE *xp, const X509 *x, int ca) { - int ret; - ret = check_purpose_ssl_server(xp, x, ca); - if (!ret || ca) { - return ret; - } - // We need to encipher or Netscape complains - if (ku_reject(x, X509v3_KU_KEY_ENCIPHERMENT)) { - return 0; - } - return ret; -} - -// purpose_smime returns one if |x| is a valid S/MIME leaf (|ca| is zero) or CA -// (|ca| is one) certificate, and zero otherwise. -static int purpose_smime(const X509 *x, int ca) { - if (xku_reject(x, XKU_SMIME)) { - return 0; - } - if (ca) { - // check nsCertType if present - if ((x->ex_flags & EXFLAG_NSCERT) && (x->ex_nscert & NS_SMIME_CA) == 0) { - return 0; - } - - return check_ca(x); - } - if (x->ex_flags & EXFLAG_NSCERT) { - return (x->ex_nscert & NS_SMIME) == NS_SMIME; - } - return 1; + // We need to encipher or Netscape complains. + return check_purpose(x, ca, XKU_SSL_SERVER, X509v3_KU_KEY_ENCIPHERMENT); } static int check_purpose_smime_sign(const X509_PURPOSE *xp, const X509 *x, int ca) { - int ret; - ret = purpose_smime(x, ca); - if (!ret || ca) { - return ret; - } - if (ku_reject(x, X509v3_KU_DIGITAL_SIGNATURE | X509v3_KU_NON_REPUDIATION)) { - return 0; - } - return ret; + return check_purpose(x, ca, XKU_SMIME, + X509v3_KU_DIGITAL_SIGNATURE | X509v3_KU_NON_REPUDIATION); } static int check_purpose_smime_encrypt(const X509_PURPOSE *xp, const X509 *x, int ca) { - int ret; - ret = purpose_smime(x, ca); - if (!ret || ca) { - return ret; - } - if (ku_reject(x, X509v3_KU_KEY_ENCIPHERMENT)) { - return 0; - } - return ret; + return check_purpose(x, ca, XKU_SMIME, X509v3_KU_KEY_ENCIPHERMENT); } static int check_purpose_crl_sign(const X509_PURPOSE *xp, const X509 *x, int ca) { - if (ca) { - return check_ca(x); - } - if (ku_reject(x, X509v3_KU_CRL_SIGN)) { - return 0; - } - return 1; -} - -// OCSP helper: this is *not* a full OCSP check. It just checks that each CA -// is valid. Additional checks must be made on the chain. - -static int ocsp_helper(const X509_PURPOSE *xp, const X509 *x, int ca) { - if (ca) { - return check_ca(x); - } - // leaf certificate is checked in OCSP_verify() - return 1; + return check_purpose(x, ca, /*required_xku=*/0, X509v3_KU_CRL_SIGN); } static int check_purpose_timestamp_sign(const X509_PURPOSE *xp, const X509 *x, int ca) { - int i_ext; - - // If ca is true we must return if this is a valid CA certificate. if (ca) { - return check_ca(x); + return 1; } // Check the optional key usage field: @@ -574,14 +475,16 @@ static int check_purpose_timestamp_sign(const X509_PURPOSE *xp, const X509 *x, } // Only time stamp key usage is permitted and it's required. + // + // TODO(davidben): Should we check EKUs up the chain like the other cases? if (!(x->ex_flags & EXFLAG_XKUSAGE) || x->ex_xkusage != XKU_TIMESTAMP) { return 0; } // Extended Key Usage MUST be critical - i_ext = X509_get_ext_by_NID((X509 *)x, NID_ext_key_usage, -1); + int i_ext = X509_get_ext_by_NID(x, NID_ext_key_usage, -1); if (i_ext >= 0) { - const X509_EXTENSION *ext = X509_get_ext((X509 *)x, i_ext); + const X509_EXTENSION *ext = X509_get_ext(x, i_ext); if (!X509_EXTENSION_get_critical(ext)) { return 0; } diff --git a/Sources/CCryptoBoringSSL/crypto/x509/x509_lu.c b/Sources/CCryptoBoringSSL/crypto/x509/x509_lu.c index 3a4ff365..75444603 100644 --- a/Sources/CCryptoBoringSSL/crypto/x509/x509_lu.c +++ b/Sources/CCryptoBoringSSL/crypto/x509/x509_lu.c @@ -230,13 +230,11 @@ int X509_STORE_CTX_get_by_subject(X509_STORE_CTX *vs, int type, X509_NAME *name, } } - // if (ret->data.ptr != NULL) X509_OBJECT_free_contents(ret); - + // TODO(crbug.com/boringssl/685): This should call + // |X509_OBJECT_free_contents|. ret->type = tmp->type; - ret->data.ptr = tmp->data.ptr; - + ret->data = tmp->data; X509_OBJECT_up_ref_count(ret); - return 1; } @@ -391,8 +389,27 @@ static X509_OBJECT *X509_OBJECT_retrieve_by_subject(STACK_OF(X509_OBJECT) *h, return sk_X509_OBJECT_value(h, idx); } -STACK_OF(X509_OBJECT) *X509_STORE_get0_objects(X509_STORE *st) { - return st->objs; +static X509_OBJECT *x509_object_dup(const X509_OBJECT *obj) { + X509_OBJECT *ret = X509_OBJECT_new(); + if (ret == NULL) { + return NULL; + } + ret->type = obj->type; + ret->data = obj->data; + X509_OBJECT_up_ref_count(ret); + return ret; +} + +STACK_OF(X509_OBJECT) *X509_STORE_get1_objects(X509_STORE *store) { + CRYPTO_MUTEX_lock_read(&store->objs_lock); + STACK_OF(X509_OBJECT) *ret = + sk_X509_OBJECT_deep_copy(store->objs, x509_object_dup, X509_OBJECT_free); + CRYPTO_MUTEX_unlock_read(&store->objs_lock); + return ret; +} + +STACK_OF(X509_OBJECT) *X509_STORE_get0_objects(X509_STORE *store) { + return store->objs; } STACK_OF(X509) *X509_STORE_CTX_get1_certs(X509_STORE_CTX *ctx, X509_NAME *nm) { @@ -587,4 +604,6 @@ void X509_STORE_set_check_crl(X509_STORE *ctx, ctx->check_crl = check_crl; } -X509_STORE *X509_STORE_CTX_get0_store(X509_STORE_CTX *ctx) { return ctx->ctx; } +X509_STORE *X509_STORE_CTX_get0_store(const X509_STORE_CTX *ctx) { + return ctx->ctx; +} diff --git a/Sources/CCryptoBoringSSL/crypto/x509/x509_trs.c b/Sources/CCryptoBoringSSL/crypto/x509/x509_trs.c index eadff0b8..9d5118d3 100644 --- a/Sources/CCryptoBoringSSL/crypto/x509/x509_trs.c +++ b/Sources/CCryptoBoringSSL/crypto/x509/x509_trs.c @@ -63,102 +63,71 @@ #include "internal.h" +typedef struct x509_trust_st X509_TRUST; + +struct x509_trust_st { + int trust; + int (*check_trust)(const X509_TRUST *, X509 *, int); + int nid; +} /* X509_TRUST */; + static int trust_1oidany(const X509_TRUST *trust, X509 *x, int flags); -static int trust_1oid(const X509_TRUST *trust, X509 *x, int flags); static int trust_compat(const X509_TRUST *trust, X509 *x, int flags); static int obj_trust(int id, X509 *x, int flags); -// WARNING: the following table should be kept in order of trust and without -// any gaps so we can just subtract the minimum trust value to get an index -// into the table - static const X509_TRUST trstandard[] = { - {X509_TRUST_COMPAT, 0, trust_compat, (char *)"compatible", 0, NULL}, - {X509_TRUST_SSL_CLIENT, 0, trust_1oidany, (char *)"SSL Client", - NID_client_auth, NULL}, - {X509_TRUST_SSL_SERVER, 0, trust_1oidany, (char *)"SSL Server", - NID_server_auth, NULL}, - {X509_TRUST_EMAIL, 0, trust_1oidany, (char *)"S/MIME email", - NID_email_protect, NULL}, - {X509_TRUST_OBJECT_SIGN, 0, trust_1oidany, (char *)"Object Signer", - NID_code_sign, NULL}, - {X509_TRUST_OCSP_SIGN, 0, trust_1oid, (char *)"OCSP responder", - NID_OCSP_sign, NULL}, - {X509_TRUST_OCSP_REQUEST, 0, trust_1oid, (char *)"OCSP request", - NID_ad_OCSP, NULL}, - {X509_TRUST_TSA, 0, trust_1oidany, (char *)"TSA server", NID_time_stamp, - NULL}}; + {X509_TRUST_COMPAT, trust_compat, 0}, + {X509_TRUST_SSL_CLIENT, trust_1oidany, NID_client_auth}, + {X509_TRUST_SSL_SERVER, trust_1oidany, NID_server_auth}, + {X509_TRUST_EMAIL, trust_1oidany, NID_email_protect}, + {X509_TRUST_OBJECT_SIGN, trust_1oidany, NID_code_sign}, + {X509_TRUST_TSA, trust_1oidany, NID_time_stamp}}; + +static const X509_TRUST *X509_TRUST_get0(int id) { + for (size_t i = 0; i < OPENSSL_ARRAY_SIZE(trstandard); i++) { + if (trstandard[i].trust == id) { + return &trstandard[i]; + } + } + return NULL; +} int X509_check_trust(X509 *x, int id, int flags) { - int idx; if (id == -1) { - return 1; + return X509_TRUST_TRUSTED; } // We get this as a default value if (id == 0) { - int rv; - rv = obj_trust(NID_anyExtendedKeyUsage, x, 0); + int rv = obj_trust(NID_anyExtendedKeyUsage, x, 0); if (rv != X509_TRUST_UNTRUSTED) { return rv; } return trust_compat(NULL, x, 0); } - idx = X509_TRUST_get_by_id(id); - if (idx == -1) { + const X509_TRUST *pt = X509_TRUST_get0(id); + if (pt == NULL) { + // Unknown trust IDs are silently reintrepreted as NIDs. This is unreachable + // from the certificate verifier itself, but wpa_supplicant relies on it. + // Note this relies on commonly-used NIDs and trust IDs not colliding. return obj_trust(id, x, flags); } - const X509_TRUST *pt = X509_TRUST_get0(idx); return pt->check_trust(pt, x, flags); } -int X509_TRUST_get_count(void) { return OPENSSL_ARRAY_SIZE(trstandard); } - -const X509_TRUST *X509_TRUST_get0(int idx) { - if (idx < 0 || (size_t)idx >= OPENSSL_ARRAY_SIZE(trstandard)) { - return NULL; - } - return trstandard + idx; +int X509_is_valid_trust_id(int trust) { + return X509_TRUST_get0(trust) != NULL; } -int X509_TRUST_get_by_id(int id) { - if (id >= X509_TRUST_MIN && id <= X509_TRUST_MAX) { - return id - X509_TRUST_MIN; - } - return -1; -} - -int X509_TRUST_set(int *t, int trust) { - if (X509_TRUST_get_by_id(trust) == -1) { - OPENSSL_PUT_ERROR(X509, X509_R_INVALID_TRUST); - return 0; - } - *t = trust; - return 1; -} - -int X509_TRUST_get_flags(const X509_TRUST *xp) { return xp->flags; } - -char *X509_TRUST_get0_name(const X509_TRUST *xp) { return xp->name; } - -int X509_TRUST_get_trust(const X509_TRUST *xp) { return xp->trust; } - static int trust_1oidany(const X509_TRUST *trust, X509 *x, int flags) { if (x->aux && (x->aux->trust || x->aux->reject)) { - return obj_trust(trust->arg1, x, flags); + return obj_trust(trust->nid, x, flags); } // we don't have any trust settings: for compatibility we return trusted // if it is self signed return trust_compat(trust, x, flags); } -static int trust_1oid(const X509_TRUST *trust, X509 *x, int flags) { - if (x->aux) { - return obj_trust(trust->arg1, x, flags); - } - return X509_TRUST_UNTRUSTED; -} - static int trust_compat(const X509_TRUST *trust, X509 *x, int flags) { if (!x509v3_cache_extensions(x)) { return X509_TRUST_UNTRUSTED; @@ -171,24 +140,21 @@ static int trust_compat(const X509_TRUST *trust, X509 *x, int flags) { } static int obj_trust(int id, X509 *x, int flags) { - ASN1_OBJECT *obj; - size_t i; - X509_CERT_AUX *ax; - ax = x->aux; + X509_CERT_AUX *ax = x->aux; if (!ax) { return X509_TRUST_UNTRUSTED; } if (ax->reject) { - for (i = 0; i < sk_ASN1_OBJECT_num(ax->reject); i++) { - obj = sk_ASN1_OBJECT_value(ax->reject, i); + for (size_t i = 0; i < sk_ASN1_OBJECT_num(ax->reject); i++) { + const ASN1_OBJECT *obj = sk_ASN1_OBJECT_value(ax->reject, i); if (OBJ_obj2nid(obj) == id) { return X509_TRUST_REJECTED; } } } if (ax->trust) { - for (i = 0; i < sk_ASN1_OBJECT_num(ax->trust); i++) { - obj = sk_ASN1_OBJECT_value(ax->trust, i); + for (size_t i = 0; i < sk_ASN1_OBJECT_num(ax->trust); i++) { + const ASN1_OBJECT *obj = sk_ASN1_OBJECT_value(ax->trust, i); if (OBJ_obj2nid(obj) == id) { return X509_TRUST_TRUSTED; } diff --git a/Sources/CCryptoBoringSSL/crypto/x509/x509_vfy.c b/Sources/CCryptoBoringSSL/crypto/x509/x509_vfy.c index 58b8807d..e9b290a9 100644 --- a/Sources/CCryptoBoringSSL/crypto/x509/x509_vfy.c +++ b/Sources/CCryptoBoringSSL/crypto/x509/x509_vfy.c @@ -182,7 +182,7 @@ int X509_verify_cert(X509_STORE_CTX *ctx) { if (ctx->cert == NULL) { OPENSSL_PUT_ERROR(X509, X509_R_NO_CERT_SET_FOR_US_TO_VERIFY); ctx->error = X509_V_ERR_INVALID_CALL; - return -1; + return 0; } if (ctx->chain != NULL) { @@ -190,7 +190,7 @@ int X509_verify_cert(X509_STORE_CTX *ctx) { // cannot do another one. OPENSSL_PUT_ERROR(X509, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); ctx->error = X509_V_ERR_INVALID_CALL; - return -1; + return 0; } if (ctx->param->flags & @@ -200,7 +200,7 @@ int X509_verify_cert(X509_STORE_CTX *ctx) { // inadvertently skip a CRL check that the caller expects, fail closed. OPENSSL_PUT_ERROR(X509, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); ctx->error = X509_V_ERR_INVALID_CALL; - return -1; + return 0; } // first we make sure the chain we are going to build is present and that @@ -258,7 +258,6 @@ int X509_verify_cert(X509_STORE_CTX *ctx) { if (issuer != NULL) { if (!sk_X509_push(ctx->chain, issuer)) { ctx->error = X509_V_ERR_OUT_OF_MEM; - ok = 0; goto end; } X509_up_ref(issuer); @@ -303,8 +302,7 @@ int X509_verify_cert(X509_STORE_CTX *ctx) { ctx->current_cert = x; ctx->error_depth = i - 1; bad_chain = 1; - ok = call_verify_cb(0, ctx); - if (!ok) { + if (!call_verify_cb(0, ctx)) { goto end; } } else { @@ -347,7 +345,6 @@ int X509_verify_cert(X509_STORE_CTX *ctx) { if (!sk_X509_push(ctx->chain, x)) { X509_free(issuer); ctx->error = X509_V_ERR_OUT_OF_MEM; - ok = 0; goto end; } num++; @@ -358,7 +355,6 @@ int X509_verify_cert(X509_STORE_CTX *ctx) { // If explicitly rejected error if (trust == X509_TRUST_REJECTED) { - ok = 0; goto end; } // If it's not explicitly trusted then check if there is an alternative @@ -404,7 +400,10 @@ int X509_verify_cert(X509_STORE_CTX *ctx) { } ctx->current_cert = x; } else { - sk_X509_push(ctx->chain, chain_ss); + if (!sk_X509_push(ctx->chain, chain_ss)) { + ctx->error = X509_V_ERR_OUT_OF_MEM; + goto end; + } num++; ctx->last_untrusted = num; ctx->current_cert = chain_ss; @@ -414,59 +413,33 @@ int X509_verify_cert(X509_STORE_CTX *ctx) { ctx->error_depth = num - 1; bad_chain = 1; - ok = call_verify_cb(0, ctx); - if (!ok) { + if (!call_verify_cb(0, ctx)) { goto end; } } // We have the chain complete: now we need to check its purpose - ok = check_chain_extensions(ctx); - - if (!ok) { + if (!check_chain_extensions(ctx) || // + !check_id(ctx) || + // We check revocation status after copying parameters because they may be + // needed for CRL signature verification. + !check_revocation(ctx) || // + !internal_verify(ctx) || // + !check_name_constraints(ctx) || + // TODO(davidben): Does |check_policy| still need to be conditioned on + // |!bad_chain|? DoS concerns have been resolved. + (!bad_chain && !check_policy(ctx))) { goto end; } - ok = check_id(ctx); - - if (!ok) { - goto end; - } - - // Check revocation status: we do this after copying parameters because - // they may be needed for CRL signature verification. - ok = check_revocation(ctx); - if (!ok) { - goto end; - } - - // At this point, we have a chain and need to verify it - ok = internal_verify(ctx); - if (!ok) { - goto end; - } - - // Check name constraints - ok = check_name_constraints(ctx); - if (!ok) { - goto end; - } - - // If we get this far, evaluate policies. - if (!bad_chain) { - ok = check_policy(ctx); - } + ok = 1; end: - if (sktmp != NULL) { - sk_X509_free(sktmp); - } - if (chain_ss != NULL) { - X509_free(chain_ss); - } + sk_X509_free(sktmp); + X509_free(chain_ss); // Safety net, error returns must set ctx->error - if (ok <= 0 && ctx->error == X509_V_OK) { + if (!ok && ctx->error == X509_V_OK) { ctx->error = X509_V_ERR_UNSPECIFIED; } return ok; @@ -526,7 +499,7 @@ static X509 *get_trusted_issuer(X509_STORE_CTX *ctx, X509 *x) { // purpose static int check_chain_extensions(X509_STORE_CTX *ctx) { - int ok = 0, plen = 0; + int plen = 0; int purpose = ctx->param->purpose; // Check all untrusted certificates @@ -537,9 +510,8 @@ static int check_chain_extensions(X509_STORE_CTX *ctx) { ctx->error = X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION; ctx->error_depth = i; ctx->current_cert = x; - ok = call_verify_cb(0, ctx); - if (!ok) { - goto end; + if (!call_verify_cb(0, ctx)) { + return 0; } } @@ -548,9 +520,8 @@ static int check_chain_extensions(X509_STORE_CTX *ctx) { ctx->error = X509_V_ERR_INVALID_CA; ctx->error_depth = i; ctx->current_cert = x; - ok = call_verify_cb(0, ctx); - if (!ok) { - goto end; + if (!call_verify_cb(0, ctx)) { + return 0; } } if (ctx->param->purpose > 0 && @@ -558,9 +529,8 @@ static int check_chain_extensions(X509_STORE_CTX *ctx) { ctx->error = X509_V_ERR_INVALID_PURPOSE; ctx->error_depth = i; ctx->current_cert = x; - ok = call_verify_cb(0, ctx); - if (!ok) { - goto end; + if (!call_verify_cb(0, ctx)) { + return 0; } } // Check pathlen if not self issued @@ -569,9 +539,8 @@ static int check_chain_extensions(X509_STORE_CTX *ctx) { ctx->error = X509_V_ERR_PATH_LENGTH_EXCEEDED; ctx->error_depth = i; ctx->current_cert = x; - ok = call_verify_cb(0, ctx); - if (!ok) { - goto end; + if (!call_verify_cb(0, ctx)) { + return 0; } } // Increment path length if not self issued @@ -579,9 +548,8 @@ static int check_chain_extensions(X509_STORE_CTX *ctx) { plen++; } } - ok = 1; -end: - return ok; + + return 1; } static int reject_dns_name_in_common_name(X509 *x509) { @@ -729,24 +697,22 @@ static int check_id(X509_STORE_CTX *ctx) { } static int check_trust(X509_STORE_CTX *ctx) { - int ok; X509 *x = NULL; // Check all trusted certificates in chain for (size_t i = ctx->last_untrusted; i < sk_X509_num(ctx->chain); i++) { x = sk_X509_value(ctx->chain, i); - ok = X509_check_trust(x, ctx->param->trust, 0); + int trust = X509_check_trust(x, ctx->param->trust, 0); // If explicitly trusted return trusted - if (ok == X509_TRUST_TRUSTED) { + if (trust == X509_TRUST_TRUSTED) { return X509_TRUST_TRUSTED; } // If explicitly rejected notify callback and reject if not // overridden. - if (ok == X509_TRUST_REJECTED) { + if (trust == X509_TRUST_REJECTED) { ctx->error_depth = (int)i; ctx->current_cert = x; ctx->error = X509_V_ERR_CERT_REJECTED; - ok = call_verify_cb(0, ctx); - if (!ok) { + if (!call_verify_cb(0, ctx)) { return X509_TRUST_REJECTED; } } @@ -785,9 +751,8 @@ static int check_revocation(X509_STORE_CTX *ctx) { } for (int i = 0; i <= last; i++) { ctx->error_depth = i; - int ok = check_cert(ctx); - if (!ok) { - return ok; + if (!check_cert(ctx)) { + return 0; } } return 1; @@ -807,23 +772,19 @@ static int check_cert(X509_STORE_CTX *ctx) { // TODO(davidben): Remove these callbacks. gRPC currently sets them, but // implements them incorrectly. It is not actually possible to implement // |get_crl| from outside the library. - ok = ctx->get_crl(ctx, &crl, x); - // If error looking up CRL, nothing we can do except notify callback - if (!ok) { + if (!ctx->get_crl(ctx, &crl, x)) { ctx->error = X509_V_ERR_UNABLE_TO_GET_CRL; ok = call_verify_cb(0, ctx); goto err; } + ctx->current_crl = crl; - ok = ctx->check_crl(ctx, crl); - if (!ok) { + if (!ctx->check_crl(ctx, crl) || // + !cert_crl(ctx, crl, x)) { goto err; } - ok = cert_crl(ctx, crl, x); - if (!ok) { - goto err; - } + ok = 1; err: X509_CRL_free(crl); @@ -1133,19 +1094,16 @@ static int crl_crldp_check(X509 *x, X509_CRL *crl, int crl_score) { // Retrieve CRL corresponding to current certificate. static int get_crl(X509_STORE_CTX *ctx, X509_CRL **pcrl, X509 *x) { - int ok; X509 *issuer = NULL; int crl_score = 0; X509_CRL *crl = NULL; - STACK_OF(X509_CRL) *skcrl; - X509_NAME *nm = X509_get_issuer_name(x); - ok = get_crl_sk(ctx, &crl, &issuer, &crl_score, ctx->crls); - if (ok) { + if (get_crl_sk(ctx, &crl, &issuer, &crl_score, ctx->crls)) { goto done; } // Lookup CRLs from store - skcrl = X509_STORE_CTX_get1_crls(ctx, nm); + STACK_OF(X509_CRL) *skcrl = + X509_STORE_CTX_get1_crls(ctx, X509_get_issuer_name(x)); // If no CRLs found and a near match from get_crl_sk use that if (!skcrl && crl) { @@ -1244,8 +1202,6 @@ static int check_crl(X509_STORE_CTX *ctx, X509_CRL *crl) { // Check certificate against CRL static int cert_crl(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x) { - int ok; - X509_REVOKED *rev; // The rules changed for this... previously if a CRL contained unhandled // critical extensions it could still be used to indicate a certificate // was revoked. This has since been changed since critical extension can @@ -1253,16 +1209,15 @@ static int cert_crl(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x) { if (!(ctx->param->flags & X509_V_FLAG_IGNORE_CRITICAL) && (crl->flags & EXFLAG_CRITICAL)) { ctx->error = X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION; - ok = call_verify_cb(0, ctx); - if (!ok) { + if (!call_verify_cb(0, ctx)) { return 0; } } // Look for serial number of certificate in CRL. + X509_REVOKED *rev; if (X509_CRL_get0_by_cert(crl, &rev, x)) { ctx->error = X509_V_ERR_CERT_REVOKED; - ok = call_verify_cb(0, ctx); - if (!ok) { + if (!call_verify_cb(0, ctx)) { return 0; } } @@ -1336,14 +1291,19 @@ static int check_cert_time(X509_STORE_CTX *ctx, X509 *x) { } static int internal_verify(X509_STORE_CTX *ctx) { - int ok = 0; - X509 *xs, *xi; - + // TODO(davidben): This logic is incredibly confusing. Rewrite this: + // + // First, don't allow the verify callback to suppress + // X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY, which will simplify the + // signature check. Then replace jumping into the middle of the loop. It's + // trying to ensure that all certificates see |check_cert_time|, then checking + // the root's self signature when requested, but not breaking partial chains + // in the process. int n = (int)sk_X509_num(ctx->chain); ctx->error_depth = n - 1; n--; - xi = sk_X509_value(ctx->chain, n); - + X509 *xi = sk_X509_value(ctx->chain, n); + X509 *xs; if (x509_check_issued_with_callback(ctx, xi, xi)) { xs = xi; } else { @@ -1354,13 +1314,11 @@ static int internal_verify(X509_STORE_CTX *ctx) { if (n <= 0) { ctx->error = X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE; ctx->current_cert = xi; - ok = call_verify_cb(0, ctx); - goto end; - } else { - n--; - ctx->error_depth = n; - xs = sk_X509_value(ctx->chain, n); + return call_verify_cb(0, ctx); } + n--; + ctx->error_depth = n; + xs = sk_X509_value(ctx->chain, n); } // ctx->error=0; not needed @@ -1375,31 +1333,27 @@ static int internal_verify(X509_STORE_CTX *ctx) { if (pkey == NULL) { ctx->error = X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY; ctx->current_cert = xi; - ok = call_verify_cb(0, ctx); - if (!ok) { - goto end; + if (!call_verify_cb(0, ctx)) { + return 0; } } else if (X509_verify(xs, pkey) <= 0) { ctx->error = X509_V_ERR_CERT_SIGNATURE_FAILURE; ctx->current_cert = xs; - ok = call_verify_cb(0, ctx); - if (!ok) { - goto end; + if (!call_verify_cb(0, ctx)) { + return 0; } } } check_cert: - ok = check_cert_time(ctx, xs); - if (!ok) { - goto end; + if (!check_cert_time(ctx, xs)) { + return 0; } // The last error (if any) is still in the error value ctx->current_cert = xs; - ok = call_verify_cb(1, ctx); - if (!ok) { - goto end; + if (!call_verify_cb(1, ctx)) { + return 0; } n--; @@ -1408,9 +1362,8 @@ static int internal_verify(X509_STORE_CTX *ctx) { xs = sk_X509_value(ctx->chain, n); } } - ok = 1; -end: - return ok; + + return 1; } int X509_cmp_current_time(const ASN1_TIME *ctm) { @@ -1456,14 +1409,7 @@ 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) { - // This function is (usually) called only once, by - // SSL_get_ex_data_X509_STORE_CTX_idx (ssl/ssl_cert.c). - int index; - if (!CRYPTO_get_ex_new_index(&g_ex_data_class, &index, argl, argp, - free_func)) { - return -1; - } - return index; + return CRYPTO_get_ex_new_index_ex(&g_ex_data_class, argl, argp, free_func); } int X509_STORE_CTX_set_ex_data(X509_STORE_CTX *ctx, int idx, void *data) { @@ -1474,53 +1420,51 @@ void *X509_STORE_CTX_get_ex_data(X509_STORE_CTX *ctx, int idx) { return CRYPTO_get_ex_data(&ctx->ex_data, idx); } -int X509_STORE_CTX_get_error(X509_STORE_CTX *ctx) { return ctx->error; } +int X509_STORE_CTX_get_error(const X509_STORE_CTX *ctx) { return ctx->error; } void X509_STORE_CTX_set_error(X509_STORE_CTX *ctx, int err) { ctx->error = err; } -int X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx) { +int X509_STORE_CTX_get_error_depth(const X509_STORE_CTX *ctx) { return ctx->error_depth; } -X509 *X509_STORE_CTX_get_current_cert(X509_STORE_CTX *ctx) { +X509 *X509_STORE_CTX_get_current_cert(const X509_STORE_CTX *ctx) { return ctx->current_cert; } -STACK_OF(X509) *X509_STORE_CTX_get_chain(X509_STORE_CTX *ctx) { +STACK_OF(X509) *X509_STORE_CTX_get_chain(const X509_STORE_CTX *ctx) { return ctx->chain; } -STACK_OF(X509) *X509_STORE_CTX_get0_chain(X509_STORE_CTX *ctx) { +STACK_OF(X509) *X509_STORE_CTX_get0_chain(const X509_STORE_CTX *ctx) { return ctx->chain; } -STACK_OF(X509) *X509_STORE_CTX_get1_chain(X509_STORE_CTX *ctx) { +STACK_OF(X509) *X509_STORE_CTX_get1_chain(const X509_STORE_CTX *ctx) { if (!ctx->chain) { return NULL; } return X509_chain_up_ref(ctx->chain); } -X509_CRL *X509_STORE_CTX_get0_current_crl(X509_STORE_CTX *ctx) { +X509_CRL *X509_STORE_CTX_get0_current_crl(const X509_STORE_CTX *ctx) { return ctx->current_crl; } -X509_STORE_CTX *X509_STORE_CTX_get0_parent_ctx(X509_STORE_CTX *ctx) { +X509_STORE_CTX *X509_STORE_CTX_get0_parent_ctx(const X509_STORE_CTX *ctx) { // In OpenSSL, an |X509_STORE_CTX| sometimes has a parent context during CRL // path validation for indirect CRLs. We require the CRL to be issued // somewhere along the certificate path, so this is always NULL. return NULL; } -void X509_STORE_CTX_set_cert(X509_STORE_CTX *ctx, X509 *x) { ctx->cert = x; } - void X509_STORE_CTX_set_chain(X509_STORE_CTX *ctx, STACK_OF(X509) *sk) { ctx->untrusted = sk; } -STACK_OF(X509) *X509_STORE_CTX_get0_untrusted(X509_STORE_CTX *ctx) { +STACK_OF(X509) *X509_STORE_CTX_get0_untrusted(const X509_STORE_CTX *ctx) { return ctx->untrusted; } @@ -1529,62 +1473,40 @@ void X509_STORE_CTX_set0_crls(X509_STORE_CTX *ctx, STACK_OF(X509_CRL) *sk) { } int X509_STORE_CTX_set_purpose(X509_STORE_CTX *ctx, int purpose) { - return X509_STORE_CTX_purpose_inherit(ctx, 0, purpose, 0); + // If |purpose| is zero, this function historically silently did nothing. + if (purpose == 0) { + return 1; + } + + const X509_PURPOSE *pobj = X509_PURPOSE_get0(purpose); + if (pobj == NULL) { + OPENSSL_PUT_ERROR(X509, X509_R_UNKNOWN_PURPOSE_ID); + return 0; + } + + int trust = X509_PURPOSE_get_trust(pobj); + if (!X509_STORE_CTX_set_trust(ctx, trust)) { + return 0; + } + + if (ctx->param->purpose == 0) { + ctx->param->purpose = purpose; + } + return 1; } int X509_STORE_CTX_set_trust(X509_STORE_CTX *ctx, int trust) { - return X509_STORE_CTX_purpose_inherit(ctx, 0, 0, trust); -} - -// This function is used to set the X509_STORE_CTX purpose and trust values. -// This is intended to be used when another structure has its own trust and -// purpose values which (if set) will be inherited by the ctx. If they aren't -// set then we will usually have a default purpose in mind which should then -// be used to set the trust value. An example of this is SSL use: an SSL -// structure will have its own purpose and trust settings which the -// application can set: if they aren't set then we use the default of SSL -// client/server. - -int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose, - int purpose, int trust) { - int idx; - // If purpose not set use default - if (!purpose) { - purpose = def_purpose; - } - // If we have a purpose then check it is valid - if (purpose) { - idx = X509_PURPOSE_get_by_id(purpose); - if (idx == -1) { - OPENSSL_PUT_ERROR(X509, X509_R_UNKNOWN_PURPOSE_ID); - return 0; - } - const X509_PURPOSE *ptmp = X509_PURPOSE_get0(idx); - if (ptmp->trust == X509_TRUST_DEFAULT) { - idx = X509_PURPOSE_get_by_id(def_purpose); - if (idx == -1) { - OPENSSL_PUT_ERROR(X509, X509_R_UNKNOWN_PURPOSE_ID); - return 0; - } - ptmp = X509_PURPOSE_get0(idx); - } - // If trust not set then get from purpose default - if (!trust) { - trust = ptmp->trust; - } - } - if (trust) { - idx = X509_TRUST_get_by_id(trust); - if (idx == -1) { - OPENSSL_PUT_ERROR(X509, X509_R_UNKNOWN_TRUST_ID); - return 0; - } + // If |trust| is zero, this function historically silently did nothing. + if (trust == 0) { + return 1; } - if (purpose && !ctx->param->purpose) { - ctx->param->purpose = purpose; + if (!X509_is_valid_trust_id(trust)) { + OPENSSL_PUT_ERROR(X509, X509_R_UNKNOWN_TRUST_ID); + return 0; } - if (trust && !ctx->param->trust) { + + if (ctx->param->trust == 0) { ctx->param->trust = trust; } return 1; @@ -1699,9 +1621,7 @@ void X509_STORE_CTX_set_time(X509_STORE_CTX *ctx, unsigned long flags, X509_STORE_CTX_set_time_posix(ctx, flags, t); } -X509 *X509_STORE_CTX_get0_cert(X509_STORE_CTX *ctx) { - return ctx->cert; -} +X509 *X509_STORE_CTX_get0_cert(const X509_STORE_CTX *ctx) { return ctx->cert; } void X509_STORE_CTX_set_verify_cb(X509_STORE_CTX *ctx, int (*verify_cb)(int, X509_STORE_CTX *)) { @@ -1709,8 +1629,7 @@ void X509_STORE_CTX_set_verify_cb(X509_STORE_CTX *ctx, } int X509_STORE_CTX_set_default(X509_STORE_CTX *ctx, const char *name) { - const X509_VERIFY_PARAM *param; - param = X509_VERIFY_PARAM_lookup(name); + const X509_VERIFY_PARAM *param = X509_VERIFY_PARAM_lookup(name); if (!param) { return 0; } diff --git a/Sources/CCryptoBoringSSL/crypto/x509/x509_vpm.c b/Sources/CCryptoBoringSSL/crypto/x509/x509_vpm.c index f7175b2f..67236014 100644 --- a/Sources/CCryptoBoringSSL/crypto/x509/x509_vpm.c +++ b/Sources/CCryptoBoringSSL/crypto/x509/x509_vpm.c @@ -269,11 +269,22 @@ unsigned long X509_VERIFY_PARAM_get_flags(const X509_VERIFY_PARAM *param) { } int X509_VERIFY_PARAM_set_purpose(X509_VERIFY_PARAM *param, int purpose) { - return X509_PURPOSE_set(¶m->purpose, purpose); + if (X509_PURPOSE_get0(purpose) == NULL) { + OPENSSL_PUT_ERROR(X509V3, X509V3_R_INVALID_PURPOSE); + return 0; + } + param->purpose = purpose; + return 1; } int X509_VERIFY_PARAM_set_trust(X509_VERIFY_PARAM *param, int trust) { - return X509_TRUST_set(¶m->trust, trust); + if (!X509_is_valid_trust_id(trust)) { + OPENSSL_PUT_ERROR(X509, X509_R_UNKNOWN_TRUST_ID); + return 0; + } + + param->trust = trust; + return 1; } void X509_VERIFY_PARAM_set_depth(X509_VERIFY_PARAM *param, int depth) { diff --git a/Sources/CCryptoBoringSSL/crypto/x509/x_crl.c b/Sources/CCryptoBoringSSL/crypto/x509/x_crl.c index 7aa3c8eb..7fa6ebcb 100644 --- a/Sources/CCryptoBoringSSL/crypto/x509/x_crl.c +++ b/Sources/CCryptoBoringSSL/crypto/x509/x_crl.c @@ -63,6 +63,7 @@ #include #include #include +#include #include diff --git a/Sources/CCryptoBoringSSL/crypto/x509/x_name.c b/Sources/CCryptoBoringSSL/crypto/x509/x_name.c index f15d2870..2c6fd9e6 100644 --- a/Sources/CCryptoBoringSSL/crypto/x509/x_name.c +++ b/Sources/CCryptoBoringSSL/crypto/x509/x_name.c @@ -511,17 +511,17 @@ int X509_NAME_set(X509_NAME **xn, X509_NAME *name) { int X509_NAME_ENTRY_set(const X509_NAME_ENTRY *ne) { return ne->set; } -int X509_NAME_get0_der(X509_NAME *nm, const unsigned char **pder, - size_t *pderlen) { +int X509_NAME_get0_der(X509_NAME *nm, const unsigned char **out_der, + size_t *out_der_len) { // Make sure encoding is valid if (i2d_X509_NAME(nm, NULL) <= 0) { return 0; } - if (pder != NULL) { - *pder = (unsigned char *)nm->bytes->data; + if (out_der != NULL) { + *out_der = (unsigned char *)nm->bytes->data; } - if (pderlen != NULL) { - *pderlen = nm->bytes->length; + if (out_der_len != NULL) { + *out_der_len = nm->bytes->length; } return 1; } diff --git a/Sources/CCryptoBoringSSL/crypto/x509/x_x509.c b/Sources/CCryptoBoringSSL/crypto/x509/x_x509.c index 5fd246a5..bc0160ee 100644 --- a/Sources/CCryptoBoringSSL/crypto/x509/x_x509.c +++ b/Sources/CCryptoBoringSSL/crypto/x509/x_x509.c @@ -380,12 +380,7 @@ int X509_up_ref(X509 *x) { int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_unused *unused, CRYPTO_EX_dup *dup_unused, CRYPTO_EX_free *free_func) { - int index; - if (!CRYPTO_get_ex_new_index(&g_ex_data_class, &index, argl, argp, - free_func)) { - return -1; - } - return index; + return CRYPTO_get_ex_new_index_ex(&g_ex_data_class, argl, argp, free_func); } int X509_set_ex_data(X509 *r, int idx, void *arg) { diff --git a/Sources/CCryptoBoringSSL/crypto/x509/x_x509a.c b/Sources/CCryptoBoringSSL/crypto/x509/x_x509a.c index f451811c..a80c8cfc 100644 --- a/Sources/CCryptoBoringSSL/crypto/x509/x_x509a.c +++ b/Sources/CCryptoBoringSSL/crypto/x509/x_x509a.c @@ -90,7 +90,7 @@ static X509_CERT_AUX *aux_get(X509 *x) { return x->aux; } -int X509_alias_set1(X509 *x, const unsigned char *name, ossl_ssize_t len) { +int X509_alias_set1(X509 *x, const uint8_t *name, ossl_ssize_t len) { X509_CERT_AUX *aux; // TODO(davidben): Empty aliases are not meaningful in PKCS#12, and the // getters cannot quite represent them. Also erase the object if |len| is @@ -112,7 +112,7 @@ int X509_alias_set1(X509 *x, const unsigned char *name, ossl_ssize_t len) { return ASN1_STRING_set(aux->alias, name, len); } -int X509_keyid_set1(X509 *x, const unsigned char *id, ossl_ssize_t len) { +int X509_keyid_set1(X509 *x, const uint8_t *id, ossl_ssize_t len) { X509_CERT_AUX *aux; // TODO(davidben): Empty key IDs are not meaningful in PKCS#12, and the // getters cannot quite represent them. Also erase the object if |len| is @@ -134,7 +134,7 @@ int X509_keyid_set1(X509 *x, const unsigned char *id, ossl_ssize_t len) { return ASN1_STRING_set(aux->keyid, id, len); } -unsigned char *X509_alias_get0(X509 *x, int *out_len) { +const uint8_t *X509_alias_get0(const X509 *x, int *out_len) { const ASN1_UTF8STRING *alias = x->aux != NULL ? x->aux->alias : NULL; if (out_len != NULL) { *out_len = alias != NULL ? alias->length : 0; @@ -142,7 +142,7 @@ unsigned char *X509_alias_get0(X509 *x, int *out_len) { return alias != NULL ? alias->data : NULL; } -unsigned char *X509_keyid_get0(X509 *x, int *out_len) { +const uint8_t *X509_keyid_get0(const X509 *x, int *out_len) { const ASN1_OCTET_STRING *keyid = x->aux != NULL ? x->aux->keyid : NULL; if (out_len != NULL) { *out_len = keyid != NULL ? keyid->length : 0; diff --git a/Sources/CCryptoBoringSSL/hash.txt b/Sources/CCryptoBoringSSL/hash.txt index 7a0dc95a..74b3edbd 100644 --- a/Sources/CCryptoBoringSSL/hash.txt +++ b/Sources/CCryptoBoringSSL/hash.txt @@ -1 +1 @@ -This directory is derived from BoringSSL cloned from https://boringssl.googlesource.com/boringssl at revision 7a813621dac6878ab53b6ed7392939a8982226e8 +This directory is derived from BoringSSL cloned from https://boringssl.googlesource.com/boringssl at revision dbad745811195c00b729efd0ee0a09b7d9fce1d2 diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_asn1.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_asn1.h index 8a7517e7..dbf5b5b8 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_asn1.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_asn1.h @@ -1636,18 +1636,18 @@ OPENSSL_EXPORT int ASN1_STRING_print(BIO *out, const ASN1_STRING *str); // ASN1_STRFLGS_ESC_2253 causes characters to be escaped as in RFC 2253, section // 2.4. -#define ASN1_STRFLGS_ESC_2253 1 +#define ASN1_STRFLGS_ESC_2253 1ul // ASN1_STRFLGS_ESC_CTRL causes all control characters to be escaped. -#define ASN1_STRFLGS_ESC_CTRL 2 +#define ASN1_STRFLGS_ESC_CTRL 2ul // ASN1_STRFLGS_ESC_MSB causes all characters above 127 to be escaped. -#define ASN1_STRFLGS_ESC_MSB 4 +#define ASN1_STRFLGS_ESC_MSB 4ul // ASN1_STRFLGS_ESC_QUOTE causes the string to be surrounded by quotes, rather // than using backslashes, when characters are escaped. Fewer characters will // require escapes in this case. -#define ASN1_STRFLGS_ESC_QUOTE 8 +#define ASN1_STRFLGS_ESC_QUOTE 8ul // ASN1_STRFLGS_UTF8_CONVERT causes the string to be encoded as UTF-8, with each // byte in the UTF-8 encoding treated as an individual character for purposes of @@ -1655,29 +1655,29 @@ OPENSSL_EXPORT int ASN1_STRING_print(BIO *out, const ASN1_STRING *str); // as a character, with wide characters escaped as "\Uxxxx" or "\Wxxxxxxxx". // Note this can be ambiguous if |ASN1_STRFLGS_ESC_*| are all unset. In that // case, backslashes are not escaped, but wide characters are. -#define ASN1_STRFLGS_UTF8_CONVERT 0x10 +#define ASN1_STRFLGS_UTF8_CONVERT 0x10ul // ASN1_STRFLGS_IGNORE_TYPE causes the string type to be ignored. The // |ASN1_STRING| in-memory representation will be printed directly. -#define ASN1_STRFLGS_IGNORE_TYPE 0x20 +#define ASN1_STRFLGS_IGNORE_TYPE 0x20ul // ASN1_STRFLGS_SHOW_TYPE causes the string type to be included in the output. -#define ASN1_STRFLGS_SHOW_TYPE 0x40 +#define ASN1_STRFLGS_SHOW_TYPE 0x40ul // ASN1_STRFLGS_DUMP_ALL causes all strings to be printed as a hexdump, using // RFC 2253 hexstring notation, such as "#0123456789ABCDEF". -#define ASN1_STRFLGS_DUMP_ALL 0x80 +#define ASN1_STRFLGS_DUMP_ALL 0x80ul // ASN1_STRFLGS_DUMP_UNKNOWN behaves like |ASN1_STRFLGS_DUMP_ALL| but only // applies to values of unknown type. If unset, unknown values will print // their contents as single-byte characters with escape sequences. -#define ASN1_STRFLGS_DUMP_UNKNOWN 0x100 +#define ASN1_STRFLGS_DUMP_UNKNOWN 0x100ul // ASN1_STRFLGS_DUMP_DER causes hexdumped strings (as determined by // |ASN1_STRFLGS_DUMP_ALL| or |ASN1_STRFLGS_DUMP_UNKNOWN|) to print the entire // DER element as in RFC 2253, rather than only the contents of the // |ASN1_STRING|. -#define ASN1_STRFLGS_DUMP_DER 0x200 +#define ASN1_STRFLGS_DUMP_DER 0x200ul // ASN1_STRFLGS_RFC2253 causes the string to be escaped as in RFC 2253, // additionally escaping control characters. diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_base.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_base.h index 34d6b47d..bf897fd5 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_base.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_base.h @@ -117,7 +117,7 @@ extern "C" { // A consumer may use this symbol in the preprocessor to temporarily build // against multiple revisions of BoringSSL at the same time. It is not // recommended to do so for longer than is necessary. -#define BORINGSSL_API_VERSION 29 +#define BORINGSSL_API_VERSION 32 #if defined(BORINGSSL_SHARED_LIBRARY) @@ -366,6 +366,7 @@ typedef struct sha_state_st SHA_CTX; typedef struct spake2_ctx_st SPAKE2_CTX; typedef struct srtp_protection_profile_st SRTP_PROTECTION_PROFILE; typedef struct ssl_cipher_st SSL_CIPHER; +typedef struct ssl_credential_st SSL_CREDENTIAL; typedef struct ssl_ctx_st SSL_CTX; typedef struct ssl_early_callback_ctx SSL_CLIENT_HELLO; typedef struct ssl_ech_keys_st SSL_ECH_KEYS; @@ -386,11 +387,11 @@ typedef struct x509_attributes_st X509_ATTRIBUTE; typedef struct x509_lookup_st X509_LOOKUP; typedef struct x509_lookup_method_st X509_LOOKUP_METHOD; typedef struct x509_object_st X509_OBJECT; +typedef struct x509_purpose_st X509_PURPOSE; typedef struct x509_revoked_st X509_REVOKED; typedef struct x509_st X509; typedef struct x509_store_ctx_st X509_STORE_CTX; typedef struct x509_store_st X509_STORE; -typedef struct x509_trust_st X509_TRUST; typedef void *OPENSSL_BLOCK; diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_bio.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_bio.h index 88084ca8..839bf205 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_bio.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_bio.h @@ -269,11 +269,11 @@ OPENSSL_EXPORT int BIO_set_close(BIO *bio, int close_flag); // BIO_number_read returns the number of bytes that have been read from // |bio|. -OPENSSL_EXPORT size_t BIO_number_read(const BIO *bio); +OPENSSL_EXPORT uint64_t BIO_number_read(const BIO *bio); // BIO_number_written returns the number of bytes that have been written to // |bio|. -OPENSSL_EXPORT size_t BIO_number_written(const BIO *bio); +OPENSSL_EXPORT uint64_t BIO_number_written(const BIO *bio); // Managing chains of BIOs. @@ -473,41 +473,82 @@ OPENSSL_EXPORT int BIO_get_fd(BIO *bio, int *out_fd); OPENSSL_EXPORT const BIO_METHOD *BIO_s_file(void); // BIO_new_file creates a file BIO by opening |filename| with the given mode. -// See the |fopen| manual page for details of the mode argument. +// See the |fopen| manual page for details of the mode argument. On Windows, +// files may be opened in either binary or text mode so, as in |fopen|, callers +// must specify the desired option in |mode|. OPENSSL_EXPORT BIO *BIO_new_file(const char *filename, const char *mode); -// BIO_new_fp creates a new file BIO that wraps the given |FILE|. If -// |close_flag| is |BIO_CLOSE|, then |fclose| will be called on |stream| when -// the BIO is closed. -OPENSSL_EXPORT BIO *BIO_new_fp(FILE *stream, int close_flag); +// BIO_FP_TEXT indicates the |FILE| should be switched to text mode on Windows. +// It has no effect on non-Windows platforms. +#define BIO_FP_TEXT 0x10 + +// BIO_new_fp creates a new file BIO that wraps |file|. If |flags| contains +// |BIO_CLOSE|, then |fclose| will be called on |file| when the BIO is closed. +// +// On Windows, if |flags| contains |BIO_FP_TEXT|, this function will +// additionally switch |file| to text mode. This is not recommended, but may be +// required for OpenSSL compatibility. If |file| was not already in text mode, +// mode changes can cause unflushed data in |file| to be written in unexpected +// ways. See |_setmode| in Windows documentation for details. +// +// Unlike OpenSSL, if |flags| does not contain |BIO_FP_TEXT|, the translation +// mode of |file| is left as-is. In OpenSSL, |file| will be set to binary, with +// the same pitfalls as above. BoringSSL does not do this so that wrapping a +// |FILE| in a |BIO| will not inadvertently change its state. +// +// To avoid these pitfalls, callers should set the desired translation mode when +// opening the file. If targeting just BoringSSL, this is sufficient. If +// targeting both OpenSSL and BoringSSL, callers should set |BIO_FP_TEXT| to +// match the desired state of the file. +OPENSSL_EXPORT BIO *BIO_new_fp(FILE *file, int flags); // BIO_get_fp sets |*out_file| to the current |FILE| for |bio|. It returns one // on success and zero otherwise. OPENSSL_EXPORT int BIO_get_fp(BIO *bio, FILE **out_file); -// BIO_set_fp sets the |FILE| for |bio|. If |close_flag| is |BIO_CLOSE| then +// BIO_set_fp sets the |FILE| for |bio|. If |flags| contains |BIO_CLOSE| then // |fclose| will be called on |file| when |bio| is closed. It returns one on // success and zero otherwise. -OPENSSL_EXPORT int BIO_set_fp(BIO *bio, FILE *file, int close_flag); +// +// On Windows, if |flags| contains |BIO_FP_TEXT|, this function will +// additionally switch |file| to text mode. This is not recommended, but may be +// required for OpenSSL compatibility. If |file| was not already in text mode, +// mode changes can cause unflushed data in |file| to be written in unexpected +// ways. See |_setmode| in Windows documentation for details. +// +// Unlike OpenSSL, if |flags| does not contain |BIO_FP_TEXT|, the translation +// mode of |file| is left as-is. In OpenSSL, |file| will be set to binary, with +// the same pitfalls as above. BoringSSL does not do this so that wrapping a +// |FILE| in a |BIO| will not inadvertently change its state. +// +// To avoid these pitfalls, callers should set the desired translation mode when +// opening the file. If targeting just BoringSSL, this is sufficient. If +// targeting both OpenSSL and BoringSSL, callers should set |BIO_FP_TEXT| to +// match the desired state of the file. +OPENSSL_EXPORT int BIO_set_fp(BIO *bio, FILE *file, int flags); // BIO_read_filename opens |filename| for reading and sets the result as the // |FILE| for |bio|. It returns one on success and zero otherwise. The |FILE| -// will be closed when |bio| is freed. +// will be closed when |bio| is freed. On Windows, the file is opened in binary +// mode. OPENSSL_EXPORT int BIO_read_filename(BIO *bio, const char *filename); // BIO_write_filename opens |filename| for writing and sets the result as the // |FILE| for |bio|. It returns one on success and zero otherwise. The |FILE| -// will be closed when |bio| is freed. +// will be closed when |bio| is freed. On Windows, the file is opened in binary +// mode. OPENSSL_EXPORT int BIO_write_filename(BIO *bio, const char *filename); // BIO_append_filename opens |filename| for appending and sets the result as // the |FILE| for |bio|. It returns one on success and zero otherwise. The -// |FILE| will be closed when |bio| is freed. +// |FILE| will be closed when |bio| is freed. On Windows, the file is opened in +// binary mode. OPENSSL_EXPORT int BIO_append_filename(BIO *bio, const char *filename); // BIO_rw_filename opens |filename| for reading and writing and sets the result // as the |FILE| for |bio|. It returns one on success and zero otherwise. The -// |FILE| will be closed when |bio| is freed. +// |FILE| will be closed when |bio| is freed. On Windows, the file is opened in +// binary mode. OPENSSL_EXPORT int BIO_rw_filename(BIO *bio, const char *filename); // BIO_tell returns the file offset of |bio|, or a negative number on error or @@ -824,37 +865,37 @@ OPENSSL_EXPORT int BIO_meth_set_puts(BIO_METHOD *method, // or change the data in any way. #define BIO_FLAGS_MEM_RDONLY 0x200 -// These are the 'types' of BIOs -#define BIO_TYPE_NONE 0 -#define BIO_TYPE_MEM (1 | 0x0400) -#define BIO_TYPE_FILE (2 | 0x0400) -#define BIO_TYPE_FD (4 | 0x0400 | 0x0100) -#define BIO_TYPE_SOCKET (5 | 0x0400 | 0x0100) -#define BIO_TYPE_NULL (6 | 0x0400) -#define BIO_TYPE_SSL (7 | 0x0200) -#define BIO_TYPE_MD (8 | 0x0200) // passive filter -#define BIO_TYPE_BUFFER (9 | 0x0200) // filter -#define BIO_TYPE_CIPHER (10 | 0x0200) // filter -#define BIO_TYPE_BASE64 (11 | 0x0200) // filter -#define BIO_TYPE_CONNECT (12 | 0x0400 | 0x0100) // socket - connect -#define BIO_TYPE_ACCEPT (13 | 0x0400 | 0x0100) // socket for accept -#define BIO_TYPE_PROXY_CLIENT (14 | 0x0200) // client proxy BIO -#define BIO_TYPE_PROXY_SERVER (15 | 0x0200) // server proxy BIO -#define BIO_TYPE_NBIO_TEST (16 | 0x0200) // server proxy BIO -#define BIO_TYPE_NULL_FILTER (17 | 0x0200) -#define BIO_TYPE_BER (18 | 0x0200) // BER -> bin filter -#define BIO_TYPE_BIO (19 | 0x0400) // (half a) BIO pair -#define BIO_TYPE_LINEBUFFER (20 | 0x0200) // filter -#define BIO_TYPE_DGRAM (21 | 0x0400 | 0x0100) -#define BIO_TYPE_ASN1 (22 | 0x0200) // filter -#define BIO_TYPE_COMP (23 | 0x0200) // filter - // BIO_TYPE_DESCRIPTOR denotes that the |BIO| responds to the |BIO_C_SET_FD| // (|BIO_set_fd|) and |BIO_C_GET_FD| (|BIO_get_fd|) control hooks. #define BIO_TYPE_DESCRIPTOR 0x0100 // socket, fd, connect or accept #define BIO_TYPE_FILTER 0x0200 #define BIO_TYPE_SOURCE_SINK 0x0400 +// These are the 'types' of BIOs +#define BIO_TYPE_NONE 0 +#define BIO_TYPE_MEM (1 | BIO_TYPE_SOURCE_SINK) +#define BIO_TYPE_FILE (2 | BIO_TYPE_SOURCE_SINK) +#define BIO_TYPE_FD (4 | BIO_TYPE_SOURCE_SINK | BIO_TYPE_DESCRIPTOR) +#define BIO_TYPE_SOCKET (5 | BIO_TYPE_SOURCE_SINK | BIO_TYPE_DESCRIPTOR) +#define BIO_TYPE_NULL (6 | BIO_TYPE_SOURCE_SINK) +#define BIO_TYPE_SSL (7 | BIO_TYPE_FILTER) +#define BIO_TYPE_MD (8 | BIO_TYPE_FILTER) +#define BIO_TYPE_BUFFER (9 | BIO_TYPE_FILTER) +#define BIO_TYPE_CIPHER (10 | BIO_TYPE_FILTER) +#define BIO_TYPE_BASE64 (11 | BIO_TYPE_FILTER) +#define BIO_TYPE_CONNECT (12 | BIO_TYPE_SOURCE_SINK | BIO_TYPE_DESCRIPTOR) +#define BIO_TYPE_ACCEPT (13 | BIO_TYPE_SOURCE_SINK | BIO_TYPE_DESCRIPTOR) +#define BIO_TYPE_PROXY_CLIENT (14 | BIO_TYPE_FILTER) +#define BIO_TYPE_PROXY_SERVER (15 | BIO_TYPE_FILTER) +#define BIO_TYPE_NBIO_TEST (16 | BIO_TYPE_FILTER) +#define BIO_TYPE_NULL_FILTER (17 | BIO_TYPE_FILTER) +#define BIO_TYPE_BER (18 | BIO_TYPE_FILTER) // BER -> bin filter +#define BIO_TYPE_BIO (19 | BIO_TYPE_SOURCE_SINK) // (half a) BIO pair +#define BIO_TYPE_LINEBUFFER (20 | BIO_TYPE_FILTER) +#define BIO_TYPE_DGRAM (21 | BIO_TYPE_SOURCE_SINK | BIO_TYPE_DESCRIPTOR) +#define BIO_TYPE_ASN1 (22 | BIO_TYPE_FILTER) +#define BIO_TYPE_COMP (23 | BIO_TYPE_FILTER) + // BIO_TYPE_START is the first user-allocated |BIO| type. No pre-defined type, // flag bits aside, may exceed this value. #define BIO_TYPE_START 128 @@ -894,7 +935,7 @@ struct bio_st { // next_bio points to the next |BIO| in a chain. This |BIO| owns a reference // to |next_bio|. BIO *next_bio; // used by filter BIOs - size_t num_read, num_write; + uint64_t num_read, num_write; }; #define BIO_C_SET_CONNECT 100 diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_boringssl_prefix_symbols.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_boringssl_prefix_symbols.h index 84940382..4b869d62 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_boringssl_prefix_symbols.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_boringssl_prefix_symbols.h @@ -510,7 +510,6 @@ #define CBS_asn1_oid_to_text BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBS_asn1_oid_to_text) #define CBS_contains_zero_byte BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBS_contains_zero_byte) #define CBS_copy_bytes BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBS_copy_bytes) -#define CBS_data BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBS_data) #define CBS_get_any_asn1 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBS_get_any_asn1) #define CBS_get_any_asn1_element BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBS_get_any_asn1_element) #define CBS_get_any_ber_asn1_element BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBS_get_any_ber_asn1_element) @@ -543,12 +542,10 @@ #define CBS_get_until_first BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBS_get_until_first) #define CBS_get_utf32_be BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBS_get_utf32_be) #define CBS_get_utf8 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBS_get_utf8) -#define CBS_init BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBS_init) #define CBS_is_unsigned_asn1_integer BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBS_is_unsigned_asn1_integer) #define CBS_is_valid_asn1_bitstring BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBS_is_valid_asn1_bitstring) #define CBS_is_valid_asn1_integer BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBS_is_valid_asn1_integer) #define CBS_is_valid_asn1_oid BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBS_is_valid_asn1_oid) -#define CBS_len BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBS_len) #define CBS_mem_equal BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBS_mem_equal) #define CBS_parse_generalized_time BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBS_parse_generalized_time) #define CBS_parse_utc_time BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CBS_parse_utc_time) @@ -623,7 +620,7 @@ #define CRYPTO_get_dynlock_destroy_callback BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_get_dynlock_destroy_callback) #define CRYPTO_get_dynlock_lock_callback BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_get_dynlock_lock_callback) #define CRYPTO_get_ex_data BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_get_ex_data) -#define CRYPTO_get_ex_new_index BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_get_ex_new_index) +#define CRYPTO_get_ex_new_index_ex BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_get_ex_new_index_ex) #define CRYPTO_get_fork_generation BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_get_fork_generation) #define CRYPTO_get_lock_name BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_get_lock_name) #define CRYPTO_get_locking_callback BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, CRYPTO_get_locking_callback) @@ -672,17 +669,24 @@ #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 ChaCha20_ctr32_avx2 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ChaCha20_ctr32_avx2) #define ChaCha20_ctr32_neon BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ChaCha20_ctr32_neon) #define ChaCha20_ctr32_nohw BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ChaCha20_ctr32_nohw) +#define ChaCha20_ctr32_ssse3 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ChaCha20_ctr32_ssse3) +#define ChaCha20_ctr32_ssse3_4x BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ChaCha20_ctr32_ssse3_4x) #define DES_decrypt3 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DES_decrypt3) #define DES_ecb3_encrypt BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DES_ecb3_encrypt) +#define DES_ecb3_encrypt_ex BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DES_ecb3_encrypt_ex) #define DES_ecb_encrypt BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DES_ecb_encrypt) +#define DES_ecb_encrypt_ex BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DES_ecb_encrypt_ex) #define DES_ede2_cbc_encrypt BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DES_ede2_cbc_encrypt) #define DES_ede3_cbc_encrypt BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DES_ede3_cbc_encrypt) +#define DES_ede3_cbc_encrypt_ex BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DES_ede3_cbc_encrypt_ex) #define DES_encrypt3 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DES_encrypt3) #define DES_ncbc_encrypt BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DES_ncbc_encrypt) +#define DES_ncbc_encrypt_ex BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DES_ncbc_encrypt_ex) #define DES_set_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DES_set_key) +#define DES_set_key_ex BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DES_set_key_ex) #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) @@ -903,6 +907,7 @@ #define ERR_get_error_line_data BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ERR_get_error_line_data) #define ERR_get_next_error_library BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ERR_get_next_error_library) #define ERR_lib_error_string BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ERR_lib_error_string) +#define ERR_lib_symbol_name BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ERR_lib_symbol_name) #define ERR_load_BIO_strings BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ERR_load_BIO_strings) #define ERR_load_ERR_strings BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ERR_load_ERR_strings) #define ERR_load_RAND_strings BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ERR_load_RAND_strings) @@ -919,6 +924,7 @@ #define ERR_print_errors_fp BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ERR_print_errors_fp) #define ERR_put_error BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ERR_put_error) #define ERR_reason_error_string BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ERR_reason_error_string) +#define ERR_reason_symbol_name BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ERR_reason_symbol_name) #define ERR_remove_state BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ERR_remove_state) #define ERR_remove_thread_state BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ERR_remove_thread_state) #define ERR_restore_state BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ERR_restore_state) @@ -1946,14 +1952,9 @@ #define X509_PUBKEY_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_PUBKEY_set) #define X509_PUBKEY_set0_param BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_PUBKEY_set0_param) #define X509_PURPOSE_get0 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_PURPOSE_get0) -#define X509_PURPOSE_get0_name BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_PURPOSE_get0_name) -#define X509_PURPOSE_get0_sname BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_PURPOSE_get0_sname) -#define X509_PURPOSE_get_by_id BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_PURPOSE_get_by_id) #define X509_PURPOSE_get_by_sname BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_PURPOSE_get_by_sname) -#define X509_PURPOSE_get_count BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_PURPOSE_get_count) #define X509_PURPOSE_get_id BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_PURPOSE_get_id) #define X509_PURPOSE_get_trust BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_PURPOSE_get_trust) -#define X509_PURPOSE_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_PURPOSE_set) #define X509_REQ_INFO_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_REQ_INFO_free) #define X509_REQ_INFO_it BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_REQ_INFO_it) #define X509_REQ_INFO_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_REQ_INFO_new) @@ -2039,11 +2040,9 @@ #define X509_STORE_CTX_get_ex_new_index BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_CTX_get_ex_new_index) #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) #define X509_STORE_CTX_set_depth BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_CTX_set_depth) @@ -2062,6 +2061,7 @@ #define X509_STORE_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_free) #define X509_STORE_get0_objects BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_get0_objects) #define X509_STORE_get0_param BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_get0_param) +#define X509_STORE_get1_objects BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_get1_objects) #define X509_STORE_load_locations BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_load_locations) #define X509_STORE_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_new) #define X509_STORE_set1_param BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_set1_param) @@ -2074,13 +2074,6 @@ #define X509_STORE_set_trust BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_set_trust) #define X509_STORE_set_verify_cb BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_set_verify_cb) #define X509_STORE_up_ref BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_STORE_up_ref) -#define X509_TRUST_get0 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_TRUST_get0) -#define X509_TRUST_get0_name BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_TRUST_get0_name) -#define X509_TRUST_get_by_id BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_TRUST_get_by_id) -#define X509_TRUST_get_count BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_TRUST_get_count) -#define X509_TRUST_get_flags BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_TRUST_get_flags) -#define X509_TRUST_get_trust BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_TRUST_get_trust) -#define X509_TRUST_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_TRUST_set) #define X509_VAL_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_VAL_free) #define X509_VAL_it BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_VAL_it) #define X509_VAL_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_VAL_new) @@ -2179,6 +2172,7 @@ #define X509_getm_notAfter BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_getm_notAfter) #define X509_getm_notBefore BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_getm_notBefore) #define X509_gmtime_adj BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_gmtime_adj) +#define X509_is_valid_trust_id BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_is_valid_trust_id) #define X509_issuer_name_cmp BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_issuer_name_cmp) #define X509_issuer_name_hash BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_issuer_name_hash) #define X509_issuer_name_hash_old BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, X509_issuer_name_hash_old) @@ -2327,14 +2321,17 @@ #define bn_mont_ctx_init BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_mont_ctx_init) #define bn_mont_ctx_set_RR_consttime BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_mont_ctx_set_RR_consttime) #define bn_mont_n0 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_mont_n0) +#define bn_mul4x_mont BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_mul4x_mont) #define bn_mul_add_words BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_mul_add_words) #define bn_mul_comba4 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_mul_comba4) #define bn_mul_comba8 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_mul_comba8) #define bn_mul_consttime BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_mul_consttime) #define bn_mul_mont BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_mul_mont) #define bn_mul_mont_gather5 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_mul_mont_gather5) +#define bn_mul_mont_nohw BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_mul_mont_nohw) #define bn_mul_small BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_mul_small) #define bn_mul_words BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_mul_words) +#define bn_mulx4x_mont BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_mulx4x_mont) #define bn_odd_number_is_obviously_composite BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_odd_number_is_obviously_composite) #define bn_one_to_montgomery BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_one_to_montgomery) #define bn_power5 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_power5) @@ -2352,6 +2349,7 @@ #define bn_set_static_words BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_set_static_words) #define bn_set_words BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_set_words) #define bn_sqr8x_internal BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_sqr8x_internal) +#define bn_sqr8x_mont BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_sqr8x_mont) #define bn_sqr_comba4 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_sqr_comba4) #define bn_sqr_comba8 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_sqr_comba8) #define bn_sqr_consttime BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_sqr_consttime) @@ -2373,7 +2371,6 @@ #define chacha20_poly1305_open BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, chacha20_poly1305_open) #define chacha20_poly1305_seal BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, chacha20_poly1305_seal) #define crypto_gcm_clmul_enabled BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, crypto_gcm_clmul_enabled) -#define d2i_ACCESS_DESCRIPTION BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_ACCESS_DESCRIPTION) #define d2i_ASN1_BIT_STRING BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_ASN1_BIT_STRING) #define d2i_ASN1_BMPSTRING BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_ASN1_BMPSTRING) #define d2i_ASN1_BOOLEAN BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_ASN1_BOOLEAN) @@ -2406,8 +2403,6 @@ #define d2i_DHparams_bio BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_DHparams_bio) #define d2i_DIRECTORYSTRING BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_DIRECTORYSTRING) #define d2i_DISPLAYTEXT BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_DISPLAYTEXT) -#define d2i_DIST_POINT BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_DIST_POINT) -#define d2i_DIST_POINT_NAME BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_DIST_POINT_NAME) #define d2i_DSAPrivateKey BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_DSAPrivateKey) #define d2i_DSAPrivateKey_bio BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_DSAPrivateKey_bio) #define d2i_DSAPrivateKey_fp BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_DSAPrivateKey_fp) @@ -2431,7 +2426,6 @@ #define d2i_ISSUING_DIST_POINT BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_ISSUING_DIST_POINT) #define d2i_NETSCAPE_SPKAC BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_NETSCAPE_SPKAC) #define d2i_NETSCAPE_SPKI BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_NETSCAPE_SPKI) -#define d2i_NOTICEREF BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_NOTICEREF) #define d2i_PKCS12 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_PKCS12) #define d2i_PKCS12_bio BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_PKCS12_bio) #define d2i_PKCS12_fp BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_PKCS12_fp) @@ -2444,8 +2438,6 @@ #define d2i_PKCS8_PRIV_KEY_INFO_fp BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_PKCS8_PRIV_KEY_INFO_fp) #define d2i_PKCS8_bio BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_PKCS8_bio) #define d2i_PKCS8_fp BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_PKCS8_fp) -#define d2i_POLICYINFO BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_POLICYINFO) -#define d2i_POLICYQUALINFO BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_POLICYQUALINFO) #define d2i_PUBKEY BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_PUBKEY) #define d2i_PUBKEY_bio BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_PUBKEY_bio) #define d2i_PUBKEY_fp BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_PUBKEY_fp) @@ -2463,7 +2455,6 @@ #define d2i_RSA_PUBKEY BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_RSA_PUBKEY) #define d2i_RSA_PUBKEY_bio BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_RSA_PUBKEY_bio) #define d2i_RSA_PUBKEY_fp BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_RSA_PUBKEY_fp) -#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_ATTRIBUTE BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_X509_ATTRIBUTE) @@ -2626,7 +2617,6 @@ #define i2a_ASN1_STRING BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2a_ASN1_STRING) #define i2c_ASN1_BIT_STRING BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2c_ASN1_BIT_STRING) #define i2c_ASN1_INTEGER BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2c_ASN1_INTEGER) -#define i2d_ACCESS_DESCRIPTION BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_ACCESS_DESCRIPTION) #define i2d_ASN1_BIT_STRING BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_ASN1_BIT_STRING) #define i2d_ASN1_BMPSTRING BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_ASN1_BMPSTRING) #define i2d_ASN1_BOOLEAN BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_ASN1_BOOLEAN) @@ -2658,8 +2648,6 @@ #define i2d_DHparams_bio BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_DHparams_bio) #define i2d_DIRECTORYSTRING BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_DIRECTORYSTRING) #define i2d_DISPLAYTEXT BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_DISPLAYTEXT) -#define i2d_DIST_POINT BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_DIST_POINT) -#define i2d_DIST_POINT_NAME BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_DIST_POINT_NAME) #define i2d_DSAPrivateKey BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_DSAPrivateKey) #define i2d_DSAPrivateKey_bio BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_DSAPrivateKey_bio) #define i2d_DSAPrivateKey_fp BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_DSAPrivateKey_fp) @@ -2683,7 +2671,6 @@ #define i2d_ISSUING_DIST_POINT BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_ISSUING_DIST_POINT) #define i2d_NETSCAPE_SPKAC BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_NETSCAPE_SPKAC) #define i2d_NETSCAPE_SPKI BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_NETSCAPE_SPKI) -#define i2d_NOTICEREF BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_NOTICEREF) #define i2d_PKCS12 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_PKCS12) #define i2d_PKCS12_bio BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_PKCS12_bio) #define i2d_PKCS12_fp BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_PKCS12_fp) @@ -2700,8 +2687,6 @@ #define i2d_PKCS8_PRIV_KEY_INFO_fp BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_PKCS8_PRIV_KEY_INFO_fp) #define i2d_PKCS8_bio BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_PKCS8_bio) #define i2d_PKCS8_fp BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_PKCS8_fp) -#define i2d_POLICYINFO BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_POLICYINFO) -#define i2d_POLICYQUALINFO BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_POLICYQUALINFO) #define i2d_PUBKEY BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_PUBKEY) #define i2d_PUBKEY_bio BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_PUBKEY_bio) #define i2d_PUBKEY_fp BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_PUBKEY_fp) @@ -2719,7 +2704,6 @@ #define i2d_RSA_PUBKEY BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_RSA_PUBKEY) #define i2d_RSA_PUBKEY_bio BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_RSA_PUBKEY_bio) #define i2d_RSA_PUBKEY_fp BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_RSA_PUBKEY_fp) -#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_ATTRIBUTE BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, i2d_X509_ATTRIBUTE) @@ -3022,6 +3006,29 @@ #define sk_BIGNUM_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_BIGNUM_is_sorted) #define sk_BIGNUM_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_BIGNUM_set_cmp_func) #define sk_BIGNUM_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_BIGNUM_deep_copy) +#define sk_X509V3_EXT_METHOD_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_call_free_func) +#define sk_X509V3_EXT_METHOD_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_call_copy_func) +#define sk_X509V3_EXT_METHOD_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_call_cmp_func) +#define sk_X509V3_EXT_METHOD_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_new) +#define sk_X509V3_EXT_METHOD_new_null BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_new_null) +#define sk_X509V3_EXT_METHOD_num BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_num) +#define sk_X509V3_EXT_METHOD_zero BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_zero) +#define sk_X509V3_EXT_METHOD_value BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_value) +#define sk_X509V3_EXT_METHOD_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_set) +#define sk_X509V3_EXT_METHOD_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_free) +#define sk_X509V3_EXT_METHOD_pop_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_pop_free) +#define sk_X509V3_EXT_METHOD_insert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_insert) +#define sk_X509V3_EXT_METHOD_delete BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_delete) +#define sk_X509V3_EXT_METHOD_delete_ptr BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_delete_ptr) +#define sk_X509V3_EXT_METHOD_find BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_find) +#define sk_X509V3_EXT_METHOD_shift BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_shift) +#define sk_X509V3_EXT_METHOD_push BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_push) +#define sk_X509V3_EXT_METHOD_pop BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_pop) +#define sk_X509V3_EXT_METHOD_dup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_dup) +#define sk_X509V3_EXT_METHOD_sort BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_sort) +#define sk_X509V3_EXT_METHOD_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_is_sorted) +#define sk_X509V3_EXT_METHOD_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_set_cmp_func) +#define sk_X509V3_EXT_METHOD_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_deep_copy) #define sk_X509_LOOKUP_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_call_free_func) #define sk_X509_LOOKUP_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_call_copy_func) #define sk_X509_LOOKUP_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_LOOKUP_call_cmp_func) @@ -3321,144 +3328,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) -#define sk_X509_ATTRIBUTE_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_new) -#define sk_X509_ATTRIBUTE_new_null BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_new_null) -#define sk_X509_ATTRIBUTE_num BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_num) -#define sk_X509_ATTRIBUTE_zero BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_zero) -#define sk_X509_ATTRIBUTE_value BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_value) -#define sk_X509_ATTRIBUTE_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_set) -#define sk_X509_ATTRIBUTE_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_free) -#define sk_X509_ATTRIBUTE_pop_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_pop_free) -#define sk_X509_ATTRIBUTE_insert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_insert) -#define sk_X509_ATTRIBUTE_delete BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_delete) -#define sk_X509_ATTRIBUTE_delete_ptr BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_delete_ptr) -#define sk_X509_ATTRIBUTE_find BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_find) -#define sk_X509_ATTRIBUTE_shift BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_shift) -#define sk_X509_ATTRIBUTE_push BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_push) -#define sk_X509_ATTRIBUTE_pop BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_pop) -#define sk_X509_ATTRIBUTE_dup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_dup) -#define sk_X509_ATTRIBUTE_sort BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_sort) -#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_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) -#define sk_X509_INFO_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_new) -#define sk_X509_INFO_new_null BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_new_null) -#define sk_X509_INFO_num BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_num) -#define sk_X509_INFO_zero BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_zero) -#define sk_X509_INFO_value BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_value) -#define sk_X509_INFO_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_set) -#define sk_X509_INFO_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_free) -#define sk_X509_INFO_pop_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_pop_free) -#define sk_X509_INFO_insert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_insert) -#define sk_X509_INFO_delete BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_delete) -#define sk_X509_INFO_delete_ptr BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_delete_ptr) -#define sk_X509_INFO_find BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_find) -#define sk_X509_INFO_shift BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_shift) -#define sk_X509_INFO_push BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_push) -#define sk_X509_INFO_pop BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_pop) -#define sk_X509_INFO_dup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_dup) -#define sk_X509_INFO_sort BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_sort) -#define sk_X509_INFO_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_is_sorted) -#define sk_X509_INFO_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_set_cmp_func) -#define sk_X509_INFO_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_deep_copy) -#define sk_X509_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) -#define sk_X509_TRUST_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_TRUST_new) -#define sk_X509_TRUST_new_null BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_TRUST_new_null) -#define sk_X509_TRUST_num BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_TRUST_num) -#define sk_X509_TRUST_zero BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_TRUST_zero) -#define sk_X509_TRUST_value BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_TRUST_value) -#define sk_X509_TRUST_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_TRUST_set) -#define sk_X509_TRUST_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_TRUST_free) -#define sk_X509_TRUST_pop_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_TRUST_pop_free) -#define sk_X509_TRUST_insert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_TRUST_insert) -#define sk_X509_TRUST_delete BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_TRUST_delete) -#define sk_X509_TRUST_delete_ptr BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_TRUST_delete_ptr) -#define sk_X509_TRUST_find BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_TRUST_find) -#define sk_X509_TRUST_shift BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_TRUST_shift) -#define sk_X509_TRUST_push BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_TRUST_push) -#define sk_X509_TRUST_pop BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_TRUST_pop) -#define sk_X509_TRUST_dup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_TRUST_dup) -#define sk_X509_TRUST_sort BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_TRUST_sort) -#define sk_X509_TRUST_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_TRUST_is_sorted) -#define sk_X509_TRUST_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_TRUST_set_cmp_func) -#define sk_X509_TRUST_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_TRUST_deep_copy) -#define sk_X509_OBJECT_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_call_free_func) -#define sk_X509_OBJECT_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_call_copy_func) -#define sk_X509_OBJECT_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_call_cmp_func) -#define sk_X509_OBJECT_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_new) -#define sk_X509_OBJECT_new_null BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_new_null) -#define sk_X509_OBJECT_num BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_num) -#define sk_X509_OBJECT_zero BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_zero) -#define sk_X509_OBJECT_value BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_value) -#define sk_X509_OBJECT_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_set) -#define sk_X509_OBJECT_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_free) -#define sk_X509_OBJECT_pop_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_pop_free) -#define sk_X509_OBJECT_insert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_insert) -#define sk_X509_OBJECT_delete BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_delete) -#define sk_X509_OBJECT_delete_ptr BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_delete_ptr) -#define sk_X509_OBJECT_find BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_find) -#define sk_X509_OBJECT_shift BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_shift) -#define sk_X509_OBJECT_push BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_push) -#define sk_X509_OBJECT_pop BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_pop) -#define sk_X509_OBJECT_dup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_dup) -#define sk_X509_OBJECT_sort BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_sort) -#define sk_X509_OBJECT_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_is_sorted) -#define sk_X509_OBJECT_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_set_cmp_func) -#define sk_X509_OBJECT_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_deep_copy) -#define sk_X509V3_EXT_METHOD_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_call_free_func) -#define sk_X509V3_EXT_METHOD_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_call_copy_func) -#define sk_X509V3_EXT_METHOD_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_call_cmp_func) -#define sk_X509V3_EXT_METHOD_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_new) -#define sk_X509V3_EXT_METHOD_new_null BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_new_null) -#define sk_X509V3_EXT_METHOD_num BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_num) -#define sk_X509V3_EXT_METHOD_zero BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_zero) -#define sk_X509V3_EXT_METHOD_value BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_value) -#define sk_X509V3_EXT_METHOD_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_set) -#define sk_X509V3_EXT_METHOD_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_free) -#define sk_X509V3_EXT_METHOD_pop_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_pop_free) -#define sk_X509V3_EXT_METHOD_insert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_insert) -#define sk_X509V3_EXT_METHOD_delete BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_delete) -#define sk_X509V3_EXT_METHOD_delete_ptr BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_delete_ptr) -#define sk_X509V3_EXT_METHOD_find BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_find) -#define sk_X509V3_EXT_METHOD_shift BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_shift) -#define sk_X509V3_EXT_METHOD_push BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_push) -#define sk_X509V3_EXT_METHOD_pop BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_pop) -#define sk_X509V3_EXT_METHOD_dup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_dup) -#define sk_X509V3_EXT_METHOD_sort BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_sort) -#define sk_X509V3_EXT_METHOD_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_is_sorted) -#define sk_X509V3_EXT_METHOD_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_set_cmp_func) -#define sk_X509V3_EXT_METHOD_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509V3_EXT_METHOD_deep_copy) +#define sk_GENERAL_SUBTREE_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_call_free_func) +#define sk_GENERAL_SUBTREE_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_call_copy_func) +#define sk_GENERAL_SUBTREE_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_call_cmp_func) +#define sk_GENERAL_SUBTREE_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_new) +#define sk_GENERAL_SUBTREE_new_null BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_new_null) +#define sk_GENERAL_SUBTREE_num BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_num) +#define sk_GENERAL_SUBTREE_zero BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_zero) +#define sk_GENERAL_SUBTREE_value BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_value) +#define sk_GENERAL_SUBTREE_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_set) +#define sk_GENERAL_SUBTREE_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_free) +#define sk_GENERAL_SUBTREE_pop_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_pop_free) +#define sk_GENERAL_SUBTREE_insert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_insert) +#define sk_GENERAL_SUBTREE_delete BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_delete) +#define sk_GENERAL_SUBTREE_delete_ptr BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_delete_ptr) +#define sk_GENERAL_SUBTREE_find BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_find) +#define sk_GENERAL_SUBTREE_shift BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_shift) +#define sk_GENERAL_SUBTREE_push BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_push) +#define sk_GENERAL_SUBTREE_pop BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_pop) +#define sk_GENERAL_SUBTREE_dup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_dup) +#define sk_GENERAL_SUBTREE_sort BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_sort) +#define sk_GENERAL_SUBTREE_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_is_sorted) +#define sk_GENERAL_SUBTREE_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_set_cmp_func) +#define sk_GENERAL_SUBTREE_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_deep_copy) #define sk_ACCESS_DESCRIPTION_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ACCESS_DESCRIPTION_call_free_func) #define sk_ACCESS_DESCRIPTION_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ACCESS_DESCRIPTION_call_copy_func) #define sk_ACCESS_DESCRIPTION_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_ACCESS_DESCRIPTION_call_cmp_func) @@ -3574,52 +3466,98 @@ #define sk_POLICY_MAPPING_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_POLICY_MAPPING_is_sorted) #define sk_POLICY_MAPPING_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_POLICY_MAPPING_set_cmp_func) #define sk_POLICY_MAPPING_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_POLICY_MAPPING_deep_copy) -#define sk_GENERAL_SUBTREE_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_call_free_func) -#define sk_GENERAL_SUBTREE_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_call_copy_func) -#define sk_GENERAL_SUBTREE_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_call_cmp_func) -#define sk_GENERAL_SUBTREE_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_new) -#define sk_GENERAL_SUBTREE_new_null BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_new_null) -#define sk_GENERAL_SUBTREE_num BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_num) -#define sk_GENERAL_SUBTREE_zero BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_zero) -#define sk_GENERAL_SUBTREE_value BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_value) -#define sk_GENERAL_SUBTREE_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_set) -#define sk_GENERAL_SUBTREE_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_free) -#define sk_GENERAL_SUBTREE_pop_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_pop_free) -#define sk_GENERAL_SUBTREE_insert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_insert) -#define sk_GENERAL_SUBTREE_delete BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_delete) -#define sk_GENERAL_SUBTREE_delete_ptr BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_delete_ptr) -#define sk_GENERAL_SUBTREE_find BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_find) -#define sk_GENERAL_SUBTREE_shift BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_shift) -#define sk_GENERAL_SUBTREE_push BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_push) -#define sk_GENERAL_SUBTREE_pop BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_pop) -#define sk_GENERAL_SUBTREE_dup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_dup) -#define sk_GENERAL_SUBTREE_sort BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_sort) -#define sk_GENERAL_SUBTREE_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_is_sorted) -#define sk_GENERAL_SUBTREE_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_set_cmp_func) -#define sk_GENERAL_SUBTREE_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_GENERAL_SUBTREE_deep_copy) -#define sk_X509_PURPOSE_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_PURPOSE_call_free_func) -#define sk_X509_PURPOSE_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_PURPOSE_call_copy_func) -#define sk_X509_PURPOSE_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_PURPOSE_call_cmp_func) -#define sk_X509_PURPOSE_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_PURPOSE_new) -#define sk_X509_PURPOSE_new_null BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_PURPOSE_new_null) -#define sk_X509_PURPOSE_num BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_PURPOSE_num) -#define sk_X509_PURPOSE_zero BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_PURPOSE_zero) -#define sk_X509_PURPOSE_value BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_PURPOSE_value) -#define sk_X509_PURPOSE_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_PURPOSE_set) -#define sk_X509_PURPOSE_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_PURPOSE_free) -#define sk_X509_PURPOSE_pop_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_PURPOSE_pop_free) -#define sk_X509_PURPOSE_insert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_PURPOSE_insert) -#define sk_X509_PURPOSE_delete BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_PURPOSE_delete) -#define sk_X509_PURPOSE_delete_ptr BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_PURPOSE_delete_ptr) -#define sk_X509_PURPOSE_find BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_PURPOSE_find) -#define sk_X509_PURPOSE_shift BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_PURPOSE_shift) -#define sk_X509_PURPOSE_push BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_PURPOSE_push) -#define sk_X509_PURPOSE_pop BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_PURPOSE_pop) -#define sk_X509_PURPOSE_dup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_PURPOSE_dup) -#define sk_X509_PURPOSE_sort BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_PURPOSE_sort) -#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_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) +#define sk_X509_ATTRIBUTE_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_new) +#define sk_X509_ATTRIBUTE_new_null BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_new_null) +#define sk_X509_ATTRIBUTE_num BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_num) +#define sk_X509_ATTRIBUTE_zero BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_zero) +#define sk_X509_ATTRIBUTE_value BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_value) +#define sk_X509_ATTRIBUTE_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_set) +#define sk_X509_ATTRIBUTE_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_free) +#define sk_X509_ATTRIBUTE_pop_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_pop_free) +#define sk_X509_ATTRIBUTE_insert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_insert) +#define sk_X509_ATTRIBUTE_delete BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_delete) +#define sk_X509_ATTRIBUTE_delete_ptr BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_delete_ptr) +#define sk_X509_ATTRIBUTE_find BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_find) +#define sk_X509_ATTRIBUTE_shift BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_shift) +#define sk_X509_ATTRIBUTE_push BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_push) +#define sk_X509_ATTRIBUTE_pop BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_pop) +#define sk_X509_ATTRIBUTE_dup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_dup) +#define sk_X509_ATTRIBUTE_sort BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_ATTRIBUTE_sort) +#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_OBJECT_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_call_free_func) +#define sk_X509_OBJECT_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_call_copy_func) +#define sk_X509_OBJECT_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_call_cmp_func) +#define sk_X509_OBJECT_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_new) +#define sk_X509_OBJECT_new_null BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_new_null) +#define sk_X509_OBJECT_num BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_num) +#define sk_X509_OBJECT_zero BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_zero) +#define sk_X509_OBJECT_value BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_value) +#define sk_X509_OBJECT_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_set) +#define sk_X509_OBJECT_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_free) +#define sk_X509_OBJECT_pop_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_pop_free) +#define sk_X509_OBJECT_insert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_insert) +#define sk_X509_OBJECT_delete BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_delete) +#define sk_X509_OBJECT_delete_ptr BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_delete_ptr) +#define sk_X509_OBJECT_find BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_find) +#define sk_X509_OBJECT_shift BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_shift) +#define sk_X509_OBJECT_push BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_push) +#define sk_X509_OBJECT_pop BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_pop) +#define sk_X509_OBJECT_dup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_dup) +#define sk_X509_OBJECT_sort BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_sort) +#define sk_X509_OBJECT_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_is_sorted) +#define sk_X509_OBJECT_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_set_cmp_func) +#define sk_X509_OBJECT_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_OBJECT_deep_copy) +#define sk_X509_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) +#define sk_X509_INFO_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_new) +#define sk_X509_INFO_new_null BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_new_null) +#define sk_X509_INFO_num BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_num) +#define sk_X509_INFO_zero BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_zero) +#define sk_X509_INFO_value BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_value) +#define sk_X509_INFO_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_set) +#define sk_X509_INFO_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_free) +#define sk_X509_INFO_pop_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_pop_free) +#define sk_X509_INFO_insert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_insert) +#define sk_X509_INFO_delete BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_delete) +#define sk_X509_INFO_delete_ptr BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_delete_ptr) +#define sk_X509_INFO_find BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_find) +#define sk_X509_INFO_shift BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_shift) +#define sk_X509_INFO_push BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_push) +#define sk_X509_INFO_pop BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_pop) +#define sk_X509_INFO_dup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_dup) +#define sk_X509_INFO_sort BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_sort) +#define sk_X509_INFO_is_sorted BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_is_sorted) +#define sk_X509_INFO_set_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_set_cmp_func) +#define sk_X509_INFO_deep_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_X509_INFO_deep_copy) #define sk_CRYPTO_BUFFER_call_free_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_CRYPTO_BUFFER_call_free_func) #define sk_CRYPTO_BUFFER_call_copy_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_CRYPTO_BUFFER_call_copy_func) #define sk_CRYPTO_BUFFER_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, sk_CRYPTO_BUFFER_call_cmp_func) @@ -3878,6 +3816,20 @@ #define lh_ASN1_OBJECT_call_doall_arg BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, lh_ASN1_OBJECT_call_doall_arg) #define lh_ASN1_OBJECT_doall BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, lh_ASN1_OBJECT_doall) #define lh_ASN1_OBJECT_doall_arg BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, lh_ASN1_OBJECT_doall_arg) +#define lh_CONF_SECTION_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, lh_CONF_SECTION_call_cmp_func) +#define lh_CONF_SECTION_call_hash_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, lh_CONF_SECTION_call_hash_func) +#define lh_CONF_SECTION_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, lh_CONF_SECTION_new) +#define lh_CONF_SECTION_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, lh_CONF_SECTION_free) +#define lh_CONF_SECTION_num_items BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, lh_CONF_SECTION_num_items) +#define lh_CONF_SECTION_retrieve BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, lh_CONF_SECTION_retrieve) +#define lh_CONF_SECTION_call_cmp_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, lh_CONF_SECTION_call_cmp_key) +#define lh_CONF_SECTION_retrieve_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, lh_CONF_SECTION_retrieve_key) +#define lh_CONF_SECTION_insert BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, lh_CONF_SECTION_insert) +#define lh_CONF_SECTION_delete BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, lh_CONF_SECTION_delete) +#define lh_CONF_SECTION_call_doall BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, lh_CONF_SECTION_call_doall) +#define lh_CONF_SECTION_call_doall_arg BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, lh_CONF_SECTION_call_doall_arg) +#define lh_CONF_SECTION_doall BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, lh_CONF_SECTION_doall) +#define lh_CONF_SECTION_doall_arg BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, lh_CONF_SECTION_doall_arg) #define lh_CONF_VALUE_call_cmp_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, lh_CONF_VALUE_call_cmp_func) #define lh_CONF_VALUE_call_hash_func BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, lh_CONF_VALUE_call_hash_func) #define lh_CONF_VALUE_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, lh_CONF_VALUE_new) diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_boringssl_prefix_symbols_asm.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_boringssl_prefix_symbols_asm.h index 0923d4fd..3f18f9d2 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_boringssl_prefix_symbols_asm.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_boringssl_prefix_symbols_asm.h @@ -515,7 +515,6 @@ #define _CBS_asn1_oid_to_text BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBS_asn1_oid_to_text) #define _CBS_contains_zero_byte BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBS_contains_zero_byte) #define _CBS_copy_bytes BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBS_copy_bytes) -#define _CBS_data BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBS_data) #define _CBS_get_any_asn1 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBS_get_any_asn1) #define _CBS_get_any_asn1_element BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBS_get_any_asn1_element) #define _CBS_get_any_ber_asn1_element BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBS_get_any_ber_asn1_element) @@ -548,12 +547,10 @@ #define _CBS_get_until_first BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBS_get_until_first) #define _CBS_get_utf32_be BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBS_get_utf32_be) #define _CBS_get_utf8 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBS_get_utf8) -#define _CBS_init BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBS_init) #define _CBS_is_unsigned_asn1_integer BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBS_is_unsigned_asn1_integer) #define _CBS_is_valid_asn1_bitstring BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBS_is_valid_asn1_bitstring) #define _CBS_is_valid_asn1_integer BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBS_is_valid_asn1_integer) #define _CBS_is_valid_asn1_oid BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBS_is_valid_asn1_oid) -#define _CBS_len BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBS_len) #define _CBS_mem_equal BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBS_mem_equal) #define _CBS_parse_generalized_time BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBS_parse_generalized_time) #define _CBS_parse_utc_time BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CBS_parse_utc_time) @@ -628,7 +625,7 @@ #define _CRYPTO_get_dynlock_destroy_callback BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_get_dynlock_destroy_callback) #define _CRYPTO_get_dynlock_lock_callback BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_get_dynlock_lock_callback) #define _CRYPTO_get_ex_data BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_get_ex_data) -#define _CRYPTO_get_ex_new_index BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_get_ex_new_index) +#define _CRYPTO_get_ex_new_index_ex BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_get_ex_new_index_ex) #define _CRYPTO_get_fork_generation BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_get_fork_generation) #define _CRYPTO_get_lock_name BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_get_lock_name) #define _CRYPTO_get_locking_callback BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, CRYPTO_get_locking_callback) @@ -677,17 +674,24 @@ #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 _ChaCha20_ctr32_avx2 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ChaCha20_ctr32_avx2) #define _ChaCha20_ctr32_neon BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ChaCha20_ctr32_neon) #define _ChaCha20_ctr32_nohw BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ChaCha20_ctr32_nohw) +#define _ChaCha20_ctr32_ssse3 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ChaCha20_ctr32_ssse3) +#define _ChaCha20_ctr32_ssse3_4x BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ChaCha20_ctr32_ssse3_4x) #define _DES_decrypt3 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DES_decrypt3) #define _DES_ecb3_encrypt BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DES_ecb3_encrypt) +#define _DES_ecb3_encrypt_ex BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DES_ecb3_encrypt_ex) #define _DES_ecb_encrypt BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DES_ecb_encrypt) +#define _DES_ecb_encrypt_ex BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DES_ecb_encrypt_ex) #define _DES_ede2_cbc_encrypt BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DES_ede2_cbc_encrypt) #define _DES_ede3_cbc_encrypt BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DES_ede3_cbc_encrypt) +#define _DES_ede3_cbc_encrypt_ex BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DES_ede3_cbc_encrypt_ex) #define _DES_encrypt3 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DES_encrypt3) #define _DES_ncbc_encrypt BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DES_ncbc_encrypt) +#define _DES_ncbc_encrypt_ex BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DES_ncbc_encrypt_ex) #define _DES_set_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DES_set_key) +#define _DES_set_key_ex BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DES_set_key_ex) #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) @@ -908,6 +912,7 @@ #define _ERR_get_error_line_data BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ERR_get_error_line_data) #define _ERR_get_next_error_library BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ERR_get_next_error_library) #define _ERR_lib_error_string BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ERR_lib_error_string) +#define _ERR_lib_symbol_name BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ERR_lib_symbol_name) #define _ERR_load_BIO_strings BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ERR_load_BIO_strings) #define _ERR_load_ERR_strings BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ERR_load_ERR_strings) #define _ERR_load_RAND_strings BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ERR_load_RAND_strings) @@ -924,6 +929,7 @@ #define _ERR_print_errors_fp BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ERR_print_errors_fp) #define _ERR_put_error BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ERR_put_error) #define _ERR_reason_error_string BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ERR_reason_error_string) +#define _ERR_reason_symbol_name BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ERR_reason_symbol_name) #define _ERR_remove_state BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ERR_remove_state) #define _ERR_remove_thread_state BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ERR_remove_thread_state) #define _ERR_restore_state BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ERR_restore_state) @@ -1951,14 +1957,9 @@ #define _X509_PUBKEY_set BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_PUBKEY_set) #define _X509_PUBKEY_set0_param BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_PUBKEY_set0_param) #define _X509_PURPOSE_get0 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_PURPOSE_get0) -#define _X509_PURPOSE_get0_name BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_PURPOSE_get0_name) -#define _X509_PURPOSE_get0_sname BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_PURPOSE_get0_sname) -#define _X509_PURPOSE_get_by_id BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_PURPOSE_get_by_id) #define _X509_PURPOSE_get_by_sname BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_PURPOSE_get_by_sname) -#define _X509_PURPOSE_get_count BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_PURPOSE_get_count) #define _X509_PURPOSE_get_id BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_PURPOSE_get_id) #define _X509_PURPOSE_get_trust BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_PURPOSE_get_trust) -#define _X509_PURPOSE_set BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_PURPOSE_set) #define _X509_REQ_INFO_free BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_REQ_INFO_free) #define _X509_REQ_INFO_it BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_REQ_INFO_it) #define _X509_REQ_INFO_new BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_REQ_INFO_new) @@ -2044,11 +2045,9 @@ #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_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) #define _X509_STORE_CTX_set_depth BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_CTX_set_depth) @@ -2067,6 +2066,7 @@ #define _X509_STORE_free BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_free) #define _X509_STORE_get0_objects BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_get0_objects) #define _X509_STORE_get0_param BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_get0_param) +#define _X509_STORE_get1_objects BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_get1_objects) #define _X509_STORE_load_locations BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_load_locations) #define _X509_STORE_new BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_new) #define _X509_STORE_set1_param BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_set1_param) @@ -2079,13 +2079,6 @@ #define _X509_STORE_set_trust BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_set_trust) #define _X509_STORE_set_verify_cb BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_set_verify_cb) #define _X509_STORE_up_ref BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_STORE_up_ref) -#define _X509_TRUST_get0 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_TRUST_get0) -#define _X509_TRUST_get0_name BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_TRUST_get0_name) -#define _X509_TRUST_get_by_id BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_TRUST_get_by_id) -#define _X509_TRUST_get_count BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_TRUST_get_count) -#define _X509_TRUST_get_flags BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_TRUST_get_flags) -#define _X509_TRUST_get_trust BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_TRUST_get_trust) -#define _X509_TRUST_set BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_TRUST_set) #define _X509_VAL_free BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_VAL_free) #define _X509_VAL_it BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_VAL_it) #define _X509_VAL_new BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_VAL_new) @@ -2184,6 +2177,7 @@ #define _X509_getm_notAfter BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_getm_notAfter) #define _X509_getm_notBefore BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_getm_notBefore) #define _X509_gmtime_adj BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_gmtime_adj) +#define _X509_is_valid_trust_id BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_is_valid_trust_id) #define _X509_issuer_name_cmp BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_issuer_name_cmp) #define _X509_issuer_name_hash BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_issuer_name_hash) #define _X509_issuer_name_hash_old BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, X509_issuer_name_hash_old) @@ -2332,14 +2326,17 @@ #define _bn_mont_ctx_init BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_mont_ctx_init) #define _bn_mont_ctx_set_RR_consttime BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_mont_ctx_set_RR_consttime) #define _bn_mont_n0 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_mont_n0) +#define _bn_mul4x_mont BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_mul4x_mont) #define _bn_mul_add_words BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_mul_add_words) #define _bn_mul_comba4 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_mul_comba4) #define _bn_mul_comba8 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_mul_comba8) #define _bn_mul_consttime BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_mul_consttime) #define _bn_mul_mont BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_mul_mont) #define _bn_mul_mont_gather5 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_mul_mont_gather5) +#define _bn_mul_mont_nohw BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_mul_mont_nohw) #define _bn_mul_small BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_mul_small) #define _bn_mul_words BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_mul_words) +#define _bn_mulx4x_mont BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_mulx4x_mont) #define _bn_odd_number_is_obviously_composite BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_odd_number_is_obviously_composite) #define _bn_one_to_montgomery BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_one_to_montgomery) #define _bn_power5 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_power5) @@ -2357,6 +2354,7 @@ #define _bn_set_static_words BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_set_static_words) #define _bn_set_words BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_set_words) #define _bn_sqr8x_internal BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_sqr8x_internal) +#define _bn_sqr8x_mont BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_sqr8x_mont) #define _bn_sqr_comba4 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_sqr_comba4) #define _bn_sqr_comba8 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_sqr_comba8) #define _bn_sqr_consttime BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_sqr_consttime) @@ -2378,7 +2376,6 @@ #define _chacha20_poly1305_open BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, chacha20_poly1305_open) #define _chacha20_poly1305_seal BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, chacha20_poly1305_seal) #define _crypto_gcm_clmul_enabled BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, crypto_gcm_clmul_enabled) -#define _d2i_ACCESS_DESCRIPTION BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_ACCESS_DESCRIPTION) #define _d2i_ASN1_BIT_STRING BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_ASN1_BIT_STRING) #define _d2i_ASN1_BMPSTRING BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_ASN1_BMPSTRING) #define _d2i_ASN1_BOOLEAN BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_ASN1_BOOLEAN) @@ -2411,8 +2408,6 @@ #define _d2i_DHparams_bio BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_DHparams_bio) #define _d2i_DIRECTORYSTRING BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_DIRECTORYSTRING) #define _d2i_DISPLAYTEXT BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_DISPLAYTEXT) -#define _d2i_DIST_POINT BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_DIST_POINT) -#define _d2i_DIST_POINT_NAME BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_DIST_POINT_NAME) #define _d2i_DSAPrivateKey BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_DSAPrivateKey) #define _d2i_DSAPrivateKey_bio BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_DSAPrivateKey_bio) #define _d2i_DSAPrivateKey_fp BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_DSAPrivateKey_fp) @@ -2436,7 +2431,6 @@ #define _d2i_ISSUING_DIST_POINT BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_ISSUING_DIST_POINT) #define _d2i_NETSCAPE_SPKAC BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_NETSCAPE_SPKAC) #define _d2i_NETSCAPE_SPKI BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_NETSCAPE_SPKI) -#define _d2i_NOTICEREF BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_NOTICEREF) #define _d2i_PKCS12 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_PKCS12) #define _d2i_PKCS12_bio BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_PKCS12_bio) #define _d2i_PKCS12_fp BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_PKCS12_fp) @@ -2449,8 +2443,6 @@ #define _d2i_PKCS8_PRIV_KEY_INFO_fp BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_PKCS8_PRIV_KEY_INFO_fp) #define _d2i_PKCS8_bio BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_PKCS8_bio) #define _d2i_PKCS8_fp BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_PKCS8_fp) -#define _d2i_POLICYINFO BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_POLICYINFO) -#define _d2i_POLICYQUALINFO BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_POLICYQUALINFO) #define _d2i_PUBKEY BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_PUBKEY) #define _d2i_PUBKEY_bio BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_PUBKEY_bio) #define _d2i_PUBKEY_fp BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_PUBKEY_fp) @@ -2468,7 +2460,6 @@ #define _d2i_RSA_PUBKEY BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_RSA_PUBKEY) #define _d2i_RSA_PUBKEY_bio BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_RSA_PUBKEY_bio) #define _d2i_RSA_PUBKEY_fp BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_RSA_PUBKEY_fp) -#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_ATTRIBUTE BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_X509_ATTRIBUTE) @@ -2631,7 +2622,6 @@ #define _i2a_ASN1_STRING BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2a_ASN1_STRING) #define _i2c_ASN1_BIT_STRING BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2c_ASN1_BIT_STRING) #define _i2c_ASN1_INTEGER BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2c_ASN1_INTEGER) -#define _i2d_ACCESS_DESCRIPTION BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_ACCESS_DESCRIPTION) #define _i2d_ASN1_BIT_STRING BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_ASN1_BIT_STRING) #define _i2d_ASN1_BMPSTRING BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_ASN1_BMPSTRING) #define _i2d_ASN1_BOOLEAN BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_ASN1_BOOLEAN) @@ -2663,8 +2653,6 @@ #define _i2d_DHparams_bio BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_DHparams_bio) #define _i2d_DIRECTORYSTRING BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_DIRECTORYSTRING) #define _i2d_DISPLAYTEXT BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_DISPLAYTEXT) -#define _i2d_DIST_POINT BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_DIST_POINT) -#define _i2d_DIST_POINT_NAME BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_DIST_POINT_NAME) #define _i2d_DSAPrivateKey BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_DSAPrivateKey) #define _i2d_DSAPrivateKey_bio BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_DSAPrivateKey_bio) #define _i2d_DSAPrivateKey_fp BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_DSAPrivateKey_fp) @@ -2688,7 +2676,6 @@ #define _i2d_ISSUING_DIST_POINT BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_ISSUING_DIST_POINT) #define _i2d_NETSCAPE_SPKAC BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_NETSCAPE_SPKAC) #define _i2d_NETSCAPE_SPKI BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_NETSCAPE_SPKI) -#define _i2d_NOTICEREF BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_NOTICEREF) #define _i2d_PKCS12 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_PKCS12) #define _i2d_PKCS12_bio BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_PKCS12_bio) #define _i2d_PKCS12_fp BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_PKCS12_fp) @@ -2705,8 +2692,6 @@ #define _i2d_PKCS8_PRIV_KEY_INFO_fp BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_PKCS8_PRIV_KEY_INFO_fp) #define _i2d_PKCS8_bio BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_PKCS8_bio) #define _i2d_PKCS8_fp BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_PKCS8_fp) -#define _i2d_POLICYINFO BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_POLICYINFO) -#define _i2d_POLICYQUALINFO BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_POLICYQUALINFO) #define _i2d_PUBKEY BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_PUBKEY) #define _i2d_PUBKEY_bio BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_PUBKEY_bio) #define _i2d_PUBKEY_fp BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_PUBKEY_fp) @@ -2724,7 +2709,6 @@ #define _i2d_RSA_PUBKEY BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_RSA_PUBKEY) #define _i2d_RSA_PUBKEY_bio BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_RSA_PUBKEY_bio) #define _i2d_RSA_PUBKEY_fp BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_RSA_PUBKEY_fp) -#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_ATTRIBUTE BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, i2d_X509_ATTRIBUTE) diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_bytestring.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_bytestring.h index 19b351e4..65f9618d 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_bytestring.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_bytestring.h @@ -58,17 +58,20 @@ struct cbs_st { // CBS_init sets |cbs| to point to |data|. It does not take ownership of // |data|. -OPENSSL_EXPORT void CBS_init(CBS *cbs, const uint8_t *data, size_t len); +OPENSSL_INLINE void CBS_init(CBS *cbs, const uint8_t *data, size_t len) { + cbs->data = data; + cbs->len = len; +} // CBS_skip advances |cbs| by |len| bytes. It returns one on success and zero // otherwise. OPENSSL_EXPORT int CBS_skip(CBS *cbs, size_t len); // CBS_data returns a pointer to the contents of |cbs|. -OPENSSL_EXPORT const uint8_t *CBS_data(const CBS *cbs); +OPENSSL_INLINE const uint8_t *CBS_data(const CBS *cbs) { return cbs->data; } // CBS_len returns the number of bytes remaining in |cbs|. -OPENSSL_EXPORT size_t CBS_len(const CBS *cbs); +OPENSSL_INLINE size_t CBS_len(const CBS *cbs) { return cbs->len; } // CBS_stow copies the current contents of |cbs| into |*out_ptr| and // |*out_len|. If |*out_ptr| is not NULL, the contents are freed with diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_crypto.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_crypto.h index c0818f32..15755064 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_crypto.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_crypto.h @@ -162,6 +162,7 @@ OPENSSL_EXPORT void OPENSSL_load_builtin_modules(void); #define OPENSSL_INIT_NO_ADD_ALL_DIGESTS 0 #define OPENSSL_INIT_LOAD_CONFIG 0 #define OPENSSL_INIT_NO_LOAD_CONFIG 0 +#define OPENSSL_INIT_NO_ATEXIT 0 // OPENSSL_init_crypto calls |CRYPTO_library_init| and returns one. OPENSSL_EXPORT int OPENSSL_init_crypto(uint64_t opts, diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_des.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_des.h index b73669ac..54265960 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_des.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_des.h @@ -163,19 +163,6 @@ OPENSSL_EXPORT void DES_ede3_cfb_encrypt(const uint8_t *in, uint8_t *out, DES_cblock *ivec, int enc); -// Private functions. -// -// These functions are only exported for use in |decrepit|. - -OPENSSL_EXPORT void DES_decrypt3(uint32_t *data, const DES_key_schedule *ks1, - const DES_key_schedule *ks2, - const DES_key_schedule *ks3); - -OPENSSL_EXPORT void DES_encrypt3(uint32_t *data, const DES_key_schedule *ks1, - const DES_key_schedule *ks2, - const DES_key_schedule *ks3); - - #if defined(__cplusplus) } // extern C #endif diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_ec.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_ec.h index f5939b55..8621c102 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_ec.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_ec.h @@ -100,6 +100,16 @@ typedef enum { // Elliptic curve groups. +// +// Elliptic curve groups are represented by |EC_GROUP| objects. Unlike OpenSSL, +// if limited to the APIs in this section, callers may treat |EC_GROUP|s as +// static, immutable objects which do not need to be copied or released. In +// BoringSSL, only custom |EC_GROUP|s created by |EC_GROUP_new_curve_GFp| +// (deprecated) are dynamic. +// +// Callers may cast away |const| and use |EC_GROUP_dup| and |EC_GROUP_free| with +// static groups, for compatibility with OpenSSL or dynamic groups, but it is +// otherwise unnecessary. // EC_group_p224 returns an |EC_GROUP| for P-224, also known as secp224r1. OPENSSL_EXPORT const EC_GROUP *EC_group_p224(void); @@ -133,12 +143,6 @@ OPENSSL_EXPORT const EC_GROUP *EC_group_p521(void); // more modern primitives. OPENSSL_EXPORT EC_GROUP *EC_GROUP_new_by_curve_name(int nid); -// EC_GROUP_free releases a reference to |group|. -OPENSSL_EXPORT void EC_GROUP_free(EC_GROUP *group); - -// EC_GROUP_dup takes a reference to |a| and returns it. -OPENSSL_EXPORT EC_GROUP *EC_GROUP_dup(const EC_GROUP *a); - // EC_GROUP_cmp returns zero if |a| and |b| are the same group and non-zero // otherwise. OPENSSL_EXPORT int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, @@ -363,9 +367,27 @@ OPENSSL_EXPORT int EC_hash_to_curve_p384_xmd_sha384_sswu( // Deprecated functions. +// EC_GROUP_free releases a reference to |group|, if |group| was created by +// |EC_GROUP_new_curve_GFp|. If |group| is static, it does nothing. +// +// This function exists for OpenSSL compatibilty, and to manage dynamic +// |EC_GROUP|s constructed by |EC_GROUP_new_curve_GFp|. Callers that do not need +// either may ignore this function. +OPENSSL_EXPORT void EC_GROUP_free(EC_GROUP *group); + +// EC_GROUP_dup increments |group|'s reference count and returns it, if |group| +// was created by |EC_GROUP_new_curve_GFp|. If |group| is static, it simply +// returns |group|. +// +// This function exists for OpenSSL compatibilty, and to manage dynamic +// |EC_GROUP|s constructed by |EC_GROUP_new_curve_GFp|. Callers that do not need +// either may ignore this function. +OPENSSL_EXPORT EC_GROUP *EC_GROUP_dup(const EC_GROUP *group); + // EC_GROUP_new_curve_GFp creates a new, arbitrary elliptic curve group based // on the equation y² = x³ + a·x + b. It returns the new group or NULL on -// error. +// error. The lifetime of the resulting object must be managed with +// |EC_GROUP_dup| and |EC_GROUP_free|. // // This new group has no generator. It is an error to use a generator-less group // with any functions except for |EC_GROUP_free|, |EC_POINT_new|, diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_err.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_err.h index 0b81040a..125a46b9 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_err.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_err.h @@ -244,6 +244,19 @@ OPENSSL_EXPORT const char *ERR_lib_error_string(uint32_t packed_error); // |packed_error|, or a placeholder string if the reason is unrecognized. OPENSSL_EXPORT const char *ERR_reason_error_string(uint32_t packed_error); +// ERR_lib_symbol_name returns the symbol name of library that generated +// |packed_error|, or NULL if unrecognized. For example, an error from +// |ERR_LIB_EVP| would return "EVP". +OPENSSL_EXPORT const char *ERR_lib_symbol_name(uint32_t packed_error); + +// ERR_reason_symbol_name returns the symbol name of the reason for +// |packed_error|, or NULL if unrecognized. For example, |ERR_R_INTERNAL_ERROR| +// would return "INTERNAL_ERROR". +// +// Errors from the |ERR_LIB_SYS| library are typically |errno| values and will +// return NULL. User-defined errors will also return NULL. +OPENSSL_EXPORT const char *ERR_reason_symbol_name(uint32_t packed_error); + // ERR_print_errors_callback_t is the type of a function used by // |ERR_print_errors_cb|. It takes a pointer to a human readable string (and // its length) that describes an entry in the error queue. The |ctx| argument diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_ex_data.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_ex_data.h index 0cf1bc1b..1bba5ea7 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_ex_data.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_ex_data.h @@ -129,11 +129,11 @@ typedef struct crypto_ex_data_st CRYPTO_EX_DATA; // Type-specific functions. -// -// Each type that supports ex_data provides three functions: #if 0 // Sample +// Each type that supports ex_data provides three functions: + // TYPE_get_ex_new_index allocates a new index for |TYPE|. An optional // |free_func| argument may be provided which is called when the owning object // is destroyed. See |CRYPTO_EX_free| for details. The |argl| and |argp| @@ -153,6 +153,18 @@ OPENSSL_EXPORT int TYPE_set_ex_data(TYPE *t, int index, void *arg); // previous call to |TYPE_get_ex_new_index|. OPENSSL_EXPORT void *TYPE_get_ex_data(const TYPE *t, int index); +// Some types additionally preallocate index zero, with all callbacks set to +// NULL. Applications that do not need the general ex_data machinery may use +// this instead. + +// TYPE_set_app_data sets |t|'s application data pointer to |arg|. It returns +// one on success and zero on error. +OPENSSL_EXPORT int TYPE_set_app_data(TYPE *t, void *arg); + +// TYPE_get_app_data returns the application data pointer for |t|, or NULL if no +// such pointer exists. +OPENSSL_EXPORT void *TYPE_get_app_data(const TYPE *t); + #endif // Sample @@ -167,7 +179,7 @@ OPENSSL_EXPORT void *TYPE_get_ex_data(const TYPE *t, int index); // |parent|. As |parent| will shortly be destroyed, callers must not perform // operations that would increment its reference count, pass ownership, or // assume the object outlives the function call. The arguments |argl| and |argp| -// contain opaque values that were given to |CRYPTO_get_ex_new_index|. +// contain opaque values that were given to |CRYPTO_get_ex_new_index_ex|. // // This callback may be called with a NULL value for |ptr| if |parent| has no // value set for this index. However, the callbacks may also be skipped entirely diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_obj.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_obj.h index d81a35a0..e22fc291 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_obj.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_obj.h @@ -194,8 +194,8 @@ OPENSSL_EXPORT int OBJ_obj2txt(char *out, int out_len, const ASN1_OBJECT *obj, // duplicate OIDs, short names, or long names. If two callers in the same // address space add conflicting values, only one registration will take effect. // Avoid this function if possible. Instead, callers can process OIDs unknown to -// BoringSSL by acting on the byte representation directly. See |OBJ_get0_data| -// and |OBJ_length|. +// BoringSSL by acting on the byte representation directly. See +// |ASN1_OBJECT_create|, |OBJ_get0_data|, and |OBJ_length|. OPENSSL_EXPORT int OBJ_create(const char *oid, const char *short_name, const char *long_name); diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_pem.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_pem.h index 5ab4435b..b93b284c 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_pem.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_pem.h @@ -142,26 +142,26 @@ extern "C" { NULL, 0, NULL, NULL); \ } -#define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \ - static int pem_write_##name##_i2d(const void *x, unsigned char **outp) { \ - return i2d_##asn1((type *)x, outp); \ - } \ - OPENSSL_EXPORT int PEM_write_##name( \ - FILE *fp, type *x, const EVP_CIPHER *enc, unsigned char *kstr, int klen, \ - pem_password_cb *cb, void *u) { \ - return PEM_ASN1_write(pem_write_##name##_i2d, str, fp, x, enc, kstr, klen, \ - cb, u); \ +#define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \ + static int pem_write_##name##_i2d(const void *x, unsigned char **outp) { \ + return i2d_##asn1((type *)x, outp); \ + } \ + OPENSSL_EXPORT int PEM_write_##name( \ + FILE *fp, type *x, const EVP_CIPHER *enc, const unsigned char *pass, \ + int pass_len, pem_password_cb *cb, void *u) { \ + return PEM_ASN1_write(pem_write_##name##_i2d, str, fp, x, enc, pass, \ + pass_len, cb, u); \ } -#define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) \ - static int pem_write_##name##_i2d(const void *x, unsigned char **outp) { \ - return i2d_##asn1((const type *)x, outp); \ - } \ - OPENSSL_EXPORT int PEM_write_##name( \ - FILE *fp, type *x, const EVP_CIPHER *enc, unsigned char *kstr, int klen, \ - pem_password_cb *cb, void *u) { \ - return PEM_ASN1_write(pem_write_##name##_i2d, str, fp, x, enc, kstr, klen, \ - cb, u); \ +#define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) \ + static int pem_write_##name##_i2d(const void *x, unsigned char **outp) { \ + return i2d_##asn1((const type *)x, outp); \ + } \ + OPENSSL_EXPORT int PEM_write_##name( \ + FILE *fp, type *x, const EVP_CIPHER *enc, const unsigned char *pass, \ + int pass_len, pem_password_cb *cb, void *u) { \ + return PEM_ASN1_write(pem_write_##name##_i2d, str, fp, x, enc, pass, \ + pass_len, cb, u); \ } @@ -199,10 +199,10 @@ extern "C" { return i2d_##asn1((type *)x, outp); \ } \ OPENSSL_EXPORT int PEM_write_bio_##name( \ - BIO *bp, type *x, const EVP_CIPHER *enc, unsigned char *kstr, int klen, \ - pem_password_cb *cb, void *u) { \ + BIO *bp, type *x, const EVP_CIPHER *enc, const unsigned char *pass, \ + int pass_len, pem_password_cb *cb, void *u) { \ return PEM_ASN1_write_bio(pem_write_bio_##name##_i2d, str, bp, x, enc, \ - kstr, klen, cb, u); \ + pass, pass_len, cb, u); \ } #define IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \ @@ -210,10 +210,10 @@ extern "C" { return i2d_##asn1((const type *)x, outp); \ } \ OPENSSL_EXPORT int PEM_write_bio_##name( \ - BIO *bp, type *x, const EVP_CIPHER *enc, unsigned char *kstr, int klen, \ - pem_password_cb *cb, void *u) { \ + BIO *bp, type *x, const EVP_CIPHER *enc, const unsigned char *pass, \ + int pass_len, pem_password_cb *cb, void *u) { \ return PEM_ASN1_write_bio(pem_write_bio_##name##_i2d, str, bp, (void *)x, \ - enc, kstr, klen, cb, u); \ + enc, pass, pass_len, cb, u); \ } #define IMPLEMENT_PEM_write(name, type, str, asn1) \ @@ -260,10 +260,10 @@ extern "C" { #define DECLARE_PEM_write_fp_const(name, type) \ OPENSSL_EXPORT int PEM_write_##name(FILE *fp, const type *x); -#define DECLARE_PEM_write_cb_fp(name, type) \ - OPENSSL_EXPORT int PEM_write_##name( \ - FILE *fp, type *x, const EVP_CIPHER *enc, unsigned char *kstr, int klen, \ - pem_password_cb *cb, void *u); +#define DECLARE_PEM_write_cb_fp(name, type) \ + OPENSSL_EXPORT int PEM_write_##name( \ + FILE *fp, type *x, const EVP_CIPHER *enc, const unsigned char *pass, \ + int pass_len, pem_password_cb *cb, void *u); #define DECLARE_PEM_read_bio(name, type) \ OPENSSL_EXPORT type *PEM_read_bio_##name(BIO *bp, type **x, \ @@ -275,10 +275,10 @@ extern "C" { #define DECLARE_PEM_write_bio_const(name, type) \ OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, const type *x); -#define DECLARE_PEM_write_cb_bio(name, type) \ - OPENSSL_EXPORT int PEM_write_bio_##name( \ - BIO *bp, type *x, const EVP_CIPHER *enc, unsigned char *kstr, int klen, \ - pem_password_cb *cb, void *u); +#define DECLARE_PEM_write_cb_bio(name, type) \ + OPENSSL_EXPORT int PEM_write_bio_##name( \ + BIO *bp, type *x, const EVP_CIPHER *enc, const unsigned char *pass, \ + int pass_len, pem_password_cb *cb, void *u); #define DECLARE_PEM_write(name, type) \ @@ -344,7 +344,7 @@ OPENSSL_EXPORT void *PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, void *u); OPENSSL_EXPORT int PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp, void *x, const EVP_CIPHER *enc, - unsigned char *kstr, int klen, + const unsigned char *pass, int pass_len, pem_password_cb *cb, void *u); // PEM_X509_INFO_read_bio reads PEM blocks from |bp| and decodes any @@ -358,6 +358,11 @@ OPENSSL_EXPORT int PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, // If |sk| is non-NULL, it appends the results to |sk| instead and returns |sk| // on success. In this case, the caller retains ownership of |sk| in both // success and failure. +// +// WARNING: If the input contains "TRUSTED CERTIFICATE" PEM blocks, this +// function parses auxiliary properties as in |d2i_X509_AUX|. Passing untrusted +// input to this function allows an attacker to influence those properties. See +// |d2i_X509_AUX| for details. OPENSSL_EXPORT STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio( BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u); @@ -376,7 +381,7 @@ OPENSSL_EXPORT void *PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp, void **x, pem_password_cb *cb, void *u); OPENSSL_EXPORT int PEM_ASN1_write(i2d_of_void *i2d, const char *name, FILE *fp, void *x, const EVP_CIPHER *enc, - unsigned char *kstr, int klen, + const unsigned char *pass, int pass_len, pem_password_cb *callback, void *u); // PEM_def_callback treats |userdata| as a string and copies it into |buf|, @@ -390,6 +395,8 @@ OPENSSL_EXPORT int PEM_def_callback(char *buf, int size, int rwflag, DECLARE_PEM_rw(X509, X509) +// TODO(crbug.com/boringssl/426): When documenting these, copy the warning +// about auxiliary properties from |PEM_X509_INFO_read_bio|. DECLARE_PEM_rw(X509_AUX, X509) DECLARE_PEM_rw(X509_REQ, X509_REQ) @@ -429,42 +436,45 @@ DECLARE_PEM_rw_cb(PrivateKey, EVP_PKEY) DECLARE_PEM_rw(PUBKEY, EVP_PKEY) OPENSSL_EXPORT int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, const EVP_PKEY *x, - int nid, char *kstr, - int klen, + int nid, const char *pass, + int pass_len, pem_password_cb *cb, void *u); -OPENSSL_EXPORT int PEM_write_bio_PKCS8PrivateKey(BIO *, const EVP_PKEY *, - const EVP_CIPHER *, char *, - int, pem_password_cb *, - void *); +OPENSSL_EXPORT int PEM_write_bio_PKCS8PrivateKey(BIO *bp, const EVP_PKEY *x, + const EVP_CIPHER *enc, + const char *pass, int pass_len, + pem_password_cb *cb, void *u); OPENSSL_EXPORT int i2d_PKCS8PrivateKey_bio(BIO *bp, const EVP_PKEY *x, - const EVP_CIPHER *enc, char *kstr, - int klen, pem_password_cb *cb, - void *u); + const EVP_CIPHER *enc, + const char *pass, int pass_len, + pem_password_cb *cb, void *u); OPENSSL_EXPORT int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, const EVP_PKEY *x, - int nid, char *kstr, int klen, + int nid, const char *pass, + int pass_len, pem_password_cb *cb, void *u); OPENSSL_EXPORT EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u); OPENSSL_EXPORT int i2d_PKCS8PrivateKey_fp(FILE *fp, const EVP_PKEY *x, - const EVP_CIPHER *enc, char *kstr, - int klen, pem_password_cb *cb, - void *u); + const EVP_CIPHER *enc, + const char *pass, int pass_len, + pem_password_cb *cb, void *u); OPENSSL_EXPORT int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, const EVP_PKEY *x, - int nid, char *kstr, int klen, - pem_password_cb *cb, void *u); + int nid, const char *pass, + int pass_len, pem_password_cb *cb, + void *u); OPENSSL_EXPORT int PEM_write_PKCS8PrivateKey_nid(FILE *fp, const EVP_PKEY *x, - int nid, char *kstr, int klen, + int nid, const char *pass, + int pass_len, pem_password_cb *cb, void *u); OPENSSL_EXPORT EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u); OPENSSL_EXPORT int PEM_write_PKCS8PrivateKey(FILE *fp, const EVP_PKEY *x, - const EVP_CIPHER *enc, char *kstr, - int klen, pem_password_cb *cd, - void *u); + const EVP_CIPHER *enc, + const char *pass, int pass_len, + pem_password_cb *cd, void *u); #ifdef __cplusplus diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_posix_time.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_posix_time.h new file mode 100644 index 00000000..740096fc --- /dev/null +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_posix_time.h @@ -0,0 +1,51 @@ +/* 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_POSIX_TIME_H +#define OPENSSL_HEADER_POSIX_TIME_H + +#include "CCryptoBoringSSL_base.h" + +#include + +#if defined(__cplusplus) +extern "C" { +#endif + + +// Time functions. + + +// OPENSSL_posix_to_tm converts a int64_t POSIX time value in |time|, which 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 |tm| contains out of range values. +OPENSSL_EXPORT int OPENSSL_tm_to_posix(const struct tm *tm, int64_t *out); + +// 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); + + +#if defined(__cplusplus) +} // extern C +#endif + +#endif // OPENSSL_HEADER_POSIX_TIME_H diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_rsa.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_rsa.h index 0be61d25..a846bb76 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_rsa.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_rsa.h @@ -236,6 +236,13 @@ OPENSSL_EXPORT int RSA_generate_key_fips(RSA *rsa, int bits, BN_GENCB *cb); // RSA_PKCS1_PADDING denotes PKCS#1 v1.5 padding. When used with encryption, // this is RSAES-PKCS1-v1_5. When used with signing, this is RSASSA-PKCS1-v1_5. +// +// WARNING: The RSAES-PKCS1-v1_5 encryption scheme is vulnerable to a +// chosen-ciphertext attack. Decrypting attacker-supplied ciphertext with +// RSAES-PKCS1-v1_5 may give the attacker control over your private key. This +// does not impact the RSASSA-PKCS1-v1_5 signature scheme. See "Chosen +// Ciphertext Attacks Against Protocols Based on the RSA Encryption Standard +// PKCS #1", Daniel Bleichenbacher, Advances in Cryptology (Crypto '98). #define RSA_PKCS1_PADDING 1 // RSA_NO_PADDING denotes a raw RSA operation. @@ -256,8 +263,7 @@ OPENSSL_EXPORT int RSA_generate_key_fips(RSA *rsa, int bits, BN_GENCB *cb); // It returns 1 on success or zero on error. // // The |padding| argument must be one of the |RSA_*_PADDING| values. If in -// doubt, use |RSA_PKCS1_OAEP_PADDING| for new protocols but -// |RSA_PKCS1_PADDING| is most common. +// doubt, use |RSA_PKCS1_OAEP_PADDING| for new protocols. OPENSSL_EXPORT int RSA_encrypt(RSA *rsa, size_t *out_len, uint8_t *out, size_t max_out, const uint8_t *in, size_t in_len, int padding); @@ -271,12 +277,16 @@ OPENSSL_EXPORT int RSA_encrypt(RSA *rsa, size_t *out_len, uint8_t *out, // The |padding| argument must be one of the |RSA_*_PADDING| values. If in // doubt, use |RSA_PKCS1_OAEP_PADDING| for new protocols. // -// Passing |RSA_PKCS1_PADDING| into this function is deprecated and insecure. If -// implementing a protocol using RSAES-PKCS1-V1_5, use |RSA_NO_PADDING| and then -// check padding in constant-time combined with a swap to a random session key -// or other mitigation. See "Chosen Ciphertext Attacks Against Protocols Based -// on the RSA Encryption Standard PKCS #1", Daniel Bleichenbacher, Advances in -// Cryptology (Crypto '98). +// WARNING: Passing |RSA_PKCS1_PADDING| into this function is deprecated and +// insecure. RSAES-PKCS1-v1_5 is vulnerable to a chosen-ciphertext attack. +// Decrypting attacker-supplied ciphertext with RSAES-PKCS1-v1_5 may give the +// attacker control over your private key. See "Chosen Ciphertext Attacks +// Against Protocols Based on the RSA Encryption Standard PKCS #1", Daniel +// Bleichenbacher, Advances in Cryptology (Crypto '98). +// +// In some limited cases, such as TLS RSA key exchange, it is possible to +// mitigate this flaw with custom, protocol-specific padding logic. This +// should be implemented with |RSA_NO_PADDING|, not |RSA_PKCS1_PADDING|. OPENSSL_EXPORT int RSA_decrypt(RSA *rsa, size_t *out_len, uint8_t *out, size_t max_out, const uint8_t *in, size_t in_len, int padding); @@ -285,8 +295,7 @@ OPENSSL_EXPORT int RSA_decrypt(RSA *rsa, size_t *out_len, uint8_t *out, // |rsa| and writes the encrypted data to |to|. The |to| buffer must have at // least |RSA_size| bytes of space. It returns the number of bytes written, or // -1 on error. The |padding| argument must be one of the |RSA_*_PADDING| -// values. If in doubt, use |RSA_PKCS1_OAEP_PADDING| for new protocols but -// |RSA_PKCS1_PADDING| is most common. +// values. If in doubt, use |RSA_PKCS1_OAEP_PADDING| for new protocols. // // WARNING: this function is dangerous because it breaks the usual return value // convention. Use |RSA_encrypt| instead. diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_span.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_span.h index b7e781fc..aa9396a7 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_span.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_span.h @@ -26,6 +26,10 @@ extern "C++" { #include #include +#if __cplusplus >= 201703L +#include +#endif + BSSL_NAMESPACE_BEGIN template @@ -40,20 +44,7 @@ class SpanBase { "Span must be derived from SpanBase"); friend bool operator==(Span lhs, Span rhs) { - // MSVC issues warning C4996 because std::equal is unsafe. The pragma to - // suppress the warning mysteriously has no effect, hence this - // implementation. See - // https://msdn.microsoft.com/en-us/library/aa985974.aspx. - if (lhs.size() != rhs.size()) { - return false; - } - for (T *l = lhs.begin(), *r = rhs.begin(); l != lhs.end() && r != rhs.end(); - ++l, ++r) { - if (*l != *r) { - return false; - } - } - return true; + return std::equal(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); } friend bool operator!=(Span lhs, Span rhs) { return !(lhs == rhs); } @@ -94,8 +85,6 @@ class SpanBase { template class Span : private internal::SpanBase { private: - static const size_t npos = static_cast(-1); - // Heuristically test whether C is a container type that can be converted into // a Span by checking for data() and size() member functions. // @@ -106,6 +95,19 @@ class Span : private internal::SpanBase { std::is_integral().size())>::value>; public: + static const size_t npos = static_cast(-1); + + using element_type = T; + using value_type = std::remove_cv_t; + using size_type = size_t; + using difference_type = ptrdiff_t; + using pointer = T *; + using const_pointer = const T *; + using reference = T &; + using const_reference = const T &; + using iterator = T *; + using const_iterator = const T *; + constexpr Span() : Span(nullptr, 0) {} constexpr Span(T *ptr, size_t len) : data_(ptr), size_(len) {} @@ -126,10 +128,10 @@ class Span : private internal::SpanBase { constexpr size_t size() const { return size_; } constexpr bool empty() const { return size_ == 0; } - constexpr T *begin() const { return data_; } - constexpr const T *cbegin() const { return data_; } - constexpr T *end() const { return data_ + size_; } - constexpr const T *cend() const { return end(); } + constexpr iterator begin() const { return data_; } + constexpr const_iterator cbegin() const { return data_; } + constexpr iterator end() const { return data_ + size_; } + constexpr const_iterator cend() const { return end(); } constexpr T &front() const { if (size_ == 0) { @@ -212,6 +214,16 @@ constexpr Span MakeConstSpan(T (&array)[size]) { return array; } +#if __cplusplus >= 201703L +inline Span StringAsBytes(std::string_view s) { + return MakeConstSpan(reinterpret_cast(s.data()), s.size()); +} + +inline std::string_view BytesAsStringView(bssl::Span b) { + return std::string_view(reinterpret_cast(b.data()), b.size()); +} +#endif + BSSL_NAMESPACE_END } // extern C++ diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_target.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_target.h index d5b5c7e5..29b1dc61 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_target.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_target.h @@ -83,7 +83,8 @@ #endif // Trusty and Android baremetal aren't Linux but currently define __linux__. -// As a workaround, we exclude them here. We also exclude nanolibc. nanolibc +// As a workaround, we exclude them here. +// We also exclude nanolibc/CrOS EC/Zephyr. nanolibc/CrOS EC/Zephyr // sometimes build for a non-Linux target (which should not define __linux__), // but also sometimes build for Linux. Although technically running in Linux // userspace, this lacks all the libc APIs we'd normally expect on Linux, so we @@ -93,7 +94,8 @@ // TODO(b/291101350): Remove this workaround once Android baremetal no longer // defines it. #if defined(__linux__) && !defined(__TRUSTY__) && \ - !defined(ANDROID_BAREMETAL) && !defined(OPENSSL_NANOLIBC) + !defined(ANDROID_BAREMETAL) && !defined(OPENSSL_NANOLIBC) && \ + !defined(CROS_EC) && !defined(CROS_ZEPHYR) #define OPENSSL_LINUX #endif diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_time.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_time.h index be419501..4f879661 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_time.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_time.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2022, Google Inc. +/* Copyright (c) 2024, 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 @@ -15,31 +15,8 @@ #ifndef OPENSSL_HEADER_TIME_H #define OPENSSL_HEADER_TIME_H -#include "CCryptoBoringSSL_base.h" +// Compatibility header, to be deprecated. use instead. -#include - -#if defined(__cplusplus) -extern "C" { -#endif - - -// Time functions. - - -// OPENSSL_posix_to_tm converts a int64_t POSIX time value in |time|, which 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 |tm| contains out of range values. -OPENSSL_EXPORT int OPENSSL_tm_to_posix(const struct tm *tm, int64_t *out); - - -#if defined(__cplusplus) -} // extern C -#endif +#include "CCryptoBoringSSL_posix_time.h" #endif // OPENSSL_HEADER_TIME_H diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_x509.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_x509.h index 94b4b086..202a42af 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_x509.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_x509.h @@ -102,10 +102,6 @@ extern "C" { // // 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. @@ -240,9 +236,6 @@ OPENSSL_EXPORT void X509_get0_uids(const X509 *x509, #define EXFLAG_KUSAGE 0x2 // EXFLAG_XKUSAGE indicates the certifcate has an extended key usage extension. #define EXFLAG_XKUSAGE 0x4 -// EXFLAG_NSCERT indicates the certificate has a legacy Netscape certificate -// type extension. -#define EXFLAG_NSCERT 0x8 // EXFLAG_CA indicates the certificate has a basic constraints extension with // the CA bit set. #define EXFLAG_CA 0x10 @@ -277,7 +270,7 @@ OPENSSL_EXPORT uint32_t X509_get_extension_flags(X509 *x509); // // TODO(crbug.com/boringssl/381): Decoding an |X509| object will not check for // invalid extensions. To detect the error case, call -// |X509_get_extensions_flags| and check the |EXFLAG_INVALID| bit. +// |X509_get_extension_flags| and check the |EXFLAG_INVALID| bit. OPENSSL_EXPORT long X509_get_pathlen(X509 *x509); // X509v3_KU_* are key usage bits returned from |X509_get_key_usage|. @@ -336,7 +329,7 @@ OPENSSL_EXPORT uint32_t X509_get_extended_key_usage(X509 *x509); // // TODO(crbug.com/boringssl/381): Decoding an |X509| object will not check for // invalid extensions. To detect the error case, call -// |X509_get_extensions_flags| and check the |EXFLAG_INVALID| bit. +// |X509_get_extension_flags| and check the |EXFLAG_INVALID| bit. OPENSSL_EXPORT const ASN1_OCTET_STRING *X509_get0_subject_key_id(X509 *x509); // X509_get0_authority_key_id returns keyIdentifier of |x509|'s authority key @@ -347,7 +340,7 @@ OPENSSL_EXPORT const ASN1_OCTET_STRING *X509_get0_subject_key_id(X509 *x509); // // TODO(crbug.com/boringssl/381): Decoding an |X509| object will not check for // invalid extensions. To detect the error case, call -// |X509_get_extensions_flags| and check the |EXFLAG_INVALID| bit. +// |X509_get_extension_flags| and check the |EXFLAG_INVALID| bit. OPENSSL_EXPORT const ASN1_OCTET_STRING *X509_get0_authority_key_id(X509 *x509); DEFINE_STACK_OF(GENERAL_NAME) @@ -361,7 +354,7 @@ typedef STACK_OF(GENERAL_NAME) GENERAL_NAMES; // // TODO(crbug.com/boringssl/381): Decoding an |X509| object will not check for // invalid extensions. To detect the error case, call -// |X509_get_extensions_flags| and check the |EXFLAG_INVALID| bit. +// |X509_get_extension_flags| and check the |EXFLAG_INVALID| bit. OPENSSL_EXPORT const GENERAL_NAMES *X509_get0_authority_issuer(X509 *x509); // X509_get0_authority_serial returns the authorityCertSerialNumber of |x509|'s @@ -372,7 +365,7 @@ OPENSSL_EXPORT const GENERAL_NAMES *X509_get0_authority_issuer(X509 *x509); // // TODO(crbug.com/boringssl/381): Decoding an |X509| object will not check for // invalid extensions. To detect the error case, call -// |X509_get_extensions_flags| and check the |EXFLAG_INVALID| bit. +// |X509_get_extension_flags| and check the |EXFLAG_INVALID| bit. OPENSSL_EXPORT const ASN1_INTEGER *X509_get0_authority_serial(X509 *x509); // X509_get0_extensions returns |x509|'s extension list, or NULL if |x509| omits @@ -473,6 +466,22 @@ OPENSSL_EXPORT STACK_OF(OPENSSL_STRING) *X509_get1_ocsp(const X509 *x509); // |OPENSSL_malloc|. If |sk| is NULL, no action is taken. OPENSSL_EXPORT void X509_email_free(STACK_OF(OPENSSL_STRING) *sk); +// X509_cmp compares |a| and |b| and returns zero if they are equal, a negative +// number if |b| sorts after |a| and a negative number if |a| sorts after |b|. +// The sort order implemented by this function is arbitrary and does not +// reflect properties of the certificate such as expiry. Applications should not +// rely on the order itself. +// +// TODO(https://crbug.com/boringssl/355): This function works by comparing a +// cached hash of the encoded certificate. If |a| or |b| could not be +// serialized, the current behavior is to compare all unencodable certificates +// as equal. This function should only be used with |X509| objects that were +// parsed from bytes and never mutated. +// +// TODO(https://crbug.com/boringssl/407): This function is const, but it is not +// always thread-safe, notably if |a| and |b| were mutated. +OPENSSL_EXPORT int X509_cmp(const X509 *a, const X509 *b); + // Issuing certificates. // @@ -603,31 +612,38 @@ OPENSSL_EXPORT int X509_set1_signature_value(X509 *x509, const uint8_t *sig, // 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); +// +// TODO(crbug.com/boringssl/407): |x509| should be const. +OPENSSL_EXPORT int i2d_X509_AUX(X509 *x509, uint8_t **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|. // -// Some auxiliary properties affect trust decisions, so this function should not -// be used with untrusted input. +// WARNING: Passing untrusted input to this function allows an attacker to +// control auxiliary properties. This can allow unexpected influence over the +// application if the certificate is used in a context that reads auxiliary +// properties. This includes PKCS#12 serialization, trusted certificates in +// |X509_STORE|, and callers of |X509_alias_get0| or |X509_keyid_get0|. // // 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, +OPENSSL_EXPORT X509 *d2i_X509_AUX(X509 **x509, const uint8_t **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, +// itself and will not be serialized by |i2d_X509|. If |x509| is serialized in +// a PKCS#12 structure, the friendlyName attribute (RFC 2985) will contain this +// alias. +OPENSSL_EXPORT int X509_alias_set1(X509 *x509, const uint8_t *name, ossl_ssize_t 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, +OPENSSL_EXPORT int X509_keyid_set1(X509 *x509, const uint8_t *id, ossl_ssize_t len); // X509_alias_get0 looks up |x509|'s alias. If found, it sets |*out_len| to the @@ -642,7 +658,7 @@ OPENSSL_EXPORT int X509_keyid_set1(X509 *x509, const unsigned char *id, // 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); +OPENSSL_EXPORT const uint8_t *X509_alias_get0(const 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 @@ -652,16 +668,24 @@ OPENSSL_EXPORT unsigned char *X509_alias_get0(X509 *x509, int *out_len); // 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 const uint8_t *X509_keyid_get0(const X509 *x509, int *out_len); // X509_add1_trust_object configures |x509| as a valid trust anchor for |obj|. // It returns one on success and zero on error. |obj| should be a certificate -// usage OID associated with an |X509_TRUST| object. +// usage OID associated with an |X509_TRUST_*| constant. +// +// See |X509_VERIFY_PARAM_set_trust| for details on how this value is evaluated. +// Note this only takes effect if |x509| was configured as a trusted certificate +// via |X509_STORE|. OPENSSL_EXPORT int X509_add1_trust_object(X509 *x509, const ASN1_OBJECT *obj); // X509_add1_reject_object configures |x509| as distrusted for |obj|. It returns // one on success and zero on error. |obj| should be a certificate usage OID -// associated with an |X509_TRUST| object. +// associated with an |X509_TRUST_*| constant. +// +// See |X509_VERIFY_PARAM_set_trust| for details on how this value is evaluated. +// Note this only takes effect if |x509| was configured as a trusted certificate +// via |X509_STORE|. OPENSSL_EXPORT int X509_add1_reject_object(X509 *x509, const ASN1_OBJECT *obj); // X509_trust_clear clears the list of OIDs for which |x509| is trusted. See @@ -722,6 +746,18 @@ OPENSSL_EXPORT X509_CRL *d2i_X509_CRL(X509_CRL **out, const uint8_t **inp, // mutated. OPENSSL_EXPORT int i2d_X509_CRL(X509_CRL *crl, uint8_t **outp); +// X509_CRL_match compares |a| and |b| and returns zero if they are equal, a +// negative number if |b| sorts after |a| and a negative number if |a| sorts +// after |b|. The sort order implemented by this function is arbitrary and does +// not reflect properties of the CRL such as expiry. Applications should not +// rely on the order itself. +// +// TODO(https://crbug.com/boringssl/355): This function works by comparing a +// cached hash of the encoded CRL. This cached hash is computed when the CRL is +// parsed, but not when mutating or issuing CRLs. This function should only be +// used with |X509_CRL| objects that were parsed from bytes and never mutated. +OPENSSL_EXPORT int X509_CRL_match(const X509_CRL *a, const X509_CRL *b); + #define X509_CRL_VERSION_1 0 #define X509_CRL_VERSION_2 1 @@ -1390,12 +1426,17 @@ OPENSSL_EXPORT X509_NAME *X509_NAME_dup(X509_NAME *name); // Although even the library itself passes this to a sorting function. OPENSSL_EXPORT int X509_NAME_cmp(const X509_NAME *a, const X509_NAME *b); -// X509_NAME_get0_der sets |*out_der| and |*out_der_len| +// X509_NAME_get0_der marshals |name| as a DER-encoded X.509 Name (RFC 5280). On +// success, it returns one and sets |*out_der| and |*out_der_len| to a buffer +// containing the result. Otherwise, it returns zero. |*out_der| is owned by +// |name| and must not be freed by the caller. It is invalidated after |name| is +// mutated or freed. // // 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. +// |X509_NAME| functions, including this one, 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); @@ -1791,6 +1832,236 @@ OPENSSL_EXPORT STACK_OF(X509_EXTENSION) *X509v3_add_ext( STACK_OF(X509_EXTENSION) **x, const X509_EXTENSION *ex, int loc); +// Built-in extensions. +// +// Several functions in the library encode and decode extension values into a +// C structure to that extension. The following extensions are supported: +// +// - |NID_authority_key_identifier| with type |AUTHORITY_KEYID| +// - |NID_basic_constraints| with type |BASIC_CONSTRAINTS| +// - |NID_certificate_issuer| with type |GENERAL_NAMES| +// - |NID_certificate_policies| with type |CERTIFICATEPOLICIES| +// - |NID_crl_distribution_points| with type |CRL_DIST_POINTS| +// - |NID_crl_number| with type |ASN1_INTEGER| +// - |NID_crl_reason| with type |ASN1_ENUMERATED| +// - |NID_delta_crl| with type |ASN1_INTEGER| +// - |NID_ext_key_usage| with type |EXTENDED_KEY_USAGE| +// - |NID_freshest_crl| with type |ISSUING_DIST_POINT| +// - |NID_id_pkix_OCSP_noCheck| with type |ASN1_NULL| +// - |NID_info_access| with type |AUTHORITY_INFO_ACCESS| +// - |NID_inhibit_any_policy| with type |ASN1_INTEGER| +// - |NID_invalidity_date| with type |ASN1_GENERALIZEDTIME| +// - |NID_issuer_alt_name| with type |GENERAL_NAMES| +// - |NID_issuing_distribution_point| with type |ISSUING_DIST_POINT| +// - |NID_key_usage| with type |ASN1_BIT_STRING| +// - |NID_name_constraints| with type |NAME_CONSTRAINTS| +// - |NID_netscape_base_url| with type |ASN1_IA5STRING| +// - |NID_netscape_ca_policy_url| with type |ASN1_IA5STRING| +// - |NID_netscape_ca_revocation_url| with type |ASN1_IA5STRING| +// - |NID_netscape_cert_type| with type |ASN1_BIT_STRING| +// - |NID_netscape_comment| with type |ASN1_IA5STRING| +// - |NID_netscape_renewal_url| with type |ASN1_IA5STRING| +// - |NID_netscape_revocation_url| with type |ASN1_IA5STRING| +// - |NID_netscape_ssl_server_name| with type |ASN1_IA5STRING| +// - |NID_policy_constraints| with type |POLICY_CONSTRAINTS| +// - |NID_policy_mappings| with type |POLICY_MAPPINGS| +// - |NID_sinfo_access| with type |AUTHORITY_INFO_ACCESS| +// - |NID_subject_alt_name| with type |GENERAL_NAMES| +// - |NID_subject_key_identifier| with type |ASN1_OCTET_STRING| +// +// If an extension does not appear in this list, e.g. for a custom extension, +// callers can instead use functions such as |X509_get_ext_by_OBJ|, +// |X509_EXTENSION_get_data|, and |X509_EXTENSION_create_by_OBJ| to inspect or +// create extensions directly. Although the |X509V3_EXT_METHOD| mechanism allows +// registering custom extensions, doing so is deprecated and may result in +// threading or memory errors. + +// X509V3_EXT_d2i decodes |ext| and returns a pointer to a newly-allocated +// structure, with type dependent on the type of the extension. It returns NULL +// if |ext| is an unsupported extension or if there was a syntax error in the +// extension. The caller should cast the return value to the expected type and +// free the structure when done. +// +// WARNING: Casting the return value to the wrong type is a potentially +// exploitable memory error, so callers must not use this function before +// checking |ext| is of a known type. See the list at the top of this section +// for the correct types. +OPENSSL_EXPORT void *X509V3_EXT_d2i(const X509_EXTENSION *ext); + +// X509V3_get_d2i finds and decodes the extension in |extensions| of type |nid|. +// If found, it decodes it and returns a newly-allocated structure, with type +// dependent on |nid|. If the extension is not found or on error, it returns +// NULL. The caller may distinguish these cases using the |out_critical| value. +// +// If |out_critical| is not NULL, this function sets |*out_critical| to one if +// the extension is found and critical, zero if it is found and not critical, -1 +// if it is not found, and -2 if there is an invalid duplicate extension. Note +// this function may set |*out_critical| to one or zero and still return NULL if +// the extension is found but has a syntax error. +// +// If |out_idx| is not NULL, this function looks for the first occurrence of the +// extension after |*out_idx|. It then sets |*out_idx| to the index of the +// extension, or -1 if not found. If |out_idx| is non-NULL, duplicate extensions +// are not treated as an error. Callers, however, should not rely on this +// behavior as it may be removed in the future. Duplicate extensions are +// forbidden in RFC 5280. +// +// WARNING: This function is difficult to use correctly. Callers should pass a +// non-NULL |out_critical| and check both the return value and |*out_critical| +// to handle errors. If the return value is NULL and |*out_critical| is not -1, +// there was an error. Otherwise, the function succeeded and but may return NULL +// for a missing extension. Callers should pass NULL to |out_idx| so that +// duplicate extensions are handled correctly. +// +// Additionally, casting the return value to the wrong type is a potentially +// exploitable memory error, so callers must ensure the cast and |nid| match. +// See the list at the top of this section for the correct types. +OPENSSL_EXPORT void *X509V3_get_d2i(const STACK_OF(X509_EXTENSION) *extensions, + int nid, int *out_critical, int *out_idx); + +// X509V3_EXT_free casts |ext_data| into the type that corresponds to |nid| and +// releases memory associated with it. It returns one on success and zero if +// |nid| is not a known extension. +// +// WARNING: Casting |ext_data| to the wrong type is a potentially exploitable +// memory error, so callers must ensure |ext_data|'s type matches |nid|. See the +// list at the top of this section for the correct types. +// +// TODO(davidben): OpenSSL upstream no longer exposes this function. Remove it? +OPENSSL_EXPORT int X509V3_EXT_free(int nid, void *ext_data); + +// X509V3_EXT_i2d casts |ext_struc| into the type that corresponds to +// |ext_nid|, serializes it, and returns a newly-allocated |X509_EXTENSION| +// object containing the serialization, or NULL on error. The |X509_EXTENSION| +// has OID |ext_nid| and is critical if |crit| is one. +// +// WARNING: Casting |ext_struc| to the wrong type is a potentially exploitable +// memory error, so callers must ensure |ext_struct|'s type matches |ext_nid|. +// See the list at the top of this section for the correct types. +OPENSSL_EXPORT X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, + void *ext_struc); + +// The following constants control the behavior of |X509V3_add1_i2d| and related +// functions. + +// X509V3_ADD_OP_MASK can be ANDed with the flags to determine how duplicate +// extensions are processed. +#define X509V3_ADD_OP_MASK 0xfL + +// X509V3_ADD_DEFAULT causes the function to fail if the extension was already +// present. +#define X509V3_ADD_DEFAULT 0L + +// X509V3_ADD_APPEND causes the function to unconditionally appended the new +// extension to to the extensions list, even if there is a duplicate. +#define X509V3_ADD_APPEND 1L + +// X509V3_ADD_REPLACE causes the function to replace the existing extension, or +// append if it is not present. +#define X509V3_ADD_REPLACE 2L + +// X509V3_ADD_REPLACE_EXISTING causes the function to replace the existing +// extension and fail if it is not present. +#define X509V3_ADD_REPLACE_EXISTING 3L + +// X509V3_ADD_KEEP_EXISTING causes the function to succeed without replacing the +// extension if already present. +#define X509V3_ADD_KEEP_EXISTING 4L + +// X509V3_ADD_DELETE causes the function to remove the matching extension. No +// new extension is added. If there is no matching extension, the function +// fails. The |value| parameter is ignored in this mode. +#define X509V3_ADD_DELETE 5L + +// X509V3_ADD_SILENT may be ORed into one of the values above to indicate the +// function should not add to the error queue on duplicate or missing extension. +// The function will continue to return zero in those cases, and it will +// continue to return -1 and add to the error queue on other errors. +#define X509V3_ADD_SILENT 0x10 + +// X509V3_add1_i2d casts |value| to the type that corresponds to |nid|, +// serializes it, and appends it to the extension list in |*x|. If |*x| is NULL, +// it will set |*x| to a newly-allocated |STACK_OF(X509_EXTENSION)| as needed. +// The |crit| parameter determines whether the new extension is critical. +// |flags| may be some combination of the |X509V3_ADD_*| constants to control +// the function's behavior on duplicate extension. +// +// This function returns one on success, zero if the operation failed due to a +// missing or duplicate extension, and -1 on other errors. +// +// WARNING: Casting |value| to the wrong type is a potentially exploitable +// memory error, so callers must ensure |value|'s type matches |nid|. See the +// list at the top of this section for the correct types. +OPENSSL_EXPORT int X509V3_add1_i2d(STACK_OF(X509_EXTENSION) **x, int nid, + void *value, int crit, unsigned long flags); + + +// Basic constraints. +// +// The basic constraints extension (RFC 5280, section 4.2.1.9) determines +// whether a certificate is a CA certificate and, if so, optionally constrains +// the maximum depth of the certificate chain. + +// A BASIC_CONSTRAINTS_st, aka |BASIC_CONSTRAINTS| represents an +// BasicConstraints structure (RFC 5280). +struct BASIC_CONSTRAINTS_st { + ASN1_BOOLEAN ca; + ASN1_INTEGER *pathlen; +} /* BASIC_CONSTRAINTS */; + +// BASIC_CONSTRAINTS is an |ASN1_ITEM| whose ASN.1 type is BasicConstraints (RFC +// 5280) and C type is |BASIC_CONSTRAINTS*|. +DECLARE_ASN1_ITEM(BASIC_CONSTRAINTS) + +// BASIC_CONSTRAINTS_new returns a newly-allocated, empty |BASIC_CONSTRAINTS| +// object, or NULL on error. +OPENSSL_EXPORT BASIC_CONSTRAINTS *BASIC_CONSTRAINTS_new(void); + +// BASIC_CONSTRAINTS_free releases memory associated with |bcons|. +OPENSSL_EXPORT void BASIC_CONSTRAINTS_free(BASIC_CONSTRAINTS *bcons); + +// d2i_BASIC_CONSTRAINTS parses up to |len| bytes from |*inp| as a DER-encoded +// BasicConstraints (RFC 5280), as described in |d2i_SAMPLE|. +OPENSSL_EXPORT BASIC_CONSTRAINTS *d2i_BASIC_CONSTRAINTS(BASIC_CONSTRAINTS **out, + const uint8_t **inp, + long len); + +// i2d_BASIC_CONSTRAINTS marshals |bcons| as a DER-encoded BasicConstraints (RFC +// 5280), as described in |i2d_SAMPLE|. +OPENSSL_EXPORT int i2d_BASIC_CONSTRAINTS(const BASIC_CONSTRAINTS *bcons, + uint8_t **outp); + + +// Extended key usage. +// +// The extended key usage extension (RFC 5280, section 4.2.1.12) indicates the +// purposes of the certificate's public key. Such constraints are important to +// avoid cross-protocol attacks. + +typedef STACK_OF(ASN1_OBJECT) EXTENDED_KEY_USAGE; + +// EXTENDED_KEY_USAGE is an |ASN1_ITEM| whose ASN.1 type is ExtKeyUsageSyntax +// (RFC 5280) and C type is |STACK_OF(ASN1_OBJECT)*|, or |EXTENDED_KEY_USAGE*|. +DECLARE_ASN1_ITEM(EXTENDED_KEY_USAGE) + +// EXTENDED_KEY_USAGE_new returns a newly-allocated, empty |EXTENDED_KEY_USAGE| +// object, or NULL on error. +OPENSSL_EXPORT EXTENDED_KEY_USAGE *EXTENDED_KEY_USAGE_new(void); + +// EXTENDED_KEY_USAGE_free releases memory associated with |eku|. +OPENSSL_EXPORT void EXTENDED_KEY_USAGE_free(EXTENDED_KEY_USAGE *eku); + +// d2i_EXTENDED_KEY_USAGE parses up to |len| bytes from |*inp| as a DER-encoded +// ExtKeyUsageSyntax (RFC 5280), as described in |d2i_SAMPLE|. +OPENSSL_EXPORT EXTENDED_KEY_USAGE *d2i_EXTENDED_KEY_USAGE( + EXTENDED_KEY_USAGE **out, const uint8_t **inp, long len); + +// i2d_EXTENDED_KEY_USAGE marshals |eku| as a DER-encoded ExtKeyUsageSyntax (RFC +// 5280), as described in |i2d_SAMPLE|. +OPENSSL_EXPORT int i2d_EXTENDED_KEY_USAGE(const EXTENDED_KEY_USAGE *eku, + uint8_t **outp); + + // General names. // // A |GENERAL_NAME| represents an X.509 GeneralName structure, defined in RFC @@ -1824,11 +2095,14 @@ typedef struct EDIPartyName_st { #define GEN_IPADD 7 #define GEN_RID 8 -// A |GENERAL_NAME_st|, aka |GENERAL_NAME|, represents an X.509 GeneralName. The +// A GENERAL_NAME_st, aka |GENERAL_NAME|, represents an X.509 GeneralName. The // |type| field determines which member of |d| is active. A |GENERAL_NAME| may // also be empty, in which case |type| is -1 and |d| is NULL. Empty // |GENERAL_NAME|s are invalid and will never be returned from the parser, but // may be created temporarily, e.g. by |GENERAL_NAME_new|. +// +// WARNING: |type| and |d| must be kept consistent. An inconsistency will result +// in a potentially exploitable memory error. struct GENERAL_NAME_st { int type; union { @@ -1966,6 +2240,389 @@ OPENSSL_EXPORT int GENERAL_NAME_get0_otherName(const GENERAL_NAME *gen, ASN1_TYPE **out_value); +// Authority key identifier. +// +// The authority key identifier extension (RFC 5280, section 4.2.1.1) allows a +// certificate to more precisely identify its issuer. This is helpful when +// multiple certificates share a name. Only the keyIdentifier (|keyid| in +// |AUTHORITY_KEYID|) field is used in practice. + +// A AUTHORITY_KEYID_st, aka |AUTHORITY_KEYID|, represents an +// AuthorityKeyIdentifier structure (RFC 5280). +struct AUTHORITY_KEYID_st { + ASN1_OCTET_STRING *keyid; + GENERAL_NAMES *issuer; + ASN1_INTEGER *serial; +} /* AUTHORITY_KEYID */; + +// AUTHORITY_KEYID is an |ASN1_ITEM| whose ASN.1 type is AuthorityKeyIdentifier +// (RFC 5280) and C type is |AUTHORITY_KEYID*|. +DECLARE_ASN1_ITEM(AUTHORITY_KEYID) + +// AUTHORITY_KEYID_new returns a newly-allocated, empty |AUTHORITY_KEYID| +// object, or NULL on error. +OPENSSL_EXPORT AUTHORITY_KEYID *AUTHORITY_KEYID_new(void); + +// AUTHORITY_KEYID_free releases memory associated with |akid|. +OPENSSL_EXPORT void AUTHORITY_KEYID_free(AUTHORITY_KEYID *akid); + +// d2i_AUTHORITY_KEYID parses up to |len| bytes from |*inp| as a DER-encoded +// AuthorityKeyIdentifier (RFC 5280), as described in |d2i_SAMPLE|. +OPENSSL_EXPORT AUTHORITY_KEYID *d2i_AUTHORITY_KEYID(AUTHORITY_KEYID **out, + const uint8_t **inp, + long len); + +// i2d_AUTHORITY_KEYID marshals |akid| as a DER-encoded AuthorityKeyIdentifier +// (RFC 5280), as described in |i2d_SAMPLE|. +// +// TODO(https://crbug.com/boringssl/407): |akid| is not const because it +// contains an |X509_NAME|. +OPENSSL_EXPORT int i2d_AUTHORITY_KEYID(AUTHORITY_KEYID *akid, uint8_t **outp); + + +// Name constraints. +// +// The name constraints extension (RFC 5280, section 4.2.1.10) constrains which +// names may be asserted by certificates issued by some CA. For example, a +// general CA may issue an intermediate certificate to the owner of example.com, +// but constrained to ".example.com". + +// A GENERAL_SUBTREE represents a GeneralSubtree structure (RFC 5280). +typedef struct GENERAL_SUBTREE_st { + GENERAL_NAME *base; + ASN1_INTEGER *minimum; + ASN1_INTEGER *maximum; +} GENERAL_SUBTREE; + +DEFINE_STACK_OF(GENERAL_SUBTREE) + +// GENERAL_SUBTREE_new returns a newly-allocated, empty |GENERAL_SUBTREE| +// object, or NULL on error. +OPENSSL_EXPORT GENERAL_SUBTREE *GENERAL_SUBTREE_new(void); + +// GENERAL_SUBTREE_free releases memory associated with |subtree|. +OPENSSL_EXPORT void GENERAL_SUBTREE_free(GENERAL_SUBTREE *subtree); + +// A NAME_CONSTRAINTS_st, aka |NAME_CONSTRAINTS|, represents a NameConstraints +// structure (RFC 5280). +struct NAME_CONSTRAINTS_st { + STACK_OF(GENERAL_SUBTREE) *permittedSubtrees; + STACK_OF(GENERAL_SUBTREE) *excludedSubtrees; +} /* NAME_CONSTRAINTS */; + +// NAME_CONSTRAINTS is an |ASN1_ITEM| whose ASN.1 type is NameConstraints (RFC +// 5280) and C type is |NAME_CONSTRAINTS*|. +DECLARE_ASN1_ITEM(NAME_CONSTRAINTS) + +// NAME_CONSTRAINTS_new returns a newly-allocated, empty |NAME_CONSTRAINTS| +// object, or NULL on error. +OPENSSL_EXPORT NAME_CONSTRAINTS *NAME_CONSTRAINTS_new(void); + +// NAME_CONSTRAINTS_free releases memory associated with |ncons|. +OPENSSL_EXPORT void NAME_CONSTRAINTS_free(NAME_CONSTRAINTS *ncons); + + +// Authority information access. +// +// The authority information access extension (RFC 5280, 4.2.2.1) describes +// where to obtain information about the issuer of a certificate. It is most +// commonly used with accessMethod values of id-ad-caIssuers and id-ad-ocsp, to +// indicate where to fetch the issuer certificate (if not provided in-band) and +// the issuer's OCSP responder, respectively. + +// An ACCESS_DESCRIPTION represents an AccessDescription structure (RFC 5280). +typedef struct ACCESS_DESCRIPTION_st { + ASN1_OBJECT *method; + GENERAL_NAME *location; +} ACCESS_DESCRIPTION; + +DEFINE_STACK_OF(ACCESS_DESCRIPTION) + +// ACCESS_DESCRIPTION_new returns a newly-allocated, empty |ACCESS_DESCRIPTION| +// object, or NULL on error. +OPENSSL_EXPORT ACCESS_DESCRIPTION *ACCESS_DESCRIPTION_new(void); + +// ACCESS_DESCRIPTION_free releases memory associated with |desc|. +OPENSSL_EXPORT void ACCESS_DESCRIPTION_free(ACCESS_DESCRIPTION *desc); + +typedef STACK_OF(ACCESS_DESCRIPTION) AUTHORITY_INFO_ACCESS; + +// AUTHORITY_INFO_ACCESS is an |ASN1_ITEM| whose ASN.1 type is +// AuthorityInfoAccessSyntax (RFC 5280) and C type is +// |STACK_OF(ACCESS_DESCRIPTION)*|, or |AUTHORITY_INFO_ACCESS*|. +DECLARE_ASN1_ITEM(AUTHORITY_INFO_ACCESS) + +// AUTHORITY_INFO_ACCESS_new returns a newly-allocated, empty +// |AUTHORITY_INFO_ACCESS| object, or NULL on error. +OPENSSL_EXPORT AUTHORITY_INFO_ACCESS *AUTHORITY_INFO_ACCESS_new(void); + +// AUTHORITY_INFO_ACCESS_free releases memory associated with |aia|. +OPENSSL_EXPORT void AUTHORITY_INFO_ACCESS_free(AUTHORITY_INFO_ACCESS *aia); + +// d2i_AUTHORITY_INFO_ACCESS parses up to |len| bytes from |*inp| as a +// DER-encoded AuthorityInfoAccessSyntax (RFC 5280), as described in +// |d2i_SAMPLE|. +OPENSSL_EXPORT AUTHORITY_INFO_ACCESS *d2i_AUTHORITY_INFO_ACCESS( + AUTHORITY_INFO_ACCESS **out, const uint8_t **inp, long len); + +// i2d_AUTHORITY_INFO_ACCESS marshals |aia| as a DER-encoded +// AuthorityInfoAccessSyntax (RFC 5280), as described in |i2d_SAMPLE|. +// +// TODO(https://crbug.com/boringssl/407): |aia| is not const because it +// contains an |X509_NAME|. +OPENSSL_EXPORT int i2d_AUTHORITY_INFO_ACCESS(AUTHORITY_INFO_ACCESS *aia, + uint8_t **outp); + + +// CRL distribution points. +// +// The CRL distribution points extension (RFC 5280, 4.2.1.13) indicates where to +// fetch a certificate issuer's CRL. The corresponding issuing distribution +// point CRL extension (RFC 5280, section 5.2.5) matches against this extension. + +// A DIST_POINT_NAME represents a DistributionPointName structure (RFC 5280). +// The |name| field contains the CHOICE value and is determined by |type|. If +// |type| is zero, |name| must be a |fullname|. If |type| is one, |name| must be +// a |relativename|. +// +// WARNING: |type| and |name| must be kept consistent. An inconsistency will +// result in a potentially exploitable memory error. +typedef struct DIST_POINT_NAME_st { + int type; + union { + GENERAL_NAMES *fullname; + STACK_OF(X509_NAME_ENTRY) *relativename; + } name; + // If relativename then this contains the full distribution point name + X509_NAME *dpname; +} DIST_POINT_NAME; + +// DIST_POINT_NAME_new returns a newly-allocated, empty |DIST_POINT_NAME| +// object, or NULL on error. +OPENSSL_EXPORT DIST_POINT_NAME *DIST_POINT_NAME_new(void); + +// DIST_POINT_NAME_free releases memory associated with |name|. +OPENSSL_EXPORT void DIST_POINT_NAME_free(DIST_POINT_NAME *name); + +// A DIST_POINT_st, aka |DIST_POINT|, represents a DistributionPoint structure +// (RFC 5280). +struct DIST_POINT_st { + DIST_POINT_NAME *distpoint; + ASN1_BIT_STRING *reasons; + GENERAL_NAMES *CRLissuer; +} /* DIST_POINT */; + +DEFINE_STACK_OF(DIST_POINT) + +// DIST_POINT_new returns a newly-allocated, empty |DIST_POINT| object, or NULL +// on error. +OPENSSL_EXPORT DIST_POINT *DIST_POINT_new(void); + +// DIST_POINT_free releases memory associated with |dp|. +OPENSSL_EXPORT void DIST_POINT_free(DIST_POINT *dp); + +typedef STACK_OF(DIST_POINT) CRL_DIST_POINTS; + +// CRL_DIST_POINTS is an |ASN1_ITEM| whose ASN.1 type is CRLDistributionPoints +// (RFC 5280) and C type is |CRL_DIST_POINTS*|. +DECLARE_ASN1_ITEM(CRL_DIST_POINTS) + +// CRL_DIST_POINTS_new returns a newly-allocated, empty |CRL_DIST_POINTS| +// object, or NULL on error. +OPENSSL_EXPORT CRL_DIST_POINTS *CRL_DIST_POINTS_new(void); + +// CRL_DIST_POINTS_free releases memory associated with |crldp|. +OPENSSL_EXPORT void CRL_DIST_POINTS_free(CRL_DIST_POINTS *crldp); + +// d2i_CRL_DIST_POINTS parses up to |len| bytes from |*inp| as a DER-encoded +// CRLDistributionPoints (RFC 5280), as described in |d2i_SAMPLE|. +OPENSSL_EXPORT CRL_DIST_POINTS *d2i_CRL_DIST_POINTS(CRL_DIST_POINTS **out, + const uint8_t **inp, + long len); + +// i2d_CRL_DIST_POINTS marshals |crldp| as a DER-encoded CRLDistributionPoints +// (RFC 5280), as described in |i2d_SAMPLE|. +// +// TODO(https://crbug.com/boringssl/407): |crldp| is not const because it +// contains an |X509_NAME|. +OPENSSL_EXPORT int i2d_CRL_DIST_POINTS(CRL_DIST_POINTS *crldp, uint8_t **outp); + +// A ISSUING_DIST_POINT_st, aka |ISSUING_DIST_POINT|, represents a +// IssuingDistributionPoint structure (RFC 5280). +struct ISSUING_DIST_POINT_st { + DIST_POINT_NAME *distpoint; + ASN1_BOOLEAN onlyuser; + ASN1_BOOLEAN onlyCA; + ASN1_BIT_STRING *onlysomereasons; + ASN1_BOOLEAN indirectCRL; + ASN1_BOOLEAN onlyattr; +} /* ISSUING_DIST_POINT */; + +// ISSUING_DIST_POINT is an |ASN1_ITEM| whose ASN.1 type is +// IssuingDistributionPoint (RFC 5280) and C type is |ISSUING_DIST_POINT*|. +DECLARE_ASN1_ITEM(ISSUING_DIST_POINT) + +// ISSUING_DIST_POINT_new returns a newly-allocated, empty |ISSUING_DIST_POINT| +// object, or NULL on error. +OPENSSL_EXPORT ISSUING_DIST_POINT *ISSUING_DIST_POINT_new(void); + +// ISSUING_DIST_POINT_free releases memory associated with |idp|. +OPENSSL_EXPORT void ISSUING_DIST_POINT_free(ISSUING_DIST_POINT *idp); + +// d2i_ISSUING_DIST_POINT parses up to |len| bytes from |*inp| as a DER-encoded +// IssuingDistributionPoint (RFC 5280), as described in |d2i_SAMPLE|. +OPENSSL_EXPORT ISSUING_DIST_POINT *d2i_ISSUING_DIST_POINT( + ISSUING_DIST_POINT **out, const uint8_t **inp, long len); + +// i2d_ISSUING_DIST_POINT marshals |idp| as a DER-encoded +// IssuingDistributionPoint (RFC 5280), as described in |i2d_SAMPLE|. +// +// TODO(https://crbug.com/boringssl/407): |idp| is not const because it +// contains an |X509_NAME|. +OPENSSL_EXPORT int i2d_ISSUING_DIST_POINT(ISSUING_DIST_POINT *idp, + uint8_t **outp); + + +// Certificate policies. +// +// The certificate policies extension (RFC 5280, section 4.2.1.4), along with a +// suite of related extensions determines the "policies" that apply to a +// certificate path. Evaluating these policies is extremely complex and has led +// to denial-of-service vulnerabilities in several X.509 implementations. See +// draft-ietf-lamps-x509-policy-graph. +// +// Do not use this mechanism. + +// A NOTICEREF represents a NoticeReference structure (RFC 5280). +typedef struct NOTICEREF_st { + ASN1_STRING *organization; + STACK_OF(ASN1_INTEGER) *noticenos; +} NOTICEREF; + +// NOTICEREF_new returns a newly-allocated, empty |NOTICEREF| object, or NULL +// on error. +OPENSSL_EXPORT NOTICEREF *NOTICEREF_new(void); + +// NOTICEREF_free releases memory associated with |ref|. +OPENSSL_EXPORT void NOTICEREF_free(NOTICEREF *ref); + +// A USERNOTICE represents a UserNotice structure (RFC 5280). +typedef struct USERNOTICE_st { + NOTICEREF *noticeref; + ASN1_STRING *exptext; +} USERNOTICE; + +// USERNOTICE_new returns a newly-allocated, empty |USERNOTICE| object, or NULL +// on error. +OPENSSL_EXPORT USERNOTICE *USERNOTICE_new(void); + +// USERNOTICE_free releases memory associated with |notice|. +OPENSSL_EXPORT void USERNOTICE_free(USERNOTICE *notice); + +// A POLICYQUALINFO represents a PolicyQualifierInfo structure (RFC 5280). |d| +// contains the qualifier field of the PolicyQualifierInfo. Its type is +// determined by |pqualid|. If |pqualid| is |NID_id_qt_cps|, |d| must be +// |cpsuri|. If |pqualid| is |NID_id_qt_unotice|, |d| must be |usernotice|. +// Otherwise, |d| must be |other|. +// +// WARNING: |pqualid| and |d| must be kept consistent. An inconsistency will +// result in a potentially exploitable memory error. +typedef struct POLICYQUALINFO_st { + ASN1_OBJECT *pqualid; + union { + ASN1_IA5STRING *cpsuri; + USERNOTICE *usernotice; + ASN1_TYPE *other; + } d; +} POLICYQUALINFO; + +DEFINE_STACK_OF(POLICYQUALINFO) + +// POLICYQUALINFO_new returns a newly-allocated, empty |POLICYQUALINFO| object, +// or NULL on error. +OPENSSL_EXPORT POLICYQUALINFO *POLICYQUALINFO_new(void); + +// POLICYQUALINFO_free releases memory associated with |info|. +OPENSSL_EXPORT void POLICYQUALINFO_free(POLICYQUALINFO *info); + +// A POLICYINFO represents a PolicyInformation structure (RFC 5280). +typedef struct POLICYINFO_st { + ASN1_OBJECT *policyid; + STACK_OF(POLICYQUALINFO) *qualifiers; +} POLICYINFO; + +DEFINE_STACK_OF(POLICYINFO) + +// POLICYINFO_new returns a newly-allocated, empty |POLICYINFO| object, or NULL +// on error. +OPENSSL_EXPORT POLICYINFO *POLICYINFO_new(void); + +// POLICYINFO_free releases memory associated with |info|. +OPENSSL_EXPORT void POLICYINFO_free(POLICYINFO *info); + +typedef STACK_OF(POLICYINFO) CERTIFICATEPOLICIES; + +// CERTIFICATEPOLICIES is an |ASN1_ITEM| whose ASN.1 type is CertificatePolicies +// (RFC 5280) and C type is |STACK_OF(POLICYINFO)*|, or |CERTIFICATEPOLICIES*|. +DECLARE_ASN1_ITEM(CERTIFICATEPOLICIES) + +// CERTIFICATEPOLICIES_new returns a newly-allocated, empty +// |CERTIFICATEPOLICIES| object, or NULL on error. +OPENSSL_EXPORT CERTIFICATEPOLICIES *CERTIFICATEPOLICIES_new(void); + +// CERTIFICATEPOLICIES_free releases memory associated with |policies|. +OPENSSL_EXPORT void CERTIFICATEPOLICIES_free(CERTIFICATEPOLICIES *policies); + +// d2i_CERTIFICATEPOLICIES parses up to |len| bytes from |*inp| as a DER-encoded +// CertificatePolicies (RFC 5280), as described in |d2i_SAMPLE|. +OPENSSL_EXPORT CERTIFICATEPOLICIES *d2i_CERTIFICATEPOLICIES( + CERTIFICATEPOLICIES **out, const uint8_t **inp, long len); + +// i2d_CERTIFICATEPOLICIES marshals |policies| as a DER-encoded +// CertificatePolicies (RFC 5280), as described in |i2d_SAMPLE|. +OPENSSL_EXPORT int i2d_CERTIFICATEPOLICIES(const CERTIFICATEPOLICIES *policies, + uint8_t **outp); + +// A POLICY_MAPPING represents an individual element of a PolicyMappings +// structure (RFC 5280). +typedef struct POLICY_MAPPING_st { + ASN1_OBJECT *issuerDomainPolicy; + ASN1_OBJECT *subjectDomainPolicy; +} POLICY_MAPPING; + +DEFINE_STACK_OF(POLICY_MAPPING) + +// POLICY_MAPPING_new returns a newly-allocated, empty |POLICY_MAPPING| object, +// or NULL on error. +OPENSSL_EXPORT POLICY_MAPPING *POLICY_MAPPING_new(void); + +// POLICY_MAPPING_free releases memory associated with |mapping|. +OPENSSL_EXPORT void POLICY_MAPPING_free(POLICY_MAPPING *mapping); + +typedef STACK_OF(POLICY_MAPPING) POLICY_MAPPINGS; + +// POLICY_MAPPINGS is an |ASN1_ITEM| whose ASN.1 type is PolicyMappings (RFC +// 5280) and C type is |STACK_OF(POLICY_MAPPING)*|, or |POLICY_MAPPINGS*|. +DECLARE_ASN1_ITEM(POLICY_MAPPINGS) + +// A POLICY_CONSTRAINTS represents a PolicyConstraints structure (RFC 5280). +typedef struct POLICY_CONSTRAINTS_st { + ASN1_INTEGER *requireExplicitPolicy; + ASN1_INTEGER *inhibitPolicyMapping; +} POLICY_CONSTRAINTS; + +// POLICY_CONSTRAINTS is an |ASN1_ITEM| whose ASN.1 type is PolicyConstraints +// (RFC 5280) and C type is |POLICY_CONSTRAINTS*|. +DECLARE_ASN1_ITEM(POLICY_CONSTRAINTS) + +// POLICY_CONSTRAINTS_new returns a newly-allocated, empty |POLICY_CONSTRAINTS| +// object, or NULL on error. +OPENSSL_EXPORT POLICY_CONSTRAINTS *POLICY_CONSTRAINTS_new(void); + +// POLICY_CONSTRAINTS_free releases memory associated with |pcons|. +OPENSSL_EXPORT void POLICY_CONSTRAINTS_free(POLICY_CONSTRAINTS *pcons); + + // Algorithm identifiers. // // An |X509_ALGOR| represents an AlgorithmIdentifier structure, used in X.509 @@ -2178,6 +2835,959 @@ OPENSSL_EXPORT ASN1_TYPE *X509_ATTRIBUTE_get0_type(X509_ATTRIBUTE *attr, int idx); +// Certificate stores. +// +// An |X509_STORE| contains trusted certificates, CRLs, and verification +// parameters that are shared between multiple certificate verifications. +// +// Certificates in an |X509_STORE| are referred to as "trusted certificates", +// but an individual certificate verification may not necessarily treat every +// trusted certificate as a trust anchor. See |X509_VERIFY_PARAM_set_trust| for +// details. +// +// WARNING: Although a trusted certificate which fails the +// |X509_VERIFY_PARAM_set_trust| check is functionally an untrusted +// intermediate certificate, callers should not rely on this to configure +// untrusted intermediates in an |X509_STORE|. The trust check is complex, so +// this risks inadvertently treating it as a trust anchor. Instead, configure +// untrusted intermediates with the |chain| parameter of |X509_STORE_CTX_init|. +// +// Certificates in |X509_STORE| may be specified in several ways: +// - Added by |X509_STORE_add_cert|. +// - Returned by an |X509_LOOKUP| added by |X509_STORE_add_lookup|. +// +// |X509_STORE|s are reference-counted and may be shared by certificate +// verifications running concurrently on multiple threads. However, an +// |X509_STORE|'s verification parameters may not be modified concurrently with +// certificate verification or other operations. Unless otherwise documented, +// functions which take const pointer may be used concurrently, while +// functions which take a non-const pointer may not. Callers that wish to modify +// verification parameters in a shared |X509_STORE| should instead modify +// |X509_STORE_CTX|s individually. +// +// Objects in an |X509_STORE| are represented as an |X509_OBJECT|. Some +// functions in this library return values with this type. + +// X509_STORE_new returns a newly-allocated |X509_STORE|, or NULL on error. +OPENSSL_EXPORT X509_STORE *X509_STORE_new(void); + +// X509_STORE_up_ref adds one to the reference count of |store| and returns one. +// Although |store| is not const, this function's use of |store| is thread-safe. +OPENSSL_EXPORT int X509_STORE_up_ref(X509_STORE *store); + +// X509_STORE_free releases memory associated with |store|. +OPENSSL_EXPORT void X509_STORE_free(X509_STORE *store); + +// X509_STORE_add_cert adds |x509| to |store| as a trusted certificate. It +// returns one on success and zero on error. This function internally increments +// |x509|'s reference count, so the caller retains ownership of |x509|. +// +// Certificates configured by this function are still subject to the checks +// described in |X509_VERIFY_PARAM_set_trust|. +// +// Although |store| is not const, this function's use of |store| is thread-safe. +// However, if this function is called concurrently with |X509_verify_cert|, it +// is a race condition whether |x509| is available for issuer lookups. +// Moreover, the result may differ for each issuer lookup performed by a single +// |X509_verify_cert| call. +OPENSSL_EXPORT int X509_STORE_add_cert(X509_STORE *store, X509 *x509); + +// X509_STORE_add_crl adds |crl| to |store|. It returns one on success and zero +// on error. This function internally increments |crl|'s reference count, so the +// caller retains ownership of |crl|. CRLs added in this way are candidates for +// CRL lookup when |X509_V_FLAG_CRL_CHECK| is set. +// +// Although |store| is not const, this function's use of |store| is thread-safe. +// However, if this function is called concurrently with |X509_verify_cert|, it +// is a race condition whether |crl| is available for CRL checks. Moreover, the +// result may differ for each CRL check performed by a single +// |X509_verify_cert| call. +// +// Note there are no supported APIs to remove CRLs from |store| once inserted. +// To vary the set of CRLs over time, callers should either create a new +// |X509_STORE| or configure CRLs on a per-verification basis with +// |X509_STORE_CTX_set0_crls|. +OPENSSL_EXPORT int X509_STORE_add_crl(X509_STORE *store, X509_CRL *crl); + +// X509_STORE_get0_param returns |store|'s verification parameters. This object +// is mutable and may be modified by the caller. For an individual certificate +// verification operation, |X509_STORE_CTX_init| initializes the +// |X509_STORE_CTX|'s parameters with these parameters. +// +// WARNING: |X509_STORE_CTX_init| applies some default parameters (as in +// |X509_VERIFY_PARAM_inherit|) after copying |store|'s parameters. This means +// it is impossible to leave some parameters unset at |store|. They must be +// explicitly unset after creating the |X509_STORE_CTX|. +// +// As of writing these late defaults are a depth limit (see +// |X509_VERIFY_PARAM_set_depth|) and the |X509_V_FLAG_TRUSTED_FIRST| flag. This +// warning does not apply if the parameters were set in |store|. +// +// TODO(crbug.com/boringssl/441): This behavior is very surprising. Can we +// remove this notion of late defaults? The unsettable value at |X509_STORE| is +// -1, which rejects everything but explicitly-trusted self-signed certificates. +// |X509_V_FLAG_TRUSTED_FIRST| is mostly a workaround for poor path-building. +OPENSSL_EXPORT X509_VERIFY_PARAM *X509_STORE_get0_param(X509_STORE *store); + +// X509_STORE_set1_param copies verification parameters from |param| as in +// |X509_VERIFY_PARAM_set1|. It returns one on success and zero on error. +OPENSSL_EXPORT int X509_STORE_set1_param(X509_STORE *store, + const X509_VERIFY_PARAM *param); + +// X509_STORE_set_flags enables all values in |flags| in |store|'s verification +// flags. |flags| should be a combination of |X509_V_FLAG_*| constants. +// +// WARNING: These flags will be combined with default flags when copied to an +// |X509_STORE_CTX|. This means it is impossible to unset those defaults from +// the |X509_STORE|. See discussion in |X509_STORE_get0_param|. +OPENSSL_EXPORT int X509_STORE_set_flags(X509_STORE *store, unsigned long flags); + +// X509_STORE_set_depth configures |store| to, by default, limit certificate +// chains to |depth| intermediate certificates. This count excludes both the +// target certificate and the trust anchor (root certificate). +OPENSSL_EXPORT int X509_STORE_set_depth(X509_STORE *store, int depth); + +// X509_STORE_set_purpose configures the purpose check for |store|. See +// |X509_VERIFY_PARAM_set_purpose| for details. +OPENSSL_EXPORT int X509_STORE_set_purpose(X509_STORE *store, int purpose); + +// X509_STORE_set_trust configures the trust check for |store|. See +// |X509_VERIFY_PARAM_set_trust| for details. +OPENSSL_EXPORT int X509_STORE_set_trust(X509_STORE *store, int trust); + +// The following constants indicate the type of an |X509_OBJECT|. +#define X509_LU_NONE 0 +#define X509_LU_X509 1 +#define X509_LU_CRL 2 +#define X509_LU_PKEY 3 + +DEFINE_STACK_OF(X509_OBJECT) + +// X509_OBJECT_new returns a newly-allocated, empty |X509_OBJECT| or NULL on +// error. +OPENSSL_EXPORT X509_OBJECT *X509_OBJECT_new(void); + +// X509_OBJECT_free releases memory associated with |obj|. +OPENSSL_EXPORT void X509_OBJECT_free(X509_OBJECT *obj); + +// X509_OBJECT_get_type returns the type of |obj|, which will be one of the +// |X509_LU_*| constants. +OPENSSL_EXPORT int X509_OBJECT_get_type(const X509_OBJECT *obj); + +// X509_OBJECT_get0_X509 returns |obj| as a certificate, or NULL if |obj| is not +// a certificate. +OPENSSL_EXPORT X509 *X509_OBJECT_get0_X509(const X509_OBJECT *obj); + +// X509_STORE_get1_objects returns a newly-allocated stack containing the +// contents of |store|, or NULL on error. The caller must release the result +// with |sk_X509_OBJECT_pop_free| and |X509_OBJECT_free| when done. +// +// The result will include all certificates and CRLs added via +// |X509_STORE_add_cert| and |X509_STORE_add_crl|, as well as any cached objects +// added by |X509_LOOKUP_add_dir|. The last of these may change over time, as +// different objects are loaded from the filesystem. Callers should not depend +// on this caching behavior. The objects are returned in no particular order. +OPENSSL_EXPORT STACK_OF(X509_OBJECT) *X509_STORE_get1_objects( + X509_STORE *store); + + +// Certificate verification. +// +// An |X509_STORE_CTX| object represents a single certificate verification +// operation. To verify a certificate chain, callers construct an +// |X509_STORE_CTX|, initialize it with |X509_STORE_CTX_init|, configure extra +// parameters with |X509_STORE_CTX_get0_param|, and call |X509_verify_cert|. + +// X509_STORE_CTX_new returns a newly-allocated, empty |X509_STORE_CTX|, or NULL +// on error. +OPENSSL_EXPORT X509_STORE_CTX *X509_STORE_CTX_new(void); + +// X509_STORE_CTX_free releases memory associated with |ctx|. +OPENSSL_EXPORT void X509_STORE_CTX_free(X509_STORE_CTX *ctx); + +// X509_STORE_CTX_init initializes |ctx| to verify |x509|, using trusted +// certificates and parameters in |store|. It returns one on success and zero on +// error. |chain| is a list of untrusted intermediate certificates to use in +// verification. +// +// |ctx| stores pointers to |store|, |x509|, and |chain|. Each of these objects +// must outlive |ctx| and may not be mutated for the duration of the certificate +// verification. +OPENSSL_EXPORT int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, + X509 *x509, STACK_OF(X509) *chain); + +// X509_verify_cert performs certifice verification with |ctx|, which must have +// been initialized with |X509_STORE_CTX_init|. It returns one on success and +// zero on error. On success, |X509_STORE_CTX_get0_chain| or +// |X509_STORE_CTX_get1_chain| may be used to return the verified certificate +// chain. On error, |X509_STORE_CTX_get_error| may be used to return additional +// error information. +OPENSSL_EXPORT int X509_verify_cert(X509_STORE_CTX *ctx); + +// X509_STORE_CTX_get0_chain, after a successful |X509_verify_cert| call, +// returns the verified certificate chain. The chain begins with the leaf and +// ends with trust anchor. +// +// At other points, such as after a failed verification or during the deprecated +// verification callback, it returns the partial chain built so far. Callers +// should avoid relying on this as this exposes unstable library implementation +// details. +OPENSSL_EXPORT STACK_OF(X509) *X509_STORE_CTX_get0_chain( + const X509_STORE_CTX *ctx); + +// X509_STORE_CTX_get1_chain behaves like |X509_STORE_CTX_get0_chain| but +// returns a newly-allocated |STACK_OF(X509)| containing the completed chain, +// with each certificate's reference count incremented. Callers must free the +// result with |sk_X509_pop_free| and |X509_free| when done. +OPENSSL_EXPORT STACK_OF(X509) *X509_STORE_CTX_get1_chain( + const X509_STORE_CTX *ctx); + +// The following values are possible outputs of |X509_STORE_CTX_get_error|. +#define X509_V_OK 0 +#define X509_V_ERR_UNSPECIFIED 1 +#define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT 2 +#define X509_V_ERR_UNABLE_TO_GET_CRL 3 +#define X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE 4 +#define X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE 5 +#define X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY 6 +#define X509_V_ERR_CERT_SIGNATURE_FAILURE 7 +#define X509_V_ERR_CRL_SIGNATURE_FAILURE 8 +#define X509_V_ERR_CERT_NOT_YET_VALID 9 +#define X509_V_ERR_CERT_HAS_EXPIRED 10 +#define X509_V_ERR_CRL_NOT_YET_VALID 11 +#define X509_V_ERR_CRL_HAS_EXPIRED 12 +#define X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD 13 +#define X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD 14 +#define X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD 15 +#define X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD 16 +#define X509_V_ERR_OUT_OF_MEM 17 +#define X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT 18 +#define X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN 19 +#define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY 20 +#define X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE 21 +#define X509_V_ERR_CERT_CHAIN_TOO_LONG 22 +#define X509_V_ERR_CERT_REVOKED 23 +#define X509_V_ERR_INVALID_CA 24 +#define X509_V_ERR_PATH_LENGTH_EXCEEDED 25 +#define X509_V_ERR_INVALID_PURPOSE 26 +#define X509_V_ERR_CERT_UNTRUSTED 27 +#define X509_V_ERR_CERT_REJECTED 28 +#define X509_V_ERR_SUBJECT_ISSUER_MISMATCH 29 +#define X509_V_ERR_AKID_SKID_MISMATCH 30 +#define X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH 31 +#define X509_V_ERR_KEYUSAGE_NO_CERTSIGN 32 +#define X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER 33 +#define X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION 34 +#define X509_V_ERR_KEYUSAGE_NO_CRL_SIGN 35 +#define X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION 36 +#define X509_V_ERR_INVALID_NON_CA 37 +#define X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED 38 +#define X509_V_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE 39 +#define X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED 40 +#define X509_V_ERR_INVALID_EXTENSION 41 +#define X509_V_ERR_INVALID_POLICY_EXTENSION 42 +#define X509_V_ERR_NO_EXPLICIT_POLICY 43 +#define X509_V_ERR_DIFFERENT_CRL_SCOPE 44 +#define X509_V_ERR_UNSUPPORTED_EXTENSION_FEATURE 45 +#define X509_V_ERR_UNNESTED_RESOURCE 46 +#define X509_V_ERR_PERMITTED_VIOLATION 47 +#define X509_V_ERR_EXCLUDED_VIOLATION 48 +#define X509_V_ERR_SUBTREE_MINMAX 49 +#define X509_V_ERR_APPLICATION_VERIFICATION 50 +#define X509_V_ERR_UNSUPPORTED_CONSTRAINT_TYPE 51 +#define X509_V_ERR_UNSUPPORTED_CONSTRAINT_SYNTAX 52 +#define X509_V_ERR_UNSUPPORTED_NAME_SYNTAX 53 +#define X509_V_ERR_CRL_PATH_VALIDATION_ERROR 54 +#define X509_V_ERR_HOSTNAME_MISMATCH 62 +#define X509_V_ERR_EMAIL_MISMATCH 63 +#define X509_V_ERR_IP_ADDRESS_MISMATCH 64 +#define X509_V_ERR_INVALID_CALL 65 +#define X509_V_ERR_STORE_LOOKUP 66 +#define X509_V_ERR_NAME_CONSTRAINTS_WITHOUT_SANS 67 + +// X509_STORE_CTX_get_error, after |X509_verify_cert| returns, returns +// |X509_V_OK| if verification succeeded or an |X509_V_ERR_*| describing why +// verification failed. This will be consistent with |X509_verify_cert|'s return +// value, unless the caller used the deprecated verification callback (see +// |X509_STORE_CTX_set_verify_cb|) in a way that breaks |ctx|'s invariants. +// +// If called during the deprecated verification callback when |ok| is zero, it +// returns the current error under consideration. +OPENSSL_EXPORT int X509_STORE_CTX_get_error(const X509_STORE_CTX *ctx); + +// X509_STORE_CTX_set_error sets |ctx|'s error to |err|, which should be +// |X509_V_OK| or an |X509_V_ERR_*| constant. It is not expected to be called in +// typical |X509_STORE_CTX| usage, but may be used in callback APIs where +// applications synthesize |X509_STORE_CTX| error conditions. See also +// |X509_STORE_CTX_set_verify_cb| and |SSL_CTX_set_cert_verify_callback|. +OPENSSL_EXPORT void X509_STORE_CTX_set_error(X509_STORE_CTX *ctx, int err); + +// 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. +OPENSSL_EXPORT const char *X509_verify_cert_error_string(long err); + +// X509_STORE_CTX_get_error_depth returns the depth at which the error returned +// by |X509_STORE_CTX_get_error| occured. This is zero-indexed integer into the +// certificate chain. Zero indicates the target certificate, one its issuer, and +// so on. +OPENSSL_EXPORT int X509_STORE_CTX_get_error_depth(const X509_STORE_CTX *ctx); + +// X509_STORE_CTX_get_current_cert returns the certificate which caused the +// error returned by |X509_STORE_CTX_get_error|. +OPENSSL_EXPORT X509 *X509_STORE_CTX_get_current_cert(const X509_STORE_CTX *ctx); + +// X509_STORE_CTX_get0_current_crl returns the CRL which caused the error +// returned by |X509_STORE_CTX_get_error|. +OPENSSL_EXPORT X509_CRL *X509_STORE_CTX_get0_current_crl( + const X509_STORE_CTX *ctx); + +// X509_STORE_CTX_get0_store returns the |X509_STORE| that |ctx| uses. +OPENSSL_EXPORT X509_STORE *X509_STORE_CTX_get0_store(const X509_STORE_CTX *ctx); + +// X509_STORE_CTX_get0_cert returns the leaf certificate that |ctx| is +// verifying. +OPENSSL_EXPORT X509 *X509_STORE_CTX_get0_cert(const X509_STORE_CTX *ctx); + +// X509_STORE_CTX_get0_untrusted returns the stack of untrusted intermediates +// used by |ctx| for certificate verification. +OPENSSL_EXPORT STACK_OF(X509) *X509_STORE_CTX_get0_untrusted( + const X509_STORE_CTX *ctx); + +// X509_STORE_CTX_set0_trusted_stack configures |ctx| to trust the certificates +// in |sk|. |sk| must remain valid for the duration of |ctx|. Calling this +// function causes |ctx| to ignore any certificates configured in the +// |X509_STORE|. Certificates in |sk| are still subject to the check described +// in |X509_VERIFY_PARAM_set_trust|. +// +// 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_set0_crls configures |ctx| to consider the CRLs in |sk| as +// candidates for CRL lookup. |sk| must remain valid for the duration of |ctx|. +// These CRLs are considered in addition to CRLs found in |X509_STORE|. +// +// 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_crls(X509_STORE_CTX *ctx, + STACK_OF(X509_CRL) *sk); + +// X509_STORE_CTX_set_default looks up the set of parameters named |name| and +// applies those default verification parameters for |ctx|. As in +// |X509_VERIFY_PARAM_inherit|, only unset parameters are changed. This function +// returns one on success and zero on error. +// +// The supported values of |name| are: +// - "default" is an internal value which configures some late defaults. See the +// discussion in |X509_STORE_get0_param|. +// - "pkcs7" configures default trust and purpose checks for PKCS#7 signatures. +// - "smime_sign" configures trust and purpose checks for S/MIME signatures. +// - "ssl_client" configures trust and purpose checks for TLS clients. +// - "ssl_server" configures trust and purpose checks for TLS servers. +// +// TODO(crbug.com/boringssl/441): Make "default" a no-op. +OPENSSL_EXPORT int X509_STORE_CTX_set_default(X509_STORE_CTX *ctx, + const char *name); + +// X509_STORE_CTX_get0_param returns |ctx|'s verification parameters. This +// object is mutable and may be modified by the caller. +OPENSSL_EXPORT X509_VERIFY_PARAM *X509_STORE_CTX_get0_param( + X509_STORE_CTX *ctx); + +// X509_STORE_CTX_set0_param returns |ctx|'s verification parameters to |param| +// and takes ownership of |param|. After this function returns, the caller +// should not free |param|. +// +// WARNING: This function discards any values which were previously applied in +// |ctx|, including the "default" parameters applied late in +// |X509_STORE_CTX_init|. These late defaults are not applied to parameters +// created standalone by |X509_VERIFY_PARAM_new|. +// +// TODO(crbug.com/boringssl/441): This behavior is very surprising. Should we +// re-apply the late defaults in |param|, or somehow avoid this notion of late +// defaults altogether? +OPENSSL_EXPORT void X509_STORE_CTX_set0_param(X509_STORE_CTX *ctx, + X509_VERIFY_PARAM *param); + +// X509_STORE_CTX_set_flags enables all values in |flags| in |ctx|'s +// verification flags. |flags| should be a combination of |X509_V_FLAG_*| +// constants. +OPENSSL_EXPORT void X509_STORE_CTX_set_flags(X509_STORE_CTX *ctx, + unsigned long flags); + +// X509_STORE_CTX_set_time configures certificate verification to use |t| +// instead of the current time. |flags| is ignored and should be zero. +OPENSSL_EXPORT void X509_STORE_CTX_set_time(X509_STORE_CTX *ctx, + unsigned long flags, time_t t); + +// X509_STORE_CTX_set_time_posix configures certificate verification to use |t| +// instead of the current time. |t| is interpreted as a POSIX timestamp in +// seconds. |flags| is ignored and should be zero. +OPENSSL_EXPORT void X509_STORE_CTX_set_time_posix(X509_STORE_CTX *ctx, + unsigned long flags, + int64_t t); + +// X509_STORE_CTX_set_depth configures |ctx| to, by default, limit certificate +// chains to |depth| intermediate certificates. This count excludes both the +// target certificate and the trust anchor (root certificate). +OPENSSL_EXPORT void X509_STORE_CTX_set_depth(X509_STORE_CTX *ctx, int depth); + +// X509_STORE_CTX_set_purpose simultaneously configures |ctx|'s purpose and +// trust checks, if unset. It returns one on success and zero if |purpose| is +// not a valid purpose value. |purpose| should be an |X509_PURPOSE_*| constant. +// If so, it configures |ctx| with a purpose check of |purpose| and a trust +// check of |purpose|'s corresponding trust value. If either the purpose or +// trust check had already been specified for |ctx|, that corresponding +// modification is silently dropped. +// +// See |X509_VERIFY_PARAM_set_purpose| and |X509_VERIFY_PARAM_set_trust| for +// details on the purpose and trust checks, respectively. +// +// If |purpose| is |X509_PURPOSE_ANY|, this function returns an error because it +// has no corresponding |X509_TRUST_*| value. It is not possible to set +// |X509_PURPOSE_ANY| with this function, only |X509_VERIFY_PARAM_set_purpose|. +// +// WARNING: Unlike similarly named functions in this header, this function +// silently does not behave the same as |X509_VERIFY_PARAM_set_purpose|. Callers +// may use |X509_VERIFY_PARAM_set_purpose| with |X509_STORE_CTX_get0_param| to +// avoid this difference. +OPENSSL_EXPORT int X509_STORE_CTX_set_purpose(X509_STORE_CTX *ctx, int purpose); + +// X509_STORE_CTX_set_trust configures |ctx|'s trust check, if unset. It returns +// one on success and zero if |trust| is not a valid trust value. |trust| should +// be an |X509_TRUST_*| constant. If so, it configures |ctx| with a trust check +// of |trust|. If the trust check had already been specified for |ctx|, it +// silently does nothing. +// +// See |X509_VERIFY_PARAM_set_trust| for details on the purpose and trust check. +// +// WARNING: Unlike similarly named functions in this header, this function +// does not behave the same as |X509_VERIFY_PARAM_set_trust|. Callers may use +// |X509_VERIFY_PARAM_set_trust| with |X509_STORE_CTX_get0_param| to avoid this +// difference. +OPENSSL_EXPORT int X509_STORE_CTX_set_trust(X509_STORE_CTX *ctx, int trust); + + +// Verification parameters. +// +// An |X509_VERIFY_PARAM| contains a set of parameters for certificate +// verification. + +// X509_VERIFY_PARAM_new returns a newly-allocated |X509_VERIFY_PARAM|, or NULL +// on error. +OPENSSL_EXPORT X509_VERIFY_PARAM *X509_VERIFY_PARAM_new(void); + +// X509_VERIFY_PARAM_free releases memory associated with |param|. +OPENSSL_EXPORT void X509_VERIFY_PARAM_free(X509_VERIFY_PARAM *param); + +// X509_VERIFY_PARAM_inherit applies |from| as the default values for |to|. That +// is, for each parameter that is unset in |to|, it copies the value in |from|. +// This function returns one on success and zero on error. +OPENSSL_EXPORT int X509_VERIFY_PARAM_inherit(X509_VERIFY_PARAM *to, + const X509_VERIFY_PARAM *from); + +// X509_VERIFY_PARAM_set1 copies parameters from |from| to |to|. If a parameter +// is unset in |from|, the existing value in |to| is preserved. This function +// returns one on success and zero on error. +OPENSSL_EXPORT int X509_VERIFY_PARAM_set1(X509_VERIFY_PARAM *to, + const X509_VERIFY_PARAM *from); + +// X509_V_FLAG_* are flags for |X509_VERIFY_PARAM_set_flags| and +// |X509_VERIFY_PARAM_clear_flags|. + +// X509_V_FLAG_CB_ISSUER_CHECK causes the deprecated verify callback (see +// |X509_STORE_CTX_set_verify_cb|) to be called for errors while matching +// subject and issuer certificates. +#define X509_V_FLAG_CB_ISSUER_CHECK 0x1 +// X509_V_FLAG_USE_CHECK_TIME is an internal flag used to track whether +// |X509_STORE_CTX_set_time| has been used. If cleared, the system time is +// restored. +#define X509_V_FLAG_USE_CHECK_TIME 0x2 +// X509_V_FLAG_CRL_CHECK enables CRL lookup and checking for the leaf. +#define X509_V_FLAG_CRL_CHECK 0x4 +// X509_V_FLAG_CRL_CHECK_ALL enables CRL lookup and checking for the entire +// certificate chain. |X509_V_FLAG_CRL_CHECK| must be set for this flag to take +// effect. +#define X509_V_FLAG_CRL_CHECK_ALL 0x8 +// X509_V_FLAG_IGNORE_CRITICAL ignores unhandled critical extensions. Do not use +// this option. Critical extensions ensure the verifier does not bypass +// unrecognized security restrictions in certificates. +#define X509_V_FLAG_IGNORE_CRITICAL 0x10 +// X509_V_FLAG_X509_STRICT does nothing. Its functionality has been enabled by +// default. +#define X509_V_FLAG_X509_STRICT 0x00 +// X509_V_FLAG_ALLOW_PROXY_CERTS does nothing. Proxy certificate support has +// been removed. +#define X509_V_FLAG_ALLOW_PROXY_CERTS 0x40 +// X509_V_FLAG_POLICY_CHECK does nothing. Policy checking is always enabled. +#define X509_V_FLAG_POLICY_CHECK 0x80 +// X509_V_FLAG_EXPLICIT_POLICY requires some policy OID to be asserted by the +// final certificate chain. See initial-explicit-policy from RFC 5280, +// section 6.1.1. +#define X509_V_FLAG_EXPLICIT_POLICY 0x100 +// X509_V_FLAG_INHIBIT_ANY inhibits the anyPolicy OID. See +// initial-any-policy-inhibit from RFC 5280, section 6.1.1. +#define X509_V_FLAG_INHIBIT_ANY 0x200 +// X509_V_FLAG_INHIBIT_MAP inhibits policy mapping. See +// initial-policy-mapping-inhibit from RFC 5280, section 6.1.1. +#define X509_V_FLAG_INHIBIT_MAP 0x400 +// X509_V_FLAG_NOTIFY_POLICY does nothing. Its functionality has been removed. +#define X509_V_FLAG_NOTIFY_POLICY 0x800 +// X509_V_FLAG_EXTENDED_CRL_SUPPORT causes all verifications to fail. Extended +// CRL features have been removed. +#define X509_V_FLAG_EXTENDED_CRL_SUPPORT 0x1000 +// X509_V_FLAG_USE_DELTAS causes all verifications to fail. Delta CRL support +// has been removed. +#define X509_V_FLAG_USE_DELTAS 0x2000 +// X509_V_FLAG_CHECK_SS_SIGNATURE checks the redundant signature on self-signed +// trust anchors. This check provides no security benefit and only wastes CPU. +#define X509_V_FLAG_CHECK_SS_SIGNATURE 0x4000 +// X509_V_FLAG_TRUSTED_FIRST, during path-building, checks for a match in the +// trust store before considering an untrusted intermediate. This flag is +// enabled by default. +#define X509_V_FLAG_TRUSTED_FIRST 0x8000 +// X509_V_FLAG_PARTIAL_CHAIN treats all trusted certificates as trust anchors, +// independent of the |X509_VERIFY_PARAM_set_trust| setting. +#define X509_V_FLAG_PARTIAL_CHAIN 0x80000 +// X509_V_FLAG_NO_ALT_CHAINS disables building alternative chains if the initial +// one was rejected. +#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 + +// X509_VERIFY_PARAM_set_flags enables all values in |flags| in |param|'s +// verification flags and returns one. |flags| should be a combination of +// |X509_V_FLAG_*| constants. +OPENSSL_EXPORT int X509_VERIFY_PARAM_set_flags(X509_VERIFY_PARAM *param, + unsigned long flags); + +// X509_VERIFY_PARAM_clear_flags disables all values in |flags| in |param|'s +// verification flags and returns one. |flags| should be a combination of +// |X509_V_FLAG_*| constants. +OPENSSL_EXPORT int X509_VERIFY_PARAM_clear_flags(X509_VERIFY_PARAM *param, + unsigned long flags); + +// X509_VERIFY_PARAM_get_flags returns |param|'s verification flags. +OPENSSL_EXPORT unsigned long X509_VERIFY_PARAM_get_flags( + const X509_VERIFY_PARAM *param); + +// X509_VERIFY_PARAM_set_depth configures |param| to limit certificate chains to +// |depth| intermediate certificates. This count excludes both the target +// certificate and the trust anchor (root certificate). +OPENSSL_EXPORT void X509_VERIFY_PARAM_set_depth(X509_VERIFY_PARAM *param, + int depth); + +// X509_VERIFY_PARAM_get_depth returns the maximum depth configured in |param|. +// See |X509_VERIFY_PARAM_set_depth|. +OPENSSL_EXPORT int X509_VERIFY_PARAM_get_depth(const X509_VERIFY_PARAM *param); + +// X509_VERIFY_PARAM_set_time configures certificate verification to use |t| +// instead of the current time. +OPENSSL_EXPORT void X509_VERIFY_PARAM_set_time(X509_VERIFY_PARAM *param, + time_t t); + +// X509_VERIFY_PARAM_set_time_posix configures certificate verification to use +// |t| instead of the current time. |t| is interpreted as a POSIX timestamp in +// seconds. +OPENSSL_EXPORT void X509_VERIFY_PARAM_set_time_posix(X509_VERIFY_PARAM *param, + int64_t t); + +// X509_VERIFY_PARAM_add0_policy adds |policy| to the user-initial-policy-set +// (see Section 6.1.1 of RFC 5280). On success, it takes ownership of +// |policy| and returns one. Otherwise, it returns zero and the caller retains +// owneship of |policy|. +OPENSSL_EXPORT int X509_VERIFY_PARAM_add0_policy(X509_VERIFY_PARAM *param, + ASN1_OBJECT *policy); + +// X509_VERIFY_PARAM_set1_policies sets the user-initial-policy-set (see +// Section 6.1.1 of RFC 5280) to a copy of |policies|. It returns one on success +// and zero on error. +OPENSSL_EXPORT int X509_VERIFY_PARAM_set1_policies( + X509_VERIFY_PARAM *param, const STACK_OF(ASN1_OBJECT) *policies); + +// X509_VERIFY_PARAM_set1_host configures |param| to check for the DNS name +// specified by |name|. It returns one on success and zero on error. +// +// By default, both subject alternative names and the subject's common name +// attribute are checked. The latter has long been deprecated, so callers should +// call |X509_VERIFY_PARAM_set_hostflags| with +// |X509_CHECK_FLAG_NEVER_CHECK_SUBJECT| to use the standard behavior. +// https://crbug.com/boringssl/464 tracks fixing the default. +OPENSSL_EXPORT int X509_VERIFY_PARAM_set1_host(X509_VERIFY_PARAM *param, + const char *name, + size_t name_len); + +// X509_VERIFY_PARAM_add1_host adds |name| to the list of names checked by +// |param|. If any configured DNS name matches the certificate, verification +// succeeds. It returns one on success and zero on error. +// +// By default, both subject alternative names and the subject's common name +// attribute are checked. The latter has long been deprecated, so callers should +// call |X509_VERIFY_PARAM_set_hostflags| with +// |X509_CHECK_FLAG_NEVER_CHECK_SUBJECT| to use the standard behavior. +// https://crbug.com/boringssl/464 tracks fixing the default. +OPENSSL_EXPORT int X509_VERIFY_PARAM_add1_host(X509_VERIFY_PARAM *param, + const char *name, + size_t name_len); + +// X509_CHECK_FLAG_NO_WILDCARDS disables wildcard matching for DNS names. +#define X509_CHECK_FLAG_NO_WILDCARDS 0x2 + +// X509_CHECK_FLAG_NEVER_CHECK_SUBJECT disables the subject fallback, normally +// enabled when subjectAltNames is missing. +#define X509_CHECK_FLAG_NEVER_CHECK_SUBJECT 0x20 + +// X509_VERIFY_PARAM_set_hostflags sets the name-checking flags on |param| to +// |flags|. |flags| should be a combination of |X509_CHECK_FLAG_*| constants. +OPENSSL_EXPORT void X509_VERIFY_PARAM_set_hostflags(X509_VERIFY_PARAM *param, + unsigned int flags); + +// X509_VERIFY_PARAM_set1_email configures |param| to check for the email +// address specified by |email|. It returns one on success and zero on error. +// +// By default, both subject alternative names and the subject's email address +// attribute are checked. The |X509_CHECK_FLAG_NEVER_CHECK_SUBJECT| flag may be +// used to change this behavior. +OPENSSL_EXPORT int X509_VERIFY_PARAM_set1_email(X509_VERIFY_PARAM *param, + const char *email, + size_t email_len); + +// X509_VERIFY_PARAM_set1_ip configures |param| to check for the IP address +// specified by |ip|. It returns one on success and zero on error. The IP +// address is specified in its binary representation. |ip_len| must be 4 for an +// IPv4 address and 16 for an IPv6 address. +OPENSSL_EXPORT int X509_VERIFY_PARAM_set1_ip(X509_VERIFY_PARAM *param, + const uint8_t *ip, size_t ip_len); + +// X509_VERIFY_PARAM_set1_ip_asc decodes |ipasc| as the ASCII representation of +// an IPv4 or IPv6 address, and configures |param| to check for it. It returns +// one on success and zero on error. +OPENSSL_EXPORT int X509_VERIFY_PARAM_set1_ip_asc(X509_VERIFY_PARAM *param, + const char *ipasc); + +// X509_PURPOSE_SSL_CLIENT validates TLS client certificates. It checks for the +// id-kp-clientAuth EKU and one of digitalSignature or keyAgreement key usages. +// The TLS library is expected to check for the key usage specific to the +// negotiated TLS parameters. +#define X509_PURPOSE_SSL_CLIENT 1 +// X509_PURPOSE_SSL_SERVER validates TLS server certificates. It checks for the +// id-kp-clientAuth EKU and one of digitalSignature, keyAgreement, or +// keyEncipherment key usages. The TLS library is expected to check for the key +// usage specific to the negotiated TLS parameters. +#define X509_PURPOSE_SSL_SERVER 2 +// X509_PURPOSE_NS_SSL_SERVER is a legacy mode. It behaves like +// |X509_PURPOSE_SSL_SERVER|, but only accepts the keyEncipherment key usage, +// used by SSL 2.0 and RSA key exchange. Do not use this. +#define X509_PURPOSE_NS_SSL_SERVER 3 +// X509_PURPOSE_SMIME_SIGN validates S/MIME signing certificates. It checks for +// the id-kp-emailProtection EKU and one of digitalSignature or nonRepudiation +// key usages. +#define X509_PURPOSE_SMIME_SIGN 4 +// X509_PURPOSE_SMIME_ENCRYPT validates S/MIME encryption certificates. It +// checks for the id-kp-emailProtection EKU and keyEncipherment key usage. +#define X509_PURPOSE_SMIME_ENCRYPT 5 +// X509_PURPOSE_CRL_SIGN validates indirect CRL signers. It checks for the +// cRLSign key usage. BoringSSL does not support indirect CRLs and does not use +// this mode. +#define X509_PURPOSE_CRL_SIGN 6 +// X509_PURPOSE_ANY performs no EKU or key usage checks. Such checks are the +// responsibility of the caller. +#define X509_PURPOSE_ANY 7 +// X509_PURPOSE_OCSP_HELPER performs no EKU or key usage checks. It was +// historically used in OpenSSL's OCSP implementation, which left those checks +// to the OCSP implementation itself. +#define X509_PURPOSE_OCSP_HELPER 8 +// X509_PURPOSE_TIMESTAMP_SIGN validates Time Stamping Authority (RFC 3161) +// certificates. It checks for the id-kp-timeStamping EKU and one of +// digitalSignature or nonRepudiation key usages. It additionally checks that +// the EKU extension is critical and that no other EKUs or key usages are +// asserted. +#define X509_PURPOSE_TIMESTAMP_SIGN 9 + +// X509_VERIFY_PARAM_set_purpose configures |param| to validate certificates for +// a specified purpose. It returns one on success and zero if |purpose| is not a +// valid purpose type. |purpose| should be one of the |X509_PURPOSE_*| values. +// +// This option controls checking the extended key usage (EKU) and key usage +// extensions. These extensions specify how a certificate's public key may be +// used and are important to avoid cross-protocol attacks, particularly in PKIs +// that may issue certificates for multiple protocols, or for protocols that use +// keys in multiple ways. If not configured, these security checks are the +// caller's responsibility. +// +// This library applies the EKU checks to all untrusted intermediates. Although +// not defined in RFC 5280, this matches widely-deployed practice. It also does +// not accept anyExtendedKeyUsage. +// +// Many purpose values have a corresponding trust value, which is not configured +// by this function. See |X509_VERIFY_PARAM_set_trust| for details. Callers +// that wish to configure both should either call both functions, or use +// |X509_STORE_CTX_set_purpose|. +// +// It is currently not possible to configure custom EKU OIDs or key usage bits. +// Contact the BoringSSL maintainers if your application needs to do so. OpenSSL +// had an |X509_PURPOSE_add| API, but it was not thread-safe and relied on +// global mutable state, so we removed it. +// +// TODO(davidben): This function additionally configures checking the legacy +// Netscape certificate type extension. Remove this. +OPENSSL_EXPORT int X509_VERIFY_PARAM_set_purpose(X509_VERIFY_PARAM *param, + int purpose); + +// X509_TRUST_COMPAT evaluates trust using only the self-signed fallback. Trust +// and distrust OIDs are ignored. +#define X509_TRUST_COMPAT 1 +// X509_TRUST_SSL_CLIENT evaluates trust with the |NID_client_auth| OID, for +// validating TLS client certificates. +#define X509_TRUST_SSL_CLIENT 2 +// X509_TRUST_SSL_SERVER evaluates trust with the |NID_server_auth| OID, for +// validating TLS server certificates. +#define X509_TRUST_SSL_SERVER 3 +// X509_TRUST_EMAIL evaluates trust with the |NID_email_protect| OID, for +// validating S/MIME email certificates. +#define X509_TRUST_EMAIL 4 +// X509_TRUST_OBJECT_SIGN evaluates trust with the |NID_code_sign| OID, for +// validating code signing certificates. +#define X509_TRUST_OBJECT_SIGN 5 +// X509_TRUST_TSA evaluates trust with the |NID_time_stamp| OID, for validating +// Time Stamping Authority (RFC 3161) certificates. +#define X509_TRUST_TSA 8 + +// X509_VERIFY_PARAM_set_trust configures which certificates from |X509_STORE| +// are trust anchors. It returns one on success and zero if |trust| is not a +// valid trust value. |trust| should be one of the |X509_TRUST_*| constants. +// This function allows applications to vary trust anchors when the same set of +// trusted certificates is used in multiple contexts. +// +// Two properties determine whether a certificate is a trust anchor: +// +// - Whether it is trusted or distrusted for some OID, via auxiliary information +// configured by |X509_add1_trust_object| or |X509_add1_reject_object|. +// +// - Whether it is "self-signed". That is, whether |X509_get_extension_flags| +// includes |EXFLAG_SS|. The signature itself is not checked. +// +// When this function is called, |trust| determines the OID to check in the +// first case. If the certificate is not explicitly trusted or distrusted for +// any OID, it is trusted if self-signed instead. +// +// If unset, the default behavior is to check for the |NID_anyExtendedKeyUsage| +// OID. If the certificate is not explicitly trusted or distrusted for this OID, +// it is trusted if self-signed instead. Note this slightly differs from the +// above. +// +// If the |X509_V_FLAG_PARTIAL_CHAIN| is set, every certificate from +// |X509_STORE| is a trust anchor, unless it was explicitly distrusted for the +// OID. +// +// It is currently not possible to configure custom trust OIDs. Contact the +// BoringSSL maintainers if your application needs to do so. OpenSSL had an +// |X509_TRUST_add| API, but it was not thread-safe and relied on global mutable +// state, so we removed it. +OPENSSL_EXPORT int X509_VERIFY_PARAM_set_trust(X509_VERIFY_PARAM *param, + int trust); + + +// Filesystem-based certificate stores. +// +// An |X509_STORE| may be configured to get its contents from the filesystem. +// This is done by adding |X509_LOOKUP| structures to the |X509_STORE| with +// |X509_STORE_add_lookup| and then configuring the |X509_LOOKUP| with paths. +// +// Most cases can use |X509_STORE_load_locations|, which configures the same +// thing but is simpler to use. + +// X509_STORE_load_locations configures |store| to load data from filepaths +// |file| and |dir|. It returns one on success and zero on error. Either of +// |file| or |dir| may be NULL, but at least one must be non-NULL. +// +// If |file| is non-NULL, it loads CRLs and trusted certificates in PEM format +// from the file at |file|, and them to |store|, as in |X509_load_cert_crl_file| +// with |X509_FILETYPE_PEM|. +// +// If |dir| is non-NULL, it configures |store| to load CRLs and trusted +// certificates from the directory at |dir| in PEM format, as in +// |X509_LOOKUP_add_dir| with |X509_FILETYPE_PEM|. +OPENSSL_EXPORT int X509_STORE_load_locations(X509_STORE *store, + const char *file, const char *dir); + +// X509_STORE_add_lookup returns an |X509_LOOKUP| associated with |store| with +// type |method|, or NULL on error. The result is owned by |store|, so callers +// are not expected to free it. This may be used with |X509_LOOKUP_add_dir| or +// |X509_LOOKUP_load_file|, depending on |method|, to configure |store|. +// +// A single |X509_LOOKUP| may be configured with multiple paths, and an +// |X509_STORE| only contains one |X509_LOOKUP| of each type, so there is no +// need to call this function multiple times for a single type. Calling it +// multiple times will return the previous |X509_LOOKUP| of that type. +OPENSSL_EXPORT X509_LOOKUP *X509_STORE_add_lookup( + X509_STORE *store, const X509_LOOKUP_METHOD *method); + +// X509_LOOKUP_hash_dir creates |X509_LOOKUP|s that may be used with +// |X509_LOOKUP_add_dir|. +OPENSSL_EXPORT const X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir(void); + +// X509_LOOKUP_file creates |X509_LOOKUP|s that may be used with +// |X509_LOOKUP_load_file|. +// +// Although this is modeled as an |X509_LOOKUP|, this function is redundant. It +// has the same effect as loading a certificate or CRL from the filesystem, in +// the caller's desired format, and then adding it with |X509_STORE_add_cert| +// and |X509_STORE_add_crl|. +OPENSSL_EXPORT const X509_LOOKUP_METHOD *X509_LOOKUP_file(void); + +// The following constants are used to specify the format of files in an +// |X509_LOOKUP|. +#define X509_FILETYPE_PEM 1 +#define X509_FILETYPE_ASN1 2 +#define X509_FILETYPE_DEFAULT 3 + +// X509_LOOKUP_load_file calls |X509_load_cert_crl_file|. |lookup| must have +// been constructed with |X509_LOOKUP_file|. +// +// If |type| is |X509_FILETYPE_DEFAULT|, it ignores |file| and instead uses some +// default system path with |X509_FILETYPE_PEM|. See also +// |X509_STORE_set_default_paths|. +OPENSSL_EXPORT int X509_LOOKUP_load_file(X509_LOOKUP *lookup, const char *file, + int type); + +// X509_LOOKUP_add_dir configures |lookup| to load CRLs and trusted certificates +// from the directories in |path|. It returns one on success and zero on error. +// |lookup| must have been constructed with |X509_LOOKUP_hash_dir|. +// +// WARNING: |path| is interpreted as a colon-separated (semicolon-separated on +// Windows) list of paths. It is not possible to configure a path containing the +// separator character. https://crbug.com/boringssl/691 tracks removing this +// behavior. +// +// |type| should be one of the |X509_FILETYPE_*| constants and determines the +// format of the files. If |type| is |X509_FILETYPE_DEFAULT|, |path| is ignored +// and some default system path is used with |X509_FILETYPE_PEM|. See also +// |X509_STORE_set_default_paths|. +// +// Trusted certificates should be named HASH.N and CRLs should be +// named HASH.rN. HASH is |X509_NAME_hash| of the certificate subject and CRL +// issuer, respectively, in hexadecimal. N is in decimal and counts hash +// collisions consecutively, starting from zero. For example, "002c0b4f.0" and +// "002c0b4f.r0". +// +// WARNING: Objects from |path| are loaded on demand, but cached in memory on +// the |X509_STORE|. If a CA is removed from the directory, existing +// |X509_STORE|s will continue to trust it. Cache entries are not evicted for +// the lifetime of the |X509_STORE|. +// +// WARNING: This mechanism is also not well-suited for CRL updates. +// |X509_STORE|s rely on this cache and never load the same CRL file twice. CRL +// updates must use a new file, with an incremented suffix, to be reflected in +// existing |X509_STORE|s. However, this means each CRL update will use +// additional storage and memory. Instead, configure inputs that vary per +// verification, such as CRLs, on each |X509_STORE_CTX| separately, using +// functions like |X509_STORE_CTX_set0_crl|. +OPENSSL_EXPORT int X509_LOOKUP_add_dir(X509_LOOKUP *lookup, const char *path, + int type); + +// X509_L_* are commands for |X509_LOOKUP_ctrl|. +#define X509_L_FILE_LOAD 1 +#define X509_L_ADD_DIR 2 + +// X509_LOOKUP_ctrl implements commands on |lookup|. |cmd| specifies the +// command. The other arguments specify the operation in a command-specific way. +// Use |X509_LOOKUP_load_file| or |X509_LOOKUP_add_dir| instead. +OPENSSL_EXPORT int X509_LOOKUP_ctrl(X509_LOOKUP *lookup, int cmd, + const char *argc, long argl, char **ret); + +// X509_load_cert_file loads trusted certificates from |file| and adds them to +// |lookup|'s |X509_STORE|. It returns one on success and zero on error. +// +// If |type| is |X509_FILETYPE_ASN1|, it loads a single DER-encoded certificate. +// If |type| is |X509_FILETYPE_PEM|, it loads a sequence of PEM-encoded +// certificates. |type| may not be |X509_FILETYPE_DEFAULT|. +OPENSSL_EXPORT int X509_load_cert_file(X509_LOOKUP *lookup, const char *file, + int type); + +// X509_load_crl_file loads CRLs from |file| and add them it to |lookup|'s +// |X509_STORE|. It returns one on success and zero on error. +// +// If |type| is |X509_FILETYPE_ASN1|, it loads a single DER-encoded CRL. If +// |type| is |X509_FILETYPE_PEM|, it loads a sequence of PEM-encoded CRLs. +// |type| may not be |X509_FILETYPE_DEFAULT|. +OPENSSL_EXPORT int X509_load_crl_file(X509_LOOKUP *lookup, const char *file, + int type); + +// X509_load_cert_crl_file loads CRLs and trusted certificates from |file| and +// adds them to |lookup|'s |X509_STORE|. It returns one on success and zero on +// error. +// +// If |type| is |X509_FILETYPE_ASN1|, it loads a single DER-encoded certificate. +// This function cannot be used to load a DER-encoded CRL. If |type| is +// |X509_FILETYPE_PEM|, it loads a sequence of PEM-encoded certificates and +// CRLs. |type| may not be |X509_FILETYPE_DEFAULT|. +OPENSSL_EXPORT int X509_load_cert_crl_file(X509_LOOKUP *lookup, + const char *file, int type); + +// X509_NAME_hash returns a hash of |name|, or zero on error. This is the new +// hash used by |X509_LOOKUP_add_dir|. +// +// This hash is specific to the |X509_LOOKUP_add_dir| filesystem format and is +// not suitable for general-purpose X.509 name processing. It is very short, so +// there will be hash collisions. It also depends on an OpenSSL-specific +// canonicalization process. +// +// TODO(https://crbug.com/boringssl/407): This should be const and thread-safe +// but currently is neither, notably if |name| was modified from its parsed +// value. +OPENSSL_EXPORT uint32_t X509_NAME_hash(X509_NAME *name); + +// X509_NAME_hash_old returns a hash of |name|, or zero on error. This is the +// legacy hash used by |X509_LOOKUP_add_dir|, which is still supported for +// compatibility. +// +// This hash is specific to the |X509_LOOKUP_add_dir| filesystem format and is +// not suitable for general-purpose X.509 name processing. It is very short, so +// there will be hash collisions. +// +// TODO(https://crbug.com/boringssl/407): This should be const and thread-safe +// but currently is neither, notably if |name| was modified from its parsed +// value. +OPENSSL_EXPORT uint32_t X509_NAME_hash_old(X509_NAME *name); + +// X509_STORE_set_default_paths configures |store| to read from some "default" +// filesystem paths. It returns one on success and zero on error. The filesystem +// paths are determined by a combination of hardcoded paths and the SSL_CERT_DIR +// and SSL_CERT_FILE environment variables. +// +// Using this function is not recommended. In OpenSSL, these defaults are +// determined by OpenSSL's install prefix. There is no corresponding concept for +// BoringSSL. Future versions of BoringSSL may change or remove this +// functionality. +OPENSSL_EXPORT int X509_STORE_set_default_paths(X509_STORE *store); + +// The following functions return filesystem paths used to determine the above +// "default" paths, when the corresponding environment variables are not set. +// +// Using these functions is not recommended. In OpenSSL, these defaults are +// determined by OpenSSL's install prefix. There is no corresponding concept for +// BoringSSL. Future versions of BoringSSL may change or remove this +// functionality. +OPENSSL_EXPORT const char *X509_get_default_cert_area(void); +OPENSSL_EXPORT const char *X509_get_default_cert_dir(void); +OPENSSL_EXPORT const char *X509_get_default_cert_file(void); +OPENSSL_EXPORT const char *X509_get_default_private_dir(void); + +// X509_get_default_cert_dir_env returns "SSL_CERT_DIR", an environment variable +// used to determine the above "default" paths. +OPENSSL_EXPORT const char *X509_get_default_cert_dir_env(void); + +// X509_get_default_cert_file_env returns "SSL_CERT_FILE", an environment +// variable used to determine the above "default" paths. +OPENSSL_EXPORT const char *X509_get_default_cert_file_env(void); + + // SignedPublicKeyAndChallenge structures. // // The SignedPublicKeyAndChallenge (SPKAC) is a legacy structure to request @@ -2527,42 +4137,42 @@ OPENSSL_EXPORT int X509_REQ_print_fp(FILE *fp, X509_REQ *req); // XN_FLAG_COMPAT prints with |X509_NAME_print|'s format and return value // convention. -#define XN_FLAG_COMPAT 0 +#define XN_FLAG_COMPAT 0ul // XN_FLAG_SEP_MASK determines the separators to use between attributes. -#define XN_FLAG_SEP_MASK (0xf << 16) +#define XN_FLAG_SEP_MASK (0xful << 16) // XN_FLAG_SEP_COMMA_PLUS separates RDNs with "," and attributes within an RDN // with "+", as in RFC 2253. -#define XN_FLAG_SEP_COMMA_PLUS (1 << 16) +#define XN_FLAG_SEP_COMMA_PLUS (1ul << 16) // XN_FLAG_SEP_CPLUS_SPC behaves like |XN_FLAG_SEP_COMMA_PLUS| but adds spaces // between the separators. -#define XN_FLAG_SEP_CPLUS_SPC (2 << 16) +#define XN_FLAG_SEP_CPLUS_SPC (2ul << 16) // XN_FLAG_SEP_SPLUS_SPC separates RDNs with "; " and attributes within an RDN // with " + ". -#define XN_FLAG_SEP_SPLUS_SPC (3 << 16) +#define XN_FLAG_SEP_SPLUS_SPC (3ul << 16) // XN_FLAG_SEP_MULTILINE prints each attribute on one line. -#define XN_FLAG_SEP_MULTILINE (4 << 16) +#define XN_FLAG_SEP_MULTILINE (4ul << 16) // XN_FLAG_DN_REV prints RDNs in reverse, from least significant to most // significant, as RFC 2253. -#define XN_FLAG_DN_REV (1 << 20) +#define XN_FLAG_DN_REV (1ul << 20) // XN_FLAG_FN_MASK determines how attribute types are displayed. -#define XN_FLAG_FN_MASK (0x3 << 21) +#define XN_FLAG_FN_MASK (0x3ul << 21) // XN_FLAG_FN_SN uses the attribute type's short name, when available. -#define XN_FLAG_FN_SN 0 +#define XN_FLAG_FN_SN 0ul // XN_FLAG_SPC_EQ wraps the "=" operator with spaces when printing attributes. -#define XN_FLAG_SPC_EQ (1 << 23) +#define XN_FLAG_SPC_EQ (1ul << 23) // XN_FLAG_DUMP_UNKNOWN_FIELDS causes unknown attribute types to be printed in // hex, as in RFC 2253. -#define XN_FLAG_DUMP_UNKNOWN_FIELDS (1 << 24) +#define XN_FLAG_DUMP_UNKNOWN_FIELDS (1ul << 24) // XN_FLAG_RFC2253 prints like RFC 2253. #define XN_FLAG_RFC2253 \ @@ -2857,18 +4467,36 @@ OPENSSL_EXPORT int X509_CRL_cmp(const X509_CRL *a, const X509_CRL *b); // X509_issuer_name_hash returns the hash of |x509|'s issuer name with // |X509_NAME_hash|. +// +// This hash is specific to the |X509_LOOKUP_add_dir| filesystem format and is +// not suitable for general-purpose X.509 name processing. It is very short, so +// there will be hash collisions. It also depends on an OpenSSL-specific +// canonicalization process. OPENSSL_EXPORT uint32_t X509_issuer_name_hash(X509 *x509); // X509_subject_name_hash returns the hash of |x509|'s subject name with // |X509_NAME_hash|. +// +// This hash is specific to the |X509_LOOKUP_add_dir| filesystem format and is +// not suitable for general-purpose X.509 name processing. It is very short, so +// there will be hash collisions. It also depends on an OpenSSL-specific +// canonicalization process. OPENSSL_EXPORT uint32_t X509_subject_name_hash(X509 *x509); -// X509_issuer_name_hash returns the hash of |x509|'s issuer name with +// X509_issuer_name_hash_old returns the hash of |x509|'s issuer name with // |X509_NAME_hash_old|. +// +// This hash is specific to the |X509_LOOKUP_add_dir| filesystem format and is +// not suitable for general-purpose X.509 name processing. It is very short, so +// there will be hash collisions. OPENSSL_EXPORT uint32_t X509_issuer_name_hash_old(X509 *x509); -// X509_usjbect_name_hash returns the hash of |x509|'s usjbect name with +// X509_subject_name_hash_old returns the hash of |x509|'s usjbect name with // |X509_NAME_hash_old|. +// +// This hash is specific to the |X509_LOOKUP_add_dir| filesystem format and is +// not suitable for general-purpose X.509 name processing. It is very short, so +// there will be hash collisions. OPENSSL_EXPORT uint32_t X509_subject_name_hash_old(X509 *x509); @@ -2891,6 +4519,10 @@ 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); +#define X509_STORE_CTX_set_app_data(ctx, data) \ + X509_STORE_CTX_set_ex_data(ctx, 0, data) +#define X509_STORE_CTX_get_app_data(ctx) X509_STORE_CTX_get_ex_data(ctx, 0) + // Hashing and signing ASN.1 structures. @@ -3084,6 +4716,68 @@ OPENSSL_EXPORT int X509_check_ip_asc(const X509 *x509, const char *ipasc, OPENSSL_EXPORT int X509_STORE_CTX_get1_issuer(X509 **out_issuer, X509_STORE_CTX *ctx, X509 *x509); +// X509_check_purpose performs checks if |x509|'s basic constraints, key usage, +// and extended key usage extensions for the specified purpose. |purpose| should +// be one of |X509_PURPOSE_*| constants. See |X509_VERIFY_PARAM_set_purpose| for +// details. It returns one if |x509|'s extensions are consistent with |purpose| +// and zero otherwise. If |ca| is non-zero, |x509| is checked as a CA +// certificate. Otherwise, it is checked as an end-entity certificate. +// +// If |purpose| is -1, this function performs no purpose checks, but it parses +// some extensions in |x509| and may return zero on syntax error. Historically, +// callers primarily used this function to trigger this parsing, but this is no +// longer necessary. Functions acting on |X509| will internally parse as needed. +OPENSSL_EXPORT int X509_check_purpose(X509 *x509, int purpose, int ca); + +#define X509_TRUST_TRUSTED 1 +#define X509_TRUST_REJECTED 2 +#define X509_TRUST_UNTRUSTED 3 + +// X509_check_trust checks if |x509| is a valid trust anchor for trust type +// |id|. See |X509_VERIFY_PARAM_set_trust| for details. It returns +// |X509_TRUST_TRUSTED| if |x509| is a trust anchor, |X509_TRUST_REJECTED| if it +// was distrusted, and |X509_TRUST_UNTRUSTED| otherwise. |id| should be one of +// the |X509_TRUST_*| constants, or zero to indicate the default behavior. +// |flags| should be zero and is ignored. +OPENSSL_EXPORT int X509_check_trust(X509 *x509, int id, int flags); + +// X509_STORE_CTX_get1_certs returns a newly-allocated stack containing all +// trusted certificates in |ctx|'s |X509_STORE| whose subject matches |name|, or +// NULL on error. The caller must release the result with |sk_X509_pop_free| and +// |X509_free| when done. +// +// TODO(crbug.com/boringssl/407): |name| should be const. +OPENSSL_EXPORT STACK_OF(X509) *X509_STORE_CTX_get1_certs(X509_STORE_CTX *ctx, + X509_NAME *name); + +// X509_STORE_CTX_get1_crls returns a newly-allocated stack containing all +// CRLs in |ctx|'s |X509_STORE| whose subject matches |name|, or NULL on error. +// The caller must release the result with |sk_X509_CRL_pop_free| and +// |X509_CRL_free| when done. +// +// TODO(crbug.com/boringssl/407): |name| should be const. +OPENSSL_EXPORT STACK_OF(X509_CRL) *X509_STORE_CTX_get1_crls(X509_STORE_CTX *ctx, + X509_NAME *name); + +// X509_STORE_CTX_get_by_subject looks up an object of type |type| in |ctx|'s +// |X509_STORE| that matches |name|. |type| should be one of the |X509_LU_*| +// constants to indicate the type of object. If a match was found, it stores the +// result in |ret| and returns one. Otherwise, it returns zero. If multiple +// objects match, this function outputs an arbitray one. +// +// WARNING: |ret| must be in the empty state, as returned by |X509_OBJECT_new|. +// Otherwise, the object currently in |ret| will be leaked when overwritten. +// https://crbug.com/boringssl/685 tracks fixing this. +// +// WARNING: Multiple trusted certificates or CRLs may share a name. In this +// case, this function returns an arbitrary match. Use +// |X509_STORE_CTX_get1_certs| or |X509_STORE_CTX_get1_crls| instead. +// +// TODO(crbug.com/boringssl/407): |name| should be const. +OPENSSL_EXPORT int X509_STORE_CTX_get_by_subject(X509_STORE_CTX *ctx, int type, + X509_NAME *name, + X509_OBJECT *ret); + // X.509 information. // @@ -3111,6 +4805,120 @@ DEFINE_STACK_OF(X509_INFO) OPENSSL_EXPORT void X509_INFO_free(X509_INFO *info); +// Deprecated custom extension registration. +// +// The following functions allow callers to register custom extensions for use +// with |X509V3_EXT_d2i| and related functions. This mechanism is deprecated and +// will be removed in the future. As discussed in |X509V3_EXT_add|, it is not +// possible to safely register a custom extension without risking race +// conditions and memory errors when linked with other users of BoringSSL. +// +// Moreover, it is not necessary to register a custom extension to process +// extensions unknown to BoringSSL. Registration does not impact certificate +// verification. Caller should instead use functions such as +// |ASN1_OBJECT_create|, |X509_get_ext_by_OBJ|, |X509_EXTENSION_get_data|, and +// |X509_EXTENSION_create_by_OBJ| to inspect or create extensions directly. + +// The following function pointer types are used in |X509V3_EXT_METHOD|. +typedef void *(*X509V3_EXT_NEW)(void); +typedef void (*X509V3_EXT_FREE)(void *ext); +typedef void *(*X509V3_EXT_D2I)(void *ext, const uint8_t **inp, long len); +typedef int (*X509V3_EXT_I2D)(void *ext, uint8_t **outp); +typedef STACK_OF(CONF_VALUE) *(*X509V3_EXT_I2V)(const X509V3_EXT_METHOD *method, + void *ext, + STACK_OF(CONF_VALUE) *extlist); +typedef void *(*X509V3_EXT_V2I)(const X509V3_EXT_METHOD *method, + const X509V3_CTX *ctx, + const STACK_OF(CONF_VALUE) *values); +typedef char *(*X509V3_EXT_I2S)(const X509V3_EXT_METHOD *method, void *ext); +typedef void *(*X509V3_EXT_S2I)(const X509V3_EXT_METHOD *method, + const X509V3_CTX *ctx, const char *str); +typedef int (*X509V3_EXT_I2R)(const X509V3_EXT_METHOD *method, void *ext, + BIO *out, int indent); +typedef void *(*X509V3_EXT_R2I)(const X509V3_EXT_METHOD *method, + const X509V3_CTX *ctx, const char *str); + +// A v3_ext_method, aka |X509V3_EXT_METHOD|, is a deprecated type which defines +// a custom extension. +struct v3_ext_method { + // ext_nid is the NID of the extension. + int ext_nid; + + // ext_flags is a combination of |X509V3_EXT_*| constants. + int ext_flags; + + // it determines how values of this extension are allocated, released, parsed, + // and marshalled. This must be non-NULL. + ASN1_ITEM_EXP *it; + + // The following functions are ignored in favor of |it|. They are retained in + // the struct only for source compatibility with existing struct definitions. + X509V3_EXT_NEW ext_new; + X509V3_EXT_FREE ext_free; + X509V3_EXT_D2I d2i; + X509V3_EXT_I2D i2d; + + // The following functions are used for string extensions. + X509V3_EXT_I2S i2s; + X509V3_EXT_S2I s2i; + + // The following functions are used for multi-valued extensions. + X509V3_EXT_I2V i2v; + X509V3_EXT_V2I v2i; + + // The following functions are used for "raw" extensions, which implement + // custom printing behavior. + X509V3_EXT_I2R i2r; + X509V3_EXT_R2I r2i; + + void *usr_data; // Any extension specific data +} /* X509V3_EXT_METHOD */; + +// X509V3_EXT_MULTILINE causes the result of an |X509V3_EXT_METHOD|'s |i2v| +// function to be printed on separate lines, rather than separated by commas. +#define X509V3_EXT_MULTILINE 0x4 + +// X509V3_EXT_get returns the |X509V3_EXT_METHOD| corresponding to |ext|'s +// extension type, or NULL if none was registered. +OPENSSL_EXPORT const X509V3_EXT_METHOD *X509V3_EXT_get( + const X509_EXTENSION *ext); + +// X509V3_EXT_get_nid returns the |X509V3_EXT_METHOD| corresponding to |nid|, or +// NULL if none was registered. +OPENSSL_EXPORT const X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid); + +// X509V3_EXT_add registers |ext| as a custom extension for the extension type +// |ext->ext_nid|. |ext| must be valid for the remainder of the address space's +// lifetime. It returns one on success and zero on error. +// +// WARNING: This function modifies global state. If other code in the same +// address space also registers an extension with type |ext->ext_nid|, the two +// registrations will conflict. Which registration takes effect is undefined. If +// the two registrations use incompatible in-memory representations, code +// expecting the other registration will then cast a type to the wrong type, +// resulting in a potentially exploitable memory error. This conflict can also +// occur if BoringSSL later adds support for |ext->ext_nid|, with a different +// in-memory representation than the one expected by |ext|. +// +// This function, additionally, is not thread-safe and cannot be called +// concurrently with any other BoringSSL function. +// +// As a result, it is impossible to safely use this function. Registering a +// custom extension has no impact on certificate verification so, instead, +// callers should simply handle the custom extension with the byte-based +// |X509_EXTENSION| APIs directly. Registering |ext| with the library has little +// practical value. +OPENSSL_EXPORT OPENSSL_DEPRECATED int X509V3_EXT_add(X509V3_EXT_METHOD *ext); + +// X509V3_EXT_add_alias registers a custom extension with NID |nid_to|. The +// corresponding ASN.1 type is copied from |nid_from|. It returns one on success +// and zero on error. +// +// WARNING: Do not use this function. See |X509V3_EXT_add|. +OPENSSL_EXPORT OPENSSL_DEPRECATED int X509V3_EXT_add_alias(int nid_to, + int nid_from); + + // Deprecated config-based extension creation. // // The following functions allow specifying X.509 extensions using OpenSSL's @@ -3394,7 +5202,7 @@ OPENSSL_EXPORT int X509_NAME_get_text_by_NID(const X509_NAME *name, int nid, // X509_STORE_CTX_get0_parent_ctx returns NULL. OPENSSL_EXPORT X509_STORE_CTX *X509_STORE_CTX_get0_parent_ctx( - X509_STORE_CTX *ctx); + const X509_STORE_CTX *ctx); // X509_OBJECT_free_contents sets |obj| to the empty object, freeing any values // that were previously there. @@ -3427,479 +5235,16 @@ OPENSSL_EXPORT int X509V3_add_standard_extensions(void); #define X509_STORE_get1_certs X509_STORE_CTX_get1_certs #define X509_STORE_get1_crls X509_STORE_CTX_get1_crls - -// 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. - -// This stuff is certificate "auxiliary info" -// it contains details which are useful in certificate -// stores and databases. When used this is tagged onto -// the end of the certificate itself - -DECLARE_STACK_OF(DIST_POINT) - -// This is used for a table of trust checking functions - -struct x509_trust_st { - int trust; - int flags; - int (*check_trust)(const X509_TRUST *, X509 *, int); - char *name; - int arg1; - void *arg2; -} /* X509_TRUST */; - -DEFINE_STACK_OF(X509_TRUST) - -// standard trust ids - -#define X509_TRUST_DEFAULT (-1) // Only valid in purpose settings - -#define X509_TRUST_COMPAT 1 -#define X509_TRUST_SSL_CLIENT 2 -#define X509_TRUST_SSL_SERVER 3 -#define X509_TRUST_EMAIL 4 -#define X509_TRUST_OBJECT_SIGN 5 -#define X509_TRUST_OCSP_SIGN 6 -#define X509_TRUST_OCSP_REQUEST 7 -#define X509_TRUST_TSA 8 - -// Keep these up to date! -#define X509_TRUST_MIN 1 -#define X509_TRUST_MAX 8 - -// check_trust return codes - -#define X509_TRUST_TRUSTED 1 -#define X509_TRUST_REJECTED 2 -#define X509_TRUST_UNTRUSTED 3 - -// 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. -OPENSSL_EXPORT const char *X509_verify_cert_error_string(long err); - -OPENSSL_EXPORT const char *X509_get_default_cert_area(void); -OPENSSL_EXPORT const char *X509_get_default_cert_dir(void); -OPENSSL_EXPORT const char *X509_get_default_cert_file(void); -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); - - -OPENSSL_EXPORT int X509_TRUST_set(int *t, int trust); - -OPENSSL_EXPORT int X509_cmp(const X509 *a, const X509 *b); - -// X509_NAME_hash returns a hash of |name|, or zero on error. This is the new -// hash used by |X509_LOOKUP_hash_dir|. -// -// TODO(https://crbug.com/boringssl/407): This should be const and thread-safe -// but currently is neither, notably if |name| was modified from its parsed -// value. -OPENSSL_EXPORT uint32_t X509_NAME_hash(X509_NAME *name); - -// X509_NAME_hash_old returns a hash of |name|, or zero on error. This is the -// legacy hash used by |X509_LOOKUP_hash_dir|, which is still supported for -// compatibility. -// -// TODO(https://crbug.com/boringssl/407): This should be const and thread-safe -// but currently is neither, notably if |name| was modified from its parsed -// value. -OPENSSL_EXPORT uint32_t X509_NAME_hash_old(X509_NAME *name); - -OPENSSL_EXPORT int X509_CRL_match(const X509_CRL *a, const X509_CRL *b); - -OPENSSL_EXPORT int X509_verify_cert(X509_STORE_CTX *ctx); - -OPENSSL_EXPORT int X509_check_trust(X509 *x, int id, int flags); -OPENSSL_EXPORT int X509_TRUST_get_count(void); -OPENSSL_EXPORT const X509_TRUST *X509_TRUST_get0(int idx); -OPENSSL_EXPORT int X509_TRUST_get_by_id(int id); -OPENSSL_EXPORT int X509_TRUST_get_flags(const X509_TRUST *xp); -OPENSSL_EXPORT char *X509_TRUST_get0_name(const X509_TRUST *xp); -OPENSSL_EXPORT int X509_TRUST_get_trust(const X509_TRUST *xp); - - -/* -SSL_CTX -> X509_STORE - -> X509_LOOKUP - ->X509_LOOKUP_METHOD - -> X509_LOOKUP - ->X509_LOOKUP_METHOD - -SSL -> X509_STORE_CTX - ->X509_STORE - -The X509_STORE holds the tables etc for verification stuff. -A X509_STORE_CTX is used while validating a single certificate. -The X509_STORE has X509_LOOKUPs for looking up certs. -The X509_STORE then calls a function to actually verify the -certificate chain. -*/ - -#define X509_LU_NONE 0 -#define X509_LU_X509 1 -#define X509_LU_CRL 2 -#define X509_LU_PKEY 3 - -DEFINE_STACK_OF(X509_OBJECT) - -typedef int (*X509_STORE_CTX_verify_cb)(int, X509_STORE_CTX *); -typedef int (*X509_STORE_CTX_get_crl_fn)(X509_STORE_CTX *ctx, X509_CRL **crl, - X509 *x); -typedef int (*X509_STORE_CTX_check_crl_fn)(X509_STORE_CTX *ctx, X509_CRL *crl); - -// X509_STORE_set_depth configures |store| to, by default, limit certificate -// chains to |depth| intermediate certificates. This count excludes both the -// target certificate and the trust anchor (root certificate). -OPENSSL_EXPORT int X509_STORE_set_depth(X509_STORE *store, int depth); - -// X509_STORE_CTX_set_depth configures |ctx| to, by default, limit certificate -// chains to |depth| intermediate certificates. This count excludes both the -// target certificate and the trust anchor (root certificate). -OPENSSL_EXPORT void X509_STORE_CTX_set_depth(X509_STORE_CTX *ctx, int depth); - -#define X509_STORE_CTX_set_app_data(ctx, data) \ - X509_STORE_CTX_set_ex_data(ctx, 0, data) -#define X509_STORE_CTX_get_app_data(ctx) X509_STORE_CTX_get_ex_data(ctx, 0) - -#define X509_L_FILE_LOAD 1 -#define X509_L_ADD_DIR 2 - -// The following constants are used to specify the format of files in an -// |X509_LOOKUP|. -#define X509_FILETYPE_PEM 1 -#define X509_FILETYPE_ASN1 2 -#define X509_FILETYPE_DEFAULT 3 - -// X509_LOOKUP_load_file configures |lookup| to load information from the file -// at |path|. It returns one on success and zero on error. |type| should be one -// of the |X509_FILETYPE_*| constants to determine if the contents are PEM or -// DER. If |type| is |X509_FILETYPE_DEFAULT|, |path| is ignored and instead some -// default system path is used. -OPENSSL_EXPORT int X509_LOOKUP_load_file(X509_LOOKUP *lookup, const char *path, - int type); - -// X509_LOOKUP_add_dir configures |lookup| to load information from the -// directory at |path|. It returns one on success and zero on error. |type| -// should be one of the |X509_FILETYPE_*| constants to determine if the contents -// are PEM or DER. If |type| is |X509_FILETYPE_DEFAULT|, |path| is ignored and -// instead some default system path is used. -OPENSSL_EXPORT int X509_LOOKUP_add_dir(X509_LOOKUP *lookup, const char *path, - int type); - -#define X509_V_OK 0 -#define X509_V_ERR_UNSPECIFIED 1 - -#define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT 2 -#define X509_V_ERR_UNABLE_TO_GET_CRL 3 -#define X509_V_ERR_UNABLE_TO_DECRYPT_CERT_SIGNATURE 4 -#define X509_V_ERR_UNABLE_TO_DECRYPT_CRL_SIGNATURE 5 -#define X509_V_ERR_UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY 6 -#define X509_V_ERR_CERT_SIGNATURE_FAILURE 7 -#define X509_V_ERR_CRL_SIGNATURE_FAILURE 8 -#define X509_V_ERR_CERT_NOT_YET_VALID 9 -#define X509_V_ERR_CERT_HAS_EXPIRED 10 -#define X509_V_ERR_CRL_NOT_YET_VALID 11 -#define X509_V_ERR_CRL_HAS_EXPIRED 12 -#define X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD 13 -#define X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD 14 -#define X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD 15 -#define X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD 16 -#define X509_V_ERR_OUT_OF_MEM 17 -#define X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT 18 -#define X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN 19 -#define X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY 20 -#define X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE 21 -#define X509_V_ERR_CERT_CHAIN_TOO_LONG 22 -#define X509_V_ERR_CERT_REVOKED 23 -#define X509_V_ERR_INVALID_CA 24 -#define X509_V_ERR_PATH_LENGTH_EXCEEDED 25 -#define X509_V_ERR_INVALID_PURPOSE 26 -#define X509_V_ERR_CERT_UNTRUSTED 27 -#define X509_V_ERR_CERT_REJECTED 28 -// These are 'informational' when looking for issuer cert -#define X509_V_ERR_SUBJECT_ISSUER_MISMATCH 29 -#define X509_V_ERR_AKID_SKID_MISMATCH 30 -#define X509_V_ERR_AKID_ISSUER_SERIAL_MISMATCH 31 -#define X509_V_ERR_KEYUSAGE_NO_CERTSIGN 32 - -#define X509_V_ERR_UNABLE_TO_GET_CRL_ISSUER 33 -#define X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION 34 -#define X509_V_ERR_KEYUSAGE_NO_CRL_SIGN 35 -#define X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION 36 -#define X509_V_ERR_INVALID_NON_CA 37 -#define X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED 38 -#define X509_V_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE 39 -#define X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED 40 - -#define X509_V_ERR_INVALID_EXTENSION 41 -#define X509_V_ERR_INVALID_POLICY_EXTENSION 42 -#define X509_V_ERR_NO_EXPLICIT_POLICY 43 -#define X509_V_ERR_DIFFERENT_CRL_SCOPE 44 -#define X509_V_ERR_UNSUPPORTED_EXTENSION_FEATURE 45 - -#define X509_V_ERR_UNNESTED_RESOURCE 46 - -#define X509_V_ERR_PERMITTED_VIOLATION 47 -#define X509_V_ERR_EXCLUDED_VIOLATION 48 -#define X509_V_ERR_SUBTREE_MINMAX 49 -#define X509_V_ERR_APPLICATION_VERIFICATION 50 -#define X509_V_ERR_UNSUPPORTED_CONSTRAINT_TYPE 51 -#define X509_V_ERR_UNSUPPORTED_CONSTRAINT_SYNTAX 52 -#define X509_V_ERR_UNSUPPORTED_NAME_SYNTAX 53 -#define X509_V_ERR_CRL_PATH_VALIDATION_ERROR 54 - -// Host, email and IP check errors -#define X509_V_ERR_HOSTNAME_MISMATCH 62 -#define X509_V_ERR_EMAIL_MISMATCH 63 -#define X509_V_ERR_IP_ADDRESS_MISMATCH 64 - -// Caller error -#define X509_V_ERR_INVALID_CALL 65 -// Issuer lookup error -#define X509_V_ERR_STORE_LOOKUP 66 - -#define X509_V_ERR_NAME_CONSTRAINTS_WITHOUT_SANS 67 - -// Certificate verify flags - -// Send issuer+subject checks to verify_cb -#define X509_V_FLAG_CB_ISSUER_CHECK 0x1 -// Use check time instead of current time -#define X509_V_FLAG_USE_CHECK_TIME 0x2 -// Lookup CRLs -#define X509_V_FLAG_CRL_CHECK 0x4 -// Lookup CRLs for whole chain -#define X509_V_FLAG_CRL_CHECK_ALL 0x8 -// Ignore unhandled critical extensions -#define X509_V_FLAG_IGNORE_CRITICAL 0x10 -// Does nothing as its functionality has been enabled by default. -#define X509_V_FLAG_X509_STRICT 0x00 -// This flag does nothing as proxy certificate support has been removed. -#define X509_V_FLAG_ALLOW_PROXY_CERTS 0x40 -// Does nothing as its functionality has been enabled by default. -#define X509_V_FLAG_POLICY_CHECK 0x80 -// Policy variable require-explicit-policy -#define X509_V_FLAG_EXPLICIT_POLICY 0x100 -// Policy variable inhibit-any-policy -#define X509_V_FLAG_INHIBIT_ANY 0x200 -// Policy variable inhibit-policy-mapping -#define X509_V_FLAG_INHIBIT_MAP 0x400 -// Does nothing -#define X509_V_FLAG_NOTIFY_POLICY 0x800 -// Causes all verifications to fail. Extended CRL features have been removed. -#define X509_V_FLAG_EXTENDED_CRL_SUPPORT 0x1000 -// Causes all verifications to fail. Delta CRL support has been removed. -#define X509_V_FLAG_USE_DELTAS 0x2000 -// Check selfsigned CA signature -#define X509_V_FLAG_CHECK_SS_SIGNATURE 0x4000 -// Use trusted store first -#define X509_V_FLAG_TRUSTED_FIRST 0x8000 - -// Allow partial chains if at least one certificate is in trusted store -#define X509_V_FLAG_PARTIAL_CHAIN 0x80000 - -// If the initial chain is not trusted, do not attempt to build an alternative -// chain. Alternate chain checking was introduced in 1.0.2b. Setting this flag -// will force the behaviour to match that of previous versions. -#define X509_V_FLAG_NO_ALT_CHAINS 0x100000 - -// X509_V_FLAG_NO_CHECK_TIME disables all time checks in certificate -// verification. -#define X509_V_FLAG_NO_CHECK_TIME 0x200000 - -// X509_OBJECT_new returns a newly-allocated, empty |X509_OBJECT| or NULL on -// error. -OPENSSL_EXPORT X509_OBJECT *X509_OBJECT_new(void); - -// X509_OBJECT_free releases memory associated with |obj|. -OPENSSL_EXPORT void X509_OBJECT_free(X509_OBJECT *obj); - -// X509_OBJECT_get_type returns the type of |obj|, which will be one of the -// |X509_LU_*| constants. -OPENSSL_EXPORT int X509_OBJECT_get_type(const X509_OBJECT *obj); - -// X509_OBJECT_get0_X509 returns |obj| as a certificate, or NULL if |obj| is not -// a certificate. -OPENSSL_EXPORT X509 *X509_OBJECT_get0_X509(const X509_OBJECT *obj); - -// X509_STORE_new returns a newly-allocated |X509_STORE|, or NULL on error. -OPENSSL_EXPORT X509_STORE *X509_STORE_new(void); - -// X509_STORE_up_ref adds one to the reference count of |store| and returns one. -OPENSSL_EXPORT int X509_STORE_up_ref(X509_STORE *store); - -// X509_STORE_free releases memory associated with |store|. -OPENSSL_EXPORT void X509_STORE_free(X509_STORE *store); - -OPENSSL_EXPORT STACK_OF(X509_OBJECT) *X509_STORE_get0_objects(X509_STORE *st); -OPENSSL_EXPORT STACK_OF(X509) *X509_STORE_CTX_get1_certs(X509_STORE_CTX *st, - X509_NAME *nm); -OPENSSL_EXPORT STACK_OF(X509_CRL) *X509_STORE_CTX_get1_crls(X509_STORE_CTX *st, - X509_NAME *nm); - -// X509_STORE_set_flags enables all values in |flags| in |store|'s verification -// flags. -// -// WARNING: These flags will be combined with default flags when copied to an -// |X509_STORE_CTX|. This means it is impossible to unset those defaults from -// the |X509_STORE|. See discussion in |X509_STORE_get0_param|. -OPENSSL_EXPORT int X509_STORE_set_flags(X509_STORE *store, unsigned long flags); - -OPENSSL_EXPORT int X509_STORE_set_purpose(X509_STORE *store, int purpose); -OPENSSL_EXPORT int X509_STORE_set_trust(X509_STORE *store, int trust); - -// |X509_STORE_set1_param| copies verification parameters from |param| as in -// |X509_VERIFY_PARAM_set1|. It returns one on success and zero on error. -OPENSSL_EXPORT int X509_STORE_set1_param(X509_STORE *store, - const X509_VERIFY_PARAM *param); - -// X509_STORE_get0_param returns |store|'s verification parameters. This object -// is mutable and may be modified by the caller. For an individual certificate -// verification operation, |X509_STORE_CTX_init| initializes the -// |X509_STORE_CTX|'s parameters with these parameters. -// -// WARNING: |X509_STORE_CTX_init| applies some default parameters (as in -// |X509_VERIFY_PARAM_inherit|) after copying |store|'s parameters. This means -// it is impossible to leave some parameters unset at |store|. They must be -// explicitly unset after creating the |X509_STORE_CTX|. -// -// As of writing these late defaults are a depth limit (see -// |X509_VERIFY_PARAM_set_depth|) and the |X509_V_FLAG_TRUSTED_FIRST| flag. This -// warning does not apply if the parameters were set in |store|. -// -// TODO(crbug.com/boringssl/441): This behavior is very surprising. Can we -// remove this notion of late defaults? The unsettable value at |X509_STORE| is -// -1, which rejects everything but explicitly-trusted self-signed certificates. -// |X509_V_FLAG_TRUSTED_FIRST| is mostly a workaround for poor path-building. -OPENSSL_EXPORT X509_VERIFY_PARAM *X509_STORE_get0_param(X509_STORE *store); - -// X509_STORE_set_verify_cb acts like |X509_STORE_CTX_set_verify_cb| but sets -// the verify callback for any |X509_STORE_CTX| created from this |X509_STORE| -// -// Do not use this funciton. see |X509_STORE_CTX_set_verify_cb|. -OPENSSL_EXPORT void X509_STORE_set_verify_cb( - X509_STORE *ctx, X509_STORE_CTX_verify_cb verify_cb); -#define X509_STORE_set_verify_cb_func(ctx, func) \ - X509_STORE_set_verify_cb((ctx), (func)) -OPENSSL_EXPORT void X509_STORE_set_get_crl(X509_STORE *ctx, - X509_STORE_CTX_get_crl_fn get_crl); -OPENSSL_EXPORT void X509_STORE_set_check_crl( - X509_STORE *ctx, X509_STORE_CTX_check_crl_fn check_crl); - -// X509_STORE_CTX_new returns a newly-allocated, empty |X509_STORE_CTX|, or NULL -// on error. -OPENSSL_EXPORT X509_STORE_CTX *X509_STORE_CTX_new(void); - -// X509_STORE_CTX_free releases memory associated with |ctx|. -OPENSSL_EXPORT void X509_STORE_CTX_free(X509_STORE_CTX *ctx); - -// X509_STORE_CTX_init initializes |ctx| to verify |x509|, using trusted -// certificates and parameters in |store|. It returns one on success and zero on -// error. |chain| is a list of untrusted intermediate certificates to use in -// verification. -// -// |ctx| stores pointers to |store|, |x509|, and |chain|. Each of these objects -// must outlive |ctx| and may not be mutated for the duration of the certificate -// verification. -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|. Calling this -// function causes |ctx| to ignore any certificates configured in the -// |X509_STORE|. -// -// 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_get_chain is a legacy alias for |X509_STORE_CTX_get0_chain|. +OPENSSL_EXPORT STACK_OF(X509) *X509_STORE_CTX_get_chain( + const X509_STORE_CTX *ctx); // 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); -// X509_STORE_CTX_get0_store returns the |X509_STORE| that |ctx| uses. -OPENSSL_EXPORT X509_STORE *X509_STORE_CTX_get0_store(X509_STORE_CTX *ctx); - -// X509_STORE_CTX_get0_cert returns the leaf certificate that |ctx| is -// verifying. -OPENSSL_EXPORT X509 *X509_STORE_CTX_get0_cert(X509_STORE_CTX *ctx); - -OPENSSL_EXPORT X509_LOOKUP *X509_STORE_add_lookup(X509_STORE *v, - const X509_LOOKUP_METHOD *m); - -OPENSSL_EXPORT const X509_LOOKUP_METHOD *X509_LOOKUP_hash_dir(void); -OPENSSL_EXPORT const X509_LOOKUP_METHOD *X509_LOOKUP_file(void); - -OPENSSL_EXPORT int X509_STORE_add_cert(X509_STORE *ctx, X509 *x); -OPENSSL_EXPORT int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x); - -OPENSSL_EXPORT int X509_STORE_CTX_get_by_subject(X509_STORE_CTX *vs, int type, - X509_NAME *name, - X509_OBJECT *ret); - -OPENSSL_EXPORT int X509_LOOKUP_ctrl(X509_LOOKUP *ctx, int cmd, const char *argc, - long argl, char **ret); - -OPENSSL_EXPORT int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, - int type); -OPENSSL_EXPORT int X509_load_crl_file(X509_LOOKUP *ctx, const char *file, - int type); -OPENSSL_EXPORT int X509_load_cert_crl_file(X509_LOOKUP *ctx, const char *file, - int type); - -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); -OPENSSL_EXPORT int X509_STORE_CTX_get_error(X509_STORE_CTX *ctx); -OPENSSL_EXPORT void X509_STORE_CTX_set_error(X509_STORE_CTX *ctx, int s); -OPENSSL_EXPORT int X509_STORE_CTX_get_error_depth(X509_STORE_CTX *ctx); -OPENSSL_EXPORT X509 *X509_STORE_CTX_get_current_cert(X509_STORE_CTX *ctx); -OPENSSL_EXPORT X509_CRL *X509_STORE_CTX_get0_current_crl(X509_STORE_CTX *ctx); -OPENSSL_EXPORT STACK_OF(X509) *X509_STORE_CTX_get_chain(X509_STORE_CTX *ctx); -OPENSSL_EXPORT STACK_OF(X509) *X509_STORE_CTX_get0_chain(X509_STORE_CTX *ctx); -OPENSSL_EXPORT STACK_OF(X509) *X509_STORE_CTX_get1_chain(X509_STORE_CTX *ctx); -OPENSSL_EXPORT void X509_STORE_CTX_set_cert(X509_STORE_CTX *c, X509 *x); -OPENSSL_EXPORT void X509_STORE_CTX_set_chain(X509_STORE_CTX *c, - STACK_OF(X509) *sk); -OPENSSL_EXPORT STACK_OF(X509) *X509_STORE_CTX_get0_untrusted( - X509_STORE_CTX *ctx); -OPENSSL_EXPORT void X509_STORE_CTX_set0_crls(X509_STORE_CTX *c, - STACK_OF(X509_CRL) *sk); -OPENSSL_EXPORT int X509_STORE_CTX_set_purpose(X509_STORE_CTX *ctx, int purpose); -OPENSSL_EXPORT int X509_STORE_CTX_set_trust(X509_STORE_CTX *ctx, int trust); -OPENSSL_EXPORT int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, - int def_purpose, int purpose, - int trust); - -// X509_STORE_CTX_set_flags enables all values in |flags| in |ctx|'s -// verification flags. -OPENSSL_EXPORT void X509_STORE_CTX_set_flags(X509_STORE_CTX *ctx, - unsigned long flags); - -// X509_STORE_CTX_set_time configures certificate verification to use |t| -// instead of the current time. |flags| is ignored and should be zero. -OPENSSL_EXPORT void X509_STORE_CTX_set_time(X509_STORE_CTX *ctx, - unsigned long flags, time_t t); - -// X509_STORE_CTX_set_time_posix configures certificate verification to use |t| -// instead of the current time. |t| is interpreted as a POSIX timestamp in -// seconds. |flags| is ignored and should be zero. -OPENSSL_EXPORT void X509_STORE_CTX_set_time_posix(X509_STORE_CTX *ctx, - unsigned long flags, - int64_t t); +typedef int (*X509_STORE_CTX_verify_cb)(int, X509_STORE_CTX *); // X509_STORE_CTX_set_verify_cb configures a callback function for |ctx| that is // called multiple times during |X509_verify_cert|. The callback returns zero to @@ -3907,14 +5252,16 @@ OPENSSL_EXPORT void X509_STORE_CTX_set_time_posix(X509_STORE_CTX *ctx, // preserves the default behavior. Returning one when |ok| is zero will proceed // past some error. The callback may inspect |ctx| and the error queue to // attempt to determine the current stage of certificate verification, but this -// is often unreliable. +// is often unreliable. When synthesizing an error, callbacks should use +// |X509_STORE_CTX_set_error| to set a corresponding error. // // WARNING: Do not use this function. It is extremely fragile and unpredictable. // This callback exposes implementation details of certificate verification, // which change as the library evolves. Attempting to use it for security checks // can introduce vulnerabilities if making incorrect assumptions about when the -// callback is called. Additionally, overriding |ok| may leave |ctx| in an -// inconsistent state and break invariants. +// callback is called. Some errors, when suppressed, may implicitly suppress +// other errors due to internal implementation details. Additionally, overriding +// |ok| may leave |ctx| in an inconsistent state and break invariants. // // Instead, customize certificate verification by configuring options on the // |X509_STORE_CTX| before verification, or applying additional checks after @@ -3922,342 +5269,113 @@ OPENSSL_EXPORT void X509_STORE_CTX_set_time_posix(X509_STORE_CTX *ctx, OPENSSL_EXPORT void X509_STORE_CTX_set_verify_cb( X509_STORE_CTX *ctx, int (*verify_cb)(int ok, X509_STORE_CTX *ctx)); -// X509_STORE_CTX_get0_param returns |ctx|'s verification parameters. This -// object is mutable and may be modified by the caller. -OPENSSL_EXPORT X509_VERIFY_PARAM *X509_STORE_CTX_get0_param( - X509_STORE_CTX *ctx); - -// X509_STORE_CTX_set0_param returns |ctx|'s verification parameters to |param| -// and takes ownership of |param|. After this function returns, the caller -// should not free |param|. +// X509_STORE_set_verify_cb acts like |X509_STORE_CTX_set_verify_cb| but sets +// the verify callback for any |X509_STORE_CTX| created from this |X509_STORE| // -// WARNING: This function discards any values which were previously applied in -// |ctx|, including the "default" parameters applied late in -// |X509_STORE_CTX_init|. These late defaults are not applied to parameters -// created standalone by |X509_VERIFY_PARAM_new|. +// Do not use this function. See |X509_STORE_CTX_set_verify_cb| for details. +OPENSSL_EXPORT void X509_STORE_set_verify_cb( + X509_STORE *store, X509_STORE_CTX_verify_cb verify_cb); + +// X509_STORE_set_verify_cb_func is a deprecated alias for +// |X509_STORE_set_verify_cb|. +#define X509_STORE_set_verify_cb_func(store, func) \ + X509_STORE_set_verify_cb((store), (func)) + +typedef int (*X509_STORE_CTX_get_crl_fn)(X509_STORE_CTX *ctx, X509_CRL **crl, + X509 *x); +typedef int (*X509_STORE_CTX_check_crl_fn)(X509_STORE_CTX *ctx, X509_CRL *crl); + +// X509_STORE_set_get_crl override's |store|'s logic for looking up CRLs. // -// TODO(crbug.com/boringssl/441): This behavior is very surprising. Should we -// re-apply the late defaults in |param|, or somehow avoid this notion of late -// defaults altogether? -OPENSSL_EXPORT void X509_STORE_CTX_set0_param(X509_STORE_CTX *ctx, - X509_VERIFY_PARAM *param); +// Do not use this function. It is temporarily retained to support one caller +// and will be removed after that caller is fixed. It is not possible for +// external callers to correctly implement this callback. The real +// implementation sets some inaccessible internal state on |X509_STORE_CTX|. +OPENSSL_EXPORT void X509_STORE_set_get_crl(X509_STORE *store, + X509_STORE_CTX_get_crl_fn get_crl); -// X509_STORE_CTX_set_default looks up the set of parameters named |name| and -// applies those default verification parameters for |ctx|. As in -// |X509_VERIFY_PARAM_inherit|, only unset parameters are changed. This function -// returns one on success and zero on error. -OPENSSL_EXPORT int X509_STORE_CTX_set_default(X509_STORE_CTX *ctx, - const char *name); - -// X509_VERIFY_PARAM functions - -// X509_VERIFY_PARAM_new returns a newly-allocated |X509_VERIFY_PARAM|, or NULL -// on error. -OPENSSL_EXPORT X509_VERIFY_PARAM *X509_VERIFY_PARAM_new(void); - -// X509_VERIFY_PARAM_free releases memory associated with |param|. -OPENSSL_EXPORT void X509_VERIFY_PARAM_free(X509_VERIFY_PARAM *param); - -// X509_VERIFY_PARAM_inherit applies |from| as the default values for |to|. That -// is, for each parameter that is unset in |to|, it copies the value in |from|. -// This function returns one on success and zero on error. -OPENSSL_EXPORT int X509_VERIFY_PARAM_inherit(X509_VERIFY_PARAM *to, - const X509_VERIFY_PARAM *from); - -// X509_VERIFY_PARAM_set1 copies parameters from |from| to |to|. If a parameter -// is unset in |from|, the existing value in |to| is preserved. This function -// returns one on success and zero on error. -OPENSSL_EXPORT int X509_VERIFY_PARAM_set1(X509_VERIFY_PARAM *to, - const X509_VERIFY_PARAM *from); - -// X509_VERIFY_PARAM_set_flags enables all values in |flags| in |param|'s -// verification flags and returns one. |flags| should be a combination of -// |X509_V_FLAG_*| constants. -OPENSSL_EXPORT int X509_VERIFY_PARAM_set_flags(X509_VERIFY_PARAM *param, - unsigned long flags); - -// X509_VERIFY_PARAM_clear_flags disables all values in |flags| in |param|'s -// verification flags and returns one. |flags| should be a combination of -// |X509_V_FLAG_*| constants. -OPENSSL_EXPORT int X509_VERIFY_PARAM_clear_flags(X509_VERIFY_PARAM *param, - unsigned long flags); - -// X509_VERIFY_PARAM_get_flags returns |param|'s verification flags. -OPENSSL_EXPORT unsigned long X509_VERIFY_PARAM_get_flags( - const X509_VERIFY_PARAM *param); - -OPENSSL_EXPORT int X509_VERIFY_PARAM_set_purpose(X509_VERIFY_PARAM *param, - int purpose); -OPENSSL_EXPORT int X509_VERIFY_PARAM_set_trust(X509_VERIFY_PARAM *param, - int trust); - -// X509_VERIFY_PARAM_set_depth configures |param| to limit certificate chains to -// |depth| intermediate certificates. This count excludes both the target -// certificate and the trust anchor (root certificate). -OPENSSL_EXPORT void X509_VERIFY_PARAM_set_depth(X509_VERIFY_PARAM *param, - int depth); - -// X509_VERIFY_PARAM_set_time configures certificate verification to use |t| -// instead of the current time. -OPENSSL_EXPORT void X509_VERIFY_PARAM_set_time(X509_VERIFY_PARAM *param, - time_t t); - -// X509_VERIFY_PARAM_set_time_posix configures certificate verification to use -// |t| instead of the current time. |t| is interpreted as a POSIX timestamp in -// seconds. -OPENSSL_EXPORT void X509_VERIFY_PARAM_set_time_posix(X509_VERIFY_PARAM *param, - int64_t t); - -// X509_VERIFY_PARAM_add0_policy adds |policy| to the user-initial-policy-set -// (see Section 6.1.1 of RFC 5280). On success, it takes ownership of -// |policy| and returns one. Otherwise, it returns zero and the caller retains -// owneship of |policy|. -OPENSSL_EXPORT int X509_VERIFY_PARAM_add0_policy(X509_VERIFY_PARAM *param, - ASN1_OBJECT *policy); - -// X509_VERIFY_PARAM_set1_policies sets the user-initial-policy-set (see -// Section 6.1.1 of RFC 5280) to a copy of |policies|. It returns one on success -// and zero on error. -OPENSSL_EXPORT int X509_VERIFY_PARAM_set1_policies( - X509_VERIFY_PARAM *param, const STACK_OF(ASN1_OBJECT) *policies); - -// X509_VERIFY_PARAM_set1_host configures |param| to check for the DNS name -// specified by |name|. It returns one on success and zero on error. +// X509_STORE_set_check_crl override's |store|'s logic for checking CRL +// validity. // -// By default, both subject alternative names and the subject's common name -// attribute are checked. The latter has long been deprecated, so callers should -// call |X509_VERIFY_PARAM_set_hostflags| with -// |X509_CHECK_FLAG_NEVER_CHECK_SUBJECT| to use the standard behavior. -// https://crbug.com/boringssl/464 tracks fixing the default. -OPENSSL_EXPORT int X509_VERIFY_PARAM_set1_host(X509_VERIFY_PARAM *param, - const char *name, - size_t name_len); +// Do not use this function. It is temporarily retained to support one caller +// and will be removed after that caller is fixed. It is not possible for +// external callers to correctly implement this callback. The real +// implementation relies some inaccessible internal state on |X509_STORE_CTX|. +OPENSSL_EXPORT void X509_STORE_set_check_crl( + X509_STORE *store, X509_STORE_CTX_check_crl_fn check_crl); -// X509_VERIFY_PARAM_add1_host adds |name| to the list of names checked by -// |param|. If any configured DNS name matches the certificate, verification -// succeeds. It returns one on success and zero on error. +// X509_STORE_CTX_set_chain configures |ctx| to use |sk| for untrusted +// intermediate certificates to use in verification. This function is redundant +// with the |chain| parameter of |X509_STORE_CTX_init|. Use the parameter +// instead. // -// By default, both subject alternative names and the subject's common name -// attribute are checked. The latter has long been deprecated, so callers should -// call |X509_VERIFY_PARAM_set_hostflags| with -// |X509_CHECK_FLAG_NEVER_CHECK_SUBJECT| to use the standard behavior. -// https://crbug.com/boringssl/464 tracks fixing the default. -OPENSSL_EXPORT int X509_VERIFY_PARAM_add1_host(X509_VERIFY_PARAM *param, - const char *name, - size_t name_len); - -// X509_VERIFY_PARAM_set_hostflags sets the name-checking flags on |param| to -// |flags|. |flags| should be a combination of |X509_CHECK_FLAG_*| constants. -OPENSSL_EXPORT void X509_VERIFY_PARAM_set_hostflags(X509_VERIFY_PARAM *param, - unsigned int flags); - -// X509_VERIFY_PARAM_set1_email configures |param| to check for the email -// address specified by |email|. It returns one on success and zero on error. +// WARNING: Despite the similar name, this function is unrelated to +// |X509_STORE_CTX_get0_chain|. // -// By default, both subject alternative names and the subject's email address -// attribute are checked. The |X509_CHECK_FLAG_NEVER_CHECK_SUBJECT| flag may be -// used to change this behavior. -OPENSSL_EXPORT int X509_VERIFY_PARAM_set1_email(X509_VERIFY_PARAM *param, - const char *email, - size_t email_len); +// WARNING: This function saves a pointer to |sk| without copying or +// incrementing reference counts. |sk| must outlive |ctx| and may not be mutated +// for the duration of the certificate verification. +OPENSSL_EXPORT void X509_STORE_CTX_set_chain(X509_STORE_CTX *ctx, + STACK_OF(X509) *sk); -// X509_VERIFY_PARAM_set1_ip configures |param| to check for the IP address -// specified by |ip|. It returns one on success and zero on error. The IP -// address is specified in its binary representation. |ip_len| must be 4 for an -// IPv4 address and 16 for an IPv6 address. -OPENSSL_EXPORT int X509_VERIFY_PARAM_set1_ip(X509_VERIFY_PARAM *param, - const uint8_t *ip, size_t ip_len); +// The following flags do nothing. The corresponding non-standard options have +// been removed. +#define X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT 0 +#define X509_CHECK_FLAG_MULTI_LABEL_WILDCARDS 0 +#define X509_CHECK_FLAG_SINGLE_LABEL_SUBDOMAINS 0 -// X509_VERIFY_PARAM_set1_ip_asc decodes |ipasc| as the ASCII representation of -// an IPv4 or IPv6 address, and configures |param| to check for it. It returns -// one on success and zero on error. -OPENSSL_EXPORT int X509_VERIFY_PARAM_set1_ip_asc(X509_VERIFY_PARAM *param, - const char *ipasc); +// X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS does nothing, but is necessary in +// OpenSSL to enable standard wildcard matching. In BoringSSL, this behavior is +// always enabled. +#define X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS 0 -// X509_VERIFY_PARAM_get_depth returns the maximum depth configured in |param|. -// See |X509_VERIFY_PARAM_set_depth|. -OPENSSL_EXPORT int X509_VERIFY_PARAM_get_depth(const X509_VERIFY_PARAM *param); +// X509_STORE_get0_objects returns a non-owning pointer of |store|'s internal +// object list. Although this function is not const, callers must not modify +// the result of this function. +// +// WARNING: This function is not thread-safe. If |store| is shared across +// multiple threads, callers cannot safely inspect the result of this function, +// because another thread may have concurrently added to it. In particular, +// |X509_LOOKUP_add_dir| treats this list as a cache and may add to it in the +// course of certificate verification. This API additionally prevents fixing +// some quadratic worst-case behavior in |X509_STORE| and may be removed in the +// future. Use |X509_STORE_get1_objects| instead. +OPENSSL_EXPORT STACK_OF(X509_OBJECT) *X509_STORE_get0_objects( + X509_STORE *store); -typedef void *(*X509V3_EXT_NEW)(void); -typedef void (*X509V3_EXT_FREE)(void *); -typedef void *(*X509V3_EXT_D2I)(void *, const unsigned char **, long); -typedef int (*X509V3_EXT_I2D)(void *, unsigned char **); -typedef STACK_OF(CONF_VALUE) *(*X509V3_EXT_I2V)(const X509V3_EXT_METHOD *method, - void *ext, - STACK_OF(CONF_VALUE) *extlist); -typedef void *(*X509V3_EXT_V2I)(const X509V3_EXT_METHOD *method, - const X509V3_CTX *ctx, - const STACK_OF(CONF_VALUE) *values); -typedef char *(*X509V3_EXT_I2S)(const X509V3_EXT_METHOD *method, void *ext); -typedef void *(*X509V3_EXT_S2I)(const X509V3_EXT_METHOD *method, - const X509V3_CTX *ctx, const char *str); -typedef int (*X509V3_EXT_I2R)(const X509V3_EXT_METHOD *method, void *ext, - BIO *out, int indent); -typedef void *(*X509V3_EXT_R2I)(const X509V3_EXT_METHOD *method, - const X509V3_CTX *ctx, const char *str); +// X509_PURPOSE_get_by_sname returns the |X509_PURPOSE_*| constant corresponding +// a short name |sname|, or -1 if |sname| was not recognized. +// +// Use |X509_PURPOSE_*| constants directly instead. The short names used by this +// function look like "sslserver" or "smimeencrypt", so they do not make +// especially good APIs. +// +// This function differs from OpenSSL, which returns an "index" to be passed to +// |X509_PURPOSE_get0|, followed by |X509_PURPOSE_get_id|, to finally obtain an +// |X509_PURPOSE_*| value suitable for use with |X509_VERIFY_PARAM_set_purpose|. +OPENSSL_EXPORT int X509_PURPOSE_get_by_sname(const char *sname); -// V3 extension structure +// X509_PURPOSE_get0 returns the |X509_PURPOSE| object corresponding to |id|, +// which should be one of the |X509_PURPOSE_*| constants, or NULL if none +// exists. +// +// This function differs from OpenSSL, which takes an "index", returned from +// |X509_PURPOSE_get_by_sname|. In BoringSSL, indices and |X509_PURPOSE_*| IDs +// are the same. +OPENSSL_EXPORT const X509_PURPOSE *X509_PURPOSE_get0(int id); -struct v3_ext_method { - int ext_nid; - int ext_flags; - - // it determines how values of this extension are allocated, released, parsed, - // and marshalled. This must be non-NULL. - ASN1_ITEM_EXP *it; - - // The following functions are ignored in favor of |it|. They are retained in - // the struct only for source compatibility with existing struct definitions. - X509V3_EXT_NEW ext_new; - X509V3_EXT_FREE ext_free; - X509V3_EXT_D2I d2i; - X509V3_EXT_I2D i2d; - - // The following pair is used for string extensions - X509V3_EXT_I2S i2s; - X509V3_EXT_S2I s2i; - - // The following pair is used for multi-valued extensions - X509V3_EXT_I2V i2v; - X509V3_EXT_V2I v2i; - - // The following are used for raw extensions - X509V3_EXT_I2R i2r; - X509V3_EXT_R2I r2i; - - void *usr_data; // Any extension specific data -}; - -DEFINE_STACK_OF(X509V3_EXT_METHOD) - -// ext_flags values -#define X509V3_EXT_CTX_DEP 0x2 -#define X509V3_EXT_MULTILINE 0x4 - -struct BASIC_CONSTRAINTS_st { - int ca; - ASN1_INTEGER *pathlen; -}; - -typedef struct ACCESS_DESCRIPTION_st { - ASN1_OBJECT *method; - GENERAL_NAME *location; -} ACCESS_DESCRIPTION; - -DEFINE_STACK_OF(ACCESS_DESCRIPTION) - -typedef STACK_OF(ACCESS_DESCRIPTION) AUTHORITY_INFO_ACCESS; - -typedef STACK_OF(ASN1_OBJECT) EXTENDED_KEY_USAGE; - -typedef struct DIST_POINT_NAME_st { - int type; - union { - GENERAL_NAMES *fullname; - STACK_OF(X509_NAME_ENTRY) *relativename; - } name; - // If relativename then this contains the full distribution point name - X509_NAME *dpname; -} DIST_POINT_NAME; -// All existing reasons -#define CRLDP_ALL_REASONS 0x807f - -#define CRL_REASON_NONE (-1) -#define CRL_REASON_UNSPECIFIED 0 -#define CRL_REASON_KEY_COMPROMISE 1 -#define CRL_REASON_CA_COMPROMISE 2 -#define CRL_REASON_AFFILIATION_CHANGED 3 -#define CRL_REASON_SUPERSEDED 4 -#define CRL_REASON_CESSATION_OF_OPERATION 5 -#define CRL_REASON_CERTIFICATE_HOLD 6 -#define CRL_REASON_REMOVE_FROM_CRL 8 -#define CRL_REASON_PRIVILEGE_WITHDRAWN 9 -#define CRL_REASON_AA_COMPROMISE 10 - -struct DIST_POINT_st { - DIST_POINT_NAME *distpoint; - ASN1_BIT_STRING *reasons; - GENERAL_NAMES *CRLissuer; -}; - -typedef STACK_OF(DIST_POINT) CRL_DIST_POINTS; - -DEFINE_STACK_OF(DIST_POINT) - -struct AUTHORITY_KEYID_st { - ASN1_OCTET_STRING *keyid; - GENERAL_NAMES *issuer; - ASN1_INTEGER *serial; -}; - -typedef struct NOTICEREF_st { - ASN1_STRING *organization; - STACK_OF(ASN1_INTEGER) *noticenos; -} NOTICEREF; - -typedef struct USERNOTICE_st { - NOTICEREF *noticeref; - ASN1_STRING *exptext; -} USERNOTICE; - -typedef struct POLICYQUALINFO_st { - ASN1_OBJECT *pqualid; - union { - ASN1_IA5STRING *cpsuri; - USERNOTICE *usernotice; - ASN1_TYPE *other; - } d; -} POLICYQUALINFO; - -DEFINE_STACK_OF(POLICYQUALINFO) - -typedef struct POLICYINFO_st { - ASN1_OBJECT *policyid; - STACK_OF(POLICYQUALINFO) *qualifiers; -} POLICYINFO; - -typedef STACK_OF(POLICYINFO) CERTIFICATEPOLICIES; - -DEFINE_STACK_OF(POLICYINFO) - -typedef struct POLICY_MAPPING_st { - ASN1_OBJECT *issuerDomainPolicy; - ASN1_OBJECT *subjectDomainPolicy; -} POLICY_MAPPING; - -DEFINE_STACK_OF(POLICY_MAPPING) - -typedef STACK_OF(POLICY_MAPPING) POLICY_MAPPINGS; - -typedef struct GENERAL_SUBTREE_st { - GENERAL_NAME *base; - ASN1_INTEGER *minimum; - ASN1_INTEGER *maximum; -} GENERAL_SUBTREE; - -DEFINE_STACK_OF(GENERAL_SUBTREE) - -struct NAME_CONSTRAINTS_st { - STACK_OF(GENERAL_SUBTREE) *permittedSubtrees; - STACK_OF(GENERAL_SUBTREE) *excludedSubtrees; -}; - -typedef struct POLICY_CONSTRAINTS_st { - ASN1_INTEGER *requireExplicitPolicy; - ASN1_INTEGER *inhibitPolicyMapping; -} POLICY_CONSTRAINTS; - -struct ISSUING_DIST_POINT_st { - DIST_POINT_NAME *distpoint; - ASN1_BOOLEAN onlyuser; - ASN1_BOOLEAN onlyCA; - ASN1_BIT_STRING *onlysomereasons; - ASN1_BOOLEAN indirectCRL; - ASN1_BOOLEAN onlyattr; -}; - -// X509_PURPOSE stuff +// X509_PURPOSE_get_id returns |purpose|'s ID. This will be one of the +// |X509_PURPOSE_*| constants. +OPENSSL_EXPORT int X509_PURPOSE_get_id(const X509_PURPOSE *purpose); +// The following constants are values for the legacy Netscape certificate type +// X.509 extension, a precursor to extended key usage. These values correspond +// to the DER encoding of the first byte of the BIT STRING. That is, 0x80 is +// bit zero and 0x01 is bit seven. +// +// TODO(davidben): These constants are only used by OpenVPN, which deprecated +// the feature in 2017. The documentation says it was removed, but they did not +// actually remove it. See if OpenVPN will accept a patch to finish this. #define NS_SSL_CLIENT 0x80 #define NS_SSL_SERVER 0x40 #define NS_SMIME 0x20 @@ -4267,259 +5385,13 @@ struct ISSUING_DIST_POINT_st { #define NS_OBJSIGN_CA 0x01 #define NS_ANY_CA (NS_SSL_CA | NS_SMIME_CA | NS_OBJSIGN_CA) -typedef struct x509_purpose_st { - int purpose; - int trust; // Default trust ID - int flags; - int (*check_purpose)(const struct x509_purpose_st *, const X509 *, int); - char *name; - char *sname; - void *usr_data; -} X509_PURPOSE; -#define X509_PURPOSE_SSL_CLIENT 1 -#define X509_PURPOSE_SSL_SERVER 2 -#define X509_PURPOSE_NS_SSL_SERVER 3 -#define X509_PURPOSE_SMIME_SIGN 4 -#define X509_PURPOSE_SMIME_ENCRYPT 5 -#define X509_PURPOSE_CRL_SIGN 6 -#define X509_PURPOSE_ANY 7 -#define X509_PURPOSE_OCSP_HELPER 8 -#define X509_PURPOSE_TIMESTAMP_SIGN 9 +// Private structures. -#define X509_PURPOSE_MIN 1 -#define X509_PURPOSE_MAX 9 - -DEFINE_STACK_OF(X509_PURPOSE) - -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) - -DECLARE_ASN1_FUNCTIONS_const(EXTENDED_KEY_USAGE) - -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, - X509_NAME *iname); - -// 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) -DECLARE_ASN1_ALLOC_FUNCTIONS(POLICY_MAPPING) -DECLARE_ASN1_ITEM(POLICY_MAPPINGS) - -DECLARE_ASN1_ITEM(GENERAL_SUBTREE) -DECLARE_ASN1_ALLOC_FUNCTIONS(GENERAL_SUBTREE) - -DECLARE_ASN1_ITEM(NAME_CONSTRAINTS) -DECLARE_ASN1_ALLOC_FUNCTIONS(NAME_CONSTRAINTS) - -DECLARE_ASN1_ALLOC_FUNCTIONS(POLICY_CONSTRAINTS) -DECLARE_ASN1_ITEM(POLICY_CONSTRAINTS) - -// X509V3_EXT_add registers |ext| as a custom extension for the extension type -// |ext->ext_nid|. |ext| must be valid for the remainder of the address space's -// lifetime. It returns one on success and zero on error. -// -// WARNING: This function modifies global state. If other code in the same -// address space also registers an extension with type |ext->ext_nid|, the two -// registrations will conflict. Which registration takes effect is undefined. If -// the two registrations use incompatible in-memory representations, code -// expecting the other registration will then cast a type to the wrong type, -// resulting in a potentially exploitable memory error. This conflict can also -// occur if BoringSSL later adds support for |ext->ext_nid|, with a different -// in-memory representation than the one expected by |ext|. -// -// This function, additionally, is not thread-safe and cannot be called -// concurrently with any other BoringSSL function. -// -// As a result, it is impossible to safely use this function. Registering a -// custom extension has no impact on certificate verification so, instead, -// callers should simply handle the custom extension with the byte-based -// |X509_EXTENSION| APIs directly. Registering |ext| with the library has little -// practical value. -OPENSSL_EXPORT OPENSSL_DEPRECATED int X509V3_EXT_add(X509V3_EXT_METHOD *ext); - -// X509V3_EXT_add_alias registers a custom extension with NID |nid_to|. The -// corresponding ASN.1 type is copied from |nid_from|. It returns one on success -// and zero on error. -// -// WARNING: Do not use this function. See |X509V3_EXT_add|. -OPENSSL_EXPORT OPENSSL_DEPRECATED int X509V3_EXT_add_alias(int nid_to, - int nid_from); - -OPENSSL_EXPORT const X509V3_EXT_METHOD *X509V3_EXT_get( - const X509_EXTENSION *ext); -OPENSSL_EXPORT const X509V3_EXT_METHOD *X509V3_EXT_get_nid(int nid); - -// X509V3_EXT_d2i decodes |ext| and returns a pointer to a newly-allocated -// structure, with type dependent on the type of the extension. It returns NULL -// if |ext| is an unsupported extension or if there was a syntax error in the -// extension. The caller should cast the return value to the expected type and -// free the structure when done. -// -// WARNING: Casting the return value to the wrong type is a potentially -// exploitable memory error, so callers must not use this function before -// checking |ext| is of a known type. -OPENSSL_EXPORT void *X509V3_EXT_d2i(const X509_EXTENSION *ext); - -// X509V3_get_d2i finds and decodes the extension in |extensions| of type |nid|. -// If found, it decodes it and returns a newly-allocated structure, with type -// dependent on |nid|. If the extension is not found or on error, it returns -// NULL. The caller may distinguish these cases using the |out_critical| value. -// -// If |out_critical| is not NULL, this function sets |*out_critical| to one if -// the extension is found and critical, zero if it is found and not critical, -1 -// if it is not found, and -2 if there is an invalid duplicate extension. Note -// this function may set |*out_critical| to one or zero and still return NULL if -// the extension is found but has a syntax error. -// -// If |out_idx| is not NULL, this function looks for the first occurrence of the -// extension after |*out_idx|. It then sets |*out_idx| to the index of the -// extension, or -1 if not found. If |out_idx| is non-NULL, duplicate extensions -// are not treated as an error. Callers, however, should not rely on this -// behavior as it may be removed in the future. Duplicate extensions are -// forbidden in RFC 5280. -// -// WARNING: This function is difficult to use correctly. Callers should pass a -// non-NULL |out_critical| and check both the return value and |*out_critical| -// to handle errors. If the return value is NULL and |*out_critical| is not -1, -// there was an error. Otherwise, the function succeeded and but may return NULL -// for a missing extension. Callers should pass NULL to |out_idx| so that -// duplicate extensions are handled correctly. -// -// Additionally, casting the return value to the wrong type is a potentially -// exploitable memory error, so callers must ensure the cast and |nid| match. -OPENSSL_EXPORT void *X509V3_get_d2i(const STACK_OF(X509_EXTENSION) *extensions, - int nid, int *out_critical, int *out_idx); - -// X509V3_EXT_free casts |ext_data| into the type that corresponds to |nid| and -// releases memory associated with it. It returns one on success and zero if -// |nid| is not a known extension. -// -// WARNING: Casting |ext_data| to the wrong type is a potentially exploitable -// memory error, so callers must ensure |ext_data|'s type matches |nid|. -// -// TODO(davidben): OpenSSL upstream no longer exposes this function. Remove it? -OPENSSL_EXPORT int X509V3_EXT_free(int nid, void *ext_data); - -// X509V3_EXT_i2d casts |ext_struc| into the type that corresponds to -// |ext_nid|, serializes it, and returns a newly-allocated |X509_EXTENSION| -// object containing the serialization, or NULL on error. The |X509_EXTENSION| -// has OID |ext_nid| and is critical if |crit| is one. -// -// WARNING: Casting |ext_struc| to the wrong type is a potentially exploitable -// memory error, so callers must ensure |ext_struct|'s type matches |ext_nid|. -OPENSSL_EXPORT X509_EXTENSION *X509V3_EXT_i2d(int ext_nid, int crit, - void *ext_struc); - -// The following constants control the behavior of |X509V3_add1_i2d| and related -// functions. - -// X509V3_ADD_OP_MASK can be ANDed with the flags to determine how duplicate -// extensions are processed. -#define X509V3_ADD_OP_MASK 0xfL - -// X509V3_ADD_DEFAULT causes the function to fail if the extension was already -// present. -#define X509V3_ADD_DEFAULT 0L - -// X509V3_ADD_APPEND causes the function to unconditionally appended the new -// extension to to the extensions list, even if there is a duplicate. -#define X509V3_ADD_APPEND 1L - -// X509V3_ADD_REPLACE causes the function to replace the existing extension, or -// append if it is not present. -#define X509V3_ADD_REPLACE 2L - -// X509V3_ADD_REPLACE causes the function to replace the existing extension and -// fail if it is not present. -#define X509V3_ADD_REPLACE_EXISTING 3L - -// X509V3_ADD_KEEP_EXISTING causes the function to succeed without replacing the -// extension if already present. -#define X509V3_ADD_KEEP_EXISTING 4L - -// X509V3_ADD_DELETE causes the function to remove the matching extension. No -// new extension is added. If there is no matching extension, the function -// fails. The |value| parameter is ignored in this mode. -#define X509V3_ADD_DELETE 5L - -// X509V3_ADD_SILENT may be ORed into one of the values above to indicate the -// function should not add to the error queue on duplicate or missing extension. -// The function will continue to return zero in those cases, and it will -// continue to return -1 and add to the error queue on other errors. -#define X509V3_ADD_SILENT 0x10 - -// X509V3_add1_i2d casts |value| to the type that corresponds to |nid|, -// serializes it, and appends it to the extension list in |*x|. If |*x| is NULL, -// it will set |*x| to a newly-allocated |STACK_OF(X509_EXTENSION)| as needed. -// The |crit| parameter determines whether the new extension is critical. -// |flags| may be some combination of the |X509V3_ADD_*| constants to control -// the function's behavior on duplicate extension. -// -// This function returns one on success, zero if the operation failed due to a -// missing or duplicate extension, and -1 on other errors. -// -// WARNING: Casting |value| to the wrong type is a potentially exploitable -// memory error, so callers must ensure |value|'s type matches |nid|. -OPENSSL_EXPORT int X509V3_add1_i2d(STACK_OF(X509_EXTENSION) **x, int nid, - void *value, int crit, unsigned long flags); - -OPENSSL_EXPORT int X509_check_purpose(X509 *x, int id, int ca); - -OPENSSL_EXPORT int X509_PURPOSE_set(int *p, int purpose); - -OPENSSL_EXPORT int X509_PURPOSE_get_count(void); -OPENSSL_EXPORT const X509_PURPOSE *X509_PURPOSE_get0(int idx); -OPENSSL_EXPORT int X509_PURPOSE_get_by_sname(const char *sname); -OPENSSL_EXPORT int X509_PURPOSE_get_by_id(int id); -OPENSSL_EXPORT char *X509_PURPOSE_get0_name(const X509_PURPOSE *xp); -OPENSSL_EXPORT char *X509_PURPOSE_get0_sname(const X509_PURPOSE *xp); -OPENSSL_EXPORT int X509_PURPOSE_get_trust(const X509_PURPOSE *xp); -OPENSSL_EXPORT int X509_PURPOSE_get_id(const X509_PURPOSE *); - -// Flags for X509_check_* functions - -// Deprecated: this flag does nothing -#define X509_CHECK_FLAG_ALWAYS_CHECK_SUBJECT 0 -// Disable wildcard matching for dnsName fields and common name. -#define X509_CHECK_FLAG_NO_WILDCARDS 0x2 -// X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS does nothing, but is necessary in -// OpenSSL to enable standard wildcard matching. In BoringSSL, this behavior is -// always enabled. -#define X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS 0 -// Deprecated: this flag does nothing -#define X509_CHECK_FLAG_MULTI_LABEL_WILDCARDS 0 -// Deprecated: this flag does nothing -#define X509_CHECK_FLAG_SINGLE_LABEL_SUBDOMAINS 0 -// Skip the subject common name fallback if subjectAltNames is missing. -#define X509_CHECK_FLAG_NEVER_CHECK_SUBJECT 0x20 +struct X509_algor_st { + ASN1_OBJECT *algorithm; + ASN1_TYPE *parameter; +} /* X509_ALGOR */; #if defined(__cplusplus) @@ -4555,6 +5427,7 @@ BORINGSSL_MAKE_DELETER(X509_INFO, X509_INFO_free) 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_OBJECT, X509_OBJECT_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/CCryptoBoringSSL/include/CCryptoBoringSSL_x509v3.h b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_x509v3.h index 01044e3f..3501b90a 100644 --- a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_x509v3.h +++ b/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_x509v3.h @@ -20,6 +20,30 @@ // However, due to conflicts, some deprecated symbols are defined here. #include "CCryptoBoringSSL_x509.h" + +// CRL reason constants. + +// TODO(davidben): These constants live here because strongswan defines +// conflicting symbols and has been relying on them only being defined in +// . Defining the constants in would break +// strongswan, but we would also like for new code to only need +// . Introduce properly namespaced versions of these constants +// and, separately, see if we can fix strongswan to similarly avoid the +// conflict. Between OpenSSL, strongswan, and wincrypt.h all defining these +// constants, it seems best for everyone to just avoid them going forward. +#define CRL_REASON_NONE (-1) +#define CRL_REASON_UNSPECIFIED 0 +#define CRL_REASON_KEY_COMPROMISE 1 +#define CRL_REASON_CA_COMPROMISE 2 +#define CRL_REASON_AFFILIATION_CHANGED 3 +#define CRL_REASON_SUPERSEDED 4 +#define CRL_REASON_CESSATION_OF_OPERATION 5 +#define CRL_REASON_CERTIFICATE_HOLD 6 +#define CRL_REASON_REMOVE_FROM_CRL 8 +#define CRL_REASON_PRIVILEGE_WITHDRAWN 9 +#define CRL_REASON_AA_COMPROMISE 10 + + // Deprecated constants. // The following constants are legacy aliases for |X509v3_KU_*|. They are diff --git a/Sources/CCryptoBoringSSL/include/boringssl_prefix_symbols_nasm.inc b/Sources/CCryptoBoringSSL/include/boringssl_prefix_symbols_nasm.inc index 1bbed795..2f360bd2 100644 --- a/Sources/CCryptoBoringSSL/include/boringssl_prefix_symbols_nasm.inc +++ b/Sources/CCryptoBoringSSL/include/boringssl_prefix_symbols_nasm.inc @@ -507,7 +507,6 @@ %xdefine _CBS_asn1_oid_to_text _ %+ BORINGSSL_PREFIX %+ _CBS_asn1_oid_to_text %xdefine _CBS_contains_zero_byte _ %+ BORINGSSL_PREFIX %+ _CBS_contains_zero_byte %xdefine _CBS_copy_bytes _ %+ BORINGSSL_PREFIX %+ _CBS_copy_bytes -%xdefine _CBS_data _ %+ BORINGSSL_PREFIX %+ _CBS_data %xdefine _CBS_get_any_asn1 _ %+ BORINGSSL_PREFIX %+ _CBS_get_any_asn1 %xdefine _CBS_get_any_asn1_element _ %+ BORINGSSL_PREFIX %+ _CBS_get_any_asn1_element %xdefine _CBS_get_any_ber_asn1_element _ %+ BORINGSSL_PREFIX %+ _CBS_get_any_ber_asn1_element @@ -540,12 +539,10 @@ %xdefine _CBS_get_until_first _ %+ BORINGSSL_PREFIX %+ _CBS_get_until_first %xdefine _CBS_get_utf32_be _ %+ BORINGSSL_PREFIX %+ _CBS_get_utf32_be %xdefine _CBS_get_utf8 _ %+ BORINGSSL_PREFIX %+ _CBS_get_utf8 -%xdefine _CBS_init _ %+ BORINGSSL_PREFIX %+ _CBS_init %xdefine _CBS_is_unsigned_asn1_integer _ %+ BORINGSSL_PREFIX %+ _CBS_is_unsigned_asn1_integer %xdefine _CBS_is_valid_asn1_bitstring _ %+ BORINGSSL_PREFIX %+ _CBS_is_valid_asn1_bitstring %xdefine _CBS_is_valid_asn1_integer _ %+ BORINGSSL_PREFIX %+ _CBS_is_valid_asn1_integer %xdefine _CBS_is_valid_asn1_oid _ %+ BORINGSSL_PREFIX %+ _CBS_is_valid_asn1_oid -%xdefine _CBS_len _ %+ BORINGSSL_PREFIX %+ _CBS_len %xdefine _CBS_mem_equal _ %+ BORINGSSL_PREFIX %+ _CBS_mem_equal %xdefine _CBS_parse_generalized_time _ %+ BORINGSSL_PREFIX %+ _CBS_parse_generalized_time %xdefine _CBS_parse_utc_time _ %+ BORINGSSL_PREFIX %+ _CBS_parse_utc_time @@ -620,7 +617,7 @@ %xdefine _CRYPTO_get_dynlock_destroy_callback _ %+ BORINGSSL_PREFIX %+ _CRYPTO_get_dynlock_destroy_callback %xdefine _CRYPTO_get_dynlock_lock_callback _ %+ BORINGSSL_PREFIX %+ _CRYPTO_get_dynlock_lock_callback %xdefine _CRYPTO_get_ex_data _ %+ BORINGSSL_PREFIX %+ _CRYPTO_get_ex_data -%xdefine _CRYPTO_get_ex_new_index _ %+ BORINGSSL_PREFIX %+ _CRYPTO_get_ex_new_index +%xdefine _CRYPTO_get_ex_new_index_ex _ %+ BORINGSSL_PREFIX %+ _CRYPTO_get_ex_new_index_ex %xdefine _CRYPTO_get_fork_generation _ %+ BORINGSSL_PREFIX %+ _CRYPTO_get_fork_generation %xdefine _CRYPTO_get_lock_name _ %+ BORINGSSL_PREFIX %+ _CRYPTO_get_lock_name %xdefine _CRYPTO_get_locking_callback _ %+ BORINGSSL_PREFIX %+ _CRYPTO_get_locking_callback @@ -669,17 +666,24 @@ %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 _ChaCha20_ctr32_avx2 _ %+ BORINGSSL_PREFIX %+ _ChaCha20_ctr32_avx2 %xdefine _ChaCha20_ctr32_neon _ %+ BORINGSSL_PREFIX %+ _ChaCha20_ctr32_neon %xdefine _ChaCha20_ctr32_nohw _ %+ BORINGSSL_PREFIX %+ _ChaCha20_ctr32_nohw +%xdefine _ChaCha20_ctr32_ssse3 _ %+ BORINGSSL_PREFIX %+ _ChaCha20_ctr32_ssse3 +%xdefine _ChaCha20_ctr32_ssse3_4x _ %+ BORINGSSL_PREFIX %+ _ChaCha20_ctr32_ssse3_4x %xdefine _DES_decrypt3 _ %+ BORINGSSL_PREFIX %+ _DES_decrypt3 %xdefine _DES_ecb3_encrypt _ %+ BORINGSSL_PREFIX %+ _DES_ecb3_encrypt +%xdefine _DES_ecb3_encrypt_ex _ %+ BORINGSSL_PREFIX %+ _DES_ecb3_encrypt_ex %xdefine _DES_ecb_encrypt _ %+ BORINGSSL_PREFIX %+ _DES_ecb_encrypt +%xdefine _DES_ecb_encrypt_ex _ %+ BORINGSSL_PREFIX %+ _DES_ecb_encrypt_ex %xdefine _DES_ede2_cbc_encrypt _ %+ BORINGSSL_PREFIX %+ _DES_ede2_cbc_encrypt %xdefine _DES_ede3_cbc_encrypt _ %+ BORINGSSL_PREFIX %+ _DES_ede3_cbc_encrypt +%xdefine _DES_ede3_cbc_encrypt_ex _ %+ BORINGSSL_PREFIX %+ _DES_ede3_cbc_encrypt_ex %xdefine _DES_encrypt3 _ %+ BORINGSSL_PREFIX %+ _DES_encrypt3 %xdefine _DES_ncbc_encrypt _ %+ BORINGSSL_PREFIX %+ _DES_ncbc_encrypt +%xdefine _DES_ncbc_encrypt_ex _ %+ BORINGSSL_PREFIX %+ _DES_ncbc_encrypt_ex %xdefine _DES_set_key _ %+ BORINGSSL_PREFIX %+ _DES_set_key +%xdefine _DES_set_key_ex _ %+ BORINGSSL_PREFIX %+ _DES_set_key_ex %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 @@ -900,6 +904,7 @@ %xdefine _ERR_get_error_line_data _ %+ BORINGSSL_PREFIX %+ _ERR_get_error_line_data %xdefine _ERR_get_next_error_library _ %+ BORINGSSL_PREFIX %+ _ERR_get_next_error_library %xdefine _ERR_lib_error_string _ %+ BORINGSSL_PREFIX %+ _ERR_lib_error_string +%xdefine _ERR_lib_symbol_name _ %+ BORINGSSL_PREFIX %+ _ERR_lib_symbol_name %xdefine _ERR_load_BIO_strings _ %+ BORINGSSL_PREFIX %+ _ERR_load_BIO_strings %xdefine _ERR_load_ERR_strings _ %+ BORINGSSL_PREFIX %+ _ERR_load_ERR_strings %xdefine _ERR_load_RAND_strings _ %+ BORINGSSL_PREFIX %+ _ERR_load_RAND_strings @@ -916,6 +921,7 @@ %xdefine _ERR_print_errors_fp _ %+ BORINGSSL_PREFIX %+ _ERR_print_errors_fp %xdefine _ERR_put_error _ %+ BORINGSSL_PREFIX %+ _ERR_put_error %xdefine _ERR_reason_error_string _ %+ BORINGSSL_PREFIX %+ _ERR_reason_error_string +%xdefine _ERR_reason_symbol_name _ %+ BORINGSSL_PREFIX %+ _ERR_reason_symbol_name %xdefine _ERR_remove_state _ %+ BORINGSSL_PREFIX %+ _ERR_remove_state %xdefine _ERR_remove_thread_state _ %+ BORINGSSL_PREFIX %+ _ERR_remove_thread_state %xdefine _ERR_restore_state _ %+ BORINGSSL_PREFIX %+ _ERR_restore_state @@ -1943,14 +1949,9 @@ %xdefine _X509_PUBKEY_set _ %+ BORINGSSL_PREFIX %+ _X509_PUBKEY_set %xdefine _X509_PUBKEY_set0_param _ %+ BORINGSSL_PREFIX %+ _X509_PUBKEY_set0_param %xdefine _X509_PURPOSE_get0 _ %+ BORINGSSL_PREFIX %+ _X509_PURPOSE_get0 -%xdefine _X509_PURPOSE_get0_name _ %+ BORINGSSL_PREFIX %+ _X509_PURPOSE_get0_name -%xdefine _X509_PURPOSE_get0_sname _ %+ BORINGSSL_PREFIX %+ _X509_PURPOSE_get0_sname -%xdefine _X509_PURPOSE_get_by_id _ %+ BORINGSSL_PREFIX %+ _X509_PURPOSE_get_by_id %xdefine _X509_PURPOSE_get_by_sname _ %+ BORINGSSL_PREFIX %+ _X509_PURPOSE_get_by_sname -%xdefine _X509_PURPOSE_get_count _ %+ BORINGSSL_PREFIX %+ _X509_PURPOSE_get_count %xdefine _X509_PURPOSE_get_id _ %+ BORINGSSL_PREFIX %+ _X509_PURPOSE_get_id %xdefine _X509_PURPOSE_get_trust _ %+ BORINGSSL_PREFIX %+ _X509_PURPOSE_get_trust -%xdefine _X509_PURPOSE_set _ %+ BORINGSSL_PREFIX %+ _X509_PURPOSE_set %xdefine _X509_REQ_INFO_free _ %+ BORINGSSL_PREFIX %+ _X509_REQ_INFO_free %xdefine _X509_REQ_INFO_it _ %+ BORINGSSL_PREFIX %+ _X509_REQ_INFO_it %xdefine _X509_REQ_INFO_new _ %+ BORINGSSL_PREFIX %+ _X509_REQ_INFO_new @@ -2036,11 +2037,9 @@ %xdefine _X509_STORE_CTX_get_ex_new_index _ %+ BORINGSSL_PREFIX %+ _X509_STORE_CTX_get_ex_new_index %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 %xdefine _X509_STORE_CTX_set_depth _ %+ BORINGSSL_PREFIX %+ _X509_STORE_CTX_set_depth @@ -2059,6 +2058,7 @@ %xdefine _X509_STORE_free _ %+ BORINGSSL_PREFIX %+ _X509_STORE_free %xdefine _X509_STORE_get0_objects _ %+ BORINGSSL_PREFIX %+ _X509_STORE_get0_objects %xdefine _X509_STORE_get0_param _ %+ BORINGSSL_PREFIX %+ _X509_STORE_get0_param +%xdefine _X509_STORE_get1_objects _ %+ BORINGSSL_PREFIX %+ _X509_STORE_get1_objects %xdefine _X509_STORE_load_locations _ %+ BORINGSSL_PREFIX %+ _X509_STORE_load_locations %xdefine _X509_STORE_new _ %+ BORINGSSL_PREFIX %+ _X509_STORE_new %xdefine _X509_STORE_set1_param _ %+ BORINGSSL_PREFIX %+ _X509_STORE_set1_param @@ -2071,13 +2071,6 @@ %xdefine _X509_STORE_set_trust _ %+ BORINGSSL_PREFIX %+ _X509_STORE_set_trust %xdefine _X509_STORE_set_verify_cb _ %+ BORINGSSL_PREFIX %+ _X509_STORE_set_verify_cb %xdefine _X509_STORE_up_ref _ %+ BORINGSSL_PREFIX %+ _X509_STORE_up_ref -%xdefine _X509_TRUST_get0 _ %+ BORINGSSL_PREFIX %+ _X509_TRUST_get0 -%xdefine _X509_TRUST_get0_name _ %+ BORINGSSL_PREFIX %+ _X509_TRUST_get0_name -%xdefine _X509_TRUST_get_by_id _ %+ BORINGSSL_PREFIX %+ _X509_TRUST_get_by_id -%xdefine _X509_TRUST_get_count _ %+ BORINGSSL_PREFIX %+ _X509_TRUST_get_count -%xdefine _X509_TRUST_get_flags _ %+ BORINGSSL_PREFIX %+ _X509_TRUST_get_flags -%xdefine _X509_TRUST_get_trust _ %+ BORINGSSL_PREFIX %+ _X509_TRUST_get_trust -%xdefine _X509_TRUST_set _ %+ BORINGSSL_PREFIX %+ _X509_TRUST_set %xdefine _X509_VAL_free _ %+ BORINGSSL_PREFIX %+ _X509_VAL_free %xdefine _X509_VAL_it _ %+ BORINGSSL_PREFIX %+ _X509_VAL_it %xdefine _X509_VAL_new _ %+ BORINGSSL_PREFIX %+ _X509_VAL_new @@ -2176,6 +2169,7 @@ %xdefine _X509_getm_notAfter _ %+ BORINGSSL_PREFIX %+ _X509_getm_notAfter %xdefine _X509_getm_notBefore _ %+ BORINGSSL_PREFIX %+ _X509_getm_notBefore %xdefine _X509_gmtime_adj _ %+ BORINGSSL_PREFIX %+ _X509_gmtime_adj +%xdefine _X509_is_valid_trust_id _ %+ BORINGSSL_PREFIX %+ _X509_is_valid_trust_id %xdefine _X509_issuer_name_cmp _ %+ BORINGSSL_PREFIX %+ _X509_issuer_name_cmp %xdefine _X509_issuer_name_hash _ %+ BORINGSSL_PREFIX %+ _X509_issuer_name_hash %xdefine _X509_issuer_name_hash_old _ %+ BORINGSSL_PREFIX %+ _X509_issuer_name_hash_old @@ -2324,14 +2318,17 @@ %xdefine _bn_mont_ctx_init _ %+ BORINGSSL_PREFIX %+ _bn_mont_ctx_init %xdefine _bn_mont_ctx_set_RR_consttime _ %+ BORINGSSL_PREFIX %+ _bn_mont_ctx_set_RR_consttime %xdefine _bn_mont_n0 _ %+ BORINGSSL_PREFIX %+ _bn_mont_n0 +%xdefine _bn_mul4x_mont _ %+ BORINGSSL_PREFIX %+ _bn_mul4x_mont %xdefine _bn_mul_add_words _ %+ BORINGSSL_PREFIX %+ _bn_mul_add_words %xdefine _bn_mul_comba4 _ %+ BORINGSSL_PREFIX %+ _bn_mul_comba4 %xdefine _bn_mul_comba8 _ %+ BORINGSSL_PREFIX %+ _bn_mul_comba8 %xdefine _bn_mul_consttime _ %+ BORINGSSL_PREFIX %+ _bn_mul_consttime %xdefine _bn_mul_mont _ %+ BORINGSSL_PREFIX %+ _bn_mul_mont %xdefine _bn_mul_mont_gather5 _ %+ BORINGSSL_PREFIX %+ _bn_mul_mont_gather5 +%xdefine _bn_mul_mont_nohw _ %+ BORINGSSL_PREFIX %+ _bn_mul_mont_nohw %xdefine _bn_mul_small _ %+ BORINGSSL_PREFIX %+ _bn_mul_small %xdefine _bn_mul_words _ %+ BORINGSSL_PREFIX %+ _bn_mul_words +%xdefine _bn_mulx4x_mont _ %+ BORINGSSL_PREFIX %+ _bn_mulx4x_mont %xdefine _bn_odd_number_is_obviously_composite _ %+ BORINGSSL_PREFIX %+ _bn_odd_number_is_obviously_composite %xdefine _bn_one_to_montgomery _ %+ BORINGSSL_PREFIX %+ _bn_one_to_montgomery %xdefine _bn_power5 _ %+ BORINGSSL_PREFIX %+ _bn_power5 @@ -2349,6 +2346,7 @@ %xdefine _bn_set_static_words _ %+ BORINGSSL_PREFIX %+ _bn_set_static_words %xdefine _bn_set_words _ %+ BORINGSSL_PREFIX %+ _bn_set_words %xdefine _bn_sqr8x_internal _ %+ BORINGSSL_PREFIX %+ _bn_sqr8x_internal +%xdefine _bn_sqr8x_mont _ %+ BORINGSSL_PREFIX %+ _bn_sqr8x_mont %xdefine _bn_sqr_comba4 _ %+ BORINGSSL_PREFIX %+ _bn_sqr_comba4 %xdefine _bn_sqr_comba8 _ %+ BORINGSSL_PREFIX %+ _bn_sqr_comba8 %xdefine _bn_sqr_consttime _ %+ BORINGSSL_PREFIX %+ _bn_sqr_consttime @@ -2370,7 +2368,6 @@ %xdefine _chacha20_poly1305_open _ %+ BORINGSSL_PREFIX %+ _chacha20_poly1305_open %xdefine _chacha20_poly1305_seal _ %+ BORINGSSL_PREFIX %+ _chacha20_poly1305_seal %xdefine _crypto_gcm_clmul_enabled _ %+ BORINGSSL_PREFIX %+ _crypto_gcm_clmul_enabled -%xdefine _d2i_ACCESS_DESCRIPTION _ %+ BORINGSSL_PREFIX %+ _d2i_ACCESS_DESCRIPTION %xdefine _d2i_ASN1_BIT_STRING _ %+ BORINGSSL_PREFIX %+ _d2i_ASN1_BIT_STRING %xdefine _d2i_ASN1_BMPSTRING _ %+ BORINGSSL_PREFIX %+ _d2i_ASN1_BMPSTRING %xdefine _d2i_ASN1_BOOLEAN _ %+ BORINGSSL_PREFIX %+ _d2i_ASN1_BOOLEAN @@ -2403,8 +2400,6 @@ %xdefine _d2i_DHparams_bio _ %+ BORINGSSL_PREFIX %+ _d2i_DHparams_bio %xdefine _d2i_DIRECTORYSTRING _ %+ BORINGSSL_PREFIX %+ _d2i_DIRECTORYSTRING %xdefine _d2i_DISPLAYTEXT _ %+ BORINGSSL_PREFIX %+ _d2i_DISPLAYTEXT -%xdefine _d2i_DIST_POINT _ %+ BORINGSSL_PREFIX %+ _d2i_DIST_POINT -%xdefine _d2i_DIST_POINT_NAME _ %+ BORINGSSL_PREFIX %+ _d2i_DIST_POINT_NAME %xdefine _d2i_DSAPrivateKey _ %+ BORINGSSL_PREFIX %+ _d2i_DSAPrivateKey %xdefine _d2i_DSAPrivateKey_bio _ %+ BORINGSSL_PREFIX %+ _d2i_DSAPrivateKey_bio %xdefine _d2i_DSAPrivateKey_fp _ %+ BORINGSSL_PREFIX %+ _d2i_DSAPrivateKey_fp @@ -2428,7 +2423,6 @@ %xdefine _d2i_ISSUING_DIST_POINT _ %+ BORINGSSL_PREFIX %+ _d2i_ISSUING_DIST_POINT %xdefine _d2i_NETSCAPE_SPKAC _ %+ BORINGSSL_PREFIX %+ _d2i_NETSCAPE_SPKAC %xdefine _d2i_NETSCAPE_SPKI _ %+ BORINGSSL_PREFIX %+ _d2i_NETSCAPE_SPKI -%xdefine _d2i_NOTICEREF _ %+ BORINGSSL_PREFIX %+ _d2i_NOTICEREF %xdefine _d2i_PKCS12 _ %+ BORINGSSL_PREFIX %+ _d2i_PKCS12 %xdefine _d2i_PKCS12_bio _ %+ BORINGSSL_PREFIX %+ _d2i_PKCS12_bio %xdefine _d2i_PKCS12_fp _ %+ BORINGSSL_PREFIX %+ _d2i_PKCS12_fp @@ -2441,8 +2435,6 @@ %xdefine _d2i_PKCS8_PRIV_KEY_INFO_fp _ %+ BORINGSSL_PREFIX %+ _d2i_PKCS8_PRIV_KEY_INFO_fp %xdefine _d2i_PKCS8_bio _ %+ BORINGSSL_PREFIX %+ _d2i_PKCS8_bio %xdefine _d2i_PKCS8_fp _ %+ BORINGSSL_PREFIX %+ _d2i_PKCS8_fp -%xdefine _d2i_POLICYINFO _ %+ BORINGSSL_PREFIX %+ _d2i_POLICYINFO -%xdefine _d2i_POLICYQUALINFO _ %+ BORINGSSL_PREFIX %+ _d2i_POLICYQUALINFO %xdefine _d2i_PUBKEY _ %+ BORINGSSL_PREFIX %+ _d2i_PUBKEY %xdefine _d2i_PUBKEY_bio _ %+ BORINGSSL_PREFIX %+ _d2i_PUBKEY_bio %xdefine _d2i_PUBKEY_fp _ %+ BORINGSSL_PREFIX %+ _d2i_PUBKEY_fp @@ -2460,7 +2452,6 @@ %xdefine _d2i_RSA_PUBKEY _ %+ BORINGSSL_PREFIX %+ _d2i_RSA_PUBKEY %xdefine _d2i_RSA_PUBKEY_bio _ %+ BORINGSSL_PREFIX %+ _d2i_RSA_PUBKEY_bio %xdefine _d2i_RSA_PUBKEY_fp _ %+ BORINGSSL_PREFIX %+ _d2i_RSA_PUBKEY_fp -%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_ATTRIBUTE _ %+ BORINGSSL_PREFIX %+ _d2i_X509_ATTRIBUTE @@ -2623,7 +2614,6 @@ %xdefine _i2a_ASN1_STRING _ %+ BORINGSSL_PREFIX %+ _i2a_ASN1_STRING %xdefine _i2c_ASN1_BIT_STRING _ %+ BORINGSSL_PREFIX %+ _i2c_ASN1_BIT_STRING %xdefine _i2c_ASN1_INTEGER _ %+ BORINGSSL_PREFIX %+ _i2c_ASN1_INTEGER -%xdefine _i2d_ACCESS_DESCRIPTION _ %+ BORINGSSL_PREFIX %+ _i2d_ACCESS_DESCRIPTION %xdefine _i2d_ASN1_BIT_STRING _ %+ BORINGSSL_PREFIX %+ _i2d_ASN1_BIT_STRING %xdefine _i2d_ASN1_BMPSTRING _ %+ BORINGSSL_PREFIX %+ _i2d_ASN1_BMPSTRING %xdefine _i2d_ASN1_BOOLEAN _ %+ BORINGSSL_PREFIX %+ _i2d_ASN1_BOOLEAN @@ -2655,8 +2645,6 @@ %xdefine _i2d_DHparams_bio _ %+ BORINGSSL_PREFIX %+ _i2d_DHparams_bio %xdefine _i2d_DIRECTORYSTRING _ %+ BORINGSSL_PREFIX %+ _i2d_DIRECTORYSTRING %xdefine _i2d_DISPLAYTEXT _ %+ BORINGSSL_PREFIX %+ _i2d_DISPLAYTEXT -%xdefine _i2d_DIST_POINT _ %+ BORINGSSL_PREFIX %+ _i2d_DIST_POINT -%xdefine _i2d_DIST_POINT_NAME _ %+ BORINGSSL_PREFIX %+ _i2d_DIST_POINT_NAME %xdefine _i2d_DSAPrivateKey _ %+ BORINGSSL_PREFIX %+ _i2d_DSAPrivateKey %xdefine _i2d_DSAPrivateKey_bio _ %+ BORINGSSL_PREFIX %+ _i2d_DSAPrivateKey_bio %xdefine _i2d_DSAPrivateKey_fp _ %+ BORINGSSL_PREFIX %+ _i2d_DSAPrivateKey_fp @@ -2680,7 +2668,6 @@ %xdefine _i2d_ISSUING_DIST_POINT _ %+ BORINGSSL_PREFIX %+ _i2d_ISSUING_DIST_POINT %xdefine _i2d_NETSCAPE_SPKAC _ %+ BORINGSSL_PREFIX %+ _i2d_NETSCAPE_SPKAC %xdefine _i2d_NETSCAPE_SPKI _ %+ BORINGSSL_PREFIX %+ _i2d_NETSCAPE_SPKI -%xdefine _i2d_NOTICEREF _ %+ BORINGSSL_PREFIX %+ _i2d_NOTICEREF %xdefine _i2d_PKCS12 _ %+ BORINGSSL_PREFIX %+ _i2d_PKCS12 %xdefine _i2d_PKCS12_bio _ %+ BORINGSSL_PREFIX %+ _i2d_PKCS12_bio %xdefine _i2d_PKCS12_fp _ %+ BORINGSSL_PREFIX %+ _i2d_PKCS12_fp @@ -2697,8 +2684,6 @@ %xdefine _i2d_PKCS8_PRIV_KEY_INFO_fp _ %+ BORINGSSL_PREFIX %+ _i2d_PKCS8_PRIV_KEY_INFO_fp %xdefine _i2d_PKCS8_bio _ %+ BORINGSSL_PREFIX %+ _i2d_PKCS8_bio %xdefine _i2d_PKCS8_fp _ %+ BORINGSSL_PREFIX %+ _i2d_PKCS8_fp -%xdefine _i2d_POLICYINFO _ %+ BORINGSSL_PREFIX %+ _i2d_POLICYINFO -%xdefine _i2d_POLICYQUALINFO _ %+ BORINGSSL_PREFIX %+ _i2d_POLICYQUALINFO %xdefine _i2d_PUBKEY _ %+ BORINGSSL_PREFIX %+ _i2d_PUBKEY %xdefine _i2d_PUBKEY_bio _ %+ BORINGSSL_PREFIX %+ _i2d_PUBKEY_bio %xdefine _i2d_PUBKEY_fp _ %+ BORINGSSL_PREFIX %+ _i2d_PUBKEY_fp @@ -2716,7 +2701,6 @@ %xdefine _i2d_RSA_PUBKEY _ %+ BORINGSSL_PREFIX %+ _i2d_RSA_PUBKEY %xdefine _i2d_RSA_PUBKEY_bio _ %+ BORINGSSL_PREFIX %+ _i2d_RSA_PUBKEY_bio %xdefine _i2d_RSA_PUBKEY_fp _ %+ BORINGSSL_PREFIX %+ _i2d_RSA_PUBKEY_fp -%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_ATTRIBUTE _ %+ BORINGSSL_PREFIX %+ _i2d_X509_ATTRIBUTE @@ -3444,7 +3428,6 @@ %xdefine CBS_asn1_oid_to_text BORINGSSL_PREFIX %+ _CBS_asn1_oid_to_text %xdefine CBS_contains_zero_byte BORINGSSL_PREFIX %+ _CBS_contains_zero_byte %xdefine CBS_copy_bytes BORINGSSL_PREFIX %+ _CBS_copy_bytes -%xdefine CBS_data BORINGSSL_PREFIX %+ _CBS_data %xdefine CBS_get_any_asn1 BORINGSSL_PREFIX %+ _CBS_get_any_asn1 %xdefine CBS_get_any_asn1_element BORINGSSL_PREFIX %+ _CBS_get_any_asn1_element %xdefine CBS_get_any_ber_asn1_element BORINGSSL_PREFIX %+ _CBS_get_any_ber_asn1_element @@ -3477,12 +3460,10 @@ %xdefine CBS_get_until_first BORINGSSL_PREFIX %+ _CBS_get_until_first %xdefine CBS_get_utf32_be BORINGSSL_PREFIX %+ _CBS_get_utf32_be %xdefine CBS_get_utf8 BORINGSSL_PREFIX %+ _CBS_get_utf8 -%xdefine CBS_init BORINGSSL_PREFIX %+ _CBS_init %xdefine CBS_is_unsigned_asn1_integer BORINGSSL_PREFIX %+ _CBS_is_unsigned_asn1_integer %xdefine CBS_is_valid_asn1_bitstring BORINGSSL_PREFIX %+ _CBS_is_valid_asn1_bitstring %xdefine CBS_is_valid_asn1_integer BORINGSSL_PREFIX %+ _CBS_is_valid_asn1_integer %xdefine CBS_is_valid_asn1_oid BORINGSSL_PREFIX %+ _CBS_is_valid_asn1_oid -%xdefine CBS_len BORINGSSL_PREFIX %+ _CBS_len %xdefine CBS_mem_equal BORINGSSL_PREFIX %+ _CBS_mem_equal %xdefine CBS_parse_generalized_time BORINGSSL_PREFIX %+ _CBS_parse_generalized_time %xdefine CBS_parse_utc_time BORINGSSL_PREFIX %+ _CBS_parse_utc_time @@ -3557,7 +3538,7 @@ %xdefine CRYPTO_get_dynlock_destroy_callback BORINGSSL_PREFIX %+ _CRYPTO_get_dynlock_destroy_callback %xdefine CRYPTO_get_dynlock_lock_callback BORINGSSL_PREFIX %+ _CRYPTO_get_dynlock_lock_callback %xdefine CRYPTO_get_ex_data BORINGSSL_PREFIX %+ _CRYPTO_get_ex_data -%xdefine CRYPTO_get_ex_new_index BORINGSSL_PREFIX %+ _CRYPTO_get_ex_new_index +%xdefine CRYPTO_get_ex_new_index_ex BORINGSSL_PREFIX %+ _CRYPTO_get_ex_new_index_ex %xdefine CRYPTO_get_fork_generation BORINGSSL_PREFIX %+ _CRYPTO_get_fork_generation %xdefine CRYPTO_get_lock_name BORINGSSL_PREFIX %+ _CRYPTO_get_lock_name %xdefine CRYPTO_get_locking_callback BORINGSSL_PREFIX %+ _CRYPTO_get_locking_callback @@ -3606,17 +3587,24 @@ %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 ChaCha20_ctr32_avx2 BORINGSSL_PREFIX %+ _ChaCha20_ctr32_avx2 %xdefine ChaCha20_ctr32_neon BORINGSSL_PREFIX %+ _ChaCha20_ctr32_neon %xdefine ChaCha20_ctr32_nohw BORINGSSL_PREFIX %+ _ChaCha20_ctr32_nohw +%xdefine ChaCha20_ctr32_ssse3 BORINGSSL_PREFIX %+ _ChaCha20_ctr32_ssse3 +%xdefine ChaCha20_ctr32_ssse3_4x BORINGSSL_PREFIX %+ _ChaCha20_ctr32_ssse3_4x %xdefine DES_decrypt3 BORINGSSL_PREFIX %+ _DES_decrypt3 %xdefine DES_ecb3_encrypt BORINGSSL_PREFIX %+ _DES_ecb3_encrypt +%xdefine DES_ecb3_encrypt_ex BORINGSSL_PREFIX %+ _DES_ecb3_encrypt_ex %xdefine DES_ecb_encrypt BORINGSSL_PREFIX %+ _DES_ecb_encrypt +%xdefine DES_ecb_encrypt_ex BORINGSSL_PREFIX %+ _DES_ecb_encrypt_ex %xdefine DES_ede2_cbc_encrypt BORINGSSL_PREFIX %+ _DES_ede2_cbc_encrypt %xdefine DES_ede3_cbc_encrypt BORINGSSL_PREFIX %+ _DES_ede3_cbc_encrypt +%xdefine DES_ede3_cbc_encrypt_ex BORINGSSL_PREFIX %+ _DES_ede3_cbc_encrypt_ex %xdefine DES_encrypt3 BORINGSSL_PREFIX %+ _DES_encrypt3 %xdefine DES_ncbc_encrypt BORINGSSL_PREFIX %+ _DES_ncbc_encrypt +%xdefine DES_ncbc_encrypt_ex BORINGSSL_PREFIX %+ _DES_ncbc_encrypt_ex %xdefine DES_set_key BORINGSSL_PREFIX %+ _DES_set_key +%xdefine DES_set_key_ex BORINGSSL_PREFIX %+ _DES_set_key_ex %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 @@ -3837,6 +3825,7 @@ %xdefine ERR_get_error_line_data BORINGSSL_PREFIX %+ _ERR_get_error_line_data %xdefine ERR_get_next_error_library BORINGSSL_PREFIX %+ _ERR_get_next_error_library %xdefine ERR_lib_error_string BORINGSSL_PREFIX %+ _ERR_lib_error_string +%xdefine ERR_lib_symbol_name BORINGSSL_PREFIX %+ _ERR_lib_symbol_name %xdefine ERR_load_BIO_strings BORINGSSL_PREFIX %+ _ERR_load_BIO_strings %xdefine ERR_load_ERR_strings BORINGSSL_PREFIX %+ _ERR_load_ERR_strings %xdefine ERR_load_RAND_strings BORINGSSL_PREFIX %+ _ERR_load_RAND_strings @@ -3853,6 +3842,7 @@ %xdefine ERR_print_errors_fp BORINGSSL_PREFIX %+ _ERR_print_errors_fp %xdefine ERR_put_error BORINGSSL_PREFIX %+ _ERR_put_error %xdefine ERR_reason_error_string BORINGSSL_PREFIX %+ _ERR_reason_error_string +%xdefine ERR_reason_symbol_name BORINGSSL_PREFIX %+ _ERR_reason_symbol_name %xdefine ERR_remove_state BORINGSSL_PREFIX %+ _ERR_remove_state %xdefine ERR_remove_thread_state BORINGSSL_PREFIX %+ _ERR_remove_thread_state %xdefine ERR_restore_state BORINGSSL_PREFIX %+ _ERR_restore_state @@ -4880,14 +4870,9 @@ %xdefine X509_PUBKEY_set BORINGSSL_PREFIX %+ _X509_PUBKEY_set %xdefine X509_PUBKEY_set0_param BORINGSSL_PREFIX %+ _X509_PUBKEY_set0_param %xdefine X509_PURPOSE_get0 BORINGSSL_PREFIX %+ _X509_PURPOSE_get0 -%xdefine X509_PURPOSE_get0_name BORINGSSL_PREFIX %+ _X509_PURPOSE_get0_name -%xdefine X509_PURPOSE_get0_sname BORINGSSL_PREFIX %+ _X509_PURPOSE_get0_sname -%xdefine X509_PURPOSE_get_by_id BORINGSSL_PREFIX %+ _X509_PURPOSE_get_by_id %xdefine X509_PURPOSE_get_by_sname BORINGSSL_PREFIX %+ _X509_PURPOSE_get_by_sname -%xdefine X509_PURPOSE_get_count BORINGSSL_PREFIX %+ _X509_PURPOSE_get_count %xdefine X509_PURPOSE_get_id BORINGSSL_PREFIX %+ _X509_PURPOSE_get_id %xdefine X509_PURPOSE_get_trust BORINGSSL_PREFIX %+ _X509_PURPOSE_get_trust -%xdefine X509_PURPOSE_set BORINGSSL_PREFIX %+ _X509_PURPOSE_set %xdefine X509_REQ_INFO_free BORINGSSL_PREFIX %+ _X509_REQ_INFO_free %xdefine X509_REQ_INFO_it BORINGSSL_PREFIX %+ _X509_REQ_INFO_it %xdefine X509_REQ_INFO_new BORINGSSL_PREFIX %+ _X509_REQ_INFO_new @@ -4973,11 +4958,9 @@ %xdefine X509_STORE_CTX_get_ex_new_index BORINGSSL_PREFIX %+ _X509_STORE_CTX_get_ex_new_index %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 %xdefine X509_STORE_CTX_set_depth BORINGSSL_PREFIX %+ _X509_STORE_CTX_set_depth @@ -4996,6 +4979,7 @@ %xdefine X509_STORE_free BORINGSSL_PREFIX %+ _X509_STORE_free %xdefine X509_STORE_get0_objects BORINGSSL_PREFIX %+ _X509_STORE_get0_objects %xdefine X509_STORE_get0_param BORINGSSL_PREFIX %+ _X509_STORE_get0_param +%xdefine X509_STORE_get1_objects BORINGSSL_PREFIX %+ _X509_STORE_get1_objects %xdefine X509_STORE_load_locations BORINGSSL_PREFIX %+ _X509_STORE_load_locations %xdefine X509_STORE_new BORINGSSL_PREFIX %+ _X509_STORE_new %xdefine X509_STORE_set1_param BORINGSSL_PREFIX %+ _X509_STORE_set1_param @@ -5008,13 +4992,6 @@ %xdefine X509_STORE_set_trust BORINGSSL_PREFIX %+ _X509_STORE_set_trust %xdefine X509_STORE_set_verify_cb BORINGSSL_PREFIX %+ _X509_STORE_set_verify_cb %xdefine X509_STORE_up_ref BORINGSSL_PREFIX %+ _X509_STORE_up_ref -%xdefine X509_TRUST_get0 BORINGSSL_PREFIX %+ _X509_TRUST_get0 -%xdefine X509_TRUST_get0_name BORINGSSL_PREFIX %+ _X509_TRUST_get0_name -%xdefine X509_TRUST_get_by_id BORINGSSL_PREFIX %+ _X509_TRUST_get_by_id -%xdefine X509_TRUST_get_count BORINGSSL_PREFIX %+ _X509_TRUST_get_count -%xdefine X509_TRUST_get_flags BORINGSSL_PREFIX %+ _X509_TRUST_get_flags -%xdefine X509_TRUST_get_trust BORINGSSL_PREFIX %+ _X509_TRUST_get_trust -%xdefine X509_TRUST_set BORINGSSL_PREFIX %+ _X509_TRUST_set %xdefine X509_VAL_free BORINGSSL_PREFIX %+ _X509_VAL_free %xdefine X509_VAL_it BORINGSSL_PREFIX %+ _X509_VAL_it %xdefine X509_VAL_new BORINGSSL_PREFIX %+ _X509_VAL_new @@ -5113,6 +5090,7 @@ %xdefine X509_getm_notAfter BORINGSSL_PREFIX %+ _X509_getm_notAfter %xdefine X509_getm_notBefore BORINGSSL_PREFIX %+ _X509_getm_notBefore %xdefine X509_gmtime_adj BORINGSSL_PREFIX %+ _X509_gmtime_adj +%xdefine X509_is_valid_trust_id BORINGSSL_PREFIX %+ _X509_is_valid_trust_id %xdefine X509_issuer_name_cmp BORINGSSL_PREFIX %+ _X509_issuer_name_cmp %xdefine X509_issuer_name_hash BORINGSSL_PREFIX %+ _X509_issuer_name_hash %xdefine X509_issuer_name_hash_old BORINGSSL_PREFIX %+ _X509_issuer_name_hash_old @@ -5261,14 +5239,17 @@ %xdefine bn_mont_ctx_init BORINGSSL_PREFIX %+ _bn_mont_ctx_init %xdefine bn_mont_ctx_set_RR_consttime BORINGSSL_PREFIX %+ _bn_mont_ctx_set_RR_consttime %xdefine bn_mont_n0 BORINGSSL_PREFIX %+ _bn_mont_n0 +%xdefine bn_mul4x_mont BORINGSSL_PREFIX %+ _bn_mul4x_mont %xdefine bn_mul_add_words BORINGSSL_PREFIX %+ _bn_mul_add_words %xdefine bn_mul_comba4 BORINGSSL_PREFIX %+ _bn_mul_comba4 %xdefine bn_mul_comba8 BORINGSSL_PREFIX %+ _bn_mul_comba8 %xdefine bn_mul_consttime BORINGSSL_PREFIX %+ _bn_mul_consttime %xdefine bn_mul_mont BORINGSSL_PREFIX %+ _bn_mul_mont %xdefine bn_mul_mont_gather5 BORINGSSL_PREFIX %+ _bn_mul_mont_gather5 +%xdefine bn_mul_mont_nohw BORINGSSL_PREFIX %+ _bn_mul_mont_nohw %xdefine bn_mul_small BORINGSSL_PREFIX %+ _bn_mul_small %xdefine bn_mul_words BORINGSSL_PREFIX %+ _bn_mul_words +%xdefine bn_mulx4x_mont BORINGSSL_PREFIX %+ _bn_mulx4x_mont %xdefine bn_odd_number_is_obviously_composite BORINGSSL_PREFIX %+ _bn_odd_number_is_obviously_composite %xdefine bn_one_to_montgomery BORINGSSL_PREFIX %+ _bn_one_to_montgomery %xdefine bn_power5 BORINGSSL_PREFIX %+ _bn_power5 @@ -5286,6 +5267,7 @@ %xdefine bn_set_static_words BORINGSSL_PREFIX %+ _bn_set_static_words %xdefine bn_set_words BORINGSSL_PREFIX %+ _bn_set_words %xdefine bn_sqr8x_internal BORINGSSL_PREFIX %+ _bn_sqr8x_internal +%xdefine bn_sqr8x_mont BORINGSSL_PREFIX %+ _bn_sqr8x_mont %xdefine bn_sqr_comba4 BORINGSSL_PREFIX %+ _bn_sqr_comba4 %xdefine bn_sqr_comba8 BORINGSSL_PREFIX %+ _bn_sqr_comba8 %xdefine bn_sqr_consttime BORINGSSL_PREFIX %+ _bn_sqr_consttime @@ -5307,7 +5289,6 @@ %xdefine chacha20_poly1305_open BORINGSSL_PREFIX %+ _chacha20_poly1305_open %xdefine chacha20_poly1305_seal BORINGSSL_PREFIX %+ _chacha20_poly1305_seal %xdefine crypto_gcm_clmul_enabled BORINGSSL_PREFIX %+ _crypto_gcm_clmul_enabled -%xdefine d2i_ACCESS_DESCRIPTION BORINGSSL_PREFIX %+ _d2i_ACCESS_DESCRIPTION %xdefine d2i_ASN1_BIT_STRING BORINGSSL_PREFIX %+ _d2i_ASN1_BIT_STRING %xdefine d2i_ASN1_BMPSTRING BORINGSSL_PREFIX %+ _d2i_ASN1_BMPSTRING %xdefine d2i_ASN1_BOOLEAN BORINGSSL_PREFIX %+ _d2i_ASN1_BOOLEAN @@ -5340,8 +5321,6 @@ %xdefine d2i_DHparams_bio BORINGSSL_PREFIX %+ _d2i_DHparams_bio %xdefine d2i_DIRECTORYSTRING BORINGSSL_PREFIX %+ _d2i_DIRECTORYSTRING %xdefine d2i_DISPLAYTEXT BORINGSSL_PREFIX %+ _d2i_DISPLAYTEXT -%xdefine d2i_DIST_POINT BORINGSSL_PREFIX %+ _d2i_DIST_POINT -%xdefine d2i_DIST_POINT_NAME BORINGSSL_PREFIX %+ _d2i_DIST_POINT_NAME %xdefine d2i_DSAPrivateKey BORINGSSL_PREFIX %+ _d2i_DSAPrivateKey %xdefine d2i_DSAPrivateKey_bio BORINGSSL_PREFIX %+ _d2i_DSAPrivateKey_bio %xdefine d2i_DSAPrivateKey_fp BORINGSSL_PREFIX %+ _d2i_DSAPrivateKey_fp @@ -5365,7 +5344,6 @@ %xdefine d2i_ISSUING_DIST_POINT BORINGSSL_PREFIX %+ _d2i_ISSUING_DIST_POINT %xdefine d2i_NETSCAPE_SPKAC BORINGSSL_PREFIX %+ _d2i_NETSCAPE_SPKAC %xdefine d2i_NETSCAPE_SPKI BORINGSSL_PREFIX %+ _d2i_NETSCAPE_SPKI -%xdefine d2i_NOTICEREF BORINGSSL_PREFIX %+ _d2i_NOTICEREF %xdefine d2i_PKCS12 BORINGSSL_PREFIX %+ _d2i_PKCS12 %xdefine d2i_PKCS12_bio BORINGSSL_PREFIX %+ _d2i_PKCS12_bio %xdefine d2i_PKCS12_fp BORINGSSL_PREFIX %+ _d2i_PKCS12_fp @@ -5378,8 +5356,6 @@ %xdefine d2i_PKCS8_PRIV_KEY_INFO_fp BORINGSSL_PREFIX %+ _d2i_PKCS8_PRIV_KEY_INFO_fp %xdefine d2i_PKCS8_bio BORINGSSL_PREFIX %+ _d2i_PKCS8_bio %xdefine d2i_PKCS8_fp BORINGSSL_PREFIX %+ _d2i_PKCS8_fp -%xdefine d2i_POLICYINFO BORINGSSL_PREFIX %+ _d2i_POLICYINFO -%xdefine d2i_POLICYQUALINFO BORINGSSL_PREFIX %+ _d2i_POLICYQUALINFO %xdefine d2i_PUBKEY BORINGSSL_PREFIX %+ _d2i_PUBKEY %xdefine d2i_PUBKEY_bio BORINGSSL_PREFIX %+ _d2i_PUBKEY_bio %xdefine d2i_PUBKEY_fp BORINGSSL_PREFIX %+ _d2i_PUBKEY_fp @@ -5397,7 +5373,6 @@ %xdefine d2i_RSA_PUBKEY BORINGSSL_PREFIX %+ _d2i_RSA_PUBKEY %xdefine d2i_RSA_PUBKEY_bio BORINGSSL_PREFIX %+ _d2i_RSA_PUBKEY_bio %xdefine d2i_RSA_PUBKEY_fp BORINGSSL_PREFIX %+ _d2i_RSA_PUBKEY_fp -%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_ATTRIBUTE BORINGSSL_PREFIX %+ _d2i_X509_ATTRIBUTE @@ -5560,7 +5535,6 @@ %xdefine i2a_ASN1_STRING BORINGSSL_PREFIX %+ _i2a_ASN1_STRING %xdefine i2c_ASN1_BIT_STRING BORINGSSL_PREFIX %+ _i2c_ASN1_BIT_STRING %xdefine i2c_ASN1_INTEGER BORINGSSL_PREFIX %+ _i2c_ASN1_INTEGER -%xdefine i2d_ACCESS_DESCRIPTION BORINGSSL_PREFIX %+ _i2d_ACCESS_DESCRIPTION %xdefine i2d_ASN1_BIT_STRING BORINGSSL_PREFIX %+ _i2d_ASN1_BIT_STRING %xdefine i2d_ASN1_BMPSTRING BORINGSSL_PREFIX %+ _i2d_ASN1_BMPSTRING %xdefine i2d_ASN1_BOOLEAN BORINGSSL_PREFIX %+ _i2d_ASN1_BOOLEAN @@ -5592,8 +5566,6 @@ %xdefine i2d_DHparams_bio BORINGSSL_PREFIX %+ _i2d_DHparams_bio %xdefine i2d_DIRECTORYSTRING BORINGSSL_PREFIX %+ _i2d_DIRECTORYSTRING %xdefine i2d_DISPLAYTEXT BORINGSSL_PREFIX %+ _i2d_DISPLAYTEXT -%xdefine i2d_DIST_POINT BORINGSSL_PREFIX %+ _i2d_DIST_POINT -%xdefine i2d_DIST_POINT_NAME BORINGSSL_PREFIX %+ _i2d_DIST_POINT_NAME %xdefine i2d_DSAPrivateKey BORINGSSL_PREFIX %+ _i2d_DSAPrivateKey %xdefine i2d_DSAPrivateKey_bio BORINGSSL_PREFIX %+ _i2d_DSAPrivateKey_bio %xdefine i2d_DSAPrivateKey_fp BORINGSSL_PREFIX %+ _i2d_DSAPrivateKey_fp @@ -5617,7 +5589,6 @@ %xdefine i2d_ISSUING_DIST_POINT BORINGSSL_PREFIX %+ _i2d_ISSUING_DIST_POINT %xdefine i2d_NETSCAPE_SPKAC BORINGSSL_PREFIX %+ _i2d_NETSCAPE_SPKAC %xdefine i2d_NETSCAPE_SPKI BORINGSSL_PREFIX %+ _i2d_NETSCAPE_SPKI -%xdefine i2d_NOTICEREF BORINGSSL_PREFIX %+ _i2d_NOTICEREF %xdefine i2d_PKCS12 BORINGSSL_PREFIX %+ _i2d_PKCS12 %xdefine i2d_PKCS12_bio BORINGSSL_PREFIX %+ _i2d_PKCS12_bio %xdefine i2d_PKCS12_fp BORINGSSL_PREFIX %+ _i2d_PKCS12_fp @@ -5634,8 +5605,6 @@ %xdefine i2d_PKCS8_PRIV_KEY_INFO_fp BORINGSSL_PREFIX %+ _i2d_PKCS8_PRIV_KEY_INFO_fp %xdefine i2d_PKCS8_bio BORINGSSL_PREFIX %+ _i2d_PKCS8_bio %xdefine i2d_PKCS8_fp BORINGSSL_PREFIX %+ _i2d_PKCS8_fp -%xdefine i2d_POLICYINFO BORINGSSL_PREFIX %+ _i2d_POLICYINFO -%xdefine i2d_POLICYQUALINFO BORINGSSL_PREFIX %+ _i2d_POLICYQUALINFO %xdefine i2d_PUBKEY BORINGSSL_PREFIX %+ _i2d_PUBKEY %xdefine i2d_PUBKEY_bio BORINGSSL_PREFIX %+ _i2d_PUBKEY_bio %xdefine i2d_PUBKEY_fp BORINGSSL_PREFIX %+ _i2d_PUBKEY_fp @@ -5653,7 +5622,6 @@ %xdefine i2d_RSA_PUBKEY BORINGSSL_PREFIX %+ _i2d_RSA_PUBKEY %xdefine i2d_RSA_PUBKEY_bio BORINGSSL_PREFIX %+ _i2d_RSA_PUBKEY_bio %xdefine i2d_RSA_PUBKEY_fp BORINGSSL_PREFIX %+ _i2d_RSA_PUBKEY_fp -%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_ATTRIBUTE BORINGSSL_PREFIX %+ _i2d_X509_ATTRIBUTE diff --git a/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_kyber.h b/Sources/CCryptoBoringSSL/include/experimental/CCryptoBoringSSL_kyber.h similarity index 100% rename from Sources/CCryptoBoringSSL/include/CCryptoBoringSSL_kyber.h rename to Sources/CCryptoBoringSSL/include/experimental/CCryptoBoringSSL_kyber.h diff --git a/Sources/CCryptoBoringSSL/crypto/spx/internal.h b/Sources/CCryptoBoringSSL/include/experimental/CCryptoBoringSSL_spx.h similarity index 98% rename from Sources/CCryptoBoringSSL/crypto/spx/internal.h rename to Sources/CCryptoBoringSSL/include/experimental/CCryptoBoringSSL_spx.h index 7d81108a..4ba38833 100644 --- a/Sources/CCryptoBoringSSL/crypto/spx/internal.h +++ b/Sources/CCryptoBoringSSL/include/experimental/CCryptoBoringSSL_spx.h @@ -15,7 +15,7 @@ #ifndef OPENSSL_HEADER_SPX_H #define OPENSSL_HEADER_SPX_H -#include +#include "CCryptoBoringSSL_base.h" #if defined(__cplusplus) extern "C" { diff --git a/scripts/vendor-boringssl.sh b/scripts/vendor-boringssl.sh index 37f0c4bb..b1bffca4 100755 --- a/scripts/vendor-boringssl.sh +++ b/scripts/vendor-boringssl.sh @@ -187,6 +187,7 @@ echo "GENERATING assembly helpers" PATTERNS=( 'include/openssl/*.h' +'include/openssl/experimental/*.h' 'ssl/*.h' 'ssl/*.cc' 'crypto/*.h' @@ -269,13 +270,18 @@ echo "RENAMING header files" rmdir "include/openssl" # Now change the imports from " to "", apply the same prefix to the 'boringssl_prefix_symbols' headers. - find . -name "*.[ch]" -or -name "*.cc" -or -name "*.S" | xargs $sed -i -e 's+include /include "CCryptoBoringSSL_\1"/' + find . -name "*.h" | xargs $sed -i -e 's+include "\([[:alpha:]/]*/\)\{0,1\}+include "\1CCryptoBoringSSL_+' -e 's+include <\([[:alpha:]/]*/\)\{0,1\}CCryptoBoringSSL_\(.*\)>+include "\1CCryptoBoringSSL_\2"+' popd )