forked from len0rd/rockbox
sbtoelf: handle the case where only one valid key is known
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30833 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
b93e15c404
commit
cab5dbded9
1 changed files with 8 additions and 3 deletions
|
@ -484,6 +484,7 @@ static void extract(unsigned long filesize)
|
||||||
/* encryption cbc-mac */
|
/* encryption cbc-mac */
|
||||||
key_array_t keys = NULL; /* array of 16-bytes keys */
|
key_array_t keys = NULL; /* array of 16-bytes keys */
|
||||||
byte real_key[16];
|
byte real_key[16];
|
||||||
|
bool valid_key = false; /* false until a matching key was found */
|
||||||
if(sb_header->nr_keys > 0)
|
if(sb_header->nr_keys > 0)
|
||||||
{
|
{
|
||||||
keys = read_keys(sb_header->nr_keys);
|
keys = read_keys(sb_header->nr_keys);
|
||||||
|
@ -512,8 +513,12 @@ static void extract(unsigned long filesize)
|
||||||
cbc_mac(g_buf, NULL, sb_header->header_size + sb_header->nr_sections,
|
cbc_mac(g_buf, NULL, sb_header->header_size + sb_header->nr_sections,
|
||||||
keys[i], zero, &computed_cbc_mac, 1);
|
keys[i], zero, &computed_cbc_mac, 1);
|
||||||
color(RED);
|
color(RED);
|
||||||
if(memcmp(dict_entry->hdr_cbc_mac, computed_cbc_mac, 16) == 0)
|
bool ok = memcmp(dict_entry->hdr_cbc_mac, computed_cbc_mac, 16) == 0;
|
||||||
|
if(ok)
|
||||||
|
{
|
||||||
|
valid_key = true;
|
||||||
printf(" Ok\n");
|
printf(" Ok\n");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
printf(" Failed\n");
|
printf(" Failed\n");
|
||||||
color(GREEN);
|
color(GREEN);
|
||||||
|
@ -531,9 +536,9 @@ static void extract(unsigned long filesize)
|
||||||
color(YELLOW);
|
color(YELLOW);
|
||||||
print_hex(decrypted_key, 16, false);
|
print_hex(decrypted_key, 16, false);
|
||||||
/* cross-check or copy */
|
/* cross-check or copy */
|
||||||
if(i == 0)
|
if(valid_key && ok)
|
||||||
memcpy(real_key, decrypted_key, 16);
|
memcpy(real_key, decrypted_key, 16);
|
||||||
else if(memcmp(real_key, decrypted_key, 16) == 0)
|
else if(valid_key && memcmp(real_key, decrypted_key, 16) == 0)
|
||||||
{
|
{
|
||||||
color(RED);
|
color(RED);
|
||||||
printf(" Cross-Check Ok");
|
printf(" Cross-Check Ok");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue