Align names to use "opaque" only everywhere

It's better for names in the API to describe the "what" (opaque keys) rather
than the "how" (using PSA), at least since we don't intend to have multiple
function doing the same "what" in different ways in the foreseeable future.
This commit is contained in:
Manuel Pégourié-Gonnard 2018-11-06 09:34:30 +01:00 committed by Hanno Becker
parent 7d51255ca7
commit 276cb64e6c
5 changed files with 24 additions and 24 deletions

View file

@ -87,7 +87,7 @@ typedef enum {
MBEDTLS_PK_ECDSA,
MBEDTLS_PK_RSA_ALT,
MBEDTLS_PK_RSASSA_PSS,
MBEDTLS_PK_OPAQUE_PSA,
MBEDTLS_PK_OPAQUE,
} mbedtls_pk_type_t;
/**
@ -210,7 +210,7 @@ void mbedtls_pk_init( mbedtls_pk_context *ctx );
* \brief Free a mbedtls_pk_context
*
* \note For contexts that have been set up with
* mbedtls_pk_setup_psa(), this does not free the underlying
* mbedtls_pk_setup_opaque(), this does not free the underlying
* key slot and you still need to call psa_destroy_key()
* independently if you want to destroy that key.
*/
@ -271,7 +271,7 @@ int mbedtls_pk_setup( mbedtls_pk_context *ctx, const mbedtls_pk_info_t *info );
* \note This function is currently only available for ECC keypair.
* Support for other key types will be added later.
*/
int mbedtls_pk_setup_psa( mbedtls_pk_context *ctx, const psa_key_slot_t key );
int mbedtls_pk_setup_opaque( mbedtls_pk_context *ctx, const psa_key_slot_t key );
#endif /* MBEDTLS_USE_PSA_CRYPTO */
#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)

View file

@ -136,7 +136,7 @@ extern const mbedtls_pk_info_t mbedtls_rsa_alt_info;
#endif
#if defined(MBEDTLS_USE_PSA_CRYPTO)
extern const mbedtls_pk_info_t mbedtls_pk_opaque_psa_info;
extern const mbedtls_pk_info_t mbedtls_pk_opaque_info;
#endif
#endif /* MBEDTLS_PK_WRAP_H */

View file

