Skip to content

Update BoringSSL to 67818bea6690a230e2f42e8a588e0f54949bbbf1 #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// Sources/CCryptoBoringSSL directory. The source repository is at
// https://boringssl.googlesource.com/boringssl.
//
// BoringSSL Commit: 54858b63c1d886f6c8d903d4a4f594f1485de189
// BoringSSL Commit: 67818bea6690a230e2f42e8a588e0f54949bbbf1

import PackageDescription

Expand Down
6 changes: 0 additions & 6 deletions Sources/CCryptoBoringSSL/crypto/asn1/asn1_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,12 +424,6 @@ int ASN1_STRING_length(const ASN1_STRING *x)
return M_ASN1_STRING_length(x);
}

void ASN1_STRING_length_set(ASN1_STRING *x, int len)
{
M_ASN1_STRING_length_set(x, len);
return;
}

int ASN1_STRING_type(const ASN1_STRING *x)
{
return M_ASN1_STRING_type(x);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Lone:

.align 5
_ChaCha20_ctr32:
AARCH64_VALID_CALL_TARGET
cbz x2,Labort
#if __has_feature(hwaddress_sanitizer) && __clang_major__ >= 10
adrp x5,:pg_hi21_nc:_OPENSSL_armcap_P
Expand All @@ -48,6 +49,7 @@ _ChaCha20_ctr32:
b.ne ChaCha20_neon

Lshort:
AARCH64_SIGN_LINK_REGISTER
stp x29,x30,[sp,#-96]!
add x29,sp,#0

Expand Down Expand Up @@ -260,6 +262,7 @@ Loop:
ldp x25,x26,[x29,#64]
ldp x27,x28,[x29,#80]
ldp x29,x30,[sp],#96
AARCH64_VALIDATE_LINK_REGISTER
Labort:
ret

Expand Down Expand Up @@ -316,12 +319,14 @@ Loop_tail:
ldp x25,x26,[x29,#64]
ldp x27,x28,[x29,#80]
ldp x29,x30,[sp],#96
AARCH64_VALIDATE_LINK_REGISTER
ret



.align 5
ChaCha20_neon:
AARCH64_SIGN_LINK_REGISTER
stp x29,x30,[sp,#-96]!
add x29,sp,#0

Expand Down Expand Up @@ -702,6 +707,7 @@ Loop_neon:
ldp x25,x26,[x29,#64]
ldp x27,x28,[x29,#80]
ldp x29,x30,[sp],#96
AARCH64_VALIDATE_LINK_REGISTER
ret

Ltail_neon:
Expand Down Expand Up @@ -811,11 +817,13 @@ Ldone_neon:
ldp x25,x26,[x29,#64]
ldp x27,x28,[x29,#80]
ldp x29,x30,[sp],#96
AARCH64_VALIDATE_LINK_REGISTER
ret


.align 5
ChaCha20_512_neon:
AARCH64_SIGN_LINK_REGISTER
stp x29,x30,[sp,#-96]!
add x29,sp,#0

Expand Down Expand Up @@ -1979,6 +1987,7 @@ Ldone_512_neon:
ldp x25,x26,[x29,#64]
ldp x27,x28,[x29,#80]
ldp x29,x30,[sp],#96
AARCH64_VALIDATE_LINK_REGISTER
ret

#endif // !OPENSSL_NO_ASM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
.type ChaCha20_ctr32,%function
.align 5
ChaCha20_ctr32:
AARCH64_VALID_CALL_TARGET
cbz x2,.Labort
#if __has_feature(hwaddress_sanitizer) && __clang_major__ >= 10
adrp x5,:pg_hi21_nc:OPENSSL_armcap_P
Expand All @@ -49,6 +50,7 @@ ChaCha20_ctr32:
b.ne ChaCha20_neon

.Lshort:
AARCH64_SIGN_LINK_REGISTER
stp x29,x30,[sp,#-96]!
add x29,sp,#0

Expand Down Expand Up @@ -261,6 +263,7 @@ ChaCha20_ctr32:
ldp x25,x26,[x29,#64]
ldp x27,x28,[x29,#80]
ldp x29,x30,[sp],#96
AARCH64_VALIDATE_LINK_REGISTER
.Labort:
ret

Expand Down Expand Up @@ -317,12 +320,14 @@ ChaCha20_ctr32:
ldp x25,x26,[x29,#64]
ldp x27,x28,[x29,#80]
ldp x29,x30,[sp],#96
AARCH64_VALIDATE_LINK_REGISTER
ret
.size ChaCha20_ctr32,.-ChaCha20_ctr32

.type ChaCha20_neon,%function
.align 5
ChaCha20_neon:
AARCH64_SIGN_LINK_REGISTER
stp x29,x30,[sp,#-96]!
add x29,sp,#0

Expand Down Expand Up @@ -703,6 +708,7 @@ ChaCha20_neon:
ldp x25,x26,[x29,#64]
ldp x27,x28,[x29,#80]
ldp x29,x30,[sp],#96
AARCH64_VALIDATE_LINK_REGISTER
ret

.Ltail_neon:
Expand Down Expand Up @@ -812,11 +818,13 @@ ChaCha20_neon:
ldp x25,x26,[x29,#64]
ldp x27,x28,[x29,#80]
ldp x29,x30,[sp],#96
AARCH64_VALIDATE_LINK_REGISTER
ret
.size ChaCha20_neon,.-ChaCha20_neon
.type ChaCha20_512_neon,%function
.align 5
ChaCha20_512_neon:
AARCH64_SIGN_LINK_REGISTER
stp x29,x30,[sp,#-96]!
add x29,sp,#0

Expand Down Expand Up @@ -1980,6 +1988,7 @@ ChaCha20_512_neon:
ldp x25,x26,[x29,#64]
ldp x27,x28,[x29,#80]
ldp x29,x30,[sp],#96
AARCH64_VALIDATE_LINK_REGISTER
ret
.size ChaCha20_512_neon,.-ChaCha20_512_neon
#endif
Expand Down
52 changes: 9 additions & 43 deletions Sources/CCryptoBoringSSL/crypto/dsa/dsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,11 @@
#include <CCryptoBoringSSL_sha.h>
#include <CCryptoBoringSSL_thread.h>

#include "internal.h"
#include "../fipsmodule/bn/internal.h"
#include "../internal.h"


#define OPENSSL_DSA_MAX_MODULUS_BITS 10000

// Primality test according to FIPS PUB 186[-1], Appendix 2.1: 50 rounds of
// Miller-Rabin.
#define DSS_prime_checks 50
Expand Down Expand Up @@ -568,23 +567,7 @@ static int mod_mul_consttime(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
}

DSA_SIG *DSA_do_sign(const uint8_t *digest, size_t digest_len, const DSA *dsa) {
if (!dsa->p || !dsa->q || !dsa->g) {
OPENSSL_PUT_ERROR(DSA, DSA_R_MISSING_PARAMETERS);
return NULL;
}

// Reject invalid parameters. In particular, the algorithm will infinite loop
// if |g| is zero.
if (BN_is_zero(dsa->p) || BN_is_zero(dsa->q) || BN_is_zero(dsa->g)) {
OPENSSL_PUT_ERROR(DSA, DSA_R_INVALID_PARAMETERS);
return NULL;
}

// We only support DSA keys that are a multiple of 8 bits. (This is a weaker
// check than the one in |DSA_do_check_signature|, which only allows 160-,
// 224-, and 256-bit keys.
if (BN_num_bits(dsa->q) % 8 != 0) {
OPENSSL_PUT_ERROR(DSA, DSA_R_BAD_Q_VALUE);
if (!dsa_check_parameters(dsa)) {
return NULL;
}

Expand Down Expand Up @@ -678,35 +661,17 @@ int DSA_do_verify(const uint8_t *digest, size_t digest_len, DSA_SIG *sig,

int DSA_do_check_signature(int *out_valid, const uint8_t *digest,
size_t digest_len, DSA_SIG *sig, const DSA *dsa) {
BN_CTX *ctx;
BIGNUM u1, u2, t1;
int ret = 0;
unsigned i;

*out_valid = 0;

if (!dsa->p || !dsa->q || !dsa->g) {
OPENSSL_PUT_ERROR(DSA, DSA_R_MISSING_PARAMETERS);
return 0;
}

i = BN_num_bits(dsa->q);
// FIPS 186-3 allows only different sizes for q.
if (i != 160 && i != 224 && i != 256) {
OPENSSL_PUT_ERROR(DSA, DSA_R_BAD_Q_VALUE);
return 0;
}

if (BN_num_bits(dsa->p) > OPENSSL_DSA_MAX_MODULUS_BITS) {
OPENSSL_PUT_ERROR(DSA, DSA_R_MODULUS_TOO_LARGE);
if (!dsa_check_parameters(dsa)) {
return 0;
}

int ret = 0;
BIGNUM u1, u2, t1;
BN_init(&u1);
BN_init(&u2);
BN_init(&t1);

ctx = BN_CTX_new();
BN_CTX *ctx = BN_CTX_new();
if (ctx == NULL) {
goto err;
}
Expand All @@ -729,11 +694,12 @@ int DSA_do_check_signature(int *out_valid, const uint8_t *digest,
}

// save M in u1
if (digest_len > (i >> 3)) {
unsigned q_bits = BN_num_bits(dsa->q);
if (digest_len > (q_bits >> 3)) {
// if the digest length is greater than the size of q use the
// BN_num_bits(dsa->q) leftmost bits of the digest, see
// fips 186-3, 4.2
digest_len = (i >> 3);
digest_len = (q_bits >> 3);
}

if (BN_bin2bn(digest, digest_len, &u1) == NULL) {
Expand Down
59 changes: 55 additions & 4 deletions Sources/CCryptoBoringSSL/crypto/dsa/dsa_asn1.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,45 @@
#include <CCryptoBoringSSL_err.h>
#include <CCryptoBoringSSL_mem.h>

#include "internal.h"
#include "../bytestring/internal.h"


#define OPENSSL_DSA_MAX_MODULUS_BITS 10000

// This function is in dsa_asn1.c rather than dsa.c because it is reachable from
// |EVP_PKEY| parsers. This makes it easier for the static linker to drop most
// of the DSA implementation.
int dsa_check_parameters(const DSA *dsa) {
if (!dsa->p || !dsa->q || !dsa->g) {
OPENSSL_PUT_ERROR(DSA, DSA_R_MISSING_PARAMETERS);
return 0;
}

// Reject invalid parameters. In particular, signing will infinite loop if |g|
// is zero.
if (BN_is_zero(dsa->p) || BN_is_zero(dsa->q) || BN_is_zero(dsa->g)) {
OPENSSL_PUT_ERROR(DSA, DSA_R_INVALID_PARAMETERS);
return 0;
}

// FIPS 186-4 allows only three different sizes for q.
unsigned q_bits = BN_num_bits(dsa->q);
if (q_bits != 160 && q_bits != 224 && q_bits != 256) {
OPENSSL_PUT_ERROR(DSA, DSA_R_BAD_Q_VALUE);
return 0;
}

// Bound |dsa->p| to avoid a DoS vector. Note this limit is much larger than
// the one in FIPS 186-4, which only allows L = 1024, 2048, and 3072.
if (BN_num_bits(dsa->p) > OPENSSL_DSA_MAX_MODULUS_BITS) {
OPENSSL_PUT_ERROR(DSA, DSA_R_MODULUS_TOO_LARGE);
return 0;
}

return 1;
}

static int parse_integer(CBS *cbs, BIGNUM **out) {
assert(*out == NULL);
*out = BN_new();
Expand Down Expand Up @@ -124,10 +160,16 @@ DSA *DSA_parse_public_key(CBS *cbs) {
!parse_integer(&child, &ret->g) ||
CBS_len(&child) != 0) {
OPENSSL_PUT_ERROR(DSA, DSA_R_DECODE_ERROR);
DSA_free(ret);
return NULL;
goto err;
}
if (!dsa_check_parameters(ret)) {
goto err;
}
return ret;

err:
DSA_free(ret);
return NULL;
}

int DSA_marshal_public_key(CBB *cbb, const DSA *dsa) {
Expand Down Expand Up @@ -156,10 +198,16 @@ DSA *DSA_parse_parameters(CBS *cbs) {
!parse_integer(&child, &ret->g) ||
CBS_len(&child) != 0) {
OPENSSL_PUT_ERROR(DSA, DSA_R_DECODE_ERROR);
DSA_free(ret);
return NULL;
goto err;
}
if (!dsa_check_parameters(ret)) {
goto err;
}
return ret;

err:
DSA_free(ret);
return NULL;
}

int DSA_marshal_parameters(CBB *cbb, const DSA *dsa) {
Expand Down Expand Up @@ -203,6 +251,9 @@ DSA *DSA_parse_private_key(CBS *cbs) {
OPENSSL_PUT_ERROR(DSA, DSA_R_DECODE_ERROR);
goto err;
}
if (!dsa_check_parameters(ret)) {
goto err;
}
return ret;

err:
Expand Down
34 changes: 34 additions & 0 deletions Sources/CCryptoBoringSSL/crypto/dsa/internal.h
Original file line number Diff line number Diff line change
@@ -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. */

#ifndef OPENSSL_HEADER_DSA_INTERNAL_H
#define OPENSSL_HEADER_DSA_INTERNAL_H

#include <CCryptoBoringSSL_dsa.h>

#if defined(__cplusplus)
extern "C" {
#endif


// dsa_check_parameters checks that |dsa|'s group is within DoS bounds. It
// returns one on success and zero on error.
int dsa_check_parameters(const DSA *dsa);


#if defined(__cplusplus)
} // extern C
#endif

#endif // OPENSSL_HEADER_DSA_INTERNAL_H
Loading