Implement CSRNG (Cryptographically Secure Random Bytes)

This commit is contained in:
Starlet 2018-07-03 12:10:35 -04:00
parent d24ea0d51b
commit b30640d749
2 changed files with 42 additions and 0 deletions

View file

@ -18,6 +18,7 @@ using Ryujinx.HLE.OsHle.Services.Prepo;
using Ryujinx.HLE.OsHle.Services.Set;
using Ryujinx.HLE.OsHle.Services.Sfdnsres;
using Ryujinx.HLE.OsHle.Services.Sm;
using Ryujinx.HLE.OsHle.Services.Spl;
using Ryujinx.HLE.OsHle.Services.Ssl;
using Ryujinx.HLE.OsHle.Services.Vi;
using System;
@ -66,6 +67,9 @@ namespace Ryujinx.HLE.OsHle.Services
case "caps:ss":
return new IScreenshotService();
case "csrng":
return new IRandomInterface();
case "friend:a":
return new IServiceCreator();

View file

@ -0,0 +1,38 @@
using Ryujinx.HLE.OsHle.Ipc;
using System.Collections.Generic;
using System.Security.Cryptography;
namespace Ryujinx.HLE.OsHle.Services.Spl
{
class IRandomInterface : IpcService
{
private Dictionary<int, ServiceProcessRequest> m_Commands;
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
private RNGCryptoServiceProvider CspRnd;
public IRandomInterface()
{
m_Commands = new Dictionary<int, ServiceProcessRequest>()
{
{ 0, GetRandomBytes }
};
CspRnd = new RNGCryptoServiceProvider();
}
public long GetRandomBytes(ServiceCtx Context)
{
(long Position, long Size) = Context.Request.GetBufferType0x21();
byte[] BytesBuffer = new byte[Size];
CspRnd.GetBytes(BytesBuffer);
Context.Memory.WriteBytes(Position, BytesBuffer);
return 0;
}
}
}