1 /*
2 * Copyright (c) 2020, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8 /**
9 * \file tfm_mbedcrypto_alt.c
10 * This file collects the alternative functions to replace the
11 * implementations in mbed-crypto if the corresponding mbed-crypto
12 * MBEDTLS__FUNCTION_NAME__ALT is selected.
13 *
14 * \note This applies only when the legacy driver API based on the _ALT
15 * implementations is selected, and has no effect when the PSA driver
16 * interface is used. This is going to be deprecated in a future version
17 * of mbed TLS.
18 */
19
20 /*
21 * A dummy include. Just add a dependency to make sure this file is compiled
22 * after all crypto header files are installed and configuration flags are set.
23 */
24 #include "tfm_mbedcrypto_include.h"
25 #if defined(MBEDTLS_AES_DECRYPT_ALT) || defined(MBEDTLS_AES_SETKEY_DEC_ALT)
26 #include "mbedtls/aes.h"
27 #include "mbedtls/error.h"
28 #endif
29
30 #if defined(MBEDTLS_AES_DECRYPT_ALT) && defined(MBEDTLS_CCM_C)
31 #pragma message("mbedtls_internal_aes_decrypt() is replaced by an empty wrapper to decrease memory footprint")
32 /*
33 * Replace the decryption process with an empty wrapper in AES-CCM mode.
34 * The decryption process is exactly the same as encryption process. Skip
35 * the decryption implementation to decrease memory footprint.
36 */
mbedtls_internal_aes_decrypt(mbedtls_aes_context * ctx,const unsigned char input[16],unsigned char output[16])37 int mbedtls_internal_aes_decrypt(mbedtls_aes_context *ctx,
38 const unsigned char input[16],
39 unsigned char output[16])
40 {
41 (void)ctx;
42 (void)input;
43 (void)output;
44
45 return MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED;
46 }
47 #endif
48
49 #if defined(MBEDTLS_AES_SETKEY_DEC_ALT) && defined(MBEDTLS_CCM_C)
50 #pragma message("mbedtls_aes_setkey_dec() is replaced by an empty wrapper to decrease memory footprint")
51 /*
52 * Replace the decryption process with an empty wrapper in AES-CCM mode.
53 * The decryption process is exactly the same as encryption process. Skip
54 * the decryption key setting to decrease memory footprint.
55 */
mbedtls_aes_setkey_dec(mbedtls_aes_context * ctx,const unsigned char * key,unsigned int keybits)56 int mbedtls_aes_setkey_dec(mbedtls_aes_context *ctx, const unsigned char *key,
57 unsigned int keybits)
58 {
59 (void)ctx;
60 (void)key;
61 (void)keybits;
62
63 return MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED;
64 }
65 #endif
66