mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-30 00:54:24 +01:00
Fixup: Add missing TinyCrypt guard in ECC private key parsing
PEM-encoded keys with PEM header -----BEGIN EC PRIVATE KEY----- ... -----END EC PRIVATE KEY----- were previously not parsed in configurations using TinyCrypt instead of legacy ECC crypto.
This commit is contained in:
parent
f2bf115057
commit
d336f721c0
@ -1414,7 +1414,7 @@ int mbedtls_pk_parse_key( mbedtls_pk_context *pk,
|
|||||||
return( ret );
|
return( ret );
|
||||||
#endif /* MBEDTLS_RSA_C */
|
#endif /* MBEDTLS_RSA_C */
|
||||||
|
|
||||||
#if defined(MBEDTLS_ECP_C)
|
#if defined(MBEDTLS_ECP_C) || defined(MBEDTLS_USE_TINYCRYPT)
|
||||||
/* Avoid calling mbedtls_pem_read_buffer() on non-null-terminated string */
|
/* Avoid calling mbedtls_pem_read_buffer() on non-null-terminated string */
|
||||||
if( key[keylen - 1] != '\0' )
|
if( key[keylen - 1] != '\0' )
|
||||||
ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT;
|
ret = MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT;
|
||||||
@ -1427,9 +1427,15 @@ int mbedtls_pk_parse_key( mbedtls_pk_context *pk,
|
|||||||
{
|
{
|
||||||
pk_info = mbedtls_pk_info_from_type( MBEDTLS_PK_ECKEY );
|
pk_info = mbedtls_pk_info_from_type( MBEDTLS_PK_ECKEY );
|
||||||
|
|
||||||
|
#if defined(MBEDTLS_USE_TINYCRYPT)
|
||||||
|
if( ( ret = mbedtls_pk_setup( pk, pk_info ) ) != 0 ||
|
||||||
|
( ret = pk_parse_key_sec1_der( mbedtls_uecc_pk( *pk ),
|
||||||
|
pem.buf, pem.buflen ) ) != 0 )
|
||||||
|
#else /* MBEDTLS_USE_TINYCRYPT */
|
||||||
if( ( ret = mbedtls_pk_setup( pk, pk_info ) ) != 0 ||
|
if( ( ret = mbedtls_pk_setup( pk, pk_info ) ) != 0 ||
|
||||||
( ret = pk_parse_key_sec1_der( mbedtls_pk_ec( *pk ),
|
( ret = pk_parse_key_sec1_der( mbedtls_pk_ec( *pk ),
|
||||||
pem.buf, pem.buflen ) ) != 0 )
|
pem.buf, pem.buflen ) ) != 0 )
|
||||||
|
#endif /* MBEDTLS_USE_TINYCRYPT */
|
||||||
{
|
{
|
||||||
mbedtls_pk_free( pk );
|
mbedtls_pk_free( pk );
|
||||||
}
|
}
|
||||||
@ -1443,7 +1449,7 @@ int mbedtls_pk_parse_key( mbedtls_pk_context *pk,
|
|||||||
return( MBEDTLS_ERR_PK_PASSWORD_REQUIRED );
|
return( MBEDTLS_ERR_PK_PASSWORD_REQUIRED );
|
||||||
else if( ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT )
|
else if( ret != MBEDTLS_ERR_PEM_NO_HEADER_FOOTER_PRESENT )
|
||||||
return( ret );
|
return( ret );
|
||||||
#endif /* MBEDTLS_ECP_C */
|
#endif /* MBEDTLS_ECP_C || MBEDTLS_USE_TINYCRYPT */
|
||||||
|
|
||||||
/* Avoid calling mbedtls_pem_read_buffer() on non-null-terminated string */
|
/* Avoid calling mbedtls_pem_read_buffer() on non-null-terminated string */
|
||||||
if( key[keylen - 1] != '\0' )
|
if( key[keylen - 1] != '\0' )
|
||||||
|
Loading…
Reference in New Issue
Block a user