Skip to content

Conversation

@athoelke
Copy link
Contributor

@athoelke athoelke commented Oct 21, 2024

Starting from #220 - this PR:

  • Strips out ML-KEM (to be presented in a PQC extension document).
  • Updates the text align with other key establishment APIs.
  • Provide a more general overview for KEMs.
  • Provide a detailed alignment for ECIES with the SEC1 procedures, as the ECIES in the Crypto API is just the key agreement aspect.
  • Moved some of the description and commentary into admonitions to clarify the content.

Some open issues:

  • The encapsulation data sizing macro names. On other APIs, we typically name these after the function and the output parameter - but that would result in PSA_ENCAPSULATE_ENCAPSULATION_SIZE() which seems somewhat repetitive. I have currently gone with PSA_ENCAPSULATION_SIZE(), as the variable name is pretty distinctive.
  • Should we consistently call this 'Encapsulation', 'Key encapsulation', or 'Key encapsulation mechanism'? - currently the text is mostly a mix of the first two.
  • The output key is variously referred to as 'output key', 'shared output key', 'shared secret', and 'shared secret key'. Is there a best/preferred term for this in this API?
  • If a decapsulation algorithm has an explicit failure (returns an error if the decapsulation fails rather than the wrong key), what error code should we use? (INVALID_ARGUMENT, or INVALID_SIGNATURE, or something else?).

This PR provides the API foundations for ML-KEM (#95).

@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 Oct 21, 2024
@athoelke athoelke added this to the Crypto API 1.3 milestone Oct 21, 2024
@athoelke
Copy link
Contributor Author

Another thing I am noticing in the additions for 1.3 - there are a lot of new key-returning functions. The list of 'key creation' functions is repeated about 8 times in the spec, and these are getting quite chunky now with over 10 such functions.

It might be worth reviewing those passages and simplifying the wording, and references to ALL of these APIs.

@athoelke athoelke mentioned this pull request Oct 22, 2024
@athoelke
Copy link
Contributor Author

Updated:

  • Decided to use "key-encapsulation algorithm" everywhere
  • Use "shared secret" when describing the result value of the encapsulation/decapsulation process
  • Use "shared output key" when describing the key object returned by psa_encapsulate() and psa_decapsulate()
  • Permit PSA_ERROR_INVALID_SIGNATURE for encapsulation data authentication failure
  • Describe failure possibility for probablistic algorithms (e.g. ML-KEM) as reason for non-identical output keys
  • Warn implementations against reporting padding validity errors

@athoelke
Copy link
Contributor Author

Decided that PSA_ENCAPSULATION_SIZE() and PSA_ENCAPSULATION_MAX_SIZE are suitable for the support macro names.

Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm left a comment

Choose a reason for hiding this comment

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

Looks mostly good to me, but with a few reservations, mostly about terminology.

Comment on lines 99 to 100
- `PSA_KEY_USAGE_ENCAPSULATE`
- `PSA_KEY_USAGE_DECAPSULATE`
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if ENCAPSULATE/DECAPSULATE are truly different usages from ENCRYPT/DECRYPT. We already have a precedent that ENCRYPT/DECRYPT covers symmetric encryption, AEAD and asymmetric encryption.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This seems reasonable.

Although ECIES uses an ECC key - the permitted algorithm policy would ensure that ENCRYPT usage indicates permission for psa_encapsulate(), and not psa_asymmetric_encrypt(). This is similar to the way ENCRYPT usage on an AES key is qualified by the permitted algorithm policy.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The [currently] last commit (145c376) has an implementation of this idea - removing the new usage flags and adding encapsulation and encapsulation to ENCRYPT/DECRYPT.

@athoelke
Copy link
Contributor Author

athoelke commented Nov 1, 2024

Addressed all of the issues raised - but one or two might benefit from validation and/or fine tuning. The removal of explicit encalsulation usage flags is a single commit that can be reverted if this does not turn out to be a better approach.

Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm left a comment

Choose a reason for hiding this comment

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

LGTM except for one confusing paragraph.

Key-encapsulation algorithms are often referred to as 'key-encapsulation mechanisms' or KEMs.

In a key-encapsulation algorithm, participant A generates a key-pair: a private decapsulation key, and a public encapsulation key.
The public encapsulation key is made available to participant B, who needs to establish secure communication with the participant A.
Copy link
Contributor

Choose a reason for hiding this comment

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

“B, who needs to establish …” — the formulation is ambiguous: is this a goal of key encapsulation, or a prerequisite? It would be clearer to first state that the goal of key encapsulation is to establish a shared secret between A and B, before starting the description of the protocol.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I patterned the current text on material elsewhere, but the motivation context will also allow me to make that sentence simpler.

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've rewritten that paragraph into more of a flow:

In a key-encapsulation algorithm, participants A and B establish a shared secret as follows:

  1. Participant A generates a key-pair: a private decapsulation key, and a public encapsulation key.
  2. The public encapsulation key is made available to participant B.
  3. Participant B uses the encapsulation key to generate one copy of a shared secret, and some ciphertext.
  4. The ciphertext is transferred to participant A.
  5. Participant A uses the private decapsulation key to compute another copy of the shared secret.

Also provide ECIES algorithm.
* Use "key-encapsulation algorithm"
* Permit INVALID_SIGNATURE error for authentication failure
* Include probablistic failure as additional reason for non-guarantee (e.g. ML-KEM)
* Add note to NOT report padding errors in a distinct manner
Leave 0x0b for key-wrapping, and use 0x0c for encapsulation.
Fixing terminology for encapsulation API. This includes updating the ciphertext buffer sizing macros to be PSA_ENCAPSULATE_CIPHERTEXT_[MAX_]SIZE.
* Errors related to invalid key handles or policy failure
* Errors related to creating a persistent key
@athoelke athoelke force-pushed the crypto-encapsulation-ecies branch from 145c376 to e99d9e0 Compare November 4, 2024 15:40
@athoelke
Copy link
Contributor Author

athoelke commented Nov 4, 2024

Rebased following merge of #221, and added improvement for the description of key encapsulation.

Copy link
Contributor

@gilles-peskine-arm gilles-peskine-arm left a comment

Choose a reason for hiding this comment

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

LGTM

@athoelke athoelke merged commit ad57e51 into ARM-software:main Nov 4, 2024
@athoelke athoelke deleted the crypto-encapsulation-ecies branch November 4, 2024 17:32
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.

2 participants