Commit Graph

9630 Commits

Author SHA1 Message Date
Gilles Peskine
bbc4b8d2be New test helper mbedtls_test_read_mpi
This test helper reads an MPI from a string and guarantees control over the
number of limbs of the MPI, allowing test cases to construct values with or
without leading zeros, including 0 with 0 limbs.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-06-22 18:47:44 +02:00
Gilles Peskine
aa9d9ac598 Clarify a few test descriptions (mostly involving 0)
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-06-22 18:47:44 +02:00
Manuel Pégourié-Gonnard
07941f45e6 Merge pull request #4690 from gilles-peskine-arm/debug-print-mpi-null-2.16
Backport 2.16: Fix mbedtls_debug_print_mpi crash on 0
2021-06-22 12:09:05 +02:00
Manuel Pégourié-Gonnard
c9807ea0cc Merge pull request #4622 from gilles-peskine-arm/default-hashes-curves-2.16
Backport 2.16: Curve and hash selection for X.509 and TLS
2021-06-22 12:08:49 +02:00
Dave Rodgman
b3b1d4d9b4 Merge pull request #4684 from JoeSubbiani/2.16FixedMissingContextFree
Backport 2.16: Add Free context at the end of aes_crypt_xts_size()
2021-06-22 09:24:19 +01:00
Manuel Pégourié-Gonnard
58344efc91 Merge pull request #4689 from gilles-peskine-arm/winsock-fd-range-2.16
Backport 2.16: Fix net_sockets regression on Windows
2021-06-22 09:29:41 +02:00
Joe Subbiani
b047f99441 Reword changelog - Test Resource Leak
- “Fix an issue where X happens” → ”Fix X“
  the extra words are just a distraction.
- “resource” → “a resource”
- “where resource is never freed” has a name: it's a resource leak
- “when running one particular test suite” → “in a test suite”

Signed-off-by: Joe Subbiani <joe.subbiani@arm.com>
2021-06-21 16:59:25 +01:00
Joe Subbiani
c8031855d0 Update changelog formatting - Missing Free Context
Missing trailing full stop added to the end of the fixed issue number

Signed-off-by: Joe Subbiani <joe.subbiani@arm.com>
2021-06-21 09:30:50 +01:00
Gilles Peskine
3db875e66a Add missing parentheses
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-06-21 10:14:41 +02:00
Gilles Peskine
5eace4c826 Indicate that the truncation from size_t to int is deliberate
MPI sizes do fit in int. Let MSVC know this conversion is deliberate.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-06-21 10:14:41 +02:00
Gilles Peskine
e1a31284de Simplify mbedtls_debug_print_mpi and fix the case of empty bignums
Rewrite mbedtls_debug_print_mpi to be simpler and smaller. Leverage
mbedtls_mpi_bitlen() instead of manually looking for the leading
zeros.

Fix #4608: the old code made an invalid memory dereference when
X->n==0 (freshly initialized bignum with the value 0).

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-06-21 10:14:41 +02:00
Gilles Peskine
6345e12161 Add mbedtls_debug_print_mpi test case for 0
There was already a test case for 0 but with a non-empty representation
(X->n == 1). Add a test case with X->n == 0 (freshly initialized mpi).

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-06-21 10:13:43 +02:00
Gilles Peskine
d8aa3dbb04 Clarify test case descriptions
Reorder test cases and make their descriptions more explicit. No
change in test data.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-06-21 10:13:43 +02:00
Gilles Peskine
3257399efb SHA-1 is allowed for handshake signatures by default
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-06-21 09:54:03 +02:00
Gilles Peskine
8297657759 Fix fd range for select on Windows
Fix mbedtls_net_poll() and mbedtls_net_recv_timeout() often failing with
MBEDTLS_ERR_NET_POLL_FAILED on Windows: they were testing that the file
descriptor is in range for fd_set, but on Windows socket descriptors are not
limited to a small range. Fixes #4465.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-06-20 23:19:05 +02:00
Gilles Peskine
9065d786fd Refactor file descriptor checks into a common function
This will make it easier to change the behavior uniformly.

No behavior change.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-06-20 23:19:04 +02:00
Joe Subbiani
dcdb277f34 Update changelog formatting - Missing Free Context
Trailing white space causing check_files.py to fail
issue4176.txt was also in dos format - this has been
changed to unix

Signed-off-by: Joe Subbiani <joe.subbiani@arm.com>
2021-06-18 18:59:01 +01:00
Joe Subbiani
cbe60337e3 Update changelog formatting - Missing Free Context
The original formatting was in dos and the changelog
assembler would fail. The length of the description was
too long horizontally. This has been updated.

Signed-off-by: Joe Subbiani <joe.subbiani@arm.com>
2021-06-18 15:23:34 +01:00
JoeSubbiani
402b1451c0 Changelog entry for Free Context in test_suite_aes fix
Signed-off-by: Joe Subbiani <joe.subbiani@arm.com>
2021-06-18 11:47:08 +01:00
JoeSubbiani
2f28c6b677 Free context at the end of aes_crypt_xts_size()
in file tests/suite/test_suite_aes.function, aes_crypt_xts_size()
did not free the context upon the function exit.
The function now frees the context on exit.

Already resolved for 2.x and development - this is a backport for
2.16

Fixes #4176

Signed-off-by: JoeSubbiani <Joe.Subbiani@arm.com>
2021-06-18 11:05:47 +01:00
Manuel Pégourié-Gonnard
56efc52d6b Merge pull request #4628 from ronald-cron-arm/dhm-key-generation-bias
dhm: Fix bias in private key generation
2021-06-16 13:13:34 +02:00
Gilles Peskine
ebe9ec448b Add changelog entry for non-uniform MPI random generation
Fix #4245.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-06-11 08:52:21 +02:00
Ronald Cron
2e0969abce ecp: Fix bias in the generation of blinding values
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2021-06-11 08:52:14 +02:00
Dave Rodgman
7ef266045b Merge pull request #4645 from daverodgman/travis-disable-osx-2.16
Backport 2.16: Disable OS X Travis builds
2021-06-10 17:48:42 +01:00
Dave Rodgman
58d238a3a4 Disable OS X builds on Travis
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2021-06-10 15:51:28 +01:00
Gilles Peskine
424d13ce7d DHM: add test case with x_size < 0
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-06-10 10:40:48 +02:00
Gilles Peskine
60c4fec07f DHM tests: add some explanations
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-06-10 10:40:42 +02:00
Gilles Peskine
39b1a51cc3 DHM: add notes about leading zeros
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-06-10 10:40:37 +02:00
Ronald Cron
b4367a358f dhm: Fix bias in private key generation and blinding
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2021-06-10 10:40:34 +02:00
Gilles Peskine
260be63e7d dhm_check_range: microoptimization
No need to build a bignum for the value 2.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-06-10 10:40:30 +02:00
Gilles Peskine
c53560ea00 DHM refactoring: use dhm_random_below in dhm_make_common
dhm_make_common includes a piece of code that is identical to
dhm_random_below except for returning a different error code in one
case. Call dhm_random_below instead of repeating the code.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-06-10 10:40:26 +02:00
Gilles Peskine
b2fbda3867 DHM blinding: don't accept P-1 as a blinding value
P-1 is as bad as 1 as a blinding value. Don't accept it.

The chance that P-1 would be randomly generated is infinitesimal, so
this is not a practical issue, but it makes the code cleaner. It was
inconsistent to accept P-1 as a blinding value but not as a private key.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-06-10 10:40:19 +02:00
Gilles Peskine
e75bb6308a DHM refactoring: unify mbedtls_dhm_make_{params,public}
Unify the common parts of mbedtls_dhm_make_params and mbedtls_dhm_make_public.

No intended behavior change, except that the exact error code may
change in some corner cases which are too exotic for the existing unit
tests.

Removed usage of MBEDTLS_ERROR_ADD which does not exist in 2.16.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-06-10 10:35:51 +02:00
Gilles Peskine
d1eb14ae8a Test mbedtls_dhm_make_params with different x_size
mbedtls_dhm_make_params() with x_size != size of P is not likely to be
useful, but it's supported, so test it.

