132b31808SJens Wiklander /**
232b31808SJens Wiklander * \file psa/crypto_compat.h
332b31808SJens Wiklander *
432b31808SJens Wiklander * \brief PSA cryptography module: Backward compatibility aliases
532b31808SJens Wiklander *
632b31808SJens Wiklander * This header declares alternative names for macro and functions.
732b31808SJens Wiklander * New application code should not use these names.
8*b0563631STom Van Eyck * These names may be removed in a future version of Mbed TLS.
932b31808SJens Wiklander *
1032b31808SJens Wiklander * \note This file may not be included directly. Applications must
1132b31808SJens Wiklander * include psa/crypto.h.
1232b31808SJens Wiklander */
1332b31808SJens Wiklander /*
1432b31808SJens Wiklander * Copyright The Mbed TLS Contributors
15*b0563631STom Van Eyck * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
1632b31808SJens Wiklander */
1732b31808SJens Wiklander
1832b31808SJens Wiklander #ifndef PSA_CRYPTO_COMPAT_H
1932b31808SJens Wiklander #define PSA_CRYPTO_COMPAT_H
2032b31808SJens Wiklander
2132b31808SJens Wiklander #ifdef __cplusplus
2232b31808SJens Wiklander extern "C" {
2332b31808SJens Wiklander #endif
2432b31808SJens Wiklander
2532b31808SJens Wiklander /*
2632b31808SJens Wiklander * To support both openless APIs and psa_open_key() temporarily, define
2732b31808SJens Wiklander * psa_key_handle_t to be equal to mbedtls_svc_key_id_t. Do not mark the
2832b31808SJens Wiklander * type and its utility macros and functions deprecated yet. This will be done
2932b31808SJens Wiklander * in a subsequent phase.
3032b31808SJens Wiklander */
3132b31808SJens Wiklander typedef mbedtls_svc_key_id_t psa_key_handle_t;
3232b31808SJens Wiklander
3332b31808SJens Wiklander #define PSA_KEY_HANDLE_INIT MBEDTLS_SVC_KEY_ID_INIT
3432b31808SJens Wiklander
3532b31808SJens Wiklander /** Check whether a handle is null.
3632b31808SJens Wiklander *
3732b31808SJens Wiklander * \param handle Handle
3832b31808SJens Wiklander *
3932b31808SJens Wiklander * \return Non-zero if the handle is null, zero otherwise.
4032b31808SJens Wiklander */
psa_key_handle_is_null(psa_key_handle_t handle)4132b31808SJens Wiklander static inline int psa_key_handle_is_null(psa_key_handle_t handle)
4232b31808SJens Wiklander {
4332b31808SJens Wiklander return mbedtls_svc_key_id_is_null(handle);
4432b31808SJens Wiklander }
4532b31808SJens Wiklander
4632b31808SJens Wiklander /** Open a handle to an existing persistent key.
4732b31808SJens Wiklander *
4832b31808SJens Wiklander * Open a handle to a persistent key. A key is persistent if it was created
4932b31808SJens Wiklander * with a lifetime other than #PSA_KEY_LIFETIME_VOLATILE. A persistent key
5032b31808SJens Wiklander * always has a nonzero key identifier, set with psa_set_key_id() when
5132b31808SJens Wiklander * creating the key. Implementations may provide additional pre-provisioned
5232b31808SJens Wiklander * keys that can be opened with psa_open_key(). Such keys have an application
5332b31808SJens Wiklander * key identifier in the vendor range, as documented in the description of
5432b31808SJens Wiklander * #psa_key_id_t.
5532b31808SJens Wiklander *
5632b31808SJens Wiklander * The application must eventually close the handle with psa_close_key() or
5732b31808SJens Wiklander * psa_destroy_key() to release associated resources. If the application dies
5832b31808SJens Wiklander * without calling one of these functions, the implementation should perform
5932b31808SJens Wiklander * the equivalent of a call to psa_close_key().
6032b31808SJens Wiklander *
6132b31808SJens Wiklander * Some implementations permit an application to open the same key multiple
6232b31808SJens Wiklander * times. If this is successful, each call to psa_open_key() will return a
6332b31808SJens Wiklander * different key handle.
6432b31808SJens Wiklander *
6532b31808SJens Wiklander * \note This API is not part of the PSA Cryptography API Release 1.0.0
6632b31808SJens Wiklander * specification. It was defined in the 1.0 Beta 3 version of the
6732b31808SJens Wiklander * specification but was removed in the 1.0.0 released version. This API is
6832b31808SJens Wiklander * kept for the time being to not break applications relying on it. It is not
6932b31808SJens Wiklander * deprecated yet but will be in the near future.
7032b31808SJens Wiklander *
7132b31808SJens Wiklander * \note Applications that rely on opening a key multiple times will not be
7232b31808SJens Wiklander * portable to implementations that only permit a single key handle to be
7332b31808SJens Wiklander * opened. See also :ref:\`key-handles\`.
7432b31808SJens Wiklander *
7532b31808SJens Wiklander *
7632b31808SJens Wiklander * \param key The persistent identifier of the key.
7732b31808SJens Wiklander * \param[out] handle On success, a handle to the key.
7832b31808SJens Wiklander *
7932b31808SJens Wiklander * \retval #PSA_SUCCESS
8032b31808SJens Wiklander * Success. The application can now use the value of `*handle`
8132b31808SJens Wiklander * to access the key.
8232b31808SJens Wiklander * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
8332b31808SJens Wiklander * The implementation does not have sufficient resources to open the
8432b31808SJens Wiklander * key. This can be due to reaching an implementation limit on the
8532b31808SJens Wiklander * number of open keys, the number of open key handles, or available
8632b31808SJens Wiklander * memory.
8732b31808SJens Wiklander * \retval #PSA_ERROR_DOES_NOT_EXIST
8832b31808SJens Wiklander * There is no persistent key with key identifier \p key.
8932b31808SJens Wiklander * \retval #PSA_ERROR_INVALID_ARGUMENT
9032b31808SJens Wiklander * \p key is not a valid persistent key identifier.
9132b31808SJens Wiklander * \retval #PSA_ERROR_NOT_PERMITTED
9232b31808SJens Wiklander * The specified key exists, but the application does not have the
9332b31808SJens Wiklander * permission to access it. Note that this specification does not
9432b31808SJens Wiklander * define any way to create such a key, but it may be possible
9532b31808SJens Wiklander * through implementation-specific means.
9632b31808SJens Wiklander * \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription
9732b31808SJens Wiklander * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
9832b31808SJens Wiklander * \retval #PSA_ERROR_STORAGE_FAILURE \emptydescription
9932b31808SJens Wiklander * \retval #PSA_ERROR_DATA_INVALID \emptydescription
10032b31808SJens Wiklander * \retval #PSA_ERROR_DATA_CORRUPT \emptydescription
10132b31808SJens Wiklander * \retval #PSA_ERROR_BAD_STATE
10232b31808SJens Wiklander * The library has not been previously initialized by psa_crypto_init().
10332b31808SJens Wiklander * It is implementation-dependent whether a failure to initialize
10432b31808SJens Wiklander * results in this error code.
10532b31808SJens Wiklander */
10632b31808SJens Wiklander psa_status_t psa_open_key(mbedtls_svc_key_id_t key,
10732b31808SJens Wiklander psa_key_handle_t *handle);
10832b31808SJens Wiklander
10932b31808SJens Wiklander /** Close a key handle.
11032b31808SJens Wiklander *
11132b31808SJens Wiklander * If the handle designates a volatile key, this will destroy the key material
11232b31808SJens Wiklander * and free all associated resources, just like psa_destroy_key().
11332b31808SJens Wiklander *
11432b31808SJens Wiklander * If this is the last open handle to a persistent key, then closing the handle
11532b31808SJens Wiklander * will free all resources associated with the key in volatile memory. The key
11632b31808SJens Wiklander * data in persistent storage is not affected and can be opened again later
11732b31808SJens Wiklander * with a call to psa_open_key().
11832b31808SJens Wiklander *
11932b31808SJens Wiklander * Closing the key handle makes the handle invalid, and the key handle
12032b31808SJens Wiklander * must not be used again by the application.
12132b31808SJens Wiklander *
12232b31808SJens Wiklander * \note This API is not part of the PSA Cryptography API Release 1.0.0
12332b31808SJens Wiklander * specification. It was defined in the 1.0 Beta 3 version of the
12432b31808SJens Wiklander * specification but was removed in the 1.0.0 released version. This API is
12532b31808SJens Wiklander * kept for the time being to not break applications relying on it. It is not
12632b31808SJens Wiklander * deprecated yet but will be in the near future.
12732b31808SJens Wiklander *
12832b31808SJens Wiklander * \note If the key handle was used to set up an active
12932b31808SJens Wiklander * :ref:\`multipart operation <multipart-operations>\`, then closing the
13032b31808SJens Wiklander * key handle can cause the multipart operation to fail. Applications should
13132b31808SJens Wiklander * maintain the key handle until after the multipart operation has finished.
13232b31808SJens Wiklander *
13332b31808SJens Wiklander * \param handle The key handle to close.
13432b31808SJens Wiklander * If this is \c 0, do nothing and return \c PSA_SUCCESS.
13532b31808SJens Wiklander *
13632b31808SJens Wiklander * \retval #PSA_SUCCESS
13732b31808SJens Wiklander * \p handle was a valid handle or \c 0. It is now closed.
13832b31808SJens Wiklander * \retval #PSA_ERROR_INVALID_HANDLE
13932b31808SJens Wiklander * \p handle is not a valid handle nor \c 0.
14032b31808SJens Wiklander * \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription
14132b31808SJens Wiklander * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
14232b31808SJens Wiklander * \retval #PSA_ERROR_BAD_STATE
14332b31808SJens Wiklander * The library has not been previously initialized by psa_crypto_init().
14432b31808SJens Wiklander * It is implementation-dependent whether a failure to initialize
14532b31808SJens Wiklander * results in this error code.
14632b31808SJens Wiklander */
14732b31808SJens Wiklander psa_status_t psa_close_key(psa_key_handle_t handle);
14832b31808SJens Wiklander
149*b0563631STom Van Eyck /** \addtogroup attributes
150*b0563631STom Van Eyck * @{
151*b0563631STom Van Eyck */
152*b0563631STom Van Eyck
153*b0563631STom Van Eyck #if !defined(MBEDTLS_DEPRECATED_REMOVED)
154*b0563631STom Van Eyck /** Custom Diffie-Hellman group.
155*b0563631STom Van Eyck *
156*b0563631STom Van Eyck * Mbed TLS does not support custom DH groups.
157*b0563631STom Van Eyck *
158*b0563631STom Van Eyck * \deprecated This value is not useful, so this macro will be removed in
159*b0563631STom Van Eyck * a future version of the library.
160*b0563631STom Van Eyck */
161*b0563631STom Van Eyck #define PSA_DH_FAMILY_CUSTOM \
162*b0563631STom Van Eyck ((psa_dh_family_t) MBEDTLS_DEPRECATED_NUMERIC_CONSTANT(0x7e))
163*b0563631STom Van Eyck
164*b0563631STom Van Eyck /**
165*b0563631STom Van Eyck * \brief Set domain parameters for a key.
166*b0563631STom Van Eyck *
167*b0563631STom Van Eyck * \deprecated Mbed TLS no longer supports any domain parameters.
168*b0563631STom Van Eyck * This function only does the equivalent of
169*b0563631STom Van Eyck * psa_set_key_type() and will be removed in a future version
170*b0563631STom Van Eyck * of the library.
171*b0563631STom Van Eyck *
172*b0563631STom Van Eyck * \param[in,out] attributes Attribute structure where \p type will be set.
173*b0563631STom Van Eyck * \param type Key type (a \c PSA_KEY_TYPE_XXX value).
174*b0563631STom Van Eyck * \param[in] data Ignored.
175*b0563631STom Van Eyck * \param data_length Must be 0.
176*b0563631STom Van Eyck *
177*b0563631STom Van Eyck * \retval #PSA_SUCCESS \emptydescription
178*b0563631STom Van Eyck * \retval #PSA_ERROR_NOT_SUPPORTED \emptydescription
179*b0563631STom Van Eyck */
psa_set_key_domain_parameters(psa_key_attributes_t * attributes,psa_key_type_t type,const uint8_t * data,size_t data_length)180*b0563631STom Van Eyck static inline psa_status_t MBEDTLS_DEPRECATED psa_set_key_domain_parameters(
181*b0563631STom Van Eyck psa_key_attributes_t *attributes,
182*b0563631STom Van Eyck psa_key_type_t type, const uint8_t *data, size_t data_length)
183*b0563631STom Van Eyck {
184*b0563631STom Van Eyck (void) data;
185*b0563631STom Van Eyck if (data_length != 0) {
186*b0563631STom Van Eyck return PSA_ERROR_NOT_SUPPORTED;
187*b0563631STom Van Eyck }
188*b0563631STom Van Eyck psa_set_key_type(attributes, type);
189*b0563631STom Van Eyck return PSA_SUCCESS;
190*b0563631STom Van Eyck }
191*b0563631STom Van Eyck
192*b0563631STom Van Eyck /**
193*b0563631STom Van Eyck * \brief Get domain parameters for a key.
194*b0563631STom Van Eyck *
195*b0563631STom Van Eyck * \deprecated Mbed TLS no longer supports any domain parameters.
196*b0563631STom Van Eyck * This function alwaya has an empty output and will be
197*b0563631STom Van Eyck * removed in a future version of the library.
198*b0563631STom Van Eyck
199*b0563631STom Van Eyck * \param[in] attributes Ignored.
200*b0563631STom Van Eyck * \param[out] data Ignored.
201*b0563631STom Van Eyck * \param data_size Ignored.
202*b0563631STom Van Eyck * \param[out] data_length Set to 0.
203*b0563631STom Van Eyck *
204*b0563631STom Van Eyck * \retval #PSA_SUCCESS \emptydescription
205*b0563631STom Van Eyck */
psa_get_key_domain_parameters(const psa_key_attributes_t * attributes,uint8_t * data,size_t data_size,size_t * data_length)206*b0563631STom Van Eyck static inline psa_status_t MBEDTLS_DEPRECATED psa_get_key_domain_parameters(
207*b0563631STom Van Eyck const psa_key_attributes_t *attributes,
208*b0563631STom Van Eyck uint8_t *data, size_t data_size, size_t *data_length)
209*b0563631STom Van Eyck {
210*b0563631STom Van Eyck (void) attributes;
211*b0563631STom Van Eyck (void) data;
212*b0563631STom Van Eyck (void) data_size;
213*b0563631STom Van Eyck *data_length = 0;
214*b0563631STom Van Eyck return PSA_SUCCESS;
215*b0563631STom Van Eyck }
216*b0563631STom Van Eyck
217*b0563631STom Van Eyck /** Safe output buffer size for psa_get_key_domain_parameters().
218*b0563631STom Van Eyck *
219*b0563631STom Van Eyck */
220*b0563631STom Van Eyck #define PSA_KEY_DOMAIN_PARAMETERS_SIZE(key_type, key_bits) \
221*b0563631STom Van Eyck MBEDTLS_DEPRECATED_NUMERIC_CONSTANT(1u)
222*b0563631STom Van Eyck #endif /* MBEDTLS_DEPRECATED_REMOVED */
223*b0563631STom Van Eyck
224*b0563631STom Van Eyck /**@}*/
225*b0563631STom Van Eyck
22632b31808SJens Wiklander #ifdef __cplusplus
22732b31808SJens Wiklander }
22832b31808SJens Wiklander #endif
22932b31808SJens Wiklander
23032b31808SJens Wiklander #endif /* PSA_CRYPTO_COMPAT_H */
231