Homebrew How to solve the AES key scrambler

uyjulian

Homebrewer
OP
Member
Joined
Nov 26, 2012
Messages
2,567
Trophies
2
Location
United States
Website
sites.google.com
XP
3,886
Country
United States
I hope this information helps some people who have trouble figuring out the AES key scrambler.

k = normal key
x = keyX
y = keyY
C = constant

let's algebra !!!!

let's start with
Code:
k = (((x <<< 2) ^ y) + C) <<< 87

Solve for k

Code:
k = (((x <<< 2) ^ y) + C) <<< 87

Solve for x

Code:
k        = (((x <<< 2) ^ y) + C) <<< 87
  >>> 87                         >>> 87
(k >>> 87)     = ((x <<< 2) ^ y) + C
           - C                   - C
((k >>> 87) - C)     = (x <<< 2) ^ y
                 ^ y             ^ y
(((k >>> 87) - C) ^ y)      = x <<< 2
                      >>> 2     >>> 2
x = (((k >>> 87) - C) ^ y) >>> 2

Solve for y

Code:
k        = (((x <<< 2) ^ y) + C) <<< 87
  >>> 87                         >>> 87
(k >>> 87)     = ((x <<< 2) ^ y) + C
           - C                   - C
((k >>> 87) - C)              = (x <<< 2) ^ y
                 ^ (x <<< 2)  ^ (x <<< 2)
y = ((k >>> 87) - C) ^ (x <<< 2)

Solve for C

Code:
k        = (((x <<< 2) ^ y) + C) <<< 87
  >>> 87                         >>> 87
(k >>> 87)                   = ((x <<< 2) ^ y) + C
           - ((x <<< 2) ^ y) - ((x <<< 2) ^ y)
C = (k >>> 87) - ((x <<< 2) ^ y)

easy, right? You just need three variables to get one of them!
 

Syphurith

Beginner
Member
Joined
Mar 8, 2013
Messages
641
Trophies
0
Location
Xi'an, Shaanxi Province
XP
364
Country
Switzerland
Well good if the implemented algorithm is that easy. But i've forgot the older one with function wrapper.
Now a implementation to just calculate the normal key with given KeyX or KeyY is needed, and I don't know how to do so.
There was a pair of KeyX/KeyY/CTR for N3DS 9.5 leaked but totally useless before, hope with its normal key we can use it to test out our recovery solution.
Wish the algorithm implemented in hardware is itself simple, or we may need to generate a lot of normal keys to get the curve of the function.
So steps: 1.calculate normalkey. 2.recover the algorithm, and constant C. 3.Use it to recover the KeyX/KeyY with anyslot that its counterpart is known.
Hope the solution is right.. wait we can check it using the keys leaked.
 

Suiginou

(null)
Member
Joined
Jun 26, 2012
Messages
565
Trophies
0
Location
pc + 8
XP
738
Country
Gambia, The
Well good if the implemented algorithm is that easy. But i've forgot the older one with function wrapper.
Now a implementation to just calculate the normal key with given KeyX or KeyY is needed, and I don't know how to do so.
There was a pair of KeyX/KeyY/CTR for N3DS 9.5 leaked but totally useless before, hope with its normal key we can use it to test out our recovery solution.
Wish the algorithm implemented in hardware is itself simple, or we may need to generate a lot of normal keys to get the curve of the function.
So steps: 1.calculate normalkey. 2.recover the algorithm, and constant C. 3.Use it to recover the KeyX/KeyY with anyslot that its counterpart is known.
Hope the solution is right.. wait we can check it using the keys leaked.
If you watch plutoo's presentation again, you need a normalkey and a keyY or keyX to actually make things happen, though. The 9.5 keyX/keyY is useless. Besides, we have a set of keyX/keyY already (7.x exefs/romfs crypto).

See also: The entirety of https://gbatemp.net/threads/aes-key-scrambler.406951/

The problem here is that normalkeys are very hard to come by. There was the example of the NFC normalkey in N3DS firmware 8.1/9.0 that got changed to a keyY in NATIVE_FIRM 9.3, but N3DSes seem to be fairly rare.
 
