Skip to content

Commit a9e2811

Browse files
authored
Merge branch 'main' into bssl-cherry-pick-b0ef87e5
2 parents 218cf60 + e2b4850 commit a9e2811

File tree

22 files changed

+443
-84
lines changed

22 files changed

+443
-84
lines changed

.github/docker_images/cmake_build_versions/cmake_build.sh

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,8 @@ NUM_CPU_THREADS=$(grep -c ^processor /proc/cpuinfo)
1515
# For older versions, we use CMake's bundled curl instead of the system curl.
1616
CONFIGURE_OPTS="--prefix=/opt/cmake --system-libarchive"
1717

18-
if [[ "${CMAKE_VERSION}" =~ ^[0-3]\. ]]; then
19-
# CMake versions 3.x and earlier: use bundled curl to avoid compatibility issues
20-
echo "Using bundled curl for CMake ${CMAKE_VERSION}"
21-
else
22-
# CMake 4.0 and later: safe to use system curl
23-
echo "Using system curl for CMake ${CMAKE_VERSION}"
24-
CONFIGURE_OPTS="${CONFIGURE_OPTS} --system-curl"
25-
fi
18+
echo "Using bundled curl for CMake ${CMAKE_VERSION}"
2619

2720
./configure ${CONFIGURE_OPTS}
2821
make -j"${NUM_CPU_THREADS}"
29-
make install
22+
make install

crypto/evp_extra/p_dh_asn1.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
#include "internal.h"
2121

