@@ -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+ )
5662define_property (TARGET
5763 PROPERTY PICOTOOL_OTP_KEY_PAGE
5864 INHERITED
@@ -376,7 +382,7 @@ function(pico_embed_pt_in_binary TARGET PTFILE)
376382 )
377383endfunction ()
378384
379- # pico_encrypt_binary(TARGET AESFILE IVFILE [SIGFILE <file>] [EMBED] [OTP_KEY_PAGE <page>])
385+ # pico_encrypt_binary(TARGET AESFILE IVFILE [SIGFILE <file>] [EMBED] [MBEDTLS] [ OTP_KEY_PAGE <page>])
380386# Encrypt the target binary with the given AES key (should be a binary
381387# file containing 128 bytes of a random key), and sign the encrypted binary.
382388# Salts the public IV with the provided IVFILE (should be a binary file
@@ -385,10 +391,13 @@ endfunction()
385391# PICOTOOL_ENC_SIGFILE to SIGFILE if specified, else PICOTOOL_SIGFILE.
386392# Optionally, use EMBED to embed a decryption stage into the encrypted binary.
387393# This sets PICOTOOL_EMBED_DECRYPTION to TRUE.
394+ # Optionally, use MBEDTLS to to use the MbedTLS based decryption stage - this
395+ # is faster, but less secure.
396+ # This sets PICOTOOL_USE_MBEDTLS_DECRYPTION to TRUE.
388397# Optionally, use OTP_KEY_PAGE to specify the OTP page storing the AES key.
389398# This sets PICOTOOL_OTP_KEY_PAGE to OTP_KEY_PAGE.
390399function (pico_encrypt_binary TARGET AESFILE IVFILE)
391- set (options EMBED)
400+ set (options EMBED MBEDTLS )
392401 set (oneValueArgs OTP_KEY_PAGE SIGFILE)
393402 # set(multiValueArgs )
394403 cmake_parse_arguments (PARSE_ARGV 3 ENC "${options} " "${oneValueArgs} " "${multiValueArgs} " )
@@ -406,6 +415,12 @@ function(pico_encrypt_binary TARGET AESFILE IVFILE)
406415 )
407416 endif ()
408417
418+ if (ENC_MBEDTLS)
419+ set_target_properties (${TARGET} PROPERTIES
420+ PICOTOOL_USE_MBEDTLS_DECRYPTION TRUE
421+ )
422+ endif ()
423+
409424 if (ENC_OTP_KEY_PAGE)
410425 set_target_properties (${TARGET} PROPERTIES
411426 PICOTOOL_OTP_KEY_PAGE ${ENC_OTP_KEY_PAGE}
@@ -572,6 +587,11 @@ function(picotool_postprocess_binary TARGET)
572587 list (APPEND picotool_encrypt_args "--embed" )
573588 endif ()
574589
590+ get_target_property (picotool_mbedtls_decryption ${TARGET} PICOTOOL_USE_MBEDTLS_DECRYPTION)
591+ if (picotool_mbedtls_decryption)
592+ list (APPEND picotool_encrypt_args "--use-mbedtls" )
593+ endif ()
594+
575595 get_target_property (otp_key_page ${TARGET} PICOTOOL_OTP_KEY_PAGE)
576596 if (otp_key_page)
577597 list (APPEND picotool_encrypt_args "--otp-key-page" ${otp_key_page} )
0 commit comments