arcium-primitives 0.4.0

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

use super::{CurveKey, GlobalFieldKey};
use crate::{
    algebra::elliptic_curve::{BaseField, Curve, Point, ScalarField},
    sharing::FieldShareKey,
};

pub type GlobalScalarKey<C> = GlobalFieldKey<ScalarField<C>>;
pub type GlobalBaseKey<C> = GlobalFieldKey<BaseField<C>>;

pub type ScalarKey<C> = FieldShareKey<ScalarField<C>>;
pub type BaseKey<C> = FieldShareKey<BaseField<C>>;

// === Curve point multiplication === //

impl<'a, C: Curve> Mul<&'a Point<C>> for &'a ScalarKey<C> {
    type Output = CurveKey<C>;

    #[inline]
    fn mul(self, other: &'a Point<C>) -> Self::Output {
        CurveKey {
            alpha: self.alpha.clone(),
            beta: other * self.beta,
        }
    }
}

impl<'a, C: Curve> Mul<&'a Point<C>> for ScalarKey<C> {
    type Output = CurveKey<C>;

    #[inline]
    fn mul(self, other: &'a Point<C>) -> Self::Output {
        CurveKey {
            alpha: self.alpha,
            beta: other * self.beta,
        }
    }
}

impl<C: Curve> Mul<Point<C>> for &ScalarKey<C> {
    type Output = CurveKey<C>;

    #[inline]
    fn mul(self, other: Point<C>) -> Self::Output {
        CurveKey {
            alpha: self.alpha.clone(),
            beta: other * self.beta,
        }
    }
}

impl<C: Curve> Mul<Point<C>> for ScalarKey<C> {
    type Output = CurveKey<C>;

    #[inline]
    fn mul(self, other: Point<C>) -> Self::Output {
        CurveKey {
            alpha: self.alpha,
            beta: other * self.beta,
        }
    }
}

impl<'a, C: Curve> Mul<&'a ScalarKey<C>> for &'a Point<C> {
    type Output = CurveKey<C>;

    #[inline]
    fn mul(self, other: &'a ScalarKey<C>) -> Self::Output {
        CurveKey {
            alpha: other.alpha.clone(),
            beta: self * other.beta,
        }
    }
}

impl<'a, C: Curve> Mul<&'a ScalarKey<C>> for Point<C> {
    type Output = CurveKey<C>;

    #[inline]
    fn mul(self, other: &'a ScalarKey<C>) -> Self::Output {
        CurveKey {
            alpha: other.alpha.clone(),
            beta: self * other.beta,
        }
    }
}

impl<C: Curve> Mul<ScalarKey<C>> for &Point<C> {
    type Output = CurveKey<C>;

    #[inline]
    fn mul(self, other: ScalarKey<C>) -> Self::Output {
        CurveKey {
            alpha: other.alpha,
            beta: other.beta * self,
        }
    }
}

impl<C: Curve> Mul<ScalarKey<C>> for Point<C> {
    type Output = CurveKey<C>;

    #[inline]
    fn mul(self, other: ScalarKey<C>) -> Self::Output {
        CurveKey {
            alpha: other.alpha,
            beta: self * other.beta,
        }
    }
}