@@ -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
@@ -398,7 +404,7 @@ function(pico_embed_pt_in_binary TARGET PTFILE)
398
404
)
399
405
endfunction ()
400
406
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>])
402
408
# Encrypt the target binary with the given AES key (should be a binary
403
409
# file containing 128 bytes of a random key), and sign the encrypted binary.
404
410
# Salts the public IV with the provided IVFILE (should be a binary file
@@ -407,10 +413,13 @@ endfunction()
407
413
# PICOTOOL_ENC_SIGFILE to SIGFILE if specified, else PICOTOOL_SIGFILE.
408
414
# Optionally, use EMBED to embed a decryption stage into the encrypted binary.
409
415
# 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.
410
419
# Optionally, use OTP_KEY_PAGE to specify the OTP page storing the AES key.
411
420
# This sets PICOTOOL_OTP_KEY_PAGE to OTP_KEY_PAGE.
412
421
function (pico_encrypt_binary TARGET AESFILE IVFILE)
413
- set (options EMBED)
422
+ set (options EMBED MBEDTLS )
414
423
set (oneValueArgs OTP_KEY_PAGE SIGFILE)
415
424
# set(multiValueArgs )
416
425
cmake_parse_arguments (PARSE_ARGV 3 ENC "${options} " "${oneValueArgs} " "${multiValueArgs} " )
@@ -428,6 +437,12 @@ function(pico_encrypt_binary TARGET AESFILE IVFILE)
428
437
)
429
438
endif ()
430
439
440
+ if (ENC_MBEDTLS)
441
+ set_target_properties (${TARGET} PROPERTIES
442
+ PICOTOOL_USE_MBEDTLS_DECRYPTION TRUE
443
+ )
444
+ endif ()
445
+
431
446
if (ENC_OTP_KEY_PAGE)
432
447
set_target_properties (${TARGET} PROPERTIES
433
448
PICOTOOL_OTP_KEY_PAGE ${ENC_OTP_KEY_PAGE}
@@ -600,6 +615,11 @@ function(picotool_postprocess_binary TARGET)
600
615
list (APPEND picotool_encrypt_args "--embed" )
601
616
endif ()
602
617
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
+
603
623
get_target_property (otp_key_page ${TARGET} PICOTOOL_OTP_KEY_PAGE)
604
624
if (otp_key_page)
605
625
list (APPEND picotool_encrypt_args "--otp-key-page" ${otp_key_page} )
0 commit comments