arcium-primitives 0.4.1

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

use crate::{
    algebra::elliptic_curve::{BaseField, Curve, Point, ScalarField},
    sharing::{CurveKeys, FieldShareKeys},
    types::{heap_array::curve_arrays::CurvePoints, Positive},
};

pub type ScalarKeys<C, M> = FieldShareKeys<ScalarField<C>, M>;
pub type BaseKeys<C, M> = FieldShareKeys<BaseField<C>, M>;

// === ScalarKeys x CurvePoint(s) === //

#[macros::op_variants(owned, borrowed, flipped)]
impl<'a, C: Curve, M: Positive> Mul<&'a CurvePoints<C, M>> for ScalarKeys<C, M> {
    type Output = CurveKeys<C, M>;

    #[inline]
    fn mul(self, other: &'a CurvePoints<C, M>) -> Self::Output {
        CurveKeys {
            alpha: self.alpha.clone(),
            betas: self.betas * other,
        }
    }
}

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

#[macros::op_variants(owned, borrowed, flipped)]
impl<'a, C: Curve, M: Positive> Mul<&'a Point<C>> for ScalarKeys<C, M> {
    type Output = CurveKeys<C, M>;

    #[inline]
    fn mul(self, other: &'a Point<C>) -> CurveKeys<C, M> {
        CurveKeys {
            alpha: self.alpha,
            betas: self.betas * other,
        }
    }
}

// --- CurvePoints x ScalarKey(s) --- //

#[macros::op_variants(owned, borrowed, flipped)]
impl<'a, C: Curve, M: Positive> Mul<&'a ScalarKeys<C, M>> for CurvePoints<C, M> {
    type Output = CurveKeys<C, M>;

    #[inline]
    fn mul(self, other: &'a ScalarKeys<C, M>) -> CurveKeys<C, M> {
        CurveKeys {
            alpha: other.alpha.clone(),
            betas: self * &other.betas,
        }
    }
}

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

#[macros::op_variants(owned, borrowed, flipped)]
impl<'a, C: Curve, M: Positive> Mul<&'a ScalarKeys<C, M>> for Point<C> {
    type Output = CurveKeys<C, M>;

    #[inline]
    fn mul(self, other: &'a ScalarKeys<C, M>) -> CurveKeys<C, M> {
        CurveKeys {
            alpha: other.alpha.clone(),
            betas: &other.betas * self,
        }
    }
}