@@ -53,6 +53,12 @@ define_property(TARGET
53
53
BRIEF_DOCS "Embed decryption stage into encrypted binary"
54
54
FULL_DOCS "Embed decryption stage into encrypted binary"
55
55
)
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
+ )
56
62
define_property (TARGET
57
63
PROPERTY PICOTOOL_OTP_KEY_PAGE
58
64
INHERITED
@@ -376,7 +382,7 @@ function(pico_embed_pt_in_binary TARGET PTFILE)
376
382
)
377
383
endfunction ()
378
384
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>])
380
386
# Encrypt the target binary with the given AES key (should be a binary
381
387
# file containing 128 bytes of a random key), and sign the encrypted binary.
382
388
# Salts the public IV with the provided IVFILE (should be a binary file
@@ -385,10 +391,13 @@ endfunction()
385
391
# PICOTOOL_ENC_SIGFILE to SIGFILE if specified, else PICOTOOL_SIGFILE.
386
392
# Optionally, use EMBED to embed a decryption stage into the encrypted binary.
387
393
# 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.
388
397
# Optionally, use OTP_KEY_PAGE to specify the OTP page storing the AES key.
389
398
# This sets PICOTOOL_OTP_KEY_PAGE to OTP_KEY_PAGE.
390
399
function (pico_encrypt_binary TARGET AESFILE IVFILE)
391
- set (options EMBED)
400
+ set (options EMBED MBEDTLS )
392
401
set (oneValueArgs OTP_KEY_PAGE SIGFILE)
393
402
# set(multiValueArgs )
394
403
cmake_parse_arguments (PARSE_ARGV 3 ENC "${options} " "${oneValueArgs} " "${multiValueArgs} " )
@@ -406,6 +415,12 @@ function(pico_encrypt_binary TARGET AESFILE IVFILE)
406
415
)
407
416
endif ()
408
417
418
+ if (ENC_MBEDTLS)
419
+ set_target_properties (${TARGET} PROPERTIES
420
+ PICOTOOL_USE_MBEDTLS_DECRYPTION TRUE
421
+ )
422
+ endif ()
423
+
409
424
if (ENC_OTP_KEY_PAGE)
410
425
set_target_properties (${TARGET} PROPERTIES
411
426
PICOTOOL_OTP_KEY_PAGE ${ENC_OTP_KEY_PAGE}
@@ -572,6 +587,11 @@ function(picotool_postprocess_binary TARGET)
572
587
list (APPEND picotool_encrypt_args "--embed" )
573
588
endif ()
574
589
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
+
575
595
get_target_property (otp_key_page ${TARGET} PICOTOOL_OTP_KEY_PAGE)
576
596
if (otp_key_page)
577
597
list (APPEND picotool_encrypt_args "--otp-key-page" ${otp_key_page} )
0 commit comments