mirror of
https://github.com/emmansun/gmsm.git
synced 2025-04-26 12:16:20 +08:00
sm9/bn256: adjust test case order
This commit is contained in:
parent
dd5fcd13d6
commit
628054399a
@ -43,6 +43,95 @@ func TestCurvePointDouble(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCurvePointDobuleComplete(t *testing.T) {
|
||||||
|
t.Run("normal case", func(t *testing.T) {
|
||||||
|
p2 := &curvePoint{}
|
||||||
|
p2.DoubleComplete(curveGen)
|
||||||
|
p2.AffineFromProjective()
|
||||||
|
|
||||||
|
p3 := &curvePoint{}
|
||||||
|
curvePointDouble(p3, curveGen)
|
||||||
|
p3.AffineFromJacobian()
|
||||||
|
|
||||||
|
if !p2.Equal(p3) {
|
||||||
|
t.Errorf("Got %v, expected %v", p2, p3)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("exception case: IsInfinity", func(t *testing.T) {
|
||||||
|
p1 := &curvePoint{}
|
||||||
|
p1.SetInfinity()
|
||||||
|
p2 := &curvePoint{}
|
||||||
|
p2.DoubleComplete(p1)
|
||||||
|
p2.AffineFromProjective()
|
||||||
|
if !p2.IsInfinity() {
|
||||||
|
t.Fatal("should be infinity")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCurvePointAddComplete(t *testing.T) {
|
||||||
|
t.Run("normal case", func(t *testing.T) {
|
||||||
|
p1 := &curvePoint{}
|
||||||
|
curvePointDouble(p1, curveGen)
|
||||||
|
p1.AffineFromJacobian()
|
||||||
|
|
||||||
|
p2 := &curvePoint{}
|
||||||
|
p2.AddComplete(p1, curveGen)
|
||||||
|
p2.AffineFromProjective()
|
||||||
|
|
||||||
|
p3 := &curvePoint{}
|
||||||
|
curvePointAdd(p3, curveGen, p1)
|
||||||
|
p3.AffineFromJacobian()
|
||||||
|
|
||||||
|
if !p2.Equal(p3) {
|
||||||
|
t.Errorf("Got %v, expected %v", p2, p3)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
t.Run("exception case: double", func(t *testing.T) {
|
||||||
|
p2 := &curvePoint{}
|
||||||
|
p2.AddComplete(curveGen, curveGen)
|
||||||
|
p2.AffineFromProjective()
|
||||||
|
|
||||||
|
p3 := &curvePoint{}
|
||||||
|
curvePointDouble(p3, curveGen)
|
||||||
|
p3.AffineFromJacobian()
|
||||||
|
if !p2.Equal(p3) {
|
||||||
|
t.Errorf("Got %v, expected %v", p2, p3)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
t.Run("exception case: neg", func(t *testing.T) {
|
||||||
|
p1 := &curvePoint{}
|
||||||
|
p1.Neg(curveGen)
|
||||||
|
p2 := &curvePoint{}
|
||||||
|
p2.AddComplete(curveGen, p1)
|
||||||
|
p2.AffineFromProjective()
|
||||||
|
if !p2.IsInfinity() {
|
||||||
|
t.Fatal("should be infinity")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
t.Run("exception case: IsInfinity", func(t *testing.T) {
|
||||||
|
p1 := &curvePoint{}
|
||||||
|
p1.SetInfinity()
|
||||||
|
p2 := &curvePoint{}
|
||||||
|
p2.AddComplete(curveGen, p1)
|
||||||
|
p2.AffineFromProjective()
|
||||||
|
if !p2.Equal(curveGen) {
|
||||||
|
t.Fatal("should be curveGen")
|
||||||
|
}
|
||||||
|
p2.AddComplete(p1, curveGen)
|
||||||
|
p2.AffineFromProjective()
|
||||||
|
if !p2.Equal(curveGen) {
|
||||||
|
t.Fatal("should be curveGen")
|
||||||
|
}
|
||||||
|
p2.AddComplete(p1, p1)
|
||||||
|
p2.AffineFromProjective()
|
||||||
|
if !p2.IsInfinity() {
|
||||||
|
t.Fatal("should be infinity")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
type g1BaseMultTest struct {
|
type g1BaseMultTest struct {
|
||||||
k string
|
k string
|
||||||
}
|
}
|
||||||
@ -611,68 +700,6 @@ func BenchmarkMarshalUnmarshal(b *testing.B) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCurvePointAddComplete(t *testing.T) {
|
|
||||||
t.Run("normal case", func(t *testing.T) {
|
|
||||||
p1 := &curvePoint{}
|
|
||||||
curvePointDouble(p1, curveGen)
|
|
||||||
p1.AffineFromJacobian()
|
|
||||||
|
|
||||||
p2 := &curvePoint{}
|
|
||||||
p2.AddComplete(p1, curveGen)
|
|
||||||
p2.AffineFromProjective()
|
|
||||||
|
|
||||||
p3 := &curvePoint{}
|
|
||||||
curvePointAdd(p3, curveGen, p1)
|
|
||||||
p3.AffineFromJacobian()
|
|
||||||
|
|
||||||
if !p2.Equal(p3) {
|
|
||||||
t.Errorf("Got %v, expected %v", p2, p3)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
t.Run("exception case: double", func(t *testing.T) {
|
|
||||||
p2 := &curvePoint{}
|
|
||||||
p2.AddComplete(curveGen, curveGen)
|
|
||||||
p2.AffineFromProjective()
|
|
||||||
|
|
||||||
p3 := &curvePoint{}
|
|
||||||
curvePointDouble(p3, curveGen)
|
|
||||||
p3.AffineFromJacobian()
|
|
||||||
if !p2.Equal(p3) {
|
|
||||||
t.Errorf("Got %v, expected %v", p2, p3)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
t.Run("exception case: neg", func(t *testing.T) {
|
|
||||||
p1 := &curvePoint{}
|
|
||||||
p1.Neg(curveGen)
|
|
||||||
p2 := &curvePoint{}
|
|
||||||
p2.AddComplete(curveGen, p1)
|
|
||||||
p2.AffineFromProjective()
|
|
||||||
if !p2.IsInfinity() {
|
|
||||||
t.Fatal("should be infinity")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
t.Run("exception case: IsInfinity", func(t *testing.T) {
|
|
||||||
p1 := &curvePoint{}
|
|
||||||
p1.SetInfinity()
|
|
||||||
p2 := &curvePoint{}
|
|
||||||
p2.AddComplete(curveGen, p1)
|
|
||||||
p2.AffineFromProjective()
|
|
||||||
if !p2.Equal(curveGen) {
|
|
||||||
t.Fatal("should be curveGen")
|
|
||||||
}
|
|
||||||
p2.AddComplete(p1, curveGen)
|
|
||||||
p2.AffineFromProjective()
|
|
||||||
if !p2.Equal(curveGen) {
|
|
||||||
t.Fatal("should be curveGen")
|
|
||||||
}
|
|
||||||
p2.AddComplete(p1, p1)
|
|
||||||
p2.AffineFromProjective()
|
|
||||||
if !p2.IsInfinity() {
|
|
||||||
t.Fatal("should be infinity")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func BenchmarkAddPoint(b *testing.B) {
|
func BenchmarkAddPoint(b *testing.B) {
|
||||||
p1 := &curvePoint{}
|
p1 := &curvePoint{}
|
||||||
curvePointDouble(p1, curveGen)
|
curvePointDouble(p1, curveGen)
|
||||||
@ -694,33 +721,6 @@ func BenchmarkAddPoint(b *testing.B) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCurvePointDobuleComplete(t *testing.T) {
|
|
||||||
t.Run("normal case", func(t *testing.T) {
|
|
||||||
p2 := &curvePoint{}
|
|
||||||
p2.DoubleComplete(curveGen)
|
|
||||||
p2.AffineFromProjective()
|
|
||||||
|
|
||||||
p3 := &curvePoint{}
|
|
||||||
curvePointDouble(p3, curveGen)
|
|
||||||
p3.AffineFromJacobian()
|
|
||||||
|
|
||||||
if !p2.Equal(p3) {
|
|
||||||
t.Errorf("Got %v, expected %v", p2, p3)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("exception case: IsInfinity", func(t *testing.T) {
|
|
||||||
p1 := &curvePoint{}
|
|
||||||
p1.SetInfinity()
|
|
||||||
p2 := &curvePoint{}
|
|
||||||
p2.DoubleComplete(p1)
|
|
||||||
p2.AffineFromProjective()
|
|
||||||
if !p2.IsInfinity() {
|
|
||||||
t.Fatal("should be infinity")
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func BenchmarkDoublePoint(b *testing.B) {
|
func BenchmarkDoublePoint(b *testing.B) {
|
||||||
p2 := &curvePoint{}
|
p2 := &curvePoint{}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user