archshift / Decrypt9

Multipurpose content dumper and decrypter for the Nintendo 3DS (SUPERSEDED)
GNU General Public License v2.0
104 stars 84 forks source link

Decryption of titlekeys broken #42

Closed ghost closed 9 years ago

ghost commented 9 years ago

Decryption of titlekeys broke between git commits 1cb661e and 4ab34916. I have tried to pinpoint the issue but have failed so far. This happens at least with the titlekeys for title IDs 0004013800000002 and 0004000000165800.

d0k3 commented 9 years ago

These are two of my commits, so I will fix this issue. I may already have an idea what happens here, but could you possibly give some more information? Is the bug in Decrypt9 or is it in the Python scripts? Is it already broken in the first commit you named? You may compare the output from a working version with a broken one.

Also is it confirmed broken for more titlekeys than the two you named?

UPDATE: I think I already fixed it. Could you try this and tell me if it works? https://github.com/d0k3/Decrypt9/tree/patch-4 I will only do the PR once you tell me it works.

ghost commented 9 years ago

The bug is with all certainty in Decrypt9, not the Python scripts. 4ab3491 left the Python scripts alone to begin with.

I compared the decTitleKeys.bin of 1cb661e and 4ab3491 for the same ticket.db -- all titlekeys mismatched, irrelevant of their type (eShop app, system title, demo, ...). It seems they do not mismatch in a simple way, such as simply being written out in reverse.

d0k3 commented 9 years ago

Yes, the Python scripts was a wild guess before I even took a look at the commits. Could you try my fix found here and tell me if it works? https://github.com/d0k3/Decrypt9/tree/patch-4

I'd test it myself, but I can't at the moment (don't have my laptop or even my 3DS here). The fix will almost certainly work, though. Also, thanks a ton for pointing this out. It must have been quite a bit of work to pinpoint the exact commits responsible for this.

ghost commented 9 years ago

Your fix works. Now I feel like an idiot, unable to see through a one-line change.

d0k3 commented 9 years ago

I am at fault. I had to change a lot of stuff in the crypto routines for TWLN decryption to work, and I simply forgot that little change for titlekey decryption. Anyways, thank you again!

d0k3 commented 9 years ago

By the way, if you want to know why this fix works... The old crypto routines only allowed big endian and normal order. For TWLN decryption to work, I had to change this to default to little endian / reversed order. And I forgot to set the titlekey decryption parameters back to big endian / normal order.

archshift commented 9 years ago

Fixed by #43.