Skip to content

Commit 06295b4

Browse files
committed
Add MbedTLS self-decrypting example
1 parent 25d5b43 commit 06295b4

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

encrypted/hello_encrypted/CMakeLists.txt

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,51 @@ pico_add_extra_outputs(hello_encrypted)
4646

4747
# add url via pico_set_program_url
4848
example_auto_set_url(hello_encrypted)
49+
50+
51+
# Example encrypted binary using MbedTLS
52+
add_executable(hello_encrypted_mbedtls
53+
hello_encrypted.c
54+
secret.S
55+
)
56+
57+
# include directory containing secret.txt
58+
target_include_directories(hello_encrypted_mbedtls PRIVATE ${CMAKE_CURRENT_LIST_DIR})
59+
60+
# pull in common dependencies
61+
target_link_libraries(hello_encrypted_mbedtls pico_stdlib)
62+
63+
# enable stdio_usb and stdio_uart
64+
pico_enable_stdio_uart(hello_encrypted_mbedtls 1)
65+
pico_enable_stdio_usb(hello_encrypted_mbedtls 1)
66+
67+
# set as no_flash binary
68+
pico_set_binary_type(hello_encrypted_mbedtls no_flash)
69+
70+
# set version (optional)
71+
pico_set_binary_version(hello_encrypted_mbedtls MAJOR 7 MINOR 3)
72+
73+
# set tbyb (optional)
74+
# target_compile_definitions(hello_encrypted_mbedtls PRIVATE PICO_CRT0_IMAGE_TYPE_TBYB=1)
75+
76+
# configure otp output
77+
pico_set_otp_key_output_file(hello_encrypted_mbedtls ${CMAKE_CURRENT_BINARY_DIR}/otp_mbedtls.json)
78+
79+
# sign, hash, and encrypt using MbedTLS
80+
pico_sign_binary(hello_encrypted_mbedtls ${CMAKE_CURRENT_LIST_DIR}/private.pem)
81+
pico_hash_binary(hello_encrypted_mbedtls)
82+
pico_encrypt_binary(hello_encrypted_mbedtls
83+
${CMAKE_CURRENT_LIST_DIR}/privateaes.bin
84+
${CMAKE_CURRENT_LIST_DIR}/ivsalt.bin
85+
EMBED
86+
MBEDTLS
87+
OTP_KEY_PAGE 29)
88+
89+
# package uf2 in flash
90+
pico_package_uf2_output(hello_encrypted_mbedtls 0x10000000)
91+
92+
# create map/bin/hex/uf2 file etc.
93+
pico_add_extra_outputs(hello_encrypted_mbedtls)
94+
95+
# add url via pico_set_program_url
96+
example_auto_set_url(hello_encrypted_mbedtls)

0 commit comments

Comments
 (0)