primitives/sharing/authenticated/batched/
scalar_shares.rs1use std::ops::Mul;
2
3use crate::{
4 algebra::elliptic_curve::{BaseField, Curve, Point, ScalarField},
5 sharing::{FieldShares, OpenFieldShares, PointShares},
6 types::{heap_array::curve_arrays::CurvePoints, Positive},
7};
8
9pub type OpenScalarShares<C, M> = OpenFieldShares<ScalarField<C>, M>;
12pub type OpenBaseFieldShares<C, M> = OpenFieldShares<BaseField<C>, M>;
13
14pub type ScalarShares<C, M> = FieldShares<ScalarField<C>, M>;
15pub type BaseFieldShares<C, M> = FieldShares<BaseField<C>, M>;
16
17impl<C: Curve, M: Positive> Mul<CurvePoints<C, M>> for ScalarShares<C, M> {
20 type Output = PointShares<C, M>;
21
22 #[inline]
23 fn mul(self, other: CurvePoints<C, M>) -> Self::Output {
24 PointShares {
25 value: self.value * &other,
26 macs: self.macs.iter().map(|mac| mac * &other).collect(),
27 keys: self.keys.iter().map(|key| key * &other).collect(),
28 }
29 }
30}
31
32impl<'a, C: Curve, M: Positive> Mul<&'a CurvePoints<C, M>> for &'a ScalarShares<C, M> {
33 type Output = PointShares<C, M>;
34
35 #[inline]
36 fn mul(self, other: &'a CurvePoints<C, M>) -> Self::Output {
37 PointShares {
38 value: &self.value * other,
39 macs: self.macs.iter().map(|mac| mac * other).collect(),
40 keys: self.keys.iter().map(|key| key * other).collect(),
41 }
42 }
43}
44
45impl<'a, C: Curve, M: Positive> Mul<&'a CurvePoints<C, M>> for ScalarShares<C, M> {
46 type Output = PointShares<C, M>;
47
48 #[inline]
49 fn mul(self, other: &'a CurvePoints<C, M>) -> Self::Output {
50 PointShares {
51 value: self.value * other,
52 macs: self.macs.iter().map(|mac| mac * other).collect(),
53 keys: self.keys.iter().map(|key| key * other).collect(),
54 }
55 }
56}
57
58impl<C: Curve, M: Positive> Mul<CurvePoints<C, M>> for &ScalarShares<C, M> {
59 type Output = PointShares<C, M>;
60
61 #[inline]
62 fn mul(self, other: CurvePoints<C, M>) -> Self::Output {
63 PointShares {
64 value: &self.value * &other,
65 macs: self.macs.iter().map(|mac| mac * &other).collect(),
66 keys: self.keys.iter().map(|key| key * &other).collect(),
67 }
68 }
69}
70
71impl<C: Curve, M: Positive> Mul<Point<C>> for ScalarShares<C, M> {
74 type Output = PointShares<C, M>;
75
76 #[inline]
77 fn mul(self, other: Point<C>) -> Self::Output {
78 PointShares {
79 value: self.value * other,
80 macs: self.macs.iter().map(|mac| mac * other).collect(),
81 keys: self.keys.iter().map(|key| key * other).collect(),
82 }
83 }
84}
85
86impl<'a, C: Curve, M: Positive> Mul<&'a Point<C>> for &'a ScalarShares<C, M> {
87 type Output = PointShares<C, M>;
88
89 #[inline]
90 fn mul(self, other: &'a Point<C>) -> Self::Output {
91 PointShares {
92 value: &self.value * other,
93 macs: self.macs.iter().map(|mac| mac * other).collect(),
94 keys: self.keys.iter().map(|key| key * other).collect(),
95 }
96 }
97}
98
99impl<'a, C: Curve, M: Positive> Mul<&'a Point<C>> for ScalarShares<C, M> {
100 type Output = PointShares<C, M>;
101
102 #[inline]
103 fn mul(self, other: &'a Point<C>) -> Self::Output {
104 PointShares {
105 value: self.value * other,
106 macs: self.macs.iter().map(|mac| mac * other).collect(),
107 keys: self.keys.iter().map(|key| key * other).collect(),
108 }
109 }
110}
111
112impl<C: Curve, M: Positive> Mul<Point<C>> for &ScalarShares<C, M> {
113 type Output = PointShares<C, M>;
114
115 #[inline]
116 fn mul(self, other: Point<C>) -> Self::Output {
117 PointShares {
118 value: &self.value * other,
119 macs: self.macs.iter().map(|mac| mac * other).collect(),
120 keys: self.keys.iter().map(|key| key * other).collect(),
121 }
122 }
123}
124
125impl<C: Curve, M: Positive> Mul<ScalarShares<C, M>> for CurvePoints<C, M> {
128 type Output = PointShares<C, M>;
129
130 #[inline]
131 fn mul(self, other: ScalarShares<C, M>) -> Self::Output {
132 PointShares {
133 value: other.value * &self,
134 macs: other.macs.iter().map(|mac| mac * &self).collect(),
135 keys: other.keys.iter().map(|key| key * &self).collect(),
136 }
137 }
138}
139
140impl<'a, C: Curve, M: Positive> Mul<&'a ScalarShares<C, M>> for &'a CurvePoints<C, M> {
141 type Output = PointShares<C, M>;
142
143 #[inline]
144 fn mul(self, other: &'a ScalarShares<C, M>) -> Self::Output {
145 PointShares {
146 value: &other.value * self,
147 macs: other.macs.iter().map(|mac| mac * self).collect(),
148 keys: other.keys.iter().map(|key| key * self).collect(),
149 }
150 }
151}
152
153impl<'a, C: Curve, M: Positive> Mul<&'a ScalarShares<C, M>> for CurvePoints<C, M> {
154 type Output = PointShares<C, M>;
155
156 #[inline]
157 fn mul(self, other: &'a ScalarShares<C, M>) -> Self::Output {
158 PointShares {
159 value: &other.value * &self,
160 macs: other.macs.iter().map(|mac| mac * &self).collect(),
161 keys: other.keys.iter().map(|key| key * &self).collect(),
162 }
163 }
164}
165
166impl<C: Curve, M: Positive> Mul<ScalarShares<C, M>> for &CurvePoints<C, M> {
167 type Output = PointShares<C, M>;
168
169 #[inline]
170 fn mul(self, other: ScalarShares<C, M>) -> Self::Output {
171 PointShares {
172 value: other.value * self,
173 macs: other.macs.iter().map(|mac| mac * self).collect(),
174 keys: other.keys.iter().map(|key| key * self).collect(),
175 }
176 }
177}
178
179impl<C: Curve, M: Positive> Mul<ScalarShares<C, M>> for Point<C> {
182 type Output = PointShares<C, M>;
183
184 #[inline]
185 fn mul(self, other: ScalarShares<C, M>) -> Self::Output {
186 PointShares {
187 value: other.value * self,
188 macs: other.macs.iter().map(|mac| mac * self).collect(),
189 keys: other.keys.iter().map(|key| key * self).collect(),
190 }
191 }
192}
193
194impl<'a, C: Curve, M: Positive> Mul<&'a ScalarShares<C, M>> for Point<C> {
195 type Output = PointShares<C, M>;
196
197 #[inline]
198 fn mul(self, other: &'a ScalarShares<C, M>) -> Self::Output {
199 PointShares {
200 value: &other.value * self,
201 macs: other.macs.iter().map(|mac| mac * self).collect(),
202 keys: other.keys.iter().map(|key| key * self).collect(),
203 }
204 }
205}
206
207impl<C: Curve, M: Positive> Mul<ScalarShares<C, M>> for &Point<C> {
208 type Output = PointShares<C, M>;
209
210 #[inline]
211 fn mul(self, other: ScalarShares<C, M>) -> Self::Output {
212 PointShares {
213 value: other.value * self,
214 macs: other.macs.iter().map(|mac| mac * self).collect(),
215 keys: other.keys.iter().map(|key| key * self).collect(),
216 }
217 }
218}
219
220impl<'a, C: Curve, M: Positive> Mul<&'a ScalarShares<C, M>> for &'a Point<C> {
221 type Output = PointShares<C, M>;
222
223 #[inline]
224 fn mul(self, other: &'a ScalarShares<C, M>) -> Self::Output {
225 PointShares {
226 value: &other.value * self,
227 macs: other.macs.iter().map(|mac| mac * self).collect(),
228 keys: other.keys.iter().map(|key| key * self).collect(),
229 }
230 }
231}