1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-08-08 17:42:09 +03:00
Commit Graph

3494 Commits

Author SHA1 Message Date
Gilles Peskine
1b6c09a62e Switch to the new code style
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2023-01-11 14:52:35 +01:00
Manuel Pégourié-Gonnard
6d08dba4f6 Fix test function derive_key_exercise()
mbedtls_test_psa_setup_key_derivation_wrap() returns 1 for success, 0
for error, so the test here was wrong.

This is just a hotfix in order to avoid a testing gap. Larger issues not
addressed here:

- I don't think we should just exit and mark the test as passed; if
we're not doing the actual testing this should be marked as SKIP.
- Returning 1 for success and 0 for failure is a violation of our
documented coding guidelines. We're also supposed to test with == 0 or
!= 0. Having consistent conventions is supposed to help avoid errors
like this.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2023-01-05 10:53:10 +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
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
df310768c8 Fix missing dependency declaration in test
muladd() (restartable or not) is only available when at least one short
weirstrass curve is enabled.

Found by depends.py curves in development.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2022-12-15 10:29:09 +01:00
Dave Rodgman
4547eae341 Merge pull request #984 from Mbed-TLS/mbedtls-2.28.2-merge-back
Mbedtls 2.28.2 merge back
2022-12-14 17:51:58 +00:00
Manuel Pégourié-Gonnard
97ead79cd7 Merge pull request #6204 from wernerlewis/ecp_group_test_2.28
[Backport 2.28] Add test for ECP group metadata
2022-12-13 09:29:40 +01:00
Aditya Deshpande
7428c61df2 Bump LTS version to 2.28.2
Signed-off-by: Aditya Deshpande <aditya.deshpande@arm.com>
2022-12-08 11:05:11 +00:00
Dave Rodgman
5c581dd602 Merge pull request #6735 from daverodgman/fix_test_dep_spelling_2.28
Backport 2.28: Fix spelling of test dependency
2022-12-07 09:06:39 +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
Dave Rodgman
9d7b8eac28 Fix spelling of test dependency
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2022-12-06 14:47:46 +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
13e7307892 Create a separate test suite for constant-time functions
This is the first step in arranging that functions from constant_time.c are
tested in test_suite_constant_time.function.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-12-01 19:49:36 +01:00
Gilles Peskine
3daa98ed95 Move constant-time HMAC testing to its own suite
These are very CPU-intensive, so make it easy to skip them. And conversely,
make it easy to run them without the growing body of SSL tests.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-12-01 19:49:36 +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
Dave Rodgman
ed179db976 Merge pull request #6657 from gilles-peskine-arm/psa-ecb-null-0-2.28
Backport 2.28: Fix NULL+0 undefined behavior in PSA crypto ECB
2022-11-25 17:07:36 +00: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
Gilles Peskine
01bf631159 Fix NULL+0 undefined behavior in ECB encryption and decryption
psa_cipher_encrypt() and psa_cipher_decrypt() sometimes add a zero offset to
a null pointer when the cipher does not use an IV. This is undefined
behavior, although it works as naively expected on most platforms. This
can cause a crash with modern Clang+ASan (depending on compiler optimizations).

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-23 17:23:44 +01:00
Andrzej Kurek
f675727701 Remove blowfish tests from test_suite_ssl
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2022-11-22 09:10:38 -05:00
Gilles Peskine
b358e46c8e Merge pull request #6618 from gilles-peskine-arm/mpi_sint-min-ub-2.28
Backport 2.28: Fix undefined behavior in bignum: NULL+0 and -most-negative-sint
2022-11-21 19:52:03 +01:00
Gilles Peskine
de1629aff9 Fix undefined behavior with the most negative mbedtls_mpi_sint
When x is the most negative value of a two's complement type,
`(unsigned_type)(-x)` has undefined behavior, whereas `-(unsigned_type)x`
has well-defined behavior and does what was intended.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-17 11:03:46 +01:00
Janos Follath
e530b5b4c4 Merge pull request #6579 from gilles-peskine-arm/negative-zero-from-add-2.28
Backport 2.28: Fix negative zero from bignum add/subtract
2022-11-16 14:06:04 +00:00
Manuel Pégourié-Gonnard
8d8266468b Merge pull request #6509 from valeriosetti/issue4577-backport
Backport 2.28: Adding unit test for mbedtls_x509write_csr_set_extension
2022-11-15 09:39:11 +01:00
Valerio Setti
d3f7df4b8a Adding unit test for mbedtls_x509write_csr_set_extension()
The already existing "x509_csr_check()" function is extended in order
to support/test also CSR's extensions. The test is performed by
adding an extended key usage.

