libctru  v1.6.0
Data Structures | Enumerations | Functions
ps.h File Reference

PS service. More...

Go to the source code of this file.

Data Structures

struct  psRSAContext
 RSA context. More...
 

Enumerations

enum  PS_AESAlgorithm {
  PS_ALGORITHM_CBC_ENC,
  PS_ALGORITHM_CBC_DEC,
  PS_ALGORITHM_CTR_ENC,
  PS_ALGORITHM_CTR_DEC,
  PS_ALGORITHM_CCM_ENC,
  PS_ALGORITHM_CCM_DEC
}
 PS AES algorithms. More...
 
enum  PS_AESKeyType {
  PS_KEYSLOT_0D,
  PS_KEYSLOT_2D,
  PS_KEYSLOT_31,
  PS_KEYSLOT_38,
  PS_KEYSLOT_32,
  PS_KEYSLOT_39_DLP,
  PS_KEYSLOT_2E,
  PS_KEYSLOT_INVALID,
  PS_KEYSLOT_36,
  PS_KEYSLOT_39_NFC
}
 PS key slots. More...
 

Functions

Result psInit (void)
 Initializes PS.
 
Result psInitHandle (Handle handle)
 Initializes PS with the specified session handle. More...
 
void psExit (void)
 Exits PS.
 
Handle psGetSessionHandle (void)
 Returns the PS session handle.
 
Result PS_SignRsaSha256 (u8 *hash, psRSAContext *ctx, u8 *signature)
 Signs a RSA signature. More...
 
Result PS_VerifyRsaSha256 (u8 *hash, psRSAContext *ctx, u8 *signature)
 Verifies a RSA signature. More...
 
Result PS_EncryptDecryptAes (u32 size, u8 *in, u8 *out, PS_AESAlgorithm aes_algo, PS_AESKeyType key_type, u8 *iv)
 Encrypts/Decrypts AES data. More...
 
Result PS_EncryptSignDecryptVerifyAesCcm (u8 *in, u32 in_size, u8 *out, u32 out_size, u32 data_len, u32 mac_data_len, u32 mac_len, PS_AESAlgorithm aes_algo, PS_AESKeyType key_type, u8 *nonce)
 Encrypts/Decrypts signed AES CCM data. More...
 
Result PS_GetLocalFriendCodeSeed (u64 *seed)
 Gets the 64-bit console friend code seed. More...
 
Result PS_GetDeviceId (u32 *device_id)
 Gets the 32-bit device ID. More...
 
Result PS_GenerateRandomBytes (void *out, size_t len)
 Generates cryptographically secure random bytes. More...
 

Detailed Description

PS service.

Enumeration Type Documentation

◆ PS_AESAlgorithm

PS AES algorithms.

Enumerator
PS_ALGORITHM_CBC_ENC 

CBC encryption.

PS_ALGORITHM_CBC_DEC 

CBC decryption.

PS_ALGORITHM_CTR_ENC 

CTR encryption.

PS_ALGORITHM_CTR_DEC 

CTR decryption(same as PS_ALGORITHM_CTR_ENC).

PS_ALGORITHM_CCM_ENC 

CCM encryption.

PS_ALGORITHM_CCM_DEC 

CCM decryption.

◆ PS_AESKeyType

PS key slots.

Enumerator
PS_KEYSLOT_0D 

Key slot 0x0D.

PS_KEYSLOT_2D 

Key slot 0x2D.

PS_KEYSLOT_31 

Key slot 0x31.

PS_KEYSLOT_38 

Key slot 0x38.

PS_KEYSLOT_32 

Key slot 0x32.

PS_KEYSLOT_39_DLP 

Key slot 0x39. (DLP)

PS_KEYSLOT_2E 

Key slot 0x2E.

PS_KEYSLOT_INVALID 

Invalid key slot.

PS_KEYSLOT_36 

Key slot 0x36.

PS_KEYSLOT_39_NFC 

Key slot 0x39. (NFC)

Function Documentation

◆ PS_EncryptDecryptAes()

Result PS_EncryptDecryptAes ( u32  size,
u8 in,
u8 out,
PS_AESAlgorithm  aes_algo,
PS_AESKeyType  key_type,
u8 iv 
)

Encrypts/Decrypts AES data.

Does not support AES CCM.

Parameters
sizeSize of the data.
inInput buffer.
outOutput buffer.
aes_algoAES algorithm to use.
key_typeKey type to use.
ivPointer to the CTR/IV. The output CTR/IV is also written here.

◆ PS_EncryptSignDecryptVerifyAesCcm()

Result PS_EncryptSignDecryptVerifyAesCcm ( u8 in,
u32  in_size,
u8 out,
u32  out_size,
u32  data_len,
u32  mac_data_len,
u32  mac_len,
PS_AESAlgorithm  aes_algo,
PS_AESKeyType  key_type,
u8 nonce 
)

Encrypts/Decrypts signed AES CCM data.

When decrypting, if the MAC is invalid, 0xC9010401 is returned. After encrypting the MAC is located at inputbufptr.

Parameters
inInput buffer.
in_sizeSize of the input buffer. Must include MAC size when decrypting.
outOutput buffer.
out_sizeSize of the output buffer. Must include MAC size when encrypting.
data_lenLength of the data to be encrypted/decrypted.
mac_data_lenLength of the MAC data.
mac_lenLength of the MAC.
aes_algoAES algorithm to use.
key_typeKey type to use.
noncePointer to the nonce.

◆ PS_GenerateRandomBytes()

Result PS_GenerateRandomBytes ( void *  out,
size_t  len 
)

Generates cryptographically secure random bytes.

Parameters
outPointer to the buffer to write the bytes to.
lenNumber of bytes to write.

◆ PS_GetDeviceId()

Result PS_GetDeviceId ( u32 device_id)

Gets the 32-bit device ID.

Parameters
device_idPointer to write the device ID to.

◆ PS_GetLocalFriendCodeSeed()

Result PS_GetLocalFriendCodeSeed ( u64 seed)

Gets the 64-bit console friend code seed.

Parameters
seedPointer to write the friend code seed to.

◆ PS_SignRsaSha256()

Result PS_SignRsaSha256 ( u8 hash,
psRSAContext ctx,
u8 signature 
)

Signs a RSA signature.

Parameters
hashSHA256 hash to sign.
ctxRSA context.
signatureRSA signature.

◆ PS_VerifyRsaSha256()

Result PS_VerifyRsaSha256 ( u8 hash,
psRSAContext ctx,
u8 signature 
)

Verifies a RSA signature.

Parameters
hashSHA256 hash to compare with.
ctxRSA context.
signatureRSA signature.

◆ psInitHandle()

Result psInitHandle ( Handle  handle)

Initializes PS with the specified session handle.

Parameters
handleSession handle.