From c323d533c29fcf420df6b63ccf5c37340c7ba6c5 Mon Sep 17 00:00:00 2001 From: Bertrik Sikken Date: Mon, 28 Jul 2008 19:43:32 +0000 Subject: Redo r18136 a little cleaner git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18141 a1c6a512-1295-4272-9138-f99709370657 --- rbutil/sansapatcher/sansapatcher.c | 9 +++++---- 1 file 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) { integers) and the key is incremented after each block */ -static void tea_decrypt_buf(const unsigned char* src, unsigned char* dest, size_t n, uint32_t * key) +static void tea_decrypt_buf(const unsigned char* src, unsigned char* dest, + size_t n, const uint32_t * initial_key) { uint32_t v0, v1; unsigned int i; + uint32_t key[4]; + memcpy(key, initial_key, sizeof(key)); for (i = 0; i < (n / 8); i++) { v0 = le2int(src); v1 = le2int(src+4); @@ -561,7 +564,6 @@ static int prepare_original_firmware(struct sansa_t* sansa, unsigned char* buf, unsigned char* tmpbuf; int i; int key_found; - uint32_t key[4]; get_mi4header(buf,mi4header); @@ -585,11 +587,10 @@ static int prepare_original_firmware(struct sansa_t* sansa, unsigned char* buf, key_found=0; for (i=0; i < NUM_KEYS && !key_found ; i++) { - memcpy(key, keys[i], sizeof(key)); tea_decrypt_buf(buf+(mi4header->plaintext+0x200), tmpbuf, mi4header->mi4size-(mi4header->plaintext+0x200), - key); + keys[i]); key_found = (le2uint(tmpbuf+mi4header->length-mi4header->plaintext-4) == 0xaa55aa55); } -- cgit v1.2.3