mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-26 06:25:43 +01:00
Reduce number of MPI's used in pk_parse_key_pkcs1_der
As the optional RSA parameters DP, DQ and QP are effectively discarded (they are only considered for their length to ensure that the key fills the entire buffer), it is not necessary to read them into separate MPI's.
This commit is contained in:
parent
e167fe6a53
commit
efa14e8b0c
@ -661,11 +661,8 @@ static int pk_parse_key_pkcs1_der( mbedtls_rsa_context *rsa,
|
|||||||
size_t len;
|
size_t len;
|
||||||
unsigned char *p, *end;
|
unsigned char *p, *end;
|
||||||
|
|
||||||
mbedtls_mpi DP, DQ, QP;
|
mbedtls_mpi T;
|
||||||
|
mbedtls_mpi_init( &T );
|
||||||
mbedtls_mpi_init( &DP );
|
|
||||||
mbedtls_mpi_init( &DQ );
|
|
||||||
mbedtls_mpi_init( &QP );
|
|
||||||
|
|
||||||
p = (unsigned char *) key;
|
p = (unsigned char *) key;
|
||||||
end = p + keylen;
|
end = p + keylen;
|
||||||
@ -749,9 +746,9 @@ static int pk_parse_key_pkcs1_der( mbedtls_rsa_context *rsa,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
/* Check optional parameters */
|
/* Check optional parameters */
|
||||||
if( ( ret = mbedtls_asn1_get_mpi( &p, end, &DP ) ) != 0 ||
|
if( ( ret = mbedtls_asn1_get_mpi( &p, end, &T ) ) != 0 ||
|
||||||
( ret = mbedtls_asn1_get_mpi( &p, end, &DQ ) ) != 0 ||
|
( ret = mbedtls_asn1_get_mpi( &p, end, &T ) ) != 0 ||
|
||||||
( ret = mbedtls_asn1_get_mpi( &p, end, &QP ) ) != 0 )
|
( ret = mbedtls_asn1_get_mpi( &p, end, &T ) ) != 0 )
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if( p != end )
|
if( p != end )
|
||||||
@ -762,12 +759,11 @@ static int pk_parse_key_pkcs1_der( mbedtls_rsa_context *rsa,
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
|
||||||
mbedtls_mpi_free( &DP );
|
mbedtls_mpi_free( &T );
|
||||||
mbedtls_mpi_free( &DQ );
|
|
||||||
mbedtls_mpi_free( &QP );
|
|
||||||
|
|
||||||
if( ret != 0 )
|
if( ret != 0 )
|
||||||
{
|
{
|
||||||
|
/* Wrap error code if it's coming from a lower level */
|
||||||
if( ( ret & 0xff80 ) == 0 )
|
if( ( ret & 0xff80 ) == 0 )
|
||||||
ret = MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret;
|
ret = MBEDTLS_ERR_PK_KEY_INVALID_FORMAT + ret;
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user