From db018d4f770f26627216e5d75c826398897d8a56 Mon Sep 17 00:00:00 2001 From: Manuel Mausz Date: Thu, 2 Jun 2016 18:48:46 +0200 Subject: Ensure Crypt::PK::ECC->key2hash()->{curve_name} is lowercase (#14) Depending on how the ec key gets created or imported key2hash() either returns the curve_name property either in lower- or uppercase. The value is lowercase if the curve parameters are imported or set by the user and uppercase if the name is directly returned from libtomcrypt. Since generate_key() expects the name in lowercase, we convert the value to lowercase as well. As a sideeffect this also avoids unneccessary curve parameter lookups in Crypt::PK::ECC::_curve_name_lookup(). --- t/pk_ecc.t | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 't/pk_ecc.t') diff --git a/t/pk_ecc.t b/t/pk_ecc.t index a8356f3a..9a83539b 100644 --- a/t/pk_ecc.t +++ b/t/pk_ecc.t @@ -1,6 +1,6 @@ use strict; use warnings; -use Test::More tests => 91; +use Test::More tests => 95; use Crypt::PK::ECC qw(ecc_encrypt ecc_decrypt ecc_sign_message ecc_verify_message ecc_sign_hash ecc_verify_hash ecc_shared_secret); @@ -128,6 +128,7 @@ for my $priv (qw/openssl_ec-short.pem openssl_ec-short.der/) { is($k->size, 32, "size $priv"); is(uc($k->key2hash->{pub_x}), 'A01532A3C0900053DE60FBEFEFCCA58793301598D308B41E6F4E364E388C2711', "key2hash $priv"); is(uc($k->curve2hash->{prime}), 'FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF', "curve2hash $priv"); + is($k->key2hash->{curve_name}, "secp256r1", "EC curve_name is lowercase"); } for my $pub (qw/openssl_ec-short.pub.pem openssl_ec-short.pub.der/) { @@ -136,4 +137,5 @@ for my $pub (qw/openssl_ec-short.pub.pem openssl_ec-short.pub.der/) { ok(!$k->is_private, "is_private $pub"); is($k->size, 32, "$pub size"); is(uc($k->key2hash->{pub_x}), 'A01532A3C0900053DE60FBEFEFCCA58793301598D308B41E6F4E364E388C2711', "key2hash $pub"); + is($k->key2hash->{curve_name}, "secp256r1", "EC curve_name is lowercase"); } -- cgit v1.2.3