1770 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
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
Qiu Chaofan
b6c35d54e3 Enable getrandom for AIX 2023-10-30 12:52:46 -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
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
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
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
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
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
89172b4ff6 rand: Clarify wasm32-logic logic.
Require `target_arch = "wasm32"` for `target_os = "wasi"`.
2023-10-14 18:29:44 -07:00
Brian Smith
65aa65d49a NFC: Don't treat wasm32 differently w.r.t. dead-code warnings. 2023-10-14 18:29:44 -07:00
JanKaul
2019d8482f Add support for wasm32-wasi.
[The files changed in this commit were part of the original PR. The
original PR also changed other files, but those changes were removed.]
2023-10-14 16:50:18 -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
e7aedb26c6 Change documentation & unnecessary qualification warnings.
Don't warn during `cargo build` or `cargo test`, but deny them
in `mk/clippy.sh` so that they are caught in CI. Limit `cargo build`
warnings to things that matter during the edit/test cycle.
2023-10-13 16:11:25 -07:00
Brian Smith
ce184528d1 NFC: Remove outdated comment about old behavior of derive(...). 2023-10-13 16:11:25 -07:00
Brian Smith
f78a8418fa Remove some superfluous warning allow(...) overrides. 2023-10-13 16:11:25 -07:00
Brian Smith
bafde9dba7 Clippy: Move lint configuration to lib.rs. 2023-10-13 16:11:25 -07:00
Brian Smith
8edeead004 Minimize scope of clippy::upper_case_acronyms. 2023-10-13 15:03:55 -07:00
Brian Smith
83719c4c0f AEAD/Polyfill: Use ArraySplitMap instead of ChunksFixed.
This is a step towards eliminating the `unsafe` code in `ChunksFixed`.
2023-10-13 11:29:41 -07:00
Brian Smith
32f209e0fd ChaCha20: Use ArraySplitMap to construct Iv.
This is a step towards eliminating the `unsafe` in `chunks_fixed()`.
2023-10-13 11:29:41 -07:00
Brian Smith
ff3febd530 AEAD/Polyfill: Implement ArraySplitMap and construct nonces with it.
This is a step towards eliminating the `unsafe` code in `ChunksFixed`.

chacha nonce
2023-10-13 11:29:41 -07:00
Brian Smith
75c620a5f1 ChaCha20 Polyfill: Remove ChunksFixedMut.
It is only used in one place so it isn't justified.
2023-10-13 10:38:21 -07:00
Brian Smith
f8cad224b5 AES: Remove use of ArrayEncoding.
Take a step towards reducing `unsafe` by eliminating another use of
`ArrayEncoding`.
2023-10-11 12:33:22 -07:00
Brian Smith
b1147381c9 Generalize array_flatten into an ArrayFlatten trait. 2023-10-11 12:33:22 -07:00
Brian Smith
faf347a24c AES-GCM: DRY Iv -> Block conversion. 2023-10-11 12:33:22 -07:00
Brian Smith
e6085e717f AEAD: Remove all use of ring::endian and u64 from Block.
In particular, eliminate the use of `ArrayEncoding::as_byte_array` as
we work towards removing that function because it uses `unsafe`.

Where `Block` is used in parameters to C/assembly code, I verified that
the C/assembly code uses `uint8_t *` as the function type (meaning
`uint8_t[16]`) in the BoringSSL headers. Until recently the stuff in
GCM was using `uint64_t` or a union containing `uint64_t`, which is why
block was previously defined in terms of `BigEndian<u64>`.
2023-10-11 11:35:05 -07:00
Brian Smith
797a6eece9 remove From<[u64; 2]> for Block 2023-10-11 10:14:39 -07:00
Brian Smith
e0eb70d848 Remove From<Block> for [u64; 2]. 2023-10-11 10:14:39 -07:00
Brian Smith
8a6d6f4dbe GCM: Remove use of Into<[BigEndian<u64>; 2]>.
Take a step towards removing the `u64` functionality from `Block`.
2023-10-11 10:14:39 -07:00
Brian Smith
d30dda0745 Remove LittleEndian usage from Poly1305 and delete LittleEndian.
This is a step towards eliminating `unsafe` usage in `ring::endian` by
eliminating one use of `ArrayEncoding::as_byte_array`.

Since this is the only usage of `LittleEndian`, it is removed
completely.

This simple `array_flatten` polyfill will be useful for multiple
improvements towards eliminating the unsafe code in `endian`.
2023-10-10 23:45:12 -07:00
Brian Smith
7cc44151d5 Remove use of ring::endian from aead::chacha20_poly1305_openssh.
This is a step towards removing `ArrayEncoding::as_byte_array()`.
2023-10-10 23:14:53 -07:00