Skip to content
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

Merge BoringSSL through 20c93abd47726624ab3e479466078f7e63f081f7 #2264

Merged
merged 44 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
6855f30
Remove unused files from pki
davidben Jan 30, 2024
56d3ad9
Require SSE2 when targetting 32-bit x86
davidben Jan 27, 2024
608becc
Fix strict aliasing issues with DES_cblock
davidben Jan 20, 2024
10a2132
Create a new NameConstraints constructor that takes in an already con…
hubertchao Feb 1, 2024
79123ca
Ensure additions in this call can't overflow.
Feb 3, 2024
34b51fa
Avoid conversion overflow from struct tm.
Feb 6, 2024
8ff5add
Tighten up the warning about RSAES-PKCS1-v1_5
davidben Feb 8, 2024
fbb4133
Add SSL_get0_chain method
gredner Feb 8, 2024
5dd15f3
Expose OPENSSL_timegm in posix_time.h
Feb 8, 2024
10605c0
Minor formatting fixes
davidben Feb 9, 2024
71c5896
Add functions to convert from Span<const uint8> and std::string_view
davidben Jan 30, 2024
c39e6cd
Use uint64_t for num_read and num_write in BIO
davidben Feb 10, 2024
324db64
Allow the delegate to indicate it wishes to accept PreCertificates
Jan 25, 2024
b1d34cb
Add public API for a certificate.
Nov 23, 2023
80b08df
Don't assume that Fiat assembly is available on Windows.
Feb 13, 2024
58a318e
Make ContainsError look only for Errors, not Warnings.
Feb 13, 2024
48b8146
Move signature_verify_cache.h to openssl/pki as public api
Dec 12, 2023
8049f26
Remove unused include in now public header
davidben Feb 14, 2024
38d17d3
Mark ASN1_STRFLAGS_* and XN_FLAG_* with the right type
davidben Feb 14, 2024
ba5eb62
Add X509_STORE_get1_objects
davidben Jan 25, 2024
5a1a5fb
Remove X509_TRUST_DEFAULT
davidben Dec 26, 2023
1b08502
Unexport most of X509_TRUST and X509_PURPOSE and simplify
davidben Dec 26, 2023
8e6a26d
Merge X509_PURPOSE/X509_TRUST IDs and indices
davidben Dec 26, 2023
a028a23
Document X509_V_FLAG_*
davidben Dec 26, 2023
cb47fdc
Switch to bindgen's static inline support
davidben Feb 14, 2024
22c5477
Include verify_unittest files in PKI_TEST_DATA
agl Feb 14, 2024
9c20a89
Guard C++ headers.
agl Feb 14, 2024
d7f5e18
Work around bindgen bug around constants
davidben Feb 14, 2024
2a5db68
Remove pki/tag.h
davidben Feb 7, 2024
0568c2c
Rewrite the warning about X509_AUX
davidben Dec 28, 2023
c528061
Allow a C++ runtime dependency in libssl
davidben Feb 15, 2024
46ff4f7
Unexport DIST_POINT_set_dpname
davidben Jan 1, 2024
ea003bd
Add x509.h to doc.config
davidben Jan 25, 2024
23824fa
bssl-crypto: remove unused code.
Feb 16, 2024
99e8c6e
Add a no-op OPENSSL_INIT_NO_ATEXIT
davidben Feb 16, 2024
da3b372
Don't report libpki headers as part of libcrypto
davidben Feb 18, 2024
48b0edf
Update delegated credentials to the final RFC
davidben Feb 11, 2024
20c93ab
Remove OPENSSL_IA32_SSE2 checks in x86 perlasm
davidben Jan 27, 2024
5ab7e72
ignore BoringSSL 6855f30.
briansmith Jan 21, 2025
5895ed0
Skip BoringSSL 56d3ad9.
briansmith Jan 21, 2025
4033766
Ignore BoringSSL 608becc..b1d34cb.
briansmith Jan 21, 2025
990b092
Merge BoringSSL 80b08df: Don't assume that Fiat assembly is available…
briansmith Jan 21, 2025
7fb4201
Ignore BoringSSL 58a318e..48b0edf.
briansmith Jan 21, 2025
ee7f382
Merge BoringSSL 20c93ab: Remove OPENSSL_IA32_SSE2 checks in x86 perlasm.
briansmith Jan 21, 2025
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
Prev Previous commit
Next Next commit
Fix strict aliasing issues with DES_cblock
After all, we have to keep this robust, modern cipher conforming to C
well-definedness expectations!

