Nat384.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 Nat384
  7. {
  8. public static void Mul(uint[] x, uint[] y, uint[] zz)
  9. {
  10. Nat192.Mul(x, y, zz);
  11. Nat192.Mul(x, 6, y, 6, zz, 12);
  12. uint c18 = Nat192.AddToEachOther(zz, 6, zz, 12);
  13. uint c12 = c18 + Nat192.AddTo(zz, 0, zz, 6, 0);
  14. c18 += Nat192.AddTo(zz, 18, zz, 12, c12);
  15. uint[] dx = Nat192.Create(), dy = Nat192.Create();
  16. bool neg = Nat192.Diff(x, 6, x, 0, dx, 0) != Nat192.Diff(y, 6, y, 0, dy, 0);
  17. uint[] tt = Nat192.CreateExt();
  18. Nat192.Mul(dx, dy, tt);
  19. c18 += neg ? Nat.AddTo(12, tt, 0, zz, 6) : (uint)Nat.SubFrom(12, tt, 0, zz, 6);
  20. Nat.AddWordAt(24, c18, zz, 18);
  21. }
  22. public static void Square(uint[] x, uint[] zz)
  23. {
  24. Nat192.Square(x, zz);
  25. Nat192.Square(x, 6, zz, 12);
  26. uint c18 = Nat192.AddToEachOther(zz, 6, zz, 12);
  27. uint c12 = c18 + Nat192.AddTo(zz, 0, zz, 6, 0);
  28. c18 += Nat192.AddTo(zz, 18, zz, 12, c12);
  29. uint[] dx = Nat192.Create();
  30. Nat192.Diff(x, 6, x, 0, dx, 0);
  31. uint[] m = Nat192.CreateExt();
  32. Nat192.Square(dx, m);
  33. c18 += (uint)Nat.SubFrom(12, m, 0, zz, 6);
  34. Nat.AddWordAt(24, c18, zz, 18);
  35. }
  36. }
  37. }
  38. #endif