arcium-primitives 0.4.0

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

use super::{FieldShare, OpenFieldShare, PointShare};
use crate::algebra::{
    elliptic_curve::{BaseField, Curve, Point, ScalarField},
    field::binary::Gf2_128,
};

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

pub type OpenScalarShare<C> = OpenFieldShare<ScalarField<C>>;
pub type OpenBaseFieldShare<C> = OpenFieldShare<BaseField<C>>;
pub type OpenBitShare = OpenFieldShare<Gf2_128>;

pub type ScalarShare<C> = FieldShare<ScalarField<C>>;
pub type BaseFieldShare<C> = FieldShare<BaseField<C>>;
pub type BitShare = FieldShare<Gf2_128>;

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

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

    #[inline]
    fn mul(self, other: &'a Point<C>) -> PointShare<C> {
        PointShare {
            value: self.value * other,
            keys: self.keys.iter().map(|key| key * other).collect(),
            macs: self.macs.iter().map(|mac| mac * other).collect(),
        }
    }
}

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

    #[inline]
    fn mul(self, other: &'a ScalarShare<C>) -> PointShare<C> {
        PointShare {
            value: other.value * self,
            macs: other.macs.iter().map(|mac| mac * self).collect(),
            keys: other.keys.iter().map(|key| key * self).collect(),
        }
    }
}