Gilles Peskine | 7a894f2 | 2019-11-26 16:06:46 +0100 | [diff] [blame] | 1 | /** |
| 2 | * \file psa/crypto_compat.h |
| 3 | * |
| 4 | * \brief PSA cryptography module: Backward compatibility aliases |
| 5 | * |
Gilles Peskine | 0168f2f | 2019-11-29 12:22:32 +0100 | [diff] [blame] | 6 | * 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 Peskine | 7a894f2 | 2019-11-26 16:06:46 +0100 | [diff] [blame] | 10 | * \note This file may not be included directly. Applications must |
| 11 | * include psa/crypto.h. |
| 12 | */ |
| 13 | /* |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 14 | * Copyright The Mbed TLS Contributors |
Gilles Peskine | 7a894f2 | 2019-11-26 16:06:46 +0100 | [diff] [blame] | 15 | * 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 Peskine | 7a894f2 | 2019-11-26 16:06:46 +0100 | [diff] [blame] | 28 | */ |
| 29 | |
| 30 | #ifndef PSA_CRYPTO_COMPAT_H |
| 31 | #define PSA_CRYPTO_COMPAT_H |
| 32 | |
Gilles Peskine | 7a894f2 | 2019-11-26 16:06:46 +0100 | [diff] [blame] | 33 | #ifdef __cplusplus |
| 34 | extern "C" { |
| 35 | #endif |
| 36 | |
Ronald Cron | cf56a0a | 2020-08-04 09:51:30 +0200 | [diff] [blame] | 37 | /* |
Ronald Cron | 1d12d87 | 2020-11-18 17:21:22 +0100 | [diff] [blame] | 38 | * To support both openless APIs and psa_open_key() temporarily, define |
Ronald Cron | cf56a0a | 2020-08-04 09:51:30 +0200 | [diff] [blame] | 39 | * 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 | */ |
| 43 | typedef mbedtls_svc_key_id_t psa_key_handle_t; |
| 44 | |
| 45 | #define PSA_KEY_HANDLE_INIT MBEDTLS_SVC_KEY_ID_INIT |
| 46 | |
Tom Cosgrove | 5205c97 | 2022-07-28 06:12:08 +0100 | [diff] [blame] | 47 | /** Check whether a handle is null. |
Ronald Cron | cf56a0a | 2020-08-04 09:51:30 +0200 | [diff] [blame] | 48 | * |
| 49 | * \param handle Handle |
| 50 | * |
| 51 | * \return Non-zero if the handle is null, zero otherwise. |
| 52 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 53 | static inline int psa_key_handle_is_null(psa_key_handle_t handle) |
Ronald Cron | cf56a0a | 2020-08-04 09:51:30 +0200 | [diff] [blame] | 54 | { |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 55 | return mbedtls_svc_key_id_is_null(handle); |
Ronald Cron | cf56a0a | 2020-08-04 09:51:30 +0200 | [diff] [blame] | 56 | } |
| 57 | |
Gilles Peskine | 7b0ab6d | 2019-11-26 16:32:12 +0100 | [diff] [blame] | 58 | #if !defined(MBEDTLS_DEPRECATED_REMOVED) |
| 59 | |
Gilles Peskine | 0168f2f | 2019-11-29 12:22:32 +0100 | [diff] [blame] | 60 | /* |
| 61 | * Mechanism for declaring deprecated values |
| 62 | */ |
Gilles Peskine | 7b0ab6d | 2019-11-26 16:32:12 +0100 | [diff] [blame] | 63 | #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 Peskine | 4151094 | 2019-11-26 16:10:58 +0100 | [diff] [blame] | 69 | typedef MBEDTLS_PSA_DEPRECATED size_t mbedtls_deprecated_size_t; |
Gilles Peskine | 7b0ab6d | 2019-11-26 16:32:12 +0100 | [diff] [blame] | 70 | typedef MBEDTLS_PSA_DEPRECATED psa_status_t mbedtls_deprecated_psa_status_t; |
Gilles Peskine | 4151094 | 2019-11-26 16:10:58 +0100 | [diff] [blame] | 71 | typedef MBEDTLS_PSA_DEPRECATED psa_key_usage_t mbedtls_deprecated_psa_key_usage_t; |
Paul Elliott | 8ff510a | 2020-06-02 17:19:28 +0100 | [diff] [blame] | 72 | typedef MBEDTLS_PSA_DEPRECATED psa_ecc_family_t mbedtls_deprecated_psa_ecc_family_t; |
Paul Elliott | 75e2703 | 2020-06-03 15:17:39 +0100 | [diff] [blame] | 73 | typedef MBEDTLS_PSA_DEPRECATED psa_dh_family_t mbedtls_deprecated_psa_dh_family_t; |
Paul Elliott | 8ff510a | 2020-06-02 17:19:28 +0100 | [diff] [blame] | 74 | typedef MBEDTLS_PSA_DEPRECATED psa_ecc_family_t psa_ecc_curve_t; |
Paul Elliott | 75e2703 | 2020-06-03 15:17:39 +0100 | [diff] [blame] | 75 | typedef MBEDTLS_PSA_DEPRECATED psa_dh_family_t psa_dh_group_t; |
Bence Szépkúti | cbe3953 | 2020-12-08 00:01:31 +0100 | [diff] [blame] | 76 | typedef MBEDTLS_PSA_DEPRECATED psa_algorithm_t mbedtls_deprecated_psa_algorithm_t; |
Paul Elliott | 8ff510a | 2020-06-02 17:19:28 +0100 | [diff] [blame] | 77 | |
| 78 | #define PSA_KEY_TYPE_GET_CURVE PSA_KEY_TYPE_ECC_GET_FAMILY |
Paul Elliott | 75e2703 | 2020-06-03 15:17:39 +0100 | [diff] [blame] | 79 | #define PSA_KEY_TYPE_GET_GROUP PSA_KEY_TYPE_DH_GET_FAMILY |
Gilles Peskine | 7b0ab6d | 2019-11-26 16:32:12 +0100 | [diff] [blame] | 80 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 81 | #define MBEDTLS_DEPRECATED_CONSTANT(type, value) \ |
| 82 | ((mbedtls_deprecated_##type) (value)) |
Gilles Peskine | 7b0ab6d | 2019-11-26 16:32:12 +0100 | [diff] [blame] | 83 | |
Gilles Peskine | 7a894f2 | 2019-11-26 16:06:46 +0100 | [diff] [blame] | 84 | /* |
Gilles Peskine | 0168f2f | 2019-11-29 12:22:32 +0100 | [diff] [blame] | 85 | * Deprecated PSA Crypto error code definitions (PSA Crypto API <= 1.0 beta2) |
Gilles Peskine | 7a894f2 | 2019-11-26 16:06:46 +0100 | [diff] [blame] | 86 | */ |
Gilles Peskine | 7a894f2 | 2019-11-26 16:06:46 +0100 | [diff] [blame] | 87 | #define PSA_ERROR_UNKNOWN_ERROR \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 88 | MBEDTLS_DEPRECATED_CONSTANT(psa_status_t, PSA_ERROR_GENERIC_ERROR) |
Gilles Peskine | 7a894f2 | 2019-11-26 16:06:46 +0100 | [diff] [blame] | 89 | #define PSA_ERROR_OCCUPIED_SLOT \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 90 | MBEDTLS_DEPRECATED_CONSTANT(psa_status_t, PSA_ERROR_ALREADY_EXISTS) |
Gilles Peskine | 7a894f2 | 2019-11-26 16:06:46 +0100 | [diff] [blame] | 91 | #define PSA_ERROR_EMPTY_SLOT \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 92 | MBEDTLS_DEPRECATED_CONSTANT(psa_status_t, PSA_ERROR_DOES_NOT_EXIST) |
Gilles Peskine | 7a894f2 | 2019-11-26 16:06:46 +0100 | [diff] [blame] | 93 | #define PSA_ERROR_INSUFFICIENT_CAPACITY \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 94 | MBEDTLS_DEPRECATED_CONSTANT(psa_status_t, PSA_ERROR_INSUFFICIENT_DATA) |
Gilles Peskine | 7a894f2 | 2019-11-26 16:06:46 +0100 | [diff] [blame] | 95 | #define PSA_ERROR_TAMPERING_DETECTED \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 96 | MBEDTLS_DEPRECATED_CONSTANT(psa_status_t, PSA_ERROR_CORRUPTION_DETECTED) |
Gilles Peskine | 7b0ab6d | 2019-11-26 16:32:12 +0100 | [diff] [blame] | 97 | |
Gilles Peskine | 4151094 | 2019-11-26 16:10:58 +0100 | [diff] [blame] | 98 | /* |
Gilles Peskine | 0168f2f | 2019-11-29 12:22:32 +0100 | [diff] [blame] | 99 | * Deprecated PSA Crypto numerical encodings (PSA Crypto API <= 1.0 beta3) |
Gilles Peskine | 4151094 | 2019-11-26 16:10:58 +0100 | [diff] [blame] | 100 | */ |
| 101 | #define PSA_KEY_USAGE_SIGN \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 102 | MBEDTLS_DEPRECATED_CONSTANT(psa_key_usage_t, PSA_KEY_USAGE_SIGN_HASH) |
Gilles Peskine | 4151094 | 2019-11-26 16:10:58 +0100 | [diff] [blame] | 103 | #define PSA_KEY_USAGE_VERIFY \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 104 | MBEDTLS_DEPRECATED_CONSTANT(psa_key_usage_t, PSA_KEY_USAGE_VERIFY_HASH) |
Gilles Peskine | 4151094 | 2019-11-26 16:10:58 +0100 | [diff] [blame] | 105 | |
| 106 | /* |
Gilles Peskine | 0168f2f | 2019-11-29 12:22:32 +0100 | [diff] [blame] | 107 | * Deprecated PSA Crypto size calculation macros (PSA Crypto API <= 1.0 beta3) |
Gilles Peskine | 4151094 | 2019-11-26 16:10:58 +0100 | [diff] [blame] | 108 | */ |
| 109 | #define PSA_ASYMMETRIC_SIGNATURE_MAX_SIZE \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 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)) |
| 113 | #define PSA_KEY_EXPORT_MAX_SIZE(key_type, key_bits) \ |
| 114 | MBEDTLS_DEPRECATED_CONSTANT(size_t, PSA_EXPORT_KEY_OUTPUT_SIZE(key_type, key_bits)) |
| 115 | #define PSA_BLOCK_CIPHER_BLOCK_SIZE(type) \ |
| 116 | MBEDTLS_DEPRECATED_CONSTANT(size_t, PSA_BLOCK_CIPHER_BLOCK_LENGTH(type)) |
gabor-mezei-arm | cbcec21 | 2020-12-18 14:23:51 +0100 | [diff] [blame] | 117 | #define PSA_MAX_BLOCK_CIPHER_BLOCK_SIZE \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 118 | MBEDTLS_DEPRECATED_CONSTANT(size_t, PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE) |
| 119 | #define PSA_HASH_SIZE(alg) \ |
| 120 | MBEDTLS_DEPRECATED_CONSTANT(size_t, PSA_HASH_LENGTH(alg)) |
| 121 | #define PSA_MAC_FINAL_SIZE(key_type, key_bits, alg) \ |
| 122 | MBEDTLS_DEPRECATED_CONSTANT(size_t, PSA_MAC_LENGTH(key_type, key_bits, alg)) |
gabor-mezei-arm | cbcec21 | 2020-12-18 14:23:51 +0100 | [diff] [blame] | 123 | #define PSA_ALG_TLS12_PSK_TO_MS_MAX_PSK_LEN \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 124 | MBEDTLS_DEPRECATED_CONSTANT(size_t, PSA_TLS12_PSK_TO_MS_PSK_MAX_SIZE) |
gabor-mezei-arm | d25ea72 | 2021-01-21 12:20:08 +0100 | [diff] [blame] | 125 | |
Gilles Peskine | 4151094 | 2019-11-26 16:10:58 +0100 | [diff] [blame] | 126 | /* |
Gilles Peskine | 0168f2f | 2019-11-29 12:22:32 +0100 | [diff] [blame] | 127 | * Deprecated PSA Crypto function names (PSA Crypto API <= 1.0 beta3) |
Gilles Peskine | 4151094 | 2019-11-26 16:10:58 +0100 | [diff] [blame] | 128 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 129 | MBEDTLS_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) |
Soby Mathew | 0a4270d | 2020-02-10 15:20:39 +0000 | [diff] [blame] | 136 | { |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 137 | return psa_sign_hash(key, alg, hash, hash_length, signature, signature_size, signature_length); |
Soby Mathew | 0a4270d | 2020-02-10 15:20:39 +0000 | [diff] [blame] | 138 | } |
| 139 | |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 140 | MBEDTLS_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) |
Soby Mathew | 0a4270d | 2020-02-10 15:20:39 +0000 | [diff] [blame] | 146 | { |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 147 | return psa_verify_hash(key, alg, hash, hash_length, signature, signature_length); |
Soby Mathew | 0a4270d | 2020-02-10 15:20:39 +0000 | [diff] [blame] | 148 | } |
| 149 | |
Gilles Peskine | 45c29ce | 2019-12-03 17:56:11 +0100 | [diff] [blame] | 150 | /* |
Paul Elliott | 75e2703 | 2020-06-03 15:17:39 +0100 | [diff] [blame] | 151 | * Size-specific elliptic curve families. |
Gilles Peskine | 45c29ce | 2019-12-03 17:56:11 +0100 | [diff] [blame] | 152 | */ |
Gilles Peskine | b87b719 | 2019-12-04 16:24:10 +0100 | [diff] [blame] | 153 | #define PSA_ECC_CURVE_SECP160K1 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 154 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_SECP_K1) |
Gilles Peskine | b87b719 | 2019-12-04 16:24:10 +0100 | [diff] [blame] | 155 | #define PSA_ECC_CURVE_SECP192K1 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 156 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_SECP_K1) |
Gilles Peskine | b87b719 | 2019-12-04 16:24:10 +0100 | [diff] [blame] | 157 | #define PSA_ECC_CURVE_SECP224K1 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 158 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_SECP_K1) |
Gilles Peskine | b87b719 | 2019-12-04 16:24:10 +0100 | [diff] [blame] | 159 | #define PSA_ECC_CURVE_SECP256K1 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 160 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_SECP_K1) |
Gilles Peskine | b87b719 | 2019-12-04 16:24:10 +0100 | [diff] [blame] | 161 | #define PSA_ECC_CURVE_SECP160R1 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 162 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1) |
Gilles Peskine | b87b719 | 2019-12-04 16:24:10 +0100 | [diff] [blame] | 163 | #define PSA_ECC_CURVE_SECP192R1 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 164 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1) |
Gilles Peskine | b87b719 | 2019-12-04 16:24:10 +0100 | [diff] [blame] | 165 | #define PSA_ECC_CURVE_SECP224R1 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 166 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1) |
Gilles Peskine | b87b719 | 2019-12-04 16:24:10 +0100 | [diff] [blame] | 167 | #define PSA_ECC_CURVE_SECP256R1 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 168 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1) |
Gilles Peskine | b87b719 | 2019-12-04 16:24:10 +0100 | [diff] [blame] | 169 | #define PSA_ECC_CURVE_SECP384R1 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 170 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1) |
Gilles Peskine | b87b719 | 2019-12-04 16:24:10 +0100 | [diff] [blame] | 171 | #define PSA_ECC_CURVE_SECP521R1 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 172 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1) |
Gilles Peskine | b87b719 | 2019-12-04 16:24:10 +0100 | [diff] [blame] | 173 | #define PSA_ECC_CURVE_SECP160R2 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 174 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R2) |
Gilles Peskine | b87b719 | 2019-12-04 16:24:10 +0100 | [diff] [blame] | 175 | #define PSA_ECC_CURVE_SECT163K1 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 176 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1) |
Gilles Peskine | b87b719 | 2019-12-04 16:24:10 +0100 | [diff] [blame] | 177 | #define PSA_ECC_CURVE_SECT233K1 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 178 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1) |
Gilles Peskine | b87b719 | 2019-12-04 16:24:10 +0100 | [diff] [blame] | 179 | #define PSA_ECC_CURVE_SECT239K1 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 180 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1) |
Gilles Peskine | b87b719 | 2019-12-04 16:24:10 +0100 | [diff] [blame] | 181 | #define PSA_ECC_CURVE_SECT283K1 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 182 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1) |
Gilles Peskine | b87b719 | 2019-12-04 16:24:10 +0100 | [diff] [blame] | 183 | #define PSA_ECC_CURVE_SECT409K1 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 184 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1) |
Gilles Peskine | b87b719 | 2019-12-04 16:24:10 +0100 | [diff] [blame] | 185 | #define PSA_ECC_CURVE_SECT571K1 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 186 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1) |
Gilles Peskine | b87b719 | 2019-12-04 16:24:10 +0100 | [diff] [blame] | 187 | #define PSA_ECC_CURVE_SECT163R1 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 188 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1) |
Gilles Peskine | b87b719 | 2019-12-04 16:24:10 +0100 | [diff] [blame] | 189 | #define PSA_ECC_CURVE_SECT193R1 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 190 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1) |
Gilles Peskine | b87b719 | 2019-12-04 16:24:10 +0100 | [diff] [blame] | 191 | #define PSA_ECC_CURVE_SECT233R1 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 192 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1) |
Gilles Peskine | b87b719 | 2019-12-04 16:24:10 +0100 | [diff] [blame] | 193 | #define PSA_ECC_CURVE_SECT283R1 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 194 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1) |
Gilles Peskine | b87b719 | 2019-12-04 16:24:10 +0100 | [diff] [blame] | 195 | #define PSA_ECC_CURVE_SECT409R1 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 196 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1) |
Gilles Peskine | b87b719 | 2019-12-04 16:24:10 +0100 | [diff] [blame] | 197 | #define PSA_ECC_CURVE_SECT571R1 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 198 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1) |
Gilles Peskine | b87b719 | 2019-12-04 16:24:10 +0100 | [diff] [blame] | 199 | #define PSA_ECC_CURVE_SECT163R2 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 200 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R2) |
Gilles Peskine | b87b719 | 2019-12-04 16:24:10 +0100 | [diff] [blame] | 201 | #define PSA_ECC_CURVE_SECT193R2 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 202 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R2) |
Gilles Peskine | b87b719 | 2019-12-04 16:24:10 +0100 | [diff] [blame] | 203 | #define PSA_ECC_CURVE_BRAINPOOL_P256R1 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 204 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_BRAINPOOL_P_R1) |
Gilles Peskine | b87b719 | 2019-12-04 16:24:10 +0100 | [diff] [blame] | 205 | #define PSA_ECC_CURVE_BRAINPOOL_P384R1 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 206 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_BRAINPOOL_P_R1) |
Gilles Peskine | b87b719 | 2019-12-04 16:24:10 +0100 | [diff] [blame] | 207 | #define PSA_ECC_CURVE_BRAINPOOL_P512R1 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 208 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_BRAINPOOL_P_R1) |
Gilles Peskine | b87b719 | 2019-12-04 16:24:10 +0100 | [diff] [blame] | 209 | #define PSA_ECC_CURVE_CURVE25519 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 210 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_MONTGOMERY) |
Gilles Peskine | b87b719 | 2019-12-04 16:24:10 +0100 | [diff] [blame] | 211 | #define PSA_ECC_CURVE_CURVE448 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 212 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_MONTGOMERY) |
Paul Elliott | 8ff510a | 2020-06-02 17:19:28 +0100 | [diff] [blame] | 213 | |
| 214 | /* |
| 215 | * Curves that changed name due to PSA specification. |
| 216 | */ |
| 217 | #define PSA_ECC_CURVE_SECP_K1 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 218 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_SECP_K1) |
Paul Elliott | 8ff510a | 2020-06-02 17:19:28 +0100 | [diff] [blame] | 219 | #define PSA_ECC_CURVE_SECP_R1 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 220 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1) |
Paul Elliott | 8ff510a | 2020-06-02 17:19:28 +0100 | [diff] [blame] | 221 | #define PSA_ECC_CURVE_SECP_R2 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 222 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R2) |
Paul Elliott | 8ff510a | 2020-06-02 17:19:28 +0100 | [diff] [blame] | 223 | #define PSA_ECC_CURVE_SECT_K1 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 224 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1) |
Paul Elliott | 8ff510a | 2020-06-02 17:19:28 +0100 | [diff] [blame] | 225 | #define PSA_ECC_CURVE_SECT_R1 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 226 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1) |
Paul Elliott | 8ff510a | 2020-06-02 17:19:28 +0100 | [diff] [blame] | 227 | #define PSA_ECC_CURVE_SECT_R2 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 228 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R2) |
Paul Elliott | 8ff510a | 2020-06-02 17:19:28 +0100 | [diff] [blame] | 229 | #define PSA_ECC_CURVE_BRAINPOOL_P_R1 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 230 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_BRAINPOOL_P_R1) |
Paul Elliott | 8ff510a | 2020-06-02 17:19:28 +0100 | [diff] [blame] | 231 | #define PSA_ECC_CURVE_MONTGOMERY \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 232 | MBEDTLS_DEPRECATED_CONSTANT(psa_ecc_family_t, PSA_ECC_FAMILY_MONTGOMERY) |
Gilles Peskine | 45c29ce | 2019-12-03 17:56:11 +0100 | [diff] [blame] | 233 | |
Paul Elliott | 75e2703 | 2020-06-03 15:17:39 +0100 | [diff] [blame] | 234 | /* |
| 235 | * Finite-field Diffie-Hellman families. |
| 236 | */ |
Gilles Peskine | b87b719 | 2019-12-04 16:24:10 +0100 | [diff] [blame] | 237 | #define PSA_DH_GROUP_FFDHE2048 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 238 | MBEDTLS_DEPRECATED_CONSTANT(psa_dh_family_t, PSA_DH_FAMILY_RFC7919) |
Gilles Peskine | b87b719 | 2019-12-04 16:24:10 +0100 | [diff] [blame] | 239 | #define PSA_DH_GROUP_FFDHE3072 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 240 | MBEDTLS_DEPRECATED_CONSTANT(psa_dh_family_t, PSA_DH_FAMILY_RFC7919) |
Gilles Peskine | b87b719 | 2019-12-04 16:24:10 +0100 | [diff] [blame] | 241 | #define PSA_DH_GROUP_FFDHE4096 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 242 | MBEDTLS_DEPRECATED_CONSTANT(psa_dh_family_t, PSA_DH_FAMILY_RFC7919) |
Gilles Peskine | b87b719 | 2019-12-04 16:24:10 +0100 | [diff] [blame] | 243 | #define PSA_DH_GROUP_FFDHE6144 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 244 | MBEDTLS_DEPRECATED_CONSTANT(psa_dh_family_t, PSA_DH_FAMILY_RFC7919) |
Gilles Peskine | b87b719 | 2019-12-04 16:24:10 +0100 | [diff] [blame] | 245 | #define PSA_DH_GROUP_FFDHE8192 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 246 | MBEDTLS_DEPRECATED_CONSTANT(psa_dh_family_t, PSA_DH_FAMILY_RFC7919) |
Paul Elliott | 75e2703 | 2020-06-03 15:17:39 +0100 | [diff] [blame] | 247 | |
| 248 | /* |
| 249 | * Diffie-Hellman families that changed name due to PSA specification. |
| 250 | */ |
| 251 | #define PSA_DH_GROUP_RFC7919 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 252 | MBEDTLS_DEPRECATED_CONSTANT(psa_dh_family_t, PSA_DH_FAMILY_RFC7919) |
Paul Elliott | 75e2703 | 2020-06-03 15:17:39 +0100 | [diff] [blame] | 253 | #define PSA_DH_GROUP_CUSTOM \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 254 | MBEDTLS_DEPRECATED_CONSTANT(psa_dh_family_t, PSA_DH_FAMILY_CUSTOM) |
Gilles Peskine | 45c29ce | 2019-12-03 17:56:11 +0100 | [diff] [blame] | 255 | |
Bence Szépkúti | 1de907d | 2020-12-07 18:20:28 +0100 | [diff] [blame] | 256 | /* |
| 257 | * Deprecated PSA Crypto stream cipher algorithms (PSA Crypto API <= 1.0 beta3) |
| 258 | */ |
| 259 | #define PSA_ALG_ARC4 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 260 | MBEDTLS_DEPRECATED_CONSTANT(psa_algorithm_t, PSA_ALG_STREAM_CIPHER) |
Bence Szépkúti | 1de907d | 2020-12-07 18:20:28 +0100 | [diff] [blame] | 261 | #define PSA_ALG_CHACHA20 \ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 262 | MBEDTLS_DEPRECATED_CONSTANT(psa_algorithm_t, PSA_ALG_STREAM_CIPHER) |
Bence Szépkúti | cbe3953 | 2020-12-08 00:01:31 +0100 | [diff] [blame] | 263 | |
Bence Szépkúti | a63b20d | 2020-12-16 11:36:46 +0100 | [diff] [blame] | 264 | /* |
| 265 | * Renamed AEAD tag length macros (PSA Crypto API <= 1.0 beta3) |
| 266 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 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, \ |
| 271 | PSA_ALG_AEAD_WITH_SHORTENED_TAG(aead_alg, tag_length)) |
Bence Szépkúti | a63b20d | 2020-12-16 11:36:46 +0100 | [diff] [blame] | 272 | |
Bence Szépkúti | 8810fd3 | 2021-03-05 14:18:33 +0100 | [diff] [blame] | 273 | /* |
| 274 | * Deprecated PSA AEAD output size macros (PSA Crypto API <= 1.0 beta3) |
| 275 | */ |
| 276 | |
| 277 | /** The tag size for an AEAD algorithm, in bytes. |
| 278 | * |
| 279 | * \param alg An AEAD algorithm |
| 280 | * (\c PSA_ALG_XXX value such that |
| 281 | * #PSA_ALG_IS_AEAD(\p alg) is true). |
| 282 | * |
| 283 | * \return The tag size for the specified algorithm. |
| 284 | * If the AEAD algorithm does not have an identified |
| 285 | * tag that can be distinguished from the rest of |
| 286 | * the ciphertext, return 0. |
| 287 | * If the AEAD algorithm is not recognized, return 0. |
| 288 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 289 | #define PSA_AEAD_TAG_LENGTH_1_ARG(alg) \ |
| 290 | MBEDTLS_DEPRECATED_CONSTANT(size_t, \ |
| 291 | PSA_ALG_IS_AEAD(alg) ? \ |
| 292 | PSA_ALG_AEAD_GET_TAG_LENGTH(alg) : \ |
| 293 | 0) |
Bence Szépkúti | 8810fd3 | 2021-03-05 14:18:33 +0100 | [diff] [blame] | 294 | |
| 295 | /** The maximum size of the output of psa_aead_encrypt(), in bytes. |
| 296 | * |
| 297 | * If the size of the ciphertext buffer is at least this large, it is |
| 298 | * guaranteed that psa_aead_encrypt() will not fail due to an |
| 299 | * insufficient buffer size. Depending on the algorithm, the actual size of |
| 300 | * the ciphertext may be smaller. |
| 301 | * |
| 302 | * \warning This macro may evaluate its arguments multiple times or |
| 303 | * zero times, so you should not pass arguments that contain |
| 304 | * side effects. |
| 305 | * |
| 306 | * \param alg An AEAD algorithm |
| 307 | * (\c PSA_ALG_XXX value such that |
| 308 | * #PSA_ALG_IS_AEAD(\p alg) is true). |
| 309 | * \param plaintext_length Size of the plaintext in bytes. |
| 310 | * |
| 311 | * \return The AEAD ciphertext size for the specified |
| 312 | * algorithm. |
| 313 | * If the AEAD algorithm is not recognized, return 0. |
| 314 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 315 | #define PSA_AEAD_ENCRYPT_OUTPUT_SIZE_2_ARG(alg, plaintext_length) \ |
| 316 | MBEDTLS_DEPRECATED_CONSTANT(size_t, \ |
| 317 | PSA_ALG_IS_AEAD(alg) ? \ |
| 318 | (plaintext_length) + PSA_ALG_AEAD_GET_TAG_LENGTH(alg) : \ |
| 319 | 0) |
Bence Szépkúti | 8810fd3 | 2021-03-05 14:18:33 +0100 | [diff] [blame] | 320 | |
| 321 | /** The maximum size of the output of psa_aead_decrypt(), in bytes. |
| 322 | * |
| 323 | * If the size of the plaintext buffer is at least this large, it is |
| 324 | * guaranteed that psa_aead_decrypt() will not fail due to an |
| 325 | * insufficient buffer size. Depending on the algorithm, the actual size of |
| 326 | * the plaintext may be smaller. |
| 327 | * |
| 328 | * \warning This macro may evaluate its arguments multiple times or |
| 329 | * zero times, so you should not pass arguments that contain |
| 330 | * side effects. |
| 331 | * |
| 332 | * \param alg An AEAD algorithm |
| 333 | * (\c PSA_ALG_XXX value such that |
| 334 | * #PSA_ALG_IS_AEAD(\p alg) is true). |
| 335 | * \param ciphertext_length Size of the plaintext in bytes. |
| 336 | * |
| 337 | * \return The AEAD ciphertext size for the specified |
| 338 | * algorithm. |
| 339 | * If the AEAD algorithm is not recognized, return 0. |
| 340 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 341 | #define PSA_AEAD_DECRYPT_OUTPUT_SIZE_2_ARG(alg, ciphertext_length) \ |
| 342 | MBEDTLS_DEPRECATED_CONSTANT(size_t, \ |
| 343 | PSA_ALG_IS_AEAD(alg) && \ |
| 344 | (ciphertext_length) > PSA_ALG_AEAD_GET_TAG_LENGTH(alg) ? \ |
| 345 | (ciphertext_length) - PSA_ALG_AEAD_GET_TAG_LENGTH(alg) : \ |
| 346 | 0) |
Bence Szépkúti | 8810fd3 | 2021-03-05 14:18:33 +0100 | [diff] [blame] | 347 | |
| 348 | /** A sufficient output buffer size for psa_aead_update(). |
| 349 | * |
| 350 | * If the size of the output buffer is at least this large, it is |
| 351 | * guaranteed that psa_aead_update() will not fail due to an |
| 352 | * insufficient buffer size. The actual size of the output may be smaller |
| 353 | * in any given call. |
| 354 | * |
| 355 | * \warning This macro may evaluate its arguments multiple times or |
| 356 | * zero times, so you should not pass arguments that contain |
| 357 | * side effects. |
| 358 | * |
| 359 | * \param alg An AEAD algorithm |
| 360 | * (\c PSA_ALG_XXX value such that |
| 361 | * #PSA_ALG_IS_AEAD(\p alg) is true). |
| 362 | * \param input_length Size of the input in bytes. |
| 363 | * |
| 364 | * \return A sufficient output buffer size for the specified |
| 365 | * algorithm. |
| 366 | * If the AEAD algorithm is not recognized, return 0. |
| 367 | */ |
| 368 | /* For all the AEAD modes defined in this specification, it is possible |
| 369 | * to emit output without delay. However, hardware may not always be |
| 370 | * capable of this. So for modes based on a block cipher, allow the |
| 371 | * implementation to delay the output until it has a full block. */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 372 | #define PSA_AEAD_UPDATE_OUTPUT_SIZE_2_ARG(alg, input_length) \ |
| 373 | MBEDTLS_DEPRECATED_CONSTANT(size_t, \ |
| 374 | PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER(alg) ? \ |
| 375 | PSA_ROUND_UP_TO_MULTIPLE(PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE, \ |
| 376 | (input_length)) : \ |
| 377 | (input_length)) |
Bence Szépkúti | 8810fd3 | 2021-03-05 14:18:33 +0100 | [diff] [blame] | 378 | |
| 379 | /** A sufficient ciphertext buffer size for psa_aead_finish(). |
| 380 | * |
| 381 | * If the size of the ciphertext buffer is at least this large, it is |
| 382 | * guaranteed that psa_aead_finish() will not fail due to an |
| 383 | * insufficient ciphertext buffer size. The actual size of the output may |
| 384 | * be smaller in any given call. |
| 385 | * |
| 386 | * \param alg An AEAD algorithm |
| 387 | * (\c PSA_ALG_XXX value such that |
| 388 | * #PSA_ALG_IS_AEAD(\p alg) is true). |
| 389 | * |
| 390 | * \return A sufficient ciphertext buffer size for the |
| 391 | * specified algorithm. |
| 392 | * If the AEAD algorithm is not recognized, return 0. |
| 393 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 394 | #define PSA_AEAD_FINISH_OUTPUT_SIZE_1_ARG(alg) \ |
| 395 | MBEDTLS_DEPRECATED_CONSTANT(size_t, \ |
| 396 | PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER(alg) ? \ |
| 397 | PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE : \ |
| 398 | 0) |
Bence Szépkúti | 8810fd3 | 2021-03-05 14:18:33 +0100 | [diff] [blame] | 399 | |
| 400 | /** A sufficient plaintext buffer size for psa_aead_verify(). |
| 401 | * |
| 402 | * If the size of the plaintext buffer is at least this large, it is |
| 403 | * guaranteed that psa_aead_verify() will not fail due to an |
| 404 | * insufficient plaintext buffer size. The actual size of the output may |
| 405 | * be smaller in any given call. |
| 406 | * |
| 407 | * \param alg An AEAD algorithm |
| 408 | * (\c PSA_ALG_XXX value such that |
| 409 | * #PSA_ALG_IS_AEAD(\p alg) is true). |
| 410 | * |
| 411 | * \return A sufficient plaintext buffer size for the |
| 412 | * specified algorithm. |
| 413 | * If the AEAD algorithm is not recognized, return 0. |
| 414 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 415 | #define PSA_AEAD_VERIFY_OUTPUT_SIZE_1_ARG(alg) \ |
| 416 | MBEDTLS_DEPRECATED_CONSTANT(size_t, \ |
| 417 | PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER(alg) ? \ |
| 418 | PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE : \ |
| 419 | 0) |
Bence Szépkúti | 8810fd3 | 2021-03-05 14:18:33 +0100 | [diff] [blame] | 420 | |
Bence Szépkúti | cbe3953 | 2020-12-08 00:01:31 +0100 | [diff] [blame] | 421 | #endif /* MBEDTLS_DEPRECATED_REMOVED */ |
Bence Szépkúti | 1de907d | 2020-12-07 18:20:28 +0100 | [diff] [blame] | 422 | |
Ronald Cron | cf56a0a | 2020-08-04 09:51:30 +0200 | [diff] [blame] | 423 | /** Open a handle to an existing persistent key. |
| 424 | * |
| 425 | * Open a handle to a persistent key. A key is persistent if it was created |
| 426 | * with a lifetime other than #PSA_KEY_LIFETIME_VOLATILE. A persistent key |
| 427 | * always has a nonzero key identifier, set with psa_set_key_id() when |
| 428 | * creating the key. Implementations may provide additional pre-provisioned |
| 429 | * keys that can be opened with psa_open_key(). Such keys have an application |
| 430 | * key identifier in the vendor range, as documented in the description of |
| 431 | * #psa_key_id_t. |
| 432 | * |
| 433 | * The application must eventually close the handle with psa_close_key() or |
| 434 | * psa_destroy_key() to release associated resources. If the application dies |
| 435 | * without calling one of these functions, the implementation should perform |
| 436 | * the equivalent of a call to psa_close_key(). |
| 437 | * |
| 438 | * Some implementations permit an application to open the same key multiple |
| 439 | * times. If this is successful, each call to psa_open_key() will return a |
| 440 | * different key handle. |
| 441 | * |
| 442 | * \note This API is not part of the PSA Cryptography API Release 1.0.0 |
| 443 | * specification. It was defined in the 1.0 Beta 3 version of the |
| 444 | * specification but was removed in the 1.0.0 released version. This API is |
| 445 | * kept for the time being to not break applications relying on it. It is not |
| 446 | * deprecated yet but will be in the near future. |
| 447 | * |
| 448 | * \note Applications that rely on opening a key multiple times will not be |
| 449 | * portable to implementations that only permit a single key handle to be |
| 450 | * opened. See also :ref:\`key-handles\`. |
| 451 | * |
| 452 | * |
| 453 | * \param key The persistent identifier of the key. |
| 454 | * \param[out] handle On success, a handle to the key. |
| 455 | * |
| 456 | * \retval #PSA_SUCCESS |
| 457 | * Success. The application can now use the value of `*handle` |
| 458 | * to access the key. |
| 459 | * \retval #PSA_ERROR_INSUFFICIENT_MEMORY |
| 460 | * The implementation does not have sufficient resources to open the |
| 461 | * key. This can be due to reaching an implementation limit on the |
| 462 | * number of open keys, the number of open key handles, or available |
| 463 | * memory. |
| 464 | * \retval #PSA_ERROR_DOES_NOT_EXIST |
Gilles Peskine | 7ef23be | 2021-03-08 17:19:47 +0100 | [diff] [blame] | 465 | * There is no persistent key with key identifier \p key. |
Ronald Cron | cf56a0a | 2020-08-04 09:51:30 +0200 | [diff] [blame] | 466 | * \retval #PSA_ERROR_INVALID_ARGUMENT |
Gilles Peskine | 7ef23be | 2021-03-08 17:19:47 +0100 | [diff] [blame] | 467 | * \p key is not a valid persistent key identifier. |
Ronald Cron | cf56a0a | 2020-08-04 09:51:30 +0200 | [diff] [blame] | 468 | * \retval #PSA_ERROR_NOT_PERMITTED |
| 469 | * The specified key exists, but the application does not have the |
| 470 | * permission to access it. Note that this specification does not |
| 471 | * define any way to create such a key, but it may be possible |
| 472 | * through implementation-specific means. |
Gilles Peskine | ec1eff3 | 2023-02-14 19:21:09 +0100 | [diff] [blame] | 473 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription |
| 474 | * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription |
| 475 | * \retval #PSA_ERROR_STORAGE_FAILURE \emptydescription |
| 476 | * \retval #PSA_ERROR_DATA_INVALID \emptydescription |
| 477 | * \retval #PSA_ERROR_DATA_CORRUPT \emptydescription |
Ronald Cron | cf56a0a | 2020-08-04 09:51:30 +0200 | [diff] [blame] | 478 | * \retval #PSA_ERROR_BAD_STATE |
| 479 | * The library has not been previously initialized by psa_crypto_init(). |
| 480 | * It is implementation-dependent whether a failure to initialize |
| 481 | * results in this error code. |
| 482 | */ |
Gilles Peskine | 1b6c09a | 2023-01-11 14:52:35 +0100 | [diff] [blame] | 483 | psa_status_t psa_open_key(mbedtls_svc_key_id_t key, |
| 484 | psa_key_handle_t *handle); |
Ronald Cron | cf56a0a | 2020-08-04 09:51:30 +0200 | [diff] [blame] | 485 | |
| 486 | /** Close a key handle. |
| 487 | * |
| 488 | * If the handle designates a volatile key, this will destroy the key material |
| 489 | * and free all associated resources, just like psa_destroy_key(). |
| 490 | * |
| 491 | * If this is the last open handle to a persistent key, then closing the handle |
| 492 | * will free all resources associated with the key in volatile memory. The key |
| 493 | * data in persistent storage is not affected and can be opened again later |
| 494 | * with a call to psa_open_key(). |
| 495 | * |
| 496 | * Closing the key handle makes the handle invalid, and the key handle |
| 497 | * must not be used again by the application. |
| 498 | * |
| 499 | * \note This API is not part of the PSA Cryptography API Release 1.0.0 |
| 500 | * specification. It was defined in the 1.0 Beta 3 version of the |
| 501 | * specification but was removed in the 1.0.0 released version. This API is |
| 502 | * kept for the time being to not break applications relying on it. It is not |
| 503 | * deprecated yet but will be in the near future. |
| 504 | * |
| 505 | * \note If the key handle was used to set up an active |
| 506 | * :ref:\`multipart operation <multipart-operations>\`, then closing the |
| 507 | * key handle can cause the multipart operation to fail. Applications should |
| 508 | * maintain the key handle until after the multipart operation has finished. |
| 509 | * |
| 510 | * \param handle The key handle to close. |
| 511 | * If this is \c 0, do nothing and return \c PSA_SUCCESS. |
| 512 | * |
| 513 | * \retval #PSA_SUCCESS |
| 514 | * \p handle was a valid handle or \c 0. It is now closed. |
| 515 | * \retval #PSA_ERROR_INVALID_HANDLE |
| 516 | * \p handle is not a valid handle nor \c 0. |
Gilles Peskine | ec1eff3 | 2023-02-14 19:21:09 +0100 | [diff] [blame] | 517 | * \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription |
| 518 | * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription |
Ronald Cron | cf56a0a | 2020-08-04 09:51:30 +0200 | [diff] [blame] | 519 | * \retval #PSA_ERROR_BAD_STATE |
| 520 | * The library has not been previously initialized by psa_crypto_init(). |
| 521 | * It is implementation-dependent whether a failure to initialize |
| 522 | * results in this error code. |
| 523 | */ |
| 524 | psa_status_t psa_close_key(psa_key_handle_t handle); |
| 525 | |
Gilles Peskine | 7a894f2 | 2019-11-26 16:06:46 +0100 | [diff] [blame] | 526 | #ifdef __cplusplus |
| 527 | } |
| 528 | #endif |
| 529 | |
| 530 | #endif /* PSA_CRYPTO_COMPAT_H */ |