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

[DRAFT v1] Define the SPAKE2+ algorithms #126

Closed
wants to merge 18 commits into from

Conversation

athoelke
Copy link
Contributor

@athoelke athoelke commented Nov 15, 2023

[Edited] : This is the first draft. An revised and reorganised version of this PR is now available: #129


This PR merges the 'best guess' result of the other PAKE and SPAKE2+ PRs (#114, #119, #120, #124), before defining the SPAKE2+ algorithms.

The Algorithm definition begins in commit e784de8, in case you have reviewed the other pieces already.

For a draft of the whole spec: Crypto_API-1.2_PAKE_Extension-bet.2-draft-spake2plus.pdf

DO NOT MERGE

There remain open issues in the preceding PRs. Once there is broad agreement on the open API design issues, I will merge the PR changes, to permit a second pass editorial review and rework of the result.

I am not convinced that the document structure is quite right. SPAKE2+ benefits from significant explanatory text for how the keys, algorithms, and operation work together - but this material is shared by three algorithm and two key API identifiers, and is currently somewhat scattered. This material cannot be delegated to other sources (as is the case for most other algorithms in the API), because the asymmetric key approach used here is novel, and we [reasonably] constrain some SPAKE2+ options in order to conform to the Matter specification.

* Add key encodings
* Define public key format
* Define key derivation procedure
* Moved the hash algorithm parameter to the PAKE cipher suite into the PAKE algorithm identifier, instead of a separate attribute of the cipher suite.
* This also makes the hash algorithm value available to the `PSA_PAKE_OUTPUT_SIZE()` and `PSA_PAKE_INPUT_SIZE()` macros.
* Replace psa_pake_get_implicit_key() with psa_pake_get_shared_key()
* Add key confirmation attribute to the PAKE cipher suite
* The shared secret is always output as a single key
* Removed the input key size, key size is determined by operation
* Removed key-size helper macro as unnecessary
* Recognise that not all PAKE algorithms produce a secret that is suitable for use as an encryption key
* Encourage the use of PAKE output as a key-derivation key
* Supporting both RFC 9393 and Matter
* New APIs:
  - `PSA_ALG_SPAKE2P_HMAC()`
  - `PSA_ALG_SPAKE2P_CMAC()`
  - `PSA_ALG_SPAKE2P_MATTER`
  - `PSA_ALG_IS_SPAKE2P()`
  - `PSA_ALG_IS_SPAKE2P_HMAC()`
  - `PSA_ALG_IS_SPAKE2P_CMAC()`
@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 DO NOT MERGE labels Nov 15, 2023
@athoelke athoelke self-assigned this Nov 15, 2023
@athoelke
Copy link
Contributor Author

@silabs-Kusumit, @silabs-hannes, @oberon-sk, @yanesca: this might be the PR you have been waiting for?

@athoelke
Copy link
Contributor Author

Reviewing the flow:

SPAKE2+ authentication flow graphic from the PR

It seems slightly odd that the key is provided during the psa_pake_setup(), and the role is set afterward, even though the role (for SPAKE2+) dictates what kind of key can be used. For example, if the operation is setup with a SPAKE2+ public key, then a subsequent call to psa_pake_set_role(..., PSA_PAKE_ROLE_CLIENT) would have to fail with PSA_ERROR_INVALID_ARGUMENT.

It seems it might feel more logical for the role to be declared as part of the setup (see #115 where the key input was moved to the setup function) so the combination of cipher-suite, key and role can be validated together.

On the other hand, it is possible to call psa_pake_set_role() with other roles (e.g. PSA_PAKE_ROLE_FIRST), that are invalid for the cipher-suite. So maybe this is not as odd as it first seemed to me?

@silabs-Kusumit
Copy link

I think that psa_pake_set_role() should be a separate function from psa_pake_setup(). The set_role() function is similar to set_user(), set_peer() functions and it doesn't feel right to add set_role to the setup function for only one PAKE algorithm.


The SPAKE2+ key types can be output from a key derivation using :code:`psa_key_derivation_output_key()`. The SPAKE2+ protocol recommends that a key-stretching kdf, such as PBKDF2, is used to hash the SPAKE2+ password. See RFC 9383 for details.

For example, after setting up the PBKDF2 operation, the following process will derive the SPAKE2+ key pair for use with the P-256 Elliptic curve group :issue:`(This example may be more than necessary in the specification?)`:
Copy link

@silabs-Kusumit silabs-Kusumit Nov 27, 2023

Choose a reason for hiding this comment

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

We can add the flow with exact steps in the registration phase diagram. And reference the same here.

Copy link
Contributor Author

@athoelke athoelke Dec 1, 2023

Choose a reason for hiding this comment

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

This is what I have done in Draft-2, as part of the reorganisation. See #129

* A SPAKE2+ public key is the pair (w0, L).

.. todo::
Would a table of required w0s/w1s lengths for each of the supported SPAKE2+ elliptic curve groups be useful here?

Choose a reason for hiding this comment

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

I think the table would be helpful for implementations

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have done this in the updated #119, and so in Draft-2 (#129).

@silabs-Kusumit
Copy link

I am not convinced that the document structure is quite right. SPAKE2+ benefits from significant explanatory text for how the keys, algorithms, and operation work together - but this material is shared by three algorithm and two key API identifiers, and is currently somewhat scattered. This material cannot be delegated to other sources (as is the case for most other algorithms in the API), because the asymmetric key approach used here is novel, and we [reasonably] constrain some SPAKE2+ options in order to conform to the Matter specification.

Maybe adding a document in the appendix folder for the details on SPAKE2+ would be helpful

@athoelke
Copy link
Contributor Author

Maybe adding a document in the appendix folder for the details on SPAKE2+ would be helpful

I've thought about this a bit more, and think there are approximately three main ways to slice this:

  1. Split the API definition into three parts: SPAKE2+ section, JPAKE section, common section.

    The algorithm-specific sections would provide an introduction to the protocol, how to use the API for the protocol (the flows), the key types, formats & derivations; and the algorithm identifiers. The common section would provide the definition of the shared parts of the API (primitives, cipher-suites, roles, and the operation itself).

    Given that the protocol descriptions only make proper sense with an understanding of the common API, it might be better to define the common section first, and then introduce the protocols?

  2. Maintain something like the first draft, where the how-to for a protocol is described as part of the various elements that make it up.

  3. Move the how-to material to an appendix.

The last option would mostly work in this Extension specification. However, when integrated into the main specification, I would be concerned that they would become detached from the PAKE API definition, and lose value as a result.

On the whole I have been trending toward moving the summaries for each category of algorithm into the section that defines that API. For example, the change in v1.1 where most of that material from the Functionality overview was moved into the intro to each cryptographic operation section of the API.

I'm going to draft something like (1) above for the next revision, to see how that looks...

@athoelke athoelke changed the title Define the SPAKE2+ algorithms [DRAFT v1] Define the SPAKE2+ algorithms Dec 1, 2023
@athoelke athoelke marked this pull request as draft December 4, 2023 15:44
@athoelke
Copy link
Contributor Author

This PR has been superseded by the alternative document layout in the [v2] PR #129.

@athoelke athoelke closed this Jan 10, 2024
@athoelke athoelke deleted the pake-spake2p branch January 10, 2024 15:34
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 DO NOT MERGE enhancement New feature or request
Projects
Development

Successfully merging this pull request may close these issues.

2 participants