Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConstantTimeEq and PartialEq for SigningKey #306

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ curve25519-dalek = { version = "=4.0.0-rc.2", default-features = false, features
ed25519 = { version = ">=2.2, <2.3", default-features = false }
signature = { version = ">=2.0, <2.1", optional = true, default-features = false }
sha2 = { version = "0.10", default-features = false }
subtle = { version = "2.3.0", default-features = false }

# optional features
merlin = { version = "3", default-features = false, optional = true }
Expand Down
15 changes: 15 additions & 0 deletions src/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use rand_core::CryptoRngCore;
use serde::{Deserialize, Deserializer, Serialize, Serializer};

use sha2::Sha512;
use subtle::{Choice, ConstantTimeEq};

use curve25519_dalek::{
digest::{generic_array::typenum::U64, Digest},
Expand Down Expand Up @@ -583,6 +584,20 @@ impl TryFrom<&[u8]> for SigningKey {
}
}

impl ConstantTimeEq for SigningKey {
fn ct_eq(&self, other: &Self) -> Choice {
self.secret_key.ct_eq(&other.secret_key)
}
}

impl PartialEq for SigningKey {
fn eq(&self, other: &Self) -> bool {
self.ct_eq(other).into()
}
}

impl Eq for SigningKey {}

#[cfg(feature = "zeroize")]
impl Drop for SigningKey {
fn drop(&mut self) {
Expand Down