aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrent Cook <busterb@gmail.com>2022-03-12 11:26:23 -0600
committerBrent Cook <busterb@gmail.com>2022-03-12 11:26:23 -0600
commit74e92e5ecf40cb9736e637e6b6dc5fc023bf7204 (patch)
tree7cc9426ba8f8cf72be725ad7acdccc37ac184066
parent2336a535c6fabfa3222d36b15008335cc236d8ac (diff)
downloadportable-74e92e5ecf40cb9736e637e6b6dc5fc023bf7204.tar.gz
portable-74e92e5ecf40cb9736e637e6b6dc5fc023bf7204.tar.bz2
portable-74e92e5ecf40cb9736e637e6b6dc5fc023bf7204.zip
add infinite loop fix in BN_mod_sqrt
-rw-r--r--patches/bn_sqrt.patch38
1 files changed, 38 insertions, 0 deletions
diff --git a/patches/bn_sqrt.patch b/patches/bn_sqrt.patch
new file mode 100644
index 0000000..495de31
--- /dev/null
+++ b/patches/bn_sqrt.patch
@@ -0,0 +1,38 @@
1--- crypto/bn/bn_sqrt.c.orig Fri Feb 18 16:30:39 2022
2+++ crypto/bn/bn_sqrt.c Sat Mar 12 11:23:53 2022
3@@ -351,21 +351,22 @@
4 goto vrfy;
5 }
6
7-
8- /* find smallest i such that b^(2^i) = 1 */
9- i = 1;
10- if (!BN_mod_sqr(t, b, p, ctx))
11- goto end;
12- while (!BN_is_one(t)) {
13- i++;
14- if (i == e) {
15- BNerror(BN_R_NOT_A_SQUARE);
16- goto end;
17+ /* Find the smallest i with 0 < i < e such that b^(2^i) = 1. */
18+ for (i = 1; i < e; i++) {
19+ if (i == 1) {
20+ if (!BN_mod_sqr(t, b, p, ctx))
21+ goto end;
22+ } else {
23+ if (!BN_mod_sqr(t, t, p, ctx))
24+ goto end;
25 }
26- if (!BN_mod_mul(t, t, t, p, ctx))
27- goto end;
28+ if (BN_is_one(t))
29+ break;
30 }
31-
32+ if (i >= e) {
33+ BNerror(BN_R_NOT_A_SQUARE);
34+ goto end;
35+ }
36
37 /* t := y^2^(e - i - 1) */
38 if (!BN_copy(t, y))