summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2017-09-19 15:30:37 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2017-09-19 15:30:37 +0200
commit99cc8f88026f930c08e2e32439fe8f0d22e5e5a8 (patch)
tree453139f31650f93fb1515d4098e7957423a4a503
parent048aecd82a1dbf73dec9b6ca903f71c4b457dc9a (diff)
downloadrockbox-99cc8f88026f930c08e2e32439fe8f0d22e5e5a8.tar.gz
rockbox-99cc8f88026f930c08e2e32439fe8f0d22e5e5a8.zip
upgtools: fix bug in brute force search
DES ignores the parity bit of each byte (making the 64-bit key really 56-bit), but the current code skipped the parity bit of each half-byte, thus missing some keys. Change-Id: Ia523ebb944e458905b7de1742df151df22166150
-rw-r--r--utils/nwztools/upgtools/keysig_search.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/utils/nwztools/upgtools/keysig_search.c b/utils/nwztools/upgtools/keysig_search.c
index 51a04bb6f9..2f234d6358 100644
--- a/utils/nwztools/upgtools/keysig_search.c
+++ b/utils/nwztools/upgtools/keysig_search.c
@@ -266,11 +266,12 @@ static bool hex_rec(bool producer, struct hex_chunk_t *ch)
266 * significant bit of each byte is an (unused) parity bit. We thus only 266 * significant bit of each byte is an (unused) parity bit. We thus only
267 * generate keys where the least significant bit is 0. */ 267 * generate keys where the least significant bit is 0. */
268 int p = ch->pos++; 268 int p = ch->pos++;
269 int step = (p % 2) ? 2 : 1; // skip significant bit at positions 1, 3, 5 and 7
269 if(ch->rem_digits > 0) 270 if(ch->rem_digits > 0)
270 { 271 {
271 ch->rem_digits--; 272 ch->rem_digits--;
272 /* NOTE (42) */ 273 /* NOTE (42) */
273 for(int i = '0'; i <= '9'; i += 2) 274 for(int i = '0'; i <= '9'; i += step)
274 { 275 {
275 ch->key[p] = i; 276 ch->key[p] = i;
276 if(hex_rec(producer, ch)) 277 if(hex_rec(producer, ch))
@@ -282,7 +283,7 @@ static bool hex_rec(bool producer, struct hex_chunk_t *ch)
282 { 283 {
283 ch->rem_letters--; 284 ch->rem_letters--;
284 /* NOTE (42) */ 285 /* NOTE (42) */
285 for(int i = 'a'; i <= 'f'; i += 2) 286 for(int i = 'a'; i <= 'f'; i += step)
286 { 287 {
287 ch->key[p] = i; 288 ch->key[p] = i;
288 if(hex_rec(producer, ch)) 289 if(hex_rec(producer, ch))
@@ -290,7 +291,7 @@ static bool hex_rec(bool producer, struct hex_chunk_t *ch)
290 } 291 }
291 if(ch->upper_case) 292 if(ch->upper_case)
292 { 293 {
293 for(int i = 'A'; i <= 'F'; i += 2) 294 for(int i = 'A'; i <= 'F'; i += step)
294 { 295 {
295 ch->key[p] = i; 296 ch->key[p] = i;
296 if(hex_rec(producer, ch)) 297 if(hex_rec(producer, ch))
@@ -379,7 +380,7 @@ static bool alnum_rec(bool producer, struct alnum_chunk_t *ch)
379 /* we list the first 5 pos in generator, and remaining 3 in workers */ 380 /* we list the first 5 pos in generator, and remaining 3 in workers */
380 if(producer && ch->pos == 4) 381 if(producer && ch->pos == 4)
381 { 382 {
382 printf("yield(%.8s,%d)\n", ch->key, ch->pos); 383 //printf("yield(%.8s,%d)\n", ch->key, ch->pos);
383 return producer_yield(ch, sizeof(struct alnum_chunk_t)); 384 return producer_yield(ch, sizeof(struct alnum_chunk_t));
384 } 385 }
385 /* filled the key ? */ 386 /* filled the key ? */
@@ -392,14 +393,15 @@ static bool alnum_rec(bool producer, struct alnum_chunk_t *ch)
392 * generate keys where the least significant bit is 0. */ 393 * generate keys where the least significant bit is 0. */
393 int p = ch->pos++; 394 int p = ch->pos++;
394 /* NOTE (42) */ 395 /* NOTE (42) */
395 for(int i = '0'; i <= '9'; i += 2) 396 int step = (p % 2) ? 2 : 1; // skip significant bit at positions 1, 3, 5 and 7
397 for(int i = '0'; i <= '9'; i += step)
396 { 398 {
397 ch->key[p] = i; 399 ch->key[p] = i;
398 if(alnum_rec(producer, ch)) 400 if(alnum_rec(producer, ch))
399 return true; 401 return true;
400 } 402 }
401 /* NOTE (42) */ 403 /* NOTE (42) */
402 for(int i = 'a'; i <= 'z'; i += 2) 404 for(int i = 'a'; i <= 'z'; i += step)
403 { 405 {
404 ch->key[p] = i; 406 ch->key[p] = i;
405 if(alnum_rec(producer, ch)) 407 if(alnum_rec(producer, ch))