mbedtls.rst 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. Mbed TLS
  2. ========
  3. :link_to_translation:`zh_CN:[中文]`
  4. `Mbed TLS <https://github.com/Mbed-TLS/mbedtls>`_ is a C library that implements cryptographic primitives, X.509 certificate manipulation and the SSL/TLS and DTLS protocols. Its small code footprint makes it suitable for embedded systems.
  5. .. note::
  6. ESP-IDF uses a `fork <https://github.com/espressif/mbedtls>`_ of Mbed TLS which includes a few patches (related to hardware routines of certain modules like ``bignum (MPI)`` and ``ECC``) over vanilla Mbed TLS.
  7. Mbed TLS supports SSL 3.0 up to TLS 1.3 and DTLS 1.0 to 1.2 communication by providing the following:
  8. - TCP/IP communication functions: listen, connect, accept, read/write.
  9. - SSL/TLS communication functions: init, handshake, read/write.
  10. - X.509 functions: CRT, CRL and key handling
  11. - Random number generation
  12. - Hashing
  13. - Encryption/decryption
  14. Supported TLS versions include SSL 3.0, TLS 1.0, TLS 1.1, TLS 1.2, and TLS 1.3, but on the latest ESP-IDF, SSL 3.0, TLS 1.0, and TLS 1.1 have been removed from Mbed TLS. Supported DTLS versions include DTLS 1.0, DTLS 1.1, and DTLS 1.2, but on the latest ESP-IDF, DTLS 1.0 has been removed from Mbed TLS.
  15. Mbed TLS Documentation
  16. ----------------------
  17. For Mbed TLS documentation please refer to the following (upstream) pointers:
  18. - `API Reference`_
  19. - `Knowledge Base`_
  20. Mbed TLS Support in ESP-IDF
  21. ---------------------------
  22. Please find the information about the Mbed TLS versions presented in different branches of ESP-IDF `here <https://github.com/espressif/mbedtls/wiki#mbed-tls-support-in-esp-idf>`__.
  23. .. note::
  24. Please refer the :ref:`migration_guide_mbedtls` to migrate from Mbed TLS version 2.x to version 3.0 or greater.
  25. Application Examples
  26. --------------------
  27. Examples in ESP-IDF use :doc:`/api-reference/protocols/esp_tls` which provides a simplified API interface for accessing the commonly used TLS functionality.
  28. Refer to the examples :example:`protocols/https_server/simple` (Simple HTTPS server) and :example:`protocols/https_request` (Make HTTPS requests) for more information.
  29. If the Mbed TLS API is to be used directly, refer to the example :example:`protocols/https_mbedtls`.
  30. Alternatives
  31. ------------
  32. :doc:`/api-reference/protocols/esp_tls` acts as an abstraction layer over the underlying SSL/TLS library and thus has an option to use Mbed TLS or wolfSSL as the underlying library. By default, only Mbed TLS is available and used in ESP-IDF whereas wolfSSL is available publicly at `<https://github.com/espressif/esp-wolfSSL>` with the upstream submodule pointer.
  33. Please refer to :ref:`ESP-TLS: Underlying SSL/TLS Library Options <esp_tls_wolfssl>` docs for more information on this and comparison of Mbed TLS and wolfSSL.
  34. Important Config Options
  35. ------------------------
  36. Following is a brief list of important config options accessible at ``Component Config -> mbedTLS``. The full list of config options can be found :ref:`here <CONFIG_MBEDTLS_MEM_ALLOC_MODE>`.
  37. .. list::
  38. - :ref:`CONFIG_MBEDTLS_SSL_PROTO_TLS1_2`: Support for TLS 1.2
  39. - :ref:`CONFIG_MBEDTLS_SSL_PROTO_TLS1_3`: Support for TLS 1.3
  40. - :ref:`CONFIG_MBEDTLS_CERTIFICATE_BUNDLE`: Support for trusted root certificate bundle (more about this: :doc:`/api-reference/protocols/esp_crt_bundle`)
  41. - :ref:`CONFIG_MBEDTLS_CLIENT_SSL_SESSION_TICKETS`: Support for TLS Session Resumption: Client session tickets
  42. - :ref:`CONFIG_MBEDTLS_SERVER_SSL_SESSION_TICKETS`: Support for TLS Session Resumption: Server session tickets
  43. - :ref:`CONFIG_MBEDTLS_HARDWARE_SHA`: Support for hardware SHA acceleration
  44. :SOC_AES_SUPPORTED: - :ref:`CONFIG_MBEDTLS_HARDWARE_AES`: Support for hardware AES acceleration
  45. :SOC_MPI_SUPPORTED: - :ref:`CONFIG_MBEDTLS_HARDWARE_MPI`: Support for hardware MPI (bignum) acceleration
  46. :SOC_ECC_SUPPORTED: - :ref:`CONFIG_MBEDTLS_HARDWARE_ECC`: Support for hardware ECC acceleration
  47. .. note::
  48. Mbed TLS v3.0.0 and later support only TLS 1.2 and TLS 1.3 (SSL 3.0, TLS 1.0, TLS 1.1, and DTLS 1.0 are not supported). The support for TLS 1.3 is experimental and only supports the client-side. More information about this can be found out `here <https://github.com/espressif/mbedtls/blob/9bb5effc3298265f829878825d9bd38478e67514/docs/architecture/tls13-support.md>`__.
  49. Performance and Memory Tweaks
  50. -----------------------------
  51. .. _reducing_ram_usage_mbedtls:
  52. Reducing Heap Usage
  53. ^^^^^^^^^^^^^^^^^^^
  54. The following table shows typical memory usage with different configs when the :example:`protocols/https_request` example (with Server Validation enabled) was run with Mbed TLS as the SSL/TLS library.
  55. .. list-table::
  56. :header-rows: 1
  57. :widths: 25 60 30
  58. :align: center
  59. * - Mbed TLS Test
  60. - Related Configs
  61. - Heap Usage (approx.)
  62. * - Default
  63. - NA
  64. - 42196 B
  65. * - Enable SSL Variable Length
  66. - :ref:`CONFIG_MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH`
  67. - 42120 B
  68. * - Disable Keep Peer Certificate
  69. - :ref:`CONFIG_MBEDTLS_SSL_KEEP_PEER_CERTIFICATE`
  70. - 38533 B
  71. * - Enable Dynamic TX/RX Buffer
  72. - :ref:`CONFIG_MBEDTLS_DYNAMIC_BUFFER`
  73. :ref:`CONFIG_MBEDTLS_DYNAMIC_FREE_CONFIG_DATA`
  74. :ref:`CONFIG_MBEDTLS_DYNAMIC_FREE_CA_CERT`
  75. - 22013 B
  76. .. note::
  77. These values are subject to change with change in configuration options and versions of Mbed TLS.
  78. Reducing Binary Size
  79. ^^^^^^^^^^^^^^^^^^^^
  80. Under ``Component Config -> mbedTLS``, there are multiple Mbed TLS features which are enabled by default but can be disabled if not needed to save code size. More information can be about this can be found in :ref:`Minimizing Binary Size <minimizing_binary_mbedtls>` docs.
  81. .. _`API Reference`: https://mbed-tls.readthedocs.io/projects/api/en/v3.4.1/
  82. .. _`Knowledge Base`: https://mbed-tls.readthedocs.io/en/latest/kb/