mbed TLS v2.24.0
crypto_compat.h
Go to the documentation of this file.
1 
13 /*
14  * Copyright The Mbed TLS Contributors
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.
28  */
29 
30 #ifndef PSA_CRYPTO_COMPAT_H
31 #define PSA_CRYPTO_COMPAT_H
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
38 
39 /*
40  * Mechanism for declaring deprecated values
41  */
42 #if defined(MBEDTLS_DEPRECATED_WARNING) && !defined(MBEDTLS_PSA_DEPRECATED)
43 #define MBEDTLS_PSA_DEPRECATED __attribute__((deprecated))
44 #else
45 #define MBEDTLS_PSA_DEPRECATED
46 #endif
47 
55 
56 #define PSA_KEY_TYPE_GET_CURVE PSA_KEY_TYPE_ECC_GET_FAMILY
57 #define PSA_KEY_TYPE_GET_GROUP PSA_KEY_TYPE_DH_GET_FAMILY
58 
59 #define MBEDTLS_DEPRECATED_CONSTANT( type, value ) \
60  ( (mbedtls_deprecated_##type) ( value ) )
61 
62 /*
63  * Deprecated PSA Crypto error code definitions (PSA Crypto API <= 1.0 beta2)
64  */
65 #define PSA_ERROR_UNKNOWN_ERROR \
66  MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_GENERIC_ERROR )
67 #define PSA_ERROR_OCCUPIED_SLOT \
68  MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_ALREADY_EXISTS )
69 #define PSA_ERROR_EMPTY_SLOT \
70  MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_DOES_NOT_EXIST )
71 #define PSA_ERROR_INSUFFICIENT_CAPACITY \
72  MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_INSUFFICIENT_DATA )
73 #define PSA_ERROR_TAMPERING_DETECTED \
74  MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_CORRUPTION_DETECTED )
75 
76 /*
77  * Deprecated PSA Crypto numerical encodings (PSA Crypto API <= 1.0 beta3)
78  */
79 #define PSA_KEY_USAGE_SIGN \
80  MBEDTLS_DEPRECATED_CONSTANT( psa_key_usage_t, PSA_KEY_USAGE_SIGN_HASH )
81 #define PSA_KEY_USAGE_VERIFY \
82  MBEDTLS_DEPRECATED_CONSTANT( psa_key_usage_t, PSA_KEY_USAGE_VERIFY_HASH )
83 
84 /*
85  * Deprecated PSA Crypto size calculation macros (PSA Crypto API <= 1.0 beta3)
86  */
87 #define PSA_ASYMMETRIC_SIGNATURE_MAX_SIZE \
88  MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_SIGNATURE_MAX_SIZE )
89 #define PSA_ASYMMETRIC_SIGN_OUTPUT_SIZE( key_type, key_bits, alg ) \
90  MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_SIGN_OUTPUT_SIZE( key_type, key_bits, alg ) )
91 
92 /*
93  * Deprecated PSA Crypto function names (PSA Crypto API <= 1.0 beta3)
94  */
96  psa_algorithm_t alg,
97  const uint8_t *hash,
98  size_t hash_length,
99  uint8_t *signature,
100  size_t signature_size,
101  size_t *signature_length )
102 {
103  return psa_sign_hash( key, alg, hash, hash_length, signature, signature_size, signature_length );
104 }
105 
107  psa_algorithm_t alg,
108  const uint8_t *hash,
109  size_t hash_length,
110  const uint8_t *signature,
111  size_t signature_length )
112 {
113  return psa_verify_hash( key, alg, hash, hash_length, signature, signature_length );
114 }
115 
116 
117 
118 #endif /* MBEDTLS_DEPRECATED_REMOVED */
119 
120 /*
121  * Size-specific elliptic curve families.
122  */
123 #define PSA_ECC_CURVE_SECP160K1 \
124  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_K1 )
125 #define PSA_ECC_CURVE_SECP192K1 \
126  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_K1 )
127 #define PSA_ECC_CURVE_SECP224K1 \
128  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_K1 )
129 #define PSA_ECC_CURVE_SECP256K1 \
130  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_K1 )
131 #define PSA_ECC_CURVE_SECP160R1 \
132  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 )
133 #define PSA_ECC_CURVE_SECP192R1 \
134  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 )
135 #define PSA_ECC_CURVE_SECP224R1 \
136  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 )
137 #define PSA_ECC_CURVE_SECP256R1 \
138  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 )
139 #define PSA_ECC_CURVE_SECP384R1 \
140  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 )
141 #define PSA_ECC_CURVE_SECP521R1 \
142  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 )
143 #define PSA_ECC_CURVE_SECP160R2 \
144  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R2 )
145 #define PSA_ECC_CURVE_SECT163K1 \
146  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 )
147 #define PSA_ECC_CURVE_SECT233K1 \
148  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 )
149 #define PSA_ECC_CURVE_SECT239K1 \
150  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 )
151 #define PSA_ECC_CURVE_SECT283K1 \
152  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 )
153 #define PSA_ECC_CURVE_SECT409K1 \
154  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 )
155 #define PSA_ECC_CURVE_SECT571K1 \
156  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 )
157 #define PSA_ECC_CURVE_SECT163R1 \
158  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 )
159 #define PSA_ECC_CURVE_SECT193R1 \
160  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 )
161 #define PSA_ECC_CURVE_SECT233R1 \
162  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 )
163 #define PSA_ECC_CURVE_SECT283R1 \
164  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 )
165 #define PSA_ECC_CURVE_SECT409R1 \
166  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 )
167 #define PSA_ECC_CURVE_SECT571R1 \
168  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 )
169 #define PSA_ECC_CURVE_SECT163R2 \
170  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R2 )
171 #define PSA_ECC_CURVE_SECT193R2 \
172  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R2 )
173 #define PSA_ECC_CURVE_BRAINPOOL_P256R1 \
174  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_BRAINPOOL_P_R1 )
175 #define PSA_ECC_CURVE_BRAINPOOL_P384R1 \
176  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_BRAINPOOL_P_R1 )
177 #define PSA_ECC_CURVE_BRAINPOOL_P512R1 \
178  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_BRAINPOOL_P_R1 )
179 #define PSA_ECC_CURVE_CURVE25519 \
180  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_MONTGOMERY )
181 #define PSA_ECC_CURVE_CURVE448 \
182  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_MONTGOMERY )
183 
184 /*
185  * Curves that changed name due to PSA specification.
186  */
187 #define PSA_ECC_CURVE_SECP_K1 \
188  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_K1 )
189 #define PSA_ECC_CURVE_SECP_R1 \
190  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R1 )
191 #define PSA_ECC_CURVE_SECP_R2 \
192  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECP_R2 )
193 #define PSA_ECC_CURVE_SECT_K1 \
194  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_K1 )
195 #define PSA_ECC_CURVE_SECT_R1 \
196  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R1 )
197 #define PSA_ECC_CURVE_SECT_R2 \
198  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_SECT_R2 )
199 #define PSA_ECC_CURVE_BRAINPOOL_P_R1 \
200  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_BRAINPOOL_P_R1 )
201 #define PSA_ECC_CURVE_MONTGOMERY \
202  MBEDTLS_DEPRECATED_CONSTANT( psa_ecc_family_t, PSA_ECC_FAMILY_MONTGOMERY )
203 
204 /*
205  * Finite-field Diffie-Hellman families.
206  */
207 #define PSA_DH_GROUP_FFDHE2048 \
208  MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_RFC7919 )
209 #define PSA_DH_GROUP_FFDHE3072 \
210  MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_RFC7919 )
211 #define PSA_DH_GROUP_FFDHE4096 \
212  MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_RFC7919 )
213 #define PSA_DH_GROUP_FFDHE6144 \
214  MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_RFC7919 )
215 #define PSA_DH_GROUP_FFDHE8192 \
216  MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_RFC7919 )
217 
218 /*
219  * Diffie-Hellman families that changed name due to PSA specification.
220  */
221 #define PSA_DH_GROUP_RFC7919 \
222  MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_RFC7919 )
223 #define PSA_DH_GROUP_CUSTOM \
224  MBEDTLS_DEPRECATED_CONSTANT( psa_dh_family_t, PSA_DH_FAMILY_CUSTOM )
225 
226 #ifdef __cplusplus
227 }
228 #endif
229 
230 #endif /* PSA_CRYPTO_COMPAT_H */
MBEDTLS_PSA_DEPRECATED psa_ecc_family_t psa_ecc_curve_t
Definition: crypto_compat.h:53
psa_status_t psa_sign_hash(psa_key_handle_t handle, psa_algorithm_t alg, const uint8_t *hash, size_t hash_length, uint8_t *signature, size_t signature_size, size_t *signature_length)
Sign a hash or short message with a private key.
psa_status_t psa_verify_hash(psa_key_handle_t handle, psa_algorithm_t alg, const uint8_t *hash, size_t hash_length, const uint8_t *signature, size_t signature_length)
Verify the signature a hash or short message using a public key.
uint8_t psa_dh_family_t
Definition: crypto_types.h:86
MBEDTLS_PSA_DEPRECATED psa_dh_family_t mbedtls_deprecated_psa_dh_family_t
Definition: crypto_compat.h:52
MBEDTLS_PSA_DEPRECATED psa_ecc_family_t mbedtls_deprecated_psa_ecc_family_t
Definition: crypto_compat.h:51
static MBEDTLS_PSA_DEPRECATED psa_status_t psa_asymmetric_verify(psa_key_handle_t key, psa_algorithm_t alg, const uint8_t *hash, size_t hash_length, const uint8_t *signature, size_t signature_length)
uint16_t psa_key_handle_t
uint32_t psa_algorithm_t
Encoding of a cryptographic algorithm.
Definition: crypto_types.h:96
#define MBEDTLS_PSA_DEPRECATED
Definition: crypto_compat.h:45
uint32_t psa_key_usage_t
Encoding of permitted usage on a key.
Definition: crypto_types.h:246
MBEDTLS_PSA_DEPRECATED psa_dh_family_t psa_dh_group_t
Definition: crypto_compat.h:54
MBEDTLS_PSA_DEPRECATED psa_key_usage_t mbedtls_deprecated_psa_key_usage_t
Definition: crypto_compat.h:50
static MBEDTLS_PSA_DEPRECATED psa_status_t psa_asymmetric_sign(psa_key_handle_t key, psa_algorithm_t alg, const uint8_t *hash, size_t hash_length, uint8_t *signature, size_t signature_size, size_t *signature_length)
Definition: crypto_compat.h:95
MBEDTLS_PSA_DEPRECATED psa_status_t mbedtls_deprecated_psa_status_t
Definition: crypto_compat.h:49
uint8_t psa_ecc_family_t
Definition: crypto_types.h:75
int32_t psa_status_t
Function return status.
Definition: crypto_types.h:53
MBEDTLS_PSA_DEPRECATED size_t mbedtls_deprecated_size_t
Definition: crypto_compat.h:48