2222
static int dh_pub_encode(CBB *out, const EVP_PKEY *key) {
23+
const DH *dh = key->pkey.dh;
24+
if (dh == NULL || dh->pub_key == NULL) {
25+
OPENSSL_PUT_ERROR(EVP, EVP_R_ENCODE_ERROR);
26+
return 0;
27+
}
28+
2329
CBB spki, algorithm, oid, key_bitstring;
2430
if (!CBB_add_asn1(out, &spki, CBS_ASN1_SEQUENCE) ||
2531
!CBB_add_asn1(&spki, &algorithm, CBS_ASN1_SEQUENCE) ||
@@ -54,7 +60,7 @@ static int dh_pub_decode(EVP_PKEY *out, CBS *oid, CBS *params, CBS *key) {
5460
}
5561

5662
pubkey = BN_new();
57-
if (pubkey == NULL || !BN_parse_asn1_unsigned(key, pubkey)) {
63+
if (pubkey == NULL || !BN_parse_asn1_unsigned(key, pubkey) || CBS_len(key) != 0) {
5864
OPENSSL_PUT_ERROR(EVP, EVP_R_DECODE_ERROR);
5965
goto err;
6066
}
@@ -65,6 +71,7 @@ static int dh_pub_decode(EVP_PKEY *out, CBS *oid, CBS *params, CBS *key) {
6571
goto err;
6672
}
6773
dh->pub_key = pubkey;
74+
pubkey = NULL;
6875

6976
if (!EVP_PKEY_assign_DH(out, dh)) {
7077
OPENSSL_PUT_ERROR(EVP, EVP_R_DECODE_ERROR);
@@ -99,6 +106,14 @@ static int dh_param_copy(EVP_PKEY *to, const EVP_PKEY *from) {
99106
return 0;
100107
}
101108

109+
// Ensure the target has an allocated DH structure.
110+
if (to->pkey.dh == NULL) {
111+
to->pkey.dh = DH_new();
112+
if (to->pkey.dh == NULL) {
113+
return 0;
114+
}
115+
}
116+
102117
const DH *dh = from->pkey.dh;
103118
const BIGNUM *q_old = DH_get0_q(dh);
104119
BIGNUM *p = BN_dup(DH_get0_p(dh));

crypto/fipsmodule/cipher/e_aesccm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ static int cipher_aes_ccm_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out,
629629
return -1;
630630
}
631631
// Validate the tag and invalidate the output if it doesn't match.
632-
if (OPENSSL_memcmp(cipher_ctx->tag, computed_tag, cipher_ctx->M)) {
632+
if (CRYPTO_memcmp(cipher_ctx->tag, computed_tag, cipher_ctx->M)) {
633633
OPENSSL_cleanse(out, len);
634634
return -1;
635635
}

crypto/fipsmodule/fips_shared_support.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@
1212
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
1313
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
1414

15+
#if defined(BORINGSSL_FIPS) && defined(BORINGSSL_SHARED_LIBRARY)
1516
#include <stdint.h>
1617

17-
18-
#if defined(BORINGSSL_FIPS) && defined(BORINGSSL_SHARED_LIBRARY)
1918
// BORINGSSL_bcm_text_hash is is default hash value for the FIPS integrity check
2019
// that must be replaced with the real value during the build process. This
2120
// value need only be distinct, i.e. so that we can safely search-and-replace it
@@ -25,4 +24,9 @@ const uint8_t BORINGSSL_bcm_text_hash[32] = {
2524
0xf6, 0x94, 0x9a, 0xfc, 0x83, 0x68, 0x27, 0xcb, 0xa0, 0xa0, 0x9f,
2625
0x6b, 0x6f, 0xde, 0x52, 0xcd, 0xe2, 0xcd, 0xff, 0x31, 0x80,
2726
};
27+
#else
28+
// C requires a translation unit to contain at least one declaration. Since
29+
// BORINGSSL_FIPS or BORINGSSL_SHARED_LIBRARY is not defined, this file is
30+
// otherwise empty. This typedef prevents MSVC warning C4206.
31+
typedef int fips_shared_support_dummy;
2832
#endif // FIPS && SHARED_LIBRARY

crypto/fipsmodule/kem/kem.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ const KEM *KEM_KEY_get0_kem(KEM_KEY* key) {
272272
}
273273

274274
int KEM_KEY_set_raw_public_key(KEM_KEY *key, const uint8_t *in) {
275+
OPENSSL_free(key->public_key);
275276
key->public_key = OPENSSL_memdup(in, key->kem->public_key_len);
276277
if (key->public_key == NULL) {
277278
return 0;
@@ -281,6 +282,7 @@ int KEM_KEY_set_raw_public_key(KEM_KEY *key, const uint8_t *in) {
281282
}
282283

283284
int KEM_KEY_set_raw_secret_key(KEM_KEY *key, const uint8_t *in) {
285+
OPENSSL_free(key->secret_key);
284286
key->secret_key = OPENSSL_memdup(in, key->kem->secret_key_len);
285287
if (key->secret_key == NULL) {
286288
return 0;
@@ -291,6 +293,8 @@ int KEM_KEY_set_raw_secret_key(KEM_KEY *key, const uint8_t *in) {
291293

292294
int KEM_KEY_set_raw_key(KEM_KEY *key, const uint8_t *in_public,
293295
const uint8_t *in_secret) {
296+
OPENSSL_free(key->public_key);
297+
OPENSSL_free(key->secret_key);
294298
key->public_key = OPENSSL_memdup(in_public, key->kem->public_key_len);
295299
key->secret_key = OPENSSL_memdup(in_secret, key->kem->secret_key_len);
296300
if (key->public_key == NULL || key->secret_key == NULL) {

crypto/fipsmodule/rand/entropy/entropy_sources.c

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,32 @@ DEFINE_BSS_GET(const struct entropy_source_methods *, entropy_source_methods_ove
1414
DEFINE_BSS_GET(int, allow_entropy_source_methods_override)
1515
DEFINE_STATIC_MUTEX(global_entropy_source_lock)
1616

17-
static int entropy_get_prediction_resistance(
18-
const struct entropy_source_t *entropy_source,
19-
uint8_t pred_resistance[RAND_PRED_RESISTANCE_LEN]) {
17+
static int entropy_cpu_get_entropy(uint8_t *entropy, size_t entropy_len) {
2018
#if defined(OPENSSL_X86_64)
21-
if (rdrand_multiple8(pred_resistance, RAND_PRED_RESISTANCE_LEN) == 1) {
19+
if (rdrand_multiple8(entropy, entropy_len) == 1) {
2220
return 1;
2321
}
2422
#elif defined(OPENSSL_AARCH64)
25-
if (rndr_multiple8(pred_resistance, RAND_PRED_RESISTANCE_LEN) == 1) {
23+
if (rndr_multiple8(entropy, entropy_len) == 1) {
2624
return 1;
2725
}
2826
#endif
2927
return 0;
3028
}
3129

32-
static int entropy_get_extra_entropy(
30+
static int entropy_cpu_get_prediction_resistance(
31+
const struct entropy_source_t *entropy_source,
32+
uint8_t pred_resistance[RAND_PRED_RESISTANCE_LEN]) {
33+
return entropy_cpu_get_entropy(pred_resistance, RAND_PRED_RESISTANCE_LEN);
34+
}
35+
36+
static int entropy_cpu_get_extra_entropy(
37+
const struct entropy_source_t *entropy_source,
38+
uint8_t extra_entropy[CTR_DRBG_ENTROPY_LEN]) {
39+
return entropy_cpu_get_entropy(extra_entropy, CTR_DRBG_ENTROPY_LEN);
40+
}
41+
42+
static int entropy_os_get_extra_entropy(
3343
const struct entropy_source_t *entropy_source,
3444
uint8_t extra_entropy[CTR_DRBG_ENTROPY_LEN]) {
3545
CRYPTO_sysrand(extra_entropy, CTR_DRBG_ENTROPY_LEN);
@@ -47,10 +57,10 @@ DEFINE_LOCAL_DATA(struct entropy_source_methods, tree_jitter_entropy_source_meth
4757
out->zeroize_thread = tree_jitter_zeroize_thread_drbg;
4858
out->free_thread = tree_jitter_free_thread_drbg;
4959
out->get_seed = tree_jitter_get_seed;
50-
out->get_extra_entropy = entropy_get_extra_entropy;
60+
out->get_extra_entropy = entropy_os_get_extra_entropy;
5161
if (have_hw_rng_x86_64() == 1 ||
5262
have_hw_rng_aarch64() == 1) {
53-
out->get_prediction_resistance = entropy_get_prediction_resistance;
63+
out->get_prediction_resistance = entropy_cpu_get_prediction_resistance;
5464
} else {
5565
out->get_prediction_resistance = NULL;
5666
}
@@ -103,7 +113,7 @@ DEFINE_LOCAL_DATA(struct entropy_source_methods, opt_out_cpu_jitter_entropy_sour
103113
out->get_seed = opt_out_cpu_jitter_get_seed_wrap;
104114
if (have_hw_rng_x86_64() == 1 ||
105115
have_hw_rng_aarch64() == 1) {
106-
out->get_extra_entropy = entropy_get_prediction_resistance;
116+
out->get_extra_entropy = entropy_cpu_get_extra_entropy;
107117
} else {
108118
// Fall back to seed source because a second source must always be present.
109119
out->get_extra_entropy = opt_out_cpu_jitter_get_seed_wrap;

crypto/pkcs7/pkcs7.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1620,7 +1620,6 @@ static int pkcs7_signature_verify(BIO *in_bio, PKCS7 *p7, PKCS7_SIGNER_INFO *si,
16201620
ASN1_ITEM_rptr(PKCS7_ATTR_VERIFY));
16211621
if (alen <= 0 || abuf == NULL) {
16221622
OPENSSL_PUT_ERROR(PKCS7, ERR_R_ASN1_LIB);
1623-
ret = -1;
16241623
goto out;
16251624
}
16261625
if (!EVP_VerifyUpdate(mdc_tmp, abuf, alen)) {
@@ -1703,14 +1702,14 @@ int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,
17031702
goto out;
17041703
}
17051704
X509_STORE_CTX_set0_crls(cert_ctx, p7->d.sign->crl);
1706-
}
1707-
// NOTE: unlike most of our functions, |X509_verify_cert| can return <= 0
1708-
if (X509_verify_cert(cert_ctx) <= 0) {
1705+
// NOTE: unlike most of our functions, |X509_verify_cert| can return <= 0
1706+
if (X509_verify_cert(cert_ctx) <= 0) {
17091707
#if !defined(BORINGSSL_UNSAFE_FUZZER_MODE)
1710-
// For fuzz testing, we do not want to bail out early.
1711-
OPENSSL_PUT_ERROR(PKCS7, PKCS7_R_CERTIFICATE_VERIFY_ERROR);
1712-
goto out;
1708+
// For fuzz testing, we do not want to bail out early.
1709+
OPENSSL_PUT_ERROR(PKCS7, PKCS7_R_CERTIFICATE_VERIFY_ERROR);
1710+
goto out;
17131711
#endif
1712+
}
17141713
}
17151714
}
17161715

@@ -1725,7 +1724,7 @@ int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,
17251724
for (size_t ii = 0; ii < sk_PKCS7_SIGNER_INFO_num(sinfos); ii++) {
17261725
PKCS7_SIGNER_INFO *si = sk_PKCS7_SIGNER_INFO_value(sinfos, ii);
17271726
X509 *signer = sk_X509_value(signers, ii);
1728-
if (!pkcs7_signature_verify(p7bio, p7, si, signer)) {
1727+
if (pkcs7_signature_verify(p7bio, p7, si, signer) != 1) {
17291728
#if !defined(BORINGSSL_UNSAFE_FUZZER_MODE)
17301729
// For fuzz testing, we do not want to bail out early.
17311730
OPENSSL_PUT_ERROR(PKCS7, PKCS7_R_SIGNATURE_FAILURE);

0 commit comments

Comments
 (0)