-
Notifications
You must be signed in to change notification settings - Fork 46
180726/nits #224
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
180726/nits #224
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,11 @@ | |
#endif | ||
|
||
|
||
#if (MEM_PAGE_LEN != SHA256_DIGEST_LENGTH) | ||
#error "Incompatible macro values" | ||
#endif | ||
|
||
|
||
static uint8_t MEM_unlocked = DEFAULT_unlocked; | ||
static uint8_t MEM_erased = DEFAULT_erased; | ||
static uint8_t MEM_setup = DEFAULT_setup; | ||
|
@@ -116,6 +121,7 @@ static uint8_t memory_eeprom(uint8_t *write_b, uint8_t *read_b, const int32_t ad | |
|
||
|
||
// Encrypted storage | ||
// `write_b` and `read_b` must be length `MEM_PAGE_LEN` | ||
static uint8_t memory_eeprom_crypt(const uint8_t *write_b, uint8_t *read_b, | ||
const int32_t addr) | ||
{ | ||
|
@@ -199,14 +205,20 @@ static uint8_t memory_eeprom_crypt(const uint8_t *write_b, uint8_t *read_b, | |
if (!dec) { | ||
goto err; | ||
} | ||
memcpy(read_b, utils_hex_to_uint8(dec), MEM_PAGE_LEN); | ||
if (read_b) { | ||
memcpy(read_b, utils_hex_to_uint8(dec), MEM_PAGE_LEN); | ||
} | ||
utils_zero(dec, dec_len); | ||
free(dec); | ||
|
||
utils_zero(mempass, MEM_PAGE_LEN); | ||
utils_clear_buffers(); | ||
return DBB_OK; | ||
err: | ||
if (read_b) { | ||
// Randomize return value on error | ||
hmac_sha256(mempass, MEM_PAGE_LEN, read_b, MEM_PAGE_LEN, read_b); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, the length of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. All the different macro lengths get a bit messy. How about something like:
which will abort at compile time. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would be perfect! I'm always happy to fail at compile time rather than later. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. commit added |
||
} | ||
utils_zero(mempass, MEM_PAGE_LEN); | ||
utils_clear_buffers(); | ||
return DBB_ERROR; | ||
|
@@ -254,7 +266,7 @@ static void memory_scramble_rn(void) | |
} | ||
|
||
|
||
uint8_t memory_setup(void) | ||
void memory_setup(void) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Github doesn't allow commenting unchanged lines so I'll do it here. I see a couple calls to I didn't look up other functions. Maybe there are others. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ACK |
||
{ | ||
if (memory_read_setup()) { | ||
// One-time setup on factory install | ||
|
@@ -264,7 +276,7 @@ uint8_t memory_setup(void) | |
// Return packet [Count(1) || Return Code (1) || CRC (2)] | ||
uint8_t ataes_ret[4] = {0}; | ||
if (ataes_process(ataes_cmd, sizeof(ataes_cmd), ataes_ret, 4) != DBB_OK) { | ||
return DBB_ERROR; | ||
HardFault_Handler(); | ||
} | ||
#endif | ||
uint32_t c = 0x00000000; | ||
|
@@ -280,7 +292,6 @@ uint8_t memory_setup(void) | |
memory_u2f_count_read(); | ||
} | ||
memory_scramble_default_aeskeys(); | ||
return DBB_OK; | ||
} | ||
|
||
|
||
|
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.
it would be nice if the args of
memory_eeprom_crypt
func were documented. For instance, I see it takesconst uint8_t *write_b
anduint8_t *read_b
but no length. Looking at the code, I assume the length is alwaysMEM_PAGE_LEN
but would be nicer to confirm this reading a function doc comment.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.
ACK
Added the comment. Thanks.