From ced26059e398dec423f5c4b861fb701de76d40d8 Mon Sep 17 00:00:00 2001 From: Harry Ramsey Date: Tue, 22 Oct 2024 09:18:18 +0100 Subject: [PATCH 01/20] Move psa programs to tf-psa-crypto directory This commit moves psa programs from the programs/psa directory to tf-psa-crypto/programs/psa directory. Signed-off-by: Harry Ramsey --- {programs => tf-psa-crypto/programs}/psa/CMakeLists.txt | 0 {programs => tf-psa-crypto/programs}/psa/aead_demo.c | 0 {programs => tf-psa-crypto/programs}/psa/crypto_examples.c | 0 {programs => tf-psa-crypto/programs}/psa/hmac_demo.c | 0 {programs => tf-psa-crypto/programs}/psa/key_ladder_demo.c | 0 {programs => tf-psa-crypto/programs}/psa/key_ladder_demo.sh | 0 {programs => tf-psa-crypto/programs}/psa/psa_constant_names.c | 0 {programs => tf-psa-crypto/programs}/psa/psa_hash.c | 0 {programs => tf-psa-crypto/programs}/psa/psa_hash_demo.sh | 0 9 files changed, 0 insertions(+), 0 deletions(-) rename {programs => tf-psa-crypto/programs}/psa/CMakeLists.txt (100%) rename {programs => tf-psa-crypto/programs}/psa/aead_demo.c (100%) rename {programs => tf-psa-crypto/programs}/psa/crypto_examples.c (100%) rename {programs => tf-psa-crypto/programs}/psa/hmac_demo.c (100%) rename {programs => tf-psa-crypto/programs}/psa/key_ladder_demo.c (100%) rename {programs => tf-psa-crypto/programs}/psa/key_ladder_demo.sh (100%) rename {programs => tf-psa-crypto/programs}/psa/psa_constant_names.c (100%) rename {programs => tf-psa-crypto/programs}/psa/psa_hash.c (100%) rename {programs => tf-psa-crypto/programs}/psa/psa_hash_demo.sh (100%) diff --git a/programs/psa/CMakeLists.txt b/tf-psa-crypto/programs/psa/CMakeLists.txt similarity index 100% rename from programs/psa/CMakeLists.txt rename to tf-psa-crypto/programs/psa/CMakeLists.txt diff --git a/programs/psa/aead_demo.c b/tf-psa-crypto/programs/psa/aead_demo.c similarity index 100% rename from programs/psa/aead_demo.c rename to tf-psa-crypto/programs/psa/aead_demo.c diff --git a/programs/psa/crypto_examples.c b/tf-psa-crypto/programs/psa/crypto_examples.c similarity index 100% rename from programs/psa/crypto_examples.c rename to tf-psa-crypto/programs/psa/crypto_examples.c diff --git a/programs/psa/hmac_demo.c b/tf-psa-crypto/programs/psa/hmac_demo.c similarity index 100% rename from programs/psa/hmac_demo.c rename to tf-psa-crypto/programs/psa/hmac_demo.c diff --git a/programs/psa/key_ladder_demo.c b/tf-psa-crypto/programs/psa/key_ladder_demo.c similarity index 100% rename from programs/psa/key_ladder_demo.c rename to tf-psa-crypto/programs/psa/key_ladder_demo.c diff --git a/programs/psa/key_ladder_demo.sh b/tf-psa-crypto/programs/psa/key_ladder_demo.sh similarity index 100% rename from programs/psa/key_ladder_demo.sh rename to tf-psa-crypto/programs/psa/key_ladder_demo.sh diff --git a/programs/psa/psa_constant_names.c b/tf-psa-crypto/programs/psa/psa_constant_names.c similarity index 100% rename from programs/psa/psa_constant_names.c rename to tf-psa-crypto/programs/psa/psa_constant_names.c diff --git a/programs/psa/psa_hash.c b/tf-psa-crypto/programs/psa/psa_hash.c similarity index 100% rename from programs/psa/psa_hash.c rename to tf-psa-crypto/programs/psa/psa_hash.c diff --git a/programs/psa/psa_hash_demo.sh b/tf-psa-crypto/programs/psa/psa_hash_demo.sh similarity index 100% rename from programs/psa/psa_hash_demo.sh rename to tf-psa-crypto/programs/psa/psa_hash_demo.sh From 75e8e030b1507fdf9b09169ddc8f4efbe2f988a7 Mon Sep 17 00:00:00 2001 From: Harry Ramsey Date: Tue, 22 Oct 2024 10:06:59 +0100 Subject: [PATCH 02/20] Fix paths for programs/psa This commit fixes paths for programs/psa to tf-psa-crypto/programs/psa. Signed-off-by: Harry Ramsey --- scripts/generate_psa_constants.py | 6 +++--- tests/psa-client-server/psasim/src/aut_psa_aead_encrypt.c | 2 +- tests/scripts/check-generated-files.sh | 2 +- tests/scripts/psa_collect_statuses.py | 2 +- tests/scripts/test_psa_constant_names.py | 2 +- tf-psa-crypto/programs/psa/aead_demo.c | 2 +- tf-psa-crypto/programs/psa/hmac_demo.c | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/generate_psa_constants.py b/scripts/generate_psa_constants.py index d472c6dc5134..a63636307ac0 100755 --- a/scripts/generate_psa_constants.py +++ b/scripts/generate_psa_constants.py @@ -1,13 +1,13 @@ #!/usr/bin/env python3 """Generate psa_constant_names_generated.c -which is included by programs/psa/psa_constant_names.c. +which is included by tf-psa-crypto/programs/psa/psa_constant_names.c. The code generated by this module is only meant to be used in the context of that program. An argument passed to this script will modify the output directory where the file is written: -* by default (no arguments passed): writes to programs/psa/ +* by default (no arguments passed): writes to tf-psa-crypto/programs/psa/ * OUTPUT_FILE_DIR passed: writes to OUTPUT_FILE_DIR/ """ @@ -327,7 +327,7 @@ def generate_psa_constants(header_file_names, output_file_name): if __name__ == '__main__': build_tree.chdir_to_root() # Allow to change the directory where psa_constant_names_generated.c is written to. - OUTPUT_FILE_DIR = sys.argv[1] if len(sys.argv) == 2 else "programs/psa" + OUTPUT_FILE_DIR = sys.argv[1] if len(sys.argv) == 2 else "tf-psa-crypto/programs/psa" generate_psa_constants(['tf-psa-crypto/include/psa/crypto_values.h', 'tf-psa-crypto/include/psa/crypto_extra.h'], diff --git a/tests/psa-client-server/psasim/src/aut_psa_aead_encrypt.c b/tests/psa-client-server/psasim/src/aut_psa_aead_encrypt.c index 64463f57fc83..ccdb62d20f48 100644 --- a/tests/psa-client-server/psasim/src/aut_psa_aead_encrypt.c +++ b/tests/psa-client-server/psasim/src/aut_psa_aead_encrypt.c @@ -47,7 +47,7 @@ void print_buf(const char *title, uint8_t *buf, size_t len) /* Run a PSA function and bail out if it fails. * The symbolic name of the error code can be recovered using: - * programs/psa/psa_constant_name status */ + * tf-psa-crypto/programs/psa/psa_constant_name status */ #define PSA_CHECK(expr) \ do \ { \ diff --git a/tests/scripts/check-generated-files.sh b/tests/scripts/check-generated-files.sh index 35990d0db2a4..934276dc35ea 100755 --- a/tests/scripts/check-generated-files.sh +++ b/tests/scripts/check-generated-files.sh @@ -163,7 +163,7 @@ else check framework/scripts/generate_psa_tests.py $(framework/scripts/generate_psa_tests.py --list) fi -check scripts/generate_psa_constants.py programs/psa/psa_constant_names_generated.c +check scripts/generate_psa_constants.py tf-psa-crypto/programs/psa/psa_constant_names_generated.c check framework/scripts/generate_test_keys.py framework/tests/src/test_keys.h check scripts/generate_driver_wrappers.py ${crypto_core_dir}/psa_crypto_driver_wrappers.h \ ${crypto_core_dir}/psa_crypto_driver_wrappers_no_static.c diff --git a/tests/scripts/psa_collect_statuses.py b/tests/scripts/psa_collect_statuses.py index 11bbebcc1f00..d835ba7c9a32 100755 --- a/tests/scripts/psa_collect_statuses.py +++ b/tests/scripts/psa_collect_statuses.py @@ -21,7 +21,7 @@ import sys DEFAULT_STATUS_LOG_FILE = 'tests/statuses.log' -DEFAULT_PSA_CONSTANT_NAMES = 'programs/psa/psa_constant_names' +DEFAULT_PSA_CONSTANT_NAMES = 'tf-psa-crypto/programs/psa/psa_constant_names' class Statuses: """Information about observed return statues of API functions.""" diff --git a/tests/scripts/test_psa_constant_names.py b/tests/scripts/test_psa_constant_names.py index 8ed0fee4b6cb..e697d1755c70 100755 --- a/tests/scripts/test_psa_constant_names.py +++ b/tests/scripts/test_psa_constant_names.py @@ -173,7 +173,7 @@ def main(): action='store_false', dest='keep_c', help='Don\'t keep the intermediate C file (default)') parser.add_argument('--program', - default='programs/psa/psa_constant_names', + default='tf-psa-crypto/programs/psa/psa_constant_names', help='Program to test') parser.add_argument('--show', action='store_true', diff --git a/tf-psa-crypto/programs/psa/aead_demo.c b/tf-psa-crypto/programs/psa/aead_demo.c index 2d99e3cbec59..e38b72a7f400 100644 --- a/tf-psa-crypto/programs/psa/aead_demo.c +++ b/tf-psa-crypto/programs/psa/aead_demo.c @@ -93,7 +93,7 @@ static void print_buf(const char *title, uint8_t *buf, size_t len) /* Run a PSA function and bail out if it fails. * The symbolic name of the error code can be recovered using: - * programs/psa/psa_constant_name status */ + * tf-psa-crypto/programs/psa/psa_constant_name status */ #define PSA_CHECK(expr) \ do \ { \ diff --git a/tf-psa-crypto/programs/psa/hmac_demo.c b/tf-psa-crypto/programs/psa/hmac_demo.c index 683f3e59c9c6..63547de9429a 100644 --- a/tf-psa-crypto/programs/psa/hmac_demo.c +++ b/tf-psa-crypto/programs/psa/hmac_demo.c @@ -70,7 +70,7 @@ static void print_buf(const char *title, uint8_t *buf, size_t len) /* Run a PSA function and bail out if it fails. * The symbolic name of the error code can be recovered using: - * programs/psa/psa_constant_name status */ + * tf-psa-crypto/programs/psa/psa_constant_name status */ #define PSA_CHECK(expr) \ do \ { \ From e1d70a00d6d7d6a2f96def749a4db47269065e12 Mon Sep 17 00:00:00 2001 From: Harry Ramsey Date: Tue, 22 Oct 2024 16:40:36 +0100 Subject: [PATCH 03/20] Adjust psa program paths in Makefile This commit adjusts the paths of programs/psa to tf-psa-crypto/programs. Signed-off-by: Harry Ramsey --- programs/Makefile | 50 ++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/programs/Makefile b/programs/Makefile index 13fb79310285..7a390a4a2e4a 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -1,3 +1,5 @@ +TF-PSA-CRYPTO_PATH = ../tf-psa-crypto/ +TF-PSA-CRYPTO_PROGRAM_PATH = ../tf-psa-crypto/programs MBEDTLS_TEST_PATH = ../tests include ../scripts/common.make @@ -55,12 +57,12 @@ APPS = \ pkey/rsa_sign_pss \ pkey/rsa_verify \ pkey/rsa_verify_pss \ - psa/aead_demo \ - psa/crypto_examples \ - psa/hmac_demo \ - psa/key_ladder_demo \ - psa/psa_constant_names \ - psa/psa_hash \ + $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/aead_demo \ + $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/crypto_examples \ + $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/hmac_demo \ + $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/key_ladder_demo \ + $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/psa_constant_names \ + $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/psa_hash \ random/gen_entropy \ random/gen_random_ctr_drbg \ ssl/dtls_client \ @@ -252,29 +254,29 @@ pkey/rsa_encrypt$(EXEXT): pkey/rsa_encrypt.c $(DEP) echo " CC pkey/rsa_encrypt.c" $(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/rsa_encrypt.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ -psa/aead_demo$(EXEXT): psa/aead_demo.c $(DEP) - echo " CC psa/aead_demo.c" - $(CC) $(LOCAL_CFLAGS) $(CFLAGS) psa/aead_demo.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ +$(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/aead_demo$(EXEXT): $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/aead_demo.c $(DEP) + echo " CC $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/aead_demo.c" + $(CC) $(LOCAL_CFLAGS) $(CFLAGS) $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/aead_demo.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ -psa/crypto_examples$(EXEXT): psa/crypto_examples.c $(DEP) - echo " CC psa/crypto_examples.c" - $(CC) $(LOCAL_CFLAGS) $(CFLAGS) psa/crypto_examples.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ +$(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/crypto_examples$(EXEXT): $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/crypto_examples.c $(DEP) + echo " CC $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/crypto_examples.c" + $(CC) $(LOCAL_CFLAGS) $(CFLAGS) $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/crypto_examples.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ -psa/hmac_demo$(EXEXT): psa/hmac_demo.c $(DEP) - echo " CC psa/hmac_demo.c" - $(CC) $(LOCAL_CFLAGS) $(CFLAGS) psa/hmac_demo.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ +$(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/hmac_demo$(EXEXT): $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/hmac_demo.c $(DEP) + echo " CC $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/hmac_demo.c" + $(CC) $(LOCAL_CFLAGS) $(CFLAGS) $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/hmac_demo.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ -psa/key_ladder_demo$(EXEXT): psa/key_ladder_demo.c $(DEP) - echo " CC psa/key_ladder_demo.c" - $(CC) $(LOCAL_CFLAGS) $(CFLAGS) psa/key_ladder_demo.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ +$(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/key_ladder_demo$(EXEXT): $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/key_ladder_demo.c $(DEP) + echo " CC $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/key_ladder_demo.c" + $(CC) $(LOCAL_CFLAGS) $(CFLAGS) $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/key_ladder_demo.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ -psa/psa_constant_names$(EXEXT): psa/psa_constant_names.c psa/psa_constant_names_generated.c $(DEP) - echo " CC psa/psa_constant_names.c" - $(CC) $(LOCAL_CFLAGS) $(CFLAGS) psa/psa_constant_names.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ +$(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/psa_constant_names$(EXEXT): $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/psa_constant_names.c psa/psa_constant_names_generated.c $(DEP) + echo " CC $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/psa_constant_names.c" + $(CC) $(LOCAL_CFLAGS) $(CFLAGS) $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/psa_constant_names.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ -psa/psa_hash$(EXEXT): psa/psa_hash.c $(DEP) - echo " CC psa/psa_hash.c" - $(CC) $(LOCAL_CFLAGS) $(CFLAGS) psa/psa_hash.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ +$(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/psa_hash$(EXEXT): $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/psa_hash.c $(DEP) + echo " CC $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/psa_hash.c" + $(CC) $(LOCAL_CFLAGS) $(CFLAGS) $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/psa_hash.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ random/gen_entropy$(EXEXT): random/gen_entropy.c $(DEP) echo " CC random/gen_entropy.c" From d66fb8475ca2a4f49d6da991891bbf31b48cf379 Mon Sep 17 00:00:00 2001 From: Harry Ramsey Date: Tue, 29 Oct 2024 11:32:01 +0000 Subject: [PATCH 04/20] Adjust psa program paths in CMakeLists This commit adjusts the paths of programs/psa to tf-psa-crypto/programs in CMakeLists.txt. Signed-off-by: Harry Ramsey --- programs/CMakeLists.txt | 2 +- tf-psa-crypto/programs/psa/CMakeLists.txt | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/programs/CMakeLists.txt b/programs/CMakeLists.txt index aaf93ba38d26..87b9a1b5a732 100644 --- a/programs/CMakeLists.txt +++ b/programs/CMakeLists.txt @@ -8,7 +8,7 @@ if (NOT WIN32) endif() add_subdirectory(hash) add_subdirectory(pkey) -add_subdirectory(psa) +add_subdirectory(../tf-psa-crypto/programs/psa ../tf-psa-crypto/programs/psa) add_subdirectory(random) add_subdirectory(ssl) add_subdirectory(test) diff --git a/tf-psa-crypto/programs/psa/CMakeLists.txt b/tf-psa-crypto/programs/psa/CMakeLists.txt index 3c20a70993f1..3e5daca97312 100644 --- a/tf-psa-crypto/programs/psa/CMakeLists.txt +++ b/tf-psa-crypto/programs/psa/CMakeLists.txt @@ -14,14 +14,14 @@ if(GEN_FILES) ${CMAKE_CURRENT_BINARY_DIR}/psa_constant_names_generated.c COMMAND ${MBEDTLS_PYTHON_EXECUTABLE} - ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/generate_psa_constants.py + ${CMAKE_CURRENT_SOURCE_DIR}/../../../scripts/generate_psa_constants.py ${CMAKE_CURRENT_BINARY_DIR} WORKING_DIRECTORY - ${CMAKE_CURRENT_SOURCE_DIR}/../.. + ${CMAKE_CURRENT_SOURCE_DIR}/../../.. DEPENDS - ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/generate_psa_constants.py - ${CMAKE_CURRENT_SOURCE_DIR}/../../tf-psa-crypto/include/psa/crypto_values.h - ${CMAKE_CURRENT_SOURCE_DIR}/../../tf-psa-crypto/include/psa/crypto_extra.h + ${CMAKE_CURRENT_SOURCE_DIR}/../../../scripts/generate_psa_constants.py + ${CMAKE_CURRENT_SOURCE_DIR}/../../../tf-psa-crypto/include/psa/crypto_values.h + ${CMAKE_CURRENT_SOURCE_DIR}/../../../tf-psa-crypto/include/psa/crypto_extra.h ) else() link_to_source(psa_constant_names_generated.c) From c94cb70d588eae0d6a861115afc044b4e0288647 Mon Sep 17 00:00:00 2001 From: Harry Ramsey Date: Thu, 31 Oct 2024 14:28:53 +0000 Subject: [PATCH 05/20] Update paths in .sln file This commit updates the paths in generate_visualc_files.pl to update the generated .sln file with the new paths for psa programs. Signed-off-by: Harry Ramsey --- scripts/generate_visualc_files.pl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/generate_visualc_files.pl b/scripts/generate_visualc_files.pl index 76a6c32406c9..f6ab627fccea 100755 --- a/scripts/generate_visualc_files.pl +++ b/scripts/generate_visualc_files.pl @@ -21,7 +21,9 @@ my $vsx_sln_tpl_file = "scripts/data_files/vs2017-sln-template.sln"; my $vsx_sln_file = "$vsx_dir/mbedTLS.sln"; -my $programs_dir = 'programs'; +my $mbedtls_programs_dir = "programs"; +my $tfpsacrypto_programs_dir = "tf-psa-crypto/programs"; + my $mbedtls_header_dir = 'include/mbedtls'; my $drivers_builtin_header_dir = 'tf-psa-crypto/drivers/builtin/include/mbedtls'; my $psa_header_dir = 'tf-psa-crypto/include/psa'; @@ -122,7 +124,8 @@ sub check_dirs { && -d $test_header_dir && -d $tls_test_header_dir && -d $test_drivers_header_dir - && -d $programs_dir; + && -d $mbedtls_programs_dir + && -d $tfpsacrypto_programs_dir; } sub slurp_file { @@ -183,6 +186,7 @@ sub gen_app { sub get_app_list { my $makefile_contents = slurp_file('programs/Makefile'); + $makefile_contents =~ s/\$\(TF-PSA-CRYPTO_PROGRAM_PATH\)/..\/tf-psa-crypto\/programs/g; $makefile_contents =~ /\n\s*APPS\s*=[\\\s]*(.*?)(? Date: Mon, 4 Nov 2024 14:02:05 +0000 Subject: [PATCH 06/20] Refactor programs/Makefile This commit refactors the Makefile in the programs directory to remove unused variables and consistent naming schemes. Signed-off-by: Harry Ramsey --- programs/Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/programs/Makefile b/programs/Makefile index 7a390a4a2e4a..b48a006bb4c3 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -1,5 +1,4 @@ -TF-PSA-CRYPTO_PATH = ../tf-psa-crypto/ -TF-PSA-CRYPTO_PROGRAM_PATH = ../tf-psa-crypto/programs +TF-PSA-CRYPTO_CORE_PATH = ../tf-psa-crypto/programs MBEDTLS_TEST_PATH = ../tests include ../scripts/common.make From e1d6f74b922383e8ecceb3c37d1a8ad0f35c350e Mon Sep 17 00:00:00 2001 From: Harry Ramsey Date: Mon, 4 Nov 2024 14:51:35 +0000 Subject: [PATCH 07/20] Move generate_psa_constants.py to tf-psa-crypto This commit moves generate_psa_constants.py to tf-psa-crypto and updates the paths inside the script necessary for that move. Signed-off-by: Harry Ramsey --- programs/Makefile | 4 ++-- tf-psa-crypto/programs/psa/CMakeLists.txt | 6 +++--- tf-psa-crypto/scripts/framework_scripts_path.py | 17 +++++++++++++++++ .../scripts}/generate_psa_constants.py | 10 +++++----- 4 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 tf-psa-crypto/scripts/framework_scripts_path.py rename {scripts => tf-psa-crypto/scripts}/generate_psa_constants.py (96%) diff --git a/programs/Makefile b/programs/Makefile index b48a006bb4c3..d2cee1cdfa85 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -133,13 +133,13 @@ ${MBEDTLS_TEST_OBJS}: GENERATED_FILES = psa/psa_constant_names_generated.c test/query_config.c generated_files: $(GENERATED_FILES) -psa/psa_constant_names_generated.c: $(gen_file_dep) ../scripts/generate_psa_constants.py +psa/psa_constant_names_generated.c: $(gen_file_dep) ../tf-psa-crypto/scripts/generate_psa_constants.py psa/psa_constant_names_generated.c: $(gen_file_dep) ../tf-psa-crypto/include/psa/crypto_values.h psa/psa_constant_names_generated.c: $(gen_file_dep) ../tf-psa-crypto/include/psa/crypto_extra.h psa/psa_constant_names_generated.c: $(gen_file_dep) ../tf-psa-crypto/tests/suites/test_suite_psa_crypto_metadata.data psa/psa_constant_names_generated.c: echo " Gen $@" - $(PYTHON) ../scripts/generate_psa_constants.py + cd ../tf-psa-crypto; $(PYTHON) ../scripts/generate_psa_constants.py test/query_config.c: $(gen_file_dep) ../scripts/generate_query_config.pl ## The generated file only depends on the options that are present in mbedtls_config.h, diff --git a/tf-psa-crypto/programs/psa/CMakeLists.txt b/tf-psa-crypto/programs/psa/CMakeLists.txt index 3e5daca97312..625b6e1291cc 100644 --- a/tf-psa-crypto/programs/psa/CMakeLists.txt +++ b/tf-psa-crypto/programs/psa/CMakeLists.txt @@ -19,9 +19,9 @@ if(GEN_FILES) WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../../.. DEPENDS - ${CMAKE_CURRENT_SOURCE_DIR}/../../../scripts/generate_psa_constants.py - ${CMAKE_CURRENT_SOURCE_DIR}/../../../tf-psa-crypto/include/psa/crypto_values.h - ${CMAKE_CURRENT_SOURCE_DIR}/../../../tf-psa-crypto/include/psa/crypto_extra.h + ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/generate_psa_constants.py + ${CMAKE_CURRENT_SOURCE_DIR}/../../include/psa/crypto_values.h + ${CMAKE_CURRENT_SOURCE_DIR}/../../include/psa/crypto_extra.h ) else() link_to_source(psa_constant_names_generated.c) diff --git a/tf-psa-crypto/scripts/framework_scripts_path.py b/tf-psa-crypto/scripts/framework_scripts_path.py new file mode 100644 index 000000000000..4d4a440c23bf --- /dev/null +++ b/tf-psa-crypto/scripts/framework_scripts_path.py @@ -0,0 +1,17 @@ +"""Add our Python library directory to the module search path. + +Usage: + + import framework_scripts_path # pylint: disable=unused-import +""" + +# Copyright The Mbed TLS Contributors +# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later +# + +import os +import sys + +sys.path.append(os.path.join(os.path.dirname(__file__), + os.path.pardir, + 'framework', 'scripts')) diff --git a/scripts/generate_psa_constants.py b/tf-psa-crypto/scripts/generate_psa_constants.py similarity index 96% rename from scripts/generate_psa_constants.py rename to tf-psa-crypto/scripts/generate_psa_constants.py index a63636307ac0..a22e406e6f91 100755 --- a/scripts/generate_psa_constants.py +++ b/tf-psa-crypto/scripts/generate_psa_constants.py @@ -1,13 +1,13 @@ #!/usr/bin/env python3 """Generate psa_constant_names_generated.c -which is included by tf-psa-crypto/programs/psa/psa_constant_names.c. +which is included by programs/psa/psa_constant_names.c. The code generated by this module is only meant to be used in the context of that program. An argument passed to this script will modify the output directory where the file is written: -* by default (no arguments passed): writes to tf-psa-crypto/programs/psa/ +* by default (no arguments passed): writes to programs/psa/ * OUTPUT_FILE_DIR passed: writes to OUTPUT_FILE_DIR/ """ @@ -327,8 +327,8 @@ def generate_psa_constants(header_file_names, output_file_name): if __name__ == '__main__': build_tree.chdir_to_root() # Allow to change the directory where psa_constant_names_generated.c is written to. - OUTPUT_FILE_DIR = sys.argv[1] if len(sys.argv) == 2 else "tf-psa-crypto/programs/psa" + OUTPUT_FILE_DIR = sys.argv[1] if len(sys.argv) == 2 else "programs/psa" - generate_psa_constants(['tf-psa-crypto/include/psa/crypto_values.h', - 'tf-psa-crypto/include/psa/crypto_extra.h'], + generate_psa_constants(['include/psa/crypto_values.h', + 'include/psa/crypto_extra.h'], OUTPUT_FILE_DIR + '/psa_constant_names_generated.c') From 61372efe953bfb3e88cc63668008db0912500f0e Mon Sep 17 00:00:00 2001 From: Harry Ramsey Date: Mon, 4 Nov 2024 15:00:27 +0000 Subject: [PATCH 08/20] Refactor tests and programs comment This commit refactors comments refering to tf-psa-crypto for the correct path upon repo split. Signed-off-by: Harry Ramsey --- tests/psa-client-server/psasim/src/aut_psa_aead_encrypt.c | 2 +- tf-psa-crypto/programs/psa/aead_demo.c | 2 +- tf-psa-crypto/programs/psa/hmac_demo.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/psa-client-server/psasim/src/aut_psa_aead_encrypt.c b/tests/psa-client-server/psasim/src/aut_psa_aead_encrypt.c index ccdb62d20f48..64463f57fc83 100644 --- a/tests/psa-client-server/psasim/src/aut_psa_aead_encrypt.c +++ b/tests/psa-client-server/psasim/src/aut_psa_aead_encrypt.c @@ -47,7 +47,7 @@ void print_buf(const char *title, uint8_t *buf, size_t len) /* Run a PSA function and bail out if it fails. * The symbolic name of the error code can be recovered using: - * tf-psa-crypto/programs/psa/psa_constant_name status */ + * programs/psa/psa_constant_name status */ #define PSA_CHECK(expr) \ do \ { \ diff --git a/tf-psa-crypto/programs/psa/aead_demo.c b/tf-psa-crypto/programs/psa/aead_demo.c index e38b72a7f400..2d99e3cbec59 100644 --- a/tf-psa-crypto/programs/psa/aead_demo.c +++ b/tf-psa-crypto/programs/psa/aead_demo.c @@ -93,7 +93,7 @@ static void print_buf(const char *title, uint8_t *buf, size_t len) /* Run a PSA function and bail out if it fails. * The symbolic name of the error code can be recovered using: - * tf-psa-crypto/programs/psa/psa_constant_name status */ + * programs/psa/psa_constant_name status */ #define PSA_CHECK(expr) \ do \ { \ diff --git a/tf-psa-crypto/programs/psa/hmac_demo.c b/tf-psa-crypto/programs/psa/hmac_demo.c index 63547de9429a..683f3e59c9c6 100644 --- a/tf-psa-crypto/programs/psa/hmac_demo.c +++ b/tf-psa-crypto/programs/psa/hmac_demo.c @@ -70,7 +70,7 @@ static void print_buf(const char *title, uint8_t *buf, size_t len) /* Run a PSA function and bail out if it fails. * The symbolic name of the error code can be recovered using: - * tf-psa-crypto/programs/psa/psa_constant_name status */ + * programs/psa/psa_constant_name status */ #define PSA_CHECK(expr) \ do \ { \ From 91c0d4685f6212cbc56b1b559765595dbd21dbde Mon Sep 17 00:00:00 2001 From: Harry Ramsey Date: Mon, 4 Nov 2024 15:06:41 +0000 Subject: [PATCH 09/20] Use static paths in makefile for programs This commit uses static paths in the makefile to create programs since the script generate_visualc_files.pl cannot substitute variable paths. Signed-off-by: Harry Ramsey --- programs/Makefile | 52 ++++++++++++++++--------------- scripts/generate_visualc_files.pl | 1 - 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/programs/Makefile b/programs/Makefile index d2cee1cdfa85..3319d714c859 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -1,4 +1,3 @@ -TF-PSA-CRYPTO_CORE_PATH = ../tf-psa-crypto/programs MBEDTLS_TEST_PATH = ../tests include ../scripts/common.make @@ -30,6 +29,9 @@ endif ## be declared by appending with `APPS += ...` afterwards. ## See the get_app_list function in scripts/generate_visualc_files.pl and ## make sure to check that it still works if you tweak the format here. +## +## Note: Variables cannot be used to define an apps path. This cannot be +## substituted by the script generate_visualc_files.pl. APPS = \ aes/crypt_and_hash \ cipher/cipher_aead_demo \ @@ -56,12 +58,12 @@ APPS = \ pkey/rsa_sign_pss \ pkey/rsa_verify \ pkey/rsa_verify_pss \ - $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/aead_demo \ - $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/crypto_examples \ - $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/hmac_demo \ - $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/key_ladder_demo \ - $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/psa_constant_names \ - $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/psa_hash \ + ../tf-psa-crypto/programs/psa/aead_demo \ + ../tf-psa-crypto/programs/psa/crypto_examples \ + ../tf-psa-crypto/programs/psa/hmac_demo \ + ../tf-psa-crypto/programs/psa/key_ladder_demo \ + ../tf-psa-crypto/programs/psa/psa_constant_names \ + ../tf-psa-crypto/programs/psa/psa_hash \ random/gen_entropy \ random/gen_random_ctr_drbg \ ssl/dtls_client \ @@ -253,29 +255,29 @@ pkey/rsa_encrypt$(EXEXT): pkey/rsa_encrypt.c $(DEP) echo " CC pkey/rsa_encrypt.c" $(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/rsa_encrypt.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ -$(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/aead_demo$(EXEXT): $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/aead_demo.c $(DEP) - echo " CC $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/aead_demo.c" - $(CC) $(LOCAL_CFLAGS) $(CFLAGS) $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/aead_demo.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ +../tf-psa-crypto/programs/psa/aead_demo$(EXEXT): ../tf-psa-crypto/programs/psa/aead_demo.c $(DEP) + echo " CC ../tf-psa-crypto/programs/psa/aead_demo.c" + $(CC) $(LOCAL_CFLAGS) $(CFLAGS) ../tf-psa-crypto/programs/psa/aead_demo.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ -$(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/crypto_examples$(EXEXT): $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/crypto_examples.c $(DEP) - echo " CC $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/crypto_examples.c" - $(CC) $(LOCAL_CFLAGS) $(CFLAGS) $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/crypto_examples.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ +../tf-psa-crypto/programs/psa/crypto_examples$(EXEXT): ../tf-psa-crypto/programs/psa/crypto_examples.c $(DEP) + echo " CC ../tf-psa-crypto/programs/psa/crypto_examples.c" + $(CC) $(LOCAL_CFLAGS) $(CFLAGS) ../tf-psa-crypto/programs/psa/crypto_examples.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ -$(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/hmac_demo$(EXEXT): $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/hmac_demo.c $(DEP) - echo " CC $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/hmac_demo.c" - $(CC) $(LOCAL_CFLAGS) $(CFLAGS) $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/hmac_demo.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ +../tf-psa-crypto/programs/psa/hmac_demo$(EXEXT): ../tf-psa-crypto/programs/psa/hmac_demo.c $(DEP) + echo " CC ../tf-psa-crypto/programs/psa/hmac_demo.c" + $(CC) $(LOCAL_CFLAGS) $(CFLAGS) ../tf-psa-crypto/programs/psa/hmac_demo.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ -$(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/key_ladder_demo$(EXEXT): $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/key_ladder_demo.c $(DEP) - echo " CC $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/key_ladder_demo.c" - $(CC) $(LOCAL_CFLAGS) $(CFLAGS) $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/key_ladder_demo.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ +../tf-psa-crypto/programs/psa/key_ladder_demo$(EXEXT): ../tf-psa-crypto/programs/psa/key_ladder_demo.c $(DEP) + echo " CC ../tf-psa-crypto/programs/psa/key_ladder_demo.c" + $(CC) $(LOCAL_CFLAGS) $(CFLAGS) ../tf-psa-crypto/programs/psa/key_ladder_demo.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ -$(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/psa_constant_names$(EXEXT): $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/psa_constant_names.c psa/psa_constant_names_generated.c $(DEP) - echo " CC $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/psa_constant_names.c" - $(CC) $(LOCAL_CFLAGS) $(CFLAGS) $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/psa_constant_names.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ +../tf-psa-crypto/programs/psa/psa_constant_names$(EXEXT): ../tf-psa-crypto/programs/psa/psa_constant_names.c psa/psa_constant_names_generated.c $(DEP) + echo " CC ../tf-psa-crypto/programs/psa/psa_constant_names.c" + $(CC) $(LOCAL_CFLAGS) $(CFLAGS) ../tf-psa-crypto/programs/psa/psa_constant_names.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ -$(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/psa_hash$(EXEXT): $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/psa_hash.c $(DEP) - echo " CC $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/psa_hash.c" - $(CC) $(LOCAL_CFLAGS) $(CFLAGS) $(TF-PSA-CRYPTO_PROGRAM_PATH)/psa/psa_hash.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ +../tf-psa-crypto/programs/psa/psa_hash$(EXEXT): ../tf-psa-crypto/programs/psa/psa_hash.c $(DEP) + echo " CC ../tf-psa-crypto/programs/psa/psa_hash.c" + $(CC) $(LOCAL_CFLAGS) $(CFLAGS) ../tf-psa-crypto/programs/psa/psa_hash.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ random/gen_entropy$(EXEXT): random/gen_entropy.c $(DEP) echo " CC random/gen_entropy.c" diff --git a/scripts/generate_visualc_files.pl b/scripts/generate_visualc_files.pl index f6ab627fccea..d0fcb7d60f9e 100755 --- a/scripts/generate_visualc_files.pl +++ b/scripts/generate_visualc_files.pl @@ -186,7 +186,6 @@ sub gen_app { sub get_app_list { my $makefile_contents = slurp_file('programs/Makefile'); - $makefile_contents =~ s/\$\(TF-PSA-CRYPTO_PROGRAM_PATH\)/..\/tf-psa-crypto\/programs/g; $makefile_contents =~ /\n\s*APPS\s*=[\\\s]*(.*?)(? Date: Mon, 4 Nov 2024 16:41:22 +0000 Subject: [PATCH 10/20] Fix incorrect paths to generate_psa_constants.py This commit fixes incorrect paths to generate_psa_constants.py after being moves to tf-psa-crypto. Signed-off-by: Harry Ramsey --- programs/Makefile | 2 +- scripts/make_generated_files.bat | 2 +- tf-psa-crypto/scripts/framework_scripts_path.py | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/programs/Makefile b/programs/Makefile index 3319d714c859..7665929f8d52 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -141,7 +141,7 @@ psa/psa_constant_names_generated.c: $(gen_file_dep) ../tf-psa-crypto/include/psa psa/psa_constant_names_generated.c: $(gen_file_dep) ../tf-psa-crypto/tests/suites/test_suite_psa_crypto_metadata.data psa/psa_constant_names_generated.c: echo " Gen $@" - cd ../tf-psa-crypto; $(PYTHON) ../scripts/generate_psa_constants.py + cd ../tf-psa-crypto; $(PYTHON) ./scripts/generate_psa_constants.py test/query_config.c: $(gen_file_dep) ../scripts/generate_query_config.pl ## The generated file only depends on the options that are present in mbedtls_config.h, diff --git a/scripts/make_generated_files.bat b/scripts/make_generated_files.bat index 4612cc2d2556..4a9c7f40045a 100644 --- a/scripts/make_generated_files.bat +++ b/scripts/make_generated_files.bat @@ -19,7 +19,7 @@ python framework\scripts\generate_ssl_debug_helpers.py || exit /b 1 perl scripts\generate_visualc_files.pl || exit /b 1 @rem @@@@ programs\** @@@@ -python scripts\generate_psa_constants.py || exit /b 1 +python tf-psa-crypto\scripts\generate_psa_constants.py || exit /b 1 @rem @@@@ tests\** @@@@ python framework\scripts\generate_bignum_tests.py --directory tf-psa-crypto\tests\suites || exit /b 1 diff --git a/tf-psa-crypto/scripts/framework_scripts_path.py b/tf-psa-crypto/scripts/framework_scripts_path.py index 4d4a440c23bf..fd39ce3e9a29 100644 --- a/tf-psa-crypto/scripts/framework_scripts_path.py +++ b/tf-psa-crypto/scripts/framework_scripts_path.py @@ -13,5 +13,6 @@ import sys sys.path.append(os.path.join(os.path.dirname(__file__), + os.path.pardir, os.path.pardir, 'framework', 'scripts')) From e9e316e8c56c14ee8054d998e08bbcbeea2ec83f Mon Sep 17 00:00:00 2001 From: Harry Ramsey Date: Tue, 5 Nov 2024 06:17:58 +0000 Subject: [PATCH 11/20] Update path in programs/psa/CMakeList.txt This commit updates the path to the generate_psa_constants.py script in programs/psa/CMakeList.txt file. Signed-off-by: Harry Ramsey --- tf-psa-crypto/programs/psa/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tf-psa-crypto/programs/psa/CMakeLists.txt b/tf-psa-crypto/programs/psa/CMakeLists.txt index 625b6e1291cc..2356c81fc181 100644 --- a/tf-psa-crypto/programs/psa/CMakeLists.txt +++ b/tf-psa-crypto/programs/psa/CMakeLists.txt @@ -14,10 +14,10 @@ if(GEN_FILES) ${CMAKE_CURRENT_BINARY_DIR}/psa_constant_names_generated.c COMMAND ${MBEDTLS_PYTHON_EXECUTABLE} - ${CMAKE_CURRENT_SOURCE_DIR}/../../../scripts/generate_psa_constants.py + ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/generate_psa_constants.py ${CMAKE_CURRENT_BINARY_DIR} WORKING_DIRECTORY - ${CMAKE_CURRENT_SOURCE_DIR}/../../.. + ${CMAKE_CURRENT_SOURCE_DIR}/../.. DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../../scripts/generate_psa_constants.py ${CMAKE_CURRENT_SOURCE_DIR}/../../include/psa/crypto_values.h From 61811e6595b42143a7181c1e42b022ad94b4f49c Mon Sep 17 00:00:00 2001 From: Harry Ramsey Date: Tue, 5 Nov 2024 06:31:42 +0000 Subject: [PATCH 12/20] Update path in check-generated-files.sh This commit updates the path to generate_psa_constants.py in check-generated-files.sh Signed-off-by: Harry Ramsey --- tests/scripts/check-generated-files.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/scripts/check-generated-files.sh b/tests/scripts/check-generated-files.sh index 934276dc35ea..6e03ce4c2791 100755 --- a/tests/scripts/check-generated-files.sh +++ b/tests/scripts/check-generated-files.sh @@ -146,6 +146,7 @@ check() # directory in Mbed TLS that is not just a TF-PSA-Crypto submodule. if [ -d tf-psa-crypto ]; then cd tf-psa-crypto + check ./scripts/generate_psa_constants.py ./programs/psa/psa_constant_names_generated.c check ../framework/scripts/generate_bignum_tests.py $(../framework/scripts/generate_bignum_tests.py --list) check ../framework/scripts/generate_config_tests.py tests/suites/test_suite_config.psa_boolean.data check ../framework/scripts/generate_ecp_tests.py $(../framework/scripts/generate_ecp_tests.py --list) From cefc67242bb87842719eaca94c19b2a812432506 Mon Sep 17 00:00:00 2001 From: Harry Ramsey Date: Tue, 5 Nov 2024 06:43:36 +0000 Subject: [PATCH 13/20] Fix make_generated_files.bat This commit fixes make_generated_files.bat as it requires the user to be inside the tf-psa-directory to invoke generate_psa_constants.py. Signed-off-by: Harry Ramsey --- scripts/make_generated_files.bat | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/make_generated_files.bat b/scripts/make_generated_files.bat index 4a9c7f40045a..60313705f4da 100644 --- a/scripts/make_generated_files.bat +++ b/scripts/make_generated_files.bat @@ -19,7 +19,9 @@ python framework\scripts\generate_ssl_debug_helpers.py || exit /b 1 perl scripts\generate_visualc_files.pl || exit /b 1 @rem @@@@ programs\** @@@@ -python tf-psa-crypto\scripts\generate_psa_constants.py || exit /b 1 +cd tf-psa-crypto +python scripts\generate_psa_constants.py || exit /b 1 +cd .. @rem @@@@ tests\** @@@@ python framework\scripts\generate_bignum_tests.py --directory tf-psa-crypto\tests\suites || exit /b 1 From 8ee1b5d098a9dee96ceb20fa09fefed6a49a7892 Mon Sep 17 00:00:00 2001 From: Harry Ramsey Date: Wed, 6 Nov 2024 10:36:41 +0000 Subject: [PATCH 14/20] Update gitignore Update gitignore in programs and tf-psa-crypto following the move of multiple files. Signed-off-by: Harry Ramsey --- programs/.gitignore | 7 ------- tf-psa-crypto/.gitignore | 11 +++++++++++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/programs/.gitignore b/programs/.gitignore index e0c49873eee3..c3e61c16bd81 100644 --- a/programs/.gitignore +++ b/programs/.gitignore @@ -33,12 +33,6 @@ pkey/rsa_sign pkey/rsa_sign_pss pkey/rsa_verify pkey/rsa_verify_pss -psa/aead_demo -psa/crypto_examples -psa/hmac_demo -psa/key_ladder_demo -psa/psa_constant_names -psa/psa_hash random/gen_entropy random/gen_random_ctr_drbg ssl/dtls_client @@ -75,7 +69,6 @@ x509/req_app ###START_GENERATED_FILES### # Generated source files -/psa/psa_constant_names_generated.c /test/query_config.c # Generated data files diff --git a/tf-psa-crypto/.gitignore b/tf-psa-crypto/.gitignore index f3c7a7c5da68..02e241208bba 100644 --- a/tf-psa-crypto/.gitignore +++ b/tf-psa-crypto/.gitignore @@ -1 +1,12 @@ Makefile + +programs/psa/aead_demo +programs/psa/crypto_examples +programs/psa/hmac_demo +programs/psa/key_ladder_demo +programs/psa/psa_constant_names +programs/psa/psa_hash + +###START_GENERATED_FILES### +# Generated source files +programs/psa/psa_constant_names_generated.c From be20844c2326f6b5bf4fb9f8685c97016dfdf49a Mon Sep 17 00:00:00 2001 From: Harry Ramsey Date: Wed, 6 Nov 2024 10:52:57 +0000 Subject: [PATCH 15/20] Update path in run_demos.py This commit updates the path to programs in run_demos.py to tf-psa-crypto/programs. Signed-off-by: Harry Ramsey --- tests/scripts/run_demos.py | 2 +- tf-psa-crypto/programs/demo_common.sh | 137 ++++++++++++++++++++++++++ 2 files changed, 138 insertions(+), 1 deletion(-) create mode 100644 tf-psa-crypto/programs/demo_common.sh diff --git a/tests/scripts/run_demos.py b/tests/scripts/run_demos.py index 6a63d232fe43..75febcdd839e 100755 --- a/tests/scripts/run_demos.py +++ b/tests/scripts/run_demos.py @@ -44,7 +44,7 @@ def run_all_demos(quiet=False): Return True if all demos passed and False if a demo fails. """ - all_demos = glob.glob('programs/*/*_demo.sh') + all_demos = glob.glob('tf-psa-crypto/programs/*/*_demo.sh') if not all_demos: # Keep the message on one line. pylint: disable=line-too-long raise Exception('No demos found. run_demos needs to operate from the Mbed TLS toplevel directory.') diff --git a/tf-psa-crypto/programs/demo_common.sh b/tf-psa-crypto/programs/demo_common.sh new file mode 100644 index 000000000000..d8fcda55447d --- /dev/null +++ b/tf-psa-crypto/programs/demo_common.sh @@ -0,0 +1,137 @@ +## Common shell functions used by demo scripts programs/*/*.sh. + +## How to write a demo script +## ========================== +## +## Include this file near the top of each demo script: +## . "${0%/*}/../demo_common.sh" +## +## Start with a "msg" call that explains the purpose of the script. +## Then call the "depends_on" function to ensure that all config +## dependencies are met. +## +## As the last thing in the script, call the cleanup function. +## +## You can use the functions and variables described below. + +set -e -u + +## $root_dir is the root directory of the Mbed TLS source tree. +root_dir="${0%/*}" +# Find a nice path to the root directory, avoiding unnecessary "../". +# The code supports demo scripts nested up to 4 levels deep. +# The code works no matter where the demo script is relative to the current +# directory, even if it is called with a relative path. +n=4 # limit the search depth +while ! [ -d "$root_dir/programs" ] || ! [ -d "$root_dir/library" ]; do + if [ $n -eq 0 ]; then + echo >&2 "This doesn't seem to be an Mbed TLS source tree." + exit 125 + fi + n=$((n - 1)) + case $root_dir in + .) root_dir="..";; + ..|?*/..) root_dir="$root_dir/..";; + ?*/*) root_dir="${root_dir%/*}";; + /*) root_dir="/";; + *) root_dir=".";; + esac +done + +## $programs_dir is the directory containing the sample programs. +# Assume an in-tree build. +programs_dir="$root_dir/programs" + +## msg LINE... +## msg &2 < Date: Wed, 6 Nov 2024 11:14:13 +0000 Subject: [PATCH 16/20] Update programs/Makefile path This commit updates a recipe path in programs/Makefile. Signed-off-by: Harry Ramsey --- programs/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/Makefile b/programs/Makefile index 7665929f8d52..6f3394de6afb 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -135,7 +135,7 @@ ${MBEDTLS_TEST_OBJS}: GENERATED_FILES = psa/psa_constant_names_generated.c test/query_config.c generated_files: $(GENERATED_FILES) -psa/psa_constant_names_generated.c: $(gen_file_dep) ../tf-psa-crypto/scripts/generate_psa_constants.py +../tf-psa-crypto/psa/psa_constant_names_generated.c: $(gen_file_dep) ../tf-psa-crypto/scripts/generate_psa_constants.py psa/psa_constant_names_generated.c: $(gen_file_dep) ../tf-psa-crypto/include/psa/crypto_values.h psa/psa_constant_names_generated.c: $(gen_file_dep) ../tf-psa-crypto/include/psa/crypto_extra.h psa/psa_constant_names_generated.c: $(gen_file_dep) ../tf-psa-crypto/tests/suites/test_suite_psa_crypto_metadata.data From af0594198b880bf673d5fa7cebdc2f6c42216771 Mon Sep 17 00:00:00 2001 From: Harry Ramsey Date: Mon, 11 Nov 2024 09:57:30 +0000 Subject: [PATCH 17/20] Revert program CC output in Makefile This commit reverts tf-psa-crypto program CC output informing the user what file is being compiled. Signed-off-by: Harry Ramsey --- programs/Makefile | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/programs/Makefile b/programs/Makefile index 6f3394de6afb..0b3025dc9656 100644 --- a/programs/Makefile +++ b/programs/Makefile @@ -256,27 +256,27 @@ pkey/rsa_encrypt$(EXEXT): pkey/rsa_encrypt.c $(DEP) $(CC) $(LOCAL_CFLAGS) $(CFLAGS) pkey/rsa_encrypt.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ ../tf-psa-crypto/programs/psa/aead_demo$(EXEXT): ../tf-psa-crypto/programs/psa/aead_demo.c $(DEP) - echo " CC ../tf-psa-crypto/programs/psa/aead_demo.c" + echo " CC psa/aead_demo.c" $(CC) $(LOCAL_CFLAGS) $(CFLAGS) ../tf-psa-crypto/programs/psa/aead_demo.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ ../tf-psa-crypto/programs/psa/crypto_examples$(EXEXT): ../tf-psa-crypto/programs/psa/crypto_examples.c $(DEP) - echo " CC ../tf-psa-crypto/programs/psa/crypto_examples.c" + echo " CC psa/crypto_examples.c" $(CC) $(LOCAL_CFLAGS) $(CFLAGS) ../tf-psa-crypto/programs/psa/crypto_examples.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ ../tf-psa-crypto/programs/psa/hmac_demo$(EXEXT): ../tf-psa-crypto/programs/psa/hmac_demo.c $(DEP) - echo " CC ../tf-psa-crypto/programs/psa/hmac_demo.c" + echo " CC psa/hmac_demo.c" $(CC) $(LOCAL_CFLAGS) $(CFLAGS) ../tf-psa-crypto/programs/psa/hmac_demo.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ ../tf-psa-crypto/programs/psa/key_ladder_demo$(EXEXT): ../tf-psa-crypto/programs/psa/key_ladder_demo.c $(DEP) - echo " CC ../tf-psa-crypto/programs/psa/key_ladder_demo.c" + echo " CC psa/key_ladder_demo.c" $(CC) $(LOCAL_CFLAGS) $(CFLAGS) ../tf-psa-crypto/programs/psa/key_ladder_demo.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ ../tf-psa-crypto/programs/psa/psa_constant_names$(EXEXT): ../tf-psa-crypto/programs/psa/psa_constant_names.c psa/psa_constant_names_generated.c $(DEP) - echo " CC ../tf-psa-crypto/programs/psa/psa_constant_names.c" + echo " CC psa/psa_constant_names.c" $(CC) $(LOCAL_CFLAGS) $(CFLAGS) ../tf-psa-crypto/programs/psa/psa_constant_names.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ ../tf-psa-crypto/programs/psa/psa_hash$(EXEXT): ../tf-psa-crypto/programs/psa/psa_hash.c $(DEP) - echo " CC ../tf-psa-crypto/programs/psa/psa_hash.c" + echo " CC psa/psa_hash.c" $(CC) $(LOCAL_CFLAGS) $(CFLAGS) ../tf-psa-crypto/programs/psa/psa_hash.c $(LOCAL_LDFLAGS) $(LDFLAGS) -o $@ random/gen_entropy$(EXEXT): random/gen_entropy.c $(DEP) From ff57cc56ba70dda7c0c1e95f2fb33d2c4102283e Mon Sep 17 00:00:00 2001 From: Harry Ramsey Date: Wed, 20 Nov 2024 09:29:08 +0000 Subject: [PATCH 18/20] Move program gitignore to tf-psa-crypto/programs This commit moves programs from tf-psa-crypto/.gitignore to tf-psa-crypto/programs/.gitignore. Signed-off-by: Harry Ramsey --- tf-psa-crypto/.gitignore | 11 ----------- tf-psa-crypto/programs/.gitignore | 10 ++++++++++ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/tf-psa-crypto/.gitignore b/tf-psa-crypto/.gitignore index 02e241208bba..f3c7a7c5da68 100644 --- a/tf-psa-crypto/.gitignore +++ b/tf-psa-crypto/.gitignore @@ -1,12 +1 @@ Makefile - -programs/psa/aead_demo -programs/psa/crypto_examples -programs/psa/hmac_demo -programs/psa/key_ladder_demo -programs/psa/psa_constant_names -programs/psa/psa_hash - -###START_GENERATED_FILES### -# Generated source files -programs/psa/psa_constant_names_generated.c diff --git a/tf-psa-crypto/programs/.gitignore b/tf-psa-crypto/programs/.gitignore index e69de29bb2d1..55c6e56a112b 100644 --- a/tf-psa-crypto/programs/.gitignore +++ b/tf-psa-crypto/programs/.gitignore @@ -0,0 +1,10 @@ +psa/aead_demo +psa/crypto_examples +psa/hmac_demo +psa/key_ladder_demo +psa/psa_constant_names +psa/psa_hash + +###START_GENERATED_FILES### +# Generated source files +psa/psa_constant_names_generated.c From 885ce72ca658973a0445a706f9fa45a1c214668e Mon Sep 17 00:00:00 2001 From: Harry Ramsey Date: Wed, 20 Nov 2024 09:52:37 +0000 Subject: [PATCH 19/20] Remove duplicate demo_common.sh in tf-psa-crypto This commit removes the duplicate demo_common.sh file in tf-psa-crypto and instead use the demo_common.sh file in mbedtls/programs. Signed-off-by: Harry Ramsey --- tf-psa-crypto/programs/demo_common.sh | 137 ------------------ tf-psa-crypto/programs/psa/key_ladder_demo.sh | 2 +- tf-psa-crypto/programs/psa/psa_hash_demo.sh | 2 +- 3 files changed, 2 insertions(+), 139 deletions(-) delete mode 100644 tf-psa-crypto/programs/demo_common.sh diff --git a/tf-psa-crypto/programs/demo_common.sh b/tf-psa-crypto/programs/demo_common.sh deleted file mode 100644 index d8fcda55447d..000000000000 --- a/tf-psa-crypto/programs/demo_common.sh +++ /dev/null @@ -1,137 +0,0 @@ -## Common shell functions used by demo scripts programs/*/*.sh. - -## How to write a demo script -## ========================== -## -## Include this file near the top of each demo script: -## . "${0%/*}/../demo_common.sh" -## -## Start with a "msg" call that explains the purpose of the script. -## Then call the "depends_on" function to ensure that all config -## dependencies are met. -## -## As the last thing in the script, call the cleanup function. -## -## You can use the functions and variables described below. - -set -e -u - -## $root_dir is the root directory of the Mbed TLS source tree. -root_dir="${0%/*}" -# Find a nice path to the root directory, avoiding unnecessary "../". -# The code supports demo scripts nested up to 4 levels deep. -# The code works no matter where the demo script is relative to the current -# directory, even if it is called with a relative path. -n=4 # limit the search depth -while ! [ -d "$root_dir/programs" ] || ! [ -d "$root_dir/library" ]; do - if [ $n -eq 0 ]; then - echo >&2 "This doesn't seem to be an Mbed TLS source tree." - exit 125 - fi - n=$((n - 1)) - case $root_dir in - .) root_dir="..";; - ..|?*/..) root_dir="$root_dir/..";; - ?*/*) root_dir="${root_dir%/*}";; - /*) root_dir="/";; - *) root_dir=".";; - esac -done - -## $programs_dir is the directory containing the sample programs. -# Assume an in-tree build. -programs_dir="$root_dir/programs" - -## msg LINE... -## msg &2 < Date: Wed, 20 Nov 2024 10:19:27 +0000 Subject: [PATCH 20/20] Concatenate program demos between Mbed TLS and TF-PSA-Crypto This commit concatenates the running of program demos between Mbed TLS and TF-PSA-Crypto. Signed-off-by: Harry Ramsey --- tests/scripts/run_demos.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/scripts/run_demos.py b/tests/scripts/run_demos.py index 75febcdd839e..f9a81001419a 100755 --- a/tests/scripts/run_demos.py +++ b/tests/scripts/run_demos.py @@ -44,7 +44,9 @@ def run_all_demos(quiet=False): Return True if all demos passed and False if a demo fails. """ - all_demos = glob.glob('tf-psa-crypto/programs/*/*_demo.sh') + mbedtls_demos = glob.glob('programs/*/*_demo.sh') + tf_psa_crypto_demos = glob.glob('tf-psa-crypto/programs/*/*_demo.sh') + all_demos = mbedtls_demos + tf_psa_crypto_demos if not all_demos: # Keep the message on one line. pylint: disable=line-too-long raise Exception('No demos found. run_demos needs to operate from the Mbed TLS toplevel directory.')