Nat320.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. #pragma warning disable
  3. using System;
  4. using System.Diagnostics;
  5. using BestHTTP.SecureProtocol.Org.BouncyCastle.Crypto.Utilities;
  6. namespace BestHTTP.SecureProtocol.Org.BouncyCastle.Math.Raw
  7. {
  8. internal abstract class Nat320
  9. {
  10. public static void Copy64(ulong[] x, ulong[] z)
  11. {
  12. z[0] = x[0];
  13. z[1] = x[1];
  14. z[2] = x[2];
  15. z[3] = x[3];
  16. z[4] = x[4];
  17. }
  18. public static void Copy64(ulong[] x, int xOff, ulong[] z, int zOff)
  19. {
  20. z[zOff + 0] = x[xOff + 0];
  21. z[zOff + 1] = x[xOff + 1];
  22. z[zOff + 2] = x[xOff + 2];
  23. z[zOff + 3] = x[xOff + 3];
  24. z[zOff + 4] = x[xOff + 4];
  25. }
  26. public static ulong[] Create64()
  27. {
  28. return new ulong[5];
  29. }
  30. public static ulong[] CreateExt64()
  31. {
  32. return new ulong[10];
  33. }
  34. public static bool Eq64(ulong[] x, ulong[] y)
  35. {
  36. for (int i = 4; i >= 0; --i)
  37. {
  38. if (x[i] != y[i])
  39. {
  40. return false;
  41. }
  42. }
  43. return true;
  44. }
  45. public static bool IsOne64(ulong[] x)
  46. {
  47. if (x[0] != 1UL)
  48. {
  49. return false;
  50. }
  51. for (int i = 1; i < 5; ++i)
  52. {
  53. if (x[i] != 0UL)
  54. {
  55. return false;
  56. }
  57. }
  58. return true;
  59. }
  60. public static bool IsZero64(ulong[] x)
  61. {
  62. for (int i = 0; i < 5; ++i)
  63. {
  64. if (x[i] != 0UL)
  65. {
  66. return false;
  67. }
  68. }
  69. return true;
  70. }
  71. public static BigInteger ToBigInteger64(ulong[] x)
  72. {
  73. byte[] bs = new byte[40];
  74. for (int i = 0; i < 5; ++i)
  75. {
  76. ulong x_i = x[i];
  77. if (x_i != 0L)
  78. {
  79. Pack.UInt64_To_BE(x_i, bs, (4 - i) << 3);
  80. }
  81. }
  82. return new BigInteger(1, bs);
  83. }
  84. }
  85. }
  86. #pragma warning restore
  87. #endif