Skip to content

Commit e4b7afc

Browse files
authored
Merge branch 'main' into methodFIPS
2 parents 6e718f5 + d3a598c commit e4b7afc

File tree

110 files changed

+23400
-3442
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+23400
-3442
lines changed

.github/workflows/integrations.yml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ jobs:
175175
- name: Run strongswan build
176176
run: |
177177
./tests/ci/integration/run_strongswan_integration.sh
178-
openvpn:
178+
openvpn2-6:
179179
if: github.repository_owner == 'aws'
180180
runs-on: ubuntu-latest
181181
steps:
@@ -187,9 +187,24 @@ jobs:
187187
libcap-ng-dev liblz4-dev liblzo2-dev libpam-dev libcmocka-dev \
188188
python3-docutils
189189
- uses: actions/checkout@v4
190-
- name: Run openvpn build
190+
- name: Run openvpn build 2.6.x
191191
run: |
192-
./tests/ci/integration/run_openvpn_integration.sh
192+
./tests/ci/integration/run_openvpn_integration.sh release/2.6
193+
openvpnMaster:
194+
if: github.repository_owner == 'aws'
195+
runs-on: ubuntu-latest
196+
steps:
197+
- name: Install OS Dependencies
198+
run: |
199+
sudo apt-get update -o Acquire::Languages=none -o Acquire::Translation=none
200+
sudo apt-get -y --no-install-recommends install \
201+
cmake gcc ninja-build golang libnl-3-dev libnl-genl-3-dev \
202+
libcap-ng-dev liblz4-dev liblzo2-dev libpam-dev libcmocka-dev \
203+
python3-docutils
204+
- uses: actions/checkout@v4
205+
- name: Run openvpn build main
206+
run: |
207+
./tests/ci/integration/run_openvpn_integration.sh master
193208
libevent:
194209
if: github.repository_owner == 'aws'
195210
runs-on: ubuntu-latest

CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -824,6 +824,16 @@ else()
824824
set(ARCH "generic")
825825
endif()
826826

827+
# If target ARCH is 32-bit x86, ensure SSE2 is enabled since it's used by the optimized assembly.
828+
# To build for targets that do not support SSE2, use the `OPENSSL_NO_ASM` flag.
829+
if(ARCH STREQUAL "x86" AND NOT OPENSSL_NO_SSE2_FOR_TESTING)
830+
# Most compilers enable SSE2 in 32-bit x86 by default, but in some cases GCC and Clang don't.
831+
# See: https://github.com/aws/aws-lc/commit/6fe8dcbe96e580ea85233fdb98a142e42951b70b
832+
if(GCC OR CLANG)
833+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse2")
834+
endif()
835+
endif()
836+
827837
if(ENABLE_DATA_INDEPENDENT_TIMING_AARCH64)
828838
add_definitions(-DMAKE_DIT_AVAILABLE)
829839
endif()

crypto/crypto_test.cc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,33 @@ TEST(CryptoTest, Strndup) {
7373
EXPECT_STREQ("", str.get());
7474
}
7575

76+
TEST(CryptoTest, OPENSSL_hexstr2buf) {
77+
const char *test_cases[][2] = {{"a2", "\xa2"},
78+
{"a213", "\xa2\x13"},
79+
{"ffeedd", "\xff\xee\xdd"},
80+
{"10aab1c2", "\x10\xaa\xb1\xc2"}};
81+
82+
for (auto test_case : test_cases) {
83+
const char *test_value = test_case[0];
84+
const char *expected_answer = test_case[1];
85+
size_t actual_answer_len = 0;
86+
// The longest test case we have is currently 4 bytes long
87+
size_t expected_answer_len = OPENSSL_strnlen(test_case[1], 5);
88+
unsigned char *buf = OPENSSL_hexstr2buf(test_value, &actual_answer_len);
89+
ASSERT_TRUE(buf != nullptr);
90+
EXPECT_EQ(expected_answer_len, actual_answer_len);
91+
EXPECT_EQ(0, OPENSSL_memcmp(buf, expected_answer, expected_answer_len));
92+
OPENSSL_free(buf);
93+
}
94+
95+
// Test failure modes
96+
size_t actual_answer_len = 0;
97+
EXPECT_FALSE(OPENSSL_hexstr2buf("a", &actual_answer_len));
98+
EXPECT_FALSE(OPENSSL_hexstr2buf(NULL, &actual_answer_len));
99+
EXPECT_FALSE(OPENSSL_hexstr2buf("ab", nullptr));
100+
EXPECT_FALSE(OPENSSL_hexstr2buf("ag", &actual_answer_len));
101+
}
102+
76103
#if defined(BORINGSSL_FIPS_COUNTERS)
77104
using CounterArray = size_t[fips_counter_max + 1];
78105

