boringssl/include/openssl
David Benjamin 38c20fe8d5 Fix threading issues with RSA freeze_private_key.
OpenSSL's RSA API is poorly designed and does not have a single place to
properly initialize the key. See
https://github.com/openssl/openssl/issues/5158.

To workaround this flaw, we must lazily instantiate pre-computed
Montgomery bits with locking. This is a ton of complexity. More
importantly, it makes it very difficult to implement RSA without side
channels. The correct in-memory representation of d, dmp1, and dmq1
depend on n, p, and q, respectively. (Those values have private
magnitudes and must be sized relative to the respective moduli.)

08805fe279 attempted to fix up the various
widths under lock, when we set up BN_MONT_CTX. However, this introduces
threading issues because other threads may access those exposed
components (RSA_get0_* also count as exposed for these purposes because
they are get0 functions), while a private key operation is in progress.

Instead, we do the following:

- There is no actual need to minimize n, p, and q, but we have minimized
  copies in the BN_MONT_CTXs, so use those.

- Store additional copies of d, dmp1, and dmq1, at the cost of more
  memory used. These copies have the correct width and are private,
  unlike d, dmp1, and dmq1 which are sadly exposed. Fix private key
  operations to use them.

- Move the frozen bit out of rsa->flags, as that too was historically
  accessible without locking.

(Serialization still uses the original BIGNUMs, but the RSAPrivateKey
serialization format already inherently leaks the magnitude, so this
doesn't matter.)

Change-Id: Ia3a9b0629f8efef23abb30bfed110d247d1db42f
Reviewed-on: https://boringssl-review.googlesource.com/25824
Commit-Queue: David Benjamin <davidben@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
Reviewed-by: Adam Langley <agl@google.com>
2018-02-09 22:17:11 +00:00
..
aead.h
aes.h
arm_arch.h
asn1_mac.h
asn1.h Add ASN1_INTEGET_set_uint64. 2018-01-02 16:01:31 +00:00
asn1t.h Remove ASN1_template_(i2d,d2i). 2017-09-15 22:53:43 +00:00
base64.h
base.h Move OPENSSL_FALLTHROUGH to internal headers. 2018-01-29 18:17:57 +00:00
bio.h Fix reference to nonexistent function. 2018-01-16 16:23:36 +00:00
blowfish.h
bn.h Add BN_count_low_zero_bits. 2018-02-06 03:10:54 +00:00
buf.h
buffer.h
bytestring.h Add some more utility functions to bytestring. 2018-01-25 23:51:36 +00:00
cast.h
chacha.h
cipher.h
cmac.h
conf.h
cpu.h
crypto.h Extract FIPS KAT tests into a function. 2018-01-22 20:16:38 +00:00
curve25519.h
des.h
dh.h
digest.h Switch OPENSSL_VERSION_NUMBER to 1.1.0. 2017-09-29 04:51:27 +00:00
dsa.h Remove DSA_sign_setup too. 2017-11-22 21:01:11 +00:00
dtls1.h Opaquify DTLS structs. 2015-05-08 18:02:02 +00:00
ec_key.h Tighten EC_KEY's association with its group. 2018-01-03 22:15:11 +00:00
ec.h
ecdh.h
ecdsa.h
engine.h
err.h Bring ERR_ERROR_STRING_BUF_LEN down to 120. 2017-12-14 19:47:23 +00:00
evp.h Documentation typo. 2018-01-25 14:47:06 +00:00
ex_data.h Run comment conversion script on include/ 2017-08-18 23:38:51 +00:00
hkdf.h
hmac.h
is_boringssl.h
lhash_macros.h
lhash.h Unexport more of lhash. 2017-10-25 04:17:18 +00:00
md4.h Run comment conversion script on include/ 2017-08-18 23:38:51 +00:00
md5.h
mem.h
nid.h
obj_mac.h
obj.h Reimplement OBJ_txt2obj and add a lower-level function. 2017-11-27 21:29:00 +00:00
objects.h
opensslconf.h Switch OPENSSL_VERSION_NUMBER to 1.1.0. 2017-09-29 04:51:27 +00:00
opensslv.h
ossl_typ.h
pem.h
pkcs7.h
pkcs8.h Run comment conversion script on include/ 2017-08-18 23:38:51 +00:00
pkcs12.h
poly1305.h
pool.h
rand.h
rc4.h Run comment conversion script on include/ 2017-08-18 23:38:51 +00:00
ripemd.h
rsa.h Fix threading issues with RSA freeze_private_key. 2018-02-09 22:17:11 +00:00
safestack.h
sha.h Run comment conversion script on include/ 2017-08-18 23:38:51 +00:00
span.h
srtp.h
ssl3.h
ssl.h Push an error if custom private keys fail. 2018-02-01 21:43:42 +00:00
stack.h Tidy up some warnings. 2018-01-09 16:01:32 +00:00
thread.h
tls1.h Remove draft22 and experiment2. 2018-01-31 18:07:53 +00:00
type_check.h
x509_vfy.h
x509.h Add X509_NAME_get0_der from OpenSSL 1.1.0. 2017-12-06 17:49:04 +00:00
x509v3.h