blob: e37f50ff49c5cbda68cee0dee45c633beea69929 [file] [log] [blame] [view]
Gilles Peskine7ee4cc32023-11-28 15:49:57 +01001Bridges between legacy and PSA crypto APIs
2==========================================
3
4## Introduction
5
6### Goal of this document
7
8This document explores the needs of applications that use both Mbed TLS legacy crypto interfaces and PSA crypto interfaces. Based on [requirements](#requirements), we [analyze gaps](#gap-analysis) and [API design](#api-design).
9
10This is a design document. The target audience is library maintainers. See the companion document [“Transitioning to the PSA API”](../../psa-transition.md) for a user focus on the same topic.
11
12### Keywords
13
14* [TODO] A part of the analysis that isn't finished.
Gilles Peskine8f1307a2023-12-25 21:42:23 +010015* [OPEN] Open question: a specific aspect of the design where there are several plausible decisions.
Gilles Peskine7ee4cc32023-11-28 15:49:57 +010016* [ACTION] A finalized part of the design that will need to be carried out.
17
18### Context
19
20Mbed TLS 3.x supports two cryptographic APIs:
21
22* The legacy API `mbedtls_xxx` is inherited from PolarSSL.
23* The PSA API `psa_xxx` was introduced in Mbed TLS 2.17.
24
25Mbed TLS is gradually shifting from the legacy API to the PSA API. Mbed TLS 4.0 will be the first version where the PSA API is considered the main API, and large parts of the legacy API will be removed.
26
27In Mbed TLS 4.0, the cryptography will be provided by a separate project [TF-PSA-Crypto](https://github.com/Mbed-TLS/TF-PSA-Crypto). For simplicity, in this document, we just refer to the whole as “Mbed TLS”.
28
29### Document history
30
31This document was originally written when preparing Mbed TLS 3.6. Mbed TLS 3.6 includes both PSA and legacy APIs covering largely overlapping ground. Many legacy APIs will be removed in Mbed TLS 4.0.
32
33## Requirements
34
35### Why mix APIs?
36
37There is functionality that is tied to one API and is not directly available in the other API:
38
39* Only PSA fully supports PSA accelerators and secure element integration.
40* Only PSA supports isolating cryptographic material in a secure service.
41* The legacy API has features that are not present (yet) in PSA, notably parsing and formatting asymmetric keys.
42
43The legacy API can partially leverage PSA features via `MBEDTLS_USE_PSA_CRYPTO`, but this has limited scope.
44
45In addition, many applications cannot be migrated in a single go. For large projects, it is impractical to rewrite a significant part of the code all at once. (For example, Mbed TLS itself will have taken more than 6 years to transition.) Projects that use one or more library in addition to Mbed TLS must follow the evolution of these libraries, each of which might have its own pace.
46
47### Where mixing happens
48
49Mbed TLS can be, and normally is, built with support for both APIs. Therefore no special effort is necessary to allow an application to use both APIs.
50
51Special effort is necessary to use both APIs as part of the implementation of the same feature. From an informal analysis of typical application requirements, we identify four parts of the use of cryptography which can be provided by different APIs:
52
53* Metadata manipulation: parsing and producing encrypted or signed files, finding mutually supported algorithms in a network protocol negotiation, etc.
54* Key management: parsing, generating, deriving and formatting cryptographic keys.
55* Data manipulation other than keys. In practice, most data formats within the scope of the legacy crypto APIs are trivial (ciphertexts, hashes, MACs, shared secrets). The one exception is ECDSA signatures.
56* Cryptographic operations: hash, sign, encrypt, etc.
57
58From this, we deduce the following requirements:
59
60* Convert between PSA and legacy metadata.
61* Creating a key with the legacy API and consuming it in the PSA API.
62* Creating a key with the PSA API and consuming it in the legacy API.
63* Manipulating data formats, other than keys, where the PSA API is lacking.
64
65### Scope limitations
66
67The goal of this document is to bridge the legacy API and the PSA API. The goal is not to provide a PSA way to do everything that is currently possible with the legacy API. The PSA API is less flexible in some regards, and extending it is out of scope in the present study.
68
69With respect to the legacy API, we do not consider functionality of low-level modules for individual algorithms. Our focus is on applications that use high-level legacy crypto modules (md, cipher, pk) and need to combine that with uses of the PSA APIs.
70
71## Gap analysis
72
Gilles Peskine8f1307a2023-12-25 21:42:23 +010073The document [“Transitioning to the PSA API”](../../psa-transition.md) enumerates the public header files in Mbed TLS 3.4 and the API elements (especially enums and functions) that they provide, listing PSA equivalents where they exist. There are gaps in two cases:
74
75* Where the PSA equivalents do not provide the same functionality. A typical example is parsing and formatting asymmetric keys.
76* To convert between data representations used by legacy APIs and data representations used by PSA APIs.
77
Gilles Peskine7ee4cc32023-11-28 15:49:57 +010078Based on “[Where mixing happens](#where-mixing-happens)”, we focus the gap analysis on two topics: metadata and keys. This chapter explores the gaps in each family of cryptographic mechanisms.
79
80### Generic metadata gaps
81
82#### Need for error code conversion
83
Gilles Peskine8f1307a2023-12-25 21:42:23 +010084[OPEN] Do we need public functions to convert between `MBEDTLS_ERR_xxx` error codes and `PSA_ERROR_xxx` error codes? We have such functions for internal use.
Gilles Peskine7ee4cc32023-11-28 15:49:57 +010085
86### Hash gap analysis
87
88Hashes do not involve keys, and involves no nontrivial data format. Therefore the only gap is with metadata, namely specifying a hash algorithm.
89
90Hashes are often used as building blocks for other mechanisms (HMAC, signatures, key derivation, etc.). Therefore metadata about hashes is relevant not only when calculating hashes, but also when performing many other cryptographic operations.
91
92Gap: functions to convert between `psa_algorithm_t` hash algorithms and `mbedtls_md_type_t`. Such functions exist in Mbed TLS 3.5 (`mbedtls_md_psa_alg_from_type`, `mbedtls_md_type_from_psa_alg`) but they are declared only in private headers.
93
94### MAC gap analysis
95
96[TODO]
97
98### Cipher and AEAD gap analysis
99
100[TODO]
101
102### Key derivation gap analysis
103
104[TODO]
105
106### Random generation gap analysis
107
108[TODO]
109
110### Asymmetric cryptography gap analysis
111
Gilles Peskine8f1307a2023-12-25 21:42:23 +0100112#### Asymmetric cryptography metadata
113
Gilles Peskine93cdb772024-01-02 13:15:04 +0100114The legacy API only has generic support for two key types: RSA and ECC, via the pk module. ECC keys can also be further classified according to their curve. The legacy API also supports DHM (Diffie-Hellman-Merkle = FFDH: finite-field Diffie-Hellman) keys, but those are not integrated in the pk module.
Gilles Peskine8f1307a2023-12-25 21:42:23 +0100115
116An RSA or ECC key can potentially be used for different algorithms in the scope of the pk module:
117
118* RSA: PKCS#1v1.5 signature, PSS signature, PKCS#1v1.5 encryption, OAEP encryption.
Gilles Peskine93cdb772024-01-02 13:15:04 +0100119* ECC: ECDSA signature (randomized or deterministic), ECDH key agreement (via `mbedtls_pk_ec`).
Gilles Peskine8f1307a2023-12-25 21:42:23 +0100120
121ECC keys are also involved in EC-JPAKE, but this happens internally: the EC-JPAKE interface only needs one piece of metadata, namely, to identify a curve.
122
123Since there is no algorithm that can be used with multiple types, and PSA keys have a policy that (for the most part) limits them to one algorithm, there does not seem to be a need to convert between legacy and PSA asymmetric key types on their own. The useful metadata conversions are:
124
125* Selecting an **elliptic curve**.
126
127 This means converting between an `mbedtls_ecp_group_id` and a pair of `{psa_ecc_family_t; size_t}`.
128
Gilles Peskine5a64c422024-01-17 10:09:16 +0100129 This is fulfilled by `mbedtls_ecc_group_to_psa` and `mbedtls_ecc_group_from_psa`, which were introduced into the public API between Mbed TLS 3.5 and 3.6 ([#8664](https://github.com/Mbed-TLS/mbedtls/pull/8664)).
Gilles Peskine8f1307a2023-12-25 21:42:23 +0100130
131* Selecting A **DHM group**.
132
133 PSA only supports predefined groups, whereas legacy only supports ad hoc groups. An existing application referring to `MBEDTLS_DHM_RFC7919_FFDHExxx` values would need to refer to `PSA_DH_FAMILY_RFC7919`; an existing application using arbitrary groups cannot migrate to PSA.
134
135* Simultaneously supporting **a key type and an algorithm**.
136
137 On the legacy side, this is an `mbedtls_pk_type_t` value and more. For ECDSA, the choice between randomized and deterministic is made at compile time. For RSA, the choice of encryption or signature algorithm is made either by configuring the underlying `mbedtls_rsa_context` or when calling the operation function.
138
139 On the PSA side, this is a `psa_key_type_t` value and an algorithm which is normally encoded as policy information in a `psa_key_attributes_t`. The algorithm is also needed in its own right when calling operation functions.
140
141#### Using a legacy key pair or public key with PSA
142
143There are several scenarios where an application has a legacy key pair or public key (`mbedtls_pk_context`) and needs to create a PSA key object (`psa_key_id_t`).
144
Gilles Peskine93cdb772024-01-02 13:15:04 +0100145Reasons for first creating a legacy key object, where it's impossible or impractical to directly create a PSA key:
Gilles Peskine8f1307a2023-12-25 21:42:23 +0100146
147* A very common case where the input is a legacy key object is parsing. PSA does not (yet) have an equivalent of the `mbedtls_pk_parse_xxx` functions.
148* The PSA key creation interface is less flexible in some cases. In particular, PSA RSA key generation does not (yet) allow choosing the public exponent.
149* The pk object may be created by a part of the application (or a third-party library) that hasn't been migrated to the PSA API yet.
150
151Reasons for needing a PSA key object:
152
Gilles Peskinea7226a12024-01-02 13:15:14 +0100153* Using the key with third-party interface that takes a PSA key identifier as input. (Mbed TLS itself has a few TLS functions that take PSA key identifiers, but as of Mbed TLS 3.5, it is always possible to use a legacy key instead.)
Gilles Peskine8f1307a2023-12-25 21:42:23 +0100154* Benefiting from a PSA accelerator, or from PSA's world separation, even without `MBEDTLS_USE_PSA_CRYPTO`. (Not a priority scenario: we generally expect people to activate `MBEDTLS_USE_PSA_CRYPTO` at an early stage of their migration to PSA.)
155
156Gap: a way to create a PSA key object from an `mbedtls_pk_context`. This partially exists in the form of `mbedtls_pk_wrap_as_opaque`, but it is not fully satisfactory, for reasons that are detailed in “[API to create a PSA key from a PK context](#api-to-create-a-psa-key-from-a-pk-context)” below.
157
158#### Using a PSA key as a PK context
159
Gilles Peskine93cdb772024-01-02 13:15:04 +0100160There are several scenarios where an application has a PSA key and needs to use it through an interface that wants an `mbedtls_pk_context` object. Typically, there is an existing key in the PSA key store (possibly in a secure element and non-exportable), and the key needs to be used in an interface that requires a `mbedtls_pk_context *` input, such as Mbed TLS's X.509 and TLS APIs or a similar third-party interface, or the `mbedtls_pk_write_xxx` interfaces which do not (yet) have PSA equivalents.
Gilles Peskine8f1307a2023-12-25 21:42:23 +0100161
162There is a function `mbedtls_pk_setup_opaque` that mostly does this. However, it has several limitations:
163
164* It creates a PK key of type `MBEDTLS_PK_OPAQUE` that wraps the PSA key. This is good enough in some scenarios, but not others. For example, it's ok for pkwrite, because we've upgraded the pkwrite code to handle `MBEDTLS_PK_OPAQUE`. That doesn't help users of third-party libraries that haven't yet been upgraded.
165* It ties the lifetime of the PK object to the PSA key, which is error-prone: if the PSA key is destroyed but the PK object isn't, there is no way to reliably detect any subsequent misuse of the PK object.
Gilles Peskine32294042024-01-17 10:07:55 +0100166* It is only available under `MBEDTLS_USE_PSA_CRYPTO`. This is not a priority concern, since we generally expect people to activate `MBEDTLS_USE_PSA_CRYPTO` at an early stage of their migration to PSA. However, this function is useful to use specific PSA keys in X.509/TLS regardless of whether X.509/TLS use the PSA API for all cryptographic operations, so this is a wart in the current API.
Gilles Peskine8f1307a2023-12-25 21:42:23 +0100167
Gilles Peskine93cdb772024-01-02 13:15:04 +0100168It therefore appears that we need two ways to convert a PSA key to PK:
169
170* Wrapping, which is what `mbedtls_pk_setup_opaque` does. This works for any PSA key but is limited by the key's lifetime and creates a PK object with limited functionality.
171* Copying, which requires a new function. This requires an exportable key but creates a fully independent, fully functional PK object.
172
Gilles Peskine8f1307a2023-12-25 21:42:23 +0100173Gap: a way to copy a PSA key into a PK context. This can only be expected to work if the PSA key is exportable.
174
175[OPEN] Is `mbedtls_pk_setup_opaque` ok or do we want to tweak it?
176
177#### Signature formats
178
179The pk module uses signature formats intended for X.509. The PSA module uses the simplest sensible signature format.
180
181* For RSA, the formats are the same.
182* For ECDSA, PSA uses a fixed-size concatenation of (r,s), whereas X.509 and pk use an ASN.1 DER encoding of the sequence (r,s).
183
184Gap: We need APIs to convert between these two formats. The conversion code already exists under the hood, but it's in pieces that can't be called directly.
185
186There is a design choice here: do we provide conversions functions for ECDSA specifically, or do we provide conversion functions that take an algorithm as argument and just happen to be a no-op with RSA? One factor is plausible extensions. These conversions functions will remain useful in Mbed TLS 4.x and perhaps beyond. We will at least add EdDSA support, and its signature encoding is the fixed-size concatenation (r,s) even in X.509. We may well also add support for some post-quantum signatures, and their concrete format is still uncertain.
187
Gilles Peskine93cdb772024-01-02 13:15:04 +0100188Given the uncertainty, it would be nice to provide a sufficiently generic interface to convert between the PSA and the pk signature format, parametrized by the algorithm. However, it is difficult to predict exactly what parameters are needed. For example, converting from an ASN.1 ECDSA signature to (r,s) requires the knowledge of the curve, or at least the curve's size. Therefore we are not going to add a generic function at this stage.
Gilles Peskine8f1307a2023-12-25 21:42:23 +0100189
Gilles Peskinef80dcc52024-01-02 13:15:47 +0100190For ECDSA, there are two plausible APIs: follow the ASN.1/X.509 write/parse APIs, or present an ordinary input/output API. The ASN.1 APIs are the way they are to accommodate nested TLV structures. But ECDSA signatures do not appear nested in TLV structures in either TLS (there's just a signature field) or X.509 (the signature is inside a BITSTRING, not directly in a SEQUENCE). So there does not seem to be a need for an ASN.1-like API for the ASN.1 format, just the format conversion itself in a buffer that just contains the signature.
191
Gilles Peskine8f1307a2023-12-25 21:42:23 +0100192#### Asymmetric cryptography TODO
193
194[TODO] Other gaps?
Gilles Peskine7ee4cc32023-11-28 15:49:57 +0100195
196## New APIs
197
198This section presents new APIs to implement based on the [gap analysis](#gap-analysis).
199
Gilles Peskine8f1307a2023-12-25 21:42:23 +0100200### General notes
201
202Each action to implement a function entails:
203
204* Implement the library function.
205* Document it precisely, including error conditions.
206* Unit-test it.
207* Mention it where relevant in the PSA transition guide.
208
Gilles Peskine7ee4cc32023-11-28 15:49:57 +0100209### Hash APIs
210
211Based on the [gap analysis](#hash-gap-analysis):
212
Gilles Peskine8f1307a2023-12-25 21:42:23 +0100213[ACTION] [#8340](https://github.com/Mbed-TLS/mbedtls/issues/8340) Move `mbedtls_md_psa_alg_from_type` and `mbedtls_md_type_from_psa_alg` from `library/md_psa.h` to `include/mbedtls/md.h`.
Gilles Peskine7ee4cc32023-11-28 15:49:57 +0100214
215### MAC APIs
216
217[TODO]
218
219### Cipher and AEAD APIs
220
221[TODO]
222
223### Key derivation APIs
224
225[TODO]
226
227### Random generation APIs
228
229[TODO]
230
231### Asymmetric cryptography APIs
232
Gilles Peskine8f1307a2023-12-25 21:42:23 +0100233#### Asymmetric cryptography metadata APIs
234
235Based on the [gap analysis](#asymmetric-cryptography-metadata):
236
237* No further work is needed about RSA specifically. The amount of metadata other than hashes is sufficiently small to be handled in ad hoc ways in applications, and hashes have [their own conversions](#hash-apis).
238* No further work is needed about ECC specifically. We have just added adequate functions.
239* No further work is needed about DHM specifically. There is no good way to translate the relevant information.
240* [OPEN] Is there a decent way to convert between `mbedtls_pk_type_t` plus extra information, and `psa_key_type_t` plus policy information? The two APIs are different in crucial ways, with different splits between key type, policy information and operation algorithm.
241
242#### API to create a PSA key from a PK context
243
244Based on the [gap analysis](#using-a-legacy-key-pair-or-public-key-with-psa):
245
246Given an `mbedtls_pk_context`, we want a function that creates a PSA key with the same key material and algorithm. “Same key material” is straightforward, but “same algorithm” is not, because a PK context has incomplete algorithm information. For example, there is no way to distinguish between an RSA key that is intended for signature or for encryption. Between algorithms of the same nature, there is no way to distinguish a key intended for PKCS#1v1.5 and one intended for PKCS#1v2.1 (OAEP/PSS): this is indicated in the underlying RSA context, but the indication there is only a default that can be overridden by calling `mbedtls_pk_{sign,verify}_ext`. Also there is no way to distinguish between `PSA_ALG_RSA_PKCS1V15_SIGN(hash_alg)` and `PSA_ALG_RSA_PKCS1V15_SIGN_RAW`: in the legacy interface, this is only determined when actually doing a signature/verification operation. Therefore the function that creates the PSA key needs extra information to indicate which algorithm to put in the key's policy.
247
248When creating a PSA key, apart from the key material, the key is determined by attributes, which fall under three categories:
249
250* Type and size. These are directly related to the key material and can be deduced from it if the key material is in a structured format, which is the case with an `mbedtls_pk_context` input.
251* Policy. This includes the chosen algorithm, which as discussed above cannot be fully deduced from the `mbedtls_pk_context` object. Just choosing one algorithm is problematic because it doesn't allow implementation-specific extensions, such as Mbed TLS's enrollment algorithm. The intended usage flags cannot be deduced from the PK context either, but the conversion function could sensibly just enable all the relevant usage flags. Users who want a more restrictive usage can call `psa_copy_key` and `psa_destroy_key` to obtain a PSA key object with a more restrictive usage.
252* Persistence and location. This is completely orthogonal to the information from the `mbedtls_pk_context` object. It is convenient, but not necessary, for the conversion function to allow customizing these aspects. If it doesn't, users can call the conversion function and then call `psa_copy_key` and `psa_destroy_key` to move the key to its desired location.
253
254To allow the full flexibility around policies, and make the creation of a persistent key more convenient, the conversion function shall take a `const psa_key_attributes_t *` input, like all other functions that create a PSA key. In addition, there shall be a helper function to populate a `psa_key_attributes_t` with a sensible default. This lets the caller choose a more flexible, or just different usage policy, unlike the default-then-copy approach which only allows restricting the policy.
255
256This is close to the existing function `mbedtls_pk_wrap_as_opaque`, but does not bake in the implementation-specific consideration that a PSA key has exactly two algorithms, and also allows the caller to benefit from default for the policy in more cases.
257
258[ACTION] Implement `mbedtls_pk_get_psa_attributes` and `mbedtls_pk_import_into_psa` as described below. These functions are available whenever `MBEDTLS_PK_C` and `MBEDTLS_PSA_CRYPTO_CLIENT` are both defined. Deprecate `mbedtls_pk_wrap_as_opaque`.
259
260```
261int mbedtls_pk_get_psa_attributes(const mbedtls_pk_context *pk,
262 psa_key_attributes_t *attributes);
263int mbedtls_pk_import_into_psa(const mbedtls_pk_context *pk,
264 const psa_key_attributes_t *attributes,
265 mbedtls_svc_key_id_t *key_id);
266```
267
268* `mbedtls_pk_get_psa_attributes` does not change the id/lifetime fields of the attributes (which indicate a volatile key by default).
269* `mbedtls_pk_get_psa_attributes` sets the type and size based on what's in the pk context.
270 * The key type is a key pair if the context contains a private key, and a public key if the context only contains a public key.
271* `mbedtls_pk_get_psa_attributes` sets all the potentially applicable usage flags: `EXPORT`, `COPY`; `VERIFY_HASH | VERIFY_MESSAGE` or `ENCRYPT` as applicable for both public keys and key pairs; `SIGN` or `DECRYPT` as applicable for a key pair.
272* [OPEN] What is the default algorithm for `mbedtls_pk_get_psa_attributes`? Suggestion: assume signature by default. For RSA, either `PSA_RSA_PKCS1_V15_SIGN(PSA_ALG_ANY_HASH)` or `PSA_ALG_RSA_PSS(hash_alg)` depending on the RSA context's padding mode. For ECC, `PSA_ALG_DETERMINISTIC_ECDSA` if `MBEDTLS_ECDSA_DETERMINISTIC` is enabled and `PSA_ALG_ECDSA` otherwise.
Gilles Peskine93cdb772024-01-02 13:15:04 +0100273* [OPEN] Or does `mbedtls_pk_get_psa_attributes` need an extra argument that conveys some kind of policy for RSA keys and, independently, some kind of policy for ECC keys?
Gilles Peskine8f1307a2023-12-25 21:42:23 +0100274* `mbedtls_pk_import_into_psa` checks that the type field in the attributes is consistent with the content of the `mbedtls_pk_context` object (RSA/ECC, and availability of the private key).
275 * The key type can be a public key even if the private key is available.
276* `mbedtls_pk_import_into_psa` does not need to check the bit-size in the attributes: `psa_import_key` will do enough checks.
277* `mbedtls_pk_import_into_psa` does not check that the policy in the attributes is sensible. That's on the user.
278
279#### API to copy a PSA key to a PK context
280
281Based on the [gap analysis](#using-a-psa-key-as-a-pk-context):
282
283[ACTION] Implement `mbedtls_pk_copy_from_psa` as described below.
284
285```
286int mbedtls_pk_copy_from_psa(mbedtls_svc_key_id_t key_id,
287 mbedtls_pk_context *pk);
288```
289
290* `pk` must be initialized, but not set up.
291* It is an error if the key is neither a key pair nor a public key.
292* It is an error if the key is not exportable.
Gilles Peskine89ca6c72024-01-17 10:08:56 +0100293* The resulting pk object has a transparent type, not `MBEDTLS_PK_OPAQUE`. That's `MBEDTLS_PK_RSA` for RSA keys (since pk objects don't use `MBEDTLS_PK_RSASSA_PSS` as a type), and `MBEDTLS_PK_ECKEY` for ECC keys (following the example of pkparse).
Gilles Peskine8f1307a2023-12-25 21:42:23 +0100294* Once this function returns, the pk object is completely independent of the PSA key.
295* Calling `mbedtls_pk_sign`, `mbedtls_pk_verify`, `mbedtls_pk_encrypt`, `mbedtls_pk_decrypt` on the resulting pk context will perform an algorithm that is compatible with the PSA key's primary algorithm policy (`psa_get_key_algorithm`), but with no restriction on the hash (as if the policy had `PSA_ALG_ANY_HASH` instead of a specific hash, and with `PSA_ALG_RSA_PKCS1V15_SIGN_RAW` merged with `PSA_ALG_RSA_PKCS1V15_SIGN(hash_alg)`). For ECDSA, the choice of deterministic vs randomized will be based on the compile-time setting `MBEDTLS_ECDSA_DETERMINISTIC`, like `mbedtls_pk_sign` today.
Gilles Peskine9fe1c692024-01-02 13:16:31 +0100296 * The primary intent of this requirement is to allow an application to switch to PSA for creating the key material (for example to benefit from a PSA accelerator driver, or to start using a secure element), without modifying the code that consumes the key. For RSA keys, the PSA primary algorithm policy is how one conveys the same information as RSA key padding information in the legacy API. [ACTION] Convey this in the documentation.
Gilles Peskine8f1307a2023-12-25 21:42:23 +0100297 * [OPEN] How do we distinguish between signature-only and encryption-only RSA keys? Do we just allow both (e.g. a PSS key gets generalized into a PSS/OAEP key)?
298 * [OPEN] What about `mbedtls_pk_sign_ext` and `mbedtls_pk_verify_ext`?
299
300[OPEN] Should there be a way to use a different algorithm? This can be resolved by `psa_copy_key` on the input to tweak the policy if needed.
301
302#### API to create a PK object that wraps a PSA key
303
304Based on the [gap analysis](#using-a-psa-key-as-a-pk-context):
305
306[ACTION] Clarify the documentation of `mbedtls_pk_setup_opaque` regarding which algorithms the resulting key will perform with `mbedtls_pk_sign`, `mbedtls_pk_verify`, `mbedtls_pk_encrypt`, `mbedtls_pk_decrypt`.
307
Gilles Peskine32294042024-01-17 10:07:55 +0100308[ACTION] Provide `mbedtls_pk_setup_opaque` whenever `MBEDTLS_PSA_CRYPTO_CLIENT` is enabled, not just when `MBEDTLS_USE_PSA_CRYPTO` is enabled. This is nice-to-have, not critical. Update `use-psa-crypto.md` accordingly.
309
Gilles Peskine8f1307a2023-12-25 21:42:23 +0100310[OPEN] What about `mbedtls_pk_sign_ext` and `mbedtls_pk_verify_ext`?
311
312#### API to convert between signature formats
313
314Based on the [gap analysis](#signature-formats):
315
316[ACTION] [#7765](https://github.com/Mbed-TLS/mbedtls/issues/7765) Implement `mbedtls_ecdsa_raw_to_der` and `mbedtls_ecdsa_der_to_raw` as described below.
317
318```
319int mbedtls_ecdsa_raw_to_der(const unsigned char *raw, size_t raw_len,
320 unsigned char *der, size_t der_size, size_t *der_len);
321int mbedtls_ecdsa_der_to_raw(const unsigned char *der, size_t der_len,
322 unsigned char *raw, size_t raw_size, size_t *raw_len,
323 size_t bits);
324```
325
326* These functions convert between the signature format used by `mbedtls_pk_{sign,verify}{,_ext}` and the signature format used by `psa_{sign,verify}_{hash,message}`.
327* The input and output buffers can overlap.