Actually use the parse functions

This commit is contained in:
Jarno Lamsa 2019-04-18 16:13:19 +03:00 committed by Hanno Becker
parent b176092656
commit 9c9e77a8ad
2 changed files with 28 additions and 0 deletions

View file

@ -172,6 +172,13 @@ static inline mbedtls_rsa_context *mbedtls_pk_rsa( const mbedtls_pk_context pk )
}
#endif /* MBEDTLS_RSA_C */
#if defined(MBEDTLS_USE_TINYCRYPT)
static inline mbedtls_uecc_keypair *mbedtls_uecc_pk( const mbedtls_pk_context pk )
{
return( (mbedtls_uecc_keypair *) (pk).pk_ctx );
}
#endif
#if defined(MBEDTLS_ECP_C)
/**
* Quick access to an EC context inside a PK context.

View file

@ -1197,6 +1197,16 @@ static int pk_parse_key_pkcs8_unencrypted_der(
}
} else
#endif /* MBEDTLS_RSA_C */
#if defined(MBEDTLS_USE_TINYCRYPT)
if( pk_alg == MBEDTLS_PK_ECDSA)
{
if( ( ret = pk_use_ecparams( &params ) ) != 0 ||
( ret = pk_parse_key_sec1_der( mbedtls_uecc_pk( *pk ), p, len ) ) != 0)
{
return( ret );
}
}
#else
#if defined(MBEDTLS_ECP_C)
if( pk_alg == MBEDTLS_PK_ECKEY || pk_alg == MBEDTLS_PK_ECKEY_DH )
{
@ -1208,6 +1218,7 @@ static int pk_parse_key_pkcs8_unencrypted_der(
}
} else
#endif /* MBEDTLS_ECP_C */
#endif
return( MBEDTLS_ERR_PK_UNKNOWN_PK_ALG );
return( 0 );
@ -1533,6 +1544,15 @@ int mbedtls_pk_parse_key( mbedtls_pk_context *pk,
mbedtls_pk_init( pk );
#endif /* MBEDTLS_RSA_C */
#if defined(MBEDTLS_USE_TINYCRYPT)
pk_info = mbedtls_pk_info_from_type( MBEDTLS_PK_ECDSA );
if( mbedtls_pk_setup( pk, pk_info ) == 0 &&
pk_parse_key_sec1_der( mbedtls_uecc_pk( *pk),
key, keylen) == 0)
{
return( 0 );
}
#else
#if defined(MBEDTLS_ECP_C)
pk_info = mbedtls_pk_info_from_type( MBEDTLS_PK_ECKEY );
if( mbedtls_pk_setup( pk, pk_info ) == 0 &&
@ -1543,6 +1563,7 @@ int mbedtls_pk_parse_key( mbedtls_pk_context *pk,
}
mbedtls_pk_free( pk );
#endif /* MBEDTLS_ECP_C */
#endif
/* If MBEDTLS_RSA_C is defined but MBEDTLS_ECP_C isn't,
* it is ok to leave the PK context initialized but not