Nat512.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #if !BESTHTTP_DISABLE_ALTERNATE_SSL && (!UNITY_WEBGL || UNITY_EDITOR)
  2. using System;
  3. using System.Diagnostics;
  4. namespace Org.BouncyCastle.Math.Raw
  5. {
  6. internal abstract class Nat512
  7. {
  8. public static void Mul(uint[] x, uint[] y, uint[] zz)
  9. {
  10. Nat256.Mul(x, y, zz);
  11. Nat256.Mul(x, 8, y, 8, zz, 16);
  12. uint c24 = Nat256.AddToEachOther(zz, 8, zz, 16);
  13. uint c16 = c24 + Nat256.AddTo(zz, 0, zz, 8, 0);
  14. c24 += Nat256.AddTo(zz, 24, zz, 16, c16);
  15. uint[] dx = Nat256.Create(), dy = Nat256.Create();
  16. bool neg = Nat256.Diff(x, 8, x, 0, dx, 0) != Nat256.Diff(y, 8, y, 0, dy, 0);
  17. uint[] tt = Nat256.CreateExt();
  18. Nat256.Mul(dx, dy, tt);
  19. c24 += neg ? Nat.AddTo(16, tt, 0, zz, 8) : (uint)Nat.SubFrom(16, tt, 0, zz, 8);
  20. Nat.AddWordAt(32, c24, zz, 24);
  21. }
  22. public static void Square(uint[] x, uint[] zz)
  23. {
  24. Nat256.Square(x, zz);
  25. Nat256.Square(x, 8, zz, 16);
  26. uint c24 = Nat256.AddToEachOther(zz, 8, zz, 16);
  27. uint c16 = c24 + Nat256.AddTo(zz, 0, zz, 8, 0);
  28. c24 += Nat256.AddTo(zz, 24, zz, 16, c16);
  29. uint[] dx = Nat256.Create();
  30. Nat256.Diff(x, 8, x, 0, dx, 0);
  31. uint[] m = Nat256.CreateExt();
  32. Nat256.Square(dx, m);
  33. c24 += (uint)Nat.SubFrom(16, m, 0, zz, 8);
  34. Nat.AddWordAt(32, c24, zz, 24);
  35. }
  36. }
  37. }
  38. #endif