-
Notifications
You must be signed in to change notification settings - Fork 135
Add support for creating self-decrypting binaries, and use 4-way AES key shares instead of just the AES key #207
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
Conversation
8ad52d7
to
28c0335
Compare
|
|
A few other random thoughts
|
I wonder if we should explicitly zero unused RAM in the LOAD_MAP of the self-encrypting binary (probably) |
These only cause issues when encrypting, as the old block needs to be included in the new load_map When signing, the old load_map can be used again without issue
Prints XXs for any rows with permissions failures Also, add `--pages` option to index by page & row (eg 63:56) rather than hex (eg 0ff8)
Modify aes.S init_key_4way to skip the 64 byte gap in the middle of the otp key share Uses 5 words of space
f0226e9
to
6743582
Compare
See the encrypted-shares-ci branch for passing CI, which now requires different SDK and examples branches due to the examples build test |
Perhaps the original comment in this PR ought to be updated to say which other pico-sdk and pico-examples PRs ought to be merged before (or in parallel with?) this PR. |
Add more notes to AES readme, fix error message, and remove commented CMake line
More details will be in the C SDK book
picotool encrypt [--quiet] [--verbose] [--embed] [--fast-rosc] [--use-mbedtls] [--otp-key-page <page>] [--hash] [--sign] <infile> [-t | ||
<type>] [-o <offset>] <outfile> [-t <type>] <aes_key> <iv_salt> <signing_key> <otp> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How hard would it be to modify the line-wrapping to prevent a line-break getting inserted in the middle of e.g. [-t <type>]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that's handled by the CLIPP library, so probably a question for @kilograham whether we want to change that code?
Lines 317 to 363 in c56c005
/** @brief handle line wrapping due to column constraints */ | |
template<class Iter> | |
void write_line(Iter first, Iter last) | |
{ | |
if(first == last) return; | |
if(only_whitespace(first, last)) return; | |
if(right_of_text_area()) wrap_soft(); | |
if(at_begin_of_line()) { | |
//discard whitespace, it we start a new line | |
first = std::find_if(first, last, | |
[](char_type c) { return !std::isspace(c); }); | |
if(first == last) return; | |
} | |
const auto n = int(std::distance(first,last)); | |
const auto m = columns_left_in_line(); | |
//if text to be printed is too long for one line -> wrap | |
if(n > m) { | |
//break before word, if break is mid-word | |
auto breakat = first + m; | |
while(breakat > first && !std::isspace(*breakat)) --breakat; | |
//could not find whitespace before word -> try after the word | |
if(!std::isspace(*breakat) && breakat == first) { | |
breakat = std::find_if(first+m, last, | |
[](char_type c) { return std::isspace(c); }); | |
} | |
if(breakat > first) { | |
if(curCol_ < 1) ++totalNonBlankLines_; | |
fix_indent(); | |
std::copy(first, breakat, std::ostream_iterator<char_type>(os_)); | |
curBlankLines_ = 0; | |
} | |
if(breakat < last) { | |
wrap_soft(); | |
write_line(breakat, last); | |
} | |
} | |
else { | |
if(curCol_ < 1) ++totalNonBlankLines_; | |
fix_indent(); | |
std::copy(first, last, std::ostream_iterator<char_type>(os_)); | |
curCol_ += n; | |
curBlankLines_ = 0; | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, sounds like There Be Dragons 🐉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not convinced that's much more helpful. Really thinking about something that helps the user know what happened and what to do - in the RP2040 case it doesn't really make sense to be signing anyway, no?
It is a valid use case to be sealing an RP2040 binary, as an RP2350 may want to hash/signature check an RP2040 binary before loading it onto an RP2040. Would this error message be clearer:
|
This is required due to 2.1.0 and 2.1.1 SDK releases pointing at picotool develop branch rather than the respective picotool releases (raspberrypi/pico-sdk#2401)
This adds support for creating self-decrypting binaries, which can be created using
This introduces a breaking change to
picotool encrypt
to take a 4-way AES key share, rather than just taking an AES key, as this makes it simpler to mask the power signature when decrypting the binary. The only difference from a user perspective is that they now need to use a 1024 bit binary file instead of the 256 bit file used before. The AES key is derived from the 4-way share as follows:This also introduces a breaking change that
picotool encrypt
now requires an IV salt binary to be passed to it as the 4th file, so the signing_key is now the 5th file and the OTP JSON is now the 6th file.This PR should be merged in parallel with raspberrypi/pico-sdk#2315 and raspberrypi/pico-examples#619 to avoid breaking the pico-examples encrypted bootloader compilation