9715 Commits

Author SHA1 Message Date
Mahavir Jain
73cfa42bd3 bignum: add provision for combined software and hardware MPI approach
For exponential mod (API mbedtls_mpi_exp_mod) operation, some ESP target
chips needs to have ability for both hardware and software implementation.

Hardware implementation provided performance advantage but it can only
support upto 3072 bit operations (e.g., ESP32-C3) and hence we fallback
to software implementation in such cases (e.g., 4096 bit operations).

Earlier this was handled using linker "--wrap" flag but that does not
work in all scenarios as API `mbedtls_mpi_exp_mod` is being used in
same tranlation (compilation unit).

This approach was found to be next best option with minimal changes in
mbedTLS library.
2021-11-26 14:46:39 +05:30
Mahavir Jain
6465247f67 Updated minimum cmake requirement down to 2.8.12
Upcoming cmake 3.19 will not support cmake 2.6 any more, hence
the fix.

Please see https://github.com/ARMmbed/mbedtls/pull/3802 for
more details.
2021-07-07 20:34:14 +05:30
Prasad Alatkar
9bfd0ffe74 Fix maybe-uninitialized warnings resulting in build failure. 2021-07-07 20:34:07 +05:30
Mahavir Jain
c446e42ed9 Fix few warnings resulting in build failures 2021-07-07 20:34:01 +05:30
Angus Gratton
49733cf7a0 mbedtls: Re-apply MBEDTLS_BIGNUM_ALT & related macros for custom bignum functions
(IDF-specific patch.)
2021-07-07 20:33:55 +05:30
Dave Rodgman
aa1d4e0973
Merge pull request #845 from ARMmbed/mbedtls-2.16.11rc0-pr
Mbedtls 2.16.11rc0 pr
2021-07-06 12:59:45 +01:00
Bence Szépkúti
571f475788 Set version and release date in ChangeLog
Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
2021-07-05 19:48:18 +02:00
Dave Rodgman
8005aa2adf Fix indentation in the Changelog
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2021-07-05 19:40:48 +02:00
Bence Szépkúti
124a87ea6f Bump library version numbers
Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
2021-07-05 18:47:36 +02:00
Bence Szépkúti
53b960d9e0 Create aggregated ChangeLog
Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
2021-07-05 16:17:07 +01:00
Bence Szépkúti
726a8ccb6d Merge branch 'mbedtls-2.16-restricted' into mbedtls-2.16.11rc0-pr 2021-07-02 14:00:19 +01:00
Dave Rodgman
4c20c774a1
Merge pull request #4735 from daverodgman/alert_bugfixes_2.16
Backport 2.16: Fix alert raised for invalid fragment length
2021-06-30 09:02:45 +01:00
Dave Rodgman
cee9e92255 Correct required config flag in ECJPAKE tests
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2021-06-29 21:15:28 +01:00
Gilles Peskine
90e6c24cf9
Merge pull request #4719 from nick-child-ibm/2.16-hashlen
Backport 2.16: pk.c: Ensure min hash_len in pk_hashlen_helper
2021-06-29 18:16:55 +02:00
Dave Rodgman
ffbbeee284 TLS UNSUPPORTED_EXTENSION error code changes
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2021-06-29 15:19:26 +01:00
Nick Child
c15e31d355 pk.c: Ensure min hash_len in pk_hashlen_helper
The function `pk_hashlen_helper` exists to ensure a valid hash_len is
used in pk_verify and pk_sign functions. This function has been
used to adjust to the corrsponding hash_len if the user passes in 0
for the hash_len argument based on the md algorithm given. If the user
does not pass in 0 as the hash_len, then it is not adjusted. This is
problematic if the user gives a hash_len and hash buffer that is less than the
associated length of the md algorithm. This error would go unchecked
and eventually lead to buffer overread when given to specific pk_sign/verify
functions, since they both ignore the hash_len argument if md_alg is not
MBEDTLS_MD_NONE.

This commit, adds a conditional to `pk_hashlen_helper` so that an
error is thrown if the user specifies a hash_length (not 0) and it is
less than the expected for the associated message digest algorithm.
This aligns better with the api documentation where it states "If
hash_len is 0, then the length associated with md_alg is used instead,
or an error returned if it is invalid"

