summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBertrik Sikken <bertrik@sikken.nl>2008-07-28 19:43:32 +0000
committerBertrik Sikken <bertrik@sikken.nl>2008-07-28 19:43:32 +0000
commitc323d533c29fcf420df6b63ccf5c37340c7ba6c5 (patch)
treec126261549ad5ec4c41e204a6f2bd06193647134
parent9b7566e3ec6586e0fc9df82e9cb1650287419308 (diff)
downloadrockbox-c323d533c29fcf420df6b63ccf5c37340c7ba6c5.tar.gz
rockbox-c323d533c29fcf420df6b63ccf5c37340c7ba6c5.zip
Redo r18136 a little cleaner
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18141 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--rbutil/sansapatcher/sansapatcher.c9
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
295static void tea_decrypt_buf(const unsigned char* src, unsigned char* dest, size_t n, uint32_t * key) 295static 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