Bits.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System.Diagnostics;
  4. #if NETSTANDARD1_0_OR_GREATER || NETCOREAPP1_0_OR_GREATER || UNITY_2021_2_OR_NEWER
  5. using System.Runtime.CompilerServices;
  6. #endif
  7. namespace Best.HTTP.SecureProtocol.Org.BouncyCastle.Math.Raw
  8. {
  9. internal static class Bits
  10. {
  11. #if NETSTANDARD1_0_OR_GREATER || NETCOREAPP1_0_OR_GREATER || UNITY_2021_2_OR_NEWER
  12. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  13. #endif
  14. internal static uint BitPermuteStep(uint x, uint m, int s)
  15. {
  16. Debug.Assert((m & (m << s)) == 0U);
  17. Debug.Assert((m << s) >> s == m);
  18. uint t = (x ^ (x >> s)) & m;
  19. return t ^ (t << s) ^ x;
  20. }
  21. #if NETSTANDARD1_0_OR_GREATER || NETCOREAPP1_0_OR_GREATER || UNITY_2021_2_OR_NEWER
  22. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  23. #endif
  24. internal static ulong BitPermuteStep(ulong x, ulong m, int s)
  25. {
  26. Debug.Assert((m & (m << s)) == 0UL);
  27. Debug.Assert((m << s) >> s == m);
  28. ulong t = (x ^ (x >> s)) & m;
  29. return t ^ (t << s) ^ x;
  30. }
  31. #if NETSTANDARD1_0_OR_GREATER || NETCOREAPP1_0_OR_GREATER || UNITY_2021_2_OR_NEWER
  32. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  33. #endif
  34. internal static void BitPermuteStep2(ref uint hi, ref uint lo, uint m, int s)
  35. {
  36. #if NETSTANDARD2_1_OR_GREATER || NETCOREAPP1_1_OR_GREATER || UNITY_2021_2_OR_NEWER
  37. //Debug.Assert(!Unsafe.AreSame(ref hi, ref lo) || (m & (m << s)) == 0U);
  38. #endif
  39. Debug.Assert((m << s) >> s == m);
  40. uint t = ((lo >> s) ^ hi) & m;
  41. lo ^= t << s;
  42. hi ^= t;
  43. }
  44. #if NETSTANDARD1_0_OR_GREATER || NETCOREAPP1_0_OR_GREATER || UNITY_2021_2_OR_NEWER
  45. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  46. #endif
  47. internal static void BitPermuteStep2(ref ulong hi, ref ulong lo, ulong m, int s)
  48. {
  49. #if NETSTANDARD2_1_OR_GREATER || NETCOREAPP1_1_OR_GREATER || UNITY_2021_2_OR_NEWER
  50. //Debug.Assert(!Unsafe.AreSame(ref hi, ref lo) || (m & (m << s)) == 0UL);
  51. #endif
  52. Debug.Assert((m << s) >> s == m);
  53. ulong t = ((lo >> s) ^ hi) & m;
  54. lo ^= t << s;
  55. hi ^= t;
  56. }
  57. #if NETSTANDARD1_0_OR_GREATER || NETCOREAPP1_0_OR_GREATER || UNITY_2021_2_OR_NEWER
  58. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  59. #endif
  60. internal static uint BitPermuteStepSimple(uint x, uint m, int s)
  61. {
  62. Debug.Assert((m & (m << s)) == 0U);
  63. Debug.Assert((m << s) >> s == m);
  64. return ((x & m) << s) | ((x >> s) & m);
  65. }
  66. #if NETSTANDARD1_0_OR_GREATER || NETCOREAPP1_0_OR_GREATER || UNITY_2021_2_OR_NEWER
  67. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  68. #endif
  69. internal static ulong BitPermuteStepSimple(ulong x, ulong m, int s)
  70. {
  71. Debug.Assert((m & (m << s)) == 0UL);
  72. Debug.Assert((m << s) >> s == m);
  73. return ((x & m) << s) | ((x >> s) & m);
  74. }
  75. }
  76. }
  77. #pragma warning restore
  78. #endif