primitives/sharing/authenticated/batched/
scalar_keys.rs

1use std::ops::Mul;
2
3use crate::{
4    algebra::elliptic_curve::{BaseField, Curve, Point, ScalarField},
5    sharing::{CurveKeys, FieldShareKeys},
6    types::{heap_array::curve_arrays::CurvePoints, Positive},
7};
8
9pub type ScalarKeys<C, M> = FieldShareKeys<ScalarField<C>, M>;
10pub type BaseKeys<C, M> = FieldShareKeys<BaseField<C>, M>;
11
12// === ScalarKeys x CurvePoint(s) === //
13
14impl<C: Curve, M: Positive> Mul<CurvePoints<C, M>> for ScalarKeys<C, M> {
15    type Output = CurveKeys<C, M>;
16
17    #[inline]
18    fn mul(self, other: CurvePoints<C, M>) -> Self::Output {
19        CurveKeys {
20            alpha: self.alpha.clone(),
21            betas: self.betas * other,
22        }
23    }
24}
25
26impl<'a, C: Curve, M: Positive> Mul<&'a CurvePoints<C, M>> for &'a ScalarKeys<C, M> {
27    type Output = CurveKeys<C, M>;
28
29    #[inline]
30    fn mul(self, other: &'a CurvePoints<C, M>) -> Self::Output {
31        CurveKeys {
32            alpha: self.alpha.clone(),
33            betas: &self.betas * other,
34        }
35    }
36}
37
38impl<'a, C: Curve, M: Positive> Mul<&'a CurvePoints<C, M>> for ScalarKeys<C, M> {
39    type Output = CurveKeys<C, M>;
40
41    #[inline]
42    fn mul(self, other: &'a CurvePoints<C, M>) -> Self::Output {
43        CurveKeys {
44            alpha: self.alpha.clone(),
45            betas: self.betas * other,
46        }
47    }
48}
49
50impl<C: Curve, M: Positive> Mul<CurvePoints<C, M>> for &ScalarKeys<C, M> {
51    type Output = CurveKeys<C, M>;
52
53    #[inline]
54    fn mul(self, other: CurvePoints<C, M>) -> Self::Output {
55        CurveKeys {
56            alpha: self.alpha.clone(),
57            betas: &self.betas * other,
58        }
59    }
60}
61
62// --- One-to-many multiplication --- //
63
64impl<C: Curve, M: Positive> Mul<Point<C>> for ScalarKeys<C, M> {
65    type Output = CurveKeys<C, M>;
66
67    #[inline]
68    fn mul(self, other: Point<C>) -> CurveKeys<C, M> {
69        CurveKeys {
70            alpha: self.alpha,
71            betas: self.betas * other,
72        }
73    }
74}
75
76impl<'a, C: Curve, M: Positive> Mul<&'a Point<C>> for &'a ScalarKeys<C, M> {
77    type Output = CurveKeys<C, M>;
78
79    #[inline]
80    fn mul(self, other: &'a Point<C>) -> CurveKeys<C, M> {
81        CurveKeys {
82            alpha: self.alpha.clone(),
83            betas: &self.betas * other,
84        }
85    }
86}
87
88impl<'a, C: Curve, M: Positive> Mul<&'a Point<C>> for ScalarKeys<C, M> {
89    type Output = CurveKeys<C, M>;
90
91    #[inline]
92    fn mul(self, other: &'a Point<C>) -> CurveKeys<C, M> {
93        CurveKeys {
94            alpha: self.alpha,
95            betas: self.betas * other,
96        }
97    }
98}
99
100impl<C: Curve, M: Positive> Mul<Point<C>> for &ScalarKeys<C, M> {
101    type Output = CurveKeys<C, M>;
102
103    #[inline]
104    fn mul(self, other: Point<C>) -> CurveKeys<C, M> {
105        CurveKeys {
106            alpha: self.alpha.clone(),
107            betas: &self.betas * other,
108        }
109    }
110}
111
112// --- CurvePoints x ScalarKey(s) --- //
113
114impl<C: Curve, M: Positive> Mul<ScalarKeys<C, M>> for CurvePoints<C, M> {
115    type Output = CurveKeys<C, M>;
116
117    #[inline]
118    fn mul(self, other: ScalarKeys<C, M>) -> CurveKeys<C, M> {
119        CurveKeys {
120            alpha: other.alpha,
121            betas: self * other.betas,
122        }
123    }
124}
125
126impl<'a, C: Curve, M: Positive> Mul<&'a ScalarKeys<C, M>> for &'a CurvePoints<C, M> {
127    type Output = CurveKeys<C, M>;
128
129    #[inline]
130    fn mul(self, other: &'a ScalarKeys<C, M>) -> CurveKeys<C, M> {
131        CurveKeys {
132            alpha: other.alpha.clone(),
133            betas: self * &other.betas,
134        }
135    }
136}
137
138impl<'a, C: Curve, M: Positive> Mul<&'a ScalarKeys<C, M>> for CurvePoints<C, M> {
139    type Output = CurveKeys<C, M>;
140
141    #[inline]
142    fn mul(self, other: &'a ScalarKeys<C, M>) -> CurveKeys<C, M> {
143        CurveKeys {
144            alpha: other.alpha.clone(),
145            betas: self * &other.betas,
146        }
147    }
148}
149
150impl<C: Curve, M: Positive> Mul<ScalarKeys<C, M>> for &CurvePoints<C, M> {
151    type Output = CurveKeys<C, M>;
152
153    #[inline]
154    fn mul(self, other: ScalarKeys<C, M>) -> CurveKeys<C, M> {
155        CurveKeys {
156            alpha: other.alpha.clone(),
157            betas: self * other.betas,
158        }
159    }
160}
161
162// --- One-to-many multiplication --- //
163
164impl<C: Curve, M: Positive> Mul<ScalarKeys<C, M>> for Point<C> {
165    type Output = CurveKeys<C, M>;
166
167    #[inline]
168    fn mul(self, other: ScalarKeys<C, M>) -> CurveKeys<C, M> {
169        CurveKeys {
170            alpha: other.alpha,
171            betas: other.betas * self,
172        }
173    }
174}
175
176impl<'a, C: Curve, M: Positive> Mul<&'a ScalarKeys<C, M>> for &'a Point<C> {
177    type Output = CurveKeys<C, M>;
178
179    #[inline]
180    fn mul(self, other: &'a ScalarKeys<C, M>) -> CurveKeys<C, M> {
181        CurveKeys {
182            alpha: other.alpha.clone(),
183            betas: &other.betas * self,
184        }
185    }
186}
187
188impl<'a, C: Curve, M: Positive> Mul<&'a ScalarKeys<C, M>> for Point<C> {
189    type Output = CurveKeys<C, M>;
190
191    #[inline]
192    fn mul(self, other: &'a ScalarKeys<C, M>) -> CurveKeys<C, M> {
193        CurveKeys {
194            alpha: other.alpha.clone(),
195            betas: &other.betas * self,
196        }
197    }
198}
199
200impl<C: Curve, M: Positive> Mul<ScalarKeys<C, M>> for &Point<C> {
201    type Output = CurveKeys<C, M>;
202
203    #[inline]
204    fn mul(self, other: ScalarKeys<C, M>) -> CurveKeys<C, M> {
205        CurveKeys {
206            alpha: other.alpha.clone(),
207            betas: other.betas * self,
208        }
209    }
210}