1393 Commits

Author SHA1 Message Date
Andrzej Kurek
de416fc2c6 depends.py: enable key exchange tests
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2023-01-17 10:40:28 -05:00
Ville Skyttä
a74468155d Use grep -E instead of egrep
`egrep` has been deprecated in GNU grep since 2007,
and since 3.8 it emits obsolescence warnings:
https://git.savannah.gnu.org/cgit/grep.git/commit/?id=a9515624709865d480e3142fd959bccd1c9372d1

Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2023-01-16 11:08:46 +00:00
Gilles Peskine
b9e56fb560 Switch code style check to enforcement mode
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-01-11 14:52:38 +01:00
Gilles Peskine
f8d190d23f
Merge pull request #6901 from gilles-peskine-arm/check-files-unicode-2.28
Backport 2.28: Reject bad characters in source code
2023-01-11 13:47:08 +01:00
Gilles Peskine
b60b7a33c0 Reject invalid UTF-8 and weird characters in text files
Reject "weird" characters in text files, especially control characters that
might be escape sequences or that might cause other text to appear garbled
(as in https://trojansource.codes/).

Also reject byte sequences that aren't valid UTF-8.

Accept only ASCII (except most control characters), letters, some non-ASCII
punctuation and some mathematical and technical symbols. This covers
everything that's currently present in Mbed TLS ( §áèéëñóöüłŽ–—’“”…≥).

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-01-10 22:13:27 +01:00
Gilles Peskine
ff723d8649 Pass line number to issue_with_line
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-01-10 22:13:27 +01:00
Gilles Peskine
66548d1fa7 Treat more *.bin files as binary
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-01-10 22:13:27 +01:00
Manuel Pégourié-Gonnard
89d4027d6c Use OPENSSL everywhere, not OPENSSL_CMD
These variables were both uses to select the default version of OpenSSL
to use for tests:
- when running compat.sh or ssl-opt.sh directly, OPENSSL_CMD was used;
- when running all.sh, OPENSSL was used.

This caused surprising situations if you had one but not the other set
in your environment. For example I used to have OPENSSL_CMD set but not
OPENSSL, so ssl-opt.sh was failing in some all.sh components but passing
when I ran it manually in the same configuration and build, a rather
unpleasant experience.

The natural name would be OPENSSL, and that's what set in the Docker
images used by the CI. However back in the 1.3.x days, that name was
already used in library/Makefile, so it was preferable to pick a
different one, hence OPENSSL_CMD. However the build system has not been
using this name since at least Mbed TLS 2.0.0, so it's now free for use
again (as demonstrated by the fact that it's been set in the CI without
causing any trouble).

So, unify things and use OPENSSL everywhere. Just leave an error message
for the benefit of developers which might have OPENSSL_CMD, not OPENSSL,
set in their environment from the old days.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2023-01-10 09:47:09 +01:00
Manuel Pégourié-Gonnard
8ee18d3787
Merge pull request #6798 from gilles-peskine-arm/check_test_cases-quiet_ci-2.28
Hide check_test_cases warnings on the CI
2022-12-21 09:42:59 +01:00
Manuel Pégourié-Gonnard
71e934f8d1
Merge pull request #6821 from gilles-peskine-arm/code-style-skip-generated-files-2.28
Backport 2.28: Don't touch the style of generated files
2022-12-19 13:06:29 +01:00
Gilles Peskine
38a49560de Simplify the coverage statistics summary
The script was parsing the output from `make lcov` to extract numbers and
calculate percentages. But everything including the percentages is already
present in the output of `make lcov`, just with a slightly different
presentation. So replace all this by a simple extraction of the relevant
lines from the output of `make lcov`.

This is more robust than the previous code, which relied on `tail -n4` to
extract relevant lines, which broke when `make lcov` started to emit one
extra line at the end.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-12-19 10:17:10 +01:00
Gilles Peskine
4ca54d417e Don't touch the style of generated files
Ideally the result of the generator would conform to the code style, but
this would be difficult, especially with respect to the placement of line
breaks in long logical lines. So, to avoid surprises when checking the style
of generated files (which happens in releases and in long-time support
branches), systematically skip generated files.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-12-19 00:58:25 +01:00
Gilles Peskine
2200f12094
Merge pull request #6807 from mpg/doc-docker-from-ci-2.28
[Backport 2.28] Point to docker images used in the CI
2022-12-17 01:54:27 +01:00
David Horstmann
e1e776caf7 Fix an incorrect regex in check_names.py
Allow check_names.py to detect declarations of the form:

enum some_enum_name {

This pattern has only just appeared due to code style correction, which
explains why the issue was not previously noticed.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2022-12-16 13:49:09 +00:00
Manuel Pégourié-Gonnard
7314798412 Point to docker images used in the CI
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2022-12-16 10:21:11 +01:00
Gilles Peskine
63c8be6075
Merge pull request #6753 from mpg/restartable-docfix-2.28
[Backport 2.28] Document ECP_RESTARTABLE
2022-12-15 19:47:47 +01:00
Gilles Peskine
5898796480 Hide check_test_cases warnings on the CI
We aren't paying attention to the warnings. So hide them and save log size.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-12-15 15:22:13 +01:00
Gilles Peskine
4b3806eb46
Merge pull request #6688 from gilles-peskine-arm/generate_test_code-function_comments-2.28
Backport 2.28: Allow comments in test function prototypes
2022-12-15 12:32:07 +01:00
Manuel Pégourié-Gonnard
1d1baa7fc3
Merge pull request #6586 from lpy4105/2.28-check-psa-name-typo
Backport 2.28: check_names: extend typo check to PSA macro/enum names
2022-12-13 09:24:56 +01:00
Manuel Pégourié-Gonnard
df86cef899
Merge pull request #6693 from mpg/optimize-with-asan-2.28
[backport 2.28] Optimize with asan
2022-12-12 11:58:21 +01:00
Manuel Pégourié-Gonnard
3dc7f238e6 Document that ECP_RESTARTABLE depends on ECP_C
This is not new, it had always been the case, just not documented.

Pointed out by depends.py pkalgs (again, now that restartable is part of
full).

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2022-12-09 10:24:52 +01:00
Manuel Pégourié-Gonnard
0e0793f4ac
Merge pull request #6706 from davidhorstmann-arm/2.28-code-style-script-non-corrected
[Backport 2.28] Add code style correction script
2022-12-09 09:41:27 +01:00
David Horstmann
e09c476eb6 Add all.sh component to test with code style
Run the main test suites after running code style correction to check
that code style correction does not break these tests.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2022-12-08 10:09:03 +00:00
Dave Rodgman
9889c66bff
Merge pull request #6710 from gilles-peskine-arm/valgrind-cf-skip-tests-2.28
Backport 2.28: Rationalize Valgrind tests
2022-12-06 18:39:39 +00:00
Tom Cosgrove
49f99bc3db Fix typos prior to release
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2022-12-04 16:44:21 +00:00
Gilles Peskine
9603a441a0 Valgrind for constant flow: skip non-CF test suites
When testing under Valgrind for constant flow, skip test suites that don't
have any constant-flow annotations, since the testing wouldn't do anything
more that testing with ordinary Valgrind (component_test_valgrind).
This is a significant time saving since testing with Valgrind is very slow.

In Mbed TLS 2.28, MBEDTLS_USE_PSA_CRYPTO does not affect constant-time
functions, so testing in the full configuration covers all we need.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-12-01 19:49:36 +01:00
Gilles Peskine
619b73d97d Test MBEDTLS_USE_PSA_CRYPTO with Valgrind
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-12-01 19:49:36 +01:00
Gilles Peskine
aec4bec53a Preserve line breaks from continued line comments
The commit "Preserve line breaks in comments before test functions"
only handled block comments. This commit handles line comments.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-30 16:39:55 +01:00
Tom Cosgrove
5f49b3cbe5 Fix the name of basic-build-test.sh within the file
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2022-11-30 11:18:35 +00:00
Manuel Pégourié-Gonnard
717f2305a4 Add comment about use of ASAN_CFLAGS
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2022-11-30 10:54:01 +01:00
Manuel Pégourié-Gonnard
154b84e664 Enable optimisation with Asan with make in all.sh
All builds using ASAN_CFLAGS were with Asan but no optimisation, making
them particularly slow. Indeed, we were overwriting CFLAGS which
defaults to -O2 and not using any -O in the replacement. (CMake already has
optimisations on with ASan.)

While at it, also remove -Wall -Wextra which are redundant as they are
already part of WARNING_CFLAGS which we are not overwriting.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2022-11-30 10:54:01 +01:00
Gilles Peskine
07995fdd2f Preserve line breaks in comments before test functions
This way line numbers match better in error messages.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-29 22:03:32 +01:00
Gilles Peskine
7e8d4b6aff Explain space preservation
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-29 21:53:31 +01:00
Gilles Peskine
43febf2890 Typos in comments
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-29 21:53:31 +01:00
Gilles Peskine
8ee3a65f14 Add test cases for comment nesting
Add a test case that would fail if all line comments were parsed before
block comments, and a test case that would fail if all block comments were
parsed before line comments.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-29 21:53:31 +01:00
Gilles Peskine
e54f63e4f3 Fix intended backslash in test data
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-29 21:53:31 +01:00
Gilles Peskine
d3ad55e496 Allow comments in prototypes of unit test functions
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-29 21:53:31 +01:00
Gilles Peskine
4711731455 Fix typo and copypasta
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-29 21:46:50 +01:00
Gilles Peskine
5f0057d861 Remove some Python 2 compatibility code
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-29 21:46:50 +01:00
Dave Rodgman
b400fb0b76
Merge pull request #6452 from AndrzejKurek/depends-py-reloaded-2-28
[Backport 2.28] Unified tests/scripts/depends.py - reloaded
2022-11-24 10:59:31 +00:00
Andrzej Kurek
f53d0ba529 depends.py: remove tls defines in SHA-512-only test
TLS 1.2 requires either SHA-256 or SHA-384.
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2022-11-23 05:54:46 -05:00
Gilles Peskine
05dcb1300d
Merge pull request #6613 from gilles-peskine-arm/run-test-suites-out-of-tree-2.28
Backport 2.28: Fix run-test-suites.pl in out-of-tree builds
2022-11-22 15:01:21 +01:00
Andrzej Kurek
aa11281c07 Add a SHA512_NO_SHA384_C test to depends.py
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2022-11-22 08:13:45 -05:00
Gilles Peskine
6b7c3ccfed Use .datax for make test, not .data
Looking for the .data file doesn't work in out-of-tree builds. Use the
.datax file instead. `make clean` removes all .datax files, so this resolves
the issue of executables not present on the current branch being left behind
after a branch change followed by a `make clean`.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-16 10:35:20 +01:00
Pengyu Lv
fda7f508d8 add exclusive rule for PSA_CRYPTO_DRIVER_TEST
This macro is expected to be defined out of the library, and there
is no definition in the library. Thus it needs to be excluded from
typo check.

Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2022-11-11 12:17:23 +08:00
Pengyu Lv
018b2f6a62 check_names: extend typo check to PSA macro/enum names
Typos of PSA macro and enum names are not checked by check_names.py.
This commit extend the check list to include PSA_XXX references.
The words should be macro/enum names defined as public_macros,
internal_macros, private_macros and enums. This commit also extend
the scope of enums to include those are defined in library/*.c.
A new type of macros "private", which are defined in library/*.c was
also added.

Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2022-11-11 12:13:04 +08:00
Gilles Peskine
83763ab6b1 Pacify pylint
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-10 15:15:25 +01:00
Gilles Peskine
92c5d31b44 Add negative zero as an input to automatically generated tests
Although negative zero is officially unsupported, we've had bugs related to
it in the past. So do test functions with a negative zero input.

There will likely be cases where we don't want to accept negative zero as if
it was valid, because it's too hard to handle. We'll add exceptions on a
case by case basis.

For the functions that are currently tested by the generated tests, the new
test cases pass.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-10 15:15:25 +01:00
Gilles Peskine
ee78b6e642 For binary operations, test both x op y and y op x
This exposes a bug in mbedtls_mpi_add_mpi() and mbedtls_mpi_sub_mpi() which
will be fixed in a subsequent commit.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-10 15:15:25 +01:00
Gilles Peskine
676df8ec88
Merge pull request #6578 from gilles-peskine-arm/bignum-test-suite-names-2.28
Backport 2.28: Rename test_suite_bignum for consistency
2022-11-10 14:40:16 +01:00