forked from wolfSSL/wolfssl
Fix fp_div_2d to return remainder correctly
If a == c are then a and c don't equal d: calculate d before c If a != c then a doesn't change in calculating c: calculate d after c
This commit is contained in:
@@ -762,9 +762,8 @@ void fp_div_2d(fp_int *a, int b, fp_int *c, fp_int *d)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get the remainder */
|
/* get the remainder before a is changed in calculating c */
|
||||||
if (d != NULL) {
|
if (a == c && d != NULL) {
|
||||||
/* NOTE: d must not be the same pointer as a or b */
|
|
||||||
fp_mod_2d (a, b, d);
|
fp_mod_2d (a, b, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -781,6 +780,12 @@ void fp_div_2d(fp_int *a, int b, fp_int *c, fp_int *d)
|
|||||||
if (D != 0) {
|
if (D != 0) {
|
||||||
fp_rshb(c, D);
|
fp_rshb(c, D);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* get the remainder if a is not changed in calculating c */
|
||||||
|
if (a != c && d != NULL) {
|
||||||
|
fp_mod_2d (a, b, d);
|
||||||
|
}
|
||||||
|
|
||||||
fp_clamp (c);
|
fp_clamp (c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user