mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-09-01 05:01:58 +03:00
Implement can_do for opaque ECC keypairs
Unfortunately the can_do wrapper does not receive the key context as an argument, so it cannot check psa_get_key_information(). Later we might want to change our internal structures to fix this, but for now we'll just restrict opaque PSA keys to be ECDSA keypairs, as this is the only thing we need for now. It also simplifies testing a bit (no need to test each key type).
This commit is contained in:
committed by
Hanno Becker
parent
683632b78e
commit
07b103fe07
@@ -147,10 +147,18 @@ int mbedtls_pk_setup_psa( mbedtls_pk_context *ctx, const psa_key_slot_t key )
|
||||
{
|
||||
const mbedtls_pk_info_t * const info = &mbedtls_pk_opaque_psa_info;
|
||||
psa_key_slot_t *pk_ctx;
|
||||
psa_key_type_t type;
|
||||
|
||||
if( ctx == NULL || ctx->pk_info != NULL )
|
||||
return( MBEDTLS_ERR_PK_BAD_INPUT_DATA );
|
||||
|
||||
if( PSA_SUCCESS != psa_get_key_information( key, &type, NULL ) )
|
||||
return( MBEDTLS_ERR_PK_BAD_INPUT_DATA );
|
||||
|
||||
/* Current implementation of can_do() relies on this. */
|
||||
if( ! PSA_KEY_TYPE_IS_ECC_KEYPAIR( type ) )
|
||||
return( MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE) ;
|
||||
|
||||
if( ( ctx->pk_ctx = info->ctx_alloc_func() ) == NULL )
|
||||
return( MBEDTLS_ERR_PK_ALLOC_FAILED );
|
||||
|
||||
|
@@ -744,11 +744,20 @@ static size_t pk_psa_get_bitlen( const void *ctx )
|
||||
return( bits );
|
||||
}
|
||||
|
||||
static int pk_psa_can_do( mbedtls_pk_type_t type )
|
||||
{
|
||||
/* For now opaque PSA keys can only wrap ECC keypairs,
|
||||
* as checked by setup_psa().
|
||||
* Also, ECKEY_DH does not really make sense with the current API. */
|
||||
return( type == MBEDTLS_PK_ECKEY ||
|
||||
type == MBEDTLS_PK_ECDSA );
|
||||
}
|
||||
|
||||
const mbedtls_pk_info_t mbedtls_pk_opaque_psa_info = {
|
||||
MBEDTLS_PK_OPAQUE_PSA,
|
||||
"Opaque (PSA)",
|
||||
pk_psa_get_bitlen,
|
||||
NULL, /* coming soon: can_do */
|
||||
pk_psa_can_do,
|
||||
NULL, /* verify - will be done later */
|
||||
NULL, /* coming soon: sign */
|
||||
#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
|
||||
|
Reference in New Issue
Block a user