@@ -108,18 +108,117 @@ typedef uint32_t psa_algorithm_t;
108108 * The lifetime of a key indicates where it is stored and what system actions
109109 * may create and destroy it.
110110 *
111- * Keys with the lifetime #PSA_KEY_LIFETIME_VOLATILE are automatically
112- * destroyed when the application terminates or on a power reset.
111+ * Lifetime values have the following structure:
112+ * - Bits 0-7 (#PSA_KEY_LIFETIME_GET_PERSISTENCE(\c lifetime)):
113+ * persistence level. This value indicates what device management
114+ * actions can cause it to be destroyed. In particular, it indicates
115+ * whether the key is _volatile_ or _persistent_.
116+ * See ::psa_key_persistence_t for more information.
117+ * - Bits 8-31 (#PSA_KEY_LIFETIME_GET_LOCATION(\c lifetime)):
118+ * location indicator. This value indicates where the key is stored
119+ * and where operations on the key are performed.
120+ * See ::psa_key_location_t for more information.
121+ *
122+ * Volatile keys are automatically destroyed when the application instance
123+ * terminates or on a power reset of the device. Persistent keys are
124+ * preserved until the application explicitly destroys them or until an
125+ * implementation-specific device management event occurs (for example,
126+ * a factory reset).
113127 *
114- * Keys with a lifetime other than #PSA_KEY_LIFETIME_VOLATILE are said
115- * to be _persistent_.
116- * Persistent keys are preserved if the application or the system restarts.
117128 * Persistent keys have a key identifier of type #psa_key_id_t.
129+ * This identifier remains valid throughout the lifetime of the key,
130+ * even if the application instance that created the key terminates.
118131 * The application can call psa_open_key() to open a persistent key that
119132 * it created previously.
133+ *
134+ * This specification defines two basic lifetime values:
135+ * - Keys with the lifetime #PSA_KEY_LIFETIME_VOLATILE are volatile.
136+ * All implementations should support this lifetime.
137+ * - Keys with the lifetime #PSA_KEY_LIFETIME_PERSISTENT are persistent.
138+ * All implementations that have access to persistent storage with
139+ * appropriate security guarantees should support this lifetime.
120140 */
121141typedef uint32_t psa_key_lifetime_t ;
122142
143+ /** Encoding of key persistence levels.
144+ *
145+ * What distinguishes different persistence levels is what device management
146+ * events may cause keys to be destroyed. _Volatile_ keys are destroyed
147+ * by a power reset. Persistent keys may be destroyed by events such as
148+ * a transfer of ownership or a factory reset. What management events
149+ * actually affect persistent keys at different levels is outside the
150+ * scope of the PSA Cryptography specification.
151+ *
152+ * This specification defines the following values of persistence levels:
153+ * - \c 0 = #PSA_KEY_PERSISTENCE_VOLATILE: volatile key.
154+ * A volatile key is automatically destroyed by the implementation when
155+ * the application instance terminates. In particular, a volatile key
156+ * is automatically destroyed on a power reset of the device.
157+ * - \c 1 = #PSA_KEY_PERSISTENCE_DEFAULT:
158+ * persistent key with a default lifetime.
159+ * Implementations should support this value if they support persistent
160+ * keys at all.
161+ * Applications should use this value if they have no specific needs that
162+ * are only met by implementation-specific features.
163+ * - \c 2-127: persistent key with a PSA-specified lifetime.
164+ * The PSA Cryptography specification does not define the meaning of these
165+ * values, but other PSA specifications may do so.
166+ * - \c 128-254: persistent key with a vendor-specified lifetime.
167+ * No PSA specification will define the meaning of these values, so
168+ * implementations may choose the meaning freely.
169+ * As a guideline, higher persistence levels should cause a key to survive
170+ * more management events than lower levels.
171+ * - \c 255 = #PSA_KEY_PERSISTENCE_READ_ONLY:
172+ * read-only or write-once key.
173+ * A key with this persistence level cannot be destroyed.
174+ * Implementations that support such keys may either allow their creation
175+ * through the PSA Cryptography API, preferably only to applications with
176+ * the appropriate privilege, or only expose keys created through
177+ * implementation-specific means such as a factory ROM engraving process.
178+ * Note that keys that are read-only due to policy restrictions
179+ * rather than due to physical limitations should not have this
180+ * persistence levels.
181+ *
182+ * \note Key persistence levels are 8-bit values. Key management
183+ * interfaces operate on lifetimes (type ::psa_key_lifetime_t) which
184+ * encode the persistence as the lower 8 bits of a 32-bit value.
185+ */
186+ typedef uint8_t psa_key_persistence_t ;
187+
188+ /** Encoding of key location indicators.
189+ *
190+ * If an implementation of this API can make calls to external
191+ * cryptoprocessors such as secure elements, the location of a key
192+ * indicates which secure element performs the operations on the key.
193+ * If an implementation offers multiple physical locations for persistent
194+ * storage, the location indicator reflects at which physical location
195+ * the key is stored.
196+ *
197+ * This specification defines the following values of location indicators:
198+ * - \c 0: primary local storage.
199+ * All implementations should support this value.
200+ * The primary local storage is typically the same storage area that
201+ * contains the key metadata.
202+ * - \c 1: primary secure element.
203+ * Implementations should support this value if there is a secure element
204+ * attached to the operating environment.
205+ * As a guideline, secure elements may provide higher resistance against
206+ * side channel and physical attacks than the primary local storage, but may
207+ * have restrictions on supported key types, sizes, policies and operations
208+ * and may have different performance characteristics.
209+ * - \c 2-0x7fffff: other locations defined by a PSA specification.
210+ * The PSA Cryptography API does not currently assign any meaning to these
211+ * locations, but future versions of this specification or other PSA
212+ * specifications may do so.
213+ * - \c 0x800000-0xffffff: vendor-defined locations.
214+ * No PSA specification will assign a meaning to locations in this range.
215+ *
216+ * \note Key location indicators are 24-bit values. Key management
217+ * interfaces operate on lifetimes (type ::psa_key_lifetime_t) which
218+ * encode the location as the upper 24 bits of a 32-bit value.
219+ */
220+ typedef uint32_t psa_key_location_t ;
221+
123222/** Encoding of identifiers of persistent keys.
124223 *
125224 * - Applications may freely choose key identifiers in the range
0 commit comments