Secure Modules Functions

Depending on the Secure Modules that is currently loaded, different commands are handled.

Request Buffer
Each request that is made sends a page aligned buffer that has a max size of a page. After as 64 byte header common to all commands, the data afterwards is specific to each command. The documentation for each command below specifies the data that goes after the header. The special command id of -1 is used to stop the current loaded Secure Module.

Command buffer structure (as seen on FWs 3.60-3.73):

On FW 0.931, and maybe in later prototype FWs, the data buffer is located at offset 0x10 instead of 0x40. Thus we can wonder why has been added the 0x30 bytes padding.

Physical Address Vector
A common format used in these requests is the Physical Address Vector which is a list of Physical Address Ranges. The simple structure of Physical Address Range is defined below. See sceKernelVARangeToPARangeForDriver for information on creating this vector.

This data format is used when passing large buffers of data to CMeP. The reason is that the memory manager in kernel could allocate contiguous virtual addresses that corresponds to varying physical addresses.

kprx_auth_sm.self
This is a special SM stored in the SLB2 partition. The raw (encrypted) SELF is stored in ARM TrustZone memory. It is placed there by an early bootloader.

kprx_auth_sm is used to decrypt SELF and SPSFO files for ARM. The CF header is passed into a page aligned buffer and a PA vector is generated from it.

0x10001 - sceSblAuthMgrAuthHeader
Used by sceSblAuthMgrAuthHeaderForKernel.

