30875 Commits

Author SHA1 Message Date
Ryan Everett
97cc7f89be Rewrite changelog
Signed-off-by: Ryan Everett <ryan.everett@arm.com>
2024-04-30 11:17:04 +01:00
Ryan Everett
b1c3d6e07b Add changelog
Signed-off-by: Ryan Everett <ryan.everett@arm.com>
2024-04-30 11:17:04 +01:00
Ryan Everett
b5a20d3bc5 Fix error handling for secure element keys in psa_start_key_creation
Signed-off-by: Ryan Everett <ryan.everett@arm.com>
2024-04-30 11:17:04 +01:00
Gilles Peskine
3dbb502098
Merge pull request #9066 from paul-elliott-arm/fix_ubsan_mp_aead_gcm_3.6
[Backport 3.6] Add early exit if zero length AEAD additional data passed in.
2024-04-30 09:48:24 +00:00
Manuel Pégourié-Gonnard
4b2639c23f
Merge pull request #9033 from valeriosetti/issue8871-backport
[3.6 backport] Improve test key generation in test_suite_pk
2024-04-29 09:25:40 +00:00
Paul Elliott
405d1f6434 Add Changelog entry
Signed-off-by: Paul Elliott <paul.elliott@arm.com>
2024-04-26 19:20:45 +01:00
Paul Elliott
304766ffa8 Add early exit if zero length AEAD AD passed in.
With multipart AEAD, if we attempt to add zero length additional data,
then with the buffer sharing fixes this can now lead to undefined
behaviour when using gcm. Fix this by returning early, as there is
nothing to do if the input length is zero.

Signed-off-by: Paul Elliott <paul.elliott@arm.com>
2024-04-26 19:20:45 +01:00
Gilles Peskine
289079855b Convert recent RSA key files in PEM format from PKCS8 to PKCS1
Like `openssl rsa`, `openssl genrsa` changed its output format from PKCS8 to
PKCS1 in OpenSSL 3.0. Note that the makefile instructions assume older
OpenSSL. Convert the files that were generated with OpenSSL 3.x and hence
were not in the intended format. The files are converted, not regenerated,
so the key material is the same.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-04-26 11:53:02 +02:00
Gilles Peskine
69eba519f0 Fix rsa_pkcs1_*_clear.der to actually be PKCS#1 files
With OpenSSL 3.0.2 (which I used to generate the previous set of "pkcs1" DER
files), the output of `openssl rsa -outform DER` is actually a
PKCS#8-encoded key, despite what the documentation says. This is a change
from OpenSSL 1.x, where the output is a PKCS#1-encoded key. OpenSSL 3.0.8
documents the output as PKCS#8.

Change to `openssl pkey`, which seems more reliable. The documentation
states that the output is PKCS#8, but the output is actually consistently
PKCS#1 at least from 1.0.2g to 3.3.0.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-04-25 16:35:04 +02:00
Gilles Peskine
786dff6701 Use large enough keys when testing parsing of non-word-aligned RSA sizes
When PSA is available, we exercise the parsed RSA key with PKCS#1v1.5
signature, which requires the modulus size in bytes to be at least
tLen + 11 (per RFC 8017 §9.2) where tLen = hLen + oidLen + 6 and
hLen = 32, oidLen = 9 for SHA-512 or SHA3-512. 10 is the DER overhead
(3 ASN.1 type-length headers with lengths <128). Replace 512-bit test
cases (good enough for SHA-256 but not SHA-384 and up) by 768-bit and
up (good enough for SHA-512).

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-04-24 18:22:22 +02:00
Gilles Peskine
0a2d48290b Add some test RSA keys of sizes 768 and up
These are sufficiently large for PKCS#1v1.5 signature with SHA-512 or
SHA3-512. Cover some non-word-aligned sizes.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-04-24 18:22:21 +02:00
Gilles Peskine
dfb7afe67e Cleartext RSA keys: also make DER formats available
We can use DER keys in builds without PEM, so it's good to have them around.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-04-24 18:22:19 +02:00
Manuel Pégourié-Gonnard
f6275b745f
Merge pull request #9021 from mpg/compat-fixes-3.6
[3.6] Small fixes to compat.sh (partial forward-port)
2024-04-24 07:11:54 +00:00
Gilles Peskine
09569d1dfe Fix misspelled dependency: there is no MBEDTLS_PEM_C
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-04-22 17:18:53 +02:00
Gilles Peskine
e6b6c14081 Allow PSA to not support RSA keys with non-byte-aligned sizes
Work around https://github.com/Mbed-TLS/mbedtls/issues/9048

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-04-22 17:18:13 +02:00
Gilles Peskine
401d6dc66c Remove redundant dependency
In the test data, remove a dependency that is already present on the function.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-04-22 15:35:34 +02:00
Manuel Pégourié-Gonnard
763b240ccd Fix full invocation of ssl-opt.sh
The previous commit had:
- one obvious mistake (-f NULL with default -e runs nothing)
- one unforeseen issue: OPENSSL_NEXT skips static ECDH
- arguably scope creep: the stated goal was to simplify the full
invocation (in particular, make it obvious that everything is run
without having to remember the default value of EXCLUDE), but it also
made an unrelated change: running most tests with OPENSSL_NEXT (hence
the previous point).

