1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-05-28 16:21:27 +03:00

17370 Commits

Author SHA1 Message Date
Gilles Peskine
4eea196d44 Enable all ciphers in OpenSSL >=1.1.0
OpenSSL may be configured to support features such as cipher suites or
protocol versions that are disabled by default. Enable them all: we're
testing, we don't care about enabling insecure stuff. This is not needed
with the builds of OpenSSL that we're currently using on the Jenkins CI, but
it's needed with more recent versions such as typically found on developer
machines, and with future CI additions.

The syntax to do that was only introduced in OpenSSL 1.1.0; fortunately we
don't need to do anything special with earlier versions.

With OpenSSL 1.1.1f on Ubuntu 20.04, this is needed to enable TLS 1.0, TLS
1.1 and DTLS 1.0. This also allows SHA-1 in certificates, which is still
needed for a few test cases in ssl-opt.sh. Curiously, this is also needed
for the cipher suite TLS-DHE-PSK-WITH-ARIA-128-GCM-SHA256 (and no other,
including other DHE-PSK or ARIA cipher suites).

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-24 22:43:10 +01:00
Ronald Cron
0f6fb0cab2 compat.sh: Restore testing against OpenSSL for pre 1.2 TLS versions
Restore compatibiltiy testing against OpenSSL for
(D)TLS versions smaller that 1.2.

. Fix the check for support in OpenSSL for these versions
. For test cases for (D)TLS version smaller than 1.2,
  restore the configuration of OpenSSL client/server
  with the given TLS version, as it was before #5660
  that broke it.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2022-11-24 14:40:01 +01: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
8fe23a065a Fix MSVC 12 (Visual Studio 2013) choking on inline
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-23 17:24:37 +01: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
f53d0ba529 depends.py: remove tls defines in SHA-512-only test
TLS 1.2 requires either SHA-256 or SHA-384.
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2022-11-23 05:54:46 -05:00
Manuel Pégourié-Gonnard
99ac73d963
Merge pull request #969 from yanesca/issue-946-backport
[2.28 Backport] Fix RSA side channel
2022-11-23 10:30:40 +01:00
Janos Follath
b118d54ff6 mpi_exp_mod: use x_index consistently
Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-22 15:00:46 +00: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
05dcb1300d
Merge pull request #6613 from gilles-peskine-arm/run-test-suites-out-of-tree-2.28
Backport 2.28: Fix run-test-suites.pl in out-of-tree builds
2022-11-22 15:01:21 +01:00
Andrzej Kurek
aa11281c07 Add a SHA512_NO_SHA384_C test to depends.py
Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
2022-11-22 08:13:45 -05:00
Janos Follath
c772869713 Changelog: expand conference acronym for clarity
Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-22 10:51:25 +00:00
Janos Follath
6c5b5adb46 mpi_exp_mod: reduce the table size by one
The first half of the table is not used, let's reuse index 0 for the
result instead of appending it in the end.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-22 10:47:10 +00:00
Janos Follath
6fa7a766cc mpi_exp_mod: fix out of bounds access
The table size was set before the configured window size bound was
applied which lead to out of bounds access when the configured window
size bound is less.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-22 10:21:52 +00:00
Janos Follath
2b72690e14 mpi_mod_exp: be pedantic about right shift
The window size starts giving diminishing returns around 6 on most
platforms and highly unlikely to be more than 31 in practical use cases.
Still, compilers and static analysers might complain about this and
better to be pedantic.

