5076 Commits

Author SHA1 Message Date
Brian Smith
8dcca73a6f Remove dead code for checking mod-exp modulus is odd.
It cannot even because BN_MONT_CTX_set only allows odd moduli.
2016-12-01 16:36:57 -10:00
Brian Smith
14f2c1648e Move creation of BN_MONT_CTX in RSA verification to Rust. 2016-12-01 16:29:34 -10:00
Brian Smith
5a9498d54f Remove useless new_mont in GFp_BN_mod_exp_mont_consttime.
`GFp_BN_mod_exp_mont_consttime` had previously been changed to require
the caller to supply a non-NULL `mont`, removing the use of `new_mont`.
2016-12-01 16:10:45 -10:00
Brian Smith
551bec6f81 Remove declaration of already-removed GFp_RSA_size. 2016-12-01 16:07:34 -10:00
Brian Smith
46f59b46ba Use is_empty() instead of comparing len() to 0. 2016-12-01 15:18:33 -10:00
Brian Smith
465bff9067 Replace outermost steps of GFp_BN_private_transform with Rust code. 2016-12-01 15:18:32 -10:00
Brian Smith
5502beccd8 Manage RSAKeyPair attributes in Rust, not in the C RSA struct. 2016-12-01 15:18:30 -10:00
Brian Smith
f1ad3efb3c Remove rsa.c, including the checks on dmp1 and dmq1. 2016-12-01 15:18:29 -10:00
Brian Smith
2906a4ce62 Calculate q**2 (mod n) in Rust in RSA signing. 2016-12-01 15:18:29 -10:00
Brian Smith
1af1b46123 Convert iqmp to the Montgomery domain in Rust in RSA signing. 2016-12-01 15:18:26 -10:00
Brian Smith
80e6231cbd Check p * q == n in Rust. 2016-12-01 15:00:02 -10:00
Brian Smith
3b188bbebf Return boolean value instead of pointer from GFp_BN_copy. 2016-11-30 17:57:20 -10:00
Brian Smith
cd221a9270 Construct most RSA private key Montgomery contexts in Rust. 2016-11-30 17:56:47 -10:00
Brian Smith
f048caf212 Check RSA private key parameter bounds in Rust. 2016-11-30 17:56:15 -10:00
Brian Smith
ea77b59dc8 Add extra check for minimum minimum RSA public modulus bit length. 2016-11-30 17:53:18 -10:00
Brian Smith
0c2cffe330 Check RSA public key parameters in Rust. 2016-11-30 17:53:17 -10:00
Brian Smith
20b4d49b98 Work around Rust legacy_directory_ownership warning. 2016-11-28 21:54:17 -10:00
Brian Smith
c964791488 Temporarily avoid conditional compilation in ring::rsa::bigint.
There will be an interim period where most of the code in
`ring::rsa::bigint` is only used during RSA signing, but eventually
a good chunk of it is likely to be used for RSA verification. Let's
deal with the conditional compilation after the dust from that settles,
so that we don't litter this module with dozens of
`#[cfg(feature = "rsa_signing")]`s.
2016-11-28 09:25:21 -10:00
Brian Smith
9b2b75098b Factor out bignum code into ring::rsa::bignum. 2016-11-28 09:25:20 -10:00
Brian Smith
54440e1ffa Avoid redundant calculation of q mod n in the Montgomery domain. 2016-11-28 09:25:19 -10:00
Brian Smith
f72ca3a422 Remove redundant copy of iqmp in RSA private keys. 2016-11-28 09:15:54 -10:00
Brian Smith
dbdbf8a287 Rename PRIVATE_KEY_PUBLIC_MODULUS_{MAX_BITS, MAX_LIMBS}. 2016-11-28 09:13:00 -10:00
Brian Smith
28f7e26612 Allow construction of BitLengths in constant expressions. 2016-11-28 09:12:58 -10:00
Brian Smith
abb3fdfc08 Fix --no-default-features build. 2016-11-23 15:07:17 -10:00
Brian Smith
5ef36f972f Note that test::rand::FixedSliceSequenceRandom isn't thread-safe. 2016-11-23 14:17:32 -10:00
Brian Smith
2539beac02 Simplify implementations of test::rand::*Random. 2016-11-23 14:11:29 -10:00
Brian Smith
2a180893ae Expose deterministic SecureRandoms in ring::test::rand. 2016-11-23 14:06:12 -10:00
Brian Smith
5a96fa8bb3 Factor out RSA padding message digest computation.
Instead of every padding verification implementation and every padding
encoding implementation doing the digesting, have `sign()` and
`verify()` to it themselves.
2016-11-23 11:38:24 -10:00
Brian Smith
a38d9a4ef9 Verify RSA PKCS#1 1.5 signatures by encode-then-check.
When we first implemented PKCS#1 1.5 signature verification we had not
implemented signature generation, so we implemented verification by
parsing the padding. Now that we have generation we can save some code
and arguably make verification safer. Also, this is the way RFC 3447
recommends to do it.
2016-11-23 09:01:36 -10:00
Brian Smith
dcba8a845f Fix definition of c::long for 64-bit non-Windows platforms. 2016-11-23 06:14:31 -10:00
David Judd
f014d94af6 RSA blinding param generation refactoring & performance improvements
Oxidize/restore special-case handling for `0b100...` range bounds,
lost when OpenSSL code was oxidized, and move RSA blinding param
generation out of limb.rs and into its own module.