Cherry-picked 33ec863570
Changed mbedtls_test_rnd_pseudo_info type to rnd_pseudo_info

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2021-06-10 10:35:36 +02:00
Gilles Peskine
863b83b666 Repeat a few DH tests
Repeat a few tests that use random data. This way the code is
exercised with a few different random values.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-06-10 10:35:18 +02:00
Gilles Peskine
92f4714e7e Test range and format of dhm_make_params output
Improve the validation of the output from mbedtls_dhm_make_params:
* Test that the output in the byte buffer matches the value in the
  context structure.
* Test that the calculated values are in the desired range.

Cherry-picked dc0b6e44b0.
Changed mbedtls_test_rnd_pseudo_rand to rnd_pseudo_rand.
Removed test step code.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2021-06-10 10:34:37 +02:00
Gilles Peskine
169fa2336b Document more precisely what goes into the default preset
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-06-07 21:30:15 +02:00
Gilles Peskine
347ada71cc Document more precisely what goes into the default profile
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-06-07 21:30:15 +02:00
Gilles Peskine
6db34e6e01 Merge pull request #4542 from mpg/fix-ssl-cf-hmac-alt-2.16
[Backport 2.16] Fix misuse of MD API in SSL constant-flow HMAC
2021-06-07 20:53:53 +02:00
Gilles Peskine
806281a663 Merge pull request #4598 from gilles-peskine-arm/ecp_muladd-tests_not_executed-2.16
Backport 2.16: Fix null pointer arithmetic in NIST_KW
2021-06-01 16:40:11 +02:00
Gilles Peskine
995d89c9f2 Fix null pointer arithmetic in error case
When mbedtls_nist_kw_wrap was called with output=NULL and out_size=0, it
performed arithmetic on the null pointer before detecting that the output
buffer is too small and returning an error code. This was unlikely to have
consequences on real-world hardware today, but it is undefined behavior and
UBSan with Clang 10 flagged it. So fix it (fix #4025).

Fix a similar-looking pattern in unwrap, though I haven't verified that it's
reachable there.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-06-01 13:03:34 +02:00
Gilles Peskine
8e7d7ee1ae Fix ecp_muladd test cases never getting executed
These test cases had been backported from Mbed TLS 2.x with a dependency
symbol that didn't exist in 2.16. Declare that symbol.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-05-31 20:25:26 +02:00
Gilles Peskine
5f45bd2bab New macros TEST_EQUAL, ASSERT_ALLOC, ASSERT_ALLOC_WEAK
Backports some test helper macros added after 2.16. This will facilitate
backporting new test code.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-05-31 15:40:31 +02:00
Gilles Peskine
e0b455fb51 Remove spurious dependencies on PEM
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-05-31 15:23:00 +02:00
Gilles Peskine
7f3f02d230 Merge pull request #4558 from gilles-peskine-arm/aria_alt-2.16
Backport 2.16: Fix ARIA_ALT header and self-test and CAMELLIA_ALT self-test
2021-05-25 20:32:49 +02:00
Gilles Peskine
a776bf8deb Changelog entry for the ARIA_ALT and CAMELLIA_ALT fixes
Fix ARMmbed/mbed-os#14694

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-05-25 18:45:46 +02:00
Gilles Peskine
39f5dae5b6 CAMELLIA: add missing context init/free
This fixes the self-test with alternative implementations.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-05-25 18:45:46 +02:00
Gilles Peskine
ba93f598cc ARIA: add missing context init/free
This fixes the self-test with alternative implementations.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-05-25 18:45:46 +02:00
Gilles Peskine
e0e132f847 Fix misplaced extern "C" affecting MBEDTLS_ARIA_ALT
Reported via Mbed OS:
https://github.com/ARMmbed/mbed-os/issues/14694

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-05-25 18:45:46 +02:00
Ronald Cron
1bc2c9cb8b Merge pull request #4534 from gilles-peskine-arm/host_test-int32-2.16
Backport 2.16: Fix build error in host_test.function when int32_t is not int
2021-05-21 16:01:50 +02:00