Checks the SELF header for decryption. The header is copied to the cmep private memory region first (on FW 1.69 with 0x1000 sized header, it is at  in cmep memory space.

0x20001 - sceSblAuthMgrSetupAuthSegment
Used by sceSblAuthMgrSetupAuthSegmentForKernel.

Set the program segment to decrypt. This corresponds to the segment index in the ELF program headers in the SELF header passed in with the command above.

0x30001 - sceSblAuthMgrLoadBlock
Used by sceSblAuthMgrAuthSegmentForKernel.

Decrypt a buffer from the SELF corresponding to the program segment number passed in above. The segment is read in  bytes chunks and is decrypted in place (the input buffer will contain the decrypted data). A PA vector is generated from the buffer. The input buffer and output buffer can be the same.

0x40001 - sceSblAuthMgrGetEKc
Decrypts provided buffer in AES ECB mode using one of three keys (NPDRM keys ?).

Used by sceSblAuthMgrGetEKcForDriver for getting klicensee.

0x50001 - sceSblAuthMgrSetDmac5Key
Used by sceSblAuthMgrSetDmac5KeyForKernel to set a key in DMAC5 keyring for decryption.

This SM function uses AES128ECB or AES128CBC and hardcoded AES keys and IVs to encrypt the provided key into the final DMAC5 key. Then it writes the final DMAC5 key into the chosen Dmac5 keyring.

Input/output size is 0x110 bytes. Buffer is untouched by the SM function as it makes an internal copy.

0x60001 - sceSblAuthMgrClearDmac5Key
Used by sceSblAuthMgrClearDmac5KeyForKernel to clear the Dmac5 Key.

This function writes zeroes into the chosen DMAC5 keyring.

Input/output size is 0x110 bytes. Buffer is untouched by the SM function as it makes an internal copy.

It has exactly same structure as kprx_auth_sm function 0x50001 and is parsed in the same kprx_auth_sm subroutine function.

0x70001 - sceSblAuthMgrDecBindData
Used by sceSblAuthMgrDecBindDataForDriver and SceNpDrm for gamecard binding data used in conjunction with the RIF license file on the gamecard for deriving the klicensee.

Input/output size is 0x18 bytes. Buffer is untouched by the SM function as it makes an internal copy, however encrypted bind data at specified physical address will be decrypted after SM function execution.

Algorithm:
 * Compute HMAC-SHA256 of seed. It gives a 0x20-byte digest.
 * First 0x10 bytes of the digest make the AES128CBC key and last 0x10 bytes make the AES128CBC IV.
 * AES128CBC decrypt bind data.

0x80001 - sceSblAuthMgrVerifySpsfo
Used by sceSblAuthMgrVerifySpsfoForDriver.

applier_sm.self
applier_sm is used to decrypt and even encrypt SELFs for ARM. It is only present in some old prototype System Software builds like 0.931.010.

0x1 - check_activation_code_1
Removed on FW 2.10.

Checks SceKitActivationData read from sd0:/act.dat.

Uses different keys (AES256CBC and AES256CMAC) than check_activation_code_2.

Used only on TOOL rev 3.

0x2 - check_activation_code_2
Removed on FW 2.10.

Checks SceKitActivationData read from sd0:VITA.ACT.

Uses different keys (AES256CBC and AES256CMAC) than check_activation_code_1.

Used on any Kit other than TOOL rev 3 (uses command 1), TEST, TOOL rev 4, Manufacturing Mode and QA flagged (bypasses activation).

0x4 - check_nvs_cmac
Not present on FW 0.931.

Checks NVS activation data authenticity using CMAC.

0x5 - gen_nvs_cmac
Removed on FW 2.10.

Generate CMAC of NVS activation data. The returned data is written to NVS at offset 0x520 or 0x530.

0x7
Removed on FW 2.10.

Check if activation is valid. The input activation data is read from NVS at offset 0x520.

0xA - gen_activation_with_sig
Introduced in FW 2.10.

Check if new activation is valid. Extended activation check with a signature. This is ran when installing a new afv.

0xB - check_activation_with_sig
Introduced in FW 2.10.

Check if Kit Activation Data is valid and not expired. Extended activation check with signature. This command is ran on boot.

0x1 - GetConsoleId
Returns the console's ConsoleId.

Used in sceSblAimgrGetConsoleIdForDriver.

0x2 - GetOpenPsId
Returns the console's OpenPsId.

Used in sceSblAimgrGetOpenPsIdForDriver.

0x3 - GetVisibleId
Returns the console's VisibleId.

Used in sceSblAimgrGetVisibleIdForDriver.

0x4 - GetPsCode
Returns the console's PsCode.

Used in sceSblAimgrGetPscode2ForDriver.

0x5 - CreatePassPhrase
Creates NP passphrase (per-console and per NP account).

Used in sceSblSsCreatePassPhraseForDriver.

Input size is 0x220 bytes.

Output size is 0x220 bytes.

compat_sm.self
Compat SM functions only works on DEX and CEX units, or on units in Manufacturing Mode or with a certain QA Flag. This is why most DevKit units don't have access to PSPEmu.

0x10006 - sceCompatSecLoadSCBootCode
Load Secure CPU Boot Code. PSP main CPU (Tachyon codename) is an Allegrex 32-bit little-endian RISC CPU with FPU and VFPU, 1 ~ 333MHz, MIPS III-based.

Called on init and before resume of PSP.

On FW 3.73 (simplified):

If an error occurs during SCBootCode loading:

The cookie, which represents the address where PRE-IPL will jump to when resuming, is passed by MIPS to ARM (written to ) just before suspending, and it is calculated the same way as on actual PSP, only that using   as input to the SHA1, instead of the MAC address.

0x20006 - sceCompatSecSetSSRAMAcl
Set Shared Static Random Access Memory Access-control list.

Removed since FW 3.50 and replaced by command 0x30006.

0x30006 - sceCompatSecSetSSRAMAcl2
Set Shared Static Random Access Memory Access-control list 2.

Appeared on FW 3.50 as replacement for command 0x20006. This change is related to the huge memory management improvement since FW 3.50. See PS Vita System software 3.50 adds 30% more memory for game use.

On 3.73-CEX (simplified):

encdec_w_portability_sm.self
This seems to be used to do some kind of key derivation. May also be used as a general purpose encryption engine.

0x1000A - EncryptWithPortability
Encrypt data. Actually it always returns, so it does nothing and is never used.

0x2000A - DecryptWithPortability
Used by sceSblSsDecryptWithPortabilityForDriver.

Decrypt data by using AES-256-CBC with an internal key selected by.

Return value of 0x800f0002 means invalid service ID. For encdec_w_portability_sm, only commmands 0x1000A and 0x2000A are supported.

Return value of 0x800f1716 means invalid argument such as invalid key ID. Valid key IDs are only 1-20.

0x1000B
Execute KIRK services.

This is one of the variable sized buffers that can be placed inside Request_Buffer.

Response value returned to Kernel comes from Request Buffer at offset 8.

Following are the supported Kirk services.

0x4 - encrypt_with_portability
Original PSP Kirk 4 service for encrypting data.

Does not use any specific data structure in.

Just encrypts data located in.

Uses one set of keys.

Available  values are (key is encrypted with key from keyring 0x345 and put into keyring 0x21): 0x02, 0x03, 0x04, 0x05, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x38, 0x39, 0x3A, 0x80, 0x81, 0x82, 0x83.

Special  0x100 is available. Uses keys from keyrings 0x601 and 0x602.

Key 0x601 is scrambled and used as seed.

Key 0x602 is scrambled and used as key.

Seed is aes cbc encrypted with key to produce resulting key.

0x7 - decrypt_with_portability
Original PSP Kirk 7 service for decrypting data.

Does not use any specific data structure in.

Just decrypts data located in.

Uses two sets of keys.

Available key ids are (key is encrypted with key from keyring 0x345 and put into keyring 0x21): 0x02, 0x03, 0x04, 0x05, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x38, 0x39, 0x3A, 0x80, 0x81, 0x82, 0x83.

Available  values are (key is encrypted with key from keyring 0x340 and put into keyring 0x10): 0x44, 0x53, 0x57, 0x63, 0x64, 0x68, 0xC0, 0xC1, 0xC2, 0xC3.

Special  0x100 is available. Uses keys from keyrings 0x601 and 0x602 (will be documented later).

Key 0x601 is scrambled and used as seed.

Key 0x602 is scrambled and used as key.

Seed is aes cbc encrypted with key to produce resulting key.

0xC - ecc160_generate_keys
Original PSP Kirk 0xC service for Generating a 160bit ECC private/public keypair. Call with an empty buffer of length 0x3C. The structure below is the return structure.

Private key  is obtained by:

1. Generating 0x40 sized random number rng.

2. dA = rng mod N

Public key  us obtained by:

Qa = dA * G

Output:

0xD - ecc160_multiply
Original PSP Kirk 0xD service for multiplying a 160bit ECC curve point with a value. Call with a multiplier, x and y point value.

Input:

Output:

0xE - ecc160_prngen
Original PSP Kirk 0xE service for 160bit Random number generation. Call with an empty buffer.

0x10 - ecc160_sig_gen
Original PSP Kirk 0x10 service for 160bit ECC signing.

Specific  is used for signing.

For example if you will implement it with openssl it will be used to calculate precomputed parts of signing operation (kinv and rp).

is obtained by:

1. Generating 0x40 sized random number rng.

2. nonce = rng mod N

Input:

Output:

0x11 - ecc160_sig_verify
Original PSP Kirk 0x11 service for 160bit ECC signature verification. Call with the below structure, then function will return pass or fail.

Input size is 0x64 bytes.

Input:

No output.

0x12 - cert_verify
This function checks that CMAC of  equals.

CMAC value of  is calculated using key from keyring 0x212.

is decrypted using a key from keyring 0x0.

Key in keyring 0x0 is derived using key from keyring 0x204 with static seed value.

Input:

0x14 - ecc224_generate_keys
New Vita Kirk 0x14 service for generating a 224bit ECC private/public keypair. Call with an empty buffer of length 0x54. The structure below is the return structure.

Private key  is obtained by:

1. Generating 0x40 sized random number rng.

2. dA = rng mod N

Public key  us obtained by:

Qa = dA * G

Output:

0x15 - ecc224_multiply
New Vita Kirk 0x15 service for multiplying a 224bit ECC curve point with a value. Call with a multiplier, x and y point value.

Input:

Output:

0x16 - ecc224_prngen
New Vita Kirk 0x16 service for 224bit Random number generation. Call with an empty buffer.

0x17 - ecc224_sig_gen
New Vita Kirk 0x17 service for 224bit ECC signing.

Specific  is used for signing.

For example if you will implement it with openssl it will be used to calculate precomputed parts of signing operation (kinv and rp).

is obtained by:

1. Generating 0x40 sized random number rng.

2. nonce = rng mod N

Input:

Output:

0x18 - ecc224_sig_verify
New Vita Kirk 0x18 service for 224bit ECDSA signature verification. Call with the below structure, then function will return pass or fail.

Input:

0x19 - cert_verify_new
This function checks that CMAC of  equals.

CMAC value of  is calculated using key from keyring 0x212.

is decrypted using a key from keyring 0x0.

Key in keyring 0x0 is derived using key from keyring 0x204 with static seed value.

This function is used to verify PS Vita new IdStorage Certificates.

Input:

0x1B - check_gc_authenticity
New Vita Kirk 0x1B service. This service is related to SceSdif and is used by SceSblGcAuthMgr. This service is part of SD MMC CMD56 custom initialization protocol. This is a data validation service with no response. Size of request is 0x53.

- packet 7 should contain challenge0 for the card that can be encrypted (by card) with key_id and master_key.

- packet 8 should contain encrypted message which can be decrypted (by vita) with key_id and master_key.

- part of message should be card_challenge0.

- another part of the message should be equal to challenge0.

- this way we know that card knows how to properly encrypt.

- Kirk service 1B will decrypt packet 8 with key_id and master_key

- then it will verify challenge0

0x1C - generate_vita_authenticity_proof
New Vita Kirk 0x1C service. This service is related to SceSdif and is used by SceSblGcAuthMgr. This service is part of SD MMC CMD56 custom initialization protocol. This is a data generation service. Size of request is 0x40. Size of response is 0x33.

- Kirk service 1C will generate packet 9

- it will decrypt packet 8 to retrieve challenge0 and card_challenge0

- then challenge0 and card_challenge0 will be tweaked

- then it will generate secondary_key0

- then packet 9 will be encrypted with key_id and master_key

- packet 9 should contain encrypted message which can be decrypted (by card) with key_id and master_key.

- message should have secondary_key0, tweaked challenge0 and tweaked card_challenge0.

- this way card will know that we know how to properly encrypt the data and we know the layout of the data because we tweak and reorder certain fields.

Request:

Response:

0x1D - challenge_handshake
New Vita Kirk 0x1D service. This service is related to SceSdif and is used by SceSblGcAuthMgr. This service is part of SD MMC CMD56 custom initialization protocol. This is a data validation service with no response. Size of request is 0xA3.

- packet 13 should contain challenge1 for the card that can be encrypted (by card) with key_id and master_key.

- packet 14 should contain challenge1 and master_key that are encrypted (by card) with key_id and master_key.

- Kirk service 0x1D will decrypt secondary_key0 from packet 9 with key_id and master_key

- then it will decrypt packet 14

- then it will verify challenge1 in packet 13 against decrypted packet 14

- then it will verify master_key in packet 6 against decrypted packet 14

0x1E - generate_packets_15_17_with_cmac_signature
New Vita Kirk 0x1E service. This service is related to SceSdif and is used by SceSblGcAuthMgr. This service is part of SD MMC CMD56 custom initialization protocol. This is a data generation service. Size of request is 0x51. Size of response is 0x33.

- Kirk service 0x1E will generate packet 15

- it will decrypt secondary_key0 from packet 9 with key_id and master_key

- then it will generate secondary_key1

- then it will create a buffer with tweaked secondary_key1 and tweak_padding

- then it will encrypt the buffer using secondary_key0

- then it will create cmd56 input like buffer with encrypted buffer

- then it will calculate cmac of cmd56 like buffer using secondary_key0

- encrypted buffer and cmac will be the resulting data of packet 15

Request:

Response:

0x1F - decrypt_packet_16
New Vita Kirk 0x1F service. This service is related to SceSdif and is used by SceSblGcAuthMgr. This service is part of SD MMC CMD56 custom initialization protocol. This is a data validation service. Size of request is 0xB3. Size of response is 0x20.

- Kirk service 0x1E will decrypt secondary_key0 from packet 9 with key_id and master_key

- then it will combine data from packet 16 into a cmd56 like buffer

- then it will calculate cmac of that cmd56 like buffer using secondary_key0

- then it will verify calculated cmac against cmac from packet 16

- then it will decrypt secondary_key1 and tweak_padding from packet 15

- then it will decrypt secondary_key1 and unknown data from packet 16

- then it will verify decrypted secondary_key1 from packet 15 against decrypted secondary_key1 from packet 16

- then it will verify that decrypted tweak_padding from packet 15 is properly tweaked

- then it will return unknown decrypted data from packet 16

Request:

Response:

0x20 - get_hash_from_gamecard_packets
New PS Vita Kirk 0x20 service. This service is related to SceSdif and is used by SceSblGcAuthMgr. This service is part of SD MMC CMD56 custom initialization protocol. This is a data generation service. Size of request is 0x116 bytes. Size of response is 0x34 bytes.

Generated data is used to obtain klicensee using sceSblAuthMgrDecBindDataForDriver.

Request:

Response:

0x21 - ecc160_hmac_sha256_sig_gen
New Vita Kirk 0x21 service for 160bit ECC signing.

Specific  is used for signing.

For example if you will implement it with openssl it will be used to calculate precomputed parts of signing operation (kinv and rp).

is obtained by:

1. Generating 0x40 sized seed which is derived from message hash and static private key using hmac256 and sha256.

2. nonce = seed mod N

Input:

Output:

0x22 - ecc224_sceebootpbp_sig_gen
New Vita Kirk 0x22 service for 224bit ECC signing.

Specific  is used for signing.

For example if you will implement it with openssl it will be used to calculate precomputed parts of signing operation (kinv and rp).

is obtained by:

1. Generating 0x40 sized seed which is derived from message hash and one of two static private keys using hmac256 and sha256. Key can be selected with key id 0 or 1.

Private key 0 is only used for signing __sceebootpbp files for firmware versions before 1.8X, otherwise private key 1 is used for signing __sceebootpbp.

2. nonce = seed mod N

Input:

Output:

0x23 - generate_cmac_signature
New Vita Kirk 0x23 service.

It encrypts the plain message with AES128CBC, static key and null IV, then calculates the AES128CMAC of the encrypted message with another static key.

Input:

Output:

pm_sm.self
sceSblPmMgrAuthEtoIForDriver uses "sd0:sm/pm_sm_sd.self" whilst other PmSm functions use "os0:sm/pm_sm.self".

Services 8, 9 and 0xA appeared on FW 1.03 (maybe 1.00). They are not present on FW 0.990 and earlier.

Keyset must be between 0-0xC on FW 0.931.

0x1 - get_product_mode
Used by sceSblPmMgrGetProductModeFromNVS.

Data size is 0x28 bytes.

Input: 0x20 buffer read from NVS at offset 0.

0x2 - set_product_mode
Used by sceSblPmMgrSetProductMode.

Data size is 0x28 bytes.

Input: 0x20 bytes buffer read from NVS at offset 0, to which is written the new product mode to set.

Output data: 0x20 buffer to write to NVS at offset 0.

0x3 - gen_req_hello
This command gets the Ernie secure packet for the first JIG auth command.

Data size is 0x30 bytes.

0x4 - gen_challenge
Data size is 0x30 bytes.

0x5 - check_response
Returns 0 on success.

Data size is 0x30 bytes.

0x6 - gen_req_result
Encrypts Ernie secure packet for step 4 with the chosen keyset.

Data size is 0x30 bytes.

0x7 - check_result
Returns 0 on success.

Data size is 0x30 bytes.

0x8 - run_pm_command
Not present in old FWs.

Used on FW 1.03+ by sceSblPmMgrGetProductModeFromNVS.

Data size is 0x70 bytes.

0x9 - gen_jig_message
Only on FW 1.03+.

Data size is 0x10C bytes.

0xA - check_jig_response
Only on FW 1.03+.

Returns 0 on success.

Data size is 0x10C bytes.

0x0
Decrypt or check QAF Token. Used on 1.03 PDEL.

0x4 - decrypt_qafv
Input: 0x20 buffer read from NVS offset 0x2A0.

Output: QAF version in this buffer of size 0x20:

0x5 - encrypt_qafv
Input QAF version in this buffer of size 0x20:

Output of size 0x20 is then written to NVS offset 0x2A0.

0x6 - check_flag (decrypt)
Input: 0x20 buffer read from NVS at offset 0.

Returns error if flag is bad, 0 on success.

Output

0x7 - set_flag (encrypt)
Input: 0x20 buffer.

Output: 0x20 encrypted buffer that can be written to NVS at offset 0.

rmauth_sm.self
Removable Media (Memory Card) authentication. Used by SceMsif.

0x1 - get_key_master_gen_no
Response (size 0x20 bytes):

0x2 - set_index_key
Scrambles and sets the DMAC5 keyring 0x1C key. The scrambling process consists of encrypting the first and second halves of the key seed with a private internal (could be considered as a couple of 0x10 keys)  key using AES128-CBC.

Request (size 0x20 bytes):

0x3
?clear_index_key?

Clears the DMAC5 keyring 0x1C key (to 0).

spkg_verifier_sm_w_key_2.self
This is an extension of update_service_sm.self. It was added to support command 0xE0002.

0xE0002 - sceSblUsSmAuthSpkgWithKey2
Used to decrypt downloaded lists (SPKGs). Same format as 0x40002.

Lists URLS:

update_service_sm.self
This is used by SceSblUpdateMgr to decrypt update packages extracted from PUP files.

Both 0x40002 and 0x50002 reference buffers in the following way: an inner PA vector is generated for the buffer containing the data to encrypt/decrypt, then an outer PA vector is generated for the inner list. That means that there are two levels of indirection in the PA vector.

Services with PA vectors to pass data to cmep decide whether to use normal vectors or deep vectors depending on the flag of the argument.

0x10002 - sceSblUsSmAuthPupHeader
SCE_SBL_SM_COMM_FID_SM_AUTH_PUP_HEADER.

Checks PUP header (with hash check).

Input data size: 0xFC0.

Input: PA vector of the PUP header including the PUP Hash (size: 0x80 + segment_num * 0x20 + segment_num * 0x40 + 0x20)

0x20002 - sceSblUsSmAuthPupSegment
SCE_SBL_SM_COMM_FID_SM_AUTH_PUP_SEGMENT.

Checks PUP segment HMAC-SHA256 hash.

Input data size: 0xFC0.

0x30002 - sceSblUsSmAuthPupWatermark
SCE_SBL_SM_COMM_FID_SM_AUTH_PUP_WM.

Checks PUP watermark.

Input data size: 0xFC0.

Input data: a packet embedding at least two physical addresses (?in a PA vector?): PUP Watermark (0x1000 bytes) and PUP Hash (0x20 bytes).

0x40002 - sceSblUsSmAuthSpkg
SCE_SBL_SM_COMM_FID_SM_AUTH_SPKG.

Decrypt a SPKG. Allocate a page aligned buffer and read the complete SPKG file into the buffer. The buffer is decrypted in place.

0x50002 - sceSblUsSmEncryptIndividualSLSK
SCE_SBL_SM_COMM_FID_SM_ENCIND_SLSK.

Re-encrypt individual SLSK files (.enp files).

Each inner PA vector is first copied to temporary cmep memory, then they all are checked for validity at once. Maximum size of inner PA vector is 0xFF7 (so probably 0xFF7 / 8 * 8 = 0xFF0). Any higher length results in  error.

How it works:
 * first, all inner entries are checked for validity, if something is invalid, bail out
 * start at last outer entry and move towards the first
 * if current entry looks valid (length >= 8), proceed to inner physical address encryption
 * if no valid entries found, error=
 * if multiple valid entries found, error= (???) (but the first one found is always encrypted)
 * if only one valid entry is found, return success

Bugs(?): 00:00:26	0 // this is physical address 0x1F000000 00:00:26	0 00:00:26	0 00:00:26	2000 00:00:26	8 00:00:26	812d40 00:00:26	0 00:00:26	1f000020 // this is physical address 0x1F00001C 00:00:26	0 00:00:26	0 00:00:26	0 00:00:26	2000 00:00:26	8 00:00:26	812d40 00:00:26	0 00:00:26	1f000040 00:00:26	0 00:00:26	0 00:00:26	0 00:00:26	2000 00:00:26	8 00:00:26	812d40 00:00:26	0 00:00:26	1f000060 00:00:26	0 00:00:26	0 00:00:26	0 00:00:26	2000 00:00:26	8 00:00:26	812d40 00:00:26	0 00:00:26	1f000080
 * encrypting same physical address twice or more times within a single inner PA vector always results in same output, no matter what input was, reproducible with length=0x10 or less
 * sum(inner list sizes) must be <= 0xFF0, but there is no overflow check, a large inner list causes cmep to overwrite memory with data like:

0x60002 - sceSblUsSmSnvsEncryptSectors
SCE_SBL_SM_COMM_FID_SM_SNVS_ENC_SECTORS.

The input is plain SNVS sectors read from NVS.

Calculates a XTS encrypt using the per console keys in keyring 0x502, and 0x503 for the tweak and decryption keys. Appears to be intended for up to 0x3E0 bytes in size, but the (size in cmep packet + 4) derives the XTS size and memcpy.

The result is XTS encrypted SNVS sectors.

Data size is (8 bytes + sectors size).

0x70002 - sceSblUsSmSnvsDecryptSectors
SCE_SBL_SM_COMM_FID_SM_SNVS_DEC_SECTORS.

The input is XTS encrypted sectors.

Calculates a XTS decrypt using the per console keys in keyring 0x502, and 0x503 for the tweak and decryption keys. Appears to be intended for up to 0x3E0 in size, but the (size in cmep packet + 4) derives the XTS size and memcpy.

The result is plain sectors.

Data size is (8 bytes + sectors size).

0x80002 - sceSblUsSmSnvsEncryptMgmtData
SCE_SBL_SM_COMM_FID_SM_SNVS_ENC_MGMT.

The input are the new status and flags, and the current Mgmt Data sector read from NVS at offset 0.

Calculates a XTS decrypt using the per console keys in keyring 0x502, and 0x503 for the tweak and decryption keys. It then calculates an HMAC using the keyring 0x504 to check the block passed in. If ok, then it uses the seed 0xACA9B1AC to recalculate the block, generate a new hmac, and xts encrypt the block.

The result is a new Mgmt Data sector, which is to be written to NVS at offset 0.

Data size is 0x28 bytes.

0x90002 - sceSblUsSmSnvsDecryptMgmtData
SCE_SBL_SM_COMM_FID_SM_SNVS_DEC_MGMT.

The input is the current Mgmt Data sector read from NVS at offset 0.

Calculates a XTS decrypt using the per console keys in keyring 0x502, and 0x503 for the tweak and decryption keys. It then calculates an HMAC using the keyring 0x504 to check the block passed in.

The result is the current status and flags.

Data size is 0x28 bytes.

If flags[SCE_SBL_SS_SNVS_UPDATER_FLAG_INDEX] is not set, updater init is skipped:

0xA0002 - sceSblUsSmAuthAdditionalSign
SCE_SBL_SM_COMM_FID_SM_AUTH_PUP_AS.

Checks PUP Additional Signatures.

0xB0002 - sceSblUsSmSnvsEncryptDecryptSector
Added on FW 1.03. Usage similar to pm_sm command 8.

Data size is 0x88 bytes.

Usage: For read: For write:
 * 1) sceSblSmCommCallFunc(id, 0xB0002, &response, data, 0x88);
 * 2) nvs_read_special(data + 0x28, 0x10, data + 0x58, 0x30)
 * 2) nvs_write_special(data + 0x28, 0x30, data + 0x58, 0x10);
 * 3) sceSblSmCommCallFunc(id, 0xB0002, &response, data, 0x88);

