32728 Commits

Author SHA1 Message Date
Manuel Pégourié-Gonnard
f34f6138ca TLS: pass actual size to ecdh_calc_secret()
This is probably a leftover from ancient times where the premaster
buffer was always that size (for FFDH). But these days it can be smaller
depending on the compile-time config. So, use the correct size macro.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-31 12:39:10 +02:00
Manuel Pégourié-Gonnard
070ba17a8a ECDH: Add ChangeLog for legacy buffer overflow
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-31 12:38:54 +02:00
Manuel Pégourié-Gonnard
1d71bcc31c ECDH: fix possible buffer overflow
We were not comparing the size of the output buffer with the actual
number of bytes we were going to write to it, but with something
possibly smaller.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-31 12:01:11 +02:00
Manuel Pégourié-Gonnard
058f57a4dd ECDH: test MSB 0 in shared secret (legacy API)
The values were generated using the script in the message of the
previous commit.

Currently all 4 new tests are failing: without sanitizers, the function
returns 0 instead of an error; with sanitizers, the buffer overwrite is
caught.

This will be fixed in the next commit.

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-31 12:01:11 +02:00
Manuel Pégourié-Gonnard
216ec7d6fc ECDH: add test cases with MSB 0 in shared secret
The goal is to catch possible bugs where we would compute the output
length based on the bitlength of the shared secret MPI. So, what matters
is the most significant byte, even for Montgomery curves where the
all values are written out little endian.

The values were generated by the following sage script. The script could
be a bit more compact by using E.random_point() instead of the
conventional base point G as the peer's key, but I prefered making the
script deterministic so its output can easily be checked.

p256 = {
    "name": "p256",
    "p": 2^224 * (2^32 - 1) + 2^192 + 2^96 - 1,
    "a": -3,
    "b": 0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b,
    "gx": 0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296,
    "gy": 0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5,
}

p521 = {
    "name": "p521",
    "p": 2^521 - 1,
    "a": -3,
    "b": 0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00,
    "gx": 0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66,
    "gy": 0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650,
}

x255 = {
    "name": "x25519",
    "p": 2^255 - 19,
    "a": 486662,
    "gx": 9,
    "gy": 14781619447589544791020593568409986887264606134616475288964881837755586237401,
}

x448 = {
    "name": "x448",
    "p": 2^448 - 2^224 - 1,
    "a": 156326,
    "gx": 5,
    "gy": 355293926785568175264127502063783334808976399387714271831880898435169088786967410002932673765864550910142774147268105838985595290606362,
}

def byte_len(i):
    return (i.bit_length() + 7) // 8

def leading0(name, p, gx, gy, a, b=None):
    is_montgomery = b is None
    if is_montgomery:
        E = EllipticCurve(GF(p), [0, a, 0, 1, 0])
        increment = 8 # x22519 scalars have the low 3 bits unset
    else:
        E = EllipticCurve(GF(p), [a, b])
        increment = 1

    G = E(gx, gy)
    s = 2^(p.bit_length() - 1) # x25519 scalars have bit 254 set

    Z = G * s
    while byte_len(Z.x().lift()) >= byte_len(p):
        s += increment
        Z += increment * G

    print(name)
    if is_montgomery:
        nbytes = byte_len(p)
        print(f"s: {s.to_bytes(nbytes, "little").hex()}")
        print(f"G: {G.x().lift().to_bytes(nbytes, "little").hex()}")
        print(f"Z: {Z.x().lift().to_bytes(nbytes, "little").hex()}")
    else:
        nibbles = byte_len(p) * 2
        print(f"s: {s:0{nibbles}x}")
        print(f"G: 04{G.x().lift():0{nibbles}x}{G.y().lift():0{nibbles}x}")
        print(f"Z: {Z.x().lift():0{nibbles}x}")