Signed-off-by: Valerio Setti <vsetti@baylibre.com>
2022-11-14 13:32:48 +01:00
Tom Cosgrove
020ab7f0af Add additional (would fail) test cases for mpi_mod_int with 0 remainder
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2022-11-10 16:21:06 +00:00
Tom Cosgrove
5c307b9bbe Use mbedtls_mpi_sint not mbedtls_mpi_uint in mpi_mod_int test
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2022-11-10 16:21:06 +00:00
Tom Cosgrove
c2c6fcbcc5 Enable mpi_mod_int test case to take full-range MPI integers
Also add commented-out test cases that currently fail

Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2022-11-10 16:21:06 +00: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
53a7206269 Support negative zero as MPI test input
The bignum module does not officially support "negative zero" (an
mbedtls_mpi object with s=-1 and all limbs zero). However, we have a
history of bugs where a function that should produce an official
zero (with s=1), produces a negative zero in some circumstances. So it's
good to check that the bignum functions are robust when passed a negative
zero as input. And for that, we need a way to construct a negative zero
from test case arguments.

There are checks that functions don't produce negative zeros as output in
the test suite. Skip those checks if there's a negative zero input: we
don't want functions to _create_ negative zeros, but we don't mind if
they _propagate_ negative zeros.

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
Gilles Peskine
d7d5e9a328 Merge pull request #6536 from davidhorstmann-arm/2.28-change-test-templating-syntax
[Backport 2.28] Change test templating syntax to be valid C
2022-11-10 12:05:58 +01:00
Gilles Peskine
d5c76cfd9f Avoid having both test_suite_XXX.data and test_suite_XXX.*.data
Although our build scripts support that, it's annoying, because it makes
"test_suite_XXX" ambiguous between "all the data for
test_suite_XXX.function" and "just test_suite_XXX.data".

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-09 21:00:28 +01:00
Gilles Peskine
5b68608b40 Rename test_suite_bignum for consistency with bignum.{h,c}
Align the name of the bignum test suite with the source module (which was
renamed from mpi.c to bignum.c in the PolarSSL 1.x days). This also brings
it into line with the test suites for the low-level bignum interfaces.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-09 21:00:28 +01:00
Gilles Peskine
cb492102bf Merge pull request #6380 from Kabbah/backport2.28-x509-info-hwmodulename-hex
[Backport 2.28] `x509_info_subject_alt_name`: Render HardwareModuleName as hex
2022-11-08 17:11:09 +01:00
David Horstmann
14bae83ca0 Change test templating syntax to be valid C
For the benefit of auto-formatting tools, move from the '$placeholder'
templating syntax to a new syntax of the form:

__MBEDTLS_TEST_TEMPLATE__PLACEHOLDER

This change allows the test code template to be almost entirely valid C.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2022-11-07 09:55:35 +00:00
Dave Rodgman
0bbe75838e Merge pull request #6191 from daverodgman/invalid-ecdsa-pubkey-backport-2.28
Improve ECDSA verify validation - 2.28 backport
2022-10-31 09:37:38 +00:00
Dave Rodgman
6d61d83f29 Build fix - remove line of dead code
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2022-10-28 09:23:09 +01:00
Dave Rodgman
584200cf4e Update tests/suites/test_suite_ecdsa.function
Co-authored-by: Gilles Peskine <gilles.peskine@arm.com>
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2022-10-27 20:34:56 +01:00
Andrzej Kurek
31788cd8ae Add missing SHA256 dependencies in test_suite_ssl
Most of the tests (including those using endpoint_init functions) parse
certificates that require MBEDTLS_SHA256_C to be present.
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2022-10-27 07:44:13 -04:00
Andrzej Kurek
9821253847 Add missing CBC dependency in test_suite_ssl
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2022-10-27 07:44:13 -04:00
Gilles Peskine
d654171087 Merge pull request #6477 from AndrzejKurek/fix-cipher-deps-2-28
[Backport 2.28] Fix PSA dependencies in test_suite_cipher.[aes|gcm|ccm]
2022-10-26 18:31:39 +02:00
Ronald Cron
2e0a11556e Merge pull request #6483 from gilles-peskine-arm/psa-pkparse-pkwrite-2.28
Backport 2.28: PSA with RSA requires PK_WRITE and PK_PARSE
2022-10-26 14:57:41 +02:00
Ronald Cron
c527796ecb Merge pull request #6392 from davidhorstmann-arm/2.28-fix-x509-get-name-cleanup
[Backport 2.28] Fix `mbedtls_x509_get_name()` cleanup
2022-10-26 14:28:04 +02:00
Gilles Peskine
c037ba9c3e Add some missing dependencies on PKCS12 for encrypted keys
This is a PKCS#8 test case using a PKCS#12 algorithm.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-10-25 21:08:39 +02:00
Gilles Peskine
bfcf2d129d test_suite_pk: Add missing dependencies on MBEDTLS_PEM_PARSE_C
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-10-25 20:08:38 +02:00
Gilles Peskine
8f3577a53d test_suite_dhm: Add missing dependencies on MBEDTLS_PEM_PARSE_C
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-10-25 20:08:29 +02:00
Gilles Peskine
4e10fb2396 Add mbedtls_dhm_parse_dhmfile test case with DER input
dh.optlen.der is the result of converting dh.optlen.pem from PEM to DER.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-10-25 20:07:49 +02:00
Andrzej Kurek
84fc52c6b3 Formatting & cosmetic fixes
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2022-10-25 04:18:30 -04:00
David Horstmann
6c4226ce95 Change brace initialization to memset
Signed-off-by: David Horstmann <david.horstmann@arm.com>
2022-10-24 15:30:30 +01:00