Skip to content

Commit a7a31d3

Browse files
committed
bootloader: mcuboot: Changes needed to support AES256
This commit adds changes which are necessary to support the AES256 encryption algorithm in mcuboot. Signed-off-by: Artur Hadasz <[email protected]>
1 parent 9d6a545 commit a7a31d3

File tree

6 files changed

+55
-4
lines changed

6 files changed

+55
-4
lines changed

cmake/mcuboot.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ function(zephyr_mcuboot_tasks)
160160
set(imgtool_args --sha 512 ${imgtool_args})
161161
endif()
162162

163+
if(NOT "${keyfile_enc}" STREQUAL "")
164+
if(CONFIG_MCUBOOT_ENCRYPTION_ALG_AES_256)
165+
set(imgtool_args ${imgtool_args} --encrypt-keylen 256)
166+
endif()
167+
endif()
168+
163169
# Extensionless prefix of any output file.
164170
set(output ${ZEPHYR_BINARY_DIR}/${KERNEL_NAME})
165171

modules/Kconfig.mcuboot

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,22 @@ config MCUBOOT_ENCRYPTION_KEY_FILE
8989

9090
If left empty, you must encrypt the Zephyr binaries manually.
9191

92+
if MCUBOOT_ENCRYPTION_KEY_FILE != ""
93+
94+
choice MCUBOOT_ENCRYPTION_ALG
95+
prompt "Algorithm used for image encryption"
96+
default MCUBOOT_ENCRYPTION_ALG_AES_128
97+
98+
config MCUBOOT_ENCRYPTION_ALG_AES_128
99+
bool "Use AES-128 for image encryption"
100+
101+
config MCUBOOT_ENCRYPTION_ALG_AES_256
102+
bool "Use AES-256 for image encryption"
103+
104+
endchoice # BOOT_ENCRYPT_ALG
105+
106+
endif # MCUBOOT_ENCRYPTION_KEY_FILE != ""
107+
92108
config MCUBOOT_IMGTOOL_SIGN_VERSION
93109
string "Version to pass to imgtool when signing"
94110
default "$(APP_VERSION_TWEAK_STRING)" if "$(VERSION_MAJOR)" != ""

share/sysbuild/image_configurations/BOOTLOADER_image_default.cmake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,12 @@ foreach(loopkeytype ${keytypes})
7878
set_config_bool(${ZCMAKE_APPLICATION} ${loopkeytype} n)
7979
endif()
8080
endforeach()
81+
82+
if(SB_CONFIG_BOOT_ENCRYPTION)
83+
set_config_string(${ZCMAKE_APPLICATION} CONFIG_BOOT_ENCRYPTION_KEY_FILE "${SB_CONFIG_BOOT_ENCRYPTION_KEY_FILE}")
84+
if(SB_CONFIG_BOOT_ENCRYPTION_ALG_AES_128)
85+
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_BOOT_ENCRYPT_ALG_AES_128 y)
86+
elseif(SB_CONFIG_BOOT_ENCRYPTION_ALG_AES_256)
87+
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_BOOT_ENCRYPT_ALG_AES_256 y)
88+
endif()
89+
endif()

share/sysbuild/image_configurations/MAIN_image_default.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,12 @@ if(SB_CONFIG_BOOTLOADER_MCUBOOT)
5151
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_RETENTION_BOOT_MODE y)
5252
endif()
5353
endif()
54+
55+
if(SB_CONFIG_BOOT_ENCRYPTION)
56+
if(SB_CONFIG_BOOT_ENCRYPTION_ALG_AES_128)
57+
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_ENCRYPTION_ALG_AES_128 y)
58+
elseif(SB_CONFIG_BOOT_ENCRYPTION_ALG_AES_256)
59+
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_ENCRYPTION_ALG_AES_256 y)
60+
endif()
61+
endif()
5462
endif()

share/sysbuild/images/bootloader/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,4 @@ if(SB_CONFIG_BOOTLOADER_MCUBOOT)
1515
sysbuild_add_dependencies(FLASH ${DEFAULT_IMAGE} ${image})
1616

1717
set_config_string(${image} CONFIG_BOOT_SIGNATURE_KEY_FILE "${SB_CONFIG_BOOT_SIGNATURE_KEY_FILE}")
18-
set_config_bool(${image} CONFIG_BOOT_ENCRYPT_IMAGE "${SB_CONFIG_BOOT_ENCRYPTION}")
19-
if(SB_CONFIG_BOOT_ENCRYPTION)
20-
set_config_string(${image} CONFIG_BOOT_ENCRYPTION_KEY_FILE "${SB_CONFIG_BOOT_ENCRYPTION_KEY_FILE}")
21-
endif()
2218
endif()

share/sysbuild/images/bootloader/Kconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,20 @@ config BOOT_ENCRYPTION_KEY_FILE
205205
help
206206
Absolute path to encryption key file to use with MCUBoot.
207207

208+
if BOOT_ENCRYPTION
209+
210+
choice BOOT_ENCRYPTION_ALG
211+
prompt "Algorithm used for image encryption"
212+
default BOOT_ENCRYPTION_ALG_AES_128
213+
214+
config BOOT_ENCRYPTION_ALG_AES_128
215+
bool "Use AES-128 for image encryption"
216+
217+
config BOOT_ENCRYPTION_ALG_AES_256
218+
bool "Use AES-256 for image encryption"
219+
220+
endchoice # BOOT_ENCRYPT_ALG
221+
222+
endif # BOOT_ENCRYPTION
223+
208224
endif

0 commit comments

Comments
 (0)