From ff29f9c8255dfc9872bd4f3547594d3dc4826e6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Wed, 18 Sep 2013 16:13:02 +0200 Subject: [PATCH] Compute public key if absent when reading EC key --- library/pkparse.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/library/pkparse.c b/library/pkparse.c index f123b6c2c8..9160e8577b 100644 --- a/library/pkparse.c +++ b/library/pkparse.c @@ -513,7 +513,7 @@ static int pk_parse_key_sec1_der( ecp_keypair *eck, } /* - * Is 'publickey' present? + * Is 'publickey' present? If not, create it from the private key. */ if( ( ret = asn1_get_tag( &p, end, &len, ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTED | 1 ) ) == 0 ) @@ -535,6 +535,12 @@ static int pk_parse_key_sec1_der( ecp_keypair *eck, ecp_keypair_free( eck ); return( POLARSSL_ERR_PK_KEY_INVALID_FORMAT + ret ); } + else if( ( ret = ecp_mul( &eck->grp, &eck->Q, &eck->d, &eck->grp.G, + NULL, NULL ) ) != 0 ) + { + ecp_keypair_free( eck ); + return( POLARSSL_ERR_PK_KEY_INVALID_FORMAT + ret ); + } if( ( ret = ecp_check_privkey( &eck->grp, &eck->d ) ) != 0 ) {