blob: 0bc8ad369ad4fbbce3784ace8d0da35298fb8a2b [file] [log] [blame]
Antonio de Angelis14276e92018-07-10 14:35:43 +01001/*
Mate Toth-Pal2a6f8c22018-12-13 16:37:17 +01002 * Copyright (c) 2018-2019, Arm Limited. All rights reserved.
Antonio de Angelis14276e92018-07-10 14:35:43 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8/**
9 * \file psa_crypto.h
10 * \brief Platform Security Architecture cryptography module
11 */
12
13#ifndef PSA_CRYPTO_H
14#define PSA_CRYPTO_H
15
Antonio de Angelis8908f472018-08-31 15:44:25 +010016/* The psa_crypto_platform.h header provides fundamental definitions used by
17 * this header, which are specific to the platform being used.
18 */
19#include "psa_crypto_platform.h"
20
Antonio de Angelis14276e92018-07-10 14:35:43 +010021#include <stddef.h>
22
23#ifdef __DOXYGEN_ONLY__
24/* This __DOXYGEN_ONLY__ block contains mock definitions for things that
25 * must be defined in the psa_crypto_platform.h header. These mock definitions
26 * are present in this file as a convenience to generate pretty-printed
Antonio de Angelis8908f472018-08-31 15:44:25 +010027 * documentation that includes those definitions.
28 */
Antonio de Angelis14276e92018-07-10 14:35:43 +010029
30/** \defgroup platform Implementation-specific definitions
31 * @{
32 */
33
34/** \brief Key slot number.
35 *
36 * This type represents key slots. It must be an unsigned integral
37 * type. The choice of type is implementation-dependent.
38 * 0 is not a valid key slot number. The meaning of other values is
39 * implementation dependent.
40 *
41 * At any given point in time, each key slot either contains a
42 * cryptographic object, or is empty. Key slots are persistent:
43 * once set, the cryptographic object remains in the key slot until
44 * explicitly destroyed.
45 */
46typedef _unsigned_integral_type_ psa_key_slot_t;
47
48/**@}*/
49#endif /* __DOXYGEN_ONLY__ */
50
51#ifdef __cplusplus
52extern "C" {
53#endif
54
55/** \defgroup basic Basic definitions
56 * @{
57 */
58
Mate Toth-Pal2a6f8c22018-12-13 16:37:17 +010059#if !defined(PSA_SUCCESS)
Antonio de Angelis14276e92018-07-10 14:35:43 +010060
61/** The action was completed successfully. */
62#define PSA_SUCCESS ((psa_status_t)0)
63
64#endif /* !defined(PSA_SUCCESS) */
65
66/** The requested operation or a parameter is not supported
67 * by this implementation.
68 *
69 * Implementations should return this error code when an enumeration
70 * parameter such as a key type, algorithm, etc. is not recognized.
71 * If a combination of parameters is recognized and identified as
Antonio de Angelis8908f472018-08-31 15:44:25 +010072 * not valid, return #PSA_ERROR_INVALID_ARGUMENT instead.
73 */
Antonio de Angelis14276e92018-07-10 14:35:43 +010074#define PSA_ERROR_NOT_SUPPORTED ((psa_status_t)1)
75
76/** The requested action is denied by a policy.
77 *
78 * Implementations should return this error code when the parameters
79 * are recognized as valid and supported, and a policy explicitly
80 * denies the requested operation.
81 *
82 * If a subset of the parameters of a function call identify a
83 * forbidden operation, and another subset of the parameters are
84 * not valid or not supported, it is unspecified whether the function
85 * returns #PSA_ERROR_NOT_PERMITTED, #PSA_ERROR_NOT_SUPPORTED or
Antonio de Angelis8908f472018-08-31 15:44:25 +010086 * #PSA_ERROR_INVALID_ARGUMENT.
87 */
Antonio de Angelis14276e92018-07-10 14:35:43 +010088#define PSA_ERROR_NOT_PERMITTED ((psa_status_t)2)
89
90/** An output buffer is too small.
91 *
92 * Applications can call the `PSA_xxx_SIZE` macro listed in the function
93 * description to determine a sufficient buffer size.
94 *
95 * Implementations should preferably return this error code only
96 * in cases when performing the operation with a larger output
97 * buffer would succeed. However implementations may return this
98 * error if a function has invalid or unsupported parameters in addition
Antonio de Angelis8908f472018-08-31 15:44:25 +010099 * to the parameters that determine the necessary output buffer size.
100 */
Antonio de Angelis14276e92018-07-10 14:35:43 +0100101#define PSA_ERROR_BUFFER_TOO_SMALL ((psa_status_t)3)
102
103/** A slot is occupied, but must be empty to carry out the
104 * requested action.
105 *
106 * If the slot number is invalid (i.e. the requested action could
107 * not be performed even after erasing the slot's content),
Antonio de Angelis8908f472018-08-31 15:44:25 +0100108 * implementations shall return #PSA_ERROR_INVALID_ARGUMENT instead.
109 */
Antonio de Angelis14276e92018-07-10 14:35:43 +0100110#define PSA_ERROR_OCCUPIED_SLOT ((psa_status_t)4)
111
112/** A slot is empty, but must be occupied to carry out the
113 * requested action.
114 *
115 * If the slot number is invalid (i.e. the requested action could
116 * not be performed even after creating appropriate content in the slot),
Antonio de Angelis8908f472018-08-31 15:44:25 +0100117 * implementations shall return #PSA_ERROR_INVALID_ARGUMENT instead.
118 */
Antonio de Angelis14276e92018-07-10 14:35:43 +0100119#define PSA_ERROR_EMPTY_SLOT ((psa_status_t)5)
120
121/** The requested action cannot be performed in the current state.
122 *
123 * Multipart operations return this error when one of the
124 * functions is called out of sequence. Refer to the function
125 * descriptions for permitted sequencing of functions.
126 *
127 * Implementations shall not return this error code to indicate
128 * that a key slot is occupied when it needs to be free or vice versa,
129 * but shall return #PSA_ERROR_OCCUPIED_SLOT or #PSA_ERROR_EMPTY_SLOT
Antonio de Angelis8908f472018-08-31 15:44:25 +0100130 * as applicable.
131 */
Antonio de Angelis14276e92018-07-10 14:35:43 +0100132#define PSA_ERROR_BAD_STATE ((psa_status_t)6)
133
134/** The parameters passed to the function are invalid.
135 *
136 * Implementations may return this error any time a parameter or
137 * combination of parameters are recognized as invalid.
138 *
139 * Implementations shall not return this error code to indicate
140 * that a key slot is occupied when it needs to be free or vice versa,
141 * but shall return #PSA_ERROR_OCCUPIED_SLOT or #PSA_ERROR_EMPTY_SLOT
Antonio de Angelis8908f472018-08-31 15:44:25 +0100142 * as applicable.
143 */
Antonio de Angelis14276e92018-07-10 14:35:43 +0100144#define PSA_ERROR_INVALID_ARGUMENT ((psa_status_t)7)
145
146/** There is not enough runtime memory.
147 *
148 * If the action is carried out across multiple security realms, this
Antonio de Angelis8908f472018-08-31 15:44:25 +0100149 * error can refer to available memory in any of the security realms.
150 */
Antonio de Angelis14276e92018-07-10 14:35:43 +0100151#define PSA_ERROR_INSUFFICIENT_MEMORY ((psa_status_t)8)
152
153/** There is not enough persistent storage.
154 *
155 * Functions that modify the key storage return this error code if
156 * there is insufficient storage space on the host media. In addition,
157 * many functions that do not otherwise access storage may return this
158 * error code if the implementation requires a mandatory log entry for
Antonio de Angelis8908f472018-08-31 15:44:25 +0100159 * the requested action and the log storage space is full.
160 */
Antonio de Angelis14276e92018-07-10 14:35:43 +0100161#define PSA_ERROR_INSUFFICIENT_STORAGE ((psa_status_t)9)
162
163/** There was a communication failure inside the implementation.
164 *
165 * This can indicate a communication failure between the application
166 * and an external cryptoprocessor or between the cryptoprocessor and
167 * an external volatile or persistent memory. A communication failure
168 * may be transient or permanent depending on the cause.
169 *
170 * \warning If a function returns this error, it is undetermined
171 * whether the requested action has completed or not. Implementations
172 * should return #PSA_SUCCESS on successful completion whenver
173 * possible, however functions may return #PSA_ERROR_COMMUNICATION_FAILURE
174 * if the requested action was completed successfully in an external
175 * cryptoprocessor but there was a breakdown of communication before
176 * the cryptoprocessor could report the status to the application.
177 */
178#define PSA_ERROR_COMMUNICATION_FAILURE ((psa_status_t)10)
179
180/** There was a storage failure that may have led to data loss.
181 *
182 * This error indicates that some persistent storage is corrupted.
183 * It should not be used for a corruption of volatile memory
184 * (use #PSA_ERROR_TAMPERING_DETECTED), for a communication error
185 * between the cryptoprocessor and its external storage (use
186 * #PSA_ERROR_COMMUNICATION_FAILURE), or when the storage is
187 * in a valid state but is full (use #PSA_ERROR_INSUFFICIENT_STORAGE).
188 *
189 * Note that a storage failure does not indicate that any data that was
190 * previously read is invalid. However this previously read data may no
191 * longer be readable from storage.
192 *
193 * When a storage failure occurs, it is no longer possible to ensure
194 * the global integrity of the keystore. Depending on the global
195 * integrity guarantees offered by the implementation, access to other
196 * data may or may not fail even if the data is still readable but
197 * its integrity canont be guaranteed.
198 *
199 * Implementations should only use this error code to report a
200 * permanent storage corruption. However application writers should
201 * keep in mind that transient errors while reading the storage may be
Antonio de Angelis8908f472018-08-31 15:44:25 +0100202 * reported using this error code.
203 */
Antonio de Angelis14276e92018-07-10 14:35:43 +0100204#define PSA_ERROR_STORAGE_FAILURE ((psa_status_t)11)
205
206/** A hardware failure was detected.
207 *
208 * A hardware failure may be transient or permanent depending on the
Antonio de Angelis8908f472018-08-31 15:44:25 +0100209 * cause.
210 */
Antonio de Angelis14276e92018-07-10 14:35:43 +0100211#define PSA_ERROR_HARDWARE_FAILURE ((psa_status_t)12)
212
213/** A tampering attempt was detected.
214 *
215 * If an application receives this error code, there is no guarantee
216 * that previously accessed or computed data was correct and remains
217 * confidential. Applications should not perform any security function
218 * and should enter a safe failure state.
219 *
220 * Implementations may return this error code if they detect an invalid
221 * state that cannot happen during normal operation and that indicates
222 * that the implementation's security guarantees no longer hold. Depending
223 * on the implementation architecture and on its security and safety goals,
224 * the implementation may forcibly terminate the application.
225 *
226 * This error code is intended as a last resort when a security breach
227 * is detected and it is unsure whether the keystore data is still
228 * protected. Implementations shall only return this error code
229 * to report an alarm from a tampering detector, to indicate that
230 * the confidentiality of stored data can no longer be guaranteed,
231 * or to indicate that the integrity of previously returned data is now
232 * considered compromised. Implementations shall not use this error code
233 * to indicate a hardware failure that merely makes it impossible to
234 * perform the requested operation (use #PSA_ERROR_COMMUNICATION_FAILURE,
235 * #PSA_ERROR_STORAGE_FAILURE, #PSA_ERROR_HARDWARE_FAILURE,
236 * #PSA_ERROR_INSUFFICIENT_ENTROPY or other applicable error code
237 * instead).
238 *
239 * This error indicates an attack against the application. Implementations
240 * shall not return this error code as a consequence of the behavior of
Antonio de Angelis8908f472018-08-31 15:44:25 +0100241 * the application itself.
242 */
Antonio de Angelis14276e92018-07-10 14:35:43 +0100243#define PSA_ERROR_TAMPERING_DETECTED ((psa_status_t)13)
244
245/** There is not enough entropy to generate random data needed
246 * for the requested action.
247 *
248 * This error indicates a failure of a hardware random generator.
249 * Application writers should note that this error can be returned not
250 * only by functions whose purpose is to generate random data, such
251 * as key, IV or nonce generation, but also by functions that execute
252 * an algorithm with a randomized result, as well as functions that
253 * use randomization of intermediate computations as a countermeasure
254 * to certain attacks.
255 *
256 * Implementations should avoid returning this error after psa_crypto_init()
257 * has succeeded. Implementations should generate sufficient
258 * entropy during initialization and subsequently use a cryptographically
259 * secure pseudorandom generator (PRNG). However implementations may return
260 * this error at any time if a policy requires the PRNG to be reseeded
Antonio de Angelis8908f472018-08-31 15:44:25 +0100261 * during normal operation.
262 */
Antonio de Angelis14276e92018-07-10 14:35:43 +0100263#define PSA_ERROR_INSUFFICIENT_ENTROPY ((psa_status_t)14)
264
265/** The signature, MAC or hash is incorrect.
266 *
267 * Verification functions return this error if the verification
268 * calculations completed successfully, and the value to be verified
269 * was determined to be incorrect.
270 *
271 * If the value to verify has an invalid size, implementations may return
Antonio de Angelis8908f472018-08-31 15:44:25 +0100272 * either #PSA_ERROR_INVALID_ARGUMENT or #PSA_ERROR_INVALID_SIGNATURE.
273 */
Antonio de Angelis14276e92018-07-10 14:35:43 +0100274#define PSA_ERROR_INVALID_SIGNATURE ((psa_status_t)15)
275
276/** The decrypted padding is incorrect.
277 *
278 * \warning In some protocols, when decrypting data, it is essential that
279 * the behavior of the application does not depend on whether the padding
280 * is correct, down to precise timing. Applications should prefer
281 * protocols that use authenticated encryption rather than plain
282 * encryption. If the application must perform a decryption of
283 * unauthenticated data, the application writer should take care not
284 * to reveal whether the padding is invalid.
285 *
286 * Implementations should strive to make valid and invalid padding
287 * as close as possible to indistinguishable to an external observer.
288 * In particular, the timing of a decryption operation should not
Antonio de Angelis8908f472018-08-31 15:44:25 +0100289 * depend on the validity of the padding.
290 */
Antonio de Angelis14276e92018-07-10 14:35:43 +0100291#define PSA_ERROR_INVALID_PADDING ((psa_status_t)16)
292
293/** An error occurred that does not correspond to any defined
294 * failure cause.
295 *
296 * Implementations may use this error code if none of the other standard
Antonio de Angelis8908f472018-08-31 15:44:25 +0100297 * error codes are applicable.
298 */
Antonio de Angelis14276e92018-07-10 14:35:43 +0100299#define PSA_ERROR_UNKNOWN_ERROR ((psa_status_t)17)
300
301/**
302 * \brief Library initialization.
303 *
304 * Applications must call this function before calling any other
305 * function in this module.
306 *
307 * Applications may call this function more than once. Once a call
308 * succeeds, subsequent calls are guaranteed to succeed.
309 *
310 * \retval PSA_SUCCESS
311 * \retval PSA_ERROR_INSUFFICIENT_MEMORY
312 * \retval PSA_ERROR_COMMUNICATION_FAILURE
313 * \retval PSA_ERROR_HARDWARE_FAILURE
314 * \retval PSA_ERROR_TAMPERING_DETECTED
315 * \retval PSA_ERROR_INSUFFICIENT_ENTROPY
316 */
317psa_status_t psa_crypto_init(void);
318
319#define PSA_BITS_TO_BYTES(bits) (((bits) + 7) / 8)
320#define PSA_BYTES_TO_BITS(bytes) ((bytes) * 8)
321
322/**@}*/
323
324/** \defgroup crypto_types Key and algorithm types
325 * @{
326 */
327
Antonio de Angelis8908f472018-08-31 15:44:25 +0100328/** \brief Encoding of a key type. */
Antonio de Angelis14276e92018-07-10 14:35:43 +0100329typedef uint32_t psa_key_type_t;
330
331/** An invalid key type value.
332 *
333 * Zero is not the encoding of any key type.
334 */
335#define PSA_KEY_TYPE_NONE ((psa_key_type_t)0x00000000)
336
337/** Vendor-defined flag
338 *
339 * Key types defined by this standard will never have the
340 * #PSA_KEY_TYPE_VENDOR_FLAG bit set. Vendors who define additional key types
341 * must use an encoding with the #PSA_KEY_TYPE_VENDOR_FLAG bit set and should
342 * respect the bitwise structure used by standard encodings whenever practical.
343 */
344#define PSA_KEY_TYPE_VENDOR_FLAG ((psa_key_type_t)0x80000000)
345
346#define PSA_KEY_TYPE_CATEGORY_MASK ((psa_key_type_t)0x7e000000)
347/** Raw data.
348 *
349 * A "key" of this type cannot be used for any cryptographic operation.
Antonio de Angelis8908f472018-08-31 15:44:25 +0100350 * Applications may use this type to store arbitrary data in the keystore.
351 */
Antonio de Angelis14276e92018-07-10 14:35:43 +0100352#define PSA_KEY_TYPE_RAW_DATA ((psa_key_type_t)0x02000000)
353#define PSA_KEY_TYPE_CATEGORY_SYMMETRIC ((psa_key_type_t)0x04000000)
354#define PSA_KEY_TYPE_CATEGORY_ASYMMETRIC ((psa_key_type_t)0x06000000)
355#define PSA_KEY_TYPE_PAIR_FLAG ((psa_key_type_t)0x01000000)
356
357/** HMAC key.
358 *
359 * The key policy determines which underlying hash algorithm the key can be
360 * used for.
361 *
362 * HMAC keys should generally have the same size as the underlying hash.
363 * This size can be calculated with `PSA_HASH_SIZE(alg)` where
Antonio de Angelis8908f472018-08-31 15:44:25 +0100364 * `alg` is the HMAC algorithm or the underlying hash algorithm.
365 */
Antonio de Angelis14276e92018-07-10 14:35:43 +0100366#define PSA_KEY_TYPE_HMAC ((psa_key_type_t)0x02000001)
367/** Key for an cipher, AEAD or MAC algorithm based on the AES block cipher.
368 *
369 * The size of the key can be 16 bytes (AES-128), 24 bytes (AES-192) or
370 * 32 bytes (AES-256).
371 */
372#define PSA_KEY_TYPE_AES ((psa_key_type_t)0x04000001)
373/** Key for a cipher or MAC algorithm based on DES or 3DES (Triple-DES).
374 *
375 * The size of the key can be 8 bytes (single DES), 16 bytes (2-key 3DES) or
376 * 24 bytes (3-key 3DES).
377 *
378 * Note that single DES and 2-key 3DES are weak and strongly
379 * deprecated and should only be used to decrypt legacy data. 3-key 3DES
380 * is weak and deprecated and should only be used in legacy protocols.
381 */
382#define PSA_KEY_TYPE_DES ((psa_key_type_t)0x04000002)
383/** Key for an cipher, AEAD or MAC algorithm based on the
Antonio de Angelis8908f472018-08-31 15:44:25 +0100384 * Camellia block cipher.
385 */
Antonio de Angelis14276e92018-07-10 14:35:43 +0100386#define PSA_KEY_TYPE_CAMELLIA ((psa_key_type_t)0x04000003)
387/** Key for the RC4 stream cipher.
388 *
389 * Note that RC4 is weak and deprecated and should only be used in
Antonio de Angelis8908f472018-08-31 15:44:25 +0100390 * legacy protocols.
391 */
Antonio de Angelis14276e92018-07-10 14:35:43 +0100392#define PSA_KEY_TYPE_ARC4 ((psa_key_type_t)0x04000004)
393
394/** RSA public key. */
395#define PSA_KEY_TYPE_RSA_PUBLIC_KEY ((psa_key_type_t)0x06010000)
396/** RSA key pair (private and public key). */
397#define PSA_KEY_TYPE_RSA_KEYPAIR ((psa_key_type_t)0x07010000)
398/** DSA public key. */
399#define PSA_KEY_TYPE_DSA_PUBLIC_KEY ((psa_key_type_t)0x06020000)
400/** DSA key pair (private and public key). */
401#define PSA_KEY_TYPE_DSA_KEYPAIR ((psa_key_type_t)0x07020000)
402#define PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE ((psa_key_type_t)0x06030000)
403#define PSA_KEY_TYPE_ECC_KEYPAIR_BASE ((psa_key_type_t)0x07030000)
404#define PSA_KEY_TYPE_ECC_CURVE_MASK ((psa_key_type_t)0x0000ffff)
405#define PSA_KEY_TYPE_ECC_KEYPAIR(curve) \
406 (PSA_KEY_TYPE_ECC_KEYPAIR_BASE | (curve))
407#define PSA_KEY_TYPE_ECC_PUBLIC_KEY(curve) \
408 (PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE | (curve))
409
410/** Whether a key type is vendor-defined. */
411#define PSA_KEY_TYPE_IS_VENDOR_DEFINED(type) \
412 (((type) & PSA_KEY_TYPE_VENDOR_FLAG) != 0)
413
414/** Whether a key type is asymmetric: either a key pair or a public key. */
415#define PSA_KEY_TYPE_IS_ASYMMETRIC(type) \
416 (((type) & PSA_KEY_TYPE_CATEGORY_MASK) == PSA_KEY_TYPE_CATEGORY_ASYMMETRIC)
417/** Whether a key type is the public part of a key pair. */
418#define PSA_KEY_TYPE_IS_PUBLIC_KEY(type) \
419 (((type) & (PSA_KEY_TYPE_CATEGORY_MASK | PSA_KEY_TYPE_PAIR_FLAG)) == \
420 PSA_KEY_TYPE_CATEGORY_ASYMMETRIC)
421/** Whether a key type is a key pair containing a private part and a public
Antonio de Angelis8908f472018-08-31 15:44:25 +0100422 * part.
423 */
Antonio de Angelis14276e92018-07-10 14:35:43 +0100424#define PSA_KEY_TYPE_IS_KEYPAIR(type) \
425 (((type) & (PSA_KEY_TYPE_CATEGORY_MASK | PSA_KEY_TYPE_PAIR_FLAG)) == \
426 (PSA_KEY_TYPE_CATEGORY_ASYMMETRIC | PSA_KEY_TYPE_PAIR_FLAG))
427/** Whether a key type is an RSA key pair or public key. */
428/** The key pair type corresponding to a public key type. */
429#define PSA_KEY_TYPE_KEYPAIR_OF_PUBLIC_KEY(type) \
430 ((type) | PSA_KEY_TYPE_PAIR_FLAG)
431/** The public key type corresponding to a key pair type. */
432#define PSA_KEY_TYPE_PUBLIC_KEY_OF_KEYPAIR(type) \
433 ((type) & ~PSA_KEY_TYPE_PAIR_FLAG)
434#define PSA_KEY_TYPE_IS_RSA(type) \
435 (PSA_KEY_TYPE_PUBLIC_KEY_OF_KEYPAIR(type) == PSA_KEY_TYPE_RSA_PUBLIC_KEY)
436/** Whether a key type is an elliptic curve key pair or public key. */
437#define PSA_KEY_TYPE_IS_ECC(type) \
438 ((PSA_KEY_TYPE_PUBLIC_KEY_OF_KEYPAIR(type) & \
439 ~PSA_KEY_TYPE_ECC_CURVE_MASK) == PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE)
440
Antonio de Angelis8908f472018-08-31 15:44:25 +0100441/** \brief The type of PSA elliptic curve identifiers. */
Antonio de Angelis14276e92018-07-10 14:35:43 +0100442typedef uint16_t psa_ecc_curve_t;
443/** Extract the curve from an elliptic curve key type. */
444#define PSA_KEY_TYPE_GET_CURVE(type) \
445 ((psa_ecc_curve_t) (PSA_KEY_TYPE_IS_ECC(type) ? \
446 ((type) & PSA_KEY_TYPE_ECC_CURVE_MASK) : \
447 0))
448
449/* The encoding of curve identifiers is currently aligned with the
450 * TLS Supported Groups Registry (formerly known as the
451 * TLS EC Named Curve Registry)
Antonio de Angelis8908f472018-08-31 15:44:25 +0100452 * https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml
453 * #tls-parameters-8
454 * The values are defined by RFC 4492, RFC 7027 and RFC 7919.
455 */
Antonio de Angelis14276e92018-07-10 14:35:43 +0100456#define PSA_ECC_CURVE_SECT163K1 ((psa_ecc_curve_t) 0x0001)
457#define PSA_ECC_CURVE_SECT163R1 ((psa_ecc_curve_t) 0x0002)
458#define PSA_ECC_CURVE_SECT163R2 ((psa_ecc_curve_t) 0x0003)
459#define PSA_ECC_CURVE_SECT193R1 ((psa_ecc_curve_t) 0x0004)
460#define PSA_ECC_CURVE_SECT193R2 ((psa_ecc_curve_t) 0x0005)
461#define PSA_ECC_CURVE_SECT233K1 ((psa_ecc_curve_t) 0x0006)
462#define PSA_ECC_CURVE_SECT233R1 ((psa_ecc_curve_t) 0x0007)
463#define PSA_ECC_CURVE_SECT239K1 ((psa_ecc_curve_t) 0x0008)
464#define PSA_ECC_CURVE_SECT283K1 ((psa_ecc_curve_t) 0x0009)
465#define PSA_ECC_CURVE_SECT283R1 ((psa_ecc_curve_t) 0x000a)
466#define PSA_ECC_CURVE_SECT409K1 ((psa_ecc_curve_t) 0x000b)
467#define PSA_ECC_CURVE_SECT409R1 ((psa_ecc_curve_t) 0x000c)
468#define PSA_ECC_CURVE_SECT571K1 ((psa_ecc_curve_t) 0x000d)
469#define PSA_ECC_CURVE_SECT571R1 ((psa_ecc_curve_t) 0x000e)
470#define PSA_ECC_CURVE_SECP160K1 ((psa_ecc_curve_t) 0x000f)
471#define PSA_ECC_CURVE_SECP160R1 ((psa_ecc_curve_t) 0x0010)
472#define PSA_ECC_CURVE_SECP160R2 ((psa_ecc_curve_t) 0x0011)
473#define PSA_ECC_CURVE_SECP192K1 ((psa_ecc_curve_t) 0x0012)
474#define PSA_ECC_CURVE_SECP192R1 ((psa_ecc_curve_t) 0x0013)
475#define PSA_ECC_CURVE_SECP224K1 ((psa_ecc_curve_t) 0x0014)
476#define PSA_ECC_CURVE_SECP224R1 ((psa_ecc_curve_t) 0x0015)
477#define PSA_ECC_CURVE_SECP256K1 ((psa_ecc_curve_t) 0x0016)
478#define PSA_ECC_CURVE_SECP256R1 ((psa_ecc_curve_t) 0x0017)
479#define PSA_ECC_CURVE_SECP384R1 ((psa_ecc_curve_t) 0x0018)
480#define PSA_ECC_CURVE_SECP521R1 ((psa_ecc_curve_t) 0x0019)
481#define PSA_ECC_CURVE_BRAINPOOL_P256R1 ((psa_ecc_curve_t) 0x001a)
482#define PSA_ECC_CURVE_BRAINPOOL_P384R1 ((psa_ecc_curve_t) 0x001b)
483#define PSA_ECC_CURVE_BRAINPOOL_P512R1 ((psa_ecc_curve_t) 0x001c)
484#define PSA_ECC_CURVE_CURVE25519 ((psa_ecc_curve_t) 0x001d)
485#define PSA_ECC_CURVE_CURVE448 ((psa_ecc_curve_t) 0x001e)
486#define PSA_ECC_CURVE_FFDHE_2048 ((psa_ecc_curve_t) 0x0100)
487#define PSA_ECC_CURVE_FFDHE_3072 ((psa_ecc_curve_t) 0x0101)
488#define PSA_ECC_CURVE_FFDHE_4096 ((psa_ecc_curve_t) 0x0102)
489#define PSA_ECC_CURVE_FFDHE_6144 ((psa_ecc_curve_t) 0x0103)
490#define PSA_ECC_CURVE_FFDHE_8192 ((psa_ecc_curve_t) 0x0104)
491
492/** The block size of a block cipher.
493 *
494 * \param type A cipher key type (value of type #psa_key_type_t).
495 *
496 * \return The block size for a block cipher, or 1 for a stream cipher.
497 * The return value is undefined if \c type is not a supported
498 * cipher key type.
499 *
500 * \note It is possible to build stream cipher algorithms on top of a block
501 * cipher, for example CTR mode (#PSA_ALG_CTR).
502 * This macro only takes the key type into account, so it cannot be
503 * used to determine the size of the data that #psa_cipher_update()
504 * might buffer for future processing in general.
505 *
506 * \note This macro returns a compile-time constant if its argument is one.
507 *
508 * \warning This macro may evaluate its argument multiple times.
509 */
510#define PSA_BLOCK_CIPHER_BLOCK_SIZE(type) \
511 ( \
512 (type) == PSA_KEY_TYPE_AES ? 16 : \
513 (type) == PSA_KEY_TYPE_DES ? 8 : \
514 (type) == PSA_KEY_TYPE_CAMELLIA ? 16 : \
515 (type) == PSA_KEY_TYPE_ARC4 ? 1 : \
516 0)
517
518/** \brief Encoding of a cryptographic algorithm.
519 *
520 * For algorithms that can be applied to multiple key types, this type
521 * does not encode the key type. For example, for symmetric ciphers
522 * based on a block cipher, #psa_algorithm_t encodes the block cipher
523 * mode and the padding mode while the block cipher itself is encoded
524 * via #psa_key_type_t.
525 */
526typedef uint32_t psa_algorithm_t;
527
528#define PSA_ALG_VENDOR_FLAG ((psa_algorithm_t)0x80000000)
529#define PSA_ALG_CATEGORY_MASK ((psa_algorithm_t)0x7f000000)
530#define PSA_ALG_CATEGORY_HASH ((psa_algorithm_t)0x01000000)
531#define PSA_ALG_CATEGORY_MAC ((psa_algorithm_t)0x02000000)
532#define PSA_ALG_CATEGORY_CIPHER ((psa_algorithm_t)0x04000000)
533#define PSA_ALG_CATEGORY_AEAD ((psa_algorithm_t)0x06000000)
534#define PSA_ALG_CATEGORY_SIGN ((psa_algorithm_t)0x10000000)
535#define PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION ((psa_algorithm_t)0x12000000)
536#define PSA_ALG_CATEGORY_KEY_AGREEMENT ((psa_algorithm_t)0x22000000)
537#define PSA_ALG_CATEGORY_KEY_DERIVATION ((psa_algorithm_t)0x30000000)
538
539#define PSA_ALG_IS_VENDOR_DEFINED(alg) \
540 (((alg) & PSA_ALG_VENDOR_FLAG) != 0)
541/** Whether the specified algorithm is a hash algorithm.
542 *
543 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
544 *
545 * \return 1 if \c alg is a hash algorithm, 0 otherwise.
546 * This macro may return either 0 or 1 if \c alg is not a valid
547 * algorithm identifier.
548 */
549#define PSA_ALG_IS_HASH(alg) \
550 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_HASH)
551#define PSA_ALG_IS_MAC(alg) \
552 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_MAC)
553#define PSA_ALG_IS_CIPHER(alg) \
554 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_CIPHER)
555#define PSA_ALG_IS_AEAD(alg) \
556 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_AEAD)
557#define PSA_ALG_IS_SIGN(alg) \
558 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_SIGN)
559#define PSA_ALG_IS_ASYMMETRIC_ENCRYPTION(alg) \
560 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION)
561#define PSA_ALG_IS_KEY_AGREEMENT(alg) \
562 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_KEY_AGREEMENT)
563#define PSA_ALG_IS_KEY_DERIVATION(alg) \
564 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_KEY_DERIVATION)
565
566#define PSA_ALG_HASH_MASK ((psa_algorithm_t)0x000000ff)
567#define PSA_ALG_MD2 ((psa_algorithm_t)0x01000001)
568#define PSA_ALG_MD4 ((psa_algorithm_t)0x01000002)
569#define PSA_ALG_MD5 ((psa_algorithm_t)0x01000003)
570#define PSA_ALG_RIPEMD160 ((psa_algorithm_t)0x01000004)
571#define PSA_ALG_SHA_1 ((psa_algorithm_t)0x01000005)
572#define PSA_ALG_SHA_224 ((psa_algorithm_t)0x01000008)
573#define PSA_ALG_SHA_256 ((psa_algorithm_t)0x01000009)
574#define PSA_ALG_SHA_384 ((psa_algorithm_t)0x0100000a)
575#define PSA_ALG_SHA_512 ((psa_algorithm_t)0x0100000b)
576#define PSA_ALG_SHA_512_224 ((psa_algorithm_t)0x0100000c)
577#define PSA_ALG_SHA_512_256 ((psa_algorithm_t)0x0100000d)
578#define PSA_ALG_SHA3_224 ((psa_algorithm_t)0x01000010)
579#define PSA_ALG_SHA3_256 ((psa_algorithm_t)0x01000011)
580#define PSA_ALG_SHA3_384 ((psa_algorithm_t)0x01000012)
581#define PSA_ALG_SHA3_512 ((psa_algorithm_t)0x01000013)
582
583#define PSA_ALG_MAC_SUBCATEGORY_MASK ((psa_algorithm_t)0x00c00000)
584#define PSA_ALG_HMAC_BASE ((psa_algorithm_t)0x02800000)
585/** Macro to build an HMAC algorithm.
586 *
587 * For example, `PSA_ALG_HMAC(PSA_ALG_SHA256)` is HMAC-SHA-256.
588 *
589 * \param alg A hash algorithm (\c PSA_ALG_XXX value such that
590 * #PSA_ALG_IS_HASH(alg) is true).
591 *
592 * \return The corresponding HMAC algorithm.
593 * \return Unspecified if \p alg is not a hash algorithm.
594 */
595#define PSA_ALG_HMAC(hash_alg) \
596 (PSA_ALG_HMAC_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
597#define PSA_ALG_HMAC_HASH(hmac_alg) \
598 (PSA_ALG_CATEGORY_HASH | ((hmac_alg) & PSA_ALG_HASH_MASK))
599#define PSA_ALG_IS_HMAC(alg) \
600 (((alg) & (PSA_ALG_CATEGORY_MASK | PSA_ALG_MAC_SUBCATEGORY_MASK)) == \
601 PSA_ALG_HMAC_BASE)
602#define PSA_ALG_CIPHER_MAC_BASE ((psa_algorithm_t)0x02c00000)
603#define PSA_ALG_CBC_MAC ((psa_algorithm_t)0x02c00001)
604#define PSA_ALG_CMAC ((psa_algorithm_t)0x02c00002)
605#define PSA_ALG_GMAC ((psa_algorithm_t)0x02c00003)
606#define PSA_ALG_IS_CIPHER_MAC(alg) \
607 (((alg) & (PSA_ALG_CATEGORY_MASK | PSA_ALG_MAC_SUBCATEGORY_MASK)) == \
608 PSA_ALG_CIPHER_MAC_BASE)
609
610#define PSA_ALG_CIPHER_SUBCATEGORY_MASK ((psa_algorithm_t)0x00c00000)
611#define PSA_ALG_BLOCK_CIPHER_BASE ((psa_algorithm_t)0x04000000)
612#define PSA_ALG_BLOCK_CIPHER_MODE_MASK ((psa_algorithm_t)0x000000ff)
613#define PSA_ALG_BLOCK_CIPHER_PADDING_MASK ((psa_algorithm_t)0x003f0000)
614#define PSA_ALG_BLOCK_CIPHER_PAD_NONE ((psa_algorithm_t)0x00000000)
615#define PSA_ALG_BLOCK_CIPHER_PAD_PKCS7 ((psa_algorithm_t)0x00010000)
616#define PSA_ALG_IS_BLOCK_CIPHER(alg) \
617 (((alg) & (PSA_ALG_CATEGORY_MASK | PSA_ALG_CIPHER_SUBCATEGORY_MASK)) == \
618 PSA_ALG_BLOCK_CIPHER_BASE)
619
620#define PSA_ALG_CBC_BASE ((psa_algorithm_t)0x04000001)
621#define PSA_ALG_CFB_BASE ((psa_algorithm_t)0x04000002)
622#define PSA_ALG_OFB_BASE ((psa_algorithm_t)0x04000003)
623#define PSA_ALG_XTS_BASE ((psa_algorithm_t)0x04000004)
624#define PSA_ALG_STREAM_CIPHER ((psa_algorithm_t)0x04800000)
625#define PSA_ALG_CTR ((psa_algorithm_t)0x04800001)
626#define PSA_ALG_ARC4 ((psa_algorithm_t)0x04800002)
627
628#define PSA_ALG_IS_STREAM_CIPHER(alg) \
629 (((alg) & (PSA_ALG_CATEGORY_MASK | PSA_ALG_CIPHER_SUBCATEGORY_MASK)) == \
630 PSA_ALG_STREAM_CIPHER)
631
632#define PSA_ALG_CCM ((psa_algorithm_t)0x06000001)
633#define PSA_ALG_GCM ((psa_algorithm_t)0x06000002)
634
635#define PSA_ALG_RSA_PKCS1V15_SIGN_RAW ((psa_algorithm_t)0x10010000)
636#define PSA_ALG_RSA_PSS_MGF1 ((psa_algorithm_t)0x10020000)
637#define PSA_ALG_RSA_PKCS1V15_CRYPT ((psa_algorithm_t)0x12010000)
638#define PSA_ALG_RSA_OAEP_MGF1_BASE ((psa_algorithm_t)0x12020000)
639#define PSA_ALG_RSA_PKCS1V15_SIGN(hash_alg) \
640 (PSA_ALG_RSA_PKCS1V15_SIGN_RAW | ((hash_alg) & PSA_ALG_HASH_MASK))
641#define PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) \
642 (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_RSA_PKCS1V15_SIGN_RAW)
643#define PSA_ALG_RSA_OAEP_MGF1(hash_alg) \
644 (PSA_ALG_RSA_OAEP_MGF1_RAW | ((hash_alg) & PSA_ALG_HASH_MASK))
645#define PSA_ALG_IS_RSA_OAEP_MGF1(alg) \
646 (((alg) & ~PSA_ALG_HASH_MASK) == PSA_ALG_RSA_OAEP_MGF1_BASE)
647#define PSA_ALG_RSA_GET_HASH(alg) \
648 (((alg) & PSA_ALG_HASH_MASK) | PSA_ALG_CATEGORY_HASH)
649
650#define PSA_ALG_ECDSA_RAW ((psa_algorithm_t)0x10030000)
651
652/**@}*/
653
654/** \defgroup key_management Key management
655 * @{
656 */
657
658/**
659 * \brief Import a key in binary format.
660 *
661 * This function supports any output from psa_export_key(). Refer to the
662 * documentation of psa_export_key() for the format for each key type.
663 *
664 * \param key Slot where the key will be stored. This must be a
665 * valid slot for a key of the chosen type. It must
666 * be unoccupied.
667 * \param type Key type (a \c PSA_KEY_TYPE_XXX value).
668 * \param data Buffer containing the key data.
669 * \param data_length Size of the \c data buffer in bytes.
670 *
671 * \retval PSA_SUCCESS
672 * Success.
673 * \retval PSA_ERROR_NOT_SUPPORTED
674 * The key type or key size is not supported, either by the
675 * implementation in general or in this particular slot.
676 * \retval PSA_ERROR_INVALID_ARGUMENT
677 * The key slot is invalid,
678 * or the key data is not correctly formatted.
679 * \retval PSA_ERROR_OCCUPIED_SLOT
680 * There is already a key in the specified slot.
681 * \retval PSA_ERROR_INSUFFICIENT_MEMORY
682 * \retval PSA_ERROR_INSUFFICIENT_STORAGE
683 * \retval PSA_ERROR_COMMUNICATION_FAILURE
684 * \retval PSA_ERROR_HARDWARE_FAILURE
685 * \retval PSA_ERROR_TAMPERING_DETECTED
686 */
687psa_status_t psa_import_key(psa_key_slot_t key,
688 psa_key_type_t type,
689 const uint8_t *data,
690 size_t data_length);
691
692/**
693 * \brief Destroy a key and restore the slot to its default state.
694 *
695 * This function destroys the content of the key slot from both volatile
696 * memory and, if applicable, non-volatile storage. Implementations shall
697 * make a best effort to ensure that any previous content of the slot is
698 * unrecoverable.
699 *
700 * This function also erases any metadata such as policies. It returns the
701 * specified slot to its default state.
702 *
703 * \param key The key slot to erase.
704 *
705 * \retval PSA_SUCCESS
706 * The slot's content, if any, has been erased.
707 * \retval PSA_ERROR_NOT_PERMITTED
708 * The slot holds content and cannot be erased because it is
709 * read-only, either due to a policy or due to physical restrictions.
710 * \retval PSA_ERROR_INVALID_ARGUMENT
711 * The specified slot number does not designate a valid slot.
712 * \retval PSA_ERROR_COMMUNICATION_FAILURE
713 * There was an failure in communication with the cryptoprocessor.
714 * The key material may still be present in the cryptoprocessor.
715 * \retval PSA_ERROR_STORAGE_FAILURE
716 * The storage is corrupted. Implementations shall make a best effort
717 * to erase key material even in this stage, however applications
718 * should be aware that it may be impossible to guarantee that the
719 * key material is not recoverable in such cases.
720 * \retval PSA_ERROR_TAMPERING_DETECTED
721 * An unexpected condition which is not a storage corruption or
722 * a communication failure occurred. The cryptoprocessor may have
723 * been compromised.
724 */
725psa_status_t psa_destroy_key(psa_key_slot_t key);
726
727/**
728 * \brief Get basic metadata about a key.
729 *
730 * \param key Slot whose content is queried. This must
731 * be an occupied key slot.
732 * \param type On success, the key type (a \c PSA_KEY_TYPE_XXX value).
733 * This may be a null pointer, in which case the key type
734 * is not written.
735 * \param bits On success, the key size in bits.
736 * This may be a null pointer, in which case the key size
737 * is not written.
738 *
739 * \retval PSA_SUCCESS
740 * \retval PSA_ERROR_EMPTY_SLOT
741 * \retval PSA_ERROR_COMMUNICATION_FAILURE
742 * \retval PSA_ERROR_HARDWARE_FAILURE
743 * \retval PSA_ERROR_TAMPERING_DETECTED
744 */
745psa_status_t psa_get_key_information(psa_key_slot_t key,
746 psa_key_type_t *type,
747 size_t *bits);
748
749/**
750 * \brief Export a key in binary format.
751 *
752 * The output of this function can be passed to psa_import_key() to
753 * create an equivalent object.
754 *
755 * If a key is created with psa_import_key() and then exported with
756 * this function, it is not guaranteed that the resulting data is
757 * identical: the implementation may choose a different representation
758 * of the same key if the format permits it.
759 *
760 * For standard key types, the output format is as follows:
761 *
762 * - For symmetric keys (including MAC keys), the format is the
763 * raw bytes of the key.
764 * - For DES, the key data consists of 8 bytes. The parity bits must be
765 * correct.
766 * - For Triple-DES, the format is the concatenation of the
767 * two or three DES keys.
768 * - For RSA key pairs (#PSA_KEY_TYPE_RSA_KEYPAIR), the format
769 * is the non-encrypted DER representation defined by PKCS\#8 (RFC 5208)
770 * as PrivateKeyInfo.
771 * - For RSA public keys (#PSA_KEY_TYPE_RSA_PUBLIC_KEY), the format
772 * is the DER representation defined by RFC 5280 as SubjectPublicKeyInfo.
773 *
774 * \param key Slot whose content is to be exported. This must
775 * be an occupied key slot.
776 * \param data Buffer where the key data is to be written.
777 * \param data_size Size of the \c data buffer in bytes.
778 * \param data_length On success, the number of bytes
779 * that make up the key data.
780 *
781 * \retval PSA_SUCCESS
782 * \retval PSA_ERROR_EMPTY_SLOT
783 * \retval PSA_ERROR_NOT_PERMITTED
784 * \retval PSA_ERROR_COMMUNICATION_FAILURE
785 * \retval PSA_ERROR_HARDWARE_FAILURE
786 * \retval PSA_ERROR_TAMPERING_DETECTED
787 */
788psa_status_t psa_export_key(psa_key_slot_t key,
789 uint8_t *data,
790 size_t data_size,
791 size_t *data_length);
792
793/**
794 * \brief Export a public key or the public part of a key pair in binary format.
795 *
796 * The output of this function can be passed to psa_import_key() to
797 * create an object that is equivalent to the public key.
798 *
799 * For standard key types, the output format is as follows:
800 *
801 * - For RSA keys (#PSA_KEY_TYPE_RSA_KEYPAIR or #PSA_KEY_TYPE_RSA_PUBLIC_KEY),
802 * the format is the DER representation of the public key defined by RFC 5280
803 * as SubjectPublicKeyInfo.
804 *
805 * \param key Slot whose content is to be exported. This must
806 * be an occupied key slot.
807 * \param data Buffer where the key data is to be written.
808 * \param data_size Size of the \c data buffer in bytes.
809 * \param data_length On success, the number of bytes
810 * that make up the key data.
811 *
812 * \retval PSA_SUCCESS
813 * \retval PSA_ERROR_EMPTY_SLOT
814 * \retval PSA_ERROR_INVALID_ARGUMENT
815 * \retval PSA_ERROR_COMMUNICATION_FAILURE
816 * \retval PSA_ERROR_HARDWARE_FAILURE
817 * \retval PSA_ERROR_TAMPERING_DETECTED
818 */
819psa_status_t psa_export_public_key(psa_key_slot_t key,
820 uint8_t *data,
821 size_t data_size,
822 size_t *data_length);
823
824/**@}*/
825
826/** \defgroup policy Key policies
827 * @{
828 */
829
830/** \brief Encoding of permitted usage on a key. */
831typedef uint32_t psa_key_usage_t;
832
833/** Whether the key may be exported.
834 *
835 * A public key or the public part of a key pair may always be exported
836 * regardless of the value of this permission flag.
837 *
838 * If a key does not have export permission, implementations shall not
839 * allow the key to be exported in plain form from the cryptoprocessor,
840 * whether through psa_export_key() or through a proprietary interface.
841 * The key may however be exportable in a wrapped form, i.e. in a form
842 * where it is encrypted by another key.
843 */
844#define PSA_KEY_USAGE_EXPORT ((psa_key_usage_t)0x00000001)
845
846/** Whether the key may be used to encrypt a message.
847 *
848 * For a key pair, this concerns the public key.
849 */
850#define PSA_KEY_USAGE_ENCRYPT ((psa_key_usage_t)0x00000100)
851
852/** Whether the key may be used to decrypt a message.
853 *
854 * For a key pair, this concerns the private key.
855 */
856#define PSA_KEY_USAGE_DECRYPT ((psa_key_usage_t)0x00000200)
857
858/** Whether the key may be used to sign a message.
859 *
860 * For a key pair, this concerns the private key.
861 */
862#define PSA_KEY_USAGE_SIGN ((psa_key_usage_t)0x00000400)
863
864/** Whether the key may be used to verify a message signature.
865 *
866 * For a key pair, this concerns the public key.
867 */
868#define PSA_KEY_USAGE_VERIFY ((psa_key_usage_t)0x00000800)
869
Antonio de Angelis8908f472018-08-31 15:44:25 +0100870/** \brief The type of the key policy data structure.
Antonio de Angelis14276e92018-07-10 14:35:43 +0100871 *
Antonio de Angelis8908f472018-08-31 15:44:25 +0100872 * This is an implementation-defined type. Applications should not
873 * make any assumptions about this type except
874 * as directed by the documentation of a specific implementation.
875 */
876typedef uint32_t psa_key_policy_t;
Antonio de Angelis14276e92018-07-10 14:35:43 +0100877
878/** \brief Initialize a key policy structure to a default that forbids all
Antonio de Angelis8908f472018-08-31 15:44:25 +0100879 * usage of the key.
880 */
Antonio de Angelis14276e92018-07-10 14:35:43 +0100881void psa_key_policy_init(psa_key_policy_t *policy);
882
883/** \brief Set the standard fields of a policy structure.
884 *
885 * Note that this function does not make any consistency check of the
886 * parameters. The values are only checked when applying the policy to
887 * a key slot with psa_set_key_policy().
888 */
889void psa_key_policy_set_usage(psa_key_policy_t *policy,
890 psa_key_usage_t usage,
891 psa_algorithm_t alg);
892
893psa_key_usage_t psa_key_policy_get_usage(psa_key_policy_t *policy);
894
895psa_algorithm_t psa_key_policy_get_algorithm(psa_key_policy_t *policy);
896
897/** \brief Set the usage policy on a key slot.
898 *
899 * This function must be called on an empty key slot, before importing,
900 * generating or creating a key in the slot. Changing the policy of an
901 * existing key is not permitted.
902 *
903 * Implementations may set restrictions on supported key policies
904 * depending on the key type and the key slot.
905 */
906psa_status_t psa_set_key_policy(psa_key_slot_t key,
907 const psa_key_policy_t *policy);
908
Antonio de Angelis8908f472018-08-31 15:44:25 +0100909/** \brief Get the usage policy for a key slot. */
Antonio de Angelis14276e92018-07-10 14:35:43 +0100910psa_status_t psa_get_key_policy(psa_key_slot_t key,
911 psa_key_policy_t *policy);
912
913/**@}*/
914
915/** \defgroup persistence Key lifetime
916 * @{
917 */
918
Antonio de Angelis8908f472018-08-31 15:44:25 +0100919/** \brief Encoding of key lifetimes. */
Antonio de Angelis14276e92018-07-10 14:35:43 +0100920typedef uint32_t psa_key_lifetime_t;
921
922/** A volatile key slot retains its content as long as the application is
923 * running. It is guaranteed to be erased on a power reset.
924 */
925#define PSA_KEY_LIFETIME_VOLATILE ((psa_key_lifetime_t)0x00000000)
926
927/** A persistent key slot retains its content as long as it is not explicitly
928 * destroyed.
929 */
930#define PSA_KEY_LIFETIME_PERSISTENT ((psa_key_lifetime_t)0x00000001)
931
932/** A write-once key slot may not be modified once a key has been set.
933 * It will retain its content as long as the device remains operational.
934 */
935#define PSA_KEY_LIFETIME_WRITE_ONCE ((psa_key_lifetime_t)0x7fffffff)
936
937/** \brief Retrieve the lifetime of a key slot.
938 *
939 * The assignment of lifetimes to slots is implementation-dependent.
940 *
941 * \param key Slot to query.
942 * \param lifetime On success, the lifetime value.
943 *
944 * \retval PSA_SUCCESS
945 * Success.
946 * \retval PSA_ERROR_INVALID_ARGUMENT
947 * The key slot is invalid.
948 * \retval PSA_ERROR_COMMUNICATION_FAILURE
949 * \retval PSA_ERROR_HARDWARE_FAILURE
950 * \retval PSA_ERROR_TAMPERING_DETECTED
951 */
952psa_status_t psa_get_key_lifetime(psa_key_slot_t key,
953 psa_key_lifetime_t *lifetime);
954
955/** \brief Change the lifetime of a key slot.
956 *
957 * Whether the lifetime of a key slot can be changed at all, and if so
958 * whether the lifetime of an occupied key slot can be changed, is
959 * implementation-dependent.
960 *
961 * \param key Slot whose lifetime is to be changed.
962 * \param lifetime The lifetime value to set for the given key slot.
963 *
964 * \retval PSA_SUCCESS
965 * Success.
966 * \retval PSA_ERROR_INVALID_ARGUMENT
967 * The key slot is invalid,
968 * or the lifetime value is invalid.
969 * \retval PSA_ERROR_NOT_SUPPORTED
970 * The implementation does not support the specified lifetime value,
971 * at least for the specified key slot.
972 * \retval PSA_ERROR_OCCUPIED_SLOT
973 * The slot contains a key, and the implementation does not support
974 * changing the lifetime of an occupied slot.
975 * \retval PSA_ERROR_COMMUNICATION_FAILURE
976 * \retval PSA_ERROR_HARDWARE_FAILURE
977 * \retval PSA_ERROR_TAMPERING_DETECTED
978 */
979psa_status_t psa_set_key_lifetime(psa_key_slot_t key,
980 psa_key_lifetime_t lifetime);
981
982/**@}*/
983
984/** \defgroup hash Message digests
985 * @{
986 */
987
Antonio de Angelis8908f472018-08-31 15:44:25 +0100988/** \brief The type of the state data structure for multipart hash operations.
Antonio de Angelis14276e92018-07-10 14:35:43 +0100989 *
Antonio de Angelis8908f472018-08-31 15:44:25 +0100990 * This is an implementation-defined type. Applications should not
991 * make any assumptions about this type except
992 * as directed by the documentation of a specific implementation.
993 */
994typedef uint32_t psa_hash_operation_t;
Antonio de Angelis14276e92018-07-10 14:35:43 +0100995
996/** The size of the output of psa_hash_finish(), in bytes.
997 *
998 * This is also the hash size that psa_hash_verify() expects.
999 *
1000 * \param alg A hash algorithm (\c PSA_ALG_XXX value such that
1001 * #PSA_ALG_IS_HASH(alg) is true), or an HMAC algorithm
1002 * (`PSA_ALG_HMAC(hash_alg)` where `hash_alg` is a
1003 * hash algorithm).
1004 *
1005 * \return The hash size for the specified hash algorithm.
1006 * If the hash algorithm is not recognized, return 0.
1007 * An implementation may return either 0 or the correct size
1008 * for a hash algorithm that it recognizes, but does not support.
1009 */
1010#define PSA_HASH_SIZE(alg) \
1011 ( \
1012 PSA_ALG_RSA_GET_HASH(alg) == PSA_ALG_MD2 ? 16 : \
1013 PSA_ALG_RSA_GET_HASH(alg) == PSA_ALG_MD4 ? 16 : \
1014 PSA_ALG_RSA_GET_HASH(alg) == PSA_ALG_MD5 ? 16 : \
1015 PSA_ALG_RSA_GET_HASH(alg) == PSA_ALG_RIPEMD160 ? 20 : \
1016 PSA_ALG_RSA_GET_HASH(alg) == PSA_ALG_SHA_1 ? 20 : \
1017 PSA_ALG_RSA_GET_HASH(alg) == PSA_ALG_SHA_224 ? 28 : \
1018 PSA_ALG_RSA_GET_HASH(alg) == PSA_ALG_SHA_256 ? 32 : \
1019 PSA_ALG_RSA_GET_HASH(alg) == PSA_ALG_SHA_384 ? 48 : \
1020 PSA_ALG_RSA_GET_HASH(alg) == PSA_ALG_SHA_512 ? 64 : \
1021 PSA_ALG_RSA_GET_HASH(alg) == PSA_ALG_SHA_512_224 ? 28 : \
1022 PSA_ALG_RSA_GET_HASH(alg) == PSA_ALG_SHA_512_256 ? 32 : \
1023 PSA_ALG_RSA_GET_HASH(alg) == PSA_ALG_SHA3_224 ? 28 : \
1024 PSA_ALG_RSA_GET_HASH(alg) == PSA_ALG_SHA3_256 ? 32 : \
1025 PSA_ALG_RSA_GET_HASH(alg) == PSA_ALG_SHA3_384 ? 48 : \
1026 PSA_ALG_RSA_GET_HASH(alg) == PSA_ALG_SHA3_512 ? 64 : \
1027 0)
1028
1029/** Start a multipart hash operation.
1030 *
1031 * The sequence of operations to calculate a hash (message digest)
1032 * is as follows:
1033 * -# Allocate an operation object which will be passed to all the functions
1034 * listed here.
1035 * -# Call psa_hash_start() to specify the algorithm.
1036 * -# Call psa_hash_update() zero, one or more times, passing a fragment
1037 * of the message each time. The hash that is calculated is the hash
1038 * of the concatenation of these messages in order.
1039 * -# To calculate the hash, call psa_hash_finish().
1040 * To compare the hash with an expected value, call psa_hash_verify().
1041 *
1042 * The application may call psa_hash_abort() at any time after the operation
1043 * has been initialized with psa_hash_start().
1044 *
1045 * After a successful call to psa_hash_start(), the application must
1046 * eventually terminate the operation. The following events terminate an
1047 * operation:
1048 * - A failed call to psa_hash_update().
1049 * - A call to psa_hash_finish(), psa_hash_verify() or psa_hash_abort().
1050 *
1051 * \param operation The operation object to use.
1052 * \param alg The hash algorithm to compute (\c PSA_ALG_XXX value
1053 * such that #PSA_ALG_IS_HASH(alg) is true).
1054 *
1055 * \retval PSA_SUCCESS
1056 * Success.
1057 * \retval PSA_ERROR_NOT_SUPPORTED
1058 * \c alg is not supported or is not a hash algorithm.
1059 * \retval PSA_ERROR_INSUFFICIENT_MEMORY
1060 * \retval PSA_ERROR_COMMUNICATION_FAILURE
1061 * \retval PSA_ERROR_HARDWARE_FAILURE
1062 * \retval PSA_ERROR_TAMPERING_DETECTED
1063 */
1064psa_status_t psa_hash_start(psa_hash_operation_t *operation,
1065 psa_algorithm_t alg);
1066
1067/** Add a message fragment to a multipart hash operation.
1068 *
1069 * The application must call psa_hash_start() before calling this function.
1070 *
1071 * If this function returns an error status, the operation becomes inactive.
1072 *
1073 * \param operation Active hash operation.
1074 * \param input Buffer containing the message fragment to hash.
1075 * \param input_length Size of the \c input buffer in bytes.
1076 *
1077 * \retval PSA_SUCCESS
1078 * Success.
1079 * \retval PSA_ERROR_BAD_STATE
1080 * The operation state is not valid (not started, or already completed).
1081 * \retval PSA_ERROR_INSUFFICIENT_MEMORY
1082 * \retval PSA_ERROR_COMMUNICATION_FAILURE
1083 * \retval PSA_ERROR_HARDWARE_FAILURE
1084 * \retval PSA_ERROR_TAMPERING_DETECTED
1085 */
1086psa_status_t psa_hash_update(psa_hash_operation_t *operation,
1087 const uint8_t *input,
1088 size_t input_length);
1089
1090/** Finish the calculation of the hash of a message.
1091 *
1092 * The application must call psa_hash_start() before calling this function.
1093 * This function calculates the hash of the message formed by concatenating
1094 * the inputs passed to preceding calls to psa_hash_update().
1095 *
1096 * When this function returns, the operation becomes inactive.
1097 *
1098 * \warning Applications should not call this function if they expect
1099 * a specific value for the hash. Call psa_hash_verify() instead.
1100 * Beware that comparing integrity or authenticity data such as
1101 * hash values with a function such as \c memcmp is risky
1102 * because the time taken by the comparison may leak information
1103 * about the hashed data which could allow an attacker to guess
1104 * a valid hash and thereby bypass security controls.
1105 *
1106 * \param operation Active hash operation.
1107 * \param hash Buffer where the hash is to be written.
1108 * \param hash_size Size of the \c hash buffer in bytes.
1109 * \param hash_length On success, the number of bytes
1110 * that make up the hash value. This is always
1111 * #PSA_HASH_SIZE(alg) where \c alg is the
1112 * hash algorithm that is calculated.
1113 *
1114 * \retval PSA_SUCCESS
1115 * Success.
1116 * \retval PSA_ERROR_BAD_STATE
1117 * The operation state is not valid (not started, or already completed).
1118 * \retval PSA_ERROR_BUFFER_TOO_SMALL
1119 * The size of the \c hash buffer is too small. You can determine a
1120 * sufficient buffer size by calling #PSA_HASH_SIZE(alg)
1121 * where \c alg is the hash algorithm that is calculated.
1122 * \retval PSA_ERROR_INSUFFICIENT_MEMORY
1123 * \retval PSA_ERROR_COMMUNICATION_FAILURE
1124 * \retval PSA_ERROR_HARDWARE_FAILURE
1125 * \retval PSA_ERROR_TAMPERING_DETECTED
1126 */
1127psa_status_t psa_hash_finish(psa_hash_operation_t *operation,
1128 uint8_t *hash,
1129 size_t hash_size,
1130 size_t *hash_length);
1131
1132/** Finish the calculation of the hash of a message and compare it with
1133 * an expected value.
1134 *
1135 * The application must call psa_hash_start() before calling this function.
1136 * This function calculates the hash of the message formed by concatenating
1137 * the inputs passed to preceding calls to psa_hash_update(). It then
1138 * compares the calculated hash with the expected hash passed as a
1139 * parameter to this function.
1140 *
1141 * When this function returns, the operation becomes inactive.
1142 *
1143 * \note Implementations shall make the best effort to ensure that the
1144 * comparison between the actual hash and the expected hash is performed
1145 * in constant time.
1146 *
1147 * \param operation Active hash operation.
1148 * \param hash Buffer containing the expected hash value.
1149 * \param hash_length Size of the \c hash buffer in bytes.
1150 *
1151 * \retval PSA_SUCCESS
1152 * The expected hash is identical to the actual hash of the message.
1153 * \retval PSA_ERROR_INVALID_SIGNATURE
1154 * The hash of the message was calculated successfully, but it
1155 * differs from the expected hash.
1156 * \retval PSA_ERROR_BAD_STATE
1157 * The operation state is not valid (not started, or already completed).
1158 * \retval PSA_ERROR_INSUFFICIENT_MEMORY
1159 * \retval PSA_ERROR_COMMUNICATION_FAILURE
1160 * \retval PSA_ERROR_HARDWARE_FAILURE
1161 * \retval PSA_ERROR_TAMPERING_DETECTED
1162 */
1163psa_status_t psa_hash_verify(psa_hash_operation_t *operation,
1164 const uint8_t *hash,
1165 size_t hash_length);
1166
1167/** Abort a hash operation.
1168 *
1169 * This function may be called at any time after psa_hash_start().
1170 * Aborting an operation frees all associated resources except for the
1171 * \c operation structure itself.
1172 *
1173 * Implementation should strive to be robust and handle inactive hash
1174 * operations safely (do nothing and return #PSA_ERROR_BAD_STATE). However,
1175 * application writers should beware that uninitialized memory may happen
1176 * to be indistinguishable from an active hash operation, and the behavior
1177 * of psa_hash_abort() is undefined in this case.
1178 *
1179 * \param operation Active hash operation.
1180 *
1181 * \retval PSA_SUCCESS
1182 * \retval PSA_ERROR_BAD_STATE
1183 * \c operation is not an active hash operation.
1184 * \retval PSA_ERROR_COMMUNICATION_FAILURE
1185 * \retval PSA_ERROR_HARDWARE_FAILURE
1186 * \retval PSA_ERROR_TAMPERING_DETECTED
1187 */
1188psa_status_t psa_hash_abort(psa_hash_operation_t *operation);
1189
1190/**@}*/
1191
1192/** \defgroup MAC Message authentication codes
1193 * @{
1194 */
1195
Antonio de Angelis8908f472018-08-31 15:44:25 +01001196/** \brief The type of the state data structure for multipart MAC operations.
Antonio de Angelis14276e92018-07-10 14:35:43 +01001197 *
Antonio de Angelis8908f472018-08-31 15:44:25 +01001198 * This is an implementation-defined type. Applications should not
1199 * make any assumptions about this type except
1200 * as directed by the documentation of a specific implementation.
1201 */
1202typedef uint32_t psa_mac_operation_t;
Antonio de Angelis14276e92018-07-10 14:35:43 +01001203
1204/** The size of the output of psa_mac_finish(), in bytes.
1205 *
1206 * This is also the MAC size that psa_mac_verify() expects.
1207 *
1208 * \param alg A MAC algorithm (\c PSA_ALG_XXX value such that
1209 * #PSA_ALG_IS_MAC(alg) is true).
1210 *
1211 * \return The MAC size for the specified algorithm.
1212 * If the MAC algorithm is not recognized, return 0.
1213 * An implementation may return either 0 or the correct size
1214 * for a MAC algorithm that it recognizes, but does not support.
1215 */
1216#define PSA_MAC_FINAL_SIZE(key_type, key_bits, alg) \
1217 (PSA_ALG_IS_HMAC(alg) ? PSA_HASH_SIZE(PSA_ALG_HMAC_HASH(alg)) : \
1218 PSA_ALG_IS_BLOCK_CIPHER_MAC(alg) ? PSA_BLOCK_CIPHER_BLOCK_SIZE(key_type) : \
1219 0)
1220
1221/** Start a multipart MAC operation.
1222 *
1223 * The sequence of operations to calculate a MAC (message authentication code)
1224 * is as follows:
1225 * -# Allocate an operation object which will be passed to all the functions
1226 * listed here.
1227 * -# Call psa_mac_start() to specify the algorithm and key.
1228 * The key remains associated with the operation even if the content
1229 * of the key slot changes.
1230 * -# Call psa_mac_update() zero, one or more times, passing a fragment
1231 * of the message each time. The MAC that is calculated is the MAC
1232 * of the concatenation of these messages in order.
1233 * -# To calculate the MAC, call psa_mac_finish().
1234 * To compare the MAC with an expected value, call psa_mac_verify().
1235 *
1236 * The application may call psa_mac_abort() at any time after the operation
1237 * has been initialized with psa_mac_start().
1238 *
1239 * After a successful call to psa_mac_start(), the application must
1240 * eventually terminate the operation. The following events terminate an
1241 * operation:
1242 * - A failed call to psa_mac_update().
1243 * - A call to psa_mac_finish(), psa_mac_verify() or psa_mac_abort().
1244 *
1245 * \param operation The operation object to use.
1246 * \param alg The MAC algorithm to compute (\c PSA_ALG_XXX value
1247 * such that #PSA_ALG_IS_MAC(alg) is true).
1248 *
1249 * \retval PSA_SUCCESS
1250 * Success.
1251 * \retval PSA_ERROR_EMPTY_SLOT
1252 * \retval PSA_ERROR_NOT_PERMITTED
1253 * \retval PSA_ERROR_INVALID_ARGUMENT
1254 * \c key is not compatible with \c alg.
1255 * \retval PSA_ERROR_NOT_SUPPORTED
1256 * \c alg is not supported or is not a MAC algorithm.
1257 * \retval PSA_ERROR_INSUFFICIENT_MEMORY
1258 * \retval PSA_ERROR_COMMUNICATION_FAILURE
1259 * \retval PSA_ERROR_HARDWARE_FAILURE
1260 * \retval PSA_ERROR_TAMPERING_DETECTED
1261 */
1262psa_status_t psa_mac_start(psa_mac_operation_t *operation,
1263 psa_key_slot_t key,
1264 psa_algorithm_t alg);
1265
1266psa_status_t psa_mac_update(psa_mac_operation_t *operation,
1267 const uint8_t *input,
1268 size_t input_length);
1269
1270psa_status_t psa_mac_finish(psa_mac_operation_t *operation,
1271 uint8_t *mac,
1272 size_t mac_size,
1273 size_t *mac_length);
1274
1275psa_status_t psa_mac_verify(psa_mac_operation_t *operation,
1276 const uint8_t *mac,
1277 size_t mac_length);
1278
1279psa_status_t psa_mac_abort(psa_mac_operation_t *operation);
1280
1281/**@}*/
1282
1283/** \defgroup cipher Symmetric ciphers
1284 * @{
1285 */
1286
Antonio de Angelis8908f472018-08-31 15:44:25 +01001287/** \brief The type of the state data structure for multipart cipher operations.
Antonio de Angelis14276e92018-07-10 14:35:43 +01001288 *
Antonio de Angelis8908f472018-08-31 15:44:25 +01001289 * This is an implementation-defined type. Applications should not
1290 * make any assumptions about this type except
1291 * as directed by the documentation of a specific implementation.
1292 */
1293typedef uint32_t psa_cipher_operation_t;
Antonio de Angelis14276e92018-07-10 14:35:43 +01001294
1295/** Set the key for a multipart symmetric encryption operation.
1296 *
1297 * The sequence of operations to encrypt a message with a symmetric cipher
1298 * is as follows:
1299 * -# Allocate an operation object which will be passed to all the functions
1300 * listed here.
1301 * -# Call psa_encrypt_setup() to specify the algorithm and key.
1302 * The key remains associated with the operation even if the content
1303 * of the key slot changes.
1304 * -# Call either psa_encrypt_generate_iv() or psa_encrypt_set_iv() to
1305 * generate or set the IV (initialization vector). You should use
1306 * psa_encrypt_generate_iv() unless the protocol you are implementing
1307 * requires a specific IV value.
1308 * -# Call psa_cipher_update() zero, one or more times, passing a fragment
1309 * of the message each time.
1310 * -# Call psa_cipher_finish().
1311 *
1312 * The application may call psa_cipher_abort() at any time after the operation
1313 * has been initialized with psa_encrypt_setup().
1314 *
1315 * After a successful call to psa_encrypt_setup(), the application must
1316 * eventually terminate the operation. The following events terminate an
1317 * operation:
1318 * - A failed call to psa_encrypt_generate_iv(), psa_encrypt_set_iv()
1319 * or psa_cipher_update().
1320 * - A call to psa_cipher_finish() or psa_cipher_abort().
1321 *
1322 * \param operation The operation object to use.
1323 * \param alg The cipher algorithm to compute (\c PSA_ALG_XXX value
1324 * such that #PSA_ALG_IS_CIPHER(alg) is true).
1325 *
1326 * \retval PSA_SUCCESS
1327 * Success.
1328 * \retval PSA_ERROR_EMPTY_SLOT
1329 * \retval PSA_ERROR_NOT_PERMITTED
1330 * \retval PSA_ERROR_INVALID_ARGUMENT
1331 * \c key is not compatible with \c alg.
1332 * \retval PSA_ERROR_NOT_SUPPORTED
1333 * \c alg is not supported or is not a cipher algorithm.
1334 * \retval PSA_ERROR_INSUFFICIENT_MEMORY
1335 * \retval PSA_ERROR_COMMUNICATION_FAILURE
1336 * \retval PSA_ERROR_HARDWARE_FAILURE
1337 * \retval PSA_ERROR_TAMPERING_DETECTED
1338 */
1339psa_status_t psa_encrypt_setup(psa_cipher_operation_t *operation,
1340 psa_key_slot_t key,
1341 psa_algorithm_t alg);
1342
1343/** Set the key for a multipart symmetric decryption operation.
1344 *
1345 * The sequence of operations to decrypt a message with a symmetric cipher
1346 * is as follows:
1347 * -# Allocate an operation object which will be passed to all the functions
1348 * listed here.
1349 * -# Call psa_decrypt_setup() to specify the algorithm and key.
1350 * The key remains associated with the operation even if the content
1351 * of the key slot changes.
1352 * -# Call psa_cipher_update() with the IV (initialization vector) for the
1353 * decryption. If the IV is prepended to the ciphertext, you can call
1354 * psa_cipher_update() on a buffer containing the IV followed by the
1355 * beginning of the message.
1356 * -# Call psa_cipher_update() zero, one or more times, passing a fragment
1357 * of the message each time.
1358 * -# Call psa_cipher_finish().
1359 *
1360 * The application may call psa_cipher_abort() at any time after the operation
1361 * has been initialized with psa_encrypt_setup().
1362 *
1363 * After a successful call to psa_decrypt_setup(), the application must
1364 * eventually terminate the operation. The following events terminate an
1365 * operation:
1366 * - A failed call to psa_cipher_update().
1367 * - A call to psa_cipher_finish() or psa_cipher_abort().
1368 *
1369 * \param operation The operation object to use.
1370 * \param alg The cipher algorithm to compute (\c PSA_ALG_XXX value
1371 * such that #PSA_ALG_IS_CIPHER(alg) is true).
1372 *
1373 * \retval PSA_SUCCESS
1374 * Success.
1375 * \retval PSA_ERROR_EMPTY_SLOT
1376 * \retval PSA_ERROR_NOT_PERMITTED
1377 * \retval PSA_ERROR_INVALID_ARGUMENT
1378 * \c key is not compatible with \c alg.
1379 * \retval PSA_ERROR_NOT_SUPPORTED
1380 * \c alg is not supported or is not a cipher algorithm.
1381 * \retval PSA_ERROR_INSUFFICIENT_MEMORY
1382 * \retval PSA_ERROR_COMMUNICATION_FAILURE
1383 * \retval PSA_ERROR_HARDWARE_FAILURE
1384 * \retval PSA_ERROR_TAMPERING_DETECTED
1385 */
1386psa_status_t psa_decrypt_setup(psa_cipher_operation_t *operation,
1387 psa_key_slot_t key,
1388 psa_algorithm_t alg);
1389
1390psa_status_t psa_encrypt_generate_iv(psa_cipher_operation_t *operation,
1391 unsigned char *iv,
1392 size_t iv_size,
1393 size_t *iv_length);
1394
1395psa_status_t psa_encrypt_set_iv(psa_cipher_operation_t *operation,
1396 const unsigned char *iv,
1397 size_t iv_length);
1398
1399psa_status_t psa_cipher_update(psa_cipher_operation_t *operation,
1400 const uint8_t *input,
1401 size_t input_length,
1402 unsigned char *output,
1403 size_t output_size,
1404 size_t *output_length);
1405
1406psa_status_t psa_cipher_finish(psa_cipher_operation_t *operation,
1407 uint8_t *output,
1408 size_t output_size,
1409 size_t *output_length);
1410
1411psa_status_t psa_cipher_abort(psa_cipher_operation_t *operation);
1412
1413/**@}*/
1414
1415/** \defgroup aead Authenticated encryption with associated data (AEAD)
1416 * @{
1417 */
1418
1419/** The tag size for an AEAD algorithm, in bytes.
1420 *
1421 * \param alg An AEAD algorithm
1422 * (\c PSA_ALG_XXX value such that
1423 * #PSA_ALG_IS_AEAD(alg) is true).
1424 *
1425 * \return The tag size for the specified algorithm.
1426 * If the AEAD algorithm does not have an identified
1427 * tag that can be distinguished from the rest of
1428 * the ciphertext, return 0.
1429 * If the AEAD algorithm is not recognized, return 0.
1430 * An implementation may return either 0 or a
1431 * correct size for an AEAD algorithm that it
1432 * recognizes, but does not support.
1433 */
1434#define PSA_AEAD_TAG_SIZE(alg) \
1435 ((alg) == PSA_ALG_GCM ? 16 : \
1436 (alg) == PSA_ALG_CCM ? 16 : \
1437 0)
1438
1439/** The maximum size of the output of psa_aead_encrypt(), in bytes.
1440 *
1441 * If the size of the ciphertext buffer is at least this large, it is
1442 * guaranteed that psa_aead_encrypt() will not fail due to an
1443 * insufficient buffer size. Depending on the algorithm, the actual size of
1444 * the ciphertext may be smaller.
1445 *
1446 * \param alg An AEAD algorithm
1447 * (\c PSA_ALG_XXX value such that
1448 * #PSA_ALG_IS_AEAD(alg) is true).
1449 * \param plaintext_length Size of the plaintext in bytes.
1450 *
1451 * \return The AEAD ciphertext size for the specified
1452 * algorithm.
1453 * If the AEAD algorithm is not recognized, return 0.
1454 * An implementation may return either 0 or a
1455 * correct size for an AEAD algorithm that it
1456 * recognizes, but does not support.
1457 */
1458#define PSA_AEAD_ENCRYPT_OUTPUT_SIZE(alg, plaintext_length) \
1459 (PSA_AEAD_TAG_SIZE(alg) != 0 ? \
1460 (plaintext_length) + PSA_AEAD_TAG_SIZE(alg) : \
1461 0)
1462
1463/** Process an authenticated encryption operation.
1464 *
1465 * \param key Slot containing the key to use.
1466 * \param alg The AEAD algorithm to compute
1467 * (\c PSA_ALG_XXX value such that
1468 * #PSA_ALG_IS_AEAD(alg) is true).
1469 * \param nonce Nonce or IV to use.
1470 * \param nonce_length Size of the \p nonce buffer in bytes.
1471 * \param additional_data Additional data that will be authenticated
1472 * but not encrypted.
1473 * \param additional_data_length Size of \p additional_data in bytes.
1474 * \param plaintext Data that will be authenticated and
1475 * encrypted.
1476 * \param plaintext_length Size of \p plaintext in bytes.
1477 * \param ciphertext Output buffer for the authenticated and
1478 * encrypted data. The additional data is not
1479 * part of this output. For algorithms where the
1480 * encrypted data and the authentication tag
1481 * are defined as separate outputs, the
1482 * authentication tag is appended to the
1483 * encrypted data.
1484 * \param ciphertext_size Size of the \p ciphertext buffer in bytes.
1485 * This must be at least
1486 * #PSA_AEAD_ENCRYPT_OUTPUT_SIZE(\p alg,
1487 * \p plaintext_length).
1488 * \param ciphertext_length On success, the size of the output
1489 * in the \b ciphertext buffer.
1490 *
1491 * \retval PSA_SUCCESS
1492 * Success.
1493 * \retval PSA_ERROR_EMPTY_SLOT
1494 * \retval PSA_ERROR_NOT_PERMITTED
1495 * \retval PSA_ERROR_INVALID_ARGUMENT
1496 * \c key is not compatible with \c alg.
1497 * \retval PSA_ERROR_NOT_SUPPORTED
1498 * \c alg is not supported or is not an AEAD algorithm.
1499 * \retval PSA_ERROR_INSUFFICIENT_MEMORY
1500 * \retval PSA_ERROR_COMMUNICATION_FAILURE
1501 * \retval PSA_ERROR_HARDWARE_FAILURE
1502 * \retval PSA_ERROR_TAMPERING_DETECTED
1503 */
1504psa_status_t psa_aead_encrypt( psa_key_slot_t key,
1505 psa_algorithm_t alg,
1506 const uint8_t *nonce,
1507 size_t nonce_length,
1508 const uint8_t *additional_data,
1509 size_t additional_data_length,
1510 const uint8_t *plaintext,
1511 size_t plaintext_length,
1512 uint8_t *ciphertext,
1513 size_t ciphertext_size,
1514 size_t *ciphertext_length );
1515
1516/** The maximum size of the output of psa_aead_decrypt(), in bytes.
1517 *
1518 * If the size of the plaintext buffer is at least this large, it is
1519 * guaranteed that psa_aead_decrypt() will not fail due to an
1520 * insufficient buffer size. Depending on the algorithm, the actual size of
1521 * the plaintext may be smaller.
1522 *
1523 * \param alg An AEAD algorithm
1524 * (\c PSA_ALG_XXX value such that
1525 * #PSA_ALG_IS_AEAD(alg) is true).
1526 * \param ciphertext_length Size of the plaintext in bytes.
1527 *
1528 * \return The AEAD ciphertext size for the specified
1529 * algorithm.
1530 * If the AEAD algorithm is not recognized, return 0.
1531 * An implementation may return either 0 or a
1532 * correct size for an AEAD algorithm that it
1533 * recognizes, but does not support.
1534 */
1535#define PSA_AEAD_DECRYPT_OUTPUT_SIZE(alg, ciphertext_length) \
1536 (PSA_AEAD_TAG_SIZE(alg) != 0 ? \
1537 (plaintext_length) - PSA_AEAD_TAG_SIZE(alg) : \
1538 0)
1539
1540/** Process an authenticated decryption operation.
1541 *
1542 * \param key Slot containing the key to use.
1543 * \param alg The AEAD algorithm to compute
1544 * (\c PSA_ALG_XXX value such that
1545 * #PSA_ALG_IS_AEAD(alg) is true).
1546 * \param nonce Nonce or IV to use.
1547 * \param nonce_length Size of the \p nonce buffer in bytes.
1548 * \param additional_data Additional data that has been authenticated
1549 * but not encrypted.
1550 * \param additional_data_length Size of \p additional_data in bytes.
1551 * \param ciphertext Data that has been authenticated and
1552 * encrypted. For algorithms where the
1553 * encrypted data and the authentication tag
1554 * are defined as separate inputs, the buffer
1555 * must contain the encrypted data followed
1556 * by the authentication tag.
1557 * \param ciphertext_length Size of \p ciphertext in bytes.
1558 * \param plaintext Output buffer for the decrypted data.
1559 * \param plaintext_size Size of the \p plaintext buffer in bytes.
1560 * This must be at least
1561 * #PSA_AEAD_DECRYPT_OUTPUT_SIZE(\p alg,
1562 * \p ciphertext_length).
1563 * \param plaintext_length On success, the size of the output
1564 * in the \b plaintext buffer.
1565 *
1566 * \retval PSA_SUCCESS
1567 * Success.
1568 * \retval PSA_ERROR_EMPTY_SLOT
1569 * \retval PSA_ERROR_INVALID_SIGNATURE
1570 * The ciphertext is not authentic.
1571 * \retval PSA_ERROR_NOT_PERMITTED
1572 * \retval PSA_ERROR_INVALID_ARGUMENT
1573 * \c key is not compatible with \c alg.
1574 * \retval PSA_ERROR_NOT_SUPPORTED
1575 * \c alg is not supported or is not an AEAD algorithm.
1576 * \retval PSA_ERROR_INSUFFICIENT_MEMORY
1577 * \retval PSA_ERROR_COMMUNICATION_FAILURE
1578 * \retval PSA_ERROR_HARDWARE_FAILURE
1579 * \retval PSA_ERROR_TAMPERING_DETECTED
1580 */
1581psa_status_t psa_aead_decrypt( psa_key_slot_t key,
1582 psa_algorithm_t alg,
1583 const uint8_t *nonce,
1584 size_t nonce_length,
1585 const uint8_t *additional_data,
1586 size_t additional_data_length,
1587 const uint8_t *ciphertext,
1588 size_t ciphertext_length,
1589 uint8_t *plaintext,
1590 size_t plaintext_size,
1591 size_t *plaintext_length );
1592
1593/**@}*/
1594
1595/** \defgroup asymmetric Asymmetric cryptography
1596 * @{
1597 */
1598
1599/**
1600 * \brief Maximum ECDSA signature size for a given curve bit size
1601 *
1602 * \param curve_bits Curve size in bits
1603 * \return Maximum signature size in bytes
1604 *
1605 * \note This macro returns a compile-time constant if its argument is one.
1606 *
1607 * \warning This macro may evaluate its argument multiple times.
1608 */
1609/*
1610 * RFC 4492 page 20:
1611 *
1612 * Ecdsa-Sig-Value ::= SEQUENCE {
1613 * r INTEGER,
1614 * s INTEGER
1615 * }
1616 *
1617 * Size is at most
1618 * 1 (tag) + 1 (len) + 1 (initial 0) + curve_bytes for each of r and s,
1619 * twice that + 1 (tag) + 2 (len) for the sequence
1620 * (assuming curve_bytes is less than 126 for r and s,
1621 * and less than 124 (total len <= 255) for the sequence)
1622 */
1623#define PSA_ECDSA_SIGNATURE_SIZE(curve_bits) \
1624 ( /*T,L of SEQUENCE*/ ((curve_bits) >= 61 * 8 ? 3 : 2) + \
1625 /*T,L of r,s*/ 2 * (((curve_bits) >= 127 * 8 ? 3 : 2) + \
1626 /*V of r,s*/ ((curve_bits) + 8) / 8))
1627
1628
1629/** Safe signature buffer size for psa_asymmetric_sign().
1630 *
1631 * This macro returns a safe buffer size for a signature using a key
1632 * of the specified type and size, with the specified algorithm.
1633 * Note that the actual size of the signature may be smaller
1634 * (some algorithms produce a variable-size signature).
1635 *
1636 * \warning This function may call its arguments multiple times or
1637 * zero times, so you should not pass arguments that contain
1638 * side effects.
1639 *
1640 * \param key_type An asymmetric key type (this may indifferently be a
1641 * key pair type or a public key type).
1642 * \param key_bits The size of the key in bits.
1643 * \param alg The signature algorithm.
1644 *
1645 * \return If the parameters are valid and supported, return
1646 * a buffer size in bytes that guarantees that
1647 * psa_asymmetric_sign() will not fail with
1648 * #PSA_ERROR_BUFFER_TOO_SMALL.
1649 * If the parameters are a valid combination that is not supported
1650 * by the implementation, this macro either shall return either a
1651 * sensible size or 0.
1652 * If the parameters are not valid, the
1653 * return value is unspecified.
1654 *
1655 */
1656#define PSA_ASYMMETRIC_SIGN_OUTPUT_SIZE(key_type, key_bits, alg) \
1657 (PSA_KEY_TYPE_IS_RSA(key_type) ? ((void)alg, PSA_BITS_TO_BYTES(key_bits)) : \
1658 PSA_KEY_TYPE_IS_ECC(key_type) ? PSA_ECDSA_SIGNATURE_SIZE(key_bits) : \
1659 ((void)alg, 0))
1660
1661/**
1662 * \brief Sign a hash or short message with a private key.
1663 *
1664 * \param key Key slot containing an asymmetric key pair.
1665 * \param alg A signature algorithm that is compatible with
1666 * the type of \c key.
1667 * \param hash The message to sign.
1668 * \param hash_length Size of the \c hash buffer in bytes.
1669 * \param salt A salt or label, if supported by the signature
1670 * algorithm.
1671 * If the signature algorithm does not support a
1672 * salt, pass \c NULL.
1673 * If the signature algorithm supports an optional
1674 * salt and you do not want to pass a salt,
1675 * pass \c NULL.
1676 * \param salt_length Size of the \c salt buffer in bytes.
1677 * If \c salt is \c NULL, pass 0.
1678 * \param signature Buffer where the signature is to be written.
1679 * \param signature_size Size of the \c signature buffer in bytes.
1680 * \param signature_length On success, the number of bytes
1681 * that make up the returned signature value.
1682 *
1683 * \retval PSA_SUCCESS
1684 * \retval PSA_ERROR_BUFFER_TOO_SMALL
1685 * The size of the \c signature buffer is too small. You can
1686 * determine a sufficient buffer size by calling
1687 * #PSA_ASYMMETRIC_SIGN_OUTPUT_SIZE(key_type, key_bits, alg)
1688 * where \c key_type and \c key_bits are the type and bit-size
1689 * respectively of \c key.
1690 * \retval PSA_ERROR_NOT_SUPPORTED
1691 * \retval PSA_ERROR_INVALID_ARGUMENT
1692 * \retval PSA_ERROR_INSUFFICIENT_MEMORY
1693 * \retval PSA_ERROR_COMMUNICATION_FAILURE
1694 * \retval PSA_ERROR_HARDWARE_FAILURE
1695 * \retval PSA_ERROR_TAMPERING_DETECTED
1696 * \retval PSA_ERROR_INSUFFICIENT_ENTROPY
1697 */
1698psa_status_t psa_asymmetric_sign(psa_key_slot_t key,
1699 psa_algorithm_t alg,
1700 const uint8_t *hash,
1701 size_t hash_length,
1702 const uint8_t *salt,
1703 size_t salt_length,
1704 uint8_t *signature,
1705 size_t signature_size,
1706 size_t *signature_length);
1707
1708/**
1709 * \brief Verify the signature a hash or short message using a public key.
1710 *
1711 * \param key Key slot containing a public key or an
1712 * asymmetric key pair.
1713 * \param alg A signature algorithm that is compatible with
1714 * the type of \c key.
1715 * \param hash The message whose signature is to be verified.
1716 * \param hash_length Size of the \c hash buffer in bytes.
1717 * \param salt A salt or label, if supported by the signature
1718 * algorithm.
1719 * If the signature algorithm does not support a
1720 * salt, pass \c NULL.
1721 * If the signature algorithm supports an optional
1722 * salt and you do not want to pass a salt,
1723 * pass \c NULL.
1724 * \param salt_length Size of the \c salt buffer in bytes.
1725 * If \c salt is \c NULL, pass 0.
1726 * \param signature Buffer containing the signature to verify.
1727 * \param signature_size Size of the \c signature buffer in bytes.
1728 *
1729 * \retval PSA_SUCCESS
1730 * The signature is valid.
1731 * \retval PSA_ERROR_INVALID_SIGNATURE
1732 * The calculation was perfomed successfully, but the passed
1733 * signature is not a valid signature.
1734 * \retval PSA_ERROR_NOT_SUPPORTED
1735 * \retval PSA_ERROR_INVALID_ARGUMENT
1736 * \retval PSA_ERROR_INSUFFICIENT_MEMORY
1737 * \retval PSA_ERROR_COMMUNICATION_FAILURE
1738 * \retval PSA_ERROR_HARDWARE_FAILURE
1739 * \retval PSA_ERROR_TAMPERING_DETECTED
1740 */
1741psa_status_t psa_asymmetric_verify(psa_key_slot_t key,
1742 psa_algorithm_t alg,
1743 const uint8_t *hash,
1744 size_t hash_length,
1745 const uint8_t *salt,
1746 size_t salt_length,
1747 uint8_t *signature,
1748 size_t signature_size);
1749
1750#define PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(key_type, key_bits, alg) \
1751 (PSA_KEY_TYPE_IS_RSA(key_type) ? \
1752 ((void)alg, PSA_BITS_TO_BYTES(key_bits)) : \
1753 0)
1754#define PSA_RSA_MINIMUM_PADDING_SIZE(alg) \
1755 (PSA_ALG_IS_RSA_OAEP_MGF1(alg) ? \
1756 2 * PSA_HASH_FINAL_SIZE(PSA_ALG_RSA_GET_HASH(alg)) + 1 : \
1757 11 /*PKCS#1v1.5*/)
1758#define PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE(key_type, key_bits, alg) \
1759 (PSA_KEY_TYPE_IS_RSA(key_type) ? \
1760 PSA_BITS_TO_BYTES(key_bits) - PSA_RSA_MINIMUM_PADDING_SIZE(alg) : \
1761 0)
1762
1763/**
1764 * \brief Encrypt a short message with a public key.
1765 *
1766 * \param key Key slot containing a public key or an asymmetric
1767 * key pair.
1768 * \param alg An asymmetric encryption algorithm that is
1769 * compatible with the type of \c key.
1770 * \param input The message to encrypt.
1771 * \param input_length Size of the \c input buffer in bytes.
1772 * \param salt A salt or label, if supported by the encryption
1773 * algorithm.
1774 * If the algorithm does not support a
1775 * salt, pass \c NULL.
1776 * If the algorithm supports an optional
1777 * salt and you do not want to pass a salt,
1778 * pass \c NULL.
1779 *
1780 * - For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is
1781 * supported.
1782 * \param salt_length Size of the \c salt buffer in bytes.
1783 * If \c salt is \c NULL, pass 0.
1784 * \param output Buffer where the encrypted message is to be written.
1785 * \param output_size Size of the \c output buffer in bytes.
1786 * \param output_length On success, the number of bytes
1787 * that make up the returned output.
1788 *
1789 * \retval PSA_SUCCESS
1790 * \retval PSA_ERROR_BUFFER_TOO_SMALL
1791 * The size of the \c output buffer is too small. You can
1792 * determine a sufficient buffer size by calling
1793 * #PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(key_type, key_bits, alg)
1794 * where \c key_type and \c key_bits are the type and bit-size
1795 * respectively of \c key.
1796 * \retval PSA_ERROR_NOT_SUPPORTED
1797 * \retval PSA_ERROR_INVALID_ARGUMENT
1798 * \retval PSA_ERROR_INSUFFICIENT_MEMORY
1799 * \retval PSA_ERROR_COMMUNICATION_FAILURE
1800 * \retval PSA_ERROR_HARDWARE_FAILURE
1801 * \retval PSA_ERROR_TAMPERING_DETECTED
1802 * \retval PSA_ERROR_INSUFFICIENT_ENTROPY
1803 */
1804psa_status_t psa_asymmetric_encrypt(psa_key_slot_t key,
1805 psa_algorithm_t alg,
1806 const uint8_t *input,
1807 size_t input_length,
1808 const uint8_t *salt,
1809 size_t salt_length,
1810 uint8_t *output,
1811 size_t output_size,
1812 size_t *output_length);
1813
1814/**
1815 * \brief Decrypt a short message with a private key.
1816 *
1817 * \param key Key slot containing an asymmetric key pair.
1818 * \param alg An asymmetric encryption algorithm that is
1819 * compatible with the type of \c key.
1820 * \param input The message to decrypt.
1821 * \param input_length Size of the \c input buffer in bytes.
1822 * \param salt A salt or label, if supported by the encryption
1823 * algorithm.
1824 * If the algorithm does not support a
1825 * salt, pass \c NULL.
1826 * If the algorithm supports an optional
1827 * salt and you do not want to pass a salt,
1828 * pass \c NULL.
1829 *
1830 * - For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is
1831 * supported.
1832 * \param salt_length Size of the \c salt buffer in bytes.
1833 * If \c salt is \c NULL, pass 0.
1834 * \param output Buffer where the decrypted message is to be written.
1835 * \param output_size Size of the \c output buffer in bytes.
1836 * \param output_length On success, the number of bytes
1837 * that make up the returned output.
1838 *
1839 * \retval PSA_SUCCESS
1840 * \retval PSA_ERROR_BUFFER_TOO_SMALL
1841 * The size of the \c output buffer is too small. You can
1842 * determine a sufficient buffer size by calling
1843 * #PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE(key_type, key_bits, alg)
1844 * where \c key_type and \c key_bits are the type and bit-size
1845 * respectively of \c key.
1846 * \retval PSA_ERROR_NOT_SUPPORTED
1847 * \retval PSA_ERROR_INVALID_ARGUMENT
1848 * \retval PSA_ERROR_INSUFFICIENT_MEMORY
1849 * \retval PSA_ERROR_COMMUNICATION_FAILURE
1850 * \retval PSA_ERROR_HARDWARE_FAILURE
1851 * \retval PSA_ERROR_TAMPERING_DETECTED
1852 * \retval PSA_ERROR_INSUFFICIENT_ENTROPY
1853 * \retval PSA_ERROR_INVALID_PADDING
1854 */
1855psa_status_t psa_asymmetric_decrypt(psa_key_slot_t key,
1856 psa_algorithm_t alg,
1857 const uint8_t *input,
1858 size_t input_length,
1859 const uint8_t *salt,
1860 size_t salt_length,
1861 uint8_t *output,
1862 size_t output_size,
1863 size_t *output_length);
1864
1865/**@}*/
1866
1867/** \defgroup generation Key generation
1868 * @{
1869 */
1870
1871/**
1872 * \brief Generate random bytes.
1873 *
1874 * \warning This function **can** fail! Callers MUST check the return status
1875 * and MUST NOT use the content of the output buffer if the return
1876 * status is not #PSA_SUCCESS.
1877 *
1878 * \note To generate a key, use psa_generate_key() instead.
1879 *
1880 * \param output Output buffer for the generated data.
1881 * \param output_size Number of bytes to generate and output.
1882 *
1883 * \retval PSA_SUCCESS
1884 * \retval PSA_ERROR_NOT_SUPPORTED
1885 * \retval PSA_ERROR_INSUFFICIENT_ENTROPY
1886 * \retval PSA_ERROR_COMMUNICATION_FAILURE
1887 * \retval PSA_ERROR_HARDWARE_FAILURE
1888 * \retval PSA_ERROR_TAMPERING_DETECTED
1889 */
1890psa_status_t psa_generate_random(uint8_t *output,
1891 size_t output_size);
1892
1893/**
1894 * \brief Generate a key or key pair.
1895 *
1896 * \param key Slot where the key will be stored. This must be a
1897 * valid slot for a key of the chosen type. It must
1898 * be unoccupied.
1899 * \param type Key type (a \c PSA_KEY_TYPE_XXX value).
1900 * \param bits Key size in bits.
1901 * \param parameters Extra parameters for key generation. The
1902 * interpretation of this parameter depends on
1903 * \c type. All types support \c NULL to use
1904 * the default parameters specified below.
1905 * \param parameters_size Size of the buffer that \p parameters
1906 * points to, in bytes.
1907 *
1908 * For any symmetric key type (type such that
1909 * `PSA_KEY_TYPE_IS_ASYMMETRIC(type)` is false), \c parameters must be
1910 * \c NULL. For asymmetric key types defined by this specification,
1911 * the parameter type and the default parameters are defined by the
1912 * table below. For vendor-defined key types, the vendor documentation
1913 * shall define the parameter type and the default parameters.
1914 *
1915 * Type | Parameter type | Meaning | Parameters used if `parameters == NULL`
1916 * ---- | -------------- | ------- | ---------------------------------------
1917 * `PSA_KEY_TYPE_RSA_KEYPAIR` | `unsigned int` | Public exponent | 65537
1918 *
1919 * \retval PSA_SUCCESS
1920 * \retval PSA_ERROR_NOT_SUPPORTED
1921 * \retval PSA_ERROR_INVALID_ARGUMENT
1922 * \retval PSA_ERROR_INSUFFICIENT_MEMORY
1923 * \retval PSA_ERROR_INSUFFICIENT_ENTROPY
1924 * \retval PSA_ERROR_COMMUNICATION_FAILURE
1925 * \retval PSA_ERROR_HARDWARE_FAILURE
1926 * \retval PSA_ERROR_TAMPERING_DETECTED
1927 */
1928psa_status_t psa_generate_key(psa_key_slot_t key,
1929 psa_key_type_t type,
1930 size_t bits,
1931 const void *parameters,
1932 size_t parameters_size);
1933
1934/**@}*/
1935
1936#ifdef __cplusplus
1937}
1938#endif
1939
Antonio de Angelis8908f472018-08-31 15:44:25 +01001940/* The file "psa_crypto_extra.h" contains vendor-specific definitions. This
1941 * can include vendor-defined algorithms, extra functions, etc.
1942 */
1943#include "psa_crypto_extra.h"
1944
Antonio de Angelis14276e92018-07-10 14:35:43 +01001945#endif /* PSA_CRYPTO_H */