You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/en/security/flash-encryption.rst
+36-40Lines changed: 36 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -283,71 +283,73 @@ To use a host generated key, take the following steps:
283
283
284
284
2. Generate a random key by running:
285
285
286
-
.. only:: SOC_FLASH_ENCRYPTION_XTS_AES_256
286
+
.. only:: SOC_FLASH_ENCRYPTION_XTS_AES_256
287
287
288
-
If :ref:`Size of generated AES-XTS key <CONFIG_SECURE_FLASH_ENCRYPTION_KEYSIZE>` is AES-256 (512-bit key) need to use the `XTS_AES_256_KEY_1` and `XTS_AES_256_KEY_2` purposes. The espsecure does not support 512-bit key, but it is possible to workaround:
288
+
If :ref:`Size of generated AES-XTS key <CONFIG_SECURE_FLASH_ENCRYPTION_KEYSIZE>` is AES-128 (256-bit key):
3. **Before the first encrypted boot**, burn the key into your device's eFuse using the command below. This action can be done **only once**.
311
+
.. code-block:: bash
313
312
314
-
.. only:: not SOC_FLASH_ENCRYPTION_XTS_AES
313
+
espefuse.py --port PORT burn_key flash_encryption my_flash_encryption_key.bin
315
314
316
-
.. code-block:: bash
315
+
.. only:: SOC_FLASH_ENCRYPTION_XTS_AES_256
316
+
317
+
.. code-block:: bash
317
318
318
-
espefuse.py --port PORT burn_key flash_encryption my_flash_encryption_key.bin
319
+
espefuse.py --port PORT burn_key BLOCK my_flash_encryption_key.bin KEYPURPOSE
319
320
320
-
.. only:: SOC_FLASH_ENCRYPTION_XTS_AES_256
321
+
where ``BLOCK`` is a free keyblock between ``BLOCK_KEY0`` and ``BLOCK_KEY5``. And ``KEYPURPOSE`` is either ``AES_256_KEY_1``, ``XTS_AES_256_KEY_2``, ``XTS_AES_128_KEY``. See `{IDF_TARGET_NAME} Technical Reference Manual <{IDF_TARGET_TRM_EN_URL}>`_ for a description of the key purposes.
321
322
322
-
.. code-block:: bash
323
+
For AES-128 (256-bit key) - ``XTS_AES_128_KEY``:
323
324
324
-
espefuse.py --port PORT burn_key BLOCK my_flash_encryption_key.bin KEYPURPOSE
325
+
.. code-block:: bash
325
326
326
-
where ``BLOCK`` is a free keyblock between ``BLOCK_KEY0`` and ``BLOCK_KEY5``. And ``KEYPURPOSE`` is either ``AES_256_KEY_1``, ``XTS_AES_256_KEY_2``, ``XTS_AES_128_KEY``. See `{IDF_TARGET_NAME} Technical Reference Manual <{IDF_TARGET_TRM_EN_URL}>`_ for a description of the key purposes.
327
+
espefuse.py --port PORT burn_key BLOCK my_flash_encryption_key.bin XTS_AES_128_KEY
327
328
328
-
AES-128 (256-bit key) - ``XTS_AES_128_KEY``:
329
+
For AES-256 (512-bit key) - ``XTS_AES_256_KEY_1`` and ``XTS_AES_256_KEY_2``. ``espefuse.py`` supports burning both these two key purposes together with a 512 bit key to two separate key blocks via the virtual key purpose ``XTS_AES_256_KEY``. When this is used ``espefuse.py`` will burn the first 256 bit of the key to the specified ``BLOCK`` and burn the corresponding block key purpose to ``XTS_AES_256_KEY_1``. The last 256 bit of the key will be burned to the first free key block after ``BLOCK`` and the corresponding block key purpose to ``XTS_AES_256_KEY_2``
329
330
330
-
.. code-block:: bash
331
+
.. code-block:: bash
331
332
332
-
espefuse.py --port PORT burn_key BLOCK my_flash_encryption_key.bin XTS_AES_128_KEY
333
+
espefuse.py --port PORT burn_key BLOCK my_flash_encryption_key.bin XTS_AES_256_KEY
333
334
334
-
AES-256 (512-bit key) - ``XTS_AES_256_KEY_1`` and ``XTS_AES_256_KEY_2``. It is not fully supported yet in espefuse.py and espsecure.py. Need to do the following steps:
335
+
If you wish to specify exactly which two blocks are used then it is possible to divide key into two 256 bit keys, and manually burn each half with ``XTS_AES_256_KEY_1`` and ``XTS_AES_256_KEY_2`` as key purposes:
335
336
336
-
.. code-block:: bash
337
+
.. code-block:: bash
337
338
338
-
espefuse.py --port PORT burn_key BLOCK my_flash_encryption_key1.bin XTS_AES_256_KEY_1
espefuse.py --port PORT burn_key BLOCK my_flash_encryption_key.bin.aa XTS_AES_256_KEY_1
341
+
espefuse.py --port PORT burn_key BLOCK+1 my_flash_encryption_key.bin.ab XTS_AES_256_KEY_2
339
342
340
-
espefuse.py --port PORT burn_key BLOCK+1 my_flash_encryption_key2.bin XTS_AES_256_KEY_2
341
343
342
-
.. only:: SOC_FLASH_ENCRYPTION_XTS_AES and not SOC_FLASH_ENCRYPTION_XTS_AES_256
344
+
.. only:: SOC_FLASH_ENCRYPTION_XTS_AES and not SOC_FLASH_ENCRYPTION_XTS_AES_256
343
345
344
-
.. code-block:: bash
346
+
.. code-block:: bash
345
347
346
-
espefuse.py --port PORT burn_key BLOCK my_flash_encryption_key.bin XTS_AES_128_KEY
348
+
espefuse.py --port PORT burn_key BLOCK my_flash_encryption_key.bin XTS_AES_128_KEY
347
349
348
-
where ``BLOCK`` is a free keyblock between ``BLOCK_KEY0`` and ``BLOCK_KEY5``.
350
+
where ``BLOCK`` is a free keyblock between ``BLOCK_KEY0`` and ``BLOCK_KEY5``.
349
351
350
-
If the key is not burned and the device is started after enabling flash encryption, the {IDF_TARGET_NAME} will generate a random key that software cannot access or modify.
352
+
If the key is not burned and the device is started after enabling flash encryption, the {IDF_TARGET_NAME} will generate a random key that software cannot access or modify.
351
353
352
354
4. In :ref:`project-configuration-menu`, do the following:
353
355
@@ -875,12 +877,6 @@ Manually encrypting or decrypting files requires the flash encryption key to be
875
877
876
878
The key file should be a single raw binary file (example: ``key.bin``).
877
879
878
-
.. only:: SOC_FLASH_ENCRYPTION_XTS_AES_256
879
-
880
-
.. note::
881
-
882
-
If using AES-XTS-256 then the key file is generated in two parts for programming via ``espefuse.py`` (``XTS_AES_256_KEY_1`` and ``XTS_AES_256_KEY_2``). ``espsecure.py`` currently only supports a single key file for encrypt/decrypt, so the individual files used for ``XTS_AES_256_KEY_1`` and ``XTS_AES_256_KEY_2`` should be manually concatenated to create a single file 64 bytes long.
883
-
884
880
For example, these are the steps to encrypt the file ``build/my-app.bin`` to flash at offset 0x10000. Run espsecure.py as follows:
885
881
886
882
.. only:: esp32
@@ -962,7 +958,7 @@ The following sections provide some reference information about the operation of
962
958
963
959
Flash Encryption Algorithm
964
960
^^^^^^^^^^^^^^^^^^^^^^^^^^
965
-
961
+
966
962
- {IDF_TARGET_NAME} use the XTS-AES block cipher mode with 256 bit or 512 bit key size for flash encryption.
967
963
968
964
- XTS-AES is a block cipher mode specifically designed for disc encryption and addresses the weaknesses other potential modes (e.g. AES-CTR) have for this use case. A detailed description of the XTS-AES algorithm can be found in `IEEE Std 1619-2007 <https://ieeexplore.ieee.org/document/4493450>`_.
0 commit comments