diff --git a/wolfcrypt/src/tfm.c b/wolfcrypt/src/tfm.c index 81372ab8c..be71639f6 100644 --- a/wolfcrypt/src/tfm.c +++ b/wolfcrypt/src/tfm.c @@ -2177,13 +2177,20 @@ int mp_div_2d(fp_int* a, int b, fp_int* c, fp_int* d) } #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) { + int x, oldused; + oldused = b->used; b->used = a->used; b->sign = a->sign; 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; + } } }