FastSalsa20EngineHelper.cs 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. using System;
  3. namespace BestHTTP.Connections.TLS.Crypto.Impl
  4. {
  5. #if BESTHTTP_WITH_BURST
  6. [Unity.Burst.BurstCompile]
  7. #endif
  8. internal static class FastSalsa20EngineHelper
  9. {
  10. #if BESTHTTP_WITH_BURST
  11. [Unity.Burst.BurstCompile]
  12. public unsafe static void ProcessBytes([Unity.Burst.NoAlias] byte* outBytes, int outOff, [Unity.Burst.NoAlias] byte* inBytes, int inOff, [Unity.Burst.NoAlias] byte* keyStream)
  13. {
  14. //for (int i = 0; i < 64; ++i)
  15. // outBytes[idx + i + outOff] = (byte)(keyStream[i] ^ inBytes[idx + i + inOff]);
  16. ulong* pulOut = (ulong*)&outBytes[outOff];
  17. ulong* pulIn = (ulong*)&inBytes[inOff];
  18. ulong* pulKeyStream = (ulong*)keyStream;
  19. pulOut[0] = pulKeyStream[0] ^ pulIn[0];
  20. pulOut[1] = pulKeyStream[1] ^ pulIn[1];
  21. pulOut[2] = pulKeyStream[2] ^ pulIn[2];
  22. pulOut[3] = pulKeyStream[3] ^ pulIn[3];
  23. }
  24. #endif
  25. }
  26. }
  27. #endif