Remove some easy bn_set_minimal_width calls.
Functions that deserialize from bytes and Montgomery multiplication have
no reason to minimize their inputs.
Bug: 232
Change-Id: I121cc9b388033d684057b9df4ad0c08364849f58
Reviewed-on: https://boringssl-review.googlesource.com/25258
Commit-Queue: David Benjamin <davidben@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
Reviewed-by: Adam Langley <agl@google.com>
diff --git a/crypto/fipsmodule/bn/bn.c b/crypto/fipsmodule/bn/bn.c
index b97bad7..0537d56 100644
--- a/crypto/fipsmodule/bn/bn.c
+++ b/crypto/fipsmodule/bn/bn.c
@@ -292,7 +292,6 @@
OPENSSL_memmove(bn->d, words, num * sizeof(BN_ULONG));
// |bn_wexpand| verified that |num| isn't too large.
bn->width = (int)num;
- bn_set_minimal_width(bn);
bn->neg = 0;
return 1;
}
diff --git a/crypto/fipsmodule/bn/bytes.c b/crypto/fipsmodule/bn/bytes.c
index 091def0..63f787e 100644
--- a/crypto/fipsmodule/bn/bytes.c
+++ b/crypto/fipsmodule/bn/bytes.c
@@ -105,9 +105,6 @@
}
}
- // need to call this due to clear byte at top if avoiding having the top bit
- // set (-ve number)
- bn_set_minimal_width(ret);
return ret;
}
@@ -142,8 +139,6 @@
// We only support little-endian platforms, so we can simply memcpy the
// internal representation.
OPENSSL_memcpy(ret->d, in, len);
-
- bn_set_minimal_width(ret);
return ret;
}
diff --git a/crypto/fipsmodule/bn/exponentiation.c b/crypto/fipsmodule/bn/exponentiation.c
index f3cc57f..c85c00b 100644
--- a/crypto/fipsmodule/bn/exponentiation.c
+++ b/crypto/fipsmodule/bn/exponentiation.c
@@ -931,7 +931,6 @@
}
b->width = top;
- bn_set_minimal_width(b);
return 1;
}
@@ -1043,7 +1042,6 @@
RSAZ_1024_mod_exp_avx2(rr->d, a->d, p->d, m->d, mont->RR.d, mont->n0[0]);
rr->width = 16;
rr->neg = 0;
- bn_set_minimal_width(rr);
ret = 1;
goto err;
}
@@ -1218,7 +1216,6 @@
ret = bn_from_montgomery(tmp.d, tmp.d, NULL, np, n0, top);
tmp.width = top;
- bn_set_minimal_width(&tmp);
if (ret) {
if (!BN_copy(rr, &tmp)) {
ret = 0;
diff --git a/crypto/fipsmodule/bn/montgomery.c b/crypto/fipsmodule/bn/montgomery.c
index baa9a0e..11aae53 100644
--- a/crypto/fipsmodule/bn/montgomery.c
+++ b/crypto/fipsmodule/bn/montgomery.c
@@ -312,21 +312,15 @@
return 1;
}
- int max = (2 * n->width); // carry is stored separately
+ int max = 2 * n->width; // carry is stored separately
if (!bn_resize_words(r, max) ||
!bn_wexpand(ret, n->width)) {
return 0;
}
+
ret->width = n->width;
-
- if (!bn_from_montgomery_in_place(ret->d, ret->width, r->d, r->width, mont)) {
- return 0;
- }
ret->neg = 0;
-
- bn_set_minimal_width(r);
- bn_set_minimal_width(ret);
- return 1;
+ return bn_from_montgomery_in_place(ret->d, ret->width, r->d, r->width, mont);
}
int BN_from_montgomery(BIGNUM *r, const BIGNUM *a, const BN_MONT_CTX *mont,
@@ -363,9 +357,6 @@
}
r->width = n->width;
r->neg = 0;
- // The upper words will be zero if the corresponding words of |n| were
- // 0xfff[...], so call |bn_set_minimal_width|.
- bn_set_minimal_width(r);
return 1;
}
@@ -430,8 +421,6 @@
}
r->neg = 0;
r->width = num;
- bn_set_minimal_width(r);
-
return 1;
}
#endif
diff --git a/crypto/fipsmodule/bn/random.c b/crypto/fipsmodule/bn/random.c
index 134afe0..733520d 100644
--- a/crypto/fipsmodule/bn/random.c
+++ b/crypto/fipsmodule/bn/random.c
@@ -286,7 +286,6 @@
r->neg = 0;
r->width = max_exclusive->width;
- bn_set_minimal_width(r);
return 1;
}