This commit should fix all this, in particular it switches back to
running most tests with OPENSSL and using OPENSSL_NEXT only when needed.

Hopefully in the future we'll do the opposite: most tests will run with
a recent OpenSSL, and only those that need an older one will use
something older. But that will be another PR.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2024-04-22 12:35:00 +02:00
Manuel Pégourié-Gonnard
b9f9c0e0fd
Merge pull request #9042 from valeriosetti/asn1-missing-guard-in-rsa-backport
[3.6 backport] Asn1 missing guard in rsa backport
2024-04-22 07:48:47 +00:00
Valerio Setti
5e965845d6 generate_test_keys: split group_id and key bitsize in the generated structure
- group_id is only used for EC keys;
- key bitsize only for RSA.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-22 05:20:47 +02:00
Valerio Setti
e53701852b test_suite_pk: fix some descriptions in data file
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-22 05:20:46 +02:00
Valerio Setti
5868548b9a generate_test_keys: minor improvements
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-22 05:20:46 +02:00
Valerio Setti
0595dc685f changelog: fix text
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-19 11:11:10 +02:00
Valerio Setti
82c3b40fef add changelog
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-19 09:40:01 +02:00
Valerio Setti
11530fd6b9 adjust_legacy_crypto: enable ASN1_[PARSE|WRITE]_C when RSA_C
RSA needs ASN1 functions to parse/write private and public keys,
but there is no guards in the code for that. So we need to enable
ASN1 support whenever RSA is enabled.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-19 09:40:01 +02:00
Manuel Pégourié-Gonnard
e7987b65e8 Simplify full invocation of compat.sh
We actually only need two invocations.

This also moves all the default tests to OPENSSL_NEXT, which is good
because OPENSSL is ancient.

I have no idea why NULL doesn't work with OPENSSL_NEXT (1.1.1a) server,
because according to the manpage [1], "ALL,COMPLEMENTOFALL" (which is
what we are using) should do it, and indeed

    $OPENSSL_NEXT ciphers "ALL,COMPLEMENTOFALL" | tr ':' '\n'

lists NULL ciphersuites, and also they work client-side with
OPENSSL_NEXT...

[1] https://www.openssl.org/docs/man1.1.1/man1/ciphers.html

Also, while at it, remove partial invocation (only non-default) from one
component, as we already have a full invocation in the same config (plus
ASan) in another component.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2024-04-17 12:30:05 +02:00
Valerio Setti
690ab4548c test_suite_pk: fix guards for pk_psa_setup()
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-17 09:52:01 +02:00
Valerio Setti
e98c37877b test_suite_pk: remove PK_PARSE_C unnecessary dependencies
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-17 05:28:37 +02:00
Valerio Setti
7903385e0f test_suite_pk: remove RSA key generation/size dependencies
- MBEDTLS_GENPRIME is removed because now we rely on predefined
  RSA keys.
- MBEDTLS_RSA_GEN_KEY_MIN_BITS is replaced with RSA_KEY_SIZE which
  is set on top of test_suite_pk to a value which is supported
  in the predefined_keys[] array.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-17 05:28:37 +02:00
