ssl: size the ECDH premaster secret by PSA alone

_pms_ecdh and _pms_ecdhe_psk are sized by
PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE, with no MBEDTLS_ECP_MAX_BYTES
fallback and no new public macro. The ChangeLog entry describes the
user-visible failure.

Signed-off-by: Paulo Santos <paulo.santos-ext@hexagon.com>
This commit is contained in:
Paulo Santos 2026-10-27 15:41:52 -03:00
parent cf6d40a92d
commit 34a8ce1e85
No known key found for this signature in database
2 changed files with 6 additions and 21 deletions

View File

@ -1,8 +1,7 @@
Bugfix
* Fix TLS 1.2 ECDHE handshakes failing in PSA-client-only
builds (MBEDTLS_PSA_CRYPTO_C disabled) where
MBEDTLS_ECP_MAX_BYTES collapses to 1 and the
premaster-secret union sized below
PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE caused
psa_raw_key_agreement() to return PSA_ERROR_BUFFER_TOO_SMALL.
(MBEDTLS_PSA_CRYPTO_C disabled) builds when PSK
and ECJPAKE key-exchanges were disabled.
In this scenario ECDHE key agreement failed returning
PSA_ERROR_BUFFER_TOO_SMALL.
Fixes #10757.

View File

@ -648,32 +648,18 @@
#endif
#endif /* !MBEDTLS_PSK_MAX_LEN */
/**
* In PSA-client-only builds (MBEDTLS_PSA_CRYPTO_C off, e.g. NS-side
* mbedtls dispatching to a secure PSA service like TF-M) the local
* ECP_LIGHT cascade does not run and MBEDTLS_ECP_MAX_BYTES collapses
* to 1. Take the larger of that and PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE,
* which is sized by the enabled PSA_WANT_ECC_* curves and is always
* defined, so psa_raw_key_agreement() has a real output buffer to
* write the ECDH shared secret into.
*/
#define MBEDTLS_SSL_PMS_ECDH_SIZE \
(PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE > MBEDTLS_ECP_MAX_BYTES \
? PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE \
: MBEDTLS_ECP_MAX_BYTES)
/* Dummy type used only for its size */
union mbedtls_ssl_premaster_secret {
unsigned char dummy; /* Make the union non-empty even with SSL disabled */
#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_RSA_ENABLED) || \
defined(MBEDTLS_KEY_EXCHANGE_ECDHE_ECDSA_ENABLED)
unsigned char _pms_ecdh[MBEDTLS_SSL_PMS_ECDH_SIZE]; /* RFC 4492 5.10 */
unsigned char _pms_ecdh[PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE]; /* RFC 4492 5.10 */
#endif
#if defined(MBEDTLS_KEY_EXCHANGE_PSK_ENABLED)
unsigned char _pms_psk[4 + 2 * MBEDTLS_PSK_MAX_LEN]; /* RFC 4279 2 */
#endif
#if defined(MBEDTLS_KEY_EXCHANGE_ECDHE_PSK_ENABLED)
unsigned char _pms_ecdhe_psk[4 + MBEDTLS_SSL_PMS_ECDH_SIZE
unsigned char _pms_ecdhe_psk[4 + PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE
+ MBEDTLS_PSK_MAX_LEN]; /* RFC 5489 2 */
#endif
#if defined(MBEDTLS_KEY_EXCHANGE_ECJPAKE_ENABLED)