Package list libcryptx-perl / 9016ac2
ecc_set_key troubles Karel Miko 3 years ago
3 changed file(s) with 13 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
2727
2828 len = inlen;
2929 if ((err = der_decode_sequence_flexi(in, &len, &decoded_list)) == CRYPT_OK) {
30 err = CRYPT_ERROR;
3031 l = decoded_list;
3132 if (l->type == LTC_ASN1_SEQUENCE &&
3233 l->child && l->child->type == LTC_ASN1_SEQUENCE) {
33 err = CRYPT_ERROR;
3434 l = l->child->child;
3535 while (l) {
3636 if (l->type == LTC_ASN1_SEQUENCE && l->data &&
2323 a = key->dp.A;
2424 b = key->dp.B;
2525
26 if (type == PK_PRIVATE && inlen <= (unsigned long)key->dp.size) {
26 if (type == PK_PRIVATE) {
2727 /* load private key */
2828 if ((err = mp_read_unsigned_bin(key->k, (unsigned char *)in, inlen)) != CRYPT_OK) {
2929 goto error;
3434 }
3535 /* compute public key */
3636 if ((err = ltc_mp.ecc_ptmul(key->k, &key->dp.base, &key->pubkey, a, prime, 1)) != CRYPT_OK) { goto error; }
37 key->type = type;
3837 }
3938 else if (type == PK_PUBLIC) {
4039 /* load public key */
4140 if ((err = ltc_ecc_import_point(in, inlen, prime, a, b, key->pubkey.x, key->pubkey.y)) != CRYPT_OK) { goto error; }
4241 if ((err = mp_set(key->pubkey.z, 1)) != CRYPT_OK) { goto error; }
43 key->type = type;
4442 }
4543 else {
4644 err = CRYPT_INVALID_PACKET;
5250 goto error;
5351 }
5452
53 key->type = type;
5554 return CRYPT_OK;
5655
5756 error:
00 use strict;
11 use warnings;
22
3 use Test::More tests => 660;
3 use Test::More tests => 661;
44 use Crypt::PK::ECC;
55
66 my $data = [
8787 ok( $ec_pub->verify_message(pack("H*", $h->{ECDSA_SHA1}), 'test-data', 'SHA1'), "$h->{PRI_FILE}/ECDSA_SHA1");
8888 ok( $ec_pub->verify_message(pack("H*", $h->{ECDSA_SHA256}), 'test-data', 'SHA256'), "$h->{PRI_FILE}/ECDSA_SHA256");
8989 }
90
91 ### ecc_set_key bug
92 my $der = pack("H*", "3081be020101041500c78b055db0706fd86b5a15e14b9e51f0043d18f9a074307202010130200607".
93 "2a8648ce3d0101021500fffffffffffffffffffffffffffffffeffffac7330060401000401070429".
94 "043b4c382ce37aa192a4019e763036f4f5dd4d7ebb938cf935318fdced6bc28286531733c3f03c4f".
95 "ee02150100000000000000000001b8fa16dfab9aca16b6b3020101a12c032a00040ca9f03d79907c".
96 "97538177a3027970abefa351073a73120e1b5d2dab02dde37c118a44f8cb267b56");
97 my $pk = Crypt::PK::ECC->new(\$der);
98 ok($pk->is_private, "ecc_set_key bug");