13491 Commits

Author SHA1 Message Date
Gilles Peskine
cb72cd2ec3 Don't reset badmac_seen on a DTLS client reconnect
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-02-17 16:36:36 +01:00
Gilles Peskine
b710599e4a Merge in_hsfraglen with badmac_seen_or_in_hsfraglen
In the `mbedtls_ssl_context` structure, merge the field `in_hsfraglen` into
`badmac_seen_or_in_hsfraglen`. This restores the ABI of `libmbedtls` as it
was in Mbed TLS 3.6.0 through 3.6.2.

The field `badmac_seen_or_in_hsfraglen` (formerly `badmac_seen`) was only
used for DTLS (despite being present in non-DTLS builds), and the field
`in_hsfraglen` was only used in non-DTLS TLS. Therefore the two values can
be stored in the same field.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-02-17 16:28:51 +01:00
Gilles Peskine
ebdd405f68 Change the type of in_hsfraglen to unsigned
In the `mbedtls_ssl_context` structure, change the type of `in_hsfraglen`
from `size_t` to `unsigned`. This is in preparation for merging
`in_hsfraglen` into `badmac_seen_or_in_hsfraglen`, which has the type
`unsigned` and cannot change since we do not want to change the ABI.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-02-17 16:26:27 +01:00
Gilles Peskine
f6a676d93f Rename badmac_seen to badmac_seen_or_in_hsfraglen
Prepare to unify two fields of the `mbedtls_ssl_context` structure:
`badmac_seen` (always present but only used in DTLS) and
`in_hsfraglen` (always present but only used in non-DTLS TLS).

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-02-17 16:10:14 +01:00
Gilles Peskine
69f8f45e6f Minor readability improvement
No behavior change.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-02-17 16:08:59 +01:00
Deomid rojer Ryabkov
bbe8745d19 Remove in_hshdr
The first fragment of a fragmented handshake message always starts at the beginning of the buffer so there's no need to store it.

Signed-off-by: Deomid rojer Ryabkov <rojer@rojer.me>
2025-02-17 15:59:55 +01:00
Deomid rojer Ryabkov
85ec2b3632 Add a safety check for in_hsfraglen
Signed-off-by: Deomid rojer Ryabkov <rojer@rojer.me>
2025-02-17 15:59:04 +01:00
Deomid rojer Ryabkov
5c853ea2c5 Allow fragments less HS msg header size (4 bytes)
Except the first

Signed-off-by: Deomid rojer Ryabkov <rojer@rojer.me>
2025-02-17 15:59:04 +01:00
Deomid rojer Ryabkov
96e2290e3d Remove mbedtls_ssl_reset_in_out_pointers
Signed-off-by: Deomid rojer Ryabkov <rojer@rojer.me>
2025-02-17 15:59:04 +01:00
Deomid rojer Ryabkov
1f4088ceda Review comments
Signed-off-by: Deomid rojer Ryabkov <rojer@rojer.me>
2025-02-17 15:59:04 +01:00
Deomid rojer Ryabkov
3fc5a4dc86 Defragment incoming TLS handshake messages
Signed-off-by: Deomid rojer Ryabkov <rojer@rojer.me>
2025-02-17 15:59:04 +01:00
minosgalanakis
484776547c Update tf-psa-crypto/drivers/builtin/src/ecp.c
Co-authored-by: Gilles Peskine <gilles.peskine@arm.com>
Signed-off-by: minosgalanakis <30719586+minosgalanakis@users.noreply.github.com>
2025-01-23 15:31:35 +00:00
Gilles Peskine
abf9f1aaa5 PSA interruptible sign/verify: detect invalid curve family in start
Detect attempts to do ECDSA with a Montgomery curve in psa_sign_hash_start()
and psa_verify_hash_start(), whereas before start() would succeed and
complete() would fail. This avoids an inconsistency between psa_sign_hash()
and psa_sign_hash_start() that would be annoying to handle in
test_suite_psa_crypto_op_fail.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2025-01-09 18:42:14 +01:00
Gilles Peskine
905899839d
Merge pull request #9796 from gilles-peskine-arm/psa-storage-test-cases-never-supported-positive-3.6
Backport 3.6: Switch generate_psa_test.py to automatic dependencies for positive test cases
2025-01-09 13:53:11 +00:00
Janos Follath
8e8dabde3a
Merge pull request #9830 from gilles-peskine-arm/9798-backport-3.6
Backport 3.6: Added debug print in tls13 ssl_tls13_write_key_share_ext
2025-01-07 16:17:27 +00:00
Gilles Peskine
bc3f917fb3 crypto_config.h: Don't list mechanisms that are not implemented
Don't list mechanisms that are not implemented in
`include/psa/crypto_config.h`, even commented out. Uncommenting them
wouldn't help anyway: they don't work. Having them listed, even commented
out, causes `find_dependencies_not_implemented()` in `psa_test_case.py` to
consider those mechanisms to be implemented, and thus causes
`generate_psa_tests.py` to generate test cases that cannot be executed.

