Skip to content
This repository has been archived by the owner on Sep 6, 2022. It is now read-only.

Replace bytes.Equal -> subtle.ConstantTimeCompare #32

Merged
merged 2 commits into from
Jul 12, 2019
Merged

Conversation

bigs
Copy link
Contributor

@bigs bigs commented Jul 10, 2019

Removes reliance on short-circuiting equality comparisons which can be cryptographically unsound.

@bigs bigs requested a review from raulk July 10, 2019 21:34
Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two nits that aren't really an issue.

@@ -131,7 +131,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 !bytes.Equal(pk, redundantPk) {
if subtle.ConstantTimeCompare(pk, redundantPk) != 1 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a public key comparison so we don't need to do this.

@@ -105,7 +105,7 @@ func (k *Ed25519PublicKey) Equals(o Key) bool {
return false
}

return bytes.Equal(k.k, edk.k)
return subtle.ConstantTimeCompare(k.k, edk.k) == 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also a public key comparison.

@bigs
Copy link
Contributor Author

bigs commented Jul 12, 2019

reverted to faster comparisons for pubkeys. going to merge once tests pass.

@bigs bigs merged commit c3f7bb2 into master Jul 12, 2019
@bigs bigs deleted the bug/key-equality branch July 12, 2019 20:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants