tfm: fix length check in add and mul_d
Check that the overflow digit is going to fit rather than whether we are at limit after adding digit.
This commit is contained in:
parent
93ae372c55
commit
9023c4d65a
@ -163,13 +163,12 @@ int s_fp_add(fp_int *a, fp_int *b, fp_int *c)
|
||||
c->dp[x] = (fp_digit)t;
|
||||
t >>= DIGIT_BIT;
|
||||
}
|
||||
if (t != 0 && x < FP_SIZE) {
|
||||
if (t != 0) {
|
||||
if (x == FP_SIZE)
|
||||
return FP_VAL;
|
||||
c->dp[c->used++] = (fp_digit)t;
|
||||
++x;
|
||||
}
|
||||
if (x == FP_SIZE) {
|
||||
return FP_VAL;
|
||||
}
|
||||
|
||||
c->used = x;
|
||||
|
||||
@ -450,7 +449,9 @@ int fp_mul_d(fp_int *a, fp_digit b, fp_int *c)
|
||||
c->dp[x] = (fp_digit)w;
|
||||
w = w >> DIGIT_BIT;
|
||||
}
|
||||
if (w != 0 && (a->used != FP_SIZE)) {
|
||||
if (w != 0) {
|
||||
if (a->used == FP_SIZE)
|
||||
return FP_VAL;
|
||||
c->dp[c->used++] = (fp_digit) w;
|
||||
++x;
|
||||
}
|
||||
@ -460,8 +461,6 @@ int fp_mul_d(fp_int *a, fp_digit b, fp_int *c)
|
||||
for (; x < oldused && x < FP_SIZE; x++) {
|
||||
c->dp[x] = 0;
|
||||
}
|
||||
if (x == FP_SIZE)
|
||||
return FP_VAL;
|
||||
|
||||
fp_clamp(c);
|
||||
return FP_OKAY;
|
||||
|
Loading…
x
Reference in New Issue
Block a user