Path: blob/master/thirdparty/mbedtls/include/psa/crypto_compat.h
9904 views
/**1* \file psa/crypto_compat.h2*3* \brief PSA cryptography module: Backward compatibility aliases4*5* This header declares alternative names for macro and functions.6* New application code should not use these names.7* These names may be removed in a future version of Mbed TLS.8*9* \note This file may not be included directly. Applications must10* include psa/crypto.h.11*/12/*13* Copyright The Mbed TLS Contributors14* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later15*/1617#ifndef PSA_CRYPTO_COMPAT_H18#define PSA_CRYPTO_COMPAT_H1920#ifdef __cplusplus21extern "C" {22#endif2324/*25* To support both openless APIs and psa_open_key() temporarily, define26* psa_key_handle_t to be equal to mbedtls_svc_key_id_t. Do not mark the27* type and its utility macros and functions deprecated yet. This will be done28* in a subsequent phase.29*/30typedef mbedtls_svc_key_id_t psa_key_handle_t;3132#define PSA_KEY_HANDLE_INIT MBEDTLS_SVC_KEY_ID_INIT3334/** Check whether a handle is null.35*36* \param handle Handle37*38* \return Non-zero if the handle is null, zero otherwise.39*/40static inline int psa_key_handle_is_null(psa_key_handle_t handle)41{42return mbedtls_svc_key_id_is_null(handle);43}4445/** Open a handle to an existing persistent key.46*47* Open a handle to a persistent key. A key is persistent if it was created48* with a lifetime other than #PSA_KEY_LIFETIME_VOLATILE. A persistent key49* always has a nonzero key identifier, set with psa_set_key_id() when50* creating the key. Implementations may provide additional pre-provisioned51* keys that can be opened with psa_open_key(). Such keys have an application52* key identifier in the vendor range, as documented in the description of53* #psa_key_id_t.54*55* The application must eventually close the handle with psa_close_key() or56* psa_destroy_key() to release associated resources. If the application dies57* without calling one of these functions, the implementation should perform58* the equivalent of a call to psa_close_key().59*60* Some implementations permit an application to open the same key multiple61* times. If this is successful, each call to psa_open_key() will return a62* different key handle.63*64* \note This API is not part of the PSA Cryptography API Release 1.0.065* specification. It was defined in the 1.0 Beta 3 version of the66* specification but was removed in the 1.0.0 released version. This API is67* kept for the time being to not break applications relying on it. It is not68* deprecated yet but will be in the near future.69*70* \note Applications that rely on opening a key multiple times will not be71* portable to implementations that only permit a single key handle to be72* opened. See also :ref:\`key-handles\`.73*74*75* \param key The persistent identifier of the key.76* \param[out] handle On success, a handle to the key.77*78* \retval #PSA_SUCCESS79* Success. The application can now use the value of `*handle`80* to access the key.81* \retval #PSA_ERROR_INSUFFICIENT_MEMORY82* The implementation does not have sufficient resources to open the83* key. This can be due to reaching an implementation limit on the84* number of open keys, the number of open key handles, or available85* memory.86* \retval #PSA_ERROR_DOES_NOT_EXIST87* There is no persistent key with key identifier \p key.88* \retval #PSA_ERROR_INVALID_ARGUMENT89* \p key is not a valid persistent key identifier.90* \retval #PSA_ERROR_NOT_PERMITTED91* The specified key exists, but the application does not have the92* permission to access it. Note that this specification does not93* define any way to create such a key, but it may be possible94* through implementation-specific means.95* \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription96* \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription97* \retval #PSA_ERROR_STORAGE_FAILURE \emptydescription98* \retval #PSA_ERROR_DATA_INVALID \emptydescription99* \retval #PSA_ERROR_DATA_CORRUPT \emptydescription100* \retval #PSA_ERROR_BAD_STATE101* The library has not been previously initialized by psa_crypto_init().102* It is implementation-dependent whether a failure to initialize103* results in this error code.104*/105psa_status_t psa_open_key(mbedtls_svc_key_id_t key,106psa_key_handle_t *handle);107108/** Close a key handle.109*110* If the handle designates a volatile key, this will destroy the key material111* and free all associated resources, just like psa_destroy_key().112*113* If this is the last open handle to a persistent key, then closing the handle114* will free all resources associated with the key in volatile memory. The key115* data in persistent storage is not affected and can be opened again later116* with a call to psa_open_key().117*118* Closing the key handle makes the handle invalid, and the key handle119* must not be used again by the application.120*121* \note This API is not part of the PSA Cryptography API Release 1.0.0122* specification. It was defined in the 1.0 Beta 3 version of the123* specification but was removed in the 1.0.0 released version. This API is124* kept for the time being to not break applications relying on it. It is not125* deprecated yet but will be in the near future.126*127* \note If the key handle was used to set up an active128* :ref:\`multipart operation <multipart-operations>\`, then closing the129* key handle can cause the multipart operation to fail. Applications should130* maintain the key handle until after the multipart operation has finished.131*132* \param handle The key handle to close.133* If this is \c 0, do nothing and return \c PSA_SUCCESS.134*135* \retval #PSA_SUCCESS136* \p handle was a valid handle or \c 0. It is now closed.137* \retval #PSA_ERROR_INVALID_HANDLE138* \p handle is not a valid handle nor \c 0.139* \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription140* \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription141* \retval #PSA_ERROR_BAD_STATE142* The library has not been previously initialized by psa_crypto_init().143* It is implementation-dependent whether a failure to initialize144* results in this error code.145*/146psa_status_t psa_close_key(psa_key_handle_t handle);147148/** \addtogroup attributes149* @{150*/151152#if !defined(MBEDTLS_DEPRECATED_REMOVED)153/** Custom Diffie-Hellman group.154*155* Mbed TLS does not support custom DH groups.156*157* \deprecated This value is not useful, so this macro will be removed in158* a future version of the library.159*/160#define PSA_DH_FAMILY_CUSTOM \161((psa_dh_family_t) MBEDTLS_DEPRECATED_NUMERIC_CONSTANT(0x7e))162163/**164* \brief Set domain parameters for a key.165*166* \deprecated Mbed TLS no longer supports any domain parameters.167* This function only does the equivalent of168* psa_set_key_type() and will be removed in a future version169* of the library.170*171* \param[in,out] attributes Attribute structure where \p type will be set.172* \param type Key type (a \c PSA_KEY_TYPE_XXX value).173* \param[in] data Ignored.174* \param data_length Must be 0.175*176* \retval #PSA_SUCCESS \emptydescription177* \retval #PSA_ERROR_NOT_SUPPORTED \emptydescription178*/179static inline psa_status_t MBEDTLS_DEPRECATED psa_set_key_domain_parameters(180psa_key_attributes_t *attributes,181psa_key_type_t type, const uint8_t *data, size_t data_length)182{183(void) data;184if (data_length != 0) {185return PSA_ERROR_NOT_SUPPORTED;186}187psa_set_key_type(attributes, type);188return PSA_SUCCESS;189}190191/**192* \brief Get domain parameters for a key.193*194* \deprecated Mbed TLS no longer supports any domain parameters.195* This function alwaya has an empty output and will be196* removed in a future version of the library.197198* \param[in] attributes Ignored.199* \param[out] data Ignored.200* \param data_size Ignored.201* \param[out] data_length Set to 0.202*203* \retval #PSA_SUCCESS \emptydescription204*/205static inline psa_status_t MBEDTLS_DEPRECATED psa_get_key_domain_parameters(206const psa_key_attributes_t *attributes,207uint8_t *data, size_t data_size, size_t *data_length)208{209(void) attributes;210(void) data;211(void) data_size;212*data_length = 0;213return PSA_SUCCESS;214}215216/** Safe output buffer size for psa_get_key_domain_parameters().217*218*/219#define PSA_KEY_DOMAIN_PARAMETERS_SIZE(key_type, key_bits) \220MBEDTLS_DEPRECATED_NUMERIC_CONSTANT(1u)221#endif /* MBEDTLS_DEPRECATED_REMOVED */222223/**@}*/224225#ifdef __cplusplus226}227#endif228229#endif /* PSA_CRYPTO_COMPAT_H */230231232