IRandomInterface.cs 956 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System.Security.Cryptography;
  2. namespace Ryujinx.HLE.HOS.Services.Spl
  3. {
  4. [Service("csrng")]
  5. class IRandomInterface : DisposableIpcService
  6. {
  7. private RandomNumberGenerator _rng;
  8. private object _lock = new object();
  9. public IRandomInterface(ServiceCtx context)
  10. {
  11. _rng = RandomNumberGenerator.Create();
  12. }
  13. [CommandHipc(0)]
  14. // GetRandomBytes() -> buffer<unknown, 6>
  15. public ResultCode GetRandomBytes(ServiceCtx context)
  16. {
  17. byte[] randomBytes = new byte[context.Request.ReceiveBuff[0].Size];
  18. _rng.GetBytes(randomBytes);
  19. context.Memory.Write(context.Request.ReceiveBuff[0].Position, randomBytes);
  20. return ResultCode.Success;
  21. }
  22. protected override void Dispose(bool isDisposing)
  23. {
  24. if (isDisposing)
  25. {
  26. _rng.Dispose();
  27. }
  28. }
  29. }
  30. }