Skip to content

Commit 95d824f

Browse files
committed
Merge branch 'docs/flash_enc_512bits' into 'master'
docs: update flash encryption docs with 512bit key related info Closes IDF-3867 See merge request espressif/esp-idf!15318
2 parents 759a01b + b62f2b3 commit 95d824f

File tree

1 file changed

+36
-40
lines changed

1 file changed

+36
-40
lines changed

docs/en/security/flash-encryption.rst

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -283,71 +283,73 @@ To use a host generated key, take the following steps:
283283

284284
2. Generate a random key by running:
285285

286-
.. only:: SOC_FLASH_ENCRYPTION_XTS_AES_256
286+
.. only:: SOC_FLASH_ENCRYPTION_XTS_AES_256
287287

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):
289289

290-
.. code-block:: bash
290+
.. code-block:: bash
291291
292-
espsecure.py generate_flash_encryption_key my_flash_encryption_key1.bin
292+
espsecure.py generate_flash_encryption_key my_flash_encryption_key.bin
293293
294-
espsecure.py generate_flash_encryption_key my_flash_encryption_key2.bin
294+
else if :ref:`Size of generated AES-XTS key <CONFIG_SECURE_FLASH_ENCRYPTION_KEYSIZE>` is AES-256 (512-bit key):
295295

296-
# To use encrypt_flash_data with XTS_AES_256 requires combining the two binary files to one 64 byte file
297-
cat my_flash_encryption_key1.bin my_flash_encryption_key2.bin > my_flash_encryption_key.bin
296+
.. code-block:: bash
298297
299-
If :ref:`Size of generated AES-XTS key <CONFIG_SECURE_FLASH_ENCRYPTION_KEYSIZE>` is AES-128 (256-bit key) need to use the `XTS_AES_128_KEY` purpose.
298+
espsecure.py generate_flash_encryption_key --keylen 512 my_flash_encryption_key.bin
300299
301-
.. code-block:: bash
302300
303-
espsecure.py generate_flash_encryption_key my_flash_encryption_key.bin
301+
.. only:: not SOC_FLASH_ENCRYPTION_XTS_AES_256
304302

303+
.. code-block:: bash
305304
306-
.. only:: not SOC_FLASH_ENCRYPTION_XTS_AES_256
305+
espsecure.py generate_flash_encryption_key my_flash_encryption_key.bin
307306
308-
.. code-block:: bash
307+
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**.
309308

310-
espsecure.py generate_flash_encryption_key my_flash_encryption_key.bin
309+
.. only:: not SOC_FLASH_ENCRYPTION_XTS_AES
311310

312-
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
313312
314-
.. only:: not SOC_FLASH_ENCRYPTION_XTS_AES
313+
espefuse.py --port PORT burn_key flash_encryption my_flash_encryption_key.bin
315314
316-
.. code-block:: bash
315+
.. only:: SOC_FLASH_ENCRYPTION_XTS_AES_256
316+
317+
.. code-block:: bash
317318
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
319320
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.
321322

322-
.. code-block:: bash
323+
For AES-128 (256-bit key) - ``XTS_AES_128_KEY``:
323324

324-
espefuse.py --port PORT burn_key BLOCK my_flash_encryption_key.bin KEYPURPOSE
325+
.. code-block:: bash
325326
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
327328
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``
329330

330-
.. code-block:: bash
331+
.. code-block:: bash
331332
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
333334
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:
335336

336-
.. code-block:: bash
337+
.. code-block:: bash
337338
338-
espefuse.py --port PORT burn_key BLOCK my_flash_encryption_key1.bin XTS_AES_256_KEY_1
339+
split -b 32 my_flash_encryption_key.bin my_flash_encryption_key.bin.
340+
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
339342
340-
espefuse.py --port PORT burn_key BLOCK+1 my_flash_encryption_key2.bin XTS_AES_256_KEY_2
341343
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
343345

344-
.. code-block:: bash
346+
.. code-block:: bash
345347
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
347349
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``.
349351

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.
351353

352354
4. In :ref:`project-configuration-menu`, do the following:
353355

@@ -875,12 +877,6 @@ Manually encrypting or decrypting files requires the flash encryption key to be
875877

876878
The key file should be a single raw binary file (example: ``key.bin``).
877879

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-
884880
For example, these are the steps to encrypt the file ``build/my-app.bin`` to flash at offset 0x10000. Run espsecure.py as follows:
885881

886882
.. only:: esp32
@@ -962,7 +958,7 @@ The following sections provide some reference information about the operation of
962958

963959
Flash Encryption Algorithm
964960
^^^^^^^^^^^^^^^^^^^^^^^^^^
965-
961+
966962
- {IDF_TARGET_NAME} use the XTS-AES block cipher mode with 256 bit or 512 bit key size for flash encryption.
967963

968964
- 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

Comments
 (0)