blob: 09c53bb342172b948490bc051d8bce1a75b57611 [file] [log] [blame]
Antonio de Angelis8908f472018-08-31 15:44:25 +01001#-------------------------------------------------------------------------------
Antonio de Angelis04debbd2019-10-14 12:12:52 +01002# Copyright (c) 2018-2020, Arm Limited. All rights reserved.
Antonio de Angelis8908f472018-08-31 15:44:25 +01003#
4# SPDX-License-Identifier: BSD-3-Clause
5#
6#-------------------------------------------------------------------------------
7
8#Definitions to compile the "crypto" module.
9#This file assumes it will be included from a project specific cmakefile, and
10#will not create a library or executable.
11#Inputs:
Raef Coles1bb168e2019-10-17 09:04:55 +010012# MBEDCRYPTO_INSTALL_DIR - directory where mbed-crypto headers and libraries can be found. Needed only when using CRYPTO_ENGINE_MBEDCRYPTO ON.
Antonio de Angelis8908f472018-08-31 15:44:25 +010013# TFM_ROOT_DIR - root directory of the TF-M repository.
14#Outputs:
15# Will modify include directories to make the source compile.
16# ALL_SRC_C: C source files to be compiled will be added to this list. This shall be added to your add_executable or add_library command.
17# ALL_SRC_CXX: C++ source files to be compiled will be added to this list. This shall be added to your add_executable or add_library command.
18# ALL_SRC_ASM: assembly source files to be compiled will be added to this list. This shall be added to your add_executable or add_library command.
19# Include directories will be modified by using the include_directories() commands as needed.
20
21#Get the current directory where this file is located.
22set(CRYPTO_DIR ${CMAKE_CURRENT_LIST_DIR})
23
24#Check input variables
25if (NOT DEFINED ENABLE_CRYPTO)
26 message(FATAL_ERROR "Incomplete build configuration: ENABLE_CRYPTO is undefined. ")
27endif()
28
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010029if (NOT DEFINED CRYPTO_ENGINE_MBEDTLS)
30 message(FATAL_ERROR "Incomplete build configuration: CRYPTO_ENGINE_MBEDTLS is undefined. ")
31endif()
32
Antonio de Angelis8908f472018-08-31 15:44:25 +010033if (ENABLE_CRYPTO)
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010034 if (CRYPTO_ENGINE_MBEDTLS)
Raef Coles1bb168e2019-10-17 09:04:55 +010035 if (NOT DEFINED MBEDCRYPTO_INSTALL_DIR)
36 message(FATAL_ERROR "Please set MBEDCRYPTO_INSTALL_DIR before including this file.")
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010037 endif()
Antonio de Angelis8908f472018-08-31 15:44:25 +010038 endif()
39
40 if (NOT DEFINED TFM_ROOT_DIR)
41 message(FATAL_ERROR "Please set TFM_ROOT_DIR before including this file.")
42 endif()
43
44 set (CRYPTO_C_SRC "${CRYPTO_DIR}/crypto_init.c"
45 "${CRYPTO_DIR}/crypto_alloc.c"
46 "${CRYPTO_DIR}/crypto_cipher.c"
Antonio de Angelisa6f72162018-09-05 11:00:37 +010047 "${CRYPTO_DIR}/crypto_hash.c"
Louis Mayencourt7a36f782018-09-24 14:00:57 +010048 "${CRYPTO_DIR}/crypto_mac.c"
Antonio de Angelis8908f472018-08-31 15:44:25 +010049 "${CRYPTO_DIR}/crypto_key.c"
Antonio de Angelis3a480992018-11-07 11:53:28 +000050 "${CRYPTO_DIR}/crypto_aead.c"
Antonio de Angelis25e2b2d2019-04-25 14:49:50 +010051 "${CRYPTO_DIR}/crypto_asymmetric.c"
Antonio de Angelis04debbd2019-10-14 12:12:52 +010052 "${CRYPTO_DIR}/crypto_key_derivation.c"
Jamie Fox9da91f32019-02-07 18:11:45 +000053 "${CRYPTO_DIR}/tfm_crypto_secure_api.c"
Antonio de Angelis8908f472018-08-31 15:44:25 +010054 )
55
David Hue954d6b2020-04-23 13:06:00 +080056 if (CRYPTO_ENGINE_MBEDTLS)
57 list(APPEND CRYPTO_C_SRC "${CRYPTO_DIR}/tfm_mbedcrypto_alt.c")
58 endif()
59
Antonio de Angelis8908f472018-08-31 15:44:25 +010060 #Append all our source files to global lists.
61 list(APPEND ALL_SRC_C ${CRYPTO_C_SRC})
62 unset(CRYPTO_C_SRC)
63
64 #Setting include directories
65 embedded_include_directories(PATH ${TFM_ROOT_DIR} ABSOLUTE)
66 embedded_include_directories(PATH ${TFM_ROOT_DIR}/interface/include ABSOLUTE)
David Hu49a28eb2019-08-14 18:18:15 +080067 embedded_include_directories(PATH ${TFM_ROOT_DIR}/secure_fw/core/include ABSOLUTE)
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010068 if (CRYPTO_ENGINE_MBEDTLS)
Raef Coles1bb168e2019-10-17 09:04:55 +010069 embedded_include_directories(PATH ${MBEDCRYPTO_INSTALL_DIR}/include ABSOLUTE)
Antonio de Angeliscf85ba22018-10-09 13:29:40 +010070 endif()
71
72 #Inform the user about Crypto service features selected based on the Crypto service cmake flags
73 message("The Crypto service compile configuration is as follows:")
Jamie Fox82b87ca2018-12-11 16:41:11 +000074 if (NOT DEFINED CRYPTO_ENGINE_BUF_SIZE)
75 message("- CRYPTO_ENGINE_BUF_SIZE using default value")
76 else()
77 message("- CRYPTO_ENGINE_BUF_SIZE: " ${CRYPTO_ENGINE_BUF_SIZE})
78 endif()
Jamie Fox0e54ebc2019-04-09 14:21:04 +010079 if (NOT DEFINED CRYPTO_CONC_OPER_NUM)
80 message("- CRYPTO_CONC_OPER_NUM using default value")
81 else()
82 message("- CRYPTO_CONC_OPER_NUM: " ${CRYPTO_CONC_OPER_NUM})
83 endif()
David Hu1e863232020-05-01 20:16:07 +080084
Antonio de Angelis7740b382019-07-16 10:59:25 +010085 if (NOT DEFINED CRYPTO_KEY_MODULE_DISABLED)
86 message("- KEY module enabled")
87 set(CRYPTO_KEY_MODULE_DISABLED 0)
88 else()
89 message("- CRYPTO_KEY_MODULE_DISABLED: " ${CRYPTO_KEY_MODULE_DISABLED})
90 endif()
David Hu1e863232020-05-01 20:16:07 +080091 if (NOT CRYPTO_KEY_MODULE_DISABLED AND
92 NOT TFM_PARTITION_INTERNAL_TRUSTED_STORAGE)
93 message(FATAL_ERROR "Internal trusted storage should be enabled for persistent key storage")
94 endif()
95
Antonio de Angelis7740b382019-07-16 10:59:25 +010096 if (NOT DEFINED CRYPTO_AEAD_MODULE_DISABLED)
97 message("- AEAD module enabled")
98 set(CRYPTO_AEAD_MODULE_DISABLED 0)
99 else()
100 message("- CRYPTO_AEAD_MODULE_DISABLED: " ${CRYPTO_AEAD_MODULE_DISABLED})
101 endif()
102 if (NOT DEFINED CRYPTO_MAC_MODULE_DISABLED)
103 message("- MAC module enabled")
104 set(CRYPTO_MAC_MODULE_DISABLED 0)
105 else()
106 message("- CRYPTO_MAC_MODULE_DISABLED: " ${CRYPTO_MAC_MODULE_DISABLED})
107 endif()
108 if (NOT DEFINED CRYPTO_HASH_MODULE_DISABLED)
109 message("- HASH module enabled")
110 set(CRYPTO_HASH_MODULE_DISABLED 0)
111 else()
112 message("- CRYPTO_HASH_MODULE_DISABLED: " ${CRYPTO_HASH_MODULE_DISABLED})
113 endif()
114 if (NOT DEFINED CRYPTO_CIPHER_MODULE_DISABLED)
115 message("- CIPHER module enabled")
116 set(CRYPTO_CIPHER_MODULE_DISABLED 0)
117 else()
118 message("- CRYPTO_CIPHER_MODULE_DISABLED: " ${CRYPTO_CIPHER_MODULE_DISABLED})
119 endif()
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100120 if (NOT DEFINED CRYPTO_KEY_DERIVATION_MODULE_DISABLED)
121 message("- KEY_DERIVATION module enabled")
122 set(CRYPTO_KEY_DERIVATION_MODULE_DISABLED 0)
Antonio de Angelis7740b382019-07-16 10:59:25 +0100123 else()
Antonio de Angelis04debbd2019-10-14 12:12:52 +0100124 message("- CRYPTO_KEY_DERIVATION_MODULE_DISABLED: " ${CRYPTO_KEY_DERIVATION_MODULE_DISABLED})
Antonio de Angelis7740b382019-07-16 10:59:25 +0100125 endif()
126 if (NOT DEFINED CRYPTO_ASYMMETRIC_MODULE_DISABLED)
127 message("- ASYMMETRIC module enabled")
128 set(CRYPTO_ASYMMETRIC_MODULE_DISABLED 0)
129 else()
130 message("- CRYPTO_ASYMMETRIC_MODULE_DISABLED: " ${CRYPTO_ASYMMETRIC_MODULE_DISABLED})
131 endif()
Antonio de Angelis4743e672019-04-11 11:38:48 +0100132 if (TFM_PSA_API)
133 if (NOT DEFINED CRYPTO_IOVEC_BUFFER_SIZE)
134 message("- CRYPTO_IOVEC_BUFFER_SIZE using default value")
135 else()
136 message("- CRYPTO_IOVEC_BUFFER_SIZE: " ${CRYPTO_IOVEC_BUFFER_SIZE})
137 endif()
138 endif()
Antonio de Angelis8908f472018-08-31 15:44:25 +0100139
140else()
141 message(FATAL_ERROR "Build system currently doesn't support selectively disabling of a service.")
142endif()