-
Notifications
You must be signed in to change notification settings - Fork 110
Address potential constant time issues #163
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
Conversation
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
|
@simo5 This is the PR. |
Pull Request Test Coverage Report for Build 1663
💛 - Coveralls |
|
The individual bignum changes look ok, but functions like TPM_RSAPrivateDecrypt() are definitely not constant time the way they are built, so they are subject to attacks of the Bleichenbacher family, as well as probably others. |
@simo5 , thanks for looking at this. I hope these changes are sufficient because I see Which RSA decryption function did you look at? When I switched it over to OpenSSL I kept the original TPM 2 code around and then built variants that use the EVP functions of OpenSSL for decryption and signing. I admit that it's a bit confusing for someone looking at it but I want to be able to track changes in the upstream TPM 2 code I would rebase on to see what they change and whether I have to follow in the OpenSSL code as well. So there's this type of #define in the code to activate the OpenSSL RSA functions for example. Similarly for EC functions related to ECDSA have this here: |
c9cba7e to
09cd84c
Compare
Oh, this is TPM 1.2 code. Is the padding check the issue here? Because for the actual decryption we rely on OpenSSL functions. |
|
@simo5 I implemented the decryption code now with the EVP functions. Is the signing code also vulnerable? This signing is a single call to RSA_Sign(): https://github.com/stefanberger/libtpms/blob/master/src/tpm12/tpm_crypto.c#L912 |
09cd84c to
c58f46d
Compare
|
Ah I forgot about the old vs new code split. So clearly the new code is in better shape, That said, if you wanted to use CryptRSADecrypt within the TLS protocol (to protect private keys in a TPM) then you would need to offer an API that returns a random buffer in case of failure, not an error (for PKCS15 padding at least). This may be an oracle for other protocols as well, it is very difficult to deal with proper constant-time as it is protocol dependent what may be an oracle and what isn't. However excluding such protocol dependent issues I thin the current patch looks ok. |
Yes padding is the issue |
If you have a signing oracle then same considerations apply. |
c58f46d to
998e08f
Compare
I now tried to convert the signing to use EVP as well but for TPM 1.2 signing scheme The |
2f15d8c to
600f15d
Compare
Set BN_FLG_CONSTTIME on the sensitive parts of the RSA key to select constant time computations. Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
600f15d to
85af0fb
Compare
Set BN_FLG_CONSTTIME on the sensitive parts of the RSA key to select constant time computations. Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
85af0fb to
4151856
Compare
This PR addresses potential constant time issues that may arise when passing secrets to certain OpenSSL BIGNUM operations.