Signed-off-by: Nick Child <nick.child@ibm.com>
Signed-off-by: Nayna Jain <nayna@linux.ibm.com>
2021-06-29 09:44:04 -04:00
Dave Rodgman
84fa2c941a Improve Changelog for TLS alert codes
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2021-06-29 14:41:55 +01:00
Dave Rodgman
459a46102d Fix TLS alert codes
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2021-06-29 09:44:35 +01:00
Gilles Peskine
f8ed50c74a
Merge pull request #841 from yanesca/reject-low-order-points-early-x25519-restricted-2.16
[Backport 2.16] Reject low order points early x25519
2021-06-28 13:45:54 +02:00
Janos Follath
1001d2c711 Fix unused parameter warning
Signed-off-by: Janos Follath <janos.follath@arm.com>
2021-06-28 10:24:20 +01:00
Janos Follath
7a8a0d7e3d Add ChangeLog entry
Signed-off-by: Janos Follath <janos.follath@arm.com>
2021-06-28 10:24:20 +01:00
Janos Follath
9a64d3e0ca Add prefix to BYTES_TO_T_UINT_*
These macros were moved into a header and now check-names.sh is failing.
Add an MBEDTLS_ prefix to the macro names to make it pass.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2021-06-28 10:24:20 +01:00
Janos Follath
84ef97a450 Fix ecp_check_pub() test cases
Negative x coordinate was tested with the value -1. It happens to be one
of the low order points both for Curve25519 and Curve448 and might be
rejected because of that and not because it is negative. Make sure that
x < 0 is the only plausible reason for the point to be rejected.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2021-06-28 10:24:20 +01:00
Janos Follath
921415b0c2 Add ecp_check_pub tests for Curve 448
Signed-off-by: Janos Follath <janos.follath@arm.com>
2021-06-28 10:24:20 +01:00
Janos Follath
5f9b667396 Reject low-order points on Curve448 early
We were already rejecting them at the end, due to the fact that with the
usual (x, z) formulas they lead to the result (0, 0) so when we want to
normalize at the end, trying to compute the modular inverse of z will
give an error.

If we wanted to support those points, we'd a special case in
ecp_normalize_mxz(). But it's actually permitted by all sources (RFC
7748 say we MAY reject 0 as a result) and recommended by some to reject
those points (either to ensure contributory behaviour, or to protect
against timing attack when the underlying field arithmetic is not
constant-time).

