10692 Commits

Author SHA1 Message Date
Brian Smith
bb17fbb9e7 AES: Change internal CTR32 API to be more like copy_within.
Match what was done for ChaCha20.
2021-02-26 14:57:56 -08:00
Brian Smith
0a40cd431b CI: Use Android "cmdline-tools" instead of SDK tools.
https://github.com/actions/virtual-environments/issues/2252 is the best
description of the difference I have found.

Also stop using `sudo`; maybe this was a holdover from Travis CI days?
2021-02-26 13:22:54 -08:00
Brian Smith
209b866c75 CI: Always use macos-latest and Xcode 12.4.
macos-11.0 is pre-production. Use macos-latest instead, to (I hope)
make macOS jobs more likely to succeed. (Presently, they frequently
fail with no logs.)

Upgrade to Xcode 12.4 in hopes that this will make things work.
2021-02-26 11:25:50 -08:00
Brian Smith
abf9efac0d AEAD: Fix typo in docs for OpeningKey::open_within. 2021-02-24 21:16:07 -08:00
Brian Smith
e8620224e6 AEAD: Move each key type into its own submodule.
Encapsulate each key type in its own module.
2021-02-24 20:15:26 -08:00
Brian Smith
47edace294 AEAD: DRY implementation of Debug for keys. 2021-02-24 20:15:26 -08:00
Brian Smith
82f88d6ac3 AEAD: Simplify the implementation of LessSafeKey.
Inline the implementation of the old `open_within_` function into
`LessSafeKey::open_within`. Rename the inner `open_within` function to
`open_within_`.
2021-02-24 20:15:26 -08:00
Brian Smith
64e9a5490a AEAD: Move LessSafeKey code into a submodule. 2021-02-24 20:15:26 -08:00
Brian Smith
565c8942b4 AEAD: Implement key types in terms of LessSafeKey.
Implement `UnboundKey`, `OpeningKey`, and `SealingKey` in terms of
`LessSafeKey`. Ultimately those key types are restrictoins on the
interface of `LessSafeKey`. It wasn't done this way previously because
we had the idea that code that uses `BoundKey` shouldn't ever touch
`LessSafeKey`. That sounded nice in theory, but the unintended result
was that we introduced code duplication and otherwise made things harder
to understand. Continuing on the previous path would have seen us
duplicate `LessSafeKey` as `KeyInner` or something similar.

Now each bound key opening/sealing function is implemented in terms of
the same-named function in `LessSafeKey`.

Replace the old `LessSafeKey::new()` with an implementation of
`From<UnboundKey>`.
2021-02-24 20:15:26 -08:00
Brian Smith
e48c324695 AEAD tests: Add tests for seal_in_place_separate_tag(). 2021-02-24 05:14:07 +00:00
Brian Smith
29b5727bc1 AEAD test: Add tests for open_in_place(). 2021-02-24 05:14:07 +00:00
Brian Smith
e49a8da4e5 AEAD tests: Further refactor tests to reduce repetition. 2021-02-24 05:14:07 +00:00
Brian Smith
16e1b77f3b AEAD tests: Split test_aead into multiple functions. 2021-02-24 05:14:07 +00:00
Brian Smith
ffa5a9f88f AEAD tests: Refactor to reduce boilerplate. 2021-02-24 05:14:07 +00:00
Brian Smith
0664f59420 AEAD tests: Remove unnecessary prefixes in some test functions. 2021-02-24 05:14:07 +00:00
Brian Smith
930b97b0c9 AEAD: Make Aad implement common traits if the underlying type does. 2021-02-24 00:49:15 +00:00
Brian Smith
c6d8f58ad0 Add a Rust ChaCha20 implementation.
See the comments in fallback.rs for more details on the origin.
2021-02-23 18:39:36 +00:00
Brian Smith
d2ff5d1b3e Tests: Remove unneeded use of Result. 2021-02-11 11:20:16 -08:00
Brian Smith
573290ff34 Curve25519: Deal with too-aggressive Clippy lint.
The function is required to return a `Result` by the higher-level API in
which it is used.
2021-02-11 11:20:16 -08:00
Brian Smith
2223e36b09 Digest internals: Clarify error handling in mgf1.
Clarify why the counter cannot overflow.

Remove the unnecessary use of `Result` in the return type since the
function never returns an error.
2021-02-11 11:20:16 -08:00
Brian Smith
501fc4eeaa Replace *ring*'s P-256 arithmetic with BoringSSL's P-256 arithmetic.
Use Fiat Crypto for non-x86_64 platforms, like BoringSSL. Continue
using the nistz256 code on Windows, differently from BoringSSL.

Make *ring* more consistent with BoringSSL.
2021-02-10 12:20:26 -08:00
Brian Smith
22040aeb34 Simplify ECC field element addition.
Don't require a specialized implementation of field element addition for
each curve; instead share an implementation between RSA and ECC.

Refactor the code to avoid needing `elem_sum`.
2021-02-10 12:20:26 -08:00
Brian Smith
d00bdbe89b AES-GCM: Clarify ghash() functions operate over complete blocks. 2021-02-10 08:42:39 -08:00
Brian Smith
bb6d3260ff Bump MSRV to 1.47.0.
This allows us to use more `const fn` goodness and no more
`array::LengthAtMost32` limitations.
2021-02-10 08:35:20 -08:00
Brian Smith
c294a14925 Use ChunksFixed for splitting OpenSSH ChaCha20 keys. 2021-02-10 01:12:56 -08:00
Brian Smith
f39f4739eb ChaCha: Reduce the use of unsafe; emulate the copy_within API.
Emulate the `copy_within` API so that the use of `unsafe` can be isolated
into a single place.

