Fix timing leak in BN_from_montgomery_word.
authorDavid Benjamin <davidben@google.com>
Wed, 31 Jan 2018 19:47:41 +0000 (14:47 -0500)
committerAndy Polyakov <appro@openssl.org>
Thu, 1 Feb 2018 20:53:57 +0000 (21:53 +0100)
commitdb91094a49b370acf03cf6adfcacf2256b8bd153
tree462cd25549a61c11392fd1cc129b13575c11ac50
parent723183b5640e9b047acac189c7c7fb78575522d4
Fix timing leak in BN_from_montgomery_word.

BN_from_montgomery_word doesn't have a constant memory access pattern.
Replace the pointer trick with a constant-time select. There is, of
course, still the bn_correct_top leak pervasive in BIGNUM itself.

See also https://boringssl-review.googlesource.com/22904 from BoringSSL.

Reviewed-by: Andy Polyakov <appro@openssl.org>
Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
(Merged from https://github.com/openssl/openssl/pull/5228)

(cherry picked from commit f345b1f39d9b4e4c9ef07e7522e9b2a870c9ca09)
crypto/bn/bn_mont.c