allow ECC private key only import

pull/797/head
Chris Conlon 2017-03-15 15:50:54 -06:00
parent 4725a8aea6
commit a13cce9213
2 changed files with 45 additions and 3 deletions

View File

@ -4790,10 +4790,38 @@ int wc_ecc_export_private_raw(ecc_key* key, byte* qx, word32* qxLen,
#endif /* HAVE_ECC_KEY_EXPORT */
#ifdef HAVE_ECC_KEY_IMPORT
int wc_ecc_import_private_key_ex(const byte* priv, word32 privSz, const byte* pub,
word32 pubSz, ecc_key* key, int curve_id)
/* import private key, public part optional if (pub) passed as NULL */
int wc_ecc_import_private_key_ex(const byte* priv, word32 privSz,
const byte* pub, word32 pubSz, ecc_key* key,
int curve_id)
{
int ret = wc_ecc_import_x963_ex(pub, pubSz, key, curve_id);
int ret;
void* heap;
/* public optional, NULL if only importing private */
if (pub != NULL) {
ret = wc_ecc_import_x963_ex(pub, pubSz, key, curve_id);
} else {
if (key == NULL || priv == NULL)
return BAD_FUNC_ARG;
/* init key */
heap = key->heap;
ret = wc_ecc_init_ex(key, NULL, INVALID_DEVID);
key->heap = heap;
key->state = ECC_STATE_NONE;
if (ret != 0)
return ret;
/* set key size */
ret = wc_ecc_set_curve(key, privSz-1, curve_id);
}
if (ret != 0)
return ret;

View File

@ -10261,6 +10261,7 @@ static int ecc_sig_test(WC_RNG* rng, ecc_key* key)
static int ecc_exp_imp_test(ecc_key* key)
{
int ret;
int curve_id;
ecc_key keyImp;
byte priv[32];
word32 privLen;
@ -10302,6 +10303,19 @@ static int ecc_exp_imp_test(ecc_key* key)
goto done;
}
wc_ecc_free(&keyImp);
wc_ecc_init(&keyImp);
curve_id = wc_ecc_get_curve_id(key->idx);
if (curve_id < 0)
return -1074;
/* test import private only */
ret = wc_ecc_import_private_key_ex(priv, privLen, NULL, 0, &keyImp,
curve_id);
if (ret != 0)
return -1075;
done:
wc_ecc_free(&keyImp);
return ret;