Skip to content

Commit 6743582

Browse files
committed
Modify bootloader to work with FIB workaround
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
1 parent f018f89 commit 6743582

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

enc_bootloader/aes.S

+7-1
Original file line numberDiff line numberDiff line change
@@ -1441,7 +1441,7 @@ storeroundkey:
14411441
.balign 4
14421442
.thumb_func
14431443
init_key_4way:
1444-
@ On entry, r0 points to 4-way shared raw key data (128 bytes)
1444+
@ On entry, r0 points to 4-way shared raw key data (64 bytes, 64 byte gap for FIB workaround, then other 64 bytes)
14451445
@ The format is a0 b0 c0 d0 a1 b1 c1 d1 ... a7 b7 c7 d7
14461446
@ That is, each word, K, of the original 256-bit key is expanded into four words whose exclusive OR is K.
14471447
@
@@ -1464,12 +1464,18 @@ init_key_4way:
14641464
bl randomisechaff
14651465
ldr r6,=rkey4way
14661466
movs r7,#8
1467+
b 1f
1468+
2:
1469+
adds r5,#64 @ Skip 64 byte gap for FIB workaround
1470+
subs r7,r7,#1
14671471
1:
14681472
ldmia r5!,{r1-r4}
14691473
bl gen_rand_sha; eors r1,r1,r0; eors r4,r4,r0
14701474
bl gen_rand_sha; eors r2,r2,r0; eors r4,r4,r0
14711475
bl gen_rand_sha; eors r3,r3,r0; eors r4,r4,r0
14721476
stmia r6!,{r1-r4}
1477+
cmp r7,#5
1478+
beq 2b
14731479
subs r7,r7,#1
14741480
bne 1b
14751481

enc_bootloader/enc_bootloader.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ bi_decl(bi_ptr_int32(0, 0, otp_key_page, 30));
153153
// That is a suitable point to lock the OTP area where key information is stored.
154154
void lock_key() {
155155
otp_hw->sw_lock[otp_key_page] = 0xf;
156+
otp_hw->sw_lock[otp_key_page + 1] = 0xf;
156157
}
157158

158159

@@ -165,14 +166,14 @@ int main() {
165166
uint16_t* otp_data = (uint16_t*)OTP_DATA_GUARDED_BASE;
166167
decrypt(
167168
(uint8_t*)&(otp_data[otp_key_page * 0x40]),
168-
(uint8_t*)&(otp_data[(otp_key_page + 1) * 0x40]),
169+
(uint8_t*)&(otp_data[(otp_key_page + 2) * 0x40]),
169170
(uint8_t*)iv,
170171
(void*)data_start_addr,
171172
data_size/16
172173
);
173174

174175
// Lock the IV salt
175-
otp_hw->sw_lock[otp_key_page + 1] = 0xf;
176+
otp_hw->sw_lock[otp_key_page + 2] = 0xf;
176177

177178
// Increase stack limit by 0x100
178179
pico_default_asm_volatile(

main.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -5321,6 +5321,7 @@ bool encrypt_command::execute(device_map &devices) {
53215321
}
53225322
auto json_out = get_file_idx(ios::out, 5);
53235323

5324+
#define FIB_WORKAROUND 1
53245325
#if FIB_WORKAROUND
53255326
// Make inverse pages to work around OTP FIB attack
53265327
vector<uint8_t> page0_data;

0 commit comments

Comments
 (0)