File crypto_se_driver.h
PSA external cryptoprocessor driver module.
This header declares types and function signatures for cryptography drivers that access key material via opaque references. This is meant for cryptoprocessors that have a separate key storage from the space in which the PSA Crypto implementation runs, typically secure elements (SEs).
This file is part of the PSA Crypto Driver HAL (hardware abstraction layer), containing functions for driver developers to implement to enable hardware to be called in a standardized way by a PSA Cryptography API implementation. The functions comprising the driver HAL, which driver authors implement, are not intended to be called by application developers.
-
struct psa_drv_se_context_t
- #include <crypto_se_driver.h>
Driver context structure.
Driver functions receive a pointer to this structure. Each registered driver has one instance of this structure.
Implementations must include the fields specified here and may include other fields.
Public Members
-
const void *const private_persistent_data
A read-only pointer to the driver’s persistent data.
Drivers typically use this persistent data to keep track of which slot numbers are available. This is only a guideline: drivers may use the persistent data for any purpose, keeping in mind the restrictions on when the persistent data is saved to storage: the persistent data is only saved after calling certain functions that receive a writable pointer to the persistent data.
The core allocates a memory buffer for the persistent data. The pointer is guaranteed to be suitably aligned for any data type, like a pointer returned by
malloc(but the core can use any method to allocate the buffer, not necessarilymalloc).The size of this buffer is in the
persistent_data_sizefield of this structure.Before the driver is initialized for the first time, the content of the persistent data is all-bits-zero. After a driver upgrade, if the size of the persistent data has increased, the original data is padded on the right with zeros; if the size has decreased, the original data is truncated to the new size.
This pointer is to read-only data. Only a few driver functions are allowed to modify the persistent data. These functions receive a writable pointer. These functions are:
psa_drv_se_t::p_init
psa_drv_se_key_management_t::p_allocate
psa_drv_se_key_management_t::p_destroy
The PSA Cryptography core saves the persistent data from one session to the next. It does this before returning from API functions that call a driver method that is allowed to modify the persistent data, specifically:
psa_crypto_init() causes a call to psa_drv_se_t::p_init, and may call psa_drv_se_key_management_t::p_destroy to complete an action that was interrupted by a power failure.
Key creation functions cause a call to psa_drv_se_key_management_t::p_allocate, and may cause a call to psa_drv_se_key_management_t::p_destroy in case an error occurs.
psa_destroy_key() causes a call to psa_drv_se_key_management_t::p_destroy.
-
const size_t private_persistent_data_size
The size of
persistent_datain bytes.This is always equal to the value of the
persistent_data_sizefield of the psa_drv_se_t structure when the driver is registered.
-
uintptr_t private_transient_data
Driver transient data.
The core initializes this value to 0 and does not read or modify it afterwards. The driver may store whatever it wants in this field.
-
const void *const private_persistent_data
-
struct psa_drv_se_mac_t
- #include <crypto_se_driver.h>
A struct containing all of the function pointers needed to perform secure element MAC operations.
PSA Crypto API implementations should populate the table as appropriate upon startup.
If one of the functions is not implemented (such as
psa_drv_se_mac_generate_t), it should be set to NULL.Driver implementers should ensure that they implement all of the functions that make sense for their hardware, and that they provide a full solution (for example, if they support
p_setup, they should also supportp_updateand at least one ofp_finishorp_finish_verify).Public Members
-
size_t private_context_size
The size in bytes of the hardware-specific secure element MAC context structure
-
psa_drv_se_mac_setup_t private_p_setup
Function that performs a MAC setup operation
-
psa_drv_se_mac_update_t private_p_update
Function that performs a MAC update operation
-
psa_drv_se_mac_finish_t private_p_finish
Function that completes a MAC operation
-
psa_drv_se_mac_finish_verify_t private_p_finish_verify
Function that completes a MAC operation with a verify check
-
psa_drv_se_mac_abort_t private_p_abort
Function that aborts a previously started MAC operation
-
psa_drv_se_mac_generate_t private_p_mac
Function that performs a MAC operation in one call
-
psa_drv_se_mac_verify_t private_p_mac_verify
Function that performs a MAC and verify operation in one call
-
size_t private_context_size
-
struct psa_drv_se_cipher_t
- #include <crypto_se_driver.h>
A struct containing all of the function pointers needed to implement cipher operations using secure elements.
PSA Crypto API implementations should populate instances of the table as appropriate upon startup or at build time.
If one of the functions is not implemented (such as
psa_drv_se_cipher_ecb_t), it should be set to NULL.Public Members
-
size_t private_context_size
The size in bytes of the hardware-specific secure element cipher context structure
-
psa_drv_se_cipher_setup_t private_p_setup
Function that performs a cipher setup operation
-
psa_drv_se_cipher_set_iv_t private_p_set_iv
Function that sets a cipher IV (if necessary)
-
psa_drv_se_cipher_update_t private_p_update
Function that performs a cipher update operation
-
psa_drv_se_cipher_finish_t private_p_finish
Function that completes a cipher operation
-
psa_drv_se_cipher_abort_t private_p_abort
Function that aborts a cipher operation
-
psa_drv_se_cipher_ecb_t private_p_ecb
Function that performs ECB mode for a cipher operation (Danger: ECB mode should not be used directly by clients of the PSA Crypto Client API)
-
size_t private_context_size
-
struct psa_drv_se_asymmetric_t
- #include <crypto_se_driver.h>
A struct containing all of the function pointers needed to implement asymmetric cryptographic operations using secure elements.
PSA Crypto API implementations should populate instances of the table as appropriate upon startup or at build time.
If one of the functions is not implemented, it should be set to NULL.
Public Members
-
psa_drv_se_asymmetric_sign_t private_p_sign
Function that performs an asymmetric sign operation
-
psa_drv_se_asymmetric_verify_t private_p_verify
Function that performs an asymmetric verify operation
-
psa_drv_se_asymmetric_encrypt_t private_p_encrypt
Function that performs an asymmetric encrypt operation
-
psa_drv_se_asymmetric_decrypt_t private_p_decrypt
Function that performs an asymmetric decrypt operation
-
psa_drv_se_asymmetric_sign_t private_p_sign
-
struct psa_drv_se_aead_t
- #include <crypto_se_driver.h>
A struct containing all of the function pointers needed to implement secure element Authenticated Encryption with Additional Data operations.
PSA Crypto API implementations should populate instances of the table as appropriate upon startup.
If one of the functions is not implemented, it should be set to NULL.
Public Members
-
psa_drv_se_aead_encrypt_t private_p_encrypt
Function that performs the AEAD encrypt operation
-
psa_drv_se_aead_decrypt_t private_p_decrypt
Function that performs the AEAD decrypt operation
-
psa_drv_se_aead_encrypt_t private_p_encrypt
-
struct psa_drv_se_key_management_t
- #include <crypto_se_driver.h>
A struct containing all of the function pointers needed to for secure element key management.
PSA Crypto API implementations should populate instances of the table as appropriate upon startup or at build time.
If one of the functions is not implemented, it should be set to NULL.
Public Members
-
psa_drv_se_allocate_key_t private_p_allocate
Function that allocates a slot for a key.
-
psa_drv_se_validate_slot_number_t private_p_validate_slot_number
Function that checks the validity of a slot for a key.
-
psa_drv_se_import_key_t private_p_import
Function that performs a key import operation
-
psa_drv_se_generate_key_t private_p_generate
Function that performs a generation
-
psa_drv_se_destroy_key_t private_p_destroy
Function that performs a key destroy operation
-
psa_drv_se_export_key_t private_p_export
Function that performs a key export operation
-
psa_drv_se_export_key_t private_p_export_public
Function that performs a public key export operation
-
psa_drv_se_allocate_key_t private_p_allocate
-
struct psa_drv_se_key_derivation_t
- #include <crypto_se_driver.h>
A struct containing all of the function pointers needed to for secure element key derivation and agreement.
PSA Crypto API implementations should populate instances of the table as appropriate upon startup.
If one of the functions is not implemented, it should be set to NULL.
Public Members
-
size_t private_context_size
The driver-specific size of the key derivation context
-
psa_drv_se_key_derivation_setup_t private_p_setup
Function that performs a key derivation setup
-
psa_drv_se_key_derivation_collateral_t private_p_collateral
Function that sets key derivation collateral
-
psa_drv_se_key_derivation_derive_t private_p_derive
Function that performs a final key derivation step
-
psa_drv_se_key_derivation_export_t private_p_export
Function that performs a final key derivation or agreement and exports the key
-
size_t private_context_size
-
struct psa_drv_se_t
- #include <crypto_se_driver.h>
A structure containing pointers to all the entry points of a secure element driver.
Future versions of this specification may add extra substructures at the end of this structure.
Public Members
-
uint32_t private_hal_version
The version of the driver HAL that this driver implements. This is a protection against loading driver binaries built against a different version of this specification. Use PSA_DRV_SE_HAL_VERSION.
-
size_t private_persistent_data_size
The size of the driver’s persistent data in bytes.
This can be 0 if the driver does not need persistent data.
See the documentation of psa_drv_se_context_t::persistent_data for more information about why and how a driver can use persistent data.
-
psa_drv_se_init_t private_p_init
The driver initialization function.
This function is called once during the initialization of the PSA Cryptography subsystem, before any other function of the driver is called. If this function returns a failure status, the driver will be unusable, at least until the next system reset.
If this field is
NULL, it is equivalent to a function that does nothing and returns PSA_SUCCESS.
-
const psa_drv_se_key_management_t *private_key_management
-
const psa_drv_se_mac_t *private_mac
-
const psa_drv_se_cipher_t *private_cipher
-
const psa_drv_se_aead_t *private_aead
-
const psa_drv_se_asymmetric_t *private_asymmetric
-
const psa_drv_se_key_derivation_t *private_derivation
-
uint32_t private_hal_version