Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion scripts/generate_psa_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,17 @@ class PSAWrapperGenerator(c_wrapper_generator.Base):
_WRAPPER_NAME_SUFFIX = ''

def gather_data(self) -> None:
"""Gather PSA Crypto API function names."""
root_dir = build_tree.guess_mbedtls_root()
for header_name in ['crypto.h', 'crypto_extra.h']:
header_path = os.path.join(root_dir, 'include', 'psa', header_name)
# Temporary, while Mbed TLS does not just rely on the TF-PSA-Crypto
# build system to build its crypto library. When it does, the first
# case can just be removed.
if os.path.isdir(os.path.join(root_dir, 'tf-psa-crypto')):
header_path = os.path.join(root_dir, 'tf-psa-crypto',
'include', 'psa', header_name)
else:
header_path = os.path.join(root_dir, 'include', 'psa', header_name)
c_parsing_helper.read_function_declarations(self.functions, header_path)

_SKIP_FUNCTIONS = frozenset([
Expand Down
29 changes: 25 additions & 4 deletions scripts/mbedtls_framework/psa_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
#

import os
import re
from collections import OrderedDict
from typing import FrozenSet, List, Optional
Expand All @@ -30,8 +31,16 @@ def remove_unwanted_macros(
def read_psa_interface(self) -> macro_collector.PSAMacroEnumerator:
"""Return the list of known key types, algorithms, etc."""
constructors = macro_collector.InputsForTest()
header_file_names = ['include/psa/crypto_values.h',
'include/psa/crypto_extra.h']
# Temporary, while Mbed TLS does not just rely on the TF-PSA-Crypto
# build system to build its crypto library. When it does, the first
# case can just be removed.
if os.path.isdir('tf-psa-crypto'):
header_file_names = ['tf-psa-crypto/include/psa/crypto_values.h',
'tf-psa-crypto/include/psa/crypto_extra.h']
else:
header_file_names = ['include/psa/crypto_values.h',
'include/psa/crypto_extra.h']

test_suites = ['tests/suites/test_suite_psa_crypto_metadata.data']
for header_file_name in header_file_names:
constructors.parse_header(header_file_name)
Expand Down Expand Up @@ -124,10 +133,22 @@ def read_implemented_dependencies(filename: str) -> FrozenSet[str]:
for symbol in re.findall(r'\bPSA_WANT_\w+\b', line))
_implemented_dependencies = None #type: Optional[FrozenSet[str]] #pylint: disable=invalid-name
def hack_dependencies_not_implemented(dependencies: List[str]) -> None:
"""
Hack dependencies to skip test cases for which at least one dependency
symbol is not available yet.
"""
global _implemented_dependencies #pylint: disable=global-statement,invalid-name
if _implemented_dependencies is None:
_implemented_dependencies = \
read_implemented_dependencies('include/psa/crypto_config.h')
# Temporary, while Mbed TLS does not just rely on the TF-PSA-Crypto
# build system to build its crypto library. When it does, the first
# case can just be removed.
if os.path.isdir('tf-psa-crypto'):
_implemented_dependencies = \
read_implemented_dependencies('tf-psa-crypto/include/psa/crypto_config.h')
else:
_implemented_dependencies = \
read_implemented_dependencies('include/psa/crypto_config.h')

if not all((dep.lstrip('!') in _implemented_dependencies or
not dep.lstrip('!').startswith('PSA_WANT'))
for dep in dependencies):
Expand Down
10 changes: 9 additions & 1 deletion scripts/mbedtls_framework/psa_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
#

import os
import re
import struct
from typing import Dict, List, Optional, Set, Union
Expand Down Expand Up @@ -41,7 +42,14 @@ def __init__(self, content: Union[int, str]):
def update_cache(self) -> None:
"""Update `value_cache` for expressions registered in `unknown_values`."""
expressions = sorted(self.unknown_values)
includes = ['include']
# Temporary, while Mbed TLS does not just rely on the TF-PSA-Crypto
# build system to build its crypto library. When it does, the first
# case can just be removed.
if os.path.isdir('tf-psa-crypto'):
includes = ['include', 'tf-psa-crypto/include']
else:
includes = ['include']

if build_tree.looks_like_tf_psa_crypto_root('.'):
includes.append('drivers/builtin/include')
values = c_build_helper.get_c_expression_values(
Expand Down