|
1 | 1 | // -*- mode: rust; -*- |
2 | 2 | // |
3 | 3 | // This file is part of subtle, part of the dalek cryptography project. |
4 | | -// Copyright (c) 2016-2022 isis lovecruft, Henry de Valence |
| 4 | +// Copyright (c) 2016-2023 isis lovecruft, Henry de Valence |
5 | 5 | // See LICENSE for licensing information. |
6 | 6 | // |
7 | 7 | // Authors: |
@@ -254,30 +254,6 @@ pub trait IteratedOperation { |
254 | 254 | fn extract_result(self) -> Choice; |
255 | 255 | } |
256 | 256 |
|
257 | | -/// Implementing this trait automatically implements [`ConstantTimeEq`] and/or |
258 | | -/// [`ConstantTimeGreater`], depending on [`Self::To`]. |
259 | | -/// |
260 | | -///``` |
261 | | -/// use subtle::{ConstantTimeEq, ConstantTimeGreater, Convertible}; |
262 | | -/// |
263 | | -/// struct S(pub u8); |
264 | | -/// impl Convertible for S { |
265 | | -/// type To = u8; |
266 | | -/// fn for_constant_operation(&self) -> u8 { self.0 } |
267 | | -/// } |
268 | | -/// |
269 | | -/// assert_eq!(0, S(0).ct_eq(&S(1)).unwrap_u8()); |
270 | | -/// assert_eq!(1, S(1).ct_eq(&S(1)).unwrap_u8()); |
271 | | -/// assert_eq!(1, S(1).ct_gt(&S(0)).unwrap_u8()); |
272 | | -/// assert_eq!(0, S(1).ct_gt(&S(1)).unwrap_u8()); |
273 | | -///``` |
274 | | -pub trait Convertible { |
275 | | - /// The type to convert to. |
276 | | - type To; |
277 | | - /// Convert to a constant-time comparable object. |
278 | | - fn for_constant_operation(&self) -> Self::To; |
279 | | -} |
280 | | - |
281 | 257 | /// An `Eq`-like trait that produces a `Choice` instead of a `bool`. |
282 | 258 | /// |
283 | 259 | /// # Example |
@@ -350,15 +326,6 @@ impl IteratedEq { |
350 | 326 | } |
351 | 327 | } |
352 | 328 |
|
353 | | -impl<T: ConstantTimeEq, C: Convertible<To = T>> ConstantTimeEq for C { |
354 | | - #[inline] |
355 | | - fn ct_eq(&self, other: &Self) -> Choice { |
356 | | - let a: T = self.for_constant_operation(); |
357 | | - let b: T = other.for_constant_operation(); |
358 | | - a.ct_eq(&b) |
359 | | - } |
360 | | -} |
361 | | - |
362 | 329 | impl<T: ConstantTimeEq> ConstantTimeEq for [T] { |
363 | 330 | /// Check whether two slices of `ConstantTimeEq` types are equal. |
364 | 331 | /// |
@@ -927,15 +894,6 @@ impl LexicographicIteratedGreater { |
927 | 894 | } |
928 | 895 | } |
929 | 896 |
|
930 | | -impl<T: ConstantTimeGreater, C: Convertible<To = T>> ConstantTimeGreater for C { |
931 | | - #[inline] |
932 | | - fn ct_gt(&self, other: &Self) -> Choice { |
933 | | - let a: T = self.for_constant_operation(); |
934 | | - let b: T = other.for_constant_operation(); |
935 | | - a.ct_gt(&b) |
936 | | - } |
937 | | -} |
938 | | - |
939 | 897 | macro_rules! generate_unsigned_integer_greater { |
940 | 898 | ($t_u: ty, $bit_width: expr) => { |
941 | 899 | impl ConstantTimeGreater for $t_u { |
@@ -1141,12 +1099,3 @@ impl LexicographicIteratedLess { |
1141 | 1099 | *was_gt |= b.ct_lt(&a); |
1142 | 1100 | } |
1143 | 1101 | } |
1144 | | - |
1145 | | -impl<T: ConstantTimeLess, C: Convertible<To = T>> ConstantTimeLess for C { |
1146 | | - #[inline] |
1147 | | - fn ct_lt(&self, other: &Self) -> Choice { |
1148 | | - let a: T = self.for_constant_operation(); |
1149 | | - let b: T = other.for_constant_operation(); |
1150 | | - a.ct_lt(&b) |
1151 | | - } |
1152 | | -} |
0 commit comments