use std::ops::Mul;
use crate::{
algebra::elliptic_curve::{BaseField, Curve, Point, ScalarField},
sharing::{FieldShares, OpenFieldShares, PointShares},
types::{heap_array::curve_arrays::CurvePoints, Positive},
};
pub type OpenScalarShares<C, M> = OpenFieldShares<ScalarField<C>, M>;
pub type OpenBaseFieldShares<C, M> = OpenFieldShares<BaseField<C>, M>;
pub type ScalarShares<C, M> = FieldShares<ScalarField<C>, M>;
pub type BaseFieldShares<C, M> = FieldShares<BaseField<C>, M>;
#[macros::op_variants(owned, borrowed, flipped)]
impl<'a, C: Curve, M: Positive> Mul<&'a CurvePoints<C, M>> for ScalarShares<C, M> {
type Output = PointShares<C, M>;
#[inline]
fn mul(self, other: &'a CurvePoints<C, M>) -> Self::Output {
PointShares {
value: self.value * other,
macs: self.macs.iter().map(|mac| mac * other).collect(),
keys: self.keys.iter().map(|key| key * other).collect(),
}
}
}
#[macros::op_variants(owned, borrowed, flipped)]
impl<'a, C: Curve, M: Positive> Mul<&'a Point<C>> for ScalarShares<C, M> {
type Output = PointShares<C, M>;
#[inline]
fn mul(self, other: &'a Point<C>) -> Self::Output {
PointShares {
value: self.value * other,
macs: self.macs.iter().map(|mac| mac * other).collect(),
keys: self.keys.iter().map(|key| key * other).collect(),
}
}
}
#[macros::op_variants(owned, borrowed, flipped)]
impl<'a, C: Curve, M: Positive> Mul<&'a ScalarShares<C, M>> for CurvePoints<C, M> {
type Output = PointShares<C, M>;
#[inline]
fn mul(self, other: &'a ScalarShares<C, M>) -> Self::Output {
PointShares {
value: &other.value * &self,
macs: other.macs.iter().map(|mac| mac * &self).collect(),
keys: other.keys.iter().map(|key| key * &self).collect(),
}
}
}
#[macros::op_variants(owned, borrowed, flipped)]
impl<'a, C: Curve, M: Positive> Mul<&'a ScalarShares<C, M>> for Point<C> {
type Output = PointShares<C, M>;
#[inline]
fn mul(self, other: &'a ScalarShares<C, M>) -> Self::Output {
PointShares {
value: &other.value * self,
macs: other.macs.iter().map(|mac| mac * self).collect(),
keys: other.keys.iter().map(|key| key * self).collect(),
}
}
}