Skip to content

Tidy up encrypted examples #652

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ App|Description

App|Description
---|---
[hello_encrypted](encrypted/hello_encrypted) | Create a self-decrypting binary.
[hello_encrypted](encrypted/hello_encrypted) | Create a self-decrypting binary, using the hardened decryption stage. This should be secure against side channel attacks.
[hello_encrypted_mbedtls](encrypted/hello_encrypted) | Create a self-decrypting binary, using the MbedTLS decryption stage. This is not secure against side channel attacks, so is fast but provides limited protection.

### HSTX (RP235x Only)

Expand Down
18 changes: 14 additions & 4 deletions bootloaders/encrypted/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# Encrypted Bootloader
add_executable(enc_bootloader
enc_bootloader.c
aes.S
mbedtls_aes.c
)

# pull in common dependencies
target_link_libraries(enc_bootloader pico_stdlib pico_rand)
target_link_libraries(enc_bootloader pico_stdlib pico_rand pico_mbedtls)

# use stack guards, as AES variables are written near the stack
target_compile_definitions(enc_bootloader PRIVATE PICO_USE_STACK_GUARDS=1)

target_link_options(enc_bootloader PUBLIC -Wl,--print-memory-usage)

target_include_directories(enc_bootloader PRIVATE ${CMAKE_CURRENT_LIST_DIR})

# set as no_flash binary
pico_set_binary_type(enc_bootloader no_flash)

Expand All @@ -35,8 +39,8 @@ function(add_linker_script target origin length)
pico_set_linker_script(${target} ${CMAKE_CURRENT_BINARY_DIR}/${target}.ld)
endfunction()

# create linker script to run from 0x20078000
add_linker_script(enc_bootloader "0x20078000" "32k")
# create linker script to run from 0x20070000
add_linker_script(enc_bootloader "0x20070000" "64k")

# sign, hash, and clear SRAM
pico_sign_binary(enc_bootloader ${CMAKE_CURRENT_LIST_DIR}/private.pem)
Expand All @@ -50,6 +54,9 @@ pico_embed_pt_in_binary(enc_bootloader ${CMAKE_CURRENT_LIST_DIR}/enc-pt.json)
pico_set_uf2_family(enc_bootloader "absolute")
pico_package_uf2_output(enc_bootloader 0x10000000)

# optionally enable USB output in addition to UART
# pico_enable_stdio_usb(enc_bootloader 1)

# create map/bin/hex/uf2 file etc.
pico_add_extra_outputs(enc_bootloader)

Expand Down Expand Up @@ -83,6 +90,9 @@ pico_encrypt_binary(hello_serial_enc ${CMAKE_CURRENT_LIST_DIR}/privateaes.bin ${
# package uf2 in flash
pico_package_uf2_output(hello_serial_enc 0x10000000)

# optionally enable USB output in addition to UART
# pico_enable_stdio_usb(hello_serial_enc 1)

# create map/bin/hex/uf2 file etc.
pico_add_extra_outputs(hello_serial_enc)

Expand Down
2 changes: 2 additions & 0 deletions bootloaders/encrypted/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
For security you **must** replace private.pem and privateaes.bin with your own keys, and ivsalt.bin with your own per-device salt. Make sure you **don't lose your keys and salts**, else you may not be able to update the code on your device.

This bootloader uses MbedTLS for decryption, so it is not secure against side channel attacks and therefore only offers limited protection against physical attackers.

Your signing key must be for the _secp256k1_ curve, in PEM format. You can create a .PEM file with:

```bash
Expand Down
Loading