Commit graph

4506 commits

Author SHA1 Message Date
Bence Szépkúti
ae79fb2c2e Merge branch 'development' into pr3431 2022-11-25 03:12:43 +01:00
Tom Cosgrove
d66d5b2fef Add unit tests for mbedtls_mpi_core_sub_int(), MPI A - scalar b
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2022-11-22 15:07:31 +00:00
Bence Szépkúti
a17d038ee1 Merge branch 'development' into pr3431 2022-11-22 15:54:52 +01:00
Gilles Peskine
4f19d86e3f
Merge pull request #6608 from mprse/ecjpake_password_fix
Make a copy of the password key in operation object while setting j-pake password
2022-11-22 14:52:12 +01:00
Gilles Peskine
339406daf9
Merge pull request #6609 from gilles-peskine-arm/mpi_sint-min-ub
Fix undefined behavior in bignum: NULL+0 and -most-negative-sint
2022-11-21 19:51:58 +01:00
Przemek Stekiel
f82effa982 Optimize pake test code
Signed-off-by: Przemek Stekiel <przemyslaw.stekiel@mobica.com>
2022-11-21 15:10:32 +01:00
Przemek Stekiel
cd356c3cdb Add ec-jpake test to verify if key can be destroyed after set_password_key
Signed-off-by: Przemek Stekiel <przemyslaw.stekiel@mobica.com>
2022-11-21 12:25:21 +01:00
Tom Cosgrove
8c0eb9744c Must call mbedtls_mpi_mod_modulus_init() before anything else in tests
Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2022-11-17 08:48:12 +00:00
Przemek Stekiel
7c7954842b Adapt ec-jpake_setup test
Now when operation holds pointer to dynamically allocated buffer for password key we can't do copy of the operation object in test instead we need to re-initialize operation object after error.

Signed-off-by: Przemek Stekiel <przemyslaw.stekiel@mobica.com>
2022-11-16 16:27:55 +01:00
Gilles Peskine
af601f9751 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-15 23:02:14 +01:00
Gilles Peskine
ca6e8aac58 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-15 20:47:07 +01:00
Gilles Peskine
2909f53740
Merge pull request #6604 from tom-cosgrove-arm/call-mbedtls_mpi_mod_modulus_init-first-cid-381893-381894
Bignum: Must call mbedtls_mpi_mod_modulus_init() before anything else in tests
2022-11-15 12:33:13 +01:00
Manuel Pégourié-Gonnard
edce0b42fb
Merge pull request #6454 from valeriosetti/issue4577
Adding unit test for mbedtls_x509write_csr_set_extension()
2022-11-15 09:39:07 +01:00
Tom Cosgrove
f90111b2b5 Must call mbedtls_mpi_mod_modulus_init() before anything else in tests
Fixes (new) Coverity issues 381893 and 381894

Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2022-11-15 06:15:15 +00:00
Valerio Setti
48e8fc737a 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:07 +01:00
Janos Follath
1b9cb62702
Merge pull request #6573 from tom-cosgrove-arm/convert-mpi_mod_int-test-cases-to-hex
Enable mpi_mod_int test case to take full-range MPI integers
2022-11-14 12:04:09 +00:00
Minos Galanakis
47691fb756 bignum_tests: Refactored mpi_mod_raw_to/fromt_mont_rep
This patch migrates the tests to use the `mbedtls_test_read_mpi_core()`.

Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2022-11-11 10:55:08 +00:00
Minos Galanakis
df070d660d bignum_tests: Added test for mbedtls_mpi_mod_raw_from_mont_rep()
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2022-11-11 10:55:08 +00:00
Minos Galanakis
631b491cbf bignum_tests: Added test for mbedtls_mpi_mod_raw_to_mont_rep()
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2022-11-11 10:55:08 +00:00
Dave Rodgman
ebd0caffdf Fix test memory allocation
Fix error in memory allocation in test code, which was triggering an
error in test_memory_buffer_allocator.

Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2022-11-10 15:33:54 +00:00
Tom Cosgrove
163d8952b3 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 12:17:36 +00:00
Tom Cosgrove
9feb19f98d 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 12:05:55 +00:00
Gilles Peskine
b4eb444a5c
Merge pull request #6535 from davidhorstmann-arm/change-test-templating-syntax
Change test templating syntax to be valid C
2022-11-10 12:05:55 +01:00
Dave Rodgman
f58172fe43 Merge remote-tracking branch 'origin/development' into pr3431 2022-11-10 09:54:49 +00:00
Gilles Peskine
ed4b34aa7c
Merge pull request #6570 from gilles-peskine-arm/bignum-mbedtls_test_read_mpi_core-nonempty
Forbid empty mpi_core in test data
2022-11-09 19:02:24 +01:00
Tom Cosgrove
91e35e3c32 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-09 11:45:29 +00:00
Manuel Pégourié-Gonnard
b9581824f7
Merge pull request #6561 from AndrzejKurek/ecjpake-error-injection
Improve error injection in EC J-PAKE tests
2022-11-09 11:48:36 +01:00
Gilles Peskine
95b5addcd6 Don't test mbedtls_mpi_core_lt_ct with 0 limbs
A core MPI must have at least 1 limb. We can no longer test with 0 limbs,
and we don't need to anyway, so don't try.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-09 11:18:38 +01:00
Gilles Peskine
4a480ac5a1
Merge pull request #6265 from Kabbah/x509-info-hwmodulename-hex
`x509_info_subject_alt_name`: Render HardwareModuleName as hex
2022-11-08 17:11:07 +01:00
Andrzej Kurek
c018204019 Improve error injection in EC J-PAKE tests
Instead of corrupting the public key part of the message,
corrupt the proof part. A proof is conceptually similar to a signature,
and changing anything in it should make it invalid with 
a high probability.
Also, instead of shifting data, perform a bitflip.
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2022-11-08 08:12:56 -05:00
Gilles Peskine
42d75f2daf
Merge pull request #6013 from gstrauss/asn1-type-free
Shared code to free x509 structs like mbedtls_x509_named_data
2022-11-08 12:20:20 +01:00
Gilles Peskine
433f1f1809
Merge pull request #6456 from gabor-mezei-arm/6237_test_update_cond_assign_swap
Update tests to use conditional assign and swap
2022-11-08 12:15:07 +01:00
Glenn Strauss
2a64299648
Update tests/suites/test_suite_asn1parse.function
Co-authored-by: Andrzej Kurek <andrzej.kurek@arm.com>
Signed-off-by: Glenn Strauss <gstrauss@gluelogic.com>
2022-11-07 20:09:38 -05:00
Glenn Strauss
aa36c2a6f6
Update tests/suites/test_suite_asn1parse.function
Co-authored-by: Andrzej Kurek <andrzej.kurek@arm.com>
Signed-off-by: Glenn Strauss <gstrauss@gluelogic.com>
2022-11-07 20:08:54 -05:00
Glenn Strauss
82ba274c01 Deprecate mbedtls_asn1_free_named_data()
Signed-off-by: Glenn Strauss <gstrauss@gluelogic.com>
2022-11-07 15:42:44 -05:00
Gilles Peskine
faefe62013
Merge pull request #6390 from mpg/fix-ecjpake-psa-format
Fix ecjpake PSA format
2022-11-07 17:35:44 +01:00
Gabor Mezei
a8cf998bc9
Let the allocated memory visible for the memory sanitizer
Signed-off-by: Gabor Mezei <gabor.mezei@arm.com>
2022-11-07 15:14:49 +01:00
Gabor Mezei
7ba7b3aded
Update tests to use mbedtls_test_read_mpi_core
In conditional assign and swap tests use the mbedtls_test_read_mpi_core
function for reading MPIs.

