Redo r18136 a little cleaner

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18141 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Bertrik Sikken 2008-07-28 19:43:32 +00:00
parent 9b7566e3ec
commit c323d533c2

View file

@ -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 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; uint32_t v0, v1;
unsigned int i; unsigned int i;
uint32_t key[4];
memcpy(key, initial_key, sizeof(key));
for (i = 0; i < (n / 8); i++) { for (i = 0; i < (n / 8); i++) {
v0 = le2int(src); v0 = le2int(src);
v1 = le2int(src+4); v1 = le2int(src+4);
@ -561,7 +564,6 @@ static int prepare_original_firmware(struct sansa_t* sansa, unsigned char* buf,
unsigned char* tmpbuf; unsigned char* tmpbuf;
int i; int i;
int key_found; int key_found;
uint32_t key[4];
get_mi4header(buf,mi4header); get_mi4header(buf,mi4header);
@ -585,11 +587,10 @@ static int prepare_original_firmware(struct sansa_t* sansa, unsigned char* buf,
key_found=0; key_found=0;
for (i=0; i < NUM_KEYS && !key_found ; i++) { for (i=0; i < NUM_KEYS && !key_found ; i++) {
memcpy(key, keys[i], sizeof(key));
tea_decrypt_buf(buf+(mi4header->plaintext+0x200), tea_decrypt_buf(buf+(mi4header->plaintext+0x200),
tmpbuf, tmpbuf,
mi4header->mi4size-(mi4header->plaintext+0x200), mi4header->mi4size-(mi4header->plaintext+0x200),
key); keys[i]);
key_found = (le2uint(tmpbuf+mi4header->length-mi4header->plaintext-4) == 0xaa55aa55); key_found = (le2uint(tmpbuf+mi4header->length-mi4header->plaintext-4) == 0xaa55aa55);
} }