-
Notifications
You must be signed in to change notification settings - Fork 128
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
Add support for creating self-decrypting binaries, and use 4-way AES key shares instead of just the AES key #207
base: develop
Are you sure you want to change the base?
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) |
If the last block has an image_def, then it is a better choice of block than the first block, so the items for the new block should be copied from it instead
enc_bootloader requires SDK 2.1.2 rename binary_data to embedded_data move mbedtls TODO into header
expand comment on configuring mbedtls 2.0.0->2.1.2 message reword mbedtls todo
These would mess up signing/encryption of an already signed/encrypted binary
Remove they -t argument from all key files (bin & pem) and JSON files, as they should always have the correct extension so it's not necessary
Implement suggested changes, and add note about IV salt
Specify file types where useful for untyped files (json, pem, bin) Expand IV salt description Abstract filename_to_hex_array into separate function
0bddfcc
to
620f448
Compare
Rebased onto the latest develop branch |
bool filename_to_hex_array(uint8_t idx, uint8_t *array, size_t size) { | ||
auto filename = settings.filenames[idx]; |
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.
IMHO this function would feel more self-contained if it was directly passed the string, instead of being passed an index into an array? 😕
if (!filename.empty() && filename.find("0x") == 0) { | ||
// Hex string instead of file | ||
if (filename.size() != size*2 + 2) { | ||
fail(ERROR_ARGS, "Hex string must be %d characters long (the supplied string is %d characters)", size*2, filename.size() - 2); |
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.
Hmmm, maybe this function should also be passed some kind of identifier to be used in the error-messages? 🤔 Because I guess if you passed both the AES key and also the salt by hex-value, then with this current message you wouldn't know which one of them was wrong!
Remove uneccessary extra setup, which isn't actually required and throws deprecation warnings in CMake 4.0.0
…ach OTP page Disabled for now behind `#if FIB_WORKAROUND`, until the bootloader change to handle this is implemented
Quick note about TBYB functionality - TLDR is that after being bought, the encrypted binary will need to call For TBYB to work, it must be set on both the outer decrypting bootloader and the inner encrypted binary. This is because if it is only set on the outer bootloader, then the With it set on both the outer bootloader and the inner binary, on first boot both the bootloader and inner binary will boot with TBYB, and then the inner binary can call On subsequent boots, the outer bootloader will boot without TBYB, but the inner binary will have TBYB set by the The following would be an example of the TBYB process for an encrypted binary: boot_info_t boot_info = {};
int ret = rom_get_boot_info(&boot_info);
if (ret) {
if (boot_info.tbyb_and_update_info & BOOT_TBYB_AND_UPDATE_FLAG_BUY_PENDING) {
uint32_t flash_update_base = boot_info.reboot_params[0];
if (flash_update_base) {
// Do self-check etc
}
uint32_t buf_size = flash_update_base ? 4096 : 0;
uint8_t* buffer = flash_update_base ? malloc(buf_size) : NULL;
int ret = rom_explicit_buy(buffer, buf_size);
assert(ret == 0);
if (buffer) free(buffer);
}
} as opposed to a normal binary which wouldn't need to check the |
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
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 requires raspberrypi/pico-sdk#2233 so should be merged after that