crypto/dilithium/p_dilithium3.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ const EVP_PKEY_METHOD dilithium3_pkey_meth = {
117117
NULL /* derive */,
118118
NULL /* paramgen */,
119119
NULL /* ctrl */,
120+
NULL /* ctrl_str */,
120121
NULL /* keygen deterministic */,
121122
NULL /* encapsulate deterministic */,
122123
NULL /* encapsulate */,

crypto/ec_extra/ec_asn1.c

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@
5656
#include <limits.h>
5757
#include <string.h>
5858

59-
#include <openssl/bytestring.h>
59+
#include <openssl/bio.h>
6060
#include <openssl/bn.h>
61+
#include <openssl/bytestring.h>
6162
#include <openssl/err.h>
6263
#include <openssl/mem.h>
6364
#include <openssl/nid.h>
@@ -76,19 +77,15 @@ static const CBS_ASN1_TAG kPublicKeyTag =
7677
// acceptable groups, so parsers don't have to pull in all four.
7778
typedef const EC_GROUP *(*ec_group_func)(void);
7879
static const ec_group_func kAllGroups[] = {
79-
&EC_group_p224,
80-
&EC_group_p256,
81-
&EC_group_p384,
82-
&EC_group_p521,
83-
&EC_group_secp256k1,
80+
&EC_group_p224, &EC_group_p256, &EC_group_p384,
81+
&EC_group_p521, &EC_group_secp256k1,
8482
};
8583

8684
EC_KEY *EC_KEY_parse_private_key(CBS *cbs, const EC_GROUP *group) {
8785
CBS ec_private_key, private_key;
8886
uint64_t version;
8987
if (!CBS_get_asn1(cbs, &ec_private_key, CBS_ASN1_SEQUENCE) ||
90-
!CBS_get_asn1_uint64(&ec_private_key, &version) ||
91-
version != 1 ||
88+
!CBS_get_asn1_uint64(&ec_private_key, &version) || version != 1 ||
9289
!CBS_get_asn1(&ec_private_key, &private_key, CBS_ASN1_OCTETSTRING)) {
9390
OPENSSL_PUT_ERROR(EC, EC_R_DECODE_ERROR);
9491
return NULL;
@@ -151,8 +148,7 @@ EC_KEY *EC_KEY_parse_private_key(CBS *cbs, const EC_GROUP *group) {
151148
!CBS_get_asn1(&child, &public_key, CBS_ASN1_BITSTRING) ||
152149
// As in a SubjectPublicKeyInfo, the byte-encoded public key is then
153150
// encoded as a BIT STRING with bits ordered as in the DER encoding.
154-
!CBS_get_u8(&public_key, &padding) ||
155-
padding != 0 ||
151+
!CBS_get_u8(&public_key, &padding) || padding != 0 ||
156152
// Explicitly check |public_key| is non-empty to save the conversion
157153
// form later.
158154
CBS_len(&public_key) == 0 ||
@@ -264,16 +260,14 @@ static int parse_explicit_prime_curve(CBS *in,
264260
int has_cofactor;
265261
uint64_t version;
266262
if (!CBS_get_asn1(in, &params, CBS_ASN1_SEQUENCE) ||
267-
!CBS_get_asn1_uint64(&params, &version) ||
268-
version != 1 ||
263+
!CBS_get_asn1_uint64(&params, &version) || version != 1 ||
269264
!CBS_get_asn1(&params, &field_id, CBS_ASN1_SEQUENCE) ||
270265
!CBS_get_asn1(&field_id, &field_type, CBS_ASN1_OBJECT) ||
271266
CBS_len(&field_type) != sizeof(kPrimeField) ||
272267
OPENSSL_memcmp(CBS_data(&field_type), kPrimeField, sizeof(kPrimeField)) !=
273268
0 ||
274269
!CBS_get_asn1(&field_id, &out->prime, CBS_ASN1_INTEGER) ||
275-
!CBS_is_unsigned_asn1_integer(&out->prime) ||
276-
CBS_len(&field_id) != 0 ||
270+
!CBS_is_unsigned_asn1_integer(&out->prime) || CBS_len(&field_id) != 0 ||
277271
!CBS_get_asn1(&params, &curve, CBS_ASN1_SEQUENCE) ||
278272
!CBS_get_asn1(&curve, &out->a, CBS_ASN1_OCTETSTRING) ||
279273
!CBS_get_asn1(&curve, &out->b, CBS_ASN1_OCTETSTRING) ||
@@ -292,8 +286,7 @@ static int parse_explicit_prime_curve(CBS *in,
292286

293287
if (has_cofactor) {
294288
// We only support prime-order curves so the cofactor must be one.
295-
if (CBS_len(&cofactor) != 1 ||
296-
CBS_data(&cofactor)[0] != 1) {
289+
if (CBS_len(&cofactor) != 1 || CBS_data(&cofactor)[0] != 1) {
297290
OPENSSL_PUT_ERROR(EC, EC_R_UNKNOWN_GROUP);
298291
return 0;
299292
}
@@ -546,6 +539,40 @@ int i2d_ECPKParameters(const EC_GROUP *group, uint8_t **outp) {
546539
return CBB_finish_i2d(&cbb, outp);
547540
}
548541

542+
EC_GROUP *d2i_ECPKParameters_bio(BIO *bio, EC_GROUP **out_group) {
543+
if (bio == NULL) {
544+
OPENSSL_PUT_ERROR(PKCS7, ERR_R_PASSED_NULL_PARAMETER);
545+
return NULL;
546+
}
547+
548+
uint8_t *data;
549+
size_t len;
550+
if (!BIO_read_asn1(bio, &data, &len, INT_MAX)) {
551+
return NULL;
552+
}
553+
const uint8_t *ptr = data;
554+
EC_GROUP *ret = d2i_ECPKParameters(out_group, &ptr, len);
555+
OPENSSL_free(data);
556+
return ret;
557+
}
558+
559+
int i2d_ECPKParameters_bio(BIO *bio, const EC_GROUP *group) {
560+
if (bio == NULL || group == NULL) {
561+
OPENSSL_PUT_ERROR(PKCS7, ERR_R_PASSED_NULL_PARAMETER);
562+
return 0;
563+
}
564+
565+
uint8_t *out = NULL;
566+
int len = i2d_ECPKParameters(group, &out);
567+
if (out == NULL) {
568+
return 0;
569+
}
570+
571+
int ret = BIO_write_all(bio, out, len);
572+
OPENSSL_free(out);
573+
return ret;
574+
}
575+
549576
EC_KEY *o2i_ECPublicKey(EC_KEY **keyp, const uint8_t **inp, long len) {
550577
EC_KEY *ret = NULL;
551578

@@ -599,8 +626,8 @@ size_t EC_get_builtin_curves(EC_builtin_curve *out_curves,
599626
}
600627

601628
static size_t EC_POINT_point2buf(const EC_GROUP *group, const EC_POINT *point,
602-
point_conversion_form_t form,
603-
uint8_t **pbuf, BN_CTX *ctx) {
629+
point_conversion_form_t form, uint8_t **pbuf,
630+
BN_CTX *ctx) {
604631
size_t len;
605632
uint8_t *buf;
606633

crypto/evp_extra/p_dh.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ const EVP_PKEY_METHOD dh_pkey_meth = {
129129
.keygen = pkey_dh_keygen,
130130
.derive = pkey_dh_derive,
131131
.ctrl = pkey_dh_ctrl,
132+
.ctrl_str = NULL
132133
};
133134

134135
int EVP_PKEY_CTX_set_dh_pad(EVP_PKEY_CTX *ctx, int pad) {

crypto/evp_extra/p_x25519.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ const EVP_PKEY_METHOD x25519_pkey_meth = {
106106
pkey_x25519_derive,
107107
NULL /* paramgen */,
108108
pkey_x25519_ctrl,
109+
NULL, /* ctrl_str */
109110
NULL /* keygen deterministic */,
110111
NULL /* encapsulate deterministic */,
111112
NULL /* encapsulate */,

crypto/fipsmodule/CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ if(ARCH STREQUAL "x86_64")
3838
p256_beeu-x86_64-asm.${ASM_EXT}
3939
rdrand-x86_64.${ASM_EXT}
4040
rsaz-avx2.${ASM_EXT}
41+
rsaz-2k-avx512.${ASM_EXT}
42+
rsaz-3k-avx512.${ASM_EXT}
43+
rsaz-4k-avx512.${ASM_EXT}
4144
sha1-x86_64.${ASM_EXT}
4245
sha256-x86_64.${ASM_EXT}
4346
sha512-x86_64.${ASM_EXT}
@@ -147,6 +150,9 @@ if(PERL_EXECUTABLE)
147150
perlasm(p256_beeu-armv8-asm.${ASM_EXT} ec/asm/p256_beeu-armv8-asm.pl)
148151
perlasm(rdrand-x86_64.${ASM_EXT} rand/asm/rdrand-x86_64.pl)
149152
perlasm(rsaz-avx2.${ASM_EXT} bn/asm/rsaz-avx2.pl)
153+
perlasm(rsaz-2k-avx512.${ASM_EXT} bn/asm/rsaz-2k-avx512.pl)
154+
perlasm(rsaz-3k-avx512.${ASM_EXT} bn/asm/rsaz-3k-avx512.pl)
155+
perlasm(rsaz-4k-avx512.${ASM_EXT} bn/asm/rsaz-4k-avx512.pl)
150156
perlasm(sha1-586.${ASM_EXT} sha/asm/sha1-586.pl)
151157
perlasm(sha1-armv4-large.${ASM_EXT} sha/asm/sha1-armv4-large.pl)
152158
perlasm(sha1-armv8.${ASM_EXT} sha/asm/sha1-armv8.pl)
@@ -175,6 +181,9 @@ if (CLANG AND (CMAKE_ASM_COMPILER_ID MATCHES "Clang" OR CMAKE_ASM_COMPILER MATCH
175181
(CMAKE_C_COMPILER_VERSION VERSION_LESS "7.0.0") AND (ARCH STREQUAL "x86_64"))
176182
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/aesni-gcm-avx512.${ASM_EXT} PROPERTIES COMPILE_FLAGS "-mavx512f -mavx512bw -mavx512dq -mavx512vl")
177183
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/aesni-xts-avx512.${ASM_EXT} PROPERTIES COMPILE_FLAGS "-mavx512f -mavx512bw -mavx512dq -mavx512vl")
184+
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/rsaz-2k-avx512.${ASM_EXT} PROPERTIES COMPILE_FLAGS "-mavx512f -mavx512bw -mavx512dq -mavx512vl -mavx512ifma")
185+
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/rsaz-3k-avx512.${ASM_EXT} PROPERTIES COMPILE_FLAGS "-mavx512f -mavx512bw -mavx512dq -mavx512vl -mavx512ifma")
186+
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/rsaz-4k-avx512.${ASM_EXT} PROPERTIES COMPILE_FLAGS "-mavx512f -mavx512bw -mavx512dq -mavx512vl -mavx512ifma")
178187
endif()
179188

180189
# s2n-bignum files can be compiled on Unix platforms only (except Apple),
@@ -384,7 +393,7 @@ if(FIPS_DELOCATE)
384393
# The flags are not required for any other compiler we are running in the CI.
385394
if (CLANG AND (CMAKE_ASM_COMPILER_ID MATCHES "Clang" OR CMAKE_ASM_COMPILER MATCHES "clang") AND
386395
(CMAKE_C_COMPILER_VERSION VERSION_LESS "7.0.0") AND (ARCH STREQUAL "x86_64"))
387-
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/bcm-delocated.S PROPERTIES COMPILE_FLAGS "-mavx512f -mavx512bw -mavx512dq -mavx512vl")
396+
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/bcm-delocated.S PROPERTIES COMPILE_FLAGS "-mavx512f -mavx512bw -mavx512dq -mavx512vl -mavx512ifma")
388397
endif()
389398
390399
add_library(

crypto/fipsmodule/bcm.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
#include "bn/prime.c"
6464
#include "bn/random.c"
6565
#include "bn/rsaz_exp.c"
66+
#include "bn/rsaz_exp_x2.c"
6667
#include "bn/shift.c"
6768
#include "bn/sqrt.c"
6869
#include "cipher/aead.c"

0 commit comments

Comments
 (0)