blob: c880586fe543980993c5c2050485df4af8228ebb [file] [log] [blame]
Gilles Peskinee59236f2018-01-27 23:32:46 +01001/**
2 * \file psa/crypto.h
3 * \brief Platform Security Architecture cryptography module
4 */
5
6#ifndef PSA_CRYPTO_H
7#define PSA_CRYPTO_H
8
9#include "crypto_platform.h"
10
Gilles Peskine2f9c4dc2018-01-28 13:16:24 +010011#include <stddef.h>
12
Gilles Peskine62a7e7e2018-02-07 21:54:47 +010013#ifdef __DOXYGEN_ONLY__
Gilles Peskinef5b9fa12018-03-07 16:40:18 +010014/* This __DOXYGEN_ONLY__ block contains mock definitions for things that
15 * must be defined in the crypto_platform.h header. These mock definitions
16 * are present in this file as a convenience to generate pretty-printed
17 * documentation that includes those definitions. */
18
Gilles Peskine62a7e7e2018-02-07 21:54:47 +010019/** \defgroup platform Implementation-specific definitions
20 * @{
21 */
22
Gilles Peskine2f9c4dc2018-01-28 13:16:24 +010023/** \brief Key slot number.
24 *
25 * This type represents key slots. It must be an unsigned integral
Gilles Peskine308b91d2018-02-08 09:47:44 +010026 * type. The choice of type is implementation-dependent.
Gilles Peskine2f9c4dc2018-01-28 13:16:24 +010027 * 0 is not a valid key slot number. The meaning of other values is
28 * implementation dependent.
29 *
30 * At any given point in time, each key slot either contains a
31 * cryptographic object, or is empty. Key slots are persistent:
32 * once set, the cryptographic object remains in the key slot until
33 * explicitly destroyed.
34 */
35typedef _unsigned_integral_type_ psa_key_slot_t;
36
Gilles Peskine62a7e7e2018-02-07 21:54:47 +010037/**@}*/
Gilles Peskinef5b9fa12018-03-07 16:40:18 +010038#endif /* __DOXYGEN_ONLY__ */
Gilles Peskine62a7e7e2018-02-07 21:54:47 +010039
Gilles Peskinee59236f2018-01-27 23:32:46 +010040#ifdef __cplusplus
41extern "C" {
42#endif
43
44/** \defgroup basic Basic definitions
45 * @{
46 */
47
48/**
49 * \brief Function return status.
50 *
51 * Zero indicates success, anything else indicates an error.
52 */
53typedef enum {
54 /** The action was completed successfully. */
55 PSA_SUCCESS = 0,
56 /** The requested operation or a parameter is not supported
Gilles Peskine65eb8582018-04-19 08:28:58 +020057 * by this implementation.
58 *
59 * Implementations should return this error code when an enumeration
60 * parameter such as a key type, algorithm, etc. is not recognized.
61 * If a combination of parameters is recognized and identified as
62 * not valid, return #PSA_ERROR_INVALID_ARGUMENT instead. */
Gilles Peskinee59236f2018-01-27 23:32:46 +010063 PSA_ERROR_NOT_SUPPORTED,
Gilles Peskine65eb8582018-04-19 08:28:58 +020064 /** The requested action is denied by a policy.
65 *
66 * Implementations should return this error code when the parameters
67 * are recognized as valid and supported, and a policy explicitly
68 * denies the requested operation.
69 *
70 * If a subset of the parameters of a function call identify a
71 * forbidden operation, and another subset of the parameters are
72 * not valid or not supported, it is unspecified whether the function
73 * returns #PSA_ERROR_NOT_PERMITTED, #PSA_ERROR_NOT_SUPPORTED or
74 * #PSA_ERROR_INVALID_ARGUMENT. */
Gilles Peskinee59236f2018-01-27 23:32:46 +010075 PSA_ERROR_NOT_PERMITTED,
Gilles Peskine65eb8582018-04-19 08:28:58 +020076 /** An output buffer is too small.
77 *
78 * Applications can call the `PSA_xxx_SIZE` macro listed in the function
79 * description to determine a sufficient buffer size.
80 *
81 * Implementations should preferably return this error code only
82 * in cases when performing the operation with a larger output
83 * buffer would succeed. However implementations may return this
84 * error if a function has invalid or unsupported parameters in addition
85 * to the parameters that determine the necessary output buffer size. */
Gilles Peskinee59236f2018-01-27 23:32:46 +010086 PSA_ERROR_BUFFER_TOO_SMALL,
87 /** A slot is occupied, but must be empty to carry out the
Gilles Peskine65eb8582018-04-19 08:28:58 +020088 * requested action.
89 *
90 * If the slot number is invalid (i.e. the requested action could
91 * not be performed even after erasing the slot's content),
92 * implementations shall return #PSA_ERROR_INVALID_ARGUMENT instead. */
Gilles Peskinee59236f2018-01-27 23:32:46 +010093 PSA_ERROR_OCCUPIED_SLOT,
94 /** A slot is empty, but must be occupied to carry out the
Gilles Peskine65eb8582018-04-19 08:28:58 +020095 * requested action.
96 *
97 * If the slot number is invalid (i.e. the requested action could
98 * not be performed even after creating appropriate content in the slot),
99 * implementations shall return #PSA_ERROR_INVALID_ARGUMENT instead. */
Gilles Peskinee59236f2018-01-27 23:32:46 +0100100 PSA_ERROR_EMPTY_SLOT,
Gilles Peskine65eb8582018-04-19 08:28:58 +0200101 /** The requested action cannot be performed in the current state.
102 *
103 * Multipart operations return this error when one of the
104 * functions is called out of sequence. Refer to the function
105 * descriptions for permitted sequencing of functions.
106 *
107 * Implementations shall not return this error code to indicate
108 * that a key slot is occupied when it needs to be free or vice versa,
109 * but shall return #PSA_ERROR_OCCUPIED_SLOT or #PSA_ERROR_EMPTY_SLOT
110 * as applicable. */
Gilles Peskinee59236f2018-01-27 23:32:46 +0100111 PSA_ERROR_BAD_STATE,
Gilles Peskine65eb8582018-04-19 08:28:58 +0200112 /** The parameters passed to the function are invalid.
113 *
114 * Implementations may return this error any time a parameter or
115 * combination of parameters are recognized as invalid.
116 *
117 * Implementations shall not return this error code to indicate
118 * that a key slot is occupied when it needs to be free or vice versa,
119 * but shall return #PSA_ERROR_OCCUPIED_SLOT or #PSA_ERROR_EMPTY_SLOT
120 * as applicable. */
Gilles Peskinee59236f2018-01-27 23:32:46 +0100121 PSA_ERROR_INVALID_ARGUMENT,
Gilles Peskine65eb8582018-04-19 08:28:58 +0200122 /** There is not enough runtime memory.
123 *
124 * If the action is carried out across multiple security realms, this
125 * error can refer to available memory in any of the security realms. */
Gilles Peskinee59236f2018-01-27 23:32:46 +0100126 PSA_ERROR_INSUFFICIENT_MEMORY,
Gilles Peskine65eb8582018-04-19 08:28:58 +0200127 /** There is not enough persistent storage.
128 *
129 * Functions that modify the key storage return this error code if
130 * there is insufficient storage space on the host media. In addition,
131 * many functions that do not otherwise access storage may return this
132 * error code if the implementation requires a mandatory log entry for
133 * the requested action and the log storage space is full. */
Gilles Peskinee59236f2018-01-27 23:32:46 +0100134 PSA_ERROR_INSUFFICIENT_STORAGE,
Gilles Peskine65eb8582018-04-19 08:28:58 +0200135 /** There was a communication failure inside the implementation.
136 *
137 * This can indicate a communication failure between the application
138 * and an external cryptoprocessor or between the cryptoprocessor and
139 * an external volatile or persistent memory. A communication failure
140 * may be transient or permanent depending on the cause.
141 *
142 * \warning If a function returns this error, it is undetermined
143 * whether the requested action has completed or not. Implementations
144 * should return #PSA_SUCCESS on successful completion whenver
145 * possible, however functions may return #PSA_ERROR_COMMUNICATION_FAILURE
146 * if the requested action was completed successfully in an external
147 * cryptoprocessor but there was a breakdown of communication before
148 * the cryptoprocessor could report the status to the application.
149 */
Gilles Peskinee59236f2018-01-27 23:32:46 +0100150 PSA_ERROR_COMMUNICATION_FAILURE,
Gilles Peskine65eb8582018-04-19 08:28:58 +0200151 /** There was a storage failure that may have led to data loss.
152 *
153 * This error indicates that some persistent storage is corrupted.
154 * It should not be used for a corruption of volatile memory
155 * (use #PSA_ERROR_TAMPERING_DETECTED), for a communication error
156 * between the cryptoprocessor and its external storage (use
157 * #PSA_ERROR_COMMUNICATION_FAILURE), or when the storage is
158 * in a valid state but is full (use #PSA_ERROR_INSUFFICIENT_STORAGE).
159 *
160 * Note that a storage failure does not indicate that any data that was
161 * previously read is invalid. However this previously read data may no
162 * longer be readable from storage.
163 *
164 * When a storage failure occurs, it is no longer possible to ensure
165 * the global integrity of the keystore. Depending on the global
166 * integrity guarantees offered by the implementation, access to other
167 * data may or may not fail even if the data is still readable but
168 * its integrity canont be guaranteed.
169 *
170 * Implementations should only use this error code to report a
171 * permanent storage corruption. However application writers should
172 * keep in mind that transient errors while reading the storage may be
173 * reported using this error code. */
Gilles Peskinea5905292018-02-07 20:59:33 +0100174 PSA_ERROR_STORAGE_FAILURE,
Gilles Peskine65eb8582018-04-19 08:28:58 +0200175 /** A hardware failure was detected.
176 *
177 * A hardware failure may be transient or permanent depending on the
178 * cause. */
Gilles Peskinee59236f2018-01-27 23:32:46 +0100179 PSA_ERROR_HARDWARE_FAILURE,
Gilles Peskine65eb8582018-04-19 08:28:58 +0200180 /** A tampering attempt was detected.
181 *
182 * If an application receives this error code, there is no guarantee
183 * that previously accessed or computed data was correct and remains
184 * confidential. Applications should not perform any security function
185 * and should enter a safe failure state.
186 *
187 * Implementations may return this error code if they detect an invalid
188 * state that cannot happen during normal operation and that indicates
189 * that the implementation's security guarantees no longer hold. Depending
190 * on the implementation architecture and on its security and safety goals,
191 * the implementation may forcibly terminate the application.
192 *
193 * This error code is intended as a last resort when a security breach
194 * is detected and it is unsure whether the keystore data is still
195 * protected. Implementations shall only return this error code
196 * to report an alarm from a tampering detector, to indicate that
197 * the confidentiality of stored data can no longer be guaranteed,
198 * or to indicate that the integrity of previously returned data is now
199 * considered compromised. Implementations shall not use this error code
200 * to indicate a hardware failure that merely makes it impossible to
201 * perform the requested operation (use #PSA_ERROR_COMMUNICATION_FAILURE,
202 * #PSA_ERROR_STORAGE_FAILURE, #PSA_ERROR_HARDWARE_FAILURE,
203 * #PSA_ERROR_INSUFFICIENT_ENTROPY or other applicable error code
204 * instead).
205 *
206 * This error indicates an attack against the application. Implementations
207 * shall not return this error code as a consequence of the behavior of
208 * the application itself. */
Gilles Peskinee59236f2018-01-27 23:32:46 +0100209 PSA_ERROR_TAMPERING_DETECTED,
210 /** There is not enough entropy to generate random data needed
Gilles Peskine65eb8582018-04-19 08:28:58 +0200211 * for the requested action.
212 *
213 * This error indicates a failure of a hardware random generator.
214 * Application writers should note that this error can be returned not
215 * only by functions whose purpose is to generate random data, such
216 * as key, IV or nonce generation, but also by functions that execute
217 * an algorithm with a randomized result, as well as functions that
218 * use randomization of intermediate computations as a countermeasure
219 * to certain attacks.
220 *
221 * Implementations should avoid returning this error after psa_crypto_init()
222 * has succeeded. Implementations should generate sufficient
223 * entropy during initialization and subsequently use a cryptographically
224 * secure pseudorandom generator (PRNG). However implementations may return
225 * this error at any time if a policy requires the PRNG to be reseeded
226 * during normal operation. */
Gilles Peskinee59236f2018-01-27 23:32:46 +0100227 PSA_ERROR_INSUFFICIENT_ENTROPY,
Gilles Peskine65eb8582018-04-19 08:28:58 +0200228 /** The signature, MAC or hash is incorrect.
229 *
230 * Verification functions return this error if the verification
231 * calculations completed successfully, and the value to be verified
232 * was determined to be incorrect.
233 *
234 * If the value to verify has an invalid size, implementations may return
235 * either #PSA_ERROR_INVALID_ARGUMENT or #PSA_ERROR_INVALID_SIGNATURE. */
Gilles Peskinee59236f2018-01-27 23:32:46 +0100236 PSA_ERROR_INVALID_SIGNATURE,
Gilles Peskine65eb8582018-04-19 08:28:58 +0200237 /** The decrypted padding is incorrect.
238 *
239 * \warning In some protocols, when decrypting data, it is essential that
240 * the behavior of the application does not depend on whether the padding
241 * is correct, down to precise timing. Applications should prefer
242 * protocols that use authenticated encryption rather than plain
243 * encryption. If the application must perform a decryption of
244 * unauthenticated data, the application writer should take care not
245 * to reveal whether the padding is invalid.
246 *
247 * Implementations should strive to make valid and invalid padding
248 * as close as possible to indistinguishable to an external observer.
249 * In particular, the timing of a decryption operation should not
250 * depend on the validity of the padding. */
Gilles Peskinea5905292018-02-07 20:59:33 +0100251 PSA_ERROR_INVALID_PADDING,
Gilles Peskinee59236f2018-01-27 23:32:46 +0100252 /** An error occurred that does not correspond to any defined
Gilles Peskine65eb8582018-04-19 08:28:58 +0200253 * failure cause.
254 *
255 * Implementations may use this error code if none of the other standard
256 * error codes are applicable. */
Gilles Peskinee59236f2018-01-27 23:32:46 +0100257 PSA_ERROR_UNKNOWN_ERROR,
258} psa_status_t;
259
260/**
261 * \brief Library initialization.
262 *
263 * Applications must call this function before calling any other
264 * function in this module.
265 *
266 * Applications may call this function more than once. Once a call
267 * succeeds, subsequent calls are guaranteed to succeed.
268 *
Gilles Peskine308b91d2018-02-08 09:47:44 +0100269 * \retval PSA_SUCCESS
270 * \retval PSA_ERROR_INSUFFICIENT_MEMORY
271 * \retval PSA_ERROR_COMMUNICATION_FAILURE
272 * \retval PSA_ERROR_HARDWARE_FAILURE
273 * \retval PSA_ERROR_TAMPERING_DETECTED
274 * \retval PSA_ERROR_INSUFFICIENT_ENTROPY
Gilles Peskinee59236f2018-01-27 23:32:46 +0100275 */
276psa_status_t psa_crypto_init(void);
277
Gilles Peskine2905a7a2018-03-07 16:39:31 +0100278#define PSA_BITS_TO_BYTES(bits) (((bits) + 7) / 8)
279#define PSA_BYTES_TO_BITS(bytes) ((bytes) * 8)
Gilles Peskine0189e752018-02-03 23:57:22 +0100280
Gilles Peskinee59236f2018-01-27 23:32:46 +0100281/**@}*/
282
Gilles Peskine2f9c4dc2018-01-28 13:16:24 +0100283/** \defgroup crypto_types Key and algorithm types
284 * @{
285 */
286
Gilles Peskine308b91d2018-02-08 09:47:44 +0100287/** \brief Encoding of a key type.
288 */
Gilles Peskine2f9c4dc2018-01-28 13:16:24 +0100289typedef uint32_t psa_key_type_t;
290
Gilles Peskinef5b9fa12018-03-07 16:40:18 +0100291/** An invalid key type value.
292 *
293 * Zero is not the encoding of any key type.
294 */
Gilles Peskine98f0a242018-02-06 18:57:29 +0100295#define PSA_KEY_TYPE_NONE ((psa_key_type_t)0x00000000)
Gilles Peskinef5b9fa12018-03-07 16:40:18 +0100296
297/** Vendor-defined flag
298 *
299 * Key types defined by this standard will never have the
300 * #PSA_KEY_TYPE_VENDOR_FLAG bit set. Vendors who define additional key types
301 * must use an encoding with the #PSA_KEY_TYPE_VENDOR_FLAG bit set and should
302 * respect the bitwise structure used by standard encodings whenever practical.
303 */
Gilles Peskine98f0a242018-02-06 18:57:29 +0100304#define PSA_KEY_TYPE_VENDOR_FLAG ((psa_key_type_t)0x80000000)
Gilles Peskine2f9c4dc2018-01-28 13:16:24 +0100305
Gilles Peskine98f0a242018-02-06 18:57:29 +0100306#define PSA_KEY_TYPE_CATEGORY_MASK ((psa_key_type_t)0x7e000000)
307#define PSA_KEY_TYPE_RAW_DATA ((psa_key_type_t)0x02000000)
308#define PSA_KEY_TYPE_CATEGORY_SYMMETRIC ((psa_key_type_t)0x04000000)
309#define PSA_KEY_TYPE_CATEGORY_ASYMMETRIC ((psa_key_type_t)0x06000000)
310#define PSA_KEY_TYPE_PAIR_FLAG ((psa_key_type_t)0x01000000)
Gilles Peskine2f9c4dc2018-01-28 13:16:24 +0100311
Gilles Peskine98f0a242018-02-06 18:57:29 +0100312#define PSA_KEY_TYPE_HMAC ((psa_key_type_t)0x02000001)
313#define PSA_KEY_TYPE_AES ((psa_key_type_t)0x04000001)
314#define PSA_KEY_TYPE_DES ((psa_key_type_t)0x04000002)
315#define PSA_KEY_TYPE_CAMELLIA ((psa_key_type_t)0x04000003)
316#define PSA_KEY_TYPE_ARC4 ((psa_key_type_t)0x04000004)
317
Gilles Peskine308b91d2018-02-08 09:47:44 +0100318/** RSA public key. */
Gilles Peskine98f0a242018-02-06 18:57:29 +0100319#define PSA_KEY_TYPE_RSA_PUBLIC_KEY ((psa_key_type_t)0x06010000)
Gilles Peskine308b91d2018-02-08 09:47:44 +0100320/** RSA key pair (private and public key). */
Gilles Peskine98f0a242018-02-06 18:57:29 +0100321#define PSA_KEY_TYPE_RSA_KEYPAIR ((psa_key_type_t)0x07010000)
Gilles Peskine06dc2632018-03-08 07:47:25 +0100322/** DSA public key. */
323#define PSA_KEY_TYPE_DSA_PUBLIC_KEY ((psa_key_type_t)0x06020000)
324/** DSA key pair (private and public key). */
325#define PSA_KEY_TYPE_DSA_KEYPAIR ((psa_key_type_t)0x07020000)
326#define PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE ((psa_key_type_t)0x06030000)
327#define PSA_KEY_TYPE_ECC_KEYPAIR_BASE ((psa_key_type_t)0x07030000)
Gilles Peskine98f0a242018-02-06 18:57:29 +0100328#define PSA_KEY_TYPE_ECC_CURVE_MASK ((psa_key_type_t)0x0000ffff)
Gilles Peskine06dc2632018-03-08 07:47:25 +0100329#define PSA_KEY_TYPE_ECC_KEYPAIR(curve) \
330 (PSA_KEY_TYPE_ECC_KEYPAIR_BASE | (curve))
331#define PSA_KEY_TYPE_ECC_PUBLIC_KEY(curve) \
332 (PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE | (curve))
Gilles Peskine98f0a242018-02-06 18:57:29 +0100333
Gilles Peskinef5b9fa12018-03-07 16:40:18 +0100334/** Whether a key type is vendor-defined. */
Gilles Peskine98f0a242018-02-06 18:57:29 +0100335#define PSA_KEY_TYPE_IS_VENDOR_DEFINED(type) \
Gilles Peskine2f9c4dc2018-01-28 13:16:24 +0100336 (((type) & PSA_KEY_TYPE_VENDOR_FLAG) != 0)
Gilles Peskine8c9def32018-02-08 10:02:12 +0100337#define PSA_KEY_TYPE_IS_RAW_BYTES(type) \
338 (((type) & PSA_KEY_TYPE_CATEGORY_MASK) == PSA_KEY_TYPE_RAW_DATA || \
339 ((type) & PSA_KEY_TYPE_CATEGORY_MASK) == PSA_KEY_TYPE_CATEGORY_SYMMETRIC)
Gilles Peskine06dc2632018-03-08 07:47:25 +0100340
341/** Whether a key type is asymmetric: either a key pair or a public key. */
Gilles Peskine98f0a242018-02-06 18:57:29 +0100342#define PSA_KEY_TYPE_IS_ASYMMETRIC(type) \
343 (((type) & PSA_KEY_TYPE_CATEGORY_MASK) == PSA_KEY_TYPE_CATEGORY_ASYMMETRIC)
Gilles Peskine06dc2632018-03-08 07:47:25 +0100344/** Whether a key type is the public part of a key pair. */
Gilles Peskine98f0a242018-02-06 18:57:29 +0100345#define PSA_KEY_TYPE_IS_PUBLIC_KEY(type) \
346 (((type) & (PSA_KEY_TYPE_CATEGORY_MASK | PSA_KEY_TYPE_PAIR_FLAG) == \
347 PSA_KEY_TYPE_CATEGORY_ASYMMETRIC))
Gilles Peskine06dc2632018-03-08 07:47:25 +0100348/** Whether a key type is a key pair containing a private part and a public
349 * part. */
Gilles Peskine98f0a242018-02-06 18:57:29 +0100350#define PSA_KEY_TYPE_IS_KEYPAIR(type) \
351 (((type) & (PSA_KEY_TYPE_CATEGORY_MASK | PSA_KEY_TYPE_PAIR_FLAG)) == \
352 (PSA_KEY_TYPE_CATEGORY_ASYMMETRIC | PSA_KEY_TYPE_PAIR_FLAG))
Gilles Peskine06dc2632018-03-08 07:47:25 +0100353/** Whether a key type is an RSA key pair or public key. */
354/** The key pair type corresponding to a public key type. */
355#define PSA_KEY_TYPE_KEYPAIR_OF_PUBLIC_KEY(type) \
356 ((type) | PSA_KEY_TYPE_PAIR_FLAG)
357/** The public key type corresponding to a key pair type. */
358#define PSA_KEY_TYPE_PUBLIC_KEY_OF_KEYPAIR(type) \
359 ((type) & ~PSA_KEY_TYPE_PAIR_FLAG)
Gilles Peskine0189e752018-02-03 23:57:22 +0100360#define PSA_KEY_TYPE_IS_RSA(type) \
Gilles Peskine06dc2632018-03-08 07:47:25 +0100361 (PSA_KEY_TYPE_PUBLIC_KEY_OF_KEYPAIR(type) == PSA_KEY_TYPE_RSA_PUBLIC_KEY)
362/** Whether a key type is an elliptic curve key pair or public key. */
Gilles Peskinec66ea6a2018-02-03 22:43:28 +0100363#define PSA_KEY_TYPE_IS_ECC(type) \
Gilles Peskine06dc2632018-03-08 07:47:25 +0100364 ((PSA_KEY_TYPE_PUBLIC_KEY_OF_KEYPAIR(type) & \
365 ~PSA_KEY_TYPE_ECC_CURVE_MASK) == PSA_KEY_TYPE_ECC_PUBLIC_KEY_BASE)
Gilles Peskine2f9c4dc2018-01-28 13:16:24 +0100366
Gilles Peskine7e198532018-03-08 07:50:30 +0100367/** The block size of a block cipher.
368 *
369 * \param type A cipher key type (value of type #psa_key_type_t).
370 *
371 * \return The block size for a block cipher, or 1 for a stream cipher.
372 * The return value is undefined if \c type does not identify
373 * a cipher algorithm.
374 *
375 * \note This macro returns a compile-time constant if its argument is one.
376 *
377 * \warning This macro may evaluate its argument multiple times.
378 */
Gilles Peskine03182e92018-03-07 16:40:52 +0100379#define PSA_BLOCK_CIPHER_BLOCK_SIZE(type) \
Gilles Peskine8c9def32018-02-08 10:02:12 +0100380 ( \
381 (type) == PSA_KEY_TYPE_AES ? 16 : \
382 (type) == PSA_KEY_TYPE_DES ? 8 : \
383 (type) == PSA_KEY_TYPE_CAMELLIA ? 16 : \
Gilles Peskine7e198532018-03-08 07:50:30 +0100384 (type) == PSA_KEY_TYPE_ARC4 ? 1 : \
Gilles Peskine8c9def32018-02-08 10:02:12 +0100385 0)
386
Gilles Peskine308b91d2018-02-08 09:47:44 +0100387/** \brief Encoding of a cryptographic algorithm.
388 *
389 * For algorithms that can be applied to multiple key types, this type
390 * does not encode the key type. For example, for symmetric ciphers
391 * based on a block cipher, #psa_algorithm_t encodes the block cipher
392 * mode and the padding mode while the block cipher itself is encoded
393 * via #psa_key_type_t.
394 */
Gilles Peskine20035e32018-02-03 22:44:14 +0100395typedef uint32_t psa_algorithm_t;
396
Gilles Peskine98f0a242018-02-06 18:57:29 +0100397#define PSA_ALG_VENDOR_FLAG ((psa_algorithm_t)0x80000000)
398#define PSA_ALG_CATEGORY_MASK ((psa_algorithm_t)0x7f000000)
399#define PSA_ALG_CATEGORY_HASH ((psa_algorithm_t)0x01000000)
400#define PSA_ALG_CATEGORY_MAC ((psa_algorithm_t)0x02000000)
401#define PSA_ALG_CATEGORY_CIPHER ((psa_algorithm_t)0x04000000)
402#define PSA_ALG_CATEGORY_AEAD ((psa_algorithm_t)0x06000000)
403#define PSA_ALG_CATEGORY_SIGN ((psa_algorithm_t)0x10000000)
404#define PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION ((psa_algorithm_t)0x12000000)
405#define PSA_ALG_CATEGORY_KEY_AGREEMENT ((psa_algorithm_t)0x22000000)
406#define PSA_ALG_CATEGORY_KEY_DERIVATION ((psa_algorithm_t)0x30000000)
Gilles Peskine20035e32018-02-03 22:44:14 +0100407
Gilles Peskine98f0a242018-02-06 18:57:29 +0100408#define PSA_ALG_IS_VENDOR_DEFINED(alg) \
409 (((alg) & PSA_ALG_VENDOR_FLAG) != 0)
Gilles Peskine308b91d2018-02-08 09:47:44 +0100410/** Whether the specified algorithm is a hash algorithm.
411 *
Gilles Peskine7e198532018-03-08 07:50:30 +0100412 * \param alg An algorithm identifier (value of type #psa_algorithm_t).
Gilles Peskine308b91d2018-02-08 09:47:44 +0100413 *
414 * \return 1 if \c alg is a hash algorithm, 0 otherwise.
415 * This macro may return either 0 or 1 if \c alg is not a valid
Gilles Peskine7e198532018-03-08 07:50:30 +0100416 * algorithm identifier.
417 */
Gilles Peskine98f0a242018-02-06 18:57:29 +0100418#define PSA_ALG_IS_HASH(alg) \
419 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_HASH)
420#define PSA_ALG_IS_MAC(alg) \
421 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_MAC)
422#define PSA_ALG_IS_CIPHER(alg) \
423 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_CIPHER)
424#define PSA_ALG_IS_AEAD(alg) \
425 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_AEAD)
426#define PSA_ALG_IS_SIGN(alg) \
427 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_SIGN)
428#define PSA_ALG_IS_ASYMMETRIC_ENCRYPTION(alg) \
429 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_ASYMMETRIC_ENCRYPTION)
430#define PSA_ALG_IS_KEY_AGREEMENT(alg) \
431 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_KEY_AGREEMENT)
432#define PSA_ALG_IS_KEY_DERIVATION(alg) \
433 (((alg) & PSA_ALG_CATEGORY_MASK) == PSA_ALG_CATEGORY_KEY_DERIVATION)
434
435#define PSA_ALG_HASH_MASK ((psa_algorithm_t)0x000000ff)
436#define PSA_ALG_MD2 ((psa_algorithm_t)0x01000001)
437#define PSA_ALG_MD4 ((psa_algorithm_t)0x01000002)
438#define PSA_ALG_MD5 ((psa_algorithm_t)0x01000003)
Gilles Peskinee3f694f2018-03-08 07:48:40 +0100439#define PSA_ALG_RIPEMD160 ((psa_algorithm_t)0x01000004)
440#define PSA_ALG_SHA_1 ((psa_algorithm_t)0x01000005)
Gilles Peskine98f0a242018-02-06 18:57:29 +0100441#define PSA_ALG_SHA_224 ((psa_algorithm_t)0x01000008)
442#define PSA_ALG_SHA_256 ((psa_algorithm_t)0x01000009)
443#define PSA_ALG_SHA_384 ((psa_algorithm_t)0x0100000a)
444#define PSA_ALG_SHA_512 ((psa_algorithm_t)0x0100000b)
445#define PSA_ALG_SHA_512_224 ((psa_algorithm_t)0x0100000c)
446#define PSA_ALG_SHA_512_256 ((psa_algorithm_t)0x0100000d)
447#define PSA_ALG_SHA3_224 ((psa_algorithm_t)0x01000010)
448#define PSA_ALG_SHA3_256 ((psa_algorithm_t)0x01000011)
449#define PSA_ALG_SHA3_384 ((psa_algorithm_t)0x01000012)
450#define PSA_ALG_SHA3_512 ((psa_algorithm_t)0x01000013)
451
Gilles Peskine8c9def32018-02-08 10:02:12 +0100452#define PSA_ALG_MAC_SUBCATEGORY_MASK ((psa_algorithm_t)0x00c00000)
Gilles Peskine98f0a242018-02-06 18:57:29 +0100453#define PSA_ALG_HMAC_BASE ((psa_algorithm_t)0x02800000)
454#define PSA_ALG_HMAC(hash_alg) \
Gilles Peskine8c9def32018-02-08 10:02:12 +0100455 (PSA_ALG_HMAC_BASE | ((hash_alg) & PSA_ALG_HASH_MASK))
456#define PSA_ALG_HMAC_HASH(hmac_alg) \
457 (PSA_ALG_CATEGORY_HASH | ((hmac_alg) & PSA_ALG_HASH_MASK))
458#define PSA_ALG_IS_HMAC(alg) \
459 (((alg) & (PSA_ALG_CATEGORY_MASK | PSA_ALG_MAC_SUBCATEGORY_MASK)) == \
460 PSA_ALG_HMAC_BASE)
461#define PSA_ALG_CIPHER_MAC_BASE ((psa_algorithm_t)0x02c00000)
462#define PSA_ALG_CBC_MAC ((psa_algorithm_t)0x02c00001)
463#define PSA_ALG_CMAC ((psa_algorithm_t)0x02c00002)
464#define PSA_ALG_GMAC ((psa_algorithm_t)0x02c00003)
465#define PSA_ALG_IS_CIPHER_MAC(alg) \
466 (((alg) & (PSA_ALG_CATEGORY_MASK | PSA_ALG_MAC_SUBCATEGORY_MASK)) == \
467 PSA_ALG_CIPHER_MAC_BASE)
Gilles Peskine98f0a242018-02-06 18:57:29 +0100468
Gilles Peskine8c9def32018-02-08 10:02:12 +0100469#define PSA_ALG_CIPHER_SUBCATEGORY_MASK ((psa_algorithm_t)0x00c00000)
Gilles Peskine428dc5a2018-03-03 21:27:18 +0100470#define PSA_ALG_BLOCK_CIPHER_BASE ((psa_algorithm_t)0x04000000)
Gilles Peskine8c9def32018-02-08 10:02:12 +0100471#define PSA_ALG_BLOCK_CIPHER_MODE_MASK ((psa_algorithm_t)0x000000ff)
Gilles Peskine428dc5a2018-03-03 21:27:18 +0100472#define PSA_ALG_BLOCK_CIPHER_PADDING_MASK ((psa_algorithm_t)0x003f0000)
473#define PSA_ALG_BLOCK_CIPHER_PAD_NONE ((psa_algorithm_t)0x00000000)
Gilles Peskine98f0a242018-02-06 18:57:29 +0100474#define PSA_ALG_BLOCK_CIPHER_PAD_PKCS7 ((psa_algorithm_t)0x00010000)
Gilles Peskine8c9def32018-02-08 10:02:12 +0100475#define PSA_ALG_IS_BLOCK_CIPHER(alg) \
476 (((alg) & (PSA_ALG_CATEGORY_MASK | PSA_ALG_CIPHER_SUBCATEGORY_MASK)) == \
477 PSA_ALG_BLOCK_CIPHER_BASE)
478
Gilles Peskine98f0a242018-02-06 18:57:29 +0100479#define PSA_ALG_CBC_BASE ((psa_algorithm_t)0x04000001)
Gilles Peskine8c9def32018-02-08 10:02:12 +0100480#define PSA_ALG_CFB_BASE ((psa_algorithm_t)0x04000002)
481#define PSA_ALG_OFB_BASE ((psa_algorithm_t)0x04000003)
482#define PSA_ALG_XTS_BASE ((psa_algorithm_t)0x04000004)
Gilles Peskine98f0a242018-02-06 18:57:29 +0100483#define PSA_ALG_STREAM_CIPHER ((psa_algorithm_t)0x04800000)
484#define PSA_ALG_CTR ((psa_algorithm_t)0x04800001)
Gilles Peskine8c9def32018-02-08 10:02:12 +0100485#define PSA_ALG_ARC4 ((psa_algorithm_t)0x04800002)
Gilles Peskine98f0a242018-02-06 18:57:29 +0100486
Gilles Peskine8c9def32018-02-08 10:02:12 +0100487#define PSA_ALG_CCM ((psa_algorithm_t)0x06000001)
488#define PSA_ALG_GCM ((psa_algorithm_t)0x06000002)
Gilles Peskine98f0a242018-02-06 18:57:29 +0100489
Gilles Peskinea5926232018-03-28 14:16:50 +0200490#define PSA_ALG_RSA_PKCS1V15_SIGN_RAW ((psa_algorithm_t)0x10010000)
Gilles Peskine98f0a242018-02-06 18:57:29 +0100491#define PSA_ALG_RSA_PSS_MGF1 ((psa_algorithm_t)0x10020000)
Gilles Peskine6944f9a2018-03-28 14:18:39 +0200492#define PSA_ALG_RSA_PKCS1V15_CRYPT ((psa_algorithm_t)0x12010000)
493#define PSA_ALG_RSA_OAEP_MGF1_BASE ((psa_algorithm_t)0x12020000)
Gilles Peskinea5926232018-03-28 14:16:50 +0200494#define PSA_ALG_RSA_PKCS1V15_SIGN(hash_alg) \
495 (PSA_ALG_RSA_PKCS1V15_SIGN_RAW | ((hash_alg) & PSA_ALG_HASH_MASK))
496#define PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) \
497 (((alg) & 0x7fffff00) == PSA_ALG_RSA_PKCS1V15_SIGN_RAW)
Gilles Peskine98f0a242018-02-06 18:57:29 +0100498#define PSA_ALG_RSA_GET_HASH(alg) \
499 (((alg) & PSA_ALG_HASH_MASK) | PSA_ALG_CATEGORY_HASH)
Gilles Peskine2f9c4dc2018-01-28 13:16:24 +0100500
501/**@}*/
502
503/** \defgroup key_management Key management
504 * @{
505 */
506
507/**
508 * \brief Import a key in binary format.
509 *
Gilles Peskinef5b9fa12018-03-07 16:40:18 +0100510 * This function supports any output from psa_export_key(). Refer to the
511 * documentation of psa_export_key() for the format for each key type.
Gilles Peskine2f9c4dc2018-01-28 13:16:24 +0100512 *
Gilles Peskine308b91d2018-02-08 09:47:44 +0100513 * \param key Slot where the key will be stored. This must be a
514 * valid slot for a key of the chosen type. It must
515 * be unoccupied.
516 * \param type Key type (a \c PSA_KEY_TYPE_XXX value).
517 * \param data Buffer containing the key data.
518 * \param data_length Size of the \c data buffer in bytes.
519 *
520 * \retval PSA_SUCCESS
521 * Success.
522 * \retval PSA_ERROR_NOT_SUPPORTED
Gilles Peskine65eb8582018-04-19 08:28:58 +0200523 * The key type or key size is not supported, either by the
524 * implementation in general or in this particular slot.
Gilles Peskine308b91d2018-02-08 09:47:44 +0100525 * \retval PSA_ERROR_INVALID_ARGUMENT
526 * The key slot is invalid,
527 * or the key data is not correctly formatted.
528 * \retval PSA_ERROR_OCCUPIED_SLOT
Gilles Peskine65eb8582018-04-19 08:28:58 +0200529 * There is already a key in the specified slot.
Gilles Peskine308b91d2018-02-08 09:47:44 +0100530 * \retval PSA_ERROR_INSUFFICIENT_MEMORY
Gilles Peskine65eb8582018-04-19 08:28:58 +0200531 * \retval PSA_ERROR_INSUFFICIENT_STORAGE
Gilles Peskine308b91d2018-02-08 09:47:44 +0100532 * \retval PSA_ERROR_COMMUNICATION_FAILURE
533 * \retval PSA_ERROR_HARDWARE_FAILURE
534 * \retval PSA_ERROR_TAMPERING_DETECTED
Gilles Peskine2f9c4dc2018-01-28 13:16:24 +0100535 */
536psa_status_t psa_import_key(psa_key_slot_t key,
537 psa_key_type_t type,
538 const uint8_t *data,
539 size_t data_length);
540
541/**
542 * \brief Destroy a key.
543 *
Gilles Peskine308b91d2018-02-08 09:47:44 +0100544 * \retval PSA_SUCCESS
Gilles Peskine65eb8582018-04-19 08:28:58 +0200545 * The slot's content, if any, has been erased.
546 * \retval PSA_ERROR_NOT_PERMITTED
547 * The slot holds content and cannot be erased because it is
548 * read-only, either due to a policy or due to physical restrictions.
549 * \retval PSA_ERROR_INVALID_ARGUMENT
550 * The specified slot number does not designate a valid slot.
Gilles Peskine308b91d2018-02-08 09:47:44 +0100551 * \retval PSA_ERROR_COMMUNICATION_FAILURE
Gilles Peskine65eb8582018-04-19 08:28:58 +0200552 * There was an failure in communication with the cryptoprocessor.
553 * The key material may still be present in the cryptoprocessor.
554 * \retval PSA_ERROR_STORAGE_FAILURE
555 * The storage is corrupted. Implementations shall make a best effort
556 * to erase key material even in this stage, however applications
557 * should be aware that it may be impossible to guarantee that the
558 * key material is not recoverable in such cases.
Gilles Peskine308b91d2018-02-08 09:47:44 +0100559 * \retval PSA_ERROR_TAMPERING_DETECTED
Gilles Peskine65eb8582018-04-19 08:28:58 +0200560 * An unexpected condition which is not a storage corruption or
561 * a communication failure occurred. The cryptoprocessor may have
562 * been compromised.
Gilles Peskine2f9c4dc2018-01-28 13:16:24 +0100563 */
564psa_status_t psa_destroy_key(psa_key_slot_t key);
565
566/**
567 * \brief Get basic metadata about a key.
568 *
Gilles Peskine308b91d2018-02-08 09:47:44 +0100569 * \param key Slot whose content is queried. This must
570 * be an occupied key slot.
571 * \param type On success, the key type (a \c PSA_KEY_TYPE_XXX value).
572 * This may be a null pointer, in which case the key type
573 * is not written.
574 * \param bits On success, the key size in bits.
Gilles Peskine9a1ba0d2018-03-21 20:49:16 +0100575 * This may be a null pointer, in which case the key size
Gilles Peskine308b91d2018-02-08 09:47:44 +0100576 * is not written.
577 *
578 * \retval PSA_SUCCESS
579 * \retval PSA_ERROR_EMPTY_SLOT
580 * \retval PSA_ERROR_COMMUNICATION_FAILURE
581 * \retval PSA_ERROR_HARDWARE_FAILURE
582 * \retval PSA_ERROR_TAMPERING_DETECTED
Gilles Peskine2f9c4dc2018-01-28 13:16:24 +0100583 */
584psa_status_t psa_get_key_information(psa_key_slot_t key,
585 psa_key_type_t *type,
586 size_t *bits);
587
588/**
589 * \brief Export a key in binary format.
590 *
591 * The output of this function can be passed to psa_import_key() to
592 * create an equivalent object.
593 *
594 * If a key is created with psa_import_key() and then exported with
595 * this function, it is not guaranteed that the resulting data is
596 * identical: the implementation may choose a different representation
Gilles Peskine92b30732018-03-03 21:29:30 +0100597 * of the same key if the format permits it.
Gilles Peskine2f9c4dc2018-01-28 13:16:24 +0100598 *
Gilles Peskine308b91d2018-02-08 09:47:44 +0100599 * For standard key types, the output format is as follows:
600 *
601 * - For symmetric keys (including MAC keys), the format is the
602 * raw bytes of the key.
603 * - For DES, the key data consists of 8 bytes. The parity bits must be
604 * correct.
605 * - For Triple-DES, the format is the concatenation of the
606 * two or three DES keys.
Gilles Peskine92b30732018-03-03 21:29:30 +0100607 * - For RSA key pairs (#PSA_KEY_TYPE_RSA_KEYPAIR), the format
Gilles Peskine308b91d2018-02-08 09:47:44 +0100608 * is the non-encrypted DER representation defined by PKCS\#8 (RFC 5208)
609 * as PrivateKeyInfo.
610 * - For RSA public keys (#PSA_KEY_TYPE_RSA_PUBLIC_KEY), the format
Gilles Peskine971f7062018-03-20 17:52:58 +0100611 * is the DER representation defined by RFC 5280 as SubjectPublicKeyInfo.
Gilles Peskine308b91d2018-02-08 09:47:44 +0100612 *
613 * \param key Slot whose content is to be exported. This must
614 * be an occupied key slot.
615 * \param data Buffer where the key data is to be written.
616 * \param data_size Size of the \c data buffer in bytes.
617 * \param data_length On success, the number of bytes
618 * that make up the key data.
619 *
620 * \retval PSA_SUCCESS
621 * \retval PSA_ERROR_EMPTY_SLOT
Gilles Peskine92b30732018-03-03 21:29:30 +0100622 * \retval PSA_ERROR_NOT_PERMITTED
Gilles Peskine308b91d2018-02-08 09:47:44 +0100623 * \retval PSA_ERROR_COMMUNICATION_FAILURE
624 * \retval PSA_ERROR_HARDWARE_FAILURE
625 * \retval PSA_ERROR_TAMPERING_DETECTED
Gilles Peskine2f9c4dc2018-01-28 13:16:24 +0100626 */
627psa_status_t psa_export_key(psa_key_slot_t key,
628 uint8_t *data,
629 size_t data_size,
630 size_t *data_length);
631
Gilles Peskine7698bcf2018-03-03 21:30:44 +0100632/**
633 * \brief Export a public key or the public part of a key pair in binary format.
634 *
635 * The output of this function can be passed to psa_import_key() to
636 * create an object that is equivalent to the public key.
637 *
638 * For standard key types, the output format is as follows:
639 *
640 * - For RSA keys (#PSA_KEY_TYPE_RSA_KEYPAIR or #PSA_KEY_TYPE_RSA_PUBLIC_KEY),
Gilles Peskine971f7062018-03-20 17:52:58 +0100641 * is the DER representation of the public key defined by RFC 5280
642 * as SubjectPublicKeyInfo.
Gilles Peskine7698bcf2018-03-03 21:30:44 +0100643 *
644 * \param key Slot whose content is to be exported. This must
645 * be an occupied key slot.
646 * \param data Buffer where the key data is to be written.
647 * \param data_size Size of the \c data buffer in bytes.
648 * \param data_length On success, the number of bytes
649 * that make up the key data.
650 *
651 * \retval PSA_SUCCESS
652 * \retval PSA_ERROR_EMPTY_SLOT
653 * \retval PSA_ERROR_INVALID_ARGUMENT
654 * \retval PSA_ERROR_COMMUNICATION_FAILURE
655 * \retval PSA_ERROR_HARDWARE_FAILURE
656 * \retval PSA_ERROR_TAMPERING_DETECTED
657 */
658psa_status_t psa_export_public_key(psa_key_slot_t key,
659 uint8_t *data,
660 size_t data_size,
661 size_t *data_length);
662
663/**@}*/
664
665/** \defgroup policy Key policies
666 * @{
667 */
668
669/** \brief Encoding of permitted usage on a key. */
670typedef uint32_t psa_key_usage_t;
671
Gilles Peskine7e198532018-03-08 07:50:30 +0100672/** Whether the key may be exported.
673 *
674 * A public key or the public part of a key pair may always be exported
675 * regardless of the value of this permission flag.
676 *
677 * If a key does not have export permission, implementations shall not
678 * allow the key to be exported in plain form from the cryptoprocessor,
679 * whether through psa_export_key() or through a proprietary interface.
680 * The key may however be exportable in a wrapped form, i.e. in a form
681 * where it is encrypted by another key.
682 */
Gilles Peskine7698bcf2018-03-03 21:30:44 +0100683#define PSA_KEY_USAGE_EXPORT ((psa_key_usage_t)0x00000001)
684
Gilles Peskine7e198532018-03-08 07:50:30 +0100685/** Whether the key may be used to encrypt a message.
686 *
687 * For a key pair, this concerns the public key.
688 */
Gilles Peskine7698bcf2018-03-03 21:30:44 +0100689#define PSA_KEY_USAGE_ENCRYPT ((psa_key_usage_t)0x00000100)
Gilles Peskine7e198532018-03-08 07:50:30 +0100690
691/** Whether the key may be used to decrypt a message.
692 *
693 * For a key pair, this concerns the private key.
694 */
Gilles Peskine7698bcf2018-03-03 21:30:44 +0100695#define PSA_KEY_USAGE_DECRYPT ((psa_key_usage_t)0x00000200)
Gilles Peskine7e198532018-03-08 07:50:30 +0100696
697/** Whether the key may be used to sign a message.
698 *
699 * For a key pair, this concerns the private key.
700 */
Gilles Peskine7698bcf2018-03-03 21:30:44 +0100701#define PSA_KEY_USAGE_SIGN ((psa_key_usage_t)0x00000400)
Gilles Peskine7e198532018-03-08 07:50:30 +0100702
703/** Whether the key may be used to verify a message signature.
704 *
705 * For a key pair, this concerns the public key.
706 */
Gilles Peskine7698bcf2018-03-03 21:30:44 +0100707#define PSA_KEY_USAGE_VERIFY ((psa_key_usage_t)0x00000800)
708
709/** The type of the key policy data structure.
710 *
711 * This is an implementation-defined \c struct. Applications should not
712 * make any assumptions about the content of this structure except
713 * as directed by the documentation of a specific implementation. */
714typedef struct psa_key_policy_s psa_key_policy_t;
715
716/** \brief Initialize a key policy structure to a default that forbids all
717 * usage of the key. */
718void psa_key_policy_init(psa_key_policy_t *policy);
719
Gilles Peskine7e198532018-03-08 07:50:30 +0100720/** \brief Set the standard fields of a policy structure.
721 *
722 * Note that this function does not make any consistency check of the
723 * parameters. The values are only checked when applying the policy to
724 * a key slot with psa_set_key_policy().
725 */
Gilles Peskine7698bcf2018-03-03 21:30:44 +0100726void psa_key_policy_set_usage(psa_key_policy_t *policy,
727 psa_key_usage_t usage,
728 psa_algorithm_t alg);
729
730psa_key_usage_t psa_key_policy_get_usage(psa_key_policy_t *policy);
731
732psa_algorithm_t psa_key_policy_get_algorithm(psa_key_policy_t *policy);
733
734/** \brief Set the usage policy on a key slot.
735 *
736 * This function must be called on an empty key slot, before importing,
737 * generating or creating a key in the slot. Changing the policy of an
738 * existing key is not permitted.
Gilles Peskine7e198532018-03-08 07:50:30 +0100739 *
740 * Implementations may set restrictions on supported key policies
741 * depending on the key type and the key slot.
Gilles Peskine7698bcf2018-03-03 21:30:44 +0100742 */
743psa_status_t psa_set_key_policy(psa_key_slot_t key,
744 const psa_key_policy_t *policy);
745
Gilles Peskine7e198532018-03-08 07:50:30 +0100746/** \brief Get the usage policy for a key slot.
747 */
Gilles Peskine7698bcf2018-03-03 21:30:44 +0100748psa_status_t psa_get_key_policy(psa_key_slot_t key,
749 psa_key_policy_t *policy);
Gilles Peskine20035e32018-02-03 22:44:14 +0100750
751/**@}*/
752
Gilles Peskine609b6a52018-03-03 21:31:50 +0100753/** \defgroup persistence Key lifetime
754 * @{
755 */
756
757/** Encoding of key lifetimes.
758 */
759typedef uint32_t psa_key_lifetime_t;
760
761/** A volatile key slot retains its content as long as the application is
762 * running. It is guaranteed to be erased on a power reset.
763 */
764#define PSA_KEY_LIFETIME_VOLATILE ((psa_key_lifetime_t)0x00000000)
765
766/** A persistent key slot retains its content as long as it is not explicitly
767 * destroyed.
768 */
769#define PSA_KEY_LIFETIME_PERSISTENT ((psa_key_lifetime_t)0x00000001)
770
771/** A write-once key slot may not be modified once a key has been set.
772 * It will retain its content as long as the device remains operational.
773 */
774#define PSA_KEY_LIFETIME_WRITE_ONCE ((psa_key_lifetime_t)0x7fffffff)
775
Gilles Peskined393e182018-03-08 07:49:16 +0100776/** \brief Retrieve the lifetime of a key slot.
777 *
778 * The assignment of lifetimes to slots is implementation-dependent.
779 */
Gilles Peskine609b6a52018-03-03 21:31:50 +0100780psa_status_t psa_get_key_lifetime(psa_key_slot_t key,
781 psa_key_lifetime_t *lifetime);
782
Gilles Peskined393e182018-03-08 07:49:16 +0100783/** \brief Change the lifetime of a key slot.
784 *
785 * Whether the lifetime of a key slot can be changed at all, and if so
Gilles Peskine19067982018-03-20 17:54:53 +0100786 * whether the lifetime of an occupied key slot can be changed, is
Gilles Peskined393e182018-03-08 07:49:16 +0100787 * implementation-dependent.
788 */
789psa_status_t psa_set_key_lifetime(psa_key_slot_t key,
790 const psa_key_lifetime_t *lifetime);
791
Gilles Peskine609b6a52018-03-03 21:31:50 +0100792/**@}*/
793
Gilles Peskine9ef733f2018-02-07 21:05:37 +0100794/** \defgroup hash Message digests
795 * @{
796 */
797
Gilles Peskine308b91d2018-02-08 09:47:44 +0100798/** The type of the state data structure for multipart hash operations.
799 *
Gilles Peskine92b30732018-03-03 21:29:30 +0100800 * This is an implementation-defined \c struct. Applications should not
Gilles Peskine308b91d2018-02-08 09:47:44 +0100801 * make any assumptions about the content of this structure except
802 * as directed by the documentation of a specific implementation. */
Gilles Peskine9ef733f2018-02-07 21:05:37 +0100803typedef struct psa_hash_operation_s psa_hash_operation_t;
804
Gilles Peskine308b91d2018-02-08 09:47:44 +0100805/** The size of the output of psa_hash_finish(), in bytes.
806 *
807 * This is also the hash size that psa_hash_verify() expects.
808 *
809 * \param alg A hash algorithm (\c PSA_ALG_XXX value such that
810 * #PSA_ALG_IS_HASH(alg) is true).
811 *
812 * \return The hash size for the specified hash algorithm.
813 * If the hash algorithm is not recognized, return 0.
814 * An implementation may return either 0 or the correct size
815 * for a hash algorithm that it recognizes, but does not support.
816 */
Gilles Peskine71bb7b72018-04-19 08:29:59 +0200817#define PSA_HASH_SIZE(alg) \
818 ( \
819 PSA_ALG_RSA_GET_HASH(alg) == PSA_ALG_MD2 ? 16 : \
820 PSA_ALG_RSA_GET_HASH(alg) == PSA_ALG_MD4 ? 16 : \
821 PSA_ALG_RSA_GET_HASH(alg) == PSA_ALG_MD5 ? 16 : \
822 PSA_ALG_RSA_GET_HASH(alg) == PSA_ALG_RIPEMD160 ? 20 : \
823 PSA_ALG_RSA_GET_HASH(alg) == PSA_ALG_SHA_1 ? 20 : \
824 PSA_ALG_RSA_GET_HASH(alg) == PSA_ALG_SHA_224 ? 28 : \
825 PSA_ALG_RSA_GET_HASH(alg) == PSA_ALG_SHA_256 ? 32 : \
826 PSA_ALG_RSA_GET_HASH(alg) == PSA_ALG_SHA_384 ? 48 : \
827 PSA_ALG_RSA_GET_HASH(alg) == PSA_ALG_SHA_512 ? 64 : \
828 PSA_ALG_RSA_GET_HASH(alg) == PSA_ALG_SHA_512_224 ? 28 : \
829 PSA_ALG_RSA_GET_HASH(alg) == PSA_ALG_SHA_512_256 ? 32 : \
830 PSA_ALG_RSA_GET_HASH(alg) == PSA_ALG_SHA3_224 ? 28 : \
831 PSA_ALG_RSA_GET_HASH(alg) == PSA_ALG_SHA3_256 ? 32 : \
832 PSA_ALG_RSA_GET_HASH(alg) == PSA_ALG_SHA3_384 ? 48 : \
833 PSA_ALG_RSA_GET_HASH(alg) == PSA_ALG_SHA3_512 ? 64 : \
Gilles Peskine9ef733f2018-02-07 21:05:37 +0100834 0)
835
Gilles Peskine308b91d2018-02-08 09:47:44 +0100836/** Start a multipart hash operation.
837 *
838 * The sequence of operations to calculate a hash (message digest)
839 * is as follows:
840 * -# Allocate an operation object which will be passed to all the functions
841 * listed here.
842 * -# Call psa_hash_start() to specify the algorithm.
Gilles Peskine7e4acc52018-02-16 21:24:11 +0100843 * -# Call psa_hash_update() zero, one or more times, passing a fragment
Gilles Peskine308b91d2018-02-08 09:47:44 +0100844 * of the message each time. The hash that is calculated is the hash
845 * of the concatenation of these messages in order.
846 * -# To calculate the hash, call psa_hash_finish().
847 * To compare the hash with an expected value, call psa_hash_verify().
848 *
849 * The application may call psa_hash_abort() at any time after the operation
850 * has been initialized with psa_hash_start().
851 *
852 * After a successful call to psa_hash_start(), the application must
Gilles Peskineed522972018-03-20 17:54:15 +0100853 * eventually terminate the operation. The following events terminate an
854 * operation:
Gilles Peskine308b91d2018-02-08 09:47:44 +0100855 * - A failed call to psa_hash_update().
Gilles Peskine19067982018-03-20 17:54:53 +0100856 * - A call to psa_hash_finish(), psa_hash_verify() or psa_hash_abort().
Gilles Peskine308b91d2018-02-08 09:47:44 +0100857 *
858 * \param operation
859 * \param alg The hash algorithm to compute (\c PSA_ALG_XXX value
860 * such that #PSA_ALG_IS_HASH(alg) is true).
861 *
862 * \retval PSA_SUCCESS
863 * Success.
864 * \retval PSA_ERROR_NOT_SUPPORTED
865 * \c alg is not supported or is not a hash algorithm.
866 * \retval PSA_ERROR_INSUFFICIENT_MEMORY
867 * \retval PSA_ERROR_COMMUNICATION_FAILURE
868 * \retval PSA_ERROR_HARDWARE_FAILURE
869 * \retval PSA_ERROR_TAMPERING_DETECTED
870 */
Gilles Peskine9ef733f2018-02-07 21:05:37 +0100871psa_status_t psa_hash_start(psa_hash_operation_t *operation,
872 psa_algorithm_t alg);
873
Gilles Peskine308b91d2018-02-08 09:47:44 +0100874/** Add a message fragment to a multipart hash operation.
875 *
876 * The application must call psa_hash_start() before calling this function.
877 *
878 * If this function returns an error status, the operation becomes inactive.
879 *
880 * \param operation Active hash operation.
881 * \param input Buffer containing the message fragment to hash.
882 * \param input_length Size of the \c input buffer in bytes.
883 *
884 * \retval PSA_SUCCESS
885 * Success.
886 * \retval PSA_ERROR_BAD_STATE
887 * The operation state is not valid (not started, or already completed).
888 * \retval PSA_ERROR_INSUFFICIENT_MEMORY
889 * \retval PSA_ERROR_COMMUNICATION_FAILURE
890 * \retval PSA_ERROR_HARDWARE_FAILURE
891 * \retval PSA_ERROR_TAMPERING_DETECTED
892 */
Gilles Peskine9ef733f2018-02-07 21:05:37 +0100893psa_status_t psa_hash_update(psa_hash_operation_t *operation,
894 const uint8_t *input,
895 size_t input_length);
896
Gilles Peskine308b91d2018-02-08 09:47:44 +0100897/** Finish the calculation of the hash of a message.
898 *
899 * The application must call psa_hash_start() before calling this function.
900 * This function calculates the hash of the message formed by concatenating
901 * the inputs passed to preceding calls to psa_hash_update().
902 *
903 * When this function returns, the operation becomes inactive.
904 *
905 * \warning Applications should not call this function if they expect
906 * a specific value for the hash. Call psa_hash_verify() instead.
907 * Beware that comparing integrity or authenticity data such as
908 * hash values with a function such as \c memcmp is risky
909 * because the time taken by the comparison may leak information
910 * about the hashed data which could allow an attacker to guess
911 * a valid hash and thereby bypass security controls.
912 *
913 * \param operation Active hash operation.
914 * \param hash Buffer where the hash is to be written.
915 * \param hash_size Size of the \c hash buffer in bytes.
916 * \param hash_length On success, the number of bytes
917 * that make up the hash value. This is always
Gilles Peskine71bb7b72018-04-19 08:29:59 +0200918 * #PSA_HASH_SIZE(alg) where \c alg is the
Gilles Peskine308b91d2018-02-08 09:47:44 +0100919 * hash algorithm that is calculated.
920 *
921 * \retval PSA_SUCCESS
922 * Success.
923 * \retval PSA_ERROR_BAD_STATE
924 * The operation state is not valid (not started, or already completed).
925 * \retval PSA_ERROR_BUFFER_TOO_SMALL
926 * The size of the \c hash buffer is too small. You can determine a
Gilles Peskine71bb7b72018-04-19 08:29:59 +0200927 * sufficient buffer size by calling #PSA_HASH_SIZE(alg)
Gilles Peskine308b91d2018-02-08 09:47:44 +0100928 * where \c alg is the hash algorithm that is calculated.
929 * \retval PSA_ERROR_INSUFFICIENT_MEMORY
930 * \retval PSA_ERROR_COMMUNICATION_FAILURE
931 * \retval PSA_ERROR_HARDWARE_FAILURE
932 * \retval PSA_ERROR_TAMPERING_DETECTED
933 */
Gilles Peskine9ef733f2018-02-07 21:05:37 +0100934psa_status_t psa_hash_finish(psa_hash_operation_t *operation,
935 uint8_t *hash,
936 size_t hash_size,
937 size_t *hash_length);
938
Gilles Peskine308b91d2018-02-08 09:47:44 +0100939/** Finish the calculation of the hash of a message and compare it with
940 * an expected value.
941 *
942 * The application must call psa_hash_start() before calling this function.
943 * This function calculates the hash of the message formed by concatenating
944 * the inputs passed to preceding calls to psa_hash_update(). It then
945 * compares the calculated hash with the expected hash passed as a
946 * parameter to this function.
947 *
948 * When this function returns, the operation becomes inactive.
949 *
Gilles Peskine19067982018-03-20 17:54:53 +0100950 * \note Implementations shall make the best effort to ensure that the
Gilles Peskine308b91d2018-02-08 09:47:44 +0100951 * comparison between the actual hash and the expected hash is performed
952 * in constant time.
953 *
954 * \param operation Active hash operation.
955 * \param hash Buffer containing the expected hash value.
956 * \param hash_length Size of the \c hash buffer in bytes.
957 *
958 * \retval PSA_SUCCESS
959 * The expected hash is identical to the actual hash of the message.
960 * \retval PSA_ERROR_INVALID_SIGNATURE
961 * The hash of the message was calculated successfully, but it
962 * differs from the expected hash.
963 * \retval PSA_ERROR_BAD_STATE
964 * The operation state is not valid (not started, or already completed).
965 * \retval PSA_ERROR_INSUFFICIENT_MEMORY
966 * \retval PSA_ERROR_COMMUNICATION_FAILURE
967 * \retval PSA_ERROR_HARDWARE_FAILURE
968 * \retval PSA_ERROR_TAMPERING_DETECTED
969 */
Gilles Peskine9ef733f2018-02-07 21:05:37 +0100970psa_status_t psa_hash_verify(psa_hash_operation_t *operation,
971 const uint8_t *hash,
972 size_t hash_length);
973
Gilles Peskine308b91d2018-02-08 09:47:44 +0100974/** Abort a hash operation.
975 *
976 * This function may be called at any time after psa_hash_start().
977 * Aborting an operation frees all associated resources except for the
978 * \c operation structure itself.
979 *
980 * Implementation should strive to be robust and handle inactive hash
981 * operations safely (do nothing and return #PSA_ERROR_BAD_STATE). However,
982 * application writers should beware that uninitialized memory may happen
983 * to be indistinguishable from an active hash operation, and the behavior
984 * of psa_hash_abort() is undefined in this case.
985 *
986 * \param operation Active hash operation.
987 *
988 * \retval PSA_SUCCESS
989 * \retval PSA_ERROR_BAD_STATE
990 * \c operation is not an active hash operation.
991 * \retval PSA_ERROR_COMMUNICATION_FAILURE
992 * \retval PSA_ERROR_HARDWARE_FAILURE
993 * \retval PSA_ERROR_TAMPERING_DETECTED
994 */
995psa_status_t psa_hash_abort(psa_hash_operation_t *operation);
Gilles Peskine9ef733f2018-02-07 21:05:37 +0100996
997/**@}*/
998
Gilles Peskine8c9def32018-02-08 10:02:12 +0100999/** \defgroup MAC Message authentication codes
1000 * @{
1001 */
1002
Gilles Peskine7e4acc52018-02-16 21:24:11 +01001003/** The type of the state data structure for multipart MAC operations.
1004 *
Gilles Peskine92b30732018-03-03 21:29:30 +01001005 * This is an implementation-defined \c struct. Applications should not
Gilles Peskine7e4acc52018-02-16 21:24:11 +01001006 * make any assumptions about the content of this structure except
1007 * as directed by the documentation of a specific implementation. */
Gilles Peskine8c9def32018-02-08 10:02:12 +01001008typedef struct psa_mac_operation_s psa_mac_operation_t;
1009
Gilles Peskine7e4acc52018-02-16 21:24:11 +01001010/** The size of the output of psa_mac_finish(), in bytes.
1011 *
1012 * This is also the MAC size that psa_mac_verify() expects.
1013 *
1014 * \param alg A MAC algorithm (\c PSA_ALG_XXX value such that
1015 * #PSA_ALG_IS_MAC(alg) is true).
1016 *
1017 * \return The MAC size for the specified algorithm.
1018 * If the MAC algorithm is not recognized, return 0.
1019 * An implementation may return either 0 or the correct size
1020 * for a MAC algorithm that it recognizes, but does not support.
1021 */
Gilles Peskine8c9def32018-02-08 10:02:12 +01001022#define PSA_MAC_FINAL_SIZE(key_type, key_bits, alg) \
Gilles Peskine71bb7b72018-04-19 08:29:59 +02001023 (PSA_ALG_IS_HMAC(alg) ? PSA_HASH_SIZE(PSA_ALG_HMAC_HASH(alg)) : \
Gilles Peskine8c9def32018-02-08 10:02:12 +01001024 PSA_ALG_IS_BLOCK_CIPHER_MAC(alg) ? PSA_BLOCK_CIPHER_BLOCK_SIZE(key_type) : \
1025 0)
1026
Gilles Peskine7e4acc52018-02-16 21:24:11 +01001027/** Start a multipart MAC operation.
1028 *
1029 * The sequence of operations to calculate a MAC (message authentication code)
1030 * is as follows:
1031 * -# Allocate an operation object which will be passed to all the functions
1032 * listed here.
1033 * -# Call psa_mac_start() to specify the algorithm and key.
1034 * The key remains associated with the operation even if the content
1035 * of the key slot changes.
1036 * -# Call psa_mac_update() zero, one or more times, passing a fragment
1037 * of the message each time. The MAC that is calculated is the MAC
1038 * of the concatenation of these messages in order.
1039 * -# To calculate the MAC, call psa_mac_finish().
1040 * To compare the MAC with an expected value, call psa_mac_verify().
1041 *
1042 * The application may call psa_mac_abort() at any time after the operation
1043 * has been initialized with psa_mac_start().
1044 *
1045 * After a successful call to psa_mac_start(), the application must
Gilles Peskineed522972018-03-20 17:54:15 +01001046 * eventually terminate the operation. The following events terminate an
1047 * operation:
Gilles Peskine7e4acc52018-02-16 21:24:11 +01001048 * - A failed call to psa_mac_update().
Gilles Peskine19067982018-03-20 17:54:53 +01001049 * - A call to psa_mac_finish(), psa_mac_verify() or psa_mac_abort().
Gilles Peskine7e4acc52018-02-16 21:24:11 +01001050 *
1051 * \param operation
1052 * \param alg The MAC algorithm to compute (\c PSA_ALG_XXX value
1053 * such that #PSA_ALG_IS_MAC(alg) is true).
1054 *
1055 * \retval PSA_SUCCESS
1056 * Success.
1057 * \retval PSA_ERROR_EMPTY_SLOT
Gilles Peskine92b30732018-03-03 21:29:30 +01001058 * \retval PSA_ERROR_NOT_PERMITTED
Gilles Peskine7e4acc52018-02-16 21:24:11 +01001059 * \retval PSA_ERROR_INVALID_ARGUMENT
1060 * \c key is not compatible with \c alg.
1061 * \retval PSA_ERROR_NOT_SUPPORTED
1062 * \c alg is not supported or is not a MAC algorithm.
1063 * \retval PSA_ERROR_INSUFFICIENT_MEMORY
1064 * \retval PSA_ERROR_COMMUNICATION_FAILURE
1065 * \retval PSA_ERROR_HARDWARE_FAILURE
1066 * \retval PSA_ERROR_TAMPERING_DETECTED
1067 */
Gilles Peskine8c9def32018-02-08 10:02:12 +01001068psa_status_t psa_mac_start(psa_mac_operation_t *operation,
1069 psa_key_slot_t key,
1070 psa_algorithm_t alg);
1071
1072psa_status_t psa_mac_update(psa_mac_operation_t *operation,
1073 const uint8_t *input,
1074 size_t input_length);
1075
1076psa_status_t psa_mac_finish(psa_mac_operation_t *operation,
1077 uint8_t *mac,
1078 size_t mac_size,
1079 size_t *mac_length);
1080
1081psa_status_t psa_mac_verify(psa_mac_operation_t *operation,
1082 const uint8_t *mac,
1083 size_t mac_length);
1084
1085psa_status_t psa_mac_abort(psa_mac_operation_t *operation);
1086
1087/**@}*/
1088
Gilles Peskine428dc5a2018-03-03 21:27:18 +01001089/** \defgroup cipher Symmetric ciphers
1090 * @{
1091 */
1092
1093/** The type of the state data structure for multipart cipher operations.
1094 *
1095 * This is an implementation-defined \c struct. Applications should not
1096 * make any assumptions about the content of this structure except
1097 * as directed by the documentation of a specific implementation. */
1098typedef struct psa_cipher_operation_s psa_cipher_operation_t;
1099
1100/** Set the key for a multipart symmetric encryption operation.
1101 *
1102 * The sequence of operations to encrypt a message with a symmetric cipher
1103 * is as follows:
1104 * -# Allocate an operation object which will be passed to all the functions
1105 * listed here.
1106 * -# Call psa_encrypt_setup() to specify the algorithm and key.
1107 * The key remains associated with the operation even if the content
1108 * of the key slot changes.
1109 * -# Call either psa_encrypt_generate_iv() or psa_encrypt_set_iv() to
1110 * generate or set the IV (initialization vector). You should use
1111 * psa_encrypt_generate_iv() unless the protocol you are implementing
1112 * requires a specific IV value.
1113 * -# Call psa_cipher_update() zero, one or more times, passing a fragment
1114 * of the message each time.
1115 * -# Call psa_cipher_finish().
1116 *
1117 * The application may call psa_cipher_abort() at any time after the operation
1118 * has been initialized with psa_encrypt_setup().
1119 *
1120 * After a successful call to psa_encrypt_setup(), the application must
Gilles Peskineed522972018-03-20 17:54:15 +01001121 * eventually terminate the operation. The following events terminate an
1122 * operation:
Gilles Peskine428dc5a2018-03-03 21:27:18 +01001123 * - A failed call to psa_encrypt_generate_iv(), psa_encrypt_set_iv()
1124 * or psa_cipher_update().
Gilles Peskine19067982018-03-20 17:54:53 +01001125 * - A call to psa_cipher_finish() or psa_cipher_abort().
Gilles Peskine428dc5a2018-03-03 21:27:18 +01001126 *
1127 * \param operation
1128 * \param alg The cipher algorithm to compute (\c PSA_ALG_XXX value
1129 * such that #PSA_ALG_IS_CIPHER(alg) is true).
1130 *
1131 * \retval PSA_SUCCESS
1132 * Success.
1133 * \retval PSA_ERROR_EMPTY_SLOT
1134 * \retval PSA_ERROR_NOT_PERMITTED
1135 * \retval PSA_ERROR_INVALID_ARGUMENT
1136 * \c key is not compatible with \c alg.
1137 * \retval PSA_ERROR_NOT_SUPPORTED
1138 * \c alg is not supported or is not a cipher algorithm.
1139 * \retval PSA_ERROR_INSUFFICIENT_MEMORY
1140 * \retval PSA_ERROR_COMMUNICATION_FAILURE
1141 * \retval PSA_ERROR_HARDWARE_FAILURE
1142 * \retval PSA_ERROR_TAMPERING_DETECTED
1143 */
1144psa_status_t psa_encrypt_setup(psa_cipher_operation_t *operation,
1145 psa_key_slot_t key,
1146 psa_algorithm_t alg);
1147
1148/** Set the key for a multipart symmetric decryption operation.
1149 *
1150 * The sequence of operations to decrypt a message with a symmetric cipher
1151 * is as follows:
1152 * -# Allocate an operation object which will be passed to all the functions
1153 * listed here.
1154 * -# Call psa_decrypt_setup() to specify the algorithm and key.
1155 * The key remains associated with the operation even if the content
1156 * of the key slot changes.
1157 * -# Call psa_cipher_update() with the IV (initialization vector) for the
1158 * decryption. If the IV is prepended to the ciphertext, you can call
1159 * psa_cipher_update() on a buffer containing the IV followed by the
1160 * beginning of the message.
1161 * -# Call psa_cipher_update() zero, one or more times, passing a fragment
1162 * of the message each time.
1163 * -# Call psa_cipher_finish().
1164 *
1165 * The application may call psa_cipher_abort() at any time after the operation
1166 * has been initialized with psa_encrypt_setup().
1167 *
1168 * After a successful call to psa_decrypt_setup(), the application must
Gilles Peskineed522972018-03-20 17:54:15 +01001169 * eventually terminate the operation. The following events terminate an
1170 * operation:
Gilles Peskine428dc5a2018-03-03 21:27:18 +01001171 * - A failed call to psa_cipher_update().
Gilles Peskine19067982018-03-20 17:54:53 +01001172 * - A call to psa_cipher_finish() or psa_cipher_abort().
Gilles Peskine428dc5a2018-03-03 21:27:18 +01001173 *
1174 * \param operation
1175 * \param alg The cipher algorithm to compute (\c PSA_ALG_XXX value
1176 * such that #PSA_ALG_IS_CIPHER(alg) is true).
1177 *
1178 * \retval PSA_SUCCESS
1179 * Success.
1180 * \retval PSA_ERROR_EMPTY_SLOT
1181 * \retval PSA_ERROR_NOT_PERMITTED
1182 * \retval PSA_ERROR_INVALID_ARGUMENT
1183 * \c key is not compatible with \c alg.
1184 * \retval PSA_ERROR_NOT_SUPPORTED
1185 * \c alg is not supported or is not a cipher algorithm.
1186 * \retval PSA_ERROR_INSUFFICIENT_MEMORY
1187 * \retval PSA_ERROR_COMMUNICATION_FAILURE
1188 * \retval PSA_ERROR_HARDWARE_FAILURE
1189 * \retval PSA_ERROR_TAMPERING_DETECTED
1190 */
1191psa_status_t psa_decrypt_setup(psa_cipher_operation_t *operation,
1192 psa_key_slot_t key,
1193 psa_algorithm_t alg);
1194
1195psa_status_t psa_encrypt_generate_iv(psa_cipher_operation_t *operation,
1196 unsigned char *iv,
1197 size_t iv_size,
1198 size_t *iv_length);
1199
1200psa_status_t psa_encrypt_set_iv(psa_cipher_operation_t *operation,
1201 const unsigned char *iv,
1202 size_t iv_length);
1203
1204psa_status_t psa_cipher_update(psa_cipher_operation_t *operation,
1205 const uint8_t *input,
1206 size_t input_length);
1207
1208psa_status_t psa_cipher_finish(psa_cipher_operation_t *operation,
1209 uint8_t *mac,
1210 size_t mac_size,
1211 size_t *mac_length);
1212
1213psa_status_t psa_cipher_abort(psa_cipher_operation_t *operation);
1214
1215/**@}*/
1216
Gilles Peskine3b555712018-03-03 21:27:57 +01001217/** \defgroup aead Authenticated encryption with associated data (AEAD)
1218 * @{
1219 */
1220
1221/** The type of the state data structure for multipart AEAD operations.
1222 *
1223 * This is an implementation-defined \c struct. Applications should not
1224 * make any assumptions about the content of this structure except
1225 * as directed by the documentation of a specific implementation. */
1226typedef struct psa_aead_operation_s psa_aead_operation_t;
1227
1228/** Set the key for a multipart authenticated encryption operation.
1229 *
1230 * The sequence of operations to authenticate-and-encrypt a message
1231 * is as follows:
1232 * -# Allocate an operation object which will be passed to all the functions
1233 * listed here.
1234 * -# Call psa_aead_encrypt_setup() to specify the algorithm and key.
1235 * The key remains associated with the operation even if the content
1236 * of the key slot changes.
1237 * -# Call either psa_aead_generate_iv() or psa_aead_set_iv() to
1238 * generate or set the IV (initialization vector). You should use
1239 * psa_encrypt_generate_iv() unless the protocol you are implementing
1240 * requires a specific IV value.
1241 * -# Call psa_aead_update_ad() to pass the associated data that is
1242 * to be authenticated but not encrypted. You may omit this step if
1243 * there is no associated data.
1244 * -# Call psa_aead_update() zero, one or more times, passing a fragment
1245 * of the data to encrypt each time.
1246 * -# Call psa_aead_finish().
1247 *
1248 * The application may call psa_aead_abort() at any time after the operation
1249 * has been initialized with psa_aead_encrypt_setup().
1250 *
Gilles Peskineed522972018-03-20 17:54:15 +01001251 * After a successful call to psa_aead_encrypt_setup(), the application must
1252 * eventually terminate the operation. The following events terminate an
1253 * operation:
Gilles Peskine3b555712018-03-03 21:27:57 +01001254 * - A failed call to psa_aead_generate_iv(), psa_aead_set_iv(),
1255 * psa_aead_update_ad() or psa_aead_update().
Gilles Peskine19067982018-03-20 17:54:53 +01001256 * - A call to psa_aead_finish() or psa_aead_abort().
Gilles Peskine3b555712018-03-03 21:27:57 +01001257 *
1258 * \param operation
1259 * \param alg The AEAD algorithm to compute (\c PSA_ALG_XXX value
1260 * such that #PSA_ALG_IS_AEAD(alg) is true).
1261 *
1262 * \retval PSA_SUCCESS
1263 * Success.
1264 * \retval PSA_ERROR_EMPTY_SLOT
1265 * \retval PSA_ERROR_NOT_PERMITTED
1266 * \retval PSA_ERROR_INVALID_ARGUMENT
1267 * \c key is not compatible with \c alg.
1268 * \retval PSA_ERROR_NOT_SUPPORTED
1269 * \c alg is not supported or is not an AEAD algorithm.
1270 * \retval PSA_ERROR_INSUFFICIENT_MEMORY
1271 * \retval PSA_ERROR_COMMUNICATION_FAILURE
1272 * \retval PSA_ERROR_HARDWARE_FAILURE
1273 * \retval PSA_ERROR_TAMPERING_DETECTED
1274 */
1275psa_status_t psa_aead_encrypt_setup(psa_aead_operation_t *operation,
1276 psa_key_slot_t key,
1277 psa_algorithm_t alg);
1278
1279/** Set the key for a multipart authenticated decryption operation.
1280 *
1281 * The sequence of operations to authenticated and decrypt a message
1282 * is as follows:
1283 * -# Allocate an operation object which will be passed to all the functions
1284 * listed here.
1285 * -# Call psa_aead_decrypt_setup() to specify the algorithm and key.
1286 * The key remains associated with the operation even if the content
1287 * of the key slot changes.
1288 * -# Call psa_aead_set_iv() to pass the initialization vector (IV)
1289 * for the authenticated decryption.
1290 * -# Call psa_aead_update_ad() to pass the associated data that is
1291 * to be authenticated but not encrypted. You may omit this step if
1292 * there is no associated data.
1293 * -# Call psa_aead_update() zero, one or more times, passing a fragment
1294 * of the data to decrypt each time.
1295 * -# Call psa_aead_finish().
1296 *
1297 * The application may call psa_aead_abort() at any time after the operation
1298 * has been initialized with psa_aead_decrypt_setup().
1299 *
Gilles Peskineed522972018-03-20 17:54:15 +01001300 * After a successful call to psa_aead_decrypt_setup(), the application must
1301 * eventually terminate the operation. The following events terminate an
1302 * operation:
Gilles Peskine3b555712018-03-03 21:27:57 +01001303 * - A failed call to psa_aead_update().
Gilles Peskine19067982018-03-20 17:54:53 +01001304 * - A call to psa_aead_finish() or psa_aead_abort().
Gilles Peskine3b555712018-03-03 21:27:57 +01001305 *
1306 * \param operation
Gilles Peskine19067982018-03-20 17:54:53 +01001307 * \param alg The AEAD algorithm to compute (\c PSA_ALG_XXX value
1308 * such that #PSA_ALG_IS_AEAD(alg) is true).
Gilles Peskine3b555712018-03-03 21:27:57 +01001309 *
1310 * \retval PSA_SUCCESS
1311 * Success.
1312 * \retval PSA_ERROR_EMPTY_SLOT
1313 * \retval PSA_ERROR_NOT_PERMITTED
1314 * \retval PSA_ERROR_INVALID_ARGUMENT
1315 * \c key is not compatible with \c alg.
1316 * \retval PSA_ERROR_NOT_SUPPORTED
Gilles Peskine19067982018-03-20 17:54:53 +01001317 * \c alg is not supported or is not an AEAD algorithm.
Gilles Peskine3b555712018-03-03 21:27:57 +01001318 * \retval PSA_ERROR_INSUFFICIENT_MEMORY
1319 * \retval PSA_ERROR_COMMUNICATION_FAILURE
1320 * \retval PSA_ERROR_HARDWARE_FAILURE
1321 * \retval PSA_ERROR_TAMPERING_DETECTED
1322 */
1323psa_status_t psa_aead_decrypt_setup(psa_aead_operation_t *operation,
1324 psa_key_slot_t key,
1325 psa_algorithm_t alg);
1326
1327psa_status_t psa_aead_generate_iv(psa_aead_operation_t *operation,
1328 unsigned char *iv,
1329 size_t iv_size,
1330 size_t *iv_length);
1331
1332psa_status_t psa_aead_set_iv(psa_aead_operation_t *operation,
1333 const unsigned char *iv,
1334 size_t iv_length);
1335
1336psa_status_t psa_aead_update_ad(psa_aead_operation_t *operation,
1337 const uint8_t *input,
1338 size_t input_length);
1339
1340psa_status_t psa_aead_update(psa_aead_operation_t *operation,
1341 const uint8_t *input,
1342 size_t input_length);
1343
1344psa_status_t psa_aead_finish(psa_aead_operation_t *operation,
1345 uint8_t *tag,
1346 size_t tag_size,
1347 size_t *tag_length);
1348
1349psa_status_t psa_aead_verify(psa_aead_operation_t *operation,
1350 uint8_t *tag,
1351 size_t tag_length);
1352
1353psa_status_t psa_aead_abort(psa_aead_operation_t *operation);
1354
1355/**@}*/
1356
Gilles Peskine20035e32018-02-03 22:44:14 +01001357/** \defgroup asymmetric Asymmetric cryptography
1358 * @{
1359 */
1360
1361/**
Gilles Peskine0189e752018-02-03 23:57:22 +01001362 * \brief Maximum ECDSA signature size for a given curve bit size
1363 *
1364 * \param curve_bits Curve size in bits
1365 * \return Maximum signature size in bytes
1366 *
1367 * \note This macro returns a compile-time constant if its argument is one.
1368 *
1369 * \warning This macro may evaluate its argument multiple times.
1370 */
1371/*
1372 * RFC 4492 page 20:
1373 *
1374 * Ecdsa-Sig-Value ::= SEQUENCE {
1375 * r INTEGER,
1376 * s INTEGER
1377 * }
1378 *
1379 * Size is at most
1380 * 1 (tag) + 1 (len) + 1 (initial 0) + curve_bytes for each of r and s,
1381 * twice that + 1 (tag) + 2 (len) for the sequence
1382 * (assuming curve_bytes is less than 126 for r and s,
1383 * and less than 124 (total len <= 255) for the sequence)
1384 */
1385#define PSA_ECDSA_SIGNATURE_SIZE(curve_bits) \
1386 ( /*T,L of SEQUENCE*/ ((curve_bits) >= 61 * 8 ? 3 : 2) + \
1387 /*T,L of r,s*/ 2 * (((curve_bits) >= 127 * 8 ? 3 : 2) + \
1388 /*V of r,s*/ ((curve_bits) + 8) / 8))
1389
1390
Gilles Peskine308b91d2018-02-08 09:47:44 +01001391/** Safe signature buffer size for psa_asymmetric_sign().
1392 *
1393 * This macro returns a safe buffer size for a signature using a key
1394 * of the specified type and size, with the specified algorithm.
1395 * Note that the actual size of the signature may be smaller
1396 * (some algorithms produce a variable-size signature).
1397 *
1398 * \warning This function may call its arguments multiple times or
1399 * zero times, so you should not pass arguments that contain
1400 * side effects.
1401 *
1402 * \param key_type An asymmetric key type (this may indifferently be a
1403 * key pair type or a public key type).
1404 * \param key_bits The size of the key in bits.
1405 * \param alg The signature algorithm.
1406 *
1407 * \return If the parameters are valid and supported, return
1408 * a buffer size in bytes that guarantees that
1409 * psa_asymmetric_sign() will not fail with
1410 * #PSA_ERROR_BUFFER_TOO_SMALL.
1411 * If the parameters are a valid combination that is not supported
1412 * by the implementation, this macro either shall return either a
1413 * sensible size or 0.
1414 * If the parameters are not valid, the
1415 * return value is unspecified.
1416 *
1417 */
Gilles Peskine0189e752018-02-03 23:57:22 +01001418#define PSA_ASYMMETRIC_SIGN_OUTPUT_SIZE(key_type, key_bits, alg) \
Gilles Peskine2905a7a2018-03-07 16:39:31 +01001419 (PSA_KEY_TYPE_IS_RSA(key_type) ? ((void)alg, PSA_BITS_TO_BYTES(key_bits)) : \
Gilles Peskine0189e752018-02-03 23:57:22 +01001420 PSA_KEY_TYPE_IS_ECC(key_type) ? PSA_ECDSA_SIGNATURE_SIZE(key_bits) : \
Gilles Peskine84845652018-03-28 14:17:40 +02001421 ((void)alg, 0))
Gilles Peskine0189e752018-02-03 23:57:22 +01001422
1423/**
Gilles Peskine20035e32018-02-03 22:44:14 +01001424 * \brief Sign a hash or short message with a private key.
1425 *
Gilles Peskine308b91d2018-02-08 09:47:44 +01001426 * \param key Key slot containing an asymmetric key pair.
1427 * \param alg A signature algorithm that is compatible with
1428 * the type of \c key.
1429 * \param hash The message to sign.
1430 * \param hash_length Size of the \c hash buffer in bytes.
1431 * \param salt A salt or label, if supported by the signature
1432 * algorithm.
1433 * If the signature algorithm does not support a
1434 * salt, pass \c NULL.
1435 * If the signature algorithm supports an optional
1436 * salt and you do not want to pass a salt,
1437 * pass \c NULL.
1438 * \param salt_length Size of the \c salt buffer in bytes.
1439 * If \c salt is \c NULL, pass 0.
1440 * \param signature Buffer where the signature is to be written.
1441 * \param signature_size Size of the \c signature buffer in bytes.
1442 * \param signature_length On success, the number of bytes
1443 * that make up the returned signature value.
Gilles Peskine308b91d2018-02-08 09:47:44 +01001444 *
1445 * \retval PSA_SUCCESS
1446 * \retval PSA_ERROR_BUFFER_TOO_SMALL
1447 * The size of the \c signature buffer is too small. You can
1448 * determine a sufficient buffer size by calling
1449 * #PSA_ASYMMETRIC_SIGN_OUTPUT_SIZE(key_type, key_bits, alg)
1450 * where \c key_type and \c key_bits are the type and bit-size
1451 * respectively of \c key.
1452 * \retval PSA_ERROR_NOT_SUPPORTED
1453 * \retval PSA_ERROR_INVALID_ARGUMENT
1454 * \retval PSA_ERROR_INSUFFICIENT_MEMORY
1455 * \retval PSA_ERROR_COMMUNICATION_FAILURE
1456 * \retval PSA_ERROR_HARDWARE_FAILURE
1457 * \retval PSA_ERROR_TAMPERING_DETECTED
1458 * \retval PSA_ERROR_INSUFFICIENT_ENTROPY
Gilles Peskine20035e32018-02-03 22:44:14 +01001459 */
1460psa_status_t psa_asymmetric_sign(psa_key_slot_t key,
1461 psa_algorithm_t alg,
1462 const uint8_t *hash,
1463 size_t hash_length,
1464 const uint8_t *salt,
1465 size_t salt_length,
1466 uint8_t *signature,
1467 size_t signature_size,
1468 size_t *signature_length);
1469
1470/**
1471 * \brief Verify the signature a hash or short message using a public key.
1472 *
Gilles Peskine308b91d2018-02-08 09:47:44 +01001473 * \param key Key slot containing a public key or an
1474 * asymmetric key pair.
1475 * \param alg A signature algorithm that is compatible with
1476 * the type of \c key.
1477 * \param hash The message whose signature is to be verified.
1478 * \param hash_length Size of the \c hash buffer in bytes.
1479 * \param salt A salt or label, if supported by the signature
1480 * algorithm.
1481 * If the signature algorithm does not support a
1482 * salt, pass \c NULL.
1483 * If the signature algorithm supports an optional
1484 * salt and you do not want to pass a salt,
1485 * pass \c NULL.
1486 * \param salt_length Size of the \c salt buffer in bytes.
1487 * If \c salt is \c NULL, pass 0.
1488 * \param signature Buffer containing the signature to verify.
1489 * \param signature_size Size of the \c signature buffer in bytes.
1490 *
1491 * \retval PSA_SUCCESS
1492 * The signature is valid.
1493 * \retval PSA_ERROR_INVALID_SIGNATURE
1494 * The calculation was perfomed successfully, but the passed
1495 * signature is not a valid signature.
1496 * \retval PSA_ERROR_NOT_SUPPORTED
1497 * \retval PSA_ERROR_INVALID_ARGUMENT
1498 * \retval PSA_ERROR_INSUFFICIENT_MEMORY
1499 * \retval PSA_ERROR_COMMUNICATION_FAILURE
1500 * \retval PSA_ERROR_HARDWARE_FAILURE
1501 * \retval PSA_ERROR_TAMPERING_DETECTED
Gilles Peskine20035e32018-02-03 22:44:14 +01001502 */
1503psa_status_t psa_asymmetric_verify(psa_key_slot_t key,
1504 psa_algorithm_t alg,
1505 const uint8_t *hash,
1506 size_t hash_length,
1507 const uint8_t *salt,
1508 size_t salt_length,
1509 uint8_t *signature,
1510 size_t signature_size);
1511
Gilles Peskine6944f9a2018-03-28 14:18:39 +02001512#define PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(key_type, key_bits, alg) \
1513 (PSA_KEY_TYPE_IS_RSA(key_type) ? ((void)alg, PSA_BITS_TO_BYTES(key_bits)) : \
1514 ((void)alg, 0))
1515#define PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE(key_type, key_bits, alg) \
1516 PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(key_type, key_bits, alg)
1517
1518/**
1519 * \brief Encrypt a short message with a public key.
1520 *
1521 * \param key Key slot containing a public key or an asymmetric
1522 * key pair.
1523 * \param alg An asymmetric encryption algorithm that is
1524 * compatible with the type of \c key.
1525 * \param input The message to encrypt.
1526 * \param input_length Size of the \c input buffer in bytes.
1527 * \param salt A salt or label, if supported by the encryption
1528 * algorithm.
1529 * If the algorithm does not support a
1530 * salt, pass \c NULL.
1531 * If the algorithm supports an optional
1532 * salt and you do not want to pass a salt,
1533 * pass \c NULL.
1534 *
1535 * - For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is
1536 * supported.
1537 * \param salt_length Size of the \c salt buffer in bytes.
1538 * If \c salt is \c NULL, pass 0.
1539 * \param output Buffer where the encrypted message is to be written.
1540 * \param output_size Size of the \c output buffer in bytes.
1541 * \param output_length On success, the number of bytes
1542 * that make up the returned output.
1543 *
1544 * \retval PSA_SUCCESS
1545 * \retval PSA_ERROR_BUFFER_TOO_SMALL
1546 * The size of the \c output buffer is too small. You can
1547 * determine a sufficient buffer size by calling
1548 * #PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(key_type, key_bits, alg)
1549 * where \c key_type and \c key_bits are the type and bit-size
1550 * respectively of \c key.
1551 * \retval PSA_ERROR_NOT_SUPPORTED
1552 * \retval PSA_ERROR_INVALID_ARGUMENT
1553 * \retval PSA_ERROR_INSUFFICIENT_MEMORY
1554 * \retval PSA_ERROR_COMMUNICATION_FAILURE
1555 * \retval PSA_ERROR_HARDWARE_FAILURE
1556 * \retval PSA_ERROR_TAMPERING_DETECTED
1557 * \retval PSA_ERROR_INSUFFICIENT_ENTROPY
1558 */
1559psa_status_t psa_asymmetric_encrypt(psa_key_slot_t key,
1560 psa_algorithm_t alg,
1561 const uint8_t *input,
1562 size_t input_length,
1563 const uint8_t *salt,
1564 size_t salt_length,
1565 uint8_t *output,
1566 size_t output_size,
1567 size_t *output_length);
1568
1569/**
1570 * \brief Decrypt a short message with a private key.
1571 *
1572 * \param key Key slot containing an asymmetric key pair.
1573 * \param alg An asymmetric encryption algorithm that is
1574 * compatible with the type of \c key.
1575 * \param input The message to decrypt.
1576 * \param input_length Size of the \c input buffer in bytes.
1577 * \param salt A salt or label, if supported by the encryption
1578 * algorithm.
1579 * If the algorithm does not support a
1580 * salt, pass \c NULL.
1581 * If the algorithm supports an optional
1582 * salt and you do not want to pass a salt,
1583 * pass \c NULL.
1584 *
1585 * - For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is
1586 * supported.
1587 * \param salt_length Size of the \c salt buffer in bytes.
1588 * If \c salt is \c NULL, pass 0.
Gilles Peskinef48af7f2018-03-28 18:44:14 +02001589 * \param output Buffer where the decrypted message is to be written.
Gilles Peskine6944f9a2018-03-28 14:18:39 +02001590 * \param output_size Size of the \c output buffer in bytes.
1591 * \param output_length On success, the number of bytes
1592 * that make up the returned output.
1593 *
1594 * \retval PSA_SUCCESS
1595 * \retval PSA_ERROR_BUFFER_TOO_SMALL
1596 * The size of the \c output buffer is too small. You can
1597 * determine a sufficient buffer size by calling
1598 * #PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE(key_type, key_bits, alg)
1599 * where \c key_type and \c key_bits are the type and bit-size
1600 * respectively of \c key.
1601 * \retval PSA_ERROR_NOT_SUPPORTED
1602 * \retval PSA_ERROR_INVALID_ARGUMENT
1603 * \retval PSA_ERROR_INSUFFICIENT_MEMORY
1604 * \retval PSA_ERROR_COMMUNICATION_FAILURE
1605 * \retval PSA_ERROR_HARDWARE_FAILURE
1606 * \retval PSA_ERROR_TAMPERING_DETECTED
1607 * \retval PSA_ERROR_INSUFFICIENT_ENTROPY
1608 * \retval PSA_ERROR_INVALID_PADDING
1609 */
1610psa_status_t psa_asymmetric_decrypt(psa_key_slot_t key,
1611 psa_algorithm_t alg,
1612 const uint8_t *input,
1613 size_t input_length,
1614 const uint8_t *salt,
1615 size_t salt_length,
1616 uint8_t *output,
1617 size_t output_size,
1618 size_t *output_length);
1619
Gilles Peskine2f9c4dc2018-01-28 13:16:24 +01001620/**@}*/
1621
Gilles Peskine9e7dc712018-03-28 14:18:50 +02001622/** \defgroup generation Key generation
1623 * @{
1624 */
1625
1626/**
1627 * \brief Generate random bytes.
1628 *
1629 * \warning This function **can** fail! Callers MUST check the return status
1630 * and MUST NOT use the content of the output buffer if the return
1631 * status is not #PSA_SUCCESS.
1632 *
1633 * \note To generate a key, use psa_generate_key() instead.
1634 *
1635 * \param output Output buffer for the generated data.
1636 * \param output_size Number of bytes to generate and output.
1637 *
1638 * \retval PSA_SUCCESS
1639 * \retval PSA_ERROR_NOT_SUPPORTED
1640 * \retval PSA_ERROR_INSUFFICIENT_ENTROPY
1641 * \retval PSA_ERROR_COMMUNICATION_FAILURE
1642 * \retval PSA_ERROR_HARDWARE_FAILURE
1643 * \retval PSA_ERROR_TAMPERING_DETECTED
1644 */
1645psa_status_t psa_generate_random(uint8_t *output,
1646 size_t output_size);
1647
1648/**
1649 * \brief Generate a key or key pair.
1650 *
1651 * \param key Slot where the key will be stored. This must be a
1652 * valid slot for a key of the chosen type. It must
1653 * be unoccupied.
1654 * \param type Key type (a \c PSA_KEY_TYPE_XXX value).
1655 * \param bits Key size in bits.
1656 * \param parameters Extra parameters for key generation. The interpretation
1657 * of this parameter depends on \c type. All types support
1658 * \c NULL to use default parameters specified below.
1659 *
1660 * For any symmetric key type (type such that
1661 * `PSA_KEY_TYPE_IS_ASYMMETRIC(type)` is false), \c parameters must be
1662 * \c NULL. For asymmetric key types defined by this specification,
1663 * the parameter type and the default parameters are defined by the
1664 * table below. For vendor-defined key types, the vendor documentation
1665 * shall define the parameter type and the default parameters.
1666 *
Gilles Peskinef48af7f2018-03-28 18:44:14 +02001667 * Type | Parameter type | Meaning | Parameters used if `parameters == NULL`
1668 * ---- | -------------- | ------- | ---------------------------------------
1669 * `PSA_KEY_TYPE_RSA_KEYPAIR` | `unsigned int` | Public exponent | 65537
Gilles Peskine9e7dc712018-03-28 14:18:50 +02001670 *
1671 * \retval PSA_SUCCESS
1672 * \retval PSA_ERROR_NOT_SUPPORTED
1673 * \retval PSA_ERROR_INVALID_ARGUMENT
1674 * \retval PSA_ERROR_INSUFFICIENT_MEMORY
1675 * \retval PSA_ERROR_INSUFFICIENT_ENTROPY
1676 * \retval PSA_ERROR_COMMUNICATION_FAILURE
1677 * \retval PSA_ERROR_HARDWARE_FAILURE
1678 * \retval PSA_ERROR_TAMPERING_DETECTED
1679 */
1680psa_status_t psa_generate_key(psa_key_slot_t key,
1681 psa_key_type_t type,
1682 size_t bits,
1683 const void *parameters);
1684
1685/**@}*/
1686
Gilles Peskinee59236f2018-01-27 23:32:46 +01001687#ifdef __cplusplus
1688}
1689#endif
1690
Gilles Peskine9ef733f2018-02-07 21:05:37 +01001691/* The file "crypto_struct.h" contains definitions for
1692 * implementation-specific structs that are declared above. */
1693#include "crypto_struct.h"
1694
1695/* The file "crypto_extra.h" contains vendor-specific definitions. This
1696 * can include vendor-defined algorithms, extra functions, etc. */
Gilles Peskinee59236f2018-01-27 23:32:46 +01001697#include "crypto_extra.h"
1698
1699#endif /* PSA_CRYPTO_H */