Skip to content

Commit 98fc1f8

Browse files
authored
Tidy up encrypted examples (#652)
* Add notes about MbedTLS and hardened stages to readme * Modify enc_bootloader example to use latest mbedtls code from picotool Also, fix stdio_uart and stdio_usb output when running clk_sys from rosc, and fix having stdio_usb in both the bootloader and the binary * Mention mbedtls insecurity in enc_bootloader readme
1 parent f9ef15b commit 98fc1f8

File tree

10 files changed

+190
-2062
lines changed

10 files changed

+190
-2062
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ App|Description
9090

9191
App|Description
9292
---|---
93-
[hello_encrypted](encrypted/hello_encrypted) | Create a self-decrypting binary.
93+
[hello_encrypted](encrypted/hello_encrypted) | Create a self-decrypting binary, using the hardened decryption stage. This should be secure against side channel attacks.
94+
[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.
9495

9596
### HSTX (RP235x Only)
9697

bootloaders/encrypted/CMakeLists.txt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
# Encrypted Bootloader
22
add_executable(enc_bootloader
33
enc_bootloader.c
4-
aes.S
4+
mbedtls_aes.c
55
)
66

77
# pull in common dependencies
8-
target_link_libraries(enc_bootloader pico_stdlib pico_rand)
8+
target_link_libraries(enc_bootloader pico_stdlib pico_rand pico_mbedtls)
99

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

13+
target_link_options(enc_bootloader PUBLIC -Wl,--print-memory-usage)
14+
15+
target_include_directories(enc_bootloader PRIVATE ${CMAKE_CURRENT_LIST_DIR})
16+
1317
# set as no_flash binary
1418
pico_set_binary_type(enc_bootloader no_flash)
1519

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

38-
# create linker script to run from 0x20078000
39-
add_linker_script(enc_bootloader "0x20078000" "32k")
42+
# create linker script to run from 0x20070000
43+
add_linker_script(enc_bootloader "0x20070000" "64k")
4044

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

57+
# optionally enable USB output in addition to UART
58+
# pico_enable_stdio_usb(enc_bootloader 1)
59+
5360
# create map/bin/hex/uf2 file etc.
5461
pico_add_extra_outputs(enc_bootloader)
5562

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

93+
# optionally enable USB output in addition to UART
94+
# pico_enable_stdio_usb(hello_serial_enc 1)
95+
8696
# create map/bin/hex/uf2 file etc.
8797
pico_add_extra_outputs(hello_serial_enc)
8898

bootloaders/encrypted/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
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.
22

3+
This bootloader uses MbedTLS for decryption, so it is not secure against side channel attacks and therefore only offers limited protection against physical attackers.
4+
35
Your signing key must be for the _secp256k1_ curve, in PEM format. You can create a .PEM file with:
46

57
```bash

0 commit comments

Comments
 (0)