Fixed scan-build warning about "len" being used un-initialized in ecc_mul2add. Cleanup of the "mu" variable handling.

This commit is contained in:
David Garske
2016-05-11 09:04:59 -07:00
parent 7c5483ba0b
commit 237193fdee

View File

@ -2019,7 +2019,6 @@ static int ecc_mul2add(ecc_point* A, mp_int* kA,
unsigned char* tB; unsigned char* tB;
int err = MP_OKAY, first, x, y; int err = MP_OKAY, first, x, y;
mp_digit mp; mp_digit mp;
mp_int mu;
/* argchks */ /* argchks */
if (A == NULL || kA == NULL || B == NULL || kB == NULL || C == NULL || if (A == NULL || kA == NULL || B == NULL || kB == NULL || C == NULL ||
@ -2042,18 +2041,15 @@ static int ecc_mul2add(ecc_point* A, mp_int* kA,
XMEMSET(tA, 0, ECC_BUFSIZE); XMEMSET(tA, 0, ECC_BUFSIZE);
XMEMSET(tB, 0, ECC_BUFSIZE); XMEMSET(tB, 0, ECC_BUFSIZE);
XMEMSET(precomp, 0, sizeof(precomp)); XMEMSET(precomp, 0, sizeof(precomp));
err = mp_init(&mu);
if (err == MP_OKAY) { /* get sizes */
/* get sizes */ lenA = mp_unsigned_bin_size(kA);
lenA = mp_unsigned_bin_size(kA); lenB = mp_unsigned_bin_size(kB);
lenB = mp_unsigned_bin_size(kB); len = MAX(lenA, lenB);
len = MAX(lenA, lenB);
/* sanity check */ /* sanity check */
if ((lenA > ECC_BUFSIZE) || (lenB > ECC_BUFSIZE)) { if ((lenA > ECC_BUFSIZE) || (lenB > ECC_BUFSIZE)) {
err = BAD_FUNC_ARG; err = BAD_FUNC_ARG;
}
} }
if (err == MP_OKAY) { if (err == MP_OKAY) {
@ -2083,27 +2079,32 @@ static int ecc_mul2add(ecc_point* A, mp_int* kA,
/* init montgomery reduction */ /* init montgomery reduction */
err = mp_montgomery_setup(modulus, &mp); err = mp_montgomery_setup(modulus, &mp);
if (err == MP_OKAY) if (err == MP_OKAY) {
err = mp_montgomery_calc_normalization(&mu, modulus); mp_int mu;
err = mp_init(&mu);
if (err == MP_OKAY) {
err = mp_montgomery_calc_normalization(&mu, modulus);
if (err == MP_OKAY) if (err == MP_OKAY)
/* copy ones ... */ /* copy ones ... */
err = mp_mulmod(A->x, &mu, modulus, precomp[1]->x); err = mp_mulmod(A->x, &mu, modulus, precomp[1]->x);
if (err == MP_OKAY) if (err == MP_OKAY)
err = mp_mulmod(A->y, &mu, modulus, precomp[1]->y); err = mp_mulmod(A->y, &mu, modulus, precomp[1]->y);
if (err == MP_OKAY) if (err == MP_OKAY)
err = mp_mulmod(A->z, &mu, modulus, precomp[1]->z); err = mp_mulmod(A->z, &mu, modulus, precomp[1]->z);
if (err == MP_OKAY) if (err == MP_OKAY)
err = mp_mulmod(B->x, &mu, modulus, precomp[1<<2]->x); err = mp_mulmod(B->x, &mu, modulus, precomp[1<<2]->x);
if (err == MP_OKAY) if (err == MP_OKAY)
err = mp_mulmod(B->y, &mu, modulus, precomp[1<<2]->y); err = mp_mulmod(B->y, &mu, modulus, precomp[1<<2]->y);
if (err == MP_OKAY) if (err == MP_OKAY)
err = mp_mulmod(B->z, &mu, modulus, precomp[1<<2]->z); err = mp_mulmod(B->z, &mu, modulus, precomp[1<<2]->z);
/* done with mu */ /* done with mu */
mp_clear(&mu); mp_clear(&mu);
}
}
if (err == MP_OKAY) if (err == MP_OKAY)
/* precomp [i,0](A + B) table */ /* precomp [i,0](A + B) table */