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

Interruptible APIs for key agreement use cases #199

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

athoelke
Copy link
Contributor

@athoelke athoelke commented Jun 20, 2024

Add interruptible operations for psa_generate_key(), psa_export_public_key() and psa_key_agreement().

This provides the new API elements, and updates the Functionality chapter to cover this simpler interruptible pattern, as well as the complex interruptible multi-part operations used for signature and verification from #107.

This is based on top of #107. The first unique commit is 57ae95c.

A preview of the PDF rendering of this PR: IHI0086-PSA_Certified_Crypto_API-1.3.0-interruptible-operations-draft3.pdf

Fixes #198

@athoelke athoelke added enhancement New feature or request API design Related the design of the API Crypto API Issue or PR related to the Cryptography API labels Jun 20, 2024
@athoelke athoelke added this to the Crypto API 1.3 milestone Jun 20, 2024
@athoelke athoelke marked this pull request as ready for review June 21, 2024 12:56
Copy link
Contributor

@MarcusJGStreets MarcusJGStreets left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look good to me

Provide interruptible operations for message and hash signature calculation and verification.

Reworked information in this section of the API relating to the behavior of different types of signature algorithm, consolidating this to the section introduction.
* Align permitted errors with the single-part functions
* Introduce the max_ops APIs
* Operation objects are now psa_xxx_iop_t, initialization PSA_XXX_IOP_INIT etc.
* Operation and support functions use 'iop' as an infix instead of 'interruptible'
Require that one of psa_xxx_iop_hash() or psa_xxx_iop_update() MUST be called in an interruptible signature operation.
Added three new interruptible operation APIs:
* psa_generate_key_iop_*() for key generation
* psa_export_public_key_iop_*() for public key export
* psa_key_agreement_iop_*() for key agreement
@athoelke
Copy link
Contributor Author

athoelke commented Aug 7, 2024

Rebased on main

Number of *ops* that the operation has taken so far.

After the interruptible operation has completed, the returned value is the number of *ops* required for the entire operation.
The value is reset to zero by a call to either `psa_key_agreement_iop_setup()` or `psa_key_agreement_iop_abort()`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we were discussing the specification, we implicitly assumed that setup takes negligible time. But this is not a safe assumption. For example, for key agreement, the public key needs to be validated. In Mbed TLS, we do this during setup (and it's the natural way to do it). Mbed TLS estimates the public key validation to take 3 ops. (The key agreement as a whole takes thousands of ops.)

So I think we should specify that setup resets the op count to 0 at the beginning of its operation, but then adds the number of ops that it takes. And recommend to implementations that this number should be lower than the value set with psa_iop_set_max_ops.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This applies to all the functions, although key agreement might be the only one for which it's really natural to have setup take a few ops.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That does complicate the way we can describe the reset of the ops value, but is a valid point. Is it sufficient to expect that validation will occur during setup, or should the recommendation be that if validation can be very complex (substantially more ops than a reasonable application-configured maximum) it should be deferred to the completion function?

Similar to the case for deferring key id allocation (PSA_ERROR_ALREADY_EXISTS returned by psa_key_agreement_iop_complete()), should we also permit psa_key_agreement_iop_complete() to return status codes related to the validation of the peer key? - which enables deferred validation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should recommend that setup should only perform a small number of ops, preferably less than whatever was set by psa_iop_set_max_ops().

And I hadn't thought of that, but indeed we should allow complete() to return status codes related to validations that may be considered slow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API design Related the design of the API Crypto API Issue or PR related to the Cryptography API enhancement New feature or request
Projects
Development

Successfully merging this pull request may close these issues.

Support for interruptible key agreement/exchange
3 participants