11265 Commits

Author SHA1 Message Date
Brian Smith
638919f872 cargo-deny: Disable some checks that are redundant with cargo-audit.
Avoid needing to configure overrides in multiple places.
2021-12-09 10:02:53 -08:00
Brian Smith
0cd0d2dc58 audit: Don't break the build due to serde_cbor being unmaintained. 2021-12-09 10:02:53 -08:00
Brian Smith
c761338721 rsa/bigint internals: Document memory safety properties of unsafe traits. 2021-12-09 10:02:53 -08:00
Brian Smith
62ffd918bc bigint/rsa: Change PublicModulus from an unsafe trait to trait.
The distinction between public and private modulus doesn't affect memory
safety.
2021-12-09 10:02:53 -08:00
Brian Smith
318dccae71 rsa internals: Remove unneeded cpu_features field.
The inner types (as of recently) now have a `cpu_features` field so the
one in `PublicKey` is redundant.
2021-12-09 10:02:53 -08:00
Brian Smith
4635eef114 digest internals: Clarify why cpu_features is needed. 2021-12-09 10:02:53 -08:00
Brian Smith
8d78cb2c01 wasm32: Add a wasm32_unknown_unknown_js feature to control use of web APIs.
Planning ahead for when WASI is to be supported, require the user to opt into
using web APIs for thw wasm32-unknown-unknown target with a new feature, since
wasm32-unknown-unknown could be used for either web or non-web environments.

Don't bother updating the tests to use this new flag, since the tests aren't
part of the "public API" of *ring*. When we add support for other WebAssembly
environments (e.g. WASI) we'll update the tests then.
2021-10-06 15:53:02 -07:00
Brian Smith
d97ae1fd08 wasm32: Make wasm32_c the default and only mode; remove the "wasm32_c" feature.
Always require a C compilare for wasm32, instead of trying to provide a subset
of the functionality.
2021-10-06 15:53:02 -07:00
Brian Smith
fe23432127 RSA: Split PSS into its own submodule. 2021-10-06 09:48:27 -07:00
Brian Smith
61c5ec82d1 RSA: Split PKCS#1 into its own submodule. 2021-10-06 09:48:27 -07:00
Brian Smith
245a76a7b3 CI: Add various feature combinations to the test matrix. 2021-10-06 08:44:03 -07:00
Brian Smith
e332ac4b61 Fix cargo test --no-default-features.
Unfortunately, some of the tests require `alloc` even when the `alloc` feature
isn't enabled. That's something to address in the future.
2021-10-06 08:44:03 -07:00
Brian Smith
034cd2b478 Fix cargo build --no-default-features.
`cargo test --no-default-features` will be fixed separately.
2021-10-06 08:44:03 -07:00
Brian Smith
6c81e9b49a RSA: Split rsa::KeyPair::sign encoding and arithmetic.
Factor out the arithmetic so that it can be reused by the upcoming OAEP
implementation.

Remove the reference to the "Manger's Attack revisited" paper since it
is already cited in `fill_be_bytes` and because, at the time
`fill_be_bytes` is called by `sign()`, that attack is no longer
relevant since we're operating on the final signature value itself.
2021-10-05 19:21:43 -07:00
Brian Smith
35642efbb9 RSA: Improve the documentation for rsa::KeyPair::sign().
Clarify that `KeyPair::sign()` won't panic. Clarify that it scribles into the
output buffer.
2021-10-05 19:21:43 -07:00
Brian Smith
4726077536 RSA: Test more output buffer lengths passed to rsa::KeyPair::sign(). 2021-10-05 19:21:43 -07:00
Brian Smith
7a443f9bb2 digest: Linkify rustdoc cross-references.
Linkify the cross-references in the `digest` module.

