Editing HDD Encryption

Jump to navigation Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
=Introduction=
=Introduction=


* The following information was reverse engineered from LV1, Storage Manager in LPAR1 and sb_iso_spu_module.self.
* The following information was reverse enginered from LV1, Storage Manager in LPAR1 and sb_iso_spu_module.self.
* I'm able to decrypt/encrypt my PS3 HDD and VFLASH on PC now.
* See also [[Mounting HDD on PC]]


=HDD Encryption=
=HDD Encryption=
==Slim Consoles==


* XTS-AES-128 is used to encrypt all data on PS3 HDD.
* XTS-AES-128 is used to encrypt all data on PS3 HDD.
* XTS is NOT CBC!!! It's AES-ECB with tweak XORing. AES-CBC is impractical for HDD encryption. Each sector can be encrypted/decrypted independently from other HDD sectors.
* Good paper about XTS-AES:  http://ntnu.diva-portal.org/smash/get/diva2:347753/FULLTEXT01
* VFLASH is encrypted twice. First with ENCDEC keys and then with ATA keys.
* VFLASH is encrypted twice. First with ENCDEC keys and then with ATA keys.
* Tweak and data XTS keys are of size 32 bytes but only the first 16 bytes are used.
* Tweak and data XTS keys are of size 32 bytes but only the first 16 bytes are used.
* '''You can set and clear ATA keys with my Linux ps3encdec device driver which I use to test HDD/VFLASH encryption. But be careful, never set/clear ATA keys while some HDD regions/partitions are mounted !!! You will corrupt your data on your HDD !!!'''
==Phat Consoles==
* On the PHAT consoles with NAND flash AES-CBC-192 is used for HDD encryption and AES-CBC-128 for VFLASH encryption.
* So no tweak and tweak key here. Each sector is encrypted with the same '''zeroed''' IV.
* VFLASH is encrypted '''once''' with ENCDEC key and zeroed IV!
* PHAT consoles are susceptible to the TLS CBC IV attack
* On the PHAT consoles with NOR flash AES-CBC-192 is used for HDD encryption(as on FAT consoles with NAND) and XTS-AES-128 for VFLASH encryption(as on slim consoles).
* Data key is of size 32 bytes but only the first 24 bytes are used for HDD and 16 bytes for VFLASH.
* See also http://www.multiupload.nl/6PIFV4GKSH (contains scripts of ENCDEC emulator for both types of consoles).


=Dumping ATA Keys=
=Dumping ATA Keys=
Line 30: Line 13:
* I modified sb_iso_spu_module.self to dump ATA keys.
* I modified sb_iso_spu_module.self to dump ATA keys.
* ATA keys are passed as parameters to sb_iso_spu_module.self.
* ATA keys are passed as parameters to sb_iso_spu_module.self.
* dump_ata_keys.tar.gz: http://www.multiupload.nl/GUNWPZ0A3P
* See also http://www.ps3devwiki.com/wiki/Making_Isolated_SPU_Modules_and_Loaders


==Program==
==Program==
Line 143: Line 124:
bi $lr
bi $lr
</pre>
</pre>
http://pastie.org/4503109


==Result==
==Result==
Line 161: Line 141:
Tweak key is at offset 0x40 (32 bytes)
Tweak key is at offset 0x40 (32 bytes)
...
...
</pre>
==Test==
* To test your ATA XTS tweak and data keys, you need encrypted HDD sectors. You can either connect your HDD to PC and dump it or use my ps3vuart-tools on Linux and clear ATA keys and then dump it from ps3da. I tried both methods. But make sure you unmount all HDD regions before using ps3vuart-tools to clear your ATA keys. Also you could use a Linux LiveCD with ps3disk driver as module and load it with region flags 0x22 for region 0. 0x22 region flags mean that all sectors will be read undecrypted, see here http://www.ps3devwiki.com/wiki/Debian_LiveCD.
* I coded a small application which implements XTS-AES encryption/decryption. XTS-AES paper is a good reference how to implement it.
* You have to pass the correct sector number in order to get correct results.
* As you see below in my examples, i pass sector number 0 and sector 8 for VFLASH because VFLASH begins at sector 8 on HDD.
* Another interesting fact is that you have to swap half-words after encrypting and before decrypting HDD sectors else you will get wrong results. This swapping is not necessary for VFLASH sectors.
* Another note is that you have to decrypt VFLASH sectors with ATA keys first and then with ENCDEC keys.
* xts_aes.tar.gz: http://www.multiupload.nl/P0SYIYRRQF
Result with 1st encrypted sector from HDD:
<pre>
glevand@debian:~/xts_aes$ cat ../hdd_1st_sector_enc.bin  | \
    ./xts_aes -d -k <your ATA XTS data key> -t <your ATA XTS tweak key> -s 0 -r | hexdump -C
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000010  00 00 00 00 0f ac e0 ff  00 00 00 00 de ad fa ce  |................|
00000020  00 00 00 00 00 00 00 03  00 00 00 00 00 00 00 02  |................|
00000030  00 00 00 00 00 00 00 08  00 00 00 00 00 08 00 00  |................|
00000040  10 70 00 00 01 00 00 01  00 00 00 00 00 00 00 0b  |.p..............|
00000050  10 70 00 00 02 00 00 01  00 00 00 00 00 00 00 03  |.p..............|
00000060  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000000c0  00 00 00 00 00 08 00 10  00 00 00 00 03 9a 8b 2d  |...............-|
000000d0  10 70 00 00 01 00 00 01  00 00 00 00 00 00 00 03  |.p..............|
000000e0  10 70 00 00 02 00 00 01  00 00 00 00 00 00 00 03  |.p..............|
000000f0  10 20 00 00 03 00 00 01  00 00 00 00 00 00 00 03  |. ..............|
00000100  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000150  00 00 00 00 03 a2 8b 45  00 00 00 00 00 3f ff f8  |.......E.....?..|
00000160  10 70 00 00 01 00 00 01  00 00 00 00 00 00 00 03  |.p..............|
00000170  10 70 00 00 02 00 00 01  00 00 00 00 00 00 00 03  |.p..............|
00000180  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001e0  00 00 00 00 03 e2 8b 46  00 00 00 00 19 39 ce 0c  |.......F.....9..|
000001f0  10 70 00 00 02 00 00 01  00 00 00 00 00 00 00 03  |.p..............|
00000200
</pre>
</pre>


