blob: 1d1f2c97e37044a12ce2cf6f363c91320512019f [file] [log] [blame]
Gilles Peskine6c723a22020-04-17 16:57:52 +02001.. _usage-considerations:
2
3Usage considerations
4--------------------
5
6Security recommendations
7~~~~~~~~~~~~~~~~~~~~~~~~
8
9Always check for errors
10^^^^^^^^^^^^^^^^^^^^^^^
11
12Most functions in this API can return errors. All functions that can fail have
13the return type `psa_status_t`. A few functions cannot fail, and thus, return
14``void`` or some other type.
15
16If an error occurs, unless otherwise specified, the content of the output
17parameters is undefined and must not be used.
18
19Some common causes of errors include:
20
21- In implementations where the keys are stored and processed in a separate
22 environment from the application, all functions that need to access the
23 cryptography processing environment might fail due to an error in the
24 communication between the two environments.
25- If an algorithm is implemented with a hardware accelerator, which is
26 logically separate from the application processor, the accelerator might fail,
27 even when the application processor keeps running normally.
28- Most functions might fail due to a lack of resources. However, some
29 implementations guarantee that certain functions always have sufficient
30 memory.
31- All functions that access persistent keys might fail due to a storage failure.
32- All functions that require randomness might fail due to a lack of entropy.
33 Implementations are encouraged to seed the random generator with sufficient
34 entropy during the execution of `psa_crypto_init()`. However, some security
35 standards require periodic reseeding from a hardware random generator, which
36 can fail.
37
38Shared memory and concurrency
39^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
40
41Some environments allow applications to be multithreaded, while others do not.
42In some environments, applications can share memory with a different security
43context. In environments with multithreaded applications or shared memory,
44applications must be written carefully to avoid data corruption or leakage. This
45specification requires the application to obey certain constraints.
46
47In general, this API allows either one writer or any number of simultaneous
48readers, on any given object. In other words, if two or more calls access the
49same object concurrently, then the behavior is only well-defined if all the
50calls are only reading from the object and do not modify it. Read accesses
51include reading memory by input parameters and reading keystore content by using
52a key. For more details, refer to the `concurrency`
53section.
54
55If an application shares memory with another security context, it can pass
56shared memory blocks as input buffers or output buffers, but not as non-buffer
57parameters. For more details, refer to the :title:`stability-of-parameters` section.
58
59Cleaning up after use
60^^^^^^^^^^^^^^^^^^^^^
61
62To minimize impact if the system is compromised, it is recommended that
63applications wipe all sensitive data from memory when it is no longer used. That
64way, only data that is currently in use can be leaked, and past data is not
65compromised.
66
67Wiping sensitive data includes:
68
69- Clearing temporary buffers in the stack or on the heap.
70- Aborting operations if they will not be finished.
71- Destroying keys that are no longer used.