Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

vor 6 Jahren
vor 6 Jahren
vor 6 Jahren
vor 6 Jahren
vor 6 Jahren
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. func fp503Mul(z *FpElementX2, x, y *FpElement) {
  35. if cpu.HasBMI2 {
  36. mulWithMULXADX(z, x, y)
  37. } else {
  38. mul(z, x, y)
  39. }
  40. }
  41. // Mul implementattion for legacy CPUs
  42. //go:noescape
  43. func mul(z *FpElementX2, x, y *FpElement)
  44. // Mul implementation for CPUs supporting carry-less MULX multiplier.
  45. //go:noescape
  46. func mulWithMULX(z *FpElementX2, x, y *FpElement)
  47. // Mul implementation for CPUs supporting two independent carry chain
  48. // (ADOX/ADCX) instructions and carry-less MULX multiplier
  49. //go:noescape
  50. func mulWithMULXADX(z *FpElementX2, x, y *FpElement)
  51. // Computes the Montgomery reduction z = x R^{-1} (mod 2*p). On return value
  52. // of x may be changed. z=x not allowed.
  53. func fp503MontgomeryReduce(z *FpElement, x *FpElementX2) {
  54. if cpu.HasBMI2 {
  55. if cpu.HasADX {
  56. redcWithMULXADX(z, x)
  57. } else {
  58. redcWithMULX(z, x)
  59. }
  60. } else {
  61. redc(z, x)
  62. }
  63. }
  64. func redc(z *FpElement, x *FpElementX2)
  65. // Mul implementation for CPUs supporting carry-less MULX multiplier.
  66. //go:noescape
  67. func redcWithMULX(z *FpElement, x *FpElementX2)
  68. // Mul implementation for CPUs supporting two independent carry chain
  69. // (ADOX/ADCX) instructions and carry-less MULX multiplier
  70. //go:noescape
  71. func redcWithMULXADX(z *FpElement, x *FpElementX2)
  72. // On initialization, set the fp503Mul function pointer to the
  73. // fastest implementation depending on CPU capabilities.
  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. }