From 550867383238de120bbea00ec62df3ec16040da5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Thu, 7 Jul 2022 12:17:55 +0200 Subject: [PATCH] Add helper macros for dependencies based on USE_PSA MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For now in an internal header as it's the safest option and that way we can change whenever we want. Later on if we think the macros can be useful to applications as well then we can move them to a public location. Signed-off-by: Manuel Pégourié-Gonnard --- library/use_psa_helpers.h | 58 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 library/use_psa_helpers.h diff --git a/library/use_psa_helpers.h b/library/use_psa_helpers.h new file mode 100644 index 000000000..6b63ce833 --- /dev/null +++ b/library/use_psa_helpers.h @@ -0,0 +1,58 @@ +/** + * Internal macros for parts of the code governed by MBEDTLS_USE_PSA_CRYPTO. + * These macros allow checking if an algorithm is available, either via the + * legacy API or the PSA Crypto API, depending on MBEDTLS_USE_PSA_CRYPTO. + * When possible, they're named after the corresponding PSA_WANT_ macro. + * + * Copyright The Mbed TLS Contributors + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef MBEDTLS_USE_PSA_HELPERS_H +#define MBEDTLS_USE_PSA_HELPERS_H + +#include "common.h" + +/* Hash algorithms */ +#if ( !defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_MD5_C) ) || \ + ( defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_MD5) ) +#define MBEDTLS_USE_PSA_WANT_ALG_MD5 +#endif +#if ( !defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_RIPEMD160_C) ) || \ + ( defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_RIPEMD160) ) +#define MBEDTLS_USE_PSA_WANT_ALG_RIPEMD160 +#endif +#if ( !defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_SHA1_C) ) || \ + ( defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_SHA_1) ) +#define MBEDTLS_USE_PSA_WANT_ALG_SHA_1 +#endif +#if ( !defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_SHA224_C) ) || \ + ( defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_SHA_224) ) +#define MBEDTLS_USE_PSA_WANT_ALG_SHA_224 +#endif +#if ( !defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_SHA256_C) ) || \ + ( defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_SHA_256) ) +#define MBEDTLS_USE_PSA_WANT_ALG_SHA_256 +#endif +#if ( !defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_SHA384_C) ) || \ + ( defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_SHA_384) ) +#define MBEDTLS_USE_PSA_WANT_ALG_SHA_384 +#endif +#if ( !defined(MBEDTLS_USE_PSA_CRYPTO) && defined(MBEDTLS_SHA512_C) ) || \ + ( defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_ALG_SHA_512) ) +#define MBEDTLS_USE_PSA_WANT_ALG_SHA_512 +#endif + +#endif /* MBEDTLS_USE_PSA_HELPERS_H */