-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Rsa remove redundant public 3.6 #10327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: mbedtls-3.6
Are you sure you want to change the base?
Rsa remove redundant public 3.6 #10327
Conversation
After doing an RSA private-key operation, we do the public-key operation. This protects against a glitch attack (Lenstra 1996) against signatures when using CRT coefficients to optimize the private-key operation. Glitch attacks are normally outside our threat model, but this one is especially easy to exploit so we defend against it. For historical reasons we ended up having this protection twice: once inside `mbedtls_rsa_private()` (before unblinding), and another one in `mbedtls_rsa_rsassa_pkcs1_v15_sign()` (but not in PSS signature). Keep only the one that's done systematically in `mbedtls_rsa_private()`. Signed-off-by: Gilles Peskine <[email protected]>
It's protection against Lenstra's glitch attack on CRT exponentiation. Signed-off-by: Gilles Peskine <[email protected]>
Slight performance improvement. Signed-off-by: Gilles Peskine <[email protected]>
The glitch attack it protects against is specifically on the algorithm that uses the CRT coefficients. Slight performance improvement when `MBEDTLS_RSA_NO_CRT` is enabled. Signed-off-by: Gilles Peskine <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's there is good, but I think the PKCS#1 v1.5 sign function needs further cleanup.
} | ||
|
||
MBEDTLS_MPI_CHK(mbedtls_rsa_private(ctx, f_rng, p_rng, sig, sig_try)); | ||
MBEDTLS_MPI_CHK(mbedtls_rsa_public(ctx, sig_try, verif)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is good but I think this function's cleanup is not complete:
- the comment a few lines above needs updating
- we no longer need
verif
- I think we don't even need
sig_try
now.
Signed-off-by: Gilles Peskine <[email protected]>
Signed-off-by: Gilles Peskine <[email protected]>
`mbedtls_rsa_private()` is ok with aliasing the output with the input. Signed-off-by: Gilles Peskine <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
I think it's good to have in 3.6 as well. As a side benefit, it should save a bit of code size. Since we need to increase code size from time to time for security fixes, it's good to also have some size savings from time to time to partially compensate. |
The CI is unhappy. I think it's because the private-key operation now calls the unsafe exponentiation (the one that leaks the exponent). It's ok from a security perspective, because we're calling the safe one with the private exponent(s) and the unsafe one only with the public exponent. But the check in our test code can't tell that. Fixing this requires some thought and I'm treating this as low-priority so this pull request may be parked for a while. |
Minor improvements to the protection against Lenstra's glitch attack in RSA:
MBEDTLS_RSA_NO_CRT
is enabled: it's pointless.Note: I did 3.6 first out of habit, but do we actually want all of these changes in the LTS? Or just add a comment?
PR checklist