Manuel Pégourié-Gonnard | 6d5f494 | 2023-07-07 12:00:49 +0200 | [diff] [blame^] | 1 | This document explains how to create builds of Mbed TLS where some |
| 2 | cryptographic mechanisms are provided only by PSA drivers (that is, no |
| 3 | built-in implementation of those algorithms), from a user's perspective. |
| 4 | |
| 5 | This is useful to save code size for people who are using either a hardware |
| 6 | accelerator, or an alternative software implementation that's more |
| 7 | aggressively optimized for code size than the default one in Mbed TLS. |
| 8 | |
| 9 | General considerations |
| 10 | ---------------------- |
| 11 | |
| 12 | This document assumes that you already have a working driver. |
| 13 | Otherwise, please see the [PSA driver example and |
| 14 | guide](psa-driver-example-and-guide.md) for information on writing a |
| 15 | driver. |
| 16 | |
| 17 | In order to have some mechanism provided only by a driver, you'll want |
| 18 | the following compile-time configuration options enabled: |
| 19 | - `MBEDTLS_PSA_CRYPTO_C` (enabled by default) - this enables PSA Crypto. |
| 20 | - `MBEDTLS_USE_PSA_CRYPTO` (disabled by default) - this makes PK, X.509 and |
| 21 | TLS use PSA Crypto. You need to enable this if you're using PK, X.509 or TLS |
| 22 | and want them to have access to the algorithms provided by your driver. (See |
| 23 | [the dedicated document](use-psa-crypto.md) for details.) |
| 24 | - `MBEDTLS_PSA_CRYPTO_CONFIG` (disabled by default) - this enables |
| 25 | configuration of cryptographic algorithms using `PSA_WANT` macros in |
| 26 | `include/psa/crypto_config.h`. See [Conditional inclusion of cryptographic |
| 27 | mechanism through the PSA API in Mbed |
| 28 | TLS](proposed/psa-conditional-inclusion-c.md) for details. |
| 29 | |
| 30 | In addition, for each mechanism you want provided only by your driver: |
| 31 | - Define the corresponding `PSA_WANT` macro in `psa/crypto_config.h` - this |
| 32 | means the algorithm will be available in the PSA Crypto API. |
| 33 | - Define the corresponding `MBEDTLS_PSA_ACCEL` in your build (could be in |
| 34 | `psa/crypto_config.h` or your compiler's command line). This informs the PSA |
| 35 | code that an accelerator is available for this. |
| 36 | - Undefine / comment out the corresponding `MBEDTLS_xxx_C` macro in |
| 37 | `mbedtls/mbedtls_config.h`. This ensures the built-in implementation is not |
| 38 | included in the build. |
| 39 | |
| 40 | For example, if you want SHA-256 to be provided only by a driver, you'll want |
| 41 | `PSA_WANT_ALG_SHA_256` and `MBEDTLS_PSA_ACCEL_SHA_256` defined, and |
| 42 | `MBEDTLS_SHA256_C` undefined. |
| 43 | |
| 44 | In addition to these compile-time considerations, at runtime you'll need to |
| 45 | make sure you call `psa_crypto_init()` before any function that uses the |
| 46 | mechanisms provided only by drivers. Note that this is already a requirement |
| 47 | for any use of the PSA Crypto API, as well as for use of the PK, X.509 and TLS |
| 48 | modules when `MBEDTLS_USE_PSA_CRYPTO` is enabled, so in most cases your |
| 49 | application will already be doing this. |
| 50 | |
| 51 | Mechanisms covered |
| 52 | ------------------ |
| 53 | |
| 54 | For now, only two families are supported: |
| 55 | - hashes: SHA-3, SHA-2, SHA-1, MD5, etc. |
| 56 | - elliptic-curve cryptography (ECC): ECDH, ECDSA, EC J-PAKE, ECC key types. |
| 57 | |
| 58 | Supported means that when those are provided only by drivers, everything |
| 59 | (including PK, X.509 and TLS if `MBEDTLS_USE_PSA_CRYPTO` is enabled) should |
| 60 | work in the same way as if the mechanisms where built-in, except as documented |
| 61 | in the "Limitations" sub-sections of the sections dedicated to each family |
| 62 | below. |
| 63 | |
| 64 | In the near future (end of 2023), we are planning to also add support for |
| 65 | ciphers (AES) and AEADs (GCM, CCM, ChachaPoly). |
| 66 | |
| 67 | Currently (mid-2023) we don't have plans to extend this to RSA of FFDH. If |
| 68 | you're interested in driver-only support for those, please let us know. |
| 69 | |
| 70 | Hashes |
| 71 | ------ |
| 72 | |
| 73 | TODO |
| 74 | |
| 75 | Elliptic-curve cryptography (ECC) |
| 76 | --------------------------------- |
| 77 | |
| 78 | TODO |