140 Commits

Author SHA1 Message Date
Brian Smith
b713290336 Remove reference counting code.
Rust programs can use Rust's `Rc` or other mechanisms for reference
counting and non-Rust code can do similar.
2016-02-14 16:05:00 -10:00
Brian Smith
8435da899b Remove unused parameters in tests. 2016-02-14 13:55:47 -10:00
Pyfisch
92806f9178 Remove rsa_get_public_exp in blinding.c.
Instead, just fail if `rsa->e` is `NULL`.

I agree to license my contributions to each file under the
same terms given at the top of each file I changed.
2016-02-13 15:50:24 -10:00
Brian Smith
7cfe90fc2b Don't cast |OPENSSL_malloc| result.
C has implicit conversion of |void *| to other pointer types so these
casts are unnecessary. Clean them up to make the code easier to read
and to make it easier to find dangerous casts.
2016-02-09 18:56:58 -10:00
Brian Smith
b8c896b6ef Remove casts from |size_t| to |unsigned| in RSA padding code. 2016-02-09 18:49:38 -10:00
Brian Smith
d617f2ff61 Merge BoringSSL 642b0b8: Remove unused bits of RSA blinding code.
This was done earlier in *ring*, but the earlier *ring* change missed
the removal of the declarations in the header file.
2016-02-09 18:37:11 -10:00
Brian Smith
642b0b825e Remove unused bits of RSA blinding code.
The |_ex| versions of these functions are unnecessary because when they
are used, they are always passed |NULL| for |r|, which is what the
non-|_ex| versions do. Just use the non-|_ex| versions instead and
remove the |_ex| versions.

Also, drop the unused flags mechanism.

Change-Id: Ida4cb5a2d4c89d9cd318e06f71867aea98408d0d
Reviewed-on: https://boringssl-review.googlesource.com/7110
Reviewed-by: David Benjamin <davidben@google.com>
2016-02-09 16:45:13 +00:00
Brian Smith
b76f52c03a Remove OPENSSL_cleanse, BN_clear_free, etc.
Ultimately, it's better to invest effort in alternative forms of
protection of key material.

Calling `OPENSSL_cleanse` with a NULL pointer is not safe, but
`OPENSSL_cleanse` is often called in cleanup code, especially error-
handling code, where it is difficult to keep track of the NULLness of
things. The likelihood of getting this wrong is compounded by the fact
that, in OpenSSL upstream, calling `OPENSSL_cleanse(NULL, x)` for any
`x` is safe (a no-op). BoringSSL upstream doesn't want to change its
`OPENSSL_cleanse` to work like OpenSSL's. We don't want to worry about
the issue.

Apart from that, by inspection, it is clear that there are many places
in the code that don't call `OPENSSL_clease` where they "should". It
would be difficult to find all the places where a call to
`OPENSSL_clease` "should" be inserted. It is unlikely we'll ever get it
right. Actually, it's basically impossible to get it right using this
coding pattern. See
http://www.daemonology.net/blog/2014-09-06-zeroing-buffers-is-insufficient.html
and https://github.com/bitcoin/secp256k1/issues/185.

Besides all that, the zeroization isn't free. Especially in the case of
non-MSVC platforms, it either interferes with the optimizer or it
doesn't work. More importantly, thinking about how to make this
approach work wastes a lot of time that could be spent actually
improving the fundementals of the security of the code.
2016-02-04 22:24:38 -10:00
Brian Smith
c5b099618f Merge BoringSSL acb2451: Rename the BIGNUM ASN.1 functions.
The changes to the tests were mostly undone since *ring* doesn't have
the "buggy" variants of the functions. BN_bn2cbb_padded was restored so
that the *ring* code would be easier to compare to the BoringSSL code.
2016-01-31 20:43:10 -10:00
Brian Smith
bbfe2e7d6b Take BoringSSL 34749f4: Remove unnecessary assignment of |e| in |rsa_setup_blinding|. 2016-01-27 21:45:07 -10:00
Brian Smith
1eb4fbe21b Merge BoringSSL 625475f: Fix bits vs. bytes confusion in RSA encryption. 2016-01-27 19:14:40 -10:00
David Benjamin
acb2451807 Rename the BIGNUM ASN.1 functions.
There's many ways to serialize a BIGNUM, so not including asn1 in the name is
confusing (and collides with BN_bn2cbb_padded). Since BN_asn12bn looks
ridiculous, match the parse/marshal naming scheme of other modules instead.