These functions should have simply taken uint8_t* pointers. Make
internal _ex variants that fix this. I've not bothered updating the
public APIs because it will cause a ton of downstream churn and make
those APIs even more OpenSSL-incompatible.  (OpenSSL's APIs take a
const-incorrect uint8_t (*in)[8]. Both our struct and their pointers
expect callers to call with &foo.) This does not seem worth the trouble.

Also since the underlying functions now access as uint8_t*, I suspect
this broadly fixes strict aliasing issues with callers that cast from a
byte array. (Though perhaps in->bytes should be (const uint8_t*)in?)

Ideally c2l and l2c would be replaced with CRYPTO_load_u32_le and
CRYPTO_store_u32_le. (It's a little rude for a header to squat those
names, especially when those name often vary in endianness.) I did that
in a couple places where we'd otherwise increment a pointer declared
with the funny array parameter syntax.  Otherwise I left it alone for
now.

Fixed: 683
Change-Id: I7b0d8b2a16697095ebf42a71482c4ba805a193e4
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/65690
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Bob Beck <bbe@google.com>
  • Loading branch information
davidben authored and Boringssl LUCI CQ committed Jan 31, 2024
commit 608becc67282174594fdaf0ec9c96daca9710d2f
43 changes: 15 additions & 28 deletions crypto/cipher_extra/e_des.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#include <openssl/des.h>
#include <openssl/nid.h>

#include "../des/internal.h"
#include "../fipsmodule/cipher/internal.h"
#include "internal.h"

Expand All @@ -71,20 +72,15 @@ typedef struct {

static int des_init_key(EVP_CIPHER_CTX *ctx, const uint8_t *key,
const uint8_t *iv, int enc) {
DES_cblock *deskey = (DES_cblock *)key;
EVP_DES_KEY *dat = (EVP_DES_KEY *)ctx->cipher_data;

DES_set_key(deskey, &dat->ks.ks);
DES_set_key_ex(key, &dat->ks.ks);
return 1;
}

static int des_cbc_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in,
size_t in_len) {
EVP_DES_KEY *dat = (EVP_DES_KEY *)ctx->cipher_data;

DES_ncbc_encrypt(in, out, in_len, &dat->ks.ks, (DES_cblock *)ctx->iv,
ctx->encrypt);

DES_ncbc_encrypt_ex(in, out, in_len, &dat->ks.ks, ctx->iv, ctx->encrypt);
return 1;
}

Expand Down Expand Up @@ -113,8 +109,7 @@ static int des_ecb_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out, const uint8_t *in,

EVP_DES_KEY *dat = (EVP_DES_KEY *)ctx->cipher_data;
for (size_t i = 0; i <= in_len; i += ctx->cipher->block_size) {
DES_ecb_encrypt((DES_cblock *)(in + i), (DES_cblock *)(out + i),
&dat->ks.ks, ctx->encrypt);
DES_ecb_encrypt_ex(in + i, out + i, &dat->ks.ks, ctx->encrypt);
}
return 1;
}
Expand Down Expand Up @@ -144,23 +139,18 @@ typedef struct {

static int des_ede3_init_key(EVP_CIPHER_CTX *ctx, const uint8_t *key,
const uint8_t *iv, int enc) {
DES_cblock *deskey = (DES_cblock *)key;
DES_EDE_KEY *dat = (DES_EDE_KEY *)ctx->cipher_data;

DES_set_key(&deskey[0], &dat->ks.ks[0]);
DES_set_key(&deskey[1], &dat->ks.ks[1]);
DES_set_key(&deskey[2], &dat->ks.ks[2]);

DES_set_key_ex(key, &dat->ks.ks[0]);
DES_set_key_ex(key + 8, &dat->ks.ks[1]);
DES_set_key_ex(key + 16, &dat->ks.ks[2]);
return 1;
}

static int des_ede3_cbc_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out,
const uint8_t *in, size_t in_len) {
DES_EDE_KEY *dat = (DES_EDE_KEY *)ctx->cipher_data;

DES_ede3_cbc_encrypt(in, out, in_len, &dat->ks.ks[0], &dat->ks.ks[1],
&dat->ks.ks[2], (DES_cblock *)ctx->iv, ctx->encrypt);

DES_ede3_cbc_encrypt_ex(in, out, in_len, &dat->ks.ks[0], &dat->ks.ks[1],
&dat->ks.ks[2], ctx->iv, ctx->encrypt);
return 1;
}

Expand All @@ -182,13 +172,11 @@ const EVP_CIPHER *EVP_des_ede3_cbc(void) { return &evp_des_ede3_cbc; }

