Gilles Peskine | e59236f | 2018-01-27 23:32:46 +0100 | [diff] [blame] | 1 | /** |
| 2 | * \file psa/crypto.h |
| 3 | * \brief Platform Security Architecture cryptography module |
| 4 | */ |
Jaeden Amero | cab5494 | 2018-07-25 13:26:13 +0100 | [diff] [blame] | 5 | /* |
| 6 | * Copyright (C) 2018, ARM Limited, All Rights Reserved |
| 7 | * SPDX-License-Identifier: Apache-2.0 |
| 8 | * |
| 9 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 10 | * not use this file except in compliance with the License. |
| 11 | * You may obtain a copy of the License at |
| 12 | * |
| 13 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | * |
| 15 | * Unless required by applicable law or agreed to in writing, software |
| 16 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 17 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | * See the License for the specific language governing permissions and |
| 19 | * limitations under the License. |
| 20 | */ |
Gilles Peskine | e59236f | 2018-01-27 23:32:46 +0100 | [diff] [blame] | 21 | |
| 22 | #ifndef PSA_CRYPTO_H |
| 23 | #define PSA_CRYPTO_H |
| 24 | |
| 25 | #include "crypto_platform.h" |
| 26 | |
Gilles Peskine | 2f9c4dc | 2018-01-28 13:16:24 +0100 | [diff] [blame] | 27 | #include <stddef.h> |
| 28 | |
Gilles Peskine | 62a7e7e | 2018-02-07 21:54:47 +0100 | [diff] [blame] | 29 | #ifdef __DOXYGEN_ONLY__ |
Gilles Peskine | f5b9fa1 | 2018-03-07 16:40:18 +0100 | [diff] [blame] | 30 | /* This __DOXYGEN_ONLY__ block contains mock definitions for things that |
| 31 | * must be defined in the crypto_platform.h header. These mock definitions |
| 32 | * are present in this file as a convenience to generate pretty-printed |
| 33 | * documentation that includes those definitions. */ |
| 34 | |
Gilles Peskine | 62a7e7e | 2018-02-07 21:54:47 +0100 | [diff] [blame] | 35 | /** \defgroup platform Implementation-specific definitions |
| 36 | * @{ |
| 37 | */ |
| 38 | |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 39 | /** \brief Key handle. |
Gilles Peskine | 2f9c4dc | 2018-01-28 13:16:24 +0100 | [diff] [blame] | 40 | * |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 41 | * This type represents open handles to keys. It must be an unsigned integral |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 42 | * type. The choice of type is implementation-dependent. |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 43 | * |
Gilles Peskine | 23fd2bd | 2018-12-11 15:51:32 +0100 | [diff] [blame] | 44 | * 0 is not a valid key handle. How other handle values are assigned is |
| 45 | * implementation-dependent. |
Gilles Peskine | 2f9c4dc | 2018-01-28 13:16:24 +0100 | [diff] [blame] | 46 | */ |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 47 | typedef _unsigned_integral_type_ psa_key_handle_t; |
Gilles Peskine | 2f9c4dc | 2018-01-28 13:16:24 +0100 | [diff] [blame] | 48 | |
Gilles Peskine | 62a7e7e | 2018-02-07 21:54:47 +0100 | [diff] [blame] | 49 | /**@}*/ |
Gilles Peskine | f5b9fa1 | 2018-03-07 16:40:18 +0100 | [diff] [blame] | 50 | #endif /* __DOXYGEN_ONLY__ */ |
Gilles Peskine | 62a7e7e | 2018-02-07 21:54:47 +0100 | [diff] [blame] | 51 | |
Gilles Peskine | e59236f | 2018-01-27 23:32:46 +0100 | [diff] [blame] | 52 | #ifdef __cplusplus |
| 53 | extern "C" { |
| 54 | #endif |
| 55 | |
Gilles Peskine | f3b731e | 2018-12-12 13:38:31 +0100 | [diff] [blame] | 56 | /* The file "crypto_types.h" declares types that encode errors, |
| 57 | * algorithms, key types, policies, etc. */ |
| 58 | #include "crypto_types.h" |
| 59 | |
| 60 | /* The file "crypto_values.h" declares macros to build and analyze values |
| 61 | * of integral types defined in "crypto_types.h". */ |
| 62 | #include "crypto_values.h" |
| 63 | |
| 64 | /** \defgroup initialization Library initialization |
Gilles Peskine | e59236f | 2018-01-27 23:32:46 +0100 | [diff] [blame] | 65 | * @{ |
| 66 | */ |
| 67 | |
| 68 | /** |
Gilles Peskine | e59236f | 2018-01-27 23:32:46 +0100 | [diff] [blame] | 69 | * \brief Library initialization. |
| 70 | * |
| 71 | * Applications must call this function before calling any other |
| 72 | * function in this module. |
| 73 | * |
| 74 | * Applications may call this function more than once. Once a call |
| 75 | * succeeds, subsequent calls are guaranteed to succeed. |
| 76 | * |
itayzafrir | 1861709 | 2018-09-16 12:22:41 +0300 | [diff] [blame] | 77 | * If the application calls other functions before calling psa_crypto_init(), |
| 78 | * the behavior is undefined. Implementations are encouraged to either perform |
| 79 | * the operation as if the library had been initialized or to return |
| 80 | * #PSA_ERROR_BAD_STATE or some other applicable error. In particular, |
| 81 | * implementations should not return a success status if the lack of |
| 82 | * initialization may have security implications, for example due to improper |
| 83 | * seeding of the random number generator. |
| 84 | * |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 85 | * \retval #PSA_SUCCESS |
| 86 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 87 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 88 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 89 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 90 | * \retval #PSA_ERROR_INSUFFICIENT_ENTROPY |
Gilles Peskine | e59236f | 2018-01-27 23:32:46 +0100 | [diff] [blame] | 91 | */ |
| 92 | psa_status_t psa_crypto_init(void); |
| 93 | |
Gilles Peskine | 2f9c4dc | 2018-01-28 13:16:24 +0100 | [diff] [blame] | 94 | /**@}*/ |
| 95 | |
Gilles Peskine | 87a5e56 | 2019-04-17 12:28:25 +0200 | [diff] [blame] | 96 | /** \defgroup attributes Key attributes |
| 97 | * @{ |
| 98 | */ |
| 99 | |
| 100 | /** The type of a structure containing key attributes. |
| 101 | * |
| 102 | * This is an opaque structure that can represent the metadata of a key |
Gilles Peskine | 9c640f9 | 2019-04-28 11:36:21 +0200 | [diff] [blame] | 103 | * object. Metadata that can be stored in attributes includes: |
| 104 | * - The location of the key in storage, indicated by its key identifier |
| 105 | * and its lifetime. |
| 106 | * - The key's policy, comprising usage flags and a specification of |
| 107 | * the permitted algorithm(s). |
| 108 | * - Information about the key itself: the key type, the key size, and |
| 109 | * for some key type additional domain parameters. |
| 110 | * - Implementations may define additional attributes. |
Gilles Peskine | 87a5e56 | 2019-04-17 12:28:25 +0200 | [diff] [blame] | 111 | * |
| 112 | * The actual key material is not considered an attribute of a key. |
| 113 | * Key attributes do not contain information that is generally considered |
| 114 | * highly confidential. |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 115 | * |
Gilles Peskine | 9c640f9 | 2019-04-28 11:36:21 +0200 | [diff] [blame] | 116 | * An attribute structure can be a simple data structure where each function |
| 117 | * `psa_set_key_xxx` sets a field and the corresponding function |
| 118 | * `psa_get_key_xxx` retrieves the value of the corresponding field. |
| 119 | * However, implementations may report values that are equivalent to the |
| 120 | * original one, but have a different encoding. For example, an |
| 121 | * implementation may use a more compact representation for types where |
| 122 | * many bit-patterns are invalid or not supported, and store all values |
| 123 | * that it does not support as a special marker value. In such an |
| 124 | * implementation, after setting an invalid value, the corresponding |
| 125 | * get function returns an invalid value which may not be the one that |
| 126 | * was originally stored. |
| 127 | * |
| 128 | * An attribute structure may contain references to auxiliary resources, |
| 129 | * for example pointers to allocated memory or indirect references to |
| 130 | * pre-calculated values. In order to free such resources, the application |
| 131 | * must call psa_reset_key_attributes(). As an exception, calling |
| 132 | * psa_reset_key_attributes() on an attribute structure is optional if |
| 133 | * the structure has only been modified by the following functions |
| 134 | * since it was initialized or last reset with psa_reset_key_attributes(): |
| 135 | * - psa_make_key_persistent() |
| 136 | * - psa_set_key_type() |
| 137 | * - psa_set_key_bits() |
| 138 | * - psa_set_key_usage_flags() |
| 139 | * - psa_set_key_algorithm() |
| 140 | * |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 141 | * Before calling any function on a key attribute structure, the application |
| 142 | * must initialize it by any of the following means: |
| 143 | * - Set the structure to all-bits-zero, for example: |
| 144 | * \code |
| 145 | * psa_key_attributes_t attributes; |
| 146 | * memset(&attributes, 0, sizeof(attributes)); |
| 147 | * \endcode |
| 148 | * - Initialize the structure to logical zero values, for example: |
| 149 | * \code |
| 150 | * psa_key_attributes_t attributes = {0}; |
| 151 | * \endcode |
| 152 | * - Initialize the structure to the initializer #PSA_KEY_ATTRIBUTES_INIT, |
| 153 | * for example: |
| 154 | * \code |
| 155 | * psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; |
| 156 | * \endcode |
| 157 | * - Assign the result of the function psa_key_attributes_init() |
| 158 | * to the structure, for example: |
| 159 | * \code |
| 160 | * psa_key_attributes_t attributes; |
| 161 | * attributes = psa_key_attributes_init(); |
| 162 | * \endcode |
| 163 | * |
| 164 | * A freshly initialized attribute structure contains the following |
| 165 | * values: |
| 166 | * |
| 167 | * - lifetime: #PSA_KEY_LIFETIME_VOLATILE. |
| 168 | * - key identifier: unspecified. |
| 169 | * - type: \c 0, with no domain parameters. |
| 170 | * - key size: \c 0. |
| 171 | * - usage flags: \c 0. |
| 172 | * - algorithm: \c 0. |
| 173 | * |
Gilles Peskine | 9c640f9 | 2019-04-28 11:36:21 +0200 | [diff] [blame] | 174 | * A typical sequence to create a key is as follows: |
| 175 | * -# Create and initialize an attribute structure. |
| 176 | * -# If the key is persistent, call psa_make_key_persistent(). |
| 177 | * -# Set the key policy with psa_set_key_usage_flags() and |
| 178 | * psa_set_key_algorithm(). |
| 179 | * -# Set the key type with psa_set_key_type(). If the key type requires |
| 180 | * domain parameters, call psa_set_key_domain_parameters() instead. |
| 181 | * Skip this step if copying an existing key with psa_copy_key(). |
Adrian L. Shaw | 5a5a79a | 2019-05-03 15:44:28 +0100 | [diff] [blame] | 182 | * -# When generating a random key with psa_generate_random_key() or deriving a key |
| 183 | * with psa_generate_derived_key(), set the desired key size with |
Gilles Peskine | 9c640f9 | 2019-04-28 11:36:21 +0200 | [diff] [blame] | 184 | * psa_set_key_bits(). |
Adrian L. Shaw | 5a5a79a | 2019-05-03 15:44:28 +0100 | [diff] [blame] | 185 | * -# Call a key creation function: psa_import_key(), psa_generate_random_key(), |
| 186 | * psa_generate_derived_key() or psa_copy_key(). This function reads |
Gilles Peskine | 1ea5e44 | 2019-05-02 20:31:10 +0200 | [diff] [blame] | 187 | * the attribute structure, creates a key with these attributes, and |
| 188 | * outputs a handle to the newly created key. |
| 189 | * -# The attribute structure is now no longer necessary. If you called |
Gilles Peskine | 9c640f9 | 2019-04-28 11:36:21 +0200 | [diff] [blame] | 190 | * psa_set_key_domain_parameters() earlier, you must call |
| 191 | * psa_reset_key_attributes() to free any resources used by the |
| 192 | * domain parameters. Otherwise calling psa_reset_key_attributes() |
| 193 | * is optional. |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 194 | * |
Gilles Peskine | 9c640f9 | 2019-04-28 11:36:21 +0200 | [diff] [blame] | 195 | * A typical sequence to query a key's attributes is as follows: |
| 196 | * -# Call psa_get_key_attributes(). |
| 197 | * -# Call `psa_get_key_xxx` functions to retrieve the attribute(s) that |
| 198 | * you are interested in. |
| 199 | * -# Call psa_reset_key_attributes() to free any resources that may be |
| 200 | * used by the attribute structure. |
| 201 | * |
| 202 | * Once a key has been created, it is impossible to change its attributes. |
Gilles Peskine | 87a5e56 | 2019-04-17 12:28:25 +0200 | [diff] [blame] | 203 | */ |
| 204 | typedef struct psa_key_attributes_s psa_key_attributes_t; |
| 205 | |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 206 | /** Declare a key as persistent. |
| 207 | * |
| 208 | * This function does not access storage, it merely fills the attribute |
| 209 | * structure with given values. The persistent key will be written to |
| 210 | * storage when the attribute structure is passed to a key creation |
Adrian L. Shaw | 5a5a79a | 2019-05-03 15:44:28 +0100 | [diff] [blame] | 211 | * function such as psa_import_key(), psa_generate_random_key(), |
| 212 | * psa_generate_derived_key() or psa_copy_key(). |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 213 | * |
| 214 | * This function overwrites any identifier and lifetime values |
| 215 | * previously set in \p attributes. |
| 216 | * |
| 217 | * This function may be declared as `static` (i.e. without external |
| 218 | * linkage). This function may be provided as a function-like macro, |
| 219 | * but in this case it must evaluate each of its arguments exactly once. |
| 220 | * |
| 221 | * \param[out] attributes The attribute structure to write to. |
| 222 | * \param id The persistent identifier for the key. |
| 223 | * \param lifetime The lifetime for the key. |
| 224 | * If this is #PSA_KEY_LIFETIME_VOLATILE, the |
| 225 | * key will be volatile, and \p id is ignored. |
| 226 | */ |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 227 | static void psa_make_key_persistent(psa_key_attributes_t *attributes, |
| 228 | psa_key_id_t id, |
| 229 | psa_key_lifetime_t lifetime); |
| 230 | |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 231 | /** Retrieve the key identifier from key attributes. |
| 232 | * |
| 233 | * This function may be declared as `static` (i.e. without external |
| 234 | * linkage). This function may be provided as a function-like macro, |
| 235 | * but in this case it must evaluate its argument exactly once. |
| 236 | * |
| 237 | * \param[in] attributes The key attribute structure to query. |
| 238 | * |
| 239 | * \return The persistent identifier stored in the attribute structure. |
| 240 | * This value is unspecified if the attribute structure declares |
| 241 | * the key as volatile. |
| 242 | */ |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 243 | static psa_key_id_t psa_get_key_id(const psa_key_attributes_t *attributes); |
| 244 | |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 245 | /** Retrieve the lifetime from key attributes. |
| 246 | * |
| 247 | * This function may be declared as `static` (i.e. without external |
| 248 | * linkage). This function may be provided as a function-like macro, |
| 249 | * but in this case it must evaluate its argument exactly once. |
| 250 | * |
| 251 | * \param[in] attributes The key attribute structure to query. |
| 252 | * |
| 253 | * \return The lifetime value stored in the attribute structure. |
| 254 | */ |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 255 | static psa_key_lifetime_t psa_get_key_lifetime( |
| 256 | const psa_key_attributes_t *attributes); |
| 257 | |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 258 | /** Declare usage flags for a key. |
| 259 | * |
| 260 | * Usage flags are part of a key's usage policy. They encode what |
| 261 | * kind of operations are permitted on the key. For more details, |
| 262 | * refer to the documentation of the type #psa_key_usage_t. |
| 263 | * |
| 264 | * This function overwrites any usage flags |
| 265 | * previously set in \p attributes. |
| 266 | * |
| 267 | * This function may be declared as `static` (i.e. without external |
| 268 | * linkage). This function may be provided as a function-like macro, |
| 269 | * but in this case it must evaluate each of its arguments exactly once. |
| 270 | * |
| 271 | * \param[out] attributes The attribute structure to write to. |
| 272 | * \param usage_flags The usage flags to write. |
| 273 | */ |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 274 | static void psa_set_key_usage_flags(psa_key_attributes_t *attributes, |
| 275 | psa_key_usage_t usage_flags); |
| 276 | |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 277 | /** Retrieve the usage flags from key attributes. |
| 278 | * |
| 279 | * This function may be declared as `static` (i.e. without external |
| 280 | * linkage). This function may be provided as a function-like macro, |
| 281 | * but in this case it must evaluate its argument exactly once. |
| 282 | * |
| 283 | * \param[in] attributes The key attribute structure to query. |
| 284 | * |
| 285 | * \return The usage flags stored in the attribute structure. |
| 286 | */ |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 287 | static psa_key_usage_t psa_get_key_usage_flags( |
| 288 | const psa_key_attributes_t *attributes); |
| 289 | |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 290 | /** Declare the permitted algorithm policy for a key. |
| 291 | * |
| 292 | * The permitted algorithm policy of a key encodes which algorithm or |
| 293 | * algorithms are permitted to be used with this key. |
| 294 | * |
| 295 | * This function overwrites any algorithm policy |
| 296 | * previously set in \p attributes. |
| 297 | * |
| 298 | * This function may be declared as `static` (i.e. without external |
| 299 | * linkage). This function may be provided as a function-like macro, |
| 300 | * but in this case it must evaluate each of its arguments exactly once. |
| 301 | * |
| 302 | * \param[out] attributes The attribute structure to write to. |
| 303 | * \param alg The permitted algorithm policy to write. |
| 304 | */ |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 305 | static void psa_set_key_algorithm(psa_key_attributes_t *attributes, |
| 306 | psa_algorithm_t alg); |
| 307 | |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 308 | /** Retrieve the algorithm policy from key attributes. |
| 309 | * |
| 310 | * This function may be declared as `static` (i.e. without external |
| 311 | * linkage). This function may be provided as a function-like macro, |
| 312 | * but in this case it must evaluate its argument exactly once. |
| 313 | * |
| 314 | * \param[in] attributes The key attribute structure to query. |
| 315 | * |
| 316 | * \return The algorithm stored in the attribute structure. |
| 317 | */ |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 318 | static psa_algorithm_t psa_get_key_algorithm( |
| 319 | const psa_key_attributes_t *attributes); |
| 320 | |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 321 | /** Declare the type of a key. |
| 322 | * |
| 323 | * If a type requires domain parameters, you must call |
| 324 | * psa_set_key_domain_parameters() instead of this function. |
| 325 | * |
| 326 | * This function overwrites any key type and domain parameters |
| 327 | * previously set in \p attributes. |
| 328 | * |
| 329 | * This function may be declared as `static` (i.e. without external |
| 330 | * linkage). This function may be provided as a function-like macro, |
| 331 | * but in this case it must evaluate each of its arguments exactly once. |
| 332 | * |
| 333 | * \param[out] attributes The attribute structure to write to. |
| 334 | * \param type The key type to write. |
| 335 | */ |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 336 | static void psa_set_key_type(psa_key_attributes_t *attributes, |
| 337 | psa_key_type_t type); |
| 338 | |
Gilles Peskine | 3a4f1f8 | 2019-04-26 13:49:28 +0200 | [diff] [blame] | 339 | /** Declare the size of a key. |
| 340 | * |
| 341 | * This function overwrites any key size previously set in \p attributes. |
| 342 | * |
| 343 | * This function may be declared as `static` (i.e. without external |
| 344 | * linkage). This function may be provided as a function-like macro, |
| 345 | * but in this case it must evaluate each of its arguments exactly once. |
| 346 | * |
| 347 | * \param[out] attributes The attribute structure to write to. |
| 348 | * \param bits The key size in bits. |
| 349 | */ |
| 350 | static void psa_set_key_bits(psa_key_attributes_t *attributes, |
| 351 | size_t bits); |
| 352 | |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 353 | /** Retrieve the key type from key attributes. |
| 354 | * |
| 355 | * This function may be declared as `static` (i.e. without external |
| 356 | * linkage). This function may be provided as a function-like macro, |
| 357 | * but in this case it must evaluate its argument exactly once. |
| 358 | * |
| 359 | * \param[in] attributes The key attribute structure to query. |
| 360 | * |
| 361 | * \return The key type stored in the attribute structure. |
| 362 | */ |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 363 | static psa_key_type_t psa_get_key_type(const psa_key_attributes_t *attributes); |
| 364 | |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 365 | /** Retrieve the key size from key attributes. |
| 366 | * |
| 367 | * This function may be declared as `static` (i.e. without external |
| 368 | * linkage). This function may be provided as a function-like macro, |
| 369 | * but in this case it must evaluate its argument exactly once. |
| 370 | * |
| 371 | * \param[in] attributes The key attribute structure to query. |
| 372 | * |
| 373 | * \return The key size stored in the attribute structure, in bits. |
| 374 | */ |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 375 | static size_t psa_get_key_bits(const psa_key_attributes_t *attributes); |
| 376 | |
Gilles Peskine | b699f07 | 2019-04-26 16:06:02 +0200 | [diff] [blame] | 377 | /** |
| 378 | * \brief Set domain parameters for a key. |
| 379 | * |
| 380 | * Some key types require additional domain parameters in addition to |
| 381 | * the key type identifier and the key size. |
| 382 | * The format for the required domain parameters varies by the key type. |
| 383 | * |
Gilles Peskine | e56e878 | 2019-04-26 17:34:02 +0200 | [diff] [blame] | 384 | * - For RSA keys (#PSA_KEY_TYPE_RSA_PUBLIC_KEY or #PSA_KEY_TYPE_RSA_KEYPAIR), |
| 385 | * the domain parameter data consists of the public exponent, |
Gilles Peskine | b699f07 | 2019-04-26 16:06:02 +0200 | [diff] [blame] | 386 | * represented as a big-endian integer with no leading zeros. |
Gilles Peskine | e56e878 | 2019-04-26 17:34:02 +0200 | [diff] [blame] | 387 | * This information is used when generating an RSA key pair. |
Gilles Peskine | b699f07 | 2019-04-26 16:06:02 +0200 | [diff] [blame] | 388 | * When importing a key, the public exponent is read from the imported |
| 389 | * key data and the exponent recorded in the attribute structure is ignored. |
Gilles Peskine | e56e878 | 2019-04-26 17:34:02 +0200 | [diff] [blame] | 390 | * As an exception, the public exponent 65537 is represented by an empty |
| 391 | * byte string. |
| 392 | * - For DSA keys (#PSA_KEY_TYPE_DSA_PUBLIC_KEY or #PSA_KEY_TYPE_DSA_KEYPAIR), |
Gilles Peskine | b699f07 | 2019-04-26 16:06:02 +0200 | [diff] [blame] | 393 | * the `Dss-Parms` format as defined by RFC 3279 §2.3.2. |
| 394 | * ``` |
| 395 | * Dss-Parms ::= SEQUENCE { |
| 396 | * p INTEGER, |
| 397 | * q INTEGER, |
| 398 | * g INTEGER |
| 399 | * } |
| 400 | * ``` |
Gilles Peskine | e56e878 | 2019-04-26 17:34:02 +0200 | [diff] [blame] | 401 | * - For Diffie-Hellman key exchange keys (#PSA_KEY_TYPE_DH_PUBLIC_KEY or |
| 402 | * #PSA_KEY_TYPE_DH_KEYPAIR), the |
Gilles Peskine | b699f07 | 2019-04-26 16:06:02 +0200 | [diff] [blame] | 403 | * `DomainParameters` format as defined by RFC 3279 §2.3.3. |
| 404 | * ``` |
| 405 | * DomainParameters ::= SEQUENCE { |
| 406 | * p INTEGER, -- odd prime, p=jq +1 |
| 407 | * g INTEGER, -- generator, g |
| 408 | * q INTEGER, -- factor of p-1 |
| 409 | * j INTEGER OPTIONAL, -- subgroup factor |
| 410 | * validationParms ValidationParms OPTIONAL |
| 411 | * } |
| 412 | * ValidationParms ::= SEQUENCE { |
| 413 | * seed BIT STRING, |
| 414 | * pgenCounter INTEGER |
| 415 | * } |
| 416 | * ``` |
| 417 | * |
Gilles Peskine | 9c640f9 | 2019-04-28 11:36:21 +0200 | [diff] [blame] | 418 | * \note This function may allocate memory or other resources. |
| 419 | * Once you have called this function on an attribute structure, |
| 420 | * you must call psa_reset_key_attributes() to free these resources. |
| 421 | * |
Gilles Peskine | b699f07 | 2019-04-26 16:06:02 +0200 | [diff] [blame] | 422 | * \param[in,out] attributes Attribute structure where the specified domain |
| 423 | * parameters will be stored. |
| 424 | * If this function fails, the content of |
| 425 | * \p attributes is not modified. |
| 426 | * \param type Key type (a \c PSA_KEY_TYPE_XXX value). |
| 427 | * \param[in] data Buffer containing the key domain parameters. |
| 428 | * The content of this buffer is interpreted |
| 429 | * according to \p type as described above. |
| 430 | * \param data_length Size of the \p data buffer in bytes. |
| 431 | * |
| 432 | * \retval #PSA_SUCCESS |
| 433 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 434 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 435 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 436 | */ |
| 437 | psa_status_t psa_set_key_domain_parameters(psa_key_attributes_t *attributes, |
| 438 | psa_key_type_t type, |
| 439 | const uint8_t *data, |
| 440 | size_t data_length); |
| 441 | |
| 442 | /** |
| 443 | * \brief Get domain parameters for a key. |
| 444 | * |
| 445 | * Get the domain parameters for a key with this function, if any. The format |
| 446 | * of the domain parameters written to \p data is specified in the |
| 447 | * documentation for psa_set_key_domain_parameters(). |
| 448 | * |
| 449 | * \param[in] attributes The key attribute structure to query. |
| 450 | * \param[out] data On success, the key domain parameters. |
| 451 | * \param data_size Size of the \p data buffer in bytes. |
Gilles Peskine | aa02c17 | 2019-04-28 11:44:17 +0200 | [diff] [blame] | 452 | * The buffer is guaranteed to be large |
| 453 | * enough if its size in bytes is at least |
| 454 | * the value given by |
| 455 | * PSA_KEY_DOMAIN_PARAMETERS_SIZE(). |
Gilles Peskine | b699f07 | 2019-04-26 16:06:02 +0200 | [diff] [blame] | 456 | * \param[out] data_length On success, the number of bytes |
| 457 | * that make up the key domain parameters data. |
| 458 | * |
| 459 | * \retval #PSA_SUCCESS |
| 460 | * \retval #PSA_ERROR_BUFFER_TOO_SMALL |
| 461 | */ |
| 462 | psa_status_t psa_get_key_domain_parameters( |
| 463 | const psa_key_attributes_t *attributes, |
| 464 | uint8_t *data, |
| 465 | size_t data_size, |
| 466 | size_t *data_length); |
| 467 | |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 468 | /** Retrieve the attributes of a key. |
| 469 | * |
| 470 | * This function first resets the attribute structure as with |
Gilles Peskine | 9c640f9 | 2019-04-28 11:36:21 +0200 | [diff] [blame] | 471 | * psa_reset_key_attributes(). It then copies the attributes of |
| 472 | * the given key into the given attribute structure. |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 473 | * |
Gilles Peskine | 9c640f9 | 2019-04-28 11:36:21 +0200 | [diff] [blame] | 474 | * \note This function may allocate memory or other resources. |
| 475 | * Once you have called this function on an attribute structure, |
| 476 | * you must call psa_reset_key_attributes() to free these resources. |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 477 | * |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 478 | * \param[in] handle Handle to the key to query. |
| 479 | * \param[in,out] attributes On success, the attributes of the key. |
| 480 | * On failure, equivalent to a |
| 481 | * freshly-initialized structure. |
| 482 | * |
| 483 | * \retval #PSA_SUCCESS |
| 484 | * \retval #PSA_ERROR_INVALID_HANDLE |
| 485 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 486 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 487 | */ |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 488 | psa_status_t psa_get_key_attributes(psa_key_handle_t handle, |
| 489 | psa_key_attributes_t *attributes); |
| 490 | |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 491 | /** Reset a key attribute structure to a freshly initialized state. |
| 492 | * |
| 493 | * You must initialize the attribute structure as described in the |
| 494 | * documentation of the type #psa_key_attributes_t before calling this |
| 495 | * function. Once the structure has been initialized, you may call this |
| 496 | * function at any time. |
| 497 | * |
| 498 | * This function frees any auxiliary resources that the structure |
| 499 | * may contain. |
| 500 | * |
| 501 | * \param[in,out] attributes The attribute structure to reset. |
| 502 | */ |
Gilles Peskine | 8c8f2ab | 2019-04-18 21:44:46 +0200 | [diff] [blame] | 503 | void psa_reset_key_attributes(psa_key_attributes_t *attributes); |
Gilles Peskine | 4747d19 | 2019-04-17 15:05:45 +0200 | [diff] [blame] | 504 | |
Gilles Peskine | 87a5e56 | 2019-04-17 12:28:25 +0200 | [diff] [blame] | 505 | /**@}*/ |
| 506 | |
Gilles Peskine | 2f9c4dc | 2018-01-28 13:16:24 +0100 | [diff] [blame] | 507 | /** \defgroup key_management Key management |
| 508 | * @{ |
| 509 | */ |
| 510 | |
Gilles Peskine | f535eb2 | 2018-11-30 14:08:36 +0100 | [diff] [blame] | 511 | /** Open a handle to an existing persistent key. |
| 512 | * |
| 513 | * Open a handle to a key which was previously created with psa_create_key(). |
| 514 | * |
| 515 | * \param lifetime The lifetime of the key. This designates a storage |
| 516 | * area where the key material is stored. This must not |
| 517 | * be #PSA_KEY_LIFETIME_VOLATILE. |
| 518 | * \param id The persistent identifier of the key. |
| 519 | * \param[out] handle On success, a handle to a key slot which contains |
| 520 | * the data and metadata loaded from the specified |
| 521 | * persistent location. |
| 522 | * |
| 523 | * \retval #PSA_SUCCESS |
| 524 | * Success. The application can now use the value of `*handle` |
| 525 | * to access the newly allocated key slot. |
| 526 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
David Saada | b4ecc27 | 2019-02-14 13:48:10 +0200 | [diff] [blame] | 527 | * \retval #PSA_ERROR_DOES_NOT_EXIST |
Gilles Peskine | f535eb2 | 2018-11-30 14:08:36 +0100 | [diff] [blame] | 528 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 529 | * \p lifetime is invalid, for example #PSA_KEY_LIFETIME_VOLATILE. |
| 530 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 531 | * \p id is invalid for the specified lifetime. |
| 532 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 533 | * \p lifetime is not supported. |
| 534 | * \retval #PSA_ERROR_NOT_PERMITTED |
| 535 | * The specified key exists, but the application does not have the |
| 536 | * permission to access it. Note that this specification does not |
| 537 | * define any way to create such a key, but it may be possible |
| 538 | * through implementation-specific means. |
| 539 | */ |
| 540 | psa_status_t psa_open_key(psa_key_lifetime_t lifetime, |
| 541 | psa_key_id_t id, |
| 542 | psa_key_handle_t *handle); |
| 543 | |
Gilles Peskine | f535eb2 | 2018-11-30 14:08:36 +0100 | [diff] [blame] | 544 | /** Close a key handle. |
| 545 | * |
| 546 | * If the handle designates a volatile key, destroy the key material and |
| 547 | * free all associated resources, just like psa_destroy_key(). |
| 548 | * |
| 549 | * If the handle designates a persistent key, free all resources associated |
| 550 | * with the key in volatile memory. The key slot in persistent storage is |
| 551 | * not affected and can be opened again later with psa_open_key(). |
| 552 | * |
Gilles Peskine | 5f25dd0 | 2019-01-14 18:24:53 +0100 | [diff] [blame] | 553 | * If the key is currently in use in a multipart operation, |
| 554 | * the multipart operation is aborted. |
| 555 | * |
Gilles Peskine | f535eb2 | 2018-11-30 14:08:36 +0100 | [diff] [blame] | 556 | * \param handle The key handle to close. |
| 557 | * |
| 558 | * \retval #PSA_SUCCESS |
| 559 | * \retval #PSA_ERROR_INVALID_HANDLE |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 560 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
Gilles Peskine | f535eb2 | 2018-11-30 14:08:36 +0100 | [diff] [blame] | 561 | */ |
| 562 | psa_status_t psa_close_key(psa_key_handle_t handle); |
| 563 | |
Gilles Peskine | 3cac8c4 | 2018-11-30 14:07:45 +0100 | [diff] [blame] | 564 | /**@}*/ |
| 565 | |
| 566 | /** \defgroup import_export Key import and export |
| 567 | * @{ |
| 568 | */ |
| 569 | |
Gilles Peskine | 2f9c4dc | 2018-01-28 13:16:24 +0100 | [diff] [blame] | 570 | /** |
| 571 | * \brief Import a key in binary format. |
| 572 | * |
Gilles Peskine | f5b9fa1 | 2018-03-07 16:40:18 +0100 | [diff] [blame] | 573 | * This function supports any output from psa_export_key(). Refer to the |
Gilles Peskine | f793393 | 2018-10-31 14:07:52 +0100 | [diff] [blame] | 574 | * documentation of psa_export_public_key() for the format of public keys |
| 575 | * and to the documentation of psa_export_key() for the format for |
| 576 | * other key types. |
| 577 | * |
| 578 | * This specification supports a single format for each key type. |
| 579 | * Implementations may support other formats as long as the standard |
| 580 | * format is supported. Implementations that support other formats |
| 581 | * should ensure that the formats are clearly unambiguous so as to |
| 582 | * minimize the risk that an invalid input is accidentally interpreted |
| 583 | * according to a different format. |
Gilles Peskine | 2f9c4dc | 2018-01-28 13:16:24 +0100 | [diff] [blame] | 584 | * |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 585 | * \param[in] attributes The attributes for the new key. |
| 586 | * The key size field in \p attributes is |
| 587 | * ignored; the actual key size is determined |
| 588 | * from the \p data buffer. |
| 589 | * \param[out] handle On success, a handle to the newly created key. |
| 590 | * \c 0 on failure. |
Gilles Peskine | f793393 | 2018-10-31 14:07:52 +0100 | [diff] [blame] | 591 | * \param[in] data Buffer containing the key data. The content of this |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 592 | * buffer is interpreted according to the type and, |
| 593 | * if applicable, domain parameters declared in |
| 594 | * \p attributes. |
| 595 | * All implementations must support at least the format |
| 596 | * described in the documentation |
Gilles Peskine | f793393 | 2018-10-31 14:07:52 +0100 | [diff] [blame] | 597 | * of psa_export_key() or psa_export_public_key() for |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 598 | * the chosen type. Implementations may allow other |
| 599 | * formats, but should be conservative: implementations |
| 600 | * should err on the side of rejecting content if it |
| 601 | * may be erroneous (e.g. wrong type or truncated data). |
Gilles Peskine | fa4070c | 2018-07-12 19:23:03 +0200 | [diff] [blame] | 602 | * \param data_length Size of the \p data buffer in bytes. |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 603 | * |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 604 | * \retval #PSA_SUCCESS |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 605 | * Success. |
Gilles Peskine | 23fd2bd | 2018-12-11 15:51:32 +0100 | [diff] [blame] | 606 | * If the key is persistent, the key material and the key's metadata |
| 607 | * have been saved to persistent storage. |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 608 | * \retval #PSA_ERROR_ALREADY_EXISTS |
| 609 | * This is an attempt to create a persistent key, and there is |
| 610 | * already a persistent key with the given identifier. |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 611 | * \retval #PSA_ERROR_NOT_SUPPORTED |
Gilles Peskine | 65eb858 | 2018-04-19 08:28:58 +0200 | [diff] [blame] | 612 | * The key type or key size is not supported, either by the |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 613 | * implementation in general or in this particular persistent location. |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 614 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 615 | * The key attributes, as a whole, are invalid, |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 616 | * or the key data is not correctly formatted. |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 617 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 618 | * \retval #PSA_ERROR_INSUFFICIENT_STORAGE |
| 619 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
Darryl Green | d49a499 | 2018-06-18 17:27:26 +0100 | [diff] [blame] | 620 | * \retval #PSA_ERROR_STORAGE_FAILURE |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 621 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 622 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
itayzafrir | 90d8c7a | 2018-09-12 11:44:52 +0300 | [diff] [blame] | 623 | * \retval #PSA_ERROR_BAD_STATE |
itayzafrir | 1861709 | 2018-09-16 12:22:41 +0300 | [diff] [blame] | 624 | * The library has not been previously initialized by psa_crypto_init(). |
| 625 | * It is implementation-dependent whether a failure to initialize |
| 626 | * results in this error code. |
Gilles Peskine | 2f9c4dc | 2018-01-28 13:16:24 +0100 | [diff] [blame] | 627 | */ |
Gilles Peskine | 87a5e56 | 2019-04-17 12:28:25 +0200 | [diff] [blame] | 628 | psa_status_t psa_import_key(const psa_key_attributes_t *attributes, |
| 629 | psa_key_handle_t *handle, |
Gilles Peskine | 2f9c4dc | 2018-01-28 13:16:24 +0100 | [diff] [blame] | 630 | const uint8_t *data, |
| 631 | size_t data_length); |
| 632 | |
| 633 | /** |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 634 | * \brief Destroy a key. |
Gilles Peskine | 154bd95 | 2018-04-19 08:38:16 +0200 | [diff] [blame] | 635 | * |
| 636 | * This function destroys the content of the key slot from both volatile |
| 637 | * memory and, if applicable, non-volatile storage. Implementations shall |
| 638 | * make a best effort to ensure that any previous content of the slot is |
| 639 | * unrecoverable. |
| 640 | * |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 641 | * This function also erases any metadata such as policies and frees all |
| 642 | * resources associated with the key. |
Gilles Peskine | 154bd95 | 2018-04-19 08:38:16 +0200 | [diff] [blame] | 643 | * |
Gilles Peskine | 5f25dd0 | 2019-01-14 18:24:53 +0100 | [diff] [blame] | 644 | * If the key is currently in use in a multipart operation, |
| 645 | * the multipart operation is aborted. |
| 646 | * |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 647 | * \param handle Handle to the key slot to erase. |
Gilles Peskine | 2f9c4dc | 2018-01-28 13:16:24 +0100 | [diff] [blame] | 648 | * |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 649 | * \retval #PSA_SUCCESS |
Gilles Peskine | 65eb858 | 2018-04-19 08:28:58 +0200 | [diff] [blame] | 650 | * The slot's content, if any, has been erased. |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 651 | * \retval #PSA_ERROR_NOT_PERMITTED |
Gilles Peskine | 65eb858 | 2018-04-19 08:28:58 +0200 | [diff] [blame] | 652 | * The slot holds content and cannot be erased because it is |
| 653 | * read-only, either due to a policy or due to physical restrictions. |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 654 | * \retval #PSA_ERROR_INVALID_HANDLE |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 655 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
Gilles Peskine | 65eb858 | 2018-04-19 08:28:58 +0200 | [diff] [blame] | 656 | * There was an failure in communication with the cryptoprocessor. |
| 657 | * The key material may still be present in the cryptoprocessor. |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 658 | * \retval #PSA_ERROR_STORAGE_FAILURE |
Gilles Peskine | 65eb858 | 2018-04-19 08:28:58 +0200 | [diff] [blame] | 659 | * The storage is corrupted. Implementations shall make a best effort |
| 660 | * to erase key material even in this stage, however applications |
| 661 | * should be aware that it may be impossible to guarantee that the |
| 662 | * key material is not recoverable in such cases. |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 663 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
Gilles Peskine | 65eb858 | 2018-04-19 08:28:58 +0200 | [diff] [blame] | 664 | * An unexpected condition which is not a storage corruption or |
| 665 | * a communication failure occurred. The cryptoprocessor may have |
| 666 | * been compromised. |
itayzafrir | 90d8c7a | 2018-09-12 11:44:52 +0300 | [diff] [blame] | 667 | * \retval #PSA_ERROR_BAD_STATE |
itayzafrir | 1861709 | 2018-09-16 12:22:41 +0300 | [diff] [blame] | 668 | * The library has not been previously initialized by psa_crypto_init(). |
| 669 | * It is implementation-dependent whether a failure to initialize |
| 670 | * results in this error code. |
Gilles Peskine | 2f9c4dc | 2018-01-28 13:16:24 +0100 | [diff] [blame] | 671 | */ |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 672 | psa_status_t psa_destroy_key(psa_key_handle_t handle); |
Gilles Peskine | 2f9c4dc | 2018-01-28 13:16:24 +0100 | [diff] [blame] | 673 | |
| 674 | /** |
Gilles Peskine | 2f9c4dc | 2018-01-28 13:16:24 +0100 | [diff] [blame] | 675 | * \brief Export a key in binary format. |
| 676 | * |
| 677 | * The output of this function can be passed to psa_import_key() to |
| 678 | * create an equivalent object. |
| 679 | * |
Gilles Peskine | f793393 | 2018-10-31 14:07:52 +0100 | [diff] [blame] | 680 | * If the implementation of psa_import_key() supports other formats |
| 681 | * beyond the format specified here, the output from psa_export_key() |
| 682 | * must use the representation specified here, not the original |
| 683 | * representation. |
Gilles Peskine | 2f9c4dc | 2018-01-28 13:16:24 +0100 | [diff] [blame] | 684 | * |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 685 | * For standard key types, the output format is as follows: |
| 686 | * |
| 687 | * - For symmetric keys (including MAC keys), the format is the |
| 688 | * raw bytes of the key. |
| 689 | * - For DES, the key data consists of 8 bytes. The parity bits must be |
| 690 | * correct. |
| 691 | * - For Triple-DES, the format is the concatenation of the |
| 692 | * two or three DES keys. |
Gilles Peskine | 92b3073 | 2018-03-03 21:29:30 +0100 | [diff] [blame] | 693 | * - For RSA key pairs (#PSA_KEY_TYPE_RSA_KEYPAIR), the format |
Gilles Peskine | 4e1e9be | 2018-08-10 18:57:40 +0200 | [diff] [blame] | 694 | * is the non-encrypted DER encoding of the representation defined by |
| 695 | * PKCS\#1 (RFC 8017) as `RSAPrivateKey`, version 0. |
| 696 | * ``` |
| 697 | * RSAPrivateKey ::= SEQUENCE { |
Gilles Peskine | 4f6c77b | 2018-08-11 01:17:53 +0200 | [diff] [blame] | 698 | * version INTEGER, -- must be 0 |
Gilles Peskine | 4e1e9be | 2018-08-10 18:57:40 +0200 | [diff] [blame] | 699 | * modulus INTEGER, -- n |
| 700 | * publicExponent INTEGER, -- e |
| 701 | * privateExponent INTEGER, -- d |
| 702 | * prime1 INTEGER, -- p |
| 703 | * prime2 INTEGER, -- q |
| 704 | * exponent1 INTEGER, -- d mod (p-1) |
| 705 | * exponent2 INTEGER, -- d mod (q-1) |
| 706 | * coefficient INTEGER, -- (inverse of q) mod p |
| 707 | * } |
| 708 | * ``` |
Jaeden Amero | 1308fb5 | 2019-01-11 13:50:43 +0000 | [diff] [blame] | 709 | * - For DSA private keys (#PSA_KEY_TYPE_DSA_KEYPAIR), the format is the |
| 710 | * representation of the private key `x` as a big-endian byte string. The |
| 711 | * length of the byte string is the private key size in bytes (leading zeroes |
| 712 | * are not stripped). |
Gilles Peskine | 4e1e9be | 2018-08-10 18:57:40 +0200 | [diff] [blame] | 713 | * - For elliptic curve key pairs (key types for which |
Gilles Peskine | f76aa77 | 2018-10-29 19:24:33 +0100 | [diff] [blame] | 714 | * #PSA_KEY_TYPE_IS_ECC_KEYPAIR is true), the format is |
Gilles Peskine | 6c6a023 | 2018-11-15 17:44:43 +0100 | [diff] [blame] | 715 | * a representation of the private value as a `ceiling(m/8)`-byte string |
| 716 | * where `m` is the bit size associated with the curve, i.e. the bit size |
| 717 | * of the order of the curve's coordinate field. This byte string is |
| 718 | * in little-endian order for Montgomery curves (curve types |
| 719 | * `PSA_ECC_CURVE_CURVEXXX`), and in big-endian order for Weierstrass |
| 720 | * curves (curve types `PSA_ECC_CURVE_SECTXXX`, `PSA_ECC_CURVE_SECPXXX` |
| 721 | * and `PSA_ECC_CURVE_BRAINPOOL_PXXX`). |
Gilles Peskine | f76aa77 | 2018-10-29 19:24:33 +0100 | [diff] [blame] | 722 | * This is the content of the `privateKey` field of the `ECPrivateKey` |
| 723 | * format defined by RFC 5915. |
Jaeden Amero | 8851c40 | 2019-01-11 14:20:03 +0000 | [diff] [blame] | 724 | * - For Diffie-Hellman key exchange key pairs (#PSA_KEY_TYPE_DH_KEYPAIR), the |
| 725 | * format is the representation of the private key `x` as a big-endian byte |
| 726 | * string. The length of the byte string is the private key size in bytes |
| 727 | * (leading zeroes are not stripped). |
Gilles Peskine | 4e1e9be | 2018-08-10 18:57:40 +0200 | [diff] [blame] | 728 | * - For public keys (key types for which #PSA_KEY_TYPE_IS_PUBLIC_KEY is |
| 729 | * true), the format is the same as for psa_export_public_key(). |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 730 | * |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 731 | * \param handle Handle to the key to export. |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 732 | * \param[out] data Buffer where the key data is to be written. |
Gilles Peskine | fa4070c | 2018-07-12 19:23:03 +0200 | [diff] [blame] | 733 | * \param data_size Size of the \p data buffer in bytes. |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 734 | * \param[out] data_length On success, the number of bytes |
| 735 | * that make up the key data. |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 736 | * |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 737 | * \retval #PSA_SUCCESS |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 738 | * \retval #PSA_ERROR_INVALID_HANDLE |
David Saada | b4ecc27 | 2019-02-14 13:48:10 +0200 | [diff] [blame] | 739 | * \retval #PSA_ERROR_DOES_NOT_EXIST |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 740 | * \retval #PSA_ERROR_NOT_PERMITTED |
Darryl Green | 9e2d7a0 | 2018-07-24 16:33:30 +0100 | [diff] [blame] | 741 | * \retval #PSA_ERROR_NOT_SUPPORTED |
Gilles Peskine | 1be949b | 2018-08-10 19:06:59 +0200 | [diff] [blame] | 742 | * \retval #PSA_ERROR_BUFFER_TOO_SMALL |
| 743 | * The size of the \p data buffer is too small. You can determine a |
| 744 | * sufficient buffer size by calling |
| 745 | * #PSA_KEY_EXPORT_MAX_SIZE(\c type, \c bits) |
| 746 | * where \c type is the key type |
| 747 | * and \c bits is the key size in bits. |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 748 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 749 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 750 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
itayzafrir | 90d8c7a | 2018-09-12 11:44:52 +0300 | [diff] [blame] | 751 | * \retval #PSA_ERROR_BAD_STATE |
itayzafrir | 1861709 | 2018-09-16 12:22:41 +0300 | [diff] [blame] | 752 | * The library has not been previously initialized by psa_crypto_init(). |
| 753 | * It is implementation-dependent whether a failure to initialize |
| 754 | * results in this error code. |
Gilles Peskine | 2f9c4dc | 2018-01-28 13:16:24 +0100 | [diff] [blame] | 755 | */ |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 756 | psa_status_t psa_export_key(psa_key_handle_t handle, |
Gilles Peskine | 2f9c4dc | 2018-01-28 13:16:24 +0100 | [diff] [blame] | 757 | uint8_t *data, |
| 758 | size_t data_size, |
| 759 | size_t *data_length); |
| 760 | |
Gilles Peskine | 7698bcf | 2018-03-03 21:30:44 +0100 | [diff] [blame] | 761 | /** |
| 762 | * \brief Export a public key or the public part of a key pair in binary format. |
| 763 | * |
| 764 | * The output of this function can be passed to psa_import_key() to |
| 765 | * create an object that is equivalent to the public key. |
| 766 | * |
Jaeden Amero | d3a0c2c | 2019-01-11 17:15:56 +0000 | [diff] [blame] | 767 | * This specification supports a single format for each key type. |
| 768 | * Implementations may support other formats as long as the standard |
| 769 | * format is supported. Implementations that support other formats |
| 770 | * should ensure that the formats are clearly unambiguous so as to |
| 771 | * minimize the risk that an invalid input is accidentally interpreted |
| 772 | * according to a different format. |
| 773 | * |
Jaeden Amero | 6b19600 | 2019-01-10 10:23:21 +0000 | [diff] [blame] | 774 | * For standard key types, the output format is as follows: |
| 775 | * - For RSA public keys (#PSA_KEY_TYPE_RSA_PUBLIC_KEY), the DER encoding of |
| 776 | * the representation defined by RFC 3279 §2.3.1 as `RSAPublicKey`. |
| 777 | * ``` |
| 778 | * RSAPublicKey ::= SEQUENCE { |
| 779 | * modulus INTEGER, -- n |
| 780 | * publicExponent INTEGER } -- e |
| 781 | * ``` |
Jaeden Amero | 0ae445f | 2019-01-10 11:42:27 +0000 | [diff] [blame] | 782 | * - For elliptic curve public keys (key types for which |
| 783 | * #PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY is true), the format is the uncompressed |
| 784 | * representation defined by SEC1 §2.3.3 as the content of an ECPoint. |
| 785 | * Let `m` be the bit size associated with the curve, i.e. the bit size of |
| 786 | * `q` for a curve over `F_q`. The representation consists of: |
| 787 | * - The byte 0x04; |
| 788 | * - `x_P` as a `ceiling(m/8)`-byte string, big-endian; |
| 789 | * - `y_P` as a `ceiling(m/8)`-byte string, big-endian. |
Jaeden Amero | 1308fb5 | 2019-01-11 13:50:43 +0000 | [diff] [blame] | 790 | * - For DSA public keys (#PSA_KEY_TYPE_DSA_PUBLIC_KEY), the format is the |
| 791 | * representation of the public key `y = g^x mod p` as a big-endian byte |
| 792 | * string. The length of the byte string is the length of the base prime `p` |
| 793 | * in bytes. |
Jaeden Amero | 8851c40 | 2019-01-11 14:20:03 +0000 | [diff] [blame] | 794 | * - For Diffie-Hellman key exchange public keys (#PSA_KEY_TYPE_DH_PUBLIC_KEY), |
| 795 | * the format is the representation of the public key `y = g^x mod p` as a |
| 796 | * big-endian byte string. The length of the byte string is the length of the |
| 797 | * base prime `p` in bytes. |
Gilles Peskine | 7698bcf | 2018-03-03 21:30:44 +0100 | [diff] [blame] | 798 | * |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 799 | * \param handle Handle to the key to export. |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 800 | * \param[out] data Buffer where the key data is to be written. |
Gilles Peskine | fa4070c | 2018-07-12 19:23:03 +0200 | [diff] [blame] | 801 | * \param data_size Size of the \p data buffer in bytes. |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 802 | * \param[out] data_length On success, the number of bytes |
| 803 | * that make up the key data. |
Gilles Peskine | 7698bcf | 2018-03-03 21:30:44 +0100 | [diff] [blame] | 804 | * |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 805 | * \retval #PSA_SUCCESS |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 806 | * \retval #PSA_ERROR_INVALID_HANDLE |
David Saada | b4ecc27 | 2019-02-14 13:48:10 +0200 | [diff] [blame] | 807 | * \retval #PSA_ERROR_DOES_NOT_EXIST |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 808 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
Gilles Peskine | 1be949b | 2018-08-10 19:06:59 +0200 | [diff] [blame] | 809 | * The key is neither a public key nor a key pair. |
| 810 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 811 | * \retval #PSA_ERROR_BUFFER_TOO_SMALL |
| 812 | * The size of the \p data buffer is too small. You can determine a |
| 813 | * sufficient buffer size by calling |
| 814 | * #PSA_KEY_EXPORT_MAX_SIZE(#PSA_KEY_TYPE_PUBLIC_KEY_OF_KEYPAIR(\c type), \c bits) |
| 815 | * where \c type is the key type |
| 816 | * and \c bits is the key size in bits. |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 817 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 818 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 819 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
itayzafrir | 90d8c7a | 2018-09-12 11:44:52 +0300 | [diff] [blame] | 820 | * \retval #PSA_ERROR_BAD_STATE |
itayzafrir | 1861709 | 2018-09-16 12:22:41 +0300 | [diff] [blame] | 821 | * The library has not been previously initialized by psa_crypto_init(). |
| 822 | * It is implementation-dependent whether a failure to initialize |
| 823 | * results in this error code. |
Gilles Peskine | 7698bcf | 2018-03-03 21:30:44 +0100 | [diff] [blame] | 824 | */ |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 825 | psa_status_t psa_export_public_key(psa_key_handle_t handle, |
Gilles Peskine | 7698bcf | 2018-03-03 21:30:44 +0100 | [diff] [blame] | 826 | uint8_t *data, |
| 827 | size_t data_size, |
| 828 | size_t *data_length); |
| 829 | |
Gilles Peskine | 4cb9dde | 2019-01-19 13:40:11 +0100 | [diff] [blame] | 830 | /** Make a copy of a key. |
Gilles Peskine | 7698bcf | 2018-03-03 21:30:44 +0100 | [diff] [blame] | 831 | * |
Gilles Peskine | 4cb9dde | 2019-01-19 13:40:11 +0100 | [diff] [blame] | 832 | * Copy key material from one location to another. |
Jaeden Amero | 70261c5 | 2019-01-04 11:47:20 +0000 | [diff] [blame] | 833 | * |
Gilles Peskine | aec5a7f | 2019-02-05 20:26:09 +0100 | [diff] [blame] | 834 | * This function is primarily useful to copy a key from one location |
| 835 | * to another, since it populates a key using the material from |
| 836 | * another key which may have a different lifetime. |
Gilles Peskine | 6ac73a9 | 2018-07-12 19:47:19 +0200 | [diff] [blame] | 837 | * |
Gilles Peskine | 4cb9dde | 2019-01-19 13:40:11 +0100 | [diff] [blame] | 838 | * In an implementation where slots have different ownerships, |
Gilles Peskine | bf7a98b | 2019-02-22 16:42:11 +0100 | [diff] [blame] | 839 | * this function may be used to share a key with a different party, |
Gilles Peskine | 4cb9dde | 2019-01-19 13:40:11 +0100 | [diff] [blame] | 840 | * subject to implementation-defined restrictions on key sharing. |
Gilles Peskine | 7e19853 | 2018-03-08 07:50:30 +0100 | [diff] [blame] | 841 | * |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 842 | * The resulting key may only be used in a way that conforms to |
| 843 | * both the policy of the original key and the policy specified in |
| 844 | * the \p attributes parameter: |
Gilles Peskine | 4cb9dde | 2019-01-19 13:40:11 +0100 | [diff] [blame] | 845 | * - The usage flags on the resulting key are the bitwise-and of the |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 846 | * usage flags on the source policy and the usage flags in \p attributes. |
| 847 | * - If both allow the same algorithm or wildcard-based |
Gilles Peskine | 4cb9dde | 2019-01-19 13:40:11 +0100 | [diff] [blame] | 848 | * algorithm policy, the resulting key has the same algorithm policy. |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 849 | * - If either of the policies allows an algorithm and the other policy |
| 850 | * allows a wildcard-based algorithm policy that includes this algorithm, |
| 851 | * the resulting key allows the same algorithm. |
| 852 | * - If the policies do not allow any algorithm in common, this function |
| 853 | * fails with the status #PSA_ERROR_INVALID_ARGUMENT. |
Gilles Peskine | 6ac73a9 | 2018-07-12 19:47:19 +0200 | [diff] [blame] | 854 | * |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 855 | * The effect of this function on implementation-defined attributes is |
Gilles Peskine | 4cb9dde | 2019-01-19 13:40:11 +0100 | [diff] [blame] | 856 | * implementation-defined. |
Gilles Peskine | 6ac73a9 | 2018-07-12 19:47:19 +0200 | [diff] [blame] | 857 | * |
Gilles Peskine | 4cb9dde | 2019-01-19 13:40:11 +0100 | [diff] [blame] | 858 | * \param source_handle The key to copy. It must be a handle to an |
| 859 | * occupied slot. |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 860 | * \param[in] attributes The attributes for the new key. |
| 861 | * They are used as follows: |
| 862 | * - The key type, key size and domain parameters |
| 863 | * are ignored. This information is copied |
| 864 | * from the source key. |
| 865 | * - The key location (the lifetime and, for |
| 866 | * persistent keys, the key identifier) is |
| 867 | * used directly. |
| 868 | * - The policy constraints (usage flags and |
| 869 | * algorithm policy) are combined from |
| 870 | * the source key and \p attributes so that |
| 871 | * both sets of restrictions apply, as |
| 872 | * described in the documentation of this function. |
| 873 | * \param[out] target_handle On success, a handle to the newly created key. |
| 874 | * \c 0 on failure. |
Gilles Peskine | 6ac73a9 | 2018-07-12 19:47:19 +0200 | [diff] [blame] | 875 | * |
| 876 | * \retval #PSA_SUCCESS |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 877 | * \retval #PSA_ERROR_INVALID_HANDLE |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 878 | * \p source_handle is invalid. |
David Saada | b4ecc27 | 2019-02-14 13:48:10 +0200 | [diff] [blame] | 879 | * \retval #PSA_ERROR_ALREADY_EXISTS |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 880 | * This is an attempt to create a persistent key, and there is |
| 881 | * already a persistent key with the given identifier. |
Gilles Peskine | 6ac73a9 | 2018-07-12 19:47:19 +0200 | [diff] [blame] | 882 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 883 | * The lifetime or identifier in \p attributes are invalid. |
| 884 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 885 | * The policy constraints on the source and specified in |
| 886 | * \p attributes are incompatible. |
Gilles Peskine | 4cb9dde | 2019-01-19 13:40:11 +0100 | [diff] [blame] | 887 | * \retval #PSA_ERROR_NOT_PERMITTED |
| 888 | * The source key is not exportable and its lifetime does not |
| 889 | * allow copying it to the target's lifetime. |
| 890 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 891 | * \retval #PSA_ERROR_INSUFFICIENT_STORAGE |
Gilles Peskine | 6ac73a9 | 2018-07-12 19:47:19 +0200 | [diff] [blame] | 892 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 893 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 894 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
Gilles Peskine | 7698bcf | 2018-03-03 21:30:44 +0100 | [diff] [blame] | 895 | */ |
Gilles Peskine | 4cb9dde | 2019-01-19 13:40:11 +0100 | [diff] [blame] | 896 | psa_status_t psa_copy_key(psa_key_handle_t source_handle, |
Gilles Peskine | 87a5e56 | 2019-04-17 12:28:25 +0200 | [diff] [blame] | 897 | const psa_key_attributes_t *attributes, |
| 898 | psa_key_handle_t *target_handle); |
Gilles Peskine | 20035e3 | 2018-02-03 22:44:14 +0100 | [diff] [blame] | 899 | |
| 900 | /**@}*/ |
| 901 | |
Gilles Peskine | 9ef733f | 2018-02-07 21:05:37 +0100 | [diff] [blame] | 902 | /** \defgroup hash Message digests |
| 903 | * @{ |
| 904 | */ |
| 905 | |
Gilles Peskine | 69647a4 | 2019-01-14 20:18:12 +0100 | [diff] [blame] | 906 | /** Calculate the hash (digest) of a message. |
| 907 | * |
| 908 | * \note To verify the hash of a message against an |
| 909 | * expected value, use psa_hash_compare() instead. |
| 910 | * |
| 911 | * \param alg The hash algorithm to compute (\c PSA_ALG_XXX value |
| 912 | * such that #PSA_ALG_IS_HASH(\p alg) is true). |
| 913 | * \param[in] input Buffer containing the message to hash. |
| 914 | * \param input_length Size of the \p input buffer in bytes. |
| 915 | * \param[out] hash Buffer where the hash is to be written. |
| 916 | * \param hash_size Size of the \p hash buffer in bytes. |
| 917 | * \param[out] hash_length On success, the number of bytes |
| 918 | * that make up the hash value. This is always |
Gilles Peskine | d338b91 | 2019-02-15 13:01:41 +0100 | [diff] [blame] | 919 | * #PSA_HASH_SIZE(\p alg). |
Gilles Peskine | 69647a4 | 2019-01-14 20:18:12 +0100 | [diff] [blame] | 920 | * |
| 921 | * \retval #PSA_SUCCESS |
| 922 | * Success. |
| 923 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 924 | * \p alg is not supported or is not a hash algorithm. |
| 925 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 926 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 927 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 928 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 929 | */ |
| 930 | psa_status_t psa_hash_compute(psa_algorithm_t alg, |
| 931 | const uint8_t *input, |
| 932 | size_t input_length, |
| 933 | uint8_t *hash, |
| 934 | size_t hash_size, |
| 935 | size_t *hash_length); |
| 936 | |
| 937 | /** Calculate the hash (digest) of a message and compare it with a |
| 938 | * reference value. |
| 939 | * |
| 940 | * \param alg The hash algorithm to compute (\c PSA_ALG_XXX value |
| 941 | * such that #PSA_ALG_IS_HASH(\p alg) is true). |
| 942 | * \param[in] input Buffer containing the message to hash. |
| 943 | * \param input_length Size of the \p input buffer in bytes. |
| 944 | * \param[out] hash Buffer containing the expected hash value. |
Gilles Peskine | a05602d | 2019-01-17 15:25:52 +0100 | [diff] [blame] | 945 | * \param hash_length Size of the \p hash buffer in bytes. |
Gilles Peskine | 69647a4 | 2019-01-14 20:18:12 +0100 | [diff] [blame] | 946 | * |
| 947 | * \retval #PSA_SUCCESS |
| 948 | * The expected hash is identical to the actual hash of the input. |
| 949 | * \retval #PSA_ERROR_INVALID_SIGNATURE |
| 950 | * The hash of the message was calculated successfully, but it |
| 951 | * differs from the expected hash. |
| 952 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 953 | * \p alg is not supported or is not a hash algorithm. |
| 954 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 955 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 956 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 957 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 958 | */ |
| 959 | psa_status_t psa_hash_compare(psa_algorithm_t alg, |
| 960 | const uint8_t *input, |
| 961 | size_t input_length, |
| 962 | const uint8_t *hash, |
| 963 | const size_t hash_length); |
| 964 | |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 965 | /** The type of the state data structure for multipart hash operations. |
| 966 | * |
Jaeden Amero | 6a25b41 | 2019-01-04 11:47:44 +0000 | [diff] [blame] | 967 | * Before calling any function on a hash operation object, the application must |
| 968 | * initialize it by any of the following means: |
| 969 | * - Set the structure to all-bits-zero, for example: |
| 970 | * \code |
| 971 | * psa_hash_operation_t operation; |
| 972 | * memset(&operation, 0, sizeof(operation)); |
| 973 | * \endcode |
| 974 | * - Initialize the structure to logical zero values, for example: |
| 975 | * \code |
| 976 | * psa_hash_operation_t operation = {0}; |
| 977 | * \endcode |
| 978 | * - Initialize the structure to the initializer #PSA_HASH_OPERATION_INIT, |
| 979 | * for example: |
| 980 | * \code |
| 981 | * psa_hash_operation_t operation = PSA_HASH_OPERATION_INIT; |
| 982 | * \endcode |
| 983 | * - Assign the result of the function psa_hash_operation_init() |
| 984 | * to the structure, for example: |
| 985 | * \code |
| 986 | * psa_hash_operation_t operation; |
| 987 | * operation = psa_hash_operation_init(); |
| 988 | * \endcode |
| 989 | * |
Gilles Peskine | 92b3073 | 2018-03-03 21:29:30 +0100 | [diff] [blame] | 990 | * This is an implementation-defined \c struct. Applications should not |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 991 | * make any assumptions about the content of this structure except |
| 992 | * as directed by the documentation of a specific implementation. */ |
Gilles Peskine | 9ef733f | 2018-02-07 21:05:37 +0100 | [diff] [blame] | 993 | typedef struct psa_hash_operation_s psa_hash_operation_t; |
| 994 | |
Jaeden Amero | 6a25b41 | 2019-01-04 11:47:44 +0000 | [diff] [blame] | 995 | /** \def PSA_HASH_OPERATION_INIT |
| 996 | * |
| 997 | * This macro returns a suitable initializer for a hash operation object |
| 998 | * of type #psa_hash_operation_t. |
| 999 | */ |
| 1000 | #ifdef __DOXYGEN_ONLY__ |
| 1001 | /* This is an example definition for documentation purposes. |
| 1002 | * Implementations should define a suitable value in `crypto_struct.h`. |
| 1003 | */ |
| 1004 | #define PSA_HASH_OPERATION_INIT {0} |
| 1005 | #endif |
| 1006 | |
| 1007 | /** Return an initial value for a hash operation object. |
| 1008 | */ |
| 1009 | static psa_hash_operation_t psa_hash_operation_init(void); |
| 1010 | |
Gilles Peskine | f45adda | 2019-01-14 18:29:18 +0100 | [diff] [blame] | 1011 | /** Set up a multipart hash operation. |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 1012 | * |
| 1013 | * The sequence of operations to calculate a hash (message digest) |
| 1014 | * is as follows: |
| 1015 | * -# Allocate an operation object which will be passed to all the functions |
| 1016 | * listed here. |
Jaeden Amero | 6a25b41 | 2019-01-04 11:47:44 +0000 | [diff] [blame] | 1017 | * -# Initialize the operation object with one of the methods described in the |
| 1018 | * documentation for #psa_hash_operation_t, e.g. PSA_HASH_OPERATION_INIT. |
Gilles Peskine | da8191d1c | 2018-07-08 19:46:38 +0200 | [diff] [blame] | 1019 | * -# Call psa_hash_setup() to specify the algorithm. |
Gilles Peskine | 7e4acc5 | 2018-02-16 21:24:11 +0100 | [diff] [blame] | 1020 | * -# Call psa_hash_update() zero, one or more times, passing a fragment |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 1021 | * of the message each time. The hash that is calculated is the hash |
| 1022 | * of the concatenation of these messages in order. |
| 1023 | * -# To calculate the hash, call psa_hash_finish(). |
| 1024 | * To compare the hash with an expected value, call psa_hash_verify(). |
| 1025 | * |
| 1026 | * The application may call psa_hash_abort() at any time after the operation |
Jaeden Amero | 6a25b41 | 2019-01-04 11:47:44 +0000 | [diff] [blame] | 1027 | * has been initialized. |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 1028 | * |
Gilles Peskine | da8191d1c | 2018-07-08 19:46:38 +0200 | [diff] [blame] | 1029 | * After a successful call to psa_hash_setup(), the application must |
Gilles Peskine | ed52297 | 2018-03-20 17:54:15 +0100 | [diff] [blame] | 1030 | * eventually terminate the operation. The following events terminate an |
| 1031 | * operation: |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 1032 | * - A failed call to psa_hash_update(). |
Gilles Peskine | 1906798 | 2018-03-20 17:54:53 +0100 | [diff] [blame] | 1033 | * - A call to psa_hash_finish(), psa_hash_verify() or psa_hash_abort(). |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 1034 | * |
Jaeden Amero | 6a25b41 | 2019-01-04 11:47:44 +0000 | [diff] [blame] | 1035 | * \param[in,out] operation The operation object to set up. It must have |
| 1036 | * been initialized as per the documentation for |
| 1037 | * #psa_hash_operation_t and not yet in use. |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 1038 | * \param alg The hash algorithm to compute (\c PSA_ALG_XXX value |
| 1039 | * such that #PSA_ALG_IS_HASH(\p alg) is true). |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 1040 | * |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 1041 | * \retval #PSA_SUCCESS |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 1042 | * Success. |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 1043 | * \retval #PSA_ERROR_NOT_SUPPORTED |
Gilles Peskine | fa4070c | 2018-07-12 19:23:03 +0200 | [diff] [blame] | 1044 | * \p alg is not supported or is not a hash algorithm. |
Gilles Peskine | 8e1addc | 2019-01-10 11:51:17 +0100 | [diff] [blame] | 1045 | * \retval #PSA_ERROR_BAD_STATE |
| 1046 | * The operation state is not valid (already set up and not |
| 1047 | * subsequently completed). |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 1048 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 1049 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 1050 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 1051 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 1052 | */ |
Gilles Peskine | da8191d1c | 2018-07-08 19:46:38 +0200 | [diff] [blame] | 1053 | psa_status_t psa_hash_setup(psa_hash_operation_t *operation, |
Gilles Peskine | 9ef733f | 2018-02-07 21:05:37 +0100 | [diff] [blame] | 1054 | psa_algorithm_t alg); |
| 1055 | |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 1056 | /** Add a message fragment to a multipart hash operation. |
| 1057 | * |
Gilles Peskine | da8191d1c | 2018-07-08 19:46:38 +0200 | [diff] [blame] | 1058 | * The application must call psa_hash_setup() before calling this function. |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 1059 | * |
| 1060 | * If this function returns an error status, the operation becomes inactive. |
| 1061 | * |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 1062 | * \param[in,out] operation Active hash operation. |
| 1063 | * \param[in] input Buffer containing the message fragment to hash. |
Gilles Peskine | fa4070c | 2018-07-12 19:23:03 +0200 | [diff] [blame] | 1064 | * \param input_length Size of the \p input buffer in bytes. |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 1065 | * |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 1066 | * \retval #PSA_SUCCESS |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 1067 | * Success. |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 1068 | * \retval #PSA_ERROR_BAD_STATE |
Gilles Peskine | f45adda | 2019-01-14 18:29:18 +0100 | [diff] [blame] | 1069 | * The operation state is not valid (not set up, or already completed). |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 1070 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 1071 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 1072 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 1073 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 1074 | */ |
Gilles Peskine | 9ef733f | 2018-02-07 21:05:37 +0100 | [diff] [blame] | 1075 | psa_status_t psa_hash_update(psa_hash_operation_t *operation, |
| 1076 | const uint8_t *input, |
| 1077 | size_t input_length); |
| 1078 | |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 1079 | /** Finish the calculation of the hash of a message. |
| 1080 | * |
Gilles Peskine | da8191d1c | 2018-07-08 19:46:38 +0200 | [diff] [blame] | 1081 | * The application must call psa_hash_setup() before calling this function. |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 1082 | * This function calculates the hash of the message formed by concatenating |
| 1083 | * the inputs passed to preceding calls to psa_hash_update(). |
| 1084 | * |
| 1085 | * When this function returns, the operation becomes inactive. |
| 1086 | * |
| 1087 | * \warning Applications should not call this function if they expect |
| 1088 | * a specific value for the hash. Call psa_hash_verify() instead. |
| 1089 | * Beware that comparing integrity or authenticity data such as |
| 1090 | * hash values with a function such as \c memcmp is risky |
| 1091 | * because the time taken by the comparison may leak information |
| 1092 | * about the hashed data which could allow an attacker to guess |
| 1093 | * a valid hash and thereby bypass security controls. |
| 1094 | * |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 1095 | * \param[in,out] operation Active hash operation. |
| 1096 | * \param[out] hash Buffer where the hash is to be written. |
| 1097 | * \param hash_size Size of the \p hash buffer in bytes. |
| 1098 | * \param[out] hash_length On success, the number of bytes |
| 1099 | * that make up the hash value. This is always |
Gilles Peskine | be42f31 | 2018-07-13 14:38:15 +0200 | [diff] [blame] | 1100 | * #PSA_HASH_SIZE(\c alg) where \c alg is the |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 1101 | * hash algorithm that is calculated. |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 1102 | * |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 1103 | * \retval #PSA_SUCCESS |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 1104 | * Success. |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 1105 | * \retval #PSA_ERROR_BAD_STATE |
Gilles Peskine | f45adda | 2019-01-14 18:29:18 +0100 | [diff] [blame] | 1106 | * The operation state is not valid (not set up, or already completed). |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 1107 | * \retval #PSA_ERROR_BUFFER_TOO_SMALL |
Gilles Peskine | fa4070c | 2018-07-12 19:23:03 +0200 | [diff] [blame] | 1108 | * The size of the \p hash buffer is too small. You can determine a |
Gilles Peskine | 7256e6c | 2018-07-12 00:34:26 +0200 | [diff] [blame] | 1109 | * sufficient buffer size by calling #PSA_HASH_SIZE(\c alg) |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 1110 | * where \c alg is the hash algorithm that is calculated. |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 1111 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 1112 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 1113 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 1114 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 1115 | */ |
Gilles Peskine | 9ef733f | 2018-02-07 21:05:37 +0100 | [diff] [blame] | 1116 | psa_status_t psa_hash_finish(psa_hash_operation_t *operation, |
| 1117 | uint8_t *hash, |
| 1118 | size_t hash_size, |
| 1119 | size_t *hash_length); |
| 1120 | |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 1121 | /** Finish the calculation of the hash of a message and compare it with |
| 1122 | * an expected value. |
| 1123 | * |
Gilles Peskine | da8191d1c | 2018-07-08 19:46:38 +0200 | [diff] [blame] | 1124 | * The application must call psa_hash_setup() before calling this function. |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 1125 | * This function calculates the hash of the message formed by concatenating |
| 1126 | * the inputs passed to preceding calls to psa_hash_update(). It then |
| 1127 | * compares the calculated hash with the expected hash passed as a |
| 1128 | * parameter to this function. |
| 1129 | * |
| 1130 | * When this function returns, the operation becomes inactive. |
| 1131 | * |
Gilles Peskine | 1906798 | 2018-03-20 17:54:53 +0100 | [diff] [blame] | 1132 | * \note Implementations shall make the best effort to ensure that the |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 1133 | * comparison between the actual hash and the expected hash is performed |
| 1134 | * in constant time. |
| 1135 | * |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 1136 | * \param[in,out] operation Active hash operation. |
| 1137 | * \param[in] hash Buffer containing the expected hash value. |
Gilles Peskine | fa4070c | 2018-07-12 19:23:03 +0200 | [diff] [blame] | 1138 | * \param hash_length Size of the \p hash buffer in bytes. |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 1139 | * |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 1140 | * \retval #PSA_SUCCESS |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 1141 | * The expected hash is identical to the actual hash of the message. |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 1142 | * \retval #PSA_ERROR_INVALID_SIGNATURE |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 1143 | * The hash of the message was calculated successfully, but it |
| 1144 | * differs from the expected hash. |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 1145 | * \retval #PSA_ERROR_BAD_STATE |
Gilles Peskine | f45adda | 2019-01-14 18:29:18 +0100 | [diff] [blame] | 1146 | * The operation state is not valid (not set up, or already completed). |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 1147 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 1148 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 1149 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 1150 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 1151 | */ |
Gilles Peskine | 9ef733f | 2018-02-07 21:05:37 +0100 | [diff] [blame] | 1152 | psa_status_t psa_hash_verify(psa_hash_operation_t *operation, |
| 1153 | const uint8_t *hash, |
| 1154 | size_t hash_length); |
| 1155 | |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 1156 | /** Abort a hash operation. |
| 1157 | * |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 1158 | * Aborting an operation frees all associated resources except for the |
Gilles Peskine | b82ab6f | 2018-07-13 15:33:43 +0200 | [diff] [blame] | 1159 | * \p operation structure itself. Once aborted, the operation object |
| 1160 | * can be reused for another operation by calling |
| 1161 | * psa_hash_setup() again. |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 1162 | * |
Gilles Peskine | b82ab6f | 2018-07-13 15:33:43 +0200 | [diff] [blame] | 1163 | * You may call this function any time after the operation object has |
| 1164 | * been initialized by any of the following methods: |
| 1165 | * - A call to psa_hash_setup(), whether it succeeds or not. |
| 1166 | * - Initializing the \c struct to all-bits-zero. |
| 1167 | * - Initializing the \c struct to logical zeros, e.g. |
| 1168 | * `psa_hash_operation_t operation = {0}`. |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 1169 | * |
Gilles Peskine | b82ab6f | 2018-07-13 15:33:43 +0200 | [diff] [blame] | 1170 | * In particular, calling psa_hash_abort() after the operation has been |
| 1171 | * terminated by a call to psa_hash_abort(), psa_hash_finish() or |
| 1172 | * psa_hash_verify() is safe and has no effect. |
| 1173 | * |
| 1174 | * \param[in,out] operation Initialized hash operation. |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 1175 | * |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 1176 | * \retval #PSA_SUCCESS |
| 1177 | * \retval #PSA_ERROR_BAD_STATE |
Gilles Peskine | fa4070c | 2018-07-12 19:23:03 +0200 | [diff] [blame] | 1178 | * \p operation is not an active hash operation. |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 1179 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 1180 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 1181 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 1182 | */ |
| 1183 | psa_status_t psa_hash_abort(psa_hash_operation_t *operation); |
Gilles Peskine | 9ef733f | 2018-02-07 21:05:37 +0100 | [diff] [blame] | 1184 | |
Gilles Peskine | ebb2c3e | 2019-01-19 12:03:41 +0100 | [diff] [blame] | 1185 | /** Clone a hash operation. |
| 1186 | * |
Gilles Peskine | e43aa39 | 2019-01-21 14:50:37 +0100 | [diff] [blame] | 1187 | * This function copies the state of an ongoing hash operation to |
| 1188 | * a new operation object. In other words, this function is equivalent |
| 1189 | * to calling psa_hash_setup() on \p target_operation with the same |
| 1190 | * algorithm that \p source_operation was set up for, then |
| 1191 | * psa_hash_update() on \p target_operation with the same input that |
| 1192 | * that was passed to \p source_operation. After this function returns, the |
| 1193 | * two objects are independent, i.e. subsequent calls involving one of |
| 1194 | * the objects do not affect the other object. |
| 1195 | * |
Gilles Peskine | ebb2c3e | 2019-01-19 12:03:41 +0100 | [diff] [blame] | 1196 | * \param[in] source_operation The active hash operation to clone. |
| 1197 | * \param[in,out] target_operation The operation object to set up. |
| 1198 | * It must be initialized but not active. |
| 1199 | * |
| 1200 | * \retval #PSA_SUCCESS |
| 1201 | * \retval #PSA_ERROR_BAD_STATE |
| 1202 | * \p source_operation is not an active hash operation. |
| 1203 | * \retval #PSA_ERROR_BAD_STATE |
Gilles Peskine | e43aa39 | 2019-01-21 14:50:37 +0100 | [diff] [blame] | 1204 | * \p target_operation is active. |
Gilles Peskine | ebb2c3e | 2019-01-19 12:03:41 +0100 | [diff] [blame] | 1205 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 1206 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 1207 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 1208 | */ |
| 1209 | psa_status_t psa_hash_clone(const psa_hash_operation_t *source_operation, |
| 1210 | psa_hash_operation_t *target_operation); |
| 1211 | |
Gilles Peskine | 9ef733f | 2018-02-07 21:05:37 +0100 | [diff] [blame] | 1212 | /**@}*/ |
| 1213 | |
Gilles Peskine | 8c9def3 | 2018-02-08 10:02:12 +0100 | [diff] [blame] | 1214 | /** \defgroup MAC Message authentication codes |
| 1215 | * @{ |
| 1216 | */ |
| 1217 | |
Gilles Peskine | 69647a4 | 2019-01-14 20:18:12 +0100 | [diff] [blame] | 1218 | /** Calculate the MAC (message authentication code) of a message. |
| 1219 | * |
| 1220 | * \note To verify the MAC of a message against an |
| 1221 | * expected value, use psa_mac_verify() instead. |
| 1222 | * Beware that comparing integrity or authenticity data such as |
| 1223 | * MAC values with a function such as \c memcmp is risky |
| 1224 | * because the time taken by the comparison may leak information |
| 1225 | * about the MAC value which could allow an attacker to guess |
| 1226 | * a valid MAC and thereby bypass security controls. |
| 1227 | * |
| 1228 | * \param handle Handle to the key to use for the operation. |
| 1229 | * \param alg The MAC algorithm to compute (\c PSA_ALG_XXX value |
Gilles Peskine | 63f7930 | 2019-02-15 13:01:17 +0100 | [diff] [blame] | 1230 | * such that #PSA_ALG_IS_MAC(\p alg) is true). |
Gilles Peskine | 69647a4 | 2019-01-14 20:18:12 +0100 | [diff] [blame] | 1231 | * \param[in] input Buffer containing the input message. |
| 1232 | * \param input_length Size of the \p input buffer in bytes. |
| 1233 | * \param[out] mac Buffer where the MAC value is to be written. |
| 1234 | * \param mac_size Size of the \p mac buffer in bytes. |
| 1235 | * \param[out] mac_length On success, the number of bytes |
Gilles Peskine | d338b91 | 2019-02-15 13:01:41 +0100 | [diff] [blame] | 1236 | * that make up the MAC value. |
Gilles Peskine | 69647a4 | 2019-01-14 20:18:12 +0100 | [diff] [blame] | 1237 | * |
| 1238 | * \retval #PSA_SUCCESS |
| 1239 | * Success. |
| 1240 | * \retval #PSA_ERROR_INVALID_HANDLE |
| 1241 | * \retval #PSA_ERROR_EMPTY_SLOT |
| 1242 | * \retval #PSA_ERROR_NOT_PERMITTED |
| 1243 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
Gilles Peskine | 3be6b7f | 2019-03-05 19:32:26 +0100 | [diff] [blame] | 1244 | * \p handle is not compatible with \p alg. |
Gilles Peskine | 69647a4 | 2019-01-14 20:18:12 +0100 | [diff] [blame] | 1245 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 1246 | * \p alg is not supported or is not a MAC algorithm. |
| 1247 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 1248 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 1249 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 1250 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 1251 | * \retval #PSA_ERROR_BAD_STATE |
| 1252 | * The library has not been previously initialized by psa_crypto_init(). |
| 1253 | * It is implementation-dependent whether a failure to initialize |
| 1254 | * results in this error code. |
| 1255 | */ |
| 1256 | psa_status_t psa_mac_compute(psa_key_handle_t handle, |
| 1257 | psa_algorithm_t alg, |
| 1258 | const uint8_t *input, |
| 1259 | size_t input_length, |
| 1260 | uint8_t *mac, |
| 1261 | size_t mac_size, |
| 1262 | size_t *mac_length); |
| 1263 | |
| 1264 | /** Calculate the MAC of a message and compare it with a reference value. |
| 1265 | * |
| 1266 | * \param handle Handle to the key to use for the operation. |
| 1267 | * \param alg The MAC algorithm to compute (\c PSA_ALG_XXX value |
Gilles Peskine | 63f7930 | 2019-02-15 13:01:17 +0100 | [diff] [blame] | 1268 | * such that #PSA_ALG_IS_MAC(\p alg) is true). |
Gilles Peskine | 69647a4 | 2019-01-14 20:18:12 +0100 | [diff] [blame] | 1269 | * \param[in] input Buffer containing the input message. |
| 1270 | * \param input_length Size of the \p input buffer in bytes. |
| 1271 | * \param[out] mac Buffer containing the expected MAC value. |
| 1272 | * \param mac_length Size of the \p mac buffer in bytes. |
| 1273 | * |
| 1274 | * \retval #PSA_SUCCESS |
| 1275 | * The expected MAC is identical to the actual MAC of the input. |
| 1276 | * \retval #PSA_ERROR_INVALID_SIGNATURE |
| 1277 | * The MAC of the message was calculated successfully, but it |
| 1278 | * differs from the expected value. |
| 1279 | * \retval #PSA_ERROR_INVALID_HANDLE |
| 1280 | * \retval #PSA_ERROR_EMPTY_SLOT |
| 1281 | * \retval #PSA_ERROR_NOT_PERMITTED |
| 1282 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
Gilles Peskine | 3be6b7f | 2019-03-05 19:32:26 +0100 | [diff] [blame] | 1283 | * \p handle is not compatible with \p alg. |
Gilles Peskine | 69647a4 | 2019-01-14 20:18:12 +0100 | [diff] [blame] | 1284 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 1285 | * \p alg is not supported or is not a MAC algorithm. |
| 1286 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 1287 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 1288 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 1289 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 1290 | */ |
Gilles Peskine | a05602d | 2019-01-17 15:25:52 +0100 | [diff] [blame] | 1291 | psa_status_t psa_mac_verify(psa_key_handle_t handle, |
| 1292 | psa_algorithm_t alg, |
Gilles Peskine | 69647a4 | 2019-01-14 20:18:12 +0100 | [diff] [blame] | 1293 | const uint8_t *input, |
| 1294 | size_t input_length, |
| 1295 | const uint8_t *mac, |
| 1296 | const size_t mac_length); |
| 1297 | |
Gilles Peskine | 7e4acc5 | 2018-02-16 21:24:11 +0100 | [diff] [blame] | 1298 | /** The type of the state data structure for multipart MAC operations. |
| 1299 | * |
Jaeden Amero | 769ce27 | 2019-01-04 11:48:03 +0000 | [diff] [blame] | 1300 | * Before calling any function on a MAC operation object, the application must |
| 1301 | * initialize it by any of the following means: |
| 1302 | * - Set the structure to all-bits-zero, for example: |
| 1303 | * \code |
| 1304 | * psa_mac_operation_t operation; |
| 1305 | * memset(&operation, 0, sizeof(operation)); |
| 1306 | * \endcode |
| 1307 | * - Initialize the structure to logical zero values, for example: |
| 1308 | * \code |
| 1309 | * psa_mac_operation_t operation = {0}; |
| 1310 | * \endcode |
| 1311 | * - Initialize the structure to the initializer #PSA_MAC_OPERATION_INIT, |
| 1312 | * for example: |
| 1313 | * \code |
| 1314 | * psa_mac_operation_t operation = PSA_MAC_OPERATION_INIT; |
| 1315 | * \endcode |
| 1316 | * - Assign the result of the function psa_mac_operation_init() |
| 1317 | * to the structure, for example: |
| 1318 | * \code |
| 1319 | * psa_mac_operation_t operation; |
| 1320 | * operation = psa_mac_operation_init(); |
| 1321 | * \endcode |
| 1322 | * |
Gilles Peskine | 92b3073 | 2018-03-03 21:29:30 +0100 | [diff] [blame] | 1323 | * This is an implementation-defined \c struct. Applications should not |
Gilles Peskine | 7e4acc5 | 2018-02-16 21:24:11 +0100 | [diff] [blame] | 1324 | * make any assumptions about the content of this structure except |
| 1325 | * as directed by the documentation of a specific implementation. */ |
Gilles Peskine | 8c9def3 | 2018-02-08 10:02:12 +0100 | [diff] [blame] | 1326 | typedef struct psa_mac_operation_s psa_mac_operation_t; |
| 1327 | |
Jaeden Amero | 769ce27 | 2019-01-04 11:48:03 +0000 | [diff] [blame] | 1328 | /** \def PSA_MAC_OPERATION_INIT |
| 1329 | * |
| 1330 | * This macro returns a suitable initializer for a MAC operation object of type |
| 1331 | * #psa_mac_operation_t. |
| 1332 | */ |
| 1333 | #ifdef __DOXYGEN_ONLY__ |
| 1334 | /* This is an example definition for documentation purposes. |
| 1335 | * Implementations should define a suitable value in `crypto_struct.h`. |
| 1336 | */ |
| 1337 | #define PSA_MAC_OPERATION_INIT {0} |
| 1338 | #endif |
| 1339 | |
| 1340 | /** Return an initial value for a MAC operation object. |
| 1341 | */ |
| 1342 | static psa_mac_operation_t psa_mac_operation_init(void); |
| 1343 | |
Gilles Peskine | f45adda | 2019-01-14 18:29:18 +0100 | [diff] [blame] | 1344 | /** Set up a multipart MAC calculation operation. |
Gilles Peskine | 7e4acc5 | 2018-02-16 21:24:11 +0100 | [diff] [blame] | 1345 | * |
Gilles Peskine | 89167cb | 2018-07-08 20:12:23 +0200 | [diff] [blame] | 1346 | * This function sets up the calculation of the MAC |
| 1347 | * (message authentication code) of a byte string. |
| 1348 | * To verify the MAC of a message against an |
| 1349 | * expected value, use psa_mac_verify_setup() instead. |
| 1350 | * |
| 1351 | * The sequence of operations to calculate a MAC is as follows: |
Gilles Peskine | 7e4acc5 | 2018-02-16 21:24:11 +0100 | [diff] [blame] | 1352 | * -# Allocate an operation object which will be passed to all the functions |
| 1353 | * listed here. |
Jaeden Amero | 769ce27 | 2019-01-04 11:48:03 +0000 | [diff] [blame] | 1354 | * -# Initialize the operation object with one of the methods described in the |
| 1355 | * documentation for #psa_mac_operation_t, e.g. PSA_MAC_OPERATION_INIT. |
Gilles Peskine | 89167cb | 2018-07-08 20:12:23 +0200 | [diff] [blame] | 1356 | * -# Call psa_mac_sign_setup() to specify the algorithm and key. |
Gilles Peskine | 7e4acc5 | 2018-02-16 21:24:11 +0100 | [diff] [blame] | 1357 | * -# Call psa_mac_update() zero, one or more times, passing a fragment |
| 1358 | * of the message each time. The MAC that is calculated is the MAC |
| 1359 | * of the concatenation of these messages in order. |
Gilles Peskine | 89167cb | 2018-07-08 20:12:23 +0200 | [diff] [blame] | 1360 | * -# At the end of the message, call psa_mac_sign_finish() to finish |
| 1361 | * calculating the MAC value and retrieve it. |
Gilles Peskine | 7e4acc5 | 2018-02-16 21:24:11 +0100 | [diff] [blame] | 1362 | * |
| 1363 | * The application may call psa_mac_abort() at any time after the operation |
Jaeden Amero | 769ce27 | 2019-01-04 11:48:03 +0000 | [diff] [blame] | 1364 | * has been initialized. |
Gilles Peskine | 7e4acc5 | 2018-02-16 21:24:11 +0100 | [diff] [blame] | 1365 | * |
Gilles Peskine | 89167cb | 2018-07-08 20:12:23 +0200 | [diff] [blame] | 1366 | * After a successful call to psa_mac_sign_setup(), the application must |
| 1367 | * eventually terminate the operation through one of the following methods: |
Gilles Peskine | 7e4acc5 | 2018-02-16 21:24:11 +0100 | [diff] [blame] | 1368 | * - A failed call to psa_mac_update(). |
Gilles Peskine | 89167cb | 2018-07-08 20:12:23 +0200 | [diff] [blame] | 1369 | * - A call to psa_mac_sign_finish() or psa_mac_abort(). |
Gilles Peskine | 7e4acc5 | 2018-02-16 21:24:11 +0100 | [diff] [blame] | 1370 | * |
Jaeden Amero | 769ce27 | 2019-01-04 11:48:03 +0000 | [diff] [blame] | 1371 | * \param[in,out] operation The operation object to set up. It must have |
| 1372 | * been initialized as per the documentation for |
| 1373 | * #psa_mac_operation_t and not yet in use. |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 1374 | * \param handle Handle to the key to use for the operation. |
Gilles Peskine | 5f25dd0 | 2019-01-14 18:24:53 +0100 | [diff] [blame] | 1375 | * It must remain valid until the operation |
| 1376 | * terminates. |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 1377 | * \param alg The MAC algorithm to compute (\c PSA_ALG_XXX value |
Gilles Peskine | 63f7930 | 2019-02-15 13:01:17 +0100 | [diff] [blame] | 1378 | * such that #PSA_ALG_IS_MAC(\p alg) is true). |
Gilles Peskine | 7e4acc5 | 2018-02-16 21:24:11 +0100 | [diff] [blame] | 1379 | * |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 1380 | * \retval #PSA_SUCCESS |
Gilles Peskine | 7e4acc5 | 2018-02-16 21:24:11 +0100 | [diff] [blame] | 1381 | * Success. |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 1382 | * \retval #PSA_ERROR_INVALID_HANDLE |
David Saada | b4ecc27 | 2019-02-14 13:48:10 +0200 | [diff] [blame] | 1383 | * \retval #PSA_ERROR_DOES_NOT_EXIST |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 1384 | * \retval #PSA_ERROR_NOT_PERMITTED |
| 1385 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
Gilles Peskine | 3be6b7f | 2019-03-05 19:32:26 +0100 | [diff] [blame] | 1386 | * \p handle is not compatible with \p alg. |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 1387 | * \retval #PSA_ERROR_NOT_SUPPORTED |
Gilles Peskine | fa4070c | 2018-07-12 19:23:03 +0200 | [diff] [blame] | 1388 | * \p alg is not supported or is not a MAC algorithm. |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 1389 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 1390 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 1391 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 1392 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
itayzafrir | 90d8c7a | 2018-09-12 11:44:52 +0300 | [diff] [blame] | 1393 | * \retval #PSA_ERROR_BAD_STATE |
Gilles Peskine | 8e1addc | 2019-01-10 11:51:17 +0100 | [diff] [blame] | 1394 | * The operation state is not valid (already set up and not |
| 1395 | * subsequently completed). |
| 1396 | * \retval #PSA_ERROR_BAD_STATE |
itayzafrir | 1861709 | 2018-09-16 12:22:41 +0300 | [diff] [blame] | 1397 | * The library has not been previously initialized by psa_crypto_init(). |
| 1398 | * It is implementation-dependent whether a failure to initialize |
| 1399 | * results in this error code. |
Gilles Peskine | 7e4acc5 | 2018-02-16 21:24:11 +0100 | [diff] [blame] | 1400 | */ |
Gilles Peskine | 89167cb | 2018-07-08 20:12:23 +0200 | [diff] [blame] | 1401 | psa_status_t psa_mac_sign_setup(psa_mac_operation_t *operation, |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 1402 | psa_key_handle_t handle, |
Gilles Peskine | 89167cb | 2018-07-08 20:12:23 +0200 | [diff] [blame] | 1403 | psa_algorithm_t alg); |
| 1404 | |
Gilles Peskine | f45adda | 2019-01-14 18:29:18 +0100 | [diff] [blame] | 1405 | /** Set up a multipart MAC verification operation. |
Gilles Peskine | 89167cb | 2018-07-08 20:12:23 +0200 | [diff] [blame] | 1406 | * |
| 1407 | * This function sets up the verification of the MAC |
| 1408 | * (message authentication code) of a byte string against an expected value. |
| 1409 | * |
| 1410 | * The sequence of operations to verify a MAC is as follows: |
| 1411 | * -# Allocate an operation object which will be passed to all the functions |
| 1412 | * listed here. |
Jaeden Amero | 769ce27 | 2019-01-04 11:48:03 +0000 | [diff] [blame] | 1413 | * -# Initialize the operation object with one of the methods described in the |
| 1414 | * documentation for #psa_mac_operation_t, e.g. PSA_MAC_OPERATION_INIT. |
Gilles Peskine | 89167cb | 2018-07-08 20:12:23 +0200 | [diff] [blame] | 1415 | * -# Call psa_mac_verify_setup() to specify the algorithm and key. |
Gilles Peskine | 89167cb | 2018-07-08 20:12:23 +0200 | [diff] [blame] | 1416 | * -# Call psa_mac_update() zero, one or more times, passing a fragment |
| 1417 | * of the message each time. The MAC that is calculated is the MAC |
| 1418 | * of the concatenation of these messages in order. |
| 1419 | * -# At the end of the message, call psa_mac_verify_finish() to finish |
| 1420 | * calculating the actual MAC of the message and verify it against |
| 1421 | * the expected value. |
| 1422 | * |
| 1423 | * The application may call psa_mac_abort() at any time after the operation |
Jaeden Amero | 769ce27 | 2019-01-04 11:48:03 +0000 | [diff] [blame] | 1424 | * has been initialized. |
Gilles Peskine | 89167cb | 2018-07-08 20:12:23 +0200 | [diff] [blame] | 1425 | * |
| 1426 | * After a successful call to psa_mac_verify_setup(), the application must |
| 1427 | * eventually terminate the operation through one of the following methods: |
| 1428 | * - A failed call to psa_mac_update(). |
| 1429 | * - A call to psa_mac_verify_finish() or psa_mac_abort(). |
| 1430 | * |
Jaeden Amero | 769ce27 | 2019-01-04 11:48:03 +0000 | [diff] [blame] | 1431 | * \param[in,out] operation The operation object to set up. It must have |
| 1432 | * been initialized as per the documentation for |
| 1433 | * #psa_mac_operation_t and not yet in use. |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 1434 | * \param handle Handle to the key to use for the operation. |
Gilles Peskine | 5f25dd0 | 2019-01-14 18:24:53 +0100 | [diff] [blame] | 1435 | * It must remain valid until the operation |
| 1436 | * terminates. |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 1437 | * \param alg The MAC algorithm to compute (\c PSA_ALG_XXX value |
| 1438 | * such that #PSA_ALG_IS_MAC(\p alg) is true). |
Gilles Peskine | 89167cb | 2018-07-08 20:12:23 +0200 | [diff] [blame] | 1439 | * |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 1440 | * \retval #PSA_SUCCESS |
Gilles Peskine | 89167cb | 2018-07-08 20:12:23 +0200 | [diff] [blame] | 1441 | * Success. |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 1442 | * \retval #PSA_ERROR_INVALID_HANDLE |
David Saada | b4ecc27 | 2019-02-14 13:48:10 +0200 | [diff] [blame] | 1443 | * \retval #PSA_ERROR_DOES_NOT_EXIST |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 1444 | * \retval #PSA_ERROR_NOT_PERMITTED |
| 1445 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
Gilles Peskine | 89167cb | 2018-07-08 20:12:23 +0200 | [diff] [blame] | 1446 | * \c key is not compatible with \c alg. |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 1447 | * \retval #PSA_ERROR_NOT_SUPPORTED |
Gilles Peskine | 89167cb | 2018-07-08 20:12:23 +0200 | [diff] [blame] | 1448 | * \c alg is not supported or is not a MAC algorithm. |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 1449 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 1450 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 1451 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 1452 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
itayzafrir | 90d8c7a | 2018-09-12 11:44:52 +0300 | [diff] [blame] | 1453 | * \retval #PSA_ERROR_BAD_STATE |
Gilles Peskine | 8e1addc | 2019-01-10 11:51:17 +0100 | [diff] [blame] | 1454 | * The operation state is not valid (already set up and not |
| 1455 | * subsequently completed). |
| 1456 | * \retval #PSA_ERROR_BAD_STATE |
itayzafrir | 1861709 | 2018-09-16 12:22:41 +0300 | [diff] [blame] | 1457 | * The library has not been previously initialized by psa_crypto_init(). |
| 1458 | * It is implementation-dependent whether a failure to initialize |
| 1459 | * results in this error code. |
Gilles Peskine | 89167cb | 2018-07-08 20:12:23 +0200 | [diff] [blame] | 1460 | */ |
| 1461 | psa_status_t psa_mac_verify_setup(psa_mac_operation_t *operation, |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 1462 | psa_key_handle_t handle, |
Gilles Peskine | 89167cb | 2018-07-08 20:12:23 +0200 | [diff] [blame] | 1463 | psa_algorithm_t alg); |
Gilles Peskine | 8c9def3 | 2018-02-08 10:02:12 +0100 | [diff] [blame] | 1464 | |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 1465 | /** Add a message fragment to a multipart MAC operation. |
| 1466 | * |
| 1467 | * The application must call psa_mac_sign_setup() or psa_mac_verify_setup() |
| 1468 | * before calling this function. |
| 1469 | * |
| 1470 | * If this function returns an error status, the operation becomes inactive. |
| 1471 | * |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 1472 | * \param[in,out] operation Active MAC operation. |
| 1473 | * \param[in] input Buffer containing the message fragment to add to |
| 1474 | * the MAC calculation. |
Gilles Peskine | fa4070c | 2018-07-12 19:23:03 +0200 | [diff] [blame] | 1475 | * \param input_length Size of the \p input buffer in bytes. |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 1476 | * |
| 1477 | * \retval #PSA_SUCCESS |
| 1478 | * Success. |
| 1479 | * \retval #PSA_ERROR_BAD_STATE |
Gilles Peskine | f45adda | 2019-01-14 18:29:18 +0100 | [diff] [blame] | 1480 | * The operation state is not valid (not set up, or already completed). |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 1481 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 1482 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 1483 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 1484 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 1485 | */ |
Gilles Peskine | 8c9def3 | 2018-02-08 10:02:12 +0100 | [diff] [blame] | 1486 | psa_status_t psa_mac_update(psa_mac_operation_t *operation, |
| 1487 | const uint8_t *input, |
| 1488 | size_t input_length); |
| 1489 | |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 1490 | /** Finish the calculation of the MAC of a message. |
| 1491 | * |
| 1492 | * The application must call psa_mac_sign_setup() before calling this function. |
| 1493 | * This function calculates the MAC of the message formed by concatenating |
| 1494 | * the inputs passed to preceding calls to psa_mac_update(). |
| 1495 | * |
| 1496 | * When this function returns, the operation becomes inactive. |
| 1497 | * |
| 1498 | * \warning Applications should not call this function if they expect |
| 1499 | * a specific value for the MAC. Call psa_mac_verify_finish() instead. |
| 1500 | * Beware that comparing integrity or authenticity data such as |
| 1501 | * MAC values with a function such as \c memcmp is risky |
| 1502 | * because the time taken by the comparison may leak information |
| 1503 | * about the MAC value which could allow an attacker to guess |
| 1504 | * a valid MAC and thereby bypass security controls. |
| 1505 | * |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 1506 | * \param[in,out] operation Active MAC operation. |
| 1507 | * \param[out] mac Buffer where the MAC value is to be written. |
| 1508 | * \param mac_size Size of the \p mac buffer in bytes. |
| 1509 | * \param[out] mac_length On success, the number of bytes |
| 1510 | * that make up the MAC value. This is always |
Gilles Peskine | dda3bd3 | 2018-07-12 19:40:46 +0200 | [diff] [blame] | 1511 | * #PSA_MAC_FINAL_SIZE(\c key_type, \c key_bits, \c alg) |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 1512 | * where \c key_type and \c key_bits are the type and |
Gilles Peskine | dda3bd3 | 2018-07-12 19:40:46 +0200 | [diff] [blame] | 1513 | * bit-size respectively of the key and \c alg is the |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 1514 | * MAC algorithm that is calculated. |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 1515 | * |
| 1516 | * \retval #PSA_SUCCESS |
| 1517 | * Success. |
| 1518 | * \retval #PSA_ERROR_BAD_STATE |
Gilles Peskine | f45adda | 2019-01-14 18:29:18 +0100 | [diff] [blame] | 1519 | * The operation state is not valid (not set up, or already completed). |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 1520 | * \retval #PSA_ERROR_BUFFER_TOO_SMALL |
Gilles Peskine | fa4070c | 2018-07-12 19:23:03 +0200 | [diff] [blame] | 1521 | * The size of the \p mac buffer is too small. You can determine a |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 1522 | * sufficient buffer size by calling PSA_MAC_FINAL_SIZE(). |
| 1523 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 1524 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 1525 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 1526 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 1527 | */ |
Gilles Peskine | acd4be3 | 2018-07-08 19:56:25 +0200 | [diff] [blame] | 1528 | psa_status_t psa_mac_sign_finish(psa_mac_operation_t *operation, |
| 1529 | uint8_t *mac, |
| 1530 | size_t mac_size, |
| 1531 | size_t *mac_length); |
Gilles Peskine | 8c9def3 | 2018-02-08 10:02:12 +0100 | [diff] [blame] | 1532 | |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 1533 | /** Finish the calculation of the MAC of a message and compare it with |
| 1534 | * an expected value. |
| 1535 | * |
| 1536 | * The application must call psa_mac_verify_setup() before calling this function. |
| 1537 | * This function calculates the MAC of the message formed by concatenating |
| 1538 | * the inputs passed to preceding calls to psa_mac_update(). It then |
| 1539 | * compares the calculated MAC with the expected MAC passed as a |
| 1540 | * parameter to this function. |
| 1541 | * |
| 1542 | * When this function returns, the operation becomes inactive. |
| 1543 | * |
| 1544 | * \note Implementations shall make the best effort to ensure that the |
| 1545 | * comparison between the actual MAC and the expected MAC is performed |
| 1546 | * in constant time. |
| 1547 | * |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 1548 | * \param[in,out] operation Active MAC operation. |
| 1549 | * \param[in] mac Buffer containing the expected MAC value. |
Gilles Peskine | fa4070c | 2018-07-12 19:23:03 +0200 | [diff] [blame] | 1550 | * \param mac_length Size of the \p mac buffer in bytes. |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 1551 | * |
| 1552 | * \retval #PSA_SUCCESS |
| 1553 | * The expected MAC is identical to the actual MAC of the message. |
| 1554 | * \retval #PSA_ERROR_INVALID_SIGNATURE |
| 1555 | * The MAC of the message was calculated successfully, but it |
| 1556 | * differs from the expected MAC. |
| 1557 | * \retval #PSA_ERROR_BAD_STATE |
Gilles Peskine | f45adda | 2019-01-14 18:29:18 +0100 | [diff] [blame] | 1558 | * The operation state is not valid (not set up, or already completed). |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 1559 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 1560 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 1561 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 1562 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 1563 | */ |
Gilles Peskine | acd4be3 | 2018-07-08 19:56:25 +0200 | [diff] [blame] | 1564 | psa_status_t psa_mac_verify_finish(psa_mac_operation_t *operation, |
| 1565 | const uint8_t *mac, |
| 1566 | size_t mac_length); |
Gilles Peskine | 8c9def3 | 2018-02-08 10:02:12 +0100 | [diff] [blame] | 1567 | |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 1568 | /** Abort a MAC operation. |
| 1569 | * |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 1570 | * Aborting an operation frees all associated resources except for the |
Gilles Peskine | b82ab6f | 2018-07-13 15:33:43 +0200 | [diff] [blame] | 1571 | * \p operation structure itself. Once aborted, the operation object |
| 1572 | * can be reused for another operation by calling |
| 1573 | * psa_mac_sign_setup() or psa_mac_verify_setup() again. |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 1574 | * |
Gilles Peskine | b82ab6f | 2018-07-13 15:33:43 +0200 | [diff] [blame] | 1575 | * You may call this function any time after the operation object has |
| 1576 | * been initialized by any of the following methods: |
| 1577 | * - A call to psa_mac_sign_setup() or psa_mac_verify_setup(), whether |
| 1578 | * it succeeds or not. |
| 1579 | * - Initializing the \c struct to all-bits-zero. |
| 1580 | * - Initializing the \c struct to logical zeros, e.g. |
| 1581 | * `psa_mac_operation_t operation = {0}`. |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 1582 | * |
Gilles Peskine | b82ab6f | 2018-07-13 15:33:43 +0200 | [diff] [blame] | 1583 | * In particular, calling psa_mac_abort() after the operation has been |
| 1584 | * terminated by a call to psa_mac_abort(), psa_mac_sign_finish() or |
| 1585 | * psa_mac_verify_finish() is safe and has no effect. |
| 1586 | * |
| 1587 | * \param[in,out] operation Initialized MAC operation. |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 1588 | * |
| 1589 | * \retval #PSA_SUCCESS |
| 1590 | * \retval #PSA_ERROR_BAD_STATE |
Gilles Peskine | fa4070c | 2018-07-12 19:23:03 +0200 | [diff] [blame] | 1591 | * \p operation is not an active MAC operation. |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 1592 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 1593 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 1594 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 1595 | */ |
Gilles Peskine | 8c9def3 | 2018-02-08 10:02:12 +0100 | [diff] [blame] | 1596 | psa_status_t psa_mac_abort(psa_mac_operation_t *operation); |
| 1597 | |
| 1598 | /**@}*/ |
| 1599 | |
Gilles Peskine | 428dc5a | 2018-03-03 21:27:18 +0100 | [diff] [blame] | 1600 | /** \defgroup cipher Symmetric ciphers |
| 1601 | * @{ |
| 1602 | */ |
| 1603 | |
Gilles Peskine | 69647a4 | 2019-01-14 20:18:12 +0100 | [diff] [blame] | 1604 | /** Encrypt a message using a symmetric cipher. |
| 1605 | * |
| 1606 | * This function encrypts a message with a random IV (initialization |
| 1607 | * vector). |
| 1608 | * |
| 1609 | * \param handle Handle to the key to use for the operation. |
| 1610 | * It must remain valid until the operation |
| 1611 | * terminates. |
| 1612 | * \param alg The cipher algorithm to compute |
| 1613 | * (\c PSA_ALG_XXX value such that |
| 1614 | * #PSA_ALG_IS_CIPHER(\p alg) is true). |
| 1615 | * \param[in] input Buffer containing the message to encrypt. |
| 1616 | * \param input_length Size of the \p input buffer in bytes. |
| 1617 | * \param[out] output Buffer where the output is to be written. |
| 1618 | * The output contains the IV followed by |
| 1619 | * the ciphertext proper. |
| 1620 | * \param output_size Size of the \p output buffer in bytes. |
| 1621 | * \param[out] output_length On success, the number of bytes |
| 1622 | * that make up the output. |
| 1623 | * |
| 1624 | * \retval #PSA_SUCCESS |
| 1625 | * Success. |
| 1626 | * \retval #PSA_ERROR_INVALID_HANDLE |
| 1627 | * \retval #PSA_ERROR_EMPTY_SLOT |
| 1628 | * \retval #PSA_ERROR_NOT_PERMITTED |
| 1629 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
Gilles Peskine | 3be6b7f | 2019-03-05 19:32:26 +0100 | [diff] [blame] | 1630 | * \p handle is not compatible with \p alg. |
Gilles Peskine | 69647a4 | 2019-01-14 20:18:12 +0100 | [diff] [blame] | 1631 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 1632 | * \p alg is not supported or is not a cipher algorithm. |
| 1633 | * \retval #PSA_ERROR_BUFFER_TOO_SMALL |
| 1634 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 1635 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 1636 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 1637 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 1638 | */ |
| 1639 | psa_status_t psa_cipher_encrypt(psa_key_handle_t handle, |
| 1640 | psa_algorithm_t alg, |
| 1641 | const uint8_t *input, |
| 1642 | size_t input_length, |
| 1643 | uint8_t *output, |
| 1644 | size_t output_size, |
| 1645 | size_t *output_length); |
| 1646 | |
| 1647 | /** Decrypt a message using a symmetric cipher. |
| 1648 | * |
| 1649 | * This function decrypts a message encrypted with a symmetric cipher. |
| 1650 | * |
| 1651 | * \param handle Handle to the key to use for the operation. |
| 1652 | * It must remain valid until the operation |
| 1653 | * terminates. |
| 1654 | * \param alg The cipher algorithm to compute |
| 1655 | * (\c PSA_ALG_XXX value such that |
| 1656 | * #PSA_ALG_IS_CIPHER(\p alg) is true). |
| 1657 | * \param[in] input Buffer containing the message to decrypt. |
| 1658 | * This consists of the IV followed by the |
| 1659 | * ciphertext proper. |
| 1660 | * \param input_length Size of the \p input buffer in bytes. |
| 1661 | * \param[out] output Buffer where the plaintext is to be written. |
| 1662 | * \param output_size Size of the \p output buffer in bytes. |
| 1663 | * \param[out] output_length On success, the number of bytes |
| 1664 | * that make up the output. |
| 1665 | * |
| 1666 | * \retval #PSA_SUCCESS |
| 1667 | * Success. |
| 1668 | * \retval #PSA_ERROR_INVALID_HANDLE |
| 1669 | * \retval #PSA_ERROR_EMPTY_SLOT |
| 1670 | * \retval #PSA_ERROR_NOT_PERMITTED |
| 1671 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
Gilles Peskine | 3be6b7f | 2019-03-05 19:32:26 +0100 | [diff] [blame] | 1672 | * \p handle is not compatible with \p alg. |
Gilles Peskine | 69647a4 | 2019-01-14 20:18:12 +0100 | [diff] [blame] | 1673 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 1674 | * \p alg is not supported or is not a cipher algorithm. |
| 1675 | * \retval #PSA_ERROR_BUFFER_TOO_SMALL |
| 1676 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 1677 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 1678 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 1679 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 1680 | */ |
| 1681 | psa_status_t psa_cipher_decrypt(psa_key_handle_t handle, |
| 1682 | psa_algorithm_t alg, |
| 1683 | const uint8_t *input, |
| 1684 | size_t input_length, |
| 1685 | uint8_t *output, |
| 1686 | size_t output_size, |
| 1687 | size_t *output_length); |
| 1688 | |
Gilles Peskine | 428dc5a | 2018-03-03 21:27:18 +0100 | [diff] [blame] | 1689 | /** The type of the state data structure for multipart cipher operations. |
| 1690 | * |
Jaeden Amero | 5bae227 | 2019-01-04 11:48:27 +0000 | [diff] [blame] | 1691 | * Before calling any function on a cipher operation object, the application |
| 1692 | * must initialize it by any of the following means: |
| 1693 | * - Set the structure to all-bits-zero, for example: |
| 1694 | * \code |
| 1695 | * psa_cipher_operation_t operation; |
| 1696 | * memset(&operation, 0, sizeof(operation)); |
| 1697 | * \endcode |
| 1698 | * - Initialize the structure to logical zero values, for example: |
| 1699 | * \code |
| 1700 | * psa_cipher_operation_t operation = {0}; |
| 1701 | * \endcode |
| 1702 | * - Initialize the structure to the initializer #PSA_CIPHER_OPERATION_INIT, |
| 1703 | * for example: |
| 1704 | * \code |
| 1705 | * psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT; |
| 1706 | * \endcode |
| 1707 | * - Assign the result of the function psa_cipher_operation_init() |
| 1708 | * to the structure, for example: |
| 1709 | * \code |
| 1710 | * psa_cipher_operation_t operation; |
| 1711 | * operation = psa_cipher_operation_init(); |
| 1712 | * \endcode |
| 1713 | * |
Gilles Peskine | 428dc5a | 2018-03-03 21:27:18 +0100 | [diff] [blame] | 1714 | * This is an implementation-defined \c struct. Applications should not |
| 1715 | * make any assumptions about the content of this structure except |
| 1716 | * as directed by the documentation of a specific implementation. */ |
| 1717 | typedef struct psa_cipher_operation_s psa_cipher_operation_t; |
| 1718 | |
Jaeden Amero | 5bae227 | 2019-01-04 11:48:27 +0000 | [diff] [blame] | 1719 | /** \def PSA_CIPHER_OPERATION_INIT |
| 1720 | * |
| 1721 | * This macro returns a suitable initializer for a cipher operation object of |
| 1722 | * type #psa_cipher_operation_t. |
| 1723 | */ |
| 1724 | #ifdef __DOXYGEN_ONLY__ |
| 1725 | /* This is an example definition for documentation purposes. |
| 1726 | * Implementations should define a suitable value in `crypto_struct.h`. |
| 1727 | */ |
| 1728 | #define PSA_CIPHER_OPERATION_INIT {0} |
| 1729 | #endif |
| 1730 | |
| 1731 | /** Return an initial value for a cipher operation object. |
| 1732 | */ |
| 1733 | static psa_cipher_operation_t psa_cipher_operation_init(void); |
| 1734 | |
Gilles Peskine | 428dc5a | 2018-03-03 21:27:18 +0100 | [diff] [blame] | 1735 | /** Set the key for a multipart symmetric encryption operation. |
| 1736 | * |
| 1737 | * The sequence of operations to encrypt a message with a symmetric cipher |
| 1738 | * is as follows: |
| 1739 | * -# Allocate an operation object which will be passed to all the functions |
| 1740 | * listed here. |
Jaeden Amero | 5bae227 | 2019-01-04 11:48:27 +0000 | [diff] [blame] | 1741 | * -# Initialize the operation object with one of the methods described in the |
| 1742 | * documentation for #psa_cipher_operation_t, e.g. |
| 1743 | * PSA_CIPHER_OPERATION_INIT. |
Gilles Peskine | fe11951 | 2018-07-08 21:39:34 +0200 | [diff] [blame] | 1744 | * -# Call psa_cipher_encrypt_setup() to specify the algorithm and key. |
itayzafrir | ed7382f | 2018-08-02 14:19:33 +0300 | [diff] [blame] | 1745 | * -# Call either psa_cipher_generate_iv() or psa_cipher_set_iv() to |
Gilles Peskine | 428dc5a | 2018-03-03 21:27:18 +0100 | [diff] [blame] | 1746 | * generate or set the IV (initialization vector). You should use |
itayzafrir | ed7382f | 2018-08-02 14:19:33 +0300 | [diff] [blame] | 1747 | * psa_cipher_generate_iv() unless the protocol you are implementing |
Gilles Peskine | 428dc5a | 2018-03-03 21:27:18 +0100 | [diff] [blame] | 1748 | * requires a specific IV value. |
| 1749 | * -# Call psa_cipher_update() zero, one or more times, passing a fragment |
| 1750 | * of the message each time. |
| 1751 | * -# Call psa_cipher_finish(). |
| 1752 | * |
| 1753 | * The application may call psa_cipher_abort() at any time after the operation |
Jaeden Amero | 5bae227 | 2019-01-04 11:48:27 +0000 | [diff] [blame] | 1754 | * has been initialized. |
Gilles Peskine | 428dc5a | 2018-03-03 21:27:18 +0100 | [diff] [blame] | 1755 | * |
Gilles Peskine | fe11951 | 2018-07-08 21:39:34 +0200 | [diff] [blame] | 1756 | * After a successful call to psa_cipher_encrypt_setup(), the application must |
Gilles Peskine | ed52297 | 2018-03-20 17:54:15 +0100 | [diff] [blame] | 1757 | * eventually terminate the operation. The following events terminate an |
| 1758 | * operation: |
Gilles Peskine | f45adda | 2019-01-14 18:29:18 +0100 | [diff] [blame] | 1759 | * - A failed call to any of the \c psa_cipher_xxx functions. |
Gilles Peskine | 1906798 | 2018-03-20 17:54:53 +0100 | [diff] [blame] | 1760 | * - A call to psa_cipher_finish() or psa_cipher_abort(). |
Gilles Peskine | 428dc5a | 2018-03-03 21:27:18 +0100 | [diff] [blame] | 1761 | * |
Jaeden Amero | 5bae227 | 2019-01-04 11:48:27 +0000 | [diff] [blame] | 1762 | * \param[in,out] operation The operation object to set up. It must have |
| 1763 | * been initialized as per the documentation for |
| 1764 | * #psa_cipher_operation_t and not yet in use. |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 1765 | * \param handle Handle to the key to use for the operation. |
Gilles Peskine | 5f25dd0 | 2019-01-14 18:24:53 +0100 | [diff] [blame] | 1766 | * It must remain valid until the operation |
| 1767 | * terminates. |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 1768 | * \param alg The cipher algorithm to compute |
| 1769 | * (\c PSA_ALG_XXX value such that |
| 1770 | * #PSA_ALG_IS_CIPHER(\p alg) is true). |
Gilles Peskine | 428dc5a | 2018-03-03 21:27:18 +0100 | [diff] [blame] | 1771 | * |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 1772 | * \retval #PSA_SUCCESS |
Gilles Peskine | 428dc5a | 2018-03-03 21:27:18 +0100 | [diff] [blame] | 1773 | * Success. |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 1774 | * \retval #PSA_ERROR_INVALID_HANDLE |
David Saada | b4ecc27 | 2019-02-14 13:48:10 +0200 | [diff] [blame] | 1775 | * \retval #PSA_ERROR_DOES_NOT_EXIST |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 1776 | * \retval #PSA_ERROR_NOT_PERMITTED |
| 1777 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
Gilles Peskine | 3be6b7f | 2019-03-05 19:32:26 +0100 | [diff] [blame] | 1778 | * \p handle is not compatible with \p alg. |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 1779 | * \retval #PSA_ERROR_NOT_SUPPORTED |
Gilles Peskine | fa4070c | 2018-07-12 19:23:03 +0200 | [diff] [blame] | 1780 | * \p alg is not supported or is not a cipher algorithm. |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 1781 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 1782 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 1783 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 1784 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
itayzafrir | 90d8c7a | 2018-09-12 11:44:52 +0300 | [diff] [blame] | 1785 | * \retval #PSA_ERROR_BAD_STATE |
Gilles Peskine | 8e1addc | 2019-01-10 11:51:17 +0100 | [diff] [blame] | 1786 | * The operation state is not valid (already set up and not |
| 1787 | * subsequently completed). |
| 1788 | * \retval #PSA_ERROR_BAD_STATE |
itayzafrir | 1861709 | 2018-09-16 12:22:41 +0300 | [diff] [blame] | 1789 | * The library has not been previously initialized by psa_crypto_init(). |
| 1790 | * It is implementation-dependent whether a failure to initialize |
| 1791 | * results in this error code. |
Gilles Peskine | 428dc5a | 2018-03-03 21:27:18 +0100 | [diff] [blame] | 1792 | */ |
Gilles Peskine | fe11951 | 2018-07-08 21:39:34 +0200 | [diff] [blame] | 1793 | psa_status_t psa_cipher_encrypt_setup(psa_cipher_operation_t *operation, |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 1794 | psa_key_handle_t handle, |
Gilles Peskine | fe11951 | 2018-07-08 21:39:34 +0200 | [diff] [blame] | 1795 | psa_algorithm_t alg); |
Gilles Peskine | 428dc5a | 2018-03-03 21:27:18 +0100 | [diff] [blame] | 1796 | |
| 1797 | /** Set the key for a multipart symmetric decryption operation. |
| 1798 | * |
| 1799 | * The sequence of operations to decrypt a message with a symmetric cipher |
| 1800 | * is as follows: |
| 1801 | * -# Allocate an operation object which will be passed to all the functions |
| 1802 | * listed here. |
Jaeden Amero | 5bae227 | 2019-01-04 11:48:27 +0000 | [diff] [blame] | 1803 | * -# Initialize the operation object with one of the methods described in the |
| 1804 | * documentation for #psa_cipher_operation_t, e.g. |
| 1805 | * PSA_CIPHER_OPERATION_INIT. |
Gilles Peskine | fe11951 | 2018-07-08 21:39:34 +0200 | [diff] [blame] | 1806 | * -# Call psa_cipher_decrypt_setup() to specify the algorithm and key. |
Gilles Peskine | f45adda | 2019-01-14 18:29:18 +0100 | [diff] [blame] | 1807 | * -# Call psa_cipher_set_iv() with the IV (initialization vector) for the |
Gilles Peskine | 428dc5a | 2018-03-03 21:27:18 +0100 | [diff] [blame] | 1808 | * decryption. If the IV is prepended to the ciphertext, you can call |
| 1809 | * psa_cipher_update() on a buffer containing the IV followed by the |
| 1810 | * beginning of the message. |
| 1811 | * -# Call psa_cipher_update() zero, one or more times, passing a fragment |
| 1812 | * of the message each time. |
| 1813 | * -# Call psa_cipher_finish(). |
| 1814 | * |
| 1815 | * The application may call psa_cipher_abort() at any time after the operation |
Jaeden Amero | 5bae227 | 2019-01-04 11:48:27 +0000 | [diff] [blame] | 1816 | * has been initialized. |
Gilles Peskine | 428dc5a | 2018-03-03 21:27:18 +0100 | [diff] [blame] | 1817 | * |
Gilles Peskine | fe11951 | 2018-07-08 21:39:34 +0200 | [diff] [blame] | 1818 | * After a successful call to psa_cipher_decrypt_setup(), the application must |
Gilles Peskine | ed52297 | 2018-03-20 17:54:15 +0100 | [diff] [blame] | 1819 | * eventually terminate the operation. The following events terminate an |
| 1820 | * operation: |
Gilles Peskine | f45adda | 2019-01-14 18:29:18 +0100 | [diff] [blame] | 1821 | * - A failed call to any of the \c psa_cipher_xxx functions. |
Gilles Peskine | 1906798 | 2018-03-20 17:54:53 +0100 | [diff] [blame] | 1822 | * - A call to psa_cipher_finish() or psa_cipher_abort(). |
Gilles Peskine | 428dc5a | 2018-03-03 21:27:18 +0100 | [diff] [blame] | 1823 | * |
Jaeden Amero | 5bae227 | 2019-01-04 11:48:27 +0000 | [diff] [blame] | 1824 | * \param[in,out] operation The operation object to set up. It must have |
| 1825 | * been initialized as per the documentation for |
| 1826 | * #psa_cipher_operation_t and not yet in use. |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 1827 | * \param handle Handle to the key to use for the operation. |
Gilles Peskine | 5f25dd0 | 2019-01-14 18:24:53 +0100 | [diff] [blame] | 1828 | * It must remain valid until the operation |
| 1829 | * terminates. |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 1830 | * \param alg The cipher algorithm to compute |
| 1831 | * (\c PSA_ALG_XXX value such that |
| 1832 | * #PSA_ALG_IS_CIPHER(\p alg) is true). |
Gilles Peskine | 428dc5a | 2018-03-03 21:27:18 +0100 | [diff] [blame] | 1833 | * |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 1834 | * \retval #PSA_SUCCESS |
Gilles Peskine | 428dc5a | 2018-03-03 21:27:18 +0100 | [diff] [blame] | 1835 | * Success. |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 1836 | * \retval #PSA_ERROR_INVALID_HANDLE |
David Saada | b4ecc27 | 2019-02-14 13:48:10 +0200 | [diff] [blame] | 1837 | * \retval #PSA_ERROR_DOES_NOT_EXIST |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 1838 | * \retval #PSA_ERROR_NOT_PERMITTED |
| 1839 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
Gilles Peskine | 3be6b7f | 2019-03-05 19:32:26 +0100 | [diff] [blame] | 1840 | * \p handle is not compatible with \p alg. |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 1841 | * \retval #PSA_ERROR_NOT_SUPPORTED |
Gilles Peskine | fa4070c | 2018-07-12 19:23:03 +0200 | [diff] [blame] | 1842 | * \p alg is not supported or is not a cipher algorithm. |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 1843 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 1844 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 1845 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 1846 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
itayzafrir | 90d8c7a | 2018-09-12 11:44:52 +0300 | [diff] [blame] | 1847 | * \retval #PSA_ERROR_BAD_STATE |
Gilles Peskine | 8e1addc | 2019-01-10 11:51:17 +0100 | [diff] [blame] | 1848 | * The operation state is not valid (already set up and not |
| 1849 | * subsequently completed). |
| 1850 | * \retval #PSA_ERROR_BAD_STATE |
itayzafrir | 1861709 | 2018-09-16 12:22:41 +0300 | [diff] [blame] | 1851 | * The library has not been previously initialized by psa_crypto_init(). |
| 1852 | * It is implementation-dependent whether a failure to initialize |
| 1853 | * results in this error code. |
Gilles Peskine | 428dc5a | 2018-03-03 21:27:18 +0100 | [diff] [blame] | 1854 | */ |
Gilles Peskine | fe11951 | 2018-07-08 21:39:34 +0200 | [diff] [blame] | 1855 | psa_status_t psa_cipher_decrypt_setup(psa_cipher_operation_t *operation, |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 1856 | psa_key_handle_t handle, |
Gilles Peskine | fe11951 | 2018-07-08 21:39:34 +0200 | [diff] [blame] | 1857 | psa_algorithm_t alg); |
Gilles Peskine | 428dc5a | 2018-03-03 21:27:18 +0100 | [diff] [blame] | 1858 | |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 1859 | /** Generate an IV for a symmetric encryption operation. |
| 1860 | * |
| 1861 | * This function generates a random IV (initialization vector), nonce |
| 1862 | * or initial counter value for the encryption operation as appropriate |
| 1863 | * for the chosen algorithm, key type and key size. |
| 1864 | * |
| 1865 | * The application must call psa_cipher_encrypt_setup() before |
| 1866 | * calling this function. |
| 1867 | * |
| 1868 | * If this function returns an error status, the operation becomes inactive. |
| 1869 | * |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 1870 | * \param[in,out] operation Active cipher operation. |
| 1871 | * \param[out] iv Buffer where the generated IV is to be written. |
Gilles Peskine | fa4070c | 2018-07-12 19:23:03 +0200 | [diff] [blame] | 1872 | * \param iv_size Size of the \p iv buffer in bytes. |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 1873 | * \param[out] iv_length On success, the number of bytes of the |
| 1874 | * generated IV. |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 1875 | * |
| 1876 | * \retval #PSA_SUCCESS |
| 1877 | * Success. |
| 1878 | * \retval #PSA_ERROR_BAD_STATE |
Gilles Peskine | f45adda | 2019-01-14 18:29:18 +0100 | [diff] [blame] | 1879 | * The operation state is not valid (not set up, or IV already set). |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 1880 | * \retval #PSA_ERROR_BUFFER_TOO_SMALL |
Gilles Peskine | dda3bd3 | 2018-07-12 19:40:46 +0200 | [diff] [blame] | 1881 | * The size of the \p iv buffer is too small. |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 1882 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 1883 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 1884 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 1885 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 1886 | */ |
Gilles Peskine | fe11951 | 2018-07-08 21:39:34 +0200 | [diff] [blame] | 1887 | psa_status_t psa_cipher_generate_iv(psa_cipher_operation_t *operation, |
| 1888 | unsigned char *iv, |
| 1889 | size_t iv_size, |
| 1890 | size_t *iv_length); |
Gilles Peskine | 428dc5a | 2018-03-03 21:27:18 +0100 | [diff] [blame] | 1891 | |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 1892 | /** Set the IV for a symmetric encryption or decryption operation. |
| 1893 | * |
Gilles Peskine | f45adda | 2019-01-14 18:29:18 +0100 | [diff] [blame] | 1894 | * This function sets the IV (initialization vector), nonce |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 1895 | * or initial counter value for the encryption or decryption operation. |
| 1896 | * |
| 1897 | * The application must call psa_cipher_encrypt_setup() before |
| 1898 | * calling this function. |
| 1899 | * |
| 1900 | * If this function returns an error status, the operation becomes inactive. |
| 1901 | * |
| 1902 | * \note When encrypting, applications should use psa_cipher_generate_iv() |
| 1903 | * instead of this function, unless implementing a protocol that requires |
| 1904 | * a non-random IV. |
| 1905 | * |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 1906 | * \param[in,out] operation Active cipher operation. |
| 1907 | * \param[in] iv Buffer containing the IV to use. |
| 1908 | * \param iv_length Size of the IV in bytes. |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 1909 | * |
| 1910 | * \retval #PSA_SUCCESS |
| 1911 | * Success. |
| 1912 | * \retval #PSA_ERROR_BAD_STATE |
Gilles Peskine | f45adda | 2019-01-14 18:29:18 +0100 | [diff] [blame] | 1913 | * The operation state is not valid (not set up, or IV already set). |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 1914 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
Gilles Peskine | fa4070c | 2018-07-12 19:23:03 +0200 | [diff] [blame] | 1915 | * The size of \p iv is not acceptable for the chosen algorithm, |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 1916 | * or the chosen algorithm does not use an IV. |
| 1917 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 1918 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 1919 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 1920 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 1921 | */ |
Gilles Peskine | fe11951 | 2018-07-08 21:39:34 +0200 | [diff] [blame] | 1922 | psa_status_t psa_cipher_set_iv(psa_cipher_operation_t *operation, |
| 1923 | const unsigned char *iv, |
| 1924 | size_t iv_length); |
Gilles Peskine | 428dc5a | 2018-03-03 21:27:18 +0100 | [diff] [blame] | 1925 | |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 1926 | /** Encrypt or decrypt a message fragment in an active cipher operation. |
| 1927 | * |
Gilles Peskine | 9ac9426 | 2018-07-12 20:15:32 +0200 | [diff] [blame] | 1928 | * Before calling this function, you must: |
| 1929 | * 1. Call either psa_cipher_encrypt_setup() or psa_cipher_decrypt_setup(). |
| 1930 | * The choice of setup function determines whether this function |
| 1931 | * encrypts or decrypts its input. |
| 1932 | * 2. If the algorithm requires an IV, call psa_cipher_generate_iv() |
| 1933 | * (recommended when encrypting) or psa_cipher_set_iv(). |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 1934 | * |
| 1935 | * If this function returns an error status, the operation becomes inactive. |
| 1936 | * |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 1937 | * \param[in,out] operation Active cipher operation. |
| 1938 | * \param[in] input Buffer containing the message fragment to |
| 1939 | * encrypt or decrypt. |
Gilles Peskine | fa4070c | 2018-07-12 19:23:03 +0200 | [diff] [blame] | 1940 | * \param input_length Size of the \p input buffer in bytes. |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 1941 | * \param[out] output Buffer where the output is to be written. |
Gilles Peskine | fa4070c | 2018-07-12 19:23:03 +0200 | [diff] [blame] | 1942 | * \param output_size Size of the \p output buffer in bytes. |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 1943 | * \param[out] output_length On success, the number of bytes |
| 1944 | * that make up the returned output. |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 1945 | * |
| 1946 | * \retval #PSA_SUCCESS |
| 1947 | * Success. |
| 1948 | * \retval #PSA_ERROR_BAD_STATE |
Gilles Peskine | f45adda | 2019-01-14 18:29:18 +0100 | [diff] [blame] | 1949 | * The operation state is not valid (not set up, IV required but |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 1950 | * not set, or already completed). |
| 1951 | * \retval #PSA_ERROR_BUFFER_TOO_SMALL |
| 1952 | * The size of the \p output buffer is too small. |
| 1953 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 1954 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 1955 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 1956 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 1957 | */ |
Gilles Peskine | 428dc5a | 2018-03-03 21:27:18 +0100 | [diff] [blame] | 1958 | psa_status_t psa_cipher_update(psa_cipher_operation_t *operation, |
| 1959 | const uint8_t *input, |
mohammad1603 | 503973b | 2018-03-12 15:59:30 +0200 | [diff] [blame] | 1960 | size_t input_length, |
Gilles Peskine | 2d27786 | 2018-06-18 15:41:12 +0200 | [diff] [blame] | 1961 | unsigned char *output, |
| 1962 | size_t output_size, |
mohammad1603 | 503973b | 2018-03-12 15:59:30 +0200 | [diff] [blame] | 1963 | size_t *output_length); |
Gilles Peskine | 428dc5a | 2018-03-03 21:27:18 +0100 | [diff] [blame] | 1964 | |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 1965 | /** Finish encrypting or decrypting a message in a cipher operation. |
| 1966 | * |
| 1967 | * The application must call psa_cipher_encrypt_setup() or |
| 1968 | * psa_cipher_decrypt_setup() before calling this function. The choice |
| 1969 | * of setup function determines whether this function encrypts or |
| 1970 | * decrypts its input. |
| 1971 | * |
| 1972 | * This function finishes the encryption or decryption of the message |
| 1973 | * formed by concatenating the inputs passed to preceding calls to |
| 1974 | * psa_cipher_update(). |
| 1975 | * |
| 1976 | * When this function returns, the operation becomes inactive. |
| 1977 | * |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 1978 | * \param[in,out] operation Active cipher operation. |
| 1979 | * \param[out] output Buffer where the output is to be written. |
Gilles Peskine | fa4070c | 2018-07-12 19:23:03 +0200 | [diff] [blame] | 1980 | * \param output_size Size of the \p output buffer in bytes. |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 1981 | * \param[out] output_length On success, the number of bytes |
| 1982 | * that make up the returned output. |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 1983 | * |
| 1984 | * \retval #PSA_SUCCESS |
| 1985 | * Success. |
| 1986 | * \retval #PSA_ERROR_BAD_STATE |
Gilles Peskine | f45adda | 2019-01-14 18:29:18 +0100 | [diff] [blame] | 1987 | * The operation state is not valid (not set up, IV required but |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 1988 | * not set, or already completed). |
| 1989 | * \retval #PSA_ERROR_BUFFER_TOO_SMALL |
| 1990 | * The size of the \p output buffer is too small. |
| 1991 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 1992 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 1993 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 1994 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 1995 | */ |
Gilles Peskine | 428dc5a | 2018-03-03 21:27:18 +0100 | [diff] [blame] | 1996 | psa_status_t psa_cipher_finish(psa_cipher_operation_t *operation, |
mohammad1603 | 503973b | 2018-03-12 15:59:30 +0200 | [diff] [blame] | 1997 | uint8_t *output, |
Moran Peker | 0071b87 | 2018-04-22 20:16:58 +0300 | [diff] [blame] | 1998 | size_t output_size, |
mohammad1603 | 503973b | 2018-03-12 15:59:30 +0200 | [diff] [blame] | 1999 | size_t *output_length); |
Gilles Peskine | 428dc5a | 2018-03-03 21:27:18 +0100 | [diff] [blame] | 2000 | |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 2001 | /** Abort a cipher operation. |
| 2002 | * |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 2003 | * Aborting an operation frees all associated resources except for the |
Gilles Peskine | b82ab6f | 2018-07-13 15:33:43 +0200 | [diff] [blame] | 2004 | * \p operation structure itself. Once aborted, the operation object |
| 2005 | * can be reused for another operation by calling |
| 2006 | * psa_cipher_encrypt_setup() or psa_cipher_decrypt_setup() again. |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 2007 | * |
Gilles Peskine | b82ab6f | 2018-07-13 15:33:43 +0200 | [diff] [blame] | 2008 | * You may call this function any time after the operation object has |
| 2009 | * been initialized by any of the following methods: |
| 2010 | * - A call to psa_cipher_encrypt_setup() or psa_cipher_decrypt_setup(), |
| 2011 | * whether it succeeds or not. |
| 2012 | * - Initializing the \c struct to all-bits-zero. |
| 2013 | * - Initializing the \c struct to logical zeros, e.g. |
| 2014 | * `psa_cipher_operation_t operation = {0}`. |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 2015 | * |
Gilles Peskine | b82ab6f | 2018-07-13 15:33:43 +0200 | [diff] [blame] | 2016 | * In particular, calling psa_cipher_abort() after the operation has been |
| 2017 | * terminated by a call to psa_cipher_abort() or psa_cipher_finish() |
| 2018 | * is safe and has no effect. |
| 2019 | * |
| 2020 | * \param[in,out] operation Initialized cipher operation. |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 2021 | * |
| 2022 | * \retval #PSA_SUCCESS |
| 2023 | * \retval #PSA_ERROR_BAD_STATE |
Gilles Peskine | fa4070c | 2018-07-12 19:23:03 +0200 | [diff] [blame] | 2024 | * \p operation is not an active cipher operation. |
Gilles Peskine | dcd1494 | 2018-07-12 00:30:52 +0200 | [diff] [blame] | 2025 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 2026 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 2027 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 2028 | */ |
Gilles Peskine | 428dc5a | 2018-03-03 21:27:18 +0100 | [diff] [blame] | 2029 | psa_status_t psa_cipher_abort(psa_cipher_operation_t *operation); |
| 2030 | |
| 2031 | /**@}*/ |
| 2032 | |
Gilles Peskine | 3b55571 | 2018-03-03 21:27:57 +0100 | [diff] [blame] | 2033 | /** \defgroup aead Authenticated encryption with associated data (AEAD) |
| 2034 | * @{ |
| 2035 | */ |
| 2036 | |
Gilles Peskine | 1e7d8f1 | 2018-06-01 16:29:38 +0200 | [diff] [blame] | 2037 | /** Process an authenticated encryption operation. |
Gilles Peskine | 3b55571 | 2018-03-03 21:27:57 +0100 | [diff] [blame] | 2038 | * |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 2039 | * \param handle Handle to the key to use for the operation. |
Gilles Peskine | 1e7d8f1 | 2018-06-01 16:29:38 +0200 | [diff] [blame] | 2040 | * \param alg The AEAD algorithm to compute |
| 2041 | * (\c PSA_ALG_XXX value such that |
Gilles Peskine | 7256e6c | 2018-07-12 00:34:26 +0200 | [diff] [blame] | 2042 | * #PSA_ALG_IS_AEAD(\p alg) is true). |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 2043 | * \param[in] nonce Nonce or IV to use. |
Gilles Peskine | 1e7d8f1 | 2018-06-01 16:29:38 +0200 | [diff] [blame] | 2044 | * \param nonce_length Size of the \p nonce buffer in bytes. |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 2045 | * \param[in] additional_data Additional data that will be authenticated |
Gilles Peskine | 1e7d8f1 | 2018-06-01 16:29:38 +0200 | [diff] [blame] | 2046 | * but not encrypted. |
| 2047 | * \param additional_data_length Size of \p additional_data in bytes. |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 2048 | * \param[in] plaintext Data that will be authenticated and |
Gilles Peskine | 1e7d8f1 | 2018-06-01 16:29:38 +0200 | [diff] [blame] | 2049 | * encrypted. |
| 2050 | * \param plaintext_length Size of \p plaintext in bytes. |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 2051 | * \param[out] ciphertext Output buffer for the authenticated and |
Gilles Peskine | 1e7d8f1 | 2018-06-01 16:29:38 +0200 | [diff] [blame] | 2052 | * encrypted data. The additional data is not |
| 2053 | * part of this output. For algorithms where the |
| 2054 | * encrypted data and the authentication tag |
| 2055 | * are defined as separate outputs, the |
| 2056 | * authentication tag is appended to the |
| 2057 | * encrypted data. |
| 2058 | * \param ciphertext_size Size of the \p ciphertext buffer in bytes. |
| 2059 | * This must be at least |
| 2060 | * #PSA_AEAD_ENCRYPT_OUTPUT_SIZE(\p alg, |
| 2061 | * \p plaintext_length). |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 2062 | * \param[out] ciphertext_length On success, the size of the output |
Gilles Peskine | 4c6fdbb | 2019-02-08 11:22:39 +0100 | [diff] [blame] | 2063 | * in the \p ciphertext buffer. |
Gilles Peskine | 3b55571 | 2018-03-03 21:27:57 +0100 | [diff] [blame] | 2064 | * |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 2065 | * \retval #PSA_SUCCESS |
Gilles Peskine | 3b55571 | 2018-03-03 21:27:57 +0100 | [diff] [blame] | 2066 | * Success. |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 2067 | * \retval #PSA_ERROR_INVALID_HANDLE |
David Saada | b4ecc27 | 2019-02-14 13:48:10 +0200 | [diff] [blame] | 2068 | * \retval #PSA_ERROR_DOES_NOT_EXIST |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 2069 | * \retval #PSA_ERROR_NOT_PERMITTED |
| 2070 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
Gilles Peskine | 3be6b7f | 2019-03-05 19:32:26 +0100 | [diff] [blame] | 2071 | * \p handle is not compatible with \p alg. |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 2072 | * \retval #PSA_ERROR_NOT_SUPPORTED |
Gilles Peskine | fa4070c | 2018-07-12 19:23:03 +0200 | [diff] [blame] | 2073 | * \p alg is not supported or is not an AEAD algorithm. |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 2074 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 2075 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 2076 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 2077 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
itayzafrir | 90d8c7a | 2018-09-12 11:44:52 +0300 | [diff] [blame] | 2078 | * \retval #PSA_ERROR_BAD_STATE |
itayzafrir | 1861709 | 2018-09-16 12:22:41 +0300 | [diff] [blame] | 2079 | * The library has not been previously initialized by psa_crypto_init(). |
| 2080 | * It is implementation-dependent whether a failure to initialize |
| 2081 | * results in this error code. |
Gilles Peskine | 3b55571 | 2018-03-03 21:27:57 +0100 | [diff] [blame] | 2082 | */ |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 2083 | psa_status_t psa_aead_encrypt(psa_key_handle_t handle, |
Gilles Peskine | 9fb0e01 | 2018-07-19 15:51:49 +0200 | [diff] [blame] | 2084 | psa_algorithm_t alg, |
| 2085 | const uint8_t *nonce, |
| 2086 | size_t nonce_length, |
| 2087 | const uint8_t *additional_data, |
| 2088 | size_t additional_data_length, |
| 2089 | const uint8_t *plaintext, |
| 2090 | size_t plaintext_length, |
| 2091 | uint8_t *ciphertext, |
| 2092 | size_t ciphertext_size, |
| 2093 | size_t *ciphertext_length); |
Gilles Peskine | 3b55571 | 2018-03-03 21:27:57 +0100 | [diff] [blame] | 2094 | |
Gilles Peskine | 1e7d8f1 | 2018-06-01 16:29:38 +0200 | [diff] [blame] | 2095 | /** Process an authenticated decryption operation. |
Gilles Peskine | 3b55571 | 2018-03-03 21:27:57 +0100 | [diff] [blame] | 2096 | * |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 2097 | * \param handle Handle to the key to use for the operation. |
Gilles Peskine | 1e7d8f1 | 2018-06-01 16:29:38 +0200 | [diff] [blame] | 2098 | * \param alg The AEAD algorithm to compute |
| 2099 | * (\c PSA_ALG_XXX value such that |
Gilles Peskine | 7256e6c | 2018-07-12 00:34:26 +0200 | [diff] [blame] | 2100 | * #PSA_ALG_IS_AEAD(\p alg) is true). |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 2101 | * \param[in] nonce Nonce or IV to use. |
Gilles Peskine | 1e7d8f1 | 2018-06-01 16:29:38 +0200 | [diff] [blame] | 2102 | * \param nonce_length Size of the \p nonce buffer in bytes. |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 2103 | * \param[in] additional_data Additional data that has been authenticated |
Gilles Peskine | 1e7d8f1 | 2018-06-01 16:29:38 +0200 | [diff] [blame] | 2104 | * but not encrypted. |
| 2105 | * \param additional_data_length Size of \p additional_data in bytes. |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 2106 | * \param[in] ciphertext Data that has been authenticated and |
Gilles Peskine | 1e7d8f1 | 2018-06-01 16:29:38 +0200 | [diff] [blame] | 2107 | * encrypted. For algorithms where the |
| 2108 | * encrypted data and the authentication tag |
| 2109 | * are defined as separate inputs, the buffer |
| 2110 | * must contain the encrypted data followed |
| 2111 | * by the authentication tag. |
| 2112 | * \param ciphertext_length Size of \p ciphertext in bytes. |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 2113 | * \param[out] plaintext Output buffer for the decrypted data. |
Gilles Peskine | 1e7d8f1 | 2018-06-01 16:29:38 +0200 | [diff] [blame] | 2114 | * \param plaintext_size Size of the \p plaintext buffer in bytes. |
| 2115 | * This must be at least |
| 2116 | * #PSA_AEAD_DECRYPT_OUTPUT_SIZE(\p alg, |
| 2117 | * \p ciphertext_length). |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 2118 | * \param[out] plaintext_length On success, the size of the output |
Gilles Peskine | 4c6fdbb | 2019-02-08 11:22:39 +0100 | [diff] [blame] | 2119 | * in the \p plaintext buffer. |
Gilles Peskine | 3b55571 | 2018-03-03 21:27:57 +0100 | [diff] [blame] | 2120 | * |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 2121 | * \retval #PSA_SUCCESS |
Gilles Peskine | 3b55571 | 2018-03-03 21:27:57 +0100 | [diff] [blame] | 2122 | * Success. |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 2123 | * \retval #PSA_ERROR_INVALID_HANDLE |
David Saada | b4ecc27 | 2019-02-14 13:48:10 +0200 | [diff] [blame] | 2124 | * \retval #PSA_ERROR_DOES_NOT_EXIST |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 2125 | * \retval #PSA_ERROR_INVALID_SIGNATURE |
Gilles Peskine | 1e7d8f1 | 2018-06-01 16:29:38 +0200 | [diff] [blame] | 2126 | * The ciphertext is not authentic. |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 2127 | * \retval #PSA_ERROR_NOT_PERMITTED |
| 2128 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
Gilles Peskine | 3be6b7f | 2019-03-05 19:32:26 +0100 | [diff] [blame] | 2129 | * \p handle is not compatible with \p alg. |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 2130 | * \retval #PSA_ERROR_NOT_SUPPORTED |
Gilles Peskine | fa4070c | 2018-07-12 19:23:03 +0200 | [diff] [blame] | 2131 | * \p alg is not supported or is not an AEAD algorithm. |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 2132 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 2133 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 2134 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 2135 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
itayzafrir | 90d8c7a | 2018-09-12 11:44:52 +0300 | [diff] [blame] | 2136 | * \retval #PSA_ERROR_BAD_STATE |
itayzafrir | 1861709 | 2018-09-16 12:22:41 +0300 | [diff] [blame] | 2137 | * The library has not been previously initialized by psa_crypto_init(). |
| 2138 | * It is implementation-dependent whether a failure to initialize |
| 2139 | * results in this error code. |
Gilles Peskine | 3b55571 | 2018-03-03 21:27:57 +0100 | [diff] [blame] | 2140 | */ |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 2141 | psa_status_t psa_aead_decrypt(psa_key_handle_t handle, |
Gilles Peskine | 9fb0e01 | 2018-07-19 15:51:49 +0200 | [diff] [blame] | 2142 | psa_algorithm_t alg, |
| 2143 | const uint8_t *nonce, |
| 2144 | size_t nonce_length, |
| 2145 | const uint8_t *additional_data, |
| 2146 | size_t additional_data_length, |
| 2147 | const uint8_t *ciphertext, |
| 2148 | size_t ciphertext_length, |
| 2149 | uint8_t *plaintext, |
| 2150 | size_t plaintext_size, |
| 2151 | size_t *plaintext_length); |
Gilles Peskine | 3b55571 | 2018-03-03 21:27:57 +0100 | [diff] [blame] | 2152 | |
Gilles Peskine | 30a9e41 | 2019-01-14 18:36:12 +0100 | [diff] [blame] | 2153 | /** The type of the state data structure for multipart AEAD operations. |
| 2154 | * |
| 2155 | * Before calling any function on an AEAD operation object, the application |
| 2156 | * must initialize it by any of the following means: |
| 2157 | * - Set the structure to all-bits-zero, for example: |
| 2158 | * \code |
| 2159 | * psa_aead_operation_t operation; |
| 2160 | * memset(&operation, 0, sizeof(operation)); |
| 2161 | * \endcode |
| 2162 | * - Initialize the structure to logical zero values, for example: |
| 2163 | * \code |
| 2164 | * psa_aead_operation_t operation = {0}; |
| 2165 | * \endcode |
| 2166 | * - Initialize the structure to the initializer #PSA_AEAD_OPERATION_INIT, |
| 2167 | * for example: |
| 2168 | * \code |
| 2169 | * psa_aead_operation_t operation = PSA_AEAD_OPERATION_INIT; |
| 2170 | * \endcode |
| 2171 | * - Assign the result of the function psa_aead_operation_init() |
| 2172 | * to the structure, for example: |
| 2173 | * \code |
| 2174 | * psa_aead_operation_t operation; |
| 2175 | * operation = psa_aead_operation_init(); |
| 2176 | * \endcode |
| 2177 | * |
| 2178 | * This is an implementation-defined \c struct. Applications should not |
| 2179 | * make any assumptions about the content of this structure except |
| 2180 | * as directed by the documentation of a specific implementation. */ |
| 2181 | typedef struct psa_aead_operation_s psa_aead_operation_t; |
| 2182 | |
| 2183 | /** \def PSA_AEAD_OPERATION_INIT |
| 2184 | * |
| 2185 | * This macro returns a suitable initializer for an AEAD operation object of |
| 2186 | * type #psa_aead_operation_t. |
| 2187 | */ |
| 2188 | #ifdef __DOXYGEN_ONLY__ |
| 2189 | /* This is an example definition for documentation purposes. |
| 2190 | * Implementations should define a suitable value in `crypto_struct.h`. |
| 2191 | */ |
| 2192 | #define PSA_AEAD_OPERATION_INIT {0} |
| 2193 | #endif |
| 2194 | |
| 2195 | /** Return an initial value for an AEAD operation object. |
| 2196 | */ |
| 2197 | static psa_aead_operation_t psa_aead_operation_init(void); |
| 2198 | |
| 2199 | /** Set the key for a multipart authenticated encryption operation. |
| 2200 | * |
| 2201 | * The sequence of operations to encrypt a message with authentication |
| 2202 | * is as follows: |
| 2203 | * -# Allocate an operation object which will be passed to all the functions |
| 2204 | * listed here. |
| 2205 | * -# Initialize the operation object with one of the methods described in the |
| 2206 | * documentation for #psa_aead_operation_t, e.g. |
| 2207 | * PSA_AEAD_OPERATION_INIT. |
| 2208 | * -# Call psa_aead_encrypt_setup() to specify the algorithm and key. |
Gilles Peskine | bc59c85 | 2019-01-17 15:26:08 +0100 | [diff] [blame] | 2209 | * -# If needed, call psa_aead_set_lengths() to specify the length of the |
| 2210 | * inputs to the subsequent calls to psa_aead_update_ad() and |
| 2211 | * psa_aead_update(). See the documentation of psa_aead_set_lengths() |
| 2212 | * for details. |
Gilles Peskine | 30a9e41 | 2019-01-14 18:36:12 +0100 | [diff] [blame] | 2213 | * -# Call either psa_aead_generate_nonce() or psa_aead_set_nonce() to |
| 2214 | * generate or set the nonce. You should use |
| 2215 | * psa_aead_generate_nonce() unless the protocol you are implementing |
| 2216 | * requires a specific nonce value. |
| 2217 | * -# Call psa_aead_update_ad() zero, one or more times, passing a fragment |
| 2218 | * of the non-encrypted additional authenticated data each time. |
| 2219 | * -# Call psa_aead_update() zero, one or more times, passing a fragment |
Gilles Peskine | a05602d | 2019-01-17 15:25:52 +0100 | [diff] [blame] | 2220 | * of the message to encrypt each time. |
Gilles Peskine | 30a9e41 | 2019-01-14 18:36:12 +0100 | [diff] [blame] | 2221 | * -# Call psa_aead_finish(). |
| 2222 | * |
| 2223 | * The application may call psa_aead_abort() at any time after the operation |
| 2224 | * has been initialized. |
| 2225 | * |
| 2226 | * After a successful call to psa_aead_encrypt_setup(), the application must |
| 2227 | * eventually terminate the operation. The following events terminate an |
| 2228 | * operation: |
| 2229 | * - A failed call to any of the \c psa_aead_xxx functions. |
| 2230 | * - A call to psa_aead_finish(), psa_aead_verify() or psa_aead_abort(). |
| 2231 | * |
| 2232 | * \param[in,out] operation The operation object to set up. It must have |
| 2233 | * been initialized as per the documentation for |
| 2234 | * #psa_aead_operation_t and not yet in use. |
| 2235 | * \param handle Handle to the key to use for the operation. |
| 2236 | * It must remain valid until the operation |
| 2237 | * terminates. |
| 2238 | * \param alg The AEAD algorithm to compute |
| 2239 | * (\c PSA_ALG_XXX value such that |
| 2240 | * #PSA_ALG_IS_AEAD(\p alg) is true). |
| 2241 | * |
| 2242 | * \retval #PSA_SUCCESS |
| 2243 | * Success. |
| 2244 | * \retval #PSA_ERROR_INVALID_HANDLE |
| 2245 | * \retval #PSA_ERROR_EMPTY_SLOT |
| 2246 | * \retval #PSA_ERROR_NOT_PERMITTED |
| 2247 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
Gilles Peskine | 3be6b7f | 2019-03-05 19:32:26 +0100 | [diff] [blame] | 2248 | * \p handle is not compatible with \p alg. |
Gilles Peskine | 30a9e41 | 2019-01-14 18:36:12 +0100 | [diff] [blame] | 2249 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 2250 | * \p alg is not supported or is not an AEAD algorithm. |
| 2251 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 2252 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 2253 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 2254 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 2255 | * \retval #PSA_ERROR_BAD_STATE |
| 2256 | * The library has not been previously initialized by psa_crypto_init(). |
| 2257 | * It is implementation-dependent whether a failure to initialize |
| 2258 | * results in this error code. |
| 2259 | */ |
| 2260 | psa_status_t psa_aead_encrypt_setup(psa_aead_operation_t *operation, |
| 2261 | psa_key_handle_t handle, |
| 2262 | psa_algorithm_t alg); |
| 2263 | |
| 2264 | /** Set the key for a multipart authenticated decryption operation. |
| 2265 | * |
| 2266 | * The sequence of operations to decrypt a message with authentication |
| 2267 | * is as follows: |
| 2268 | * -# Allocate an operation object which will be passed to all the functions |
| 2269 | * listed here. |
| 2270 | * -# Initialize the operation object with one of the methods described in the |
| 2271 | * documentation for #psa_aead_operation_t, e.g. |
| 2272 | * PSA_AEAD_OPERATION_INIT. |
| 2273 | * -# Call psa_aead_decrypt_setup() to specify the algorithm and key. |
Gilles Peskine | bc59c85 | 2019-01-17 15:26:08 +0100 | [diff] [blame] | 2274 | * -# If needed, call psa_aead_set_lengths() to specify the length of the |
| 2275 | * inputs to the subsequent calls to psa_aead_update_ad() and |
| 2276 | * psa_aead_update(). See the documentation of psa_aead_set_lengths() |
| 2277 | * for details. |
Gilles Peskine | 30a9e41 | 2019-01-14 18:36:12 +0100 | [diff] [blame] | 2278 | * -# Call psa_aead_set_nonce() with the nonce for the decryption. |
| 2279 | * -# Call psa_aead_update_ad() zero, one or more times, passing a fragment |
| 2280 | * of the non-encrypted additional authenticated data each time. |
| 2281 | * -# Call psa_aead_update() zero, one or more times, passing a fragment |
Gilles Peskine | a05602d | 2019-01-17 15:25:52 +0100 | [diff] [blame] | 2282 | * of the ciphertext to decrypt each time. |
| 2283 | * -# Call psa_aead_verify(). |
Gilles Peskine | 30a9e41 | 2019-01-14 18:36:12 +0100 | [diff] [blame] | 2284 | * |
| 2285 | * The application may call psa_aead_abort() at any time after the operation |
| 2286 | * has been initialized. |
| 2287 | * |
| 2288 | * After a successful call to psa_aead_decrypt_setup(), the application must |
| 2289 | * eventually terminate the operation. The following events terminate an |
| 2290 | * operation: |
| 2291 | * - A failed call to any of the \c psa_aead_xxx functions. |
| 2292 | * - A call to psa_aead_finish(), psa_aead_verify() or psa_aead_abort(). |
| 2293 | * |
| 2294 | * \param[in,out] operation The operation object to set up. It must have |
| 2295 | * been initialized as per the documentation for |
| 2296 | * #psa_aead_operation_t and not yet in use. |
| 2297 | * \param handle Handle to the key to use for the operation. |
| 2298 | * It must remain valid until the operation |
| 2299 | * terminates. |
| 2300 | * \param alg The AEAD algorithm to compute |
| 2301 | * (\c PSA_ALG_XXX value such that |
| 2302 | * #PSA_ALG_IS_AEAD(\p alg) is true). |
| 2303 | * |
| 2304 | * \retval #PSA_SUCCESS |
| 2305 | * Success. |
| 2306 | * \retval #PSA_ERROR_INVALID_HANDLE |
| 2307 | * \retval #PSA_ERROR_EMPTY_SLOT |
| 2308 | * \retval #PSA_ERROR_NOT_PERMITTED |
| 2309 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
Gilles Peskine | 3be6b7f | 2019-03-05 19:32:26 +0100 | [diff] [blame] | 2310 | * \p handle is not compatible with \p alg. |
Gilles Peskine | 30a9e41 | 2019-01-14 18:36:12 +0100 | [diff] [blame] | 2311 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 2312 | * \p alg is not supported or is not an AEAD algorithm. |
| 2313 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 2314 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 2315 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 2316 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 2317 | * \retval #PSA_ERROR_BAD_STATE |
| 2318 | * The library has not been previously initialized by psa_crypto_init(). |
| 2319 | * It is implementation-dependent whether a failure to initialize |
| 2320 | * results in this error code. |
| 2321 | */ |
| 2322 | psa_status_t psa_aead_decrypt_setup(psa_aead_operation_t *operation, |
| 2323 | psa_key_handle_t handle, |
| 2324 | psa_algorithm_t alg); |
| 2325 | |
| 2326 | /** Generate a random nonce for an authenticated encryption operation. |
| 2327 | * |
| 2328 | * This function generates a random nonce for the authenticated encryption |
| 2329 | * operation with an appropriate size for the chosen algorithm, key type |
| 2330 | * and key size. |
| 2331 | * |
| 2332 | * The application must call psa_aead_encrypt_setup() before |
| 2333 | * calling this function. |
| 2334 | * |
| 2335 | * If this function returns an error status, the operation becomes inactive. |
| 2336 | * |
| 2337 | * \param[in,out] operation Active AEAD operation. |
| 2338 | * \param[out] nonce Buffer where the generated nonce is to be |
| 2339 | * written. |
| 2340 | * \param nonce_size Size of the \p nonce buffer in bytes. |
| 2341 | * \param[out] nonce_length On success, the number of bytes of the |
| 2342 | * generated nonce. |
| 2343 | * |
| 2344 | * \retval #PSA_SUCCESS |
| 2345 | * Success. |
| 2346 | * \retval #PSA_ERROR_BAD_STATE |
| 2347 | * The operation state is not valid (not set up, or nonce already set). |
| 2348 | * \retval #PSA_ERROR_BUFFER_TOO_SMALL |
| 2349 | * The size of the \p nonce buffer is too small. |
| 2350 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 2351 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 2352 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 2353 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 2354 | */ |
| 2355 | psa_status_t psa_aead_generate_nonce(psa_aead_operation_t *operation, |
| 2356 | unsigned char *nonce, |
| 2357 | size_t nonce_size, |
| 2358 | size_t *nonce_length); |
| 2359 | |
| 2360 | /** Set the nonce for an authenticated encryption or decryption operation. |
| 2361 | * |
| 2362 | * This function sets the nonce for the authenticated |
| 2363 | * encryption or decryption operation. |
| 2364 | * |
| 2365 | * The application must call psa_aead_encrypt_setup() before |
| 2366 | * calling this function. |
| 2367 | * |
| 2368 | * If this function returns an error status, the operation becomes inactive. |
| 2369 | * |
Gilles Peskine | a05602d | 2019-01-17 15:25:52 +0100 | [diff] [blame] | 2370 | * \note When encrypting, applications should use psa_aead_generate_nonce() |
Gilles Peskine | 30a9e41 | 2019-01-14 18:36:12 +0100 | [diff] [blame] | 2371 | * instead of this function, unless implementing a protocol that requires |
| 2372 | * a non-random IV. |
| 2373 | * |
| 2374 | * \param[in,out] operation Active AEAD operation. |
Gilles Peskine | a05602d | 2019-01-17 15:25:52 +0100 | [diff] [blame] | 2375 | * \param[in] nonce Buffer containing the nonce to use. |
| 2376 | * \param nonce_length Size of the nonce in bytes. |
Gilles Peskine | 30a9e41 | 2019-01-14 18:36:12 +0100 | [diff] [blame] | 2377 | * |
| 2378 | * \retval #PSA_SUCCESS |
| 2379 | * Success. |
| 2380 | * \retval #PSA_ERROR_BAD_STATE |
| 2381 | * The operation state is not valid (not set up, or nonce already set). |
| 2382 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 2383 | * The size of \p nonce is not acceptable for the chosen algorithm. |
| 2384 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 2385 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 2386 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 2387 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 2388 | */ |
| 2389 | psa_status_t psa_aead_set_nonce(psa_aead_operation_t *operation, |
| 2390 | const unsigned char *nonce, |
| 2391 | size_t nonce_length); |
| 2392 | |
Gilles Peskine | bc59c85 | 2019-01-17 15:26:08 +0100 | [diff] [blame] | 2393 | /** Declare the lengths of the message and additional data for AEAD. |
| 2394 | * |
| 2395 | * The application must call this function before calling |
| 2396 | * psa_aead_update_ad() or psa_aead_update() if the algorithm for |
| 2397 | * the operation requires it. If the algorithm does not require it, |
| 2398 | * calling this function is optional, but if this function is called |
| 2399 | * then the implementation must enforce the lengths. |
| 2400 | * |
| 2401 | * You may call this function before or after setting the nonce with |
| 2402 | * psa_aead_set_nonce() or psa_aead_generate_nonce(). |
| 2403 | * |
| 2404 | * - For #PSA_ALG_CCM, calling this function is required. |
| 2405 | * - For the other AEAD algorithms defined in this specification, calling |
| 2406 | * this function is not required. |
| 2407 | * - For vendor-defined algorithm, refer to the vendor documentation. |
| 2408 | * |
| 2409 | * \param[in,out] operation Active AEAD operation. |
| 2410 | * \param ad_length Size of the non-encrypted additional |
| 2411 | * authenticated data in bytes. |
| 2412 | * \param plaintext_length Size of the plaintext to encrypt in bytes. |
| 2413 | * |
| 2414 | * \retval #PSA_SUCCESS |
| 2415 | * Success. |
| 2416 | * \retval #PSA_ERROR_BAD_STATE |
| 2417 | * The operation state is not valid (not set up, already completed, |
| 2418 | * or psa_aead_update_ad() or psa_aead_update() already called). |
| 2419 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 2420 | * At least one of the lengths is not acceptable for the chosen |
| 2421 | * algorithm. |
| 2422 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 2423 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 2424 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 2425 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 2426 | */ |
| 2427 | psa_status_t psa_aead_set_lengths(psa_aead_operation_t *operation, |
| 2428 | size_t ad_length, |
| 2429 | size_t plaintext_length); |
| 2430 | |
Gilles Peskine | 30a9e41 | 2019-01-14 18:36:12 +0100 | [diff] [blame] | 2431 | /** Pass additional data to an active AEAD operation. |
| 2432 | * |
| 2433 | * Additional data is authenticated, but not encrypted. |
| 2434 | * |
| 2435 | * You may call this function multiple times to pass successive fragments |
| 2436 | * of the additional data. You may not call this function after passing |
| 2437 | * data to encrypt or decrypt with psa_aead_update(). |
| 2438 | * |
| 2439 | * Before calling this function, you must: |
| 2440 | * 1. Call either psa_aead_encrypt_setup() or psa_aead_decrypt_setup(). |
| 2441 | * 2. Set the nonce with psa_aead_generate_nonce() or psa_aead_set_nonce(). |
| 2442 | * |
| 2443 | * If this function returns an error status, the operation becomes inactive. |
| 2444 | * |
| 2445 | * \warning When decrypting, until psa_aead_verify() has returned #PSA_SUCCESS, |
| 2446 | * there is no guarantee that the input is valid. Therefore, until |
| 2447 | * you have called psa_aead_verify() and it has returned #PSA_SUCCESS, |
| 2448 | * treat the input as untrusted and prepare to undo any action that |
| 2449 | * depends on the input if psa_aead_verify() returns an error status. |
| 2450 | * |
| 2451 | * \param[in,out] operation Active AEAD operation. |
| 2452 | * \param[in] input Buffer containing the fragment of |
| 2453 | * additional data. |
| 2454 | * \param input_length Size of the \p input buffer in bytes. |
| 2455 | * |
| 2456 | * \retval #PSA_SUCCESS |
| 2457 | * Success. |
| 2458 | * \retval #PSA_ERROR_BAD_STATE |
| 2459 | * The operation state is not valid (not set up, nonce not set, |
| 2460 | * psa_aead_update() already called, or operation already completed). |
Gilles Peskine | bc59c85 | 2019-01-17 15:26:08 +0100 | [diff] [blame] | 2461 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 2462 | * The total input length overflows the additional data length that |
| 2463 | * was previously specified with psa_aead_set_lengths(). |
Gilles Peskine | 30a9e41 | 2019-01-14 18:36:12 +0100 | [diff] [blame] | 2464 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 2465 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 2466 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 2467 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 2468 | */ |
| 2469 | psa_status_t psa_aead_update_ad(psa_aead_operation_t *operation, |
| 2470 | const uint8_t *input, |
| 2471 | size_t input_length); |
| 2472 | |
| 2473 | /** Encrypt or decrypt a message fragment in an active AEAD operation. |
| 2474 | * |
| 2475 | * Before calling this function, you must: |
| 2476 | * 1. Call either psa_aead_encrypt_setup() or psa_aead_decrypt_setup(). |
| 2477 | * The choice of setup function determines whether this function |
| 2478 | * encrypts or decrypts its input. |
| 2479 | * 2. Set the nonce with psa_aead_generate_nonce() or psa_aead_set_nonce(). |
| 2480 | * 3. Call psa_aead_update_ad() to pass all the additional data. |
| 2481 | * |
| 2482 | * If this function returns an error status, the operation becomes inactive. |
| 2483 | * |
| 2484 | * \warning When decrypting, until psa_aead_verify() has returned #PSA_SUCCESS, |
| 2485 | * there is no guarantee that the input is valid. Therefore, until |
| 2486 | * you have called psa_aead_verify() and it has returned #PSA_SUCCESS: |
| 2487 | * - Do not use the output in any way other than storing it in a |
| 2488 | * confidential location. If you take any action that depends |
| 2489 | * on the tentative decrypted data, this action will need to be |
| 2490 | * undone if the input turns out not to be valid. Furthermore, |
| 2491 | * if an adversary can observe that this action took place |
| 2492 | * (for example through timing), they may be able to use this |
| 2493 | * fact as an oracle to decrypt any message encrypted with the |
| 2494 | * same key. |
| 2495 | * - In particular, do not copy the output anywhere but to a |
| 2496 | * memory or storage space that you have exclusive access to. |
| 2497 | * |
Gilles Peskine | f02aec9 | 2019-05-06 15:42:54 +0200 | [diff] [blame] | 2498 | * This function does not require the input to be aligned to any |
| 2499 | * particular block boundary. If the implementation can only process |
Gilles Peskine | ac99e32 | 2019-05-14 16:10:53 +0200 | [diff] [blame^] | 2500 | * a whole block at a time, it must consume all the input provided, but |
| 2501 | * it may delay the end of the corresponding output until a subsequent |
| 2502 | * call to psa_aead_update(), psa_aead_finish() or psa_aead_verify() |
| 2503 | * provides sufficient input. The amount of data that can be delayed |
| 2504 | * in this way is bounded by #PSA_AEAD_UPDATE_OUTPUT_SIZE. |
Gilles Peskine | f02aec9 | 2019-05-06 15:42:54 +0200 | [diff] [blame] | 2505 | * |
Gilles Peskine | 30a9e41 | 2019-01-14 18:36:12 +0100 | [diff] [blame] | 2506 | * \param[in,out] operation Active AEAD operation. |
| 2507 | * \param[in] input Buffer containing the message fragment to |
| 2508 | * encrypt or decrypt. |
| 2509 | * \param input_length Size of the \p input buffer in bytes. |
| 2510 | * \param[out] output Buffer where the output is to be written. |
| 2511 | * \param output_size Size of the \p output buffer in bytes. |
Gilles Peskine | 49dd8d8 | 2019-05-06 15:16:19 +0200 | [diff] [blame] | 2512 | * This must be at least |
| 2513 | * #PSA_AEAD_UPDATE_OUTPUT_SIZE(\c alg, |
| 2514 | * \p input_length) where \c alg is the |
| 2515 | * algorithm that is being calculated. |
Gilles Peskine | 30a9e41 | 2019-01-14 18:36:12 +0100 | [diff] [blame] | 2516 | * \param[out] output_length On success, the number of bytes |
| 2517 | * that make up the returned output. |
| 2518 | * |
| 2519 | * \retval #PSA_SUCCESS |
| 2520 | * Success. |
| 2521 | * \retval #PSA_ERROR_BAD_STATE |
| 2522 | * The operation state is not valid (not set up, nonce not set |
| 2523 | * or already completed). |
| 2524 | * \retval #PSA_ERROR_BUFFER_TOO_SMALL |
| 2525 | * The size of the \p output buffer is too small. |
Gilles Peskine | 49dd8d8 | 2019-05-06 15:16:19 +0200 | [diff] [blame] | 2526 | * You can determine a sufficient buffer size by calling |
| 2527 | * #PSA_AEAD_UPDATE_OUTPUT_SIZE(\c alg, \p input_length) |
| 2528 | * where \c alg is the algorithm that is being calculated. |
Gilles Peskine | bc59c85 | 2019-01-17 15:26:08 +0100 | [diff] [blame] | 2529 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 2530 | * The total length of input to psa_aead_update_ad() so far is |
| 2531 | * less than the additional data length that was previously |
| 2532 | * specified with psa_aead_set_lengths(). |
| 2533 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 2534 | * The total input length overflows the plaintext length that |
| 2535 | * was previously specified with psa_aead_set_lengths(). |
Gilles Peskine | 30a9e41 | 2019-01-14 18:36:12 +0100 | [diff] [blame] | 2536 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 2537 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 2538 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 2539 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 2540 | */ |
| 2541 | psa_status_t psa_aead_update(psa_aead_operation_t *operation, |
| 2542 | const uint8_t *input, |
| 2543 | size_t input_length, |
| 2544 | unsigned char *output, |
| 2545 | size_t output_size, |
| 2546 | size_t *output_length); |
| 2547 | |
| 2548 | /** Finish encrypting a message in an AEAD operation. |
| 2549 | * |
| 2550 | * The operation must have been set up with psa_aead_encrypt_setup(). |
| 2551 | * |
| 2552 | * This function finishes the authentication of the additional data |
| 2553 | * formed by concatenating the inputs passed to preceding calls to |
| 2554 | * psa_aead_update_ad() with the plaintext formed by concatenating the |
| 2555 | * inputs passed to preceding calls to psa_aead_update(). |
| 2556 | * |
| 2557 | * This function has two output buffers: |
| 2558 | * - \p ciphertext contains trailing ciphertext that was buffered from |
Gilles Peskine | f02aec9 | 2019-05-06 15:42:54 +0200 | [diff] [blame] | 2559 | * preceding calls to psa_aead_update(). |
Gilles Peskine | 30a9e41 | 2019-01-14 18:36:12 +0100 | [diff] [blame] | 2560 | * - \p tag contains the authentication tag. Its length is always |
Gilles Peskine | 3be6b7f | 2019-03-05 19:32:26 +0100 | [diff] [blame] | 2561 | * #PSA_AEAD_TAG_LENGTH(\c alg) where \c alg is the AEAD algorithm |
Gilles Peskine | 30a9e41 | 2019-01-14 18:36:12 +0100 | [diff] [blame] | 2562 | * that the operation performs. |
| 2563 | * |
| 2564 | * When this function returns, the operation becomes inactive. |
| 2565 | * |
| 2566 | * \param[in,out] operation Active AEAD operation. |
| 2567 | * \param[out] ciphertext Buffer where the last part of the ciphertext |
| 2568 | * is to be written. |
| 2569 | * \param ciphertext_size Size of the \p ciphertext buffer in bytes. |
Gilles Peskine | 49dd8d8 | 2019-05-06 15:16:19 +0200 | [diff] [blame] | 2570 | * This must be at least |
| 2571 | * #PSA_AEAD_FINISH_OUTPUT_SIZE(\c alg) where |
| 2572 | * \c alg is the algorithm that is being |
| 2573 | * calculated. |
Gilles Peskine | 30a9e41 | 2019-01-14 18:36:12 +0100 | [diff] [blame] | 2574 | * \param[out] ciphertext_length On success, the number of bytes of |
| 2575 | * returned ciphertext. |
| 2576 | * \param[out] tag Buffer where the authentication tag is |
| 2577 | * to be written. |
| 2578 | * \param tag_size Size of the \p tag buffer in bytes. |
Gilles Peskine | 49dd8d8 | 2019-05-06 15:16:19 +0200 | [diff] [blame] | 2579 | * This must be at least |
| 2580 | * #PSA_AEAD_TAG_LENGTH(\c alg) where \c alg is |
| 2581 | * the algorithm that is being calculated. |
Gilles Peskine | 30a9e41 | 2019-01-14 18:36:12 +0100 | [diff] [blame] | 2582 | * \param[out] tag_length On success, the number of bytes |
| 2583 | * that make up the returned tag. |
| 2584 | * |
| 2585 | * \retval #PSA_SUCCESS |
| 2586 | * Success. |
| 2587 | * \retval #PSA_ERROR_BAD_STATE |
| 2588 | * The operation state is not valid (not set up, nonce not set, |
| 2589 | * decryption, or already completed). |
| 2590 | * \retval #PSA_ERROR_BUFFER_TOO_SMALL |
Gilles Peskine | 3be6b7f | 2019-03-05 19:32:26 +0100 | [diff] [blame] | 2591 | * The size of the \p ciphertext or \p tag buffer is too small. |
Gilles Peskine | 49dd8d8 | 2019-05-06 15:16:19 +0200 | [diff] [blame] | 2592 | * You can determine a sufficient buffer size for \p ciphertext by |
| 2593 | * calling #PSA_AEAD_FINISH_OUTPUT_SIZE(\c alg) |
| 2594 | * where \c alg is the algorithm that is being calculated. |
| 2595 | * You can determine a sufficient buffer size for \p tag by |
| 2596 | * calling #PSA_AEAD_TAG_LENGTH(\c alg). |
Gilles Peskine | bc59c85 | 2019-01-17 15:26:08 +0100 | [diff] [blame] | 2597 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 2598 | * The total length of input to psa_aead_update_ad() so far is |
| 2599 | * less than the additional data length that was previously |
| 2600 | * specified with psa_aead_set_lengths(). |
| 2601 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 2602 | * The total length of input to psa_aead_update() so far is |
| 2603 | * less than the plaintext length that was previously |
| 2604 | * specified with psa_aead_set_lengths(). |
Gilles Peskine | 30a9e41 | 2019-01-14 18:36:12 +0100 | [diff] [blame] | 2605 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 2606 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 2607 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 2608 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 2609 | */ |
| 2610 | psa_status_t psa_aead_finish(psa_aead_operation_t *operation, |
Gilles Peskine | a05602d | 2019-01-17 15:25:52 +0100 | [diff] [blame] | 2611 | uint8_t *ciphertext, |
| 2612 | size_t ciphertext_size, |
| 2613 | size_t *ciphertext_length, |
Gilles Peskine | 30a9e41 | 2019-01-14 18:36:12 +0100 | [diff] [blame] | 2614 | uint8_t *tag, |
| 2615 | size_t tag_size, |
| 2616 | size_t *tag_length); |
| 2617 | |
| 2618 | /** Finish authenticating and decrypting a message in an AEAD operation. |
| 2619 | * |
| 2620 | * The operation must have been set up with psa_aead_decrypt_setup(). |
| 2621 | * |
| 2622 | * This function finishes the authentication of the additional data |
| 2623 | * formed by concatenating the inputs passed to preceding calls to |
| 2624 | * psa_aead_update_ad() with the ciphertext formed by concatenating the |
| 2625 | * inputs passed to preceding calls to psa_aead_update(). |
| 2626 | * |
| 2627 | * When this function returns, the operation becomes inactive. |
| 2628 | * |
| 2629 | * \param[in,out] operation Active AEAD operation. |
Gilles Peskine | 5211efb | 2019-05-06 15:56:05 +0200 | [diff] [blame] | 2630 | * \param[out] plaintext Buffer where the last part of the plaintext |
Gilles Peskine | ac99e32 | 2019-05-14 16:10:53 +0200 | [diff] [blame^] | 2631 | * is to be written. This is the remaining data |
Gilles Peskine | 5211efb | 2019-05-06 15:56:05 +0200 | [diff] [blame] | 2632 | * from previous calls to psa_aead_update() |
| 2633 | * that could not be processed until the end |
| 2634 | * of the input. |
| 2635 | * \param plaintext_size Size of the \p plaintext buffer in bytes. |
Gilles Peskine | 49dd8d8 | 2019-05-06 15:16:19 +0200 | [diff] [blame] | 2636 | * This must be at least |
| 2637 | * #PSA_AEAD_VERIFY_OUTPUT_SIZE(\c alg) where |
| 2638 | * \c alg is the algorithm that is being |
| 2639 | * calculated. |
Gilles Peskine | 5211efb | 2019-05-06 15:56:05 +0200 | [diff] [blame] | 2640 | * \param[out] plaintext_length On success, the number of bytes of |
| 2641 | * returned plaintext. |
Gilles Peskine | 30a9e41 | 2019-01-14 18:36:12 +0100 | [diff] [blame] | 2642 | * \param[in] tag Buffer containing the authentication tag. |
| 2643 | * \param tag_length Size of the \p tag buffer in bytes. |
| 2644 | * |
| 2645 | * \retval #PSA_SUCCESS |
| 2646 | * Success. |
| 2647 | * \retval #PSA_ERROR_BAD_STATE |
| 2648 | * The operation state is not valid (not set up, nonce not set, |
| 2649 | * encryption, or already completed). |
Gilles Peskine | 49dd8d8 | 2019-05-06 15:16:19 +0200 | [diff] [blame] | 2650 | * \retval #PSA_ERROR_BUFFER_TOO_SMALL |
| 2651 | * The size of the \p plaintext buffer is too small. |
| 2652 | * You can determine a sufficient buffer size for \p plaintext by |
| 2653 | * calling #PSA_AEAD_VERIFY_OUTPUT_SIZE(\c alg) |
| 2654 | * where \c alg is the algorithm that is being calculated. |
Gilles Peskine | bc59c85 | 2019-01-17 15:26:08 +0100 | [diff] [blame] | 2655 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 2656 | * The total length of input to psa_aead_update_ad() so far is |
| 2657 | * less than the additional data length that was previously |
| 2658 | * specified with psa_aead_set_lengths(). |
| 2659 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 2660 | * The total length of input to psa_aead_update() so far is |
| 2661 | * less than the plaintext length that was previously |
| 2662 | * specified with psa_aead_set_lengths(). |
Gilles Peskine | 30a9e41 | 2019-01-14 18:36:12 +0100 | [diff] [blame] | 2663 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 2664 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 2665 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 2666 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 2667 | */ |
| 2668 | psa_status_t psa_aead_verify(psa_aead_operation_t *operation, |
Gilles Peskine | 5211efb | 2019-05-06 15:56:05 +0200 | [diff] [blame] | 2669 | uint8_t *plaintext, |
| 2670 | size_t plaintext_size, |
| 2671 | size_t *plaintext_length, |
Gilles Peskine | 30a9e41 | 2019-01-14 18:36:12 +0100 | [diff] [blame] | 2672 | const uint8_t *tag, |
| 2673 | size_t tag_length); |
| 2674 | |
| 2675 | /** Abort an AEAD operation. |
| 2676 | * |
| 2677 | * Aborting an operation frees all associated resources except for the |
| 2678 | * \p operation structure itself. Once aborted, the operation object |
| 2679 | * can be reused for another operation by calling |
| 2680 | * psa_aead_encrypt_setup() or psa_aead_decrypt_setup() again. |
| 2681 | * |
| 2682 | * You may call this function any time after the operation object has |
| 2683 | * been initialized by any of the following methods: |
| 2684 | * - A call to psa_aead_encrypt_setup() or psa_aead_decrypt_setup(), |
| 2685 | * whether it succeeds or not. |
| 2686 | * - Initializing the \c struct to all-bits-zero. |
| 2687 | * - Initializing the \c struct to logical zeros, e.g. |
| 2688 | * `psa_aead_operation_t operation = {0}`. |
| 2689 | * |
| 2690 | * In particular, calling psa_aead_abort() after the operation has been |
| 2691 | * terminated by a call to psa_aead_abort() or psa_aead_finish() |
| 2692 | * is safe and has no effect. |
| 2693 | * |
| 2694 | * \param[in,out] operation Initialized AEAD operation. |
| 2695 | * |
| 2696 | * \retval #PSA_SUCCESS |
| 2697 | * \retval #PSA_ERROR_BAD_STATE |
| 2698 | * \p operation is not an active AEAD operation. |
| 2699 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 2700 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 2701 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 2702 | */ |
| 2703 | psa_status_t psa_aead_abort(psa_aead_operation_t *operation); |
| 2704 | |
Gilles Peskine | 3b55571 | 2018-03-03 21:27:57 +0100 | [diff] [blame] | 2705 | /**@}*/ |
| 2706 | |
Gilles Peskine | 20035e3 | 2018-02-03 22:44:14 +0100 | [diff] [blame] | 2707 | /** \defgroup asymmetric Asymmetric cryptography |
| 2708 | * @{ |
| 2709 | */ |
| 2710 | |
| 2711 | /** |
| 2712 | * \brief Sign a hash or short message with a private key. |
| 2713 | * |
Gilles Peskine | 08bac71 | 2018-06-26 16:14:46 +0200 | [diff] [blame] | 2714 | * Note that to perform a hash-and-sign signature algorithm, you must |
Gilles Peskine | da8191d1c | 2018-07-08 19:46:38 +0200 | [diff] [blame] | 2715 | * first calculate the hash by calling psa_hash_setup(), psa_hash_update() |
Gilles Peskine | 08bac71 | 2018-06-26 16:14:46 +0200 | [diff] [blame] | 2716 | * and psa_hash_finish(). Then pass the resulting hash as the \p hash |
| 2717 | * parameter to this function. You can use #PSA_ALG_SIGN_GET_HASH(\p alg) |
| 2718 | * to determine the hash algorithm to use. |
| 2719 | * |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 2720 | * \param handle Handle to the key to use for the operation. |
| 2721 | * It must be an asymmetric key pair. |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 2722 | * \param alg A signature algorithm that is compatible with |
Gilles Peskine | 3be6b7f | 2019-03-05 19:32:26 +0100 | [diff] [blame] | 2723 | * the type of \p handle. |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 2724 | * \param[in] hash The hash or message to sign. |
Gilles Peskine | fa4070c | 2018-07-12 19:23:03 +0200 | [diff] [blame] | 2725 | * \param hash_length Size of the \p hash buffer in bytes. |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 2726 | * \param[out] signature Buffer where the signature is to be written. |
Gilles Peskine | fa4070c | 2018-07-12 19:23:03 +0200 | [diff] [blame] | 2727 | * \param signature_size Size of the \p signature buffer in bytes. |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 2728 | * \param[out] signature_length On success, the number of bytes |
| 2729 | * that make up the returned signature value. |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 2730 | * |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 2731 | * \retval #PSA_SUCCESS |
| 2732 | * \retval #PSA_ERROR_BUFFER_TOO_SMALL |
Gilles Peskine | fa4070c | 2018-07-12 19:23:03 +0200 | [diff] [blame] | 2733 | * The size of the \p signature buffer is too small. You can |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 2734 | * determine a sufficient buffer size by calling |
Gilles Peskine | 7256e6c | 2018-07-12 00:34:26 +0200 | [diff] [blame] | 2735 | * #PSA_ASYMMETRIC_SIGN_OUTPUT_SIZE(\c key_type, \c key_bits, \p alg) |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 2736 | * where \c key_type and \c key_bits are the type and bit-size |
Gilles Peskine | 3be6b7f | 2019-03-05 19:32:26 +0100 | [diff] [blame] | 2737 | * respectively of \p handle. |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 2738 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 2739 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 2740 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 2741 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 2742 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 2743 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 2744 | * \retval #PSA_ERROR_INSUFFICIENT_ENTROPY |
itayzafrir | 90d8c7a | 2018-09-12 11:44:52 +0300 | [diff] [blame] | 2745 | * \retval #PSA_ERROR_BAD_STATE |
itayzafrir | 1861709 | 2018-09-16 12:22:41 +0300 | [diff] [blame] | 2746 | * The library has not been previously initialized by psa_crypto_init(). |
| 2747 | * It is implementation-dependent whether a failure to initialize |
| 2748 | * results in this error code. |
Gilles Peskine | 20035e3 | 2018-02-03 22:44:14 +0100 | [diff] [blame] | 2749 | */ |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 2750 | psa_status_t psa_asymmetric_sign(psa_key_handle_t handle, |
Gilles Peskine | 20035e3 | 2018-02-03 22:44:14 +0100 | [diff] [blame] | 2751 | psa_algorithm_t alg, |
| 2752 | const uint8_t *hash, |
| 2753 | size_t hash_length, |
Gilles Peskine | 20035e3 | 2018-02-03 22:44:14 +0100 | [diff] [blame] | 2754 | uint8_t *signature, |
| 2755 | size_t signature_size, |
| 2756 | size_t *signature_length); |
| 2757 | |
| 2758 | /** |
| 2759 | * \brief Verify the signature a hash or short message using a public key. |
| 2760 | * |
Gilles Peskine | 08bac71 | 2018-06-26 16:14:46 +0200 | [diff] [blame] | 2761 | * Note that to perform a hash-and-sign signature algorithm, you must |
Gilles Peskine | da8191d1c | 2018-07-08 19:46:38 +0200 | [diff] [blame] | 2762 | * first calculate the hash by calling psa_hash_setup(), psa_hash_update() |
Gilles Peskine | 08bac71 | 2018-06-26 16:14:46 +0200 | [diff] [blame] | 2763 | * and psa_hash_finish(). Then pass the resulting hash as the \p hash |
| 2764 | * parameter to this function. You can use #PSA_ALG_SIGN_GET_HASH(\p alg) |
| 2765 | * to determine the hash algorithm to use. |
| 2766 | * |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 2767 | * \param handle Handle to the key to use for the operation. |
| 2768 | * It must be a public key or an asymmetric key pair. |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 2769 | * \param alg A signature algorithm that is compatible with |
Gilles Peskine | 3be6b7f | 2019-03-05 19:32:26 +0100 | [diff] [blame] | 2770 | * the type of \p handle. |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 2771 | * \param[in] hash The hash or message whose signature is to be |
Gilles Peskine | 08bac71 | 2018-06-26 16:14:46 +0200 | [diff] [blame] | 2772 | * verified. |
Gilles Peskine | fa4070c | 2018-07-12 19:23:03 +0200 | [diff] [blame] | 2773 | * \param hash_length Size of the \p hash buffer in bytes. |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 2774 | * \param[in] signature Buffer containing the signature to verify. |
Gilles Peskine | fa4070c | 2018-07-12 19:23:03 +0200 | [diff] [blame] | 2775 | * \param signature_length Size of the \p signature buffer in bytes. |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 2776 | * |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 2777 | * \retval #PSA_SUCCESS |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 2778 | * The signature is valid. |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 2779 | * \retval #PSA_ERROR_INVALID_SIGNATURE |
Gilles Peskine | 308b91d | 2018-02-08 09:47:44 +0100 | [diff] [blame] | 2780 | * The calculation was perfomed successfully, but the passed |
| 2781 | * signature is not a valid signature. |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 2782 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 2783 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 2784 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 2785 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 2786 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 2787 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
itayzafrir | 90d8c7a | 2018-09-12 11:44:52 +0300 | [diff] [blame] | 2788 | * \retval #PSA_ERROR_BAD_STATE |
itayzafrir | 1861709 | 2018-09-16 12:22:41 +0300 | [diff] [blame] | 2789 | * The library has not been previously initialized by psa_crypto_init(). |
| 2790 | * It is implementation-dependent whether a failure to initialize |
| 2791 | * results in this error code. |
Gilles Peskine | 20035e3 | 2018-02-03 22:44:14 +0100 | [diff] [blame] | 2792 | */ |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 2793 | psa_status_t psa_asymmetric_verify(psa_key_handle_t handle, |
Gilles Peskine | 20035e3 | 2018-02-03 22:44:14 +0100 | [diff] [blame] | 2794 | psa_algorithm_t alg, |
| 2795 | const uint8_t *hash, |
| 2796 | size_t hash_length, |
Gilles Peskine | e9191ff | 2018-06-27 14:58:41 +0200 | [diff] [blame] | 2797 | const uint8_t *signature, |
Gilles Peskine | 526fab0 | 2018-06-27 18:19:40 +0200 | [diff] [blame] | 2798 | size_t signature_length); |
Gilles Peskine | 20035e3 | 2018-02-03 22:44:14 +0100 | [diff] [blame] | 2799 | |
Gilles Peskine | 6944f9a | 2018-03-28 14:18:39 +0200 | [diff] [blame] | 2800 | /** |
| 2801 | * \brief Encrypt a short message with a public key. |
| 2802 | * |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 2803 | * \param handle Handle to the key to use for the operation. |
| 2804 | * It must be a public key or an asymmetric |
| 2805 | * key pair. |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 2806 | * \param alg An asymmetric encryption algorithm that is |
Gilles Peskine | 3be6b7f | 2019-03-05 19:32:26 +0100 | [diff] [blame] | 2807 | * compatible with the type of \p handle. |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 2808 | * \param[in] input The message to encrypt. |
Gilles Peskine | fa4070c | 2018-07-12 19:23:03 +0200 | [diff] [blame] | 2809 | * \param input_length Size of the \p input buffer in bytes. |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 2810 | * \param[in] salt A salt or label, if supported by the |
| 2811 | * encryption algorithm. |
| 2812 | * If the algorithm does not support a |
| 2813 | * salt, pass \c NULL. |
| 2814 | * If the algorithm supports an optional |
| 2815 | * salt and you do not want to pass a salt, |
| 2816 | * pass \c NULL. |
Gilles Peskine | 6944f9a | 2018-03-28 14:18:39 +0200 | [diff] [blame] | 2817 | * |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 2818 | * - For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is |
| 2819 | * supported. |
Gilles Peskine | fa4070c | 2018-07-12 19:23:03 +0200 | [diff] [blame] | 2820 | * \param salt_length Size of the \p salt buffer in bytes. |
| 2821 | * If \p salt is \c NULL, pass 0. |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 2822 | * \param[out] output Buffer where the encrypted message is to |
| 2823 | * be written. |
Gilles Peskine | fa4070c | 2018-07-12 19:23:03 +0200 | [diff] [blame] | 2824 | * \param output_size Size of the \p output buffer in bytes. |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 2825 | * \param[out] output_length On success, the number of bytes |
| 2826 | * that make up the returned output. |
Gilles Peskine | 6944f9a | 2018-03-28 14:18:39 +0200 | [diff] [blame] | 2827 | * |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 2828 | * \retval #PSA_SUCCESS |
| 2829 | * \retval #PSA_ERROR_BUFFER_TOO_SMALL |
Gilles Peskine | fa4070c | 2018-07-12 19:23:03 +0200 | [diff] [blame] | 2830 | * The size of the \p output buffer is too small. You can |
Gilles Peskine | 6944f9a | 2018-03-28 14:18:39 +0200 | [diff] [blame] | 2831 | * determine a sufficient buffer size by calling |
Gilles Peskine | 7256e6c | 2018-07-12 00:34:26 +0200 | [diff] [blame] | 2832 | * #PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(\c key_type, \c key_bits, \p alg) |
Gilles Peskine | 6944f9a | 2018-03-28 14:18:39 +0200 | [diff] [blame] | 2833 | * where \c key_type and \c key_bits are the type and bit-size |
Gilles Peskine | 3be6b7f | 2019-03-05 19:32:26 +0100 | [diff] [blame] | 2834 | * respectively of \p handle. |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 2835 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 2836 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 2837 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 2838 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 2839 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 2840 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 2841 | * \retval #PSA_ERROR_INSUFFICIENT_ENTROPY |
itayzafrir | 90d8c7a | 2018-09-12 11:44:52 +0300 | [diff] [blame] | 2842 | * \retval #PSA_ERROR_BAD_STATE |
itayzafrir | 1861709 | 2018-09-16 12:22:41 +0300 | [diff] [blame] | 2843 | * The library has not been previously initialized by psa_crypto_init(). |
| 2844 | * It is implementation-dependent whether a failure to initialize |
| 2845 | * results in this error code. |
Gilles Peskine | 6944f9a | 2018-03-28 14:18:39 +0200 | [diff] [blame] | 2846 | */ |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 2847 | psa_status_t psa_asymmetric_encrypt(psa_key_handle_t handle, |
Gilles Peskine | 6944f9a | 2018-03-28 14:18:39 +0200 | [diff] [blame] | 2848 | psa_algorithm_t alg, |
| 2849 | const uint8_t *input, |
| 2850 | size_t input_length, |
| 2851 | const uint8_t *salt, |
| 2852 | size_t salt_length, |
| 2853 | uint8_t *output, |
| 2854 | size_t output_size, |
| 2855 | size_t *output_length); |
| 2856 | |
| 2857 | /** |
| 2858 | * \brief Decrypt a short message with a private key. |
| 2859 | * |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 2860 | * \param handle Handle to the key to use for the operation. |
| 2861 | * It must be an asymmetric key pair. |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 2862 | * \param alg An asymmetric encryption algorithm that is |
Gilles Peskine | 3be6b7f | 2019-03-05 19:32:26 +0100 | [diff] [blame] | 2863 | * compatible with the type of \p handle. |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 2864 | * \param[in] input The message to decrypt. |
Gilles Peskine | fa4070c | 2018-07-12 19:23:03 +0200 | [diff] [blame] | 2865 | * \param input_length Size of the \p input buffer in bytes. |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 2866 | * \param[in] salt A salt or label, if supported by the |
| 2867 | * encryption algorithm. |
| 2868 | * If the algorithm does not support a |
| 2869 | * salt, pass \c NULL. |
| 2870 | * If the algorithm supports an optional |
| 2871 | * salt and you do not want to pass a salt, |
| 2872 | * pass \c NULL. |
Gilles Peskine | 6944f9a | 2018-03-28 14:18:39 +0200 | [diff] [blame] | 2873 | * |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 2874 | * - For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is |
| 2875 | * supported. |
Gilles Peskine | fa4070c | 2018-07-12 19:23:03 +0200 | [diff] [blame] | 2876 | * \param salt_length Size of the \p salt buffer in bytes. |
| 2877 | * If \p salt is \c NULL, pass 0. |
Gilles Peskine | edd11a1 | 2018-07-12 01:08:58 +0200 | [diff] [blame] | 2878 | * \param[out] output Buffer where the decrypted message is to |
| 2879 | * be written. |
| 2880 | * \param output_size Size of the \c output buffer in bytes. |
| 2881 | * \param[out] output_length On success, the number of bytes |
| 2882 | * that make up the returned output. |
Gilles Peskine | 6944f9a | 2018-03-28 14:18:39 +0200 | [diff] [blame] | 2883 | * |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 2884 | * \retval #PSA_SUCCESS |
| 2885 | * \retval #PSA_ERROR_BUFFER_TOO_SMALL |
Gilles Peskine | fa4070c | 2018-07-12 19:23:03 +0200 | [diff] [blame] | 2886 | * The size of the \p output buffer is too small. You can |
Gilles Peskine | 6944f9a | 2018-03-28 14:18:39 +0200 | [diff] [blame] | 2887 | * determine a sufficient buffer size by calling |
Gilles Peskine | dda3bd3 | 2018-07-12 19:40:46 +0200 | [diff] [blame] | 2888 | * #PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE(\c key_type, \c key_bits, \p alg) |
Gilles Peskine | 6944f9a | 2018-03-28 14:18:39 +0200 | [diff] [blame] | 2889 | * where \c key_type and \c key_bits are the type and bit-size |
Gilles Peskine | 3be6b7f | 2019-03-05 19:32:26 +0100 | [diff] [blame] | 2890 | * respectively of \p handle. |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 2891 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 2892 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 2893 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 2894 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 2895 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 2896 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 2897 | * \retval #PSA_ERROR_INSUFFICIENT_ENTROPY |
| 2898 | * \retval #PSA_ERROR_INVALID_PADDING |
itayzafrir | 90d8c7a | 2018-09-12 11:44:52 +0300 | [diff] [blame] | 2899 | * \retval #PSA_ERROR_BAD_STATE |
itayzafrir | 1861709 | 2018-09-16 12:22:41 +0300 | [diff] [blame] | 2900 | * The library has not been previously initialized by psa_crypto_init(). |
| 2901 | * It is implementation-dependent whether a failure to initialize |
| 2902 | * results in this error code. |
Gilles Peskine | 6944f9a | 2018-03-28 14:18:39 +0200 | [diff] [blame] | 2903 | */ |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 2904 | psa_status_t psa_asymmetric_decrypt(psa_key_handle_t handle, |
Gilles Peskine | 6944f9a | 2018-03-28 14:18:39 +0200 | [diff] [blame] | 2905 | psa_algorithm_t alg, |
| 2906 | const uint8_t *input, |
| 2907 | size_t input_length, |
| 2908 | const uint8_t *salt, |
| 2909 | size_t salt_length, |
| 2910 | uint8_t *output, |
| 2911 | size_t output_size, |
| 2912 | size_t *output_length); |
| 2913 | |
Gilles Peskine | 2f9c4dc | 2018-01-28 13:16:24 +0100 | [diff] [blame] | 2914 | /**@}*/ |
| 2915 | |
Gilles Peskine | edd7687 | 2018-07-20 17:42:05 +0200 | [diff] [blame] | 2916 | /** \defgroup generators Generators |
Gilles Peskine | eab56e4 | 2018-07-12 17:12:33 +0200 | [diff] [blame] | 2917 | * @{ |
| 2918 | */ |
| 2919 | |
| 2920 | /** The type of the state data structure for generators. |
| 2921 | * |
| 2922 | * Before calling any function on a generator, the application must |
| 2923 | * initialize it by any of the following means: |
| 2924 | * - Set the structure to all-bits-zero, for example: |
| 2925 | * \code |
| 2926 | * psa_crypto_generator_t generator; |
| 2927 | * memset(&generator, 0, sizeof(generator)); |
| 2928 | * \endcode |
| 2929 | * - Initialize the structure to logical zero values, for example: |
| 2930 | * \code |
| 2931 | * psa_crypto_generator_t generator = {0}; |
| 2932 | * \endcode |
| 2933 | * - Initialize the structure to the initializer #PSA_CRYPTO_GENERATOR_INIT, |
| 2934 | * for example: |
| 2935 | * \code |
| 2936 | * psa_crypto_generator_t generator = PSA_CRYPTO_GENERATOR_INIT; |
| 2937 | * \endcode |
| 2938 | * - Assign the result of the function psa_crypto_generator_init() |
| 2939 | * to the structure, for example: |
| 2940 | * \code |
| 2941 | * psa_crypto_generator_t generator; |
| 2942 | * generator = psa_crypto_generator_init(); |
| 2943 | * \endcode |
| 2944 | * |
| 2945 | * This is an implementation-defined \c struct. Applications should not |
| 2946 | * make any assumptions about the content of this structure except |
| 2947 | * as directed by the documentation of a specific implementation. |
| 2948 | */ |
| 2949 | typedef struct psa_crypto_generator_s psa_crypto_generator_t; |
| 2950 | |
| 2951 | /** \def PSA_CRYPTO_GENERATOR_INIT |
| 2952 | * |
| 2953 | * This macro returns a suitable initializer for a generator object |
| 2954 | * of type #psa_crypto_generator_t. |
| 2955 | */ |
| 2956 | #ifdef __DOXYGEN_ONLY__ |
| 2957 | /* This is an example definition for documentation purposes. |
| 2958 | * Implementations should define a suitable value in `crypto_struct.h`. |
| 2959 | */ |
| 2960 | #define PSA_CRYPTO_GENERATOR_INIT {0} |
| 2961 | #endif |
| 2962 | |
| 2963 | /** Return an initial value for a generator object. |
| 2964 | */ |
| 2965 | static psa_crypto_generator_t psa_crypto_generator_init(void); |
| 2966 | |
| 2967 | /** Retrieve the current capacity of a generator. |
| 2968 | * |
| 2969 | * The capacity of a generator is the maximum number of bytes that it can |
| 2970 | * return. Reading *N* bytes from a generator reduces its capacity by *N*. |
| 2971 | * |
| 2972 | * \param[in] generator The generator to query. |
| 2973 | * \param[out] capacity On success, the capacity of the generator. |
| 2974 | * |
Gilles Peskine | 644cd5f | 2018-12-11 16:47:35 +0100 | [diff] [blame] | 2975 | * \retval #PSA_SUCCESS |
| 2976 | * \retval #PSA_ERROR_BAD_STATE |
| 2977 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
Gilles Peskine | eab56e4 | 2018-07-12 17:12:33 +0200 | [diff] [blame] | 2978 | */ |
| 2979 | psa_status_t psa_get_generator_capacity(const psa_crypto_generator_t *generator, |
| 2980 | size_t *capacity); |
| 2981 | |
Gilles Peskine | b70a0fd | 2019-01-07 22:59:38 +0100 | [diff] [blame] | 2982 | /** Set the maximum capacity of a generator. |
| 2983 | * |
| 2984 | * \param[in,out] generator The generator object to modify. |
| 2985 | * \param capacity The new capacity of the generator. |
| 2986 | * It must be less or equal to the generator's |
| 2987 | * current capacity. |
| 2988 | * |
| 2989 | * \retval #PSA_SUCCESS |
| 2990 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 2991 | * \p capacity is larger than the generator's current capacity. |
| 2992 | * \retval #PSA_ERROR_BAD_STATE |
| 2993 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 2994 | */ |
| 2995 | psa_status_t psa_set_generator_capacity(psa_crypto_generator_t *generator, |
| 2996 | size_t capacity); |
| 2997 | |
Gilles Peskine | eab56e4 | 2018-07-12 17:12:33 +0200 | [diff] [blame] | 2998 | /** Read some data from a generator. |
| 2999 | * |
| 3000 | * This function reads and returns a sequence of bytes from a generator. |
| 3001 | * The data that is read is discarded from the generator. The generator's |
| 3002 | * capacity is decreased by the number of bytes read. |
| 3003 | * |
| 3004 | * \param[in,out] generator The generator object to read from. |
| 3005 | * \param[out] output Buffer where the generator output will be |
| 3006 | * written. |
| 3007 | * \param output_length Number of bytes to output. |
| 3008 | * |
Gilles Peskine | 644cd5f | 2018-12-11 16:47:35 +0100 | [diff] [blame] | 3009 | * \retval #PSA_SUCCESS |
David Saada | b4ecc27 | 2019-02-14 13:48:10 +0200 | [diff] [blame] | 3010 | * \retval #PSA_ERROR_INSUFFICIENT_DATA |
Gilles Peskine | eab56e4 | 2018-07-12 17:12:33 +0200 | [diff] [blame] | 3011 | * There were fewer than \p output_length bytes |
| 3012 | * in the generator. Note that in this case, no |
| 3013 | * output is written to the output buffer. |
| 3014 | * The generator's capacity is set to 0, thus |
| 3015 | * subsequent calls to this function will not |
| 3016 | * succeed, even with a smaller output buffer. |
Gilles Peskine | 644cd5f | 2018-12-11 16:47:35 +0100 | [diff] [blame] | 3017 | * \retval #PSA_ERROR_BAD_STATE |
| 3018 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 3019 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 3020 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 3021 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
Gilles Peskine | eab56e4 | 2018-07-12 17:12:33 +0200 | [diff] [blame] | 3022 | */ |
| 3023 | psa_status_t psa_generator_read(psa_crypto_generator_t *generator, |
| 3024 | uint8_t *output, |
| 3025 | size_t output_length); |
| 3026 | |
Gilles Peskine | fa4486d | 2019-03-11 17:30:31 +0100 | [diff] [blame] | 3027 | /** Generate a key deterministically from data read from a generator. |
Gilles Peskine | eab56e4 | 2018-07-12 17:12:33 +0200 | [diff] [blame] | 3028 | * |
Gilles Peskine | fa4486d | 2019-03-11 17:30:31 +0100 | [diff] [blame] | 3029 | * This function uses the output of a generator to derive a key. |
| 3030 | * How much output it consumes and how the key is derived depends on the |
| 3031 | * key type. |
Gilles Peskine | eab56e4 | 2018-07-12 17:12:33 +0200 | [diff] [blame] | 3032 | * |
Gilles Peskine | fa4486d | 2019-03-11 17:30:31 +0100 | [diff] [blame] | 3033 | * - For key types for which the key is an arbitrary sequence of bytes |
| 3034 | * of a given size, |
| 3035 | * this function is functionally equivalent to calling #psa_generator_read |
| 3036 | * and passing the resulting output to #psa_import_key. |
| 3037 | * However, this function has a security benefit: |
| 3038 | * if the implementation provides an isolation boundary then |
| 3039 | * the key material is not exposed outside the isolation boundary. |
| 3040 | * As a consequence, for these key types, this function always consumes |
| 3041 | * exactly (\p bits / 8) bytes from the generator. |
| 3042 | * The following key types defined in this specification follow this scheme: |
| 3043 | * |
| 3044 | * - #PSA_KEY_TYPE_AES; |
Gilles Peskine | fa4486d | 2019-03-11 17:30:31 +0100 | [diff] [blame] | 3045 | * - #PSA_KEY_TYPE_ARC4; |
| 3046 | * - #PSA_KEY_TYPE_CAMELLIA; |
Gilles Peskine | fa4486d | 2019-03-11 17:30:31 +0100 | [diff] [blame] | 3047 | * - #PSA_KEY_TYPE_DERIVE; |
| 3048 | * - #PSA_KEY_TYPE_HMAC. |
| 3049 | * |
| 3050 | * - For ECC keys on a Montgomery elliptic curve |
| 3051 | * (#PSA_KEY_TYPE_ECC_KEYPAIR(\c curve) where \c curve designates a |
| 3052 | * Montgomery curve), this function always draws a byte string whose |
| 3053 | * length is determined by the curve, and sets the mandatory bits |
| 3054 | * accordingly. That is: |
| 3055 | * |
| 3056 | * - #PSA_ECC_CURVE_CURVE25519: draw a 32-byte string |
| 3057 | * and process it as specified in RFC 7748 §5. |
| 3058 | * - #PSA_ECC_CURVE_CURVE448: draw a 56-byte string |
| 3059 | * and process it as specified in RFC 7748 §5. |
| 3060 | * |
| 3061 | * - For key types for which the key is represented by a single sequence of |
| 3062 | * \p bits bits with constraints as to which bit sequences are acceptable, |
| 3063 | * this function draws a byte string of length (\p bits / 8) bytes rounded |
| 3064 | * up to the nearest whole number of bytes. If the resulting byte string |
| 3065 | * is acceptable, it becomes the key, otherwise the drawn bytes are discarded. |
| 3066 | * This process is repeated until an acceptable byte string is drawn. |
| 3067 | * The byte string drawn from the generator is interpreted as specified |
| 3068 | * for the output produced by psa_export_key(). |
| 3069 | * The following key types defined in this specification follow this scheme: |
| 3070 | * |
Gilles Peskine | 2de2c0d | 2019-03-11 17:59:16 +0100 | [diff] [blame] | 3071 | * - #PSA_KEY_TYPE_DES. |
| 3072 | * Force-set the parity bits, but discard forbidden weak keys. |
| 3073 | * For 2-key and 3-key triple-DES, the three keys are generated |
| 3074 | * successively (for example, for 3-key triple-DES, |
| 3075 | * if the first 8 bytes specify a weak key and the next 8 bytes do not, |
| 3076 | * discard the first 8 bytes, use the next 8 bytes as the first key, |
| 3077 | * and continue reading output from the generator to derive the other |
| 3078 | * two keys). |
| 3079 | * - Finite-field Diffie-Hellman keys (#PSA_KEY_TYPE_DH_KEYPAIR), |
| 3080 | * DSA keys (#PSA_KEY_TYPE_DSA_KEYPAIR), and |
| 3081 | * ECC keys on a Weierstrass elliptic curve |
| 3082 | * (#PSA_KEY_TYPE_ECC_KEYPAIR(\c curve) where \c curve designates a |
| 3083 | * Weierstrass curve). |
| 3084 | * For these key types, interpret the byte string as integer |
| 3085 | * in big-endian order. Discard it if it is not in the range |
| 3086 | * [0, *N* - 2] where *N* is the boundary of the private key domain |
| 3087 | * (the prime *p* for Diffie-Hellman, the subprime *q* for DSA, |
Gilles Peskine | 5579971 | 2019-03-12 11:50:26 +0100 | [diff] [blame] | 3088 | * or the order of the curve's base point for ECC). |
Gilles Peskine | 2de2c0d | 2019-03-11 17:59:16 +0100 | [diff] [blame] | 3089 | * Add 1 to the resulting integer and use this as the private key *x*. |
Gilles Peskine | 5579971 | 2019-03-12 11:50:26 +0100 | [diff] [blame] | 3090 | * This method allows compliance to NIST standards, specifically |
| 3091 | * the methods titled "key-pair generation by testing candidates" |
Gilles Peskine | 2de2c0d | 2019-03-11 17:59:16 +0100 | [diff] [blame] | 3092 | * in NIST SP 800-56A §5.6.1.1.4 for Diffie-Hellman, |
| 3093 | * in FIPS 186-4 §B.1.2 for DSA, and |
| 3094 | * in NIST SP 800-56A §5.6.1.2.2 or |
| 3095 | * FIPS 186-4 §B.4.2 for elliptic curve keys. |
Gilles Peskine | fa4486d | 2019-03-11 17:30:31 +0100 | [diff] [blame] | 3096 | * |
| 3097 | * - For other key types, including #PSA_KEY_TYPE_RSA_KEYPAIR, |
| 3098 | * the way in which the generator output is consumed is |
| 3099 | * implementation-defined. |
| 3100 | * |
| 3101 | * In all cases, the data that is read is discarded from the generator. |
| 3102 | * The generator's capacity is decreased by the number of bytes read. |
Gilles Peskine | eab56e4 | 2018-07-12 17:12:33 +0200 | [diff] [blame] | 3103 | * |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 3104 | * \param[in] attributes The attributes for the new key. |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 3105 | * \param[out] handle On success, a handle to the newly created key. |
| 3106 | * \c 0 on failure. |
Gilles Peskine | eab56e4 | 2018-07-12 17:12:33 +0200 | [diff] [blame] | 3107 | * \param[in,out] generator The generator object to read from. |
| 3108 | * |
Gilles Peskine | 644cd5f | 2018-12-11 16:47:35 +0100 | [diff] [blame] | 3109 | * \retval #PSA_SUCCESS |
Gilles Peskine | eab56e4 | 2018-07-12 17:12:33 +0200 | [diff] [blame] | 3110 | * Success. |
Gilles Peskine | 23fd2bd | 2018-12-11 15:51:32 +0100 | [diff] [blame] | 3111 | * If the key is persistent, the key material and the key's metadata |
| 3112 | * have been saved to persistent storage. |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 3113 | * \retval #PSA_ERROR_ALREADY_EXISTS |
| 3114 | * This is an attempt to create a persistent key, and there is |
| 3115 | * already a persistent key with the given identifier. |
David Saada | b4ecc27 | 2019-02-14 13:48:10 +0200 | [diff] [blame] | 3116 | * \retval #PSA_ERROR_INSUFFICIENT_DATA |
Gilles Peskine | fa4486d | 2019-03-11 17:30:31 +0100 | [diff] [blame] | 3117 | * There was not enough data to create the desired key. |
| 3118 | * Note that in this case, no output is written to the output buffer. |
| 3119 | * The generator's capacity is set to 0, thus subsequent calls to |
| 3120 | * this function will not succeed, even with a smaller output buffer. |
Gilles Peskine | 644cd5f | 2018-12-11 16:47:35 +0100 | [diff] [blame] | 3121 | * \retval #PSA_ERROR_NOT_SUPPORTED |
Gilles Peskine | eab56e4 | 2018-07-12 17:12:33 +0200 | [diff] [blame] | 3122 | * The key type or key size is not supported, either by the |
| 3123 | * implementation in general or in this particular slot. |
Gilles Peskine | 644cd5f | 2018-12-11 16:47:35 +0100 | [diff] [blame] | 3124 | * \retval #PSA_ERROR_BAD_STATE |
Gilles Peskine | 644cd5f | 2018-12-11 16:47:35 +0100 | [diff] [blame] | 3125 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 3126 | * \retval #PSA_ERROR_INSUFFICIENT_STORAGE |
| 3127 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 3128 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 3129 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
itayzafrir | 90d8c7a | 2018-09-12 11:44:52 +0300 | [diff] [blame] | 3130 | * \retval #PSA_ERROR_BAD_STATE |
itayzafrir | 1861709 | 2018-09-16 12:22:41 +0300 | [diff] [blame] | 3131 | * The library has not been previously initialized by psa_crypto_init(). |
| 3132 | * It is implementation-dependent whether a failure to initialize |
| 3133 | * results in this error code. |
Gilles Peskine | eab56e4 | 2018-07-12 17:12:33 +0200 | [diff] [blame] | 3134 | */ |
Adrian L. Shaw | 5a5a79a | 2019-05-03 15:44:28 +0100 | [diff] [blame] | 3135 | psa_status_t psa_generate_derived_key(const psa_key_attributes_t *attributes, |
Gilles Peskine | 87a5e56 | 2019-04-17 12:28:25 +0200 | [diff] [blame] | 3136 | psa_key_handle_t *handle, |
Gilles Peskine | eab56e4 | 2018-07-12 17:12:33 +0200 | [diff] [blame] | 3137 | psa_crypto_generator_t *generator); |
| 3138 | |
| 3139 | /** Abort a generator. |
| 3140 | * |
| 3141 | * Once a generator has been aborted, its capacity is zero. |
| 3142 | * Aborting a generator frees all associated resources except for the |
| 3143 | * \c generator structure itself. |
| 3144 | * |
| 3145 | * This function may be called at any time as long as the generator |
| 3146 | * object has been initialized to #PSA_CRYPTO_GENERATOR_INIT, to |
| 3147 | * psa_crypto_generator_init() or a zero value. In particular, it is valid |
| 3148 | * to call psa_generator_abort() twice, or to call psa_generator_abort() |
| 3149 | * on a generator that has not been set up. |
| 3150 | * |
| 3151 | * Once aborted, the generator object may be called. |
| 3152 | * |
| 3153 | * \param[in,out] generator The generator to abort. |
| 3154 | * |
Gilles Peskine | 644cd5f | 2018-12-11 16:47:35 +0100 | [diff] [blame] | 3155 | * \retval #PSA_SUCCESS |
| 3156 | * \retval #PSA_ERROR_BAD_STATE |
| 3157 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 3158 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 3159 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
Gilles Peskine | eab56e4 | 2018-07-12 17:12:33 +0200 | [diff] [blame] | 3160 | */ |
| 3161 | psa_status_t psa_generator_abort(psa_crypto_generator_t *generator); |
| 3162 | |
Gilles Peskine | 8feb3a8 | 2018-09-18 12:06:11 +0200 | [diff] [blame] | 3163 | /** Use the maximum possible capacity for a generator. |
| 3164 | * |
| 3165 | * Use this value as the capacity argument when setting up a generator |
| 3166 | * to indicate that the generator should have the maximum possible capacity. |
| 3167 | * The value of the maximum possible capacity depends on the generator |
| 3168 | * algorithm. |
| 3169 | */ |
| 3170 | #define PSA_GENERATOR_UNBRIDLED_CAPACITY ((size_t)(-1)) |
| 3171 | |
Gilles Peskine | eab56e4 | 2018-07-12 17:12:33 +0200 | [diff] [blame] | 3172 | /**@}*/ |
| 3173 | |
Gilles Peskine | ea0fb49 | 2018-07-12 17:17:20 +0200 | [diff] [blame] | 3174 | /** \defgroup derivation Key derivation |
| 3175 | * @{ |
| 3176 | */ |
| 3177 | |
| 3178 | /** Set up a key derivation operation. |
| 3179 | * |
Gilles Peskine | b70a0fd | 2019-01-07 22:59:38 +0100 | [diff] [blame] | 3180 | * A key derivation algorithm takes some inputs and uses them to create |
| 3181 | * a byte generator which can be used to produce keys and other |
| 3182 | * cryptographic material. |
Gilles Peskine | ea0fb49 | 2018-07-12 17:17:20 +0200 | [diff] [blame] | 3183 | * |
Gilles Peskine | b70a0fd | 2019-01-07 22:59:38 +0100 | [diff] [blame] | 3184 | * To use a generator for key derivation: |
| 3185 | * - Start with an initialized object of type #psa_crypto_generator_t. |
| 3186 | * - Call psa_key_derivation_setup() to select the algorithm. |
| 3187 | * - Provide the inputs for the key derivation by calling |
| 3188 | * psa_key_derivation_input_bytes() or psa_key_derivation_input_key() |
| 3189 | * as appropriate. Which inputs are needed, in what order, and whether |
| 3190 | * they may be keys and if so of what type depends on the algorithm. |
| 3191 | * - Optionally set the generator's maximum capacity with |
| 3192 | * psa_set_generator_capacity(). You may do this before, in the middle of |
| 3193 | * or after providing inputs. For some algorithms, this step is mandatory |
| 3194 | * because the output depends on the maximum capacity. |
| 3195 | * - Generate output with psa_generator_read() or |
Adrian L. Shaw | 5a5a79a | 2019-05-03 15:44:28 +0100 | [diff] [blame] | 3196 | * psa_generate_derived_key(). Successive calls to these functions |
Gilles Peskine | b70a0fd | 2019-01-07 22:59:38 +0100 | [diff] [blame] | 3197 | * use successive output bytes from the generator. |
| 3198 | * - Clean up the generator object with psa_generator_abort(). |
Gilles Peskine | ea0fb49 | 2018-07-12 17:17:20 +0200 | [diff] [blame] | 3199 | * |
Gilles Peskine | b70a0fd | 2019-01-07 22:59:38 +0100 | [diff] [blame] | 3200 | * \param[in,out] generator The generator object to set up. It must |
| 3201 | * have been initialized but not set up yet. |
Gilles Peskine | ea0fb49 | 2018-07-12 17:17:20 +0200 | [diff] [blame] | 3202 | * \param alg The key derivation algorithm to compute |
| 3203 | * (\c PSA_ALG_XXX value such that |
| 3204 | * #PSA_ALG_IS_KEY_DERIVATION(\p alg) is true). |
Gilles Peskine | ea0fb49 | 2018-07-12 17:17:20 +0200 | [diff] [blame] | 3205 | * |
| 3206 | * \retval #PSA_SUCCESS |
| 3207 | * Success. |
Gilles Peskine | ea0fb49 | 2018-07-12 17:17:20 +0200 | [diff] [blame] | 3208 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
Gilles Peskine | b70a0fd | 2019-01-07 22:59:38 +0100 | [diff] [blame] | 3209 | * \c alg is not a key derivation algorithm. |
Gilles Peskine | ea0fb49 | 2018-07-12 17:17:20 +0200 | [diff] [blame] | 3210 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 3211 | * \c alg is not supported or is not a key derivation algorithm. |
| 3212 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 3213 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 3214 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 3215 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
itayzafrir | 90d8c7a | 2018-09-12 11:44:52 +0300 | [diff] [blame] | 3216 | * \retval #PSA_ERROR_BAD_STATE |
Gilles Peskine | b70a0fd | 2019-01-07 22:59:38 +0100 | [diff] [blame] | 3217 | */ |
| 3218 | psa_status_t psa_key_derivation_setup(psa_crypto_generator_t *generator, |
| 3219 | psa_algorithm_t alg); |
| 3220 | |
Gilles Peskine | 6cdfdb7 | 2019-01-08 10:31:27 +0100 | [diff] [blame] | 3221 | /** Provide an input for key derivation or key agreement. |
Gilles Peskine | b70a0fd | 2019-01-07 22:59:38 +0100 | [diff] [blame] | 3222 | * |
Gilles Peskine | 6cdfdb7 | 2019-01-08 10:31:27 +0100 | [diff] [blame] | 3223 | * Which inputs are required and in what order depends on the algorithm. |
| 3224 | * Refer to the documentation of each key derivation or key agreement |
| 3225 | * algorithm for information. |
Gilles Peskine | b70a0fd | 2019-01-07 22:59:38 +0100 | [diff] [blame] | 3226 | * |
Gilles Peskine | 6cdfdb7 | 2019-01-08 10:31:27 +0100 | [diff] [blame] | 3227 | * This function passes direct inputs. Some inputs must be passed as keys |
| 3228 | * using psa_key_derivation_input_key() instead of this function. Refer to |
| 3229 | * the documentation of individual step types for information. |
Gilles Peskine | b70a0fd | 2019-01-07 22:59:38 +0100 | [diff] [blame] | 3230 | * |
| 3231 | * \param[in,out] generator The generator object to use. It must |
| 3232 | * have been set up with |
| 3233 | * psa_key_derivation_setup() and must not |
| 3234 | * have produced any output yet. |
| 3235 | * \param step Which step the input data is for. |
Gilles Peskine | b70a0fd | 2019-01-07 22:59:38 +0100 | [diff] [blame] | 3236 | * \param[in] data Input data to use. |
| 3237 | * \param data_length Size of the \p data buffer in bytes. |
| 3238 | * |
| 3239 | * \retval #PSA_SUCCESS |
| 3240 | * Success. |
| 3241 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 3242 | * \c step is not compatible with the generator's algorithm. |
Gilles Peskine | 6cdfdb7 | 2019-01-08 10:31:27 +0100 | [diff] [blame] | 3243 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 3244 | * \c step does not allow direct inputs. |
Gilles Peskine | b70a0fd | 2019-01-07 22:59:38 +0100 | [diff] [blame] | 3245 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 3246 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 3247 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 3248 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 3249 | * \retval #PSA_ERROR_BAD_STATE |
| 3250 | * The value of \p step is not valid given the state of \p generator. |
| 3251 | * \retval #PSA_ERROR_BAD_STATE |
itayzafrir | 1861709 | 2018-09-16 12:22:41 +0300 | [diff] [blame] | 3252 | * The library has not been previously initialized by psa_crypto_init(). |
| 3253 | * It is implementation-dependent whether a failure to initialize |
| 3254 | * results in this error code. |
Gilles Peskine | ea0fb49 | 2018-07-12 17:17:20 +0200 | [diff] [blame] | 3255 | */ |
Gilles Peskine | b70a0fd | 2019-01-07 22:59:38 +0100 | [diff] [blame] | 3256 | psa_status_t psa_key_derivation_input_bytes(psa_crypto_generator_t *generator, |
| 3257 | psa_key_derivation_step_t step, |
| 3258 | const uint8_t *data, |
| 3259 | size_t data_length); |
Gilles Peskine | ea0fb49 | 2018-07-12 17:17:20 +0200 | [diff] [blame] | 3260 | |
Gilles Peskine | b70a0fd | 2019-01-07 22:59:38 +0100 | [diff] [blame] | 3261 | /** Provide an input for key derivation in the form of a key. |
| 3262 | * |
Gilles Peskine | 6cdfdb7 | 2019-01-08 10:31:27 +0100 | [diff] [blame] | 3263 | * Which inputs are required and in what order depends on the algorithm. |
| 3264 | * Refer to the documentation of each key derivation or key agreement |
| 3265 | * algorithm for information. |
| 3266 | * |
| 3267 | * This function passes key inputs. Some inputs must be passed as keys |
| 3268 | * of the appropriate type using this function, while others must be |
| 3269 | * passed as direct inputs using psa_key_derivation_input_bytes(). Refer to |
| 3270 | * the documentation of individual step types for information. |
Gilles Peskine | b70a0fd | 2019-01-07 22:59:38 +0100 | [diff] [blame] | 3271 | * |
| 3272 | * \param[in,out] generator The generator object to use. It must |
| 3273 | * have been set up with |
| 3274 | * psa_key_derivation_setup() and must not |
| 3275 | * have produced any output yet. |
| 3276 | * \param step Which step the input data is for. |
Gilles Peskine | 6cdfdb7 | 2019-01-08 10:31:27 +0100 | [diff] [blame] | 3277 | * \param handle Handle to the key. It must have an |
| 3278 | * appropriate type for \p step and must |
| 3279 | * allow the usage #PSA_KEY_USAGE_DERIVE. |
Gilles Peskine | b70a0fd | 2019-01-07 22:59:38 +0100 | [diff] [blame] | 3280 | * |
| 3281 | * \retval #PSA_SUCCESS |
| 3282 | * Success. |
| 3283 | * \retval #PSA_ERROR_INVALID_HANDLE |
Gilles Peskine | 3135184 | 2019-04-09 12:00:00 +0200 | [diff] [blame] | 3284 | * \retval #PSA_ERROR_DOES_NOT_EXIST |
Gilles Peskine | b70a0fd | 2019-01-07 22:59:38 +0100 | [diff] [blame] | 3285 | * \retval #PSA_ERROR_NOT_PERMITTED |
| 3286 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 3287 | * \c step is not compatible with the generator's algorithm. |
Gilles Peskine | 6cdfdb7 | 2019-01-08 10:31:27 +0100 | [diff] [blame] | 3288 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 3289 | * \c step does not allow key inputs. |
Gilles Peskine | b70a0fd | 2019-01-07 22:59:38 +0100 | [diff] [blame] | 3290 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 3291 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 3292 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 3293 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 3294 | * \retval #PSA_ERROR_BAD_STATE |
| 3295 | * The value of \p step is not valid given the state of \p generator. |
| 3296 | * \retval #PSA_ERROR_BAD_STATE |
| 3297 | * The library has not been previously initialized by psa_crypto_init(). |
| 3298 | * It is implementation-dependent whether a failure to initialize |
| 3299 | * results in this error code. |
| 3300 | */ |
| 3301 | psa_status_t psa_key_derivation_input_key(psa_crypto_generator_t *generator, |
| 3302 | psa_key_derivation_step_t step, |
| 3303 | psa_key_handle_t handle); |
| 3304 | |
Gilles Peskine | 969c5d6 | 2019-01-16 15:53:06 +0100 | [diff] [blame] | 3305 | /** Perform a key agreement and use the shared secret as input to a key |
| 3306 | * derivation. |
Gilles Peskine | 01d718c | 2018-09-18 12:01:02 +0200 | [diff] [blame] | 3307 | * |
| 3308 | * A key agreement algorithm takes two inputs: a private key \p private_key |
| 3309 | * a public key \p peer_key. |
Gilles Peskine | 969c5d6 | 2019-01-16 15:53:06 +0100 | [diff] [blame] | 3310 | * The result of this function is passed as input to a key derivation. |
| 3311 | * The output of this key derivation can be extracted by reading from the |
| 3312 | * resulting generator to produce keys and other cryptographic material. |
Gilles Peskine | 01d718c | 2018-09-18 12:01:02 +0200 | [diff] [blame] | 3313 | * |
Gilles Peskine | 969c5d6 | 2019-01-16 15:53:06 +0100 | [diff] [blame] | 3314 | * \param[in,out] generator The generator object to use. It must |
| 3315 | * have been set up with |
| 3316 | * psa_key_derivation_setup() with a |
Gilles Peskine | 6843c29 | 2019-01-18 16:44:49 +0100 | [diff] [blame] | 3317 | * key agreement and derivation algorithm |
| 3318 | * \c alg (\c PSA_ALG_XXX value such that |
Gilles Peskine | 3be6b7f | 2019-03-05 19:32:26 +0100 | [diff] [blame] | 3319 | * #PSA_ALG_IS_KEY_AGREEMENT(\c alg) is true |
| 3320 | * and #PSA_ALG_IS_RAW_KEY_AGREEMENT(\c alg) |
Gilles Peskine | 6843c29 | 2019-01-18 16:44:49 +0100 | [diff] [blame] | 3321 | * is false). |
Gilles Peskine | 969c5d6 | 2019-01-16 15:53:06 +0100 | [diff] [blame] | 3322 | * The generator must be ready for an |
| 3323 | * input of the type given by \p step. |
| 3324 | * \param step Which step the input data is for. |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 3325 | * \param private_key Handle to the private key to use. |
Jaeden Amero | 8afbff8 | 2019-01-14 16:56:20 +0000 | [diff] [blame] | 3326 | * \param[in] peer_key Public key of the peer. The peer key must be in the |
| 3327 | * same format that psa_import_key() accepts for the |
| 3328 | * public key type corresponding to the type of |
| 3329 | * private_key. That is, this function performs the |
| 3330 | * equivalent of |
Gilles Peskine | 47e79fb | 2019-02-08 11:24:59 +0100 | [diff] [blame] | 3331 | * #psa_import_key(`internal_public_key_handle`, |
| 3332 | * #PSA_KEY_TYPE_PUBLIC_KEY_OF_KEYPAIR(`private_key_type`), |
| 3333 | * `peer_key`, `peer_key_length`) where |
Jaeden Amero | 8afbff8 | 2019-01-14 16:56:20 +0000 | [diff] [blame] | 3334 | * `private_key_type` is the type of `private_key`. |
| 3335 | * For example, for EC keys, this means that peer_key |
| 3336 | * is interpreted as a point on the curve that the |
| 3337 | * private key is on. The standard formats for public |
| 3338 | * keys are documented in the documentation of |
| 3339 | * psa_export_public_key(). |
Gilles Peskine | 01d718c | 2018-09-18 12:01:02 +0200 | [diff] [blame] | 3340 | * \param peer_key_length Size of \p peer_key in bytes. |
Gilles Peskine | 01d718c | 2018-09-18 12:01:02 +0200 | [diff] [blame] | 3341 | * |
| 3342 | * \retval #PSA_SUCCESS |
| 3343 | * Success. |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 3344 | * \retval #PSA_ERROR_INVALID_HANDLE |
David Saada | b4ecc27 | 2019-02-14 13:48:10 +0200 | [diff] [blame] | 3345 | * \retval #PSA_ERROR_DOES_NOT_EXIST |
Gilles Peskine | 01d718c | 2018-09-18 12:01:02 +0200 | [diff] [blame] | 3346 | * \retval #PSA_ERROR_NOT_PERMITTED |
| 3347 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 3348 | * \c private_key is not compatible with \c alg, |
| 3349 | * or \p peer_key is not valid for \c alg or not compatible with |
| 3350 | * \c private_key. |
| 3351 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 3352 | * \c alg is not supported or is not a key derivation algorithm. |
| 3353 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 3354 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 3355 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 3356 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 3357 | */ |
| 3358 | psa_status_t psa_key_agreement(psa_crypto_generator_t *generator, |
Gilles Peskine | 969c5d6 | 2019-01-16 15:53:06 +0100 | [diff] [blame] | 3359 | psa_key_derivation_step_t step, |
Gilles Peskine | ae32aac | 2018-11-30 14:39:32 +0100 | [diff] [blame] | 3360 | psa_key_handle_t private_key, |
Gilles Peskine | 01d718c | 2018-09-18 12:01:02 +0200 | [diff] [blame] | 3361 | const uint8_t *peer_key, |
Gilles Peskine | 969c5d6 | 2019-01-16 15:53:06 +0100 | [diff] [blame] | 3362 | size_t peer_key_length); |
Gilles Peskine | 01d718c | 2018-09-18 12:01:02 +0200 | [diff] [blame] | 3363 | |
Gilles Peskine | 769c7a6 | 2019-01-18 16:42:29 +0100 | [diff] [blame] | 3364 | /** Perform a key agreement and use the shared secret as input to a key |
| 3365 | * derivation. |
| 3366 | * |
| 3367 | * A key agreement algorithm takes two inputs: a private key \p private_key |
| 3368 | * a public key \p peer_key. |
| 3369 | * |
| 3370 | * \warning The raw result of a key agreement algorithm such as finite-field |
| 3371 | * Diffie-Hellman or elliptic curve Diffie-Hellman has biases and should |
| 3372 | * not be used directly as key material. It should instead be passed as |
| 3373 | * input to a key derivation algorithm. To chain a key agreement with |
| 3374 | * a key derivation, use psa_key_agreement() and other functions from |
| 3375 | * the key derivation and generator interface. |
| 3376 | * |
Gilles Peskine | 47e79fb | 2019-02-08 11:24:59 +0100 | [diff] [blame] | 3377 | * \param alg The key agreement algorithm to compute |
| 3378 | * (\c PSA_ALG_XXX value such that |
| 3379 | * #PSA_ALG_IS_RAW_KEY_AGREEMENT(\p alg) |
| 3380 | * is true). |
Gilles Peskine | 769c7a6 | 2019-01-18 16:42:29 +0100 | [diff] [blame] | 3381 | * \param private_key Handle to the private key to use. |
| 3382 | * \param[in] peer_key Public key of the peer. It must be |
| 3383 | * in the same format that psa_import_key() |
| 3384 | * accepts. The standard formats for public |
| 3385 | * keys are documented in the documentation |
| 3386 | * of psa_export_public_key(). |
| 3387 | * \param peer_key_length Size of \p peer_key in bytes. |
| 3388 | * \param[out] output Buffer where the decrypted message is to |
| 3389 | * be written. |
| 3390 | * \param output_size Size of the \c output buffer in bytes. |
| 3391 | * \param[out] output_length On success, the number of bytes |
| 3392 | * that make up the returned output. |
| 3393 | * |
| 3394 | * \retval #PSA_SUCCESS |
| 3395 | * Success. |
| 3396 | * \retval #PSA_ERROR_INVALID_HANDLE |
| 3397 | * \retval #PSA_ERROR_EMPTY_SLOT |
| 3398 | * \retval #PSA_ERROR_NOT_PERMITTED |
| 3399 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 3400 | * \p alg is not a key agreement algorithm |
| 3401 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 3402 | * \p private_key is not compatible with \p alg, |
| 3403 | * or \p peer_key is not valid for \p alg or not compatible with |
| 3404 | * \p private_key. |
| 3405 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 3406 | * \p alg is not a supported key agreement algorithm. |
| 3407 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 3408 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 3409 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 3410 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 3411 | */ |
| 3412 | psa_status_t psa_key_agreement_raw_shared_secret(psa_algorithm_t alg, |
| 3413 | psa_key_handle_t private_key, |
| 3414 | const uint8_t *peer_key, |
| 3415 | size_t peer_key_length, |
| 3416 | uint8_t *output, |
| 3417 | size_t output_size, |
| 3418 | size_t *output_length); |
Gilles Peskine | 4c317f4 | 2018-07-12 01:24:09 +0200 | [diff] [blame] | 3419 | |
| 3420 | /**@}*/ |
Gilles Peskine | 9e7dc71 | 2018-03-28 14:18:50 +0200 | [diff] [blame] | 3421 | |
| 3422 | /** \defgroup random Random generation |
| 3423 | * @{ |
Gilles Peskine | 4e69d7a | 2018-06-19 20:19:14 +0200 | [diff] [blame] | 3424 | */ |
| 3425 | |
| 3426 | /** |
| 3427 | * \brief Generate random bytes. |
| 3428 | * |
Gilles Peskine | 53d991e | 2018-07-12 01:14:59 +0200 | [diff] [blame] | 3429 | * \warning This function **can** fail! Callers MUST check the return status |
Gilles Peskine | 4e69d7a | 2018-06-19 20:19:14 +0200 | [diff] [blame] | 3430 | * and MUST NOT use the content of the output buffer if the return |
Gilles Peskine | fa4070c | 2018-07-12 19:23:03 +0200 | [diff] [blame] | 3431 | * status is not #PSA_SUCCESS. |
Gilles Peskine | 3fa675c | 2018-07-12 01:31:03 +0200 | [diff] [blame] | 3432 | * |
Adrian L. Shaw | 5a5a79a | 2019-05-03 15:44:28 +0100 | [diff] [blame] | 3433 | * \note To generate a key, use psa_generate_random_key() instead. |
Gilles Peskine | 9e7dc71 | 2018-03-28 14:18:50 +0200 | [diff] [blame] | 3434 | * |
| 3435 | * \param[out] output Output buffer for the generated data. |
| 3436 | * \param output_size Number of bytes to generate and output. |
| 3437 | * |
| 3438 | * \retval #PSA_SUCCESS |
| 3439 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 3440 | * \retval #PSA_ERROR_INSUFFICIENT_ENTROPY |
| 3441 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 3442 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 3443 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 3444 | * \retval #PSA_ERROR_BAD_STATE |
| 3445 | * The library has not been previously initialized by psa_crypto_init(). |
| 3446 | * It is implementation-dependent whether a failure to initialize |
| 3447 | * results in this error code. |
Gilles Peskine | 4e69d7a | 2018-06-19 20:19:14 +0200 | [diff] [blame] | 3448 | */ |
| 3449 | psa_status_t psa_generate_random(uint8_t *output, |
| 3450 | size_t output_size); |
| 3451 | |
Gilles Peskine | 4e69d7a | 2018-06-19 20:19:14 +0200 | [diff] [blame] | 3452 | /** |
| 3453 | * \brief Generate a key or key pair. |
| 3454 | * |
Gilles Peskine | e56e878 | 2019-04-26 17:34:02 +0200 | [diff] [blame] | 3455 | * The key is generated randomly. |
| 3456 | * Its location, policy, type and size are taken from \p attributes. |
| 3457 | * |
| 3458 | * If the type requires additional domain parameters, these are taken |
| 3459 | * from \p attributes as well. The following types use domain parameters: |
| 3460 | * - When generating an RSA key (#PSA_KEY_TYPE_RSA_KEYPAIR), |
| 3461 | * the default public exponent is 65537. This value is used if |
| 3462 | * \p attributes was set with psa_set_key_type() or by passing an empty |
| 3463 | * byte string as domain parameters to psa_set_key_domain_parameters(). |
| 3464 | * If psa_set_key_domain_parameters() was used to set a non-empty |
| 3465 | * domain parameter string in \p attributes, this string is read as |
| 3466 | * a big-endian integer which is used as the public exponent. |
| 3467 | * - When generating a DSA key (#PSA_KEY_TYPE_DSA_KEYPAIR) or a |
| 3468 | * Diffie-Hellman key (#PSA_KEY_TYPE_DH_KEYPAIR), the domain parameters |
| 3469 | * from \p attributes are interpreted as described for |
| 3470 | * psa_set_key_domain_parameters(). |
| 3471 | * |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 3472 | * \param[in] attributes The attributes for the new key. |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 3473 | * \param[out] handle On success, a handle to the newly created key. |
| 3474 | * \c 0 on failure. |
Gilles Peskine | 9e7dc71 | 2018-03-28 14:18:50 +0200 | [diff] [blame] | 3475 | * |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 3476 | * \retval #PSA_SUCCESS |
Gilles Peskine | 23fd2bd | 2018-12-11 15:51:32 +0100 | [diff] [blame] | 3477 | * Success. |
| 3478 | * If the key is persistent, the key material and the key's metadata |
| 3479 | * have been saved to persistent storage. |
David Saada | b4ecc27 | 2019-02-14 13:48:10 +0200 | [diff] [blame] | 3480 | * \retval #PSA_ERROR_ALREADY_EXISTS |
Gilles Peskine | 2062859 | 2019-04-19 19:29:50 +0200 | [diff] [blame] | 3481 | * This is an attempt to create a persistent key, and there is |
| 3482 | * already a persistent key with the given identifier. |
Gilles Peskine | 2853849 | 2018-07-11 17:34:00 +0200 | [diff] [blame] | 3483 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 3484 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 3485 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 3486 | * \retval #PSA_ERROR_INSUFFICIENT_ENTROPY |
| 3487 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 3488 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 3489 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
itayzafrir | 90d8c7a | 2018-09-12 11:44:52 +0300 | [diff] [blame] | 3490 | * \retval #PSA_ERROR_BAD_STATE |
itayzafrir | 1861709 | 2018-09-16 12:22:41 +0300 | [diff] [blame] | 3491 | * The library has not been previously initialized by psa_crypto_init(). |
| 3492 | * It is implementation-dependent whether a failure to initialize |
| 3493 | * results in this error code. |
Gilles Peskine | 9e7dc71 | 2018-03-28 14:18:50 +0200 | [diff] [blame] | 3494 | */ |
Adrian L. Shaw | 5a5a79a | 2019-05-03 15:44:28 +0100 | [diff] [blame] | 3495 | psa_status_t psa_generate_random_key(const psa_key_attributes_t *attributes, |
Gilles Peskine | e56e878 | 2019-04-26 17:34:02 +0200 | [diff] [blame] | 3496 | psa_key_handle_t *handle); |
Gilles Peskine | 9e7dc71 | 2018-03-28 14:18:50 +0200 | [diff] [blame] | 3497 | |
| 3498 | /**@}*/ |
| 3499 | |
Gilles Peskine | e59236f | 2018-01-27 23:32:46 +0100 | [diff] [blame] | 3500 | #ifdef __cplusplus |
| 3501 | } |
| 3502 | #endif |
| 3503 | |
Gilles Peskine | 0cad07c | 2018-06-27 19:49:02 +0200 | [diff] [blame] | 3504 | /* The file "crypto_sizes.h" contains definitions for size calculation |
| 3505 | * macros whose definitions are implementation-specific. */ |
| 3506 | #include "crypto_sizes.h" |
| 3507 | |
Gilles Peskine | 9ef733f | 2018-02-07 21:05:37 +0100 | [diff] [blame] | 3508 | /* The file "crypto_struct.h" contains definitions for |
| 3509 | * implementation-specific structs that are declared above. */ |
| 3510 | #include "crypto_struct.h" |
| 3511 | |
| 3512 | /* The file "crypto_extra.h" contains vendor-specific definitions. This |
| 3513 | * can include vendor-defined algorithms, extra functions, etc. */ |
Gilles Peskine | e59236f | 2018-01-27 23:32:46 +0100 | [diff] [blame] | 3514 | #include "crypto_extra.h" |
| 3515 | |
| 3516 | #endif /* PSA_CRYPTO_H */ |