You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

72 line
1.9 KiB

  1. // +build amd64,!noasm
  2. package p751
  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 fp751ConditionalSwap(x, y *FpElement, choice uint8)
  12. // Compute z = x + y (mod p).
  13. //go:noescape
  14. func fp751AddReduced(z, x, y *FpElement)
  15. // Compute z = x - y (mod p).
  16. //go:noescape
  17. func fp751SubReduced(z, x, y *FpElement)
  18. // Compute z = x + y, without reducing mod p.
  19. //go:noescape
  20. func fp751AddLazy(z, x, y *FpElement)
  21. // Compute z = x + y, without reducing mod p.
  22. //go:noescape
  23. func fp751X2AddLazy(z, x, y *FpElementX2)
  24. // Compute z = x - y, without reducing mod p.
  25. //go:noescape
  26. func fp751X2SubLazy(z, x, y *FpElementX2)
  27. // Compute z = x * y.
  28. //go:noescape
  29. func fp751Mul(z *FpElementX2, x, y *FpElement)
  30. // Function pointer that should point to one of the
  31. // fp751MontgomeryReduce implementations below.
  32. // When set, it performs Montgomery reduction: set z = x R^{-1} (mod 2*p).
  33. // It may destroy the input value.
  34. var fp751MontgomeryReduce func(z *FpElement, x *FpElementX2)
  35. //go:noescape
  36. func fp751MontgomeryReduceBMI2ADX(z *FpElement, x *FpElementX2)
  37. //go:noescape
  38. func fp751MontgomeryReduceBMI2(z *FpElement, x *FpElementX2)
  39. //go:noescape
  40. func fp751MontgomeryReduceFallback(z *FpElement, x *FpElementX2)
  41. // Reduce a field element in [0, 2*p) to one in [0,p).
  42. //go:noescape
  43. func fp751StrongReduce(x *FpElement)
  44. // On initialization, set the fp751MontgomeryReduce function pointer to the
  45. // fastest implementation depending on CPU capabilities.
  46. func init() {
  47. if cpu.HasBMI2 {
  48. if cpu.HasADX {
  49. fp751MontgomeryReduce = fp751MontgomeryReduceBMI2ADX
  50. } else {
  51. fp751MontgomeryReduce = fp751MontgomeryReduceBMI2
  52. }
  53. } else {
  54. fp751MontgomeryReduce = fp751MontgomeryReduceFallback
  55. }
  56. }