lattice_test.go 731 B

123456789101112131415161718192021222324252627282930
  1. package bn256
  2. import (
  3. "crypto/rand"
  4. "testing"
  5. )
  6. func TestLatticeReduceCurve(t *testing.T) {
  7. k, _ := rand.Int(rand.Reader, Order)
  8. ks := curveLattice.decompose(k)
  9. if ks[0].BitLen() > 130 || ks[1].BitLen() > 130 {
  10. t.Fatal("reduction too large")
  11. } else if ks[0].Sign() < 0 || ks[1].Sign() < 0 {
  12. t.Fatal("reduction must be positive")
  13. }
  14. }
  15. func TestLatticeReduceTarget(t *testing.T) {
  16. k, _ := rand.Int(rand.Reader, Order)
  17. ks := targetLattice.decompose(k)
  18. if ks[0].BitLen() > 66 || ks[1].BitLen() > 66 || ks[2].BitLen() > 66 || ks[3].BitLen() > 66 {
  19. t.Fatal("reduction too large")
  20. } else if ks[0].Sign() < 0 || ks[1].Sign() < 0 || ks[2].Sign() < 0 || ks[3].Sign() < 0 {
  21. t.Fatal("reduction must be positive")
  22. }
  23. }