Reduce function parameter

This commit is contained in:
Emman 2021-12-02 10:48:23 +08:00
parent 6e3f8e5d1c
commit 78e22c4df2
2 changed files with 4 additions and 4 deletions

View File

@ -369,15 +369,15 @@ func decrypt(priv *PrivateKey, ciphertext []byte, opts *DecrypterOpts) ([]byte,
return msg, nil 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 { if from == to {
return ciphertext, nil return ciphertext, nil
} }
ciphertextLen := len(ciphertext) 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") return nil, errors.New("SM2: invalid ciphertext length")
} }
curve := pub.Curve
// get C1, and check C1 // get C1, and check C1
_, _, c3Start, err := bytes2Point(curve, ciphertext) _, _, c3Start, err := bytes2Point(curve, ciphertext)

View File

@ -61,7 +61,7 @@ func Test_SplicingOrder(t *testing.T) {
} }
//Adjust splicing order //Adjust splicing order
ciphertext, err = AdjustCipherTextSplicingOrder(&priv.PublicKey, ciphertext, tt.from, tt.to) ciphertext, err = AdjustCipherTextSplicingOrder(ciphertext, tt.from, tt.to)
if err != nil { if err != nil {
t.Fatalf("adjust splicing order failed %v", err) t.Fatalf("adjust splicing order failed %v", err)
} }