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
2 changes: 1 addition & 1 deletion src/pk/dsa/dsa_import.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static int s_dsa_import_pkcs1(const unsigned char *in, unsigned long inlen, dsa_
LTC_ASN1_INTEGER, 1UL, key->y,
LTC_ASN1_INTEGER, 1UL, key->x,
LTC_ASN1_EOL, 0UL, NULL)) == CRYPT_OK) {

if (zero != 0) return CRYPT_INVALID_PACKET;
key->type = PK_PRIVATE;
}
return err;
Expand Down
2 changes: 2 additions & 0 deletions src/pk/ecc/ecc_import_openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ static int s_ecc_import_private_with_oid(const unsigned char *in, unsigned long
/* try to load private key */
err = der_decode_sequence(in, inlen, seq_priv, 4);
if (err != CRYPT_OK) { goto error; }
if (pkver != 1) { err = CRYPT_INVALID_PACKET; goto error; }
err = ecc_import_with_oid(bin_k, seq_priv[1].size, curveoid, custom[0].size, PK_PRIVATE, key);
error:
return err;
Expand Down Expand Up @@ -88,6 +89,7 @@ int ecc_import_with_curve(const unsigned char *in, unsigned long inlen, int type
LTC_SET_ASN1_CUSTOM_CONSTRUCTED(seq_priv, 3, LTC_ASN1_CL_CONTEXT_SPECIFIC, 1, custom + 1); /* context specific 1 */
/* try to load private key */
err = der_decode_sequence(in, inlen, seq_priv, 4);
if (err == CRYPT_OK && pkver != 1) err = CRYPT_INVALID_PACKET;
} else if (type == PK_PUBLIC) {
/* try to load public key */
len_xy = sizeof(bin_xy);
Expand Down
5 changes: 5 additions & 0 deletions tests/dsa_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ static int s_dsa_compat_test(void)
"DSA public export from dsa_import(priv_key)\n", __LINE__);
dsa_free(&key);

/* the DSAPrivateKey version has to be 0 */
XMEMCPY(tmp, ltc_dsa_private_test_key, sizeof(ltc_dsa_private_test_key));
tmp[6] = 0x01;
SHOULD_FAIL(dsa_import(tmp, sizeof(ltc_dsa_private_test_key), &key));

DO(dsa_import(openssl_pub_dsa, sizeof(openssl_pub_dsa), &key));

x = sizeof(tmp);
Expand Down
7 changes: 7 additions & 0 deletions tests/ecc_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2237,6 +2237,13 @@ static int s_ecc_import_export(void) {
DO(ecc_import_openssl(long_pric, sizeof(long_pric), &key));
DO(ecc_key_cmp(PK_PRIVATE, &pri, &key));
ecc_free(&key);
/* the ECPrivateKey version has to be 1 */
XMEMCPY(out, short_pri, sizeof(short_pri));
out[4] = 0x02;
SHOULD_FAIL(ecc_import_openssl(out, sizeof(short_pri), &key));
XMEMCPY(out, ltc_ecc_long_pri_test_key, sizeof(ltc_ecc_long_pri_test_key));
out[6] = 0x02;
SHOULD_FAIL(ecc_import_openssl(out, sizeof(ltc_ecc_long_pri_test_key), &key));
DO(ecc_import_openssl(long_pub, sizeof(long_pub), &key));
DO(ecc_key_cmp(PK_PUBLIC, &pub, &key));
ecc_free(&key);
Expand Down
Loading