blob: 83a65053df20cfc1c967334600ee2e11f0fcfedb [file] [log] [blame]
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001/**
2 * \file psa/crypto_values.h
3 *
4 * \brief PSA cryptography module: macros to build and analyze integer values.
5 *
6 * \note This file may not be included directly. Applications must
7 * include psa/crypto.h. Drivers must include the appropriate driver
8 * header file.
9 *
10 * This file contains portable definitions of macros to build and analyze
11 * values of integral types that encode properties of cryptographic keys,
12 * designations of cryptographic algorithms, and error codes returned by
13 * the library.
14 *
15 * This header file only defines preprocessor macros.
16 */
17/*
18 * Copyright (C) 2018, ARM Limited, All Rights Reserved
19 * SPDX-License-Identifier: Apache-2.0
20 *
21 * Licensed under the Apache License, Version 2.0 (the "License"); you may
22 * not use this file except in compliance with the License.
23 * You may obtain a copy of the License at
24 *
25 * http://www.apache.org/licenses/LICENSE-2.0
26 *
27 * Unless required by applicable law or agreed to in writing, software
28 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
29 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30 * See the License for the specific language governing permissions and
31 * limitations under the License.
32 *
33 * This file is part of mbed TLS (https://tls.mbed.org)
34 */
35
36#ifndef PSA_CRYPTO_VALUES_H
37#define PSA_CRYPTO_VALUES_H
38
39/** \defgroup error Error codes
40 * @{
41 */
42
David Saadab4ecc272019-02-14 13:48:10 +020043/* PSA error codes */
44
Gilles Peskinef3b731e2018-12-12 13:38:31 +010045/** The action was completed successfully. */
46#define PSA_SUCCESS ((psa_status_t)0)
Gilles Peskinef3b731e2018-12-12 13:38:31 +010047
48/** An error occurred that does not correspond to any defined
49 * failure cause.
50 *
51 * Implementations may use this error code if none of the other standard
52 * error codes are applicable. */
David Saadab4ecc272019-02-14 13:48:10 +020053#define PSA_ERROR_GENERIC_ERROR ((psa_status_t)-132)
Gilles Peskinef3b731e2018-12-12 13:38:31 +010054
55/** The requested operation or a parameter is not supported
56 * by this implementation.
57 *
58 * Implementations should return this error code when an enumeration
59 * parameter such as a key type, algorithm, etc. is not recognized.
60 * If a combination of parameters is recognized and identified as
61 * not valid, return #PSA_ERROR_INVALID_ARGUMENT instead. */
David Saadab4ecc272019-02-14 13:48:10 +020062#define PSA_ERROR_NOT_SUPPORTED ((psa_status_t)-134)
Gilles Peskinef3b731e2018-12-12 13:38:31 +010063
64/** The requested action is denied by a policy.
65 *
66 * Implementations should return this error code when the parameters
67 * are recognized as valid and supported, and a policy explicitly
68 * denies the requested operation.
69 *
70 * If a subset of the parameters of a function call identify a
71 * forbidden operation, and another subset of the parameters are
72 * not valid or not supported, it is unspecified whether the function
73 * returns #PSA_ERROR_NOT_PERMITTED, #PSA_ERROR_NOT_SUPPORTED or
74 * #PSA_ERROR_INVALID_ARGUMENT. */
David Saadab4ecc272019-02-14 13:48:10 +020075#define PSA_ERROR_NOT_PERMITTED ((psa_status_t)-133)
Gilles Peskinef3b731e2018-12-12 13:38:31 +010076
77/** An output buffer is too small.
78 *
79 * Applications can call the \c PSA_xxx_SIZE macro listed in the function
80 * description to determine a sufficient buffer size.
81 *
82 * Implementations should preferably return this error code only
83 * in cases when performing the operation with a larger output
84 * buffer would succeed. However implementations may return this
85 * error if a function has invalid or unsupported parameters in addition
86 * to the parameters that determine the necessary output buffer size. */
David Saadab4ecc272019-02-14 13:48:10 +020087#define PSA_ERROR_BUFFER_TOO_SMALL ((psa_status_t)-138)
Gilles Peskinef3b731e2018-12-12 13:38:31 +010088
David Saadab4ecc272019-02-14 13:48:10 +020089/** Asking for an item that already exists
Gilles Peskinef3b731e2018-12-12 13:38:31 +010090 *
David Saadab4ecc272019-02-14 13:48:10 +020091 * Implementations should return this error, when attempting
92 * to write an item (like a key) that already exists. */
93#define PSA_ERROR_ALREADY_EXISTS ((psa_status_t)-139)
Gilles Peskinef3b731e2018-12-12 13:38:31 +010094
David Saadab4ecc272019-02-14 13:48:10 +020095/** Asking for an item that doesn't exist
Gilles Peskinef3b731e2018-12-12 13:38:31 +010096 *
David Saadab4ecc272019-02-14 13:48:10 +020097 * Implementations should return this error, if a requested item (like
98 * a key) does not exist. */
99#define PSA_ERROR_DOES_NOT_EXIST ((psa_status_t)-140)
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100100
101/** The requested action cannot be performed in the current state.
102 *
103 * Multipart operations return this error when one of the
104 * functions is called out of sequence. Refer to the function
105 * descriptions for permitted sequencing of functions.
106 *
107 * Implementations shall not return this error code to indicate
Adrian L. Shaw67e1c7a2019-05-14 15:24:21 +0100108 * that a key either exists or not,
109 * but shall instead return #PSA_ERROR_ALREADY_EXISTS or #PSA_ERROR_DOES_NOT_EXIST
Adrian L. Shawd56456c2019-05-15 11:36:13 +0100110 * as applicable.
111 *
112 * Implementations shall not return this error code to indicate that a
113 * key handle is invalid, but shall return #PSA_ERROR_INVALID_HANDLE
114 * instead. */
David Saadab4ecc272019-02-14 13:48:10 +0200115#define PSA_ERROR_BAD_STATE ((psa_status_t)-137)
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100116
117/** The parameters passed to the function are invalid.
118 *
119 * Implementations may return this error any time a parameter or
120 * combination of parameters are recognized as invalid.
121 *
Adrian L. Shawd56456c2019-05-15 11:36:13 +0100122 * Implementations shall not return this error code to indicate that a
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100123 * key handle is invalid, but shall return #PSA_ERROR_INVALID_HANDLE
124 * instead.
125 */
David Saadab4ecc272019-02-14 13:48:10 +0200126#define PSA_ERROR_INVALID_ARGUMENT ((psa_status_t)-135)
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100127
128/** There is not enough runtime memory.
129 *
130 * If the action is carried out across multiple security realms, this
131 * error can refer to available memory in any of the security realms. */
David Saadab4ecc272019-02-14 13:48:10 +0200132#define PSA_ERROR_INSUFFICIENT_MEMORY ((psa_status_t)-141)
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100133
134/** There is not enough persistent storage.
135 *
136 * Functions that modify the key storage return this error code if
137 * there is insufficient storage space on the host media. In addition,
138 * many functions that do not otherwise access storage may return this
139 * error code if the implementation requires a mandatory log entry for
140 * the requested action and the log storage space is full. */
David Saadab4ecc272019-02-14 13:48:10 +0200141#define PSA_ERROR_INSUFFICIENT_STORAGE ((psa_status_t)-142)
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100142
143/** There was a communication failure inside the implementation.
144 *
145 * This can indicate a communication failure between the application
146 * and an external cryptoprocessor or between the cryptoprocessor and
147 * an external volatile or persistent memory. A communication failure
148 * may be transient or permanent depending on the cause.
149 *
150 * \warning If a function returns this error, it is undetermined
151 * whether the requested action has completed or not. Implementations
152 * should return #PSA_SUCCESS on successful completion whenver
153 * possible, however functions may return #PSA_ERROR_COMMUNICATION_FAILURE
154 * if the requested action was completed successfully in an external
155 * cryptoprocessor but there was a breakdown of communication before
156 * the cryptoprocessor could report the status to the application.
157 */
David Saadab4ecc272019-02-14 13:48:10 +0200158#define PSA_ERROR_COMMUNICATION_FAILURE ((psa_status_t)-145)
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100159
160/** There was a storage failure that may have led to data loss.
161 *
162 * This error indicates that some persistent storage is corrupted.
163 * It should not be used for a corruption of volatile memory
164 * (use #PSA_ERROR_TAMPERING_DETECTED), for a communication error
165 * between the cryptoprocessor and its external storage (use
166 * #PSA_ERROR_COMMUNICATION_FAILURE), or when the storage is
167 * in a valid state but is full (use #PSA_ERROR_INSUFFICIENT_STORAGE).
168 *
169 * Note that a storage failure does not indicate that any data that was
170 * previously read is invalid. However this previously read data may no
171 * longer be readable from storage.
172 *
173 * When a storage failure occurs, it is no longer possible to ensure
174 * the global integrity of the keystore. Depending on the global
175 * integrity guarantees offered by the implementation, access to other
176 * data may or may not fail even if the data is still readable but
Gilles Peskinebf7a98b2019-02-22 16:42:11 +0100177 * its integrity cannot be guaranteed.
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100178 *
179 * Implementations should only use this error code to report a
180 * permanent storage corruption. However application writers should
181 * keep in mind that transient errors while reading the storage may be
182 * reported using this error code. */
David Saadab4ecc272019-02-14 13:48:10 +0200183#define PSA_ERROR_STORAGE_FAILURE ((psa_status_t)-146)
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100184
185/** A hardware failure was detected.
186 *
187 * A hardware failure may be transient or permanent depending on the
188 * cause. */
David Saadab4ecc272019-02-14 13:48:10 +0200189#define PSA_ERROR_HARDWARE_FAILURE ((psa_status_t)-147)
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100190
191/** A tampering attempt was detected.
192 *
193 * If an application receives this error code, there is no guarantee
194 * that previously accessed or computed data was correct and remains
195 * confidential. Applications should not perform any security function
196 * and should enter a safe failure state.
197 *
198 * Implementations may return this error code if they detect an invalid
199 * state that cannot happen during normal operation and that indicates
200 * that the implementation's security guarantees no longer hold. Depending
201 * on the implementation architecture and on its security and safety goals,
202 * the implementation may forcibly terminate the application.
203 *
204 * This error code is intended as a last resort when a security breach
205 * is detected and it is unsure whether the keystore data is still
206 * protected. Implementations shall only return this error code
207 * to report an alarm from a tampering detector, to indicate that
208 * the confidentiality of stored data can no longer be guaranteed,
209 * or to indicate that the integrity of previously returned data is now
210 * considered compromised. Implementations shall not use this error code
211 * to indicate a hardware failure that merely makes it impossible to
212 * perform the requested operation (use #PSA_ERROR_COMMUNICATION_FAILURE,
213 * #PSA_ERROR_STORAGE_FAILURE, #PSA_ERROR_HARDWARE_FAILURE,
214 * #PSA_ERROR_INSUFFICIENT_ENTROPY or other applicable error code
215 * instead).
216 *
217 * This error indicates an attack against the application. Implementations
218 * shall not return this error code as a consequence of the behavior of
219 * the application itself. */
David Saadab4ecc272019-02-14 13:48:10 +0200220#define PSA_ERROR_TAMPERING_DETECTED ((psa_status_t)-151)
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100221
222/** There is not enough entropy to generate random data needed
223 * for the requested action.
224 *
225 * This error indicates a failure of a hardware random generator.
226 * Application writers should note that this error can be returned not
227 * only by functions whose purpose is to generate random data, such
228 * as key, IV or nonce generation, but also by functions that execute
229 * an algorithm with a randomized result, as well as functions that
230 * use randomization of intermediate computations as a countermeasure
231 * to certain attacks.
232 *
233 * Implementations should avoid returning this error after psa_crypto_init()
234 * has succeeded. Implementations should generate sufficient
235 * entropy during initialization and subsequently use a cryptographically
236 * secure pseudorandom generator (PRNG). However implementations may return
237 * this error at any time if a policy requires the PRNG to be reseeded
238 * during normal operation. */
David Saadab4ecc272019-02-14 13:48:10 +0200239#define PSA_ERROR_INSUFFICIENT_ENTROPY ((psa_status_t)-148)
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100240
241/** The signature, MAC or hash is incorrect.
242 *
243 * Verification functions return this error if the verification
244 * calculations completed successfully, and the value to be verified
245 * was determined to be incorrect.
246 *
247 * If the value to verify has an invalid size, implementations may return
248 * either #PSA_ERROR_INVALID_ARGUMENT or #PSA_ERROR_INVALID_SIGNATURE. */
David Saadab4ecc272019-02-14 13:48:10 +0200249#define PSA_ERROR_INVALID_SIGNATURE ((psa_status_t)-149)
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100250
251/** The decrypted padding is incorrect.
252 *
253 * \warning In some protocols, when decrypting data, it is essential that
254 * the behavior of the application does not depend on whether the padding
255 * is correct, down to precise timing. Applications should prefer
256 * protocols that use authenticated encryption rather than plain
257 * encryption. If the application must perform a decryption of
258 * unauthenticated data, the application writer should take care not
259 * to reveal whether the padding is invalid.
260 *
261 * Implementations should strive to make valid and invalid padding
262 * as close as possible to indistinguishable to an external observer.
263 * In particular, the timing of a decryption operation should not
264 * depend on the validity of the padding. */
David Saadab4ecc272019-02-14 13:48:10 +0200265#define PSA_ERROR_INVALID_PADDING ((psa_status_t)-150)
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100266
David Saadab4ecc272019-02-14 13:48:10 +0200267/** Return this error when there's insufficient data when attempting
268 * to read from a resource. */
269#define PSA_ERROR_INSUFFICIENT_DATA ((psa_status_t)-143)
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100270
271/** The key handle is not valid.
272 */
David Saadab4ecc272019-02-14 13:48:10 +0200273#define PSA_ERROR_INVALID_HANDLE ((psa_status_t)-136)
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100274
275/**@}*/
276
277/** \defgroup crypto_types Key and algorithm types
278 * @{
279 */
280
281/** An invalid key type value.
282 *
283 * Zero is not the encoding of any key type.
284 */
285#define PSA_KEY_TYPE_NONE ((psa_key_type_t)0x00000000)
286
287/** Vendor-defined flag
288 *
289 * Key types defined by this standard will never have the
290 * #PSA_KEY_TYPE_VENDOR_FLAG bit set. Vendors who define additional key types
291 * must use an encoding with the #PSA_KEY_TYPE_VENDOR_FLAG bit set and should
292 * respect the bitwise structure used by standard encodings whenever practical.
293 */
294#define PSA_KEY_TYPE_VENDOR_FLAG ((psa_key_type_t)0x80000000)
295
296#define PSA_KEY_TYPE_CATEGORY_MASK ((psa_key_type_t)0x70000000)
297#define PSA_KEY_TYPE_CATEGORY_SYMMETRIC ((psa_key_type_t)0x40000000)
298#define PSA_KEY_TYPE_CATEGORY_RAW ((psa_key_type_t)0x50000000)
299#define PSA_KEY_TYPE_CATEGORY_PUBLIC_KEY ((psa_key_type_t)0x60000000)
300#define PSA_KEY_TYPE_CATEGORY_KEY_PAIR ((psa_key_type_t)0x70000000)
301
302#define PSA_KEY_TYPE_CATEGORY_FLAG_PAIR ((psa_key_type_t)0x10000000)
303
304/** Whether a key type is vendor-defined. */
305#define PSA_KEY_TYPE_IS_VENDOR_DEFINED(type) \
306 (((type) & PSA_KEY_TYPE_VENDOR_FLAG) != 0)
307
308/** Whether a key type is an unstructured array of bytes.
309 *
310 * This encompasses both symmetric keys and non-key data.
311 */
312#define PSA_KEY_TYPE_IS_UNSTRUCTURED(type) \
313 (((type) & PSA_KEY_TYPE_CATEGORY_MASK & ~(psa_key_type_t)0x10000000) == \
314 PSA_KEY_TYPE_CATEGORY_SYMMETRIC)
315
316/** Whether a key type is asymmetric: either a key pair or a public key. */
317#define PSA_KEY_TYPE_IS_ASYMMETRIC(type) \
318 (((type) & PSA_KEY_TYPE_CATEGORY_MASK \
319 & ~PSA_KEY_TYPE_CATEGORY_FLAG_PAIR) == \
320 PSA_KEY_TYPE_CATEGORY_PUBLIC_KEY)
321/** Whether a key type is the public part of a key pair. */
322#define PSA_KEY_TYPE_IS_PUBLIC_KEY(type) \
323 (((type) & PSA_KEY_TYPE_CATEGORY_MASK) == PSA_KEY_TYPE_CATEGORY_PUBLIC_KEY)
324/** Whether a key type is a key pair containing a private part and a public
325 * part. */
326#define PSA_KEY_TYPE_IS_KEYPAIR(type) \
327 (((type) & PSA_KEY_TYPE_CATEGORY_MASK) == PSA_KEY_TYPE_CATEGORY_KEY_PAIR)
328/** The key pair type corresponding to a public key type.
329 *
330 * You may also pass a key pair type as \p type, it will be left unchanged.
331 *
332 * \param type A public key type or key pair type.
333 *
334 * \return The corresponding key pair type.
335 * If \p type is not a public key or a key pair,
336 * the return value is undefined.
337 */
338#define PSA_KEY_TYPE_KEYPAIR_OF_PUBLIC_KEY(type) \
339 ((type) | PSA_KEY_TYPE_CATEGORY_FLAG_PAIR)
340/** The public key type corresponding to a key pair type.
341 *
342 * You may also pass a key pair type as \p type, it will be left unchanged.
343 *
344 * \param type A public key type or key pair type.
345 *
346 * \return The corresponding public key type.
347 * If \p type is not a public key or a key pair,
348 * the return value is undefined.
349 */
350#define PSA_KEY_TYPE_PUBLIC_KEY_OF_KEYPAIR(type) \
351 ((type) & ~PSA_KEY_TYPE_CATEGORY_FLAG_PAIR)
352
353/** Raw data.
354 *
355 * A "key" of this type cannot be used for any cryptographic operation.
356 * Applications may use this type to store arbitrary data in the keystore. */
357#define PSA_KEY_TYPE_RAW_DATA ((psa_key_type_t)0x50000001)
358
359/** HMAC key.
360 *
361 * The key policy determines which underlying hash algorithm the key can be
362 * used for.
363 *
364 * HMAC keys should generally have the same size as the underlying hash.
365 * This size can be calculated with #PSA_HASH_SIZE(\c alg) where
366 * \c alg is the HMAC algorithm or the underlying hash algorithm. */
367#define PSA_KEY_TYPE_HMAC ((psa_key_type_t)0x51000000)
368
369/** A secret for key derivation.
370 *
371 * The key policy determines which key derivation algorithm the key
372 * can be used for.
373 */
374#define PSA_KEY_TYPE_DERIVE ((psa_key_type_t)0x52000000)
375
376/** Key for an cipher, AEAD or MAC algorithm based on the AES block cipher.
377 *
378 * The size of the key can be 16 bytes (AES-128), 24 bytes (AES-192) or
379 * 32 bytes (AES-256).
380 */
381#define PSA_KEY_TYPE_AES ((psa_key_type_t)0x40000001)
382
383/** Key for a cipher or MAC algorithm based on DES or 3DES (Triple-DES).
384 *
385 * The size of the key can be 8 bytes (single DES), 16 bytes (2-key 3DES) or
386 * 24 bytes (3-key 3DES).
387 *
388 * Note that single DES and 2-key 3DES are weak and strongly
389 * deprecated and should only be used to decrypt legacy data. 3-key 3DES
390 * is weak and deprecated and should only be used in legacy protocols.
391 */
392#define PSA_KEY_TYPE_DES ((psa_key_type_t)0x40000002)
393
394/** Key for an cipher, AEAD or MAC algorithm based on the
395 * Camellia block cipher. */
396#define PSA_KEY_TYPE_CAMELLIA ((psa_key_type_t)0x40000003)
397
398/** Key for the RC4 stream cipher.
399 *
400 * Note that RC4 is weak and deprecated and should only be used in
401 * legacy protocols. */
402#define PSA_KEY_TYPE_ARC4 ((psa_key_type_t)0x40000004)
403
Gilles Peskine3e79c8e2019-05-06 15:20:04 +0200404/** Key for the ChaCha20 stream cipher or the Chacha20-Poly1305 AEAD algorithm.
405 *
406 * ChaCha20 and the ChaCha20_Poly1305 construction are defined in RFC 7539.
407 *
408 * Implementations must support 12-byte nonces, may support 8-byte nonces,
409 * and should reject other sizes.
410 */
411#define PSA_KEY_TYPE_CHACHA20 ((psa_key_type_t)0x40000005)
412
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100413/** RSA public key. */
414#define PSA_KEY_TYPE_RSA_PUBLIC_KEY ((psa_key_type_t)0x60010000)
415/** RSA key pair (private and public key). */
416#define PSA_KEY_TYPE_RSA_KEYPAIR ((psa_key_type_t)0x70010000)
417/** Whether a key type is an RSA key (pair or public-only). */
418#define PSA_KEY_TYPE_IS_RSA(type) \
419 (PSA_KEY_TYPE_PUBLIC_KEY_OF_KEYPAIR(type) == PSA_KEY_TYPE_RSA_PUBLIC_KEY)
420
421/** DSA public key. */
422#define PSA_KEY_TYPE_DSA_PUBLIC_KEY ((psa_key_type_t)0x60020000)
423/** DSA key pair (private and public key). */
424#define PSA_KEY_TYPE_DSA_KEYPAIR ((psa_key_type_t)0x70020000)
425/** Whether a key type is an DSA key (pair or public-only). */
426#define PSA_KEY_TYPE_IS_DSA(type) \
427 (PSA_KEY_TYPE_PUBLIC_KEY_OF_KEYPAIR(type) == PSA_KEY_TYPE_DSA_PUBLIC_KEY)
428
429#define PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE ((psa_key_type_t)0x60030000)
430#define PSA_KEY_TYPE_ECC_KEYPAIR_BASE ((psa_key_type_t)0x70030000)
431#define PSA_KEY_TYPE_ECC_CURVE_MASK ((psa_key_type_t)0x0000ffff)
432/** Elliptic curve key pair. */
433#define PSA_KEY_TYPE_ECC_KEYPAIR(curve) \
434 (PSA_KEY_TYPE_ECC_KEYPAIR_BASE | (curve))
435/** Elliptic curve public key. */
436#define PSA_KEY_TYPE_ECC_PUBLIC_KEY(curve) \
437 (PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE | (curve))
438
439/** Whether a key type is an elliptic curve key (pair or public-only). */
440#define PSA_KEY_TYPE_IS_ECC(type) \
441 ((PSA_KEY_TYPE_PUBLIC_KEY_OF_KEYPAIR(type) & \
442 ~PSA_KEY_TYPE_ECC_CURVE_MASK) == PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE)
Gilles Peskine5e9c9cc2018-12-12 14:02:48 +0100443/** Whether a key type is an elliptic curve key pair. */
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100444#define PSA_KEY_TYPE_IS_ECC_KEYPAIR(type) \
445 (((type) & ~PSA_KEY_TYPE_ECC_CURVE_MASK) == \
446 PSA_KEY_TYPE_ECC_KEYPAIR_BASE)
Gilles Peskine5e9c9cc2018-12-12 14:02:48 +0100447/** Whether a key type is an elliptic curve public key. */
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100448#define PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY(type) \
449 (((type) & ~PSA_KEY_TYPE_ECC_CURVE_MASK) == \
450 PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE)
451
452/** Extract the curve from an elliptic curve key type. */
453#define PSA_KEY_TYPE_GET_CURVE(type) \
454 ((psa_ecc_curve_t) (PSA_KEY_TYPE_IS_ECC(type) ? \
455 ((type) & PSA_KEY_TYPE_ECC_CURVE_MASK) : \
456 0))
457
458/* The encoding of curve identifiers is currently aligned with the
459 * TLS Supported Groups Registry (formerly known as the
460 * TLS EC Named Curve Registry)
461 * https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-8
462 * The values are defined by RFC 8422 and RFC 7027. */
463#define PSA_ECC_CURVE_SECT163K1 ((psa_ecc_curve_t) 0x0001)
464#define PSA_ECC_CURVE_SECT163R1 ((psa_ecc_curve_t) 0x0002)
465#define PSA_ECC_CURVE_SECT163R2 ((psa_ecc_curve_t) 0x0003)
466#define PSA_ECC_CURVE_SECT193R1 ((psa_ecc_curve_t) 0x0004)
467#define PSA_ECC_CURVE_SECT193R2 ((psa_ecc_curve_t) 0x0005)
468#define PSA_ECC_CURVE_SECT233K1 ((psa_ecc_curve_t) 0x0006)
469#define PSA_ECC_CURVE_SECT233R1 ((psa_ecc_curve_t) 0x0007)
470#define PSA_ECC_CURVE_SECT239K1 ((psa_ecc_curve_t) 0x0008)
471#define PSA_ECC_CURVE_SECT283K1 ((psa_ecc_curve_t) 0x0009)
472#define PSA_ECC_CURVE_SECT283R1 ((psa_ecc_curve_t) 0x000a)
473#define PSA_ECC_CURVE_SECT409K1 ((psa_ecc_curve_t) 0x000b)
474#define PSA_ECC_CURVE_SECT409R1 ((psa_ecc_curve_t) 0x000c)
475#define PSA_ECC_CURVE_SECT571K1 ((psa_ecc_curve_t) 0x000d)
476#define PSA_ECC_CURVE_SECT571R1 ((psa_ecc_curve_t) 0x000e)
477#define PSA_ECC_CURVE_SECP160K1 ((psa_ecc_curve_t) 0x000f)
478#define PSA_ECC_CURVE_SECP160R1 ((psa_ecc_curve_t) 0x0010)
479#define PSA_ECC_CURVE_SECP160R2 ((psa_ecc_curve_t) 0x0011)
480#define PSA_ECC_CURVE_SECP192K1 ((psa_ecc_curve_t) 0x0012)
481#define PSA_ECC_CURVE_SECP192R1 ((psa_ecc_curve_t) 0x0013)
482#define PSA_ECC_CURVE_SECP224K1 ((psa_ecc_curve_t) 0x0014)
483#define PSA_ECC_CURVE_SECP224R1 ((psa_ecc_curve_t) 0x0015)
484#define PSA_ECC_CURVE_SECP256K1 ((psa_ecc_curve_t) 0x0016)
485#define PSA_ECC_CURVE_SECP256R1 ((psa_ecc_curve_t) 0x0017)
486#define PSA_ECC_CURVE_SECP384R1 ((psa_ecc_curve_t) 0x0018)
487#define PSA_ECC_CURVE_SECP521R1 ((psa_ecc_curve_t) 0x0019)
488#define PSA_ECC_CURVE_BRAINPOOL_P256R1 ((psa_ecc_curve_t) 0x001a)
489#define PSA_ECC_CURVE_BRAINPOOL_P384R1 ((psa_ecc_curve_t) 0x001b)
490#define PSA_ECC_CURVE_BRAINPOOL_P512R1 ((psa_ecc_curve_t) 0x001c)
491#define PSA_ECC_CURVE_CURVE25519 ((psa_ecc_curve_t) 0x001d)
492#define PSA_ECC_CURVE_CURVE448 ((psa_ecc_curve_t) 0x001e)
493
Jaeden Amero8851c402019-01-11 14:20:03 +0000494/** Diffie-Hellman key exchange public key. */
495#define PSA_KEY_TYPE_DH_PUBLIC_KEY ((psa_key_type_t)0x60040000)
496/** Diffie-Hellman key exchange key pair (private and public key). */
497#define PSA_KEY_TYPE_DH_KEYPAIR ((psa_key_type_t)0x70040000)
498/** Whether a key type is a Diffie-Hellman key exchange key (pair or
499 * public-only). */
500#define PSA_KEY_TYPE_IS_DH(type) \
501 (PSA_KEY_TYPE_PUBLIC_KEY_OF_KEYPAIR(type) == PSA_KEY_TYPE_DH_PUBLIC_KEY)
502
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100503/** The block size of a block cipher.
504 *
505 * \param type A cipher key type (value of type #psa_key_type_t).
506 *
507 * \return The block size for a block cipher, or 1 for a stream cipher.
508 * The return value is undefined if \p type is not a supported
509 * cipher key type.
510 *
511 * \note It is possible to build stream cipher algorithms on top of a block
512 * cipher, for example CTR mode (#PSA_ALG_CTR).
513 * This macro only takes the key type into account, so it cannot be
514 * used to determine the size of the data that #psa_cipher_update()
515 * might buffer for future processing in general.
516 *
517 * \note This macro returns a compile-time constant if its argument is one.
518 *
519 * \warning This macro may evaluate its argument multiple times.
520 */
521#define PSA_BLOCK_CIPHER_BLOCK_SIZE(type) \
522 ( \
523 (type) == PSA_KEY_TYPE_AES ? 16 : \
524 (type) == PSA_KEY_TYPE_DES ? 8 : \
525 (type) == PSA_KEY_TYPE_CAMELLIA ? 16 : \
526 (type) == PSA_KEY_TYPE_ARC4 ? 1 : \
527 0)
528
529#define PSA_ALG_VENDOR_FLAG ((psa_algorithm_t)0x80000000)
530#define PSA_ALG_CATEGORY_MASK ((psa_algorithm_t)0x7f000000)
531#define PSA_ALG_CATEGORY_HASH ((psa_algorithm_t)0x01000000)
532#define PSA_ALG_CATEGORY_MAC ((psa_algorithm_t)0x02000000)
533#define PSA_ALG_CATEGORY_CIPHER ((psa_algorithm_t)0x04000000)
534#define PSA_ALG_CATEGORY_AEAD ((psa_algorithm_t)0x06000000)
535#define PSA_ALG_CATEGORY_SIGN ((psa_algorithm_t)0x10000000)
536#define PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION ((psa_algorithm_t)0x12000000)
Gilles Peskine6843c292019-01-18 16:44:49 +0100537#define PSA_ALG_CATEGORY_KEY_DERIVATION ((psa_algorithm_t)0x20000000)
538#define PSA_ALG_CATEGORY_KEY_AGREEMENT ((psa_algorithm_t)0x30000000)
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100539
540#define PSA_ALG_IS_VENDOR_DEFINED(alg) \
541 (((alg) & PSA_ALG_VENDOR_FLAG) != 0)
542
543/** Whether the specified algorithm is a hash algorithm.
544 *
545 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
546 *
547 * \return 1 if \p alg is a hash algorithm, 0 otherwise.
548 * This macro may return either 0 or 1 if \p alg is not a supported
549 * algorithm identifier.
550 */
551#define PSA_ALG_IS_HASH(alg) \
552 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_HASH)
553
554/** Whether the specified algorithm is a MAC algorithm.
555 *
556 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
557 *
558 * \return 1 if \p alg is a MAC algorithm, 0 otherwise.
559 * This macro may return either 0 or 1 if \p alg is not a supported
560 * algorithm identifier.
561 */
562#define PSA_ALG_IS_MAC(alg) \
563 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_MAC)
564
565/** Whether the specified algorithm is a symmetric cipher algorithm.
566 *
567 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
568 *
569 * \return 1 if \p alg is a symmetric cipher algorithm, 0 otherwise.
570 * This macro may return either 0 or 1 if \p alg is not a supported
571 * algorithm identifier.
572 */
573#define PSA_ALG_IS_CIPHER(alg) \
574 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_CIPHER)
575
576/** Whether the specified algorithm is an authenticated encryption
577 * with associated data (AEAD) algorithm.
578 *
579 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
580 *
581 * \return 1 if \p alg is an AEAD algorithm, 0 otherwise.
582 * This macro may return either 0 or 1 if \p alg is not a supported
583 * algorithm identifier.
584 */
585#define PSA_ALG_IS_AEAD(alg) \
586 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_AEAD)
587
588/** Whether the specified algorithm is a public-key signature algorithm.
589 *
590 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
591 *
592 * \return 1 if \p alg is a public-key signature algorithm, 0 otherwise.
593 * This macro may return either 0 or 1 if \p alg is not a supported
594 * algorithm identifier.
595 */
596#define PSA_ALG_IS_SIGN(alg) \
597 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_SIGN)
598
599/** Whether the specified algorithm is a public-key encryption algorithm.
600 *
601 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
602 *
603 * \return 1 if \p alg is a public-key encryption algorithm, 0 otherwise.
604 * This macro may return either 0 or 1 if \p alg is not a supported
605 * algorithm identifier.
606 */
607#define PSA_ALG_IS_ASYMMETRIC_ENCRYPTION(alg) \
608 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION)
609
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100610/** Whether the specified algorithm is a key agreement algorithm.
611 *
612 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
613 *
614 * \return 1 if \p alg is a key agreement algorithm, 0 otherwise.
615 * This macro may return either 0 or 1 if \p alg is not a supported
616 * algorithm identifier.
617 */
618#define PSA_ALG_IS_KEY_AGREEMENT(alg) \
Gilles Peskine47e79fb2019-02-08 11:24:59 +0100619 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_KEY_AGREEMENT)
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100620
621/** Whether the specified algorithm is a key derivation algorithm.
622 *
623 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
624 *
625 * \return 1 if \p alg is a key derivation algorithm, 0 otherwise.
626 * This macro may return either 0 or 1 if \p alg is not a supported
627 * algorithm identifier.
628 */
629#define PSA_ALG_IS_KEY_DERIVATION(alg) \
630 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_KEY_DERIVATION)
631
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100632#define PSA_ALG_HASH_MASK ((psa_algorithm_t)0x000000ff)
Gilles Peskine30f77cd2019-01-14 16:06:39 +0100633
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100634#define PSA_ALG_MD2 ((psa_algorithm_t)0x01000001)
635#define PSA_ALG_MD4 ((psa_algorithm_t)0x01000002)
636#define PSA_ALG_MD5 ((psa_algorithm_t)0x01000003)
637#define PSA_ALG_RIPEMD160 ((psa_algorithm_t)0x01000004)
638#define PSA_ALG_SHA_1 ((psa_algorithm_t)0x01000005)
639/** SHA2-224 */
640#define PSA_ALG_SHA_224 ((psa_algorithm_t)0x01000008)
641/** SHA2-256 */
642#define PSA_ALG_SHA_256 ((psa_algorithm_t)0x01000009)
643/** SHA2-384 */
644#define PSA_ALG_SHA_384 ((psa_algorithm_t)0x0100000a)
645/** SHA2-512 */
646#define PSA_ALG_SHA_512 ((psa_algorithm_t)0x0100000b)
647/** SHA2-512/224 */
648#define PSA_ALG_SHA_512_224 ((psa_algorithm_t)0x0100000c)
649/** SHA2-512/256 */
650#define PSA_ALG_SHA_512_256 ((psa_algorithm_t)0x0100000d)
651/** SHA3-224 */
652#define PSA_ALG_SHA3_224 ((psa_algorithm_t)0x01000010)
653/** SHA3-256 */
654#define PSA_ALG_SHA3_256 ((psa_algorithm_t)0x01000011)
655/** SHA3-384 */
656#define PSA_ALG_SHA3_384 ((psa_algorithm_t)0x01000012)
657/** SHA3-512 */
658#define PSA_ALG_SHA3_512 ((psa_algorithm_t)0x01000013)
659
Gilles Peskine763fb9a2019-01-28 13:29:01 +0100660/** In a hash-and-sign algorithm policy, allow any hash algorithm.
Gilles Peskine30f77cd2019-01-14 16:06:39 +0100661 *
Gilles Peskine763fb9a2019-01-28 13:29:01 +0100662 * This value may be used to form the algorithm usage field of a policy
663 * for a signature algorithm that is parametrized by a hash. The key
664 * may then be used to perform operations using the same signature
665 * algorithm parametrized with any supported hash.
666 *
667 * That is, suppose that `PSA_xxx_SIGNATURE` is one of the following macros:
Gilles Peskine30f77cd2019-01-14 16:06:39 +0100668 * - #PSA_ALG_RSA_PKCS1V15_SIGN, #PSA_ALG_RSA_PSS,
669 * - #PSA_ALG_DSA, #PSA_ALG_DETERMINISTIC_DSA,
670 * - #PSA_ALG_ECDSA, #PSA_ALG_DETERMINISTIC_ECDSA.
Gilles Peskine763fb9a2019-01-28 13:29:01 +0100671 * Then you may create and use a key as follows:
Gilles Peskine30f77cd2019-01-14 16:06:39 +0100672 * - Set the key usage field using #PSA_ALG_ANY_HASH, for example:
673 * ```
Gilles Peskine80b39ae2019-05-15 16:09:46 +0200674 * psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_SIGN); // or VERIFY
675 * psa_set_key_algorithm(&attributes, PSA_xxx_SIGNATURE(PSA_ALG_ANY_HASH));
Gilles Peskine30f77cd2019-01-14 16:06:39 +0100676 * ```
677 * - Import or generate key material.
678 * - Call psa_asymmetric_sign() or psa_asymmetric_verify(), passing
679 * an algorithm built from `PSA_xxx_SIGNATURE` and a specific hash. Each
680 * call to sign or verify a message may use a different hash.
681 * ```
682 * psa_asymmetric_sign(handle, PSA_xxx_SIGNATURE(PSA_ALG_SHA_256), ...);
683 * psa_asymmetric_sign(handle, PSA_xxx_SIGNATURE(PSA_ALG_SHA_512), ...);
684 * psa_asymmetric_sign(handle, PSA_xxx_SIGNATURE(PSA_ALG_SHA3_256), ...);
685 * ```
686 *
687 * This value may not be used to build other algorithms that are
688 * parametrized over a hash. For any valid use of this macro to build
Gilles Peskine3be6b7f2019-03-05 19:32:26 +0100689 * an algorithm \c alg, #PSA_ALG_IS_HASH_AND_SIGN(\c alg) is true.
Gilles Peskine30f77cd2019-01-14 16:06:39 +0100690 *
691 * This value may not be used to build an algorithm specification to
692 * perform an operation. It is only valid to build policies.
693 */
694#define PSA_ALG_ANY_HASH ((psa_algorithm_t)0x010000ff)
695
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100696#define PSA_ALG_MAC_SUBCATEGORY_MASK ((psa_algorithm_t)0x00c00000)
697#define PSA_ALG_HMAC_BASE ((psa_algorithm_t)0x02800000)
698/** Macro to build an HMAC algorithm.
699 *
700 * For example, #PSA_ALG_HMAC(#PSA_ALG_SHA_256) is HMAC-SHA-256.
701 *
702 * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
703 * #PSA_ALG_IS_HASH(\p hash_alg) is true).
704 *
705 * \return The corresponding HMAC algorithm.
Gilles Peskine3be6b7f2019-03-05 19:32:26 +0100706 * \return Unspecified if \p hash_alg is not a supported
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100707 * hash algorithm.
708 */
709#define PSA_ALG_HMAC(hash_alg) \
710 (PSA_ALG_HMAC_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
711
712#define PSA_ALG_HMAC_GET_HASH(hmac_alg) \
713 (PSA_ALG_CATEGORY_HASH | ((hmac_alg) & PSA_ALG_HASH_MASK))
714
715/** Whether the specified algorithm is an HMAC algorithm.
716 *
717 * HMAC is a family of MAC algorithms that are based on a hash function.
718 *
719 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
720 *
721 * \return 1 if \p alg is an HMAC algorithm, 0 otherwise.
722 * This macro may return either 0 or 1 if \p alg is not a supported
723 * algorithm identifier.
724 */
725#define PSA_ALG_IS_HMAC(alg) \
726 (((alg) & (PSA_ALG_CATEGORY_MASK | PSA_ALG_MAC_SUBCATEGORY_MASK)) == \
727 PSA_ALG_HMAC_BASE)
728
729/* In the encoding of a MAC algorithm, the bits corresponding to
730 * PSA_ALG_MAC_TRUNCATION_MASK encode the length to which the MAC is
731 * truncated. As an exception, the value 0 means the untruncated algorithm,
732 * whatever its length is. The length is encoded in 6 bits, so it can
733 * reach up to 63; the largest MAC is 64 bytes so its trivial truncation
734 * to full length is correctly encoded as 0 and any non-trivial truncation
735 * is correctly encoded as a value between 1 and 63. */
736#define PSA_ALG_MAC_TRUNCATION_MASK ((psa_algorithm_t)0x00003f00)
737#define PSA_MAC_TRUNCATION_OFFSET 8
738
739/** Macro to build a truncated MAC algorithm.
740 *
741 * A truncated MAC algorithm is identical to the corresponding MAC
742 * algorithm except that the MAC value for the truncated algorithm
743 * consists of only the first \p mac_length bytes of the MAC value
744 * for the untruncated algorithm.
745 *
746 * \note This macro may allow constructing algorithm identifiers that
747 * are not valid, either because the specified length is larger
748 * than the untruncated MAC or because the specified length is
749 * smaller than permitted by the implementation.
750 *
751 * \note It is implementation-defined whether a truncated MAC that
752 * is truncated to the same length as the MAC of the untruncated
753 * algorithm is considered identical to the untruncated algorithm
754 * for policy comparison purposes.
755 *
Gilles Peskine434899f2018-10-19 11:30:26 +0200756 * \param mac_alg A MAC algorithm identifier (value of type
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100757 * #psa_algorithm_t such that #PSA_ALG_IS_MAC(\p alg)
758 * is true). This may be a truncated or untruncated
759 * MAC algorithm.
760 * \param mac_length Desired length of the truncated MAC in bytes.
761 * This must be at most the full length of the MAC
762 * and must be at least an implementation-specified
763 * minimum. The implementation-specified minimum
764 * shall not be zero.
765 *
766 * \return The corresponding MAC algorithm with the specified
767 * length.
768 * \return Unspecified if \p alg is not a supported
769 * MAC algorithm or if \p mac_length is too small or
770 * too large for the specified MAC algorithm.
771 */
Gilles Peskine434899f2018-10-19 11:30:26 +0200772#define PSA_ALG_TRUNCATED_MAC(mac_alg, mac_length) \
773 (((mac_alg) & ~PSA_ALG_MAC_TRUNCATION_MASK) | \
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100774 ((mac_length) << PSA_MAC_TRUNCATION_OFFSET & PSA_ALG_MAC_TRUNCATION_MASK))
775
776/** Macro to build the base MAC algorithm corresponding to a truncated
777 * MAC algorithm.
778 *
Gilles Peskine434899f2018-10-19 11:30:26 +0200779 * \param mac_alg A MAC algorithm identifier (value of type
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100780 * #psa_algorithm_t such that #PSA_ALG_IS_MAC(\p alg)
781 * is true). This may be a truncated or untruncated
782 * MAC algorithm.
783 *
784 * \return The corresponding base MAC algorithm.
785 * \return Unspecified if \p alg is not a supported
786 * MAC algorithm.
787 */
Gilles Peskine434899f2018-10-19 11:30:26 +0200788#define PSA_ALG_FULL_LENGTH_MAC(mac_alg) \
789 ((mac_alg) & ~PSA_ALG_MAC_TRUNCATION_MASK)
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100790
791/** Length to which a MAC algorithm is truncated.
792 *
Gilles Peskine434899f2018-10-19 11:30:26 +0200793 * \param mac_alg A MAC algorithm identifier (value of type
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100794 * #psa_algorithm_t such that #PSA_ALG_IS_MAC(\p alg)
795 * is true).
796 *
797 * \return Length of the truncated MAC in bytes.
798 * \return 0 if \p alg is a non-truncated MAC algorithm.
799 * \return Unspecified if \p alg is not a supported
800 * MAC algorithm.
801 */
Gilles Peskine434899f2018-10-19 11:30:26 +0200802#define PSA_MAC_TRUNCATED_LENGTH(mac_alg) \
803 (((mac_alg) & PSA_ALG_MAC_TRUNCATION_MASK) >> PSA_MAC_TRUNCATION_OFFSET)
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100804
805#define PSA_ALG_CIPHER_MAC_BASE ((psa_algorithm_t)0x02c00000)
806#define PSA_ALG_CBC_MAC ((psa_algorithm_t)0x02c00001)
807#define PSA_ALG_CMAC ((psa_algorithm_t)0x02c00002)
808#define PSA_ALG_GMAC ((psa_algorithm_t)0x02c00003)
809
810/** Whether the specified algorithm is a MAC algorithm based on a block cipher.
811 *
812 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
813 *
814 * \return 1 if \p alg is a MAC algorithm based on a block cipher, 0 otherwise.
815 * This macro may return either 0 or 1 if \p alg is not a supported
816 * algorithm identifier.
817 */
818#define PSA_ALG_IS_BLOCK_CIPHER_MAC(alg) \
819 (((alg) & (PSA_ALG_CATEGORY_MASK | PSA_ALG_MAC_SUBCATEGORY_MASK)) == \
820 PSA_ALG_CIPHER_MAC_BASE)
821
822#define PSA_ALG_CIPHER_STREAM_FLAG ((psa_algorithm_t)0x00800000)
823#define PSA_ALG_CIPHER_FROM_BLOCK_FLAG ((psa_algorithm_t)0x00400000)
824
825/** Whether the specified algorithm is a stream cipher.
826 *
827 * A stream cipher is a symmetric cipher that encrypts or decrypts messages
828 * by applying a bitwise-xor with a stream of bytes that is generated
829 * from a key.
830 *
831 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
832 *
833 * \return 1 if \p alg is a stream cipher algorithm, 0 otherwise.
834 * This macro may return either 0 or 1 if \p alg is not a supported
835 * algorithm identifier or if it is not a symmetric cipher algorithm.
836 */
837#define PSA_ALG_IS_STREAM_CIPHER(alg) \
838 (((alg) & (PSA_ALG_CATEGORY_MASK | PSA_ALG_CIPHER_STREAM_FLAG)) == \
839 (PSA_ALG_CATEGORY_CIPHER | PSA_ALG_CIPHER_STREAM_FLAG))
840
841/** The ARC4 stream cipher algorithm.
842 */
843#define PSA_ALG_ARC4 ((psa_algorithm_t)0x04800001)
844
Gilles Peskine3e79c8e2019-05-06 15:20:04 +0200845/** The ChaCha20 stream cipher.
846 *
847 * ChaCha20 is defined in RFC 7539.
848 *
849 * The nonce size for psa_cipher_set_iv() or psa_cipher_generate_iv()
850 * must be 12.
851 *
852 * The initial block counter is always 0.
853 *
854 */
855#define PSA_ALG_CHACHA20 ((psa_algorithm_t)0x04800005)
856
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100857/** The CTR stream cipher mode.
858 *
859 * CTR is a stream cipher which is built from a block cipher.
860 * The underlying block cipher is determined by the key type.
861 * For example, to use AES-128-CTR, use this algorithm with
862 * a key of type #PSA_KEY_TYPE_AES and a length of 128 bits (16 bytes).
863 */
864#define PSA_ALG_CTR ((psa_algorithm_t)0x04c00001)
865
866#define PSA_ALG_CFB ((psa_algorithm_t)0x04c00002)
867
868#define PSA_ALG_OFB ((psa_algorithm_t)0x04c00003)
869
870/** The XTS cipher mode.
871 *
872 * XTS is a cipher mode which is built from a block cipher. It requires at
873 * least one full block of input, but beyond this minimum the input
874 * does not need to be a whole number of blocks.
875 */
876#define PSA_ALG_XTS ((psa_algorithm_t)0x044000ff)
877
878/** The CBC block cipher chaining mode, with no padding.
879 *
880 * The underlying block cipher is determined by the key type.
881 *
882 * This symmetric cipher mode can only be used with messages whose lengths
883 * are whole number of blocks for the chosen block cipher.
884 */
885#define PSA_ALG_CBC_NO_PADDING ((psa_algorithm_t)0x04600100)
886
887/** The CBC block cipher chaining mode with PKCS#7 padding.
888 *
889 * The underlying block cipher is determined by the key type.
890 *
891 * This is the padding method defined by PKCS#7 (RFC 2315) &sect;10.3.
892 */
893#define PSA_ALG_CBC_PKCS7 ((psa_algorithm_t)0x04600101)
894
Gilles Peskine679693e2019-05-06 15:10:16 +0200895#define PSA_ALG_AEAD_FROM_BLOCK_FLAG ((psa_algorithm_t)0x00400000)
896
897/** Whether the specified algorithm is an AEAD mode on a block cipher.
898 *
899 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
900 *
901 * \return 1 if \p alg is an AEAD algorithm which is an AEAD mode based on
902 * a block cipher, 0 otherwise.
903 * This macro may return either 0 or 1 if \p alg is not a supported
904 * algorithm identifier.
905 */
906#define PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER(alg) \
907 (((alg) & (PSA_ALG_CATEGORY_MASK | PSA_ALG_AEAD_FROM_BLOCK_FLAG)) == \
908 (PSA_ALG_CATEGORY_AEAD | PSA_ALG_AEAD_FROM_BLOCK_FLAG))
909
Gilles Peskine9153ec02019-02-15 13:02:02 +0100910/** The CCM authenticated encryption algorithm.
911 */
Gilles Peskine679693e2019-05-06 15:10:16 +0200912#define PSA_ALG_CCM ((psa_algorithm_t)0x06401001)
Gilles Peskine9153ec02019-02-15 13:02:02 +0100913
914/** The GCM authenticated encryption algorithm.
915 */
Gilles Peskine679693e2019-05-06 15:10:16 +0200916#define PSA_ALG_GCM ((psa_algorithm_t)0x06401002)
917
918/** The Chacha20-Poly1305 AEAD algorithm.
919 *
920 * The ChaCha20_Poly1305 construction is defined in RFC 7539.
Gilles Peskine3e79c8e2019-05-06 15:20:04 +0200921 *
922 * Implementations must support 12-byte nonces, may support 8-byte nonces,
923 * and should reject other sizes.
924 *
925 * Implementations must support 16-byte tags and should reject other sizes.
Gilles Peskine679693e2019-05-06 15:10:16 +0200926 */
927#define PSA_ALG_CHACHA20_POLY1305 ((psa_algorithm_t)0x06001005)
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100928
929/* In the encoding of a AEAD algorithm, the bits corresponding to
930 * PSA_ALG_AEAD_TAG_LENGTH_MASK encode the length of the AEAD tag.
931 * The constants for default lengths follow this encoding.
932 */
933#define PSA_ALG_AEAD_TAG_LENGTH_MASK ((psa_algorithm_t)0x00003f00)
934#define PSA_AEAD_TAG_LENGTH_OFFSET 8
935
936/** Macro to build a shortened AEAD algorithm.
937 *
938 * A shortened AEAD algorithm is similar to the corresponding AEAD
939 * algorithm, but has an authentication tag that consists of fewer bytes.
940 * Depending on the algorithm, the tag length may affect the calculation
941 * of the ciphertext.
942 *
Gilles Peskine434899f2018-10-19 11:30:26 +0200943 * \param aead_alg An AEAD algorithm identifier (value of type
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100944 * #psa_algorithm_t such that #PSA_ALG_IS_AEAD(\p alg)
945 * is true).
946 * \param tag_length Desired length of the authentication tag in bytes.
947 *
948 * \return The corresponding AEAD algorithm with the specified
949 * length.
950 * \return Unspecified if \p alg is not a supported
951 * AEAD algorithm or if \p tag_length is not valid
952 * for the specified AEAD algorithm.
953 */
Gilles Peskine434899f2018-10-19 11:30:26 +0200954#define PSA_ALG_AEAD_WITH_TAG_LENGTH(aead_alg, tag_length) \
955 (((aead_alg) & ~PSA_ALG_AEAD_TAG_LENGTH_MASK) | \
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100956 ((tag_length) << PSA_AEAD_TAG_LENGTH_OFFSET & \
957 PSA_ALG_AEAD_TAG_LENGTH_MASK))
958
959/** Calculate the corresponding AEAD algorithm with the default tag length.
960 *
Gilles Peskine434899f2018-10-19 11:30:26 +0200961 * \param aead_alg An AEAD algorithm (\c PSA_ALG_XXX value such that
962 * #PSA_ALG_IS_AEAD(\p alg) is true).
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100963 *
Gilles Peskine434899f2018-10-19 11:30:26 +0200964 * \return The corresponding AEAD algorithm with the default
965 * tag length for that algorithm.
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100966 */
Gilles Peskine434899f2018-10-19 11:30:26 +0200967#define PSA_ALG_AEAD_WITH_DEFAULT_TAG_LENGTH(aead_alg) \
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100968 ( \
Gilles Peskine434899f2018-10-19 11:30:26 +0200969 PSA__ALG_AEAD_WITH_DEFAULT_TAG_LENGTH__CASE(aead_alg, PSA_ALG_CCM) \
970 PSA__ALG_AEAD_WITH_DEFAULT_TAG_LENGTH__CASE(aead_alg, PSA_ALG_GCM) \
Gilles Peskine3e79c8e2019-05-06 15:20:04 +0200971 PSA__ALG_AEAD_WITH_DEFAULT_TAG_LENGTH__CASE(aead_alg, PSA_ALG_CHACHA20_POLY1305) \
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100972 0)
Gilles Peskine434899f2018-10-19 11:30:26 +0200973#define PSA__ALG_AEAD_WITH_DEFAULT_TAG_LENGTH__CASE(aead_alg, ref) \
974 PSA_ALG_AEAD_WITH_TAG_LENGTH(aead_alg, 0) == \
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100975 PSA_ALG_AEAD_WITH_TAG_LENGTH(ref, 0) ? \
976 ref :
977
978#define PSA_ALG_RSA_PKCS1V15_SIGN_BASE ((psa_algorithm_t)0x10020000)
979/** RSA PKCS#1 v1.5 signature with hashing.
980 *
981 * This is the signature scheme defined by RFC 8017
982 * (PKCS#1: RSA Cryptography Specifications) under the name
983 * RSASSA-PKCS1-v1_5.
984 *
985 * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
986 * #PSA_ALG_IS_HASH(\p hash_alg) is true).
Gilles Peskine30f77cd2019-01-14 16:06:39 +0100987 * This includes #PSA_ALG_ANY_HASH
988 * when specifying the algorithm in a usage policy.
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100989 *
990 * \return The corresponding RSA PKCS#1 v1.5 signature algorithm.
Gilles Peskine3be6b7f2019-03-05 19:32:26 +0100991 * \return Unspecified if \p hash_alg is not a supported
Gilles Peskinef3b731e2018-12-12 13:38:31 +0100992 * hash algorithm.
993 */
994#define PSA_ALG_RSA_PKCS1V15_SIGN(hash_alg) \
995 (PSA_ALG_RSA_PKCS1V15_SIGN_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
996/** Raw PKCS#1 v1.5 signature.
997 *
998 * The input to this algorithm is the DigestInfo structure used by
999 * RFC 8017 (PKCS#1: RSA Cryptography Specifications), &sect;9.2
1000 * steps 3&ndash;6.
1001 */
1002#define PSA_ALG_RSA_PKCS1V15_SIGN_RAW PSA_ALG_RSA_PKCS1V15_SIGN_BASE
1003#define PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) \
1004 (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_RSA_PKCS1V15_SIGN_BASE)
1005
1006#define PSA_ALG_RSA_PSS_BASE ((psa_algorithm_t)0x10030000)
1007/** RSA PSS signature with hashing.
1008 *
1009 * This is the signature scheme defined by RFC 8017
1010 * (PKCS#1: RSA Cryptography Specifications) under the name
1011 * RSASSA-PSS, with the message generation function MGF1, and with
1012 * a salt length equal to the length of the hash. The specified
1013 * hash algorithm is used to hash the input message, to create the
1014 * salted hash, and for the mask generation.
1015 *
1016 * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
1017 * #PSA_ALG_IS_HASH(\p hash_alg) is true).
Gilles Peskine30f77cd2019-01-14 16:06:39 +01001018 * This includes #PSA_ALG_ANY_HASH
1019 * when specifying the algorithm in a usage policy.
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001020 *
1021 * \return The corresponding RSA PSS signature algorithm.
Gilles Peskine3be6b7f2019-03-05 19:32:26 +01001022 * \return Unspecified if \p hash_alg is not a supported
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001023 * hash algorithm.
1024 */
1025#define PSA_ALG_RSA_PSS(hash_alg) \
1026 (PSA_ALG_RSA_PSS_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1027#define PSA_ALG_IS_RSA_PSS(alg) \
1028 (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_RSA_PSS_BASE)
1029
1030#define PSA_ALG_DSA_BASE ((psa_algorithm_t)0x10040000)
1031/** DSA signature with hashing.
1032 *
1033 * This is the signature scheme defined by FIPS 186-4,
1034 * with a random per-message secret number (*k*).
1035 *
1036 * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
1037 * #PSA_ALG_IS_HASH(\p hash_alg) is true).
Gilles Peskine30f77cd2019-01-14 16:06:39 +01001038 * This includes #PSA_ALG_ANY_HASH
1039 * when specifying the algorithm in a usage policy.
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001040 *
1041 * \return The corresponding DSA signature algorithm.
Gilles Peskine3be6b7f2019-03-05 19:32:26 +01001042 * \return Unspecified if \p hash_alg is not a supported
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001043 * hash algorithm.
1044 */
1045#define PSA_ALG_DSA(hash_alg) \
1046 (PSA_ALG_DSA_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1047#define PSA_ALG_DETERMINISTIC_DSA_BASE ((psa_algorithm_t)0x10050000)
1048#define PSA_ALG_DSA_DETERMINISTIC_FLAG ((psa_algorithm_t)0x00010000)
Gilles Peskine9153ec02019-02-15 13:02:02 +01001049/** Deterministic DSA signature with hashing.
1050 *
1051 * This is the deterministic variant defined by RFC 6979 of
1052 * the signature scheme defined by FIPS 186-4.
1053 *
1054 * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
1055 * #PSA_ALG_IS_HASH(\p hash_alg) is true).
1056 * This includes #PSA_ALG_ANY_HASH
1057 * when specifying the algorithm in a usage policy.
1058 *
1059 * \return The corresponding DSA signature algorithm.
Gilles Peskine3be6b7f2019-03-05 19:32:26 +01001060 * \return Unspecified if \p hash_alg is not a supported
Gilles Peskine9153ec02019-02-15 13:02:02 +01001061 * hash algorithm.
1062 */
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001063#define PSA_ALG_DETERMINISTIC_DSA(hash_alg) \
1064 (PSA_ALG_DETERMINISTIC_DSA_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1065#define PSA_ALG_IS_DSA(alg) \
1066 (((alg) & ~PSA_ALG_HASH_MASK & ~PSA_ALG_DSA_DETERMINISTIC_FLAG) == \
1067 PSA_ALG_DSA_BASE)
1068#define PSA_ALG_DSA_IS_DETERMINISTIC(alg) \
1069 (((alg) & PSA_ALG_DSA_DETERMINISTIC_FLAG) != 0)
1070#define PSA_ALG_IS_DETERMINISTIC_DSA(alg) \
1071 (PSA_ALG_IS_DSA(alg) && PSA_ALG_DSA_IS_DETERMINISTIC(alg))
1072#define PSA_ALG_IS_RANDOMIZED_DSA(alg) \
1073 (PSA_ALG_IS_DSA(alg) && !PSA_ALG_DSA_IS_DETERMINISTIC(alg))
1074
1075#define PSA_ALG_ECDSA_BASE ((psa_algorithm_t)0x10060000)
1076/** ECDSA signature with hashing.
1077 *
1078 * This is the ECDSA signature scheme defined by ANSI X9.62,
1079 * with a random per-message secret number (*k*).
1080 *
1081 * The representation of the signature as a byte string consists of
1082 * the concatentation of the signature values *r* and *s*. Each of
1083 * *r* and *s* is encoded as an *N*-octet string, where *N* is the length
1084 * of the base point of the curve in octets. Each value is represented
1085 * in big-endian order (most significant octet first).
1086 *
1087 * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
1088 * #PSA_ALG_IS_HASH(\p hash_alg) is true).
Gilles Peskine30f77cd2019-01-14 16:06:39 +01001089 * This includes #PSA_ALG_ANY_HASH
1090 * when specifying the algorithm in a usage policy.
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001091 *
1092 * \return The corresponding ECDSA signature algorithm.
Gilles Peskine3be6b7f2019-03-05 19:32:26 +01001093 * \return Unspecified if \p hash_alg is not a supported
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001094 * hash algorithm.
1095 */
1096#define PSA_ALG_ECDSA(hash_alg) \
1097 (PSA_ALG_ECDSA_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1098/** ECDSA signature without hashing.
1099 *
1100 * This is the same signature scheme as #PSA_ALG_ECDSA(), but
1101 * without specifying a hash algorithm. This algorithm may only be
1102 * used to sign or verify a sequence of bytes that should be an
1103 * already-calculated hash. Note that the input is padded with
1104 * zeros on the left or truncated on the left as required to fit
1105 * the curve size.
1106 */
1107#define PSA_ALG_ECDSA_ANY PSA_ALG_ECDSA_BASE
1108#define PSA_ALG_DETERMINISTIC_ECDSA_BASE ((psa_algorithm_t)0x10070000)
1109/** Deterministic ECDSA signature with hashing.
1110 *
1111 * This is the deterministic ECDSA signature scheme defined by RFC 6979.
1112 *
1113 * The representation of a signature is the same as with #PSA_ALG_ECDSA().
1114 *
1115 * Note that when this algorithm is used for verification, signatures
1116 * made with randomized ECDSA (#PSA_ALG_ECDSA(\p hash_alg)) with the
1117 * same private key are accepted. In other words,
1118 * #PSA_ALG_DETERMINISTIC_ECDSA(\p hash_alg) differs from
1119 * #PSA_ALG_ECDSA(\p hash_alg) only for signature, not for verification.
1120 *
1121 * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
1122 * #PSA_ALG_IS_HASH(\p hash_alg) is true).
Gilles Peskine30f77cd2019-01-14 16:06:39 +01001123 * This includes #PSA_ALG_ANY_HASH
1124 * when specifying the algorithm in a usage policy.
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001125 *
1126 * \return The corresponding deterministic ECDSA signature
1127 * algorithm.
Gilles Peskine3be6b7f2019-03-05 19:32:26 +01001128 * \return Unspecified if \p hash_alg is not a supported
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001129 * hash algorithm.
1130 */
1131#define PSA_ALG_DETERMINISTIC_ECDSA(hash_alg) \
1132 (PSA_ALG_DETERMINISTIC_ECDSA_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1133#define PSA_ALG_IS_ECDSA(alg) \
1134 (((alg) & ~PSA_ALG_HASH_MASK & ~PSA_ALG_DSA_DETERMINISTIC_FLAG) == \
1135 PSA_ALG_ECDSA_BASE)
1136#define PSA_ALG_ECDSA_IS_DETERMINISTIC(alg) \
1137 (((alg) & PSA_ALG_DSA_DETERMINISTIC_FLAG) != 0)
1138#define PSA_ALG_IS_DETERMINISTIC_ECDSA(alg) \
1139 (PSA_ALG_IS_ECDSA(alg) && PSA_ALG_ECDSA_IS_DETERMINISTIC(alg))
1140#define PSA_ALG_IS_RANDOMIZED_ECDSA(alg) \
1141 (PSA_ALG_IS_ECDSA(alg) && !PSA_ALG_ECDSA_IS_DETERMINISTIC(alg))
1142
Gilles Peskined35b4892019-01-14 16:02:15 +01001143/** Whether the specified algorithm is a hash-and-sign algorithm.
1144 *
1145 * Hash-and-sign algorithms are public-key signature algorithms structured
1146 * in two parts: first the calculation of a hash in a way that does not
1147 * depend on the key, then the calculation of a signature from the
1148 * hash value and the key.
1149 *
1150 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
1151 *
1152 * \return 1 if \p alg is a hash-and-sign algorithm, 0 otherwise.
1153 * This macro may return either 0 or 1 if \p alg is not a supported
1154 * algorithm identifier.
1155 */
1156#define PSA_ALG_IS_HASH_AND_SIGN(alg) \
1157 (PSA_ALG_IS_RSA_PSS(alg) || PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) || \
1158 PSA_ALG_IS_DSA(alg) || PSA_ALG_IS_ECDSA(alg))
1159
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001160/** Get the hash used by a hash-and-sign signature algorithm.
1161 *
1162 * A hash-and-sign algorithm is a signature algorithm which is
1163 * composed of two phases: first a hashing phase which does not use
1164 * the key and produces a hash of the input message, then a signing
1165 * phase which only uses the hash and the key and not the message
1166 * itself.
1167 *
1168 * \param alg A signature algorithm (\c PSA_ALG_XXX value such that
1169 * #PSA_ALG_IS_SIGN(\p alg) is true).
1170 *
1171 * \return The underlying hash algorithm if \p alg is a hash-and-sign
1172 * algorithm.
1173 * \return 0 if \p alg is a signature algorithm that does not
1174 * follow the hash-and-sign structure.
1175 * \return Unspecified if \p alg is not a signature algorithm or
1176 * if it is not supported by the implementation.
1177 */
1178#define PSA_ALG_SIGN_GET_HASH(alg) \
Gilles Peskined35b4892019-01-14 16:02:15 +01001179 (PSA_ALG_IS_HASH_AND_SIGN(alg) ? \
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001180 ((alg) & PSA_ALG_HASH_MASK) == 0 ? /*"raw" algorithm*/ 0 : \
1181 ((alg) & PSA_ALG_HASH_MASK) | PSA_ALG_CATEGORY_HASH : \
1182 0)
1183
1184/** RSA PKCS#1 v1.5 encryption.
1185 */
1186#define PSA_ALG_RSA_PKCS1V15_CRYPT ((psa_algorithm_t)0x12020000)
1187
1188#define PSA_ALG_RSA_OAEP_BASE ((psa_algorithm_t)0x12030000)
1189/** RSA OAEP encryption.
1190 *
1191 * This is the encryption scheme defined by RFC 8017
1192 * (PKCS#1: RSA Cryptography Specifications) under the name
1193 * RSAES-OAEP, with the message generation function MGF1.
1194 *
1195 * \param hash_alg The hash algorithm (\c PSA_ALG_XXX value such that
1196 * #PSA_ALG_IS_HASH(\p hash_alg) is true) to use
1197 * for MGF1.
1198 *
1199 * \return The corresponding RSA OAEP signature algorithm.
Gilles Peskine3be6b7f2019-03-05 19:32:26 +01001200 * \return Unspecified if \p hash_alg is not a supported
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001201 * hash algorithm.
1202 */
1203#define PSA_ALG_RSA_OAEP(hash_alg) \
1204 (PSA_ALG_RSA_OAEP_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1205#define PSA_ALG_IS_RSA_OAEP(alg) \
1206 (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_RSA_OAEP_BASE)
1207#define PSA_ALG_RSA_OAEP_GET_HASH(alg) \
1208 (PSA_ALG_IS_RSA_OAEP(alg) ? \
1209 ((alg) & PSA_ALG_HASH_MASK) | PSA_ALG_CATEGORY_HASH : \
1210 0)
1211
Gilles Peskine6843c292019-01-18 16:44:49 +01001212#define PSA_ALG_HKDF_BASE ((psa_algorithm_t)0x20000100)
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001213/** Macro to build an HKDF algorithm.
1214 *
1215 * For example, `PSA_ALG_HKDF(PSA_ALG_SHA256)` is HKDF using HMAC-SHA-256.
1216 *
Gilles Peskine6cdfdb72019-01-08 10:31:27 +01001217 * This key derivation algorithm uses the following inputs:
Gilles Peskine03410b52019-05-16 16:05:19 +02001218 * - #PSA_KEY_DERIVATION_INPUT_SALT is the salt used in the "extract" step.
Gilles Peskine6cdfdb72019-01-08 10:31:27 +01001219 * It is optional; if omitted, the derivation uses an empty salt.
Gilles Peskine03410b52019-05-16 16:05:19 +02001220 * - #PSA_KEY_DERIVATION_INPUT_SECRET is the secret key used in the "extract" step.
1221 * - #PSA_KEY_DERIVATION_INPUT_INFO is the info string used in the "expand" step.
1222 * You must pass #PSA_KEY_DERIVATION_INPUT_SALT before #PSA_KEY_DERIVATION_INPUT_SECRET.
1223 * You may pass #PSA_KEY_DERIVATION_INPUT_INFO at any time after steup and before
Gilles Peskine6cdfdb72019-01-08 10:31:27 +01001224 * starting to generate output.
1225 *
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001226 * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
1227 * #PSA_ALG_IS_HASH(\p hash_alg) is true).
1228 *
1229 * \return The corresponding HKDF algorithm.
Gilles Peskine3be6b7f2019-03-05 19:32:26 +01001230 * \return Unspecified if \p hash_alg is not a supported
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001231 * hash algorithm.
1232 */
1233#define PSA_ALG_HKDF(hash_alg) \
1234 (PSA_ALG_HKDF_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1235/** Whether the specified algorithm is an HKDF algorithm.
1236 *
1237 * HKDF is a family of key derivation algorithms that are based on a hash
1238 * function and the HMAC construction.
1239 *
1240 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
1241 *
1242 * \return 1 if \c alg is an HKDF algorithm, 0 otherwise.
1243 * This macro may return either 0 or 1 if \c alg is not a supported
1244 * key derivation algorithm identifier.
1245 */
1246#define PSA_ALG_IS_HKDF(alg) \
1247 (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_HKDF_BASE)
1248#define PSA_ALG_HKDF_GET_HASH(hkdf_alg) \
1249 (PSA_ALG_CATEGORY_HASH | ((hkdf_alg) & PSA_ALG_HASH_MASK))
1250
Gilles Peskine6843c292019-01-18 16:44:49 +01001251#define PSA_ALG_TLS12_PRF_BASE ((psa_algorithm_t)0x20000200)
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001252/** Macro to build a TLS-1.2 PRF algorithm.
1253 *
1254 * TLS 1.2 uses a custom pseudorandom function (PRF) for key schedule,
1255 * specified in Section 5 of RFC 5246. It is based on HMAC and can be
1256 * used with either SHA-256 or SHA-384.
1257 *
1258 * For the application to TLS-1.2, the salt and label arguments passed
1259 * to psa_key_derivation() are what's called 'seed' and 'label' in RFC 5246,
1260 * respectively. For example, for TLS key expansion, the salt is the
1261 * concatenation of ServerHello.Random + ClientHello.Random,
1262 * while the label is "key expansion".
1263 *
1264 * For example, `PSA_ALG_TLS12_PRF(PSA_ALG_SHA256)` represents the
1265 * TLS 1.2 PRF using HMAC-SHA-256.
1266 *
1267 * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
1268 * #PSA_ALG_IS_HASH(\p hash_alg) is true).
1269 *
1270 * \return The corresponding TLS-1.2 PRF algorithm.
Gilles Peskine3be6b7f2019-03-05 19:32:26 +01001271 * \return Unspecified if \p hash_alg is not a supported
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001272 * hash algorithm.
1273 */
1274#define PSA_ALG_TLS12_PRF(hash_alg) \
1275 (PSA_ALG_TLS12_PRF_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1276
1277/** Whether the specified algorithm is a TLS-1.2 PRF algorithm.
1278 *
1279 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
1280 *
1281 * \return 1 if \c alg is a TLS-1.2 PRF algorithm, 0 otherwise.
1282 * This macro may return either 0 or 1 if \c alg is not a supported
1283 * key derivation algorithm identifier.
1284 */
1285#define PSA_ALG_IS_TLS12_PRF(alg) \
1286 (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_TLS12_PRF_BASE)
1287#define PSA_ALG_TLS12_PRF_GET_HASH(hkdf_alg) \
1288 (PSA_ALG_CATEGORY_HASH | ((hkdf_alg) & PSA_ALG_HASH_MASK))
1289
Gilles Peskine6843c292019-01-18 16:44:49 +01001290#define PSA_ALG_TLS12_PSK_TO_MS_BASE ((psa_algorithm_t)0x20000300)
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001291/** Macro to build a TLS-1.2 PSK-to-MasterSecret algorithm.
1292 *
1293 * In a pure-PSK handshake in TLS 1.2, the master secret is derived
1294 * from the PreSharedKey (PSK) through the application of padding
1295 * (RFC 4279, Section 2) and the TLS-1.2 PRF (RFC 5246, Section 5).
1296 * The latter is based on HMAC and can be used with either SHA-256
1297 * or SHA-384.
1298 *
1299 * For the application to TLS-1.2, the salt passed to psa_key_derivation()
1300 * (and forwarded to the TLS-1.2 PRF) is the concatenation of the
1301 * ClientHello.Random + ServerHello.Random, while the label is "master secret"
1302 * or "extended master secret".
1303 *
1304 * For example, `PSA_ALG_TLS12_PSK_TO_MS(PSA_ALG_SHA256)` represents the
1305 * TLS-1.2 PSK to MasterSecret derivation PRF using HMAC-SHA-256.
1306 *
1307 * \param hash_alg A hash algorithm (\c PSA_ALG_XXX value such that
1308 * #PSA_ALG_IS_HASH(\p hash_alg) is true).
1309 *
1310 * \return The corresponding TLS-1.2 PSK to MS algorithm.
Gilles Peskine3be6b7f2019-03-05 19:32:26 +01001311 * \return Unspecified if \p hash_alg is not a supported
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001312 * hash algorithm.
1313 */
1314#define PSA_ALG_TLS12_PSK_TO_MS(hash_alg) \
1315 (PSA_ALG_TLS12_PSK_TO_MS_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
1316
1317/** Whether the specified algorithm is a TLS-1.2 PSK to MS algorithm.
1318 *
1319 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
1320 *
1321 * \return 1 if \c alg is a TLS-1.2 PSK to MS algorithm, 0 otherwise.
1322 * This macro may return either 0 or 1 if \c alg is not a supported
1323 * key derivation algorithm identifier.
1324 */
1325#define PSA_ALG_IS_TLS12_PSK_TO_MS(alg) \
1326 (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_TLS12_PSK_TO_MS_BASE)
1327#define PSA_ALG_TLS12_PSK_TO_MS_GET_HASH(hkdf_alg) \
1328 (PSA_ALG_CATEGORY_HASH | ((hkdf_alg) & PSA_ALG_HASH_MASK))
1329
Gilles Peskinea52460c2019-04-12 00:11:21 +02001330#define PSA_ALG_KEY_DERIVATION_MASK ((psa_algorithm_t)0x0803ffff)
1331#define PSA_ALG_KEY_AGREEMENT_MASK ((psa_algorithm_t)0x10fc0000)
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001332
Gilles Peskine6843c292019-01-18 16:44:49 +01001333/** Macro to build a combined algorithm that chains a key agreement with
1334 * a key derivation.
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001335 *
Gilles Peskine6843c292019-01-18 16:44:49 +01001336 * \param ka_alg A key agreement algorithm (\c PSA_ALG_XXX value such
1337 * that #PSA_ALG_IS_KEY_AGREEMENT(\p ka_alg) is true).
1338 * \param kdf_alg A key derivation algorithm (\c PSA_ALG_XXX value such
1339 * that #PSA_ALG_IS_KEY_DERIVATION(\p kdf_alg) is true).
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001340 *
Gilles Peskine6843c292019-01-18 16:44:49 +01001341 * \return The corresponding key agreement and derivation
1342 * algorithm.
1343 * \return Unspecified if \p ka_alg is not a supported
1344 * key agreement algorithm or \p kdf_alg is not a
1345 * supported key derivation algorithm.
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001346 */
Gilles Peskine6843c292019-01-18 16:44:49 +01001347#define PSA_ALG_KEY_AGREEMENT(ka_alg, kdf_alg) \
1348 ((ka_alg) | (kdf_alg))
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001349
1350#define PSA_ALG_KEY_AGREEMENT_GET_KDF(alg) \
1351 (((alg) & PSA_ALG_KEY_DERIVATION_MASK) | PSA_ALG_CATEGORY_KEY_DERIVATION)
1352
Gilles Peskine6843c292019-01-18 16:44:49 +01001353#define PSA_ALG_KEY_AGREEMENT_GET_BASE(alg) \
1354 (((alg) & PSA_ALG_KEY_AGREEMENT_MASK) | PSA_ALG_CATEGORY_KEY_AGREEMENT)
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001355
Gilles Peskine47e79fb2019-02-08 11:24:59 +01001356/** Whether the specified algorithm is a raw key agreement algorithm.
1357 *
1358 * A raw key agreement algorithm is one that does not specify
1359 * a key derivation function.
1360 * Usually, raw key agreement algorithms are constructed directly with
1361 * a \c PSA_ALG_xxx macro while non-raw key agreement algorithms are
1362 * constructed with PSA_ALG_KEY_AGREEMENT().
1363 *
1364 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
1365 *
1366 * \return 1 if \p alg is a raw key agreement algorithm, 0 otherwise.
1367 * This macro may return either 0 or 1 if \p alg is not a supported
1368 * algorithm identifier.
1369 */
Gilles Peskine6843c292019-01-18 16:44:49 +01001370#define PSA_ALG_IS_RAW_KEY_AGREEMENT(alg) \
Gilles Peskine47e79fb2019-02-08 11:24:59 +01001371 (PSA_ALG_IS_KEY_AGREEMENT(alg) && \
1372 PSA_ALG_KEY_AGREEMENT_GET_KDF(alg) == PSA_ALG_CATEGORY_KEY_DERIVATION)
Gilles Peskine6843c292019-01-18 16:44:49 +01001373
1374#define PSA_ALG_IS_KEY_DERIVATION_OR_AGREEMENT(alg) \
1375 ((PSA_ALG_IS_KEY_DERIVATION(alg) || PSA_ALG_IS_KEY_AGREEMENT(alg)))
1376
1377/** The finite-field Diffie-Hellman (DH) key agreement algorithm.
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001378 *
Gilles Peskine2e37c0d2019-03-05 19:32:02 +01001379 * The shared secret produced by key agreement is
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001380 * `g^{ab}` in big-endian format.
1381 * It is `ceiling(m / 8)` bytes long where `m` is the size of the prime `p`
1382 * in bits.
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001383 */
Gilles Peskine6843c292019-01-18 16:44:49 +01001384#define PSA_ALG_FFDH ((psa_algorithm_t)0x30100000)
1385
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001386/** Whether the specified algorithm is a finite field Diffie-Hellman algorithm.
1387 *
Gilles Peskine2e37c0d2019-03-05 19:32:02 +01001388 * This includes the raw finite field Diffie-Hellman algorithm as well as
1389 * finite-field Diffie-Hellman followed by any supporter key derivation
1390 * algorithm.
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001391 *
1392 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
1393 *
1394 * \return 1 if \c alg is a finite field Diffie-Hellman algorithm, 0 otherwise.
1395 * This macro may return either 0 or 1 if \c alg is not a supported
1396 * key agreement algorithm identifier.
1397 */
1398#define PSA_ALG_IS_FFDH(alg) \
Gilles Peskine6843c292019-01-18 16:44:49 +01001399 (PSA_ALG_KEY_AGREEMENT_GET_BASE(alg) == PSA_ALG_FFDH)
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001400
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001401/** The elliptic curve Diffie-Hellman (ECDH) key agreement algorithm.
1402 *
Gilles Peskine6843c292019-01-18 16:44:49 +01001403 * The shared secret produced by key agreement is the x-coordinate of
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001404 * the shared secret point. It is always `ceiling(m / 8)` bytes long where
1405 * `m` is the bit size associated with the curve, i.e. the bit size of the
1406 * order of the curve's coordinate field. When `m` is not a multiple of 8,
1407 * the byte containing the most significant bit of the shared secret
1408 * is padded with zero bits. The byte order is either little-endian
1409 * or big-endian depending on the curve type.
1410 *
1411 * - For Montgomery curves (curve types `PSA_ECC_CURVE_CURVEXXX`),
1412 * the shared secret is the x-coordinate of `d_A Q_B = d_B Q_A`
1413 * in little-endian byte order.
1414 * The bit size is 448 for Curve448 and 255 for Curve25519.
1415 * - For Weierstrass curves over prime fields (curve types
1416 * `PSA_ECC_CURVE_SECPXXX` and `PSA_ECC_CURVE_BRAINPOOL_PXXX`),
1417 * the shared secret is the x-coordinate of `d_A Q_B = d_B Q_A`
1418 * in big-endian byte order.
1419 * The bit size is `m = ceiling(log_2(p))` for the field `F_p`.
1420 * - For Weierstrass curves over binary fields (curve types
1421 * `PSA_ECC_CURVE_SECTXXX`),
1422 * the shared secret is the x-coordinate of `d_A Q_B = d_B Q_A`
1423 * in big-endian byte order.
1424 * The bit size is `m` for the field `F_{2^m}`.
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001425 */
Gilles Peskine6843c292019-01-18 16:44:49 +01001426#define PSA_ALG_ECDH ((psa_algorithm_t)0x30200000)
1427
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001428/** Whether the specified algorithm is an elliptic curve Diffie-Hellman
1429 * algorithm.
1430 *
Gilles Peskine2e37c0d2019-03-05 19:32:02 +01001431 * This includes the raw elliptic curve Diffie-Hellman algorithm as well as
1432 * elliptic curve Diffie-Hellman followed by any supporter key derivation
1433 * algorithm.
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001434 *
1435 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
1436 *
1437 * \return 1 if \c alg is an elliptic curve Diffie-Hellman algorithm,
1438 * 0 otherwise.
1439 * This macro may return either 0 or 1 if \c alg is not a supported
1440 * key agreement algorithm identifier.
1441 */
1442#define PSA_ALG_IS_ECDH(alg) \
Gilles Peskine6843c292019-01-18 16:44:49 +01001443 (PSA_ALG_KEY_AGREEMENT_GET_BASE(alg) == PSA_ALG_ECDH)
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001444
Gilles Peskine30f77cd2019-01-14 16:06:39 +01001445/** Whether the specified algorithm encoding is a wildcard.
1446 *
1447 * Wildcard values may only be used to set the usage algorithm field in
1448 * a policy, not to perform an operation.
1449 *
1450 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
1451 *
1452 * \return 1 if \c alg is a wildcard algorithm encoding.
1453 * \return 0 if \c alg is a non-wildcard algorithm encoding (suitable for
1454 * an operation).
1455 * \return This macro may return either 0 or 1 if \c alg is not a supported
1456 * algorithm identifier.
1457 */
1458#define PSA_ALG_IS_WILDCARD(alg) \
1459 (PSA_ALG_IS_HASH_AND_SIGN(alg) ? \
1460 PSA_ALG_SIGN_GET_HASH(alg) == PSA_ALG_ANY_HASH : \
1461 (alg) == PSA_ALG_ANY_HASH)
1462
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001463/**@}*/
1464
1465/** \defgroup key_lifetimes Key lifetimes
1466 * @{
1467 */
1468
1469/** A volatile key only exists as long as the handle to it is not closed.
1470 * The key material is guaranteed to be erased on a power reset.
1471 */
1472#define PSA_KEY_LIFETIME_VOLATILE ((psa_key_lifetime_t)0x00000000)
1473
1474/** The default storage area for persistent keys.
1475 *
1476 * A persistent key remains in storage until it is explicitly destroyed or
1477 * until the corresponding storage area is wiped. This specification does
1478 * not define any mechanism to wipe a storage area, but implementations may
1479 * provide their own mechanism (for example to perform a factory reset,
1480 * to prepare for device refurbishment, or to uninstall an application).
1481 *
1482 * This lifetime value is the default storage area for the calling
1483 * application. Implementations may offer other storage areas designated
1484 * by other lifetime values as implementation-specific extensions.
1485 */
1486#define PSA_KEY_LIFETIME_PERSISTENT ((psa_key_lifetime_t)0x00000001)
1487
Gilles Peskine4a231b82019-05-06 18:56:14 +02001488/** The minimum value for a key identifier chosen by the application.
1489 */
Gilles Peskinef9fbc382019-05-15 18:42:09 +02001490#define PSA_KEY_ID_USER_MIN ((psa_key_id_t)0x00000001)
Gilles Peskine280948a2019-05-16 15:27:14 +02001491/** The maximum value for a key identifier chosen by the application.
Gilles Peskine4a231b82019-05-06 18:56:14 +02001492 */
1493#define PSA_KEY_ID_USER_MAX ((psa_key_id_t)0x3fffffff)
Gilles Peskine280948a2019-05-16 15:27:14 +02001494/** The minimum value for a key identifier chosen by the implementation.
Gilles Peskine4a231b82019-05-06 18:56:14 +02001495 */
1496#define PSA_KEY_ID_VENDOR_MIN ((psa_key_id_t)0x40000000)
Gilles Peskine280948a2019-05-16 15:27:14 +02001497/** The maximum value for a key identifier chosen by the implementation.
Gilles Peskine4a231b82019-05-06 18:56:14 +02001498 */
1499#define PSA_KEY_ID_VENDOR_MAX ((psa_key_id_t)0x7fffffff)
1500
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001501/**@}*/
1502
1503/** \defgroup policy Key policies
1504 * @{
1505 */
1506
1507/** Whether the key may be exported.
1508 *
1509 * A public key or the public part of a key pair may always be exported
1510 * regardless of the value of this permission flag.
1511 *
1512 * If a key does not have export permission, implementations shall not
1513 * allow the key to be exported in plain form from the cryptoprocessor,
1514 * whether through psa_export_key() or through a proprietary interface.
1515 * The key may however be exportable in a wrapped form, i.e. in a form
1516 * where it is encrypted by another key.
1517 */
1518#define PSA_KEY_USAGE_EXPORT ((psa_key_usage_t)0x00000001)
1519
Gilles Peskine8e0206a2019-05-14 14:24:28 +02001520/** Whether the key may be copied.
1521 *
Gilles Peskined6a8f5f2019-05-14 16:25:50 +02001522 * This flag allows the use of psa_copy_key() to make a copy of the key
Gilles Peskine8e0206a2019-05-14 14:24:28 +02001523 * with the same policy or a more restrictive policy.
1524 *
Gilles Peskined6a8f5f2019-05-14 16:25:50 +02001525 * For lifetimes for which the key is located in a secure element which
1526 * enforce the non-exportability of keys, copying a key outside the secure
1527 * element also requires the usage flag #PSA_KEY_USAGE_EXPORT.
1528 * Copying the key inside the secure element is permitted with just
1529 * #PSA_KEY_USAGE_COPY if the secure element supports it.
1530 * For keys with the lifetime #PSA_KEY_LIFETIME_VOLATILE or
Gilles Peskine8e0206a2019-05-14 14:24:28 +02001531 * #PSA_KEY_LIFETIME_PERSISTENT, the usage flag #PSA_KEY_USAGE_COPY
1532 * is sufficient to permit the copy.
1533 */
1534#define PSA_KEY_USAGE_COPY ((psa_key_usage_t)0x00000002)
1535
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001536/** Whether the key may be used to encrypt a message.
1537 *
1538 * This flag allows the key to be used for a symmetric encryption operation,
1539 * for an AEAD encryption-and-authentication operation,
1540 * or for an asymmetric encryption operation,
1541 * if otherwise permitted by the key's type and policy.
1542 *
1543 * For a key pair, this concerns the public key.
1544 */
1545#define PSA_KEY_USAGE_ENCRYPT ((psa_key_usage_t)0x00000100)
1546
1547/** Whether the key may be used to decrypt a message.
1548 *
1549 * This flag allows the key to be used for a symmetric decryption operation,
1550 * for an AEAD decryption-and-verification operation,
1551 * or for an asymmetric decryption operation,
1552 * if otherwise permitted by the key's type and policy.
1553 *
1554 * For a key pair, this concerns the private key.
1555 */
1556#define PSA_KEY_USAGE_DECRYPT ((psa_key_usage_t)0x00000200)
1557
1558/** Whether the key may be used to sign a message.
1559 *
1560 * This flag allows the key to be used for a MAC calculation operation
1561 * or for an asymmetric signature operation,
1562 * if otherwise permitted by the key's type and policy.
1563 *
1564 * For a key pair, this concerns the private key.
1565 */
1566#define PSA_KEY_USAGE_SIGN ((psa_key_usage_t)0x00000400)
1567
1568/** Whether the key may be used to verify a message signature.
1569 *
1570 * This flag allows the key to be used for a MAC verification operation
1571 * or for an asymmetric signature verification operation,
1572 * if otherwise permitted by by the key's type and policy.
1573 *
1574 * For a key pair, this concerns the public key.
1575 */
1576#define PSA_KEY_USAGE_VERIFY ((psa_key_usage_t)0x00000800)
1577
1578/** Whether the key may be used to derive other keys.
1579 */
1580#define PSA_KEY_USAGE_DERIVE ((psa_key_usage_t)0x00001000)
1581
1582/**@}*/
1583
Gilles Peskineb70a0fd2019-01-07 22:59:38 +01001584/** \defgroup derivation Key derivation
1585 * @{
1586 */
1587
Gilles Peskine6cdfdb72019-01-08 10:31:27 +01001588/** A secret input for key derivation.
1589 *
1590 * This must be a key of type #PSA_KEY_TYPE_DERIVE.
1591 */
Gilles Peskinecf7292e2019-05-16 17:53:40 +02001592#define PSA_KEY_DERIVATION_INPUT_SECRET ((psa_key_derivation_step_t)0x0101)
Gilles Peskine6cdfdb72019-01-08 10:31:27 +01001593
1594/** A label for key derivation.
1595 *
1596 * This must be a direct input.
1597 */
Gilles Peskinecf7292e2019-05-16 17:53:40 +02001598#define PSA_KEY_DERIVATION_INPUT_LABEL ((psa_key_derivation_step_t)0x0201)
Gilles Peskine6cdfdb72019-01-08 10:31:27 +01001599
1600/** A salt for key derivation.
1601 *
1602 * This must be a direct input.
1603 */
Gilles Peskinecf7292e2019-05-16 17:53:40 +02001604#define PSA_KEY_DERIVATION_INPUT_SALT ((psa_key_derivation_step_t)0x0202)
Gilles Peskine6cdfdb72019-01-08 10:31:27 +01001605
1606/** An information string for key derivation.
1607 *
1608 * This must be a direct input.
1609 */
Gilles Peskinecf7292e2019-05-16 17:53:40 +02001610#define PSA_KEY_DERIVATION_INPUT_INFO ((psa_key_derivation_step_t)0x0203)
Gilles Peskine6cdfdb72019-01-08 10:31:27 +01001611
Gilles Peskineb70a0fd2019-01-07 22:59:38 +01001612/**@}*/
1613
Gilles Peskinef3b731e2018-12-12 13:38:31 +01001614#endif /* PSA_CRYPTO_VALUES_H */