mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-01-12 19:35:38 +00:00
Rename x509_get_pubkey to _rsa and split it up
This commit is contained in:
parent
f16ac763f6
commit
094ad9e512
|
@ -538,12 +538,45 @@ static int x509_get_dates( unsigned char **p,
|
||||||
return( 0 );
|
return( 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* RSAPublicKey ::= SEQUENCE {
|
||||||
|
* modulus INTEGER, -- n
|
||||||
|
* publicExponent INTEGER -- e
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
static int x509_get_rsapubkey( unsigned char **p,
|
||||||
|
const unsigned char *end,
|
||||||
|
rsa_context *rsa )
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
if( ( ret = asn1_get_tag( p, end, &len,
|
||||||
|
ASN1_CONSTRUCTED | ASN1_SEQUENCE ) ) != 0 )
|
||||||
|
return( POLARSSL_ERR_X509_CERT_INVALID_PUBKEY + ret );
|
||||||
|
|
||||||
|
if( *p + len != end )
|
||||||
|
return( POLARSSL_ERR_X509_CERT_INVALID_PUBKEY +
|
||||||
|
POLARSSL_ERR_ASN1_LENGTH_MISMATCH );
|
||||||
|
|
||||||
|
if( ( ret = asn1_get_mpi( p, end, &rsa->N ) ) != 0 ||
|
||||||
|
( ret = asn1_get_mpi( p, end, &rsa->E ) ) != 0 )
|
||||||
|
return( POLARSSL_ERR_X509_CERT_INVALID_PUBKEY + ret );
|
||||||
|
|
||||||
|
if( ( ret = rsa_check_pubkey( rsa ) ) != 0 )
|
||||||
|
return( ret );
|
||||||
|
|
||||||
|
rsa->len = mpi_size( &rsa->N );
|
||||||
|
|
||||||
|
return( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* SubjectPublicKeyInfo ::= SEQUENCE {
|
* SubjectPublicKeyInfo ::= SEQUENCE {
|
||||||
* algorithm AlgorithmIdentifier,
|
* algorithm AlgorithmIdentifier,
|
||||||
* subjectPublicKey BIT STRING }
|
* subjectPublicKey BIT STRING }
|
||||||
*/
|
*/
|
||||||
static int x509_get_pubkey( unsigned char **p,
|
static int x509_get_pubkey_rsa( unsigned char **p,
|
||||||
const unsigned char *end,
|
const unsigned char *end,
|
||||||
rsa_context *rsa )
|
rsa_context *rsa )
|
||||||
{
|
{
|
||||||
|
@ -588,30 +621,7 @@ static int x509_get_pubkey( unsigned char **p,
|
||||||
if( *(*p)++ != 0 )
|
if( *(*p)++ != 0 )
|
||||||
return( POLARSSL_ERR_X509_CERT_INVALID_PUBKEY );
|
return( POLARSSL_ERR_X509_CERT_INVALID_PUBKEY );
|
||||||
|
|
||||||
/*
|
return( x509_get_rsapubkey( p, end, rsa ) );
|
||||||
* RSAPublicKey ::= SEQUENCE {
|
|
||||||
* modulus INTEGER, -- n
|
|
||||||
* publicExponent INTEGER -- e
|
|
||||||
* }
|
|
||||||
*/
|
|
||||||
if( ( ret = asn1_get_tag( p, end, &len,
|
|
||||||
ASN1_CONSTRUCTED | ASN1_SEQUENCE ) ) != 0 )
|
|
||||||
return( POLARSSL_ERR_X509_CERT_INVALID_PUBKEY + ret );
|
|
||||||
|
|
||||||
if( *p + len != end )
|
|
||||||
return( POLARSSL_ERR_X509_CERT_INVALID_PUBKEY +
|
|
||||||
POLARSSL_ERR_ASN1_LENGTH_MISMATCH );
|
|
||||||
|
|
||||||
if( ( ret = asn1_get_mpi( p, end, &rsa->N ) ) != 0 ||
|
|
||||||
( ret = asn1_get_mpi( p, end, &rsa->E ) ) != 0 )
|
|
||||||
return( POLARSSL_ERR_X509_CERT_INVALID_PUBKEY + ret );
|
|
||||||
|
|
||||||
if( ( ret = rsa_check_pubkey( rsa ) ) != 0 )
|
|
||||||
return( ret );
|
|
||||||
|
|
||||||
rsa->len = mpi_size( &rsa->N );
|
|
||||||
|
|
||||||
return( 0 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int x509_get_sig( unsigned char **p,
|
static int x509_get_sig( unsigned char **p,
|
||||||
|
@ -1378,8 +1388,7 @@ static int x509parse_crt_der_core( x509_cert *crt, const unsigned char *buf,
|
||||||
/*
|
/*
|
||||||
* SubjectPublicKeyInfo
|
* SubjectPublicKeyInfo
|
||||||
*/
|
*/
|
||||||
if( ( ret = x509_get_pubkey( &p, end,
|
if( ( ret = x509_get_pubkey_rsa( &p, end, &crt->rsa ) ) != 0 )
|
||||||
&crt->rsa ) ) != 0 )
|
|
||||||
{
|
{
|
||||||
x509_free( crt );
|
x509_free( crt );
|
||||||
return( ret );
|
return( ret );
|
||||||
|
@ -2609,7 +2618,7 @@ int x509parse_public_key_rsa( rsa_context *rsa,
|
||||||
#endif
|
#endif
|
||||||
end = p + keylen;
|
end = p + keylen;
|
||||||
|
|
||||||
if( ( ret = x509_get_pubkey( &p, end, rsa ) ) != 0 )
|
if( ( ret = x509_get_pubkey_rsa( &p, end, rsa ) ) != 0 )
|
||||||
{
|
{
|
||||||
#if defined(POLARSSL_PEM_C)
|
#if defined(POLARSSL_PEM_C)
|
||||||
pem_free( &pem );
|
pem_free( &pem );
|
||||||
|
|
Loading…
Reference in a new issue