5504 Commits

Author SHA1 Message Date
Brian Smith
a0ce2d3c22 internal: Add generalized "noinline" attribute support.
There are some functions that we never want to be (cross-language)
inlined, and we expect to add more. Make it easier to add more, and
make it easier to extend this capability to more C compilers.
2024-01-12 17:09:36 -08:00
Brian Smith
f932b941bd Stop exporting unmangled symbols on ARM/AArch64.
We want all of our internal symbols to be internal so that none of
these internal symbols leak from a static/dynamic library that is
built with *ring* inside.
2023-11-27 12:57:54 -08:00
Brian Smith
07aff69462 EC: Fix support for curves like P-521 in the code generator.
Values for P-521 have an odd number of limbs in 32-bit mode, which
means we can't keep using `TOBN`, and also Montgomery-encoded
values are different for 32-bit and 64-bit.
2023-11-13 12:45:39 -08:00
Brian Smith
d87972edc9 EC: Add C code generation to mk/generate_curves.py.
Generate some of the C boilerplate, particularly the large constants.
The output is written into target/curves/, and can be merged into
the actual code in crypto/fipsmodule/ec/ using a two-way merge tool;
this is the same as the Rust code generation.

Changes to gfp_p{256,384}.c are due to differences in the generator's
output:

* The generator doesn't generate trailing commas in arrays.
* The generator consistently avoids adding leading zeros to hex
  constants, and consistently format values less than 10 in decimal;
  the exiting code used a mix of styles.
* The generator wraps arrays consistently; the existing code used a
  mix of wrapping styles.
* The generator does not nest constants in the functions that need
  them. This was changed to support future refactorings.
2023-11-13 12:45:39 -08:00
Brian Smith
fce7153096 Include arm_arch.h in crypto/internal.h.
Do it because BoringSSL does it. BoringSSL has some other headers it
includes here but we intentionally do not have them and/or we
intentionally do not include them here (string.h and assert.h).
2023-10-30 16:01:42 -07:00
Brian Smith
19a93d2b10 Curve25519: Add missing static assertion.
Sync with BoringSSL.
2023-10-30 13:23:18 -07:00
Brian Smith
61ad435f09 EC: Add scalar base point multiplication test case generator.
Add a new scalar base point multiplication test case generator that
where the points are *not* Montgomery-encoded. This way we don't need
to generate different test data files when the Montgomery encoding
for a curve isn't the same for 32-bit and 64-bit targets (P-521).

This version of the generator produces the test cases for all the
scalars that the current P-256 and P-384 tests generate, in the same
format; the only exception is that the point is not
Montgomery-encoded.
2023-10-26 10:25:46 -07:00
David Benjamin
4f2adbd947 Cherry-pick BoringSSL 50418af: Add some EC base point multiplication test vectors.
`git cherry-pick 50418afb7f7e9467bd9b01b42b7732ef46b96baa`.

Bring in the test vector generator unmodified.
2023-10-26 10:25:46 -07:00
Brian Smith
27aa5386a0 EC P-384: Use array types for crossing Rust<->C boundary.
Avoid using the P384_POINT type on the C side. It seems to work for all
the targets we support, for P-384, but this pattern probably doesn't
work in general. Especially due to alignment issues for 32-bit targets,
it is doubtful it would work for P-521.
2023-10-18 11:39:04 -07:00
Brian Smith
327831e6b3 P-256 nistz: Use arrays instead of P256_POINT in boundary functions.
Better match the Rust declarations of these functions. Prepare to
support more target platforms and more weird things (like P-521) that
by avoiding any kind of alignment assumptions at the language
boundary (or elsewhere).
2023-10-18 11:39:04 -07:00
Brian Smith
9a49f379e3 P-256 ECDSA verification: Clarify multiplication.
Move more of the logic for the nistz256 multiplication into Rust.
2023-10-18 09:49:30 -07:00
Brian Smith
6283ca087f P-256 ECDSA verification: Use optimized nistz256 verification.
Import the optimized nistz256 verification from BoringSSL.
2023-10-18 09:49:30 -07:00
Brian Smith
dbfbba4f1a Import ecp_nistz256_points_mul_public from BoringSSL.
From BoringSSL commit 8d71d244c0debac4079beeb02b5802fde59b94bd.

