boringssl/crypto/fipsmodule
Brian Smith fee8709f69 Replace |alloca| in |BN_mod_exp_mont_consttime|.
|alloca| is dangerous and poorly specified, according to any
description of |alloca|. It's also hard for some analysis tools to
reason about.

The code here assumed |alloca| is a macro, which isn't a valid
assumption. Depending on what which headers are included and what
toolchain is being used, |alloca| may or may not be defined as a macro,
and this might change over time if/when toolchains are updated. Or, we
might be doing static analysis and/or dynamic analysis with a different
configuration w.r.t. the availability of |alloca| than production
builds use.

Regardless, the |alloca| code path only kicked in when the inputs are
840 bits or smaller. Since the multi-prime RSA support was removed, for
interesting RSA key sizes the input will be at least 1024 bits and this
code path won't be triggered since powerbufLen will be larger than 3072
bytes in those cases. ECC inversion via Fermat's Little Theorem has its
own constant-time exponentiation so there are no cases where smaller
inputs need to be fast.

The RSAZ code avoids the |OPENSSL_malloc| for 2048-bit RSA keys.
Increasingly the RSAZ code won't be used though, since it will be
skipped over on Broadwell+ CPUs. Generalize the RSAZ stack allocation
to work for non-RSAZ code paths. In order to ensure this doesn't cause
too much stack usage on platforms where RSAZ wasn't already being used,
only do so on x86-64, which already has this large stack size
requirement due to RSAZ.

This change will make it easier to refactor |BN_mod_exp_mont_consttime|
to do that more safely and in a way that's more compatible with various
analysis tools.

This is also a step towards eliminating the |uintptr_t|-based alignment
hack.

Since this change increases the number of times |OPENSSL_free| is
skipped, I've added an explicit |OPENSSL_cleanse| to ensure the
zeroization is done. This should be done regardless of the other changes
here.

Change-Id: I8a161ce2720a26127e85fff7513f394883e50b2e
Reviewed-on: https://boringssl-review.googlesource.com/28584
Commit-Queue: David Benjamin <davidben@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
Reviewed-by: David Benjamin <davidben@google.com>
2018-05-21 19:43:05 +00:00
..
aes Rename |asm_AES_*| to |aes_nohw_*|. 2018-05-15 23:02:52 +00:00
bn Replace |alloca| in |BN_mod_exp_mont_consttime|. 2018-05-21 19:43:05 +00:00
cipher Revert "Revert "Revert "Revert "Make x86(-64) use the same aes_hw_* infrastructure as POWER and the ARMs."""" 2018-05-14 22:09:29 +00:00
des Move OPENSSL_FALLTHROUGH to internal headers. 2018-01-29 18:17:57 +00:00
digest Switch OPENSSL_VERSION_NUMBER to 1.1.0. 2017-09-29 04:51:27 +00:00
ec More compatibility stuff. 2018-05-15 23:57:53 +00:00
ecdsa Align ECDSA sign/verify scalar inversions. 2018-04-24 16:00:12 +00:00
hmac Switch OPENSSL_VERSION_NUMBER to 1.1.0. 2017-09-29 04:51:27 +00:00
md4 Run the comment converter on libcrypto. 2017-08-18 21:49:04 +00:00
md5 Run the comment converter on libcrypto. 2017-08-18 21:49:04 +00:00
modes Revert "Revert "Revert "Revert "Make x86(-64) use the same aes_hw_* infrastructure as POWER and the ARMs."""" 2018-05-14 22:09:29 +00:00
policydocs
rand Show an error before we abort the process for an entropy failure. 2018-05-11 22:30:24 +00:00
rsa Spell Falko Strenzke's name correctly. 2018-05-21 18:18:04 +00:00
self_check Split BORINGSSL_self_test into its own file. 2018-01-22 23:06:41 +00:00
sha Add SHA256_TransformBlocks. 2018-04-25 17:51:50 +00:00
tls Fix include path. 2018-05-08 16:26:05 +00:00
bcm.c Move some RSA keygen support code into separate files. 2018-05-08 21:25:46 +00:00
CMakeLists.txt
delocate.h Run the comment converter on libcrypto. 2017-08-18 21:49:04 +00:00
FIPS.md Update link to CMVP certificate. 2018-02-26 22:14:35 +00:00
intcheck1.png
intcheck2.png
intcheck3.png
is_fips.c Add some more compatibility functions. 2018-05-08 20:51:15 +00:00