選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 

66 行
1.7 KiB

  1. // +build amd64,!noasm
  2. package p751
  3. import (
  4. "golang.org/x/sys/cpu"
  5. . "github.com/cloudflare/p751sidh/internal/isogeny"
  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. func fp751MontgomeryReduce(z *FpElement, x *FpElementX2) {
  35. if cpu.X86.HasBMI2 && cpu.X86.HasADX {
  36. fp751MontgomeryReduceBMI2ADX(z,x)
  37. } else if cpu.X86.HasBMI2 {
  38. fp751MontgomeryReduceBMI2(z,x)
  39. } else {
  40. fp751MontgomeryReduceFallback(z,x)
  41. }
  42. }
  43. //go:noescape
  44. func fp751MontgomeryReduceBMI2ADX(z *FpElement, x *FpElementX2)
  45. //go:noescape
  46. func fp751MontgomeryReduceBMI2(z *FpElement, x *FpElementX2)
  47. //go:noescape
  48. func fp751MontgomeryReduceFallback(z *FpElement, x *FpElementX2)
  49. // Reduce a field element in [0, 2*p) to one in [0,p).
  50. //go:noescape
  51. func fp751StrongReduce(x *FpElement)