2023-07-07 12:00:49 +02:00
|
|
|
This document explains how to create builds of Mbed TLS where some
|
|
|
|
cryptographic mechanisms are provided only by PSA drivers (that is, no
|
|
|
|
built-in implementation of those algorithms), from a user's perspective.
|
|
|
|
|
|
|
|
This is useful to save code size for people who are using either a hardware
|
|
|
|
accelerator, or an alternative software implementation that's more
|
|
|
|
aggressively optimized for code size than the default one in Mbed TLS.
|
|
|
|
|
|
|
|
General considerations
|
|
|
|
----------------------
|
|
|
|
|
|
|
|
This document assumes that you already have a working driver.
|
|
|
|
Otherwise, please see the [PSA driver example and
|
|
|
|
guide](psa-driver-example-and-guide.md) for information on writing a
|
|
|
|
driver.
|
|
|
|
|
|
|
|
In order to have some mechanism provided only by a driver, you'll want
|
|
|
|
the following compile-time configuration options enabled:
|
|
|
|
- `MBEDTLS_PSA_CRYPTO_C` (enabled by default) - this enables PSA Crypto.
|
|
|
|
- `MBEDTLS_USE_PSA_CRYPTO` (disabled by default) - this makes PK, X.509 and
|
|
|
|
TLS use PSA Crypto. You need to enable this if you're using PK, X.509 or TLS
|
|
|
|
and want them to have access to the algorithms provided by your driver. (See
|
|
|
|
[the dedicated document](use-psa-crypto.md) for details.)
|
|
|
|
- `MBEDTLS_PSA_CRYPTO_CONFIG` (disabled by default) - this enables
|
|
|
|
configuration of cryptographic algorithms using `PSA_WANT` macros in
|
|
|
|
`include/psa/crypto_config.h`. See [Conditional inclusion of cryptographic
|
|
|
|
mechanism through the PSA API in Mbed
|
|
|
|
TLS](proposed/psa-conditional-inclusion-c.md) for details.
|
|
|
|
|
|
|
|
In addition, for each mechanism you want provided only by your driver:
|
|
|
|
- Define the corresponding `PSA_WANT` macro in `psa/crypto_config.h` - this
|
|
|
|
means the algorithm will be available in the PSA Crypto API.
|
2023-07-18 10:40:56 +02:00
|
|
|
- Define the corresponding `MBEDTLS_PSA_ACCEL` in your build. This could be
|
|
|
|
defined in `psa/crypto_config.h` or your compiler's command line. This
|
|
|
|
informs the PSA code that an accelerator is available for this mechanism.
|
2023-07-07 12:00:49 +02:00
|
|
|
- Undefine / comment out the corresponding `MBEDTLS_xxx_C` macro in
|
|
|
|
`mbedtls/mbedtls_config.h`. This ensures the built-in implementation is not
|
|
|
|
included in the build.
|
|
|
|
|
|
|
|
For example, if you want SHA-256 to be provided only by a driver, you'll want
|
|
|
|
`PSA_WANT_ALG_SHA_256` and `MBEDTLS_PSA_ACCEL_SHA_256` defined, and
|
|
|
|
`MBEDTLS_SHA256_C` undefined.
|
|
|
|
|
|
|
|
In addition to these compile-time considerations, at runtime you'll need to
|
|
|
|
make sure you call `psa_crypto_init()` before any function that uses the
|
2023-07-18 10:40:56 +02:00
|
|
|
driver-only mechanisms. Note that this is already a requirement for any use of
|
|
|
|
the PSA Crypto API, as well as for use of the PK, X.509 and TLS modules when
|
|
|
|
`MBEDTLS_USE_PSA_CRYPTO` is enabled, so in most cases your application will
|
|
|
|
already be doing this.
|
2023-07-07 12:00:49 +02:00
|
|
|
|
|
|
|
Mechanisms covered
|
|
|
|
------------------
|
|
|
|
|
2023-07-11 11:11:20 +02:00
|
|
|
For now, only the following (families of) mechanisms are supported:
|
2023-07-07 12:00:49 +02:00
|
|
|
- hashes: SHA-3, SHA-2, SHA-1, MD5, etc.
|
|
|
|
- elliptic-curve cryptography (ECC): ECDH, ECDSA, EC J-PAKE, ECC key types.
|
2023-07-11 11:11:20 +02:00
|
|
|
- finite-field Diffie-Hellman: FFDH algorithm, DH key types.
|
2023-07-07 12:00:49 +02:00
|
|
|
|
|
|
|
Supported means that when those are provided only by drivers, everything
|
|
|
|
(including PK, X.509 and TLS if `MBEDTLS_USE_PSA_CRYPTO` is enabled) should
|
|
|
|
work in the same way as if the mechanisms where built-in, except as documented
|
|
|
|
in the "Limitations" sub-sections of the sections dedicated to each family
|
|
|
|
below.
|
|
|
|
|
|
|
|
In the near future (end of 2023), we are planning to also add support for
|
|
|
|
ciphers (AES) and AEADs (GCM, CCM, ChachaPoly).
|
|
|
|
|
2023-07-11 11:11:20 +02:00
|
|
|
Currently (mid-2023) we don't have plans to extend this to RSA. If
|
|
|
|
you're interested in driver-only support for RSA, please let us know.
|
2023-07-07 12:00:49 +02:00
|
|
|
|
|
|
|
Hashes
|
|
|
|
------
|
|
|
|
|
|
|
|
TODO
|
|
|
|
|
|
|
|
Elliptic-curve cryptography (ECC)
|
|
|
|
---------------------------------
|
|
|
|
|
2023-07-07 16:43:56 +02:00
|
|
|
It is possible to have most ECC operations provided only by a driver:
|
|
|
|
- the ECDH, ECDSA and EC J-PAKE algorithms;
|
|
|
|
- key import, export, and random generation.
|
|
|
|
|
|
|
|
More precisely:
|
|
|
|
- you can enable `PSA_WANT_ALG_ECDH` without `MBEDTLS_ECDH_C` provided
|
|
|
|
`MBEDTLS_PSA_ACCEL_ALG_ECDH` is enabled;
|
|
|
|
- you can enable `PSA_WANT_ALG_ECDSA` without `MBEDTLS_ECDSA_C` provided
|
|
|
|
`MBEDTLS_PSA_ACCEL_ALG_ECDSA` is enabled;
|
|
|
|
- you can enable `PSA_WANT_ALG_JPAKE` without `MBEDTLS_ECJPAKE_C` provided
|
|
|
|
`MBEDTLS_PSA_ACCEL_ALG_JPAKE` is enabled.
|
|
|
|
|
|
|
|
In addition, if none of `MBEDTLS_ECDH_C`, `MBEDTLS_ECDSA_C`,
|
2023-07-18 10:40:56 +02:00
|
|
|
`MBEDTLS_ECJPAKE_C` are enabled, you can enable:
|
2023-07-07 16:43:56 +02:00
|
|
|
- `PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY`;
|
|
|
|
- `PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_BASIC`;
|
|
|
|
- `PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_IMPORT`;
|
|
|
|
- `PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_EXPORT`;
|
|
|
|
- `PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_GENERATE`;
|
|
|
|
without `MBEDTLS_ECP_C` provided the corresponding
|
|
|
|
`MBEDTLS_PSA_ACCEL_KEY_TYPE_xxx` are enabled.
|
|
|
|
|
|
|
|
[Coming soon] If `MBEDTLS_ECP_C` is disabled and `ecp.c` is fully removed (see
|
|
|
|
"Limitations regarding fully removing `ecp.c`" below), and you're not using
|
|
|
|
RSA or FFDH, then you can also disable `MBEDTLS_BIGNUM_C` for further code
|
|
|
|
size saving.
|
|
|
|
|
2023-08-15 10:59:58 +02:00
|
|
|
[Coming soon] As noted in the "Limitations regarding the selection of curves"
|
|
|
|
section below, there is an upcoming requirement for all the required curves to
|
|
|
|
be also accelerated in the PSA driver in order to exclude the builtin algs
|
|
|
|
support.
|
|
|
|
|
2023-07-07 16:43:56 +02:00
|
|
|
### Limitations regarding fully removing `ecp.c`
|
|
|
|
|
|
|
|
A limited subset of `ecp.c` will still be automatically re-enabled if any of
|
|
|
|
the following is enabled:
|
|
|
|
- `MBEDTLS_PK_PARSE_EC_COMPRESSED` - support for parsing ECC keys where the
|
|
|
|
public part is in compressed format;
|
|
|
|
- `MBEDTLS_PK_PARSE_EC_EXTENDED` - support for parsing ECC keys where the
|
|
|
|
curve is identified not by name, but by explicit parameters;
|
|
|
|
- `PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_DERIVE` - support for deterministic
|
|
|
|
derivation of an ECC keypair with `psa_key_derivation_output_key()`.
|
|
|
|
|
2023-07-11 11:14:15 +02:00
|
|
|
Note: when any of the above options is enabled, a subset of `ecp.c` will
|
|
|
|
automatically be included in the build in order to support it. Therefore
|
|
|
|
you can still disable `MBEDTLS_ECP_C` in `mbedtls_config.h` and this will
|
|
|
|
result in some code size savings, but not as much as when none of the
|
|
|
|
above features are enabled.
|
2023-07-07 16:43:56 +02:00
|
|
|
|
|
|
|
We do have plans to support each of these with `ecp.c` fully removed in the
|
2023-07-18 10:40:56 +02:00
|
|
|
future, however there is no established timeline. If you're interested, please
|
|
|
|
let us know, so we can take it into consideration in our planning.
|
2023-07-07 16:43:56 +02:00
|
|
|
|
|
|
|
### Limitations regarding restartable / interruptible ECC operations
|
|
|
|
|
2023-07-11 11:14:15 +02:00
|
|
|
At the moment, there is not driver support for interruptible operations
|
2023-07-07 16:43:56 +02:00
|
|
|
(see `psa_sign_hash_start()` + `psa_sign_hash_complete()` etc.) so as a
|
|
|
|
consequence these are not supported in builds without `MBEDTLS_ECDSA_C`.
|
|
|
|
|
|
|
|
Similarly, there is no PSA support for interruptible ECDH operations so these
|
|
|
|
are not supported without `ECDH_C`. See also limitations regarding
|
|
|
|
restartable operations with `MBEDTLS_USE_PSA_CRYPTO` in [its
|
|
|
|
documentation](use-psa-crypto.md).
|
|
|
|
|
2023-07-18 10:40:56 +02:00
|
|
|
Again, we have plans to support this in the future but not with an established
|
2023-07-07 16:43:56 +02:00
|
|
|
timeline, please let us know if you're interested.
|
|
|
|
|
|
|
|
### Limitations regarding the selection of curves
|
|
|
|
|
2023-08-15 10:59:58 +02:00
|
|
|
There is an ongoing work which tries to establish a link/constrain between
|
|
|
|
the list of supported curves and supported algorithms both in builtin and PSA
|
|
|
|
sides. In particular:
|
|
|
|
|
|
|
|
- #8014 ensures that the curves supported on the PSA side (`PSA_WANT_ECC_xxx`)
|
|
|
|
are always a superset of the builtin ones (`MBEDTLS_ECP_DP_xxx`)
|
|
|
|
- #8016 forces builtin alg support as soon as there is at least one builtin
|
|
|
|
curve. In other words, in order to exclue all builtin algs, all the required
|
|
|
|
curves should be supported and accelerated by the PSA driver.
|
2023-07-11 11:11:20 +02:00
|
|
|
|
|
|
|
Finite-field Diffie-Hellman
|
|
|
|
---------------------------
|
|
|
|
|
2023-08-15 10:59:58 +02:00
|
|
|
Support is pretty similar to the "Elliptic-curve cryptography (ECC)" section
|
|
|
|
above.
|
|
|
|
Key management and usage can be enabled by means of the usual `PSA_WANT` +
|
|
|
|
`MBEDTLS_PSA_ACCEL` pairs:
|
|
|
|
|
|
|
|
- `[PSA_WANT|MBEDTLS_PSA_ACCEL]_KEY_TYPE_DH_PUBLIC_KEY`;
|
|
|
|
- `[PSA_WANT|MBEDTLS_PSA_ACCEL]_KEY_TYPE_DH_KEY_PAIR_BASIC`;
|
|
|
|
- `[PSA_WANT|MBEDTLS_PSA_ACCEL]_KEY_TYPE_DH_KEY_PAIR_IMPORT`;
|
|
|
|
- `[PSA_WANT|MBEDTLS_PSA_ACCEL]_KEY_TYPE_DH_KEY_PAIR_EXPORT`;
|
|
|
|
- `[PSA_WANT|MBEDTLS_PSA_ACCEL]_KEY_TYPE_DH_KEY_PAIR_GENERATE`;
|
|
|
|
|
|
|
|
The same holds for the associated algorithm:
|
|
|
|
`[PSA_WANT|MBEDTLS_PSA_ACCEL]_ALG_FFDH` allow to build accelerating FFDH and
|
|
|
|
removing builtin support (i.e. `MBEDTLS_DHM_C`).
|
|
|
|
|
|
|
|
### Limitations
|
|
|
|
Support for deterministic derivation of a DH keypair
|
|
|
|
(i.e. `PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_DERIVE`) is not supported.
|