sm2: fix test cases

This commit is contained in:
Sun Yimin 2024-12-19 08:28:00 +08:00 committed by GitHub
parent 89317b8f0b
commit 6b18205bba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 3 deletions

View File

@ -54,8 +54,8 @@ func TestNewPrivateKey(t *testing.T) {
func TestNewPrivateKeyFromInt(t *testing.T) {
// test nil
_, err := NewPrivateKeyFromInt(nil)
if err == nil || err.Error() != "sm2: invalid private key size" {
t.Errorf("should throw sm2: invalid private key size")
if err == nil || err.Error() != "sm2: private key is nil" {
t.Errorf("should throw sm2: private key is nil")
}
// test 1
_, err = NewPrivateKeyFromInt(big.NewInt(1))

View File

@ -301,7 +301,10 @@ func calculateSampleZA(pub *ecdsa.PublicKey, a *big.Int, uid []byte) ([]byte, er
if uidLen > 0 {
md.Write(uid)
}
writeCurveParams(md, pub.Curve.Params())
md.Write(bigIntToBytes(pub.Curve, a))
md.Write(bigIntToBytes(pub.Curve, pub.Params().B))
md.Write(bigIntToBytes(pub.Curve, pub.Params().Gx))
md.Write(bigIntToBytes(pub.Curve, pub.Params().Gy))
md.Write(bigIntToBytes(pub.Curve, pub.X))
md.Write(bigIntToBytes(pub.Curve, pub.Y))
return md.Sum(nil), nil