github.com/linapex/ethereum-dpos-chinese@v0.0.0-20190316121959-b78b3a4a1ece/crypto/bn256/cloudflare/lattice_test.go (about)

     1  
     2  //<developer>
     3  //    <name>linapex 曹一峰</name>
     4  //    <email>linapex@163.com</email>
     5  //    <wx>superexc</wx>
     6  //    <qqgroup>128148617</qqgroup>
     7  //    <url>https://jsq.ink</url>
     8  //    <role>pku engineer</role>
     9  //    <date>2019-03-16 12:09:36</date>
    10  //</624342625410879488>
    11  
    12  package bn256
    13  
    14  import (
    15  	"crypto/rand"
    16  
    17  	"testing"
    18  )
    19  
    20  func TestLatticeReduceCurve(t *testing.T) {
    21  	k, _ := rand.Int(rand.Reader, Order)
    22  	ks := curveLattice.decompose(k)
    23  
    24  	if ks[0].BitLen() > 130 || ks[1].BitLen() > 130 {
    25  		t.Fatal("reduction too large")
    26  	} else if ks[0].Sign() < 0 || ks[1].Sign() < 0 {
    27  		t.Fatal("reduction must be positive")
    28  	}
    29  }
    30  
    31  func TestLatticeReduceTarget(t *testing.T) {
    32  	k, _ := rand.Int(rand.Reader, Order)
    33  	ks := targetLattice.decompose(k)
    34  
    35  	if ks[0].BitLen() > 66 || ks[1].BitLen() > 66 || ks[2].BitLen() > 66 || ks[3].BitLen() > 66 {
    36  		t.Fatal("reduction too large")
    37  	} else if ks[0].Sign() < 0 || ks[1].Sign() < 0 || ks[2].Sign() < 0 || ks[3].Sign() < 0 {
    38  		t.Fatal("reduction must be positive")
    39  	}
    40  }
    41