elliptic_curve_tools/
sum_of_products.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use elliptic_curve::{ff::PrimeFieldBits, Group};

/// A trait for a group that can compute the sum of products
/// of a slice of group elements and a slice of scalars.
/// The length of the slices must be equal.
pub trait SumOfProducts: Group<Scalar: PrimeFieldBits> {
    /// Compute the sum of products of a slice of group elements and a slice of scalars
    /// as group[0]^field[0] * group[1]^field[1] * ... * group[n]^field[n]
    fn sum_of_products(pairs: &[(Self::Scalar, Self)]) -> Self;
}

#[cfg(any(feature = "alloc", feature = "std"))]
impl<G> SumOfProducts for G
where
    G: Group,
    G::Scalar: PrimeFieldBits + zeroize::Zeroize,
{
    fn sum_of_products(pairs: &[(Self::Scalar, Self)]) -> Self {
        multiexp::multiexp::<Self>(pairs)
    }
}