mirror of https://github.com/wolfSSL/wolfssl.git
Fix to improve fp_copy performance without ALT_ECC_SIZE defined. This change is required for async because we can’t memcpy/memset the entire fp_int.
parent
338cc9e873
commit
19ee499c96
|
@ -2348,18 +2348,32 @@ int mp_div_2d(fp_int* a, int b, fp_int* c, fp_int* d)
|
|||
|
||||
void fp_copy(fp_int *a, fp_int *b)
|
||||
{
|
||||
if (a != b && b->size >= a->used) {
|
||||
int x, oldused;
|
||||
oldused = b->used;
|
||||
/* if source and destination are different */
|
||||
if (a != b) {
|
||||
#ifdef ALT_ECC_SIZE
|
||||
/* verify a will fit in b */
|
||||
if (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;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* TODO: Handle error case */
|
||||
}
|
||||
#else
|
||||
/* all dp's are same size, so do straight copy */
|
||||
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;
|
||||
}
|
||||
XMEMCPY(b->dp, a->dp, FP_SIZE * sizeof(fp_digit));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -283,8 +283,8 @@
|
|||
|
||||
/* a FP type */
|
||||
typedef struct fp_int {
|
||||
int used,
|
||||
sign;
|
||||
int used;
|
||||
int sign;
|
||||
int size;
|
||||
fp_digit dp[FP_SIZE];
|
||||
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||
|
|
Loading…
Reference in New Issue