Kenji Arai / mbed-os_TYBLE16

Dependents:   TYBLE16_simple_data_logger TYBLE16_MP3_Air

Embed: (wiki syntax)

« Back to documentation index

psa_crypto_storage.h File Reference

psa_crypto_storage.h File Reference

PSA cryptography module: Mbed TLS key storage. More...

Go to the source code of this file.

Data Structures

union  psa_crypto_transaction_t
 Transaction data. More...

Typedefs

typedef uint16_t psa_crypto_transaction_type_t
 The type of transaction that is in progress.

Functions

int psa_is_key_present_in_storage (const psa_key_file_id_t key)
 Checks if persistent data is stored for the given key slot number.
psa_status_t psa_save_persistent_key (const psa_core_key_attributes_t *attr, const uint8_t *data, const size_t data_length)
 Format key data and metadata and save to a location for given key slot.
psa_status_t psa_load_persistent_key (psa_core_key_attributes_t *attr, uint8_t **data, size_t *data_length)
 Parses key data and metadata and load persistent key for given key slot number.
psa_status_t psa_destroy_persistent_key (const psa_key_file_id_t key)
 Remove persistent data for the given key slot number.
void psa_free_persistent_key_data (uint8_t *key_data, size_t key_data_length)
 Free the temporary buffer allocated by psa_load_persistent_key().
void psa_format_key_data_for_storage (const uint8_t *data, const size_t data_length, const psa_core_key_attributes_t *attr, uint8_t *storage_data)
 Formats key data and metadata for persistent storage.
psa_status_t psa_parse_key_data_from_storage (const uint8_t *storage_data, size_t storage_data_length, uint8_t **key_data, size_t *key_data_length, psa_core_key_attributes_t *attr)
 Parses persistent storage data into key data and metadata.
static void psa_crypto_prepare_transaction (psa_crypto_transaction_type_t type)
 Prepare for a transaction.
psa_status_t psa_crypto_save_transaction (void)
 Save the transaction data to storage.
psa_status_t psa_crypto_load_transaction (void)
 Load the transaction data from storage, if any.
psa_status_t psa_crypto_stop_transaction (void)
 Indicate that the current transaction is finished.
psa_status_t mbedtls_psa_storage_inject_entropy (const unsigned char *seed, size_t seed_size)
 Backend side of mbedtls_psa_inject_entropy().

Variables

psa_crypto_transaction_t psa_crypto_transaction
 The single active transaction.

Detailed Description

PSA cryptography module: Mbed TLS key storage.

Definition in file psa_crypto_storage.h.


Typedef Documentation

The type of transaction that is in progress.

Definition at line 210 of file psa_crypto_storage.h.


Function Documentation

psa_status_t mbedtls_psa_storage_inject_entropy ( const unsigned char *  seed,
size_t  seed_size 
)

Backend side of mbedtls_psa_inject_entropy().

This function stores the supplied data into the entropy seed file.

Return values:
PSA_SUCCESSSuccess
PSA_ERROR_STORAGE_FAILURE
PSA_ERROR_INSUFFICIENT_STORAGE
PSA_ERROR_NOT_PERMITTEDThe entropy seed file already exists.

Definition at line 470 of file psa_crypto_storage.c.

psa_status_t psa_crypto_load_transaction ( void   )

Load the transaction data from storage, if any.

This function is meant to be called from psa_crypto_init() to recover in case a transaction was interrupted by a system crash.

Return values:
PSA_SUCCESSThe data about the ongoing transaction has been loaded to psa_crypto_transaction.
PSA_ERROR_DOES_NOT_EXISTThere is no ongoing transaction.
PSA_ERROR_STORAGE_FAILURE

Definition at line 437 of file psa_crypto_storage.c.

static void psa_crypto_prepare_transaction ( psa_crypto_transaction_type_t  type ) [static]

Prepare for a transaction.

There must not be an ongoing transaction.

Parameters:
typeThe type of transaction to start.

Definition at line 311 of file psa_crypto_storage.h.

psa_status_t psa_crypto_save_transaction ( void   )

Save the transaction data to storage.

You may call this function multiple times during a transaction to atomically update the transaction state.

Return values:
PSA_SUCCESS
PSA_ERROR_INSUFFICIENT_STORAGE
PSA_ERROR_STORAGE_FAILURE

Definition at line 418 of file psa_crypto_storage.c.

psa_status_t psa_crypto_stop_transaction ( void   )

Indicate that the current transaction is finished.

Call this function at the very end of transaction processing. This function does not "commit" or "abort" the transaction: the storage subsystem has no concept of "commit" and "abort", just saving and removing the transaction information in storage.

This function erases the transaction data in storage (if any) and resets the transaction data in memory.

Return values:
PSA_SUCCESSThere was transaction data in storage.
PSA_ERROR_DOES_NOT_EXISTThere was no transaction data in storage.
PSA_ERROR_STORAGE_FAILUREIt was impossible to determine whether there was transaction data in storage, or the transaction data could not be erased.

