github.com/emmansun/gmsm@v0.29.1/internal/sm2ec/p256_asm_table_test.go (about) 1 //go:build (amd64 || arm64 || s390x) && !purego 2 3 package sm2ec 4 5 import ( 6 "fmt" 7 "testing" 8 ) 9 10 func TestP256PrecomputedTable(t *testing.T) { 11 base := NewSM2P256Point().SetGenerator() 12 13 for i := 0; i < 43; i++ { 14 t.Run(fmt.Sprintf("table[%d]", i), func(t *testing.T) { 15 testP256AffineTable(t, base, &p256Precomputed[i]) 16 }) 17 18 for k := 0; k < 6; k++ { 19 base.Double(base) 20 } 21 } 22 } 23 24 func testP256AffineTable(t *testing.T, base *SM2P256Point, table *p256AffineTable) { 25 p := NewSM2P256Point() 26 zInv := new(p256Element) 27 zInvSq := new(p256Element) 28 29 for j := 0; j < 32; j++ { 30 p.Add(p, base) 31 32 // Convert p to affine coordinates. 33 p256Inverse(zInv, &p.z) 34 p256Sqr(zInvSq, zInv, 1) 35 p256Mul(zInv, zInv, zInvSq) 36 37 p256Mul(&p.x, &p.x, zInvSq) 38 p256Mul(&p.y, &p.y, zInv) 39 p.z = p256One 40 41 if p256Equal(&table[j].x, &p.x) != 1 || p256Equal(&table[j].y, &p.y) != 1 { 42 t.Fatalf("incorrect table entry at index %d", j) 43 } 44 } 45 }