blob: d83ad1be9ceb1a21039bcced6d383ddc27aa409f [file] [log] [blame]
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001/**
2 * \file psa/crypto_values.h
3 *
4 * \brief PSA cryptography module: macros to build and analyze integer values.
5 *
6 * \note This file may not be included directly. Applications must
7 * include psa/crypto.h. Drivers must include the appropriate driver
8 * header file.
9 *
10 * This file contains portable definitions of macros to build and analyze
11 * values of integral types that encode properties of cryptographic keys,
12 * designations of cryptographic algorithms, and error codes returned by
13 * the library.
14 *
15 * This header file only defines preprocessor macros.
16 */
17/*
18 * Copyright (C) 2018, ARM Limited, All Rights Reserved
19 * SPDX-License-Identifier: Apache-2.0
20 *
21 * Licensed under the Apache License, Version 2.0 (the "License"); you may
22 * not use this file except in compliance with the License.
23 * You may obtain a copy of the License at
24 *
25 * http://www.apache.org/licenses/LICENSE-2.0
26 *
27 * Unless required by applicable law or agreed to in writing, software
28 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
29 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30 * See the License for the specific language governing permissions and
31 * limitations under the License.
32 *
33 * This file is part of mbed TLS (https://tls.mbed.org)
34 */
35
36#ifndef PSA_CRYPTO_VALUES_H
37#define PSA_CRYPTO_VALUES_H
38
39/** \defgroup error Error codes
40 * @{
41 */
42
43#if !defined(PSA_SUCCESS)
44/* If PSA_SUCCESS is defined, assume that PSA crypto is being used
45 * together with PSA IPC, which also defines the identifier
46 * PSA_SUCCESS. We must not define PSA_SUCCESS ourselves in that case;
47 * the other error code names don't clash. This is a temporary hack
48 * until we unify error reporting in PSA IPC and PSA crypto.
49 *
50 * Note that psa_defs.h must be included before this header!
51 */
52/** The action was completed successfully. */
53#define PSA_SUCCESS ((psa_status_t)0)
54#endif /* !defined(PSA_SUCCESS) */
55
56/** An error occurred that does not correspond to any defined
57 * failure cause.
58 *
59 * Implementations may use this error code if none of the other standard
60 * error codes are applicable. */
61#define PSA_ERROR_UNKNOWN_ERROR ((psa_status_t)1)
62
63/** The requested operation or a parameter is not supported
64 * by this implementation.
65 *
66 * Implementations should return this error code when an enumeration
67 * parameter such as a key type, algorithm, etc. is not recognized.
68 * If a combination of parameters is recognized and identified as
69 * not valid, return #PSA_ERROR_INVALID_ARGUMENT instead. */
70#define PSA_ERROR_NOT_SUPPORTED ((psa_status_t)2)
71
72/** The requested action is denied by a policy.
73 *
74 * Implementations should return this error code when the parameters
75 * are recognized as valid and supported, and a policy explicitly
76 * denies the requested operation.
77 *
78 * If a subset of the parameters of a function call identify a
79 * forbidden operation, and another subset of the parameters are
80 * not valid or not supported, it is unspecified whether the function
81 * returns #PSA_ERROR_NOT_PERMITTED, #PSA_ERROR_NOT_SUPPORTED or
82 * #PSA_ERROR_INVALID_ARGUMENT. */
83#define PSA_ERROR_NOT_PERMITTED ((psa_status_t)3)
84
85/** An output buffer is too small.
86 *
87 * Applications can call the \c PSA_xxx_SIZE macro listed in the function
88 * description to determine a sufficient buffer size.
89 *
90 * Implementations should preferably return this error code only
91 * in cases when performing the operation with a larger output
92 * buffer would succeed. However implementations may return this
93 * error if a function has invalid or unsupported parameters in addition
94 * to the parameters that determine the necessary output buffer size. */
95#define PSA_ERROR_BUFFER_TOO_SMALL ((psa_status_t)4)
96
97/** A slot is occupied, but must be empty to carry out the
98 * requested action.
99 *
100 * If a handle is invalid, it does not designate an occupied slot.
101 * The error for an invalid handle is #PSA_ERROR_INVALID_HANDLE.
102 */
103#define PSA_ERROR_OCCUPIED_SLOT ((psa_status_t)5)
104
105/** A slot is empty, but must be occupied to carry out the
106 * requested action.
107 *
108 * If a handle is invalid, it does not designate an empty slot.
109 * The error for an invalid handle is #PSA_ERROR_INVALID_HANDLE.
110 */
111#define PSA_ERROR_EMPTY_SLOT ((psa_status_t)6)
112
113/** The requested action cannot be performed in the current state.
114 *
115 * Multipart operations return this error when one of the
116 * functions is called out of sequence. Refer to the function
117 * descriptions for permitted sequencing of functions.
118 *
119 * Implementations shall not return this error code to indicate
120 * that a key slot is occupied when it needs to be free or vice versa,
121 * but shall return #PSA_ERROR_OCCUPIED_SLOT or #PSA_ERROR_EMPTY_SLOT
122 * as applicable. */
123#define PSA_ERROR_BAD_STATE ((psa_status_t)7)
124
125/** The parameters passed to the function are invalid.
126 *
127 * Implementations may return this error any time a parameter or
128 * combination of parameters are recognized as invalid.
129 *
130 * Implementations shall not return this error code to indicate
131 * that a key slot is occupied when it needs to be free or vice versa,
132 * but shall return #PSA_ERROR_OCCUPIED_SLOT or #PSA_ERROR_EMPTY_SLOT
133 * as applicable.
134 *
135 * Implementation shall not return this error code to indicate that a
136 * key handle is invalid, but shall return #PSA_ERROR_INVALID_HANDLE
137 * instead.
138 */
139#define PSA_ERROR_INVALID_ARGUMENT ((psa_status_t)8)
140
141/** There is not enough runtime memory.
142 *
143 * If the action is carried out across multiple security realms, this
144 * error can refer to available memory in any of the security realms. */
145#define PSA_ERROR_INSUFFICIENT_MEMORY ((psa_status_t)9)
146
147/** There is not enough persistent storage.
148 *
149 * Functions that modify the key storage return this error code if
150 * there is insufficient storage space on the host media. In addition,
151 * many functions that do not otherwise access storage may return this
152 * error code if the implementation requires a mandatory log entry for
153 * the requested action and the log storage space is full. */
154#define PSA_ERROR_INSUFFICIENT_STORAGE ((psa_status_t)10)
155
156/** There was a communication failure inside the implementation.
157 *
158 * This can indicate a communication failure between the application
159 * and an external cryptoprocessor or between the cryptoprocessor and
160 * an external volatile or persistent memory. A communication failure
161 * may be transient or permanent depending on the cause.
162 *
163 * \warning If a function returns this error, it is undetermined
164 * whether the requested action has completed or not. Implementations
165 * should return #PSA_SUCCESS on successful completion whenver
166 * possible, however functions may return #PSA_ERROR_COMMUNICATION_FAILURE
167 * if the requested action was completed successfully in an external
168 * cryptoprocessor but there was a breakdown of communication before
169 * the cryptoprocessor could report the status to the application.
170 */
171#define PSA_ERROR_COMMUNICATION_FAILURE ((psa_status_t)11)
172
173/** There was a storage failure that may have led to data loss.
174 *
175 * This error indicates that some persistent storage is corrupted.
176 * It should not be used for a corruption of volatile memory
177 * (use #PSA_ERROR_TAMPERING_DETECTED), for a communication error
178 * between the cryptoprocessor and its external storage (use
179 * #PSA_ERROR_COMMUNICATION_FAILURE), or when the storage is
180 * in a valid state but is full (use #PSA_ERROR_INSUFFICIENT_STORAGE).
181 *
182 * Note that a storage failure does not indicate that any data that was
183 * previously read is invalid. However this previously read data may no
184 * longer be readable from storage.
185 *
186 * When a storage failure occurs, it is no longer possible to ensure
187 * the global integrity of the keystore. Depending on the global
188 * integrity guarantees offered by the implementation, access to other
189 * data may or may not fail even if the data is still readable but
190 * its integrity canont be guaranteed.
191 *
192 * Implementations should only use this error code to report a
193 * permanent storage corruption. However application writers should
194 * keep in mind that transient errors while reading the storage may be
195 * reported using this error code. */
196#define PSA_ERROR_STORAGE_FAILURE ((psa_status_t)12)
197
198/** A hardware failure was detected.
199 *
200 * A hardware failure may be transient or permanent depending on the
201 * cause. */
202#define PSA_ERROR_HARDWARE_FAILURE ((psa_status_t)13)
203
204/** A tampering attempt was detected.
205 *
206 * If an application receives this error code, there is no guarantee
207 * that previously accessed or computed data was correct and remains
208 * confidential. Applications should not perform any security function
209 * and should enter a safe failure state.
210 *
211 * Implementations may return this error code if they detect an invalid
212 * state that cannot happen during normal operation and that indicates
213 * that the implementation's security guarantees no longer hold. Depending
214 * on the implementation architecture and on its security and safety goals,
215 * the implementation may forcibly terminate the application.
216 *
217 * This error code is intended as a last resort when a security breach
218 * is detected and it is unsure whether the keystore data is still
219 * protected. Implementations shall only return this error code
220 * to report an alarm from a tampering detector, to indicate that
221 * the confidentiality of stored data can no longer be guaranteed,
222 * or to indicate that the integrity of previously returned data is now
223 * considered compromised. Implementations shall not use this error code
224 * to indicate a hardware failure that merely makes it impossible to
225 * perform the requested operation (use #PSA_ERROR_COMMUNICATION_FAILURE,
226 * #PSA_ERROR_STORAGE_FAILURE, #PSA_ERROR_HARDWARE_FAILURE,
227 * #PSA_ERROR_INSUFFICIENT_ENTROPY or other applicable error code
228 * instead).
229 *
230 * This error indicates an attack against the application. Implementations
231 * shall not return this error code as a consequence of the behavior of
232 * the application itself. */
233#define PSA_ERROR_TAMPERING_DETECTED ((psa_status_t)14)
234
235/** There is not enough entropy to generate random data needed
236 * for the requested action.
237 *
238 * This error indicates a failure of a hardware random generator.
239 * Application writers should note that this error can be returned not
240 * only by functions whose purpose is to generate random data, such
241 * as key, IV or nonce generation, but also by functions that execute
242 * an algorithm with a randomized result, as well as functions that
243 * use randomization of intermediate computations as a countermeasure
244 * to certain attacks.
245 *
246 * Implementations should avoid returning this error after psa_crypto_init()
247 * has succeeded. Implementations should generate sufficient
248 * entropy during initialization and subsequently use a cryptographically
249 * secure pseudorandom generator (PRNG). However implementations may return
250 * this error at any time if a policy requires the PRNG to be reseeded
251 * during normal operation. */
252#define PSA_ERROR_INSUFFICIENT_ENTROPY ((psa_status_t)15)
253
254/** The signature, MAC or hash is incorrect.
255 *
256 * Verification functions return this error if the verification
257 * calculations completed successfully, and the value to be verified
258 * was determined to be incorrect.
259 *
260 * If the value to verify has an invalid size, implementations may return
261 * either #PSA_ERROR_INVALID_ARGUMENT or #PSA_ERROR_INVALID_SIGNATURE. */
262#define PSA_ERROR_INVALID_SIGNATURE ((psa_status_t)16)
263
264/** The decrypted padding is incorrect.
265 *
266 * \warning In some protocols, when decrypting data, it is essential that
267 * the behavior of the application does not depend on whether the padding
268 * is correct, down to precise timing. Applications should prefer
269 * protocols that use authenticated encryption rather than plain
270 * encryption. If the application must perform a decryption of
271 * unauthenticated data, the application writer should take care not
272 * to reveal whether the padding is invalid.
273 *
274 * Implementations should strive to make valid and invalid padding
275 * as close as possible to indistinguishable to an external observer.
276 * In particular, the timing of a decryption operation should not
277 * depend on the validity of the padding. */
278#define PSA_ERROR_INVALID_PADDING ((psa_status_t)17)
279
280/** The generator has insufficient capacity left.
281 *
282 * Once a function returns this error, attempts to read from the
283 * generator will always return this error. */
284#define PSA_ERROR_INSUFFICIENT_CAPACITY ((psa_status_t)18)
285
286/** The key handle is not valid.
287 */
288#define PSA_ERROR_INVALID_HANDLE ((psa_status_t)19)
289
290/**@}*/
291
292/** \defgroup crypto_types Key and algorithm types
293 * @{
294 */
295
296/** An invalid key type value.
297 *
298 * Zero is not the encoding of any key type.
299 */
300#define PSA_KEY_TYPE_NONE ((psa_key_type_t)0x00000000)
301
302/** Vendor-defined flag
303 *
304 * Key types defined by this standard will never have the
305 * #PSA_KEY_TYPE_VENDOR_FLAG bit set. Vendors who define additional key types
306 * must use an encoding with the #PSA_KEY_TYPE_VENDOR_FLAG bit set and should
307 * respect the bitwise structure used by standard encodings whenever practical.
308 */
309#define PSA_KEY_TYPE_VENDOR_FLAG ((psa_key_type_t)0x80000000)
310
311#define PSA_KEY_TYPE_CATEGORY_MASK ((psa_key_type_t)0x70000000)
312#define PSA_KEY_TYPE_CATEGORY_SYMMETRIC ((psa_key_type_t)0x40000000)
313#define PSA_KEY_TYPE_CATEGORY_RAW ((psa_key_type_t)0x50000000)
314#define PSA_KEY_TYPE_CATEGORY_PUBLIC_KEY ((psa_key_type_t)0x60000000)
315#define PSA_KEY_TYPE_CATEGORY_KEY_PAIR ((psa_key_type_t)0x70000000)
316
317#define PSA_KEY_TYPE_CATEGORY_FLAG_PAIR ((psa_key_type_t)0x10000000)
318
319/** Whether a key type is vendor-defined. */
320#define PSA_KEY_TYPE_IS_VENDOR_DEFINED(type) \
321 (((type) & PSA_KEY_TYPE_VENDOR_FLAG) != 0)
322
323/** Whether a key type is an unstructured array of bytes.
324 *
325 * This encompasses both symmetric keys and non-key data.
326 */
327#define PSA_KEY_TYPE_IS_UNSTRUCTURED(type) \
328 (((type) & PSA_KEY_TYPE_CATEGORY_MASK & ~(psa_key_type_t)0x10000000) == \
329 PSA_KEY_TYPE_CATEGORY_SYMMETRIC)
330
331/** Whether a key type is asymmetric: either a key pair or a public key. */
332#define PSA_KEY_TYPE_IS_ASYMMETRIC(type) \
333 (((type) & PSA_KEY_TYPE_CATEGORY_MASK \
334 & ~PSA_KEY_TYPE_CATEGORY_FLAG_PAIR) == \
335 PSA_KEY_TYPE_CATEGORY_PUBLIC_KEY)
336/** Whether a key type is the public part of a key pair. */
337#define PSA_KEY_TYPE_IS_PUBLIC_KEY(type) \
338 (((type) & PSA_KEY_TYPE_CATEGORY_MASK) == PSA_KEY_TYPE_CATEGORY_PUBLIC_KEY)
339/** Whether a key type is a key pair containing a private part and a public
340 * part. */
341#define PSA_KEY_TYPE_IS_KEYPAIR(type) \
342 (((type) & PSA_KEY_TYPE_CATEGORY_MASK) == PSA_KEY_TYPE_CATEGORY_KEY_PAIR)
343/** The key pair type corresponding to a public key type.
344 *
345 * You may also pass a key pair type as \p type, it will be left unchanged.
346 *
347 * \param type A public key type or key pair type.
348 *
349 * \return The corresponding key pair type.
350 * If \p type is not a public key or a key pair,
351 * the return value is undefined.
352 */
353#define PSA_KEY_TYPE_KEYPAIR_OF_PUBLIC_KEY(type) \
354 ((type) | PSA_KEY_TYPE_CATEGORY_FLAG_PAIR)
355/** The public key type corresponding to a key pair type.
356 *
357 * You may also pass a key pair type as \p type, it will be left unchanged.
358 *
359 * \param type A public key type or key pair type.
360 *
361 * \return The corresponding public key type.
362 * If \p type is not a public key or a key pair,
363 * the return value is undefined.
364 */
365#define PSA_KEY_TYPE_PUBLIC_KEY_OF_KEYPAIR(type) \
366 ((type) & ~PSA_KEY_TYPE_CATEGORY_FLAG_PAIR)
367
368/** Raw data.
369 *
370 * A "key" of this type cannot be used for any cryptographic operation.
371 * Applications may use this type to store arbitrary data in the keystore. */
372#define PSA_KEY_TYPE_RAW_DATA ((psa_key_type_t)0x50000001)
373
374/** HMAC key.
375 *
376 * The key policy determines which underlying hash algorithm the key can be
377 * used for.
378 *
379 * HMAC keys should generally have the same size as the underlying hash.
380 * This size can be calculated with #PSA_HASH_SIZE(\c alg) where
381 * \c alg is the HMAC algorithm or the underlying hash algorithm. */
382#define PSA_KEY_TYPE_HMAC ((psa_key_type_t)0x51000000)
383
384/** A secret for key derivation.
385 *
386 * The key policy determines which key derivation algorithm the key
387 * can be used for.
388 */
389#define PSA_KEY_TYPE_DERIVE ((psa_key_type_t)0x52000000)
390
391/** Key for an cipher, AEAD or MAC algorithm based on the AES block cipher.
392 *
393 * The size of the key can be 16 bytes (AES-128), 24 bytes (AES-192) or
394 * 32 bytes (AES-256).
395 */
396#define PSA_KEY_TYPE_AES ((psa_key_type_t)0x40000001)
397
398/** Key for a cipher or MAC algorithm based on DES or 3DES (Triple-DES).
399 *
400 * The size of the key can be 8 bytes (single DES), 16 bytes (2-key 3DES) or
401 * 24 bytes (3-key 3DES).
402 *
403 * Note that single DES and 2-key 3DES are weak and strongly
404 * deprecated and should only be used to decrypt legacy data. 3-key 3DES
405 * is weak and deprecated and should only be used in legacy protocols.
406 */
407#define PSA_KEY_TYPE_DES ((psa_key_type_t)0x40000002)
408
409/** Key for an cipher, AEAD or MAC algorithm based on the
410 * Camellia block cipher. */
411#define PSA_KEY_TYPE_CAMELLIA ((psa_key_type_t)0x40000003)
412
413/** Key for the RC4 stream cipher.
414 *
415 * Note that RC4 is weak and deprecated and should only be used in
416 * legacy protocols. */
417#define PSA_KEY_TYPE_ARC4 ((psa_key_type_t)0x40000004)
418
419/** RSA public key. */
420#define PSA_KEY_TYPE_RSA_PUBLIC_KEY ((psa_key_type_t)0x60010000)
421/** RSA key pair (private and public key). */
422#define PSA_KEY_TYPE_RSA_KEYPAIR ((psa_key_type_t)0x70010000)
423/** Whether a key type is an RSA key (pair or public-only). */
424#define PSA_KEY_TYPE_IS_RSA(type) \
425 (PSA_KEY_TYPE_PUBLIC_KEY_OF_KEYPAIR(type) == PSA_KEY_TYPE_RSA_PUBLIC_KEY)
426
427/** DSA public key. */
428#define PSA_KEY_TYPE_DSA_PUBLIC_KEY ((psa_key_type_t)0x60020000)
429/** DSA key pair (private and public key). */
430#define PSA_KEY_TYPE_DSA_KEYPAIR ((psa_key_type_t)0x70020000)
431/** Whether a key type is an DSA key (pair or public-only). */
432#define PSA_KEY_TYPE_IS_DSA(type) \
433 (PSA_KEY_TYPE_PUBLIC_KEY_OF_KEYPAIR(type) == PSA_KEY_TYPE_DSA_PUBLIC_KEY)
434
435#define PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE ((psa_key_type_t)0x60030000)
436#define PSA_KEY_TYPE_ECC_KEYPAIR_BASE ((psa_key_type_t)0x70030000)
437#define PSA_KEY_TYPE_ECC_CURVE_MASK ((psa_key_type_t)0x0000ffff)
438/** Elliptic curve key pair. */
439#define PSA_KEY_TYPE_ECC_KEYPAIR(curve) \
440 (PSA_KEY_TYPE_ECC_KEYPAIR_BASE | (curve))
441/** Elliptic curve public key. */
442#define PSA_KEY_TYPE_ECC_PUBLIC_KEY(curve) \
443 (PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE | (curve))
444
445/** Whether a key type is an elliptic curve key (pair or public-only). */
446#define PSA_KEY_TYPE_IS_ECC(type) \
447 ((PSA_KEY_TYPE_PUBLIC_KEY_OF_KEYPAIR(type) & \
448 ~PSA_KEY_TYPE_ECC_CURVE_MASK) == PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE)
449#define PSA_KEY_TYPE_IS_ECC_KEYPAIR(type) \
450 (((type) & ~PSA_KEY_TYPE_ECC_CURVE_MASK) == \
451 PSA_KEY_TYPE_ECC_KEYPAIR_BASE)
452#define PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY(type) \
453 (((type) & ~PSA_KEY_TYPE_ECC_CURVE_MASK) == \
454 PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE)
455
456/** Extract the curve from an elliptic curve key type. */
457#define PSA_KEY_TYPE_GET_CURVE(type) \
458 ((psa_ecc_curve_t) (PSA_KEY_TYPE_IS_ECC(type) ? \
459 ((type) & PSA_KEY_TYPE_ECC_CURVE_MASK) : \
460 0))
461
462/* The encoding of curve identifiers is currently aligned with the
463 * TLS Supported Groups Registry (formerly known as the
464 * TLS EC Named Curve Registry)
465 * https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-8
466 * The values are defined by RFC 8422 and RFC 7027. */
467#define PSA_ECC_CURVE_SECT163K1 ((psa_ecc_curve_t) 0x0001)
468#define PSA_ECC_CURVE_SECT163R1 ((psa_ecc_curve_t) 0x0002)
469#define PSA_ECC_CURVE_SECT163R2 ((psa_ecc_curve_t) 0x0003)
470#define PSA_ECC_CURVE_SECT193R1 ((psa_ecc_curve_t) 0x0004)
471#define PSA_ECC_CURVE_SECT193R2 ((psa_ecc_curve_t) 0x0005)
472#define PSA_ECC_CURVE_SECT233K1 ((psa_ecc_curve_t) 0x0006)
473#define PSA_ECC_CURVE_SECT233R1 ((psa_ecc_curve_t) 0x0007)
474#define PSA_ECC_CURVE_SECT239K1 ((psa_ecc_curve_t) 0x0008)
475#define PSA_ECC_CURVE_SECT283K1 ((psa_ecc_curve_t) 0x0009)
476#define PSA_ECC_CURVE_SECT283R1 ((psa_ecc_curve_t) 0x000a)
477#define PSA_ECC_CURVE_SECT409K1 ((psa_ecc_curve_t) 0x000b)
478#define PSA_ECC_CURVE_SECT409R1 ((psa_ecc_curve_t) 0x000c)
479#define PSA_ECC_CURVE_SECT571K1 ((psa_ecc_curve_t) 0x000d)
480#define PSA_ECC_CURVE_SECT571R1 ((psa_ecc_curve_t) 0x000e)
481#define PSA_ECC_CURVE_SECP160K1 ((psa_ecc_curve_t) 0x000f)
482#define PSA_ECC_CURVE_SECP160R1 ((psa_ecc_curve_t) 0x0010)
483#define PSA_ECC_CURVE_SECP160R2 ((psa_ecc_curve_t) 0x0011)
484#define PSA_ECC_CURVE_SECP192K1 ((psa_ecc_curve_t) 0x0012)
485#define PSA_ECC_CURVE_SECP192R1 ((psa_ecc_curve_t) 0x0013)
486#define PSA_ECC_CURVE_SECP224K1 ((psa_ecc_curve_t) 0x0014)
487#define PSA_ECC_CURVE_SECP224R1 ((psa_ecc_curve_t) 0x0015)
488#define PSA_ECC_CURVE_SECP256K1 ((psa_ecc_curve_t) 0x0016)
489#define PSA_ECC_CURVE_SECP256R1 ((psa_ecc_curve_t) 0x0017)
490#define PSA_ECC_CURVE_SECP384R1 ((psa_ecc_curve_t) 0x0018)
491#define PSA_ECC_CURVE_SECP521R1 ((psa_ecc_curve_t) 0x0019)
492#define PSA_ECC_CURVE_BRAINPOOL_P256R1 ((psa_ecc_curve_t) 0x001a)
493#define PSA_ECC_CURVE_BRAINPOOL_P384R1 ((psa_ecc_curve_t) 0x001b)
494#define PSA_ECC_CURVE_BRAINPOOL_P512R1 ((psa_ecc_curve_t) 0x001c)
495#define PSA_ECC_CURVE_CURVE25519 ((psa_ecc_curve_t) 0x001d)
496#define PSA_ECC_CURVE_CURVE448 ((psa_ecc_curve_t) 0x001e)
497
498/** The block size of a block cipher.
499 *
500 * \param type A cipher key type (value of type #psa_key_type_t).
501 *
502 * \return The block size for a block cipher, or 1 for a stream cipher.
503 * The return value is undefined if \p type is not a supported
504 * cipher key type.
505 *
506 * \note It is possible to build stream cipher algorithms on top of a block
507 * cipher, for example CTR mode (#PSA_ALG_CTR).
508 * This macro only takes the key type into account, so it cannot be
509 * used to determine the size of the data that #psa_cipher_update()
510 * might buffer for future processing in general.
511 *
512 * \note This macro returns a compile-time constant if its argument is one.
513 *
514 * \warning This macro may evaluate its argument multiple times.
515 */
516#define PSA_BLOCK_CIPHER_BLOCK_SIZE(type) \
517 ( \
518 (type) == PSA_KEY_TYPE_AES ? 16 : \
519 (type) == PSA_KEY_TYPE_DES ? 8 : \
520 (type) == PSA_KEY_TYPE_CAMELLIA ? 16 : \
521 (type) == PSA_KEY_TYPE_ARC4 ? 1 : \
522 0)
523
524#define PSA_ALG_VENDOR_FLAG ((psa_algorithm_t)0x80000000)
525#define PSA_ALG_CATEGORY_MASK ((psa_algorithm_t)0x7f000000)
526#define PSA_ALG_CATEGORY_HASH ((psa_algorithm_t)0x01000000)
527#define PSA_ALG_CATEGORY_MAC ((psa_algorithm_t)0x02000000)
528#define PSA_ALG_CATEGORY_CIPHER ((psa_algorithm_t)0x04000000)
529#define PSA_ALG_CATEGORY_AEAD ((psa_algorithm_t)0x06000000)
530#define PSA_ALG_CATEGORY_SIGN ((psa_algorithm_t)0x10000000)
531#define PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION ((psa_algorithm_t)0x12000000)
532#define PSA_ALG_CATEGORY_KEY_AGREEMENT ((psa_algorithm_t)0x22000000)
533#define PSA_ALG_CATEGORY_KEY_DERIVATION ((psa_algorithm_t)0x30000000)
534#define PSA_ALG_CATEGORY_KEY_SELECTION ((psa_algorithm_t)0x31000000)
535
536#define PSA_ALG_IS_VENDOR_DEFINED(alg) \
537 (((alg) & PSA_ALG_VENDOR_FLAG) != 0)
538
539/** Whether the specified algorithm is a hash algorithm.
540 *
541 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
542 *
543 * \return 1 if \p alg is a hash algorithm, 0 otherwise.
544 * This macro may return either 0 or 1 if \p alg is not a supported
545 * algorithm identifier.
546 */
547#define PSA_ALG_IS_HASH(alg) \
548 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_HASH)
549
550/** Whether the specified algorithm is a MAC algorithm.
551 *
552 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
553 *
554 * \return 1 if \p alg is a MAC algorithm, 0 otherwise.
555 * This macro may return either 0 or 1 if \p alg is not a supported
556 * algorithm identifier.
557 */
558#define PSA_ALG_IS_MAC(alg) \
559 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_MAC)
560
561/** Whether the specified algorithm is a symmetric cipher algorithm.
562 *
563 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
564 *
565 * \return 1 if \p alg is a symmetric cipher algorithm, 0 otherwise.
566 * This macro may return either 0 or 1 if \p alg is not a supported
567 * algorithm identifier.
568 */
569#define PSA_ALG_IS_CIPHER(alg) \
570 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_CIPHER)
571
572/** Whether the specified algorithm is an authenticated encryption
573 * with associated data (AEAD) algorithm.
574 *
575 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
576 *
577 * \return 1 if \p alg is an AEAD algorithm, 0 otherwise.
578 * This macro may return either 0 or 1 if \p alg is not a supported
579 * algorithm identifier.
580 */
581#define PSA_ALG_IS_AEAD(alg) \
582 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_AEAD)
583
584/** Whether the specified algorithm is a public-key signature algorithm.
585 *
586 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
587 *
588 * \return 1 if \p alg is a public-key signature algorithm, 0 otherwise.
589 * This macro may return either 0 or 1 if \p alg is not a supported
590 * algorithm identifier.
591 */
592#define PSA_ALG_IS_SIGN(alg) \
593 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_SIGN)
594
595/** Whether the specified algorithm is a public-key encryption algorithm.
596 *
597 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
598 *
599 * \return 1 if \p alg is a public-key encryption algorithm, 0 otherwise.
600 * This macro may return either 0 or 1 if \p alg is not a supported
601 * algorithm identifier.
602 */
603#define PSA_ALG_IS_ASYMMETRIC_ENCRYPTION(alg) \
604 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION)
605
606#define PSA_ALG_KEY_SELECTION_FLAG ((psa_algorithm_t)0x01000000)
607/** Whether the specified algorithm is a key agreement algorithm.
608 *
609 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
610 *
611 * \return 1 if \p alg is a key agreement algorithm, 0 otherwise.
612 * This macro may return either 0 or 1 if \p alg is not a supported
613 * algorithm identifier.
614 */
615#define PSA_ALG_IS_KEY_AGREEMENT(alg) \
616 (((alg) & PSA_ALG_CATEGORY_MASK & ~PSA_ALG_KEY_SELECTION_FLAG) == \
617 PSA_ALG_CATEGORY_KEY_AGREEMENT)
618
619/** Whether the specified algorithm is a key derivation algorithm.
620 *
621 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
622 *
623 * \return 1 if \p alg is a key derivation algorithm, 0 otherwise.
624 * This macro may return either 0 or 1 if \p alg is not a supported
625 * algorithm identifier.
626 */
627#define PSA_ALG_IS_KEY_DERIVATION(alg) \
628 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_KEY_DERIVATION)
629
630/** Whether the specified algorithm is a key selection algorithm.
631 *
632 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
633 *
634 * \return 1 if \p alg is a key selection algorithm, 0 otherwise.
635 * This macro may return either 0 or 1 if \p alg is not a supported
636 * algorithm identifier.
637 */
638#define PSA_ALG_IS_KEY_SELECTION(alg) \
639 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_KEY_SELECTION)
640
641#define PSA_ALG_HASH_MASK ((psa_algorithm_t)0x000000ff)
642#define PSA_ALG_MD2 ((psa_algorithm_t)0x01000001)
643#define PSA_ALG_MD4 ((psa_algorithm_t)0x01000002)
644#define PSA_ALG_MD5 ((psa_algorithm_t)0x01000003)
645#define PSA_ALG_RIPEMD160 ((psa_algorithm_t)0x01000004)
646#define PSA_ALG_SHA_1 ((psa_algorithm_t)0x01000005)
647/** SHA2-224 */
648#define PSA_ALG_SHA_224 ((psa_algorithm_t)0x01000008)
649/** SHA2-256 */
650#define PSA_ALG_SHA_256 ((psa_algorithm_t)0x01000009)
651/** SHA2-384 */
652#define PSA_ALG_SHA_384 ((psa_algorithm_t)0x0100000a)
653/** SHA2-512 */
654#define PSA_ALG_SHA_512 ((psa_algorithm_t)0x0100000b)
655/** SHA2-512/224 */
656#define PSA_ALG_SHA_512_224 ((psa_algorithm_t)0x0100000c)
657/** SHA2-512/256 */
658#define PSA_ALG_SHA_512_256 ((psa_algorithm_t)0x0100000d)
659/** SHA3-224 */
660#define PSA_ALG_SHA3_224 ((psa_algorithm_t)0x01000010)
661/** SHA3-256 */
662#define PSA_ALG_SHA3_256 ((psa_algorithm_t)0x01000011)
663/** SHA3-384 */
664#define PSA_ALG_SHA3_384 ((psa_algorithm_t)0x01000012)
665/** SHA3-512 */
666#define PSA_ALG_SHA3_512 ((psa_algorithm_t)0x01000013)
667
668#define PSA_ALG_MAC_SUBCATEGORY_MASK ((psa_algorithm_t)0x00c00000)
669#define PSA_ALG_HMAC_BASE ((psa_algorithm_t)0x02800000)
670/** Macro to build an HMAC algorithm.
671 *
672 * For example, #PSA_ALG_HMAC(#PSA_ALG_SHA_256) is HMAC-SHA-256.
673 *
674 * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
675 * #PSA_ALG_IS_HASH(\p hash_alg) is true).
676 *
677 * \return The corresponding HMAC algorithm.
678 * \return Unspecified if \p alg is not a supported
679 * hash algorithm.
680 */
681#define PSA_ALG_HMAC(hash_alg) \
682 (PSA_ALG_HMAC_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
683
684#define PSA_ALG_HMAC_GET_HASH(hmac_alg) \
685 (PSA_ALG_CATEGORY_HASH | ((hmac_alg) & PSA_ALG_HASH_MASK))
686
687/** Whether the specified algorithm is an HMAC algorithm.
688 *
689 * HMAC is a family of MAC algorithms that are based on a hash function.
690 *
691 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
692 *
693 * \return 1 if \p alg is an HMAC algorithm, 0 otherwise.
694 * This macro may return either 0 or 1 if \p alg is not a supported
695 * algorithm identifier.
696 */
697#define PSA_ALG_IS_HMAC(alg) \
698 (((alg) & (PSA_ALG_CATEGORY_MASK | PSA_ALG_MAC_SUBCATEGORY_MASK)) == \
699 PSA_ALG_HMAC_BASE)
700
701/* In the encoding of a MAC algorithm, the bits corresponding to
702 * PSA_ALG_MAC_TRUNCATION_MASK encode the length to which the MAC is
703 * truncated. As an exception, the value 0 means the untruncated algorithm,
704 * whatever its length is. The length is encoded in 6 bits, so it can
705 * reach up to 63; the largest MAC is 64 bytes so its trivial truncation
706 * to full length is correctly encoded as 0 and any non-trivial truncation
707 * is correctly encoded as a value between 1 and 63. */
708#define PSA_ALG_MAC_TRUNCATION_MASK ((psa_algorithm_t)0x00003f00)
709#define PSA_MAC_TRUNCATION_OFFSET 8
710
711/** Macro to build a truncated MAC algorithm.
712 *
713 * A truncated MAC algorithm is identical to the corresponding MAC
714 * algorithm except that the MAC value for the truncated algorithm
715 * consists of only the first \p mac_length bytes of the MAC value
716 * for the untruncated algorithm.
717 *
718 * \note This macro may allow constructing algorithm identifiers that
719 * are not valid, either because the specified length is larger
720 * than the untruncated MAC or because the specified length is
721 * smaller than permitted by the implementation.
722 *
723 * \note It is implementation-defined whether a truncated MAC that
724 * is truncated to the same length as the MAC of the untruncated
725 * algorithm is considered identical to the untruncated algorithm
726 * for policy comparison purposes.
727 *
728 * \param alg A MAC algorithm identifier (value of type
729 * #psa_algorithm_t such that #PSA_ALG_IS_MAC(\p alg)
730 * is true). This may be a truncated or untruncated
731 * MAC algorithm.
732 * \param mac_length Desired length of the truncated MAC in bytes.
733 * This must be at most the full length of the MAC
734 * and must be at least an implementation-specified
735 * minimum. The implementation-specified minimum
736 * shall not be zero.
737 *
738 * \return The corresponding MAC algorithm with the specified
739 * length.
740 * \return Unspecified if \p alg is not a supported
741 * MAC algorithm or if \p mac_length is too small or
742 * too large for the specified MAC algorithm.
743 */
744#define PSA_ALG_TRUNCATED_MAC(alg, mac_length) \
745 (((alg) & ~PSA_ALG_MAC_TRUNCATION_MASK) | \
746 ((mac_length) << PSA_MAC_TRUNCATION_OFFSET & PSA_ALG_MAC_TRUNCATION_MASK))
747
748/** Macro to build the base MAC algorithm corresponding to a truncated
749 * MAC algorithm.
750 *
751 * \param alg A MAC algorithm identifier (value of type
752 * #psa_algorithm_t such that #PSA_ALG_IS_MAC(\p alg)
753 * is true). This may be a truncated or untruncated
754 * MAC algorithm.
755 *
756 * \return The corresponding base MAC algorithm.
757 * \return Unspecified if \p alg is not a supported
758 * MAC algorithm.
759 */
760#define PSA_ALG_FULL_LENGTH_MAC(alg) \
761 ((alg) & ~PSA_ALG_MAC_TRUNCATION_MASK)
762
763/** Length to which a MAC algorithm is truncated.
764 *
765 * \param alg A MAC algorithm identifier (value of type
766 * #psa_algorithm_t such that #PSA_ALG_IS_MAC(\p alg)
767 * is true).
768 *
769 * \return Length of the truncated MAC in bytes.
770 * \return 0 if \p alg is a non-truncated MAC algorithm.
771 * \return Unspecified if \p alg is not a supported
772 * MAC algorithm.
773 */
774#define PSA_MAC_TRUNCATED_LENGTH(alg) \
775 (((alg) & PSA_ALG_MAC_TRUNCATION_MASK) >> PSA_MAC_TRUNCATION_OFFSET)
776
777#define PSA_ALG_CIPHER_MAC_BASE ((psa_algorithm_t)0x02c00000)
778#define PSA_ALG_CBC_MAC ((psa_algorithm_t)0x02c00001)
779#define PSA_ALG_CMAC ((psa_algorithm_t)0x02c00002)
780#define PSA_ALG_GMAC ((psa_algorithm_t)0x02c00003)
781
782/** Whether the specified algorithm is a MAC algorithm based on a block cipher.
783 *
784 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
785 *
786 * \return 1 if \p alg is a MAC algorithm based on a block cipher, 0 otherwise.
787 * This macro may return either 0 or 1 if \p alg is not a supported
788 * algorithm identifier.
789 */
790#define PSA_ALG_IS_BLOCK_CIPHER_MAC(alg) \
791 (((alg) & (PSA_ALG_CATEGORY_MASK | PSA_ALG_MAC_SUBCATEGORY_MASK)) == \
792 PSA_ALG_CIPHER_MAC_BASE)
793
794#define PSA_ALG_CIPHER_STREAM_FLAG ((psa_algorithm_t)0x00800000)
795#define PSA_ALG_CIPHER_FROM_BLOCK_FLAG ((psa_algorithm_t)0x00400000)
796
797/** Whether the specified algorithm is a stream cipher.
798 *
799 * A stream cipher is a symmetric cipher that encrypts or decrypts messages
800 * by applying a bitwise-xor with a stream of bytes that is generated
801 * from a key.
802 *
803 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
804 *
805 * \return 1 if \p alg is a stream cipher algorithm, 0 otherwise.
806 * This macro may return either 0 or 1 if \p alg is not a supported
807 * algorithm identifier or if it is not a symmetric cipher algorithm.
808 */
809#define PSA_ALG_IS_STREAM_CIPHER(alg) \
810 (((alg) & (PSA_ALG_CATEGORY_MASK | PSA_ALG_CIPHER_STREAM_FLAG)) == \
811 (PSA_ALG_CATEGORY_CIPHER | PSA_ALG_CIPHER_STREAM_FLAG))
812
813/** The ARC4 stream cipher algorithm.
814 */
815#define PSA_ALG_ARC4 ((psa_algorithm_t)0x04800001)
816
817/** The CTR stream cipher mode.
818 *
819 * CTR is a stream cipher which is built from a block cipher.
820 * The underlying block cipher is determined by the key type.
821 * For example, to use AES-128-CTR, use this algorithm with
822 * a key of type #PSA_KEY_TYPE_AES and a length of 128 bits (16 bytes).
823 */
824#define PSA_ALG_CTR ((psa_algorithm_t)0x04c00001)
825
826#define PSA_ALG_CFB ((psa_algorithm_t)0x04c00002)
827
828#define PSA_ALG_OFB ((psa_algorithm_t)0x04c00003)
829
830/** The XTS cipher mode.
831 *
832 * XTS is a cipher mode which is built from a block cipher. It requires at
833 * least one full block of input, but beyond this minimum the input
834 * does not need to be a whole number of blocks.
835 */
836#define PSA_ALG_XTS ((psa_algorithm_t)0x044000ff)
837
838/** The CBC block cipher chaining mode, with no padding.
839 *
840 * The underlying block cipher is determined by the key type.
841 *
842 * This symmetric cipher mode can only be used with messages whose lengths
843 * are whole number of blocks for the chosen block cipher.
844 */
845#define PSA_ALG_CBC_NO_PADDING ((psa_algorithm_t)0x04600100)
846
847/** The CBC block cipher chaining mode with PKCS#7 padding.
848 *
849 * The underlying block cipher is determined by the key type.
850 *
851 * This is the padding method defined by PKCS#7 (RFC 2315) &sect;10.3.
852 */
853#define PSA_ALG_CBC_PKCS7 ((psa_algorithm_t)0x04600101)
854
855#define PSA_ALG_CCM ((psa_algorithm_t)0x06001001)
856#define PSA_ALG_GCM ((psa_algorithm_t)0x06001002)
857
858/* In the encoding of a AEAD algorithm, the bits corresponding to
859 * PSA_ALG_AEAD_TAG_LENGTH_MASK encode the length of the AEAD tag.
860 * The constants for default lengths follow this encoding.
861 */
862#define PSA_ALG_AEAD_TAG_LENGTH_MASK ((psa_algorithm_t)0x00003f00)
863#define PSA_AEAD_TAG_LENGTH_OFFSET 8
864
865/** Macro to build a shortened AEAD algorithm.
866 *
867 * A shortened AEAD algorithm is similar to the corresponding AEAD
868 * algorithm, but has an authentication tag that consists of fewer bytes.
869 * Depending on the algorithm, the tag length may affect the calculation
870 * of the ciphertext.
871 *
872 * \param alg A AEAD algorithm identifier (value of type
873 * #psa_algorithm_t such that #PSA_ALG_IS_AEAD(\p alg)
874 * is true).
875 * \param tag_length Desired length of the authentication tag in bytes.
876 *
877 * \return The corresponding AEAD algorithm with the specified
878 * length.
879 * \return Unspecified if \p alg is not a supported
880 * AEAD algorithm or if \p tag_length is not valid
881 * for the specified AEAD algorithm.
882 */
883#define PSA_ALG_AEAD_WITH_TAG_LENGTH(alg, tag_length) \
884 (((alg) & ~PSA_ALG_AEAD_TAG_LENGTH_MASK) | \
885 ((tag_length) << PSA_AEAD_TAG_LENGTH_OFFSET & \
886 PSA_ALG_AEAD_TAG_LENGTH_MASK))
887
888/** Calculate the corresponding AEAD algorithm with the default tag length.
889 *
890 * \param alg An AEAD algorithm (\c PSA_ALG_XXX value such that
891 * #PSA_ALG_IS_AEAD(\p alg) is true).
892 *
893 * \return The corresponding AEAD algorithm with the default tag length
894 * for that algorithm.
895 */
896#define PSA_ALG_AEAD_WITH_DEFAULT_TAG_LENGTH(alg) \
897 ( \
898 PSA__ALG_AEAD_WITH_DEFAULT_TAG_LENGTH__CASE(alg, PSA_ALG_CCM) \
899 PSA__ALG_AEAD_WITH_DEFAULT_TAG_LENGTH__CASE(alg, PSA_ALG_GCM) \
900 0)
901#define PSA__ALG_AEAD_WITH_DEFAULT_TAG_LENGTH__CASE(alg, ref) \
902 PSA_ALG_AEAD_WITH_TAG_LENGTH(alg, 0) == \
903 PSA_ALG_AEAD_WITH_TAG_LENGTH(ref, 0) ? \
904 ref :
905
906#define PSA_ALG_RSA_PKCS1V15_SIGN_BASE ((psa_algorithm_t)0x10020000)
907/** RSA PKCS#1 v1.5 signature with hashing.
908 *
909 * This is the signature scheme defined by RFC 8017
910 * (PKCS#1: RSA Cryptography Specifications) under the name
911 * RSASSA-PKCS1-v1_5.
912 *
913 * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
914 * #PSA_ALG_IS_HASH(\p hash_alg) is true).
915 *
916 * \return The corresponding RSA PKCS#1 v1.5 signature algorithm.
917 * \return Unspecified if \p alg is not a supported
918 * hash algorithm.
919 */
920#define PSA_ALG_RSA_PKCS1V15_SIGN(hash_alg) \
921 (PSA_ALG_RSA_PKCS1V15_SIGN_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
922/** Raw PKCS#1 v1.5 signature.
923 *
924 * The input to this algorithm is the DigestInfo structure used by
925 * RFC 8017 (PKCS#1: RSA Cryptography Specifications), &sect;9.2
926 * steps 3&ndash;6.
927 */
928#define PSA_ALG_RSA_PKCS1V15_SIGN_RAW PSA_ALG_RSA_PKCS1V15_SIGN_BASE
929#define PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) \
930 (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_RSA_PKCS1V15_SIGN_BASE)
931
932#define PSA_ALG_RSA_PSS_BASE ((psa_algorithm_t)0x10030000)
933/** RSA PSS signature with hashing.
934 *
935 * This is the signature scheme defined by RFC 8017
936 * (PKCS#1: RSA Cryptography Specifications) under the name
937 * RSASSA-PSS, with the message generation function MGF1, and with
938 * a salt length equal to the length of the hash. The specified
939 * hash algorithm is used to hash the input message, to create the
940 * salted hash, and for the mask generation.
941 *
942 * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
943 * #PSA_ALG_IS_HASH(\p hash_alg) is true).
944 *
945 * \return The corresponding RSA PSS signature algorithm.
946 * \return Unspecified if \p alg is not a supported
947 * hash algorithm.
948 */
949#define PSA_ALG_RSA_PSS(hash_alg) \
950 (PSA_ALG_RSA_PSS_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
951#define PSA_ALG_IS_RSA_PSS(alg) \
952 (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_RSA_PSS_BASE)
953
954#define PSA_ALG_DSA_BASE ((psa_algorithm_t)0x10040000)
955/** DSA signature with hashing.
956 *
957 * This is the signature scheme defined by FIPS 186-4,
958 * with a random per-message secret number (*k*).
959 *
960 * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
961 * #PSA_ALG_IS_HASH(\p hash_alg) is true).
962 *
963 * \return The corresponding DSA signature algorithm.
964 * \return Unspecified if \p alg is not a supported
965 * hash algorithm.
966 */
967#define PSA_ALG_DSA(hash_alg) \
968 (PSA_ALG_DSA_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
969#define PSA_ALG_DETERMINISTIC_DSA_BASE ((psa_algorithm_t)0x10050000)
970#define PSA_ALG_DSA_DETERMINISTIC_FLAG ((psa_algorithm_t)0x00010000)
971#define PSA_ALG_DETERMINISTIC_DSA(hash_alg) \
972 (PSA_ALG_DETERMINISTIC_DSA_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
973#define PSA_ALG_IS_DSA(alg) \
974 (((alg) & ~PSA_ALG_HASH_MASK & ~PSA_ALG_DSA_DETERMINISTIC_FLAG) == \
975 PSA_ALG_DSA_BASE)
976#define PSA_ALG_DSA_IS_DETERMINISTIC(alg) \
977 (((alg) & PSA_ALG_DSA_DETERMINISTIC_FLAG) != 0)
978#define PSA_ALG_IS_DETERMINISTIC_DSA(alg) \
979 (PSA_ALG_IS_DSA(alg) && PSA_ALG_DSA_IS_DETERMINISTIC(alg))
980#define PSA_ALG_IS_RANDOMIZED_DSA(alg) \
981 (PSA_ALG_IS_DSA(alg) && !PSA_ALG_DSA_IS_DETERMINISTIC(alg))
982
983#define PSA_ALG_ECDSA_BASE ((psa_algorithm_t)0x10060000)
984/** ECDSA signature with hashing.
985 *
986 * This is the ECDSA signature scheme defined by ANSI X9.62,
987 * with a random per-message secret number (*k*).
988 *
989 * The representation of the signature as a byte string consists of
990 * the concatentation of the signature values *r* and *s*. Each of
991 * *r* and *s* is encoded as an *N*-octet string, where *N* is the length
992 * of the base point of the curve in octets. Each value is represented
993 * in big-endian order (most significant octet first).
994 *
995 * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
996 * #PSA_ALG_IS_HASH(\p hash_alg) is true).
997 *
998 * \return The corresponding ECDSA signature algorithm.
999 * \return Unspecified if \p alg is not a supported
1000 * hash algorithm.
1001 */
1002#define PSA_ALG_ECDSA(hash_alg) \
1003 (PSA_ALG_ECDSA_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1004/** ECDSA signature without hashing.
1005 *
1006 * This is the same signature scheme as #PSA_ALG_ECDSA(), but
1007 * without specifying a hash algorithm. This algorithm may only be
1008 * used to sign or verify a sequence of bytes that should be an
1009 * already-calculated hash. Note that the input is padded with
1010 * zeros on the left or truncated on the left as required to fit
1011 * the curve size.
1012 */
1013#define PSA_ALG_ECDSA_ANY PSA_ALG_ECDSA_BASE
1014#define PSA_ALG_DETERMINISTIC_ECDSA_BASE ((psa_algorithm_t)0x10070000)
1015/** Deterministic ECDSA signature with hashing.
1016 *
1017 * This is the deterministic ECDSA signature scheme defined by RFC 6979.
1018 *
1019 * The representation of a signature is the same as with #PSA_ALG_ECDSA().
1020 *
1021 * Note that when this algorithm is used for verification, signatures
1022 * made with randomized ECDSA (#PSA_ALG_ECDSA(\p hash_alg)) with the
1023 * same private key are accepted. In other words,
1024 * #PSA_ALG_DETERMINISTIC_ECDSA(\p hash_alg) differs from
1025 * #PSA_ALG_ECDSA(\p hash_alg) only for signature, not for verification.
1026 *
1027 * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
1028 * #PSA_ALG_IS_HASH(\p hash_alg) is true).
1029 *
1030 * \return The corresponding deterministic ECDSA signature
1031 * algorithm.
1032 * \return Unspecified if \p alg is not a supported
1033 * hash algorithm.
1034 */
1035#define PSA_ALG_DETERMINISTIC_ECDSA(hash_alg) \
1036 (PSA_ALG_DETERMINISTIC_ECDSA_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1037#define PSA_ALG_IS_ECDSA(alg) \
1038 (((alg) & ~PSA_ALG_HASH_MASK & ~PSA_ALG_DSA_DETERMINISTIC_FLAG) == \
1039 PSA_ALG_ECDSA_BASE)
1040#define PSA_ALG_ECDSA_IS_DETERMINISTIC(alg) \
1041 (((alg) & PSA_ALG_DSA_DETERMINISTIC_FLAG) != 0)
1042#define PSA_ALG_IS_DETERMINISTIC_ECDSA(alg) \
1043 (PSA_ALG_IS_ECDSA(alg) && PSA_ALG_ECDSA_IS_DETERMINISTIC(alg))
1044#define PSA_ALG_IS_RANDOMIZED_ECDSA(alg) \
1045 (PSA_ALG_IS_ECDSA(alg) && !PSA_ALG_ECDSA_IS_DETERMINISTIC(alg))
1046
1047/** Get the hash used by a hash-and-sign signature algorithm.
1048 *
1049 * A hash-and-sign algorithm is a signature algorithm which is
1050 * composed of two phases: first a hashing phase which does not use
1051 * the key and produces a hash of the input message, then a signing
1052 * phase which only uses the hash and the key and not the message
1053 * itself.
1054 *
1055 * \param alg A signature algorithm (\c PSA_ALG_XXX value such that
1056 * #PSA_ALG_IS_SIGN(\p alg) is true).
1057 *
1058 * \return The underlying hash algorithm if \p alg is a hash-and-sign
1059 * algorithm.
1060 * \return 0 if \p alg is a signature algorithm that does not
1061 * follow the hash-and-sign structure.
1062 * \return Unspecified if \p alg is not a signature algorithm or
1063 * if it is not supported by the implementation.
1064 */
1065#define PSA_ALG_SIGN_GET_HASH(alg) \
1066 (PSA_ALG_IS_RSA_PSS(alg) || PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) || \
1067 PSA_ALG_IS_DSA(alg) || PSA_ALG_IS_ECDSA(alg) ? \
1068 ((alg) & PSA_ALG_HASH_MASK) == 0 ? /*"raw" algorithm*/ 0 : \
1069 ((alg) & PSA_ALG_HASH_MASK) | PSA_ALG_CATEGORY_HASH : \
1070 0)
1071
1072/** RSA PKCS#1 v1.5 encryption.
1073 */
1074#define PSA_ALG_RSA_PKCS1V15_CRYPT ((psa_algorithm_t)0x12020000)
1075
1076#define PSA_ALG_RSA_OAEP_BASE ((psa_algorithm_t)0x12030000)
1077/** RSA OAEP encryption.
1078 *
1079 * This is the encryption scheme defined by RFC 8017
1080 * (PKCS#1: RSA Cryptography Specifications) under the name
1081 * RSAES-OAEP, with the message generation function MGF1.
1082 *
1083 * \param hash_alg The hash algorithm (\c PSA_ALG_XXX value such that
1084 * #PSA_ALG_IS_HASH(\p hash_alg) is true) to use
1085 * for MGF1.
1086 *
1087 * \return The corresponding RSA OAEP signature algorithm.
1088 * \return Unspecified if \p alg is not a supported
1089 * hash algorithm.
1090 */
1091#define PSA_ALG_RSA_OAEP(hash_alg) \
1092 (PSA_ALG_RSA_OAEP_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1093#define PSA_ALG_IS_RSA_OAEP(alg) \
1094 (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_RSA_OAEP_BASE)
1095#define PSA_ALG_RSA_OAEP_GET_HASH(alg) \
1096 (PSA_ALG_IS_RSA_OAEP(alg) ? \
1097 ((alg) & PSA_ALG_HASH_MASK) | PSA_ALG_CATEGORY_HASH : \
1098 0)
1099
1100#define PSA_ALG_HKDF_BASE ((psa_algorithm_t)0x30000100)
1101/** Macro to build an HKDF algorithm.
1102 *
1103 * For example, `PSA_ALG_HKDF(PSA_ALG_SHA256)` is HKDF using HMAC-SHA-256.
1104 *
1105 * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
1106 * #PSA_ALG_IS_HASH(\p hash_alg) is true).
1107 *
1108 * \return The corresponding HKDF algorithm.
1109 * \return Unspecified if \p alg is not a supported
1110 * hash algorithm.
1111 */
1112#define PSA_ALG_HKDF(hash_alg) \
1113 (PSA_ALG_HKDF_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1114/** Whether the specified algorithm is an HKDF algorithm.
1115 *
1116 * HKDF is a family of key derivation algorithms that are based on a hash
1117 * function and the HMAC construction.
1118 *
1119 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
1120 *
1121 * \return 1 if \c alg is an HKDF algorithm, 0 otherwise.
1122 * This macro may return either 0 or 1 if \c alg is not a supported
1123 * key derivation algorithm identifier.
1124 */
1125#define PSA_ALG_IS_HKDF(alg) \
1126 (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_HKDF_BASE)
1127#define PSA_ALG_HKDF_GET_HASH(hkdf_alg) \
1128 (PSA_ALG_CATEGORY_HASH | ((hkdf_alg) & PSA_ALG_HASH_MASK))
1129
1130#define PSA_ALG_TLS12_PRF_BASE ((psa_algorithm_t)0x30000200)
1131/** Macro to build a TLS-1.2 PRF algorithm.
1132 *
1133 * TLS 1.2 uses a custom pseudorandom function (PRF) for key schedule,
1134 * specified in Section 5 of RFC 5246. It is based on HMAC and can be
1135 * used with either SHA-256 or SHA-384.
1136 *
1137 * For the application to TLS-1.2, the salt and label arguments passed
1138 * to psa_key_derivation() are what's called 'seed' and 'label' in RFC 5246,
1139 * respectively. For example, for TLS key expansion, the salt is the
1140 * concatenation of ServerHello.Random + ClientHello.Random,
1141 * while the label is "key expansion".
1142 *
1143 * For example, `PSA_ALG_TLS12_PRF(PSA_ALG_SHA256)` represents the
1144 * TLS 1.2 PRF using HMAC-SHA-256.
1145 *
1146 * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
1147 * #PSA_ALG_IS_HASH(\p hash_alg) is true).
1148 *
1149 * \return The corresponding TLS-1.2 PRF algorithm.
1150 * \return Unspecified if \p alg is not a supported
1151 * hash algorithm.
1152 */
1153#define PSA_ALG_TLS12_PRF(hash_alg) \
1154 (PSA_ALG_TLS12_PRF_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1155
1156/** Whether the specified algorithm is a TLS-1.2 PRF algorithm.
1157 *
1158 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
1159 *
1160 * \return 1 if \c alg is a TLS-1.2 PRF algorithm, 0 otherwise.
1161 * This macro may return either 0 or 1 if \c alg is not a supported
1162 * key derivation algorithm identifier.
1163 */
1164#define PSA_ALG_IS_TLS12_PRF(alg) \
1165 (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_TLS12_PRF_BASE)
1166#define PSA_ALG_TLS12_PRF_GET_HASH(hkdf_alg) \
1167 (PSA_ALG_CATEGORY_HASH | ((hkdf_alg) & PSA_ALG_HASH_MASK))
1168
1169#define PSA_ALG_TLS12_PSK_TO_MS_BASE ((psa_algorithm_t)0x30000300)
1170/** Macro to build a TLS-1.2 PSK-to-MasterSecret algorithm.
1171 *
1172 * In a pure-PSK handshake in TLS 1.2, the master secret is derived
1173 * from the PreSharedKey (PSK) through the application of padding
1174 * (RFC 4279, Section 2) and the TLS-1.2 PRF (RFC 5246, Section 5).
1175 * The latter is based on HMAC and can be used with either SHA-256
1176 * or SHA-384.
1177 *
1178 * For the application to TLS-1.2, the salt passed to psa_key_derivation()
1179 * (and forwarded to the TLS-1.2 PRF) is the concatenation of the
1180 * ClientHello.Random + ServerHello.Random, while the label is "master secret"
1181 * or "extended master secret".
1182 *
1183 * For example, `PSA_ALG_TLS12_PSK_TO_MS(PSA_ALG_SHA256)` represents the
1184 * TLS-1.2 PSK to MasterSecret derivation PRF using HMAC-SHA-256.
1185 *
1186 * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
1187 * #PSA_ALG_IS_HASH(\p hash_alg) is true).
1188 *
1189 * \return The corresponding TLS-1.2 PSK to MS algorithm.
1190 * \return Unspecified if \p alg is not a supported
1191 * hash algorithm.
1192 */
1193#define PSA_ALG_TLS12_PSK_TO_MS(hash_alg) \
1194 (PSA_ALG_TLS12_PSK_TO_MS_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1195
1196/** Whether the specified algorithm is a TLS-1.2 PSK to MS algorithm.
1197 *
1198 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
1199 *
1200 * \return 1 if \c alg is a TLS-1.2 PSK to MS algorithm, 0 otherwise.
1201 * This macro may return either 0 or 1 if \c alg is not a supported
1202 * key derivation algorithm identifier.
1203 */
1204#define PSA_ALG_IS_TLS12_PSK_TO_MS(alg) \
1205 (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_TLS12_PSK_TO_MS_BASE)
1206#define PSA_ALG_TLS12_PSK_TO_MS_GET_HASH(hkdf_alg) \
1207 (PSA_ALG_CATEGORY_HASH | ((hkdf_alg) & PSA_ALG_HASH_MASK))
1208
1209#define PSA_ALG_KEY_DERIVATION_MASK ((psa_algorithm_t)0x010fffff)
1210
1211/** Use a shared secret as is.
1212 *
1213 * Specify this algorithm as the selection component of a key agreement
1214 * to use the raw result of the key agreement as key material.
1215 *
1216 * \warning The raw result of a key agreement algorithm such as finite-field
1217 * Diffie-Hellman or elliptic curve Diffie-Hellman has biases and should
1218 * not be used directly as key material. It can however be used as the secret
1219 * input in a key derivation algorithm.
1220 */
1221#define PSA_ALG_SELECT_RAW ((psa_algorithm_t)0x31000001)
1222
1223#define PSA_ALG_KEY_AGREEMENT_GET_KDF(alg) \
1224 (((alg) & PSA_ALG_KEY_DERIVATION_MASK) | PSA_ALG_CATEGORY_KEY_DERIVATION)
1225
1226#define PSA_ALG_KEY_AGREEMENT_GET_BASE(alg) \
1227 ((alg) & ~PSA_ALG_KEY_DERIVATION_MASK)
1228
1229#define PSA_ALG_FFDH_BASE ((psa_algorithm_t)0x22100000)
1230/** The Diffie-Hellman key agreement algorithm.
1231 *
1232 * This algorithm combines the finite-field Diffie-Hellman (DH) key
1233 * agreement, also known as Diffie-Hellman-Merkle (DHM) key agreement,
1234 * to produce a shared secret from a private key and the peer's
1235 * public key, with a key selection or key derivation algorithm to produce
1236 * one or more shared keys and other shared cryptographic material.
1237 *
1238 * The shared secret produced by key agreement and passed as input to the
1239 * derivation or selection algorithm \p kdf_alg is the shared secret
1240 * `g^{ab}` in big-endian format.
1241 * It is `ceiling(m / 8)` bytes long where `m` is the size of the prime `p`
1242 * in bits.
1243 *
1244 * \param kdf_alg A key derivation algorithm (\c PSA_ALG_XXX value such
1245 * that #PSA_ALG_IS_KEY_DERIVATION(\p hash_alg) is true)
1246 * or a key selection algorithm (\c PSA_ALG_XXX value such
1247 * that #PSA_ALG_IS_KEY_SELECTION(\p hash_alg) is true).
1248 *
1249 * \return The Diffie-Hellman algorithm with the specified
1250 * selection or derivation algorithm.
1251 */
1252#define PSA_ALG_FFDH(kdf_alg) \
1253 (PSA_ALG_FFDH_BASE | ((kdf_alg) & PSA_ALG_KEY_DERIVATION_MASK))
1254/** Whether the specified algorithm is a finite field Diffie-Hellman algorithm.
1255 *
1256 * This includes every supported key selection or key agreement algorithm
1257 * for the output of the Diffie-Hellman calculation.
1258 *
1259 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
1260 *
1261 * \return 1 if \c alg is a finite field Diffie-Hellman algorithm, 0 otherwise.
1262 * This macro may return either 0 or 1 if \c alg is not a supported
1263 * key agreement algorithm identifier.
1264 */
1265#define PSA_ALG_IS_FFDH(alg) \
1266 (PSA_ALG_KEY_AGREEMENT_GET_BASE(alg) == PSA_ALG_FFDH_BASE)
1267
1268#define PSA_ALG_ECDH_BASE ((psa_algorithm_t)0x22200000)
1269/** The elliptic curve Diffie-Hellman (ECDH) key agreement algorithm.
1270 *
1271 * This algorithm combines the elliptic curve Diffie-Hellman key
1272 * agreement to produce a shared secret from a private key and the peer's
1273 * public key, with a key selection or key derivation algorithm to produce
1274 * one or more shared keys and other shared cryptographic material.
1275 *
1276 * The shared secret produced by key agreement and passed as input to the
1277 * derivation or selection algorithm \p kdf_alg is the x-coordinate of
1278 * the shared secret point. It is always `ceiling(m / 8)` bytes long where
1279 * `m` is the bit size associated with the curve, i.e. the bit size of the
1280 * order of the curve's coordinate field. When `m` is not a multiple of 8,
1281 * the byte containing the most significant bit of the shared secret
1282 * is padded with zero bits. The byte order is either little-endian
1283 * or big-endian depending on the curve type.
1284 *
1285 * - For Montgomery curves (curve types `PSA_ECC_CURVE_CURVEXXX`),
1286 * the shared secret is the x-coordinate of `d_A Q_B = d_B Q_A`
1287 * in little-endian byte order.
1288 * The bit size is 448 for Curve448 and 255 for Curve25519.
1289 * - For Weierstrass curves over prime fields (curve types
1290 * `PSA_ECC_CURVE_SECPXXX` and `PSA_ECC_CURVE_BRAINPOOL_PXXX`),
1291 * the shared secret is the x-coordinate of `d_A Q_B = d_B Q_A`
1292 * in big-endian byte order.
1293 * The bit size is `m = ceiling(log_2(p))` for the field `F_p`.
1294 * - For Weierstrass curves over binary fields (curve types
1295 * `PSA_ECC_CURVE_SECTXXX`),
1296 * the shared secret is the x-coordinate of `d_A Q_B = d_B Q_A`
1297 * in big-endian byte order.
1298 * The bit size is `m` for the field `F_{2^m}`.
1299 *
1300 * \param kdf_alg A key derivation algorithm (\c PSA_ALG_XXX value such
1301 * that #PSA_ALG_IS_KEY_DERIVATION(\p hash_alg) is true)
1302 * or a selection algorithm (\c PSA_ALG_XXX value such
1303 * that #PSA_ALG_IS_KEY_SELECTION(\p hash_alg) is true).
1304 *
1305 * \return The Diffie-Hellman algorithm with the specified
1306 * selection or derivation algorithm.
1307 */
1308#define PSA_ALG_ECDH(kdf_alg) \
1309 (PSA_ALG_ECDH_BASE | ((kdf_alg) & PSA_ALG_KEY_DERIVATION_MASK))
1310/** Whether the specified algorithm is an elliptic curve Diffie-Hellman
1311 * algorithm.
1312 *
1313 * This includes every supported key selection or key agreement algorithm
1314 * for the output of the Diffie-Hellman calculation.
1315 *
1316 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
1317 *
1318 * \return 1 if \c alg is an elliptic curve Diffie-Hellman algorithm,
1319 * 0 otherwise.
1320 * This macro may return either 0 or 1 if \c alg is not a supported
1321 * key agreement algorithm identifier.
1322 */
1323#define PSA_ALG_IS_ECDH(alg) \
1324 (PSA_ALG_KEY_AGREEMENT_GET_BASE(alg) == PSA_ALG_ECDH_BASE)
1325
1326/**@}*/
1327
1328/** \defgroup key_lifetimes Key lifetimes
1329 * @{
1330 */
1331
1332/** A volatile key only exists as long as the handle to it is not closed.
1333 * The key material is guaranteed to be erased on a power reset.
1334 */
1335#define PSA_KEY_LIFETIME_VOLATILE ((psa_key_lifetime_t)0x00000000)
1336
1337/** The default storage area for persistent keys.
1338 *
1339 * A persistent key remains in storage until it is explicitly destroyed or
1340 * until the corresponding storage area is wiped. This specification does
1341 * not define any mechanism to wipe a storage area, but implementations may
1342 * provide their own mechanism (for example to perform a factory reset,
1343 * to prepare for device refurbishment, or to uninstall an application).
1344 *
1345 * This lifetime value is the default storage area for the calling
1346 * application. Implementations may offer other storage areas designated
1347 * by other lifetime values as implementation-specific extensions.
1348 */
1349#define PSA_KEY_LIFETIME_PERSISTENT ((psa_key_lifetime_t)0x00000001)
1350
1351/**@}*/
1352
1353/** \defgroup policy Key policies
1354 * @{
1355 */
1356
1357/** Whether the key may be exported.
1358 *
1359 * A public key or the public part of a key pair may always be exported
1360 * regardless of the value of this permission flag.
1361 *
1362 * If a key does not have export permission, implementations shall not
1363 * allow the key to be exported in plain form from the cryptoprocessor,
1364 * whether through psa_export_key() or through a proprietary interface.
1365 * The key may however be exportable in a wrapped form, i.e. in a form
1366 * where it is encrypted by another key.
1367 */
1368#define PSA_KEY_USAGE_EXPORT ((psa_key_usage_t)0x00000001)
1369
1370/** Whether the key may be used to encrypt a message.
1371 *
1372 * This flag allows the key to be used for a symmetric encryption operation,
1373 * for an AEAD encryption-and-authentication operation,
1374 * or for an asymmetric encryption operation,
1375 * if otherwise permitted by the key's type and policy.
1376 *
1377 * For a key pair, this concerns the public key.
1378 */
1379#define PSA_KEY_USAGE_ENCRYPT ((psa_key_usage_t)0x00000100)
1380
1381/** Whether the key may be used to decrypt a message.
1382 *
1383 * This flag allows the key to be used for a symmetric decryption operation,
1384 * for an AEAD decryption-and-verification operation,
1385 * or for an asymmetric decryption operation,
1386 * if otherwise permitted by the key's type and policy.
1387 *
1388 * For a key pair, this concerns the private key.
1389 */
1390#define PSA_KEY_USAGE_DECRYPT ((psa_key_usage_t)0x00000200)
1391
1392/** Whether the key may be used to sign a message.
1393 *
1394 * This flag allows the key to be used for a MAC calculation operation
1395 * or for an asymmetric signature operation,
1396 * if otherwise permitted by the key's type and policy.
1397 *
1398 * For a key pair, this concerns the private key.
1399 */
1400#define PSA_KEY_USAGE_SIGN ((psa_key_usage_t)0x00000400)
1401
1402/** Whether the key may be used to verify a message signature.
1403 *
1404 * This flag allows the key to be used for a MAC verification operation
1405 * or for an asymmetric signature verification operation,
1406 * if otherwise permitted by by the key's type and policy.
1407 *
1408 * For a key pair, this concerns the public key.
1409 */
1410#define PSA_KEY_USAGE_VERIFY ((psa_key_usage_t)0x00000800)
1411
1412/** Whether the key may be used to derive other keys.
1413 */
1414#define PSA_KEY_USAGE_DERIVE ((psa_key_usage_t)0x00001000)
1415
1416/**@}*/
1417
1418#endif /* PSA_CRYPTO_VALUES_H */