Change-Id: I53d22ae0537a98e223ed943e943c48cb0743cf51
Reviewed-on: https://boringssl-review.googlesource.com/6822
Reviewed-by: Adam Langley <alangley@gmail.com>
2016-01-27 22:37:44 +00:00
Brian Smith
927f1fed28 Remove unused bits of RSA blinding code. 2016-01-24 23:41:56 -10:00
Brian Smith
34749f47da Remove unnecessary assignment of |e| in |rsa_setup_blinding|.
After its initial assignment, |e| is immediately reassigned another
value and so the initial assignment from |BN_CTX_get| is useless. If
that were not the case, then the |BN_free(e)| at the end of the
function would be very bad.

Change-Id: Id63a172073501c8ac157db9188a22f55ee36b205
Reviewed-on: https://boringssl-review.googlesource.com/6951
Reviewed-by: David Benjamin <davidben@google.com>
2016-01-23 17:08:23 +00:00
Brian Smith
e8c72d9975 Suppress -Wcast-qual warning in |STATIC_BIGNUM|. 2016-01-19 11:57:04 -10:00
Brian Smith
803346d2ae Replace |RSA_generate_key_ex| with |RSA_generate|.
|RSA_generate| creates the |RSA| struct for the key, instead of taking
it as an input like |RSA_generate_key_ex| does. This is a step towards
making |RSA| instances immutable.

Also, its exponent parameter |e| is a |uint32_t| instead of a |BIGNUM|
in order to help avoid the generation of keys that won't be accepted
by the Windows CryptoAPI.
2016-01-13 20:10:45 -10:00
Brian Smith
995875de60 Remove |RSA_new_engine| and |ENGINE|.
|RSA_new_engine| only supported the case where |ENGINE| is NULL, for
backward compatibility, but now *ring* is not doing backward
compatibility in that way.
2016-01-13 20:10:44 -10:00
Brian Smith
625475f3e3 Fix bits vs. bytes confusion in RSA encryption.
rsa_default_encrypt allowed an RSA modulus 8 times larger than the
intended maximum size due to bits vs. bytes confusion.

Further, as |rsa_default_encrypt| got this wrong while
|rsa_default_verify_raw| got it right, factor out the duplicated logic
so that such inconsistencies are less likely to occur.

BUG=576856

Change-Id: Ic842fadcbb3b140d2ba4295793457af2b62d9444
Reviewed-on: https://boringssl-review.googlesource.com/6900
Reviewed-by: David Benjamin <davidben@chromium.org>
Reviewed-by: Adam Langley <agl@google.com>
2016-01-13 22:28:54 +00:00
Brian Smith
ea761faa23 Stop exporting |RSA_verify| and |RSA_verify_raw|.
This is a step towards removing the use of the |RSA| struct during
signature verification.
2016-01-12 17:06:45 -10:00
Brian Smith
4d38252481 Remove |RSAPublicKey_dup| (dead code). 2016-01-12 14:10:20 -10:00
Brian Smith
afa8ac1398 Check |BN_CTX_get| failure earlier in |RSA_verify_raw|. 2016-01-12 14:10:20 -10:00
Brian Smith
38aa1674a0 Always use |BN_mod_exp_mont| for RSA blinding, not |BN_mod_exp|.
|BN_mod_exp| will always choose its |BN_mod_exp_mont| code path anyway.
This will allow us to move |BN_mod_exp| out of libcrypto.

Don't use CACHE_PUBLIC flag to determine how to do blinding.

fix.
2016-01-12 09:55:12 -10:00
Brian Smith
676e612b3d Merge BoringSSL 3f5b43d: Simplify RSA key exchange padding check. 2016-01-05 13:32:17 -10:00
Brian Smith
178f7e01b3 Cherry-pick relevant portions of old commit BoringSSL 231cb82.
Originally *ring* did not merge any portion of BoringSSL 231cb82 as
*ring* does not need to support badly-formed Estonian smart card public
keys. However, instead of ignoring the entire commit, we should take
the parts that verify that |BN_cbs2unsigned| rejects them. Also, it is
a good idea to take the whitespace changes in bn_asn1.c so that it is
easier to compare *ring* and BoringSSL.
2016-01-05 13:17:08 -10:00
Brian Smith
4a74905222 Merge BoringSSL 3ef6085: Refuse to parse RSA pubkeys with invalid exponents. 2016-01-05 13:09:25 -10:00
Brian Smith
150b4c85f9 Merge BoringSSL 1634a33: Convert rsa/padding.c to constant-time helpers.
Only the PKCS#1 1.5 changes were merged since the OAEP/PSS code was
already removed in *ring*.
2016-01-04 17:10:42 -10:00
David Benjamin
3f5b43df07 Simplify RSA key exchange padding check.
This check was fixed a while ago, but it could have been much simpler.

