1749 Commits

Author SHA1 Message Date
Brian Smith
4907ff419f Fix organization of |ring::hmac| documentation.
One sentence was in the wrong use case.
2015-10-25 13:28:41 -10:00
Brian Smith
e78a64dc54 Add |ring::hmac::verify_with_own_key|.
|ring::hmac::verify_with_own_key| takes a |SigningKey| instead of a
|VerificationKey|. This is more efficient than constructing a
|VerificationKey| with the same key value and then using `verify`. It
also better matches the mental model for the type of applications that
need such functionality; the need to construct two different keys with
the same value was confusing.

Also, the documentation now more clearly explains how to use the HMAC
API for the three different use cases I could think of today.
2015-10-25 11:42:01 -10:00
Brian Smith
d4c1555d99 Add ring::hmac::SigningKey::generate. 2015-10-25 11:42:00 -10:00
Brian Smith
c6bd7bf0e2 Fix typo in |ring::hmac::sign| documentation. 2015-10-25 11:41:59 -10:00
Brian Smith
a8276b2b9a Use usize instead of u8 for sizes in |ring::aead|.
The use of `u8` comes from when the structure had to be binary
compatible with BoringSSL's C structure. That's no longer the case.
This change allows us to remove the last remaining uses of Rust's
dangerous `as` operator.
2015-10-22 19:58:05 -10:00
Brian Smith
5cb9831f9c Move constant time comparison to a module outside of |ring::ffi|.
Having the constant-time utilities in |ring::ffi| is misleading as
|use ring::ffi| gives the impression that a module was using the FFI
when really it is FFI-free. |ring::hmac| and |ring::pbkdf2| are
examples of that.

