Skip to content

Commit d98a71e

Browse files
SE key registration: call p_validate_slot_number
When registering a key in a secure element, if the driver has a p_validate_slot_number method, call it.
1 parent c88b896 commit d98a71e

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

include/psa/crypto_se_driver.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,27 @@ typedef enum
818818
PSA_KEY_CREATION_GENERATE, /**< During psa_generate_key() */
819819
PSA_KEY_CREATION_DERIVE, /**< During psa_key_derivation_output_key() */
820820
PSA_KEY_CREATION_COPY, /**< During psa_copy_key() */
821+
822+
#ifndef __DOXYGEN_ONLY__
823+
/** A key is being registered with mbedtls_psa_register_se_key().
824+
*
825+
* The core only passes this value to
826+
* psa_drv_se_key_management_t::p_validate_slot_number, not to
827+
* psa_drv_se_key_management_t::p_allocate. The call to
828+
* `p_validate_slot_number` is not followed by any other call to the
829+
* driver: the key is considered successfully registered if the call to
830+
* `p_validate_slot_number` succeeds, or if `p_validate_slot_number` is
831+
* null.
832+
*
833+
* With this creation method, the driver must return #PSA_SUCCESS if
834+
* the given attributes are compatible with the existing key in the slot,
835+
* and #PSA_ERROR_DOES_NOT_EXIST if the driver can determine that there
836+
* is no key with the specified slot number.
837+
*
838+
* This is an Mbed Crypto extension.
839+
*/
840+
PSA_KEY_CREATION_REGISTER,
841+
#endif
821842
} psa_key_creation_method_t;
822843

823844
/** \brief A function that allocates a slot for a key.

library/psa_crypto.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,6 +1914,21 @@ psa_status_t mbedtls_psa_register_se_key(
19141914
goto exit;
19151915
}
19161916

1917+
/* If the driver has a slot number validation method, call it.
1918+
* If it doesn't, it means the secure element is unable to validate
1919+
* anything and so we have to trust the application. */
1920+
if( drv->key_management != NULL &&
1921+
drv->key_management->p_validate_slot_number != NULL )
1922+
{
1923+
status = drv->key_management->p_validate_slot_number(
1924+
psa_get_se_driver_context( driver ),
1925+
attributes,
1926+
PSA_KEY_CREATION_REGISTER,
1927+
slot->data.se.slot_number );
1928+
if( status != PSA_SUCCESS )
1929+
goto exit;
1930+
}
1931+
19171932
status = psa_finish_key_creation( slot, driver );
19181933

19191934
exit:

0 commit comments

Comments
 (0)