diff --git a/src/ltc/pk/ecc/ecc_import_x509.c b/src/ltc/pk/ecc/ecc_import_x509.c index 1427e98..786e095 100644 --- a/src/ltc/pk/ecc/ecc_import_x509.c +++ b/src/ltc/pk/ecc/ecc_import_x509.c @@ -28,10 +28,10 @@ len = inlen; if ((err = der_decode_sequence_flexi(in, &len, &decoded_list)) == CRYPT_OK) { + err = CRYPT_ERROR; l = decoded_list; if (l->type == LTC_ASN1_SEQUENCE && l->child && l->child->type == LTC_ASN1_SEQUENCE) { - err = CRYPT_ERROR; l = l->child->child; while (l) { if (l->type == LTC_ASN1_SEQUENCE && l->data && diff --git a/src/ltc/pk/ecc/ecc_set_key.c b/src/ltc/pk/ecc/ecc_set_key.c index 75e047b..0b1538f 100644 --- a/src/ltc/pk/ecc/ecc_set_key.c +++ b/src/ltc/pk/ecc/ecc_set_key.c @@ -24,7 +24,7 @@ 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; @@ -35,13 +35,11 @@ } /* 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; @@ -53,6 +51,7 @@ goto error; } + key->type = type; return CRYPT_OK; error: diff --git a/t/pk_ecc_test_vectors_openssl.t b/t/pk_ecc_test_vectors_openssl.t index 982f869..a27fbf2 100644 --- a/t/pk_ecc_test_vectors_openssl.t +++ b/t/pk_ecc_test_vectors_openssl.t @@ -1,7 +1,7 @@ use strict; use warnings; -use Test::More tests => 660; +use Test::More tests => 661; use Crypt::PK::ECC; my $data = [ @@ -88,3 +88,12 @@ ok( $ec_pub->verify_message(pack("H*", $h->{ECDSA_SHA1}), 'test-data', 'SHA1'), "$h->{PRI_FILE}/ECDSA_SHA1"); ok( $ec_pub->verify_message(pack("H*", $h->{ECDSA_SHA256}), 'test-data', 'SHA256'), "$h->{PRI_FILE}/ECDSA_SHA256"); } + +### ecc_set_key bug +my $der = pack("H*", "3081be020101041500c78b055db0706fd86b5a15e14b9e51f0043d18f9a074307202010130200607". + "2a8648ce3d0101021500fffffffffffffffffffffffffffffffeffffac7330060401000401070429". + "043b4c382ce37aa192a4019e763036f4f5dd4d7ebb938cf935318fdced6bc28286531733c3f03c4f". + "ee02150100000000000000000001b8fa16dfab9aca16b6b3020101a12c032a00040ca9f03d79907c". + "97538177a3027970abefa351073a73120e1b5d2dab02dde37c118a44f8cb267b56"); +my $pk = Crypt::PK::ECC->new(\$der); +ok($pk->is_private, "ecc_set_key bug"); \ No newline at end of file