Skip to content

Commit 1112e56

Browse files
committed
ConstantTimeEq and PartialEq for SigningKey
1 parent 9b166b7 commit 1112e56

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ curve25519-dalek = { version = "=4.0.0-rc.2", default-features = false, features
2929
ed25519 = { version = ">=2.2, <2.3", default-features = false }
3030
signature = { version = ">=2.0, <2.1", optional = true, default-features = false }
3131
sha2 = { version = "0.10", default-features = false }
32+
subtle = { version = "2.3.0", default-features = false }
3233

3334
# optional features
3435
merlin = { version = "3", default-features = false, optional = true }

src/signing.rs

+15
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use rand_core::CryptoRngCore;
1919
use serde::{Deserialize, Deserializer, Serialize, Serializer};
2020

2121
use sha2::Sha512;
22+
use subtle::{Choice, ConstantTimeEq};
2223

2324
use curve25519_dalek::{
2425
digest::{generic_array::typenum::U64, Digest},
@@ -583,6 +584,20 @@ impl TryFrom<&[u8]> for SigningKey {
583584
}
584585
}
585586

587+
impl ConstantTimeEq for SigningKey {
588+
fn ct_eq(&self, other: &Self) -> Choice {
589+
self.secret_key.ct_eq(&other.secret_key)
590+
}
591+
}
592+
593+
impl PartialEq for SigningKey {
594+
fn eq(&self, other: &Self) -> bool {
595+
self.ct_eq(other).into()
596+
}
597+
}
598+
599+
impl Eq for SigningKey {}
600+
586601
#[cfg(feature = "zeroize")]
587602
impl Drop for SigningKey {
588603
fn drop(&mut self) {

0 commit comments

Comments
 (0)