mirror of
https://github.com/espressif/mbedtls.git
synced 2026-09-05 18:09:55 +00:00
mbedtls 4.1.1 replaced the trial-division small-factor test in prime
generation with a constant-time GCD against the 1380-bit small-primes
product (same change as upstream mbedtls commit 7a29052238 in 3.6.7).
The GCD runs a fixed (A_limbs + N_limbs) * biL iterations per prime
candidate, making RSA key generation ~5x slower on 64-bit hosts and
~10x slower on ESP chips, and its non-yielding software loop starves
the FreeRTOS idle task, tripping the task watchdog.
Restore the pre-3.6.7 variable-time trial division and keep the
constant-time implementation available behind the new
MBEDTLS_MPI_PRIME_SIEVE_VARIABLE_TIME macro (defined by ESP-IDF's
esp_config.h unless CONFIG_MBEDTLS_CONSTANT_TIME_PRIME_GEN is enabled).
The trial-division path keeps the 4.x input contract (X <= 997 returns
MBEDTLS_ERR_MPI_BAD_INPUT_DATA). Builds without the macro keep upstream
behavior unchanged.