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

k256: impl Eq/PartialEq/ConstantTimeEq for SigningKey #359

Merged
merged 1 commit into from
Jun 14, 2021
Merged
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
4 changes: 2 additions & 2 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion k256/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ keywords = ["bitcoin", "crypto", "ecc", "ethereum", "secp256k1"]

[dependencies]
cfg-if = "1.0"
elliptic-curve = { version = "0.10", default-features = false, features = ["hazmat"] }
elliptic-curve = { version = "0.10.2", default-features = false, features = ["hazmat"] }

# optional dependencies
hex-literal = { version = "0.3", optional = true }
Expand Down
15 changes: 15 additions & 0 deletions k256/src/ecdsa/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use elliptic_curve::{
consts::U32,
ops::Invert,
rand_core::{CryptoRng, RngCore},
subtle::{Choice, ConstantTimeEq},
};

#[cfg(any(feature = "keccak256", feature = "sha256"))]
Expand Down Expand Up @@ -189,13 +190,27 @@ impl RecoverableSignPrimitive<Secp256k1> for Scalar {
}
}

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

impl Debug for SigningKey {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// TODO(tarcieri): use `finish_non_exhaustive` when stable
f.debug_tuple("SigningKey").field(&"...").finish()
}
}

impl Eq for SigningKey {}

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

impl From<SecretKey> for SigningKey {
fn from(secret_key: SecretKey) -> SigningKey {
Self::from(&secret_key)
Expand Down