Rewrite and simplify BN_MONT_CTX_set()
authorjsing <jsing@openbsd.org>
Wed, 22 Feb 2023 05:25:47 +0000 (05:25 +0000)
committerjsing <jsing@openbsd.org>
Wed, 22 Feb 2023 05:25:47 +0000 (05:25 +0000)
commitcef02a03bdfda22e7aa90ce135df6620f17d5fc5
treed7a742b4fdfcc21a837785decf6f9a5d30173173
parent28ee9a64f58a969dfd4b1d2a78cc5905d094ee71
Rewrite and simplify BN_MONT_CTX_set()

OpenSSL commit 4d524040bc8 changed BN_MONT_CTX_set() so that it computed
a 64 bit N^-1 on both BN_BITS2 == 32 and BN_BITS2 == 64 platforms. However,
the way in which this was done was to duplicate half the code and wrap it
in #ifdef.

Rewrite this code to use a single code path on all platforms, with #ifdef
being limited to setting an additional word in the temporary N and storing
the result on BN_BITS2 == 32 platforms. Also remove stack based BIGNUM in
favour of using the already present BN_CTX.

ok tb@
lib/libcrypto/bn/bn_local.h
lib/libcrypto/bn/bn_mont.c