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:
parent
41ab3d91fd
commit
4d0478a287
@ -762,9 +762,8 @@ void fp_div_2d(fp_int *a, int b, fp_int *c, fp_int *d)
|
||||
return;
|
||||
}
|
||||
|
||||
/* get the remainder */
|
||||
if (d != NULL) {
|
||||
/* NOTE: d must not be the same pointer as a or b */
|
||||
/* get the remainder before a is changed in calculating c */
|
||||
if (a == c && d != NULL) {
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user