Merge pull request #632 from toddouska/init_multi

fix non ecc_make_key init_mulit potential problems
This commit is contained in:
dgarske 2016-11-14 19:34:14 -08:00 committed by GitHub
commit ee53853d2f
3 changed files with 30 additions and 12 deletions

View File

@ -17521,9 +17521,9 @@ WOLFSSL_ECDSA_SIG *wolfSSL_ECDSA_do_sign(const unsigned char *d, int dlen,
sig = NULL;
}
mp_clear(&sig_r);
mp_clear(&sig_s);
}
mp_clear(&sig_r);
mp_clear(&sig_s);
}
}

View File

@ -3462,9 +3462,12 @@ int wc_ecc_import_point_der(byte* in, word32 inLen, const int curve_idx,
#ifdef HAVE_COMP_KEY
if (err == MP_OKAY && compressed == 1) { /* build y */
mp_int t1, t2, prime, a, b;
int did_init = 0;
if (mp_init_multi(&t1, &t2, &prime, &a, &b, NULL) != MP_OKAY)
err = MEMORY_E;
else
did_init = 1;
/* read in the specs for this curve */
if (err == MP_OKAY)
@ -3505,13 +3508,15 @@ int wc_ecc_import_point_der(byte* in, word32 inLen, const int curve_idx,
}
}
if (did_init) {
#ifndef USE_FAST_MATH
mp_clear(&a);
mp_clear(&b);
mp_clear(&prime);
mp_clear(&t2);
mp_clear(&t1);
mp_clear(&a);
mp_clear(&b);
mp_clear(&prime);
mp_clear(&t2);
mp_clear(&t1);
#endif
}
}
#endif
@ -3891,6 +3896,8 @@ int wc_ecc_check_key(ecc_key* key)
return ECC_INF_E;
err = mp_init_multi(&prime, &a, &order, NULL, NULL, NULL);
if (err != MP_OKAY)
return err;
/* read in the specs for this curve */
if (err == MP_OKAY)
@ -3985,9 +3992,12 @@ int wc_ecc_import_x963_ex(const byte* in, word32 inLen, ecc_key* key,
#ifdef HAVE_COMP_KEY
if (err == MP_OKAY && compressed == 1) { /* build y */
mp_int t1, t2, prime, a, b;
int did_init = 0;
if (mp_init_multi(&t1, &t2, &prime, &a, &b, NULL) != MP_OKAY)
err = MEMORY_E;
else
did_init = 1;
/* read in the specs for this curve */
if (err == MP_OKAY)
@ -4029,13 +4039,15 @@ int wc_ecc_import_x963_ex(const byte* in, word32 inLen, ecc_key* key,
mp_copy(&t2, key->pubkey.y);
}
if (did_init) {
#ifndef USE_FAST_MATH
mp_clear(&a);
mp_clear(&b);
mp_clear(&prime);
mp_clear(&t2);
mp_clear(&t1);
mp_clear(&a);
mp_clear(&b);
mp_clear(&prime);
mp_clear(&t2);
mp_clear(&t1);
#endif
}
}
#endif /* HAVE_COMP_KEY */

View File

@ -1074,6 +1074,12 @@ int mp_invmod_slow (mp_int * a, mp_int * b, mp_int * c)
/* init rest of tmps temps */
if ((res = mp_init_multi(&C, &D, 0, 0, 0, 0)) != MP_OKAY) {
mp_clear(&x);
mp_clear(&y);
mp_clear(&u);
mp_clear(&v);
mp_clear(&A);
mp_clear(&B);
return res;
}