0xC0002 - sceSblUsSmSnvsEncryptDecryptMgmtData
Added on FW 1.03. Usage similar to pm_sm command 8.

Data size is 0x70 bytes.

Usage: For write: For read:
 * 1) sceSblSmCommCallFunc(id, 0xC0002, &response, data, 0x70);
 * 2) nvs_write_special(data + 0x10, 0x30, data + 0x40, 0x10);
 * 2) nvs_read_special(data + 0x10, 0x10, data + 0x40, 0x30);
 * 3) sceSblSmCommCallFunc(id, 0xC0002, &response, data, 0x70);

0xD0002
Syscon update related. Usage is to proxy encrypted data cmep <=> Syscon.

Data size is 0x58 bytes.

Usage: For modes 0, 1 and 3:
 * 1) sceSblSmCommCallFunc(id, 0xD0002, &response, data, 0x58);
 * 2) memcpy(data + 8, data + 0x30, 0x28); SceSysconForDriver_4D03754A(data + 8, 0x28, data + 0x30, 0x28); // Calls Syscon command 0xD0.
 * 3) sceSblSmCommCallFunc(id, 0xD0002, &response, data, 0x58);

Mode:
 * 0 - Do init 0x28 buffer.
 * 1 - Do Bigmac unknown crypto with some blob.
 * 2 - Do Bigmac unknown crypto with some blob.
 * 3 - Do Bigmac unknown crypto with some blob.
 * 4 - Do some working. And reset Syscon ticket count with Bigmac PRNG (keyring 0x512).

0x1 - check_utoken
Checks SceUtoken buffer.

0x2 - decrypt_utoken
Decrypt SceUtoken buffer, in order to get UT Flags.

mgkm_sm.self
Magic Gate Key Manager secure module.

Present on 0.931-3.73. Commands are almost the same on any FW, only KEY_31 varies. 0 These commands are used to set keys (as seen on FWs from 0.940 to 3.60) to DMAC5 registers in NS memory. These keys are used in to do encryption stuff with AES-ECB and TripleDES-ECB algorithms through DMAC5.

On FW 0.940, commands 1 and 2 are only called by SceSblMgKeyMgrForDriver_1C5388D0 which consists of: