Talk:Keys: Difference between revisions

From PS4 Developer wiki
Jump to navigation Jump to search
(Moved to non-talk.)
 
(151 intermediate revisions by 9 users not shown)
Line 1: Line 1:
= Other random values in ShellCore =
= EAP/EMC Aeolia Script for decrypting and keeping header =


* 59 ED 05 E1 2B 97 3E E0 62 B8 07 A4 EB 48 10 10 (http related)
<pre>
* 65 9A 82 19 27 CF D6 2F 0C 1C C2 5F AF 67 96 5B (0x40 size, prolly http related)
import struct
* E7 F5 9C F2 AC 00 1C 3C 57 17 1C 82 4D 80 0B 57 (0x80 size, NP COMM SIGN related)
from binascii import unhexlify as uhx
* 27 59 CD 8F 49 24 CF C5 64 2C 1A 44 E6 B6 12 79 (0x20 size, sp-int/ prod-qa / mgmt / np related? interesting stuff)
from binascii import hexlify as hx
* 56 EE 5E 50 F9 58 97 47 DF 80 5B 3D 31 A5 A7 6B (0x20 size, sp-int/ prod-qa / mgmt / np related? interesting stuff)
from Crypto.Cipher import AES
* 4D 35 CC 3E 38 17 64 E2 DE F1 DC 7C 97 3E 6D 62 (0x100 size, sp-int?)
from Crypto.Hash import SHA, HMAC
* B3 A8 76 EC D6 BA 02 43 72 B1 95 AD D7 47 3C 74 (0x100 size, prod-qa?)
 
* 09 CC 88 B3 8F D3 51 78 28 0F 63 E8 85 2A 00 E0 (0x100 size, mgmt?)
import os
* C1 64 9F 42 A4 70 6B B5 2E 93 E2 6E C2 2B 64 BC (0x100 size, np?)
import sys
* 27 38 04 D2 5D A5 BA DE FF 59 C1 B9 2B 39 B8 40 (0x20 size)
* 33 D5 1F 9C 1A 4A AE 43 EC 54 99 4A 77 04 41 B2 (0x80 size, AES related)
* A7 99 29 D4 F4 25 C5 5C 9C A7 30 D4 62 D2 18 10 (0x80 size, AES related)
* BC C7 43 2A 7D 34 0A D8 35 6C 4F 6C AE 55 52 6B (0x80 size, AES related)
* D2 C3 D1 98 09 5C 73 FB 69 6F 6C 09 22 E3 84 0D (0x80 size, AES related)
* DE EF DF 9A 3A A6 C9 58 85 9A F0 D6 69 F7 A1 AD (0x20 size, AES related)
* 67 A7 CA 31 48 7A 5C 32 B4 83 8F 37 AA E5 9A 2A (0x20 size, AES related)
* 6E 58 9C 22 A7 96 11 2B 80 25 15 22 CC BA D1 72 (0x20 size, AES related)
* 33 F0 8A B8 DA 6F DD 99 08 6B 68 FF 28 DE E3 2D (0x20 size, AES related)
* 16 6B CA 06 61 F5 EA 64 FA CF 4A 87 8B AE D2 C0 (AES related)
* F7 D3 E8 A1 AB A1 FE 27 8E A1 C2 62 5D 1D F8 C4 (0x80 bytes)


= Database reconstruction magic =
CIPHERKEYSEMC = ['5F74FE7790127FECF82CC6E6D91FA2D1'] # FULL
CIPHERKEYSEAP = ['581A75D7E9C01F3C1BD7473DBD443B98']
HASHERKEYEMC  = ['73FE06F3906B05ECB506DFB8691F9F54']
HASHERKEYEAP  = ['824D9BB4DBA3209294C93976221249E4']
ZEROS128 =      ['00000000000000000000000000000000']


<pre>
def aes_decrypt_cbc(key, iv, input):
0102FECA (or CAFE0201 byteswapped)
    return AES.new(key, AES.MODE_CBC, iv).decrypt(input)
