primitives/sharing/authenticated/
scalar_key.rs

1use std::ops::Mul;
2
3use super::{CurveKey, GlobalFieldKey};
4use crate::{
5    algebra::elliptic_curve::{BaseField, Curve, Point, ScalarField},
6    sharing::FieldShareKey,
7};
8
9pub type GlobalScalarKey<C> = GlobalFieldKey<ScalarField<C>>;
10pub type GlobalBaseKey<C> = GlobalFieldKey<BaseField<C>>;
11
12pub type ScalarKey<C> = FieldShareKey<ScalarField<C>>;
13pub type BaseKey<C> = FieldShareKey<BaseField<C>>;
14
15// === Curve point multiplication === //
16
17impl<'a, C: Curve> Mul<&'a Point<C>> for &'a ScalarKey<C> {
18    type Output = CurveKey<C>;
19
20    #[inline]
21    fn mul(self, other: &'a Point<C>) -> Self::Output {
22        CurveKey {
23            alpha: self.alpha.clone(),
24            beta: other * self.beta,
25        }
26    }
27}
28
29impl<'a, C: Curve> Mul<&'a Point<C>> for ScalarKey<C> {
30    type Output = CurveKey<C>;
31
32    #[inline]
33    fn mul(self, other: &'a Point<C>) -> Self::Output {
34        CurveKey {
35            alpha: self.alpha,
36            beta: other * self.beta,
37        }
38    }
39}
40
41impl<C: Curve> Mul<Point<C>> for &ScalarKey<C> {
42    type Output = CurveKey<C>;
43
44    #[inline]
45    fn mul(self, other: Point<C>) -> Self::Output {
46        CurveKey {
47            alpha: self.alpha.clone(),
48            beta: other * self.beta,
49        }
50    }
51}
52
53impl<C: Curve> Mul<Point<C>> for ScalarKey<C> {
54    type Output = CurveKey<C>;
55
56    #[inline]
57    fn mul(self, other: Point<C>) -> Self::Output {
58        CurveKey {
59            alpha: self.alpha,
60            beta: other * self.beta,
61        }
62    }
63}
64
65impl<'a, C: Curve> Mul<&'a ScalarKey<C>> for &'a Point<C> {
66    type Output = CurveKey<C>;
67
68    #[inline]
69    fn mul(self, other: &'a ScalarKey<C>) -> Self::Output {
70        CurveKey {
71            alpha: other.alpha.clone(),
72            beta: self * other.beta,
73        }
74    }
75}
76
77impl<'a, C: Curve> Mul<&'a ScalarKey<C>> for Point<C> {
78    type Output = CurveKey<C>;
79
80    #[inline]
81    fn mul(self, other: &'a ScalarKey<C>) -> Self::Output {
82        CurveKey {
83            alpha: other.alpha.clone(),
84            beta: self * other.beta,
85        }
86    }
87}
88
89impl<C: Curve> Mul<ScalarKey<C>> for &Point<C> {
90    type Output = CurveKey<C>;
91
92    #[inline]
93    fn mul(self, other: ScalarKey<C>) -> Self::Output {
94        CurveKey {
95            alpha: other.alpha,
96            beta: other.beta * self,
97        }
98    }
99}
100
101impl<C: Curve> Mul<ScalarKey<C>> for Point<C> {
102    type Output = CurveKey<C>;
103
104    #[inline]
105    fn mul(self, other: ScalarKey<C>) -> Self::Output {
106        CurveKey {
107            alpha: other.alpha,
108            beta: self * other.beta,
109        }
110    }
111}