In the RSA key exchange, the expected size of the output is known, making the
padding check much simpler. There isn't any use in exporting the more general
RSA_message_index_PKCS1_type_2. (Without knowing the expected size, any
integrity check or swap to randomness or other mitigation is basically doomed
to fail.)

Verified with the valgrind uninitialized memory trick that we're still
constant-time.

Also update rsa.h to recommend against using the PKCS#1 v1.5 schemes.

Thanks to Ryan Sleevi for the suggestion.

Change-Id: I4328076b1d2e5e06617dd8907cdaa702635c2651
Reviewed-on: https://boringssl-review.googlesource.com/6613
Reviewed-by: Adam Langley <agl@google.com>
2015-12-22 00:10:14 +00:00
Luke Granger-Brown
3ef608594d Refuse to parse RSA pubkeys with invalid exponents.
We should reject RSA public keys with exponents of less than 3.

This change also rejects even exponents, although the usefulness
of such a public key is somewhat questionable.

BUG=chromium:541257

Change-Id: I1499e9762ba40a7cf69155d21d55bc210cd6d273
Reviewed-on: https://boringssl-review.googlesource.com/6710
Reviewed-by: Adam Langley <agl@google.com>
2015-12-21 23:49:02 +00:00
Brian Smith
c350197bdd Remove openssl/obj.h and openssl/objects.h.
These headers are no longer needed as we only need obj_mac.h.
2015-12-15 14:31:06 -10:00
David Benjamin
8a58933db0 Remove the CRYPTO_EX_new callback.
This callback is never used. The one caller I've ever seen is in Android
code which isn't built with BoringSSL and it was a no-op.

It also doesn't actually make much sense. A callback cannot reasonably
assume that it sees every, say, SSL_CTX created because the index may be
registered after the first SSL_CTX is created. Nor is there any point in
an EX_DATA consumer in one file knowing about an SSL_CTX created in
completely unrelated code.

Replace all the pointers with a typedef to int*. This will ensure code
which passes NULL or 0 continues to compile while breaking code which
passes an actual function.

This simplifies some object creation functions which now needn't worry
about CRYPTO_new_ex_data failing. (Also avoids bouncing on the lock, but
it's taking a read lock, so this doesn't really matter.)

BUG=391192

Change-Id: I02893883c6fa8693682075b7b130aa538a0a1437
Reviewed-on: https://boringssl-review.googlesource.com/6625
Reviewed-by: Adam Langley <agl@google.com>
2015-12-15 21:29:46 +00:00
David Benjamin
756ad17337 Initialize |one_index| in OAEP padding check.
This was a mistake in https://boringssl-review.googlesource.com/6611.

Change-Id: Ifb5c52cc7571b6f1ada4af9b46eab1f9b080b4f6
Reviewed-on: https://boringssl-review.googlesource.com/6730
Reviewed-by: Adam Langley <agl@google.com>
2015-12-15 19:46:39 +00:00
David Benjamin
1634a33495 Convert rsa/padding.c to constant-time helpers.
Remove the custom copy of those helpers.

Change-Id: I810c3ae8dbf7bc0654d3e9fb9900c425d36f64aa
Reviewed-on: https://boringssl-review.googlesource.com/6611
Reviewed-by: Adam Langley <agl@google.com>
2015-12-15 19:39:37 +00:00
Brian Smith
c483bc966d Refactor RSA signature verification interface.
* Rename |ring::rsa| to |ring::signature| in preparation for moving all
signature algorithms to the module.

* Make min/max key size explicit in the interface, similar to how ECDSA
fixes key sizes.

