Skip to content

[nrf fromlist] bootloader: mcuboot: Changes needed to support AES256 #3103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cmake/mcuboot.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ function(zephyr_mcuboot_tasks)
set(imgtool_args --sha 512 ${imgtool_args})
endif()

if(NOT "${keyfile_enc}" STREQUAL "")
if(CONFIG_MCUBOOT_ENCRYPTION_ALG_AES_256)
# Note: this overrides the default behavior of using AES-128
set(imgtool_args ${imgtool_args} --encrypt-keylen 256)
endif()
endif()

# Extensionless prefix of any output file.
set(output ${ZEPHYR_BINARY_DIR}/${KERNEL_NAME})

Expand Down
16 changes: 16 additions & 0 deletions modules/Kconfig.mcuboot
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,22 @@ config MCUBOOT_ENCRYPTION_KEY_FILE

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

if MCUBOOT_ENCRYPTION_KEY_FILE != ""

choice MCUBOOT_ENCRYPTION_ALG
prompt "Algorithm used for image encryption"
default MCUBOOT_ENCRYPTION_ALG_AES_128

config MCUBOOT_ENCRYPTION_ALG_AES_128
bool "Use AES-128 for image encryption"

config MCUBOOT_ENCRYPTION_ALG_AES_256
bool "Use AES-256 for image encryption"

endchoice # MCUBOOT_ENCRYPTION_ALG

endif # MCUBOOT_ENCRYPTION_KEY_FILE != ""

config MCUBOOT_IMGTOOL_SIGN_VERSION
string "Version to pass to imgtool when signing"
default "$(APP_VERSION_TWEAK_STRING)" if "$(VERSION_MAJOR)" != ""
Expand Down
10 changes: 10 additions & 0 deletions share/sysbuild/image_configurations/BOOTLOADER_image_default.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,13 @@ foreach(loopkeytype ${keytypes})
set_config_bool(${ZCMAKE_APPLICATION} ${loopkeytype} n)
endif()
endforeach()

if(SB_CONFIG_BOOT_ENCRYPTION)
set_config_bool(${image} CONFIG_BOOT_ENCRYPT_IMAGE y)
set_config_string(${ZCMAKE_APPLICATION} CONFIG_BOOT_ENCRYPTION_KEY_FILE "${SB_CONFIG_BOOT_ENCRYPTION_KEY_FILE}")
if(SB_CONFIG_BOOT_ENCRYPTION_ALG_AES_128)
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_BOOT_ENCRYPT_ALG_AES_128 y)
elseif(SB_CONFIG_BOOT_ENCRYPTION_ALG_AES_256)
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_BOOT_ENCRYPT_ALG_AES_256 y)
endif()
endif()
8 changes: 8 additions & 0 deletions share/sysbuild/image_configurations/MAIN_image_default.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,12 @@ if(SB_CONFIG_BOOTLOADER_MCUBOOT)
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_RETENTION_BOOT_MODE y)
endif()
endif()

if(SB_CONFIG_BOOT_ENCRYPTION)
if(SB_CONFIG_BOOT_ENCRYPTION_ALG_AES_128)
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_ENCRYPTION_ALG_AES_128 y)
elseif(SB_CONFIG_BOOT_ENCRYPTION_ALG_AES_256)
set_config_bool(${ZCMAKE_APPLICATION} CONFIG_MCUBOOT_ENCRYPTION_ALG_AES_256 y)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

endif()
endif()
endif()
4 changes: 0 additions & 4 deletions share/sysbuild/images/bootloader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,4 @@ if(SB_CONFIG_BOOTLOADER_MCUBOOT)
sysbuild_add_dependencies(FLASH ${DEFAULT_IMAGE} ${image})

set_config_string(${image} CONFIG_BOOT_SIGNATURE_KEY_FILE "${SB_CONFIG_BOOT_SIGNATURE_KEY_FILE}")
set_config_bool(${image} CONFIG_BOOT_ENCRYPT_IMAGE "${SB_CONFIG_BOOT_ENCRYPTION}")
if(SB_CONFIG_BOOT_ENCRYPTION)
set_config_string(${image} CONFIG_BOOT_ENCRYPTION_KEY_FILE "${SB_CONFIG_BOOT_ENCRYPTION_KEY_FILE}")
endif()
endif()
16 changes: 16 additions & 0 deletions share/sysbuild/images/bootloader/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,20 @@ config BOOT_ENCRYPTION_KEY_FILE
help
Absolute path to encryption key file to use with MCUBoot.

if BOOT_ENCRYPTION

choice BOOT_ENCRYPTION_ALG
prompt "Algorithm used for image encryption"
default BOOT_ENCRYPTION_ALG_AES_128

config BOOT_ENCRYPTION_ALG_AES_128
bool "Use AES-128 for image encryption"

config BOOT_ENCRYPTION_ALG_AES_256
bool "Use AES-256 for image encryption"

endchoice # BOOT_ENCRYPTION_ALG

endif # BOOT_ENCRYPTION

endif