SE driver lookup functions

Expose the type of an entry in the SE driver table as an opaque type
to other library modules. Soon, driver table entries will have state,
and callers will need to be able to access this state through
functions using this opaque type.

Provide functions to look up a driver by its lifetime and to retrieve
the method table from an entry.
This commit is contained in:
Gilles Peskine 2019-06-26 18:18:12 +02:00
parent e62b74e68f
commit f989dbe6d8
2 changed files with 87 additions and 3 deletions

View File

@ -32,13 +32,53 @@
#include "psa_crypto_se.h"
typedef struct
/****************************************************************/
/* Driver lookup */
/****************************************************************/
typedef struct psa_se_drv_table_entry_s
{
psa_key_lifetime_t lifetime;
const psa_drv_se_t *methods;
} method_table_entry_t;
} psa_se_drv_table_entry_t;
static method_table_entry_t driver_table[PSA_MAX_SE_DRIVERS];
static psa_se_drv_table_entry_t driver_table[PSA_MAX_SE_DRIVERS];
const psa_se_drv_table_entry_t *psa_get_se_driver_entry(
psa_key_lifetime_t lifetime )
{
size_t i;
if( lifetime == 0 )
return( NULL );
for( i = 0; i < PSA_MAX_SE_DRIVERS; i++ )
{
if( driver_table[i].lifetime == lifetime )
return( &driver_table[i] );
}
return( NULL );
}
const psa_drv_se_t *psa_get_se_driver_methods(
const psa_se_drv_table_entry_t *drv )
{
return( drv->methods );
}
const psa_drv_se_t *psa_get_se_driver( psa_key_lifetime_t lifetime )
{
const psa_se_drv_table_entry_t *drv = psa_get_se_driver_entry( lifetime );
if( drv == NULL )
return( NULL );
else
return( drv->methods );
}
/****************************************************************/
/* Driver registration */
/****************************************************************/
psa_status_t psa_register_se_driver(
psa_key_lifetime_t lifetime,
@ -83,4 +123,10 @@ void psa_unregister_all_se_drivers( void )
memset( driver_table, 0, sizeof( driver_table ) );
}
/****************************************************************/
/* The end */
/****************************************************************/
#endif /* MBEDTLS_PSA_CRYPTO_SE_C */

View File

@ -42,4 +42,42 @@
*/
void psa_unregister_all_se_drivers( void );
/** A structure that describes a registered secure element driver.
*
* A secure element driver table entry contains a pointer to the
* driver's method table and a pointer to the driver's slot usage
* structure.
*/
typedef struct psa_se_drv_table_entry_s psa_se_drv_table_entry_t;
/** Return the secure element driver table entry for a lifetime value.
*
* \param lifetime The lifetime value to query.
*
* \return The driver table entry for \p lifetime, or
* \p NULL if \p lifetime does not correspond to a registered driver.
*/
const psa_se_drv_table_entry_t *psa_get_se_driver_entry(
psa_key_lifetime_t lifetime );
/** Return the method table for a secure element driver.
*
* \param[in] drv The driver table entry to access.
*
* \return The driver table entry for \p lifetime, or
* \p NULL if \p lifetime does not correspond to a registered driver.
*/
const psa_drv_se_t *psa_get_se_driver_methods(
const psa_se_drv_table_entry_t *drv );
/** Return the secure element driver method table for a lifetime value.
*
* \param lifetime The lifetime value to query.
*
* \return The driver method table for \p lifetime, or
* \p NULL if \p lifetime does not correspond to a registered driver.
*/
const psa_drv_se_t *psa_get_se_driver(
psa_key_lifetime_t lifetime );
#endif /* PSA_CRYPTO_SE_H */