2021-11-28 20:24:17 +00:00
|
|
|
|
using System.Security.Cryptography;
|
2018-07-13 22:36:57 +01:00
|
|
|
|
|
2018-08-17 00:47:36 +01:00
|
|
|
|
namespace Ryujinx.HLE.HOS.Services.Spl
|
2018-07-13 22:36:57 +01:00
|
|
|
|
{
|
2019-07-10 16:59:54 +01:00
|
|
|
|
[Service("csrng")]
|
2021-06-29 18:37:13 +01:00
|
|
|
|
class IRandomInterface : DisposableIpcService
|
2018-07-13 22:36:57 +01:00
|
|
|
|
{
|
2021-11-28 20:24:17 +00:00
|
|
|
|
private RandomNumberGenerator _rng;
|
2018-07-13 22:36:57 +01:00
|
|
|
|
|
2021-06-29 18:37:13 +01:00
|
|
|
|
private object _lock = new object();
|
|
|
|
|
|
2019-07-10 16:59:54 +01:00
|
|
|
|
public IRandomInterface(ServiceCtx context)
|
2018-07-13 22:36:57 +01:00
|
|
|
|
{
|
2021-11-28 20:24:17 +00:00
|
|
|
|
_rng = RandomNumberGenerator.Create();
|
2018-07-13 22:36:57 +01:00
|
|
|
|
}
|
|
|
|
|
|
2023-04-15 00:00:34 +01:00
|
|
|
|
[CommandCmif(0)]
|
2019-07-12 02:13:43 +01:00
|
|
|
|
// GetRandomBytes() -> buffer<unknown, 6>
|
2019-07-14 20:04:38 +01:00
|
|
|
|
public ResultCode GetRandomBytes(ServiceCtx context)
|
2018-07-13 22:36:57 +01:00
|
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
|
byte[] randomBytes = new byte[context.Request.ReceiveBuff[0].Size];
|
2018-07-13 22:36:57 +01:00
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
|
_rng.GetBytes(randomBytes);
|
2018-07-13 22:36:57 +01:00
|
|
|
|
|
2021-04-24 11:16:01 +01:00
|
|
|
|
context.Memory.Write(context.Request.ReceiveBuff[0].Position, randomBytes);
|
2018-07-13 22:36:57 +01:00
|
|
|
|
|
2019-07-14 20:04:38 +01:00
|
|
|
|
return ResultCode.Success;
|
2018-07-13 22:36:57 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-29 18:37:13 +01:00
|
|
|
|
protected override void Dispose(bool isDisposing)
|
2018-07-13 22:36:57 +01:00
|
|
|
|
{
|
2021-06-29 18:37:13 +01:00
|
|
|
|
if (isDisposing)
|
2018-07-13 22:36:57 +01:00
|
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
|
_rng.Dispose();
|
2018-07-13 22:36:57 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|