static int des_ede_init_key(EVP_CIPHER_CTX *ctx, const uint8_t *key,
const uint8_t *iv, int enc) {
DES_cblock *deskey = (DES_cblock *)key;
DES_EDE_KEY *dat = (DES_EDE_KEY *)ctx->cipher_data;

DES_set_key(&deskey[0], &dat->ks.ks[0]);
DES_set_key(&deskey[1], &dat->ks.ks[1]);
DES_set_key(&deskey[0], &dat->ks.ks[2]);

// 2-DES is 3-DES with the first key used twice.
DES_set_key_ex(key, &dat->ks.ks[0]);
DES_set_key_ex(key + 8, &dat->ks.ks[1]);
DES_set_key_ex(key, &dat->ks.ks[2]);
return 1;
}

Expand Down Expand Up @@ -217,9 +205,8 @@ static int des_ede_ecb_cipher(EVP_CIPHER_CTX *ctx, uint8_t *out,

DES_EDE_KEY *dat = (DES_EDE_KEY *) ctx->cipher_data;
for (size_t i = 0; i <= in_len; i += ctx->cipher->block_size) {
DES_ecb3_encrypt((DES_cblock *) (in + i), (DES_cblock *) (out + i),
&dat->ks.ks[0], &dat->ks.ks[1], &dat->ks.ks[2],
ctx->encrypt);
DES_ecb3_encrypt_ex(in + i, out + i, &dat->ks.ks[0], &dat->ks.ks[1],
&dat->ks.ks[2], ctx->encrypt);
}
return 1;
}
Expand Down
77 changes: 45 additions & 32 deletions crypto/des/des.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,13 +379,17 @@ static const uint32_t DES_SPtrans[8][64] = {
(a) = (a) ^ (t) ^ ((t) >> (16 - (n))))

void DES_set_key(const DES_cblock *key, DES_key_schedule *schedule) {
DES_set_key_ex(key->bytes, schedule);
}