Signed-off-by: Gabor Mezei <gabor.mezei@arm.com>
2022-11-07 15:14:49 +01:00
David Horstmann
b85838f2f4 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-04 19:53:39 +00:00
Dave Rodgman
2364aaefa6
Update tests/suites/test_suite_pkcs7.function
Address test dependency issue

Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2022-11-04 11:33:04 +00:00
Nick Child
fc234b7b52 test/pkcs7: Add Windows CRLF EOF to data files
Windows tests are failing pkcs7 verification due to differnt line
endings. Therefore, add make instuctions for building the data
files with Windows EOF instead. As a result, regenerate other data
files so that verification works.

Add these CRLF EOF files to the exception in check_files to ignore
the line endings.

Signed-off-by: Nick Child <nick.child@ibm.com>
2022-11-03 09:24:20 -05:00
Janos Follath
c1a81bc998 Remove trailing new lines
Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-02 17:33:11 +00:00
Janos Follath
6642cafae3 Fix merge separator position
Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-02 17:28:39 +00:00
Janos Follath
be13652296 Use comments for merge separators in .data files
We do have a comment syntax for .data files, there is no need for dummy
test cases.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-02 17:28:37 +00:00
Janos Follath
5933f691a2 Add merge slots to Bignum files
Legacy Bignum is excluded as it doesn't get regular extensions like new
ones.

Each slot uses comments of their respective filetype. Since .data files
don't have a syntax for comments, dummy test cases are used. (These test
cases will never be executed and no noise will be added to tests.)

Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-02 17:27:25 +00:00
Gilles Peskine
dd54324765 Increase iterations for some statistical tests
I ran into a sequence where the assertion `stats[8] > 0` failed for the
range 1..272 with 100 iterations.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-02 16:00:01 +01:00
Gilles Peskine
5980f2bd36 Implement mbedtls_mpi_core_fill_random
Turn mpi_fill_random_internal() into mbedtls_mpi_core_fill_random(). It
had basically the right code except for how X is passed to the function.

Write unit tests.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-02 15:59:36 +01:00
Janos Follath
f1ed5815ba
Merge pull request #6512 from yanesca/extract_uint_table_lookup_core
Implement mbedtls_mpi_core_ct_uint_table_lookup()
2022-11-02 13:58:19 +00:00
Janos Follath
28f85e6683 Fix const time in mpi_core_ct_uint_table_lookup test
Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-02 10:20:35 +00:00
Janos Follath
ef67d38bc0 Fix memory leak in mpi_core_ct_uint_table_lookup test
Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-10-31 15:11:49 +00:00