Only build mbedtls_rsa_deduce_private_exponent when key generation is enabled #669

Open
opened 2026-01-21 07:37:29 -06:00 by gilles-peskine-arm · 0 comments
gilles-peskine-arm commented 2026-01-21 07:37:29 -06:00 (Migrated from github.com)

Since TF-PSA-Crypto 1.0, there is no way to import an RSA private key without the private exponent. We've already done some cleanup (https://github.com/Mbed-TLS/TF-PSA-Crypto/issues/576), but the now private function mbedtls_rsa_deduce_private_exponent() is still present in the build and used in tests.

mbedtls_rsa_deduce_private_exponent() needs to remain in the code because it's used during key generation. But we don't need it in builds without RSA key generation.

There is test data in test_suite_rsa.data which has key pairs given only by (N, E, Q, P) without D. We should rewrite this test data to have complete RSA key data, in particular with D. Strictly speaking, the goal of this issue is only to add the private exponent to the data; however we might want to move directly to the standard ASN.1 representation of private keys with all the fields.

Goals of this issue:

  • test_suite_rsa.data doesn't have key pairs given only by (N, E, Q, P).
  • In test_suite_rsa.function, mbedtls_rsa_test_fill_context() doesn't try to fill in for a missing D. (Of course, in public keys, only N and E are present.)
  • mbedtls_rsa_deduce_private_exponent is guarded by MBEDTLS_PSA_BUILTIN_WANT_RSA_KEY_PAIR_GENERATE (or MBEDTLS_GENPRIME, which is the legacy symbol with the same meaning).
Since TF-PSA-Crypto 1.0, there is no way to import an RSA private key without the private exponent. We've already done some cleanup (https://github.com/Mbed-TLS/TF-PSA-Crypto/issues/576), but the now private function `mbedtls_rsa_deduce_private_exponent()` is still present in the build and used in tests. `mbedtls_rsa_deduce_private_exponent()` needs to remain in the code because it's used during key generation. But we don't need it in builds without RSA key generation. There is test data in `test_suite_rsa.data` which has key pairs given only by (N, E, Q, P) without D. We should rewrite this test data to have complete RSA key data, in particular with D. Strictly speaking, the goal of this issue is only to add the private exponent to the data; however we might want to move directly to the standard ASN.1 representation of private keys with all the fields. Goals of this issue: * `test_suite_rsa.data` doesn't have key pairs given only by (N, E, Q, P). * In `test_suite_rsa.function`, `mbedtls_rsa_test_fill_context()` doesn't try to fill in for a missing D. (Of course, in public keys, only N and E are present.) * `mbedtls_rsa_deduce_private_exponent` is guarded by `MBEDTLS_PSA_BUILTIN_WANT_RSA_KEY_PAIR_GENERATE` (or `MBEDTLS_GENPRIME`, which is the legacy symbol with the same meaning).
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-Mbed-TLS/TF-PSA-Crypto#669
No description provided.