|
1 | 1 | //! [`BoxedUint`] bitwise right shift operations.
|
2 | 2 |
|
3 |
| -use crate::{BoxedUint, ConstChoice, ConstantTimeSelect, Limb, WrappingShr, Zero}; |
| 3 | +use crate::{BoxedUint, ConstantTimeSelect, Limb, WrappingShr, Zero}; |
4 | 4 | use core::ops::{Shr, ShrAssign};
|
5 | 5 | use subtle::{Choice, ConstantTimeLess};
|
6 | 6 |
|
@@ -115,24 +115,6 @@ impl BoxedUint {
|
115 | 115 | Some(())
|
116 | 116 | }
|
117 | 117 |
|
118 |
| - /// Computes `self >> shift`. |
119 |
| - /// Returns `None` if `shift >= self.bits_precision()`. |
120 |
| - /// |
121 |
| - /// NOTE: this operation is variable time with respect to `shift` *ONLY*. |
122 |
| - /// |
123 |
| - /// When used with a fixed `shift`, this function is constant-time with respect to `self`. |
124 |
| - #[inline(always)] |
125 |
| - pub fn shr_vartime(&self, shift: u32) -> (Self, ConstChoice) { |
126 |
| - let mut result = Self::zero_with_precision(self.bits_precision()); |
127 |
| - let success = self.shr_vartime_into(&mut result, shift); |
128 |
| - // TODO: is this okay? |
129 |
| - ( |
130 |
| - result, |
131 |
| - // If success, then return ConstChoice::False since it's not overflowing |
132 |
| - success.map_or(ConstChoice::TRUE, |_| ConstChoice::FALSE), |
133 |
| - ) |
134 |
| - } |
135 |
| - |
136 | 118 | /// Computes `self >> 1` in constant-time, returning a true [`Choice`]
|
137 | 119 | /// if the least significant bit was set, and a false [`Choice::FALSE`] otherwise.
|
138 | 120 | pub(crate) fn shr1_with_carry(&self) -> (Self, Choice) {
|
@@ -221,9 +203,9 @@ mod tests {
|
221 | 203 | #[test]
|
222 | 204 | fn shr_vartime() {
|
223 | 205 | let n = BoxedUint::from(0x80000000000000000u128);
|
224 |
| - assert_eq!(BoxedUint::zero(), n.shr_vartime(68).0); |
225 |
| - assert_eq!(BoxedUint::one(), n.shr_vartime(67).0); |
226 |
| - assert_eq!(BoxedUint::from(2u8), n.shr_vartime(66).0); |
227 |
| - assert_eq!(BoxedUint::from(4u8), n.shr_vartime(65).0); |
| 206 | + assert_eq!(BoxedUint::zero(), n.overflowing_shr(68).0); |
| 207 | + assert_eq!(BoxedUint::one(), n.overflowing_shr(67).0); |
| 208 | + assert_eq!(BoxedUint::from(2u8), n.overflowing_shr(66).0); |
| 209 | + assert_eq!(BoxedUint::from(4u8), n.overflowing_shr(65).0); |
228 | 210 | }
|
229 | 211 | }
|
0 commit comments