Commit 963cc997 authored by Steven Allen's avatar Steven Allen

remove non-constant-time private key comparison

parent 9a4415d1
......@@ -4,7 +4,6 @@
package crypto
import (
"bytes"
"crypto/elliptic"
"crypto/hmac"
"crypto/rand"
......@@ -380,5 +379,5 @@ func basicEquals(k1, k2 Key) bool {
if err != nil {
return false
}
return bytes.Equal(a, b)
return subtle.ConstantTimeCompare(a, b) == 1
}
......@@ -108,6 +108,7 @@ func (sk *RsaPrivateKey) Equals(k Key) bool {
a := sk.sk
b := other.sk
// Don't care about constant time. We're only comparing the public half.
if a.PublicKey.N.Cmp(b.PublicKey.N) != 0 {
return false
}
......@@ -115,10 +116,6 @@ func (sk *RsaPrivateKey) Equals(k Key) bool {
return false
}
if a.D.Cmp(b.D) != 0 {
return false
}
return true
}
......
......@@ -69,7 +69,7 @@ func (k *Secp256k1PrivateKey) Equals(o Key) bool {
return basicEquals(k, o)
}
return k.D.Cmp(sk.D) == 0
return k.GetPublic().Equals(sk.GetPublic())
}
// Sign returns a signature from input data
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment