Skip to content

Commit 24562ae

Browse files
committed
elliptic-curve: remove generic invert_vartime implementation
It's mathematically unsafe in that it relies on field element representations outside the curve's modulus, which doesn't work in a generic context. The newly added `Invert::invert_vartime` method allows plugging in generic variable-time inversions.
1 parent d19d50f commit 24562ae

File tree

4 files changed

+5
-88
lines changed

4 files changed

+5
-88
lines changed

elliptic-curve/src/scalar.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
#[cfg(feature = "arithmetic")]
44
mod blinded;
55
#[cfg(feature = "arithmetic")]
6-
mod invert;
7-
#[cfg(feature = "arithmetic")]
86
mod nonzero;
97
mod primitive;
108

119
pub use self::primitive::ScalarPrimitive;
1210
#[cfg(feature = "arithmetic")]
13-
pub use self::{blinded::BlindedScalar, invert::invert_vartime, nonzero::NonZeroScalar};
11+
pub use self::{blinded::BlindedScalar, nonzero::NonZeroScalar};
1412

1513
use crypto_bigint::Integer;
1614
use subtle::Choice;

elliptic-curve/src/scalar/blinded.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Random blinding support for [`Scalar`]
22
3-
use super::{invert_vartime, Scalar};
3+
use super::Scalar;
44
use crate::{ops::Invert, CurveArithmetic};
55
use group::ff::Field;
66
use rand_core::CryptoRngCore;
@@ -57,8 +57,9 @@ where
5757
fn invert(&self) -> CtOption<Scalar<C>> {
5858
// prevent side channel analysis of scalar inversion by pre-and-post-multiplying
5959
// with the random masking scalar
60-
let masked_scalar = self.scalar * self.mask;
61-
invert_vartime::<C>(&masked_scalar).map(|s| s * self.mask)
60+
(self.scalar * self.mask)
61+
.invert_vartime()
62+
.map(|s| s * self.mask)
6263
}
6364
}
6465

elliptic-curve/src/scalar/invert.rs

Lines changed: 0 additions & 69 deletions
This file was deleted.

elliptic-curve/src/scalar/nonzero.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,6 @@ where
6767
pub fn from_uint(uint: C::Uint) -> CtOption<Self> {
6868
ScalarPrimitive::new(uint).and_then(|scalar| Self::new(scalar.into()))
6969
}
70-
71-
/// Perform an inversion in variable-time.
72-
///
73-
/// ⚠️ WARNING!
74-
///
75-
/// This method should not be used with (unblinded) secret scalars, as its
76-
/// variable-time operation can potentially leak secrets through
77-
/// sidechannels.
78-
pub fn invert_vartime(&self) -> Self {
79-
Self {
80-
scalar: super::invert_vartime::<C>(&self.scalar).unwrap(),
81-
}
82-
}
8370
}
8471

8572
impl<C> AsRef<Scalar<C>> for NonZeroScalar<C>

0 commit comments

Comments
 (0)