257 Commits

Author SHA1 Message Date
Brian Smith
ce0b0a6b9b Undo some unnecessary differences from BoringSSL. 2021-05-12 19:06:16 -07:00
Brian Smith
b86067da4e Address clippy::vec_init_then_push. 2021-05-11 18:34:48 -07:00
Brian Smith
e898b00d53 Build: Derive FFI symbol prefix and FFI lib prefix from Cargo.toml "links".
Now "links" in Cargo.toml is the only thing that needs to be manually modified
when the prefix changes.

build.rs enforces that the package name and version are consistent with the
"links" field.
2021-05-03 16:28:56 -07:00
Brian Smith
badca90d14 Simplify assembly pre-generation mechanism.
Eliminate the extra Cargo.toml that was used just for this feature. It was
too error-prone to keep it in sync with the real Cargo.toml. Having one
Cargo.toml will allow us to reliably use the `CARGO_MANIFEST_LINKS` value
to keep the symbol prefix in sync with the `links` field in Cargo.toml in
the near future.
2021-05-03 13:36:20 -07:00
Brian Smith
36854dee45 build.rs: Tell Cargo about some environment variables that are used.
This doesn't tell Cargo about environment variables used by cc-rs and
the like, but it is a step in the right direction.
2021-05-03 13:36:20 -07:00
Brian Smith
0df1844530 Pass prefix from build.rs to src/prefixed.rs through cargo:rustc-env.
Eliminate one place where the prefix would have to be manually updated.
2021-05-03 12:39:35 -07:00
Brian Smith
7886603cee Use some variant of "ring core" instead of "GFp" as a prefix for everything.
"GFp_" isn't in the code at all anymore.
2021-05-02 22:09:07 -07:00
Brian Smith
384f7d056b Replace manual FFI symbol prefixing with automatic symbol prefixing.
Revert the names used in the BoringSSL C/asm code to the names used in
BoringSSL. This substantially reduces the diff between *ring* and
BoringSSL for these files.

Use a variant of BoringSSL's symbol prefixing machinery to semi-
automatically prefix FFI symbols with the `GFp_` prefix. The names aren't
all exactly the same as before, because previously we *replaced* a
symbol's original prefix with the `GFp_` prefix; now we're prepending
`GFp_`. In the future we'll use a different prefix entirely.

This paves the way for using different prefixes for each version so that
multiple versions of *ring* can be linked into an executable at once.
2021-05-02 22:09:07 -07:00
Brian Smith
0e800b80ce build.rs: Replace manual dirty file checking with cargo:rerun-if-changed.
Simplify build.rs to make it easier to maintain. It seemed like the logic
being removed here wasn't always correct.
2021-04-30 13:37:46 -07:00
Brian Smith
508f5a3293 CI/CD: Use a GitHub-hosted copy of nasm instead of downloading it from nasm.us.
Downloading from nasm.us frequently fails. Avoid depending on it.

Change the expected location of nasm in build.rs.
2021-04-29 15:10:32 -07:00
Brian Smith
f37b8a2f3e Only use assembly code on known-compatible OS+Arch combinations.
Assume by default that an operating system does not have an ABI compatible
with the PerlAsm sources. Add all the operating systems that we've
explicitly added support for to the allowlist. Avoid trying to build or
use the PerlAsm code for those targets.

On top of this, we can build fallback logic for using Rust (or C)
implementations for those targets that aren't compatible with the
assembly.
2021-04-20 15:45:28 -07: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
Vlad Krasnov
34424d829d Enable the integrated assembly x86-64 ChaCha20-Poly1305 implementation from BoringSSL 2021-01-26 10:12:14 -08:00
Brian Smith
b9d7d089d9 Remove #![forbid(warnings)]; reply on Clippy in CI/CD instead.
The newest Rust Nightly is getting stricter about `forbid(warnings)`
which breaks the build.

Use "deny" instead of "forbid". And only deny when running Clippy in
CI/CD, so that when hacking on *ring* we don't have to deal with
warnings right away; we now only have to deal with them when we're ready
to submit a change to be merged.
2020-12-03 17:40:33 -08:00
Brian Smith
15c823a571 Build: Replace use of Yasm with use of Nasm for Windows assembly.
Match BoringSSL. According to the Chromium discussion about nasm, it
is also substantially faster.
2020-11-25 16:32:53 -08:00
Brian Smith
034bfe7143 Avoid opportunistically including system header files.
Don't use the presence of a header to determine whether to include it. Instead,
communicate from build.rs whether system header files should be used.
2020-11-24 09:22:50 -08:00
Brian Smith
7bac725679 Allow cross-compiling to *-linux-musl (except x86_64) w/o a sysroot.
Avoid requiring a sysroot for *-linux-musl targets when using Clang.

