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