Skip to content

Commit 1c4e190

Browse files
committed
elliptic-curve: add vartime BatchInvert/BatchNormalize methods
Adds the following: - `BatchInvert::batch_invert_in_place_vartime` - `BatchNormalize::batch_normalize_vartime` Both are provided methods that currently call the constant-time path, but in the future we can potentially provide default implementations that are variable-time and optimized. Since the new methods are provided, this isn't a breaking change.
1 parent ab8ee23 commit 1c4e190

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

elliptic-curve/src/ops.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ pub trait BatchInvert: Field {
2929
fn batch_invert_in_place(elements: &mut [Self], scratch_space: &mut [Self]) -> Self {
3030
BatchInverter::invert_with_external_scratch(elements, scratch_space)
3131
}
32+
33+
/// Variable-time batch inversion.
34+
///
35+
/// <div class="warning">
36+
/// <b>Security Warning</b>
37+
///
38+
/// This should NOT be used on secret values!
39+
/// </b>
40+
fn batch_invert_in_place_vartime(elements: &mut [Self], scratch_space: &mut [Self]) -> Self {
41+
// Call the constant-time implementation by default
42+
Self::batch_invert_in_place(elements, scratch_space)
43+
}
3244
}
3345

3446
/// Perform a doubling (i.e. `self + self`).

elliptic-curve/src/point.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,20 @@ pub trait BatchNormalize<Points: ?Sized> {
5151
/// Perform a batched conversion to affine representation on a sequence of projective points
5252
/// at an amortized cost that should be practically as efficient as a single conversion.
5353
/// Internally, implementors should rely upon `InvertBatch`.
54-
fn batch_normalize(points: &Points) -> <Self as BatchNormalize<Points>>::Output;
54+
fn batch_normalize(points: &Points) -> Self::Output;
55+
56+
/// Perform a batched conversion to affine representation on a sequence of projective points
57+
/// in variable-time.
58+
///
59+
/// <div class="warning">
60+
/// <b>Security Warning</b>
61+
///
62+
/// This should NOT be used on points which represent secrets!
63+
/// </b>
64+
fn batch_normalize_vartime(points: &Points) -> Self::Output {
65+
// Call the constant-time implementation by default
66+
Self::batch_normalize(points)
67+
}
5568
}
5669

5770
/// Decompress an elliptic curve point.

0 commit comments

Comments
 (0)