Skip to content

Commit ff3a8ab

Browse files
authored
Merge branch 'main' into cipherfuncs
2 parents a00c196 + c932cf4 commit ff3a8ab

File tree

113 files changed

+11667
-3874
lines changed

Some content is hidden

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

113 files changed

+11667
-3874
lines changed

.github/workflows/aws-lc-rs.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,5 @@ jobs:
6969
- name: Install cross
7070
run: cargo install cross --git https://github.com/cross-rs/cross
7171
- name: Cross-compile arm-linux-androideabi
72-
working-directory: ./aws-lc-rs/aws-lc-rs
73-
run: cross test --release --features bindgen,unstable --target arm-linux-androideabi
72+
working-directory: ./aws-lc-rs
73+
run: cross test -p aws-lc-rs --release --features bindgen,unstable --target arm-linux-androideabi

.github/workflows/integrations.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
steps:
2727
- name: Install OS Dependencies
2828
run: |
29-
sudo apt-get update && sudo apt-get -y --no-install-recommends install cmake gcc ninja-build golang autoconf-archive libcmocka0 libcmocka-dev procps iproute2 build-essential git pkg-config gcc libtool automake libssl-dev uthash-dev autoconf doxygen libjson-c-dev libini-config-dev libcurl4-openssl-dev uuid-dev libltdl-dev libusb-1.0-0-dev libftdi-dev
29+
sudo apt-get update && sudo apt-get -y --no-install-recommends install cmake gcc ninja-build golang autoconf-archive libcmocka0 libcmocka-dev procps iproute2 build-essential git pkg-config gcc libtool automake libssl-dev uthash-dev autoconf doxygen libjson-c-dev libini-config-dev libcurl4-openssl-dev uuid-dev libltdl-dev libusb-1.0-0-dev libftdi-dev libglib2.0-dev pandoc
3030
- uses: actions/checkout@v3
3131
- name: Run integration build
3232
run: |

.github/workflows/mingw.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: MinGW
2+
on:
3+
pull_request:
4+
branches: [ '*' ]
5+
push:
6+
branches: [ '*' ]
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
10+
cancel-in-progress: true
11+
jobs:
12+
mingw:
13+
if: github.repository == 'aws/aws-lc'
14+
runs-on: windows-latest
15+
steps:
16+
- name: Install NASM
17+
uses: ilammy/[email protected]
18+
- name: Checkout
19+
uses: actions/checkout@v4
20+
- name: Setup MinGW
21+
uses: egor-tensin/[email protected]
22+
id: setup_mingw
23+
with:
24+
static: 0
25+
- name: Setup CMake
26+
uses: threeal/[email protected]
27+
with:
28+
generator: Ninja
29+
c-compiler: ${{ steps.setup_mingw.outputs.gcc }}
30+
cxx-compiler: ${{ steps.setup_mingw.outputs.gxx }}
31+
options: |
32+
CMAKE_SYSTEM_NAME=Windows \
33+
CMAKE_SYSTEM_PROCESSOR=x86_64 \
34+
CMAKE_BUILD_TOOL=C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64/bin/ninja.exe \
35+
CMAKE_FIND_ROOT_PATH=C:/ProgramData/chocolatey/lib/mingw/tools/install/mingw64 \
36+
CMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER \
37+
CMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
38+
CMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \
39+
- name: Build Project
40+
run: cmake --build ./build --target all
41+
- name: Run tests
42+
run: cmake --build ./build --target run_tests

LICENSE

+2-2
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ are met:
206206
written permission.
207207

208208

209-
The code in crypto/kyber/pqcrystals-kyber_kyber512_ref carries the
210-
Public Domain license:
209+
The code in crypto/kyber/pqcrystals-kyber_kyber512_ref and
210+
crypto/ml_kem/ml_kem_ipd_ref_common carries the Public Domain license:
211211

