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