Blame SOURCES/openssl-1.0.2k-cve-2022-0778.patch

f388f3
diff -up openssl-1.0.2k/crypto/bn/bn_sqrt.c.cve_2022_0778 openssl-1.0.2k/crypto/bn/bn_sqrt.c
f388f3
--- openssl-1.0.2k/crypto/bn/bn_sqrt.c.cve_2022_0778	2022-03-23 11:23:25.900783626 +0100
f388f3
+++ openssl-1.0.2k/crypto/bn/bn_sqrt.c	2022-03-23 11:27:14.447109005 +0100
f388f3
@@ -64,7 +64,8 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BI
f388f3
 /*
f388f3
  * Returns 'ret' such that ret^2 == a (mod p), using the Tonelli/Shanks
f388f3
  * algorithm (cf. Henri Cohen, "A Course in Algebraic Computational Number
f388f3
- * Theory", algorithm 1.5.1). 'p' must be prime!
f388f3
+ * Theory", algorithm 1.5.1). 'p' must be prime, otherwise an error or
f388f3
+ * an incorrect "result" will be returned.
f388f3
  */
f388f3
 {
f388f3
     BIGNUM *ret = in;
f388f3
@@ -350,18 +351,23 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BI
f388f3
             goto vrfy;
f388f3
         }
f388f3
 
f388f3
-        /* find smallest  i  such that  b^(2^i) = 1 */
f388f3
-        i = 1;
f388f3
-        if (!BN_mod_sqr(t, b, p, ctx))
f388f3
-            goto end;
f388f3
-        while (!BN_is_one(t)) {
f388f3
-            i++;
f388f3
-            if (i == e) {
f388f3
-                BNerr(BN_F_BN_MOD_SQRT, BN_R_NOT_A_SQUARE);
f388f3
-                goto end;
f388f3
+        /* Find the smallest i, 0 < i < e, such that b^(2^i) = 1. */
f388f3
+        for (i = 1; i < e; i++) {
f388f3
+            if (i == 1) {
f388f3
+                if (!BN_mod_sqr(t, b, p, ctx))
f388f3
+                    goto end;
f388f3
+
f388f3
+            } else {
f388f3
+                if (!BN_mod_mul(t, t, t, p, ctx))
f388f3
+                    goto end;
f388f3
             }
f388f3
-            if (!BN_mod_mul(t, t, t, p, ctx))
f388f3
-                goto end;
f388f3
+            if (BN_is_one(t))
f388f3
+                break;
f388f3
+        }
f388f3
+        /* If not found, a is not a square or p is not prime. */
f388f3
+        if (i >= e) {
f388f3
+            BNerr(BN_F_BN_MOD_SQRT, BN_R_NOT_A_SQUARE);
f388f3
+            goto end;
f388f3
         }
f388f3
 
f388f3
         /* t := y^2^(e - i - 1) */