Merge pull request #300 from infinicore/master

Add support for ps:ps#GenerateRandomBytes.
This commit is contained in:
fincs 2016-07-22 11:12:56 +02:00 committed by GitHub
commit d149355fb7
2 changed files with 22 additions and 0 deletions

View File

@ -74,3 +74,10 @@ Result PS_GetLocalFriendCodeSeed(u64* seed);
* @param device_id Pointer to write the device ID to. * @param device_id Pointer to write the device ID to.
*/ */
Result PS_GetDeviceId(u32* device_id); Result PS_GetDeviceId(u32* device_id);
/**
* @brief Generates cryptographically secure random bytes.
* @param out Pointer to the buffer to write the bytes to.
* @param len Number of bytes to write.
*/
Result PS_GenerateRandomBytes(void* out, size_t len);

View File

@ -103,3 +103,18 @@ Result PS_GetDeviceId(u32* device_id)
return (Result)cmdbuf[1]; return (Result)cmdbuf[1];
} }
Result PS_GenerateRandomBytes(void* out, size_t len)
{
Result ret = 0;
u32 *cmdbuf = getThreadCommandBuffer();
cmdbuf[0] = IPC_MakeHeader(0xD,1,2); // 0xD0042
cmdbuf[1] = len;
cmdbuf[2] = IPC_Desc_Buffer(len, IPC_BUFFER_W);
cmdbuf[3] = (u32)out;
if(R_FAILED(ret = svcSendSyncRequest(psHandle)))return ret;
return (Result)cmdbuf[1];
}