blob: 6160d8a32017f19ab267d9182ee17d3193955fdf [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 *
6 * \note This file may not be included directly. Applications must
7 * include psa/crypto.h.
8 */
9/*
10 * Copyright (C) 2019, ARM Limited, All Rights Reserved
11 * SPDX-License-Identifier: Apache-2.0
12 *
13 * Licensed under the Apache License, Version 2.0 (the "License"); you may
14 * not use this file except in compliance with the License.
15 * You may obtain a copy of the License at
16 *
17 * http://www.apache.org/licenses/LICENSE-2.0
18 *
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
21 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
24 *
25 * This file is part of mbed TLS (https://tls.mbed.org)
26 */
27
28#ifndef PSA_CRYPTO_COMPAT_H
29#define PSA_CRYPTO_COMPAT_H
30
Gilles Peskine7a894f22019-11-26 16:06:46 +010031#ifdef __cplusplus
32extern "C" {
33#endif
34
Gilles Peskine7b0ab6d2019-11-26 16:32:12 +010035#if !defined(MBEDTLS_DEPRECATED_REMOVED)
36
37#if defined(MBEDTLS_DEPRECATED_WARNING) && !defined(MBEDTLS_PSA_DEPRECATED)
38#define MBEDTLS_PSA_DEPRECATED __attribute__((deprecated))
39#else
40#define MBEDTLS_PSA_DEPRECATED
41#endif
42
Gilles Peskine41510942019-11-26 16:10:58 +010043typedef MBEDTLS_PSA_DEPRECATED size_t mbedtls_deprecated_size_t;
Gilles Peskine7b0ab6d2019-11-26 16:32:12 +010044typedef MBEDTLS_PSA_DEPRECATED psa_status_t mbedtls_deprecated_psa_status_t;
Gilles Peskine41510942019-11-26 16:10:58 +010045typedef MBEDTLS_PSA_DEPRECATED psa_key_usage_t mbedtls_deprecated_psa_key_usage_t;
Gilles Peskine7b0ab6d2019-11-26 16:32:12 +010046
47#define MBEDTLS_DEPRECATED_CONSTANT( type, value ) \
48 ( (mbedtls_deprecated_##type) ( value ) )
49
Gilles Peskine7a894f22019-11-26 16:06:46 +010050/*
51 * Deprecated PSA Crypto error code definitions
52 */
Gilles Peskine7a894f22019-11-26 16:06:46 +010053#define PSA_ERROR_UNKNOWN_ERROR \
Gilles Peskine7b0ab6d2019-11-26 16:32:12 +010054 MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_GENERIC_ERROR )
Gilles Peskine7a894f22019-11-26 16:06:46 +010055#define PSA_ERROR_OCCUPIED_SLOT \
Gilles Peskine7b0ab6d2019-11-26 16:32:12 +010056 MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_ALREADY_EXISTS )
Gilles Peskine7a894f22019-11-26 16:06:46 +010057#define PSA_ERROR_EMPTY_SLOT \
Gilles Peskine7b0ab6d2019-11-26 16:32:12 +010058 MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_DOES_NOT_EXIST )
Gilles Peskine7a894f22019-11-26 16:06:46 +010059#define PSA_ERROR_INSUFFICIENT_CAPACITY \
Gilles Peskine7b0ab6d2019-11-26 16:32:12 +010060 MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_INSUFFICIENT_DATA )
Gilles Peskine7a894f22019-11-26 16:06:46 +010061#define PSA_ERROR_TAMPERING_DETECTED \
Gilles Peskine7b0ab6d2019-11-26 16:32:12 +010062 MBEDTLS_DEPRECATED_CONSTANT( psa_status_t, PSA_ERROR_CORRUPTION_DETECTED )
63
Gilles Peskine41510942019-11-26 16:10:58 +010064/*
65 * Deprecated PSA Crypto numerical encodings
66 */
67#define PSA_KEY_USAGE_SIGN \
68 MBEDTLS_DEPRECATED_CONSTANT( psa_key_usage_t, PSA_KEY_USAGE_SIGN_HASH )
69#define PSA_KEY_USAGE_VERIFY \
70 MBEDTLS_DEPRECATED_CONSTANT( psa_key_usage_t, PSA_KEY_USAGE_VERIFY_HASH )
71
72/*
73 * Deprecated PSA Crypto size calculation macros
74 */
75#define PSA_ASYMMETRIC_SIGNATURE_MAX_SIZE \
76 MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_SIGNATURE_MAX_SIZE )
77#define PSA_ASYMMETRIC_SIGN_OUTPUT_SIZE( key_type, key_bits, alg ) \
78 MBEDTLS_DEPRECATED_CONSTANT( size_t, PSA_SIGN_OUTPUT_SIZE( key_type, key_bits, alg ) )
79
80/*
81 * Deprecated PSA Crypto function names
82 */
83/* Make these macros and not wrappers so that there is no cost to
84 * applications that don't use the deprecated names.
85 *
86 * Put backslash-newline after "#define" to bypass check-names.sh which
87 * would otherwise complain about lowercase macro names.
88 */
89#define \
90 psa_asymmetric_sign( key, alg, hash, hash_length, signature, signature_size, signature_length ) \
91 ( (mbedtls_deprecated_psa_status_t) psa_sign_hash( key, alg, hash, hash_length, signature, signature_size, signature_length ) )
92#define \
93 psa_asymmetric_verify( key, alg, hash, hash_length, signature, signature_length ) \
94 ( (mbedtls_deprecated_psa_status_t) psa_verify_hash( key, alg, hash, hash_length, signature, signature_length ) )
95
Gilles Peskine7b0ab6d2019-11-26 16:32:12 +010096#endif /* MBEDTLS_DEPRECATED_REMOVED */
Gilles Peskine7a894f22019-11-26 16:06:46 +010097
98#ifdef __cplusplus
99}
100#endif
101
102#endif /* PSA_CRYPTO_COMPAT_H */