crypto/secp256r1: remove check for (0, 0)

This commit is contained in:
Felix Lange 2025-06-11 14:55:25 +02:00
parent e8c3207261
commit 881459ff5e

View file

@ -23,21 +23,11 @@ import (
"math/big" "math/big"
) )
func newPublicKey(x, y *big.Int) *ecdsa.PublicKey {
if x == nil || y == nil || !elliptic.P256().IsOnCurve(x, y) {
return nil
}
if x.Sign() == 0 && y.Sign() == 0 {
return nil
}
return &ecdsa.PublicKey{Curve: elliptic.P256(), X: x, Y: y}
}
// Verify checks the given signature (r, s) for the given hash and public key (x, y). // Verify checks the given signature (r, s) for the given hash and public key (x, y).
func Verify(hash []byte, r, s, x, y *big.Int) bool { func Verify(hash []byte, r, s, x, y *big.Int) bool {
publicKey := newPublicKey(x, y) if x == nil || y == nil || !elliptic.P256().IsOnCurve(x, y) {
if publicKey == nil {
return false return false
} }
return ecdsa.Verify(publicKey, hash, r, s) pk := &ecdsa.PublicKey{Curve: elliptic.P256(), X: x, Y: y}
return ecdsa.Verify(pk, hash, r, s)
} }