IRandomInterface.cs 1003 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using System.Security.Cryptography;
  3. namespace Ryujinx.HLE.HOS.Services.Spl
  4. {
  5. [Service("csrng")]
  6. class IRandomInterface : IpcService, IDisposable
  7. {
  8. private RNGCryptoServiceProvider _rng;
  9. public IRandomInterface(ServiceCtx context)
  10. {
  11. _rng = new RNGCryptoServiceProvider();
  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. public void Dispose()
  23. {
  24. Dispose(true);
  25. }
  26. protected virtual void Dispose(bool disposing)
  27. {
  28. if (disposing)
  29. {
  30. _rng.Dispose();
  31. }
  32. }
  33. }
  34. }