mirror of
https://github.com/apple/swift-crypto
synced 2026-11-22 04:30:39 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8dafe0fdce | ||
|
|
e2dd5a547b | ||
|
|
46072478ca | ||
|
|
c370ad81a1 | ||
|
|
33f65a3cbc | ||
|
|
fdfdc11707 | ||
|
|
a3866d45d9 | ||
|
|
5fb3819b51 | ||
|
|
3c060cc4af | ||
|
|
c36d19a064 | ||
|
|
bc1c29221f | ||
|
|
2adec617e6 | ||
|
|
89876ab72c | ||
|
|
f0525da24d | ||
|
|
52d0d9f15a | ||
|
|
9960a73340 | ||
|
|
606608da08 | ||
|
|
029eeacda4 |
No files matched your search
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>NSPrivacyTracking</key>
|
||||
<false/>
|
||||
<key>NSPrivacyAccessedAPITypes</key>
|
||||
<array/>
|
||||
<key>NSPrivacyCollectedDataTypes</key>
|
||||
<array/>
|
||||
<key>NSPrivacyTrackingDomains</key>
|
||||
<array/>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
+18
-3
@@ -1,4 +1,4 @@
|
||||
// swift-tools-version:5.7
|
||||
// swift-tools-version:5.8
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the SwiftCrypto open source project
|
||||
@@ -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
|
||||
|
||||
@@ -88,6 +88,9 @@ let package = Package(
|
||||
"crypto/bio/socket_helper.c",
|
||||
"crypto/bio/socket.c"
|
||||
],
|
||||
resources: [
|
||||
.copy("PrivacyInfo.xcprivacy"),
|
||||
],
|
||||
cSettings: [
|
||||
// These defines come from BoringSSL's build system
|
||||
.define("_HAS_EXCEPTIONS", to: "0", .when(platforms: [Platform.windows])),
|
||||
@@ -106,6 +109,9 @@ let package = Package(
|
||||
dependencies: ["CCryptoBoringSSL"],
|
||||
exclude: [
|
||||
"CMakeLists.txt"
|
||||
],
|
||||
resources: [
|
||||
.copy("PrivacyInfo.xcprivacy"),
|
||||
]
|
||||
),
|
||||
.target(
|
||||
@@ -118,7 +124,10 @@ let package = Package(
|
||||
"Key Agreement/ECDH.swift.gyb",
|
||||
"Signatures/ECDSA.swift.gyb",
|
||||
],
|
||||
swiftSettings: swiftSettings
|
||||
resources: [
|
||||
.copy("PrivacyInfo.xcprivacy"),
|
||||
],
|
||||
swiftSettings: swiftSettings + [.define("MODULE_IS_CRYPTO")]
|
||||
),
|
||||
.target(
|
||||
name: "_CryptoExtras",
|
||||
@@ -131,6 +140,9 @@ let package = Package(
|
||||
exclude: [
|
||||
"CMakeLists.txt",
|
||||
],
|
||||
resources: [
|
||||
.copy("PrivacyInfo.xcprivacy"),
|
||||
],
|
||||
swiftSettings: swiftSettings
|
||||
),
|
||||
.target(
|
||||
@@ -141,6 +153,9 @@ let package = Package(
|
||||
],
|
||||
exclude: [
|
||||
"CMakeLists.txt",
|
||||
],
|
||||
resources: [
|
||||
.copy("PrivacyInfo.xcprivacy"),
|
||||
]
|
||||
),
|
||||
.executableTarget(name: "crypto-shasum", dependencies: ["Crypto"]),
|
||||
|
||||
@@ -7,9 +7,9 @@ Swift Crypto is an open-source implementation of a substantial portion of the AP
|
||||
Swift Crypto is available as a Swift Package Manager package. To use it, add the following dependency in your `Package.swift`:
|
||||
|
||||
```swift
|
||||
// swift-crypto 1.x and 2.x are almost API compatible, so most clients should
|
||||
// allow either
|
||||
.package(url: "https://github.com/apple/swift-crypto.git", "1.0.0" ..< "3.0.0"),
|
||||
// swift-crypto 1.x, 2.x and 3.x are almost API compatible, so most clients
|
||||
// should allow any of them
|
||||
.package(url: "https://github.com/apple/swift-crypto.git", "1.0.0" ..< "4.0.0"),
|
||||
```
|
||||
|
||||
and to your target, add `Crypto` to your dependencies. You can then `import Crypto` to get access to Swift Crypto's functionality.
|
||||
@@ -116,7 +116,8 @@ Swift Crypto | Minimum Swift Version
|
||||
`2.1.0 ..< 2.2.0` | 5.4
|
||||
`2.2.0 ..< 2.4.2` | 5.5
|
||||
`2.4.2 ..< 3.1.0` | 5.6
|
||||
`3.1.0 ...` | 5.7
|
||||
`3.1.0 ..< 3.3.0` | 5.7
|
||||
`3.3.0 ...` | 5.8
|
||||
|
||||
### Compatibility
|
||||
|
||||
@@ -136,5 +137,5 @@ To do so, please use the following dependency in your `Package.swift`:
|
||||
|
||||
### Developing Swift Crypto on macOS
|
||||
|
||||
Swift Crypto normally defers to the OS implementation of CryptoKit on macOS. Naturally, this makes developing Swift Crypto on macOS tricky. To get Swift Crypto to build the open source implementation on macOS, in `Package.swift`, uncomment the line that reads: `//.define("CRYPTO_IN_SWIFTPM_FORCE_BUILD_API")`, as this will force Swift Crypto to build its public API.
|
||||
Swift Crypto normally defers to the OS implementation of CryptoKit on macOS. Naturally, this makes developing Swift Crypto on macOS tricky. To get Swift Crypto to build the open source implementation on macOS, in `Package.swift`, change `let development = false` to `let development = true`, as this will force Swift Crypto to build its public API.
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
../../.PrivacyInfo.xcprivacy
|
||||
@@ -58,7 +58,7 @@
|
||||
#include <CCryptoBoringSSL_bytestring.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_time.h>
|
||||
#include <CCryptoBoringSSL_posix_time.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
* [including the GNU Public Licence.] */
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
#include <CCryptoBoringSSL_time.h>
|
||||
#include <CCryptoBoringSSL_posix_time.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
#include <CCryptoBoringSSL_bytestring.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_time.h>
|
||||
#include <CCryptoBoringSSL_posix_time.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.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
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
// Time conversion to/from POSIX time_t and struct tm, with no support
|
||||
// for time zones other than UTC
|
||||
|
||||
#include <CCryptoBoringSSL_time.h>
|
||||
#include <CCryptoBoringSSL_posix_time.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <inttypes.h>
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -73,6 +73,7 @@
|
||||
|
||||
#include <CCryptoBoringSSL_bio.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@@ -82,6 +83,10 @@
|
||||
|
||||
#include "../internal.h"
|
||||
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
#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) {
|
||||
|
||||
@@ -18,13 +18,10 @@
|
||||
#include <string.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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__)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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],
|
||||
|
||||
@@ -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
|
||||
|
||||
+8
-6
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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));
|
||||
|
||||
|
||||
@@ -58,6 +58,7 @@
|
||||
#include <CCryptoBoringSSL_des.h>
|
||||
#include <CCryptoBoringSSL_nid.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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|.
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<<size);
|
||||
can be used to swap and move bits between words.
|
||||
|
||||
So l = 0 1 2 3 r = 16 17 18 19
|
||||
4 5 6 7 20 21 22 23
|
||||
8 9 10 11 24 25 26 27
|
||||
12 13 14 15 28 29 30 31
|
||||
becomes (for size == 2 and mask == 0x3333)
|
||||
t = 2^16 3^17 -- -- l = 0 1 16 17 r = 2 3 18 19
|
||||
6^20 7^21 -- -- 4 5 20 21 6 7 22 23
|
||||
10^24 11^25 -- -- 8 9 24 25 10 11 24 25
|
||||
14^28 15^29 -- -- 12 13 28 29 14 15 28 29
|
||||
|
||||
Thanks for hints from Richard Outerbridge - he told me IP&FP
|
||||
could be done in 15 xor, 10 shifts and 5 ands.
|
||||
When I finally started to think of the problem in 2D
|
||||
I first got ~42 operations without xors. When I remembered
|
||||
how to use xors :-) I got it to its final state.
|
||||
*/
|
||||
#define PERM_OP(a, b, t, n, m) \
|
||||
do { \
|
||||
(t) = ((((a) >> (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
|
||||
@@ -58,6 +58,7 @@
|
||||
#define OPENSSL_HEADER_DES_INTERNAL_H
|
||||
|
||||
#include <CCryptoBoringSSL_base.h>
|
||||
#include <CCryptoBoringSSL_des.h>
|
||||
|
||||
#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<<size);
|
||||
can be used to swap and move bits between words.
|
||||
void DES_set_key_ex(const uint8_t key[8], DES_key_schedule *schedule);
|
||||
void DES_ecb_encrypt_ex(const uint8_t in[8], uint8_t out[8],
|
||||
const DES_key_schedule *schedule, int is_encrypt);
|
||||
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);
|
||||
void DES_ecb3_encrypt_ex(const uint8_t input[8], uint8_t output[8],
|
||||
const DES_key_schedule *ks1,
|
||||
const DES_key_schedule *ks2,
|
||||
const DES_key_schedule *ks3, int 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);
|
||||
|
||||
So l = 0 1 2 3 r = 16 17 18 19
|
||||
4 5 6 7 20 21 22 23
|
||||
8 9 10 11 24 25 26 27
|
||||
12 13 14 15 28 29 30 31
|
||||
becomes (for size == 2 and mask == 0x3333)
|
||||
t = 2^16 3^17 -- -- l = 0 1 16 17 r = 2 3 18 19
|
||||
6^20 7^21 -- -- 4 5 20 21 6 7 22 23
|
||||
10^24 11^25 -- -- 8 9 24 25 10 11 24 25
|
||||
14^28 15^29 -- -- 12 13 28 29 14 15 28 29
|
||||
|
||||
Thanks for hints from Richard Outerbridge - he told me IP&FP
|
||||
could be done in 15 xor, 10 shifts and 5 ands.
|
||||
When I finally started to think of the problem in 2D
|
||||
I first got ~42 operations without xors. When I remembered
|
||||
how to use xors :-) I got it to its final state.
|
||||
*/
|
||||
#define PERM_OP(a, b, t, n, m) \
|
||||
do { \
|
||||
(t) = ((((a) >> (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)
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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__)
|
||||
|
||||
@@ -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__)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -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__)
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
#define OPENSSL_HEADER_CRYPTO_KYBER_INTERNAL_H
|
||||
|
||||
#include <CCryptoBoringSSL_base.h>
|
||||
#include <CCryptoBoringSSL_kyber.h>
|
||||
#include <experimental/CCryptoBoringSSL_kyber.h>
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "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 <CCryptoBoringSSL_kyber.h>
|
||||
#include <experimental/CCryptoBoringSSL_kyber.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -65,10 +65,10 @@
|
||||
#include <CCryptoBoringSSL_x509.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,11 +16,11 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <experimental/CCryptoBoringSSL_spx.h>
|
||||
#include <CCryptoBoringSSL_rand.h>
|
||||
|
||||
#include "./address.h"
|
||||
#include "./fors.h"
|
||||
#include "./internal.h"
|
||||
#include "./merkle.h"
|
||||
#include "./params.h"
|
||||
#include "./spx_util.h"
|
||||
|
||||
@@ -56,8 +56,6 @@
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <CCryptoBoringSSL_buf.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -59,6 +59,7 @@
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_obj.h>
|
||||
#include <CCryptoBoringSSL_x509.h>
|
||||
#include <CCryptoBoringSSL_x509v3.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -54,8 +54,6 @@
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com). */
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <CCryptoBoringSSL_digest.h>
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -63,6 +63,7 @@
|
||||
#include <CCryptoBoringSSL_stack.h>
|
||||
#include <CCryptoBoringSSL_thread.h>
|
||||
#include <CCryptoBoringSSL_x509.h>
|
||||
#include <CCryptoBoringSSL_x509v3.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Vendored
+1
-1
@@ -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
|
||||
@@ -31,7 +31,6 @@
|
||||
#include "CCryptoBoringSSL_cpu.h"
|
||||
#include "CCryptoBoringSSL_curve25519.h"
|
||||
#include "CCryptoBoringSSL_des.h"
|
||||
#include "CCryptoBoringSSL_dtls1.h"
|
||||
#include "CCryptoBoringSSL_e_os2.h"
|
||||
#include "CCryptoBoringSSL_ec.h"
|
||||
#include "CCryptoBoringSSL_ec_key.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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Loaded 100 of 157 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user