github.com/luckypickle/go-ethereum-vet@v1.14.2/crypto/bn256/cloudflare/lattice_test.go (about)

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