Trim some of the superfluous text instead of linkifying it.
2021-10-04 15:37:16 -07:00
Brian Smith
4df3aa8417 digest: Use Rustdoc conventions for summary/detail documentation. 2021-10-04 15:37:16 -07:00
Brian Smith
a26925cd1e digest: Make public Algorithm fields accessor functions.
This was done a long time ago for `aead` and other modules.
2021-10-04 15:37:16 -07:00
Brian Smith
6510527bff signature: Fix doc test when --feature=std is used. 2021-10-04 15:05:58 -07:00
Brian Smith
f0cad0ad07 Remove BitLength, PublicModulus, PublicExponent from the public API.
Replace `rsa::PublicKey::{n,e}()` with an implementation of `From<&PublicKey>`
for `PublicKeyComponents`. This will fit better with the plans to do the same
for other public key cryptosystem types. This also allows us to remove
`BitLength` from the public API and also to remove some `Debug` implementations.
2021-09-29 13:01:25 -07:00
Brian Smith
1879c0555d RSA: Flatten API by removing public and keypair submodules.
When looking at how this would generlaize to the other public key
cryptosystems (ECDSA, ED25519, etc.), I think having fewer submodules
involved makes more sense.
2021-09-29 13:01:25 -07:00
Brian Smith
88c281e3ea RSA: Move rsa::keypair::Components to rsa::KeyPairComponents.
Take a step towards flattening (and simplifying) the public API of
the RSA submodule. This is done as a separate step from the rest of
the work so that the Git history will correctly reflect that signing.rs
gets renamed to keypair.rs, with only minimial modifications, in the
next commit. (If this were merged with the following commit, then Git
would report the new keypair.rs as a new file without any history from
signing.rs.)
2021-09-29 13:01:25 -07:00
Brian Smith
6cde4b8142 RSA: Derive Clone and Copy more instead of manually implementing them. 2021-09-28 15:02:24 -07:00
Brian Smith
d608eeba3e Refactor RSA PSS MGF processing to enable future use by OAEP.
Previously, `mgf1()` wrote the mask to the buffer, and then we XOR'd
the data onto the mask. Now, `mgf1()` XOR's the mask onto the data
that is already in the `out` buffer.
2021-09-28 12:47:44 -07:00
Brian Smith
766d5be0dd RSA: Remove misleading documentation about side channels protection.
When *ring* first started, BoringSSL and OpenSSL upstream were both
using an implementation of constant-time-ish exponentiation that took
shortcuts that made it clearly not constant-time. Long ago, that code
was replaced here and in BoringSSL (and probably OpenSSL upstream), so
this comment is no longer correct.
2021-09-28 11:18:40 -07:00
Brian Smith
b6fe6caf77 RSA: Split RSA public key arithmetic from signature verification logic.
`Exponent::exponentiate` will eventually be used for both signature
verification and encrypting using a public key.
2021-09-28 10:18:50 -07:00
Brian Smith
8c89dbddf6 RSA/bigint: Thread proof of CPU feature detection through bigint.
The tests of `bigint` were not doing CPU feature detection themselves.
Thus they were depending on some other tests that run before them to do
it, or else they were not making use of all the CPU optimizations
possible, and thus not testing all the interesting code paths.

Also, as we are expanding the functionality of the RSA module, it has
become more difficult to track where CPU feature detection has been done
and where it needs to be done. Move the proof that the CPU feature
detection has been done down into the callers of the `bn_` functions
that need CPU feature detection to have been done.

This will also be helpful if/when we expand the use of the `bigint`
module beyond RSA.
2021-09-27 19:09:08 -07:00
Brian Smith
93d7db9e88 RSA: Remove From<Exponent> for NonZeroU64 implementation.
We shouldn't promise to external users that the exponent will always
fit in a 64-bit integer as in the future we may need to allow larger
exponents.
2021-09-27 19:08:44 -07:00
Brian Smith
751c014e1b RSA internals: Move digest instead of passing a reference when doing padding.
The digest is never used after encoding, so move it instead of referencing it.
This is more correct since for signing (and soon encryption) the padded value
is only supposed to be used once.
2021-09-27 14:57:01 -07:00
Brian Smith
f172986113 RSA: Replace RsaSubjectPublicKey with rsa::public::Key. 2021-09-27 13:09:01 -07:00
Brian Smith
0df07b8483 Eliminate type-level type constraint on UnparsedPublicKey types.
Idiomatic practice in Rust is to avoid type-level constraints in favor
of impl-level constraints so that things aren't over-constrained.