leading0(**p256)
leading0(**p521)
leading0(**x255)
leading0(**x448)

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-31 12:01:11 +02:00
Manuel Pégourié-Gonnard
0d318a0f3a ECDH: test calc_secret output buffer too small
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-31 12:01:11 +02:00
Manuel Pégourié-Gonnard
df13f5cd52 ECDH: document sufficient size for shared secret
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-31 12:00:59 +02:00
Gilles Peskine
77b1a22bc3
Merge pull request #1536 from ronald-cron-arm/3.6-context_load_and_session_load_documentation
3.6 backport: Tighten context/session load and save APIs documentation
2026-03-26 21:32:09 +01:00
minosgalanakis
39acf7d2c8
Merge pull request #1535 from Mbed-TLS/release/changelog_fixes_3.6.6
[Release] Added attributions & CVE to ChangeLogs (3.6 LTS)
2026-03-26 17:38:26 +00:00
Ronald Cron
86b6812003 Update change log.
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-26 18:25:06 +01:00
Minos Galanakis
860cde63e6 MOufa
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2026-03-26 16:43:03 +00:00
Minos Galanakis
e4c6f6819e Added attribution for ffdh-peerkey-check
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2026-03-26 16:42:23 +00:00
Minos Galanakis
441beaeeac Extended attributions & CVE
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2026-03-26 14:51:36 +00:00
Ronald Cron
f45d735826 Improve change log
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-26 13:18:10 +01:00
Ronald Cron
e7076b1639 Add change log
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-26 13:18:10 +01:00
Ronald Cron
e7c9b1dfb3 Reduce duplication between save/load documentations
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-26 13:18:10 +01:00
Ronald Cron
dd20b0644a Add warning in mbedtls_ssl_session_load/save documentation
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-26 13:18:10 +01:00
Ronald Cron
6712bd07b3 Add warning in mbedtls_ssl_context_save/load documentation
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-26 13:18:10 +01:00
Minos Galanakis
0205ff782b Added attributions & CVE
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2026-03-26 11:11:12 +00:00
Manuel Pégourié-Gonnard
3746d7bbe0
Merge pull request #1531 from minosgalanakis/bugfix/ccm_finish_boundary_check_3.6_accr
Added attribution to fix-ccm-finish changelog entry (mbedtls3.6)
2026-03-26 09:36:56 +01:00
minosgalanakis
e944c99027
Merge pull request #1519 from ronald-cron-arm/dtls-3.6
3.6: Fixes relative to DTLS invalid/unexpected first record
2026-03-25 22:31:18 +00:00
minosgalanakis
6522a260b2
Merge pull request #1530 from mpg/ffdh-changelog-fix
Remove attribution that wasn't agreed on
2026-03-25 19:38:16 +00:00
Minos Galanakis
17c19f9782 Added attribution to fix-ccm-finish changelog entry
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2026-03-25 16:14:18 +00:00
Ronald Cron
0c718e863a dtls: Log mapping of UNEXPECTED_RECORD to UNEXPECTED_MESSAGE
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-25 15:05:53 +01:00
Ronald Cron
eb1cdf45cd dtls: Fix adaptation to first ClientHello
For each received ClientHello fragment, check
that its epoch is zero and update the
record-level sequence number.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-25 14:28:17 +01:00
Ronald Cron
953c584eec Remove debug leftover
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-25 14:28:17 +01:00
Ronald Cron
3a3d1d3dcd Improve comments
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-25 14:28:17 +01:00
Ronald Cron
9be94ba6ae Restrict mapping of UNEXPECTED_RECORD to UNEXPECTED_MESSAGE
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-25 14:28:17 +01:00
Ronald Cron
42dec1f97c ssl-opt.sh: Fix log checks in some "DTLS reassembly" tests
In DTLS reassembly tests, the server may receive a close_notify alert at the
end of a test. In this case, the Mbed TLS server logs an error, so these tests
should not check for the absence of the string "error" in the server logs.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-25 14:28:17 +01:00
Ronald Cron
ed156d0699 Disable "DTLS proxy: 3d, (openssl|gnutls) client, fragmentation" tests
The tests fail intermittently on the CI with a frequency that
significantly impacts CI throughput.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-25 14:28:17 +01:00
Ronald Cron
db25da0f32 dtls: Fix log level
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-25 14:28:17 +01:00
Ronald Cron
243a28c7fd dtls: parse_client_hello: Adapt mbedtls_ssl_read_record() error code
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-25 14:28:17 +01:00
Ronald Cron
4decf92956 dtls: Keep invalid/unexpected record header error code
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-25 14:28:17 +01:00
Ronald Cron
82be755414 dtls: Improve comment
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-25 14:28:17 +01:00
Ronald Cron
7a50711061 Update buffering when adapting to ClientHello message_seq
Credit to OSS-Fuzz for detecting the problem.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-25 14:26:16 +01:00
Manuel Pégourié-Gonnard
38fe3d463e Remove attribution that wasn't agreed on
Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
2026-03-25 13:36:01 +01:00
Ronald Cron
7fabb42524 Introduce ssl_buffering_shift_slots
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-23 19:18:26 +01:00
Ronald Cron
072ddb0346 dtls: Error out on invalid/unexpected record header
Error out on invalid/unexpected record header
when reading the DTLS 1.2 ClientHello.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-23 19:18:26 +01:00
Ronald Cron
f8dd49e047 dtls: Fix debug log
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-23 19:18:26 +01:00
Ronald Cron
36d75df56b Revert "ssl_server2.c: DTLS: Attempt to read the response to the close notification"
This reverts commit 0a8c35d273257d7102ef8af1e351fa9c7bb688d9.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
2026-03-23 19:18:26 +01:00
Gilles Peskine
b7a34b9224
Merge pull request #1522 from ronald-cron-arm/mbedtls-3.6-release-sync-merge
Merge of 'mbedtls-restricted/mbedtls-3.6-release-sync' into 'mbedtls-restricted/mbedtls-3.6-restricted'
2026-03-23 14:29:17 +01:00
Ronald Cron
707c8c34ec Merge remote-tracking branch 'mbedtls-restricted/mbedtls-3.6-release-sync' into 'mbedtls-restricted/mbedtls-3.6-restricted' 2026-03-23 12:08:25 +01:00
Bence Szépkúti
8530b5e708
Merge pull request #1504 from gilles-peskine-arm/psa-rng-fork-3.6
Backport 3.6: PSA RNG fork protection
2026-03-19 17:26:52 +01:00
Gilles Peskine
f6118b40e1
Merge pull request #1492 from minosgalanakis/bugfix/ccm_finish_boundary_check_3.6
Bugfix/ccm finish boundary check 3.6
2026-03-17 21:57:28 +01:00
Ronald Cron
303504fba9
Merge pull request #10645 from minosgalanakis/mbedtls-3.6-release-sync
MbedTLS 3.6.6 release sync
2026-03-17 20:46:43 +00:00
Gilles Peskine
9dfe49a980 Update framework with mbedtls_test_fork_run_child merged
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2026-03-17 21:29:58 +01:00
Minos Galanakis
b19eec6495 Updated framework pointer
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2026-03-17 16:55:40 +00:00
Ronald Cron
c1cd21d854
Merge pull request #1510 from yanesca/1445_fix_signature_algorithm_injection-backport
Fix signature algorithm injection [3.6 Backport]
2026-03-17 17:09:51 +01:00
Bence Szépkúti
444d0ac2c1
Merge pull request #10443 from davidhorstmann-arm/verify-result-default-failure-3.6
[Backport 3.6] Hardening: Make `mbedtls_ssl_get_verify_result()` default to failure
2026-03-17 12:14:48 +00:00
Minos Galanakis
73c6d6d3e9 test_suite_ccm: Added error.h
Signed-off-by: Minos Galanakis <minos.galanakis@arm.com>
2026-03-17 11:42:42 +00:00