mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-26 15:45:43 +01:00
Simplify length mismatch check in x509_get_pubkey
This commit is contained in:
parent
20c12f6b5f
commit
f16ac763f6
@ -550,7 +550,6 @@ static int x509_get_pubkey( unsigned char **p,
|
|||||||
int ret;
|
int ret;
|
||||||
size_t len;
|
size_t len;
|
||||||
x509_buf pk_alg_oid;
|
x509_buf pk_alg_oid;
|
||||||
unsigned char *end2;
|
|
||||||
pk_type_t pk_alg = POLARSSL_PK_NONE;
|
pk_type_t pk_alg = POLARSSL_PK_NONE;
|
||||||
|
|
||||||
if( ( ret = asn1_get_tag( p, end, &len,
|
if( ( ret = asn1_get_tag( p, end, &len,
|
||||||
@ -582,7 +581,9 @@ static int x509_get_pubkey( unsigned char **p,
|
|||||||
return( POLARSSL_ERR_X509_CERT_INVALID_PUBKEY +
|
return( POLARSSL_ERR_X509_CERT_INVALID_PUBKEY +
|
||||||
POLARSSL_ERR_ASN1_OUT_OF_DATA );
|
POLARSSL_ERR_ASN1_OUT_OF_DATA );
|
||||||
|
|
||||||
end2 = *p + len;
|
if( *p + len != end )
|
||||||
|
return( POLARSSL_ERR_X509_CERT_INVALID_PUBKEY +
|
||||||
|
POLARSSL_ERR_ASN1_LENGTH_MISMATCH );
|
||||||
|
|
||||||
if( *(*p)++ != 0 )
|
if( *(*p)++ != 0 )
|
||||||
return( POLARSSL_ERR_X509_CERT_INVALID_PUBKEY );
|
return( POLARSSL_ERR_X509_CERT_INVALID_PUBKEY );
|
||||||
@ -593,22 +594,18 @@ static int x509_get_pubkey( unsigned char **p,
|
|||||||
* publicExponent INTEGER -- e
|
* publicExponent INTEGER -- e
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
if( ( ret = asn1_get_tag( p, end2, &len,
|
if( ( ret = asn1_get_tag( p, end, &len,
|
||||||
ASN1_CONSTRUCTED | ASN1_SEQUENCE ) ) != 0 )
|
ASN1_CONSTRUCTED | ASN1_SEQUENCE ) ) != 0 )
|
||||||
return( POLARSSL_ERR_X509_CERT_INVALID_PUBKEY + ret );
|
return( POLARSSL_ERR_X509_CERT_INVALID_PUBKEY + ret );
|
||||||
|
|
||||||
if( *p + len != end2 )
|
if( *p + len != end )
|
||||||
return( POLARSSL_ERR_X509_CERT_INVALID_PUBKEY +
|
return( POLARSSL_ERR_X509_CERT_INVALID_PUBKEY +
|
||||||
POLARSSL_ERR_ASN1_LENGTH_MISMATCH );
|
POLARSSL_ERR_ASN1_LENGTH_MISMATCH );
|
||||||
|
|
||||||
if( ( ret = asn1_get_mpi( p, end2, &rsa->N ) ) != 0 ||
|
if( ( ret = asn1_get_mpi( p, end, &rsa->N ) ) != 0 ||
|
||||||
( ret = asn1_get_mpi( p, end2, &rsa->E ) ) != 0 )
|
( ret = asn1_get_mpi( p, end, &rsa->E ) ) != 0 )
|
||||||
return( POLARSSL_ERR_X509_CERT_INVALID_PUBKEY + ret );
|
return( POLARSSL_ERR_X509_CERT_INVALID_PUBKEY + ret );
|
||||||
|
|
||||||
if( *p != end )
|
|
||||||
return( POLARSSL_ERR_X509_CERT_INVALID_PUBKEY +
|
|
||||||
POLARSSL_ERR_ASN1_LENGTH_MISMATCH );
|
|
||||||
|
|
||||||
if( ( ret = rsa_check_pubkey( rsa ) ) != 0 )
|
if( ( ret = rsa_check_pubkey( rsa ) ) != 0 )
|
||||||
return( ret );
|
return( ret );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user