IRandomInterface.cs 973 B

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