mirror of
https://github.com/libp2p/go-libp2p-core.git
synced 2025-03-11 10:40:07 +08:00
Use short-circuiting comparisons for public keys
This commit is contained in:
parent
2726b6493c
commit
652a852edd
@ -1,6 +1,7 @@
|
||||
package crypto
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/subtle"
|
||||
"errors"
|
||||
"fmt"
|
||||
@ -105,7 +106,7 @@ func (k *Ed25519PublicKey) Equals(o Key) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
return subtle.ConstantTimeCompare(k.k, edk.k) == 1
|
||||
return bytes.Equal(k.k, edk.k)
|
||||
}
|
||||
|
||||
// Verify checks a signature agains the input data.
|
||||
@ -131,7 +132,7 @@ func UnmarshalEd25519PrivateKey(data []byte) (PrivKey, error) {
|
||||
// Remove the redundant public key. See issue #36.
|
||||
redundantPk := data[ed25519.PrivateKeySize:]
|
||||
pk := data[ed25519.PrivateKeySize-ed25519.PublicKeySize : ed25519.PrivateKeySize]
|
||||
if subtle.ConstantTimeCompare(pk, redundantPk) != 1 {
|
||||
if !bytes.Equal(pk, redundantPk) {
|
||||
return nil, errors.New("expected redundant ed25519 public key to be redundant")
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user