The affected mechanisms are:

* `PSA_ALG_CBC_MAC` (`PSA_WANT_ALG_CBC_MAC`)
* `PSA_ALG_XTS` (`PSA_WANT_ALG_XTS`)
* `PSA_ECC_FAMILY_SECP_K1` 224-bit (`PSA_WANT_ECC_SECP_K1_224`)

Also remove the affected mechanisms from configuration adjustment files,
since that is code that can never be triggered.

There were already no generated test cases for SECP224K1 because
`PSA_WANT_ECC_SECP_K1_224` was already detected as a dependency that cannot
be implemented, because that is not a valid size: PSA defines SECP224K1 as
225-bit, and `crypto_knowledge.py` follows suite, so `generate_psa_tests.py`
saw `PSA_WANT_ECC_SECP_K1_225` in its enumeration but skipped it because it
was never mentioned in `crypto_config.h`.

This causes generated PSA tests to no longer include positive test cases for
`PSA_ALG_CBC_MAC` and `PSA_ALG_XTS`.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-12-24 20:03:29 +01:00
Solar Designer
e65428ed3d Specify previously missed XMM register clobbers in AES-NI asm blocks
Noticed by Gilles Peskine

Co-authored-by: Gilles Peskine <gilles.peskine@arm.com>
Signed-off-by: Solar Designer <solar@openwall.com>
2024-12-13 02:10:01 +01:00
Solar Designer
98910a1437 Specify register clobbers in mbedtls_aesni_crypt_ecb()
Signed-off-by: Solar Designer <solar@openwall.com>
2024-12-13 02:09:51 +01:00
Janos Follath
a770f30ee9
Merge pull request #9782 from gilles-peskine-arm/psa-storage-test-cases-never-supported-preliminaries-3.6
Backport 3.6: Make some edge cases of not-supported or invalid mechanisms more uniform
2024-12-10 18:16:05 +00:00
Nadav Tasher
aebe857339 Added debug print in tls13 ssl_tls13_write_key_share_ext
Signed-off-by: Nadav Tasher <tashernadav@gmail.com>
2024-12-09 20:16:48 +01:00
SuperIlu
7e6d4c13a8 Make mbedTLS compile with MS-DOS DJGPP
Signed-off-by: SuperIlu <superilu@yahoo.com>
2024-12-01 10:31:50 +01:00
Gilles Peskine
8a8aa59f52 PSA interruptible sign/verify: detect unsupported mechanism in start
In particular, if interruptible ECDSA is supported but not the deterministic
variant, detect this in psa_sign_hash_start(), whereas before start() would
succeed and psa_sign_hash_complete() would fail. This avoids an
inconsistency between psa_sign_hash() and psa_sign_hash_start() that would
be annoying to handle in test_suite_psa_crypto_op_fail.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-11-21 09:48:35 +01:00
Gilles Peskine
808b541316 PSA sign/verify: more uniform error on an unsupported hash
Uniformly return PSA_ERROR_NOT_SUPPORTED if given an algorithm that includes
a hash, but that hash algorithm is not supported. This will make it easier
to have a uniform treatment of unsupported hashes in automatically generated
tests.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-11-19 17:36:07 +01:00
David Horstmann
dcf42a0b53 Update references to test helpers
Replace:
* tests/src -> framework/tests/src
* tests/include -> framework/tests/include

Except for occurrences of:
* tests/src/test_helpers (since this only contains ssl_helpers.c)
* tests/src/test_certs.h
* tests/include/alt_dummy

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2024-11-14 14:19:40 +00:00
Paul Elliott
346d2f4e58
Merge pull request #9731 from gilles-peskine-arm/coverity-20241004-3.6
Backport 3.6: Fix edge cases of mbedtls_psa_raw_to_der and mbedtls_psa_der_to_raw
2024-11-06 19:02:54 +00:00
Gilles Peskine
c8b668deae mbedtls_psa_ecp_generate_key: don't calculate the public key
mbedtls_ecp_gen_key() generates a private key and calculates the public key.
Calculating the public key takes most of the CPU time. But the PSA key store
doesn't store the key, in order to simplify the plumbing when drivers are
involved. So the time spent calculating the public key is a waste.

Instead, call mbedtls_ecp_gen_privkey(), which does not calculate the public
key.

This also saves 8 instructions in a sample arm thumb build.

Resolves #9732.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-10-30 12:18:16 +01:00
Gilles Peskine
5dea5f355a mbedtls_ecdsa_raw_to_der and mbedtls_ecdsa_der_to_raw: reject bits==0
Cleanly reject bits == 0 when calling mbedtls_ecdsa_raw_to_der() and
mbedtls_ecdsa_der_to_raw(). This can plausibly happen when bits is
user-provided data that the calling application doesn't check.

Before this patch, there was typically-benign undefined behavior, such as
adding 0 to a null pointer or calling memcpy on a null pointer with a size
of 0.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-10-28 10:09:18 +01:00
Gilles Peskine
91972cc13d
Merge pull request #9608 from gilles-peskine-arm/outcome-check-repeated-configurations-all.sh-preliminaries-3.6
Backport 3.6: Fix some all.sh components with sub-components
2024-10-25 11:47:48 +00:00
Gilles Peskine
0b8b7a1ee1
Merge pull request #9448 from valeriosetti/psa-use-static-slots-backport
[Backport 3.6] PSA: use static key slots to store keys
2024-10-24 07:27:43 +00:00
David Horstmann
0f170ad60b
Merge pull request #9714 from ThePassionate/mbedtls-1022-3.6.0
[Backport 3.6] net/mbedtls_net_connect: Preventing double close problem
2024-10-22 16:49:18 +00:00
makejian
66b39d4cf1 net/mbedtls_net_connect: Preventing double close problem
In the test examples and real usage scenarios, 'mbedtls_net_free' is called after 'mbedtls_net_connect' fails, which will cause the problem of double close the same fd. It is possible to close this closed fd which has been applied by other link.

Signed-off-by: makejian <makejian@xiaomi.com>
2024-10-22 20:02:51 +08:00
Valerio Setti
fe0f09e35f Documentation: fix some nits
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-10-22 13:31:19 +02:00
Valerio Setti
ce84921298 psa: move default definition of MBEDTLS_PSA_STATIC_KEY_SLOT_BUFFER_SIZE
Move the default definition of MBEDTLS_PSA_STATIC_KEY_SLOT_BUFFER_SIZE
from psa_crypto_core.h to the public header crypto_extra.h in order
to solve documentation build issues.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-10-22 13:31:19 +02:00
Valerio Setti
dbfb2ab4ea psa: zeroize static key buffer content when key slot is freed
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-10-22 13:31:19 +02:00
Valerio Setti
f51488b95d psa: fix some macro definition
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-10-22 13:31:19 +02:00
Valerio Setti
70fa89c1f9 psa-core: remove unnecessary element in psa_key_slot_t
Instead of checking for "in_use" to be true/false or "key.data"
to be not NULL, simply check that "key.bytes" is 0/not-0.
psa_allocate_buffer_to_slot() will update this value whenever
a new slot is allocated (for the fully static case "allocated"
actually mean "taken").

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-10-22 13:31:19 +02:00
Valerio Setti
faed169e57 psa_crypto_core: take also cipher's key length into account when sizing static key buffer
Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-10-22 13:31:19 +02:00
Valerio Setti
1980bb781e psa-core: properly set PSA_CRYPTO_MAX_STORAGE_SIZE
If MBEDTLS_PSA_STATIC_KEY_SLOTS is set then limit PSA_CRYPTO_MAX_STORAGE_SIZE
to MBEDTLS_PSA_STATIC_KEY_SLOT_BUFFER_SIZE, otherwise keep the previous
PSA_BITS_TO_BYTES(PSA_MAX_KEY_BITS) size.

