mirror of
https://github.com/apple/swift-nio-ssl
synced 2026-11-27 05:04:24 +00:00
Update BoringSSL to df75139becd7355e117c9860452265b898b49376. (#261)
This commit is contained in:
1 parent
c585b79ac0
commit
62bf5083df
53 files changed
+5767
-5276
No files matched your search
+1
-1
@@ -22,7 +22,7 @@ import PackageDescription
|
||||
// Sources/CNIOBoringSSL directory. The source repository is at
|
||||
// https://boringssl.googlesource.com/boringssl.
|
||||
//
|
||||
// BoringSSL Commit: 4a265be4d931e35f0d108040c94d37bb49827948
|
||||
// BoringSSL Commit: df75139becd7355e117c9860452265b898b49376
|
||||
|
||||
let package = Package(
|
||||
name: "swift-nio-ssl",
|
||||
|
||||
@@ -223,6 +223,15 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_MSTRING:
|
||||
/*
|
||||
* It never makes sense for multi-strings to have implicit tagging, so
|
||||
* if tag != -1, then this looks like an error in the template.
|
||||
*/
|
||||
if (tag != -1) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
p = *in;
|
||||
/* Just read in tag and class */
|
||||
ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, NULL,
|
||||
@@ -256,6 +265,15 @@ static int asn1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in,
|
||||
return ef->asn1_ex_d2i(pval, in, len, it, tag, aclass, opt, ctx);
|
||||
|
||||
case ASN1_ITYPE_CHOICE:
|
||||
/*
|
||||
* It never makes sense for CHOICE types to have implicit tagging, so if
|
||||
* tag != -1, then this looks like an error in the template.
|
||||
*/
|
||||
if (tag != -1) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it, NULL))
|
||||
goto auxerr;
|
||||
|
||||
|
||||
@@ -145,9 +145,25 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
|
||||
break;
|
||||
|
||||
case ASN1_ITYPE_MSTRING:
|
||||
/*
|
||||
* It never makes sense for multi-strings to have implicit tagging, so
|
||||
* if tag != -1, then this looks like an error in the template.
|
||||
*/
|
||||
if (tag != -1) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
|
||||
return -1;
|
||||
}
|
||||
return asn1_i2d_ex_primitive(pval, out, it, -1, aclass);
|
||||
|
||||
case ASN1_ITYPE_CHOICE:
|
||||
/*
|
||||
* It never makes sense for CHOICE types to have implicit tagging, so if
|
||||
* tag != -1, then this looks like an error in the template.
|
||||
*/
|
||||
if (tag != -1) {
|
||||
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BAD_TEMPLATE);
|
||||
return -1;
|
||||
}
|
||||
if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it, NULL))
|
||||
return 0;
|
||||
i = asn1_get_choice_selector(pval, it);
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <CNIOBoringSSL_arm_arch.h>
|
||||
|
||||
|
||||
.private_extern _OPENSSL_armcap_P
|
||||
|
||||
.section __TEXT,__const
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <CNIOBoringSSL_arm_arch.h>
|
||||
|
||||
|
||||
.hidden OPENSSL_armcap_P
|
||||
|
||||
.section .rodata
|
||||
|
||||
|
||||
+1912
-1980
File diff suppressed because it is too large.
Load diff
+1867
-1977
File diff suppressed because it is too large.
Load diff
@@ -18,18 +18,15 @@
|
||||
|
||||
#include <CNIOBoringSSL_chacha.h>
|
||||
#include <CNIOBoringSSL_cipher.h>
|
||||
#include <CNIOBoringSSL_cpu.h>
|
||||
#include <CNIOBoringSSL_err.h>
|
||||
#include <CNIOBoringSSL_mem.h>
|
||||
#include <CNIOBoringSSL_poly1305.h>
|
||||
#include <CNIOBoringSSL_type_check.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "../chacha/internal.h"
|
||||
#include "../fipsmodule/cipher/internal.h"
|
||||
#include "../internal.h"
|
||||
#include "../chacha/internal.h"
|
||||
|
||||
|
||||
#define POLY1305_TAG_LEN 16
|
||||
|
||||
struct aead_chacha20_poly1305_ctx {
|
||||
uint8_t key[32];
|
||||
@@ -44,78 +41,6 @@ OPENSSL_STATIC_ASSERT(alignof(union evp_aead_ctx_st_state) >=
|
||||
"AEAD state has insufficient alignment");
|
||||
#endif
|
||||
|
||||
// For convenience (the x86_64 calling convention allows only six parameters in
|
||||
// registers), the final parameter for the assembly functions is both an input
|
||||
// and output parameter.
|
||||
union open_data {
|
||||
struct {
|
||||
alignas(16) uint8_t key[32];
|
||||
uint32_t counter;
|
||||
uint8_t nonce[12];
|
||||
} in;
|
||||
struct {
|
||||
uint8_t tag[POLY1305_TAG_LEN];
|
||||
} out;
|
||||
};
|
||||
|
||||
union seal_data {
|
||||
struct {
|
||||
alignas(16) uint8_t key[32];
|
||||
uint32_t counter;
|
||||
uint8_t nonce[12];
|
||||
const uint8_t *extra_ciphertext;
|
||||
size_t extra_ciphertext_len;
|
||||
} in;
|
||||
struct {
|
||||
uint8_t tag[POLY1305_TAG_LEN];
|
||||
} out;
|
||||
};
|
||||
|
||||
#if defined(OPENSSL_X86_64) && !defined(OPENSSL_NO_ASM) && \
|
||||
!defined(OPENSSL_WINDOWS)
|
||||
static int asm_capable(void) {
|
||||
const int sse41_capable = (OPENSSL_ia32cap_P[1] & (1 << 19)) != 0;
|
||||
return sse41_capable;
|
||||
}
|
||||
|
||||
OPENSSL_STATIC_ASSERT(sizeof(union open_data) == 48, "wrong open_data size");
|
||||
OPENSSL_STATIC_ASSERT(sizeof(union seal_data) == 48 + 8 + 8,
|
||||
"wrong seal_data size");
|
||||
|
||||
// chacha20_poly1305_open is defined in chacha20_poly1305_x86_64.pl. It decrypts
|
||||
// |plaintext_len| bytes from |ciphertext| and writes them to |out_plaintext|.
|
||||
// Additional input parameters are passed in |aead_data->in|. On exit, it will
|
||||
// write calculated tag value to |aead_data->out.tag|, which the caller must
|
||||
// check.
|
||||
extern void chacha20_poly1305_open(uint8_t *out_plaintext,
|
||||
const uint8_t *ciphertext,
|
||||
size_t plaintext_len, const uint8_t *ad,
|
||||
size_t ad_len, union open_data *aead_data);
|
||||
|
||||
// chacha20_poly1305_open is defined in chacha20_poly1305_x86_64.pl. It encrypts
|
||||
// |plaintext_len| bytes from |plaintext| and writes them to |out_ciphertext|.
|
||||
// Additional input parameters are passed in |aead_data->in|. The calculated tag
|
||||
// value is over the computed ciphertext concatenated with |extra_ciphertext|
|
||||
// and written to |aead_data->out.tag|.
|
||||
extern void chacha20_poly1305_seal(uint8_t *out_ciphertext,
|
||||
const uint8_t *plaintext,
|
||||
size_t plaintext_len, const uint8_t *ad,
|
||||
size_t ad_len, union seal_data *aead_data);
|
||||
#else
|
||||
static int asm_capable(void) { return 0; }
|
||||
|
||||
|
||||
static void chacha20_poly1305_open(uint8_t *out_plaintext,
|
||||
const uint8_t *ciphertext,
|
||||
size_t plaintext_len, const uint8_t *ad,
|
||||
size_t ad_len, union open_data *aead_data) {}
|
||||
|
||||
static void chacha20_poly1305_seal(uint8_t *out_ciphertext,
|
||||
const uint8_t *plaintext,
|
||||
size_t plaintext_len, const uint8_t *ad,
|
||||
size_t ad_len, union seal_data *aead_data) {}
|
||||
#endif
|
||||
|
||||
static int aead_chacha20_poly1305_init(EVP_AEAD_CTX *ctx, const uint8_t *key,
|
||||
size_t key_len, size_t tag_len) {
|
||||
struct aead_chacha20_poly1305_ctx *c20_ctx =
|
||||
@@ -238,8 +163,8 @@ static int chacha20_poly1305_seal_scatter(
|
||||
}
|
||||
}
|
||||
|
||||
union seal_data data;
|
||||
if (asm_capable()) {
|
||||
union chacha20_poly1305_seal_data data;
|
||||
if (chacha20_poly1305_asm_capable()) {
|
||||
OPENSSL_memcpy(data.in.key, key, 32);
|
||||
data.in.counter = 0;
|
||||
OPENSSL_memcpy(data.in.nonce, nonce, 12);
|
||||
@@ -321,8 +246,8 @@ static int chacha20_poly1305_open_gather(
|
||||
return 0;
|
||||
}
|
||||
|
||||
union open_data data;
|
||||
if (asm_capable()) {
|
||||
union chacha20_poly1305_open_data data;
|
||||
if (chacha20_poly1305_asm_capable()) {
|
||||
OPENSSL_memcpy(data.in.key, key, 32);
|
||||
data.in.counter = 0;
|
||||
OPENSSL_memcpy(data.in.nonce, nonce, 12);
|
||||
|
||||
@@ -57,7 +57,11 @@
|
||||
#ifndef OPENSSL_HEADER_CIPHER_EXTRA_INTERNAL_H
|
||||
#define OPENSSL_HEADER_CIPHER_EXTRA_INTERNAL_H
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <CNIOBoringSSL_base.h>
|
||||
#include <CNIOBoringSSL_cpu.h>
|
||||
#include <CNIOBoringSSL_type_check.h>
|
||||
|
||||
#include "../internal.h"
|
||||
|
||||
@@ -120,6 +124,89 @@ int EVP_tls_cbc_digest_record(const EVP_MD *md, uint8_t *md_out,
|
||||
const uint8_t *mac_secret,
|
||||
unsigned mac_secret_length);
|
||||
|
||||
#define POLY1305_TAG_LEN 16
|
||||
|
||||
// For convenience (the x86_64 calling convention allows only six parameters in
|
||||
// registers), the final parameter for the assembly functions is both an input
|
||||
// and output parameter.
|
||||
union chacha20_poly1305_open_data {
|
||||
struct {
|
||||
alignas(16) uint8_t key[32];
|
||||
uint32_t counter;
|
||||
uint8_t nonce[12];
|
||||
} in;
|
||||
struct {
|
||||
uint8_t tag[POLY1305_TAG_LEN];
|
||||
} out;
|
||||
};
|
||||
|
||||
union chacha20_poly1305_seal_data {
|
||||
struct {
|
||||
alignas(16) uint8_t key[32];
|
||||
uint32_t counter;
|
||||
uint8_t nonce[12];
|
||||
const uint8_t *extra_ciphertext;
|
||||
size_t extra_ciphertext_len;
|
||||
} in;
|
||||
struct {
|
||||
uint8_t tag[POLY1305_TAG_LEN];
|
||||
} out;
|
||||
};
|
||||
|
||||
#if defined(OPENSSL_X86_64) && !defined(OPENSSL_NO_ASM)
|
||||
|
||||
OPENSSL_STATIC_ASSERT(sizeof(union chacha20_poly1305_open_data) == 48,
|
||||
"wrong chacha20_poly1305_open_data size");
|
||||
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;
|
||||
}
|
||||
|
||||
// chacha20_poly1305_open is defined in chacha20_poly1305_x86_64.pl. It decrypts
|
||||
// |plaintext_len| bytes from |ciphertext| and writes them to |out_plaintext|.
|
||||
// Additional input parameters are passed in |aead_data->in|. On exit, it will
|
||||
// write calculated tag value to |aead_data->out.tag|, which the caller must
|
||||
// check.
|
||||
extern void chacha20_poly1305_open(uint8_t *out_plaintext,
|
||||
const uint8_t *ciphertext,
|
||||
size_t plaintext_len, const uint8_t *ad,
|
||||
size_t ad_len,
|
||||
union chacha20_poly1305_open_data *data);
|
||||
|
||||
// chacha20_poly1305_open is defined in chacha20_poly1305_x86_64.pl. It encrypts
|
||||
// |plaintext_len| bytes from |plaintext| and writes them to |out_ciphertext|.
|
||||
// Additional input parameters are passed in |aead_data->in|. The calculated tag
|
||||
// value is over the computed ciphertext concatenated with |extra_ciphertext|
|
||||
// and written to |aead_data->out.tag|.
|
||||
extern void chacha20_poly1305_seal(uint8_t *out_ciphertext,
|
||||
const uint8_t *plaintext,
|
||||
size_t plaintext_len, const uint8_t *ad,
|
||||
size_t ad_len,
|
||||
union chacha20_poly1305_seal_data *data);
|
||||
#else
|
||||
|
||||
OPENSSL_INLINE int chacha20_poly1305_asm_capable(void) { return 0; }
|
||||
|
||||
OPENSSL_INLINE void chacha20_poly1305_open(uint8_t *out_plaintext,
|
||||
const uint8_t *ciphertext,
|
||||
size_t plaintext_len, const uint8_t *ad,
|
||||
size_t ad_len,
|
||||
union chacha20_poly1305_open_data *data) {
|
||||
abort();
|
||||
}
|
||||
|
||||
OPENSSL_INLINE void chacha20_poly1305_seal(uint8_t *out_ciphertext,
|
||||
const uint8_t *plaintext,
|
||||
size_t plaintext_len, const uint8_t *ad,
|
||||
size_t ad_len,
|
||||
union chacha20_poly1305_seal_data *data) {
|
||||
abort();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // extern C
|
||||
|
||||
File renamed without changes.
+179
@@ -53,6 +53,8 @@
|
||||
#include <CNIOBoringSSL_dh.h>
|
||||
|
||||
#include <CNIOBoringSSL_bn.h>
|
||||
#include <CNIOBoringSSL_err.h>
|
||||
#include <CNIOBoringSSL_mem.h>
|
||||
|
||||
#include "../fipsmodule/bn/internal.h"
|
||||
|
||||
@@ -91,3 +93,180 @@ BIGNUM *BN_get_rfc3526_prime_1536(BIGNUM *ret) {
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int DH_generate_parameters_ex(DH *dh, int prime_bits, int generator,
|
||||
BN_GENCB *cb) {
|
||||
// We generate DH parameters as follows
|
||||
// find a prime q which is prime_bits/2 bits long.
|
||||
// p=(2*q)+1 or (p-1)/2 = q
|
||||
// For this case, g is a generator if
|
||||
// g^((p-1)/q) mod p != 1 for values of q which are the factors of p-1.
|
||||
// Since the factors of p-1 are q and 2, we just need to check
|
||||
// g^2 mod p != 1 and g^q mod p != 1.
|
||||
//
|
||||
// Having said all that,
|
||||
// there is another special case method for the generators 2, 3 and 5.
|
||||
// for 2, p mod 24 == 11
|
||||
// for 3, p mod 12 == 5 <<<<< does not work for safe primes.
|
||||
// for 5, p mod 10 == 3 or 7
|
||||
//
|
||||
// Thanks to Phil Karn <karn@qualcomm.com> for the pointers about the
|
||||
// special generators and for answering some of my questions.
|
||||
//
|
||||
// I've implemented the second simple method :-).
|
||||
// Since DH should be using a safe prime (both p and q are prime),
|
||||
// this generator function can take a very very long time to run.
|
||||
|
||||
// Actually there is no reason to insist that 'generator' be a generator.
|
||||
// It's just as OK (and in some sense better) to use a generator of the
|
||||
// order-q subgroup.
|
||||
|
||||
BIGNUM *t1, *t2;
|
||||
int g, ok = 0;
|
||||
BN_CTX *ctx = NULL;
|
||||
|
||||
ctx = BN_CTX_new();
|
||||
if (ctx == NULL) {
|
||||
goto err;
|
||||
}
|
||||
BN_CTX_start(ctx);
|
||||
t1 = BN_CTX_get(ctx);
|
||||
t2 = BN_CTX_get(ctx);
|
||||
if (t1 == NULL || t2 == NULL) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
// Make sure |dh| has the necessary elements
|
||||
if (dh->p == NULL) {
|
||||
dh->p = BN_new();
|
||||
if (dh->p == NULL) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
if (dh->g == NULL) {
|
||||
dh->g = BN_new();
|
||||
if (dh->g == NULL) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
if (generator <= 1) {
|
||||
OPENSSL_PUT_ERROR(DH, DH_R_BAD_GENERATOR);
|
||||
goto err;
|
||||
}
|
||||
if (generator == DH_GENERATOR_2) {
|
||||
if (!BN_set_word(t1, 24)) {
|
||||
goto err;
|
||||
}
|
||||
if (!BN_set_word(t2, 11)) {
|
||||
goto err;
|
||||
}
|
||||
g = 2;
|
||||
} else if (generator == DH_GENERATOR_5) {
|
||||
if (!BN_set_word(t1, 10)) {
|
||||
goto err;
|
||||
}
|
||||
if (!BN_set_word(t2, 3)) {
|
||||
goto err;
|
||||
}
|
||||
// BN_set_word(t3,7); just have to miss
|
||||
// out on these ones :-(
|
||||
g = 5;
|
||||
} else {
|
||||
// in the general case, don't worry if 'generator' is a
|
||||
// generator or not: since we are using safe primes,
|
||||
// it will generate either an order-q or an order-2q group,
|
||||
// which both is OK
|
||||
if (!BN_set_word(t1, 2)) {
|
||||
goto err;
|
||||
}
|
||||
if (!BN_set_word(t2, 1)) {
|
||||
goto err;
|
||||
}
|
||||
g = generator;
|
||||
}
|
||||
|
||||
if (!BN_generate_prime_ex(dh->p, prime_bits, 1, t1, t2, cb)) {
|
||||
goto err;
|
||||
}
|
||||
if (!BN_GENCB_call(cb, 3, 0)) {
|
||||
goto err;
|
||||
}
|
||||
if (!BN_set_word(dh->g, g)) {
|
||||
goto err;
|
||||
}
|
||||
ok = 1;
|
||||
|
||||
err:
|
||||
if (!ok) {
|
||||
OPENSSL_PUT_ERROR(DH, ERR_R_BN_LIB);
|
||||
}
|
||||
|
||||
if (ctx != NULL) {
|
||||
BN_CTX_end(ctx);
|
||||
BN_CTX_free(ctx);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int int_dh_bn_cpy(BIGNUM **dst, const BIGNUM *src) {
|
||||
BIGNUM *a = NULL;
|
||||
|
||||
if (src) {
|
||||
a = BN_dup(src);
|
||||
if (!a) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
BN_free(*dst);
|
||||
*dst = a;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int int_dh_param_copy(DH *to, const DH *from, int is_x942) {
|
||||
if (is_x942 == -1) {
|
||||
is_x942 = !!from->q;
|
||||
}
|
||||
if (!int_dh_bn_cpy(&to->p, from->p) ||
|
||||
!int_dh_bn_cpy(&to->g, from->g)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!is_x942) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!int_dh_bn_cpy(&to->q, from->q) ||
|
||||
!int_dh_bn_cpy(&to->j, from->j)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
OPENSSL_free(to->seed);
|
||||
to->seed = NULL;
|
||||
to->seedlen = 0;
|
||||
|
||||
if (from->seed) {
|
||||
to->seed = OPENSSL_memdup(from->seed, from->seedlen);
|
||||
if (!to->seed) {
|
||||
return 0;
|
||||
}
|
||||
to->seedlen = from->seedlen;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
DH *DHparams_dup(const DH *dh) {
|
||||
DH *ret = DH_new();
|
||||
if (!ret) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!int_dh_param_copy(ret, dh, -1)) {
|
||||
DH_free(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -632,20 +632,34 @@ _aes_hw_ctr32_encrypt_blocks:
|
||||
add r7,r3,#32
|
||||
mov r6,r5
|
||||
movlo r12,#0
|
||||
|
||||
@ ARM Cortex-A57 and Cortex-A72 cores running in 32-bit mode are
|
||||
@ affected by silicon errata #1742098 [0] and #1655431 [1],
|
||||
@ respectively, where the second instruction of an aese/aesmc
|
||||
@ instruction pair may execute twice if an interrupt is taken right
|
||||
@ after the first instruction consumes an input register of which a
|
||||
@ single 32-bit lane has been updated the last time it was modified.
|
||||
@
|
||||
@ This function uses a counter in one 32-bit lane. The
|
||||
@ could write to q1 and q10 directly, but that trips this bugs.
|
||||
@ We write to q6 and copy to the final register as a workaround.
|
||||
@
|
||||
@ [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__
|
||||
rev r8, r8
|
||||
#endif
|
||||
vorr q1,q0,q0
|
||||
add r10, r8, #1
|
||||
vorr q10,q0,q0
|
||||
add r8, r8, #2
|
||||
vorr q6,q0,q0
|
||||
rev r10, r10
|
||||
vmov.32 d3[1],r10
|
||||
vmov.32 d13[1],r10
|
||||
add r8, r8, #2
|
||||
vorr q1,q6,q6
|
||||
bls Lctr32_tail
|
||||
rev r12, r8
|
||||
vmov.32 d13[1],r12
|
||||
sub r2,r2,#3 @ bias
|
||||
vmov.32 d21[1],r12
|
||||
vorr q10,q6,q6
|
||||
b Loop3x_ctr32
|
||||
|
||||
.align 4
|
||||
@@ -672,11 +686,11 @@ Loop3x_ctr32:
|
||||
.byte 0x20,0x23,0xb0,0xf3 @ aese q1,q8
|
||||
.byte 0x82,0xa3,0xb0,0xf3 @ aesmc q5,q1
|
||||
vld1.8 {q2},[r0]!
|
||||
vorr q0,q6,q6
|
||||
add r9,r8,#1
|
||||
.byte 0x20,0x43,0xf0,0xf3 @ aese q10,q8
|
||||
.byte 0xa4,0x43,0xf0,0xf3 @ aesmc q10,q10
|
||||
vld1.8 {q3},[r0]!
|
||||
vorr q1,q6,q6
|
||||
rev r9,r9
|
||||
.byte 0x22,0x83,0xb0,0xf3 @ aese q4,q9
|
||||
.byte 0x88,0x83,0xb0,0xf3 @ aesmc q4,q4
|
||||
.byte 0x22,0xa3,0xb0,0xf3 @ aese q5,q9
|
||||
@@ -685,8 +699,6 @@ Loop3x_ctr32:
|
||||
mov r7,r3
|
||||
.byte 0x22,0x43,0xf0,0xf3 @ aese q10,q9
|
||||
.byte 0xa4,0x23,0xf0,0xf3 @ aesmc q9,q10
|
||||
vorr q10,q6,q6
|
||||
add r9,r8,#1
|
||||
.byte 0x28,0x83,0xb0,0xf3 @ aese q4,q12
|
||||
.byte 0x88,0x83,0xb0,0xf3 @ aesmc q4,q4
|
||||
.byte 0x28,0xa3,0xb0,0xf3 @ aese q5,q12
|
||||
@@ -701,21 +713,26 @@ Loop3x_ctr32:
|
||||
.byte 0x88,0x83,0xb0,0xf3 @ aesmc q4,q4
|
||||
.byte 0x2a,0xa3,0xb0,0xf3 @ aese q5,q13
|
||||
.byte 0x8a,0xa3,0xb0,0xf3 @ aesmc q5,q5
|
||||
@ Note the logic to update q0, q1, and q1 is written to work
|
||||
@ around a bug in ARM Cortex-A57 and Cortex-A72 cores running in
|
||||
@ 32-bit mode. See the comment above.
|
||||
veor q11,q11,q7
|
||||
rev r9,r9
|
||||
vmov.32 d13[1], r9
|
||||
.byte 0x2a,0x23,0xf0,0xf3 @ aese q9,q13
|
||||
.byte 0xa2,0x23,0xf0,0xf3 @ aesmc q9,q9
|
||||
vmov.32 d1[1], r9
|
||||
vorr q0,q6,q6
|
||||
rev r10,r10
|
||||
.byte 0x2c,0x83,0xb0,0xf3 @ aese q4,q14
|
||||
.byte 0x88,0x83,0xb0,0xf3 @ aesmc q4,q4
|
||||
vmov.32 d13[1], r10
|
||||
rev r12,r8
|
||||
.byte 0x2c,0xa3,0xb0,0xf3 @ aese q5,q14
|
||||
.byte 0x8a,0xa3,0xb0,0xf3 @ aesmc q5,q5
|
||||
vmov.32 d3[1], r10
|
||||
rev r12,r8
|
||||
vorr q1,q6,q6
|
||||
vmov.32 d13[1], r12
|
||||
.byte 0x2c,0x23,0xf0,0xf3 @ aese q9,q14
|
||||
.byte 0xa2,0x23,0xf0,0xf3 @ aesmc q9,q9
|
||||
vmov.32 d21[1], r12
|
||||
vorr q10,q6,q6
|
||||
subs r2,r2,#3
|
||||
.byte 0x2e,0x83,0xb0,0xf3 @ aese q4,q15
|
||||
.byte 0x2e,0xa3,0xb0,0xf3 @ aese q5,q15
|
||||
|
||||
@@ -621,20 +621,34 @@ aes_hw_ctr32_encrypt_blocks:
|
||||
add r7,r3,#32
|
||||
mov r6,r5
|
||||
movlo r12,#0
|
||||
|
||||
@ ARM Cortex-A57 and Cortex-A72 cores running in 32-bit mode are
|
||||
@ affected by silicon errata #1742098 [0] and #1655431 [1],
|
||||
@ respectively, where the second instruction of an aese/aesmc
|
||||
@ instruction pair may execute twice if an interrupt is taken right
|
||||
@ after the first instruction consumes an input register of which a
|
||||
@ single 32-bit lane has been updated the last time it was modified.
|
||||
@
|
||||
@ This function uses a counter in one 32-bit lane. The
|
||||
@ could write to q1 and q10 directly, but that trips this bugs.
|
||||
@ We write to q6 and copy to the final register as a workaround.
|
||||
@
|
||||
@ [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__
|
||||
rev r8, r8
|
||||
#endif
|
||||
vorr q1,q0,q0
|
||||
add r10, r8, #1
|
||||
vorr q10,q0,q0
|
||||
add r8, r8, #2
|
||||
vorr q6,q0,q0
|
||||
rev r10, r10
|
||||
vmov.32 d3[1],r10
|
||||
vmov.32 d13[1],r10
|
||||
add r8, r8, #2
|
||||
vorr q1,q6,q6
|
||||
bls .Lctr32_tail
|
||||
rev r12, r8
|
||||
vmov.32 d13[1],r12
|
||||
sub r2,r2,#3 @ bias
|
||||
vmov.32 d21[1],r12
|
||||
vorr q10,q6,q6
|
||||
b .Loop3x_ctr32
|
||||
|
||||
.align 4
|
||||
@@ -661,11 +675,11 @@ aes_hw_ctr32_encrypt_blocks:
|
||||
.byte 0x20,0x23,0xb0,0xf3 @ aese q1,q8
|
||||
.byte 0x82,0xa3,0xb0,0xf3 @ aesmc q5,q1
|
||||
vld1.8 {q2},[r0]!
|
||||
vorr q0,q6,q6
|
||||
add r9,r8,#1
|
||||
.byte 0x20,0x43,0xf0,0xf3 @ aese q10,q8
|
||||
.byte 0xa4,0x43,0xf0,0xf3 @ aesmc q10,q10
|
||||
vld1.8 {q3},[r0]!
|
||||
vorr q1,q6,q6
|
||||
rev r9,r9
|
||||
.byte 0x22,0x83,0xb0,0xf3 @ aese q4,q9
|
||||
.byte 0x88,0x83,0xb0,0xf3 @ aesmc q4,q4
|
||||
.byte 0x22,0xa3,0xb0,0xf3 @ aese q5,q9
|
||||
@@ -674,8 +688,6 @@ aes_hw_ctr32_encrypt_blocks:
|
||||
mov r7,r3
|
||||
.byte 0x22,0x43,0xf0,0xf3 @ aese q10,q9
|
||||
.byte 0xa4,0x23,0xf0,0xf3 @ aesmc q9,q10
|
||||
vorr q10,q6,q6
|
||||
add r9,r8,#1
|
||||
.byte 0x28,0x83,0xb0,0xf3 @ aese q4,q12
|
||||
.byte 0x88,0x83,0xb0,0xf3 @ aesmc q4,q4
|
||||
.byte 0x28,0xa3,0xb0,0xf3 @ aese q5,q12
|
||||
@@ -690,21 +702,26 @@ aes_hw_ctr32_encrypt_blocks:
|
||||
.byte 0x88,0x83,0xb0,0xf3 @ aesmc q4,q4
|
||||
.byte 0x2a,0xa3,0xb0,0xf3 @ aese q5,q13
|
||||
.byte 0x8a,0xa3,0xb0,0xf3 @ aesmc q5,q5
|
||||
@ Note the logic to update q0, q1, and q1 is written to work
|
||||
@ around a bug in ARM Cortex-A57 and Cortex-A72 cores running in
|
||||
@ 32-bit mode. See the comment above.
|
||||
veor q11,q11,q7
|
||||
rev r9,r9
|
||||
vmov.32 d13[1], r9
|
||||
.byte 0x2a,0x23,0xf0,0xf3 @ aese q9,q13
|
||||
.byte 0xa2,0x23,0xf0,0xf3 @ aesmc q9,q9
|
||||
vmov.32 d1[1], r9
|
||||
vorr q0,q6,q6
|
||||
rev r10,r10
|
||||
.byte 0x2c,0x83,0xb0,0xf3 @ aese q4,q14
|
||||
.byte 0x88,0x83,0xb0,0xf3 @ aesmc q4,q4
|
||||
vmov.32 d13[1], r10
|
||||
rev r12,r8
|
||||
.byte 0x2c,0xa3,0xb0,0xf3 @ aese q5,q14
|
||||
.byte 0x8a,0xa3,0xb0,0xf3 @ aesmc q5,q5
|
||||
vmov.32 d3[1], r10
|
||||
rev r12,r8
|
||||
vorr q1,q6,q6
|
||||
vmov.32 d13[1], r12
|
||||
.byte 0x2c,0x23,0xf0,0xf3 @ aese q9,q14
|
||||
.byte 0xa2,0x23,0xf0,0xf3 @ aesmc q9,q9
|
||||
vmov.32 d21[1], r12
|
||||
vorr q10,q6,q6
|
||||
subs r2,r2,#3
|
||||
.byte 0x2e,0x83,0xb0,0xf3 @ aese q4,q15
|
||||
.byte 0x2e,0xa3,0xb0,0xf3 @ aese q5,q15
|
||||
|
||||
@@ -622,20 +622,34 @@ _aes_hw_ctr32_encrypt_blocks:
|
||||
add x7,x3,#32
|
||||
mov w6,w5
|
||||
csel x12,xzr,x12,lo
|
||||
|
||||
// ARM Cortex-A57 and Cortex-A72 cores running in 32-bit mode are
|
||||
// affected by silicon errata #1742098 [0] and #1655431 [1],
|
||||
// respectively, where the second instruction of an aese/aesmc
|
||||
// instruction pair may execute twice if an interrupt is taken right
|
||||
// after the first instruction consumes an input register of which a
|
||||
// single 32-bit lane has been updated the last time it was modified.
|
||||
//
|
||||
// This function uses a counter in one 32-bit lane. The vmov lines
|
||||
// could write to v1.16b and v18.16b directly, but that trips this bugs.
|
||||
// We write to v6.16b and copy to the final register as a workaround.
|
||||
//
|
||||
// [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__
|
||||
rev w8, w8
|
||||
#endif
|
||||
orr v1.16b,v0.16b,v0.16b
|
||||
add w10, w8, #1
|
||||
orr v18.16b,v0.16b,v0.16b
|
||||
add w8, w8, #2
|
||||
orr v6.16b,v0.16b,v0.16b
|
||||
rev w10, w10
|
||||
mov v1.s[3],w10
|
||||
mov v6.s[3],w10
|
||||
add w8, w8, #2
|
||||
orr v1.16b,v6.16b,v6.16b
|
||||
b.ls Lctr32_tail
|
||||
rev w12, w8
|
||||
mov v6.s[3],w12
|
||||
sub x2,x2,#3 // bias
|
||||
mov v18.s[3],w12
|
||||
orr v18.16b,v6.16b,v6.16b
|
||||
b Loop3x_ctr32
|
||||
|
||||
.align 4
|
||||
@@ -662,11 +676,11 @@ Loop3x_ctr32:
|
||||
aese v1.16b,v16.16b
|
||||
aesmc v5.16b,v1.16b
|
||||
ld1 {v2.16b},[x0],#16
|
||||
orr v0.16b,v6.16b,v6.16b
|
||||
add w9,w8,#1
|
||||
aese v18.16b,v16.16b
|
||||
aesmc v18.16b,v18.16b
|
||||
ld1 {v3.16b},[x0],#16
|
||||
orr v1.16b,v6.16b,v6.16b
|
||||
rev w9,w9
|
||||
aese v4.16b,v17.16b
|
||||
aesmc v4.16b,v4.16b
|
||||
aese v5.16b,v17.16b
|
||||
@@ -675,8 +689,6 @@ Loop3x_ctr32:
|
||||
mov x7,x3
|
||||
aese v18.16b,v17.16b
|
||||
aesmc v17.16b,v18.16b
|
||||
orr v18.16b,v6.16b,v6.16b
|
||||
add w9,w8,#1
|
||||
aese v4.16b,v20.16b
|
||||
aesmc v4.16b,v4.16b
|
||||
aese v5.16b,v20.16b
|
||||
@@ -691,21 +703,26 @@ Loop3x_ctr32:
|
||||
aesmc v4.16b,v4.16b
|
||||
aese v5.16b,v21.16b
|
||||
aesmc v5.16b,v5.16b
|
||||
// Note the logic to update v0.16b, v1.16b, and v1.16b is written to work
|
||||
// around a bug in ARM Cortex-A57 and Cortex-A72 cores running in
|
||||
// 32-bit mode. See the comment above.
|
||||
eor v19.16b,v19.16b,v7.16b
|
||||
rev w9,w9
|
||||
mov v6.s[3], w9
|
||||
aese v17.16b,v21.16b
|
||||
aesmc v17.16b,v17.16b
|
||||
mov v0.s[3], w9
|
||||
orr v0.16b,v6.16b,v6.16b
|
||||
rev w10,w10
|
||||
aese v4.16b,v22.16b
|
||||
aesmc v4.16b,v4.16b
|
||||
mov v6.s[3], w10
|
||||
rev w12,w8
|
||||
aese v5.16b,v22.16b
|
||||
aesmc v5.16b,v5.16b
|
||||
mov v1.s[3], w10
|
||||
rev w12,w8
|
||||
orr v1.16b,v6.16b,v6.16b
|
||||
mov v6.s[3], w12
|
||||
aese v17.16b,v22.16b
|
||||
aesmc v17.16b,v17.16b
|
||||
mov v18.s[3], w12
|
||||
orr v18.16b,v6.16b,v6.16b
|
||||
subs x2,x2,#3
|
||||
aese v4.16b,v23.16b
|
||||
aese v5.16b,v23.16b
|
||||
|
||||
@@ -623,20 +623,34 @@ aes_hw_ctr32_encrypt_blocks:
|
||||
add x7,x3,#32
|
||||
mov w6,w5
|
||||
csel x12,xzr,x12,lo
|
||||
|
||||
// ARM Cortex-A57 and Cortex-A72 cores running in 32-bit mode are
|
||||
// affected by silicon errata #1742098 [0] and #1655431 [1],
|
||||
// respectively, where the second instruction of an aese/aesmc
|
||||
// instruction pair may execute twice if an interrupt is taken right
|
||||
// after the first instruction consumes an input register of which a
|
||||
// single 32-bit lane has been updated the last time it was modified.
|
||||
//
|
||||
// This function uses a counter in one 32-bit lane. The vmov lines
|
||||
// could write to v1.16b and v18.16b directly, but that trips this bugs.
|
||||
// We write to v6.16b and copy to the final register as a workaround.
|
||||
//
|
||||
// [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__
|
||||
rev w8, w8
|
||||
#endif
|
||||
orr v1.16b,v0.16b,v0.16b
|
||||
add w10, w8, #1
|
||||
orr v18.16b,v0.16b,v0.16b
|
||||
add w8, w8, #2
|
||||
orr v6.16b,v0.16b,v0.16b
|
||||
rev w10, w10
|
||||
mov v1.s[3],w10
|
||||
mov v6.s[3],w10
|
||||
add w8, w8, #2
|
||||
orr v1.16b,v6.16b,v6.16b
|
||||
b.ls .Lctr32_tail
|
||||
rev w12, w8
|
||||
mov v6.s[3],w12
|
||||
sub x2,x2,#3 // bias
|
||||
mov v18.s[3],w12
|
||||
orr v18.16b,v6.16b,v6.16b
|
||||
b .Loop3x_ctr32
|
||||
|
||||
.align 4
|
||||
@@ -663,11 +677,11 @@ aes_hw_ctr32_encrypt_blocks:
|
||||
aese v1.16b,v16.16b
|
||||
aesmc v5.16b,v1.16b
|
||||
ld1 {v2.16b},[x0],#16
|
||||
orr v0.16b,v6.16b,v6.16b
|
||||
add w9,w8,#1
|
||||
aese v18.16b,v16.16b
|
||||
aesmc v18.16b,v18.16b
|
||||
ld1 {v3.16b},[x0],#16
|
||||
orr v1.16b,v6.16b,v6.16b
|
||||
rev w9,w9
|
||||
aese v4.16b,v17.16b
|
||||
aesmc v4.16b,v4.16b
|
||||
aese v5.16b,v17.16b
|
||||
@@ -676,8 +690,6 @@ aes_hw_ctr32_encrypt_blocks:
|
||||
mov x7,x3
|
||||
aese v18.16b,v17.16b
|
||||
aesmc v17.16b,v18.16b
|
||||
orr v18.16b,v6.16b,v6.16b
|
||||
add w9,w8,#1
|
||||
aese v4.16b,v20.16b
|
||||
aesmc v4.16b,v4.16b
|
||||
aese v5.16b,v20.16b
|
||||
@@ -692,21 +704,26 @@ aes_hw_ctr32_encrypt_blocks:
|
||||
aesmc v4.16b,v4.16b
|
||||
aese v5.16b,v21.16b
|
||||
aesmc v5.16b,v5.16b
|
||||
// Note the logic to update v0.16b, v1.16b, and v1.16b is written to work
|
||||
// around a bug in ARM Cortex-A57 and Cortex-A72 cores running in
|
||||
// 32-bit mode. See the comment above.
|
||||
eor v19.16b,v19.16b,v7.16b
|
||||
rev w9,w9
|
||||
mov v6.s[3], w9
|
||||
aese v17.16b,v21.16b
|
||||
aesmc v17.16b,v17.16b
|
||||
mov v0.s[3], w9
|
||||
orr v0.16b,v6.16b,v6.16b
|
||||
rev w10,w10
|
||||
aese v4.16b,v22.16b
|
||||
aesmc v4.16b,v4.16b
|
||||
mov v6.s[3], w10
|
||||
rev w12,w8
|
||||
aese v5.16b,v22.16b
|
||||
aesmc v5.16b,v5.16b
|
||||
mov v1.s[3], w10
|
||||
rev w12,w8
|
||||
orr v1.16b,v6.16b,v6.16b
|
||||
mov v6.s[3], w12
|
||||
aese v17.16b,v22.16b
|
||||
aesmc v17.16b,v17.16b
|
||||
mov v18.s[3], w12
|
||||
orr v18.16b,v6.16b,v6.16b
|
||||
subs x2,x2,#3
|
||||
aese v4.16b,v23.16b
|
||||
aese v5.16b,v23.16b
|
||||
|
||||
@@ -123,7 +123,7 @@
|
||||
#ifndef OPENSSL_HEADER_BN_INTERNAL_H
|
||||
#define OPENSSL_HEADER_BN_INTERNAL_H
|
||||
|
||||
#include <CNIOBoringSSL_base.h>
|
||||
#include <CNIOBoringSSL_bn.h>
|
||||
|
||||
#if defined(OPENSSL_X86_64) && defined(_MSC_VER)
|
||||
OPENSSL_MSVC_PRAGMA(warning(push, 3))
|
||||
|
||||
File renamed without changes.
+96
-233
@@ -60,17 +60,15 @@
|
||||
|
||||
#include <CNIOBoringSSL_bn.h>
|
||||
#include <CNIOBoringSSL_err.h>
|
||||
#include <CNIOBoringSSL_ex_data.h>
|
||||
#include <CNIOBoringSSL_digest.h>
|
||||
#include <CNIOBoringSSL_mem.h>
|
||||
#include <CNIOBoringSSL_thread.h>
|
||||
|
||||
#include "../internal.h"
|
||||
#include "../../internal.h"
|
||||
|
||||
|
||||
#define OPENSSL_DH_MAX_MODULUS_BITS 10000
|
||||
|
||||
static CRYPTO_EX_DATA_CLASS g_ex_data_class = CRYPTO_EX_DATA_CLASS_INIT;
|
||||
|
||||
DH *DH_new(void) {
|
||||
DH *dh = OPENSSL_malloc(sizeof(DH));
|
||||
if (dh == NULL) {
|
||||
@@ -83,7 +81,6 @@ DH *DH_new(void) {
|
||||
CRYPTO_MUTEX_init(&dh->method_mont_p_lock);
|
||||
|
||||
dh->references = 1;
|
||||
CRYPTO_new_ex_data(&dh->ex_data);
|
||||
|
||||
return dh;
|
||||
}
|
||||
@@ -97,8 +94,6 @@ void DH_free(DH *dh) {
|
||||
return;
|
||||
}
|
||||
|
||||
CRYPTO_free_ex_data(&g_ex_data_class, dh, &dh->ex_data);
|
||||
|
||||
BN_MONT_CTX_free(dh->method_mont_p);
|
||||
BN_clear_free(dh->p);
|
||||
BN_clear_free(dh->g);
|
||||
@@ -189,120 +184,6 @@ int DH_set_length(DH *dh, unsigned priv_length) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int DH_generate_parameters_ex(DH *dh, int prime_bits, int generator, BN_GENCB *cb) {
|
||||
// We generate DH parameters as follows
|
||||
// find a prime q which is prime_bits/2 bits long.
|
||||
// p=(2*q)+1 or (p-1)/2 = q
|
||||
// For this case, g is a generator if
|
||||
// g^((p-1)/q) mod p != 1 for values of q which are the factors of p-1.
|
||||
// Since the factors of p-1 are q and 2, we just need to check
|
||||
// g^2 mod p != 1 and g^q mod p != 1.
|
||||
//
|
||||
// Having said all that,
|
||||
// there is another special case method for the generators 2, 3 and 5.
|
||||
// for 2, p mod 24 == 11
|
||||
// for 3, p mod 12 == 5 <<<<< does not work for safe primes.
|
||||
// for 5, p mod 10 == 3 or 7
|
||||
//
|
||||
// Thanks to Phil Karn <karn@qualcomm.com> for the pointers about the
|
||||
// special generators and for answering some of my questions.
|
||||
//
|
||||
// I've implemented the second simple method :-).
|
||||
// Since DH should be using a safe prime (both p and q are prime),
|
||||
// this generator function can take a very very long time to run.
|
||||
|
||||
// Actually there is no reason to insist that 'generator' be a generator.
|
||||
// It's just as OK (and in some sense better) to use a generator of the
|
||||
// order-q subgroup.
|
||||
|
||||
BIGNUM *t1, *t2;
|
||||
int g, ok = 0;
|
||||
BN_CTX *ctx = NULL;
|
||||
|
||||
ctx = BN_CTX_new();
|
||||
if (ctx == NULL) {
|
||||
goto err;
|
||||
}
|
||||
BN_CTX_start(ctx);
|
||||
t1 = BN_CTX_get(ctx);
|
||||
t2 = BN_CTX_get(ctx);
|
||||
if (t1 == NULL || t2 == NULL) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
// Make sure |dh| has the necessary elements
|
||||
if (dh->p == NULL) {
|
||||
dh->p = BN_new();
|
||||
if (dh->p == NULL) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
if (dh->g == NULL) {
|
||||
dh->g = BN_new();
|
||||
if (dh->g == NULL) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
if (generator <= 1) {
|
||||
OPENSSL_PUT_ERROR(DH, DH_R_BAD_GENERATOR);
|
||||
goto err;
|
||||
}
|
||||
if (generator == DH_GENERATOR_2) {
|
||||
if (!BN_set_word(t1, 24)) {
|
||||
goto err;
|
||||
}
|
||||
if (!BN_set_word(t2, 11)) {
|
||||
goto err;
|
||||
}
|
||||
g = 2;
|
||||
} else if (generator == DH_GENERATOR_5) {
|
||||
if (!BN_set_word(t1, 10)) {
|
||||
goto err;
|
||||
}
|
||||
if (!BN_set_word(t2, 3)) {
|
||||
goto err;
|
||||
}
|
||||
// BN_set_word(t3,7); just have to miss
|
||||
// out on these ones :-(
|
||||
g = 5;
|
||||
} else {
|
||||
// in the general case, don't worry if 'generator' is a
|
||||
// generator or not: since we are using safe primes,
|
||||
// it will generate either an order-q or an order-2q group,
|
||||
// which both is OK
|
||||
if (!BN_set_word(t1, 2)) {
|
||||
goto err;
|
||||
}
|
||||
if (!BN_set_word(t2, 1)) {
|
||||
goto err;
|
||||
}
|
||||
g = generator;
|
||||
}
|
||||
|
||||
if (!BN_generate_prime_ex(dh->p, prime_bits, 1, t1, t2, cb)) {
|
||||
goto err;
|
||||
}
|
||||
if (!BN_GENCB_call(cb, 3, 0)) {
|
||||
goto err;
|
||||
}
|
||||
if (!BN_set_word(dh->g, g)) {
|
||||
goto err;
|
||||
}
|
||||
ok = 1;
|
||||
|
||||
err:
|
||||
if (!ok) {
|
||||
OPENSSL_PUT_ERROR(DH, ERR_R_BN_LIB);
|
||||
}
|
||||
|
||||
if (ctx != NULL) {
|
||||
BN_CTX_end(ctx);
|
||||
BN_CTX_free(ctx);
|
||||
}
|
||||
return ok;
|
||||
}
|
||||
|
||||
int DH_generate_key(DH *dh) {
|
||||
int ok = 0;
|
||||
int generate_new_key = 0;
|
||||
@@ -390,56 +271,118 @@ err:
|
||||
return ok;
|
||||
}
|
||||
|
||||
int DH_compute_key(unsigned char *out, const BIGNUM *peers_key, DH *dh) {
|
||||
BN_CTX *ctx = NULL;
|
||||
BIGNUM *shared_key;
|
||||
int ret = -1;
|
||||
int check_result;
|
||||
|
||||
static int dh_compute_key(DH *dh, BIGNUM *out_shared_key,
|
||||
const BIGNUM *peers_key, BN_CTX *ctx) {
|
||||
if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS) {
|
||||
OPENSSL_PUT_ERROR(DH, DH_R_MODULUS_TOO_LARGE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
ctx = BN_CTX_new();
|
||||
if (ctx == NULL) {
|
||||
goto err;
|
||||
}
|
||||
BN_CTX_start(ctx);
|
||||
shared_key = BN_CTX_get(ctx);
|
||||
if (shared_key == NULL) {
|
||||
goto err;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (dh->priv_key == NULL) {
|
||||
OPENSSL_PUT_ERROR(DH, DH_R_NO_PRIVATE_VALUE);
|
||||
goto err;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!BN_MONT_CTX_set_locked(&dh->method_mont_p, &dh->method_mont_p_lock,
|
||||
int check_result;
|
||||
if (!DH_check_pub_key(dh, peers_key, &check_result) || check_result) {
|
||||
OPENSSL_PUT_ERROR(DH, DH_R_INVALID_PUBKEY);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ret = 0;
|
||||
BN_CTX_start(ctx);
|
||||
BIGNUM *p_minus_1 = BN_CTX_get(ctx);
|
||||
|
||||
if (!p_minus_1 ||
|
||||
!BN_MONT_CTX_set_locked(&dh->method_mont_p, &dh->method_mont_p_lock,
|
||||
dh->p, ctx)) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!DH_check_pub_key(dh, peers_key, &check_result) || check_result) {
|
||||
OPENSSL_PUT_ERROR(DH, DH_R_INVALID_PUBKEY);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (!BN_mod_exp_mont_consttime(shared_key, peers_key, dh->priv_key, dh->p,
|
||||
ctx, dh->method_mont_p)) {
|
||||
if (!BN_mod_exp_mont_consttime(out_shared_key, peers_key, dh->priv_key, dh->p,
|
||||
ctx, dh->method_mont_p) ||
|
||||
!BN_copy(p_minus_1, dh->p) ||
|
||||
!BN_sub_word(p_minus_1, 1)) {
|
||||
OPENSSL_PUT_ERROR(DH, ERR_R_BN_LIB);
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = BN_bn2bin(shared_key, out);
|
||||
|
||||
err:
|
||||
if (ctx != NULL) {
|
||||
BN_CTX_end(ctx);
|
||||
BN_CTX_free(ctx);
|
||||
// This performs the check required by SP 800-56Ar3 section 5.7.1.1 step two.
|
||||
if (BN_cmp_word(out_shared_key, 1) <= 0 ||
|
||||
BN_cmp(out_shared_key, p_minus_1) == 0) {
|
||||
OPENSSL_PUT_ERROR(DH, DH_R_INVALID_PUBKEY);
|
||||
goto err;
|
||||
}
|
||||
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
BN_CTX_end(ctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int DH_compute_key(unsigned char *out, const BIGNUM *peers_key, DH *dh) {
|
||||
BN_CTX *ctx = BN_CTX_new();
|
||||
if (ctx == NULL) {
|
||||
return -1;
|
||||
}
|
||||
BN_CTX_start(ctx);
|
||||
|
||||
int ret = -1;
|
||||
BIGNUM *shared_key = BN_CTX_get(ctx);
|
||||
if (shared_key && dh_compute_key(dh, shared_key, peers_key, ctx)) {
|
||||
ret = BN_bn2bin(shared_key, out);
|
||||
}
|
||||
|
||||
BN_CTX_end(ctx);
|
||||
BN_CTX_free(ctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int DH_compute_key_hashed(DH *dh, uint8_t *out, size_t *out_len,
|
||||
size_t max_out_len, const BIGNUM *peers_key,
|
||||
const EVP_MD *digest) {
|
||||
*out_len = (size_t)-1;
|
||||
|
||||
const size_t digest_len = EVP_MD_size(digest);
|
||||
if (digest_len > max_out_len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
BN_CTX *ctx = BN_CTX_new();
|
||||
if (ctx == NULL) {
|
||||
return 0;
|
||||
}
|
||||
BN_CTX_start(ctx);
|
||||
|
||||
int ret = 0;
|
||||
BIGNUM *shared_key = BN_CTX_get(ctx);
|
||||
const size_t p_len = BN_num_bytes(dh->p);
|
||||
uint8_t *shared_bytes = OPENSSL_malloc(p_len);
|
||||
unsigned out_len_unsigned;
|
||||
if (!shared_key ||
|
||||
!shared_bytes ||
|
||||
!dh_compute_key(dh, shared_key, peers_key, ctx) ||
|
||||
// |DH_compute_key| doesn't pad the output. SP 800-56A is ambiguous about
|
||||
// whether the output should be padded prior to revision three. But
|
||||
// revision three, section C.1, awkwardly specifies padding to the length
|
||||
// of p.
|
||||
//
|
||||
// Also, padded output avoids side-channels, so is always strongly
|
||||
// advisable.
|
||||
!BN_bn2bin_padded(shared_bytes, p_len, shared_key) ||
|
||||
!EVP_Digest(shared_bytes, p_len, out, &out_len_unsigned, digest, NULL) ||
|
||||
out_len_unsigned != digest_len) {
|
||||
goto err;
|
||||
}
|
||||
|
||||
*out_len = digest_len;
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
BN_CTX_end(ctx);
|
||||
BN_CTX_free(ctx);
|
||||
OPENSSL_free(shared_bytes);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -451,83 +394,3 @@ int DH_up_ref(DH *dh) {
|
||||
CRYPTO_refcount_inc(&dh->references);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int int_dh_bn_cpy(BIGNUM **dst, const BIGNUM *src) {
|
||||
BIGNUM *a = NULL;
|
||||
|
||||
if (src) {
|
||||
a = BN_dup(src);
|
||||
if (!a) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
BN_free(*dst);
|
||||
*dst = a;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int int_dh_param_copy(DH *to, const DH *from, int is_x942) {
|
||||
if (is_x942 == -1) {
|
||||
is_x942 = !!from->q;
|
||||
}
|
||||
if (!int_dh_bn_cpy(&to->p, from->p) ||
|
||||
!int_dh_bn_cpy(&to->g, from->g)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!is_x942) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (!int_dh_bn_cpy(&to->q, from->q) ||
|
||||
!int_dh_bn_cpy(&to->j, from->j)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
OPENSSL_free(to->seed);
|
||||
to->seed = NULL;
|
||||
to->seedlen = 0;
|
||||
|
||||
if (from->seed) {
|
||||
to->seed = OPENSSL_memdup(from->seed, from->seedlen);
|
||||
if (!to->seed) {
|
||||
return 0;
|
||||
}
|
||||
to->seedlen = from->seedlen;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
DH *DHparams_dup(const DH *dh) {
|
||||
DH *ret = DH_new();
|
||||
if (!ret) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!int_dh_param_copy(ret, dh, -1)) {
|
||||
DH_free(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int DH_get_ex_new_index(long argl, void *argp, CRYPTO_EX_unused *unused,
|
||||
CRYPTO_EX_dup *dup_unused, CRYPTO_EX_free *free_func) {
|
||||
int index;
|
||||
if (!CRYPTO_get_ex_new_index(&g_ex_data_class, &index, argl, argp,
|
||||
free_func)) {
|
||||
return -1;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
|
||||
int DH_set_ex_data(DH *d, int idx, void *arg) {
|
||||
return CRYPTO_set_ex_data(&d->ex_data, idx, arg);
|
||||
}
|
||||
|
||||
void *DH_get_ex_data(DH *d, int idx) {
|
||||
return CRYPTO_get_ex_data(&d->ex_data, idx);
|
||||
}
|
||||
@@ -440,7 +440,15 @@ int EC_KEY_generate_key(EC_KEY *key) {
|
||||
}
|
||||
|
||||
int EC_KEY_generate_key_fips(EC_KEY *eckey) {
|
||||
return EC_KEY_generate_key(eckey) && EC_KEY_check_fips(eckey);
|
||||
if (EC_KEY_generate_key(eckey) && EC_KEY_check_fips(eckey)) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
EC_POINT_free(eckey->pub_key);
|
||||
ec_wrapped_scalar_free(eckey->priv_key);
|
||||
eckey->pub_key = NULL;
|
||||
eckey->priv_key = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int EC_KEY_get_ex_new_index(long argl, void *argp, CRYPTO_EX_unused *unused,
|
||||
|
||||
@@ -36,6 +36,34 @@ extern "C" {
|
||||
void RAND_bytes_with_additional_data(uint8_t *out, size_t out_len,
|
||||
const uint8_t user_additional_data[32]);
|
||||
|
||||
#if defined(BORINGSSL_FIPS)
|
||||
|
||||
// We overread from /dev/urandom or RDRAND by a factor of 10 and XOR to whiten.
|
||||
#define BORINGSSL_FIPS_OVERREAD 10
|
||||
|
||||
// CRYPTO_get_seed_entropy writes |out_entropy_len| bytes of entropy, suitable
|
||||
// for seeding a DRBG, to |out_entropy|. It sets |*out_used_cpu| to one if the
|
||||
// entropy came directly from the CPU and zero if it came from the OS. It
|
||||
// actively obtains entropy from the CPU/OS and so should not be called from
|
||||
// within the FIPS module if |BORINGSSL_FIPS_PASSIVE_ENTROPY| is defined.
|
||||
void CRYPTO_get_seed_entropy(uint8_t *out_entropy, size_t out_entropy_len,
|
||||
int *out_used_cpu);
|
||||
|
||||
#if defined(BORINGSSL_FIPS_PASSIVE_ENTROPY)
|
||||
|
||||
// RAND_load_entropy supplies |entropy_len| bytes of entropy to the module. The
|
||||
// |from_cpu| parameter is true iff the entropy was obtained directly from the
|
||||
// CPU.
|
||||
void RAND_load_entropy(const uint8_t *entropy, size_t entropy_len,
|
||||
int from_cpu);
|
||||
|
||||
// RAND_need_entropy is implemented outside of the FIPS module and is called
|
||||
// when the module has stopped because it has run out of entropy.
|
||||
void RAND_need_entropy(size_t bytes_needed);
|
||||
|
||||
#endif // BORINGSSL_FIPS_PASSIVE_ENTROPY
|
||||
#endif // BORINGSSL_FIPS
|
||||
|
||||
// CRYPTO_sysrand fills |len| bytes at |buf| with entropy from the operating
|
||||
// system.
|
||||
void CRYPTO_sysrand(uint8_t *buf, size_t len);
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <CNIOBoringSSL_chacha.h>
|
||||
#include <CNIOBoringSSL_cpu.h>
|
||||
#include <CNIOBoringSSL_mem.h>
|
||||
#include <CNIOBoringSSL_type_check.h>
|
||||
|
||||
#include "internal.h"
|
||||
#include "fork_detect.h"
|
||||
@@ -63,11 +64,11 @@ struct rand_thread_state {
|
||||
// (re)seeded. This is bound by |kReseedInterval|.
|
||||
unsigned calls;
|
||||
// last_block_valid is non-zero iff |last_block| contains data from
|
||||
// |CRYPTO_sysrand_for_seed|.
|
||||
// |get_seed_entropy|.
|
||||
int last_block_valid;
|
||||
|
||||
#if defined(BORINGSSL_FIPS)
|
||||
// last_block contains the previous block from |CRYPTO_sysrand_for_seed|.
|
||||
// last_block contains the previous block from |get_seed_entropy|.
|
||||
uint8_t last_block[CRNGT_BLOCK_SIZE];
|
||||
// next and prev form a NULL-terminated, double-linked list of all states in
|
||||
// a process.
|
||||
@@ -146,12 +147,6 @@ static int rdrand(uint8_t *buf, const size_t len) {
|
||||
OPENSSL_memcpy(buf + len_multiple8, rand_buf, remainder);
|
||||
}
|
||||
|
||||
#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(buf, 0, len);
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -165,25 +160,110 @@ static int rdrand(uint8_t *buf, size_t len) {
|
||||
|
||||
#if defined(BORINGSSL_FIPS)
|
||||
|
||||
void CRYPTO_get_seed_entropy(uint8_t *out_entropy, size_t out_entropy_len,
|
||||
int *out_used_cpu) {
|
||||
*out_used_cpu = 0;
|
||||
if (have_rdrand() && rdrand(out_entropy, out_entropy_len)) {
|
||||
*out_used_cpu = 1;
|
||||
} else {
|
||||
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 defined(BORINGSSL_FIPS_PASSIVE_ENTROPY)
|
||||
|
||||
// In passive entropy mode, entropy is supplied from outside of the module via
|
||||
// |RAND_load_entropy| and is stored in global instance of the following
|
||||
// structure.
|
||||
|
||||
struct entropy_buffer {
|
||||
// bytes contains entropy suitable for seeding a DRBG.
|
||||
uint8_t bytes[CTR_DRBG_ENTROPY_LEN * BORINGSSL_FIPS_OVERREAD];
|
||||
// bytes_valid indicates the number of bytes of |bytes| that contain valid
|
||||
// data.
|
||||
size_t bytes_valid;
|
||||
// from_cpu is true if any of the contents of |bytes| were obtained directly
|
||||
// from the CPU.
|
||||
int from_cpu;
|
||||
};
|
||||
|
||||
DEFINE_BSS_GET(struct entropy_buffer, entropy_buffer);
|
||||
DEFINE_STATIC_MUTEX(entropy_buffer_lock);
|
||||
|
||||
void RAND_load_entropy(const uint8_t *entropy, size_t entropy_len,
|
||||
int from_cpu) {
|
||||
struct entropy_buffer *const buffer = entropy_buffer_bss_get();
|
||||
|
||||
CRYPTO_STATIC_MUTEX_lock_write(entropy_buffer_lock_bss_get());
|
||||
const size_t space = sizeof(buffer->bytes) - buffer->bytes_valid;
|
||||
if (entropy_len > space) {
|
||||
entropy_len = space;
|
||||
}
|
||||
|
||||
OPENSSL_memcpy(&buffer->bytes[buffer->bytes_valid], entropy, entropy_len);
|
||||
buffer->bytes_valid += entropy_len;
|
||||
buffer->from_cpu |= from_cpu && (entropy_len != 0);
|
||||
CRYPTO_STATIC_MUTEX_unlock_write(entropy_buffer_lock_bss_get());
|
||||
}
|
||||
|
||||
// get_seed_entropy fills |out_entropy_len| bytes of |out_entropy| from the
|
||||
// global |entropy_buffer|.
|
||||
static void get_seed_entropy(uint8_t *out_entropy, size_t out_entropy_len,
|
||||
int *out_used_cpu) {
|
||||
struct entropy_buffer *const buffer = entropy_buffer_bss_get();
|
||||
if (out_entropy_len > sizeof(buffer->bytes)) {
|
||||
abort();
|
||||
}
|
||||
|
||||
CRYPTO_STATIC_MUTEX_lock_write(entropy_buffer_lock_bss_get());
|
||||
while (buffer->bytes_valid < out_entropy_len) {
|
||||
CRYPTO_STATIC_MUTEX_unlock_write(entropy_buffer_lock_bss_get());
|
||||
RAND_need_entropy(out_entropy_len - buffer->bytes_valid);
|
||||
CRYPTO_STATIC_MUTEX_lock_write(entropy_buffer_lock_bss_get());
|
||||
}
|
||||
|
||||
*out_used_cpu = buffer->from_cpu;
|
||||
OPENSSL_memcpy(out_entropy, buffer->bytes, out_entropy_len);
|
||||
OPENSSL_memmove(buffer->bytes, &buffer->bytes[out_entropy_len],
|
||||
buffer->bytes_valid - out_entropy_len);
|
||||
buffer->bytes_valid -= out_entropy_len;
|
||||
if (buffer->bytes_valid == 0) {
|
||||
buffer->from_cpu = 0;
|
||||
}
|
||||
|
||||
CRYPTO_STATIC_MUTEX_unlock_write(entropy_buffer_lock_bss_get());
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// In the active case, |get_seed_entropy| simply calls |CRYPTO_get_seed_entropy|
|
||||
// in order to obtain entropy from the CPU or OS.
|
||||
static void get_seed_entropy(uint8_t *out_entropy, size_t out_entropy_len,
|
||||
int *out_used_cpu) {
|
||||
CRYPTO_get_seed_entropy(out_entropy, out_entropy_len, out_used_cpu);
|
||||
}
|
||||
|
||||
#endif // !BORINGSSL_FIPS_PASSIVE_ENTROPY
|
||||
|
||||
// rand_get_seed fills |seed| with entropy and sets |*out_used_cpu| to one if
|
||||
// that entropy came directly from the CPU and zero otherwise.
|
||||
static void rand_get_seed(struct rand_thread_state *state,
|
||||
uint8_t seed[CTR_DRBG_ENTROPY_LEN]) {
|
||||
uint8_t seed[CTR_DRBG_ENTROPY_LEN],
|
||||
int *out_used_cpu) {
|
||||
if (!state->last_block_valid) {
|
||||
if (!have_rdrand() ||
|
||||
!rdrand(state->last_block, sizeof(state->last_block))) {
|
||||
CRYPTO_sysrand_for_seed(state->last_block, sizeof(state->last_block));
|
||||
}
|
||||
int unused;
|
||||
get_seed_entropy(state->last_block, sizeof(state->last_block), &unused);
|
||||
state->last_block_valid = 1;
|
||||
}
|
||||
|
||||
// We overread from /dev/urandom or RDRAND by a factor of 10 and XOR to
|
||||
// whiten.
|
||||
#define FIPS_OVERREAD 10
|
||||
uint8_t entropy[CTR_DRBG_ENTROPY_LEN * FIPS_OVERREAD];
|
||||
|
||||
int used_rdrand = have_rdrand() && rdrand(entropy, sizeof(entropy));
|
||||
if (!used_rdrand) {
|
||||
CRYPTO_sysrand_for_seed(entropy, sizeof(entropy));
|
||||
}
|
||||
uint8_t entropy[CTR_DRBG_ENTROPY_LEN * BORINGSSL_FIPS_OVERREAD];
|
||||
get_seed_entropy(entropy, sizeof(entropy), out_used_cpu);
|
||||
|
||||
// See FIPS 140-2, section 4.9.2. This is the “continuous random number
|
||||
// generator test” which causes the program to randomly abort. Hopefully the
|
||||
@@ -193,6 +273,7 @@ static void rand_get_seed(struct rand_thread_state *state,
|
||||
BORINGSSL_FIPS_abort();
|
||||
}
|
||||
|
||||
OPENSSL_STATIC_ASSERT(sizeof(entropy) % CRNGT_BLOCK_SIZE == 0, "");
|
||||
for (size_t i = CRNGT_BLOCK_SIZE; i < sizeof(entropy);
|
||||
i += CRNGT_BLOCK_SIZE) {
|
||||
if (CRYPTO_memcmp(entropy + i - CRNGT_BLOCK_SIZE, entropy + i,
|
||||
@@ -207,31 +288,24 @@ static void rand_get_seed(struct rand_thread_state *state,
|
||||
|
||||
OPENSSL_memcpy(seed, entropy, CTR_DRBG_ENTROPY_LEN);
|
||||
|
||||
for (size_t i = 1; i < FIPS_OVERREAD; i++) {
|
||||
for (size_t i = 1; i < BORINGSSL_FIPS_OVERREAD; i++) {
|
||||
for (size_t j = 0; j < CTR_DRBG_ENTROPY_LEN; j++) {
|
||||
seed[j] ^= entropy[CTR_DRBG_ENTROPY_LEN * i + j];
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(OPENSSL_URANDOM)
|
||||
// If we used RDRAND, also opportunistically read from the system. This avoids
|
||||
// solely relying on the hardware once the entropy pool has been initialized.
|
||||
if (used_rdrand) {
|
||||
CRYPTO_sysrand_if_available(entropy, CTR_DRBG_ENTROPY_LEN);
|
||||
for (size_t i = 0; i < CTR_DRBG_ENTROPY_LEN; i++) {
|
||||
seed[i] ^= entropy[i];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
// rand_get_seed fills |seed| with entropy and sets |*out_used_cpu| to one if
|
||||
// that entropy came directly from the CPU and zero otherwise.
|
||||
static void rand_get_seed(struct rand_thread_state *state,
|
||||
uint8_t seed[CTR_DRBG_ENTROPY_LEN]) {
|
||||
uint8_t seed[CTR_DRBG_ENTROPY_LEN],
|
||||
int *out_used_cpu) {
|
||||
// If not in FIPS mode, we don't overread from the system entropy source and
|
||||
// we don't depend only on the hardware RDRAND.
|
||||
CRYPTO_sysrand(seed, CTR_DRBG_ENTROPY_LEN);
|
||||
*out_used_cpu = 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -290,8 +364,23 @@ void RAND_bytes_with_additional_data(uint8_t *out, size_t out_len,
|
||||
|
||||
state->last_block_valid = 0;
|
||||
uint8_t seed[CTR_DRBG_ENTROPY_LEN];
|
||||
rand_get_seed(state, seed);
|
||||
if (!CTR_DRBG_init(&state->drbg, seed, NULL, 0)) {
|
||||
int used_cpu;
|
||||
rand_get_seed(state, seed, &used_cpu);
|
||||
|
||||
uint8_t personalization[CTR_DRBG_ENTROPY_LEN];
|
||||
size_t personalization_len = 0;
|
||||
#if defined(OPENSSL_URANDOM)
|
||||
// If we used RDRAND, also opportunistically read from the system. This
|
||||
// avoids solely relying on the hardware once the entropy pool has been
|
||||
// initialized.
|
||||
if (used_cpu &&
|
||||
CRYPTO_sysrand_if_available(personalization, sizeof(personalization))) {
|
||||
personalization_len = sizeof(personalization);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!CTR_DRBG_init(&state->drbg, seed, personalization,
|
||||
personalization_len)) {
|
||||
abort();
|
||||
}
|
||||
state->calls = 0;
|
||||
@@ -315,7 +404,8 @@ void RAND_bytes_with_additional_data(uint8_t *out, size_t out_len,
|
||||
if (state->calls >= kReseedInterval ||
|
||||
state->fork_generation != fork_generation) {
|
||||
uint8_t seed[CTR_DRBG_ENTROPY_LEN];
|
||||
rand_get_seed(state, seed);
|
||||
int used_cpu;
|
||||
rand_get_seed(state, seed, &used_cpu);
|
||||
#if defined(BORINGSSL_FIPS)
|
||||
// Take a read lock around accesses to |state->drbg|. This is needed to
|
||||
// avoid returning bad entropy if we race with
|
||||
|
||||
@@ -366,14 +366,7 @@ void CRYPTO_sysrand_for_seed(uint8_t *out, size_t requested) {
|
||||
perror("entropy fill failed");
|
||||
abort();
|
||||
}
|
||||
|
||||
#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, 0, requested);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif // BORINGSSL_FIPS
|
||||
|
||||
int CRYPTO_sysrand_if_available(uint8_t *out, size_t requested) {
|
||||
|
||||
@@ -1316,52 +1316,72 @@ static void replace_bn_mont_ctx(BN_MONT_CTX **out, BN_MONT_CTX **in) {
|
||||
*in = NULL;
|
||||
}
|
||||
|
||||
int RSA_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e_value,
|
||||
BN_GENCB *cb) {
|
||||
static int RSA_generate_key_ex_maybe_fips(RSA *rsa, int bits,
|
||||
const BIGNUM *e_value, BN_GENCB *cb,
|
||||
int check_fips) {
|
||||
RSA *tmp = NULL;
|
||||
uint32_t err;
|
||||
int ret = 0;
|
||||
|
||||
// |rsa_generate_key_impl|'s 2^-20 failure probability is too high at scale,
|
||||
// so we run the FIPS algorithm four times, bringing it down to 2^-80. We
|
||||
// should just adjust the retry limit, but FIPS 186-4 prescribes that value
|
||||
// and thus results in unnecessary complexity.
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int failures = 0;
|
||||
do {
|
||||
ERR_clear_error();
|
||||
// Generate into scratch space, to avoid leaving partial work on failure.
|
||||
RSA *tmp = RSA_new();
|
||||
tmp = RSA_new();
|
||||
if (tmp == NULL) {
|
||||
return 0;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (rsa_generate_key_impl(tmp, bits, e_value, cb)) {
|
||||
replace_bignum(&rsa->n, &tmp->n);
|
||||
replace_bignum(&rsa->e, &tmp->e);
|
||||
replace_bignum(&rsa->d, &tmp->d);
|
||||
replace_bignum(&rsa->p, &tmp->p);
|
||||
replace_bignum(&rsa->q, &tmp->q);
|
||||
replace_bignum(&rsa->dmp1, &tmp->dmp1);
|
||||
replace_bignum(&rsa->dmq1, &tmp->dmq1);
|
||||
replace_bignum(&rsa->iqmp, &tmp->iqmp);
|
||||
replace_bn_mont_ctx(&rsa->mont_n, &tmp->mont_n);
|
||||
replace_bn_mont_ctx(&rsa->mont_p, &tmp->mont_p);
|
||||
replace_bn_mont_ctx(&rsa->mont_q, &tmp->mont_q);
|
||||
replace_bignum(&rsa->d_fixed, &tmp->d_fixed);
|
||||
replace_bignum(&rsa->dmp1_fixed, &tmp->dmp1_fixed);
|
||||
replace_bignum(&rsa->dmq1_fixed, &tmp->dmq1_fixed);
|
||||
replace_bignum(&rsa->inv_small_mod_large_mont,
|
||||
&tmp->inv_small_mod_large_mont);
|
||||
rsa->private_key_frozen = tmp->private_key_frozen;
|
||||
RSA_free(tmp);
|
||||
return 1;
|
||||
break;
|
||||
}
|
||||
uint32_t err = ERR_peek_error();
|
||||
|
||||
err = ERR_peek_error();
|
||||
RSA_free(tmp);
|
||||
tmp = NULL;
|
||||
failures++;
|
||||
|
||||
// Only retry on |RSA_R_TOO_MANY_ITERATIONS|. This is so a caller-induced
|
||||
// failure in |BN_GENCB_call| is still fatal.
|
||||
if (ERR_GET_LIB(err) != ERR_LIB_RSA ||
|
||||
ERR_GET_REASON(err) != RSA_R_TOO_MANY_ITERATIONS) {
|
||||
return 0;
|
||||
}
|
||||
} while (failures < 4 && ERR_GET_LIB(err) == ERR_LIB_RSA &&
|
||||
ERR_GET_REASON(err) == RSA_R_TOO_MANY_ITERATIONS);
|
||||
|
||||
if (tmp == NULL || (check_fips && !RSA_check_fips(tmp))) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
return 0;
|
||||
replace_bignum(&rsa->n, &tmp->n);
|
||||
replace_bignum(&rsa->e, &tmp->e);
|
||||
replace_bignum(&rsa->d, &tmp->d);
|
||||
replace_bignum(&rsa->p, &tmp->p);
|
||||
replace_bignum(&rsa->q, &tmp->q);
|
||||
replace_bignum(&rsa->dmp1, &tmp->dmp1);
|
||||
replace_bignum(&rsa->dmq1, &tmp->dmq1);
|
||||
replace_bignum(&rsa->iqmp, &tmp->iqmp);
|
||||
replace_bn_mont_ctx(&rsa->mont_n, &tmp->mont_n);
|
||||
replace_bn_mont_ctx(&rsa->mont_p, &tmp->mont_p);
|
||||
replace_bn_mont_ctx(&rsa->mont_q, &tmp->mont_q);
|
||||
replace_bignum(&rsa->d_fixed, &tmp->d_fixed);
|
||||
replace_bignum(&rsa->dmp1_fixed, &tmp->dmp1_fixed);
|
||||
replace_bignum(&rsa->dmq1_fixed, &tmp->dmq1_fixed);
|
||||
replace_bignum(&rsa->inv_small_mod_large_mont,
|
||||
&tmp->inv_small_mod_large_mont);
|
||||
rsa->private_key_frozen = tmp->private_key_frozen;
|
||||
ret = 1;
|
||||
|
||||
out:
|
||||
RSA_free(tmp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int RSA_generate_key_ex(RSA *rsa, int bits, const BIGNUM *e_value,
|
||||
BN_GENCB *cb) {
|
||||
return RSA_generate_key_ex_maybe_fips(rsa, bits, e_value, cb,
|
||||
/*check_fips=*/0);
|
||||
}
|
||||
|
||||
int RSA_generate_key_fips(RSA *rsa, int bits, BN_GENCB *cb) {
|
||||
@@ -1377,8 +1397,7 @@ int RSA_generate_key_fips(RSA *rsa, int bits, BN_GENCB *cb) {
|
||||
BIGNUM *e = BN_new();
|
||||
int ret = e != NULL &&
|
||||
BN_set_word(e, RSA_F4) &&
|
||||
RSA_generate_key_ex(rsa, bits, e, cb) &&
|
||||
RSA_check_fips(rsa);
|
||||
RSA_generate_key_ex_maybe_fips(rsa, bits, e, cb, /*check_fips=*/1);
|
||||
BN_free(e);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include <CNIOBoringSSL_aes.h>
|
||||
#include <CNIOBoringSSL_bn.h>
|
||||
#include <CNIOBoringSSL_des.h>
|
||||
#include <CNIOBoringSSL_digest.h>
|
||||
#include <CNIOBoringSSL_ec.h>
|
||||
#include <CNIOBoringSSL_ecdsa.h>
|
||||
#include <CNIOBoringSSL_ec_key.h>
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
.text
|
||||
|
||||
|
||||
.private_extern _OPENSSL_armcap_P
|
||||
.globl _sha1_block_data_order
|
||||
.private_extern _sha1_block_data_order
|
||||
|
||||
@@ -1233,8 +1234,6 @@ Lconst:
|
||||
.byte 83,72,65,49,32,98,108,111,99,107,32,116,114,97,110,115,102,111,114,109,32,102,111,114,32,65,82,77,118,56,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0
|
||||
.align 2
|
||||
.align 2
|
||||
.comm _OPENSSL_armcap_P,4,4
|
||||
.private_extern _OPENSSL_armcap_P
|
||||
#endif // !OPENSSL_NO_ASM
|
||||
#endif // defined(__aarch64__) && defined(__APPLE__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
.text
|
||||
|
||||
|
||||
.hidden OPENSSL_armcap_P
|
||||
.globl sha1_block_data_order
|
||||
.hidden sha1_block_data_order
|
||||
.type sha1_block_data_order,%function
|
||||
@@ -1234,8 +1235,6 @@ sha1_block_armv8:
|
||||
.byte 83,72,65,49,32,98,108,111,99,107,32,116,114,97,110,115,102,111,114,109,32,102,111,114,32,65,82,77,118,56,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0
|
||||
.align 2
|
||||
.align 2
|
||||
.comm OPENSSL_armcap_P,4,4
|
||||
.hidden OPENSSL_armcap_P
|
||||
#endif
|
||||
#endif // !OPENSSL_NO_ASM
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
|
||||
@@ -60,6 +60,7 @@
|
||||
.text
|
||||
|
||||
|
||||
.private_extern _OPENSSL_armcap_P
|
||||
.globl _sha256_block_data_order
|
||||
.private_extern _sha256_block_data_order
|
||||
|
||||
@@ -1208,10 +1209,6 @@ Loop_hw:
|
||||
ldr x29,[sp],#16
|
||||
ret
|
||||
|
||||
#endif
|
||||
#ifndef __KERNEL__
|
||||
.comm _OPENSSL_armcap_P,4,4
|
||||
.private_extern _OPENSSL_armcap_P
|
||||
#endif
|
||||
#endif // !OPENSSL_NO_ASM
|
||||
#endif // defined(__aarch64__) && defined(__APPLE__)
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
.text
|
||||
|
||||
|
||||
.hidden OPENSSL_armcap_P
|
||||
.globl sha256_block_data_order
|
||||
.hidden sha256_block_data_order
|
||||
.type sha256_block_data_order,%function
|
||||
@@ -1210,10 +1211,6 @@ sha256_block_armv8:
|
||||
ret
|
||||
.size sha256_block_armv8,.-sha256_block_armv8
|
||||
#endif
|
||||
#ifndef __KERNEL__
|
||||
.comm OPENSSL_armcap_P,4,4
|
||||
.hidden OPENSSL_armcap_P
|
||||
#endif
|
||||
#endif
|
||||
#endif // !OPENSSL_NO_ASM
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
|
||||
@@ -60,6 +60,7 @@
|
||||
.text
|
||||
|
||||
|
||||
.private_extern _OPENSSL_armcap_P
|
||||
.globl _sha512_block_data_order
|
||||
.private_extern _sha512_block_data_order
|
||||
|
||||
@@ -1079,10 +1080,6 @@ LK512:
|
||||
.byte 83,72,65,53,49,50,32,98,108,111,99,107,32,116,114,97,110,115,102,111,114,109,32,102,111,114,32,65,82,77,118,56,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0
|
||||
.align 2
|
||||
.align 2
|
||||
#ifndef __KERNEL__
|
||||
.comm _OPENSSL_armcap_P,4,4
|
||||
.private_extern _OPENSSL_armcap_P
|
||||
#endif
|
||||
#endif // !OPENSSL_NO_ASM
|
||||
#endif // defined(__aarch64__) && defined(__APPLE__)
|
||||
#if defined(__linux__) && defined(__ELF__)
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
.text
|
||||
|
||||
|
||||
.hidden OPENSSL_armcap_P
|
||||
.globl sha512_block_data_order
|
||||
.hidden sha512_block_data_order
|
||||
.type sha512_block_data_order,%function
|
||||
@@ -1080,10 +1081,6 @@ sha512_block_data_order:
|
||||
.byte 83,72,65,53,49,50,32,98,108,111,99,107,32,116,114,97,110,115,102,111,114,109,32,102,111,114,32,65,82,77,118,56,44,32,67,82,89,80,84,79,71,65,77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101,110,115,115,108,46,111,114,103,62,0
|
||||
.align 2
|
||||
.align 2
|
||||
#ifndef __KERNEL__
|
||||
.comm OPENSSL_armcap_P,4,4
|
||||
.hidden OPENSSL_armcap_P
|
||||
#endif
|
||||
#endif
|
||||
#endif // !OPENSSL_NO_ASM
|
||||
.section .note.GNU-stack,"",%progbits
|
||||
|
||||
@@ -125,7 +125,7 @@ static int hpke_extract_and_expand(const EVP_MD *hkdf_md, uint8_t *out_key,
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const EVP_AEAD *hpke_get_aead(uint16_t aead_id) {
|
||||
const EVP_AEAD *EVP_HPKE_get_aead(uint16_t aead_id) {
|
||||
switch (aead_id) {
|
||||
case EVP_HPKE_AEAD_AES_GCM_128:
|
||||
return EVP_aead_aes_128_gcm();
|
||||
@@ -138,7 +138,7 @@ static const EVP_AEAD *hpke_get_aead(uint16_t aead_id) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static const EVP_MD *hpke_get_kdf(uint16_t kdf_id) {
|
||||
const EVP_MD *EVP_HPKE_get_hkdf_md(uint16_t kdf_id) {
|
||||
switch (kdf_id) {
|
||||
case EVP_HPKE_HKDF_SHA256:
|
||||
return EVP_sha256();
|
||||
@@ -174,7 +174,7 @@ static int hpke_key_schedule(EVP_HPKE_CTX *hpke, uint8_t mode,
|
||||
}
|
||||
|
||||
// Attempt to get an EVP_AEAD*.
|
||||
const EVP_AEAD *aead = hpke_get_aead(hpke->aead_id);
|
||||
const EVP_AEAD *aead = EVP_HPKE_get_aead(hpke->aead_id);
|
||||
if (aead == NULL) {
|
||||
return 0;
|
||||
}
|
||||
@@ -351,7 +351,7 @@ int EVP_HPKE_CTX_setup_base_s_x25519_for_test(
|
||||
hpke->is_sender = 1;
|
||||
hpke->kdf_id = kdf_id;
|
||||
hpke->aead_id = aead_id;
|
||||
hpke->hkdf_md = hpke_get_kdf(kdf_id);
|
||||
hpke->hkdf_md = EVP_HPKE_get_hkdf_md(kdf_id);
|
||||
if (hpke->hkdf_md == NULL) {
|
||||
return 0;
|
||||
}
|
||||
@@ -375,7 +375,7 @@ int EVP_HPKE_CTX_setup_base_r_x25519(
|
||||
hpke->is_sender = 0;
|
||||
hpke->kdf_id = kdf_id;
|
||||
hpke->aead_id = aead_id;
|
||||
hpke->hkdf_md = hpke_get_kdf(kdf_id);
|
||||
hpke->hkdf_md = EVP_HPKE_get_hkdf_md(kdf_id);
|
||||
if (hpke->hkdf_md == NULL) {
|
||||
return 0;
|
||||
}
|
||||
@@ -415,7 +415,7 @@ int EVP_HPKE_CTX_setup_psk_s_x25519_for_test(
|
||||
hpke->is_sender = 1;
|
||||
hpke->kdf_id = kdf_id;
|
||||
hpke->aead_id = aead_id;
|
||||
hpke->hkdf_md = hpke_get_kdf(kdf_id);
|
||||
hpke->hkdf_md = EVP_HPKE_get_hkdf_md(kdf_id);
|
||||
if (hpke->hkdf_md == NULL) {
|
||||
return 0;
|
||||
}
|
||||
@@ -440,7 +440,7 @@ int EVP_HPKE_CTX_setup_psk_r_x25519(
|
||||
hpke->is_sender = 0;
|
||||
hpke->kdf_id = kdf_id;
|
||||
hpke->aead_id = aead_id;
|
||||
hpke->hkdf_md = hpke_get_kdf(kdf_id);
|
||||
hpke->hkdf_md = EVP_HPKE_get_hkdf_md(kdf_id);
|
||||
if (hpke->hkdf_md == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <CNIOBoringSSL_aead.h>
|
||||
#include <CNIOBoringSSL_base.h>
|
||||
#include <CNIOBoringSSL_curve25519.h>
|
||||
#include <CNIOBoringSSL_digest.h>
|
||||
|
||||
#if defined(__cplusplus)
|
||||
extern "C" {
|
||||
@@ -77,8 +78,8 @@ OPENSSL_EXPORT void EVP_HPKE_CTX_cleanup(EVP_HPKE_CTX *ctx);
|
||||
// In each of the following functions, |hpke| must have been initialized with
|
||||
// |EVP_HPKE_CTX_init|. |kdf_id| selects the KDF for non-KEM HPKE operations and
|
||||
// must be one of the |EVP_HPKE_HKDF_*| constants. |aead_id| selects the AEAD
|
||||
// for the "open" and "seal" operations and must be one of the |EVP_HPKE_AEAD_*"
|
||||
// constants."
|
||||
// for the "open" and "seal" operations and must be one of the |EVP_HPKE_AEAD_*|
|
||||
// constants.
|
||||
|
||||
// EVP_HPKE_CTX_setup_base_s_x25519 sets up |hpke| as a sender context that can
|
||||
// encrypt for the private key corresponding to |peer_public_value| (the
|
||||
@@ -215,6 +216,14 @@ OPENSSL_EXPORT int EVP_HPKE_CTX_export(const EVP_HPKE_CTX *hpke, uint8_t *out,
|
||||
// set up as a sender.
|
||||
OPENSSL_EXPORT size_t EVP_HPKE_CTX_max_overhead(const EVP_HPKE_CTX *hpke);
|
||||
|
||||
// EVP_HPKE_get_aead returns the AEAD corresponding to |aead_id|, or NULL if
|
||||
// |aead_id| is not a known AEAD identifier.
|
||||
OPENSSL_EXPORT const EVP_AEAD *EVP_HPKE_get_aead(uint16_t aead_id);
|
||||
|
||||
// EVP_HPKE_get_hkdf_md returns the hash function associated with |kdf_id|, or
|
||||
// NULL if |kdf_id| is not a known KDF identifier that uses HKDF.
|
||||
OPENSSL_EXPORT const EVP_MD *EVP_HPKE_get_hkdf_md(uint16_t kdf_id);
|
||||
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} // extern C
|
||||
|
||||
@@ -46,10 +46,14 @@ struct poly1305_state_st {
|
||||
uint32_t s1, s2, s3, s4;
|
||||
uint32_t h0, h1, h2, h3, h4;
|
||||
uint8_t buf[16];
|
||||
unsigned int buf_used;
|
||||
size_t buf_used;
|
||||
uint8_t key[16];
|
||||
};
|
||||
|
||||
OPENSSL_STATIC_ASSERT(
|
||||
sizeof(struct poly1305_state_st) + 63 <= sizeof(poly1305_state),
|
||||
"poly1305_state isn't large enough to hold aligned poly1305_state_st");
|
||||
|
||||
static inline struct poly1305_state_st *poly1305_aligned_state(
|
||||
poly1305_state *state) {
|
||||
return (struct poly1305_state_st *)(((uintptr_t)state + 63) & ~63);
|
||||
@@ -200,7 +204,6 @@ void CRYPTO_poly1305_init(poly1305_state *statep, const uint8_t key[32]) {
|
||||
|
||||
void CRYPTO_poly1305_update(poly1305_state *statep, const uint8_t *in,
|
||||
size_t in_len) {
|
||||
unsigned int i;
|
||||
struct poly1305_state_st *state = poly1305_aligned_state(statep);
|
||||
|
||||
#if defined(OPENSSL_POLY1305_NEON)
|
||||
@@ -211,11 +214,11 @@ void CRYPTO_poly1305_update(poly1305_state *statep, const uint8_t *in,
|
||||
#endif
|
||||
|
||||
if (state->buf_used) {
|
||||
unsigned todo = 16 - state->buf_used;
|
||||
size_t todo = 16 - state->buf_used;
|
||||
if (todo > in_len) {
|
||||
todo = (unsigned)in_len;
|
||||
todo = in_len;
|
||||
}
|
||||
for (i = 0; i < todo; i++) {
|
||||
for (size_t i = 0; i < todo; i++) {
|
||||
state->buf[state->buf_used + i] = in[i];
|
||||
}
|
||||
state->buf_used += todo;
|
||||
@@ -236,10 +239,10 @@ void CRYPTO_poly1305_update(poly1305_state *statep, const uint8_t *in,
|
||||
}
|
||||
|
||||
if (in_len) {
|
||||
for (i = 0; i < in_len; i++) {
|
||||
for (size_t i = 0; i < in_len; i++) {
|
||||
state->buf[i] = in[i];
|
||||
}
|
||||
state->buf_used = (unsigned)in_len;
|
||||
state->buf_used = in_len;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ extern void addmulmod(fe1305x2 *r, const fe1305x2 *x, const fe1305x2 *y,
|
||||
const fe1305x2 *c);
|
||||
|
||||
extern int blocks(fe1305x2 *h, const fe1305x2 *precomp, const uint8_t *in,
|
||||
unsigned int inlen);
|
||||
size_t inlen);
|
||||
|
||||
static void freeze(fe1305x2 *r) {
|
||||
int i;
|
||||
@@ -136,7 +136,7 @@ static void fe1305x2_tobytearray(uint8_t r[16], fe1305x2 *x) {
|
||||
}
|
||||
|
||||
static void fe1305x2_frombytearray(fe1305x2 *r, const uint8_t *x, size_t xlen) {
|
||||
unsigned i;
|
||||
size_t i;
|
||||
uint8_t t[17];
|
||||
|
||||
for (i = 0; (i < 16) && (i < xlen); i++) {
|
||||
@@ -179,17 +179,20 @@ static const alignas(16) fe1305x2 zero;
|
||||
struct poly1305_state_st {
|
||||
uint8_t data[sizeof(fe1305x2[5]) + 128];
|
||||
uint8_t buf[32];
|
||||
unsigned int buf_used;
|
||||
size_t buf_used;
|
||||
uint8_t key[16];
|
||||
};
|
||||
|
||||
OPENSSL_STATIC_ASSERT(
|
||||
sizeof(struct poly1305_state_st) + 63 <= sizeof(poly1305_state),
|
||||
"poly1305_state isn't large enough to hold aligned poly1305_state_st.");
|
||||
|
||||
void CRYPTO_poly1305_init_neon(poly1305_state *state, const uint8_t key[32]) {
|
||||
struct poly1305_state_st *st = (struct poly1305_state_st *)(state);
|
||||
fe1305x2 *const r = (fe1305x2 *)(st->data + (15 & (-(int)st->data)));
|
||||
fe1305x2 *const h = r + 1;
|
||||
fe1305x2 *const c = h + 1;
|
||||
fe1305x2 *const precomp = c + 1;
|
||||
unsigned int j;
|
||||
|
||||
r->v[1] = r->v[0] = 0x3ffffff & load32(key);
|
||||
r->v[3] = r->v[2] = 0x3ffff03 & (load32(key + 3) >> 2);
|
||||
@@ -197,7 +200,7 @@ void CRYPTO_poly1305_init_neon(poly1305_state *state, const uint8_t key[32]) {
|
||||
r->v[7] = r->v[6] = 0x3f03fff & (load32(key + 9) >> 6);
|
||||
r->v[9] = r->v[8] = 0x00fffff & (load32(key + 12) >> 8);
|
||||
|
||||
for (j = 0; j < 10; j++) {
|
||||
for (size_t j = 0; j < 10; j++) {
|
||||
h->v[j] = 0; // XXX: should fast-forward a bit
|
||||
}
|
||||
|
||||
@@ -215,14 +218,13 @@ void CRYPTO_poly1305_update_neon(poly1305_state *state, const uint8_t *in,
|
||||
fe1305x2 *const h = r + 1;
|
||||
fe1305x2 *const c = h + 1;
|
||||
fe1305x2 *const precomp = c + 1;
|
||||
unsigned int i;
|
||||
|
||||
if (st->buf_used) {
|
||||
unsigned int todo = 32 - st->buf_used;
|
||||
size_t todo = 32 - st->buf_used;
|
||||
if (todo > in_len) {
|
||||
todo = in_len;
|
||||
}
|
||||
for (i = 0; i < todo; i++) {
|
||||
for (size_t i = 0; i < todo; i++) {
|
||||
st->buf[st->buf_used + i] = in[i];
|
||||
}
|
||||
st->buf_used += todo;
|
||||
@@ -232,7 +234,7 @@ void CRYPTO_poly1305_update_neon(poly1305_state *state, const uint8_t *in,
|
||||
if (st->buf_used == sizeof(st->buf) && in_len) {
|
||||
addmulmod(h, h, precomp, &zero);
|
||||
fe1305x2_frombytearray(c, st->buf, sizeof(st->buf));
|
||||
for (i = 0; i < 10; i++) {
|
||||
for (size_t i = 0; i < 10; i++) {
|
||||
h->v[i] += c->v[i];
|
||||
}
|
||||
st->buf_used = 0;
|
||||
@@ -240,7 +242,7 @@ void CRYPTO_poly1305_update_neon(poly1305_state *state, const uint8_t *in,
|
||||
}
|
||||
|
||||
while (in_len > 32) {
|
||||
unsigned int tlen = 1048576;
|
||||
size_t tlen = 1048576;
|
||||
if (in_len < tlen) {
|
||||
tlen = in_len;
|
||||
}
|
||||
@@ -250,7 +252,7 @@ void CRYPTO_poly1305_update_neon(poly1305_state *state, const uint8_t *in,
|
||||
}
|
||||
|
||||
if (in_len) {
|
||||
for (i = 0; i < in_len; i++) {
|
||||
for (size_t i = 0; i < in_len; i++) {
|
||||
st->buf[i] = in[i];
|
||||
}
|
||||
st->buf_used = in_len;
|
||||
|
||||
@@ -92,6 +92,10 @@ typedef struct poly1305_state_internal_t {
|
||||
} poly1305_state_internal; /* 448 bytes total + 63 bytes for
|
||||
alignment = 511 bytes raw */
|
||||
|
||||
OPENSSL_STATIC_ASSERT(
|
||||
sizeof(struct poly1305_state_internal_t) + 63 <= sizeof(poly1305_state),
|
||||
"poly1305_state isn't large enough to hold aligned poly1305_state_internal_t");
|
||||
|
||||
static inline poly1305_state_internal *poly1305_aligned_state(
|
||||
poly1305_state *state) {
|
||||
return (poly1305_state_internal *)(((uint64_t)state + 63) & ~63);
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/* Copyright (c) 2020, Google Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and/or distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
|
||||
|
||||
#include <CNIOBoringSSL_base.h>
|
||||
#include "../fipsmodule/rand/internal.h"
|
||||
|
||||
#if defined(BORINGSSL_FIPS_PASSIVE_ENTROPY)
|
||||
|
||||
// RAND_need_entropy is called by the FIPS module when it has blocked because of
|
||||
// a lack of entropy. This signal is used as an indication to feed it more.
|
||||
void RAND_need_entropy(size_t bytes_needed) {
|
||||
uint8_t buf[CTR_DRBG_ENTROPY_LEN * BORINGSSL_FIPS_OVERREAD];
|
||||
size_t todo = sizeof(buf);
|
||||
if (todo > bytes_needed) {
|
||||
todo = bytes_needed;
|
||||
}
|
||||
|
||||
int used_cpu;
|
||||
CRYPTO_get_seed_entropy(buf, todo, &used_cpu);
|
||||
RAND_load_entropy(buf, todo, used_cpu);
|
||||
}
|
||||
|
||||
#endif // BORINGSSL_FIPS_PASSIVE_ENTROPY
|
||||
@@ -57,7 +57,6 @@
|
||||
#include <CNIOBoringSSL_stack.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <CNIOBoringSSL_mem.h>
|
||||
|
||||
@@ -69,11 +68,9 @@
|
||||
static const size_t kMinSize = 4;
|
||||
|
||||
_STACK *sk_new(stack_cmp_func comp) {
|
||||
_STACK *ret;
|
||||
|
||||
ret = OPENSSL_malloc(sizeof(_STACK));
|
||||
_STACK *ret = OPENSSL_malloc(sizeof(_STACK));
|
||||
if (ret == NULL) {
|
||||
goto err;
|
||||
return NULL;
|
||||
}
|
||||
OPENSSL_memset(ret, 0, sizeof(_STACK));
|
||||
|
||||
@@ -331,23 +328,20 @@ void *sk_pop(_STACK *sk) {
|
||||
}
|
||||
|
||||
_STACK *sk_dup(const _STACK *sk) {
|
||||
_STACK *ret;
|
||||
void **s;
|
||||
|
||||
if (sk == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = sk_new(sk->comp);
|
||||
_STACK *ret = OPENSSL_malloc(sizeof(_STACK));
|
||||
if (ret == NULL) {
|
||||
goto err;
|
||||
return NULL;
|
||||
}
|
||||
OPENSSL_memset(ret, 0, sizeof(_STACK));
|
||||
|
||||
s = (void **)OPENSSL_realloc(ret->data, sizeof(void *) * sk->num_alloc);
|
||||
if (s == NULL) {
|
||||
ret->data = OPENSSL_malloc(sizeof(void *) * sk->num_alloc);
|
||||
if (ret->data == NULL) {
|
||||
goto err;
|
||||
}
|
||||
ret->data = s;
|
||||
|
||||
ret->num = sk->num;
|
||||
OPENSSL_memcpy(ret->data, sk->data, sizeof(void *) * sk->num);
|
||||
|
||||
@@ -72,8 +72,9 @@ ASN1_SEQUENCE(OTHERNAME) = {
|
||||
IMPLEMENT_ASN1_FUNCTIONS(OTHERNAME)
|
||||
|
||||
ASN1_SEQUENCE(EDIPARTYNAME) = {
|
||||
ASN1_IMP_OPT(EDIPARTYNAME, nameAssigner, DIRECTORYSTRING, 0),
|
||||
ASN1_IMP_OPT(EDIPARTYNAME, partyName, DIRECTORYSTRING, 1)
|
||||
/* DirectoryString is a CHOICE type, so use explicit tagging. */
|
||||
ASN1_EXP_OPT(EDIPARTYNAME, nameAssigner, DIRECTORYSTRING, 0),
|
||||
ASN1_EXP(EDIPARTYNAME, partyName, DIRECTORYSTRING, 1)
|
||||
} ASN1_SEQUENCE_END(EDIPARTYNAME)
|
||||
|
||||
IMPLEMENT_ASN1_FUNCTIONS(EDIPARTYNAME)
|
||||
@@ -102,42 +103,56 @@ IMPLEMENT_ASN1_FUNCTIONS(GENERAL_NAMES)
|
||||
|
||||
IMPLEMENT_ASN1_DUP_FUNCTION(GENERAL_NAME)
|
||||
|
||||
/* Returns 0 if they are equal, != 0 otherwise. */
|
||||
int GENERAL_NAME_cmp(GENERAL_NAME *a, GENERAL_NAME *b)
|
||||
static int edipartyname_cmp(const EDIPARTYNAME *a, const EDIPARTYNAME *b)
|
||||
{
|
||||
int result = -1;
|
||||
/* nameAssigner is optional and may be NULL. */
|
||||
if (a->nameAssigner == NULL) {
|
||||
if (b->nameAssigner != NULL) {
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
if (b->nameAssigner == NULL ||
|
||||
ASN1_STRING_cmp(a->nameAssigner, b->nameAssigner) != 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/* partyName may not be NULL. */
|
||||
return ASN1_STRING_cmp(a->partyName, b->partyName);
|
||||
}
|
||||
|
||||
/* Returns 0 if they are equal, != 0 otherwise. */
|
||||
int GENERAL_NAME_cmp(const GENERAL_NAME *a, const GENERAL_NAME *b)
|
||||
{
|
||||
if (!a || !b || a->type != b->type)
|
||||
return -1;
|
||||
|
||||
switch (a->type) {
|
||||
case GEN_X400:
|
||||
return ASN1_TYPE_cmp(a->d.x400Address, b->d.x400Address);
|
||||
|
||||
case GEN_EDIPARTY:
|
||||
result = ASN1_TYPE_cmp(a->d.other, b->d.other);
|
||||
break;
|
||||
return edipartyname_cmp(a->d.ediPartyName, b->d.ediPartyName);
|
||||
|
||||
case GEN_OTHERNAME:
|
||||
result = OTHERNAME_cmp(a->d.otherName, b->d.otherName);
|
||||
break;
|
||||
return OTHERNAME_cmp(a->d.otherName, b->d.otherName);
|
||||
|
||||
case GEN_EMAIL:
|
||||
case GEN_DNS:
|
||||
case GEN_URI:
|
||||
result = ASN1_STRING_cmp(a->d.ia5, b->d.ia5);
|
||||
break;
|
||||
return ASN1_STRING_cmp(a->d.ia5, b->d.ia5);
|
||||
|
||||
case GEN_DIRNAME:
|
||||
result = X509_NAME_cmp(a->d.dirn, b->d.dirn);
|
||||
break;
|
||||
return X509_NAME_cmp(a->d.dirn, b->d.dirn);
|
||||
|
||||
case GEN_IPADD:
|
||||
result = ASN1_OCTET_STRING_cmp(a->d.ip, b->d.ip);
|
||||
break;
|
||||
return ASN1_OCTET_STRING_cmp(a->d.ip, b->d.ip);
|
||||
|
||||
case GEN_RID:
|
||||
result = OBJ_cmp(a->d.rid, b->d.rid);
|
||||
break;
|
||||
return OBJ_cmp(a->d.rid, b->d.rid);
|
||||
}
|
||||
return result;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Returns 0 if they are equal, != 0 otherwise. */
|
||||
@@ -159,8 +174,11 @@ void GENERAL_NAME_set0_value(GENERAL_NAME *a, int type, void *value)
|
||||
{
|
||||
switch (type) {
|
||||
case GEN_X400:
|
||||
a->d.x400Address = value;
|
||||
break;
|
||||
|
||||
case GEN_EDIPARTY:
|
||||
a->d.other = value;
|
||||
a->d.ediPartyName = value;
|
||||
break;
|
||||
|
||||
case GEN_OTHERNAME:
|
||||
@@ -194,8 +212,10 @@ void *GENERAL_NAME_get0_value(const GENERAL_NAME *a, int *ptype)
|
||||
*ptype = a->type;
|
||||
switch (a->type) {
|
||||
case GEN_X400:
|
||||
return a->d.x400Address;
|
||||
|
||||
case GEN_EDIPARTY:
|
||||
return a->d.other;
|
||||
return a->d.ediPartyName;
|
||||
|
||||
case GEN_OTHERNAME:
|
||||
return a->d.otherName;
|
||||
|
||||
Vendored
+1
-1
@@ -1 +1 @@
|
||||
This directory is derived from BoringSSL cloned from https://boringssl.googlesource.com/boringssl at revision 4a265be4d931e35f0d108040c94d37bb49827948
|
||||
This directory is derived from BoringSSL cloned from https://boringssl.googlesource.com/boringssl at revision df75139becd7355e117c9860452265b898b49376
|
||||
@@ -1012,5 +1012,6 @@ BSSL_NAMESPACE_END
|
||||
#define ASN1_R_WRONG_TAG 190
|
||||
#define ASN1_R_WRONG_TYPE 191
|
||||
#define ASN1_R_NESTED_TOO_DEEP 192
|
||||
#define ASN1_R_BAD_TEMPLATE 193
|
||||
|
||||
#endif
|
||||
@@ -95,19 +95,19 @@ extern "C" {
|
||||
#elif defined(__x86) || defined(__i386) || defined(__i386__) || defined(_M_IX86)
|
||||
#define OPENSSL_32_BIT
|
||||
#define OPENSSL_X86
|
||||
#elif defined(__aarch64__) || defined(_M_ARM64)
|
||||
#elif defined(__AARCH64EL__) || defined(_M_ARM64)
|
||||
#define OPENSSL_64_BIT
|
||||
#define OPENSSL_AARCH64
|
||||
#elif defined(__arm) || defined(__arm__) || defined(_M_ARM)
|
||||
#elif defined(__ARMEL__) || defined(_M_ARM)
|
||||
#define OPENSSL_32_BIT
|
||||
#define OPENSSL_ARM
|
||||
#elif (defined(__PPC64__) || defined(__powerpc64__)) && defined(_LITTLE_ENDIAN)
|
||||
#define OPENSSL_64_BIT
|
||||
#define OPENSSL_PPC64LE
|
||||
#elif defined(__mips__) && !defined(__LP64__)
|
||||
#elif defined(__MIPSEL__) && !defined(__LP64__)
|
||||
#define OPENSSL_32_BIT
|
||||
#define OPENSSL_MIPS
|
||||
#elif defined(__mips__) && defined(__LP64__)
|
||||
#elif defined(__MIPSEL__) && defined(__LP64__)
|
||||
#define OPENSSL_64_BIT
|
||||
#define OPENSSL_MIPS64
|
||||
#elif defined(__pnacl__)
|
||||
@@ -161,6 +161,10 @@ extern "C" {
|
||||
|
||||
#if defined(__ANDROID_API__)
|
||||
#define OPENSSL_ANDROID
|
||||
#if defined(BORINGSSL_FIPS)
|
||||
// The FIPS module on Android passively receives entropy.
|
||||
#define BORINGSSL_FIPS_PASSIVE_ENTROPY
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// BoringSSL requires platform's locking APIs to make internal global state
|
||||
@@ -192,7 +196,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 12
|
||||
#define BORINGSSL_API_VERSION 13
|
||||
|
||||
#if defined(BORINGSSL_SHARED_LIBRARY)
|
||||
|
||||
|
||||
@@ -642,6 +642,7 @@
|
||||
#define DH_check BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_check)
|
||||
#define DH_check_pub_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_check_pub_key)
|
||||
#define DH_compute_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_compute_key)
|
||||
#define DH_compute_key_hashed BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_compute_key_hashed)
|
||||
#define DH_free BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_free)
|
||||
#define DH_generate_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_generate_key)
|
||||
#define DH_generate_parameters_ex BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_generate_parameters_ex)
|
||||
@@ -652,15 +653,12 @@
|
||||
#define DH_get0_priv_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_get0_priv_key)
|
||||
#define DH_get0_pub_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_get0_pub_key)
|
||||
#define DH_get0_q BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_get0_q)
|
||||
#define DH_get_ex_data BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_get_ex_data)
|
||||
#define DH_get_ex_new_index BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_get_ex_new_index)
|
||||
#define DH_marshal_parameters BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_marshal_parameters)
|
||||
#define DH_new BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_new)
|
||||
#define DH_num_bits BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_num_bits)
|
||||
#define DH_parse_parameters BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_parse_parameters)
|
||||
#define DH_set0_key BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_set0_key)
|
||||
#define DH_set0_pqg BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_set0_pqg)
|
||||
#define DH_set_ex_data BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_set_ex_data)
|
||||
#define DH_set_length BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_set_length)
|
||||
#define DH_size BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_size)
|
||||
#define DH_up_ref BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, DH_up_ref)
|
||||
@@ -968,6 +966,8 @@
|
||||
#define EVP_HPKE_CTX_setup_psk_r_x25519 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_HPKE_CTX_setup_psk_r_x25519)
|
||||
#define EVP_HPKE_CTX_setup_psk_s_x25519 BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_HPKE_CTX_setup_psk_s_x25519)
|
||||
#define EVP_HPKE_CTX_setup_psk_s_x25519_for_test BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_HPKE_CTX_setup_psk_s_x25519_for_test)
|
||||
#define EVP_HPKE_get_aead BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_HPKE_get_aead)
|
||||
#define EVP_HPKE_get_hkdf_md BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_HPKE_get_hkdf_md)
|
||||
#define EVP_MD_CTX_block_size BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, EVP_MD_CTX_block_size)
|
||||
#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)
|
||||
@@ -1977,6 +1977,7 @@
|
||||
#define SSL_set_connect_state BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, SSL_set_connect_state)
|
||||
#define SSL_set_custom_verify BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, SSL_set_custom_verify)
|
||||
#define SSL_set_early_data_enabled BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, SSL_set_early_data_enabled)
|
||||
#define SSL_set_enable_ech_grease BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, SSL_set_enable_ech_grease)
|
||||
#define SSL_set_enforce_rsa_key_usage BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, SSL_set_enforce_rsa_key_usage)
|
||||
#define SSL_set_ex_data BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, SSL_set_ex_data)
|
||||
#define SSL_set_fd BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, SSL_set_fd)
|
||||
@@ -2000,6 +2001,7 @@
|
||||
#define SSL_set_quic_early_data_context BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, SSL_set_quic_early_data_context)
|
||||
#define SSL_set_quic_method BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, SSL_set_quic_method)
|
||||
#define SSL_set_quic_transport_params BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, SSL_set_quic_transport_params)
|
||||
#define SSL_set_quic_use_legacy_codepoint BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, SSL_set_quic_use_legacy_codepoint)
|
||||
#define SSL_set_quiet_shutdown BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, SSL_set_quiet_shutdown)
|
||||
#define SSL_set_read_ahead BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, SSL_set_read_ahead)
|
||||
#define SSL_set_renegotiate_mode BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, SSL_set_renegotiate_mode)
|
||||
|
||||
@@ -647,6 +647,7 @@
|
||||
#define _DH_check BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_check)
|
||||
#define _DH_check_pub_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_check_pub_key)
|
||||
#define _DH_compute_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_compute_key)
|
||||
#define _DH_compute_key_hashed BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_compute_key_hashed)
|
||||
#define _DH_free BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_free)
|
||||
#define _DH_generate_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_generate_key)
|
||||
#define _DH_generate_parameters_ex BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_generate_parameters_ex)
|
||||
@@ -657,15 +658,12 @@
|
||||
#define _DH_get0_priv_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_get0_priv_key)
|
||||
#define _DH_get0_pub_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_get0_pub_key)
|
||||
#define _DH_get0_q BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_get0_q)
|
||||
#define _DH_get_ex_data BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_get_ex_data)
|
||||
#define _DH_get_ex_new_index BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_get_ex_new_index)
|
||||
#define _DH_marshal_parameters BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_marshal_parameters)
|
||||
#define _DH_new BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_new)
|
||||
#define _DH_num_bits BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_num_bits)
|
||||
#define _DH_parse_parameters BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_parse_parameters)
|
||||
#define _DH_set0_key BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_set0_key)
|
||||
#define _DH_set0_pqg BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_set0_pqg)
|
||||
#define _DH_set_ex_data BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_set_ex_data)
|
||||
#define _DH_set_length BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_set_length)
|
||||
#define _DH_size BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_size)
|
||||
#define _DH_up_ref BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, DH_up_ref)
|
||||
@@ -973,6 +971,8 @@
|
||||
#define _EVP_HPKE_CTX_setup_psk_r_x25519 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_HPKE_CTX_setup_psk_r_x25519)
|
||||
#define _EVP_HPKE_CTX_setup_psk_s_x25519 BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_HPKE_CTX_setup_psk_s_x25519)
|
||||
#define _EVP_HPKE_CTX_setup_psk_s_x25519_for_test BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_HPKE_CTX_setup_psk_s_x25519_for_test)
|
||||
#define _EVP_HPKE_get_aead BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_HPKE_get_aead)
|
||||
#define _EVP_HPKE_get_hkdf_md BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_HPKE_get_hkdf_md)
|
||||
#define _EVP_MD_CTX_block_size BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, EVP_MD_CTX_block_size)
|
||||
#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)
|
||||
@@ -1982,6 +1982,7 @@
|
||||
#define _SSL_set_connect_state BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, SSL_set_connect_state)
|
||||
#define _SSL_set_custom_verify BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, SSL_set_custom_verify)
|
||||
#define _SSL_set_early_data_enabled BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, SSL_set_early_data_enabled)
|
||||
#define _SSL_set_enable_ech_grease BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, SSL_set_enable_ech_grease)
|
||||
#define _SSL_set_enforce_rsa_key_usage BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, SSL_set_enforce_rsa_key_usage)
|
||||
#define _SSL_set_ex_data BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, SSL_set_ex_data)
|
||||
#define _SSL_set_fd BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, SSL_set_fd)
|
||||
@@ -2005,6 +2006,7 @@
|
||||
#define _SSL_set_quic_early_data_context BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, SSL_set_quic_early_data_context)
|
||||
#define _SSL_set_quic_method BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, SSL_set_quic_method)
|
||||
#define _SSL_set_quic_transport_params BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, SSL_set_quic_transport_params)
|
||||
#define _SSL_set_quic_use_legacy_codepoint BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, SSL_set_quic_use_legacy_codepoint)
|
||||
#define _SSL_set_quiet_shutdown BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, SSL_set_quiet_shutdown)
|
||||
#define _SSL_set_read_ahead BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, SSL_set_read_ahead)
|
||||
#define _SSL_set_renegotiate_mode BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, SSL_set_renegotiate_mode)
|
||||
|
||||
@@ -59,7 +59,6 @@
|
||||
|
||||
#include "CNIOBoringSSL_base.h"
|
||||
|
||||
#include "CNIOBoringSSL_ex_data.h"
|
||||
#include "CNIOBoringSSL_thread.h"
|
||||
|
||||
#if defined(__cplusplus)
|
||||
@@ -179,6 +178,19 @@ OPENSSL_EXPORT int DH_generate_key(DH *dh);
|
||||
OPENSSL_EXPORT int DH_compute_key(uint8_t *out, const BIGNUM *peers_key,
|
||||
DH *dh);
|
||||
|
||||
// DH_compute_key_hashed calculates the shared key between |dh| and |peers_key|
|
||||
// and hashes it with the given |digest|. If the hash output is less than
|
||||
// |max_out_len| bytes then it writes the hash output to |out| and sets
|
||||
// |*out_len| to the number of bytes written. Otherwise it signals an error. It
|
||||
// returns one on success or zero on error.
|
||||
//
|
||||
// NOTE: this follows the usual BoringSSL return-value convention, but that's
|
||||
// different from |DH_compute_key|, above.
|
||||
OPENSSL_EXPORT int DH_compute_key_hashed(DH *dh, uint8_t *out, size_t *out_len,
|
||||
size_t max_out_len,
|
||||
const BIGNUM *peers_key,
|
||||
const EVP_MD *digest);
|
||||
|
||||
|
||||
// Utility functions.
|
||||
|
||||
@@ -237,18 +249,6 @@ OPENSSL_EXPORT DH *DH_parse_parameters(CBS *cbs);
|
||||
OPENSSL_EXPORT int DH_marshal_parameters(CBB *cbb, const DH *dh);
|
||||
|
||||
|
||||
// ex_data functions.
|
||||
//
|
||||
// See |ex_data.h| for details.
|
||||
|
||||
OPENSSL_EXPORT int DH_get_ex_new_index(long argl, void *argp,
|
||||
CRYPTO_EX_unused *unused,
|
||||
CRYPTO_EX_dup *dup_unused,
|
||||
CRYPTO_EX_free *free_func);
|
||||
OPENSSL_EXPORT int DH_set_ex_data(DH *d, int idx, void *arg);
|
||||
OPENSSL_EXPORT void *DH_get_ex_data(DH *d, int idx);
|
||||
|
||||
|
||||
// Deprecated functions.
|
||||
|
||||
// DH_generate_parameters behaves like |DH_generate_parameters_ex|, which is
|
||||
@@ -301,7 +301,6 @@ struct dh_st {
|
||||
|
||||
int flags;
|
||||
CRYPTO_refcount_t references;
|
||||
CRYPTO_EX_DATA ex_data;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -21,8 +21,9 @@
|
||||
|
||||
extern "C++" {
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <type_traits>
|
||||
|
||||
BSSL_NAMESPACE_BEGIN
|
||||
|
||||
@@ -2823,13 +2823,11 @@ OPENSSL_EXPORT int SSL_has_application_settings(const SSL *ssl);
|
||||
|
||||
// Certificate compression.
|
||||
//
|
||||
// Certificates in TLS 1.3 can be compressed[1]. BoringSSL supports this as both
|
||||
// a client and a server, but does not link against any specific compression
|
||||
// libraries in order to keep dependencies to a minimum. Instead, hooks for
|
||||
// compression and decompression can be installed in an |SSL_CTX| to enable
|
||||
// support.
|
||||
//
|
||||
// [1] https://tools.ietf.org/html/draft-ietf-tls-certificate-compression-03.
|
||||
// Certificates in TLS 1.3 can be compressed (RFC 8879). BoringSSL supports this
|
||||
// as both a client and a server, but does not link against any specific
|
||||
// compression libraries in order to keep dependencies to a minimum. Instead,
|
||||
// hooks for compression and decompression can be installed in an |SSL_CTX| to
|
||||
// enable support.
|
||||
|
||||
// ssl_cert_compression_func_t is a pointer to a function that performs
|
||||
// compression. It must write the compressed representation of |in| to |out|,
|
||||
@@ -3386,6 +3384,12 @@ OPENSSL_EXPORT int SSL_set_quic_transport_params(SSL *ssl,
|
||||
OPENSSL_EXPORT void SSL_get_peer_quic_transport_params(
|
||||
const SSL *ssl, const uint8_t **out_params, size_t *out_params_len);
|
||||
|
||||
// SSL_set_quic_use_legacy_codepoint configures whether to use the legacy QUIC
|
||||
// extension codepoint 0xffa5 as opposed to the official value 57. Call with
|
||||
// |use_legacy| set to 1 to use 0xffa5 and call with 0 to use 57. The default
|
||||
// value for this is currently 1 but it will change to 0 at a later date.
|
||||
OPENSSL_EXPORT void SSL_set_quic_use_legacy_codepoint(SSL *ssl, int use_legacy);
|
||||
|
||||
// SSL_set_quic_early_data_context configures a context string in QUIC servers
|
||||
// for accepting early data. If a resumption connection offers early data, the
|
||||
// server will check if the value matches that of the connection which minted
|
||||
@@ -3555,6 +3559,21 @@ OPENSSL_EXPORT const char *SSL_early_data_reason_string(
|
||||
enum ssl_early_data_reason_t reason);
|
||||
|
||||
|
||||
// Encrypted Client Hello.
|
||||
//
|
||||
// ECH is a mechanism for encrypting the entire ClientHello message in TLS 1.3.
|
||||
// This can prevent observers from seeing cleartext information about the
|
||||
// connection, such as the server_name extension.
|
||||
//
|
||||
// ECH support in BoringSSL is still experimental and under development.
|
||||
//
|
||||
// See https://tools.ietf.org/html/draft-ietf-tls-esni-08.
|
||||
|
||||
// SSL_set_enable_ech_grease configures whether the client may send ECH GREASE
|
||||
// as part of this connection.
|
||||
OPENSSL_EXPORT void SSL_set_enable_ech_grease(SSL *ssl, int enable);
|
||||
|
||||
|
||||
// Alerts.
|
||||
//
|
||||
// TLS uses alerts to signal error conditions. Alerts have a type (warning or
|
||||
|
||||
@@ -206,13 +206,15 @@ extern "C" {
|
||||
// ExtensionType value from draft-ietf-tokbind-negotiation-10
|
||||
#define TLSEXT_TYPE_token_binding 24
|
||||
|
||||
// ExtensionType value from draft-ietf-quic-tls. Note that this collides with
|
||||
// TLS-LTS and, based on scans, something else too. Since it's QUIC-only, that
|
||||
// shouldn't be a problem in practice.
|
||||
#define TLSEXT_TYPE_quic_transport_parameters 0xffa5
|
||||
// ExtensionType value from draft-ietf-quic-tls. Drafts 00 through 32 use
|
||||
// 0xffa5 which is part of the Private Use section of the registry, and it
|
||||
// collides with TLS-LTS and, based on scans, something else too (though this
|
||||
// hasn't been a problem in practice since it's QUIC-only). Drafts 33 onward
|
||||
// use the value 57 which was officially registered with IANA.
|
||||
#define TLSEXT_TYPE_quic_transport_parameters_legacy 0xffa5
|
||||
#define TLSEXT_TYPE_quic_transport_parameters 57
|
||||
|
||||
// ExtensionType value assigned to
|
||||
// https://tools.ietf.org/html/draft-ietf-tls-certificate-compression-03
|
||||
// ExtensionType value from RFC8879
|
||||
#define TLSEXT_TYPE_cert_compression 27
|
||||
|
||||
// ExtensionType value from RFC4507
|
||||
@@ -239,6 +241,10 @@ extern "C" {
|
||||
// extension number.
|
||||
#define TLSEXT_TYPE_application_settings 17513
|
||||
|
||||
// ExtensionType value from draft-ietf-tls-esni-08. This is not an IANA defined
|
||||
// extension number.
|
||||
#define TLSEXT_TYPE_encrypted_client_hello 0xfe08
|
||||
|
||||
// ExtensionType value from RFC6962
|
||||
#define TLSEXT_TYPE_certificate_timestamp 18
|
||||
|
||||
@@ -271,7 +277,7 @@ extern "C" {
|
||||
#define TLSEXT_hash_sha384 5
|
||||
#define TLSEXT_hash_sha512 6
|
||||
|
||||
// From https://tools.ietf.org/html/draft-ietf-tls-certificate-compression-03#section-3
|
||||
// From https://www.rfc-editor.org/rfc/rfc8879.html#section-3
|
||||
#define TLSEXT_cert_compression_zlib 1
|
||||
#define TLSEXT_cert_compression_brotli 2
|
||||
|
||||
|
||||
@@ -474,7 +474,12 @@ DECLARE_ASN1_FUNCTIONS(AUTHORITY_KEYID)
|
||||
|
||||
DECLARE_ASN1_FUNCTIONS(GENERAL_NAME)
|
||||
OPENSSL_EXPORT GENERAL_NAME *GENERAL_NAME_dup(GENERAL_NAME *a);
|
||||
OPENSSL_EXPORT int GENERAL_NAME_cmp(GENERAL_NAME *a, GENERAL_NAME *b);
|
||||
|
||||
// GENERAL_NAME_cmp returns zero if |a| and |b| are equal and a non-zero
|
||||
// value otherwise. Note this function does not provide a comparison suitable
|
||||
// for sorting.
|
||||
OPENSSL_EXPORT int GENERAL_NAME_cmp(const GENERAL_NAME *a,
|
||||
const GENERAL_NAME *b);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -639,6 +639,7 @@
|
||||
%xdefine _DH_check _ %+ BORINGSSL_PREFIX %+ _DH_check
|
||||
%xdefine _DH_check_pub_key _ %+ BORINGSSL_PREFIX %+ _DH_check_pub_key
|
||||
%xdefine _DH_compute_key _ %+ BORINGSSL_PREFIX %+ _DH_compute_key
|
||||
%xdefine _DH_compute_key_hashed _ %+ BORINGSSL_PREFIX %+ _DH_compute_key_hashed
|
||||
%xdefine _DH_free _ %+ BORINGSSL_PREFIX %+ _DH_free
|
||||
%xdefine _DH_generate_key _ %+ BORINGSSL_PREFIX %+ _DH_generate_key
|
||||
%xdefine _DH_generate_parameters_ex _ %+ BORINGSSL_PREFIX %+ _DH_generate_parameters_ex
|
||||
@@ -649,15 +650,12 @@
|
||||
%xdefine _DH_get0_priv_key _ %+ BORINGSSL_PREFIX %+ _DH_get0_priv_key
|
||||
%xdefine _DH_get0_pub_key _ %+ BORINGSSL_PREFIX %+ _DH_get0_pub_key
|
||||
%xdefine _DH_get0_q _ %+ BORINGSSL_PREFIX %+ _DH_get0_q
|
||||
%xdefine _DH_get_ex_data _ %+ BORINGSSL_PREFIX %+ _DH_get_ex_data
|
||||
%xdefine _DH_get_ex_new_index _ %+ BORINGSSL_PREFIX %+ _DH_get_ex_new_index
|
||||
%xdefine _DH_marshal_parameters _ %+ BORINGSSL_PREFIX %+ _DH_marshal_parameters
|
||||
%xdefine _DH_new _ %+ BORINGSSL_PREFIX %+ _DH_new
|
||||
%xdefine _DH_num_bits _ %+ BORINGSSL_PREFIX %+ _DH_num_bits
|
||||
%xdefine _DH_parse_parameters _ %+ BORINGSSL_PREFIX %+ _DH_parse_parameters
|
||||
%xdefine _DH_set0_key _ %+ BORINGSSL_PREFIX %+ _DH_set0_key
|
||||
%xdefine _DH_set0_pqg _ %+ BORINGSSL_PREFIX %+ _DH_set0_pqg
|
||||
%xdefine _DH_set_ex_data _ %+ BORINGSSL_PREFIX %+ _DH_set_ex_data
|
||||
%xdefine _DH_set_length _ %+ BORINGSSL_PREFIX %+ _DH_set_length
|
||||
%xdefine _DH_size _ %+ BORINGSSL_PREFIX %+ _DH_size
|
||||
%xdefine _DH_up_ref _ %+ BORINGSSL_PREFIX %+ _DH_up_ref
|
||||
@@ -966,6 +964,8 @@
|
||||
%xdefine _EVP_HPKE_CTX_setup_psk_r_x25519 _ %+ BORINGSSL_PREFIX %+ _EVP_HPKE_CTX_setup_psk_r_x25519
|
||||
%xdefine _EVP_HPKE_CTX_setup_psk_s_x25519 _ %+ BORINGSSL_PREFIX %+ _EVP_HPKE_CTX_setup_psk_s_x25519
|
||||
%xdefine _EVP_HPKE_CTX_setup_psk_s_x25519_for_test _ %+ BORINGSSL_PREFIX %+ _EVP_HPKE_CTX_setup_psk_s_x25519_for_test
|
||||
%xdefine _EVP_HPKE_get_aead _ %+ BORINGSSL_PREFIX %+ _EVP_HPKE_get_aead
|
||||
%xdefine _EVP_HPKE_get_hkdf_md _ %+ BORINGSSL_PREFIX %+ _EVP_HPKE_get_hkdf_md
|
||||
%xdefine _EVP_MD_CTX_block_size _ %+ BORINGSSL_PREFIX %+ _EVP_MD_CTX_block_size
|
||||
%xdefine _EVP_MD_CTX_cleanup _ %+ BORINGSSL_PREFIX %+ _EVP_MD_CTX_cleanup
|
||||
%xdefine _EVP_MD_CTX_copy _ %+ BORINGSSL_PREFIX %+ _EVP_MD_CTX_copy
|
||||
@@ -1975,6 +1975,7 @@
|
||||
%xdefine _SSL_set_connect_state _ %+ BORINGSSL_PREFIX %+ _SSL_set_connect_state
|
||||
%xdefine _SSL_set_custom_verify _ %+ BORINGSSL_PREFIX %+ _SSL_set_custom_verify
|
||||
%xdefine _SSL_set_early_data_enabled _ %+ BORINGSSL_PREFIX %+ _SSL_set_early_data_enabled
|
||||
%xdefine _SSL_set_enable_ech_grease _ %+ BORINGSSL_PREFIX %+ _SSL_set_enable_ech_grease
|
||||
%xdefine _SSL_set_enforce_rsa_key_usage _ %+ BORINGSSL_PREFIX %+ _SSL_set_enforce_rsa_key_usage
|
||||
%xdefine _SSL_set_ex_data _ %+ BORINGSSL_PREFIX %+ _SSL_set_ex_data
|
||||
%xdefine _SSL_set_fd _ %+ BORINGSSL_PREFIX %+ _SSL_set_fd
|
||||
@@ -1998,6 +1999,7 @@
|
||||
%xdefine _SSL_set_quic_early_data_context _ %+ BORINGSSL_PREFIX %+ _SSL_set_quic_early_data_context
|
||||
%xdefine _SSL_set_quic_method _ %+ BORINGSSL_PREFIX %+ _SSL_set_quic_method
|
||||
%xdefine _SSL_set_quic_transport_params _ %+ BORINGSSL_PREFIX %+ _SSL_set_quic_transport_params
|
||||
%xdefine _SSL_set_quic_use_legacy_codepoint _ %+ BORINGSSL_PREFIX %+ _SSL_set_quic_use_legacy_codepoint
|
||||
%xdefine _SSL_set_quiet_shutdown _ %+ BORINGSSL_PREFIX %+ _SSL_set_quiet_shutdown
|
||||
%xdefine _SSL_set_read_ahead _ %+ BORINGSSL_PREFIX %+ _SSL_set_read_ahead
|
||||
%xdefine _SSL_set_renegotiate_mode _ %+ BORINGSSL_PREFIX %+ _SSL_set_renegotiate_mode
|
||||
@@ -3994,6 +3996,7 @@
|
||||
%xdefine DH_check BORINGSSL_PREFIX %+ _DH_check
|
||||
%xdefine DH_check_pub_key BORINGSSL_PREFIX %+ _DH_check_pub_key
|
||||
%xdefine DH_compute_key BORINGSSL_PREFIX %+ _DH_compute_key
|
||||
%xdefine DH_compute_key_hashed BORINGSSL_PREFIX %+ _DH_compute_key_hashed
|
||||
%xdefine DH_free BORINGSSL_PREFIX %+ _DH_free
|
||||
%xdefine DH_generate_key BORINGSSL_PREFIX %+ _DH_generate_key
|
||||
%xdefine DH_generate_parameters_ex BORINGSSL_PREFIX %+ _DH_generate_parameters_ex
|
||||
@@ -4004,15 +4007,12 @@
|
||||
%xdefine DH_get0_priv_key BORINGSSL_PREFIX %+ _DH_get0_priv_key
|
||||
%xdefine DH_get0_pub_key BORINGSSL_PREFIX %+ _DH_get0_pub_key
|
||||
%xdefine DH_get0_q BORINGSSL_PREFIX %+ _DH_get0_q
|
||||
%xdefine DH_get_ex_data BORINGSSL_PREFIX %+ _DH_get_ex_data
|
||||
%xdefine DH_get_ex_new_index BORINGSSL_PREFIX %+ _DH_get_ex_new_index
|
||||
%xdefine DH_marshal_parameters BORINGSSL_PREFIX %+ _DH_marshal_parameters
|
||||
%xdefine DH_new BORINGSSL_PREFIX %+ _DH_new
|
||||
%xdefine DH_num_bits BORINGSSL_PREFIX %+ _DH_num_bits
|
||||
%xdefine DH_parse_parameters BORINGSSL_PREFIX %+ _DH_parse_parameters
|
||||
%xdefine DH_set0_key BORINGSSL_PREFIX %+ _DH_set0_key
|
||||
%xdefine DH_set0_pqg BORINGSSL_PREFIX %+ _DH_set0_pqg
|
||||
%xdefine DH_set_ex_data BORINGSSL_PREFIX %+ _DH_set_ex_data
|
||||
%xdefine DH_set_length BORINGSSL_PREFIX %+ _DH_set_length
|
||||
%xdefine DH_size BORINGSSL_PREFIX %+ _DH_size
|
||||
%xdefine DH_up_ref BORINGSSL_PREFIX %+ _DH_up_ref
|
||||
@@ -4321,6 +4321,8 @@
|
||||
%xdefine EVP_HPKE_CTX_setup_psk_r_x25519 BORINGSSL_PREFIX %+ _EVP_HPKE_CTX_setup_psk_r_x25519
|
||||
%xdefine EVP_HPKE_CTX_setup_psk_s_x25519 BORINGSSL_PREFIX %+ _EVP_HPKE_CTX_setup_psk_s_x25519
|
||||
%xdefine EVP_HPKE_CTX_setup_psk_s_x25519_for_test BORINGSSL_PREFIX %+ _EVP_HPKE_CTX_setup_psk_s_x25519_for_test
|
||||
%xdefine EVP_HPKE_get_aead BORINGSSL_PREFIX %+ _EVP_HPKE_get_aead
|
||||
%xdefine EVP_HPKE_get_hkdf_md BORINGSSL_PREFIX %+ _EVP_HPKE_get_hkdf_md
|
||||
%xdefine EVP_MD_CTX_block_size BORINGSSL_PREFIX %+ _EVP_MD_CTX_block_size
|
||||
%xdefine EVP_MD_CTX_cleanup BORINGSSL_PREFIX %+ _EVP_MD_CTX_cleanup
|
||||
%xdefine EVP_MD_CTX_copy BORINGSSL_PREFIX %+ _EVP_MD_CTX_copy
|
||||
@@ -5330,6 +5332,7 @@
|
||||
%xdefine SSL_set_connect_state BORINGSSL_PREFIX %+ _SSL_set_connect_state
|
||||
%xdefine SSL_set_custom_verify BORINGSSL_PREFIX %+ _SSL_set_custom_verify
|
||||
%xdefine SSL_set_early_data_enabled BORINGSSL_PREFIX %+ _SSL_set_early_data_enabled
|
||||
%xdefine SSL_set_enable_ech_grease BORINGSSL_PREFIX %+ _SSL_set_enable_ech_grease
|
||||
%xdefine SSL_set_enforce_rsa_key_usage BORINGSSL_PREFIX %+ _SSL_set_enforce_rsa_key_usage
|
||||
%xdefine SSL_set_ex_data BORINGSSL_PREFIX %+ _SSL_set_ex_data
|
||||
%xdefine SSL_set_fd BORINGSSL_PREFIX %+ _SSL_set_fd
|
||||
@@ -5353,6 +5356,7 @@
|
||||
%xdefine SSL_set_quic_early_data_context BORINGSSL_PREFIX %+ _SSL_set_quic_early_data_context
|
||||
%xdefine SSL_set_quic_method BORINGSSL_PREFIX %+ _SSL_set_quic_method
|
||||
%xdefine SSL_set_quic_transport_params BORINGSSL_PREFIX %+ _SSL_set_quic_transport_params
|
||||
%xdefine SSL_set_quic_use_legacy_codepoint BORINGSSL_PREFIX %+ _SSL_set_quic_use_legacy_codepoint
|
||||
%xdefine SSL_set_quiet_shutdown BORINGSSL_PREFIX %+ _SSL_set_quiet_shutdown
|
||||
%xdefine SSL_set_read_ahead BORINGSSL_PREFIX %+ _SSL_set_read_ahead
|
||||
%xdefine SSL_set_renegotiate_mode BORINGSSL_PREFIX %+ _SSL_set_renegotiate_mode
|
||||
|
||||
@@ -1638,6 +1638,10 @@ struct SSL_HANDSHAKE {
|
||||
// cookie is the value of the cookie received from the server, if any.
|
||||
Array<uint8_t> cookie;
|
||||
|
||||
// ech_grease contains the bytes of the GREASE ECH extension that was sent in
|
||||
// the first ClientHello.
|
||||
Array<uint8_t> ech_grease;
|
||||
|
||||
// key_share_bytes is the value of the previously sent KeyShare extension by
|
||||
// the client in TLS 1.3.
|
||||
Array<uint8_t> key_share_bytes;
|
||||
@@ -2729,6 +2733,10 @@ struct SSL_CONFIG {
|
||||
// verify_mode is a bitmask of |SSL_VERIFY_*| values.
|
||||
uint8_t verify_mode = SSL_VERIFY_NONE;
|
||||
|
||||
// ech_grease_enabled controls whether ECH GREASE may be sent in the
|
||||
// ClientHello.
|
||||
bool ech_grease_enabled : 1;
|
||||
|
||||
// Enable signed certificate time stamps. Currently client only.
|
||||
bool signed_cert_timestamps_enabled : 1;
|
||||
|
||||
@@ -2764,6 +2772,10 @@ struct SSL_CONFIG {
|
||||
// jdk11_workaround is whether to disable TLS 1.3 for JDK 11 clients, as a
|
||||
// workaround for https://bugs.openjdk.java.net/browse/JDK-8211806.
|
||||
bool jdk11_workaround : 1;
|
||||
|
||||
// QUIC drafts up to and including 32 used a different TLS extension
|
||||
// codepoint to convey QUIC's transport parameters.
|
||||
bool quic_use_legacy_codepoint : 1;
|
||||
};
|
||||
|
||||
// From RFC 8446, used in determining PSK modes.
|
||||
|
||||
@@ -722,6 +722,7 @@ SSL *SSL_new(SSL_CTX *ctx) {
|
||||
|
||||
SSL_CONFIG::SSL_CONFIG(SSL *ssl_arg)
|
||||
: ssl(ssl_arg),
|
||||
ech_grease_enabled(false),
|
||||
signed_cert_timestamps_enabled(false),
|
||||
ocsp_stapling_enabled(false),
|
||||
channel_id_enabled(false),
|
||||
@@ -729,7 +730,8 @@ SSL_CONFIG::SSL_CONFIG(SSL *ssl_arg)
|
||||
retain_only_sha256_of_client_certs(false),
|
||||
handoff(false),
|
||||
shed_handshake_config(false),
|
||||
jdk11_workaround(false) {
|
||||
jdk11_workaround(false),
|
||||
quic_use_legacy_codepoint(true) {
|
||||
assert(ssl);
|
||||
}
|
||||
|
||||
@@ -1466,6 +1468,13 @@ const char *SSL_error_description(int err) {
|
||||
}
|
||||
}
|
||||
|
||||
void SSL_set_enable_ech_grease(SSL *ssl, int enable) {
|
||||
if (!ssl->config) {
|
||||
return;
|
||||
}
|
||||
ssl->config->ech_grease_enabled = !!enable;
|
||||
}
|
||||
|
||||
uint32_t SSL_CTX_set_options(SSL_CTX *ctx, uint32_t options) {
|
||||
ctx->options |= options;
|
||||
return ctx->options;
|
||||
@@ -2950,6 +2959,13 @@ void SSL_set_jdk11_workaround(SSL *ssl, int enable) {
|
||||
ssl->config->jdk11_workaround = !!enable;
|
||||
}
|
||||
|
||||
void SSL_set_quic_use_legacy_codepoint(SSL *ssl, int use_legacy) {
|
||||
if (!ssl->config) {
|
||||
return;
|
||||
}
|
||||
ssl->config->quic_use_legacy_codepoint = !!use_legacy;
|
||||
}
|
||||
|
||||
int SSL_clear(SSL *ssl) {
|
||||
if (!ssl->config) {
|
||||
return 0; // SSL_clear may not be used after shedding config.
|
||||
|
||||
@@ -113,10 +113,13 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
#include <CNIOBoringSSL_aead.h>
|
||||
#include <CNIOBoringSSL_bytestring.h>
|
||||
#include <CNIOBoringSSL_chacha.h>
|
||||
#include <CNIOBoringSSL_curve25519.h>
|
||||
#include <CNIOBoringSSL_digest.h>
|
||||
#include <CNIOBoringSSL_err.h>
|
||||
#include <CNIOBoringSSL_evp.h>
|
||||
@@ -125,6 +128,7 @@
|
||||
#include <CNIOBoringSSL_nid.h>
|
||||
#include <CNIOBoringSSL_rand.h>
|
||||
|
||||
#include "../crypto/hpke/internal.h"
|
||||
#include "../crypto/internal.h"
|
||||
#include "internal.h"
|
||||
|
||||
@@ -587,6 +591,160 @@ static bool ext_sni_add_serverhello(SSL_HANDSHAKE *hs, CBB *out) {
|
||||
}
|
||||
|
||||
|
||||
// Encrypted Client Hello (ECH)
|
||||
//
|
||||
// https://tools.ietf.org/html/draft-ietf-tls-esni-08
|
||||
|
||||
// random_size returns a random value between |min| and |max|, inclusive.
|
||||
static size_t random_size(size_t min, size_t max) {
|
||||
assert(min < max);
|
||||
size_t value;
|
||||
RAND_bytes(reinterpret_cast<uint8_t *>(&value), sizeof(value));
|
||||
return value % (max - min + 1) + min;
|
||||
}
|
||||
|
||||
static bool ext_ech_add_clienthello_grease(SSL_HANDSHAKE *hs, CBB *out) {
|
||||
// If we are responding to the server's HelloRetryRequest, we repeat the bytes
|
||||
// of the first ECH GREASE extension.
|
||||
if (hs->ssl->s3->used_hello_retry_request) {
|
||||
CBB ech_body;
|
||||
if (!CBB_add_u16(out, TLSEXT_TYPE_encrypted_client_hello) ||
|
||||
!CBB_add_u16_length_prefixed(out, &ech_body) ||
|
||||
!CBB_add_bytes(&ech_body, hs->ech_grease.data(),
|
||||
hs->ech_grease.size()) ||
|
||||
!CBB_flush(out)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
constexpr uint16_t kdf_id = EVP_HPKE_HKDF_SHA256;
|
||||
const EVP_MD *kdf = EVP_HPKE_get_hkdf_md(kdf_id);
|
||||
assert(kdf != nullptr);
|
||||
|
||||
const uint16_t aead_id = EVP_has_aes_hardware()
|
||||
? EVP_HPKE_AEAD_AES_GCM_128
|
||||
: EVP_HPKE_AEAD_CHACHA20POLY1305;
|
||||
const EVP_AEAD *aead = EVP_HPKE_get_aead(aead_id);
|
||||
assert(aead != nullptr);
|
||||
|
||||
uint8_t ech_config_id_buf[EVP_MAX_MD_SIZE];
|
||||
Span<uint8_t> ech_config_id(ech_config_id_buf, EVP_MD_size(kdf));
|
||||
RAND_bytes(ech_config_id.data(), ech_config_id.size());
|
||||
|
||||
uint8_t ech_enc[X25519_PUBLIC_VALUE_LEN];
|
||||
uint8_t private_key_unused[X25519_PRIVATE_KEY_LEN];
|
||||
X25519_keypair(ech_enc, private_key_unused);
|
||||
|
||||
// To determine a plausible length for the payload, we first estimate the size
|
||||
// of a typical EncodedClientHelloInner, with an expected use of
|
||||
// outer_extensions. To limit the size, we only consider initial ClientHellos
|
||||
// that do not offer resumption.
|
||||
//
|
||||
// Field/Extension Size
|
||||
// ---------------------------------------------------------------------
|
||||
// version 2
|
||||
// random 32
|
||||
// legacy_session_id 1
|
||||
// - Has a U8 length prefix, but body is
|
||||
// always empty string in inner CH.
|
||||
// cipher_suites 2 (length prefix)
|
||||
// - Only includes TLS 1.3 ciphers (3). 6
|
||||
// - Maybe also include a GREASE suite. 2
|
||||
// legacy_compression_methods 2 (length prefix)
|
||||
// - Always has "null" compression method. 1
|
||||
// extensions: 2 (length prefix)
|
||||
// - encrypted_client_hello (empty). 4 (id + length prefix)
|
||||
// - supported_versions. 4 (id + length prefix)
|
||||
// - U8 length prefix 1
|
||||
// - U16 protocol version (TLS 1.3) 2
|
||||
// - outer_extensions. 4 (id + length prefix)
|
||||
// - U8 length prefix 1
|
||||
// - N extension IDs (2 bytes each):
|
||||
// - key_share 2
|
||||
// - sigalgs 2
|
||||
// - sct 2
|
||||
// - alpn 2
|
||||
// - supported_groups. 2
|
||||
// - status_request. 2
|
||||
// - psk_key_exchange_modes. 2
|
||||
// - compress_certificate. 2
|
||||
//
|
||||
// The server_name extension has an overhead of 9 bytes, plus up to an
|
||||
// estimated 100 bytes of hostname. Rounding up to a multiple of 32 yields a
|
||||
// range of 96 to 192. Note that this estimate does not fully capture
|
||||
// optional extensions like GREASE, but the rounding gives some leeway.
|
||||
|
||||
uint8_t payload[EVP_AEAD_MAX_OVERHEAD + 192];
|
||||
const size_t payload_len =
|
||||
EVP_AEAD_max_overhead(aead) + 32 * random_size(96 / 32, 192 / 32);
|
||||
assert(payload_len <= sizeof(payload));
|
||||
RAND_bytes(payload, payload_len);
|
||||
|
||||
// Inside the TLS extension contents, write a serialized ClientEncryptedCH.
|
||||
CBB ech_body, config_id_cbb, enc_cbb, payload_cbb;
|
||||
if (!CBB_add_u16(out, TLSEXT_TYPE_encrypted_client_hello) ||
|
||||
!CBB_add_u16_length_prefixed(out, &ech_body) ||
|
||||
!CBB_add_u16(&ech_body, kdf_id) || //
|
||||
!CBB_add_u16(&ech_body, aead_id) ||
|
||||
!CBB_add_u8_length_prefixed(&ech_body, &config_id_cbb) ||
|
||||
!CBB_add_bytes(&config_id_cbb, ech_config_id.data(),
|
||||
ech_config_id.size()) ||
|
||||
!CBB_add_u16_length_prefixed(&ech_body, &enc_cbb) ||
|
||||
!CBB_add_bytes(&enc_cbb, ech_enc, OPENSSL_ARRAY_SIZE(ech_enc)) ||
|
||||
!CBB_add_u16_length_prefixed(&ech_body, &payload_cbb) ||
|
||||
!CBB_add_bytes(&payload_cbb, payload, payload_len) || //
|
||||
!CBB_flush(&ech_body)) {
|
||||
return false;
|
||||
}
|
||||
// Save the bytes of the newly-generated extension in case the server sends
|
||||
// a HelloRetryRequest.
|
||||
if (!hs->ech_grease.CopyFrom(
|
||||
MakeConstSpan(CBB_data(&ech_body), CBB_len(&ech_body)))) {
|
||||
return false;
|
||||
}
|
||||
return CBB_flush(out);
|
||||
}
|
||||
|
||||
static bool ext_ech_add_clienthello(SSL_HANDSHAKE *hs, CBB *out) {
|
||||
if (hs->max_version < TLS1_3_VERSION) {
|
||||
return true;
|
||||
}
|
||||
if (hs->config->ech_grease_enabled) {
|
||||
return ext_ech_add_clienthello_grease(hs, out);
|
||||
}
|
||||
// Nothing to do, since we don't yet implement the non-GREASE parts of ECH.
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool ext_ech_parse_serverhello(SSL_HANDSHAKE *hs, uint8_t *out_alert,
|
||||
CBS *contents) {
|
||||
if (contents == NULL) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// If the client only sent GREASE, we must check the extension syntactically.
|
||||
CBS ech_configs;
|
||||
if (!CBS_get_u16_length_prefixed(contents, &ech_configs) ||
|
||||
CBS_len(&ech_configs) == 0 || //
|
||||
CBS_len(contents) > 0) {
|
||||
*out_alert = SSL_AD_DECODE_ERROR;
|
||||
return false;
|
||||
}
|
||||
while (CBS_len(&ech_configs) > 0) {
|
||||
// Do a top-level parse of the ECHConfig, stopping before ECHConfigContents.
|
||||
uint16_t version;
|
||||
CBS ech_config_contents;
|
||||
if (!CBS_get_u16(&ech_configs, &version) ||
|
||||
!CBS_get_u16_length_prefixed(&ech_configs, &ech_config_contents)) {
|
||||
*out_alert = SSL_AD_DECODE_ERROR;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Renegotiation indication.
|
||||
//
|
||||
// https://tools.ietf.org/html/rfc5746
|
||||
@@ -2592,8 +2750,8 @@ static bool ext_token_binding_add_serverhello(SSL_HANDSHAKE *hs, CBB *out) {
|
||||
|
||||
// QUIC Transport Parameters
|
||||
|
||||
static bool ext_quic_transport_params_add_clienthello(SSL_HANDSHAKE *hs,
|
||||
CBB *out) {
|
||||
static bool ext_quic_transport_params_add_clienthello_impl(
|
||||
SSL_HANDSHAKE *hs, CBB *out, bool use_legacy_codepoint) {
|
||||
if (hs->config->quic_transport_params.empty() && !hs->ssl->quic_method) {
|
||||
return true;
|
||||
}
|
||||
@@ -2605,9 +2763,18 @@ static bool ext_quic_transport_params_add_clienthello(SSL_HANDSHAKE *hs,
|
||||
return false;
|
||||
}
|
||||
assert(hs->min_version > TLS1_2_VERSION);
|
||||
if (use_legacy_codepoint != hs->config->quic_use_legacy_codepoint) {
|
||||
// Do nothing, we'll send the other codepoint.
|
||||
return true;
|
||||
}
|
||||
|
||||
uint16_t extension_type = TLSEXT_TYPE_quic_transport_parameters;
|
||||
if (hs->config->quic_use_legacy_codepoint) {
|
||||
extension_type = TLSEXT_TYPE_quic_transport_parameters_legacy;
|
||||
}
|
||||
|
||||
CBB contents;
|
||||
if (!CBB_add_u16(out, TLSEXT_TYPE_quic_transport_parameters) ||
|
||||
if (!CBB_add_u16(out, extension_type) ||
|
||||
!CBB_add_u16_length_prefixed(out, &contents) ||
|
||||
!CBB_add_bytes(&contents, hs->config->quic_transport_params.data(),
|
||||
hs->config->quic_transport_params.size()) ||
|
||||
@@ -2617,31 +2784,61 @@ static bool ext_quic_transport_params_add_clienthello(SSL_HANDSHAKE *hs,
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool ext_quic_transport_params_parse_serverhello(SSL_HANDSHAKE *hs,
|
||||
uint8_t *out_alert,
|
||||
CBS *contents) {
|
||||
static bool ext_quic_transport_params_add_clienthello(SSL_HANDSHAKE *hs,
|
||||
CBB *out) {
|
||||
return ext_quic_transport_params_add_clienthello_impl(
|
||||
hs, out, /*use_legacy_codepoint=*/false);
|
||||
}
|
||||
|
||||
static bool ext_quic_transport_params_add_clienthello_legacy(SSL_HANDSHAKE *hs,
|
||||
CBB *out) {
|
||||
return ext_quic_transport_params_add_clienthello_impl(
|
||||
hs, out, /*use_legacy_codepoint=*/true);
|
||||
}
|
||||
|
||||
static bool ext_quic_transport_params_parse_serverhello_impl(
|
||||
SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents,
|
||||
bool used_legacy_codepoint) {
|
||||
SSL *const ssl = hs->ssl;
|
||||
if (contents == nullptr) {
|
||||
if (used_legacy_codepoint != hs->config->quic_use_legacy_codepoint) {
|
||||
// Silently ignore because we expect the other QUIC codepoint.
|
||||
return true;
|
||||
}
|
||||
if (!ssl->quic_method) {
|
||||
return true;
|
||||
}
|
||||
assert(ssl->quic_method);
|
||||
*out_alert = SSL_AD_MISSING_EXTENSION;
|
||||
return false;
|
||||
}
|
||||
if (!ssl->quic_method) {
|
||||
*out_alert = SSL_AD_UNSUPPORTED_EXTENSION;
|
||||
return false;
|
||||
}
|
||||
// QUIC requires TLS 1.3.
|
||||
// The extensions parser will check for unsolicited extensions before
|
||||
// calling the callback.
|
||||
assert(ssl->quic_method != nullptr);
|
||||
assert(ssl_protocol_version(ssl) == TLS1_3_VERSION);
|
||||
|
||||
assert(used_legacy_codepoint == hs->config->quic_use_legacy_codepoint);
|
||||
return ssl->s3->peer_quic_transport_params.CopyFrom(*contents);
|
||||
}
|
||||
|
||||
static bool ext_quic_transport_params_parse_clienthello(SSL_HANDSHAKE *hs,
|
||||
static bool ext_quic_transport_params_parse_serverhello(SSL_HANDSHAKE *hs,
|
||||
uint8_t *out_alert,
|
||||
CBS *contents) {
|
||||
return ext_quic_transport_params_parse_serverhello_impl(
|
||||
hs, out_alert, contents, /*used_legacy_codepoint=*/false);
|
||||
}
|
||||
|
||||
static bool ext_quic_transport_params_parse_serverhello_legacy(
|
||||
SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents) {
|
||||
return ext_quic_transport_params_parse_serverhello_impl(
|
||||
hs, out_alert, contents, /*used_legacy_codepoint=*/true);
|
||||
}
|
||||
|
||||
static bool ext_quic_transport_params_parse_clienthello_impl(
|
||||
SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents,
|
||||
bool used_legacy_codepoint) {
|
||||
if (used_legacy_codepoint != hs->config->quic_use_legacy_codepoint) {
|
||||
// Silently ignore because we expect the other QUIC codepoint.
|
||||
return true;
|
||||
}
|
||||
SSL *const ssl = hs->ssl;
|
||||
if (!contents) {
|
||||
if (!ssl->quic_method) {
|
||||
@@ -2664,17 +2861,39 @@ static bool ext_quic_transport_params_parse_clienthello(SSL_HANDSHAKE *hs,
|
||||
return ssl->s3->peer_quic_transport_params.CopyFrom(*contents);
|
||||
}
|
||||
|
||||
static bool ext_quic_transport_params_add_serverhello(SSL_HANDSHAKE *hs,
|
||||
CBB *out) {
|
||||
static bool ext_quic_transport_params_parse_clienthello(SSL_HANDSHAKE *hs,
|
||||
uint8_t *out_alert,
|
||||
CBS *contents) {
|
||||
return ext_quic_transport_params_parse_clienthello_impl(
|
||||
hs, out_alert, contents, /*used_legacy_codepoint=*/false);
|
||||
}
|
||||
|
||||
static bool ext_quic_transport_params_parse_clienthello_legacy(
|
||||
SSL_HANDSHAKE *hs, uint8_t *out_alert, CBS *contents) {
|
||||
return ext_quic_transport_params_parse_clienthello_impl(
|
||||
hs, out_alert, contents, /*used_legacy_codepoint=*/true);
|
||||
}
|
||||
|
||||
static bool ext_quic_transport_params_add_serverhello_impl(
|
||||
SSL_HANDSHAKE *hs, CBB *out, bool use_legacy_codepoint) {
|
||||
assert(hs->ssl->quic_method != nullptr);
|
||||
if (hs->config->quic_transport_params.empty()) {
|
||||
// Transport parameters must be set when using QUIC.
|
||||
OPENSSL_PUT_ERROR(SSL, SSL_R_QUIC_TRANSPORT_PARAMETERS_MISCONFIGURED);
|
||||
return false;
|
||||
}
|
||||
if (use_legacy_codepoint != hs->config->quic_use_legacy_codepoint) {
|
||||
// Do nothing, we'll send the other codepoint.
|
||||
return true;
|
||||
}
|
||||
|
||||
uint16_t extension_type = TLSEXT_TYPE_quic_transport_parameters;
|
||||
if (hs->config->quic_use_legacy_codepoint) {
|
||||
extension_type = TLSEXT_TYPE_quic_transport_parameters_legacy;
|
||||
}
|
||||
|
||||
CBB contents;
|
||||
if (!CBB_add_u16(out, TLSEXT_TYPE_quic_transport_parameters) ||
|
||||
if (!CBB_add_u16(out, extension_type) ||
|
||||
!CBB_add_u16_length_prefixed(out, &contents) ||
|
||||
!CBB_add_bytes(&contents, hs->config->quic_transport_params.data(),
|
||||
hs->config->quic_transport_params.size()) ||
|
||||
@@ -2685,6 +2904,18 @@ static bool ext_quic_transport_params_add_serverhello(SSL_HANDSHAKE *hs,
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool ext_quic_transport_params_add_serverhello(SSL_HANDSHAKE *hs,
|
||||
CBB *out) {
|
||||
return ext_quic_transport_params_add_serverhello_impl(
|
||||
hs, out, /*use_legacy_codepoint=*/false);
|
||||
}
|
||||
|
||||
static bool ext_quic_transport_params_add_serverhello_legacy(SSL_HANDSHAKE *hs,
|
||||
CBB *out) {
|
||||
return ext_quic_transport_params_add_serverhello_impl(
|
||||
hs, out, /*use_legacy_codepoint=*/true);
|
||||
}
|
||||
|
||||
// Delegated credentials.
|
||||
//
|
||||
// https://tools.ietf.org/html/draft-ietf-tls-subcerts
|
||||
@@ -2970,6 +3201,14 @@ static const struct tls_extension kExtensions[] = {
|
||||
ext_sni_parse_clienthello,
|
||||
ext_sni_add_serverhello,
|
||||
},
|
||||
{
|
||||
TLSEXT_TYPE_encrypted_client_hello,
|
||||
NULL,
|
||||
ext_ech_add_clienthello,
|
||||
ext_ech_parse_serverhello,
|
||||
ignore_parse_clienthello,
|
||||
dont_add_serverhello,
|
||||
},
|
||||
{
|
||||
TLSEXT_TYPE_extended_master_secret,
|
||||
NULL,
|
||||
@@ -3116,6 +3355,14 @@ static const struct tls_extension kExtensions[] = {
|
||||
ext_quic_transport_params_parse_clienthello,
|
||||
ext_quic_transport_params_add_serverhello,
|
||||
},
|
||||
{
|
||||
TLSEXT_TYPE_quic_transport_parameters_legacy,
|
||||
NULL,
|
||||
ext_quic_transport_params_add_clienthello_legacy,
|
||||
ext_quic_transport_params_parse_serverhello_legacy,
|
||||
ext_quic_transport_params_parse_clienthello_legacy,
|
||||
ext_quic_transport_params_add_serverhello_legacy,
|
||||
},
|
||||
{
|
||||
TLSEXT_TYPE_token_binding,
|
||||
NULL,
|
||||
|
||||
Reference in new issue
Block a user