Fix a bug in BN_mod_sqrt() that can cause it to loop forever.
Approved by: so
Obtained from: OpenSSL Project
Security: CVE-2022-0778
Security: FreeBSD-SA-22:03.openssl
(cherry picked from commit fdc418f15e92732a3551832bcb625ba9b47242df)
(cherry picked from commit c2a7d6e643bbc8801b1b83c9e64d57e726eeed98)