https://wiki.henkaku.xyz/vita/api.php?action=feedcontributions&user=Red-EyeX32&feedformat=atomVita Development Wiki - User contributions [en]2024-03-29T01:54:26ZUser contributionsMediaWiki 1.35.13https://wiki.henkaku.xyz/vita/index.php?title=PSVIMG&diff=10670PSVIMG2019-02-04T11:35:27Z<p>Red-EyeX32: /* Source code */</p>
<hr />
<div>PSVIMG files are encrypted files generated by [[CMA]] in backing up and restoring data from the Vita. The format is documented in this tool [https://github.com/yifanlu/psvimgtools].<br />
<br />
== Generating PSVIMG ==<br />
<br />
When [[CMA]] is used to backup system, game, or savedata from the PSVita to a PC or PS3, the following algorithm is used:<br />
<br />
# Using a tar-like structure, stream all of the file data into a file.<br />
# If making a PSVMD file, use the deflate algorithm to compress.<br />
# Generate a random nonce for the first 0x10 bytes using the RndNumber syscall.<br />
# Generate a [[#PSVIMG_Key_Derivation|unique session AES256-CBC key]] using a secret phrase and the account id.<br />
# Generate a SHA256 hash of the plaintext every 0x8000 bytes and insert the hash into the filestream.<br />
# Encrypt the stream data using [[SceSblSsMgr#sceSblDmac5EncDecKeyGen|sceSblDmac5EncDecKeyGen]] with the nonce as the header and the AES256-CBC session key. This key is set through kprx_auth_sm using [[F00D_Commands#0x50001|service 0x50001]]. It is then used in conjunction with encdec_w_portability to decrypt/encrypt PSVIMG blocks.<br />
# Transmit to PC or PS3.<br />
<br />
=== PSVIMG Key Derivation ===<br />
<br />
The AES256-CBC session key is calculated by:<br />
* Creating a 33 byte buffer composed of 8 byte hex binary representation of your account id followed by the 0x19 byte PSVIMG secret passphrase.<br />
* Calculating a SHA-256 hash of buffer above.<br />
* Decrypting the 32 byte output of the calculated SHA-256 hash with AES128-ECB (128 bit key stored in kprx_auth_sm).<br />
* This decrypted output is the derived PSVIMG AES256-CBC key.<br />
<br />
When you backup with CMA, the files are stored in a directory in your PC that consists of 16 character hex directory name within your backup path. That hex directory name is a representation of your account id.<br />
<br />
ex: \Documents\PS Vita\PSAVEDATA\0123456789abcdef\ with '0123456789abcdef' being your account id.<br />
<br />
==== Pseudocode ====<br />
<br />
<source lang="C"><br />
#define NP_ACCOUNT_ID_LEN 8<br />
#define CMA_PASSPHRASE_LEN 25<br />
<br />
static uint8_t passphrase[CMA_PASSPHRASE_LEN] = "Sri Jayewardenepura Kotte";<br />
<br />
{<br />
...<br />
memcpy(seed, aid, NP_ACCOUNT_ID_LEN);<br />
memcpy(seed + NP_ACCOUNT_ID_LEN, passphrase, CMA_PASSPHRASE_LEN);<br />
...<br />
<br />
int seed_len = (NP_ACCOUNT_ID_LEN + CMA_PASSPHRASE_LEN);<br />
sha256((uint8_t*)seed, seed_len, session_key, 0);<br />
aes_ecb_decrypt(session_key, CMA_SESSION_KEY_LEN);<br />
<br />
return session_key;<br />
}<br />
</source><br />
<br />
==== Example ====<br />
<br />
This is an example where we are going to use account id: 0123456789abcdef.<br />
<br />
<source><br />
Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F<br />
<br />
00000000 01 23 45 67 89 AB CD EF 53 72 69 20 4A 61 79 65 .#Eg‰«ÍïSri Jaye<br />
00000010 77 61 72 64 65 6E 65 70 75 72 61 20 4B 6F 74 74 wardenepura Kott<br />
00000020 65 e e<br />
</source><br />
<br />
SHA-256 hash of this 32 byte buffer:<br />
<source><br />
02EAAB5A00EC9D4207E8B1F53F8A2F3F91F1A73AAFDD2A81CCFEE3E83E5B101A<br />
</source><br />
<br />
The decrypted hash produces the following result after decrypting with AES128-ECB:<br />
<source><br />
Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F<br />
<br />
00000000 AC A8 2B 25 34 69 8F 3B 3B EB 21 20 69 E8 37 D3 ¬¨+%4i.;;ë! iè7Ó<br />
00000010 9E 85 34 69 73 78 89 8D 0E D7 30 7A D1 30 31 D4 ž…4isx‰..×0zÑ01Ô<br />
</source><br />
<br />
This 32 byte (256 bits) sized buffer is the PSVIMG AES256-CBC key.<br />
<br />
<br />
[[Category:Formats]]</div>Red-EyeX32https://wiki.henkaku.xyz/vita/index.php?title=PSVIMG&diff=10662PSVIMG2019-02-03T20:27:38Z<p>Red-EyeX32: /* Generating PSVIMG */</p>
<hr />
<div>PSVIMG files are encrypted files generated by [[CMA]] in backing up and restoring data from the Vita. The format is documented in this tool [https://github.com/yifanlu/psvimgtools].<br />
<br />
== Generating PSVIMG ==<br />
<br />
When [[CMA]] is used to backup system, game, or savedata from the PSVita to a PC or PS3, the following algorithm is used:<br />
<br />
# Using a tar-like structure, stream all of the file data into a file.<br />
# If making a PSVMD file, use the deflate algorithm to compress.<br />
# Generate a random nonce for the first 0x10 bytes using the RndNumber syscall.<br />
# Generate a [[#Key_Derivation|unique session AES256-CBC key]] using a secret phrase and the account id.<br />
# Generate a SHA256 hash of the plaintext every 0x8000 bytes and insert the hash into the filestream.<br />
# Encrypt the stream data using [[SceSblSsMgr#sceSblDmac5EncDecKeyGen|sceSblDmac5EncDecKeyGen]] with the nonce as the header and the AES256-CBC session key.<br />
# Transmit to PC or PS3.<br />
<br />
=== Key Derivation ===<br />
<br />
The AES256-CBC session key is calculated by:<br />
* Creating a 33 byte buffer composed of 8 byte hex binary representation of your account id followed by a secret passphrase.<br />
* Calculating a SHA-256 hash of buffer above.<br />
* Decrypt the 32 byte output of the calculated SHA-256 hash with AES128-ECB (128 bit key stored in kprx_sm_auth).<br />
* This decrypted output is the derived PSVIMG AES256-CBC key.<br />
<br />
When you backup with CMA, there should be a directory in your PC that consists of 16 character hex directory name within your backup path.<br />
<br />
That hex directory name is a representation of your account id. ex: \Documents\PS Vita\PSAVEDATA\0123456789abcdef\ '0123456789abcdef' being your account id.<br />
<source lang="cpp"><br />
#define CMA_ACCOUNT_ID_LEN 8<br />
#define CMA_PASSPHRASE_LEN 25<br />
<br />
static uint8_t passphrase[CMA_PASSPHRASE_LEN] = "Sri Jayewardenepura Kotte";<br />
<br />
{<br />
...<br />
memcpy(seed, aid, CMA_ACCOUNT_ID_LEN);<br />
memcpy(seed + CMA_ACCOUNT_ID_LEN, passphrase, CMA_PASSPHRASE_LEN);<br />
...<br />
<br />
int seed_len = (CMA_ACCOUNT_ID_LEN + CMA_PASSPHRASE_LEN);<br />
sha256((uint8_t*)seed, seed_len, session_key, 0);<br />
aes_ecb_decrypt(session_key, CMA_SESSION_KEY_LEN);<br />
<br />
return session_key;<br />
}<br />
</source><br />
==== Example ====<br />
<br />
This is an example where we are going to use account id: 0123456789abcdef<br />
<br />
<source><br />
Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F<br />
<br />
00000000 01 23 45 67 89 AB CD EF 53 72 69 20 4A 61 79 65 .#Eg‰«ÍïSri Jaye<br />
00000010 77 61 72 64 65 6E 65 70 75 72 61 20 4B 6F 74 74 wardenepura Kott<br />
00000020 65 e e<br />
</source><br />
SHA-256 hash of this 32 byte buffer:<br />
<source><br />
02EAAB5A00EC9D4207E8B1F53F8A2F3F91F1A73AAFDD2A81CCFEE3E83E5B101A<br />
</source><br />
<br />
The decrypted hash produces the following result after decrypting with AES128-ECB:<br />
<source><br />
Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F<br />
<br />
00000000 AC A8 2B 25 34 69 8F 3B 3B EB 21 20 69 E8 37 D3 ¬¨+%4i.;;ë! iè7Ó<br />
00000010 9E 85 34 69 73 78 89 8D 0E D7 30 7A D1 30 31 D4 ž…4isx‰..×0zÑ01Ô<br />
</source><br />
<br />
This 32 byte (256 bits) sized buffer is the PSVIMG AES256-CBC key.<br />
<br />
[[Category:Formats]]</div>Red-EyeX32https://wiki.henkaku.xyz/vita/index.php?title=PSVIMG&diff=10661PSVIMG2019-02-03T20:27:11Z<p>Red-EyeX32: /* Generating PSVIMG */</p>
<hr />
<div>PSVIMG files are encrypted files generated by [[CMA]] in backing up and restoring data from the Vita. The format is documented in this tool [https://github.com/yifanlu/psvimgtools].<br />
<br />
== Generating PSVIMG ==<br />
<br />
When [[CMA]] is used to backup system, game, or savedata from the PSVita to a PC or PS3, the following algorithm is used:<br />
<br />
# Using a tar-like structure, stream all of the file data into a file.<br />
# If making a PSVMD file, use the deflate algorithm to compress.<br />
# Generate a random nonce for the first 0x10 bytes using the RndNumber syscall.<br />
# Generate a [[#PSVIMG_Key_Derivation|unique session AES256-CBC key]] using a secret phrase and the account id.<br />
# Generate a SHA256 hash of the plaintext every 0x8000 bytes and insert the hash into the filestream.<br />
# Encrypt the stream data using [[SceSblSsMgr#sceSblDmac5EncDecKeyGen|sceSblDmac5EncDecKeyGen]] with the nonce as the header and the AES256-CBC session key.<br />
# Transmit to PC or PS3.<br />
<br />
=== Key Derivation ===<br />
<br />
The AES256-CBC session key is calculated by:<br />
* Creating a 33 byte buffer composed of 8 byte hex binary representation of your account id followed by a secret passphrase.<br />
* Calculating a SHA-256 hash of buffer above.<br />
* Decrypt the 32 byte output of the calculated SHA-256 hash with AES128-ECB (128 bit key stored in kprx_sm_auth).<br />
* This decrypted output is the derived PSVIMG AES256-CBC key.<br />
<br />
When you backup with CMA, there should be a directory in your PC that consists of 16 character hex directory name within your backup path.<br />
<br />
That hex directory name is a representation of your account id. ex: \Documents\PS Vita\PSAVEDATA\0123456789abcdef\ '0123456789abcdef' being your account id.<br />
<source lang="cpp"><br />
#define CMA_ACCOUNT_ID_LEN 8<br />
#define CMA_PASSPHRASE_LEN 25<br />
<br />
static uint8_t passphrase[CMA_PASSPHRASE_LEN] = "Sri Jayewardenepura Kotte";<br />
<br />
{<br />
...<br />
memcpy(seed, aid, CMA_ACCOUNT_ID_LEN);<br />
memcpy(seed + CMA_ACCOUNT_ID_LEN, passphrase, CMA_PASSPHRASE_LEN);<br />
...<br />
<br />
int seed_len = (CMA_ACCOUNT_ID_LEN + CMA_PASSPHRASE_LEN);<br />
sha256((uint8_t*)seed, seed_len, session_key, 0);<br />
aes_ecb_decrypt(session_key, CMA_SESSION_KEY_LEN);<br />
<br />
return session_key;<br />
}<br />
</source><br />
==== Example ====<br />
<br />
This is an example where we are going to use account id: 0123456789abcdef<br />
<br />
<source><br />
Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F<br />
<br />
00000000 01 23 45 67 89 AB CD EF 53 72 69 20 4A 61 79 65 .#Eg‰«ÍïSri Jaye<br />
00000010 77 61 72 64 65 6E 65 70 75 72 61 20 4B 6F 74 74 wardenepura Kott<br />
00000020 65 e e<br />
</source><br />
SHA-256 hash of this 32 byte buffer:<br />
<source><br />
02EAAB5A00EC9D4207E8B1F53F8A2F3F91F1A73AAFDD2A81CCFEE3E83E5B101A<br />
</source><br />
<br />
The decrypted hash produces the following result after decrypting with AES128-ECB:<br />
<source><br />
Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F<br />
<br />
00000000 AC A8 2B 25 34 69 8F 3B 3B EB 21 20 69 E8 37 D3 ¬¨+%4i.;;ë! iè7Ó<br />
00000010 9E 85 34 69 73 78 89 8D 0E D7 30 7A D1 30 31 D4 ž…4isx‰..×0zÑ01Ô<br />
</source><br />
<br />
This 32 byte (256 bits) sized buffer is the PSVIMG AES256-CBC key.<br />
<br />
[[Category:Formats]]</div>Red-EyeX32https://wiki.henkaku.xyz/vita/index.php?title=PSVIMG&diff=10660PSVIMG2019-02-03T20:21:11Z<p>Red-EyeX32: </p>
<hr />
<div>PSVIMG files are encrypted files generated by [[CMA]] in backing up and restoring data from the Vita. The format is documented in this tool [https://github.com/yifanlu/psvimgtools].<br />
<br />
== Generating PSVIMG ==<br />
<br />
When [[CMA]] is used to backup system, game, or savedata from the PSVita to a PC or PS3, the following algorithm is used:<br />
<br />
# Using a tar-like structure, stream all of the file data into a file.<br />
# If making a PSVMD file, use the deflate algorithm to compress.<br />
# Generate a random nonce for the first 0x10 bytes using the RndNumber syscall.<br />
# Generate a [[#PSVIMG_AES256-CBC_key generation|unique session AES256-CBC key]] using a secret phrase and the PSN account id.<br />
# Generate a SHA256 hash of the plaintext every 0x8000 bytes and insert the hash into the filestream.<br />
# Encrypt the stream data using [[SceSblSsMgr#sceSblDmac5EncDecKeyGen|sceSblDmac5EncDecKeyGen]] with the nonce as the header and the AES256-CBC session key.<br />
# Transmit to PC or PS3.<br />
<br />
=== Key Derivation ===<br />
<br />
The AES256-CBC session key is calculated by:<br />
* Creating a 33 byte buffer composed of 8 byte hex binary representation of your account id followed by a secret passphrase.<br />
* Calculating a SHA-256 hash of buffer above.<br />
* Decrypt the 32 byte output of the calculated SHA-256 hash with AES128-ECB (128 bit key stored in kprx_sm_auth).<br />
* This decrypted output is the derived PSVIMG AES256-CBC key.<br />
<br />
When you backup with CMA, there should be a directory in your PC that consists of 16 character hex directory name within your backup path.<br />
<br />
That hex directory name is a representation of your account id. ex: \Documents\PS Vita\PSAVEDATA\0123456789abcdef\ '0123456789abcdef' being your account id.<br />
<source lang="cpp"><br />
#define CMA_ACCOUNT_ID_LEN 8<br />
#define CMA_PASSPHRASE_LEN 25<br />
<br />
static uint8_t passphrase[CMA_PASSPHRASE_LEN] = "Sri Jayewardenepura Kotte";<br />
<br />
{<br />
...<br />
memcpy(seed, aid, CMA_ACCOUNT_ID_LEN);<br />
memcpy(seed + CMA_ACCOUNT_ID_LEN, passphrase, CMA_PASSPHRASE_LEN);<br />
...<br />
<br />
int seed_len = (CMA_ACCOUNT_ID_LEN + CMA_PASSPHRASE_LEN);<br />
sha256((uint8_t*)seed, seed_len, session_key, 0);<br />
aes_ecb_decrypt(session_key, CMA_SESSION_KEY_LEN);<br />
<br />
return session_key;<br />
}<br />
</source><br />
==== Example ====<br />
<br />
This is an example where we are going to use account id: 0123456789abcdef<br />
<br />
<source><br />
Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F<br />
<br />
00000000 01 23 45 67 89 AB CD EF 53 72 69 20 4A 61 79 65 .#Eg‰«ÍïSri Jaye<br />
00000010 77 61 72 64 65 6E 65 70 75 72 61 20 4B 6F 74 74 wardenepura Kott<br />
00000020 65 e e<br />
</source><br />
SHA-256 hash of this 32 byte buffer:<br />
<source><br />
02EAAB5A00EC9D4207E8B1F53F8A2F3F91F1A73AAFDD2A81CCFEE3E83E5B101A<br />
</source><br />
<br />
The decrypted hash produces the following result after decrypting with AES128-ECB:<br />
<source><br />
Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F<br />
<br />
00000000 AC A8 2B 25 34 69 8F 3B 3B EB 21 20 69 E8 37 D3 ¬¨+%4i.;;ë! iè7Ó<br />
00000010 9E 85 34 69 73 78 89 8D 0E D7 30 7A D1 30 31 D4 ž…4isx‰..×0zÑ01Ô<br />
</source><br />
<br />
This 32 byte (256 bits) sized buffer is the PSVIMG AES256-CBC key.<br />
<br />
[[Category:Formats]]</div>Red-EyeX32