Unregister drivers on library deinitialization

This commit is contained in:
Gilles Peskine 2019-06-24 14:34:43 +02:00
parent a899a72fd0
commit d089021128
3 changed files with 19 additions and 0 deletions

View File

@ -32,6 +32,7 @@
#include "psa_crypto_core.h"
#include "psa_crypto_invasive.h"
#include "psa_crypto_se.h"
#include "psa_crypto_slot_management.h"
/* Include internal declarations that are useful for implementing persistently
* stored keys. */
@ -5211,6 +5212,9 @@ void mbedtls_psa_crypto_free( void )
* In particular, this sets all state indicator to the value
* indicating "uninitialized". */
mbedtls_platform_zeroize( &global_data, sizeof( global_data ) );
/* Unregister all secure element drivers, so that we restart from
* a pristine state. */
psa_unregister_all_se_drivers( );
}
psa_status_t psa_crypto_init( void )

View File

@ -27,6 +27,8 @@
#if defined(MBEDTLS_PSA_CRYPTO_C)
#include <string.h>
#include "psa_crypto_se.h"
typedef struct
@ -69,4 +71,9 @@ psa_status_t psa_register_se_driver(
return( PSA_SUCCESS );
}
void psa_unregister_all_se_drivers( void )
{
memset( driver_table, 0, sizeof( driver_table ) );
}
#endif /* MBEDTLS_PSA_CRYPTO_C */

View File

@ -34,4 +34,12 @@
/** The maximum number of registered secure element driver lifetimes. */
#define PSA_MAX_SE_DRIVERS 4
/** Unregister all secure element drivers.
*
* \warning Do not call this function while the library is in the initialized
* state. This function is only intended to be called at the end
* of mbedtls_psa_crypto_free().
*/
void psa_unregister_all_se_drivers( void );
#endif /* PSA_CRYPTO_SE_H */