void DES_set_key_ex(const uint8_t key[8], DES_key_schedule *schedule) {
static const int shifts2[16] = {0, 0, 1, 1, 1, 1, 1, 1,
0, 1, 1, 1, 1, 1, 1, 0};
uint32_t c, d, t, s, t2;
const uint8_t *in;
int i;

in = key->bytes;
in = key;

c2l(in, c);
c2l(in, d);
Expand Down Expand Up @@ -626,32 +630,34 @@ void DES_decrypt3(uint32_t data[2], const DES_key_schedule *ks1,

void DES_ecb_encrypt(const DES_cblock *in_block, DES_cblock *out_block,
const DES_key_schedule *schedule, int is_encrypt) {
uint32_t l;
uint32_t ll[2];
const uint8_t *in = in_block->bytes;
uint8_t *out = out_block->bytes;
DES_ecb_encrypt_ex(in_block->bytes, out_block->bytes, schedule, is_encrypt);
}

c2l(in, l);
ll[0] = l;
c2l(in, l);
ll[1] = l;
void DES_ecb_encrypt_ex(const uint8_t in[8], uint8_t out[8],
const DES_key_schedule *schedule, int is_encrypt) {
uint32_t ll[2];
ll[0] = CRYPTO_load_u32_le(in);
ll[1] = CRYPTO_load_u32_le(in + 4);
DES_encrypt1(ll, schedule, is_encrypt);
l = ll[0];
l2c(l, out);
l = ll[1];
l2c(l, out);
ll[0] = ll[1] = 0;
CRYPTO_store_u32_le(out, ll[0]);
CRYPTO_store_u32_le(out + 4, ll[1]);
}

void DES_ncbc_encrypt(const uint8_t *in, uint8_t *out, size_t len,
const DES_key_schedule *schedule, DES_cblock *ivec,
int enc) {
DES_ncbc_encrypt_ex(in, out, len, schedule, ivec->bytes, enc);
}

void DES_ncbc_encrypt_ex(const uint8_t *in, uint8_t *out, size_t len,
const DES_key_schedule *schedule, uint8_t ivec[8],
int enc) {
uint32_t tin0, tin1;
uint32_t tout0, tout1, xor0, xor1;
uint32_t tin[2];
unsigned char *iv;

iv = ivec->bytes;
iv = ivec;

if (enc) {
c2l(iv, tout0);
Expand Down Expand Up @@ -681,7 +687,7 @@ void DES_ncbc_encrypt(const uint8_t *in, uint8_t *out, size_t len,
tout1 = tin[1];
l2c(tout1, out);
}
iv = ivec->bytes;
iv = ivec;
l2c(tout0, iv);
l2c(tout1, iv);
} else {
Expand Down Expand Up @@ -712,7 +718,7 @@ void DES_ncbc_encrypt(const uint8_t *in, uint8_t *out, size_t len,
xor0 = tin0;
xor1 = tin1;
}
iv = ivec->bytes;
iv = ivec;
l2c(xor0, iv);
l2c(xor1, iv);
}
Expand All @@ -722,37 +728,44 @@ void DES_ncbc_encrypt(const uint8_t *in, uint8_t *out, size_t len,
void DES_ecb3_encrypt(const DES_cblock *input, DES_cblock *output,
const DES_key_schedule *ks1, const DES_key_schedule *ks2,
const DES_key_schedule *ks3, int enc) {
uint32_t l0, l1;
uint32_t ll[2];
const uint8_t *in = input->bytes;
uint8_t *out = output->bytes;
DES_ecb3_encrypt_ex(input->bytes, output->bytes, ks1, ks2, ks3, enc);
}

c2l(in, l0);
c2l(in, l1);
ll[0] = l0;
ll[1] = l1;
void DES_ecb3_encrypt_ex(const uint8_t in[8], uint8_t out[8],
const DES_key_schedule *ks1,
const DES_key_schedule *ks2,
const DES_key_schedule *ks3, int enc) {
uint32_t ll[2];
ll[0] = CRYPTO_load_u32_le(in);
ll[1] = CRYPTO_load_u32_le(in + 4);
if (enc) {
DES_encrypt3(ll, ks1, ks2, ks3);
} else {
DES_decrypt3(ll, ks1, ks2, ks3);
}
l0 = ll[0];
l1 = ll[1];
l2c(l0, out);
l2c(l1, out);
CRYPTO_store_u32_le(out, ll[0]);
CRYPTO_store_u32_le(out + 4, ll[1]);
}

void DES_ede3_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t len,
const DES_key_schedule *ks1,
const DES_key_schedule *ks2,
const DES_key_schedule *ks3, DES_cblock *ivec,
int enc) {
DES_ede3_cbc_encrypt_ex(in, out, len, ks1, ks2, ks3, ivec->bytes, enc);
}

void DES_ede3_cbc_encrypt_ex(const uint8_t *in, uint8_t *out, size_t len,
const DES_key_schedule *ks1,
const DES_key_schedule *ks2,
const DES_key_schedule *ks3, uint8_t ivec[8],
int enc) {
uint32_t tin0, tin1;
uint32_t tout0, tout1, xor0, xor1;
uint32_t tin[2];
uint8_t *iv;

iv = ivec->bytes;
iv = ivec;

if (enc) {
c2l(iv, tout0);
Expand Down Expand Up @@ -786,7 +799,7 @@ void DES_ede3_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t len,
l2c(tout0, out);
l2c(tout1, out);
}
iv = ivec->bytes;
iv = ivec;
l2c(tout0, iv);
l2c(tout1, iv);
} else {
Expand Down Expand Up @@ -834,7 +847,7 @@ void DES_ede3_cbc_encrypt(const uint8_t *in, uint8_t *out, size_t len,
xor1 = t1;
}

iv = ivec->bytes;
iv = ivec;
l2c(xor0, iv);
l2c(xor1, iv);
}
Expand Down
24 changes: 24 additions & 0 deletions crypto/des/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ extern "C" {
#endif


// TODO(davidben): Ideally these macros would be replaced with
// |CRYPTO_load_u32_le| and |CRYPTO_store_u32_le|.

#define c2l(c, l) \
do { \
(l) = ((uint32_t)(*((c)++))); \
Expand Down Expand Up @@ -147,6 +150,27 @@ extern "C" {
} while (0)


// Correctly-typed versions of DES functions.
//
// See https://crbug.com/boringssl/683.

void DES_set_key_ex(const uint8_t key[8], DES_key_schedule *schedule);
void DES_ecb_encrypt_ex(const uint8_t in[8], uint8_t out[8],
const DES_key_schedule *schedule, int is_encrypt);
void DES_ncbc_encrypt_ex(const uint8_t *in, uint8_t *out, size_t len,
const DES_key_schedule *schedule, uint8_t ivec[8],
int enc);
void DES_ecb3_encrypt_ex(const uint8_t input[8], uint8_t output[8],
const DES_key_schedule *ks1,
const DES_key_schedule *ks2,
const DES_key_schedule *ks3, int enc);
void DES_ede3_cbc_encrypt_ex(const uint8_t *in, uint8_t *out, size_t len,
const DES_key_schedule *ks1,
const DES_key_schedule *ks2,
const DES_key_schedule *ks3, uint8_t ivec[8],
int enc);


// Private functions.
//
// These functions are only exported for use in |decrepit|.
Expand Down