Add a sanity check to detect the most common problem, which is a missing
include directory leading to compilation errors (which this script is unable
to report due to a limitation of the clang python bindings).
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Remove the remaining Mbed TLS-specific bits of field_report.py.
Create a wrapper script that calls field_report.py with options for Mbed TLS
specifically.
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
get_canonical() sees through typedefs, but it doesn't dereference pointers.
So we need to continue digging after reaching a canonical type.
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
The score is the access cost on Cortex-M0+ thumb builds, expressed in
instructions. This commit does not have any provisions to calculate
different scores based on the target architecture, so it's only meaningful
when running this script with `-t armv6m-unknown-eabi`.
Go with a simple model: direct access is possible for the first 128 fields
of a structure, direct access costs 1 instruction, indirect access costs 3
instructions.
The score calculation assumes that each lexical use in the source code
corresponds to one access. This does not take into account unused code,
inlining, uses from application code, etc.
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Don't skip structure definitions that have no name, but for which there is a
named typedef. Do skip unions and anonymous structs that don't have a type
name (which is common for structs embedded in another struct or union).
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This is a lot easier for testing.
Production usage is now
```
scripts/field_report.py include/*/*.h library/*.[hc]
```
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
The previous code did not correctly associate typedefs with structs when the
two had different names.
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Report how many places in the code access each field.
Known bug: the code in this commit doesn't match type names at the point of
declaration with type names at the point of use properly. I think the
problem is that field definitions are recorded against the name of the
struct when it has one, but field uses are recorded against the typedef.
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Report the size, alignment and offset of fields of structures defined in
Mbed TLS headers.
Usage example on Cortex-M0:
```
cd mbedtls/struct-optimization
scripts/config.py baremetal
../types-report/scripts/types_report.py -t armv6m-unknown-eabi -I ~/Packages/ARMCompiler6.6/include
```
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
They were recognized by a prior commit. In this commit, replace line
breaks (with optional comment continuation marker) by spaces.
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Before this commit, definitions of error codes must match a strict pattern,
with a Doxygen comment following the definition on the same line and
starting with "/**<". Change how generate_errors.pl so that the Doxygen
comment can be before the definition instead of after, and doesn't have to
be on the same line.
Also allow spaces between "#" and "define", and allow Doxygen comments to
start with "/*!" rather than "/**". Starting with "///" or "//!" is not
supported.
This commit does not change the output of generate_errors.pl.
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Add test cases validating that if a stored key only had the hash policy,
then after loading it psa_get_key_attributes reports that it also has the
message policy, and the key can be used with message functions.
Signed-off-by: gabor-mezei-arm <gabor.mezei@arm.com>
Also remove preprocessor logic for MBEDTLS_CONFIG_FILE, since
build_info.h alreadyy handles it.
This commit was generated using the following script:
# ========================
#!/bin/sh
git ls-files | grep -v '^include/mbedtls/build_info\.h$' | xargs sed -b -E -i '
/^#if !?defined\(MBEDTLS_CONFIG_FILE\)/i#include "mbedtls/build_info.h"
//,/^#endif/d
'
# ========================
Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
Test keys with various persistence levels, enumerated from the
metadata tests.
For read-only keys, do not attempt to create or destroy the key
through the API, only to read a key that has been injected into
storage directly through filesystem access.
Do not test keys with a non-default location, since they require a
driver and we do not yet have a dependency mechanism to require the
presence of a driver for a specific location value.
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
It was used to remove the code used when mbedtls_ecp_mul() received a
NULL RNG parameter. This code is no longer relevant (as the RNG may no
longer be NULL) and will be unconditionally removed in the next commit.
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
The new method `Config.change_matching` and the new command-line
commands `set-all` and `unset-all` change a batch of existing boolean
settings to the desired state (active or inactive).
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>