blob: 25c6662c16eccebd7e7a4d1f3fff7e1e8adbb154 [file] [log] [blame]
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001/*
Maulik Patel28659c42021-01-06 14:09:22 +00002 * Copyright (c) 2018-2021, Arm Limited. All rights reserved.
Jamie Fox0e54ebc2019-04-09 14:21:04 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7/**
Jamie Foxcc31d402019-01-28 17:13:52 +00008 * \file psa/crypto_values.h
Jamie Fox0e54ebc2019-04-09 14:21:04 +01009 *
10 * \brief PSA cryptography module: macros to build and analyze integer values.
11 *
12 * \note This file may not be included directly. Applications must
Jamie Foxcc31d402019-01-28 17:13:52 +000013 * include psa/crypto.h. Drivers must include the appropriate driver
Jamie Fox0e54ebc2019-04-09 14:21:04 +010014 * header file.
15 *
16 * This file contains portable definitions of macros to build and analyze
17 * values of integral types that encode properties of cryptographic keys,
18 * designations of cryptographic algorithms, and error codes returned by
19 * the library.
20 *
21 * This header file only defines preprocessor macros.
22 */
23
24#ifndef PSA_CRYPTO_VALUES_H
25#define PSA_CRYPTO_VALUES_H
26
27/** \defgroup error Error codes
28 * @{
29 */
30
31/* PSA error codes */
32
33/** The action was completed successfully. */
34#ifndef PSA_SUCCESS
35#define PSA_SUCCESS ((psa_status_t)0)
36#endif
37
38/** An error occurred that does not correspond to any defined
39 * failure cause.
40 *
41 * Implementations may use this error code if none of the other standard
42 * error codes are applicable. */
43#define PSA_ERROR_GENERIC_ERROR ((psa_status_t)-132)
44
45/** The requested operation or a parameter is not supported
46 * by this implementation.
47 *
48 * Implementations should return this error code when an enumeration
49 * parameter such as a key type, algorithm, etc. is not recognized.
50 * If a combination of parameters is recognized and identified as
51 * not valid, return #PSA_ERROR_INVALID_ARGUMENT instead. */
52#define PSA_ERROR_NOT_SUPPORTED ((psa_status_t)-134)
53
54/** The requested action is denied by a policy.
55 *
56 * Implementations should return this error code when the parameters
57 * are recognized as valid and supported, and a policy explicitly
58 * denies the requested operation.
59 *
60 * If a subset of the parameters of a function call identify a
61 * forbidden operation, and another subset of the parameters are
62 * not valid or not supported, it is unspecified whether the function
63 * returns #PSA_ERROR_NOT_PERMITTED, #PSA_ERROR_NOT_SUPPORTED or
64 * #PSA_ERROR_INVALID_ARGUMENT. */
65#define PSA_ERROR_NOT_PERMITTED ((psa_status_t)-133)
66
67/** An output buffer is too small.
68 *
69 * Applications can call the \c PSA_xxx_SIZE macro listed in the function
70 * description to determine a sufficient buffer size.
71 *
72 * Implementations should preferably return this error code only
73 * in cases when performing the operation with a larger output
74 * buffer would succeed. However implementations may return this
75 * error if a function has invalid or unsupported parameters in addition
76 * to the parameters that determine the necessary output buffer size. */
77#define PSA_ERROR_BUFFER_TOO_SMALL ((psa_status_t)-138)
78
79/** Asking for an item that already exists
80 *
81 * Implementations should return this error, when attempting
82 * to write an item (like a key) that already exists. */
83#define PSA_ERROR_ALREADY_EXISTS ((psa_status_t)-139)
84
85/** Asking for an item that doesn't exist
86 *
87 * Implementations should return this error, if a requested item (like
88 * a key) does not exist. */
89#define PSA_ERROR_DOES_NOT_EXIST ((psa_status_t)-140)
90
91/** The requested action cannot be performed in the current state.
92 *
93 * Multipart operations return this error when one of the
94 * functions is called out of sequence. Refer to the function
95 * descriptions for permitted sequencing of functions.
96 *
97 * Implementations shall not return this error code to indicate
Antonio de Angelis04debbd2019-10-14 12:12:52 +010098 * that a key either exists or not,
99 * but shall instead return #PSA_ERROR_ALREADY_EXISTS or #PSA_ERROR_DOES_NOT_EXIST
100 * as applicable.
101 *
102 * Implementations shall not return this error code to indicate that a
Maulik Patel28659c42021-01-06 14:09:22 +0000103 * key identifier is invalid, but shall return #PSA_ERROR_INVALID_HANDLE
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100104 * instead. */
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100105#define PSA_ERROR_BAD_STATE ((psa_status_t)-137)
106
107/** The parameters passed to the function are invalid.
108 *
109 * Implementations may return this error any time a parameter or
110 * combination of parameters are recognized as invalid.
111 *
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100112 * Implementations shall not return this error code to indicate that a
Maulik Patel28659c42021-01-06 14:09:22 +0000113 * key identifier is invalid, but shall return #PSA_ERROR_INVALID_HANDLE
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100114 * instead.
115 */
116#define PSA_ERROR_INVALID_ARGUMENT ((psa_status_t)-135)
117
118/** There is not enough runtime memory.
119 *
120 * If the action is carried out across multiple security realms, this
121 * error can refer to available memory in any of the security realms. */
122#define PSA_ERROR_INSUFFICIENT_MEMORY ((psa_status_t)-141)
123
124/** There is not enough persistent storage.
125 *
126 * Functions that modify the key storage return this error code if
127 * there is insufficient storage space on the host media. In addition,
128 * many functions that do not otherwise access storage may return this
129 * error code if the implementation requires a mandatory log entry for
130 * the requested action and the log storage space is full. */
131#define PSA_ERROR_INSUFFICIENT_STORAGE ((psa_status_t)-142)
132
133/** There was a communication failure inside the implementation.
134 *
135 * This can indicate a communication failure between the application
136 * and an external cryptoprocessor or between the cryptoprocessor and
137 * an external volatile or persistent memory. A communication failure
138 * may be transient or permanent depending on the cause.
139 *
140 * \warning If a function returns this error, it is undetermined
141 * whether the requested action has completed or not. Implementations
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100142 * should return #PSA_SUCCESS on successful completion whenever
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100143 * possible, however functions may return #PSA_ERROR_COMMUNICATION_FAILURE
144 * if the requested action was completed successfully in an external
145 * cryptoprocessor but there was a breakdown of communication before
146 * the cryptoprocessor could report the status to the application.
147 */
148#define PSA_ERROR_COMMUNICATION_FAILURE ((psa_status_t)-145)
149
150/** There was a storage failure that may have led to data loss.
151 *
152 * This error indicates that some persistent storage is corrupted.
153 * It should not be used for a corruption of volatile memory
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100154 * (use #PSA_ERROR_CORRUPTION_DETECTED), for a communication error
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100155 * between the cryptoprocessor and its external storage (use
156 * #PSA_ERROR_COMMUNICATION_FAILURE), or when the storage is
157 * in a valid state but is full (use #PSA_ERROR_INSUFFICIENT_STORAGE).
158 *
159 * Note that a storage failure does not indicate that any data that was
160 * previously read is invalid. However this previously read data may no
161 * longer be readable from storage.
162 *
163 * When a storage failure occurs, it is no longer possible to ensure
164 * the global integrity of the keystore. Depending on the global
165 * integrity guarantees offered by the implementation, access to other
166 * data may or may not fail even if the data is still readable but
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100167 * its integrity cannot be guaranteed.
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100168 *
169 * Implementations should only use this error code to report a
170 * permanent storage corruption. However application writers should
171 * keep in mind that transient errors while reading the storage may be
172 * reported using this error code. */
173#define PSA_ERROR_STORAGE_FAILURE ((psa_status_t)-146)
174
175/** A hardware failure was detected.
176 *
177 * A hardware failure may be transient or permanent depending on the
178 * cause. */
179#define PSA_ERROR_HARDWARE_FAILURE ((psa_status_t)-147)
180
181/** A tampering attempt was detected.
182 *
183 * If an application receives this error code, there is no guarantee
184 * that previously accessed or computed data was correct and remains
185 * confidential. Applications should not perform any security function
186 * and should enter a safe failure state.
187 *
188 * Implementations may return this error code if they detect an invalid
189 * state that cannot happen during normal operation and that indicates
190 * that the implementation's security guarantees no longer hold. Depending
191 * on the implementation architecture and on its security and safety goals,
192 * the implementation may forcibly terminate the application.
193 *
194 * This error code is intended as a last resort when a security breach
195 * is detected and it is unsure whether the keystore data is still
196 * protected. Implementations shall only return this error code
197 * to report an alarm from a tampering detector, to indicate that
198 * the confidentiality of stored data can no longer be guaranteed,
199 * or to indicate that the integrity of previously returned data is now
200 * considered compromised. Implementations shall not use this error code
201 * to indicate a hardware failure that merely makes it impossible to
202 * perform the requested operation (use #PSA_ERROR_COMMUNICATION_FAILURE,
203 * #PSA_ERROR_STORAGE_FAILURE, #PSA_ERROR_HARDWARE_FAILURE,
204 * #PSA_ERROR_INSUFFICIENT_ENTROPY or other applicable error code
205 * instead).
206 *
207 * This error indicates an attack against the application. Implementations
208 * shall not return this error code as a consequence of the behavior of
209 * the application itself. */
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100210#define PSA_ERROR_CORRUPTION_DETECTED ((psa_status_t)-151)
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100211
212/** There is not enough entropy to generate random data needed
213 * for the requested action.
214 *
215 * This error indicates a failure of a hardware random generator.
216 * Application writers should note that this error can be returned not
217 * only by functions whose purpose is to generate random data, such
218 * as key, IV or nonce generation, but also by functions that execute
219 * an algorithm with a randomized result, as well as functions that
220 * use randomization of intermediate computations as a countermeasure
221 * to certain attacks.
222 *
223 * Implementations should avoid returning this error after psa_crypto_init()
224 * has succeeded. Implementations should generate sufficient
225 * entropy during initialization and subsequently use a cryptographically
226 * secure pseudorandom generator (PRNG). However implementations may return
227 * this error at any time if a policy requires the PRNG to be reseeded
228 * during normal operation. */
229#define PSA_ERROR_INSUFFICIENT_ENTROPY ((psa_status_t)-148)
230
231/** The signature, MAC or hash is incorrect.
232 *
233 * Verification functions return this error if the verification
234 * calculations completed successfully, and the value to be verified
235 * was determined to be incorrect.
236 *
237 * If the value to verify has an invalid size, implementations may return
238 * either #PSA_ERROR_INVALID_ARGUMENT or #PSA_ERROR_INVALID_SIGNATURE. */
239#define PSA_ERROR_INVALID_SIGNATURE ((psa_status_t)-149)
240
241/** The decrypted padding is incorrect.
242 *
243 * \warning In some protocols, when decrypting data, it is essential that
244 * the behavior of the application does not depend on whether the padding
245 * is correct, down to precise timing. Applications should prefer
246 * protocols that use authenticated encryption rather than plain
247 * encryption. If the application must perform a decryption of
248 * unauthenticated data, the application writer should take care not
249 * to reveal whether the padding is invalid.
250 *
251 * Implementations should strive to make valid and invalid padding
252 * as close as possible to indistinguishable to an external observer.
253 * In particular, the timing of a decryption operation should not
254 * depend on the validity of the padding. */
255#define PSA_ERROR_INVALID_PADDING ((psa_status_t)-150)
256
257/** Return this error when there's insufficient data when attempting
258 * to read from a resource. */
259#define PSA_ERROR_INSUFFICIENT_DATA ((psa_status_t)-143)
260
Maulik Patel28659c42021-01-06 14:09:22 +0000261/** The key identifier is not valid. See also :ref:\`key-handles\`.
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100262 */
263#define PSA_ERROR_INVALID_HANDLE ((psa_status_t)-136)
264
Maulik Patel13b27cf2021-05-14 11:44:53 +0100265/** Stored data has been corrupted.
266 *
267 * This error indicates that some persistent storage has suffered corruption.
268 * It does not indicate the following situations, which have specific error
269 * codes:
270 *
271 * - A corruption of volatile memory - use #PSA_ERROR_CORRUPTION_DETECTED.
272 * - A communication error between the cryptoprocessor and its external
273 * storage - use #PSA_ERROR_COMMUNICATION_FAILURE.
274 * - When the storage is in a valid state but is full - use
275 * #PSA_ERROR_INSUFFICIENT_STORAGE.
276 * - When the storage fails for other reasons - use
277 * #PSA_ERROR_STORAGE_FAILURE.
278 * - When the stored data is not valid - use #PSA_ERROR_DATA_INVALID.
279 *
280 * \note A storage corruption does not indicate that any data that was
281 * previously read is invalid. However this previously read data might no
282 * longer be readable from storage.
283 *
284 * When a storage failure occurs, it is no longer possible to ensure the
285 * global integrity of the keystore.
286 */
287#define PSA_ERROR_DATA_CORRUPT ((psa_status_t)-152)
288
289/** Data read from storage is not valid for the implementation.
290 *
291 * This error indicates that some data read from storage does not have a valid
292 * format. It does not indicate the following situations, which have specific
293 * error codes:
294 *
295 * - When the storage or stored data is corrupted - use #PSA_ERROR_DATA_CORRUPT
296 * - When the storage fails for other reasons - use #PSA_ERROR_STORAGE_FAILURE
297 * - An invalid argument to the API - use #PSA_ERROR_INVALID_ARGUMENT
298 *
299 * This error is typically a result of either storage corruption on a
300 * cleartext storage backend, or an attempt to read data that was
301 * written by an incompatible version of the library.
302 */
303#define PSA_ERROR_DATA_INVALID ((psa_status_t)-153)
304
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100305/**@}*/
306
307/** \defgroup crypto_types Key and algorithm types
308 * @{
309 */
310
311/** An invalid key type value.
312 *
313 * Zero is not the encoding of any key type.
314 */
Soby Mathew07ef6e42020-07-20 21:09:23 +0100315#define PSA_KEY_TYPE_NONE ((psa_key_type_t)0x0000)
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100316
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100317/** Vendor-defined key type flag.
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100318 *
319 * Key types defined by this standard will never have the
320 * #PSA_KEY_TYPE_VENDOR_FLAG bit set. Vendors who define additional key types
321 * must use an encoding with the #PSA_KEY_TYPE_VENDOR_FLAG bit set and should
322 * respect the bitwise structure used by standard encodings whenever practical.
323 */
Soby Mathew07ef6e42020-07-20 21:09:23 +0100324#define PSA_KEY_TYPE_VENDOR_FLAG ((psa_key_type_t)0x8000)
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100325
Soby Mathew07ef6e42020-07-20 21:09:23 +0100326#define PSA_KEY_TYPE_CATEGORY_MASK ((psa_key_type_t)0x7000)
327#define PSA_KEY_TYPE_CATEGORY_RAW ((psa_key_type_t)0x1000)
328#define PSA_KEY_TYPE_CATEGORY_SYMMETRIC ((psa_key_type_t)0x2000)
329#define PSA_KEY_TYPE_CATEGORY_PUBLIC_KEY ((psa_key_type_t)0x4000)
330#define PSA_KEY_TYPE_CATEGORY_KEY_PAIR ((psa_key_type_t)0x7000)
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100331
Soby Mathew07ef6e42020-07-20 21:09:23 +0100332#define PSA_KEY_TYPE_CATEGORY_FLAG_PAIR ((psa_key_type_t)0x3000)
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100333
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100334/** Whether a key type is vendor-defined.
335 *
336 * See also #PSA_KEY_TYPE_VENDOR_FLAG.
337 */
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100338#define PSA_KEY_TYPE_IS_VENDOR_DEFINED(type) \
339 (((type) & PSA_KEY_TYPE_VENDOR_FLAG) != 0)
340
341/** Whether a key type is an unstructured array of bytes.
342 *
343 * This encompasses both symmetric keys and non-key data.
344 */
345#define PSA_KEY_TYPE_IS_UNSTRUCTURED(type) \
Soby Mathew07ef6e42020-07-20 21:09:23 +0100346 (((type) & PSA_KEY_TYPE_CATEGORY_MASK) == PSA_KEY_TYPE_CATEGORY_RAW || \
347 ((type) & PSA_KEY_TYPE_CATEGORY_MASK) == PSA_KEY_TYPE_CATEGORY_SYMMETRIC)
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100348
349/** Whether a key type is asymmetric: either a key pair or a public key. */
350#define PSA_KEY_TYPE_IS_ASYMMETRIC(type) \
351 (((type) & PSA_KEY_TYPE_CATEGORY_MASK \
352 & ~PSA_KEY_TYPE_CATEGORY_FLAG_PAIR) == \
353 PSA_KEY_TYPE_CATEGORY_PUBLIC_KEY)
354/** Whether a key type is the public part of a key pair. */
355#define PSA_KEY_TYPE_IS_PUBLIC_KEY(type) \
356 (((type) & PSA_KEY_TYPE_CATEGORY_MASK) == PSA_KEY_TYPE_CATEGORY_PUBLIC_KEY)
357/** Whether a key type is a key pair containing a private part and a public
358 * part. */
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100359#define PSA_KEY_TYPE_IS_KEY_PAIR(type) \
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100360 (((type) & PSA_KEY_TYPE_CATEGORY_MASK) == PSA_KEY_TYPE_CATEGORY_KEY_PAIR)
361/** The key pair type corresponding to a public key type.
362 *
363 * You may also pass a key pair type as \p type, it will be left unchanged.
364 *
365 * \param type A public key type or key pair type.
366 *
367 * \return The corresponding key pair type.
368 * If \p type is not a public key or a key pair,
369 * the return value is undefined.
370 */
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100371#define PSA_KEY_TYPE_KEY_PAIR_OF_PUBLIC_KEY(type) \
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100372 ((type) | PSA_KEY_TYPE_CATEGORY_FLAG_PAIR)
373/** The public key type corresponding to a key pair type.
374 *
375 * You may also pass a key pair type as \p type, it will be left unchanged.
376 *
377 * \param type A public key type or key pair type.
378 *
379 * \return The corresponding public key type.
380 * If \p type is not a public key or a key pair,
381 * the return value is undefined.
382 */
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100383#define PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(type) \
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100384 ((type) & ~PSA_KEY_TYPE_CATEGORY_FLAG_PAIR)
385
386/** Raw data.
387 *
388 * A "key" of this type cannot be used for any cryptographic operation.
389 * Applications may use this type to store arbitrary data in the keystore. */
Soby Mathew07ef6e42020-07-20 21:09:23 +0100390#define PSA_KEY_TYPE_RAW_DATA ((psa_key_type_t)0x1001)
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100391
392/** HMAC key.
393 *
394 * The key policy determines which underlying hash algorithm the key can be
395 * used for.
396 *
397 * HMAC keys should generally have the same size as the underlying hash.
Maulik Patel13b27cf2021-05-14 11:44:53 +0100398 * This size can be calculated with #PSA_HASH_LENGTH(\c alg) where
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100399 * \c alg is the HMAC algorithm or the underlying hash algorithm. */
Soby Mathew07ef6e42020-07-20 21:09:23 +0100400#define PSA_KEY_TYPE_HMAC ((psa_key_type_t)0x1100)
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100401
402/** A secret for key derivation.
403 *
404 * The key policy determines which key derivation algorithm the key
405 * can be used for.
406 */
Soby Mathew07ef6e42020-07-20 21:09:23 +0100407#define PSA_KEY_TYPE_DERIVE ((psa_key_type_t)0x1200)
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100408
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100409/** Key for a cipher, AEAD or MAC algorithm based on the AES block cipher.
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100410 *
411 * The size of the key can be 16 bytes (AES-128), 24 bytes (AES-192) or
412 * 32 bytes (AES-256).
413 */
Soby Mathew07ef6e42020-07-20 21:09:23 +0100414#define PSA_KEY_TYPE_AES ((psa_key_type_t)0x2400)
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100415
416/** Key for a cipher or MAC algorithm based on DES or 3DES (Triple-DES).
417 *
418 * The size of the key can be 8 bytes (single DES), 16 bytes (2-key 3DES) or
419 * 24 bytes (3-key 3DES).
420 *
421 * Note that single DES and 2-key 3DES are weak and strongly
422 * deprecated and should only be used to decrypt legacy data. 3-key 3DES
423 * is weak and deprecated and should only be used in legacy protocols.
424 */
Soby Mathew07ef6e42020-07-20 21:09:23 +0100425#define PSA_KEY_TYPE_DES ((psa_key_type_t)0x2301)
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100426
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100427/** Key for a cipher, AEAD or MAC algorithm based on the
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100428 * Camellia block cipher. */
Soby Mathew07ef6e42020-07-20 21:09:23 +0100429#define PSA_KEY_TYPE_CAMELLIA ((psa_key_type_t)0x2403)
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100430
431/** Key for the RC4 stream cipher.
432 *
433 * Note that RC4 is weak and deprecated and should only be used in
434 * legacy protocols. */
Soby Mathew07ef6e42020-07-20 21:09:23 +0100435#define PSA_KEY_TYPE_ARC4 ((psa_key_type_t)0x2002)
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100436
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100437/** Key for the ChaCha20 stream cipher or the Chacha20-Poly1305 AEAD algorithm.
438 *
439 * ChaCha20 and the ChaCha20_Poly1305 construction are defined in RFC 7539.
440 *
441 * Implementations must support 12-byte nonces, may support 8-byte nonces,
442 * and should reject other sizes.
443 */
Soby Mathew07ef6e42020-07-20 21:09:23 +0100444#define PSA_KEY_TYPE_CHACHA20 ((psa_key_type_t)0x2004)
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100445
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100446/** RSA public key. */
Soby Mathew07ef6e42020-07-20 21:09:23 +0100447#define PSA_KEY_TYPE_RSA_PUBLIC_KEY ((psa_key_type_t)0x4001)
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100448/** RSA key pair (private and public key). */
Soby Mathew07ef6e42020-07-20 21:09:23 +0100449#define PSA_KEY_TYPE_RSA_KEY_PAIR ((psa_key_type_t)0x7001)
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100450/** Whether a key type is an RSA key (pair or public-only). */
451#define PSA_KEY_TYPE_IS_RSA(type) \
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100452 (PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(type) == PSA_KEY_TYPE_RSA_PUBLIC_KEY)
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100453
Soby Mathew07ef6e42020-07-20 21:09:23 +0100454#define PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE ((psa_key_type_t)0x4100)
455#define PSA_KEY_TYPE_ECC_KEY_PAIR_BASE ((psa_key_type_t)0x7100)
456#define PSA_KEY_TYPE_ECC_CURVE_MASK ((psa_key_type_t)0x00ff)
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100457/** Elliptic curve key pair.
458 *
Summer Qin0e5b2e02020-10-22 11:23:39 +0800459 * \param curve A value of type ::psa_ecc_family_t that
460 * identifies the ECC curve to be used.
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100461 */
462#define PSA_KEY_TYPE_ECC_KEY_PAIR(curve) \
463 (PSA_KEY_TYPE_ECC_KEY_PAIR_BASE | (curve))
464/** Elliptic curve public key.
465 *
Summer Qin0e5b2e02020-10-22 11:23:39 +0800466 * \param curve A value of type ::psa_ecc_family_t that
467 * identifies the ECC curve to be used.
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100468 */
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100469#define PSA_KEY_TYPE_ECC_PUBLIC_KEY(curve) \
470 (PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE | (curve))
471
472/** Whether a key type is an elliptic curve key (pair or public-only). */
473#define PSA_KEY_TYPE_IS_ECC(type) \
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100474 ((PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(type) & \
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100475 ~PSA_KEY_TYPE_ECC_CURVE_MASK) == PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE)
476/** Whether a key type is an elliptic curve key pair. */
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100477#define PSA_KEY_TYPE_IS_ECC_KEY_PAIR(type) \
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100478 (((type) & ~PSA_KEY_TYPE_ECC_CURVE_MASK) == \
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100479 PSA_KEY_TYPE_ECC_KEY_PAIR_BASE)
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100480/** Whether a key type is an elliptic curve public key. */
481#define PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY(type) \
482 (((type) & ~PSA_KEY_TYPE_ECC_CURVE_MASK) == \
483 PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE)
484
485/** Extract the curve from an elliptic curve key type. */
Summer Qin0e5b2e02020-10-22 11:23:39 +0800486#define PSA_KEY_TYPE_ECC_GET_FAMILY(type) \
487 ((psa_ecc_family_t) (PSA_KEY_TYPE_IS_ECC(type) ? \
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100488 ((type) & PSA_KEY_TYPE_ECC_CURVE_MASK) : \
489 0))
490
Soby Mathew07ef6e42020-07-20 21:09:23 +0100491/** SEC Koblitz curves over prime fields.
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100492 *
Soby Mathew07ef6e42020-07-20 21:09:23 +0100493 * This family comprises the following curves:
494 * secp192k1, secp224k1, secp256k1.
495 * They are defined in _Standards for Efficient Cryptography_,
496 * _SEC 2: Recommended Elliptic Curve Domain Parameters_.
497 * https://www.secg.org/sec2-v2.pdf
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100498 */
Summer Qin0e5b2e02020-10-22 11:23:39 +0800499#define PSA_ECC_FAMILY_SECP_K1 ((psa_ecc_family_t) 0x17)
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100500
Soby Mathew07ef6e42020-07-20 21:09:23 +0100501/** SEC random curves over prime fields.
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100502 *
Soby Mathew07ef6e42020-07-20 21:09:23 +0100503 * This family comprises the following curves:
504 * secp192k1, secp224r1, secp256r1, secp384r1, secp521r1.
505 * They are defined in _Standards for Efficient Cryptography_,
506 * _SEC 2: Recommended Elliptic Curve Domain Parameters_.
507 * https://www.secg.org/sec2-v2.pdf
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100508 */
Summer Qin0e5b2e02020-10-22 11:23:39 +0800509#define PSA_ECC_FAMILY_SECP_R1 ((psa_ecc_family_t) 0x12)
Soby Mathew07ef6e42020-07-20 21:09:23 +0100510/* SECP160R2 (SEC2 v1, obsolete) */
Summer Qin0e5b2e02020-10-22 11:23:39 +0800511#define PSA_ECC_FAMILY_SECP_R2 ((psa_ecc_family_t) 0x1b)
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100512
Soby Mathew07ef6e42020-07-20 21:09:23 +0100513/** SEC Koblitz curves over binary fields.
514 *
515 * This family comprises the following curves:
516 * sect163k1, sect233k1, sect239k1, sect283k1, sect409k1, sect571k1.
517 * They are defined in _Standards for Efficient Cryptography_,
518 * _SEC 2: Recommended Elliptic Curve Domain Parameters_.
519 * https://www.secg.org/sec2-v2.pdf
520 */
Summer Qin0e5b2e02020-10-22 11:23:39 +0800521#define PSA_ECC_FAMILY_SECT_K1 ((psa_ecc_family_t) 0x27)
Soby Mathew07ef6e42020-07-20 21:09:23 +0100522
523/** SEC random curves over binary fields.
524 *
525 * This family comprises the following curves:
526 * sect163r1, sect233r1, sect283r1, sect409r1, sect571r1.
527 * They are defined in _Standards for Efficient Cryptography_,
528 * _SEC 2: Recommended Elliptic Curve Domain Parameters_.
529 * https://www.secg.org/sec2-v2.pdf
530 */
Summer Qin0e5b2e02020-10-22 11:23:39 +0800531#define PSA_ECC_FAMILY_SECT_R1 ((psa_ecc_family_t) 0x22)
Soby Mathew07ef6e42020-07-20 21:09:23 +0100532
533/** SEC additional random curves over binary fields.
534 *
535 * This family comprises the following curve:
536 * sect163r2.
537 * It is defined in _Standards for Efficient Cryptography_,
538 * _SEC 2: Recommended Elliptic Curve Domain Parameters_.
539 * https://www.secg.org/sec2-v2.pdf
540 */
Summer Qin0e5b2e02020-10-22 11:23:39 +0800541#define PSA_ECC_FAMILY_SECT_R2 ((psa_ecc_family_t) 0x2b)
Soby Mathew07ef6e42020-07-20 21:09:23 +0100542
543/** Brainpool P random curves.
544 *
545 * This family comprises the following curves:
546 * brainpoolP160r1, brainpoolP192r1, brainpoolP224r1, brainpoolP256r1,
547 * brainpoolP320r1, brainpoolP384r1, brainpoolP512r1.
548 * It is defined in RFC 5639.
549 */
Summer Qin0e5b2e02020-10-22 11:23:39 +0800550#define PSA_ECC_FAMILY_BRAINPOOL_P_R1 ((psa_ecc_family_t) 0x30)
Soby Mathew07ef6e42020-07-20 21:09:23 +0100551
552/** Curve25519 and Curve448.
553 *
554 * This family comprises the following Montgomery curves:
555 * - 255-bit: Bernstein et al.,
556 * _Curve25519: new Diffie-Hellman speed records_, LNCS 3958, 2006.
557 * The algorithm #PSA_ALG_ECDH performs X25519 when used with this curve.
558 * - 448-bit: Hamburg,
559 * _Ed448-Goldilocks, a new elliptic curve_, NIST ECC Workshop, 2015.
560 * The algorithm #PSA_ALG_ECDH performs X448 when used with this curve.
561 */
Summer Qin0e5b2e02020-10-22 11:23:39 +0800562#define PSA_ECC_FAMILY_MONTGOMERY ((psa_ecc_family_t) 0x41)
Soby Mathew07ef6e42020-07-20 21:09:23 +0100563
564#define PSA_KEY_TYPE_DH_PUBLIC_KEY_BASE ((psa_key_type_t)0x4200)
565#define PSA_KEY_TYPE_DH_KEY_PAIR_BASE ((psa_key_type_t)0x7200)
566#define PSA_KEY_TYPE_DH_GROUP_MASK ((psa_key_type_t)0x00ff)
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100567/** Diffie-Hellman key pair.
568 *
Summer Qin0e5b2e02020-10-22 11:23:39 +0800569 * \param group A value of type ::psa_dh_family_t that identifies the
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100570 * Diffie-Hellman group to be used.
571 */
572#define PSA_KEY_TYPE_DH_KEY_PAIR(group) \
573 (PSA_KEY_TYPE_DH_KEY_PAIR_BASE | (group))
574/** Diffie-Hellman public key.
575 *
Summer Qin0e5b2e02020-10-22 11:23:39 +0800576 * \param group A value of type ::psa_dh_family_t that identifies the
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100577 * Diffie-Hellman group to be used.
578 */
579#define PSA_KEY_TYPE_DH_PUBLIC_KEY(group) \
580 (PSA_KEY_TYPE_DH_PUBLIC_KEY_BASE | (group))
581
582/** Whether a key type is a Diffie-Hellman key (pair or public-only). */
583#define PSA_KEY_TYPE_IS_DH(type) \
584 ((PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(type) & \
585 ~PSA_KEY_TYPE_DH_GROUP_MASK) == PSA_KEY_TYPE_DH_PUBLIC_KEY_BASE)
586/** Whether a key type is a Diffie-Hellman key pair. */
587#define PSA_KEY_TYPE_IS_DH_KEY_PAIR(type) \
588 (((type) & ~PSA_KEY_TYPE_DH_GROUP_MASK) == \
589 PSA_KEY_TYPE_DH_KEY_PAIR_BASE)
590/** Whether a key type is a Diffie-Hellman public key. */
591#define PSA_KEY_TYPE_IS_DH_PUBLIC_KEY(type) \
592 (((type) & ~PSA_KEY_TYPE_DH_GROUP_MASK) == \
593 PSA_KEY_TYPE_DH_PUBLIC_KEY_BASE)
594
595/** Extract the group from a Diffie-Hellman key type. */
Summer Qin0e5b2e02020-10-22 11:23:39 +0800596#define PSA_KEY_TYPE_DH_GET_FAMILY(type) \
597 ((psa_dh_family_t) (PSA_KEY_TYPE_IS_DH(type) ? \
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100598 ((type) & PSA_KEY_TYPE_DH_GROUP_MASK) : \
599 0))
600
Soby Mathew07ef6e42020-07-20 21:09:23 +0100601/** Diffie-Hellman groups defined in RFC 7919 Appendix A.
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100602 *
Soby Mathew07ef6e42020-07-20 21:09:23 +0100603 * This family includes groups with the following key sizes (in bits):
604 * 2048, 3072, 4096, 6144, 8192. A given implementation may support
605 * all of these sizes or only a subset.
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100606 */
Summer Qin0e5b2e02020-10-22 11:23:39 +0800607#define PSA_DH_FAMILY_RFC7919 ((psa_dh_family_t) 0x03)
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100608
Soby Mathew07ef6e42020-07-20 21:09:23 +0100609#define PSA_GET_KEY_TYPE_BLOCK_SIZE_EXPONENT(type) \
610 (((type) >> 8) & 7)
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100611/** The block size of a block cipher.
612 *
613 * \param type A cipher key type (value of type #psa_key_type_t).
614 *
615 * \return The block size for a block cipher, or 1 for a stream cipher.
616 * The return value is undefined if \p type is not a supported
617 * cipher key type.
618 *
619 * \note It is possible to build stream cipher algorithms on top of a block
620 * cipher, for example CTR mode (#PSA_ALG_CTR).
621 * This macro only takes the key type into account, so it cannot be
622 * used to determine the size of the data that #psa_cipher_update()
623 * might buffer for future processing in general.
624 *
625 * \note This macro returns a compile-time constant if its argument is one.
626 *
627 * \warning This macro may evaluate its argument multiple times.
628 */
Maulik Patel13b27cf2021-05-14 11:44:53 +0100629#define PSA_BLOCK_CIPHER_BLOCK_LENGTH(type) \
Soby Mathew07ef6e42020-07-20 21:09:23 +0100630 (((type) & PSA_KEY_TYPE_CATEGORY_MASK) == PSA_KEY_TYPE_CATEGORY_SYMMETRIC ? \
Maulik Patel13b27cf2021-05-14 11:44:53 +0100631 1u << PSA_GET_KEY_TYPE_BLOCK_SIZE_EXPONENT(type) : \
Soby Mathew07ef6e42020-07-20 21:09:23 +0100632 0u)
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100633
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100634/** Vendor-defined algorithm flag.
635 *
636 * Algorithms defined by this standard will never have the #PSA_ALG_VENDOR_FLAG
637 * bit set. Vendors who define additional algorithms must use an encoding with
638 * the #PSA_ALG_VENDOR_FLAG bit set and should respect the bitwise structure
639 * used by standard encodings whenever practical.
640 */
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100641#define PSA_ALG_VENDOR_FLAG ((psa_algorithm_t)0x80000000)
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100642
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100643#define PSA_ALG_CATEGORY_MASK ((psa_algorithm_t)0x7f000000)
Maulik Patel28659c42021-01-06 14:09:22 +0000644#define PSA_ALG_CATEGORY_HASH ((psa_algorithm_t)0x02000000)
645#define PSA_ALG_CATEGORY_MAC ((psa_algorithm_t)0x03000000)
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100646#define PSA_ALG_CATEGORY_CIPHER ((psa_algorithm_t)0x04000000)
Maulik Patel28659c42021-01-06 14:09:22 +0000647#define PSA_ALG_CATEGORY_AEAD ((psa_algorithm_t)0x05000000)
648#define PSA_ALG_CATEGORY_SIGN ((psa_algorithm_t)0x06000000)
649#define PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION ((psa_algorithm_t)0x07000000)
650#define PSA_ALG_CATEGORY_KEY_DERIVATION ((psa_algorithm_t)0x08000000)
651#define PSA_ALG_CATEGORY_KEY_AGREEMENT ((psa_algorithm_t)0x09000000)
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100652
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100653/** Whether an algorithm is vendor-defined.
654 *
655 * See also #PSA_ALG_VENDOR_FLAG.
656 */
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100657#define PSA_ALG_IS_VENDOR_DEFINED(alg) \
658 (((alg) & PSA_ALG_VENDOR_FLAG) != 0)
659
660/** Whether the specified algorithm is a hash algorithm.
661 *
662 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
663 *
664 * \return 1 if \p alg is a hash algorithm, 0 otherwise.
665 * This macro may return either 0 or 1 if \p alg is not a supported
666 * algorithm identifier.
667 */
668#define PSA_ALG_IS_HASH(alg) \
669 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_HASH)
670
671/** Whether the specified algorithm is a MAC algorithm.
672 *
673 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
674 *
675 * \return 1 if \p alg is a MAC algorithm, 0 otherwise.
676 * This macro may return either 0 or 1 if \p alg is not a supported
677 * algorithm identifier.
678 */
679#define PSA_ALG_IS_MAC(alg) \
680 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_MAC)
681
682/** Whether the specified algorithm is a symmetric cipher algorithm.
683 *
684 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
685 *
686 * \return 1 if \p alg is a symmetric cipher algorithm, 0 otherwise.
687 * This macro may return either 0 or 1 if \p alg is not a supported
688 * algorithm identifier.
689 */
690#define PSA_ALG_IS_CIPHER(alg) \
691 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_CIPHER)
692
693/** Whether the specified algorithm is an authenticated encryption
694 * with associated data (AEAD) algorithm.
695 *
696 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
697 *
698 * \return 1 if \p alg is an AEAD algorithm, 0 otherwise.
699 * This macro may return either 0 or 1 if \p alg is not a supported
700 * algorithm identifier.
701 */
702#define PSA_ALG_IS_AEAD(alg) \
703 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_AEAD)
704
Soby Mathew07ef6e42020-07-20 21:09:23 +0100705/** Whether the specified algorithm is an asymmetric signature algorithm,
706 * also known as public-key signature algorithm.
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100707 *
708 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
709 *
Soby Mathew07ef6e42020-07-20 21:09:23 +0100710 * \return 1 if \p alg is an asymmetric signature algorithm, 0 otherwise.
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100711 * This macro may return either 0 or 1 if \p alg is not a supported
712 * algorithm identifier.
713 */
714#define PSA_ALG_IS_SIGN(alg) \
715 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_SIGN)
716
Soby Mathew07ef6e42020-07-20 21:09:23 +0100717/** Whether the specified algorithm is an asymmetric encryption algorithm,
718 * also known as public-key encryption algorithm.
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100719 *
720 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
721 *
Soby Mathew07ef6e42020-07-20 21:09:23 +0100722 * \return 1 if \p alg is an asymmetric encryption algorithm, 0 otherwise.
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100723 * This macro may return either 0 or 1 if \p alg is not a supported
724 * algorithm identifier.
725 */
726#define PSA_ALG_IS_ASYMMETRIC_ENCRYPTION(alg) \
727 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION)
728
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100729/** Whether the specified algorithm is a key agreement algorithm.
730 *
731 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
732 *
733 * \return 1 if \p alg is a key agreement algorithm, 0 otherwise.
734 * This macro may return either 0 or 1 if \p alg is not a supported
735 * algorithm identifier.
736 */
737#define PSA_ALG_IS_KEY_AGREEMENT(alg) \
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100738 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_KEY_AGREEMENT)
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100739
740/** Whether the specified algorithm is a key derivation algorithm.
741 *
742 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
743 *
744 * \return 1 if \p alg is a key derivation algorithm, 0 otherwise.
745 * This macro may return either 0 or 1 if \p alg is not a supported
746 * algorithm identifier.
747 */
748#define PSA_ALG_IS_KEY_DERIVATION(alg) \
749 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_KEY_DERIVATION)
750
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100751#define PSA_ALG_HASH_MASK ((psa_algorithm_t)0x000000ff)
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100752/** MD2 */
Maulik Patel28659c42021-01-06 14:09:22 +0000753#define PSA_ALG_MD2 ((psa_algorithm_t)0x02000001)
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100754/** MD4 */
Maulik Patel28659c42021-01-06 14:09:22 +0000755#define PSA_ALG_MD4 ((psa_algorithm_t)0x02000002)
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100756/** MD5 */
Maulik Patel28659c42021-01-06 14:09:22 +0000757#define PSA_ALG_MD5 ((psa_algorithm_t)0x02000003)
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100758/** PSA_ALG_RIPEMD160 */
Maulik Patel28659c42021-01-06 14:09:22 +0000759#define PSA_ALG_RIPEMD160 ((psa_algorithm_t)0x02000004)
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100760/** SHA1 */
Maulik Patel28659c42021-01-06 14:09:22 +0000761#define PSA_ALG_SHA_1 ((psa_algorithm_t)0x02000005)
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100762/** SHA2-224 */
Maulik Patel28659c42021-01-06 14:09:22 +0000763#define PSA_ALG_SHA_224 ((psa_algorithm_t)0x02000008)
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100764/** SHA2-256 */
Maulik Patel28659c42021-01-06 14:09:22 +0000765#define PSA_ALG_SHA_256 ((psa_algorithm_t)0x02000009)
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100766/** SHA2-384 */
Maulik Patel28659c42021-01-06 14:09:22 +0000767#define PSA_ALG_SHA_384 ((psa_algorithm_t)0x0200000a)
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100768/** SHA2-512 */
Maulik Patel28659c42021-01-06 14:09:22 +0000769#define PSA_ALG_SHA_512 ((psa_algorithm_t)0x0200000b)
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100770/** SHA2-512/224 */
Maulik Patel28659c42021-01-06 14:09:22 +0000771#define PSA_ALG_SHA_512_224 ((psa_algorithm_t)0x0200000c)
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100772/** SHA2-512/256 */
Maulik Patel28659c42021-01-06 14:09:22 +0000773#define PSA_ALG_SHA_512_256 ((psa_algorithm_t)0x0200000d)
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100774/** SHA3-224 */
Maulik Patel28659c42021-01-06 14:09:22 +0000775#define PSA_ALG_SHA3_224 ((psa_algorithm_t)0x02000010)
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100776/** SHA3-256 */
Maulik Patel28659c42021-01-06 14:09:22 +0000777#define PSA_ALG_SHA3_256 ((psa_algorithm_t)0x02000011)
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100778/** SHA3-384 */
Maulik Patel28659c42021-01-06 14:09:22 +0000779#define PSA_ALG_SHA3_384 ((psa_algorithm_t)0x02000012)
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100780/** SHA3-512 */
Maulik Patel28659c42021-01-06 14:09:22 +0000781#define PSA_ALG_SHA3_512 ((psa_algorithm_t)0x02000013)
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100782
783/** In a hash-and-sign algorithm policy, allow any hash algorithm.
784 *
785 * This value may be used to form the algorithm usage field of a policy
786 * for a signature algorithm that is parametrized by a hash. The key
787 * may then be used to perform operations using the same signature
788 * algorithm parametrized with any supported hash.
789 *
790 * That is, suppose that `PSA_xxx_SIGNATURE` is one of the following macros:
791 * - #PSA_ALG_RSA_PKCS1V15_SIGN, #PSA_ALG_RSA_PSS,
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100792 * - #PSA_ALG_ECDSA, #PSA_ALG_DETERMINISTIC_ECDSA.
793 * Then you may create and use a key as follows:
794 * - Set the key usage field using #PSA_ALG_ANY_HASH, for example:
795 * ```
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100796 * psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_SIGN_HASH); // or VERIFY
797 * psa_set_key_algorithm(&attributes, PSA_xxx_SIGNATURE(PSA_ALG_ANY_HASH));
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100798 * ```
799 * - Import or generate key material.
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100800 * - Call psa_sign_hash() or psa_verify_hash(), passing
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100801 * an algorithm built from `PSA_xxx_SIGNATURE` and a specific hash. Each
802 * call to sign or verify a message may use a different hash.
803 * ```
Maulik Patel28659c42021-01-06 14:09:22 +0000804 * psa_sign_hash(key, PSA_xxx_SIGNATURE(PSA_ALG_SHA_256), ...);
805 * psa_sign_hash(key, PSA_xxx_SIGNATURE(PSA_ALG_SHA_512), ...);
806 * psa_sign_hash(key, PSA_xxx_SIGNATURE(PSA_ALG_SHA3_256), ...);
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100807 * ```
808 *
809 * This value may not be used to build other algorithms that are
810 * parametrized over a hash. For any valid use of this macro to build
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100811 * an algorithm \c alg, #PSA_ALG_IS_HASH_AND_SIGN(\c alg) is true.
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100812 *
813 * This value may not be used to build an algorithm specification to
814 * perform an operation. It is only valid to build policies.
815 */
Maulik Patel28659c42021-01-06 14:09:22 +0000816#define PSA_ALG_ANY_HASH ((psa_algorithm_t)0x020000ff)
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100817
818#define PSA_ALG_MAC_SUBCATEGORY_MASK ((psa_algorithm_t)0x00c00000)
Maulik Patel28659c42021-01-06 14:09:22 +0000819#define PSA_ALG_HMAC_BASE ((psa_algorithm_t)0x03800000)
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100820/** Macro to build an HMAC algorithm.
821 *
822 * For example, #PSA_ALG_HMAC(#PSA_ALG_SHA_256) is HMAC-SHA-256.
823 *
824 * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
825 * #PSA_ALG_IS_HASH(\p hash_alg) is true).
826 *
827 * \return The corresponding HMAC algorithm.
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100828 * \return Unspecified if \p hash_alg is not a supported
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100829 * hash algorithm.
830 */
831#define PSA_ALG_HMAC(hash_alg) \
832 (PSA_ALG_HMAC_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
833
834#define PSA_ALG_HMAC_GET_HASH(hmac_alg) \
835 (PSA_ALG_CATEGORY_HASH | ((hmac_alg) & PSA_ALG_HASH_MASK))
836
837/** Whether the specified algorithm is an HMAC algorithm.
838 *
839 * HMAC is a family of MAC algorithms that are based on a hash function.
840 *
841 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
842 *
843 * \return 1 if \p alg is an HMAC algorithm, 0 otherwise.
844 * This macro may return either 0 or 1 if \p alg is not a supported
845 * algorithm identifier.
846 */
847#define PSA_ALG_IS_HMAC(alg) \
848 (((alg) & (PSA_ALG_CATEGORY_MASK | PSA_ALG_MAC_SUBCATEGORY_MASK)) == \
849 PSA_ALG_HMAC_BASE)
850
851/* In the encoding of a MAC algorithm, the bits corresponding to
852 * PSA_ALG_MAC_TRUNCATION_MASK encode the length to which the MAC is
853 * truncated. As an exception, the value 0 means the untruncated algorithm,
854 * whatever its length is. The length is encoded in 6 bits, so it can
855 * reach up to 63; the largest MAC is 64 bytes so its trivial truncation
856 * to full length is correctly encoded as 0 and any non-trivial truncation
857 * is correctly encoded as a value between 1 and 63. */
Maulik Patel28659c42021-01-06 14:09:22 +0000858#define PSA_ALG_MAC_TRUNCATION_MASK ((psa_algorithm_t)0x003f0000)
859#define PSA_MAC_TRUNCATION_OFFSET 16
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100860
Maulik Patel13b27cf2021-05-14 11:44:53 +0100861/* In the encoding of a MAC algorithm, the bit corresponding to
862 * #PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG encodes the fact that the algorithm
863 * is a wildcard algorithm. A key with such wildcard algorithm as permitted
864 * algorithm policy can be used with any algorithm corresponding to the
865 * same base class and having a (potentially truncated) MAC length greater or
866 * equal than the one encoded in #PSA_ALG_MAC_TRUNCATION_MASK. */
867#define PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG ((psa_algorithm_t)0x00008000)
868
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100869/** Macro to build a truncated MAC algorithm.
870 *
871 * A truncated MAC algorithm is identical to the corresponding MAC
872 * algorithm except that the MAC value for the truncated algorithm
873 * consists of only the first \p mac_length bytes of the MAC value
874 * for the untruncated algorithm.
875 *
876 * \note This macro may allow constructing algorithm identifiers that
877 * are not valid, either because the specified length is larger
878 * than the untruncated MAC or because the specified length is
879 * smaller than permitted by the implementation.
880 *
881 * \note It is implementation-defined whether a truncated MAC that
882 * is truncated to the same length as the MAC of the untruncated
883 * algorithm is considered identical to the untruncated algorithm
884 * for policy comparison purposes.
885 *
886 * \param mac_alg A MAC algorithm identifier (value of type
887 * #psa_algorithm_t such that #PSA_ALG_IS_MAC(\p alg)
888 * is true). This may be a truncated or untruncated
889 * MAC algorithm.
890 * \param mac_length Desired length of the truncated MAC in bytes.
891 * This must be at most the full length of the MAC
892 * and must be at least an implementation-specified
893 * minimum. The implementation-specified minimum
894 * shall not be zero.
895 *
896 * \return The corresponding MAC algorithm with the specified
897 * length.
898 * \return Unspecified if \p alg is not a supported
899 * MAC algorithm or if \p mac_length is too small or
900 * too large for the specified MAC algorithm.
901 */
Maulik Patel13b27cf2021-05-14 11:44:53 +0100902#define PSA_ALG_TRUNCATED_MAC(mac_alg, mac_length) \
903 (((mac_alg) & ~(PSA_ALG_MAC_TRUNCATION_MASK | \
904 PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG)) | \
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100905 ((mac_length) << PSA_MAC_TRUNCATION_OFFSET & PSA_ALG_MAC_TRUNCATION_MASK))
906
907/** Macro to build the base MAC algorithm corresponding to a truncated
908 * MAC algorithm.
909 *
910 * \param mac_alg A MAC algorithm identifier (value of type
911 * #psa_algorithm_t such that #PSA_ALG_IS_MAC(\p alg)
912 * is true). This may be a truncated or untruncated
913 * MAC algorithm.
914 *
915 * \return The corresponding base MAC algorithm.
916 * \return Unspecified if \p alg is not a supported
917 * MAC algorithm.
918 */
Maulik Patel13b27cf2021-05-14 11:44:53 +0100919#define PSA_ALG_FULL_LENGTH_MAC(mac_alg) \
920 ((mac_alg) & ~(PSA_ALG_MAC_TRUNCATION_MASK | \
921 PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG))
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100922
923/** Length to which a MAC algorithm is truncated.
924 *
925 * \param mac_alg A MAC algorithm identifier (value of type
926 * #psa_algorithm_t such that #PSA_ALG_IS_MAC(\p alg)
927 * is true).
928 *
929 * \return Length of the truncated MAC in bytes.
930 * \return 0 if \p alg is a non-truncated MAC algorithm.
931 * \return Unspecified if \p alg is not a supported
932 * MAC algorithm.
933 */
934#define PSA_MAC_TRUNCATED_LENGTH(mac_alg) \
935 (((mac_alg) & PSA_ALG_MAC_TRUNCATION_MASK) >> PSA_MAC_TRUNCATION_OFFSET)
936
Maulik Patel13b27cf2021-05-14 11:44:53 +0100937/** Macro to build a MAC minimum-MAC-length wildcard algorithm.
938 *
939 * A minimum-MAC-length MAC wildcard algorithm permits all MAC algorithms
940 * sharing the same base algorithm, and where the (potentially truncated) MAC
941 * length of the specific algorithm is equal to or larger then the wildcard
942 * algorithm's minimum MAC length.
943 *
944 * \note When setting the minimum required MAC length to less than the
945 * smallest MAC length allowed by the base algorithm, this effectively
946 * becomes an 'any-MAC-length-allowed' policy for that base algorithm.
947 *
948 * \param mac_alg A MAC algorithm identifier (value of type
949 * #psa_algorithm_t such that #PSA_ALG_IS_MAC(\p mac_alg)
950 * is true).
951 * \param min_mac_length Desired minimum length of the message authentication
952 * code in bytes. This must be at most the untruncated
953 * length of the MAC and must be at least 1.
954 *
955 * \return The corresponding MAC wildcard algorithm with the
956 * specified minimum length.
957 * \return Unspecified if \p mac_alg is not a supported MAC
958 * algorithm or if \p min_mac_length is less than 1 or
959 * too large for the specified MAC algorithm.
960 */
961#define PSA_ALG_AT_LEAST_THIS_LENGTH_MAC(mac_alg, min_mac_length) \
962 ( PSA_ALG_TRUNCATED_MAC(mac_alg, min_mac_length) | \
963 PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG )
964
Maulik Patel28659c42021-01-06 14:09:22 +0000965#define PSA_ALG_CIPHER_MAC_BASE ((psa_algorithm_t)0x03c00000)
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100966/** The CBC-MAC construction over a block cipher
967 *
968 * \warning CBC-MAC is insecure in many cases.
969 * A more secure mode, such as #PSA_ALG_CMAC, is recommended.
970 */
Maulik Patel28659c42021-01-06 14:09:22 +0000971#define PSA_ALG_CBC_MAC ((psa_algorithm_t)0x03c00100)
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100972/** The CMAC construction over a block cipher */
Maulik Patel28659c42021-01-06 14:09:22 +0000973#define PSA_ALG_CMAC ((psa_algorithm_t)0x03c00200)
Jamie Fox0e54ebc2019-04-09 14:21:04 +0100974
975/** Whether the specified algorithm is a MAC algorithm based on a block cipher.
976 *
977 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
978 *
979 * \return 1 if \p alg is a MAC algorithm based on a block cipher, 0 otherwise.
980 * This macro may return either 0 or 1 if \p alg is not a supported
981 * algorithm identifier.
982 */
983#define PSA_ALG_IS_BLOCK_CIPHER_MAC(alg) \
984 (((alg) & (PSA_ALG_CATEGORY_MASK | PSA_ALG_MAC_SUBCATEGORY_MASK)) == \
985 PSA_ALG_CIPHER_MAC_BASE)
986
987#define PSA_ALG_CIPHER_STREAM_FLAG ((psa_algorithm_t)0x00800000)
988#define PSA_ALG_CIPHER_FROM_BLOCK_FLAG ((psa_algorithm_t)0x00400000)
989
990/** Whether the specified algorithm is a stream cipher.
991 *
992 * A stream cipher is a symmetric cipher that encrypts or decrypts messages
993 * by applying a bitwise-xor with a stream of bytes that is generated
994 * from a key.
995 *
996 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
997 *
998 * \return 1 if \p alg is a stream cipher algorithm, 0 otherwise.
999 * This macro may return either 0 or 1 if \p alg is not a supported
1000 * algorithm identifier or if it is not a symmetric cipher algorithm.
1001 */
1002#define PSA_ALG_IS_STREAM_CIPHER(alg) \
1003 (((alg) & (PSA_ALG_CATEGORY_MASK | PSA_ALG_CIPHER_STREAM_FLAG)) == \
1004 (PSA_ALG_CATEGORY_CIPHER | PSA_ALG_CIPHER_STREAM_FLAG))
1005
Maulik Patel28659c42021-01-06 14:09:22 +00001006/** The stream cipher mode of a stream cipher algorithm.
1007 *
1008 * The underlying stream cipher is determined by the key type.
1009 * - To use ChaCha20, use a key type of #PSA_KEY_TYPE_CHACHA20.
1010 * - To use ARC4, use a key type of #PSA_KEY_TYPE_ARC4.
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001011 */
Maulik Patel28659c42021-01-06 14:09:22 +00001012#define PSA_ALG_STREAM_CIPHER ((psa_algorithm_t)0x04800100)
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001013
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001014/** The CTR stream cipher mode.
1015 *
1016 * CTR is a stream cipher which is built from a block cipher.
1017 * The underlying block cipher is determined by the key type.
1018 * For example, to use AES-128-CTR, use this algorithm with
1019 * a key of type #PSA_KEY_TYPE_AES and a length of 128 bits (16 bytes).
1020 */
Maulik Patel28659c42021-01-06 14:09:22 +00001021#define PSA_ALG_CTR ((psa_algorithm_t)0x04c01000)
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001022
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001023/** The CFB stream cipher mode.
1024 *
1025 * The underlying block cipher is determined by the key type.
1026 */
Maulik Patel28659c42021-01-06 14:09:22 +00001027#define PSA_ALG_CFB ((psa_algorithm_t)0x04c01100)
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001028
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001029/** The OFB stream cipher mode.
1030 *
1031 * The underlying block cipher is determined by the key type.
1032 */
Maulik Patel28659c42021-01-06 14:09:22 +00001033#define PSA_ALG_OFB ((psa_algorithm_t)0x04c01200)
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001034
1035/** The XTS cipher mode.
1036 *
1037 * XTS is a cipher mode which is built from a block cipher. It requires at
1038 * least one full block of input, but beyond this minimum the input
1039 * does not need to be a whole number of blocks.
1040 */
Maulik Patel28659c42021-01-06 14:09:22 +00001041#define PSA_ALG_XTS ((psa_algorithm_t)0x0440ff00)
1042
1043/** The Electronic Code Book (ECB) mode of a block cipher, with no padding.
1044 *
1045 * \warning ECB mode does not protect the confidentiality of the encrypted data
1046 * except in extremely narrow circumstances. It is recommended that applications
1047 * only use ECB if they need to construct an operating mode that the
1048 * implementation does not provide. Implementations are encouraged to provide
1049 * the modes that applications need in preference to supporting direct access
1050 * to ECB.
1051 *
1052 * The underlying block cipher is determined by the key type.
1053 *
1054 * This symmetric cipher mode can only be used with messages whose lengths are a
1055 * multiple of the block size of the chosen block cipher.
1056 *
1057 * ECB mode does not accept an initialization vector (IV). When using a
1058 * multi-part cipher operation with this algorithm, psa_cipher_generate_iv()
1059 * and psa_cipher_set_iv() must not be called.
1060 */
1061#define PSA_ALG_ECB_NO_PADDING ((psa_algorithm_t)0x04404400)
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001062
1063/** The CBC block cipher chaining mode, with no padding.
1064 *
1065 * The underlying block cipher is determined by the key type.
1066 *
1067 * This symmetric cipher mode can only be used with messages whose lengths
1068 * are whole number of blocks for the chosen block cipher.
1069 */
Maulik Patel28659c42021-01-06 14:09:22 +00001070#define PSA_ALG_CBC_NO_PADDING ((psa_algorithm_t)0x04404000)
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001071
1072/** The CBC block cipher chaining mode with PKCS#7 padding.
1073 *
1074 * The underlying block cipher is determined by the key type.
1075 *
1076 * This is the padding method defined by PKCS#7 (RFC 2315) &sect;10.3.
1077 */
Maulik Patel28659c42021-01-06 14:09:22 +00001078#define PSA_ALG_CBC_PKCS7 ((psa_algorithm_t)0x04404100)
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001079
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001080#define PSA_ALG_AEAD_FROM_BLOCK_FLAG ((psa_algorithm_t)0x00400000)
1081
1082/** Whether the specified algorithm is an AEAD mode on a block cipher.
1083 *
1084 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
1085 *
1086 * \return 1 if \p alg is an AEAD algorithm which is an AEAD mode based on
1087 * a block cipher, 0 otherwise.
1088 * This macro may return either 0 or 1 if \p alg is not a supported
1089 * algorithm identifier.
1090 */
1091#define PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER(alg) \
1092 (((alg) & (PSA_ALG_CATEGORY_MASK | PSA_ALG_AEAD_FROM_BLOCK_FLAG)) == \
1093 (PSA_ALG_CATEGORY_AEAD | PSA_ALG_AEAD_FROM_BLOCK_FLAG))
1094
1095/** The CCM authenticated encryption algorithm.
1096 *
1097 * The underlying block cipher is determined by the key type.
1098 */
Maulik Patel28659c42021-01-06 14:09:22 +00001099#define PSA_ALG_CCM ((psa_algorithm_t)0x05500100)
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001100
1101/** The GCM authenticated encryption algorithm.
1102 *
1103 * The underlying block cipher is determined by the key type.
1104 */
Maulik Patel28659c42021-01-06 14:09:22 +00001105#define PSA_ALG_GCM ((psa_algorithm_t)0x05500200)
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001106
1107/** The Chacha20-Poly1305 AEAD algorithm.
1108 *
1109 * The ChaCha20_Poly1305 construction is defined in RFC 7539.
1110 *
1111 * Implementations must support 12-byte nonces, may support 8-byte nonces,
1112 * and should reject other sizes.
1113 *
1114 * Implementations must support 16-byte tags and should reject other sizes.
1115 */
Maulik Patel28659c42021-01-06 14:09:22 +00001116#define PSA_ALG_CHACHA20_POLY1305 ((psa_algorithm_t)0x05100500)
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001117
1118/* In the encoding of a AEAD algorithm, the bits corresponding to
1119 * PSA_ALG_AEAD_TAG_LENGTH_MASK encode the length of the AEAD tag.
1120 * The constants for default lengths follow this encoding.
1121 */
Maulik Patel28659c42021-01-06 14:09:22 +00001122#define PSA_ALG_AEAD_TAG_LENGTH_MASK ((psa_algorithm_t)0x003f0000)
1123#define PSA_AEAD_TAG_LENGTH_OFFSET 16
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001124
Maulik Patel13b27cf2021-05-14 11:44:53 +01001125/* In the encoding of an AEAD algorithm, the bit corresponding to
1126 * #PSA_ALG_AEAD_AT_LEAST_THIS_LENGTH_FLAG encodes the fact that the algorithm
1127 * is a wildcard algorithm. A key with such wildcard algorithm as permitted
1128 * algorithm policy can be used with any algorithm corresponding to the
1129 * same base class and having a tag length greater than or equal to the one
1130 * encoded in #PSA_ALG_AEAD_TAG_LENGTH_MASK. */
1131#define PSA_ALG_AEAD_AT_LEAST_THIS_LENGTH_FLAG ((psa_algorithm_t)0x00008000)
1132
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001133/** Macro to build a shortened AEAD algorithm.
1134 *
1135 * A shortened AEAD algorithm is similar to the corresponding AEAD
1136 * algorithm, but has an authentication tag that consists of fewer bytes.
1137 * Depending on the algorithm, the tag length may affect the calculation
1138 * of the ciphertext.
1139 *
1140 * \param aead_alg An AEAD algorithm identifier (value of type
1141 * #psa_algorithm_t such that #PSA_ALG_IS_AEAD(\p alg)
1142 * is true).
1143 * \param tag_length Desired length of the authentication tag in bytes.
1144 *
1145 * \return The corresponding AEAD algorithm with the specified
1146 * length.
1147 * \return Unspecified if \p alg is not a supported
1148 * AEAD algorithm or if \p tag_length is not valid
1149 * for the specified AEAD algorithm.
1150 */
Maulik Patel13b27cf2021-05-14 11:44:53 +01001151#define PSA_ALG_AEAD_WITH_SHORTENED_TAG(aead_alg, tag_length) \
1152 (((aead_alg) & ~(PSA_ALG_AEAD_TAG_LENGTH_MASK | \
1153 PSA_ALG_AEAD_AT_LEAST_THIS_LENGTH_FLAG)) | \
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001154 ((tag_length) << PSA_AEAD_TAG_LENGTH_OFFSET & \
1155 PSA_ALG_AEAD_TAG_LENGTH_MASK))
1156
Maulik Patel13b27cf2021-05-14 11:44:53 +01001157/** Retrieve the tag length of a specified AEAD algorithm
1158 *
1159 * \param aead_alg An AEAD algorithm identifier (value of type
1160 * #psa_algorithm_t such that #PSA_ALG_IS_AEAD(\p alg)
1161 * is true).
1162 *
1163 * \return The tag length specified by the input algorithm.
1164 * \return Unspecified if \p alg is not a supported
1165 * AEAD algorithm or if \p tag_length is not valid
1166 * for the specified AEAD algorithm.
1167 */
1168#define PSA_ALG_AEAD_GET_TAG_LENGTH(aead_alg) \
1169 (((aead_alg) & PSA_ALG_AEAD_TAG_LENGTH_MASK) >> \
1170 PSA_AEAD_TAG_LENGTH_OFFSET )
1171
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001172/** Calculate the corresponding AEAD algorithm with the default tag length.
1173 *
1174 * \param aead_alg An AEAD algorithm (\c PSA_ALG_XXX value such that
1175 * #PSA_ALG_IS_AEAD(\p alg) is true).
1176 *
1177 * \return The corresponding AEAD algorithm with the default
1178 * tag length for that algorithm.
1179 */
Maulik Patel13b27cf2021-05-14 11:44:53 +01001180#define PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG(aead_alg) \
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001181 ( \
Maulik Patel13b27cf2021-05-14 11:44:53 +01001182 PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG_CASE(aead_alg, PSA_ALG_CCM) \
1183 PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG_CASE(aead_alg, PSA_ALG_GCM) \
1184 PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG_CASE(aead_alg, PSA_ALG_CHACHA20_POLY1305) \
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001185 0)
Maulik Patel13b27cf2021-05-14 11:44:53 +01001186#define PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG_CASE(aead_alg, ref) \
1187 PSA_ALG_AEAD_WITH_SHORTENED_TAG(aead_alg, 0) == \
1188 PSA_ALG_AEAD_WITH_SHORTENED_TAG(ref, 0) ? \
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001189 ref :
1190
Maulik Patel13b27cf2021-05-14 11:44:53 +01001191/** Macro to build an AEAD minimum-tag-length wildcard algorithm.
1192 *
1193 * A minimum-tag-length AEAD wildcard algorithm permits all AEAD algorithms
1194 * sharing the same base algorithm, and where the tag length of the specific
1195 * algorithm is equal to or larger then the minimum tag length specified by the
1196 * wildcard algorithm.
1197 *
1198 * \note When setting the minimum required tag length to less than the
1199 * smallest tag length allowed by the base algorithm, this effectively
1200 * becomes an 'any-tag-length-allowed' policy for that base algorithm.
1201 *
1202 * \param aead_alg An AEAD algorithm identifier (value of type
1203 * #psa_algorithm_t such that
1204 * #PSA_ALG_IS_AEAD(\p aead_alg) is true).
1205 * \param min_tag_length Desired minimum length of the authentication tag in
1206 * bytes. This must be at least 1 and at most the largest
1207 * allowed tag length of the algorithm.
1208 *
1209 * \return The corresponding AEAD wildcard algorithm with the
1210 * specified minimum length.
1211 * \return Unspecified if \p aead_alg is not a supported
1212 * AEAD algorithm or if \p min_tag_length is less than 1
1213 * or too large for the specified AEAD algorithm.
1214 */
1215#define PSA_ALG_AEAD_WITH_AT_LEAST_THIS_LENGTH_TAG(aead_alg, min_tag_length) \
1216 ( PSA_ALG_AEAD_WITH_SHORTENED_TAG(aead_alg, min_tag_length) | \
1217 PSA_ALG_AEAD_AT_LEAST_THIS_LENGTH_FLAG )
1218
Maulik Patel28659c42021-01-06 14:09:22 +00001219#define PSA_ALG_RSA_PKCS1V15_SIGN_BASE ((psa_algorithm_t)0x06000200)
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001220/** RSA PKCS#1 v1.5 signature with hashing.
1221 *
1222 * This is the signature scheme defined by RFC 8017
1223 * (PKCS#1: RSA Cryptography Specifications) under the name
1224 * RSASSA-PKCS1-v1_5.
1225 *
1226 * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
1227 * #PSA_ALG_IS_HASH(\p hash_alg) is true).
1228 * This includes #PSA_ALG_ANY_HASH
1229 * when specifying the algorithm in a usage policy.
1230 *
1231 * \return The corresponding RSA PKCS#1 v1.5 signature algorithm.
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001232 * \return Unspecified if \p hash_alg is not a supported
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001233 * hash algorithm.
1234 */
1235#define PSA_ALG_RSA_PKCS1V15_SIGN(hash_alg) \
1236 (PSA_ALG_RSA_PKCS1V15_SIGN_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1237/** Raw PKCS#1 v1.5 signature.
1238 *
1239 * The input to this algorithm is the DigestInfo structure used by
1240 * RFC 8017 (PKCS#1: RSA Cryptography Specifications), &sect;9.2
1241 * steps 3&ndash;6.
1242 */
1243#define PSA_ALG_RSA_PKCS1V15_SIGN_RAW PSA_ALG_RSA_PKCS1V15_SIGN_BASE
1244#define PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) \
1245 (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_RSA_PKCS1V15_SIGN_BASE)
1246
Maulik Patel28659c42021-01-06 14:09:22 +00001247#define PSA_ALG_RSA_PSS_BASE ((psa_algorithm_t)0x06000300)
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001248/** RSA PSS signature with hashing.
1249 *
1250 * This is the signature scheme defined by RFC 8017
1251 * (PKCS#1: RSA Cryptography Specifications) under the name
1252 * RSASSA-PSS, with the message generation function MGF1, and with
1253 * a salt length equal to the length of the hash. The specified
1254 * hash algorithm is used to hash the input message, to create the
1255 * salted hash, and for the mask generation.
1256 *
1257 * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
1258 * #PSA_ALG_IS_HASH(\p hash_alg) is true).
1259 * This includes #PSA_ALG_ANY_HASH
1260 * when specifying the algorithm in a usage policy.
1261 *
1262 * \return The corresponding RSA PSS signature algorithm.
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001263 * \return Unspecified if \p hash_alg is not a supported
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001264 * hash algorithm.
1265 */
1266#define PSA_ALG_RSA_PSS(hash_alg) \
1267 (PSA_ALG_RSA_PSS_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1268#define PSA_ALG_IS_RSA_PSS(alg) \
1269 (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_RSA_PSS_BASE)
1270
Maulik Patel28659c42021-01-06 14:09:22 +00001271#define PSA_ALG_ECDSA_BASE ((psa_algorithm_t)0x06000600)
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001272/** ECDSA signature with hashing.
1273 *
1274 * This is the ECDSA signature scheme defined by ANSI X9.62,
1275 * with a random per-message secret number (*k*).
1276 *
1277 * The representation of the signature as a byte string consists of
1278 * the concatentation of the signature values *r* and *s*. Each of
1279 * *r* and *s* is encoded as an *N*-octet string, where *N* is the length
1280 * of the base point of the curve in octets. Each value is represented
1281 * in big-endian order (most significant octet first).
1282 *
1283 * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
1284 * #PSA_ALG_IS_HASH(\p hash_alg) is true).
1285 * This includes #PSA_ALG_ANY_HASH
1286 * when specifying the algorithm in a usage policy.
1287 *
1288 * \return The corresponding ECDSA signature algorithm.
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001289 * \return Unspecified if \p hash_alg is not a supported
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001290 * hash algorithm.
1291 */
1292#define PSA_ALG_ECDSA(hash_alg) \
1293 (PSA_ALG_ECDSA_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1294/** ECDSA signature without hashing.
1295 *
1296 * This is the same signature scheme as #PSA_ALG_ECDSA(), but
1297 * without specifying a hash algorithm. This algorithm may only be
1298 * used to sign or verify a sequence of bytes that should be an
1299 * already-calculated hash. Note that the input is padded with
1300 * zeros on the left or truncated on the left as required to fit
1301 * the curve size.
1302 */
1303#define PSA_ALG_ECDSA_ANY PSA_ALG_ECDSA_BASE
Maulik Patel28659c42021-01-06 14:09:22 +00001304#define PSA_ALG_DETERMINISTIC_ECDSA_BASE ((psa_algorithm_t)0x06000700)
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001305/** Deterministic ECDSA signature with hashing.
1306 *
1307 * This is the deterministic ECDSA signature scheme defined by RFC 6979.
1308 *
1309 * The representation of a signature is the same as with #PSA_ALG_ECDSA().
1310 *
1311 * Note that when this algorithm is used for verification, signatures
1312 * made with randomized ECDSA (#PSA_ALG_ECDSA(\p hash_alg)) with the
1313 * same private key are accepted. In other words,
1314 * #PSA_ALG_DETERMINISTIC_ECDSA(\p hash_alg) differs from
1315 * #PSA_ALG_ECDSA(\p hash_alg) only for signature, not for verification.
1316 *
1317 * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
1318 * #PSA_ALG_IS_HASH(\p hash_alg) is true).
1319 * This includes #PSA_ALG_ANY_HASH
1320 * when specifying the algorithm in a usage policy.
1321 *
1322 * \return The corresponding deterministic ECDSA signature
1323 * algorithm.
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001324 * \return Unspecified if \p hash_alg is not a supported
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001325 * hash algorithm.
1326 */
1327#define PSA_ALG_DETERMINISTIC_ECDSA(hash_alg) \
1328 (PSA_ALG_DETERMINISTIC_ECDSA_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
Maulik Patel28659c42021-01-06 14:09:22 +00001329#define PSA_ALG_ECDSA_DETERMINISTIC_FLAG ((psa_algorithm_t)0x00000100)
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001330#define PSA_ALG_IS_ECDSA(alg) \
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001331 (((alg) & ~PSA_ALG_HASH_MASK & ~PSA_ALG_ECDSA_DETERMINISTIC_FLAG) == \
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001332 PSA_ALG_ECDSA_BASE)
1333#define PSA_ALG_ECDSA_IS_DETERMINISTIC(alg) \
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001334 (((alg) & PSA_ALG_ECDSA_DETERMINISTIC_FLAG) != 0)
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001335#define PSA_ALG_IS_DETERMINISTIC_ECDSA(alg) \
1336 (PSA_ALG_IS_ECDSA(alg) && PSA_ALG_ECDSA_IS_DETERMINISTIC(alg))
1337#define PSA_ALG_IS_RANDOMIZED_ECDSA(alg) \
1338 (PSA_ALG_IS_ECDSA(alg) && !PSA_ALG_ECDSA_IS_DETERMINISTIC(alg))
1339
1340/** Whether the specified algorithm is a hash-and-sign algorithm.
1341 *
Soby Mathew07ef6e42020-07-20 21:09:23 +01001342 * Hash-and-sign algorithms are asymmetric (public-key) signature algorithms
1343 * structured in two parts: first the calculation of a hash in a way that
1344 * does not depend on the key, then the calculation of a signature from the
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001345 * hash value and the key.
1346 *
1347 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
1348 *
1349 * \return 1 if \p alg is a hash-and-sign algorithm, 0 otherwise.
1350 * This macro may return either 0 or 1 if \p alg is not a supported
1351 * algorithm identifier.
1352 */
1353#define PSA_ALG_IS_HASH_AND_SIGN(alg) \
1354 (PSA_ALG_IS_RSA_PSS(alg) || PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) || \
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001355 PSA_ALG_IS_ECDSA(alg))
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001356
1357/** Get the hash used by a hash-and-sign signature algorithm.
1358 *
1359 * A hash-and-sign algorithm is a signature algorithm which is
1360 * composed of two phases: first a hashing phase which does not use
1361 * the key and produces a hash of the input message, then a signing
1362 * phase which only uses the hash and the key and not the message
1363 * itself.
1364 *
1365 * \param alg A signature algorithm (\c PSA_ALG_XXX value such that
1366 * #PSA_ALG_IS_SIGN(\p alg) is true).
1367 *
1368 * \return The underlying hash algorithm if \p alg is a hash-and-sign
1369 * algorithm.
1370 * \return 0 if \p alg is a signature algorithm that does not
1371 * follow the hash-and-sign structure.
1372 * \return Unspecified if \p alg is not a signature algorithm or
1373 * if it is not supported by the implementation.
1374 */
1375#define PSA_ALG_SIGN_GET_HASH(alg) \
1376 (PSA_ALG_IS_HASH_AND_SIGN(alg) ? \
1377 ((alg) & PSA_ALG_HASH_MASK) == 0 ? /*"raw" algorithm*/ 0 : \
1378 ((alg) & PSA_ALG_HASH_MASK) | PSA_ALG_CATEGORY_HASH : \
1379 0)
1380
1381/** RSA PKCS#1 v1.5 encryption.
1382 */
Maulik Patel28659c42021-01-06 14:09:22 +00001383#define PSA_ALG_RSA_PKCS1V15_CRYPT ((psa_algorithm_t)0x07000200)
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001384
Maulik Patel28659c42021-01-06 14:09:22 +00001385#define PSA_ALG_RSA_OAEP_BASE ((psa_algorithm_t)0x07000300)
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001386/** RSA OAEP encryption.
1387 *
1388 * This is the encryption scheme defined by RFC 8017
1389 * (PKCS#1: RSA Cryptography Specifications) under the name
1390 * RSAES-OAEP, with the message generation function MGF1.
1391 *
1392 * \param hash_alg The hash algorithm (\c PSA_ALG_XXX value such that
1393 * #PSA_ALG_IS_HASH(\p hash_alg) is true) to use
1394 * for MGF1.
1395 *
Soby Mathew07ef6e42020-07-20 21:09:23 +01001396 * \return The corresponding RSA OAEP encryption algorithm.
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001397 * \return Unspecified if \p hash_alg is not a supported
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001398 * hash algorithm.
1399 */
1400#define PSA_ALG_RSA_OAEP(hash_alg) \
1401 (PSA_ALG_RSA_OAEP_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1402#define PSA_ALG_IS_RSA_OAEP(alg) \
1403 (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_RSA_OAEP_BASE)
1404#define PSA_ALG_RSA_OAEP_GET_HASH(alg) \
1405 (PSA_ALG_IS_RSA_OAEP(alg) ? \
1406 ((alg) & PSA_ALG_HASH_MASK) | PSA_ALG_CATEGORY_HASH : \
1407 0)
1408
Maulik Patel28659c42021-01-06 14:09:22 +00001409#define PSA_ALG_HKDF_BASE ((psa_algorithm_t)0x08000100)
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001410/** Macro to build an HKDF algorithm.
1411 *
1412 * For example, `PSA_ALG_HKDF(PSA_ALG_SHA256)` is HKDF using HMAC-SHA-256.
1413 *
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001414 * This key derivation algorithm uses the following inputs:
1415 * - #PSA_KEY_DERIVATION_INPUT_SALT is the salt used in the "extract" step.
1416 * It is optional; if omitted, the derivation uses an empty salt.
1417 * - #PSA_KEY_DERIVATION_INPUT_SECRET is the secret key used in the "extract" step.
1418 * - #PSA_KEY_DERIVATION_INPUT_INFO is the info string used in the "expand" step.
1419 * You must pass #PSA_KEY_DERIVATION_INPUT_SALT before #PSA_KEY_DERIVATION_INPUT_SECRET.
1420 * You may pass #PSA_KEY_DERIVATION_INPUT_INFO at any time after steup and before
1421 * starting to generate output.
1422 *
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001423 * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
1424 * #PSA_ALG_IS_HASH(\p hash_alg) is true).
1425 *
1426 * \return The corresponding HKDF algorithm.
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001427 * \return Unspecified if \p hash_alg is not a supported
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001428 * hash algorithm.
1429 */
1430#define PSA_ALG_HKDF(hash_alg) \
1431 (PSA_ALG_HKDF_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1432/** Whether the specified algorithm is an HKDF algorithm.
1433 *
1434 * HKDF is a family of key derivation algorithms that are based on a hash
1435 * function and the HMAC construction.
1436 *
1437 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
1438 *
1439 * \return 1 if \c alg is an HKDF algorithm, 0 otherwise.
1440 * This macro may return either 0 or 1 if \c alg is not a supported
1441 * key derivation algorithm identifier.
1442 */
1443#define PSA_ALG_IS_HKDF(alg) \
1444 (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_HKDF_BASE)
1445#define PSA_ALG_HKDF_GET_HASH(hkdf_alg) \
1446 (PSA_ALG_CATEGORY_HASH | ((hkdf_alg) & PSA_ALG_HASH_MASK))
1447
Maulik Patel28659c42021-01-06 14:09:22 +00001448#define PSA_ALG_TLS12_PRF_BASE ((psa_algorithm_t)0x08000200)
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001449/** Macro to build a TLS-1.2 PRF algorithm.
1450 *
1451 * TLS 1.2 uses a custom pseudorandom function (PRF) for key schedule,
1452 * specified in Section 5 of RFC 5246. It is based on HMAC and can be
1453 * used with either SHA-256 or SHA-384.
1454 *
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001455 * This key derivation algorithm uses the following inputs, which must be
1456 * passed in the order given here:
1457 * - #PSA_KEY_DERIVATION_INPUT_SEED is the seed.
1458 * - #PSA_KEY_DERIVATION_INPUT_SECRET is the secret key.
1459 * - #PSA_KEY_DERIVATION_INPUT_LABEL is the label.
1460 *
1461 * For the application to TLS-1.2 key expansion, the seed is the
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001462 * concatenation of ServerHello.Random + ClientHello.Random,
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001463 * and the label is "key expansion".
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001464 *
1465 * For example, `PSA_ALG_TLS12_PRF(PSA_ALG_SHA256)` represents the
1466 * TLS 1.2 PRF using HMAC-SHA-256.
1467 *
1468 * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
1469 * #PSA_ALG_IS_HASH(\p hash_alg) is true).
1470 *
1471 * \return The corresponding TLS-1.2 PRF algorithm.
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001472 * \return Unspecified if \p hash_alg is not a supported
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001473 * hash algorithm.
1474 */
1475#define PSA_ALG_TLS12_PRF(hash_alg) \
1476 (PSA_ALG_TLS12_PRF_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1477
1478/** Whether the specified algorithm is a TLS-1.2 PRF algorithm.
1479 *
1480 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
1481 *
1482 * \return 1 if \c alg is a TLS-1.2 PRF algorithm, 0 otherwise.
1483 * This macro may return either 0 or 1 if \c alg is not a supported
1484 * key derivation algorithm identifier.
1485 */
1486#define PSA_ALG_IS_TLS12_PRF(alg) \
1487 (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_TLS12_PRF_BASE)
1488#define PSA_ALG_TLS12_PRF_GET_HASH(hkdf_alg) \
1489 (PSA_ALG_CATEGORY_HASH | ((hkdf_alg) & PSA_ALG_HASH_MASK))
1490
Maulik Patel28659c42021-01-06 14:09:22 +00001491#define PSA_ALG_TLS12_PSK_TO_MS_BASE ((psa_algorithm_t)0x08000300)
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001492/** Macro to build a TLS-1.2 PSK-to-MasterSecret algorithm.
1493 *
1494 * In a pure-PSK handshake in TLS 1.2, the master secret is derived
1495 * from the PreSharedKey (PSK) through the application of padding
1496 * (RFC 4279, Section 2) and the TLS-1.2 PRF (RFC 5246, Section 5).
1497 * The latter is based on HMAC and can be used with either SHA-256
1498 * or SHA-384.
1499 *
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001500 * This key derivation algorithm uses the following inputs, which must be
1501 * passed in the order given here:
1502 * - #PSA_KEY_DERIVATION_INPUT_SEED is the seed.
1503 * - #PSA_KEY_DERIVATION_INPUT_SECRET is the secret key.
1504 * - #PSA_KEY_DERIVATION_INPUT_LABEL is the label.
1505 *
1506 * For the application to TLS-1.2, the seed (which is
1507 * forwarded to the TLS-1.2 PRF) is the concatenation of the
1508 * ClientHello.Random + ServerHello.Random,
1509 * and the label is "master secret" or "extended master secret".
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001510 *
1511 * For example, `PSA_ALG_TLS12_PSK_TO_MS(PSA_ALG_SHA256)` represents the
1512 * TLS-1.2 PSK to MasterSecret derivation PRF using HMAC-SHA-256.
1513 *
1514 * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
1515 * #PSA_ALG_IS_HASH(\p hash_alg) is true).
1516 *
1517 * \return The corresponding TLS-1.2 PSK to MS algorithm.
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001518 * \return Unspecified if \p hash_alg is not a supported
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001519 * hash algorithm.
1520 */
1521#define PSA_ALG_TLS12_PSK_TO_MS(hash_alg) \
1522 (PSA_ALG_TLS12_PSK_TO_MS_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1523
1524/** Whether the specified algorithm is a TLS-1.2 PSK to MS algorithm.
1525 *
1526 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
1527 *
1528 * \return 1 if \c alg is a TLS-1.2 PSK to MS algorithm, 0 otherwise.
1529 * This macro may return either 0 or 1 if \c alg is not a supported
1530 * key derivation algorithm identifier.
1531 */
1532#define PSA_ALG_IS_TLS12_PSK_TO_MS(alg) \
1533 (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_TLS12_PSK_TO_MS_BASE)
1534#define PSA_ALG_TLS12_PSK_TO_MS_GET_HASH(hkdf_alg) \
1535 (PSA_ALG_CATEGORY_HASH | ((hkdf_alg) & PSA_ALG_HASH_MASK))
1536
Maulik Patel28659c42021-01-06 14:09:22 +00001537#define PSA_ALG_KEY_DERIVATION_MASK ((psa_algorithm_t)0xfe00ffff)
1538#define PSA_ALG_KEY_AGREEMENT_MASK ((psa_algorithm_t)0xffff0000)
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001539
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001540/** Macro to build a combined algorithm that chains a key agreement with
1541 * a key derivation.
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001542 *
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001543 * \param ka_alg A key agreement algorithm (\c PSA_ALG_XXX value such
1544 * that #PSA_ALG_IS_KEY_AGREEMENT(\p ka_alg) is true).
1545 * \param kdf_alg A key derivation algorithm (\c PSA_ALG_XXX value such
1546 * that #PSA_ALG_IS_KEY_DERIVATION(\p kdf_alg) is true).
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001547 *
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001548 * \return The corresponding key agreement and derivation
1549 * algorithm.
1550 * \return Unspecified if \p ka_alg is not a supported
1551 * key agreement algorithm or \p kdf_alg is not a
1552 * supported key derivation algorithm.
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001553 */
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001554#define PSA_ALG_KEY_AGREEMENT(ka_alg, kdf_alg) \
1555 ((ka_alg) | (kdf_alg))
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001556
1557#define PSA_ALG_KEY_AGREEMENT_GET_KDF(alg) \
1558 (((alg) & PSA_ALG_KEY_DERIVATION_MASK) | PSA_ALG_CATEGORY_KEY_DERIVATION)
1559
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001560#define PSA_ALG_KEY_AGREEMENT_GET_BASE(alg) \
1561 (((alg) & PSA_ALG_KEY_AGREEMENT_MASK) | PSA_ALG_CATEGORY_KEY_AGREEMENT)
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001562
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001563/** Whether the specified algorithm is a raw key agreement algorithm.
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001564 *
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001565 * A raw key agreement algorithm is one that does not specify
1566 * a key derivation function.
1567 * Usually, raw key agreement algorithms are constructed directly with
1568 * a \c PSA_ALG_xxx macro while non-raw key agreement algorithms are
Maulik Patel28659c42021-01-06 14:09:22 +00001569 * constructed with #PSA_ALG_KEY_AGREEMENT().
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001570 *
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001571 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
1572 *
1573 * \return 1 if \p alg is a raw key agreement algorithm, 0 otherwise.
1574 * This macro may return either 0 or 1 if \p alg is not a supported
1575 * algorithm identifier.
1576 */
1577#define PSA_ALG_IS_RAW_KEY_AGREEMENT(alg) \
1578 (PSA_ALG_IS_KEY_AGREEMENT(alg) && \
1579 PSA_ALG_KEY_AGREEMENT_GET_KDF(alg) == PSA_ALG_CATEGORY_KEY_DERIVATION)
1580
1581#define PSA_ALG_IS_KEY_DERIVATION_OR_AGREEMENT(alg) \
1582 ((PSA_ALG_IS_KEY_DERIVATION(alg) || PSA_ALG_IS_KEY_AGREEMENT(alg)))
1583
1584/** The finite-field Diffie-Hellman (DH) key agreement algorithm.
1585 *
1586 * The shared secret produced by key agreement is
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001587 * `g^{ab}` in big-endian format.
1588 * It is `ceiling(m / 8)` bytes long where `m` is the size of the prime `p`
1589 * in bits.
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001590 */
Maulik Patel28659c42021-01-06 14:09:22 +00001591#define PSA_ALG_FFDH ((psa_algorithm_t)0x09010000)
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001592
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001593/** Whether the specified algorithm is a finite field Diffie-Hellman algorithm.
1594 *
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001595 * This includes the raw finite field Diffie-Hellman algorithm as well as
1596 * finite-field Diffie-Hellman followed by any supporter key derivation
1597 * algorithm.
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001598 *
1599 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
1600 *
1601 * \return 1 if \c alg is a finite field Diffie-Hellman algorithm, 0 otherwise.
1602 * This macro may return either 0 or 1 if \c alg is not a supported
1603 * key agreement algorithm identifier.
1604 */
1605#define PSA_ALG_IS_FFDH(alg) \
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001606 (PSA_ALG_KEY_AGREEMENT_GET_BASE(alg) == PSA_ALG_FFDH)
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001607
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001608/** The elliptic curve Diffie-Hellman (ECDH) key agreement algorithm.
1609 *
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001610 * The shared secret produced by key agreement is the x-coordinate of
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001611 * the shared secret point. It is always `ceiling(m / 8)` bytes long where
1612 * `m` is the bit size associated with the curve, i.e. the bit size of the
1613 * order of the curve's coordinate field. When `m` is not a multiple of 8,
1614 * the byte containing the most significant bit of the shared secret
1615 * is padded with zero bits. The byte order is either little-endian
1616 * or big-endian depending on the curve type.
1617 *
Summer Qin0e5b2e02020-10-22 11:23:39 +08001618 * - For Montgomery curves (curve types `PSA_ECC_FAMILY_CURVEXXX`),
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001619 * the shared secret is the x-coordinate of `d_A Q_B = d_B Q_A`
1620 * in little-endian byte order.
1621 * The bit size is 448 for Curve448 and 255 for Curve25519.
1622 * - For Weierstrass curves over prime fields (curve types
Summer Qin0e5b2e02020-10-22 11:23:39 +08001623 * `PSA_ECC_FAMILY_SECPXXX` and `PSA_ECC_FAMILY_BRAINPOOL_PXXX`),
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001624 * the shared secret is the x-coordinate of `d_A Q_B = d_B Q_A`
1625 * in big-endian byte order.
1626 * The bit size is `m = ceiling(log_2(p))` for the field `F_p`.
1627 * - For Weierstrass curves over binary fields (curve types
Summer Qin0e5b2e02020-10-22 11:23:39 +08001628 * `PSA_ECC_FAMILY_SECTXXX`),
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001629 * the shared secret is the x-coordinate of `d_A Q_B = d_B Q_A`
1630 * in big-endian byte order.
1631 * The bit size is `m` for the field `F_{2^m}`.
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001632 */
Maulik Patel28659c42021-01-06 14:09:22 +00001633#define PSA_ALG_ECDH ((psa_algorithm_t)0x09020000)
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001634
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001635/** Whether the specified algorithm is an elliptic curve Diffie-Hellman
1636 * algorithm.
1637 *
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001638 * This includes the raw elliptic curve Diffie-Hellman algorithm as well as
1639 * elliptic curve Diffie-Hellman followed by any supporter key derivation
1640 * algorithm.
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001641 *
1642 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
1643 *
1644 * \return 1 if \c alg is an elliptic curve Diffie-Hellman algorithm,
1645 * 0 otherwise.
1646 * This macro may return either 0 or 1 if \c alg is not a supported
1647 * key agreement algorithm identifier.
1648 */
1649#define PSA_ALG_IS_ECDH(alg) \
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001650 (PSA_ALG_KEY_AGREEMENT_GET_BASE(alg) == PSA_ALG_ECDH)
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001651
1652/** Whether the specified algorithm encoding is a wildcard.
1653 *
1654 * Wildcard values may only be used to set the usage algorithm field in
1655 * a policy, not to perform an operation.
1656 *
1657 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
1658 *
1659 * \return 1 if \c alg is a wildcard algorithm encoding.
1660 * \return 0 if \c alg is a non-wildcard algorithm encoding (suitable for
1661 * an operation).
1662 * \return This macro may return either 0 or 1 if \c alg is not a supported
1663 * algorithm identifier.
1664 */
Maulik Patel13b27cf2021-05-14 11:44:53 +01001665#define PSA_ALG_IS_WILDCARD(alg) \
1666 (PSA_ALG_IS_HASH_AND_SIGN(alg) ? \
1667 PSA_ALG_SIGN_GET_HASH(alg) == PSA_ALG_ANY_HASH : \
1668 PSA_ALG_IS_MAC(alg) ? \
1669 (alg & PSA_ALG_MAC_AT_LEAST_THIS_LENGTH_FLAG) != 0 : \
1670 PSA_ALG_IS_AEAD(alg) ? \
1671 (alg & PSA_ALG_AEAD_AT_LEAST_THIS_LENGTH_FLAG) != 0 : \
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001672 (alg) == PSA_ALG_ANY_HASH)
1673
1674/**@}*/
1675
1676/** \defgroup key_lifetimes Key lifetimes
1677 * @{
1678 */
1679
Soby Mathew07ef6e42020-07-20 21:09:23 +01001680/** The default lifetime for volatile keys.
1681 *
Maulik Patel28659c42021-01-06 14:09:22 +00001682 * A volatile key only exists as long as the identifier to it is not destroyed.
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001683 * The key material is guaranteed to be erased on a power reset.
Soby Mathew07ef6e42020-07-20 21:09:23 +01001684 *
1685 * A key with this lifetime is typically stored in the RAM area of the
1686 * PSA Crypto subsystem. However this is an implementation choice.
1687 * If an implementation stores data about the key in a non-volatile memory,
1688 * it must release all the resources associated with the key and erase the
1689 * key material if the calling application terminates.
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001690 */
1691#define PSA_KEY_LIFETIME_VOLATILE ((psa_key_lifetime_t)0x00000000)
1692
Soby Mathew07ef6e42020-07-20 21:09:23 +01001693/** The default lifetime for persistent keys.
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001694 *
1695 * A persistent key remains in storage until it is explicitly destroyed or
1696 * until the corresponding storage area is wiped. This specification does
Maulik Patel13b27cf2021-05-14 11:44:53 +01001697 * not define any mechanism to wipe a storage area, but integrations may
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001698 * provide their own mechanism (for example to perform a factory reset,
1699 * to prepare for device refurbishment, or to uninstall an application).
1700 *
1701 * This lifetime value is the default storage area for the calling
Maulik Patel13b27cf2021-05-14 11:44:53 +01001702 * application. Integrations of Mbed TLS may support other persistent lifetimes.
Soby Mathew07ef6e42020-07-20 21:09:23 +01001703 * See ::psa_key_lifetime_t for more information.
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001704 */
1705#define PSA_KEY_LIFETIME_PERSISTENT ((psa_key_lifetime_t)0x00000001)
1706
Soby Mathew07ef6e42020-07-20 21:09:23 +01001707/** The persistence level of volatile keys.
1708 *
1709 * See ::psa_key_persistence_t for more information.
1710 */
1711#define PSA_KEY_PERSISTENCE_VOLATILE ((psa_key_persistence_t)0x00)
1712
1713/** The default persistence level for persistent keys.
1714 *
1715 * See ::psa_key_persistence_t for more information.
1716 */
1717#define PSA_KEY_PERSISTENCE_DEFAULT ((psa_key_persistence_t)0x01)
1718
1719/** A persistence level indicating that a key is never destroyed.
1720 *
1721 * See ::psa_key_persistence_t for more information.
1722 */
1723#define PSA_KEY_PERSISTENCE_READ_ONLY ((psa_key_persistence_t)0xff)
1724
1725#define PSA_KEY_LIFETIME_GET_PERSISTENCE(lifetime) \
1726 ((psa_key_persistence_t)((lifetime) & 0x000000ff))
1727
1728#define PSA_KEY_LIFETIME_GET_LOCATION(lifetime) \
1729 ((psa_key_location_t)((lifetime) >> 8))
1730
1731/** Whether a key lifetime indicates that the key is volatile.
1732 *
1733 * A volatile key is automatically destroyed by the implementation when
1734 * the application instance terminates. In particular, a volatile key
1735 * is automatically destroyed on a power reset of the device.
1736 *
1737 * A key that is not volatile is persistent. Persistent keys are
1738 * preserved until the application explicitly destroys them or until an
1739 * implementation-specific device management event occurs (for example,
1740 * a factory reset).
1741 *
1742 * \param lifetime The lifetime value to query (value of type
1743 * ::psa_key_lifetime_t).
1744 *
1745 * \return \c 1 if the key is volatile, otherwise \c 0.
1746 */
1747#define PSA_KEY_LIFETIME_IS_VOLATILE(lifetime) \
1748 (PSA_KEY_LIFETIME_GET_PERSISTENCE(lifetime) == \
Summer Qin0e5b2e02020-10-22 11:23:39 +08001749 PSA_KEY_PERSISTENCE_VOLATILE)
Soby Mathew07ef6e42020-07-20 21:09:23 +01001750
1751/** Construct a lifetime from a persistence level and a location.
1752 *
1753 * \param persistence The persistence level
1754 * (value of type ::psa_key_persistence_t).
1755 * \param location The location indicator
1756 * (value of type ::psa_key_location_t).
1757 *
1758 * \return The constructed lifetime value.
1759 */
1760#define PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(persistence, location) \
1761 ((location) << 8 | (persistence))
1762
1763/** The local storage area for persistent keys.
1764 *
1765 * This storage area is available on all systems that can store persistent
1766 * keys without delegating the storage to a third-party cryptoprocessor.
1767 *
1768 * See ::psa_key_location_t for more information.
1769 */
1770#define PSA_KEY_LOCATION_LOCAL_STORAGE ((psa_key_location_t)0x000000)
1771
1772#define PSA_KEY_LOCATION_VENDOR_FLAG ((psa_key_location_t)0x800000)
1773
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001774/** The minimum value for a key identifier chosen by the application.
1775 */
Soby Mathewd7b79f22020-05-21 15:06:54 +01001776#define PSA_KEY_ID_USER_MIN ((psa_key_id_t)0x00000001)
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001777/** The maximum value for a key identifier chosen by the application.
1778 */
Soby Mathewd7b79f22020-05-21 15:06:54 +01001779#define PSA_KEY_ID_USER_MAX ((psa_key_id_t)0x3fffffff)
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001780/** The minimum value for a key identifier chosen by the implementation.
1781 */
Soby Mathewd7b79f22020-05-21 15:06:54 +01001782#define PSA_KEY_ID_VENDOR_MIN ((psa_key_id_t)0x40000000)
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001783/** The maximum value for a key identifier chosen by the implementation.
1784 */
Soby Mathewd7b79f22020-05-21 15:06:54 +01001785#define PSA_KEY_ID_VENDOR_MAX ((psa_key_id_t)0x7fffffff)
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001786
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001787/**@}*/
1788
1789/** \defgroup policy Key policies
1790 * @{
1791 */
1792
1793/** Whether the key may be exported.
1794 *
1795 * A public key or the public part of a key pair may always be exported
1796 * regardless of the value of this permission flag.
1797 *
1798 * If a key does not have export permission, implementations shall not
1799 * allow the key to be exported in plain form from the cryptoprocessor,
1800 * whether through psa_export_key() or through a proprietary interface.
1801 * The key may however be exportable in a wrapped form, i.e. in a form
1802 * where it is encrypted by another key.
1803 */
1804#define PSA_KEY_USAGE_EXPORT ((psa_key_usage_t)0x00000001)
1805
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001806/** Whether the key may be copied.
1807 *
1808 * This flag allows the use of psa_copy_key() to make a copy of the key
1809 * with the same policy or a more restrictive policy.
1810 *
1811 * For lifetimes for which the key is located in a secure element which
1812 * enforce the non-exportability of keys, copying a key outside the secure
1813 * element also requires the usage flag #PSA_KEY_USAGE_EXPORT.
1814 * Copying the key inside the secure element is permitted with just
1815 * #PSA_KEY_USAGE_COPY if the secure element supports it.
1816 * For keys with the lifetime #PSA_KEY_LIFETIME_VOLATILE or
1817 * #PSA_KEY_LIFETIME_PERSISTENT, the usage flag #PSA_KEY_USAGE_COPY
1818 * is sufficient to permit the copy.
1819 */
1820#define PSA_KEY_USAGE_COPY ((psa_key_usage_t)0x00000002)
1821
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001822/** Whether the key may be used to encrypt a message.
1823 *
1824 * This flag allows the key to be used for a symmetric encryption operation,
1825 * for an AEAD encryption-and-authentication operation,
1826 * or for an asymmetric encryption operation,
1827 * if otherwise permitted by the key's type and policy.
1828 *
1829 * For a key pair, this concerns the public key.
1830 */
1831#define PSA_KEY_USAGE_ENCRYPT ((psa_key_usage_t)0x00000100)
1832
1833/** Whether the key may be used to decrypt a message.
1834 *
1835 * This flag allows the key to be used for a symmetric decryption operation,
1836 * for an AEAD decryption-and-verification operation,
1837 * or for an asymmetric decryption operation,
1838 * if otherwise permitted by the key's type and policy.
1839 *
1840 * For a key pair, this concerns the private key.
1841 */
1842#define PSA_KEY_USAGE_DECRYPT ((psa_key_usage_t)0x00000200)
1843
1844/** Whether the key may be used to sign a message.
1845 *
1846 * This flag allows the key to be used for a MAC calculation operation
1847 * or for an asymmetric signature operation,
1848 * if otherwise permitted by the key's type and policy.
1849 *
1850 * For a key pair, this concerns the private key.
1851 */
Maulik Patel28659c42021-01-06 14:09:22 +00001852#define PSA_KEY_USAGE_SIGN_HASH ((psa_key_usage_t)0x00001000)
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001853
1854/** Whether the key may be used to verify a message signature.
1855 *
1856 * This flag allows the key to be used for a MAC verification operation
1857 * or for an asymmetric signature verification operation,
1858 * if otherwise permitted by by the key's type and policy.
1859 *
1860 * For a key pair, this concerns the public key.
1861 */
Maulik Patel28659c42021-01-06 14:09:22 +00001862#define PSA_KEY_USAGE_VERIFY_HASH ((psa_key_usage_t)0x00002000)
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001863
1864/** Whether the key may be used to derive other keys.
1865 */
Maulik Patel28659c42021-01-06 14:09:22 +00001866#define PSA_KEY_USAGE_DERIVE ((psa_key_usage_t)0x00004000)
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001867
1868/**@}*/
1869
Antonio de Angelis04debbd2019-10-14 12:12:52 +01001870/** \defgroup derivation Key derivation
1871 * @{
1872 */
1873
1874/** A secret input for key derivation.
1875 *
1876 * This should be a key of type #PSA_KEY_TYPE_DERIVE
1877 * (passed to psa_key_derivation_input_key())
1878 * or the shared secret resulting from a key agreement
1879 * (obtained via psa_key_derivation_key_agreement()).
1880 *
1881 * The secret can also be a direct input (passed to
1882 * key_derivation_input_bytes()). In this case, the derivation operation
1883 * may not be used to derive keys: the operation will only allow
1884 * psa_key_derivation_output_bytes(), not psa_key_derivation_output_key().
1885 */
1886#define PSA_KEY_DERIVATION_INPUT_SECRET ((psa_key_derivation_step_t)0x0101)
1887
1888/** A label for key derivation.
1889 *
1890 * This should be a direct input.
1891 * It can also be a key of type #PSA_KEY_TYPE_RAW_DATA.
1892 */
1893#define PSA_KEY_DERIVATION_INPUT_LABEL ((psa_key_derivation_step_t)0x0201)
1894
1895/** A salt for key derivation.
1896 *
1897 * This should be a direct input.
1898 * It can also be a key of type #PSA_KEY_TYPE_RAW_DATA.
1899 */
1900#define PSA_KEY_DERIVATION_INPUT_SALT ((psa_key_derivation_step_t)0x0202)
1901
1902/** An information string for key derivation.
1903 *
1904 * This should be a direct input.
1905 * It can also be a key of type #PSA_KEY_TYPE_RAW_DATA.
1906 */
1907#define PSA_KEY_DERIVATION_INPUT_INFO ((psa_key_derivation_step_t)0x0203)
1908
1909/** A seed for key derivation.
1910 *
1911 * This should be a direct input.
1912 * It can also be a key of type #PSA_KEY_TYPE_RAW_DATA.
1913 */
1914#define PSA_KEY_DERIVATION_INPUT_SEED ((psa_key_derivation_step_t)0x0204)
1915
1916/**@}*/
1917
Jamie Fox0e54ebc2019-04-09 14:21:04 +01001918#endif /* PSA_CRYPTO_VALUES_H */