mirror of
https://github.com/apple/swift-crypto
synced 2026-11-22 04:30:39 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cc76b89416 | ||
|
|
3e8497753e | ||
|
|
c1825df19b | ||
|
|
09f7a993f6 | ||
|
|
ed66091040 | ||
|
|
b793a1e564 | ||
|
|
f4b21dbde7 | ||
|
|
3df7fa0626 | ||
|
|
7644bdcc76 | ||
|
|
fade397763 | ||
|
|
c4f2e9938a | ||
|
|
b51f1d6845 | ||
|
|
faad1cf4fd | ||
|
|
629f0b679d | ||
|
|
953b34a601 | ||
|
|
710deacf79 | ||
|
|
a234f8a62e | ||
|
|
9c1b699540 | ||
|
|
5ac5632286 | ||
|
|
cba358dec9 | ||
|
|
c433cd3341 |
No files matched your search
@@ -15,3 +15,4 @@ DerivedData
|
||||
|
||||
.*.sw[nop]
|
||||
|
||||
.vscode
|
||||
+21
-13
@@ -1,4 +1,4 @@
|
||||
// swift-tools-version:5.6
|
||||
// swift-tools-version:5.7
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// 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: abfd5ebc87ddca0fab9fca067c9d7edbc355eae8
|
||||
// BoringSSL Commit: 7a813621dac6878ab53b6ed7392939a8982226e8
|
||||
|
||||
import PackageDescription
|
||||
|
||||
@@ -40,15 +40,16 @@ if development {
|
||||
"CryptoBoringWrapper"
|
||||
]
|
||||
} else {
|
||||
swiftSettings = [
|
||||
.define("CRYPTO_IN_SWIFTPM"),
|
||||
]
|
||||
let platforms: [Platform] = [
|
||||
Platform.linux,
|
||||
Platform.android,
|
||||
Platform.windows,
|
||||
Platform.wasi,
|
||||
]
|
||||
swiftSettings = [
|
||||
.define("CRYPTO_IN_SWIFTPM"),
|
||||
.define("CRYPTO_IN_SWIFTPM_FORCE_BUILD_API", .when(platforms: platforms)),
|
||||
]
|
||||
dependencies = [
|
||||
.target(name: "CCryptoBoringSSL", condition: .when(platforms: platforms)),
|
||||
.target(name: "CCryptoBoringSSLShims", condition: .when(platforms: platforms)),
|
||||
@@ -88,12 +89,11 @@ let package = Package(
|
||||
"crypto/bio/socket.c"
|
||||
],
|
||||
cSettings: [
|
||||
/*
|
||||
* This define is required on Windows, but because we need older
|
||||
* versions of SPM, we cannot conditionally define this on Windows
|
||||
* only. Unconditionally define it instead.
|
||||
*/
|
||||
.define("WIN32_LEAN_AND_MEAN"),
|
||||
// These defines come from BoringSSL's build system
|
||||
.define("_HAS_EXCEPTIONS", to: "0", .when(platforms: [Platform.windows])),
|
||||
.define("WIN32_LEAN_AND_MEAN", .when(platforms: [Platform.windows])),
|
||||
.define("NOMINMAX", .when(platforms: [Platform.windows])),
|
||||
.define("_CRT_SECURE_NO_WARNINGS", .when(platforms: [Platform.windows])),
|
||||
/*
|
||||
* These defines are required on Wasm/WASI, to disable use of pthread.
|
||||
*/
|
||||
@@ -130,7 +130,8 @@ let package = Package(
|
||||
],
|
||||
exclude: [
|
||||
"CMakeLists.txt",
|
||||
]
|
||||
],
|
||||
swiftSettings: swiftSettings
|
||||
),
|
||||
.target(
|
||||
name: "CryptoBoringWrapper",
|
||||
@@ -143,7 +144,14 @@ let package = Package(
|
||||
]
|
||||
),
|
||||
.executableTarget(name: "crypto-shasum", dependencies: ["Crypto"]),
|
||||
.testTarget(name: "CryptoTests", dependencies: ["Crypto"], swiftSettings: swiftSettings),
|
||||
.testTarget(
|
||||
name: "CryptoTests",
|
||||
dependencies: ["Crypto"],
|
||||
resources: [
|
||||
.copy("HPKE/hpke-test-vectors.json"),
|
||||
],
|
||||
swiftSettings: swiftSettings
|
||||
),
|
||||
.testTarget(name: "_CryptoExtrasTests", dependencies: ["_CryptoExtras"]),
|
||||
],
|
||||
cxxLanguageStandard: .cxx11
|
||||
|
||||
@@ -108,14 +108,15 @@ If you believe you have identified a vulnerability in Swift Crypto, please [repo
|
||||
|
||||
### Swift versions
|
||||
|
||||
The most recent versions of Swift Crypto support Swift 5.6 and newer. The minimum Swift version supported by Swift Crypto releases are detailed below:
|
||||
The most recent versions of Swift Crypto support Swift 5.7 and newer. The minimum Swift version supported by Swift Crypto releases are detailed below:
|
||||
|
||||
Swift Crypto | Minimum Swift Version
|
||||
------------------|----------------------
|
||||
`2.0.0 ..< 2.1.0` | 5.2
|
||||
`2.1.0 ..< 2.2.0` | 5.4
|
||||
`2.2.0 ..< 2.4.2` | 5.5
|
||||
`2.4.2 ...` | 5.6
|
||||
`2.4.2 ..< 3.1.0` | 5.6
|
||||
`3.1.0 ...` | 5.7
|
||||
|
||||
### Compatibility
|
||||
|
||||
|
||||
+41
-33
@@ -44,6 +44,7 @@ add_library(CCryptoBoringSSL STATIC
|
||||
"crypto/bio/bio.c"
|
||||
"crypto/bio/bio_mem.c"
|
||||
"crypto/bio/connect.c"
|
||||
"crypto/bio/errno.c"
|
||||
"crypto/bio/fd.c"
|
||||
"crypto/bio/file.c"
|
||||
"crypto/bio/hexdump.c"
|
||||
@@ -74,16 +75,17 @@ add_library(CCryptoBoringSSL STATIC
|
||||
"crypto/cipher_extra/tls_cbc.c"
|
||||
"crypto/conf/conf.c"
|
||||
"crypto/cpu_aarch64_apple.c"
|
||||
"crypto/cpu_aarch64_freebsd.c"
|
||||
"crypto/cpu_aarch64_fuchsia.c"
|
||||
"crypto/cpu_aarch64_linux.c"
|
||||
"crypto/cpu_aarch64_openbsd.c"
|
||||
"crypto/cpu_aarch64_sysreg.c"
|
||||
"crypto/cpu_aarch64_win.c"
|
||||
"crypto/cpu_arm.c"
|
||||
"crypto/cpu_arm_freebsd.c"
|
||||
"crypto/cpu_arm_linux.c"
|
||||
"crypto/cpu_intel.c"
|
||||
"crypto/crypto.c"
|
||||
"crypto/curve25519/curve25519.c"
|
||||
"crypto/curve25519/curve25519_64_adx.c"
|
||||
"crypto/curve25519/spake25519.c"
|
||||
"crypto/des/des.c"
|
||||
"crypto/dh_extra/dh_asn1.c"
|
||||
@@ -168,6 +170,7 @@ add_library(CCryptoBoringSSL STATIC
|
||||
"crypto/fipsmodule/ecdh/ecdh.c"
|
||||
"crypto/fipsmodule/ecdsa/ecdsa.c"
|
||||
"crypto/fipsmodule/fips_shared_support.c"
|
||||
"crypto/fipsmodule/hkdf/hkdf.c"
|
||||
"crypto/fipsmodule/hmac/hmac.c"
|
||||
"crypto/fipsmodule/md4/md4.c"
|
||||
"crypto/fipsmodule/md5/md5.c"
|
||||
@@ -193,10 +196,9 @@ add_library(CCryptoBoringSSL STATIC
|
||||
"crypto/fipsmodule/sha/sha256.c"
|
||||
"crypto/fipsmodule/sha/sha512.c"
|
||||
"crypto/fipsmodule/tls/kdf.c"
|
||||
"crypto/hkdf/hkdf.c"
|
||||
"crypto/hpke/hpke.c"
|
||||
"crypto/hrss/hrss.c"
|
||||
"crypto/kyber/keccak.c"
|
||||
"crypto/keccak/keccak.c"
|
||||
"crypto/kyber/kyber.c"
|
||||
"crypto/lhash/lhash.c"
|
||||
"crypto/mem.c"
|
||||
@@ -221,17 +223,25 @@ add_library(CCryptoBoringSSL STATIC
|
||||
"crypto/pool/pool.c"
|
||||
"crypto/rand_extra/deterministic.c"
|
||||
"crypto/rand_extra/forkunsafe.c"
|
||||
"crypto/rand_extra/fuchsia.c"
|
||||
"crypto/rand_extra/getentropy.c"
|
||||
"crypto/rand_extra/ios.c"
|
||||
"crypto/rand_extra/passive.c"
|
||||
"crypto/rand_extra/rand_extra.c"
|
||||
"crypto/rand_extra/trusty.c"
|
||||
"crypto/rand_extra/windows.c"
|
||||
"crypto/rc4/rc4.c"
|
||||
"crypto/refcount_c11.c"
|
||||
"crypto/refcount_lock.c"
|
||||
"crypto/refcount.c"
|
||||
"crypto/rsa_extra/rsa_asn1.c"
|
||||
"crypto/rsa_extra/rsa_crypt.c"
|
||||
"crypto/rsa_extra/rsa_print.c"
|
||||
"crypto/siphash/siphash.c"
|
||||
"crypto/spx/address.c"
|
||||
"crypto/spx/fors.c"
|
||||
"crypto/spx/merkle.c"
|
||||
"crypto/spx/spx.c"
|
||||
"crypto/spx/spx_util.c"
|
||||
"crypto/spx/thash.c"
|
||||
"crypto/spx/wots.c"
|
||||
"crypto/stack/stack.c"
|
||||
"crypto/thread.c"
|
||||
"crypto/thread_none.c"
|
||||
@@ -255,6 +265,29 @@ add_library(CCryptoBoringSSL STATIC
|
||||
"crypto/x509/t_req.c"
|
||||
"crypto/x509/t_x509.c"
|
||||
"crypto/x509/t_x509a.c"
|
||||
"crypto/x509/v3_akey.c"
|
||||
"crypto/x509/v3_akeya.c"
|
||||
"crypto/x509/v3_alt.c"
|
||||
"crypto/x509/v3_bcons.c"
|
||||
"crypto/x509/v3_bitst.c"
|
||||
"crypto/x509/v3_conf.c"
|
||||
"crypto/x509/v3_cpols.c"
|
||||
"crypto/x509/v3_crld.c"
|
||||
"crypto/x509/v3_enum.c"
|
||||
"crypto/x509/v3_extku.c"
|
||||
"crypto/x509/v3_genn.c"
|
||||
"crypto/x509/v3_ia5.c"
|
||||
"crypto/x509/v3_info.c"
|
||||
"crypto/x509/v3_int.c"
|
||||
"crypto/x509/v3_lib.c"
|
||||
"crypto/x509/v3_ncons.c"
|
||||
"crypto/x509/v3_ocsp.c"
|
||||
"crypto/x509/v3_pcons.c"
|
||||
"crypto/x509/v3_pmaps.c"
|
||||
"crypto/x509/v3_prn.c"
|
||||
"crypto/x509/v3_purp.c"
|
||||
"crypto/x509/v3_skey.c"
|
||||
"crypto/x509/v3_utl.c"
|
||||
"crypto/x509/x509.c"
|
||||
"crypto/x509/x509_att.c"
|
||||
"crypto/x509/x509_cmp.c"
|
||||
@@ -279,39 +312,14 @@ add_library(CCryptoBoringSSL STATIC
|
||||
"crypto/x509/x_attrib.c"
|
||||
"crypto/x509/x_crl.c"
|
||||
"crypto/x509/x_exten.c"
|
||||
"crypto/x509/x_info.c"
|
||||
"crypto/x509/x_name.c"
|
||||
"crypto/x509/x_pkey.c"
|
||||
"crypto/x509/x_pubkey.c"
|
||||
"crypto/x509/x_req.c"
|
||||
"crypto/x509/x_sig.c"
|
||||
"crypto/x509/x_spki.c"
|
||||
"crypto/x509/x_val.c"
|
||||
"crypto/x509/x_x509.c"
|
||||
"crypto/x509/x_x509a.c"
|
||||
"crypto/x509v3/v3_akey.c"
|
||||
"crypto/x509v3/v3_akeya.c"
|
||||
"crypto/x509v3/v3_alt.c"
|
||||
"crypto/x509v3/v3_bcons.c"
|
||||
"crypto/x509v3/v3_bitst.c"
|
||||
"crypto/x509v3/v3_conf.c"
|
||||
"crypto/x509v3/v3_cpols.c"
|
||||
"crypto/x509v3/v3_crld.c"
|
||||
"crypto/x509v3/v3_enum.c"
|
||||
"crypto/x509v3/v3_extku.c"
|
||||
"crypto/x509v3/v3_genn.c"
|
||||
"crypto/x509v3/v3_ia5.c"
|
||||
"crypto/x509v3/v3_info.c"
|
||||
"crypto/x509v3/v3_int.c"
|
||||
"crypto/x509v3/v3_lib.c"
|
||||
"crypto/x509v3/v3_ncons.c"
|
||||
"crypto/x509v3/v3_ocsp.c"
|
||||
"crypto/x509v3/v3_pcons.c"
|
||||
"crypto/x509v3/v3_pmaps.c"
|
||||
"crypto/x509v3/v3_prn.c"
|
||||
"crypto/x509v3/v3_purp.c"
|
||||
"crypto/x509v3/v3_skey.c"
|
||||
"crypto/x509v3/v3_utl.c")
|
||||
"crypto/x509/x_x509a.c")
|
||||
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL Darwin AND CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x86_64")
|
||||
target_sources(CCryptoBoringSSL PRIVATE
|
||||
|
||||
@@ -60,6 +60,7 @@
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_time.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
@@ -123,9 +124,12 @@ ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_adj(ASN1_GENERALIZEDTIME *s,
|
||||
}
|
||||
|
||||
char buf[16];
|
||||
BIO_snprintf(buf, sizeof(buf), "%04d%02d%02d%02d%02d%02dZ",
|
||||
data.tm_year + 1900, data.tm_mon + 1, data.tm_mday, data.tm_hour,
|
||||
data.tm_min, data.tm_sec);
|
||||
int ret = snprintf(buf, sizeof(buf), "%04d%02d%02d%02d%02d%02dZ",
|
||||
data.tm_year + 1900, data.tm_mon + 1, data.tm_mday,
|
||||
data.tm_hour, data.tm_min, data.tm_sec);
|
||||
if (ret != (int)(sizeof(buf) - 1)) {
|
||||
abort(); // |snprintf| should neither truncate nor write fewer bytes.
|
||||
}
|
||||
|
||||
int free_s = 0;
|
||||
if (s == NULL) {
|
||||
|
||||
@@ -73,18 +73,19 @@
|
||||
// horrible: it has to be :-( The 'ncopy' form checks minimum and maximum
|
||||
// size limits too.
|
||||
|
||||
int ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in, int len,
|
||||
int inform, unsigned long mask) {
|
||||
return ASN1_mbstring_ncopy(out, in, len, inform, mask, 0, 0);
|
||||
int ASN1_mbstring_copy(ASN1_STRING **out, const unsigned char *in,
|
||||
ossl_ssize_t len, int inform, unsigned long mask) {
|
||||
return ASN1_mbstring_ncopy(out, in, len, inform, mask, /*minsize=*/0,
|
||||
/*maxsize=*/0);
|
||||
}
|
||||
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, INVALID_BMPSTRING)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, INVALID_UNIVERSALSTRING)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, INVALID_UTF8STRING)
|
||||
|
||||
int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
|
||||
int inform, unsigned long mask, long minsize,
|
||||
long maxsize) {
|
||||
int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in,
|
||||
ossl_ssize_t len, int inform, unsigned long mask,
|
||||
ossl_ssize_t minsize, ossl_ssize_t maxsize) {
|
||||
if (len == -1) {
|
||||
len = strlen((const char *)in);
|
||||
}
|
||||
@@ -96,22 +97,22 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
|
||||
int error;
|
||||
switch (inform) {
|
||||
case MBSTRING_BMP:
|
||||
decode_func = cbs_get_ucs2_be;
|
||||
decode_func = CBS_get_ucs2_be;
|
||||
error = ASN1_R_INVALID_BMPSTRING;
|
||||
break;
|
||||
|
||||
case MBSTRING_UNIV:
|
||||
decode_func = cbs_get_utf32_be;
|
||||
decode_func = CBS_get_utf32_be;
|
||||
error = ASN1_R_INVALID_UNIVERSALSTRING;
|
||||
break;
|
||||
|
||||
case MBSTRING_UTF8:
|
||||
decode_func = cbs_get_utf8;
|
||||
decode_func = CBS_get_utf8;
|
||||
error = ASN1_R_INVALID_UTF8STRING;
|
||||
break;
|
||||
|
||||
case MBSTRING_ASC:
|
||||
decode_func = cbs_get_latin1;
|
||||
decode_func = CBS_get_latin1;
|
||||
error = ERR_R_INTERNAL_ERROR; // Latin-1 inputs are never invalid.
|
||||
break;
|
||||
|
||||
@@ -161,23 +162,23 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
|
||||
}
|
||||
|
||||
nchar++;
|
||||
utf8_len += cbb_get_utf8_len(c);
|
||||
utf8_len += CBB_get_utf8_len(c);
|
||||
if (maxsize > 0 && nchar > (size_t)maxsize) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_STRING_TOO_LONG);
|
||||
ERR_add_error_dataf("maxsize=%ld", maxsize);
|
||||
ERR_add_error_dataf("maxsize=%zu", (size_t)maxsize);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (minsize > 0 && nchar < (size_t)minsize) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_STRING_TOO_SHORT);
|
||||
ERR_add_error_dataf("minsize=%ld", minsize);
|
||||
ERR_add_error_dataf("minsize=%zu", (size_t)minsize);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Now work out output format and string type
|
||||
int str_type;
|
||||
int (*encode_func)(CBB *, uint32_t) = cbb_add_latin1;
|
||||
int (*encode_func)(CBB *, uint32_t) = CBB_add_latin1;
|
||||
size_t size_estimate = nchar;
|
||||
int outform = MBSTRING_ASC;
|
||||
if (mask & B_ASN1_PRINTABLESTRING) {
|
||||
@@ -189,17 +190,17 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
|
||||
} else if (mask & B_ASN1_BMPSTRING) {
|
||||
str_type = V_ASN1_BMPSTRING;
|
||||
outform = MBSTRING_BMP;
|
||||
encode_func = cbb_add_ucs2_be;
|
||||
encode_func = CBB_add_ucs2_be;
|
||||
size_estimate = 2 * nchar;
|
||||
} else if (mask & B_ASN1_UNIVERSALSTRING) {
|
||||
str_type = V_ASN1_UNIVERSALSTRING;
|
||||
encode_func = cbb_add_utf32_be;
|
||||
encode_func = CBB_add_utf32_be;
|
||||
size_estimate = 4 * nchar;
|
||||
outform = MBSTRING_UNIV;
|
||||
} else if (mask & B_ASN1_UTF8STRING) {
|
||||
str_type = V_ASN1_UTF8STRING;
|
||||
outform = MBSTRING_UTF8;
|
||||
encode_func = cbb_add_utf8;
|
||||
encode_func = CBB_add_utf8;
|
||||
size_estimate = utf8_len;
|
||||
} else {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_ILLEGAL_CHARACTERS);
|
||||
|
||||
@@ -68,6 +68,7 @@
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
#include "../bytestring/internal.h"
|
||||
#include "../internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
@@ -89,18 +90,18 @@ static int do_esc_char(uint32_t c, unsigned long flags, char *do_quotes,
|
||||
char buf[16]; // Large enough for "\\W01234567".
|
||||
unsigned char u8 = (unsigned char)c;
|
||||
if (c > 0xffff) {
|
||||
BIO_snprintf(buf, sizeof(buf), "\\W%08" PRIX32, c);
|
||||
snprintf(buf, sizeof(buf), "\\W%08" PRIX32, c);
|
||||
} else if (c > 0xff) {
|
||||
BIO_snprintf(buf, sizeof(buf), "\\U%04" PRIX32, c);
|
||||
snprintf(buf, sizeof(buf), "\\U%04" PRIX32, c);
|
||||
} else if ((flags & ASN1_STRFLGS_ESC_MSB) && c > 0x7f) {
|
||||
BIO_snprintf(buf, sizeof(buf), "\\%02X", c);
|
||||
snprintf(buf, sizeof(buf), "\\%02X", c);
|
||||
} else if ((flags & ASN1_STRFLGS_ESC_CTRL) && is_control_character(c)) {
|
||||
BIO_snprintf(buf, sizeof(buf), "\\%02X", c);
|
||||
snprintf(buf, sizeof(buf), "\\%02X", c);
|
||||
} else if (flags & ASN1_STRFLGS_ESC_2253) {
|
||||
// See RFC 2253, sections 2.4 and 4.
|
||||
if (c == '\\' || c == '"') {
|
||||
// Quotes and backslashes are always escaped, quoted or not.
|
||||
BIO_snprintf(buf, sizeof(buf), "\\%c", (int)c);
|
||||
snprintf(buf, sizeof(buf), "\\%c", (int)c);
|
||||
} else if (c == ',' || c == '+' || c == '<' || c == '>' || c == ';' ||
|
||||
(is_first && (c == ' ' || c == '#')) ||
|
||||
(is_last && (c == ' '))) {
|
||||
@@ -111,13 +112,13 @@ static int do_esc_char(uint32_t c, unsigned long flags, char *do_quotes,
|
||||
}
|
||||
return maybe_write(out, &u8, 1) ? 1 : -1;
|
||||
}
|
||||
BIO_snprintf(buf, sizeof(buf), "\\%c", (int)c);
|
||||
snprintf(buf, sizeof(buf), "\\%c", (int)c);
|
||||
} else {
|
||||
return maybe_write(out, &u8, 1) ? 1 : -1;
|
||||
}
|
||||
} else if ((flags & ESC_FLAGS) && c == '\\') {
|
||||
// If any escape flags are set, also escape backslashes.
|
||||
BIO_snprintf(buf, sizeof(buf), "\\%c", (int)c);
|
||||
snprintf(buf, sizeof(buf), "\\%c", (int)c);
|
||||
} else {
|
||||
return maybe_write(out, &u8, 1) ? 1 : -1;
|
||||
}
|
||||
@@ -137,19 +138,19 @@ static int do_buf(const unsigned char *buf, int buflen, int encoding,
|
||||
int get_char_error;
|
||||
switch (encoding) {
|
||||
case MBSTRING_UNIV:
|
||||
get_char = cbs_get_utf32_be;
|
||||
get_char = CBS_get_utf32_be;
|
||||
get_char_error = ASN1_R_INVALID_UNIVERSALSTRING;
|
||||
break;
|
||||
case MBSTRING_BMP:
|
||||
get_char = cbs_get_ucs2_be;
|
||||
get_char = CBS_get_ucs2_be;
|
||||
get_char_error = ASN1_R_INVALID_BMPSTRING;
|
||||
break;
|
||||
case MBSTRING_ASC:
|
||||
get_char = cbs_get_latin1;
|
||||
get_char = CBS_get_latin1;
|
||||
get_char_error = ERR_R_INTERNAL_ERROR; // Should not be possible.
|
||||
break;
|
||||
case MBSTRING_UTF8:
|
||||
get_char = cbs_get_utf8;
|
||||
get_char = CBS_get_utf8;
|
||||
get_char_error = ASN1_R_INVALID_UTF8STRING;
|
||||
break;
|
||||
default:
|
||||
@@ -172,7 +173,7 @@ static int do_buf(const unsigned char *buf, int buflen, int encoding,
|
||||
uint8_t utf8_buf[6];
|
||||
CBB utf8_cbb;
|
||||
CBB_init_fixed(&utf8_cbb, utf8_buf, sizeof(utf8_buf));
|
||||
if (!cbb_add_utf8(&utf8_cbb, c)) {
|
||||
if (!CBB_add_utf8(&utf8_cbb, c)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_INTERNAL_ERROR);
|
||||
return 1;
|
||||
}
|
||||
@@ -238,22 +239,8 @@ static int do_dump(unsigned long flags, BIO *out, const ASN1_STRING *str) {
|
||||
// Placing the ASN1_STRING in a temporary ASN1_TYPE allows the DER encoding
|
||||
// to readily obtained.
|
||||
ASN1_TYPE t;
|
||||
t.type = str->type;
|
||||
// Negative INTEGER and ENUMERATED values are the only case where
|
||||
// |ASN1_STRING| and |ASN1_TYPE| types do not match.
|
||||
//
|
||||
// TODO(davidben): There are also some type fields which, in |ASN1_TYPE|, do
|
||||
// not correspond to |ASN1_STRING|. It is unclear whether those are allowed
|
||||
// in |ASN1_STRING| at all, or what the space of allowed types is.
|
||||
// |ASN1_item_ex_d2i| will never produce such a value so, for now, we say
|
||||
// this is an invalid input. But this corner of the library in general
|
||||
// should be more robust.
|
||||
if (t.type == V_ASN1_NEG_INTEGER) {
|
||||
t.type = V_ASN1_INTEGER;
|
||||
} else if (t.type == V_ASN1_NEG_ENUMERATED) {
|
||||
t.type = V_ASN1_ENUMERATED;
|
||||
}
|
||||
t.value.asn1_string = (ASN1_STRING *)str;
|
||||
OPENSSL_memset(&t, 0, sizeof(ASN1_TYPE));
|
||||
asn1_type_set0_string(&t, (ASN1_STRING *)str);
|
||||
unsigned char *der_buf = NULL;
|
||||
int der_len = i2d_ASN1_TYPE(&t, &der_buf);
|
||||
if (der_len < 0) {
|
||||
|
||||
@@ -72,7 +72,7 @@
|
||||
DEFINE_LHASH_OF(ASN1_STRING_TABLE)
|
||||
|
||||
static LHASH_OF(ASN1_STRING_TABLE) *string_tables = NULL;
|
||||
static struct CRYPTO_STATIC_MUTEX string_tables_lock = CRYPTO_STATIC_MUTEX_INIT;
|
||||
static CRYPTO_MUTEX string_tables_lock = CRYPTO_MUTEX_INIT;
|
||||
|
||||
void ASN1_STRING_set_default_mask(unsigned long mask) {}
|
||||
|
||||
@@ -87,7 +87,7 @@ static const ASN1_STRING_TABLE *asn1_string_table_get(int nid);
|
||||
// a corresponding OID. For example certificates and certificate requests.
|
||||
|
||||
ASN1_STRING *ASN1_STRING_set_by_NID(ASN1_STRING **out, const unsigned char *in,
|
||||
int len, int inform, int nid) {
|
||||
ossl_ssize_t len, int inform, int nid) {
|
||||
ASN1_STRING *str = NULL;
|
||||
int ret;
|
||||
if (!out) {
|
||||
@@ -176,11 +176,11 @@ static const ASN1_STRING_TABLE *asn1_string_table_get(int nid) {
|
||||
return tbl;
|
||||
}
|
||||
|
||||
CRYPTO_STATIC_MUTEX_lock_read(&string_tables_lock);
|
||||
CRYPTO_MUTEX_lock_read(&string_tables_lock);
|
||||
if (string_tables != NULL) {
|
||||
tbl = lh_ASN1_STRING_TABLE_retrieve(string_tables, &key);
|
||||
}
|
||||
CRYPTO_STATIC_MUTEX_unlock_read(&string_tables_lock);
|
||||
CRYPTO_MUTEX_unlock_read(&string_tables_lock);
|
||||
// Note returning |tbl| without the lock is only safe because
|
||||
// |ASN1_STRING_TABLE_add| cannot modify or delete existing entries. If we
|
||||
// wish to support that, this function must copy the result under a lock.
|
||||
@@ -196,7 +196,7 @@ int ASN1_STRING_TABLE_add(int nid, long minsize, long maxsize,
|
||||
}
|
||||
|
||||
int ret = 0;
|
||||
CRYPTO_STATIC_MUTEX_lock_write(&string_tables_lock);
|
||||
CRYPTO_MUTEX_lock_write(&string_tables_lock);
|
||||
|
||||
if (string_tables == NULL) {
|
||||
string_tables = lh_ASN1_STRING_TABLE_new(table_hash, table_cmp);
|
||||
@@ -232,7 +232,7 @@ int ASN1_STRING_TABLE_add(int nid, long minsize, long maxsize,
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
CRYPTO_STATIC_MUTEX_unlock_write(&string_tables_lock);
|
||||
CRYPTO_MUTEX_unlock_write(&string_tables_lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
#include <time.h>
|
||||
|
||||
#include <CCryptoBoringSSL_asn1t.h>
|
||||
#include <CCryptoBoringSSL_bytestring.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
@@ -82,6 +83,10 @@ ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s, time_t time) {
|
||||
return ASN1_TIME_adj(s, time, 0, 0);
|
||||
}
|
||||
|
||||
static int fits_in_utc_time(const struct tm *tm) {
|
||||
return 50 <= tm->tm_year && tm->tm_year < 150;
|
||||
}
|
||||
|
||||
ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, int64_t posix_time, int offset_day,
|
||||
long offset_sec) {
|
||||
struct tm tm;
|
||||
@@ -95,7 +100,7 @@ ASN1_TIME *ASN1_TIME_adj(ASN1_TIME *s, int64_t posix_time, int offset_day,
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
if ((tm.tm_year >= 50) && (tm.tm_year < 150)) {
|
||||
if (fits_in_utc_time(&tm)) {
|
||||
return ASN1_UTCTIME_adj(s, posix_time, offset_day, offset_sec);
|
||||
}
|
||||
return ASN1_GENERALIZEDTIME_adj(s, posix_time, offset_day, offset_sec);
|
||||
@@ -171,6 +176,34 @@ int ASN1_TIME_set_string(ASN1_TIME *s, const char *str) {
|
||||
ASN1_GENERALIZEDTIME_set_string(s, str);
|
||||
}
|
||||
|
||||
int ASN1_TIME_set_string_X509(ASN1_TIME *s, const char *str) {
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, (const uint8_t*)str, strlen(str));
|
||||
int type;
|
||||
struct tm tm;
|
||||
if (CBS_parse_utc_time(&cbs, /*out_tm=*/NULL,
|
||||
/*allow_timezone_offset=*/0)) {
|
||||
type = V_ASN1_UTCTIME;
|
||||
} else if (CBS_parse_generalized_time(&cbs, &tm,
|
||||
/*allow_timezone_offset=*/0)) {
|
||||
type = V_ASN1_GENERALIZEDTIME;
|
||||
if (fits_in_utc_time(&tm)) {
|
||||
type = V_ASN1_UTCTIME;
|
||||
CBS_skip(&cbs, 2);
|
||||
}
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (s != NULL) {
|
||||
if (!ASN1_STRING_set(s, CBS_data(&cbs), CBS_len(&cbs))) {
|
||||
return 0;
|
||||
}
|
||||
s->type = type;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int asn1_time_to_tm(struct tm *tm, const ASN1_TIME *t,
|
||||
int allow_timezone_offset) {
|
||||
if (t == NULL) {
|
||||
|
||||
@@ -56,7 +56,8 @@
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
|
||||
#include <CCryptoBoringSSL_asn1t.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_obj.h>
|
||||
@@ -89,6 +90,23 @@ const void *asn1_type_value_as_pointer(const ASN1_TYPE *a) {
|
||||
}
|
||||
}
|
||||
|
||||
void asn1_type_set0_string(ASN1_TYPE *a, ASN1_STRING *str) {
|
||||
// |ASN1_STRING| types are almost the same as |ASN1_TYPE| types, except that
|
||||
// the negative flag is not reflected into |ASN1_TYPE|.
|
||||
int type = str->type;
|
||||
if (type == V_ASN1_NEG_INTEGER) {
|
||||
type = V_ASN1_INTEGER;
|
||||
} else if (type == V_ASN1_NEG_ENUMERATED) {
|
||||
type = V_ASN1_ENUMERATED;
|
||||
}
|
||||
|
||||
// These types are not |ASN1_STRING| types and use a different
|
||||
// representation when stored in |ASN1_TYPE|.
|
||||
assert(type != V_ASN1_NULL && type != V_ASN1_OBJECT &&
|
||||
type != V_ASN1_BOOLEAN);
|
||||
ASN1_TYPE_set(a, type, str);
|
||||
}
|
||||
|
||||
void asn1_type_cleanup(ASN1_TYPE *a) {
|
||||
switch (a->type) {
|
||||
case V_ASN1_NULL:
|
||||
|
||||
@@ -60,6 +60,7 @@
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_time.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
@@ -83,11 +84,14 @@ int ASN1_UTCTIME_check(const ASN1_UTCTIME *d) {
|
||||
}
|
||||
|
||||
int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str) {
|
||||
// Although elsewhere we allow timezone offsets with UTCTime, to be compatible
|
||||
// with some existing misissued certificates, this function is used to
|
||||
// construct new certificates and can be stricter.
|
||||
size_t len = strlen(str);
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, (const uint8_t *)str, len);
|
||||
if (!CBS_parse_utc_time(&cbs, /*out_tm=*/NULL,
|
||||
/*allow_timezone_offset=*/1)) {
|
||||
/*allow_timezone_offset=*/0)) {
|
||||
return 0;
|
||||
}
|
||||
if (s != NULL) {
|
||||
@@ -121,9 +125,12 @@ ASN1_UTCTIME *ASN1_UTCTIME_adj(ASN1_UTCTIME *s, int64_t posix_time, int offset_d
|
||||
}
|
||||
|
||||
char buf[14];
|
||||
BIO_snprintf(buf, sizeof(buf), "%02d%02d%02d%02d%02d%02dZ",
|
||||
data.tm_year % 100, data.tm_mon + 1, data.tm_mday, data.tm_hour,
|
||||
data.tm_min, data.tm_sec);
|
||||
int ret = snprintf(buf, sizeof(buf), "%02d%02d%02d%02d%02d%02dZ",
|
||||
data.tm_year % 100, data.tm_mon + 1, data.tm_mday,
|
||||
data.tm_hour, data.tm_min, data.tm_sec);
|
||||
if (ret != (int)(sizeof(buf) - 1)) {
|
||||
abort(); // |snprintf| should neither truncate nor write fewer bytes.
|
||||
}
|
||||
|
||||
int free_s = 0;
|
||||
if (s == NULL) {
|
||||
|
||||
@@ -102,6 +102,15 @@ OPENSSL_DECLARE_ERROR_REASON(ASN1, UNKNOWN_FORMAT)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, UNKNOWN_TAG)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, UNSUPPORTED_TYPE)
|
||||
|
||||
// Limit |ASN1_STRING|s to 64 MiB of data. Most of this module, as well as
|
||||
// downstream code, does not correctly handle overflow. We cap string fields
|
||||
// more tightly than strictly necessary to fit in |int|. This is not expected to
|
||||
// impact real world uses of this field.
|
||||
//
|
||||
// In particular, this limit is small enough that the bit count of a BIT STRING
|
||||
// comfortably fits in an |int|, with room for arithmetic.
|
||||
#define ASN1_STRING_MAX (64 * 1024 * 1024)
|
||||
|
||||
static void asn1_put_length(unsigned char **pp, int length);
|
||||
|
||||
int ASN1_get_object(const unsigned char **inp, long *out_len, int *out_tag,
|
||||
@@ -273,9 +282,8 @@ int ASN1_STRING_set(ASN1_STRING *str, const void *_data, ossl_ssize_t len_s) {
|
||||
len = (size_t)len_s;
|
||||
}
|
||||
|
||||
// |ASN1_STRING| cannot represent strings that exceed |int|, and we must
|
||||
// reserve space for a trailing NUL below.
|
||||
if (len > INT_MAX || len + 1 < len) {
|
||||
static_assert(ASN1_STRING_MAX < INT_MAX, "len will not overflow int");
|
||||
if (len > ASN1_STRING_MAX) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_OVERFLOW);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -210,6 +210,10 @@ void asn1_encoding_clear(ASN1_ENCODING *enc);
|
||||
// a pointer.
|
||||
const void *asn1_type_value_as_pointer(const ASN1_TYPE *a);
|
||||
|
||||
// asn1_type_set0_string sets |a|'s value to the object represented by |str| and
|
||||
// takes ownership of |str|.
|
||||
void asn1_type_set0_string(ASN1_TYPE *a, ASN1_STRING *str);
|
||||
|
||||
// asn1_type_cleanup releases memory associated with |a|'s value, without
|
||||
// freeing |a| itself.
|
||||
void asn1_type_cleanup(ASN1_TYPE *a);
|
||||
@@ -256,7 +260,6 @@ typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
|
||||
typedef struct ASN1_EXTERN_FUNCS_st {
|
||||
ASN1_ex_new_func *asn1_ex_new;
|
||||
ASN1_ex_free_func *asn1_ex_free;
|
||||
ASN1_ex_free_func *asn1_ex_clear;
|
||||
ASN1_ex_d2i *asn1_ex_d2i;
|
||||
ASN1_ex_i2d *asn1_ex_i2d;
|
||||
} ASN1_EXTERN_FUNCS;
|
||||
|
||||
@@ -850,7 +850,7 @@ static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, long len,
|
||||
if (utype == V_ASN1_BMPSTRING) {
|
||||
while (CBS_len(&cbs) != 0) {
|
||||
uint32_t c;
|
||||
if (!cbs_get_ucs2_be(&cbs, &c)) {
|
||||
if (!CBS_get_ucs2_be(&cbs, &c)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_BMPSTRING);
|
||||
goto err;
|
||||
}
|
||||
@@ -859,7 +859,7 @@ static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, long len,
|
||||
if (utype == V_ASN1_UNIVERSALSTRING) {
|
||||
while (CBS_len(&cbs) != 0) {
|
||||
uint32_t c;
|
||||
if (!cbs_get_utf32_be(&cbs, &c)) {
|
||||
if (!CBS_get_utf32_be(&cbs, &c)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_UNIVERSALSTRING);
|
||||
goto err;
|
||||
}
|
||||
@@ -868,7 +868,7 @@ static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, long len,
|
||||
if (utype == V_ASN1_UTF8STRING) {
|
||||
while (CBS_len(&cbs) != 0) {
|
||||
uint32_t c;
|
||||
if (!cbs_get_utf8(&cbs, &c)) {
|
||||
if (!CBS_get_utf8(&cbs, &c)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_UTF8STRING);
|
||||
goto err;
|
||||
}
|
||||
|
||||
@@ -452,14 +452,9 @@ static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out,
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (sk_ASN1_VALUE_num(sk) > ((size_t)-1) / sizeof(DER_ENC)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_OVERFLOW);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ret = 0;
|
||||
unsigned char *const buf = OPENSSL_malloc(skcontlen);
|
||||
DER_ENC *encoded = OPENSSL_malloc(sk_ASN1_VALUE_num(sk) * sizeof(*encoded));
|
||||
DER_ENC *encoded = OPENSSL_calloc(sk_ASN1_VALUE_num(sk), sizeof(*encoded));
|
||||
if (encoded == NULL || buf == NULL) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
@@ -127,11 +127,10 @@ int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
*pval = OPENSSL_malloc(it->size);
|
||||
*pval = OPENSSL_zalloc(it->size);
|
||||
if (!*pval) {
|
||||
goto memerr;
|
||||
}
|
||||
OPENSSL_memset(*pval, 0, it->size);
|
||||
asn1_set_choice_selector(pval, -1, it);
|
||||
if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it, NULL)) {
|
||||
goto auxerr2;
|
||||
@@ -151,11 +150,10 @@ int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
*pval = OPENSSL_malloc(it->size);
|
||||
*pval = OPENSSL_zalloc(it->size);
|
||||
if (!*pval) {
|
||||
goto memerr;
|
||||
}
|
||||
OPENSSL_memset(*pval, 0, it->size);
|
||||
asn1_refcount_set_one(pval, it);
|
||||
asn1_enc_init(pval, it);
|
||||
for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
|
||||
@@ -185,16 +183,9 @@ auxerr:
|
||||
}
|
||||
|
||||
static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
const ASN1_EXTERN_FUNCS *ef;
|
||||
|
||||
switch (it->itype) {
|
||||
case ASN1_ITYPE_EXTERN:
|
||||
ef = it->funcs;
|
||||
if (ef && ef->asn1_ex_clear) {
|
||||
ef->asn1_ex_clear(pval, it);
|
||||
} else {
|
||||
*pval = NULL;
|
||||
}
|
||||
*pval = NULL;
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_PRIMITIVE:
|
||||
@@ -276,7 +267,7 @@ static int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it) {
|
||||
}
|
||||
switch (utype) {
|
||||
case V_ASN1_OBJECT:
|
||||
*pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef);
|
||||
*pval = (ASN1_VALUE *)OBJ_get_undef();
|
||||
return 1;
|
||||
|
||||
case V_ASN1_BOOLEAN:
|
||||
|
||||
@@ -121,12 +121,7 @@ int EVP_EncodedLength(size_t *out_len, size_t len) {
|
||||
}
|
||||
|
||||
EVP_ENCODE_CTX *EVP_ENCODE_CTX_new(void) {
|
||||
EVP_ENCODE_CTX *ret = OPENSSL_malloc(sizeof(EVP_ENCODE_CTX));
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
OPENSSL_memset(ret, 0, sizeof(EVP_ENCODE_CTX));
|
||||
return ret;
|
||||
return OPENSSL_zalloc(sizeof(EVP_ENCODE_CTX));
|
||||
}
|
||||
|
||||
void EVP_ENCODE_CTX_free(EVP_ENCODE_CTX *ctx) {
|
||||
|
||||
@@ -69,16 +69,19 @@
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
static CRYPTO_EX_DATA_CLASS g_ex_data_class =
|
||||
CRYPTO_EX_DATA_CLASS_INIT_WITH_APP_DATA;
|
||||
|
||||
BIO *BIO_new(const BIO_METHOD *method) {
|
||||
BIO *ret = OPENSSL_malloc(sizeof(BIO));
|
||||
BIO *ret = OPENSSL_zalloc(sizeof(BIO));
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
OPENSSL_memset(ret, 0, sizeof(BIO));
|
||||
ret->method = method;
|
||||
ret->shutdown = 1;
|
||||
ret->references = 1;
|
||||
CRYPTO_new_ex_data(&ret->ex_data);
|
||||
|
||||
if (method->create != NULL && !method->create(ret)) {
|
||||
OPENSSL_free(ret);
|
||||
@@ -102,6 +105,7 @@ int BIO_free(BIO *bio) {
|
||||
bio->method->destroy(bio);
|
||||
}
|
||||
|
||||
CRYPTO_free_ex_data(&g_ex_data_class, bio, &bio->ex_data);
|
||||
OPENSSL_free(bio);
|
||||
}
|
||||
return 1;
|
||||
@@ -628,23 +632,22 @@ void BIO_set_retry_special(BIO *bio) {
|
||||
|
||||
int BIO_set_write_buffer_size(BIO *bio, int buffer_size) { return 0; }
|
||||
|
||||
static struct CRYPTO_STATIC_MUTEX g_index_lock = CRYPTO_STATIC_MUTEX_INIT;
|
||||
static CRYPTO_MUTEX g_index_lock = CRYPTO_MUTEX_INIT;
|
||||
static int g_index = BIO_TYPE_START;
|
||||
|
||||
int BIO_get_new_index(void) {
|
||||
CRYPTO_STATIC_MUTEX_lock_write(&g_index_lock);
|
||||
CRYPTO_MUTEX_lock_write(&g_index_lock);
|
||||
// If |g_index| exceeds 255, it will collide with the flags bits.
|
||||
int ret = g_index > 255 ? -1 : g_index++;
|
||||
CRYPTO_STATIC_MUTEX_unlock_write(&g_index_lock);
|
||||
CRYPTO_MUTEX_unlock_write(&g_index_lock);
|
||||
return ret;
|
||||
}
|
||||
|
||||
BIO_METHOD *BIO_meth_new(int type, const char *name) {
|
||||
BIO_METHOD *method = OPENSSL_malloc(sizeof(BIO_METHOD));
|
||||
BIO_METHOD *method = OPENSSL_zalloc(sizeof(BIO_METHOD));
|
||||
if (method == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
OPENSSL_memset(method, 0, sizeof(BIO_METHOD));
|
||||
method->type = type;
|
||||
method->name = name;
|
||||
return method;
|
||||
@@ -706,3 +709,23 @@ int BIO_meth_set_puts(BIO_METHOD *method, int (*puts)(BIO *, const char *)) {
|
||||
// Ignore the parameter. We implement |BIO_puts| using |BIO_write|.
|
||||
return 1;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
int BIO_set_ex_data(BIO *bio, int idx, void *data) {
|
||||
return CRYPTO_set_ex_data(&bio->ex_data, idx, data);
|
||||
}
|
||||
|
||||
void *BIO_get_ex_data(const BIO *bio, int idx) {
|
||||
return CRYPTO_get_ex_data(&bio->ex_data, idx);
|
||||
}
|
||||
@@ -206,7 +206,6 @@ static int mem_gets(BIO *bio, char *buf, int size) {
|
||||
|
||||
static long mem_ctrl(BIO *bio, int cmd, long num, void *ptr) {
|
||||
long ret = 1;
|
||||
char **pptr;
|
||||
|
||||
BUF_MEM *b = (BUF_MEM *)bio->ptr;
|
||||
|
||||
@@ -232,8 +231,8 @@ static long mem_ctrl(BIO *bio, int cmd, long num, void *ptr) {
|
||||
case BIO_CTRL_INFO:
|
||||
ret = (long)b->length;
|
||||
if (ptr != NULL) {
|
||||
pptr = (char **)ptr;
|
||||
*pptr = (char *)&b->data[0];
|
||||
char **pptr = ptr;
|
||||
*pptr = b->data;
|
||||
}
|
||||
break;
|
||||
case BIO_C_SET_BUF_MEM:
|
||||
@@ -243,8 +242,8 @@ static long mem_ctrl(BIO *bio, int cmd, long num, void *ptr) {
|
||||
break;
|
||||
case BIO_C_GET_BUF_MEM_PTR:
|
||||
if (ptr != NULL) {
|
||||
pptr = (char **)ptr;
|
||||
*pptr = (char *)b;
|
||||
BUF_MEM **pptr = ptr;
|
||||
*pptr = b;
|
||||
}
|
||||
break;
|
||||
case BIO_CTRL_GET_CLOSE:
|
||||
@@ -294,15 +293,15 @@ int BIO_mem_contents(const BIO *bio, const uint8_t **out_contents,
|
||||
}
|
||||
|
||||
long BIO_get_mem_data(BIO *bio, char **contents) {
|
||||
return BIO_ctrl(bio, BIO_CTRL_INFO, 0, (char *) contents);
|
||||
return BIO_ctrl(bio, BIO_CTRL_INFO, 0, contents);
|
||||
}
|
||||
|
||||
int BIO_get_mem_ptr(BIO *bio, BUF_MEM **out) {
|
||||
return (int)BIO_ctrl(bio, BIO_C_GET_BUF_MEM_PTR, 0, (char *) out);
|
||||
return (int)BIO_ctrl(bio, BIO_C_GET_BUF_MEM_PTR, 0, out);
|
||||
}
|
||||
|
||||
int BIO_set_mem_buf(BIO *bio, BUF_MEM *b, int take_ownership) {
|
||||
return (int)BIO_ctrl(bio, BIO_C_SET_BUF_MEM, take_ownership, (char *) b);
|
||||
return (int)BIO_ctrl(bio, BIO_C_SET_BUF_MEM, take_ownership, b);
|
||||
}
|
||||
|
||||
int BIO_set_mem_eof_return(BIO *bio, int eof_value) {
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
|
||||
#include <CCryptoBoringSSL_bio.h>
|
||||
|
||||
#if !defined(OPENSSL_TRUSTY)
|
||||
#if !defined(OPENSSL_NO_SOCK)
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
@@ -233,7 +233,7 @@ static int conn_state(BIO *bio, BIO_CONNECT *c) {
|
||||
BIO_clear_retry_flags(bio);
|
||||
ret = connect(bio->num, (struct sockaddr*) &c->them, c->them_length);
|
||||
if (ret < 0) {
|
||||
if (bio_fd_should_retry(ret)) {
|
||||
if (bio_socket_should_retry(ret)) {
|
||||
BIO_set_flags(bio, (BIO_FLAGS_IO_SPECIAL | BIO_FLAGS_SHOULD_RETRY));
|
||||
c->state = BIO_CONN_S_BLOCKED_CONNECT;
|
||||
bio->retry_reason = BIO_RR_CONNECT;
|
||||
@@ -252,7 +252,7 @@ static int conn_state(BIO *bio, BIO_CONNECT *c) {
|
||||
case BIO_CONN_S_BLOCKED_CONNECT:
|
||||
i = bio_sock_error(bio->num);
|
||||
if (i) {
|
||||
if (bio_fd_should_retry(ret)) {
|
||||
if (bio_socket_should_retry(ret)) {
|
||||
BIO_set_flags(bio, (BIO_FLAGS_IO_SPECIAL | BIO_FLAGS_SHOULD_RETRY));
|
||||
c->state = BIO_CONN_S_BLOCKED_CONNECT;
|
||||
bio->retry_reason = BIO_RR_CONNECT;
|
||||
@@ -296,13 +296,10 @@ end:
|
||||
}
|
||||
|
||||
static BIO_CONNECT *BIO_CONNECT_new(void) {
|
||||
BIO_CONNECT *ret = OPENSSL_malloc(sizeof(BIO_CONNECT));
|
||||
|
||||
BIO_CONNECT *ret = OPENSSL_zalloc(sizeof(BIO_CONNECT));
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
OPENSSL_memset(ret, 0, sizeof(BIO_CONNECT));
|
||||
|
||||
ret->state = BIO_CONN_S_BEFORE;
|
||||
return ret;
|
||||
}
|
||||
@@ -366,7 +363,7 @@ static int conn_read(BIO *bio, char *out, int out_len) {
|
||||
ret = (int)recv(bio->num, out, out_len, 0);
|
||||
BIO_clear_retry_flags(bio);
|
||||
if (ret <= 0) {
|
||||
if (bio_fd_should_retry(ret)) {
|
||||
if (bio_socket_should_retry(ret)) {
|
||||
BIO_set_retry_read(bio);
|
||||
}
|
||||
}
|
||||
@@ -390,7 +387,7 @@ static int conn_write(BIO *bio, const char *in, int in_len) {
|
||||
ret = (int)send(bio->num, in, in_len, 0);
|
||||
BIO_clear_retry_flags(bio);
|
||||
if (ret <= 0) {
|
||||
if (bio_fd_should_retry(ret)) {
|
||||
if (bio_socket_should_retry(ret)) {
|
||||
BIO_set_retry_write(bio);
|
||||
}
|
||||
}
|
||||
@@ -532,7 +529,7 @@ int BIO_set_conn_port(BIO *bio, const char *port_str) {
|
||||
|
||||
int BIO_set_conn_int_port(BIO *bio, const int *port) {
|
||||
char buf[DECIMAL_SIZE(int) + 1];
|
||||
BIO_snprintf(buf, sizeof(buf), "%d", *port);
|
||||
snprintf(buf, sizeof(buf), "%d", *port);
|
||||
return BIO_set_conn_port(bio, buf);
|
||||
}
|
||||
|
||||
@@ -544,4 +541,4 @@ int BIO_do_connect(BIO *bio) {
|
||||
return (int)BIO_ctrl(bio, BIO_C_DO_STATE_MACHINE, 0, NULL);
|
||||
}
|
||||
|
||||
#endif // OPENSSL_TRUSTY
|
||||
#endif // OPENSSL_NO_SOCK
|
||||
+30
-38
@@ -54,47 +54,39 @@
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.] */
|
||||
|
||||
#include <CCryptoBoringSSL_x509.h>
|
||||
#include <CCryptoBoringSSL_bio.h>
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_thread.h>
|
||||
#include <errno.h>
|
||||
|
||||
X509_INFO *X509_INFO_new(void) {
|
||||
X509_INFO *ret = NULL;
|
||||
#include "internal.h"
|
||||
|
||||
ret = (X509_INFO *)OPENSSL_malloc(sizeof(X509_INFO));
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
|
||||
int bio_errno_should_retry(int return_value) {
|
||||
if (return_value != -1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret->enc_cipher.cipher = NULL;
|
||||
ret->enc_len = 0;
|
||||
ret->enc_data = NULL;
|
||||
|
||||
ret->x509 = NULL;
|
||||
ret->crl = NULL;
|
||||
ret->x_pkey = NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void X509_INFO_free(X509_INFO *x) {
|
||||
if (x == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (x->x509 != NULL) {
|
||||
X509_free(x->x509);
|
||||
}
|
||||
if (x->crl != NULL) {
|
||||
X509_CRL_free(x->crl);
|
||||
}
|
||||
if (x->x_pkey != NULL) {
|
||||
X509_PKEY_free(x->x_pkey);
|
||||
}
|
||||
if (x->enc_data != NULL) {
|
||||
OPENSSL_free(x->enc_data);
|
||||
}
|
||||
OPENSSL_free(x);
|
||||
return
|
||||
#ifdef EWOULDBLOCK
|
||||
errno == EWOULDBLOCK ||
|
||||
#endif
|
||||
#ifdef ENOTCONN
|
||||
errno == ENOTCONN ||
|
||||
#endif
|
||||
#ifdef EINTR
|
||||
errno == EINTR ||
|
||||
#endif
|
||||
#ifdef EAGAIN
|
||||
errno == EAGAIN ||
|
||||
#endif
|
||||
#ifdef EPROTO
|
||||
errno == EPROTO ||
|
||||
#endif
|
||||
#ifdef EINPROGRESS
|
||||
errno == EINPROGRESS ||
|
||||
#endif
|
||||
#ifdef EALREADY
|
||||
errno == EALREADY ||
|
||||
#endif
|
||||
0;
|
||||
}
|
||||
@@ -56,7 +56,7 @@
|
||||
|
||||
#include <CCryptoBoringSSL_bio.h>
|
||||
|
||||
#if !defined(OPENSSL_TRUSTY)
|
||||
#if !defined(OPENSSL_NO_POSIX_IO)
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
@@ -65,9 +65,6 @@
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include <io.h>
|
||||
OPENSSL_MSVC_PRAGMA(warning(push, 3))
|
||||
#include <windows.h>
|
||||
OPENSSL_MSVC_PRAGMA(warning(pop))
|
||||
#endif
|
||||
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
@@ -77,59 +74,18 @@ OPENSSL_MSVC_PRAGMA(warning(pop))
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
static int bio_fd_non_fatal_error(int err) {
|
||||
if (
|
||||
#ifdef EWOULDBLOCK
|
||||
err == EWOULDBLOCK ||
|
||||
#endif
|
||||
#ifdef WSAEWOULDBLOCK
|
||||
err == WSAEWOULDBLOCK ||
|
||||
#endif
|
||||
#ifdef ENOTCONN
|
||||
err == ENOTCONN ||
|
||||
#endif
|
||||
#ifdef EINTR
|
||||
err == EINTR ||
|
||||
#endif
|
||||
#ifdef EAGAIN
|
||||
err == EAGAIN ||
|
||||
#endif
|
||||
#ifdef EPROTO
|
||||
err == EPROTO ||
|
||||
#endif
|
||||
#ifdef EINPROGRESS
|
||||
err == EINPROGRESS ||
|
||||
#endif
|
||||
#ifdef EALREADY
|
||||
err == EALREADY ||
|
||||
#endif
|
||||
0) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
#define BORINGSSL_ERRNO (int)GetLastError()
|
||||
#define BORINGSSL_CLOSE _close
|
||||
#define BORINGSSL_LSEEK _lseek
|
||||
#define BORINGSSL_READ _read
|
||||
#define BORINGSSL_WRITE _write
|
||||
#else
|
||||
#define BORINGSSL_ERRNO errno
|
||||
#define BORINGSSL_CLOSE close
|
||||
#define BORINGSSL_LSEEK lseek
|
||||
#define BORINGSSL_READ read
|
||||
#define BORINGSSL_WRITE write
|
||||
#endif
|
||||
|
||||
int bio_fd_should_retry(int i) {
|
||||
if (i == -1) {
|
||||
return bio_fd_non_fatal_error(BORINGSSL_ERRNO);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIO *BIO_new_fd(int fd, int close_flag) {
|
||||
BIO *ret = BIO_new(BIO_s_fd());
|
||||
if (ret == NULL) {
|
||||
@@ -161,7 +117,7 @@ static int fd_read(BIO *b, char *out, int outl) {
|
||||
ret = (int)BORINGSSL_READ(b->num, out, outl);
|
||||
BIO_clear_retry_flags(b);
|
||||
if (ret <= 0) {
|
||||
if (bio_fd_should_retry(ret)) {
|
||||
if (bio_errno_should_retry(ret)) {
|
||||
BIO_set_retry_read(b);
|
||||
}
|
||||
}
|
||||
@@ -173,7 +129,7 @@ static int fd_write(BIO *b, const char *in, int inl) {
|
||||
int ret = (int)BORINGSSL_WRITE(b->num, in, inl);
|
||||
BIO_clear_retry_flags(b);
|
||||
if (ret <= 0) {
|
||||
if (bio_fd_should_retry(ret)) {
|
||||
if (bio_errno_should_retry(ret)) {
|
||||
BIO_set_retry_write(b);
|
||||
}
|
||||
}
|
||||
@@ -268,6 +224,8 @@ static const BIO_METHOD methods_fdp = {
|
||||
|
||||
const BIO_METHOD *BIO_s_fd(void) { return &methods_fdp; }
|
||||
|
||||
#endif // OPENSSL_NO_POSIX_IO
|
||||
|
||||
int BIO_set_fd(BIO *bio, int fd, int close_flag) {
|
||||
return (int)BIO_int_ctrl(bio, BIO_C_SET_FD, close_flag, fd);
|
||||
}
|
||||
@@ -275,5 +233,3 @@ int BIO_set_fd(BIO *bio, int fd, int close_flag) {
|
||||
int BIO_get_fd(BIO *bio, int *out_fd) {
|
||||
return (int)BIO_ctrl(bio, BIO_C_GET_FD, 0, (char *) out_fd);
|
||||
}
|
||||
|
||||
#endif // OPENSSL_TRUSTY
|
||||
@@ -73,8 +73,6 @@
|
||||
|
||||
#include <CCryptoBoringSSL_bio.h>
|
||||
|
||||
#if !defined(OPENSSL_TRUSTY)
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@@ -89,11 +87,20 @@
|
||||
#define BIO_FP_WRITE 0x04
|
||||
#define BIO_FP_APPEND 0x08
|
||||
|
||||
#if !defined(OPENSSL_NO_FILESYSTEM)
|
||||
#define fopen_if_available fopen
|
||||
#else
|
||||
static FILE *fopen_if_available(const char *path, const char *mode) {
|
||||
errno = ENOENT;
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
BIO *BIO_new_file(const char *filename, const char *mode) {
|
||||
BIO *ret;
|
||||
FILE *file;
|
||||
|
||||
file = fopen(filename, mode);
|
||||
file = fopen_if_available(filename, mode);
|
||||
if (file == NULL) {
|
||||
OPENSSL_PUT_SYSTEM_ERROR();
|
||||
|
||||
@@ -172,7 +179,6 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr) {
|
||||
long ret = 1;
|
||||
FILE *fp = (FILE *)b->ptr;
|
||||
FILE **fpp;
|
||||
char p[4];
|
||||
|
||||
switch (cmd) {
|
||||
case BIO_CTRL_RESET:
|
||||
@@ -197,27 +203,28 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr) {
|
||||
case BIO_C_SET_FILENAME:
|
||||
file_free(b);
|
||||
b->shutdown = (int)num & BIO_CLOSE;
|
||||
const char *mode;
|
||||
if (num & BIO_FP_APPEND) {
|
||||
if (num & BIO_FP_READ) {
|
||||
OPENSSL_strlcpy(p, "a+", sizeof(p));
|
||||
mode = "a+";
|
||||
} else {
|
||||
OPENSSL_strlcpy(p, "a", sizeof(p));
|
||||
mode = "a";
|
||||
}
|
||||
} else if ((num & BIO_FP_READ) && (num & BIO_FP_WRITE)) {
|
||||
OPENSSL_strlcpy(p, "r+", sizeof(p));
|
||||
mode = "r+";
|
||||
} else if (num & BIO_FP_WRITE) {
|
||||
OPENSSL_strlcpy(p, "w", sizeof(p));
|
||||
mode = "w";
|
||||
} else if (num & BIO_FP_READ) {
|
||||
OPENSSL_strlcpy(p, "r", sizeof(p));
|
||||
mode = "r";
|
||||
} else {
|
||||
OPENSSL_PUT_ERROR(BIO, BIO_R_BAD_FOPEN_MODE);
|
||||
ret = 0;
|
||||
break;
|
||||
}
|
||||
fp = fopen(ptr, p);
|
||||
fp = fopen_if_available(ptr, mode);
|
||||
if (fp == NULL) {
|
||||
OPENSSL_PUT_SYSTEM_ERROR();
|
||||
ERR_add_error_data(5, "fopen('", ptr, "','", p, "')");
|
||||
ERR_add_error_data(5, "fopen('", ptr, "','", mode, "')");
|
||||
OPENSSL_PUT_ERROR(BIO, ERR_R_SYS_LIB);
|
||||
ret = 0;
|
||||
break;
|
||||
@@ -310,5 +317,3 @@ long BIO_tell(BIO *bio) { return BIO_ctrl(bio, BIO_C_FILE_TELL, 0, NULL); }
|
||||
long BIO_seek(BIO *bio, long offset) {
|
||||
return BIO_ctrl(bio, BIO_C_FILE_SEEK, offset, NULL);
|
||||
}
|
||||
|
||||
#endif // OPENSSL_TRUSTY
|
||||
@@ -59,6 +59,7 @@
|
||||
|
||||
#include <CCryptoBoringSSL_base.h>
|
||||
|
||||
#if !defined(OPENSSL_NO_SOCK)
|
||||
#if !defined(OPENSSL_WINDOWS)
|
||||
#if defined(OPENSSL_PNACL)
|
||||
// newlib uses u_short in socket.h without defining it.
|
||||
@@ -72,13 +73,16 @@ OPENSSL_MSVC_PRAGMA(warning(push, 3))
|
||||
OPENSSL_MSVC_PRAGMA(warning(pop))
|
||||
typedef int socklen_t;
|
||||
#endif
|
||||
#endif // !OPENSSL_NO_SOCK
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
// BIO_ip_and_port_to_socket_and_addr creates a socket and fills in |*out_addr|
|
||||
#if !defined(OPENSSL_NO_SOCK)
|
||||
|
||||
// bio_ip_and_port_to_socket_and_addr creates a socket and fills in |*out_addr|
|
||||
// and |*out_addr_length| with the correct values for connecting to |hostname|
|
||||
// on |port_str|. It returns one on success or zero on error.
|
||||
int bio_ip_and_port_to_socket_and_addr(int *out_sock,
|
||||
@@ -87,21 +91,27 @@ int bio_ip_and_port_to_socket_and_addr(int *out_sock,
|
||||
const char *hostname,
|
||||
const char *port_str);
|
||||
|
||||
// BIO_socket_nbio sets whether |sock| is non-blocking. It returns one on
|
||||
// bio_socket_nbio sets whether |sock| is non-blocking. It returns one on
|
||||
// success and zero otherwise.
|
||||
int bio_socket_nbio(int sock, int on);
|
||||
|
||||
// BIO_clear_socket_error clears the last system socket error.
|
||||
// bio_clear_socket_error clears the last system socket error.
|
||||
//
|
||||
// TODO(fork): remove all callers of this.
|
||||
void bio_clear_socket_error(void);
|
||||
|
||||
// BIO_sock_error returns the last socket error on |sock|.
|
||||
// bio_sock_error returns the last socket error on |sock|.
|
||||
int bio_sock_error(int sock);
|
||||
|
||||
// BIO_fd_should_retry returns non-zero if |return_value| indicates an error
|
||||
// bio_socket_should_retry returns non-zero if |return_value| indicates an error
|
||||
// and the last socket error indicates that it's non-fatal.
|
||||
int bio_socket_should_retry(int return_value);
|
||||
|
||||
#endif // !OPENSSL_NO_SOCK
|
||||
|
||||
// bio_errno_should_retry returns non-zero if |return_value| indicates an error
|
||||
// and |errno| indicates that it's non-fatal.
|
||||
int bio_fd_should_retry(int return_value);
|
||||
int bio_errno_should_retry(int return_value);
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
|
||||
@@ -81,13 +81,10 @@ struct bio_bio_st {
|
||||
};
|
||||
|
||||
static int bio_new(BIO *bio) {
|
||||
struct bio_bio_st *b;
|
||||
|
||||
b = OPENSSL_malloc(sizeof *b);
|
||||
struct bio_bio_st *b = OPENSSL_zalloc(sizeof *b);
|
||||
if (b == NULL) {
|
||||
return 0;
|
||||
}
|
||||
OPENSSL_memset(b, 0, sizeof(struct bio_bio_st));
|
||||
|
||||
b->size = 17 * 1024; // enough for one TLS record (just a default)
|
||||
bio->ptr = b;
|
||||
|
||||
@@ -56,7 +56,7 @@
|
||||
|
||||
#include <CCryptoBoringSSL_bio.h>
|
||||
|
||||
#if !defined(OPENSSL_TRUSTY)
|
||||
#if !defined(OPENSSL_NO_SOCK)
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
@@ -104,7 +104,7 @@ static int sock_read(BIO *b, char *out, int outl) {
|
||||
#endif
|
||||
BIO_clear_retry_flags(b);
|
||||
if (ret <= 0) {
|
||||
if (bio_fd_should_retry(ret)) {
|
||||
if (bio_socket_should_retry(ret)) {
|
||||
BIO_set_retry_read(b);
|
||||
}
|
||||
}
|
||||
@@ -120,7 +120,7 @@ static int sock_write(BIO *b, const char *in, int inl) {
|
||||
#endif
|
||||
BIO_clear_retry_flags(b);
|
||||
if (ret <= 0) {
|
||||
if (bio_fd_should_retry(ret)) {
|
||||
if (bio_socket_should_retry(ret)) {
|
||||
BIO_set_retry_write(b);
|
||||
}
|
||||
}
|
||||
@@ -186,4 +186,4 @@ BIO *BIO_new_socket(int fd, int close_flag) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif // OPENSSL_TRUSTY
|
||||
#endif // OPENSSL_NO_SOCK
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <CCryptoBoringSSL_bio.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
|
||||
#if !defined(OPENSSL_TRUSTY)
|
||||
#if !defined(OPENSSL_NO_SOCK)
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
@@ -121,4 +121,13 @@ int bio_sock_error(int sock) {
|
||||
return error;
|
||||
}
|
||||
|
||||
#endif // OPENSSL_TRUSTY
|
||||
int bio_socket_should_retry(int return_value) {
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
return return_value == -1 && WSAGetLastError() == WSAEWOULDBLOCK;
|
||||
#else
|
||||
// On POSIX platforms, sockets and fds are the same.
|
||||
return bio_errno_should_retry(return_value);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // OPENSSL_NO_SOCK
|
||||
@@ -55,10 +55,13 @@ static void blake2b_mix(uint64_t v[16], int a, int b, int c, int d, uint64_t x,
|
||||
v[b] = CRYPTO_rotr_u64(v[b] ^ v[c], 63);
|
||||
}
|
||||
|
||||
static void blake2b_transform(
|
||||
BLAKE2B_CTX *b2b,
|
||||
const uint64_t block_words[BLAKE2B_CBLOCK / sizeof(uint64_t)],
|
||||
size_t num_bytes, int is_final_block) {
|
||||
static uint64_t blake2b_load(const uint8_t block[BLAKE2B_CBLOCK], size_t i) {
|
||||
return CRYPTO_load_u64_le(block + 8 * i);
|
||||
}
|
||||
|
||||
static void blake2b_transform(BLAKE2B_CTX *b2b,
|
||||
const uint8_t block[BLAKE2B_CBLOCK],
|
||||
size_t num_bytes, int is_final_block) {
|
||||
// https://tools.ietf.org/html/rfc7693#section-3.2
|
||||
uint64_t v[16];
|
||||
static_assert(sizeof(v) == sizeof(b2b->h) + sizeof(kIV), "");
|
||||
@@ -78,14 +81,22 @@ static void blake2b_transform(
|
||||
|
||||
for (int round = 0; round < 12; round++) {
|
||||
const uint8_t *const s = &kSigma[16 * (round % 10)];
|
||||
blake2b_mix(v, 0, 4, 8, 12, block_words[s[0]], block_words[s[1]]);
|
||||
blake2b_mix(v, 1, 5, 9, 13, block_words[s[2]], block_words[s[3]]);
|
||||
blake2b_mix(v, 2, 6, 10, 14, block_words[s[4]], block_words[s[5]]);
|
||||
blake2b_mix(v, 3, 7, 11, 15, block_words[s[6]], block_words[s[7]]);
|
||||
blake2b_mix(v, 0, 5, 10, 15, block_words[s[8]], block_words[s[9]]);
|
||||
blake2b_mix(v, 1, 6, 11, 12, block_words[s[10]], block_words[s[11]]);
|
||||
blake2b_mix(v, 2, 7, 8, 13, block_words[s[12]], block_words[s[13]]);
|
||||
blake2b_mix(v, 3, 4, 9, 14, block_words[s[14]], block_words[s[15]]);
|
||||
blake2b_mix(v, 0, 4, 8, 12, blake2b_load(block, s[0]),
|
||||
blake2b_load(block, s[1]));
|
||||
blake2b_mix(v, 1, 5, 9, 13, blake2b_load(block, s[2]),
|
||||
blake2b_load(block, s[3]));
|
||||
blake2b_mix(v, 2, 6, 10, 14, blake2b_load(block, s[4]),
|
||||
blake2b_load(block, s[5]));
|
||||
blake2b_mix(v, 3, 7, 11, 15, blake2b_load(block, s[6]),
|
||||
blake2b_load(block, s[7]));
|
||||
blake2b_mix(v, 0, 5, 10, 15, blake2b_load(block, s[8]),
|
||||
blake2b_load(block, s[9]));
|
||||
blake2b_mix(v, 1, 6, 11, 12, blake2b_load(block, s[10]),
|
||||
blake2b_load(block, s[11]));
|
||||
blake2b_mix(v, 2, 7, 8, 13, blake2b_load(block, s[12]),
|
||||
blake2b_load(block, s[13]));
|
||||
blake2b_mix(v, 3, 4, 9, 14, blake2b_load(block, s[14]),
|
||||
blake2b_load(block, s[15]));
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < OPENSSL_ARRAY_SIZE(b2b->h); i++) {
|
||||
@@ -111,11 +122,11 @@ void BLAKE2B256_Update(BLAKE2B_CTX *b2b, const void *in_data, size_t len) {
|
||||
}
|
||||
|
||||
const uint8_t *data = in_data;
|
||||
size_t todo = sizeof(b2b->block.bytes) - b2b->block_used;
|
||||
size_t todo = sizeof(b2b->block) - b2b->block_used;
|
||||
if (todo > len) {
|
||||
todo = len;
|
||||
}
|
||||
OPENSSL_memcpy(&b2b->block.bytes[b2b->block_used], data, todo);
|
||||
OPENSSL_memcpy(&b2b->block[b2b->block_used], data, todo);
|
||||
b2b->block_used += todo;
|
||||
data += todo;
|
||||
len -= todo;
|
||||
@@ -126,26 +137,24 @@ void BLAKE2B256_Update(BLAKE2B_CTX *b2b, const void *in_data, size_t len) {
|
||||
|
||||
// More input remains therefore we must have filled |b2b->block|.
|
||||
assert(b2b->block_used == BLAKE2B_CBLOCK);
|
||||
blake2b_transform(b2b, b2b->block.words, BLAKE2B_CBLOCK,
|
||||
blake2b_transform(b2b, b2b->block, BLAKE2B_CBLOCK,
|
||||
/*is_final_block=*/0);
|
||||
b2b->block_used = 0;
|
||||
|
||||
while (len > BLAKE2B_CBLOCK) {
|
||||
uint64_t block_words[BLAKE2B_CBLOCK / sizeof(uint64_t)];
|
||||
OPENSSL_memcpy(block_words, data, sizeof(block_words));
|
||||
blake2b_transform(b2b, block_words, BLAKE2B_CBLOCK, /*is_final_block=*/0);
|
||||
blake2b_transform(b2b, data, BLAKE2B_CBLOCK, /*is_final_block=*/0);
|
||||
data += BLAKE2B_CBLOCK;
|
||||
len -= BLAKE2B_CBLOCK;
|
||||
}
|
||||
|
||||
OPENSSL_memcpy(b2b->block.bytes, data, len);
|
||||
OPENSSL_memcpy(b2b->block, data, len);
|
||||
b2b->block_used = len;
|
||||
}
|
||||
|
||||
void BLAKE2B256_Final(uint8_t out[BLAKE2B256_DIGEST_LENGTH], BLAKE2B_CTX *b2b) {
|
||||
OPENSSL_memset(&b2b->block.bytes[b2b->block_used], 0,
|
||||
sizeof(b2b->block.bytes) - b2b->block_used);
|
||||
blake2b_transform(b2b, b2b->block.words, b2b->block_used,
|
||||
OPENSSL_memset(&b2b->block[b2b->block_used], 0,
|
||||
sizeof(b2b->block) - b2b->block_used);
|
||||
blake2b_transform(b2b, b2b->block, b2b->block_used,
|
||||
/*is_final_block=*/1);
|
||||
static_assert(BLAKE2B256_DIGEST_LENGTH <= sizeof(b2b->h), "");
|
||||
memcpy(out, b2b->h, BLAKE2B256_DIGEST_LENGTH);
|
||||
|
||||
@@ -455,3 +455,11 @@ int BN_bn2binpad(const BIGNUM *in, uint8_t *out, int len) {
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
int BN_bn2lebinpad(const BIGNUM *in, uint8_t *out, int len) {
|
||||
if (len < 0 ||
|
||||
!BN_bn2le_padded(out, (size_t)len, in)) {
|
||||
return -1;
|
||||
}
|
||||
return len;
|
||||
}
|
||||
@@ -64,17 +64,7 @@
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
BUF_MEM *BUF_MEM_new(void) {
|
||||
BUF_MEM *ret;
|
||||
|
||||
ret = OPENSSL_malloc(sizeof(BUF_MEM));
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
OPENSSL_memset(ret, 0, sizeof(BUF_MEM));
|
||||
return ret;
|
||||
}
|
||||
BUF_MEM *BUF_MEM_new(void) { return OPENSSL_zalloc(sizeof(BUF_MEM)); }
|
||||
|
||||
void BUF_MEM_free(BUF_MEM *buf) {
|
||||
if (buf == NULL) {
|
||||
|
||||
@@ -155,6 +155,29 @@ static struct cbb_buffer_st *cbb_get_base(CBB *cbb) {
|
||||
return &cbb->u.base;
|
||||
}
|
||||
|
||||
static void cbb_on_error(CBB *cbb) {
|
||||
// Due to C's lack of destructors and |CBB|'s auto-flushing API, a failing
|
||||
// |CBB|-taking function may leave a dangling pointer to a child |CBB|. As a
|
||||
// result, the convention is callers may not write to |CBB|s that have failed.
|
||||
// But, as a safety measure, we lock the |CBB| into an error state. Once the
|
||||
// error bit is set, |cbb->child| will not be read.
|
||||
//
|
||||
// TODO(davidben): This still isn't quite ideal. A |CBB| function *outside*
|
||||
// this file may originate an error while the |CBB| points to a local child.
|
||||
// In that case we don't set the error bit and are reliant on the error
|
||||
// convention. Perhaps we allow |CBB_cleanup| on child |CBB|s and make every
|
||||
// child's |CBB_cleanup| set the error bit if unflushed. That will be
|
||||
// convenient for C++ callers, but very tedious for C callers. So C callers
|
||||
// perhaps should get a |CBB_on_error| function that can be, less tediously,
|
||||
// stuck in a |goto err| block.
|
||||
cbb_get_base(cbb)->error = 1;
|
||||
|
||||
// Clearing the pointer is not strictly necessary, but GCC's dangling pointer
|
||||
// warning does not know |cbb->child| will not be read once |error| is set
|
||||
// above.
|
||||
cbb->child = NULL;
|
||||
}
|
||||
|
||||
// CBB_flush recurses and then writes out any pending length prefix. The
|
||||
// current length of the underlying base is taken to be the length of the
|
||||
// length-prefixed data.
|
||||
@@ -244,7 +267,7 @@ int CBB_flush(CBB *cbb) {
|
||||
return 1;
|
||||
|
||||
err:
|
||||
base->error = 1;
|
||||
cbb_on_error(cbb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -420,7 +443,7 @@ static int cbb_add_u(CBB *cbb, uint64_t v, size_t len_len) {
|
||||
|
||||
// |v| must fit in |len_len| bytes.
|
||||
if (v != 0) {
|
||||
cbb_get_base(cbb)->error = 1;
|
||||
cbb_on_error(cbb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -479,7 +502,7 @@ int CBB_add_asn1_uint64(CBB *cbb, uint64_t value) {
|
||||
int CBB_add_asn1_uint64_with_tag(CBB *cbb, uint64_t value, CBS_ASN1_TAG tag) {
|
||||
CBB child;
|
||||
if (!CBB_add_asn1(cbb, &child, tag)) {
|
||||
return 0;
|
||||
goto err;
|
||||
}
|
||||
|
||||
int started = 0;
|
||||
@@ -493,21 +516,25 @@ int CBB_add_asn1_uint64_with_tag(CBB *cbb, uint64_t value, CBS_ASN1_TAG tag) {
|
||||
// If the high bit is set, add a padding byte to make it
|
||||
// unsigned.
|
||||
if ((byte & 0x80) && !CBB_add_u8(&child, 0)) {
|
||||
return 0;
|
||||
goto err;
|
||||
}
|
||||
started = 1;
|
||||
}
|
||||
if (!CBB_add_u8(&child, byte)) {
|
||||
return 0;
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
// 0 is encoded as a single 0, not the empty string.
|
||||
if (!started && !CBB_add_u8(&child, 0)) {
|
||||
return 0;
|
||||
goto err;
|
||||
}
|
||||
|
||||
return CBB_flush(cbb);
|
||||
|
||||
err:
|
||||
cbb_on_error(cbb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CBB_add_asn1_int64(CBB *cbb, int64_t value) {
|
||||
@@ -529,14 +556,18 @@ int CBB_add_asn1_int64_with_tag(CBB *cbb, int64_t value, CBS_ASN1_TAG tag) {
|
||||
|
||||
CBB child;
|
||||
if (!CBB_add_asn1(cbb, &child, tag)) {
|
||||
return 0;
|
||||
goto err;
|
||||
}
|
||||
for (int i = start; i >= 0; i--) {
|
||||
if (!CBB_add_u8(&child, bytes[i])) {
|
||||
return 0;
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
return CBB_flush(cbb);
|
||||
|
||||
err:
|
||||
cbb_on_error(cbb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CBB_add_asn1_octet_string(CBB *cbb, const uint8_t *data, size_t data_len) {
|
||||
@@ -544,6 +575,7 @@ int CBB_add_asn1_octet_string(CBB *cbb, const uint8_t *data, size_t data_len) {
|
||||
if (!CBB_add_asn1(cbb, &child, CBS_ASN1_OCTETSTRING) ||
|
||||
!CBB_add_bytes(&child, data, data_len) ||
|
||||
!CBB_flush(cbb)) {
|
||||
cbb_on_error(cbb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -555,6 +587,7 @@ int CBB_add_asn1_bool(CBB *cbb, int value) {
|
||||
if (!CBB_add_asn1(cbb, &child, CBS_ASN1_BOOLEAN) ||
|
||||
!CBB_add_u8(&child, value != 0 ? 0xff : 0) ||
|
||||
!CBB_flush(cbb)) {
|
||||
cbb_on_error(cbb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -649,16 +682,13 @@ int CBB_flush_asn1_set_of(CBB *cbb) {
|
||||
if (num_children < 2) {
|
||||
return 1; // Nothing to do. This is the common case for X.509.
|
||||
}
|
||||
if (num_children > ((size_t)-1) / sizeof(CBS)) {
|
||||
return 0; // Overflow.
|
||||
}
|
||||
|
||||
// Parse out the children and sort. We alias them into a copy of so they
|
||||
// remain valid as we rewrite |cbb|.
|
||||
int ret = 0;
|
||||
size_t buf_len = CBB_len(cbb);
|
||||
uint8_t *buf = OPENSSL_memdup(CBB_data(cbb), buf_len);
|
||||
CBS *children = OPENSSL_malloc(num_children * sizeof(CBS));
|
||||
CBS *children = OPENSSL_calloc(num_children, sizeof(CBS));
|
||||
if (buf == NULL || children == NULL) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
@@ -694,7 +694,7 @@ int CBS_is_unsigned_asn1_integer(const CBS *cbs) {
|
||||
|
||||
static int add_decimal(CBB *out, uint64_t v) {
|
||||
char buf[DECIMAL_SIZE(uint64_t) + 1];
|
||||
BIO_snprintf(buf, sizeof(buf), "%" PRIu64, v);
|
||||
snprintf(buf, sizeof(buf), "%" PRIu64, v);
|
||||
return CBB_add_bytes(out, (const uint8_t *)buf, strlen(buf));
|
||||
}
|
||||
|
||||
|
||||
@@ -67,28 +67,6 @@ OPENSSL_EXPORT int CBS_get_asn1_implicit_string(CBS *in, CBS *out,
|
||||
int CBB_finish_i2d(CBB *cbb, uint8_t **outp);
|
||||
|
||||
|
||||
// Unicode utilities.
|
||||
|
||||
// The following functions read one Unicode code point from |cbs| with the
|
||||
// corresponding encoding and store it in |*out|. They return one on success and
|
||||
// zero on error.
|
||||
OPENSSL_EXPORT int cbs_get_utf8(CBS *cbs, uint32_t *out);
|
||||
OPENSSL_EXPORT int cbs_get_latin1(CBS *cbs, uint32_t *out);
|
||||
OPENSSL_EXPORT int cbs_get_ucs2_be(CBS *cbs, uint32_t *out);
|
||||
OPENSSL_EXPORT int cbs_get_utf32_be(CBS *cbs, uint32_t *out);
|
||||
|
||||
// cbb_get_utf8_len returns the number of bytes needed to represent |u| in
|
||||
// UTF-8.
|
||||
OPENSSL_EXPORT size_t cbb_get_utf8_len(uint32_t u);
|
||||
|
||||
// The following functions encode |u| to |cbb| with the corresponding
|
||||
// encoding. They return one on success and zero on error.
|
||||
OPENSSL_EXPORT int cbb_add_utf8(CBB *cbb, uint32_t u);
|
||||
OPENSSL_EXPORT int cbb_add_latin1(CBB *cbb, uint32_t u);
|
||||
OPENSSL_EXPORT int cbb_add_ucs2_be(CBB *cbb, uint32_t u);
|
||||
OPENSSL_EXPORT int cbb_add_utf32_be(CBB *cbb, uint32_t u);
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // extern C
|
||||
#endif
|
||||
|
||||
@@ -38,7 +38,7 @@ static int is_valid_code_point(uint32_t v) {
|
||||
// TOP_BITS returns a byte with the top |n| bits set.
|
||||
#define TOP_BITS(n) ((uint8_t)~BOTTOM_BITS(8 - (n)))
|
||||
|
||||
int cbs_get_utf8(CBS *cbs, uint32_t *out) {
|
||||
int CBS_get_utf8(CBS *cbs, uint32_t *out) {
|
||||
uint8_t c;
|
||||
if (!CBS_get_u8(cbs, &c)) {
|
||||
return 0;
|
||||
@@ -80,7 +80,7 @@ int cbs_get_utf8(CBS *cbs, uint32_t *out) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int cbs_get_latin1(CBS *cbs, uint32_t *out) {
|
||||
int CBS_get_latin1(CBS *cbs, uint32_t *out) {
|
||||
uint8_t c;
|
||||
if (!CBS_get_u8(cbs, &c)) {
|
||||
return 0;
|
||||
@@ -89,7 +89,7 @@ int cbs_get_latin1(CBS *cbs, uint32_t *out) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int cbs_get_ucs2_be(CBS *cbs, uint32_t *out) {
|
||||
int CBS_get_ucs2_be(CBS *cbs, uint32_t *out) {
|
||||
// Note UCS-2 (used by BMPString) does not support surrogates.
|
||||
uint16_t c;
|
||||
if (!CBS_get_u16(cbs, &c) ||
|
||||
@@ -100,11 +100,11 @@ int cbs_get_ucs2_be(CBS *cbs, uint32_t *out) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int cbs_get_utf32_be(CBS *cbs, uint32_t *out) {
|
||||
int CBS_get_utf32_be(CBS *cbs, uint32_t *out) {
|
||||
return CBS_get_u32(cbs, out) && is_valid_code_point(*out);
|
||||
}
|
||||
|
||||
size_t cbb_get_utf8_len(uint32_t u) {
|
||||
size_t CBB_get_utf8_len(uint32_t u) {
|
||||
if (u <= 0x7f) {
|
||||
return 1;
|
||||
}
|
||||
@@ -117,7 +117,7 @@ size_t cbb_get_utf8_len(uint32_t u) {
|
||||
return 4;
|
||||
}
|
||||
|
||||
int cbb_add_utf8(CBB *cbb, uint32_t u) {
|
||||
int CBB_add_utf8(CBB *cbb, uint32_t u) {
|
||||
if (!is_valid_code_point(u)) {
|
||||
return 0;
|
||||
}
|
||||
@@ -142,14 +142,14 @@ int cbb_add_utf8(CBB *cbb, uint32_t u) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cbb_add_latin1(CBB *cbb, uint32_t u) {
|
||||
int CBB_add_latin1(CBB *cbb, uint32_t u) {
|
||||
return u <= 0xff && CBB_add_u8(cbb, (uint8_t)u);
|
||||
}
|
||||
|
||||
int cbb_add_ucs2_be(CBB *cbb, uint32_t u) {
|
||||
int CBB_add_ucs2_be(CBB *cbb, uint32_t u) {
|
||||
return u <= 0xffff && is_valid_code_point(u) && CBB_add_u16(cbb, (uint16_t)u);
|
||||
}
|
||||
|
||||
int cbb_add_utf32_be(CBB *cbb, uint32_t u) {
|
||||
int CBB_add_utf32_be(CBB *cbb, uint32_t u) {
|
||||
return is_valid_code_point(u) && CBB_add_u32(cbb, u);
|
||||
}
|
||||
@@ -3,17 +3,9 @@
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if !defined(__has_feature)
|
||||
#define __has_feature(x) 0
|
||||
#endif
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
#define OPENSSL_NO_ASM
|
||||
#endif
|
||||
#include <CCryptoBoringSSL_asm_base.h>
|
||||
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(__ARMEL__) && defined(__APPLE__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
#include <CCryptoBoringSSL_boringssl_prefix_symbols_asm.h>
|
||||
#endif
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_ARM) && defined(__APPLE__)
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
@ Silence ARMv8 deprecated IT instruction warnings. This file is used by both
|
||||
@@ -39,49 +31,19 @@ Lsigma:
|
||||
.long 0x61707865,0x3320646e,0x79622d32,0x6b206574 @ endian-neutral
|
||||
Lone:
|
||||
.long 1,0,0,0
|
||||
#if __ARM_MAX_ARCH__>=7
|
||||
LOPENSSL_armcap:
|
||||
.word OPENSSL_armcap_P-LChaCha20_ctr32
|
||||
#else
|
||||
.word -1
|
||||
#endif
|
||||
|
||||
.globl _ChaCha20_ctr32
|
||||
.private_extern _ChaCha20_ctr32
|
||||
.globl _ChaCha20_ctr32_nohw
|
||||
.private_extern _ChaCha20_ctr32_nohw
|
||||
#ifdef __thumb2__
|
||||
.thumb_func _ChaCha20_ctr32
|
||||
.thumb_func _ChaCha20_ctr32_nohw
|
||||
#endif
|
||||
.align 5
|
||||
_ChaCha20_ctr32:
|
||||
LChaCha20_ctr32:
|
||||
_ChaCha20_ctr32_nohw:
|
||||
ldr r12,[sp,#0] @ pull pointer to counter and nonce
|
||||
stmdb sp!,{r0,r1,r2,r4-r11,lr}
|
||||
#if __ARM_ARCH__<7 && !defined(__thumb2__)
|
||||
sub r14,pc,#16 @ _ChaCha20_ctr32
|
||||
#else
|
||||
adr r14,LChaCha20_ctr32
|
||||
#endif
|
||||
cmp r2,#0 @ len==0?
|
||||
#ifdef __thumb2__
|
||||
itt eq
|
||||
#endif
|
||||
addeq sp,sp,#4*3
|
||||
beq Lno_data
|
||||
#if __ARM_MAX_ARCH__>=7
|
||||
cmp r2,#192 @ test len
|
||||
bls Lshort
|
||||
ldr r4,[r14,#-32]
|
||||
ldr r4,[r14,r4]
|
||||
# ifdef __APPLE__
|
||||
ldr r4,[r4]
|
||||
# endif
|
||||
tst r4,#ARMV7_NEON
|
||||
bne LChaCha20_neon
|
||||
Lshort:
|
||||
#endif
|
||||
adr r14,Lsigma
|
||||
ldmia r12,{r4,r5,r6,r7} @ load counter and nonce
|
||||
sub sp,sp,#4*(16) @ off-load area
|
||||
sub r14,r14,#64 @ Lsigma
|
||||
stmdb sp!,{r4,r5,r6,r7} @ copy counter and nonce
|
||||
ldmia r3,{r4,r5,r6,r7,r8,r9,r10,r11} @ load key
|
||||
ldmia r14,{r0,r1,r2,r3} @ load sigma
|
||||
@@ -242,8 +204,8 @@ Loop:
|
||||
ldr r8,[sp,#4*(0)] @ load key material
|
||||
ldr r9,[sp,#4*(1)]
|
||||
|
||||
#if __ARM_ARCH__>=6 || !defined(__ARMEB__)
|
||||
# if __ARM_ARCH__<7
|
||||
#if __ARM_ARCH>=6 || !defined(__ARMEB__)
|
||||
# if __ARM_ARCH<7
|
||||
orr r10,r12,r14
|
||||
tst r10,#3 @ are input and output aligned?
|
||||
ldr r10,[sp,#4*(2)]
|
||||
@@ -269,7 +231,7 @@ Loop:
|
||||
# endif
|
||||
ldrhs r10,[r12,#-8]
|
||||
ldrhs r11,[r12,#-4]
|
||||
# if __ARM_ARCH__>=6 && defined(__ARMEB__)
|
||||
# if __ARM_ARCH>=6 && defined(__ARMEB__)
|
||||
rev r0,r0
|
||||
rev r1,r1
|
||||
rev r2,r2
|
||||
@@ -306,7 +268,7 @@ Loop:
|
||||
# endif
|
||||
ldrhs r10,[r12,#-8]
|
||||
ldrhs r11,[r12,#-4]
|
||||
# if __ARM_ARCH__>=6 && defined(__ARMEB__)
|
||||
# if __ARM_ARCH>=6 && defined(__ARMEB__)
|
||||
rev r4,r4
|
||||
rev r5,r5
|
||||
rev r6,r6
|
||||
@@ -351,7 +313,7 @@ Loop:
|
||||
# endif
|
||||
ldrhs r10,[r12,#-8]
|
||||
ldrhs r11,[r12,#-4]
|
||||
# if __ARM_ARCH__>=6 && defined(__ARMEB__)
|
||||
# if __ARM_ARCH>=6 && defined(__ARMEB__)
|
||||
rev r0,r0
|
||||
rev r1,r1
|
||||
rev r2,r2
|
||||
@@ -393,7 +355,7 @@ Loop:
|
||||
# endif
|
||||
ldrhs r10,[r12,#-8]
|
||||
ldrhs r11,[r12,#-4]
|
||||
# if __ARM_ARCH__>=6 && defined(__ARMEB__)
|
||||
# if __ARM_ARCH>=6 && defined(__ARMEB__)
|
||||
rev r4,r4
|
||||
rev r5,r5
|
||||
rev r6,r6
|
||||
@@ -424,7 +386,7 @@ Loop:
|
||||
bhi Loop_outer
|
||||
|
||||
beq Ldone
|
||||
# if __ARM_ARCH__<7
|
||||
# if __ARM_ARCH<7
|
||||
b Ltail
|
||||
|
||||
.align 4
|
||||
@@ -432,7 +394,7 @@ Lunaligned:@ unaligned endian-neutral path
|
||||
cmp r11,#64 @ restore flags
|
||||
# endif
|
||||
#endif
|
||||
#if __ARM_ARCH__<7
|
||||
#if __ARM_ARCH<7
|
||||
ldr r11,[sp,#4*(3)]
|
||||
add r0,r0,r8 @ accumulate key material
|
||||
add r1,r1,r9
|
||||
@@ -808,21 +770,21 @@ Loop_tail:
|
||||
|
||||
Ldone:
|
||||
add sp,sp,#4*(32+3)
|
||||
Lno_data:
|
||||
ldmia sp!,{r4,r5,r6,r7,r8,r9,r10,r11,pc}
|
||||
|
||||
#if __ARM_MAX_ARCH__>=7
|
||||
|
||||
|
||||
|
||||
.globl _ChaCha20_ctr32_neon
|
||||
.private_extern _ChaCha20_ctr32_neon
|
||||
#ifdef __thumb2__
|
||||
.thumb_func ChaCha20_neon
|
||||
.thumb_func _ChaCha20_ctr32_neon
|
||||
#endif
|
||||
.align 5
|
||||
ChaCha20_neon:
|
||||
_ChaCha20_ctr32_neon:
|
||||
ldr r12,[sp,#0] @ pull pointer to counter and nonce
|
||||
stmdb sp!,{r0,r1,r2,r4-r11,lr}
|
||||
LChaCha20_neon:
|
||||
adr r14,Lsigma
|
||||
vstmdb sp!,{d8,d9,d10,d11,d12,d13,d14,d15} @ ABI spec says so
|
||||
stmdb sp!,{r0,r1,r2,r3}
|
||||
@@ -1491,17 +1453,8 @@ Ldone_neon:
|
||||
add sp,sp,#4*(16+3)
|
||||
ldmia sp!,{r4,r5,r6,r7,r8,r9,r10,r11,pc}
|
||||
|
||||
.comm _OPENSSL_armcap_P,4
|
||||
.non_lazy_symbol_pointer
|
||||
OPENSSL_armcap_P:
|
||||
.indirect_symbol _OPENSSL_armcap_P
|
||||
.long 0
|
||||
#endif
|
||||
#endif // !OPENSSL_NO_ASM && defined(__ARMEL__) && defined(__APPLE__)
|
||||
#if defined(__ELF__)
|
||||
// See https://www.airs.com/blog/archives/518.
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
#endif // !OPENSSL_NO_ASM && defined(OPENSSL_ARM) && defined(__APPLE__)
|
||||
#endif // defined(__arm__) && defined(__APPLE__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
|
||||
@@ -3,17 +3,9 @@
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if !defined(__has_feature)
|
||||
#define __has_feature(x) 0
|
||||
#endif
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
#define OPENSSL_NO_ASM
|
||||
#endif
|
||||
#include <CCryptoBoringSSL_asm_base.h>
|
||||
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(__ARMEL__) && defined(__ELF__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
#include <CCryptoBoringSSL_boringssl_prefix_symbols_asm.h>
|
||||
#endif
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_ARM) && defined(__ELF__)
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
@ Silence ARMv8 deprecated IT instruction warnings. This file is used by both
|
||||
@@ -39,47 +31,17 @@
|
||||
.long 0x61707865,0x3320646e,0x79622d32,0x6b206574 @ endian-neutral
|
||||
.Lone:
|
||||
.long 1,0,0,0
|
||||
#if __ARM_MAX_ARCH__>=7
|
||||
.LOPENSSL_armcap:
|
||||
.word OPENSSL_armcap_P-.LChaCha20_ctr32
|
||||
#else
|
||||
.word -1
|
||||
#endif
|
||||
|
||||
.globl ChaCha20_ctr32
|
||||
.hidden ChaCha20_ctr32
|
||||
.type ChaCha20_ctr32,%function
|
||||
.globl ChaCha20_ctr32_nohw
|
||||
.hidden ChaCha20_ctr32_nohw
|
||||
.type ChaCha20_ctr32_nohw,%function
|
||||
.align 5
|
||||
ChaCha20_ctr32:
|
||||
.LChaCha20_ctr32:
|
||||
ChaCha20_ctr32_nohw:
|
||||
ldr r12,[sp,#0] @ pull pointer to counter and nonce
|
||||
stmdb sp!,{r0,r1,r2,r4-r11,lr}
|
||||
#if __ARM_ARCH__<7 && !defined(__thumb2__)
|
||||
sub r14,pc,#16 @ ChaCha20_ctr32
|
||||
#else
|
||||
adr r14,.LChaCha20_ctr32
|
||||
#endif
|
||||
cmp r2,#0 @ len==0?
|
||||
#ifdef __thumb2__
|
||||
itt eq
|
||||
#endif
|
||||
addeq sp,sp,#4*3
|
||||
beq .Lno_data
|
||||
#if __ARM_MAX_ARCH__>=7
|
||||
cmp r2,#192 @ test len
|
||||
bls .Lshort
|
||||
ldr r4,[r14,#-32]
|
||||
ldr r4,[r14,r4]
|
||||
# ifdef __APPLE__
|
||||
ldr r4,[r4]
|
||||
# endif
|
||||
tst r4,#ARMV7_NEON
|
||||
bne .LChaCha20_neon
|
||||
.Lshort:
|
||||
#endif
|
||||
adr r14,.Lsigma
|
||||
ldmia r12,{r4,r5,r6,r7} @ load counter and nonce
|
||||
sub sp,sp,#4*(16) @ off-load area
|
||||
sub r14,r14,#64 @ .Lsigma
|
||||
stmdb sp!,{r4,r5,r6,r7} @ copy counter and nonce
|
||||
ldmia r3,{r4,r5,r6,r7,r8,r9,r10,r11} @ load key
|
||||
ldmia r14,{r0,r1,r2,r3} @ load sigma
|
||||
@@ -240,8 +202,8 @@ ChaCha20_ctr32:
|
||||
ldr r8,[sp,#4*(0)] @ load key material
|
||||
ldr r9,[sp,#4*(1)]
|
||||
|
||||
#if __ARM_ARCH__>=6 || !defined(__ARMEB__)
|
||||
# if __ARM_ARCH__<7
|
||||
#if __ARM_ARCH>=6 || !defined(__ARMEB__)
|
||||
# if __ARM_ARCH<7
|
||||
orr r10,r12,r14
|
||||
tst r10,#3 @ are input and output aligned?
|
||||
ldr r10,[sp,#4*(2)]
|
||||
@@ -267,7 +229,7 @@ ChaCha20_ctr32:
|
||||
# endif
|
||||
ldrhs r10,[r12,#-8]
|
||||
ldrhs r11,[r12,#-4]
|
||||
# if __ARM_ARCH__>=6 && defined(__ARMEB__)
|
||||
# if __ARM_ARCH>=6 && defined(__ARMEB__)
|
||||
rev r0,r0
|
||||
rev r1,r1
|
||||
rev r2,r2
|
||||
@@ -304,7 +266,7 @@ ChaCha20_ctr32:
|
||||
# endif
|
||||
ldrhs r10,[r12,#-8]
|
||||
ldrhs r11,[r12,#-4]
|
||||
# if __ARM_ARCH__>=6 && defined(__ARMEB__)
|
||||
# if __ARM_ARCH>=6 && defined(__ARMEB__)
|
||||
rev r4,r4
|
||||
rev r5,r5
|
||||
rev r6,r6
|
||||
@@ -349,7 +311,7 @@ ChaCha20_ctr32:
|
||||
# endif
|
||||
ldrhs r10,[r12,#-8]
|
||||
ldrhs r11,[r12,#-4]
|
||||
# if __ARM_ARCH__>=6 && defined(__ARMEB__)
|
||||
# if __ARM_ARCH>=6 && defined(__ARMEB__)
|
||||
rev r0,r0
|
||||
rev r1,r1
|
||||
rev r2,r2
|
||||
@@ -391,7 +353,7 @@ ChaCha20_ctr32:
|
||||
# endif
|
||||
ldrhs r10,[r12,#-8]
|
||||
ldrhs r11,[r12,#-4]
|
||||
# if __ARM_ARCH__>=6 && defined(__ARMEB__)
|
||||
# if __ARM_ARCH>=6 && defined(__ARMEB__)
|
||||
rev r4,r4
|
||||
rev r5,r5
|
||||
rev r6,r6
|
||||
@@ -422,7 +384,7 @@ ChaCha20_ctr32:
|
||||
bhi .Loop_outer
|
||||
|
||||
beq .Ldone
|
||||
# if __ARM_ARCH__<7
|
||||
# if __ARM_ARCH<7
|
||||
b .Ltail
|
||||
|
||||
.align 4
|
||||
@@ -430,7 +392,7 @@ ChaCha20_ctr32:
|
||||
cmp r11,#64 @ restore flags
|
||||
# endif
|
||||
#endif
|
||||
#if __ARM_ARCH__<7
|
||||
#if __ARM_ARCH<7
|
||||
ldr r11,[sp,#4*(3)]
|
||||
add r0,r0,r8 @ accumulate key material
|
||||
add r1,r1,r9
|
||||
@@ -806,19 +768,19 @@ ChaCha20_ctr32:
|
||||
|
||||
.Ldone:
|
||||
add sp,sp,#4*(32+3)
|
||||
.Lno_data:
|
||||
ldmia sp!,{r4,r5,r6,r7,r8,r9,r10,r11,pc}
|
||||
.size ChaCha20_ctr32,.-ChaCha20_ctr32
|
||||
.size ChaCha20_ctr32_nohw,.-ChaCha20_ctr32_nohw
|
||||
#if __ARM_MAX_ARCH__>=7
|
||||
.arch armv7-a
|
||||
.fpu neon
|
||||
|
||||
.type ChaCha20_neon,%function
|
||||
.globl ChaCha20_ctr32_neon
|
||||
.hidden ChaCha20_ctr32_neon
|
||||
.type ChaCha20_ctr32_neon,%function
|
||||
.align 5
|
||||
ChaCha20_neon:
|
||||
ChaCha20_ctr32_neon:
|
||||
ldr r12,[sp,#0] @ pull pointer to counter and nonce
|
||||
stmdb sp!,{r0,r1,r2,r4-r11,lr}
|
||||
.LChaCha20_neon:
|
||||
adr r14,.Lsigma
|
||||
vstmdb sp!,{d8,d9,d10,d11,d12,d13,d14,d15} @ ABI spec says so
|
||||
stmdb sp!,{r0,r1,r2,r3}
|
||||
@@ -1486,14 +1448,9 @@ ChaCha20_neon:
|
||||
vldmia sp,{d8,d9,d10,d11,d12,d13,d14,d15}
|
||||
add sp,sp,#4*(16+3)
|
||||
ldmia sp!,{r4,r5,r6,r7,r8,r9,r10,r11,pc}
|
||||
.size ChaCha20_neon,.-ChaCha20_neon
|
||||
.comm OPENSSL_armcap_P,4,4
|
||||
#endif
|
||||
#endif // !OPENSSL_NO_ASM && defined(__ARMEL__) && defined(__ELF__)
|
||||
#if defined(__ELF__)
|
||||
// See https://www.airs.com/blog/archives/518.
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
.size ChaCha20_ctr32_neon,.-ChaCha20_ctr32_neon
|
||||
#endif
|
||||
#endif // !OPENSSL_NO_ASM && defined(OPENSSL_ARM) && defined(__ELF__)
|
||||
#endif // defined(__arm__) && defined(__linux__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
|
||||
@@ -3,22 +3,11 @@
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if !defined(__has_feature)
|
||||
#define __has_feature(x) 0
|
||||
#endif
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
#define OPENSSL_NO_ASM
|
||||
#endif
|
||||
#include <CCryptoBoringSSL_asm_base.h>
|
||||
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(__AARCH64EL__) && defined(__APPLE__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
#include <CCryptoBoringSSL_boringssl_prefix_symbols_asm.h>
|
||||
#endif
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_AARCH64) && defined(__APPLE__)
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
|
||||
.private_extern _OPENSSL_armcap_P
|
||||
|
||||
.section __TEXT,__const
|
||||
|
||||
.align 5
|
||||
@@ -31,25 +20,11 @@ Lone:
|
||||
|
||||
.text
|
||||
|
||||
.globl _ChaCha20_ctr32
|
||||
.private_extern _ChaCha20_ctr32
|
||||
.globl _ChaCha20_ctr32_nohw
|
||||
.private_extern _ChaCha20_ctr32_nohw
|
||||
|
||||
.align 5
|
||||
_ChaCha20_ctr32:
|
||||
AARCH64_VALID_CALL_TARGET
|
||||
cbz x2,Labort
|
||||
#if __has_feature(hwaddress_sanitizer) && __clang_major__ >= 10
|
||||
adrp x5,:pg_hi21_nc:_OPENSSL_armcap_P
|
||||
#else
|
||||
adrp x5,_OPENSSL_armcap_P@PAGE
|
||||
#endif
|
||||
cmp x2,#192
|
||||
b.lo Lshort
|
||||
ldr w17,[x5,_OPENSSL_armcap_P@PAGEOFF]
|
||||
tst w17,#ARMV7_NEON
|
||||
b.ne ChaCha20_neon
|
||||
|
||||
Lshort:
|
||||
_ChaCha20_ctr32_nohw:
|
||||
AARCH64_SIGN_LINK_REGISTER
|
||||
stp x29,x30,[sp,#-96]!
|
||||
add x29,sp,#0
|
||||
@@ -264,7 +239,6 @@ Loop:
|
||||
ldp x27,x28,[x29,#80]
|
||||
ldp x29,x30,[sp],#96
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
Labort:
|
||||
ret
|
||||
|
||||
.align 4
|
||||
@@ -324,9 +298,11 @@ Loop_tail:
|
||||
ret
|
||||
|
||||
|
||||
.globl _ChaCha20_ctr32_neon
|
||||
.private_extern _ChaCha20_ctr32_neon
|
||||
|
||||
.align 5
|
||||
ChaCha20_neon:
|
||||
_ChaCha20_ctr32_neon:
|
||||
AARCH64_SIGN_LINK_REGISTER
|
||||
stp x29,x30,[sp,#-96]!
|
||||
add x29,sp,#0
|
||||
@@ -1991,11 +1967,7 @@ Ldone_512_neon:
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
|
||||
#endif // !OPENSSL_NO_ASM && defined(__AARCH64EL__) && defined(__APPLE__)
|
||||
#if defined(__ELF__)
|
||||
// See https://www.airs.com/blog/archives/518.
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
#endif // !OPENSSL_NO_ASM && defined(OPENSSL_AARCH64) && defined(__APPLE__)
|
||||
#endif // defined(__aarch64__) && defined(__APPLE__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
|
||||
@@ -3,22 +3,11 @@
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if !defined(__has_feature)
|
||||
#define __has_feature(x) 0
|
||||
#endif
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
#define OPENSSL_NO_ASM
|
||||
#endif
|
||||
#include <CCryptoBoringSSL_asm_base.h>
|
||||
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(__AARCH64EL__) && defined(__ELF__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
#include <CCryptoBoringSSL_boringssl_prefix_symbols_asm.h>
|
||||
#endif
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_AARCH64) && defined(__ELF__)
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
|
||||
.hidden OPENSSL_armcap_P
|
||||
|
||||
.section .rodata
|
||||
|
||||
.align 5
|
||||
@@ -31,25 +20,11 @@
|
||||
|
||||
.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 5
|
||||
ChaCha20_ctr32:
|
||||
AARCH64_VALID_CALL_TARGET
|
||||
cbz x2,.Labort
|
||||
#if __has_feature(hwaddress_sanitizer) && __clang_major__ >= 10
|
||||
adrp x5,:pg_hi21_nc:OPENSSL_armcap_P
|
||||
#else
|
||||
adrp x5,OPENSSL_armcap_P
|
||||
#endif
|
||||
cmp x2,#192
|
||||
b.lo .Lshort
|
||||
ldr w17,[x5,:lo12:OPENSSL_armcap_P]
|
||||
tst w17,#ARMV7_NEON
|
||||
b.ne ChaCha20_neon
|
||||
|
||||
.Lshort:
|
||||
ChaCha20_ctr32_nohw:
|
||||
AARCH64_SIGN_LINK_REGISTER
|
||||
stp x29,x30,[sp,#-96]!
|
||||
add x29,sp,#0
|
||||
@@ -264,7 +239,6 @@ ChaCha20_ctr32:
|
||||
ldp x27,x28,[x29,#80]
|
||||
ldp x29,x30,[sp],#96
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
.Labort:
|
||||
ret
|
||||
|
||||
.align 4
|
||||
@@ -322,11 +296,13 @@ ChaCha20_ctr32:
|
||||
ldp x29,x30,[sp],#96
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
.size ChaCha20_ctr32,.-ChaCha20_ctr32
|
||||
.size ChaCha20_ctr32_nohw,.-ChaCha20_ctr32_nohw
|
||||
|
||||
.type ChaCha20_neon,%function
|
||||
.globl ChaCha20_ctr32_neon
|
||||
.hidden ChaCha20_ctr32_neon
|
||||
.type ChaCha20_ctr32_neon,%function
|
||||
.align 5
|
||||
ChaCha20_neon:
|
||||
ChaCha20_ctr32_neon:
|
||||
AARCH64_SIGN_LINK_REGISTER
|
||||
stp x29,x30,[sp,#-96]!
|
||||
add x29,sp,#0
|
||||
@@ -820,7 +796,7 @@ ChaCha20_neon:
|
||||
ldp x29,x30,[sp],#96
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
.size ChaCha20_neon,.-ChaCha20_neon
|
||||
.size ChaCha20_ctr32_neon,.-ChaCha20_ctr32_neon
|
||||
.type ChaCha20_512_neon,%function
|
||||
.align 5
|
||||
ChaCha20_512_neon:
|
||||
@@ -1991,11 +1967,7 @@ ChaCha20_512_neon:
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
ret
|
||||
.size ChaCha20_512_neon,.-ChaCha20_512_neon
|
||||
#endif // !OPENSSL_NO_ASM && defined(__AARCH64EL__) && defined(__ELF__)
|
||||
#if defined(__ELF__)
|
||||
// See https://www.airs.com/blog/archives/518.
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
#endif // !OPENSSL_NO_ASM && defined(OPENSSL_AARCH64) && defined(__ELF__)
|
||||
#endif // defined(__aarch64__) && defined(__linux__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
|
||||
@@ -3,16 +3,9 @@
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
#define OPENSSL_NO_ASM
|
||||
#endif
|
||||
#endif
|
||||
#include <CCryptoBoringSSL_asm_base.h>
|
||||
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(__i386__) && defined(__ELF__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
#include <CCryptoBoringSSL_boringssl_prefix_symbols_asm.h>
|
||||
#endif
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86) && defined(__ELF__)
|
||||
.text
|
||||
.globl ChaCha20_ctr32
|
||||
.hidden ChaCha20_ctr32
|
||||
@@ -979,11 +972,7 @@ ChaCha20_ssse3:
|
||||
.byte 44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32
|
||||
.byte 60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111
|
||||
.byte 114,103,62,0
|
||||
#endif // !defined(OPENSSL_NO_ASM) && defined(__i386__) && defined(__ELF__)
|
||||
#if defined(__ELF__)
|
||||
// See https://www.airs.com/blog/archives/518.
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
#endif // !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86) && defined(__ELF__)
|
||||
#endif // defined(__i386__) && defined(__linux__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
|
||||
@@ -3,16 +3,9 @@
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
#define OPENSSL_NO_ASM
|
||||
#endif
|
||||
#endif
|
||||
#include <CCryptoBoringSSL_asm_base.h>
|
||||
|
||||
#if defined(__x86_64__) && !defined(OPENSSL_NO_ASM) && defined(__ELF__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
#include <CCryptoBoringSSL_boringssl_prefix_symbols_asm.h>
|
||||
#endif
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64) && defined(__ELF__)
|
||||
.text
|
||||
|
||||
.extern OPENSSL_ia32cap_P
|
||||
@@ -55,6 +48,7 @@
|
||||
.align 64
|
||||
ChaCha20_ctr32:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
cmpq $0,%rdx
|
||||
je .Lno_data
|
||||
movq OPENSSL_ia32cap_P+4(%rip),%r10
|
||||
@@ -335,7 +329,7 @@ ChaCha20_ctr32:
|
||||
leaq (%rsi),%rsp
|
||||
.cfi_adjust_cfa_offset -136
|
||||
.Lno_data:
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size ChaCha20_ctr32,.-ChaCha20_ctr32
|
||||
.type ChaCha20_ssse3,@function
|
||||
@@ -472,7 +466,7 @@ ChaCha20_ssse3:
|
||||
leaq (%r9),%rsp
|
||||
.cfi_def_cfa_register rsp
|
||||
.Lssse3_epilogue:
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size ChaCha20_ssse3,.-ChaCha20_ssse3
|
||||
.type ChaCha20_4x,@function
|
||||
@@ -1024,7 +1018,7 @@ ChaCha20_4x:
|
||||
leaq (%r9),%rsp
|
||||
.cfi_def_cfa_register rsp
|
||||
.L4x_epilogue:
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size ChaCha20_4x,.-ChaCha20_4x
|
||||
.type ChaCha20_8x,@function
|
||||
@@ -1630,14 +1624,10 @@ ChaCha20_8x:
|
||||
leaq (%r9),%rsp
|
||||
.cfi_def_cfa_register rsp
|
||||
.L8x_epilogue:
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size ChaCha20_8x,.-ChaCha20_8x
|
||||
#endif
|
||||
#if defined(__ELF__)
|
||||
// See https://www.airs.com/blog/archives/518.
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
#endif // defined(__x86_64__) && defined(__linux__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
|
||||
@@ -3,16 +3,9 @@
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
#define OPENSSL_NO_ASM
|
||||
#endif
|
||||
#endif
|
||||
#include <CCryptoBoringSSL_asm_base.h>
|
||||
|
||||
#if defined(__x86_64__) && !defined(OPENSSL_NO_ASM) && defined(__APPLE__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
#include <CCryptoBoringSSL_boringssl_prefix_symbols_asm.h>
|
||||
#endif
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64) && defined(__APPLE__)
|
||||
.text
|
||||
|
||||
|
||||
@@ -54,6 +47,7 @@ L$sixteen:
|
||||
.p2align 6
|
||||
_ChaCha20_ctr32:
|
||||
|
||||
_CET_ENDBR
|
||||
cmpq $0,%rdx
|
||||
je L$no_data
|
||||
movq _OPENSSL_ia32cap_P+4(%rip),%r10
|
||||
@@ -328,7 +322,7 @@ L$done:
|
||||
leaq (%rsi),%rsp
|
||||
|
||||
L$no_data:
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
|
||||
@@ -465,7 +459,7 @@ L$done_ssse3:
|
||||
leaq (%r9),%rsp
|
||||
|
||||
L$ssse3_epilogue:
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
|
||||
@@ -1017,7 +1011,7 @@ L$done4x:
|
||||
leaq (%r9),%rsp
|
||||
|
||||
L$4x_epilogue:
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
|
||||
@@ -1623,13 +1617,9 @@ L$done8x:
|
||||
leaq (%r9),%rsp
|
||||
|
||||
L$8x_epilogue:
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
#endif
|
||||
#if defined(__ELF__)
|
||||
// See https://www.airs.com/blog/archives/518.
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
#endif // defined(__x86_64__) && defined(__APPLE__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
|
||||
@@ -60,7 +60,22 @@ void CRYPTO_hchacha20(uint8_t out[32], const uint8_t key[32],
|
||||
OPENSSL_memcpy(&out[16], &x[12], sizeof(uint32_t) * 4);
|
||||
}
|
||||
|
||||
#if defined(CHACHA20_ASM)
|
||||
#if defined(CHACHA20_ASM_NOHW)
|
||||
static void ChaCha20_ctr32(uint8_t *out, const uint8_t *in, size_t in_len,
|
||||
const uint32_t key[8], const uint32_t counter[4]) {
|
||||
#if defined(CHACHA20_ASM_NEON)
|
||||
if (ChaCha20_ctr32_neon_capable(in_len)) {
|
||||
ChaCha20_ctr32_neon(out, in, in_len, key, counter);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (in_len > 0) {
|
||||
ChaCha20_ctr32_nohw(out, in, in_len, key, counter);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CHACHA20_ASM) || 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],
|
||||
@@ -91,7 +106,25 @@ void CRYPTO_chacha_20(uint8_t *out, const uint8_t *in, size_t in_len,
|
||||
}
|
||||
#endif
|
||||
|
||||
ChaCha20_ctr32(out, in, in_len, key_ptr, counter_nonce);
|
||||
while (in_len > 0) {
|
||||
// The assembly functions do not have defined overflow behavior. While
|
||||
// overflow is almost always a bug in the caller, we prefer our functions to
|
||||
// behave the same across platforms, so divide into multiple calls to avoid
|
||||
// this case.
|
||||
uint64_t todo = 64 * ((UINT64_C(1) << 32) - counter_nonce[0]);
|
||||
if (todo > in_len) {
|
||||
todo = in_len;
|
||||
}
|
||||
|
||||
ChaCha20_ctr32(out, in, (size_t)todo, key_ptr, counter_nonce);
|
||||
in += todo;
|
||||
out += todo;
|
||||
in_len -= todo;
|
||||
|
||||
// We're either done and will next break out of the loop, or we stopped at
|
||||
// the wraparound point and the counter should continue at zero.
|
||||
counter_nonce[0] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
|
||||
#include <CCryptoBoringSSL_base.h>
|
||||
|
||||
#include "../internal.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -27,16 +29,43 @@ 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) || \
|
||||
defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64))
|
||||
#if !defined(OPENSSL_NO_ASM) && \
|
||||
(defined(OPENSSL_X86) || defined(OPENSSL_X86_64))
|
||||
|
||||
#define CHACHA20_ASM
|
||||
|
||||
// ChaCha20_ctr32 is defined in asm/chacha-*.pl.
|
||||
#elif !defined(OPENSSL_NO_ASM) && \
|
||||
(defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64))
|
||||
|
||||
#define CHACHA20_ASM_NOHW
|
||||
|
||||
#define CHACHA20_ASM_NEON
|
||||
OPENSSL_INLINE int ChaCha20_ctr32_neon_capable(size_t len) {
|
||||
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]);
|
||||
#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.
|
||||
//
|
||||
// |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
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // extern C
|
||||
|
||||
+47
-40
@@ -3,16 +3,9 @@
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
#define OPENSSL_NO_ASM
|
||||
#endif
|
||||
#endif
|
||||
#include <CCryptoBoringSSL_asm_base.h>
|
||||
|
||||
#if defined(__x86_64__) && !defined(OPENSSL_NO_ASM) && defined(__ELF__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
#include <CCryptoBoringSSL_boringssl_prefix_symbols_asm.h>
|
||||
#endif
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64) && defined(__ELF__)
|
||||
.section .rodata
|
||||
|
||||
.align 16
|
||||
@@ -71,7 +64,7 @@ GFMUL:
|
||||
vpxor %xmm4,%xmm3,%xmm2
|
||||
|
||||
vpxor %xmm5,%xmm2,%xmm0
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size GFMUL, .-GFMUL
|
||||
.globl aesgcmsiv_htable_init
|
||||
@@ -80,6 +73,7 @@ GFMUL:
|
||||
.align 16
|
||||
aesgcmsiv_htable_init:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
vmovdqa (%rsi),%xmm0
|
||||
vmovdqa %xmm0,%xmm1
|
||||
vmovdqa %xmm0,(%rdi)
|
||||
@@ -97,7 +91,7 @@ aesgcmsiv_htable_init:
|
||||
vmovdqa %xmm0,96(%rdi)
|
||||
call GFMUL
|
||||
vmovdqa %xmm0,112(%rdi)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aesgcmsiv_htable_init, .-aesgcmsiv_htable_init
|
||||
.globl aesgcmsiv_htable6_init
|
||||
@@ -106,6 +100,7 @@ aesgcmsiv_htable_init:
|
||||
.align 16
|
||||
aesgcmsiv_htable6_init:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
vmovdqa (%rsi),%xmm0
|
||||
vmovdqa %xmm0,%xmm1
|
||||
vmovdqa %xmm0,(%rdi)
|
||||
@@ -119,7 +114,7 @@ aesgcmsiv_htable6_init:
|
||||
vmovdqa %xmm0,64(%rdi)
|
||||
call GFMUL
|
||||
vmovdqa %xmm0,80(%rdi)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aesgcmsiv_htable6_init, .-aesgcmsiv_htable6_init
|
||||
.globl aesgcmsiv_htable_polyval
|
||||
@@ -128,9 +123,10 @@ aesgcmsiv_htable6_init:
|
||||
.align 16
|
||||
aesgcmsiv_htable_polyval:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
testq %rdx,%rdx
|
||||
jnz .Lhtable_polyval_start
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
.Lhtable_polyval_start:
|
||||
vzeroall
|
||||
@@ -336,7 +332,7 @@ aesgcmsiv_htable_polyval:
|
||||
|
||||
vmovdqu %xmm1,(%rcx)
|
||||
vzeroupper
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aesgcmsiv_htable_polyval,.-aesgcmsiv_htable_polyval
|
||||
.globl aesgcmsiv_polyval_horner
|
||||
@@ -345,9 +341,10 @@ aesgcmsiv_htable_polyval:
|
||||
.align 16
|
||||
aesgcmsiv_polyval_horner:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
testq %rcx,%rcx
|
||||
jnz .Lpolyval_horner_start
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
.Lpolyval_horner_start:
|
||||
|
||||
@@ -369,7 +366,7 @@ aesgcmsiv_polyval_horner:
|
||||
|
||||
|
||||
vmovdqa %xmm0,(%rdi)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aesgcmsiv_polyval_horner,.-aesgcmsiv_polyval_horner
|
||||
.globl aes128gcmsiv_aes_ks
|
||||
@@ -378,6 +375,7 @@ aesgcmsiv_polyval_horner:
|
||||
.align 16
|
||||
aes128gcmsiv_aes_ks:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
vmovdqu (%rdi),%xmm1
|
||||
vmovdqa %xmm1,(%rsi)
|
||||
|
||||
@@ -425,7 +423,7 @@ aes128gcmsiv_aes_ks:
|
||||
vpxor %xmm3,%xmm1,%xmm1
|
||||
vpxor %xmm2,%xmm1,%xmm1
|
||||
vmovdqa %xmm1,32(%rsi)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aes128gcmsiv_aes_ks,.-aes128gcmsiv_aes_ks
|
||||
.globl aes256gcmsiv_aes_ks
|
||||
@@ -434,6 +432,7 @@ aes128gcmsiv_aes_ks:
|
||||
.align 16
|
||||
aes256gcmsiv_aes_ks:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
vmovdqu (%rdi),%xmm1
|
||||
vmovdqu 16(%rdi),%xmm3
|
||||
vmovdqa %xmm1,(%rsi)
|
||||
@@ -473,7 +472,7 @@ aes256gcmsiv_aes_ks:
|
||||
vpxor %xmm4,%xmm1,%xmm1
|
||||
vpxor %xmm2,%xmm1,%xmm1
|
||||
vmovdqa %xmm1,32(%rsi)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.globl aes128gcmsiv_aes_ks_enc_x1
|
||||
.hidden aes128gcmsiv_aes_ks_enc_x1
|
||||
@@ -481,6 +480,7 @@ aes256gcmsiv_aes_ks:
|
||||
.align 16
|
||||
aes128gcmsiv_aes_ks_enc_x1:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
vmovdqa (%rcx),%xmm1
|
||||
vmovdqa 0(%rdi),%xmm4
|
||||
|
||||
@@ -614,7 +614,7 @@ aes128gcmsiv_aes_ks_enc_x1:
|
||||
|
||||
|
||||
vmovdqa %xmm4,0(%rsi)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aes128gcmsiv_aes_ks_enc_x1,.-aes128gcmsiv_aes_ks_enc_x1
|
||||
.globl aes128gcmsiv_kdf
|
||||
@@ -623,6 +623,7 @@ aes128gcmsiv_aes_ks_enc_x1:
|
||||
.align 16
|
||||
aes128gcmsiv_kdf:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
|
||||
|
||||
|
||||
@@ -707,7 +708,7 @@ aes128gcmsiv_kdf:
|
||||
vmovdqa %xmm10,16(%rsi)
|
||||
vmovdqa %xmm11,32(%rsi)
|
||||
vmovdqa %xmm12,48(%rsi)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aes128gcmsiv_kdf,.-aes128gcmsiv_kdf
|
||||
.globl aes128gcmsiv_enc_msg_x4
|
||||
@@ -716,9 +717,10 @@ aes128gcmsiv_kdf:
|
||||
.align 16
|
||||
aes128gcmsiv_enc_msg_x4:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
testq %r8,%r8
|
||||
jnz .L128_enc_msg_x4_start
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
.L128_enc_msg_x4_start:
|
||||
pushq %r12
|
||||
@@ -886,7 +888,7 @@ aes128gcmsiv_enc_msg_x4:
|
||||
popq %r12
|
||||
.cfi_adjust_cfa_offset -8
|
||||
.cfi_restore %r12
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aes128gcmsiv_enc_msg_x4,.-aes128gcmsiv_enc_msg_x4
|
||||
.globl aes128gcmsiv_enc_msg_x8
|
||||
@@ -895,9 +897,10 @@ aes128gcmsiv_enc_msg_x4:
|
||||
.align 16
|
||||
aes128gcmsiv_enc_msg_x8:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
testq %r8,%r8
|
||||
jnz .L128_enc_msg_x8_start
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
.L128_enc_msg_x8_start:
|
||||
pushq %r12
|
||||
@@ -1147,7 +1150,7 @@ aes128gcmsiv_enc_msg_x8:
|
||||
popq %r12
|
||||
.cfi_adjust_cfa_offset -8
|
||||
.cfi_restore %r12
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aes128gcmsiv_enc_msg_x8,.-aes128gcmsiv_enc_msg_x8
|
||||
.globl aes128gcmsiv_dec
|
||||
@@ -1156,9 +1159,10 @@ aes128gcmsiv_enc_msg_x8:
|
||||
.align 16
|
||||
aes128gcmsiv_dec:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
testq $~15,%r9
|
||||
jnz .L128_dec_start
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
.L128_dec_start:
|
||||
vzeroupper
|
||||
@@ -1639,7 +1643,7 @@ aes128gcmsiv_dec:
|
||||
|
||||
.L128_dec_out:
|
||||
vmovdqu %xmm0,(%rdx)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aes128gcmsiv_dec, .-aes128gcmsiv_dec
|
||||
.globl aes128gcmsiv_ecb_enc_block
|
||||
@@ -1648,6 +1652,7 @@ aes128gcmsiv_dec:
|
||||
.align 16
|
||||
aes128gcmsiv_ecb_enc_block:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
vmovdqa (%rdi),%xmm1
|
||||
|
||||
vpxor (%rdx),%xmm1,%xmm1
|
||||
@@ -1664,7 +1669,7 @@ aes128gcmsiv_ecb_enc_block:
|
||||
|
||||
vmovdqa %xmm1,(%rsi)
|
||||
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aes128gcmsiv_ecb_enc_block,.-aes128gcmsiv_ecb_enc_block
|
||||
.globl aes256gcmsiv_aes_ks_enc_x1
|
||||
@@ -1673,6 +1678,7 @@ aes128gcmsiv_ecb_enc_block:
|
||||
.align 16
|
||||
aes256gcmsiv_aes_ks_enc_x1:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
vmovdqa con1(%rip),%xmm0
|
||||
vmovdqa mask(%rip),%xmm15
|
||||
vmovdqa (%rdi),%xmm8
|
||||
@@ -1847,7 +1853,7 @@ aes256gcmsiv_aes_ks_enc_x1:
|
||||
vmovdqu %xmm1,224(%rdx)
|
||||
|
||||
vmovdqa %xmm8,(%rsi)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aes256gcmsiv_aes_ks_enc_x1,.-aes256gcmsiv_aes_ks_enc_x1
|
||||
.globl aes256gcmsiv_ecb_enc_block
|
||||
@@ -1856,6 +1862,7 @@ aes256gcmsiv_aes_ks_enc_x1:
|
||||
.align 16
|
||||
aes256gcmsiv_ecb_enc_block:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
vmovdqa (%rdi),%xmm1
|
||||
vpxor (%rdx),%xmm1,%xmm1
|
||||
vaesenc 16(%rdx),%xmm1,%xmm1
|
||||
@@ -1873,7 +1880,7 @@ aes256gcmsiv_ecb_enc_block:
|
||||
vaesenc 208(%rdx),%xmm1,%xmm1
|
||||
vaesenclast 224(%rdx),%xmm1,%xmm1
|
||||
vmovdqa %xmm1,(%rsi)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aes256gcmsiv_ecb_enc_block,.-aes256gcmsiv_ecb_enc_block
|
||||
.globl aes256gcmsiv_enc_msg_x4
|
||||
@@ -1882,9 +1889,10 @@ aes256gcmsiv_ecb_enc_block:
|
||||
.align 16
|
||||
aes256gcmsiv_enc_msg_x4:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
testq %r8,%r8
|
||||
jnz .L256_enc_msg_x4_start
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
.L256_enc_msg_x4_start:
|
||||
movq %r8,%r10
|
||||
@@ -2074,7 +2082,7 @@ aes256gcmsiv_enc_msg_x4:
|
||||
jne .L256_enc_msg_x4_loop2
|
||||
|
||||
.L256_enc_msg_x4_out:
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aes256gcmsiv_enc_msg_x4,.-aes256gcmsiv_enc_msg_x4
|
||||
.globl aes256gcmsiv_enc_msg_x8
|
||||
@@ -2083,9 +2091,10 @@ aes256gcmsiv_enc_msg_x4:
|
||||
.align 16
|
||||
aes256gcmsiv_enc_msg_x8:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
testq %r8,%r8
|
||||
jnz .L256_enc_msg_x8_start
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
.L256_enc_msg_x8_start:
|
||||
|
||||
@@ -2362,7 +2371,7 @@ aes256gcmsiv_enc_msg_x8:
|
||||
jnz .L256_enc_msg_x8_loop2
|
||||
|
||||
.L256_enc_msg_x8_out:
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
.cfi_endproc
|
||||
.size aes256gcmsiv_enc_msg_x8,.-aes256gcmsiv_enc_msg_x8
|
||||
@@ -2372,9 +2381,10 @@ aes256gcmsiv_enc_msg_x8:
|
||||
.align 16
|
||||
aes256gcmsiv_dec:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
testq $~15,%r9
|
||||
jnz .L256_dec_start
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
.L256_dec_start:
|
||||
vzeroupper
|
||||
@@ -2923,7 +2933,7 @@ aes256gcmsiv_dec:
|
||||
|
||||
.L256_dec_out:
|
||||
vmovdqu %xmm0,(%rdx)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aes256gcmsiv_dec, .-aes256gcmsiv_dec
|
||||
.globl aes256gcmsiv_kdf
|
||||
@@ -2932,6 +2942,7 @@ aes256gcmsiv_dec:
|
||||
.align 16
|
||||
aes256gcmsiv_kdf:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
|
||||
|
||||
|
||||
@@ -3074,14 +3085,10 @@ aes256gcmsiv_kdf:
|
||||
vmovdqa %xmm11,48(%rsi)
|
||||
vmovdqa %xmm12,64(%rsi)
|
||||
vmovdqa %xmm13,80(%rsi)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aes256gcmsiv_kdf, .-aes256gcmsiv_kdf
|
||||
#endif
|
||||
#if defined(__ELF__)
|
||||
// See https://www.airs.com/blog/archives/518.
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
#endif // defined(__x86_64__) && defined(__linux__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
|
||||
@@ -3,16 +3,9 @@
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
#define OPENSSL_NO_ASM
|
||||
#endif
|
||||
#endif
|
||||
#include <CCryptoBoringSSL_asm_base.h>
|
||||
|
||||
#if defined(__x86_64__) && !defined(OPENSSL_NO_ASM) && defined(__APPLE__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
#include <CCryptoBoringSSL_boringssl_prefix_symbols_asm.h>
|
||||
#endif
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64) && defined(__APPLE__)
|
||||
.section __DATA,__const
|
||||
|
||||
.p2align 4
|
||||
@@ -71,7 +64,7 @@ GFMUL:
|
||||
vpxor %xmm4,%xmm3,%xmm2
|
||||
|
||||
vpxor %xmm5,%xmm2,%xmm0
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aesgcmsiv_htable_init
|
||||
@@ -80,6 +73,7 @@ GFMUL:
|
||||
.p2align 4
|
||||
_aesgcmsiv_htable_init:
|
||||
|
||||
_CET_ENDBR
|
||||
vmovdqa (%rsi),%xmm0
|
||||
vmovdqa %xmm0,%xmm1
|
||||
vmovdqa %xmm0,(%rdi)
|
||||
@@ -97,7 +91,7 @@ _aesgcmsiv_htable_init:
|
||||
vmovdqa %xmm0,96(%rdi)
|
||||
call GFMUL
|
||||
vmovdqa %xmm0,112(%rdi)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aesgcmsiv_htable6_init
|
||||
@@ -106,6 +100,7 @@ _aesgcmsiv_htable_init:
|
||||
.p2align 4
|
||||
_aesgcmsiv_htable6_init:
|
||||
|
||||
_CET_ENDBR
|
||||
vmovdqa (%rsi),%xmm0
|
||||
vmovdqa %xmm0,%xmm1
|
||||
vmovdqa %xmm0,(%rdi)
|
||||
@@ -119,7 +114,7 @@ _aesgcmsiv_htable6_init:
|
||||
vmovdqa %xmm0,64(%rdi)
|
||||
call GFMUL
|
||||
vmovdqa %xmm0,80(%rdi)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aesgcmsiv_htable_polyval
|
||||
@@ -128,9 +123,10 @@ _aesgcmsiv_htable6_init:
|
||||
.p2align 4
|
||||
_aesgcmsiv_htable_polyval:
|
||||
|
||||
_CET_ENDBR
|
||||
testq %rdx,%rdx
|
||||
jnz L$htable_polyval_start
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
L$htable_polyval_start:
|
||||
vzeroall
|
||||
@@ -336,7 +332,7 @@ L$htable_polyval_out:
|
||||
|
||||
vmovdqu %xmm1,(%rcx)
|
||||
vzeroupper
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aesgcmsiv_polyval_horner
|
||||
@@ -345,9 +341,10 @@ L$htable_polyval_out:
|
||||
.p2align 4
|
||||
_aesgcmsiv_polyval_horner:
|
||||
|
||||
_CET_ENDBR
|
||||
testq %rcx,%rcx
|
||||
jnz L$polyval_horner_start
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
L$polyval_horner_start:
|
||||
|
||||
@@ -369,7 +366,7 @@ L$polyval_horner_loop:
|
||||
|
||||
|
||||
vmovdqa %xmm0,(%rdi)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aes128gcmsiv_aes_ks
|
||||
@@ -378,6 +375,7 @@ L$polyval_horner_loop:
|
||||
.p2align 4
|
||||
_aes128gcmsiv_aes_ks:
|
||||
|
||||
_CET_ENDBR
|
||||
vmovdqu (%rdi),%xmm1
|
||||
vmovdqa %xmm1,(%rsi)
|
||||
|
||||
@@ -425,7 +423,7 @@ L$ks128_loop:
|
||||
vpxor %xmm3,%xmm1,%xmm1
|
||||
vpxor %xmm2,%xmm1,%xmm1
|
||||
vmovdqa %xmm1,32(%rsi)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aes256gcmsiv_aes_ks
|
||||
@@ -434,6 +432,7 @@ L$ks128_loop:
|
||||
.p2align 4
|
||||
_aes256gcmsiv_aes_ks:
|
||||
|
||||
_CET_ENDBR
|
||||
vmovdqu (%rdi),%xmm1
|
||||
vmovdqu 16(%rdi),%xmm3
|
||||
vmovdqa %xmm1,(%rsi)
|
||||
@@ -473,7 +472,7 @@ L$ks256_loop:
|
||||
vpxor %xmm4,%xmm1,%xmm1
|
||||
vpxor %xmm2,%xmm1,%xmm1
|
||||
vmovdqa %xmm1,32(%rsi)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
.globl _aes128gcmsiv_aes_ks_enc_x1
|
||||
.private_extern _aes128gcmsiv_aes_ks_enc_x1
|
||||
@@ -481,6 +480,7 @@ L$ks256_loop:
|
||||
.p2align 4
|
||||
_aes128gcmsiv_aes_ks_enc_x1:
|
||||
|
||||
_CET_ENDBR
|
||||
vmovdqa (%rcx),%xmm1
|
||||
vmovdqa 0(%rdi),%xmm4
|
||||
|
||||
@@ -614,7 +614,7 @@ _aes128gcmsiv_aes_ks_enc_x1:
|
||||
|
||||
|
||||
vmovdqa %xmm4,0(%rsi)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aes128gcmsiv_kdf
|
||||
@@ -623,6 +623,7 @@ _aes128gcmsiv_aes_ks_enc_x1:
|
||||
.p2align 4
|
||||
_aes128gcmsiv_kdf:
|
||||
|
||||
_CET_ENDBR
|
||||
|
||||
|
||||
|
||||
@@ -707,7 +708,7 @@ _aes128gcmsiv_kdf:
|
||||
vmovdqa %xmm10,16(%rsi)
|
||||
vmovdqa %xmm11,32(%rsi)
|
||||
vmovdqa %xmm12,48(%rsi)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aes128gcmsiv_enc_msg_x4
|
||||
@@ -716,9 +717,10 @@ _aes128gcmsiv_kdf:
|
||||
.p2align 4
|
||||
_aes128gcmsiv_enc_msg_x4:
|
||||
|
||||
_CET_ENDBR
|
||||
testq %r8,%r8
|
||||
jnz L$128_enc_msg_x4_start
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
L$128_enc_msg_x4_start:
|
||||
pushq %r12
|
||||
@@ -882,7 +884,7 @@ L$128_enc_msg_x4_out:
|
||||
|
||||
popq %r12
|
||||
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aes128gcmsiv_enc_msg_x8
|
||||
@@ -891,9 +893,10 @@ L$128_enc_msg_x4_out:
|
||||
.p2align 4
|
||||
_aes128gcmsiv_enc_msg_x8:
|
||||
|
||||
_CET_ENDBR
|
||||
testq %r8,%r8
|
||||
jnz L$128_enc_msg_x8_start
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
L$128_enc_msg_x8_start:
|
||||
pushq %r12
|
||||
@@ -1137,7 +1140,7 @@ L$128_enc_msg_x8_out:
|
||||
|
||||
popq %r12
|
||||
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aes128gcmsiv_dec
|
||||
@@ -1146,9 +1149,10 @@ L$128_enc_msg_x8_out:
|
||||
.p2align 4
|
||||
_aes128gcmsiv_dec:
|
||||
|
||||
_CET_ENDBR
|
||||
testq $~15,%r9
|
||||
jnz L$128_dec_start
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
L$128_dec_start:
|
||||
vzeroupper
|
||||
@@ -1629,7 +1633,7 @@ L$128_dec_loop2:
|
||||
|
||||
L$128_dec_out:
|
||||
vmovdqu %xmm0,(%rdx)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aes128gcmsiv_ecb_enc_block
|
||||
@@ -1638,6 +1642,7 @@ L$128_dec_out:
|
||||
.p2align 4
|
||||
_aes128gcmsiv_ecb_enc_block:
|
||||
|
||||
_CET_ENDBR
|
||||
vmovdqa (%rdi),%xmm1
|
||||
|
||||
vpxor (%rdx),%xmm1,%xmm1
|
||||
@@ -1654,7 +1659,7 @@ _aes128gcmsiv_ecb_enc_block:
|
||||
|
||||
vmovdqa %xmm1,(%rsi)
|
||||
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aes256gcmsiv_aes_ks_enc_x1
|
||||
@@ -1663,6 +1668,7 @@ _aes128gcmsiv_ecb_enc_block:
|
||||
.p2align 4
|
||||
_aes256gcmsiv_aes_ks_enc_x1:
|
||||
|
||||
_CET_ENDBR
|
||||
vmovdqa con1(%rip),%xmm0
|
||||
vmovdqa mask(%rip),%xmm15
|
||||
vmovdqa (%rdi),%xmm8
|
||||
@@ -1837,7 +1843,7 @@ _aes256gcmsiv_aes_ks_enc_x1:
|
||||
vmovdqu %xmm1,224(%rdx)
|
||||
|
||||
vmovdqa %xmm8,(%rsi)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aes256gcmsiv_ecb_enc_block
|
||||
@@ -1846,6 +1852,7 @@ _aes256gcmsiv_aes_ks_enc_x1:
|
||||
.p2align 4
|
||||
_aes256gcmsiv_ecb_enc_block:
|
||||
|
||||
_CET_ENDBR
|
||||
vmovdqa (%rdi),%xmm1
|
||||
vpxor (%rdx),%xmm1,%xmm1
|
||||
vaesenc 16(%rdx),%xmm1,%xmm1
|
||||
@@ -1863,7 +1870,7 @@ _aes256gcmsiv_ecb_enc_block:
|
||||
vaesenc 208(%rdx),%xmm1,%xmm1
|
||||
vaesenclast 224(%rdx),%xmm1,%xmm1
|
||||
vmovdqa %xmm1,(%rsi)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aes256gcmsiv_enc_msg_x4
|
||||
@@ -1872,9 +1879,10 @@ _aes256gcmsiv_ecb_enc_block:
|
||||
.p2align 4
|
||||
_aes256gcmsiv_enc_msg_x4:
|
||||
|
||||
_CET_ENDBR
|
||||
testq %r8,%r8
|
||||
jnz L$256_enc_msg_x4_start
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
L$256_enc_msg_x4_start:
|
||||
movq %r8,%r10
|
||||
@@ -2064,7 +2072,7 @@ L$256_enc_msg_x4_loop2:
|
||||
jne L$256_enc_msg_x4_loop2
|
||||
|
||||
L$256_enc_msg_x4_out:
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aes256gcmsiv_enc_msg_x8
|
||||
@@ -2073,9 +2081,10 @@ L$256_enc_msg_x4_out:
|
||||
.p2align 4
|
||||
_aes256gcmsiv_enc_msg_x8:
|
||||
|
||||
_CET_ENDBR
|
||||
testq %r8,%r8
|
||||
jnz L$256_enc_msg_x8_start
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
L$256_enc_msg_x8_start:
|
||||
|
||||
@@ -2352,7 +2361,7 @@ L$256_enc_msg_x8_loop2:
|
||||
jnz L$256_enc_msg_x8_loop2
|
||||
|
||||
L$256_enc_msg_x8_out:
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
|
||||
@@ -2362,9 +2371,10 @@ L$256_enc_msg_x8_out:
|
||||
.p2align 4
|
||||
_aes256gcmsiv_dec:
|
||||
|
||||
_CET_ENDBR
|
||||
testq $~15,%r9
|
||||
jnz L$256_dec_start
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
L$256_dec_start:
|
||||
vzeroupper
|
||||
@@ -2913,7 +2923,7 @@ L$256_dec_loop2:
|
||||
|
||||
L$256_dec_out:
|
||||
vmovdqu %xmm0,(%rdx)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aes256gcmsiv_kdf
|
||||
@@ -2922,6 +2932,7 @@ L$256_dec_out:
|
||||
.p2align 4
|
||||
_aes256gcmsiv_kdf:
|
||||
|
||||
_CET_ENDBR
|
||||
|
||||
|
||||
|
||||
@@ -3064,13 +3075,9 @@ _aes256gcmsiv_kdf:
|
||||
vmovdqa %xmm11,48(%rsi)
|
||||
vmovdqa %xmm12,64(%rsi)
|
||||
vmovdqa %xmm13,80(%rsi)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
#endif
|
||||
#if defined(__ELF__)
|
||||
// See https://www.airs.com/blog/archives/518.
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
#endif // defined(__x86_64__) && defined(__APPLE__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
|
||||
+3
-15
@@ -3,17 +3,9 @@
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if !defined(__has_feature)
|
||||
#define __has_feature(x) 0
|
||||
#endif
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
#define OPENSSL_NO_ASM
|
||||
#endif
|
||||
#include <CCryptoBoringSSL_asm_base.h>
|
||||
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(__AARCH64EL__) && defined(__APPLE__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
#include <CCryptoBoringSSL_boringssl_prefix_symbols_asm.h>
|
||||
#endif
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_AARCH64) && defined(__APPLE__)
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
.section __TEXT,__const
|
||||
|
||||
@@ -3016,11 +3008,7 @@ Lopen_128_hash_64:
|
||||
b Lopen_128_hash_64
|
||||
.cfi_endproc
|
||||
|
||||
#endif // !OPENSSL_NO_ASM && defined(__AARCH64EL__) && defined(__APPLE__)
|
||||
#if defined(__ELF__)
|
||||
// See https://www.airs.com/blog/archives/518.
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
#endif // !OPENSSL_NO_ASM && defined(OPENSSL_AARCH64) && defined(__APPLE__)
|
||||
#endif // defined(__aarch64__) && defined(__APPLE__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
|
||||
+3
-15
@@ -3,17 +3,9 @@
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if !defined(__has_feature)
|
||||
#define __has_feature(x) 0
|
||||
#endif
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
#define OPENSSL_NO_ASM
|
||||
#endif
|
||||
#include <CCryptoBoringSSL_asm_base.h>
|
||||
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(__AARCH64EL__) && defined(__ELF__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
#include <CCryptoBoringSSL_boringssl_prefix_symbols_asm.h>
|
||||
#endif
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_AARCH64) && defined(__ELF__)
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
.section .rodata
|
||||
|
||||
@@ -3016,11 +3008,7 @@ chacha20_poly1305_open:
|
||||
b .Lopen_128_hash_64
|
||||
.cfi_endproc
|
||||
.size chacha20_poly1305_open,.-chacha20_poly1305_open
|
||||
#endif // !OPENSSL_NO_ASM && defined(__AARCH64EL__) && defined(__ELF__)
|
||||
#if defined(__ELF__)
|
||||
// See https://www.airs.com/blog/archives/518.
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
#endif // !OPENSSL_NO_ASM && defined(OPENSSL_AARCH64) && defined(__ELF__)
|
||||
#endif // defined(__aarch64__) && defined(__linux__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
|
||||
+8
-17
@@ -3,16 +3,9 @@
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
#define OPENSSL_NO_ASM
|
||||
#endif
|
||||
#endif
|
||||
#include <CCryptoBoringSSL_asm_base.h>
|
||||
|
||||
#if defined(__x86_64__) && !defined(OPENSSL_NO_ASM) && defined(__ELF__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
#include <CCryptoBoringSSL_boringssl_prefix_symbols_asm.h>
|
||||
#endif
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64) && defined(__ELF__)
|
||||
.text
|
||||
.extern OPENSSL_ia32cap_P
|
||||
.hidden OPENSSL_ia32cap_P
|
||||
@@ -113,7 +106,7 @@ poly_hash_ad_internal:
|
||||
adcq %r9,%r11
|
||||
adcq $0,%r12
|
||||
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.Lhash_ad_loop:
|
||||
|
||||
cmpq $16,%r8
|
||||
@@ -222,7 +215,7 @@ poly_hash_ad_internal:
|
||||
|
||||
|
||||
.Lhash_ad_done:
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size poly_hash_ad_internal, .-poly_hash_ad_internal
|
||||
|
||||
@@ -232,6 +225,7 @@ poly_hash_ad_internal:
|
||||
.align 64
|
||||
chacha20_poly1305_open:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
pushq %rbp
|
||||
.cfi_adjust_cfa_offset 8
|
||||
.cfi_offset %rbp,-16
|
||||
@@ -1870,7 +1864,7 @@ chacha20_poly1305_open:
|
||||
popq %rbp
|
||||
.cfi_adjust_cfa_offset -8
|
||||
.cfi_restore %rbp
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
.Lopen_sse_128:
|
||||
.cfi_restore_state
|
||||
@@ -2117,6 +2111,7 @@ chacha20_poly1305_open:
|
||||
.align 64
|
||||
chacha20_poly1305_seal:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
pushq %rbp
|
||||
.cfi_adjust_cfa_offset 8
|
||||
.cfi_offset %rbp,-16
|
||||
@@ -3935,7 +3930,7 @@ process_extra_in_trailer:
|
||||
popq %rbp
|
||||
.cfi_adjust_cfa_offset -8
|
||||
.cfi_restore %rbp
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
.Lseal_sse_128:
|
||||
.cfi_restore_state
|
||||
@@ -8923,10 +8918,6 @@ chacha20_poly1305_seal_avx2:
|
||||
.cfi_endproc
|
||||
.size chacha20_poly1305_seal_avx2, .-chacha20_poly1305_seal_avx2
|
||||
#endif
|
||||
#if defined(__ELF__)
|
||||
// See https://www.airs.com/blog/archives/518.
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
#endif // defined(__x86_64__) && defined(__linux__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
|
||||
+8
-17
@@ -3,16 +3,9 @@
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
#define OPENSSL_NO_ASM
|
||||
#endif
|
||||
#endif
|
||||
#include <CCryptoBoringSSL_asm_base.h>
|
||||
|
||||
#if defined(__x86_64__) && !defined(OPENSSL_NO_ASM) && defined(__APPLE__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
#include <CCryptoBoringSSL_boringssl_prefix_symbols_asm.h>
|
||||
#endif
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64) && defined(__APPLE__)
|
||||
.text
|
||||
|
||||
|
||||
@@ -112,7 +105,7 @@ L$poly_fast_tls_ad:
|
||||
adcq %r9,%r11
|
||||
adcq $0,%r12
|
||||
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
L$hash_ad_loop:
|
||||
|
||||
cmpq $16,%r8
|
||||
@@ -221,7 +214,7 @@ L$hash_ad_tail_loop:
|
||||
|
||||
|
||||
L$hash_ad_done:
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
|
||||
@@ -231,6 +224,7 @@ L$hash_ad_done:
|
||||
.p2align 6
|
||||
_chacha20_poly1305_open:
|
||||
|
||||
_CET_ENDBR
|
||||
pushq %rbp
|
||||
|
||||
pushq %rbx
|
||||
@@ -1855,7 +1849,7 @@ L$open_sse_finalize:
|
||||
|
||||
popq %rbp
|
||||
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
L$open_sse_128:
|
||||
|
||||
@@ -2102,6 +2096,7 @@ L$open_sse_128_xor_hash:
|
||||
.p2align 6
|
||||
_chacha20_poly1305_seal:
|
||||
|
||||
_CET_ENDBR
|
||||
pushq %rbp
|
||||
|
||||
pushq %rbx
|
||||
@@ -3906,7 +3901,7 @@ L$do_length_block:
|
||||
|
||||
popq %rbp
|
||||
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
L$seal_sse_128:
|
||||
|
||||
@@ -8879,10 +8874,6 @@ L$seal_avx2_exit:
|
||||
jmp L$seal_sse_tail_16
|
||||
|
||||
|
||||
#endif
|
||||
#if defined(__ELF__)
|
||||
// See https://www.airs.com/blog/archives/518.
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
#endif // defined(__x86_64__) && defined(__APPLE__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
|
||||
@@ -400,6 +400,14 @@ static int aead_aes_128_cbc_sha1_tls_implicit_iv_init(
|
||||
EVP_sha1(), 1);
|
||||
}
|
||||
|
||||
static int aead_aes_128_cbc_sha256_tls_init(EVP_AEAD_CTX *ctx,
|
||||
const uint8_t *key, size_t key_len,
|
||||
size_t tag_len,
|
||||
enum evp_aead_direction_t dir) {
|
||||
return aead_tls_init(ctx, key, key_len, tag_len, dir, EVP_aes_128_cbc(),
|
||||
EVP_sha256(), 0);
|
||||
}
|
||||
|
||||
static int aead_aes_256_cbc_sha1_tls_init(EVP_AEAD_CTX *ctx, const uint8_t *key,
|
||||
size_t key_len, size_t tag_len,
|
||||
enum evp_aead_direction_t dir) {
|
||||
@@ -442,13 +450,6 @@ static int aead_tls_get_iv(const EVP_AEAD_CTX *ctx, const uint8_t **out_iv,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int aead_null_sha1_tls_init(EVP_AEAD_CTX *ctx, const uint8_t *key,
|
||||
size_t key_len, size_t tag_len,
|
||||
enum evp_aead_direction_t dir) {
|
||||
return aead_tls_init(ctx, key, key_len, tag_len, dir, EVP_enc_null(),
|
||||
EVP_sha1(), 1 /* implicit iv */);
|
||||
}
|
||||
|
||||
static const EVP_AEAD aead_aes_128_cbc_sha1_tls = {
|
||||
SHA_DIGEST_LENGTH + 16, // key len (SHA1 + AES128)
|
||||
16, // nonce len (IV)
|
||||
@@ -483,6 +484,23 @@ static const EVP_AEAD aead_aes_128_cbc_sha1_tls_implicit_iv = {
|
||||
aead_tls_tag_len,
|
||||
};
|
||||
|
||||
static const EVP_AEAD aead_aes_128_cbc_sha256_tls = {
|
||||
SHA256_DIGEST_LENGTH + 16, // key len (SHA256 + AES128)
|
||||
16, // nonce len (IV)
|
||||
16 + SHA256_DIGEST_LENGTH, // overhead (padding + SHA256)
|
||||
SHA256_DIGEST_LENGTH, // max tag length
|
||||
0, // seal_scatter_supports_extra_in
|
||||
|
||||
NULL, // init
|
||||
aead_aes_128_cbc_sha256_tls_init,
|
||||
aead_tls_cleanup,
|
||||
aead_tls_open,
|
||||
aead_tls_seal_scatter,
|
||||
NULL, // open_gather
|
||||
NULL, // get_iv
|
||||
aead_tls_tag_len,
|
||||
};
|
||||
|
||||
static const EVP_AEAD aead_aes_256_cbc_sha1_tls = {
|
||||
SHA_DIGEST_LENGTH + 32, // key len (SHA1 + AES256)
|
||||
16, // nonce len (IV)
|
||||
@@ -551,23 +569,6 @@ static const EVP_AEAD aead_des_ede3_cbc_sha1_tls_implicit_iv = {
|
||||
aead_tls_tag_len,
|
||||
};
|
||||
|
||||
static const EVP_AEAD aead_null_sha1_tls = {
|
||||
SHA_DIGEST_LENGTH, // key len
|
||||
0, // nonce len
|
||||
SHA_DIGEST_LENGTH, // overhead (SHA1)
|
||||
SHA_DIGEST_LENGTH, // max tag length
|
||||
0, // seal_scatter_supports_extra_in
|
||||
|
||||
NULL, // init
|
||||
aead_null_sha1_tls_init,
|
||||
aead_tls_cleanup,
|
||||
aead_tls_open,
|
||||
aead_tls_seal_scatter,
|
||||
NULL, // open_gather
|
||||
NULL, // get_iv
|
||||
aead_tls_tag_len,
|
||||
};
|
||||
|
||||
const EVP_AEAD *EVP_aead_aes_128_cbc_sha1_tls(void) {
|
||||
return &aead_aes_128_cbc_sha1_tls;
|
||||
}
|
||||
@@ -576,6 +577,10 @@ const EVP_AEAD *EVP_aead_aes_128_cbc_sha1_tls_implicit_iv(void) {
|
||||
return &aead_aes_128_cbc_sha1_tls_implicit_iv;
|
||||
}
|
||||
|
||||
const EVP_AEAD *EVP_aead_aes_128_cbc_sha256_tls(void) {
|
||||
return &aead_aes_128_cbc_sha256_tls;
|
||||
}
|
||||
|
||||
const EVP_AEAD *EVP_aead_aes_256_cbc_sha1_tls(void) {
|
||||
return &aead_aes_256_cbc_sha1_tls;
|
||||
}
|
||||
@@ -591,5 +596,3 @@ const EVP_AEAD *EVP_aead_des_ede3_cbc_sha1_tls(void) {
|
||||
const EVP_AEAD *EVP_aead_des_ede3_cbc_sha1_tls_implicit_iv(void) {
|
||||
return &aead_des_ede3_cbc_sha1_tls_implicit_iv;
|
||||
}
|
||||
|
||||
const EVP_AEAD *EVP_aead_null_sha1_tls(void) { return &aead_null_sha1_tls; }
|
||||
@@ -109,6 +109,14 @@ OPENSSL_EXPORT int EVP_sha1_final_with_secret_suffix(
|
||||
SHA_CTX *ctx, uint8_t out[SHA_DIGEST_LENGTH], const uint8_t *in, size_t len,
|
||||
size_t max_len);
|
||||
|
||||
// EVP_sha256_final_with_secret_suffix acts like
|
||||
// |EVP_sha1_final_with_secret_suffix|, but for SHA-256.
|
||||
//
|
||||
// This function is exported for unit tests.
|
||||
OPENSSL_EXPORT int EVP_sha256_final_with_secret_suffix(
|
||||
SHA256_CTX *ctx, uint8_t out[SHA256_DIGEST_LENGTH], const uint8_t *in,
|
||||
size_t len, size_t max_len);
|
||||
|
||||
// EVP_tls_cbc_digest_record computes the MAC of a decrypted, padded TLS
|
||||
// record.
|
||||
//
|
||||
|
||||
@@ -267,24 +267,115 @@ int EVP_sha1_final_with_secret_suffix(SHA_CTX *ctx,
|
||||
return 1;
|
||||
}
|
||||
|
||||
int EVP_tls_cbc_record_digest_supported(const EVP_MD *md) {
|
||||
return EVP_MD_type(md) == NID_sha1;
|
||||
}
|
||||
|
||||
int EVP_tls_cbc_digest_record(const EVP_MD *md, uint8_t *md_out,
|
||||
size_t *md_out_size, const uint8_t header[13],
|
||||
const uint8_t *data, size_t data_size,
|
||||
size_t data_plus_mac_plus_padding_size,
|
||||
const uint8_t *mac_secret,
|
||||
unsigned mac_secret_length) {
|
||||
if (EVP_MD_type(md) != NID_sha1) {
|
||||
// EVP_tls_cbc_record_digest_supported should have been called first to
|
||||
// check that the hash function is supported.
|
||||
assert(0);
|
||||
*md_out_size = 0;
|
||||
return 0;
|
||||
int EVP_sha256_final_with_secret_suffix(SHA256_CTX *ctx,
|
||||
uint8_t out[SHA256_DIGEST_LENGTH],
|
||||
const uint8_t *in, size_t len,
|
||||
size_t max_len) {
|
||||
// Bound the input length so |total_bits| below fits in four bytes. This is
|
||||
// redundant with TLS record size limits. This also ensures |input_idx| below
|
||||
// does not overflow.
|
||||
size_t max_len_bits = max_len << 3;
|
||||
if (ctx->Nh != 0 ||
|
||||
(max_len_bits >> 3) != max_len || // Overflow
|
||||
ctx->Nl + max_len_bits < max_len_bits ||
|
||||
ctx->Nl + max_len_bits > UINT32_MAX) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// We need to hash the following into |ctx|:
|
||||
//
|
||||
// - ctx->data[:ctx->num]
|
||||
// - in[:len]
|
||||
// - A 0x80 byte
|
||||
// - However many zero bytes are needed to pad up to a block.
|
||||
// - Eight bytes of length.
|
||||
size_t num_blocks = (ctx->num + len + 1 + 8 + SHA256_CBLOCK - 1) >> 6;
|
||||
size_t last_block = num_blocks - 1;
|
||||
size_t max_blocks = (ctx->num + max_len + 1 + 8 + SHA256_CBLOCK - 1) >> 6;
|
||||
|
||||
// The bounds above imply |total_bits| fits in four bytes.
|
||||
size_t total_bits = ctx->Nl + (len << 3);
|
||||
uint8_t length_bytes[4];
|
||||
length_bytes[0] = (uint8_t)(total_bits >> 24);
|
||||
length_bytes[1] = (uint8_t)(total_bits >> 16);
|
||||
length_bytes[2] = (uint8_t)(total_bits >> 8);
|
||||
length_bytes[3] = (uint8_t)total_bits;
|
||||
|
||||
// We now construct and process each expected block in constant-time.
|
||||
uint8_t block[SHA256_CBLOCK] = {0};
|
||||
uint32_t result[8] = {0};
|
||||
// input_idx is the index into |in| corresponding to the current block.
|
||||
// However, we allow this index to overflow beyond |max_len|, to simplify the
|
||||
// 0x80 byte.
|
||||
size_t input_idx = 0;
|
||||
for (size_t i = 0; i < max_blocks; i++) {
|
||||
// Fill |block| with data from the partial block in |ctx| and |in|. We copy
|
||||
// as if we were hashing up to |max_len| and then zero the excess later.
|
||||
size_t block_start = 0;
|
||||
if (i == 0) {
|
||||
OPENSSL_memcpy(block, ctx->data, ctx->num);
|
||||
block_start = ctx->num;
|
||||
}
|
||||
if (input_idx < max_len) {
|
||||
size_t to_copy = SHA256_CBLOCK - block_start;
|
||||
if (to_copy > max_len - input_idx) {
|
||||
to_copy = max_len - input_idx;
|
||||
}
|
||||
OPENSSL_memcpy(block + block_start, in + input_idx, to_copy);
|
||||
}
|
||||
|
||||
// Zero any bytes beyond |len| and add the 0x80 byte.
|
||||
for (size_t j = block_start; j < SHA256_CBLOCK; j++) {
|
||||
// input[idx] corresponds to block[j].
|
||||
size_t idx = input_idx + j - block_start;
|
||||
// The barriers on |len| are not strictly necessary. However, without
|
||||
// them, GCC compiles this code by incorporating |len| into the loop
|
||||
// counter and subtracting it out later. This is still constant-time, but
|
||||
// it frustrates attempts to validate this.
|
||||
uint8_t is_in_bounds = constant_time_lt_8(idx, value_barrier_w(len));
|
||||
uint8_t is_padding_byte = constant_time_eq_8(idx, value_barrier_w(len));
|
||||
block[j] &= is_in_bounds;
|
||||
block[j] |= 0x80 & is_padding_byte;
|
||||
}
|
||||
|
||||
input_idx += SHA256_CBLOCK - block_start;
|
||||
|
||||
// Fill in the length if this is the last block.
|
||||
crypto_word_t is_last_block = constant_time_eq_w(i, last_block);
|
||||
for (size_t j = 0; j < 4; j++) {
|
||||
block[SHA256_CBLOCK - 4 + j] |= is_last_block & length_bytes[j];
|
||||
}
|
||||
|
||||
// Process the block and save the hash state if it is the final value.
|
||||
SHA256_Transform(ctx, block);
|
||||
for (size_t j = 0; j < 8; j++) {
|
||||
result[j] |= is_last_block & ctx->h[j];
|
||||
}
|
||||
}
|
||||
|
||||
// Write the output.
|
||||
for (size_t i = 0; i < 8; i++) {
|
||||
CRYPTO_store_u32_be(out + 4 * i, result[i]);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int EVP_tls_cbc_record_digest_supported(const EVP_MD *md) {
|
||||
switch (EVP_MD_type(md)) {
|
||||
case NID_sha1:
|
||||
case NID_sha256:
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static int tls_cbc_digest_record_sha1(uint8_t *md_out, size_t *md_out_size,
|
||||
const uint8_t header[13],
|
||||
const uint8_t *data, size_t data_size,
|
||||
size_t data_plus_mac_plus_padding_size,
|
||||
const uint8_t *mac_secret,
|
||||
unsigned mac_secret_length) {
|
||||
if (mac_secret_length > SHA_CBLOCK) {
|
||||
// HMAC pads small keys with zeros and hashes large keys down. This function
|
||||
// should never reach the large key case.
|
||||
@@ -336,3 +427,88 @@ int EVP_tls_cbc_digest_record(const EVP_MD *md, uint8_t *md_out,
|
||||
*md_out_size = SHA_DIGEST_LENGTH;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tls_cbc_digest_record_sha256(uint8_t *md_out, size_t *md_out_size,
|
||||
const uint8_t header[13],
|
||||
const uint8_t *data, size_t data_size,
|
||||
size_t data_plus_mac_plus_padding_size,
|
||||
const uint8_t *mac_secret,
|
||||
unsigned mac_secret_length) {
|
||||
if (mac_secret_length > SHA256_CBLOCK) {
|
||||
// HMAC pads small keys with zeros and hashes large keys down. This function
|
||||
// should never reach the large key case.
|
||||
assert(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Compute the initial HMAC block.
|
||||
uint8_t hmac_pad[SHA256_CBLOCK];
|
||||
OPENSSL_memset(hmac_pad, 0, sizeof(hmac_pad));
|
||||
OPENSSL_memcpy(hmac_pad, mac_secret, mac_secret_length);
|
||||
for (size_t i = 0; i < SHA256_CBLOCK; i++) {
|
||||
hmac_pad[i] ^= 0x36;
|
||||
}
|
||||
|
||||
SHA256_CTX ctx;
|
||||
SHA256_Init(&ctx);
|
||||
SHA256_Update(&ctx, hmac_pad, SHA256_CBLOCK);
|
||||
SHA256_Update(&ctx, header, 13);
|
||||
|
||||
// There are at most 256 bytes of padding, so we can compute the public
|
||||
// minimum length for |data_size|.
|
||||
size_t min_data_size = 0;
|
||||
if (data_plus_mac_plus_padding_size > SHA256_DIGEST_LENGTH + 256) {
|
||||
min_data_size =
|
||||
data_plus_mac_plus_padding_size - SHA256_DIGEST_LENGTH - 256;
|
||||
}
|
||||
|
||||
// Hash the public minimum length directly. This reduces the number of blocks
|
||||
// that must be computed in constant-time.
|
||||
SHA256_Update(&ctx, data, min_data_size);
|
||||
|
||||
// Hash the remaining data without leaking |data_size|.
|
||||
uint8_t mac_out[SHA256_DIGEST_LENGTH];
|
||||
if (!EVP_sha256_final_with_secret_suffix(
|
||||
&ctx, mac_out, data + min_data_size, data_size - min_data_size,
|
||||
data_plus_mac_plus_padding_size - min_data_size)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Complete the HMAC in the standard manner.
|
||||
SHA256_Init(&ctx);
|
||||
for (size_t i = 0; i < SHA256_CBLOCK; i++) {
|
||||
hmac_pad[i] ^= 0x6a;
|
||||
}
|
||||
|
||||
SHA256_Update(&ctx, hmac_pad, SHA256_CBLOCK);
|
||||
SHA256_Update(&ctx, mac_out, SHA256_DIGEST_LENGTH);
|
||||
SHA256_Final(md_out, &ctx);
|
||||
*md_out_size = SHA256_DIGEST_LENGTH;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int EVP_tls_cbc_digest_record(const EVP_MD *md, uint8_t *md_out,
|
||||
size_t *md_out_size, const uint8_t header[13],
|
||||
const uint8_t *data, size_t data_size,
|
||||
size_t data_plus_mac_plus_padding_size,
|
||||
const uint8_t *mac_secret,
|
||||
unsigned mac_secret_length) {
|
||||
switch (EVP_MD_type(md)) {
|
||||
case NID_sha1:
|
||||
return tls_cbc_digest_record_sha1(
|
||||
md_out, md_out_size, header, data, data_size,
|
||||
data_plus_mac_plus_padding_size, mac_secret, mac_secret_length);
|
||||
|
||||
case NID_sha256:
|
||||
return tls_cbc_digest_record_sha256(
|
||||
md_out, md_out_size, header, data, data_size,
|
||||
data_plus_mac_plus_padding_size, mac_secret, mac_secret_length);
|
||||
|
||||
default:
|
||||
// EVP_tls_cbc_record_digest_supported should have been called first to
|
||||
// check that the hash function is supported.
|
||||
assert(0);
|
||||
*md_out_size = 0;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -68,21 +68,10 @@
|
||||
#include "conf_def.h"
|
||||
#include "internal.h"
|
||||
#include "../internal.h"
|
||||
#include "../lhash/internal.h"
|
||||
|
||||
|
||||
DEFINE_LHASH_OF(CONF_VALUE)
|
||||
|
||||
struct conf_st {
|
||||
LHASH_OF(CONF_VALUE) *data;
|
||||
};
|
||||
|
||||
static const char kDefaultSectionName[] = "default";
|
||||
|
||||
// The maximum length we can grow a value to after variable expansion. 64k
|
||||
// should be more than enough for all reasonable uses.
|
||||
#define MAX_CONF_VALUE_LENGTH 65536
|
||||
|
||||
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;
|
||||
@@ -129,34 +118,26 @@ CONF *NCONF_new(void *method) {
|
||||
return conf;
|
||||
}
|
||||
|
||||
CONF_VALUE *CONF_VALUE_new(void) {
|
||||
CONF_VALUE *v = OPENSSL_malloc(sizeof(CONF_VALUE));
|
||||
if (!v) {
|
||||
return NULL;
|
||||
}
|
||||
OPENSSL_memset(v, 0, sizeof(CONF_VALUE));
|
||||
return v;
|
||||
}
|
||||
CONF_VALUE *CONF_VALUE_new(void) { return OPENSSL_zalloc(sizeof(CONF_VALUE)); }
|
||||
|
||||
static void value_free_contents(CONF_VALUE *value) {
|
||||
if (value->section) {
|
||||
OPENSSL_free(value->section);
|
||||
}
|
||||
OPENSSL_free(value->section);
|
||||
if (value->name) {
|
||||
OPENSSL_free(value->name);
|
||||
if (value->value) {
|
||||
OPENSSL_free(value->value);
|
||||
}
|
||||
OPENSSL_free(value->value);
|
||||
} else {
|
||||
if (value->value) {
|
||||
sk_CONF_VALUE_free((STACK_OF(CONF_VALUE)*)value->value);
|
||||
}
|
||||
// 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) {
|
||||
value_free_contents(value);
|
||||
OPENSSL_free(value);
|
||||
if (value != NULL) {
|
||||
value_free_contents(value);
|
||||
OPENSSL_free(value);
|
||||
}
|
||||
}
|
||||
|
||||
static void value_free_arg(CONF_VALUE *value, void *arg) { value_free(value); }
|
||||
@@ -192,28 +173,21 @@ static CONF_VALUE *NCONF_new_section(const CONF *conf, const char *section) {
|
||||
if (!lh_CONF_VALUE_insert(conf->data, &old_value, v)) {
|
||||
goto err;
|
||||
}
|
||||
if (old_value) {
|
||||
value_free(old_value);
|
||||
}
|
||||
value_free(old_value);
|
||||
ok = 1;
|
||||
|
||||
err:
|
||||
if (!ok) {
|
||||
if (sk != NULL) {
|
||||
sk_CONF_VALUE_free(sk);
|
||||
}
|
||||
if (v != NULL) {
|
||||
OPENSSL_free(v);
|
||||
}
|
||||
sk_CONF_VALUE_free(sk);
|
||||
OPENSSL_free(v);
|
||||
v = NULL;
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
static int str_copy(CONF *conf, char *section, char **pto, char *from) {
|
||||
int q, r, rr = 0, to = 0, len = 0;
|
||||
char *s, *e, *rp, *rrp, *np, *cp, v;
|
||||
const char *p;
|
||||
int q, to = 0, len = 0;
|
||||
char v;
|
||||
BUF_MEM *buf;
|
||||
|
||||
buf = BUF_MEM_new();
|
||||
@@ -242,22 +216,6 @@ static int str_copy(CONF *conf, char *section, char **pto, char *from) {
|
||||
if (*from == q) {
|
||||
from++;
|
||||
}
|
||||
} else if (IS_DQUOTE(conf, *from)) {
|
||||
q = *from;
|
||||
from++;
|
||||
while (!IS_EOF(conf, *from)) {
|
||||
if (*from == q) {
|
||||
if (*(from + 1) == q) {
|
||||
from++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
buf->data[to++] = *(from++);
|
||||
}
|
||||
if (*from == q) {
|
||||
from++;
|
||||
}
|
||||
} else if (IS_ESC(conf, *from)) {
|
||||
from++;
|
||||
v = *(from++);
|
||||
@@ -276,102 +234,23 @@ static int str_copy(CONF *conf, char *section, char **pto, char *from) {
|
||||
} else if (IS_EOF(conf, *from)) {
|
||||
break;
|
||||
} else if (*from == '$') {
|
||||
// try to expand it
|
||||
rrp = NULL;
|
||||
s = &(from[1]);
|
||||
if (*s == '{') {
|
||||
q = '}';
|
||||
} else if (*s == '(') {
|
||||
q = ')';
|
||||
} else {
|
||||
q = 0;
|
||||
}
|
||||
|
||||
if (q) {
|
||||
s++;
|
||||
}
|
||||
cp = section;
|
||||
e = np = s;
|
||||
while (IS_ALPHA_NUMERIC(conf, *e)) {
|
||||
e++;
|
||||
}
|
||||
if (e[0] == ':' && e[1] == ':') {
|
||||
cp = np;
|
||||
rrp = e;
|
||||
rr = *e;
|
||||
*rrp = '\0';
|
||||
e += 2;
|
||||
np = e;
|
||||
while (IS_ALPHA_NUMERIC(conf, *e)) {
|
||||
e++;
|
||||
}
|
||||
}
|
||||
r = *e;
|
||||
*e = '\0';
|
||||
rp = e;
|
||||
if (q) {
|
||||
if (r != q) {
|
||||
OPENSSL_PUT_ERROR(CONF, CONF_R_NO_CLOSE_BRACE);
|
||||
goto err;
|
||||
}
|
||||
e++;
|
||||
}
|
||||
// So at this point we have
|
||||
// np which is the start of the name string which is
|
||||
// '\0' terminated.
|
||||
// cp which is the start of the section string which is
|
||||
// '\0' terminated.
|
||||
// e is the 'next point after'.
|
||||
// r and rr are the chars replaced by the '\0'
|
||||
// rp and rrp is where 'r' and 'rr' came from.
|
||||
p = NCONF_get_string(conf, cp, np);
|
||||
if (rrp != NULL) {
|
||||
*rrp = rr;
|
||||
}
|
||||
*rp = r;
|
||||
if (p == NULL) {
|
||||
OPENSSL_PUT_ERROR(CONF, CONF_R_VARIABLE_HAS_NO_VALUE);
|
||||
goto err;
|
||||
}
|
||||
size_t newsize = strlen(p) + buf->length - (e - from);
|
||||
if (newsize > MAX_CONF_VALUE_LENGTH) {
|
||||
OPENSSL_PUT_ERROR(CONF, CONF_R_VARIABLE_EXPANSION_TOO_LONG);
|
||||
goto err;
|
||||
}
|
||||
if (!BUF_MEM_grow_clean(buf, newsize)) {
|
||||
goto err;
|
||||
}
|
||||
while (*p) {
|
||||
buf->data[to++] = *(p++);
|
||||
}
|
||||
|
||||
/* Since we change the pointer 'from', we also have
|
||||
to change the perceived length of the string it
|
||||
points at. /RL */
|
||||
len -= e - from;
|
||||
from = e;
|
||||
|
||||
/* In case there were no braces or parenthesis around
|
||||
the variable reference, we have to put back the
|
||||
character that was replaced with a '\0'. /RL */
|
||||
*rp = r;
|
||||
// Historically, $foo would expand to a previously-parsed value. This
|
||||
// feature has been removed as it was unused and is a DoS vector.
|
||||
OPENSSL_PUT_ERROR(CONF, CONF_R_VARIABLE_EXPANSION_NOT_SUPPORTED);
|
||||
goto err;
|
||||
} else {
|
||||
buf->data[to++] = *(from++);
|
||||
}
|
||||
}
|
||||
|
||||
buf->data[to] = '\0';
|
||||
if (*pto != NULL) {
|
||||
OPENSSL_free(*pto);
|
||||
}
|
||||
OPENSSL_free(*pto);
|
||||
*pto = buf->data;
|
||||
OPENSSL_free(buf);
|
||||
return 1;
|
||||
|
||||
err:
|
||||
if (buf != NULL) {
|
||||
BUF_MEM_free(buf);
|
||||
}
|
||||
BUF_MEM_free(buf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -472,33 +351,8 @@ static char *scan_quote(CONF *conf, char *p) {
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
static char *scan_dquote(CONF *conf, char *p) {
|
||||
int q = *p;
|
||||
|
||||
p++;
|
||||
while (!(IS_EOF(conf, *p))) {
|
||||
if (*p == q) {
|
||||
if (*(p + 1) == q) {
|
||||
p++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
p++;
|
||||
}
|
||||
if (*p == q) {
|
||||
p++;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
static void clear_comments(CONF *conf, char *p) {
|
||||
for (;;) {
|
||||
if (IS_FCOMMENT(conf, *p)) {
|
||||
*p = '\0';
|
||||
return;
|
||||
}
|
||||
if (!IS_WS(conf, *p)) {
|
||||
break;
|
||||
}
|
||||
@@ -510,10 +364,6 @@ static void clear_comments(CONF *conf, char *p) {
|
||||
*p = '\0';
|
||||
return;
|
||||
}
|
||||
if (IS_DQUOTE(conf, *p)) {
|
||||
p = scan_dquote(conf, p);
|
||||
continue;
|
||||
}
|
||||
if (IS_QUOTE(conf, *p)) {
|
||||
p = scan_quote(conf, p);
|
||||
continue;
|
||||
@@ -530,7 +380,7 @@ static void clear_comments(CONF *conf, char *p) {
|
||||
}
|
||||
}
|
||||
|
||||
static int def_load_bio(CONF *conf, BIO *in, long *out_error_line) {
|
||||
int NCONF_load_bio(CONF *conf, BIO *in, long *out_error_line) {
|
||||
static const size_t CONFBUFSIZE = 512;
|
||||
int bufnum = 0, i, ii;
|
||||
BUF_MEM *buff = NULL;
|
||||
@@ -707,37 +557,23 @@ static int def_load_bio(CONF *conf, BIO *in, long *out_error_line) {
|
||||
v = NULL;
|
||||
}
|
||||
}
|
||||
if (buff != NULL) {
|
||||
BUF_MEM_free(buff);
|
||||
}
|
||||
if (section != NULL) {
|
||||
OPENSSL_free(section);
|
||||
}
|
||||
BUF_MEM_free(buff);
|
||||
OPENSSL_free(section);
|
||||
return 1;
|
||||
|
||||
err:
|
||||
if (buff != NULL) {
|
||||
BUF_MEM_free(buff);
|
||||
}
|
||||
if (section != NULL) {
|
||||
OPENSSL_free(section);
|
||||
}
|
||||
BUF_MEM_free(buff);
|
||||
OPENSSL_free(section);
|
||||
if (out_error_line != NULL) {
|
||||
*out_error_line = eline;
|
||||
}
|
||||
BIO_snprintf(btmp, sizeof btmp, "%ld", eline);
|
||||
snprintf(btmp, sizeof btmp, "%ld", eline);
|
||||
ERR_add_error_data(2, "line ", btmp);
|
||||
|
||||
if (v != NULL) {
|
||||
if (v->name != NULL) {
|
||||
OPENSSL_free(v->name);
|
||||
}
|
||||
if (v->value != NULL) {
|
||||
OPENSSL_free(v->value);
|
||||
}
|
||||
if (v != NULL) {
|
||||
OPENSSL_free(v);
|
||||
}
|
||||
OPENSSL_free(v->name);
|
||||
OPENSSL_free(v->value);
|
||||
OPENSSL_free(v);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -751,16 +587,12 @@ int NCONF_load(CONF *conf, const char *filename, long *out_error_line) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = def_load_bio(conf, in, out_error_line);
|
||||
ret = NCONF_load_bio(conf, in, out_error_line);
|
||||
BIO_free(in);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int NCONF_load_bio(CONF *conf, BIO *bio, long *out_error_line) {
|
||||
return def_load_bio(conf, bio, out_error_line);
|
||||
}
|
||||
|
||||
int CONF_parse_list(const char *list, char sep, int remove_whitespace,
|
||||
int (*list_cb)(const char *elem, size_t len, void *usr),
|
||||
void *arg) {
|
||||
|
||||
@@ -55,8 +55,9 @@
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
/* THIS FILE WAS AUTOMAGICALLY GENERATED!
|
||||
Please modify and use keysets.pl to regenerate it. */
|
||||
// This file was historically generated by keysets.pl in OpenSSL.
|
||||
//
|
||||
// TODO(davidben): Replace it with something more readable.
|
||||
|
||||
#define CONF_NUMBER 1
|
||||
#define CONF_UPPER 2
|
||||
@@ -66,9 +67,7 @@
|
||||
#define CONF_WS 16
|
||||
#define CONF_ESC 32
|
||||
#define CONF_QUOTE 64
|
||||
#define CONF_DQUOTE 1024
|
||||
#define CONF_COMMENT 128
|
||||
#define CONF_FCOMMENT 2048
|
||||
#define CONF_EOF 8
|
||||
#define CONF_HIGHBIT 4096
|
||||
#define CONF_ALPHA (CONF_UPPER|CONF_LOWER)
|
||||
@@ -78,7 +77,6 @@
|
||||
|
||||
#define KEYTYPES(c) CONF_type_default
|
||||
#define IS_COMMENT(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_COMMENT)
|
||||
#define IS_FCOMMENT(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_FCOMMENT)
|
||||
#define IS_EOF(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_EOF)
|
||||
#define IS_ESC(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_ESC)
|
||||
#define IS_NUMBER(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_NUMBER)
|
||||
@@ -87,8 +85,6 @@
|
||||
#define IS_ALPHA_NUMERIC_PUNCT(c,a) \
|
||||
(KEYTYPES(c)[(a)&0xff]&CONF_ALPHA_NUMERIC_PUNCT)
|
||||
#define IS_QUOTE(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_QUOTE)
|
||||
#define IS_DQUOTE(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_DQUOTE)
|
||||
#define IS_HIGHBIT(c,a) (KEYTYPES(c)[(a)&0xff]&CONF_HIGHBIT)
|
||||
|
||||
static const unsigned short CONF_type_default[256]={
|
||||
0x0008,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,
|
||||
|
||||
@@ -17,11 +17,19 @@
|
||||
|
||||
#include <CCryptoBoringSSL_base.h>
|
||||
|
||||
#include "../lhash/internal.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
DEFINE_LHASH_OF(CONF_VALUE)
|
||||
|
||||
struct conf_st {
|
||||
LHASH_OF(CONF_VALUE) *data;
|
||||
};
|
||||
|
||||
// CONF_VALUE_new returns a freshly allocated and zeroed |CONF_VALUE|.
|
||||
CONF_VALUE *CONF_VALUE_new(void);
|
||||
|
||||
|
||||
@@ -23,8 +23,6 @@
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
|
||||
extern uint32_t OPENSSL_armcap_P;
|
||||
|
||||
static int has_hw_feature(const char *name) {
|
||||
int value;
|
||||
size_t len = sizeof(value);
|
||||
@@ -65,6 +63,9 @@ void OPENSSL_cpuid_setup(void) {
|
||||
// available in macOS 12. For compatibility with macOS 11, we also support
|
||||
// the old names. The old names don't have values for features like FEAT_AES,
|
||||
// so instead we detect them statically above.
|
||||
//
|
||||
// If querying new sysctls, update the Chromium sandbox definition. See
|
||||
// https://crrev.com/c/4415225.
|
||||
if (has_hw_feature("hw.optional.arm.FEAT_SHA512") ||
|
||||
has_hw_feature("hw.optional.armv8_2_sha512")) {
|
||||
OPENSSL_armcap_P |= ARMV8_SHA512;
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
extern uint32_t OPENSSL_armcap_P;
|
||||
|
||||
void OPENSSL_cpuid_setup(void) {
|
||||
uint32_t hwcap;
|
||||
|
||||
@@ -22,8 +22,6 @@
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
|
||||
extern uint32_t OPENSSL_armcap_P;
|
||||
|
||||
void OPENSSL_cpuid_setup(void) {
|
||||
unsigned long hwcap = getauxval(AT_HWCAP);
|
||||
|
||||
|
||||
+23
-24
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2022, Google Inc.
|
||||
/* Copyright (c) 2022, Robert Nagy <robert.nagy@gmail.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -12,51 +12,50 @@
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
#include "internal.h"
|
||||
#include <CCryptoBoringSSL_cpu.h>
|
||||
|
||||
#if defined(OPENSSL_AARCH64) && defined(OPENSSL_FREEBSD) && \
|
||||
#if defined(OPENSSL_AARCH64) && defined(OPENSSL_OPENBSD) && \
|
||||
!defined(OPENSSL_STATIC_ARMCAP)
|
||||
|
||||
#include <sys/sysctl.h>
|
||||
#include <machine/cpu.h>
|
||||
#include <machine/armreg.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
extern uint32_t OPENSSL_armcap_P;
|
||||
#include "internal.h"
|
||||
|
||||
// ID_AA64ISAR0_*_VAL are defined starting FreeBSD 13.0. When FreeBSD
|
||||
// 12.x is out of support, these compatibility macros can be removed.
|
||||
|
||||
#ifndef ID_AA64ISAR0_AES_VAL
|
||||
#define ID_AA64ISAR0_AES_VAL ID_AA64ISAR0_AES
|
||||
#endif
|
||||
#ifndef ID_AA64ISAR0_SHA1_VAL
|
||||
#define ID_AA64ISAR0_SHA1_VAL ID_AA64ISAR0_SHA1
|
||||
#endif
|
||||
#ifndef ID_AA64ISAR0_SHA2_VAL
|
||||
#define ID_AA64ISAR0_SHA2_VAL ID_AA64ISAR0_SHA2
|
||||
#endif
|
||||
|
||||
void OPENSSL_cpuid_setup(void) {
|
||||
uint64_t id_aa64isar0 = READ_SPECIALREG(id_aa64isar0_el1);
|
||||
int isar0_mib[] = { CTL_MACHDEP, CPU_ID_AA64ISAR0 };
|
||||
uint64_t cpu_id = 0;
|
||||
size_t len = sizeof(cpu_id);
|
||||
|
||||
if (sysctl(isar0_mib, 2, &cpu_id, &len, NULL, 0) < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
OPENSSL_armcap_P |= ARMV7_NEON;
|
||||
|
||||
if (ID_AA64ISAR0_AES_VAL(id_aa64isar0) >= ID_AA64ISAR0_AES_BASE) {
|
||||
if (ID_AA64ISAR0_AES(cpu_id) >= ID_AA64ISAR0_AES_BASE) {
|
||||
OPENSSL_armcap_P |= ARMV8_AES;
|
||||
}
|
||||
if (ID_AA64ISAR0_AES_VAL(id_aa64isar0) >= ID_AA64ISAR0_AES_PMULL) {
|
||||
|
||||
if (ID_AA64ISAR0_AES(cpu_id) >= ID_AA64ISAR0_AES_PMULL) {
|
||||
OPENSSL_armcap_P |= ARMV8_PMULL;
|
||||
}
|
||||
if (ID_AA64ISAR0_SHA1_VAL(id_aa64isar0) >= ID_AA64ISAR0_SHA1_BASE) {
|
||||
|
||||
if (ID_AA64ISAR0_SHA1(cpu_id) >= ID_AA64ISAR0_SHA1_BASE) {
|
||||
OPENSSL_armcap_P |= ARMV8_SHA1;
|
||||
}
|
||||
if (ID_AA64ISAR0_SHA2_VAL(id_aa64isar0) >= ID_AA64ISAR0_SHA2_BASE) {
|
||||
|
||||
if (ID_AA64ISAR0_SHA2(cpu_id) >= ID_AA64ISAR0_SHA2_BASE) {
|
||||
OPENSSL_armcap_P |= ARMV8_SHA256;
|
||||
}
|
||||
if (ID_AA64ISAR0_SHA2_VAL(id_aa64isar0) >= ID_AA64ISAR0_SHA2_512) {
|
||||
|
||||
if (ID_AA64ISAR0_SHA2(cpu_id) >= ID_AA64ISAR0_SHA2_512) {
|
||||
OPENSSL_armcap_P |= ARMV8_SHA512;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OPENSSL_AARCH64 && OPENSSL_FREEBSD && !OPENSSL_STATIC_ARMCAP
|
||||
#endif // OPENSSL_AARCH64 && OPENSSL_OPENBSD && !OPENSSL_STATIC_ARMCAP
|
||||
@@ -0,0 +1,93 @@
|
||||
/* Copyright (c) 2023, Google Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
// While Arm system registers are normally not available to userspace, FreeBSD
|
||||
// expects userspace to simply read them. It traps the reads and fills in CPU
|
||||
// capabilities.
|
||||
#if defined(OPENSSL_AARCH64) && !defined(OPENSSL_STATIC_ARMCAP) && \
|
||||
(defined(ANDROID_BAREMETAL) || defined(OPENSSL_FREEBSD))
|
||||
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
#define ID_AA64PFR0_EL1_ADVSIMD 5
|
||||
|
||||
#define ID_AA64ISAR0_EL1_AES 1
|
||||
#define ID_AA64ISAR0_EL1_SHA1 2
|
||||
#define ID_AA64ISAR0_EL1_SHA2 3
|
||||
|
||||
#define NBITS_ID_FIELD 4
|
||||
|
||||
#define READ_SYSREG(name) \
|
||||
({ \
|
||||
uint64_t _r; \
|
||||
__asm__("mrs %0, " name : "=r"(_r)); \
|
||||
_r; \
|
||||
})
|
||||
|
||||
static unsigned get_id_field(uint64_t reg, unsigned field) {
|
||||
return (reg >> (field * NBITS_ID_FIELD)) & ((1 << NBITS_ID_FIELD) - 1);
|
||||
}
|
||||
|
||||
static int get_signed_id_field(uint64_t reg, unsigned field) {
|
||||
unsigned value = get_id_field(reg, field);
|
||||
if (value & (1 << (NBITS_ID_FIELD - 1))) {
|
||||
return (int)(value | (UINT64_MAX << NBITS_ID_FIELD));
|
||||
} else {
|
||||
return (int)value;
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t read_armcap(void) {
|
||||
uint32_t armcap = ARMV7_NEON;
|
||||
|
||||
uint64_t id_aa64pfr0_el1 = READ_SYSREG("id_aa64pfr0_el1");
|
||||
|
||||
if (get_signed_id_field(id_aa64pfr0_el1, ID_AA64PFR0_EL1_ADVSIMD) < 0) {
|
||||
// If AdvSIMD ("NEON") is missing, don't report other features either.
|
||||
// This matches OpenSSL.
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64_t id_aa64isar0_el1 = READ_SYSREG("id_aa64isar0_el1");
|
||||
|
||||
unsigned aes = get_id_field(id_aa64isar0_el1, ID_AA64ISAR0_EL1_AES);
|
||||
if (aes > 0) {
|
||||
armcap |= ARMV8_AES;
|
||||
}
|
||||
if (aes > 1) {
|
||||
armcap |= ARMV8_PMULL;
|
||||
}
|
||||
|
||||
unsigned sha1 = get_id_field(id_aa64isar0_el1, ID_AA64ISAR0_EL1_SHA1);
|
||||
if (sha1 > 0) {
|
||||
armcap |= ARMV8_SHA1;
|
||||
}
|
||||
|
||||
unsigned sha2 = get_id_field(id_aa64isar0_el1, ID_AA64ISAR0_EL1_SHA2);
|
||||
if (sha2 > 0) {
|
||||
armcap |= ARMV8_SHA256;
|
||||
}
|
||||
if (sha2 > 1) {
|
||||
armcap |= ARMV8_SHA512;
|
||||
}
|
||||
|
||||
return armcap;
|
||||
}
|
||||
|
||||
void OPENSSL_cpuid_setup(void) { OPENSSL_armcap_P |= read_armcap(); }
|
||||
|
||||
#endif // OPENSSL_AARCH64 && !OPENSSL_STATIC_ARMCAP &&
|
||||
// (ANDROID_BAREMETAL || OPENSSL_FREEBSD)
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
extern uint32_t OPENSSL_armcap_P;
|
||||
|
||||
void OPENSSL_cpuid_setup(void) {
|
||||
// We do not need to check for the presence of NEON, as Armv8-A always has it
|
||||
OPENSSL_armcap_P |= ARMV7_NEON;
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
extern uint32_t OPENSSL_armcap_P;
|
||||
|
||||
void OPENSSL_cpuid_setup(void) {
|
||||
unsigned long hwcap = 0, hwcap2 = 0;
|
||||
|
||||
@@ -95,8 +95,6 @@ err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
extern uint32_t OPENSSL_armcap_P;
|
||||
|
||||
static int g_needs_hwcap2_workaround;
|
||||
|
||||
void OPENSSL_cpuid_setup(void) {
|
||||
|
||||
@@ -78,6 +78,11 @@ HIDDEN uint8_t BORINGSSL_function_hit[7] = {0};
|
||||
// This value must be explicitly initialized to zero. See similar comment above.
|
||||
HIDDEN uint32_t OPENSSL_ia32cap_P[4] = {0};
|
||||
|
||||
uint32_t OPENSSL_get_ia32cap(int idx) {
|
||||
CRYPTO_library_init();
|
||||
return OPENSSL_ia32cap_P[idx];
|
||||
}
|
||||
|
||||
#elif defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)
|
||||
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
@@ -116,10 +121,16 @@ HIDDEN uint32_t OPENSSL_armcap_P =
|
||||
HIDDEN uint32_t OPENSSL_armcap_P = 0;
|
||||
|
||||
uint32_t *OPENSSL_get_armcap_pointer_for_test(void) {
|
||||
CRYPTO_library_init();
|
||||
return &OPENSSL_armcap_P;
|
||||
}
|
||||
#endif
|
||||
|
||||
uint32_t OPENSSL_get_armcap(void) {
|
||||
CRYPTO_library_init();
|
||||
return OPENSSL_armcap_P;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(BORINGSSL_FIPS)
|
||||
|
||||
@@ -19,17 +19,9 @@
|
||||
* domain licensed but the standard ISC license is included above to keep
|
||||
* licensing simple. */
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
#define OPENSSL_NO_ASM
|
||||
#endif
|
||||
#endif
|
||||
#include <CCryptoBoringSSL_asm_base.h>
|
||||
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(__ARMEL__) && defined(__ELF__)
|
||||
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
#include <CCryptoBoringSSL_boringssl_prefix_symbols_asm.h>
|
||||
#endif
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_ARM) && defined(__ELF__)
|
||||
|
||||
.fpu neon
|
||||
.text
|
||||
@@ -2131,11 +2123,7 @@ mov sp,r12
|
||||
vpop {q4,q5,q6,q7}
|
||||
bx lr
|
||||
|
||||
#endif /* !OPENSSL_NO_ASM && __ARMEL__ && __ELF__ */
|
||||
|
||||
#if defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
#endif /* !OPENSSL_NO_ASM && OPENSSL_ARM && __ELF__ */
|
||||
#endif // defined(__arm__) && defined(__linux__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
//
|
||||
// The field functions are shared by Ed25519 and X25519 where possible.
|
||||
|
||||
#include <CCryptoBoringSSL_curve25519.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -31,15 +29,16 @@
|
||||
#include "internal.h"
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
// Various pre-computed constants.
|
||||
#include "./curve25519_tables.h"
|
||||
|
||||
#if defined(BORINGSSL_CURVE25519_64BIT)
|
||||
#if defined(BORINGSSL_HAS_UINT128)
|
||||
#include "../../third_party/fiat/curve25519_64.h"
|
||||
#elif defined(OPENSSL_64_BIT)
|
||||
#include "../../third_party/fiat/curve25519_64_msvc.h"
|
||||
#else
|
||||
#include "../../third_party/fiat/curve25519_32.h"
|
||||
#endif // BORINGSSL_CURVE25519_64BIT
|
||||
#endif
|
||||
|
||||
|
||||
// Low-level intrinsic operations
|
||||
@@ -64,7 +63,7 @@ static uint64_t load_4(const uint8_t *in) {
|
||||
|
||||
// Field operations.
|
||||
|
||||
#if defined(BORINGSSL_CURVE25519_64BIT)
|
||||
#if defined(OPENSSL_64_BIT)
|
||||
|
||||
typedef uint64_t fe_limb_t;
|
||||
#define FE_NUM_LIMBS 5
|
||||
@@ -144,7 +143,7 @@ typedef uint32_t fe_limb_t;
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#endif // BORINGSSL_CURVE25519_64BIT
|
||||
#endif // OPENSSL_64_BIT
|
||||
|
||||
static_assert(sizeof(fe) == sizeof(fe_limb_t) * FE_NUM_LIMBS,
|
||||
"fe_limb_t[FE_NUM_LIMBS] is inconsistent with fe");
|
||||
@@ -313,11 +312,6 @@ static void fe_copy_lt(fe_loose *h, const fe *f) {
|
||||
static_assert(sizeof(fe_loose) == sizeof(fe), "fe and fe_loose mismatch");
|
||||
OPENSSL_memmove(h, f, sizeof(fe));
|
||||
}
|
||||
#if !defined(OPENSSL_SMALL)
|
||||
static void fe_copy_ll(fe_loose *h, const fe_loose *f) {
|
||||
OPENSSL_memmove(h, f, sizeof(fe_loose));
|
||||
}
|
||||
#endif // !defined(OPENSSL_SMALL)
|
||||
|
||||
static void fe_loose_invert(fe *out, const fe_loose *z) {
|
||||
fe t0;
|
||||
@@ -696,16 +690,6 @@ void x25519_ge_sub(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q) {
|
||||
fe_add(&r->T, &trZ, &trT);
|
||||
}
|
||||
|
||||
static uint8_t equal(signed char b, signed char c) {
|
||||
uint8_t ub = b;
|
||||
uint8_t uc = c;
|
||||
uint8_t x = ub ^ uc; // 0: yes; 1..255: no
|
||||
uint32_t y = x; // 0: yes; 1..255: no
|
||||
y -= 1; // 4294967295: yes; 0..254: no
|
||||
y >>= 31; // 1: yes; 0: no
|
||||
return y;
|
||||
}
|
||||
|
||||
static void cmov(ge_precomp *t, const ge_precomp *u, uint8_t b) {
|
||||
fe_cmov(&t->yplusx, &u->yplusx, b);
|
||||
fe_cmov(&t->yminusx, &u->yminusx, b);
|
||||
@@ -752,7 +736,7 @@ void x25519_ge_scalarmult_small_precomp(
|
||||
ge_precomp_0(&e);
|
||||
|
||||
for (j = 1; j < 16; j++) {
|
||||
cmov(&e, &multiples[j-1], equal(index, j));
|
||||
cmov(&e, &multiples[j-1], 1&constant_time_eq_w(index, j));
|
||||
}
|
||||
|
||||
ge_cached cached;
|
||||
@@ -774,35 +758,36 @@ void x25519_ge_scalarmult_base(ge_p3 *h, const uint8_t a[32]) {
|
||||
|
||||
#else
|
||||
|
||||
static uint8_t negative(signed char b) {
|
||||
uint32_t x = b;
|
||||
x >>= 31; // 1: yes; 0: no
|
||||
return x;
|
||||
}
|
||||
static void table_select(ge_precomp *t, const int pos, const signed char b) {
|
||||
uint8_t bnegative = constant_time_msb_w(b);
|
||||
uint8_t babs = b - ((bnegative & b) << 1);
|
||||
|
||||
uint8_t t_bytes[3][32] = {
|
||||
{constant_time_is_zero_w(b) & 1}, {constant_time_is_zero_w(b) & 1}, {0}};
|
||||
#if defined(__clang__) // materialize for vectorization, 6% speedup
|
||||
__asm__("" : "+m" (t_bytes) : /*no inputs*/);
|
||||
#endif
|
||||
static_assert(sizeof(t_bytes) == sizeof(k25519Precomp[pos][0]), "");
|
||||
for (int i = 0; i < 8; i++) {
|
||||
constant_time_conditional_memxor(t_bytes, k25519Precomp[pos][i],
|
||||
sizeof(t_bytes),
|
||||
constant_time_eq_w(babs, 1 + i));
|
||||
}
|
||||
|
||||
fe yplusx, yminusx, xy2d;
|
||||
fe_frombytes_strict(&yplusx, t_bytes[0]);
|
||||
fe_frombytes_strict(&yminusx, t_bytes[1]);
|
||||
fe_frombytes_strict(&xy2d, t_bytes[2]);
|
||||
|
||||
fe_copy_lt(&t->yplusx, &yplusx);
|
||||
fe_copy_lt(&t->yminusx, &yminusx);
|
||||
fe_copy_lt(&t->xy2d, &xy2d);
|
||||
|
||||
static void table_select(ge_precomp *t, int pos, signed char b) {
|
||||
ge_precomp minust;
|
||||
uint8_t bnegative = negative(b);
|
||||
uint8_t babs = b - ((uint8_t)((-bnegative) & b) << 1);
|
||||
|
||||
ge_precomp_0(t);
|
||||
cmov(t, &k25519Precomp[pos][0], equal(babs, 1));
|
||||
cmov(t, &k25519Precomp[pos][1], equal(babs, 2));
|
||||
cmov(t, &k25519Precomp[pos][2], equal(babs, 3));
|
||||
cmov(t, &k25519Precomp[pos][3], equal(babs, 4));
|
||||
cmov(t, &k25519Precomp[pos][4], equal(babs, 5));
|
||||
cmov(t, &k25519Precomp[pos][5], equal(babs, 6));
|
||||
cmov(t, &k25519Precomp[pos][6], equal(babs, 7));
|
||||
cmov(t, &k25519Precomp[pos][7], equal(babs, 8));
|
||||
fe_copy_ll(&minust.yplusx, &t->yminusx);
|
||||
fe_copy_ll(&minust.yminusx, &t->yplusx);
|
||||
|
||||
// NOTE: the input table is canonical, but types don't encode it
|
||||
fe tmp;
|
||||
fe_carry(&tmp, &t->xy2d);
|
||||
fe_neg(&minust.xy2d, &tmp);
|
||||
|
||||
cmov(t, &minust, bnegative);
|
||||
fe_copy_lt(&minust.yplusx, &yminusx);
|
||||
fe_copy_lt(&minust.yminusx, &yplusx);
|
||||
fe_neg(&minust.xy2d, &xy2d);
|
||||
cmov(t, &minust, bnegative>>7);
|
||||
}
|
||||
|
||||
// h = a * B
|
||||
@@ -812,6 +797,18 @@ static void table_select(ge_precomp *t, int pos, signed char b) {
|
||||
// Preconditions:
|
||||
// a[31] <= 127
|
||||
void x25519_ge_scalarmult_base(ge_p3 *h, const uint8_t a[32]) {
|
||||
#if defined(BORINGSSL_FE25519_ADX)
|
||||
if (CRYPTO_is_BMI1_capable() && CRYPTO_is_BMI2_capable() &&
|
||||
CRYPTO_is_ADX_capable()) {
|
||||
uint8_t t[4][32];
|
||||
x25519_ge_scalarmult_base_adx(t, a);
|
||||
fiat_25519_from_bytes(h->X.v, t[0]);
|
||||
fiat_25519_from_bytes(h->Y.v, t[1]);
|
||||
fiat_25519_from_bytes(h->Z.v, t[2]);
|
||||
fiat_25519_from_bytes(h->T.v, t[3]);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
signed char e[64];
|
||||
signed char carry;
|
||||
ge_p1p1 r;
|
||||
@@ -914,7 +911,7 @@ void x25519_ge_scalarmult(ge_p2 *r, const uint8_t *scalar, const ge_p3 *A) {
|
||||
ge_cached selected;
|
||||
ge_cached_0(&selected);
|
||||
for (j = 0; j < 16; j++) {
|
||||
cmov_cached(&selected, &Ai[j], equal(j, index));
|
||||
cmov_cached(&selected, &Ai[j], 1&constant_time_eq_w(index, j));
|
||||
}
|
||||
|
||||
x25519_ge_add(&t, &u, &selected);
|
||||
@@ -2081,6 +2078,12 @@ static void x25519_scalar_mult(uint8_t out[32], const uint8_t scalar[32],
|
||||
x25519_NEON(out, scalar, point);
|
||||
return;
|
||||
}
|
||||
#elif defined(BORINGSSL_FE25519_ADX)
|
||||
if (CRYPTO_is_BMI1_capable() && CRYPTO_is_BMI2_capable() &&
|
||||
CRYPTO_is_ADX_capable()) {
|
||||
x25519_scalar_mult_adx(out, scalar, point);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
x25519_scalar_mult_generic(out, scalar, point);
|
||||
@@ -2114,7 +2117,8 @@ int X25519(uint8_t out_shared_key[32], const uint8_t private_key[32],
|
||||
static const uint8_t kZeros[32] = {0};
|
||||
x25519_scalar_mult(out_shared_key, private_key, peer_public_value);
|
||||
// The all-zero output results when the input is a point of small order.
|
||||
return CRYPTO_memcmp(kZeros, out_shared_key, 32) != 0;
|
||||
return constant_time_declassify_int(
|
||||
CRYPTO_memcmp(kZeros, out_shared_key, 32)) != 0;
|
||||
}
|
||||
|
||||
void X25519_public_from_private(uint8_t out_public_value[32],
|
||||
@@ -2145,4 +2149,5 @@ void X25519_public_from_private(uint8_t out_public_value[32],
|
||||
fe_loose_invert(&zminusy_inv, &zminusy);
|
||||
fe_mul_tlt(&zminusy_inv, &zplusy, &zminusy_inv);
|
||||
fe_tobytes(out_public_value, &zminusy_inv);
|
||||
CONSTTIME_DECLASSIFY(out_public_value, 32);
|
||||
}
|
||||
+4
-24
@@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2014, Google Inc.
|
||||
/* Copyright (c) 2023, Google Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
@@ -13,26 +13,6 @@
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
#if (defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)) && \
|
||||
!defined(OPENSSL_STATIC_ARMCAP)
|
||||
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
|
||||
extern uint32_t OPENSSL_armcap_P;
|
||||
|
||||
int CRYPTO_is_NEON_capable_at_runtime(void) {
|
||||
return (OPENSSL_armcap_P & ARMV7_NEON) != 0;
|
||||
}
|
||||
|
||||
int CRYPTO_is_ARMv8_AES_capable_at_runtime(void) {
|
||||
return (OPENSSL_armcap_P & ARMV8_AES) != 0;
|
||||
}
|
||||
|
||||
int CRYPTO_is_ARMv8_PMULL_capable_at_runtime(void) {
|
||||
return (OPENSSL_armcap_P & ARMV8_PMULL) != 0;
|
||||
}
|
||||
|
||||
#endif /* (defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)) &&
|
||||
!defined(OPENSSL_STATIC_ARMCAP) */
|
||||
#if defined(BORINGSSL_FE25519_ADX)
|
||||
#include "../../third_party/fiat/curve25519_64_adx.h"
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
@@ -15,14 +15,13 @@
|
||||
#ifndef OPENSSL_HEADER_CURVE25519_INTERNAL_H
|
||||
#define OPENSSL_HEADER_CURVE25519_INTERNAL_H
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <CCryptoBoringSSL_base.h>
|
||||
#include <CCryptoBoringSSL_curve25519.h>
|
||||
|
||||
#include "../internal.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if defined(OPENSSL_ARM) && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_APPLE)
|
||||
#define BORINGSSL_X25519_NEON
|
||||
@@ -32,11 +31,28 @@ void x25519_NEON(uint8_t out[32], const uint8_t scalar[32],
|
||||
const uint8_t point[32]);
|
||||
#endif
|
||||
|
||||
#if defined(BORINGSSL_HAS_UINT128)
|
||||
#define BORINGSSL_CURVE25519_64BIT
|
||||
#if !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_SMALL) && \
|
||||
defined(__GNUC__) && defined(__x86_64__)
|
||||
#define BORINGSSL_FE25519_ADX
|
||||
|
||||
// fiat_curve25519_adx_mul is defined in
|
||||
// third_party/fiat/asm/fiat_curve25519_adx_mul.S
|
||||
void __attribute__((sysv_abi))
|
||||
fiat_curve25519_adx_mul(uint64_t out[4], const uint64_t in1[4],
|
||||
const uint64_t in2[4]);
|
||||
|
||||
// fiat_curve25519_adx_square is defined in
|
||||
// third_party/fiat/asm/fiat_curve25519_adx_square.S
|
||||
void __attribute__((sysv_abi))
|
||||
fiat_curve25519_adx_square(uint64_t out[4], const uint64_t in[4]);
|
||||
|
||||
// x25519_scalar_mult_adx is defined in third_party/fiat/curve25519_64_adx.h
|
||||
void x25519_scalar_mult_adx(uint8_t out[32], const uint8_t scalar[32],
|
||||
const uint8_t point[32]);
|
||||
void x25519_ge_scalarmult_base_adx(uint8_t h[4][32], const uint8_t a[32]);
|
||||
#endif
|
||||
|
||||
#if defined(BORINGSSL_CURVE25519_64BIT)
|
||||
#if defined(OPENSSL_64_BIT)
|
||||
// fe means field element. Here the field is \Z/(2^255-19). An element t,
|
||||
// entries t[0]...t[4], represents the integer t[0]+2^51 t[1]+2^102 t[2]+2^153
|
||||
// t[3]+2^204 t[4].
|
||||
@@ -139,6 +155,8 @@ struct spake2_ctx_st {
|
||||
};
|
||||
|
||||
|
||||
extern const uint8_t k25519Precomp[32][8][3][32];
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // extern C
|
||||
#endif
|
||||
|
||||
@@ -272,12 +272,11 @@ static const uint8_t kSpakeMSmallPrecomp[15 * 2 * 32] = {
|
||||
SPAKE2_CTX *SPAKE2_CTX_new(enum spake2_role_t my_role,
|
||||
const uint8_t *my_name, size_t my_name_len,
|
||||
const uint8_t *their_name, size_t their_name_len) {
|
||||
SPAKE2_CTX *ctx = OPENSSL_malloc(sizeof(SPAKE2_CTX));
|
||||
SPAKE2_CTX *ctx = OPENSSL_zalloc(sizeof(SPAKE2_CTX));
|
||||
if (ctx == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
OPENSSL_memset(ctx, 0, sizeof(SPAKE2_CTX));
|
||||
ctx->my_role = my_role;
|
||||
|
||||
CBS my_name_cbs, their_name_cbs;
|
||||
|
||||
@@ -110,6 +110,10 @@ DH *DH_parse_parameters(CBS *cbs) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!dh_check_params_fast(ret)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
err:
|
||||
|
||||
@@ -337,6 +337,11 @@ int DH_generate_parameters_ex(DH *dh, int prime_bits, int generator,
|
||||
// It's just as OK (and in some sense better) to use a generator of the
|
||||
// order-q subgroup.
|
||||
|
||||
if (prime_bits <= 0 || prime_bits > OPENSSL_DH_MAX_MODULUS_BITS) {
|
||||
OPENSSL_PUT_ERROR(DH, DH_R_MODULUS_TOO_LARGE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIGNUM *t1, *t2;
|
||||
int g, ok = 0;
|
||||
BN_CTX *ctx = NULL;
|
||||
|
||||
@@ -88,18 +88,14 @@ static int dsa_sign_setup(const DSA *dsa, BN_CTX *ctx_in, BIGNUM **out_kinv,
|
||||
static CRYPTO_EX_DATA_CLASS g_ex_data_class = CRYPTO_EX_DATA_CLASS_INIT;
|
||||
|
||||
DSA *DSA_new(void) {
|
||||
DSA *dsa = OPENSSL_malloc(sizeof(DSA));
|
||||
DSA *dsa = OPENSSL_zalloc(sizeof(DSA));
|
||||
if (dsa == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
OPENSSL_memset(dsa, 0, sizeof(DSA));
|
||||
|
||||
dsa->references = 1;
|
||||
|
||||
CRYPTO_MUTEX_init(&dsa->method_mont_lock);
|
||||
CRYPTO_new_ex_data(&dsa->ex_data);
|
||||
|
||||
return dsa;
|
||||
}
|
||||
|
||||
@@ -202,6 +198,10 @@ int DSA_set0_pqg(DSA *dsa, BIGNUM *p, BIGNUM *q, BIGNUM *g) {
|
||||
dsa->g = g;
|
||||
}
|
||||
|
||||
BN_MONT_CTX_free(dsa->method_mont_p);
|
||||
dsa->method_mont_p = NULL;
|
||||
BN_MONT_CTX_free(dsa->method_mont_q);
|
||||
dsa->method_mont_q = NULL;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -529,16 +529,7 @@ err:
|
||||
return ok;
|
||||
}
|
||||
|
||||
DSA_SIG *DSA_SIG_new(void) {
|
||||
DSA_SIG *sig;
|
||||
sig = OPENSSL_malloc(sizeof(DSA_SIG));
|
||||
if (!sig) {
|
||||
return NULL;
|
||||
}
|
||||
sig->r = NULL;
|
||||
sig->s = NULL;
|
||||
return sig;
|
||||
}
|
||||
DSA_SIG *DSA_SIG_new(void) { return OPENSSL_zalloc(sizeof(DSA_SIG)); }
|
||||
|
||||
void DSA_SIG_free(DSA_SIG *sig) {
|
||||
if (!sig) {
|
||||
|
||||
@@ -17,11 +17,31 @@
|
||||
|
||||
#include <CCryptoBoringSSL_dsa.h>
|
||||
|
||||
#include <CCryptoBoringSSL_thread.h>
|
||||
|
||||
#include "../internal.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
struct dsa_st {
|
||||
BIGNUM *p;
|
||||
BIGNUM *q;
|
||||
BIGNUM *g;
|
||||
|
||||
BIGNUM *pub_key;
|
||||
BIGNUM *priv_key;
|
||||
|
||||
// Normally used to cache montgomery values
|
||||
CRYPTO_MUTEX method_mont_lock;
|
||||
BN_MONT_CTX *method_mont_p;
|
||||
BN_MONT_CTX *method_mont_q;
|
||||
CRYPTO_refcount_t references;
|
||||
CRYPTO_EX_DATA ex_data;
|
||||
};
|
||||
|
||||
// dsa_check_key performs cheap self-checks on |dsa|, and ensures it is within
|
||||
// DoS bounds. It returns one on success and zero on error.
|
||||
int dsa_check_key(const DSA *dsa);
|
||||
|
||||
@@ -72,6 +72,16 @@ static const CBS_ASN1_TAG kParametersTag =
|
||||
static const CBS_ASN1_TAG kPublicKeyTag =
|
||||
CBS_ASN1_CONSTRUCTED | CBS_ASN1_CONTEXT_SPECIFIC | 1;
|
||||
|
||||
// TODO(https://crbug.com/boringssl/497): Allow parsers to specify a list of
|
||||
// acceptable groups, so parsers don't have to pull in all four.
|
||||
typedef const EC_GROUP *(*ec_group_func)(void);
|
||||
static const ec_group_func kAllGroups[] = {
|
||||
&EC_group_p224,
|
||||
&EC_group_p256,
|
||||
&EC_group_p384,
|
||||
&EC_group_p521,
|
||||
};
|
||||
|
||||
EC_KEY *EC_KEY_parse_private_key(CBS *cbs, const EC_GROUP *group) {
|
||||
CBS ec_private_key, private_key;
|
||||
uint64_t version;
|
||||
@@ -84,7 +94,6 @@ EC_KEY *EC_KEY_parse_private_key(CBS *cbs, const EC_GROUP *group) {
|
||||
}
|
||||
|
||||
// Parse the optional parameters field.
|
||||
EC_GROUP *inner_group = NULL;
|
||||
EC_KEY *ret = NULL;
|
||||
BIGNUM *priv_key = NULL;
|
||||
if (CBS_peek_asn1_tag(&ec_private_key, kParametersTag)) {
|
||||
@@ -97,7 +106,7 @@ EC_KEY *EC_KEY_parse_private_key(CBS *cbs, const EC_GROUP *group) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_DECODE_ERROR);
|
||||
goto err;
|
||||
}
|
||||
inner_group = EC_KEY_parse_parameters(&child);
|
||||
const EC_GROUP *inner_group = EC_KEY_parse_parameters(&child);
|
||||
if (inner_group == NULL) {
|
||||
goto err;
|
||||
}
|
||||
@@ -179,13 +188,11 @@ EC_KEY *EC_KEY_parse_private_key(CBS *cbs, const EC_GROUP *group) {
|
||||
}
|
||||
|
||||
BN_free(priv_key);
|
||||
EC_GROUP_free(inner_group);
|
||||
return ret;
|
||||
|
||||
err:
|
||||
EC_KEY_free(ret);
|
||||
BN_free(priv_key);
|
||||
EC_GROUP_free(inner_group);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -244,9 +251,12 @@ int EC_KEY_marshal_private_key(CBB *cbb, const EC_KEY *key,
|
||||
// kPrimeFieldOID is the encoding of 1.2.840.10045.1.1.
|
||||
static const uint8_t kPrimeField[] = {0x2a, 0x86, 0x48, 0xce, 0x3d, 0x01, 0x01};
|
||||
|
||||
static int parse_explicit_prime_curve(CBS *in, CBS *out_prime, CBS *out_a,
|
||||
CBS *out_b, CBS *out_base_x,
|
||||
CBS *out_base_y, CBS *out_order) {
|
||||
struct explicit_prime_curve {
|
||||
CBS prime, a, b, base_x, base_y, order;
|
||||
};
|
||||
|
||||
static int parse_explicit_prime_curve(CBS *in,
|
||||
struct explicit_prime_curve *out) {
|
||||
// See RFC 3279, section 2.3.5. Note that RFC 3279 calls this structure an
|
||||
// ECParameters while RFC 5480 calls it a SpecifiedECDomain.
|
||||
CBS params, field_id, field_type, curve, base, cofactor;
|
||||
@@ -260,18 +270,18 @@ static int parse_explicit_prime_curve(CBS *in, CBS *out_prime, CBS *out_a,
|
||||
CBS_len(&field_type) != sizeof(kPrimeField) ||
|
||||
OPENSSL_memcmp(CBS_data(&field_type), kPrimeField, sizeof(kPrimeField)) !=
|
||||
0 ||
|
||||
!CBS_get_asn1(&field_id, out_prime, CBS_ASN1_INTEGER) ||
|
||||
!CBS_is_unsigned_asn1_integer(out_prime) ||
|
||||
!CBS_get_asn1(&field_id, &out->prime, CBS_ASN1_INTEGER) ||
|
||||
!CBS_is_unsigned_asn1_integer(&out->prime) ||
|
||||
CBS_len(&field_id) != 0 ||
|
||||
!CBS_get_asn1(¶ms, &curve, CBS_ASN1_SEQUENCE) ||
|
||||
!CBS_get_asn1(&curve, out_a, CBS_ASN1_OCTETSTRING) ||
|
||||
!CBS_get_asn1(&curve, out_b, CBS_ASN1_OCTETSTRING) ||
|
||||
!CBS_get_asn1(&curve, &out->a, CBS_ASN1_OCTETSTRING) ||
|
||||
!CBS_get_asn1(&curve, &out->b, CBS_ASN1_OCTETSTRING) ||
|
||||
// |curve| has an optional BIT STRING seed which we ignore.
|
||||
!CBS_get_optional_asn1(&curve, NULL, NULL, CBS_ASN1_BITSTRING) ||
|
||||
CBS_len(&curve) != 0 ||
|
||||
!CBS_get_asn1(¶ms, &base, CBS_ASN1_OCTETSTRING) ||
|
||||
!CBS_get_asn1(¶ms, out_order, CBS_ASN1_INTEGER) ||
|
||||
!CBS_is_unsigned_asn1_integer(out_order) ||
|
||||
!CBS_get_asn1(¶ms, &out->order, CBS_ASN1_INTEGER) ||
|
||||
!CBS_is_unsigned_asn1_integer(&out->order) ||
|
||||
!CBS_get_optional_asn1(¶ms, &cofactor, &has_cofactor,
|
||||
CBS_ASN1_INTEGER) ||
|
||||
CBS_len(¶ms) != 0) {
|
||||
@@ -300,25 +310,33 @@ static int parse_explicit_prime_curve(CBS *in, CBS *out_prime, CBS *out_a,
|
||||
return 0;
|
||||
}
|
||||
size_t field_len = CBS_len(&base) / 2;
|
||||
CBS_init(out_base_x, CBS_data(&base), field_len);
|
||||
CBS_init(out_base_y, CBS_data(&base) + field_len, field_len);
|
||||
CBS_init(&out->base_x, CBS_data(&base), field_len);
|
||||
CBS_init(&out->base_y, CBS_data(&base) + field_len, field_len);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// integers_equal returns one if |a| and |b| are equal, up to leading zeros, and
|
||||
// integers_equal returns one if |bytes| is a big-endian encoding of |bn|, and
|
||||
// zero otherwise.
|
||||
static int integers_equal(const CBS *a, const uint8_t *b, size_t b_len) {
|
||||
// Remove leading zeros from |a| and |b|.
|
||||
CBS a_copy = *a;
|
||||
while (CBS_len(&a_copy) > 0 && CBS_data(&a_copy)[0] == 0) {
|
||||
CBS_skip(&a_copy, 1);
|
||||
static int integers_equal(const CBS *bytes, const BIGNUM *bn) {
|
||||
// Although, in SEC 1, Field-Element-to-Octet-String has a fixed width,
|
||||
// OpenSSL mis-encodes the |a| and |b|, so we tolerate any number of leading
|
||||
// zeros. (This matters for P-521 whose |b| has a leading 0.)
|
||||
CBS copy = *bytes;
|
||||
while (CBS_len(©) > 0 && CBS_data(©)[0] == 0) {
|
||||
CBS_skip(©, 1);
|
||||
}
|
||||
while (b_len > 0 && b[0] == 0) {
|
||||
b++;
|
||||
b_len--;
|
||||
|
||||
if (CBS_len(©) > EC_MAX_BYTES) {
|
||||
return 0;
|
||||
}
|
||||
return CBS_mem_equal(&a_copy, b, b_len);
|
||||
uint8_t buf[EC_MAX_BYTES];
|
||||
if (!BN_bn2bin_padded(buf, CBS_len(©), bn)) {
|
||||
ERR_clear_error();
|
||||
return 0;
|
||||
}
|
||||
|
||||
return CBS_mem_equal(©, buf, CBS_len(©));
|
||||
}
|
||||
|
||||
EC_GROUP *EC_KEY_parse_curve_name(CBS *cbs) {
|
||||
@@ -329,13 +347,10 @@ EC_GROUP *EC_KEY_parse_curve_name(CBS *cbs) {
|
||||
}
|
||||
|
||||
// Look for a matching curve.
|
||||
const struct built_in_curves *const curves = OPENSSL_built_in_curves();
|
||||
for (size_t i = 0; i < OPENSSL_NUM_BUILT_IN_CURVES; i++) {
|
||||
const struct built_in_curve *curve = &curves->curves[i];
|
||||
if (CBS_len(&named_curve) == curve->oid_len &&
|
||||
OPENSSL_memcmp(CBS_data(&named_curve), curve->oid, curve->oid_len) ==
|
||||
0) {
|
||||
return EC_GROUP_new_by_curve_name(curve->nid);
|
||||
for (size_t i = 0; i < OPENSSL_ARRAY_SIZE(kAllGroups); i++) {
|
||||
const EC_GROUP *group = kAllGroups[i]();
|
||||
if (CBS_mem_equal(&named_curve, group->oid, group->oid_len)) {
|
||||
return (EC_GROUP *)group;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -344,25 +359,15 @@ EC_GROUP *EC_KEY_parse_curve_name(CBS *cbs) {
|
||||
}
|
||||
|
||||
int EC_KEY_marshal_curve_name(CBB *cbb, const EC_GROUP *group) {
|
||||
int nid = EC_GROUP_get_curve_name(group);
|
||||
if (nid == NID_undef) {
|
||||
if (group->oid_len == 0) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_UNKNOWN_GROUP);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const struct built_in_curves *const curves = OPENSSL_built_in_curves();
|
||||
for (size_t i = 0; i < OPENSSL_NUM_BUILT_IN_CURVES; i++) {
|
||||
const struct built_in_curve *curve = &curves->curves[i];
|
||||
if (curve->nid == nid) {
|
||||
CBB child;
|
||||
return CBB_add_asn1(cbb, &child, CBS_ASN1_OBJECT) &&
|
||||
CBB_add_bytes(&child, curve->oid, curve->oid_len) &&
|
||||
CBB_flush(cbb);
|
||||
}
|
||||
}
|
||||
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_UNKNOWN_GROUP);
|
||||
return 0;
|
||||
CBB child;
|
||||
return CBB_add_asn1(cbb, &child, CBS_ASN1_OBJECT) &&
|
||||
CBB_add_bytes(&child, group->oid, group->oid_len) && //
|
||||
CBB_flush(cbb);
|
||||
}
|
||||
|
||||
EC_GROUP *EC_KEY_parse_parameters(CBS *cbs) {
|
||||
@@ -374,34 +379,56 @@ EC_GROUP *EC_KEY_parse_parameters(CBS *cbs) {
|
||||
// of named curves.
|
||||
//
|
||||
// TODO(davidben): Remove support for this.
|
||||
CBS prime, a, b, base_x, base_y, order;
|
||||
if (!parse_explicit_prime_curve(cbs, &prime, &a, &b, &base_x, &base_y,
|
||||
&order)) {
|
||||
struct explicit_prime_curve curve;
|
||||
if (!parse_explicit_prime_curve(cbs, &curve)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Look for a matching prime curve.
|
||||
const struct built_in_curves *const curves = OPENSSL_built_in_curves();
|
||||
for (size_t i = 0; i < OPENSSL_NUM_BUILT_IN_CURVES; i++) {
|
||||
const struct built_in_curve *curve = &curves->curves[i];
|
||||
const unsigned param_len = curve->param_len;
|
||||
// |curve->params| is ordered p, a, b, x, y, order, each component
|
||||
// zero-padded up to the field length. Although SEC 1 states that the
|
||||
// Field-Element-to-Octet-String conversion also pads, OpenSSL mis-encodes
|
||||
// |a| and |b|, so this comparison must allow omitting leading zeros. (This
|
||||
// is relevant for P-521 whose |b| has a leading 0.)
|
||||
if (integers_equal(&prime, curve->params, param_len) &&
|
||||
integers_equal(&a, curve->params + param_len, param_len) &&
|
||||
integers_equal(&b, curve->params + param_len * 2, param_len) &&
|
||||
integers_equal(&base_x, curve->params + param_len * 3, param_len) &&
|
||||
integers_equal(&base_y, curve->params + param_len * 4, param_len) &&
|
||||
integers_equal(&order, curve->params + param_len * 5, param_len)) {
|
||||
return EC_GROUP_new_by_curve_name(curve->nid);
|
||||
}
|
||||
const EC_GROUP *ret = NULL;
|
||||
BIGNUM *p = BN_new(), *a = BN_new(), *b = BN_new(), *x = BN_new(),
|
||||
*y = BN_new();
|
||||
if (p == NULL || a == NULL || b == NULL || x == NULL || y == NULL) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_UNKNOWN_GROUP);
|
||||
return NULL;
|
||||
for (size_t i = 0; i < OPENSSL_ARRAY_SIZE(kAllGroups); i++) {
|
||||
const EC_GROUP *group = kAllGroups[i]();
|
||||
if (!integers_equal(&curve.order, EC_GROUP_get0_order(group))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// The order alone uniquely identifies the group, but we check the other
|
||||
// parameters to avoid misinterpreting the group.
|
||||
if (!EC_GROUP_get_curve_GFp(group, p, a, b, NULL)) {
|
||||
goto err;
|
||||
}
|
||||
if (!integers_equal(&curve.prime, p) || !integers_equal(&curve.a, a) ||
|
||||
!integers_equal(&curve.b, b)) {
|
||||
break;
|
||||
}
|
||||
if (!EC_POINT_get_affine_coordinates_GFp(
|
||||
group, EC_GROUP_get0_generator(group), x, y, NULL)) {
|
||||
goto err;
|
||||
}
|
||||
if (!integers_equal(&curve.base_x, x) ||
|
||||
!integers_equal(&curve.base_y, y)) {
|
||||
break;
|
||||
}
|
||||
ret = group;
|
||||
break;
|
||||
}
|
||||
|
||||
if (ret == NULL) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_UNKNOWN_GROUP);
|
||||
}
|
||||
|
||||
err:
|
||||
BN_free(p);
|
||||
BN_free(a);
|
||||
BN_free(b);
|
||||
BN_free(x);
|
||||
BN_free(y);
|
||||
return (EC_GROUP *)ret;
|
||||
}
|
||||
|
||||
int EC_POINT_point2cbb(CBB *out, const EC_GROUP *group, const EC_POINT *point,
|
||||
@@ -458,18 +485,16 @@ EC_KEY *d2i_ECParameters(EC_KEY **out_key, const uint8_t **inp, long len) {
|
||||
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, *inp, (size_t)len);
|
||||
EC_GROUP *group = EC_KEY_parse_parameters(&cbs);
|
||||
const EC_GROUP *group = EC_KEY_parse_parameters(&cbs);
|
||||
if (group == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
EC_KEY *ret = EC_KEY_new();
|
||||
if (ret == NULL || !EC_KEY_set_group(ret, group)) {
|
||||
EC_GROUP_free(group);
|
||||
EC_KEY_free(ret);
|
||||
return NULL;
|
||||
}
|
||||
EC_GROUP_free(group);
|
||||
|
||||
if (out_key != NULL) {
|
||||
EC_KEY_free(*out_key);
|
||||
@@ -532,3 +557,16 @@ int i2o_ECPublicKey(const EC_KEY *key, uint8_t **outp) {
|
||||
// Historically, this function used the wrong return value on error.
|
||||
return ret > 0 ? ret : 0;
|
||||
}
|
||||
|
||||
size_t EC_get_builtin_curves(EC_builtin_curve *out_curves,
|
||||
size_t max_num_curves) {
|
||||
if (max_num_curves > OPENSSL_ARRAY_SIZE(kAllGroups)) {
|
||||
max_num_curves = OPENSSL_ARRAY_SIZE(kAllGroups);
|
||||
}
|
||||
for (size_t i = 0; i < max_num_curves; i++) {
|
||||
const EC_GROUP *group = kAllGroups[i]();
|
||||
out_curves[i].nid = group->curve_name;
|
||||
out_curves[i].comment = group->comment;
|
||||
}
|
||||
return OPENSSL_ARRAY_SIZE(kAllGroups);
|
||||
}
|
||||
@@ -55,7 +55,8 @@ EC_KEY *EC_KEY_derive_from_secret(const EC_GROUP *group, const uint8_t *secret,
|
||||
}
|
||||
|
||||
uint8_t derived[EC_KEY_DERIVE_EXTRA_BYTES + EC_MAX_BYTES];
|
||||
size_t derived_len = BN_num_bytes(&group->order) + EC_KEY_DERIVE_EXTRA_BYTES;
|
||||
size_t derived_len =
|
||||
BN_num_bytes(EC_GROUP_get0_order(group)) + EC_KEY_DERIVE_EXTRA_BYTES;
|
||||
assert(derived_len <= sizeof(derived));
|
||||
if (!HKDF(derived, derived_len, EVP_sha256(), secret, secret_len,
|
||||
/*salt=*/NULL, /*salt_len=*/0, (const uint8_t *)info,
|
||||
@@ -74,10 +75,10 @@ EC_KEY *EC_KEY_derive_from_secret(const EC_GROUP *group, const uint8_t *secret,
|
||||
// enough. 2^(num_bytes(order)) < 2^8 * order, so:
|
||||
//
|
||||
// priv < 2^8 * order * 2^128 < order * order < order * R
|
||||
!BN_from_montgomery(priv, priv, group->order_mont, ctx) ||
|
||||
!BN_from_montgomery(priv, priv, &group->order, ctx) ||
|
||||
// Multiply by R^2 and do another Montgomery reduction to compute
|
||||
// priv * R^-1 * R^2 * R^-1 = priv mod order.
|
||||
!BN_to_montgomery(priv, priv, group->order_mont, ctx) ||
|
||||
!BN_to_montgomery(priv, priv, &group->order, ctx) ||
|
||||
!EC_POINT_mul(group, pub, priv, NULL, NULL, ctx) ||
|
||||
!EC_KEY_set_group(key, group) || !EC_KEY_set_public_key(key, pub) ||
|
||||
!EC_KEY_set_private_key(key, priv)) {
|
||||
|
||||
@@ -26,8 +26,7 @@
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
// This file implements hash-to-curve, as described in
|
||||
// draft-irtf-cfrg-hash-to-curve-16.
|
||||
// This file implements hash-to-curve, as described in RFC 9380.
|
||||
//
|
||||
// This hash-to-curve implementation is written generically with the
|
||||
// expectation that we will eventually wish to support other curves. If it
|
||||
@@ -48,8 +47,7 @@
|
||||
// templates to make specializing more convenient.
|
||||
|
||||
// expand_message_xmd implements the operation described in section 5.3.1 of
|
||||
// draft-irtf-cfrg-hash-to-curve-16. It returns one on success and zero on
|
||||
// error.
|
||||
// RFC 9380. It returns one on success and zero on error.
|
||||
static int expand_message_xmd(const EVP_MD *md, uint8_t *out, size_t out_len,
|
||||
const uint8_t *msg, size_t msg_len,
|
||||
const uint8_t *dst, size_t dst_len) {
|
||||
@@ -138,7 +136,7 @@ err:
|
||||
|
||||
// num_bytes_to_derive determines the number of bytes to derive when hashing to
|
||||
// a number modulo |modulus|. See the hash_to_field operation defined in
|
||||
// section 5.2 of draft-irtf-cfrg-hash-to-curve-16.
|
||||
// section 5.2 of RFC 9380.
|
||||
static int num_bytes_to_derive(size_t *out, const BIGNUM *modulus, unsigned k) {
|
||||
size_t bits = BN_num_bits(modulus);
|
||||
size_t L = (bits + k + 7) / 8;
|
||||
@@ -171,20 +169,19 @@ static void big_endian_to_words(BN_ULONG *out, size_t num_words,
|
||||
}
|
||||
|
||||
// hash_to_field implements the operation described in section 5.2
|
||||
// of draft-irtf-cfrg-hash-to-curve-16, with count = 2. |k| is the security
|
||||
// factor.
|
||||
// of RFC 9380, with count = 2. |k| is the security factor.
|
||||
static int hash_to_field2(const EC_GROUP *group, const EVP_MD *md,
|
||||
EC_FELEM *out1, EC_FELEM *out2, const uint8_t *dst,
|
||||
size_t dst_len, unsigned k, const uint8_t *msg,
|
||||
size_t msg_len) {
|
||||
size_t L;
|
||||
uint8_t buf[4 * EC_MAX_BYTES];
|
||||
if (!num_bytes_to_derive(&L, &group->field, k) ||
|
||||
if (!num_bytes_to_derive(&L, &group->field.N, k) ||
|
||||
!expand_message_xmd(md, buf, 2 * L, msg, msg_len, dst, dst_len)) {
|
||||
return 0;
|
||||
}
|
||||
BN_ULONG words[2 * EC_MAX_WORDS];
|
||||
size_t num_words = 2 * group->field.width;
|
||||
size_t num_words = 2 * group->field.N.width;
|
||||
big_endian_to_words(words, num_words, buf, L);
|
||||
group->meth->felem_reduce(group, out1, words, num_words);
|
||||
big_endian_to_words(words, num_words, buf + L, L);
|
||||
@@ -197,15 +194,16 @@ static int hash_to_field2(const EC_GROUP *group, const EVP_MD *md,
|
||||
static int hash_to_scalar(const EC_GROUP *group, const EVP_MD *md,
|
||||
EC_SCALAR *out, const uint8_t *dst, size_t dst_len,
|
||||
unsigned k, const uint8_t *msg, size_t msg_len) {
|
||||
const BIGNUM *order = EC_GROUP_get0_order(group);
|
||||
size_t L;
|
||||
uint8_t buf[EC_MAX_BYTES * 2];
|
||||
if (!num_bytes_to_derive(&L, &group->order, k) ||
|
||||
if (!num_bytes_to_derive(&L, order, k) ||
|
||||
!expand_message_xmd(md, buf, L, msg, msg_len, dst, dst_len)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
BN_ULONG words[2 * EC_MAX_WORDS];
|
||||
size_t num_words = 2 * group->order.width;
|
||||
size_t num_words = 2 * order->width;
|
||||
big_endian_to_words(words, num_words, buf, L);
|
||||
ec_scalar_reduce(group, out, words, num_words);
|
||||
return 1;
|
||||
@@ -220,8 +218,7 @@ static inline void mul_A(const EC_GROUP *group, EC_FELEM *out,
|
||||
ec_felem_sub(group, out, in, &tmp); // out = -3*in
|
||||
}
|
||||
|
||||
// sgn0 implements the operation described in section 4.1.2 of
|
||||
// draft-irtf-cfrg-hash-to-curve-16.
|
||||
// sgn0 implements the operation described in section 4.1.2 of RFC 9380.
|
||||
static BN_ULONG sgn0(const EC_GROUP *group, const EC_FELEM *a) {
|
||||
uint8_t buf[EC_MAX_BYTES];
|
||||
size_t len;
|
||||
@@ -230,11 +227,11 @@ static BN_ULONG sgn0(const EC_GROUP *group, const EC_FELEM *a) {
|
||||
}
|
||||
|
||||
OPENSSL_UNUSED static int is_3mod4(const EC_GROUP *group) {
|
||||
return group->field.width > 0 && (group->field.d[0] & 3) == 3;
|
||||
return group->field.N.width > 0 && (group->field.N.d[0] & 3) == 3;
|
||||
}
|
||||
|
||||
// sqrt_ratio_3mod4 implements the operation described in appendix F.2.1.2
|
||||
// of draft-irtf-cfrg-hash-to-curve-16.
|
||||
// of RFC 9380.
|
||||
static BN_ULONG sqrt_ratio_3mod4(const EC_GROUP *group, const EC_FELEM *Z,
|
||||
const BN_ULONG *c1, size_t num_c1,
|
||||
const EC_FELEM *c2, EC_FELEM *out_y,
|
||||
@@ -269,11 +266,10 @@ static BN_ULONG sqrt_ratio_3mod4(const EC_GROUP *group, const EC_FELEM *Z,
|
||||
}
|
||||
|
||||
// map_to_curve_simple_swu implements the operation described in section 6.6.2
|
||||
// of draft-irtf-cfrg-hash-to-curve-16, using the straight-line implementation
|
||||
// in appendix F.2.
|
||||
// of RFC 9380, using the straight-line implementation in appendix F.2.
|
||||
static void map_to_curve_simple_swu(const EC_GROUP *group, const EC_FELEM *Z,
|
||||
const BN_ULONG *c1, size_t num_c1,
|
||||
const EC_FELEM *c2, EC_RAW_POINT *out,
|
||||
const EC_FELEM *c2, EC_JACOBIAN *out,
|
||||
const EC_FELEM *u) {
|
||||
// This function requires the prime be 3 mod 4, and that A = -3.
|
||||
assert(is_3mod4(group));
|
||||
@@ -285,12 +281,12 @@ static void map_to_curve_simple_swu(const EC_GROUP *group, const EC_FELEM *Z,
|
||||
group->meth->felem_sqr;
|
||||
|
||||
EC_FELEM tv1, tv2, tv3, tv4, tv5, tv6, x, y, y1;
|
||||
felem_sqr(group, &tv1, u); // 1. tv1 = u^2
|
||||
felem_mul(group, &tv1, Z, &tv1); // 2. tv1 = Z * tv1
|
||||
felem_sqr(group, &tv2, &tv1); // 3. tv2 = tv1^2
|
||||
ec_felem_add(group, &tv2, &tv2, &tv1); // 4. tv2 = tv2 + tv1
|
||||
ec_felem_add(group, &tv3, &tv2, &group->one); // 5. tv3 = tv2 + 1
|
||||
felem_mul(group, &tv3, &group->b, &tv3); // 6. tv3 = B * tv3
|
||||
felem_sqr(group, &tv1, u); // 1. tv1 = u^2
|
||||
felem_mul(group, &tv1, Z, &tv1); // 2. tv1 = Z * tv1
|
||||
felem_sqr(group, &tv2, &tv1); // 3. tv2 = tv1^2
|
||||
ec_felem_add(group, &tv2, &tv2, &tv1); // 4. tv2 = tv2 + tv1
|
||||
ec_felem_add(group, &tv3, &tv2, ec_felem_one(group)); // 5. tv3 = tv2 + 1
|
||||
felem_mul(group, &tv3, &group->b, &tv3); // 6. tv3 = B * tv3
|
||||
|
||||
// 7. tv4 = CMOV(Z, -tv2, tv2 != 0)
|
||||
const BN_ULONG tv2_non_zero = ec_felem_non_zero_mask(group, &tv2);
|
||||
@@ -344,7 +340,7 @@ static void map_to_curve_simple_swu(const EC_GROUP *group, const EC_FELEM *Z,
|
||||
|
||||
static int hash_to_curve(const EC_GROUP *group, const EVP_MD *md,
|
||||
const EC_FELEM *Z, const EC_FELEM *c2, unsigned k,
|
||||
EC_RAW_POINT *out, const uint8_t *dst, size_t dst_len,
|
||||
EC_JACOBIAN *out, const uint8_t *dst, size_t dst_len,
|
||||
const uint8_t *msg, size_t msg_len) {
|
||||
EC_FELEM u0, u1;
|
||||
if (!hash_to_field2(group, md, &u0, &u1, dst, dst_len, k, msg, msg_len)) {
|
||||
@@ -353,13 +349,13 @@ static int hash_to_curve(const EC_GROUP *group, const EVP_MD *md,
|
||||
|
||||
// Compute |c1| = (p - 3) / 4.
|
||||
BN_ULONG c1[EC_MAX_WORDS];
|
||||
size_t num_c1 = group->field.width;
|
||||
if (!bn_copy_words(c1, num_c1, &group->field)) {
|
||||
size_t num_c1 = group->field.N.width;
|
||||
if (!bn_copy_words(c1, num_c1, &group->field.N)) {
|
||||
return 0;
|
||||
}
|
||||
bn_rshift_words(c1, c1, /*shift=*/2, /*num=*/num_c1);
|
||||
|
||||
EC_RAW_POINT Q0, Q1;
|
||||
EC_JACOBIAN Q0, Q1;
|
||||
map_to_curve_simple_swu(group, Z, c1, num_c1, c2, &Q0, &u0);
|
||||
map_to_curve_simple_swu(group, Z, c1, num_c1, c2, &Q1, &u1);
|
||||
|
||||
@@ -370,7 +366,7 @@ static int hash_to_curve(const EC_GROUP *group, const EVP_MD *md,
|
||||
|
||||
static int felem_from_u8(const EC_GROUP *group, EC_FELEM *out, uint8_t a) {
|
||||
uint8_t bytes[EC_MAX_BYTES] = {0};
|
||||
size_t len = BN_num_bytes(&group->field);
|
||||
size_t len = BN_num_bytes(&group->field.N);
|
||||
bytes[len - 1] = a;
|
||||
return ec_felem_from_bytes(group, out, bytes, len);
|
||||
}
|
||||
@@ -401,10 +397,10 @@ static const uint8_t kP384Sqrt12[] = {
|
||||
0xa8, 0x0f, 0x7e, 0x19, 0x14, 0xe2, 0xec, 0x69, 0xf5, 0xa6, 0x26, 0xb3};
|
||||
|
||||
int ec_hash_to_curve_p256_xmd_sha256_sswu(const EC_GROUP *group,
|
||||
EC_RAW_POINT *out, const uint8_t *dst,
|
||||
EC_JACOBIAN *out, const uint8_t *dst,
|
||||
size_t dst_len, const uint8_t *msg,
|
||||
size_t msg_len) {
|
||||
// See section 8.3 of draft-irtf-cfrg-hash-to-curve-16.
|
||||
// See section 8.3 of RFC 9380.
|
||||
if (EC_GROUP_get_curve_name(group) != NID_X9_62_prime256v1) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_GROUP_MISMATCH);
|
||||
return 0;
|
||||
@@ -434,10 +430,10 @@ int EC_hash_to_curve_p256_xmd_sha256_sswu(const EC_GROUP *group, EC_POINT *out,
|
||||
}
|
||||
|
||||
int ec_hash_to_curve_p384_xmd_sha384_sswu(const EC_GROUP *group,
|
||||
EC_RAW_POINT *out, const uint8_t *dst,
|
||||
EC_JACOBIAN *out, const uint8_t *dst,
|
||||
size_t dst_len, const uint8_t *msg,
|
||||
size_t msg_len) {
|
||||
// See section 8.3 of draft-irtf-cfrg-hash-to-curve-16.
|
||||
// See section 8.3 of RFC 9380.
|
||||
if (EC_GROUP_get_curve_name(group) != NID_secp384r1) {
|
||||
OPENSSL_PUT_ERROR(EC, EC_R_GROUP_MISMATCH);
|
||||
return 0;
|
||||
@@ -479,7 +475,7 @@ int ec_hash_to_scalar_p384_xmd_sha384(
|
||||
}
|
||||
|
||||
int ec_hash_to_curve_p384_xmd_sha512_sswu_draft07(
|
||||
const EC_GROUP *group, EC_RAW_POINT *out, const uint8_t *dst,
|
||||
const EC_GROUP *group, EC_JACOBIAN *out, const uint8_t *dst,
|
||||
size_t dst_len, const uint8_t *msg, size_t msg_len) {
|
||||
// See section 8.3 of draft-irtf-cfrg-hash-to-curve-07.
|
||||
if (EC_GROUP_get_curve_name(group) != NID_secp384r1) {
|
||||
|
||||
@@ -26,28 +26,26 @@ extern "C" {
|
||||
|
||||
// Hash-to-curve.
|
||||
//
|
||||
// Internal |EC_RAW_POINT| versions of the corresponding public APIs.
|
||||
// Internal |EC_JACOBIAN| versions of the corresponding public APIs.
|
||||
|
||||
// ec_hash_to_curve_p256_xmd_sha256_sswu hashes |msg| to a point on |group| and
|
||||
// writes the result to |out|, implementing the P256_XMD:SHA-256_SSWU_RO_ suite
|
||||
// from draft-irtf-cfrg-hash-to-curve-16. It returns one on success and zero on
|
||||
// error.
|
||||
// from RFC 9380. It returns one on success and zero on error.
|
||||
OPENSSL_EXPORT int ec_hash_to_curve_p256_xmd_sha256_sswu(
|
||||
const EC_GROUP *group, EC_RAW_POINT *out, const uint8_t *dst,
|
||||
size_t dst_len, const uint8_t *msg, size_t msg_len);
|
||||
const EC_GROUP *group, EC_JACOBIAN *out, const uint8_t *dst, size_t dst_len,
|
||||
const uint8_t *msg, size_t msg_len);
|
||||
|
||||
// ec_hash_to_curve_p384_xmd_sha384_sswu hashes |msg| to a point on |group| and
|
||||
// writes the result to |out|, implementing the P384_XMD:SHA-384_SSWU_RO_ suite
|
||||
// from draft-irtf-cfrg-hash-to-curve-16. It returns one on success and zero on
|
||||
// error.
|
||||
// from RFC 9380. It returns one on success and zero on error.
|
||||
OPENSSL_EXPORT int ec_hash_to_curve_p384_xmd_sha384_sswu(
|
||||
const EC_GROUP *group, EC_RAW_POINT *out, const uint8_t *dst,
|
||||
size_t dst_len, const uint8_t *msg, size_t msg_len);
|
||||
const EC_GROUP *group, EC_JACOBIAN *out, const uint8_t *dst, size_t dst_len,
|
||||
const uint8_t *msg, size_t msg_len);
|
||||
|
||||
// ec_hash_to_scalar_p384_xmd_sha384 hashes |msg| to a scalar on |group|
|
||||
// and writes the result to |out|, using the hash_to_field operation from the
|
||||
// P384_XMD:SHA-384_SSWU_RO_ suite from draft-irtf-cfrg-hash-to-curve-16, but
|
||||
// generating a value modulo the group order rather than a field element.
|
||||
// P384_XMD:SHA-384_SSWU_RO_ suite from RFC 9380, but generating a value modulo
|
||||
// the group order rather than a field element.
|
||||
OPENSSL_EXPORT int ec_hash_to_scalar_p384_xmd_sha384(
|
||||
const EC_GROUP *group, EC_SCALAR *out, const uint8_t *dst, size_t dst_len,
|
||||
const uint8_t *msg, size_t msg_len);
|
||||
@@ -59,8 +57,8 @@ OPENSSL_EXPORT int ec_hash_to_scalar_p384_xmd_sha384(
|
||||
//
|
||||
// TODO(https://crbug.com/1414562): Migrate this to the final version.
|
||||
OPENSSL_EXPORT int ec_hash_to_curve_p384_xmd_sha512_sswu_draft07(
|
||||
const EC_GROUP *group, EC_RAW_POINT *out, const uint8_t *dst,
|
||||
size_t dst_len, const uint8_t *msg, size_t msg_len);
|
||||
const EC_GROUP *group, EC_JACOBIAN *out, const uint8_t *dst, size_t dst_len,
|
||||
const uint8_t *msg, size_t msg_len);
|
||||
|
||||
// ec_hash_to_scalar_p384_xmd_sha512_draft07 hashes |msg| to a scalar on |group|
|
||||
// and writes the result to |out|, using the hash_to_field operation from the
|
||||
|
||||
@@ -92,7 +92,7 @@ int ECDH_compute_key(void *out, size_t out_len, const EC_POINT *pub_key,
|
||||
return -1;
|
||||
}
|
||||
|
||||
EC_RAW_POINT shared_point;
|
||||
EC_JACOBIAN shared_point;
|
||||
uint8_t buf[EC_MAX_BYTES];
|
||||
size_t buf_len;
|
||||
if (!ec_point_mul_scalar(group, &shared_point, &pub_key->raw, priv) ||
|
||||
|
||||
@@ -31,15 +31,7 @@ struct engine_st {
|
||||
ECDSA_METHOD *ecdsa_method;
|
||||
};
|
||||
|
||||
ENGINE *ENGINE_new(void) {
|
||||
ENGINE *engine = OPENSSL_malloc(sizeof(ENGINE));
|
||||
if (engine == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
OPENSSL_memset(engine, 0, sizeof(ENGINE));
|
||||
return engine;
|
||||
}
|
||||
ENGINE *ENGINE_new(void) { return OPENSSL_zalloc(sizeof(ENGINE)); }
|
||||
|
||||
int ENGINE_free(ENGINE *engine) {
|
||||
// Methods are currently required to be static so are not unref'ed.
|
||||
|
||||
@@ -146,13 +146,13 @@ struct err_error_st {
|
||||
|
||||
// ERR_STATE contains the per-thread, error queue.
|
||||
typedef struct err_state_st {
|
||||
// errors contains the ERR_NUM_ERRORS most recent errors, organised as a ring
|
||||
// buffer.
|
||||
// errors contains up to ERR_NUM_ERRORS - 1 most recent errors, organised as a
|
||||
// ring buffer.
|
||||
struct err_error_st errors[ERR_NUM_ERRORS];
|
||||
// top contains the index one past the most recent error. If |top| equals
|
||||
// |bottom| then the queue is empty.
|
||||
// top contains the index of the most recent error. If |top| equals |bottom|
|
||||
// then the queue is empty.
|
||||
unsigned top;
|
||||
// bottom contains the index of the last error in the queue.
|
||||
// bottom contains the index before the least recent error in the queue.
|
||||
unsigned bottom;
|
||||
|
||||
// to_free, if not NULL, contains a pointer owned by this structure that was
|
||||
@@ -192,8 +192,7 @@ static int global_next_library = ERR_NUM_LIBS;
|
||||
|
||||
// global_next_library_mutex protects |global_next_library| from concurrent
|
||||
// updates.
|
||||
static struct CRYPTO_STATIC_MUTEX global_next_library_mutex =
|
||||
CRYPTO_STATIC_MUTEX_INIT;
|
||||
static CRYPTO_MUTEX global_next_library_mutex = CRYPTO_MUTEX_INIT;
|
||||
|
||||
static void err_state_free(void *statep) {
|
||||
ERR_STATE *state = statep;
|
||||
@@ -367,9 +366,9 @@ void ERR_remove_thread_state(const CRYPTO_THREADID *tid) {
|
||||
int ERR_get_next_error_library(void) {
|
||||
int ret;
|
||||
|
||||
CRYPTO_STATIC_MUTEX_lock_write(&global_next_library_mutex);
|
||||
CRYPTO_MUTEX_lock_write(&global_next_library_mutex);
|
||||
ret = global_next_library++;
|
||||
CRYPTO_STATIC_MUTEX_unlock_write(&global_next_library_mutex);
|
||||
CRYPTO_MUTEX_unlock_write(&global_next_library_mutex);
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -553,22 +552,21 @@ char *ERR_error_string_n(uint32_t packed_error, char *buf, size_t len) {
|
||||
const char *lib_str = err_lib_error_string(packed_error);
|
||||
const char *reason_str = err_reason_error_string(packed_error);
|
||||
|
||||
char lib_buf[64], reason_buf[64];
|
||||
char lib_buf[32], reason_buf[32];
|
||||
if (lib_str == NULL) {
|
||||
BIO_snprintf(lib_buf, sizeof(lib_buf), "lib(%u)", lib);
|
||||
snprintf(lib_buf, sizeof(lib_buf), "lib(%u)", lib);
|
||||
lib_str = lib_buf;
|
||||
}
|
||||
|
||||
if (reason_str == NULL) {
|
||||
BIO_snprintf(reason_buf, sizeof(reason_buf), "reason(%u)", reason);
|
||||
if (reason_str == NULL) {
|
||||
snprintf(reason_buf, sizeof(reason_buf), "reason(%u)", reason);
|
||||
reason_str = reason_buf;
|
||||
}
|
||||
|
||||
BIO_snprintf(buf, len, "error:%08" PRIx32 ":%s:OPENSSL_internal:%s",
|
||||
packed_error, lib_str, reason_str);
|
||||
|
||||
if (strlen(buf) == len - 1) {
|
||||
// output may be truncated; make sure we always have 5 colon-separated
|
||||
int ret = snprintf(buf, len, "error:%08" PRIx32 ":%s:OPENSSL_internal:%s",
|
||||
packed_error, lib_str, reason_str);
|
||||
if (ret >= 0 && (size_t)ret >= len) {
|
||||
// The output was truncated; make sure we always have 5 colon-separated
|
||||
// fields, i.e. 4 colons.
|
||||
static const unsigned num_colons = 4;
|
||||
unsigned i;
|
||||
@@ -618,8 +616,8 @@ void ERR_print_errors_cb(ERR_print_errors_callback_t callback, void *ctx) {
|
||||
}
|
||||
|
||||
ERR_error_string_n(packed_error, buf, sizeof(buf));
|
||||
BIO_snprintf(buf2, sizeof(buf2), "%lu:%s:%s:%d:%s\n", thread_hash, buf,
|
||||
file, line, (flags & ERR_FLAG_STRING) ? data : "");
|
||||
snprintf(buf2, sizeof(buf2), "%lu:%s:%s:%d:%s\n", thread_hash, buf, file,
|
||||
line, (flags & ERR_FLAG_STRING) ? data : "");
|
||||
if (callback(buf2, strlen(buf2), ctx) <= 0) {
|
||||
break;
|
||||
}
|
||||
@@ -867,6 +865,10 @@ void ERR_restore_state(const ERR_SAVE_STATE *state) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (state->num_errors >= ERR_NUM_ERRORS) {
|
||||
abort();
|
||||
}
|
||||
|
||||
ERR_STATE *const dst = err_get_state();
|
||||
if (dst == NULL) {
|
||||
return;
|
||||
@@ -875,6 +877,6 @@ void ERR_restore_state(const ERR_SAVE_STATE *state) {
|
||||
for (size_t i = 0; i < state->num_errors; i++) {
|
||||
err_copy(&dst->errors[i], &state->errors[i]);
|
||||
}
|
||||
dst->top = state->num_errors - 1;
|
||||
dst->top = (unsigned)(state->num_errors - 1);
|
||||
dst->bottom = ERR_NUM_ERRORS - 1;
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -81,17 +81,13 @@ OPENSSL_DECLARE_ERROR_REASON(EVP, NOT_XOF_OR_INVALID_LENGTH)
|
||||
OPENSSL_DECLARE_ERROR_REASON(EVP, EMPTY_PSK)
|
||||
|
||||
EVP_PKEY *EVP_PKEY_new(void) {
|
||||
EVP_PKEY *ret;
|
||||
|
||||
ret = OPENSSL_malloc(sizeof(EVP_PKEY));
|
||||
EVP_PKEY *ret = OPENSSL_zalloc(sizeof(EVP_PKEY));
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
OPENSSL_memset(ret, 0, sizeof(EVP_PKEY));
|
||||
ret->type = EVP_PKEY_NONE;
|
||||
ret->references = 1;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -229,6 +225,13 @@ static const EVP_PKEY_ASN1_METHOD *evp_pkey_asn1_find(int nid) {
|
||||
}
|
||||
}
|
||||
|
||||
static void evp_pkey_set_method(EVP_PKEY *pkey,
|
||||
const EVP_PKEY_ASN1_METHOD *method) {
|
||||
free_it(pkey);
|
||||
pkey->ameth = method;
|
||||
pkey->type = pkey->ameth->pkey_id;
|
||||
}
|
||||
|
||||
int EVP_PKEY_type(int nid) {
|
||||
const EVP_PKEY_ASN1_METHOD *meth = evp_pkey_asn1_find(nid);
|
||||
if (meth == NULL) {
|
||||
@@ -246,7 +249,9 @@ int EVP_PKEY_set1_RSA(EVP_PKEY *pkey, RSA *key) {
|
||||
}
|
||||
|
||||
int EVP_PKEY_assign_RSA(EVP_PKEY *pkey, RSA *key) {
|
||||
return EVP_PKEY_assign(pkey, EVP_PKEY_RSA, key);
|
||||
evp_pkey_set_method(pkey, &rsa_asn1_meth);
|
||||
pkey->pkey = key;
|
||||
return key != NULL;
|
||||
}
|
||||
|
||||
RSA *EVP_PKEY_get0_RSA(const EVP_PKEY *pkey) {
|
||||
@@ -274,7 +279,9 @@ int EVP_PKEY_set1_DSA(EVP_PKEY *pkey, DSA *key) {
|
||||
}
|
||||
|
||||
int EVP_PKEY_assign_DSA(EVP_PKEY *pkey, DSA *key) {
|
||||
return EVP_PKEY_assign(pkey, EVP_PKEY_DSA, key);
|
||||
evp_pkey_set_method(pkey, &dsa_asn1_meth);
|
||||
pkey->pkey = key;
|
||||
return key != NULL;
|
||||
}
|
||||
|
||||
DSA *EVP_PKEY_get0_DSA(const EVP_PKEY *pkey) {
|
||||
@@ -302,7 +309,9 @@ int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, EC_KEY *key) {
|
||||
}
|
||||
|
||||
int EVP_PKEY_assign_EC_KEY(EVP_PKEY *pkey, EC_KEY *key) {
|
||||
return EVP_PKEY_assign(pkey, EVP_PKEY_EC, key);
|
||||
evp_pkey_set_method(pkey, &ec_asn1_meth);
|
||||
pkey->pkey = key;
|
||||
return key != NULL;
|
||||
}
|
||||
|
||||
EC_KEY *EVP_PKEY_get0_EC_KEY(const EVP_PKEY *pkey) {
|
||||
@@ -325,21 +334,32 @@ DH *EVP_PKEY_get0_DH(const EVP_PKEY *pkey) { return NULL; }
|
||||
DH *EVP_PKEY_get1_DH(const EVP_PKEY *pkey) { return NULL; }
|
||||
|
||||
int EVP_PKEY_assign(EVP_PKEY *pkey, int type, void *key) {
|
||||
if (!EVP_PKEY_set_type(pkey, type)) {
|
||||
return 0;
|
||||
// This function can only be used to assign RSA, DSA, and EC keys. Other key
|
||||
// types have internal representations which are not exposed through the
|
||||
// public API.
|
||||
switch (type) {
|
||||
case EVP_PKEY_RSA:
|
||||
return EVP_PKEY_assign_RSA(pkey, key);
|
||||
case EVP_PKEY_DSA:
|
||||
return EVP_PKEY_assign_DSA(pkey, key);
|
||||
case EVP_PKEY_EC:
|
||||
return EVP_PKEY_assign_EC_KEY(pkey, key);
|
||||
}
|
||||
pkey->pkey = key;
|
||||
return key != NULL;
|
||||
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_R_UNSUPPORTED_ALGORITHM);
|
||||
ERR_add_error_dataf("algorithm %d", type);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int EVP_PKEY_set_type(EVP_PKEY *pkey, int type) {
|
||||
const EVP_PKEY_ASN1_METHOD *ameth;
|
||||
|
||||
if (pkey && pkey->pkey) {
|
||||
// This isn't strictly necessary, but historically |EVP_PKEY_set_type| would
|
||||
// clear |pkey| even if |evp_pkey_asn1_find| failed, so we preserve that
|
||||
// behavior.
|
||||
free_it(pkey);
|
||||
}
|
||||
|
||||
ameth = evp_pkey_asn1_find(type);
|
||||
const EVP_PKEY_ASN1_METHOD *ameth = evp_pkey_asn1_find(type);
|
||||
if (ameth == NULL) {
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_R_UNSUPPORTED_ALGORITHM);
|
||||
ERR_add_error_dataf("algorithm %d", type);
|
||||
@@ -347,8 +367,7 @@ int EVP_PKEY_set_type(EVP_PKEY *pkey, int type) {
|
||||
}
|
||||
|
||||
if (pkey) {
|
||||
pkey->ameth = ameth;
|
||||
pkey->type = pkey->ameth->pkey_id;
|
||||
evp_pkey_set_method(pkey, ameth);
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
@@ -86,11 +86,10 @@ static const EVP_PKEY_METHOD *evp_pkey_meth_find(int type) {
|
||||
|
||||
static EVP_PKEY_CTX *evp_pkey_ctx_new(EVP_PKEY *pkey, ENGINE *e,
|
||||
const EVP_PKEY_METHOD *pmeth) {
|
||||
EVP_PKEY_CTX *ret = OPENSSL_malloc(sizeof(EVP_PKEY_CTX));
|
||||
EVP_PKEY_CTX *ret = OPENSSL_zalloc(sizeof(EVP_PKEY_CTX));
|
||||
if (!ret) {
|
||||
return NULL;
|
||||
}
|
||||
OPENSSL_memset(ret, 0, sizeof(EVP_PKEY_CTX));
|
||||
|
||||
ret->engine = e;
|
||||
ret->pmeth = pmeth;
|
||||
@@ -156,13 +155,11 @@ EVP_PKEY_CTX *EVP_PKEY_CTX_dup(EVP_PKEY_CTX *ctx) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
EVP_PKEY_CTX *ret = OPENSSL_malloc(sizeof(EVP_PKEY_CTX));
|
||||
EVP_PKEY_CTX *ret = OPENSSL_zalloc(sizeof(EVP_PKEY_CTX));
|
||||
if (!ret) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
OPENSSL_memset(ret, 0, sizeof(EVP_PKEY_CTX));
|
||||
|
||||
ret->pmeth = ctx->pmeth;
|
||||
ret->engine = ctx->engine;
|
||||
ret->operation = ctx->operation;
|
||||
|
||||
@@ -75,20 +75,17 @@
|
||||
typedef struct {
|
||||
// message digest
|
||||
const EVP_MD *md;
|
||||
EC_GROUP *gen_group;
|
||||
const EC_GROUP *gen_group;
|
||||
} EC_PKEY_CTX;
|
||||
|
||||
|
||||
static int pkey_ec_init(EVP_PKEY_CTX *ctx) {
|
||||
EC_PKEY_CTX *dctx;
|
||||
dctx = OPENSSL_malloc(sizeof(EC_PKEY_CTX));
|
||||
EC_PKEY_CTX *dctx = OPENSSL_zalloc(sizeof(EC_PKEY_CTX));
|
||||
if (!dctx) {
|
||||
return 0;
|
||||
}
|
||||
OPENSSL_memset(dctx, 0, sizeof(EC_PKEY_CTX));
|
||||
|
||||
ctx->data = dctx;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -111,7 +108,6 @@ static void pkey_ec_cleanup(EVP_PKEY_CTX *ctx) {
|
||||
return;
|
||||
}
|
||||
|
||||
EC_GROUP_free(dctx->gen_group);
|
||||
OPENSSL_free(dctx);
|
||||
}
|
||||
|
||||
@@ -195,11 +191,10 @@ static int pkey_ec_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) {
|
||||
return 1;
|
||||
|
||||
case EVP_PKEY_CTRL_EC_PARAMGEN_CURVE_NID: {
|
||||
EC_GROUP *group = EC_GROUP_new_by_curve_name(p1);
|
||||
const EC_GROUP *group = EC_GROUP_new_by_curve_name(p1);
|
||||
if (group == NULL) {
|
||||
return 0;
|
||||
}
|
||||
EC_GROUP_free(dctx->gen_group);
|
||||
dctx->gen_group = group;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ static int eckey_pub_decode(EVP_PKEY *out, CBS *params, CBS *key) {
|
||||
|
||||
// The parameters are a named curve.
|
||||
EC_KEY *eckey = NULL;
|
||||
EC_GROUP *group = EC_KEY_parse_curve_name(params);
|
||||
const EC_GROUP *group = EC_KEY_parse_curve_name(params);
|
||||
if (group == NULL || CBS_len(params) != 0) {
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_R_DECODE_ERROR);
|
||||
goto err;
|
||||
@@ -107,12 +107,10 @@ static int eckey_pub_decode(EVP_PKEY *out, CBS *params, CBS *key) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
EC_GROUP_free(group);
|
||||
EVP_PKEY_assign_EC_KEY(out, eckey);
|
||||
return 1;
|
||||
|
||||
err:
|
||||
EC_GROUP_free(group);
|
||||
EC_KEY_free(eckey);
|
||||
return 0;
|
||||
}
|
||||
@@ -135,15 +133,13 @@ static int eckey_pub_cmp(const EVP_PKEY *a, const EVP_PKEY *b) {
|
||||
|
||||
static int eckey_priv_decode(EVP_PKEY *out, CBS *params, CBS *key) {
|
||||
// See RFC 5915.
|
||||
EC_GROUP *group = EC_KEY_parse_parameters(params);
|
||||
const EC_GROUP *group = EC_KEY_parse_parameters(params);
|
||||
if (group == NULL || CBS_len(params) != 0) {
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_R_DECODE_ERROR);
|
||||
EC_GROUP_free(group);
|
||||
return 0;
|
||||
}
|
||||
|
||||
EC_KEY *ec_key = EC_KEY_parse_private_key(key, group);
|
||||
EC_GROUP_free(group);
|
||||
if (ec_key == NULL || CBS_len(key) != 0) {
|
||||
OPENSSL_PUT_ERROR(EVP, EVP_R_DECODE_ERROR);
|
||||
EC_KEY_free(ec_key);
|
||||
@@ -215,7 +211,7 @@ static int ec_bits(const EVP_PKEY *pkey) {
|
||||
ERR_clear_error();
|
||||
return 0;
|
||||
}
|
||||
return BN_num_bits(EC_GROUP_get0_order(group));
|
||||
return EC_GROUP_order_bits(group);
|
||||
}
|
||||
|
||||
static int ec_missing_parameters(const EVP_PKEY *pkey) {
|
||||
|
||||
@@ -35,12 +35,11 @@ typedef struct {
|
||||
} HKDF_PKEY_CTX;
|
||||
|
||||
static int pkey_hkdf_init(EVP_PKEY_CTX *ctx) {
|
||||
HKDF_PKEY_CTX *hctx = OPENSSL_malloc(sizeof(HKDF_PKEY_CTX));
|
||||
HKDF_PKEY_CTX *hctx = OPENSSL_zalloc(sizeof(HKDF_PKEY_CTX));
|
||||
if (hctx == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
OPENSSL_memset(hctx, 0, sizeof(HKDF_PKEY_CTX));
|
||||
if (!CBB_init(&hctx->info, 0)) {
|
||||
OPENSSL_free(hctx);
|
||||
return 0;
|
||||
|
||||
@@ -97,12 +97,10 @@ typedef struct {
|
||||
} RSA_OAEP_LABEL_PARAMS;
|
||||
|
||||
static int pkey_rsa_init(EVP_PKEY_CTX *ctx) {
|
||||
RSA_PKEY_CTX *rctx;
|
||||
rctx = OPENSSL_malloc(sizeof(RSA_PKEY_CTX));
|
||||
RSA_PKEY_CTX *rctx = OPENSSL_zalloc(sizeof(RSA_PKEY_CTX));
|
||||
if (!rctx) {
|
||||
return 0;
|
||||
}
|
||||
OPENSSL_memset(rctx, 0, sizeof(RSA_PKEY_CTX));
|
||||
|
||||
rctx->nbits = 2048;
|
||||
rctx->pad_mode = RSA_PKCS1_PADDING;
|
||||
|
||||
@@ -63,7 +63,7 @@
|
||||
|
||||
|
||||
int PKCS5_PBKDF2_HMAC(const char *password, size_t password_len,
|
||||
const uint8_t *salt, size_t salt_len, unsigned iterations,
|
||||
const uint8_t *salt, size_t salt_len, uint32_t iterations,
|
||||
const EVP_MD *digest, size_t key_len, uint8_t *out_key) {
|
||||
// See RFC 8018, section 5.2.
|
||||
int ret = 0;
|
||||
@@ -98,7 +98,7 @@ int PKCS5_PBKDF2_HMAC(const char *password, size_t password_len,
|
||||
}
|
||||
|
||||
OPENSSL_memcpy(out_key, digest_tmp, todo);
|
||||
for (unsigned j = 1; j < iterations; j++) {
|
||||
for (uint32_t j = 1; j < iterations; j++) {
|
||||
// Compute the remaining U_* values and XOR.
|
||||
if (!HMAC_Init_ex(&hctx, NULL, 0, NULL, NULL) ||
|
||||
!HMAC_Update(&hctx, digest_tmp, md_len) ||
|
||||
@@ -139,7 +139,7 @@ err:
|
||||
|
||||
int PKCS5_PBKDF2_HMAC_SHA1(const char *password, size_t password_len,
|
||||
const uint8_t *salt, size_t salt_len,
|
||||
unsigned iterations, size_t key_len,
|
||||
uint32_t iterations, size_t key_len,
|
||||
uint8_t *out_key) {
|
||||
return PKCS5_PBKDF2_HMAC(password, password_len, salt, salt_len, iterations,
|
||||
EVP_sha1(), key_len, out_key);
|
||||
|
||||
@@ -196,12 +196,12 @@ static int rsa_priv_print(BIO *bp, const EVP_PKEY *pkey, int indent) {
|
||||
static int do_dsa_print(BIO *bp, const DSA *x, int off, int ptype) {
|
||||
const BIGNUM *priv_key = NULL;
|
||||
if (ptype == 2) {
|
||||
priv_key = x->priv_key;
|
||||
priv_key = DSA_get0_priv_key(x);
|
||||
}
|
||||
|
||||
const BIGNUM *pub_key = NULL;
|
||||
if (ptype > 0) {
|
||||
pub_key = x->pub_key;
|
||||
pub_key = DSA_get0_pub_key(x);
|
||||
}
|
||||
|
||||
const char *ktype = "DSA-Parameters";
|
||||
@@ -212,14 +212,15 @@ static int do_dsa_print(BIO *bp, const DSA *x, int off, int ptype) {
|
||||
}
|
||||
|
||||
if (!BIO_indent(bp, off, 128) ||
|
||||
BIO_printf(bp, "%s: (%u bit)\n", ktype, BN_num_bits(x->p)) <= 0 ||
|
||||
BIO_printf(bp, "%s: (%u bit)\n", ktype, BN_num_bits(DSA_get0_p(x))) <=
|
||||
0 ||
|
||||
// |priv_key| and |pub_key| may be NULL, in which case |bn_print| will
|
||||
// silently skip them.
|
||||
!bn_print(bp, "priv:", priv_key, off) ||
|
||||
!bn_print(bp, "pub:", pub_key, off) ||
|
||||
!bn_print(bp, "P:", x->p, off) ||
|
||||
!bn_print(bp, "Q:", x->q, off) ||
|
||||
!bn_print(bp, "G:", x->g, off)) {
|
||||
!bn_print(bp, "P:", DSA_get0_p(x), off) ||
|
||||
!bn_print(bp, "Q:", DSA_get0_q(x), off) ||
|
||||
!bn_print(bp, "G:", DSA_get0_g(x), off)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -170,12 +170,12 @@ int EVP_PBE_scrypt(const char *password, size_t password_len,
|
||||
|
||||
// Allocate and divide up the scratch space. |max_mem| fits in a size_t, which
|
||||
// is no bigger than uint64_t, so none of these operations may overflow.
|
||||
static_assert(UINT64_MAX >= ((size_t)-1), "size_t exceeds uint64_t");
|
||||
static_assert(UINT64_MAX >= SIZE_MAX, "size_t exceeds uint64_t");
|
||||
size_t B_blocks = p * 2 * r;
|
||||
size_t B_bytes = B_blocks * sizeof(block_t);
|
||||
size_t T_blocks = 2 * r;
|
||||
size_t V_blocks = N * 2 * r;
|
||||
block_t *B = OPENSSL_malloc((B_blocks + T_blocks + V_blocks) * sizeof(block_t));
|
||||
block_t *B = OPENSSL_calloc(B_blocks + T_blocks + V_blocks, sizeof(block_t));
|
||||
if (B == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -116,7 +116,6 @@
|
||||
#include <CCryptoBoringSSL_crypto.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_stack.h>
|
||||
#include <CCryptoBoringSSL_thread.h>
|
||||
|
||||
#include "internal.h"
|
||||
@@ -128,14 +127,14 @@ struct crypto_ex_data_func_st {
|
||||
long argl; // Arbitary long
|
||||
void *argp; // Arbitary void pointer
|
||||
CRYPTO_EX_free *free_func;
|
||||
// next points to the next |CRYPTO_EX_DATA_FUNCS| or NULL if this is the last
|
||||
// one. It may only be read if synchronized with a read from |num_funcs|.
|
||||
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) {
|
||||
CRYPTO_EX_DATA_FUNCS *funcs;
|
||||
int ret = 0;
|
||||
|
||||
funcs = OPENSSL_malloc(sizeof(CRYPTO_EX_DATA_FUNCS));
|
||||
CRYPTO_EX_DATA_FUNCS *funcs = OPENSSL_malloc(sizeof(CRYPTO_EX_DATA_FUNCS));
|
||||
if (funcs == NULL) {
|
||||
return 0;
|
||||
}
|
||||
@@ -143,37 +142,32 @@ int CRYPTO_get_ex_new_index(CRYPTO_EX_DATA_CLASS *ex_data_class, int *out_index,
|
||||
funcs->argl = argl;
|
||||
funcs->argp = argp;
|
||||
funcs->free_func = free_func;
|
||||
funcs->next = NULL;
|
||||
|
||||
CRYPTO_STATIC_MUTEX_lock_write(&ex_data_class->lock);
|
||||
|
||||
if (ex_data_class->meth == NULL) {
|
||||
ex_data_class->meth = sk_CRYPTO_EX_DATA_FUNCS_new_null();
|
||||
}
|
||||
|
||||
if (ex_data_class->meth == NULL) {
|
||||
goto err;
|
||||
}
|
||||
CRYPTO_MUTEX_lock_write(&ex_data_class->lock);
|
||||
|
||||
uint32_t num_funcs = CRYPTO_atomic_load_u32(&ex_data_class->num_funcs);
|
||||
// The index must fit in |int|.
|
||||
if (sk_CRYPTO_EX_DATA_FUNCS_num(ex_data_class->meth) >
|
||||
(size_t)(INT_MAX - ex_data_class->num_reserved)) {
|
||||
if (num_funcs > (size_t)(INT_MAX - ex_data_class->num_reserved)) {
|
||||
OPENSSL_PUT_ERROR(CRYPTO, ERR_R_OVERFLOW);
|
||||
goto err;
|
||||
CRYPTO_MUTEX_unlock_write(&ex_data_class->lock);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!sk_CRYPTO_EX_DATA_FUNCS_push(ex_data_class->meth, funcs)) {
|
||||
goto err;
|
||||
// Append |funcs| to the linked list.
|
||||
if (ex_data_class->last == NULL) {
|
||||
assert(num_funcs == 0);
|
||||
ex_data_class->funcs = funcs;
|
||||
ex_data_class->last = funcs;
|
||||
} else {
|
||||
ex_data_class->last->next = funcs;
|
||||
ex_data_class->last = funcs;
|
||||
}
|
||||
funcs = NULL; // |sk_CRYPTO_EX_DATA_FUNCS_push| takes ownership.
|
||||
|
||||
*out_index = (int)sk_CRYPTO_EX_DATA_FUNCS_num(ex_data_class->meth) - 1 +
|
||||
ex_data_class->num_reserved;
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
CRYPTO_STATIC_MUTEX_unlock_write(&ex_data_class->lock);
|
||||
OPENSSL_free(funcs);
|
||||
return ret;
|
||||
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;
|
||||
}
|
||||
|
||||
int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int index, void *val) {
|
||||
@@ -209,33 +203,6 @@ void *CRYPTO_get_ex_data(const CRYPTO_EX_DATA *ad, int idx) {
|
||||
return sk_void_value(ad->sk, idx);
|
||||
}
|
||||
|
||||
// get_func_pointers takes a copy of the CRYPTO_EX_DATA_FUNCS pointers, if any,
|
||||
// for the given class. If there are some pointers, it sets |*out| to point to
|
||||
// a fresh stack of them. Otherwise it sets |*out| to NULL. It returns one on
|
||||
// success or zero on error.
|
||||
static int get_func_pointers(STACK_OF(CRYPTO_EX_DATA_FUNCS) **out,
|
||||
CRYPTO_EX_DATA_CLASS *ex_data_class) {
|
||||
size_t n;
|
||||
|
||||
*out = NULL;
|
||||
|
||||
// CRYPTO_EX_DATA_FUNCS structures are static once set, so we can take a
|
||||
// shallow copy of the list under lock and then use the structures without
|
||||
// the lock held.
|
||||
CRYPTO_STATIC_MUTEX_lock_read(&ex_data_class->lock);
|
||||
n = sk_CRYPTO_EX_DATA_FUNCS_num(ex_data_class->meth);
|
||||
if (n > 0) {
|
||||
*out = sk_CRYPTO_EX_DATA_FUNCS_dup(ex_data_class->meth);
|
||||
}
|
||||
CRYPTO_STATIC_MUTEX_unlock_read(&ex_data_class->lock);
|
||||
|
||||
if (n > 0 && *out == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void CRYPTO_new_ex_data(CRYPTO_EX_DATA *ad) {
|
||||
ad->sk = NULL;
|
||||
}
|
||||
@@ -247,26 +214,21 @@ void CRYPTO_free_ex_data(CRYPTO_EX_DATA_CLASS *ex_data_class, void *obj,
|
||||
return;
|
||||
}
|
||||
|
||||
STACK_OF(CRYPTO_EX_DATA_FUNCS) *func_pointers;
|
||||
if (!get_func_pointers(&func_pointers, ex_data_class)) {
|
||||
// TODO(davidben): This leaks memory on malloc error.
|
||||
return;
|
||||
}
|
||||
|
||||
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|.
|
||||
assert(sk_CRYPTO_EX_DATA_FUNCS_num(func_pointers) <=
|
||||
(size_t)(INT_MAX - ex_data_class->num_reserved));
|
||||
for (int i = 0; i < (int)sk_CRYPTO_EX_DATA_FUNCS_num(func_pointers); i++) {
|
||||
CRYPTO_EX_DATA_FUNCS *func_pointer =
|
||||
sk_CRYPTO_EX_DATA_FUNCS_value(func_pointers, i);
|
||||
if (func_pointer->free_func) {
|
||||
void *ptr = CRYPTO_get_ex_data(ad, i + ex_data_class->num_reserved);
|
||||
func_pointer->free_func(obj, ptr, ad, i + ex_data_class->num_reserved,
|
||||
func_pointer->argl, func_pointer->argp);
|
||||
}
|
||||
}
|
||||
assert(num_funcs <= (size_t)(INT_MAX - ex_data_class->num_reserved));
|
||||
|
||||
sk_CRYPTO_EX_DATA_FUNCS_free(func_pointers);
|
||||
// Defer dereferencing |ex_data_class->funcs| and |funcs->next|. It must come
|
||||
// after the |num_funcs| comparison to be correctly synchronized.
|
||||
CRYPTO_EX_DATA_FUNCS *const *funcs = &ex_data_class->funcs;
|
||||
for (uint32_t i = 0; i < num_funcs; i++) {
|
||||
if ((*funcs)->free_func != NULL) {
|
||||
int index = (int)i + ex_data_class->num_reserved;
|
||||
void *ptr = CRYPTO_get_ex_data(ad, index);
|
||||
(*funcs)->free_func(obj, ptr, ad, index, (*funcs)->argl, (*funcs)->argp);
|
||||
}
|
||||
funcs = &(*funcs)->next;
|
||||
}
|
||||
|
||||
sk_void_free(ad->sk);
|
||||
ad->sk = NULL;
|
||||
|
||||
@@ -3,16 +3,9 @@
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
#define OPENSSL_NO_ASM
|
||||
#endif
|
||||
#endif
|
||||
#include <CCryptoBoringSSL_asm_base.h>
|
||||
|
||||
#if defined(__x86_64__) && !defined(OPENSSL_NO_ASM) && defined(__ELF__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
#include <CCryptoBoringSSL_boringssl_prefix_symbols_asm.h>
|
||||
#endif
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64) && defined(__ELF__)
|
||||
.text
|
||||
|
||||
.type _aesni_ctr32_ghash_6x,@function
|
||||
@@ -345,7 +338,7 @@ _aesni_ctr32_ghash_6x:
|
||||
vpxor 16+8(%rsp),%xmm8,%xmm8
|
||||
vpxor %xmm4,%xmm8,%xmm8
|
||||
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size _aesni_ctr32_ghash_6x,.-_aesni_ctr32_ghash_6x
|
||||
.globl aesni_gcm_decrypt
|
||||
@@ -355,6 +348,7 @@ _aesni_ctr32_ghash_6x:
|
||||
aesni_gcm_decrypt:
|
||||
.cfi_startproc
|
||||
|
||||
_CET_ENDBR
|
||||
xorq %rax,%rax
|
||||
|
||||
|
||||
@@ -385,17 +379,18 @@ aesni_gcm_decrypt:
|
||||
|
||||
vzeroupper
|
||||
|
||||
movq 16(%rbp),%r12
|
||||
vmovdqu (%r8),%xmm1
|
||||
addq $-128,%rsp
|
||||
movl 12(%r8),%ebx
|
||||
leaq .Lbswap_mask(%rip),%r11
|
||||
leaq -128(%rcx),%r14
|
||||
movq $0xf80,%r15
|
||||
vmovdqu (%r9),%xmm8
|
||||
vmovdqu (%r12),%xmm8
|
||||
andq $-128,%rsp
|
||||
vmovdqu (%r11),%xmm0
|
||||
leaq 128(%rcx),%rcx
|
||||
leaq 32+32(%r9),%r9
|
||||
leaq 32(%r9),%r9
|
||||
movl 240-128(%rcx),%r10d
|
||||
vpshufb %xmm0,%xmm8,%xmm8
|
||||
|
||||
@@ -440,6 +435,7 @@ aesni_gcm_decrypt:
|
||||
|
||||
call _aesni_ctr32_ghash_6x
|
||||
|
||||
movq 16(%rbp),%r12
|
||||
vmovups %xmm9,-96(%rsi)
|
||||
vmovups %xmm10,-80(%rsi)
|
||||
vmovups %xmm11,-64(%rsi)
|
||||
@@ -448,7 +444,7 @@ aesni_gcm_decrypt:
|
||||
vmovups %xmm14,-16(%rsi)
|
||||
|
||||
vpshufb (%r11),%xmm8,%xmm8
|
||||
vmovdqu %xmm8,-64(%r9)
|
||||
vmovdqu %xmm8,(%r12)
|
||||
|
||||
vzeroupper
|
||||
leaq -40(%rbp),%rsp
|
||||
@@ -472,7 +468,7 @@ aesni_gcm_decrypt:
|
||||
.cfi_adjust_cfa_offset -8
|
||||
.cfi_restore %rbp
|
||||
.Lgcm_dec_abort:
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
.cfi_endproc
|
||||
.size aesni_gcm_decrypt,.-aesni_gcm_decrypt
|
||||
@@ -543,7 +539,7 @@ _aesni_ctr32_6x:
|
||||
vmovups %xmm14,80(%rsi)
|
||||
leaq 96(%rsi),%rsi
|
||||
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.align 32
|
||||
.Lhandle_ctr32_2:
|
||||
vpshufb %xmm0,%xmm1,%xmm6
|
||||
@@ -576,6 +572,7 @@ _aesni_ctr32_6x:
|
||||
aesni_gcm_encrypt:
|
||||
.cfi_startproc
|
||||
|
||||
_CET_ENDBR
|
||||
#ifdef BORINGSSL_DISPATCH_TEST
|
||||
.extern BORINGSSL_function_hit
|
||||
.hidden BORINGSSL_function_hit
|
||||
@@ -660,8 +657,9 @@ aesni_gcm_encrypt:
|
||||
|
||||
call _aesni_ctr32_6x
|
||||
|
||||
vmovdqu (%r9),%xmm8
|
||||
leaq 32+32(%r9),%r9
|
||||
movq 16(%rbp),%r12
|
||||
leaq 32(%r9),%r9
|
||||
vmovdqu (%r12),%xmm8
|
||||
subq $12,%rdx
|
||||
movq $192,%rax
|
||||
vpshufb %xmm0,%xmm8,%xmm8
|
||||
@@ -839,8 +837,9 @@ aesni_gcm_encrypt:
|
||||
vpclmulqdq $0x10,%xmm3,%xmm8,%xmm8
|
||||
vpxor %xmm7,%xmm2,%xmm2
|
||||
vpxor %xmm2,%xmm8,%xmm8
|
||||
movq 16(%rbp),%r12
|
||||
vpshufb (%r11),%xmm8,%xmm8
|
||||
vmovdqu %xmm8,-64(%r9)
|
||||
vmovdqu %xmm8,(%r12)
|
||||
|
||||
vzeroupper
|
||||
leaq -40(%rbp),%rsp
|
||||
@@ -864,10 +863,10 @@ aesni_gcm_encrypt:
|
||||
.cfi_adjust_cfa_offset -8
|
||||
.cfi_restore %rbp
|
||||
.Lgcm_enc_abort:
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
.cfi_endproc
|
||||
.size aesni_gcm_decrypt,.-aesni_gcm_decrypt
|
||||
.size aesni_gcm_encrypt,.-aesni_gcm_encrypt
|
||||
.section .rodata
|
||||
.align 64
|
||||
.Lbswap_mask:
|
||||
@@ -884,10 +883,6 @@ aesni_gcm_encrypt:
|
||||
.align 64
|
||||
.text
|
||||
#endif
|
||||
#if defined(__ELF__)
|
||||
// See https://www.airs.com/blog/archives/518.
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
#endif // defined(__x86_64__) && defined(__linux__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
|
||||
@@ -3,16 +3,9 @@
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
#define OPENSSL_NO_ASM
|
||||
#endif
|
||||
#endif
|
||||
#include <CCryptoBoringSSL_asm_base.h>
|
||||
|
||||
#if defined(__x86_64__) && !defined(OPENSSL_NO_ASM) && defined(__APPLE__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
#include <CCryptoBoringSSL_boringssl_prefix_symbols_asm.h>
|
||||
#endif
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64) && defined(__APPLE__)
|
||||
.text
|
||||
|
||||
|
||||
@@ -345,7 +338,7 @@ L$6x_done:
|
||||
vpxor 16+8(%rsp),%xmm8,%xmm8
|
||||
vpxor %xmm4,%xmm8,%xmm8
|
||||
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aesni_gcm_decrypt
|
||||
@@ -355,6 +348,7 @@ L$6x_done:
|
||||
_aesni_gcm_decrypt:
|
||||
|
||||
|
||||
_CET_ENDBR
|
||||
xorq %rax,%rax
|
||||
|
||||
|
||||
@@ -384,17 +378,18 @@ _aesni_gcm_decrypt:
|
||||
|
||||
vzeroupper
|
||||
|
||||
movq 16(%rbp),%r12
|
||||
vmovdqu (%r8),%xmm1
|
||||
addq $-128,%rsp
|
||||
movl 12(%r8),%ebx
|
||||
leaq L$bswap_mask(%rip),%r11
|
||||
leaq -128(%rcx),%r14
|
||||
movq $0xf80,%r15
|
||||
vmovdqu (%r9),%xmm8
|
||||
vmovdqu (%r12),%xmm8
|
||||
andq $-128,%rsp
|
||||
vmovdqu (%r11),%xmm0
|
||||
leaq 128(%rcx),%rcx
|
||||
leaq 32+32(%r9),%r9
|
||||
leaq 32(%r9),%r9
|
||||
movl 240-128(%rcx),%r10d
|
||||
vpshufb %xmm0,%xmm8,%xmm8
|
||||
|
||||
@@ -439,6 +434,7 @@ L$dec_no_key_aliasing:
|
||||
|
||||
call _aesni_ctr32_ghash_6x
|
||||
|
||||
movq 16(%rbp),%r12
|
||||
vmovups %xmm9,-96(%rsi)
|
||||
vmovups %xmm10,-80(%rsi)
|
||||
vmovups %xmm11,-64(%rsi)
|
||||
@@ -447,7 +443,7 @@ L$dec_no_key_aliasing:
|
||||
vmovups %xmm14,-16(%rsi)
|
||||
|
||||
vpshufb (%r11),%xmm8,%xmm8
|
||||
vmovdqu %xmm8,-64(%r9)
|
||||
vmovdqu %xmm8,(%r12)
|
||||
|
||||
vzeroupper
|
||||
leaq -40(%rbp),%rsp
|
||||
@@ -465,7 +461,7 @@ L$dec_no_key_aliasing:
|
||||
popq %rbp
|
||||
|
||||
L$gcm_dec_abort:
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
|
||||
@@ -536,7 +532,7 @@ L$oop_ctr32:
|
||||
vmovups %xmm14,80(%rsi)
|
||||
leaq 96(%rsi),%rsi
|
||||
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.p2align 5
|
||||
L$handle_ctr32_2:
|
||||
vpshufb %xmm0,%xmm1,%xmm6
|
||||
@@ -569,6 +565,7 @@ L$handle_ctr32_2:
|
||||
_aesni_gcm_encrypt:
|
||||
|
||||
|
||||
_CET_ENDBR
|
||||
#ifdef BORINGSSL_DISPATCH_TEST
|
||||
|
||||
movb $1,_BORINGSSL_function_hit+2(%rip)
|
||||
@@ -651,8 +648,9 @@ L$enc_no_key_aliasing:
|
||||
|
||||
call _aesni_ctr32_6x
|
||||
|
||||
vmovdqu (%r9),%xmm8
|
||||
leaq 32+32(%r9),%r9
|
||||
movq 16(%rbp),%r12
|
||||
leaq 32(%r9),%r9
|
||||
vmovdqu (%r12),%xmm8
|
||||
subq $12,%rdx
|
||||
movq $192,%rax
|
||||
vpshufb %xmm0,%xmm8,%xmm8
|
||||
@@ -830,8 +828,9 @@ L$enc_no_key_aliasing:
|
||||
vpclmulqdq $0x10,%xmm3,%xmm8,%xmm8
|
||||
vpxor %xmm7,%xmm2,%xmm2
|
||||
vpxor %xmm2,%xmm8,%xmm8
|
||||
movq 16(%rbp),%r12
|
||||
vpshufb (%r11),%xmm8,%xmm8
|
||||
vmovdqu %xmm8,-64(%r9)
|
||||
vmovdqu %xmm8,(%r12)
|
||||
|
||||
vzeroupper
|
||||
leaq -40(%rbp),%rsp
|
||||
@@ -849,7 +848,7 @@ L$enc_no_key_aliasing:
|
||||
popq %rbp
|
||||
|
||||
L$gcm_enc_abort:
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
|
||||
@@ -869,10 +868,6 @@ L$one_lsb:
|
||||
.p2align 6
|
||||
.text
|
||||
#endif
|
||||
#if defined(__ELF__)
|
||||
// See https://www.airs.com/blog/archives/518.
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
#endif // defined(__x86_64__) && defined(__APPLE__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
|
||||
@@ -3,16 +3,9 @@
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
#define OPENSSL_NO_ASM
|
||||
#endif
|
||||
#endif
|
||||
#include <CCryptoBoringSSL_asm_base.h>
|
||||
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(__i386__) && defined(__ELF__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
#include <CCryptoBoringSSL_boringssl_prefix_symbols_asm.h>
|
||||
#endif
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86) && defined(__ELF__)
|
||||
.text
|
||||
#ifdef BORINGSSL_DISPATCH_TEST
|
||||
#endif
|
||||
@@ -2517,11 +2510,7 @@ aes_hw_set_decrypt_key:
|
||||
.byte 83,45,78,73,44,32,67,82,89,80,84,79,71,65,77,83
|
||||
.byte 32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115
|
||||
.byte 115,108,46,111,114,103,62,0
|
||||
#endif // !defined(OPENSSL_NO_ASM) && defined(__i386__) && defined(__ELF__)
|
||||
#if defined(__ELF__)
|
||||
// See https://www.airs.com/blog/archives/518.
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
#endif // !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86) && defined(__ELF__)
|
||||
#endif // defined(__i386__) && defined(__linux__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
|
||||
@@ -3,16 +3,9 @@
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
#define OPENSSL_NO_ASM
|
||||
#endif
|
||||
#endif
|
||||
#include <CCryptoBoringSSL_asm_base.h>
|
||||
|
||||
#if defined(__x86_64__) && !defined(OPENSSL_NO_ASM) && defined(__ELF__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
#include <CCryptoBoringSSL_boringssl_prefix_symbols_asm.h>
|
||||
#endif
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64) && defined(__ELF__)
|
||||
.text
|
||||
.extern OPENSSL_ia32cap_P
|
||||
.hidden OPENSSL_ia32cap_P
|
||||
@@ -22,6 +15,7 @@
|
||||
.align 16
|
||||
aes_hw_encrypt:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
#ifdef BORINGSSL_DISPATCH_TEST
|
||||
.extern BORINGSSL_function_hit
|
||||
.hidden BORINGSSL_function_hit
|
||||
@@ -44,7 +38,7 @@ aes_hw_encrypt:
|
||||
pxor %xmm1,%xmm1
|
||||
movups %xmm2,(%rsi)
|
||||
pxor %xmm2,%xmm2
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aes_hw_encrypt,.-aes_hw_encrypt
|
||||
|
||||
@@ -54,6 +48,7 @@ aes_hw_encrypt:
|
||||
.align 16
|
||||
aes_hw_decrypt:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
movups (%rdi),%xmm2
|
||||
movl 240(%rdx),%eax
|
||||
movups (%rdx),%xmm0
|
||||
@@ -71,7 +66,7 @@ aes_hw_decrypt:
|
||||
pxor %xmm1,%xmm1
|
||||
movups %xmm2,(%rsi)
|
||||
pxor %xmm2,%xmm2
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aes_hw_decrypt, .-aes_hw_decrypt
|
||||
.type _aesni_encrypt2,@function
|
||||
@@ -102,7 +97,7 @@ _aesni_encrypt2:
|
||||
.byte 102,15,56,220,217
|
||||
.byte 102,15,56,221,208
|
||||
.byte 102,15,56,221,216
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size _aesni_encrypt2,.-_aesni_encrypt2
|
||||
.type _aesni_decrypt2,@function
|
||||
@@ -133,7 +128,7 @@ _aesni_decrypt2:
|
||||
.byte 102,15,56,222,217
|
||||
.byte 102,15,56,223,208
|
||||
.byte 102,15,56,223,216
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size _aesni_decrypt2,.-_aesni_decrypt2
|
||||
.type _aesni_encrypt3,@function
|
||||
@@ -169,7 +164,7 @@ _aesni_encrypt3:
|
||||
.byte 102,15,56,221,208
|
||||
.byte 102,15,56,221,216
|
||||
.byte 102,15,56,221,224
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size _aesni_encrypt3,.-_aesni_encrypt3
|
||||
.type _aesni_decrypt3,@function
|
||||
@@ -205,7 +200,7 @@ _aesni_decrypt3:
|
||||
.byte 102,15,56,223,208
|
||||
.byte 102,15,56,223,216
|
||||
.byte 102,15,56,223,224
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size _aesni_decrypt3,.-_aesni_decrypt3
|
||||
.type _aesni_encrypt4,@function
|
||||
@@ -247,7 +242,7 @@ _aesni_encrypt4:
|
||||
.byte 102,15,56,221,216
|
||||
.byte 102,15,56,221,224
|
||||
.byte 102,15,56,221,232
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size _aesni_encrypt4,.-_aesni_encrypt4
|
||||
.type _aesni_decrypt4,@function
|
||||
@@ -289,7 +284,7 @@ _aesni_decrypt4:
|
||||
.byte 102,15,56,223,216
|
||||
.byte 102,15,56,223,224
|
||||
.byte 102,15,56,223,232
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size _aesni_decrypt4,.-_aesni_decrypt4
|
||||
.type _aesni_encrypt6,@function
|
||||
@@ -345,7 +340,7 @@ _aesni_encrypt6:
|
||||
.byte 102,15,56,221,232
|
||||
.byte 102,15,56,221,240
|
||||
.byte 102,15,56,221,248
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size _aesni_encrypt6,.-_aesni_encrypt6
|
||||
.type _aesni_decrypt6,@function
|
||||
@@ -401,7 +396,7 @@ _aesni_decrypt6:
|
||||
.byte 102,15,56,223,232
|
||||
.byte 102,15,56,223,240
|
||||
.byte 102,15,56,223,248
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size _aesni_decrypt6,.-_aesni_decrypt6
|
||||
.type _aesni_encrypt8,@function
|
||||
@@ -467,7 +462,7 @@ _aesni_encrypt8:
|
||||
.byte 102,15,56,221,248
|
||||
.byte 102,68,15,56,221,192
|
||||
.byte 102,68,15,56,221,200
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size _aesni_encrypt8,.-_aesni_encrypt8
|
||||
.type _aesni_decrypt8,@function
|
||||
@@ -533,7 +528,7 @@ _aesni_decrypt8:
|
||||
.byte 102,15,56,223,248
|
||||
.byte 102,68,15,56,223,192
|
||||
.byte 102,68,15,56,223,200
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size _aesni_decrypt8,.-_aesni_decrypt8
|
||||
.globl aes_hw_ecb_encrypt
|
||||
@@ -542,6 +537,7 @@ _aesni_decrypt8:
|
||||
.align 16
|
||||
aes_hw_ecb_encrypt:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
andq $-16,%rdx
|
||||
jz .Lecb_ret
|
||||
|
||||
@@ -878,7 +874,7 @@ aes_hw_ecb_encrypt:
|
||||
.Lecb_ret:
|
||||
xorps %xmm0,%xmm0
|
||||
pxor %xmm1,%xmm1
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aes_hw_ecb_encrypt,.-aes_hw_ecb_encrypt
|
||||
.globl aes_hw_ctr32_encrypt_blocks
|
||||
@@ -887,6 +883,7 @@ aes_hw_ecb_encrypt:
|
||||
.align 16
|
||||
aes_hw_ctr32_encrypt_blocks:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
#ifdef BORINGSSL_DISPATCH_TEST
|
||||
movb $1,BORINGSSL_function_hit(%rip)
|
||||
#endif
|
||||
@@ -1264,6 +1261,8 @@ aes_hw_ctr32_encrypt_blocks:
|
||||
pxor %xmm0,%xmm13
|
||||
movdqu 80(%rdi),%xmm15
|
||||
pxor %xmm0,%xmm14
|
||||
prefetcht0 448(%rdi)
|
||||
prefetcht0 512(%rdi)
|
||||
pxor %xmm0,%xmm15
|
||||
.byte 102,15,56,220,209
|
||||
.byte 102,15,56,220,217
|
||||
@@ -1461,7 +1460,7 @@ aes_hw_ctr32_encrypt_blocks:
|
||||
leaq (%r11),%rsp
|
||||
.cfi_def_cfa_register %rsp
|
||||
.Lctr32_epilogue:
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aes_hw_ctr32_encrypt_blocks,.-aes_hw_ctr32_encrypt_blocks
|
||||
.globl aes_hw_cbc_encrypt
|
||||
@@ -1470,6 +1469,7 @@ aes_hw_ctr32_encrypt_blocks:
|
||||
.align 16
|
||||
aes_hw_cbc_encrypt:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
testq %rdx,%rdx
|
||||
jz .Lcbc_ret
|
||||
|
||||
@@ -2054,7 +2054,7 @@ aes_hw_cbc_encrypt:
|
||||
leaq (%r11),%rsp
|
||||
.cfi_def_cfa_register %rsp
|
||||
.Lcbc_ret:
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aes_hw_cbc_encrypt,.-aes_hw_cbc_encrypt
|
||||
.globl aes_hw_set_decrypt_key
|
||||
@@ -2063,6 +2063,7 @@ aes_hw_cbc_encrypt:
|
||||
.align 16
|
||||
aes_hw_set_decrypt_key:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
.byte 0x48,0x83,0xEC,0x08
|
||||
.cfi_adjust_cfa_offset 8
|
||||
call __aesni_set_encrypt_key
|
||||
@@ -2098,7 +2099,7 @@ aes_hw_set_decrypt_key:
|
||||
.Ldec_key_ret:
|
||||
addq $8,%rsp
|
||||
.cfi_adjust_cfa_offset -8
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.LSEH_end_set_decrypt_key:
|
||||
.size aes_hw_set_decrypt_key,.-aes_hw_set_decrypt_key
|
||||
@@ -2109,6 +2110,7 @@ aes_hw_set_decrypt_key:
|
||||
aes_hw_set_encrypt_key:
|
||||
__aesni_set_encrypt_key:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
#ifdef BORINGSSL_DISPATCH_TEST
|
||||
movb $1,BORINGSSL_function_hit+3(%rip)
|
||||
#endif
|
||||
@@ -2408,7 +2410,7 @@ __aesni_set_encrypt_key:
|
||||
pxor %xmm5,%xmm5
|
||||
addq $8,%rsp
|
||||
.cfi_adjust_cfa_offset -8
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.LSEH_end_set_encrypt_key:
|
||||
|
||||
@@ -2423,7 +2425,7 @@ __aesni_set_encrypt_key:
|
||||
xorps %xmm4,%xmm0
|
||||
shufps $255,%xmm1,%xmm1
|
||||
xorps %xmm1,%xmm0
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
.align 16
|
||||
.Lkey_expansion_192a:
|
||||
@@ -2443,7 +2445,7 @@ __aesni_set_encrypt_key:
|
||||
pxor %xmm1,%xmm0
|
||||
pshufd $255,%xmm0,%xmm3
|
||||
pxor %xmm3,%xmm2
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
.align 16
|
||||
.Lkey_expansion_192b:
|
||||
@@ -2466,7 +2468,7 @@ __aesni_set_encrypt_key:
|
||||
xorps %xmm4,%xmm0
|
||||
shufps $255,%xmm1,%xmm1
|
||||
xorps %xmm1,%xmm0
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
.align 16
|
||||
.Lkey_expansion_256b:
|
||||
@@ -2479,7 +2481,7 @@ __aesni_set_encrypt_key:
|
||||
xorps %xmm4,%xmm2
|
||||
shufps $170,%xmm1,%xmm1
|
||||
xorps %xmm1,%xmm2
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.size aes_hw_set_encrypt_key,.-aes_hw_set_encrypt_key
|
||||
.size __aesni_set_encrypt_key,.-__aesni_set_encrypt_key
|
||||
.section .rodata
|
||||
@@ -2507,10 +2509,6 @@ __aesni_set_encrypt_key:
|
||||
.align 64
|
||||
.text
|
||||
#endif
|
||||
#if defined(__ELF__)
|
||||
// See https://www.airs.com/blog/archives/518.
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
#endif // defined(__x86_64__) && defined(__linux__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
|
||||
@@ -3,16 +3,9 @@
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if defined(__has_feature)
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
#define OPENSSL_NO_ASM
|
||||
#endif
|
||||
#endif
|
||||
#include <CCryptoBoringSSL_asm_base.h>
|
||||
|
||||
#if defined(__x86_64__) && !defined(OPENSSL_NO_ASM) && defined(__APPLE__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
#include <CCryptoBoringSSL_boringssl_prefix_symbols_asm.h>
|
||||
#endif
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64) && defined(__APPLE__)
|
||||
.text
|
||||
|
||||
.globl _aes_hw_encrypt
|
||||
@@ -21,6 +14,7 @@
|
||||
.p2align 4
|
||||
_aes_hw_encrypt:
|
||||
|
||||
_CET_ENDBR
|
||||
#ifdef BORINGSSL_DISPATCH_TEST
|
||||
|
||||
movb $1,_BORINGSSL_function_hit+1(%rip)
|
||||
@@ -42,7 +36,7 @@ L$oop_enc1_1:
|
||||
pxor %xmm1,%xmm1
|
||||
movups %xmm2,(%rsi)
|
||||
pxor %xmm2,%xmm2
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
|
||||
@@ -52,6 +46,7 @@ L$oop_enc1_1:
|
||||
.p2align 4
|
||||
_aes_hw_decrypt:
|
||||
|
||||
_CET_ENDBR
|
||||
movups (%rdi),%xmm2
|
||||
movl 240(%rdx),%eax
|
||||
movups (%rdx),%xmm0
|
||||
@@ -69,7 +64,7 @@ L$oop_dec1_2:
|
||||
pxor %xmm1,%xmm1
|
||||
movups %xmm2,(%rsi)
|
||||
pxor %xmm2,%xmm2
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
|
||||
@@ -100,7 +95,7 @@ L$enc_loop2:
|
||||
.byte 102,15,56,220,217
|
||||
.byte 102,15,56,221,208
|
||||
.byte 102,15,56,221,216
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
|
||||
@@ -131,7 +126,7 @@ L$dec_loop2:
|
||||
.byte 102,15,56,222,217
|
||||
.byte 102,15,56,223,208
|
||||
.byte 102,15,56,223,216
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
|
||||
@@ -167,7 +162,7 @@ L$enc_loop3:
|
||||
.byte 102,15,56,221,208
|
||||
.byte 102,15,56,221,216
|
||||
.byte 102,15,56,221,224
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
|
||||
@@ -203,7 +198,7 @@ L$dec_loop3:
|
||||
.byte 102,15,56,223,208
|
||||
.byte 102,15,56,223,216
|
||||
.byte 102,15,56,223,224
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
|
||||
@@ -245,7 +240,7 @@ L$enc_loop4:
|
||||
.byte 102,15,56,221,216
|
||||
.byte 102,15,56,221,224
|
||||
.byte 102,15,56,221,232
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
|
||||
@@ -287,7 +282,7 @@ L$dec_loop4:
|
||||
.byte 102,15,56,223,216
|
||||
.byte 102,15,56,223,224
|
||||
.byte 102,15,56,223,232
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
|
||||
@@ -343,7 +338,7 @@ L$enc_loop6_enter:
|
||||
.byte 102,15,56,221,232
|
||||
.byte 102,15,56,221,240
|
||||
.byte 102,15,56,221,248
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
|
||||
@@ -399,7 +394,7 @@ L$dec_loop6_enter:
|
||||
.byte 102,15,56,223,232
|
||||
.byte 102,15,56,223,240
|
||||
.byte 102,15,56,223,248
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
|
||||
@@ -465,7 +460,7 @@ L$enc_loop8_enter:
|
||||
.byte 102,15,56,221,248
|
||||
.byte 102,68,15,56,221,192
|
||||
.byte 102,68,15,56,221,200
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
|
||||
@@ -531,7 +526,7 @@ L$dec_loop8_enter:
|
||||
.byte 102,15,56,223,248
|
||||
.byte 102,68,15,56,223,192
|
||||
.byte 102,68,15,56,223,200
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aes_hw_ecb_encrypt
|
||||
@@ -540,6 +535,7 @@ L$dec_loop8_enter:
|
||||
.p2align 4
|
||||
_aes_hw_ecb_encrypt:
|
||||
|
||||
_CET_ENDBR
|
||||
andq $-16,%rdx
|
||||
jz L$ecb_ret
|
||||
|
||||
@@ -876,7 +872,7 @@ L$ecb_dec_six:
|
||||
L$ecb_ret:
|
||||
xorps %xmm0,%xmm0
|
||||
pxor %xmm1,%xmm1
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aes_hw_ctr32_encrypt_blocks
|
||||
@@ -885,6 +881,7 @@ L$ecb_ret:
|
||||
.p2align 4
|
||||
_aes_hw_ctr32_encrypt_blocks:
|
||||
|
||||
_CET_ENDBR
|
||||
#ifdef BORINGSSL_DISPATCH_TEST
|
||||
movb $1,_BORINGSSL_function_hit(%rip)
|
||||
#endif
|
||||
@@ -1262,6 +1259,8 @@ L$ctr32_enc_done:
|
||||
pxor %xmm0,%xmm13
|
||||
movdqu 80(%rdi),%xmm15
|
||||
pxor %xmm0,%xmm14
|
||||
prefetcht0 448(%rdi)
|
||||
prefetcht0 512(%rdi)
|
||||
pxor %xmm0,%xmm15
|
||||
.byte 102,15,56,220,209
|
||||
.byte 102,15,56,220,217
|
||||
@@ -1459,7 +1458,7 @@ L$ctr32_done:
|
||||
leaq (%r11),%rsp
|
||||
|
||||
L$ctr32_epilogue:
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aes_hw_cbc_encrypt
|
||||
@@ -1468,6 +1467,7 @@ L$ctr32_epilogue:
|
||||
.p2align 4
|
||||
_aes_hw_cbc_encrypt:
|
||||
|
||||
_CET_ENDBR
|
||||
testq %rdx,%rdx
|
||||
jz L$cbc_ret
|
||||
|
||||
@@ -2052,7 +2052,7 @@ L$cbc_dec_ret:
|
||||
leaq (%r11),%rsp
|
||||
|
||||
L$cbc_ret:
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aes_hw_set_decrypt_key
|
||||
@@ -2061,6 +2061,7 @@ L$cbc_ret:
|
||||
.p2align 4
|
||||
_aes_hw_set_decrypt_key:
|
||||
|
||||
_CET_ENDBR
|
||||
.byte 0x48,0x83,0xEC,0x08
|
||||
|
||||
call __aesni_set_encrypt_key
|
||||
@@ -2096,7 +2097,7 @@ L$dec_key_inverse:
|
||||
L$dec_key_ret:
|
||||
addq $8,%rsp
|
||||
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
L$SEH_end_set_decrypt_key:
|
||||
|
||||
@@ -2107,6 +2108,7 @@ L$SEH_end_set_decrypt_key:
|
||||
_aes_hw_set_encrypt_key:
|
||||
__aesni_set_encrypt_key:
|
||||
|
||||
_CET_ENDBR
|
||||
#ifdef BORINGSSL_DISPATCH_TEST
|
||||
movb $1,_BORINGSSL_function_hit+3(%rip)
|
||||
#endif
|
||||
@@ -2406,7 +2408,7 @@ L$enc_key_ret:
|
||||
pxor %xmm5,%xmm5
|
||||
addq $8,%rsp
|
||||
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
L$SEH_end_set_encrypt_key:
|
||||
|
||||
@@ -2421,7 +2423,7 @@ L$key_expansion_128_cold:
|
||||
xorps %xmm4,%xmm0
|
||||
shufps $255,%xmm1,%xmm1
|
||||
xorps %xmm1,%xmm0
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
.p2align 4
|
||||
L$key_expansion_192a:
|
||||
@@ -2441,7 +2443,7 @@ L$key_expansion_192b_warm:
|
||||
pxor %xmm1,%xmm0
|
||||
pshufd $255,%xmm0,%xmm3
|
||||
pxor %xmm3,%xmm2
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
.p2align 4
|
||||
L$key_expansion_192b:
|
||||
@@ -2464,7 +2466,7 @@ L$key_expansion_256a_cold:
|
||||
xorps %xmm4,%xmm0
|
||||
shufps $255,%xmm1,%xmm1
|
||||
xorps %xmm1,%xmm0
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
.p2align 4
|
||||
L$key_expansion_256b:
|
||||
@@ -2477,7 +2479,7 @@ L$key_expansion_256b:
|
||||
xorps %xmm4,%xmm2
|
||||
shufps $170,%xmm1,%xmm1
|
||||
xorps %xmm1,%xmm2
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.section __DATA,__const
|
||||
@@ -2505,10 +2507,6 @@ L$key_rcon1b:
|
||||
.p2align 6
|
||||
.text
|
||||
#endif
|
||||
#if defined(__ELF__)
|
||||
// See https://www.airs.com/blog/archives/518.
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
#endif // defined(__x86_64__) && defined(__APPLE__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
|
||||
@@ -3,17 +3,9 @@
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if !defined(__has_feature)
|
||||
#define __has_feature(x) 0
|
||||
#endif
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
#define OPENSSL_NO_ASM
|
||||
#endif
|
||||
#include <CCryptoBoringSSL_asm_base.h>
|
||||
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(__ARMEL__) && defined(__APPLE__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
#include <CCryptoBoringSSL_boringssl_prefix_symbols_asm.h>
|
||||
#endif
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_ARM) && defined(__APPLE__)
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
#if __ARM_MAX_ARCH__>=7
|
||||
@@ -808,11 +800,7 @@ Lctr32_done:
|
||||
ldmia sp!,{r4,r5,r6,r7,r8,r9,r10,pc}
|
||||
|
||||
#endif
|
||||
#endif // !OPENSSL_NO_ASM && defined(__ARMEL__) && defined(__APPLE__)
|
||||
#if defined(__ELF__)
|
||||
// See https://www.airs.com/blog/archives/518.
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
#endif // !OPENSSL_NO_ASM && defined(OPENSSL_ARM) && defined(__APPLE__)
|
||||
#endif // defined(__arm__) && defined(__APPLE__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
|
||||
@@ -3,17 +3,9 @@
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if !defined(__has_feature)
|
||||
#define __has_feature(x) 0
|
||||
#endif
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
#define OPENSSL_NO_ASM
|
||||
#endif
|
||||
#include <CCryptoBoringSSL_asm_base.h>
|
||||
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(__ARMEL__) && defined(__ELF__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
#include <CCryptoBoringSSL_boringssl_prefix_symbols_asm.h>
|
||||
#endif
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_ARM) && defined(__ELF__)
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
#if __ARM_MAX_ARCH__>=7
|
||||
@@ -796,11 +788,7 @@ aes_hw_ctr32_encrypt_blocks:
|
||||
ldmia sp!,{r4,r5,r6,r7,r8,r9,r10,pc}
|
||||
.size aes_hw_ctr32_encrypt_blocks,.-aes_hw_ctr32_encrypt_blocks
|
||||
#endif
|
||||
#endif // !OPENSSL_NO_ASM && defined(__ARMEL__) && defined(__ELF__)
|
||||
#if defined(__ELF__)
|
||||
// See https://www.airs.com/blog/archives/518.
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
#endif // !OPENSSL_NO_ASM && defined(OPENSSL_ARM) && defined(__ELF__)
|
||||
#endif // defined(__arm__) && defined(__linux__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
|
||||
@@ -3,17 +3,9 @@
|
||||
// This file is generated from a similarly-named Perl script in the BoringSSL
|
||||
// source tree. Do not edit by hand.
|
||||
|
||||
#if !defined(__has_feature)
|
||||
#define __has_feature(x) 0
|
||||
#endif
|
||||
#if __has_feature(memory_sanitizer) && !defined(OPENSSL_NO_ASM)
|
||||
#define OPENSSL_NO_ASM
|
||||
#endif
|
||||
#include <CCryptoBoringSSL_asm_base.h>
|
||||
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(__AARCH64EL__) && defined(__APPLE__)
|
||||
#if defined(BORINGSSL_PREFIX)
|
||||
#include <CCryptoBoringSSL_boringssl_prefix_symbols_asm.h>
|
||||
#endif
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_AARCH64) && defined(__APPLE__)
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
#if __ARM_MAX_ARCH__>=7
|
||||
@@ -798,11 +790,7 @@ Lctr32_done:
|
||||
ret
|
||||
|
||||
#endif
|
||||
#endif // !OPENSSL_NO_ASM && defined(__AARCH64EL__) && defined(__APPLE__)
|
||||
#if defined(__ELF__)
|
||||
// See https://www.airs.com/blog/archives/518.
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
#endif
|
||||
#endif // !OPENSSL_NO_ASM && defined(OPENSSL_AARCH64) && defined(__APPLE__)
|
||||
#endif // defined(__aarch64__) && defined(__APPLE__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
|
||||
Loaded 100 of 537 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user