Skip to content
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

Implement Interruptible ECC Keypair Generation #9106

Open
paul-elliott-arm opened this issue May 7, 2024 · 6 comments
Open

Implement Interruptible ECC Keypair Generation #9106

paul-elliott-arm opened this issue May 7, 2024 · 6 comments
Labels
component-psa PSA keystore/dispatch layer (storage, drivers, …) size-m Estimated task size: medium (~1w)

Comments

@paul-elliott-arm
Copy link
Member

Following on from the design finalised in #9044, implement the PSA interruptible ECC keypair generation.

This will include a basic driver wrapper layer that will only route to the internal implementation, and nested context structures to facilitate this and any future driver work in this area.

@paul-elliott-arm paul-elliott-arm added component-psa PSA keystore/dispatch layer (storage, drivers, …) size-m Estimated task size: medium (~1w) labels May 7, 2024
@paul-elliott-arm paul-elliott-arm added this to PSA Crypto: Interruptable ECC work in Backlog for Mbed TLS May 7, 2024
@gilles-peskine-arm
Copy link
Contributor

gilles-peskine-arm commented May 7, 2024

Do we really need interruptible keypair generation?

ECC private key generation is very fast: it's essentially a symmetric operation. The costly part of ECC key pair generation is calculating the public key. The way Mbed TLS is structured, we don't store the public key, we recalculate it each time it's needed. So we don't need interruptibility for psa_generate_key. The same applies to FFDH.

RSA private key generation is slow, but we have no demand for interruptible RSA. And even if we did, RSA private key generation is so slow that it typically wouldn't be done in contexts where interruptibility is required.

@paul-elliott-arm
Copy link
Member Author

I'm going off the spec sheet on #7293 to be honest - tagging @mpg for further discussion on this.

@yanesca
Copy link
Contributor

yanesca commented May 9, 2024

The way Mbed TLS is structured, we don't store the public key, we recalculate it each time it's needed.

As far as I can tell we call mbedtls_ecp_gen_key() from PSA, which calculates the public key as well.

@gilles-peskine-arm
Copy link
Contributor

As far as I can tell we call mbedtls_ecp_gen_key() from PSA, which calculates the public key as well.

Ah, indeed. So this ticket should morph into making PSA call code that doesn't waste time calculating the public key. (It wasn't a waste of time when originally written, because back then we kept the public key in memory.) I guess mbedtls_ecp_gen_privkey instead of mbedtls_ecp_gen_key. We should do this for 3.6 too.

@mpg
Copy link
Contributor

mpg commented May 15, 2024

I think Andrew has summarized things quite clearly here: ARM-software/psa-api#198

It seems to me that PSA Crypto implementation are free to compute the public key either during keygen or when exporting it (or both, as we're currently doing, though that's silly of course). So, I think the PSA Crypto API needs both interruptible keygen and interruptible export-public in order to preserve implementation freedom.

OTOH, our implementation should indeed be changed to not compute the public key during keygen only to discard it right away. Once that's done, I guess we could choose not to implement interruptible keygen and instead have our documentation say that ECC keygen is fast enough.

However, doing so would create a compatibility constraint: once we promise ECC keygen is fast enough, we're not allowed to change that in a minor release. Otherwise, people who have working code calling non-interruptible keygen would have to change their code in order to start calling interruptible keygen when upgrading, which is contrary to our compatibility promises.

So, in order to avoid imposing that compatibility constraint on ourselves, we might want to implement interruptible keygen right away. The implementation would probably be relatively as complete() would always complete the work the first time it's called. But the documentation would not promise it to be so (and perhaps even include a warning that this may change in the future, in case people notice and start wrongly thinking they can rely on this).

Then we'd be free to change our strategy about when the public part is computed and whether it's stored whenever we please.

Wdyt?

@gilles-peskine-arm
Copy link
Contributor

@mpg Right, at the API level we don't want to commit whether the public key is calculated at generation time or each time it's needed. So there will be both an interruptible generate-key-pair and an interruptible export-public-key.

In Mbed TLS, since we don't keep the public key around (because it makes driver support easier), we should have psa_generate_key call mbedtls_ecp_gen_privkey rather than mbedtls_ecp_gen_key (which dates back from when we were keeping the mbedtls_ecp_keypair object around, instead of just keeping the export form of the key which only contains the private value).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component-psa PSA keystore/dispatch layer (storage, drivers, …) size-m Estimated task size: medium (~1w)
Projects
Backlog for Mbed TLS
PSA Crypto: Interruptable ECC work
Development

No branches or pull requests

4 participants