Fix for fp_copy() when used with ALT_ECC_SIZE so any excess digits on the destination that we didn't write to are set to zero.

This commit is contained in:
David Garske
2016-05-04 23:15:38 -07:00
parent 9001036e09
commit 7c3fbd7644

View File

@ -2177,13 +2177,20 @@ int mp_div_2d(fp_int* a, int b, fp_int* c, fp_int* d)
} }
#ifdef ALT_ECC_SIZE #ifdef ALT_ECC_SIZE
void fp_copy(fp_int *a, fp_int* b) void fp_copy(fp_int *a, fp_int *b)
{ {
if (a != b && b->size >= a->used) { if (a != b && b->size >= a->used) {
int x, oldused;
oldused = b->used;
b->used = a->used; b->used = a->used;
b->sign = a->sign; b->sign = a->sign;
XMEMCPY(b->dp, a->dp, a->used * sizeof(fp_digit)); XMEMCPY(b->dp, a->dp, a->used * sizeof(fp_digit));
/* zero any excess digits on the destination that we didn't write to */
for (x = b->used; x < oldused; x++) {
b->dp[x] = 0;
}
} }
} }