forked from wolfSSL/wolfssl
SP math all: sp_exch fixed up
This commit is contained in:
@ -2456,7 +2456,12 @@ int wc_DhGenerateParams(WC_RNG *rng, int modSz, DhKey *dh)
|
|||||||
|
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
/* at this point tmp generates a group of order q mod p */
|
/* at this point tmp generates a group of order q mod p */
|
||||||
|
#ifndef USE_FAST_MATH
|
||||||
|
/* Exchanging is quick when the data pointer can be copied. */
|
||||||
mp_exch(&tmp, &dh->g);
|
mp_exch(&tmp, &dh->g);
|
||||||
|
#else
|
||||||
|
mp_copy(&tmp, &dh->g);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* clear the parameters if there was an error */
|
/* clear the parameters if there was an error */
|
||||||
|
@ -412,7 +412,12 @@ int wc_MakeDsaParameters(WC_RNG *rng, int modulus_size, DsaKey *dsa)
|
|||||||
} while (mp_cmp_d(&tmp, 1) == MP_EQ);
|
} while (mp_cmp_d(&tmp, 1) == MP_EQ);
|
||||||
|
|
||||||
/* at this point tmp generates a group of order q mod p */
|
/* at this point tmp generates a group of order q mod p */
|
||||||
|
#ifndef USE_FAST_MATH
|
||||||
|
/* Exchanging is quick when the data pointer can be copied. */
|
||||||
mp_exch(&tmp, &dsa->g);
|
mp_exch(&tmp, &dsa->g);
|
||||||
|
#else
|
||||||
|
mp_copy(&tmp, &dsa->g);
|
||||||
|
#endif
|
||||||
|
|
||||||
mp_clear(&tmp);
|
mp_clear(&tmp);
|
||||||
mp_clear(&tmp2);
|
mp_clear(&tmp2);
|
||||||
|
@ -2425,12 +2425,19 @@ int sp_exch(sp_int* a, sp_int* b)
|
|||||||
if ((a == NULL) || (b == NULL)) {
|
if ((a == NULL) || (b == NULL)) {
|
||||||
err = MP_VAL;
|
err = MP_VAL;
|
||||||
}
|
}
|
||||||
|
if ((err == MP_OKAY) && ((a->size < b->used) || (b->size < a->used))) {
|
||||||
|
err = MP_VAL;
|
||||||
|
}
|
||||||
|
|
||||||
ALLOC_SP_INT(t, a->used, err, NULL);
|
ALLOC_SP_INT(t, a->used, err, NULL);
|
||||||
if (err == MP_OKAY) {
|
if (err == MP_OKAY) {
|
||||||
|
int asize = a->size;
|
||||||
|
int bsize = b->size;
|
||||||
XMEMCPY(t, a, MP_INT_SIZEOF(a->used));
|
XMEMCPY(t, a, MP_INT_SIZEOF(a->used));
|
||||||
XMEMCPY(a, b, MP_INT_SIZEOF(b->used));
|
XMEMCPY(a, b, MP_INT_SIZEOF(b->used));
|
||||||
XMEMCPY(b, t, MP_INT_SIZEOF(a->used));
|
XMEMCPY(b, t, MP_INT_SIZEOF(t->used));
|
||||||
|
a->size = asize;
|
||||||
|
b->size = bsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
FREE_SP_INT(t, NULL);
|
FREE_SP_INT(t, NULL);
|
||||||
|
Reference in New Issue
Block a user