7. Usage considerations¶
7.1. Security recommendations¶
7.1.1. Always check for errors¶
Most functions in the Crypto API can return errors. All functions that can fail have
the return type psa_status_t
. A few functions cannot fail, and thus, return
void
or some other type.
If an error occurs, unless otherwise specified, the content of the output parameters is undefined and must not be used.
Some common causes of errors include:
In implementations where the keys are stored and processed in a separate environment from the application, all functions that need to access the cryptography processing environment might fail due to an error in the communication between the two environments.
If an algorithm is implemented with a hardware accelerator, which is logically separate from the application processor, the accelerator might fail, even when the application processor keeps running normally.
Most functions might fail due to a lack of resources. However, some implementations guarantee that certain functions always have sufficient memory.
All functions that access persistent keys might fail due to a storage failure.
All functions that require randomness might fail due to a lack of entropy. Implementations are encouraged to seed the random generator with sufficient entropy during the execution of
psa_crypto_init()
. However, some security standards require periodic reseeding from a hardware random generator, which can fail.
7.1.3. Cleaning up after use¶
To minimize impact if the system is compromised, it is recommended that applications wipe all sensitive data from memory when it is no longer used. That way, only data that is currently in use can be leaked, and past data is not compromised.
Wiping sensitive data includes:
Clearing temporary buffers in the stack or on the heap.
Aborting operations if they will not be finished.
Destroying keys that are no longer used.