12921 Commits

Author SHA1 Message Date
Brian Smith
69d1dd34e6 NFC RsaKeyPair: Add notes about wastefulness of qq and q_mod_n. 2023-11-06 12:52:27 -08:00
Brian Smith
1659f14295 bigint elem_exp_consttime: Make implementations more consistent.
Use the same argument order, naming, etc. as the x86-64 version.
2023-11-04 10:21:59 -07:00
Brian Smith
3044ee705d bigint elem_exp_consttime: Avoid one slice copy.
Take a step towards aligning the two implementations.
2023-11-04 10:21:59 -07:00
Brian Smith
4658c27d52 NFC bigint: Remove Width.
The original idea of `Width` was that we'd support operatings that
worked on multiple same-width but different-modulus values, and/or
we'd support splitting a 2N-limb `BoxedLimb` into two N-limb
`&[Limb]`, etc. However, as things are now, `Width` doesn't really
serve a useful purpose.
2023-11-04 10:21:10 -07:00
Brian Smith
8ed48604d0 RSA signature verification: Avoid wasteful key re-serialization.
When we added `rsa::PublicKey` we changed the `ring::signature` RSA
implementation to construct an `rsa::PublicKey` and then verify the
signature using it. Unfortunately for backward compatibility with old
uses of `RsaKeyPair`, `rsa::PublicKey` constructor constructs (and
allocates) a copy of the ASN.1-serialized public key. This is not
acceptable for users who are using `ring::signature` to verify a
single signature. Refactor `PublicKey` so that it can be bypassed
by the `ring::signature` implementation.

This is a step towards implementing allocation-free RSA signature
verification.
2023-11-02 17:26:13 -07:00
Brian Smith
6920c4fc40 Digest/Polyfill: Remove SHA-1 use of ChunksFixed and delete it.
This is the last step in the removal of `ChunksFixed`, which contains
one line of `unsafe` code.
2023-10-31 11:15:25 -07:00
Brian Smith
6c1d378d8d Chacha20-Poly1305-OpenSSH: Remove use of ChunksFixed.
Take a step towards removing the `unsafe` in `ChunksFixed`'s implementation.
2023-10-31 11:15:25 -07:00
Jiaqi Gao
a9b88826e7 third_party/fiat: replace memcpy with OPENSSL_memcpy
Align with the other use of `OPENSSL_memcpy` in `curve25519_64_adx.h`.
`string.h` will no longer be needed.

Signed-off-by: Jiaqi Gao <jiaqi.gao@intel.com>
2023-10-30 20:01:15 -07:00
Brian Smith
1432533ce9 Enforce clippy::cast_possible_truncation.
For now, just put `#[allow(...)]` directives in the places where the
conversions are done. We'll follow up in the future with the correct
replacement for `as` for each case, as several PRs.
2023-10-30 19:17:48 -07:00
Brian Smith
2b1194c845 NFC: Use pointer::cast instead of as for pointer casts.
Enforce this pattern with Clippy.
2023-10-30 19:17:48 -07:00
Brian Smith
1fa6d09eef Have Clippy block most use of as conversions. 2023-10-30 19:17:48 -07:00
Brian Smith
ad356c99ac Limit libc dependency to ARM and AArch64 targets. 2023-10-30 18:38:06 -07: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
acf9f0df2d Generalize agreement benchmarks to support all algorithms. 2023-10-30 15:41:34 -07:00
Vlad Krasnov
0223beea17 Benchmarks: add ECDSA benchmarks
Fixes: #1772
2023-10-30 13:37:11 -07:00
Brian Smith
19a93d2b10 Curve25519: Add missing static assertion.
Sync with BoringSSL.
2023-10-30 13:23:18 -07:00
Qiu Chaofan
b6c35d54e3 Enable getrandom for AIX 2023-10-30 12:52:46 -07:00
Brian Smith
711d9fc062 AEAD benchmarks: Rewrite to avoid macros.
When this benchmark was imported from crypto-bench to *ring* and
ported from the libtest `#[bench]` framework to Criterion.rs, we
kept the macro-based structure from the original benchmarks. However,
Criterion.rs actually supports the kind of parameterized benchmarking
we do much more naturally, and so we don't need the macros. Get rid of
them.

Also remove distinction between TLS 1.2 and TLS 1.3 AAD. These
benchmarks were originally written long ago when the TLS 1.3 draft
specified a different AAD format.

I hope this will serve as a better example of how to write such
benchmarks than it previously did.
2023-10-27 10:08:58 -07:00
Brian Smith
e7cf02f403 Agreement docs: Eliminate redundant nested peer_public_key in example. 2023-10-26 16:10:15 -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
6613481632 Add P-521 to mk/generate_curves.py.
Add preliminary support for P-521 but don't sync the existing
(semi-)generated code with it.
2023-10-25 13:46:08 -07:00
Brian Smith
e83cf0c0bb Add simplified elliptic curve code generator.
Add a tool to generate and/or verify NIST curve boilerplate.