</pre>
   
def aes_encrypt_cbc(key, iv, input):
    return AES.new(key, AES.MODE_CBC, iv).encrypt(input)


= Portable Keys Dumps =
def emc_decrypt_header(hdr):
    return hdr[:0x30] + aes_decrypt_cbc(uhx(CIPHERKEYSEMC[0]), uhx(ZEROS128[0]), hdr[0x30:0x80])
   
def emc_encrypt_header(hdr):
    return hdr[:0x30] + aes_encrypt_cbc(uhx(CIPHERKEYSEMC[0]), uhx(ZEROS128[0]), hdr[0x30:0x80])
   
def eap_decrypt_header(hdr):
    return hdr[:0x30] + aes_decrypt_cbc(uhx(CIPHERKEYSEAP[0]), uhx(ZEROS128[0]), hdr[0x30:0x80])
   
def eap_encrypt_header(hdr):
    return hdr[:0x30] + aes_encrypt_cbc(uhx(CIPHERKEYSEAP[0]), uhx(ZEROS128[0]), hdr[0x30:0x80])


== pfsSKKey__SecKey (External) ==
def main(argc, argv):
        with open(sys.argv[1], 'rb') as f:
            data = f.read(0x80)
            type = data[7:8]
            if type == uhx('48'):
                print 'EMC'
                hdr = emc_decrypt_header(data)
                body_aes_key  = hdr[0x30:0x40]
                body_hmac_key = hdr[0x40:0x50]
                body_hmac = hdr[0x50:0x64]
                zeroes = hdr[0x64:0x6C]
                print(hx(zeroes))
                header_hmac = hdr[0x6C:0x80]
                body_len = struct.unpack('<L', hdr[0xc:0x10])[0]
                print body_len
                ehdr = hdr[:0x6C]
                ebody = f.read(body_len)
                bhmac = HMAC.new(body_hmac_key, ebody, SHA)
                hhmac = HMAC.new(uhx(HASHERKEYEMC[0]), ehdr, SHA)
                body = aes_decrypt_cbc(body_aes_key, uhx(ZEROS128[0]), ebody)
                print bhmac.hexdigest()
                print hhmac.hexdigest()
                print hx(body_hmac)
                print hx(header_hmac)
                with open(sys.argv[1] + '.bin', 'wb') as g:
                    g.write(hdr+body)
            if type == uhx('68'):
                print 'EAP'
                hdr = eap_decrypt_header(data)
                body_aes_key  = hdr[0x30:0x40]
                body_hmac_key = hdr[0x40:0x50]
                body_hmac = hdr[0x50:0x64]
                zeroes = hdr[0x64:0x6C]
                print(hx(zeroes))
                header_hmac = hdr[0x6C:0x80]
                body_len = struct.unpack('<L', hdr[0xc:0x10])[0]
                print body_len
                ehdr = hdr[:0x6C]
                ebody = f.read(body_len)
                bhmac = HMAC.new(body_hmac_key, ebody, SHA)
                hhmac = HMAC.new(uhx(HASHERKEYEAP[0]), ehdr, SHA)
                body = aes_decrypt_cbc(body_aes_key, uhx(ZEROS128[0]), ebody)
                print bhmac.hexdigest()
                print hhmac.hexdigest()
                print hx(body_hmac)
                print hx(header_hmac)
                with open(sys.argv[1] + '.bin', 'wb') as g:
                    g.write(hdr+body)
           
           


<pre>
if __name__ == '__main__':
00000000  70 66 73 53 4b 4b 65 79  5f 5f 53 65 63 4b 65 79  |pfsSKKey__SecKey|
    main(len(sys.argv), sys.argv)
00000010  b5 da ef ff 39 e6 d9 0e  ca 7d c5 b0 29 a8 15 3e  |....9....}..)..>|
00000020  87 07 96 0a 53 46 8d 6c  84 3b 3d c9 62 4e 22 af  |....SF.l.;=.bN".|
00000030  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000080
</pre>
</pre>


