25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

111 satır
2.8 KiB

  1. // +build amd64,!noasm
  2. package p503
  3. import (
  4. . "github.com/cloudflare/p751sidh/internal/isogeny"
  5. cpu "github.com/cloudflare/p751sidh/internal/utils"
  6. )
  7. // If choice = 0, leave x,y unchanged. If choice = 1, set x,y = y,x.
  8. // If choice is neither 0 nor 1 then behaviour is undefined.
  9. // This function executes in constant time.
  10. //go:noescape
  11. func fp503ConditionalSwap(x, y *FpElement, choice uint8)
  12. // Compute z = x + y (mod p).
  13. //go:noescape
  14. func fp503AddReduced(z, x, y *FpElement)
  15. // Compute z = x - y (mod p).
  16. //go:noescape
  17. func fp503SubReduced(z, x, y *FpElement)
  18. // Compute z = x + y, without reducing mod p.
  19. //go:noescape
  20. func fp503AddLazy(z, x, y *FpElement)
  21. // Compute z = x + y, without reducing mod p.
  22. //go:noescape
  23. func fp503X2AddLazy(z, x, y *FpElementX2)
  24. // Compute z = x - y, without reducing mod p.
  25. //go:noescape
  26. func fp503X2SubLazy(z, x, y *FpElementX2)
  27. // Reduce a field element in [0, 2*p) to one in [0,p).
  28. //go:noescape
  29. func fp503StrongReduce(x *FpElement)
  30. // Function pointer to function computing z = x * y.
  31. // Concrete implementation depends on capabilities of the CPU which
  32. // are resolved at runtime. CPUs with ADCX, ADOX and MULX support
  33. // run most optimized implementation
  34. //go:noescape
  35. // var fp503Mul func(z *FpElementX2, x, y *FpElement)
  36. // Mul implementattion for legacy CPUs
  37. //go:noescape
  38. func mul(z *FpElementX2, x, y *FpElement)
  39. // Mul implementation for CPUs supporting carry-less MULX multiplier.
  40. //go:noescape
  41. func mulWithMULX(z *FpElementX2, x, y *FpElement)
  42. // Mul implementation for CPUs supporting two independent carry chain
  43. // (ADOX/ADCX) instructions and carry-less MULX multiplier
  44. func fp503Mul(z *FpElementX2, x, y *FpElement) {
  45. if cpu.HasBMI2 {
  46. mulWithMULXADX(z, x, y)
  47. } else {
  48. mul(z, x, y)
  49. }
  50. }
  51. //go:noescape
  52. func fp503MulXXX(z, x, y []uint64)
  53. var fp503Mul1 func(z, x, y []uint64)
  54. //go:noescape
  55. func mulWithMULXADX(z *FpElementX2, x, y *FpElement)
  56. // Computes the Montgomery reduction z = x R^{-1} (mod 2*p). On return value
  57. // of x may be changed. z=x not allowed.
  58. //go:noescape
  59. func fp503MontgomeryReduce(z *FpElement, x *FpElementX2)
  60. func redc(z *FpElement, x *FpElementX2)
  61. // Mul implementation for CPUs supporting carry-less MULX multiplier.
  62. //go:noescape
  63. func redcWithMULX(z *FpElement, x *FpElementX2)
  64. // Mul implementation for CPUs supporting two independent carry chain
  65. // (ADOX/ADCX) instructions and carry-less MULX multiplier
  66. //go:noescape
  67. func redcWithMULXADX(z *FpElement, x *FpElementX2)
  68. // On initialization, set the fp503Mul function pointer to the
  69. // fastest implementation depending on CPU capabilities.
  70. func init() {
  71. fp503Mul1 = fp503MulXXX
  72. }
  73. /*
  74. func init() {
  75. if cpu.HasBMI2 {
  76. if cpu.HasADX {
  77. //fp503Mul = mulWithMULXADX
  78. fp503MontgomeryReduce = redcWithMULXADX
  79. } else {
  80. //fp503Mul = mulWithMULX
  81. fp503MontgomeryReduce = redcWithMULX
  82. }
  83. } else {
  84. //fp503Mul = mul
  85. fp503MontgomeryReduce = redc
  86. }
  87. }
  88. */