crypto: use basicEquals for ECDSA
The check was incomplete as it didn't test the curve. This switches us to use
basicEquals (which is also constant-time).
Note: This key type isn't used by anyone in-practice (to the best of my
knowledge).
@@ -117,14 +117,9 @@ func (ePriv *ECDSAPrivateKey) Raw() ([]byte, error) {
// Equals compares two private keys
func (ePriv *ECDSAPrivateKey) Equals(o Key) bool {
- oPriv, ok := o.(*ECDSAPrivateKey)
- if !ok {
return basicEquals(ePriv, o)
}
- return ePriv.priv.D.Cmp(oPriv.priv.D) == 0
-}
-
// Sign returns the signature of the input data
func (ePriv *ECDSAPrivateKey) Sign(data []byte) ([]byte, error) {
hash := sha256.Sum256(data)
@@ -161,15 +156,9 @@ func (ePub *ECDSAPublicKey) Raw() ([]byte, error) {
// Equals compares to public keys
func (ePub *ECDSAPublicKey) Equals(o Key) bool {
- oPub, ok := o.(*ECDSAPublicKey)
- if !ok {
return basicEquals(ePub, o)
}
- return ePub.pub.X != nil && ePub.pub.Y != nil && oPub.pub.X != nil && oPub.pub.Y != nil &&
- 0 == ePub.pub.X.Cmp(oPub.pub.X) && 0 == ePub.pub.Y.Cmp(oPub.pub.Y)
-}
-
// Verify compares data to a signature
func (ePub *ECDSAPublicKey) Verify(data, sigBytes []byte) (bool, error) {
sig := new(ECDSASig)
