Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

76 lignes
1.9 KiB

  1. // +build amd64,!noasm
  2. package p751
  3. import (
  4. . "github.com/cloudflare/sidh/internal/isogeny"
  5. cpu "github.com/cloudflare/sidh/internal/utils"
  6. "testing"
  7. "testing/quick"
  8. )
  9. type OptimFlag uint
  10. const (
  11. kUse_MUL OptimFlag = 1 << 0
  12. kUse_MULX = 1 << 1
  13. kUse_MULXADX = 1 << 2
  14. )
  15. // Utility function used for testing REDC implementations. Tests caller provided
  16. // redcFunc against redc()
  17. func testRedc(t *testing.T, f1, f2 OptimFlag) {
  18. doRedcTest := func(aRR FpElementX2) bool {
  19. defer recognizecpu()
  20. var resRedcF1, resRedcF2 FpElement
  21. var aRRcpy = aRR
  22. // Compute redc with first implementation
  23. useMULX = (kUse_MULX & f1) == kUse_MULX
  24. useADXMULX = (kUse_MULXADX & f1) == kUse_MULXADX
  25. fp751MontgomeryReduce(&resRedcF1, &aRR)
  26. // Compute redc with second implementation
  27. useMULX = (kUse_MULX & f2) == kUse_MULX
  28. useADXMULX = (kUse_MULXADX & f2) == kUse_MULXADX
  29. fp751MontgomeryReduce(&resRedcF2, &aRRcpy)
  30. // Compare results
  31. return reflect.DeepEqual(resRedcF2, resRedcF1)
  32. }
  33. if err := quick.Check(doRedcTest, quickCheckConfig); err != nil {
  34. t.Error(err)
  35. }
  36. }
  37. // Ensures corretness of Montgomery reduction implementation which uses MULX
  38. func TestRedcWithMULX(t *testing.T) {
  39. defer recognizecpu()
  40. if !cpu.HasBMI2 {
  41. t.Skip("MULX not supported by the platform")
  42. }
  43. testRedc(t, kUse_MULX, kUse_MUL)
  44. }
  45. // Ensures corretness of Montgomery reduction implementation which uses MULX
  46. // and ADX
  47. func TestRedcWithMULXADX(t *testing.T) {
  48. defer recognizecpu()
  49. if !(cpu.HasADX && cpu.HasBMI2) {
  50. t.Skip("MULX, ADCX and ADOX not supported by the platform")
  51. }
  52. testRedc(t, kUse_MULXADX, kUse_MUL)
  53. }
  54. // Ensures corretness of Montgomery reduction implementation which uses MULX
  55. // and ADX.
  56. func TestRedcWithMULXADXAgainstMULX(t *testing.T) {
  57. defer recognizecpu()
  58. if !(cpu.HasADX && cpu.HasBMI2) {
  59. t.Skip("MULX, ADCX and ADOX not supported by the platform")
  60. }
  61. testRedc(t, kUse_MULXADX, kUse_MULX)
  62. }