Line 205: Line 146:


* VFLASH is encrypted twice. First with ENCDEC keys and then with ATA keys.
* VFLASH is encrypted twice. First with ENCDEC keys and then with ATA keys.
* You cannot dump ENCDEC keys with sb_iso_spu_module.self. They are set in lv1ldr only (see here: http://gitorious.ps3dev.net/reversing/lv1ldr/trees/master).
* You cannot dump ENCDEC keys with sb_iso_spu_module.self. They are set in lv1ldr only.
* I used a modified lv1ldr with my Linux spuldrfs driver and dumped ENCDEC keys.
* I used a modified lv1ldr with my Linux spuldrfs driver and dumped ENCDEC keys.
* XTS-AES-128 with 128bit tweak key and 128bit data key, just like ATA keys.
* XTS-AES-128 with 128bit tweak key and 128bit data key, just like ATA keys.
* ENCDEC tweak and data keys are passed to lv1ldr NOT in clear text.
* ENCDEC tweak and data keys are passed to lv1ldr NOT in clear text.
* ENCDEC keys are computed by lv1ldr with AES-CBC-256 by encrypting 32byte seeds.
* ENCDEC keys are computed by lv1ldr with AES-CBC-256 by encrypting 32bytes seeds.
* metldr passes to lv1ldr AES-CBC-256 IV and key which are used to compute ENCDEC keys.
* metldlr passes to lv1ldr AES-CBC-256 IV and key which are used to compute ENCDEC keys.
* I tested my ENCDEC keys with my ps3encdec Linux driver and set them again, and VFLASH was still working fine. As soon as i changed some bits in these keys, VFLASH could not be decrypted properly anymore :) It means keys are correct.
* dump_encdec_keys.tar.gz: http://www.multiupload.nl/5PIRW98Z5X


==ENCDEC Key Seeds==
==ENCDEC Key Seeds==


* Use the dumped ENCDEC IV and key to encrypt these seeds and you will get your ENCDEC keys for VFLASH.
Tweak key seed:
* You can find these seeds in [http://pastie.org/4558824 lv1ldr].
 
Data key seed:


<pre>
<pre>
Line 228: Line 164:
</pre>  
</pre>  


Tweak key seed:
Data key seed:


<pre>
<pre>
Line 374: Line 310:
bi $lr
bi $lr
</pre>
</pre>
http://pastie.org/4503119


==Result==
==Result==


* Test run with spuldrfs on Linux 3.5.1
* Test run with spuldrfs


<pre>
<pre>
Line 396: Line 331:
...
...
</pre>
</pre>
==Test==
* To test your ENCDEC XTS tweak and data keys, you need encrypted VFLASH sectors. You can dump it from ps3da starting with sector 8.
* You have to pass the correct sector number in order to get correct results.
* As you see below in my examples, i pass sector 8 for VFLASH because VFLASH begins at sector 8 on HDD.
* The input sector was already decrypted with ATA keys.
Result with 1st encrypted sector from VFLASH:
<pre>
glevand@debian:~/xts_aes$ cat ../vflash_1st_sector_enc.bin | \
    ./xts_aes -d -k <your ENCDEC data key> -t <your ENCDEC tweak key> -s 8 | hexdump -C
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000010  00 00 00 00 0f ac e0 ff  00 00 00 00 de ad fa ce  |................|
00000020  00 00 00 00 00 00 00 03  00 00 00 00 00 00 00 02  |................|
00000030  00 00 00 00 00 00 00 08  00 00 00 00 00 00 75 f8  |..............u.|
00000040  10 70 00 00 01 00 00 01  00 00 00 00 00 00 00 03  |.p..............|
00000050  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000000c0  00 00 00 00 00 00 78 00  00 00 00 00 00 06 3e 00  |......x.......>.|
000000d0  10 70 00 00 02 00 00 01  00 00 00 00 00 00 00 03  |.p..............|
000000e0  10 70 00 00 01 00 00 01  00 00 00 00 00 00 00 03  |.p..............|
000000f0  10 20 00 00 03 00 00 01  00 00 00 00 00 00 00 01  |. ..............|
00000100  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000150  00 00 00 00 00 06 b6 00  00 00 00 00 00 00 80 00  |................|
00000160  10 70 00 00 02 00 00 01  00 00 00 00 00 00 00 03  |.p..............|
00000170  10 70 00 00 01 00 00 01  00 00 00 00 00 00 00 03  |.p..............|
00000180  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
000001e0  00 00 00 00 00 07 36 00  00 00 00 00 00 00 04 00  |......6.........|
000001f0  10 70 00 00 02 00 00 01  00 00 00 00 00 00 00 03  |.p..............|
00000200
</pre>
{{Reverse engineering}}<noinclude>[[Category:Main]]</noinclude>
Please note that all contributions to PS3 Developer wiki are considered to be released under the GNU Free Documentation License 1.2 (see PS3 Developer wiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following hCaptcha:

Cancel Editing help (opens in new window)