diff --git a/sm2/sm2.go b/sm2/sm2.go index 7f5fec4..66b604c 100644 --- a/sm2/sm2.go +++ b/sm2/sm2.go @@ -369,15 +369,15 @@ func decrypt(priv *PrivateKey, ciphertext []byte, opts *DecrypterOpts) ([]byte, return msg, nil } -func AdjustCipherTextSplicingOrder(pub *ecdsa.PublicKey, ciphertext []byte, from, to cipherTextSplicingOrder) ([]byte, error) { +func AdjustCipherTextSplicingOrder(ciphertext []byte, from, to cipherTextSplicingOrder) ([]byte, error) { + curve := P256() if from == to { return ciphertext, nil } ciphertextLen := len(ciphertext) - if ciphertextLen <= 1+(pub.Params().BitSize/8)+sm3.Size { + if ciphertextLen <= 1+(curve.Params().BitSize/8)+sm3.Size { return nil, errors.New("SM2: invalid ciphertext length") } - curve := pub.Curve // get C1, and check C1 _, _, c3Start, err := bytes2Point(curve, ciphertext) diff --git a/sm2/sm2_test.go b/sm2/sm2_test.go index 01a9549..3c9b018 100644 --- a/sm2/sm2_test.go +++ b/sm2/sm2_test.go @@ -61,7 +61,7 @@ func Test_SplicingOrder(t *testing.T) { } //Adjust splicing order - ciphertext, err = AdjustCipherTextSplicingOrder(&priv.PublicKey, ciphertext, tt.from, tt.to) + ciphertext, err = AdjustCipherTextSplicingOrder(ciphertext, tt.from, tt.to) if err != nil { t.Fatalf("adjust splicing order failed %v", err) }