mirror of
https://github.com/apple/swift-crypto
synced 2026-11-22 04:30:39 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
067254c794 | ||
|
|
476397d837 | ||
|
|
facc82fbb4 | ||
|
|
3fb2ea5d41 |
No files matched your search
@@ -37,6 +37,11 @@ if(BUILD_SHARED_LIBS)
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE YES)
|
||||
endif()
|
||||
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL Darwin AND NOT CMAKE_CROSSCOMPILING)
|
||||
set(CMAKE_AR "/usr/bin/ar")
|
||||
set(CMAKE_C_ARCHIVE_CREATE "<CMAKE_AR> crs <TARGET> <LINK_FLAGS> <OBJECTS>")
|
||||
endif()
|
||||
|
||||
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
|
||||
find_package(dispatch CONFIG)
|
||||
find_package(Foundation CONFIG)
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@
|
||||
// Sources/CCryptoBoringSSL directory. The source repository is at
|
||||
// https://boringssl.googlesource.com/boringssl.
|
||||
//
|
||||
// BoringSSL Commit: 295b31324f8c557dcd3c1c831857e33a7f23bc52
|
||||
// BoringSSL Commit: 8bbefbfeee609b17622deedd100163c12f5c95dc
|
||||
|
||||
import PackageDescription
|
||||
|
||||
|
||||
+2
-3
@@ -17,7 +17,6 @@ add_library(CCryptoBoringSSL STATIC
|
||||
"crypto/asn1/a_bool.c"
|
||||
"crypto/asn1/a_d2i_fp.c"
|
||||
"crypto/asn1/a_dup.c"
|
||||
"crypto/asn1/a_enum.c"
|
||||
"crypto/asn1/a_gentm.c"
|
||||
"crypto/asn1/a_i2d_fp.c"
|
||||
"crypto/asn1/a_int.c"
|
||||
@@ -70,6 +69,7 @@ add_library(CCryptoBoringSSL STATIC
|
||||
"crypto/cipher_extra/e_aesctrhmac.c"
|
||||
"crypto/cipher_extra/e_aesgcmsiv.c"
|
||||
"crypto/cipher_extra/e_chacha20poly1305.c"
|
||||
"crypto/cipher_extra/e_des.c"
|
||||
"crypto/cipher_extra/e_null.c"
|
||||
"crypto/cipher_extra/e_rc2.c"
|
||||
"crypto/cipher_extra/e_rc4.c"
|
||||
@@ -88,6 +88,7 @@ add_library(CCryptoBoringSSL STATIC
|
||||
"crypto/crypto.c"
|
||||
"crypto/curve25519/curve25519.c"
|
||||
"crypto/curve25519/spake25519.c"
|
||||
"crypto/des/des.c"
|
||||
"crypto/dh_extra/dh_asn1.c"
|
||||
"crypto/dh_extra/params.c"
|
||||
"crypto/digest_extra/digest_extra.c"
|
||||
@@ -147,8 +148,6 @@ add_library(CCryptoBoringSSL STATIC
|
||||
"crypto/fipsmodule/cipher/aead.c"
|
||||
"crypto/fipsmodule/cipher/cipher.c"
|
||||
"crypto/fipsmodule/cipher/e_aes.c"
|
||||
"crypto/fipsmodule/cipher/e_des.c"
|
||||
"crypto/fipsmodule/des/des.c"
|
||||
"crypto/fipsmodule/dh/check.c"
|
||||
"crypto/fipsmodule/dh/dh.c"
|
||||
"crypto/fipsmodule/digest/digest.c"
|
||||
|
||||
@@ -1,195 +0,0 @@
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.] */
|
||||
|
||||
#include <CCryptoBoringSSL_asn1.h>
|
||||
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
/*
|
||||
* Code for ENUMERATED type: identical to INTEGER apart from a different tag.
|
||||
* for comments on encoding see a_int.c
|
||||
*/
|
||||
|
||||
int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v)
|
||||
{
|
||||
int j, k;
|
||||
unsigned int i;
|
||||
unsigned char buf[sizeof(long) + 1];
|
||||
long d;
|
||||
|
||||
a->type = V_ASN1_ENUMERATED;
|
||||
if (a->length < (int)(sizeof(long) + 1)) {
|
||||
if (a->data != NULL)
|
||||
OPENSSL_free(a->data);
|
||||
if ((a->data =
|
||||
(unsigned char *)OPENSSL_malloc(sizeof(long) + 1)) != NULL)
|
||||
OPENSSL_memset((char *)a->data, 0, sizeof(long) + 1);
|
||||
}
|
||||
if (a->data == NULL) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
|
||||
return (0);
|
||||
}
|
||||
d = v;
|
||||
if (d < 0) {
|
||||
d = -d;
|
||||
a->type = V_ASN1_NEG_ENUMERATED;
|
||||
}
|
||||
|
||||
for (i = 0; i < sizeof(long); i++) {
|
||||
if (d == 0)
|
||||
break;
|
||||
buf[i] = (int)d & 0xff;
|
||||
d >>= 8;
|
||||
}
|
||||
j = 0;
|
||||
for (k = i - 1; k >= 0; k--)
|
||||
a->data[j++] = buf[k];
|
||||
a->length = j;
|
||||
return (1);
|
||||
}
|
||||
|
||||
long ASN1_ENUMERATED_get(const ASN1_ENUMERATED *a)
|
||||
{
|
||||
int neg = 0, i;
|
||||
|
||||
if (a == NULL)
|
||||
return (0L);
|
||||
i = a->type;
|
||||
if (i == V_ASN1_NEG_ENUMERATED)
|
||||
neg = 1;
|
||||
else if (i != V_ASN1_ENUMERATED)
|
||||
return -1;
|
||||
|
||||
OPENSSL_STATIC_ASSERT(sizeof(uint64_t) >= sizeof(long),
|
||||
"long larger than uint64_t");
|
||||
|
||||
if (a->length > (int)sizeof(uint64_t)) {
|
||||
/* hmm... a bit ugly */
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint64_t r64 = 0;
|
||||
if (a->data != NULL) {
|
||||
for (i = 0; i < a->length; i++) {
|
||||
r64 <<= 8;
|
||||
r64 |= (unsigned char)a->data[i];
|
||||
}
|
||||
|
||||
if (r64 > LONG_MAX) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
long r = (long) r64;
|
||||
if (neg)
|
||||
r = -r;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(const BIGNUM *bn, ASN1_ENUMERATED *ai)
|
||||
{
|
||||
ASN1_ENUMERATED *ret;
|
||||
int len, j;
|
||||
|
||||
if (ai == NULL)
|
||||
ret = ASN1_ENUMERATED_new();
|
||||
else
|
||||
ret = ai;
|
||||
if (ret == NULL) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
||||
goto err;
|
||||
}
|
||||
if (BN_is_negative(bn))
|
||||
ret->type = V_ASN1_NEG_ENUMERATED;
|
||||
else
|
||||
ret->type = V_ASN1_ENUMERATED;
|
||||
j = BN_num_bits(bn);
|
||||
len = ((j == 0) ? 0 : ((j / 8) + 1));
|
||||
if (ret->length < len + 4) {
|
||||
unsigned char *new_data = OPENSSL_realloc(ret->data, len + 4);
|
||||
if (!new_data) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
ret->data = new_data;
|
||||
}
|
||||
|
||||
ret->length = BN_bn2bin(bn, ret->data);
|
||||
return (ret);
|
||||
err:
|
||||
if (ret != ai)
|
||||
ASN1_ENUMERATED_free(ret);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
BIGNUM *ASN1_ENUMERATED_to_BN(const ASN1_ENUMERATED *ai, BIGNUM *bn)
|
||||
{
|
||||
BIGNUM *ret;
|
||||
|
||||
if ((ret = BN_bin2bn(ai->data, ai->length, bn)) == NULL)
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BN_LIB);
|
||||
else if (ai->type == V_ASN1_NEG_ENUMERATED)
|
||||
BN_set_negative(ret, 1);
|
||||
return (ret);
|
||||
}
|
||||
@@ -59,8 +59,10 @@
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <CCryptoBoringSSL_bytestring.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_type_check.h>
|
||||
|
||||
#include "../internal.h"
|
||||
|
||||
@@ -72,129 +74,110 @@ ASN1_INTEGER *ASN1_INTEGER_dup(const ASN1_INTEGER *x)
|
||||
|
||||
int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y)
|
||||
{
|
||||
int neg, ret;
|
||||
/* Compare signs */
|
||||
neg = x->type & V_ASN1_NEG;
|
||||
/* Compare signs. */
|
||||
int neg = x->type & V_ASN1_NEG;
|
||||
if (neg != (y->type & V_ASN1_NEG)) {
|
||||
if (neg)
|
||||
return -1;
|
||||
else
|
||||
return neg ? -1 : 1;
|
||||
}
|
||||
|
||||
int ret = ASN1_STRING_cmp(x, y);
|
||||
if (neg) {
|
||||
/* This could be |-ret|, but |ASN1_STRING_cmp| is not forbidden from
|
||||
* returning |INT_MIN|. */
|
||||
if (ret < 0) {
|
||||
return 1;
|
||||
} else if (ret > 0) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
ret = ASN1_STRING_cmp(x, y);
|
||||
|
||||
if (neg)
|
||||
return -ret;
|
||||
else
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* This converts an ASN1 INTEGER into its content encoding.
|
||||
* The internal representation is an ASN1_STRING whose data is a big endian
|
||||
* representation of the value, ignoring the sign. The sign is determined by
|
||||
* the type: V_ASN1_INTEGER for positive and V_ASN1_NEG_INTEGER for negative.
|
||||
*
|
||||
* Positive integers are no problem: they are almost the same as the DER
|
||||
* encoding, except if the first byte is >= 0x80 we need to add a zero pad.
|
||||
*
|
||||
* Negative integers are a bit trickier...
|
||||
* The DER representation of negative integers is in 2s complement form.
|
||||
* The internal form is converted by complementing each octet and finally
|
||||
* adding one to the result. This can be done less messily with a little trick.
|
||||
* If the internal form has trailing zeroes then they will become FF by the
|
||||
* complement and 0 by the add one (due to carry) so just copy as many trailing
|
||||
* zeros to the destination as there are in the source. The carry will add one
|
||||
* to the last none zero octet: so complement this octet and add one and finally
|
||||
* complement any left over until you get to the start of the string.
|
||||
*
|
||||
* Padding is a little trickier too. If the first bytes is > 0x80 then we pad
|
||||
* with 0xff. However if the first byte is 0x80 and one of the following bytes
|
||||
* is non-zero we pad with 0xff. The reason for this distinction is that 0x80
|
||||
* followed by optional zeros isn't padded.
|
||||
*/
|
||||
|
||||
int i2c_ASN1_INTEGER(const ASN1_INTEGER *a, unsigned char **pp)
|
||||
/* negate_twos_complement negates |len| bytes from |buf| in-place, interpreted
|
||||
* as a signed, big-endian two's complement value. */
|
||||
static void negate_twos_complement(uint8_t *buf, size_t len)
|
||||
{
|
||||
int pad = 0, ret, i, neg;
|
||||
unsigned char *p, *n, pb = 0;
|
||||
|
||||
if (a == NULL)
|
||||
return (0);
|
||||
neg = a->type & V_ASN1_NEG;
|
||||
if (a->length == 0)
|
||||
ret = 1;
|
||||
else {
|
||||
ret = a->length;
|
||||
i = a->data[0];
|
||||
if (ret == 1 && i == 0)
|
||||
neg = 0;
|
||||
if (!neg && (i > 127)) {
|
||||
pad = 1;
|
||||
pb = 0;
|
||||
} else if (neg) {
|
||||
if (i > 128) {
|
||||
pad = 1;
|
||||
pb = 0xFF;
|
||||
} else if (i == 128) {
|
||||
/*
|
||||
* Special case: if any other bytes non zero we pad:
|
||||
* otherwise we don't.
|
||||
*/
|
||||
for (i = 1; i < a->length; i++)
|
||||
if (a->data[i]) {
|
||||
pad = 1;
|
||||
pb = 0xFF;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
ret += pad;
|
||||
uint8_t borrow = 0;
|
||||
for (size_t i = len - 1; i < len; i--) {
|
||||
uint8_t t = buf[i];
|
||||
buf[i] = 0u - borrow - t;
|
||||
borrow |= t != 0;
|
||||
}
|
||||
if (pp == NULL)
|
||||
return (ret);
|
||||
p = *pp;
|
||||
|
||||
if (pad)
|
||||
*(p++) = pb;
|
||||
if (a->length == 0)
|
||||
*(p++) = 0;
|
||||
else if (!neg)
|
||||
OPENSSL_memcpy(p, a->data, (unsigned int)a->length);
|
||||
else {
|
||||
/* Begin at the end of the encoding */
|
||||
n = a->data + a->length - 1;
|
||||
p += a->length - 1;
|
||||
i = a->length;
|
||||
/* Copy zeros to destination as long as source is zero */
|
||||
while (!*n && i > 1) {
|
||||
*(p--) = 0;
|
||||
n--;
|
||||
i--;
|
||||
}
|
||||
/* Complement and increment next octet */
|
||||
*(p--) = ((*(n--)) ^ 0xff) + 1;
|
||||
i--;
|
||||
/* Complement any octets left */
|
||||
for (; i > 0; i--)
|
||||
*(p--) = *(n--) ^ 0xff;
|
||||
}
|
||||
|
||||
*pp += ret;
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/* Convert just ASN1 INTEGER content octets to ASN1_INTEGER structure */
|
||||
static int is_all_zeros(const uint8_t *in, size_t len) {
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
if (in[i] != 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp,
|
||||
int i2c_ASN1_INTEGER(const ASN1_INTEGER *in, unsigned char **outp)
|
||||
{
|
||||
if (in == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* |ASN1_INTEGER|s should be represented minimally, but it is possible to
|
||||
* construct invalid ones. Skip leading zeros so this does not produce an
|
||||
* invalid encoding or break invariants. */
|
||||
int start = 0;
|
||||
while (start < in->length && in->data[start] == 0) {
|
||||
start++;
|
||||
}
|
||||
|
||||
int is_negative = (in->type & V_ASN1_NEG) != 0;
|
||||
int pad;
|
||||
if (start >= in->length) {
|
||||
/* Zero is represented as a single byte. */
|
||||
is_negative = 0;
|
||||
pad = 1;
|
||||
} else if (is_negative) {
|
||||
/* 0x80...01 through 0xff...ff have a two's complement of 0x7f...ff
|
||||
* through 0x00...01 and need an extra byte to be negative.
|
||||
* 0x01...00 through 0x80...00 have a two's complement of 0xfe...ff
|
||||
* through 0x80...00 and can be negated as-is. */
|
||||
pad = in->data[start] > 0x80 ||
|
||||
(in->data[start] == 0x80 &&
|
||||
!is_all_zeros(in->data + start + 1, in->length - start - 1));
|
||||
} else {
|
||||
/* If the high bit is set, the signed representation needs an extra
|
||||
* byte to be positive. */
|
||||
pad = (in->data[start] & 0x80) != 0;
|
||||
}
|
||||
|
||||
if (in->length - start > INT_MAX - pad) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_OVERFLOW);
|
||||
return 0;
|
||||
}
|
||||
int len = pad + in->length - start;
|
||||
assert(len > 0);
|
||||
if (outp == NULL) {
|
||||
return len;
|
||||
}
|
||||
|
||||
if (pad) {
|
||||
(*outp)[0] = 0;
|
||||
}
|
||||
OPENSSL_memcpy(*outp + pad, in->data + start, in->length - start);
|
||||
if (is_negative) {
|
||||
negate_twos_complement(*outp, len);
|
||||
assert((*outp)[0] >= 0x80);
|
||||
} else {
|
||||
assert((*outp)[0] < 0x80);
|
||||
}
|
||||
*outp += len;
|
||||
return len;
|
||||
}
|
||||
|
||||
ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **out, const unsigned char **inp,
|
||||
long len)
|
||||
{
|
||||
ASN1_INTEGER *ret = NULL;
|
||||
const unsigned char *p, *pend;
|
||||
unsigned char *to, *s;
|
||||
int i;
|
||||
|
||||
/*
|
||||
* This function can handle lengths up to INT_MAX - 1, but the rest of the
|
||||
* legacy ASN.1 code mixes integer types, so avoid exposing it to
|
||||
@@ -205,85 +188,69 @@ ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((a == NULL) || ((*a) == NULL)) {
|
||||
if ((ret = ASN1_INTEGER_new()) == NULL)
|
||||
return (NULL);
|
||||
ret->type = V_ASN1_INTEGER;
|
||||
} else
|
||||
ret = (*a);
|
||||
|
||||
p = *pp;
|
||||
pend = p + len;
|
||||
|
||||
/*
|
||||
* We must OPENSSL_malloc stuff, even for 0 bytes otherwise it signifies
|
||||
* a missing NULL parameter.
|
||||
*/
|
||||
s = (unsigned char *)OPENSSL_malloc((int)len + 1);
|
||||
if (s == NULL) {
|
||||
i = ERR_R_MALLOC_FAILURE;
|
||||
goto err;
|
||||
CBS cbs;
|
||||
CBS_init(&cbs, *inp, (size_t)len);
|
||||
int is_negative;
|
||||
if (!CBS_is_valid_asn1_integer(&cbs, &is_negative)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_INTEGER);
|
||||
return NULL;
|
||||
}
|
||||
to = s;
|
||||
if (!len) {
|
||||
/*
|
||||
* Strictly speaking this is an illegal INTEGER but we tolerate it.
|
||||
*/
|
||||
ret->type = V_ASN1_INTEGER;
|
||||
} else if (*p & 0x80) { /* a negative number */
|
||||
ret->type = V_ASN1_NEG_INTEGER;
|
||||
if ((*p == 0xff) && (len != 1)) {
|
||||
p++;
|
||||
len--;
|
||||
}
|
||||
i = len;
|
||||
p += i - 1;
|
||||
to += i - 1;
|
||||
while ((!*p) && i) {
|
||||
*(to--) = 0;
|
||||
i--;
|
||||
p--;
|
||||
}
|
||||
/*
|
||||
* Special case: if all zeros then the number will be of the form FF
|
||||
* followed by n zero bytes: this corresponds to 1 followed by n zero
|
||||
* bytes. We've already written n zeros so we just append an extra
|
||||
* one and set the first byte to a 1. This is treated separately
|
||||
* because it is the only case where the number of bytes is larger
|
||||
* than len.
|
||||
*/
|
||||
if (!i) {
|
||||
*s = 1;
|
||||
s[len] = 0;
|
||||
len++;
|
||||
} else {
|
||||
*(to--) = (*(p--) ^ 0xff) + 1;
|
||||
i--;
|
||||
for (; i > 0; i--)
|
||||
*(to--) = *(p--) ^ 0xff;
|
||||
|
||||
ASN1_INTEGER *ret = NULL;
|
||||
if (out == NULL || *out == NULL) {
|
||||
ret = ASN1_INTEGER_new();
|
||||
if (ret == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
ret->type = V_ASN1_INTEGER;
|
||||
if ((*p == 0) && (len != 1)) {
|
||||
p++;
|
||||
len--;
|
||||
}
|
||||
OPENSSL_memcpy(s, p, (int)len);
|
||||
ret = *out;
|
||||
}
|
||||
|
||||
if (ret->data != NULL)
|
||||
OPENSSL_free(ret->data);
|
||||
ret->data = s;
|
||||
ret->length = (int)len;
|
||||
if (a != NULL)
|
||||
(*a) = ret;
|
||||
*pp = pend;
|
||||
return (ret);
|
||||
/* Convert to |ASN1_INTEGER|'s sign-and-magnitude representation. First,
|
||||
* determine the size needed for a minimal result. */
|
||||
if (is_negative) {
|
||||
/* 0xff00...01 through 0xff7f..ff have a two's complement of 0x00ff...ff
|
||||
* through 0x000100...001 and need one leading zero removed. 0x8000...00
|
||||
* through 0xff00...00 have a two's complement of 0x8000...00 through
|
||||
* 0x0100...00 and will be minimally-encoded as-is. */
|
||||
if (CBS_len(&cbs) > 0 && CBS_data(&cbs)[0] == 0xff &&
|
||||
!is_all_zeros(CBS_data(&cbs) + 1, CBS_len(&cbs) - 1)) {
|
||||
CBS_skip(&cbs, 1);
|
||||
}
|
||||
} else {
|
||||
/* Remove the leading zero byte, if any. */
|
||||
if (CBS_len(&cbs) > 0 && CBS_data(&cbs)[0] == 0x00) {
|
||||
CBS_skip(&cbs, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (!ASN1_STRING_set(ret, CBS_data(&cbs), CBS_len(&cbs))) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (is_negative) {
|
||||
ret->type = V_ASN1_NEG_INTEGER;
|
||||
negate_twos_complement(ret->data, ret->length);
|
||||
} else {
|
||||
ret->type = V_ASN1_INTEGER;
|
||||
}
|
||||
|
||||
/* The value should be minimally-encoded. */
|
||||
assert(ret->length == 0 || ret->data[0] != 0);
|
||||
/* Zero is not negative. */
|
||||
assert(!is_negative || ret->length > 0);
|
||||
|
||||
*inp += len;
|
||||
if (out != NULL) {
|
||||
*out = ret;
|
||||
}
|
||||
return ret;
|
||||
|
||||
err:
|
||||
OPENSSL_PUT_ERROR(ASN1, i);
|
||||
if ((ret != NULL) && ((a == NULL) || (*a != ret)))
|
||||
if (ret != NULL && (out == NULL || *out != ret)) {
|
||||
ASN1_INTEGER_free(ret);
|
||||
return (NULL);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int ASN1_INTEGER_set(ASN1_INTEGER *a, long v)
|
||||
@@ -300,121 +267,196 @@ int ASN1_INTEGER_set(ASN1_INTEGER *a, long v)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ASN1_INTEGER_set_uint64(ASN1_INTEGER *out, uint64_t v)
|
||||
int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v)
|
||||
{
|
||||
uint8_t *const newdata = OPENSSL_malloc(sizeof(uint64_t));
|
||||
if (newdata == NULL) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
|
||||
if (v >= 0) {
|
||||
return ASN1_ENUMERATED_set_uint64(a, (uint64_t) v);
|
||||
}
|
||||
|
||||
if (!ASN1_ENUMERATED_set_uint64(a, 0 - (uint64_t) v)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
OPENSSL_free(out->data);
|
||||
out->data = newdata;
|
||||
v = CRYPTO_bswap8(v);
|
||||
memcpy(out->data, &v, sizeof(v));
|
||||
|
||||
out->type = V_ASN1_INTEGER;
|
||||
a->type = V_ASN1_NEG_ENUMERATED;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int asn1_string_set_uint64(ASN1_STRING *out, uint64_t v, int type)
|
||||
{
|
||||
uint8_t buf[sizeof(uint64_t)];
|
||||
CRYPTO_store_u64_be(buf, v);
|
||||
size_t leading_zeros;
|
||||
for (leading_zeros = 0; leading_zeros < sizeof(uint64_t) - 1;
|
||||
leading_zeros++) {
|
||||
if (out->data[leading_zeros] != 0) {
|
||||
break;
|
||||
}
|
||||
for (leading_zeros = 0; leading_zeros < sizeof(buf); leading_zeros++) {
|
||||
if (buf[leading_zeros] != 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
out->length = sizeof(uint64_t) - leading_zeros;
|
||||
OPENSSL_memmove(out->data, out->data + leading_zeros, out->length);
|
||||
|
||||
if (!ASN1_STRING_set(out, buf + leading_zeros,
|
||||
sizeof(buf) - leading_zeros)) {
|
||||
return 0;
|
||||
}
|
||||
out->type = type;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ASN1_INTEGER_set_uint64(ASN1_INTEGER *out, uint64_t v)
|
||||
{
|
||||
return asn1_string_set_uint64(out, v, V_ASN1_INTEGER);
|
||||
}
|
||||
|
||||
int ASN1_ENUMERATED_set_uint64(ASN1_ENUMERATED *out, uint64_t v)
|
||||
{
|
||||
return asn1_string_set_uint64(out, v, V_ASN1_ENUMERATED);
|
||||
}
|
||||
|
||||
static int asn1_string_get_abs_uint64(uint64_t *out, const ASN1_STRING *a,
|
||||
int type)
|
||||
{
|
||||
if ((a->type & ~V_ASN1_NEG) != type) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_WRONG_INTEGER_TYPE);
|
||||
return 0;
|
||||
}
|
||||
uint8_t buf[sizeof(uint64_t)] = {0};
|
||||
if (a->length > (int)sizeof(buf)) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_INTEGER);
|
||||
return 0;
|
||||
}
|
||||
OPENSSL_memcpy(buf + sizeof(buf) - a->length, a->data, a->length);
|
||||
*out = CRYPTO_load_u64_be(buf);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int asn1_string_get_uint64(uint64_t *out, const ASN1_STRING *a, int type)
|
||||
{
|
||||
if (!asn1_string_get_abs_uint64(out, a, type)) {
|
||||
return 0;
|
||||
}
|
||||
if (a->type & V_ASN1_NEG) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_INVALID_INTEGER);
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ASN1_INTEGER_get_uint64(uint64_t *out, const ASN1_INTEGER *a)
|
||||
{
|
||||
return asn1_string_get_uint64(out, a, V_ASN1_INTEGER);
|
||||
}
|
||||
|
||||
int ASN1_ENUMERATED_get_uint64(uint64_t *out, const ASN1_ENUMERATED *a)
|
||||
{
|
||||
return asn1_string_get_uint64(out, a, V_ASN1_ENUMERATED);
|
||||
}
|
||||
|
||||
static long asn1_string_get_long(const ASN1_STRING *a, int type)
|
||||
{
|
||||
if (a == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint64_t v;
|
||||
if (!asn1_string_get_abs_uint64(&v, a, type)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
int64_t i64;
|
||||
int fits_in_i64;
|
||||
/* Check |v != 0| to handle manually-constructed negative zeros. */
|
||||
if ((a->type & V_ASN1_NEG) && v != 0) {
|
||||
i64 = (int64_t)(0u - v);
|
||||
fits_in_i64 = i64 < 0;
|
||||
} else {
|
||||
i64 = (int64_t)v;
|
||||
fits_in_i64 = i64 >= 0;
|
||||
}
|
||||
OPENSSL_STATIC_ASSERT(sizeof(long) <= sizeof(int64_t), "long is too big");
|
||||
|
||||
if (fits_in_i64 && LONG_MIN <= i64 && i64 <= LONG_MAX) {
|
||||
return (long)i64;
|
||||
}
|
||||
|
||||
err:
|
||||
/* This function's return value does not distinguish overflow from -1. */
|
||||
ERR_clear_error();
|
||||
return -1;
|
||||
}
|
||||
|
||||
long ASN1_INTEGER_get(const ASN1_INTEGER *a)
|
||||
{
|
||||
int neg = 0, i;
|
||||
|
||||
if (a == NULL)
|
||||
return (0L);
|
||||
i = a->type;
|
||||
if (i == V_ASN1_NEG_INTEGER)
|
||||
neg = 1;
|
||||
else if (i != V_ASN1_INTEGER)
|
||||
return -1;
|
||||
|
||||
OPENSSL_STATIC_ASSERT(sizeof(uint64_t) >= sizeof(long),
|
||||
"long larger than uint64_t");
|
||||
|
||||
if (a->length > (int)sizeof(uint64_t)) {
|
||||
/* hmm... a bit ugly, return all ones */
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint64_t r64 = 0;
|
||||
if (a->data != NULL) {
|
||||
for (i = 0; i < a->length; i++) {
|
||||
r64 <<= 8;
|
||||
r64 |= (unsigned char)a->data[i];
|
||||
}
|
||||
|
||||
if (r64 > LONG_MAX) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
long r = (long) r64;
|
||||
if (neg)
|
||||
r = -r;
|
||||
|
||||
return r;
|
||||
return asn1_string_get_long(a, V_ASN1_INTEGER);
|
||||
}
|
||||
|
||||
ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai)
|
||||
long ASN1_ENUMERATED_get(const ASN1_ENUMERATED *a)
|
||||
{
|
||||
return asn1_string_get_long(a, V_ASN1_ENUMERATED);
|
||||
}
|
||||
|
||||
static ASN1_STRING *bn_to_asn1_string(const BIGNUM *bn, ASN1_STRING *ai,
|
||||
int type)
|
||||
{
|
||||
ASN1_INTEGER *ret;
|
||||
int len, j;
|
||||
|
||||
if (ai == NULL)
|
||||
ret = ASN1_INTEGER_new();
|
||||
else
|
||||
if (ai == NULL) {
|
||||
ret = ASN1_STRING_type_new(type);
|
||||
} else {
|
||||
ret = ai;
|
||||
}
|
||||
if (ret == NULL) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_NESTED_ASN1_ERROR);
|
||||
goto err;
|
||||
}
|
||||
if (BN_is_negative(bn) && !BN_is_zero(bn))
|
||||
ret->type = V_ASN1_NEG_INTEGER;
|
||||
else
|
||||
ret->type = V_ASN1_INTEGER;
|
||||
j = BN_num_bits(bn);
|
||||
len = ((j == 0) ? 0 : ((j / 8) + 1));
|
||||
if (ret->length < len + 4) {
|
||||
unsigned char *new_data = OPENSSL_realloc(ret->data, len + 4);
|
||||
if (!new_data) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
ret->data = new_data;
|
||||
|
||||
if (BN_is_negative(bn) && !BN_is_zero(bn)) {
|
||||
ret->type = type | V_ASN1_NEG;
|
||||
} else {
|
||||
ret->type = type;
|
||||
}
|
||||
ret->length = BN_bn2bin(bn, ret->data);
|
||||
/* Correct zero case */
|
||||
if (!ret->length) {
|
||||
ret->data[0] = 0;
|
||||
ret->length = 1;
|
||||
|
||||
int len = BN_num_bytes(bn);
|
||||
if (!ASN1_STRING_set(ret, NULL, len) ||
|
||||
!BN_bn2bin_padded(ret->data, len, bn)) {
|
||||
goto err;
|
||||
}
|
||||
return (ret);
|
||||
return ret;
|
||||
|
||||
err:
|
||||
if (ret != ai)
|
||||
ASN1_INTEGER_free(ret);
|
||||
return (NULL);
|
||||
if (ret != ai) {
|
||||
ASN1_STRING_free(ret);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ASN1_INTEGER *BN_to_ASN1_INTEGER(const BIGNUM *bn, ASN1_INTEGER *ai)
|
||||
{
|
||||
return bn_to_asn1_string(bn, ai, V_ASN1_INTEGER);
|
||||
}
|
||||
|
||||
ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(const BIGNUM *bn, ASN1_ENUMERATED *ai)
|
||||
{
|
||||
return bn_to_asn1_string(bn, ai, V_ASN1_ENUMERATED);
|
||||
}
|
||||
|
||||
static BIGNUM *asn1_string_to_bn(const ASN1_STRING *ai, BIGNUM *bn, int type)
|
||||
{
|
||||
if ((ai->type & ~V_ASN1_NEG) != type) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_WRONG_INTEGER_TYPE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BIGNUM *ret;
|
||||
if ((ret = BN_bin2bn(ai->data, ai->length, bn)) == NULL)
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BN_LIB);
|
||||
else if (ai->type & V_ASN1_NEG)
|
||||
BN_set_negative(ret, 1);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
BIGNUM *ASN1_INTEGER_to_BN(const ASN1_INTEGER *ai, BIGNUM *bn)
|
||||
{
|
||||
BIGNUM *ret;
|
||||
|
||||
if ((ret = BN_bin2bn(ai->data, ai->length, bn)) == NULL)
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BN_LIB);
|
||||
else if (ai->type == V_ASN1_NEG_INTEGER)
|
||||
BN_set_negative(ret, 1);
|
||||
return (ret);
|
||||
return asn1_string_to_bn(ai, bn, V_ASN1_INTEGER);
|
||||
}
|
||||
|
||||
BIGNUM *ASN1_ENUMERATED_to_BN(const ASN1_ENUMERATED *ai, BIGNUM *bn)
|
||||
{
|
||||
return asn1_string_to_bn(ai, bn, V_ASN1_ENUMERATED);
|
||||
}
|
||||
@@ -574,7 +574,8 @@ int ASN1_GENERALIZEDTIME_print(BIO *bp, const ASN1_GENERALIZEDTIME *tm)
|
||||
// their value, updates |v| and |len|, and returns one. Otherwise, returns
|
||||
// zero.
|
||||
static int consume_two_digits(int* out, const char **v, int *len) {
|
||||
if (*len < 2|| !isdigit((*v)[0]) || !isdigit((*v)[1])) {
|
||||
if (*len < 2 || !isdigit((unsigned char)((*v)[0])) ||
|
||||
!isdigit((unsigned char)((*v)[1]))) {
|
||||
return 0;
|
||||
}
|
||||
*out = ((*v)[0] - '0') * 10 + ((*v)[1] - '0');
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <CCryptoBoringSSL_asn1_mac.h>
|
||||
#include <CCryptoBoringSSL_bytestring.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
@@ -104,101 +104,54 @@ OPENSSL_DECLARE_ERROR_REASON(ASN1, UNKNOWN_FORMAT)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, UNKNOWN_TAG)
|
||||
OPENSSL_DECLARE_ERROR_REASON(ASN1, UNSUPPORTED_TYPE)
|
||||
|
||||
static int asn1_get_length(const unsigned char **pp, long *rl, long max);
|
||||
static void asn1_put_length(unsigned char **pp, int length);
|
||||
|
||||
int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag,
|
||||
int *pclass, long omax)
|
||||
int ASN1_get_object(const unsigned char **inp, long *out_len, int *out_tag,
|
||||
int *out_class, long in_len)
|
||||
{
|
||||
int i, ret;
|
||||
long l;
|
||||
const unsigned char *p = *pp;
|
||||
int tag, xclass;
|
||||
long max = omax;
|
||||
|
||||
if (!max)
|
||||
goto err;
|
||||
ret = (*p & V_ASN1_CONSTRUCTED);
|
||||
xclass = (*p & V_ASN1_PRIVATE);
|
||||
i = *p & V_ASN1_PRIMITIVE_TAG;
|
||||
if (i == V_ASN1_PRIMITIVE_TAG) { /* high-tag */
|
||||
p++;
|
||||
if (--max == 0)
|
||||
goto err;
|
||||
l = 0;
|
||||
while (*p & 0x80) {
|
||||
l <<= 7L;
|
||||
l |= *(p++) & 0x7f;
|
||||
if (--max == 0)
|
||||
goto err;
|
||||
if (l > (INT_MAX >> 7L))
|
||||
goto err;
|
||||
}
|
||||
l <<= 7L;
|
||||
l |= *(p++) & 0x7f;
|
||||
tag = (int)l;
|
||||
if (--max == 0)
|
||||
goto err;
|
||||
} else {
|
||||
tag = i;
|
||||
p++;
|
||||
if (--max == 0)
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* To avoid ambiguity with V_ASN1_NEG, impose a limit on universal tags. */
|
||||
if (xclass == V_ASN1_UNIVERSAL && tag > V_ASN1_MAX_UNIVERSAL)
|
||||
goto err;
|
||||
|
||||
*ptag = tag;
|
||||
*pclass = xclass;
|
||||
if (!asn1_get_length(&p, plength, max))
|
||||
goto err;
|
||||
|
||||
if (*plength > (omax - (p - *pp))) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_TOO_LONG);
|
||||
if (in_len < 0) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_HEADER_TOO_LONG);
|
||||
return 0x80;
|
||||
}
|
||||
*pp = p;
|
||||
return ret;
|
||||
err:
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_HEADER_TOO_LONG);
|
||||
return 0x80;
|
||||
}
|
||||
|
||||
static int asn1_get_length(const unsigned char **pp, long *rl, long max)
|
||||
{
|
||||
const unsigned char *p = *pp;
|
||||
unsigned long ret = 0;
|
||||
unsigned long i;
|
||||
/* TODO(https://crbug.com/boringssl/354): This should use |CBS_get_asn1| to
|
||||
* reject non-minimal lengths, which are only allowed in BER. However,
|
||||
* Android sometimes needs allow a non-minimal length in certificate
|
||||
* signature fields (see b/18228011). Make this only apply to that field,
|
||||
* while requiring DER elsewhere. Better yet, it should be limited to an
|
||||
* preprocessing step in that part of Android. */
|
||||
unsigned tag;
|
||||
size_t header_len;
|
||||
int indefinite;
|
||||
CBS cbs, body;
|
||||
CBS_init(&cbs, *inp, (size_t)in_len);
|
||||
if (!CBS_get_any_ber_asn1_element(&cbs, &body, &tag, &header_len,
|
||||
/*out_ber_found=*/NULL, &indefinite) ||
|
||||
indefinite ||
|
||||
!CBS_skip(&body, header_len) ||
|
||||
/* Bound the length to comfortably fit in an int. Lengths in this
|
||||
* module often switch between int and long without overflow checks. */
|
||||
CBS_len(&body) > INT_MAX / 2) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_HEADER_TOO_LONG);
|
||||
return 0x80;
|
||||
}
|
||||
|
||||
if (max-- < 1) {
|
||||
return 0;
|
||||
/* Convert between tag representations. */
|
||||
int tag_class = (tag & CBS_ASN1_CLASS_MASK) >> CBS_ASN1_TAG_SHIFT;
|
||||
int constructed = (tag & CBS_ASN1_CONSTRUCTED) >> CBS_ASN1_TAG_SHIFT;
|
||||
int tag_number = tag & CBS_ASN1_TAG_NUMBER_MASK;
|
||||
|
||||
/* To avoid ambiguity with V_ASN1_NEG, impose a limit on universal tags. */
|
||||
if (tag_class == V_ASN1_UNIVERSAL && tag_number > V_ASN1_MAX_UNIVERSAL) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_HEADER_TOO_LONG);
|
||||
return 0x80;
|
||||
}
|
||||
if (*p == 0x80) {
|
||||
/* We do not support BER indefinite-length encoding. */
|
||||
return 0;
|
||||
}
|
||||
i = *p & 0x7f;
|
||||
if (*(p++) & 0x80) {
|
||||
if (i > sizeof(ret) || max < (long)i)
|
||||
return 0;
|
||||
while (i-- > 0) {
|
||||
ret <<= 8L;
|
||||
ret |= *(p++);
|
||||
}
|
||||
} else {
|
||||
ret = i;
|
||||
}
|
||||
/*
|
||||
* Bound the length to comfortably fit in an int. Lengths in this module
|
||||
* often switch between int and long without overflow checks.
|
||||
*/
|
||||
if (ret > INT_MAX / 2)
|
||||
return 0;
|
||||
*pp = p;
|
||||
*rl = (long)ret;
|
||||
return 1;
|
||||
|
||||
*inp = CBS_data(&body);
|
||||
*out_len = CBS_len(&body);
|
||||
*out_tag = tag_number;
|
||||
*out_class = tag_class;
|
||||
return constructed;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -223,7 +223,6 @@ const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt,
|
||||
int nullerr) {
|
||||
const ASN1_ADB *adb;
|
||||
const ASN1_ADB_TABLE *atbl;
|
||||
long selector;
|
||||
ASN1_VALUE **sfld;
|
||||
int i;
|
||||
if (!(tt->flags & ASN1_TFLG_ADB_MASK)) {
|
||||
@@ -244,14 +243,11 @@ const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt,
|
||||
return adb->null_tt;
|
||||
}
|
||||
|
||||
/* Convert type to a long:
|
||||
/* Convert type to a NID:
|
||||
* NB: don't check for NID_undef here because it
|
||||
* might be a legitimate value in the table */
|
||||
if (tt->flags & ASN1_TFLG_ADB_OID) {
|
||||
selector = OBJ_obj2nid((ASN1_OBJECT *)*sfld);
|
||||
} else {
|
||||
selector = ASN1_INTEGER_get((ASN1_INTEGER *)*sfld);
|
||||
}
|
||||
assert(tt->flags & ASN1_TFLG_ADB_OID);
|
||||
int selector = OBJ_obj2nid((ASN1_OBJECT *)*sfld);
|
||||
|
||||
/* Try to find matching entry in table Maybe should check application types
|
||||
* first to allow application override? Might also be useful to have a flag
|
||||
|
||||
@@ -69,9 +69,9 @@ static int cbs_find_ber(const CBS *orig_in, int *ber_found, unsigned depth) {
|
||||
CBS contents;
|
||||
unsigned tag;
|
||||
size_t header_len;
|
||||
|
||||
int indefinite;
|
||||
if (!CBS_get_any_ber_asn1_element(&in, &contents, &tag, &header_len,
|
||||
ber_found)) {
|
||||
ber_found, &indefinite)) {
|
||||
return 0;
|
||||
}
|
||||
if (*ber_found) {
|
||||
@@ -119,11 +119,11 @@ static int cbs_convert_ber(CBS *in, CBB *out, unsigned string_tag,
|
||||
CBS contents;
|
||||
unsigned tag, child_string_tag = string_tag;
|
||||
size_t header_len;
|
||||
int ber_found;
|
||||
int indefinite;
|
||||
CBB *out_contents, out_contents_storage;
|
||||
|
||||
if (!CBS_get_any_ber_asn1_element(in, &contents, &tag, &header_len,
|
||||
&ber_found)) {
|
||||
/*out_ber_found=*/NULL, &indefinite)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -153,11 +153,9 @@ static int cbs_convert_ber(CBS *in, CBB *out, unsigned string_tag,
|
||||
out_contents = &out_contents_storage;
|
||||
}
|
||||
|
||||
if (CBS_len(&contents) == header_len && header_len > 0 &&
|
||||
CBS_data(&contents)[header_len - 1] == 0x80) {
|
||||
// This is an indefinite length element.
|
||||
if (indefinite) {
|
||||
if (!cbs_convert_ber(in, out_contents, child_string_tag,
|
||||
1 /* looking for eoc */, depth + 1) ||
|
||||
/*looking_for_eoc=*/1, depth + 1) ||
|
||||
!CBB_flush(out)) {
|
||||
return 0;
|
||||
}
|
||||
@@ -171,7 +169,7 @@ static int cbs_convert_ber(CBS *in, CBB *out, unsigned string_tag,
|
||||
if (tag & CBS_ASN1_CONSTRUCTED) {
|
||||
// Recurse into children.
|
||||
if (!cbs_convert_ber(&contents, out_contents, child_string_tag,
|
||||
0 /* not looking for eoc */, depth + 1)) {
|
||||
/*looking_for_eoc=*/0, depth + 1)) {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -285,7 +285,7 @@ static int parse_asn1_tag(CBS *cbs, unsigned *out) {
|
||||
|
||||
static int cbs_get_any_asn1_element(CBS *cbs, CBS *out, unsigned *out_tag,
|
||||
size_t *out_header_len, int *out_ber_found,
|
||||
int ber_ok) {
|
||||
int *out_indefinite, int ber_ok) {
|
||||
CBS header = *cbs;
|
||||
CBS throwaway;
|
||||
|
||||
@@ -294,6 +294,10 @@ static int cbs_get_any_asn1_element(CBS *cbs, CBS *out, unsigned *out_tag,
|
||||
}
|
||||
if (ber_ok) {
|
||||
*out_ber_found = 0;
|
||||
*out_indefinite = 0;
|
||||
} else {
|
||||
assert(out_ber_found == NULL);
|
||||
assert(out_indefinite == NULL);
|
||||
}
|
||||
|
||||
unsigned tag;
|
||||
@@ -333,6 +337,7 @@ static int cbs_get_any_asn1_element(CBS *cbs, CBS *out, unsigned *out_tag,
|
||||
*out_header_len = header_len;
|
||||
}
|
||||
*out_ber_found = 1;
|
||||
*out_indefinite = 1;
|
||||
return CBS_get_bytes(cbs, out, header_len);
|
||||
}
|
||||
|
||||
@@ -395,16 +400,18 @@ int CBS_get_any_asn1(CBS *cbs, CBS *out, unsigned *out_tag) {
|
||||
|
||||
int CBS_get_any_asn1_element(CBS *cbs, CBS *out, unsigned *out_tag,
|
||||
size_t *out_header_len) {
|
||||
return cbs_get_any_asn1_element(cbs, out, out_tag, out_header_len,
|
||||
NULL, 0 /* DER only */);
|
||||
return cbs_get_any_asn1_element(cbs, out, out_tag, out_header_len, NULL, NULL,
|
||||
/*ber_ok=*/0);
|
||||
}
|
||||
|
||||
int CBS_get_any_ber_asn1_element(CBS *cbs, CBS *out, unsigned *out_tag,
|
||||
size_t *out_header_len, int *out_ber_found) {
|
||||
size_t *out_header_len, int *out_ber_found,
|
||||
int *out_indefinite) {
|
||||
int ber_found_temp;
|
||||
return cbs_get_any_asn1_element(
|
||||
cbs, out, out_tag, out_header_len,
|
||||
out_ber_found ? out_ber_found : &ber_found_temp, 1 /* BER allowed */);
|
||||
out_ber_found ? out_ber_found : &ber_found_temp, out_indefinite,
|
||||
/*ber_ok=*/1);
|
||||
}
|
||||
|
||||
static int cbs_get_asn1(CBS *cbs, CBS *out, unsigned tag_value,
|
||||
|
||||
@@ -67,7 +67,7 @@ Lshort:
|
||||
ldp x24,x25,[x3] // load key
|
||||
ldp x26,x27,[x3,#16]
|
||||
ldp x28,x30,[x4] // load counter
|
||||
#ifdef __ARMEB__
|
||||
#ifdef __AARCH64EB__
|
||||
ror x24,x24,#32
|
||||
ror x25,x25,#32
|
||||
ror x26,x26,#32
|
||||
@@ -228,7 +228,7 @@ Loop:
|
||||
add x20,x20,x21,lsl#32
|
||||
ldp x19,x21,[x1,#48]
|
||||
add x1,x1,#64
|
||||
#ifdef __ARMEB__
|
||||
#ifdef __AARCH64EB__
|
||||
rev x5,x5
|
||||
rev x7,x7
|
||||
rev x9,x9
|
||||
@@ -285,7 +285,7 @@ Less_than_64:
|
||||
add x15,x15,x16,lsl#32
|
||||
add x17,x17,x19,lsl#32
|
||||
add x20,x20,x21,lsl#32
|
||||
#ifdef __ARMEB__
|
||||
#ifdef __AARCH64EB__
|
||||
rev x5,x5
|
||||
rev x7,x7
|
||||
rev x9,x9
|
||||
@@ -351,7 +351,7 @@ ChaCha20_neon:
|
||||
ldp x28,x30,[x4] // load counter
|
||||
ld1 {v27.4s},[x4]
|
||||
ld1 {v31.4s},[x5]
|
||||
#ifdef __ARMEB__
|
||||
#ifdef __AARCH64EB__
|
||||
rev64 v24.4s,v24.4s
|
||||
ror x24,x24,#32
|
||||
ror x25,x25,#32
|
||||
@@ -649,7 +649,7 @@ Loop_neon:
|
||||
add x20,x20,x21,lsl#32
|
||||
ldp x19,x21,[x1,#48]
|
||||
add x1,x1,#64
|
||||
#ifdef __ARMEB__
|
||||
#ifdef __AARCH64EB__
|
||||
rev x5,x5
|
||||
rev x7,x7
|
||||
rev x9,x9
|
||||
@@ -729,7 +729,7 @@ Ltail_neon:
|
||||
add x20,x20,x21,lsl#32
|
||||
ldp x19,x21,[x1,#48]
|
||||
add x1,x1,#64
|
||||
#ifdef __ARMEB__
|
||||
#ifdef __AARCH64EB__
|
||||
rev x5,x5
|
||||
rev x7,x7
|
||||
rev x9,x9
|
||||
@@ -847,7 +847,7 @@ L512_or_more_neon:
|
||||
ldp x28,x30,[x4] // load counter
|
||||
ld1 {v27.4s},[x4]
|
||||
ld1 {v31.4s},[x5]
|
||||
#ifdef __ARMEB__
|
||||
#ifdef __AARCH64EB__
|
||||
rev64 v24.4s,v24.4s
|
||||
ror x24,x24,#32
|
||||
ror x25,x25,#32
|
||||
@@ -1360,7 +1360,7 @@ Loop_upper_neon:
|
||||
add x20,x20,x21,lsl#32
|
||||
ldp x19,x21,[x1,#48]
|
||||
add x1,x1,#64
|
||||
#ifdef __ARMEB__
|
||||
#ifdef __AARCH64EB__
|
||||
rev x5,x5
|
||||
rev x7,x7
|
||||
rev x9,x9
|
||||
@@ -1874,7 +1874,7 @@ Loop_lower_neon:
|
||||
add x1,x1,#64
|
||||
add v21.4s,v21.4s,v25.4s
|
||||
|
||||
#ifdef __ARMEB__
|
||||
#ifdef __AARCH64EB__
|
||||
rev x5,x5
|
||||
rev x7,x7
|
||||
rev x9,x9
|
||||
|
||||
@@ -68,7 +68,7 @@ ChaCha20_ctr32:
|
||||
ldp x24,x25,[x3] // load key
|
||||
ldp x26,x27,[x3,#16]
|
||||
ldp x28,x30,[x4] // load counter
|
||||
#ifdef __ARMEB__
|
||||
#ifdef __AARCH64EB__
|
||||
ror x24,x24,#32
|
||||
ror x25,x25,#32
|
||||
ror x26,x26,#32
|
||||
@@ -229,7 +229,7 @@ ChaCha20_ctr32:
|
||||
add x20,x20,x21,lsl#32
|
||||
ldp x19,x21,[x1,#48]
|
||||
add x1,x1,#64
|
||||
#ifdef __ARMEB__
|
||||
#ifdef __AARCH64EB__
|
||||
rev x5,x5
|
||||
rev x7,x7
|
||||
rev x9,x9
|
||||
@@ -286,7 +286,7 @@ ChaCha20_ctr32:
|
||||
add x15,x15,x16,lsl#32
|
||||
add x17,x17,x19,lsl#32
|
||||
add x20,x20,x21,lsl#32
|
||||
#ifdef __ARMEB__
|
||||
#ifdef __AARCH64EB__
|
||||
rev x5,x5
|
||||
rev x7,x7
|
||||
rev x9,x9
|
||||
@@ -352,7 +352,7 @@ ChaCha20_neon:
|
||||
ldp x28,x30,[x4] // load counter
|
||||
ld1 {v27.4s},[x4]
|
||||
ld1 {v31.4s},[x5]
|
||||
#ifdef __ARMEB__
|
||||
#ifdef __AARCH64EB__
|
||||
rev64 v24.4s,v24.4s
|
||||
ror x24,x24,#32
|
||||
ror x25,x25,#32
|
||||
@@ -650,7 +650,7 @@ ChaCha20_neon:
|
||||
add x20,x20,x21,lsl#32
|
||||
ldp x19,x21,[x1,#48]
|
||||
add x1,x1,#64
|
||||
#ifdef __ARMEB__
|
||||
#ifdef __AARCH64EB__
|
||||
rev x5,x5
|
||||
rev x7,x7
|
||||
rev x9,x9
|
||||
@@ -730,7 +730,7 @@ ChaCha20_neon:
|
||||
add x20,x20,x21,lsl#32
|
||||
ldp x19,x21,[x1,#48]
|
||||
add x1,x1,#64
|
||||
#ifdef __ARMEB__
|
||||
#ifdef __AARCH64EB__
|
||||
rev x5,x5
|
||||
rev x7,x7
|
||||
rev x9,x9
|
||||
@@ -848,7 +848,7 @@ ChaCha20_512_neon:
|
||||
ldp x28,x30,[x4] // load counter
|
||||
ld1 {v27.4s},[x4]
|
||||
ld1 {v31.4s},[x5]
|
||||
#ifdef __ARMEB__
|
||||
#ifdef __AARCH64EB__
|
||||
rev64 v24.4s,v24.4s
|
||||
ror x24,x24,#32
|
||||
ror x25,x25,#32
|
||||
@@ -1361,7 +1361,7 @@ ChaCha20_512_neon:
|
||||
add x20,x20,x21,lsl#32
|
||||
ldp x19,x21,[x1,#48]
|
||||
add x1,x1,#64
|
||||
#ifdef __ARMEB__
|
||||
#ifdef __AARCH64EB__
|
||||
rev x5,x5
|
||||
rev x7,x7
|
||||
rev x9,x9
|
||||
@@ -1875,7 +1875,7 @@ ChaCha20_512_neon:
|
||||
add x1,x1,#64
|
||||
add v21.4s,v21.4s,v25.4s
|
||||
|
||||
#ifdef __ARMEB__
|
||||
#ifdef __AARCH64EB__
|
||||
rev x5,x5
|
||||
rev x7,x7
|
||||
rev x9,x9
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <CCryptoBoringSSL_cpu.h>
|
||||
|
||||
#include "../internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
@@ -50,7 +50,6 @@
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <CCryptoBoringSSL_cpu.h>
|
||||
#include <CCryptoBoringSSL_cipher.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
@@ -17,11 +17,11 @@
|
||||
#include <assert.h>
|
||||
|
||||
#include <CCryptoBoringSSL_cipher.h>
|
||||
#include <CCryptoBoringSSL_cpu.h>
|
||||
#include <CCryptoBoringSSL_crypto.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
|
||||
#include "../fipsmodule/cipher/internal.h"
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
#define EVP_AEAD_AES_GCM_SIV_NONCE_LEN 12
|
||||
@@ -857,22 +857,15 @@ static const EVP_AEAD aead_aes_256_gcm_siv = {
|
||||
|
||||
#if defined(AES_GCM_SIV_ASM)
|
||||
|
||||
static char avx_aesni_capable(void) {
|
||||
const uint32_t ecx = OPENSSL_ia32cap_P[1];
|
||||
|
||||
return (ecx & (1 << (57 - 32))) != 0 /* AESNI */ &&
|
||||
(ecx & (1 << 28)) != 0 /* AVX */;
|
||||
}
|
||||
|
||||
const EVP_AEAD *EVP_aead_aes_128_gcm_siv(void) {
|
||||
if (avx_aesni_capable()) {
|
||||
if (CRYPTO_is_AVX_capable() && CRYPTO_is_AESNI_capable()) {
|
||||
return &aead_aes_128_gcm_siv_asm;
|
||||
}
|
||||
return &aead_aes_128_gcm_siv;
|
||||
}
|
||||
|
||||
const EVP_AEAD *EVP_aead_aes_256_gcm_siv(void) {
|
||||
if (avx_aesni_capable()) {
|
||||
if (CRYPTO_is_AVX_capable() && CRYPTO_is_AESNI_capable()) {
|
||||
return &aead_aes_256_gcm_siv_asm;
|
||||
}
|
||||
return &aead_aes_256_gcm_siv;
|
||||
|
||||
+99
-78
@@ -59,7 +59,6 @@
|
||||
#include <CCryptoBoringSSL_nid.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "../delocate.h"
|
||||
|
||||
|
||||
typedef struct {
|
||||
@@ -88,17 +87,21 @@ static int des_cbc_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in,
|
||||
return 1;
|
||||
}
|
||||
|
||||
DEFINE_METHOD_FUNCTION(EVP_CIPHER, EVP_des_cbc) {
|
||||
memset(out, 0, sizeof(EVP_CIPHER));
|
||||
out->nid = NID_des_cbc;
|
||||
out->block_size = 8;
|
||||
out->key_len = 8;
|
||||
out->iv_len = 8;
|
||||
out->ctx_size = sizeof(EVP_DES_KEY);
|
||||
out->flags = EVP_CIPH_CBC_MODE;
|
||||
out->init = des_init_key;
|
||||
out->cipher = des_cbc_cipher;
|
||||
}
|
||||
static const EVP_CIPHER evp_des_cbc = {
|
||||
/* nid = */ NID_des_cbc,
|
||||
/* block_size = */ 8,
|
||||
/* key_len = */ 8,
|
||||
/* iv_len = */ 8,
|
||||
/* ctx_size = */ sizeof(EVP_DES_KEY),
|
||||
/* flags = */ EVP_CIPH_CBC_MODE,
|
||||
/* app_data = */ NULL,
|
||||
/* init = */ des_init_key,
|
||||
/* cipher = */ des_cbc_cipher,
|
||||
/* cleanup = */ NULL,
|
||||
/* ctrl = */ NULL,
|
||||
};
|
||||
|
||||
const EVP_CIPHER *EVP_des_cbc(void) { return &evp_des_cbc; }
|
||||
|
||||
static int des_ecb_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in,
|
||||
size_t in_len) {
|
||||
@@ -107,25 +110,29 @@ static int des_ecb_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in,
|
||||
}
|
||||
in_len -= ctx->cipher->block_size;
|
||||
|
||||
EVP_DES_KEY *dat = (EVP_DES_KEY *) ctx->cipher_data;
|
||||
EVP_DES_KEY *dat = (EVP_DES_KEY *)ctx->cipher_data;
|
||||
for (size_t i = 0; i <= in_len; i += ctx->cipher->block_size) {
|
||||
DES_ecb_encrypt((DES_cblock *) (in + i), (DES_cblock *) (out + i),
|
||||
DES_ecb_encrypt((DES_cblock *)(in + i), (DES_cblock *)(out + i),
|
||||
&dat->ks.ks, ctx->encrypt);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
DEFINE_METHOD_FUNCTION(EVP_CIPHER, EVP_des_ecb) {
|
||||
memset(out, 0, sizeof(EVP_CIPHER));
|
||||
out->nid = NID_des_ecb;
|
||||
out->block_size = 8;
|
||||
out->key_len = 8;
|
||||
out->iv_len = 0;
|
||||
out->ctx_size = sizeof(EVP_DES_KEY);
|
||||
out->flags = EVP_CIPH_ECB_MODE;
|
||||
out->init = des_init_key;
|
||||
out->cipher = des_ecb_cipher;
|
||||
}
|
||||
static const EVP_CIPHER evp_des_ecb = {
|
||||
/* nid = */ NID_des_ecb,
|
||||
/* block_size = */ 8,
|
||||
/* key_len = */ 8,
|
||||
/* iv_len = */ 0,
|
||||
/* ctx_size = */ sizeof(EVP_DES_KEY),
|
||||
/* flags = */ EVP_CIPH_ECB_MODE,
|
||||
/* app_data = */ NULL,
|
||||
/* init = */ des_init_key,
|
||||
/* cipher = */ des_ecb_cipher,
|
||||
/* cleanup = */ NULL,
|
||||
/* ctrl = */ NULL,
|
||||
};
|
||||
|
||||
const EVP_CIPHER *EVP_des_ecb(void) { return &evp_des_ecb; }
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
@@ -137,7 +144,7 @@ typedef struct {
|
||||
static int des_ede3_init_key(EVP_CIPHER_CTX *ctx, const uint8_t *key,
|
||||
const uint8_t *iv, int enc) {
|
||||
DES_cblock *deskey = (DES_cblock *)key;
|
||||
DES_EDE_KEY *dat = (DES_EDE_KEY*) ctx->cipher_data;
|
||||
DES_EDE_KEY *dat = (DES_EDE_KEY *)ctx->cipher_data;
|
||||
|
||||
DES_set_key(&deskey[0], &dat->ks.ks[0]);
|
||||
DES_set_key(&deskey[1], &dat->ks.ks[1]);
|
||||
@@ -147,8 +154,8 @@ static int des_ede3_init_key(EVP_CIPHER_CTX *ctx, const uint8_t *key,
|
||||
}
|
||||
|
||||
static int des_ede3_cbc_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out,
|
||||
const uint8_t *in, size_t in_len) {
|
||||
DES_EDE_KEY *dat = (DES_EDE_KEY*) ctx->cipher_data;
|
||||
const uint8_t *in, size_t in_len) {
|
||||
DES_EDE_KEY *dat = (DES_EDE_KEY *)ctx->cipher_data;
|
||||
|
||||
DES_ede3_cbc_encrypt(in, out, in_len, &dat->ks.ks[0], &dat->ks.ks[1],
|
||||
&dat->ks.ks[2], (DES_cblock *)ctx->iv, ctx->encrypt);
|
||||
@@ -156,22 +163,26 @@ static int des_ede3_cbc_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out,
|
||||
return 1;
|
||||
}
|
||||
|
||||
DEFINE_METHOD_FUNCTION(EVP_CIPHER, EVP_des_ede3_cbc) {
|
||||
memset(out, 0, sizeof(EVP_CIPHER));
|
||||
out->nid = NID_des_ede3_cbc;
|
||||
out->block_size = 8;
|
||||
out->key_len = 24;
|
||||
out->iv_len = 8;
|
||||
out->ctx_size = sizeof(DES_EDE_KEY);
|
||||
out->flags = EVP_CIPH_CBC_MODE;
|
||||
out->init = des_ede3_init_key;
|
||||
out->cipher = des_ede3_cbc_cipher;
|
||||
}
|
||||
static const EVP_CIPHER evp_des_ede3_cbc = {
|
||||
/* nid = */ NID_des_ede3_cbc,
|
||||
/* block_size = */ 8,
|
||||
/* key_len = */ 24,
|
||||
/* iv_len = */ 8,
|
||||
/* ctx_size = */ sizeof(DES_EDE_KEY),
|
||||
/* flags = */ EVP_CIPH_CBC_MODE,
|
||||
/* app_data = */ NULL,
|
||||
/* init = */ des_ede3_init_key,
|
||||
/* cipher = */ des_ede3_cbc_cipher,
|
||||
/* cleanup = */ NULL,
|
||||
/* ctrl = */ NULL,
|
||||
};
|
||||
|
||||
const EVP_CIPHER *EVP_des_ede3_cbc(void) { return &evp_des_ede3_cbc; }
|
||||
|
||||
static int des_ede_init_key(EVP_CIPHER_CTX *ctx, const uint8_t *key,
|
||||
const uint8_t *iv, int enc) {
|
||||
DES_cblock *deskey = (DES_cblock *) key;
|
||||
DES_EDE_KEY *dat = (DES_EDE_KEY *) ctx->cipher_data;
|
||||
const uint8_t *iv, int enc) {
|
||||
DES_cblock *deskey = (DES_cblock *)key;
|
||||
DES_EDE_KEY *dat = (DES_EDE_KEY *)ctx->cipher_data;
|
||||
|
||||
DES_set_key(&deskey[0], &dat->ks.ks[0]);
|
||||
DES_set_key(&deskey[1], &dat->ks.ks[1]);
|
||||
@@ -180,17 +191,21 @@ static int des_ede_init_key(EVP_CIPHER_CTX *ctx, const uint8_t *key,
|
||||
return 1;
|
||||
}
|
||||
|
||||
DEFINE_METHOD_FUNCTION(EVP_CIPHER, EVP_des_ede_cbc) {
|
||||
memset(out, 0, sizeof(EVP_CIPHER));
|
||||
out->nid = NID_des_ede_cbc;
|
||||
out->block_size = 8;
|
||||
out->key_len = 16;
|
||||
out->iv_len = 8;
|
||||
out->ctx_size = sizeof(DES_EDE_KEY);
|
||||
out->flags = EVP_CIPH_CBC_MODE;
|
||||
out->init = des_ede_init_key;
|
||||
out->cipher = des_ede3_cbc_cipher;
|
||||
}
|
||||
static const EVP_CIPHER evp_des_ede_cbc = {
|
||||
/* nid = */ NID_des_ede_cbc,
|
||||
/* block_size = */ 8,
|
||||
/* key_len = */ 16,
|
||||
/* iv_len = */ 8,
|
||||
/* ctx_size = */ sizeof(DES_EDE_KEY),
|
||||
/* flags = */ EVP_CIPH_CBC_MODE,
|
||||
/* app_data = */ NULL,
|
||||
/* init = */ des_ede_init_key,
|
||||
/* cipher = */ des_ede3_cbc_cipher,
|
||||
/* cleanup = */ NULL,
|
||||
/* ctrl = */ NULL,
|
||||
};
|
||||
|
||||
const EVP_CIPHER *EVP_des_ede_cbc(void) { return &evp_des_ede_cbc; }
|
||||
|
||||
static int des_ede_ecb_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out,
|
||||
const uint8_t *in, size_t in_len) {
|
||||
@@ -208,30 +223,36 @@ static int des_ede_ecb_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out,
|
||||
return 1;
|
||||
}
|
||||
|
||||
DEFINE_METHOD_FUNCTION(EVP_CIPHER, EVP_des_ede) {
|
||||
memset(out, 0, sizeof(EVP_CIPHER));
|
||||
out->nid = NID_des_ede_ecb;
|
||||
out->block_size = 8;
|
||||
out->key_len = 16;
|
||||
out->iv_len = 0;
|
||||
out->ctx_size = sizeof(DES_EDE_KEY);
|
||||
out->flags = EVP_CIPH_ECB_MODE;
|
||||
out->init = des_ede_init_key;
|
||||
out->cipher = des_ede_ecb_cipher;
|
||||
}
|
||||
static const EVP_CIPHER evp_des_ede = {
|
||||
/* nid = */ NID_des_ede_ecb,
|
||||
/* block_size = */ 8,
|
||||
/* key_len = */ 16,
|
||||
/* iv_len = */ 0,
|
||||
/* ctx_size = */ sizeof(DES_EDE_KEY),
|
||||
/* flags = */ EVP_CIPH_ECB_MODE,
|
||||
/* app_data = */ NULL,
|
||||
/* init = */ des_ede_init_key,
|
||||
/* cipher = */ des_ede_ecb_cipher,
|
||||
/* cleanup = */ NULL,
|
||||
/* ctrl = */ NULL,
|
||||
};
|
||||
|
||||
DEFINE_METHOD_FUNCTION(EVP_CIPHER, EVP_des_ede3) {
|
||||
memset(out, 0, sizeof(EVP_CIPHER));
|
||||
out->nid = NID_des_ede3_ecb;
|
||||
out->block_size = 8;
|
||||
out->key_len = 24;
|
||||
out->iv_len = 0;
|
||||
out->ctx_size = sizeof(DES_EDE_KEY);
|
||||
out->flags = EVP_CIPH_ECB_MODE;
|
||||
out->init = des_ede3_init_key;
|
||||
out->cipher = des_ede_ecb_cipher;
|
||||
}
|
||||
const EVP_CIPHER *EVP_des_ede(void) { return &evp_des_ede; }
|
||||
|
||||
const EVP_CIPHER* EVP_des_ede3_ecb(void) {
|
||||
return EVP_des_ede3();
|
||||
}
|
||||
static const EVP_CIPHER evp_des_ede3 = {
|
||||
/* nid = */ NID_des_ede3_ecb,
|
||||
/* block_size = */ 8,
|
||||
/* key_len = */ 24,
|
||||
/* iv_len = */ 0,
|
||||
/* ctx_size = */ sizeof(DES_EDE_KEY),
|
||||
/* flags = */ EVP_CIPH_ECB_MODE,
|
||||
/* app_data = */ NULL,
|
||||
/* init = */ des_ede3_init_key,
|
||||
/* cipher = */ des_ede_ecb_cipher,
|
||||
/* cleanup = */ NULL,
|
||||
/* ctrl = */ NULL,
|
||||
};
|
||||
|
||||
const EVP_CIPHER *EVP_des_ede3(void) { return &evp_des_ede3; }
|
||||
|
||||
const EVP_CIPHER *EVP_des_ede3_ecb(void) { return EVP_des_ede3(); }
|
||||
@@ -60,7 +60,6 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <CCryptoBoringSSL_base.h>
|
||||
#include <CCryptoBoringSSL_cpu.h>
|
||||
#include <CCryptoBoringSSL_type_check.h>
|
||||
|
||||
#include "../internal.h"
|
||||
@@ -172,8 +171,7 @@ OPENSSL_STATIC_ASSERT(sizeof(union chacha20_poly1305_seal_data) == 48 + 8 + 8,
|
||||
"wrong chacha20_poly1305_seal_data size");
|
||||
|
||||
OPENSSL_INLINE int chacha20_poly1305_asm_capable(void) {
|
||||
const int sse41_capable = (OPENSSL_ia32cap_P[1] & (1 << 19)) != 0;
|
||||
return sse41_capable;
|
||||
return CRYPTO_is_SSE4_1_capable();
|
||||
}
|
||||
|
||||
// chacha20_poly1305_open is defined in chacha20_poly1305_x86_64.pl. It decrypts
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
#include <CCryptoBoringSSL_cpu.h>
|
||||
#include "internal.h"
|
||||
|
||||
#if defined(OPENSSL_AARCH64) && defined(OPENSSL_APPLE) && \
|
||||
!defined(OPENSSL_STATIC_ARMCAP)
|
||||
@@ -22,8 +22,6 @@
|
||||
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
extern uint32_t OPENSSL_armcap_P;
|
||||
|
||||
@@ -53,7 +51,8 @@ void OPENSSL_cpuid_setup(void) {
|
||||
// Apple ARM64 platforms have NEON and cryptography extensions available
|
||||
// statically, so we do not need to query them. In particular, there sometimes
|
||||
// are no sysctls corresponding to such features. See below.
|
||||
#if !defined(__ARM_NEON) || !defined(__ARM_FEATURE_CRYPTO)
|
||||
#if !defined(__ARM_NEON) || !defined(__ARM_FEATURE_AES) || \
|
||||
!defined(__ARM_FEATURE_SHA2)
|
||||
#error "NEON and crypto extensions should be statically available."
|
||||
#endif
|
||||
OPENSSL_armcap_P =
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
#include <CCryptoBoringSSL_cpu.h>
|
||||
#include "internal.h"
|
||||
|
||||
#if defined(OPENSSL_AARCH64) && defined(OPENSSL_FUCHSIA) && \
|
||||
!defined(OPENSSL_STATIC_ARMCAP)
|
||||
@@ -23,16 +23,14 @@
|
||||
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
extern uint32_t OPENSSL_armcap_P;
|
||||
|
||||
void OPENSSL_cpuid_setup(void) {
|
||||
uint32_t hwcap;
|
||||
zx_status_t rc = zx_system_get_features(ZX_FEATURE_KIND_CPU, &hwcap);
|
||||
if (rc != ZX_OK || (hwcap & ZX_ARM64_FEATURE_ISA_ASIMD) == 0) {
|
||||
// Matching OpenSSL, if NEON/ASIMD is missing, don't report other features
|
||||
// either.
|
||||
// If NEON/ASIMD is missing, don't report other features either. This
|
||||
// matches OpenSSL, and the other features depend on SIMD registers.
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -47,12 +45,12 @@ void OPENSSL_cpuid_setup(void) {
|
||||
if (hwcap & ZX_ARM64_FEATURE_ISA_SHA1) {
|
||||
OPENSSL_armcap_P |= ARMV8_SHA1;
|
||||
}
|
||||
if (hwcap & ZX_ARM64_FEATURE_ISA_SHA2) {
|
||||
if (hwcap & ZX_ARM64_FEATURE_ISA_SHA256) {
|
||||
OPENSSL_armcap_P |= ARMV8_SHA256;
|
||||
}
|
||||
// As of writing, Fuchsia does not have a flag for ARMv8.2 SHA-512
|
||||
// extensions. When it does, add it here. See
|
||||
// https://bugs.fuchsia.dev/p/fuchsia/issues/detail?id=90759.
|
||||
if (hwcap & ZX_ARM64_FEATURE_ISA_SHA512) {
|
||||
OPENSSL_armcap_P |= ARMV8_SHA512;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // OPENSSL_AARCH64 && OPENSSL_FUCHSIA && !OPENSSL_STATIC_ARMCAP
|
||||
@@ -12,7 +12,7 @@
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
#include <CCryptoBoringSSL_cpu.h>
|
||||
#include "internal.h"
|
||||
|
||||
#if defined(OPENSSL_AARCH64) && defined(OPENSSL_LINUX) && \
|
||||
!defined(OPENSSL_STATIC_ARMCAP)
|
||||
@@ -21,8 +21,6 @@
|
||||
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
|
||||
extern uint32_t OPENSSL_armcap_P;
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
#include <CCryptoBoringSSL_cpu.h>
|
||||
#include "internal.h"
|
||||
|
||||
#if defined(OPENSSL_AARCH64) && defined(OPENSSL_WINDOWS) && \
|
||||
!defined(OPENSSL_STATIC_ARMCAP)
|
||||
@@ -22,8 +22,6 @@
|
||||
|
||||
#include <CCryptoBoringSSL_arm_arch.h>
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
extern uint32_t OPENSSL_armcap_P;
|
||||
void OPENSSL_cpuid_setup(void) {
|
||||
// We do not need to check for the presence of NEON, as Armv8-A always has it
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
#include <CCryptoBoringSSL_cpu.h>
|
||||
#include "internal.h"
|
||||
|
||||
#if (defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)) && \
|
||||
!defined(OPENSSL_STATIC_ARMCAP)
|
||||
|
||||
@@ -12,9 +12,10 @@
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
#include <CCryptoBoringSSL_cpu.h>
|
||||
#include "internal.h"
|
||||
|
||||
#if defined(OPENSSL_ARM) && !defined(OPENSSL_STATIC_ARMCAP)
|
||||
#if defined(OPENSSL_ARM) && defined(OPENSSL_LINUX) && \
|
||||
!defined(OPENSSL_STATIC_ARMCAP)
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
@@ -226,4 +227,4 @@ int CRYPTO_has_broken_NEON(void) { return g_has_broken_neon; }
|
||||
|
||||
int CRYPTO_needs_hwcap2_workaround(void) { return g_needs_hwcap2_workaround; }
|
||||
|
||||
#endif // OPENSSL_ARM && !OPENSSL_STATIC_ARMCAP
|
||||
#endif // OPENSSL_ARM && OPENSSL_LINUX && !OPENSSL_STATIC_ARMCAP
|
||||
@@ -54,8 +54,7 @@
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.] */
|
||||
|
||||
#include <CCryptoBoringSSL_cpu.h>
|
||||
|
||||
#include <CCryptoBoringSSL_base.h>
|
||||
|
||||
#if !defined(OPENSSL_NO_ASM) && (defined(OPENSSL_X86) || defined(OPENSSL_X86_64))
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
#include <CCryptoBoringSSL_cpu.h>
|
||||
#include <CCryptoBoringSSL_base.h>
|
||||
|
||||
#if defined(OPENSSL_PPC64LE)
|
||||
|
||||
|
||||
@@ -14,8 +14,6 @@
|
||||
|
||||
#include <CCryptoBoringSSL_crypto.h>
|
||||
|
||||
#include <CCryptoBoringSSL_cpu.h>
|
||||
|
||||
#include "fipsmodule/rand/fork_detect.h"
|
||||
#include "fipsmodule/rand/internal.h"
|
||||
#include "internal.h"
|
||||
@@ -88,23 +86,29 @@ HIDDEN unsigned long OPENSSL_ppc64le_hwcap2 = 0;
|
||||
|
||||
#if defined(OPENSSL_STATIC_ARMCAP)
|
||||
|
||||
// See ARM ACLE for the definitions of these macros. Note |__ARM_FEATURE_AES|
|
||||
// covers both AES and PMULL and |__ARM_FEATURE_SHA2| covers SHA-1 and SHA-256.
|
||||
// https://developer.arm.com/architectures/system-architectures/software-standards/acle
|
||||
// https://github.com/ARM-software/acle/issues/152
|
||||
//
|
||||
// TODO(davidben): Do we still need |OPENSSL_STATIC_ARMCAP_*| or are the
|
||||
// standard flags and -march sufficient?
|
||||
HIDDEN uint32_t OPENSSL_armcap_P =
|
||||
#if defined(OPENSSL_STATIC_ARMCAP_NEON) || \
|
||||
(defined(__ARM_NEON__) || defined(__ARM_NEON))
|
||||
#if defined(OPENSSL_STATIC_ARMCAP_NEON) || defined(__ARM_NEON)
|
||||
ARMV7_NEON |
|
||||
#endif
|
||||
#if defined(OPENSSL_STATIC_ARMCAP_AES) || defined(__ARM_FEATURE_CRYPTO)
|
||||
#if defined(OPENSSL_STATIC_ARMCAP_AES) || defined(__ARM_FEATURE_AES)
|
||||
ARMV8_AES |
|
||||
#endif
|
||||
#if defined(OPENSSL_STATIC_ARMCAP_SHA1) || defined(__ARM_FEATURE_CRYPTO)
|
||||
#if defined(OPENSSL_STATIC_ARMCAP_PMULL) || defined(__ARM_FEATURE_AES)
|
||||
ARMV8_PMULL |
|
||||
#endif
|
||||
#if defined(OPENSSL_STATIC_ARMCAP_SHA1) || defined(__ARM_FEATURE_SHA2)
|
||||
ARMV8_SHA1 |
|
||||
#endif
|
||||
#if defined(OPENSSL_STATIC_ARMCAP_SHA256) || defined(__ARM_FEATURE_CRYPTO)
|
||||
#if defined(OPENSSL_STATIC_ARMCAP_SHA256) || defined(__ARM_FEATURE_SHA2)
|
||||
ARMV8_SHA256 |
|
||||
#endif
|
||||
#if defined(OPENSSL_STATIC_ARMCAP_PMULL) || defined(__ARM_FEATURE_CRYPTO)
|
||||
ARMV8_PMULL |
|
||||
#endif
|
||||
#if defined(__ARM_FEATURE_SHA512)
|
||||
ARMV8_SHA512 |
|
||||
#endif
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <CCryptoBoringSSL_cpu.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_rand.h>
|
||||
#include <CCryptoBoringSSL_sha.h>
|
||||
@@ -503,27 +502,21 @@ static void ge_p3_tobytes(uint8_t s[32], const ge_p3 *h) {
|
||||
int x25519_ge_frombytes_vartime(ge_p3 *h, const uint8_t s[32]) {
|
||||
fe u;
|
||||
fe_loose v;
|
||||
fe v3;
|
||||
fe w;
|
||||
fe vxx;
|
||||
fe_loose check;
|
||||
|
||||
fe_frombytes(&h->Y, s);
|
||||
fe_1(&h->Z);
|
||||
fe_sq_tt(&v3, &h->Y);
|
||||
fe_mul_ttt(&vxx, &v3, &d);
|
||||
fe_sub(&v, &v3, &h->Z); // u = y^2-1
|
||||
fe_sq_tt(&w, &h->Y);
|
||||
fe_mul_ttt(&vxx, &w, &d);
|
||||
fe_sub(&v, &w, &h->Z); // u = y^2-1
|
||||
fe_carry(&u, &v);
|
||||
fe_add(&v, &vxx, &h->Z); // v = dy^2+1
|
||||
|
||||
fe_sq_tl(&v3, &v);
|
||||
fe_mul_ttl(&v3, &v3, &v); // v3 = v^3
|
||||
fe_sq_tt(&h->X, &v3);
|
||||
fe_mul_ttl(&h->X, &h->X, &v);
|
||||
fe_mul_ttt(&h->X, &h->X, &u); // x = uv^7
|
||||
|
||||
fe_pow22523(&h->X, &h->X); // x = (uv^7)^((q-5)/8)
|
||||
fe_mul_ttt(&h->X, &h->X, &v3);
|
||||
fe_mul_ttt(&h->X, &h->X, &u); // x = uv^3(uv^7)^((q-5)/8)
|
||||
fe_mul_ttl(&w, &u, &v); // w = u*v
|
||||
fe_pow22523(&h->X, &w); // x = w^((q-5)/8)
|
||||
fe_mul_ttt(&h->X, &h->X, &u); // x = u*w^((q-5)/8)
|
||||
|
||||
fe_sq_tt(&vxx, &h->X);
|
||||
fe_mul_ttl(&vxx, &vxx, &v);
|
||||
|
||||
File renamed without changes.
+1
-1
@@ -59,7 +59,7 @@
|
||||
|
||||
#include <CCryptoBoringSSL_base.h>
|
||||
|
||||
#include "../../internal.h"
|
||||
#include "../internal.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
File diff suppressed because it is too large.
Load diff
@@ -50,8 +50,6 @@
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <CCryptoBoringSSL_cpu.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "../modes/internal.h"
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <CCryptoBoringSSL_cpu.h>
|
||||
#include "../../internal.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
@@ -30,18 +30,14 @@ extern "C" {
|
||||
#define HWAES
|
||||
#define HWAES_ECB
|
||||
|
||||
OPENSSL_INLINE int hwaes_capable(void) {
|
||||
return (OPENSSL_ia32cap_get()[1] & (1 << (57 - 32))) != 0;
|
||||
}
|
||||
OPENSSL_INLINE int hwaes_capable(void) { return CRYPTO_is_AESNI_capable(); }
|
||||
|
||||
#define VPAES
|
||||
#if defined(OPENSSL_X86_64)
|
||||
#define VPAES_CTR32
|
||||
#endif
|
||||
#define VPAES_CBC
|
||||
OPENSSL_INLINE int vpaes_capable(void) {
|
||||
return (OPENSSL_ia32cap_get()[1] & (1 << (41 - 32))) != 0;
|
||||
}
|
||||
OPENSSL_INLINE int vpaes_capable(void) { return CRYPTO_is_SSSE3_capable(); }
|
||||
|
||||
#elif defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)
|
||||
#define HWAES
|
||||
|
||||
@@ -636,7 +636,7 @@ _aes_hw_ctr32_encrypt_blocks:
|
||||
//
|
||||
// [0] ARM-EPM-049219 v23 Cortex-A57 MPCore Software Developers Errata Notice
|
||||
// [1] ARM-EPM-012079 v11.0 Cortex-A72 MPCore Software Developers Errata Notice
|
||||
#ifndef __ARMEB__
|
||||
#ifndef __AARCH64EB__
|
||||
rev w8, w8
|
||||
#endif
|
||||
add w10, w8, #1
|
||||
|
||||
@@ -637,7 +637,7 @@ aes_hw_ctr32_encrypt_blocks:
|
||||
//
|
||||
// [0] ARM-EPM-049219 v23 Cortex-A57 MPCore Software Developers Errata Notice
|
||||
// [1] ARM-EPM-012079 v11.0 Cortex-A72 MPCore Software Developers Errata Notice
|
||||
#ifndef __ARMEB__
|
||||
#ifndef __AARCH64EB__
|
||||
rev w8, w8
|
||||
#endif
|
||||
add w10, w8, #1
|
||||
|
||||
@@ -112,7 +112,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <CCryptoBoringSSL_cpu.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
#define OPENSSL_HEADER_BN_RSAZ_EXP_H
|
||||
|
||||
#include <CCryptoBoringSSL_bn.h>
|
||||
#include <CCryptoBoringSSL_cpu.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "../../internal.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
@@ -41,18 +41,17 @@ void RSAZ_1024_mod_exp_avx2(BN_ULONG result[16], const BN_ULONG base_norm[16],
|
||||
BN_ULONG storage_words[MOD_EXP_CTIME_STORAGE_LEN]);
|
||||
|
||||
OPENSSL_INLINE int rsaz_avx2_capable(void) {
|
||||
const uint32_t *cap = OPENSSL_ia32cap_get();
|
||||
return (cap[2] & (1 << 5)) != 0; // AVX2
|
||||
return CRYPTO_is_AVX2_capable();
|
||||
}
|
||||
|
||||
OPENSSL_INLINE int rsaz_avx2_preferred(void) {
|
||||
const uint32_t *cap = OPENSSL_ia32cap_get();
|
||||
static const uint32_t kBMI2AndADX = (1 << 8) | (1 << 19);
|
||||
if ((cap[2] & kBMI2AndADX) == kBMI2AndADX) {
|
||||
// If BMI2 and ADX are available, x86_64-mont5.pl is faster.
|
||||
if (CRYPTO_is_BMI1_capable() && CRYPTO_is_BMI2_capable() &&
|
||||
CRYPTO_is_ADX_capable()) {
|
||||
// If BMI1, BMI2, and ADX are available, x86_64-mont5.pl is faster. See the
|
||||
// .Lmulx4x_enter and .Lpowerx5_enter branches.
|
||||
return 0;
|
||||
}
|
||||
return (cap[2] & (1 << 5)) != 0; // AVX2
|
||||
return CRYPTO_is_AVX2_capable();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -306,8 +306,7 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) {
|
||||
}
|
||||
|
||||
// x := a^((q-1)/2)
|
||||
if (BN_is_zero(t)) // special case: p = 2^e + 1
|
||||
{
|
||||
if (BN_is_zero(t)) { // special case: p = 2^e + 1
|
||||
if (!BN_nnmod(t, A, p, ctx)) {
|
||||
goto end;
|
||||
}
|
||||
@@ -350,7 +349,6 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) {
|
||||
// We have a*b = x^2,
|
||||
// y^2^(e-1) = -1,
|
||||
// b^2^(e-1) = 1.
|
||||
|
||||
if (BN_is_one(b)) {
|
||||
if (!BN_copy(ret, x)) {
|
||||
goto end;
|
||||
@@ -359,23 +357,26 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) {
|
||||
goto vrfy;
|
||||
}
|
||||
|
||||
|
||||
// find smallest i such that b^(2^i) = 1
|
||||
i = 1;
|
||||
if (!BN_mod_sqr(t, b, p, ctx)) {
|
||||
// Find the smallest i, 0 < i < e, such that b^(2^i) = 1
|
||||
for (i = 1; i < e; i++) {
|
||||
if (i == 1) {
|
||||
if (!BN_mod_sqr(t, b, p, ctx)) {
|
||||
goto end;
|
||||
}
|
||||
} else {
|
||||
if (!BN_mod_mul(t, t, t, p, ctx)) {
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
if (BN_is_one(t)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// If not found, a is not a square or p is not a prime.
|
||||
if (i >= e) {
|
||||
OPENSSL_PUT_ERROR(BN, BN_R_NOT_A_SQUARE);
|
||||
goto end;
|
||||
}
|
||||
while (!BN_is_one(t)) {
|
||||
i++;
|
||||
if (i == e) {
|
||||
OPENSSL_PUT_ERROR(BN, BN_R_NOT_A_SQUARE);
|
||||
goto end;
|
||||
}
|
||||
if (!BN_mod_mul(t, t, t, p, ctx)) {
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// t := y^2^(e - i - 1)
|
||||
if (!BN_copy(t, y)) {
|
||||
@@ -391,14 +392,15 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) {
|
||||
!BN_mod_mul(b, b, y, p, ctx)) {
|
||||
goto end;
|
||||
}
|
||||
|
||||
// e decreases each iteration, so this loop will terminate.
|
||||
assert(i < e);
|
||||
e = i;
|
||||
}
|
||||
|
||||
vrfy:
|
||||
if (!err) {
|
||||
// verify the result -- the input might have been not a square
|
||||
// (test added in 0.9.8)
|
||||
|
||||
// Verify the result. The input might have been not a square.
|
||||
if (!BN_mod_sqr(x, ret, p, ctx)) {
|
||||
err = 1;
|
||||
}
|
||||
|
||||
@@ -51,6 +51,9 @@ EVP_AEAD_CTX *EVP_AEAD_CTX_new(const EVP_AEAD *aead, const uint8_t *key,
|
||||
}
|
||||
|
||||
void EVP_AEAD_CTX_free(EVP_AEAD_CTX *ctx) {
|
||||
if (ctx == NULL) {
|
||||
return;
|
||||
}
|
||||
EVP_AEAD_CTX_cleanup(ctx);
|
||||
OPENSSL_free(ctx);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,6 @@
|
||||
#include <CCryptoBoringSSL_aead.h>
|
||||
#include <CCryptoBoringSSL_aes.h>
|
||||
#include <CCryptoBoringSSL_cipher.h>
|
||||
#include <CCryptoBoringSSL_cpu.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_nid.h>
|
||||
|
||||
@@ -64,6 +64,7 @@
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_thread.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "../../internal.h"
|
||||
#include "../bn/internal.h"
|
||||
|
||||
@@ -186,6 +187,8 @@ int DH_set_length(DH *dh, unsigned priv_length) {
|
||||
}
|
||||
|
||||
int DH_generate_key(DH *dh) {
|
||||
boringssl_ensure_ffdh_self_test();
|
||||
|
||||
int ok = 0;
|
||||
int generate_new_key = 0;
|
||||
BN_CTX *ctx = NULL;
|
||||
@@ -322,7 +325,8 @@ static int dh_compute_key(DH *dh, BIGNUM *out_shared_key,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int DH_compute_key_padded(unsigned char *out, const BIGNUM *peers_key, DH *dh) {
|
||||
int dh_compute_key_padded_no_self_test(unsigned char *out,
|
||||
const BIGNUM *peers_key, DH *dh) {
|
||||
BN_CTX *ctx = BN_CTX_new();
|
||||
if (ctx == NULL) {
|
||||
return -1;
|
||||
@@ -343,7 +347,15 @@ int DH_compute_key_padded(unsigned char *out, const BIGNUM *peers_key, DH *dh) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
int DH_compute_key_padded(unsigned char *out, const BIGNUM *peers_key, DH *dh) {
|
||||
boringssl_ensure_ffdh_self_test();
|
||||
|
||||
return dh_compute_key_padded_no_self_test(out, peers_key, dh);
|
||||
}
|
||||
|
||||
int DH_compute_key(unsigned char *out, const BIGNUM *peers_key, DH *dh) {
|
||||
boringssl_ensure_ffdh_self_test();
|
||||
|
||||
BN_CTX *ctx = BN_CTX_new();
|
||||
if (ctx == NULL) {
|
||||
return -1;
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/* Copyright (c) 2022, Google Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
#ifndef OPENSSL_HEADER_CRYPTO_FIPSMODULE_DH_INTERNAL_H
|
||||
#define OPENSSL_HEADER_CRYPTO_FIPSMODULE_DH_INTERNAL_H
|
||||
|
||||
#include <CCryptoBoringSSL_base.h>
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
// 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.
|
||||
int dh_compute_key_padded_no_self_test(unsigned char *out,
|
||||
const BIGNUM *peers_key, DH *dh);
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // OPENSSL_HEADER_CRYPTO_FIPSMODULE_DH_INTERNAL_H
|
||||
@@ -106,6 +106,11 @@ int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
void EVP_MD_CTX_cleanse(EVP_MD_CTX *ctx) {
|
||||
OPENSSL_cleanse(ctx->md_data, ctx->digest->ctx_size);
|
||||
EVP_MD_CTX_cleanup(ctx);
|
||||
}
|
||||
|
||||
void EVP_MD_CTX_free(EVP_MD_CTX *ctx) {
|
||||
if (!ctx) {
|
||||
return;
|
||||
|
||||
@@ -943,8 +943,9 @@ static int arbitrary_bignum_to_scalar(const EC_GROUP *group, EC_SCALAR *out,
|
||||
return ok;
|
||||
}
|
||||
|
||||
int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar,
|
||||
const EC_POINT *p, const BIGNUM *p_scalar, BN_CTX *ctx) {
|
||||
int ec_point_mul_no_self_test(const EC_GROUP *group, EC_POINT *r,
|
||||
const BIGNUM *g_scalar, const EC_POINT *p,
|
||||
const BIGNUM *p_scalar, BN_CTX *ctx) {
|
||||
// Previously, this function set |r| to the point at infinity if there was
|
||||
// nothing to multiply. But, nobody should be calling this function with
|
||||
// nothing to multiply in the first place.
|
||||
@@ -1010,6 +1011,13 @@ err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar,
|
||||
const EC_POINT *p, const BIGNUM *p_scalar, BN_CTX *ctx) {
|
||||
boringssl_ensure_ecc_self_test();
|
||||
|
||||
return ec_point_mul_no_self_test(group, r, g_scalar, p, p_scalar, ctx);
|
||||
}
|
||||
|
||||
int ec_point_mul_scalar_public(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
const EC_SCALAR *g_scalar, const EC_RAW_POINT *p,
|
||||
const EC_SCALAR *p_scalar) {
|
||||
|
||||
@@ -308,6 +308,9 @@ int EC_KEY_check_key(const EC_KEY *eckey) {
|
||||
}
|
||||
|
||||
// Check the public and private keys match.
|
||||
//
|
||||
// NOTE: this is a FIPS pair-wise consistency check for the ECDH case. See SP
|
||||
// 800-56Ar3, page 36.
|
||||
if (eckey->priv_key != NULL) {
|
||||
EC_RAW_POINT point;
|
||||
if (!ec_point_mul_scalar_base(eckey->group, &point,
|
||||
@@ -339,9 +342,9 @@ int EC_KEY_check_fips(const EC_KEY *key) {
|
||||
if (key->priv_key) {
|
||||
uint8_t data[16] = {0};
|
||||
ECDSA_SIG *sig = ECDSA_do_sign(data, sizeof(data), key);
|
||||
#if defined(BORINGSSL_FIPS_BREAK_ECDSA_PWCT)
|
||||
data[0] = ~data[0];
|
||||
#endif
|
||||
if (boringssl_fips_break_test("ECDSA_PWCT")) {
|
||||
data[0] = ~data[0];
|
||||
}
|
||||
int ok = sig != NULL &&
|
||||
ECDSA_do_verify(data, sizeof(data), sig, key);
|
||||
ECDSA_SIG_free(sig);
|
||||
@@ -439,6 +442,8 @@ int EC_KEY_generate_key(EC_KEY *key) {
|
||||
}
|
||||
|
||||
int EC_KEY_generate_key_fips(EC_KEY *eckey) {
|
||||
boringssl_ensure_ecc_self_test();
|
||||
|
||||
if (EC_KEY_generate_key(eckey) && EC_KEY_check_fips(eckey)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -301,6 +301,13 @@ int ec_jacobian_to_affine_batch(const EC_GROUP *group, EC_AFFINE *out,
|
||||
int ec_point_set_affine_coordinates(const EC_GROUP *group, EC_AFFINE *out,
|
||||
const EC_FELEM *x, const EC_FELEM *y);
|
||||
|
||||
// ec_point_mul_no_self_test does the same as |EC_POINT_mul|, but doesn't try to
|
||||
// run the self-test first. This is for use in the self tests themselves, to
|
||||
// prevent an infinite loop.
|
||||
int ec_point_mul_no_self_test(const EC_GROUP *group, EC_POINT *r,
|
||||
const BIGNUM *g_scalar, const EC_POINT *p,
|
||||
const BIGNUM *p_scalar, BN_CTX *ctx);
|
||||
|
||||
// ec_point_mul_scalar sets |r| to |p| * |scalar|. Both inputs are considered
|
||||
// secret.
|
||||
int ec_point_mul_scalar(const EC_GROUP *group, EC_RAW_POINT *r,
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#include <string.h>
|
||||
|
||||
#include <CCryptoBoringSSL_bn.h>
|
||||
#include <CCryptoBoringSSL_cpu.h>
|
||||
#include <CCryptoBoringSSL_crypto.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
|
||||
@@ -557,7 +556,7 @@ static void ecp_nistz256_inv0_mod_ord(const EC_GROUP *group, EC_SCALAR *out,
|
||||
static int ecp_nistz256_scalar_to_montgomery_inv_vartime(const EC_GROUP *group,
|
||||
EC_SCALAR *out,
|
||||
const EC_SCALAR *in) {
|
||||
if ((OPENSSL_ia32cap_get()[1] & (1 << 28)) == 0) {
|
||||
if (!CRYPTO_is_AVX_capable()) {
|
||||
// No AVX support; fallback to generic code.
|
||||
return ec_simple_scalar_to_montgomery_inv_vartime(group, out, in);
|
||||
}
|
||||
|
||||
@@ -75,10 +75,13 @@
|
||||
#include <CCryptoBoringSSL_sha.h>
|
||||
|
||||
#include "../ec/internal.h"
|
||||
#include "../../internal.h"
|
||||
|
||||
|
||||
int ECDH_compute_key_fips(uint8_t *out, size_t out_len, const EC_POINT *pub_key,
|
||||
const EC_KEY *priv_key) {
|
||||
boringssl_ensure_ecc_self_test();
|
||||
|
||||
if (priv_key->priv_key == NULL) {
|
||||
OPENSSL_PUT_ERROR(ECDH, ECDH_R_NO_PRIVATE_VALUE);
|
||||
return 0;
|
||||
|
||||
@@ -151,8 +151,8 @@ int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ECDSA_do_verify(const uint8_t *digest, size_t digest_len,
|
||||
const ECDSA_SIG *sig, const EC_KEY *eckey) {
|
||||
int ecdsa_do_verify_no_self_test(const uint8_t *digest, size_t digest_len,
|
||||
const ECDSA_SIG *sig, const EC_KEY *eckey) {
|
||||
const EC_GROUP *group = EC_KEY_get0_group(eckey);
|
||||
const EC_POINT *pub_key = EC_KEY_get0_public_key(eckey);
|
||||
if (group == NULL || pub_key == NULL || sig == NULL) {
|
||||
@@ -198,6 +198,13 @@ int ECDSA_do_verify(const uint8_t *digest, size_t digest_len,
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ECDSA_do_verify(const uint8_t *digest, size_t digest_len,
|
||||
const ECDSA_SIG *sig, const EC_KEY *eckey) {
|
||||
boringssl_ensure_ecc_self_test();
|
||||
|
||||
return ecdsa_do_verify_no_self_test(digest, digest_len, sig, eckey);
|
||||
}
|
||||
|
||||
static ECDSA_SIG *ecdsa_sign_impl(const EC_GROUP *group, int *out_retry,
|
||||
const EC_SCALAR *priv_key, const EC_SCALAR *k,
|
||||
const uint8_t *digest, size_t digest_len) {
|
||||
@@ -292,12 +299,16 @@ ECDSA_SIG *ecdsa_sign_with_nonce_for_known_answer_test(const uint8_t *digest,
|
||||
ECDSA_SIG *ECDSA_sign_with_nonce_and_leak_private_key_for_testing(
|
||||
const uint8_t *digest, size_t digest_len, const EC_KEY *eckey,
|
||||
const uint8_t *nonce, size_t nonce_len) {
|
||||
boringssl_ensure_ecc_self_test();
|
||||
|
||||
return ecdsa_sign_with_nonce_for_known_answer_test(digest, digest_len, eckey,
|
||||
nonce, nonce_len);
|
||||
}
|
||||
|
||||
ECDSA_SIG *ECDSA_do_sign(const uint8_t *digest, size_t digest_len,
|
||||
const EC_KEY *eckey) {
|
||||
boringssl_ensure_ecc_self_test();
|
||||
|
||||
if (eckey->ecdsa_meth && eckey->ecdsa_meth->sign) {
|
||||
OPENSSL_PUT_ERROR(ECDSA, ECDSA_R_NOT_IMPLEMENTED);
|
||||
return NULL;
|
||||
|
||||
@@ -31,6 +31,12 @@ ECDSA_SIG *ecdsa_sign_with_nonce_for_known_answer_test(const uint8_t *digest,
|
||||
const uint8_t *nonce,
|
||||
size_t nonce_len);
|
||||
|
||||
// ecdsa_do_verify_no_self_test does the same as |ECDSA_do_verify|, but doesn't
|
||||
// try to run the self-test first. This is for use in the self tests themselves,
|
||||
// to prevent an infinite loop.
|
||||
int ecdsa_do_verify_no_self_test(const uint8_t *digest, size_t digest_len,
|
||||
const ECDSA_SIG *sig, const EC_KEY *eckey);
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ _gcm_gmult_v8:
|
||||
movi v19.16b,#0xe1
|
||||
ld1 {v20.2d,v21.2d},[x1] //load twisted H, ...
|
||||
shl v19.2d,v19.2d,#57
|
||||
#ifndef __ARMEB__
|
||||
#ifndef __AARCH64EB__
|
||||
rev64 v17.16b,v17.16b
|
||||
#endif
|
||||
ext v3.16b,v17.16b,v17.16b,#8
|
||||
@@ -146,7 +146,7 @@ _gcm_gmult_v8:
|
||||
eor v18.16b,v18.16b,v2.16b
|
||||
eor v0.16b,v0.16b,v18.16b
|
||||
|
||||
#ifndef __ARMEB__
|
||||
#ifndef __AARCH64EB__
|
||||
rev64 v0.16b,v0.16b
|
||||
#endif
|
||||
ext v0.16b,v0.16b,v0.16b,#8
|
||||
@@ -185,14 +185,14 @@ _gcm_ghash_v8:
|
||||
ext v0.16b,v0.16b,v0.16b,#8 //rotate Xi
|
||||
ld1 {v16.2d},[x2],#16 //load [rotated] I[0]
|
||||
shl v19.2d,v19.2d,#57 //compose 0xc2.0 constant
|
||||
#ifndef __ARMEB__
|
||||
#ifndef __AARCH64EB__
|
||||
rev64 v16.16b,v16.16b
|
||||
rev64 v0.16b,v0.16b
|
||||
#endif
|
||||
ext v3.16b,v16.16b,v16.16b,#8 //rotate I[0]
|
||||
b.lo Lodd_tail_v8 //x3 was less than 32
|
||||
ld1 {v17.2d},[x2],x12 //load [rotated] I[1]
|
||||
#ifndef __ARMEB__
|
||||
#ifndef __AARCH64EB__
|
||||
rev64 v17.16b,v17.16b
|
||||
#endif
|
||||
ext v7.16b,v17.16b,v17.16b,#8
|
||||
@@ -224,13 +224,13 @@ Loop_mod2x_v8:
|
||||
eor v18.16b,v0.16b,v2.16b
|
||||
eor v1.16b,v1.16b,v17.16b
|
||||
ld1 {v17.2d},[x2],x12 //load [rotated] I[i+3]
|
||||
#ifndef __ARMEB__
|
||||
#ifndef __AARCH64EB__
|
||||
rev64 v16.16b,v16.16b
|
||||
#endif
|
||||
eor v1.16b,v1.16b,v18.16b
|
||||
pmull v18.1q,v0.1d,v19.1d //1st phase of reduction
|
||||
|
||||
#ifndef __ARMEB__
|
||||
#ifndef __AARCH64EB__
|
||||
rev64 v17.16b,v17.16b
|
||||
#endif
|
||||
ins v2.d[0],v1.d[1]
|
||||
@@ -280,7 +280,7 @@ Lodd_tail_v8:
|
||||
eor v0.16b,v0.16b,v18.16b
|
||||
|
||||
Ldone_v8:
|
||||
#ifndef __ARMEB__
|
||||
#ifndef __AARCH64EB__
|
||||
rev64 v0.16b,v0.16b
|
||||
#endif
|
||||
ext v0.16b,v0.16b,v0.16b,#8
|
||||
@@ -299,7 +299,7 @@ Lgcm_ghash_v8_4x:
|
||||
shl v19.2d,v19.2d,#57 //compose 0xc2.0 constant
|
||||
|
||||
ld1 {v4.2d,v5.2d,v6.2d,v7.2d},[x2],#64
|
||||
#ifndef __ARMEB__
|
||||
#ifndef __AARCH64EB__
|
||||
rev64 v0.16b,v0.16b
|
||||
rev64 v5.16b,v5.16b
|
||||
rev64 v6.16b,v6.16b
|
||||
@@ -343,7 +343,7 @@ Loop4x:
|
||||
eor v16.16b,v4.16b,v0.16b
|
||||
ld1 {v4.2d,v5.2d,v6.2d,v7.2d},[x2],#64
|
||||
ext v3.16b,v16.16b,v16.16b,#8
|
||||
#ifndef __ARMEB__
|
||||
#ifndef __AARCH64EB__
|
||||
rev64 v5.16b,v5.16b
|
||||
rev64 v6.16b,v6.16b
|
||||
rev64 v7.16b,v7.16b
|
||||
@@ -426,7 +426,7 @@ Lthree:
|
||||
eor v1.16b,v1.16b,v17.16b
|
||||
ld1 {v4.2d,v5.2d,v6.2d},[x2]
|
||||
eor v1.16b,v1.16b,v18.16b
|
||||
#ifndef __ARMEB__
|
||||
#ifndef __AARCH64EB__
|
||||
rev64 v5.16b,v5.16b
|
||||
rev64 v6.16b,v6.16b
|
||||
rev64 v4.16b,v4.16b
|
||||
@@ -478,7 +478,7 @@ Ltwo:
|
||||
eor v1.16b,v1.16b,v17.16b
|
||||
ld1 {v4.2d,v5.2d},[x2]
|
||||
eor v1.16b,v1.16b,v18.16b
|
||||
#ifndef __ARMEB__
|
||||
#ifndef __AARCH64EB__
|
||||
rev64 v5.16b,v5.16b
|
||||
rev64 v4.16b,v4.16b
|
||||
#endif
|
||||
@@ -521,7 +521,7 @@ Lone:
|
||||
eor v1.16b,v1.16b,v17.16b
|
||||
ld1 {v4.2d},[x2]
|
||||
eor v1.16b,v1.16b,v18.16b
|
||||
#ifndef __ARMEB__
|
||||
#ifndef __AARCH64EB__
|
||||
rev64 v4.16b,v4.16b
|
||||
#endif
|
||||
|
||||
@@ -561,7 +561,7 @@ Ldone4x:
|
||||
eor v0.16b,v0.16b,v18.16b
|
||||
ext v0.16b,v0.16b,v0.16b,#8
|
||||
|
||||
#ifndef __ARMEB__
|
||||
#ifndef __AARCH64EB__
|
||||
rev64 v0.16b,v0.16b
|
||||
#endif
|
||||
st1 {v0.2d},[x0] //write out Xi
|
||||
|
||||
@@ -122,7 +122,7 @@ gcm_gmult_v8:
|
||||
movi v19.16b,#0xe1
|
||||
ld1 {v20.2d,v21.2d},[x1] //load twisted H, ...
|
||||
shl v19.2d,v19.2d,#57
|
||||
#ifndef __ARMEB__
|
||||
#ifndef __AARCH64EB__
|
||||
rev64 v17.16b,v17.16b
|
||||
#endif
|
||||
ext v3.16b,v17.16b,v17.16b,#8
|
||||
@@ -147,7 +147,7 @@ gcm_gmult_v8:
|
||||
eor v18.16b,v18.16b,v2.16b
|
||||
eor v0.16b,v0.16b,v18.16b
|
||||
|
||||
#ifndef __ARMEB__
|
||||
#ifndef __AARCH64EB__
|
||||
rev64 v0.16b,v0.16b
|
||||
#endif
|
||||
ext v0.16b,v0.16b,v0.16b,#8
|
||||
@@ -186,14 +186,14 @@ gcm_ghash_v8:
|
||||
ext v0.16b,v0.16b,v0.16b,#8 //rotate Xi
|
||||
ld1 {v16.2d},[x2],#16 //load [rotated] I[0]
|
||||
shl v19.2d,v19.2d,#57 //compose 0xc2.0 constant
|
||||
#ifndef __ARMEB__
|
||||
#ifndef __AARCH64EB__
|
||||
rev64 v16.16b,v16.16b
|
||||
rev64 v0.16b,v0.16b
|
||||
#endif
|
||||
ext v3.16b,v16.16b,v16.16b,#8 //rotate I[0]
|
||||
b.lo .Lodd_tail_v8 //x3 was less than 32
|
||||
ld1 {v17.2d},[x2],x12 //load [rotated] I[1]
|
||||
#ifndef __ARMEB__
|
||||
#ifndef __AARCH64EB__
|
||||
rev64 v17.16b,v17.16b
|
||||
#endif
|
||||
ext v7.16b,v17.16b,v17.16b,#8
|
||||
@@ -225,13 +225,13 @@ gcm_ghash_v8:
|
||||
eor v18.16b,v0.16b,v2.16b
|
||||
eor v1.16b,v1.16b,v17.16b
|
||||
ld1 {v17.2d},[x2],x12 //load [rotated] I[i+3]
|
||||
#ifndef __ARMEB__
|
||||
#ifndef __AARCH64EB__
|
||||
rev64 v16.16b,v16.16b
|
||||
#endif
|
||||
eor v1.16b,v1.16b,v18.16b
|
||||
pmull v18.1q,v0.1d,v19.1d //1st phase of reduction
|
||||
|
||||
#ifndef __ARMEB__
|
||||
#ifndef __AARCH64EB__
|
||||
rev64 v17.16b,v17.16b
|
||||
#endif
|
||||
ins v2.d[0],v1.d[1]
|
||||
@@ -281,7 +281,7 @@ gcm_ghash_v8:
|
||||
eor v0.16b,v0.16b,v18.16b
|
||||
|
||||
.Ldone_v8:
|
||||
#ifndef __ARMEB__
|
||||
#ifndef __AARCH64EB__
|
||||
rev64 v0.16b,v0.16b
|
||||
#endif
|
||||
ext v0.16b,v0.16b,v0.16b,#8
|
||||
@@ -300,7 +300,7 @@ gcm_ghash_v8_4x:
|
||||
shl v19.2d,v19.2d,#57 //compose 0xc2.0 constant
|
||||
|
||||
ld1 {v4.2d,v5.2d,v6.2d,v7.2d},[x2],#64
|
||||
#ifndef __ARMEB__
|
||||
#ifndef __AARCH64EB__
|
||||
rev64 v0.16b,v0.16b
|
||||
rev64 v5.16b,v5.16b
|
||||
rev64 v6.16b,v6.16b
|
||||
@@ -344,7 +344,7 @@ gcm_ghash_v8_4x:
|
||||
eor v16.16b,v4.16b,v0.16b
|
||||
ld1 {v4.2d,v5.2d,v6.2d,v7.2d},[x2],#64
|
||||
ext v3.16b,v16.16b,v16.16b,#8
|
||||
#ifndef __ARMEB__
|
||||
#ifndef __AARCH64EB__
|
||||
rev64 v5.16b,v5.16b
|
||||
rev64 v6.16b,v6.16b
|
||||
rev64 v7.16b,v7.16b
|
||||
@@ -427,7 +427,7 @@ gcm_ghash_v8_4x:
|
||||
eor v1.16b,v1.16b,v17.16b
|
||||
ld1 {v4.2d,v5.2d,v6.2d},[x2]
|
||||
eor v1.16b,v1.16b,v18.16b
|
||||
#ifndef __ARMEB__
|
||||
#ifndef __AARCH64EB__
|
||||
rev64 v5.16b,v5.16b
|
||||
rev64 v6.16b,v6.16b
|
||||
rev64 v4.16b,v4.16b
|
||||
@@ -479,7 +479,7 @@ gcm_ghash_v8_4x:
|
||||
eor v1.16b,v1.16b,v17.16b
|
||||
ld1 {v4.2d,v5.2d},[x2]
|
||||
eor v1.16b,v1.16b,v18.16b
|
||||
#ifndef __ARMEB__
|
||||
#ifndef __AARCH64EB__
|
||||
rev64 v5.16b,v5.16b
|
||||
rev64 v4.16b,v4.16b
|
||||
#endif
|
||||
@@ -522,7 +522,7 @@ gcm_ghash_v8_4x:
|
||||
eor v1.16b,v1.16b,v17.16b
|
||||
ld1 {v4.2d},[x2]
|
||||
eor v1.16b,v1.16b,v18.16b
|
||||
#ifndef __ARMEB__
|
||||
#ifndef __AARCH64EB__
|
||||
rev64 v4.16b,v4.16b
|
||||
#endif
|
||||
|
||||
@@ -562,7 +562,7 @@ gcm_ghash_v8_4x:
|
||||
eor v0.16b,v0.16b,v18.16b
|
||||
ext v0.16b,v0.16b,v0.16b,#8
|
||||
|
||||
#ifndef __ARMEB__
|
||||
#ifndef __AARCH64EB__
|
||||
rev64 v0.16b,v0.16b
|
||||
#endif
|
||||
st1 {v0.2d},[x0] //write out Xi
|
||||
|
||||
@@ -102,6 +102,13 @@ void HMAC_CTX_cleanup(HMAC_CTX *ctx) {
|
||||
OPENSSL_cleanse(ctx, sizeof(HMAC_CTX));
|
||||
}
|
||||
|
||||
void HMAC_CTX_cleanse(HMAC_CTX *ctx) {
|
||||
EVP_MD_CTX_cleanse(&ctx->i_ctx);
|
||||
EVP_MD_CTX_cleanse(&ctx->o_ctx);
|
||||
EVP_MD_CTX_cleanse(&ctx->md_ctx);
|
||||
OPENSSL_cleanse(ctx, sizeof(HMAC_CTX));
|
||||
}
|
||||
|
||||
void HMAC_CTX_free(HMAC_CTX *ctx) {
|
||||
if (ctx == NULL) {
|
||||
return;
|
||||
|
||||
@@ -52,7 +52,6 @@
|
||||
#include <string.h>
|
||||
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_cpu.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "../../internal.h"
|
||||
@@ -153,7 +152,7 @@ void CRYPTO_ghash_init(gmult_func *out_mult, ghash_func *out_hash,
|
||||
|
||||
#if defined(GHASH_ASM_X86_64)
|
||||
if (crypto_gcm_clmul_enabled()) {
|
||||
if (((OPENSSL_ia32cap_get()[1] >> 22) & 0x41) == 0x41) { // AVX+MOVBE
|
||||
if (CRYPTO_is_AVX_capable() && CRYPTO_is_MOVBE_capable()) {
|
||||
gcm_init_avx(out_table, H.u);
|
||||
*out_mult = gcm_gmult_avx;
|
||||
*out_hash = gcm_ghash_avx;
|
||||
@@ -165,7 +164,7 @@ void CRYPTO_ghash_init(gmult_func *out_mult, ghash_func *out_hash,
|
||||
*out_hash = gcm_ghash_clmul;
|
||||
return;
|
||||
}
|
||||
if (gcm_ssse3_capable()) {
|
||||
if (CRYPTO_is_SSSE3_capable()) {
|
||||
gcm_init_ssse3(out_table, H.u);
|
||||
*out_mult = gcm_gmult_ssse3;
|
||||
*out_hash = gcm_ghash_ssse3;
|
||||
@@ -178,7 +177,7 @@ void CRYPTO_ghash_init(gmult_func *out_mult, ghash_func *out_hash,
|
||||
*out_hash = gcm_ghash_clmul;
|
||||
return;
|
||||
}
|
||||
if (gcm_ssse3_capable()) {
|
||||
if (CRYPTO_is_SSSE3_capable()) {
|
||||
gcm_init_ssse3(out_table, H.u);
|
||||
*out_mult = gcm_gmult_ssse3;
|
||||
*out_hash = gcm_ghash_ssse3;
|
||||
@@ -723,9 +722,7 @@ void CRYPTO_gcm128_tag(GCM128_CONTEXT *ctx, unsigned char *tag, size_t len) {
|
||||
#if defined(OPENSSL_X86) || defined(OPENSSL_X86_64)
|
||||
int crypto_gcm_clmul_enabled(void) {
|
||||
#if defined(GHASH_ASM_X86) || defined(GHASH_ASM_X86_64)
|
||||
const uint32_t *ia32cap = OPENSSL_ia32cap_get();
|
||||
return (ia32cap[0] & (1 << 24)) && // check FXSR bit
|
||||
(ia32cap[1] & (1 << 1)); // check PCLMULQDQ bit
|
||||
return CRYPTO_is_FXSR_capable() && CRYPTO_is_PCLMUL_capable();
|
||||
#else
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
@@ -52,7 +52,6 @@
|
||||
#include <CCryptoBoringSSL_base.h>
|
||||
|
||||
#include <CCryptoBoringSSL_aes.h>
|
||||
#include <CCryptoBoringSSL_cpu.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -254,10 +253,6 @@ void gcm_gmult_clmul(uint64_t Xi[2], const u128 Htable[16]);
|
||||
void gcm_ghash_clmul(uint64_t Xi[2], const u128 Htable[16], const uint8_t *inp,
|
||||
size_t len);
|
||||
|
||||
OPENSSL_INLINE char gcm_ssse3_capable(void) {
|
||||
return (OPENSSL_ia32cap_get()[1] & (1 << (41 - 32))) != 0;
|
||||
}
|
||||
|
||||
// |gcm_gmult_ssse3| and |gcm_ghash_ssse3| require |Htable| to be
|
||||
// 16-byte-aligned, but |gcm_init_ssse3| does not.
|
||||
void gcm_init_ssse3(u128 Htable[16], const uint64_t Xi[2]);
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
#define OPENSSL_HEADER_CRYPTO_RAND_INTERNAL_H
|
||||
|
||||
#include <CCryptoBoringSSL_aes.h>
|
||||
#include <CCryptoBoringSSL_cpu.h>
|
||||
|
||||
#include "../../internal.h"
|
||||
#include "../modes/internal.h"
|
||||
@@ -144,15 +143,14 @@ OPENSSL_EXPORT void CTR_DRBG_clear(CTR_DRBG_STATE *drbg);
|
||||
#if defined(OPENSSL_X86_64) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
OPENSSL_INLINE int have_rdrand(void) {
|
||||
return (OPENSSL_ia32cap_get()[1] & (1u << 30)) != 0;
|
||||
return CRYPTO_is_RDRAND_capable();
|
||||
}
|
||||
|
||||
// have_fast_rdrand returns true if RDRAND is supported and it's reasonably
|
||||
// fast. Concretely the latter is defined by whether the chip is Intel (fast) or
|
||||
// not (assumed slow).
|
||||
OPENSSL_INLINE int have_fast_rdrand(void) {
|
||||
const uint32_t *const ia32cap = OPENSSL_ia32cap_get();
|
||||
return (ia32cap[1] & (1u << 30)) && (ia32cap[0] & (1u << 30));
|
||||
return CRYPTO_is_RDRAND_capable() && CRYPTO_is_intel_cpu();
|
||||
}
|
||||
|
||||
// CRYPTO_rdrand writes eight bytes of random data from the hardware RNG to
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
#endif
|
||||
|
||||
#include <CCryptoBoringSSL_chacha.h>
|
||||
#include <CCryptoBoringSSL_cpu.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_type_check.h>
|
||||
|
||||
@@ -171,11 +170,11 @@ void CRYPTO_get_seed_entropy(uint8_t *out_entropy, size_t out_entropy_len,
|
||||
CRYPTO_sysrand_for_seed(out_entropy, out_entropy_len);
|
||||
}
|
||||
|
||||
#if defined(BORINGSSL_FIPS_BREAK_CRNG)
|
||||
// This breaks the "continuous random number generator test" defined in FIPS
|
||||
// 140-2, section 4.9.2, and implemented in |rand_get_seed|.
|
||||
OPENSSL_memset(out_entropy, 0, out_entropy_len);
|
||||
#endif
|
||||
if (boringssl_fips_break_test("CRNG")) {
|
||||
// This breaks the "continuous random number generator test" defined in FIPS
|
||||
// 140-2, section 4.9.2, and implemented in |rand_get_seed|.
|
||||
OPENSSL_memset(out_entropy, 0, out_entropy_len);
|
||||
}
|
||||
}
|
||||
|
||||
// In passive entropy mode, entropy is supplied from outside of the module via
|
||||
|
||||
@@ -124,6 +124,28 @@ extern const BN_ULONG kBoringSSLRSASqrtTwo[];
|
||||
extern const size_t kBoringSSLRSASqrtTwoLen;
|
||||
|
||||
|
||||
// Functions that avoid self-tests.
|
||||
//
|
||||
// Self-tests need to call functions that don't try and ensure that the
|
||||
// self-tests have passed. These functions, in turn, need to limit themselves
|
||||
// to such functions too.
|
||||
//
|
||||
// These functions are the same as their public versions, but skip the self-test
|
||||
// check.
|
||||
|
||||
int rsa_verify_no_self_test(int hash_nid, const uint8_t *digest,
|
||||
size_t digest_len, const uint8_t *sig,
|
||||
size_t sig_len, RSA *rsa);
|
||||
|
||||
int rsa_verify_raw_no_self_test(RSA *rsa, size_t *out_len, uint8_t *out,
|
||||
size_t max_out, const uint8_t *in,
|
||||
size_t in_len, int padding);
|
||||
|
||||
int rsa_sign_no_self_test(int hash_nid, const uint8_t *digest,
|
||||
unsigned digest_len, uint8_t *out, unsigned *out_len,
|
||||
RSA *rsa);
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // extern C
|
||||
#endif
|
||||
|
||||
@@ -303,8 +303,9 @@ int RSA_public_encrypt(size_t flen, const uint8_t *from, uint8_t *to, RSA *rsa,
|
||||
return out_len;
|
||||
}
|
||||
|
||||
int RSA_sign_raw(RSA *rsa, size_t *out_len, uint8_t *out, size_t max_out,
|
||||
const uint8_t *in, size_t in_len, int padding) {
|
||||
static int rsa_sign_raw_no_self_test(RSA *rsa, size_t *out_len, uint8_t *out,
|
||||
size_t max_out, const uint8_t *in,
|
||||
size_t in_len, int padding) {
|
||||
if (rsa->meth->sign_raw) {
|
||||
return rsa->meth->sign_raw(rsa, out_len, out, max_out, in, in_len, padding);
|
||||
}
|
||||
@@ -312,6 +313,13 @@ int RSA_sign_raw(RSA *rsa, size_t *out_len, uint8_t *out, size_t max_out,
|
||||
return rsa_default_sign_raw(rsa, out_len, out, max_out, in, in_len, padding);
|
||||
}
|
||||
|
||||
int RSA_sign_raw(RSA *rsa, size_t *out_len, uint8_t *out, size_t max_out,
|
||||
const uint8_t *in, size_t in_len, int padding) {
|
||||
boringssl_ensure_rsa_self_test();
|
||||
return rsa_sign_raw_no_self_test(rsa, out_len, out, max_out, in, in_len,
|
||||
padding);
|
||||
}
|
||||
|
||||
int RSA_private_encrypt(size_t flen, const uint8_t *from, uint8_t *to, RSA *rsa,
|
||||
int padding) {
|
||||
size_t out_len;
|
||||
@@ -523,8 +531,9 @@ int RSA_add_pkcs1_prefix(uint8_t **out_msg, size_t *out_msg_len,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int RSA_sign(int hash_nid, const uint8_t *digest, unsigned digest_len,
|
||||
uint8_t *out, unsigned *out_len, RSA *rsa) {
|
||||
int rsa_sign_no_self_test(int hash_nid, const uint8_t *digest,
|
||||
unsigned digest_len, uint8_t *out, unsigned *out_len,
|
||||
RSA *rsa) {
|
||||
const unsigned rsa_size = RSA_size(rsa);
|
||||
int ret = 0;
|
||||
uint8_t *signed_msg = NULL;
|
||||
@@ -539,8 +548,9 @@ int RSA_sign(int hash_nid, const uint8_t *digest, unsigned digest_len,
|
||||
if (!RSA_add_pkcs1_prefix(&signed_msg, &signed_msg_len,
|
||||
&signed_msg_is_alloced, hash_nid, digest,
|
||||
digest_len) ||
|
||||
!RSA_sign_raw(rsa, &size_t_out_len, out, rsa_size, signed_msg,
|
||||
signed_msg_len, RSA_PKCS1_PADDING)) {
|
||||
!rsa_sign_raw_no_self_test(rsa, &size_t_out_len, out, rsa_size,
|
||||
signed_msg, signed_msg_len,
|
||||
RSA_PKCS1_PADDING)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
@@ -554,6 +564,13 @@ err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int RSA_sign(int hash_nid, const uint8_t *digest, unsigned digest_len,
|
||||
uint8_t *out, unsigned *out_len, RSA *rsa) {
|
||||
boringssl_ensure_rsa_self_test();
|
||||
|
||||
return rsa_sign_no_self_test(hash_nid, digest, digest_len, out, out_len, rsa);
|
||||
}
|
||||
|
||||
int RSA_sign_pss_mgf1(RSA *rsa, size_t *out_len, uint8_t *out, size_t max_out,
|
||||
const uint8_t *digest, size_t digest_len,
|
||||
const EVP_MD *md, const EVP_MD *mgf1_md, int salt_len) {
|
||||
@@ -577,8 +594,9 @@ int RSA_sign_pss_mgf1(RSA *rsa, size_t *out_len, uint8_t *out, size_t max_out,
|
||||
return ret;
|
||||
}
|
||||
|
||||
int RSA_verify(int hash_nid, const uint8_t *digest, size_t digest_len,
|
||||
const uint8_t *sig, size_t sig_len, RSA *rsa) {
|
||||
int rsa_verify_no_self_test(int hash_nid, const uint8_t *digest,
|
||||
size_t digest_len, const uint8_t *sig,
|
||||
size_t sig_len, RSA *rsa) {
|
||||
if (rsa->n == NULL || rsa->e == NULL) {
|
||||
OPENSSL_PUT_ERROR(RSA, RSA_R_VALUE_MISSING);
|
||||
return 0;
|
||||
@@ -602,12 +620,9 @@ int RSA_verify(int hash_nid, const uint8_t *digest, size_t digest_len,
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!RSA_verify_raw(rsa, &len, buf, rsa_size, sig, sig_len,
|
||||
RSA_PKCS1_PADDING)) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!RSA_add_pkcs1_prefix(&signed_msg, &signed_msg_len,
|
||||
if (!rsa_verify_raw_no_self_test(rsa, &len, buf, rsa_size, sig, sig_len,
|
||||
RSA_PKCS1_PADDING) ||
|
||||
!RSA_add_pkcs1_prefix(&signed_msg, &signed_msg_len,
|
||||
&signed_msg_is_alloced, hash_nid, digest,
|
||||
digest_len)) {
|
||||
goto out;
|
||||
@@ -630,6 +645,13 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int RSA_verify(int hash_nid, const uint8_t *digest, size_t digest_len,
|
||||
const uint8_t *sig, size_t sig_len, RSA *rsa) {
|
||||
boringssl_ensure_rsa_self_test();
|
||||
return rsa_verify_no_self_test(hash_nid, digest, digest_len, sig, sig_len,
|
||||
rsa);
|
||||
}
|
||||
|
||||
int RSA_verify_pss_mgf1(RSA *rsa, const uint8_t *digest, size_t digest_len,
|
||||
const EVP_MD *md, const EVP_MD *mgf1_md, int salt_len,
|
||||
const uint8_t *sig, size_t sig_len) {
|
||||
@@ -905,9 +927,9 @@ int RSA_check_fips(RSA *key) {
|
||||
ret = 0;
|
||||
goto cleanup;
|
||||
}
|
||||
#if defined(BORINGSSL_FIPS_BREAK_RSA_PWCT)
|
||||
data[0] = ~data[0];
|
||||
#endif
|
||||
if (boringssl_fips_break_test("RSA_PWCT")) {
|
||||
data[0] = ~data[0];
|
||||
}
|
||||
if (!RSA_verify(NID_sha256, data, sizeof(data), sig, sig_len, key)) {
|
||||
OPENSSL_PUT_ERROR(RSA, ERR_R_INTERNAL_ERROR);
|
||||
ret = 0;
|
||||
|
||||
@@ -261,6 +261,8 @@ size_t rsa_default_size(const RSA *rsa) {
|
||||
|
||||
int RSA_encrypt(RSA *rsa, size_t *out_len, uint8_t *out, size_t max_out,
|
||||
const uint8_t *in, size_t in_len, int padding) {
|
||||
boringssl_ensure_rsa_self_test();
|
||||
|
||||
if (!rsa_check_public_key(rsa)) {
|
||||
return 0;
|
||||
}
|
||||
@@ -528,6 +530,8 @@ err:
|
||||
|
||||
int rsa_default_decrypt(RSA *rsa, size_t *out_len, uint8_t *out, size_t max_out,
|
||||
const uint8_t *in, size_t in_len, int padding) {
|
||||
boringssl_ensure_rsa_self_test();
|
||||
|
||||
const unsigned rsa_size = RSA_size(rsa);
|
||||
uint8_t *buf = NULL;
|
||||
int ret = 0;
|
||||
@@ -593,8 +597,9 @@ err:
|
||||
|
||||
static int mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx);
|
||||
|
||||
int RSA_verify_raw(RSA *rsa, size_t *out_len, uint8_t *out, size_t max_out,
|
||||
const uint8_t *in, size_t in_len, int padding) {
|
||||
int rsa_verify_raw_no_self_test(RSA *rsa, size_t *out_len, uint8_t *out,
|
||||
size_t max_out, const uint8_t *in,
|
||||
size_t in_len, int padding) {
|
||||
if (!rsa_check_public_key(rsa)) {
|
||||
return 0;
|
||||
}
|
||||
@@ -686,6 +691,14 @@ err:
|
||||
return ret;
|
||||
}
|
||||
|
||||
int RSA_verify_raw(RSA *rsa, size_t *out_len, uint8_t *out,
|
||||
size_t max_out, const uint8_t *in,
|
||||
size_t in_len, int padding) {
|
||||
boringssl_ensure_rsa_self_test();
|
||||
return rsa_verify_raw_no_self_test(rsa, out_len, out, max_out, in, in_len,
|
||||
padding);
|
||||
}
|
||||
|
||||
int rsa_default_private_transform(RSA *rsa, uint8_t *out, const uint8_t *in,
|
||||
size_t len) {
|
||||
if (rsa->n == NULL || rsa->d == NULL) {
|
||||
@@ -1324,6 +1337,8 @@ static void replace_bn_mont_ctx(BN_MONT_CTX **out, BN_MONT_CTX **in) {
|
||||
static int RSA_generate_key_ex_maybe_fips(RSA *rsa, int bits,
|
||||
const BIGNUM *e_value, BN_GENCB *cb,
|
||||
int check_fips) {
|
||||
boringssl_ensure_rsa_self_test();
|
||||
|
||||
RSA *tmp = NULL;
|
||||
uint32_t err;
|
||||
int ret = 0;
|
||||
|
||||
@@ -28,6 +28,45 @@ int FIPS_mode(void) {
|
||||
|
||||
int FIPS_mode_set(int on) { return on == FIPS_mode(); }
|
||||
|
||||
uint32_t FIPS_version(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int FIPS_query_algorithm_status(const char *algorithm) {
|
||||
#if defined(BORINGSSL_FIPS)
|
||||
static const char kApprovedAlgorithms[][13] = {
|
||||
"AES-CBC",
|
||||
"AES-CCM",
|
||||
"AES-CTR",
|
||||
"AES-ECB",
|
||||
"AES-GCM",
|
||||
"AES-KW",
|
||||
"AES-KWP",
|
||||
"ctrDRBG",
|
||||
"ECC-SSC",
|
||||
"ECDSA-sign",
|
||||
"ECDSA-verify",
|
||||
"FFC-SSC",
|
||||
"HMAC",
|
||||
"RSA-sign",
|
||||
"RSA-verify",
|
||||
"SHA-1",
|
||||
"SHA2-224",
|
||||
"SHA2-256",
|
||||
"SHA2-384",
|
||||
"SHA2-512",
|
||||
"SHA2-512/256",
|
||||
};
|
||||
for (size_t i = 0; i < OPENSSL_ARRAY_SIZE(kApprovedAlgorithms); i++) {
|
||||
if (strcmp(algorithm, kApprovedAlgorithms[i]) == 0) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
#endif // BORINGSSL_FIPS
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(BORINGSSL_FIPS_COUNTERS)
|
||||
|
||||
size_t FIPS_read_counter(enum fips_counter_t counter) {
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -53,7 +53,7 @@ Loop:
|
||||
movz w28,#0x7999
|
||||
sub x2,x2,#1
|
||||
movk w28,#0x5a82,lsl#16
|
||||
#ifdef __ARMEB__
|
||||
#ifdef __AARCH64EB__
|
||||
ror x3,x3,#32
|
||||
#else
|
||||
rev32 x3,x3
|
||||
@@ -71,7 +71,7 @@ Loop:
|
||||
ror w21,w21,#2
|
||||
add w23,w23,w4 // future e+=X[i]
|
||||
add w24,w24,w25 // e+=F(b,c,d)
|
||||
#ifdef __ARMEB__
|
||||
#ifdef __AARCH64EB__
|
||||
ror x5,x5,#32
|
||||
#else
|
||||
rev32 x5,x5
|
||||
@@ -96,7 +96,7 @@ Loop:
|
||||
ror w24,w24,#2
|
||||
add w21,w21,w6 // future e+=X[i]
|
||||
add w22,w22,w25 // e+=F(b,c,d)
|
||||
#ifdef __ARMEB__
|
||||
#ifdef __AARCH64EB__
|
||||
ror x7,x7,#32
|
||||
#else
|
||||
rev32 x7,x7
|
||||
@@ -121,7 +121,7 @@ Loop:
|
||||
ror w22,w22,#2
|
||||
add w24,w24,w8 // future e+=X[i]
|
||||
add w20,w20,w25 // e+=F(b,c,d)
|
||||
#ifdef __ARMEB__
|
||||
#ifdef __AARCH64EB__
|
||||
ror x9,x9,#32
|
||||
#else
|
||||
rev32 x9,x9
|
||||
@@ -146,7 +146,7 @@ Loop:
|
||||
ror w20,w20,#2
|
||||
add w22,w22,w10 // future e+=X[i]
|
||||
add w23,w23,w25 // e+=F(b,c,d)
|
||||
#ifdef __ARMEB__
|
||||
#ifdef __AARCH64EB__
|
||||
ror x11,x11,#32
|
||||
#else
|
||||
rev32 x11,x11
|
||||
@@ -171,7 +171,7 @@ Loop:
|
||||
ror w23,w23,#2
|
||||
add w20,w20,w12 // future e+=X[i]
|
||||
add w21,w21,w25 // e+=F(b,c,d)
|
||||
#ifdef __ARMEB__
|
||||
#ifdef __AARCH64EB__
|
||||
ror x13,x13,#32
|
||||
#else
|
||||
rev32 x13,x13
|
||||
@@ -196,7 +196,7 @@ Loop:
|
||||
ror w21,w21,#2
|
||||
add w23,w23,w14 // future e+=X[i]
|
||||
add w24,w24,w25 // e+=F(b,c,d)
|
||||
#ifdef __ARMEB__
|
||||
#ifdef __AARCH64EB__
|
||||
ror x15,x15,#32
|
||||
#else
|
||||
rev32 x15,x15
|
||||
@@ -221,7 +221,7 @@ Loop:
|
||||
ror w24,w24,#2
|
||||
add w21,w21,w16 // future e+=X[i]
|
||||
add w22,w22,w25 // e+=F(b,c,d)
|
||||
#ifdef __ARMEB__
|
||||
#ifdef __AARCH64EB__
|
||||
ror x17,x17,#32
|
||||
#else
|
||||
rev32 x17,x17
|
||||
|
||||
@@ -54,7 +54,7 @@ sha1_block_data_order:
|
||||
movz w28,#0x7999
|
||||
sub x2,x2,#1
|
||||
movk w28,#0x5a82,lsl#16
|
||||
#ifdef __ARMEB__
|
||||
#ifdef __AARCH64EB__
|
||||
ror x3,x3,#32
|
||||
#else
|
||||
rev32 x3,x3
|
||||
@@ -72,7 +72,7 @@ sha1_block_data_order:
|
||||
ror w21,w21,#2
|
||||
add w23,w23,w4 // future e+=X[i]
|
||||
add w24,w24,w25 // e+=F(b,c,d)
|
||||
#ifdef __ARMEB__
|
||||
#ifdef __AARCH64EB__
|
||||
ror x5,x5,#32
|
||||
#else
|
||||
rev32 x5,x5
|
||||
@@ -97,7 +97,7 @@ sha1_block_data_order:
|
||||
ror w24,w24,#2
|
||||
add w21,w21,w6 // future e+=X[i]
|
||||
add w22,w22,w25 // e+=F(b,c,d)
|
||||
#ifdef __ARMEB__
|
||||
#ifdef __AARCH64EB__
|
||||
ror x7,x7,#32
|
||||
#else
|
||||
rev32 x7,x7
|
||||
@@ -122,7 +122,7 @@ sha1_block_data_order:
|
||||
ror w22,w22,#2
|
||||
add w24,w24,w8 // future e+=X[i]
|
||||
add w20,w20,w25 // e+=F(b,c,d)
|
||||
#ifdef __ARMEB__
|
||||
#ifdef __AARCH64EB__
|
||||
ror x9,x9,#32
|
||||
#else
|
||||
rev32 x9,x9
|
||||
@@ -147,7 +147,7 @@ sha1_block_data_order:
|
||||
ror w20,w20,#2
|
||||
add w22,w22,w10 // future e+=X[i]
|
||||
add w23,w23,w25 // e+=F(b,c,d)
|
||||
#ifdef __ARMEB__
|
||||
#ifdef __AARCH64EB__
|
||||
ror x11,x11,#32
|
||||
#else
|
||||
rev32 x11,x11
|
||||
@@ -172,7 +172,7 @@ sha1_block_data_order:
|
||||
ror w23,w23,#2
|
||||
add w20,w20,w12 // future e+=X[i]
|
||||
add w21,w21,w25 // e+=F(b,c,d)
|
||||
#ifdef __ARMEB__
|
||||
#ifdef __AARCH64EB__
|
||||
ror x13,x13,#32
|
||||
#else
|
||||
rev32 x13,x13
|
||||
@@ -197,7 +197,7 @@ sha1_block_data_order:
|
||||
ror w21,w21,#2
|
||||
add w23,w23,w14 // future e+=X[i]
|
||||
add w24,w24,w25 // e+=F(b,c,d)
|
||||
#ifdef __ARMEB__
|
||||
#ifdef __AARCH64EB__
|
||||
ror x15,x15,#32
|
||||
#else
|
||||
rev32 x15,x15
|
||||
@@ -222,7 +222,7 @@ sha1_block_data_order:
|
||||
ror w24,w24,#2
|
||||
add w21,w21,w16 // future e+=X[i]
|
||||
add w22,w22,w25 // e+=F(b,c,d)
|
||||
#ifdef __ARMEB__
|
||||
#ifdef __AARCH64EB__
|
||||
ror x17,x17,#32
|
||||
#else
|
||||
rev32 x17,x17
|
||||
|
||||
@@ -27,6 +27,8 @@ sha256_block_data_order:
|
||||
movl 0(%r11),%r9d
|
||||
movl 4(%r11),%r10d
|
||||
movl 8(%r11),%r11d
|
||||
testl $536870912,%r11d
|
||||
jnz .Lshaext_shortcut
|
||||
andl $1073741824,%r9d
|
||||
andl $268435968,%r10d
|
||||
orl %r9d,%r10d
|
||||
@@ -1783,6 +1785,215 @@ K256:
|
||||
.long 0xffffffff,0xffffffff,0x03020100,0x0b0a0908
|
||||
.long 0xffffffff,0xffffffff,0x03020100,0x0b0a0908
|
||||
.byte 83,72,65,50,53,54,32,98,108,111,99,107,32,116,114,97,110,115,102,111,114,109,32,102,111,114,32,120,56,54,95,54,52,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0
|
||||
.type sha256_block_data_order_shaext,@function
|
||||
.align 64
|
||||
sha256_block_data_order_shaext:
|
||||
.cfi_startproc
|
||||
.Lshaext_shortcut:
|
||||
leaq K256+128(%rip),%rcx
|
||||
movdqu (%rdi),%xmm1
|
||||
movdqu 16(%rdi),%xmm2
|
||||
movdqa 512-128(%rcx),%xmm7
|
||||
|
||||
pshufd $0x1b,%xmm1,%xmm0
|
||||
pshufd $0xb1,%xmm1,%xmm1
|
||||
pshufd $0x1b,%xmm2,%xmm2
|
||||
movdqa %xmm7,%xmm8
|
||||
.byte 102,15,58,15,202,8
|
||||
punpcklqdq %xmm0,%xmm2
|
||||
jmp .Loop_shaext
|
||||
|
||||
.align 16
|
||||
.Loop_shaext:
|
||||
movdqu (%rsi),%xmm3
|
||||
movdqu 16(%rsi),%xmm4
|
||||
movdqu 32(%rsi),%xmm5
|
||||
.byte 102,15,56,0,223
|
||||
movdqu 48(%rsi),%xmm6
|
||||
|
||||
movdqa 0-128(%rcx),%xmm0
|
||||
paddd %xmm3,%xmm0
|
||||
.byte 102,15,56,0,231
|
||||
movdqa %xmm2,%xmm10
|
||||
.byte 15,56,203,209
|
||||
pshufd $0x0e,%xmm0,%xmm0
|
||||
nop
|
||||
movdqa %xmm1,%xmm9
|
||||
.byte 15,56,203,202
|
||||
|
||||
movdqa 32-128(%rcx),%xmm0
|
||||
paddd %xmm4,%xmm0
|
||||
.byte 102,15,56,0,239
|
||||
.byte 15,56,203,209
|
||||
pshufd $0x0e,%xmm0,%xmm0
|
||||
leaq 64(%rsi),%rsi
|
||||
.byte 15,56,204,220
|
||||
.byte 15,56,203,202
|
||||
|
||||
movdqa 64-128(%rcx),%xmm0
|
||||
paddd %xmm5,%xmm0
|
||||
.byte 102,15,56,0,247
|
||||
.byte 15,56,203,209
|
||||
pshufd $0x0e,%xmm0,%xmm0
|
||||
movdqa %xmm6,%xmm7
|
||||
.byte 102,15,58,15,253,4
|
||||
nop
|
||||
paddd %xmm7,%xmm3
|
||||
.byte 15,56,204,229
|
||||
.byte 15,56,203,202
|
||||
|
||||
movdqa 96-128(%rcx),%xmm0
|
||||
paddd %xmm6,%xmm0
|
||||
.byte 15,56,205,222
|
||||
.byte 15,56,203,209
|
||||
pshufd $0x0e,%xmm0,%xmm0
|
||||
movdqa %xmm3,%xmm7
|
||||
.byte 102,15,58,15,254,4
|
||||
nop
|
||||
paddd %xmm7,%xmm4
|
||||
.byte 15,56,204,238
|
||||
.byte 15,56,203,202
|
||||
movdqa 128-128(%rcx),%xmm0
|
||||
paddd %xmm3,%xmm0
|
||||
.byte 15,56,205,227
|
||||
.byte 15,56,203,209
|
||||
pshufd $0x0e,%xmm0,%xmm0
|
||||
movdqa %xmm4,%xmm7
|
||||
.byte 102,15,58,15,251,4
|
||||
nop
|
||||
paddd %xmm7,%xmm5
|
||||
.byte 15,56,204,243
|
||||
.byte 15,56,203,202
|
||||
movdqa 160-128(%rcx),%xmm0
|
||||
paddd %xmm4,%xmm0
|
||||
.byte 15,56,205,236
|
||||
.byte 15,56,203,209
|
||||
pshufd $0x0e,%xmm0,%xmm0
|
||||
movdqa %xmm5,%xmm7
|
||||
.byte 102,15,58,15,252,4
|
||||
nop
|
||||
paddd %xmm7,%xmm6
|
||||
.byte 15,56,204,220
|
||||
.byte 15,56,203,202
|
||||
movdqa 192-128(%rcx),%xmm0
|
||||
paddd %xmm5,%xmm0
|
||||
.byte 15,56,205,245
|
||||
.byte 15,56,203,209
|
||||
pshufd $0x0e,%xmm0,%xmm0
|
||||
movdqa %xmm6,%xmm7
|
||||
.byte 102,15,58,15,253,4
|
||||
nop
|
||||
paddd %xmm7,%xmm3
|
||||
.byte 15,56,204,229
|
||||
.byte 15,56,203,202
|
||||
movdqa 224-128(%rcx),%xmm0
|
||||
paddd %xmm6,%xmm0
|
||||
.byte 15,56,205,222
|
||||
.byte 15,56,203,209
|
||||
pshufd $0x0e,%xmm0,%xmm0
|
||||
movdqa %xmm3,%xmm7
|
||||
.byte 102,15,58,15,254,4
|
||||
nop
|
||||
paddd %xmm7,%xmm4
|
||||
.byte 15,56,204,238
|
||||
.byte 15,56,203,202
|
||||
movdqa 256-128(%rcx),%xmm0
|
||||
paddd %xmm3,%xmm0
|
||||
.byte 15,56,205,227
|
||||
.byte 15,56,203,209
|
||||
pshufd $0x0e,%xmm0,%xmm0
|
||||
movdqa %xmm4,%xmm7
|
||||
.byte 102,15,58,15,251,4
|
||||
nop
|
||||
paddd %xmm7,%xmm5
|
||||
.byte 15,56,204,243
|
||||
.byte 15,56,203,202
|
||||
movdqa 288-128(%rcx),%xmm0
|
||||
paddd %xmm4,%xmm0
|
||||
.byte 15,56,205,236
|
||||
.byte 15,56,203,209
|
||||
pshufd $0x0e,%xmm0,%xmm0
|
||||
movdqa %xmm5,%xmm7
|
||||
.byte 102,15,58,15,252,4
|
||||
nop
|
||||
paddd %xmm7,%xmm6
|
||||
.byte 15,56,204,220
|
||||
.byte 15,56,203,202
|
||||
movdqa 320-128(%rcx),%xmm0
|
||||
paddd %xmm5,%xmm0
|
||||
.byte 15,56,205,245
|
||||
.byte 15,56,203,209
|
||||
pshufd $0x0e,%xmm0,%xmm0
|
||||
movdqa %xmm6,%xmm7
|
||||
.byte 102,15,58,15,253,4
|
||||
nop
|
||||
paddd %xmm7,%xmm3
|
||||
.byte 15,56,204,229
|
||||
.byte 15,56,203,202
|
||||
movdqa 352-128(%rcx),%xmm0
|
||||
paddd %xmm6,%xmm0
|
||||
.byte 15,56,205,222
|
||||
.byte 15,56,203,209
|
||||
pshufd $0x0e,%xmm0,%xmm0
|
||||
movdqa %xmm3,%xmm7
|
||||
.byte 102,15,58,15,254,4
|
||||
nop
|
||||
paddd %xmm7,%xmm4
|
||||
.byte 15,56,204,238
|
||||
.byte 15,56,203,202
|
||||
movdqa 384-128(%rcx),%xmm0
|
||||
paddd %xmm3,%xmm0
|
||||
.byte 15,56,205,227
|
||||
.byte 15,56,203,209
|
||||
pshufd $0x0e,%xmm0,%xmm0
|
||||
movdqa %xmm4,%xmm7
|
||||
.byte 102,15,58,15,251,4
|
||||
nop
|
||||
paddd %xmm7,%xmm5
|
||||
.byte 15,56,204,243
|
||||
.byte 15,56,203,202
|
||||
movdqa 416-128(%rcx),%xmm0
|
||||
paddd %xmm4,%xmm0
|
||||
.byte 15,56,205,236
|
||||
.byte 15,56,203,209
|
||||
pshufd $0x0e,%xmm0,%xmm0
|
||||
movdqa %xmm5,%xmm7
|
||||
.byte 102,15,58,15,252,4
|
||||
.byte 15,56,203,202
|
||||
paddd %xmm7,%xmm6
|
||||
|
||||
movdqa 448-128(%rcx),%xmm0
|
||||
paddd %xmm5,%xmm0
|
||||
.byte 15,56,203,209
|
||||
pshufd $0x0e,%xmm0,%xmm0
|
||||
.byte 15,56,205,245
|
||||
movdqa %xmm8,%xmm7
|
||||
.byte 15,56,203,202
|
||||
|
||||
movdqa 480-128(%rcx),%xmm0
|
||||
paddd %xmm6,%xmm0
|
||||
nop
|
||||
.byte 15,56,203,209
|
||||
pshufd $0x0e,%xmm0,%xmm0
|
||||
decq %rdx
|
||||
nop
|
||||
.byte 15,56,203,202
|
||||
|
||||
paddd %xmm10,%xmm2
|
||||
paddd %xmm9,%xmm1
|
||||
jnz .Loop_shaext
|
||||
|
||||
pshufd $0xb1,%xmm2,%xmm2
|
||||
pshufd $0x1b,%xmm1,%xmm7
|
||||
pshufd $0xb1,%xmm1,%xmm1
|
||||
punpckhqdq %xmm2,%xmm1
|
||||
.byte 102,15,58,15,215,8
|
||||
|
||||
movdqu %xmm1,(%rdi)
|
||||
movdqu %xmm2,16(%rdi)
|
||||
.byte 0xf3,0xc3
|
||||
.cfi_endproc
|
||||
.size sha256_block_data_order_shaext,.-sha256_block_data_order_shaext
|
||||
.type sha256_block_data_order_ssse3,@function
|
||||
.align 64
|
||||
sha256_block_data_order_ssse3:
|
||||
|
||||
@@ -26,6 +26,8 @@ _sha256_block_data_order:
|
||||
movl 0(%r11),%r9d
|
||||
movl 4(%r11),%r10d
|
||||
movl 8(%r11),%r11d
|
||||
testl $536870912,%r11d
|
||||
jnz L$shaext_shortcut
|
||||
andl $1073741824,%r9d
|
||||
andl $268435968,%r10d
|
||||
orl %r9d,%r10d
|
||||
@@ -1783,6 +1785,215 @@ K256:
|
||||
.long 0xffffffff,0xffffffff,0x03020100,0x0b0a0908
|
||||
.byte 83,72,65,50,53,54,32,98,108,111,99,107,32,116,114,97,110,115,102,111,114,109,32,102,111,114,32,120,56,54,95,54,52,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0
|
||||
|
||||
.p2align 6
|
||||
sha256_block_data_order_shaext:
|
||||
|
||||
L$shaext_shortcut:
|
||||
leaq K256+128(%rip),%rcx
|
||||
movdqu (%rdi),%xmm1
|
||||
movdqu 16(%rdi),%xmm2
|
||||
movdqa 512-128(%rcx),%xmm7
|
||||
|
||||
pshufd $0x1b,%xmm1,%xmm0
|
||||
pshufd $0xb1,%xmm1,%xmm1
|
||||
pshufd $0x1b,%xmm2,%xmm2
|
||||
movdqa %xmm7,%xmm8
|
||||
.byte 102,15,58,15,202,8
|
||||
punpcklqdq %xmm0,%xmm2
|
||||
jmp L$oop_shaext
|
||||
|
||||
.p2align 4
|
||||
L$oop_shaext:
|
||||
movdqu (%rsi),%xmm3
|
||||
movdqu 16(%rsi),%xmm4
|
||||
movdqu 32(%rsi),%xmm5
|
||||
.byte 102,15,56,0,223
|
||||
movdqu 48(%rsi),%xmm6
|
||||
|
||||
movdqa 0-128(%rcx),%xmm0
|
||||
paddd %xmm3,%xmm0
|
||||
.byte 102,15,56,0,231
|
||||
movdqa %xmm2,%xmm10
|
||||
.byte 15,56,203,209
|
||||
pshufd $0x0e,%xmm0,%xmm0
|
||||
nop
|
||||
movdqa %xmm1,%xmm9
|
||||
.byte 15,56,203,202
|
||||
|
||||
movdqa 32-128(%rcx),%xmm0
|
||||
paddd %xmm4,%xmm0
|
||||
.byte 102,15,56,0,239
|
||||
.byte 15,56,203,209
|
||||
pshufd $0x0e,%xmm0,%xmm0
|
||||
leaq 64(%rsi),%rsi
|
||||
.byte 15,56,204,220
|
||||
.byte 15,56,203,202
|
||||
|
||||
movdqa 64-128(%rcx),%xmm0
|
||||
paddd %xmm5,%xmm0
|
||||
.byte 102,15,56,0,247
|
||||
.byte 15,56,203,209
|
||||
pshufd $0x0e,%xmm0,%xmm0
|
||||
movdqa %xmm6,%xmm7
|
||||
.byte 102,15,58,15,253,4
|
||||
nop
|
||||
paddd %xmm7,%xmm3
|
||||
.byte 15,56,204,229
|
||||
.byte 15,56,203,202
|
||||
|
||||
movdqa 96-128(%rcx),%xmm0
|
||||
paddd %xmm6,%xmm0
|
||||
.byte 15,56,205,222
|
||||
.byte 15,56,203,209
|
||||
pshufd $0x0e,%xmm0,%xmm0
|
||||
movdqa %xmm3,%xmm7
|
||||
.byte 102,15,58,15,254,4
|
||||
nop
|
||||
paddd %xmm7,%xmm4
|
||||
.byte 15,56,204,238
|
||||
.byte 15,56,203,202
|
||||
movdqa 128-128(%rcx),%xmm0
|
||||
paddd %xmm3,%xmm0
|
||||
.byte 15,56,205,227
|
||||
.byte 15,56,203,209
|
||||
pshufd $0x0e,%xmm0,%xmm0
|
||||
movdqa %xmm4,%xmm7
|
||||
.byte 102,15,58,15,251,4
|
||||
nop
|
||||
paddd %xmm7,%xmm5
|
||||
.byte 15,56,204,243
|
||||
.byte 15,56,203,202
|
||||
movdqa 160-128(%rcx),%xmm0
|
||||
paddd %xmm4,%xmm0
|
||||
.byte 15,56,205,236
|
||||
.byte 15,56,203,209
|
||||
pshufd $0x0e,%xmm0,%xmm0
|
||||
movdqa %xmm5,%xmm7
|
||||
.byte 102,15,58,15,252,4
|
||||
nop
|
||||
paddd %xmm7,%xmm6
|
||||
.byte 15,56,204,220
|
||||
.byte 15,56,203,202
|
||||
movdqa 192-128(%rcx),%xmm0
|
||||
paddd %xmm5,%xmm0
|
||||
.byte 15,56,205,245
|
||||
.byte 15,56,203,209
|
||||
pshufd $0x0e,%xmm0,%xmm0
|
||||
movdqa %xmm6,%xmm7
|
||||
.byte 102,15,58,15,253,4
|
||||
nop
|
||||
paddd %xmm7,%xmm3
|
||||
.byte 15,56,204,229
|
||||
.byte 15,56,203,202
|
||||
movdqa 224-128(%rcx),%xmm0
|
||||
paddd %xmm6,%xmm0
|
||||
.byte 15,56,205,222
|
||||
.byte 15,56,203,209
|
||||
pshufd $0x0e,%xmm0,%xmm0
|
||||
movdqa %xmm3,%xmm7
|
||||
.byte 102,15,58,15,254,4
|
||||
nop
|
||||
paddd %xmm7,%xmm4
|
||||
.byte 15,56,204,238
|
||||
.byte 15,56,203,202
|
||||
movdqa 256-128(%rcx),%xmm0
|
||||
paddd %xmm3,%xmm0
|
||||
.byte 15,56,205,227
|
||||
.byte 15,56,203,209
|
||||
pshufd $0x0e,%xmm0,%xmm0
|
||||
movdqa %xmm4,%xmm7
|
||||
.byte 102,15,58,15,251,4
|
||||
nop
|
||||
paddd %xmm7,%xmm5
|
||||
.byte 15,56,204,243
|
||||
.byte 15,56,203,202
|
||||
movdqa 288-128(%rcx),%xmm0
|
||||
paddd %xmm4,%xmm0
|
||||
.byte 15,56,205,236
|
||||
.byte 15,56,203,209
|
||||
pshufd $0x0e,%xmm0,%xmm0
|
||||
movdqa %xmm5,%xmm7
|
||||
.byte 102,15,58,15,252,4
|
||||
nop
|
||||
paddd %xmm7,%xmm6
|
||||
.byte 15,56,204,220
|
||||
.byte 15,56,203,202
|
||||
movdqa 320-128(%rcx),%xmm0
|
||||
paddd %xmm5,%xmm0
|
||||
.byte 15,56,205,245
|
||||
.byte 15,56,203,209
|
||||
pshufd $0x0e,%xmm0,%xmm0
|
||||
movdqa %xmm6,%xmm7
|
||||
.byte 102,15,58,15,253,4
|
||||
nop
|
||||
paddd %xmm7,%xmm3
|
||||
.byte 15,56,204,229
|
||||
.byte 15,56,203,202
|
||||
movdqa 352-128(%rcx),%xmm0
|
||||
paddd %xmm6,%xmm0
|
||||
.byte 15,56,205,222
|
||||
.byte 15,56,203,209
|
||||
pshufd $0x0e,%xmm0,%xmm0
|
||||
movdqa %xmm3,%xmm7
|
||||
.byte 102,15,58,15,254,4
|
||||
nop
|
||||
paddd %xmm7,%xmm4
|
||||
.byte 15,56,204,238
|
||||
.byte 15,56,203,202
|
||||
movdqa 384-128(%rcx),%xmm0
|
||||
paddd %xmm3,%xmm0
|
||||
.byte 15,56,205,227
|
||||
.byte 15,56,203,209
|
||||
pshufd $0x0e,%xmm0,%xmm0
|
||||
movdqa %xmm4,%xmm7
|
||||
.byte 102,15,58,15,251,4
|
||||
nop
|
||||
paddd %xmm7,%xmm5
|
||||
.byte 15,56,204,243
|
||||
.byte 15,56,203,202
|
||||
movdqa 416-128(%rcx),%xmm0
|
||||
paddd %xmm4,%xmm0
|
||||
.byte 15,56,205,236
|
||||
.byte 15,56,203,209
|
||||
pshufd $0x0e,%xmm0,%xmm0
|
||||
movdqa %xmm5,%xmm7
|
||||
.byte 102,15,58,15,252,4
|
||||
.byte 15,56,203,202
|
||||
paddd %xmm7,%xmm6
|
||||
|
||||
movdqa 448-128(%rcx),%xmm0
|
||||
paddd %xmm5,%xmm0
|
||||
.byte 15,56,203,209
|
||||
pshufd $0x0e,%xmm0,%xmm0
|
||||
.byte 15,56,205,245
|
||||
movdqa %xmm8,%xmm7
|
||||
.byte 15,56,203,202
|
||||
|
||||
movdqa 480-128(%rcx),%xmm0
|
||||
paddd %xmm6,%xmm0
|
||||
nop
|
||||
.byte 15,56,203,209
|
||||
pshufd $0x0e,%xmm0,%xmm0
|
||||
decq %rdx
|
||||
nop
|
||||
.byte 15,56,203,202
|
||||
|
||||
paddd %xmm10,%xmm2
|
||||
paddd %xmm9,%xmm1
|
||||
jnz L$oop_shaext
|
||||
|
||||
pshufd $0xb1,%xmm2,%xmm2
|
||||
pshufd $0x1b,%xmm1,%xmm7
|
||||
pshufd $0xb1,%xmm1,%xmm1
|
||||
punpckhqdq %xmm2,%xmm1
|
||||
.byte 102,15,58,15,215,8
|
||||
|
||||
movdqu %xmm1,(%rdi)
|
||||
movdqu %xmm2,16(%rdi)
|
||||
.byte 0xf3,0xc3
|
||||
|
||||
|
||||
|
||||
.p2align 6
|
||||
sha256_block_data_order_ssse3:
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
// This file implements draft-irtf-cfrg-hpke-12.
|
||||
// This file implements RFC 9180.
|
||||
|
||||
#define MAX_SEED_LEN X25519_PRIVATE_KEY_LEN
|
||||
#define MAX_SHARED_SECRET_LEN SHA256_DIGEST_LENGTH
|
||||
@@ -115,7 +115,7 @@ static int hpke_labeled_expand(const EVP_MD *hkdf_md, uint8_t *out_key,
|
||||
// KEM implementations.
|
||||
|
||||
// dhkem_extract_and_expand implements the ExtractAndExpand operation in the
|
||||
// DHKEM construction. See section 4.1 of draft-irtf-cfrg-hpke-12.
|
||||
// DHKEM construction. See section 4.1 of RFC 9180.
|
||||
static int dhkem_extract_and_expand(uint16_t kem_id, const EVP_MD *hkdf_md,
|
||||
uint8_t *out_key, size_t out_len,
|
||||
const uint8_t *dh, size_t dh_len,
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <CCryptoBoringSSL_bn.h>
|
||||
#include <CCryptoBoringSSL_cpu.h>
|
||||
#include <CCryptoBoringSSL_hmac.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_rand.h>
|
||||
@@ -39,8 +38,7 @@
|
||||
#include <emmintrin.h>
|
||||
#endif
|
||||
|
||||
#if (defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)) && \
|
||||
(defined(__ARM_NEON__) || defined(__ARM_NEON))
|
||||
#if (defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)) && defined(__ARM_NEON)
|
||||
#include <arm_neon.h>
|
||||
#endif
|
||||
|
||||
@@ -190,8 +188,7 @@ static inline vec_t vec_broadcast_bit(vec_t a) {
|
||||
// compiler requires that |i| be a compile-time constant.)
|
||||
#define vec_get_word(v, i) _mm_extract_epi16(v, i)
|
||||
|
||||
#elif (defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)) && \
|
||||
(defined(__ARM_NEON__) || defined(__ARM_NEON))
|
||||
#elif (defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)) && defined(__ARM_NEON)
|
||||
|
||||
#define HRSS_HAVE_VECTOR_UNIT
|
||||
typedef uint16x8_t vec_t;
|
||||
@@ -1318,8 +1315,7 @@ static void poly_mul_novec(struct POLY_MUL_SCRATCH *scratch, struct poly *out,
|
||||
static void poly_mul(struct POLY_MUL_SCRATCH *scratch, struct poly *r,
|
||||
const struct poly *a, const struct poly *b) {
|
||||
#if defined(POLY_RQ_MUL_ASM)
|
||||
const int has_avx2 = (OPENSSL_ia32cap_P[2] & (1 << 5)) != 0;
|
||||
if (has_avx2) {
|
||||
if (CRYPTO_is_AVX2_capable()) {
|
||||
poly_Rq_mul(r->v, a->v, b->v, scratch->u.rq);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -121,6 +121,10 @@
|
||||
#include <valgrind/memcheck.h>
|
||||
#endif
|
||||
|
||||
#if defined(BORINGSSL_FIPS_BREAK_TESTS)
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#if !defined(__cplusplus)
|
||||
#if defined(_MSC_VER)
|
||||
#define alignas(x) __declspec(align(x))
|
||||
@@ -932,19 +936,50 @@ static inline uint64_t CRYPTO_rotr_u64(uint64_t value, int shift) {
|
||||
// FIPS functions.
|
||||
|
||||
#if defined(BORINGSSL_FIPS)
|
||||
|
||||
// BORINGSSL_FIPS_abort is called when a FIPS power-on or continuous test
|
||||
// fails. It prevents any further cryptographic operations by the current
|
||||
// process.
|
||||
void BORINGSSL_FIPS_abort(void) __attribute__((noreturn));
|
||||
#endif
|
||||
|
||||
// boringssl_fips_self_test runs the FIPS KAT-based self tests. It returns one
|
||||
// on success and zero on error. The argument is the integrity hash of the FIPS
|
||||
// module and may be used to check and write flag files to suppress duplicate
|
||||
// self-tests. If |module_hash_len| is zero then no flag file will be checked
|
||||
// nor written and tests will always be run.
|
||||
int boringssl_fips_self_test(const uint8_t *module_hash,
|
||||
size_t module_hash_len);
|
||||
// boringssl_self_test_startup runs all startup self tests and returns one on
|
||||
// success or zero on error. Startup self tests do not include lazy tests.
|
||||
// Call |BORINGSSL_self_test| to run every self test.
|
||||
int boringssl_self_test_startup(void);
|
||||
|
||||
// boringssl_ensure_rsa_self_test checks whether the RSA self-test has been run
|
||||
// in this address space. If not, it runs it and crashes the address space if
|
||||
// unsuccessful.
|
||||
void boringssl_ensure_rsa_self_test(void);
|
||||
|
||||
// boringssl_ensure_ecc_self_test checks whether the ECDSA and ECDH self-test
|
||||
// has been run in this address space. If not, it runs it and crashes the
|
||||
// address space if unsuccessful.
|
||||
void boringssl_ensure_ecc_self_test(void);
|
||||
|
||||
// boringssl_ensure_ffdh_self_test checks whether the FFDH self-test has been
|
||||
// run in this address space. If not, it runs it and crashes the address space
|
||||
// if unsuccessful.
|
||||
void boringssl_ensure_ffdh_self_test(void);
|
||||
|
||||
#else
|
||||
|
||||
// Outside of FIPS mode, the lazy tests are no-ops.
|
||||
|
||||
OPENSSL_INLINE void boringssl_ensure_rsa_self_test(void) {}
|
||||
OPENSSL_INLINE void boringssl_ensure_ecc_self_test(void) {}
|
||||
OPENSSL_INLINE void boringssl_ensure_ffdh_self_test(void) {}
|
||||
|
||||
#endif // FIPS
|
||||
|
||||
// boringssl_self_test_sha256 performs a SHA-256 KAT.
|
||||
int boringssl_self_test_sha256(void);
|
||||
|
||||
// boringssl_self_test_sha512 performs a SHA-512 KAT.
|
||||
int boringssl_self_test_sha512(void);
|
||||
|
||||
// boringssl_self_test_hmac_sha256 performs an HMAC-SHA-256 KAT.
|
||||
int boringssl_self_test_hmac_sha256(void);
|
||||
|
||||
#if defined(BORINGSSL_FIPS_COUNTERS)
|
||||
void boringssl_fips_inc_counter(enum fips_counter_t counter);
|
||||
@@ -952,6 +987,260 @@ void boringssl_fips_inc_counter(enum fips_counter_t counter);
|
||||
OPENSSL_INLINE void boringssl_fips_inc_counter(enum fips_counter_t counter) {}
|
||||
#endif
|
||||
|
||||
#if defined(BORINGSSL_FIPS_BREAK_TESTS)
|
||||
OPENSSL_INLINE int boringssl_fips_break_test(const char *test) {
|
||||
const char *const value = getenv("BORINGSSL_FIPS_BREAK_TEST");
|
||||
return value != NULL && strcmp(value, test) == 0;
|
||||
}
|
||||
#else
|
||||
OPENSSL_INLINE int boringssl_fips_break_test(const char *test) {
|
||||
return 0;
|
||||
}
|
||||
#endif // BORINGSSL_FIPS_BREAK_TESTS
|
||||
|
||||
|
||||
// Runtime CPU feature support
|
||||
|
||||
#if defined(OPENSSL_X86) || defined(OPENSSL_X86_64)
|
||||
// OPENSSL_ia32cap_P contains the Intel CPUID bits when running on an x86 or
|
||||
// x86-64 system.
|
||||
//
|
||||
// Index 0:
|
||||
// EDX for CPUID where EAX = 1
|
||||
// Bit 20 is always zero
|
||||
// Bit 28 is adjusted to reflect whether the data cache is shared between
|
||||
// multiple logical cores
|
||||
// Bit 30 is used to indicate an Intel CPU
|
||||
// Index 1:
|
||||
// ECX for CPUID where EAX = 1
|
||||
// Bit 11 is used to indicate AMD XOP support, not SDBG
|
||||
// Index 2:
|
||||
// EBX for CPUID where EAX = 7
|
||||
// Index 3:
|
||||
// ECX for CPUID where EAX = 7
|
||||
//
|
||||
// Note: the CPUID bits are pre-adjusted for the OSXSAVE bit and the YMM and XMM
|
||||
// bits in XCR0, so it is not necessary to check those.
|
||||
extern uint32_t OPENSSL_ia32cap_P[4];
|
||||
|
||||
#if defined(BORINGSSL_FIPS) && !defined(BORINGSSL_SHARED_LIBRARY)
|
||||
// The FIPS module, as a static library, requires an out-of-line version of
|
||||
// |OPENSSL_ia32cap_get| so accesses can be rewritten by delocate. Mark the
|
||||
// function const so multiple accesses can be optimized together.
|
||||
const uint32_t *OPENSSL_ia32cap_get(void) __attribute__((const));
|
||||
#else
|
||||
OPENSSL_INLINE const uint32_t *OPENSSL_ia32cap_get(void) {
|
||||
return OPENSSL_ia32cap_P;
|
||||
}
|
||||
#endif
|
||||
|
||||
// See Intel manual, volume 2A, table 3-11.
|
||||
|
||||
OPENSSL_INLINE int CRYPTO_is_FXSR_capable(void) {
|
||||
#if defined(__FXSR__)
|
||||
return 1;
|
||||
#else
|
||||
return (OPENSSL_ia32cap_get()[0] & (1 << 24)) != 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
OPENSSL_INLINE int CRYPTO_is_intel_cpu(void) {
|
||||
// The reserved bit 30 is used to indicate an Intel CPU.
|
||||
return (OPENSSL_ia32cap_get()[0] & (1 << 30)) != 0;
|
||||
}
|
||||
|
||||
// See Intel manual, volume 2A, table 3-10.
|
||||
|
||||
OPENSSL_INLINE int CRYPTO_is_PCLMUL_capable(void) {
|
||||
#if defined(__PCLMUL__)
|
||||
return 1;
|
||||
#else
|
||||
return (OPENSSL_ia32cap_get()[1] & (1 << 1)) != 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
OPENSSL_INLINE int CRYPTO_is_SSSE3_capable(void) {
|
||||
#if defined(__SSSE3__)
|
||||
return 1;
|
||||
#else
|
||||
return (OPENSSL_ia32cap_get()[1] & (1 << 9)) != 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
OPENSSL_INLINE int CRYPTO_is_SSE4_1_capable(void) {
|
||||
#if defined(__SSE4_1__)
|
||||
return 1;
|
||||
#else
|
||||
return (OPENSSL_ia32cap_P[1] & (1 << 19)) != 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
OPENSSL_INLINE int CRYPTO_is_MOVBE_capable(void) {
|
||||
#if defined(__MOVBE__)
|
||||
return 1;
|
||||
#else
|
||||
return (OPENSSL_ia32cap_get()[1] & (1 << 22)) != 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
OPENSSL_INLINE int CRYPTO_is_AESNI_capable(void) {
|
||||
#if defined(__AES__)
|
||||
return 1;
|
||||
#else
|
||||
return (OPENSSL_ia32cap_get()[1] & (1 << 25)) != 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
OPENSSL_INLINE int CRYPTO_is_AVX_capable(void) {
|
||||
#if defined(__AVX__)
|
||||
return 1;
|
||||
#else
|
||||
return (OPENSSL_ia32cap_get()[1] & (1 << 28)) != 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
OPENSSL_INLINE int CRYPTO_is_RDRAND_capable(void) {
|
||||
// The GCC/Clang feature name and preprocessor symbol for RDRAND are "rdrnd"
|
||||
// and |__RDRND__|, respectively.
|
||||
#if defined(__RDRND__)
|
||||
return 1;
|
||||
#else
|
||||
return (OPENSSL_ia32cap_get()[1] & (1u << 30)) != 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
// See Intel manual, volume 2A, table 3-8.
|
||||
|
||||
OPENSSL_INLINE int CRYPTO_is_BMI1_capable(void) {
|
||||
#if defined(__BMI1__)
|
||||
return 1;
|
||||
#else
|
||||
return (OPENSSL_ia32cap_get()[2] & (1 << 3)) != 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
OPENSSL_INLINE int CRYPTO_is_AVX2_capable(void) {
|
||||
#if defined(__AVX2__)
|
||||
return 1;
|
||||
#else
|
||||
return (OPENSSL_ia32cap_get()[2] & (1 << 5)) != 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
OPENSSL_INLINE int CRYPTO_is_BMI2_capable(void) {
|
||||
#if defined(__BMI2__)
|
||||
return 1;
|
||||
#else
|
||||
return (OPENSSL_ia32cap_get()[2] & (1 << 8)) != 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
OPENSSL_INLINE int CRYPTO_is_ADX_capable(void) {
|
||||
#if defined(__ADX__)
|
||||
return 1;
|
||||
#else
|
||||
return (OPENSSL_ia32cap_get()[2] & (1 << 19)) != 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // OPENSSL_X86 || OPENSSL_X86_64
|
||||
|
||||
#if defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)
|
||||
|
||||
#if defined(OPENSSL_APPLE) && defined(OPENSSL_ARM)
|
||||
// We do not detect any features at runtime for Apple's 32-bit ARM platforms. On
|
||||
// 64-bit ARM, we detect some post-ARMv8.0 features.
|
||||
#define OPENSSL_STATIC_ARMCAP
|
||||
#endif
|
||||
|
||||
// Normalize some older feature flags to their modern ACLE values.
|
||||
// https://developer.arm.com/architectures/system-architectures/software-standards/acle
|
||||
#if defined(__ARM_NEON__) && !defined(__ARM_NEON)
|
||||
#define __ARM_NEON 1
|
||||
#endif
|
||||
#if defined(__ARM_FEATURE_CRYPTO)
|
||||
#if !defined(__ARM_FEATURE_AES)
|
||||
#define __ARM_FEATURE_AES 1
|
||||
#endif
|
||||
#if !defined(__ARM_FEATURE_SHA2)
|
||||
#define __ARM_FEATURE_SHA2 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if !defined(OPENSSL_STATIC_ARMCAP)
|
||||
// CRYPTO_is_NEON_capable_at_runtime returns true if the current CPU has a NEON
|
||||
// unit. Note that |OPENSSL_armcap_P| also exists and contains the same
|
||||
// information in a form that's easier for assembly to use.
|
||||
OPENSSL_EXPORT int CRYPTO_is_NEON_capable_at_runtime(void);
|
||||
|
||||
// CRYPTO_is_ARMv8_AES_capable_at_runtime returns true if the current CPU
|
||||
// supports the ARMv8 AES instruction.
|
||||
int CRYPTO_is_ARMv8_AES_capable_at_runtime(void);
|
||||
|
||||
// CRYPTO_is_ARMv8_PMULL_capable_at_runtime returns true if the current CPU
|
||||
// supports the ARMv8 PMULL instruction.
|
||||
int CRYPTO_is_ARMv8_PMULL_capable_at_runtime(void);
|
||||
#endif // !OPENSSL_STATIC_ARMCAP
|
||||
|
||||
// CRYPTO_is_NEON_capable returns true if the current CPU has a NEON unit. If
|
||||
// this is known statically, it is a constant inline function.
|
||||
OPENSSL_INLINE int CRYPTO_is_NEON_capable(void) {
|
||||
#if defined(OPENSSL_STATIC_ARMCAP_NEON) || defined(__ARM_NEON)
|
||||
return 1;
|
||||
#elif defined(OPENSSL_STATIC_ARMCAP)
|
||||
return 0;
|
||||
#else
|
||||
return CRYPTO_is_NEON_capable_at_runtime();
|
||||
#endif
|
||||
}
|
||||
|
||||
OPENSSL_INLINE int CRYPTO_is_ARMv8_AES_capable(void) {
|
||||
#if defined(OPENSSL_STATIC_ARMCAP_AES) || defined(__ARM_FEATURE_AES)
|
||||
return 1;
|
||||
#elif defined(OPENSSL_STATIC_ARMCAP)
|
||||
return 0;
|
||||
#else
|
||||
return CRYPTO_is_ARMv8_AES_capable_at_runtime();
|
||||
#endif
|
||||
}
|
||||
|
||||
OPENSSL_INLINE int CRYPTO_is_ARMv8_PMULL_capable(void) {
|
||||
#if defined(OPENSSL_STATIC_ARMCAP_PMULL) || defined(__ARM_FEATURE_AES)
|
||||
return 1;
|
||||
#elif defined(OPENSSL_STATIC_ARMCAP)
|
||||
return 0;
|
||||
#else
|
||||
return CRYPTO_is_ARMv8_PMULL_capable_at_runtime();
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // OPENSSL_ARM || OPENSSL_AARCH64
|
||||
|
||||
#if defined(OPENSSL_PPC64LE)
|
||||
|
||||
// CRYPTO_is_PPC64LE_vcrypto_capable returns true iff the current CPU supports
|
||||
// the Vector.AES category of instructions.
|
||||
int CRYPTO_is_PPC64LE_vcrypto_capable(void);
|
||||
|
||||
extern unsigned long OPENSSL_ppc64le_hwcap2;
|
||||
|
||||
#endif // OPENSSL_PPC64LE
|
||||
|
||||
#if defined(BORINGSSL_DISPATCH_TEST)
|
||||
// Runtime CPU dispatch testing support
|
||||
|
||||
// BORINGSSL_function_hit is an array of flags. The following functions will
|
||||
// set these flags if BORINGSSL_DISPATCH_TEST is defined.
|
||||
// 0: aes_hw_ctr32_encrypt_blocks
|
||||
// 1: aes_hw_encrypt
|
||||
// 2: aesni_gcm_encrypt
|
||||
// 3: aes_hw_set_encrypt_key
|
||||
// 4: vpaes_encrypt
|
||||
// 5: vpaes_set_encrypt_key
|
||||
extern uint8_t BORINGSSL_function_hit[7];
|
||||
#endif // BORINGSSL_DISPATCH_TEST
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // extern C
|
||||
#endif
|
||||
|
||||
@@ -132,7 +132,7 @@ static const uint8_t kBoringSSLBinaryTag[18] = {
|
||||
0x8c, 0x62, 0x20, 0x0b, 0xd2, 0xa0, 0x72, 0x58,
|
||||
0x44, 0xa8, 0x96, 0x69, 0xad, 0x55, 0x7e, 0xec,
|
||||
// Current source iteration. Incremented ~monthly.
|
||||
2, 0,
|
||||
3, 0,
|
||||
};
|
||||
|
||||
void *OPENSSL_malloc(size_t size) {
|
||||
|
||||
@@ -200,7 +200,7 @@ DSA *PEM_read_bio_DSAPrivateKey(BIO *bp, DSA **dsa, pem_password_cb *cb,
|
||||
IMPLEMENT_PEM_write_cb_const(DSAPrivateKey, DSA, PEM_STRING_DSA,
|
||||
DSAPrivateKey)
|
||||
|
||||
IMPLEMENT_PEM_rw(DSA_PUBKEY, DSA, PEM_STRING_PUBLIC, DSA_PUBKEY)
|
||||
IMPLEMENT_PEM_rw(DSA_PUBKEY, DSA, PEM_STRING_PUBLIC, DSA_PUBKEY)
|
||||
DSA *PEM_read_DSAPrivateKey(FILE *fp, DSA **dsa, pem_password_cb *cb, void *u)
|
||||
{
|
||||
EVP_PKEY *pktmp;
|
||||
@@ -237,7 +237,7 @@ EC_KEY *PEM_read_bio_ECPrivateKey(BIO *bp, EC_KEY **key, pem_password_cb *cb,
|
||||
IMPLEMENT_PEM_write_cb(ECPrivateKey, EC_KEY, PEM_STRING_ECPRIVATEKEY,
|
||||
ECPrivateKey)
|
||||
|
||||
IMPLEMENT_PEM_rw(EC_PUBKEY, EC_KEY, PEM_STRING_PUBLIC, EC_PUBKEY)
|
||||
IMPLEMENT_PEM_rw(EC_PUBKEY, EC_KEY, PEM_STRING_PUBLIC, EC_PUBKEY)
|
||||
EC_KEY *PEM_read_ECPrivateKey(FILE *fp, EC_KEY **eckey, pem_password_cb *cb,
|
||||
void *u)
|
||||
{
|
||||
@@ -247,6 +247,6 @@ EC_KEY *PEM_read_ECPrivateKey(FILE *fp, EC_KEY **eckey, pem_password_cb *cb,
|
||||
}
|
||||
|
||||
|
||||
IMPLEMENT_PEM_write_const(DHparams, DH, PEM_STRING_DHPARAMS, DHparams)
|
||||
IMPLEMENT_PEM_rw_const(DHparams, DH, PEM_STRING_DHPARAMS, DHparams)
|
||||
|
||||
IMPLEMENT_PEM_rw(PUBKEY, EVP_PKEY, PEM_STRING_PUBLIC, PUBKEY)
|
||||
IMPLEMENT_PEM_rw(PUBKEY, EVP_PKEY, PEM_STRING_PUBLIC, PUBKEY)
|
||||
@@ -176,39 +176,3 @@ int PEM_write_PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
|
||||
BIO_free(b);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* Transparently read in PKCS#3 or X9.42 DH parameters */
|
||||
|
||||
DH *PEM_read_bio_DHparams(BIO *bp, DH **x, pem_password_cb *cb, void *u)
|
||||
{
|
||||
char *nm = NULL;
|
||||
const unsigned char *p = NULL;
|
||||
unsigned char *data = NULL;
|
||||
long len;
|
||||
DH *ret = NULL;
|
||||
|
||||
if (!PEM_bytes_read_bio(&data, &len, &nm, PEM_STRING_DHPARAMS, bp, cb, u))
|
||||
return NULL;
|
||||
p = data;
|
||||
|
||||
ret = d2i_DHparams(x, &p, len);
|
||||
|
||||
if (ret == NULL)
|
||||
OPENSSL_PUT_ERROR(PEM, ERR_R_ASN1_LIB);
|
||||
OPENSSL_free(nm);
|
||||
OPENSSL_free(data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
DH *PEM_read_DHparams(FILE *fp, DH **x, pem_password_cb *cb, void *u)
|
||||
{
|
||||
BIO *b = BIO_new_fp(fp, BIO_NOCLOSE);
|
||||
if (b == NULL) {
|
||||
OPENSSL_PUT_ERROR(PEM, ERR_R_BUF_LIB);
|
||||
return NULL;
|
||||
}
|
||||
DH *ret = PEM_read_bio_DHparams(b, x, cb, u);
|
||||
BIO_free(b);
|
||||
return ret;
|
||||
}
|
||||
@@ -20,8 +20,6 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <CCryptoBoringSSL_cpu.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "../internal.h"
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ struct crypto_buffer_st {
|
||||
struct crypto_buffer_pool_st {
|
||||
LHASH_OF(CRYPTO_BUFFER) *bufs;
|
||||
CRYPTO_MUTEX lock;
|
||||
const uint64_t hash_key[2];
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
|
||||
#include <CCryptoBoringSSL_bytestring.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
#include <CCryptoBoringSSL_rand.h>
|
||||
#include <CCryptoBoringSSL_siphash.h>
|
||||
#include <CCryptoBoringSSL_thread.h>
|
||||
|
||||
#include "../internal.h"
|
||||
@@ -26,10 +28,13 @@
|
||||
|
||||
|
||||
static uint32_t CRYPTO_BUFFER_hash(const CRYPTO_BUFFER *buf) {
|
||||
return OPENSSL_hash32(buf->data, buf->len);
|
||||
return (uint32_t)SIPHASH_24(buf->pool->hash_key, buf->data, buf->len);
|
||||
}
|
||||
|
||||
static int CRYPTO_BUFFER_cmp(const CRYPTO_BUFFER *a, const CRYPTO_BUFFER *b) {
|
||||
// Only |CRYPTO_BUFFER|s from the same pool have compatible hashes.
|
||||
assert(a->pool != NULL);
|
||||
assert(a->pool == b->pool);
|
||||
if (a->len != b->len) {
|
||||
return 1;
|
||||
}
|
||||
@@ -50,6 +55,7 @@ CRYPTO_BUFFER_POOL* CRYPTO_BUFFER_POOL_new(void) {
|
||||
}
|
||||
|
||||
CRYPTO_MUTEX_init(&pool->lock);
|
||||
RAND_bytes((uint8_t *)&pool->hash_key, sizeof(pool->hash_key));
|
||||
|
||||
return pool;
|
||||
}
|
||||
@@ -84,6 +90,7 @@ static CRYPTO_BUFFER *crypto_buffer_new(const uint8_t *data, size_t len,
|
||||
CRYPTO_BUFFER tmp;
|
||||
tmp.data = (uint8_t *) data;
|
||||
tmp.len = len;
|
||||
tmp.pool = pool;
|
||||
|
||||
CRYPTO_MUTEX_lock_read(&pool->lock);
|
||||
CRYPTO_BUFFER *duplicate = lh_CRYPTO_BUFFER_retrieve(pool->bufs, &tmp);
|
||||
|
||||
@@ -438,6 +438,13 @@ static int get_cert_by_subject(X509_LOOKUP *xl, int type, X509_NAME *name,
|
||||
ok = 1;
|
||||
ret->type = tmp->type;
|
||||
OPENSSL_memcpy(&ret->data, &tmp->data, sizeof(ret->data));
|
||||
|
||||
/*
|
||||
* Clear any errors that might have been raised processing empty
|
||||
* or malformed files.
|
||||
*/
|
||||
ERR_clear_error();
|
||||
|
||||
/*
|
||||
* If we were going to up the reference count, we would need
|
||||
* to do it on a perl 'type' basis
|
||||
|
||||
@@ -126,8 +126,6 @@ int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type)
|
||||
int i, count = 0;
|
||||
X509 *x = NULL;
|
||||
|
||||
if (file == NULL)
|
||||
return (1);
|
||||
in = BIO_new(BIO_s_file());
|
||||
|
||||
if ((in == NULL) || (BIO_read_filename(in, file) <= 0)) {
|
||||
@@ -171,6 +169,11 @@ int X509_load_cert_file(X509_LOOKUP *ctx, const char *file, int type)
|
||||
OPENSSL_PUT_ERROR(X509, X509_R_BAD_X509_FILETYPE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
OPENSSL_PUT_ERROR(X509, X509_R_NO_CERTIFICATE_FOUND);
|
||||
}
|
||||
|
||||
err:
|
||||
if (x != NULL)
|
||||
X509_free(x);
|
||||
@@ -186,8 +189,6 @@ int X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type)
|
||||
int i, count = 0;
|
||||
X509_CRL *x = NULL;
|
||||
|
||||
if (file == NULL)
|
||||
return (1);
|
||||
in = BIO_new(BIO_s_file());
|
||||
|
||||
if ((in == NULL) || (BIO_read_filename(in, file) <= 0)) {
|
||||
@@ -231,6 +232,11 @@ int X509_load_crl_file(X509_LOOKUP *ctx, const char *file, int type)
|
||||
OPENSSL_PUT_ERROR(X509, X509_R_BAD_X509_FILETYPE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
OPENSSL_PUT_ERROR(X509, X509_R_NO_CRL_FOUND);
|
||||
}
|
||||
|
||||
err:
|
||||
if (x != NULL)
|
||||
X509_CRL_free(x);
|
||||
@@ -246,6 +252,7 @@ int X509_load_cert_crl_file(X509_LOOKUP *ctx, const char *file, int type)
|
||||
BIO *in;
|
||||
size_t i;
|
||||
int count = 0;
|
||||
|
||||
if (type != X509_FILETYPE_PEM)
|
||||
return X509_load_cert_file(ctx, file, type);
|
||||
in = BIO_new_file(file, "r");
|
||||
@@ -262,14 +269,24 @@ int X509_load_cert_crl_file(X509_LOOKUP *ctx, const char *file, int type)
|
||||
for (i = 0; i < sk_X509_INFO_num(inf); i++) {
|
||||
itmp = sk_X509_INFO_value(inf, i);
|
||||
if (itmp->x509) {
|
||||
X509_STORE_add_cert(ctx->store_ctx, itmp->x509);
|
||||
if (!X509_STORE_add_cert(ctx->store_ctx, itmp->x509)) {
|
||||
goto err;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
if (itmp->crl) {
|
||||
X509_STORE_add_crl(ctx->store_ctx, itmp->crl);
|
||||
if (!X509_STORE_add_crl(ctx->store_ctx, itmp->crl)) {
|
||||
goto err;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
if (count == 0) {
|
||||
OPENSSL_PUT_ERROR(X509, X509_R_NO_CERTIFICATE_OR_CRL_FOUND);
|
||||
}
|
||||
|
||||
err:
|
||||
sk_X509_INFO_pop_free(inf, X509_INFO_free);
|
||||
return count;
|
||||
}
|
||||
|
||||
@@ -106,13 +106,14 @@ struct x509_attributes_st {
|
||||
STACK_OF(ASN1_TYPE) *set;
|
||||
} /* X509_ATTRIBUTE */;
|
||||
|
||||
struct x509_cert_aux_st {
|
||||
typedef struct x509_cert_aux_st {
|
||||
STACK_OF(ASN1_OBJECT) *trust; // trusted uses
|
||||
STACK_OF(ASN1_OBJECT) *reject; // rejected uses
|
||||
ASN1_UTF8STRING *alias; // "friendly name"
|
||||
ASN1_OCTET_STRING *keyid; // key id of private key
|
||||
STACK_OF(X509_ALGOR) *other; // other unspecified info
|
||||
} /* X509_CERT_AUX */;
|
||||
} X509_CERT_AUX;
|
||||
|
||||
DECLARE_ASN1_FUNCTIONS(X509_CERT_AUX)
|
||||
|
||||
struct X509_extension_st {
|
||||
ASN1_OBJECT *object;
|
||||
@@ -370,6 +371,8 @@ struct x509_store_ctx_st {
|
||||
|
||||
ASN1_TYPE *ASN1_generate_v3(const char *str, X509V3_CTX *cnf);
|
||||
|
||||
int X509_CERT_AUX_print(BIO *bp, X509_CERT_AUX *x, int indent);
|
||||
|
||||
|
||||
/* RSA-PSS functions. */
|
||||
|
||||
|
||||
@@ -134,13 +134,12 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags,
|
||||
}
|
||||
|
||||
const ASN1_INTEGER *serial = X509_get0_serialNumber(x);
|
||||
/* |ASN1_INTEGER_get| returns -1 on overflow, so this check skips
|
||||
* negative and large serial numbers. */
|
||||
l = ASN1_INTEGER_get(serial);
|
||||
if (l >= 0) {
|
||||
uint64_t serial_u64;
|
||||
if (ASN1_INTEGER_get_uint64(&serial_u64, serial)) {
|
||||
assert(serial->type != V_ASN1_NEG_INTEGER);
|
||||
if (BIO_printf(bp, " %ld (0x%lx)\n", l, (unsigned long)l) <= 0) {
|
||||
goto err;
|
||||
if (BIO_printf(bp, " %" PRIu64 " (0x%" PRIx64 ")\n", serial_u64,
|
||||
serial_u64) <= 0) {
|
||||
goto err;
|
||||
}
|
||||
} else {
|
||||
neg = (serial->type == V_ASN1_NEG_INTEGER) ? " (Negative)" : "";
|
||||
|
||||
@@ -332,76 +332,54 @@ int X509_STORE_get_by_subject(X509_STORE_CTX *vs, int type, X509_NAME *name,
|
||||
return 1;
|
||||
}
|
||||
|
||||
int X509_STORE_add_cert(X509_STORE *ctx, X509 *x)
|
||||
static int x509_store_add(X509_STORE *ctx, void *x, int is_crl)
|
||||
{
|
||||
X509_OBJECT *obj;
|
||||
int ret = 1;
|
||||
|
||||
if (x == NULL)
|
||||
if (x == NULL) {
|
||||
return 0;
|
||||
obj = (X509_OBJECT *)OPENSSL_malloc(sizeof(X509_OBJECT));
|
||||
}
|
||||
|
||||
X509_OBJECT *const obj = (X509_OBJECT *)OPENSSL_malloc(sizeof(X509_OBJECT));
|
||||
if (obj == NULL) {
|
||||
OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
obj->type = X509_LU_X509;
|
||||
obj->data.x509 = x;
|
||||
|
||||
if (is_crl) {
|
||||
obj->type = X509_LU_CRL;
|
||||
obj->data.crl = (X509_CRL *)x;
|
||||
} else {
|
||||
obj->type = X509_LU_X509;
|
||||
obj->data.x509 = (X509 *)x;
|
||||
}
|
||||
X509_OBJECT_up_ref_count(obj);
|
||||
|
||||
CRYPTO_MUTEX_lock_write(&ctx->objs_lock);
|
||||
|
||||
X509_OBJECT_up_ref_count(obj);
|
||||
|
||||
if (X509_OBJECT_retrieve_match(ctx->objs, obj)) {
|
||||
X509_OBJECT_free_contents(obj);
|
||||
OPENSSL_free(obj);
|
||||
OPENSSL_PUT_ERROR(X509, X509_R_CERT_ALREADY_IN_HASH_TABLE);
|
||||
ret = 0;
|
||||
} else if (!sk_X509_OBJECT_push(ctx->objs, obj)) {
|
||||
X509_OBJECT_free_contents(obj);
|
||||
OPENSSL_free(obj);
|
||||
OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
|
||||
ret = 0;
|
||||
int ret = 1;
|
||||
int added = 0;
|
||||
/* Duplicates are silently ignored */
|
||||
if (!X509_OBJECT_retrieve_match(ctx->objs, obj)) {
|
||||
ret = added = (sk_X509_OBJECT_push(ctx->objs, obj) != 0);
|
||||
}
|
||||
|
||||
CRYPTO_MUTEX_unlock_write(&ctx->objs_lock);
|
||||
|
||||
if (!added) {
|
||||
X509_OBJECT_free_contents(obj);
|
||||
OPENSSL_free(obj);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int X509_STORE_add_cert(X509_STORE *ctx, X509 *x)
|
||||
{
|
||||
return x509_store_add(ctx, x, /*is_crl=*/0);
|
||||
}
|
||||
|
||||
int X509_STORE_add_crl(X509_STORE *ctx, X509_CRL *x)
|
||||
{
|
||||
X509_OBJECT *obj;
|
||||
int ret = 1;
|
||||
|
||||
if (x == NULL)
|
||||
return 0;
|
||||
obj = (X509_OBJECT *)OPENSSL_malloc(sizeof(X509_OBJECT));
|
||||
if (obj == NULL) {
|
||||
OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
obj->type = X509_LU_CRL;
|
||||
obj->data.crl = x;
|
||||
|
||||
CRYPTO_MUTEX_lock_write(&ctx->objs_lock);
|
||||
|
||||
X509_OBJECT_up_ref_count(obj);
|
||||
|
||||
if (X509_OBJECT_retrieve_match(ctx->objs, obj)) {
|
||||
X509_OBJECT_free_contents(obj);
|
||||
OPENSSL_free(obj);
|
||||
OPENSSL_PUT_ERROR(X509, X509_R_CERT_ALREADY_IN_HASH_TABLE);
|
||||
ret = 0;
|
||||
} else if (!sk_X509_OBJECT_push(ctx->objs, obj)) {
|
||||
X509_OBJECT_free_contents(obj);
|
||||
OPENSSL_free(obj);
|
||||
OPENSSL_PUT_ERROR(X509, ERR_R_MALLOC_FAILURE);
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
CRYPTO_MUTEX_unlock_write(&ctx->objs_lock);
|
||||
|
||||
return ret;
|
||||
return x509_store_add(ctx, x, /*is_crl=*/1);
|
||||
}
|
||||
|
||||
int X509_OBJECT_up_ref_count(X509_OBJECT *a)
|
||||
|
||||
@@ -78,7 +78,6 @@ ASN1_SEQUENCE(X509_CERT_AUX) = {
|
||||
ASN1_IMP_SEQUENCE_OF_OPT(X509_CERT_AUX, reject, ASN1_OBJECT, 0),
|
||||
ASN1_OPT(X509_CERT_AUX, alias, ASN1_UTF8STRING),
|
||||
ASN1_OPT(X509_CERT_AUX, keyid, ASN1_OCTET_STRING),
|
||||
ASN1_IMP_SEQUENCE_OF_OPT(X509_CERT_AUX, other, X509_ALGOR, 1)
|
||||
} ASN1_SEQUENCE_END(X509_CERT_AUX)
|
||||
|
||||
IMPLEMENT_ASN1_FUNCTIONS(X509_CERT_AUX)
|
||||
@@ -95,6 +94,9 @@ static X509_CERT_AUX *aux_get(X509 *x)
|
||||
int X509_alias_set1(X509 *x, const unsigned char *name, int len)
|
||||
{
|
||||
X509_CERT_AUX *aux;
|
||||
/* TODO(davidben): Empty aliases are not meaningful in PKCS#12, and the
|
||||
* getters cannot quite represent them. Also erase the object if |len| is
|
||||
* zero. */
|
||||
if (!name) {
|
||||
if (!x || !x->aux || !x->aux->alias)
|
||||
return 1;
|
||||
@@ -112,6 +114,9 @@ int X509_alias_set1(X509 *x, const unsigned char *name, int len)
|
||||
int X509_keyid_set1(X509 *x, const unsigned char *id, int len)
|
||||
{
|
||||
X509_CERT_AUX *aux;
|
||||
/* TODO(davidben): Empty key IDs are not meaningful in PKCS#12, and the
|
||||
* getters cannot quite represent them. Also erase the object if |len| is
|
||||
* zero. */
|
||||
if (!id) {
|
||||
if (!x || !x->aux || !x->aux->keyid)
|
||||
return 1;
|
||||
@@ -126,22 +131,22 @@ int X509_keyid_set1(X509 *x, const unsigned char *id, int len)
|
||||
return ASN1_STRING_set(aux->keyid, id, len);
|
||||
}
|
||||
|
||||
unsigned char *X509_alias_get0(X509 *x, int *len)
|
||||
unsigned char *X509_alias_get0(X509 *x, int *out_len)
|
||||
{
|
||||
if (!x->aux || !x->aux->alias)
|
||||
return NULL;
|
||||
if (len)
|
||||
*len = x->aux->alias->length;
|
||||
return x->aux->alias->data;
|
||||
const ASN1_UTF8STRING *alias = x->aux != NULL ? x->aux->alias : NULL;
|
||||
if (out_len != NULL) {
|
||||
*out_len = alias != NULL ? alias->length : 0;
|
||||
}
|
||||
return alias != NULL ? alias->data : NULL;
|
||||
}
|
||||
|
||||
unsigned char *X509_keyid_get0(X509 *x, int *len)
|
||||
unsigned char *X509_keyid_get0(X509 *x, int *out_len)
|
||||
{
|
||||
if (!x->aux || !x->aux->keyid)
|
||||
return NULL;
|
||||
if (len)
|
||||
*len = x->aux->keyid->length;
|
||||
return x->aux->keyid->data;
|
||||
const ASN1_OCTET_STRING *keyid = x->aux != NULL ? x->aux->keyid : NULL;
|
||||
if (out_len != NULL) {
|
||||
*out_len = keyid != NULL ? keyid->length : 0;
|
||||
}
|
||||
return keyid != NULL ? keyid->data : NULL;
|
||||
}
|
||||
|
||||
int X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj)
|
||||
|
||||
@@ -70,21 +70,21 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
// x509v3_bytes_to_hex encodes |len| bytes from |buffer| to hex and returns a
|
||||
// x509v3_bytes_to_hex encodes |len| bytes from |in| to hex and returns a
|
||||
// newly-allocated NUL-terminated string containing the result, or NULL on
|
||||
// allocation error.
|
||||
//
|
||||
// Note this function was historically named |hex_to_string| in OpenSSL, not
|
||||
// |string_to_hex|.
|
||||
char *x509v3_bytes_to_hex(const unsigned char *buffer, long len);
|
||||
// This function was historically named |hex_to_string| in OpenSSL. Despite the
|
||||
// name, |hex_to_string| converted to hex.
|
||||
OPENSSL_EXPORT char *x509v3_bytes_to_hex(const uint8_t *in, size_t len);
|
||||
|
||||
// x509v3_hex_string_to_bytes decodes |str| in hex and returns a newly-allocated
|
||||
// array containing the result, or NULL on error. On success, it sets |*len| to
|
||||
// the length of the result. Colon separators between bytes in the input are
|
||||
// allowed and ignored.
|
||||
//
|
||||
// Note this function was historically named |string_to_hex| in OpenSSL, not
|
||||
// |hex_to_string|.
|
||||
// This function was historically named |string_to_hex| in OpenSSL. Despite the
|
||||
// name, |string_to_hex| converted from hex.
|
||||
unsigned char *x509v3_hex_to_bytes(const char *str, long *len);
|
||||
|
||||
// x509v3_name_cmp returns zero if |name| is equal to |cmp| or begins with |cmp|
|
||||
|
||||
@@ -93,10 +93,10 @@ static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
|
||||
STACK_OF(CONF_VALUE)
|
||||
*extlist)
|
||||
{
|
||||
char *tmp = NULL;
|
||||
int extlist_was_null = extlist == NULL;
|
||||
if (akeyid->keyid) {
|
||||
tmp = x509v3_bytes_to_hex(akeyid->keyid->data, akeyid->keyid->length);
|
||||
char *tmp = x509v3_bytes_to_hex(akeyid->keyid->data,
|
||||
akeyid->keyid->length);
|
||||
int ok = tmp != NULL && X509V3_add_value("keyid", tmp, &extlist);
|
||||
OPENSSL_free(tmp);
|
||||
if (!ok) {
|
||||
@@ -112,10 +112,7 @@ static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
|
||||
extlist = tmpextlist;
|
||||
}
|
||||
if (akeyid->serial) {
|
||||
tmp = x509v3_bytes_to_hex(akeyid->serial->data, akeyid->serial->length);
|
||||
int ok = tmp != NULL && X509V3_add_value("serial", tmp, &extlist);
|
||||
OPENSSL_free(tmp);
|
||||
if (!ok) {
|
||||
if (!X509V3_add_value_int("serial", akeyid->serial, &extlist)) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +63,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include <CCryptoBoringSSL_bn.h>
|
||||
#include <CCryptoBoringSSL_bytestring.h>
|
||||
#include <CCryptoBoringSSL_conf.h>
|
||||
#include <CCryptoBoringSSL_err.h>
|
||||
#include <CCryptoBoringSSL_mem.h>
|
||||
@@ -467,33 +468,33 @@ static char *strip_spaces(char *name)
|
||||
|
||||
/* hex string utilities */
|
||||
|
||||
/*
|
||||
* Given a buffer of length 'len' return a OPENSSL_malloc'ed string with its
|
||||
* hex representation @@@ (Contents of buffer are always kept in ASCII, also
|
||||
* on EBCDIC machines)
|
||||
*/
|
||||
|
||||
char *x509v3_bytes_to_hex(const unsigned char *buffer, long len)
|
||||
char *x509v3_bytes_to_hex(const uint8_t *in, size_t len)
|
||||
{
|
||||
char *tmp, *q;
|
||||
const unsigned char *p;
|
||||
int i;
|
||||
static const char hexdig[] = "0123456789ABCDEF";
|
||||
if (!buffer || !len)
|
||||
return NULL;
|
||||
if (!(tmp = OPENSSL_malloc(len * 3 + 1))) {
|
||||
OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
|
||||
return NULL;
|
||||
CBB cbb;
|
||||
if (!CBB_init(&cbb, len * 3 + 1)) {
|
||||
goto err;
|
||||
}
|
||||
q = tmp;
|
||||
for (i = 0, p = buffer; i < len; i++, p++) {
|
||||
*q++ = hexdig[(*p >> 4) & 0xf];
|
||||
*q++ = hexdig[*p & 0xf];
|
||||
*q++ = ':';
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
static const char hex[] = "0123456789ABCDEF";
|
||||
if ((i > 0 && !CBB_add_u8(&cbb, ':')) ||
|
||||
!CBB_add_u8(&cbb, hex[in[i] >> 4]) ||
|
||||
!CBB_add_u8(&cbb, hex[in[i] & 0xf])) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
uint8_t *ret;
|
||||
size_t unused_len;
|
||||
if (!CBB_add_u8(&cbb, 0) ||
|
||||
!CBB_finish(&cbb, &ret, &unused_len)) {
|
||||
goto err;
|
||||
}
|
||||
q[-1] = 0;
|
||||
|
||||
return tmp;
|
||||
return (char *)ret;
|
||||
|
||||
err:
|
||||
OPENSSL_PUT_ERROR(X509V3, ERR_R_MALLOC_FAILURE);
|
||||
CBB_cleanup(&cbb);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
unsigned char *x509v3_hex_to_bytes(const char *str, long *len)
|
||||
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
This directory is derived from BoringSSL cloned from https://boringssl.googlesource.com/boringssl at revision 295b31324f8c557dcd3c1c831857e33a7f23bc52
|
||||
This directory is derived from BoringSSL cloned from https://boringssl.googlesource.com/boringssl at revision 8bbefbfeee609b17622deedd100163c12f5c95dc
|
||||
@@ -50,58 +50,15 @@
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com). */
|
||||
|
||||
#if __arm__ || __arm64__ || __aarch64__
|
||||
#ifndef OPENSSL_HEADER_ARM_ARCH_H
|
||||
#define OPENSSL_HEADER_ARM_ARCH_H
|
||||
|
||||
#if !defined(__ARM_ARCH__)
|
||||
# if defined(__CC_ARM)
|
||||
# define __ARM_ARCH__ __TARGET_ARCH_ARM
|
||||
# if defined(__BIG_ENDIAN)
|
||||
# define __ARMEB__
|
||||
# else
|
||||
# define __ARMEL__
|
||||
# endif
|
||||
# elif defined(__GNUC__)
|
||||
# if defined(__aarch64__)
|
||||
# define __ARM_ARCH__ 8
|
||||
# if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
||||
# define __ARMEB__
|
||||
# else
|
||||
# define __ARMEL__
|
||||
# endif
|
||||
// Why doesn't gcc define __ARM_ARCH__? Instead it defines
|
||||
// bunch of below macros. See all_architectires[] table in
|
||||
// gcc/config/arm/arm.c. On a side note it defines
|
||||
// __ARMEL__/__ARMEB__ for little-/big-endian.
|
||||
# elif defined(__ARM_ARCH)
|
||||
# define __ARM_ARCH__ __ARM_ARCH
|
||||
# elif defined(__ARM_ARCH_8A__)
|
||||
# define __ARM_ARCH__ 8
|
||||
# elif defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || \
|
||||
defined(__ARM_ARCH_7R__)|| defined(__ARM_ARCH_7M__) || \
|
||||
defined(__ARM_ARCH_7EM__)
|
||||
# define __ARM_ARCH__ 7
|
||||
# elif defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || \
|
||||
defined(__ARM_ARCH_6K__)|| defined(__ARM_ARCH_6M__) || \
|
||||
defined(__ARM_ARCH_6Z__)|| defined(__ARM_ARCH_6ZK__) || \
|
||||
defined(__ARM_ARCH_6T2__)
|
||||
# define __ARM_ARCH__ 6
|
||||
# elif defined(__ARM_ARCH_5__) || defined(__ARM_ARCH_5T__) || \
|
||||
defined(__ARM_ARCH_5E__)|| defined(__ARM_ARCH_5TE__) || \
|
||||
defined(__ARM_ARCH_5TEJ__)
|
||||
# define __ARM_ARCH__ 5
|
||||
# elif defined(__ARM_ARCH_4__) || defined(__ARM_ARCH_4T__)
|
||||
# define __ARM_ARCH__ 4
|
||||
# else
|
||||
# error "unsupported ARM architecture"
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
// arm_arch.h contains symbols used by ARM assembly, and the C code that calls
|
||||
// it. It is included as a public header to simplify the build, but is not
|
||||
// intended for external use.
|
||||
|
||||
// Even when building for 32-bit ARM, support for aarch64 crypto instructions
|
||||
// will be included.
|
||||
#define __ARM_MAX_ARCH__ 8
|
||||
#if defined(__ARMEL__) || defined(_M_ARM) || defined(__AARCH64EL__) || \
|
||||
defined(_M_ARM64)
|
||||
|
||||
// ARMV7_NEON is true when a NEON unit is present in the current CPU.
|
||||
#define ARMV7_NEON (1 << 0)
|
||||
@@ -123,6 +80,23 @@
|
||||
|
||||
#if defined(__ASSEMBLER__)
|
||||
|
||||
// We require the ARM assembler provide |__ARM_ARCH| from Arm C Language
|
||||
// Extensions (ACLE). This is supported in GCC 4.8+ and Clang 3.2+. MSVC does
|
||||
// not implement ACLE, but we require Clang's assembler on Windows.
|
||||
#if !defined(__ARM_ARCH)
|
||||
#error "ARM assembler must define __ARM_ARCH"
|
||||
#endif
|
||||
|
||||
// __ARM_ARCH__ is used by OpenSSL assembly to determine the minimum target ARM
|
||||
// version.
|
||||
//
|
||||
// TODO(davidben): Switch the assembly to use |__ARM_ARCH| directly.
|
||||
#define __ARM_ARCH__ __ARM_ARCH
|
||||
|
||||
// Even when building for 32-bit ARM, support for aarch64 crypto instructions
|
||||
// will be included.
|
||||
#define __ARM_MAX_ARCH__ 8
|
||||
|
||||
// Support macros for
|
||||
// - Armv8.3-A Pointer Authentication and
|
||||
// - Armv8.5-A Branch Target Identification
|
||||
@@ -239,7 +213,8 @@
|
||||
.popsection;
|
||||
#endif
|
||||
|
||||
#endif /* defined __ASSEMBLER__ */
|
||||
#endif // __ASSEMBLER__
|
||||
|
||||
#endif // __ARMEL__ || _M_ARM || __AARCH64EL__ || _M_ARM64
|
||||
|
||||
#endif // OPENSSL_HEADER_ARM_ARCH_H
|
||||
#endif // __arm__ || __arm64__ || __aarch64__
|
||||
@@ -605,7 +605,9 @@ OPENSSL_EXPORT int ASN1_STRING_length(const ASN1_STRING *str);
|
||||
OPENSSL_EXPORT int ASN1_STRING_cmp(const ASN1_STRING *a, const ASN1_STRING *b);
|
||||
|
||||
// ASN1_STRING_set sets the contents of |str| to a copy of |len| bytes from
|
||||
// |data|. It returns one on success and zero on error.
|
||||
// |data|. It returns one on success and zero on error. If |data| is NULL, it
|
||||
// updates the length and allocates the buffer as needed, but does not
|
||||
// initialize the contents.
|
||||
OPENSSL_EXPORT int ASN1_STRING_set(ASN1_STRING *str, const void *data, int len);
|
||||
|
||||
// ASN1_STRING_set0 sets the contents of |str| to |len| bytes from |data|. It
|
||||
@@ -1014,6 +1016,12 @@ OPENSSL_EXPORT int ASN1_BIT_STRING_check(const ASN1_BIT_STRING *str,
|
||||
// |V_ASN1_INTEGER| or |V_ASN1_ENUMERATED|, while negative values have a type of
|
||||
// |V_ASN1_NEG_INTEGER| or |V_ASN1_NEG_ENUMERATED|. Note this differs from DER's
|
||||
// two's complement representation.
|
||||
//
|
||||
// The data in the |ASN1_STRING| may not have leading zeros. Note this means
|
||||
// zero is represented as the empty string. Parsing functions will never return
|
||||
// invalid representations. If an invalid input is constructed, the marshaling
|
||||
// functions will skip leading zeros, however other functions, such as
|
||||
// |ASN1_INTEGER_cmp| or |ASN1_INTEGER_get|, may not return the correct result.
|
||||
|
||||
DEFINE_STACK_OF(ASN1_INTEGER)
|
||||
|
||||
@@ -1068,16 +1076,25 @@ OPENSSL_EXPORT int i2c_ASN1_INTEGER(const ASN1_INTEGER *in, uint8_t **outp);
|
||||
// |ASN1_INTEGER*|.
|
||||
DECLARE_ASN1_ITEM(ASN1_INTEGER)
|
||||
|
||||
// ASN1_INTEGER_set sets |a| to an INTEGER with value |v|. It returns one on
|
||||
// success and zero on error.
|
||||
OPENSSL_EXPORT int ASN1_INTEGER_set(ASN1_INTEGER *a, long v);
|
||||
|
||||
// ASN1_INTEGER_set_uint64 sets |a| to an INTEGER with value |v|. It returns one
|
||||
// on success and zero on error.
|
||||
OPENSSL_EXPORT int ASN1_INTEGER_set_uint64(ASN1_INTEGER *out, uint64_t v);
|
||||
|
||||
// ASN1_INTEGER_set sets |a| to an INTEGER with value |v|. It returns one on
|
||||
// success and zero on error.
|
||||
OPENSSL_EXPORT int ASN1_INTEGER_set(ASN1_INTEGER *a, long v);
|
||||
|
||||
// ASN1_INTEGER_get_uint64 converts |a| to a |uint64_t|. On success, it returns
|
||||
// one and sets |*out| to the result. If |a| did not fit or has the wrong type,
|
||||
// it returns zero.
|
||||
OPENSSL_EXPORT int ASN1_INTEGER_get_uint64(uint64_t *out,
|
||||
const ASN1_INTEGER *a);
|
||||
|
||||
// ASN1_INTEGER_get returns the value of |a| as a |long|, or -1 if |a| is out of
|
||||
// range or the wrong type.
|
||||
//
|
||||
// WARNING: This function's return value cannot distinguish errors from -1.
|
||||
// Prefer |ASN1_INTEGER_get_uint64|.
|
||||
OPENSSL_EXPORT long ASN1_INTEGER_get(const ASN1_INTEGER *a);
|
||||
|
||||
// BN_to_ASN1_INTEGER sets |ai| to an INTEGER with value |bn| and returns |ai|
|
||||
@@ -1123,18 +1140,31 @@ OPENSSL_EXPORT int i2d_ASN1_ENUMERATED(const ASN1_ENUMERATED *in,
|
||||
// |ASN1_ENUMERATED*|.
|
||||
DECLARE_ASN1_ITEM(ASN1_ENUMERATED)
|
||||
|
||||
// ASN1_ENUMERATED_set_uint64 sets |a| to an ENUMERATED with value |v|. It
|
||||
// returns one on success and zero on error.
|
||||
OPENSSL_EXPORT int ASN1_ENUMERATED_set_uint64(ASN1_ENUMERATED *out, uint64_t v);
|
||||
|
||||
// ASN1_ENUMERATED_set sets |a| to an ENUMERATED with value |v|. It returns one
|
||||
// on success and zero on error.
|
||||
OPENSSL_EXPORT int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v);
|
||||
|
||||
// ASN1_ENUMERATED_get_uint64 converts |a| to a |uint64_t|. On success, it
|
||||
// returns one and sets |*out| to the result. If |a| did not fit or has the
|
||||
// wrong type, it returns zero.
|
||||
OPENSSL_EXPORT int ASN1_ENUMERATED_get_uint64(uint64_t *out,
|
||||
const ASN1_ENUMERATED *a);
|
||||
|
||||
// ASN1_ENUMERATED_get returns the value of |a| as a |long|, or -1 if |a| is out
|
||||
// of range or the wrong type.
|
||||
//
|
||||
// WARNING: This function's return value cannot distinguish errors from -1.
|
||||
// Prefer |ASN1_ENUMERATED_get_uint64|.
|
||||
OPENSSL_EXPORT long ASN1_ENUMERATED_get(const ASN1_ENUMERATED *a);
|
||||
|
||||
// BN_to_ASN1_ENUMERATED sets |ai| to an ENUMERATED with value |bn| and returns
|
||||
// |ai| on success or NULL or error. If |ai| is NULL, it returns a
|
||||
// newly-allocated |ASN1_INTEGER| on success instead, which the caller must
|
||||
// release with |ASN1_INTEGER_free|.
|
||||
// newly-allocated |ASN1_ENUMERATED| on success instead, which the caller must
|
||||
// release with |ASN1_ENUMERATED_free|.
|
||||
OPENSSL_EXPORT ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(const BIGNUM *bn,
|
||||
ASN1_ENUMERATED *ai);
|
||||
|
||||
@@ -2035,5 +2065,7 @@ BSSL_NAMESPACE_END
|
||||
#define ASN1_R_NESTED_TOO_DEEP 192
|
||||
#define ASN1_R_BAD_TEMPLATE 193
|
||||
#define ASN1_R_INVALID_BIT_STRING_PADDING 194
|
||||
#define ASN1_R_WRONG_INTEGER_TYPE 195
|
||||
#define ASN1_R_INVALID_INTEGER 196
|
||||
|
||||
#endif
|
||||
@@ -260,7 +260,6 @@ typedef struct ASN1_TLC_st ASN1_TLC;
|
||||
/* Any defined by macros: the field used is in the table itself */
|
||||
|
||||
#define ASN1_ADB_OBJECT(tblname) { ASN1_TFLG_ADB_OID, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) }
|
||||
#define ASN1_ADB_INTEGER(tblname) { ASN1_TFLG_ADB_INT, -1, 0, #tblname, (const ASN1_ITEM *)&(tblname##_adb) }
|
||||
/* Plain simple type */
|
||||
#define ASN1_SIMPLE(stname, field, type) ASN1_EX_TYPE(0,0, stname, field, type)
|
||||
|
||||
@@ -377,7 +376,7 @@ struct ASN1_ADB_st {
|
||||
};
|
||||
|
||||
struct ASN1_ADB_TABLE_st {
|
||||
long value; /* NID for an object or value for an int */
|
||||
int value; /* NID for an object */
|
||||
const ASN1_TEMPLATE tt; /* item for this value */
|
||||
};
|
||||
|
||||
@@ -442,8 +441,6 @@ struct ASN1_ADB_TABLE_st {
|
||||
|
||||
#define ASN1_TFLG_ADB_OID (0x1<<8)
|
||||
|
||||
#define ASN1_TFLG_ADB_INT (0x1<<9)
|
||||
|
||||
/* This flag means a parent structure is passed
|
||||
* instead of the field: this is useful is a
|
||||
* SEQUENCE is being combined with a CHOICE for
|
||||
|
||||
@@ -203,7 +203,7 @@ extern "C" {
|
||||
// A consumer may use this symbol in the preprocessor to temporarily build
|
||||
// against multiple revisions of BoringSSL at the same time. It is not
|
||||
// recommended to do so for longer than is necessary.
|
||||
#define BORINGSSL_API_VERSION 16
|
||||
#define BORINGSSL_API_VERSION 17
|
||||
|
||||
#if defined(BORINGSSL_SHARED_LIBRARY)
|
||||
|
||||
@@ -456,7 +456,6 @@ typedef struct trust_token_issuer_st TRUST_TOKEN_ISSUER;
|
||||
typedef struct trust_token_method_st TRUST_TOKEN_METHOD;
|
||||
typedef struct v3_ext_ctx X509V3_CTX;
|
||||
typedef struct x509_attributes_st X509_ATTRIBUTE;
|
||||
typedef struct x509_cert_aux_st X509_CERT_AUX;
|
||||
typedef struct x509_crl_method_st X509_CRL_METHOD;
|
||||
typedef struct x509_lookup_st X509_LOOKUP;
|
||||
typedef struct x509_lookup_method_st X509_LOOKUP_METHOD;
|
||||
|
||||
@@ -126,6 +126,7 @@
|
||||
#include "CCryptoBoringSSL_base.h"
|
||||
#include "CCryptoBoringSSL_thread.h"
|
||||
|
||||
#include <inttypes.h> // for PRIu64 and friends
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h> // for FILE*
|
||||
|
||||
@@ -148,14 +149,14 @@ extern "C" {
|
||||
// Projects which use |BN_*_FMT*| with outdated C headers may need to define it
|
||||
// externally.
|
||||
#if defined(OPENSSL_64_BIT)
|
||||
#define BN_ULONG uint64_t
|
||||
typedef uint64_t BN_ULONG;
|
||||
#define BN_BITS2 64
|
||||
#define BN_DEC_FMT1 "%" PRIu64
|
||||
#define BN_DEC_FMT2 "%019" PRIu64
|
||||
#define BN_HEX_FMT1 "%" PRIx64
|
||||
#define BN_HEX_FMT2 "%016" PRIx64
|
||||
#elif defined(OPENSSL_32_BIT)
|
||||
#define BN_ULONG uint32_t
|
||||
typedef uint32_t BN_ULONG;
|
||||
#define BN_BITS2 32
|
||||
#define BN_DEC_FMT1 "%" PRIu32
|
||||
#define BN_DEC_FMT2 "%09" PRIu32
|
||||
@@ -584,9 +585,14 @@ OPENSSL_EXPORT int BN_mod_lshift1_quick(BIGNUM *r, const BIGNUM *a,
|
||||
const BIGNUM *m);
|
||||
|
||||
// BN_mod_sqrt returns a newly-allocated |BIGNUM|, r, such that
|
||||
// r^2 == a (mod p). |p| must be a prime. It returns NULL on error or if |a| is
|
||||
// not a square mod |p|. In the latter case, it will add |BN_R_NOT_A_SQUARE| to
|
||||
// the error queue.
|
||||
// r^2 == a (mod p). It returns NULL on error or if |a| is not a square mod |p|.
|
||||
// In the latter case, it will add |BN_R_NOT_A_SQUARE| to the error queue.
|
||||
// If |a| is a square and |p| > 2, there are two possible square roots. This
|
||||
// function may return either and may even select one non-deterministically.
|
||||
//
|
||||
// This function only works if |p| is a prime. If |p| is composite, it may fail
|
||||
// or return an arbitrary value. Callers should not pass attacker-controlled
|
||||
// values of |p|.
|
||||
OPENSSL_EXPORT BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p,
|
||||
BN_CTX *ctx);
|
||||
|
||||
|
||||
@@ -49,9 +49,11 @@
|
||||
#define ASN1_BOOLEAN_it BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_BOOLEAN_it)
|
||||
#define ASN1_ENUMERATED_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_ENUMERATED_free)
|
||||
#define ASN1_ENUMERATED_get BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_ENUMERATED_get)
|
||||
#define ASN1_ENUMERATED_get_uint64 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_ENUMERATED_get_uint64)
|
||||
#define ASN1_ENUMERATED_it BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_ENUMERATED_it)
|
||||
#define ASN1_ENUMERATED_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_ENUMERATED_new)
|
||||
#define ASN1_ENUMERATED_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_ENUMERATED_set)
|
||||
#define ASN1_ENUMERATED_set_uint64 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_ENUMERATED_set_uint64)
|
||||
#define ASN1_ENUMERATED_to_BN BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_ENUMERATED_to_BN)
|
||||
#define ASN1_FBOOLEAN_it BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_FBOOLEAN_it)
|
||||
#define ASN1_GENERALIZEDTIME_adj BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_GENERALIZEDTIME_adj)
|
||||
@@ -72,6 +74,7 @@
|
||||
#define ASN1_INTEGER_dup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_INTEGER_dup)
|
||||
#define ASN1_INTEGER_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_INTEGER_free)
|
||||
#define ASN1_INTEGER_get BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_INTEGER_get)
|
||||
#define ASN1_INTEGER_get_uint64 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_INTEGER_get_uint64)
|
||||
#define ASN1_INTEGER_it BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_INTEGER_it)
|
||||
#define ASN1_INTEGER_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_INTEGER_new)
|
||||
#define ASN1_INTEGER_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ASN1_INTEGER_set)
|
||||
@@ -994,6 +997,7 @@
|
||||
#define EVP_HPKE_KEY_public_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_HPKE_KEY_public_key)
|
||||
#define EVP_HPKE_KEY_zero BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_HPKE_KEY_zero)
|
||||
#define EVP_MD_CTX_block_size BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_MD_CTX_block_size)
|
||||
#define EVP_MD_CTX_cleanse BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_MD_CTX_cleanse)
|
||||
#define EVP_MD_CTX_cleanup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_MD_CTX_cleanup)
|
||||
#define EVP_MD_CTX_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_MD_CTX_copy)
|
||||
#define EVP_MD_CTX_copy_ex BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_MD_CTX_copy_ex)
|
||||
@@ -1196,7 +1200,9 @@
|
||||
#define EXTENDED_KEY_USAGE_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EXTENDED_KEY_USAGE_new)
|
||||
#define FIPS_mode BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, FIPS_mode)
|
||||
#define FIPS_mode_set BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, FIPS_mode_set)
|
||||
#define FIPS_query_algorithm_status BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, FIPS_query_algorithm_status)
|
||||
#define FIPS_read_counter BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, FIPS_read_counter)
|
||||
#define FIPS_version BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, FIPS_version)
|
||||
#define GENERAL_NAMES_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, GENERAL_NAMES_free)
|
||||
#define GENERAL_NAMES_it BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, GENERAL_NAMES_it)
|
||||
#define GENERAL_NAMES_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, GENERAL_NAMES_new)
|
||||
@@ -1217,6 +1223,7 @@
|
||||
#define HKDF_expand BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, HKDF_expand)
|
||||
#define HKDF_extract BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, HKDF_extract)
|
||||
#define HMAC BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, HMAC)
|
||||
#define HMAC_CTX_cleanse BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, HMAC_CTX_cleanse)
|
||||
#define HMAC_CTX_cleanup BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, HMAC_CTX_cleanup)
|
||||
#define HMAC_CTX_copy BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, HMAC_CTX_copy)
|
||||
#define HMAC_CTX_copy_ex BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, HMAC_CTX_copy_ex)
|
||||
@@ -2317,7 +2324,9 @@
|
||||
#define bn_uadd_consttime BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_uadd_consttime)
|
||||
#define bn_usub_consttime BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_usub_consttime)
|
||||
#define bn_wexpand BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, bn_wexpand)
|
||||
#define boringssl_fips_self_test BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, boringssl_fips_self_test)
|
||||
#define boringssl_self_test_hmac_sha256 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, boringssl_self_test_hmac_sha256)
|
||||
#define boringssl_self_test_sha256 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, boringssl_self_test_sha256)
|
||||
#define boringssl_self_test_sha512 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, boringssl_self_test_sha512)
|
||||
#define c2i_ASN1_BIT_STRING BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, c2i_ASN1_BIT_STRING)
|
||||
#define c2i_ASN1_INTEGER BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, c2i_ASN1_INTEGER)
|
||||
#define c2i_ASN1_OBJECT BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, c2i_ASN1_OBJECT)
|
||||
@@ -2453,6 +2462,7 @@
|
||||
#define d2i_X509_VAL BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_X509_VAL)
|
||||
#define d2i_X509_bio BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_X509_bio)
|
||||
#define d2i_X509_fp BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, d2i_X509_fp)
|
||||
#define dh_compute_key_padded_no_self_test BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, dh_compute_key_padded_no_self_test)
|
||||
#define dsa_asn1_meth BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, dsa_asn1_meth)
|
||||
#define dsa_check_parameters BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, dsa_check_parameters)
|
||||
#define ec_GFp_mont_add BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_GFp_mont_add)
|
||||
@@ -2512,6 +2522,7 @@
|
||||
#define ec_jacobian_to_affine_batch BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_jacobian_to_affine_batch)
|
||||
#define ec_pkey_meth BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_pkey_meth)
|
||||
#define ec_point_from_uncompressed BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_point_from_uncompressed)
|
||||
#define ec_point_mul_no_self_test BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_point_mul_no_self_test)
|
||||
#define ec_point_mul_scalar BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_point_mul_scalar)
|
||||
#define ec_point_mul_scalar_base BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_point_mul_scalar_base)
|
||||
#define ec_point_mul_scalar_batch BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_point_mul_scalar_batch)
|
||||
@@ -2540,6 +2551,7 @@
|
||||
#define ec_set_to_safe_point BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_set_to_safe_point)
|
||||
#define ec_simple_scalar_inv0_montgomery BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_simple_scalar_inv0_montgomery)
|
||||
#define ec_simple_scalar_to_montgomery_inv_vartime BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ec_simple_scalar_to_montgomery_inv_vartime)
|
||||
#define ecdsa_do_verify_no_self_test BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ecdsa_do_verify_no_self_test)
|
||||
#define ecdsa_sign_with_nonce_for_known_answer_test BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ecdsa_sign_with_nonce_for_known_answer_test)
|
||||
#define ecp_nistz256_avx2_select_w7 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ecp_nistz256_avx2_select_w7)
|
||||
#define ecp_nistz256_mul_mont BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ecp_nistz256_mul_mont)
|
||||
@@ -2766,6 +2778,9 @@
|
||||
#define rsa_default_sign_raw BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, rsa_default_sign_raw)
|
||||
#define rsa_default_size BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, rsa_default_size)
|
||||
#define rsa_pkey_meth BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, rsa_pkey_meth)
|
||||
#define rsa_sign_no_self_test BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, rsa_sign_no_self_test)
|
||||
#define rsa_verify_no_self_test BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, rsa_verify_no_self_test)
|
||||
#define rsa_verify_raw_no_self_test BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, rsa_verify_raw_no_self_test)
|
||||
#define rsaz_1024_gather5_avx2 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, rsaz_1024_gather5_avx2)
|
||||
#define rsaz_1024_mul_avx2 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, rsaz_1024_mul_avx2)
|
||||
#define rsaz_1024_norm2red_avx2 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, rsaz_1024_norm2red_avx2)
|
||||
|
||||
@@ -54,9 +54,11 @@
|
||||
#define _ASN1_BOOLEAN_it BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_BOOLEAN_it)
|
||||
#define _ASN1_ENUMERATED_free BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_ENUMERATED_free)
|
||||
#define _ASN1_ENUMERATED_get BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_ENUMERATED_get)
|
||||
#define _ASN1_ENUMERATED_get_uint64 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_ENUMERATED_get_uint64)
|
||||
#define _ASN1_ENUMERATED_it BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_ENUMERATED_it)
|
||||
#define _ASN1_ENUMERATED_new BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_ENUMERATED_new)
|
||||
#define _ASN1_ENUMERATED_set BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_ENUMERATED_set)
|
||||
#define _ASN1_ENUMERATED_set_uint64 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_ENUMERATED_set_uint64)
|
||||
#define _ASN1_ENUMERATED_to_BN BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_ENUMERATED_to_BN)
|
||||
#define _ASN1_FBOOLEAN_it BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_FBOOLEAN_it)
|
||||
#define _ASN1_GENERALIZEDTIME_adj BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_GENERALIZEDTIME_adj)
|
||||
@@ -77,6 +79,7 @@
|
||||
#define _ASN1_INTEGER_dup BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_INTEGER_dup)
|
||||
#define _ASN1_INTEGER_free BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_INTEGER_free)
|
||||
#define _ASN1_INTEGER_get BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_INTEGER_get)
|
||||
#define _ASN1_INTEGER_get_uint64 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_INTEGER_get_uint64)
|
||||
#define _ASN1_INTEGER_it BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_INTEGER_it)
|
||||
#define _ASN1_INTEGER_new BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_INTEGER_new)
|
||||
#define _ASN1_INTEGER_set BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ASN1_INTEGER_set)
|
||||
@@ -999,6 +1002,7 @@
|
||||
#define _EVP_HPKE_KEY_public_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_HPKE_KEY_public_key)
|
||||
#define _EVP_HPKE_KEY_zero BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_HPKE_KEY_zero)
|
||||
#define _EVP_MD_CTX_block_size BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_MD_CTX_block_size)
|
||||
#define _EVP_MD_CTX_cleanse BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_MD_CTX_cleanse)
|
||||
#define _EVP_MD_CTX_cleanup BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_MD_CTX_cleanup)
|
||||
#define _EVP_MD_CTX_copy BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_MD_CTX_copy)
|
||||
#define _EVP_MD_CTX_copy_ex BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_MD_CTX_copy_ex)
|
||||
@@ -1201,7 +1205,9 @@
|
||||
#define _EXTENDED_KEY_USAGE_new BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EXTENDED_KEY_USAGE_new)
|
||||
#define _FIPS_mode BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, FIPS_mode)
|
||||
#define _FIPS_mode_set BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, FIPS_mode_set)
|
||||
#define _FIPS_query_algorithm_status BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, FIPS_query_algorithm_status)
|
||||
#define _FIPS_read_counter BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, FIPS_read_counter)
|
||||
#define _FIPS_version BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, FIPS_version)
|
||||
#define _GENERAL_NAMES_free BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, GENERAL_NAMES_free)
|
||||
#define _GENERAL_NAMES_it BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, GENERAL_NAMES_it)
|
||||
#define _GENERAL_NAMES_new BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, GENERAL_NAMES_new)
|
||||
@@ -1222,6 +1228,7 @@
|
||||
#define _HKDF_expand BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, HKDF_expand)
|
||||
#define _HKDF_extract BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, HKDF_extract)
|
||||
#define _HMAC BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, HMAC)
|
||||
#define _HMAC_CTX_cleanse BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, HMAC_CTX_cleanse)
|
||||
#define _HMAC_CTX_cleanup BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, HMAC_CTX_cleanup)
|
||||
#define _HMAC_CTX_copy BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, HMAC_CTX_copy)
|
||||
#define _HMAC_CTX_copy_ex BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, HMAC_CTX_copy_ex)
|
||||
@@ -2322,7 +2329,9 @@
|
||||
#define _bn_uadd_consttime BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_uadd_consttime)
|
||||
#define _bn_usub_consttime BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_usub_consttime)
|
||||
#define _bn_wexpand BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, bn_wexpand)
|
||||
#define _boringssl_fips_self_test BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, boringssl_fips_self_test)
|
||||
#define _boringssl_self_test_hmac_sha256 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, boringssl_self_test_hmac_sha256)
|
||||
#define _boringssl_self_test_sha256 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, boringssl_self_test_sha256)
|
||||
#define _boringssl_self_test_sha512 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, boringssl_self_test_sha512)
|
||||
#define _c2i_ASN1_BIT_STRING BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, c2i_ASN1_BIT_STRING)
|
||||
#define _c2i_ASN1_INTEGER BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, c2i_ASN1_INTEGER)
|
||||
#define _c2i_ASN1_OBJECT BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, c2i_ASN1_OBJECT)
|
||||
@@ -2458,6 +2467,7 @@
|
||||
#define _d2i_X509_VAL BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_X509_VAL)
|
||||
#define _d2i_X509_bio BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_X509_bio)
|
||||
#define _d2i_X509_fp BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, d2i_X509_fp)
|
||||
#define _dh_compute_key_padded_no_self_test BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, dh_compute_key_padded_no_self_test)
|
||||
#define _dsa_asn1_meth BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, dsa_asn1_meth)
|
||||
#define _dsa_check_parameters BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, dsa_check_parameters)
|
||||
#define _ec_GFp_mont_add BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_GFp_mont_add)
|
||||
@@ -2517,6 +2527,7 @@
|
||||
#define _ec_jacobian_to_affine_batch BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_jacobian_to_affine_batch)
|
||||
#define _ec_pkey_meth BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_pkey_meth)
|
||||
#define _ec_point_from_uncompressed BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_point_from_uncompressed)
|
||||
#define _ec_point_mul_no_self_test BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_point_mul_no_self_test)
|
||||
#define _ec_point_mul_scalar BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_point_mul_scalar)
|
||||
#define _ec_point_mul_scalar_base BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_point_mul_scalar_base)
|
||||
#define _ec_point_mul_scalar_batch BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_point_mul_scalar_batch)
|
||||
@@ -2545,6 +2556,7 @@
|
||||
#define _ec_set_to_safe_point BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_set_to_safe_point)
|
||||
#define _ec_simple_scalar_inv0_montgomery BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_simple_scalar_inv0_montgomery)
|
||||
#define _ec_simple_scalar_to_montgomery_inv_vartime BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ec_simple_scalar_to_montgomery_inv_vartime)
|
||||
#define _ecdsa_do_verify_no_self_test BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ecdsa_do_verify_no_self_test)
|
||||
#define _ecdsa_sign_with_nonce_for_known_answer_test BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ecdsa_sign_with_nonce_for_known_answer_test)
|
||||
#define _ecp_nistz256_avx2_select_w7 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ecp_nistz256_avx2_select_w7)
|
||||
#define _ecp_nistz256_mul_mont BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, ecp_nistz256_mul_mont)
|
||||
@@ -2771,6 +2783,9 @@
|
||||
#define _rsa_default_sign_raw BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, rsa_default_sign_raw)
|
||||
#define _rsa_default_size BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, rsa_default_size)
|
||||
#define _rsa_pkey_meth BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, rsa_pkey_meth)
|
||||
#define _rsa_sign_no_self_test BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, rsa_sign_no_self_test)
|
||||
#define _rsa_verify_no_self_test BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, rsa_verify_no_self_test)
|
||||
#define _rsa_verify_raw_no_self_test BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, rsa_verify_raw_no_self_test)
|
||||
#define _rsaz_1024_gather5_avx2 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, rsaz_1024_gather5_avx2)
|
||||
#define _rsaz_1024_mul_avx2 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, rsaz_1024_mul_avx2)
|
||||
#define _rsaz_1024_norm2red_avx2 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, rsaz_1024_norm2red_avx2)
|
||||
|
||||
@@ -259,15 +259,17 @@ OPENSSL_EXPORT int CBS_get_any_asn1_element(CBS *cbs, CBS *out,
|
||||
|
||||
// CBS_get_any_ber_asn1_element acts the same as |CBS_get_any_asn1_element| but
|
||||
// also allows indefinite-length elements to be returned and does not enforce
|
||||
// that lengths are minimal. For indefinite-lengths, |*out_header_len| and
|
||||
// that lengths are minimal. It sets |*out_indefinite| to one if the length was
|
||||
// indefinite and zero otherwise. If indefinite, |*out_header_len| and
|
||||
// |CBS_len(out)| will be equal as only the header is returned (although this is
|
||||
// also true for empty elements so the length must be checked too). If
|
||||
// also true for empty elements so |*out_indefinite| should be checked). If
|
||||
// |out_ber_found| is not NULL then it is set to one if any case of invalid DER
|
||||
// but valid BER is found, and to zero otherwise.
|
||||
OPENSSL_EXPORT int CBS_get_any_ber_asn1_element(CBS *cbs, CBS *out,
|
||||
unsigned *out_tag,
|
||||
size_t *out_header_len,
|
||||
int *out_ber_found);
|
||||
int *out_ber_found,
|
||||
int *out_indefinite);
|
||||
|
||||
// CBS_get_asn1_uint64 gets an ASN.1 INTEGER from |cbs| using |CBS_get_asn1|
|
||||
// and sets |*out| to its value. It returns one on success and zero on error,
|
||||
|
||||
@@ -1,203 +1,18 @@
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
/* Copyright (c) 2014, Google Inc.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
* 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.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*
|
||||
* This product includes cryptographic software written by Eric Young
|
||||
* (eay@cryptsoft.com). This product includes software written by Tim
|
||||
* Hudson (tjh@cryptsoft.com). */
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
#ifndef OPENSSL_HEADER_CPU_H
|
||||
#define OPENSSL_HEADER_CPU_H
|
||||
// This header is provided for compatibility with older revisions of BoringSSL.
|
||||
// TODO(davidben): Remove this header.
|
||||
|
||||
#include "CCryptoBoringSSL_base.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
// Runtime CPU feature support
|
||||
|
||||
|
||||
#if defined(OPENSSL_X86) || defined(OPENSSL_X86_64)
|
||||
// OPENSSL_ia32cap_P contains the Intel CPUID bits when running on an x86 or
|
||||
// x86-64 system.
|
||||
//
|
||||
// Index 0:
|
||||
// EDX for CPUID where EAX = 1
|
||||
// Bit 20 is always zero
|
||||
// Bit 28 is adjusted to reflect whether the data cache is shared between
|
||||
// multiple logical cores
|
||||
// Bit 30 is used to indicate an Intel CPU
|
||||
// Index 1:
|
||||
// ECX for CPUID where EAX = 1
|
||||
// Bit 11 is used to indicate AMD XOP support, not SDBG
|
||||
// Index 2:
|
||||
// EBX for CPUID where EAX = 7
|
||||
// Index 3:
|
||||
// ECX for CPUID where EAX = 7
|
||||
//
|
||||
// Note: the CPUID bits are pre-adjusted for the OSXSAVE bit and the YMM and XMM
|
||||
// bits in XCR0, so it is not necessary to check those.
|
||||
extern uint32_t OPENSSL_ia32cap_P[4];
|
||||
|
||||
#if defined(BORINGSSL_FIPS) && !defined(BORINGSSL_SHARED_LIBRARY)
|
||||
const uint32_t *OPENSSL_ia32cap_get(void);
|
||||
#else
|
||||
OPENSSL_INLINE const uint32_t *OPENSSL_ia32cap_get(void) {
|
||||
return OPENSSL_ia32cap_P;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)
|
||||
|
||||
#if defined(OPENSSL_APPLE) && defined(OPENSSL_ARM)
|
||||
// We do not detect any features at runtime for Apple's 32-bit ARM platforms. On
|
||||
// 64-bit ARM, we detect some post-ARMv8.0 features.
|
||||
#define OPENSSL_STATIC_ARMCAP
|
||||
#endif
|
||||
|
||||
#if !defined(OPENSSL_STATIC_ARMCAP)
|
||||
// CRYPTO_is_NEON_capable_at_runtime returns true if the current CPU has a NEON
|
||||
// unit. Note that |OPENSSL_armcap_P| also exists and contains the same
|
||||
// information in a form that's easier for assembly to use.
|
||||
OPENSSL_EXPORT int CRYPTO_is_NEON_capable_at_runtime(void);
|
||||
|
||||
// CRYPTO_is_ARMv8_AES_capable_at_runtime returns true if the current CPU
|
||||
// supports the ARMv8 AES instruction.
|
||||
int CRYPTO_is_ARMv8_AES_capable_at_runtime(void);
|
||||
|
||||
// CRYPTO_is_ARMv8_PMULL_capable_at_runtime returns true if the current CPU
|
||||
// supports the ARMv8 PMULL instruction.
|
||||
int CRYPTO_is_ARMv8_PMULL_capable_at_runtime(void);
|
||||
|
||||
#if defined(OPENSSL_ARM)
|
||||
// CRYPTO_has_broken_NEON returns one if the current CPU is known to have a
|
||||
// broken NEON unit. See https://crbug.com/341598.
|
||||
OPENSSL_EXPORT int CRYPTO_has_broken_NEON(void);
|
||||
|
||||
// CRYPTO_needs_hwcap2_workaround returns one if the ARMv8 AArch32 AT_HWCAP2
|
||||
// workaround was needed. See https://crbug.com/boringssl/46.
|
||||
OPENSSL_EXPORT int CRYPTO_needs_hwcap2_workaround(void);
|
||||
#endif
|
||||
#endif // !OPENSSL_STATIC_ARMCAP
|
||||
|
||||
// CRYPTO_is_NEON_capable returns true if the current CPU has a NEON unit. If
|
||||
// this is known statically, it is a constant inline function.
|
||||
OPENSSL_INLINE int CRYPTO_is_NEON_capable(void) {
|
||||
#if defined(__ARM_NEON__) || defined(__ARM_NEON) || \
|
||||
defined(OPENSSL_STATIC_ARMCAP_NEON)
|
||||
return 1;
|
||||
#elif defined(OPENSSL_STATIC_ARMCAP)
|
||||
return 0;
|
||||
#else
|
||||
return CRYPTO_is_NEON_capable_at_runtime();
|
||||
#endif
|
||||
}
|
||||
|
||||
OPENSSL_INLINE int CRYPTO_is_ARMv8_AES_capable(void) {
|
||||
#if defined(OPENSSL_STATIC_ARMCAP_AES) || defined(__ARM_FEATURE_CRYPTO)
|
||||
return 1;
|
||||
#elif defined(OPENSSL_STATIC_ARMCAP)
|
||||
return 0;
|
||||
#else
|
||||
return CRYPTO_is_ARMv8_AES_capable_at_runtime();
|
||||
#endif
|
||||
}
|
||||
|
||||
OPENSSL_INLINE int CRYPTO_is_ARMv8_PMULL_capable(void) {
|
||||
#if defined(OPENSSL_STATIC_ARMCAP_PMULL) || defined(__ARM_FEATURE_CRYPTO)
|
||||
return 1;
|
||||
#elif defined(OPENSSL_STATIC_ARMCAP)
|
||||
return 0;
|
||||
#else
|
||||
return CRYPTO_is_ARMv8_PMULL_capable_at_runtime();
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // OPENSSL_ARM || OPENSSL_AARCH64
|
||||
|
||||
#if defined(OPENSSL_PPC64LE)
|
||||
|
||||
// CRYPTO_is_PPC64LE_vcrypto_capable returns true iff the current CPU supports
|
||||
// the Vector.AES category of instructions.
|
||||
int CRYPTO_is_PPC64LE_vcrypto_capable(void);
|
||||
|
||||
extern unsigned long OPENSSL_ppc64le_hwcap2;
|
||||
|
||||
#endif // OPENSSL_PPC64LE
|
||||
|
||||
#if defined(BORINGSSL_DISPATCH_TEST)
|
||||
// Runtime CPU dispatch testing support
|
||||
|
||||
// BORINGSSL_function_hit is an array of flags. The following functions will
|
||||
// set these flags if BORINGSSL_DISPATCH_TEST is defined.
|
||||
// 0: aes_hw_ctr32_encrypt_blocks
|
||||
// 1: aes_hw_encrypt
|
||||
// 2: aesni_gcm_encrypt
|
||||
// 3: aes_hw_set_encrypt_key
|
||||
// 4: vpaes_encrypt
|
||||
// 5: vpaes_set_encrypt_key
|
||||
extern uint8_t BORINGSSL_function_hit[7];
|
||||
#endif // BORINGSSL_DISPATCH_TEST
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // extern C
|
||||
#endif
|
||||
|
||||
#endif // OPENSSL_HEADER_CPU_H
|
||||
#include "CCryptoBoringSSL_crypto.h"
|
||||
@@ -59,6 +59,12 @@ OPENSSL_EXPORT int CRYPTO_has_asm(void);
|
||||
// success and zero on error.
|
||||
OPENSSL_EXPORT int BORINGSSL_self_test(void);
|
||||
|
||||
// BORINGSSL_integrity_test triggers the module's integrity test where the code
|
||||
// and data of the module is matched against a hash injected at build time. It
|
||||
// returns one on success or zero if there's a mismatch. This function only
|
||||
// exists if the module was built in FIPS mode without ASAN.
|
||||
OPENSSL_EXPORT int BORINGSSL_integrity_test(void);
|
||||
|
||||
// CRYPTO_pre_sandbox_init initializes the crypto library, pre-acquiring some
|
||||
// unusual resources to aid running in sandboxed environments. It is safe to
|
||||
// call this function multiple times and concurrently from multiple threads.
|
||||
@@ -67,6 +73,17 @@ OPENSSL_EXPORT int BORINGSSL_self_test(void);
|
||||
// SANDBOXING.md in the source tree.
|
||||
OPENSSL_EXPORT void CRYPTO_pre_sandbox_init(void);
|
||||
|
||||
#if defined(OPENSSL_ARM) && defined(OPENSSL_LINUX) && \
|
||||
!defined(OPENSSL_STATIC_ARMCAP)
|
||||
// CRYPTO_has_broken_NEON returns one if the current CPU is known to have a
|
||||
// broken NEON unit. See https://crbug.com/341598.
|
||||
OPENSSL_EXPORT int CRYPTO_has_broken_NEON(void);
|
||||
|
||||
// CRYPTO_needs_hwcap2_workaround returns one if the ARMv8 AArch32 AT_HWCAP2
|
||||
// workaround was needed. See https://crbug.com/boringssl/46.
|
||||
OPENSSL_EXPORT int CRYPTO_needs_hwcap2_workaround(void);
|
||||
#endif // OPENSSL_ARM && OPENSSL_LINUX && !OPENSSL_STATIC_ARMCAP
|
||||
|
||||
|
||||
// FIPS monitoring
|
||||
|
||||
@@ -161,6 +178,18 @@ OPENSSL_EXPORT void OPENSSL_cleanup(void);
|
||||
// |BORINGSSL_FIPS| and zero otherwise.
|
||||
OPENSSL_EXPORT int FIPS_mode_set(int on);
|
||||
|
||||
// FIPS_version returns the version of the FIPS module, or zero if the build
|
||||
// isn't exactly at a verified version. The version, expressed in base 10, will
|
||||
// be a date in the form yyyymmddXX where XX is often "00", but can be
|
||||
// incremented if multiple versions are defined on a single day.
|
||||
//
|
||||
// (This format exceeds a |uint32_t| in the year 4294.)
|
||||
OPENSSL_EXPORT uint32_t FIPS_version(void);
|
||||
|
||||
// FIPS_query_algorithm_status returns one if |algorithm| is FIPS validated in
|
||||
// the current BoringSSL and zero otherwise.
|
||||
OPENSSL_EXPORT int FIPS_query_algorithm_status(const char *algorithm);
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // extern C
|
||||
|
||||
@@ -117,6 +117,13 @@ OPENSSL_EXPORT EVP_MD_CTX *EVP_MD_CTX_new(void);
|
||||
// freshly initialised state. It does not free |ctx| itself. It returns one.
|
||||
OPENSSL_EXPORT int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx);
|
||||
|
||||
// EVP_MD_CTX_cleanse zeros the digest state in |ctx| and then performs the
|
||||
// actions of |EVP_MD_CTX_cleanup|. Note that some |EVP_MD_CTX| objects contain
|
||||
// more than just a digest (e.g. those resulting from |EVP_DigestSignInit|) but
|
||||
// this function does not zero out more than just the digest state even in that
|
||||
// case.
|
||||
OPENSSL_EXPORT void EVP_MD_CTX_cleanse(EVP_MD_CTX *ctx);
|
||||
|
||||
// EVP_MD_CTX_free calls |EVP_MD_CTX_cleanup| and then frees |ctx| itself.
|
||||
OPENSSL_EXPORT void EVP_MD_CTX_free(EVP_MD_CTX *ctx);
|
||||
|
||||
|
||||
@@ -323,7 +323,15 @@ OPENSSL_EXPORT int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r,
|
||||
// |EC_GROUP_cmp| (even to themselves). |EC_GROUP_get_curve_name| will always
|
||||
// return |NID_undef|.
|
||||
//
|
||||
// Avoid using arbitrary curves and use |EC_GROUP_new_by_curve_name| instead.
|
||||
// This function is provided for compatibility with some legacy applications
|
||||
// only. Avoid using arbitrary curves and use |EC_GROUP_new_by_curve_name|
|
||||
// instead. This ensures the result meets preconditions necessary for
|
||||
// elliptic curve algorithms to function correctly and securely.
|
||||
//
|
||||
// Given invalid parameters, this function may fail or it may return an
|
||||
// |EC_GROUP| which breaks these preconditions. Subsequent operations may then
|
||||
// return arbitrary, incorrect values. Callers should not pass
|
||||
// attacker-controlled values to this function.
|
||||
OPENSSL_EXPORT EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p,
|
||||
const BIGNUM *a,
|
||||
const BIGNUM *b, BN_CTX *ctx);
|
||||
|
||||
@@ -167,8 +167,9 @@ OPENSSL_EXPORT void EC_KEY_set_conv_form(EC_KEY *key,
|
||||
// about the problem can be found on the error stack.
|
||||
OPENSSL_EXPORT int EC_KEY_check_key(const EC_KEY *key);
|
||||
|
||||
// EC_KEY_check_fips performs a signing pairwise consistency test (FIPS 140-2
|
||||
// 4.9.2). It returns one if it passes and zero otherwise.
|
||||
// EC_KEY_check_fips performs both a signing pairwise consistency test
|
||||
// (FIPS 140-2 4.9.2) and the consistency test from SP 800-56Ar3 section
|
||||
// 5.6.2.1.4. It returns one if it passes and zero otherwise.
|
||||
OPENSSL_EXPORT int EC_KEY_check_fips(const EC_KEY *key);
|
||||
|
||||
// EC_KEY_set_public_key_affine_coordinates sets the public key in |key| to
|
||||
@@ -194,7 +195,9 @@ OPENSSL_EXPORT size_t EC_KEY_key2buf(const EC_KEY *key,
|
||||
OPENSSL_EXPORT int EC_KEY_generate_key(EC_KEY *key);
|
||||
|
||||
// EC_KEY_generate_key_fips behaves like |EC_KEY_generate_key| but performs
|
||||
// additional checks for FIPS compliance.
|
||||
// additional checks for FIPS compliance. This function is applicable when
|
||||
// generating keys for either signing/verification or key agreement because
|
||||
// both types of consistency check (PCT) are performed.
|
||||
OPENSSL_EXPORT int EC_KEY_generate_key_fips(EC_KEY *key);
|
||||
|
||||
// EC_KEY_derive_from_secret deterministically derives a private key for |group|
|
||||
|
||||
@@ -98,6 +98,10 @@ OPENSSL_EXPORT HMAC_CTX *HMAC_CTX_new(void);
|
||||
// HMAC_CTX_cleanup frees data owned by |ctx|. It does not free |ctx| itself.
|
||||
OPENSSL_EXPORT void HMAC_CTX_cleanup(HMAC_CTX *ctx);
|
||||
|
||||
// HMAC_CTX_cleanse zeros the digest state from |ctx| and then performs the
|
||||
// actions of |HMAC_CTX_cleanup|.
|
||||
OPENSSL_EXPORT void HMAC_CTX_cleanse(HMAC_CTX *ctx);
|
||||
|
||||
// HMAC_CTX_free calls |HMAC_CTX_cleanup| and then frees |ctx| itself.
|
||||
OPENSSL_EXPORT void HMAC_CTX_free(HMAC_CTX *ctx);
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ extern "C" {
|
||||
// Hybrid Public Key Encryption (HPKE) enables a sender to encrypt messages to a
|
||||
// receiver with a public key.
|
||||
//
|
||||
// See https://tools.ietf.org/html/draft-irtf-cfrg-hpke-12.
|
||||
// See RFC 9180.
|
||||
|
||||
|
||||
// Parameters.
|
||||
|
||||
@@ -77,14 +77,13 @@ typedef struct crypto_mutex_st {
|
||||
typedef union crypto_mutex_st {
|
||||
void *handle;
|
||||
} CRYPTO_MUTEX;
|
||||
#elif defined(__MACH__) && defined(__APPLE__)
|
||||
#elif !defined(__GLIBC__)
|
||||
typedef pthread_rwlock_t CRYPTO_MUTEX;
|
||||
#else
|
||||
// It is reasonable to include pthread.h on non-Windows systems, however the
|
||||
// |pthread_rwlock_t| that we need is hidden under feature flags, and we can't
|
||||
// ensure that we'll be able to get it. It's statically asserted that this
|
||||
// structure is large enough to contain a |pthread_rwlock_t| by
|
||||
// thread_pthread.c.
|
||||
// On glibc, |pthread_rwlock_t| is hidden under feature flags, and we can't
|
||||
// ensure that we'll be able to get it from a public header. It's statically
|
||||
// asserted that this structure is large enough to contain a |pthread_rwlock_t|
|
||||
// by thread_pthread.c.
|
||||
typedef union crypto_mutex_st {
|
||||
double alignment;
|
||||
uint8_t padding[3*sizeof(int) + 5*sizeof(unsigned) + 16 + 8];
|
||||
|
||||
Loaded 100 of 108 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user