2018-08-16 19:47:36 -04:00
|
|
|
|
using Ryujinx.HLE.HOS.Ipc;
|
2018-07-13 17:36:57 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Security.Cryptography;
|
|
|
|
|
|
2018-08-16 19:47:36 -04:00
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Spl
|
2018-07-13 17:36:57 -04:00
|
|
|
|
{
|
|
|
|
|
class IRandomInterface : IpcService, IDisposable
|
|
|
|
|
{
|
2018-12-04 15:23:37 -05:00
|
|
|
|
private Dictionary<int, ServiceProcessRequest> _commands;
|
2018-07-13 17:36:57 -04:00
|
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
|
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => _commands;
|
2018-07-13 17:36:57 -04:00
|
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
|
private RNGCryptoServiceProvider _rng;
|
2018-07-13 17:36:57 -04:00
|
|
|
|
|
|
|
|
|
public IRandomInterface()
|
|
|
|
|
{
|
2018-12-04 15:23:37 -05:00
|
|
|
|
_commands = new Dictionary<int, ServiceProcessRequest>
|
2018-07-13 17:36:57 -04:00
|
|
|
|
{
|
|
|
|
|
{ 0, GetRandomBytes }
|
|
|
|
|
};
|
|
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
|
_rng = new RNGCryptoServiceProvider();
|
2018-07-13 17:36:57 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
|
public long GetRandomBytes(ServiceCtx context)
|
2018-07-13 17:36:57 -04:00
|
|
|
|
{
|
2018-12-04 15:23:37 -05:00
|
|
|
|
byte[] randomBytes = new byte[context.Request.ReceiveBuff[0].Size];
|
2018-07-13 17:36:57 -04:00
|
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
|
_rng.GetBytes(randomBytes);
|
2018-07-13 17:36:57 -04:00
|
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
|
context.Memory.WriteBytes(context.Request.ReceiveBuff[0].Position, randomBytes);
|
2018-07-13 17:36:57 -04:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
Dispose(true);
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 15:23:37 -05:00
|
|
|
|
protected virtual void Dispose(bool disposing)
|
2018-07-13 17:36:57 -04:00
|
|
|
|
{
|
2018-12-04 15:23:37 -05:00
|
|
|
|
if (disposing)
|
2018-07-13 17:36:57 -04:00
|
|
|
|
{
|
2018-12-04 15:23:37 -05:00
|
|
|
|
_rng.Dispose();
|
2018-07-13 17:36:57 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|