Add one AAarch64 and one 32-bit ARM MUSL target to GitHub Actions.

Use Rust 1.48's `-Clink-self-contained=yes` in CI for musl targets.

Support the non-default variants of the *-musl targets.
2020-11-24 09:22:50 -08:00
Brian Smith
f26bae0a6a Add support for aarch64-apple-darwin.
Change the static CPU feature detection logic to assume all aarch64-apple-* targets
have the same capabilities as far as the features we use are concerned.

Use the "ios64" PerlAsm flavour for aarch64-apple-darwin, like OpenSSL upstream does.

Add (build-only) cross-compilation jobs to GitHub Actions.
2020-11-18 00:00:12 -08:00
Brian Smith
f19c4f626b Remove dead crypto/fipsmodule/modes/internal.h. 2020-11-17 23:55:28 -08:00
Brian Smith
bbf935c17b Switch Poly1305 implementation to the BoringSSL implementation.
Previously the OpenSSL implementation was being used. Switch to the BoringSSL
version.

Switching to the BoringSSL implementation will make it easier to refactor the CPU feature
detection, which is important for upcoming ports.

This switch will also implicitly add support for BTI and pointer authentication for
Poly1305.

This is based on BoringSSL 63d06626d3a104868eee622e8e56d9f2dd643366.
2020-11-17 10:19:30 -08:00
Brian Smith
72abf71710 build.rs: Sort header files alphabetically 2020-11-17 10:19:30 -08:00
Brian Smith
6fcbd8905e build.rs: Remove printing of environment variables.
Avoid any potential for leaking sensitive environment variables that would
be irrelevant to the build.
2020-11-12 18:10:20 -08:00
Brian Smith
e19b16e9f8 build.rs: Take clippy's advice about unwrap_or_else. 2020-11-11 16:46:41 -08:00
Brian Smith
d05e9b19dc build.rs: Take clippy's advice about into_iter(). 2020-11-11 16:46:41 -08:00
Brian Smith
b7ff765577 build.rs: Take Clippy's advice about useless conversions. 2020-11-11 16:46:41 -08:00
Brian Smith
2befd3268e build.rs: Take Clippy's advice about removing unneeded &s. 2020-11-11 16:46:41 -08:00
Brian Smith
89bcf8ed30 build.rs: Apply Clippy's advice regarding rustfmt::skip. 2020-11-11 16:46:41 -08:00
Brian Smith
ef7cf3bfc5 Merge BoringSSL 47b1e39: Tidy up third_party/fiat. 2020-06-02 14:02:26 -05:00
Brian Smith
e8bdd5b7b1 Make RSA work for WebAssembly targets when the "wasm32_c" feature is enabled.
Run the RSA and signature tests in WebAssembly.

Implement Elem*Elem multiplication for platforms for which we have no assembly
language implementation of it. Refactor the code to accomodate this.

`elem_reduced` was infallible previously as it always ensured the prerequisites
for the reduction were met. Make this clear in the return type, as a side-effect
of the refactoring needed for implementing the multiplication.

This implementation is far from efficient. More work needs to be done to make it
faster.
2020-05-29 21:07:20 -05:00
Brian Smith
fae863956b bigint: Replace GFp_bn_mul_add_word with GFp_limbs_mul_add_limb.
Replace `GFp_bn_mul_add_word` with a clearer, simpler implementation.
The new `GFp_limbs_mul_add_limb` avoid explicit branches at the C code
level, unlike the code it replaces. (Obviously, even with the new
"branchless" code the compiler might be able to synthesize branches.)
2020-05-29 21:07:20 -05:00
Brian Smith
0e7fdf5e91 Split ASSERT into dev_assert_secret and debug_assert_nonsecret. 2020-05-29 13:23:29 -05:00
Brian Smith
0c5f61b14f Merge BoringSSL c556d87: Add aes_nohw.c fallback AES implementation.
Add the BoringSSL aes_nohw implementation with minimal changes needed to
build. Enable the AES-GCM AEAD tests for wasm32 targets gated on the "wasm_c"
feature.
2020-05-28 10:51:03 -05:00
Brian Smith
742f0ebb11 Implement ASSERT() for wasm32 targets. 2020-05-27 15:09:15 -05:00
Brian Smith
10c4b68e63 Add new "wasm32_c" feature to enable more functionality for wasm32 targets. 2020-05-27 14:59:52 -05:00
Brian Smith
e2543e48d0 AES: Import ARMv7 VPAES implementation from BoringSSL.
Use the VPAES implementation from BoringSSL as of commit c556d87ddfe836294c8e04fc59d0c298951a4cc7,
with the 192-bit key handling and decryption removed.

