blob: 17dcee2d9e4a9d1b255491f5e2a1615fc8bbda9d [file] [log] [blame]
Summer Qin0e5b2e02020-10-22 11:23:39 +08001/*
Maulik Patel28659c42021-01-06 14:09:22 +00002 * Copyright (c) 2019-2021, Arm Limited. All rights reserved.
Summer Qin0e5b2e02020-10-22 11:23:39 +08003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
Antonio de Angelis04debbd2019-10-14 12:12:52 +01007/**
8 * \file psa/crypto_compat.h
9 *
10 * \brief PSA cryptography module: Backward compatibility aliases
11 *
12 * This header declares alternative names for macro and functions.
13 * New application code should not use these names.
14 * These names may be removed in a future version of Mbed Crypto.
15 *
16 * \note This file may not be included directly. Applications must
17 * include psa/crypto.h.
18 */
Antonio de Angelis04debbd2019-10-14 12:12:52 +010019
20#ifndef PSA_CRYPTO_COMPAT_H
21#define PSA_CRYPTO_COMPAT_H
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
Maulik Patel28659c42021-01-06 14:09:22 +000027/*
28 * To support both openless APIs and psa_open_key() temporarily, define
29 * psa_key_handle_t to be equal to psa_key_id_t. Do not mark the
30 * type and its utility macros and functions deprecated yet. This will be done
31 * in a subsequent phase.
32 */
33typedef psa_key_id_t psa_key_handle_t;
34
35/** Check whether an handle is null.
36 *
37 * \param handle Handle
38 *
39 * \return Non-zero if the handle is null, zero otherwise.
40 */
41static inline int psa_key_handle_is_null(psa_key_handle_t handle)
42{
43 return(handle == 0);
44}
45
Antonio de Angelis04debbd2019-10-14 12:12:52 +010046#if !defined(MBEDTLS_DEPRECATED_REMOVED)
47
48/*
49 * Mechanism for declaring deprecated values
50 */
51#if defined(MBEDTLS_DEPRECATED_WARNING) && !defined(MBEDTLS_PSA_DEPRECATED)
52#define MBEDTLS_PSA_DEPRECATED __attribute__((deprecated))
53#else
54#define MBEDTLS_PSA_DEPRECATED
55#endif
56
57typedef MBEDTLS_PSA_DEPRECATED size_t mbedtls_deprecated_size_t;
58typedef MBEDTLS_PSA_DEPRECATED psa_status_t mbedtls_deprecated_psa_status_t;
59typedef MBEDTLS_PSA_DEPRECATED psa_key_usage_t mbedtls_deprecated_psa_key_usage_t;
Summer Qin0e5b2e02020-10-22 11:23:39 +080060typedef MBEDTLS_PSA_DEPRECATED psa_ecc_family_t mbedtls_deprecated_psa_ecc_family_t;
61typedef MBEDTLS_PSA_DEPRECATED psa_dh_family_t mbedtls_deprecated_psa_dh_family_t;
62typedef MBEDTLS_PSA_DEPRECATED psa_ecc_family_t psa_ecc_curve_t;
63typedef MBEDTLS_PSA_DEPRECATED psa_dh_family_t psa_dh_group_t;
Maulik Patel28659c42021-01-06 14:09:22 +000064typedef MBEDTLS_PSA_DEPRECATED psa_algorithm_t mbedtls_deprecated_psa_algorithm_t;
Summer Qin0e5b2e02020-10-22 11:23:39 +080065
66#define PSA_KEY_TYPE_GET_CURVE PSA_KEY_TYPE_ECC_GET_FAMILY
67#define PSA_KEY_TYPE_GET_GROUP PSA_KEY_TYPE_DH_GET_FAMILY
Antonio de Angelis04debbd2019-10-14 12:12:52 +010068
69#define MBEDTLS_DEPRECATED_CONSTANT( type, value ) \
70 ( (mbedtls_deprecated_##type) ( value ) )
71
72/*
73 * Deprecated PSA Crypto error code definitions (PSA Crypto API <= 1.0 beta2)
74 */
75#define PSA_ERROR_UNKNOWN_ERROR \
76 MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_GENERIC_ERROR )
77#define PSA_ERROR_OCCUPIED_SLOT \
78 MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_ALREADY_EXISTS )
79#define PSA_ERROR_EMPTY_SLOT \
80 MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_DOES_NOT_EXIST )
81#define PSA_ERROR_INSUFFICIENT_CAPACITY \
82 MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_INSUFFICIENT_DATA )
83#define PSA_ERROR_TAMPERING_DETECTED \
84 MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_CORRUPTION_DETECTED )
85
86/*
87 * Deprecated PSA Crypto numerical encodings (PSA Crypto API <= 1.0 beta3)
88 */
89#define PSA_KEY_USAGE_SIGN \
90 MBEDTLS_DEPRECATED_CONSTANT( psa_key_usage_t, PSA_KEY_USAGE_SIGN_HASH )
91#define PSA_KEY_USAGE_VERIFY \
92 MBEDTLS_DEPRECATED_CONSTANT( psa_key_usage_t, PSA_KEY_USAGE_VERIFY_HASH )
93
94/*
95 * Deprecated PSA Crypto size calculation macros (PSA Crypto API <= 1.0 beta3)
96 */
97#define PSA_ASYMMETRIC_SIGNATURE_MAX_SIZE \
98 MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_SIGNATURE_MAX_SIZE )
99#define PSA_ASYMMETRIC_SIGN_OUTPUT_SIZE( key_type, key_bits, alg ) \
100 MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_SIGN_OUTPUT_SIZE( key_type, key_bits, alg ) )
Maulik Patel13b27cf2021-05-14 11:44:53 +0100101#define PSA_KEY_EXPORT_MAX_SIZE( key_type, key_bits ) \
102 MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_EXPORT_KEY_OUTPUT_SIZE( key_type, key_bits ) )
103#define PSA_BLOCK_CIPHER_BLOCK_SIZE( type ) \
104 MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_BLOCK_CIPHER_BLOCK_LENGTH( type ) )
105#define PSA_MAX_BLOCK_CIPHER_BLOCK_SIZE \
106 MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE )
107#define PSA_HASH_SIZE( alg ) \
108 MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_HASH_LENGTH( alg ) )
109#define PSA_MAC_FINAL_SIZE( key_type, key_bits, alg ) \
110 MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_MAC_LENGTH( key_type, key_bits, alg ) )
111#define PSA_ALG_TLS12_PSK_TO_MS_MAX_PSK_LEN \
112 MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_TLS12_PSK_TO_MS_PSK_MAX_SIZE )
Soby Mathewfd247c42020-02-24 10:23:43 +0000113/*
114 * Deprecated PSA Crypto function names (PSA Crypto API <= 1.0 beta3)
115 */
116MBEDTLS_PSA_DEPRECATED psa_status_t psa_asymmetric_sign( psa_key_handle_t key,
117 psa_algorithm_t alg,
118 const uint8_t *hash,
119 size_t hash_length,
120 uint8_t *signature,
121 size_t signature_size,
122 size_t *signature_length );
123
124MBEDTLS_PSA_DEPRECATED psa_status_t psa_asymmetric_verify( psa_key_handle_t key,
125 psa_algorithm_t alg,
126 const uint8_t *hash,
127 size_t hash_length,
128 const uint8_t *signature,
129 size_t signature_length );
130
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100131
Soby Mathew07ef6e42020-07-20 21:09:23 +0100132/*
Summer Qin0e5b2e02020-10-22 11:23:39 +0800133 * Size-specific elliptic curve families.
Soby Mathew07ef6e42020-07-20 21:09:23 +0100134 */
135#define PSA_ECC_CURVE_SECP160K1 \
Summer Qin0e5b2e02020-10-22 11:23:39 +0800136 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_K1 )
Soby Mathew07ef6e42020-07-20 21:09:23 +0100137#define PSA_ECC_CURVE_SECP192K1 \
Summer Qin0e5b2e02020-10-22 11:23:39 +0800138 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_K1 )
Soby Mathew07ef6e42020-07-20 21:09:23 +0100139#define PSA_ECC_CURVE_SECP224K1 \
Summer Qin0e5b2e02020-10-22 11:23:39 +0800140 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_K1 )
Soby Mathew07ef6e42020-07-20 21:09:23 +0100141#define PSA_ECC_CURVE_SECP256K1 \
Summer Qin0e5b2e02020-10-22 11:23:39 +0800142 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_K1 )
Soby Mathew07ef6e42020-07-20 21:09:23 +0100143#define PSA_ECC_CURVE_SECP160R1 \
Summer Qin0e5b2e02020-10-22 11:23:39 +0800144 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 )
Soby Mathew07ef6e42020-07-20 21:09:23 +0100145#define PSA_ECC_CURVE_SECP192R1 \
Summer Qin0e5b2e02020-10-22 11:23:39 +0800146 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 )
Soby Mathew07ef6e42020-07-20 21:09:23 +0100147#define PSA_ECC_CURVE_SECP224R1 \
Summer Qin0e5b2e02020-10-22 11:23:39 +0800148 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 )
Soby Mathew07ef6e42020-07-20 21:09:23 +0100149#define PSA_ECC_CURVE_SECP256R1 \
Summer Qin0e5b2e02020-10-22 11:23:39 +0800150 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 )
Soby Mathew07ef6e42020-07-20 21:09:23 +0100151#define PSA_ECC_CURVE_SECP384R1 \
Summer Qin0e5b2e02020-10-22 11:23:39 +0800152 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 )
Soby Mathew07ef6e42020-07-20 21:09:23 +0100153#define PSA_ECC_CURVE_SECP521R1 \
Summer Qin0e5b2e02020-10-22 11:23:39 +0800154 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 )
Soby Mathew07ef6e42020-07-20 21:09:23 +0100155#define PSA_ECC_CURVE_SECP160R2 \
Summer Qin0e5b2e02020-10-22 11:23:39 +0800156 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R2 )
Soby Mathew07ef6e42020-07-20 21:09:23 +0100157#define PSA_ECC_CURVE_SECT163K1 \
Summer Qin0e5b2e02020-10-22 11:23:39 +0800158 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 )
Soby Mathew07ef6e42020-07-20 21:09:23 +0100159#define PSA_ECC_CURVE_SECT233K1 \
Summer Qin0e5b2e02020-10-22 11:23:39 +0800160 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 )
Soby Mathew07ef6e42020-07-20 21:09:23 +0100161#define PSA_ECC_CURVE_SECT239K1 \
Summer Qin0e5b2e02020-10-22 11:23:39 +0800162 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 )
Soby Mathew07ef6e42020-07-20 21:09:23 +0100163#define PSA_ECC_CURVE_SECT283K1 \
Summer Qin0e5b2e02020-10-22 11:23:39 +0800164 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 )
Soby Mathew07ef6e42020-07-20 21:09:23 +0100165#define PSA_ECC_CURVE_SECT409K1 \
Summer Qin0e5b2e02020-10-22 11:23:39 +0800166 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 )
Soby Mathew07ef6e42020-07-20 21:09:23 +0100167#define PSA_ECC_CURVE_SECT571K1 \
Summer Qin0e5b2e02020-10-22 11:23:39 +0800168 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 )
Soby Mathew07ef6e42020-07-20 21:09:23 +0100169#define PSA_ECC_CURVE_SECT163R1 \
Summer Qin0e5b2e02020-10-22 11:23:39 +0800170 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 )
Soby Mathew07ef6e42020-07-20 21:09:23 +0100171#define PSA_ECC_CURVE_SECT193R1 \
Summer Qin0e5b2e02020-10-22 11:23:39 +0800172 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 )
Soby Mathew07ef6e42020-07-20 21:09:23 +0100173#define PSA_ECC_CURVE_SECT233R1 \
Summer Qin0e5b2e02020-10-22 11:23:39 +0800174 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 )
Soby Mathew07ef6e42020-07-20 21:09:23 +0100175#define PSA_ECC_CURVE_SECT283R1 \
Summer Qin0e5b2e02020-10-22 11:23:39 +0800176 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 )
Soby Mathew07ef6e42020-07-20 21:09:23 +0100177#define PSA_ECC_CURVE_SECT409R1 \
Summer Qin0e5b2e02020-10-22 11:23:39 +0800178 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 )
Soby Mathew07ef6e42020-07-20 21:09:23 +0100179#define PSA_ECC_CURVE_SECT571R1 \
Summer Qin0e5b2e02020-10-22 11:23:39 +0800180 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 )
Soby Mathew07ef6e42020-07-20 21:09:23 +0100181#define PSA_ECC_CURVE_SECT163R2 \
Summer Qin0e5b2e02020-10-22 11:23:39 +0800182 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R2 )
Soby Mathew07ef6e42020-07-20 21:09:23 +0100183#define PSA_ECC_CURVE_SECT193R2 \
Summer Qin0e5b2e02020-10-22 11:23:39 +0800184 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R2 )
Soby Mathew07ef6e42020-07-20 21:09:23 +0100185#define PSA_ECC_CURVE_BRAINPOOL_P256R1 \
Summer Qin0e5b2e02020-10-22 11:23:39 +0800186 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_BRAINPOOL_P_R1 )
Soby Mathew07ef6e42020-07-20 21:09:23 +0100187#define PSA_ECC_CURVE_BRAINPOOL_P384R1 \
Summer Qin0e5b2e02020-10-22 11:23:39 +0800188 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_BRAINPOOL_P_R1 )
Soby Mathew07ef6e42020-07-20 21:09:23 +0100189#define PSA_ECC_CURVE_BRAINPOOL_P512R1 \
Summer Qin0e5b2e02020-10-22 11:23:39 +0800190 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_BRAINPOOL_P_R1 )
Soby Mathew07ef6e42020-07-20 21:09:23 +0100191#define PSA_ECC_CURVE_CURVE25519 \
Summer Qin0e5b2e02020-10-22 11:23:39 +0800192 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_MONTGOMERY )
Soby Mathew07ef6e42020-07-20 21:09:23 +0100193#define PSA_ECC_CURVE_CURVE448 \
Summer Qin0e5b2e02020-10-22 11:23:39 +0800194 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_MONTGOMERY )
Soby Mathew07ef6e42020-07-20 21:09:23 +0100195
Summer Qin0e5b2e02020-10-22 11:23:39 +0800196/*
197 * Curves that changed name due to PSA specification.
198 */
199#define PSA_ECC_CURVE_SECP_K1 \
200 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_K1 )
201#define PSA_ECC_CURVE_SECP_R1 \
202 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 )
203#define PSA_ECC_CURVE_SECP_R2 \
204 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R2 )
205#define PSA_ECC_CURVE_SECT_K1 \
206 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 )
207#define PSA_ECC_CURVE_SECT_R1 \
208 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 )
209#define PSA_ECC_CURVE_SECT_R2 \
210 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R2 )
211#define PSA_ECC_CURVE_BRAINPOOL_P_R1 \
212 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_BRAINPOOL_P_R1 )
213#define PSA_ECC_CURVE_MONTGOMERY \
214 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_MONTGOMERY )
215
216/*
217 * Finite-field Diffie-Hellman families.
218 */
Soby Mathew07ef6e42020-07-20 21:09:23 +0100219#define PSA_DH_GROUP_FFDHE2048 \
Summer Qin0e5b2e02020-10-22 11:23:39 +0800220 MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_RFC7919 )
Soby Mathew07ef6e42020-07-20 21:09:23 +0100221#define PSA_DH_GROUP_FFDHE3072 \
Summer Qin0e5b2e02020-10-22 11:23:39 +0800222 MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_RFC7919 )
Soby Mathew07ef6e42020-07-20 21:09:23 +0100223#define PSA_DH_GROUP_FFDHE4096 \
Summer Qin0e5b2e02020-10-22 11:23:39 +0800224 MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_RFC7919 )
Soby Mathew07ef6e42020-07-20 21:09:23 +0100225#define PSA_DH_GROUP_FFDHE6144 \
Summer Qin0e5b2e02020-10-22 11:23:39 +0800226 MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_RFC7919 )
Soby Mathew07ef6e42020-07-20 21:09:23 +0100227#define PSA_DH_GROUP_FFDHE8192 \
Summer Qin0e5b2e02020-10-22 11:23:39 +0800228 MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_RFC7919 )
229
230/*
231 * Diffie-Hellman families that changed name due to PSA specification.
232 */
233#define PSA_DH_GROUP_RFC7919 \
234 MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_RFC7919 )
235#define PSA_DH_GROUP_CUSTOM \
236 MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_CUSTOM )
Soby Mathew07ef6e42020-07-20 21:09:23 +0100237
Maulik Patel28659c42021-01-06 14:09:22 +0000238/*
239 * Deprecated PSA Crypto stream cipher algorithms (PSA Crypto API <= 1.0 beta3)
240 */
241#define PSA_ALG_ARC4 \
242 MBEDTLS_DEPRECATED_CONSTANT(psa_algorithm_t, PSA_ALG_STREAM_CIPHER)
243#define PSA_ALG_CHACHA20 \
244 MBEDTLS_DEPRECATED_CONSTANT(psa_algorithm_t, PSA_ALG_STREAM_CIPHER)
245
Maulik Patel13b27cf2021-05-14 11:44:53 +0100246/*
247 * Renamed AEAD tag length macros (PSA Crypto API <= 1.0 beta3)
248 */
249#define PSA_ALG_AEAD_WITH_DEFAULT_TAG_LENGTH( aead_alg ) \
250 MBEDTLS_DEPRECATED_CONSTANT( psa_algorithm_t, PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG( aead_alg ) )
251#define PSA_ALG_AEAD_WITH_TAG_LENGTH( aead_alg, tag_length ) \
252 MBEDTLS_DEPRECATED_CONSTANT( psa_algorithm_t, PSA_ALG_AEAD_WITH_SHORTENED_TAG( aead_alg, tag_length ) )
253
254
Maulik Patel28659c42021-01-06 14:09:22 +0000255#endif /* MBEDTLS_DEPRECATED_REMOVED */
256
257/** Open a handle to an existing persistent key.
258 *
259 * Open a handle to a persistent key. A key is persistent if it was created
260 * with a lifetime other than #PSA_KEY_LIFETIME_VOLATILE. A persistent key
261 * always has a nonzero key identifier, set with psa_set_key_id() when
262 * creating the key. Implementations may provide additional pre-provisioned
263 * keys that can be opened with psa_open_key(). Such keys have an application
264 * key identifier in the vendor range, as documented in the description of
265 * #psa_key_id_t.
266 *
267 * The application must eventually close the handle with psa_close_key() or
268 * psa_destroy_key() to release associated resources. If the application dies
269 * without calling one of these functions, the implementation should perform
270 * the equivalent of a call to psa_close_key().
271 *
272 * Some implementations permit an application to open the same key multiple
273 * times. If this is successful, each call to psa_open_key() will return a
274 * different key handle.
275 *
276 * \note This API is not part of the PSA Cryptography API Release 1.0.0
277 * specification. It was defined in the 1.0 Beta 3 version of the
278 * specification but was removed in the 1.0.0 released version. This API is
279 * kept for the time being to not break applications relying on it. It is not
280 * deprecated yet but will be in the near future.
281 *
282 * \note Applications that rely on opening a key multiple times will not be
283 * portable to implementations that only permit a single key handle to be
284 * opened. See also :ref:\`key-handles\`.
285 *
286 *
287 * \param id The persistent identifier of the key.
288 * \param[out] key On success, a handle to the key.
289 *
290 * \retval #PSA_SUCCESS
291 * Success. The application can now use the value of `*handle`
292 * to access the key.
293 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
294 * The implementation does not have sufficient resources to open the
295 * key. This can be due to reaching an implementation limit on the
296 * number of open keys, the number of open key handles, or available
297 * memory.
298 * \retval #PSA_ERROR_DOES_NOT_EXIST
299 * There is no persistent key with key identifier \p id.
300 * \retval #PSA_ERROR_INVALID_ARGUMENT
301 * \p id is not a valid persistent key identifier.
302 * \retval #PSA_ERROR_NOT_PERMITTED
303 * The specified key exists, but the application does not have the
304 * permission to access it. Note that this specification does not
305 * define any way to create such a key, but it may be possible
306 * through implementation-specific means.
307 * \retval #PSA_ERROR_COMMUNICATION_FAILURE
308 * \retval #PSA_ERROR_CORRUPTION_DETECTED
309 * \retval #PSA_ERROR_STORAGE_FAILURE
Maulik Patel13b27cf2021-05-14 11:44:53 +0100310 * \retval #PSA_ERROR_DATA_INVALID
311 * \retval #PSA_ERROR_DATA_CORRUPT
Maulik Patel28659c42021-01-06 14:09:22 +0000312 * \retval #PSA_ERROR_BAD_STATE
313 * The library has not been previously initialized by psa_crypto_init().
314 * It is implementation-dependent whether a failure to initialize
315 * results in this error code.
316 */
317psa_status_t psa_open_key(psa_key_id_t id,
318 psa_key_id_t *key);
319
320/** Close a key handle.
321 *
322 * If the handle designates a volatile key, this will destroy the key material
323 * and free all associated resources, just like psa_destroy_key().
324 *
325 * If this is the last open handle to a persistent key, then closing the handle
326 * will free all resources associated with the key in volatile memory. The key
327 * data in persistent storage is not affected and can be opened again later
328 * with a call to psa_open_key().
329 *
330 * Closing the key handle makes the handle invalid, and the key handle
331 * must not be used again by the application.
332 *
333 * \note This API is not part of the PSA Cryptography API Release 1.0.0
334 * specification. It was defined in the 1.0 Beta 3 version of the
335 * specification but was removed in the 1.0.0 released version. This API is
336 * kept for the time being to not break applications relying on it. It is not
337 * deprecated yet but will be in the near future.
338 *
339 * \note If the key handle was used to set up an active
340 * :ref:\`multipart operation <multipart-operations>\`, then closing the
341 * key handle can cause the multipart operation to fail. Applications should
342 * maintain the key handle until after the multipart operation has finished.
343 *
344 * \param key The key to close.
345 * If this is \c 0, do nothing and return \c PSA_SUCCESS.
346 *
347 * \retval #PSA_SUCCESS
348 * \p handle was a valid handle or \c 0. It is now closed.
349 * \retval #PSA_ERROR_INVALID_HANDLE
350 * \p handle is not a valid handle nor \c 0.
351 * \retval #PSA_ERROR_COMMUNICATION_FAILURE
352 * \retval #PSA_ERROR_CORRUPTION_DETECTED
353 * \retval #PSA_ERROR_BAD_STATE
354 * The library has not been previously initialized by psa_crypto_init().
355 * It is implementation-dependent whether a failure to initialize
356 * results in this error code.
357 */
358psa_status_t psa_close_key(psa_key_id_t key);
359
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100360#ifdef __cplusplus
361}
362#endif
363
364#endif /* PSA_CRYPTO_COMPAT_H */