@@ -811,6 +811,42 @@ typedef struct {
811
811
/**@{*/
812
812
813
813
/** \brief A function that allocates a slot for a key.
814
+ *
815
+ * To create a key in a specific slot in a secure element, the core
816
+ * first calls this function to determine a valid slot number,
817
+ * then calls a function to create the key material in that slot.
818
+ * For example, in nominal conditions (that is, if no error occurs),
819
+ * the effect of a call to psa_import_key() with a lifetime that places
820
+ * the key in a secure element is the following:
821
+ * -# The core calls psa_drv_se_key_management_t::p_allocate
822
+ * (or in some implementations
823
+ * psa_drv_se_key_management_t::p_validate_slot_number). The driver
824
+ * selects (or validates) a suitable slot number given the key attributes
825
+ * and the state of the secure element.
826
+ * -# The core calls psa_drv_se_key_management_t::p_import to import
827
+ * the key material in the selected slot.
828
+ *
829
+ * Other key creation methods lead to similar sequences. For example, the
830
+ * sequence for psa_generate_key() is the same except that the second step
831
+ * is a call to psa_drv_se_key_management_t::p_generate.
832
+ *
833
+ * In case of errors, other behaviors are possible.
834
+ * - If the PSA Cryptography subsystem dies after the first step,
835
+ * for example because the device has lost power abruptly,
836
+ * the second step may never happen, or may happen after a reset
837
+ * and re-initialization. Alternatively, after a reset and
838
+ * re-initialization, the core may call
839
+ * psa_drv_se_key_management_t::p_destroy on the slot number that
840
+ * was allocated (or validated) instead of calling a key creation function.
841
+ * - If an error occurs, the core may call
842
+ * psa_drv_se_key_management_t::p_destroy on the slot number that
843
+ * was allocated (or validated) instead of calling a key creation function.
844
+ *
845
+ * Errors and system resets also have an impact on the driver's persistent
846
+ * data. If a reset happens before the overall key creation process is
847
+ * completed (before or after the second step above), it is unspecified
848
+ * whether the persistent data after the reset is identical to what it
849
+ * was before or after the call to `p_allocate` (or `p_validate_slot_number`).
814
850
*
815
851
* \param[in,out] drv_context The driver context structure.
816
852
* \param[in,out] persistent_data A pointer to the persistent data
@@ -833,6 +869,42 @@ typedef psa_status_t (*psa_drv_se_allocate_key_t)(
833
869
const psa_key_attributes_t * attributes ,
834
870
psa_key_slot_number_t * key_slot );
835
871
872
+ /** \brief A function that determines whether a slot number is valid
873
+ * for a key.
874
+ *
875
+ * To create a key in a specific slot in a secure element, the core
876
+ * first calls this function to validate the choice of slot number,
877
+ * then calls a function to create the key material in that slot.
878
+ * See the documentation of #psa_drv_se_allocate_key_t for more details.
879
+ *
880
+ * As of the PSA Cryptography API specification version 1.0, there is no way
881
+ * for applications to trigger a call to this function. However some
882
+ * implementations offer the capability to create or declare a key in
883
+ * a specific slot via implementation-specific means, generally for the
884
+ * sake of initial device provisioning or onboarding. Such a mechanism may
885
+ * be added to a future version of the PSA Cryptography API specification.
886
+ *
887
+ * \param[in,out] drv_context The driver context structure.
888
+ * \param[in] attributes Attributes of the key.
889
+ * \param[in] key_slot Slot where the key is to be stored.
890
+ *
891
+ * \retval #PSA_SUCCESS
892
+ * The given slot number is valid for a key with the given
893
+ * attributes.
894
+ * \retval #PSA_ERROR_INVALID_ARGUMENT
895
+ * The given slot number is not valid for a key with the
896
+ * given attributes. This includes the case where the slot
897
+ * number is not valid at all.
898
+ * \retval #PSA_ERROR_ALREADY_EXISTS
899
+ * There is already a key with the specified slot number.
900
+ * Drivers may choose to return this error from the key
901
+ * creation function instead.
902
+ */
903
+ typedef psa_status_t (* psa_drv_se_validate_slot_number_t )(
904
+ psa_drv_se_context_t * drv_context ,
905
+ const psa_key_attributes_t * attributes ,
906
+ psa_key_slot_number_t key_slot );
907
+
836
908
/** \brief A function that imports a key into a secure element in binary format
837
909
*
838
910
* This function can support any output from psa_export_key(). Refer to the
@@ -977,8 +1049,10 @@ typedef psa_status_t (*psa_drv_se_generate_key_t)(psa_drv_se_context_t *drv_cont
977
1049
* If one of the functions is not implemented, it should be set to NULL.
978
1050
*/
979
1051
typedef struct {
980
- /** Function that allocates a slot. */
1052
+ /** Function that allocates a slot for a key . */
981
1053
psa_drv_se_allocate_key_t p_allocate ;
1054
+ /** Function that checks the validity of a slot for a key. */
1055
+ psa_drv_se_validate_slot_number_t p_validate_slot_number ;
982
1056
/** Function that performs a key import operation */
983
1057
psa_drv_se_import_key_t p_import ;
984
1058
/** Function that performs a generation */
0 commit comments