From 7e8a0adede9ad6413152e919afcdc5551563a2db Mon Sep 17 00:00:00 2001 From: Danny McClanahan <1305167+cosmicexplorer@users.noreply.github.com> Date: Sat, 31 Dec 2022 23:29:48 -0500 Subject: [PATCH] [TODO: use ConditionallySelectable for IteratedGreater!] save --- src/lib.rs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 46e60a9..b134054 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -871,7 +871,7 @@ pub trait ConstantTimeGreater { /// ///``` /// use subtle::{ -/// Choice, IteratedOperation, ConstantTimeEq, IteratedEq, ConstantTimeGreater, IteratedGreater, +/// Choice, IteratedOperation, ConstantTimeEq, IteratedEq, ConstantTimeGreater, LexicographicIteratedGreater, /// }; /// /// struct S { pub len: usize, pub live: bool }; @@ -885,7 +885,7 @@ pub trait ConstantTimeGreater { /// } /// impl ConstantTimeGreater for S { /// fn ct_gt(&self, other: &Self) -> Choice { -/// let mut x = IteratedGreater::initiate(); +/// let mut x = LexicographicIteratedGreater::initiate(); /// x.apply_gt(&(self.len as u64), &(other.len as u64)); /// x.apply_gt(&(self.live as u8), &(other.live as u8)); /// x.extract_result() @@ -900,16 +900,16 @@ pub trait ConstantTimeGreater { /// assert_eq!(1, s2.ct_gt(&s1).unwrap_u8()); /// assert_eq!(1, s3.ct_gt(&s2).unwrap_u8()); ///``` -pub struct IteratedGreater { +pub struct LexicographicIteratedGreater { was_gt: Choice, was_lt: Choice, } -impl IteratedOperation for IteratedGreater { +impl IteratedOperation for LexicographicIteratedGreater { fn initiate() -> Self { Self { - was_gt: Choice::from(0), - was_lt: Choice::from(0), + was_gt: Choice::of_bool(false), + was_lt: Choice::of_bool(false), } } fn extract_result(self) -> Choice { @@ -917,7 +917,7 @@ impl IteratedOperation for IteratedGreater { } } -impl IteratedGreater { +impl LexicographicIteratedGreater { /// Unconditionally modify internal state with result of two directed "greater" comparisons. #[inline] pub fn apply_gt(&mut self, a: &T, b: &T) { @@ -1022,7 +1022,7 @@ impl ConstantTimeGreater for [T] { } } - let mut x = IteratedGreater::initiate(); + let mut x = LexicographicIteratedGreater::initiate(); for (ai, bi) in self.iter().zip(_rhs.iter()) { x.apply_gt(ai, bi); } @@ -1077,8 +1077,8 @@ pub trait ConstantTimeLess: ConstantTimeGreater { /// ///``` /// use subtle::{ -/// Choice, IteratedOperation, ConstantTimeEq, IteratedEq, ConstantTimeGreater, IteratedGreater, -/// ConstantTimeLess, IteratedLess, +/// Choice, IteratedOperation, ConstantTimeEq, IteratedEq, ConstantTimeGreater, LexicographicIteratedGreater, +/// ConstantTimeLess, LexicographicIteratedLess, /// }; /// /// struct S { pub len: usize, pub live: bool }; @@ -1092,7 +1092,7 @@ pub trait ConstantTimeLess: ConstantTimeGreater { /// } /// impl ConstantTimeGreater for S { /// fn ct_gt(&self, other: &Self) -> Choice { -/// let mut x = IteratedGreater::initiate(); +/// let mut x = LexicographicIteratedGreater::initiate(); /// x.apply_gt(&(self.len as u64), &(other.len as u64)); /// x.apply_gt(&(self.live as u8), &(other.live as u8)); /// x.extract_result() @@ -1100,7 +1100,7 @@ pub trait ConstantTimeLess: ConstantTimeGreater { /// } /// impl ConstantTimeLess for S { /// fn ct_lt(&self, other: &Self) -> Choice { -/// let mut x = IteratedLess::initiate(); +/// let mut x = LexicographicIteratedLess::initiate(); /// x.apply_lt(&(self.len as u64), &(other.len as u64)); /// x.apply_lt(&(self.live as u8), &(other.live as u8)); /// x.extract_result() @@ -1115,16 +1115,16 @@ pub trait ConstantTimeLess: ConstantTimeGreater { /// assert_eq!(1, s2.ct_gt(&s1).unwrap_u8()); /// assert_eq!(1, s2.ct_lt(&s3).unwrap_u8()); ///``` -pub struct IteratedLess { +pub struct LexicographicIteratedLess { was_lt: Choice, was_gt: Choice, } -impl IteratedOperation for IteratedLess { +impl IteratedOperation for LexicographicIteratedLess { fn initiate() -> Self { Self { - was_lt: Choice::from(0), - was_gt: Choice::from(0), + was_lt: Choice::of_bool(false), + was_gt: Choice::of_bool(false), } } fn extract_result(self) -> Choice { @@ -1132,7 +1132,7 @@ impl IteratedOperation for IteratedLess { } } -impl IteratedLess { +impl LexicographicIteratedLess { /// Unconditionally modify internal state with result of two directed "less" comparisons. #[inline] pub fn apply_lt(&mut self, a: &T, b: &T) {