Definition at line 451 of file psa_crypto_storage.c.

psa_status_t psa_destroy_persistent_key ( const psa_key_file_id_t  key )

Remove persistent data for the given key slot number.

Parameters:
keyPersistent identifier of the key to remove from persistent storage.
Return values:
PSA_SUCCESSThe key was successfully removed, or the key did not exist.
PSA_ERROR_STORAGE_FAILURE

Definition at line 182 of file psa_crypto_storage.c.

void psa_format_key_data_for_storage ( const uint8_t *  data,
const size_t  data_length,
const psa_core_key_attributes_t *  attr,
uint8_t *  storage_data 
)

Formats key data and metadata for persistent storage.

Parameters:
[in]dataBuffer containing the key data.
data_lengthLength of the key data buffer.
[in]attrThe core attributes of the key.
[out]storage_dataOutput buffer for the formatted data.

Definition at line 268 of file psa_crypto_storage.c.

void psa_free_persistent_key_data ( uint8_t *  key_data,
size_t  key_data_length 
)

Free the temporary buffer allocated by psa_load_persistent_key().

This function must be called at some point after psa_load_persistent_key() to zeroize and free the memory allocated to the buffer in that function.

Parameters:
key_dataBuffer for the key data.
key_data_lengthSize of the key data buffer.

Definition at line 369 of file psa_crypto_storage.c.

int psa_is_key_present_in_storage ( const psa_key_file_id_t  key )

Checks if persistent data is stored for the given key slot number.

This function checks if any key data or metadata exists for the key slot in the persistent storage.

Parameters:
keyPersistent identifier to check.
Return values:
0No persistent data present for slot number
1Persistent data present for slot number

Definition at line 118 of file psa_crypto_storage.c.

psa_status_t psa_load_persistent_key ( psa_core_key_attributes_t *  attr,
uint8_t **  data,
size_t *  data_length 
)

Parses key data and metadata and load persistent key for given key slot number.

This function reads from a storage backend, parses the key data and metadata and writes them to the appropriate output parameters.

Note: This function allocates a buffer and returns a pointer to it through the data parameter. psa_free_persistent_key_data() must be called after this function to zeroize and free this buffer, regardless of whether this function succeeds or fails.

Parameters:
[in,out]attrOn input, the key identifier field identifies the key to load. Other fields are ignored. On success, the attribute structure contains the key metadata that was loaded from storage.
[out]dataPointer to an allocated key data buffer on return.
[out]data_lengthThe number of bytes that make up the key data.
Return values:
PSA_SUCCESS
PSA_ERROR_INSUFFICIENT_MEMORY
PSA_ERROR_STORAGE_FAILURE
PSA_ERROR_DOES_NOT_EXIST

Definition at line 378 of file psa_crypto_storage.c.

psa_status_t psa_parse_key_data_from_storage ( const uint8_t *  storage_data,
size_t  storage_data_length,
uint8_t **  key_data,
size_t *  key_data_length,
psa_core_key_attributes_t *  attr 
)

Parses persistent storage data into key data and metadata.

Parameters:
[in]storage_dataBuffer for the storage data.
storage_data_lengthLength of the storage data buffer
[out]key_dataOn output, pointer to a newly allocated buffer containing the key data. This must be freed using psa_free_persistent_key_data()
[out]key_data_lengthLength of the key data buffer
[out]attrOn success, the attribute structure is filled with the loaded key metadata.
Return values:
PSA_SUCCESS
PSA_ERROR_INSUFFICIENT_STORAGE
PSA_ERROR_INSUFFICIENT_MEMORY
PSA_ERROR_STORAGE_FAILURE

Definition at line 295 of file psa_crypto_storage.c.

psa_status_t psa_save_persistent_key ( const psa_core_key_attributes_t *  attr,
const uint8_t *  data,
const size_t  data_length 
)

Format key data and metadata and save to a location for given key slot.

This function formats the key data and metadata and saves it to a persistent storage backend. The storage location corresponding to the key slot must be empty, otherwise this function will fail. This function should be called after psa_import_key_into_slot() to ensure the persistent key is not saved into a storage location corresponding to an already occupied non-persistent key, as well as validating the key data.

Parameters:
[in]attrThe attributes of the key to save. The key identifier field in the attributes determines the key's location.
[in]dataBuffer containing the key data.
data_lengthThe number of bytes that make up the key data.
Return values:
PSA_SUCCESS
PSA_ERROR_INSUFFICIENT_MEMORY
PSA_ERROR_INSUFFICIENT_STORAGE
PSA_ERROR_STORAGE_FAILURE
PSA_ERROR_ALREADY_EXISTS

Definition at line 343 of file psa_crypto_storage.c.


Variable Documentation

The single active transaction.

Definition at line 416 of file psa_crypto_storage.c.