Co-authored-by: Gilles Peskine <gilles.peskine@arm.com>
Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-22 10:21:03 +00: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
Janos Follath
82e8133edc Add paper title to Changelog
Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-21 16:22:35 +00:00
Janos Follath
6e2d8e3e28 mpi_exp_mod: improve documentation
Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-21 16:14:54 +00:00
Janos Follath
d88e21941c mpi_exp_mod: remove the 'one' variable
Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-21 15:54:20 +00:00
Janos Follath
a92f9155a5 mpi_exp_mod: simplify freeing loop
Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-21 15:05:31 +00:00
Janos Follath
aadbadbf42 mpi_exp_mod: move X next to the precomputed values
With small exponents (for example, when doing RSA-1024 with CRT, each
prime is 512 bits and we'll use wsize = 5 which may be smaller that the
maximum - or even worse when doing public RSA operations which typically
have a 16-bit exponent so we'll use wsize = 1) the usage of W will have
pre-computed values, then empty space, then the accumulator at the very
end.

Move X next to the precomputed values to make accesses more efficient
and intuitive.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-21 14:55:05 +00:00
Janos Follath
6632383993 mpi_exp_mod: rename local variables
Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-21 14:48:02 +00:00
Janos Follath
f0ceb1cae1 mpi_exp_mod: remove memory ownership confusion
Elements of W didn't all have the same owner: all were owned by this
function, except W[x_index]. It is more robust if we make a proper copy
of X.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-21 14:31:22 +00:00
Manuel Pégourié-Gonnard
597e87eb48
Merge pull request #974 from ronald-cron-arm/buffer-overflow-in-cid-fix-2.28
[2.28 Backport] Fix in_cid buffer size in transform structure
2022-11-18 09:48:15 +01:00
Ronald Cron
7345073aaf Add ChangeLog
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2022-11-17 15:21:07 +01:00
Ronald Cron
f385fcebee tls: Fix in_cid buffer size in transform structure
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2022-11-17 15:20:21 +01:00
Gilles Peskine
ae7cbd7576 Express abs(z) in a way that satisfies GCC and MSVC
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-17 11:03:46 +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
Gilles Peskine
103cf59e46 Fix NULL+0 in addition 0 + 0
Fix undefined behavior (typically harmless in practice) of
mbedtls_mpi_add_mpi(), mbedtls_mpi_add_abs() and mbedtls_mpi_add_int() when
both operands are 0 and the left operand is represented with 0 limbs.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-17 11:03:46 +01:00
Gilles Peskine
cab02f6bc8 Document mbedtls_mpi_uint and mbedtls_mpi_sint
Since they're part of the public API (even if only through a few functions),
they should be documented.

I deliberately skipped documenting how to configure the size of the type.
Right now, MBEDTLS_HAVE_INT32 and MBEDTLS_HAVE_INT64 have no Doxygen
documentation, so it's ambiguous whether they're part of the public API.
Resolving this ambiguity is out of scope of my current work.

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
Gilles Peskine
6b7c3ccfed Use .datax for make test, not .data
Looking for the .data file doesn't work in out-of-tree builds. Use the
.datax file instead. `make clean` removes all .datax files, so this resolves
the issue of executables not present on the current branch being left behind
after a branch change followed by a `make clean`.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-16 10:35:20 +01:00
Gilles Peskine
0fcc1cb4c2
Merge pull request #6583 from aditya-deshpande-arm/bugfix-dh_genprime
[Backport 2.28] dh_genprime: Fix issue where the error code returned by mbedtls_mpi_write_file() is incorrectly reported on failure
2022-11-15 12:38:38 +01: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
Janos Follath
5c03ec3429
Merge pull request #6575 from tom-cosgrove-arm/convert-mpi_mod_int-test-cases-to-hex-228
Backport 2.28: Enable mpi_mod_int test case to take full-range MPI integers
2022-11-14 12:03:00 +00:00
Janos Follath
3a3c50ca0a mpi_exp_mod: improve documentation
Signed-off-by: Janos Follath <janos.follath@arm.com>
2022-11-11 15:56:38 +00:00
Gilles Peskine
d64123a17e Fix autocucumber in documentation
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-11 15:59:51 +01:00
Pengyu Lv
f513197d0d fix PSA_XXX typos detected by check_names.py
Fix the PSA_XXX typos detected by check_names.py.

Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2022-11-11 14:19:22 +08:00
Pengyu Lv
fda7f508d8 add exclusive rule for PSA_CRYPTO_DRIVER_TEST
This macro is expected to be defined out of the library, and there
is no definition in the library. Thus it needs to be excluded from
typo check.

Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2022-11-11 12:17:23 +08:00
Pengyu Lv
018b2f6a62 check_names: extend typo check to PSA macro/enum names
Typos of PSA macro and enum names are not checked by check_names.py.
This commit extend the check list to include PSA_XXX references.
The words should be macro/enum names defined as public_macros,
internal_macros, private_macros and enums. This commit also extend
the scope of enums to include those are defined in library/*.c.
A new type of macros "private", which are defined in library/*.c was
also added.

Signed-off-by: Pengyu Lv <pengyu.lv@arm.com>
2022-11-11 12:13:04 +08: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
Aditya Deshpande
f22f73ef4e Fix issue in dh_genprime.c where the error code returned by mbedtls_mpi_write_file() is incorrectly reported on failure
Signed-off-by: Aditya Deshpande <aditya.deshpande@arm.com>
2022-11-10 15:33:11 +00:00
Paul Elliott
4637ed2205
Merge pull request #6545 from davidhorstmann-arm/2.28-fix-unusual-macros-0-followup
Refactor/tidy after fixing unusual macros
2022-11-10 14:27:14 +00:00
Gilles Peskine
83763ab6b1 Pacify pylint
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-10 15:15:25 +01: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
195e1c8107 Changelog entry for the negative zero from add/sub
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-11-10 15:15:25 +01:00