You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -81,12 +81,17 @@ When a key is used in a cryptographic operation, the application must supply the
81
81
Key usage flags
82
82
---------------
83
83
84
-
The usage flags are encoded in a bitmask, which has the type `psa_key_usage_t`. Four kinds of usage flag can be specified:
84
+
The usage flags are encoded in a bitmask, which has the type `psa_key_usage_t`. There are two kinds of usage flag:
85
85
86
-
* The extractable flag `PSA_KEY_USAGE_EXPORT` determines whether the key material can be extracted from the cryptoprocessor, or copied outside of its current security boundary.
87
-
* The copyable flag `PSA_KEY_USAGE_COPY` determines whether the key material can be copied into a new key, which can have a different lifetime or a more restrictive policy.
88
-
* The cacheable flag `PSA_KEY_USAGE_CACHE` determines whether the implementation is permitted to retain non-essential copies of the key material in RAM. This policy only applies to persistent keys. See also :secref:`key-material`.
89
-
* The following usage flags determine whether the corresponding operations are permitted with the key:
86
+
1. Key-management usage flags.
87
+
88
+
- The extractable flag `PSA_KEY_USAGE_EXPORT` determines whether the key material can be extracted from the cryptoprocessor, or copied outside of its current security boundary.
89
+
- The copyable flag `PSA_KEY_USAGE_COPY` determines whether the key material can be copied into a new key, which can have a different lifetime or a more restrictive policy.
90
+
- The cacheable flag `PSA_KEY_USAGE_CACHE` determines whether the implementation is permitted to retain non-essential copies of the key material in RAM. This policy only applies to persistent keys. See also :secref:`key-material`.
91
+
92
+
2. Cryptographic-operation usage flags.
93
+
94
+
The following usage flags determine whether the corresponding cryptographic operations are permitted with the key:
90
95
91
96
- `PSA_KEY_USAGE_ENCRYPT`
92
97
- `PSA_KEY_USAGE_DECRYPT`
@@ -97,6 +102,8 @@ The usage flags are encoded in a bitmask, which has the type `psa_key_usage_t`.
97
102
- `PSA_KEY_USAGE_DERIVE`
98
103
- `PSA_KEY_USAGE_VERIFY_DERIVATION`
99
104
105
+
The flag `PSA_KEY_USAGE_DERIVE_PUBLIC` is used in the function `psa_check_key_usage()` to query if a key can be used for the public role in the specified algorithm.
106
+
100
107
.. typedef:: uint32_t psa_key_usage_t
101
108
102
109
.. summary::
@@ -108,7 +115,7 @@ The usage flags are encoded in a bitmask, which has the type `psa_key_usage_t`.
108
115
.. summary::
109
116
Permission to export the key.
110
117
111
-
This flag permits a key to be moved outside of the security boundary of its current storage location. In particular:
118
+
This key-management usage flag permits a key to be moved outside of the security boundary of its current storage location. In particular:
112
119
113
120
* This flag is required to export a key from the cryptoprocessor using `psa_export_key()`. A public key or the public part of a key pair can always be exported regardless of the value of this permission flag.
114
121
@@ -122,7 +129,7 @@ The usage flags are encoded in a bitmask, which has the type `psa_key_usage_t`.
122
129
.. summary::
123
130
Permission to copy the key.
124
131
125
-
This flag is required to make a copy of a key using `psa_copy_key()`.
132
+
This key-management usage flag is required to make a copy of a key using `psa_copy_key()`.
126
133
127
134
For a key lifetime that corresponds to a secure element location that enforces the non-exportability of keys, copying a key outside the secure element also requires the usage flag `PSA_KEY_USAGE_EXPORT`. Copying the key within the secure element is permitted with just `PSA_KEY_USAGE_COPY`, if the secure element supports it. For keys with the lifetime `PSA_KEY_LIFETIME_VOLATILE` or `PSA_KEY_LIFETIME_PERSISTENT`, the usage flag `PSA_KEY_USAGE_COPY` is sufficient to permit the copy.
128
135
@@ -132,7 +139,7 @@ The usage flags are encoded in a bitmask, which has the type `psa_key_usage_t`.
132
139
.. summary::
133
140
Permission for the implementation to cache the key.
134
141
135
-
This flag permits the implementation to make additional copies of the key material that are not in storage and not for the purpose of an ongoing operation. Applications can use it as a hint for the cryptoprocessor, to keep a copy of the key around for repeated access.
142
+
This key-management usage flag permits the implementation to make additional copies of the key material that are not in storage and not for the purpose of an ongoing operation. Applications can use it as a hint for the cryptoprocessor, to keep a copy of the key around for repeated access.
136
143
137
144
An application can request that cached key material is removed from memory by calling `psa_purge_key()`.
138
145
@@ -153,7 +160,7 @@ The usage flags are encoded in a bitmask, which has the type `psa_key_usage_t`.
153
160
.. summary::
154
161
Permission to encrypt a message, or perform key encapsulation, with the key.
155
162
156
-
This flag is required to use the key in a symmetric encryption operation, in an AEAD encryption-and-authentication operation, in an asymmetric encryption operation, or in a key-encapsulation operation. The flag must be present on keys used with the following APIs:
163
+
This cryptographic-operation usage flag is required to use the key in a symmetric encryption operation, in an AEAD encryption-and-authentication operation, in an asymmetric encryption operation, or in a key-encapsulation operation. The flag must be present on keys used with the following APIs:
157
164
158
165
* `psa_cipher_encrypt()`
159
166
* `psa_cipher_encrypt_setup()`
@@ -170,7 +177,7 @@ The usage flags are encoded in a bitmask, which has the type `psa_key_usage_t`.
170
177
.. summary::
171
178
Permission to decrypt a message, or perform key decapsulation, with the key.
172
179
173
-
This flag is required to use the key in a symmetric decryption operation, in an AEAD decryption-and-verification operation, in an asymmetric decryption operation, or in a key-decapsulation operation. The flag must be present on keys used with the following APIs:
180
+
This cryptographic-operation usage flag is required to use the key in a symmetric decryption operation, in an AEAD decryption-and-verification operation, in an asymmetric decryption operation, or in a key-decapsulation operation. The flag must be present on keys used with the following APIs:
174
181
175
182
* `psa_cipher_decrypt()`
176
183
* `psa_cipher_decrypt_setup()`
@@ -187,7 +194,7 @@ The usage flags are encoded in a bitmask, which has the type `psa_key_usage_t`.
187
194
.. summary::
188
195
Permission to sign a message with the key.
189
196
190
-
This flag is required to use the key in a MAC calculation operation, or in an asymmetric message signature operation. The flag must be present on keys used with the following APIs:
197
+
This cryptographic-operation usage flag is required to use the key in a MAC calculation operation, or in an asymmetric message signature operation. The flag must be present on keys used with the following APIs:
191
198
192
199
* `psa_mac_compute()`
193
200
* `psa_mac_sign_setup()`
@@ -201,7 +208,7 @@ The usage flags are encoded in a bitmask, which has the type `psa_key_usage_t`.
201
208
.. summary::
202
209
Permission to verify a message signature with the key.
203
210
204
-
This flag is required to use the key in a MAC verification operation, or in an asymmetric message signature verification operation. The flag must be present on keys used with the following APIs:
211
+
This cryptographic-operation usage flag is required to use the key in a MAC verification operation, or in an asymmetric message signature verification operation. The flag must be present on keys used with the following APIs:
205
212
206
213
* `psa_mac_verify()`
207
214
* `psa_mac_verify_setup()`
@@ -215,7 +222,7 @@ The usage flags are encoded in a bitmask, which has the type `psa_key_usage_t`.
215
222
.. summary::
216
223
Permission to sign a message hash with the key.
217
224
218
-
This flag is required to use the key to sign a pre-computed message hash in an asymmetric signature operation. The flag must be present on keys used with the following APIs:
225
+
This cryptographic-operation usage flag is required to use the key to sign a pre-computed message hash in an asymmetric signature operation. The flag must be present on keys used with the following APIs:
219
226
220
227
* `psa_sign_hash()`
221
228
@@ -229,7 +236,7 @@ The usage flags are encoded in a bitmask, which has the type `psa_key_usage_t`.
229
236
.. summary::
230
237
Permission to verify a message hash with the key.
231
238
232
-
This flag is required to use the key to verify a pre-computed message hash in an asymmetric signature verification operation. The flag must be present on keys used with the following APIs:
239
+
This cryptographic-operation usage flag is required to use the key to verify a pre-computed message hash in an asymmetric signature verification operation. The flag must be present on keys used with the following APIs:
233
240
234
241
* `psa_verify_hash()`
235
242
@@ -243,7 +250,7 @@ The usage flags are encoded in a bitmask, which has the type `psa_key_usage_t`.
243
250
.. summary::
244
251
Permission to derive other keys or produce a password hash from this key.
245
252
246
-
This flag is required to use the key for derivation in a key-derivation operation, or in a key-agreement operation.
253
+
This cryptographic-operation usage flag is required to use the key for derivation in a key-derivation operation, or in a key-agreement operation.
247
254
248
255
This flag must be present on keys used with the following APIs:
249
256
@@ -261,12 +268,32 @@ The usage flags are encoded in a bitmask, which has the type `psa_key_usage_t`.
261
268
262
269
.. versionadded:: 1.1
263
270
264
-
This flag is required to use the key for verification in a key-derivation operation.
271
+
This cryptographic-operation usage flag is required to use the key for verification in a key-derivation operation.
265
272
266
273
This flag must be present on keys used with `psa_key_derivation_verify_key()`.
267
274
268
275
If this flag is present on all keys used in calls to `psa_key_derivation_input_key()` for a key-derivation operation, then it permits calling `psa_key_derivation_verify_bytes()` or `psa_key_derivation_verify_key()` at the end of the operation.
269
276
277
+
.. macro:: PSA_KEY_USAGE_DERIVE_PUBLIC
278
+
:definition: ((psa_key_usage_t)0x00000080)
279
+
280
+
.. summary::
281
+
Used in the `psa_check_key_usage()` function to determine if the key can be used in the public key role in a key-agreement or a PAKE operation.
282
+
283
+
.. versionadded:: 1.4
284
+
285
+
This cryptographic-operation usage flag is only used with the `psa_check_key_usage()` function.
286
+
This flag is not currently checked when performing any cryptographic operation.
287
+
288
+
For example, calling `psa_check_key_usage()` with `PSA_KEY_USAGE_DERIVE_PUBLIC` and with:
289
+
290
+
* `PSA_ALG_ECDH` checks that the key can be used as the public share in the ECDH key agreement.
291
+
There are no checks on permissions as the key share is provided in a buffer.
292
+
* `PSA_ALG_SPAKE2P_HMAC` will check that the key can be used in the Verifier role in the SPAKE2+ algorithm.
293
+
The key must have the `PSA_KEY_USAGE_DERIVE` permission.
294
+
* `PSA_ALG_HKDF` is invalid, as there is no such role in single-key derivation algorithms.
295
+
296
+
270
297
.. function:: psa_set_key_usage_flags
271
298
272
299
.. summary::
@@ -302,3 +329,80 @@ The usage flags are encoded in a bitmask, which has the type `psa_key_usage_t`.
302
329
.. admonition:: Implementation note
303
330
304
331
This is a simple accessor function that is not required to validate its inputs. It can be efficiently implemented as a ``static inline`` function or a function-like-macro.
332
+
333
+
.. function:: psa_check_key_usage
334
+
335
+
.. summary::
336
+
Query the capability of a key.
337
+
338
+
.. versionadded:: 1.4
339
+
340
+
.. param:: psa_key_id_t key
341
+
Identifier of the key to check.
342
+
.. param:: psa_algorithm_t alg
343
+
An algorithm identifier: a value of type `psa_algorithm_t`.
344
+
.. param:: psa_key_usage_t usage
345
+
A single ``PSA_KEY_USAGE_xxx`` flag.
346
+
347
+
.. return:: psa_status_t
348
+
349
+
.. retval:: PSA_SUCCESS
350
+
``key`` can be used for the requested operation on this implementation.
351
+
.. retval:: PSA_ERROR_INVALID_ARGUMENT
352
+
The following conditions can result in this error:
353
+
354
+
* ``usage`` is a key-management usage flag and ``alg`` is not `PSA_ALG_NONE`.
355
+
* ``usage`` is a cryptographic-operation usage flag and ``alg`` is not a valid, specific algorithm.
356
+
A 'specific algorithm' is one that is neither `PSA_ALG_NONE` nor a wildcard algorithm.
357
+
* ``usage`` is not a valid role for algorithm ``alg``.
358
+
* ``key`` is not compatible with ``alg`` and ``usage``.
359
+
.. retval: PSA_ERROR_INVALID_HANDLE:
360
+
``key`` is not a valid key identifier.
361
+
.. retval: PSA_ERROR_NOT_PERMITTED
362
+
``key`` does not permit the requested usage or algorithm.
363
+
.. retval:: PSA_ERROR_NOT_SUPPORTED
364
+
The following conditions can result in this error:
365
+
366
+
* The implementation does not support algorithm ``alg``.
367
+
* The implementation does not support using ``key`` with the operation associated with ``alg`` and ``usage``.
368
+
.. retval:: PSA_ERROR_INSUFFICIENT_MEMORY
369
+
.. retval:: PSA_ERROR_COMMUNICATION_FAILURE
370
+
.. retval:: PSA_ERROR_CORRUPTION_DETECTED
371
+
.. retval:: PSA_ERROR_STORAGE_FAILURE
372
+
.. retval:: PSA_ERROR_DATA_CORRUPT
373
+
.. retval:: PSA_ERROR_DATA_INVALID
374
+
.. retval:: PSA_ERROR_BAD_STATE
375
+
The library requires initializing by a call to `psa_crypto_init()`.
376
+
377
+
This function reports whether the implementation supports the use of a key with the operation associated with a provided algorithm and usage.
378
+
This function does not attempt to perform the operation.
379
+
380
+
If ``usage`` is a key-management usage flag, then:
381
+
382
+
* ``alg`` must be `PSA_ALG_NONE`.
383
+
* ``key`` must exist, and permit the requested usage flag.
384
+
385
+
If ``usage`` is a cryptographic-operation usage flag, then:
386
+
387
+
* ``alg`` must be a valid, fully specified algorithm, and not a wildcard.
388
+
For example:
389
+
390
+
- :code:`PSA_ALG_ECDSA(PSA_ALG_ANY_HASH)` is invalid as it is a wildcard algorithm.
391
+
- :code:`PSA_ALG_AEAD_WITH_SHORTENED_TAG(PSA_ALG_GCM, 9)` is invalid as it has an invalid tag-length for GCM.
392
+
- :code:`PSA_ALG_SPAKE2P_HMAC(PSA_ALG_SHA_1)` is invalid as SPAKE2+ does have SHA-1 in any cipher-suite.
393
+
* ``usage`` must identify a valid role within the algorithm.
394
+
For example, if :code:`alg == PSA_ALG_GCM`, the ``usage`` must be either `PSA_KEY_USAGE_ENCRYPT` or `PSA_KEY_USAGE_DECRYPT`, as these are the key-usage policy flags for AEAD functions.
395
+
* ``key`` must exist, have a type and size that are compatible with the operation associated with ``alg`` and ``usage``, and have the required permission for the algorithm and usage.
396
+
For example:
397
+
398
+
- An Edwards25519 key pair is not compatible with :code:`PSA_ALG_ECDSA(PSA_ALG_SHA_256)`.
399
+
- A ``512``-bit RSA key pair is not compatible with :code:`PSA_ALG_RSA_OAEP(PSA_ALG_SHA_512)` as the algorithm requires a larger key size.
400
+
- A ``512``-bit AES key (double-length key for use in AES-256-XTS) is not compatible with `PSA_ALG_CTR`.
401
+
402
+
.. note::
403
+
For the key pair or public key of a valid type in a key agreement function, this function returns :code:`PSA_SUCCESS` for the usage `PSA_KEY_USAGE_DERIVE_PUBLIC`, regardless of the key's policy.
404
+
This is because the corresponding API functions take a key buffer as input, not a key object, and the key data can extracted by calling `psa_export_public_key()`, which does not require any usage flag.
405
+
406
+
.. admonition:: Implementation note
407
+
408
+
The intended behavior of this function is to include any check that can be made using the accessible key attributes, but without requiring logic or arithmetic using the key material.
0 commit comments