Closed bchauvaux closed 7 years ago
I think we can accept this PR, as this makes the behavior of fp_read_unsigned_bin()
consistent whether or not the endianness is known.
...but the description needs to be fixed as there could never be an overflow...
...but the description needs to be fixed as there could never be an overflow...
damn, I was wrong, the last iteration would indeed overflow dp
...
Would this change probably make sense too?
@@ -13,7 +13,7 @@
void fp_mul_2d(fp_int *a, int b, fp_int *c)
{
fp_digit carry, carrytmp, shift;
- int x;
+ int x, limit;
/* copy it */
fp_copy(a, c);
@@ -28,7 +28,8 @@ void fp_mul_2d(fp_int *a, int b, fp_int *c)
if (b != 0) {
carry = 0;
shift = DIGIT_BIT - b;
- for (x = 0; x < c->used; x++) {
+ limit = MIN(c->used, FP_SIZE);
+ for (x = 0; x < limit; x++) {
carrytmp = c->dp[x] >> shift;
c->dp[x] = (c->dp[x] << b) + carry;
carry = carrytmp;
Yes it would but this is one of the many location where ->used is ... "used". There are few other locations where ->used is increased without verification.
This fix addresses the case where the input array is longer than the fp_int capacity and ENDIANNESS is not specified... in which case the existing code would overflow fp_int