pub trait BatchInvert: Field {
// Provided methods
fn batch_invert_in_place(
elements: &mut [Self],
scratch_space: &mut [Self],
) -> Self { ... }
fn batch_invert_in_place_vartime(
elements: &mut [Self],
scratch_space: &mut [Self],
) -> Self { ... }
}Expand description
Perform a batched inversion on a slice of field elements (i.e. base field elements or scalars)
at an amortized cost that should be practically as efficient as a single inversion, writing
the field element inversions into element, and utilizing scratch as temporary storage.
Note: the ff crate also provides ff::BatchInvert, however that trait has a hard
requirement on alloc whereas this one is always available, even in no_alloc contexts.
§Panics
If elements and scratch are not the same length.
Provided Methods§
Sourcefn batch_invert_in_place(
elements: &mut [Self],
scratch_space: &mut [Self],
) -> Self
fn batch_invert_in_place( elements: &mut [Self], scratch_space: &mut [Self], ) -> Self
Inverts each field element in elements (when non-zero). Zero-valued elements are
left as zero.
scratch_space is a slice of field elements that can be freely overwritten.
Returns the inverse of the product of all non-zero field elements.
§Panics
If elements.len() != scratch_space.len().
Sourcefn batch_invert_in_place_vartime(
elements: &mut [Self],
scratch_space: &mut [Self],
) -> Self
fn batch_invert_in_place_vartime( elements: &mut [Self], scratch_space: &mut [Self], ) -> Self
Variable-time batch inversion.
This should NOT be used on secret values!
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.