@@ -677,6 +677,49 @@ typedef struct {
677
677
} psa_drv_se_aead_t ;
678
678
/**@}*/
679
679
680
+ /** \defgroup se_slot_usage Secure element slot usage mask
681
+ */
682
+ /**@{*/
683
+
684
+ /** The type of slot usage data for a driver.
685
+ *
686
+ * A driver can use this data to keep track of which slot numbers are in use
687
+ * and which are available for new keys. The core stores this data to
688
+ * internal persistent storage.
689
+ *
690
+ * The representation of this type is opaque. To access it,
691
+ * the driver can call psa_drv_cb_find_free_slot().
692
+ */
693
+ typedef struct psa_drv_se_slot_usage_s psa_drv_se_slot_usage_t ;
694
+
695
+ /** Callback function to find a free slot within a range.
696
+ *
697
+ * The PSA Crypto core provides this function to access the opaque
698
+ * data type that represents the slot usage.
699
+ *
700
+ * \param[in] slot_usage The opaque data structure containing the
701
+ * driver's slot usage table.
702
+ * \param from The start of the range.
703
+ * It is included in the search.
704
+ * \param before The end of the range.
705
+ * It is not included in the search.
706
+ * \param[out] found On success, a free slot number such that
707
+ * `from <= found < before`.
708
+ *
709
+ * \retval #PSA_SUCCESS
710
+ * Success. \c *found contains a slot number which is between
711
+ * \p from and \p before-1 inclusive and which is currently free.
712
+ * \retval #PSA_ERROR_INSUFFICIENT_STORAGE
713
+ * All slots in the indicated range are occupied.
714
+ */
715
+ psa_status_t psa_drv_cb_find_free_slot (
716
+ const psa_drv_se_slot_usage_t * slot_usage ,
717
+ psa_key_slot_number_t from ,
718
+ psa_key_slot_number_t before ,
719
+ psa_key_slot_number_t * found );
720
+
721
+ /**@}*/
722
+
680
723
/** \defgroup se_key_management Secure Element Key Management
681
724
* Currently, key management is limited to importing keys in the clear,
682
725
* destroying keys, and exporting keys in the clear.
@@ -685,6 +728,32 @@ typedef struct {
685
728
*/
686
729
/**@{*/
687
730
731
+ /* This type is documented in crypto.h. As far as drivers are concerned,
732
+ * this is an opaque type. */
733
+ typedef struct psa_key_attributes_s psa_key_attributes_t ;
734
+
735
+ /** \brief A function that allocates a slot number for a key.
736
+ *
737
+ * This function is typically implemented as one or more calls to
738
+ * psa_drv_cb_find_free_slot(), with bounds determined by the key
739
+ * attributes and the secure element configuration.
740
+ *
741
+ * \param[in] attributes Attributes of the key.
742
+ * \param[in] slot_usage Slot usage data of the driver.
743
+ * \param[out] key_slot Slot where the key will be stored.
744
+ * This must be a valid slot for a key of the
745
+ * chosen type. It must be unoccupied.
746
+ *
747
+ * \retval #PSA_SUCCESS
748
+ * Success.
749
+ * \retval #PSA_ERROR_NOT_SUPPORTED
750
+ * \retval #PSA_ERROR_INSUFFICIENT_STORAGE
751
+ */
752
+ typedef psa_status_t (* psa_drv_se_allocate_key_t )(
753
+ const psa_key_attributes_t * attributes ,
754
+ const psa_drv_se_slot_usage_t * slot_usage ,
755
+ psa_key_slot_number_t * key_slot );
756
+
688
757
/** \brief A function that imports a key into a secure element in binary format
689
758
*
690
759
* This function can support any output from psa_export_key(). Refer to the
@@ -815,6 +884,13 @@ typedef struct {
815
884
* slots numbered 0 through `slot_count - 1`.
816
885
*/
817
886
psa_key_slot_number_t slot_count ;
887
+ /** Function that allocates a slot number.
888
+ *
889
+ * If the secure element has no constraints regarding which keys
890
+ * can go into which slots, this should be \c NULL. In this case
891
+ * the core will pick any free slot when creating a key.
892
+ */
893
+ psa_drv_se_allocate_key_t p_allocate ;
818
894
/** Function that performs a key import operation */
819
895
psa_drv_se_import_key_t p_import ;
820
896
/** Function that performs a generation */
0 commit comments