Sync the existing P-256 and P-384 code with the generator.
2023-10-25 13:46:08 -07:00
Brian Smith
3565fe830f EC Suite B: Remove reudndant "point_mul" tests.
When I generated these test vectors, I gave all of them the same point: the
generator of the curve. Consequently these input files are 100% redundant
with the `point_mul_base.txt` input files. So just remove them and use the
`point_mul_base.txt` files instead.
2023-10-25 10:03:48 -07:00
Brian Smith
be27e8e259 RSA signature verification: Save one multiplication.
Use David Benjamin's idea.
2023-10-20 18:05:47 -07:00
Brian Smith
9dd6141f91 NFC EC: Reduce scope of constant ONE. 2023-10-19 13:12:12 -07:00
Brian Smith
c3fda8b4dd 0.17.5. 2023-10-18 20:58:28 -07:00
Brian Smith
a86b7fabb9 0.17.5-alpha.1. 2023-10-18 20:58:28 -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
159f52c769 Eliminate gathering during table construction.
When `elem_exp_consttime` replaced `BN_mod_exp_mont_consttime` I did
not fully understand the way the table was constructed in the original
function. Recent BoringSSL changes clarify the table construction. Do
it the same way, to restore performance to what it was previously.

This addresses the `// TODO: Optimize this to avoid gathering`.
2023-10-18 11:14:38 -07:00
Brian Smith
19fe19124b bigint elem_exp_consttime: Get rid of entry/entry_mut indexing.
When this code was written, it wasn't clear which assembly language
functions took a pointer to the entire state vs. just a pointer to
the accumulator (etc.). Now upstream clarified things and we can
clarify this code.
2023-10-18 11:14:38 -07:00
Brian Smith
d4bf41eb00 bigint elem_exp_consttime: Add some clarifying comments. 2023-10-18 11:14:38 -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
30665a9759 NFC P-256: Add twin_mul method to PublicScalarOps.
Allow each curve to provide its own `twin_mul` implementation. For now,
use the same implementation we've been using.
2023-10-18 09:49:30 -07:00
Brian Smith
2a0e495903 NFC EC: DRY oneRR_mod_n.
Avoid repeating the value of `oneRR_mod_n` twice in each file.
2023-10-17 10:47:15 -07:00
Vlad Krasnov
20672b2b09 Replace limbs initializer with const from_hex
The current macro initializer is not uniform across architectures,
and doesn't work when the number of 64bit limbs is not exactly half
that of 32bit limbs, (i.e. 521 bit).
This change replaces all limbs! initializers with a new const
function with hex string initializers, which is more portable and
more ergonomic.
2023-10-16 23:18:30 -07:00
Brian Smith
057de0ff98 0.17.4. 2023-10-15 20:57:03 -07:00
Brian Smith
e0bc21f51a 0.17.4-alpha.1. 2023-10-15 12:48:10 -07:00
Brian Smith
ae376cb94e rand: Sort target_os list. 2023-10-15 12:48:10 -07:00
Brian Smith
f56cc4190d rand: Remove redundant target_os = "wasi".
It's already included as part of the `all(target_arch = "wasm32" ...)`
below.
2023-10-15 12:48:10 -07:00
tema2
4aa1b14dcf use default rand impl for hermit since getrand has it for 8 month 2023-10-15 09:00:58 -07:00
Brian Smith
9d4bb22ef8 build.rs: Sort non-MSVC C compiler flags alphabetically.
All the `-W...` flags make do difference in packaged releases,
but `-fvisibility=hidden` is a big deal, so don't hide it after
all the warning stuff.
2023-10-14 22:03:50 -07:00
Brian Smith
8909e6eddf build.rs: Don't enable MSVC SDL warnings.
They hardly matter for this codebase any more.
2023-10-14 22:03:50 -07:00
Brian Smith
65941d014f build.rs: Don't override Windows exception/RTTI/C++ compiler flags.
Use whatever cc-rs does by default. This shouldn't impact us as we
don't use C++.
2023-10-14 22:03:50 -07:00
Brian Smith
2201721cd3 build.rs: Let cc-rs choose the hardening flags, if any.
Now that we have almost no C code in *ring* there's little
need for these extra hardening flags.
2023-10-14 22:03:50 -07:00
Brian Smith
89172b4ff6 rand: Clarify wasm32-logic logic.
Require `target_arch = "wasm32"` for `target_os = "wasi"`.
2023-10-14 18:29:44 -07:00
Brian Smith
c32f7a23d8 Digest tests: Don't disable tests for wasm32 targets. 2023-10-14 18:29:44 -07:00