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

75 行
2.1 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. "reflect"
  7. "testing"
  8. "testing/quick"
  9. )
  10. // Utility function used for testing Mul implementations. Tests caller provided
  11. // mulFunc against mul()
  12. func testMul(t *testing.T, mulFunc func(z *FpElementX2, x, y *FpElement)) {
  13. doMulTest := func(multiplier, multiplicant FpElement) bool {
  14. var resMulRef, resMulOptim FpElementX2
  15. mul(&resMulRef, &multiplier, &multiplicant)
  16. mulFunc(&resMulOptim, &multiplier, &multiplicant)
  17. return reflect.DeepEqual(resMulRef, resMulOptim)
  18. }
  19. if err := quick.Check(doMulTest, quickCheckConfig); err != nil {
  20. t.Error(err)
  21. }
  22. }
  23. // Utility function used for testing REDC implementations. Tests caller provided
  24. // redcFunc against redc()
  25. func testRedc(t *testing.T, redcFunc func(z *FpElement, x *FpElementX2)) {
  26. doRedcTest := func(aRR FpElementX2) bool {
  27. var resRedcRef, resRedcOptim FpElement
  28. var aRRcpy = aRR
  29. redc(&resRedcRef, &aRR)
  30. redcFunc(&resRedcOptim, &aRRcpy)
  31. return reflect.DeepEqual(resRedcRef, resRedcOptim)
  32. }
  33. if err := quick.Check(doRedcTest, quickCheckConfig); err != nil {
  34. t.Error(err)
  35. }
  36. }
  37. // Ensures corretness of implementation of mul operation which uses MULX
  38. func TestMulWithMULX(t *testing.T) {
  39. if !cpu.HasBMI2 {
  40. t.Skip("MULX not supported by the platform")
  41. }
  42. testMul(t, mulWithMULX)
  43. }
  44. // Ensures corretness of implementation of mul operation which uses MULX and ADOX/ADCX
  45. func TestMulWithMULXADX(t *testing.T) {
  46. if !(cpu.HasADX && cpu.HasBMI2) {
  47. t.Skip("MULX, ADCX and ADOX not supported by the platform")
  48. }
  49. testMul(t, mulWithMULXADX)
  50. }
  51. // Ensures corretness of Montgomery reduction implementation which uses MULX
  52. func TestRedcWithMULX(t *testing.T) {
  53. if !cpu.HasBMI2 {
  54. t.Skip("MULX not supported by the platform")
  55. }
  56. testRedc(t, redcWithMULX)
  57. }
  58. // Ensures corretness of Montgomery reduction implementation which uses MULX
  59. func TestRedcWithMULXADX(t *testing.T) {
  60. if !(cpu.HasADX && cpu.HasBMI2) {
  61. t.Skip("MULX, ADCX and ADOX not supported by the platform")
  62. }
  63. testRedc(t, redcWithMULXADX)
  64. }