Derive `Clone` and `Copy` instead of explicitly implementing them,
which is now possible after implementing the type-level constraints.
2021-09-27 12:09:42 -07:00
Brian Smith
d33461b877 Derive Clone qnd Copy more instead of explicitly defining them. 2021-09-27 12:09:42 -07:00
Brian Smith
fed775d2c3 RSA: Make rsa::public::Key clonable. 2021-09-24 17:04:16 -07:00
Brian Smith
511740c29f RSA: Replace RsaSubjectPublicKey::{modulus,exponent} with rsa::Public::{Modulus,Exponent}::be_bytes().
This is a step towards removing the heap-allocated and usually-unnecessary
`public_key: RsaSubjectPublicKey` field. The new API allows the caller to
better control how it stores/allocates the component values. This also removes
a couple of infallible `unwrap()`s.

This is a step towards removing `io::Positive` from the public API.

This is a breaking API change.
2021-09-24 14:08:08 -07:00
Brian Smith
dd14e593e1 Testing: Test iterator cloning. 2021-09-24 14:08:08 -07:00
Brian Smith
d3d17338c4 Polyfill: Add LeadingZerosStripped. 2021-09-24 14:08:08 -07:00
Brian Smith
92e15f23dc Make ArrayFlatMap compatible with Rust 1.52.1 (current MSRV). 2021-09-23 16:20:33 -07:00
Brian Smith
b8b35ff124 Internal: Replace some manual big-endian encoding w/ standard library use.
Refactor `limb::big_endian_from_limbs` to use an approach based on
iterators. We will be then be able to use the new `limb::be_bytes`
to implement `rsa::public::Exponent::be_bytes()` and
`rsa::public::Modulus::be_bytes()` and eventually other similar functions.
We want those functions to return `ExactSizeIterator`s.

This is also part of an ongoing process to eliminate replace all the
big-endian/little-endian encoding logic in *ring* w/ use of core APIs.
2021-09-23 16:20:33 -07:00
Brian Smith
0e6be9778d RSA: Add a public RsaKeyPair::from_components function. 2021-09-23 10:44:03 -07:00
Brian Smith
466b724335 Allow private and public RSA key pair components to be of different
types.

In particular, allow the type for the public components to implement
`Debug` without requiring the type for the private components to
implement `Debug`, for the purpose of implementing `Debug` for the
`Components` type itself.
2021-09-23 10:44:03 -07:00
Brian Smith
4a3a17fd21 RSA: Split PKCS#8-specific logic out from general RSA private key construction logic.
Prepare for the introduction of a public API for constructing RSA key pairs from
components, and for the introduction of RSA encryption APIs.
2021-09-23 10:44:03 -07:00
Brian Smith
617b09baa6 RSA: Deprecate and replace RsaKeyPair::public_modulus_len. 2021-09-23 10:43:13 -07:00
Brian Smith
e05f7e1273 Make rsa::{self, public::{self, *}} public. 2021-09-23 10:43:13 -07:00
Brian Smith
6a6ea5893e RSA: Reduce visibility of pub(in crate::rsa) items.
Avoid `pub(in crate::rsa)` in favor of relative visibility constraints.
2021-09-23 10:43:13 -07:00
Brian Smith
d881b64792 Make bits::{self, BitLength} public. 2021-09-23 10:43:13 -07:00
Brian Smith
8ac90f4c3e RSA: Move test_signature_rsa_pkcs1_sign_output_buffer_len to tests/.
It's only using the public API so it should be an integration test.
2021-09-22 13:55:57 -07:00
Brian Smith
562b5e4500 RSA: Clarify validity checking for exponents.
Move the comments citing the standard to more appropriate places. Do the
steps in order.
2021-09-22 11:26:57 -07:00
Brian Smith
b3f07e3df1 Factor out rsa::public::Modulus.
This is a step towards making `rsa::public::Key` public.
2021-09-22 09:49:03 -07:00
Brian Smith
ebb7ba1235 AEAD: Fix rustdoc warnings.
The types `OpeningKey` and `SealingKey` are not in scope so we need to
qualify them.
2021-09-22 08:01:08 -07:00