Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion src/pk/ecc/ecc_import_pkcs8.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ int ecc_import_pkcs8_asn1(ltc_asn1_list *alg_id, ltc_asn1_list *priv_key, ecc_ke
*/

if (ltc_mp_cmp_d(version->data, 1) != LTC_MP_EQ) {
err = CRYPT_INVALID_PACKET;
goto LBL_DONE;
}
cofactor = ltc_mp_get_int(p_cofactor->data);
Expand All @@ -91,6 +92,9 @@ int ecc_import_pkcs8_asn1(ltc_asn1_list *alg_id, ltc_asn1_list *priv_key, ecc_ke
if ((err = ecc_set_curve_from_mpis(a, b, prime->data, order->data, gx, gy, cofactor, key)) != CRYPT_OK) {
goto LBL_DONE;
}
} else {
err = CRYPT_INVALID_PACKET;
goto LBL_DONE;
}
} else {
err = CRYPT_INVALID_PACKET;
Expand All @@ -115,7 +119,6 @@ int ecc_import_pkcs8_asn1(ltc_asn1_list *alg_id, ltc_asn1_list *priv_key, ecc_ke
}
}
err = CRYPT_INVALID_PACKET;
goto LBL_DONE;

LBL_ECCFREE:
ecc_free(key);
Expand Down
11 changes: 11 additions & 0 deletions tests/ecc_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2277,6 +2277,17 @@ static int s_ecc_import_export(void) {
DO(ecc_key_cmp(PK_PRIVATE, &pri, &key));
ecc_free(&key);

/* import - private PKCS8 format - malformed explicit curve parameters or private key */
XMEMCPY(out, long_pri_pkcs8, sizeof(long_pri_pkcs8));
out[24] = 0x02; /* ECParameters version 2 */
SHOULD_FAIL(ecc_import_pkcs8(out, sizeof(long_pri_pkcs8), NULL, &key));
XMEMCPY(out, long_pri_pkcs8, sizeof(long_pri_pkcs8));
out[73] = 0x02; /* curve A as INTEGER instead of OCTET STRING */
SHOULD_FAIL(ecc_import_pkcs8(out, sizeof(long_pri_pkcs8), NULL, &key));
XMEMCPY(out, long_pri_pkcs8, sizeof(long_pri_pkcs8));
out[186] = 0x31; /* ECPrivateKey as SET instead of SEQUENCE, the already set curve has to be freed */
SHOULD_FAIL(ecc_import_pkcs8(out, sizeof(long_pri_pkcs8), NULL, &key));

/* import - private PKCS8 format - password protected (PBES1 algorithms) */
#ifdef LTC_MD2
DO(ecc_import_pkcs8(long_pri_pkcs8_pbe_md2_des, sizeof(long_pri_pkcs8_pbe_md2_des), &pw_ctx, &key));
Expand Down
Loading