CVE-2022-0778.patch 1.33 KB
Newer Older
J0WI's avatar
J0WI committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
From 3a4ec28b238edf9d85759b7a3d78fd85e4d5aaef Mon Sep 17 00:00:00 2001
From: Brent Cook <busterb@gmail.com>
Date: Sat, 12 Mar 2022 11:26:23 -0600
Subject: [PATCH] add infinite loop fix in BN_mod_sqrt

---
 patches/bn_sqrt.patch | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 patches/bn_sqrt.patch

diff --git a/patches/bn_sqrt.patch b/patches/bn_sqrt.patch
new file mode 100644
index 000000000..495de3120
--- /dev/null
+++ b/patches/bn_sqrt.patch
@@ -0,0 +1,38 @@
+--- crypto/bn/bn_sqrt.c.orig	Fri Feb 18 16:30:39 2022
++++ crypto/bn/bn_sqrt.c	Sat Mar 12 11:23:53 2022
+@@ -351,21 +351,22 @@
+ 			goto vrfy;
+ 		}
+ 
+-
+-		/* find smallest  i  such that  b^(2^i) = 1 */
+-		i = 1;
+-		if (!BN_mod_sqr(t, b, p, ctx))
+-			goto end;
+-		while (!BN_is_one(t)) {
+-			i++;
+-			if (i == e) {
+-				BNerror(BN_R_NOT_A_SQUARE);
+-				goto end;
++		/* Find the smallest i with 0 < i < e such that b^(2^i) = 1. */
++		for (i = 1; i < e; i++) {
++			if (i == 1) {
++				if (!BN_mod_sqr(t, b, p, ctx))
++					goto end;
++			} else {
++				if (!BN_mod_sqr(t, t, p, ctx))
++					goto end;
+ 			}
+-			if (!BN_mod_mul(t, t, t, p, ctx))
+-				goto end;
++			if (BN_is_one(t))
++				break;
+ 		}
+-
++		if (i >= e) {
++			BNerror(BN_R_NOT_A_SQUARE);
++			goto end;
++		}
+ 
+ 		/* t := y^2^(e - i - 1) */
+ 		if (!BN_copy(t, y))