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