@ -143,9 +143,9 @@ int mbedtls_pk_setup( mbedtls_pk_context *ctx, const mbedtls_pk_info_t *info )
/*
* Initialise a PSA-wrapping context
*/
int mbedtls_pk_setup_psa( mbedtls_pk_context *ctx, const psa_key_slot_t key )
int mbedtls_pk_setup_opaque( mbedtls_pk_context *ctx, const psa_key_slot_t key )
{
const mbedtls_pk_info_t * const info = &mbedtls_pk_opaque_psa_info;
const mbedtls_pk_info_t * const info = &mbedtls_pk_opaque_info;
psa_key_slot_t *pk_ctx;
psa_key_type_t type;

View file

@ -726,7 +726,7 @@ const mbedtls_pk_info_t mbedtls_rsa_alt_info = {
#if defined(MBEDTLS_USE_PSA_CRYPTO)
static void *pk_psa_alloc_wrap( void )
static void *pk_opaque_alloc_wrap( void )
{
void *ctx = mbedtls_calloc( 1, sizeof( psa_key_slot_t ) );
@ -735,13 +735,13 @@ static void *pk_psa_alloc_wrap( void )
return( ctx );
}
static void pk_psa_free_wrap( void *ctx )
static void pk_opaque_free_wrap( void *ctx )
{
mbedtls_platform_zeroize( ctx, sizeof( psa_key_slot_t ) );
mbedtls_free( ctx );
}
static size_t pk_psa_get_bitlen( const void *ctx )
static size_t pk_opaque_get_bitlen( const void *ctx )
{
const psa_key_slot_t *key = (const psa_key_slot_t *) ctx;
size_t bits;
@ -752,7 +752,7 @@ static size_t pk_psa_get_bitlen( const void *ctx )
return( bits );
}
static int pk_psa_can_do( mbedtls_pk_type_t type )
static int pk_opaque_can_do( mbedtls_pk_type_t type )
{
/* For now opaque PSA keys can only wrap ECC keypairs,
* as checked by setup_psa().
@ -819,7 +819,7 @@ static int pk_ecdsa_sig_asn1_from_psa( const unsigned char *sig, size_t *sig_len
return( 0 );
}
static int pk_psa_sign_wrap( void *ctx, mbedtls_md_type_t md_alg,
static int pk_opaque_sign_wrap( void *ctx, mbedtls_md_type_t md_alg,
const unsigned char *hash, size_t hash_len,
unsigned char *sig, size_t *sig_len,
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng )
@ -864,13 +864,13 @@ static int pk_psa_sign_wrap( void *ctx, mbedtls_md_type_t md_alg,
return( 0 );
}
const mbedtls_pk_info_t mbedtls_pk_opaque_psa_info = {
MBEDTLS_PK_OPAQUE_PSA,
"Opaque (PSA)",
pk_psa_get_bitlen,
pk_psa_can_do,
const mbedtls_pk_info_t mbedtls_pk_opaque_info = {
MBEDTLS_PK_OPAQUE,
"Opaque",
pk_opaque_get_bitlen,
pk_opaque_can_do,
NULL, /* verify - will be done later */
pk_psa_sign_wrap,
pk_opaque_sign_wrap,
#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
NULL, /* restartable verify - not relevant */
NULL, /* restartable sign - not relevant */
@ -878,8 +878,8 @@ const mbedtls_pk_info_t mbedtls_pk_opaque_psa_info = {
NULL, /* decrypt - will be done later */
NULL, /* encrypt - will be done later */
NULL, /* check_pair - could be done later or left NULL */
pk_psa_alloc_wrap,
pk_psa_free_wrap,
pk_opaque_alloc_wrap,
pk_opaque_free_wrap,
#if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
NULL, /* restart alloc - not relevant */
NULL, /* restart free - not relevant */

View file

@ -114,7 +114,7 @@ void pk_psa_utils( )
mbedtls_pk_context pk, pk2;
psa_key_slot_t key;
const char * const name = "Opaque (PSA)";
const char * const name = "Opaque";
const size_t bitlen = 256; /* harcoded in genkey() */
mbedtls_md_type_t md_alg = MBEDTLS_MD_NONE;
@ -125,7 +125,7 @@ void pk_psa_utils( )
mbedtls_pk_init( &pk );
mbedtls_pk_init( &pk2 );
TEST_ASSERT( mbedtls_pk_setup_psa( &pk, 0 ) ==
TEST_ASSERT( mbedtls_pk_setup_opaque( &pk, 0 ) ==
MBEDTLS_ERR_PK_BAD_INPUT_DATA );
mbedtls_pk_free( &pk );
@ -134,9 +134,9 @@ void pk_psa_utils( )
key = pk_psa_genkey();
TEST_ASSERT( key != 0 );
TEST_ASSERT( mbedtls_pk_setup_psa( &pk, key ) == 0 );
TEST_ASSERT( mbedtls_pk_setup_opaque( &pk, key ) == 0 );
TEST_ASSERT( mbedtls_pk_get_type( &pk ) == MBEDTLS_PK_OPAQUE_PSA );
TEST_ASSERT( mbedtls_pk_get_type( &pk ) == MBEDTLS_PK_OPAQUE );
TEST_ASSERT( strcmp( mbedtls_pk_get_name( &pk), name ) == 0 );
TEST_ASSERT( mbedtls_pk_get_bitlen( &pk ) == bitlen );
@ -797,7 +797,7 @@ void pk_psa_sign( )
key = pk_psa_genkey();
TEST_ASSERT( key != 0 );
TEST_ASSERT( mbedtls_pk_setup_psa( &pk, key ) == 0 );
TEST_ASSERT( mbedtls_pk_setup_opaque( &pk, key ) == 0 );
TEST_ASSERT( mbedtls_pk_sign( &pk, MBEDTLS_MD_SHA256,
hash, sizeof hash, sig, &sig_len,