mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2026-09-13 14:22:19 +08:00
compatible with PSA configs and test improvements
Signed-off-by: Yi Wu <yi.wu2@arm.com>
This commit is contained in:
parent
c734d57590
commit
5c906f7fa0
@ -139,6 +139,13 @@ set(MBEDTLS_CONFIG_NAME "" CACHE STRING "Named Mbed TLS configuration (see confi
|
|||||||
set(MBEDTLS_CONFIG_SET "" CACHE STRING "Options to set, separated by semicolons (OPTION or OPTION=VALUE).")
|
set(MBEDTLS_CONFIG_SET "" CACHE STRING "Options to set, separated by semicolons (OPTION or OPTION=VALUE).")
|
||||||
set(MBEDTLS_CONFIG_UNSET "" CACHE STRING "Options to unset, separated by semicolons.")
|
set(MBEDTLS_CONFIG_UNSET "" CACHE STRING "Options to unset, separated by semicolons.")
|
||||||
|
|
||||||
|
set(MBEDTLS_CONFIG_TRANSFORMED FALSE)
|
||||||
|
if(NOT "${MBEDTLS_CONFIG_NAME}" STREQUAL "" OR
|
||||||
|
NOT "${MBEDTLS_CONFIG_SET}" STREQUAL "" OR
|
||||||
|
NOT "${MBEDTLS_CONFIG_UNSET}" STREQUAL "")
|
||||||
|
set(MBEDTLS_CONFIG_TRANSFORMED TRUE)
|
||||||
|
endif()
|
||||||
|
|
||||||
if(NOT "${MBEDTLS_CONFIG_FILE}" STREQUAL "" AND
|
if(NOT "${MBEDTLS_CONFIG_FILE}" STREQUAL "" AND
|
||||||
(NOT "${MBEDTLS_CONFIG_BASE_FILE}" STREQUAL "" OR
|
(NOT "${MBEDTLS_CONFIG_BASE_FILE}" STREQUAL "" OR
|
||||||
NOT "${MBEDTLS_CONFIG_NAME}" STREQUAL "" OR
|
NOT "${MBEDTLS_CONFIG_NAME}" STREQUAL "" OR
|
||||||
@ -149,6 +156,19 @@ if(NOT "${MBEDTLS_CONFIG_FILE}" STREQUAL "" AND
|
|||||||
"MBEDTLS_CONFIG_NAME, MBEDTLS_CONFIG_SET or MBEDTLS_CONFIG_UNSET.")
|
"MBEDTLS_CONFIG_NAME, MBEDTLS_CONFIG_SET or MBEDTLS_CONFIG_UNSET.")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(MBEDTLS_CONFIG_TRANSFORMED AND
|
||||||
|
(NOT "${TF_PSA_CRYPTO_CONFIG_FILE}" STREQUAL "" OR
|
||||||
|
NOT "${TF_PSA_CRYPTO_CONFIG_BASE_FILE}" STREQUAL "" OR
|
||||||
|
NOT "${TF_PSA_CRYPTO_CONFIG_NAME}" STREQUAL "" OR
|
||||||
|
NOT "${TF_PSA_CRYPTO_CONFIG_SET}" STREQUAL "" OR
|
||||||
|
NOT "${TF_PSA_CRYPTO_CONFIG_UNSET}" STREQUAL ""))
|
||||||
|
message(FATAL_ERROR
|
||||||
|
"TF_PSA_CRYPTO_CONFIG_FILE, TF_PSA_CRYPTO_CONFIG_BASE_FILE, "
|
||||||
|
"TF_PSA_CRYPTO_CONFIG_NAME, TF_PSA_CRYPTO_CONFIG_SET and "
|
||||||
|
"TF_PSA_CRYPTO_CONFIG_UNSET cannot be combined with "
|
||||||
|
"MBEDTLS_CONFIG_NAME, MBEDTLS_CONFIG_SET or MBEDTLS_CONFIG_UNSET.")
|
||||||
|
endif()
|
||||||
|
|
||||||
if(NOT "${MBEDTLS_CONFIG_BASE_FILE}" STREQUAL "" OR
|
if(NOT "${MBEDTLS_CONFIG_BASE_FILE}" STREQUAL "" OR
|
||||||
NOT "${MBEDTLS_CONFIG_NAME}" STREQUAL "" OR
|
NOT "${MBEDTLS_CONFIG_NAME}" STREQUAL "" OR
|
||||||
NOT "${MBEDTLS_CONFIG_SET}" STREQUAL "" OR
|
NOT "${MBEDTLS_CONFIG_SET}" STREQUAL "" OR
|
||||||
@ -185,16 +205,21 @@ if(NOT "${MBEDTLS_CONFIG_BASE_FILE}" STREQUAL "" OR
|
|||||||
|
|
||||||
set(MBEDTLS_GENERATED_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated/include")
|
set(MBEDTLS_GENERATED_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated/include")
|
||||||
set(MBEDTLS_GENERATED_CONFIG_FILE "${MBEDTLS_GENERATED_CONFIG_DIR}/mbedtls/mbedtls_config.h")
|
set(MBEDTLS_GENERATED_CONFIG_FILE "${MBEDTLS_GENERATED_CONFIG_DIR}/mbedtls/mbedtls_config.h")
|
||||||
set(MBEDTLS_GENERATED_CRYPTO_CONFIG_FILE "${MBEDTLS_GENERATED_CONFIG_DIR}/psa/crypto_config.h")
|
|
||||||
file(MAKE_DIRECTORY "${MBEDTLS_GENERATED_CONFIG_DIR}/mbedtls")
|
file(MAKE_DIRECTORY "${MBEDTLS_GENERATED_CONFIG_DIR}/mbedtls")
|
||||||
file(MAKE_DIRECTORY "${MBEDTLS_GENERATED_CONFIG_DIR}/psa")
|
|
||||||
configure_file("${MBEDTLS_BASE_CONFIG_FILE}"
|
configure_file("${MBEDTLS_BASE_CONFIG_FILE}"
|
||||||
"${MBEDTLS_GENERATED_CONFIG_FILE}" COPYONLY)
|
"${MBEDTLS_GENERATED_CONFIG_FILE}" COPYONLY)
|
||||||
# config.py handles the Mbed TLS and PSA configurations together. Give it
|
|
||||||
# a build-tree PSA configuration so that it never modifies the source tree.
|
if(MBEDTLS_CONFIG_TRANSFORMED)
|
||||||
configure_file(
|
set(MBEDTLS_GENERATED_CRYPTO_CONFIG_FILE
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/tf-psa-crypto/include/psa/crypto_config.h"
|
"${MBEDTLS_GENERATED_CONFIG_DIR}/psa/crypto_config.h")
|
||||||
"${MBEDTLS_GENERATED_CRYPTO_CONFIG_FILE}" COPYONLY)
|
file(MAKE_DIRECTORY "${MBEDTLS_GENERATED_CONFIG_DIR}/psa")
|
||||||
|
# config.py handles the Mbed TLS and PSA configurations together. Give
|
||||||
|
# it a build-tree PSA configuration so that it never modifies the
|
||||||
|
# source tree.
|
||||||
|
configure_file(
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/tf-psa-crypto/include/psa/crypto_config.h"
|
||||||
|
"${MBEDTLS_GENERATED_CRYPTO_CONFIG_FILE}" COPYONLY)
|
||||||
|
endif()
|
||||||
|
|
||||||
function(mbedtls_configure_generated_file)
|
function(mbedtls_configure_generated_file)
|
||||||
execute_process(
|
execute_process(
|
||||||
@ -231,12 +256,9 @@ if(NOT "${MBEDTLS_CONFIG_BASE_FILE}" STREQUAL "" OR
|
|||||||
|
|
||||||
set(MBEDTLS_CONFIG_FILE
|
set(MBEDTLS_CONFIG_FILE
|
||||||
"$<BUILD_INTERFACE:${MBEDTLS_GENERATED_CONFIG_FILE}>$<INSTALL_INTERFACE:mbedtls/mbedtls_config.h>")
|
"$<BUILD_INTERFACE:${MBEDTLS_GENERATED_CONFIG_FILE}>$<INSTALL_INTERFACE:mbedtls/mbedtls_config.h>")
|
||||||
if("${TF_PSA_CRYPTO_CONFIG_FILE}" STREQUAL "" AND
|
if(MBEDTLS_CONFIG_TRANSFORMED)
|
||||||
"${TF_PSA_CRYPTO_CONFIG_NAME}" STREQUAL "")
|
|
||||||
# Named configurations can adjust both configuration files.
|
|
||||||
set(TF_PSA_CRYPTO_CONFIG_FILE
|
set(TF_PSA_CRYPTO_CONFIG_FILE
|
||||||
"$<BUILD_INTERFACE:${MBEDTLS_GENERATED_CRYPTO_CONFIG_FILE}>$<INSTALL_INTERFACE:psa/crypto_config_mbedtls.h>"
|
"$<BUILD_INTERFACE:${MBEDTLS_GENERATED_CRYPTO_CONFIG_FILE}>$<INSTALL_INTERFACE:psa/crypto_config_mbedtls.h>")
|
||||||
CACHE STRING "TF-PSA-Crypto config file (overrides default)." FORCE)
|
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|||||||
@ -303,6 +303,8 @@ component_build_cmake_config_options () {
|
|||||||
msg "configure: cmake with a false-like option name"
|
msg "configure: cmake with a false-like option name"
|
||||||
cmake -DMBEDTLS_CONFIG_SET=NO "$MBEDTLS_ROOT_DIR"
|
cmake -DMBEDTLS_CONFIG_SET=NO "$MBEDTLS_ROOT_DIR"
|
||||||
grep '^#define NO$' generated/include/mbedtls/mbedtls_config.h
|
grep '^#define NO$' generated/include/mbedtls/mbedtls_config.h
|
||||||
|
cmake -DMBEDTLS_CONFIG_SET= .
|
||||||
|
grep '^TF_PSA_CRYPTO_CONFIG_FILE:FILEPATH=$' CMakeCache.txt
|
||||||
|
|
||||||
cd "$MBEDTLS_ROOT_DIR"
|
cd "$MBEDTLS_ROOT_DIR"
|
||||||
rm -rf "$OUT_OF_SOURCE_DIR"
|
rm -rf "$OUT_OF_SOURCE_DIR"
|
||||||
@ -314,6 +316,7 @@ component_build_cmake_config_options () {
|
|||||||
"$MBEDTLS_ROOT_DIR"
|
"$MBEDTLS_ROOT_DIR"
|
||||||
cmp "$MBEDTLS_ROOT_DIR/configs/config-ccm-psk-tls1_2.h" \
|
cmp "$MBEDTLS_ROOT_DIR/configs/config-ccm-psk-tls1_2.h" \
|
||||||
generated/include/mbedtls/mbedtls_config.h
|
generated/include/mbedtls/mbedtls_config.h
|
||||||
|
not test -e generated/include/psa/crypto_config.h
|
||||||
|
|
||||||
cd "$MBEDTLS_ROOT_DIR"
|
cd "$MBEDTLS_ROOT_DIR"
|
||||||
rm -rf "$OUT_OF_SOURCE_DIR"
|
rm -rf "$OUT_OF_SOURCE_DIR"
|
||||||
@ -325,6 +328,24 @@ component_build_cmake_config_options () {
|
|||||||
-DMBEDTLS_CONFIG_SET=MBEDTLS_DEBUG_C "$MBEDTLS_ROOT_DIR"
|
-DMBEDTLS_CONFIG_SET=MBEDTLS_DEBUG_C "$MBEDTLS_ROOT_DIR"
|
||||||
|
|
||||||
cd "$MBEDTLS_ROOT_DIR"
|
cd "$MBEDTLS_ROOT_DIR"
|
||||||
|
for option in \
|
||||||
|
"TF_PSA_CRYPTO_CONFIG_FILE=$MBEDTLS_ROOT_DIR/tf-psa-crypto/include/psa/crypto_config.h" \
|
||||||
|
"TF_PSA_CRYPTO_CONFIG_BASE_FILE=$MBEDTLS_ROOT_DIR/tf-psa-crypto/include/psa/crypto_config.h" \
|
||||||
|
"TF_PSA_CRYPTO_CONFIG_NAME=full" \
|
||||||
|
"TF_PSA_CRYPTO_CONFIG_SET=PSA_WANT_ALG_SHA_256" \
|
||||||
|
"TF_PSA_CRYPTO_CONFIG_UNSET=PSA_WANT_ALG_CMAC"
|
||||||
|
do
|
||||||
|
rm -rf "$OUT_OF_SOURCE_DIR"
|
||||||
|
mkdir "$OUT_OF_SOURCE_DIR"
|
||||||
|
cd "$OUT_OF_SOURCE_DIR"
|
||||||
|
|
||||||
|
msg "configure: reject $option with Mbed TLS transformations"
|
||||||
|
not cmake "-D$option" -DMBEDTLS_CONFIG_SET=MBEDTLS_DEBUG_C \
|
||||||
|
"$MBEDTLS_ROOT_DIR"
|
||||||
|
|
||||||
|
cd "$MBEDTLS_ROOT_DIR"
|
||||||
|
done
|
||||||
|
|
||||||
rm -rf "$OUT_OF_SOURCE_DIR"
|
rm -rf "$OUT_OF_SOURCE_DIR"
|
||||||
mkdir "$OUT_OF_SOURCE_DIR"
|
mkdir "$OUT_OF_SOURCE_DIR"
|
||||||
cd "$OUT_OF_SOURCE_DIR"
|
cd "$OUT_OF_SOURCE_DIR"
|
||||||
@ -358,7 +379,7 @@ component_build_cmake_config_options () {
|
|||||||
"$MBEDTLS_ROOT_DIR/configs/config-ccm-psk-tls1_2.h"
|
"$MBEDTLS_ROOT_DIR/configs/config-ccm-psk-tls1_2.h"
|
||||||
|
|
||||||
msg "install: generated configurations are relocatable"
|
msg "install: generated configurations are relocatable"
|
||||||
install_dir="$OUT_OF_SOURCE_DIR/install"
|
install_dir="$OUT_OF_SOURCE_DIR.install"
|
||||||
cmake -DCMAKE_INSTALL_PREFIX="$install_dir" .
|
cmake -DCMAKE_INSTALL_PREFIX="$install_dir" .
|
||||||
cmake --build . --target install
|
cmake --build . --target install
|
||||||
cmp generated/include/mbedtls/mbedtls_config.h \
|
cmp generated/include/mbedtls/mbedtls_config.h \
|
||||||
@ -366,9 +387,11 @@ component_build_cmake_config_options () {
|
|||||||
cmp generated/include/psa/crypto_config.h \
|
cmp generated/include/psa/crypto_config.h \
|
||||||
"$install_dir/include/psa/crypto_config_mbedtls.h"
|
"$install_dir/include/psa/crypto_config_mbedtls.h"
|
||||||
|
|
||||||
# The installed targets must not refer to configuration headers in the
|
# The installed targets must not refer to the build tree.
|
||||||
# build tree.
|
cd "$MBEDTLS_ROOT_DIR"
|
||||||
mv generated generated.moved
|
mv "$OUT_OF_SOURCE_DIR" "$OUT_OF_SOURCE_DIR.moved"
|
||||||
|
mkdir "$OUT_OF_SOURCE_DIR"
|
||||||
|
cd "$OUT_OF_SOURCE_DIR"
|
||||||
mkdir consumer
|
mkdir consumer
|
||||||
cat >consumer/CMakeLists.txt <<EOF
|
cat >consumer/CMakeLists.txt <<EOF
|
||||||
cmake_minimum_required(VERSION 3.10)
|
cmake_minimum_required(VERSION 3.10)
|
||||||
@ -386,7 +409,7 @@ EOF
|
|||||||
cd ..
|
cd ..
|
||||||
|
|
||||||
cd "$MBEDTLS_ROOT_DIR"
|
cd "$MBEDTLS_ROOT_DIR"
|
||||||
rm -rf "$OUT_OF_SOURCE_DIR"
|
rm -rf "$OUT_OF_SOURCE_DIR" "$OUT_OF_SOURCE_DIR.moved" "$install_dir"
|
||||||
|
|
||||||
msg "configure: reject transformations in an in-tree build"
|
msg "configure: reject transformations in an in-tree build"
|
||||||
not cmake -DMBEDTLS_CONFIG_SET=NO .
|
not cmake -DMBEDTLS_CONFIG_SET=NO .
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user