This commit also removes changes to test_suite_psa_crypto_persistent_key.data
done previously since MBEDTLS_PSA_STATIC_KEY_SLOTS is always up to date
with key buffer size.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-10-22 13:31:19 +02:00
Valerio Setti
8d4f15013f psa: allow to use static key buffers instead of dynamic ones
This helps reducing heap memory usage and, if heap memory is
not used anywhere else in an embedded device, it also reduces
code footprint since there is no need for heap management code
in this case.

A new build symbol is added for this purpose, named
MBEDTLS_PSA_STATIC_KEY_SLOTS. It's disabled by default so that
normal usage of Mbed TLS library is not affected.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-10-22 13:31:19 +02:00
David Horstmann
e905442f7e
Merge pull request #9675 from eleuzi01/backport-9673
[Backport 3.6] Move TLS auxiliary test scripts to the framework
2024-10-17 17:18:57 +00:00
Elena Uziunaite
5adc9c304b Add "common.h"
Needed after b81cd1af6418823a2b5ffbd3710ceac9b0e0afa4 (#9671)
since generate_ssl_debug_helpers.py was moved to the framework

Signed-off-by: Elena Uziunaite <elena.uziunaite@arm.com>
2024-10-15 16:58:16 +01:00
David Horstmann
78542bf85d
Merge pull request #9698 from gilles-peskine-arm/3.6.2-rc2-mergeback-3
Merge 3.6.2 into 3.6 (updated cmake gcc+Asan build flags)
2024-10-15 14:00:21 +00:00
Elena Uziunaite
7f5ec13a12 Adjust file path for generate_ssl_debug_helpers.py
Signed-off-by: Elena Uziunaite <elena.uziunaite@arm.com>
2024-10-15 12:41:42 +01:00
David Horstmann
bfb9f71fa3 Revert "Add generated files"
This reverts commit 0d1117692ee261d6d89e2819a742c64e06e5bd42.

Signed-off-by: David Horstmann <david.horstmann@arm.com>
2024-10-15 12:06:18 +02:00
Gilles Peskine
a712d8dda5 Bump version to 3.6.2
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-10-14 11:04:31 +02:00
Valerio Setti
5f1c8a720f pkwrite: fix buffer overrun
This commit fixes potential buffer overrun in:
- pk_write_rsa_der
- pk_write_ec_pubkey

In both functions, when dealing with opaque keys, there was no
check that the provided buffer was large enough to contain the
key being exported. This commit fixes this problem and it also
adds some testing in test_suite_pkwrite to trigger these checks.

Signed-off-by: Valerio Setti <valerio.setti@nordicsemi.no>
2024-10-14 10:37:00 +02:00
Manuel Pégourié-Gonnard
8536c3c792
Merge pull request #9161 from mpg/doc-guards
[3.6 only] Document transitional feature macros / guards
2024-10-09 10:30:50 +00:00
Gilles Peskine
698a90da40 Ignore and clean generated assembly
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-09-20 17:34:46 +02:00
Gilles Peskine
925e9ad5a7 Add target to compile to assembly
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-09-20 17:34:46 +02:00
Gilles Peskine
5a668dd5af Reduce level of non-error debug message
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2024-09-20 07:44:36 +02:00