TPM2_Sign vs TPM2_RSA_Decrypt
Hi,
I'm pushing with James Prestwood RSA and ECDSA based asymmetric keys to asymmetric keys subsystem of the kernel and for e.g. RSA we can just use TPM2_RSA_Decrypt:
https://lore.kernel.org/all/[email protected]/
I've implemented some code that make this fit more cleanly to the kernel and James will refactor his old code on top of that. I.e. add the padding and asn1 data and make x.509 compatible scheme. Just do textbook style RSA part with TPM2.
Just for plain interest, because I'm not too familiar with TPM2_Sign:
when would you choose to use it instead? I just want to make sure that we're doing right things right :-)
BR, Jarkko
For the OpenSSL engines and also the GNU-TLS engine, we go ahead and use TPM2_RSA_Decrypt for RSA Signing but TPM2_Sign for ECDSA signing.
The reason here was, that OpenSSL wants to perform SHA512 digests and padding, whilst the TPM only supported SHA384. And an OpenSSL engine could not tell the OpenSSL-TLS-module, which Hash-Algs are supported.
If that restriction does not exist, I would also tend to use TPM2_Sign for RSA signing.
Cheers,
Andreas
-----Original Message-----
From: Jarkko Sakkinen <[email protected]>
Sent: Donnerstag, 16. Mai 2024 12:25
To: [email protected]
Subject: TPM2_Sign vs TPM2_RSA_Decrypt
Caution: This e-mail originated outside Infineon Technologies. Do not click on links or open attachments unless you validate it is safe<https://intranet-content.infineon.com/explore/aboutinfineon/rules/informationsecurity/ug/SocialEngineering/Pages/SocialEngineeringElements_en.aspx>.
Hi,
I'm pushing with James Prestwood RSA and ECDSA based asymmetric keys to asymmetric keys subsystem of the kernel and for e.g. RSA we can just use TPM2_RSA_Decrypt:
https://lore.kernel.org/all/[email protected]/
I've implemented some code that make this fit more cleanly to the kernel and James will refactor his old code on top of that. I.e. add the padding and asn1 data and make x.509 compatible scheme. Just do textbook style RSA part with TPM2.
Just for plain interest, because I'm not too familiar with TPM2_Sign:
when would you choose to use it instead? I just want to make sure that we're doing right things right :-)
BR, Jarkko
Quoted 2 lines · EEST,
For the OpenSSL engines and also the GNU-TLS engine, we go ahead and use
TPM2_RSA_Decryptfor RSA Signing butTPM2_Signfor ECDSA signing.
Yeah we get simplest and most understandable and most compatible RSA because it is textbook style with no strings attached :-) You can fit it to any scheme.
I can admit after reading TPM2_Sign documentation, my head hurts and I still don't think I fully get the gist of it so better not to use something that you don't get, right? :-)
If someone could really put TPM2_Sign into nutshell that'd be awesome.
Quoted 5 lines
The reason here was, that OpenSSL wants to perform SHA512 digests and padding, whilst the TPM only supported SHA384. And an OpenSSL engine could not tell the OpenSSL-TLS-module, which Hash-Algs are supported. If that restriction does not exist, I would also tend to use
TPM2_Signfor RSA signing.
Maybe a dumb question but what I could possibly accomplish with TPM2_Sign that I could not accomplish with TPM2_RSA_Decrypt and appropraite ASN.1 heading and padding?
This connects to the not understanding TPM2_Sign (obviously).
Just trying to make sure that we make exactly right call for kernel.
Thanks for responding!
Quoted 3 lines
Cheers,
Andreas
BR, Jarkko
Quoted 1 line
If someone could really put
TPM2_Signinto nutshell that'd be awesome.
Well, TPM2_Sign will perform a signing operation for you given the key. You can set the scheme in the scheme parameter. That's about it...
Quoted 1 line
Maybe a dumb question but what I could possibly accomplish with
TPM2_Signthat I could not accomplish withTPM2_RSA_Decryptand appropraite ASN.1 heading and padding?
Yes. If you set TPMA_OBJECT_SIGN but unset TPMA_OBJECT_DECRYPT. This way you can make sure that only signing-padding can ever be executed but never decrypt-based stuff. In order to use TPM2_RSA_Decrypt you need to set TPMA_OBJECT_DECRYPT which is kind of weird.
Also, if you want to use a restriced key (formally called Attestation Key) for regular signing operations, you need to have a TPMA_OBJECT_SIGN and must not have TPMA_OBJECT_DECRYPT set.
Those would be the reasons for preferring TPM2_Sign wherever possible IMHO.
Cheers,
Andreas
-----Original Message-----
From: Jarkko Sakkinen <[email protected]>
Sent: Donnerstag, 16. Mai 2024 14:52
To: Fuchs Andreas (SMD C3 EMEA TM) <[email protected]>; [email protected]
Cc: James Prestwood <[email protected]>
Subject: Re: TPM2_Sign vs TPM2_RSA_Decrypt
Caution: This e-mail originated outside Infineon Technologies. Do not click on links or open attachments unless you validate it is safe<https://intranet-content.infineon.com/explore/aboutinfineon/rules/informationsecurity/ug/SocialEngineering/Pages/SocialEngineeringElements_en.aspx>.
Quoted 2 lines · EEST,
For the OpenSSL engines and also the GNU-TLS engine, we go ahead and use
TPM2_RSA_Decryptfor RSA Signing butTPM2_Signfor ECDSA signing.
Yeah we get simplest and most understandable and most compatible RSA because it is textbook style with no strings attached :-) You can fit it to any scheme.
I can admit after reading TPM2_Sign documentation, my head hurts and I still don't think I fully get the gist of it so better not to use something that you don't get, right? :-)
If someone could really put TPM2_Sign into nutshell that'd be awesome.
Quoted 5 lines
The reason here was, that OpenSSL wants to perform SHA512 digests and padding, whilst the TPM only supported SHA384. And an OpenSSL engine could not tell the OpenSSL-TLS-module, which Hash-Algs are supported. If that restriction does not exist, I would also tend to use
TPM2_Signfor RSA signing.
Maybe a dumb question but what I could possibly accomplish with TPM2_Sign that I could not accomplish with TPM2_RSA_Decrypt and appropraite ASN.1 heading and padding?
This connects to the not understanding TPM2_Sign (obviously).
Just trying to make sure that we make exactly right call for kernel.
Thanks for responding!
Quoted 3 lines
Cheers,
Andreas
BR, Jarkko
Quoted 4 lines · EEST,
Quoted 1 line
If someone could really put
TPM2_Signinto nutshell that'd be awesome.Well,
TPM2_Signwill perform a signing operation for you given the key. You can set the scheme in the scheme parameter. That's about it...
Right. What about the ticket? Can you imagine a use case for that?
Quoted 6 lines
Quoted 1 line
Maybe a dumb question but what I could possibly accomplish with
TPM2_Signthat I could not accomplish withTPM2_RSA_Decryptand appropraite ASN.1 heading and padding?Yes. If you set
TPMA_OBJECT_SIGNbut unsetTPMA_OBJECT_DECRYPT. This way you can make sure that only signing-padding can ever be executed but never decrypt-based stuff. In order to useTPM2_RSA_Decryptyou need to setTPMA_OBJECT_DECRYPTwhich is kind of weird.
David, did you have a "framework" for deciding between these two when you originally implemented the patch? I.e. did you consider TPM2_Sign but ended up to TPM2_RSA_Decrypt?
Not meaning to blame just want to go fully through this :-) It is working code after all.
Huge benefit I see with TPM2_Sign would be probably that we get ECDSA from the same functionality.
Disadvantage is that we can use TPM2_Decrypt, i.e. single command for decrypt operation. Encryption side is done in the case asymmetric keys with software as it is done with the public key.
Have not actually looked at yet TPM2_EncrypDecrypt and TPM2_EncryptDecrypt2 (do not know even their difference).
Quoted 5 lines
Also, if you want to use a restriced key (formally called Attestation Key) for regular signing operations, you need to have a
TPMA_OBJECT_SIGNand must not haveTPMA_OBJECT_DECRYPTset.Those would be the reasons for preferring
TPM2_Signwherever possible IMHO.
Actually I think in our case it should be non-restricted as the point is x.509 certs not proving TPM inherent properties.
Also section 3.5 seems to support this view, if I understand it correctly:
So technically I see TPM2_RSA_Decrypt and TPM2_Sign still equivalent in the context of use case...
Quoted 3 lines
Cheers,
Andreas
BR, Jarkko
Quoted 8 lines · Jarkko Sakkinen
Quoted 4 lines · EEST,
Quoted 1 line
If someone could really put
TPM2_Signinto nutshell that'd be awesome.Well,
TPM2_Signwill perform a signing operation for you given the key. You can set the scheme in the scheme parameter. That's about it...Right. What about the ticket? Can you imagine a use case for that?
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Maybe a dumb question but what I could possibly accomplish with
TPM2_Signthat I could not accomplish withTPM2_RSA_Decryptand appropraite ASN.1 heading and padding?Yes. If you set
TPMA_OBJECT_SIGNbut unsetTPMA_OBJECT_DECRYPT. This way you can make sure that only signing-padding can ever be executed but never decrypt-based stuff. In order to useTPM2_RSA_Decryptyou need to setTPMA_OBJECT_DECRYPTwhich is kind of weird.David, did you have a "framework" for deciding between these two
~~~~~
James
Ugh, sorry ;-)
BR, Jarkko
Quoted 11 lines · Jarkko Sakkinen
Quoted 3 lines · EEST,
Quoted 1 line
If someone could really put
TPM2_Signinto nutshell that'd be awesome.Well,
TPM2_Signwill perform a signing operation for you given the key. You can set the scheme in the scheme parameter. That's about it...Right. What about the ticket? Can you imagine a use case for that?
Quoted 5 lines
Quoted 1 line
Maybe a dumb question but what I could possibly accomplish with
TPM2_Signthat I could not accomplish withTPM2_RSA_Decryptand appropraite ASN.1 heading and padding?Yes. If you set
TPMA_OBJECT_SIGNbut unsetTPMA_OBJECT_DECRYPT. This way you can make sure that only signing-padding can ever be executed but never decrypt-based stuff. In order to useTPM2_RSA_Decryptyou need to setTPMA_OBJECT_DECRYPTwhich is kind of weird.
Quoted 6 lines
David, did you have a "framework" for deciding between these two when you originally implemented the patch? I.e. did you consider
TPM2_Signbut ended up toTPM2_RSA_Decrypt?Not meaning to blame just want to go fully through this :-) It is working code after all.
To be honest I started with encrypt/decrypt and included the signing operation because it was basically "free" by using tpm2_rsa_decrypt(). I was not aware of this distinction/difference between that and doing signing on the TPM itself. I don't think I ever looked into the signing command on the TPM itself.
Quoted 30 lines
Huge benefit I see with
TPM2_Signwould be probably that we get ECDSA from the same functionality.Disadvantage is that we can use
TPM2_Decrypt, i.e. single command for decrypt operation. Encryption side is done in the case asymmetric keys with software as it is done with the public key.Have not actually looked at yet
TPM2_EncrypDecryptandTPM2_EncryptDecrypt2(do not know even their difference).Quoted 5 lines
Also, if you want to use a restriced key (formally called Attestation Key) for regular signing operations, you need to have a
TPMA_OBJECT_SIGNand must not haveTPMA_OBJECT_DECRYPTset.Those would be the reasons for preferring
TPM2_Signwherever possible IMHO.Actually I think in our case it should be non-restricted as the point is x.509 certs not proving TPM inherent properties.
Also section 3.5 seems to support this view, if I understand it correctly:
So technically I see
TPM2_RSA_DecryptandTPM2_Signstill equivalent in the context of use case...Quoted 2 lines
Cheers,
AndreasBR, Jarkko
Quoted 5 lines · James Prestwood
To be honest I started with encrypt/decrypt and included the signing operation because it was basically "free" by using
tpm2_rsa_decrypt(). I was not aware of this distinction/difference between that and doing signing on the TPM itself. I don't think I ever looked into the signing command on the TPM itself.
My personal take: I'd start RSA with the working code and just clean up the parts for the first round. It is tested code and does the job, right? :-)
Then we will weight the odds and cons in the review. That said, if you want to use TPM_Sign and TPM2_EncryptDecrypt(2) that is fine too, but not demand.
As for ECDSA, it can be part of the patch set, or we can start just with the RSA part.
Andreas, is it OK if the patch set is CC'd to you so you can give your feedback/remarks on it?
BR, Jarkko
Quoted 9 lines · Jarkko Sakkinen
Quoted 5 lines · James Prestwood
To be honest I started with encrypt/decrypt and included the signing operation because it was basically "free" by using
tpm2_rsa_decrypt(). I was not aware of this distinction/difference between that and doing signing on the TPM itself. I don't think I ever looked into the signing command on the TPM itself.My personal take: I'd start RSA with the working code and just clean up the parts for the first round. It is tested code and does the job, right? :-)
It was tested then yes, obviously need to verify that after 4 years :)
Quoted 11 lines
Then we will weight the odds and cons in the review. That said, if you want to use
TPM_SignandTPM2_EncryptDecrypt(2)that is fine too, but not demand.As for ECDSA, it can be part of the patch set, or we can start just with the RSA part.
Andreas, is it OK if the patch set is CC'd to you so you can give your feedback/remarks on it?BR, Jarkko
TPM2_EncryptDecrypt2 is for Symmetric encryption (i.e. AES) only.
I'd still recommend to go for TPM2_Sign().
Note also that switching may be hard later down the road, since the key usage flags are define during creation. So backwards compatibility is nasty here.
Feel free to CC me.
I'll do what I can.
-----Original Message-----
From: James Prestwood <[email protected]>
Sent: Donnerstag, 16. Mai 2024 15:59
To: Jarkko Sakkinen <[email protected]>; Fuchs Andreas (SMD C3 EMEA TM) <[email protected]>; [email protected]
Subject: Re: TPM2_Sign vs TPM2_RSA_Decrypt
Caution: This e-mail originated outside Infineon Technologies. Do not click on links or open attachments unless you validate it is safe<https://intranet-content.infineon.com/explore/aboutinfineon/rules/informationsecurity/ug/SocialEngineering/Pages/SocialEngineeringElements_en.aspx>.
Quoted 9 lines · Jarkko Sakkinen
Quoted 5 lines · James Prestwood
To be honest I started with encrypt/decrypt and included the signing operation because it was basically "free" by using
tpm2_rsa_decrypt(). I was not aware of this distinction/difference between that and doing signing on the TPM itself. I don't think I ever looked into the signing command on the TPM itself.My personal take: I'd start RSA with the working code and just clean up the parts for the first round. It is tested code and does the job, right? :-)
It was tested then yes, obviously need to verify that after 4 years :)
Quoted 11 lines
Then we will weight the odds and cons in the review. That said, if you want to use
TPM_SignandTPM2_EncryptDecrypt(2)that is fine too, but not demand.As for ECDSA, it can be part of the patch set, or we can start just with the RSA part.
Andreas, is it OK if the patch set is CC'd to you so you can give your feedback/remarks on it?BR, Jarkko
Quoted 11 lines · James Prestwood
Quoted 9 lines · Jarkko Sakkinen
Quoted 5 lines · James Prestwood
To be honest I started with encrypt/decrypt and included the signing operation because it was basically "free" by using
tpm2_rsa_decrypt(). I was not aware of this distinction/difference between that and doing signing on the TPM itself. I don't think I ever looked into the signing command on the TPM itself.My personal take: I'd start RSA with the working code and just clean up the parts for the first round. It is tested code and does the job, right? :-)
It was tested then yes, obviously need to verify that after 4 years :)
Yeah, I gave some nitpicks for you (private) and yeah branch (tpm2_key) branch has shenigans to call ANS.1 template acquiring function from the stock RSA code in the kernel :-)
Better to do as little as possible and then we look at what actually needs to be done.
In addition to Andreas, I'd recommend to first of all CC the patch set to linux-crypto too in addition to linux-integrity and keyrings and also Herbert Xu (crypto maintainer).
I know this is some effort to you but isn't it any way worth it because then the work that you did years ago was not wasted? :-)
BR, Jarkko
Quoted 8 lines · EEST,
TPM2_EncryptDecrypt2is for Symmetric encryption (i.e. AES) only.I'd still recommend to go for
TPM2_Sign().
Note also that switching may be hard later down the road, since the key usage flags are define during creation. So backwards compatibility is nasty here.Feel free to CC me.
I'll do what I can.
Great I get that but I'd still start with the existing code because it was how it was done. I'm strong believer of "change only by stimulus" and it is rare for feature patch set anyway land in the first round.
BR, Jarkko
Quoted 7 lines · Jarkko Sakkinen
Quoted 6 lines · EEST,
TPM2_EncryptDecrypt2is for Symmetric encryption (i.e. AES) only.I'd still recommend to go for
TPM2_Sign().
Note also that switching may be hard later down the road, since the key usage flags are define during creation. So backwards compatibility is nasty here.
Quoted 6 lines
Quoted 2 lines
Feel free to CC me.
I'll do what I can.Great I get that but I'd still start with the existing code because it was how it was done. I'm strong believer of "change only by stimulus" and it is rare for feature patch set anyway land in the first round.
In the case of asymmetric keys, the hash comes from outside and it is signed by the TPM so to be neutral to the source, TPM2_RSA_Decrypt does make sense. It is more robust in this case.
BR, Jarkko