2019-07-11 21:13:43 -04:00
|
|
|
|
using System;
|
2018-07-13 17:36:57 -04:00
|
|
|
|
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
|
|
|
|
{
|
2019-07-10 11:59:54 -04:00
|
|
|
|
[Service("csrng")]
|
2021-06-29 13:37:13 -04:00
|
|
|
|
class IRandomInterface : DisposableIpcService
|
2018-07-13 17:36:57 -04:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
private RNGCryptoServiceProvider _rng;
|
2018-07-13 17:36:57 -04:00
|
|
|
|
|
2021-06-29 13:37:13 -04:00
|
|
|
|
private object _lock = new object();
|
|
|
|
|
|
2019-07-10 11:59:54 -04:00
|
|
|
|
public IRandomInterface(ServiceCtx context)
|
2018-07-13 17:36:57 -04:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
_rng = new RNGCryptoServiceProvider();
|
2018-07-13 17:36:57 -04:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-13 18:01:24 -04:00
|
|
|
|
[CommandHipc(0)]
|
2019-07-11 21:13:43 -04:00
|
|
|
|
// GetRandomBytes() -> buffer<unknown, 6>
|
2019-07-14 15:04:38 -04:00
|
|
|
|
public ResultCode GetRandomBytes(ServiceCtx context)
|
2018-07-13 17:36:57 -04:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
byte[] randomBytes = new byte[context.Request.ReceiveBuff[0].Size];
|
2018-07-13 17:36:57 -04:00
|
|
|
|
|
2018-12-06 06:16:24 -05:00
|
|
|
|
_rng.GetBytes(randomBytes);
|
2018-07-13 17:36:57 -04:00
|
|
|
|
|
2021-04-24 06:16:01 -04:00
|
|
|
|
context.Memory.Write(context.Request.ReceiveBuff[0].Position, randomBytes);
|
2018-07-13 17:36:57 -04:00
|
|
|
|
|
2019-07-14 15:04:38 -04:00
|
|
|
|
return ResultCode.Success;
|
2018-07-13 17:36:57 -04:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-29 13:37:13 -04:00
|
|
|
|
protected override void Dispose(bool isDisposing)
|
2018-07-13 17:36:57 -04:00
|
|
|
|
{
|
2021-06-29 13:37:13 -04:00
|
|
|
|
if (isDisposing)
|
2018-07-13 17:36:57 -04:00
|
|
|
|
{
|
2018-12-06 06:16:24 -05:00
|
|
|
|
_rng.Dispose();
|
2018-07-13 17:36:57 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|