Since our field arithmetic is indeed not constant-time, let's reject
those points before they get mixed with sensitive data (in
ecp_mul_mxz()), in order to avoid exploitable leaks caused by the
special cases they would trigger. (See the "May the Fourth" paper
https://eprint.iacr.org/2017/806.pdf)

Signed-off-by: Janos Follath <janos.follath@arm.com>
2021-06-28 10:24:20 +01:00
Janos Follath
15fc884f04 Add DoS test case for ecp_check_pub
A test case for which the loop would take practically forever if it was
reached. The point would be to validate that the loop is not reached.
The test case should cause the CI to time out if starting with the
current code, ecp_check_pubkey_mx() was changed to call
ecp_check_pubkey_x25519() first and run the mbedtls_mpi_size(() test
afterwards, which would make no semantic difference in terms of memory
contents when the function returns, but would open the way for a DoS.

Signed-off-by: Janos Follath <janos.follath@arm.com>
2021-06-28 10:24:20 +01:00
Janos Follath
b741e8d263 Use mbedtls_mpi_lset() more
Signed-off-by: Janos Follath <janos.follath@arm.com>
2021-06-28 10:24:20 +01:00
Janos Follath
7d34e2e655 Move mpi constant macros to bn_mul.h
Signed-off-by: Janos Follath <janos.follath@arm.com>
2021-06-28 10:23:57 +01:00
Janos Follath
bf1afdc2bb Remove redundant ecp_check_pub() tests
Signed-off-by: Janos Follath <janos.follath@arm.com>
2021-06-28 10:05:32 +01:00
Janos Follath
c16ec6be85 Prevent memory leak in ecp_check_pubkey_x25519()
Signed-off-by: Janos Follath <janos.follath@arm.com>
2021-06-28 10:05:31 +01:00
Manuel Pégourié-Gonnard
9f12b11be0 Avoid complaints about undeclared non-static symbols
Clang was complaining and check-names.sh too

This only duplicates macros, so no impact on code size. In 3.0 we can
probably avoid the duplication by using an internal header under
library/ but this won't work for 2.16.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2021-06-28 10:05:31 +01:00
Manuel Pégourié-Gonnard
89ce7d2445 Use more compact encoding of Montgomery curve constants
Base 256 beats base 16.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2021-06-28 10:05:31 +01:00
Manuel Pégourié-Gonnard
6ec1535148 Use a more compact encoding of bad points
Base 10 is horrible, base 256 is much better.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2021-06-28 10:05:31 +01:00
Manuel Pégourié-Gonnard
98967959df Add test for check_pubkey for x25519
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2021-06-28 10:05:31 +01:00
Manuel Pégourié-Gonnard
4d0b9da37d Reject low-order points on Curve25519 early
We were already rejecting them at the end, due to the fact that with the
usual (x, z) formulas they lead to the result (0, 0) so when we want to
normalize at the end, trying to compute the modular inverse of z will
give an error.

If we wanted to support those points, we'd a special case in
ecp_normalize_mxz(). But it's actually permitted by all sources
(RFC 7748 say we MAY reject 0 as a result) and recommended by some to
reject those points (either to ensure contributory behaviour, or to
protect against timing attack when the underlying field arithmetic is
not constant-time).

Since our field arithmetic is indeed not constant-time, let's reject
those points before they get mixed with sensitive data (in
ecp_mul_mxz()), in order to avoid exploitable leaks caused by the
special cases they would trigger. (See the "May the Fourth" paper
https://eprint.iacr.org/2017/806.pdf)

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2021-06-28 10:05:29 +01:00
Janos Follath
438ef16d45
Merge pull request #4654 from gilles-peskine-arm/mpi_montmul-null-2.16
Backport 2.16: Fix several bugs with the value 0 in bignum
2021-06-23 13:39:57 +01:00
Gilles Peskine
18efd1c2c3 Correct some statements about the ordering of A and B
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-06-22 18:48:37 +02:00
Gilles Peskine
f95d433655 Clarification in a comment
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-06-22 18:48:37 +02:00
Gilles Peskine
1d6b1dc955 Simplify is-zero check
The loop exits early iff there is a nonzero limb, so i==0 means that
all limbs are 0, whether the number of limbs is 0 or not.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-06-22 18:48:37 +02:00
Gilles Peskine
55e6abc99f Fix copypasta in test data
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-06-22 18:48:37 +02:00
Gilles Peskine
afbf191b17 Write a proof of correctness for mbedtls_mpi_gcd
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-06-22 18:48:37 +02:00
Gilles Peskine
2949d3ac1b Explain how the code relates to the description in HAC
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-06-22 18:48:37 +02:00
Gilles Peskine
ead6660d8c Fix copypasta in test cases
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-06-22 18:48:37 +02:00
Gilles Peskine
3cfb7be72f Annotate the choice of representation of 0 in more places
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-06-22 18:48:37 +02:00
Gilles Peskine
8c68c97db7 Improve coverage of mbedtls_mpi_cmp_mpi
Test with and without leading zeros on each side.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-06-22 18:48:37 +02:00
Gilles Peskine
5ce7cb3d3c Fix copypasta in test function argument name
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-06-22 18:48:37 +02:00
Gilles Peskine
14357a35f7 Unify G=1 and G=-1 test cases
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-06-22 18:48:37 +02:00
Gilles Peskine
05a1af6d0f In test cases where the result is 0, express it as "0", not ""
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-06-22 18:48:37 +02:00
Gilles Peskine
44e6bb6b38 Fix multiplication with negative result and a low-order 0 limb
Fix a bug introduced in "Fix multiplication producing a negative zero" that
caused the sign to be forced to +1 when A > 0, B < 0 and B's low-order limb
is 0.

Add a non-regression test. More generally, systematically test combinations
of leading zeros, trailing zeros and signs.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-06-22 18:48:37 +02:00
Gilles Peskine
266275e924 mpi_shrink test: just set the top bit
No need to bypass the API to fill limbs. It's a better test to just
set the top bit that we want to have set, and it's one less bypass of
the API.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-06-22 18:48:37 +02:00