From 2808d0cd7110d969f2a63fcbf09e39980c505ff6 Mon Sep 17 00:00:00 2001 From: Elena Uziunaite Date: Thu, 24 Oct 2024 15:08:15 +0100 Subject: [PATCH 01/11] Add psa_or_3_6_feature_macro function Signed-off-by: Elena Uziunaite --- scripts/mbedtls_framework/test_case.py | 44 +++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/scripts/mbedtls_framework/test_case.py b/scripts/mbedtls_framework/test_case.py index 6ed5e849d..5ad1737af 100644 --- a/scripts/mbedtls_framework/test_case.py +++ b/scripts/mbedtls_framework/test_case.py @@ -10,12 +10,34 @@ import os import sys from typing import Iterable, List, Optional +from . import build_tree +from . import psa_information from . import typing_util +hashes_3_6 = { + "PSA_WANT_ALG_MD5" : "MBEDTLS_MD_CAN_MD5", + "PSA_WANT_ALG_RIPEMD160" : "MBEDTLS_MD_CAN_RIPEMD160", + "PSA_WANT_ALG_SHA_1" : "MBEDTLS_MD_CAN_SHA1", + "PSA_WANT_ALG_SHA_224" : "MBEDTLS_MD_CAN_SHA224", + "PSA_WANT_ALG_SHA_256" : "MBEDTLS_MD_CAN_SHA256", + "PSA_WANT_ALG_SHA_384" : "MBEDTLS_MD_CAN_SHA384", + "PSA_WANT_ALG_SHA_512" : "MBEDTLS_MD_CAN_SHA512", + "PSA_WANT_ALG_SHA3_224" : "MBEDTLS_MD_CAN_SHA3_224", + "PSA_WANT_ALG_SHA3_256" : "MBEDTLS_MD_CAN_SHA3_256", + "PSA_WANT_ALG_SHA3_384" : "MBEDTLS_MD_CAN_SHA3_384", + "PSA_WANT_ALG_SHA3_512" : "MBEDTLS_MD_CAN_SHA3_512" +} + +pk_macros_3_6 = { + "PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY" : "MBEDTLS_PK_HAVE_ECC_KEYS", + "PSA_HAVE_ALG_SOME_ECDSA" : "MBEDTLS_PK_CAN_ECDSA_SOME", + "PSA_HAVE_ALG_ECDSA_SIGN" : "MBEDTLS_PK_CAN_ECDSA_SIGN", + "PSA_HAVE_ALG_ECSA_VERIFY" : "MBEDTS_PK_CAN_ECDSA_VERIFY" +} + def hex_string(data: bytes) -> str: return '"' + binascii.hexlify(data).decode('ascii') + '"' - class MissingDescription(Exception): pass @@ -89,3 +111,23 @@ def write_data_file(filename: str, tc.write(out) out.write('\n# End of automatically generated file.\n') os.replace(tempfile, filename) + +def psa_or_3_6_feature_macro(psa_alg: str, + domain_3_6: str) -> str: + + if domain_3_6 == "DOMAIN_3_6_PSA" or not build_tree.is_mbedtls_3_6(): + if psa_alg in pk_macros_3_6 or psa_alg in hashes_3_6: + return psa_alg + elif psa_alg.startswith('PSA_ALG_') and psa_alg[8:] in ['MD5', 'RIPEMD160', 'SHA_1', 'SHA_224', + 'SHA_256', 'SHA_384', 'SHA_512', 'SHA3_224', + 'SHA3_256', 'SHA3_384', 'SHA3_512']: + return psa_information.psa_want_symbol(psa_alg) + + if psa_alg in hashes_3_6: + return hashes_3_6[psa_alg] + if psa_information.psa_want_symbol(psa_alg) in hashes_3_6: + return hashes_3_6[psa_information.psa_want_symbol(psa_alg)] + if psa_alg in pk_macros_3_6: + return pk_macros_3_6[psa_alg] + + raise ValueError('Unable to determine dependency symbol for ' + psa_alg) From 9cfdbe933ef77cf3743773a4aa128e1f0733ea54 Mon Sep 17 00:00:00 2001 From: Elena Uziunaite Date: Thu, 24 Oct 2024 15:47:08 +0100 Subject: [PATCH 02/11] Undo temporary solution Signed-off-by: Elena Uziunaite --- scripts/generate_config_tests.py | 8 +------- scripts/generate_pkcs7_tests.py | 9 ++------- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/scripts/generate_config_tests.py b/scripts/generate_config_tests.py index 28690cb3f..4e5ae54f8 100755 --- a/scripts/generate_config_tests.py +++ b/scripts/generate_config_tests.py @@ -14,7 +14,6 @@ import config from mbedtls_framework import config_common from mbedtls_framework import test_case from mbedtls_framework import test_data_generation -from mbedtls_framework import build_tree def single_setting_case(setting: config_common.Setting, when_on: bool, @@ -88,12 +87,7 @@ def dependencies_of_setting(cfg: config_common.Config, if name.startswith('MBEDTLS_CIPHER_PADDING_'): return 'MBEDTLS_CIPHER_C:MBEDTLS_CIPHER_MODE_CBC' if name.startswith('MBEDTLS_PK_PARSE_EC_'): - #temporary solution to determine correct dependency macros between 3.6 and 4.0 - #see issue #51 in mbedtls-framework - if build_tree.is_mbedtls_3_6(): - return 'MBEDTLS_PK_C:MBEDTLS_PK_HAVE_ECC_KEYS' - else: - return 'MBEDTLS_PK_C:PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY' + return 'MBEDTLS_PK_C:' + test_case.psa_or_3_6_feature_macro('PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY','') # For TLS settings, insist on having them once off and once on in # a configuration where both client support and server support are diff --git a/scripts/generate_pkcs7_tests.py b/scripts/generate_pkcs7_tests.py index e79539d0c..6e6fd987d 100755 --- a/scripts/generate_pkcs7_tests.py +++ b/scripts/generate_pkcs7_tests.py @@ -16,7 +16,7 @@ Given a valid DER pkcs7 file add tests to the test_suite_pkcs7.data file import sys from os.path import exists -from mbedtls_framework import build_tree +from mbedtls_framework import test_case PKCS7_TEST_FILE = "../suites/test_suite_pkcs7.data" @@ -38,12 +38,7 @@ class TestData: Take in test_suite_pkcs7.data file. Allow for new tests to be added. """ - #temporary solution to determine correct dependency macros between 3.6 and 4.0 - #see issue #51 in mbedtls-framework - if build_tree.is_mbedtls_3_6(): - mandatory_dep = "MBEDTLS_MD_CAN_SHA256" - else: - mandatory_dep = "PSA_WANT_ALG_SHA_256" + mandatory_dep = test_case.psa_or_3_6_feature_macro("PSA_ALG_SHA_256", "") test_name = "PKCS7 Parse Failure Invalid ASN1" test_function = "pkcs7_asn1_fail:" From 223bdffd6b00d36d141a98151e06be9a7a4192be Mon Sep 17 00:00:00 2001 From: Elena Uziunaite Date: Thu, 24 Oct 2024 16:33:14 +0100 Subject: [PATCH 03/11] Add a short description Signed-off-by: Elena Uziunaite --- scripts/mbedtls_framework/test_case.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/mbedtls_framework/test_case.py b/scripts/mbedtls_framework/test_case.py index 5ad1737af..d71014eca 100644 --- a/scripts/mbedtls_framework/test_case.py +++ b/scripts/mbedtls_framework/test_case.py @@ -114,6 +114,10 @@ def write_data_file(filename: str, def psa_or_3_6_feature_macro(psa_alg: str, domain_3_6: str) -> str: + """Determine the dependency symbol for a given psa_alg based on + the domain and Mbed TLS version. For more information about the domains, + and MBEDTLS_MD_CAN_ prefixed symbols, see transition-guards.md. + """ if domain_3_6 == "DOMAIN_3_6_PSA" or not build_tree.is_mbedtls_3_6(): if psa_alg in pk_macros_3_6 or psa_alg in hashes_3_6: From 4788a00df91d16357b438b5e4828bb7e7088bc43 Mon Sep 17 00:00:00 2001 From: Elena Uziunaite Date: Fri, 25 Oct 2024 12:52:44 +0100 Subject: [PATCH 04/11] Fix code style Signed-off-by: Elena Uziunaite --- scripts/generate_config_tests.py | 3 ++- scripts/mbedtls_framework/test_case.py | 25 +++++++++++++------------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/scripts/generate_config_tests.py b/scripts/generate_config_tests.py index 4e5ae54f8..e29910add 100755 --- a/scripts/generate_config_tests.py +++ b/scripts/generate_config_tests.py @@ -87,7 +87,8 @@ def dependencies_of_setting(cfg: config_common.Config, if name.startswith('MBEDTLS_CIPHER_PADDING_'): return 'MBEDTLS_CIPHER_C:MBEDTLS_CIPHER_MODE_CBC' if name.startswith('MBEDTLS_PK_PARSE_EC_'): - return 'MBEDTLS_PK_C:' + test_case.psa_or_3_6_feature_macro('PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY','') + return 'MBEDTLS_PK_C:' + test_case.psa_or_3_6_feature_macro( + 'PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY', '') # For TLS settings, insist on having them once off and once on in # a configuration where both client support and server support are diff --git a/scripts/mbedtls_framework/test_case.py b/scripts/mbedtls_framework/test_case.py index d71014eca..2ffe8e3f5 100644 --- a/scripts/mbedtls_framework/test_case.py +++ b/scripts/mbedtls_framework/test_case.py @@ -14,7 +14,7 @@ from . import build_tree from . import psa_information from . import typing_util -hashes_3_6 = { +HASHES_3_6 = { "PSA_WANT_ALG_MD5" : "MBEDTLS_MD_CAN_MD5", "PSA_WANT_ALG_RIPEMD160" : "MBEDTLS_MD_CAN_RIPEMD160", "PSA_WANT_ALG_SHA_1" : "MBEDTLS_MD_CAN_SHA1", @@ -28,7 +28,7 @@ hashes_3_6 = { "PSA_WANT_ALG_SHA3_512" : "MBEDTLS_MD_CAN_SHA3_512" } -pk_macros_3_6 = { +PK_MACROS_3_6 = { "PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY" : "MBEDTLS_PK_HAVE_ECC_KEYS", "PSA_HAVE_ALG_SOME_ECDSA" : "MBEDTLS_PK_CAN_ECDSA_SOME", "PSA_HAVE_ALG_ECDSA_SIGN" : "MBEDTLS_PK_CAN_ECDSA_SIGN", @@ -120,18 +120,19 @@ def psa_or_3_6_feature_macro(psa_alg: str, """ if domain_3_6 == "DOMAIN_3_6_PSA" or not build_tree.is_mbedtls_3_6(): - if psa_alg in pk_macros_3_6 or psa_alg in hashes_3_6: + if psa_alg in PK_MACROS_3_6 or psa_alg in HASHES_3_6: return psa_alg - elif psa_alg.startswith('PSA_ALG_') and psa_alg[8:] in ['MD5', 'RIPEMD160', 'SHA_1', 'SHA_224', - 'SHA_256', 'SHA_384', 'SHA_512', 'SHA3_224', - 'SHA3_256', 'SHA3_384', 'SHA3_512']: + if psa_alg.startswith('PSA_ALG_') and \ + psa_alg[8:] in ['MD5', 'RIPEMD160', 'SHA_1', 'SHA_224', 'SHA_256', + 'SHA_384', 'SHA_512', 'SHA3_224', + 'SHA3_256', 'SHA3_384', 'SHA3_512']: return psa_information.psa_want_symbol(psa_alg) - if psa_alg in hashes_3_6: - return hashes_3_6[psa_alg] - if psa_information.psa_want_symbol(psa_alg) in hashes_3_6: - return hashes_3_6[psa_information.psa_want_symbol(psa_alg)] - if psa_alg in pk_macros_3_6: - return pk_macros_3_6[psa_alg] + if psa_alg in HASHES_3_6: + return HASHES_3_6[psa_alg] + if psa_information.psa_want_symbol(psa_alg) in HASHES_3_6: + return HASHES_3_6[psa_information.psa_want_symbol(psa_alg)] + if psa_alg in PK_MACROS_3_6: + return PK_MACROS_3_6[psa_alg] raise ValueError('Unable to determine dependency symbol for ' + psa_alg) From 480ce84563ab8e30604b9b6e0bc5f02def7d1f61 Mon Sep 17 00:00:00 2001 From: Elena Uziunaite Date: Fri, 1 Nov 2024 13:38:49 +0000 Subject: [PATCH 05/11] Edit HASHES_3_6 and PK_MACROS_3_6 Signed-off-by: Elena Uziunaite --- scripts/mbedtls_framework/test_case.py | 27 ++++++++++++-------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/scripts/mbedtls_framework/test_case.py b/scripts/mbedtls_framework/test_case.py index 2ffe8e3f5..417bc1ca4 100644 --- a/scripts/mbedtls_framework/test_case.py +++ b/scripts/mbedtls_framework/test_case.py @@ -15,24 +15,21 @@ from . import psa_information from . import typing_util HASHES_3_6 = { - "PSA_WANT_ALG_MD5" : "MBEDTLS_MD_CAN_MD5", - "PSA_WANT_ALG_RIPEMD160" : "MBEDTLS_MD_CAN_RIPEMD160", - "PSA_WANT_ALG_SHA_1" : "MBEDTLS_MD_CAN_SHA1", - "PSA_WANT_ALG_SHA_224" : "MBEDTLS_MD_CAN_SHA224", - "PSA_WANT_ALG_SHA_256" : "MBEDTLS_MD_CAN_SHA256", - "PSA_WANT_ALG_SHA_384" : "MBEDTLS_MD_CAN_SHA384", - "PSA_WANT_ALG_SHA_512" : "MBEDTLS_MD_CAN_SHA512", - "PSA_WANT_ALG_SHA3_224" : "MBEDTLS_MD_CAN_SHA3_224", - "PSA_WANT_ALG_SHA3_256" : "MBEDTLS_MD_CAN_SHA3_256", - "PSA_WANT_ALG_SHA3_384" : "MBEDTLS_MD_CAN_SHA3_384", - "PSA_WANT_ALG_SHA3_512" : "MBEDTLS_MD_CAN_SHA3_512" + "PSA_ALG_MD5" : "MBEDTLS_MD_CAN_MD5", + "PSA_ALG_RIPEMD160" : "MBEDTLS_MD_CAN_RIPEMD160", + "PSA_ALG_SHA_1" : "MBEDTLS_MD_CAN_SHA1", + "PSA_ALG_SHA_224" : "MBEDTLS_MD_CAN_SHA224", + "PSA_ALG_SHA_256" : "MBEDTLS_MD_CAN_SHA256", + "PSA_ALG_SHA_384" : "MBEDTLS_MD_CAN_SHA384", + "PSA_ALG_SHA_512" : "MBEDTLS_MD_CAN_SHA512", + "PSA_ALG_SHA3_224" : "MBEDTLS_MD_CAN_SHA3_224", + "PSA_ALG_SHA3_256" : "MBEDTLS_MD_CAN_SHA3_256", + "PSA_ALG_SHA3_384" : "MBEDTLS_MD_CAN_SHA3_384", + "PSA_ALG_SHA3_512" : "MBEDTLS_MD_CAN_SHA3_512" } PK_MACROS_3_6 = { - "PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY" : "MBEDTLS_PK_HAVE_ECC_KEYS", - "PSA_HAVE_ALG_SOME_ECDSA" : "MBEDTLS_PK_CAN_ECDSA_SOME", - "PSA_HAVE_ALG_ECDSA_SIGN" : "MBEDTLS_PK_CAN_ECDSA_SIGN", - "PSA_HAVE_ALG_ECSA_VERIFY" : "MBEDTS_PK_CAN_ECDSA_VERIFY" + "PSA_KEY_TYPE_ECC_PUBLIC_KEY" : "MBEDTLS_PK_HAVE_ECC_KEYS" } def hex_string(data: bytes) -> str: From d278ec4beba841e5f027dd079ffde6ec981b3007 Mon Sep 17 00:00:00 2001 From: Elena Uziunaite Date: Fri, 1 Nov 2024 13:48:07 +0000 Subject: [PATCH 06/11] Introduce Domain_3_6 Signed-off-by: Elena Uziunaite --- scripts/mbedtls_framework/test_case.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/scripts/mbedtls_framework/test_case.py b/scripts/mbedtls_framework/test_case.py index 417bc1ca4..dd9b63168 100644 --- a/scripts/mbedtls_framework/test_case.py +++ b/scripts/mbedtls_framework/test_case.py @@ -9,6 +9,7 @@ import binascii import os import sys from typing import Iterable, List, Optional +from enum import Enum from . import build_tree from . import psa_information @@ -32,6 +33,12 @@ PK_MACROS_3_6 = { "PSA_KEY_TYPE_ECC_PUBLIC_KEY" : "MBEDTLS_PK_HAVE_ECC_KEYS" } +class Domain_3_6(Enum): + PSA = 1 + TLS_1_3_ONLY = 2 + USE_PSA = 3 + LEGACY = 4 + def hex_string(data: bytes) -> str: return '"' + binascii.hexlify(data).decode('ascii') + '"' @@ -110,13 +117,13 @@ def write_data_file(filename: str, os.replace(tempfile, filename) def psa_or_3_6_feature_macro(psa_alg: str, - domain_3_6: str) -> str: + domain_3_6: Domain_3_6) -> str: """Determine the dependency symbol for a given psa_alg based on the domain and Mbed TLS version. For more information about the domains, and MBEDTLS_MD_CAN_ prefixed symbols, see transition-guards.md. """ - if domain_3_6 == "DOMAIN_3_6_PSA" or not build_tree.is_mbedtls_3_6(): + if domain_3_6 == Domain_3_6.PSA or domain_3_6 == Domain_3_6.TLS_1_3_ONLY or not build_tree.is_mbedtls_3_6(): if psa_alg in PK_MACROS_3_6 or psa_alg in HASHES_3_6: return psa_alg if psa_alg.startswith('PSA_ALG_') and \ @@ -129,7 +136,9 @@ def psa_or_3_6_feature_macro(psa_alg: str, return HASHES_3_6[psa_alg] if psa_information.psa_want_symbol(psa_alg) in HASHES_3_6: return HASHES_3_6[psa_information.psa_want_symbol(psa_alg)] - if psa_alg in PK_MACROS_3_6: - return PK_MACROS_3_6[psa_alg] - raise ValueError('Unable to determine dependency symbol for ' + psa_alg) + if domain_3_6 == Domain_3_6.USE_PSA: + if psa_alg in PK_MACROS_3_6: + return PK_MACROS_3_6[psa_alg] + + raise ValueError(f'Unable to determine dependency symbol for {psa_alg} in {domain_3_6}') From 66d6789a17c52c388eab8f6bbe942bc41830cc72 Mon Sep 17 00:00:00 2001 From: Elena Uziunaite Date: Fri, 1 Nov 2024 13:49:37 +0000 Subject: [PATCH 07/11] Change psa_alg to psa_name Signed-off-by: Elena Uziunaite --- scripts/mbedtls_framework/test_case.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/scripts/mbedtls_framework/test_case.py b/scripts/mbedtls_framework/test_case.py index dd9b63168..98ed3bf72 100644 --- a/scripts/mbedtls_framework/test_case.py +++ b/scripts/mbedtls_framework/test_case.py @@ -116,7 +116,7 @@ def write_data_file(filename: str, out.write('\n# End of automatically generated file.\n') os.replace(tempfile, filename) -def psa_or_3_6_feature_macro(psa_alg: str, +def psa_or_3_6_feature_macro(psa_name: str, domain_3_6: Domain_3_6) -> str: """Determine the dependency symbol for a given psa_alg based on the domain and Mbed TLS version. For more information about the domains, @@ -124,21 +124,21 @@ def psa_or_3_6_feature_macro(psa_alg: str, """ if domain_3_6 == Domain_3_6.PSA or domain_3_6 == Domain_3_6.TLS_1_3_ONLY or not build_tree.is_mbedtls_3_6(): - if psa_alg in PK_MACROS_3_6 or psa_alg in HASHES_3_6: - return psa_alg - if psa_alg.startswith('PSA_ALG_') and \ - psa_alg[8:] in ['MD5', 'RIPEMD160', 'SHA_1', 'SHA_224', 'SHA_256', + if psa_name in PK_MACROS_3_6 or psa_name in HASHES_3_6: + return psa_name + if psa_name.startswith('PSA_ALG_') and \ + psa_name[8:] in ['MD5', 'RIPEMD160', 'SHA_1', 'SHA_224', 'SHA_256', 'SHA_384', 'SHA_512', 'SHA3_224', 'SHA3_256', 'SHA3_384', 'SHA3_512']: - return psa_information.psa_want_symbol(psa_alg) + return psa_information.psa_want_symbol(psa_name) - if psa_alg in HASHES_3_6: - return HASHES_3_6[psa_alg] - if psa_information.psa_want_symbol(psa_alg) in HASHES_3_6: - return HASHES_3_6[psa_information.psa_want_symbol(psa_alg)] + if psa_name in HASHES_3_6: + return HASHES_3_6[psa_name] + if psa_information.psa_want_symbol(psa_name) in HASHES_3_6: + return HASHES_3_6[psa_information.psa_want_symbol(psa_name)] if domain_3_6 == Domain_3_6.USE_PSA: - if psa_alg in PK_MACROS_3_6: - return PK_MACROS_3_6[psa_alg] + if psa_name in PK_MACROS_3_6: + return PK_MACROS_3_6[psa_name] - raise ValueError(f'Unable to determine dependency symbol for {psa_alg} in {domain_3_6}') + raise ValueError(f'Unable to determine dependency symbol for {psa_name} in {domain_3_6}') From cb855d780c4642e0cdba5fa1e01d03909aded981 Mon Sep 17 00:00:00 2001 From: Elena Uziunaite Date: Fri, 1 Nov 2024 13:58:12 +0000 Subject: [PATCH 08/11] Clean up psa_or_3_6_feature_macro Signed-off-by: Elena Uziunaite --- scripts/mbedtls_framework/test_case.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/scripts/mbedtls_framework/test_case.py b/scripts/mbedtls_framework/test_case.py index 98ed3bf72..276eba524 100644 --- a/scripts/mbedtls_framework/test_case.py +++ b/scripts/mbedtls_framework/test_case.py @@ -121,24 +121,18 @@ def psa_or_3_6_feature_macro(psa_name: str, """Determine the dependency symbol for a given psa_alg based on the domain and Mbed TLS version. For more information about the domains, and MBEDTLS_MD_CAN_ prefixed symbols, see transition-guards.md. + Currently works with hashes and PK symbols only. """ if domain_3_6 == Domain_3_6.PSA or domain_3_6 == Domain_3_6.TLS_1_3_ONLY or not build_tree.is_mbedtls_3_6(): if psa_name in PK_MACROS_3_6 or psa_name in HASHES_3_6: - return psa_name - if psa_name.startswith('PSA_ALG_') and \ - psa_name[8:] in ['MD5', 'RIPEMD160', 'SHA_1', 'SHA_224', 'SHA_256', - 'SHA_384', 'SHA_512', 'SHA3_224', - 'SHA3_256', 'SHA3_384', 'SHA3_512']: return psa_information.psa_want_symbol(psa_name) - if psa_name in HASHES_3_6: - return HASHES_3_6[psa_name] - if psa_information.psa_want_symbol(psa_name) in HASHES_3_6: - return HASHES_3_6[psa_information.psa_want_symbol(psa_name)] - if domain_3_6 == Domain_3_6.USE_PSA: if psa_name in PK_MACROS_3_6: return PK_MACROS_3_6[psa_name] + if psa_name in HASHES_3_6: + return HASHES_3_6[psa_name] + raise ValueError(f'Unable to determine dependency symbol for {psa_name} in {domain_3_6}') From f7e1f6ff1d65f5bddc3ab9904fd498d4829578cd Mon Sep 17 00:00:00 2001 From: Elena Uziunaite Date: Fri, 1 Nov 2024 13:59:40 +0000 Subject: [PATCH 09/11] Edit function calls Signed-off-by: Elena Uziunaite --- scripts/generate_config_tests.py | 2 +- scripts/generate_pkcs7_tests.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/generate_config_tests.py b/scripts/generate_config_tests.py index e29910add..7d6b3c976 100755 --- a/scripts/generate_config_tests.py +++ b/scripts/generate_config_tests.py @@ -88,7 +88,7 @@ def dependencies_of_setting(cfg: config_common.Config, return 'MBEDTLS_CIPHER_C:MBEDTLS_CIPHER_MODE_CBC' if name.startswith('MBEDTLS_PK_PARSE_EC_'): return 'MBEDTLS_PK_C:' + test_case.psa_or_3_6_feature_macro( - 'PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY', '') + 'PSA_KEY_TYPE_ECC_PUBLIC_KEY', test_case.Domain_3_6.USE_PSA) # For TLS settings, insist on having them once off and once on in # a configuration where both client support and server support are diff --git a/scripts/generate_pkcs7_tests.py b/scripts/generate_pkcs7_tests.py index 6e6fd987d..629b3a8c6 100755 --- a/scripts/generate_pkcs7_tests.py +++ b/scripts/generate_pkcs7_tests.py @@ -38,7 +38,7 @@ class TestData: Take in test_suite_pkcs7.data file. Allow for new tests to be added. """ - mandatory_dep = test_case.psa_or_3_6_feature_macro("PSA_ALG_SHA_256", "") + mandatory_dep = test_case.psa_or_3_6_feature_macro("PSA_ALG_SHA_256", test_case.Domain_3_6.USE_PSA) test_name = "PKCS7 Parse Failure Invalid ASN1" test_function = "pkcs7_asn1_fail:" From 561a3c4ec7bdf4cbe3b1707c4c1beb4e86225913 Mon Sep 17 00:00:00 2001 From: Elena Uziunaite Date: Fri, 1 Nov 2024 14:49:44 +0000 Subject: [PATCH 10/11] Fix code style pt2 Signed-off-by: Elena Uziunaite --- scripts/generate_config_tests.py | 2 +- scripts/generate_pkcs7_tests.py | 3 ++- scripts/mbedtls_framework/test_case.py | 9 +++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/scripts/generate_config_tests.py b/scripts/generate_config_tests.py index 7d6b3c976..469d895e4 100755 --- a/scripts/generate_config_tests.py +++ b/scripts/generate_config_tests.py @@ -88,7 +88,7 @@ def dependencies_of_setting(cfg: config_common.Config, return 'MBEDTLS_CIPHER_C:MBEDTLS_CIPHER_MODE_CBC' if name.startswith('MBEDTLS_PK_PARSE_EC_'): return 'MBEDTLS_PK_C:' + test_case.psa_or_3_6_feature_macro( - 'PSA_KEY_TYPE_ECC_PUBLIC_KEY', test_case.Domain_3_6.USE_PSA) + 'PSA_KEY_TYPE_ECC_PUBLIC_KEY', test_case.Domain36.USE_PSA) # For TLS settings, insist on having them once off and once on in # a configuration where both client support and server support are diff --git a/scripts/generate_pkcs7_tests.py b/scripts/generate_pkcs7_tests.py index 629b3a8c6..b97cebbf4 100755 --- a/scripts/generate_pkcs7_tests.py +++ b/scripts/generate_pkcs7_tests.py @@ -38,7 +38,8 @@ class TestData: Take in test_suite_pkcs7.data file. Allow for new tests to be added. """ - mandatory_dep = test_case.psa_or_3_6_feature_macro("PSA_ALG_SHA_256", test_case.Domain_3_6.USE_PSA) + mandatory_dep = test_case.psa_or_3_6_feature_macro("PSA_ALG_SHA_256", + test_case.Domain36.USE_PSA) test_name = "PKCS7 Parse Failure Invalid ASN1" test_function = "pkcs7_asn1_fail:" diff --git a/scripts/mbedtls_framework/test_case.py b/scripts/mbedtls_framework/test_case.py index 276eba524..d2de72754 100644 --- a/scripts/mbedtls_framework/test_case.py +++ b/scripts/mbedtls_framework/test_case.py @@ -33,7 +33,7 @@ PK_MACROS_3_6 = { "PSA_KEY_TYPE_ECC_PUBLIC_KEY" : "MBEDTLS_PK_HAVE_ECC_KEYS" } -class Domain_3_6(Enum): +class Domain36(Enum): PSA = 1 TLS_1_3_ONLY = 2 USE_PSA = 3 @@ -117,18 +117,19 @@ def write_data_file(filename: str, os.replace(tempfile, filename) def psa_or_3_6_feature_macro(psa_name: str, - domain_3_6: Domain_3_6) -> str: + domain_3_6: Domain36) -> str: """Determine the dependency symbol for a given psa_alg based on the domain and Mbed TLS version. For more information about the domains, and MBEDTLS_MD_CAN_ prefixed symbols, see transition-guards.md. Currently works with hashes and PK symbols only. """ - if domain_3_6 == Domain_3_6.PSA or domain_3_6 == Domain_3_6.TLS_1_3_ONLY or not build_tree.is_mbedtls_3_6(): + if domain_3_6 == Domain36.PSA or domain_3_6 == Domain36.TLS_1_3_ONLY or \ + not build_tree.is_mbedtls_3_6(): if psa_name in PK_MACROS_3_6 or psa_name in HASHES_3_6: return psa_information.psa_want_symbol(psa_name) - if domain_3_6 == Domain_3_6.USE_PSA: + if domain_3_6 == Domain36.USE_PSA: if psa_name in PK_MACROS_3_6: return PK_MACROS_3_6[psa_name] From f93ac3be7c55cfcd4257949c0a7d0deb4c2bc716 Mon Sep 17 00:00:00 2001 From: Elena Uziunaite Date: Mon, 4 Nov 2024 10:35:32 +0000 Subject: [PATCH 11/11] Edit documentation Signed-off-by: Elena Uziunaite --- scripts/mbedtls_framework/test_case.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/mbedtls_framework/test_case.py b/scripts/mbedtls_framework/test_case.py index d2de72754..47a5e4f7d 100644 --- a/scripts/mbedtls_framework/test_case.py +++ b/scripts/mbedtls_framework/test_case.py @@ -118,10 +118,11 @@ def write_data_file(filename: str, def psa_or_3_6_feature_macro(psa_name: str, domain_3_6: Domain36) -> str: - """Determine the dependency symbol for a given psa_alg based on + """Determine the dependency symbol for a given psa_name based on the domain and Mbed TLS version. For more information about the domains, and MBEDTLS_MD_CAN_ prefixed symbols, see transition-guards.md. - Currently works with hashes and PK symbols only. + This function currently works with hashes and some PK symbols only. + It accepts PSA_ALG_xxx or PSA_KEY_TYPE_xxx as inputs for psa_name. """ if domain_3_6 == Domain36.PSA or domain_3_6 == Domain36.TLS_1_3_ONLY or \