diff options
Diffstat (limited to 'rbutil')
-rw-r--r-- | rbutil/sansapatcher/sansapatcher.c | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/rbutil/sansapatcher/sansapatcher.c b/rbutil/sansapatcher/sansapatcher.c index 4f04179064..eb6f7d12a5 100644 --- a/rbutil/sansapatcher/sansapatcher.c +++ b/rbutil/sansapatcher/sansapatcher.c | |||
@@ -292,11 +292,14 @@ static void tea_decrypt(uint32_t* v0, uint32_t* v1, const uint32_t* k) { | |||
292 | integers) and the key is incremented after each block | 292 | integers) and the key is incremented after each block |
293 | */ | 293 | */ |
294 | 294 | ||
295 | static void tea_decrypt_buf(const unsigned char* src, unsigned char* dest, size_t n, uint32_t * key) | 295 | static void tea_decrypt_buf(const unsigned char* src, unsigned char* dest, |
296 | size_t n, const uint32_t * initial_key) | ||
296 | { | 297 | { |
297 | uint32_t v0, v1; | 298 | uint32_t v0, v1; |
298 | unsigned int i; | 299 | unsigned int i; |
300 | uint32_t key[4]; | ||
299 | 301 | ||
302 | memcpy(key, initial_key, sizeof(key)); | ||
300 | for (i = 0; i < (n / 8); i++) { | 303 | for (i = 0; i < (n / 8); i++) { |
301 | v0 = le2int(src); | 304 | v0 = le2int(src); |
302 | v1 = le2int(src+4); | 305 | v1 = le2int(src+4); |
@@ -561,7 +564,6 @@ static int prepare_original_firmware(struct sansa_t* sansa, unsigned char* buf, | |||
561 | unsigned char* tmpbuf; | 564 | unsigned char* tmpbuf; |
562 | int i; | 565 | int i; |
563 | int key_found; | 566 | int key_found; |
564 | uint32_t key[4]; | ||
565 | 567 | ||
566 | get_mi4header(buf,mi4header); | 568 | get_mi4header(buf,mi4header); |
567 | 569 | ||
@@ -585,11 +587,10 @@ static int prepare_original_firmware(struct sansa_t* sansa, unsigned char* buf, | |||
585 | 587 | ||
586 | key_found=0; | 588 | key_found=0; |
587 | for (i=0; i < NUM_KEYS && !key_found ; i++) { | 589 | for (i=0; i < NUM_KEYS && !key_found ; i++) { |
588 | memcpy(key, keys[i], sizeof(key)); | ||
589 | tea_decrypt_buf(buf+(mi4header->plaintext+0x200), | 590 | tea_decrypt_buf(buf+(mi4header->plaintext+0x200), |
590 | tmpbuf, | 591 | tmpbuf, |
591 | mi4header->mi4size-(mi4header->plaintext+0x200), | 592 | mi4header->mi4size-(mi4header->plaintext+0x200), |
592 | key); | 593 | keys[i]); |
593 | key_found = (le2uint(tmpbuf+mi4header->length-mi4header->plaintext-4) == 0xaa55aa55); | 594 | key_found = (le2uint(tmpbuf+mi4header->length-mi4header->plaintext-4) == 0xaa55aa55); |
594 | } | 595 | } |
595 | 596 | ||