Skip to content

Commit 2d3cfea

Browse files
committed
Revert "feat: add constant-time equality checking"
This reverts commit 004f3da.
1 parent 004f3da commit 2d3cfea

6 files changed

Lines changed: 154 additions & 119 deletions

File tree

Cargo.lock

Lines changed: 143 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ documentation = "https://docs.rs/secure-string/"
1111
edition = "2021"
1212

1313
[dependencies]
14-
libc = "0.2"
15-
zeroize = { version = "1", features = ["std"] }
16-
serde = { version = "1", optional = true }
17-
subtle = "2"
14+
libc = "0.2.148"
15+
zeroize = { version = "1.6.0", features = ["std"] }
16+
serde = { version = "1.0.188", optional = true }
1817

1918
[dev-dependencies]
19+
pre = "0.2.1"
2020
serde_cbor = "0.11"
21-
serde_json = "1"
21+
serde_json = "1.0.105"

src/secure_types/array.rs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::{
44
str::FromStr,
55
};
66

7-
use subtle::ConstantTimeEq;
87
use zeroize::Zeroize;
98

109
use crate::secure_utils::memlock;
@@ -18,7 +17,7 @@ use crate::secure_utils::memlock;
1817
/// - Automatic `madvise(MADV_NOCORE/MADV_DONTDUMP)` to protect against leaking into core dumps (FreeBSD, DragonflyBSD, Linux)
1918
///
2019
/// Comparisons using the `PartialEq` implementation are undefined behavior (and most likely wrong) if `T` has any padding bytes.
21-
#[derive(Eq, PartialOrd, Ord, Hash)]
20+
#[derive(Eq, PartialEq, PartialOrd, Ord, Hash)]
2221
pub struct SecureArray<T, const LENGTH: usize>
2322
where
2423
T: Copy + Zeroize,
@@ -57,29 +56,6 @@ impl<T: Copy + Zeroize, const LENGTH: usize> Clone for SecureArray<T, LENGTH> {
5756
}
5857
}
5958

60-
impl<T, const LENGTH: usize> PartialEq for SecureArray<T, LENGTH>
61-
where
62-
T: Copy + Zeroize,
63-
{
64-
fn eq(&self, other: &Self) -> bool {
65-
let self_bytes = unsafe {
66-
std::slice::from_raw_parts(
67-
self.content.as_ptr() as *const T as *const u8,
68-
LENGTH * std::mem::size_of::<T>(),
69-
)
70-
};
71-
72-
let other_bytes = unsafe {
73-
std::slice::from_raw_parts(
74-
other.content.as_ptr() as *const T as *const u8,
75-
LENGTH * std::mem::size_of::<T>(),
76-
)
77-
};
78-
79-
self_bytes.ct_eq(other_bytes).into()
80-
}
81-
}
82-
8359
// Creation
8460
impl<T, const LENGTH: usize> From<[T; LENGTH]> for SecureArray<T, LENGTH>
8561
where

src/secure_types/boxed.rs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::{
44
mem::MaybeUninit,
55
};
66

7-
use subtle::ConstantTimeEq;
87
use zeroize::Zeroize;
98

109
use crate::secure_utils::memlock;
@@ -18,7 +17,7 @@ use crate::secure_utils::memlock;
1817
/// - Automatic `madvise(MADV_NOCORE/MADV_DONTDUMP)` to protect against leaking into core dumps (FreeBSD, DragonflyBSD, Linux)
1918
///
2019
/// Comparisons using the `PartialEq` implementation are undefined behavior (and most likely wrong) if `T` has any padding bytes.
21-
#[derive(Eq, PartialOrd, Ord, Hash)]
20+
#[derive(Eq, PartialEq, PartialOrd, Ord, Hash)]
2221
pub struct SecureBox<T>
2322
where
2423
T: Copy,
@@ -54,29 +53,6 @@ impl<T: Copy> Clone for SecureBox<T> {
5453
}
5554
}
5655

57-
impl<T> PartialEq for SecureBox<T>
58-
where
59-
T: Copy,
60-
{
61-
fn eq(&self, other: &Self) -> bool {
62-
let self_bytes = unsafe {
63-
std::slice::from_raw_parts(
64-
self.content.as_ref().expect("SecureBox content should always be Some").as_ref() as *const T as *const u8,
65-
std::mem::size_of::<T>(),
66-
)
67-
};
68-
69-
let other_bytes = unsafe {
70-
std::slice::from_raw_parts(
71-
other.content.as_ref().expect("SecureBox content should always be Some").as_ref() as *const T as *const u8,
72-
std::mem::size_of::<T>(),
73-
)
74-
};
75-
76-
self_bytes.ct_eq(other_bytes).into()
77-
}
78-
}
79-
8056
// Delegate indexing
8157
impl<T, U> std::ops::Index<U> for SecureBox<T>
8258
where

0 commit comments

Comments
 (0)