Remove the test for encryption into disjoint buffers. We should expose
such an API in the future, but currently we don't, so this was testing a
scenerio that would never occur. Removing this part of the test was
necessary to enable this refactoring. We'll need to bring it back when
we implement out-of-place encryption.
2021-02-09 19:08:35 -08:00
Brian Smith
3ffaab5577 ChaCha20: Clarify BLOCK_LEN.
Change the definition of `BLOCK_LEN` to the more useful/correct one that
can be used by the upcoming Rust implementation of ChaCha.
2021-02-09 17:38:22 -08:00
Brian Smith
89df9a0d3a ChaCha20 tests: Stop skipping the offset buffer cases for ARM and x86.
When the test was originally written, it was calling the assembly
function directly. Now it is calling the wrapper that works around the
problem, so we can verify that the workaround works.
2021-02-09 15:07:14 -08:00
Brian Smith
4b5e1e2437 Chacha20 test: Improve buffer handling.
Reset the buffer between iterations. Clarify the slicing.
2021-02-09 15:07:14 -08:00
Brian Smith
c15974c83b Further improve ChaCha20 Counter/IV handling.
The code had this comment:
```
   /// XXX: Although this takes an `Iv`, this actually uses it like a
   /// `Counter`.
```

With the recent refactorings we can fix the type to be `&Counter`. Further
we can get rid of `CounterOrIv`.
2021-02-09 12:34:48 -08:00
Brian Smith
275551e2db Separate Counter and Iv for AES-CTR & ChaCha20; clarify alignment.
Ensure we're always passing in u32-aligned values to `GFp_ChaCha20_ctr32`.

Get rid of the attempt to abstract away the difference between ChaCha20
and AES-CTR w.r.t. counters and IVs. The abstraction wasn't actually used
by any shared code. The AES-CTR (GCM) code does endian conversion in the
assembly so endian conversion cannot easily be deferred to later. For
ChaCha20, it makes more sense to do endian conversion at the time of
`Counter`/`Iv` construction. Despite the slight duplication of logic in
having two `Counter` types and two `Iv` types, this is actually a net
reduction of code. If we ever have a third implementation of these types
we can apply the Rule of Three to factor out the commonality.
2021-02-09 08:53:09 -08:00
Brian Smith
f07e71c150 Add an abstraction for coercing arrays into fixed-length chunks. 2021-02-09 07:24:26 -08:00
Brian Smith
5186d53e6b Remove reference to removed module polyfill::convert. 2021-02-09 07:24:26 -08:00
Brian Smith
46d4362e8b Reimplement Block in terms of endian and simplify its API.
Remove all the `unsafe` blocks from `Block` by reimplementing it using
`endian`. Simplify the API for endian-swapping.
2021-02-05 14:01:48 -08:00
Brian Smith
4c3c93a241 Remove endian::as_byte_slice().
We don't need it now that `ArrayEncoding::as_byte_array()` can handle larger
arrays.
2021-02-05 14:00:41 -08:00
Brian Smith
5a930d247d AEAD: Reorganize imports of aead::block types.
Clarify slightly that `aead::block` is used by AES-GCM only.
2021-02-05 10:48:12 -08:00
Brian Smith
290d8f3883 ChaCha20-Poly1305: Stop using aead::block.
This will let us simplify `aead::block`.

The previous implementation of `poly1305_update_padded_16` was optimized for
the API of the earlier Poly1305 implementation, and was duplicating some
I-U-F logic from the current Poly1305 implementation. Simplify it to avoid
that duplication.
2021-02-05 10:48:12 -08:00
Brian Smith
9ca9d6f586 ChaCha20-Poly1305: Remove Block::from_u64_le.
This will allow us to simplify the implementation of `Block` and eliminate
its use of `unsafe`.
2021-02-05 10:48:12 -08:00
Brian Smith
8b2101c386 Chacha20-Poly1305 for OpenSSH: Remove use of BLOCK_LEN. 2021-02-05 10:48:12 -08:00
Brian Smith
e077aacf41 ChaCha20-Poly1305: Use poly1305::KEY_LEN more. 2021-02-05 10:48:12 -08:00
Brian Smith
cae2378e62 ChaCha: Stop using BLOCK_LEN.
`BLOCK_LEN` really doesn't make sense for ChaCha at all.
2021-02-05 10:48:12 -08:00
Brian Smith
f2488d6118 Agreement: Stop requiring the KDF to return a Result.
Many (most?) KDFs are infallible, so optimize for that case. If the KDF
is fallible then the result will be `Ok(Err(_))` which is messy.

This eliminates the `error_value` parameter.
2021-02-04 19:06:25 -08:00
Brian Smith
d93b954901 Remove definitions of deprecated Error::description()/cause(). 2021-02-04 17:07:41 -08:00
Brian Smith
51f743c44e Remove deprecated APIs. 2021-02-01 16:29:35 -08:00
Brian Smith
27a045642a Dependencies: Require latest libc. 2021-02-01 16:19:08 -08:00
Brian Smith
62d90f7d50 Dependencies: Require latest cc-rs. 2021-02-01 16:19:08 -08:00
Brian Smith
9cc0d45f4d 0.16.20. 2021-02-01 13:14:08 -08:00
Brian Smith
cdd1955d9c
Merge pull request #1179 from briansmith/b/merge-boringssl-integrated-chacha-x86_64
Use integrated ChaCha20-Poly1305 assembly from BoringSSL
2021-01-27 14:45:23 -08:00
Brian Smith
a822206929 Remove currently-unused test vectors for AES-GCM-SIV.
We'll add them back when we add the actual AES-GCM-SIV code.
2021-01-27 12:23:45 -08:00
Brian Smith
af3fa46f29 ChaCha20-Poly1305: Clarify alignment of the output tag in the integrated x86-64 code. 2021-01-26 15:37:56 -08:00