Unify BN_rshift design
authorCesar Pereida Garcia <cesar.pereidagarcia@tut.fi>
Wed, 16 Oct 2019 09:10:18 +0000 (12:10 +0300)
committerNicola Tuveri <nic.tuv@gmail.com>
Thu, 17 Oct 2019 11:31:28 +0000 (14:31 +0300)
commitd63332a5f204195ed6922abf62a7ac7d0d0c7fd6
tree9a1e8682cae618209a35994f60482127f68db64b
parentbf585d60fc4de00724a099faa66229ddafbebe00
Unify BN_rshift design

This commit aims at refactoring the `BN_rshift` by making it a wrapper
around `bn_rshift_fixed_top`, in order to match the current design of
`BN_lshift`, as suggested in the discussion at
https://github.com/openssl/openssl/pull/10122#discussion_r332474277 .

As described in the code, by refactoring this function, `BN_rshift`
provides a constant-time behavior for sufficiently[!] zero-padded inputs
under the following assumptions: `|n < BN_BITS2|` or `|n / BN_BITS2|`
being non-secret.

Notice that `BN_rshift` returns a canonical representation of the
BIGNUM, if a `fixed_top` representation is required, the caller should
call `bn_rshift_fixed_top` instead.

(cherry picked from commit 8eba6de59e2b06f23c214344423a5a618d1c9ffd)

Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/10196)
crypto/bn/bn_shift.c