PSX-SCENE Forum Discussion for Sony PlayStation/PsOne/PS2/PS3/PSP/PS VITA
  • PS2 Classics Algorithm By flatz

    PS3 Developerr Flatz has published all his information he has on the PS2 Classics Algorithm that he has been working hard on the past months. As he no longer has the time to work on PS3 stuff anymore. However he has released a wealth of information that will no doubt be useful to the scene. Hopefully others will be able to continue on with his work and we will be able to play our disc backups on all PS3 systems as we should be able to if it wasn't for the greed of a company named Sony. Check below at the wealth of information he has shared to the scene. Thanks to flatz for all your work in this scene!!!




    Posted info from Flatz via Ps3Hax (for informational purposes only)



    Ok, guys. Unfortunately I forced to admit that I have no more time to work on PS3 stuff because I'm very busy lately. So I decided to publish all information related to PS2 classics as JuanNadie did with the NPDRM algorithm one year ago. Firstly I wanted to say that he was the first who started reverse-engineering on this subject and when he left the scene I decided to continue his work to keep it from going to waste. And so I would like to thank JuanNadie for his amazing contribution to the PS3 scene. Besides that, he gave me some piece of information on the subject.

    All PS2 classics runs within the ps2_netemu.self which represents a different kernel for execution these PS2 games but before it started the VSH module loads your individual data for PSN/SEN (such as act.dat and .rif file for your game). It is absolutely the same process as used for usual PSN games and the goal of it is getting the key used for decryption of PS2 content which includes an optional CONFIG file, ISO.BIN.EDAT and ISO.BIN.ENC. The latest one is the actual encrypted disc image of the game. All mentioned files are encrypted with the same key (called klicensee) which is stored in encrypted form inside .rif file for your game and it decrypted with the specified key from key table stored in act.dat. When you get this key you can decrypt ISO.BIN.EDAT and see if it contains a game title (for example, SLUS-20062 for GTA 3). This will mean that key is correct. Since almost all the information regarding EDATs is known (see there and there) I will not going to explain it again.

    Well, now there are two another formats along with EDAT. Let's call the first one as ENC (it represents the actual disc image) and the second as VME (encrypted virtual memory cards). They are encrypted using different algorithms. The ENC format is similar to EDAT and the VME format have a simple encryption layer.

    As I said before, ENC file is similar to EDAT and it have the header like in EDAT (but with different magic) and composed of segments of 16384 bytes each (you can see it at the header). I just remind you that file header consists of file magic (PS2\x00), version number (major and minor: 01.01), license type (it always 0x02), application type (0x01), content id, QA digest (seems like to be a SHA-1 hash of the non-finalized file generated using the tool from SDK), CID-FN hash (an AES CMAC hash of concatenation of content id and file name using the third NPDRM OMAC key as CMAC key), header hash (an AES CMAC hash of the 0x60 bytes from the beginning of file using xored bytes of the first NPDRM OMAC key and the second NPDRM OMAC key as CMAC key), time information which includes start and end time of the validity period (they are usually zeroed, base ticks = 62135596800000000), file flags (always zeros), segment size (16384 bytes), data size of the file data, two unknown hashes of 16 bytes each, 40 bytes of unknown data (possible another unknown signature) and <R,S> pair of an ECDSA signature (40 bytes using the second VSH curve and the VSH public key). I also remind you that two unknown hashes for EDAT case are known and represents meta data sections hash and extended header hash (an AES CMAC hash of 160 bytes from the beginning of file), both hashes uses the hash key as CMAC key and it depends on the file flags and keys). I don't know exactly what hashes are there for ENC format but when we zeroed them it seems like they are not checked on current firmwares. The file header ends at the offset of 256 bytes.

    Segments are divided into two types: a meta data section and a file data section. Each meta data section can include 512 entries (max) of 32 bytes each (16384 / 32 = 512) and associates with a particular file data section. So if we have a meta data section which consists of 512 entries then it will mean that there are 512 file data sections after it and each file data section have size of 16384 bytes. Besides that, the first meta data segment located at the offset of 16384 bytes. I don't know what data are stored before it but we also tried to zero them (these bytes starting at the offset of 256 bytes and ending at the offset of 16384 bytes) and it works as usual. I guess that it can be the encrypted garbage because the alignment of file data should be equal to the segment size.

    Now I will explain what keys are used and how they are obtained. ENC/VME files are decrypted using the ENCDEC device so the decryption process are more faster than at EDAT case. While vSH checks files for their validity period, CMAC hashes and ECDSA signature and obtains the key for decryption from .rif file and it makes a system call # 475 to LV2 (on older firmwares it was # 471) along with the NPDRM information, klicensee, act.dat key and encrypted rif key. LV2 gets your console ID, encrypts the NPDRM constant using it as a key, decrypts the key from act.dat using the encrypted NPDRM constant and finally decrypts klicensee from .rif using the decrypted key from act.dat. Now we have a klicensee which will be used for later decryption process. For EDAT case we can use free EDATs without .rif but for PS2 classics we should always use paid content and .rif file. So if you want to resign the game you need to generate .rif for the account on your console (I call this process as "personalization"). Don't forget that .rif file should be created for your act.dat (because it shares the account id) and console ID. Let's move on. When the PS3 gets the final decryption key it send a packet to the system manager inside LV1 which sets the inter-lpar parameter of type 3. This parameter contains a version information and the klicensee. A system manager catches this packet and sends a request to the storage manager inside SS server # 1 which then configures ENCDEC keys used for later decryption. It should be kept in mind that keys for decryption differs between CEX and DEX consoles so the storage manager checks the device type and uses different key slots for ENCDEC. The configuration process started with running isolated SPU SB module which creates the final keys using klicensee as a key seed and send them back to the PPU which then send them to the device directly during the secure session. There are three types of keys: meta key, data key and vmc key and they are configured separately. The process of making keys consists of applying an AES 128 algorithm on the klicensee while using three different keys.

    There are SHA-1 hashes of each of three keys (you should decrypt sb_iso_spu_module.self from 4.xx FW and find each of 16 bytes key by its SHA-1 hash):

    For CEX mode:
    Code:

    Code:
    1. Meta key: B9CACFF9E126F63634DC38AF61040BDF6F370A26
    	2. Data key: CB0BAECAAADF9E5C629522B11757F78C7CD5B23C
    	3. VMC key:  EB03D83F96E3394A05BCE68F8645DA134CDA5545
    For DEX mode (you actually don't need it but anyways):
    Code:

    Code:
    	1. Meta key: 4FCFB6683AC46E73FFFCE49895E3F303A117BE8C
    	2. Data key: AEC7A9C13A4023FE268A163FFDC8382F45496928
    	3. VMC key:  B41AEE9D3B6C54292469C9C754AE8FE75ACBE958
    Now we have all keys which are required to decrypt all files. So what we should also know?

    ENC encryption uses an AES algorithm in CBC mode and the initialization vector of all zeros. The actual process of decryption of CONFIG and ISO.BIN.ENC started at seeking to the offset of 16384 bytes. There is a first meta data section so we should use the meta key as key for AES and decrypt the entire segment of 16384 bytes. As I said before each meta data sections contains of some entries and each entry have a size of 32 bytes. Each entry contains a SHA-1 hash (20 bytes) of the corresponding entire encrypted file data section and all these sections are located after this meta data section. After the SHA-1 hash we can see the section index of the corresponding file data section (4 bytes). The rest is padded of zeros. After decryption of the meta data section we can decrypt all file data sections after it. Now we should use the data key! Before the actual decryption we can check the SHA-1 hash of each encrypted file data section and see if they matched to the hashes at entry table of the meta data section. If the actual file size of the disc image is not a multiple of 16834 bytes then we have less entries inside the latest meta data section. After we finished the decryption of first 512 file data sections we can started decryption of the second meta data section and set of 512 file data sections after it and so on. I recommend to write decrypted meta data entries to another file than in the same file as file data section. It will make a process more easier. After decryption you should truncate your actual file to the data size specified at the header. Now you got an UDF disc image and you can mount it on your PC, for example.

    So what is the next step? The next step is the decryption of encrypted virtual memory cards. Each PS2 classics package contains two empty encrypted virtual memory cards which located at SCEVMC0.VME and SCEVMC1.VME. As far I see they are identical for all games so we can use templates for all new virtual memory cards but only encrypts them with the new klicensee. To decrypt virtual memory cards you need to read an each segment of 16384 bytes and apply an AES encryption in CBC mode too but for this case you should use the VMC key. After decryption you should see Sony PS2 Memory Card Format 1.2.0.0 at the top of file.

    Well, I attached a draft script for decryption of ENC/VME files. It was written for Python 2.7 and requires CryptoPlus (can be downloaded from: http://repo.or.cz/w/python-cryptoplus.git) and "ecdsa" (use EasyInstall or another package manager) libraries. I intentionally left all keys as SHA-1 hashes because of legal issues but you can find all keys by yourself using my hints. My script uses CONFIG/ISO.BIN.ENC/SCEVM0.VME/SCEVM1.VME file and klicensee file as input parameters. I hope that someone will create tools for that.
    To use the script you need to create a file with name vsh.curves and put the contents of the curve table from VSH (get it from http://ps3devwiki.com/wiki/Keys at vsh pub + curvetable) and replace all hashes of keys by their real values (see FIXME comments). Also replace three NPDRM OMAC keys and VSH public key by their values from http://ps3devwiki.com/wiki/Keys.

    I think that creation of PS2 remastering tool can lead us to getting the fully working games on our consoles but it requires testing. I recommend to create a static klicensee which can be used to encrypt all images in the same manner (static klicensee can also be implemented by patching VSH/LV2 at runtime, for example). After generating a klicensee you should create all keys based on it.
    To build an encrypted disc image you should dump the original disc image and then append zero bytes to the end to make it multiple of 16384 bytes. Then you need to encrypt each of 512 segments using the generated data key. Then you should calculate SHA-1 hashes of each encrypted segment and generate meta data section for each pair of segment hash and segment index. After this you need to encrypt meta data section and so on. At the end you need to write an original disc image size to the header, write a content id for it and generate hashes at the file header.
    After building ISO.BIN.ENC file you should create a file with the title id and pad it with zero bytes from the right side to get 12 bytes total. Then you need to create an EDAT container for this file. Hint: you can see a correct title id when mounting a disc image on your PC and looking at SYSTEM.CNF of it.
    Unfortunately, I hadn't time to see what the CONFIG file does so I will skip this step. I only know that this file is optional or can be empty inside (after decryption).
    You are not required (and you simply can't do it) to generate a valid ECDSA signature for files because all custom firmwares are patched to skip the ECDSA check.
    Will be nice to be able to generate a game package for your PS2 game too if everything will works fine. Remember, that some flags at PS2 pkg format can be different.

    Private Paste - Pastie

    Credits to:
    graf_chokolo, fail0verflow, JuanNadie, ps3dev.net, glevand and all my friends (you know who you are).




    Source: Ps3Hax.net


    PSX-SCENE: The Pinnacle Scene Xenocracy
    deank, Spacerat, SkyNet and 6 others like this.
    Comments 10 Comments
    1. RazorX's Avatar
      RazorX -
      i hope this leads to an app that allows you to create ps2 classics from ps2 isos that would be great
    1. Three-Socks's Avatar
      Three-Socks -
      Sad to hear flatz won't be working on ps3 anymore but what a leaving present!

      Thanks flaz/JuanNadie for all the hard work and time you put into this.
    1. ccfman2004's Avatar
      ccfman2004 -
      This is some great info. Too bad I don't understand most of it.

      I hope this will eventually lead us to be able to create our own PS2 classics as Sony seems to be only interested in games like Dora the Explorer and Diego.
    1. JOshISPoser's Avatar
      JOshISPoser -
      hopefully it allows us to play from discs, also. i mean, ps2 are a lil bigger than psx games and that'll fill an internal drive pretty quickly.
    1. bearmon2010's Avatar
      bearmon2010 -
      Wait.. it did say all PS3 systems!!! Including PS3 slim too? I hope so.
    1. OpenSource's Avatar
      OpenSource -
      PS2Classic first commit uploaded by USER on PS3DEV Git net.

      http://gitorious.ps3dev.net/ps2classic

      here compiled ver:

      http://www.mediafire.com/?721sd3035o9s22t

      Is a new version of py script of flatz ported to C and now including encryption stuff, so now we can decrypt and encrypt any ps2 classic, ps2 backwards compatibility for every PS3!.

      So ps2 modding of any ps2 classic is possible like modding gta san andreas ps2 classic like on ps2 times and obviusly too encrypting any ps2 iso but we don't know all about compatibility but it looks like a good amount of games should work.

      We need to test Open PS2 loader and ps2 homebrew and see if they work too on last emulator from sony.

      usage:
      iso:
      ps2classic d [cex/dex] [klicensee] [encrypted image] [out data] [out meta]
      ps2classic e [cex/dex] [klicensee] [iso] [out data] [real out name] [CID]
      vmc:
      ps2classic vd [cex/dex] [vme file] [out vmc] [(eid root key)]
      ps2classic ve [cex/dex] [vmc file] [out vme] [(eid root key)]

      Thanks to flatz and user for the source code.
    1. STLcardsWS's Avatar
      STLcardsWS -
      Awesome Work #fllatz i see lots of good things coimg to slim owners
    1. szczuru's Avatar
      szczuru -
      Remastering "PS2 games non released as classics" is now avadible! I'm Now playing FFX on Slim

      Tutorial:
      [Guide] Obtain, unpack, decrypt, encrypt and repackage a PS2 Classic - PS3Hax Network - Playstation 3 Hacks and Mods

      Necessary info - need to be added to iso before converting (not included in tutorial):
      PS3Hax Network - Playstation 3 Hacks and Mods - View Single Post - PS2 classics algorithm

      Also Aldo released a 1.1 version of his GUI for PS2Classics:

      Changes in 1.1:
      - Added support for drag & drop and command line interface (CLI) -> pass the full path of the image as parameter.
      - Added support for auto decryption if a PKG is selected or passed as parameter.
      - RAP files are auto copied to the RAPS folder if they are present in the same folder of the PKG or in a "exdata" folder
      - Pad verification (for multiple of 0x4000) now asks if you want to add the required padding when needed.
      - Image type (CD or DVD) is now detected and displayed on the GUI
      - Added option to patch the image with the file size and image type (CD or DVD)
      The program looks for the LIMG header in the offset (File Size - 0x4000), and changes the 4 bytes size (in big endian format) to:
      (Image Size - 0x4000) \ 0x800 for DVD and sets 8th byte to 1. Bytes 15-16 are set to 08 00
      (Image Size - 0x4000) \ 0x930 for CD and sets 8th byte to 2. Bytes 15-16 are set to 09 30


      http://aldostools.org/temp/ps2classics_GUI.rar
    1. JonJonB's Avatar
      JonJonB -
      Wow, that was a quick turnaround. Awesome news, I'll have to look into having a go myself.
    1. shadowXtreme's Avatar
      shadowXtreme -
      As far as I read, I can say thath ps2classics can work on DEX MODE, but .. ps2classics are not working for me in dex mode, and maybe never will..
  • Daily Digest


    Want to receive the latest PSX info in your email?

    Sign up for our Daily Digest!



    Want to learn more about the team keeping you up to date with the latest scene news?

    Read about them now!

    Check out our Developer bios, too!

  • Recent Threads

    TheRealDR3W

    Borderlands 2 Modding

    Thread Starter: TheRealDR3W

    I've been doing some research and I've found some pretty handy tools but I'm still having trouble wrapping my head around a lot of it. I don't suppose

    Last Post By: TheRealDR3W Today, 03:29 AM Go to last post
    Bluexmen

    Backup Hd to another hd?

    Thread Starter: Bluexmen

    Hi was wondering if there was a way to backup an old hard drive to another new hard drive either from PS2 or PC or mac? I would be alright with mac. or

    Last Post By: No0bZiLLa Today, 01:00 AM Go to last post
    hni19

    Problem when attempting to play Kingdom Hearts burned from ISO file?

    Thread Starter: hni19

    I seem to be having a problem attempting to get Kingdom Hearts working through burning an ISO file.

    The process which I follow is.

    Last Post By: amp2006 Today, 01:39 AM Go to last post
    STLcardsWS

    PSX-Scene Files: The Collection

    Thread Starter: STLcardsWS





    What is PSX-Scene Files?

    PSX-Scene Files is a new series we have decided to kick off here at PSX-Scene.com

    Last Post By: STLcardsWS Yesterday, 08:52 PM Go to last post
    ilikeUallNOgay

    RELEASE pOrtal mod

    Thread Starter: ilikeUallNOgay

    its complete , no more glitches . and i added more stuff to it .
    pleaze tell me what would you want me to add and i will for sure D

    Last Post By: Avery Yesterday, 10:45 PM Go to last post
    suddene

    Strange HD Swap auto Downgraded Rogero 4.41 to 4.40 1.03

    Thread Starter: suddene

    Had a strange incident earlier, just wondering why it happened, maybe it's a common occurrence, not sure, any insight would be appreciated. I had a 160GB

    Last Post By: suddene Yesterday, 07:36 PM Go to last post
  • Recent Comments

    Tranced

    Looks like Microsoft is rethinking their DRM restrictions

    Then we will boycott the game developers like we would have with Xbox One. Imagine spending... Go to last post

    Tranced Today 03:26 AM
    Slainedog

    Looks like Microsoft is rethinking their DRM restrictions

    What a U-turn. Like they needed feedback to figure that it was a bad idea. They just knew the PS4... Go to last post

    Slainedog Today 03:12 AM
    JonJonB

    PS3 Official Firmware 4.45 Released Then Pulled - Reports Suggest A Brick Fest!

    Where does this idea come from? They gave me a replacement PS2 like ten years ago, all I had to do... Go to last post

    JonJonB Today 03:04 AM
    phistyle

    Looks like Microsoft is rethinking their DRM restrictions

    I don't know why people keep saying it's too late for the xbox one. Well, actually, I do know. ... Go to last post

    phistyle Today 02:22 AM
    BahumatLord

    Looks like Microsoft is rethinking their DRM restrictions

    Kinda wondering why nobody seems to be talking about these camera devices on consoles and the NSA's... Go to last post

    BahumatLord Today 02:05 AM
    NuBiXx

    Looks like Microsoft is rethinking their DRM restrictions

    Oh OK Go to last post

    NuBiXx Today 01:04 AM
    No0bZiLLa

    Looks like Microsoft is rethinking their DRM restrictions

    nah, im pretty sure they mean after you setup the xbox one itself, then you can play all yoru games... Go to last post

    No0bZiLLa Today 01:03 AM
    NuBiXx

    Looks like Microsoft is rethinking their DRM restrictions

    Maybe I'm wrong, the way I think it says that you can play offline after a one time setup by setup... Go to last post

    NuBiXx Today 01:01 AM
    No0bZiLLa

    Looks like Microsoft is rethinking their DRM restrictions

    yes, the one time setup is for the system itself. not games. all games can be played without having... Go to last post

    No0bZiLLa Today 12:57 AM
    No0bZiLLa

    Looks like Microsoft is rethinking their DRM restrictions

    you dont have to have it connected to the internet to play games. it says it right in the quote... Go to last post

    No0bZiLLa Today 12:55 AM