arcium-primitives 0.4.1

Arcium primitives
Documentation
use std::ops::Mul;

use crate::{
    algebra::elliptic_curve::{BaseField, Curve, Point, ScalarField},
    sharing::{FieldShares, OpenFieldShares, PointShares},
    types::{heap_array::curve_arrays::CurvePoints, Positive},
};

// === Scalar shares === //

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>;

// === CurvePoint(s) x ScalarShares === //

#[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(),
        }
    }
}

// --- One-to-many multiplication --- //

#[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(),
        }
    }
}

// --- ScalarShares x CurvePoint(s) --- //

#[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(),
        }
    }
}

// --- One-to-many multiplication --- //

#[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(),
        }
    }
}