Last edited by Suiginou,
  • Like
Reactions: Syphurith

Syphurith

Beginner
Member
Joined
Mar 8, 2013
Messages
641
Trophies
0
Location
Xi'an, Shaanxi Province
XP
364
Country
Switzerland
If you watch plutoo's presentation again, you need a normalkey and a keyY or keyX to actually make things happen, though. The 9.5 keyX/keyY is useless. Besides, we have a set of keyX/keyY already (7.x exefs/romfs crypto).
See also: The entirety of https://gbatemp.net/threads/aes-key-scrambler.406951/
I don't know if we can use the pair of keyX and keyY to calculate the normal one and get it out of the keyscrambler.
The 9.5 slot0x16 is useless before, and if it can not be used to check the recovery then that's useless afterwards (orz).
Still thanks for every effort made to the recovery..

UPDATE: Seen your post. So you can't read that out..
 
Last edited by Syphurith, , Reason: Well I know that now.

Suiginou

(null)
Member
Joined
Jun 26, 2012
Messages
565
Trophies
0
Location
pc + 8
XP
738
Country
Gambia, The
I don't know if we can use the pair of keyX and keyY to calculate the normal one and get it out of the keyscrambler.
The 9.5 slot0x16 is useless before, and if it can not be used to check the recovery then that's useless afterwards (orz).
Still thanks for every effort made to the recovery..
You can use keyX/keyY to calculate the normalkey once you have the constant C. The public doesn't have C yet, however. Figuring the key scrambler out has, at this point, nearly no practical applications. If you're here for usable hax, you're looking in the wrong place.

The current method presented by plutoo is to get a normalkey and a keyY and apply some bitwise logic to derive keyX and from there get C. The public, me included, is currently still stuck at the "find a normalkey" part.
 

Syphurith

Beginner
Member
Joined
Mar 8, 2013
Messages
641
Trophies
0
Location
Xi'an, Shaanxi Province
XP
364
Country
Switzerland
You can use keyX/keyY to calculate the normalkey once you have the constant C. The public doesn't have C yet, however. Figuring the key scrambler out has, at this point, nearly no practical applications. If you're here for usable hax, you're looking in the wrong place.
The current method presented by plutoo is to get a normalkey and a keyY and apply some bitwise logic to derive keyX and from there get C. The public, me included, is currently still stuck at the "find a normalkey" part.
Not for the hax. I just want to know the progress on the calculations. Well I'm happy with my coldboot rx old 9.2.
So the normalkey is still blocking us. I'm quite sad but can not help with it then.

@Suiginou Eh.. Oh wait then why they said in the talk that bitflips the KeyY can be used to recover the KeyX (that sharing the same bit of produced normal key)? If their calculation is right but no way to get the normal one out? How do they figure this out.. That's weird.
 
Last edited by Syphurith, , Reason: WTF.

dark_samus3

Well-Known Member
Member
Joined
May 30, 2015
Messages
2,372
Trophies
0
XP
2,042
Country
United States
You can use keyX/keyY to calculate the normalkey once you have the constant C. The public doesn't have C yet, however. Figuring the key scrambler out has, at this point, nearly no practical applications. If you're here for usable hax, you're looking in the wrong place.

The current method presented by plutoo is to get a normalkey and a keyY and apply some bitwise logic to derive keyX and from there get C. The public, me included, is currently still stuck at the "find a normalkey" part.
I haven't gotten anything done with it, but I think the step most people missed is encrypt something on the 3ds, a file with all zeros... Then look at the result, flip a bit, repeat above process, look at what changed, record the change, rinse and repeat for all 128 bits of KeyY, then once KeyX is know (not sure but I think it is somehow derived in the results of the all zero file that was encrypted) all you need is C
 

shinyquagsire23

SALT/Sm4sh Leak Guy
Member
Joined
Nov 18, 2012
Messages
1,977
Trophies
2
Age
26
Location
Las Vegas
XP
3,765
Country
United States
The problem though is that you can't find C itself without all three keys (keyX, keyY and normal), which is the tough part since you have to find keyX indirectly from a normal key and keyX without C. Doing it indirectly requires using the hardware keyscrambler for comparison so that's why it's actually difficult, you have to brute force finding the keyX somewhat.
 
