Remove resp variable in BN_div
It's much clearer if we just reference res->d[i] directly. Note that the
removed res->neg clearing is a no-op because bn_set_minimal_width fills
the value in anyway. It was also impossible for res->width to be zero
because of the resizing step (see the bn_resize_words call). Even if it
were possible for it to be zero, that would mean the loop doesn't run,
and the resp pointer was only read outside the loop. So we can treat the
function as if it unconditionally decremented resp.
Bug: 358687140
Change-Id: I5e2d4ca03fd808cacd4f4647843a7894bf7a2f05
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/70176
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Bob Beck <bbe@google.com>
diff --git a/crypto/fipsmodule/bn/div.c b/crypto/fipsmodule/bn/div.c
index 36e9658..d05b747 100644
--- a/crypto/fipsmodule/bn/div.c
+++ b/crypto/fipsmodule/bn/div.c
@@ -271,29 +271,19 @@
goto err;
}
res->width = loop - 1;
- BN_ULONG *resp = &(res->d[loop - 1]);
// space for temp
if (!bn_wexpand(tmp, div_n + 1)) {
goto err;
}
- // if res->width == 0 then clear the neg value otherwise decrease
- // the resp pointer
- if (res->width == 0) {
- res->neg = 0;
- } else {
- resp--;
- }
-
// Compute the quotient with a word-by-word long division. Note that Knuth
// indexes words from most to least significant, so our index is reversed.
// Each loop iteration computes res->d[i] of the quotient and updates snum
// with the running remainder. Before each loop iteration, wnum <= sdiv.
- for (int i = loop - 2; i >= 0; i--, wnump--, resp--) {
+ for (int i = loop - 2; i >= 0; i--, wnump--) {
// TODO(crbug.com/358687140): Remove these running pointers.
wnum.d--;
- assert(resp == res->d + i);
assert(wnum.d == snum->d + i + 1);
assert(wnump == wnum.d + div_n);
@@ -359,7 +349,7 @@
}
}
// store part of the result
- *resp = q;
+ res->d[i] = q;
}
bn_set_minimal_width(snum);