Compare commits

..
3 Commits
Author SHA1 Message Date
Cory Benfield 60f13f60c4 Update BoringSSL to 7ae2b910c13017b63f1a8bd6c8decfce692869b0 (#190) (#193)
* Update vendoring script to use docker

* Update BoringSSL to 7ae2b910c13017b63f1a8bd6c8decfce692869b0

* RSA is opaque now

(cherry picked from commit a234f8a62e)
2023-08-03 17:02:34 +01:00
Cory BenfieldandFranz Busch b71d0c1c9b Switch to canImport instead of os conditions (#184) (#192)
* Rework canImport to just defines with platform conditions

* Soundness and make

---------

Co-authored-by: Cory Benfield <lukasa@apple.com>
(cherry picked from commit 9c1b699540)

Co-authored-by: Franz Busch <f.busch@apple.com>
2023-08-03 16:54:00 +01:00
Cory BenfieldandGwynne Raskind ac03330c12 Add API providing basic RSA pubkey encrypt and privkey decrypt (#125) (#191)
* Add basic RSA encrypt/decrypt API.

* Add test vectors and tests for RSA encryption API

* Fix build failures

* Fix soundness issue

* Remove support for RSA encryption using the unsafe PKCS1 v1.5 padding

* Fix deprecation warning about the "pointer" version of Data.withUnsafeMutableBytes() by nudging the compiler to infer the "buffer" version.

* Fix deprecation warning about String.init(bytesNoCopy:length:freeWhenDone:) by using String.init(unsafeInitializedCapacity:initializingWith:) instead.

* Make _RSA.Encryption.[Public|Private]Key their own types

* Remove _RSA.Encryption.RSA[Encrypted|Decrypted]Data and just use Data directly. Don't use intermediate Array in BoringSSL implementations.

* Document the message size limits on RSA encrypt/decrypt operations

* Mark `_RSA` visible to documentation so the new docs can actually be seen (underscored name is assumed private by default)

* Fix generic type parameter shadowing warning (new warning in Swift 5.9)

* Fix pre-5.8 build

* Un-correct switch case indentation to make it wrong

(cherry picked from commit 5ac5632286)

Co-authored-by: Gwynne Raskind <gwynne@darkrainfall.org>
2023-08-03 16:20:19 +01:00
333 changed files with 7584 additions and 15827 deletions

No files matched your search

-1
View File
@@ -15,4 +15,3 @@ DerivedData
.*.sw[nop]
.vscode
+10 -17
View File
@@ -1,4 +1,4 @@
// swift-tools-version:5.7
// swift-tools-version:5.6
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftCrypto open source project
@@ -20,7 +20,7 @@
// Sources/CCryptoBoringSSL directory. The source repository is at
// https://boringssl.googlesource.com/boringssl.
//
// BoringSSL Commit: 7a813621dac6878ab53b6ed7392939a8982226e8
// BoringSSL Commit: 7ae2b910c13017b63f1a8bd6c8decfce692869b0
import PackageDescription
@@ -89,11 +89,12 @@ let package = Package(
"crypto/bio/socket.c"
],
cSettings: [
// These defines come from BoringSSL's build system
.define("_HAS_EXCEPTIONS", to: "0", .when(platforms: [Platform.windows])),
.define("WIN32_LEAN_AND_MEAN", .when(platforms: [Platform.windows])),
.define("NOMINMAX", .when(platforms: [Platform.windows])),
.define("_CRT_SECURE_NO_WARNINGS", .when(platforms: [Platform.windows])),
/*
* This define is required on Windows, but because we need older
* versions of SPM, we cannot conditionally define this on Windows
* only. Unconditionally define it instead.
*/
.define("WIN32_LEAN_AND_MEAN"),
/*
* These defines are required on Wasm/WASI, to disable use of pthread.
*/
@@ -130,8 +131,7 @@ let package = Package(
],
exclude: [
"CMakeLists.txt",
],
swiftSettings: swiftSettings
]
),
.target(
name: "CryptoBoringWrapper",
@@ -144,14 +144,7 @@ let package = Package(
]
),
.executableTarget(name: "crypto-shasum", dependencies: ["Crypto"]),
.testTarget(
name: "CryptoTests",
dependencies: ["Crypto"],
resources: [
.copy("HPKE/hpke-test-vectors.json"),
],
swiftSettings: swiftSettings
),
.testTarget(name: "CryptoTests", dependencies: ["Crypto"], swiftSettings: swiftSettings),
.testTarget(name: "_CryptoExtrasTests", dependencies: ["_CryptoExtras"]),
],
cxxLanguageStandard: .cxx11
+2 -3
View File
@@ -108,15 +108,14 @@ 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.7 and newer. The minimum Swift version supported by Swift Crypto releases are detailed below:
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:
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 ..< 3.1.0` | 5.6
`3.1.0 ...` | 5.7
`2.4.2 ...` | 5.6
### Compatibility
+28 -32
View File
@@ -80,6 +80,7 @@ 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"
@@ -198,7 +199,7 @@ add_library(CCryptoBoringSSL STATIC
"crypto/fipsmodule/tls/kdf.c"
"crypto/hpke/hpke.c"
"crypto/hrss/hrss.c"
"crypto/keccak/keccak.c"
"crypto/kyber/keccak.c"
"crypto/kyber/kyber.c"
"crypto/lhash/lhash.c"
"crypto/mem.c"
@@ -235,13 +236,6 @@ 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"
@@ -265,29 +259,6 @@ 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"
@@ -312,14 +283,39 @@ 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/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")
if(CMAKE_SYSTEM_NAME STREQUAL Darwin AND CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x86_64")
target_sources(CCryptoBoringSSL PRIVATE
@@ -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);
+21 -8
View File
@@ -68,7 +68,6 @@
#include <CCryptoBoringSSL_mem.h>
#include "../bytestring/internal.h"
#include "../internal.h"
#include "internal.h"
@@ -138,19 +137,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:
@@ -173,7 +172,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;
}
@@ -239,8 +238,22 @@ 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;
OPENSSL_memset(&t, 0, sizeof(ASN1_TYPE));
asn1_type_set0_string(&t, (ASN1_STRING *)str);
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;
unsigned char *der_buf = NULL;
int der_len = i2d_ASN1_TYPE(&t, &der_buf);
if (der_len < 0) {
+1 -19
View File
@@ -56,8 +56,7 @@
#include <CCryptoBoringSSL_asn1.h>
#include <assert.h>
#include <CCryptoBoringSSL_asn1t.h>
#include <CCryptoBoringSSL_err.h>
#include <CCryptoBoringSSL_mem.h>
#include <CCryptoBoringSSL_obj.h>
@@ -90,23 +89,6 @@ 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:
@@ -102,15 +102,6 @@ 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,
@@ -282,8 +273,9 @@ int ASN1_STRING_set(ASN1_STRING *str, const void *_data, ossl_ssize_t len_s) {
len = (size_t)len_s;
}
static_assert(ASN1_STRING_MAX < INT_MAX, "len will not overflow int");
if (len > ASN1_STRING_MAX) {
// |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) {
OPENSSL_PUT_ERROR(ASN1, ERR_R_OVERFLOW);
return 0;
}
@@ -210,10 +210,6 @@ 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);
@@ -260,6 +256,7 @@ typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
typedef struct ASN1_EXTERN_FUNCS_st {
ASN1_ex_new_func *asn1_ex_new;
ASN1_ex_free_func *asn1_ex_free;
ASN1_ex_free_func *asn1_ex_clear;
ASN1_ex_d2i *asn1_ex_d2i;
ASN1_ex_i2d *asn1_ex_i2d;
} ASN1_EXTERN_FUNCS;
@@ -850,7 +850,7 @@ static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, long len,
if (utype == V_ASN1_BMPSTRING) {
while (CBS_len(&cbs) != 0) {
uint32_t c;
if (!CBS_get_ucs2_be(&cbs, &c)) {
if (!cbs_get_ucs2_be(&cbs, &c)) {
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_BMPSTRING);
goto err;
}
@@ -859,7 +859,7 @@ static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, long len,
if (utype == V_ASN1_UNIVERSALSTRING) {
while (CBS_len(&cbs) != 0) {
uint32_t c;
if (!CBS_get_utf32_be(&cbs, &c)) {
if (!cbs_get_utf32_be(&cbs, &c)) {
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_UNIVERSALSTRING);
goto err;
}
@@ -868,7 +868,7 @@ static int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, long len,
if (utype == V_ASN1_UTF8STRING) {
while (CBS_len(&cbs) != 0) {
uint32_t c;
if (!CBS_get_utf8(&cbs, &c)) {
if (!cbs_get_utf8(&cbs, &c)) {
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_UTF8STRING);
goto err;
}
@@ -452,9 +452,14 @@ 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_calloc(sk_ASN1_VALUE_num(sk), sizeof(*encoded));
DER_ENC *encoded = OPENSSL_malloc(sk_ASN1_VALUE_num(sk) * sizeof(*encoded));
if (encoded == NULL || buf == NULL) {
goto err;
}
@@ -127,10 +127,11 @@ int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it) {
return 1;
}
}
*pval = OPENSSL_zalloc(it->size);
*pval = OPENSSL_malloc(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;
@@ -150,10 +151,11 @@ int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it) {
return 1;
}
}
*pval = OPENSSL_zalloc(it->size);
*pval = OPENSSL_malloc(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++) {
@@ -183,9 +185,16 @@ 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:
*pval = NULL;
ef = it->funcs;
if (ef && ef->asn1_ex_clear) {
ef->asn1_ex_clear(pval, it);
} else {
*pval = NULL;
}
break;
case ASN1_ITYPE_PRIMITIVE:
@@ -267,7 +276,7 @@ static int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it) {
}
switch (utype) {
case V_ASN1_OBJECT:
*pval = (ASN1_VALUE *)OBJ_get_undef();
*pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef);
return 1;
case V_ASN1_BOOLEAN:
@@ -121,7 +121,12 @@ int EVP_EncodedLength(size_t *out_len, size_t len) {
}
EVP_ENCODE_CTX *EVP_ENCODE_CTX_new(void) {
return OPENSSL_zalloc(sizeof(EVP_ENCODE_CTX));
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;
}
void EVP_ENCODE_CTX_free(EVP_ENCODE_CTX *ctx) {
+4 -27
View File
@@ -69,19 +69,16 @@
#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_zalloc(sizeof(BIO));
BIO *ret = OPENSSL_malloc(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);
@@ -105,7 +102,6 @@ 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;
@@ -644,10 +640,11 @@ int BIO_get_new_index(void) {
}
BIO_METHOD *BIO_meth_new(int type, const char *name) {
BIO_METHOD *method = OPENSSL_zalloc(sizeof(BIO_METHOD));
BIO_METHOD *method = OPENSSL_malloc(sizeof(BIO_METHOD));
if (method == NULL) {
return NULL;
}
OPENSSL_memset(method, 0, sizeof(BIO_METHOD));
method->type = type;
method->name = name;
return method;
@@ -709,23 +706,3 @@ int BIO_meth_set_puts(BIO_METHOD *method, int (*puts)(BIO *, const char *)) {
// Ignore the parameter. We implement |BIO_puts| using |BIO_write|.
return 1;
}
int BIO_get_ex_new_index(long argl, void *argp,
CRYPTO_EX_unused *unused,
CRYPTO_EX_dup *dup_unused,
CRYPTO_EX_free *free_func) {
int index;
if (!CRYPTO_get_ex_new_index(&g_ex_data_class, &index, argl, argp,
free_func)) {
return -1;
}
return index;
}
int BIO_set_ex_data(BIO *bio, int idx, void *data) {
return CRYPTO_set_ex_data(&bio->ex_data, idx, data);
}
void *BIO_get_ex_data(const BIO *bio, int idx) {
return CRYPTO_get_ex_data(&bio->ex_data, idx);
}
@@ -296,10 +296,13 @@ end:
}
static BIO_CONNECT *BIO_CONNECT_new(void) {
BIO_CONNECT *ret = OPENSSL_zalloc(sizeof(BIO_CONNECT));
BIO_CONNECT *ret = OPENSSL_malloc(sizeof(BIO_CONNECT));
if (ret == NULL) {
return NULL;
}
OPENSSL_memset(ret, 0, sizeof(BIO_CONNECT));
ret->state = BIO_CONN_S_BEFORE;
return ret;
}
+4 -1
View File
@@ -81,10 +81,13 @@ struct bio_bio_st {
};
static int bio_new(BIO *bio) {
struct bio_bio_st *b = OPENSSL_zalloc(sizeof *b);
struct bio_bio_st *b;
b = OPENSSL_malloc(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,11 +455,3 @@ 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;
}
+11 -1
View File
@@ -64,7 +64,17 @@
#include "../internal.h"
BUF_MEM *BUF_MEM_new(void) { return OPENSSL_zalloc(sizeof(BUF_MEM)); }
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;
}
void BUF_MEM_free(BUF_MEM *buf) {
if (buf == NULL) {
@@ -155,29 +155,6 @@ 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.
@@ -267,7 +244,7 @@ int CBB_flush(CBB *cbb) {
return 1;
err:
cbb_on_error(cbb);
base->error = 1;
return 0;
}
@@ -443,7 +420,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_on_error(cbb);
cbb_get_base(cbb)->error = 1;
return 0;
}
@@ -502,7 +479,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)) {
goto err;
return 0;
}
int started = 0;
@@ -516,25 +493,21 @@ 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)) {
goto err;
return 0;
}
started = 1;
}
if (!CBB_add_u8(&child, byte)) {
goto err;
return 0;
}
}
// 0 is encoded as a single 0, not the empty string.
if (!started && !CBB_add_u8(&child, 0)) {
goto err;
return 0;
}
return CBB_flush(cbb);
err:
cbb_on_error(cbb);
return 0;
}
int CBB_add_asn1_int64(CBB *cbb, int64_t value) {
@@ -556,18 +529,14 @@ 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)) {
goto err;
return 0;
}
for (int i = start; i >= 0; i--) {
if (!CBB_add_u8(&child, bytes[i])) {
goto err;
return 0;
}
}
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) {
@@ -575,7 +544,6 @@ 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;
}
@@ -587,7 +555,6 @@ 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;
}
@@ -682,13 +649,16 @@ 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_calloc(num_children, sizeof(CBS));
CBS *children = OPENSSL_malloc(num_children * sizeof(CBS));
if (buf == NULL || children == NULL) {
goto err;
}
@@ -67,6 +67,28 @@ 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,19 +31,49 @@ 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_nohw
.private_extern _ChaCha20_ctr32_nohw
.globl _ChaCha20_ctr32
.private_extern _ChaCha20_ctr32
#ifdef __thumb2__
.thumb_func _ChaCha20_ctr32_nohw
.thumb_func _ChaCha20_ctr32
#endif
.align 5
_ChaCha20_ctr32_nohw:
_ChaCha20_ctr32:
LChaCha20_ctr32:
ldr r12,[sp,#0] @ pull pointer to counter and nonce
stmdb sp!,{r0,r1,r2,r4-r11,lr}
adr r14,Lsigma
#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
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
@@ -204,8 +234,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)]
@@ -231,7 +261,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
@@ -268,7 +298,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
@@ -313,7 +343,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
@@ -355,7 +385,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
@@ -386,7 +416,7 @@ Loop:
bhi Loop_outer
beq Ldone
# if __ARM_ARCH<7
# if __ARM_ARCH__<7
b Ltail
.align 4
@@ -394,7 +424,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
@@ -770,21 +800,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_ctr32_neon
.thumb_func ChaCha20_neon
#endif
.align 5
_ChaCha20_ctr32_neon:
ChaCha20_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}
@@ -1453,6 +1483,11 @@ 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,17 +31,47 @@
.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_nohw
.hidden ChaCha20_ctr32_nohw
.type ChaCha20_ctr32_nohw,%function
.globl ChaCha20_ctr32
.hidden ChaCha20_ctr32
.type ChaCha20_ctr32,%function
.align 5
ChaCha20_ctr32_nohw:
ChaCha20_ctr32:
.LChaCha20_ctr32:
ldr r12,[sp,#0] @ pull pointer to counter and nonce
stmdb sp!,{r0,r1,r2,r4-r11,lr}
adr r14,.Lsigma
#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
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
@@ -202,8 +232,8 @@ ChaCha20_ctr32_nohw:
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)]
@@ -229,7 +259,7 @@ ChaCha20_ctr32_nohw:
# 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
@@ -266,7 +296,7 @@ ChaCha20_ctr32_nohw:
# 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
@@ -311,7 +341,7 @@ ChaCha20_ctr32_nohw:
# 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
@@ -353,7 +383,7 @@ ChaCha20_ctr32_nohw:
# 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
@@ -384,7 +414,7 @@ ChaCha20_ctr32_nohw:
bhi .Loop_outer
beq .Ldone
# if __ARM_ARCH<7
# if __ARM_ARCH__<7
b .Ltail
.align 4
@@ -392,7 +422,7 @@ ChaCha20_ctr32_nohw:
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
@@ -768,19 +798,19 @@ ChaCha20_ctr32_nohw:
.Ldone:
add sp,sp,#4*(32+3)
.Lno_data:
ldmia sp!,{r4,r5,r6,r7,r8,r9,r10,r11,pc}
.size ChaCha20_ctr32_nohw,.-ChaCha20_ctr32_nohw
.size ChaCha20_ctr32,.-ChaCha20_ctr32
#if __ARM_MAX_ARCH__>=7
.arch armv7-a
.fpu neon
.globl ChaCha20_ctr32_neon
.hidden ChaCha20_ctr32_neon
.type ChaCha20_ctr32_neon,%function
.type ChaCha20_neon,%function
.align 5
ChaCha20_ctr32_neon:
ChaCha20_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}
@@ -1448,7 +1478,8 @@ ChaCha20_ctr32_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_ctr32_neon,.-ChaCha20_ctr32_neon
.size ChaCha20_neon,.-ChaCha20_neon
.comm OPENSSL_armcap_P,4,4
#endif
#endif // !OPENSSL_NO_ASM && defined(OPENSSL_ARM) && defined(__ELF__)
#endif // defined(__arm__) && defined(__linux__)
@@ -8,6 +8,9 @@
#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
@@ -20,11 +23,25 @@ Lone:
.text
.globl _ChaCha20_ctr32_nohw
.private_extern _ChaCha20_ctr32_nohw
.globl _ChaCha20_ctr32
.private_extern _ChaCha20_ctr32
.align 5
_ChaCha20_ctr32_nohw:
_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:
AARCH64_SIGN_LINK_REGISTER
stp x29,x30,[sp,#-96]!
add x29,sp,#0
@@ -239,6 +256,7 @@ Loop:
ldp x27,x28,[x29,#80]
ldp x29,x30,[sp],#96
AARCH64_VALIDATE_LINK_REGISTER
Labort:
ret
.align 4
@@ -298,11 +316,9 @@ Loop_tail:
ret
.globl _ChaCha20_ctr32_neon
.private_extern _ChaCha20_ctr32_neon
.align 5
_ChaCha20_ctr32_neon:
ChaCha20_neon:
AARCH64_SIGN_LINK_REGISTER
stp x29,x30,[sp,#-96]!
add x29,sp,#0
@@ -8,6 +8,9 @@
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_AARCH64) && defined(__ELF__)
#include <CCryptoBoringSSL_arm_arch.h>
.hidden OPENSSL_armcap_P
.section .rodata
.align 5
@@ -20,11 +23,25 @@
.text
.globl ChaCha20_ctr32_nohw
.hidden ChaCha20_ctr32_nohw
.type ChaCha20_ctr32_nohw,%function
.globl ChaCha20_ctr32
.hidden ChaCha20_ctr32
.type ChaCha20_ctr32,%function
.align 5
ChaCha20_ctr32_nohw:
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:
AARCH64_SIGN_LINK_REGISTER
stp x29,x30,[sp,#-96]!
add x29,sp,#0
@@ -239,6 +256,7 @@ ChaCha20_ctr32_nohw:
ldp x27,x28,[x29,#80]
ldp x29,x30,[sp],#96
AARCH64_VALIDATE_LINK_REGISTER
.Labort:
ret
.align 4
@@ -296,13 +314,11 @@ ChaCha20_ctr32_nohw:
ldp x29,x30,[sp],#96
AARCH64_VALIDATE_LINK_REGISTER
ret
.size ChaCha20_ctr32_nohw,.-ChaCha20_ctr32_nohw
.size ChaCha20_ctr32,.-ChaCha20_ctr32
.globl ChaCha20_ctr32_neon
.hidden ChaCha20_ctr32_neon
.type ChaCha20_ctr32_neon,%function
.type ChaCha20_neon,%function
.align 5
ChaCha20_ctr32_neon:
ChaCha20_neon:
AARCH64_SIGN_LINK_REGISTER
stp x29,x30,[sp,#-96]!
add x29,sp,#0
@@ -796,7 +812,7 @@ ChaCha20_ctr32_neon:
ldp x29,x30,[sp],#96
AARCH64_VALIDATE_LINK_REGISTER
ret
.size ChaCha20_ctr32_neon,.-ChaCha20_ctr32_neon
.size ChaCha20_neon,.-ChaCha20_neon
.type ChaCha20_512_neon,%function
.align 5
ChaCha20_512_neon:
@@ -329,7 +329,7 @@ _CET_ENDBR
leaq (%rsi),%rsp
.cfi_adjust_cfa_offset -136
.Lno_data:
ret
.byte 0xf3,0xc3
.cfi_endproc
.size ChaCha20_ctr32,.-ChaCha20_ctr32
.type ChaCha20_ssse3,@function
@@ -466,7 +466,7 @@ ChaCha20_ssse3:
leaq (%r9),%rsp
.cfi_def_cfa_register rsp
.Lssse3_epilogue:
ret
.byte 0xf3,0xc3
.cfi_endproc
.size ChaCha20_ssse3,.-ChaCha20_ssse3
.type ChaCha20_4x,@function
@@ -1018,7 +1018,7 @@ ChaCha20_4x:
leaq (%r9),%rsp
.cfi_def_cfa_register rsp
.L4x_epilogue:
ret
.byte 0xf3,0xc3
.cfi_endproc
.size ChaCha20_4x,.-ChaCha20_4x
.type ChaCha20_8x,@function
@@ -1624,7 +1624,7 @@ ChaCha20_8x:
leaq (%r9),%rsp
.cfi_def_cfa_register rsp
.L8x_epilogue:
ret
.byte 0xf3,0xc3
.cfi_endproc
.size ChaCha20_8x,.-ChaCha20_8x
#endif
@@ -322,7 +322,7 @@ L$done:
leaq (%rsi),%rsp
L$no_data:
ret
.byte 0xf3,0xc3
@@ -459,7 +459,7 @@ L$done_ssse3:
leaq (%r9),%rsp
L$ssse3_epilogue:
ret
.byte 0xf3,0xc3
@@ -1011,7 +1011,7 @@ L$done4x:
leaq (%r9),%rsp
L$4x_epilogue:
ret
.byte 0xf3,0xc3
@@ -1617,7 +1617,7 @@ L$done8x:
leaq (%r9),%rsp
L$8x_epilogue:
ret
.byte 0xf3,0xc3
#endif
@@ -60,22 +60,7 @@ 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_NOHW)
static void ChaCha20_ctr32(uint8_t *out, const uint8_t *in, size_t in_len,
const uint32_t key[8], const uint32_t counter[4]) {
#if defined(CHACHA20_ASM_NEON)
if (ChaCha20_ctr32_neon_capable(in_len)) {
ChaCha20_ctr32_neon(out, in, in_len, key, counter);
return;
}
#endif
if (in_len > 0) {
ChaCha20_ctr32_nohw(out, in, in_len, key, counter);
}
}
#endif
#if defined(CHACHA20_ASM) || defined(CHACHA20_ASM_NOHW)
#if defined(CHACHA20_ASM)
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,8 +17,6 @@
#include <CCryptoBoringSSL_base.h>
#include "../internal.h"
#if defined(__cplusplus)
extern "C" {
#endif
@@ -29,25 +27,11 @@ extern "C" {
void CRYPTO_hchacha20(uint8_t out[32], const uint8_t key[32],
const uint8_t nonce[16]);
#if !defined(OPENSSL_NO_ASM) && \
(defined(OPENSSL_X86) || defined(OPENSSL_X86_64))
#if !defined(OPENSSL_NO_ASM) && \
(defined(OPENSSL_X86) || defined(OPENSSL_X86_64) || \
defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64))
#define CHACHA20_ASM
#elif !defined(OPENSSL_NO_ASM) && \
(defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64))
#define CHACHA20_ASM_NOHW
#define CHACHA20_ASM_NEON
OPENSSL_INLINE int ChaCha20_ctr32_neon_capable(size_t len) {
return (len >= 192) && CRYPTO_is_NEON_capable();
}
void ChaCha20_ctr32_neon(uint8_t *out, const uint8_t *in, size_t in_len,
const uint32_t key[8], const uint32_t counter[4]);
#endif
#if defined(CHACHA20_ASM)
// ChaCha20_ctr32 encrypts |in_len| bytes from |in| and writes the result to
// |out|. If |in| and |out| alias, they must be equal.
//
@@ -60,12 +44,6 @@ void ChaCha20_ctr32(uint8_t *out, const uint8_t *in, size_t in_len,
const uint32_t key[8], const uint32_t counter[4]);
#endif
#if defined(CHACHA20_ASM_NOHW)
// ChaCha20_ctr32_nohw is like |ChaCha20_ctr32| except |in_len| must be nonzero.
void ChaCha20_ctr32_nohw(uint8_t *out, const uint8_t *in, size_t in_len,
const uint32_t key[8], const uint32_t counter[4]);
#endif
#if defined(__cplusplus)
} // extern C
@@ -64,7 +64,7 @@ GFMUL:
vpxor %xmm4,%xmm3,%xmm2
vpxor %xmm5,%xmm2,%xmm0
ret
.byte 0xf3,0xc3
.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)
ret
.byte 0xf3,0xc3
.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)
ret
.byte 0xf3,0xc3
.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
ret
.byte 0xf3,0xc3
.Lhtable_polyval_start:
vzeroall
@@ -332,7 +332,7 @@ _CET_ENDBR
vmovdqu %xmm1,(%rcx)
vzeroupper
ret
.byte 0xf3,0xc3
.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
ret
.byte 0xf3,0xc3
.Lpolyval_horner_start:
@@ -366,7 +366,7 @@ _CET_ENDBR
vmovdqa %xmm0,(%rdi)
ret
.byte 0xf3,0xc3
.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)
ret
.byte 0xf3,0xc3
.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)
ret
.byte 0xf3,0xc3
.cfi_endproc
.globl aes128gcmsiv_aes_ks_enc_x1
.hidden aes128gcmsiv_aes_ks_enc_x1
@@ -614,7 +614,7 @@ _CET_ENDBR
vmovdqa %xmm4,0(%rsi)
ret
.byte 0xf3,0xc3
.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)
ret
.byte 0xf3,0xc3
.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
ret
.byte 0xf3,0xc3
.L128_enc_msg_x4_start:
pushq %r12
@@ -888,7 +888,7 @@ _CET_ENDBR
popq %r12
.cfi_adjust_cfa_offset -8
.cfi_restore %r12
ret
.byte 0xf3,0xc3
.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
ret
.byte 0xf3,0xc3
.L128_enc_msg_x8_start:
pushq %r12
@@ -1150,7 +1150,7 @@ _CET_ENDBR
popq %r12
.cfi_adjust_cfa_offset -8
.cfi_restore %r12
ret
.byte 0xf3,0xc3
.cfi_endproc
.size aes128gcmsiv_enc_msg_x8,.-aes128gcmsiv_enc_msg_x8
.globl aes128gcmsiv_dec
@@ -1162,7 +1162,7 @@ aes128gcmsiv_dec:
_CET_ENDBR
testq $~15,%r9
jnz .L128_dec_start
ret
.byte 0xf3,0xc3
.L128_dec_start:
vzeroupper
@@ -1643,7 +1643,7 @@ _CET_ENDBR
.L128_dec_out:
vmovdqu %xmm0,(%rdx)
ret
.byte 0xf3,0xc3
.cfi_endproc
.size aes128gcmsiv_dec, .-aes128gcmsiv_dec
.globl aes128gcmsiv_ecb_enc_block
@@ -1669,7 +1669,7 @@ _CET_ENDBR
vmovdqa %xmm1,(%rsi)
ret
.byte 0xf3,0xc3
.cfi_endproc
.size aes128gcmsiv_ecb_enc_block,.-aes128gcmsiv_ecb_enc_block
.globl aes256gcmsiv_aes_ks_enc_x1
@@ -1853,7 +1853,7 @@ _CET_ENDBR
vmovdqu %xmm1,224(%rdx)
vmovdqa %xmm8,(%rsi)
ret
.byte 0xf3,0xc3
.cfi_endproc
.size aes256gcmsiv_aes_ks_enc_x1,.-aes256gcmsiv_aes_ks_enc_x1
.globl aes256gcmsiv_ecb_enc_block
@@ -1880,7 +1880,7 @@ _CET_ENDBR
vaesenc 208(%rdx),%xmm1,%xmm1
vaesenclast 224(%rdx),%xmm1,%xmm1
vmovdqa %xmm1,(%rsi)
ret
.byte 0xf3,0xc3
.cfi_endproc
.size aes256gcmsiv_ecb_enc_block,.-aes256gcmsiv_ecb_enc_block
.globl aes256gcmsiv_enc_msg_x4
@@ -1892,7 +1892,7 @@ aes256gcmsiv_enc_msg_x4:
_CET_ENDBR
testq %r8,%r8
jnz .L256_enc_msg_x4_start
ret
.byte 0xf3,0xc3
.L256_enc_msg_x4_start:
movq %r8,%r10
@@ -2082,7 +2082,7 @@ _CET_ENDBR
jne .L256_enc_msg_x4_loop2
.L256_enc_msg_x4_out:
ret
.byte 0xf3,0xc3
.cfi_endproc
.size aes256gcmsiv_enc_msg_x4,.-aes256gcmsiv_enc_msg_x4
.globl aes256gcmsiv_enc_msg_x8
@@ -2094,7 +2094,7 @@ aes256gcmsiv_enc_msg_x8:
_CET_ENDBR
testq %r8,%r8
jnz .L256_enc_msg_x8_start
ret
.byte 0xf3,0xc3
.L256_enc_msg_x8_start:
@@ -2371,7 +2371,7 @@ _CET_ENDBR
jnz .L256_enc_msg_x8_loop2
.L256_enc_msg_x8_out:
ret
.byte 0xf3,0xc3
.cfi_endproc
.size aes256gcmsiv_enc_msg_x8,.-aes256gcmsiv_enc_msg_x8
@@ -2384,7 +2384,7 @@ aes256gcmsiv_dec:
_CET_ENDBR
testq $~15,%r9
jnz .L256_dec_start
ret
.byte 0xf3,0xc3
.L256_dec_start:
vzeroupper
@@ -2933,7 +2933,7 @@ _CET_ENDBR
.L256_dec_out:
vmovdqu %xmm0,(%rdx)
ret
.byte 0xf3,0xc3
.cfi_endproc
.size aes256gcmsiv_dec, .-aes256gcmsiv_dec
.globl aes256gcmsiv_kdf
@@ -3085,7 +3085,7 @@ _CET_ENDBR
vmovdqa %xmm11,48(%rsi)
vmovdqa %xmm12,64(%rsi)
vmovdqa %xmm13,80(%rsi)
ret
.byte 0xf3,0xc3
.cfi_endproc
.size aes256gcmsiv_kdf, .-aes256gcmsiv_kdf
#endif
@@ -64,7 +64,7 @@ GFMUL:
vpxor %xmm4,%xmm3,%xmm2
vpxor %xmm5,%xmm2,%xmm0
ret
.byte 0xf3,0xc3
.globl _aesgcmsiv_htable_init
@@ -91,7 +91,7 @@ _CET_ENDBR
vmovdqa %xmm0,96(%rdi)
call GFMUL
vmovdqa %xmm0,112(%rdi)
ret
.byte 0xf3,0xc3
.globl _aesgcmsiv_htable6_init
@@ -114,7 +114,7 @@ _CET_ENDBR
vmovdqa %xmm0,64(%rdi)
call GFMUL
vmovdqa %xmm0,80(%rdi)
ret
.byte 0xf3,0xc3
.globl _aesgcmsiv_htable_polyval
@@ -126,7 +126,7 @@ _aesgcmsiv_htable_polyval:
_CET_ENDBR
testq %rdx,%rdx
jnz L$htable_polyval_start
ret
.byte 0xf3,0xc3
L$htable_polyval_start:
vzeroall
@@ -332,7 +332,7 @@ L$htable_polyval_out:
vmovdqu %xmm1,(%rcx)
vzeroupper
ret
.byte 0xf3,0xc3
.globl _aesgcmsiv_polyval_horner
@@ -344,7 +344,7 @@ _aesgcmsiv_polyval_horner:
_CET_ENDBR
testq %rcx,%rcx
jnz L$polyval_horner_start
ret
.byte 0xf3,0xc3
L$polyval_horner_start:
@@ -366,7 +366,7 @@ L$polyval_horner_loop:
vmovdqa %xmm0,(%rdi)
ret
.byte 0xf3,0xc3
.globl _aes128gcmsiv_aes_ks
@@ -423,7 +423,7 @@ L$ks128_loop:
vpxor %xmm3,%xmm1,%xmm1
vpxor %xmm2,%xmm1,%xmm1
vmovdqa %xmm1,32(%rsi)
ret
.byte 0xf3,0xc3
.globl _aes256gcmsiv_aes_ks
@@ -472,7 +472,7 @@ L$ks256_loop:
vpxor %xmm4,%xmm1,%xmm1
vpxor %xmm2,%xmm1,%xmm1
vmovdqa %xmm1,32(%rsi)
ret
.byte 0xf3,0xc3
.globl _aes128gcmsiv_aes_ks_enc_x1
.private_extern _aes128gcmsiv_aes_ks_enc_x1
@@ -614,7 +614,7 @@ _CET_ENDBR
vmovdqa %xmm4,0(%rsi)
ret
.byte 0xf3,0xc3
.globl _aes128gcmsiv_kdf
@@ -708,7 +708,7 @@ _CET_ENDBR
vmovdqa %xmm10,16(%rsi)
vmovdqa %xmm11,32(%rsi)
vmovdqa %xmm12,48(%rsi)
ret
.byte 0xf3,0xc3
.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
ret
.byte 0xf3,0xc3
L$128_enc_msg_x4_start:
pushq %r12
@@ -884,7 +884,7 @@ L$128_enc_msg_x4_out:
popq %r12
ret
.byte 0xf3,0xc3
.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
ret
.byte 0xf3,0xc3
L$128_enc_msg_x8_start:
pushq %r12
@@ -1140,7 +1140,7 @@ L$128_enc_msg_x8_out:
popq %r12
ret
.byte 0xf3,0xc3
.globl _aes128gcmsiv_dec
@@ -1152,7 +1152,7 @@ _aes128gcmsiv_dec:
_CET_ENDBR
testq $~15,%r9
jnz L$128_dec_start
ret
.byte 0xf3,0xc3
L$128_dec_start:
vzeroupper
@@ -1633,7 +1633,7 @@ L$128_dec_loop2:
L$128_dec_out:
vmovdqu %xmm0,(%rdx)
ret
.byte 0xf3,0xc3
.globl _aes128gcmsiv_ecb_enc_block
@@ -1659,7 +1659,7 @@ _CET_ENDBR
vmovdqa %xmm1,(%rsi)
ret
.byte 0xf3,0xc3
.globl _aes256gcmsiv_aes_ks_enc_x1
@@ -1843,7 +1843,7 @@ _CET_ENDBR
vmovdqu %xmm1,224(%rdx)
vmovdqa %xmm8,(%rsi)
ret
.byte 0xf3,0xc3
.globl _aes256gcmsiv_ecb_enc_block
@@ -1870,7 +1870,7 @@ _CET_ENDBR
vaesenc 208(%rdx),%xmm1,%xmm1
vaesenclast 224(%rdx),%xmm1,%xmm1
vmovdqa %xmm1,(%rsi)
ret
.byte 0xf3,0xc3
.globl _aes256gcmsiv_enc_msg_x4
@@ -1882,7 +1882,7 @@ _aes256gcmsiv_enc_msg_x4:
_CET_ENDBR
testq %r8,%r8
jnz L$256_enc_msg_x4_start
ret
.byte 0xf3,0xc3
L$256_enc_msg_x4_start:
movq %r8,%r10
@@ -2072,7 +2072,7 @@ L$256_enc_msg_x4_loop2:
jne L$256_enc_msg_x4_loop2
L$256_enc_msg_x4_out:
ret
.byte 0xf3,0xc3
.globl _aes256gcmsiv_enc_msg_x8
@@ -2084,7 +2084,7 @@ _aes256gcmsiv_enc_msg_x8:
_CET_ENDBR
testq %r8,%r8
jnz L$256_enc_msg_x8_start
ret
.byte 0xf3,0xc3
L$256_enc_msg_x8_start:
@@ -2361,7 +2361,7 @@ L$256_enc_msg_x8_loop2:
jnz L$256_enc_msg_x8_loop2
L$256_enc_msg_x8_out:
ret
.byte 0xf3,0xc3
@@ -2374,7 +2374,7 @@ _aes256gcmsiv_dec:
_CET_ENDBR
testq $~15,%r9
jnz L$256_dec_start
ret
.byte 0xf3,0xc3
L$256_dec_start:
vzeroupper
@@ -2923,7 +2923,7 @@ L$256_dec_loop2:
L$256_dec_out:
vmovdqu %xmm0,(%rdx)
ret
.byte 0xf3,0xc3
.globl _aes256gcmsiv_kdf
@@ -3075,7 +3075,7 @@ _CET_ENDBR
vmovdqa %xmm11,48(%rsi)
vmovdqa %xmm12,64(%rsi)
vmovdqa %xmm13,80(%rsi)
ret
.byte 0xf3,0xc3
#endif
@@ -106,7 +106,7 @@ poly_hash_ad_internal:
adcq %r9,%r11
adcq $0,%r12
ret
.byte 0xf3,0xc3
.Lhash_ad_loop:
cmpq $16,%r8
@@ -215,7 +215,7 @@ poly_hash_ad_internal:
.Lhash_ad_done:
ret
.byte 0xf3,0xc3
.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
ret
.byte 0xf3,0xc3
.Lopen_sse_128:
.cfi_restore_state
@@ -3930,7 +3930,7 @@ process_extra_in_trailer:
popq %rbp
.cfi_adjust_cfa_offset -8
.cfi_restore %rbp
ret
.byte 0xf3,0xc3
.Lseal_sse_128:
.cfi_restore_state
@@ -105,7 +105,7 @@ L$poly_fast_tls_ad:
adcq %r9,%r11
adcq $0,%r12
ret
.byte 0xf3,0xc3
L$hash_ad_loop:
cmpq $16,%r8
@@ -214,7 +214,7 @@ L$hash_ad_tail_loop:
L$hash_ad_done:
ret
.byte 0xf3,0xc3
@@ -1849,7 +1849,7 @@ L$open_sse_finalize:
popq %rbp
ret
.byte 0xf3,0xc3
L$open_sse_128:
@@ -3901,7 +3901,7 @@ L$do_length_block:
popq %rbp
ret
.byte 0xf3,0xc3
L$seal_sse_128:
+8 -1
View File
@@ -118,7 +118,14 @@ CONF *NCONF_new(void *method) {
return conf;
}
CONF_VALUE *CONF_VALUE_new(void) { return OPENSSL_zalloc(sizeof(CONF_VALUE)); }
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);
+36
View File
@@ -0,0 +1,36 @@
/* 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) */
-11
View File
@@ -78,11 +78,6 @@ 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>
@@ -121,16 +116,10 @@ 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)
@@ -272,11 +272,12 @@ 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_zalloc(sizeof(SPAKE2_CTX));
SPAKE2_CTX *ctx = OPENSSL_malloc(sizeof(SPAKE2_CTX));
if (ctx == NULL) {
return NULL;
}
OPENSSL_memset(ctx, 0, sizeof(SPAKE2_CTX));
ctx->my_role = my_role;
CBS my_name_cbs, their_name_cbs;
@@ -110,10 +110,6 @@ DH *DH_parse_parameters(CBS *cbs) {
goto err;
}
if (!dh_check_params_fast(ret)) {
goto err;
}
return ret;
err:
@@ -337,11 +337,6 @@ 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;
+15 -2
View File
@@ -88,14 +88,18 @@ 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_zalloc(sizeof(DSA));
DSA *dsa = OPENSSL_malloc(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;
}
@@ -529,7 +533,16 @@ err:
return ok;
}
DSA_SIG *DSA_SIG_new(void) { return OPENSSL_zalloc(sizeof(DSA_SIG)); }
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;
}
void DSA_SIG_free(DSA_SIG *sig) {
if (!sig) {
@@ -26,7 +26,8 @@
#include "../internal.h"
// This file implements hash-to-curve, as described in RFC 9380.
// This file implements hash-to-curve, as described in
// draft-irtf-cfrg-hash-to-curve-16.
//
// This hash-to-curve implementation is written generically with the
// expectation that we will eventually wish to support other curves. If it
@@ -47,7 +48,8 @@
// templates to make specializing more convenient.
// expand_message_xmd implements the operation described in section 5.3.1 of
// RFC 9380. It returns one on success and zero on error.
// draft-irtf-cfrg-hash-to-curve-16. 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) {
@@ -136,7 +138,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 RFC 9380.
// section 5.2 of draft-irtf-cfrg-hash-to-curve-16.
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;
@@ -169,7 +171,8 @@ 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 RFC 9380, with count = 2. |k| is the security factor.
// of draft-irtf-cfrg-hash-to-curve-16, 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,
@@ -218,7 +221,8 @@ 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 RFC 9380.
// sgn0 implements the operation described in section 4.1.2 of
// draft-irtf-cfrg-hash-to-curve-16.
static BN_ULONG sgn0(const EC_GROUP *group, const EC_FELEM *a) {
uint8_t buf[EC_MAX_BYTES];
size_t len;
@@ -231,7 +235,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 RFC 9380.
// of draft-irtf-cfrg-hash-to-curve-16.
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,
@@ -266,7 +270,8 @@ 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 RFC 9380, using the straight-line implementation in appendix F.2.
// of draft-irtf-cfrg-hash-to-curve-16, 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,
@@ -400,7 +405,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 RFC 9380.
// See section 8.3 of draft-irtf-cfrg-hash-to-curve-16.
if (EC_GROUP_get_curve_name(group) != NID_X9_62_prime256v1) {
OPENSSL_PUT_ERROR(EC, EC_R_GROUP_MISMATCH);
return 0;
@@ -433,7 +438,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 RFC 9380.
// See section 8.3 of draft-irtf-cfrg-hash-to-curve-16.
if (EC_GROUP_get_curve_name(group) != NID_secp384r1) {
OPENSSL_PUT_ERROR(EC, EC_R_GROUP_MISMATCH);
return 0;
@@ -30,22 +30,24 @@ 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 RFC 9380. It returns one on success and zero on error.
// from draft-irtf-cfrg-hash-to-curve-16. 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 RFC 9380. It returns one on success and zero on error.
// from draft-irtf-cfrg-hash-to-curve-16. 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 RFC 9380, but generating a value modulo
// the group order rather than a field element.
// 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.
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,7 +31,15 @@ struct engine_st {
ECDSA_METHOD *ecdsa_method;
};
ENGINE *ENGINE_new(void) { return OPENSSL_zalloc(sizeof(ENGINE)); }
ENGINE *ENGINE_new(void) {
ENGINE *engine = OPENSSL_malloc(sizeof(ENGINE));
if (engine == NULL) {
return NULL;
}
OPENSSL_memset(engine, 0, sizeof(ENGINE));
return engine;
}
int ENGINE_free(ENGINE *engine) {
// Methods are currently required to be static so are not unref'ed.
+290 -293
View File
@@ -81,7 +81,7 @@ const uint32_t kOpenSSLReasonValues[] = {
0x10339666,
0x10341679,
0x10348f93,
0x10350cdf,
0x10350ccc,
0x1035968c,
0x103616b6,
0x103696c9,
@@ -103,7 +103,7 @@ const uint32_t kOpenSSLReasonValues[] = {
0x103e9839,
0x103f1850,
0x103f9863,
0x10400ca3,
0x10400c90,
0x10409876,
0x10411894,
0x104198a7,
@@ -125,12 +125,11 @@ const uint32_t kOpenSSLReasonValues[] = {
0x104997d7,
0x104a16a1,
0x14320c73,
0x14328c94,
0x14330ca3,
0x14338cb5,
0x14328c81,
0x14330c90,
0x14338ca2,
0x143400b9,
0x143480f7,
0x14350c81,
0x18320090,
0x18328fe9,
0x183300b9,
@@ -164,7 +163,7 @@ const uint32_t kOpenSSLReasonValues[] = {
0x18411164,
0x1841912f,
0x1842114e,
0x18428c81,
0x18428cd8,
0x1843110a,
0x18439176,
0x18441028,
@@ -186,60 +185,60 @@ const uint32_t kOpenSSLReasonValues[] = {
0x2438133b,
0x24389348,
0x2439135b,
0x28320cd3,
0x28320cc0,
0x28328ceb,
0x28330ca3,
0x28330c90,
0x28338cfe,
0x28340cdf,
0x28340ccc,
0x283480b9,
0x283500f7,
0x28358c81,
0x28358cd8,
0x2836099a,
0x2c3232e7,
0x2c3232d0,
0x2c329372,
0x2c3332f5,
0x2c33b307,
0x2c34331b,
0x2c34b32d,
0x2c353348,
0x2c35b35a,
0x2c36338a,
0x2c3332de,
0x2c33b2f0,
0x2c343304,
0x2c34b316,
0x2c353331,
0x2c35b343,
0x2c363373,
0x2c36833a,
0x2c373397,
0x2c37b3c3,
0x2c383401,
0x2c38b418,
0x2c393436,
0x2c39b446,
0x2c3a3458,
0x2c3ab46c,
0x2c3b347d,
0x2c3bb49c,
0x2c373380,
0x2c37b3ac,
0x2c3833ea,
0x2c38b401,
0x2c39341f,
0x2c39b42f,
0x2c3a3441,
0x2c3ab455,
0x2c3b3466,
0x2c3bb485,
0x2c3c1384,
0x2c3c939a,
0x2c3d34e1,
0x2c3d34ca,
0x2c3d93b3,
0x2c3e350b,
0x2c3eb519,
0x2c3f3531,
0x2c3fb549,
0x2c403573,
0x2c3e34f4,
0x2c3eb502,
0x2c3f351a,
0x2c3fb532,
0x2c40355c,
0x2c409285,
0x2c413584,
0x2c41b597,
0x2c41356d,
0x2c41b580,
0x2c42124b,
0x2c42b5a8,
0x2c42b591,
0x2c43076d,
0x2c43b48e,
0x2c4433d6,
0x2c44b556,
0x2c45336d,
0x2c45b3a9,
0x2c463426,
0x2c46b4b0,
0x2c4734c5,
0x2c47b4fe,
0x2c4833e8,
0x2c43b477,
0x2c4433bf,
0x2c44b53f,
0x2c453356,
0x2c45b392,
0x2c46340f,
0x2c46b499,
0x2c4734ae,
0x2c47b4e7,
0x2c4833d1,
0x30320000,
0x30328015,
0x3033001f,
@@ -437,203 +436,202 @@ const uint32_t kOpenSSLReasonValues[] = {
0x404da092,
0x404e20a6,
0x404ea0b3,
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,
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,
0x405e8afe,
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,
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,
0x4071084d,
0x4071afb1,
0x40722fc4,
0x4072affa,
0x40733012,
0x4071af9a,
0x40722fad,
0x4072afe3,
0x40732ffb,
0x4073959c,
0x40743026,
0x4074b040,
0x40753051,
0x4075b065,
0x40763073,
0x4074300f,
0x4074b029,
0x4075303a,
0x4075b04e,
0x4076305c,
0x40769348,
0x40773098,
0x4077b0d8,
0x407830f3,
0x4078b12c,
0x40793143,
0x4079b159,
0x407a3185,
0x407ab198,
0x407b31ad,
0x407bb1bf,
0x407c31f0,
0x407cb1f9,
0x407d28bb,
0x407da202,
0x407e3108,
0x407ea444,
0x40773081,
0x4077b0c1,
0x407830dc,
0x4078b115,
0x4079312c,
0x4079b142,
0x407a316e,
0x407ab181,
0x407b3196,
0x407bb1a8,
0x407c31d9,
0x407cb1e2,
0x407d28a4,
0x407da1eb,
0x407e30f1,
0x407ea42d,
0x407f1e27,
0x407f9ffa,
0x40802174,
0x4080215d,
0x40809e4f,
0x408122b2,
0x4081229b,
0x4081a101,
0x40822e7c,
0x40822e65,
0x40829ba2,
0x4083241f,
0x4083a738,
0x40832408,
0x4083a721,
0x40841e63,
0x4084a47c,
0x408524f1,
0x4085a615,
0x40862571,
0x4086a21c,
0x40872ec2,
0x4087a663,
0x4084a465,
0x408524da,
0x4085a5fe,
0x4086255a,
0x4086a205,
0x40872eab,
0x4087a64c,
0x40881be0,
0x4088a84a,
0x4088a833,
0x40891c2f,
0x40899bbc,
0x408a2b3a,
0x408a2b23,
0x408a99b4,
0x408b31d4,
0x408baf4c,
0x408c2501,
0x408b31bd,
0x408baf35,
0x408c24ea,
0x408c99ec,
0x408d1f4b,
0x408d9e95,
0x408e207b,
0x408ea36f,
0x408f285e,
0x408fa631,
0x40902813,
0x4090a543,
0x40912b22,
0x408ea358,
0x408f2847,
0x408fa61a,
0x409027fc,
0x4090a52c,
0x40912b0b,
0x40919a12,
0x40921c7c,
0x4092aefd,
0x40932fdd,
0x4093a22d,
0x4092aee6,
0x40932fc6,
0x4093a216,
0x40941e77,
0x4094ab53,
0x409526bf,
0x4095b165,
0x40962ea9,
0x4096a18d,
0x40972278,
0x4094ab3c,
0x409526a8,
0x4095b14e,
0x40962e92,
0x4096a176,
0x40972261,
0x4097a0ca,
0x40981cdc,
0x4098a6d3,
0x40992f19,
0x4099a39c,
0x409a2335,
0x4098a6bc,
0x40992f02,
0x4099a385,
0x409a231e,
0x409a99d0,
0x409b1ed1,
0x409b9efc,
0x409c30ba,
0x409c30a3,
0x409c9f24,
0x409d2149,
0x409d2132,
0x409da117,
0x409e1d6d,
0x409ea1c2,
0x409f21aa,
0x409ea1ab,
0x409f2193,
0x409f9ec4,
0x40a021ea,
0x40a021d3,
0x40a0a0e4,
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,
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,
0x44320778,
0x44328787,
0x44330793,
@@ -678,7 +676,7 @@ const uint32_t kOpenSSLReasonValues[] = {
0x4c3c1574,
0x4c3c9583,
0x4c3d159c,
0x4c3d8cc6,
0x4c3d8cb3,
0x4c3e1609,
0x4c3e95ab,
0x4c3f162b,
@@ -689,71 +687,71 @@ const uint32_t kOpenSSLReasonValues[] = {
0x4c41947c,
0x4c4215e5,
0x4c4293c4,
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,
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,
0x503f83b3,
0x504037eb,
0x5040b7fb,
0x50413815,
0x5041b824,
0x5042383e,
0x5042b85b,
0x5043386b,
0x5043b87b,
0x50443898,
0x504037d4,
0x5040b7e4,
0x504137fe,
0x5041b80d,
0x50423827,
0x5042b844,
0x50433854,
0x5043b864,
0x50443881,
0x50448469,
0x504538ac,
0x5045b8ca,
0x504638dd,
0x5046b8f3,
0x50473905,
0x5047b91a,
0x50483940,
0x5048b94e,
0x50493961,
0x5049b976,
0x504a398c,
0x504ab99c,
0x504b39bc,
0x504bb9cf,
0x504c39f2,
0x504cba20,
0x504d3a4d,
0x504dba6a,
0x504e3a85,
0x504ebaa1,
0x504f3ab3,
0x504fbaca,
0x50503ad9,
0x50453895,
0x5045b8b3,
0x504638c6,
0x5046b8dc,
0x504738ee,
0x5047b903,
0x50483929,
0x5048b937,
0x5049394a,
0x5049b95f,
0x504a3975,
0x504ab985,
0x504b39a5,
0x504bb9b8,
0x504c39db,
0x504cba09,
0x504d3a36,
0x504dba53,
0x504e3a6e,
0x504eba8a,
0x504f3a9c,
0x504fbab3,
0x50503ac2,
0x50508729,
0x50513aec,
0x5051b88a,
0x50523a32,
0x50513ad5,
0x5051b873,
0x50523a1b,
0x58320fd1,
0x68320f93,
0x68328ceb,
@@ -763,12 +761,12 @@ const uint32_t kOpenSSLReasonValues[] = {
0x683480f7,
0x6835099a,
0x6c320f59,
0x6c328cb5,
0x6c328ca2,
0x6c330f64,
0x6c338f7d,
0x74320a66,
0x743280b9,
0x74330cc6,
0x74330cb3,
0x783209cb,
0x783289e0,
0x783309ec,
@@ -798,19 +796,19 @@ const uint32_t kOpenSSLReasonValues[] = {
0x7c321261,
0x8032148f,
0x80328090,
0x803332b6,
0x8033329f,
0x803380b9,
0x803432c5,
0x8034b22d,
0x8035324b,
0x8035b2d9,
0x8036328d,
0x8036b23c,
0x8037327f,
0x8037b21a,
0x803832a0,
0x8038b25c,
0x80393271,
0x803432ae,
0x8034b216,
0x80353234,
0x8035b2c2,
0x80363276,
0x8036b225,
0x80373268,
0x8037b203,
0x80383289,
0x8038b245,
0x8039325a,
};
const size_t kOpenSSLReasonValuesLen = sizeof(kOpenSSLReasonValues) / sizeof(kOpenSSLReasonValues[0]);
@@ -983,13 +981,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"
@@ -1231,7 +1229,6 @@ 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"
+5 -1
View File
@@ -81,13 +81,17 @@ 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 = OPENSSL_zalloc(sizeof(EVP_PKEY));
EVP_PKEY *ret;
ret = OPENSSL_malloc(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,10 +86,11 @@ 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_zalloc(sizeof(EVP_PKEY_CTX));
EVP_PKEY_CTX *ret = OPENSSL_malloc(sizeof(EVP_PKEY_CTX));
if (!ret) {
return NULL;
}
OPENSSL_memset(ret, 0, sizeof(EVP_PKEY_CTX));
ret->engine = e;
ret->pmeth = pmeth;
@@ -155,11 +156,13 @@ EVP_PKEY_CTX *EVP_PKEY_CTX_dup(EVP_PKEY_CTX *ctx) {
return NULL;
}
EVP_PKEY_CTX *ret = OPENSSL_zalloc(sizeof(EVP_PKEY_CTX));
EVP_PKEY_CTX *ret = OPENSSL_malloc(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;
+4 -1
View File
@@ -80,12 +80,15 @@ typedef struct {
static int pkey_ec_init(EVP_PKEY_CTX *ctx) {
EC_PKEY_CTX *dctx = OPENSSL_zalloc(sizeof(EC_PKEY_CTX));
EC_PKEY_CTX *dctx;
dctx = OPENSSL_malloc(sizeof(EC_PKEY_CTX));
if (!dctx) {
return 0;
}
OPENSSL_memset(dctx, 0, sizeof(EC_PKEY_CTX));
ctx->data = dctx;
return 1;
}
+2 -1
View File
@@ -35,11 +35,12 @@ typedef struct {
} HKDF_PKEY_CTX;
static int pkey_hkdf_init(EVP_PKEY_CTX *ctx) {
HKDF_PKEY_CTX *hctx = OPENSSL_zalloc(sizeof(HKDF_PKEY_CTX));
HKDF_PKEY_CTX *hctx = OPENSSL_malloc(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;
+3 -1
View File
@@ -97,10 +97,12 @@ typedef struct {
} RSA_OAEP_LABEL_PARAMS;
static int pkey_rsa_init(EVP_PKEY_CTX *ctx) {
RSA_PKEY_CTX *rctx = OPENSSL_zalloc(sizeof(RSA_PKEY_CTX));
RSA_PKEY_CTX *rctx;
rctx = OPENSSL_malloc(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;
+2 -2
View File
@@ -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_MAX, "size_t exceeds uint64_t");
static_assert(UINT64_MAX >= ((size_t)-1), "size_t exceeds uint64_t");
size_t B_blocks = p * 2 * r;
size_t B_bytes = B_blocks * sizeof(block_t);
size_t T_blocks = 2 * r;
size_t V_blocks = N * 2 * r;
block_t *B = OPENSSL_calloc(B_blocks + T_blocks + V_blocks, sizeof(block_t));
block_t *B = OPENSSL_malloc((B_blocks + T_blocks + V_blocks) * sizeof(block_t));
if (B == NULL) {
return 0;
}
@@ -338,7 +338,7 @@ _aesni_ctr32_ghash_6x:
vpxor 16+8(%rsp),%xmm8,%xmm8
vpxor %xmm4,%xmm8,%xmm8
ret
.byte 0xf3,0xc3
.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:
ret
.byte 0xf3,0xc3
.cfi_endproc
.size aesni_gcm_decrypt,.-aesni_gcm_decrypt
@@ -539,7 +539,7 @@ _aesni_ctr32_6x:
vmovups %xmm14,80(%rsi)
leaq 96(%rsi),%rsi
ret
.byte 0xf3,0xc3
.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:
ret
.byte 0xf3,0xc3
.cfi_endproc
.size aesni_gcm_encrypt,.-aesni_gcm_encrypt
.size aesni_gcm_decrypt,.-aesni_gcm_decrypt
.section .rodata
.align 64
.Lbswap_mask:
@@ -338,7 +338,7 @@ L$6x_done:
vpxor 16+8(%rsp),%xmm8,%xmm8
vpxor %xmm4,%xmm8,%xmm8
ret
.byte 0xf3,0xc3
.globl _aesni_gcm_decrypt
@@ -461,7 +461,7 @@ L$dec_no_key_aliasing:
popq %rbp
L$gcm_dec_abort:
ret
.byte 0xf3,0xc3
@@ -532,7 +532,7 @@ L$oop_ctr32:
vmovups %xmm14,80(%rsi)
leaq 96(%rsi),%rsi
ret
.byte 0xf3,0xc3
.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:
ret
.byte 0xf3,0xc3
@@ -38,7 +38,7 @@ _CET_ENDBR
pxor %xmm1,%xmm1
movups %xmm2,(%rsi)
pxor %xmm2,%xmm2
ret
.byte 0xf3,0xc3
.cfi_endproc
.size aes_hw_encrypt,.-aes_hw_encrypt
@@ -66,7 +66,7 @@ _CET_ENDBR
pxor %xmm1,%xmm1
movups %xmm2,(%rsi)
pxor %xmm2,%xmm2
ret
.byte 0xf3,0xc3
.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
ret
.byte 0xf3,0xc3
.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
ret
.byte 0xf3,0xc3
.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
ret
.byte 0xf3,0xc3
.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
ret
.byte 0xf3,0xc3
.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
ret
.byte 0xf3,0xc3
.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
ret
.byte 0xf3,0xc3
.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
ret
.byte 0xf3,0xc3
.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
ret
.byte 0xf3,0xc3
.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
ret
.byte 0xf3,0xc3
.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
ret
.byte 0xf3,0xc3
.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
ret
.byte 0xf3,0xc3
.cfi_endproc
.size aes_hw_ecb_encrypt,.-aes_hw_ecb_encrypt
.globl aes_hw_ctr32_encrypt_blocks
@@ -1460,7 +1460,7 @@ _CET_ENDBR
leaq (%r11),%rsp
.cfi_def_cfa_register %rsp
.Lctr32_epilogue:
ret
.byte 0xf3,0xc3
.cfi_endproc
.size aes_hw_ctr32_encrypt_blocks,.-aes_hw_ctr32_encrypt_blocks
.globl aes_hw_cbc_encrypt
@@ -2054,7 +2054,7 @@ _CET_ENDBR
leaq (%r11),%rsp
.cfi_def_cfa_register %rsp
.Lcbc_ret:
ret
.byte 0xf3,0xc3
.cfi_endproc
.size aes_hw_cbc_encrypt,.-aes_hw_cbc_encrypt
.globl aes_hw_set_decrypt_key
@@ -2099,7 +2099,7 @@ _CET_ENDBR
.Ldec_key_ret:
addq $8,%rsp
.cfi_adjust_cfa_offset -8
ret
.byte 0xf3,0xc3
.cfi_endproc
.LSEH_end_set_decrypt_key:
.size aes_hw_set_decrypt_key,.-aes_hw_set_decrypt_key
@@ -2410,7 +2410,7 @@ _CET_ENDBR
pxor %xmm5,%xmm5
addq $8,%rsp
.cfi_adjust_cfa_offset -8
ret
.byte 0xf3,0xc3
.cfi_endproc
.LSEH_end_set_encrypt_key:
@@ -2425,7 +2425,7 @@ _CET_ENDBR
xorps %xmm4,%xmm0
shufps $255,%xmm1,%xmm1
xorps %xmm1,%xmm0
ret
.byte 0xf3,0xc3
.align 16
.Lkey_expansion_192a:
@@ -2445,7 +2445,7 @@ _CET_ENDBR
pxor %xmm1,%xmm0
pshufd $255,%xmm0,%xmm3
pxor %xmm3,%xmm2
ret
.byte 0xf3,0xc3
.align 16
.Lkey_expansion_192b:
@@ -2468,7 +2468,7 @@ _CET_ENDBR
xorps %xmm4,%xmm0
shufps $255,%xmm1,%xmm1
xorps %xmm1,%xmm0
ret
.byte 0xf3,0xc3
.align 16
.Lkey_expansion_256b:
@@ -2481,7 +2481,7 @@ _CET_ENDBR
xorps %xmm4,%xmm2
shufps $170,%xmm1,%xmm1
xorps %xmm1,%xmm2
ret
.byte 0xf3,0xc3
.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
ret
.byte 0xf3,0xc3
@@ -64,7 +64,7 @@ L$oop_dec1_2:
pxor %xmm1,%xmm1
movups %xmm2,(%rsi)
pxor %xmm2,%xmm2
ret
.byte 0xf3,0xc3
@@ -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
ret
.byte 0xf3,0xc3
@@ -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
ret
.byte 0xf3,0xc3
@@ -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
ret
.byte 0xf3,0xc3
@@ -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
ret
.byte 0xf3,0xc3
@@ -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
ret
.byte 0xf3,0xc3
@@ -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
ret
.byte 0xf3,0xc3
@@ -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
ret
.byte 0xf3,0xc3
@@ -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
ret
.byte 0xf3,0xc3
@@ -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
ret
.byte 0xf3,0xc3
@@ -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
ret
.byte 0xf3,0xc3
.globl _aes_hw_ecb_encrypt
@@ -872,7 +872,7 @@ L$ecb_dec_six:
L$ecb_ret:
xorps %xmm0,%xmm0
pxor %xmm1,%xmm1
ret
.byte 0xf3,0xc3
.globl _aes_hw_ctr32_encrypt_blocks
@@ -1458,7 +1458,7 @@ L$ctr32_done:
leaq (%r11),%rsp
L$ctr32_epilogue:
ret
.byte 0xf3,0xc3
.globl _aes_hw_cbc_encrypt
@@ -2052,7 +2052,7 @@ L$cbc_dec_ret:
leaq (%r11),%rsp
L$cbc_ret:
ret
.byte 0xf3,0xc3
.globl _aes_hw_set_decrypt_key
@@ -2097,7 +2097,7 @@ L$dec_key_inverse:
L$dec_key_ret:
addq $8,%rsp
ret
.byte 0xf3,0xc3
L$SEH_end_set_decrypt_key:
@@ -2408,7 +2408,7 @@ L$enc_key_ret:
pxor %xmm5,%xmm5
addq $8,%rsp
ret
.byte 0xf3,0xc3
L$SEH_end_set_encrypt_key:
@@ -2423,7 +2423,7 @@ L$key_expansion_128_cold:
xorps %xmm4,%xmm0
shufps $255,%xmm1,%xmm1
xorps %xmm1,%xmm0
ret
.byte 0xf3,0xc3
.p2align 4
L$key_expansion_192a:
@@ -2443,7 +2443,7 @@ L$key_expansion_192b_warm:
pxor %xmm1,%xmm0
pshufd $255,%xmm0,%xmm3
pxor %xmm3,%xmm2
ret
.byte 0xf3,0xc3
.p2align 4
L$key_expansion_192b:
@@ -2466,7 +2466,7 @@ L$key_expansion_256a_cold:
xorps %xmm4,%xmm0
shufps $255,%xmm1,%xmm1
xorps %xmm1,%xmm0
ret
.byte 0xf3,0xc3
.p2align 4
L$key_expansion_256b:
@@ -2479,7 +2479,7 @@ L$key_expansion_256b:
xorps %xmm4,%xmm2
shufps $170,%xmm1,%xmm1
xorps %xmm1,%xmm2
ret
.byte 0xf3,0xc3
.section __DATA,__const
@@ -197,7 +197,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
@@ -195,7 +195,7 @@ 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
@@ -117,7 +117,10 @@ 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->d[i] = CRYPTO_addc_w(a->d[i], 0, carry, &carry);
// |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[max] = carry;
@@ -238,7 +241,10 @@ 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->d[i] = CRYPTO_subc_w(a->d[i], 0, borrow, &borrow);
// |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];
}
if (borrow) {
@@ -361,7 +361,7 @@ int bn_wexpand(BIGNUM *bn, size_t words) {
return 0;
}
a = OPENSSL_calloc(words, sizeof(BN_ULONG));
a = OPENSSL_malloc(sizeof(BN_ULONG) * words);
if (a == NULL) {
return 0;
}
@@ -116,7 +116,7 @@ BIGNUM *BN_bin2bn(const uint8_t *in, size_t len, BIGNUM *ret) {
return ret;
}
BIGNUM *BN_lebin2bn(const uint8_t *in, size_t len, BIGNUM *ret) {
BIGNUM *BN_le2bn(const uint8_t *in, size_t len, BIGNUM *ret) {
BIGNUM *bn = NULL;
if (ret == NULL) {
bn = BN_new();
@@ -149,10 +149,6 @@ BIGNUM *BN_lebin2bn(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_MAX / sizeof(size_t)) {
if (new_size <= st->size || new_size > ((size_t)-1) / 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_MAX / BN_BITS2) {
num_p > ((size_t)-1) / BN_BITS2) {
abort();
}
assert(BN_is_odd(&mont->N));
@@ -567,6 +567,37 @@ 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) {
@@ -575,17 +606,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] = 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);
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);
a += 4;
b += 4;
r += 4;
n -= 4;
}
while (n) {
r[0] = CRYPTO_addc_w(a[0], b[0], carry, &carry);
r[0] = bn_add_with_carry(a[0], b[0], carry, &carry);
a++;
b++;
r++;
@@ -602,17 +633,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] = 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);
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);
a += 4;
b += 4;
r += 4;
n -= 4;
}
while (n) {
r[0] = CRYPTO_subc_w(a[0], b[0], borrow, &borrow);
r[0] = bn_sub_with_borrow(a[0], b[0], borrow, &borrow);
a++;
b++;
r++;
@@ -143,13 +143,17 @@ 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] = CRYPTO_subc_w(0, b[i], borrow, &borrow);
r[i] = 0u - b[i] - borrow;
borrow |= r[i] != 0;
}
} 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[i] = CRYPTO_subc_w(a[i], 0, borrow, &borrow);
// |r| and |a| may alias, so use a temporary.
BN_ULONG tmp = a[i];
r[i] = a[i] - borrow;
borrow = tmp < r[i];
}
}
@@ -359,7 +359,14 @@ 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) { return OPENSSL_zalloc(sizeof(BN_GENCB)); }
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;
}
void BN_GENCB_free(BN_GENCB *callback) { OPENSSL_free(callback); }
@@ -69,6 +69,7 @@
# 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,6 +69,7 @@
# 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,11 +113,12 @@ 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_memdup(in->cipher_data, in->cipher->ctx_size);
out->cipher_data = OPENSSL_malloc(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) {
@@ -585,16 +586,6 @@ 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,6 +408,22 @@ 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) {
@@ -438,10 +454,6 @@ 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;
@@ -469,7 +481,9 @@ static int aes_gcm_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) {
if (arg < 4 || (gctx->ivlen - arg) < 8) {
return 0;
}
OPENSSL_memcpy(gctx->iv, ptr, arg);
if (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
@@ -481,7 +495,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;
}
@@ -490,13 +504,12 @@ 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, 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);
// 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);
gctx->iv_set = 1;
return 1;
}
case EVP_CTRL_GCM_SET_IV_INV:
if (gctx->iv_gen == 0 || gctx->key_set == 0 || c->encrypt) {
@@ -86,7 +86,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_MAX
return ctx->L >= sizeof(size_t) ? (size_t)-1
: (((size_t)1) << (ctx->L * 8)) - 1;
}
@@ -57,40 +57,12 @@
#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) {
@@ -101,14 +73,17 @@ 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.
if (BN_cmp(pub_key, BN_value_one()) <= 0) {
BIGNUM *tmp = BN_CTX_get(ctx);
if (tmp == NULL ||
!BN_set_word(tmp, 1)) {
goto err;
}
if (BN_cmp(pub_key, tmp) <= 0) {
*out_flags |= DH_CHECK_PUBKEY_TOO_SMALL;
}
// Check |pub_key| is less than |dh->p| - 1.
BIGNUM *tmp = BN_CTX_get(ctx);
if (tmp == NULL ||
!BN_copy(tmp, dh->p) ||
if (!BN_copy(tmp, dh->p) ||
!BN_sub_word(tmp, 1)) {
goto err;
}
@@ -138,11 +113,6 @@ 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
@@ -154,6 +124,7 @@ 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,14 +70,20 @@
#include "internal.h"
#define OPENSSL_DH_MAX_MODULUS_BITS 10000
DH *DH_new(void) {
DH *dh = OPENSSL_zalloc(sizeof(DH));
DH *dh = OPENSSL_malloc(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;
}
@@ -185,14 +191,15 @@ 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, *priv_key_limit = 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;
}
ctx = BN_CTX_new();
if (ctx == NULL) {
@@ -225,44 +232,22 @@ int DH_generate_key(DH *dh) {
if (generate_new_key) {
if (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)) {
if (!BN_rand_range_ex(priv_key, 2, dh->q)) {
goto err;
}
} else {
// 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)) {
// 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) {
goto err;
}
priv_bits = p_bits - 1;
}
// Choose a private key uniformly from [1, M-1].
if (!BN_rand_range_ex(priv_key, 1, priv_key_limit)) {
if (!BN_rand(priv_key, priv_bits, BN_RAND_TOP_ONE, BN_RAND_BOTTOM_ANY)) {
goto err;
}
}
@@ -288,14 +273,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 (!dh_check_params_fast(dh)) {
if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS) {
OPENSSL_PUT_ERROR(DH, DH_R_MODULUS_TOO_LARGE);
return 0;
}
@@ -394,7 +379,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_MAX;
*out_len = (size_t)-1;
const size_t digest_len = EVP_MD_size(digest);
if (digest_len > max_out_len) {
@@ -26,8 +26,6 @@ extern "C" {
#endif
#define OPENSSL_DH_MAX_MODULUS_BITS 10000
struct dh_st {
BIGNUM *p;
BIGNUM *g;
@@ -46,11 +44,6 @@ 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.
@@ -250,10 +250,11 @@ EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a,
goto err;
}
ret = OPENSSL_zalloc(sizeof(EC_GROUP));
ret = OPENSSL_malloc(sizeof(EC_GROUP));
if (ret == NULL) {
return NULL;
}
OPENSSL_memset(ret, 0, sizeof(EC_GROUP));
ret->references = 1;
ret->meth = EC_GFp_mont_method();
bn_mont_ctx_init(&ret->field);
@@ -86,11 +86,12 @@
DEFINE_STATIC_EX_DATA_CLASS(g_ec_ex_data_class)
static EC_WRAPPED_SCALAR *ec_wrapped_scalar_new(const EC_GROUP *group) {
EC_WRAPPED_SCALAR *wrapped = OPENSSL_zalloc(sizeof(EC_WRAPPED_SCALAR));
EC_WRAPPED_SCALAR *wrapped = OPENSSL_malloc(sizeof(EC_WRAPPED_SCALAR));
if (wrapped == NULL) {
return NULL;
}
OPENSSL_memset(wrapped, 0, sizeof(EC_WRAPPED_SCALAR));
wrapped->bignum.d = wrapped->scalar.words;
wrapped->bignum.width = group->order.N.width;
wrapped->bignum.dmax = group->order.N.width;
@@ -105,11 +106,13 @@ static void ec_wrapped_scalar_free(EC_WRAPPED_SCALAR *scalar) {
EC_KEY *EC_KEY_new(void) { return EC_KEY_new_method(NULL); }
EC_KEY *EC_KEY_new_method(const ENGINE *engine) {
EC_KEY *ret = OPENSSL_zalloc(sizeof(EC_KEY));
EC_KEY *ret = OPENSSL_malloc(sizeof(EC_KEY));
if (ret == NULL) {
return NULL;
}
OPENSSL_memset(ret, 0, sizeof(EC_KEY));
if (engine) {
ret->ecdsa_meth = ENGINE_get_ECDSA_method(engine);
}
@@ -163,12 +166,12 @@ void EC_KEY_free(EC_KEY *r) {
METHOD_unref(r->ecdsa_meth);
}
CRYPTO_free_ex_data(g_ec_ex_data_class_bss_get(), r, &r->ex_data);
EC_GROUP_free(r->group);
EC_POINT_free(r->pub_key);
ec_wrapped_scalar_free(r->priv_key);
CRYPTO_free_ex_data(g_ec_ex_data_class_bss_get(), r, &r->ex_data);
OPENSSL_free(r);
}
@@ -24,7 +24,6 @@
#include <CCryptoBoringSSL_err.h>
#include <CCryptoBoringSSL_mem.h>
#include <assert.h>
#include <string.h>
#include "internal.h"
@@ -837,12 +836,12 @@ static void p224_select_point(const uint64_t idx, size_t size,
for (size_t i = 0; i < size; i++) {
const p224_limb *inlimbs = &pre_comp[i][0][0];
static_assert(sizeof(uint64_t) <= sizeof(crypto_word_t),
"crypto_word_t too small");
static_assert(sizeof(size_t) <= sizeof(crypto_word_t),
"crypto_word_t too small");
// Without a value barrier, Clang adds a branch here.
uint64_t mask = value_barrier_w(constant_time_eq_w(i, idx));
uint64_t mask = i ^ idx;
mask |= mask >> 4;
mask |= mask >> 2;
mask |= mask >> 1;
mask &= 1;
mask--;
for (size_t j = 0; j < 4 * 3; j++) {
outlimbs[j] |= inlimbs[j] & mask;
}
@@ -197,8 +197,13 @@ int ec_GFp_mont_mul_public_batch(const EC_GROUP *group, EC_JACOBIAN *r,
wNAF = wNAF_stack;
precomp = precomp_stack;
} else {
wNAF_alloc = OPENSSL_calloc(num, sizeof(wNAF_alloc[0]));
precomp_alloc = OPENSSL_calloc(num, sizeof(precomp_alloc[0]));
if (num >= ((size_t)-1) / sizeof(wNAF_alloc[0]) ||
num >= ((size_t)-1) / sizeof(precomp_alloc[0])) {
OPENSSL_PUT_ERROR(EC, ERR_R_OVERFLOW);
goto err;
}
wNAF_alloc = OPENSSL_malloc(num * sizeof(wNAF_alloc[0]));
precomp_alloc = OPENSSL_malloc(num * sizeof(precomp_alloc[0]));
if (wNAF_alloc == NULL || precomp_alloc == NULL) {
goto err;
}
@@ -194,7 +194,7 @@ _CET_ENDBR
pxor %xmm4,%xmm4
pxor %xmm5,%xmm5
pxor %xmm6,%xmm6
ret
.byte 0xf3,0xc3
.cfi_endproc
.size gcm_gmult_ssse3,.-gcm_gmult_ssse3
@@ -407,7 +407,7 @@ _CET_ENDBR
pxor %xmm4,%xmm4
pxor %xmm5,%xmm5
pxor %xmm6,%xmm6
ret
.byte 0xf3,0xc3
.cfi_endproc
.size gcm_ghash_ssse3,.-gcm_ghash_ssse3
@@ -194,7 +194,7 @@ L$oop_row_3:
pxor %xmm4,%xmm4
pxor %xmm5,%xmm5
pxor %xmm6,%xmm6
ret
.byte 0xf3,0xc3
@@ -407,7 +407,7 @@ L$oop_row_6:
pxor %xmm4,%xmm4
pxor %xmm5,%xmm5
pxor %xmm6,%xmm6
ret
.byte 0xf3,0xc3
@@ -167,7 +167,7 @@ _CET_ENDBR
movdqu %xmm0,64(%rdi)
.byte 102,15,58,15,227,8
movdqu %xmm4,80(%rdi)
ret
.byte 0xf3,0xc3
.cfi_endproc
.size gcm_init_clmul,.-gcm_init_clmul
@@ -223,7 +223,7 @@ _CET_ENDBR
pxor %xmm1,%xmm0
.byte 102,15,56,0,197
movdqu %xmm0,(%rdi)
ret
.byte 0xf3,0xc3
.cfi_endproc
.size gcm_gmult_clmul,.-gcm_gmult_clmul
.globl gcm_ghash_clmul
@@ -612,7 +612,7 @@ _CET_ENDBR
.Ldone:
.byte 102,65,15,56,0,194
movdqu %xmm0,(%rdi)
ret
.byte 0xf3,0xc3
.cfi_endproc
.size gcm_ghash_clmul,.-gcm_ghash_clmul
@@ -724,7 +724,7 @@ _CET_ENDBR
vmovdqu %xmm5,-16(%rdi)
vzeroupper
ret
.byte 0xf3,0xc3
.cfi_endproc
.size gcm_init_avx,.-gcm_init_avx
@@ -1115,7 +1115,7 @@ _CET_ENDBR
vpshufb %xmm13,%xmm10,%xmm10
vmovdqu %xmm10,(%rdi)
vzeroupper
ret
.byte 0xf3,0xc3
.cfi_endproc
.size gcm_ghash_avx,.-gcm_ghash_avx
@@ -166,7 +166,7 @@ L$_init_clmul:
movdqu %xmm0,64(%rdi)
.byte 102,15,58,15,227,8
movdqu %xmm4,80(%rdi)
ret
.byte 0xf3,0xc3
@@ -222,7 +222,7 @@ L$_gmult_clmul:
pxor %xmm1,%xmm0
.byte 102,15,56,0,197
movdqu %xmm0,(%rdi)
ret
.byte 0xf3,0xc3
.globl _gcm_ghash_clmul
@@ -611,7 +611,7 @@ L$odd_tail:
L$done:
.byte 102,65,15,56,0,194
movdqu %xmm0,(%rdi)
ret
.byte 0xf3,0xc3
@@ -723,7 +723,7 @@ L$init_start_avx:
vmovdqu %xmm5,-16(%rdi)
vzeroupper
ret
.byte 0xf3,0xc3
@@ -1114,7 +1114,7 @@ L$tail_no_xor_avx:
vpshufb %xmm13,%xmm10,%xmm10
vmovdqu %xmm10,(%rdi)
vzeroupper
ret
.byte 0xf3,0xc3
@@ -691,7 +691,7 @@ _CET_ENDBR
addq $40,%rsp
.cfi_adjust_cfa_offset -40
.Lepilogue:
ret
.byte 0xf3,0xc3
.cfi_endproc
.size md5_block_asm_data_order,.-md5_block_asm_data_order
#endif
@@ -686,7 +686,7 @@ L$end:
addq $40,%rsp
L$epilogue:
ret
.byte 0xf3,0xc3
#endif
@@ -88,7 +88,7 @@ _CET_ENDBR
leaq 16(%rsp),%rsp
.cfi_adjust_cfa_offset -16
.Lneg_epilogue:
ret
.byte 0xf3,0xc3
.cfi_endproc
.size ecp_nistz256_neg,.-ecp_nistz256_neg
@@ -422,7 +422,7 @@ _CET_ENDBR
leaq 48(%rsp),%rsp
.cfi_adjust_cfa_offset -48
.Lord_mul_epilogue:
ret
.byte 0xf3,0xc3
.cfi_endproc
.size ecp_nistz256_ord_mul_mont,.-ecp_nistz256_ord_mul_mont
@@ -727,7 +727,7 @@ _CET_ENDBR
leaq 48(%rsp),%rsp
.cfi_adjust_cfa_offset -48
.Lord_sqr_epilogue:
ret
.byte 0xf3,0xc3
.cfi_endproc
.size ecp_nistz256_ord_sqr_mont,.-ecp_nistz256_ord_sqr_mont
@@ -969,7 +969,7 @@ ecp_nistz256_ord_mul_montx:
leaq 48(%rsp),%rsp
.cfi_adjust_cfa_offset -48
.Lord_mulx_epilogue:
ret
.byte 0xf3,0xc3
.cfi_endproc
.size ecp_nistz256_ord_mul_montx,.-ecp_nistz256_ord_mul_montx
@@ -1183,7 +1183,7 @@ ecp_nistz256_ord_sqr_montx:
leaq 48(%rsp),%rsp
.cfi_adjust_cfa_offset -48
.Lord_sqrx_epilogue:
ret
.byte 0xf3,0xc3
.cfi_endproc
.size ecp_nistz256_ord_sqr_montx,.-ecp_nistz256_ord_sqr_montx
@@ -1261,7 +1261,7 @@ _CET_ENDBR
leaq 48(%rsp),%rsp
.cfi_adjust_cfa_offset -48
.Lmul_epilogue:
ret
.byte 0xf3,0xc3
.cfi_endproc
.size ecp_nistz256_mul_mont,.-ecp_nistz256_mul_mont
@@ -1479,7 +1479,7 @@ __ecp_nistz256_mul_montq:
movq %r8,16(%rdi)
movq %r9,24(%rdi)
ret
.byte 0xf3,0xc3
.cfi_endproc
.size __ecp_nistz256_mul_montq,.-__ecp_nistz256_mul_montq
@@ -1554,7 +1554,7 @@ _CET_ENDBR
leaq 48(%rsp),%rsp
.cfi_adjust_cfa_offset -48
.Lsqr_epilogue:
ret
.byte 0xf3,0xc3
.cfi_endproc
.size ecp_nistz256_sqr_mont,.-ecp_nistz256_sqr_mont
@@ -1718,7 +1718,7 @@ __ecp_nistz256_sqr_montq:
movq %r14,16(%rdi)
movq %r15,24(%rdi)
ret
.byte 0xf3,0xc3
.cfi_endproc
.size __ecp_nistz256_sqr_montq,.-__ecp_nistz256_sqr_montq
.type __ecp_nistz256_mul_montx,@function
@@ -1886,7 +1886,7 @@ __ecp_nistz256_mul_montx:
movq %r8,16(%rdi)
movq %r9,24(%rdi)
ret
.byte 0xf3,0xc3
.cfi_endproc
.size __ecp_nistz256_mul_montx,.-__ecp_nistz256_mul_montx
@@ -2016,7 +2016,7 @@ __ecp_nistz256_sqr_montx:
movq %r14,16(%rdi)
movq %r15,24(%rdi)
ret
.byte 0xf3,0xc3
.cfi_endproc
.size __ecp_nistz256_sqr_montx,.-__ecp_nistz256_sqr_montx
@@ -2082,7 +2082,7 @@ _CET_ENDBR
movdqu %xmm5,48(%rdi)
movdqu %xmm6,64(%rdi)
movdqu %xmm7,80(%rdi)
ret
.byte 0xf3,0xc3
.cfi_endproc
.LSEH_end_ecp_nistz256_select_w5:
.size ecp_nistz256_select_w5,.-ecp_nistz256_select_w5
@@ -2139,7 +2139,7 @@ _CET_ENDBR
movdqu %xmm3,16(%rdi)
movdqu %xmm4,32(%rdi)
movdqu %xmm5,48(%rdi)
ret
.byte 0xf3,0xc3
.cfi_endproc
.LSEH_end_ecp_nistz256_select_w7:
.size ecp_nistz256_select_w7,.-ecp_nistz256_select_w7
@@ -2202,7 +2202,7 @@ ecp_nistz256_avx2_select_w5:
vmovdqu %ymm3,32(%rdi)
vmovdqu %ymm4,64(%rdi)
vzeroupper
ret
.byte 0xf3,0xc3
.cfi_endproc
.LSEH_end_ecp_nistz256_avx2_select_w5:
.size ecp_nistz256_avx2_select_w5,.-ecp_nistz256_avx2_select_w5
@@ -2284,7 +2284,7 @@ _CET_ENDBR
vmovdqu %ymm2,0(%rdi)
vmovdqu %ymm3,32(%rdi)
vzeroupper
ret
.byte 0xf3,0xc3
.cfi_endproc
.LSEH_end_ecp_nistz256_avx2_select_w7:
.size ecp_nistz256_avx2_select_w7,.-ecp_nistz256_avx2_select_w7
@@ -2318,7 +2318,7 @@ __ecp_nistz256_add_toq:
movq %r8,16(%rdi)
movq %r9,24(%rdi)
ret
.byte 0xf3,0xc3
.cfi_endproc
.size __ecp_nistz256_add_toq,.-__ecp_nistz256_add_toq
@@ -2351,7 +2351,7 @@ __ecp_nistz256_sub_fromq:
movq %r8,16(%rdi)
movq %r9,24(%rdi)
ret
.byte 0xf3,0xc3
.cfi_endproc
.size __ecp_nistz256_sub_fromq,.-__ecp_nistz256_sub_fromq
@@ -2380,7 +2380,7 @@ __ecp_nistz256_subq:
cmovnzq %rcx,%r8
cmovnzq %r10,%r9
ret
.byte 0xf3,0xc3
.cfi_endproc
.size __ecp_nistz256_subq,.-__ecp_nistz256_subq
@@ -2414,7 +2414,7 @@ __ecp_nistz256_mul_by_2q:
movq %r8,16(%rdi)
movq %r9,24(%rdi)
ret
.byte 0xf3,0xc3
.cfi_endproc
.size __ecp_nistz256_mul_by_2q,.-__ecp_nistz256_mul_by_2q
.globl ecp_nistz256_point_double
@@ -2649,7 +2649,7 @@ _CET_ENDBR
leaq (%rsi),%rsp
.cfi_def_cfa_register %rsp
.Lpoint_doubleq_epilogue:
ret
.byte 0xf3,0xc3
.cfi_endproc
.size ecp_nistz256_point_double,.-ecp_nistz256_point_double
.globl ecp_nistz256_point_add
@@ -3087,7 +3087,7 @@ _CET_ENDBR
leaq (%rsi),%rsp
.cfi_def_cfa_register %rsp
.Lpoint_addq_epilogue:
ret
.byte 0xf3,0xc3
.cfi_endproc
.size ecp_nistz256_point_add,.-ecp_nistz256_point_add
.globl ecp_nistz256_point_add_affine
@@ -3422,7 +3422,7 @@ _CET_ENDBR
leaq (%rsi),%rsp
.cfi_def_cfa_register %rsp
.Ladd_affineq_epilogue:
ret
.byte 0xf3,0xc3
.cfi_endproc
.size ecp_nistz256_point_add_affine,.-ecp_nistz256_point_add_affine
.type __ecp_nistz256_add_tox,@function
@@ -3456,7 +3456,7 @@ __ecp_nistz256_add_tox:
movq %r8,16(%rdi)
movq %r9,24(%rdi)
ret
.byte 0xf3,0xc3
.cfi_endproc
.size __ecp_nistz256_add_tox,.-__ecp_nistz256_add_tox
@@ -3491,7 +3491,7 @@ __ecp_nistz256_sub_fromx:
movq %r8,16(%rdi)
movq %r9,24(%rdi)
ret
.byte 0xf3,0xc3
.cfi_endproc
.size __ecp_nistz256_sub_fromx,.-__ecp_nistz256_sub_fromx
@@ -3522,7 +3522,7 @@ __ecp_nistz256_subx:
cmovcq %rcx,%r8
cmovcq %r10,%r9
ret
.byte 0xf3,0xc3
.cfi_endproc
.size __ecp_nistz256_subx,.-__ecp_nistz256_subx
@@ -3557,7 +3557,7 @@ __ecp_nistz256_mul_by_2x:
movq %r8,16(%rdi)
movq %r9,24(%rdi)
ret
.byte 0xf3,0xc3
.cfi_endproc
.size __ecp_nistz256_mul_by_2x,.-__ecp_nistz256_mul_by_2x
.type ecp_nistz256_point_doublex,@function
@@ -3785,7 +3785,7 @@ ecp_nistz256_point_doublex:
leaq (%rsi),%rsp
.cfi_def_cfa_register %rsp
.Lpoint_doublex_epilogue:
ret
.byte 0xf3,0xc3
.cfi_endproc
.size ecp_nistz256_point_doublex,.-ecp_nistz256_point_doublex
.type ecp_nistz256_point_addx,@function
@@ -4216,7 +4216,7 @@ ecp_nistz256_point_addx:
leaq (%rsi),%rsp
.cfi_def_cfa_register %rsp
.Lpoint_addx_epilogue:
ret
.byte 0xf3,0xc3
.cfi_endproc
.size ecp_nistz256_point_addx,.-ecp_nistz256_point_addx
.type ecp_nistz256_point_add_affinex,@function
@@ -4544,7 +4544,7 @@ ecp_nistz256_point_add_affinex:
leaq (%rsi),%rsp
.cfi_def_cfa_register %rsp
.Ladd_affinex_epilogue:
ret
.byte 0xf3,0xc3
.cfi_endproc
.size ecp_nistz256_point_add_affinex,.-ecp_nistz256_point_add_affinex
#endif
@@ -85,7 +85,7 @@ L$neg_body:
leaq 16(%rsp),%rsp
L$neg_epilogue:
ret
.byte 0xf3,0xc3
@@ -413,7 +413,7 @@ L$ord_mul_body:
leaq 48(%rsp),%rsp
L$ord_mul_epilogue:
ret
.byte 0xf3,0xc3
@@ -712,7 +712,7 @@ L$oop_ord_sqr:
leaq 48(%rsp),%rsp
L$ord_sqr_epilogue:
ret
.byte 0xf3,0xc3
@@ -948,7 +948,7 @@ L$ord_mulx_body:
leaq 48(%rsp),%rsp
L$ord_mulx_epilogue:
ret
.byte 0xf3,0xc3
@@ -1156,7 +1156,7 @@ L$oop_ord_sqrx:
leaq 48(%rsp),%rsp
L$ord_sqrx_epilogue:
ret
.byte 0xf3,0xc3
@@ -1228,7 +1228,7 @@ L$mul_mont_done:
leaq 48(%rsp),%rsp
L$mul_epilogue:
ret
.byte 0xf3,0xc3
@@ -1446,7 +1446,7 @@ __ecp_nistz256_mul_montq:
movq %r8,16(%rdi)
movq %r9,24(%rdi)
ret
.byte 0xf3,0xc3
@@ -1515,7 +1515,7 @@ L$sqr_mont_done:
leaq 48(%rsp),%rsp
L$sqr_epilogue:
ret
.byte 0xf3,0xc3
@@ -1679,7 +1679,7 @@ __ecp_nistz256_sqr_montq:
movq %r14,16(%rdi)
movq %r15,24(%rdi)
ret
.byte 0xf3,0xc3
@@ -1847,7 +1847,7 @@ __ecp_nistz256_mul_montx:
movq %r8,16(%rdi)
movq %r9,24(%rdi)
ret
.byte 0xf3,0xc3
@@ -1977,7 +1977,7 @@ __ecp_nistz256_sqr_montx:
movq %r14,16(%rdi)
movq %r15,24(%rdi)
ret
.byte 0xf3,0xc3
@@ -2043,7 +2043,7 @@ L$select_loop_sse_w5:
movdqu %xmm5,48(%rdi)
movdqu %xmm6,64(%rdi)
movdqu %xmm7,80(%rdi)
ret
.byte 0xf3,0xc3
L$SEH_end_ecp_nistz256_select_w5:
@@ -2100,7 +2100,7 @@ L$select_loop_sse_w7:
movdqu %xmm3,16(%rdi)
movdqu %xmm4,32(%rdi)
movdqu %xmm5,48(%rdi)
ret
.byte 0xf3,0xc3
L$SEH_end_ecp_nistz256_select_w7:
@@ -2163,7 +2163,7 @@ L$select_loop_avx2_w5:
vmovdqu %ymm3,32(%rdi)
vmovdqu %ymm4,64(%rdi)
vzeroupper
ret
.byte 0xf3,0xc3
L$SEH_end_ecp_nistz256_avx2_select_w5:
@@ -2245,7 +2245,7 @@ L$select_loop_avx2_w7:
vmovdqu %ymm2,0(%rdi)
vmovdqu %ymm3,32(%rdi)
vzeroupper
ret
.byte 0xf3,0xc3
L$SEH_end_ecp_nistz256_avx2_select_w7:
@@ -2279,7 +2279,7 @@ __ecp_nistz256_add_toq:
movq %r8,16(%rdi)
movq %r9,24(%rdi)
ret
.byte 0xf3,0xc3
@@ -2312,7 +2312,7 @@ __ecp_nistz256_sub_fromq:
movq %r8,16(%rdi)
movq %r9,24(%rdi)
ret
.byte 0xf3,0xc3
@@ -2341,7 +2341,7 @@ __ecp_nistz256_subq:
cmovnzq %rcx,%r8
cmovnzq %r10,%r9
ret
.byte 0xf3,0xc3
@@ -2375,7 +2375,7 @@ __ecp_nistz256_mul_by_2q:
movq %r8,16(%rdi)
movq %r9,24(%rdi)
ret
.byte 0xf3,0xc3
.globl _ecp_nistz256_point_double
@@ -2604,7 +2604,7 @@ L$point_double_shortcutq:
leaq (%rsi),%rsp
L$point_doubleq_epilogue:
ret
.byte 0xf3,0xc3
.globl _ecp_nistz256_point_add
@@ -3036,7 +3036,7 @@ L$add_doneq:
leaq (%rsi),%rsp
L$point_addq_epilogue:
ret
.byte 0xf3,0xc3
.globl _ecp_nistz256_point_add_affine
@@ -3365,7 +3365,7 @@ L$add_affineq_body:
leaq (%rsi),%rsp
L$add_affineq_epilogue:
ret
.byte 0xf3,0xc3
@@ -3399,7 +3399,7 @@ __ecp_nistz256_add_tox:
movq %r8,16(%rdi)
movq %r9,24(%rdi)
ret
.byte 0xf3,0xc3
@@ -3434,7 +3434,7 @@ __ecp_nistz256_sub_fromx:
movq %r8,16(%rdi)
movq %r9,24(%rdi)
ret
.byte 0xf3,0xc3
@@ -3465,7 +3465,7 @@ __ecp_nistz256_subx:
cmovcq %rcx,%r8
cmovcq %r10,%r9
ret
.byte 0xf3,0xc3
@@ -3500,7 +3500,7 @@ __ecp_nistz256_mul_by_2x:
movq %r8,16(%rdi)
movq %r9,24(%rdi)
ret
.byte 0xf3,0xc3
@@ -3722,7 +3722,7 @@ L$point_double_shortcutx:
leaq (%rsi),%rsp
L$point_doublex_epilogue:
ret
.byte 0xf3,0xc3
@@ -4147,7 +4147,7 @@ L$add_donex:
leaq (%rsi),%rsp
L$point_addx_epilogue:
ret
.byte 0xf3,0xc3
@@ -4469,7 +4469,7 @@ L$add_affinex_body:
leaq (%rsi),%rsp
L$add_affinex_epilogue:
ret
.byte 0xf3,0xc3
#endif
@@ -331,7 +331,7 @@ _CET_ENDBR
popq %rbp
.cfi_adjust_cfa_offset -8
.cfi_restore rbp
ret
.byte 0xf3,0xc3
.cfi_endproc
.size beeu_mod_inverse_vartime, .-beeu_mod_inverse_vartime
@@ -317,7 +317,7 @@ L$beeu_finish:
popq %rbp
ret
.byte 0xf3,0xc3
@@ -17,34 +17,31 @@
#endif
#include <CCryptoBoringSSL_base.h>
#include "fork_detect.h"
#if defined(OPENSSL_FORK_DETECTION_MADVISE)
#include <unistd.h>
#include <stdlib.h>
#if defined(OPENSSL_LINUX)
#include <assert.h>
#include <sys/mman.h>
#include <unistd.h>
#include <stdlib.h>
#include "../delocate.h"
#include "../../internal.h"
#if defined(MADV_WIPEONFORK)
static_assert(MADV_WIPEONFORK == 18, "MADV_WIPEONFORK is not 18");
#else
#define MADV_WIPEONFORK 18
#endif
#elif defined(OPENSSL_FORK_DETECTION_PTHREAD_ATFORK)
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>
#endif // OPENSSL_FORK_DETECTION_MADVISE
#include "../delocate.h"
#include "../../internal.h"
#if defined(OPENSSL_FORK_DETECTION_MADVISE)
DEFINE_BSS_GET(int, g_force_madv_wipeonfork);
DEFINE_BSS_GET(int, g_force_madv_wipeonfork_enabled);
DEFINE_STATIC_ONCE(g_fork_detect_once);
DEFINE_STATIC_MUTEX(g_fork_detect_lock);
DEFINE_BSS_GET(CRYPTO_atomic_u32 *, g_fork_detect_addr);
DEFINE_BSS_GET(uint64_t, g_fork_generation);
DEFINE_BSS_GET(int, g_force_madv_wipeonfork);
DEFINE_BSS_GET(int, g_force_madv_wipeonfork_enabled);
static void init_fork_detect(void) {
if (*g_force_madv_wipeonfork_bss_get()) {
@@ -76,12 +73,9 @@ static void init_fork_detect(void) {
CRYPTO_atomic_store_u32(addr, 1);
*g_fork_detect_addr_bss_get() = addr;
*g_fork_generation_bss_get() = 1;
}
uint64_t CRYPTO_get_fork_generation(void) {
CRYPTO_once(g_fork_detect_once_bss_get(), init_fork_detect);
// In a single-threaded process, there are obviously no races because there's
// only a single mutator in the address space.
//
@@ -93,6 +87,7 @@ uint64_t CRYPTO_get_fork_generation(void) {
// child process is single-threaded, the child may become multi-threaded
// before it observes this. Therefore, we must synchronize the logic below.
CRYPTO_once(g_fork_detect_once_bss_get(), init_fork_detect);
CRYPTO_atomic_u32 *const flag_ptr = *g_fork_detect_addr_bss_get();
if (flag_ptr == NULL) {
// Our kernel is too old to support |MADV_WIPEONFORK| or
@@ -103,12 +98,6 @@ uint64_t CRYPTO_get_fork_generation(void) {
// doesn't support it.
return 42;
}
// With Linux and clone(), we do not believe that pthread_atfork() is
// sufficient for detecting all forms of address space duplication. At this
// point we have a kernel that does not support MADV_WIPEONFORK. We could
// return the generation number from pthread_atfork() here and it would
// probably be safe in almost any situation, but to ensure safety we return
// 0 and force an entropy draw on every call.
return 0;
}
@@ -151,34 +140,7 @@ void CRYPTO_fork_detect_force_madv_wipeonfork_for_testing(int on) {
*g_force_madv_wipeonfork_enabled_bss_get() = on;
}
#elif defined(OPENSSL_FORK_DETECTION_PTHREAD_ATFORK)
DEFINE_STATIC_ONCE(g_pthread_fork_detection_once);
DEFINE_BSS_GET(uint64_t, g_atfork_fork_generation);
static void we_are_forked(void) {
// Immediately after a fork, the process must be single-threaded.
uint64_t value = *g_atfork_fork_generation_bss_get() + 1;
if (value == 0) {
value = 1;
}
*g_atfork_fork_generation_bss_get() = value;
}
static void init_pthread_fork_detection(void) {
if (pthread_atfork(NULL, NULL, we_are_forked) != 0) {
abort();
}
*g_atfork_fork_generation_bss_get() = 1;
}
uint64_t CRYPTO_get_fork_generation(void) {
CRYPTO_once(g_pthread_fork_detection_once_bss_get(), init_pthread_fork_detection);
return *g_atfork_fork_generation_bss_get();
}
#elif defined(OPENSSL_DOES_NOT_FORK)
#elif defined(OPENSSL_WINDOWS) || defined(OPENSSL_TRUSTY)
// These platforms are guaranteed not to fork, and therefore do not require
// fork detection support. Returning a constant non zero value makes BoringSSL
@@ -17,23 +17,6 @@
#include <CCryptoBoringSSL_base.h>
#if defined(OPENSSL_LINUX)
// On linux we use MADVISE instead of pthread_atfork(), due
// to concerns about clone() being used for address space
// duplication.
#define OPENSSL_FORK_DETECTION
#define OPENSSL_FORK_DETECTION_MADVISE
#elif defined(OPENSSL_MACOS) || defined(OPENSSL_IOS) || \
defined(OPENSSL_OPENBSD) || defined(OPENSSL_FREEBSD)
// These platforms may detect address space duplication with pthread_atfork.
// iOS doesn't normally allow fork in apps, but it's there.
#define OPENSSL_FORK_DETECTION
#define OPENSSL_FORK_DETECTION_PTHREAD_ATFORK
#elif defined(OPENSSL_WINDOWS) || defined(OPENSSL_TRUSTY)
// These platforms do not fork.
#define OPENSSL_DOES_NOT_FORK
#endif
#if defined(__cplusplus)
extern "C" {
#endif
@@ -23,7 +23,7 @@ _CET_ENDBR
adcq %rax,%rax
movq %rdx,0(%rdi)
ret
.byte 0xf3,0xc3
.cfi_endproc
.size CRYPTO_rdrand,.-CRYPTO_rdrand
@@ -50,10 +50,10 @@ _CET_ENDBR
jnz .Lloop
.Lout:
movq $1,%rax
ret
.byte 0xf3,0xc3
.Lerr:
xorq %rax,%rax
ret
.byte 0xf3,0xc3
.cfi_endproc
.size CRYPTO_rdrand_multiple8_buf,.-CRYPTO_rdrand_multiple8_buf
#endif
@@ -23,7 +23,7 @@ _CET_ENDBR
adcq %rax,%rax
movq %rdx,0(%rdi)
ret
.byte 0xf3,0xc3
@@ -50,10 +50,10 @@ L$loop:
jnz L$loop
L$out:
movq $1,%rax
ret
.byte 0xf3,0xc3
L$err:
xorq %rax,%rax
ret
.byte 0xf3,0xc3
#endif
@@ -130,10 +130,11 @@ static int bn_blinding_create_param(BN_BLINDING *b, const BIGNUM *e,
const BN_MONT_CTX *mont, BN_CTX *ctx);
BN_BLINDING *BN_BLINDING_new(void) {
BN_BLINDING *ret = OPENSSL_zalloc(sizeof(BN_BLINDING));
BN_BLINDING *ret = OPENSSL_malloc(sizeof(BN_BLINDING));
if (ret == NULL) {
return NULL;
}
OPENSSL_memset(ret, 0, sizeof(BN_BLINDING));
ret->A = BN_new();
if (ret->A == NULL) {
@@ -206,11 +206,13 @@ RSA *RSA_new_private_key_large_e(const BIGNUM *n, const BIGNUM *e,
RSA *RSA_new(void) { return RSA_new_method(NULL); }
RSA *RSA_new_method(const ENGINE *engine) {
RSA *rsa = OPENSSL_zalloc(sizeof(RSA));
RSA *rsa = OPENSSL_malloc(sizeof(RSA));
if (rsa == NULL) {
return NULL;
}
OPENSSL_memset(rsa, 0, sizeof(RSA));
if (engine) {
rsa->meth = ENGINE_get_RSA_method(engine);
}
@@ -376,7 +376,7 @@ static BN_BLINDING *rsa_blinding_get(RSA *rsa, size_t *index_used,
assert(new_num_blindings > rsa->num_blindings);
BN_BLINDING **new_blindings =
OPENSSL_calloc(new_num_blindings, sizeof(BN_BLINDING *));
OPENSSL_malloc(sizeof(BN_BLINDING *) * new_num_blindings);
uint8_t *new_blindings_inuse = OPENSSL_malloc(new_num_blindings);
if (new_blindings == NULL || new_blindings_inuse == NULL) {
goto err;
@@ -660,7 +660,7 @@ _CET_ENDBR
leaq (%rax),%rsp
.cfi_def_cfa_register %rsp
.Lsqr_1024_epilogue:
ret
.byte 0xf3,0xc3
.cfi_endproc
.size rsaz_1024_sqr_avx2,.-rsaz_1024_sqr_avx2
.globl rsaz_1024_mul_avx2
@@ -1217,7 +1217,7 @@ _CET_ENDBR
leaq (%rax),%rsp
.cfi_def_cfa_register %rsp
.Lmul_1024_epilogue:
ret
.byte 0xf3,0xc3
.cfi_endproc
.size rsaz_1024_mul_avx2,.-rsaz_1024_mul_avx2
.globl rsaz_1024_red2norm_avx2
@@ -1417,7 +1417,7 @@ _CET_ENDBR
adcq $0,%r11
movq %rax,120(%rdi)
movq %r11,%rax
ret
.byte 0xf3,0xc3
.cfi_endproc
.size rsaz_1024_red2norm_avx2,.-rsaz_1024_red2norm_avx2
@@ -1579,7 +1579,7 @@ _CET_ENDBR
movq %r8,168(%rdi)
movq %r8,176(%rdi)
movq %r8,184(%rdi)
ret
.byte 0xf3,0xc3
.cfi_endproc
.size rsaz_1024_norm2red_avx2,.-rsaz_1024_norm2red_avx2
.globl rsaz_1024_scatter5_avx2
@@ -1607,7 +1607,7 @@ _CET_ENDBR
jnz .Loop_scatter_1024
vzeroupper
ret
.byte 0xf3,0xc3
.cfi_endproc
.size rsaz_1024_scatter5_avx2,.-rsaz_1024_scatter5_avx2
@@ -1730,7 +1730,7 @@ _CET_ENDBR
vzeroupper
leaq (%r11),%rsp
.cfi_def_cfa_register %rsp
ret
.byte 0xf3,0xc3
.cfi_endproc
.LSEH_end_rsaz_1024_gather5:
.size rsaz_1024_gather5_avx2,.-rsaz_1024_gather5_avx2
@@ -660,7 +660,7 @@ L$OOP_REDUCE_1024:
leaq (%rax),%rsp
L$sqr_1024_epilogue:
ret
.byte 0xf3,0xc3
.globl _rsaz_1024_mul_avx2
@@ -1217,7 +1217,7 @@ L$oop_mul_1024:
leaq (%rax),%rsp
L$mul_1024_epilogue:
ret
.byte 0xf3,0xc3
.globl _rsaz_1024_red2norm_avx2
@@ -1417,7 +1417,7 @@ _CET_ENDBR
adcq $0,%r11
movq %rax,120(%rdi)
movq %r11,%rax
ret
.byte 0xf3,0xc3
@@ -1579,7 +1579,7 @@ _CET_ENDBR
movq %r8,168(%rdi)
movq %r8,176(%rdi)
movq %r8,184(%rdi)
ret
.byte 0xf3,0xc3
.globl _rsaz_1024_scatter5_avx2
@@ -1607,7 +1607,7 @@ L$oop_scatter_1024:
jnz L$oop_scatter_1024
vzeroupper
ret
.byte 0xf3,0xc3
@@ -1730,7 +1730,7 @@ L$oop_gather_1024:
vzeroupper
leaq (%r11),%rsp
ret
.byte 0xf3,0xc3
L$SEH_end_rsaz_1024_gather5:
@@ -94,11 +94,12 @@ void boringssl_fips_inc_counter(enum fips_counter_t counter) {
CRYPTO_get_thread_local(OPENSSL_THREAD_LOCAL_FIPS_COUNTERS);
if (!array) {
const size_t num_bytes = sizeof(size_t) * (fips_counter_max + 1);
array = OPENSSL_zalloc(num_bytes);
array = OPENSSL_malloc(num_bytes);
if (!array) {
return;
}
OPENSSL_memset(array, 0, num_bytes);
if (!CRYPTO_set_thread_local(OPENSSL_THREAD_LOCAL_FIPS_COUNTERS, array,
OPENSSL_free)) {
// |OPENSSL_free| has already been called by |CRYPTO_set_thread_local|.
@@ -17,172 +17,25 @@
#include <CCryptoBoringSSL_base.h>
#include "../../internal.h"
#if defined(__cplusplus)
extern "C" {
#endif
// Define SHA{n}[_{variant}]_ASM if sha{n}_block_data_order[_{variant}] is
// defined in assembly.
#if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86)
#if !defined(OPENSSL_NO_ASM) && \
(defined(OPENSSL_X86) || defined(OPENSSL_X86_64) || \
defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64))
#define SHA1_ASM
#define SHA256_ASM
#define SHA512_ASM
void sha1_block_data_order(uint32_t *state, const uint8_t *data,
void sha1_block_data_order(uint32_t *state, const uint8_t *in,
size_t num_blocks);
void sha256_block_data_order(uint32_t *state, const uint8_t *data,
void sha256_block_data_order(uint32_t *state, const uint8_t *in,
size_t num_blocks);
void sha512_block_data_order(uint64_t *state, const uint8_t *data,
void sha512_block_data_order(uint64_t *state, const uint8_t *in,
size_t num_blocks);
#elif !defined(OPENSSL_NO_ASM) && defined(OPENSSL_ARM)
#define SHA1_ASM_NOHW
#define SHA256_ASM_NOHW
#define SHA512_ASM_NOHW
#define SHA1_ASM_HW
OPENSSL_INLINE int sha1_hw_capable(void) {
return CRYPTO_is_ARMv8_SHA1_capable();
}
#define SHA1_ASM_NEON
void sha1_block_data_order_neon(uint32_t *state, const uint8_t *data,
size_t num);
#define SHA256_ASM_HW
OPENSSL_INLINE int sha256_hw_capable(void) {
return CRYPTO_is_ARMv8_SHA256_capable();
}
#define SHA256_ASM_NEON
void sha256_block_data_order_neon(uint32_t *state, const uint8_t *data,
size_t num);
// Armv8.2 SHA-512 instructions are not available in 32-bit.
#define SHA512_ASM_NEON
void sha512_block_data_order_neon(uint64_t *state, const uint8_t *data,
size_t num);
#elif !defined(OPENSSL_NO_ASM) && defined(OPENSSL_AARCH64)
#define SHA1_ASM_NOHW
#define SHA256_ASM_NOHW
#define SHA512_ASM_NOHW
#define SHA1_ASM_HW
OPENSSL_INLINE int sha1_hw_capable(void) {
return CRYPTO_is_ARMv8_SHA1_capable();
}
#define SHA256_ASM_HW
OPENSSL_INLINE int sha256_hw_capable(void) {
return CRYPTO_is_ARMv8_SHA256_capable();
}
#define SHA512_ASM_HW
OPENSSL_INLINE int sha512_hw_capable(void) {
return CRYPTO_is_ARMv8_SHA512_capable();
}
#elif !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64)
#define SHA1_ASM_NOHW
#define SHA256_ASM_NOHW
#define SHA512_ASM_NOHW
#define SHA1_ASM_HW
OPENSSL_INLINE int sha1_hw_capable(void) {
return CRYPTO_is_x86_SHA_capable() && CRYPTO_is_SSSE3_capable();
}
#define SHA1_ASM_AVX2
OPENSSL_INLINE int sha1_avx2_capable(void) {
return CRYPTO_is_AVX2_capable() && CRYPTO_is_BMI2_capable() &&
CRYPTO_is_BMI1_capable();
}
void sha1_block_data_order_avx2(uint32_t *state, const uint8_t *data,
size_t num);
#define SHA1_ASM_AVX
OPENSSL_INLINE int sha1_avx_capable(void) {
// Pre-Zen AMD CPUs had slow SHLD/SHRD; Zen added the SHA extension; see the
// discussion in sha1-586.pl.
return CRYPTO_is_AVX_capable() && CRYPTO_is_intel_cpu();
}
void sha1_block_data_order_avx(uint32_t *state, const uint8_t *data,
size_t num);
#define SHA1_ASM_SSSE3
OPENSSL_INLINE int sha1_ssse3_capable(void) {
return CRYPTO_is_SSSE3_capable();
}
void sha1_block_data_order_ssse3(uint32_t *state, const uint8_t *data,
size_t num);
#define SHA256_ASM_HW
OPENSSL_INLINE int sha256_hw_capable(void) {
// Note that the original assembly did not check SSSE3.
return CRYPTO_is_x86_SHA_capable() && CRYPTO_is_SSSE3_capable();
}
#define SHA256_ASM_AVX
OPENSSL_INLINE int sha256_avx_capable(void) {
// Pre-Zen AMD CPUs had slow SHLD/SHRD; Zen added the SHA extension; see the
// discussion in sha1-586.pl.
return CRYPTO_is_AVX_capable() && CRYPTO_is_intel_cpu();
}
void sha256_block_data_order_avx(uint32_t *state, const uint8_t *data,
size_t num);
#define SHA256_ASM_SSSE3
OPENSSL_INLINE int sha256_ssse3_capable(void) {
return CRYPTO_is_SSSE3_capable();
}
void sha256_block_data_order_ssse3(uint32_t *state, const uint8_t *data,
size_t num);
#define SHA512_ASM_AVX
OPENSSL_INLINE int sha512_avx_capable(void) {
// Pre-Zen AMD CPUs had slow SHLD/SHRD; Zen added the SHA extension; see the
// discussion in sha1-586.pl.
return CRYPTO_is_AVX_capable() && CRYPTO_is_intel_cpu();
}
void sha512_block_data_order_avx(uint64_t *state, const uint8_t *data,
size_t num);
#endif
#if defined(SHA1_ASM_HW)
void sha1_block_data_order_hw(uint32_t *state, const uint8_t *data, size_t num);
#endif
#if defined(SHA1_ASM_NOHW)
void sha1_block_data_order_nohw(uint32_t *state, const uint8_t *data,
size_t num);
#endif
#if defined(SHA256_ASM_HW)
void sha256_block_data_order_hw(uint32_t *state, const uint8_t *data,
size_t num);
#endif
#if defined(SHA256_ASM_NOHW)
void sha256_block_data_order_nohw(uint32_t *state, const uint8_t *data,
size_t num);
#endif
#if defined(SHA512_ASM_HW)
void sha512_block_data_order_hw(uint64_t *state, const uint8_t *data,
size_t num);
#endif
#if defined(SHA512_ASM_NOHW)
void sha512_block_data_order_nohw(uint64_t *state, const uint8_t *data,
size_t num);
#endif
#if defined(__cplusplus)
} // extern "C"
@@ -100,60 +100,19 @@ int SHA1_Update(SHA_CTX *c, const void *data, size_t len) {
return 1;
}
static void sha1_output_state(uint8_t out[SHA_DIGEST_LENGTH],
const SHA_CTX *ctx) {
CRYPTO_store_u32_be(out, ctx->h[0]);
CRYPTO_store_u32_be(out + 4, ctx->h[1]);
CRYPTO_store_u32_be(out + 8, ctx->h[2]);
CRYPTO_store_u32_be(out + 12, ctx->h[3]);
CRYPTO_store_u32_be(out + 16, ctx->h[4]);
}
int SHA1_Final(uint8_t out[SHA_DIGEST_LENGTH], SHA_CTX *c) {
crypto_md32_final(&sha1_block_data_order, c->h, c->data, SHA_CBLOCK, &c->num,
c->Nh, c->Nl, /*is_big_endian=*/1);
sha1_output_state(out, c);
CRYPTO_store_u32_be(out, c->h[0]);
CRYPTO_store_u32_be(out + 4, c->h[1]);
CRYPTO_store_u32_be(out + 8, c->h[2]);
CRYPTO_store_u32_be(out + 12, c->h[3]);
CRYPTO_store_u32_be(out + 16, c->h[4]);
FIPS_service_indicator_update_state();
return 1;
}
void CRYPTO_fips_186_2_prf(uint8_t *out, size_t out_len,
const uint8_t xkey[SHA_DIGEST_LENGTH]) {
// XKEY and XVAL are 160-bit values, but are internally right-padded up to
// block size. See FIPS 186-2, Appendix 3.3. This buffer maintains both the
// current value of XKEY and the padding.
uint8_t block[SHA_CBLOCK] = {0};
OPENSSL_memcpy(block, xkey, SHA_DIGEST_LENGTH);
while (out_len != 0) {
// We always use a zero XSEED, so we can merge the inner and outer loops.
// XVAL is also always equal to XKEY.
SHA_CTX ctx;
SHA1_Init(&ctx);
SHA1_Transform(&ctx, block);
// XKEY = (1 + XKEY + w_i) mod 2^b
uint32_t carry = 1;
for (int i = 4; i >= 0; i--) {
uint32_t tmp = CRYPTO_load_u32_be(block + i * 4);
tmp = CRYPTO_addc_u32(tmp, ctx.h[i], carry, &carry);
CRYPTO_store_u32_be(block + i * 4, tmp);
}
// Output w_i.
if (out_len < SHA_DIGEST_LENGTH) {
uint8_t buf[SHA_DIGEST_LENGTH];
sha1_output_state(buf, &ctx);
OPENSSL_memcpy(out, buf, out_len);
break;
}
sha1_output_state(out, &ctx);
out += SHA_DIGEST_LENGTH;
out_len -= SHA_DIGEST_LENGTH;
}
}
#define Xupdate(a, ix, ia, ib, ic, id) \
do { \
(a) = ((ia) ^ (ib) ^ (ic) ^ (id)); \
@@ -232,10 +191,8 @@ void CRYPTO_fips_186_2_prf(uint8_t *out, size_t out_len,
#define X(i) XX##i
#if !defined(SHA1_ASM)
#if !defined(SHA1_ASM_NOHW)
static void sha1_block_data_order_nohw(uint32_t *state, const uint8_t *data,
size_t num) {
static void sha1_block_data_order(uint32_t *state, const uint8_t *data,
size_t num) {
register uint32_t A, B, C, D, E, T;
uint32_t XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7, XX8, XX9, XX10,
XX11, XX12, XX13, XX14, XX15;
@@ -382,44 +339,7 @@ static void sha1_block_data_order_nohw(uint32_t *state, const uint8_t *data,
E = state[4];
}
}
#endif // !SHA1_ASM_NOHW
static void sha1_block_data_order(uint32_t *state, const uint8_t *data,
size_t num) {
#if defined(SHA1_ASM_HW)
if (sha1_hw_capable()) {
sha1_block_data_order_hw(state, data, num);
return;
}
#endif
#if defined(SHA1_ASM_AVX2)
if (sha1_avx2_capable()) {
sha1_block_data_order_avx(state, data, num);
return;
}
#endif
#if defined(SHA1_ASM_AVX)
if (sha1_avx_capable()) {
sha1_block_data_order_avx(state, data, num);
return;
}
#endif
#if defined(SHA1_ASM_SSSE3)
if (sha1_ssse3_capable()) {
sha1_block_data_order_ssse3(state, data, num);
return;
}
#endif
#if defined(SHA1_ASM_NEON)
if (CRYPTO_is_NEON_capable()) {
sha1_block_data_order_neon(state, data, num);
return;
}
#endif
sha1_block_data_order_nohw(state, data, num);
}
#endif // !SHA1_ASM
#undef Xupdate
#undef K_00_19
@@ -114,7 +114,7 @@ uint8_t *SHA256(const uint8_t *data, size_t len,
return out;
}
#if !defined(SHA256_ASM)
#ifndef SHA256_ASM
static void sha256_block_data_order(uint32_t *state, const uint8_t *in,
size_t num);
#endif
@@ -172,9 +172,7 @@ int SHA224_Final(uint8_t out[SHA224_DIGEST_LENGTH], SHA256_CTX *ctx) {
return sha256_final_impl(out, SHA224_DIGEST_LENGTH, ctx);
}
#if !defined(SHA256_ASM)
#if !defined(SHA256_ASM_NOHW)
#ifndef SHA256_ASM
static const uint32_t K256[64] = {
0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL, 0x3956c25bUL,
0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL, 0xd807aa98UL, 0x12835b01UL,
@@ -223,8 +221,8 @@ static const uint32_t K256[64] = {
ROUND_00_15(i, a, b, c, d, e, f, g, h); \
} while (0)
static void sha256_block_data_order_nohw(uint32_t *state, const uint8_t *data,
size_t num) {
static void sha256_block_data_order(uint32_t *state, const uint8_t *data,
size_t num) {
uint32_t a, b, c, d, e, f, g, h, s0, s1, T1;
uint32_t X[16];
int i;
@@ -310,39 +308,7 @@ static void sha256_block_data_order_nohw(uint32_t *state, const uint8_t *data,
}
}
#endif // !defined(SHA256_ASM_NOHW)
static void sha256_block_data_order(uint32_t *state, const uint8_t *data,
size_t num) {
#if defined(SHA256_ASM_HW)
if (sha256_hw_capable()) {
sha256_block_data_order_hw(state, data, num);
return;
}
#endif
#if defined(SHA256_ASM_AVX)
if (sha256_avx_capable()) {
sha256_block_data_order_avx(state, data, num);
return;
}
#endif
#if defined(SHA256_ASM_SSSE3)
if (sha256_ssse3_capable()) {
sha256_block_data_order_ssse3(state, data, num);
return;
}
#endif
#if defined(SHA256_ASM_NEON)
if (CRYPTO_is_NEON_capable()) {
sha256_block_data_order_neon(state, data, num);
return;
}
#endif
sha256_block_data_order_nohw(state, data, num);
}
#endif // !defined(SHA256_ASM)
#endif // !SHA256_ASM
void SHA256_TransformBlocks(uint32_t state[8], const uint8_t *data,
size_t num_blocks) {
@@ -279,9 +279,7 @@ static int sha512_final_impl(uint8_t *out, size_t md_len, SHA512_CTX *sha) {
return 1;
}
#if !defined(SHA512_ASM)
#if !defined(SHA512_ASM_NOHW)
#ifndef SHA512_ASM
static const uint64_t K512[80] = {
UINT64_C(0x428a2f98d728ae22), UINT64_C(0x7137449123ef65cd),
UINT64_C(0xb5c0fbcfec4d3b2f), UINT64_C(0xe9b5dba58189dbbc),
@@ -343,8 +341,8 @@ static const uint64_t K512[80] = {
#if defined(__i386) || defined(__i386__) || defined(_M_IX86)
// This code should give better results on 32-bit CPU with less than
// ~24 registers, both size and performance wise...
static void sha512_block_data_order_nohw(uint64_t *state, const uint8_t *in,
size_t num) {
static void sha512_block_data_order(uint64_t *state, const uint8_t *in,
size_t num) {
uint64_t A, E, T;
uint64_t X[9 + 80], *F;
int i;
@@ -416,8 +414,8 @@ static void sha512_block_data_order_nohw(uint64_t *state, const uint8_t *in,
ROUND_00_15(i + j, a, b, c, d, e, f, g, h); \
} while (0)
static void sha512_block_data_order_nohw(uint64_t *state, const uint8_t *in,
size_t num) {
static void sha512_block_data_order(uint64_t *state, const uint8_t *in,
size_t num) {
uint64_t a, b, c, d, e, f, g, h, s0, s1, T1;
uint64_t X[16];
int i;
@@ -500,31 +498,6 @@ static void sha512_block_data_order_nohw(uint64_t *state, const uint8_t *in,
#endif
#endif // !SHA512_ASM_NOHW
static void sha512_block_data_order(uint64_t *state, const uint8_t *data,
size_t num) {
#if defined(SHA512_ASM_HW)
if (sha512_hw_capable()) {
sha512_block_data_order_hw(state, data, num);
return;
}
#endif
#if defined(SHA512_ASM_AVX)
if (sha512_avx_capable()) {
sha512_block_data_order_avx(state, data, num);
return;
}
#endif
#if defined(SHA512_ASM_NEON)
if (CRYPTO_is_NEON_capable()) {
sha512_block_data_order_neon(state, data, num);
return;
}
#endif
sha512_block_data_order_nohw(state, data, num);
}
#endif // !SHA512_ASM
#undef Sigma0
Loaded 100 of 333 files, more files were not shown because too many files have changed in this diff. Show more