27 Commits

Author SHA1 Message Date
Brian Smith
a804615ed2 Bring back the ring::c internal C types module. 2019-06-14 09:26:38 -10:00
Brian Smith
f0d4d21e85 Use stable rustfmt. 2019-04-10 09:33:38 -10:00
Brian Smith
5dc4dda179 Use libc's types instead of defining our own ring::c.
As far as I know, `libc` is available for every target now. Especially
since the introduction of `bssl::Result` we hardly reference these
types, other than `size_t`. This will help get rid of crypto/crypto.c.
2019-02-05 19:41:48 -10:00
Brian Smith
1194b80cb4 Simplify constant_time_test & remove its stdlib.h dependency.
Remove the trivial stdlib.h dependency from the test. Now the test
works more like other tests, so it's a double win.
2019-02-02 16:08:12 -10:00
Brian Smith
ab0726d0cd Embed test data into test executables.
Embed test data files into test executables so that file I/O isn't
necessary during tests. This allows the tests to run on platforms that
don't have file I/O. It also makes it easier to run the tests on a
separate (virtual) machine from the build machine since the test
automation no longer needs to keep track of the test files.
2019-02-02 13:21:02 -10:00
Brian Smith
df627f6650 Represent detected CPU features as an object. 2019-01-28 14:33:31 -10:00
Brian Smith
7ad3bb79f9 Fix trivial no_std-breaking issues. 2018-12-27 09:14:40 -10:00
Brian Smith
948846061e cargo fix --edition && cargo +nightly fmt. 2018-12-08 21:39:17 -10:00
Brian Smith
3dedc86772 rustfmt +nightly fmt 2018-12-06 10:49:53 -10:00
Brian Smith
e2ba6cb73b Rename ring::init::init_once() to ring::cpu::cache_detected_features().
This is an internal API so this doesn't affect users.
2018-12-01 08:50:39 -10:00
Brian Smith
5ae5f0b1df Reformat everything else except {chacha.rs, poly1305.rs, aead/**}.
chacha.rs, poly1305.rs, and aead/** will be reformatted later.
2018-11-15 16:17:50 -10:00
Brian Smith
26ac52b250 Replace "use {...}" with "use crate::{...}" 2018-11-12 16:51:43 -10:00
Dylan MacKenzie
408089da4d Replace the bssl::map_result function with a new bssl::Result type.
This commit introduces a `#[repr(transparent)]` newtype to represent
the return type of foreign functions which return 1 on success and 0 on
failure. This type is `#[must_use]`, so these return codes must be
checked by the caller.

It also adds `#[must_use]` to foreign functions which use a different
convention to return an error.

I agree to license my contributions to each file under the terms given
at the top of each file I changed.
2018-10-22 11:54:36 -10:00
Brian Smith
2db042dc0d Remove duplicate definition of bssl_test!.
The duplicate was accidentally added in
commit 8b026c93f2c3174ce43d0ef7bd6f618e4f772920.

This was causing an "unused_macro" warning which was causing
beta and nightly builds to fail.
2017-06-07 15:43:42 -10:00
Brian Smith
8b026c93f2 Replace C code for serializing Elems with Rust code. 2017-03-19 11:48:57 -10:00
Mathieu Poumeyrol
e4443e8541 Fix file-based tests on iOS.
I agree to license my contributions to each file under the terms given
at the top of each file I changed.
2017-01-27 15:21:59 -10:00
Brian Smith
77c8c8091c Allow unsafe_code everywhere.
Since the unsafe code is already in `unsafe` blocks, it's redundant to
also require `#[allow(unsafe_code)]`.
2016-09-18 10:48:44 -10:00
Brian Smith
279bd0a2e9 Reformat based on suggestions from rustfmt.
This is a first step toward fully-automated formatting. A custom format
is used, primarily to tell rustfmt to wrap at column 80(-ish) instead of
column 100(-ish), and to use more compact styles.

Many rustfmt suggestions for rewrapping function calls were ignored
because they did not result in the minimum number of lines and/or
because I'm still unsure the best way to format a long chain. Some
suggestions for reformatting macros were ignored because they ruined
the indention. Some other suggestions were ignored because they seemed
like bugs and/or seemed to make things clearly worse.

Further work is planned, in order to make the formatting fully
automatic.
2016-08-28 17:32:32 -10:00
Brian Smith
ac848e11c5 Use ring::error::Unspecified instead of () as the error type.
This may help users of *ring* map *ring* errors into their own error
types.
2016-08-11 09:09:22 -10:00
Brian Smith
bc764776bb Normalize the use of use.
Avoid using `super::` to import top-level submodules of *ring*. Sort
`use` lines alphabetically.
2016-06-14 22:10:50 -10:00
Brian Smith
880b89760d Rework the API and implementation of ECDH.
Instead of having `ring::agreement::EphemeralKeyPair`, we now have
`ring::agreement::EphemeralPrivateKey`, which doesn't store the public
key. This is slightly more memory-efficient because in real-world
protocols we don't need to do anything with the public key except send
it to the peer.

The interface between the Rust and C code was changed with an eye
towards making it easy to add X25519 support. New, simpler, C code
implementing ECDH (for NIST curves) replaces the old code in
crypto/ecdh. In particular, now `EC_KEY` isn't used at all for ECDH.

Finally, add the test vectors for ECDH P-256 and P-384 from the NIST
website. These test vectors don't test the most interesting cases,
however.
2016-05-23 11:20:43 -10:00
Brian Smith
a281f58027 Make SecureRandom sharable between threads; share /dev/urandom handle.
Because `SecureRandom::fill` took `&mut self`, it wasn't possible to
have multiple *usable* references to a `SecureRandom`. Change it so
that `fill` takes non-mutable `&self` so that multi-thread sharing
works.
2016-05-19 16:47:55 -10:00
Brian Smith
c594ac9472 Open /dev/urandom lazily when using /dev/urandom.
This way, `SystemRandom::new()` becomes infallible and non-blocking,
which makes it easier to deal with at app startup time.
2016-05-19 08:59:54 -10:00
Brian Smith
006d93a203 Avoid static initializers, lazily load CPUID info from Rust.
Avoid all the messiness involved with static initializers by doing it
the dumb way. Static initializers are commonly banned from applications
because they add latency to application startup.

This implementation needs to be fine-tuned to account for cases where
we don't need CPUID info (e.g. hard-coded ARM target profiles, NO_ASM
builds, platforms where we have no ASM code).

Also, it is worth investigating whether the Rust implementation of
`call_once` has optimal performance, but for now we punt on that issue.
2016-04-25 17:17:56 -10:00
Brian Smith
c97365e774 Refactor ring::rand.
Stop using `CRYPTO_once`. Instead, require that the CSPRNG is
explicitly threaded through every function that requires a CSPRNG. The
constructor of `SystemRandom` will then initialize the file handle for
/dev/urandom as necessary.
2016-04-25 10:12:18 -10:00
Brian Smith
4165289b36 Use one process for all tests.
Instead of building the test suites inherited from BoringSSL as
seperate executables, link them all together into one executable,
giving all their `main` functions unique names.

This allows all the tests to be run, even on platforms that don't have
traditional process spawning, and avoids the need to keep track of
directory names even on platforms that do support process spawning.

This also makes it easier to integrate new BoringSSL test suites on
Windows, because we don't need to create a new `vcxproj` file for each
one.

Having one test executable may also make code coverage easier.
2016-04-16 18:55:05 -10:00
Brian Smith
99e8438157 Rename ring::ffi to ring::bssl.
Also remove the now-redundant `bssl_` part of the names of the things
inside the module.

This should help avoid confusion in the event we create a ring-ffi
crate.
2016-01-22 16:44:07 -10:00