Skip to content

Commit e4518a2

Browse files
committed
sec1: replace subtle with ctutils
This follows upstream changes in the `crypto-bigint` and `elliptic-curve` crates: RustCrypto/traits#2153
1 parent ce4f1da commit e4518a2

3 files changed

Lines changed: 29 additions & 28 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sec1/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ rust-version = "1.85"
1818

1919
[dependencies]
2020
base16ct = { version = "1", optional = true, default-features = false }
21+
ctutils = { version = "0.3", optional = true, default-features = false }
2122
der = { version = "0.8.0-rc.10", optional = true, features = ["oid"] }
2223
hybrid-array = { version = "0.4", optional = true, default-features = false }
2324
serdect = { version = "0.4", optional = true, default-features = false, features = ["alloc"] }
24-
subtle = { version = "2", optional = true, default-features = false }
2525
zeroize = { version = "1", optional = true, default-features = false }
2626

2727
[dev-dependencies]
@@ -37,6 +37,7 @@ der = ["dep:der", "zeroize"]
3737
pem = ["alloc", "der/pem"]
3838
point = ["dep:base16ct", "dep:hybrid-array"]
3939
serde = ["dep:serdect"]
40+
subtle = [] # TODO(tarcieri): remove this when elliptic-curve is updated
4041
zeroize = ["dep:zeroize", "der?/zeroize"]
4142

4243
[package.metadata.docs.rs]

sec1/src/point.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ use hybrid_array::{Array, ArraySize, typenum::U1};
1919
#[cfg(feature = "alloc")]
2020
use alloc::boxed::Box;
2121

22+
#[cfg(feature = "ctutils")]
23+
use ctutils::{Choice, CtSelect};
24+
2225
#[cfg(feature = "serde")]
2326
use serdect::serde::{Deserialize, Serialize, de, ser};
2427

25-
#[cfg(feature = "subtle")]
26-
use subtle::{Choice, ConditionallySelectable};
27-
2828
#[cfg(feature = "zeroize")]
2929
use zeroize::Zeroize;
3030

@@ -254,23 +254,6 @@ where
254254
}
255255
}
256256

257-
#[cfg(feature = "subtle")]
258-
impl<Size> ConditionallySelectable for EncodedPoint<Size>
259-
where
260-
Size: ModulusSize,
261-
<Size::UncompressedPointSize as ArraySize>::ArrayType<u8>: Copy,
262-
{
263-
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self {
264-
let mut bytes = Array::default();
265-
266-
for (i, byte) in bytes.iter_mut().enumerate() {
267-
*byte = u8::conditional_select(&a.bytes[i], &b.bytes[i], choice);
268-
}
269-
270-
Self { bytes }
271-
}
272-
}
273-
274257
impl<Size> Copy for EncodedPoint<Size>
275258
where
276259
Size: ModulusSize,
@@ -392,6 +375,23 @@ where
392375
}
393376
}
394377

378+
// TODO(tarcieri): add `ctutils` support to `hybrid-array`
379+
#[cfg(feature = "ctutils")]
380+
impl<Size> CtSelect for EncodedPoint<Size>
381+
where
382+
Size: ModulusSize,
383+
{
384+
fn ct_select(&self, other: &Self, choice: Choice) -> Self {
385+
let mut bytes = Array::default();
386+
387+
for (i, byte) in bytes.iter_mut().enumerate() {
388+
*byte = self.bytes[i].ct_select(&other.bytes[i], choice);
389+
}
390+
391+
Self { bytes }
392+
}
393+
}
394+
395395
#[cfg(feature = "serde")]
396396
impl<Size> Serialize for EncodedPoint<Size>
397397
where
@@ -565,8 +565,8 @@ mod tests {
565565
#[cfg(feature = "alloc")]
566566
use alloc::string::ToString;
567567

568-
#[cfg(feature = "subtle")]
569-
use subtle::ConditionallySelectable;
568+
#[cfg(feature = "ctutils")]
569+
use ctutils::CtSelect;
570570

571571
type EncodedPoint = super::EncodedPoint<U32>;
572572

@@ -731,16 +731,16 @@ mod tests {
731731
assert_eq!(compressed_point.as_bytes(), &COMPRESSED_BYTES[..]);
732732
}
733733

734-
#[cfg(feature = "subtle")]
734+
#[cfg(feature = "ctutils")]
735735
#[test]
736-
fn conditional_select() {
736+
fn ct_select() {
737737
let a = EncodedPoint::from_bytes(&COMPRESSED_BYTES[..]).unwrap();
738738
let b = EncodedPoint::from_bytes(&UNCOMPRESSED_BYTES[..]).unwrap();
739739

740-
let a_selected = EncodedPoint::conditional_select(&a, &b, 0.into());
740+
let a_selected = EncodedPoint::ct_select(&a, &b, 0.into());
741741
assert_eq!(a, a_selected);
742742

743-
let b_selected = EncodedPoint::conditional_select(&a, &b, 1.into());
743+
let b_selected = EncodedPoint::ct_select(&a, &b, 1.into());
744744
assert_eq!(b, b_selected);
745745
}
746746

0 commit comments

Comments
 (0)