Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/pk/ecc/ecc_set_key.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,22 @@ int ecc_set_key(const unsigned char *in, unsigned long inlen, int type, ecc_key
a = key->dp.A;
b = key->dp.B;

if (type == PK_PRIVATE && inlen <= (unsigned long)key->dp.size) {
if (type == PK_PRIVATE) {
/* load private key */
if ((err = mp_read_unsigned_bin(key->k, (unsigned char *)in, inlen)) != CRYPT_OK) {
goto error;
}
if (mp_iszero(key->k)) {
if (mp_iszero(key->k) || (mp_cmp(key->k, key->dp.order) != LTC_MP_LT)) {
err = CRYPT_INVALID_PACKET;
goto error;
}
/* compute public key */
if ((err = ltc_mp.ecc_ptmul(key->k, &key->dp.base, &key->pubkey, a, prime, 1)) != CRYPT_OK) { goto error; }
key->type = type;
}
else if (type == PK_PUBLIC) {
/* load public key */
if ((err = ltc_ecc_import_point(in, inlen, prime, a, b, key->pubkey.x, key->pubkey.y)) != CRYPT_OK) { goto error; }
if ((err = mp_set(key->pubkey.z, 1)) != CRYPT_OK) { goto error; }
key->type = type;
}
else {
err = CRYPT_INVALID_PACKET;
Expand All @@ -53,6 +51,7 @@ int ecc_set_key(const unsigned char *in, unsigned long inlen, int type, ecc_key
goto error;
}

key->type = type;
return CRYPT_OK;

error:
Expand Down