blob: 2f920b28e767e8464036696681a8a60fefe9bc79 [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;
Bence Szépkúticbe39532020-12-08 00:01:31 +010076typedef MBEDTLS_PSA_DEPRECATED psa_algorithm_t mbedtls_deprecated_psa_algorithm_t;
Paul Elliott8ff510a2020-06-02 17:19:28 +010077
78#define PSA_KEY_TYPE_GET_CURVE PSA_KEY_TYPE_ECC_GET_FAMILY
Paul Elliott75e27032020-06-03 15:17:39 +010079#define PSA_KEY_TYPE_GET_GROUP PSA_KEY_TYPE_DH_GET_FAMILY
Gilles Peskine7b0ab6d2019-11-26 16:32:12 +010080
81#define MBEDTLS_DEPRECATED_CONSTANT( type, value ) \
82 ( (mbedtls_deprecated_##type) ( value ) )
83
Gilles Peskine7a894f22019-11-26 16:06:46 +010084/*
Gilles Peskine0168f2f2019-11-29 12:22:32 +010085 * Deprecated PSA Crypto error code definitions (PSA Crypto API <= 1.0 beta2)
Gilles Peskine7a894f22019-11-26 16:06:46 +010086 */
Gilles Peskine7a894f22019-11-26 16:06:46 +010087#define PSA_ERROR_UNKNOWN_ERROR \
Gilles Peskine7b0ab6d2019-11-26 16:32:12 +010088 MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_GENERIC_ERROR )
Gilles Peskine7a894f22019-11-26 16:06:46 +010089#define PSA_ERROR_OCCUPIED_SLOT \
Gilles Peskine7b0ab6d2019-11-26 16:32:12 +010090 MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_ALREADY_EXISTS )
Gilles Peskine7a894f22019-11-26 16:06:46 +010091#define PSA_ERROR_EMPTY_SLOT \
Gilles Peskine7b0ab6d2019-11-26 16:32:12 +010092 MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_DOES_NOT_EXIST )
Gilles Peskine7a894f22019-11-26 16:06:46 +010093#define PSA_ERROR_INSUFFICIENT_CAPACITY \
Gilles Peskine7b0ab6d2019-11-26 16:32:12 +010094 MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_INSUFFICIENT_DATA )
Gilles Peskine7a894f22019-11-26 16:06:46 +010095#define PSA_ERROR_TAMPERING_DETECTED \
Gilles Peskine7b0ab6d2019-11-26 16:32:12 +010096 MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_CORRUPTION_DETECTED )
97
Gilles Peskine41510942019-11-26 16:10:58 +010098/*
Gilles Peskine0168f2f2019-11-29 12:22:32 +010099 * Deprecated PSA Crypto numerical encodings (PSA Crypto API <= 1.0 beta3)
Gilles Peskine41510942019-11-26 16:10:58 +0100100 */
101#define PSA_KEY_USAGE_SIGN \
102 MBEDTLS_DEPRECATED_CONSTANT( psa_key_usage_t, PSA_KEY_USAGE_SIGN_HASH )
103#define PSA_KEY_USAGE_VERIFY \
104 MBEDTLS_DEPRECATED_CONSTANT( psa_key_usage_t, PSA_KEY_USAGE_VERIFY_HASH )
105
106/*
Gilles Peskine0168f2f2019-11-29 12:22:32 +0100107 * Deprecated PSA Crypto size calculation macros (PSA Crypto API <= 1.0 beta3)
Gilles Peskine41510942019-11-26 16:10:58 +0100108 */
109#define PSA_ASYMMETRIC_SIGNATURE_MAX_SIZE \
110 MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_SIGNATURE_MAX_SIZE )
111#define PSA_ASYMMETRIC_SIGN_OUTPUT_SIZE( key_type, key_bits, alg ) \
112 MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_SIGN_OUTPUT_SIZE( key_type, key_bits, alg ) )
gabor-mezei-armcbcec212020-12-18 14:23:51 +0100113#define PSA_KEY_EXPORT_MAX_SIZE( key_type, key_bits ) \
gabor-mezei-armd25ea722021-01-21 12:20:08 +0100114 MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_EXPORT_KEY_OUTPUT_SIZE( key_type, key_bits ) )
gabor-mezei-armcbcec212020-12-18 14:23:51 +0100115#define PSA_BLOCK_CIPHER_BLOCK_SIZE( type ) \
gabor-mezei-armd25ea722021-01-21 12:20:08 +0100116 MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_BLOCK_CIPHER_BLOCK_LENGTH( type ) )
gabor-mezei-armcbcec212020-12-18 14:23:51 +0100117#define PSA_MAX_BLOCK_CIPHER_BLOCK_SIZE \
gabor-mezei-armd25ea722021-01-21 12:20:08 +0100118 MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE )
gabor-mezei-armcbcec212020-12-18 14:23:51 +0100119#define PSA_HASH_SIZE( alg ) \
gabor-mezei-armd25ea722021-01-21 12:20:08 +0100120 MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_HASH_LENGTH( alg ) )
gabor-mezei-armcbcec212020-12-18 14:23:51 +0100121#define PSA_MAC_FINAL_SIZE( key_type, key_bits, alg ) \
gabor-mezei-armd25ea722021-01-21 12:20:08 +0100122 MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_MAC_LENGTH( key_type, key_bits, alg ) )
gabor-mezei-armcbcec212020-12-18 14:23:51 +0100123#define PSA_ALG_TLS12_PSK_TO_MS_MAX_PSK_LEN \
gabor-mezei-armd25ea722021-01-21 12:20:08 +0100124 MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_TLS12_PSK_TO_MS_PSK_MAX_SIZE )
125
Gilles Peskine41510942019-11-26 16:10:58 +0100126/*
Gilles Peskine0168f2f2019-11-29 12:22:32 +0100127 * Deprecated PSA Crypto function names (PSA Crypto API <= 1.0 beta3)
Gilles Peskine41510942019-11-26 16:10:58 +0100128 */
Soby Mathew0a4270d2020-02-10 15:20:39 +0000129MBEDTLS_PSA_DEPRECATED static inline psa_status_t psa_asymmetric_sign( psa_key_handle_t key,
130 psa_algorithm_t alg,
131 const uint8_t *hash,
132 size_t hash_length,
133 uint8_t *signature,
134 size_t signature_size,
135 size_t *signature_length )
136{
137 return psa_sign_hash( key, alg, hash, hash_length, signature, signature_size, signature_length );
138}
139
140MBEDTLS_PSA_DEPRECATED static inline psa_status_t psa_asymmetric_verify( psa_key_handle_t key,
141 psa_algorithm_t alg,
142 const uint8_t *hash,
143 size_t hash_length,
144 const uint8_t *signature,
145 size_t signature_length )
146{
147 return psa_verify_hash( key, alg, hash, hash_length, signature, signature_length );
148}
149
Gilles Peskine45c29ce2019-12-03 17:56:11 +0100150/*
Paul Elliott75e27032020-06-03 15:17:39 +0100151 * Size-specific elliptic curve families.
Gilles Peskine45c29ce2019-12-03 17:56:11 +0100152 */
Gilles Peskineb87b7192019-12-04 16:24:10 +0100153#define PSA_ECC_CURVE_SECP160K1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100154 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_K1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100155#define PSA_ECC_CURVE_SECP192K1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100156 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_K1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100157#define PSA_ECC_CURVE_SECP224K1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100158 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_K1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100159#define PSA_ECC_CURVE_SECP256K1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100160 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_K1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100161#define PSA_ECC_CURVE_SECP160R1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100162 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100163#define PSA_ECC_CURVE_SECP192R1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100164 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100165#define PSA_ECC_CURVE_SECP224R1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100166 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100167#define PSA_ECC_CURVE_SECP256R1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100168 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100169#define PSA_ECC_CURVE_SECP384R1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100170 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100171#define PSA_ECC_CURVE_SECP521R1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100172 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100173#define PSA_ECC_CURVE_SECP160R2 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100174 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R2 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100175#define PSA_ECC_CURVE_SECT163K1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100176 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100177#define PSA_ECC_CURVE_SECT233K1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100178 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100179#define PSA_ECC_CURVE_SECT239K1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100180 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100181#define PSA_ECC_CURVE_SECT283K1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100182 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100183#define PSA_ECC_CURVE_SECT409K1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100184 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100185#define PSA_ECC_CURVE_SECT571K1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100186 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100187#define PSA_ECC_CURVE_SECT163R1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100188 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100189#define PSA_ECC_CURVE_SECT193R1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100190 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100191#define PSA_ECC_CURVE_SECT233R1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100192 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100193#define PSA_ECC_CURVE_SECT283R1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100194 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100195#define PSA_ECC_CURVE_SECT409R1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100196 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100197#define PSA_ECC_CURVE_SECT571R1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100198 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100199#define PSA_ECC_CURVE_SECT163R2 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100200 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R2 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100201#define PSA_ECC_CURVE_SECT193R2 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100202 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R2 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100203#define PSA_ECC_CURVE_BRAINPOOL_P256R1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100204 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_BRAINPOOL_P_R1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100205#define PSA_ECC_CURVE_BRAINPOOL_P384R1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100206 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_BRAINPOOL_P_R1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100207#define PSA_ECC_CURVE_BRAINPOOL_P512R1 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100208 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_BRAINPOOL_P_R1 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100209#define PSA_ECC_CURVE_CURVE25519 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100210 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_MONTGOMERY )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100211#define PSA_ECC_CURVE_CURVE448 \
Paul Elliott8ff510a2020-06-02 17:19:28 +0100212 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_MONTGOMERY )
213
214/*
215 * Curves that changed name due to PSA specification.
216 */
217#define PSA_ECC_CURVE_SECP_K1 \
218 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_K1 )
219#define PSA_ECC_CURVE_SECP_R1 \
220 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 )
221#define PSA_ECC_CURVE_SECP_R2 \
222 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R2 )
223#define PSA_ECC_CURVE_SECT_K1 \
224 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 )
225#define PSA_ECC_CURVE_SECT_R1 \
226 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 )
227#define PSA_ECC_CURVE_SECT_R2 \
228 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R2 )
229#define PSA_ECC_CURVE_BRAINPOOL_P_R1 \
230 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_BRAINPOOL_P_R1 )
231#define PSA_ECC_CURVE_MONTGOMERY \
232 MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_MONTGOMERY )
Gilles Peskine45c29ce2019-12-03 17:56:11 +0100233
Paul Elliott75e27032020-06-03 15:17:39 +0100234/*
235 * Finite-field Diffie-Hellman families.
236 */
Gilles Peskineb87b7192019-12-04 16:24:10 +0100237#define PSA_DH_GROUP_FFDHE2048 \
Paul Elliott75e27032020-06-03 15:17:39 +0100238 MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_RFC7919 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100239#define PSA_DH_GROUP_FFDHE3072 \
Paul Elliott75e27032020-06-03 15:17:39 +0100240 MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_RFC7919 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100241#define PSA_DH_GROUP_FFDHE4096 \
Paul Elliott75e27032020-06-03 15:17:39 +0100242 MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_RFC7919 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100243#define PSA_DH_GROUP_FFDHE6144 \
Paul Elliott75e27032020-06-03 15:17:39 +0100244 MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_RFC7919 )
Gilles Peskineb87b7192019-12-04 16:24:10 +0100245#define PSA_DH_GROUP_FFDHE8192 \
Paul Elliott75e27032020-06-03 15:17:39 +0100246 MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_RFC7919 )
247
248/*
249 * Diffie-Hellman families that changed name due to PSA specification.
250 */
251#define PSA_DH_GROUP_RFC7919 \
252 MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_RFC7919 )
253#define PSA_DH_GROUP_CUSTOM \
254 MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_CUSTOM )
Gilles Peskine45c29ce2019-12-03 17:56:11 +0100255
Bence Szépkúti1de907d2020-12-07 18:20:28 +0100256/*
257 * Deprecated PSA Crypto stream cipher algorithms (PSA Crypto API <= 1.0 beta3)
258 */
259#define PSA_ALG_ARC4 \
Bence Szépkúticbe39532020-12-08 00:01:31 +0100260 MBEDTLS_DEPRECATED_CONSTANT( psa_algorithm_t, PSA_ALG_STREAM_CIPHER )
Bence Szépkúti1de907d2020-12-07 18:20:28 +0100261#define PSA_ALG_CHACHA20 \
Bence Szépkúticbe39532020-12-08 00:01:31 +0100262 MBEDTLS_DEPRECATED_CONSTANT( psa_algorithm_t, PSA_ALG_STREAM_CIPHER )
263
Bence Szépkútia63b20d2020-12-16 11:36:46 +0100264/*
265 * Renamed AEAD tag length macros (PSA Crypto API <= 1.0 beta3)
266 */
267#define PSA_ALG_AEAD_WITH_DEFAULT_TAG_LENGTH( aead_alg ) \
268 MBEDTLS_DEPRECATED_CONSTANT( psa_algorithm_t, PSA_ALG_AEAD_WITH_DEFAULT_LENGTH_TAG( aead_alg ) )
269#define PSA_ALG_AEAD_WITH_TAG_LENGTH( aead_alg, tag_length ) \
270 MBEDTLS_DEPRECATED_CONSTANT( psa_algorithm_t, PSA_ALG_AEAD_WITH_SHORTENED_TAG( aead_alg, tag_length ) )
271
Bence Szépkúti8810fd32021-03-05 14:18:33 +0100272/*
273 * Deprecated PSA AEAD output size macros (PSA Crypto API <= 1.0 beta3)
274 */
275
276/** The tag size for an AEAD algorithm, in bytes.
277 *
278 * \param alg An AEAD algorithm
279 * (\c PSA_ALG_XXX value such that
280 * #PSA_ALG_IS_AEAD(\p alg) is true).
281 *
282 * \return The tag size for the specified algorithm.
283 * If the AEAD algorithm does not have an identified
284 * tag that can be distinguished from the rest of
285 * the ciphertext, return 0.
286 * If the AEAD algorithm is not recognized, return 0.
287 */
Bence Szépkúti670df7a2021-03-08 10:52:26 +0100288#define PSA_AEAD_TAG_LENGTH_1_ARG(alg) \
289 (PSA_ALG_IS_AEAD(alg) ? \
Bence Szépkúti8810fd32021-03-05 14:18:33 +0100290 (((alg) & PSA_ALG_AEAD_TAG_LENGTH_MASK) >> PSA_AEAD_TAG_LENGTH_OFFSET) : \
291 0)
292
293/** The maximum size of the output of psa_aead_encrypt(), in bytes.
294 *
295 * If the size of the ciphertext buffer is at least this large, it is
296 * guaranteed that psa_aead_encrypt() will not fail due to an
297 * insufficient buffer size. Depending on the algorithm, the actual size of
298 * the ciphertext may be smaller.
299 *
300 * \warning This macro may evaluate its arguments multiple times or
301 * zero times, so you should not pass arguments that contain
302 * side effects.
303 *
304 * \param alg An AEAD algorithm
305 * (\c PSA_ALG_XXX value such that
306 * #PSA_ALG_IS_AEAD(\p alg) is true).
307 * \param plaintext_length Size of the plaintext in bytes.
308 *
309 * \return The AEAD ciphertext size for the specified
310 * algorithm.
311 * If the AEAD algorithm is not recognized, return 0.
312 */
Bence Szépkúti670df7a2021-03-08 10:52:26 +0100313#define PSA_AEAD_ENCRYPT_OUTPUT_SIZE_2_ARG(alg, plaintext_length) \
314 (PSA_AEAD_TAG_LENGTH_1_ARG(alg) != 0 ? \
315 (plaintext_length) + PSA_AEAD_TAG_LENGTH_1_ARG(alg) : \
Bence Szépkúti8810fd32021-03-05 14:18:33 +0100316 0)
317
318/** The maximum size of the output of psa_aead_decrypt(), in bytes.
319 *
320 * If the size of the plaintext buffer is at least this large, it is
321 * guaranteed that psa_aead_decrypt() will not fail due to an
322 * insufficient buffer size. Depending on the algorithm, the actual size of
323 * the plaintext may be smaller.
324 *
325 * \warning This macro may evaluate its arguments multiple times or
326 * zero times, so you should not pass arguments that contain
327 * side effects.
328 *
329 * \param alg An AEAD algorithm
330 * (\c PSA_ALG_XXX value such that
331 * #PSA_ALG_IS_AEAD(\p alg) is true).
332 * \param ciphertext_length Size of the plaintext in bytes.
333 *
334 * \return The AEAD ciphertext size for the specified
335 * algorithm.
336 * If the AEAD algorithm is not recognized, return 0.
337 */
Bence Szépkúti670df7a2021-03-08 10:52:26 +0100338#define PSA_AEAD_DECRYPT_OUTPUT_SIZE_2_ARG(alg, ciphertext_length) \
339 (PSA_AEAD_TAG_LENGTH_1_ARG(alg) != 0 ? \
340 (ciphertext_length) - PSA_AEAD_TAG_LENGTH_1_ARG(alg) : \
Bence Szépkúti8810fd32021-03-05 14:18:33 +0100341 0)
342
343/** A sufficient output buffer size for psa_aead_update().
344 *
345 * If the size of the output buffer is at least this large, it is
346 * guaranteed that psa_aead_update() will not fail due to an
347 * insufficient buffer size. The actual size of the output may be smaller
348 * in any given call.
349 *
350 * \warning This macro may evaluate its arguments multiple times or
351 * zero times, so you should not pass arguments that contain
352 * side effects.
353 *
354 * \param alg An AEAD algorithm
355 * (\c PSA_ALG_XXX value such that
356 * #PSA_ALG_IS_AEAD(\p alg) is true).
357 * \param input_length Size of the input in bytes.
358 *
359 * \return A sufficient output buffer size for the specified
360 * algorithm.
361 * If the AEAD algorithm is not recognized, return 0.
362 */
363/* For all the AEAD modes defined in this specification, it is possible
364 * to emit output without delay. However, hardware may not always be
365 * capable of this. So for modes based on a block cipher, allow the
366 * implementation to delay the output until it has a full block. */
Bence Szépkúti670df7a2021-03-08 10:52:26 +0100367#define PSA_AEAD_UPDATE_OUTPUT_SIZE_2_ARG(alg, input_length) \
Bence Szépkúti8810fd32021-03-05 14:18:33 +0100368 (PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER(alg) ? \
369 PSA_ROUND_UP_TO_MULTIPLE(PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE, (input_length)) : \
370 (input_length))
371
372/** A sufficient ciphertext buffer size for psa_aead_finish().
373 *
374 * If the size of the ciphertext buffer is at least this large, it is
375 * guaranteed that psa_aead_finish() will not fail due to an
376 * insufficient ciphertext buffer size. The actual size of the output may
377 * be smaller in any given call.
378 *
379 * \param alg An AEAD algorithm
380 * (\c PSA_ALG_XXX value such that
381 * #PSA_ALG_IS_AEAD(\p alg) is true).
382 *
383 * \return A sufficient ciphertext buffer size for the
384 * specified algorithm.
385 * If the AEAD algorithm is not recognized, return 0.
386 */
Bence Szépkúti670df7a2021-03-08 10:52:26 +0100387#define PSA_AEAD_FINISH_OUTPUT_SIZE_1_ARG(alg) \
Bence Szépkúti8810fd32021-03-05 14:18:33 +0100388 (PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER(alg) ? \
389 PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE : \
390 0)
391
392/** A sufficient plaintext buffer size for psa_aead_verify().
393 *
394 * If the size of the plaintext buffer is at least this large, it is
395 * guaranteed that psa_aead_verify() will not fail due to an
396 * insufficient plaintext buffer size. The actual size of the output may
397 * be smaller in any given call.
398 *
399 * \param alg An AEAD algorithm
400 * (\c PSA_ALG_XXX value such that
401 * #PSA_ALG_IS_AEAD(\p alg) is true).
402 *
403 * \return A sufficient plaintext buffer size for the
404 * specified algorithm.
405 * If the AEAD algorithm is not recognized, return 0.
406 */
Bence Szépkúti670df7a2021-03-08 10:52:26 +0100407#define PSA_AEAD_VERIFY_OUTPUT_SIZE_1_ARG(alg) \
Bence Szépkúti8810fd32021-03-05 14:18:33 +0100408 (PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER(alg) ? \
409 PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE : \
410 0)
411
Bence Szépkúticbe39532020-12-08 00:01:31 +0100412#endif /* MBEDTLS_DEPRECATED_REMOVED */
Bence Szépkúti1de907d2020-12-07 18:20:28 +0100413
Ronald Croncf56a0a2020-08-04 09:51:30 +0200414/** Open a handle to an existing persistent key.
415 *
416 * Open a handle to a persistent key. A key is persistent if it was created
417 * with a lifetime other than #PSA_KEY_LIFETIME_VOLATILE. A persistent key
418 * always has a nonzero key identifier, set with psa_set_key_id() when
419 * creating the key. Implementations may provide additional pre-provisioned
420 * keys that can be opened with psa_open_key(). Such keys have an application
421 * key identifier in the vendor range, as documented in the description of
422 * #psa_key_id_t.
423 *
424 * The application must eventually close the handle with psa_close_key() or
425 * psa_destroy_key() to release associated resources. If the application dies
426 * without calling one of these functions, the implementation should perform
427 * the equivalent of a call to psa_close_key().
428 *
429 * Some implementations permit an application to open the same key multiple
430 * times. If this is successful, each call to psa_open_key() will return a
431 * different key handle.
432 *
433 * \note This API is not part of the PSA Cryptography API Release 1.0.0
434 * specification. It was defined in the 1.0 Beta 3 version of the
435 * specification but was removed in the 1.0.0 released version. This API is
436 * kept for the time being to not break applications relying on it. It is not
437 * deprecated yet but will be in the near future.
438 *
439 * \note Applications that rely on opening a key multiple times will not be
440 * portable to implementations that only permit a single key handle to be
441 * opened. See also :ref:\`key-handles\`.
442 *
443 *
444 * \param key The persistent identifier of the key.
445 * \param[out] handle On success, a handle to the key.
446 *
447 * \retval #PSA_SUCCESS
448 * Success. The application can now use the value of `*handle`
449 * to access the key.
450 * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
451 * The implementation does not have sufficient resources to open the
452 * key. This can be due to reaching an implementation limit on the
453 * number of open keys, the number of open key handles, or available
454 * memory.
455 * \retval #PSA_ERROR_DOES_NOT_EXIST
Gilles Peskine7ef23be2021-03-08 17:19:47 +0100456 * There is no persistent key with key identifier \p key.
Ronald Croncf56a0a2020-08-04 09:51:30 +0200457 * \retval #PSA_ERROR_INVALID_ARGUMENT
Gilles Peskine7ef23be2021-03-08 17:19:47 +0100458 * \p key is not a valid persistent key identifier.
Ronald Croncf56a0a2020-08-04 09:51:30 +0200459 * \retval #PSA_ERROR_NOT_PERMITTED
460 * The specified key exists, but the application does not have the
461 * permission to access it. Note that this specification does not
462 * define any way to create such a key, but it may be possible
463 * through implementation-specific means.
464 * \retval #PSA_ERROR_COMMUNICATION_FAILURE
465 * \retval #PSA_ERROR_CORRUPTION_DETECTED
466 * \retval #PSA_ERROR_STORAGE_FAILURE
gabor-mezei-arm452b0a32020-11-09 17:42:55 +0100467 * \retval #PSA_ERROR_DATA_INVALID
468 * \retval #PSA_ERROR_DATA_CORRUPT
Ronald Croncf56a0a2020-08-04 09:51:30 +0200469 * \retval #PSA_ERROR_BAD_STATE
470 * The library has not been previously initialized by psa_crypto_init().
471 * It is implementation-dependent whether a failure to initialize
472 * results in this error code.
473 */
474psa_status_t psa_open_key( mbedtls_svc_key_id_t key,
475 psa_key_handle_t *handle );
476
477/** Close a key handle.
478 *
479 * If the handle designates a volatile key, this will destroy the key material
480 * and free all associated resources, just like psa_destroy_key().
481 *
482 * If this is the last open handle to a persistent key, then closing the handle
483 * will free all resources associated with the key in volatile memory. The key
484 * data in persistent storage is not affected and can be opened again later
485 * with a call to psa_open_key().
486 *
487 * Closing the key handle makes the handle invalid, and the key handle
488 * must not be used again by the application.
489 *
490 * \note This API is not part of the PSA Cryptography API Release 1.0.0
491 * specification. It was defined in the 1.0 Beta 3 version of the
492 * specification but was removed in the 1.0.0 released version. This API is
493 * kept for the time being to not break applications relying on it. It is not
494 * deprecated yet but will be in the near future.
495 *
496 * \note If the key handle was used to set up an active
497 * :ref:\`multipart operation <multipart-operations>\`, then closing the
498 * key handle can cause the multipart operation to fail. Applications should
499 * maintain the key handle until after the multipart operation has finished.
500 *
501 * \param handle The key handle to close.
502 * If this is \c 0, do nothing and return \c PSA_SUCCESS.
503 *
504 * \retval #PSA_SUCCESS
505 * \p handle was a valid handle or \c 0. It is now closed.
506 * \retval #PSA_ERROR_INVALID_HANDLE
507 * \p handle is not a valid handle nor \c 0.
508 * \retval #PSA_ERROR_COMMUNICATION_FAILURE
509 * \retval #PSA_ERROR_CORRUPTION_DETECTED
510 * \retval #PSA_ERROR_BAD_STATE
511 * The library has not been previously initialized by psa_crypto_init().
512 * It is implementation-dependent whether a failure to initialize
513 * results in this error code.
514 */
515psa_status_t psa_close_key(psa_key_handle_t handle);
516
Gilles Peskine7a894f22019-11-26 16:06:46 +0100517#ifdef __cplusplus
518}
519#endif
520
521#endif /* PSA_CRYPTO_COMPAT_H */