4458 Commits

Author SHA1 Message Date
Manuel Pégourié-Gonnard
b0bb3c8b7d Bump version to 2.16.12
scripts/bump_version.sh --version 2.16.12

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2021-12-14 11:12:26 +01:00
Manuel Pégourié-Gonnard
fef64d5de9 Merge branch 'mbedtls-2.16-restricted' into mbedtls-2.16.12rc0-pr
* mbedtls-2.16-restricted:
  Add changelog entry for session copy bugfix
  [session] fix a session copy bug fix a possible double reference on 'ticket' when peer_cert/peer_cert_digest calloc failed.
2021-12-14 09:27:48 +01:00
Gilles Peskine
7b9cd91587 Merge pull request #5328 from gilles-peskine-arm/zeroize-tag-2.16
Backport 2.16: Zeroize expected MAC/tag intermediate variables
2021-12-13 19:09:34 +01:00
Gilles Peskine
b3f2273aed mbedtls_cipher_check_tag: jump on error for more robustness to refactoring
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-12-13 16:57:47 +01:00
Gilles Peskine
e72ab7767f Merge pull request #5311 from paul-elliott-arm/pkcs12_fix_2.16
Backport 2.16: Fixes for pkcs12 with NULL and/or zero length password
2021-12-13 14:52:47 +01:00
Gilles Peskine
7cab499af2 Initialize hash_len before using it
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-12-13 14:47:17 +01:00
Gilles Peskine
6f8d7f1b8c PKCS#1v1.5 signature: better cleanup of temporary values
Zeroize temporary buffers used to sanity-check the signature.

If there is an error, overwrite the tentative signature in the output
buffer.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-12-13 14:28:26 +01:00
Gilles Peskine
cd9e751f2f mbedtls_ssl_parse_finished: zeroize expected finished value on error
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-12-13 14:28:26 +01:00
Gilles Peskine
75b596fc3c mbedtls_ssl_cookie_check: zeroize expected cookie on cookie mismatch
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-12-13 14:18:44 +01:00
Gilles Peskine
8dc7b243ae mbedtls_cipher_check_tag: zeroize expected tag on tag mismatch
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-12-13 14:15:39 +01:00
Gilles Peskine
a89bdf03ba Catch failures of md_hmac operations
Check the return values of mbedtls_md_xx functions in our code. We were
already doing that everywhere for hash calculations, but not for HMAC
calculations.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-12-11 17:37:47 +01:00
Gilles Peskine
957e383f87 Zeroize local MAC variables
Zeroize local MAC variables used for CBC+HMAC cipher suites. In encryption,
this is just good hygiene but probably not needed for security since the
data protected by the MAC that could leak is about to be transmitted anyway.
In DTLS decryption, this could be a security issue since an adversary could
learn the MAC of data that they were trying to inject. At least with
encrypt-then-MAC, the adversary could then easily inject a datagram with
a corrected packet. TLS would still be safe since the receiver would close
the connection after the bad MAC.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-12-11 17:37:47 +01:00
Paul Elliott
987bb386be Remove incorrect hashing
Incorrect interpretation of 'empty'

Signed-off-by: Paul Elliott <paul.elliott@arm.com>
2021-12-10 18:08:31 +00:00
Paul Elliott
b4bfcbbd67 Add explanation for safety in function
Signed-off-by: Paul Elliott <paul.elliott@arm.com>
2021-12-10 18:08:31 +00:00
Paul Elliott
6b5707c90a Better fix for empty password / salt
Signed-off-by: Paul Elliott <paul.elliott@arm.com>
2021-12-10 17:51:11 +00:00
Paul Elliott
4d44341369 Fix for pkcs12 with NULL or zero length password
Previously passing a NULL or zero length password into either
mbedtls_pkcs12_pbe() or mbedtls_pkcs12_derive() could cause an infinate
loop, and it was also possible to pass a NULL password, with a non-zero
length, which would cause memory corruption.
I have fixed these errors, and improved the documentation to reflect the
changes and further explain what is expected of the inputs.

Signed-off-by: Paul Elliott <paul.elliott@arm.com>
2021-12-10 17:49:21 +00:00
吴敬辉
eb490aabf6 [session] fix a session copy bug
fix a possible double reference on 'ticket'
when peer_cert/peer_cert_digest calloc failed.

Signed-off-by: 吴敬辉 <11137405@vivo.com>
2021-12-08 12:33:12 +00:00
Tom Cosgrove
7b420a896f Fix builds when config.h only defines MBEDTLS_BIGNUM_C
Fixes #4929

Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2021-12-06 20:42:50 +01:00
Gilles Peskine
1d2c74cee0 Merge pull request #5135 from openluopworld/origin/mbedtls-2.16
Backport 2.16: Fix GCM calculation with very long IV
2021-11-22 22:22:42 +01:00
Tom Cosgrove
0a817205cf Serialise builds of the .a files on Windows
This is a workaround for an issue with mkstemp() in older MinGW releases that
causes simultaneous creation of .a files in the same directory to fail.

Fixes #5146

Signed-off-by: Tom Cosgrove <tom.cosgrove@arm.com>
2021-11-10 12:29:30 +00:00
openluopworld
ed798a9092 An initialization vector IV can have any number of bits between 1 and
2^64. So it should be filled to the lower 64-bit in the last step
when computing ghash.

Signed-off-by: openluopworld <wuhanluop@163.com>
2021-11-05 19:40:40 +08:00
Manuel Pégourié-Gonnard
70227d217d Merge pull request #4819 from gilles-peskine-arm/base64-no-table-2.16
Backport 2.16: range-based constant-flow base64
2021-10-27 12:18:42 +02:00
Gilles Peskine
cda1281ee2 Fix copypasta in comment
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-10-25 21:13:27 +02:00
Gilles Peskine
90b10c379f Merge pull request #4847 from mstarzyk-mobica/ecb-alt-ret-2.16
Backport 2.16: Catch failures of mbedtls_aes_crypt_ecb and its DES equivalents
2021-10-14 12:10:58 +02:00
Kenneth Soerensen
806ac52be3 Backport 2.16: Remove compiler warning if only MBEDTLS_PK_PARSE_C is defined
Warning reported with IAR compiler:
"mbedtls\library\pkparse.c",1167  Warning[Pe550]: variable "ret" was set but never used

Signed-off-by: Kenneth Soerensen <knnthsrnsn@gmail.com>
2021-09-01 11:27:17 +02:00
Janos Follath
f1b0c70faf Merge pull request #4044 from darrenkrahn/mbedtls-2.16
[Backport 2.16] Mark basic constraints critical as appropriate.
2021-08-26 16:23:58 +01:00
Gilles Peskine
621333f41b Catch failures of AES or DES operations
A DES or AES block operation can fail in alternative implementations of
mbedtls_internal_aes_encrypt() (under MBEDTLS_AES_ENCRYPT_ALT),
mbedtls_internal_aes_decrypt() (under MBEDTLS_AES_DECRYPT_ALT),
mbedtls_des_crypt_ecb() (under MBEDTLS_DES_CRYPT_ECB_ALT),
mbedtls_des3_crypt_ecb() (under MBEDTLS_DES3_CRYPT_ECB_ALT).
A failure can happen if the accelerator peripheral is in a bad state.
Several block modes were not catching the error.

This commit does the following code changes:

* Fix DES and AES API calls which ignored the return values:
    * In library code: on failure, goto exit and return ret.
    * In pkey programs: goto exit.
    * In the benchmark program: exit (not ideal since there's no error
      message, but it's what the code currently does for failures).
    * In test code: TEST_ASSERT.
* Changelog entry.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Mateusz Starzyk <mateusz.starzyk@mobica.com>
2021-08-05 15:31:48 +02:00
Gilles Peskine
bbf97cd1d0 mask_of_range: simplify high comparison
To test c <= high, instead of testing the sign of (high + 1) - c, negate the
sign of high - c (as we're doing for c - low). This is a little easier to
read and shaves 2 instructions off the arm thumb build with
arm-none-eabi-gcc 7.3.1.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-07-30 12:57:22 +02:00
Gilles Peskine
231b67a6b2 Base64 decode: simplify local variables (n)
n was used for two different purposes. Give it a different name the second
time. This does not seem to change the generated code when compiling with
optimization for size or performance.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-07-30 12:56:21 +02:00
Gilles Peskine
b44517ebb3 Base64 encoding: use ranges instead of tables
Instead of doing constant-flow table lookup, which requires 64 memory loads
for each lookup into a 64-entry table, do a range-based calculation, which
requires more CPU instructions per range but there are only 5 ranges.

I expect a significant performance gain (although smaller than for decoding
since the encoding table is half the size), but I haven't measured. Code
size is slightly smaller.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-07-28 14:34:26 +02:00
Gilles Peskine
ea96b3aed9 Base64 decode: simplify local variables
Document what each local variable does when it isn't obvious from the name.
Don't reuse a variable for different purposes.

This commit has very little impact on the generated code (same code size on
a sample Thumb build), although it does fix a theoretical bug that 2^32
spaces inside a line would be ignored instead of treated as an error.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-07-28 14:34:26 +02:00
Gilles Peskine
f4a0a271d6 Base64 decoding: use ranges instead of tables
Instead of doing constant-flow table lookup, which requires 128 memory loads
for each lookup into a 128-entry table, do a range-based calculation, which
requires more CPU instructions per range but there are only 5 ranges.

Experimentally, this is ~12x faster on my PC (based on
programs/x509/load_roots). The code is slightly smaller, too.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-07-28 14:33:58 +02:00
Gilles Peskine
a47fdcf119 Base64 decoding: don't use the table for '='
Base64 decoding uses equality comparison tests for characters that don't
leak information about the content of the data other than its length, such
as whitespace. Do this with '=' as well, since it only reveals information
about the length. This way the table lookup can focus on character validity
and decoding value.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2021-07-28 11:33:04 +02:00
Ronald Cron
ae466e78f4 Merge pull request #4787 from gilles-peskine-arm/fix-clang12-Wstring-concatenation-2.16
Backport 2.16: Prevent triggering Clang 12 -Wstring-concatenation warning
2021-07-23 14:07:58 +02:00
Guido Vranken
70bdf8d1df Use single-line string literals.
Signed-off-by: Guido Vranken <guidovranken@gmail.com>
2021-07-18 16:16:44 +02:00
Guido Vranken
4a78d58f25 Prevent triggering Clang 12 -Wstring-concatenation warning
Wrap multi-line string literals in parentheses
to prevent a Clang 12 -Wstring-concatenation warning
(activated by -Wall), which caused the build to fail.

Fixes https://github.com/ARMmbed/mbedtls/issues/3586

Signed-off-by: Guido Vranken <guidovranken@gmail.com>
2021-07-18 16:16:43 +02:00
Yuto Takano
1cded872a8 Replace _RR with prec_RR to prevent reserved identifier clashes
Signed-off-by: Yuto Takano <yuto.takano@arm.com>
2021-07-14 15:04:11 +01:00
Yuto Takano
d7cd60fba0 Replace _B with B to prevent reserved identifier clashes
Signed-off-by: Yuto Takano <yuto.takano@arm.com>
2021-07-14 15:03:09 +01: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
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
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
459a46102d Fix TLS alert codes
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
2021-06-29 09:44:35 +01: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
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
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
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
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