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