blob: 339ef270e1e6f53fc165bbb721486777e717d473 [file] [log] [blame]
Gilles Peskine7a894f22019-11-26 16:06:46 +01001/**
2 * \file psa/crypto_compat.h
3 *
4 * \brief PSA cryptography module: Backward compatibility aliases
5 *
Gilles Peskine0168f2f2019-11-29 12:22:32 +01006 * This header declares alternative names for macro and functions.
7 * New application code should not use these names.
8 * These names may be removed in a future version of Mbed Crypto.
9 *
Gilles Peskine7a894f22019-11-26 16:06:46 +010010 * \note This file may not be included directly. Applications must
11 * include psa/crypto.h.
12 */
13/*
Bence Szépkúti1e148272020-08-07 13:07:28 +020014 * Copyright The Mbed TLS Contributors
Gilles Peskine7a894f22019-11-26 16:06:46 +010015 * SPDX-License-Identifier: Apache-2.0
16 *
17 * Licensed under the Apache License, Version 2.0 (the "License"); you may
18 * not use this file except in compliance with the License.
19 * You may obtain a copy of the License at
20 *
21 * http://www.apache.org/licenses/LICENSE-2.0
22 *
23 * Unless required by applicable law or agreed to in writing, software
24 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
25 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
26 * See the License for the specific language governing permissions and
27 * limitations under the License.
Gilles Peskine7a894f22019-11-26 16:06:46 +010028 */
29
30#ifndef PSA_CRYPTO_COMPAT_H
31#define PSA_CRYPTO_COMPAT_H
32
Gilles Peskine7a894f22019-11-26 16:06:46 +010033#ifdef __cplusplus
34extern "C" {
35#endif
36
Ronald Croncf56a0a2020-08-04 09:51:30 +020037/*
Ronald Cron1d12d872020-11-18 17:21:22 +010038 * To support both openless APIs and psa_open_key() temporarily, define
Ronald Croncf56a0a2020-08-04 09:51:30 +020039 * psa_key_handle_t to be equal to mbedtls_svc_key_id_t. Do not mark the
40 * type and its utility macros and functions deprecated yet. This will be done
41 * in a subsequent phase.
42 */
43typedef mbedtls_svc_key_id_t psa_key_handle_t;
44
45#define PSA_KEY_HANDLE_INIT MBEDTLS_SVC_KEY_ID_INIT
46
Ronald Croncf56a0a2020-08-04 09:51:30 +020047/** Check wether an handle is null.
48 *
49 * \param handle Handle
50 *
51 * \return Non-zero if the handle is null, zero otherwise.
52 */
53static inline int psa_key_handle_is_null( psa_key_handle_t handle )
54{
55 return( mbedtls_svc_key_id_is_null( handle ) );
56}
57
Gilles Peskine7b0ab6d2019-11-26 16:32:12 +010058#if !defined(MBEDTLS_DEPRECATED_REMOVED)
59
Gilles Peskine0168f2f2019-11-29 12:22:32 +010060/*
61 * Mechanism for declaring deprecated values
62 */
Gilles Peskine7b0ab6d2019-11-26 16:32:12 +010063#if defined(MBEDTLS_DEPRECATED_WARNING) && !defined(MBEDTLS_PSA_DEPRECATED)
64#define MBEDTLS_PSA_DEPRECATED __attribute__((deprecated))
65#else
66#define MBEDTLS_PSA_DEPRECATED
67#endif
68
Gilles Peskine41510942019-11-26 16:10:58 +010069typedef MBEDTLS_PSA_DEPRECATED size_t mbedtls_deprecated_size_t;
Gilles Peskine7b0ab6d2019-11-26 16:32:12 +010070typedef MBEDTLS_PSA_DEPRECATED psa_status_t mbedtls_deprecated_psa_status_t;
Gilles Peskine41510942019-11-26 16:10:58 +010071typedef MBEDTLS_PSA_DEPRECATED psa_key_usage_t mbedtls_deprecated_psa_key_usage_t;
Paul Elliott8ff510a2020-06-02 17:19:28 +010072typedef MBEDTLS_PSA_DEPRECATED psa_ecc_family_t mbedtls_deprecated_psa_ecc_family_t;
Paul Elliott75e27032020-06-03 15:17:39 +010073typedef MBEDTLS_PSA_DEPRECATED psa_dh_family_t mbedtls_deprecated_psa_dh_family_t;
Paul Elliott8ff510a2020-06-02 17:19:28 +010074typedef MBEDTLS_PSA_DEPRECATED psa_ecc_family_t psa_ecc_curve_t;
Paul Elliott75e27032020-06-03 15:17:39 +010075typedef MBEDTLS_PSA_DEPRECATED psa_dh_family_t psa_dh_group_t;
Paul Elliott8ff510a2020-06-02 17:19:28 +010076
77#define PSA_KEY_TYPE_GET_CURVE PSA_KEY_TYPE_ECC_GET_FAMILY
Paul Elliott75e27032020-06-03 15:17:39 +010078#define PSA_KEY_TYPE_GET_GROUP PSA_KEY_TYPE_DH_GET_FAMILY
Gilles Peskine7b0ab6d2019-11-26 16:32:12 +010079
80#define MBEDTLS_DEPRECATED_CONSTANT( type, value ) \
81 ( (mbedtls_deprecated_##type) ( value ) )
82
Gilles Peskine7a894f22019-11-26 16:06:46 +010083/*
Gilles Peskine0168f2f2019-11-29 12:22:32 +010084 * Deprecated PSA Crypto error code definitions (PSA Crypto API <= 1.0 beta2)
Gilles Peskine7a894f22019-11-26 16:06:46 +010085 */
Gilles Peskine7a894f22019-11-26 16:06:46 +010086#define PSA_ERROR_UNKNOWN_ERROR \
Gilles Peskine7b0ab6d2019-11-26 16:32:12 +010087 MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_GENERIC_ERROR )
Gilles Peskine7a894f22019-11-26 16:06:46 +010088#define PSA_ERROR_OCCUPIED_SLOT \
Gilles Peskine7b0ab6d2019-11-26 16:32:12 +010089 MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_ALREADY_EXISTS )
Gilles Peskine7a894f22019-11-26 16:06:46 +010090#define PSA_ERROR_EMPTY_SLOT \
Gilles Peskine7b0ab6d2019-11-26 16:32:12 +010091 MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_DOES_NOT_EXIST )
Gilles Peskine7a894f22019-11-26 16:06:46 +010092#define PSA_ERROR_INSUFFICIENT_CAPACITY \
Gilles Peskine7b0ab6d2019-11-26 16:32:12 +010093 MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_INSUFFICIENT_DATA )
Gilles Peskine7a894f22019-11-26 16:06:46 +010094#define PSA_ERROR_TAMPERING_DETECTED \
Gilles Peskine7b0ab6d2019-11-26 16:32:12 +010095 MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_CORRUPTION_DETECTED )
96
Gilles Peskine41510942019-11-26 16:10:58 +010097/*
Gilles Peskine0168f2f2019-11-29 12:22:32 +010098 * Deprecated PSA Crypto numerical encodings (PSA Crypto API <= 1.0 beta3)
Gilles Peskine41510942019-11-26 16:10:58 +010099 */
100#define PSA_KEY_USAGE_SIGN \
101 MBEDTLS_DEPRECATED_CONSTANT( psa_key_usage_t, PSA_KEY_USAGE_SIGN_HASH )
102#define PSA_KEY_USAGE_VERIFY \
103 MBEDTLS_DEPRECATED_CONSTANT( psa_key_usage_t, PSA_KEY_USAGE_VERIFY_HASH )
104
105/*
Gilles Peskine0168f2f2019-11-29 12:22:32 +0100106 * Deprecated PSA Crypto size calculation macros (PSA Crypto API <= 1.0 beta3)
Gilles Peskine41510942019-11-26 16:10:58 +0100107 */
108#define PSA_ASYMMETRIC_SIGNATURE_MAX_SIZE \
109 MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_SIGNATURE_MAX_SIZE )
110#define PSA_ASYMMETRIC_SIGN_OUTPUT_SIZE( key_type, key_bits, alg ) \
111 MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_SIGN_OUTPUT_SIZE( key_type, key_bits, alg ) )
112
113/*
Gilles Peskine0168f2f2019-11-29 12:22:32 +0100114 * Deprecated PSA Crypto function names (PSA Crypto API <= 1.0 beta3)
Gilles Peskine41510942019-11-26 16:10:58 +0100115 */
Soby Mathew0a4270d2020-02-10 15:20:39 +0000116MBEDTLS_PSA_DEPRECATED static inline 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{
124 return psa_sign_hash( key, alg, hash, hash_length, signature, signature_size, signature_length );
125}
126
127MBEDTLS_PSA_DEPRECATED static inline psa_status_t psa_asymmetric_verify( psa_key_handle_t key,
128 psa_algorithm_t alg,
129 const uint8_t *hash,
130 size_t hash_length,
131 const uint8_t *signature,
132 size_t signature_length )
133{
134 return psa_verify_hash( key, alg, hash, hash_length, signature, signature_length );
135}
136
137
Gilles Peskine41510942019-11-26 16:10:58 +0100138
Gilles Peskine7b0ab6d2019-11-26 16:32:12 +0100139#endif /* MBEDTLS_DEPRECATED_REMOVED */
Gilles Peskine7a894f22019-11-26 16:06:46 +0100140
Gilles Peskine45c29ce2019-12-03 17:56:11 +0100141/*
Paul Elliott75e27032020-06-03 15:17:39 +0100142 * Size-specific elliptic curve families.
Gilles Peskine45c29ce2019-12-03 17:56:11 +0100143 */
Gilles Peskineb87b7192019-12-04 16:24:10 +0100144#define PSA_ECC_CURVE_SECP160K1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100145 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_K1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100146#define PSA_ECC_CURVE_SECP192K1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100147 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_K1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100148#define PSA_ECC_CURVE_SECP224K1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100149 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_K1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100150#define PSA_ECC_CURVE_SECP256K1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100151 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_K1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100152#define PSA_ECC_CURVE_SECP160R1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100153 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100154#define PSA_ECC_CURVE_SECP192R1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100155 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100156#define PSA_ECC_CURVE_SECP224R1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100157 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100158#define PSA_ECC_CURVE_SECP256R1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100159 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100160#define PSA_ECC_CURVE_SECP384R1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100161 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100162#define PSA_ECC_CURVE_SECP521R1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100163 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100164#define PSA_ECC_CURVE_SECP160R2 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100165 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R2 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100166#define PSA_ECC_CURVE_SECT163K1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100167 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100168#define PSA_ECC_CURVE_SECT233K1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100169 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100170#define PSA_ECC_CURVE_SECT239K1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100171 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100172#define PSA_ECC_CURVE_SECT283K1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100173 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100174#define PSA_ECC_CURVE_SECT409K1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100175 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100176#define PSA_ECC_CURVE_SECT571K1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100177 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100178#define PSA_ECC_CURVE_SECT163R1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100179 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100180#define PSA_ECC_CURVE_SECT193R1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100181 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100182#define PSA_ECC_CURVE_SECT233R1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100183 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100184#define PSA_ECC_CURVE_SECT283R1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100185 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100186#define PSA_ECC_CURVE_SECT409R1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100187 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100188#define PSA_ECC_CURVE_SECT571R1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100189 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100190#define PSA_ECC_CURVE_SECT163R2 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100191 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R2 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100192#define PSA_ECC_CURVE_SECT193R2 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100193 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R2 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100194#define PSA_ECC_CURVE_BRAINPOOL_P256R1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100195 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_BRAINPOOL_P_R1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100196#define PSA_ECC_CURVE_BRAINPOOL_P384R1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100197 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_BRAINPOOL_P_R1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100198#define PSA_ECC_CURVE_BRAINPOOL_P512R1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100199 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_BRAINPOOL_P_R1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100200#define PSA_ECC_CURVE_CURVE25519 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100201 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_MONTGOMERY )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100202#define PSA_ECC_CURVE_CURVE448 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100203 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_MONTGOMERY )
204
205/*
206 * Curves that changed name due to PSA specification.
207 */
208#define PSA_ECC_CURVE_SECP_K1 \
209 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_K1 )
210#define PSA_ECC_CURVE_SECP_R1 \
211 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 )
212#define PSA_ECC_CURVE_SECP_R2 \
213 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R2 )
214#define PSA_ECC_CURVE_SECT_K1 \
215 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 )
216#define PSA_ECC_CURVE_SECT_R1 \
217 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 )
218#define PSA_ECC_CURVE_SECT_R2 \
219 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R2 )
220#define PSA_ECC_CURVE_BRAINPOOL_P_R1 \
221 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_BRAINPOOL_P_R1 )
222#define PSA_ECC_CURVE_MONTGOMERY \
223 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_MONTGOMERY )
Gilles Peskine45c29ce2019-12-03 17:56:11 +0100224
Paul Elliott75e27032020-06-03 15:17:39 +0100225/*
226 * Finite-field Diffie-Hellman families.
227 */
Gilles Peskineb87b7192019-12-04 16:24:10 +0100228#define PSA_DH_GROUP_FFDHE2048 \
Paul Elliott75e27032020-06-03 15:17:39 +0100229 MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_RFC7919 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100230#define PSA_DH_GROUP_FFDHE3072 \
Paul Elliott75e27032020-06-03 15:17:39 +0100231 MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_RFC7919 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100232#define PSA_DH_GROUP_FFDHE4096 \
Paul Elliott75e27032020-06-03 15:17:39 +0100233 MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_RFC7919 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100234#define PSA_DH_GROUP_FFDHE6144 \
Paul Elliott75e27032020-06-03 15:17:39 +0100235 MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_RFC7919 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100236#define PSA_DH_GROUP_FFDHE8192 \
Paul Elliott75e27032020-06-03 15:17:39 +0100237 MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_RFC7919 )
238
239/*
240 * Diffie-Hellman families that changed name due to PSA specification.
241 */
242#define PSA_DH_GROUP_RFC7919 \
243 MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_RFC7919 )
244#define PSA_DH_GROUP_CUSTOM \
245 MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_CUSTOM )
Gilles Peskine45c29ce2019-12-03 17:56:11 +0100246
Ronald Croncf56a0a2020-08-04 09:51:30 +0200247/** Open a handle to an existing persistent key.
248 *
249 * Open a handle to a persistent key. A key is persistent if it was created
250 * with a lifetime other than #PSA_KEY_LIFETIME_VOLATILE. A persistent key
251 * always has a nonzero key identifier, set with psa_set_key_id() when
252 * creating the key. Implementations may provide additional pre-provisioned
253 * keys that can be opened with psa_open_key(). Such keys have an application
254 * key identifier in the vendor range, as documented in the description of
255 * #psa_key_id_t.
256 *
257 * The application must eventually close the handle with psa_close_key() or
258 * psa_destroy_key() to release associated resources. If the application dies
259 * without calling one of these functions, the implementation should perform
260 * the equivalent of a call to psa_close_key().
261 *
262 * Some implementations permit an application to open the same key multiple
263 * times. If this is successful, each call to psa_open_key() will return a
264 * different key handle.
265 *
266 * \note This API is not part of the PSA Cryptography API Release 1.0.0
267 * specification. It was defined in the 1.0 Beta 3 version of the
268 * specification but was removed in the 1.0.0 released version. This API is
269 * kept for the time being to not break applications relying on it. It is not
270 * deprecated yet but will be in the near future.
271 *
272 * \note Applications that rely on opening a key multiple times will not be
273 * portable to implementations that only permit a single key handle to be
274 * opened. See also :ref:\`key-handles\`.
275 *
276 *
277 * \param key The persistent identifier of the key.
278 * \param[out] handle On success, a handle to the key.
279 *
280 * \retval #PSA_SUCCESS
281 * Success. The application can now use the value of `*handle`
282 * to access the key.
283 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
284 * The implementation does not have sufficient resources to open the
285 * key. This can be due to reaching an implementation limit on the
286 * number of open keys, the number of open key handles, or available
287 * memory.
288 * \retval #PSA_ERROR_DOES_NOT_EXIST
289 * There is no persistent key with key identifier \p id.
290 * \retval #PSA_ERROR_INVALID_ARGUMENT
291 * \p id is not a valid persistent key identifier.
292 * \retval #PSA_ERROR_NOT_PERMITTED
293 * The specified key exists, but the application does not have the
294 * permission to access it. Note that this specification does not
295 * define any way to create such a key, but it may be possible
296 * through implementation-specific means.
297 * \retval #PSA_ERROR_COMMUNICATION_FAILURE
298 * \retval #PSA_ERROR_CORRUPTION_DETECTED
299 * \retval #PSA_ERROR_STORAGE_FAILURE
300 * \retval #PSA_ERROR_BAD_STATE
301 * The library has not been previously initialized by psa_crypto_init().
302 * It is implementation-dependent whether a failure to initialize
303 * results in this error code.
304 */
305psa_status_t psa_open_key( mbedtls_svc_key_id_t key,
306 psa_key_handle_t *handle );
307
308/** Close a key handle.
309 *
310 * If the handle designates a volatile key, this will destroy the key material
311 * and free all associated resources, just like psa_destroy_key().
312 *
313 * If this is the last open handle to a persistent key, then closing the handle
314 * will free all resources associated with the key in volatile memory. The key
315 * data in persistent storage is not affected and can be opened again later
316 * with a call to psa_open_key().
317 *
318 * Closing the key handle makes the handle invalid, and the key handle
319 * must not be used again by the application.
320 *
321 * \note This API is not part of the PSA Cryptography API Release 1.0.0
322 * specification. It was defined in the 1.0 Beta 3 version of the
323 * specification but was removed in the 1.0.0 released version. This API is
324 * kept for the time being to not break applications relying on it. It is not
325 * deprecated yet but will be in the near future.
326 *
327 * \note If the key handle was used to set up an active
328 * :ref:\`multipart operation <multipart-operations>\`, then closing the
329 * key handle can cause the multipart operation to fail. Applications should
330 * maintain the key handle until after the multipart operation has finished.
331 *
332 * \param handle The key handle to close.
333 * If this is \c 0, do nothing and return \c PSA_SUCCESS.
334 *
335 * \retval #PSA_SUCCESS
336 * \p handle was a valid handle or \c 0. It is now closed.
337 * \retval #PSA_ERROR_INVALID_HANDLE
338 * \p handle is not a valid handle nor \c 0.
339 * \retval #PSA_ERROR_COMMUNICATION_FAILURE
340 * \retval #PSA_ERROR_CORRUPTION_DETECTED
341 * \retval #PSA_ERROR_BAD_STATE
342 * The library has not been previously initialized by psa_crypto_init().
343 * It is implementation-dependent whether a failure to initialize
344 * results in this error code.
345 */
346psa_status_t psa_close_key(psa_key_handle_t handle);
347
Gilles Peskine7a894f22019-11-26 16:06:46 +0100348#ifdef __cplusplus
349}
350#endif
351
352#endif /* PSA_CRYPTO_COMPAT_H */