Valerio Setti
ab4b01bbbe test_suite_pk: enhance pk_psa_setup() to support all key types
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-17 05:28:37 +02:00
Valerio Setti
7ee12b7669 test_suite_pk: use pk_setup() instead of mbedtls_rsa_gen_key() in pk_psa_wrap_sign_ext()
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-17 05:28:37 +02:00
Valerio Setti
73932e3b83 test_suite_pk: use predefined RSA keys in pk_setup_for_type()
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-17 05:28:36 +02:00
Valerio Setti
5a07cff575 test_suite_pk: rename pk_genkey() and pk_psa_genkey()
- pk_genkey -> pk_setup
- pk_psa_genkey -> pk_psa_setup

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-17 05:28:36 +02:00
Valerio Setti
83ddd43e86 test_suite_pk: fix get_predefined_key_data() return value
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-17 05:28:36 +02:00
Valerio Setti
04ee26404b generate_test_keys: generate also look-up table in script
Remove static declaration of look-up table from test_suite_pk
and generate it automatically with Python.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-17 05:28:36 +02:00
Valerio Setti
65953e227a generate_test_keys: generate arrays for all keys in asymmetric_key_data.py
Only unused (from test_suite_pk point of view) EC curves are skipped.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-17 05:28:36 +02:00
Valerio Setti
f38640d07d generate_test_keys: generate also RSA public key arrays
This is to manage RSA and EC keys in the same way in order to
prepare for the following commits.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-17 05:28:36 +02:00
Valerio Setti
ea9c8bdb5c generate_test_keys: minor improvements
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-17 05:28:36 +02:00
Valerio Setti
eba7f8c364 asymmetric_key_data: fix public RSA-2048 key
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-17 05:28:36 +02:00
Valerio Setti
2b0242b6fc generate_test_keys: fix mypy issue for imported path
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-17 05:28:36 +02:00
Valerio Setti
7affeef725 generate_test_keys: use keys from asymmetric_key_data.py
asymmetric_key_data.py already provides EC/RSA key pair values that
are suitable for generate_test_keys.py. So instead of re-generating
the keys using gen_key program, we use those keys.

This commit also:
- extends asymmetric_key_data.py to introduce
RSA bit sizes that are used in test_suite_pk but were missing from
asymmetric_key_data.py.
- updates test_keys.h with new keys.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-17 05:28:36 +02:00
Valerio Setti
b9a3f79a2a test_suite_pk: minor code fixes and comments improvements
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-17 05:28:36 +02:00
Valerio Setti
001ec961c6 generate_test_keys.py: minor improvements
- remove BEGIN_FILE/END_FILE lines from output header file.
- add single disclaimer at the beginning of the file instead
  of having it repeated for every array.
- improved exception message for missing key generation program.

This commits also regenerates "test_keys.h" in order to fully
comply with the new format.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-17 05:28:36 +02:00
Valerio Setti
09e9872037 test_suite_pk: fix guards
Now that key generation has been replaced with parsing predefined
keys, guards for MBEDTLS_PK_PARSE_C need to be added in test
code.
This commits also removes remaining usage of GENPRIME.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-17 05:28:36 +02:00
Valerio Setti
4a350cac4f pk: fix unused variable in copy_from_psa()
key_bits is unused when neither MBEDTLS_RSA_C or MBEDTLS_PK_HAVE_ECC_KEYS
are defined.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-17 05:28:36 +02:00
Valerio Setti
bdb7ae1dad test_suite_pk: add python script to generate predefined keys
This commit adds "generate_test_keys.py" script to generate
predefined keys used in test_suite_pk. Keys are generated with
"programs/pkey/gen_key" tool and converted to C array using
the python script.

tests/src/test_keys.h is automatically generated using the
above mentioned script.

test_suite_pk is updated in order to use the new format.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-17 05:28:36 +02:00
Valerio Setti
88ab0d4ec9 test_suite_pk: simplify pk_psa_genkey()
Instead of using PK module to import/export the key in a PSA friendly
format:

- for RSA keys we use the DER input data directly;
- for EC keys we extract the private key manually.

This helps avoiding dependencies from PK_WRITE and PK_PARSE.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-17 05:28:36 +02:00
Valerio Setti
9658e777b6 test_suite_pk: simplify pk_genkey()
Add pk_info parameter in order to ease the requirements on the provided
PK context. Now it can simply be initialized, but not setup.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-17 05:28:36 +02:00
Valerio Setti
0b15050d5b test_suite_pk: fix key_id initialization value
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-17 05:28:36 +02:00
Valerio Setti
cca2d437d2 test_suite_pk: use look-up table instead of file for the predefined keys
This helps dropping dependency on FS_IO.
This commit also removes DER files that were previusly added and which
are not more needed/used.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-17 05:28:36 +02:00
Valerio Setti
5ec934119d test_suite_pk: remove PSA_WANT_KEY_TYPE_[ECC/RSA]_KEY_PAIR_GENERATE dependencies
EC and RSA keys are now loaded from a file so there is no need
to generate them at runtime.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-04-17 05:28:36 +02:00