github.com/hellobchain/newcryptosm@v0.0.0-20221019060107-edb949a317e9/ecdsa/sm2_ecdsa_test.go (about) 1 package ecdsa_test 2 3 import ( 4 "github.com/hellobchain/newcryptosm/ecdsa" 5 "github.com/hellobchain/newcryptosm/sm2" 6 "math/big" 7 "testing" 8 ) 9 10 func TestStandardData(t *testing.T) { 11 priv := &ecdsa.PrivateKey{} 12 priv.Curve = sm2.SM2() 13 priv.D, _ = new(big.Int).SetString("3945208F7B2144B13F36E38AC6D39F95889393692860B51A42FB81EF4DF7C5B8", 16) 14 priv.X, priv.Y = priv.ScalarBaseMult(priv.D.Bytes()) 15 16 expPubX, _ := new(big.Int).SetString("09F9DF311E5421A150DD7D161E4BC5C672179FAD1833FC076BB08FF356F35020", 16) 17 expPubY, _ := new(big.Int).SetString("CCEA490CE26775A52DC6EA718CC1AA600AED05FBF35E084A6632F6072DA9AD13", 16) 18 if priv.X.Cmp(expPubX) != 0 || priv.Y.Cmp(expPubY) != 0 { 19 t.Fatal("public key is not equal") 20 } 21 22 message := []byte("message digest") 23 24 r, _ := new(big.Int).SetString("F5A03B0648D2C4630EEAC513E1BB81A15944DA3827D5B74143AC7EACEEE720B3", 16) 25 s, _ := new(big.Int).SetString("B1B6AA29DF212FD8763182BC0D421CA1BB9038FD1F7F42D4840B69C485BBC1AA", 16) 26 27 if verify := ecdsa.Verify(&priv.PublicKey, message, r, s); !verify { 28 t.Fatal("verify fail") 29 } 30 }