PK: add mbedtls_pk_get_key_type() #509

Closed
opened 2025-10-09 06:00:57 -05:00 by mpg · 1 comment
mpg commented 2025-10-09 06:00:57 -05:00 (Migrated from github.com)

Create a new public function mbedtls_pk_get_key_type() that takes as input a pk_context and returns a PSA key type, namely one of:

  • PSA_KEY_TYPE_RSA_KEY_PAIR
  • PSA_KEY_TYPE_RSA_PUBLIC_KEY
  • PSA_KEY_TYPE_ECC_KEY_PAIR(curve)
  • PSA_KEY_TYPE_ECC_PUBLIC_KEY(curve)
  • PSA_KEY_TYPE_NONE (if the context is not populated)

Test plan:

  • the input context can be unpopulated, or populated with pk_wrap_psa(), pk_parse_key() or pk_parse_public_key(), pk_copy_from_psa() or pk_copy_public_from_psa()
  • for each input case we want exercise all possible outputs (ideally with two different curves for ECC keys). (Note that wrap_psa only creates key pairs, like pk_parse_key(); conversely, pk_parse_public_key() and pk_copy_public_from_psa() only creates public keys, and IIRC pk_copy_from_psa() can create both.)
Create a new public function `mbedtls_pk_get_key_type()` that takes as input a `pk_context` and returns a PSA key type, namely one of: - `PSA_KEY_TYPE_RSA_KEY_PAIR` - `PSA_KEY_TYPE_RSA_PUBLIC_KEY` - `PSA_KEY_TYPE_ECC_KEY_PAIR(curve)` - `PSA_KEY_TYPE_ECC_PUBLIC_KEY(curve)` - `PSA_KEY_TYPE_NONE` (if the context is not populated) Test plan: - the input context can be unpopulated, or populated with `pk_wrap_psa()`, `pk_parse_key()` or `pk_parse_public_key()`, `pk_copy_from_psa()` or `pk_copy_public_from_psa()` - for each input case we want exercise all possible outputs (ideally with two different curves for ECC keys). (Note that `wrap_psa` only creates key pairs, like `pk_parse_key()`; conversely, `pk_parse_public_key()` and `pk_copy_public_from_psa()` only creates public keys, and IIRC `pk_copy_from_psa()` can create both.)
mpg commented 2025-10-15 03:19:37 -05:00 (Migrated from github.com)

Note: currently the documentation of the various parsing functions recommend using mbedtls_pk_can_do_psa() if you want to check the key's type after parsing. We should update that to recommend using pk_get_key_type() once it's added.

Note: currently the documentation of the various parsing functions recommend using `mbedtls_pk_can_do_psa()` if you want to check the key's type after parsing. We should update that to recommend using `pk_get_key_type()` once it's added.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-Mbed-TLS/TF-PSA-Crypto#509
No description provided.