Gilles Peskine | e59236f | 2018-01-27 23:32:46 +0100 | [diff] [blame] | 1 | /** |
| 2 | * \file psa/crypto_extra.h |
| 3 | * |
| 4 | * \brief PSA cryptography module: Mbed TLS vendor extensions |
Gilles Peskine | 07c91f5 | 2018-06-28 18:02:53 +0200 | [diff] [blame] | 5 | * |
| 6 | * \note This file may not be included directly. Applications must |
| 7 | * include psa/crypto.h. |
| 8 | * |
| 9 | * This file is reserved for vendor-specific definitions. |
Gilles Peskine | e59236f | 2018-01-27 23:32:46 +0100 | [diff] [blame] | 10 | */ |
| 11 | /* |
| 12 | * Copyright (C) 2018, ARM Limited, All Rights Reserved |
| 13 | * SPDX-License-Identifier: Apache-2.0 |
| 14 | * |
| 15 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 16 | * not use this file except in compliance with the License. |
| 17 | * You may obtain a copy of the License at |
| 18 | * |
| 19 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 20 | * |
| 21 | * Unless required by applicable law or agreed to in writing, software |
| 22 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 23 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 24 | * See the License for the specific language governing permissions and |
| 25 | * limitations under the License. |
| 26 | * |
| 27 | * This file is part of mbed TLS (https://tls.mbed.org) |
| 28 | */ |
| 29 | |
| 30 | #ifndef PSA_CRYPTO_EXTRA_H |
| 31 | #define PSA_CRYPTO_EXTRA_H |
| 32 | |
Jaeden Amero | 81cefed | 2019-02-25 08:51:27 +0000 | [diff] [blame] | 33 | #include "mbedtls/platform_util.h" |
| 34 | |
Gilles Peskine | e59236f | 2018-01-27 23:32:46 +0100 | [diff] [blame] | 35 | #ifdef __cplusplus |
| 36 | extern "C" { |
| 37 | #endif |
| 38 | |
Netanel Gonen | 2bcd312 | 2018-11-19 11:53:02 +0200 | [diff] [blame] | 39 | /* UID for secure storage seed */ |
avolinski | 0d2c266 | 2018-11-21 17:31:07 +0200 | [diff] [blame] | 40 | #define PSA_CRYPTO_ITS_RANDOM_SEED_UID 0xFFFFFF52 |
Netanel Gonen | 2bcd312 | 2018-11-19 11:53:02 +0200 | [diff] [blame] | 41 | |
Jaeden Amero | 5e6d24c | 2019-02-21 10:41:29 +0000 | [diff] [blame] | 42 | /* |
| 43 | * Deprecated PSA Crypto error code definitions |
| 44 | */ |
| 45 | #if !defined(MBEDTLS_DEPRECATED_REMOVED) |
| 46 | #define PSA_ERROR_UNKNOWN_ERROR \ |
| 47 | MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( PSA_ERROR_GENERIC_ERROR ) |
| 48 | #endif |
| 49 | |
| 50 | #if !defined(MBEDTLS_DEPRECATED_REMOVED) |
| 51 | #define PSA_ERROR_OCCUPIED_SLOT \ |
| 52 | MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( PSA_ERROR_ALREADY_EXISTS ) |
| 53 | #endif |
| 54 | |
| 55 | #if !defined(MBEDTLS_DEPRECATED_REMOVED) |
| 56 | #define PSA_ERROR_EMPTY_SLOT \ |
| 57 | MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( PSA_ERROR_DOES_NOT_EXIST ) |
| 58 | #endif |
| 59 | |
| 60 | #if !defined(MBEDTLS_DEPRECATED_REMOVED) |
| 61 | #define PSA_ERROR_INSUFFICIENT_CAPACITY \ |
| 62 | MBEDTLS_DEPRECATED_NUMERIC_CONSTANT( PSA_ERROR_INSUFFICIENT_DATA ) |
| 63 | #endif |
| 64 | |
Gilles Peskine | e59236f | 2018-01-27 23:32:46 +0100 | [diff] [blame] | 65 | /** |
| 66 | * \brief Library deinitialization. |
| 67 | * |
| 68 | * This function clears all data associated with the PSA layer, |
| 69 | * including the whole key store. |
| 70 | * |
| 71 | * This is an Mbed TLS extension. |
| 72 | */ |
| 73 | void mbedtls_psa_crypto_free( void ); |
| 74 | |
Netanel Gonen | 2bcd312 | 2018-11-19 11:53:02 +0200 | [diff] [blame] | 75 | |
Netanel Gonen | 2bcd312 | 2018-11-19 11:53:02 +0200 | [diff] [blame] | 76 | /** |
Gilles Peskine | ee2ffd3 | 2018-11-16 11:02:49 +0100 | [diff] [blame] | 77 | * \brief Inject an initial entropy seed for the random generator into |
| 78 | * secure storage. |
Gilles Peskine | 0338ded | 2018-11-15 18:19:27 +0100 | [diff] [blame] | 79 | * |
| 80 | * This function injects data to be used as a seed for the random generator |
| 81 | * used by the PSA Crypto implementation. On devices that lack a trusted |
| 82 | * entropy source (preferably a hardware random number generator), |
| 83 | * the Mbed PSA Crypto implementation uses this value to seed its |
| 84 | * random generator. |
| 85 | * |
| 86 | * On devices without a trusted entropy source, this function must be |
| 87 | * called exactly once in the lifetime of the device. On devices with |
| 88 | * a trusted entropy source, calling this function is optional. |
| 89 | * In all cases, this function may only be called before calling any |
| 90 | * other function in the PSA Crypto API, including psa_crypto_init(). |
| 91 | * |
| 92 | * When this function returns successfully, it populates a file in |
| 93 | * persistent storage. Once the file has been created, this function |
| 94 | * can no longer succeed. |
Gilles Peskine | ee2ffd3 | 2018-11-16 11:02:49 +0100 | [diff] [blame] | 95 | * |
| 96 | * If any error occurs, this function does not change the system state. |
| 97 | * You can call this function again after correcting the reason for the |
| 98 | * error if possible. |
Netanel Gonen | 2bcd312 | 2018-11-19 11:53:02 +0200 | [diff] [blame] | 99 | * |
| 100 | * \warning This function **can** fail! Callers MUST check the return status. |
| 101 | * |
Gilles Peskine | 0338ded | 2018-11-15 18:19:27 +0100 | [diff] [blame] | 102 | * \warning If you use this function, you should use it as part of a |
| 103 | * factory provisioning process. The value of the injected seed |
| 104 | * is critical to the security of the device. It must be |
| 105 | * *secret*, *unpredictable* and (statistically) *unique per device*. |
| 106 | * You should be generate it randomly using a cryptographically |
| 107 | * secure random generator seeded from trusted entropy sources. |
| 108 | * You should transmit it securely to the device and ensure |
| 109 | * that its value is not leaked or stored anywhere beyond the |
| 110 | * needs of transmitting it from the point of generation to |
| 111 | * the call of this function, and erase all copies of the value |
| 112 | * once this function returns. |
Netanel Gonen | 2bcd312 | 2018-11-19 11:53:02 +0200 | [diff] [blame] | 113 | * |
Gilles Peskine | 0338ded | 2018-11-15 18:19:27 +0100 | [diff] [blame] | 114 | * This is an Mbed TLS extension. |
| 115 | * |
Netanel Gonen | 1d7195f | 2018-11-22 16:24:48 +0200 | [diff] [blame] | 116 | * \note This function is only available on the following platforms: |
Gilles Peskine | e3dbdd8 | 2019-02-25 11:04:06 +0100 | [diff] [blame] | 117 | * * If the compile-time option MBEDTLS_PSA_INJECT_ENTROPY is enabled. |
| 118 | * Note that you must provide compatible implementations of |
| 119 | * mbedtls_nv_seed_read and mbedtls_nv_seed_write. |
Gilles Peskine | 0cfaed1 | 2018-11-22 17:11:45 +0200 | [diff] [blame] | 120 | * * In a client-server integration of PSA Cryptography, on the client side, |
Netanel Gonen | 1d7195f | 2018-11-22 16:24:48 +0200 | [diff] [blame] | 121 | * if the server supports this feature. |
Netanel Gonen | 596e65e | 2018-11-22 18:41:43 +0200 | [diff] [blame] | 122 | * \param[in] seed Buffer containing the seed value to inject. |
Gilles Peskine | 0cfaed1 | 2018-11-22 17:11:45 +0200 | [diff] [blame] | 123 | * \param[in] seed_size Size of the \p seed buffer. |
Netanel Gonen | 596e65e | 2018-11-22 18:41:43 +0200 | [diff] [blame] | 124 | * The size of the seed in bytes must be greater |
| 125 | * or equal to both #MBEDTLS_ENTROPY_MIN_PLATFORM |
| 126 | * and #MBEDTLS_ENTROPY_BLOCK_SIZE. |
| 127 | * It must be less or equal to |
| 128 | * #MBEDTLS_ENTROPY_MAX_SEED_SIZE. |
Netanel Gonen | 2bcd312 | 2018-11-19 11:53:02 +0200 | [diff] [blame] | 129 | * |
| 130 | * \retval #PSA_SUCCESS |
Gilles Peskine | 0338ded | 2018-11-15 18:19:27 +0100 | [diff] [blame] | 131 | * The seed value was injected successfully. The random generator |
| 132 | * of the PSA Crypto implementation is now ready for use. |
| 133 | * You may now call psa_crypto_init() and use the PSA Crypto |
| 134 | * implementation. |
Netanel Gonen | 2bcd312 | 2018-11-19 11:53:02 +0200 | [diff] [blame] | 135 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
Gilles Peskine | ee2ffd3 | 2018-11-16 11:02:49 +0100 | [diff] [blame] | 136 | * \p seed_size is out of range. |
Netanel Gonen | 2bcd312 | 2018-11-19 11:53:02 +0200 | [diff] [blame] | 137 | * \retval #PSA_ERROR_STORAGE_FAILURE |
Gilles Peskine | 0338ded | 2018-11-15 18:19:27 +0100 | [diff] [blame] | 138 | * There was a failure reading or writing from storage. |
Netanel Gonen | 2bcd312 | 2018-11-19 11:53:02 +0200 | [diff] [blame] | 139 | * \retval #PSA_ERROR_NOT_PERMITTED |
Gilles Peskine | 0338ded | 2018-11-15 18:19:27 +0100 | [diff] [blame] | 140 | * The library has already been initialized. It is no longer |
| 141 | * possible to call this function. |
Netanel Gonen | 2bcd312 | 2018-11-19 11:53:02 +0200 | [diff] [blame] | 142 | */ |
| 143 | psa_status_t mbedtls_psa_inject_entropy(const unsigned char *seed, |
| 144 | size_t seed_size); |
| 145 | |
Gilles Peskine | 5dcd3ce | 2019-01-18 16:41:31 +0100 | [diff] [blame] | 146 | /** Set up a key derivation operation. |
| 147 | * |
| 148 | * FIMXE This function is no longer part of the official API. Its prototype |
| 149 | * is only kept around for the sake of tests that haven't been updated yet. |
| 150 | * |
Gilles Peskine | 3be6b7f | 2019-03-05 19:32:26 +0100 | [diff] [blame] | 151 | * A key derivation algorithm takes three inputs: a secret input \p handle and |
Gilles Peskine | 5dcd3ce | 2019-01-18 16:41:31 +0100 | [diff] [blame] | 152 | * two non-secret inputs \p label and p salt. |
| 153 | * The result of this function is a byte generator which can |
| 154 | * be used to produce keys and other cryptographic material. |
| 155 | * |
| 156 | * The role of \p label and \p salt is as follows: |
| 157 | * - For HKDF (#PSA_ALG_HKDF), \p salt is the salt used in the "extract" step |
| 158 | * and \p label is the info string used in the "expand" step. |
| 159 | * |
| 160 | * \param[in,out] generator The generator object to set up. It must have |
| 161 | * been initialized as per the documentation for |
| 162 | * #psa_crypto_generator_t and not yet in use. |
| 163 | * \param handle Handle to the secret key. |
| 164 | * \param alg The key derivation algorithm to compute |
| 165 | * (\c PSA_ALG_XXX value such that |
| 166 | * #PSA_ALG_IS_KEY_DERIVATION(\p alg) is true). |
| 167 | * \param[in] salt Salt to use. |
| 168 | * \param salt_length Size of the \p salt buffer in bytes. |
| 169 | * \param[in] label Label to use. |
| 170 | * \param label_length Size of the \p label buffer in bytes. |
| 171 | * \param capacity The maximum number of bytes that the |
| 172 | * generator will be able to provide. |
| 173 | * |
| 174 | * \retval #PSA_SUCCESS |
| 175 | * Success. |
| 176 | * \retval #PSA_ERROR_INVALID_HANDLE |
| 177 | * \retval #PSA_ERROR_EMPTY_SLOT |
| 178 | * \retval #PSA_ERROR_NOT_PERMITTED |
| 179 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 180 | * \c key is not compatible with \c alg, |
| 181 | * or \p capacity is too large for the specified algorithm and key. |
| 182 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 183 | * \c alg is not supported or is not a key derivation algorithm. |
| 184 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 185 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 186 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 187 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 188 | * \retval #PSA_ERROR_BAD_STATE |
| 189 | * The library has not been previously initialized by psa_crypto_init(). |
| 190 | * It is implementation-dependent whether a failure to initialize |
| 191 | * results in this error code. |
| 192 | */ |
| 193 | psa_status_t psa_key_derivation(psa_crypto_generator_t *generator, |
| 194 | psa_key_handle_t handle, |
| 195 | psa_algorithm_t alg, |
| 196 | const uint8_t *salt, |
| 197 | size_t salt_length, |
| 198 | const uint8_t *label, |
| 199 | size_t label_length, |
| 200 | size_t capacity); |
| 201 | |
Gilles Peskine | 6843c29 | 2019-01-18 16:44:49 +0100 | [diff] [blame] | 202 | /* FIXME Deprecated. Remove this as soon as all the tests are updated. */ |
| 203 | #define PSA_ALG_SELECT_RAW ((psa_algorithm_t)0x31000001) |
Netanel Gonen | 2bcd312 | 2018-11-19 11:53:02 +0200 | [diff] [blame] | 204 | |
Gilles Peskine | a3dd737 | 2019-04-19 19:42:26 +0200 | [diff] [blame] | 205 | /** \defgroup policy Key policies |
| 206 | * @{ |
| 207 | * |
| 208 | * The functions in this section are legacy interfaces where the properties |
| 209 | * of a key object are set after allocating a handle, in constrast with the |
| 210 | * preferred interface where key objects are created atomically from |
| 211 | * a structure that represents the properties. |
| 212 | */ |
| 213 | |
| 214 | /** \def PSA_KEY_POLICY_INIT |
| 215 | * |
| 216 | * This macro returns a suitable initializer for a key policy object of type |
| 217 | * #psa_key_policy_t. |
| 218 | */ |
| 219 | #ifdef __DOXYGEN_ONLY__ |
| 220 | /* This is an example definition for documentation purposes. |
| 221 | * Implementations should define a suitable value in `crypto_struct.h`. |
| 222 | */ |
| 223 | #define PSA_KEY_POLICY_INIT {0} |
| 224 | #endif |
| 225 | |
| 226 | /** Return an initial value for a key policy that forbids all usage of the key. |
| 227 | */ |
| 228 | static psa_key_policy_t psa_key_policy_init(void); |
| 229 | |
| 230 | /** \brief Set the standard fields of a policy structure. |
| 231 | * |
| 232 | * Note that this function does not make any consistency check of the |
| 233 | * parameters. The values are only checked when applying the policy to |
| 234 | * a key slot with psa_set_key_policy(). |
| 235 | * |
| 236 | * \param[in,out] policy The key policy to modify. It must have been |
| 237 | * initialized as per the documentation for |
| 238 | * #psa_key_policy_t. |
| 239 | * \param usage The permitted uses for the key. |
| 240 | * \param alg The algorithm that the key may be used for. |
| 241 | */ |
| 242 | void psa_key_policy_set_usage(psa_key_policy_t *policy, |
| 243 | psa_key_usage_t usage, |
| 244 | psa_algorithm_t alg); |
| 245 | |
| 246 | /** \brief Retrieve the usage field of a policy structure. |
| 247 | * |
| 248 | * \param[in] policy The policy object to query. |
| 249 | * |
| 250 | * \return The permitted uses for a key with this policy. |
| 251 | */ |
| 252 | psa_key_usage_t psa_key_policy_get_usage(const psa_key_policy_t *policy); |
| 253 | |
| 254 | /** \brief Retrieve the algorithm field of a policy structure. |
| 255 | * |
| 256 | * \param[in] policy The policy object to query. |
| 257 | * |
| 258 | * \return The permitted algorithm for a key with this policy. |
| 259 | */ |
| 260 | psa_algorithm_t psa_key_policy_get_algorithm(const psa_key_policy_t *policy); |
| 261 | |
| 262 | /** \brief Set the usage policy on a key slot. |
| 263 | * |
| 264 | * This function must be called on an empty key slot, before importing, |
| 265 | * generating or creating a key in the slot. Changing the policy of an |
| 266 | * existing key is not permitted. |
| 267 | * |
| 268 | * Implementations may set restrictions on supported key policies |
| 269 | * depending on the key type and the key slot. |
| 270 | * |
| 271 | * \param handle Handle to the key whose policy is to be changed. |
| 272 | * \param[in] policy The policy object to query. |
| 273 | * |
| 274 | * \retval #PSA_SUCCESS |
| 275 | * Success. |
| 276 | * If the key is persistent, it is implementation-defined whether |
| 277 | * the policy has been saved to persistent storage. Implementations |
| 278 | * may defer saving the policy until the key material is created. |
| 279 | * \retval #PSA_ERROR_INVALID_HANDLE |
| 280 | * \retval #PSA_ERROR_ALREADY_EXISTS |
| 281 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 282 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 283 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 284 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 285 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 286 | * \retval #PSA_ERROR_BAD_STATE |
| 287 | * The library has not been previously initialized by psa_crypto_init(). |
| 288 | * It is implementation-dependent whether a failure to initialize |
| 289 | * results in this error code. |
| 290 | */ |
| 291 | psa_status_t psa_set_key_policy(psa_key_handle_t handle, |
| 292 | const psa_key_policy_t *policy); |
| 293 | |
| 294 | /** \brief Get the usage policy for a key slot. |
| 295 | * |
| 296 | * \param handle Handle to the key slot whose policy is being queried. |
| 297 | * \param[out] policy On success, the key's policy. |
| 298 | * |
| 299 | * \retval #PSA_SUCCESS |
| 300 | * \retval #PSA_ERROR_INVALID_HANDLE |
| 301 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 302 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 303 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 304 | * \retval #PSA_ERROR_BAD_STATE |
| 305 | * The library has not been previously initialized by psa_crypto_init(). |
| 306 | * It is implementation-dependent whether a failure to initialize |
| 307 | * results in this error code. |
| 308 | */ |
| 309 | psa_status_t psa_get_key_policy(psa_key_handle_t handle, |
| 310 | psa_key_policy_t *policy); |
| 311 | |
| 312 | /**@}*/ |
| 313 | |
Gilles Peskine | 87a5e56 | 2019-04-17 12:28:25 +0200 | [diff] [blame] | 314 | /** \defgroup to_handle Key creation to allocated handle |
| 315 | * @{ |
| 316 | * |
| 317 | * The functions in this section are legacy interfaces where the properties |
| 318 | * of a key object are set after allocating a handle, in constrast with the |
| 319 | * preferred interface where key objects are created atomically from |
| 320 | * a structure that represents the properties. |
| 321 | */ |
| 322 | |
| 323 | /** Create a new persistent key slot. |
| 324 | * |
| 325 | * Create a new persistent key slot and return a handle to it. The handle |
| 326 | * remains valid until the application calls psa_close_key() or terminates. |
| 327 | * The application can open the key again with psa_open_key() until it |
| 328 | * removes the key by calling psa_destroy_key(). |
| 329 | * |
| 330 | * \param lifetime The lifetime of the key. This designates a storage |
| 331 | * area where the key material is stored. This must not |
| 332 | * be #PSA_KEY_LIFETIME_VOLATILE. |
| 333 | * \param id The persistent identifier of the key. |
| 334 | * \param[out] handle On success, a handle to the newly created key slot. |
| 335 | * When key material is later created in this key slot, |
| 336 | * it will be saved to the specified persistent location. |
| 337 | * |
| 338 | * \retval #PSA_SUCCESS |
| 339 | * Success. The application can now use the value of `*handle` |
| 340 | * to access the newly allocated key slot. |
| 341 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 342 | * \retval #PSA_ERROR_INSUFFICIENT_STORAGE |
| 343 | * \retval #PSA_ERROR_ALREADY_EXISTS |
| 344 | * There is already a key with the identifier \p id in the storage |
| 345 | * area designated by \p lifetime. |
| 346 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 347 | * \p lifetime is invalid, for example #PSA_KEY_LIFETIME_VOLATILE. |
| 348 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
| 349 | * \p id is invalid for the specified lifetime. |
| 350 | * \retval #PSA_ERROR_NOT_SUPPORTED |
| 351 | * \p lifetime is not supported. |
| 352 | * \retval #PSA_ERROR_NOT_PERMITTED |
| 353 | * \p lifetime is valid, but the application does not have the |
| 354 | * permission to create a key there. |
| 355 | */ |
| 356 | psa_status_t psa_create_key(psa_key_lifetime_t lifetime, |
| 357 | psa_key_id_t id, |
| 358 | psa_key_handle_t *handle); |
| 359 | |
Gilles Peskine | a3dd737 | 2019-04-19 19:42:26 +0200 | [diff] [blame] | 360 | /** Allocate a key slot for a transient key, i.e. a key which is only stored |
| 361 | * in volatile memory. |
| 362 | * |
| 363 | * The allocated key slot and its handle remain valid until the |
| 364 | * application calls psa_close_key() or psa_destroy_key() or until the |
| 365 | * application terminates. |
| 366 | * |
| 367 | * \param[out] handle On success, a handle to a volatile key slot. |
| 368 | * |
| 369 | * \retval #PSA_SUCCESS |
| 370 | * Success. The application can now use the value of `*handle` |
| 371 | * to access the newly allocated key slot. |
| 372 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 373 | * There was not enough memory, or the maximum number of key slots |
| 374 | * has been reached. |
| 375 | */ |
| 376 | psa_status_t psa_allocate_key(psa_key_handle_t *handle); |
| 377 | |
| 378 | /** |
| 379 | * \brief Get basic metadata about a key. |
| 380 | * |
| 381 | * \param handle Handle to the key slot to query. |
| 382 | * \param[out] type On success, the key type (a \c PSA_KEY_TYPE_XXX value). |
| 383 | * This may be a null pointer, in which case the key type |
| 384 | * is not written. |
| 385 | * \param[out] bits On success, the key size in bits. |
| 386 | * This may be a null pointer, in which case the key size |
| 387 | * is not written. |
| 388 | * |
| 389 | * \retval #PSA_SUCCESS |
| 390 | * \retval #PSA_ERROR_INVALID_HANDLE |
| 391 | * \retval #PSA_ERROR_DOES_NOT_EXIST |
| 392 | * The handle is to a key slot which does not contain key material yet. |
| 393 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 394 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 395 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 396 | * \retval #PSA_ERROR_BAD_STATE |
| 397 | * The library has not been previously initialized by psa_crypto_init(). |
| 398 | * It is implementation-dependent whether a failure to initialize |
| 399 | * results in this error code. |
| 400 | */ |
| 401 | psa_status_t psa_get_key_information(psa_key_handle_t handle, |
| 402 | psa_key_type_t *type, |
| 403 | size_t *bits); |
| 404 | |
Gilles Peskine | 87a5e56 | 2019-04-17 12:28:25 +0200 | [diff] [blame] | 405 | /** \brief Retrieve the lifetime of an open key. |
| 406 | * |
| 407 | * \param handle Handle to query. |
| 408 | * \param[out] lifetime On success, the lifetime value. |
| 409 | * |
| 410 | * \retval #PSA_SUCCESS |
| 411 | * Success. |
| 412 | * \retval #PSA_ERROR_INVALID_HANDLE |
| 413 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE |
| 414 | * \retval #PSA_ERROR_HARDWARE_FAILURE |
| 415 | * \retval #PSA_ERROR_TAMPERING_DETECTED |
| 416 | * \retval #PSA_ERROR_BAD_STATE |
| 417 | * The library has not been previously initialized by psa_crypto_init(). |
| 418 | * It is implementation-dependent whether a failure to initialize |
| 419 | * results in this error code. |
| 420 | */ |
| 421 | psa_status_t psa_get_key_lifetime_from_handle(psa_key_handle_t handle, |
| 422 | psa_key_lifetime_t *lifetime); |
| 423 | |
| 424 | psa_status_t psa_import_key_to_handle(psa_key_handle_t handle, |
| 425 | psa_key_type_t type, |
| 426 | const uint8_t *data, |
| 427 | size_t data_length); |
| 428 | |
| 429 | psa_status_t psa_copy_key_to_handle(psa_key_handle_t source_handle, |
| 430 | psa_key_handle_t target_handle, |
| 431 | const psa_key_policy_t *constraint); |
| 432 | |
Adrian L. Shaw | 5a5a79a | 2019-05-03 15:44:28 +0100 | [diff] [blame^] | 433 | psa_status_t psa_generate_derived_key_to_handle(psa_key_handle_t handle, |
Gilles Peskine | 87a5e56 | 2019-04-17 12:28:25 +0200 | [diff] [blame] | 434 | psa_key_type_t type, |
| 435 | size_t bits, |
| 436 | psa_crypto_generator_t *generator); |
| 437 | |
Adrian L. Shaw | 5a5a79a | 2019-05-03 15:44:28 +0100 | [diff] [blame^] | 438 | psa_status_t psa_generate_random_key_to_handle(psa_key_handle_t handle, |
Gilles Peskine | 87a5e56 | 2019-04-17 12:28:25 +0200 | [diff] [blame] | 439 | psa_key_type_t type, |
| 440 | size_t bits, |
| 441 | const void *extra, |
| 442 | size_t extra_size); |
| 443 | |
| 444 | /**@}*/ |
| 445 | |
Gilles Peskine | e59236f | 2018-01-27 23:32:46 +0100 | [diff] [blame] | 446 | #ifdef __cplusplus |
| 447 | } |
| 448 | #endif |
| 449 | |
| 450 | #endif /* PSA_CRYPTO_EXTRA_H */ |