Nat576.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 Nat576
  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. z[5] = x[5];
  18. z[6] = x[6];
  19. z[7] = x[7];
  20. z[8] = x[8];
  21. }
  22. public static void Copy64(ulong[] x, int xOff, ulong[] z, int zOff)
  23. {
  24. z[zOff + 0] = x[xOff + 0];
  25. z[zOff + 1] = x[xOff + 1];
  26. z[zOff + 2] = x[xOff + 2];
  27. z[zOff + 3] = x[xOff + 3];
  28. z[zOff + 4] = x[xOff + 4];
  29. z[zOff + 5] = x[xOff + 5];
  30. z[zOff + 6] = x[xOff + 6];
  31. z[zOff + 7] = x[xOff + 7];
  32. z[zOff + 8] = x[xOff + 8];
  33. }
  34. public static ulong[] Create64()
  35. {
  36. return new ulong[9];
  37. }
  38. public static ulong[] CreateExt64()
  39. {
  40. return new ulong[18];
  41. }
  42. public static bool Eq64(ulong[] x, ulong[] y)
  43. {
  44. for (int i = 8; i >= 0; --i)
  45. {
  46. if (x[i] != y[i])
  47. {
  48. return false;
  49. }
  50. }
  51. return true;
  52. }
  53. public static bool IsOne64(ulong[] x)
  54. {
  55. if (x[0] != 1UL)
  56. {
  57. return false;
  58. }
  59. for (int i = 1; i < 9; ++i)
  60. {
  61. if (x[i] != 0UL)
  62. {
  63. return false;
  64. }
  65. }
  66. return true;
  67. }
  68. public static bool IsZero64(ulong[] x)
  69. {
  70. for (int i = 0; i < 9; ++i)
  71. {
  72. if (x[i] != 0UL)
  73. {
  74. return false;
  75. }
  76. }
  77. return true;
  78. }
  79. public static BigInteger ToBigInteger64(ulong[] x)
  80. {
  81. byte[] bs = new byte[72];
  82. for (int i = 0; i < 9; ++i)
  83. {
  84. ulong x_i = x[i];
  85. if (x_i != 0L)
  86. {
  87. Pack.UInt64_To_BE(x_i, bs, (8 - i) << 3);
  88. }
  89. }
  90. return new BigInteger(1, bs);
  91. }
  92. }
  93. }
  94. #pragma warning restore
  95. #endif