@@ -41,6 +41,12 @@ define_property(TARGET
41
41
BRIEF_DOCS "AES key for encrypting"
42
42
FULL_DOCS "AES key for encrypting"
43
43
)
44
+ define_property (TARGET
45
+ PROPERTY PICOTOOL_IVFILE
46
+ INHERITED
47
+ BRIEF_DOCS "IV OTP salt for encrypting"
48
+ FULL_DOCS "IV OTP salt for encrypting"
49
+ )
44
50
define_property (TARGET
45
51
PROPERTY PICOTOOL_EMBED_DECRYPTION
46
52
INHERITED
@@ -370,24 +376,29 @@ function(pico_embed_pt_in_binary TARGET PTFILE)
370
376
)
371
377
endfunction ()
372
378
373
- # pico_encrypt_binary(TARGET AESFILE [SIGFILE <file>] [EMBED] [OTP_KEY_PAGE <page>])
379
+ # pico_encrypt_binary(TARGET AESFILE IVFILE [SIGFILE <file>] [EMBED] [OTP_KEY_PAGE <page>])
374
380
# Encrypt the target binary with the given AES key (should be a binary
375
381
# file containing 128 bytes of a random key), and sign the encrypted binary.
376
- # This sets PICOTOOL_AESFILE to AESFILE, and PICOTOOL_ENC_SIGFILE to SIGFILE
377
- # if present, else PICOTOOL_SIGFILE.
382
+ # Salts the public IV with the provided IVFILE (should be a binary file
383
+ # containing 16 bytes of a random IV), to give the IV used by the encryption.
384
+ # This sets PICOTOOL_AESFILE to AESFILE, PICOTOOL_IVFILE to IVFILE, and
385
+ # PICOTOOL_ENC_SIGFILE to SIGFILE if specified, else PICOTOOL_SIGFILE.
378
386
# Optionally, use EMBED to embed a decryption stage into the encrypted binary.
379
387
# This sets PICOTOOL_EMBED_DECRYPTION to TRUE.
380
388
# Optionally, use OTP_KEY_PAGE to specify the OTP page storing the AES key.
381
389
# This sets PICOTOOL_OTP_KEY_PAGE to OTP_KEY_PAGE.
382
- function (pico_encrypt_binary TARGET AESFILE)
390
+ function (pico_encrypt_binary TARGET AESFILE IVFILE )
383
391
set (options EMBED)
384
392
set (oneValueArgs OTP_KEY_PAGE SIGFILE)
385
393
# set(multiValueArgs )
386
- cmake_parse_arguments (PARSE_ARGV 2 ENC "${options} " "${oneValueArgs} " "${multiValueArgs} " )
394
+ cmake_parse_arguments (PARSE_ARGV 3 ENC "${options} " "${oneValueArgs} " "${multiValueArgs} " )
387
395
picotool_check_configurable(${TARGET} )
388
396
set_target_properties (${TARGET} PROPERTIES
389
397
PICOTOOL_AESFILE ${AESFILE}
390
398
)
399
+ set_target_properties (${TARGET} PROPERTIES
400
+ PICOTOOL_IVFILE ${IVFILE}
401
+ )
391
402
392
403
if (ENC_EMBED)
393
404
set_target_properties (${TARGET} PROPERTIES
@@ -512,6 +523,10 @@ function(picotool_postprocess_binary TARGET)
512
523
if (picotool_aesfile)
513
524
pico_add_link_depend(${TARGET} ${picotool_aesfile} )
514
525
endif ()
526
+ get_target_property (picotool_ivfile ${TARGET} PICOTOOL_IVFILE)
527
+ if (picotool_ivfile)
528
+ pico_add_link_depend(${TARGET} ${picotool_ivfile} )
529
+ endif ()
515
530
get_target_property (picotool_enc_sigfile ${TARGET} PICOTOOL_ENC_SIGFILE)
516
531
if (picotool_enc_sigfile)
517
532
pico_add_link_depend(${TARGET} ${picotool_enc_sigfile} )
@@ -551,7 +566,7 @@ function(picotool_postprocess_binary TARGET)
551
566
VERBATIM )
552
567
endif ()
553
568
# Encryption
554
- if (picotool_aesfile)
569
+ if (picotool_aesfile AND picotool_ivfile )
555
570
get_target_property (picotool_embed_decryption ${TARGET} PICOTOOL_EMBED_DECRYPTION)
556
571
if (picotool_embed_decryption)
557
572
list (APPEND picotool_encrypt_args "--embed" )
@@ -563,13 +578,13 @@ function(picotool_postprocess_binary TARGET)
563
578
endif ()
564
579
565
580
add_custom_command (TARGET ${TARGET} POST_BUILD
566
- DEPENDS ${picotool_enc_sigfile} ${picotool_aesfile}
581
+ DEPENDS ${picotool_enc_sigfile} ${picotool_aesfile} ${picotool_ivfile}
567
582
COMMAND picotool
568
583
ARGS encrypt
569
584
--quiet --hash --sign
570
585
${picotool_encrypt_args}
571
586
$<TARGET_FILE:${TARGET} > $<TARGET_FILE:${TARGET} >
572
- ${picotool_aesfile} ${picotool_enc_sigfile} ${otp_file}
587
+ ${picotool_aesfile} ${picotool_ivfile} ${ picotool_enc_sigfile} ${otp_file}
573
588
COMMAND_EXPAND_LISTS
574
589
VERBATIM )
575
590
if (ARGC EQUAL 2)
0 commit comments