Comment it out until it is modified to work.
2023-10-18 09:49:30 -07:00
Brian Smith
da23dc037e Use small Curve25519 for wasm32 & other non-{aarch64,x86_64}.
Enable `ring::agreement` for wasm32 targets using the small
implementation of Curve25519.

Use the small Curve25519 implementation of Curve25519 (and
P-256) for all targets except for Aarch64 and x86-64.

Besides being smaller, the small implementations are likely
more resistant to compiler-introduced side-channels, which
is especially important for the wasm32 virtual machine and
other targets that we don't QA as thoroughly as AAarch64
and x86-64.

Bring in the previously-removed definition of `fe_mul_llt`
from BoringSSL as of commit
8d71d244c0debac4079beeb02b5802fde59b94bd.
2023-10-14 16:49:57 -07:00
Brian Smith
d1e42e30fd Remove #pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
...for compatibility with compilers that don't know about
`unused-but-set-parameter`.
2023-10-09 21:03:42 -07:00
Brian Smith
639ab71e64 Use CRYPTO_memcmp name the same as BoringSSL.
*ring* defined a function named `OPENSSL_memcmp` that did what
`CRYPTO_memcmp` does in BoringSSL, and BoringSSL has a different
function called `OPENSSL_memcmp`. *ring* doesn't need
`OPENSSL_memcmp` so sync the `CRYPTO_memcmp` stuff with BoringSSL.

This eliminates unnecessary differences from BoringSSL.
2023-10-09 15:17:19 -07:00
Brian Smith
af7c37f8af Enable FE25519_ADX Curve25519 base point mult. except on Windows. 2023-10-06 09:54:59 -07:00
Brian Smith
5aa224c4bc Import constant_time_conditional_memcpy from BoringSSL.
Previously we didn't need it. Now we do.
2023-10-06 09:54:59 -07:00
Brian Smith
3d993da504 Revert "AES: Use SSE2-based implementation as the fallback on x86 and x86-64."
This reverts commit 1a5ad00222405b8e64ee322c61942bdd63cc1e29.

Not all C compilers for i686 support SSE2 by default.
2023-10-01 23:08:30 -07:00
Brian Smith
1a5ad00222 AES: Use SSE2-based implementation as the fallback on x86 and x86-64.
Address some warnings from Clang/GCC in the SSE2 code that are disabled
by default in BoringSSL but not in *ring*.
2023-10-01 21:30:19 -07:00
Ulrich Weigand
079a4faef6 Support big-endian platforms 2023-10-01 14:33:16 -07:00
Brian Smith
7bd536e9df Replicate BoringSSL's test for constant_time_conditional_memxor. 2023-09-30 13:40:06 -07:00
Brian Smith
4581b6fee7 Merge BoringSSL 'bd20800': Add a comment for what compiler_test.cc is about
Try to support more than what BoringSSL does w.r.t. aliasing pointers.
2023-09-29 17:59:31 -07:00
Brian Smith
8bc545d482 Take BoringSSL '764e6a3': Stop rewriting ret to repz ret on x86_64 2023-09-29 17:45:57 -07:00
Brian Smith
0d8ff226ea Take BoringSSL '9f4cad2': Fix typo in .size directives for aesni_gcm_encrypt. 2023-09-29 17:39:19 -07:00
Brian Smith
2f9969b9aa Merge BoringSSL '7ce5d41': Select SHA-256 vs SHA-512 explicitly in perlasm. 2023-09-29 17:27:53 -07:00
Brian Smith
58758d3a0d Merge BoringSSL 'd43fef7': Fix aarch64 build with GCC 2023-09-29 17:12:06 -07:00
Brian Smith
78c62f91df Merge BoringSSL '9fc1c33': Add Intel Indirect Branch Tracking support. 2023-09-29 17:08:34 -07:00
Brian Smith
00da1cb1f7 Merge BoringSSL 'a905bbb': Consistently include BTI markers in every assembly file 2023-09-29 14:52:41 -07:00
David Benjamin
bd20800c22 Add a comment for what compiler_test.cc is about
It's probably worth explaining in a comment that this is about
implementation-defined behavior, and why we consider it okay to make
assumptions like uint8_t == unsigned char.