* Use the Input/Reader interface.
2015-12-10 16:13:33 -10:00
Brian Smith
bfff5d911d Take BoringSSL 60a45aa: Remove reference to removed |RSA_FLAG_NO_CONSTTIME| flag. 2015-12-05 15:25:05 -10:00
Brian Smith
0dc1bbf789 Merge BoringSSL e82e6f6: Constify more BN_MONT_CTX parameters. 2015-11-29 13:36:16 -10:00
Brian Smith
1756257355 Merge BoringSSL 8fb0f52: Free BN_MONT_CTX in generic code.
*ring* was already doing this. This merge just rearranges *ring* to use
the same naming and same code as BoringSSL.
2015-11-29 13:18:51 -10:00
Brian Smith
60a45aa7cc Remove reference to removed |RSA_FLAG_NO_CONSTTIME| flag.
Change-Id: I0bfdccf009772d4ff8cd419758ab5bfae95f5cc5
Reviewed-on: https://boringssl-review.googlesource.com/6530
Reviewed-by: Adam Langley <agl@google.com>
2015-11-20 19:59:29 +00:00
Brian Smith
8cb362f994 Implement digest I-U-F framework in Rust.
The crypto-bench results did not change in any significant way;
the difference is consistently mixed +/-. However, the code size
difference should be significant. Previously, every digest algorithm
implemented its own |init|, |update|, and |finish| functions. Now,
all of them share one implementation of each.
2015-11-08 16:48:52 -10:00
David Benjamin
e82e6f6696 Constify more BN_MONT_CTX parameters.
Most functions can take this in as const. Note this changes an
RSA_METHOD hook, though one I would not expect anyone to override.

Change-Id: Ib70ae65e5876b01169bdc594e465e3e3c4319a8b
Reviewed-on: https://boringssl-review.googlesource.com/6419
Reviewed-by: Adam Langley <agl@google.com>
2015-11-06 20:04:36 +00:00
David Benjamin
8fb0f525e1 Free BN_MONT_CTX in generic code.
Although those are only created by code owned by RSA_METHOD, custom RSA_METHODs
shouldn't be allowed to squat our internal fields and then change how you free
things.

Remove 'method' from their names now that they're not method-specific.

Change-Id: I9494ef9a7754ad59ac9fba7fd463b3336d826e0b
Reviewed-on: https://boringssl-review.googlesource.com/6423
Reviewed-by: Adam Langley <agl@google.com>
2015-11-03 23:39:41 +00:00
David Benjamin
bb875350b3 Fix ASan bot.
This restores the original semantics of the finished hook.

Change-Id: I70da393c7e66fb6e3be1e2511e08b34bb54fc0b4
Reviewed-on: https://boringssl-review.googlesource.com/6422
Reviewed-by: Adam Langley <agl@google.com>
2015-11-03 23:28:56 +00:00
David Benjamin
d93831d71a Make it possible for a static linker to discard unused RSA functions.
Having a single RSA_METHOD means they all get pulled in. Notably, RSA key
generation pulls in the primality-checking code.

Change-Id: Iece480113754da090ddf87b64d8769f01e05d26c
Reviewed-on: https://boringssl-review.googlesource.com/6389
Reviewed-by: Adam Langley <agl@google.com>
2015-11-03 23:02:38 +00:00
Brian Smith
17f6149c64 Remove SHA-224. 2015-10-31 22:30:01 -10:00
Brian Smith
b1dd1f596d Remove include/openssl/digest.h. 2015-10-31 22:28:48 -10:00
Brian Smith
4f3535ed43 Remove OAEP and PSS support from crypto/rsa.
This removes the last non-test dependency on |EVP_Digest*|.
2015-10-31 16:10:11 -10:00
Brian Smith
96b9f3b68c Switch rsa_test.cc to use the new RSA encrypt/decrypt API.
Change-Id: I799e289a402612446e08f64f59e0243f164cf695
Reviewed-on: https://boringssl-review.googlesource.com/6372
Reviewed-by: David Benjamin <davidben@chromium.org>
Reviewed-by: Adam Langley <agl@google.com>
2015-10-28 23:36:44 +00:00
Brian Smith
af68f3653f Merge BoringSSL ccf2517: Only emit RSA_R_BAD_VERSION on bad RSAPrivateKey versions. 2015-10-27 17:26:25 -10:00
Adam Langley
96c2a28171 Fix all sign/unsigned warnings with Clang and GCC.
Change-Id: If2a83698236f7b0dcd46701ccd257a85463d6ce5
Reviewed-on: https://boringssl-review.googlesource.com/4992
Reviewed-by: Adam Langley <agl@google.com>
2015-10-27 22:48:00 +00:00
Brian Smith
58600f15b4 Remove deprecated, duplicative, RSA API functions.
See also 978f16e.
2015-10-26 21:21:26 -10:00
Brian Smith
f44cd25afc Merge BoringSSL 978f16e: size_t RSA functions. 2015-10-26 20:55:35 -10:00