blob: fb2c15028e74165d996302563e1332e14064eef6 [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/*
14 * Copyright (C) 2019, ARM Limited, All Rights Reserved
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 * This file is part of mbed TLS (https://tls.mbed.org)
30 */
31
32#ifndef PSA_CRYPTO_COMPAT_H
33#define PSA_CRYPTO_COMPAT_H
34
Gilles Peskine7a894f22019-11-26 16:06:46 +010035#ifdef __cplusplus
36extern "C" {
37#endif
38
Gilles Peskine7b0ab6d2019-11-26 16:32:12 +010039#if !defined(MBEDTLS_DEPRECATED_REMOVED)
40
Gilles Peskine0168f2f2019-11-29 12:22:32 +010041/*
42 * Mechanism for declaring deprecated values
43 */
Gilles Peskine7b0ab6d2019-11-26 16:32:12 +010044#if defined(MBEDTLS_DEPRECATED_WARNING) && !defined(MBEDTLS_PSA_DEPRECATED)
45#define MBEDTLS_PSA_DEPRECATED __attribute__((deprecated))
46#else
47#define MBEDTLS_PSA_DEPRECATED
48#endif
49
Gilles Peskine41510942019-11-26 16:10:58 +010050typedef MBEDTLS_PSA_DEPRECATED size_t mbedtls_deprecated_size_t;
Gilles Peskine7b0ab6d2019-11-26 16:32:12 +010051typedef MBEDTLS_PSA_DEPRECATED psa_status_t mbedtls_deprecated_psa_status_t;
Gilles Peskine41510942019-11-26 16:10:58 +010052typedef MBEDTLS_PSA_DEPRECATED psa_key_usage_t mbedtls_deprecated_psa_key_usage_t;
Gilles Peskine7b0ab6d2019-11-26 16:32:12 +010053
54#define MBEDTLS_DEPRECATED_CONSTANT( type, value ) \
55 ( (mbedtls_deprecated_##type) ( value ) )
56
Gilles Peskine7a894f22019-11-26 16:06:46 +010057/*
Gilles Peskine0168f2f2019-11-29 12:22:32 +010058 * Deprecated PSA Crypto error code definitions (PSA Crypto API <= 1.0 beta2)
Gilles Peskine7a894f22019-11-26 16:06:46 +010059 */
Gilles Peskine7a894f22019-11-26 16:06:46 +010060#define PSA_ERROR_UNKNOWN_ERROR \
Gilles Peskine7b0ab6d2019-11-26 16:32:12 +010061 MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_GENERIC_ERROR )
Gilles Peskine7a894f22019-11-26 16:06:46 +010062#define PSA_ERROR_OCCUPIED_SLOT \
Gilles Peskine7b0ab6d2019-11-26 16:32:12 +010063 MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_ALREADY_EXISTS )
Gilles Peskine7a894f22019-11-26 16:06:46 +010064#define PSA_ERROR_EMPTY_SLOT \
Gilles Peskine7b0ab6d2019-11-26 16:32:12 +010065 MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_DOES_NOT_EXIST )
Gilles Peskine7a894f22019-11-26 16:06:46 +010066#define PSA_ERROR_INSUFFICIENT_CAPACITY \
Gilles Peskine7b0ab6d2019-11-26 16:32:12 +010067 MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_INSUFFICIENT_DATA )
Gilles Peskine7a894f22019-11-26 16:06:46 +010068#define PSA_ERROR_TAMPERING_DETECTED \
Gilles Peskine7b0ab6d2019-11-26 16:32:12 +010069 MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_CORRUPTION_DETECTED )
70
Gilles Peskine41510942019-11-26 16:10:58 +010071/*
Gilles Peskine0168f2f2019-11-29 12:22:32 +010072 * Deprecated PSA Crypto numerical encodings (PSA Crypto API <= 1.0 beta3)
Gilles Peskine41510942019-11-26 16:10:58 +010073 */
74#define PSA_KEY_USAGE_SIGN \
75 MBEDTLS_DEPRECATED_CONSTANT( psa_key_usage_t, PSA_KEY_USAGE_SIGN_HASH )
76#define PSA_KEY_USAGE_VERIFY \
77 MBEDTLS_DEPRECATED_CONSTANT( psa_key_usage_t, PSA_KEY_USAGE_VERIFY_HASH )
78
79/*
Gilles Peskine0168f2f2019-11-29 12:22:32 +010080 * Deprecated PSA Crypto size calculation macros (PSA Crypto API <= 1.0 beta3)
Gilles Peskine41510942019-11-26 16:10:58 +010081 */
82#define PSA_ASYMMETRIC_SIGNATURE_MAX_SIZE \
83 MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_SIGNATURE_MAX_SIZE )
84#define PSA_ASYMMETRIC_SIGN_OUTPUT_SIZE( key_type, key_bits, alg ) \
85 MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_SIGN_OUTPUT_SIZE( key_type, key_bits, alg ) )
86
87/*
Gilles Peskine0168f2f2019-11-29 12:22:32 +010088 * Deprecated PSA Crypto function names (PSA Crypto API <= 1.0 beta3)
Gilles Peskine41510942019-11-26 16:10:58 +010089 */
90/* Make these macros and not wrappers so that there is no cost to
91 * applications that don't use the deprecated names.
92 *
93 * Put backslash-newline after "#define" to bypass check-names.sh which
94 * would otherwise complain about lowercase macro names.
95 */
96#define \
97 psa_asymmetric_sign( key, alg, hash, hash_length, signature, signature_size, signature_length ) \
98 ( (mbedtls_deprecated_psa_status_t) psa_sign_hash( key, alg, hash, hash_length, signature, signature_size, signature_length ) )
99#define \
100 psa_asymmetric_verify( key, alg, hash, hash_length, signature, signature_length ) \
101 ( (mbedtls_deprecated_psa_status_t) psa_verify_hash( key, alg, hash, hash_length, signature, signature_length ) )
102
Gilles Peskine7b0ab6d2019-11-26 16:32:12 +0100103#endif /* MBEDTLS_DEPRECATED_REMOVED */
Gilles Peskine7a894f22019-11-26 16:06:46 +0100104
Gilles Peskine45c29ce2019-12-03 17:56:11 +0100105/*
106 * Size-specific elliptic curve and Diffie-Hellman group names
107 */
108#define PSA_ECC_CURVE_SECP160K1 ((psa_ecc_curve_t) 0x1600a0)
109#define PSA_ECC_CURVE_SECP192K1 ((psa_ecc_curve_t) 0x1600c0)
110#define PSA_ECC_CURVE_SECP224K1 ((psa_ecc_curve_t) 0x1600e0)
111#define PSA_ECC_CURVE_SECP256K1 ((psa_ecc_curve_t) 0x160100)
112#define PSA_ECC_CURVE_SECP160R1 ((psa_ecc_curve_t) 0x1200a0)
113#define PSA_ECC_CURVE_SECP192R1 ((psa_ecc_curve_t) 0x1200c0)
114#define PSA_ECC_CURVE_SECP224R1 ((psa_ecc_curve_t) 0x1200e0)
115#define PSA_ECC_CURVE_SECP256R1 ((psa_ecc_curve_t) 0x120100)
116#define PSA_ECC_CURVE_SECP384R1 ((psa_ecc_curve_t) 0x120180)
117#define PSA_ECC_CURVE_SECP521R1 ((psa_ecc_curve_t) 0x120209)
118#define PSA_ECC_CURVE_SECP160R2 ((psa_ecc_curve_t) 0x1a00a0)
119#define PSA_ECC_CURVE_SECT163K1 ((psa_ecc_curve_t) 0x2600a3)
120#define PSA_ECC_CURVE_SECT233K1 ((psa_ecc_curve_t) 0x2600e9)
121#define PSA_ECC_CURVE_SECT239K1 ((psa_ecc_curve_t) 0x2600ef)
122#define PSA_ECC_CURVE_SECT283K1 ((psa_ecc_curve_t) 0x26011b)
123#define PSA_ECC_CURVE_SECT409K1 ((psa_ecc_curve_t) 0x260199)
124#define PSA_ECC_CURVE_SECT571K1 ((psa_ecc_curve_t) 0x26023b)
125#define PSA_ECC_CURVE_SECT163R1 ((psa_ecc_curve_t) 0x2200a3)
126#define PSA_ECC_CURVE_SECT193R1 ((psa_ecc_curve_t) 0x2200c1)
127#define PSA_ECC_CURVE_SECT233R1 ((psa_ecc_curve_t) 0x2200e9)
128#define PSA_ECC_CURVE_SECT283R1 ((psa_ecc_curve_t) 0x22011b)
129#define PSA_ECC_CURVE_SECT409R1 ((psa_ecc_curve_t) 0x220199)
130#define PSA_ECC_CURVE_SECT571R1 ((psa_ecc_curve_t) 0x22023b)
131#define PSA_ECC_CURVE_SECT163R2 ((psa_ecc_curve_t) 0x2a00a3)
132#define PSA_ECC_CURVE_SECT193R2 ((psa_ecc_curve_t) 0x2a00c1)
133#define PSA_ECC_CURVE_BRAINPOOL_P256R1 ((psa_ecc_curve_t) 0x300100)
134#define PSA_ECC_CURVE_BRAINPOOL_P384R1 ((psa_ecc_curve_t) 0x300180)
135#define PSA_ECC_CURVE_BRAINPOOL_P512R1 ((psa_ecc_curve_t) 0x300200)
136#define PSA_ECC_CURVE_CURVE25519 ((psa_ecc_curve_t) 0x0200ff)
137#define PSA_ECC_CURVE_CURVE448 ((psa_ecc_curve_t) 0x0201c0)
138
139#define PSA_DH_GROUP_FFDHE2048 ((psa_dh_group_t) 0x020800)
140#define PSA_DH_GROUP_FFDHE3072 ((psa_dh_group_t) 0x020c00)
141#define PSA_DH_GROUP_FFDHE4096 ((psa_dh_group_t) 0x021000)
142#define PSA_DH_GROUP_FFDHE6144 ((psa_dh_group_t) 0x021800)
143#define PSA_DH_GROUP_FFDHE8192 ((psa_dh_group_t) 0x022000)
144
Gilles Peskine7a894f22019-11-26 16:06:46 +0100145#ifdef __cplusplus
146}
147#endif
148
149#endif /* PSA_CRYPTO_COMPAT_H */