rsa: fix bn_reduce_once_in_place call for rsaz_mod_exp_avx512_x2
authorXi Ruoyao <xry111@xry111.site>
Wed, 22 Jun 2022 10:07:05 +0000 (18:07 +0800)
committerPauli <pauli@openssl.org>
Thu, 23 Jun 2022 02:51:36 +0000 (12:51 +1000)
bn_reduce_once_in_place expects the number of BN_ULONG, but factor_size
is moduli bit size.

Fixes #18625.

Signed-off-by: Xi Ruoyao <xry111@xry111.site>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/18626)

crypto/bn/rsaz_exp_x2.c

index 6b04486e3f56355711b93861f5ae7f1178c55ee0..f979cebd6fb783474f6c66598fda23d36cfc73f7 100644 (file)
@@ -257,6 +257,9 @@ int ossl_rsaz_mod_exp_avx512_x2(BN_ULONG *res1,
     from_words52(res1, factor_size, rr1_red);
     from_words52(res2, factor_size, rr2_red);
 
+    /* bn_reduce_once_in_place expects number of BN_ULONG, not bit size */
+    factor_size /= sizeof(BN_ULONG) * 8;
+
     bn_reduce_once_in_place(res1, /*carry=*/0, m1, storage, factor_size);
     bn_reduce_once_in_place(res2, /*carry=*/0, m2, storage, factor_size);