Commit Graph

20 Commits

Author SHA1 Message Date
Joseph Birr-Pixton 327444fdb8 Expose FIPS "service indicator"
This means a `ClientConfig` and `ServerConfig` can be asked whether it
is in fips mode, and it answers by asking the same of all its
constituent cryptography.
2023-12-07 13:45:27 +00:00
Joseph Birr-Pixton f0a6ec1110 Make receiver of `cipher::Message{En,De}crypter` mutable
This is necessary if implementations want to keep state between calls --
(eg, *ring*'s `aead::OpeningKey`).  The next commit takes advantage
of this.
2023-11-21 09:58:03 +00:00
Joseph Birr-Pixton 9931adfdc7 Split off tls12 module for aws-lc-rs 2023-11-21 09:58:03 +00:00
Joseph Birr-Pixton fdd1f8dd4f Move key usage limits up into `CipherSuiteCommon` 2023-11-17 19:27:21 +00:00
Christian Poveda 63ddf03a7c add `encrypted_payload_len` to `MessageEncrypter` 2023-11-16 19:15:54 +00:00
Joseph Birr-Pixton aaf21d1cdf Allow optional use of aws-lc-rs
Provide shims for limited number of places where ring 0.17 and
aws-lc-rs (ring 0.16-era) APIs have diverged.  This is a
short-term fix, as they are likely to diverge more over time.
Eventually we'll have to stop sharing the code like this.

For unit-like tests, export a `test_provider` alias that resolves
to a provider module, for use in these tests.

This resolves to:

- *ring* if cfg(feature = "ring"), else
- aws-lc-rs if cfg(feature = "aws_lc_rs"), else
- is absent
2023-11-09 16:18:11 +00:00
Joseph Birr-Pixton 7aa87e98a4 Make modules in crypto::ring reusable
They take the dependency on ring via `super::ring_like`, which
means they can be reused against a different, ring-compatible
crate.
2023-11-09 16:18:11 +00:00
Joseph Birr-Pixton d5923030d6 Put TLS1.2 PRF implementation behind a trait
This replaces the HMAC trait in Tls12CipherSuite
(there were no other uses of HMAC).

Provide an implementation of the new PRF trait in terms of
HMAC, for convenience of providers that have a HMAC (common)
but not a separate TLS1.2 PRF (relatively uncommon).  The
*ring* and `provider-example/` providers use this.
2023-10-26 11:12:05 +00:00
Jorge Aparicio 5427a4d6e9 use `core::prelude` instead of `std::prelude` 2023-10-10 15:53:23 +00:00
Daniel McCarney 55bb27953d suites: rework `ConnectionTrafficSecrets`
This commit updates `ConnectionTrafficSecrets` to hold `AeadKey` and
`Iv` instances, instead of byte arrays, removing the need for the
`slices_to_arrays` and `slice_to_array` helpers.
2023-09-28 12:57:59 +00:00
Daniel McCarney 21a7df5700 proj: remove secret_extraction feature
In an effort to reduce our feature list, this commit replaces the
`secret_extraction` feature flag with functions that are always present,
but named `dangerous_extract_secrets` to emphasize potential danger.

Cargo features are additive, which means transitive dependencies could
enable them for you without explicit opt-in. Using obviously named
functions will maintain the property that it's easy to grep for imports,
but avoids feature flag bloat and the additive downsides.
2023-09-27 13:21:16 +00:00
Daniel McCarney 79fd1f7639 suites: lift slice_to_array(s) helpers
The *ring* TLS 1.2 and TLS 1.3 AEAD algorithm implementations all shared
the same `slice_to_array` and `slices_to_arrays` helpers used to carve
up IV values for `extract_keys`.

This commit lifts these helpers to be associated with the
`ConnectionTrafficSecrets` type in the `suites` mod. This reduces
duplication, allowing all usages to share the same implementation.
2023-09-27 13:21:16 +00:00
Daniel McCarney fdcaed4145 cipher: impl `AsRef<[u8]>` for `Iv`
The TLS1.3 `Tls13AeadAlgorithm` trait passes an `Iv` instance to
`extract_secrets`. In order for a crate-external crypto provider to
offer an instance of this trait there needs to be a way to access the
`Iv`'s underlying `&[u8]` value. The crate-internal implementations of
`Tls13AeadAlgorithm` do this by accessing `Iv.0`, but this field is
`pub(crate)`.

This commit implements `AsRef<[u8]>` for `Iv` for this purpose, and
switches the existing `Iv.0` accesses to use it too. This allows
removing the `pub(crate)` access to the underlying array after also
exporting the cipher `NONCE_LEN` and exposing `Iv::new` for construction
from the correct size nonce array.
2023-09-27 13:21:16 +00:00
Daniel McCarney 3ab24727ac cipher: make extract_keys fallible
The `ConnectionTrafficSecrets` enum has a fixed number of variants,
describing supported AEAD algorithm secrets. Since it's now possible for
a crate-external crypto provider to supply new AEAD algorithms we need
to make the `extract_secrets` fn of the TLS 1.2 and TLS 1.3 AEAD
algorithm traits fallible so that if an algorithm is provided that
doesn't have a matching `ConnectionTrafficSecrets` variant, the
algorithm can return an `UnsupportedOperationError` when
`extract_secrets` is called.
2023-09-27 13:21:16 +00:00
Joseph Birr-Pixton f6f7df55c9 OpaqueMessage: privatize payload type
This removes a further need for `Payload` to be understood outside
this crate.  `payload()` allows immutable access as a slice,
`payload_mut()` allows mutable access to the underlying vec (such
as needed to decrypt the message without a copy).
2023-09-13 15:32:29 +00:00
Joseph Birr-Pixton 49f071b775 OpaqueMessage: allow construction without exposing `Payload` 2023-09-13 15:32:29 +00:00
Joseph Birr-Pixton 0f9206e782 Tighten up key type on `Tls12AeadAlgorithm` 2023-08-25 14:01:04 +00:00
Joseph Birr-Pixton b421083f51 crypto::cipher: publicise traits for external use
This makes `Tls12AeadAlgorithm` and `Tls13AeadAlgorithm` public, as well as
the types that are associated with them.

Document fields that need to become public to allow `Tls12CipherSuite` and
`Tls13CipherSuite` to become public.
2023-08-25 14:01:04 +00:00
Joseph Birr-Pixton 6757c25a4f Remove unused BulkAlgorithm enum 2023-08-25 14:01:04 +00:00
Joseph Birr-Pixton d0db689d08 Move ring-backed ciphersuites into crypto::ring
As a result, crate::tls12::cipher becomes trivial enough to merge
into its parent.
2023-08-25 14:01:04 +00:00