summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorAmaury Pouly <pamaury@rockbox.org>2011-10-23 18:14:38 +0000
committerAmaury Pouly <pamaury@rockbox.org>2011-10-23 18:14:38 +0000
commitcab5dbded9bb4003113e2dbae5a7dcd5f9524f29 (patch)
tree3c3df31099f11d81b8da2b4e3f080ba46d10e466 /utils
parentb93e15c404cda96397ba2b98e49359a81d34c957 (diff)
downloadrockbox-cab5dbded9bb4003113e2dbae5a7dcd5f9524f29.tar.gz
rockbox-cab5dbded9bb4003113e2dbae5a7dcd5f9524f29.tar.bz2
rockbox-cab5dbded9bb4003113e2dbae5a7dcd5f9524f29.zip
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
Diffstat (limited to 'utils')
-rw-r--r--utils/sbtools/sbtoelf.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/utils/sbtools/sbtoelf.c b/utils/sbtools/sbtoelf.c
index 4878c73faf..44f6e074da 100644
--- a/utils/sbtools/sbtoelf.c
+++ b/utils/sbtools/sbtoelf.c
@@ -484,6 +484,7 @@ static void extract(unsigned long filesize)
/* encryption cbc-mac */
key_array_t keys = NULL; /* array of 16-bytes keys */
byte real_key[16];
+ bool valid_key = false; /* false until a matching key was found */
if(sb_header->nr_keys > 0)
{
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,
keys[i], zero, &computed_cbc_mac, 1);
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");
+ }
else
printf(" Failed\n");
color(GREEN);
@@ -531,9 +536,9 @@ static void extract(unsigned long filesize)
color(YELLOW);
print_hex(decrypted_key, 16, false);
/* cross-check or copy */
- if(i == 0)
+ if(valid_key && ok)
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);
printf(" Cross-Check Ok");