2019-07-11 18:13:43 -07:00
|
|
|
|
using System;
|
2018-07-13 14:36:57 -07:00
|
|
|
|
using System.Security.Cryptography;
|
|
|
|
|
|
2018-08-16 16:47:36 -07:00
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Spl
|
2018-07-13 14:36:57 -07:00
|
|
|
|
{
|
2019-07-10 08:59:54 -07:00
|
|
|
|
[Service("csrng")]
|
2018-07-13 14:36:57 -07:00
|
|
|
|
class IRandomInterface : IpcService, IDisposable
|
|
|
|
|
{
|
2018-12-06 03:16:24 -08:00
|
|
|
|
private RNGCryptoServiceProvider _rng;
|
2018-07-13 14:36:57 -07:00
|
|
|
|
|
2019-07-10 08:59:54 -07:00
|
|
|
|
public IRandomInterface(ServiceCtx context)
|
2018-07-13 14:36:57 -07:00
|
|
|
|
{
|
2018-12-06 03:16:24 -08:00
|
|
|
|
_rng = new RNGCryptoServiceProvider();
|
2018-07-13 14:36:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-13 15:01:24 -07:00
|
|
|
|
[CommandHipc(0)]
|
2019-07-11 18:13:43 -07:00
|
|
|
|
// GetRandomBytes() -> buffer<unknown, 6>
|
2019-07-14 12:04:38 -07:00
|
|
|
|
public ResultCode GetRandomBytes(ServiceCtx context)
|
2018-07-13 14:36:57 -07:00
|
|
|
|
{
|
2018-12-06 03:16:24 -08:00
|
|
|
|
byte[] randomBytes = new byte[context.Request.ReceiveBuff[0].Size];
|
2018-07-13 14:36:57 -07:00
|
|
|
|
|
2018-12-06 03:16:24 -08:00
|
|
|
|
_rng.GetBytes(randomBytes);
|
2018-07-13 14:36:57 -07:00
|
|
|
|
|
2021-04-24 03:16:01 -07:00
|
|
|
|
context.Memory.Write(context.Request.ReceiveBuff[0].Position, randomBytes);
|
2018-07-13 14:36:57 -07:00
|
|
|
|
|
2019-07-14 12:04:38 -07:00
|
|
|
|
return ResultCode.Success;
|
2018-07-13 14:36:57 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
|
{
|
|
|
|
|
Dispose(true);
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 03:16:24 -08:00
|
|
|
|
protected virtual void Dispose(bool disposing)
|
2018-07-13 14:36:57 -07:00
|
|
|
|
{
|
2018-12-06 03:16:24 -08:00
|
|
|
|
if (disposing)
|
2018-07-13 14:36:57 -07:00
|
|
|
|
{
|
2018-12-06 03:16:24 -08:00
|
|
|
|
_rng.Dispose();
|
2018-07-13 14:36:57 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|