Improve bn_montgomery_multiply_words().
authorjsing <jsing@openbsd.org>
Tue, 7 Mar 2023 09:42:09 +0000 (09:42 +0000)
committerjsing <jsing@openbsd.org>
Tue, 7 Mar 2023 09:42:09 +0000 (09:42 +0000)
commitef872b157ee1a74b4840ccefe795b824722d9c88
tree4dfd93ff712fc500cbbdff3413a2ff8f6753d2fd
parent0d14184dcde1700fb9a3c644bd11fe5bd5acd347
Improve bn_montgomery_multiply_words().

Rather than calling bn_mul_add_words() twice - once to multiply and once
to reduce - perform the multiplication and reduction in a single pass using
bn_mulw_addw_addw() directly. Also simplify the addition of the resulting
carries, which in turn allows us to avoid zeroing the top half of the
temporary words.

This provides a ~20-25% performance improvement for RSA operations on
aarch64.

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