== SCE_EAP_HDD__KEY (External) ==
= EAP/EMC Aeolia Script for encrypting (with header necessary) =


<pre>
<pre>
00000000  53 43 45 5f 45 41 50 5f  48 44 44 5f 5f 4b 45 59  |SCE_EAP_HDD__KEY|
import struct
00000010  bb 6c d6 6d dc 67 1f ac  36 64 f7 bf 50 49 ba a8  |.l.m.g..6d..PI..|
from binascii import unhexlify as uhx
00000020  c4 68 79 04 bc 31 cf 4f  2f 4e 9f 89 fa 45 87 93  |.hy..1.O/N...E..|
from binascii import hexlify as hx
00000030  81 17 45 e7 c7 e8 0d 46  0f af 23 26 55 0b d7 e4  |..E....F..#&U...|
from Crypto.Cipher import AES
00000040  d2 a0 a0 d9 72 9d e5 d2  11 7d 70 67 6f 1d 55 74  |....r....}pgo.Ut|
from Crypto.Hash import SHA, HMAC
00000050  8d c1 7c df 29 c8 6a 85  5f 2a e9 a1 ad 3e 91 5f  |..|.).j._*...>._|
00000060  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000080
</pre>


== CFK1 (External) ==
import os
import sys


<pre>
CIPHERKEYSEMC = ['5F74FE7790127FECF82CC6E6D91FA2D1'] # FULL
00000000  43 46 4b 31 00 00 00 00  00 00 00 00 00 00 00 00  |CFK1............|
CIPHERKEYSEAP = ['581A75D7E9C01F3C1BD7473DBD443B98']
00000010 00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
HASHERKEYEMC = ['73FE06F3906B05ECB506DFB8691F9F54']
00000020 61 9a d0 db 62 cb 51 37  d8 aa 84 d0 28 b9 92 2d  |a...b.Q7....(..-|
HASHERKEYEAP = ['824D9BB4DBA3209294C93976221249E4']
00000030  74 46 01 4d 5a 20 67 31  af d2 ab 62 44 d1 f5 92  |tF.MZ g1...bD...|
ZEROS128 =     ['00000000000000000000000000000000']
00000040  de 9f 35 6c 99 1b 1c 04  3d 76 cd 9f b1 a7 03 57  |..5l....=v.....W|
00000050  89 73 d9 26 a1 60 ea 72  d8 e7 33 9f b0 52 f0 e2  |.s.&.`.r..3..R..|
00000060  06 80 47 c4 d7 7a fd fd  95 72 27 8d 97 ab f4 21  |..G..z...r'....!|
00000070  aa cd 9d 9d 2a a2 30 cc  0d 37 b8 69 47 d1 6a ac  |....*.0..7.iG.j.|
00000080
</pre>


== CFK1 (External-Extra) ==
def aes_decrypt_cbc(key, iv, input):
    return AES.new(key, AES.MODE_CBC, iv).decrypt(input)
   
def aes_encrypt_cbc(key, iv, input):
    return AES.new(key, AES.MODE_CBC, iv).encrypt(input)


<pre>
def emc_decrypt_header(hdr):
00000000  40 83 63 f3 b4 d0 4b 54  09 ba f3 f4 27 41 13 c4  |@.c...KT....'A..|
    return hdr[:0x30] + aes_decrypt_cbc(uhx(CIPHERKEYSEMC[0]), uhx(ZEROS128[0]), hdr[0x30:0x80])
00000010  ac 97 ae 26 3b 9b 26 1c  2d 87 50 35 80 a3 e0 34  |...&;.&.-.P5...4|
   
00000020  f9 97 e5 b9 8c 85 9d 90  33 68 04 32 81 1b 50 21  |........3h.2..P!|
def emc_encrypt_header(hdr):
00000030  1f a4 5d 36 63 a3 50 7b  cc 68 12 7c bf 9a aa 2d  |..]6c.P{.h.|...-|
    return hdr[:0x30] + aes_encrypt_cbc(uhx(CIPHERKEYSEMC[0]), uhx(ZEROS128[0]), hdr[0x30:])
00000040  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
   
*
def eap_decrypt_header(hdr):
00000080
    return hdr[:0x30] + aes_decrypt_cbc(uhx(CIPHERKEYSEAP[0]), uhx(ZEROS128[0]), hdr[0x30:0x80])
</pre>
   
def eap_encrypt_header(hdr):
    return hdr[:0x30] + aes_encrypt_cbc(uhx(CIPHERKEYSEAP[0]), uhx(ZEROS128[0]), hdr[0x30:0x80])


== SCEROOTPARAM_KEY (External) ==
def main(argc, argv):
        with open(sys.argv[1], 'rb') as f:
            data = f.read()
            type = data[7:8]
            if type == uhx('48'):
                print 'EMC'
               
                body_len = struct.unpack('<L', data[0xc:0x10])[0]
                body = data[0x80:0x80+body_len]
                body_aes_key  = data[0x30:0x40]
                ebody = aes_encrypt_cbc(body_aes_key, uhx(ZEROS128[0]), body)
                body_hmac_key = data[0x40:0x50]
                bhmac = HMAC.new(body_hmac_key, ebody, SHA)
                hdr = (data[0:0x50] + uhx(bhmac.hexdigest()) + data[0x64:0x6C])
                hhmac = HMAC.new(uhx(HASHERKEYEMC[0]), hdr, SHA)
                hdr = (hdr + uhx(hhmac.hexdigest()))
                hdr = emc_encrypt_header(hdr)
                print bhmac.hexdigest()
                print hhmac.hexdigest()
                with open(sys.argv[1] + '.bin', 'wb') as g:
                    g.write(hdr+ebody)
            if type == uhx('68'):
                print 'EAP'
                body_len = struct.unpack('<L', data[0xc:0x10])[0]
                body = data[0x80:0x80+body_len]
                body_aes_key  = data[0x30:0x40]
                ebody = aes_encrypt_cbc(body_aes_key, uhx(ZEROS128[0]), body)
                body_hmac_key = data[0x40:0x50]
                bhmac = HMAC.new(body_hmac_key, ebody, SHA)
                hdr = (data[0:0x50] + uhx(bhmac.hexdigest()) + data[0x64:0x6C])
                hhmac = HMAC.new(uhx(HASHERKEYEAP[0]), hdr, SHA)
                hdr = (hdr + uhx(hhmac.hexdigest()))
                hdr = eap_encrypt_header(hdr)
                print bhmac.hexdigest()
                print hhmac.hexdigest()
                with open(sys.argv[1] + '.bin', 'wb') as g:
                    g.write(hdr+ebody)
           
           


<pre>
if __name__ == '__main__':
00000000  53 43 45 52 4f 4f 54 50  41 52 41 4d 5f 4b 45 59  |SCEROOTPARAM_KEY|
    main(len(sys.argv), sys.argv)
00000010  01 00 01 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000020  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000040  29 ed 9c 0a f8 d3 97 00  29 85 a9 df d0 f2 47 21  |).......).....G!|
00000050  03 ea a7 1e b1 10 c0 03  99 b1 1d ec b2 e5 df 08  |................|
00000060  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000080
</pre>
</pre>


== SCEROOTPARAM_KEY (External-Extra1) ==
= Order of keys in [[SceShellCore]] =


<pre>
P->Q->DQ->QP
00000000  ab 75 84 e1 58 6e f3 38  66 3b 39 9b 09 40 49 54  |.u..Xn.8f;9..@IT|
 
00000010  6b ce b2 f0 9f 32 0a 1b  f8 de 0a a0 d1 5f 28 bd  |k....2......._(.|
Trophy Debug -> Trophy Retail
00000020  7f f5 78 1d c5 4c 80 fb  e4 7a 3e 36 91 8d 19 3e  |..x..L...z>6...>|
00000030  09 67 ae 3d 61 4e b1 4f  7d 71 cf 20 e4 40 71 1f  |.g.=aN.O}q. .@q.|
00000040  05 65 93 0d fd 2d a6 d1  21 3c ef f4 5a 00 97 cb  |.e...-..!<..Z...|
00000050  2f e9 ed b5 ce 07 bb d3  57 4e fa b1 ac a3 fe 80  |/.......WN......|
00000060  88 3f 0a 0e 75 9b 4f 2f  40 6a c6 ef 98 23 b9 e5  |.?..u.O/@j...#..|
00000070  ae bd 3b 75 b7 c6 e1 68  5f b3 90 c4 12 a0 4d 24  |..;u...h_.....M$|
00000080
</pre>


== SCE_LwUtoken_Key (External) ==
= Other random values in [[SceShellCore]] =


<pre>
* 59 ED 05 E1 2B 97 3E E0 62 B8 07 A4 EB 48 10 10 (HTTP related)
00000000  53 43 45 5f 4c 77 55 74 6f 6b 65 6e 5f 4b 65 79  |SCE_LwUtoken_Key|
* 65 9A 82 19 27 CF D6 2F 0C 1C C2 5F AF 67 96 5B (0x40 size, probably HTTP related)
00000010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
* E7 F5 9C F2 AC 00 1C 3C 57 17 1C 82 4D 80 0B 57 (0x80 size, NP COMM SIGN related)
*
* 27 59 CD 8F 49 24 CF C5 64 2C 1A 44 E6 B6 12 79 (0x20 size, sp-int/ prod-qa / mgmt / np related? interesting stuff)
00000040  e4 03 52 c3 02 18 f1 a6  22 5a cf 4c a7 9e 54 eb  |..R....."Z.L..T.|
* 56 EE 5E 50 F9 58 97 47 DF 80 5B 3D 31 A5 A7 6B (0x20 size, sp-int/ prod-qa / mgmt / np related? interesting stuff)
00000050  b2 7a bc be b7 1f b4 7a  5c d0 66 c7 9e 99 9f 2a  |.z.....z\.f....*|
* 4D 35 CC 3E 38 17 64 E2 DE F1 DC 7C 97 3E 6D 62 (0x100 size, sp-int?)
00000060  66 4a b9 75 36 4c f3 0e  75 ee 24 15 9c 38 51 f3  |fJ.u6L..u.$..8Q.|
* B3 A8 76 EC D6 BA 02 43 72 B1 95 AD D7 47 3C 74 (0x100 size, prod-qa?)
00000070  01 00 01 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
* 09 CC 88 B3 8F D3 51 78 28 0F 63 E8 85 2A 00 E0 (0x100 size, mgmt?)
00000080
* C1 64 9F 42 A4 70 6B B5 2E 93 E2 6E C2 2B 64 BC (0x100 size, np?)
</pre>
* 27 38 04 D2 5D A5 BA DE FF 59 C1 B9 2B 39 B8 40 (0x20 size)
* 33 D5 1F 9C 1A 4A AE 43 EC 54 99 4A 77 04 41 B2 (0x80 size, AES related)
* A7 99 29 D4 F4 25 C5 5C 9C A7 30 D4 62 D2 18 10 (0x80 size, AES related)
* BC C7 43 2A 7D 34 0A D8 35 6C 4F 6C AE 55 52 6B (0x80 size, AES related)
* D2 C3 D1 98 09 5C 73 FB 69 6F 6C 09 22 E3 84 0D (0x80 size, AES related)
* DE EF DF 9A 3A A6 C9 58 85 9A F0 D6 69 F7 A1 AD (0x20 size, AES related)
* 67 A7 CA 31 48 7A 5C 32 B4 83 8F 37 AA E5 9A 2A (0x20 size, AES related)
* 6E 58 9C 22 A7 96 11 2B 80 25 15 22 CC BA D1 72 (0x20 size, AES related)
* 33 F0 8A B8 DA 6F DD 99 08 6B 68 FF 28 DE E3 2D (0x20 size, AES related)
* 16 6B CA 06 61 F5 EA 64 FA CF 4A 87 8B AE D2 C0 (AES related)
* F7 D3 E8 A1 AB A1 FE 27 8E A1 C2 62 5D 1D F8 C4 (0x80 bytes)
* <s>42 42 AA FD 7A 05 B4 5C F3 5E 08 22 D4 55 97 45</s> (SceShellCore, QP, 0x80)

Latest revision as of 05:13, 1 January 2025

EAP/EMC Aeolia Script for decrypting and keeping header[edit source]

import struct
from binascii import unhexlify as uhx
from binascii import hexlify as hx
from Crypto.Cipher import AES
from Crypto.Hash import SHA, HMAC

import os
import sys

CIPHERKEYSEMC = ['5F74FE7790127FECF82CC6E6D91FA2D1'] # FULL
CIPHERKEYSEAP = ['581A75D7E9C01F3C1BD7473DBD443B98']
HASHERKEYEMC  = ['73FE06F3906B05ECB506DFB8691F9F54']
HASHERKEYEAP  = ['824D9BB4DBA3209294C93976221249E4']
ZEROS128 =      ['00000000000000000000000000000000']

def aes_decrypt_cbc(key, iv, input):
    return AES.new(key, AES.MODE_CBC, iv).decrypt(input)
    
def aes_encrypt_cbc(key, iv, input):
    return AES.new(key, AES.MODE_CBC, iv).encrypt(input)

def emc_decrypt_header(hdr):
    return hdr[:0x30] + aes_decrypt_cbc(uhx(CIPHERKEYSEMC[0]), uhx(ZEROS128[0]), hdr[0x30:0x80])
    
def emc_encrypt_header(hdr):
    return hdr[:0x30] + aes_encrypt_cbc(uhx(CIPHERKEYSEMC[0]), uhx(ZEROS128[0]), hdr[0x30:0x80])
    
def eap_decrypt_header(hdr):
    return hdr[:0x30] + aes_decrypt_cbc(uhx(CIPHERKEYSEAP[0]), uhx(ZEROS128[0]), hdr[0x30:0x80])
    
def eap_encrypt_header(hdr):
    return hdr[:0x30] + aes_encrypt_cbc(uhx(CIPHERKEYSEAP[0]), uhx(ZEROS128[0]), hdr[0x30:0x80])

def main(argc, argv):
        with open(sys.argv[1], 'rb') as f:
            data = f.read(0x80)
            type = data[7:8]
            if type == uhx('48'):
                print 'EMC'
                hdr = emc_decrypt_header(data)
                body_aes_key  = hdr[0x30:0x40]
                body_hmac_key = hdr[0x40:0x50]
                body_hmac = hdr[0x50:0x64]
                zeroes = hdr[0x64:0x6C]
                print(hx(zeroes))
                header_hmac = hdr[0x6C:0x80]
                body_len = struct.unpack('<L', hdr[0xc:0x10])[0]
                print body_len
                ehdr = hdr[:0x6C]
                ebody = f.read(body_len)
                bhmac = HMAC.new(body_hmac_key, ebody, SHA)
                hhmac = HMAC.new(uhx(HASHERKEYEMC[0]), ehdr, SHA)
                body = aes_decrypt_cbc(body_aes_key, uhx(ZEROS128[0]), ebody)
                print bhmac.hexdigest()
                print hhmac.hexdigest()
                print hx(body_hmac)
                print hx(header_hmac)
                with open(sys.argv[1] + '.bin', 'wb') as g:
                    g.write(hdr+body)
            if type == uhx('68'):
                print 'EAP'
                hdr = eap_decrypt_header(data)
                body_aes_key  = hdr[0x30:0x40]
                body_hmac_key = hdr[0x40:0x50]
                body_hmac = hdr[0x50:0x64]
                zeroes = hdr[0x64:0x6C]
                print(hx(zeroes))
                header_hmac = hdr[0x6C:0x80]
                body_len = struct.unpack('<L', hdr[0xc:0x10])[0]
                print body_len
                ehdr = hdr[:0x6C]
                ebody = f.read(body_len)
                bhmac = HMAC.new(body_hmac_key, ebody, SHA)
                hhmac = HMAC.new(uhx(HASHERKEYEAP[0]), ehdr, SHA)
                body = aes_decrypt_cbc(body_aes_key, uhx(ZEROS128[0]), ebody)
                print bhmac.hexdigest()
                print hhmac.hexdigest()
                print hx(body_hmac)
                print hx(header_hmac)
                with open(sys.argv[1] + '.bin', 'wb') as g:
                    g.write(hdr+body)
            
            

if __name__ == '__main__':
    main(len(sys.argv), sys.argv)

EAP/EMC Aeolia Script for encrypting (with header necessary)[edit source]

import struct
from binascii import unhexlify as uhx
from binascii import hexlify as hx
from Crypto.Cipher import AES
from Crypto.Hash import SHA, HMAC

import os
import sys

CIPHERKEYSEMC = ['5F74FE7790127FECF82CC6E6D91FA2D1'] # FULL
CIPHERKEYSEAP = ['581A75D7E9C01F3C1BD7473DBD443B98']
HASHERKEYEMC  = ['73FE06F3906B05ECB506DFB8691F9F54']
HASHERKEYEAP  = ['824D9BB4DBA3209294C93976221249E4']
ZEROS128 =      ['00000000000000000000000000000000']

def aes_decrypt_cbc(key, iv, input):
    return AES.new(key, AES.MODE_CBC, iv).decrypt(input)
    
def aes_encrypt_cbc(key, iv, input):
    return AES.new(key, AES.MODE_CBC, iv).encrypt(input)

def emc_decrypt_header(hdr):
    return hdr[:0x30] + aes_decrypt_cbc(uhx(CIPHERKEYSEMC[0]), uhx(ZEROS128[0]), hdr[0x30:0x80])
    
def emc_encrypt_header(hdr):
    return hdr[:0x30] + aes_encrypt_cbc(uhx(CIPHERKEYSEMC[0]), uhx(ZEROS128[0]), hdr[0x30:])
    
def eap_decrypt_header(hdr):
    return hdr[:0x30] + aes_decrypt_cbc(uhx(CIPHERKEYSEAP[0]), uhx(ZEROS128[0]), hdr[0x30:0x80])
    
def eap_encrypt_header(hdr):
    return hdr[:0x30] + aes_encrypt_cbc(uhx(CIPHERKEYSEAP[0]), uhx(ZEROS128[0]), hdr[0x30:0x80])

def main(argc, argv):
        with open(sys.argv[1], 'rb') as f:
            data = f.read()
            type = data[7:8]
            if type == uhx('48'):
                print 'EMC'
                
                body_len = struct.unpack('<L', data[0xc:0x10])[0]
                body = data[0x80:0x80+body_len]
                body_aes_key  = data[0x30:0x40]
                ebody = aes_encrypt_cbc(body_aes_key, uhx(ZEROS128[0]), body)
                body_hmac_key = data[0x40:0x50]
                bhmac = HMAC.new(body_hmac_key, ebody, SHA)
                hdr = (data[0:0x50] + uhx(bhmac.hexdigest()) + data[0x64:0x6C])
                hhmac = HMAC.new(uhx(HASHERKEYEMC[0]), hdr, SHA)
                hdr = (hdr + uhx(hhmac.hexdigest()))
                hdr = emc_encrypt_header(hdr)
                print bhmac.hexdigest()
                print hhmac.hexdigest()
                with open(sys.argv[1] + '.bin', 'wb') as g:
                    g.write(hdr+ebody)
            if type == uhx('68'):
                print 'EAP'
                body_len = struct.unpack('<L', data[0xc:0x10])[0]
                body = data[0x80:0x80+body_len]
                body_aes_key  = data[0x30:0x40]
                ebody = aes_encrypt_cbc(body_aes_key, uhx(ZEROS128[0]), body)
                body_hmac_key = data[0x40:0x50]
                bhmac = HMAC.new(body_hmac_key, ebody, SHA)
                hdr = (data[0:0x50] + uhx(bhmac.hexdigest()) + data[0x64:0x6C])
                hhmac = HMAC.new(uhx(HASHERKEYEAP[0]), hdr, SHA)
                hdr = (hdr + uhx(hhmac.hexdigest()))
                hdr = eap_encrypt_header(hdr)
                print bhmac.hexdigest()
                print hhmac.hexdigest()
                with open(sys.argv[1] + '.bin', 'wb') as g:
                    g.write(hdr+ebody)
            
            

if __name__ == '__main__':
    main(len(sys.argv), sys.argv)

Order of keys in SceShellCore[edit source]

P->Q->DQ->QP

Trophy Debug -> Trophy Retail

Other random values in SceShellCore[edit source]

  • 59 ED 05 E1 2B 97 3E E0 62 B8 07 A4 EB 48 10 10 (HTTP related)
  • 65 9A 82 19 27 CF D6 2F 0C 1C C2 5F AF 67 96 5B (0x40 size, probably HTTP related)
  • E7 F5 9C F2 AC 00 1C 3C 57 17 1C 82 4D 80 0B 57 (0x80 size, NP COMM SIGN related)
  • 27 59 CD 8F 49 24 CF C5 64 2C 1A 44 E6 B6 12 79 (0x20 size, sp-int/ prod-qa / mgmt / np related? interesting stuff)
  • 56 EE 5E 50 F9 58 97 47 DF 80 5B 3D 31 A5 A7 6B (0x20 size, sp-int/ prod-qa / mgmt / np related? interesting stuff)
  • 4D 35 CC 3E 38 17 64 E2 DE F1 DC 7C 97 3E 6D 62 (0x100 size, sp-int?)
  • B3 A8 76 EC D6 BA 02 43 72 B1 95 AD D7 47 3C 74 (0x100 size, prod-qa?)
  • 09 CC 88 B3 8F D3 51 78 28 0F 63 E8 85 2A 00 E0 (0x100 size, mgmt?)
  • C1 64 9F 42 A4 70 6B B5 2E 93 E2 6E C2 2B 64 BC (0x100 size, np?)
  • 27 38 04 D2 5D A5 BA DE FF 59 C1 B9 2B 39 B8 40 (0x20 size)
  • 33 D5 1F 9C 1A 4A AE 43 EC 54 99 4A 77 04 41 B2 (0x80 size, AES related)
  • A7 99 29 D4 F4 25 C5 5C 9C A7 30 D4 62 D2 18 10 (0x80 size, AES related)
  • BC C7 43 2A 7D 34 0A D8 35 6C 4F 6C AE 55 52 6B (0x80 size, AES related)
  • D2 C3 D1 98 09 5C 73 FB 69 6F 6C 09 22 E3 84 0D (0x80 size, AES related)
  • DE EF DF 9A 3A A6 C9 58 85 9A F0 D6 69 F7 A1 AD (0x20 size, AES related)
  • 67 A7 CA 31 48 7A 5C 32 B4 83 8F 37 AA E5 9A 2A (0x20 size, AES related)
  • 6E 58 9C 22 A7 96 11 2B 80 25 15 22 CC BA D1 72 (0x20 size, AES related)
  • 33 F0 8A B8 DA 6F DD 99 08 6B 68 FF 28 DE E3 2D (0x20 size, AES related)
  • 16 6B CA 06 61 F5 EA 64 FA CF 4A 87 8B AE D2 C0 (AES related)
  • F7 D3 E8 A1 AB A1 FE 27 8E A1 C2 62 5D 1D F8 C4 (0x80 bytes)
  • 42 42 AA FD 7A 05 B4 5C F3 5E 08 22 D4 55 97 45 (SceShellCore, QP, 0x80)