Last edited by shinyquagsire23,

Psi-hate

GBATemp's Official Psi-Hater
Member
Joined
Dec 14, 2014
Messages
1,749
Trophies
1
XP
3,411
Country
United States
The problem though is that you can't find C itself without all three keys (keyX, keyY and normal), which is the tough part since you have to do it indirectly. Doing it indirectly requires using the hardware keyscrambler for comparison so that's why it's actually difficult, you have to brute force finding the keyX somewhat.
Rei says she has she just got the keyscrambler figured out and has it out of the way apparently.
 
  • Like
Reactions: Syphurith

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • BakerMan @ BakerMan:
    ok, because here it's in september, right before the fuckin school year starts
  • Xdqwerty @ Xdqwerty:
    good night
  • BakerMan @ BakerMan:
    as to you
  • K3Nv2 @ K3Nv2:
    How do you know if the night will be good when you're asleep
  • BakerMan @ BakerMan:
    because i didn't say i was asleep
  • BakerMan @ BakerMan:
    i said i was sleeping...
  • BakerMan @ BakerMan:
    sleeping with uremum
  • K3Nv2 @ K3Nv2:
    Even my mum slept on that uremum
  • TwoSpikedHands @ TwoSpikedHands:
    yall im torn... ive been hacking away at tales of phantasia GBA (the USA version) and have so many documents of reverse engineering i've done
  • TwoSpikedHands @ TwoSpikedHands:
    I just found out that the EU version is better in literally every way, better sound quality, better lighting, and there's even a patch someone made to make the text look nicer
  • TwoSpikedHands @ TwoSpikedHands:
    Do I restart now using what i've learned on the EU version since it's a better overall experience? or do I continue with the US version since that is what ive been using, and if someone decides to play my hack, it would most likely be that version?
  • Sicklyboy @ Sicklyboy:
    @TwoSpikedHands, I'll preface this with the fact that I know nothing about the game, but, I think it depends on what your goals are. Are you trying to make a definitive version of the game? You may want to refocus your efforts on the EU version then. Or, are you trying to make a better US version? In which case, the only way to make a better US version is to keep on plugging away at that one ;)
  • Sicklyboy @ Sicklyboy:
    I'm not familiar with the technicalities of the differences between the two versions, but I'm wondering if at least some of those differences are things that you could port over to the US version in your patch without having to include copyrighted assets from the EU version
  • TwoSpikedHands @ TwoSpikedHands:
    @Sicklyboy I am wanting to fully change the game and bend it to my will lol. I would like to eventually have the ability to add more characters, enemies, even have a completely different story if i wanted. I already have the ability to change the tilemaps in the US version, so I can basically make my own map and warp to it in game - so I'm pretty far into it!
  • TwoSpikedHands @ TwoSpikedHands:
    I really would like to make a hack that I would enjoy playing, and maybe other people would too. swapping to the EU version would also mean my US friends could not legally play it
  • TwoSpikedHands @ TwoSpikedHands:
    I am definitely considering porting over some of the EU features without using the actual ROM itself, tbh that would probably be the best way to go about it... but i'm sad that the voice acting is so.... not good on the US version. May not be a way around that though
  • TwoSpikedHands @ TwoSpikedHands:
    I appreciate the insight!
  • The Real Jdbye @ The Real Jdbye:
    @TwoSpikedHands just switch, all the knowledge you learned still applies and most of the code and assets should be the same anyway
  • The Real Jdbye @ The Real Jdbye:
    and realistically they wouldn't

    be able to play it legally anyway since they need a ROM and they probably don't have the means to dump it themselves
  • The Real Jdbye @ The Real Jdbye:
    why the shit does the shitbox randomly insert newlines in my messages
  • Veho @ Veho:
    It does that when I edit a post.
  • Veho @ Veho:
    It inserts a newline in a random spot.
    Veho @ Veho: It inserts a newline in a random spot.