mirror of
https://github.com/apple/swift-crypto
synced 2026-11-22 04:30:39 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
46072478ca | ||
|
|
c370ad81a1 | ||
|
|
33f65a3cbc | ||
|
|
fdfdc11707 | ||
|
|
a3866d45d9 | ||
|
|
5fb3819b51 | ||
|
|
3c060cc4af | ||
|
|
c36d19a064 | ||
|
|
bc1c29221f | ||
|
|
2adec617e6 | ||
|
|
89876ab72c | ||
|
|
f0525da24d | ||
|
|
52d0d9f15a | ||
|
|
9960a73340 | ||
|
|
606608da08 | ||
|
|
029eeacda4 | ||
|
|
cc76b89416 | ||
|
|
3e8497753e | ||
|
|
c1825df19b | ||
|
|
09f7a993f6 | ||
|
|
ed66091040 | ||
|
|
b793a1e564 | ||
|
|
f4b21dbde7 | ||
|
|
3df7fa0626 | ||
|
|
7644bdcc76 | ||
|
|
fade397763 | ||
|
|
c4f2e9938a | ||
|
|
b51f1d6845 | ||
|
|
faad1cf4fd |
No files matched your search
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>NSPrivacyTracking</key>
|
||||
<false/>
|
||||
<key>NSPrivacyAccessedAPITypes</key>
|
||||
<array/>
|
||||
<key>NSPrivacyCollectedDataTypes</key>
|
||||
<array/>
|
||||
<key>NSPrivacyTrackingDomains</key>
|
||||
<array/>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
@@ -15,3 +15,4 @@ DerivedData
|
||||
|
||||
.*.sw[nop]
|
||||
|
||||
.vscode
|
||||
+20
-4
@@ -1,4 +1,4 @@
|
||||
// swift-tools-version:5.6
|
||||
// swift-tools-version:5.8
|
||||
//===----------------------------------------------------------------------===//
|
||||
//
|
||||
// This source file is part of the SwiftCrypto open source project
|
||||
@@ -20,7 +20,7 @@
|
||||
// Sources/CCryptoBoringSSL directory. The source repository is at
|
||||
// https://boringssl.googlesource.com/boringssl.
|
||||
//
|
||||
// BoringSSL Commit: 7ae2b910c13017b63f1a8bd6c8decfce692869b0
|
||||
// BoringSSL Commit: dbad745811195c00b729efd0ee0a09b7d9fce1d2
|
||||
|
||||
import PackageDescription
|
||||
|
||||
@@ -88,6 +88,9 @@ let package = Package(
|
||||
"crypto/bio/socket_helper.c",
|
||||
"crypto/bio/socket.c"
|
||||
],
|
||||
resources: [
|
||||
.copy("PrivacyInfo.xcprivacy"),
|
||||
],
|
||||
cSettings: [
|
||||
// These defines come from BoringSSL's build system
|
||||
.define("_HAS_EXCEPTIONS", to: "0", .when(platforms: [Platform.windows])),
|
||||
@@ -106,6 +109,9 @@ let package = Package(
|
||||
dependencies: ["CCryptoBoringSSL"],
|
||||
exclude: [
|
||||
"CMakeLists.txt"
|
||||
],
|
||||
resources: [
|
||||
.copy("PrivacyInfo.xcprivacy"),
|
||||
]
|
||||
),
|
||||
.target(
|
||||
@@ -118,7 +124,10 @@ let package = Package(
|
||||
"Key Agreement/ECDH.swift.gyb",
|
||||
"Signatures/ECDSA.swift.gyb",
|
||||
],
|
||||
swiftSettings: swiftSettings
|
||||
resources: [
|
||||
.copy("PrivacyInfo.xcprivacy"),
|
||||
],
|
||||
swiftSettings: swiftSettings + [.define("MODULE_IS_CRYPTO")]
|
||||
),
|
||||
.target(
|
||||
name: "_CryptoExtras",
|
||||
@@ -130,7 +139,11 @@ let package = Package(
|
||||
],
|
||||
exclude: [
|
||||
"CMakeLists.txt",
|
||||
]
|
||||
],
|
||||
resources: [
|
||||
.copy("PrivacyInfo.xcprivacy"),
|
||||
],
|
||||
swiftSettings: swiftSettings
|
||||
),
|
||||
.target(
|
||||
name: "CryptoBoringWrapper",
|
||||
@@ -140,6 +153,9 @@ let package = Package(
|
||||
],
|
||||
exclude: [
|
||||
"CMakeLists.txt",
|
||||
],
|
||||
resources: [
|
||||
.copy("PrivacyInfo.xcprivacy"),
|
||||
]
|
||||
),
|
||||
.executableTarget(name: "crypto-shasum", dependencies: ["Crypto"]),
|
||||
|
||||
@@ -7,9 +7,9 @@ Swift Crypto is an open-source implementation of a substantial portion of the AP
|
||||
Swift Crypto is available as a Swift Package Manager package. To use it, add the following dependency in your `Package.swift`:
|
||||
|
||||
```swift
|
||||
// swift-crypto 1.x and 2.x are almost API compatible, so most clients should
|
||||
// allow either
|
||||
.package(url: "https://github.com/apple/swift-crypto.git", "1.0.0" ..< "3.0.0"),
|
||||
// swift-crypto 1.x, 2.x and 3.x are almost API compatible, so most clients
|
||||
// should allow any of them
|
||||
.package(url: "https://github.com/apple/swift-crypto.git", "1.0.0" ..< "4.0.0"),
|
||||
```
|
||||
|
||||
and to your target, add `Crypto` to your dependencies. You can then `import Crypto` to get access to Swift Crypto's functionality.
|
||||
@@ -108,14 +108,16 @@ 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 ..< 3.3.0` | 5.7
|
||||
`3.3.0 ...` | 5.8
|
||||
|
||||
### Compatibility
|
||||
|
||||
@@ -135,5 +137,5 @@ To do so, please use the following dependency in your `Package.swift`:
|
||||
|
||||
### Developing Swift Crypto on macOS
|
||||
|
||||
Swift Crypto normally defers to the OS implementation of CryptoKit on macOS. Naturally, this makes developing Swift Crypto on macOS tricky. To get Swift Crypto to build the open source implementation on macOS, in `Package.swift`, uncomment the line that reads: `//.define("CRYPTO_IN_SWIFTPM_FORCE_BUILD_API")`, as this will force Swift Crypto to build its public API.
|
||||
Swift Crypto normally defers to the OS implementation of CryptoKit on macOS. Naturally, this makes developing Swift Crypto on macOS tricky. To get Swift Crypto to build the open source implementation on macOS, in `Package.swift`, change `let development = false` to `let development = true`, as this will force Swift Crypto to build its public API.
|
||||
|
||||
+32
-28
@@ -80,7 +80,6 @@ add_library(CCryptoBoringSSL STATIC
|
||||
"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"
|
||||
@@ -199,7 +198,7 @@ add_library(CCryptoBoringSSL STATIC
|
||||
"crypto/fipsmodule/tls/kdf.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"
|
||||
@@ -236,6 +235,13 @@ add_library(CCryptoBoringSSL STATIC
|
||||
"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"
|
||||
@@ -259,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"
|
||||
@@ -283,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
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
../../.PrivacyInfo.xcprivacy
|
||||
@@ -58,7 +58,7 @@
|
||||
#include <CCryptoBoringSSL_bytestring.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_time.h>
|
||||
#include <CCryptoBoringSSL_posix_time.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -97,22 +97,22 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in,
|
||||
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;
|
||||
|
||||
@@ -162,7 +162,7 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in,
|
||||
}
|
||||
|
||||
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=%zu", (size_t)maxsize);
|
||||
@@ -178,7 +178,7 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in,
|
||||
|
||||
// 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) {
|
||||
@@ -190,17 +190,17 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in,
|
||||
} 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"
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
* [including the GNU Public Licence.] */
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
#include <CCryptoBoringSSL_time.h>
|
||||
#include <CCryptoBoringSSL_posix_time.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -58,7 +58,7 @@
|
||||
#include <CCryptoBoringSSL_bytestring.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_time.h>
|
||||
#include <CCryptoBoringSSL_posix_time.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -76,18 +76,12 @@ extern "C" {
|
||||
// returned. On failure NULL is returned.
|
||||
OPENSSL_EXPORT struct tm *OPENSSL_gmtime(const time_t *time, struct tm *result);
|
||||
|
||||
// OPENSSL_timegm converts a time value between the years 0 and 9999 in |tm| to
|
||||
// a time_t value in |out|. One is returned on success, zero is returned on
|
||||
// failure. It is a failure if the converted time can not be represented in a
|
||||
// time_t, or if the tm contains out of range values.
|
||||
OPENSSL_EXPORT int OPENSSL_timegm(const struct tm *tm, time_t *out);
|
||||
|
||||
// OPENSSL_gmtime_adj returns one on success, and updates |tm| by adding
|
||||
// |offset_day| days and |offset_sec| seconds. It returns zero on failure. |tm|
|
||||
// must be in the range of year 0000 to 9999 both before and after the update or
|
||||
// a failure will be returned.
|
||||
OPENSSL_EXPORT int OPENSSL_gmtime_adj(struct tm *tm, int offset_day,
|
||||
long offset_sec);
|
||||
int64_t offset_sec);
|
||||
|
||||
// OPENSSL_gmtime_diff calculates the difference between |from| and |to|. It
|
||||
// returns one, and outputs the difference as a number of days and seconds in
|
||||
@@ -210,6 +204,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 +254,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;
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
// Time conversion to/from POSIX time_t and struct tm, with no support
|
||||
// for time zones other than UTC
|
||||
|
||||
#include <CCryptoBoringSSL_time.h>
|
||||
#include <CCryptoBoringSSL_posix_time.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <inttypes.h>
|
||||
@@ -26,12 +26,12 @@
|
||||
#include "internal.h"
|
||||
|
||||
#define SECS_PER_HOUR (60 * 60)
|
||||
#define SECS_PER_DAY (24 * SECS_PER_HOUR)
|
||||
#define SECS_PER_DAY (INT64_C(24) * SECS_PER_HOUR)
|
||||
|
||||
|
||||
// Is a year/month/day combination valid, in the range from year 0000
|
||||
// to 9999?
|
||||
static int is_valid_date(int year, int month, int day) {
|
||||
static int is_valid_date(int64_t year, int64_t month, int64_t day) {
|
||||
if (day < 1 || month < 1 || year < 0 || year > 9999) {
|
||||
return 0;
|
||||
}
|
||||
@@ -62,7 +62,7 @@ static int is_valid_date(int year, int month, int day) {
|
||||
|
||||
// Is a time valid? Leap seconds of 60 are not considered valid, as
|
||||
// the POSIX time in seconds does not include them.
|
||||
static int is_valid_time(int hours, int minutes, int seconds) {
|
||||
static int is_valid_time(int64_t hours, int64_t minutes, int64_t seconds) {
|
||||
if (hours < 0 || minutes < 0 || seconds < 0 || hours > 23 || minutes > 59 ||
|
||||
seconds > 59) {
|
||||
return 0;
|
||||
@@ -70,17 +70,22 @@ static int is_valid_time(int hours, int minutes, int seconds) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Is a int64 time representing a time within our expected range?
|
||||
static int is_valid_epoch_time(int64_t time) {
|
||||
// 0000-01-01 00:00:00 UTC to 9999-12-31 23:59:59 UTC
|
||||
return (int64_t)-62167219200 <= time && time <= (int64_t)253402300799;
|
||||
// 0000-01-01 00:00:00 UTC
|
||||
#define MIN_POSIX_TIME INT64_C(-62167219200)
|
||||
// 9999-12-31 23:59:59 UTC
|
||||
#define MAX_POSIX_TIME INT64_C(253402300799)
|
||||
|
||||
// Is an int64 time within our expected range?
|
||||
static int is_valid_posix_time(int64_t time) {
|
||||
return MIN_POSIX_TIME <= time && time <= MAX_POSIX_TIME;
|
||||
}
|
||||
|
||||
// Inspired by algorithms presented in
|
||||
// https://howardhinnant.github.io/date_algorithms.html
|
||||
// (Public Domain)
|
||||
static int posix_time_from_utc(int year, int month, int day, int hours,
|
||||
int minutes, int seconds, int64_t *out_time) {
|
||||
static int posix_time_from_utc(int64_t year, int64_t month, int64_t day,
|
||||
int64_t hours, int64_t minutes, int64_t seconds,
|
||||
int64_t *out_time) {
|
||||
if (!is_valid_date(year, month, day) ||
|
||||
!is_valid_time(hours, minutes, seconds)) {
|
||||
return 0;
|
||||
@@ -108,7 +113,7 @@ static int posix_time_from_utc(int year, int month, int day, int hours,
|
||||
static int utc_from_posix_time(int64_t time, int *out_year, int *out_month,
|
||||
int *out_day, int *out_hours, int *out_minutes,
|
||||
int *out_seconds) {
|
||||
if (!is_valid_epoch_time(time)) {
|
||||
if (!is_valid_posix_time(time)) {
|
||||
return 0;
|
||||
}
|
||||
int64_t days = time / SECS_PER_DAY;
|
||||
@@ -143,19 +148,21 @@ static int utc_from_posix_time(int64_t time, int *out_year, int *out_month,
|
||||
}
|
||||
|
||||
int OPENSSL_tm_to_posix(const struct tm *tm, int64_t *out) {
|
||||
return posix_time_from_utc(tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
|
||||
tm->tm_hour, tm->tm_min, tm->tm_sec, out);
|
||||
return posix_time_from_utc(tm->tm_year + INT64_C(1900),
|
||||
tm->tm_mon + INT64_C(1), tm->tm_mday, tm->tm_hour,
|
||||
tm->tm_min, tm->tm_sec, out);
|
||||
}
|
||||
|
||||
int OPENSSL_posix_to_tm(int64_t time, struct tm *out_tm) {
|
||||
memset(out_tm, 0, sizeof(struct tm));
|
||||
if (!utc_from_posix_time(time, &out_tm->tm_year, &out_tm->tm_mon,
|
||||
&out_tm->tm_mday, &out_tm->tm_hour, &out_tm->tm_min,
|
||||
&out_tm->tm_sec)) {
|
||||
struct tm tmp_tm = {0};
|
||||
if (!utc_from_posix_time(time, &tmp_tm.tm_year, &tmp_tm.tm_mon,
|
||||
&tmp_tm.tm_mday, &tmp_tm.tm_hour, &tmp_tm.tm_min,
|
||||
&tmp_tm.tm_sec)) {
|
||||
return 0;
|
||||
}
|
||||
out_tm->tm_year -= 1900;
|
||||
out_tm->tm_mon -= 1;
|
||||
tmp_tm.tm_year -= 1900;
|
||||
tmp_tm.tm_mon -= 1;
|
||||
*out_tm = tmp_tm;
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -187,43 +194,47 @@ struct tm *OPENSSL_gmtime(const time_t *time, struct tm *out_tm) {
|
||||
return out_tm;
|
||||
}
|
||||
|
||||
int OPENSSL_gmtime_adj(struct tm *tm, int off_day, long offset_sec) {
|
||||
int OPENSSL_gmtime_adj(struct tm *tm, int offset_day, int64_t offset_sec) {
|
||||
int64_t posix_time;
|
||||
if (!posix_time_from_utc(tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
|
||||
tm->tm_hour, tm->tm_min, tm->tm_sec, &posix_time)) {
|
||||
if (!OPENSSL_tm_to_posix(tm, &posix_time)) {
|
||||
return 0;
|
||||
}
|
||||
if (!utc_from_posix_time(
|
||||
posix_time + (int64_t)off_day * SECS_PER_DAY + offset_sec,
|
||||
&tm->tm_year, &tm->tm_mon, &tm->tm_mday, &tm->tm_hour, &tm->tm_min,
|
||||
&tm->tm_sec)) {
|
||||
static_assert(INT_MAX <= INT64_MAX / SECS_PER_DAY,
|
||||
"day offset in seconds cannot overflow");
|
||||
static_assert(MAX_POSIX_TIME <= INT64_MAX - INT_MAX * SECS_PER_DAY,
|
||||
"addition cannot overflow");
|
||||
static_assert(MIN_POSIX_TIME >= INT64_MIN - INT_MIN * SECS_PER_DAY,
|
||||
"addition cannot underflow");
|
||||
posix_time += offset_day * SECS_PER_DAY;
|
||||
if (posix_time > 0 && offset_sec > INT64_MAX - posix_time) {
|
||||
return 0;
|
||||
}
|
||||
if (posix_time < 0 && offset_sec < INT64_MIN - posix_time) {
|
||||
return 0;
|
||||
}
|
||||
posix_time += offset_sec;
|
||||
|
||||
if (!OPENSSL_posix_to_tm(posix_time, tm)) {
|
||||
return 0;
|
||||
}
|
||||
tm->tm_year -= 1900;
|
||||
tm->tm_mon -= 1;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int OPENSSL_gmtime_diff(int *out_days, int *out_secs, const struct tm *from,
|
||||
const struct tm *to) {
|
||||
int64_t time_to;
|
||||
if (!posix_time_from_utc(to->tm_year + 1900, to->tm_mon + 1, to->tm_mday,
|
||||
to->tm_hour, to->tm_min, to->tm_sec, &time_to)) {
|
||||
return 0;
|
||||
}
|
||||
int64_t time_from;
|
||||
if (!posix_time_from_utc(from->tm_year + 1900, from->tm_mon + 1,
|
||||
from->tm_mday, from->tm_hour, from->tm_min,
|
||||
from->tm_sec, &time_from)) {
|
||||
int64_t time_to, time_from;
|
||||
if (!OPENSSL_tm_to_posix(to, &time_to) ||
|
||||
!OPENSSL_tm_to_posix(from, &time_from)) {
|
||||
return 0;
|
||||
}
|
||||
// Times are in range, so these calculations can not overflow.
|
||||
static_assert(SECS_PER_DAY <= INT_MAX, "seconds per day does not fit in int");
|
||||
static_assert((MAX_POSIX_TIME - MIN_POSIX_TIME) / SECS_PER_DAY <= INT_MAX,
|
||||
"range of valid POSIX times, in days, does not fit in int");
|
||||
int64_t timediff = time_to - time_from;
|
||||
int64_t daydiff = timediff / SECS_PER_DAY;
|
||||
timediff %= SECS_PER_DAY;
|
||||
if (daydiff > INT_MAX || daydiff < INT_MIN) {
|
||||
return 0;
|
||||
}
|
||||
*out_secs = (int)timediff;
|
||||
*out_days = (int)daydiff;
|
||||
return 1;
|
||||
|
||||
@@ -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;
|
||||
@@ -341,11 +345,11 @@ int BIO_set_close(BIO *bio, int close_flag) {
|
||||
return (int)BIO_ctrl(bio, BIO_CTRL_SET_CLOSE, close_flag, NULL);
|
||||
}
|
||||
|
||||
OPENSSL_EXPORT size_t BIO_number_read(const BIO *bio) {
|
||||
OPENSSL_EXPORT uint64_t BIO_number_read(const BIO *bio) {
|
||||
return bio->num_read;
|
||||
}
|
||||
|
||||
OPENSSL_EXPORT size_t BIO_number_written(const BIO *bio) {
|
||||
OPENSSL_EXPORT uint64_t BIO_number_written(const BIO *bio) {
|
||||
return bio->num_write;
|
||||
}
|
||||
|
||||
@@ -640,11 +644,10 @@ int BIO_get_new_index(void) {
|
||||
}
|
||||
|
||||
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,18 @@ 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) {
|
||||
return CRYPTO_get_ex_new_index_ex(&g_ex_data_class, argl, argp, free_func);
|
||||
}
|
||||
|
||||
int BIO_set_ex_data(BIO *bio, int idx, void *data) {
|
||||
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);
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -73,6 +73,7 @@
|
||||
|
||||
#include <CCryptoBoringSSL_bio.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
@@ -82,6 +83,10 @@
|
||||
|
||||
#include "../internal.h"
|
||||
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
#endif
|
||||
|
||||
#define BIO_FP_READ 0x02
|
||||
#define BIO_FP_WRITE 0x04
|
||||
@@ -122,14 +127,13 @@ BIO *BIO_new_file(const char *filename, const char *mode) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
BIO *BIO_new_fp(FILE *stream, int close_flag) {
|
||||
BIO *BIO_new_fp(FILE *stream, int flags) {
|
||||
BIO *ret = BIO_new(BIO_s_file());
|
||||
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BIO_set_fp(ret, stream, close_flag);
|
||||
BIO_set_fp(ret, stream, flags);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -196,6 +200,17 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr) {
|
||||
break;
|
||||
case BIO_C_SET_FILE_PTR:
|
||||
file_free(b);
|
||||
static_assert((BIO_CLOSE & BIO_FP_TEXT) == 0,
|
||||
"BIO_CLOSE and BIO_FP_TEXT must not collide");
|
||||
#if defined(OPENSSL_WINDOWS)
|
||||
// If |BIO_FP_TEXT| is not set, OpenSSL will switch the file to binary
|
||||
// mode. BoringSSL intentionally diverges here because it means code
|
||||
// tested under POSIX will inadvertently change the state of |FILE|
|
||||
// objects when wrapping them in a |BIO|.
|
||||
if (num & BIO_FP_TEXT) {
|
||||
_setmode(_fileno(ptr), _O_TEXT);
|
||||
}
|
||||
#endif
|
||||
b->shutdown = (int)num & BIO_CLOSE;
|
||||
b->ptr = ptr;
|
||||
b->init = 1;
|
||||
@@ -206,16 +221,16 @@ static long file_ctrl(BIO *b, int cmd, long num, void *ptr) {
|
||||
const char *mode;
|
||||
if (num & BIO_FP_APPEND) {
|
||||
if (num & BIO_FP_READ) {
|
||||
mode = "a+";
|
||||
mode = "ab+";
|
||||
} else {
|
||||
mode = "a";
|
||||
mode = "ab";
|
||||
}
|
||||
} else if ((num & BIO_FP_READ) && (num & BIO_FP_WRITE)) {
|
||||
mode = "r+";
|
||||
mode = "rb+";
|
||||
} else if (num & BIO_FP_WRITE) {
|
||||
mode = "w";
|
||||
mode = "wb";
|
||||
} else if (num & BIO_FP_READ) {
|
||||
mode = "r";
|
||||
mode = "rb";
|
||||
} else {
|
||||
OPENSSL_PUT_ERROR(BIO, BIO_R_BAD_FOPEN_MODE);
|
||||
ret = 0;
|
||||
@@ -287,8 +302,8 @@ int BIO_get_fp(BIO *bio, FILE **out_file) {
|
||||
return (int)BIO_ctrl(bio, BIO_C_GET_FILE_PTR, 0, (char *)out_file);
|
||||
}
|
||||
|
||||
int BIO_set_fp(BIO *bio, FILE *file, int close_flag) {
|
||||
return (int)BIO_ctrl(bio, BIO_C_SET_FILE_PTR, close_flag, (char *)file);
|
||||
int BIO_set_fp(BIO *bio, FILE *file, int flags) {
|
||||
return (int)BIO_ctrl(bio, BIO_C_SET_FILE_PTR, flags, (char *)file);
|
||||
}
|
||||
|
||||
int BIO_read_filename(BIO *bio, const char *filename) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -18,13 +18,10 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
// kMaxDepth is a just a sanity limit. The code should be such that the length
|
||||
// of the input being processes always decreases. None the less, a very large
|
||||
// input could otherwise cause the stack to overflow.
|
||||
static const uint32_t kMaxDepth = 2048;
|
||||
// kMaxDepth limits the recursion depth to avoid overflowing the stack.
|
||||
static const uint32_t kMaxDepth = 128;
|
||||
|
||||
// is_string_type returns one if |tag| is a string type and zero otherwise. It
|
||||
// ignores the constructed bit.
|
||||
@@ -56,13 +53,11 @@ static int is_string_type(CBS_ASN1_TAG tag) {
|
||||
// found. The value of |orig_in| is not changed. It returns one on success (i.e.
|
||||
// |*ber_found| was set) and zero on error.
|
||||
static int cbs_find_ber(const CBS *orig_in, int *ber_found, uint32_t depth) {
|
||||
CBS in;
|
||||
|
||||
if (depth > kMaxDepth) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
CBS_init(&in, CBS_data(orig_in), CBS_len(orig_in));
|
||||
CBS in = *orig_in;
|
||||
*ber_found = 0;
|
||||
|
||||
while (CBS_len(&in) > 0) {
|
||||
@@ -87,6 +82,10 @@ static int cbs_find_ber(const CBS *orig_in, int *ber_found, uint32_t depth) {
|
||||
!cbs_find_ber(&contents, ber_found, depth + 1)) {
|
||||
return 0;
|
||||
}
|
||||
if (*ber_found) {
|
||||
// We already found BER. No need to continue parsing.
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -26,11 +26,6 @@
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
void CBS_init(CBS *cbs, const uint8_t *data, size_t len) {
|
||||
cbs->data = data;
|
||||
cbs->len = len;
|
||||
}
|
||||
|
||||
static int cbs_get(CBS *cbs, const uint8_t **p, size_t n) {
|
||||
if (cbs->len < n) {
|
||||
return 0;
|
||||
@@ -47,14 +42,6 @@ int CBS_skip(CBS *cbs, size_t len) {
|
||||
return cbs_get(cbs, &dummy, len);
|
||||
}
|
||||
|
||||
const uint8_t *CBS_data(const CBS *cbs) {
|
||||
return cbs->data;
|
||||
}
|
||||
|
||||
size_t CBS_len(const CBS *cbs) {
|
||||
return cbs->len;
|
||||
}
|
||||
|
||||
int CBS_stow(const CBS *cbs, uint8_t **out_ptr, size_t *out_len) {
|
||||
OPENSSL_free(*out_ptr);
|
||||
*out_ptr = NULL;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -31,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
|
||||
@@ -234,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)]
|
||||
@@ -261,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
|
||||
@@ -298,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
|
||||
@@ -343,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
|
||||
@@ -385,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
|
||||
@@ -416,7 +386,7 @@ Loop:
|
||||
bhi Loop_outer
|
||||
|
||||
beq Ldone
|
||||
# if __ARM_ARCH__<7
|
||||
# if __ARM_ARCH<7
|
||||
b Ltail
|
||||
|
||||
.align 4
|
||||
@@ -424,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
|
||||
@@ -800,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}
|
||||
@@ -1483,11 +1453,6 @@ 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(OPENSSL_ARM) && defined(__APPLE__)
|
||||
#endif // defined(__arm__) && defined(__APPLE__)
|
||||
|
||||
@@ -31,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
|
||||
@@ -232,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)]
|
||||
@@ -259,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
|
||||
@@ -296,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
|
||||
@@ -341,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
|
||||
@@ -383,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
|
||||
@@ -414,7 +384,7 @@ ChaCha20_ctr32:
|
||||
bhi .Loop_outer
|
||||
|
||||
beq .Ldone
|
||||
# if __ARM_ARCH__<7
|
||||
# if __ARM_ARCH<7
|
||||
b .Ltail
|
||||
|
||||
.align 4
|
||||
@@ -422,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
|
||||
@@ -798,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}
|
||||
@@ -1478,8 +1448,7 @@ 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
|
||||
.size ChaCha20_ctr32_neon,.-ChaCha20_ctr32_neon
|
||||
#endif
|
||||
#endif // !OPENSSL_NO_ASM && defined(OPENSSL_ARM) && defined(__ELF__)
|
||||
#endif // defined(__arm__) && defined(__linux__)
|
||||
|
||||
@@ -8,9 +8,6 @@
|
||||
#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
|
||||
@@ -23,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 defined(OPENSSL_HWASAN) && __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
|
||||
@@ -256,7 +239,6 @@ Loop:
|
||||
ldp x27,x28,[x29,#80]
|
||||
ldp x29,x30,[sp],#96
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
Labort:
|
||||
ret
|
||||
|
||||
.align 4
|
||||
@@ -316,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
|
||||
|
||||
@@ -8,9 +8,6 @@
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_AARCH64) && defined(__ELF__)
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
|
||||
.hidden OPENSSL_armcap_P
|
||||
|
||||
.section .rodata
|
||||
|
||||
.align 5
|
||||
@@ -23,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 defined(OPENSSL_HWASAN) && __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
|
||||
@@ -256,7 +239,6 @@ ChaCha20_ctr32:
|
||||
ldp x27,x28,[x29,#80]
|
||||
ldp x29,x30,[sp],#96
|
||||
AARCH64_VALIDATE_LINK_REGISTER
|
||||
.Labort:
|
||||
ret
|
||||
|
||||
.align 4
|
||||
@@ -314,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
|
||||
@@ -812,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:
|
||||
|
||||
@@ -7,29 +7,16 @@
|
||||
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86) && defined(__ELF__)
|
||||
.text
|
||||
.globl ChaCha20_ctr32
|
||||
.hidden ChaCha20_ctr32
|
||||
.type ChaCha20_ctr32,@function
|
||||
.globl ChaCha20_ctr32_nohw
|
||||
.hidden ChaCha20_ctr32_nohw
|
||||
.type ChaCha20_ctr32_nohw,@function
|
||||
.align 16
|
||||
ChaCha20_ctr32:
|
||||
.L_ChaCha20_ctr32_begin:
|
||||
ChaCha20_ctr32_nohw:
|
||||
.L_ChaCha20_ctr32_nohw_begin:
|
||||
pushl %ebp
|
||||
pushl %ebx
|
||||
pushl %esi
|
||||
pushl %edi
|
||||
xorl %eax,%eax
|
||||
cmpl 28(%esp),%eax
|
||||
je .L000no_data
|
||||
call .Lpic_point
|
||||
.Lpic_point:
|
||||
popl %eax
|
||||
leal OPENSSL_ia32cap_P-.Lpic_point(%eax),%ebp
|
||||
testl $16777216,(%ebp)
|
||||
jz .L001x86
|
||||
testl $512,4(%ebp)
|
||||
jz .L001x86
|
||||
jmp .Lssse3_shortcut
|
||||
.L001x86:
|
||||
movl 32(%esp),%esi
|
||||
movl 36(%esp),%edi
|
||||
subl $132,%esp
|
||||
@@ -58,13 +45,13 @@ ChaCha20_ctr32:
|
||||
movl %ebx,116(%esp)
|
||||
movl %ecx,120(%esp)
|
||||
movl %edx,124(%esp)
|
||||
jmp .L002entry
|
||||
jmp .L000entry
|
||||
.align 16
|
||||
.L003outer_loop:
|
||||
.L001outer_loop:
|
||||
movl %ebx,156(%esp)
|
||||
movl %eax,152(%esp)
|
||||
movl %ecx,160(%esp)
|
||||
.L002entry:
|
||||
.L000entry:
|
||||
movl $1634760805,%eax
|
||||
movl $857760878,4(%esp)
|
||||
movl $2036477234,8(%esp)
|
||||
@@ -92,9 +79,9 @@ ChaCha20_ctr32:
|
||||
movl %edi,60(%esp)
|
||||
movl %edx,112(%esp)
|
||||
movl $10,%ebx
|
||||
jmp .L004loop
|
||||
jmp .L002loop
|
||||
.align 16
|
||||
.L004loop:
|
||||
.L002loop:
|
||||
addl %ebp,%eax
|
||||
movl %ebx,128(%esp)
|
||||
movl %ebp,%ebx
|
||||
@@ -248,14 +235,14 @@ ChaCha20_ctr32:
|
||||
xorl %esi,%ebp
|
||||
roll $7,%ebp
|
||||
decl %ebx
|
||||
jnz .L004loop
|
||||
jnz .L002loop
|
||||
movl 160(%esp),%ebx
|
||||
addl $1634760805,%eax
|
||||
addl 80(%esp),%ebp
|
||||
addl 96(%esp),%ecx
|
||||
addl 100(%esp),%esi
|
||||
cmpl $64,%ebx
|
||||
jb .L005tail
|
||||
jb .L003tail
|
||||
movl 156(%esp),%ebx
|
||||
addl 112(%esp),%edx
|
||||
addl 120(%esp),%edi
|
||||
@@ -318,9 +305,9 @@ ChaCha20_ctr32:
|
||||
movl %ebp,(%eax)
|
||||
leal 64(%eax),%eax
|
||||
subl $64,%ecx
|
||||
jnz .L003outer_loop
|
||||
jmp .L006done
|
||||
.L005tail:
|
||||
jnz .L001outer_loop
|
||||
jmp .L004done
|
||||
.L003tail:
|
||||
addl 112(%esp),%edx
|
||||
addl 120(%esp),%edi
|
||||
movl %eax,(%esp)
|
||||
@@ -364,34 +351,35 @@ ChaCha20_ctr32:
|
||||
movl %edi,60(%esp)
|
||||
xorl %eax,%eax
|
||||
xorl %edx,%edx
|
||||
.L007tail_loop:
|
||||
.L005tail_loop:
|
||||
movb (%esi,%ebp,1),%al
|
||||
movb (%esp,%esi,1),%dl
|
||||
leal 1(%esi),%esi
|
||||
xorb %dl,%al
|
||||
movb %al,-1(%ecx,%esi,1)
|
||||
decl %ebx
|
||||
jnz .L007tail_loop
|
||||
.L006done:
|
||||
jnz .L005tail_loop
|
||||
.L004done:
|
||||
addl $132,%esp
|
||||
.L000no_data:
|
||||
popl %edi
|
||||
popl %esi
|
||||
popl %ebx
|
||||
popl %ebp
|
||||
ret
|
||||
.size ChaCha20_ctr32,.-.L_ChaCha20_ctr32_begin
|
||||
.globl ChaCha20_ssse3
|
||||
.hidden ChaCha20_ssse3
|
||||
.type ChaCha20_ssse3,@function
|
||||
.size ChaCha20_ctr32_nohw,.-.L_ChaCha20_ctr32_nohw_begin
|
||||
.globl ChaCha20_ctr32_ssse3
|
||||
.hidden ChaCha20_ctr32_ssse3
|
||||
.type ChaCha20_ctr32_ssse3,@function
|
||||
.align 16
|
||||
ChaCha20_ssse3:
|
||||
.L_ChaCha20_ssse3_begin:
|
||||
ChaCha20_ctr32_ssse3:
|
||||
.L_ChaCha20_ctr32_ssse3_begin:
|
||||
pushl %ebp
|
||||
pushl %ebx
|
||||
pushl %esi
|
||||
pushl %edi
|
||||
.Lssse3_shortcut:
|
||||
call .Lpic_point
|
||||
.Lpic_point:
|
||||
popl %eax
|
||||
movl 20(%esp),%edi
|
||||
movl 24(%esp),%esi
|
||||
movl 28(%esp),%ecx
|
||||
@@ -404,7 +392,7 @@ ChaCha20_ssse3:
|
||||
leal .Lssse3_data-.Lpic_point(%eax),%eax
|
||||
movdqu (%ebx),%xmm3
|
||||
cmpl $256,%ecx
|
||||
jb .L0081x
|
||||
jb .L0061x
|
||||
movl %edx,516(%esp)
|
||||
movl %ebx,520(%esp)
|
||||
subl $256,%ecx
|
||||
@@ -449,9 +437,9 @@ ChaCha20_ssse3:
|
||||
movdqa %xmm7,-80(%ebp)
|
||||
leal 128(%esi),%esi
|
||||
leal 128(%edi),%edi
|
||||
jmp .L009outer_loop
|
||||
jmp .L007outer_loop
|
||||
.align 16
|
||||
.L009outer_loop:
|
||||
.L007outer_loop:
|
||||
movdqa -112(%ebp),%xmm1
|
||||
movdqa -96(%ebp),%xmm2
|
||||
movdqa -80(%ebp),%xmm3
|
||||
@@ -486,7 +474,7 @@ ChaCha20_ssse3:
|
||||
movl $10,%edx
|
||||
nop
|
||||
.align 16
|
||||
.L010loop:
|
||||
.L008loop:
|
||||
paddd %xmm3,%xmm0
|
||||
movdqa %xmm3,%xmm2
|
||||
pxor %xmm0,%xmm6
|
||||
@@ -686,7 +674,7 @@ ChaCha20_ssse3:
|
||||
psrld $25,%xmm1
|
||||
por %xmm1,%xmm3
|
||||
decl %edx
|
||||
jnz .L010loop
|
||||
jnz .L008loop
|
||||
movdqa %xmm3,-64(%ebx)
|
||||
movdqa %xmm4,(%ebx)
|
||||
movdqa %xmm5,16(%ebx)
|
||||
@@ -828,9 +816,9 @@ ChaCha20_ssse3:
|
||||
movdqu %xmm7,64(%edi)
|
||||
leal 208(%edi),%edi
|
||||
subl $256,%ecx
|
||||
jnc .L009outer_loop
|
||||
jnc .L007outer_loop
|
||||
addl $256,%ecx
|
||||
jz .L011done
|
||||
jz .L009done
|
||||
movl 520(%esp),%ebx
|
||||
leal -128(%esi),%esi
|
||||
movl 516(%esp),%edx
|
||||
@@ -840,7 +828,7 @@ ChaCha20_ssse3:
|
||||
paddd 96(%eax),%xmm2
|
||||
pand 112(%eax),%xmm3
|
||||
por %xmm2,%xmm3
|
||||
.L0081x:
|
||||
.L0061x:
|
||||
movdqa 32(%eax),%xmm0
|
||||
movdqu (%edx),%xmm1
|
||||
movdqu 16(%edx),%xmm2
|
||||
@@ -852,9 +840,9 @@ ChaCha20_ssse3:
|
||||
movdqa %xmm2,32(%esp)
|
||||
movdqa %xmm3,48(%esp)
|
||||
movl $10,%edx
|
||||
jmp .L012loop1x
|
||||
jmp .L010loop1x
|
||||
.align 16
|
||||
.L013outer1x:
|
||||
.L011outer1x:
|
||||
movdqa 80(%eax),%xmm3
|
||||
movdqa (%esp),%xmm0
|
||||
movdqa 16(%esp),%xmm1
|
||||
@@ -862,9 +850,9 @@ ChaCha20_ssse3:
|
||||
paddd 48(%esp),%xmm3
|
||||
movl $10,%edx
|
||||
movdqa %xmm3,48(%esp)
|
||||
jmp .L012loop1x
|
||||
jmp .L010loop1x
|
||||
.align 16
|
||||
.L012loop1x:
|
||||
.L010loop1x:
|
||||
paddd %xmm1,%xmm0
|
||||
pxor %xmm0,%xmm3
|
||||
.byte 102,15,56,0,222
|
||||
@@ -909,13 +897,13 @@ ChaCha20_ssse3:
|
||||
pshufd $147,%xmm1,%xmm1
|
||||
pshufd $57,%xmm3,%xmm3
|
||||
decl %edx
|
||||
jnz .L012loop1x
|
||||
jnz .L010loop1x
|
||||
paddd (%esp),%xmm0
|
||||
paddd 16(%esp),%xmm1
|
||||
paddd 32(%esp),%xmm2
|
||||
paddd 48(%esp),%xmm3
|
||||
cmpl $64,%ecx
|
||||
jb .L014tail
|
||||
jb .L012tail
|
||||
movdqu (%esi),%xmm4
|
||||
movdqu 16(%esi),%xmm5
|
||||
pxor %xmm4,%xmm0
|
||||
@@ -931,9 +919,9 @@ ChaCha20_ssse3:
|
||||
movdqu %xmm3,48(%edi)
|
||||
leal 64(%edi),%edi
|
||||
subl $64,%ecx
|
||||
jnz .L013outer1x
|
||||
jmp .L011done
|
||||
.L014tail:
|
||||
jnz .L011outer1x
|
||||
jmp .L009done
|
||||
.L012tail:
|
||||
movdqa %xmm0,(%esp)
|
||||
movdqa %xmm1,16(%esp)
|
||||
movdqa %xmm2,32(%esp)
|
||||
@@ -941,22 +929,22 @@ ChaCha20_ssse3:
|
||||
xorl %eax,%eax
|
||||
xorl %edx,%edx
|
||||
xorl %ebp,%ebp
|
||||
.L015tail_loop:
|
||||
.L013tail_loop:
|
||||
movb (%esp,%ebp,1),%al
|
||||
movb (%esi,%ebp,1),%dl
|
||||
leal 1(%ebp),%ebp
|
||||
xorb %dl,%al
|
||||
movb %al,-1(%edi,%ebp,1)
|
||||
decl %ecx
|
||||
jnz .L015tail_loop
|
||||
.L011done:
|
||||
jnz .L013tail_loop
|
||||
.L009done:
|
||||
movl 512(%esp),%esp
|
||||
popl %edi
|
||||
popl %esi
|
||||
popl %ebx
|
||||
popl %ebp
|
||||
ret
|
||||
.size ChaCha20_ssse3,.-.L_ChaCha20_ssse3_begin
|
||||
.size ChaCha20_ctr32_ssse3,.-.L_ChaCha20_ctr32_ssse3_begin
|
||||
.align 64
|
||||
.Lssse3_data:
|
||||
.byte 2,3,0,1,6,7,4,5,10,11,8,9,14,15,12,13
|
||||
|
||||
@@ -15,27 +15,14 @@ section .text code align=64
|
||||
%else
|
||||
section .text code
|
||||
%endif
|
||||
global _ChaCha20_ctr32
|
||||
global _ChaCha20_ctr32_nohw
|
||||
align 16
|
||||
_ChaCha20_ctr32:
|
||||
L$_ChaCha20_ctr32_begin:
|
||||
_ChaCha20_ctr32_nohw:
|
||||
L$_ChaCha20_ctr32_nohw_begin:
|
||||
push ebp
|
||||
push ebx
|
||||
push esi
|
||||
push edi
|
||||
xor eax,eax
|
||||
cmp eax,DWORD [28+esp]
|
||||
je NEAR L$000no_data
|
||||
call L$pic_point
|
||||
L$pic_point:
|
||||
pop eax
|
||||
lea ebp,[_OPENSSL_ia32cap_P]
|
||||
test DWORD [ebp],16777216
|
||||
jz NEAR L$001x86
|
||||
test DWORD [4+ebp],512
|
||||
jz NEAR L$001x86
|
||||
jmp NEAR L$ssse3_shortcut
|
||||
L$001x86:
|
||||
mov esi,DWORD [32+esp]
|
||||
mov edi,DWORD [36+esp]
|
||||
sub esp,132
|
||||
@@ -64,13 +51,13 @@ L$001x86:
|
||||
mov DWORD [116+esp],ebx
|
||||
mov DWORD [120+esp],ecx
|
||||
mov DWORD [124+esp],edx
|
||||
jmp NEAR L$002entry
|
||||
jmp NEAR L$000entry
|
||||
align 16
|
||||
L$003outer_loop:
|
||||
L$001outer_loop:
|
||||
mov DWORD [156+esp],ebx
|
||||
mov DWORD [152+esp],eax
|
||||
mov DWORD [160+esp],ecx
|
||||
L$002entry:
|
||||
L$000entry:
|
||||
mov eax,1634760805
|
||||
mov DWORD [4+esp],857760878
|
||||
mov DWORD [8+esp],2036477234
|
||||
@@ -98,9 +85,9 @@ L$002entry:
|
||||
mov DWORD [60+esp],edi
|
||||
mov DWORD [112+esp],edx
|
||||
mov ebx,10
|
||||
jmp NEAR L$004loop
|
||||
jmp NEAR L$002loop
|
||||
align 16
|
||||
L$004loop:
|
||||
L$002loop:
|
||||
add eax,ebp
|
||||
mov DWORD [128+esp],ebx
|
||||
mov ebx,ebp
|
||||
@@ -254,14 +241,14 @@ L$004loop:
|
||||
xor ebp,esi
|
||||
rol ebp,7
|
||||
dec ebx
|
||||
jnz NEAR L$004loop
|
||||
jnz NEAR L$002loop
|
||||
mov ebx,DWORD [160+esp]
|
||||
add eax,1634760805
|
||||
add ebp,DWORD [80+esp]
|
||||
add ecx,DWORD [96+esp]
|
||||
add esi,DWORD [100+esp]
|
||||
cmp ebx,64
|
||||
jb NEAR L$005tail
|
||||
jb NEAR L$003tail
|
||||
mov ebx,DWORD [156+esp]
|
||||
add edx,DWORD [112+esp]
|
||||
add edi,DWORD [120+esp]
|
||||
@@ -324,9 +311,9 @@ L$004loop:
|
||||
mov DWORD [eax],ebp
|
||||
lea eax,[64+eax]
|
||||
sub ecx,64
|
||||
jnz NEAR L$003outer_loop
|
||||
jmp NEAR L$006done
|
||||
L$005tail:
|
||||
jnz NEAR L$001outer_loop
|
||||
jmp NEAR L$004done
|
||||
L$003tail:
|
||||
add edx,DWORD [112+esp]
|
||||
add edi,DWORD [120+esp]
|
||||
mov DWORD [esp],eax
|
||||
@@ -370,31 +357,32 @@ L$005tail:
|
||||
mov DWORD [60+esp],edi
|
||||
xor eax,eax
|
||||
xor edx,edx
|
||||
L$007tail_loop:
|
||||
L$005tail_loop:
|
||||
mov al,BYTE [ebp*1+esi]
|
||||
mov dl,BYTE [esi*1+esp]
|
||||
lea esi,[1+esi]
|
||||
xor al,dl
|
||||
mov BYTE [esi*1+ecx-1],al
|
||||
dec ebx
|
||||
jnz NEAR L$007tail_loop
|
||||
L$006done:
|
||||
jnz NEAR L$005tail_loop
|
||||
L$004done:
|
||||
add esp,132
|
||||
L$000no_data:
|
||||
pop edi
|
||||
pop esi
|
||||
pop ebx
|
||||
pop ebp
|
||||
ret
|
||||
global _ChaCha20_ssse3
|
||||
global _ChaCha20_ctr32_ssse3
|
||||
align 16
|
||||
_ChaCha20_ssse3:
|
||||
L$_ChaCha20_ssse3_begin:
|
||||
_ChaCha20_ctr32_ssse3:
|
||||
L$_ChaCha20_ctr32_ssse3_begin:
|
||||
push ebp
|
||||
push ebx
|
||||
push esi
|
||||
push edi
|
||||
L$ssse3_shortcut:
|
||||
call L$pic_point
|
||||
L$pic_point:
|
||||
pop eax
|
||||
mov edi,DWORD [20+esp]
|
||||
mov esi,DWORD [24+esp]
|
||||
mov ecx,DWORD [28+esp]
|
||||
@@ -407,7 +395,7 @@ L$ssse3_shortcut:
|
||||
lea eax,[(L$ssse3_data-L$pic_point)+eax]
|
||||
movdqu xmm3,[ebx]
|
||||
cmp ecx,256
|
||||
jb NEAR L$0081x
|
||||
jb NEAR L$0061x
|
||||
mov DWORD [516+esp],edx
|
||||
mov DWORD [520+esp],ebx
|
||||
sub ecx,256
|
||||
@@ -452,9 +440,9 @@ L$ssse3_shortcut:
|
||||
movdqa [ebp-80],xmm7
|
||||
lea esi,[128+esi]
|
||||
lea edi,[128+edi]
|
||||
jmp NEAR L$009outer_loop
|
||||
jmp NEAR L$007outer_loop
|
||||
align 16
|
||||
L$009outer_loop:
|
||||
L$007outer_loop:
|
||||
movdqa xmm1,[ebp-112]
|
||||
movdqa xmm2,[ebp-96]
|
||||
movdqa xmm3,[ebp-80]
|
||||
@@ -489,7 +477,7 @@ L$009outer_loop:
|
||||
mov edx,10
|
||||
nop
|
||||
align 16
|
||||
L$010loop:
|
||||
L$008loop:
|
||||
paddd xmm0,xmm3
|
||||
movdqa xmm2,xmm3
|
||||
pxor xmm6,xmm0
|
||||
@@ -689,7 +677,7 @@ L$010loop:
|
||||
psrld xmm1,25
|
||||
por xmm3,xmm1
|
||||
dec edx
|
||||
jnz NEAR L$010loop
|
||||
jnz NEAR L$008loop
|
||||
movdqa [ebx-64],xmm3
|
||||
movdqa [ebx],xmm4
|
||||
movdqa [16+ebx],xmm5
|
||||
@@ -831,9 +819,9 @@ L$010loop:
|
||||
movdqu [64+edi],xmm7
|
||||
lea edi,[208+edi]
|
||||
sub ecx,256
|
||||
jnc NEAR L$009outer_loop
|
||||
jnc NEAR L$007outer_loop
|
||||
add ecx,256
|
||||
jz NEAR L$011done
|
||||
jz NEAR L$009done
|
||||
mov ebx,DWORD [520+esp]
|
||||
lea esi,[esi-128]
|
||||
mov edx,DWORD [516+esp]
|
||||
@@ -843,7 +831,7 @@ L$010loop:
|
||||
paddd xmm2,[96+eax]
|
||||
pand xmm3,[112+eax]
|
||||
por xmm3,xmm2
|
||||
L$0081x:
|
||||
L$0061x:
|
||||
movdqa xmm0,[32+eax]
|
||||
movdqu xmm1,[edx]
|
||||
movdqu xmm2,[16+edx]
|
||||
@@ -855,9 +843,9 @@ L$0081x:
|
||||
movdqa [32+esp],xmm2
|
||||
movdqa [48+esp],xmm3
|
||||
mov edx,10
|
||||
jmp NEAR L$012loop1x
|
||||
jmp NEAR L$010loop1x
|
||||
align 16
|
||||
L$013outer1x:
|
||||
L$011outer1x:
|
||||
movdqa xmm3,[80+eax]
|
||||
movdqa xmm0,[esp]
|
||||
movdqa xmm1,[16+esp]
|
||||
@@ -865,9 +853,9 @@ L$013outer1x:
|
||||
paddd xmm3,[48+esp]
|
||||
mov edx,10
|
||||
movdqa [48+esp],xmm3
|
||||
jmp NEAR L$012loop1x
|
||||
jmp NEAR L$010loop1x
|
||||
align 16
|
||||
L$012loop1x:
|
||||
L$010loop1x:
|
||||
paddd xmm0,xmm1
|
||||
pxor xmm3,xmm0
|
||||
db 102,15,56,0,222
|
||||
@@ -912,13 +900,13 @@ db 102,15,56,0,223
|
||||
pshufd xmm1,xmm1,147
|
||||
pshufd xmm3,xmm3,57
|
||||
dec edx
|
||||
jnz NEAR L$012loop1x
|
||||
jnz NEAR L$010loop1x
|
||||
paddd xmm0,[esp]
|
||||
paddd xmm1,[16+esp]
|
||||
paddd xmm2,[32+esp]
|
||||
paddd xmm3,[48+esp]
|
||||
cmp ecx,64
|
||||
jb NEAR L$014tail
|
||||
jb NEAR L$012tail
|
||||
movdqu xmm4,[esi]
|
||||
movdqu xmm5,[16+esi]
|
||||
pxor xmm0,xmm4
|
||||
@@ -934,9 +922,9 @@ db 102,15,56,0,223
|
||||
movdqu [48+edi],xmm3
|
||||
lea edi,[64+edi]
|
||||
sub ecx,64
|
||||
jnz NEAR L$013outer1x
|
||||
jmp NEAR L$011done
|
||||
L$014tail:
|
||||
jnz NEAR L$011outer1x
|
||||
jmp NEAR L$009done
|
||||
L$012tail:
|
||||
movdqa [esp],xmm0
|
||||
movdqa [16+esp],xmm1
|
||||
movdqa [32+esp],xmm2
|
||||
@@ -944,15 +932,15 @@ L$014tail:
|
||||
xor eax,eax
|
||||
xor edx,edx
|
||||
xor ebp,ebp
|
||||
L$015tail_loop:
|
||||
L$013tail_loop:
|
||||
mov al,BYTE [ebp*1+esp]
|
||||
mov dl,BYTE [ebp*1+esi]
|
||||
lea ebp,[1+ebp]
|
||||
xor al,dl
|
||||
mov BYTE [ebp*1+edi-1],al
|
||||
dec ecx
|
||||
jnz NEAR L$015tail_loop
|
||||
L$011done:
|
||||
jnz NEAR L$013tail_loop
|
||||
L$009done:
|
||||
mov esp,DWORD [512+esp]
|
||||
pop edi
|
||||
pop esi
|
||||
@@ -974,8 +962,6 @@ db 67,104,97,67,104,97,50,48,32,102,111,114,32,120,56,54
|
||||
db 44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32
|
||||
db 60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111
|
||||
db 114,103,62,0
|
||||
segment .bss
|
||||
common _OPENSSL_ia32cap_P 16
|
||||
%else
|
||||
; Work around https://bugzilla.nasm.us/show_bug.cgi?id=3392738
|
||||
ret
|
||||
|
||||
@@ -8,9 +8,6 @@
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64) && defined(__ELF__)
|
||||
.text
|
||||
|
||||
.extern OPENSSL_ia32cap_P
|
||||
.hidden OPENSSL_ia32cap_P
|
||||
|
||||
.section .rodata
|
||||
.align 64
|
||||
.Lzero:
|
||||
@@ -42,19 +39,13 @@
|
||||
.long 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16
|
||||
.byte 67,104,97,67,104,97,50,48,32,102,111,114,32,120,56,54,95,54,52,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0
|
||||
.text
|
||||
.globl ChaCha20_ctr32
|
||||
.hidden ChaCha20_ctr32
|
||||
.type ChaCha20_ctr32,@function
|
||||
.globl ChaCha20_ctr32_nohw
|
||||
.hidden ChaCha20_ctr32_nohw
|
||||
.type ChaCha20_ctr32_nohw,@function
|
||||
.align 64
|
||||
ChaCha20_ctr32:
|
||||
ChaCha20_ctr32_nohw:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
cmpq $0,%rdx
|
||||
je .Lno_data
|
||||
movq OPENSSL_ia32cap_P+4(%rip),%r10
|
||||
testl $512,%r10d
|
||||
jnz .LChaCha20_ssse3
|
||||
|
||||
pushq %rbx
|
||||
.cfi_adjust_cfa_offset 8
|
||||
.cfi_offset rbx,-16
|
||||
@@ -329,20 +320,18 @@ _CET_ENDBR
|
||||
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
|
||||
.size ChaCha20_ctr32_nohw,.-ChaCha20_ctr32_nohw
|
||||
.globl ChaCha20_ctr32_ssse3
|
||||
.hidden ChaCha20_ctr32_ssse3
|
||||
.type ChaCha20_ctr32_ssse3,@function
|
||||
.align 32
|
||||
ChaCha20_ssse3:
|
||||
.LChaCha20_ssse3:
|
||||
ChaCha20_ctr32_ssse3:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
movq %rsp,%r9
|
||||
.cfi_def_cfa_register r9
|
||||
cmpq $128,%rdx
|
||||
ja .LChaCha20_4x
|
||||
|
||||
.Ldo_sse3_after_all:
|
||||
subq $64+8,%rsp
|
||||
movdqa .Lsigma(%rip),%xmm0
|
||||
movdqu (%rcx),%xmm1
|
||||
@@ -466,28 +455,19 @@ 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
|
||||
.size ChaCha20_ctr32_ssse3,.-ChaCha20_ctr32_ssse3
|
||||
.globl ChaCha20_ctr32_ssse3_4x
|
||||
.hidden ChaCha20_ctr32_ssse3_4x
|
||||
.type ChaCha20_ctr32_ssse3_4x,@function
|
||||
.align 32
|
||||
ChaCha20_4x:
|
||||
.LChaCha20_4x:
|
||||
ChaCha20_ctr32_ssse3_4x:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
movq %rsp,%r9
|
||||
.cfi_def_cfa_register r9
|
||||
movq %r10,%r11
|
||||
shrq $32,%r10
|
||||
testq $32,%r10
|
||||
jnz .LChaCha20_8x
|
||||
cmpq $192,%rdx
|
||||
ja .Lproceed4x
|
||||
|
||||
andq $71303168,%r11
|
||||
cmpq $4194304,%r11
|
||||
je .Ldo_sse3_after_all
|
||||
|
||||
.Lproceed4x:
|
||||
subq $0x140+8,%rsp
|
||||
movdqa .Lsigma(%rip),%xmm11
|
||||
movdqu (%rcx),%xmm15
|
||||
@@ -1018,14 +998,16 @@ 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
|
||||
.size ChaCha20_ctr32_ssse3_4x,.-ChaCha20_ctr32_ssse3_4x
|
||||
.globl ChaCha20_ctr32_avx2
|
||||
.hidden ChaCha20_ctr32_avx2
|
||||
.type ChaCha20_ctr32_avx2,@function
|
||||
.align 32
|
||||
ChaCha20_8x:
|
||||
.LChaCha20_8x:
|
||||
ChaCha20_ctr32_avx2:
|
||||
.cfi_startproc
|
||||
_CET_ENDBR
|
||||
movq %rsp,%r9
|
||||
.cfi_def_cfa_register r9
|
||||
subq $0x280+8,%rsp
|
||||
@@ -1624,9 +1606,9 @@ ChaCha20_8x:
|
||||
leaq (%r9),%rsp
|
||||
.cfi_def_cfa_register rsp
|
||||
.L8x_epilogue:
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size ChaCha20_8x,.-ChaCha20_8x
|
||||
.size ChaCha20_ctr32_avx2,.-ChaCha20_ctr32_avx2
|
||||
#endif
|
||||
#endif // defined(__x86_64__) && defined(__linux__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64) && defined(__APPLE__)
|
||||
.text
|
||||
|
||||
|
||||
|
||||
.section __DATA,__const
|
||||
.p2align 6
|
||||
L$zero:
|
||||
@@ -41,19 +39,13 @@ L$sixteen:
|
||||
.long 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16
|
||||
.byte 67,104,97,67,104,97,50,48,32,102,111,114,32,120,56,54,95,54,52,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0
|
||||
.text
|
||||
.globl _ChaCha20_ctr32
|
||||
.private_extern _ChaCha20_ctr32
|
||||
.globl _ChaCha20_ctr32_nohw
|
||||
.private_extern _ChaCha20_ctr32_nohw
|
||||
|
||||
.p2align 6
|
||||
_ChaCha20_ctr32:
|
||||
_ChaCha20_ctr32_nohw:
|
||||
|
||||
_CET_ENDBR
|
||||
cmpq $0,%rdx
|
||||
je L$no_data
|
||||
movq _OPENSSL_ia32cap_P+4(%rip),%r10
|
||||
testl $512,%r10d
|
||||
jnz L$ChaCha20_ssse3
|
||||
|
||||
pushq %rbx
|
||||
|
||||
pushq %rbp
|
||||
@@ -322,20 +314,18 @@ L$done:
|
||||
leaq (%rsi),%rsp
|
||||
|
||||
L$no_data:
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _ChaCha20_ctr32_ssse3
|
||||
.private_extern _ChaCha20_ctr32_ssse3
|
||||
|
||||
.p2align 5
|
||||
ChaCha20_ssse3:
|
||||
L$ChaCha20_ssse3:
|
||||
_ChaCha20_ctr32_ssse3:
|
||||
|
||||
_CET_ENDBR
|
||||
movq %rsp,%r9
|
||||
|
||||
cmpq $128,%rdx
|
||||
ja L$ChaCha20_4x
|
||||
|
||||
L$do_sse3_after_all:
|
||||
subq $64+8,%rsp
|
||||
movdqa L$sigma(%rip),%xmm0
|
||||
movdqu (%rcx),%xmm1
|
||||
@@ -459,28 +449,19 @@ L$done_ssse3:
|
||||
leaq (%r9),%rsp
|
||||
|
||||
L$ssse3_epilogue:
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _ChaCha20_ctr32_ssse3_4x
|
||||
.private_extern _ChaCha20_ctr32_ssse3_4x
|
||||
|
||||
.p2align 5
|
||||
ChaCha20_4x:
|
||||
L$ChaCha20_4x:
|
||||
_ChaCha20_ctr32_ssse3_4x:
|
||||
|
||||
_CET_ENDBR
|
||||
movq %rsp,%r9
|
||||
|
||||
movq %r10,%r11
|
||||
shrq $32,%r10
|
||||
testq $32,%r10
|
||||
jnz L$ChaCha20_8x
|
||||
cmpq $192,%rdx
|
||||
ja L$proceed4x
|
||||
|
||||
andq $71303168,%r11
|
||||
cmpq $4194304,%r11
|
||||
je L$do_sse3_after_all
|
||||
|
||||
L$proceed4x:
|
||||
subq $0x140+8,%rsp
|
||||
movdqa L$sigma(%rip),%xmm11
|
||||
movdqu (%rcx),%xmm15
|
||||
@@ -1011,14 +992,16 @@ L$done4x:
|
||||
leaq (%r9),%rsp
|
||||
|
||||
L$4x_epilogue:
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _ChaCha20_ctr32_avx2
|
||||
.private_extern _ChaCha20_ctr32_avx2
|
||||
|
||||
.p2align 5
|
||||
ChaCha20_8x:
|
||||
L$ChaCha20_8x:
|
||||
_ChaCha20_ctr32_avx2:
|
||||
|
||||
_CET_ENDBR
|
||||
movq %rsp,%r9
|
||||
|
||||
subq $0x280+8,%rsp
|
||||
@@ -1617,7 +1600,7 @@ L$done8x:
|
||||
leaq (%r9),%rsp
|
||||
|
||||
L$8x_epilogue:
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -60,7 +60,40 @@ 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 defined(CHACHA20_ASM_AVX2)
|
||||
if (ChaCha20_ctr32_avx2_capable(in_len)) {
|
||||
ChaCha20_ctr32_avx2(out, in, in_len, key, counter);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#if defined(CHACHA20_ASM_SSSE3_4X)
|
||||
if (ChaCha20_ctr32_ssse3_4x_capable(in_len)) {
|
||||
ChaCha20_ctr32_ssse3_4x(out, in, in_len, key, counter);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
#if defined(CHACHA20_ASM_SSSE3)
|
||||
if (ChaCha20_ctr32_ssse3_capable(in_len)) {
|
||||
ChaCha20_ctr32_ssse3(out, in, in_len, key, counter);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
if (in_len > 0) {
|
||||
ChaCha20_ctr32_nohw(out, in, in_len, key, counter);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(CHACHA20_ASM_NOHW)
|
||||
|
||||
void CRYPTO_chacha_20(uint8_t *out, const uint8_t *in, size_t in_len,
|
||||
const uint8_t key[32], const uint8_t nonce[12],
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
|
||||
#include <CCryptoBoringSSL_base.h>
|
||||
|
||||
#include "../internal.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -27,21 +29,69 @@ 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))
|
||||
#define CHACHA20_ASM
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86)
|
||||
|
||||
// ChaCha20_ctr32 encrypts |in_len| bytes from |in| and writes the result to
|
||||
// |out|. If |in| and |out| alias, they must be equal.
|
||||
#define CHACHA20_ASM_NOHW
|
||||
|
||||
#define CHACHA20_ASM_SSSE3
|
||||
OPENSSL_INLINE int ChaCha20_ctr32_ssse3_capable(size_t len) {
|
||||
// Unlike the x86_64 version, the x86 SSSE3 routine runs for all non-zero
|
||||
// lengths.
|
||||
return len > 0 && CRYPTO_is_SSSE3_capable() && CRYPTO_is_FXSR_capable();
|
||||
}
|
||||
void ChaCha20_ctr32_ssse3(uint8_t *out, const uint8_t *in, size_t in_len,
|
||||
const uint32_t key[8], const uint32_t counter[4]);
|
||||
|
||||
#elif !defined(OPENSSL_NO_ASM) && \
|
||||
(defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64))
|
||||
|
||||
#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]);
|
||||
#elif !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64)
|
||||
#define CHACHA20_ASM_NOHW
|
||||
|
||||
#define CHACHA20_ASM_AVX2
|
||||
OPENSSL_INLINE int ChaCha20_ctr32_avx2_capable(size_t len) {
|
||||
return len > 128 && CRYPTO_is_AVX2_capable();
|
||||
}
|
||||
void ChaCha20_ctr32_avx2(uint8_t *out, const uint8_t *in, size_t in_len,
|
||||
const uint32_t key[8], const uint32_t counter[4]);
|
||||
|
||||
#define CHACHA20_ASM_SSSE3_4X
|
||||
OPENSSL_INLINE int ChaCha20_ctr32_ssse3_4x_capable(size_t len) {
|
||||
int capable = len > 128 && CRYPTO_is_SSSE3_capable();
|
||||
int faster = len > 192 || !CRYPTO_cpu_perf_is_like_silvermont();
|
||||
return capable && faster;
|
||||
}
|
||||
void ChaCha20_ctr32_ssse3_4x(uint8_t *out, const uint8_t *in, size_t in_len,
|
||||
const uint32_t key[8], const uint32_t counter[4]);
|
||||
|
||||
#define CHACHA20_ASM_SSSE3
|
||||
OPENSSL_INLINE int ChaCha20_ctr32_ssse3_capable(size_t len) {
|
||||
return len > 128 && CRYPTO_is_SSSE3_capable();
|
||||
}
|
||||
void ChaCha20_ctr32_ssse3(uint8_t *out, const uint8_t *in, size_t in_len,
|
||||
const uint32_t key[8], const uint32_t counter[4]);
|
||||
#endif
|
||||
|
||||
#if defined(CHACHA20_ASM_NOHW)
|
||||
// ChaCha20_ctr32_nohw encrypts |in_len| bytes from |in| and writes the result
|
||||
// to |out|. If |in| and |out| alias, they must be equal. |in_len| may not be
|
||||
// zero.
|
||||
//
|
||||
// |counter[0]| is the initial 32-bit block counter, and the remainder is the
|
||||
// 96-bit nonce. If the counter overflows, the output is undefined. The function
|
||||
// will produce output, but the output may vary by machine and may not be
|
||||
// self-consistent. (On some architectures, the assembly implements a mix of
|
||||
// 64-bit and 32-bit counters.)
|
||||
void ChaCha20_ctr32(uint8_t *out, const uint8_t *in, size_t in_len,
|
||||
const uint32_t key[8], const uint32_t counter[4]);
|
||||
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
|
||||
|
||||
|
||||
|
||||
+35
-33
@@ -64,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
|
||||
@@ -91,7 +91,7 @@ _CET_ENDBR
|
||||
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
|
||||
@@ -114,7 +114,7 @@ _CET_ENDBR
|
||||
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
|
||||
@@ -126,7 +126,7 @@ aesgcmsiv_htable_polyval:
|
||||
_CET_ENDBR
|
||||
testq %rdx,%rdx
|
||||
jnz .Lhtable_polyval_start
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
.Lhtable_polyval_start:
|
||||
vzeroall
|
||||
@@ -332,7 +332,7 @@ _CET_ENDBR
|
||||
|
||||
vmovdqu %xmm1,(%rcx)
|
||||
vzeroupper
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aesgcmsiv_htable_polyval,.-aesgcmsiv_htable_polyval
|
||||
.globl aesgcmsiv_polyval_horner
|
||||
@@ -344,7 +344,7 @@ aesgcmsiv_polyval_horner:
|
||||
_CET_ENDBR
|
||||
testq %rcx,%rcx
|
||||
jnz .Lpolyval_horner_start
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
.Lpolyval_horner_start:
|
||||
|
||||
@@ -366,7 +366,7 @@ _CET_ENDBR
|
||||
|
||||
|
||||
vmovdqa %xmm0,(%rdi)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aesgcmsiv_polyval_horner,.-aesgcmsiv_polyval_horner
|
||||
.globl aes128gcmsiv_aes_ks
|
||||
@@ -423,7 +423,7 @@ _CET_ENDBR
|
||||
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
|
||||
@@ -472,7 +472,7 @@ _CET_ENDBR
|
||||
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
|
||||
@@ -614,7 +614,7 @@ _CET_ENDBR
|
||||
|
||||
|
||||
vmovdqa %xmm4,0(%rsi)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aes128gcmsiv_aes_ks_enc_x1,.-aes128gcmsiv_aes_ks_enc_x1
|
||||
.globl aes128gcmsiv_kdf
|
||||
@@ -708,7 +708,7 @@ _CET_ENDBR
|
||||
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
|
||||
@@ -720,7 +720,7 @@ aes128gcmsiv_enc_msg_x4:
|
||||
_CET_ENDBR
|
||||
testq %r8,%r8
|
||||
jnz .L128_enc_msg_x4_start
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
.L128_enc_msg_x4_start:
|
||||
pushq %r12
|
||||
@@ -888,7 +888,7 @@ _CET_ENDBR
|
||||
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
|
||||
@@ -900,7 +900,7 @@ aes128gcmsiv_enc_msg_x8:
|
||||
_CET_ENDBR
|
||||
testq %r8,%r8
|
||||
jnz .L128_enc_msg_x8_start
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
.L128_enc_msg_x8_start:
|
||||
pushq %r12
|
||||
@@ -1150,7 +1150,7 @@ _CET_ENDBR
|
||||
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
|
||||
@@ -1162,19 +1162,20 @@ aes128gcmsiv_dec:
|
||||
_CET_ENDBR
|
||||
testq $~15,%r9
|
||||
jnz .L128_dec_start
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
.L128_dec_start:
|
||||
vzeroupper
|
||||
vmovdqa (%rdx),%xmm0
|
||||
|
||||
|
||||
vmovdqu 16(%rdx),%xmm15
|
||||
vpor OR_MASK(%rip),%xmm15,%xmm15
|
||||
movq %rdx,%rax
|
||||
|
||||
leaq 32(%rax),%rax
|
||||
leaq 32(%rcx),%rcx
|
||||
|
||||
|
||||
vmovdqu (%rdi,%r9,1),%xmm15
|
||||
vpor OR_MASK(%rip),%xmm15,%xmm15
|
||||
andq $~15,%r9
|
||||
|
||||
|
||||
@@ -1643,7 +1644,7 @@ _CET_ENDBR
|
||||
|
||||
.L128_dec_out:
|
||||
vmovdqu %xmm0,(%rdx)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aes128gcmsiv_dec, .-aes128gcmsiv_dec
|
||||
.globl aes128gcmsiv_ecb_enc_block
|
||||
@@ -1669,7 +1670,7 @@ _CET_ENDBR
|
||||
|
||||
vmovdqa %xmm1,(%rsi)
|
||||
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aes128gcmsiv_ecb_enc_block,.-aes128gcmsiv_ecb_enc_block
|
||||
.globl aes256gcmsiv_aes_ks_enc_x1
|
||||
@@ -1853,7 +1854,7 @@ _CET_ENDBR
|
||||
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
|
||||
@@ -1880,7 +1881,7 @@ _CET_ENDBR
|
||||
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
|
||||
@@ -1892,7 +1893,7 @@ aes256gcmsiv_enc_msg_x4:
|
||||
_CET_ENDBR
|
||||
testq %r8,%r8
|
||||
jnz .L256_enc_msg_x4_start
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
.L256_enc_msg_x4_start:
|
||||
movq %r8,%r10
|
||||
@@ -2082,7 +2083,7 @@ _CET_ENDBR
|
||||
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
|
||||
@@ -2094,7 +2095,7 @@ aes256gcmsiv_enc_msg_x8:
|
||||
_CET_ENDBR
|
||||
testq %r8,%r8
|
||||
jnz .L256_enc_msg_x8_start
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
.L256_enc_msg_x8_start:
|
||||
|
||||
@@ -2371,7 +2372,7 @@ _CET_ENDBR
|
||||
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
|
||||
@@ -2384,19 +2385,20 @@ aes256gcmsiv_dec:
|
||||
_CET_ENDBR
|
||||
testq $~15,%r9
|
||||
jnz .L256_dec_start
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
.L256_dec_start:
|
||||
vzeroupper
|
||||
vmovdqa (%rdx),%xmm0
|
||||
|
||||
|
||||
vmovdqu 16(%rdx),%xmm15
|
||||
vpor OR_MASK(%rip),%xmm15,%xmm15
|
||||
movq %rdx,%rax
|
||||
|
||||
leaq 32(%rax),%rax
|
||||
leaq 32(%rcx),%rcx
|
||||
|
||||
|
||||
vmovdqu (%rdi,%r9,1),%xmm15
|
||||
vpor OR_MASK(%rip),%xmm15,%xmm15
|
||||
andq $~15,%r9
|
||||
|
||||
|
||||
@@ -2933,7 +2935,7 @@ _CET_ENDBR
|
||||
|
||||
.L256_dec_out:
|
||||
vmovdqu %xmm0,(%rdx)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aes256gcmsiv_dec, .-aes256gcmsiv_dec
|
||||
.globl aes256gcmsiv_kdf
|
||||
@@ -3085,7 +3087,7 @@ _CET_ENDBR
|
||||
vmovdqa %xmm11,48(%rsi)
|
||||
vmovdqa %xmm12,64(%rsi)
|
||||
vmovdqa %xmm13,80(%rsi)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aes256gcmsiv_kdf, .-aes256gcmsiv_kdf
|
||||
#endif
|
||||
|
||||
@@ -64,7 +64,7 @@ GFMUL:
|
||||
vpxor %xmm4,%xmm3,%xmm2
|
||||
|
||||
vpxor %xmm5,%xmm2,%xmm0
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aesgcmsiv_htable_init
|
||||
@@ -91,7 +91,7 @@ _CET_ENDBR
|
||||
vmovdqa %xmm0,96(%rdi)
|
||||
call GFMUL
|
||||
vmovdqa %xmm0,112(%rdi)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aesgcmsiv_htable6_init
|
||||
@@ -114,7 +114,7 @@ _CET_ENDBR
|
||||
vmovdqa %xmm0,64(%rdi)
|
||||
call GFMUL
|
||||
vmovdqa %xmm0,80(%rdi)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aesgcmsiv_htable_polyval
|
||||
@@ -126,7 +126,7 @@ _aesgcmsiv_htable_polyval:
|
||||
_CET_ENDBR
|
||||
testq %rdx,%rdx
|
||||
jnz L$htable_polyval_start
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
L$htable_polyval_start:
|
||||
vzeroall
|
||||
@@ -332,7 +332,7 @@ L$htable_polyval_out:
|
||||
|
||||
vmovdqu %xmm1,(%rcx)
|
||||
vzeroupper
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aesgcmsiv_polyval_horner
|
||||
@@ -344,7 +344,7 @@ _aesgcmsiv_polyval_horner:
|
||||
_CET_ENDBR
|
||||
testq %rcx,%rcx
|
||||
jnz L$polyval_horner_start
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
L$polyval_horner_start:
|
||||
|
||||
@@ -366,7 +366,7 @@ L$polyval_horner_loop:
|
||||
|
||||
|
||||
vmovdqa %xmm0,(%rdi)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aes128gcmsiv_aes_ks
|
||||
@@ -423,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
|
||||
@@ -472,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
|
||||
@@ -614,7 +614,7 @@ _CET_ENDBR
|
||||
|
||||
|
||||
vmovdqa %xmm4,0(%rsi)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aes128gcmsiv_kdf
|
||||
@@ -708,7 +708,7 @@ _CET_ENDBR
|
||||
vmovdqa %xmm10,16(%rsi)
|
||||
vmovdqa %xmm11,32(%rsi)
|
||||
vmovdqa %xmm12,48(%rsi)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aes128gcmsiv_enc_msg_x4
|
||||
@@ -720,7 +720,7 @@ _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
|
||||
@@ -884,7 +884,7 @@ L$128_enc_msg_x4_out:
|
||||
|
||||
popq %r12
|
||||
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aes128gcmsiv_enc_msg_x8
|
||||
@@ -896,7 +896,7 @@ _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
|
||||
@@ -1140,7 +1140,7 @@ L$128_enc_msg_x8_out:
|
||||
|
||||
popq %r12
|
||||
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aes128gcmsiv_dec
|
||||
@@ -1152,19 +1152,20 @@ _aes128gcmsiv_dec:
|
||||
_CET_ENDBR
|
||||
testq $~15,%r9
|
||||
jnz L$128_dec_start
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
L$128_dec_start:
|
||||
vzeroupper
|
||||
vmovdqa (%rdx),%xmm0
|
||||
|
||||
|
||||
vmovdqu 16(%rdx),%xmm15
|
||||
vpor OR_MASK(%rip),%xmm15,%xmm15
|
||||
movq %rdx,%rax
|
||||
|
||||
leaq 32(%rax),%rax
|
||||
leaq 32(%rcx),%rcx
|
||||
|
||||
|
||||
vmovdqu (%rdi,%r9,1),%xmm15
|
||||
vpor OR_MASK(%rip),%xmm15,%xmm15
|
||||
andq $~15,%r9
|
||||
|
||||
|
||||
@@ -1633,7 +1634,7 @@ L$128_dec_loop2:
|
||||
|
||||
L$128_dec_out:
|
||||
vmovdqu %xmm0,(%rdx)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aes128gcmsiv_ecb_enc_block
|
||||
@@ -1659,7 +1660,7 @@ _CET_ENDBR
|
||||
|
||||
vmovdqa %xmm1,(%rsi)
|
||||
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aes256gcmsiv_aes_ks_enc_x1
|
||||
@@ -1843,7 +1844,7 @@ _CET_ENDBR
|
||||
vmovdqu %xmm1,224(%rdx)
|
||||
|
||||
vmovdqa %xmm8,(%rsi)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aes256gcmsiv_ecb_enc_block
|
||||
@@ -1870,7 +1871,7 @@ _CET_ENDBR
|
||||
vaesenc 208(%rdx),%xmm1,%xmm1
|
||||
vaesenclast 224(%rdx),%xmm1,%xmm1
|
||||
vmovdqa %xmm1,(%rsi)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aes256gcmsiv_enc_msg_x4
|
||||
@@ -1882,7 +1883,7 @@ _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
|
||||
@@ -2072,7 +2073,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
|
||||
@@ -2084,7 +2085,7 @@ _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:
|
||||
|
||||
@@ -2361,7 +2362,7 @@ L$256_enc_msg_x8_loop2:
|
||||
jnz L$256_enc_msg_x8_loop2
|
||||
|
||||
L$256_enc_msg_x8_out:
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
|
||||
@@ -2374,19 +2375,20 @@ _aes256gcmsiv_dec:
|
||||
_CET_ENDBR
|
||||
testq $~15,%r9
|
||||
jnz L$256_dec_start
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
L$256_dec_start:
|
||||
vzeroupper
|
||||
vmovdqa (%rdx),%xmm0
|
||||
|
||||
|
||||
vmovdqu 16(%rdx),%xmm15
|
||||
vpor OR_MASK(%rip),%xmm15,%xmm15
|
||||
movq %rdx,%rax
|
||||
|
||||
leaq 32(%rax),%rax
|
||||
leaq 32(%rcx),%rcx
|
||||
|
||||
|
||||
vmovdqu (%rdi,%r9,1),%xmm15
|
||||
vpor OR_MASK(%rip),%xmm15,%xmm15
|
||||
andq $~15,%r9
|
||||
|
||||
|
||||
@@ -2923,7 +2925,7 @@ L$256_dec_loop2:
|
||||
|
||||
L$256_dec_out:
|
||||
vmovdqu %xmm0,(%rdx)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aes256gcmsiv_kdf
|
||||
@@ -3075,7 +3077,7 @@ _CET_ENDBR
|
||||
vmovdqa %xmm11,48(%rsi)
|
||||
vmovdqa %xmm12,64(%rsi)
|
||||
vmovdqa %xmm13,80(%rsi)
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
+4
-4
@@ -106,7 +106,7 @@ poly_hash_ad_internal:
|
||||
adcq %r9,%r11
|
||||
adcq $0,%r12
|
||||
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.Lhash_ad_loop:
|
||||
|
||||
cmpq $16,%r8
|
||||
@@ -215,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
|
||||
|
||||
@@ -1864,7 +1864,7 @@ _CET_ENDBR
|
||||
popq %rbp
|
||||
.cfi_adjust_cfa_offset -8
|
||||
.cfi_restore %rbp
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
.Lopen_sse_128:
|
||||
.cfi_restore_state
|
||||
@@ -3930,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
|
||||
|
||||
+4
-4
@@ -105,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
|
||||
@@ -214,7 +214,7 @@ L$hash_ad_tail_loop:
|
||||
|
||||
|
||||
L$hash_ad_done:
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
|
||||
@@ -1849,7 +1849,7 @@ L$open_sse_finalize:
|
||||
|
||||
popq %rbp
|
||||
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
L$open_sse_128:
|
||||
|
||||
@@ -3901,7 +3901,7 @@ L$do_length_block:
|
||||
|
||||
popq %rbp
|
||||
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
L$seal_sse_128:
|
||||
|
||||
|
||||
@@ -126,16 +126,16 @@ extern void aesgcmsiv_htable_polyval(const uint8_t htable[16 * 8],
|
||||
uint8_t in_out_poly[16]);
|
||||
|
||||
// aes128gcmsiv_dec decrypts |in_len| & ~15 bytes from |out| and writes them to
|
||||
// |in|. (The full value of |in_len| is still used to find the authentication
|
||||
// tag appended to the ciphertext, however, so must not be pre-masked.)
|
||||
// |in|. |in| and |out| may be equal, but must not otherwise alias.
|
||||
//
|
||||
// |in| and |out| may be equal, but must not otherwise overlap.
|
||||
// |in_out_calculated_tag_and_scratch|, on entry, must contain:
|
||||
// 1. The current value of the calculated tag, which will be updated during
|
||||
// decryption and written back to the beginning of this buffer on exit.
|
||||
// 2. The claimed tag, which is needed to derive counter values.
|
||||
//
|
||||
// While decrypting, it updates the POLYVAL value found at the beginning of
|
||||
// |in_out_calculated_tag_and_scratch| and writes the updated value back before
|
||||
// return. During executation, it may use the whole of this space for other
|
||||
// purposes. In order to decrypt and update the POLYVAL value, it uses the
|
||||
// expanded key from |key| and the table of powers in |htable|.
|
||||
// While decrypting, the whole of |in_out_calculated_tag_and_scratch| may be
|
||||
// used for other purposes. In order to decrypt and update the POLYVAL value, it
|
||||
// uses the expanded key from |key| and the table of powers in |htable|.
|
||||
extern void aes128gcmsiv_dec(const uint8_t *in, uint8_t *out,
|
||||
uint8_t in_out_calculated_tag_and_scratch[16 * 8],
|
||||
const uint8_t htable[16 * 6],
|
||||
@@ -393,14 +393,10 @@ static int aead_aes_gcm_siv_asm_seal_scatter(
|
||||
return 1;
|
||||
}
|
||||
|
||||
// TODO(martinkr): Add aead_aes_gcm_siv_asm_open_gather. N.B. aes128gcmsiv_dec
|
||||
// expects ciphertext and tag in a contiguous buffer.
|
||||
|
||||
static int aead_aes_gcm_siv_asm_open(const EVP_AEAD_CTX *ctx, uint8_t *out,
|
||||
size_t *out_len, size_t max_out_len,
|
||||
const uint8_t *nonce, size_t nonce_len,
|
||||
const uint8_t *in, size_t in_len,
|
||||
const uint8_t *ad, size_t ad_len) {
|
||||
static int aead_aes_gcm_siv_asm_open_gather(
|
||||
const EVP_AEAD_CTX *ctx, uint8_t *out, const uint8_t *nonce,
|
||||
size_t nonce_len, const uint8_t *in, size_t in_len, const uint8_t *in_tag,
|
||||
size_t in_tag_len, const uint8_t *ad, size_t ad_len) {
|
||||
const uint64_t ad_len_64 = ad_len;
|
||||
if (ad_len_64 >= (UINT64_C(1) << 61)) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_TOO_LARGE);
|
||||
@@ -408,8 +404,8 @@ static int aead_aes_gcm_siv_asm_open(const EVP_AEAD_CTX *ctx, uint8_t *out,
|
||||
}
|
||||
|
||||
const uint64_t in_len_64 = in_len;
|
||||
if (in_len < EVP_AEAD_AES_GCM_SIV_TAG_LEN ||
|
||||
in_len_64 > (UINT64_C(1) << 36) + AES_BLOCK_SIZE) {
|
||||
if (in_len_64 > UINT64_C(1) << 36 ||
|
||||
in_tag_len != EVP_AEAD_AES_GCM_SIV_TAG_LEN) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_BAD_DECRYPT);
|
||||
return 0;
|
||||
}
|
||||
@@ -420,13 +416,6 @@ static int aead_aes_gcm_siv_asm_open(const EVP_AEAD_CTX *ctx, uint8_t *out,
|
||||
}
|
||||
|
||||
const struct aead_aes_gcm_siv_asm_ctx *gcm_siv_ctx = asm_ctx_from_ctx(ctx);
|
||||
const size_t plaintext_len = in_len - EVP_AEAD_AES_GCM_SIV_TAG_LEN;
|
||||
const uint8_t *const given_tag = in + plaintext_len;
|
||||
|
||||
if (max_out_len < plaintext_len) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_BUFFER_TOO_SMALL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
alignas(16) uint64_t record_auth_key[2];
|
||||
alignas(16) uint64_t record_enc_key[4];
|
||||
@@ -459,27 +448,27 @@ static int aead_aes_gcm_siv_asm_open(const EVP_AEAD_CTX *ctx, uint8_t *out,
|
||||
alignas(16) uint8_t htable[16 * 6];
|
||||
aesgcmsiv_htable6_init(htable, (const uint8_t *)record_auth_key);
|
||||
|
||||
// aes[128|256]gcmsiv_dec needs access to the claimed tag. So it's put into
|
||||
// its scratch space.
|
||||
memcpy(calculated_tag + 16, in_tag, EVP_AEAD_AES_GCM_SIV_TAG_LEN);
|
||||
if (gcm_siv_ctx->is_128_bit) {
|
||||
aes128gcmsiv_dec(in, out, calculated_tag, htable, &expanded_key,
|
||||
plaintext_len);
|
||||
aes128gcmsiv_dec(in, out, calculated_tag, htable, &expanded_key, in_len);
|
||||
} else {
|
||||
aes256gcmsiv_dec(in, out, calculated_tag, htable, &expanded_key,
|
||||
plaintext_len);
|
||||
aes256gcmsiv_dec(in, out, calculated_tag, htable, &expanded_key, in_len);
|
||||
}
|
||||
|
||||
if (plaintext_len & 15) {
|
||||
if (in_len & 15) {
|
||||
aead_aes_gcm_siv_asm_crypt_last_block(gcm_siv_ctx->is_128_bit, out, in,
|
||||
plaintext_len, given_tag,
|
||||
&expanded_key);
|
||||
in_len, in_tag, &expanded_key);
|
||||
OPENSSL_memset(scratch, 0, sizeof(scratch));
|
||||
OPENSSL_memcpy(scratch, out + (plaintext_len & ~15), plaintext_len & 15);
|
||||
OPENSSL_memcpy(scratch, out + (in_len & ~15), in_len & 15);
|
||||
aesgcmsiv_polyval_horner(calculated_tag, (const uint8_t *)record_auth_key,
|
||||
scratch, 1);
|
||||
}
|
||||
|
||||
uint8_t length_block[16];
|
||||
CRYPTO_store_u64_le(length_block, ad_len * 8);
|
||||
CRYPTO_store_u64_le(length_block + 8, plaintext_len * 8);
|
||||
CRYPTO_store_u64_le(length_block + 8, in_len * 8);
|
||||
aesgcmsiv_polyval_horner(calculated_tag, (const uint8_t *)record_auth_key,
|
||||
length_block, 1);
|
||||
|
||||
@@ -495,13 +484,12 @@ static int aead_aes_gcm_siv_asm_open(const EVP_AEAD_CTX *ctx, uint8_t *out,
|
||||
aes256gcmsiv_ecb_enc_block(calculated_tag, calculated_tag, &expanded_key);
|
||||
}
|
||||
|
||||
if (CRYPTO_memcmp(calculated_tag, given_tag, EVP_AEAD_AES_GCM_SIV_TAG_LEN) !=
|
||||
if (CRYPTO_memcmp(calculated_tag, in_tag, EVP_AEAD_AES_GCM_SIV_TAG_LEN) !=
|
||||
0) {
|
||||
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_BAD_DECRYPT);
|
||||
return 0;
|
||||
}
|
||||
|
||||
*out_len = in_len - EVP_AEAD_AES_GCM_SIV_TAG_LEN;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -515,9 +503,9 @@ static const EVP_AEAD aead_aes_128_gcm_siv_asm = {
|
||||
aead_aes_gcm_siv_asm_init,
|
||||
NULL /* init_with_direction */,
|
||||
aead_aes_gcm_siv_asm_cleanup,
|
||||
aead_aes_gcm_siv_asm_open,
|
||||
NULL /* open */,
|
||||
aead_aes_gcm_siv_asm_seal_scatter,
|
||||
NULL /* open_gather */,
|
||||
aead_aes_gcm_siv_asm_open_gather,
|
||||
NULL /* get_iv */,
|
||||
NULL /* tag_len */,
|
||||
};
|
||||
@@ -532,9 +520,9 @@ static const EVP_AEAD aead_aes_256_gcm_siv_asm = {
|
||||
aead_aes_gcm_siv_asm_init,
|
||||
NULL /* init_with_direction */,
|
||||
aead_aes_gcm_siv_asm_cleanup,
|
||||
aead_aes_gcm_siv_asm_open,
|
||||
NULL /* open */,
|
||||
aead_aes_gcm_siv_asm_seal_scatter,
|
||||
NULL /* open_gather */,
|
||||
aead_aes_gcm_siv_asm_open_gather,
|
||||
NULL /* get_iv */,
|
||||
NULL /* tag_len */,
|
||||
};
|
||||
@@ -647,8 +635,8 @@ static void gcm_siv_polyval(
|
||||
}
|
||||
|
||||
uint8_t length_block[16];
|
||||
CRYPTO_store_u64_le(length_block, ad_len * 8);
|
||||
CRYPTO_store_u64_le(length_block + 8, in_len * 8);
|
||||
CRYPTO_store_u64_le(length_block, ((uint64_t) ad_len) * 8);
|
||||
CRYPTO_store_u64_le(length_block + 8, ((uint64_t) in_len) * 8);
|
||||
CRYPTO_POLYVAL_update_blocks(&polyval_ctx, length_block,
|
||||
sizeof(length_block));
|
||||
|
||||
|
||||
@@ -58,6 +58,7 @@
|
||||
#include <CCryptoBoringSSL_des.h>
|
||||
#include <CCryptoBoringSSL_nid.h>
|
||||
|
||||
#include "../des/internal.h"
|
||||
#include "../fipsmodule/cipher/internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
@@ -71,20 +72,15 @@ typedef struct {
|
||||
|
||||
static int des_init_key(EVP_CIPHER_CTX *ctx, const uint8_t *key,
|
||||
const uint8_t *iv, int enc) {
|
||||
DES_cblock *deskey = (DES_cblock *)key;
|
||||
EVP_DES_KEY *dat = (EVP_DES_KEY *)ctx->cipher_data;
|
||||
|
||||
DES_set_key(deskey, &dat->ks.ks);
|
||||
DES_set_key_ex(key, &dat->ks.ks);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int des_cbc_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in,
|
||||
size_t in_len) {
|
||||
EVP_DES_KEY *dat = (EVP_DES_KEY *)ctx->cipher_data;
|
||||
|
||||
DES_ncbc_encrypt(in, out, in_len, &dat->ks.ks, (DES_cblock *)ctx->iv,
|
||||
ctx->encrypt);
|
||||
|
||||
DES_ncbc_encrypt_ex(in, out, in_len, &dat->ks.ks, ctx->iv, ctx->encrypt);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -113,8 +109,7 @@ static int des_ecb_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in,
|
||||
|
||||
EVP_DES_KEY *dat = (EVP_DES_KEY *)ctx->cipher_data;
|
||||
for (size_t i = 0; i <= in_len; i += ctx->cipher->block_size) {
|
||||
DES_ecb_encrypt((DES_cblock *)(in + i), (DES_cblock *)(out + i),
|
||||
&dat->ks.ks, ctx->encrypt);
|
||||
DES_ecb_encrypt_ex(in + i, out + i, &dat->ks.ks, ctx->encrypt);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -144,23 +139,18 @@ typedef struct {
|
||||
|
||||
static int des_ede3_init_key(EVP_CIPHER_CTX *ctx, const uint8_t *key,
|
||||
const uint8_t *iv, int enc) {
|
||||
DES_cblock *deskey = (DES_cblock *)key;
|
||||
DES_EDE_KEY *dat = (DES_EDE_KEY *)ctx->cipher_data;
|
||||
|
||||
DES_set_key(&deskey[0], &dat->ks.ks[0]);
|
||||
DES_set_key(&deskey[1], &dat->ks.ks[1]);
|
||||
DES_set_key(&deskey[2], &dat->ks.ks[2]);
|
||||
|
||||
DES_set_key_ex(key, &dat->ks.ks[0]);
|
||||
DES_set_key_ex(key + 8, &dat->ks.ks[1]);
|
||||
DES_set_key_ex(key + 16, &dat->ks.ks[2]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int des_ede3_cbc_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out,
|
||||
const uint8_t *in, size_t in_len) {
|
||||
DES_EDE_KEY *dat = (DES_EDE_KEY *)ctx->cipher_data;
|
||||
|
||||
DES_ede3_cbc_encrypt(in, out, in_len, &dat->ks.ks[0], &dat->ks.ks[1],
|
||||
&dat->ks.ks[2], (DES_cblock *)ctx->iv, ctx->encrypt);
|
||||
|
||||
DES_ede3_cbc_encrypt_ex(in, out, in_len, &dat->ks.ks[0], &dat->ks.ks[1],
|
||||
&dat->ks.ks[2], ctx->iv, ctx->encrypt);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -182,13 +172,11 @@ const EVP_CIPHER *EVP_des_ede3_cbc(void) { return &evp_des_ede3_cbc; }
|
||||
|
||||
static int des_ede_init_key(EVP_CIPHER_CTX *ctx, const uint8_t *key,
|
||||
const uint8_t *iv, int enc) {
|
||||
DES_cblock *deskey = (DES_cblock *)key;
|
||||
DES_EDE_KEY *dat = (DES_EDE_KEY *)ctx->cipher_data;
|
||||
|
||||
DES_set_key(&deskey[0], &dat->ks.ks[0]);
|
||||
DES_set_key(&deskey[1], &dat->ks.ks[1]);
|
||||
DES_set_key(&deskey[0], &dat->ks.ks[2]);
|
||||
|
||||
// 2-DES is 3-DES with the first key used twice.
|
||||
DES_set_key_ex(key, &dat->ks.ks[0]);
|
||||
DES_set_key_ex(key + 8, &dat->ks.ks[1]);
|
||||
DES_set_key_ex(key, &dat->ks.ks[2]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -217,9 +205,8 @@ static int des_ede_ecb_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out,
|
||||
|
||||
DES_EDE_KEY *dat = (DES_EDE_KEY *) ctx->cipher_data;
|
||||
for (size_t i = 0; i <= in_len; i += ctx->cipher->block_size) {
|
||||
DES_ecb3_encrypt((DES_cblock *) (in + i), (DES_cblock *) (out + i),
|
||||
&dat->ks.ks[0], &dat->ks.ks[1], &dat->ks.ks[2],
|
||||
ctx->encrypt);
|
||||
DES_ecb3_encrypt_ex(in + i, out + i, &dat->ks.ks[0], &dat->ks.ks[1],
|
||||
&dat->ks.ks[2], ctx->encrypt);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -70,126 +70,117 @@
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
struct conf_section_st {
|
||||
char *name;
|
||||
// values contains non-owning pointers to the values in the section.
|
||||
STACK_OF(CONF_VALUE) *values;
|
||||
};
|
||||
|
||||
static const char kDefaultSectionName[] = "default";
|
||||
|
||||
static uint32_t conf_section_hash(const CONF_SECTION *s) {
|
||||
return OPENSSL_strhash(s->name);
|
||||
}
|
||||
|
||||
static int conf_section_cmp(const CONF_SECTION *a, const CONF_SECTION *b) {
|
||||
return strcmp(a->name, b->name);
|
||||
}
|
||||
|
||||
static uint32_t conf_value_hash(const CONF_VALUE *v) {
|
||||
const uint32_t section_hash = v->section ? OPENSSL_strhash(v->section) : 0;
|
||||
const uint32_t name_hash = v->name ? OPENSSL_strhash(v->name) : 0;
|
||||
const uint32_t section_hash = OPENSSL_strhash(v->section);
|
||||
const uint32_t name_hash = OPENSSL_strhash(v->name);
|
||||
return (section_hash << 2) ^ name_hash;
|
||||
}
|
||||
|
||||
static int conf_value_cmp(const CONF_VALUE *a, const CONF_VALUE *b) {
|
||||
int i;
|
||||
|
||||
if (a->section != b->section) {
|
||||
i = strcmp(a->section, b->section);
|
||||
if (i) {
|
||||
return i;
|
||||
}
|
||||
int cmp = strcmp(a->section, b->section);
|
||||
if (cmp != 0) {
|
||||
return cmp;
|
||||
}
|
||||
|
||||
if (a->name != NULL && b->name != NULL) {
|
||||
return strcmp(a->name, b->name);
|
||||
} else if (a->name == b->name) {
|
||||
return 0;
|
||||
} else {
|
||||
return (a->name == NULL) ? -1 : 1;
|
||||
}
|
||||
return strcmp(a->name, b->name);
|
||||
}
|
||||
|
||||
CONF *NCONF_new(void *method) {
|
||||
CONF *conf;
|
||||
|
||||
if (method != NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
conf = OPENSSL_malloc(sizeof(CONF));
|
||||
CONF *conf = OPENSSL_malloc(sizeof(CONF));
|
||||
if (conf == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
conf->data = lh_CONF_VALUE_new(conf_value_hash, conf_value_cmp);
|
||||
if (conf->data == NULL) {
|
||||
OPENSSL_free(conf);
|
||||
conf->sections = lh_CONF_SECTION_new(conf_section_hash, conf_section_cmp);
|
||||
conf->values = lh_CONF_VALUE_new(conf_value_hash, conf_value_cmp);
|
||||
if (conf->sections == NULL || conf->values == NULL) {
|
||||
NCONF_free(conf);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static void value_free_contents(CONF_VALUE *value) {
|
||||
OPENSSL_free(value->section);
|
||||
if (value->name) {
|
||||
OPENSSL_free(value->name);
|
||||
OPENSSL_free(value->value);
|
||||
} else {
|
||||
// TODO(davidben): When |value->name| is NULL, |CONF_VALUE| is actually an
|
||||
// entirely different structure. This is fragile and confusing. Make a
|
||||
// proper |CONF_SECTION| type that doesn't require this.
|
||||
sk_CONF_VALUE_free((STACK_OF(CONF_VALUE) *)value->value);
|
||||
}
|
||||
}
|
||||
CONF_VALUE *CONF_VALUE_new(void) { return OPENSSL_zalloc(sizeof(CONF_VALUE)); }
|
||||
|
||||
static void value_free(CONF_VALUE *value) {
|
||||
if (value != NULL) {
|
||||
value_free_contents(value);
|
||||
OPENSSL_free(value);
|
||||
if (value == NULL) {
|
||||
return;
|
||||
}
|
||||
OPENSSL_free(value->section);
|
||||
OPENSSL_free(value->name);
|
||||
OPENSSL_free(value->value);
|
||||
OPENSSL_free(value);
|
||||
}
|
||||
|
||||
static void section_free(CONF_SECTION *section) {
|
||||
if (section == NULL) {
|
||||
return;
|
||||
}
|
||||
OPENSSL_free(section->name);
|
||||
sk_CONF_VALUE_free(section->values);
|
||||
OPENSSL_free(section);
|
||||
}
|
||||
|
||||
static void value_free_arg(CONF_VALUE *value, void *arg) { value_free(value); }
|
||||
|
||||
static void section_free_arg(CONF_SECTION *section, void *arg) {
|
||||
section_free(section);
|
||||
}
|
||||
|
||||
void NCONF_free(CONF *conf) {
|
||||
if (conf == NULL || conf->data == NULL) {
|
||||
if (conf == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
lh_CONF_VALUE_doall_arg(conf->data, value_free_arg, NULL);
|
||||
lh_CONF_VALUE_free(conf->data);
|
||||
lh_CONF_SECTION_doall_arg(conf->sections, section_free_arg, NULL);
|
||||
lh_CONF_SECTION_free(conf->sections);
|
||||
lh_CONF_VALUE_doall_arg(conf->values, value_free_arg, NULL);
|
||||
lh_CONF_VALUE_free(conf->values);
|
||||
OPENSSL_free(conf);
|
||||
}
|
||||
|
||||
static CONF_VALUE *NCONF_new_section(const CONF *conf, const char *section) {
|
||||
STACK_OF(CONF_VALUE) *sk = NULL;
|
||||
int ok = 0;
|
||||
CONF_VALUE *v = NULL, *old_value;
|
||||
|
||||
sk = sk_CONF_VALUE_new_null();
|
||||
v = CONF_VALUE_new();
|
||||
if (sk == NULL || v == NULL) {
|
||||
goto err;
|
||||
static CONF_SECTION *NCONF_new_section(const CONF *conf, const char *section) {
|
||||
CONF_SECTION *s = OPENSSL_malloc(sizeof(CONF_SECTION));
|
||||
if (!s) {
|
||||
return NULL;
|
||||
}
|
||||
v->section = OPENSSL_strdup(section);
|
||||
if (v->section == NULL) {
|
||||
s->name = OPENSSL_strdup(section);
|
||||
s->values = sk_CONF_VALUE_new_null();
|
||||
if (s->name == NULL || s->values == NULL) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
v->name = NULL;
|
||||
v->value = (char *)sk;
|
||||
|
||||
if (!lh_CONF_VALUE_insert(conf->data, &old_value, v)) {
|
||||
CONF_SECTION *old_section;
|
||||
if (!lh_CONF_SECTION_insert(conf->sections, &old_section, s)) {
|
||||
goto err;
|
||||
}
|
||||
value_free(old_value);
|
||||
ok = 1;
|
||||
section_free(old_section);
|
||||
return s;
|
||||
|
||||
err:
|
||||
if (!ok) {
|
||||
sk_CONF_VALUE_free(sk);
|
||||
OPENSSL_free(v);
|
||||
v = NULL;
|
||||
}
|
||||
return v;
|
||||
section_free(s);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int str_copy(CONF *conf, char *section, char **pto, char *from) {
|
||||
@@ -261,21 +252,20 @@ err:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static CONF_VALUE *get_section(const CONF *conf, const char *section) {
|
||||
CONF_VALUE template;
|
||||
|
||||
static CONF_SECTION *get_section(const CONF *conf, const char *section) {
|
||||
CONF_SECTION template;
|
||||
OPENSSL_memset(&template, 0, sizeof(template));
|
||||
template.section = (char *) section;
|
||||
return lh_CONF_VALUE_retrieve(conf->data, &template);
|
||||
template.name = (char *) section;
|
||||
return lh_CONF_SECTION_retrieve(conf->sections, &template);
|
||||
}
|
||||
|
||||
const STACK_OF(CONF_VALUE) *NCONF_get_section(const CONF *conf,
|
||||
const char *section) {
|
||||
const CONF_VALUE *section_value = get_section(conf, section);
|
||||
if (section_value == NULL) {
|
||||
const CONF_SECTION *section_obj = get_section(conf, section);
|
||||
if (section_obj == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return (STACK_OF(CONF_VALUE)*) section_value->value;
|
||||
return section_obj->values;
|
||||
}
|
||||
|
||||
const char *NCONF_get_string(const CONF *conf, const char *section,
|
||||
@@ -287,30 +277,35 @@ const char *NCONF_get_string(const CONF *conf, const char *section,
|
||||
}
|
||||
|
||||
OPENSSL_memset(&template, 0, sizeof(template));
|
||||
template.section = (char *) section;
|
||||
template.name = (char *) name;
|
||||
value = lh_CONF_VALUE_retrieve(conf->data, &template);
|
||||
template.section = (char *)section;
|
||||
template.name = (char *)name;
|
||||
value = lh_CONF_VALUE_retrieve(conf->values, &template);
|
||||
if (value == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
return value->value;
|
||||
}
|
||||
|
||||
static int add_string(const CONF *conf, CONF_VALUE *section,
|
||||
static int add_string(const CONF *conf, CONF_SECTION *section,
|
||||
CONF_VALUE *value) {
|
||||
STACK_OF(CONF_VALUE) *section_stack = (STACK_OF(CONF_VALUE)*) section->value;
|
||||
CONF_VALUE *old_value;
|
||||
|
||||
value->section = OPENSSL_strdup(section->section);
|
||||
if (!sk_CONF_VALUE_push(section_stack, value)) {
|
||||
value->section = OPENSSL_strdup(section->name);
|
||||
if (value->section == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!lh_CONF_VALUE_insert(conf->data, &old_value, value)) {
|
||||
if (!sk_CONF_VALUE_push(section->values, value)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
CONF_VALUE *old_value;
|
||||
if (!lh_CONF_VALUE_insert(conf->values, &old_value, value)) {
|
||||
// Remove |value| from |section->values|, so we do not leave a dangling
|
||||
// pointer.
|
||||
sk_CONF_VALUE_pop(section->values);
|
||||
return 0;
|
||||
}
|
||||
if (old_value != NULL) {
|
||||
(void)sk_CONF_VALUE_delete_ptr(section_stack, old_value);
|
||||
(void)sk_CONF_VALUE_delete_ptr(section->values, old_value);
|
||||
value_free(old_value);
|
||||
}
|
||||
|
||||
@@ -395,8 +390,8 @@ int NCONF_load_bio(CONF *conf, BIO *in, long *out_error_line) {
|
||||
int again;
|
||||
long eline = 0;
|
||||
char btmp[DECIMAL_SIZE(eline) + 1];
|
||||
CONF_VALUE *v = NULL, *tv;
|
||||
CONF_VALUE *sv = NULL;
|
||||
CONF_VALUE *v = NULL;
|
||||
CONF_SECTION *sv = NULL;
|
||||
char *section = NULL, *buf;
|
||||
char *start, *psection, *pname;
|
||||
|
||||
@@ -547,6 +542,7 @@ int NCONF_load_bio(CONF *conf, BIO *in, long *out_error_line) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
CONF_SECTION *tv;
|
||||
if (strcmp(psection, section) != 0) {
|
||||
if ((tv = get_section(conf, psection)) == NULL) {
|
||||
tv = NCONF_new_section(conf, psection);
|
||||
@@ -576,12 +572,7 @@ err:
|
||||
}
|
||||
snprintf(btmp, sizeof btmp, "%ld", eline);
|
||||
ERR_add_error_data(2, "line ", btmp);
|
||||
|
||||
if (v != NULL) {
|
||||
OPENSSL_free(v->name);
|
||||
OPENSSL_free(v->value);
|
||||
OPENSSL_free(v);
|
||||
}
|
||||
value_free(v);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,10 +24,14 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct conf_section_st CONF_SECTION;
|
||||
|
||||
DEFINE_LHASH_OF(CONF_SECTION)
|
||||
DEFINE_LHASH_OF(CONF_VALUE)
|
||||
|
||||
struct conf_st {
|
||||
LHASH_OF(CONF_VALUE) *data;
|
||||
LHASH_OF(CONF_VALUE) *values;
|
||||
LHASH_OF(CONF_SECTION) *sections;
|
||||
};
|
||||
|
||||
// CONF_VALUE_new returns a freshly allocated and zeroed |CONF_VALUE|.
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
/* Copyright (c) 2014, 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"
|
||||
|
||||
#if (defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)) && \
|
||||
!defined(OPENSSL_STATIC_ARMCAP)
|
||||
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
|
||||
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) */
|
||||
@@ -211,7 +211,8 @@ void OPENSSL_cpuid_setup(void) {
|
||||
|
||||
// Clear the XSAVE bit on Knights Landing to mimic Silvermont. This enables
|
||||
// some Silvermont-specific codepaths which perform better. See OpenSSL
|
||||
// commit 64d92d74985ebb3d0be58a9718f9e080a14a8e7f.
|
||||
// commit 64d92d74985ebb3d0be58a9718f9e080a14a8e7f and
|
||||
// |CRYPTO_cpu_perf_is_like_silvermont|.
|
||||
if ((eax & 0x0fff0ff0) == 0x00050670 /* Knights Landing */ ||
|
||||
(eax & 0x0fff0ff0) == 0x00080650 /* Knights Mill (per SDE) */) {
|
||||
ecx &= ~(1u << 26);
|
||||
@@ -238,7 +239,8 @@ void OPENSSL_cpuid_setup(void) {
|
||||
// Clear AVX2 and AVX512* bits.
|
||||
//
|
||||
// TODO(davidben): Should bits 17 and 26-28 also be cleared? Upstream
|
||||
// doesn't clear those.
|
||||
// doesn't clear those. See the comments in
|
||||
// |CRYPTO_hardware_supports_XSAVE|.
|
||||
extended_features[0] &=
|
||||
~((1u << 5) | (1u << 16) | (1u << 21) | (1u << 30) | (1u << 31));
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -1906,6 +1906,8 @@ int ED25519_sign(uint8_t out_sig[64], const uint8_t *message,
|
||||
x25519_sc_reduce(hram);
|
||||
sc_muladd(out_sig + 32, hram, az, nonce);
|
||||
|
||||
// The signature is computed from the private key, but is public.
|
||||
CONSTTIME_DECLASSIFY(out_sig, 64);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1983,6 +1985,8 @@ void ED25519_keypair_from_seed(uint8_t out_public_key[32],
|
||||
ge_p3 A;
|
||||
x25519_ge_scalarmult_base(&A, az);
|
||||
ge_p3_tobytes(out_public_key, &A);
|
||||
// The public key is derived from the private key, but it is public.
|
||||
CONSTTIME_DECLASSIFY(out_public_key, 32);
|
||||
|
||||
OPENSSL_memcpy(out_private_key, seed, 32);
|
||||
OPENSSL_memcpy(out_private_key + 32, out_public_key, 32);
|
||||
|
||||
@@ -32,7 +32,7 @@ void x25519_NEON(uint8_t out[32], const uint8_t scalar[32],
|
||||
#endif
|
||||
|
||||
#if !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_SMALL) && \
|
||||
defined(__GNUC__) && defined(__x86_64__)
|
||||
defined(__GNUC__) && defined(__x86_64__) && !defined(OPENSSL_WINDOWS)
|
||||
#define BORINGSSL_FE25519_ADX
|
||||
|
||||
// fiat_curve25519_adx_mul is defined in
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -61,6 +61,91 @@
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
/* IP and FP
|
||||
* The problem is more of a geometric problem that random bit fiddling.
|
||||
0 1 2 3 4 5 6 7 62 54 46 38 30 22 14 6
|
||||
8 9 10 11 12 13 14 15 60 52 44 36 28 20 12 4
|
||||
16 17 18 19 20 21 22 23 58 50 42 34 26 18 10 2
|
||||
24 25 26 27 28 29 30 31 to 56 48 40 32 24 16 8 0
|
||||
|
||||
32 33 34 35 36 37 38 39 63 55 47 39 31 23 15 7
|
||||
40 41 42 43 44 45 46 47 61 53 45 37 29 21 13 5
|
||||
48 49 50 51 52 53 54 55 59 51 43 35 27 19 11 3
|
||||
56 57 58 59 60 61 62 63 57 49 41 33 25 17 9 1
|
||||
|
||||
The output has been subject to swaps of the form
|
||||
0 1 -> 3 1 but the odd and even bits have been put into
|
||||
2 3 2 0
|
||||
different words. The main trick is to remember that
|
||||
t=((l>>size)^r)&(mask);
|
||||
r^=t;
|
||||
l^=(t<<size);
|
||||
can be used to swap and move bits between words.
|
||||
|
||||
So l = 0 1 2 3 r = 16 17 18 19
|
||||
4 5 6 7 20 21 22 23
|
||||
8 9 10 11 24 25 26 27
|
||||
12 13 14 15 28 29 30 31
|
||||
becomes (for size == 2 and mask == 0x3333)
|
||||
t = 2^16 3^17 -- -- l = 0 1 16 17 r = 2 3 18 19
|
||||
6^20 7^21 -- -- 4 5 20 21 6 7 22 23
|
||||
10^24 11^25 -- -- 8 9 24 25 10 11 24 25
|
||||
14^28 15^29 -- -- 12 13 28 29 14 15 28 29
|
||||
|
||||
Thanks for hints from Richard Outerbridge - he told me IP&FP
|
||||
could be done in 15 xor, 10 shifts and 5 ands.
|
||||
When I finally started to think of the problem in 2D
|
||||
I first got ~42 operations without xors. When I remembered
|
||||
how to use xors :-) I got it to its final state.
|
||||
*/
|
||||
#define PERM_OP(a, b, t, n, m) \
|
||||
do { \
|
||||
(t) = ((((a) >> (n)) ^ (b)) & (m)); \
|
||||
(b) ^= (t); \
|
||||
(a) ^= ((t) << (n)); \
|
||||
} while (0)
|
||||
|
||||
#define IP(l, r) \
|
||||
do { \
|
||||
uint32_t tt; \
|
||||
PERM_OP(r, l, tt, 4, 0x0f0f0f0fL); \
|
||||
PERM_OP(l, r, tt, 16, 0x0000ffffL); \
|
||||
PERM_OP(r, l, tt, 2, 0x33333333L); \
|
||||
PERM_OP(l, r, tt, 8, 0x00ff00ffL); \
|
||||
PERM_OP(r, l, tt, 1, 0x55555555L); \
|
||||
} while (0)
|
||||
|
||||
#define FP(l, r) \
|
||||
do { \
|
||||
uint32_t tt; \
|
||||
PERM_OP(l, r, tt, 1, 0x55555555L); \
|
||||
PERM_OP(r, l, tt, 8, 0x00ff00ffL); \
|
||||
PERM_OP(l, r, tt, 2, 0x33333333L); \
|
||||
PERM_OP(r, l, tt, 16, 0x0000ffffL); \
|
||||
PERM_OP(l, r, tt, 4, 0x0f0f0f0fL); \
|
||||
} while (0)
|
||||
|
||||
#define LOAD_DATA(ks, R, S, u, t, E0, E1) \
|
||||
do { \
|
||||
(u) = (R) ^ (ks)->subkeys[S][0]; \
|
||||
(t) = (R) ^ (ks)->subkeys[S][1]; \
|
||||
} while (0)
|
||||
|
||||
#define D_ENCRYPT(ks, LL, R, S) \
|
||||
do { \
|
||||
LOAD_DATA(ks, R, S, u, t, E0, E1); \
|
||||
t = CRYPTO_rotr_u32(t, 4); \
|
||||
(LL) ^= \
|
||||
DES_SPtrans[0][(u >> 2L) & 0x3f] ^ DES_SPtrans[2][(u >> 10L) & 0x3f] ^ \
|
||||
DES_SPtrans[4][(u >> 18L) & 0x3f] ^ \
|
||||
DES_SPtrans[6][(u >> 26L) & 0x3f] ^ DES_SPtrans[1][(t >> 2L) & 0x3f] ^ \
|
||||
DES_SPtrans[3][(t >> 10L) & 0x3f] ^ \
|
||||
DES_SPtrans[5][(t >> 18L) & 0x3f] ^ DES_SPtrans[7][(t >> 26L) & 0x3f]; \
|
||||
} while (0)
|
||||
|
||||
#define ITERATIONS 16
|
||||
#define HALF_ITERATIONS 8
|
||||
|
||||
static const uint32_t des_skb[8][64] = {
|
||||
{ // for C bits (numbered as per FIPS 46) 1 2 3 4 5 6
|
||||
0x00000000, 0x00000010, 0x20000000, 0x20000010, 0x00010000,
|
||||
@@ -294,13 +379,17 @@ static const uint32_t DES_SPtrans[8][64] = {
|
||||
(a) = (a) ^ (t) ^ ((t) >> (16 - (n))))
|
||||
|
||||
void DES_set_key(const DES_cblock *key, DES_key_schedule *schedule) {
|
||||
DES_set_key_ex(key->bytes, schedule);
|
||||
}
|
||||
|
||||
void DES_set_key_ex(const uint8_t key[8], DES_key_schedule *schedule) {
|
||||
static const int shifts2[16] = {0, 0, 1, 1, 1, 1, 1, 1,
|
||||
0, 1, 1, 1, 1, 1, 1, 0};
|
||||
uint32_t c, d, t, s, t2;
|
||||
const uint8_t *in;
|
||||
int i;
|
||||
|
||||
in = key->bytes;
|
||||
in = key;
|
||||
|
||||
c2l(in, c);
|
||||
c2l(in, d);
|
||||
@@ -378,7 +467,8 @@ void DES_set_odd_parity(DES_cblock *key) {
|
||||
}
|
||||
}
|
||||
|
||||
static void DES_encrypt1(uint32_t *data, const DES_key_schedule *ks, int enc) {
|
||||
static void DES_encrypt1(uint32_t data[2], const DES_key_schedule *ks,
|
||||
int enc) {
|
||||
uint32_t l, r, t, u;
|
||||
|
||||
r = data[0];
|
||||
@@ -442,7 +532,8 @@ static void DES_encrypt1(uint32_t *data, const DES_key_schedule *ks, int enc) {
|
||||
data[1] = r;
|
||||
}
|
||||
|
||||
static void DES_encrypt2(uint32_t *data, const DES_key_schedule *ks, int enc) {
|
||||
static void DES_encrypt2(uint32_t data[2], const DES_key_schedule *ks,
|
||||
int enc) {
|
||||
uint32_t l, r, t, u;
|
||||
|
||||
r = data[0];
|
||||
@@ -499,7 +590,7 @@ static void DES_encrypt2(uint32_t *data, const DES_key_schedule *ks, int enc) {
|
||||
data[1] = CRYPTO_rotr_u32(r, 3);
|
||||
}
|
||||
|
||||
void DES_encrypt3(uint32_t *data, const DES_key_schedule *ks1,
|
||||
void DES_encrypt3(uint32_t data[2], const DES_key_schedule *ks1,
|
||||
const DES_key_schedule *ks2, const DES_key_schedule *ks3) {
|
||||
uint32_t l, r;
|
||||
|
||||
@@ -508,9 +599,9 @@ void DES_encrypt3(uint32_t *data, const DES_key_schedule *ks1,
|
||||
IP(l, r);
|
||||
data[0] = l;
|
||||
data[1] = r;
|
||||
DES_encrypt2((uint32_t *)data, ks1, DES_ENCRYPT);
|
||||
DES_encrypt2((uint32_t *)data, ks2, DES_DECRYPT);
|
||||
DES_encrypt2((uint32_t *)data, ks3, DES_ENCRYPT);
|
||||
DES_encrypt2(data, ks1, DES_ENCRYPT);
|
||||
DES_encrypt2(data, ks2, DES_DECRYPT);
|
||||
DES_encrypt2(data, ks3, DES_ENCRYPT);
|
||||
l = data[0];
|
||||
r = data[1];
|
||||
FP(r, l);
|
||||
@@ -518,7 +609,7 @@ void DES_encrypt3(uint32_t *data, const DES_key_schedule *ks1,
|
||||
data[1] = r;
|
||||
}
|
||||
|
||||
void DES_decrypt3(uint32_t *data, const DES_key_schedule *ks1,
|
||||
void DES_decrypt3(uint32_t data[2], const DES_key_schedule *ks1,
|
||||
const DES_key_schedule *ks2, const DES_key_schedule *ks3) {
|
||||
uint32_t l, r;
|
||||
|
||||
@@ -527,9 +618,9 @@ void DES_decrypt3(uint32_t *data, const DES_key_schedule *ks1,
|
||||
IP(l, r);
|
||||
data[0] = l;
|
||||
data[1] = r;
|
||||
DES_encrypt2((uint32_t *)data, ks3, DES_DECRYPT);
|
||||
DES_encrypt2((uint32_t *)data, ks2, DES_ENCRYPT);
|
||||
DES_encrypt2((uint32_t *)data, ks1, DES_DECRYPT);
|
||||
DES_encrypt2(data, ks3, DES_DECRYPT);
|
||||
DES_encrypt2(data, ks2, DES_ENCRYPT);
|
||||
DES_encrypt2(data, ks1, DES_DECRYPT);
|
||||
l = data[0];
|
||||
r = data[1];
|
||||
FP(r, l);
|
||||
@@ -539,32 +630,34 @@ void DES_decrypt3(uint32_t *data, const DES_key_schedule *ks1,
|
||||
|
||||
void DES_ecb_encrypt(const DES_cblock *in_block, DES_cblock *out_block,
|
||||
const DES_key_schedule *schedule, int is_encrypt) {
|
||||
uint32_t l;
|
||||
uint32_t ll[2];
|
||||
const uint8_t *in = in_block->bytes;
|
||||
uint8_t *out = out_block->bytes;
|
||||
DES_ecb_encrypt_ex(in_block->bytes, out_block->bytes, schedule, is_encrypt);
|
||||
}
|
||||
|
||||
c2l(in, l);
|
||||
ll[0] = l;
|
||||
c2l(in, l);
|
||||
ll[1] = l;
|
||||
void DES_ecb_encrypt_ex(const uint8_t in[8], uint8_t out[8],
|
||||
const DES_key_schedule *schedule, int is_encrypt) {
|
||||
uint32_t ll[2];
|
||||
ll[0] = CRYPTO_load_u32_le(in);
|
||||
ll[1] = CRYPTO_load_u32_le(in + 4);
|
||||
DES_encrypt1(ll, schedule, is_encrypt);
|
||||
l = ll[0];
|
||||
l2c(l, out);
|
||||
l = ll[1];
|
||||
l2c(l, out);
|
||||
ll[0] = ll[1] = 0;
|
||||
CRYPTO_store_u32_le(out, ll[0]);
|
||||
CRYPTO_store_u32_le(out + 4, ll[1]);
|
||||
}
|
||||
|
||||
void DES_ncbc_encrypt(const uint8_t *in, uint8_t *out, size_t len,
|
||||
const DES_key_schedule *schedule, DES_cblock *ivec,
|
||||
int enc) {
|
||||
DES_ncbc_encrypt_ex(in, out, len, schedule, ivec->bytes, enc);
|
||||
}
|
||||
|
||||
void DES_ncbc_encrypt_ex(const uint8_t *in, uint8_t *out, size_t len,
|
||||
const DES_key_schedule *schedule, uint8_t ivec[8],
|
||||
int enc) {
|
||||
uint32_t tin0, tin1;
|
||||
uint32_t tout0, tout1, xor0, xor1;
|
||||
uint32_t tin[2];
|
||||
unsigned char *iv;
|
||||
|
||||
iv = ivec->bytes;
|
||||
iv = ivec;
|
||||
|
||||
if (enc) {
|
||||
c2l(iv, tout0);
|
||||
@@ -576,7 +669,7 @@ void DES_ncbc_encrypt(const uint8_t *in, uint8_t *out, size_t len,
|
||||
tin[0] = tin0;
|
||||
tin1 ^= tout1;
|
||||
tin[1] = tin1;
|
||||
DES_encrypt1((uint32_t *)tin, schedule, DES_ENCRYPT);
|
||||
DES_encrypt1(tin, schedule, DES_ENCRYPT);
|
||||
tout0 = tin[0];
|
||||
l2c(tout0, out);
|
||||
tout1 = tin[1];
|
||||
@@ -588,13 +681,13 @@ void DES_ncbc_encrypt(const uint8_t *in, uint8_t *out, size_t len,
|
||||
tin[0] = tin0;
|
||||
tin1 ^= tout1;
|
||||
tin[1] = tin1;
|
||||
DES_encrypt1((uint32_t *)tin, schedule, DES_ENCRYPT);
|
||||
DES_encrypt1(tin, schedule, DES_ENCRYPT);
|
||||
tout0 = tin[0];
|
||||
l2c(tout0, out);
|
||||
tout1 = tin[1];
|
||||
l2c(tout1, out);
|
||||
}
|
||||
iv = ivec->bytes;
|
||||
iv = ivec;
|
||||
l2c(tout0, iv);
|
||||
l2c(tout1, iv);
|
||||
} else {
|
||||
@@ -605,7 +698,7 @@ void DES_ncbc_encrypt(const uint8_t *in, uint8_t *out, size_t len,
|
||||
tin[0] = tin0;
|
||||
c2l(in, tin1);
|
||||
tin[1] = tin1;
|
||||
DES_encrypt1((uint32_t *)tin, schedule, DES_DECRYPT);
|
||||
DES_encrypt1(tin, schedule, DES_DECRYPT);
|
||||
tout0 = tin[0] ^ xor0;
|
||||
tout1 = tin[1] ^ xor1;
|
||||
l2c(tout0, out);
|
||||
@@ -618,14 +711,14 @@ void DES_ncbc_encrypt(const uint8_t *in, uint8_t *out, size_t len,
|
||||
tin[0] = tin0;
|
||||
c2l(in, tin1);
|
||||
tin[1] = tin1;
|
||||
DES_encrypt1((uint32_t *)tin, schedule, DES_DECRYPT);
|
||||
DES_encrypt1(tin, schedule, DES_DECRYPT);
|
||||
tout0 = tin[0] ^ xor0;
|
||||
tout1 = tin[1] ^ xor1;
|
||||
l2cn(tout0, tout1, out, len);
|
||||
xor0 = tin0;
|
||||
xor1 = tin1;
|
||||
}
|
||||
iv = ivec->bytes;
|
||||
iv = ivec;
|
||||
l2c(xor0, iv);
|
||||
l2c(xor1, iv);
|
||||
}
|
||||
@@ -635,24 +728,23 @@ void DES_ncbc_encrypt(const uint8_t *in, uint8_t *out, size_t len,
|
||||
void DES_ecb3_encrypt(const DES_cblock *input, DES_cblock *output,
|
||||
const DES_key_schedule *ks1, const DES_key_schedule *ks2,
|
||||
const DES_key_schedule *ks3, int enc) {
|
||||
uint32_t l0, l1;
|
||||
uint32_t ll[2];
|
||||
const uint8_t *in = input->bytes;
|
||||
uint8_t *out = output->bytes;
|
||||
DES_ecb3_encrypt_ex(input->bytes, output->bytes, ks1, ks2, ks3, enc);
|
||||
}
|
||||
|
||||
c2l(in, l0);
|
||||
c2l(in, l1);
|
||||
ll[0] = l0;
|
||||
ll[1] = l1;
|
||||
void DES_ecb3_encrypt_ex(const uint8_t in[8], uint8_t out[8],
|
||||
const DES_key_schedule *ks1,
|
||||
const DES_key_schedule *ks2,
|
||||
const DES_key_schedule *ks3, int enc) {
|
||||
uint32_t ll[2];
|
||||
ll[0] = CRYPTO_load_u32_le(in);
|
||||
ll[1] = CRYPTO_load_u32_le(in + 4);
|
||||
if (enc) {
|
||||
DES_encrypt3(ll, ks1, ks2, ks3);
|
||||
} else {
|
||||
DES_decrypt3(ll, ks1, ks2, ks3);
|
||||
}
|
||||
l0 = ll[0];
|
||||
l1 = ll[1];
|
||||
l2c(l0, out);
|
||||
l2c(l1, out);
|
||||
CRYPTO_store_u32_le(out, ll[0]);
|
||||
CRYPTO_store_u32_le(out + 4, ll[1]);
|
||||
}
|
||||
|
||||
void DES_ede3_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t len,
|
||||
@@ -660,12 +752,20 @@ void DES_ede3_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t len,
|
||||
const DES_key_schedule *ks2,
|
||||
const DES_key_schedule *ks3, DES_cblock *ivec,
|
||||
int enc) {
|
||||
DES_ede3_cbc_encrypt_ex(in, out, len, ks1, ks2, ks3, ivec->bytes, enc);
|
||||
}
|
||||
|
||||
void DES_ede3_cbc_encrypt_ex(const uint8_t *in, uint8_t *out, size_t len,
|
||||
const DES_key_schedule *ks1,
|
||||
const DES_key_schedule *ks2,
|
||||
const DES_key_schedule *ks3, uint8_t ivec[8],
|
||||
int enc) {
|
||||
uint32_t tin0, tin1;
|
||||
uint32_t tout0, tout1, xor0, xor1;
|
||||
uint32_t tin[2];
|
||||
uint8_t *iv;
|
||||
|
||||
iv = ivec->bytes;
|
||||
iv = ivec;
|
||||
|
||||
if (enc) {
|
||||
c2l(iv, tout0);
|
||||
@@ -678,7 +778,7 @@ void DES_ede3_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t len,
|
||||
|
||||
tin[0] = tin0;
|
||||
tin[1] = tin1;
|
||||
DES_encrypt3((uint32_t *)tin, ks1, ks2, ks3);
|
||||
DES_encrypt3(tin, ks1, ks2, ks3);
|
||||
tout0 = tin[0];
|
||||
tout1 = tin[1];
|
||||
|
||||
@@ -692,14 +792,14 @@ void DES_ede3_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t len,
|
||||
|
||||
tin[0] = tin0;
|
||||
tin[1] = tin1;
|
||||
DES_encrypt3((uint32_t *)tin, ks1, ks2, ks3);
|
||||
DES_encrypt3(tin, ks1, ks2, ks3);
|
||||
tout0 = tin[0];
|
||||
tout1 = tin[1];
|
||||
|
||||
l2c(tout0, out);
|
||||
l2c(tout1, out);
|
||||
}
|
||||
iv = ivec->bytes;
|
||||
iv = ivec;
|
||||
l2c(tout0, iv);
|
||||
l2c(tout1, iv);
|
||||
} else {
|
||||
@@ -716,7 +816,7 @@ void DES_ede3_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t len,
|
||||
|
||||
tin[0] = tin0;
|
||||
tin[1] = tin1;
|
||||
DES_decrypt3((uint32_t *)tin, ks1, ks2, ks3);
|
||||
DES_decrypt3(tin, ks1, ks2, ks3);
|
||||
tout0 = tin[0];
|
||||
tout1 = tin[1];
|
||||
|
||||
@@ -736,7 +836,7 @@ void DES_ede3_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t len,
|
||||
|
||||
tin[0] = tin0;
|
||||
tin[1] = tin1;
|
||||
DES_decrypt3((uint32_t *)tin, ks1, ks2, ks3);
|
||||
DES_decrypt3(tin, ks1, ks2, ks3);
|
||||
tout0 = tin[0];
|
||||
tout1 = tin[1];
|
||||
|
||||
@@ -747,7 +847,7 @@ void DES_ede3_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t len,
|
||||
xor1 = t1;
|
||||
}
|
||||
|
||||
iv = ivec->bytes;
|
||||
iv = ivec;
|
||||
l2c(xor0, iv);
|
||||
l2c(xor1, iv);
|
||||
}
|
||||
@@ -769,16 +869,3 @@ void DES_ede2_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t len,
|
||||
void DES_set_key_unchecked(const DES_cblock *key, DES_key_schedule *schedule) {
|
||||
DES_set_key(key, schedule);
|
||||
}
|
||||
|
||||
#undef HPERM_OP
|
||||
#undef c2l
|
||||
#undef l2c
|
||||
#undef c2ln
|
||||
#undef l2cn
|
||||
#undef PERM_OP
|
||||
#undef IP
|
||||
#undef FP
|
||||
#undef LOAD_DATA
|
||||
#undef D_ENCRYPT
|
||||
#undef ITERATIONS
|
||||
#undef HALF_ITERATIONS
|
||||
@@ -58,6 +58,7 @@
|
||||
#define OPENSSL_HEADER_DES_INTERNAL_H
|
||||
|
||||
#include <CCryptoBoringSSL_base.h>
|
||||
#include <CCryptoBoringSSL_des.h>
|
||||
|
||||
#include "../internal.h"
|
||||
|
||||
@@ -66,6 +67,9 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
// TODO(davidben): Ideally these macros would be replaced with
|
||||
// |CRYPTO_load_u32_le| and |CRYPTO_store_u32_le|.
|
||||
|
||||
#define c2l(c, l) \
|
||||
do { \
|
||||
(l) = ((uint32_t)(*((c)++))); \
|
||||
@@ -145,90 +149,39 @@ extern "C" {
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/* IP and FP
|
||||
* The problem is more of a geometric problem that random bit fiddling.
|
||||
0 1 2 3 4 5 6 7 62 54 46 38 30 22 14 6
|
||||
8 9 10 11 12 13 14 15 60 52 44 36 28 20 12 4
|
||||
16 17 18 19 20 21 22 23 58 50 42 34 26 18 10 2
|
||||
24 25 26 27 28 29 30 31 to 56 48 40 32 24 16 8 0
|
||||
|
||||
32 33 34 35 36 37 38 39 63 55 47 39 31 23 15 7
|
||||
40 41 42 43 44 45 46 47 61 53 45 37 29 21 13 5
|
||||
48 49 50 51 52 53 54 55 59 51 43 35 27 19 11 3
|
||||
56 57 58 59 60 61 62 63 57 49 41 33 25 17 9 1
|
||||
// Correctly-typed versions of DES functions.
|
||||
//
|
||||
// See https://crbug.com/boringssl/683.
|
||||
|
||||
The output has been subject to swaps of the form
|
||||
0 1 -> 3 1 but the odd and even bits have been put into
|
||||
2 3 2 0
|
||||
different words. The main trick is to remember that
|
||||
t=((l>>size)^r)&(mask);
|
||||
r^=t;
|
||||
l^=(t<<size);
|
||||
can be used to swap and move bits between words.
|
||||
void DES_set_key_ex(const uint8_t key[8], DES_key_schedule *schedule);
|
||||
void DES_ecb_encrypt_ex(const uint8_t in[8], uint8_t out[8],
|
||||
const DES_key_schedule *schedule, int is_encrypt);
|
||||
void DES_ncbc_encrypt_ex(const uint8_t *in, uint8_t *out, size_t len,
|
||||
const DES_key_schedule *schedule, uint8_t ivec[8],
|
||||
int enc);
|
||||
void DES_ecb3_encrypt_ex(const uint8_t input[8], uint8_t output[8],
|
||||
const DES_key_schedule *ks1,
|
||||
const DES_key_schedule *ks2,
|
||||
const DES_key_schedule *ks3, int enc);
|
||||
void DES_ede3_cbc_encrypt_ex(const uint8_t *in, uint8_t *out, size_t len,
|
||||
const DES_key_schedule *ks1,
|
||||
const DES_key_schedule *ks2,
|
||||
const DES_key_schedule *ks3, uint8_t ivec[8],
|
||||
int enc);
|
||||
|
||||
So l = 0 1 2 3 r = 16 17 18 19
|
||||
4 5 6 7 20 21 22 23
|
||||
8 9 10 11 24 25 26 27
|
||||
12 13 14 15 28 29 30 31
|
||||
becomes (for size == 2 and mask == 0x3333)
|
||||
t = 2^16 3^17 -- -- l = 0 1 16 17 r = 2 3 18 19
|
||||
6^20 7^21 -- -- 4 5 20 21 6 7 22 23
|
||||
10^24 11^25 -- -- 8 9 24 25 10 11 24 25
|
||||
14^28 15^29 -- -- 12 13 28 29 14 15 28 29
|
||||
|
||||
Thanks for hints from Richard Outerbridge - he told me IP&FP
|
||||
could be done in 15 xor, 10 shifts and 5 ands.
|
||||
When I finally started to think of the problem in 2D
|
||||
I first got ~42 operations without xors. When I remembered
|
||||
how to use xors :-) I got it to its final state.
|
||||
*/
|
||||
#define PERM_OP(a, b, t, n, m) \
|
||||
do { \
|
||||
(t) = ((((a) >> (n)) ^ (b)) & (m)); \
|
||||
(b) ^= (t); \
|
||||
(a) ^= ((t) << (n)); \
|
||||
} while (0)
|
||||
// Private functions.
|
||||
//
|
||||
// These functions are only exported for use in |decrepit|.
|
||||
|
||||
#define IP(l, r) \
|
||||
do { \
|
||||
uint32_t tt; \
|
||||
PERM_OP(r, l, tt, 4, 0x0f0f0f0fL); \
|
||||
PERM_OP(l, r, tt, 16, 0x0000ffffL); \
|
||||
PERM_OP(r, l, tt, 2, 0x33333333L); \
|
||||
PERM_OP(l, r, tt, 8, 0x00ff00ffL); \
|
||||
PERM_OP(r, l, tt, 1, 0x55555555L); \
|
||||
} while (0)
|
||||
OPENSSL_EXPORT void DES_decrypt3(uint32_t data[2], const DES_key_schedule *ks1,
|
||||
const DES_key_schedule *ks2,
|
||||
const DES_key_schedule *ks3);
|
||||
|
||||
#define FP(l, r) \
|
||||
do { \
|
||||
uint32_t tt; \
|
||||
PERM_OP(l, r, tt, 1, 0x55555555L); \
|
||||
PERM_OP(r, l, tt, 8, 0x00ff00ffL); \
|
||||
PERM_OP(l, r, tt, 2, 0x33333333L); \
|
||||
PERM_OP(r, l, tt, 16, 0x0000ffffL); \
|
||||
PERM_OP(l, r, tt, 4, 0x0f0f0f0fL); \
|
||||
} while (0)
|
||||
|
||||
#define LOAD_DATA(ks, R, S, u, t, E0, E1) \
|
||||
do { \
|
||||
(u) = (R) ^ (ks)->subkeys[S][0]; \
|
||||
(t) = (R) ^ (ks)->subkeys[S][1]; \
|
||||
} while (0)
|
||||
|
||||
#define D_ENCRYPT(ks, LL, R, S) \
|
||||
do { \
|
||||
LOAD_DATA(ks, R, S, u, t, E0, E1); \
|
||||
t = CRYPTO_rotr_u32(t, 4); \
|
||||
(LL) ^= \
|
||||
DES_SPtrans[0][(u >> 2L) & 0x3f] ^ DES_SPtrans[2][(u >> 10L) & 0x3f] ^ \
|
||||
DES_SPtrans[4][(u >> 18L) & 0x3f] ^ \
|
||||
DES_SPtrans[6][(u >> 26L) & 0x3f] ^ DES_SPtrans[1][(t >> 2L) & 0x3f] ^ \
|
||||
DES_SPtrans[3][(t >> 10L) & 0x3f] ^ \
|
||||
DES_SPtrans[5][(t >> 18L) & 0x3f] ^ DES_SPtrans[7][(t >> 26L) & 0x3f]; \
|
||||
} while (0)
|
||||
|
||||
#define ITERATIONS 16
|
||||
#define HALF_ITERATIONS 8
|
||||
OPENSSL_EXPORT void DES_encrypt3(uint32_t data[2], const DES_key_schedule *ks1,
|
||||
const DES_key_schedule *ks2,
|
||||
const DES_key_schedule *ks3);
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -533,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) {
|
||||
@@ -947,12 +934,7 @@ err:
|
||||
|
||||
int DSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_unused *unused,
|
||||
CRYPTO_EX_dup *dup_unused, CRYPTO_EX_free *free_func) {
|
||||
int index;
|
||||
if (!CRYPTO_get_ex_new_index(&g_ex_data_class, &index, argl, argp,
|
||||
free_func)) {
|
||||
return -1;
|
||||
}
|
||||
return index;
|
||||
return CRYPTO_get_ex_new_index_ex(&g_ex_data_class, argl, argp, free_func);
|
||||
}
|
||||
|
||||
int DSA_set_ex_data(DSA *dsa, int idx, void *arg) {
|
||||
|
||||
@@ -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,8 +169,7 @@ 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,
|
||||
@@ -221,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;
|
||||
@@ -235,7 +231,7 @@ OPENSSL_UNUSED static int is_3mod4(const EC_GROUP *group) {
|
||||
}
|
||||
|
||||
// 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,
|
||||
@@ -270,8 +266,7 @@ 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_JACOBIAN *out,
|
||||
@@ -405,7 +400,7 @@ int ec_hash_to_curve_p256_xmd_sha256_sswu(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-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;
|
||||
@@ -438,7 +433,7 @@ int ec_hash_to_curve_p384_xmd_sha384_sswu(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-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;
|
||||
|
||||
@@ -30,24 +30,22 @@ extern "C" {
|
||||
|
||||
// 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_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_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);
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -428,50 +428,52 @@ static const char *err_string_lookup(uint32_t lib, uint32_t key,
|
||||
return &string_data[(*result) & 0x7fff];
|
||||
}
|
||||
|
||||
static const char *const kLibraryNames[ERR_NUM_LIBS] = {
|
||||
"invalid library (0)",
|
||||
"unknown library", // ERR_LIB_NONE
|
||||
"system library", // ERR_LIB_SYS
|
||||
"bignum routines", // ERR_LIB_BN
|
||||
"RSA routines", // ERR_LIB_RSA
|
||||
"Diffie-Hellman routines", // ERR_LIB_DH
|
||||
"public key routines", // ERR_LIB_EVP
|
||||
"memory buffer routines", // ERR_LIB_BUF
|
||||
"object identifier routines", // ERR_LIB_OBJ
|
||||
"PEM routines", // ERR_LIB_PEM
|
||||
"DSA routines", // ERR_LIB_DSA
|
||||
"X.509 certificate routines", // ERR_LIB_X509
|
||||
"ASN.1 encoding routines", // ERR_LIB_ASN1
|
||||
"configuration file routines", // ERR_LIB_CONF
|
||||
"common libcrypto routines", // ERR_LIB_CRYPTO
|
||||
"elliptic curve routines", // ERR_LIB_EC
|
||||
"SSL routines", // ERR_LIB_SSL
|
||||
"BIO routines", // ERR_LIB_BIO
|
||||
"PKCS7 routines", // ERR_LIB_PKCS7
|
||||
"PKCS8 routines", // ERR_LIB_PKCS8
|
||||
"X509 V3 routines", // ERR_LIB_X509V3
|
||||
"random number generator", // ERR_LIB_RAND
|
||||
"ENGINE routines", // ERR_LIB_ENGINE
|
||||
"OCSP routines", // ERR_LIB_OCSP
|
||||
"UI routines", // ERR_LIB_UI
|
||||
"COMP routines", // ERR_LIB_COMP
|
||||
"ECDSA routines", // ERR_LIB_ECDSA
|
||||
"ECDH routines", // ERR_LIB_ECDH
|
||||
"HMAC routines", // ERR_LIB_HMAC
|
||||
"Digest functions", // ERR_LIB_DIGEST
|
||||
"Cipher functions", // ERR_LIB_CIPHER
|
||||
"HKDF functions", // ERR_LIB_HKDF
|
||||
"Trust Token functions", // ERR_LIB_TRUST_TOKEN
|
||||
"User defined functions", // ERR_LIB_USER
|
||||
typedef struct library_name_st {
|
||||
const char *str;
|
||||
const char *symbol;
|
||||
const char *reason_symbol;
|
||||
} LIBRARY_NAME;
|
||||
|
||||
static const LIBRARY_NAME kLibraryNames[ERR_NUM_LIBS] = {
|
||||
{"invalid library (0)", NULL, NULL},
|
||||
{"unknown library", "NONE", "NONE_LIB"},
|
||||
{"system library", "SYS", "SYS_LIB"},
|
||||
{"bignum routines", "BN", "BN_LIB"},
|
||||
{"RSA routines", "RSA", "RSA_LIB"},
|
||||
{"Diffie-Hellman routines", "DH", "DH_LIB"},
|
||||
{"public key routines", "EVP", "EVP_LIB"},
|
||||
{"memory buffer routines", "BUF", "BUF_LIB"},
|
||||
{"object identifier routines", "OBJ", "OBJ_LIB"},
|
||||
{"PEM routines", "PEM", "PEM_LIB"},
|
||||
{"DSA routines", "DSA", "DSA_LIB"},
|
||||
{"X.509 certificate routines", "X509", "X509_LIB"},
|
||||
{"ASN.1 encoding routines", "ASN1", "ASN1_LIB"},
|
||||
{"configuration file routines", "CONF", "CONF_LIB"},
|
||||
{"common libcrypto routines", "CRYPTO", "CRYPTO_LIB"},
|
||||
{"elliptic curve routines", "EC", "EC_LIB"},
|
||||
{"SSL routines", "SSL", "SSL_LIB"},
|
||||
{"BIO routines", "BIO", "BIO_LIB"},
|
||||
{"PKCS7 routines", "PKCS7", "PKCS7_LIB"},
|
||||
{"PKCS8 routines", "PKCS8", "PKCS8_LIB"},
|
||||
{"X509 V3 routines", "X509V3", "X509V3_LIB"},
|
||||
{"random number generator", "RAND", "RAND_LIB"},
|
||||
{"ENGINE routines", "ENGINE", "ENGINE_LIB"},
|
||||
{"OCSP routines", "OCSP", "OCSP_LIB"},
|
||||
{"UI routines", "UI", "UI_LIB"},
|
||||
{"COMP routines", "COMP", "COMP_LIB"},
|
||||
{"ECDSA routines", "ECDSA", "ECDSA_LIB"},
|
||||
{"ECDH routines", "ECDH", "ECDH_LIB"},
|
||||
{"HMAC routines", "HMAC", "HMAC_LIB"},
|
||||
{"Digest functions", "DIGEST", "DIGEST_LIB"},
|
||||
{"Cipher functions", "CIPHER", "CIPHER_LIB"},
|
||||
{"HKDF functions", "HKDF", "HKDF_LIB"},
|
||||
{"Trust Token functions", "TRUST_TOKEN", "TRUST_TOKEN_LIB"},
|
||||
{"User defined functions", "USER", "USER_LIB"},
|
||||
};
|
||||
|
||||
static const char *err_lib_error_string(uint32_t packed_error) {
|
||||
const uint32_t lib = ERR_GET_LIB(packed_error);
|
||||
|
||||
if (lib >= ERR_NUM_LIBS) {
|
||||
return NULL;
|
||||
}
|
||||
return kLibraryNames[lib];
|
||||
return lib >= ERR_NUM_LIBS ? NULL : kLibraryNames[lib].str;
|
||||
}
|
||||
|
||||
const char *ERR_lib_error_string(uint32_t packed_error) {
|
||||
@@ -479,51 +481,67 @@ const char *ERR_lib_error_string(uint32_t packed_error) {
|
||||
return ret == NULL ? "unknown library" : ret;
|
||||
}
|
||||
|
||||
const char *ERR_lib_symbol_name(uint32_t packed_error) {
|
||||
const uint32_t lib = ERR_GET_LIB(packed_error);
|
||||
return lib >= ERR_NUM_LIBS ? NULL : kLibraryNames[lib].symbol;
|
||||
}
|
||||
|
||||
const char *ERR_func_error_string(uint32_t packed_error) {
|
||||
return "OPENSSL_internal";
|
||||
}
|
||||
|
||||
static const char *err_reason_error_string(uint32_t packed_error) {
|
||||
static const char *err_reason_error_string(uint32_t packed_error, int symbol) {
|
||||
const uint32_t lib = ERR_GET_LIB(packed_error);
|
||||
const uint32_t reason = ERR_GET_REASON(packed_error);
|
||||
|
||||
if (lib == ERR_LIB_SYS) {
|
||||
if (reason < 127) {
|
||||
if (!symbol && reason < 127) {
|
||||
return strerror(reason);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (reason < ERR_NUM_LIBS) {
|
||||
return kLibraryNames[reason];
|
||||
return symbol ? kLibraryNames[reason].reason_symbol
|
||||
: kLibraryNames[reason].str;
|
||||
}
|
||||
|
||||
if (reason < 100) {
|
||||
// TODO(davidben): All our other reason strings match the symbol name. Only
|
||||
// the common ones differ. Should we just consistently return the symbol
|
||||
// name?
|
||||
switch (reason) {
|
||||
case ERR_R_MALLOC_FAILURE:
|
||||
return "malloc failure";
|
||||
return symbol ? "MALLOC_FAILURE" : "malloc failure";
|
||||
case ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED:
|
||||
return "function should not have been called";
|
||||
return symbol ? "SHOULD_NOT_HAVE_BEEN_CALLED"
|
||||
: "function should not have been called";
|
||||
case ERR_R_PASSED_NULL_PARAMETER:
|
||||
return "passed a null parameter";
|
||||
return symbol ? "PASSED_NULL_PARAMETER" : "passed a null parameter";
|
||||
case ERR_R_INTERNAL_ERROR:
|
||||
return "internal error";
|
||||
return symbol ? "INTERNAL_ERROR" : "internal error";
|
||||
case ERR_R_OVERFLOW:
|
||||
return "overflow";
|
||||
return symbol ? "OVERFLOW" : "overflow";
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// Unlike OpenSSL, BoringSSL's reason strings already match symbol name, so we
|
||||
// do not need to check |symbol|.
|
||||
return err_string_lookup(lib, reason, kOpenSSLReasonValues,
|
||||
kOpenSSLReasonValuesLen, kOpenSSLReasonStringData);
|
||||
}
|
||||
|
||||
const char *ERR_reason_error_string(uint32_t packed_error) {
|
||||
const char *ret = err_reason_error_string(packed_error);
|
||||
const char *ret = err_reason_error_string(packed_error, /*symbol=*/0);
|
||||
return ret == NULL ? "unknown error" : ret;
|
||||
}
|
||||
|
||||
const char *ERR_reason_symbol_name(uint32_t packed_error) {
|
||||
return err_reason_error_string(packed_error, /*symbol=*/1);
|
||||
}
|
||||
|
||||
char *ERR_error_string(uint32_t packed_error, char *ret) {
|
||||
static char buf[ERR_ERROR_STRING_BUF_LEN];
|
||||
|
||||
@@ -550,7 +568,7 @@ char *ERR_error_string_n(uint32_t packed_error, char *buf, size_t len) {
|
||||
unsigned reason = ERR_GET_REASON(packed_error);
|
||||
|
||||
const char *lib_str = err_lib_error_string(packed_error);
|
||||
const char *reason_str = err_reason_error_string(packed_error);
|
||||
const char *reason_str = err_reason_error_string(packed_error, /*symbol=*/0);
|
||||
|
||||
char lib_buf[32], reason_buf[32];
|
||||
if (lib_str == NULL) {
|
||||
|
||||
@@ -81,7 +81,7 @@ const uint32_t kOpenSSLReasonValues[] = {
|
||||
0x10339666,
|
||||
0x10341679,
|
||||
0x10348f93,
|
||||
0x10350ccc,
|
||||
0x10350cdf,
|
||||
0x1035968c,
|
||||
0x103616b6,
|
||||
0x103696c9,
|
||||
@@ -103,7 +103,7 @@ const uint32_t kOpenSSLReasonValues[] = {
|
||||
0x103e9839,
|
||||
0x103f1850,
|
||||
0x103f9863,
|
||||
0x10400c90,
|
||||
0x10400ca3,
|
||||
0x10409876,
|
||||
0x10411894,
|
||||
0x104198a7,
|
||||
@@ -125,11 +125,12 @@ const uint32_t kOpenSSLReasonValues[] = {
|
||||
0x104997d7,
|
||||
0x104a16a1,
|
||||
0x14320c73,
|
||||
0x14328c81,
|
||||
0x14330c90,
|
||||
0x14338ca2,
|
||||
0x14328c94,
|
||||
0x14330ca3,
|
||||
0x14338cb5,
|
||||
0x143400b9,
|
||||
0x143480f7,
|
||||
0x14350c81,
|
||||
0x18320090,
|
||||
0x18328fe9,
|
||||
0x183300b9,
|
||||
@@ -163,7 +164,7 @@ const uint32_t kOpenSSLReasonValues[] = {
|
||||
0x18411164,
|
||||
0x1841912f,
|
||||
0x1842114e,
|
||||
0x18428cd8,
|
||||
0x18428c81,
|
||||
0x1843110a,
|
||||
0x18439176,
|
||||
0x18441028,
|
||||
@@ -185,60 +186,60 @@ const uint32_t kOpenSSLReasonValues[] = {
|
||||
0x2438133b,
|
||||
0x24389348,
|
||||
0x2439135b,
|
||||
0x28320cc0,
|
||||
0x28320cd3,
|
||||
0x28328ceb,
|
||||
0x28330c90,
|
||||
0x28330ca3,
|
||||
0x28338cfe,
|
||||
0x28340ccc,
|
||||
0x28340cdf,
|
||||
0x283480b9,
|
||||
0x283500f7,
|
||||
0x28358cd8,
|
||||
0x28358c81,
|
||||
0x2836099a,
|
||||
0x2c3232d0,
|
||||
0x2c3232e7,
|
||||
0x2c329372,
|
||||
0x2c3332de,
|
||||
0x2c33b2f0,
|
||||
0x2c343304,
|
||||
0x2c34b316,
|
||||
0x2c353331,
|
||||
0x2c35b343,
|
||||
0x2c363373,
|
||||
0x2c3332f5,
|
||||
0x2c33b307,
|
||||
0x2c34331b,
|
||||
0x2c34b32d,
|
||||
0x2c353348,
|
||||
0x2c35b35a,
|
||||
0x2c36338a,
|
||||
0x2c36833a,
|
||||
0x2c373380,
|
||||
0x2c37b3ac,
|
||||
0x2c3833ea,
|
||||
0x2c38b401,
|
||||
0x2c39341f,
|
||||
0x2c39b42f,
|
||||
0x2c3a3441,
|
||||
0x2c3ab455,
|
||||
0x2c3b3466,
|
||||
0x2c3bb485,
|
||||
0x2c373397,
|
||||
0x2c37b3c3,
|
||||
0x2c383401,
|
||||
0x2c38b418,
|
||||
0x2c393436,
|
||||
0x2c39b446,
|
||||
0x2c3a3458,
|
||||
0x2c3ab46c,
|
||||
0x2c3b347d,
|
||||
0x2c3bb49c,
|
||||
0x2c3c1384,
|
||||
0x2c3c939a,
|
||||
0x2c3d34ca,
|
||||
0x2c3d34e1,
|
||||
0x2c3d93b3,
|
||||
0x2c3e34f4,
|
||||
0x2c3eb502,
|
||||
0x2c3f351a,
|
||||
0x2c3fb532,
|
||||
0x2c40355c,
|
||||
0x2c3e350b,
|
||||
0x2c3eb519,
|
||||
0x2c3f3531,
|
||||
0x2c3fb549,
|
||||
0x2c403573,
|
||||
0x2c409285,
|
||||
0x2c41356d,
|
||||
0x2c41b580,
|
||||
0x2c413584,
|
||||
0x2c41b597,
|
||||
0x2c42124b,
|
||||
0x2c42b591,
|
||||
0x2c42b5a8,
|
||||
0x2c43076d,
|
||||
0x2c43b477,
|
||||
0x2c4433bf,
|
||||
0x2c44b53f,
|
||||
0x2c453356,
|
||||
0x2c45b392,
|
||||
0x2c46340f,
|
||||
0x2c46b499,
|
||||
0x2c4734ae,
|
||||
0x2c47b4e7,
|
||||
0x2c4833d1,
|
||||
0x2c43b48e,
|
||||
0x2c4433d6,
|
||||
0x2c44b556,
|
||||
0x2c45336d,
|
||||
0x2c45b3a9,
|
||||
0x2c463426,
|
||||
0x2c46b4b0,
|
||||
0x2c4734c5,
|
||||
0x2c47b4fe,
|
||||
0x2c4833e8,
|
||||
0x30320000,
|
||||
0x30328015,
|
||||
0x3033001f,
|
||||
@@ -436,202 +437,203 @@ const uint32_t kOpenSSLReasonValues[] = {
|
||||
0x404da092,
|
||||
0x404e20a6,
|
||||
0x404ea0b3,
|
||||
0x404f214d,
|
||||
0x404fa1c3,
|
||||
0x40502232,
|
||||
0x4050a246,
|
||||
0x40512279,
|
||||
0x40522289,
|
||||
0x4052a2ad,
|
||||
0x405322c5,
|
||||
0x4053a2d8,
|
||||
0x405422ed,
|
||||
0x4054a310,
|
||||
0x4055233b,
|
||||
0x4055a378,
|
||||
0x4056239d,
|
||||
0x4056a3b6,
|
||||
0x405723ce,
|
||||
0x4057a3e1,
|
||||
0x405823f6,
|
||||
0x4058a41d,
|
||||
0x4059244c,
|
||||
0x4059a479,
|
||||
0x405aa48d,
|
||||
0x405b24a5,
|
||||
0x405ba4b6,
|
||||
0x405c24c9,
|
||||
0x405ca508,
|
||||
0x405d2515,
|
||||
0x405da53a,
|
||||
0x405e2578,
|
||||
0x404f2164,
|
||||
0x404fa1da,
|
||||
0x40502249,
|
||||
0x4050a25d,
|
||||
0x40512290,
|
||||
0x405222a0,
|
||||
0x4052a2c4,
|
||||
0x405322dc,
|
||||
0x4053a2ef,
|
||||
0x40542304,
|
||||
0x4054a327,
|
||||
0x40552352,
|
||||
0x4055a38f,
|
||||
0x405623b4,
|
||||
0x4056a3cd,
|
||||
0x405723e5,
|
||||
0x4057a3f8,
|
||||
0x4058240d,
|
||||
0x4058a434,
|
||||
0x40592463,
|
||||
0x4059a490,
|
||||
0x405aa4a4,
|
||||
0x405b24bc,
|
||||
0x405ba4cd,
|
||||
0x405c24e0,
|
||||
0x405ca51f,
|
||||
0x405d252c,
|
||||
0x405da551,
|
||||
0x405e258f,
|
||||
0x405e8afe,
|
||||
0x405f2599,
|
||||
0x405fa5a6,
|
||||
0x406025b4,
|
||||
0x4060a5d6,
|
||||
0x40612637,
|
||||
0x4061a66f,
|
||||
0x40622686,
|
||||
0x4062a697,
|
||||
0x406326e4,
|
||||
0x4063a6f9,
|
||||
0x40642710,
|
||||
0x4064a73c,
|
||||
0x40652757,
|
||||
0x4065a76e,
|
||||
0x40662786,
|
||||
0x4066a7b0,
|
||||
0x406727db,
|
||||
0x4067a820,
|
||||
0x40682868,
|
||||
0x4068a889,
|
||||
0x406928bb,
|
||||
0x4069a8e9,
|
||||
0x406a290a,
|
||||
0x406aa92a,
|
||||
0x406b2ab2,
|
||||
0x406baad5,
|
||||
0x406c2aeb,
|
||||
0x406cadf5,
|
||||
0x406d2e24,
|
||||
0x406dae4c,
|
||||
0x406e2e7a,
|
||||
0x406eaec7,
|
||||
0x406f2f20,
|
||||
0x406faf58,
|
||||
0x40702f6b,
|
||||
0x4070af88,
|
||||
0x405f25b0,
|
||||
0x405fa5bd,
|
||||
0x406025cb,
|
||||
0x4060a5ed,
|
||||
0x4061264e,
|
||||
0x4061a686,
|
||||
0x4062269d,
|
||||
0x4062a6ae,
|
||||
0x406326fb,
|
||||
0x4063a710,
|
||||
0x40642727,
|
||||
0x4064a753,
|
||||
0x4065276e,
|
||||
0x4065a785,
|
||||
0x4066279d,
|
||||
0x4066a7c7,
|
||||
0x406727f2,
|
||||
0x4067a837,
|
||||
0x4068287f,
|
||||
0x4068a8a0,
|
||||
0x406928d2,
|
||||
0x4069a900,
|
||||
0x406a2921,
|
||||
0x406aa941,
|
||||
0x406b2ac9,
|
||||
0x406baaec,
|
||||
0x406c2b02,
|
||||
0x406cae0c,
|
||||
0x406d2e3b,
|
||||
0x406dae63,
|
||||
0x406e2e91,
|
||||
0x406eaede,
|
||||
0x406f2f37,
|
||||
0x406faf6f,
|
||||
0x40702f82,
|
||||
0x4070af9f,
|
||||
0x4071084d,
|
||||
0x4071af9a,
|
||||
0x40722fad,
|
||||
0x4072afe3,
|
||||
0x40732ffb,
|
||||
0x4071afb1,
|
||||
0x40722fc4,
|
||||
0x4072affa,
|
||||
0x40733012,
|
||||
0x4073959c,
|
||||
0x4074300f,
|
||||
0x4074b029,
|
||||
0x4075303a,
|
||||
0x4075b04e,
|
||||
0x4076305c,
|
||||
0x40743026,
|
||||
0x4074b040,
|
||||
0x40753051,
|
||||
0x4075b065,
|
||||
0x40763073,
|
||||
0x40769348,
|
||||
0x40773081,
|
||||
0x4077b0c1,
|
||||
0x407830dc,
|
||||
0x4078b115,
|
||||
0x4079312c,
|
||||
0x4079b142,
|
||||
0x407a316e,
|
||||
0x407ab181,
|
||||
0x407b3196,
|
||||
0x407bb1a8,
|
||||
0x407c31d9,
|
||||
0x407cb1e2,
|
||||
0x407d28a4,
|
||||
0x407da1eb,
|
||||
0x407e30f1,
|
||||
0x407ea42d,
|
||||
0x40773098,
|
||||
0x4077b0d8,
|
||||
0x407830f3,
|
||||
0x4078b12c,
|
||||
0x40793143,
|
||||
0x4079b159,
|
||||
0x407a3185,
|
||||
0x407ab198,
|
||||
0x407b31ad,
|
||||
0x407bb1bf,
|
||||
0x407c31f0,
|
||||
0x407cb1f9,
|
||||
0x407d28bb,
|
||||
0x407da202,
|
||||
0x407e3108,
|
||||
0x407ea444,
|
||||
0x407f1e27,
|
||||
0x407f9ffa,
|
||||
0x4080215d,
|
||||
0x40802174,
|
||||
0x40809e4f,
|
||||
0x4081229b,
|
||||
0x408122b2,
|
||||
0x4081a101,
|
||||
0x40822e65,
|
||||
0x40822e7c,
|
||||
0x40829ba2,
|
||||
0x40832408,
|
||||
0x4083a721,
|
||||
0x4083241f,
|
||||
0x4083a738,
|
||||
0x40841e63,
|
||||
0x4084a465,
|
||||
0x408524da,
|
||||
0x4085a5fe,
|
||||
0x4086255a,
|
||||
0x4086a205,
|
||||
0x40872eab,
|
||||
0x4087a64c,
|
||||
0x4084a47c,
|
||||
0x408524f1,
|
||||
0x4085a615,
|
||||
0x40862571,
|
||||
0x4086a21c,
|
||||
0x40872ec2,
|
||||
0x4087a663,
|
||||
0x40881be0,
|
||||
0x4088a833,
|
||||
0x4088a84a,
|
||||
0x40891c2f,
|
||||
0x40899bbc,
|
||||
0x408a2b23,
|
||||
0x408a2b3a,
|
||||
0x408a99b4,
|
||||
0x408b31bd,
|
||||
0x408baf35,
|
||||
0x408c24ea,
|
||||
0x408b31d4,
|
||||
0x408baf4c,
|
||||
0x408c2501,
|
||||
0x408c99ec,
|
||||
0x408d1f4b,
|
||||
0x408d9e95,
|
||||
0x408e207b,
|
||||
0x408ea358,
|
||||
0x408f2847,
|
||||
0x408fa61a,
|
||||
0x409027fc,
|
||||
0x4090a52c,
|
||||
0x40912b0b,
|
||||
0x408ea36f,
|
||||
0x408f285e,
|
||||
0x408fa631,
|
||||
0x40902813,
|
||||
0x4090a543,
|
||||
0x40912b22,
|
||||
0x40919a12,
|
||||
0x40921c7c,
|
||||
0x4092aee6,
|
||||
0x40932fc6,
|
||||
0x4093a216,
|
||||
0x4092aefd,
|
||||
0x40932fdd,
|
||||
0x4093a22d,
|
||||
0x40941e77,
|
||||
0x4094ab3c,
|
||||
0x409526a8,
|
||||
0x4095b14e,
|
||||
0x40962e92,
|
||||
0x4096a176,
|
||||
0x40972261,
|
||||
0x4094ab53,
|
||||
0x409526bf,
|
||||
0x4095b165,
|
||||
0x40962ea9,
|
||||
0x4096a18d,
|
||||
0x40972278,
|
||||
0x4097a0ca,
|
||||
0x40981cdc,
|
||||
0x4098a6bc,
|
||||
0x40992f02,
|
||||
0x4099a385,
|
||||
0x409a231e,
|
||||
0x4098a6d3,
|
||||
0x40992f19,
|
||||
0x4099a39c,
|
||||
0x409a2335,
|
||||
0x409a99d0,
|
||||
0x409b1ed1,
|
||||
0x409b9efc,
|
||||
0x409c30a3,
|
||||
0x409c30ba,
|
||||
0x409c9f24,
|
||||
0x409d2132,
|
||||
0x409d2149,
|
||||
0x409da117,
|
||||
0x409e1d6d,
|
||||
0x409ea1ab,
|
||||
0x409f2193,
|
||||
0x409ea1c2,
|
||||
0x409f21aa,
|
||||
0x409f9ec4,
|
||||
0x40a021d3,
|
||||
0x40a021ea,
|
||||
0x40a0a0e4,
|
||||
0x41f429dd,
|
||||
0x41f92a6f,
|
||||
0x41fe2962,
|
||||
0x41feac18,
|
||||
0x41ff2d46,
|
||||
0x420329f6,
|
||||
0x42082a18,
|
||||
0x4208aa54,
|
||||
0x42092946,
|
||||
0x4209aa8e,
|
||||
0x420a299d,
|
||||
0x420aa97d,
|
||||
0x420b29bd,
|
||||
0x420baa36,
|
||||
0x420c2d62,
|
||||
0x420cab4c,
|
||||
0x420d2bff,
|
||||
0x420dac36,
|
||||
0x42122c69,
|
||||
0x42172d29,
|
||||
0x4217acab,
|
||||
0x421c2ccd,
|
||||
0x421f2c88,
|
||||
0x42212dda,
|
||||
0x42262d0c,
|
||||
0x422b2db8,
|
||||
0x422babda,
|
||||
0x422c2d9a,
|
||||
0x422cab8d,
|
||||
0x422d2b66,
|
||||
0x422dad79,
|
||||
0x422e2bb9,
|
||||
0x42302ce8,
|
||||
0x4230ac50,
|
||||
0x40a12132,
|
||||
0x41f429f4,
|
||||
0x41f92a86,
|
||||
0x41fe2979,
|
||||
0x41feac2f,
|
||||
0x41ff2d5d,
|
||||
0x42032a0d,
|
||||
0x42082a2f,
|
||||
0x4208aa6b,
|
||||
0x4209295d,
|
||||
0x4209aaa5,
|
||||
0x420a29b4,
|
||||
0x420aa994,
|
||||
0x420b29d4,
|
||||
0x420baa4d,
|
||||
0x420c2d79,
|
||||
0x420cab63,
|
||||
0x420d2c16,
|
||||
0x420dac4d,
|
||||
0x42122c80,
|
||||
0x42172d40,
|
||||
0x4217acc2,
|
||||
0x421c2ce4,
|
||||
0x421f2c9f,
|
||||
0x42212df1,
|
||||
0x42262d23,
|
||||
0x422b2dcf,
|
||||
0x422babf1,
|
||||
0x422c2db1,
|
||||
0x422caba4,
|
||||
0x422d2b7d,
|
||||
0x422dad90,
|
||||
0x422e2bd0,
|
||||
0x42302cff,
|
||||
0x4230ac67,
|
||||
0x44320778,
|
||||
0x44328787,
|
||||
0x44330793,
|
||||
@@ -676,7 +678,7 @@ const uint32_t kOpenSSLReasonValues[] = {
|
||||
0x4c3c1574,
|
||||
0x4c3c9583,
|
||||
0x4c3d159c,
|
||||
0x4c3d8cb3,
|
||||
0x4c3d8cc6,
|
||||
0x4c3e1609,
|
||||
0x4c3e95ab,
|
||||
0x4c3f162b,
|
||||
@@ -687,71 +689,71 @@ const uint32_t kOpenSSLReasonValues[] = {
|
||||
0x4c41947c,
|
||||
0x4c4215e5,
|
||||
0x4c4293c4,
|
||||
0x503235a3,
|
||||
0x5032b5b2,
|
||||
0x503335bd,
|
||||
0x5033b5cd,
|
||||
0x503435e6,
|
||||
0x5034b600,
|
||||
0x5035360e,
|
||||
0x5035b624,
|
||||
0x50363636,
|
||||
0x5036b64c,
|
||||
0x50373665,
|
||||
0x5037b678,
|
||||
0x50383690,
|
||||
0x5038b6a1,
|
||||
0x503936b6,
|
||||
0x5039b6ca,
|
||||
0x503a36ea,
|
||||
0x503ab700,
|
||||
0x503b3718,
|
||||
0x503bb72a,
|
||||
0x503c3746,
|
||||
0x503cb75d,
|
||||
0x503d3776,
|
||||
0x503db78c,
|
||||
0x503e3799,
|
||||
0x503eb7af,
|
||||
0x503f37c1,
|
||||
0x503235ba,
|
||||
0x5032b5c9,
|
||||
0x503335d4,
|
||||
0x5033b5e4,
|
||||
0x503435fd,
|
||||
0x5034b617,
|
||||
0x50353625,
|
||||
0x5035b63b,
|
||||
0x5036364d,
|
||||
0x5036b663,
|
||||
0x5037367c,
|
||||
0x5037b68f,
|
||||
0x503836a7,
|
||||
0x5038b6b8,
|
||||
0x503936cd,
|
||||
0x5039b6e1,
|
||||
0x503a3701,
|
||||
0x503ab717,
|
||||
0x503b372f,
|
||||
0x503bb741,
|
||||
0x503c375d,
|
||||
0x503cb774,
|
||||
0x503d378d,
|
||||
0x503db7a3,
|
||||
0x503e37b0,
|
||||
0x503eb7c6,
|
||||
0x503f37d8,
|
||||
0x503f83b3,
|
||||
0x504037d4,
|
||||
0x5040b7e4,
|
||||
0x504137fe,
|
||||
0x5041b80d,
|
||||
0x50423827,
|
||||
0x5042b844,
|
||||
0x50433854,
|
||||
0x5043b864,
|
||||
0x50443881,
|
||||
0x504037eb,
|
||||
0x5040b7fb,
|
||||
0x50413815,
|
||||
0x5041b824,
|
||||
0x5042383e,
|
||||
0x5042b85b,
|
||||
0x5043386b,
|
||||
0x5043b87b,
|
||||
0x50443898,
|
||||
0x50448469,
|
||||
0x50453895,
|
||||
0x5045b8b3,
|
||||
0x504638c6,
|
||||
0x5046b8dc,
|
||||
0x504738ee,
|
||||
0x5047b903,
|
||||
0x50483929,
|
||||
0x5048b937,
|
||||
0x5049394a,
|
||||
0x5049b95f,
|
||||
0x504a3975,
|
||||
0x504ab985,
|
||||
0x504b39a5,
|
||||
0x504bb9b8,
|
||||
0x504c39db,
|
||||
0x504cba09,
|
||||
0x504d3a36,
|
||||
0x504dba53,
|
||||
0x504e3a6e,
|
||||
0x504eba8a,
|
||||
0x504f3a9c,
|
||||
0x504fbab3,
|
||||
0x50503ac2,
|
||||
0x504538ac,
|
||||
0x5045b8ca,
|
||||
0x504638dd,
|
||||
0x5046b8f3,
|
||||
0x50473905,
|
||||
0x5047b91a,
|
||||
0x50483940,
|
||||
0x5048b94e,
|
||||
0x50493961,
|
||||
0x5049b976,
|
||||
0x504a398c,
|
||||
0x504ab99c,
|
||||
0x504b39bc,
|
||||
0x504bb9cf,
|
||||
0x504c39f2,
|
||||
0x504cba20,
|
||||
0x504d3a4d,
|
||||
0x504dba6a,
|
||||
0x504e3a85,
|
||||
0x504ebaa1,
|
||||
0x504f3ab3,
|
||||
0x504fbaca,
|
||||
0x50503ad9,
|
||||
0x50508729,
|
||||
0x50513ad5,
|
||||
0x5051b873,
|
||||
0x50523a1b,
|
||||
0x50513aec,
|
||||
0x5051b88a,
|
||||
0x50523a32,
|
||||
0x58320fd1,
|
||||
0x68320f93,
|
||||
0x68328ceb,
|
||||
@@ -761,12 +763,12 @@ const uint32_t kOpenSSLReasonValues[] = {
|
||||
0x683480f7,
|
||||
0x6835099a,
|
||||
0x6c320f59,
|
||||
0x6c328ca2,
|
||||
0x6c328cb5,
|
||||
0x6c330f64,
|
||||
0x6c338f7d,
|
||||
0x74320a66,
|
||||
0x743280b9,
|
||||
0x74330cb3,
|
||||
0x74330cc6,
|
||||
0x783209cb,
|
||||
0x783289e0,
|
||||
0x783309ec,
|
||||
@@ -796,19 +798,19 @@ const uint32_t kOpenSSLReasonValues[] = {
|
||||
0x7c321261,
|
||||
0x8032148f,
|
||||
0x80328090,
|
||||
0x8033329f,
|
||||
0x803332b6,
|
||||
0x803380b9,
|
||||
0x803432ae,
|
||||
0x8034b216,
|
||||
0x80353234,
|
||||
0x8035b2c2,
|
||||
0x80363276,
|
||||
0x8036b225,
|
||||
0x80373268,
|
||||
0x8037b203,
|
||||
0x80383289,
|
||||
0x8038b245,
|
||||
0x8039325a,
|
||||
0x803432c5,
|
||||
0x8034b22d,
|
||||
0x8035324b,
|
||||
0x8035b2d9,
|
||||
0x8036328d,
|
||||
0x8036b23c,
|
||||
0x8037327f,
|
||||
0x8037b21a,
|
||||
0x803832a0,
|
||||
0x8038b25c,
|
||||
0x80393271,
|
||||
};
|
||||
|
||||
const size_t kOpenSSLReasonValuesLen = sizeof(kOpenSSLReasonValues) / sizeof(kOpenSSLReasonValues[0]);
|
||||
@@ -981,13 +983,13 @@ const char kOpenSSLReasonStringData[] =
|
||||
"VARIABLE_EXPANSION_TOO_LONG\0"
|
||||
"VARIABLE_HAS_NO_VALUE\0"
|
||||
"BAD_GENERATOR\0"
|
||||
"INVALID_PARAMETERS\0"
|
||||
"INVALID_PUBKEY\0"
|
||||
"MODULUS_TOO_LARGE\0"
|
||||
"NO_PRIVATE_VALUE\0"
|
||||
"UNKNOWN_HASH\0"
|
||||
"BAD_Q_VALUE\0"
|
||||
"BAD_VERSION\0"
|
||||
"INVALID_PARAMETERS\0"
|
||||
"MISSING_PARAMETERS\0"
|
||||
"NEED_NEW_SETUP_VALUES\0"
|
||||
"BIGNUM_OUT_OF_RANGE\0"
|
||||
@@ -1229,6 +1231,7 @@ const char kOpenSSLReasonStringData[] =
|
||||
"INCONSISTENT_ECH_NEGOTIATION\0"
|
||||
"INVALID_ALPN_PROTOCOL\0"
|
||||
"INVALID_ALPN_PROTOCOL_LIST\0"
|
||||
"INVALID_ALPS_CODEPOINT\0"
|
||||
"INVALID_CLIENT_HELLO_INNER\0"
|
||||
"INVALID_COMMAND\0"
|
||||
"INVALID_COMPRESSION_LIST\0"
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -80,15 +80,12 @@ typedef struct {
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -132,11 +132,11 @@ struct crypto_ex_data_func_st {
|
||||
CRYPTO_EX_DATA_FUNCS *next;
|
||||
};
|
||||
|
||||
int CRYPTO_get_ex_new_index(CRYPTO_EX_DATA_CLASS *ex_data_class, int *out_index,
|
||||
long argl, void *argp, CRYPTO_EX_free *free_func) {
|
||||
int CRYPTO_get_ex_new_index_ex(CRYPTO_EX_DATA_CLASS *ex_data_class, long argl,
|
||||
void *argp, CRYPTO_EX_free *free_func) {
|
||||
CRYPTO_EX_DATA_FUNCS *funcs = OPENSSL_malloc(sizeof(CRYPTO_EX_DATA_FUNCS));
|
||||
if (funcs == NULL) {
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
funcs->argl = argl;
|
||||
@@ -151,7 +151,7 @@ int CRYPTO_get_ex_new_index(CRYPTO_EX_DATA_CLASS *ex_data_class, int *out_index,
|
||||
if (num_funcs > (size_t)(INT_MAX - ex_data_class->num_reserved)) {
|
||||
OPENSSL_PUT_ERROR(CRYPTO, ERR_R_OVERFLOW);
|
||||
CRYPTO_MUTEX_unlock_write(&ex_data_class->lock);
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Append |funcs| to the linked list.
|
||||
@@ -166,8 +166,7 @@ int CRYPTO_get_ex_new_index(CRYPTO_EX_DATA_CLASS *ex_data_class, int *out_index,
|
||||
|
||||
CRYPTO_atomic_store_u32(&ex_data_class->num_funcs, num_funcs + 1);
|
||||
CRYPTO_MUTEX_unlock_write(&ex_data_class->lock);
|
||||
*out_index = (int)num_funcs + ex_data_class->num_reserved;
|
||||
return 1;
|
||||
return (int)num_funcs + ex_data_class->num_reserved;
|
||||
}
|
||||
|
||||
int CRYPTO_set_ex_data(CRYPTO_EX_DATA *ad, int index, void *val) {
|
||||
@@ -215,7 +214,7 @@ void CRYPTO_free_ex_data(CRYPTO_EX_DATA_CLASS *ex_data_class, void *obj,
|
||||
}
|
||||
|
||||
uint32_t num_funcs = CRYPTO_atomic_load_u32(&ex_data_class->num_funcs);
|
||||
// |CRYPTO_get_ex_new_index| will not allocate indices beyond |INT_MAX|.
|
||||
// |CRYPTO_get_ex_new_index_ex| will not allocate indices beyond |INT_MAX|.
|
||||
assert(num_funcs <= (size_t)(INT_MAX - ex_data_class->num_reserved));
|
||||
|
||||
// Defer dereferencing |ex_data_class->funcs| and |funcs->next|. It must come
|
||||
|
||||
@@ -338,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
|
||||
@@ -468,7 +468,7 @@ _CET_ENDBR
|
||||
.cfi_adjust_cfa_offset -8
|
||||
.cfi_restore %rbp
|
||||
.Lgcm_dec_abort:
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
.cfi_endproc
|
||||
.size aesni_gcm_decrypt,.-aesni_gcm_decrypt
|
||||
@@ -539,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
|
||||
@@ -863,10 +863,10 @@ _CET_ENDBR
|
||||
.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:
|
||||
|
||||
@@ -338,7 +338,7 @@ L$6x_done:
|
||||
vpxor 16+8(%rsp),%xmm8,%xmm8
|
||||
vpxor %xmm4,%xmm8,%xmm8
|
||||
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aesni_gcm_decrypt
|
||||
@@ -461,7 +461,7 @@ L$dec_no_key_aliasing:
|
||||
popq %rbp
|
||||
|
||||
L$gcm_dec_abort:
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
|
||||
@@ -532,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
|
||||
@@ -848,7 +848,7 @@ L$enc_no_key_aliasing:
|
||||
popq %rbp
|
||||
|
||||
L$gcm_enc_abort:
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ _CET_ENDBR
|
||||
pxor %xmm1,%xmm1
|
||||
movups %xmm2,(%rsi)
|
||||
pxor %xmm2,%xmm2
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.size aes_hw_encrypt,.-aes_hw_encrypt
|
||||
|
||||
@@ -66,7 +66,7 @@ _CET_ENDBR
|
||||
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
|
||||
@@ -97,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
|
||||
@@ -128,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
|
||||
@@ -164,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
|
||||
@@ -200,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
|
||||
@@ -242,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
|
||||
@@ -284,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
|
||||
@@ -340,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
|
||||
@@ -396,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
|
||||
@@ -462,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
|
||||
@@ -528,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
|
||||
@@ -874,7 +874,7 @@ _CET_ENDBR
|
||||
.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
|
||||
@@ -973,10 +973,7 @@ _CET_ENDBR
|
||||
leaq 7(%r8),%r9
|
||||
movl %r10d,96+12(%rsp)
|
||||
bswapl %r9d
|
||||
leaq OPENSSL_ia32cap_P(%rip),%r10
|
||||
movl 4(%r10),%r10d
|
||||
xorl %ebp,%r9d
|
||||
andl $71303168,%r10d
|
||||
movl %r9d,112+12(%rsp)
|
||||
|
||||
movups 16(%rcx),%xmm1
|
||||
@@ -987,104 +984,10 @@ _CET_ENDBR
|
||||
cmpq $8,%rdx
|
||||
jb .Lctr32_tail
|
||||
|
||||
subq $6,%rdx
|
||||
cmpl $4194304,%r10d
|
||||
je .Lctr32_6x
|
||||
|
||||
leaq 128(%rcx),%rcx
|
||||
subq $2,%rdx
|
||||
subq $8,%rdx
|
||||
jmp .Lctr32_loop8
|
||||
|
||||
.align 16
|
||||
.Lctr32_6x:
|
||||
shll $4,%eax
|
||||
movl $48,%r10d
|
||||
bswapl %ebp
|
||||
leaq 32(%rcx,%rax,1),%rcx
|
||||
subq %rax,%r10
|
||||
jmp .Lctr32_loop6
|
||||
|
||||
.align 16
|
||||
.Lctr32_loop6:
|
||||
addl $6,%r8d
|
||||
movups -48(%rcx,%r10,1),%xmm0
|
||||
.byte 102,15,56,220,209
|
||||
movl %r8d,%eax
|
||||
xorl %ebp,%eax
|
||||
.byte 102,15,56,220,217
|
||||
.byte 0x0f,0x38,0xf1,0x44,0x24,12
|
||||
leal 1(%r8),%eax
|
||||
.byte 102,15,56,220,225
|
||||
xorl %ebp,%eax
|
||||
.byte 0x0f,0x38,0xf1,0x44,0x24,28
|
||||
.byte 102,15,56,220,233
|
||||
leal 2(%r8),%eax
|
||||
xorl %ebp,%eax
|
||||
.byte 102,15,56,220,241
|
||||
.byte 0x0f,0x38,0xf1,0x44,0x24,44
|
||||
leal 3(%r8),%eax
|
||||
.byte 102,15,56,220,249
|
||||
movups -32(%rcx,%r10,1),%xmm1
|
||||
xorl %ebp,%eax
|
||||
|
||||
.byte 102,15,56,220,208
|
||||
.byte 0x0f,0x38,0xf1,0x44,0x24,60
|
||||
leal 4(%r8),%eax
|
||||
.byte 102,15,56,220,216
|
||||
xorl %ebp,%eax
|
||||
.byte 0x0f,0x38,0xf1,0x44,0x24,76
|
||||
.byte 102,15,56,220,224
|
||||
leal 5(%r8),%eax
|
||||
xorl %ebp,%eax
|
||||
.byte 102,15,56,220,232
|
||||
.byte 0x0f,0x38,0xf1,0x44,0x24,92
|
||||
movq %r10,%rax
|
||||
.byte 102,15,56,220,240
|
||||
.byte 102,15,56,220,248
|
||||
movups -16(%rcx,%r10,1),%xmm0
|
||||
|
||||
call .Lenc_loop6
|
||||
|
||||
movdqu (%rdi),%xmm8
|
||||
movdqu 16(%rdi),%xmm9
|
||||
movdqu 32(%rdi),%xmm10
|
||||
movdqu 48(%rdi),%xmm11
|
||||
movdqu 64(%rdi),%xmm12
|
||||
movdqu 80(%rdi),%xmm13
|
||||
leaq 96(%rdi),%rdi
|
||||
movups -64(%rcx,%r10,1),%xmm1
|
||||
pxor %xmm2,%xmm8
|
||||
movaps 0(%rsp),%xmm2
|
||||
pxor %xmm3,%xmm9
|
||||
movaps 16(%rsp),%xmm3
|
||||
pxor %xmm4,%xmm10
|
||||
movaps 32(%rsp),%xmm4
|
||||
pxor %xmm5,%xmm11
|
||||
movaps 48(%rsp),%xmm5
|
||||
pxor %xmm6,%xmm12
|
||||
movaps 64(%rsp),%xmm6
|
||||
pxor %xmm7,%xmm13
|
||||
movaps 80(%rsp),%xmm7
|
||||
movdqu %xmm8,(%rsi)
|
||||
movdqu %xmm9,16(%rsi)
|
||||
movdqu %xmm10,32(%rsi)
|
||||
movdqu %xmm11,48(%rsi)
|
||||
movdqu %xmm12,64(%rsi)
|
||||
movdqu %xmm13,80(%rsi)
|
||||
leaq 96(%rsi),%rsi
|
||||
|
||||
subq $6,%rdx
|
||||
jnc .Lctr32_loop6
|
||||
|
||||
addq $6,%rdx
|
||||
jz .Lctr32_done
|
||||
|
||||
leal -48(%r10),%eax
|
||||
leaq -80(%rcx,%r10,1),%rcx
|
||||
negl %eax
|
||||
shrl $4,%eax
|
||||
jmp .Lctr32_tail
|
||||
|
||||
.align 32
|
||||
.Lctr32_loop8:
|
||||
addl $8,%r8d
|
||||
@@ -1460,7 +1363,7 @@ _CET_ENDBR
|
||||
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
|
||||
@@ -1586,16 +1489,10 @@ _CET_ENDBR
|
||||
movdqa %xmm5,%xmm14
|
||||
movdqu 80(%rdi),%xmm7
|
||||
movdqa %xmm6,%xmm15
|
||||
leaq OPENSSL_ia32cap_P(%rip),%r9
|
||||
movl 4(%r9),%r9d
|
||||
cmpq $0x70,%rdx
|
||||
jbe .Lcbc_dec_six_or_seven
|
||||
|
||||
andl $71303168,%r9d
|
||||
subq $0x50,%rdx
|
||||
cmpl $4194304,%r9d
|
||||
je .Lcbc_dec_loop6_enter
|
||||
subq $0x20,%rdx
|
||||
subq $0x70,%rdx
|
||||
leaq 112(%rcx),%rcx
|
||||
jmp .Lcbc_dec_loop8_enter
|
||||
.align 16
|
||||
@@ -1866,51 +1763,6 @@ _CET_ENDBR
|
||||
pxor %xmm9,%xmm9
|
||||
jmp .Lcbc_dec_tail_collected
|
||||
|
||||
.align 16
|
||||
.Lcbc_dec_loop6:
|
||||
movups %xmm7,(%rsi)
|
||||
leaq 16(%rsi),%rsi
|
||||
movdqu 0(%rdi),%xmm2
|
||||
movdqu 16(%rdi),%xmm3
|
||||
movdqa %xmm2,%xmm11
|
||||
movdqu 32(%rdi),%xmm4
|
||||
movdqa %xmm3,%xmm12
|
||||
movdqu 48(%rdi),%xmm5
|
||||
movdqa %xmm4,%xmm13
|
||||
movdqu 64(%rdi),%xmm6
|
||||
movdqa %xmm5,%xmm14
|
||||
movdqu 80(%rdi),%xmm7
|
||||
movdqa %xmm6,%xmm15
|
||||
.Lcbc_dec_loop6_enter:
|
||||
leaq 96(%rdi),%rdi
|
||||
movdqa %xmm7,%xmm8
|
||||
|
||||
call _aesni_decrypt6
|
||||
|
||||
pxor %xmm10,%xmm2
|
||||
movdqa %xmm8,%xmm10
|
||||
pxor %xmm11,%xmm3
|
||||
movdqu %xmm2,(%rsi)
|
||||
pxor %xmm12,%xmm4
|
||||
movdqu %xmm3,16(%rsi)
|
||||
pxor %xmm13,%xmm5
|
||||
movdqu %xmm4,32(%rsi)
|
||||
pxor %xmm14,%xmm6
|
||||
movq %rbp,%rcx
|
||||
movdqu %xmm5,48(%rsi)
|
||||
pxor %xmm15,%xmm7
|
||||
movl %r10d,%eax
|
||||
movdqu %xmm6,64(%rsi)
|
||||
leaq 80(%rsi),%rsi
|
||||
subq $0x60,%rdx
|
||||
ja .Lcbc_dec_loop6
|
||||
|
||||
movdqa %xmm7,%xmm2
|
||||
addq $0x50,%rdx
|
||||
jle .Lcbc_dec_clear_tail_collected
|
||||
movups %xmm7,(%rsi)
|
||||
leaq 16(%rsi),%rsi
|
||||
|
||||
.Lcbc_dec_tail:
|
||||
movups (%rdi),%xmm2
|
||||
subq $0x10,%rdx
|
||||
@@ -2054,7 +1906,7 @@ _CET_ENDBR
|
||||
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
|
||||
@@ -2099,7 +1951,7 @@ _CET_ENDBR
|
||||
.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
|
||||
@@ -2410,7 +2262,7 @@ _CET_ENDBR
|
||||
pxor %xmm5,%xmm5
|
||||
addq $8,%rsp
|
||||
.cfi_adjust_cfa_offset -8
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
.cfi_endproc
|
||||
.LSEH_end_set_encrypt_key:
|
||||
|
||||
@@ -2425,7 +2277,7 @@ _CET_ENDBR
|
||||
xorps %xmm4,%xmm0
|
||||
shufps $255,%xmm1,%xmm1
|
||||
xorps %xmm1,%xmm0
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
.align 16
|
||||
.Lkey_expansion_192a:
|
||||
@@ -2445,7 +2297,7 @@ _CET_ENDBR
|
||||
pxor %xmm1,%xmm0
|
||||
pshufd $255,%xmm0,%xmm3
|
||||
pxor %xmm3,%xmm2
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
.align 16
|
||||
.Lkey_expansion_192b:
|
||||
@@ -2468,7 +2320,7 @@ _CET_ENDBR
|
||||
xorps %xmm4,%xmm0
|
||||
shufps $255,%xmm1,%xmm1
|
||||
xorps %xmm1,%xmm0
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
.align 16
|
||||
.Lkey_expansion_256b:
|
||||
@@ -2481,7 +2333,7 @@ _CET_ENDBR
|
||||
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
|
||||
|
||||
@@ -36,7 +36,7 @@ L$oop_enc1_1:
|
||||
pxor %xmm1,%xmm1
|
||||
movups %xmm2,(%rsi)
|
||||
pxor %xmm2,%xmm2
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ L$oop_dec1_2:
|
||||
pxor %xmm1,%xmm1
|
||||
movups %xmm2,(%rsi)
|
||||
pxor %xmm2,%xmm2
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
|
||||
@@ -95,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
|
||||
|
||||
|
||||
|
||||
@@ -126,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
|
||||
|
||||
|
||||
|
||||
@@ -162,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
|
||||
|
||||
|
||||
|
||||
@@ -198,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
|
||||
|
||||
|
||||
|
||||
@@ -240,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
|
||||
|
||||
|
||||
|
||||
@@ -282,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
|
||||
|
||||
|
||||
|
||||
@@ -338,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
|
||||
|
||||
|
||||
|
||||
@@ -394,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
|
||||
|
||||
|
||||
|
||||
@@ -460,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
|
||||
|
||||
|
||||
|
||||
@@ -526,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
|
||||
@@ -872,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
|
||||
@@ -971,10 +971,7 @@ L$ctr32_bulk:
|
||||
leaq 7(%r8),%r9
|
||||
movl %r10d,96+12(%rsp)
|
||||
bswapl %r9d
|
||||
leaq _OPENSSL_ia32cap_P(%rip),%r10
|
||||
movl 4(%r10),%r10d
|
||||
xorl %ebp,%r9d
|
||||
andl $71303168,%r10d
|
||||
movl %r9d,112+12(%rsp)
|
||||
|
||||
movups 16(%rcx),%xmm1
|
||||
@@ -985,104 +982,10 @@ L$ctr32_bulk:
|
||||
cmpq $8,%rdx
|
||||
jb L$ctr32_tail
|
||||
|
||||
subq $6,%rdx
|
||||
cmpl $4194304,%r10d
|
||||
je L$ctr32_6x
|
||||
|
||||
leaq 128(%rcx),%rcx
|
||||
subq $2,%rdx
|
||||
subq $8,%rdx
|
||||
jmp L$ctr32_loop8
|
||||
|
||||
.p2align 4
|
||||
L$ctr32_6x:
|
||||
shll $4,%eax
|
||||
movl $48,%r10d
|
||||
bswapl %ebp
|
||||
leaq 32(%rcx,%rax,1),%rcx
|
||||
subq %rax,%r10
|
||||
jmp L$ctr32_loop6
|
||||
|
||||
.p2align 4
|
||||
L$ctr32_loop6:
|
||||
addl $6,%r8d
|
||||
movups -48(%rcx,%r10,1),%xmm0
|
||||
.byte 102,15,56,220,209
|
||||
movl %r8d,%eax
|
||||
xorl %ebp,%eax
|
||||
.byte 102,15,56,220,217
|
||||
.byte 0x0f,0x38,0xf1,0x44,0x24,12
|
||||
leal 1(%r8),%eax
|
||||
.byte 102,15,56,220,225
|
||||
xorl %ebp,%eax
|
||||
.byte 0x0f,0x38,0xf1,0x44,0x24,28
|
||||
.byte 102,15,56,220,233
|
||||
leal 2(%r8),%eax
|
||||
xorl %ebp,%eax
|
||||
.byte 102,15,56,220,241
|
||||
.byte 0x0f,0x38,0xf1,0x44,0x24,44
|
||||
leal 3(%r8),%eax
|
||||
.byte 102,15,56,220,249
|
||||
movups -32(%rcx,%r10,1),%xmm1
|
||||
xorl %ebp,%eax
|
||||
|
||||
.byte 102,15,56,220,208
|
||||
.byte 0x0f,0x38,0xf1,0x44,0x24,60
|
||||
leal 4(%r8),%eax
|
||||
.byte 102,15,56,220,216
|
||||
xorl %ebp,%eax
|
||||
.byte 0x0f,0x38,0xf1,0x44,0x24,76
|
||||
.byte 102,15,56,220,224
|
||||
leal 5(%r8),%eax
|
||||
xorl %ebp,%eax
|
||||
.byte 102,15,56,220,232
|
||||
.byte 0x0f,0x38,0xf1,0x44,0x24,92
|
||||
movq %r10,%rax
|
||||
.byte 102,15,56,220,240
|
||||
.byte 102,15,56,220,248
|
||||
movups -16(%rcx,%r10,1),%xmm0
|
||||
|
||||
call L$enc_loop6
|
||||
|
||||
movdqu (%rdi),%xmm8
|
||||
movdqu 16(%rdi),%xmm9
|
||||
movdqu 32(%rdi),%xmm10
|
||||
movdqu 48(%rdi),%xmm11
|
||||
movdqu 64(%rdi),%xmm12
|
||||
movdqu 80(%rdi),%xmm13
|
||||
leaq 96(%rdi),%rdi
|
||||
movups -64(%rcx,%r10,1),%xmm1
|
||||
pxor %xmm2,%xmm8
|
||||
movaps 0(%rsp),%xmm2
|
||||
pxor %xmm3,%xmm9
|
||||
movaps 16(%rsp),%xmm3
|
||||
pxor %xmm4,%xmm10
|
||||
movaps 32(%rsp),%xmm4
|
||||
pxor %xmm5,%xmm11
|
||||
movaps 48(%rsp),%xmm5
|
||||
pxor %xmm6,%xmm12
|
||||
movaps 64(%rsp),%xmm6
|
||||
pxor %xmm7,%xmm13
|
||||
movaps 80(%rsp),%xmm7
|
||||
movdqu %xmm8,(%rsi)
|
||||
movdqu %xmm9,16(%rsi)
|
||||
movdqu %xmm10,32(%rsi)
|
||||
movdqu %xmm11,48(%rsi)
|
||||
movdqu %xmm12,64(%rsi)
|
||||
movdqu %xmm13,80(%rsi)
|
||||
leaq 96(%rsi),%rsi
|
||||
|
||||
subq $6,%rdx
|
||||
jnc L$ctr32_loop6
|
||||
|
||||
addq $6,%rdx
|
||||
jz L$ctr32_done
|
||||
|
||||
leal -48(%r10),%eax
|
||||
leaq -80(%rcx,%r10,1),%rcx
|
||||
negl %eax
|
||||
shrl $4,%eax
|
||||
jmp L$ctr32_tail
|
||||
|
||||
.p2align 5
|
||||
L$ctr32_loop8:
|
||||
addl $8,%r8d
|
||||
@@ -1458,7 +1361,7 @@ L$ctr32_done:
|
||||
leaq (%r11),%rsp
|
||||
|
||||
L$ctr32_epilogue:
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aes_hw_cbc_encrypt
|
||||
@@ -1584,16 +1487,10 @@ L$cbc_decrypt_bulk:
|
||||
movdqa %xmm5,%xmm14
|
||||
movdqu 80(%rdi),%xmm7
|
||||
movdqa %xmm6,%xmm15
|
||||
leaq _OPENSSL_ia32cap_P(%rip),%r9
|
||||
movl 4(%r9),%r9d
|
||||
cmpq $0x70,%rdx
|
||||
jbe L$cbc_dec_six_or_seven
|
||||
|
||||
andl $71303168,%r9d
|
||||
subq $0x50,%rdx
|
||||
cmpl $4194304,%r9d
|
||||
je L$cbc_dec_loop6_enter
|
||||
subq $0x20,%rdx
|
||||
subq $0x70,%rdx
|
||||
leaq 112(%rcx),%rcx
|
||||
jmp L$cbc_dec_loop8_enter
|
||||
.p2align 4
|
||||
@@ -1864,51 +1761,6 @@ L$cbc_dec_seven:
|
||||
pxor %xmm9,%xmm9
|
||||
jmp L$cbc_dec_tail_collected
|
||||
|
||||
.p2align 4
|
||||
L$cbc_dec_loop6:
|
||||
movups %xmm7,(%rsi)
|
||||
leaq 16(%rsi),%rsi
|
||||
movdqu 0(%rdi),%xmm2
|
||||
movdqu 16(%rdi),%xmm3
|
||||
movdqa %xmm2,%xmm11
|
||||
movdqu 32(%rdi),%xmm4
|
||||
movdqa %xmm3,%xmm12
|
||||
movdqu 48(%rdi),%xmm5
|
||||
movdqa %xmm4,%xmm13
|
||||
movdqu 64(%rdi),%xmm6
|
||||
movdqa %xmm5,%xmm14
|
||||
movdqu 80(%rdi),%xmm7
|
||||
movdqa %xmm6,%xmm15
|
||||
L$cbc_dec_loop6_enter:
|
||||
leaq 96(%rdi),%rdi
|
||||
movdqa %xmm7,%xmm8
|
||||
|
||||
call _aesni_decrypt6
|
||||
|
||||
pxor %xmm10,%xmm2
|
||||
movdqa %xmm8,%xmm10
|
||||
pxor %xmm11,%xmm3
|
||||
movdqu %xmm2,(%rsi)
|
||||
pxor %xmm12,%xmm4
|
||||
movdqu %xmm3,16(%rsi)
|
||||
pxor %xmm13,%xmm5
|
||||
movdqu %xmm4,32(%rsi)
|
||||
pxor %xmm14,%xmm6
|
||||
movq %rbp,%rcx
|
||||
movdqu %xmm5,48(%rsi)
|
||||
pxor %xmm15,%xmm7
|
||||
movl %r10d,%eax
|
||||
movdqu %xmm6,64(%rsi)
|
||||
leaq 80(%rsi),%rsi
|
||||
subq $0x60,%rdx
|
||||
ja L$cbc_dec_loop6
|
||||
|
||||
movdqa %xmm7,%xmm2
|
||||
addq $0x50,%rdx
|
||||
jle L$cbc_dec_clear_tail_collected
|
||||
movups %xmm7,(%rsi)
|
||||
leaq 16(%rsi),%rsi
|
||||
|
||||
L$cbc_dec_tail:
|
||||
movups (%rdi),%xmm2
|
||||
subq $0x10,%rdx
|
||||
@@ -2052,7 +1904,7 @@ L$cbc_dec_ret:
|
||||
leaq (%r11),%rsp
|
||||
|
||||
L$cbc_ret:
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.globl _aes_hw_set_decrypt_key
|
||||
@@ -2097,7 +1949,7 @@ L$dec_key_inverse:
|
||||
L$dec_key_ret:
|
||||
addq $8,%rsp
|
||||
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
L$SEH_end_set_decrypt_key:
|
||||
|
||||
@@ -2408,7 +2260,7 @@ L$enc_key_ret:
|
||||
pxor %xmm5,%xmm5
|
||||
addq $8,%rsp
|
||||
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
L$SEH_end_set_encrypt_key:
|
||||
|
||||
@@ -2423,7 +2275,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:
|
||||
@@ -2443,7 +2295,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:
|
||||
@@ -2466,7 +2318,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:
|
||||
@@ -2479,7 +2331,7 @@ L$key_expansion_256b:
|
||||
xorps %xmm4,%xmm2
|
||||
shufps $170,%xmm1,%xmm1
|
||||
xorps %xmm1,%xmm2
|
||||
.byte 0xf3,0xc3
|
||||
ret
|
||||
|
||||
|
||||
.section __DATA,__const
|
||||
|
||||
@@ -20,40 +20,16 @@
|
||||
.code 32
|
||||
#endif
|
||||
|
||||
#if __ARM_MAX_ARCH__>=7
|
||||
.align 5
|
||||
LOPENSSL_armcap:
|
||||
.word OPENSSL_armcap_P-Lbn_mul_mont
|
||||
#endif
|
||||
|
||||
.globl _bn_mul_mont
|
||||
.private_extern _bn_mul_mont
|
||||
.globl _bn_mul_mont_nohw
|
||||
.private_extern _bn_mul_mont_nohw
|
||||
#ifdef __thumb2__
|
||||
.thumb_func _bn_mul_mont
|
||||
.thumb_func _bn_mul_mont_nohw
|
||||
#endif
|
||||
|
||||
.align 5
|
||||
_bn_mul_mont:
|
||||
Lbn_mul_mont:
|
||||
_bn_mul_mont_nohw:
|
||||
ldr ip,[sp,#4] @ load num
|
||||
stmdb sp!,{r0,r2} @ sp points at argument block
|
||||
#if __ARM_MAX_ARCH__>=7
|
||||
tst ip,#7
|
||||
bne Lialu
|
||||
adr r0,Lbn_mul_mont
|
||||
ldr r2,LOPENSSL_armcap
|
||||
ldr r0,[r0,r2]
|
||||
#ifdef __APPLE__
|
||||
ldr r0,[r0]
|
||||
#endif
|
||||
tst r0,#ARMV7_NEON @ NEON available?
|
||||
ldmia sp, {r0,r2}
|
||||
beq Lialu
|
||||
add sp,sp,#8
|
||||
b bn_mul8x_mont_neon
|
||||
.align 4
|
||||
Lialu:
|
||||
#endif
|
||||
cmp ip,#2
|
||||
mov r0,ip @ load num
|
||||
#ifdef __thumb2__
|
||||
@@ -197,7 +173,7 @@ Lcopy: ldr r7,[r4] @ conditional copy
|
||||
add sp,sp,#2*4 @ skip over {r0,r2}
|
||||
mov r0,#1
|
||||
Labrt:
|
||||
#if __ARM_ARCH__>=5
|
||||
#if __ARM_ARCH>=5
|
||||
bx lr @ bx lr
|
||||
#else
|
||||
tst lr,#1
|
||||
@@ -209,11 +185,13 @@ Labrt:
|
||||
|
||||
|
||||
|
||||
.globl _bn_mul8x_mont_neon
|
||||
.private_extern _bn_mul8x_mont_neon
|
||||
#ifdef __thumb2__
|
||||
.thumb_func bn_mul8x_mont_neon
|
||||
.thumb_func _bn_mul8x_mont_neon
|
||||
#endif
|
||||
.align 5
|
||||
bn_mul8x_mont_neon:
|
||||
_bn_mul8x_mont_neon:
|
||||
mov ip,sp
|
||||
stmdb sp!,{r4,r5,r6,r7,r8,r9,r10,r11}
|
||||
vstmdb sp!,{d8,d9,d10,d11,d12,d13,d14,d15} @ ABI specification says so
|
||||
@@ -964,15 +942,6 @@ LNEON_copy_n_zap:
|
||||
#endif
|
||||
.byte 77,111,110,116,103,111,109,101,114,121,32,109,117,108,116,105,112,108,105,99,97,116,105,111,110,32,102,111,114,32,65,82,77,118,52,47,78,69,79,78,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0
|
||||
.align 2
|
||||
.align 2
|
||||
#if __ARM_MAX_ARCH__>=7
|
||||
.comm _OPENSSL_armcap_P,4
|
||||
.non_lazy_symbol_pointer
|
||||
OPENSSL_armcap_P:
|
||||
.indirect_symbol _OPENSSL_armcap_P
|
||||
.long 0
|
||||
.private_extern _OPENSSL_armcap_P
|
||||
#endif
|
||||
#endif // !OPENSSL_NO_ASM && defined(OPENSSL_ARM) && defined(__APPLE__)
|
||||
#endif // defined(__arm__) && defined(__APPLE__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
|
||||
@@ -20,38 +20,14 @@
|
||||
.code 32
|
||||
#endif
|
||||
|
||||
#if __ARM_MAX_ARCH__>=7
|
||||
.align 5
|
||||
.LOPENSSL_armcap:
|
||||
.word OPENSSL_armcap_P-.Lbn_mul_mont
|
||||
#endif
|
||||
|
||||
.globl bn_mul_mont
|
||||
.hidden bn_mul_mont
|
||||
.type bn_mul_mont,%function
|
||||
.globl bn_mul_mont_nohw
|
||||
.hidden bn_mul_mont_nohw
|
||||
.type bn_mul_mont_nohw,%function
|
||||
|
||||
.align 5
|
||||
bn_mul_mont:
|
||||
.Lbn_mul_mont:
|
||||
bn_mul_mont_nohw:
|
||||
ldr ip,[sp,#4] @ load num
|
||||
stmdb sp!,{r0,r2} @ sp points at argument block
|
||||
#if __ARM_MAX_ARCH__>=7
|
||||
tst ip,#7
|
||||
bne .Lialu
|
||||
adr r0,.Lbn_mul_mont
|
||||
ldr r2,.LOPENSSL_armcap
|
||||
ldr r0,[r0,r2]
|
||||
#ifdef __APPLE__
|
||||
ldr r0,[r0]
|
||||
#endif
|
||||
tst r0,#ARMV7_NEON @ NEON available?
|
||||
ldmia sp, {r0,r2}
|
||||
beq .Lialu
|
||||
add sp,sp,#8
|
||||
b bn_mul8x_mont_neon
|
||||
.align 4
|
||||
.Lialu:
|
||||
#endif
|
||||
cmp ip,#2
|
||||
mov r0,ip @ load num
|
||||
#ifdef __thumb2__
|
||||
@@ -195,18 +171,20 @@ bn_mul_mont:
|
||||
add sp,sp,#2*4 @ skip over {r0,r2}
|
||||
mov r0,#1
|
||||
.Labrt:
|
||||
#if __ARM_ARCH__>=5
|
||||
#if __ARM_ARCH>=5
|
||||
bx lr @ bx lr
|
||||
#else
|
||||
tst lr,#1
|
||||
moveq pc,lr @ be binary compatible with V4, yet
|
||||
.word 0xe12fff1e @ interoperable with Thumb ISA:-)
|
||||
#endif
|
||||
.size bn_mul_mont,.-bn_mul_mont
|
||||
.size bn_mul_mont_nohw,.-bn_mul_mont_nohw
|
||||
#if __ARM_MAX_ARCH__>=7
|
||||
.arch armv7-a
|
||||
.fpu neon
|
||||
|
||||
.globl bn_mul8x_mont_neon
|
||||
.hidden bn_mul8x_mont_neon
|
||||
.type bn_mul8x_mont_neon,%function
|
||||
.align 5
|
||||
bn_mul8x_mont_neon:
|
||||
@@ -960,11 +938,6 @@ bn_mul8x_mont_neon:
|
||||
#endif
|
||||
.byte 77,111,110,116,103,111,109,101,114,121,32,109,117,108,116,105,112,108,105,99,97,116,105,111,110,32,102,111,114,32,65,82,77,118,52,47,78,69,79,78,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0
|
||||
.align 2
|
||||
.align 2
|
||||
#if __ARM_MAX_ARCH__>=7
|
||||
.comm OPENSSL_armcap_P,4,4
|
||||
.hidden OPENSSL_armcap_P
|
||||
#endif
|
||||
#endif // !OPENSSL_NO_ASM && defined(OPENSSL_ARM) && defined(__ELF__)
|
||||
#endif // defined(__arm__) && defined(__linux__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
|
||||
@@ -15,10 +15,104 @@ section .text code align=64
|
||||
%else
|
||||
section .text code
|
||||
%endif
|
||||
;extern _OPENSSL_ia32cap_P
|
||||
global _bn_mul_add_words
|
||||
align 16
|
||||
_bn_mul_add_words:
|
||||
L$_bn_mul_add_words_begin:
|
||||
lea eax,[_OPENSSL_ia32cap_P]
|
||||
bt DWORD [eax],26
|
||||
jnc NEAR L$000maw_non_sse2
|
||||
mov eax,DWORD [4+esp]
|
||||
mov edx,DWORD [8+esp]
|
||||
mov ecx,DWORD [12+esp]
|
||||
movd mm0,DWORD [16+esp]
|
||||
pxor mm1,mm1
|
||||
jmp NEAR L$001maw_sse2_entry
|
||||
align 16
|
||||
L$002maw_sse2_unrolled:
|
||||
movd mm3,DWORD [eax]
|
||||
paddq mm1,mm3
|
||||
movd mm2,DWORD [edx]
|
||||
pmuludq mm2,mm0
|
||||
movd mm4,DWORD [4+edx]
|
||||
pmuludq mm4,mm0
|
||||
movd mm6,DWORD [8+edx]
|
||||
pmuludq mm6,mm0
|
||||
movd mm7,DWORD [12+edx]
|
||||
pmuludq mm7,mm0
|
||||
paddq mm1,mm2
|
||||
movd mm3,DWORD [4+eax]
|
||||
paddq mm3,mm4
|
||||
movd mm5,DWORD [8+eax]
|
||||
paddq mm5,mm6
|
||||
movd mm4,DWORD [12+eax]
|
||||
paddq mm7,mm4
|
||||
movd DWORD [eax],mm1
|
||||
movd mm2,DWORD [16+edx]
|
||||
pmuludq mm2,mm0
|
||||
psrlq mm1,32
|
||||
movd mm4,DWORD [20+edx]
|
||||
pmuludq mm4,mm0
|
||||
paddq mm1,mm3
|
||||
movd mm6,DWORD [24+edx]
|
||||
pmuludq mm6,mm0
|
||||
movd DWORD [4+eax],mm1
|
||||
psrlq mm1,32
|
||||
movd mm3,DWORD [28+edx]
|
||||
add edx,32
|
||||
pmuludq mm3,mm0
|
||||
paddq mm1,mm5
|
||||
movd mm5,DWORD [16+eax]
|
||||
paddq mm2,mm5
|
||||
movd DWORD [8+eax],mm1
|
||||
psrlq mm1,32
|
||||
paddq mm1,mm7
|
||||
movd mm5,DWORD [20+eax]
|
||||
paddq mm4,mm5
|
||||
movd DWORD [12+eax],mm1
|
||||
psrlq mm1,32
|
||||
paddq mm1,mm2
|
||||
movd mm5,DWORD [24+eax]
|
||||
paddq mm6,mm5
|
||||
movd DWORD [16+eax],mm1
|
||||
psrlq mm1,32
|
||||
paddq mm1,mm4
|
||||
movd mm5,DWORD [28+eax]
|
||||
paddq mm3,mm5
|
||||
movd DWORD [20+eax],mm1
|
||||
psrlq mm1,32
|
||||
paddq mm1,mm6
|
||||
movd DWORD [24+eax],mm1
|
||||
psrlq mm1,32
|
||||
paddq mm1,mm3
|
||||
movd DWORD [28+eax],mm1
|
||||
lea eax,[32+eax]
|
||||
psrlq mm1,32
|
||||
sub ecx,8
|
||||
jz NEAR L$003maw_sse2_exit
|
||||
L$001maw_sse2_entry:
|
||||
test ecx,4294967288
|
||||
jnz NEAR L$002maw_sse2_unrolled
|
||||
align 4
|
||||
L$004maw_sse2_loop:
|
||||
movd mm2,DWORD [edx]
|
||||
movd mm3,DWORD [eax]
|
||||
pmuludq mm2,mm0
|
||||
lea edx,[4+edx]
|
||||
paddq mm1,mm3
|
||||
paddq mm1,mm2
|
||||
movd DWORD [eax],mm1
|
||||
sub ecx,1
|
||||
psrlq mm1,32
|
||||
lea eax,[4+eax]
|
||||
jnz NEAR L$004maw_sse2_loop
|
||||
L$003maw_sse2_exit:
|
||||
movd eax,mm1
|
||||
emms
|
||||
ret
|
||||
align 16
|
||||
L$000maw_non_sse2:
|
||||
push ebp
|
||||
push ebx
|
||||
push esi
|
||||
@@ -31,9 +125,9 @@ L$_bn_mul_add_words_begin:
|
||||
and ecx,4294967288
|
||||
mov ebp,DWORD [32+esp]
|
||||
push ecx
|
||||
jz NEAR L$000maw_finish
|
||||
jz NEAR L$005maw_finish
|
||||
align 16
|
||||
L$001maw_loop:
|
||||
L$006maw_loop:
|
||||
; Round 0
|
||||
mov eax,DWORD [ebx]
|
||||
mul ebp
|
||||
@@ -110,13 +204,13 @@ L$001maw_loop:
|
||||
sub ecx,8
|
||||
lea ebx,[32+ebx]
|
||||
lea edi,[32+edi]
|
||||
jnz NEAR L$001maw_loop
|
||||
L$000maw_finish:
|
||||
jnz NEAR L$006maw_loop
|
||||
L$005maw_finish:
|
||||
mov ecx,DWORD [32+esp]
|
||||
and ecx,7
|
||||
jnz NEAR L$002maw_finish2
|
||||
jmp NEAR L$003maw_end
|
||||
L$002maw_finish2:
|
||||
jnz NEAR L$007maw_finish2
|
||||
jmp NEAR L$008maw_end
|
||||
L$007maw_finish2:
|
||||
; Tail Round 0
|
||||
mov eax,DWORD [ebx]
|
||||
mul ebp
|
||||
@@ -127,7 +221,7 @@ L$002maw_finish2:
|
||||
dec ecx
|
||||
mov DWORD [edi],eax
|
||||
mov esi,edx
|
||||
jz NEAR L$003maw_end
|
||||
jz NEAR L$008maw_end
|
||||
; Tail Round 1
|
||||
mov eax,DWORD [4+ebx]
|
||||
mul ebp
|
||||
@@ -138,7 +232,7 @@ L$002maw_finish2:
|
||||
dec ecx
|
||||
mov DWORD [4+edi],eax
|
||||
mov esi,edx
|
||||
jz NEAR L$003maw_end
|
||||
jz NEAR L$008maw_end
|
||||
; Tail Round 2
|
||||
mov eax,DWORD [8+ebx]
|
||||
mul ebp
|
||||
@@ -149,7 +243,7 @@ L$002maw_finish2:
|
||||
dec ecx
|
||||
mov DWORD [8+edi],eax
|
||||
mov esi,edx
|
||||
jz NEAR L$003maw_end
|
||||
jz NEAR L$008maw_end
|
||||
; Tail Round 3
|
||||
mov eax,DWORD [12+ebx]
|
||||
mul ebp
|
||||
@@ -160,7 +254,7 @@ L$002maw_finish2:
|
||||
dec ecx
|
||||
mov DWORD [12+edi],eax
|
||||
mov esi,edx
|
||||
jz NEAR L$003maw_end
|
||||
jz NEAR L$008maw_end
|
||||
; Tail Round 4
|
||||
mov eax,DWORD [16+ebx]
|
||||
mul ebp
|
||||
@@ -171,7 +265,7 @@ L$002maw_finish2:
|
||||
dec ecx
|
||||
mov DWORD [16+edi],eax
|
||||
mov esi,edx
|
||||
jz NEAR L$003maw_end
|
||||
jz NEAR L$008maw_end
|
||||
; Tail Round 5
|
||||
mov eax,DWORD [20+ebx]
|
||||
mul ebp
|
||||
@@ -182,7 +276,7 @@ L$002maw_finish2:
|
||||
dec ecx
|
||||
mov DWORD [20+edi],eax
|
||||
mov esi,edx
|
||||
jz NEAR L$003maw_end
|
||||
jz NEAR L$008maw_end
|
||||
; Tail Round 6
|
||||
mov eax,DWORD [24+ebx]
|
||||
mul ebp
|
||||
@@ -192,7 +286,7 @@ L$002maw_finish2:
|
||||
adc edx,0
|
||||
mov DWORD [24+edi],eax
|
||||
mov esi,edx
|
||||
L$003maw_end:
|
||||
L$008maw_end:
|
||||
mov eax,esi
|
||||
pop ecx
|
||||
pop edi
|
||||
@@ -204,6 +298,30 @@ global _bn_mul_words
|
||||
align 16
|
||||
_bn_mul_words:
|
||||
L$_bn_mul_words_begin:
|
||||
lea eax,[_OPENSSL_ia32cap_P]
|
||||
bt DWORD [eax],26
|
||||
jnc NEAR L$009mw_non_sse2
|
||||
mov eax,DWORD [4+esp]
|
||||
mov edx,DWORD [8+esp]
|
||||
mov ecx,DWORD [12+esp]
|
||||
movd mm0,DWORD [16+esp]
|
||||
pxor mm1,mm1
|
||||
align 16
|
||||
L$010mw_sse2_loop:
|
||||
movd mm2,DWORD [edx]
|
||||
pmuludq mm2,mm0
|
||||
lea edx,[4+edx]
|
||||
paddq mm1,mm2
|
||||
movd DWORD [eax],mm1
|
||||
sub ecx,1
|
||||
psrlq mm1,32
|
||||
lea eax,[4+eax]
|
||||
jnz NEAR L$010mw_sse2_loop
|
||||
movd eax,mm1
|
||||
emms
|
||||
ret
|
||||
align 16
|
||||
L$009mw_non_sse2:
|
||||
push ebp
|
||||
push ebx
|
||||
push esi
|
||||
@@ -215,8 +333,8 @@ L$_bn_mul_words_begin:
|
||||
mov ebp,DWORD [28+esp]
|
||||
mov ecx,DWORD [32+esp]
|
||||
and ebp,4294967288
|
||||
jz NEAR L$004mw_finish
|
||||
L$005mw_loop:
|
||||
jz NEAR L$011mw_finish
|
||||
L$012mw_loop:
|
||||
; Round 0
|
||||
mov eax,DWORD [ebx]
|
||||
mul ecx
|
||||
@@ -277,14 +395,14 @@ L$005mw_loop:
|
||||
add ebx,32
|
||||
add edi,32
|
||||
sub ebp,8
|
||||
jz NEAR L$004mw_finish
|
||||
jmp NEAR L$005mw_loop
|
||||
L$004mw_finish:
|
||||
jz NEAR L$011mw_finish
|
||||
jmp NEAR L$012mw_loop
|
||||
L$011mw_finish:
|
||||
mov ebp,DWORD [28+esp]
|
||||
and ebp,7
|
||||
jnz NEAR L$006mw_finish2
|
||||
jmp NEAR L$007mw_end
|
||||
L$006mw_finish2:
|
||||
jnz NEAR L$013mw_finish2
|
||||
jmp NEAR L$014mw_end
|
||||
L$013mw_finish2:
|
||||
; Tail Round 0
|
||||
mov eax,DWORD [ebx]
|
||||
mul ecx
|
||||
@@ -293,7 +411,7 @@ L$006mw_finish2:
|
||||
mov DWORD [edi],eax
|
||||
mov esi,edx
|
||||
dec ebp
|
||||
jz NEAR L$007mw_end
|
||||
jz NEAR L$014mw_end
|
||||
; Tail Round 1
|
||||
mov eax,DWORD [4+ebx]
|
||||
mul ecx
|
||||
@@ -302,7 +420,7 @@ L$006mw_finish2:
|
||||
mov DWORD [4+edi],eax
|
||||
mov esi,edx
|
||||
dec ebp
|
||||
jz NEAR L$007mw_end
|
||||
jz NEAR L$014mw_end
|
||||
; Tail Round 2
|
||||
mov eax,DWORD [8+ebx]
|
||||
mul ecx
|
||||
@@ -311,7 +429,7 @@ L$006mw_finish2:
|
||||
mov DWORD [8+edi],eax
|
||||
mov esi,edx
|
||||
dec ebp
|
||||
jz NEAR L$007mw_end
|
||||
jz NEAR L$014mw_end
|
||||
; Tail Round 3
|
||||
mov eax,DWORD [12+ebx]
|
||||
mul ecx
|
||||
@@ -320,7 +438,7 @@ L$006mw_finish2:
|
||||
mov DWORD [12+edi],eax
|
||||
mov esi,edx
|
||||
dec ebp
|
||||
jz NEAR L$007mw_end
|
||||
jz NEAR L$014mw_end
|
||||
; Tail Round 4
|
||||
mov eax,DWORD [16+ebx]
|
||||
mul ecx
|
||||
@@ -329,7 +447,7 @@ L$006mw_finish2:
|
||||
mov DWORD [16+edi],eax
|
||||
mov esi,edx
|
||||
dec ebp
|
||||
jz NEAR L$007mw_end
|
||||
jz NEAR L$014mw_end
|
||||
; Tail Round 5
|
||||
mov eax,DWORD [20+ebx]
|
||||
mul ecx
|
||||
@@ -338,7 +456,7 @@ L$006mw_finish2:
|
||||
mov DWORD [20+edi],eax
|
||||
mov esi,edx
|
||||
dec ebp
|
||||
jz NEAR L$007mw_end
|
||||
jz NEAR L$014mw_end
|
||||
; Tail Round 6
|
||||
mov eax,DWORD [24+ebx]
|
||||
mul ecx
|
||||
@@ -346,7 +464,7 @@ L$006mw_finish2:
|
||||
adc edx,0
|
||||
mov DWORD [24+edi],eax
|
||||
mov esi,edx
|
||||
L$007mw_end:
|
||||
L$014mw_end:
|
||||
mov eax,esi
|
||||
pop edi
|
||||
pop esi
|
||||
@@ -357,6 +475,25 @@ global _bn_sqr_words
|
||||
align 16
|
||||
_bn_sqr_words:
|
||||
L$_bn_sqr_words_begin:
|
||||
lea eax,[_OPENSSL_ia32cap_P]
|
||||
bt DWORD [eax],26
|
||||
jnc NEAR L$015sqr_non_sse2
|
||||
mov eax,DWORD [4+esp]
|
||||
mov edx,DWORD [8+esp]
|
||||
mov ecx,DWORD [12+esp]
|
||||
align 16
|
||||
L$016sqr_sse2_loop:
|
||||
movd mm0,DWORD [edx]
|
||||
pmuludq mm0,mm0
|
||||
lea edx,[4+edx]
|
||||
movq [eax],mm0
|
||||
sub ecx,1
|
||||
lea eax,[8+eax]
|
||||
jnz NEAR L$016sqr_sse2_loop
|
||||
emms
|
||||
ret
|
||||
align 16
|
||||
L$015sqr_non_sse2:
|
||||
push ebp
|
||||
push ebx
|
||||
push esi
|
||||
@@ -366,8 +503,8 @@ L$_bn_sqr_words_begin:
|
||||
mov edi,DWORD [24+esp]
|
||||
mov ebx,DWORD [28+esp]
|
||||
and ebx,4294967288
|
||||
jz NEAR L$008sw_finish
|
||||
L$009sw_loop:
|
||||
jz NEAR L$017sw_finish
|
||||
L$018sw_loop:
|
||||
; Round 0
|
||||
mov eax,DWORD [edi]
|
||||
mul eax
|
||||
@@ -412,59 +549,59 @@ L$009sw_loop:
|
||||
add edi,32
|
||||
add esi,64
|
||||
sub ebx,8
|
||||
jnz NEAR L$009sw_loop
|
||||
L$008sw_finish:
|
||||
jnz NEAR L$018sw_loop
|
||||
L$017sw_finish:
|
||||
mov ebx,DWORD [28+esp]
|
||||
and ebx,7
|
||||
jz NEAR L$010sw_end
|
||||
jz NEAR L$019sw_end
|
||||
; Tail Round 0
|
||||
mov eax,DWORD [edi]
|
||||
mul eax
|
||||
mov DWORD [esi],eax
|
||||
dec ebx
|
||||
mov DWORD [4+esi],edx
|
||||
jz NEAR L$010sw_end
|
||||
jz NEAR L$019sw_end
|
||||
; Tail Round 1
|
||||
mov eax,DWORD [4+edi]
|
||||
mul eax
|
||||
mov DWORD [8+esi],eax
|
||||
dec ebx
|
||||
mov DWORD [12+esi],edx
|
||||
jz NEAR L$010sw_end
|
||||
jz NEAR L$019sw_end
|
||||
; Tail Round 2
|
||||
mov eax,DWORD [8+edi]
|
||||
mul eax
|
||||
mov DWORD [16+esi],eax
|
||||
dec ebx
|
||||
mov DWORD [20+esi],edx
|
||||
jz NEAR L$010sw_end
|
||||
jz NEAR L$019sw_end
|
||||
; Tail Round 3
|
||||
mov eax,DWORD [12+edi]
|
||||
mul eax
|
||||
mov DWORD [24+esi],eax
|
||||
dec ebx
|
||||
mov DWORD [28+esi],edx
|
||||
jz NEAR L$010sw_end
|
||||
jz NEAR L$019sw_end
|
||||
; Tail Round 4
|
||||
mov eax,DWORD [16+edi]
|
||||
mul eax
|
||||
mov DWORD [32+esi],eax
|
||||
dec ebx
|
||||
mov DWORD [36+esi],edx
|
||||
jz NEAR L$010sw_end
|
||||
jz NEAR L$019sw_end
|
||||
; Tail Round 5
|
||||
mov eax,DWORD [20+edi]
|
||||
mul eax
|
||||
mov DWORD [40+esi],eax
|
||||
dec ebx
|
||||
mov DWORD [44+esi],edx
|
||||
jz NEAR L$010sw_end
|
||||
jz NEAR L$019sw_end
|
||||
; Tail Round 6
|
||||
mov eax,DWORD [24+edi]
|
||||
mul eax
|
||||
mov DWORD [48+esi],eax
|
||||
mov DWORD [52+esi],edx
|
||||
L$010sw_end:
|
||||
L$019sw_end:
|
||||
pop edi
|
||||
pop esi
|
||||
pop ebx
|
||||
@@ -494,8 +631,8 @@ L$_bn_add_words_begin:
|
||||
mov ebp,DWORD [32+esp]
|
||||
xor eax,eax
|
||||
and ebp,4294967288
|
||||
jz NEAR L$011aw_finish
|
||||
L$012aw_loop:
|
||||
jz NEAR L$020aw_finish
|
||||
L$021aw_loop:
|
||||
; Round 0
|
||||
mov ecx,DWORD [esi]
|
||||
mov edx,DWORD [edi]
|
||||
@@ -573,11 +710,11 @@ L$012aw_loop:
|
||||
add edi,32
|
||||
add ebx,32
|
||||
sub ebp,8
|
||||
jnz NEAR L$012aw_loop
|
||||
L$011aw_finish:
|
||||
jnz NEAR L$021aw_loop
|
||||
L$020aw_finish:
|
||||
mov ebp,DWORD [32+esp]
|
||||
and ebp,7
|
||||
jz NEAR L$013aw_end
|
||||
jz NEAR L$022aw_end
|
||||
; Tail Round 0
|
||||
mov ecx,DWORD [esi]
|
||||
mov edx,DWORD [edi]
|
||||
@@ -588,7 +725,7 @@ L$011aw_finish:
|
||||
adc eax,0
|
||||
dec ebp
|
||||
mov DWORD [ebx],ecx
|
||||
jz NEAR L$013aw_end
|
||||
jz NEAR L$022aw_end
|
||||
; Tail Round 1
|
||||
mov ecx,DWORD [4+esi]
|
||||
mov edx,DWORD [4+edi]
|
||||
@@ -599,7 +736,7 @@ L$011aw_finish:
|
||||
adc eax,0
|
||||
dec ebp
|
||||
mov DWORD [4+ebx],ecx
|
||||
jz NEAR L$013aw_end
|
||||
jz NEAR L$022aw_end
|
||||
; Tail Round 2
|
||||
mov ecx,DWORD [8+esi]
|
||||
mov edx,DWORD [8+edi]
|
||||
@@ -610,7 +747,7 @@ L$011aw_finish:
|
||||
adc eax,0
|
||||
dec ebp
|
||||
mov DWORD [8+ebx],ecx
|
||||
jz NEAR L$013aw_end
|
||||
jz NEAR L$022aw_end
|
||||
; Tail Round 3
|
||||
mov ecx,DWORD [12+esi]
|
||||
mov edx,DWORD [12+edi]
|
||||
@@ -621,7 +758,7 @@ L$011aw_finish:
|
||||
adc eax,0
|
||||
dec ebp
|
||||
mov DWORD [12+ebx],ecx
|
||||
jz NEAR L$013aw_end
|
||||
jz NEAR L$022aw_end
|
||||
; Tail Round 4
|
||||
mov ecx,DWORD [16+esi]
|
||||
mov edx,DWORD [16+edi]
|
||||
@@ -632,7 +769,7 @@ L$011aw_finish:
|
||||
adc eax,0
|
||||
dec ebp
|
||||
mov DWORD [16+ebx],ecx
|
||||
jz NEAR L$013aw_end
|
||||
jz NEAR L$022aw_end
|
||||
; Tail Round 5
|
||||
mov ecx,DWORD [20+esi]
|
||||
mov edx,DWORD [20+edi]
|
||||
@@ -643,7 +780,7 @@ L$011aw_finish:
|
||||
adc eax,0
|
||||
dec ebp
|
||||
mov DWORD [20+ebx],ecx
|
||||
jz NEAR L$013aw_end
|
||||
jz NEAR L$022aw_end
|
||||
; Tail Round 6
|
||||
mov ecx,DWORD [24+esi]
|
||||
mov edx,DWORD [24+edi]
|
||||
@@ -653,7 +790,7 @@ L$011aw_finish:
|
||||
add ecx,edx
|
||||
adc eax,0
|
||||
mov DWORD [24+ebx],ecx
|
||||
L$013aw_end:
|
||||
L$022aw_end:
|
||||
pop edi
|
||||
pop esi
|
||||
pop ebx
|
||||
@@ -674,8 +811,8 @@ L$_bn_sub_words_begin:
|
||||
mov ebp,DWORD [32+esp]
|
||||
xor eax,eax
|
||||
and ebp,4294967288
|
||||
jz NEAR L$014aw_finish
|
||||
L$015aw_loop:
|
||||
jz NEAR L$023aw_finish
|
||||
L$024aw_loop:
|
||||
; Round 0
|
||||
mov ecx,DWORD [esi]
|
||||
mov edx,DWORD [edi]
|
||||
@@ -753,11 +890,11 @@ L$015aw_loop:
|
||||
add edi,32
|
||||
add ebx,32
|
||||
sub ebp,8
|
||||
jnz NEAR L$015aw_loop
|
||||
L$014aw_finish:
|
||||
jnz NEAR L$024aw_loop
|
||||
L$023aw_finish:
|
||||
mov ebp,DWORD [32+esp]
|
||||
and ebp,7
|
||||
jz NEAR L$016aw_end
|
||||
jz NEAR L$025aw_end
|
||||
; Tail Round 0
|
||||
mov ecx,DWORD [esi]
|
||||
mov edx,DWORD [edi]
|
||||
@@ -768,7 +905,7 @@ L$014aw_finish:
|
||||
adc eax,0
|
||||
dec ebp
|
||||
mov DWORD [ebx],ecx
|
||||
jz NEAR L$016aw_end
|
||||
jz NEAR L$025aw_end
|
||||
; Tail Round 1
|
||||
mov ecx,DWORD [4+esi]
|
||||
mov edx,DWORD [4+edi]
|
||||
@@ -779,7 +916,7 @@ L$014aw_finish:
|
||||
adc eax,0
|
||||
dec ebp
|
||||
mov DWORD [4+ebx],ecx
|
||||
jz NEAR L$016aw_end
|
||||
jz NEAR L$025aw_end
|
||||
; Tail Round 2
|
||||
mov ecx,DWORD [8+esi]
|
||||
mov edx,DWORD [8+edi]
|
||||
@@ -790,7 +927,7 @@ L$014aw_finish:
|
||||
adc eax,0
|
||||
dec ebp
|
||||
mov DWORD [8+ebx],ecx
|
||||
jz NEAR L$016aw_end
|
||||
jz NEAR L$025aw_end
|
||||
; Tail Round 3
|
||||
mov ecx,DWORD [12+esi]
|
||||
mov edx,DWORD [12+edi]
|
||||
@@ -801,7 +938,7 @@ L$014aw_finish:
|
||||
adc eax,0
|
||||
dec ebp
|
||||
mov DWORD [12+ebx],ecx
|
||||
jz NEAR L$016aw_end
|
||||
jz NEAR L$025aw_end
|
||||
; Tail Round 4
|
||||
mov ecx,DWORD [16+esi]
|
||||
mov edx,DWORD [16+edi]
|
||||
@@ -812,7 +949,7 @@ L$014aw_finish:
|
||||
adc eax,0
|
||||
dec ebp
|
||||
mov DWORD [16+ebx],ecx
|
||||
jz NEAR L$016aw_end
|
||||
jz NEAR L$025aw_end
|
||||
; Tail Round 5
|
||||
mov ecx,DWORD [20+esi]
|
||||
mov edx,DWORD [20+edi]
|
||||
@@ -823,7 +960,7 @@ L$014aw_finish:
|
||||
adc eax,0
|
||||
dec ebp
|
||||
mov DWORD [20+ebx],ecx
|
||||
jz NEAR L$016aw_end
|
||||
jz NEAR L$025aw_end
|
||||
; Tail Round 6
|
||||
mov ecx,DWORD [24+esi]
|
||||
mov edx,DWORD [24+edi]
|
||||
@@ -833,12 +970,14 @@ L$014aw_finish:
|
||||
sub ecx,edx
|
||||
adc eax,0
|
||||
mov DWORD [24+ebx],ecx
|
||||
L$016aw_end:
|
||||
L$025aw_end:
|
||||
pop edi
|
||||
pop esi
|
||||
pop ebx
|
||||
pop ebp
|
||||
ret
|
||||
segment .bss
|
||||
common _OPENSSL_ia32cap_P 16
|
||||
%else
|
||||
; Work around https://bugzilla.nasm.us/show_bug.cgi?id=3392738
|
||||
ret
|
||||
|
||||
@@ -117,10 +117,7 @@ int bn_uadd_consttime(BIGNUM *r, const BIGNUM *a, const BIGNUM *b) {
|
||||
|
||||
BN_ULONG carry = bn_add_words(r->d, a->d, b->d, min);
|
||||
for (int i = min; i < max; i++) {
|
||||
// |r| and |a| may alias, so use a temporary.
|
||||
BN_ULONG tmp = carry + a->d[i];
|
||||
carry = tmp < a->d[i];
|
||||
r->d[i] = tmp;
|
||||
r->d[i] = CRYPTO_addc_w(a->d[i], 0, carry, &carry);
|
||||
}
|
||||
|
||||
r->d[max] = carry;
|
||||
@@ -241,10 +238,7 @@ int bn_usub_consttime(BIGNUM *r, const BIGNUM *a, const BIGNUM *b) {
|
||||
|
||||
BN_ULONG borrow = bn_sub_words(r->d, a->d, b->d, b_width);
|
||||
for (int i = b_width; i < a->width; i++) {
|
||||
// |r| and |a| may alias, so use a temporary.
|
||||
BN_ULONG tmp = a->d[i];
|
||||
r->d[i] = a->d[i] - borrow;
|
||||
borrow = tmp < r->d[i];
|
||||
r->d[i] = CRYPTO_subc_w(a->d[i], 0, borrow, &borrow);
|
||||
}
|
||||
|
||||
if (borrow) {
|
||||
|
||||
@@ -361,7 +361,7 @@ int bn_wexpand(BIGNUM *bn, size_t words) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
a = OPENSSL_malloc(sizeof(BN_ULONG) * words);
|
||||
a = OPENSSL_calloc(words, sizeof(BN_ULONG));
|
||||
if (a == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -63,26 +63,31 @@
|
||||
|
||||
void bn_big_endian_to_words(BN_ULONG *out, size_t out_len, const uint8_t *in,
|
||||
size_t in_len) {
|
||||
for (size_t i = 0; i < out_len; i++) {
|
||||
if (in_len < sizeof(BN_ULONG)) {
|
||||
// Load the last partial word.
|
||||
BN_ULONG word = 0;
|
||||
for (size_t j = 0; j < in_len; j++) {
|
||||
word = (word << 8) | in[j];
|
||||
}
|
||||
in_len = 0;
|
||||
out[i] = word;
|
||||
// Fill the remainder with zeros.
|
||||
OPENSSL_memset(out + i + 1, 0, (out_len - i - 1) * sizeof(BN_ULONG));
|
||||
break;
|
||||
}
|
||||
// The caller should have sized |out| to fit |in| without truncating. This
|
||||
// condition ensures we do not overflow |out|, so use a runtime check.
|
||||
BSSL_CHECK(in_len <= out_len * sizeof(BN_ULONG));
|
||||
|
||||
// Load whole words.
|
||||
while (in_len >= sizeof(BN_ULONG)) {
|
||||
in_len -= sizeof(BN_ULONG);
|
||||
out[i] = CRYPTO_load_word_be(in + in_len);
|
||||
out[0] = CRYPTO_load_word_be(in + in_len);
|
||||
out++;
|
||||
out_len--;
|
||||
}
|
||||
|
||||
// The caller should have sized the output to avoid truncation.
|
||||
assert(in_len == 0);
|
||||
// Load the last partial word.
|
||||
if (in_len != 0) {
|
||||
BN_ULONG word = 0;
|
||||
for (size_t i = 0; i < in_len; i++) {
|
||||
word = (word << 8) | in[i];
|
||||
}
|
||||
out[0] = word;
|
||||
out++;
|
||||
out_len--;
|
||||
}
|
||||
|
||||
// Fill the remainder with zeros.
|
||||
OPENSSL_memset(out, 0, out_len * sizeof(BN_ULONG));
|
||||
}
|
||||
|
||||
BIGNUM *BN_bin2bn(const uint8_t *in, size_t len, BIGNUM *ret) {
|
||||
@@ -116,7 +121,7 @@ BIGNUM *BN_bin2bn(const uint8_t *in, size_t len, BIGNUM *ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
BIGNUM *BN_le2bn(const uint8_t *in, size_t len, BIGNUM *ret) {
|
||||
BIGNUM *BN_lebin2bn(const uint8_t *in, size_t len, BIGNUM *ret) {
|
||||
BIGNUM *bn = NULL;
|
||||
if (ret == NULL) {
|
||||
bn = BN_new();
|
||||
@@ -149,6 +154,10 @@ BIGNUM *BN_le2bn(const uint8_t *in, size_t len, BIGNUM *ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
BIGNUM *BN_le2bn(const uint8_t *in, size_t len, BIGNUM *ret) {
|
||||
return BN_lebin2bn(in, len, ret);
|
||||
}
|
||||
|
||||
// fits_in_bytes returns one if the |num_words| words in |words| can be
|
||||
// represented in |num_bytes| bytes.
|
||||
static int fits_in_bytes(const BN_ULONG *words, size_t num_words,
|
||||
|
||||
@@ -210,7 +210,7 @@ static int BN_STACK_push(BN_STACK *st, size_t idx) {
|
||||
// This function intentionally does not push to the error queue on error.
|
||||
// Error-reporting is deferred to |BN_CTX_get|.
|
||||
size_t new_size = st->size != 0 ? st->size * 3 / 2 : BN_CTX_START_FRAMES;
|
||||
if (new_size <= st->size || new_size > ((size_t)-1) / sizeof(size_t)) {
|
||||
if (new_size <= st->size || new_size > SIZE_MAX / sizeof(size_t)) {
|
||||
return 0;
|
||||
}
|
||||
size_t *new_indexes =
|
||||
|
||||
@@ -724,7 +724,7 @@ void bn_mod_exp_mont_small(BN_ULONG *r, const BN_ULONG *a, size_t num,
|
||||
const BN_ULONG *p, size_t num_p,
|
||||
const BN_MONT_CTX *mont) {
|
||||
if (num != (size_t)mont->N.width || num > BN_SMALL_MAX_WORDS ||
|
||||
num_p > ((size_t)-1) / BN_BITS2) {
|
||||
num_p > SIZE_MAX / BN_BITS2) {
|
||||
abort();
|
||||
}
|
||||
assert(BN_is_odd(&mont->N));
|
||||
@@ -898,7 +898,9 @@ int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
|
||||
OPENSSL_PUT_ERROR(BN, BN_R_NEGATIVE_NUMBER);
|
||||
return 0;
|
||||
}
|
||||
if (a->neg || BN_ucmp(a, m) >= 0) {
|
||||
// |a| is secret, but it is required to be in range, so these comparisons may
|
||||
// be leaked.
|
||||
if (a->neg || constant_time_declassify_int(BN_ucmp(a, m) >= 0)) {
|
||||
OPENSSL_PUT_ERROR(BN, BN_R_INPUT_NOT_REDUCED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -327,7 +327,10 @@ int BN_mod_inverse_blinded(BIGNUM *out, int *out_no_inverse, const BIGNUM *a,
|
||||
const BN_MONT_CTX *mont, BN_CTX *ctx) {
|
||||
*out_no_inverse = 0;
|
||||
|
||||
if (BN_is_negative(a) || BN_cmp(a, &mont->N) >= 0) {
|
||||
// |a| is secret, but it is required to be in range, so these comparisons may
|
||||
// be leaked.
|
||||
if (BN_is_negative(a) ||
|
||||
constant_time_declassify_int(BN_cmp(a, &mont->N) >= 0)) {
|
||||
OPENSSL_PUT_ERROR(BN, BN_R_INPUT_NOT_REDUCED);
|
||||
return 0;
|
||||
}
|
||||
@@ -336,11 +339,29 @@ int BN_mod_inverse_blinded(BIGNUM *out, int *out_no_inverse, const BIGNUM *a,
|
||||
BIGNUM blinding_factor;
|
||||
BN_init(&blinding_factor);
|
||||
|
||||
if (!BN_rand_range_ex(&blinding_factor, 1, &mont->N) ||
|
||||
!BN_mod_mul_montgomery(out, &blinding_factor, a, mont, ctx) ||
|
||||
!BN_mod_inverse_odd(out, out_no_inverse, out, &mont->N, ctx) ||
|
||||
// |BN_mod_inverse_odd| is leaky, so generate a secret blinding factor and
|
||||
// blind |a|. This works because (ar)^-1 * r = a^-1, supposing r is
|
||||
// invertible. If r is not invertible, this function will fail. However, we
|
||||
// only use this in RSA, where stumbling on an uninvertible element means
|
||||
// stumbling on the key's factorization. That is, if this function fails, the
|
||||
// RSA key was not actually a product of two large primes.
|
||||
//
|
||||
// TODO(crbug.com/boringssl/677): When the PRNG output is marked secret by
|
||||
// default, the explicit |bn_secret| call can be removed.
|
||||
if (!BN_rand_range_ex(&blinding_factor, 1, &mont->N)) {
|
||||
goto err;
|
||||
}
|
||||
bn_secret(&blinding_factor);
|
||||
if (!BN_mod_mul_montgomery(out, &blinding_factor, a, mont, ctx)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
// Once blinded, |out| is no longer secret, so it may be passed to a leaky
|
||||
// mod inverse function. Note |blinding_factor| is secret, so |out| will be
|
||||
// secret again after multiplying.
|
||||
bn_declassify(out);
|
||||
if (!BN_mod_inverse_odd(out, out_no_inverse, out, &mont->N, ctx) ||
|
||||
!BN_mod_mul_montgomery(out, &blinding_factor, out, mont, ctx)) {
|
||||
OPENSSL_PUT_ERROR(BN, ERR_R_BN_LIB);
|
||||
goto err;
|
||||
}
|
||||
|
||||
|
||||
@@ -567,37 +567,6 @@ void bn_sqr_comba4(BN_ULONG r[8], const BN_ULONG a[4]) {
|
||||
|
||||
#if !defined(BN_ADD_ASM)
|
||||
|
||||
// bn_add_with_carry returns |x + y + carry|, and sets |*out_carry| to the
|
||||
// carry bit. |carry| must be zero or one.
|
||||
static inline BN_ULONG bn_add_with_carry(BN_ULONG x, BN_ULONG y, BN_ULONG carry,
|
||||
BN_ULONG *out_carry) {
|
||||
assert(carry == 0 || carry == 1);
|
||||
#if defined(BN_ULLONG)
|
||||
BN_ULLONG ret = carry;
|
||||
ret += (BN_ULLONG)x + y;
|
||||
*out_carry = (BN_ULONG)(ret >> BN_BITS2);
|
||||
return (BN_ULONG)ret;
|
||||
#else
|
||||
x += carry;
|
||||
carry = x < carry;
|
||||
BN_ULONG ret = x + y;
|
||||
carry += ret < x;
|
||||
*out_carry = carry;
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
|
||||
// bn_sub_with_borrow returns |x - y - borrow|, and sets |*out_borrow| to the
|
||||
// borrow bit. |borrow| must be zero or one.
|
||||
static inline BN_ULONG bn_sub_with_borrow(BN_ULONG x, BN_ULONG y,
|
||||
BN_ULONG borrow,
|
||||
BN_ULONG *out_borrow) {
|
||||
assert(borrow == 0 || borrow == 1);
|
||||
BN_ULONG ret = x - y - borrow;
|
||||
*out_borrow = (x < y) | ((x == y) & borrow);
|
||||
return ret;
|
||||
}
|
||||
|
||||
BN_ULONG bn_add_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b,
|
||||
size_t n) {
|
||||
if (n == 0) {
|
||||
@@ -606,17 +575,17 @@ BN_ULONG bn_add_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b,
|
||||
|
||||
BN_ULONG carry = 0;
|
||||
while (n & ~3) {
|
||||
r[0] = bn_add_with_carry(a[0], b[0], carry, &carry);
|
||||
r[1] = bn_add_with_carry(a[1], b[1], carry, &carry);
|
||||
r[2] = bn_add_with_carry(a[2], b[2], carry, &carry);
|
||||
r[3] = bn_add_with_carry(a[3], b[3], carry, &carry);
|
||||
r[0] = CRYPTO_addc_w(a[0], b[0], carry, &carry);
|
||||
r[1] = CRYPTO_addc_w(a[1], b[1], carry, &carry);
|
||||
r[2] = CRYPTO_addc_w(a[2], b[2], carry, &carry);
|
||||
r[3] = CRYPTO_addc_w(a[3], b[3], carry, &carry);
|
||||
a += 4;
|
||||
b += 4;
|
||||
r += 4;
|
||||
n -= 4;
|
||||
}
|
||||
while (n) {
|
||||
r[0] = bn_add_with_carry(a[0], b[0], carry, &carry);
|
||||
r[0] = CRYPTO_addc_w(a[0], b[0], carry, &carry);
|
||||
a++;
|
||||
b++;
|
||||
r++;
|
||||
@@ -633,17 +602,17 @@ BN_ULONG bn_sub_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b,
|
||||
|
||||
BN_ULONG borrow = 0;
|
||||
while (n & ~3) {
|
||||
r[0] = bn_sub_with_borrow(a[0], b[0], borrow, &borrow);
|
||||
r[1] = bn_sub_with_borrow(a[1], b[1], borrow, &borrow);
|
||||
r[2] = bn_sub_with_borrow(a[2], b[2], borrow, &borrow);
|
||||
r[3] = bn_sub_with_borrow(a[3], b[3], borrow, &borrow);
|
||||
r[0] = CRYPTO_subc_w(a[0], b[0], borrow, &borrow);
|
||||
r[1] = CRYPTO_subc_w(a[1], b[1], borrow, &borrow);
|
||||
r[2] = CRYPTO_subc_w(a[2], b[2], borrow, &borrow);
|
||||
r[3] = CRYPTO_subc_w(a[3], b[3], borrow, &borrow);
|
||||
a += 4;
|
||||
b += 4;
|
||||
r += 4;
|
||||
n -= 4;
|
||||
}
|
||||
while (n) {
|
||||
r[0] = bn_sub_with_borrow(a[0], b[0], borrow, &borrow);
|
||||
r[0] = CRYPTO_subc_w(a[0], b[0], borrow, &borrow);
|
||||
a++;
|
||||
b++;
|
||||
r++;
|
||||
|
||||
@@ -149,6 +149,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#define BN_BITS2 64
|
||||
#define BN_BITS2_LG 6
|
||||
#define BN_BYTES 8
|
||||
#define BN_BITS4 32
|
||||
#define BN_MASK2 (0xffffffffffffffffUL)
|
||||
@@ -165,6 +166,7 @@ extern "C" {
|
||||
#define BN_ULLONG uint64_t
|
||||
#define BN_CAN_DIVIDE_ULLONG
|
||||
#define BN_BITS2 32
|
||||
#define BN_BITS2_LG 5
|
||||
#define BN_BYTES 4
|
||||
#define BN_BITS4 16
|
||||
#define BN_MASK2 (0xffffffffUL)
|
||||
@@ -269,6 +271,18 @@ int bn_copy_words(BN_ULONG *out, size_t num, const BIGNUM *bn);
|
||||
// validation.
|
||||
void bn_assert_fits_in_bytes(const BIGNUM *bn, size_t num);
|
||||
|
||||
// bn_secret marks |bn|'s contents, but not its width or sign, as secret. See
|
||||
// |CONSTTIME_SECRET| for details.
|
||||
OPENSSL_INLINE void bn_secret(BIGNUM *bn) {
|
||||
CONSTTIME_SECRET(bn->d, bn->width * sizeof(BN_ULONG));
|
||||
}
|
||||
|
||||
// bn_declassify marks |bn|'s value as public. See |CONSTTIME_DECLASSIFY| for
|
||||
// details.
|
||||
OPENSSL_INLINE void bn_declassify(BIGNUM *bn) {
|
||||
CONSTTIME_DECLASSIFY(bn->d, bn->width * sizeof(BN_ULONG));
|
||||
}
|
||||
|
||||
// bn_mul_add_words multiples |ap| by |w|, adds the result to |rp|, and places
|
||||
// the result in |rp|. |ap| and |rp| must both be |num| words long. It returns
|
||||
// the carry word of the operation. |ap| and |rp| may be equal but otherwise may
|
||||
@@ -386,8 +400,41 @@ int bn_rand_secret_range(BIGNUM *r, int *out_is_uniform, BN_ULONG min_inclusive,
|
||||
// inputs.
|
||||
int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
|
||||
const BN_ULONG *np, const BN_ULONG *n0, size_t num);
|
||||
|
||||
#if defined(OPENSSL_X86_64)
|
||||
OPENSSL_INLINE int bn_mulx_adx_capable(void) {
|
||||
// MULX is in BMI2.
|
||||
return CRYPTO_is_BMI2_capable() && CRYPTO_is_ADX_capable();
|
||||
}
|
||||
int bn_mul_mont_nohw(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
|
||||
const BN_ULONG *np, const BN_ULONG *n0, size_t num);
|
||||
OPENSSL_INLINE int bn_mul4x_mont_capable(size_t num) {
|
||||
return num >= 8 && (num & 3) == 0;
|
||||
}
|
||||
int bn_mul4x_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
|
||||
const BN_ULONG *np, const BN_ULONG *n0, size_t num);
|
||||
OPENSSL_INLINE int bn_mulx4x_mont_capable(size_t num) {
|
||||
return bn_mul4x_mont_capable(num) && bn_mulx_adx_capable();
|
||||
}
|
||||
int bn_mulx4x_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
|
||||
const BN_ULONG *np, const BN_ULONG *n0, size_t num);
|
||||
OPENSSL_INLINE int bn_sqr8x_mont_capable(size_t num) {
|
||||
return num >= 8 && (num & 7) == 0;
|
||||
}
|
||||
int bn_sqr8x_mont(BN_ULONG *rp, const BN_ULONG *ap, BN_ULONG mulx_adx_capable,
|
||||
const BN_ULONG *np, const BN_ULONG *n0, size_t num);
|
||||
#elif defined(OPENSSL_ARM)
|
||||
OPENSSL_INLINE int bn_mul8x_mont_neon_capable(size_t num) {
|
||||
return (num & 7) == 0 && CRYPTO_is_NEON_capable();
|
||||
}
|
||||
int bn_mul8x_mont_neon(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
|
||||
const BN_ULONG *np, const BN_ULONG *n0, size_t num);
|
||||
int bn_mul_mont_nohw(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
|
||||
const BN_ULONG *np, const BN_ULONG *n0, size_t num);
|
||||
#endif
|
||||
|
||||
#endif // OPENSSL_BN_ASM_MONT
|
||||
|
||||
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64)
|
||||
#define OPENSSL_BN_ASM_MONT5
|
||||
|
||||
@@ -754,8 +801,8 @@ void bn_mod_inverse0_prime_mont_small(BN_ULONG *r, const BN_ULONG *a,
|
||||
|
||||
// bn_big_endian_to_words interprets |in_len| bytes from |in| as a big-endian,
|
||||
// unsigned integer and writes the result to |out_len| words in |out|. |out_len|
|
||||
// must be large enough to represent any |in_len|-byte value. That is, |out_len|
|
||||
// must be at least |BN_BYTES * in_len|.
|
||||
// must be large enough to represent any |in_len|-byte value. That is, |in_len|
|
||||
// must be at most |BN_BYTES * out_len|.
|
||||
void bn_big_endian_to_words(BN_ULONG *out, size_t out_len, const uint8_t *in,
|
||||
size_t in_len);
|
||||
|
||||
|
||||
@@ -504,3 +504,29 @@ void bn_mod_mul_montgomery_small(BN_ULONG *r, const BN_ULONG *a,
|
||||
}
|
||||
OPENSSL_cleanse(tmp, 2 * num * sizeof(BN_ULONG));
|
||||
}
|
||||
|
||||
#if defined(OPENSSL_BN_ASM_MONT) && defined(OPENSSL_X86_64)
|
||||
int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
|
||||
const BN_ULONG *np, const BN_ULONG *n0, size_t num) {
|
||||
if (ap == bp && bn_sqr8x_mont_capable(num)) {
|
||||
return bn_sqr8x_mont(rp, ap, bn_mulx_adx_capable(), np, n0, num);
|
||||
}
|
||||
if (bn_mulx4x_mont_capable(num)) {
|
||||
return bn_mulx4x_mont(rp, ap, bp, np, n0, num);
|
||||
}
|
||||
if (bn_mul4x_mont_capable(num)) {
|
||||
return bn_mul4x_mont(rp, ap, bp, np, n0, num);
|
||||
}
|
||||
return bn_mul_mont_nohw(rp, ap, bp, np, n0, num);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(OPENSSL_BN_ASM_MONT) && defined(OPENSSL_ARM)
|
||||
int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
|
||||
const BN_ULONG *np, const BN_ULONG *n0, size_t num) {
|
||||
if (bn_mul8x_mont_neon_capable(num)) {
|
||||
return bn_mul8x_mont_neon(rp, ap, bp, np, n0, num);
|
||||
}
|
||||
return bn_mul_mont_nohw(rp, ap, bp, np, n0, num);
|
||||
}
|
||||
#endif
|
||||
@@ -179,42 +179,43 @@ int bn_mont_ctx_set_RR_consttime(BN_MONT_CTX *mont, BN_CTX *ctx) {
|
||||
// Montgomery domain, 2R or 2^(lgBigR+1), and then use Montgomery
|
||||
// square-and-multiply to exponentiate.
|
||||
//
|
||||
// The multiply steps take 2^n R to 2^(n+1) R. It is faster to double
|
||||
// the value instead. The square steps take 2^n R to 2^(2n) R. This is
|
||||
// equivalent to doubling n times. When n is below some threshold, doubling is
|
||||
// faster. When above, squaring is faster.
|
||||
// The square steps take 2^n R to (2^n)*(2^n) R = 2^2n R. This is the same as
|
||||
// doubling 2^n R, n times (doubling any x, n times, computes 2^n * x). When n
|
||||
// is below some threshold, doubling is faster; when above, squaring is
|
||||
// faster. From benchmarking various 32-bit and 64-bit architectures, the word
|
||||
// count seems to work well as a threshold. (Doubling scales linearly and
|
||||
// Montgomery reduction scales quadratically, so the threshold should scale
|
||||
// roughly linearly.)
|
||||
//
|
||||
// We double to this threshold, then switch to Montgomery squaring. From
|
||||
// benchmarking various 32-bit and 64-bit architectures, the word count seems
|
||||
// to work well as a threshold. (Doubling scales linearly and Montgomery
|
||||
// reduction scales quadratically, so the threshold should scale roughly
|
||||
// linearly.)
|
||||
unsigned threshold = mont->N.width;
|
||||
unsigned iters;
|
||||
for (iters = 0; iters < sizeof(lgBigR) * 8; iters++) {
|
||||
if ((lgBigR >> iters) <= threshold) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// The multiply steps take 2^n R to 2*2^n R = 2^(n+1) R. It is faster to
|
||||
// double the value instead, so the square-and-multiply exponentiation would
|
||||
// become square-and-double. However, when using the word count as the
|
||||
// threshold, it turns out that no multiply/double steps will be needed at
|
||||
// all, because squaring any x, i times, computes x^(2^i):
|
||||
//
|
||||
// (2^threshold)^(2^BN_BITS2_LG) R
|
||||
// (2^mont->N.width)^BN_BITS2 R
|
||||
// = 2^(mont->N.width*BN_BITS2) R
|
||||
// = 2^lgBigR R
|
||||
// = RR
|
||||
int threshold = mont->N.width;
|
||||
|
||||
// Compute 2^(lgBigR >> iters) R, or 2^((lgBigR >> iters) + lgBigR), by
|
||||
// doubling. The first n_bits - 1 doubles can be skipped because we don't need
|
||||
// to reduce.
|
||||
// Calculate 2^threshold R = 2^(threshold + lgBigR) by doubling. The
|
||||
// first n_bits - 1 doubles can be skipped because we don't need to reduce.
|
||||
if (!BN_set_bit(&mont->RR, n_bits - 1) ||
|
||||
!bn_mod_lshift_consttime(&mont->RR, &mont->RR,
|
||||
(lgBigR >> iters) + lgBigR - (n_bits - 1),
|
||||
threshold + (lgBigR - (n_bits - 1)),
|
||||
&mont->N, ctx)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (unsigned i = iters - 1; i < iters; i--) {
|
||||
// The above steps are the same regardless of the threshold. The steps below
|
||||
// need to be modified if the threshold changes.
|
||||
assert(threshold == mont->N.width);
|
||||
for (unsigned i = 0; i < BN_BITS2_LG; i++) {
|
||||
if (!BN_mod_mul_montgomery(&mont->RR, &mont->RR, &mont->RR, mont, ctx)) {
|
||||
return 0;
|
||||
}
|
||||
if ((lgBigR & (1u << i)) != 0 &&
|
||||
!bn_mod_lshift1_consttime(&mont->RR, &mont->RR, &mont->N, ctx)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return bn_resize_words(&mont->RR, mont->N.width);
|
||||
|
||||
@@ -143,17 +143,13 @@ static BN_ULONG bn_sub_part_words(BN_ULONG *r, const BN_ULONG *a,
|
||||
// in |a| were zeros.
|
||||
dl = -dl;
|
||||
for (int i = 0; i < dl; i++) {
|
||||
r[i] = 0u - b[i] - borrow;
|
||||
borrow |= r[i] != 0;
|
||||
r[i] = CRYPTO_subc_w(0, b[i], borrow, &borrow);
|
||||
}
|
||||
} else {
|
||||
// |b| is shorter than |a|. Complete the subtraction as if the excess words
|
||||
// in |b| were zeros.
|
||||
for (int i = 0; i < dl; i++) {
|
||||
// |r| and |a| may alias, so use a temporary.
|
||||
BN_ULONG tmp = a[i];
|
||||
r[i] = a[i] - borrow;
|
||||
borrow = tmp < r[i];
|
||||
r[i] = CRYPTO_subc_w(a[i], 0, borrow, &borrow);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -359,14 +359,7 @@ static int probable_prime_dh(BIGNUM *rnd, int bits, const BIGNUM *add,
|
||||
static int probable_prime_dh_safe(BIGNUM *rnd, int bits, const BIGNUM *add,
|
||||
const BIGNUM *rem, BN_CTX *ctx);
|
||||
|
||||
BN_GENCB *BN_GENCB_new(void) {
|
||||
BN_GENCB *callback = OPENSSL_malloc(sizeof(BN_GENCB));
|
||||
if (callback == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
OPENSSL_memset(callback, 0, sizeof(BN_GENCB));
|
||||
return callback;
|
||||
}
|
||||
BN_GENCB *BN_GENCB_new(void) { return OPENSSL_zalloc(sizeof(BN_GENCB)); }
|
||||
|
||||
void BN_GENCB_free(BN_GENCB *callback) { OPENSSL_free(callback); }
|
||||
|
||||
|
||||
@@ -281,8 +281,14 @@ int bn_rand_range_words(BN_ULONG *out, BN_ULONG min_inclusive,
|
||||
out[words - 1] &= mask;
|
||||
|
||||
// If out >= max_exclusive or out < min_inclusive, retry. This implements
|
||||
// the equivalent of steps 6 and 7 without leaking the value of |out|.
|
||||
} while (!bn_in_range_words(out, min_inclusive, max_exclusive, words));
|
||||
// the equivalent of steps 6 and 7 without leaking the value of |out|. The
|
||||
// result of this comparison may be treated as public. It only reveals how
|
||||
// many attempts were needed before we found a value in range. This is
|
||||
// independent of the final secret output, and has a distribution that
|
||||
// depends only on |min_inclusive| and |max_exclusive|, both of which are
|
||||
// public.
|
||||
} while (!constant_time_declassify_int(
|
||||
bn_in_range_words(out, min_inclusive, max_exclusive, words)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -69,7 +69,6 @@
|
||||
# define VFP_ABI_FRAME 0
|
||||
# define BSAES_ASM_EXTENDED_KEY
|
||||
# define XTS_CHAIN_TWEAK
|
||||
# define __ARM_ARCH__ __LINUX_ARM_ARCH__
|
||||
# define __ARM_MAX_ARCH__ 7
|
||||
#endif
|
||||
|
||||
|
||||
@@ -69,7 +69,6 @@
|
||||
# define VFP_ABI_FRAME 0
|
||||
# define BSAES_ASM_EXTENDED_KEY
|
||||
# define XTS_CHAIN_TWEAK
|
||||
# define __ARM_ARCH__ __LINUX_ARM_ARCH__
|
||||
# define __ARM_MAX_ARCH__ 7
|
||||
#endif
|
||||
|
||||
|
||||
@@ -113,12 +113,11 @@ int EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, const EVP_CIPHER_CTX *in) {
|
||||
OPENSSL_memcpy(out, in, sizeof(EVP_CIPHER_CTX));
|
||||
|
||||
if (in->cipher_data && in->cipher->ctx_size) {
|
||||
out->cipher_data = OPENSSL_malloc(in->cipher->ctx_size);
|
||||
out->cipher_data = OPENSSL_memdup(in->cipher_data, in->cipher->ctx_size);
|
||||
if (!out->cipher_data) {
|
||||
out->cipher = NULL;
|
||||
return 0;
|
||||
}
|
||||
OPENSSL_memcpy(out->cipher_data, in->cipher_data, in->cipher->ctx_size);
|
||||
}
|
||||
|
||||
if (in->cipher->flags & EVP_CIPH_CUSTOM_COPY) {
|
||||
@@ -586,6 +585,16 @@ unsigned EVP_CIPHER_CTX_key_length(const EVP_CIPHER_CTX *ctx) {
|
||||
}
|
||||
|
||||
unsigned EVP_CIPHER_CTX_iv_length(const EVP_CIPHER_CTX *ctx) {
|
||||
if (EVP_CIPHER_mode(ctx->cipher) == EVP_CIPH_GCM_MODE) {
|
||||
int length;
|
||||
int res = EVP_CIPHER_CTX_ctrl((EVP_CIPHER_CTX *)ctx, EVP_CTRL_GET_IVLEN, 0,
|
||||
&length);
|
||||
// EVP_CIPHER_CTX_ctrl returning an error should be impossible under this
|
||||
// circumstance. If it somehow did, fallback to the static cipher iv_len.
|
||||
if (res == 1) {
|
||||
return length;
|
||||
}
|
||||
}
|
||||
return ctx->cipher->iv_len;
|
||||
}
|
||||
|
||||
|
||||
@@ -408,22 +408,6 @@ static void aes_gcm_cleanup(EVP_CIPHER_CTX *c) {
|
||||
}
|
||||
}
|
||||
|
||||
// increment counter (64-bit int) by 1
|
||||
static void ctr64_inc(uint8_t *counter) {
|
||||
int n = 8;
|
||||
uint8_t c;
|
||||
|
||||
do {
|
||||
--n;
|
||||
c = counter[n];
|
||||
++c;
|
||||
counter[n] = c;
|
||||
if (c) {
|
||||
return;
|
||||
}
|
||||
} while (n);
|
||||
}
|
||||
|
||||
static int aes_gcm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) {
|
||||
EVP_AES_GCM_CTX *gctx = aes_gcm_from_cipher_ctx(c);
|
||||
switch (type) {
|
||||
@@ -454,6 +438,10 @@ static int aes_gcm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) {
|
||||
gctx->ivlen = arg;
|
||||
return 1;
|
||||
|
||||
case EVP_CTRL_GET_IVLEN:
|
||||
*(int *)ptr = gctx->ivlen;
|
||||
return 1;
|
||||
|
||||
case EVP_CTRL_AEAD_SET_TAG:
|
||||
if (arg <= 0 || arg > 16 || c->encrypt) {
|
||||
return 0;
|
||||
@@ -481,9 +469,7 @@ static int aes_gcm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) {
|
||||
if (arg < 4 || (gctx->ivlen - arg) < 8) {
|
||||
return 0;
|
||||
}
|
||||
if (arg) {
|
||||
OPENSSL_memcpy(gctx->iv, ptr, arg);
|
||||
}
|
||||
OPENSSL_memcpy(gctx->iv, ptr, arg);
|
||||
if (c->encrypt) {
|
||||
// |RAND_bytes| calls within the fipsmodule should be wrapped with state
|
||||
// lock functions to avoid updating the service indicator with the DRBG
|
||||
@@ -495,7 +481,7 @@ static int aes_gcm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) {
|
||||
gctx->iv_gen = 1;
|
||||
return 1;
|
||||
|
||||
case EVP_CTRL_GCM_IV_GEN:
|
||||
case EVP_CTRL_GCM_IV_GEN: {
|
||||
if (gctx->iv_gen == 0 || gctx->key_set == 0) {
|
||||
return 0;
|
||||
}
|
||||
@@ -504,12 +490,13 @@ static int aes_gcm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) {
|
||||
arg = gctx->ivlen;
|
||||
}
|
||||
OPENSSL_memcpy(ptr, gctx->iv + gctx->ivlen - arg, arg);
|
||||
// Invocation field will be at least 8 bytes in size and
|
||||
// so no need to check wrap around or increment more than
|
||||
// last 8 bytes.
|
||||
ctr64_inc(gctx->iv + gctx->ivlen - 8);
|
||||
// Invocation field will be at least 8 bytes in size, so no need to check
|
||||
// wrap around or increment more than last 8 bytes.
|
||||
uint8_t *ctr = gctx->iv + gctx->ivlen - 8;
|
||||
CRYPTO_store_u64_be(ctr, CRYPTO_load_u64_be(ctr) + 1);
|
||||
gctx->iv_set = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
case EVP_CTRL_GCM_SET_IV_INV:
|
||||
if (gctx->iv_gen == 0 || gctx->key_set == 0 || c->encrypt) {
|
||||
|
||||
@@ -55,6 +55,7 @@
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
#include "../delocate.h"
|
||||
#include "../modes/internal.h"
|
||||
#include "../service_indicator/internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
@@ -66,10 +67,8 @@ struct ccm128_context {
|
||||
};
|
||||
|
||||
struct ccm128_state {
|
||||
union {
|
||||
uint64_t u[2];
|
||||
uint8_t c[16];
|
||||
} nonce, cmac;
|
||||
alignas(16) uint8_t nonce[16];
|
||||
alignas(16) uint8_t cmac[16];
|
||||
};
|
||||
|
||||
static int CRYPTO_ccm128_init(struct ccm128_context *ctx, const AES_KEY *key,
|
||||
@@ -86,7 +85,7 @@ static int CRYPTO_ccm128_init(struct ccm128_context *ctx, const AES_KEY *key,
|
||||
}
|
||||
|
||||
static size_t CRYPTO_ccm128_max_input(const struct ccm128_context *ctx) {
|
||||
return ctx->L >= sizeof(size_t) ? (size_t)-1
|
||||
return ctx->L >= sizeof(size_t) ? SIZE_MAX
|
||||
: (((size_t)1) << (ctx->L * 8)) - 1;
|
||||
}
|
||||
|
||||
@@ -107,16 +106,16 @@ static int ccm128_init_state(const struct ccm128_context *ctx,
|
||||
|
||||
// Assemble the first block for computing the MAC.
|
||||
OPENSSL_memset(state, 0, sizeof(*state));
|
||||
state->nonce.c[0] = (uint8_t)((L - 1) | ((M - 2) / 2) << 3);
|
||||
state->nonce[0] = (uint8_t)((L - 1) | ((M - 2) / 2) << 3);
|
||||
if (aad_len != 0) {
|
||||
state->nonce.c[0] |= 0x40; // Set AAD Flag
|
||||
state->nonce[0] |= 0x40; // Set AAD Flag
|
||||
}
|
||||
OPENSSL_memcpy(&state->nonce.c[1], nonce, nonce_len);
|
||||
OPENSSL_memcpy(&state->nonce[1], nonce, nonce_len);
|
||||
for (unsigned i = 0; i < L; i++) {
|
||||
state->nonce.c[15 - i] = (uint8_t)(plaintext_len >> (8 * i));
|
||||
state->nonce[15 - i] = (uint8_t)(plaintext_len >> (8 * i));
|
||||
}
|
||||
|
||||
(*block)(state->nonce.c, state->cmac.c, key);
|
||||
(*block)(state->nonce, state->cmac, key);
|
||||
size_t blocks = 1;
|
||||
|
||||
if (aad_len != 0) {
|
||||
@@ -124,38 +123,38 @@ static int ccm128_init_state(const struct ccm128_context *ctx,
|
||||
// Cast to u64 to avoid the compiler complaining about invalid shifts.
|
||||
uint64_t aad_len_u64 = aad_len;
|
||||
if (aad_len_u64 < 0x10000 - 0x100) {
|
||||
state->cmac.c[0] ^= (uint8_t)(aad_len_u64 >> 8);
|
||||
state->cmac.c[1] ^= (uint8_t)aad_len_u64;
|
||||
state->cmac[0] ^= (uint8_t)(aad_len_u64 >> 8);
|
||||
state->cmac[1] ^= (uint8_t)aad_len_u64;
|
||||
i = 2;
|
||||
} else if (aad_len_u64 <= 0xffffffff) {
|
||||
state->cmac.c[0] ^= 0xff;
|
||||
state->cmac.c[1] ^= 0xfe;
|
||||
state->cmac.c[2] ^= (uint8_t)(aad_len_u64 >> 24);
|
||||
state->cmac.c[3] ^= (uint8_t)(aad_len_u64 >> 16);
|
||||
state->cmac.c[4] ^= (uint8_t)(aad_len_u64 >> 8);
|
||||
state->cmac.c[5] ^= (uint8_t)aad_len_u64;
|
||||
state->cmac[0] ^= 0xff;
|
||||
state->cmac[1] ^= 0xfe;
|
||||
state->cmac[2] ^= (uint8_t)(aad_len_u64 >> 24);
|
||||
state->cmac[3] ^= (uint8_t)(aad_len_u64 >> 16);
|
||||
state->cmac[4] ^= (uint8_t)(aad_len_u64 >> 8);
|
||||
state->cmac[5] ^= (uint8_t)aad_len_u64;
|
||||
i = 6;
|
||||
} else {
|
||||
state->cmac.c[0] ^= 0xff;
|
||||
state->cmac.c[1] ^= 0xff;
|
||||
state->cmac.c[2] ^= (uint8_t)(aad_len_u64 >> 56);
|
||||
state->cmac.c[3] ^= (uint8_t)(aad_len_u64 >> 48);
|
||||
state->cmac.c[4] ^= (uint8_t)(aad_len_u64 >> 40);
|
||||
state->cmac.c[5] ^= (uint8_t)(aad_len_u64 >> 32);
|
||||
state->cmac.c[6] ^= (uint8_t)(aad_len_u64 >> 24);
|
||||
state->cmac.c[7] ^= (uint8_t)(aad_len_u64 >> 16);
|
||||
state->cmac.c[8] ^= (uint8_t)(aad_len_u64 >> 8);
|
||||
state->cmac.c[9] ^= (uint8_t)aad_len_u64;
|
||||
state->cmac[0] ^= 0xff;
|
||||
state->cmac[1] ^= 0xff;
|
||||
state->cmac[2] ^= (uint8_t)(aad_len_u64 >> 56);
|
||||
state->cmac[3] ^= (uint8_t)(aad_len_u64 >> 48);
|
||||
state->cmac[4] ^= (uint8_t)(aad_len_u64 >> 40);
|
||||
state->cmac[5] ^= (uint8_t)(aad_len_u64 >> 32);
|
||||
state->cmac[6] ^= (uint8_t)(aad_len_u64 >> 24);
|
||||
state->cmac[7] ^= (uint8_t)(aad_len_u64 >> 16);
|
||||
state->cmac[8] ^= (uint8_t)(aad_len_u64 >> 8);
|
||||
state->cmac[9] ^= (uint8_t)aad_len_u64;
|
||||
i = 10;
|
||||
}
|
||||
|
||||
do {
|
||||
for (; i < 16 && aad_len != 0; i++) {
|
||||
state->cmac.c[i] ^= *aad;
|
||||
state->cmac[i] ^= *aad;
|
||||
aad++;
|
||||
aad_len--;
|
||||
}
|
||||
(*block)(state->cmac.c, state->cmac.c, key);
|
||||
(*block)(state->cmac, state->cmac, key);
|
||||
blocks++;
|
||||
i = 0;
|
||||
} while (aad_len != 0);
|
||||
@@ -174,7 +173,7 @@ static int ccm128_init_state(const struct ccm128_context *ctx,
|
||||
// Assemble the first block for encrypting and decrypting. The bottom |L|
|
||||
// bytes are replaced with a counter and all bit the encoding of |L| is
|
||||
// cleared in the first byte.
|
||||
state->nonce.c[0] &= 7;
|
||||
state->nonce[0] &= 7;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -183,17 +182,17 @@ static int ccm128_encrypt(const struct ccm128_context *ctx,
|
||||
uint8_t *out, const uint8_t *in, size_t len) {
|
||||
// The counter for encryption begins at one.
|
||||
for (unsigned i = 0; i < ctx->L; i++) {
|
||||
state->nonce.c[15 - i] = 0;
|
||||
state->nonce[15 - i] = 0;
|
||||
}
|
||||
state->nonce.c[15] = 1;
|
||||
state->nonce[15] = 1;
|
||||
|
||||
uint8_t partial_buf[16];
|
||||
unsigned num = 0;
|
||||
if (ctx->ctr != NULL) {
|
||||
CRYPTO_ctr128_encrypt_ctr32(in, out, len, key, state->nonce.c, partial_buf,
|
||||
CRYPTO_ctr128_encrypt_ctr32(in, out, len, key, state->nonce, partial_buf,
|
||||
&num, ctx->ctr);
|
||||
} else {
|
||||
CRYPTO_ctr128_encrypt(in, out, len, key, state->nonce.c, partial_buf, &num,
|
||||
CRYPTO_ctr128_encrypt(in, out, len, key, state->nonce, partial_buf, &num,
|
||||
ctx->block);
|
||||
}
|
||||
return 1;
|
||||
@@ -209,34 +208,28 @@ static int ccm128_compute_mac(const struct ccm128_context *ctx,
|
||||
}
|
||||
|
||||
// Incorporate |in| into the MAC.
|
||||
union {
|
||||
uint64_t u[2];
|
||||
uint8_t c[16];
|
||||
} tmp;
|
||||
while (len >= 16) {
|
||||
OPENSSL_memcpy(tmp.c, in, 16);
|
||||
state->cmac.u[0] ^= tmp.u[0];
|
||||
state->cmac.u[1] ^= tmp.u[1];
|
||||
(*block)(state->cmac.c, state->cmac.c, key);
|
||||
CRYPTO_xor16(state->cmac, state->cmac, in);
|
||||
(*block)(state->cmac, state->cmac, key);
|
||||
in += 16;
|
||||
len -= 16;
|
||||
}
|
||||
if (len > 0) {
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
state->cmac.c[i] ^= in[i];
|
||||
state->cmac[i] ^= in[i];
|
||||
}
|
||||
(*block)(state->cmac.c, state->cmac.c, key);
|
||||
(*block)(state->cmac, state->cmac, key);
|
||||
}
|
||||
|
||||
// Encrypt the MAC with counter zero.
|
||||
for (unsigned i = 0; i < ctx->L; i++) {
|
||||
state->nonce.c[15 - i] = 0;
|
||||
state->nonce[15 - i] = 0;
|
||||
}
|
||||
(*block)(state->nonce.c, tmp.c, key);
|
||||
state->cmac.u[0] ^= tmp.u[0];
|
||||
state->cmac.u[1] ^= tmp.u[1];
|
||||
alignas(16) uint8_t tmp[16];
|
||||
(*block)(state->nonce, tmp, key);
|
||||
CRYPTO_xor16(state->cmac, state->cmac, tmp);
|
||||
|
||||
OPENSSL_memcpy(out_tag, state->cmac.c, tag_len);
|
||||
OPENSSL_memcpy(out_tag, state->cmac, tag_len);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,12 +57,40 @@
|
||||
#include <CCryptoBoringSSL_dh.h>
|
||||
|
||||
#include <CCryptoBoringSSL_bn.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
int dh_check_params_fast(const DH *dh) {
|
||||
// Most operations scale with p and q.
|
||||
if (BN_is_negative(dh->p) || !BN_is_odd(dh->p) ||
|
||||
BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS) {
|
||||
OPENSSL_PUT_ERROR(DH, DH_R_INVALID_PARAMETERS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// q must be bounded by p.
|
||||
if (dh->q != NULL && (BN_is_negative(dh->q) || BN_ucmp(dh->q, dh->p) > 0)) {
|
||||
OPENSSL_PUT_ERROR(DH, DH_R_INVALID_PARAMETERS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// g must be an element of p's multiplicative group.
|
||||
if (BN_is_negative(dh->g) || BN_is_zero(dh->g) ||
|
||||
BN_ucmp(dh->g, dh->p) >= 0) {
|
||||
OPENSSL_PUT_ERROR(DH, DH_R_INVALID_PARAMETERS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int DH_check_pub_key(const DH *dh, const BIGNUM *pub_key, int *out_flags) {
|
||||
*out_flags = 0;
|
||||
if (!dh_check_params_fast(dh)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
BN_CTX *ctx = BN_CTX_new();
|
||||
if (ctx == NULL) {
|
||||
@@ -73,17 +101,14 @@ int DH_check_pub_key(const DH *dh, const BIGNUM *pub_key, int *out_flags) {
|
||||
int ok = 0;
|
||||
|
||||
// Check |pub_key| is greater than 1.
|
||||
BIGNUM *tmp = BN_CTX_get(ctx);
|
||||
if (tmp == NULL ||
|
||||
!BN_set_word(tmp, 1)) {
|
||||
goto err;
|
||||
}
|
||||
if (BN_cmp(pub_key, tmp) <= 0) {
|
||||
if (BN_cmp(pub_key, BN_value_one()) <= 0) {
|
||||
*out_flags |= DH_CHECK_PUBKEY_TOO_SMALL;
|
||||
}
|
||||
|
||||
// Check |pub_key| is less than |dh->p| - 1.
|
||||
if (!BN_copy(tmp, dh->p) ||
|
||||
BIGNUM *tmp = BN_CTX_get(ctx);
|
||||
if (tmp == NULL ||
|
||||
!BN_copy(tmp, dh->p) ||
|
||||
!BN_sub_word(tmp, 1)) {
|
||||
goto err;
|
||||
}
|
||||
@@ -113,6 +138,11 @@ err:
|
||||
|
||||
|
||||
int DH_check(const DH *dh, int *out_flags) {
|
||||
*out_flags = 0;
|
||||
if (!dh_check_params_fast(dh)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Check that p is a safe prime and if g is 2, 3 or 5, check that it is a
|
||||
// suitable generator where:
|
||||
// for 2, p mod 24 == 11
|
||||
@@ -124,7 +154,6 @@ int DH_check(const DH *dh, int *out_flags) {
|
||||
BN_ULONG l;
|
||||
BIGNUM *t1 = NULL, *t2 = NULL;
|
||||
|
||||
*out_flags = 0;
|
||||
ctx = BN_CTX_new();
|
||||
if (ctx == NULL) {
|
||||
goto err;
|
||||
|
||||
@@ -70,20 +70,14 @@
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
#define OPENSSL_DH_MAX_MODULUS_BITS 10000
|
||||
|
||||
DH *DH_new(void) {
|
||||
DH *dh = OPENSSL_malloc(sizeof(DH));
|
||||
DH *dh = OPENSSL_zalloc(sizeof(DH));
|
||||
if (dh == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
OPENSSL_memset(dh, 0, sizeof(DH));
|
||||
|
||||
CRYPTO_MUTEX_init(&dh->method_mont_p_lock);
|
||||
|
||||
dh->references = 1;
|
||||
|
||||
return dh;
|
||||
}
|
||||
|
||||
@@ -191,15 +185,14 @@ int DH_set_length(DH *dh, unsigned priv_length) {
|
||||
int DH_generate_key(DH *dh) {
|
||||
boringssl_ensure_ffdh_self_test();
|
||||
|
||||
if (!dh_check_params_fast(dh)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ok = 0;
|
||||
int generate_new_key = 0;
|
||||
BN_CTX *ctx = NULL;
|
||||
BIGNUM *pub_key = NULL, *priv_key = NULL;
|
||||
|
||||
if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS) {
|
||||
OPENSSL_PUT_ERROR(DH, DH_R_MODULUS_TOO_LARGE);
|
||||
goto err;
|
||||
}
|
||||
BIGNUM *pub_key = NULL, *priv_key = NULL, *priv_key_limit = NULL;
|
||||
|
||||
ctx = BN_CTX_new();
|
||||
if (ctx == NULL) {
|
||||
@@ -232,22 +225,44 @@ int DH_generate_key(DH *dh) {
|
||||
|
||||
if (generate_new_key) {
|
||||
if (dh->q) {
|
||||
if (!BN_rand_range_ex(priv_key, 2, dh->q)) {
|
||||
// Section 5.6.1.1.4 of SP 800-56A Rev3 generates a private key uniformly
|
||||
// from [1, min(2^N-1, q-1)].
|
||||
//
|
||||
// Although SP 800-56A Rev3 now permits a private key length N,
|
||||
// |dh->priv_length| historically was ignored when q is available. We
|
||||
// continue to ignore it and interpret such a configuration as N = len(q).
|
||||
if (!BN_rand_range_ex(priv_key, 1, dh->q)) {
|
||||
goto err;
|
||||
}
|
||||
} else {
|
||||
// secret exponent length
|
||||
unsigned priv_bits = dh->priv_length;
|
||||
if (priv_bits == 0) {
|
||||
const unsigned p_bits = BN_num_bits(dh->p);
|
||||
if (p_bits == 0) {
|
||||
// If q is unspecified, we expect p to be a safe prime, with g generating
|
||||
// the (p-1)/2 subgroup. So, we use q = (p-1)/2. (If g generates a smaller
|
||||
// prime-order subgroup, q will still divide (p-1)/2.)
|
||||
//
|
||||
// We set N from |dh->priv_length|. Section 5.6.1.1.4 of SP 800-56A Rev3
|
||||
// says to reject N > len(q), or N > num_bits(p) - 1. However, this logic
|
||||
// originally aligned with PKCS#3, which allows num_bits(p). Instead, we
|
||||
// clamp |dh->priv_length| before invoking the algorithm.
|
||||
|
||||
// Compute M = min(2^N, q).
|
||||
priv_key_limit = BN_new();
|
||||
if (priv_key_limit == NULL) {
|
||||
goto err;
|
||||
}
|
||||
if (dh->priv_length == 0 || dh->priv_length >= BN_num_bits(dh->p) - 1) {
|
||||
// M = q = (p - 1) / 2.
|
||||
if (!BN_rshift1(priv_key_limit, dh->p)) {
|
||||
goto err;
|
||||
}
|
||||
} else {
|
||||
// M = 2^N.
|
||||
if (!BN_set_bit(priv_key_limit, dh->priv_length)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
priv_bits = p_bits - 1;
|
||||
}
|
||||
|
||||
if (!BN_rand(priv_key, priv_bits, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY)) {
|
||||
// Choose a private key uniformly from [1, M-1].
|
||||
if (!BN_rand_range_ex(priv_key, 1, priv_key_limit)) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
@@ -273,14 +288,14 @@ err:
|
||||
if (dh->priv_key == NULL) {
|
||||
BN_free(priv_key);
|
||||
}
|
||||
BN_free(priv_key_limit);
|
||||
BN_CTX_free(ctx);
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int dh_compute_key(DH *dh, BIGNUM *out_shared_key,
|
||||
const BIGNUM *peers_key, BN_CTX *ctx) {
|
||||
if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS) {
|
||||
OPENSSL_PUT_ERROR(DH, DH_R_MODULUS_TOO_LARGE);
|
||||
if (!dh_check_params_fast(dh)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -379,7 +394,7 @@ int DH_compute_key(unsigned char *out, const BIGNUM *peers_key, DH *dh) {
|
||||
int DH_compute_key_hashed(DH *dh, uint8_t *out, size_t *out_len,
|
||||
size_t max_out_len, const BIGNUM *peers_key,
|
||||
const EVP_MD *digest) {
|
||||
*out_len = (size_t)-1;
|
||||
*out_len = SIZE_MAX;
|
||||
|
||||
const size_t digest_len = EVP_MD_size(digest);
|
||||
if (digest_len > max_out_len) {
|
||||
|
||||
@@ -26,6 +26,8 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
#define OPENSSL_DH_MAX_MODULUS_BITS 10000
|
||||
|
||||
struct dh_st {
|
||||
BIGNUM *p;
|
||||
BIGNUM *g;
|
||||
@@ -44,6 +46,11 @@ struct dh_st {
|
||||
CRYPTO_refcount_t references;
|
||||
};
|
||||
|
||||
// dh_check_params_fast checks basic invariants on |dh|'s domain parameters. It
|
||||
// does not check that |dh| forms a valid group, only that the sizes are within
|
||||
// DoS bounds.
|
||||
int dh_check_params_fast(const DH *dh);
|
||||
|
||||
// dh_compute_key_padded_no_self_test does the same as |DH_compute_key_padded|,
|
||||
// but doesn't try to run the self-test first. This is for use in the self tests
|
||||
// themselves, to prevent an infinite loop.
|
||||
|
||||
@@ -185,6 +185,10 @@ int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in) {
|
||||
void EVP_MD_CTX_move(EVP_MD_CTX *out, EVP_MD_CTX *in) {
|
||||
EVP_MD_CTX_cleanup(out);
|
||||
// While not guaranteed, |EVP_MD_CTX| is currently safe to move with |memcpy|.
|
||||
// bssl-crypto currently relies on this, however, so if we change this, we
|
||||
// need to box the |HMAC_CTX|. (Relying on this is only fine because we assume
|
||||
// BoringSSL and bssl-crypto will always be updated atomically. We do not
|
||||
// allow any version skew between the two.)
|
||||
OPENSSL_memcpy(out, in, sizeof(EVP_MD_CTX));
|
||||
EVP_MD_CTX_init(in);
|
||||
}
|
||||
|
||||
Loaded 100 of 347 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user