I agree to license my contributions to each file under the terms
given at the top of each file I changed.

[The code was reordered and slightly tweaked by me before it was
commited. - Brian]
2016-11-22 17:07:12 -10:00
Brian Smith
5c4627a849 Add c::long. 2016-11-22 15:44:06 -10:00
Brian Smith
1f0135d80b Use Rust 1.13 for stable builds on AppVeyor.
Rust 1.13 is the minimum supported version.
2016-11-21 14:41:26 -10:00
Brian Smith
21b0ad94b6 Fix --no-default-features build. 2016-11-18 15:55:20 -10:00
Brian Smith
ba3de7c7d3 Pass lengths as a single full block in ChaCha20-Poly1305 AEAD. 2016-11-16 11:21:34 -10:00
Brian Smith
634caf42fa Use polyfill::u64_from_usize in ring::digest. 2016-11-16 11:21:13 -10:00
Brian Smith
f9de08c6f2 Move the alignment comment in ring::digest to the type. 2016-11-15 15:35:50 -10:00
Brian Smith
14b1c56b55 0.6.0-alpha. 2016-11-15 12:12:06 -10:00
Brian Smith
f0f9b00e1a Expose RSAEncoding in the public API.
Expose `RSAEncoding` in the public API so that users of *ring* can use
it in type signatures. Add an "RSA" prefix to the exported types, since
they will be exported from `ring::signature`. Modify RSA tests to use
only the public API so as to ensure that enough of the API is public.
2016-11-15 12:02:42 -10:00
Brian Smith
5fb1fc8a5e Add and use PUBLIC_KEY_PUBLIC_MODULUS_MAX_LEN.
`PUBLIC_KEY_PUBLIC_MODULUS_MAX_LEN` is measured in bytes, whereas
`PUBLIC_MODULUS_MAX_LEN` was measured in bits.
2016-11-15 10:43:31 -10:00
Brian Smith
be08baa959 Add BitLength type and use it in RSA padding.
Besides improving type safety generally, this fixes a bug in RSA PSS
signing where the wrong value of `mod_bits` was being passed to
`Encoding::encode()`.
2016-11-15 10:43:30 -10:00
Brian Smith
4c9a9c8751 Refactor PSS encoding. 2016-11-15 10:43:29 -10:00
Brian Smith
eeb99a780e Factor out common metric calculations in PSS padding. 2016-11-15 10:43:27 -10:00
Brian Smith
18ff68f90c Factor out shared digesting logic in PSS padding. 2016-11-15 10:41:18 -10:00
Brian Smith
5be8b7f960 Fix (mod_bits - 1) % 8 == 0 case for PSS encoding.
fix encoding
2016-11-15 10:41:16 -10:00
Sam Scott
2e9ef69c23 Implement RSA-PSS signing.
-  Refactor Encoding trait to be randomised.
 -  Add RSA-PSS signing test cases.

I agree to license my contributions to each file under the terms given
at the top of each file I changed.
2016-11-15 10:39:48 -10:00
Brian Smith
8cb3673417 Factor out common logic in internal RSA padding interface.
Factor out the duplicate checks that `m` is fully consumed.
2016-11-15 10:39:34 -10:00
Brian Smith
ba8199b175 Expand RSA PKCS#1 1.5 signature documentation. 2016-11-15 10:39:33 -10:00
Brian Smith
0ce0643f95 Expand documentation for RSA-PSS signatures. 2016-11-15 10:39:32 -10:00
Brian Smith
7520d283eb Fix (mod_bits - 1) % == 0 case in RSA PSS verification.
Output the extra leading zero byte when necessary.

Rename parameters in the `Encoding` interface to match the
specification and update the implementations to use the updated
variable names.
2016-11-15 10:39:32 -10:00