1*62c56f98SSadaf EbrahimiConditional inclusion of cryptographic mechanism through the PSA API in Mbed TLS 2*62c56f98SSadaf Ebrahimi================================================================================ 3*62c56f98SSadaf Ebrahimi 4*62c56f98SSadaf EbrahimiThis document is a proposed interface for deciding at build time which cryptographic mechanisms to include in the PSA Cryptography interface. 5*62c56f98SSadaf Ebrahimi 6*62c56f98SSadaf EbrahimiThis is currently a proposal for Mbed TLS. It is not currently on track for standardization in PSA. 7*62c56f98SSadaf Ebrahimi 8*62c56f98SSadaf Ebrahimi## Introduction 9*62c56f98SSadaf Ebrahimi 10*62c56f98SSadaf Ebrahimi### Purpose of this specification 11*62c56f98SSadaf Ebrahimi 12*62c56f98SSadaf EbrahimiThe [PSA Cryptography API specification](https://armmbed.github.io/mbed-crypto/psa/#application-programming-interface) specifies the interface between a PSA Cryptography implementation and an application. The interface defines a number of categories of cryptographic algorithms (hashes, MAC, signatures, etc.). In each category, a typical implementation offers many algorithms (e.g. for signatures: RSA-PKCS#1v1.5, RSA-PSS, ECDSA). When building the implementation for a specific use case, it is often desirable to include only a subset of the available cryptographic mechanisms, primarily in order to reduce the code footprint of the compiled system. 13*62c56f98SSadaf Ebrahimi 14*62c56f98SSadaf EbrahimiThe present document proposes a way for an application using the PSA cryptography interface to declare which mechanisms it requires. 15*62c56f98SSadaf Ebrahimi 16*62c56f98SSadaf Ebrahimi### Conditional inclusion of legacy cryptography modules 17*62c56f98SSadaf Ebrahimi 18*62c56f98SSadaf EbrahimiMbed TLS offers a way to select which cryptographic mechanisms are included in a build through its configuration file (`mbedtls_config.h`). This mechanism is based on two main sets of symbols: `MBEDTLS_xxx_C` controls the availability of the mechanism to the application, and `MBEDTLS_xxx_ALT` controls the availability of an alternative implementation, so the software implementation is only included if `MBEDTLS_xxx_C` is defined but not `MBEDTLS_xxx_ALT`. 19*62c56f98SSadaf Ebrahimi 20*62c56f98SSadaf Ebrahimi### PSA evolution 21*62c56f98SSadaf Ebrahimi 22*62c56f98SSadaf EbrahimiIn the PSA cryptography interface, the **core** (built-in implementations of cryptographic mechanisms) can be augmented with drivers. **Transparent drivers** replace the built-in implementation of a cryptographic mechanism (or, with **fallback**, the built-in implementation is tried if the driver only has partial support for the mechanism). **Opaque drivers** implement cryptographic mechanisms on keys which are stored in a separate domain such as a secure element, for which the core only does key management and dispatch using wrapped key blobs or key identifiers. 23*62c56f98SSadaf Ebrahimi 24*62c56f98SSadaf EbrahimiThe current model is difficult to adapt to the PSA interface for several reasons. The `MBEDTLS_xxx_ALT` symbols are somewhat inconsistent, and in particular do not work well for asymmetric cryptography. For example, many parts of the ECC code have no `MBEDTLS_xxx_ALT` symbol, so a platform with ECC acceleration that can perform all ECDSA and ECDH operations in the accelerator would still embark the `bignum` module and large parts of the `ecp_curves`, `ecp` and `ecdsa` modules. Also the availability of a transparent driver for a mechanism does not translate directly to `MBEDTLS_xxx` symbols. 25*62c56f98SSadaf Ebrahimi 26*62c56f98SSadaf Ebrahimi### Requirements 27*62c56f98SSadaf Ebrahimi 28*62c56f98SSadaf Ebrahimi[Req.interface] The application can declare which cryptographic mechanisms it needs. 29*62c56f98SSadaf Ebrahimi 30*62c56f98SSadaf Ebrahimi[Req.inclusion] If the application does not require a mechanism, a suitably configured Mbed TLS build must not include it. The granularity of mechanisms must work for typical use cases and has [acceptable limitations](#acceptable-limitations). 31*62c56f98SSadaf Ebrahimi 32*62c56f98SSadaf Ebrahimi[Req.drivers] If a PSA driver is available in the build, a suitably configured Mbed TLS build must not include the corresponding software code (unless a software fallback is needed). 33*62c56f98SSadaf Ebrahimi 34*62c56f98SSadaf Ebrahimi[Req.c] The configuration mechanism consists of C preprocessor definitions, and the build does not require tools other than a C compiler. This is necessary to allow building an application and Mbed TLS in development environments that do not allow third-party tools. 35*62c56f98SSadaf Ebrahimi 36*62c56f98SSadaf Ebrahimi[Req.adaptability] The implementation of the mechanism must be adaptable with future evolution of the PSA cryptography specifications and Mbed TLS. Therefore the interface must remain sufficiently simple and abstract. 37*62c56f98SSadaf Ebrahimi 38*62c56f98SSadaf Ebrahimi### Acceptable limitations 39*62c56f98SSadaf Ebrahimi 40*62c56f98SSadaf Ebrahimi[Limitation.matrix] If a mechanism is defined by a combination of algorithms and key types, for example a block cipher mode (CBC, CTR, CFB, …) and a block permutation (AES, CAMELLIA, ARIA, …), there is no requirement to include only specific combinations. 41*62c56f98SSadaf Ebrahimi 42*62c56f98SSadaf Ebrahimi[Limitation.direction] For mechanisms that have multiple directions (for example encrypt/decrypt, sign/verify), there is no requirement to include only one direction. 43*62c56f98SSadaf Ebrahimi 44*62c56f98SSadaf Ebrahimi[Limitation.size] There is no requirement to include only support for certain key sizes. 45*62c56f98SSadaf Ebrahimi 46*62c56f98SSadaf Ebrahimi[Limitation.multipart] Where there are multiple ways to perform an operation, for example single-part and multi-part, there is no mechanism to select only one or a subset of the possible ways. 47*62c56f98SSadaf Ebrahimi 48*62c56f98SSadaf Ebrahimi## Interface 49*62c56f98SSadaf Ebrahimi 50*62c56f98SSadaf Ebrahimi### PSA Crypto configuration file 51*62c56f98SSadaf Ebrahimi 52*62c56f98SSadaf EbrahimiThe PSA Crypto configuration file `psa/crypto_config.h` defines a series of symbols of the form `PSA_WANT_xxx` where `xxx` describes the feature that the symbol enables. The symbols are documented in the section [“PSA Crypto configuration symbols”](#psa-crypto-configuration-symbols) below. 53*62c56f98SSadaf Ebrahimi 54*62c56f98SSadaf EbrahimiThe symbol `MBEDTLS_PSA_CRYPTO_CONFIG` in `mbedtls/mbedtls_config.h` determines whether `psa/crypto_config.h` is used. 55*62c56f98SSadaf Ebrahimi 56*62c56f98SSadaf Ebrahimi* If `MBEDTLS_PSA_CRYPTO_CONFIG` is unset, which is the default at least in Mbed TLS 2.x versions, things are as they are today: the PSA subsystem includes generic code unconditionally, and includes support for specific mechanisms conditionally based on the existing `MBEDTLS_xxx_` symbols. 57*62c56f98SSadaf Ebrahimi* If `MBEDTLS_PSA_CRYPTO_CONFIG` is set, the necessary software implementations of cryptographic algorithms are included based on both the content of the PSA Crypto configuration file and the Mbed TLS configuration file. For example, the code in `aes.c` is enabled if either `mbedtls/mbedtls_config.h` contains `MBEDTLS_AES_C` or `psa/crypto_config.h` contains `PSA_WANT_KEY_TYPE_AES`. 58*62c56f98SSadaf Ebrahimi 59*62c56f98SSadaf Ebrahimi### PSA Crypto configuration symbols 60*62c56f98SSadaf Ebrahimi 61*62c56f98SSadaf Ebrahimi#### Configuration symbol syntax 62*62c56f98SSadaf Ebrahimi 63*62c56f98SSadaf EbrahimiA PSA Crypto configuration symbol is a C preprocessor symbol whose name starts with `PSA_WANT_`. 64*62c56f98SSadaf Ebrahimi 65*62c56f98SSadaf Ebrahimi* If the symbol is not defined, the corresponding feature is not included. 66*62c56f98SSadaf Ebrahimi* If the symbol is defined to a preprocessor expression with the value `1`, the corresponding feature is included. 67*62c56f98SSadaf Ebrahimi* If the symbol is defined with a different value, the behavior is currently undefined and reserved for future use. 68*62c56f98SSadaf Ebrahimi 69*62c56f98SSadaf Ebrahimi#### Configuration symbol usage 70*62c56f98SSadaf Ebrahimi 71*62c56f98SSadaf EbrahimiThe presence of a symbol `PSA_WANT_xxx` in the Mbed TLS configuration determines whether a feature is available through the PSA API. These symbols should be used in any place that requires conditional compilation based on the availability of a cryptographic mechanism through the PSA API, including: 72*62c56f98SSadaf Ebrahimi 73*62c56f98SSadaf Ebrahimi* In Mbed TLS test code. 74*62c56f98SSadaf Ebrahimi* In Mbed TLS library code using `MBEDTLS_USE_PSA_CRYPTO`, for example in TLS to determine which cipher suites to enable. 75*62c56f98SSadaf Ebrahimi* In application code that provides additional features based on cryptographic capabilities, for example additional key parsing and formatting functions, or cipher suite availability for network protocols. 76*62c56f98SSadaf Ebrahimi 77*62c56f98SSadaf Ebrahimi#### Configuration symbol semantics 78*62c56f98SSadaf Ebrahimi 79*62c56f98SSadaf EbrahimiIf a feature is not requested for inclusion in the PSA Crypto configuration file, it may still be included in the build, either because the feature has been requested in some other way, or because the library does not support the exclusion of this feature. Mbed TLS should make a best effort to support the exclusion of all features, but in some cases this may be judged too much effort for too little benefit. 80*62c56f98SSadaf Ebrahimi 81*62c56f98SSadaf Ebrahimi#### Configuration symbols for key types 82*62c56f98SSadaf Ebrahimi 83*62c56f98SSadaf EbrahimiFor most constant or constructor macros of the form `PSA_KEY_TYPE_xxx`, the symbol **`PSA_WANT_KEY_TYPE_xxx`** indicates that support for this key type is desired. 84*62c56f98SSadaf Ebrahimi 85*62c56f98SSadaf EbrahimiAs an exception, starting in Mbed TLS 3.5.0, for `KEY_PAIR` types (that is, private keys for asymmetric cryptography), the feature selection is more fine-grained, with an additional suffix: 86*62c56f98SSadaf Ebrahimi* `PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_BASIC` enables basic support for the key type, and in particular support for operations with a key of that type for enabled algorithms. This is automatically enabled if any of the other `PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy` options is enabled. 87*62c56f98SSadaf Ebrahimi* `PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_IMPORT` enables support for `psa_import_key` to import a key of that type. 88*62c56f98SSadaf Ebrahimi* `PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_GENERATE` enables support for `psa_generate_key` to randomly generate a key of that type. 89*62c56f98SSadaf Ebrahimi* `PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_DERIVE` enables support for `psa_key_derivation_output_key` to deterministically derive a key of that type. 90*62c56f98SSadaf Ebrahimi* `PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_EXPORT` enables support for `psa_export_key` to export a key of that type. 91*62c56f98SSadaf Ebrahimi 92*62c56f98SSadaf EbrahimiFor asymmetric cryptography, `PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_BASIC` determines whether private-key operations are desired, and `PSA_WANT_KEY_TYPE_xxx_PUBLIC_KEY` determines whether public-key operations are desired. `PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_BASIC` implicitly enables `PSA_WANT_KEY_TYPE_xxx_PUBLIC_KEY`, as well as support for `psa_export_public_key` on the private key: there is no way to only include private-key operations (which typically saves little code). 93*62c56f98SSadaf Ebrahimi 94*62c56f98SSadaf EbrahimiNote: the implementation is always free to include support for more than what was explicitly requested. (For example, as of Mbed TLS 3.5.0, `PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_BASIC` implicitly enables import and export support for that key type, but this may not be the case in future versions.) Applications should always request support for all operations they need, rather than rely on them being implicitly enabled by the implementation. The only thing that is documented and guaranteed in the future is as follows: `PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_yyy` -> `PSA_WANT_KEY_TYPE_xxx_KEY_PAIR_BASIC` -> `PSA_WANT_KEY_TYPE_xxx_PUBLIC_KEY`. 95*62c56f98SSadaf Ebrahimi 96*62c56f98SSadaf Ebrahimi#### Configuration symbols for elliptic curves 97*62c56f98SSadaf Ebrahimi 98*62c56f98SSadaf EbrahimiFor elliptic curve key types, only the specified curves are included. To include a curve, include a symbol of the form **`PSA_WANT_ECC_family_size`**. For example: `PSA_WANT_ECC_SECP_R1_256` for secp256r1, `PSA_WANT_ECC_MONTGOMERY_255` for Curve25519. It is an error to require an ECC key type but no curve, and Mbed TLS will reject this at compile time. 99*62c56f98SSadaf Ebrahimi 100*62c56f98SSadaf EbrahimiRationale: this is a deviation of the general principle that `PSA_ECC_FAMILY_xxx` would have a corresponding symbol `PSA_WANT_ECC_FAMILY_xxx`. This deviation is justified by the fact that it is very common to wish to include only certain curves in a family, and that can lead to a significant gain in code size. 101*62c56f98SSadaf Ebrahimi 102*62c56f98SSadaf Ebrahimi#### Configuration symbols for Diffie-Hellman groups 103*62c56f98SSadaf Ebrahimi 104*62c56f98SSadaf EbrahimiThere are no configuration symbols for Diffie-Hellman groups (`PSA_DH_GROUP_xxx`). 105*62c56f98SSadaf Ebrahimi 106*62c56f98SSadaf EbrahimiRationale: Finite-field Diffie-Hellman code is usually not specialized for any particular group, so reducing the number of available groups at compile time only saves a little code space. Constrained implementations tend to omit FFDH anyway, so the small code size gain is not important. 107*62c56f98SSadaf Ebrahimi 108*62c56f98SSadaf Ebrahimi#### Configuration symbols for algorithms 109*62c56f98SSadaf Ebrahimi 110*62c56f98SSadaf EbrahimiFor each constant or constructor macro of the form `PSA_ALG_xxx`, the symbol **`PSA_WANT_ALG_xxx`** indicates that support for this algorithm is desired. 111*62c56f98SSadaf Ebrahimi 112*62c56f98SSadaf EbrahimiFor parametrized algorithms, the `PSA_WANT_ALG_xxx` symbol indicates whether the base mechanism is supported. Parameters must themselves be included through their own `PSA_WANT_ALG_xxx` symbols. It is an error to include a base mechanism without at least one possible parameter, and Mbed TLS will reject this at compile time. For example, `PSA_WANT_ALG_ECDSA` requires the inclusion of randomized ECDSA for all hash algorithms whose corresponding symbol `PSA_WANT_ALG_xxx` is enabled. 113*62c56f98SSadaf Ebrahimi 114*62c56f98SSadaf Ebrahimi## Implementation 115*62c56f98SSadaf Ebrahimi 116*62c56f98SSadaf Ebrahimi### Additional non-public symbols 117*62c56f98SSadaf Ebrahimi 118*62c56f98SSadaf Ebrahimi#### Accounting for transparent drivers 119*62c56f98SSadaf Ebrahimi 120*62c56f98SSadaf EbrahimiIn addition to the [configuration symbols](#psa-crypto-configuration-symbols), we need two parallel or mostly parallel sets of symbols: 121*62c56f98SSadaf Ebrahimi 122*62c56f98SSadaf Ebrahimi* **`MBEDTLS_PSA_ACCEL_xxx`** indicates whether a fully-featured, fallback-free transparent driver is available. 123*62c56f98SSadaf Ebrahimi* **`MBEDTLS_PSA_BUILTIN_xxx`** indicates whether the software implementation is needed. 124*62c56f98SSadaf Ebrahimi 125*62c56f98SSadaf Ebrahimi`MBEDTLS_PSA_ACCEL_xxx` is one of the outputs of the transpilation of a driver description, alongside the glue code for calling the drivers. 126*62c56f98SSadaf Ebrahimi 127*62c56f98SSadaf Ebrahimi`MBEDTLS_PSA_BUILTIN_xxx` is enabled when `PSA_WANT_xxx` is enabled and `MBEDTLS_PSA_ACCEL_xxx` is disabled. 128*62c56f98SSadaf Ebrahimi 129*62c56f98SSadaf EbrahimiThese symbols are not part of the public interface of Mbed TLS towards applications or to drivers, regardless of whether the symbols are actually visible. 130*62c56f98SSadaf Ebrahimi 131*62c56f98SSadaf Ebrahimi### Architecture of symbol definitions 132*62c56f98SSadaf Ebrahimi 133*62c56f98SSadaf Ebrahimi#### New-style definition of configuration symbols 134*62c56f98SSadaf Ebrahimi 135*62c56f98SSadaf EbrahimiWhen `MBEDTLS_PSA_CRYPTO_CONFIG` is set, the header file `mbedtls/mbedtls_config.h` needs to define all the `MBEDTLS_xxx_C` configuration symbols, including the ones deduced from the PSA Crypto configuration. It does this by including the new header file **`mbedtls/config_psa.h`**, which defines the `MBEDTLS_PSA_BUILTIN_xxx` symbols and deduces the corresponding `MBEDTLS_xxx_C` (and other) symbols. 136*62c56f98SSadaf Ebrahimi 137*62c56f98SSadaf Ebrahimi`mbedtls/config_psa.h` includes `psa/crypto_config.h`, the user-editable file that defines application requirements. 138*62c56f98SSadaf Ebrahimi 139*62c56f98SSadaf Ebrahimi#### Old-style definition of configuration symbols 140*62c56f98SSadaf Ebrahimi 141*62c56f98SSadaf EbrahimiWhen `MBEDTLS_PSA_CRYPTO_CONFIG` is not set, the configuration of Mbed TLS works as before, and the inclusion of non-PSA code only depends on `MBEDTLS_xxx` symbols defined (or not) in `mbedtls/mbedtls_config.h`. Furthermore, the new header file **`mbedtls/config_psa.h`** deduces PSA configuration symbols (`PSA_WANT_xxx`, `MBEDTLS_PSA_BUILTIN_xxx`) from classic configuration symbols (`MBEDTLS_xxx`). 142*62c56f98SSadaf Ebrahimi 143*62c56f98SSadaf EbrahimiThe `PSA_WANT_xxx` definitions in `mbedtls/config_psa.h` are needed not only to build the PSA parts of the library, but also to build code that uses these parts. This includes structure definitions in `psa/crypto_struct.h`, size calculations in `psa/crypto_sizes.h`, and application code that's specific to a given cryptographic mechanism. In Mbed TLS itself, code under `MBEDTLS_USE_PSA_CRYPTO` and conditional compilation guards in tests and sample programs need `PSA_WANT_xxx`. 144*62c56f98SSadaf Ebrahimi 145*62c56f98SSadaf EbrahimiSince some existing applications use a handwritten `mbedtls/mbedtls_config.h` or an edited copy of `mbedtls/mbedtls_config.h` from an earlier version of Mbed TLS, `mbedtls/config_psa.h` must be included via an already existing header that is not `mbedtls/mbedtls_config.h`, so it is included via `psa/crypto.h` (for example from `psa/crypto_platform.h`). 146*62c56f98SSadaf Ebrahimi 147*62c56f98SSadaf Ebrahimi#### Summary of definitions of configuration symbols 148*62c56f98SSadaf Ebrahimi 149*62c56f98SSadaf EbrahimiWhether `MBEDTLS_PSA_CRYPTO_CONFIG` is set or not, `mbedtls/config_psa.h` includes `mbedtls/crypto_drivers.h`, a header file generated by the transpilation of the driver descriptions. It defines `MBEDTLS_PSA_ACCEL_xxx` symbols according to the availability of transparent drivers without fallback. 150*62c56f98SSadaf Ebrahimi 151*62c56f98SSadaf EbrahimiThe following table summarizes where symbols are defined depending on the configuration mode. 152*62c56f98SSadaf Ebrahimi 153*62c56f98SSadaf Ebrahimi* (U) indicates a symbol that is defined by the user (application). 154*62c56f98SSadaf Ebrahimi* (D) indicates a symbol that is deduced from other symbols by code that ships with Mbed TLS. 155*62c56f98SSadaf Ebrahimi* (G) indicates a symbol that is generated from driver descriptions. 156*62c56f98SSadaf Ebrahimi 157*62c56f98SSadaf Ebrahimi| Symbols | With `MBEDTLS_PSA_CRYPTO_CONFIG` | Without `MBEDTLS_PSA_CRYPTO_CONFIG` | 158*62c56f98SSadaf Ebrahimi| ------------------------- | --------------------------------- | ----------------------------------- | 159*62c56f98SSadaf Ebrahimi| `MBEDTLS_xxx_C` | `mbedtls/mbedtls_config.h` (U) or | `mbedtls/mbedtls_config.h` (U) | 160*62c56f98SSadaf Ebrahimi| | `mbedtls/config_psa.h` (D) | | 161*62c56f98SSadaf Ebrahimi| `PSA_WANT_xxx` | `psa/crypto_config.h` (U) | `mbedtls/config_psa.h` (D) | 162*62c56f98SSadaf Ebrahimi| `MBEDTLS_PSA_BUILTIN_xxx` | `mbedtls/config_psa.h` (D) | `mbedtls/config_psa.h` (D) | 163*62c56f98SSadaf Ebrahimi| `MBEDTLS_PSA_ACCEL_xxx` | `mbedtls/crypto_drivers.h` (G) | N/A | 164*62c56f98SSadaf Ebrahimi 165*62c56f98SSadaf Ebrahimi#### Visibility of internal symbols 166*62c56f98SSadaf Ebrahimi 167*62c56f98SSadaf EbrahimiIdeally, the `MBEDTLS_PSA_ACCEL_xxx` and `MBEDTLS_PSA_BUILTIN_xxx` symbols should not be visible to application code or driver code, since they are not part of the public interface of the library. However these symbols are needed to deduce whether to include library modules (for example `MBEDTLS_AES_C` has to be enabled if `MBEDTLS_PSA_BUILTIN_KEY_TYPE_AES` is enabled), which makes it difficult to keep them private. 168*62c56f98SSadaf Ebrahimi 169*62c56f98SSadaf Ebrahimi#### Compile-time checks 170*62c56f98SSadaf Ebrahimi 171*62c56f98SSadaf EbrahimiThe header file **`library/psa_check_config.h`** applies sanity checks to the configuration, throwing `#error` if something is wrong. 172*62c56f98SSadaf Ebrahimi 173*62c56f98SSadaf EbrahimiA mechanism similar to `mbedtls/check_config.h` detects errors such as enabling ECDSA but no curve. 174*62c56f98SSadaf Ebrahimi 175*62c56f98SSadaf EbrahimiSince configuration symbols must be undefined or 1, any other value should trigger an `#error`. 176*62c56f98SSadaf Ebrahimi 177*62c56f98SSadaf Ebrahimi#### Automatic generation of preprocessor symbol manipulations 178*62c56f98SSadaf Ebrahimi 179*62c56f98SSadaf EbrahimiA lot of the preprocessor symbol manipulation is systematic calculations that analyze the configuration. `mbedtls/config_psa.h` and `library/psa_check_config.h` should be generated automatically, in the same manner as `version_features.c`. 180*62c56f98SSadaf Ebrahimi 181*62c56f98SSadaf Ebrahimi### Structure of PSA Crypto library code 182*62c56f98SSadaf Ebrahimi 183*62c56f98SSadaf Ebrahimi#### Conditional inclusion of library entry points 184*62c56f98SSadaf Ebrahimi 185*62c56f98SSadaf EbrahimiAn entry point can be eliminated entirely if no algorithm requires it. 186*62c56f98SSadaf Ebrahimi 187*62c56f98SSadaf Ebrahimi#### Conditional inclusion of mechanism-specific code 188*62c56f98SSadaf Ebrahimi 189*62c56f98SSadaf EbrahimiCode that is specific to certain key types or to certain algorithms must be guarded by the applicable symbols: `PSA_WANT_xxx` for code that is independent of the application, and `MBEDTLS_PSA_BUILTIN_xxx` for code that calls an Mbed TLS software implementation. 190*62c56f98SSadaf Ebrahimi 191*62c56f98SSadaf Ebrahimi## PSA standardization 192*62c56f98SSadaf Ebrahimi 193*62c56f98SSadaf Ebrahimi### JSON configuration mechanism 194*62c56f98SSadaf Ebrahimi 195*62c56f98SSadaf EbrahimiAt the time of writing, the preferred configuration mechanism for a PSA service is in JSON syntax. The translation from JSON to build instructions is not specified by PSA. 196*62c56f98SSadaf Ebrahimi 197*62c56f98SSadaf EbrahimiFor PSA Crypto, the preferred configuration mechanism would be similar to capability specifications of transparent drivers. The same JSON properties that are used to mean “this driver can perform that mechanism” in a driver description would be used to mean “the application wants to perform that mechanism” in the application configuration. 198*62c56f98SSadaf Ebrahimi 199*62c56f98SSadaf Ebrahimi### From JSON to C 200*62c56f98SSadaf Ebrahimi 201*62c56f98SSadaf EbrahimiThe JSON capability language allows a more fine-grained selection than the C mechanism proposed here. For example, it allows requesting only single-part mechanisms, only certain key sizes, or only certain combinations of algorithms and key types. 202*62c56f98SSadaf Ebrahimi 203*62c56f98SSadaf EbrahimiThe JSON capability language can be translated approximately to the boolean symbol mechanism proposed here. The approximation considers a feature to be enabled if any part of it is enabled. For example, if there is a capability for AES-CTR and one for CAMELLIA-GCM, the translation to boolean symbols will also include AES-GCM and CAMELLIA-CTR. If there is a capability for AES-128, the translation will also include AES-192 and AES-256. 204*62c56f98SSadaf Ebrahimi 205*62c56f98SSadaf EbrahimiThe boolean symbol mechanism proposed here can be translated to a list of JSON capabilities: for each included algorithm, include a capability with that algorithm, the key types that apply to that algorithm, no size restriction, and all the entry points that apply to that algorithm. 206*62c56f98SSadaf Ebrahimi 207*62c56f98SSadaf Ebrahimi## Open questions 208*62c56f98SSadaf Ebrahimi 209*62c56f98SSadaf Ebrahimi### Open questions about the interface 210*62c56f98SSadaf Ebrahimi 211*62c56f98SSadaf Ebrahimi#### Naming of symbols 212*62c56f98SSadaf Ebrahimi 213*62c56f98SSadaf EbrahimiThe names of [elliptic curve symbols](#configuration-symbols-for-elliptic-curves) are a bit weird: `SECP_R1_256` instead of `SECP256R1`, `MONTGOMERY_255` instead of `CURVE25519`. Should we make them more classical, but less systematic? 214*62c56f98SSadaf Ebrahimi 215*62c56f98SSadaf Ebrahimi#### Impossible combinations 216*62c56f98SSadaf Ebrahimi 217*62c56f98SSadaf EbrahimiWhat does it mean to have `PSA_WANT_ALG_ECDSA` enabled but with only Curve25519? Is it a mandatory error? 218*62c56f98SSadaf Ebrahimi 219*62c56f98SSadaf Ebrahimi#### Diffie-Hellman 220*62c56f98SSadaf Ebrahimi 221*62c56f98SSadaf EbrahimiWay to request only specific groups? Not a priority: constrained devices don't do FFDH. Specify it as may change in future versions. 222*62c56f98SSadaf Ebrahimi 223*62c56f98SSadaf Ebrahimi#### Coexistence with the current Mbed TLS configuration 224*62c56f98SSadaf Ebrahimi 225*62c56f98SSadaf EbrahimiThe two mechanisms have very different designs. Is there serious potential for confusion? Do we understand how the combinations work? 226*62c56f98SSadaf Ebrahimi 227*62c56f98SSadaf Ebrahimi### Open questions about the design 228*62c56f98SSadaf Ebrahimi 229*62c56f98SSadaf Ebrahimi#### Algorithms without a key type or vice versa 230*62c56f98SSadaf Ebrahimi 231*62c56f98SSadaf EbrahimiIs it realistic to mandate a compile-time error if a key type is required, but no matching algorithm, or vice versa? Is it always the right thing, for example if there is an opaque driver that manipulates this key type? 232*62c56f98SSadaf Ebrahimi 233*62c56f98SSadaf Ebrahimi#### Opaque-only mechanisms 234*62c56f98SSadaf Ebrahimi 235*62c56f98SSadaf EbrahimiIf a mechanism should only be supported in an opaque driver, what does the core need to know about it? Do we have all the information we need? 236*62c56f98SSadaf Ebrahimi 237*62c56f98SSadaf EbrahimiThis is especially relevant to suppress a mechanism completely if there is no matching algorithm. For example, if there is no transparent implementation of RSA or ECDSA, `psa_sign_hash` and `psa_verify_hash` may still be needed if there is an opaque signature driver. 238*62c56f98SSadaf Ebrahimi 239*62c56f98SSadaf Ebrahimi### Open questions about the implementation 240*62c56f98SSadaf Ebrahimi 241*62c56f98SSadaf Ebrahimi#### Testability 242*62c56f98SSadaf Ebrahimi 243*62c56f98SSadaf EbrahimiIs this proposal decently testable? There are a lot of combinations. What combinations should we test? 244*62c56f98SSadaf Ebrahimi 245*62c56f98SSadaf Ebrahimi<!-- 246*62c56f98SSadaf EbrahimiLocal Variables: 247*62c56f98SSadaf Ebrahimitime-stamp-line-limit: 40 248*62c56f98SSadaf Ebrahimitime-stamp-start: "Time-stamp: *\"" 249*62c56f98SSadaf Ebrahimitime-stamp-end: "\"" 250*62c56f98SSadaf Ebrahimitime-stamp-format: "%04Y/%02m/%02d %02H:%02M:%02S %Z" 251*62c56f98SSadaf Ebrahimitime-stamp-time-zone: "GMT" 252*62c56f98SSadaf EbrahimiEnd: 253*62c56f98SSadaf Ebrahimi--> 254