Skip to content

Commit 70d800f

Browse files
committed
fix ecc_set_key - no check of private key input buffer size
1 parent 5043967 commit 70d800f

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/pk/ecc/ecc_set_key.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,22 @@ int ecc_set_key(const unsigned char *in, unsigned long inlen, int type, ecc_key
2424
a = key->dp.A;
2525
b = key->dp.B;
2626

27-
if (type == PK_PRIVATE && inlen <= (unsigned long)key->dp.size) {
27+
if (type == PK_PRIVATE) {
2828
/* load private key */
2929
if ((err = mp_read_unsigned_bin(key->k, (unsigned char *)in, inlen)) != CRYPT_OK) {
3030
goto error;
3131
}
32-
if (mp_iszero(key->k)) {
32+
if (mp_iszero(key->k) || (mp_cmp(key->k, key->dp.order) != LTC_MP_LT)) {
3333
err = CRYPT_INVALID_PACKET;
3434
goto error;
3535
}
3636
/* compute public key */
3737
if ((err = ltc_mp.ecc_ptmul(key->k, &key->dp.base, &key->pubkey, a, prime, 1)) != CRYPT_OK) { goto error; }
38-
key->type = type;
3938
}
4039
else if (type == PK_PUBLIC) {
4140
/* load public key */
4241
if ((err = ltc_ecc_import_point(in, inlen, prime, a, b, key->pubkey.x, key->pubkey.y)) != CRYPT_OK) { goto error; }
4342
if ((err = mp_set(key->pubkey.z, 1)) != CRYPT_OK) { goto error; }
44-
key->type = type;
4543
}
4644
else {
4745
err = CRYPT_INVALID_PACKET;
@@ -53,6 +51,7 @@ int ecc_set_key(const unsigned char *in, unsigned long inlen, int type, ecc_key
5351
goto error;
5452
}
5553

54+
key->type = type;
5655
return CRYPT_OK;
5756

5857
error:

0 commit comments

Comments
 (0)