Change-Id: Ia35248aef7895b0998831b6bac06993e845e6297
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/63285
Auto-Submit: David Benjamin <davidben@google.com>
Commit-Queue: Adam Langley <agl@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2023-09-29 19:14:27 +00:00
Brian Smith
b78f7deffb Merge BoringSSL '3f680b0': Remove a layer of indirection from fiat curve25519 assembly 2023-09-29 12:13:26 -07:00
Brian Smith
0a12e31e02 Partial merge of BoringSSL '9d4f833': Use ADX asm for Curve25519 base-point multiplication.
Add the code but don't plumb it in.
2023-09-29 12:10:32 -07:00
Brian Smith
e0948076a5 Partial merge of BoringSSL '43f8891': Add saturated X25519 for x86_64+ADX running Linux
Add the new code but don't plumb it in yet.
2023-09-29 12:04:04 -07:00
Brian Smith
c274480f40 NFC: Remove more unused constant-time utilities. 2023-09-29 11:54:54 -07:00
Brian Smith
2e6d759e56 NFC: Remove dead code from syncing with BoringSSL.
*ring* doesn't use the BoringSSL code that uses these constant-time
utilities.
2023-09-29 10:30:01 -07:00
Brian Smith
7b59320e3e Merge BoringSSL 'd605df5': Use packed representation for large Curve25519 table 2023-09-28 19:58:53 -07:00
Brian Smith
2d8fbe09e9 Import currently-unused utilities in crypto/internal.h
Bring these in as they were in 4a0393fcf37d7dbd090a5bb2293601a9ec7605da.
The next merge will modify these.
2023-09-28 18:14:14 -07:00
Brian Smith
2270dc6943 Rename crypto_word back to crypto_word_t.
Originally I was trying to be pedantic and avoid any use of `_t`-
suffixed names. However, this hasn't really accomplished anything
except annoying me, so just do what BoringSSL does.
2023-09-28 18:11:05 -07:00
Brian Smith
03de1fa014 Merge BoringSSL '55b069d': Add a value barrier when checking for point doubling. 2023-09-28 17:43:49 -07:00
Brian Smith
30171c0829 Partial merge of BoringSSL 'da757e6': Add constant-time validation for curve25519.
Don't add the constant-time validation tests since we need to develop the
framework for it first.

Do add the public-from-private test.
2023-09-28 17:30:25 -07:00
Brian Smith
e17b48df3c Take BoringSSL '5fcd47d': Add prefetch to aes_hw_ctr32_encrypt_blocks. 2023-09-28 17:09:39 -07:00
Brian Smith
14142649d3 Merge BoringSSL '62f9751': Don't make assumptions about GCM128_CONTEXT layout in aesni-gcm-x86_64.pl. 2023-09-28 16:57:34 -07:00
Brian Smith
1d14b3de74 Partial merge of BoringSSL 'a7f83c4': Don't make assumptions about GCM128_CONTEXT layout in aesv8-gcm-armv8.pl.
This is modifying not-yet-used code.
2023-09-28 16:18:31 -07:00
Brian Smith
183332021f Merge BoringSSL 'ece1f86': Re-add go:build ignore lines 2023-09-28 14:33:29 -07:00
Brian Smith
6e85944940 Merge BoringSSL 'aa31748': Generate 64-bit Curve25519 and P256 code for MSVC 2023-09-28 14:28:33 -07:00
Brian Smith
88331f0737 Take BoringSSL 'abb9af8': Work around a NASM bug. 2023-09-28 12:42:21 -07:00
Brian Smith
c833ff64f9 Merge BoringSSL 'ebd43ef': Move data from .text to .rodata on x86_64 2023-09-28 12:38:20 -07:00
Brian Smith
7dcdf3cf13 Merge BoringSSL 'e18ba27': Move constants from .text to .rodata on aarch64. 2023-09-28 12:35:08 -07:00
Brian Smith
0671a90267 Partial merge of BoringSSL 'd1b4516': Add bn_add_words and bn_sub_words assembly for aarch64.
Bring in the new code as we'll likely use it soon, but not now.

Merged as-is except with the "arm_arch.h" include changed to what we need.
2023-09-28 12:05:52 -07:00
Brian Smith
8166b6855f Merge BoringSSL '53b876a'.
The *ring* counterpart to `copy_from_prebuf` is `LIMBS_select_512_32`
which is already written very (too?) conservatively w.r.t. compiler-
introduced side channels. I inspected the generated code before/after
adding additional `value_barrier_w` and it made no difference.
2023-09-28 11:47:45 -07:00