212212
Public Domain (https://creativecommons.org/share-your-work/public-domain/cc0/)
213213

crypto/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ add_library(
434434
refcount_win.c
435435
rsa_extra/rsa_asn1.c
436436
rsa_extra/rsassa_pss_asn1.c
437+
rsa_extra/rsa_crypt.c
437438
rsa_extra/rsa_print.c
438439
stack/stack.c
439440
siphash/siphash.c
@@ -781,7 +782,7 @@ if(BUILD_TESTING)
781782
add_dependencies(${CRYPTO_TEST_EXEC} boringssl_prefix_symbols)
782783
target_link_libraries(${CRYPTO_TEST_EXEC} test_support_lib boringssl_gtest_main crypto)
783784
target_include_directories(${CRYPTO_TEST_EXEC} BEFORE PRIVATE ${PROJECT_BINARY_DIR}/symbol_prefix_include)
784-
if(WIN32)
785+
if(MSVC)
785786
target_link_libraries(${CRYPTO_TEST_EXEC} ws2_32)
786787
else()
787788
target_compile_options(${CRYPTO_TEST_EXEC} PUBLIC -Wno-deprecated-declarations)

crypto/asn1/a_i2d_fp.c

+33
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,46 @@
5454
* copied and put under another distribution licence
5555
* [including the GNU Public Licence.] */
5656

57+
#include <assert.h>
58+
5759
#include <openssl/asn1.h>
5860

5961
#include <openssl/bio.h>
6062
#include <openssl/err.h>
6163
#include <openssl/mem.h>
6264

6365

66+
int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, void *in) {
67+
if (i2d == NULL || out == NULL || in == NULL) {
68+
OPENSSL_PUT_ERROR(ASN1, ERR_R_PASSED_NULL_PARAMETER);
69+
return 0;
70+
}
71+
72+
int size = i2d(in, NULL);
73+
if (size <= 0) {
74+
OPENSSL_PUT_ERROR(ASN1, ERR_R_INTERNAL_ERROR);
75+
return 0;
76+
}
77+
78+
unsigned char *buffer = (unsigned char *)OPENSSL_malloc(size);
79+
if (buffer == NULL) {
80+
OPENSSL_PUT_ERROR(ASN1, ERR_R_MALLOC_FAILURE);
81+
return 0;
82+
}
83+
84+
unsigned char *outp = buffer;
85+
int ret = i2d(in, &outp);
86+
if (ret < 0 || ret > size) {
87+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BUFFER_TOO_SMALL);
88+
OPENSSL_free(buffer);
89+
return 0;
90+
}
91+
92+
ret = BIO_write_all(out, buffer, size);
93+
OPENSSL_free(buffer);
94+
return ret;
95+
}
96+
6497
int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x) {
6598
BIO *b = BIO_new_fp(out, BIO_NOCLOSE);
6699
if (b == NULL) {

crypto/asn1/asn1_test.cc

+29-1
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ static struct tm make_tm(int sec, int min, int hour, int mday, int mon, int year
979979
t.tm_wday = wday;
980980
t.tm_yday = yday;
981981
t.tm_isdst = isdst;
982-
#if defined(__GNUC__)
982+
#if defined(__GNU__)
983983
t.tm_gmtoff = gmtoff;
984984
t.tm_zone = zone;
985985
#endif
@@ -2471,6 +2471,34 @@ TEST(ASN1Test, Recursive) {
24712471
ASN1_LINKED_LIST_free(list);
24722472
}
24732473

2474+
static int i2d_ASN1_LINKED_LIST_void(const void *a, unsigned char **out) {
2475+
return i2d_ASN1_LINKED_LIST((ASN1_LINKED_LIST *)a, out);
2476+
}
2477+
2478+
TEST(ASN1Test, BIO) {
2479+
bssl::UniquePtr<BIO> bio(BIO_new(BIO_s_mem()));
2480+
bssl::UniquePtr<uint8_t> data;
2481+
size_t len;
2482+
ASSERT_TRUE(MakeLinkedList(&data, &len, 5));
2483+
const uint8_t *ptr = data.get();
2484+
ASN1_LINKED_LIST *list = d2i_ASN1_LINKED_LIST(nullptr, &ptr, len);
2485+
EXPECT_TRUE(list);
2486+
2487+
// Retrieve expected bytes.
2488+
uint8_t *expected = nullptr;
2489+
int expected_len = i2d_ASN1_LINKED_LIST(list, &expected);
2490+
ASSERT_GT(expected_len, 0);
2491+
2492+
const uint8_t *out;
2493+
size_t out_len;
2494+
EXPECT_TRUE(ASN1_i2d_bio(i2d_ASN1_LINKED_LIST_void, bio.get(), list));
2495+
ASSERT_TRUE(BIO_mem_contents(bio.get(), &out, &out_len));
2496+
2497+
EXPECT_EQ(Bytes(out, out_len), Bytes(expected, expected_len));
2498+
OPENSSL_free(expected);
2499+
ASN1_LINKED_LIST_free(list);
2500+
}
2501+
24742502
struct IMPLICIT_CHOICE {
24752503
ASN1_STRING *string;
24762504
};

crypto/base64/base64.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ int EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, uint8_t *out, int *out_len,
193193
if (total > INT_MAX) {
194194
// We cannot signal an error, but we can at least avoid making *out_len
195195
// negative.
196-
total = 0;
196+
*out_len = 0;
197197
return 0;
198198
}
199199
*out_len = (int)total;

crypto/bio/bio.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,11 @@ int BIO_write(BIO *bio, const void *in, int inl) {
239239
int BIO_write_all(BIO *bio, const void *data, size_t len) {
240240
const uint8_t *data_u8 = data;
241241
while (len > 0) {
242-
int ret = BIO_write(bio, data_u8, len > INT_MAX ? INT_MAX : (int)len);
242+
const int write_len = ((len > INT_MAX) ? INT_MAX : (int)len);
243+
int ret = BIO_write(bio, data_u8, write_len);
244+
assert(ret <= write_len);
243245
if (ret <= 0) {
246+
OPENSSL_PUT_ERROR(ASN1, ASN1_R_BUFFER_TOO_SMALL);
244247
return 0;
245248
}
246249
data_u8 += ret;

crypto/bio/bio_test.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ TEST(BIOTest, CloseFlags) {
373373

374374
// Assert that CRLF line endings get inserted on write and translated back out
375375
// on read for text mode.
376-
TempFILE text_bio_file(tmpfile());
376+
TempFILE text_bio_file = createTempFILE();
377377
ASSERT_TRUE(text_bio_file);
378378
bssl::UniquePtr<BIO> text_bio(
379379
BIO_new_fp(text_bio_file.get(), BIO_NOCLOSE | BIO_FP_TEXT));
@@ -403,7 +403,7 @@ TEST(BIOTest, CloseFlags) {
403403

404404
// Assert that CRLF line endings don't get inserted on write for
405405
// (default) binary mode.
406-
TempFILE binary_bio_file(tmpfile());
406+
TempFILE binary_bio_file = createTempFILE();
407407
ASSERT_TRUE(binary_bio_file);
408408
bssl::UniquePtr<BIO> binary_bio(
409409
BIO_new_fp(binary_bio_file.get(), BIO_NOCLOSE));
@@ -432,7 +432,7 @@ TEST(BIOTest, CloseFlags) {
432432

433433
// Assert that BIO_CLOSE causes the underlying file to be closed on BIO free
434434
// (ftell will return < 0)
435-
FILE *tmp = tmpfile();
435+
FILE *tmp = createRawTempFILE();
436436
ASSERT_TRUE(tmp);
437437
BIO *bio = BIO_new_fp(tmp, BIO_CLOSE);
438438
EXPECT_EQ(0, BIO_tell(bio));
@@ -449,7 +449,7 @@ TEST(BIOTest, CloseFlags) {
449449
#endif
450450

451451
// Assert that BIO_NOCLOSE does not close the underlying file on BIO free
452-
tmp = tmpfile();
452+
tmp = createRawTempFILE();
453453
ASSERT_TRUE(tmp);
454454
bio = BIO_new_fp(tmp, BIO_NOCLOSE);
455455
EXPECT_EQ(0, BIO_tell(bio));
@@ -737,7 +737,7 @@ TEST(BIOTest, Gets) {
737737
check_bio_gets(bio.get());
738738
}
739739

740-
TempFILE file(tmpfile());
740+
TempFILE file = createTempFILE();
741741
#if defined(OPENSSL_ANDROID)
742742
// On Android, when running from an APK, |tmpfile| does not work. See
743743
// b/36991167#comment8.

crypto/cipher_extra/aead_test.cc

+15-7
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ static const struct KnownAEAD kAEADs[] = {
133133
"aes_128_cbc_sha256_tls_implicit_iv_tests.txt",
134134
kLimitedImplementation | RequiresADLength(11)},
135135

136+
{"AES_256_CBC_SHA384_TLS", EVP_aead_aes_256_cbc_sha384_tls,
137+
"aes_256_cbc_sha384_tls_tests.txt",
138+
kLimitedImplementation | RequiresADLength(11)},
139+
136140
{"AES_256_CBC_SHA1_TLS", EVP_aead_aes_256_cbc_sha1_tls,
137141
"aes_256_cbc_sha1_tls_tests.txt",
138142
kLimitedImplementation | RequiresADLength(11)},
@@ -1372,13 +1376,15 @@ struct EvpAeadCtxSerdeTestParams {
13721376
class EvpAeadCtxSerdeTest
13731377
: public testing::TestWithParam<EvpAeadCtxSerdeTestParams> {};
13741378

1375-
static const uint8_t kEvpAeadCtxKey[68] = {
1376-
0x49, 0xd4, 0x9f, 0x84, 0x62, 0xf1, 0xda, 0x3a, 0xe1, 0x60, 0x08, 0xf3,
1377-
0xcf, 0xf6, 0x01, 0x2d, 0x95, 0x90, 0x08, 0xfe, 0xad, 0x89, 0x31, 0x21,
1378-
0x1c, 0x84, 0xf0, 0x77, 0x57, 0x18, 0x94, 0x03, 0xe3, 0x85, 0x30, 0x32,
1379-
0xc3, 0x0f, 0xae, 0x54, 0x54, 0x8d, 0x21, 0x55, 0x68, 0xc9, 0x6f, 0xb9,
1380-
0x23, 0x4e, 0xbc, 0xba, 0x1a, 0x4c, 0x9a, 0xd8, 0x35, 0x96, 0xc2, 0xb3,
1381-
0x6e, 0x7a, 0x47, 0xa8, 0x8e, 0xdd, 0x6e, 0x1d};
1379+
static const uint8_t kEvpAeadCtxKey[80] = {
1380+
0x03, 0xeb, 0x1d, 0xb2, 0x2c, 0xa8, 0xc0, 0x3b, 0x29, 0x9c, 0x66, 0xe5,
1381+
0xdd, 0xb7, 0x70, 0x6c, 0x39, 0x86, 0x71, 0x94, 0x79, 0x5c, 0xf5, 0x88,
1382+
0xde, 0xd9, 0x05, 0x1f, 0x28, 0x96, 0x86, 0x28, 0x01, 0xb0, 0x59, 0x11,
1383+
0xb0, 0x3f, 0x35, 0xe6, 0xb5, 0x2f, 0x3b, 0xee, 0xbc, 0xf9, 0x11, 0xb1,
1384+
0x9e, 0x58, 0xf6, 0xb7, 0xf3, 0x3e, 0x5b, 0x66, 0x28, 0x85, 0x0c, 0x66,
1385+
0x2b, 0x75, 0xb7, 0x86, 0xfd, 0xa4, 0x2d, 0x4b, 0x8c, 0xe0, 0x9a, 0x58,
1386+
0xbf, 0xc6, 0x22, 0x4c, 0x39, 0x25, 0x66, 0xfd
1387+
};
13821388

13831389
static const EvpAeadCtxSerdeTestParams kEvpAeadCtxSerde[] = {
13841390
{"EVP_aead_aes_128_gcm", EVP_aead_aes_128_gcm(), kEvpAeadCtxKey, 16, 16,
@@ -1421,6 +1427,8 @@ static const EvpAeadCtxSerdeTestParams kEvpAeadCtxSerde[] = {
14211427
kEvpAeadCtxKey, 48, 32, 11},
14221428
{"EVP_aead_aes_128_cbc_sha256_tls_implicit_iv",
14231429
EVP_aead_aes_128_cbc_sha256_tls_implicit_iv(), kEvpAeadCtxKey, 64, 32, 12},
1430+
{"EVP_aead_aes_256_cbc_sha384_tls", EVP_aead_aes_256_cbc_sha384_tls(),
1431+
kEvpAeadCtxKey, 80, 48, 28},
14241432
{"EVP_aead_des_ede3_cbc_sha1_tls", EVP_aead_des_ede3_cbc_sha1_tls(),
14251433
kEvpAeadCtxKey, 44, 20, 13},
14261434
{"EVP_aead_des_ede3_cbc_sha1_tls_implicit_iv",

crypto/cipher_extra/cipher_test.cc

+48
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,54 @@ TEST(CipherTest, SHA256WithSecretSuffix) {
10081008
}
10091009
}
10101010

1011+
TEST(CipherTest, SHA384WithSecretSuffix) {
1012+
uint8_t buf[SHA384_CBLOCK * 4];
1013+
RAND_bytes(buf, sizeof(buf));
1014+
// Hashing should run in time independent of the bytes.
1015+
CONSTTIME_SECRET(buf, sizeof(buf));
1016+
1017+
// Exhaustively testing interesting cases in this function is cubic in the
1018+
// block size, so we test in 7-byte increments.
1019+
constexpr size_t kSkip = 7;
1020+
// This value should be less than 16 to test the edge case when the 16-byte
1021+
// length wraps to the next block.
1022+
static_assert(kSkip < 16, "kSkip is too large");
1023+
1024+
// |EVP_final_with_secret_suffix_sha384| is sensitive to the public length of
1025+
// the partial block previously hashed. In TLS, this is the HMAC prefix, the
1026+
// header, and the public minimum padding length.
1027+
for (size_t prefix = 0; prefix < SHA384_CBLOCK; prefix += kSkip) {
1028+
SCOPED_TRACE(prefix);
1029+
// The first block is treated differently, so we run with up to three
1030+
// blocks of length variability.
1031+
for (size_t max_len = 0; max_len < 3 * SHA384_CBLOCK; max_len += kSkip) {
1032+
SCOPED_TRACE(max_len);
1033+
for (size_t len = 0; len <= max_len; len += kSkip) {
1034+
SCOPED_TRACE(len);
1035+
1036+
uint8_t expected[SHA384_DIGEST_LENGTH];
1037+
SHA384(buf, prefix + len, expected);
1038+
CONSTTIME_DECLASSIFY(expected, sizeof(expected));
1039+
1040+
// Make a copy of the secret length to avoid interfering with the loop.
1041+
size_t secret_len = len;
1042+
CONSTTIME_SECRET(&secret_len, sizeof(secret_len));
1043+
1044+
SHA512_CTX ctx;
1045+
SHA384_Init(&ctx);
1046+
SHA384_Update(&ctx, buf, prefix);
1047+
uint8_t computed[SHA384_DIGEST_LENGTH];
1048+
ASSERT_TRUE(EVP_final_with_secret_suffix_sha384(
1049+
&ctx, computed, buf + prefix, secret_len, max_len));
1050+
1051+
CONSTTIME_DECLASSIFY(computed, sizeof(computed));
1052+
EXPECT_EQ(Bytes(expected), Bytes(computed));
1053+
}
1054+
}
1055+
}
1056+
}
1057+
1058+
10111059
TEST(CipherTest, GetCipher) {
10121060
const EVP_CIPHER *cipher = EVP_get_cipherbynid(NID_aes_128_gcm);
10131061
ASSERT_TRUE(cipher);

crypto/cipher_extra/e_aes_cbc_hmac_sha256.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,9 @@ static int aesni_cbc_hmac_sha256_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out,
246246
size_t mac_len;
247247
uint8_t record_mac_tmp[EVP_MAX_MD_SIZE];
248248
uint8_t *record_mac;
249-
if (!EVP_tls_cbc_digest_record_sha256(EVP_sha256(), mac, &mac_len, key->aux.tls_aad,
250-
out, data_len, len, key->hmac_key, 64)) {
249+
if (!EVP_tls_cbc_digest_record(EVP_sha256(), mac, &mac_len,
250+
key->aux.tls_aad, out, data_len, len,
251+
key->hmac_key, 64)) {
251252
OPENSSL_PUT_ERROR(CIPHER, CIPHER_R_BAD_DECRYPT);
252253
return 0;
253254
}

0 commit comments

Comments
 (0)