Commit graph

14236 commits

Author SHA1 Message Date
Gilles Peskine 0370c17105 mypy: require at least version 0.780
0.780 works. The previous release, 0.770, does not.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-01-20 12:03:24 +01:00
Gilles Peskine 4738b96d75 Use $PYTHON when running mypy
Make sure to run mypy with the desired Python version.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-01-19 21:45:32 +01:00
Gilles Peskine c3b178768f Use can_mypy rather than just checking for mypy
As indicated in the comments in the can_mypy function, we don't just
need a mypy executable to be present, we need it to work.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-01-19 21:43:24 +01:00
Gilles Peskine bdde5d002c Use Python to check the version of pylint
This reduces dependencies, doesn't require maintainers to know awk,
and makes the version parsing more robust.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-01-19 21:42:05 +01:00
Gilles Peskine 6d82a7ef9f Say we're running pylint
Now that the script might additionally run mypy, it's more
user-friendly to indicate what's going on at the beginning as well.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-01-19 21:23:11 +01:00
Gilles Peskine 2991b5f6c0 Minor documentation fixes
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-01-19 21:23:11 +01:00
Gilles Peskine 1cc6a8ea15 Add --can-pylint and --can-mypy options
With just the option --can-pylint or --can-mypy, check whether the
requisite tool is available with an acceptable version and exit.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-01-06 17:12:18 +01:00
Gilles Peskine b13ed70b32 Check scripts/mbedtls_dev/*.py with pylint
mypy automatically checks the modules when it encounters them as
imports. Don't make it check them twice, because it would complain
about encountering them through different paths (via the command line
as scripts/mbedtls_dev/*.py and via imports as just mbedtls_dev/*.py).

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-01-06 17:12:10 +01:00
Gilles Peskine 86fc21cd3b mypy: support mbedtls_dev.foo
Tell mypy to support packages without an __init__.py (PEP 420
namespace packages). Python 3.3 and (modern) Pylint support them out
of the box, but mypy needs to be told to support them.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2020-12-11 00:35:19 +01:00
Gilles Peskine 2adebc89da Move get_c_expression_values into a separate module
Create a directory mbedtls_dev intended to contain various Python
module for use by Python scripts located anywhere in the Mbed TLS
source tree.

Move get_c_expression_values and its auxiliary functions into a new
Python module mbedtls_dev.c_build_helper.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2020-12-11 00:35:19 +01:00
Gilles Peskine fc62211e3b Refactor and generalize run_c
Generalize the very ad hoc run_c function into a function to generate
a C program to print the value of a list of expressions. Refactor the
code into several functions to make it more manageable.

No intended behavior change.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2020-12-11 00:35:11 +01:00
Gilles Peskine 45d350b9dc Allow tests/scripts/foo.py to import from scripts
Allow Python scripts in tests/scripts to import modules located in the
scripts directory. To do this, use
```
import scripts_path # pylint: disable=unused-import
```

Declare the scripts directory to pylint and to mypy.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2020-12-10 23:16:03 +01:00
Gilles Peskine 7be4551f23 Check typing of python scripts if mypy is available
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2020-12-10 21:32:32 +01:00
Gilles Peskine e6d0ac26ca mbedtls_test.py: Tell mypy to ignore mbed_host_tests
Since no typing stubs are available for mbed_host_tests.py, mypy
errors out on mbedtls_test.py with

    error: Skipping analyzing 'mbed_host_tests': found module but no type hints or library stubs

Ignore this import to get at least some benefit from mypy without
spending significant effort to write stubs.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2020-12-10 21:30:14 +01:00
Gilles Peskine 38b66dfc85 test_generate_test_code: remove Python 2 compatibility code
This makes the code cleaner.

As a bonus, mypy no longer gets confused.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2020-12-10 21:30:08 +01:00
Gilles Peskine ac9e7c0b6e check_files.py: pass mypy
Add enough type annotations to pass mypy 0.782 with Python 3.5. The
source code will still run normally under older Python versions.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2020-12-10 21:30:01 +01:00
Gilles Peskine 4aebb8d936 Test shebang lines
Executable scripts must have shebang (#!) line to be effectively
executable on most Unix-like systems. Enforce this, and conversely
enforce that files with a shebang line are executable.

Check that the specified interperter is consistent with the file
extension.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2020-12-10 21:29:55 +01:00
Gilles Peskine 15898eec23 Allow Python files not to be executable
.py files may be modules which are not standalone program, so allow
them not to be executable.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2020-12-10 21:29:49 +01:00
Gilles Peskine 6d5c7bc69a
Merge pull request #3898 from paul-elliott-arm/fix_pem_write
Remove Extraneous bytes from buffer post pem write
2020-12-08 12:31:40 +01:00
Gilles Peskine 2b759626a9
Merge pull request #3948 from bensze01/update_psa_values
Update the values of PSA Crypto API macros to version 1.0.0
2020-12-08 11:03:33 +01:00
Bence Szépkúti 7e37bf97ee Update test_psa_constant_names.py for new values
Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
2020-12-08 07:33:08 +01:00
Bence Szépkúti 6879f42be4 Add changelog
Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
2020-12-08 00:24:41 +01:00
Bence Szépkúti 99ffb2b275 Simplify description of PSA_ALG_STREAM_CIPHER
Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
2020-12-08 00:09:08 +01:00
Bence Szépkúti cbe395332c Substitute PSA_ALG_STREAM_CIPHER into all files
Deprecate PSA_ALG_ARC4 and PSA_ALG_CHACHA20.

Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
2020-12-08 00:01:31 +01:00
Bence Szépkúti c6a26c940c Update PSA Crypto persistent key storage tests
Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
2020-12-07 23:03:59 +01:00
Bence Szépkúti a294551446 Update PSA Crypto macro values to version 1.0.0
This should be everything that's needed for the stable storage format.

Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
2020-12-07 21:03:05 +01:00
Bence Szépkúti 1de907d4a4 Introduce PSA_ALG_STREAM_CIPHER
This algorithm replaces the pre-existing stream cipher algorithms.
The underlying stream cipher is determined by the key type.

Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
2020-12-07 21:03:05 +01:00
Paul Elliott 557b8d663a Remove Extraneous bytes from buffer post pem write
In order to remove large buffers from the stack, the der data is written
into the same buffer that the pem is eventually written into, however
although the pem data is zero terminated, there is now data left in the
buffer after the zero termination, which can cause
mbedtls_x509_crt_parse to fail to parse the same buffer if passed back
in. Patches also applied to mbedtls_pk_write_pubkey_pem, and
mbedtls_pk_write_key_pem, which use similar methods of writing der data
to the same buffer, and tests modified to hopefully catch any future
regression on this.

Signed-off-by: Paul Elliott <paul.elliott@arm.com>
2020-12-07 17:29:42 +00:00
Ronald Cron 771090659e
Merge pull request #3393 from geecrypt/development
Support set *_drbg reseed interval before seed
2020-12-07 14:29:52 +01:00
Gilles Peskine 3a0535b465
Merge pull request #3916 from jdurkop/psa-crypto-config-hashes-3672
Add support to crypto config for hashes
2020-12-07 13:50:56 +01:00
Gilles Peskine d33aabf388
Merge pull request #3942 from gilles-peskine-arm/ecp-bignum-error-checks-development
Add missing some error checks in ECP and bignum
2020-12-07 13:06:47 +01:00
Gilles Peskine e410bf7320 Add changelog entry for the memory management fixes
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2020-12-06 22:32:02 +01:00
Gilles Peskine e54be3a9c3 Fix uncaught error if fix_negative fails
fix_negative allocates memory for its result. The calling site didn't
check the return value, so an out-of-memory error could lead to an
incorrect calculation. Fix this.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2020-12-06 22:32:02 +01:00
Gilles Peskine 89b4130098 Fix memory leak in mbedtls_mpi_sub_abs
Fix a memory leak in mbedtls_mpi_sub_abs when the output parameter is
aliased to the second operand (X = A - X) and the result is negative.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2020-12-06 22:32:02 +01:00
Gilles Peskine 56f943a184 Always test in-place addition and subtraction
Run all the addition and subtraction tests with the result aliased to
the first operand and with the result aliased to the second operand.
Before, only some of the aliasing possibilities were tested, for only
some of the functions, with only some inputs.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2020-12-06 22:32:02 +01:00
gacquroff 1bfeb8a837 Add changelog entry file for bugfix 2927
Signed-off-by: gacquroff <gavina352@gmail.com>
2020-12-03 12:28:25 -08:00
John Durkop 6ca2327150 Update guards for ALG_SHA_224 and ALG_SHA_384 in crypto library
The previous revision of guards around SHA_224 and SHA_384 were not
correct. This set of changes ensures the proper code is available
when SHA_224 and SHA_384 are enabled for use.

Signed-off-by: John Durkop <john.durkop@fermatsoftware.com>
2020-12-03 06:07:04 -08:00
Gilles Peskine 54a6f23393
Merge pull request #3930 from ccvca/fix_missing_argument
Fix: Add missing arguments to debug message.
2020-12-03 12:29:03 +01:00
Christian von Arnim 883d304785
Fix: Add missing arguments to debug message.
Signed-off-by: Christian von Arnim <christian.von-arnim@isw.uni-stuttgart.de>
2020-12-02 10:13:02 +01:00
Gilles Peskine d9d4e807fa
Merge pull request #3848 from rodrigo-dc/development
Fix build failure on gcc-11
2020-12-01 13:26:27 +01:00
John Durkop d62b678473 Minor updates to address review comments
Removed unecessary checks on the ALG_SHA_224 and ALG_SHA_384 since
those are handled in config_psa.h by ensuring the correct _C is
included. Reformatted config_psa.h to be alphabetical and made the
assignments line up correctly for consistency. Fixed the guards
for ALG_SHA_224 and ALG_SHA_384 to be correct in the crypto library
source.

Signed-off-by: John Durkop <john.durkop@fermatsoftware.com>
2020-11-30 21:06:05 -08:00
Gilles Peskine e533ff7bb7
Merge pull request #3695 from gilles-peskine-arm/psa-unified-driver-specs-20200918
PSA unified driver specification: key validation and transparent key import
2020-11-30 15:54:45 +01:00
Ronald Cron b55e083515
Merge pull request #3924 from bensze01/deprecated_removed
Fix removal of deprecated PSA constants
2020-11-30 08:59:54 +01:00
Bence Szépkúti d4585ff3c5 Fix removal of deprecated PSA constants
Due to a misplaced #endif, the (non-functional) macro definitions were
not properly removed from crypto_compat.h if MBEDTLS_DEPRECATED_REMOVED
was declared.

Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
2020-11-27 17:52:56 +01:00
John Durkop 1b7ee05461 Added tests to confirm hash support for crypto config
New tests have been added for all the hash algorithms to
confirm they compile correctly when using PSA_WANT and
accelerator guards.

Signed-off-by: John Durkop <john.durkop@fermatsoftware.com>
2020-11-27 08:51:22 -08:00
John Durkop ee4e6602bd Use new MBEDTLS_PSA_BUILTIN_ macros for hashes in crypto library
This set of changes converts all the previous MBEDTLS_*_C guards in
the crypto library to use the new MBEDTLS_PSA_BUILTIN_ guards for
hash algorithms.

Signed-off-by: John Durkop <john.durkop@fermatsoftware.com>
2020-11-27 08:48:46 -08:00
John Durkop 316052ef2a Add in dependency check for crypto config hashes
With the addition of hash algorithms to crypto config there
are new dependencies for SHA224 and SHA384 that need to be confirmed
for those hashes to be used.

Signed-off-by: John Durkop <john.durkop@fermatsoftware.com>
2020-11-27 08:45:01 -08:00
John Durkop fb764a60b9 Add hashes as crypto config by default
This change adds in all the hashes to the crypto config
by default.

Signed-off-by: John Durkop <john.durkop@fermatsoftware.com>
2020-11-27 08:43:28 -08:00
Gilles Peskine 2cecfbab8a Support PSA_WANT_xxx and MBEDTLS_PSA_BUILTIN_xxx for hashes
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2020-11-27 08:18:47 -08:00
Gilles Peskine cd1495c037 In old-style PSA configuration, define PSA_WANT_xxx
When MBEDTLS_PSA_CRYPTO_CONFIG is disabled, if an Mbed TLS crypto
feature is enabled, declare the corresponding PSA feature as enabled,
in addition to enabling its software implementation. This is necessary
for code that uses PSA APIs and relies on PSA_WANT_xxx symbols to know
which features are enabled (application code, our library code using
MBEDTLS_USE_PSA_CRYPTO, our test dependencies, etc.).

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2020-11-27 08:17:29 -08:00