Avoid temporary
This commit is contained in:
parent
c17c47715a
commit
27e6485995
@ -20,8 +20,6 @@ int mp_div_2d (mp_int * a, int b, mp_int * c, mp_int * d)
|
|||||||
{
|
{
|
||||||
mp_digit D, r, rr;
|
mp_digit D, r, rr;
|
||||||
int x, res;
|
int x, res;
|
||||||
mp_int t;
|
|
||||||
|
|
||||||
|
|
||||||
/* if the shift count is <= 0 then we do no work */
|
/* if the shift count is <= 0 then we do no work */
|
||||||
if (b <= 0) {
|
if (b <= 0) {
|
||||||
@ -32,24 +30,19 @@ int mp_div_2d (mp_int * a, int b, mp_int * c, mp_int * d)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((res = mp_init (&t)) != MP_OKAY) {
|
/* copy */
|
||||||
|
if ((res = mp_copy (a, c)) != MP_OKAY) {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
/* 'a' should not be used after here - it might be the same as d */
|
||||||
|
|
||||||
/* get the remainder */
|
/* get the remainder */
|
||||||
if (d != NULL) {
|
if (d != NULL) {
|
||||||
if ((res = mp_mod_2d (a, b, &t)) != MP_OKAY) {
|
if ((res = mp_mod_2d (a, b, d)) != MP_OKAY) {
|
||||||
mp_clear (&t);
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* copy */
|
|
||||||
if ((res = mp_copy (a, c)) != MP_OKAY) {
|
|
||||||
mp_clear (&t);
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* shift by as many digits in the bit count */
|
/* shift by as many digits in the bit count */
|
||||||
if (b >= (int)DIGIT_BIT) {
|
if (b >= (int)DIGIT_BIT) {
|
||||||
mp_rshd (c, b / DIGIT_BIT);
|
mp_rshd (c, b / DIGIT_BIT);
|
||||||
@ -84,10 +77,6 @@ int mp_div_2d (mp_int * a, int b, mp_int * c, mp_int * d)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
mp_clamp (c);
|
mp_clamp (c);
|
||||||
if (d != NULL) {
|
|
||||||
mp_exch (&t, d);
|
|
||||||
}
|
|
||||||
mp_clear (&t);
|
|
||||||
return MP_OKAY;
|
return MP_OKAY;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user