Merge the VPAES and BSAES cases to VPAES_BSAES. Switch between the VPAES and BSAES implementation
on ARMv7 based on the amount of data being encrypted.

Clarify the dispatching logic in `ring::aead::aes`. In particular, avoid using `_` patterns
when matching on the result of `detect_implementation()`. Also rename Fallback to NOHW.
2020-05-21 18:44:42 -05:00
Brian Smith
192d946b82 Replace gcm_nohw.c with gcm_nohw.rs. 2020-05-06 10:57:33 -05:00
Brian Smith
d3cab43a4a Merge BoringSSL 9855c1c: Add a constant-time fallback GHASH
implementation.

*ring* tries to work without type-punning `memcpy`, so the use of that
in `GFp_gcm_ghash_nohw` was replaced by the use of `u64_from_be_bytes`.
This will (I hope) also help with the eventual support for big-endian
targets. Here's the diff from BoringSSL in that function:

```diff
-void gcm_ghash_nohw(uint64_t Xi[2], const u128 Htable[16], const uint8_t *inp,
-                    size_t len) {
+void GFp_gcm_ghash_nohw(uint64_t Xi[2], const u128 Htable[16], const uint8_t *inp,
+                        size_t len) {
   uint64_t swapped[2];
   swapped[0] = CRYPTO_bswap8(Xi[1]);
   swapped[1] = CRYPTO_bswap8(Xi[0]);

   while (len >= 16) {
-    uint64_t block[2];
-    OPENSSL_memcpy(block, inp, 16);
-    swapped[0] ^= CRYPTO_bswap8(block[1]);
-    swapped[1] ^= CRYPTO_bswap8(block[0]);
+    swapped[0] ^= u64_from_be_bytes(&inp[8]);
+    swapped[1] ^= u64_from_be_bytes(inp);
     gcm_polyval_nohw(swapped, &Htable[0]);
     inp += 16;
     len -= 16;
```

I also had to add a couple of (uint32_t) truncating casts where
BoringSSL expects an implicit truncation to occur, to avoid
`-Werror=conversion`.

During the merge, I found that `GFp_gcm_gmult_clmul` had its
`.cfi_startproc` on the wrong line. I fixed that as part of the merge.

During my review of the BoringSSL changes, I noticed that BoringSSL had
left some of the dead code in ghash-x86_64.pl, which had previously been
removed in *ring*. That removal is being done in BoringSSL in [1].

[1] https://boringssl-review.googlesource.com/c/boringssl/+/41144
2020-05-04 10:54:19 -05:00
Brian Smith
a9705a1ec3 Remove more dead code. 2020-05-01 21:59:37 -05:00
Brian Smith
2f8b7e7568 Remove unused aes128gcmsiv-x86_64.pl. 2020-05-01 10:40:21 -05:00
Brian Smith
92f936bc3b Fix the case where a cargo environment variable is set in build.rs.
Previously, build.rs. would print "cargo:..." to stdout if a variable
`$cargo` was set. This conflicted with Cargo's interpretation of
"cargo:..." to direct it to do things; see [1].

Instead, write to stderr to avoid the conflict. Also change the
formatting of the the environment variable logging so that even if
stderr gets redirected to stdout, such conflicts won't occur.

[1]
https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script
2020-04-28 11:02:54 -05:00
Brian Smith
f15828a7a6 Stop disabling legacy_directory_ownership to fix Rust 1.41 beta channel builds. 2019-12-23 18:41:07 -06:00
Brian Smith
f6c0e0d1ea cargo fmt. 2019-12-23 15:25:24 -06:00
lzutao
c250e3125e Use array::iter
See clippy::into_iter lint and https://github.com/rust-lang/rust/pull/65819
2019-12-23 12:42:49 -06:00
Brian Smith
ffc0f9714e Always use release configuration for C code in published builds. 2019-07-22 12:08:35 -10:00
Brian Smith
8943885e63 build.rs: Remove redundant Target accessors. 2019-07-22 12:06:59 -10:00
Brian Smith
e32e46c922 Stop defining _XOPEN_SOURCE.
It is no longer needed.
2019-07-15 17:30:40 -10:00
Brian Smith
d367526a27 Remove 32-bit x86 SHA-2 assembly code. 2019-07-09 17:25:46 -10:00
Brian Smith
c53955ea8a Initial wasm32-unknown-unknown support. 2019-07-03 12:20:00 -10:00
Brian Smith
9a99848d74 Enable VPAES fallback implementation of AES for Aarch64. 2019-07-02 16:13:32 -10:00
Brian Smith
b1b75a241f Replace GFp_block128_xor with Rust code. 2019-06-14 14:36:59 -10:00