At some point, |ring::constant_time| may be added to the public API,
but for now it is private.
2015-10-22 19:58:04 -10:00
Brian Smith
377f611859 Add |ring::c| to define C types, removing libc crate dependency.
The libc crate is full of badness and we need almost none of it. We
don't want to use the C standard library at all from Rust and we
definitely don't want to force users of *ring* to have to link to the
C standard library. (The C code inherited from BoringSSL depends on the
C standard library, but we've removed a lot of those dependencies and
we'll continue to do so.)

Also the definition of |libc::size_t| as an alias for a type that isn't
implicitly convertable to |usize| was forcing us to do a lot of
unnecessary casting, which is inherently danger-prone and thus
dangerous.
2015-10-22 19:58:04 -10:00
Brian Smith
a4dd459e32 Silence older rustc warnings about usize in FFI declarations.
Until Rust 1.4, rustc will warn when `usize` or `isize` is used in an
FFI declaration. This patch silences those warnings so that *ring* can
compile without warnings with rustc 1.3 (the current stable version).
This workaround will be reverted when Rust 1.4 is released.

The code doesn't actually trigger this warning yet, but the next commit
would have made it do so.
2015-10-22 19:58:03 -10:00
Brian Smith
d34b6ea0c0 Use |ring::ffi::map_bssl_result| in |ring::rsa|. 2015-10-22 19:58:03 -10:00
Brian Smith
7b06c73175 Remove trailing whitespace.
Trailing whitespace in the code inherited from BoringSSL was not removed.
2015-10-22 19:57:27 -10:00
Brian Smith
8e089dddc1 Avoid using the heap in |ring::aead|. 2015-10-15 01:26:44 -10:00
Brian Smith
8664b367db Add ChaCha20-Poly1305 to ring::aead. 2015-10-15 01:26:22 -10:00
Brian Smith
2e6b6b31b6 Drop support for arbitrary truncations of AEAD tags. 2015-10-15 01:21:59 -10:00
Brian Smith
0c3ac091eb Add additional tests for |ring::aead::CHACHA20_POLY1305|.
The tests in crypto/cipher/test/chacha20_poly1305_deprecated_tests.txt
were adapted to the RFC 7539 AEAD construction by recalculating the tags.
Also a few additional vectors were added. These vectors were verified
against nettle. See
feb7292bf1.
2015-10-15 00:45:30 -10:00
Brian Smith
8813dea863 Correct types of AEAD methods. 2015-10-12 17:36:04 -10:00
Brian Smith
e825b0b48c Fix documentation for |ring::pbkdf2| and add an example. 2015-10-12 15:58:31 -10:00
Brian Smith
883b49687a Use more idiomatic style for |use ring::| in examples.
In particular, avoid |use ring::*|.
2015-10-12 14:16:37 -10:00
Brian Smith
cb782e0cf3 Refactor PBKDF2 API, now in |ring::pbkdf2|. 2015-10-11 14:51:49 -10:00
Brian Smith
6491d50f38 Add AES-GCM tests from cipher_test.txt to the AEAD test suite. 2015-10-05 10:29:34 -10:00
Brian Smith
a8c80803d3 Require input nonce lengths to equal nominal nonce lengths.
Change the implementation of the C AEAD interface to enforce the
requirement that the nonce length is equal to the result of
|EVP_AEAD_nonce_length| for all AEADs. Previously, the requirement was
not enforced for AES-GCM cipher suites. This in turn enforces that the
input nonces for |open_in_place| and |seal_in_place| are equal to
|ring::aead::Algorithm::nonce_len|.

An issue was filed to remove the underlying code that supports oddball
nonce lengths in the AES-GCM code:
https://github.com/briansmith/ring/issues/22.

In order to move the enforcement of the nonce length to the common code
paths shared by all AEADs, the interface for the AES key wrap AEADs
(currently only available through the C API, not the Rust API) was
changed as described in openssl/include/aead.h.

Some updates were need to keep the C version of the AEAD tests in
crypto/cipher/aead_test.cc working. In particular, the tests were
reorganized so that the tests for |EVP_AEAD_CTX_open| don't depend on
the output of |EVP_AEAD_CTX_seal|, since |EVP_AEAD_CTX_seal| won't
succeed when an invalid nonce is given to it, but we need the test to
keep on going so that we can verify that |EVP_AEAD_CTX_open| also
rejects the invalid nonce. In turn, because we changed the
interpretation of the FAILS attribute in these tests, the old logic
that supported the tests for the removed-in-*ring* stateful AEADs
was removed.
2015-09-24 16:03:27 -10:00
Brian Smith
7766c1cd81 Add key size tests. 2015-09-24 16:00:27 -10:00
Brian Smith
f354618ff8 Add AEAD tests for |AES_128_GCM| and |AES_128_GCM|.
The test data was normalized to meet the *ring* requirement that empty
values be represented as "" instead of nothing.
2015-09-24 09:44:41 -10:00
Brian Smith
6ecc4aeae6 Use ":" to separate test key from test value in |ring::file_test|.
Also, don't allow values to be omitted; instead require empty values to
be given as empty quoted strings.

This also removes some debugging println! calls that were accidentally
left in.
2015-09-24 09:44:41 -10:00
Brian Smith
d2fe198048 Fix trailing whitespace in src/aead.rs. 2015-09-24 09:44:41 -10:00
Brian Smith
992e93bf15 Add the |ring::aead| submodule. 2015-09-23 17:03:14 -07:00
Brian Smith
252ef3144c Improve ECDSA verification LTO dead code elimination. 2015-09-23 17:03:14 -07:00
Brian Smith
8f71107bce Generalize |ring::ecdh| to support both roles of ECDH agreement.
The previous interface supported only the role that receives its peer's
public key point before it has to send its own public key point. The
new interface supports both roles, symmetrically.
2015-09-23 17:03:13 -07:00
Brian Smith
dd9031b021 Add panic documentation to |ring::pbkdf2_hmac::verify|. 2015-09-23 15:42:30 -07:00
Brian Smith
b7f8b1ac55 Implement separate |hkdf::extract| and |hkdf::expand| functions.
Some protocols may benefit slightly performance-wise if it is possible
to use the same intermediate PRK value for multiple operations. See
https://github.com/tlswg/tls13-spec/pull/248.
2015-09-21 03:42:14 -07:00
Brian Smith
39d0557b5a Make reusing a salt for multiple HKDF derivations more efficient. 2015-09-21 03:30:12 -07:00
Brian Smith
7e4a0b1101 Remove MD5.
MD5 is still useful for TLS 1.0/1.1 implementations, but in that case
the TLS implementation can implement it itself.
2015-09-19 20:06:32 -07:00
Brian Smith
c8f72f70d1 Remove the C implementation of HMAC.
This has been superceded by the Rust implementation in |ring::hmac|.

See also the memory safety issues pointed out in
https://boringssl-review.googlesource.com/#/c/5911/.
2015-09-17 23:11:11 -07:00
Brian Smith
7e3a415ec9 Improve the PBKDF2-HMAC interface.
Now PBKDF2-HMAC is available as `ring::pbkdf2_hmac::derive` and
`ring::pbkdf2_hmac::verify`. The former function is the new name for
the old `ring::pbkdf2_hmac` function and the new function is new,
implementing constant-time comparison of the expected and computed
derived keys.
2015-09-17 21:49:05 -07:00
Brian Smith
65663f9a61 Rewrite digest tests using the file_test framework. 2015-09-17 13:49:33 -07:00
Brian Smith
53aafe15a9 Add ephemeral ECDH support to |ring::ecc|.
The C function |ECDH_ephemeral| was accidentally included in commit
1dd99fe (Split |ring::signature| into |ring:ecc| and |ring::rsa|) but
it was really supposed to be part of this commit.
2015-09-16 22:35:22 -07:00
Brian Smith
bf016c3c34 Add PBKDF2 as |rust::pbkdf2_hmac|. 2015-09-16 16:42:51 -07:00
Brian Smith
37317a2a00 Add HKDF as |ring::hkdf|. 2015-09-16 16:41:41 -07:00
Brian Smith
12596a32f9 Remove |ring::hmac::VerificationContext|.
Ilari Liusvaara pointed out that an Init-Update-Finalize interface for
HMAC verification is generally unneeded and encourages the bad practice
of processing streams of data before the HMAC over that data has been
verified.

This commit also improves some of the documentation.
2015-09-16 16:23:22 -07:00
Brian Smith
f3098d3e6b Rename |test| submodules to |tests|.
The new name is the idiomatic one for Rust code.
2015-09-16 15:33:04 -07:00
Brian Smith
3bdaaf5879 Add HMAC in |ring::hmac|.
This HMAC implementation is built on top of |ring::digest| in Rust
instead of using the FFI to call into the C implementation of HMAC.

This also adds constant-time byte slice comparison to |ring::ffi|,
which is used for HMAC verification.
2015-09-15 17:25:10 -07:00
Brian Smith
81e87baa58 Add Rust implementation of BoringSSL's crypto/test/file_test.cc.
This is just the subset of the BoringSSL version's functionality thatjust
is enough to get the HMAC tests working.
2015-09-15 16:59:40 -07:00
Brian Smith
32480fc591 Refactor |ring::digest| to have a more usable API.
The previous interface suffered from multiple problems that made it
annoying to use in contexts that needed to digest data with a digest
function that wasn't known statically at build time. The old interface
was also hard to avoid uses of the heap when digest algorithm agility
is required. It was also annoying that one had to import the |Digest|
trait even in code that only wanted to use a statically-chosen digest
function, because calling a method declared in a trait requires that.

The updates to examples/checkdigest.rs demonstrate the improved
usability.

This change also moves to a new style where it is assumed that users of
*ring* will |use ring::*| and then access submodules using
partially-qualified syntax. For example, instead of naming the digest
context type |DigestContext|, it is named just |Context| with the
expectation that code will refer to it as |digest::Context|. Future
sub-modules will follow this convention so that, for example, the HMAC
context type will be |ring::hmac::Context|.

The new interface also helps establish the convention that algorithms
exposed as |pub static| values of some type, usually a struct type.
This convention help enable the linker to discard the code for unused
algorithms.

The fact that |SignatureDigestAlgorithm| is no longer needed in this
new design is a good indication that we're on a better track.
2015-09-15 16:58:53 -07:00
Brian Smith
1dd99fe88b Split |ring::signature| into |ring:ecc| and |ring::rsa|. 2015-09-15 16:58:52 -07:00
Brian Smith
0f55730d18 Replace |append_secure_random| with |fill_secure_random|.
We need a PRNG function that operates on slices that aren't |Vec|, but
it isn't clear we need a function that appends to a |Vec|. The new
function is not re-exported from the main |ring| module.
2015-09-15 16:58:51 -07:00
Brian Smith
521178b8e7 add ffi.rs 2015-09-15 14:56:38 -07:00
Brian Smith
69a3fe3131 Fix digest doc tests. 2015-08-29 23:25:23 -07:00
Brian Smith
3ad953fc00 Rust: Add append_secure_random. 2015-08-26 21:18:43 -07:00
Brian Smith
d6411bde92 Rust: Add RSA and ECDSA signature verification API. 2015-08-26 21:18:39 -07:00
Brian Smith
20b97a69a9 Rust: Add API for calculating digests (SHA-256, etc.). 2015-08-26 21:18:37 -07:00