Skip to content

Commit dc1f3df

Browse files
committed
Add MBEDTLS option to use mbedtls decryption stage
1 parent 2d0ecd5 commit dc1f3df

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

tools/CMakeLists.txt

+22-2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ define_property(TARGET
5353
BRIEF_DOCS "Embed decryption stage into encrypted binary"
5454
FULL_DOCS "Embed decryption stage into encrypted binary"
5555
)
56+
define_property(TARGET
57+
PROPERTY PICOTOOL_USE_MBEDTLS_DECRYPTION
58+
INHERITED
59+
BRIEF_DOCS "Use MbedTLS based decryption stage - this is faster, but not secure against power snooping"
60+
FULL_DOCS "Use MbedTLS based decryption stage - this is faster, but not secure against power snooping"
61+
)
5662
define_property(TARGET
5763
PROPERTY PICOTOOL_OTP_KEY_PAGE
5864
INHERITED
@@ -398,7 +404,7 @@ function(pico_embed_pt_in_binary TARGET PTFILE)
398404
)
399405
endfunction()
400406

401-
# pico_encrypt_binary(TARGET AESFILE IVFILE [SIGFILE <file>] [EMBED] [OTP_KEY_PAGE <page>])
407+
# pico_encrypt_binary(TARGET AESFILE IVFILE [SIGFILE <file>] [EMBED] [MBEDTLS] [OTP_KEY_PAGE <page>])
402408
# Encrypt the target binary with the given AES key (should be a binary
403409
# file containing 128 bytes of a random key), and sign the encrypted binary.
404410
# Salts the public IV with the provided IVFILE (should be a binary file
@@ -407,10 +413,13 @@ endfunction()
407413
# PICOTOOL_ENC_SIGFILE to SIGFILE if specified, else PICOTOOL_SIGFILE.
408414
# Optionally, use EMBED to embed a decryption stage into the encrypted binary.
409415
# This sets PICOTOOL_EMBED_DECRYPTION to TRUE.
416+
# Optionally, use MBEDTLS to to use the MbedTLS based decryption stage - this
417+
# is faster, but less secure.
418+
# This sets PICOTOOL_USE_MBEDTLS_DECRYPTION to TRUE.
410419
# Optionally, use OTP_KEY_PAGE to specify the OTP page storing the AES key.
411420
# This sets PICOTOOL_OTP_KEY_PAGE to OTP_KEY_PAGE.
412421
function(pico_encrypt_binary TARGET AESFILE IVFILE)
413-
set(options EMBED)
422+
set(options EMBED MBEDTLS)
414423
set(oneValueArgs OTP_KEY_PAGE SIGFILE)
415424
# set(multiValueArgs )
416425
cmake_parse_arguments(PARSE_ARGV 3 ENC "${options}" "${oneValueArgs}" "${multiValueArgs}")
@@ -428,6 +437,12 @@ function(pico_encrypt_binary TARGET AESFILE IVFILE)
428437
)
429438
endif()
430439

440+
if (ENC_MBEDTLS)
441+
set_target_properties(${TARGET} PROPERTIES
442+
PICOTOOL_USE_MBEDTLS_DECRYPTION TRUE
443+
)
444+
endif()
445+
431446
if (ENC_OTP_KEY_PAGE)
432447
set_target_properties(${TARGET} PROPERTIES
433448
PICOTOOL_OTP_KEY_PAGE ${ENC_OTP_KEY_PAGE}
@@ -600,6 +615,11 @@ function(picotool_postprocess_binary TARGET)
600615
list(APPEND picotool_encrypt_args "--embed")
601616
endif()
602617

618+
get_target_property(picotool_mbedtls_decryption ${TARGET} PICOTOOL_USE_MBEDTLS_DECRYPTION)
619+
if (picotool_mbedtls_decryption)
620+
list(APPEND picotool_encrypt_args "--use-mbedtls")
621+
endif()
622+
603623
get_target_property(otp_key_page ${TARGET} PICOTOOL_OTP_KEY_PAGE)
604624
if (otp_key_page)
605625
list(APPEND picotool_encrypt_args "--otp-key-page" ${otp_key_page})

0 commit comments

Comments
 (0)