Compute public key if absent when reading EC key

This commit is contained in:
Manuel Pégourié-Gonnard 2013-09-18 16:13:02 +02:00
parent 4fc090af9c
commit ff29f9c825

View File

@ -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, if( ( ret = asn1_get_tag( &p, end, &len,
ASN1_CONTEXT_SPECIFIC | ASN1_CONSTRUCTED | 1 ) ) == 0 ) 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 ); ecp_keypair_free( eck );
return( POLARSSL_ERR_PK_KEY_INVALID_FORMAT + ret ); 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 ) if( ( ret = ecp_check_privkey( &eck->grp, &eck->d ) ) != 0 )
{ {