Skip to content

Commit 80f9867

Browse files
committed
Add MBEDTLS option to use mbedtls decryption stage
1 parent 2305932 commit 80f9867

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

tools/CMakeLists.txt

Lines changed: 25 additions & 2 deletions
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
@@ -438,7 +444,7 @@ function(pico_embed_pt_in_binary TARGET PTFILE)
438444
)
439445
endfunction()
440446

441-
# pico_encrypt_binary(TARGET AESFILE IVFILE [SIGFILE <file>] [EMBED] [OTP_KEY_PAGE <page>])
447+
# pico_encrypt_binary(TARGET AESFILE IVFILE [SIGFILE <file>] [EMBED] [MBEDTLS] [OTP_KEY_PAGE <page>])
442448
# \brief_nodesc\ Encrypt the taget binary
443449
#
444450
# Encrypt the target binary with the given AES key (should be a binary
@@ -453,15 +459,21 @@ endfunction()
453459
# Optionally, use EMBED to embed a decryption stage into the encrypted binary.
454460
# This sets the target property PICOTOOL_EMBED_DECRYPTION to TRUE.
455461
#
462+
# Optionally, use MBEDTLS to to use the MbedTLS based decryption stage - this
463+
# is faster, but less secure.
464+
# This sets the target property PICOTOOL_USE_MBEDTLS_DECRYPTION to TRUE.
465+
#
456466
# Optionally, use OTP_KEY_PAGE to specify the OTP page storing the AES key.
457467
# This sets the target property PICOTOOL_OTP_KEY_PAGE to OTP_KEY_PAGE.
458468
#
459469
# \param\ AESFILE The AES key file to use
470+
# \param\ IVFILE The IV file to use
460471
# \param\ SIGFILE The PEM signature file to use
461472
# \param\ EMBED Embed a decryption stage into the encrypted binary
473+
# \param\ MBEDTLS Use MbedTLS based decryption stage (faster, but less secure)
462474
# \param\ OTP_KEY_PAGE The OTP page storing the AES key
463475
function(pico_encrypt_binary TARGET AESFILE IVFILE)
464-
set(options EMBED)
476+
set(options EMBED MBEDTLS)
465477
set(oneValueArgs OTP_KEY_PAGE SIGFILE)
466478
# set(multiValueArgs )
467479
cmake_parse_arguments(PARSE_ARGV 3 ENC "${options}" "${oneValueArgs}" "${multiValueArgs}")
@@ -479,6 +491,12 @@ function(pico_encrypt_binary TARGET AESFILE IVFILE)
479491
)
480492
endif()
481493

494+
if (ENC_MBEDTLS)
495+
set_target_properties(${TARGET} PROPERTIES
496+
PICOTOOL_USE_MBEDTLS_DECRYPTION TRUE
497+
)
498+
endif()
499+
482500
if (ENC_OTP_KEY_PAGE)
483501
set_target_properties(${TARGET} PROPERTIES
484502
PICOTOOL_OTP_KEY_PAGE ${ENC_OTP_KEY_PAGE}
@@ -653,6 +671,11 @@ function(picotool_postprocess_binary TARGET)
653671
list(APPEND picotool_encrypt_args "--embed")
654672
endif()
655673

674+
get_target_property(picotool_mbedtls_decryption ${TARGET} PICOTOOL_USE_MBEDTLS_DECRYPTION)
675+
if (picotool_mbedtls_decryption)
676+
list(APPEND picotool_encrypt_args "--use-mbedtls")
677+
endif()
678+
656679
get_target_property(otp_key_page ${TARGET} PICOTOOL_OTP_KEY_PAGE)
657680
if (otp_key_page)
658681
list(APPEND picotool_encrypt_args "--otp-key-page" ${otp_key_page})

0 commit comments

Comments
 (0)