Skip to content

Commit a969a7d

Browse files
committed
Shrink IV storage size
Use bi_ptr_string instead of 4 bi_ptr_int32s
1 parent c13c61a commit a969a7d

File tree

2 files changed

+5
-16
lines changed

2 files changed

+5
-16
lines changed

enc_bootloader/enc_bootloader.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -282,25 +282,15 @@ int main() {
282282

283283
bi_decl(bi_ptr_int32(0, 0, data_start_addr, 0x20000000));
284284
bi_decl(bi_ptr_int32(0, 0, data_size, 0x78000));
285-
bi_decl(bi_ptr_int32(0, 0, iv0, 0));
286-
bi_decl(bi_ptr_int32(0, 0, iv1, 1));
287-
bi_decl(bi_ptr_int32(0, 0, iv2, 2));
288-
bi_decl(bi_ptr_int32(0, 0, iv3, 3));
285+
bi_decl(bi_ptr_string(0, 0, iv, "0123456789abcdef", 17))
289286
bi_decl(bi_ptr_int32(0, 0, otp_key_page, 30));
290287

291-
// Initialise IV from binary info words
292-
uint8_t iv[16];
293-
memcpy(iv, (void*)&iv0, sizeof(iv0));
294-
memcpy(iv + 4, (void*)&iv1, sizeof(iv1));
295-
memcpy(iv + 8, (void*)&iv2, sizeof(iv2));
296-
memcpy(iv + 12, (void*)&iv3, sizeof(iv3));
297-
298288
// Initialise random state
299289
init_rstate();
300290

301291
// Read key directly from OTP - guarded reads will throw a bus fault if there are any errors
302292
uint16_t* otp_data = (uint16_t*)OTP_DATA_GUARDED_BASE;
303-
decrypt((uint8_t*)&(otp_data[(OTP_CMD_ROW_BITS & (otp_key_page * 0x40))]), iv, (void*)data_start_addr, data_size/16);
293+
decrypt((uint8_t*)&(otp_data[(OTP_CMD_ROW_BITS & (otp_key_page * 0x40))]), (uint8_t*)iv, (void*)data_start_addr, data_size/16);
304294
otp_hw->sw_lock[otp_key_page] = 0xf;
305295

306296
// Increase stack limit by 0x100

main.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5008,10 +5008,9 @@ bool encrypt_command::execute(device_map &devices) {
50085008
config_guts(program);
50095009
// iv
50105010
for (int i=0; i < 4; i++) {
5011-
std::stringstream ss;
5012-
ss << "iv" << i;
5013-
settings.config.key = ss.str();
5014-
settings.config.value = hex_string(*(uint32_t*)(iv_data.data() + i*sizeof(uint32_t)));
5011+
string s((char*)iv_data.data(), iv_data.size());
5012+
settings.config.key = "iv";
5013+
settings.config.value = s;
50155014
config_guts(program);
50165015
}
50175016
// otp_key_page

0 commit comments

Comments
 (0)