decaf377/ark_curve/ops/
projective.rs1use core::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign};
2
3use crate::{ark_curve::element::projective::Element, ark_curve::AffinePoint, Fr};
4
5impl<'a, 'b> Add<&'b Element> for &'a Element {
6 type Output = Element;
7
8 fn add(self, other: &'b Element) -> Element {
9 Element {
10 inner: self.inner + other.inner,
11 }
12 }
13}
14
15impl<'b> Add<&'b Element> for Element {
16 type Output = Element;
17 fn add(self, other: &'b Element) -> Element {
18 &self + other
19 }
20}
21
22impl<'a> Add<Element> for &'a Element {
23 type Output = Element;
24 fn add(self, other: Element) -> Element {
25 self + &other
26 }
27}
28
29impl Add<Element> for Element {
30 type Output = Element;
31 fn add(self, other: Element) -> Element {
32 &self + &other
33 }
34}
35
36impl<'b> AddAssign<&'b Element> for Element {
37 fn add_assign(&mut self, other: &'b Element) {
38 *self = Element {
39 inner: self.inner + other.inner,
40 }
41 }
42}
43
44impl AddAssign<Element> for Element {
45 fn add_assign(&mut self, other: Element) {
46 *self += &other;
47 }
48}
49
50impl<'a, 'b> Sub<&'b Element> for &'a Element {
51 type Output = Element;
52
53 fn sub(self, other: &'b Element) -> Element {
54 Element {
55 inner: self.inner - other.inner,
56 }
57 }
58}
59
60impl<'b> Sub<&'b Element> for Element {
61 type Output = Element;
62
63 fn sub(self, other: &'b Element) -> Element {
64 &self - other
65 }
66}
67
68impl<'a> Sub<Element> for &'a Element {
69 type Output = Element;
70
71 fn sub(self, other: Element) -> Element {
72 self - &other
73 }
74}
75
76impl Sub<Element> for Element {
77 type Output = Element;
78
79 fn sub(self, other: Element) -> Element {
80 &self - &other
81 }
82}
83
84impl<'b> SubAssign<&'b Element> for Element {
85 fn sub_assign(&mut self, other: &'b Element) {
86 *self = Element {
87 inner: self.inner - other.inner,
88 }
89 }
90}
91
92impl SubAssign<Element> for Element {
93 fn sub_assign(&mut self, other: Element) {
94 *self -= &other;
95 }
96}
97
98impl Neg for Element {
99 type Output = Self;
100
101 fn neg(self) -> Self {
102 Element { inner: -self.inner }
103 }
104}
105
106impl<'b> MulAssign<&'b Fr> for Element {
107 fn mul_assign(&mut self, point: &'b Fr) {
111 let mut p = self.inner;
112 p *= *point;
113 *self = Element { inner: p }
114 }
115}
116
117impl MulAssign<Fr> for Element {
118 fn mul_assign(&mut self, other: Fr) {
119 *self *= &other;
120 }
121}
122
123impl<'a, 'b> Mul<&'b Fr> for &'a Element {
124 type Output = Element;
125
126 fn mul(self, point: &'b Fr) -> Element {
127 let mut p = self.inner;
128 p *= *point;
129 Element { inner: p }
130 }
131}
132
133impl<'a, 'b> Mul<&'b Element> for &'a Fr {
134 type Output = Element;
135
136 fn mul(self, point: &'b Element) -> Element {
137 point * self
138 }
139}
140
141impl<'b> Mul<&'b Fr> for Element {
142 type Output = Element;
143
144 fn mul(self, other: &'b Fr) -> Element {
145 &self * other
146 }
147}
148
149impl<'a> Mul<Fr> for &'a Element {
150 type Output = Element;
151
152 fn mul(self, other: Fr) -> Element {
153 self * &other
154 }
155}
156
157impl Mul<Fr> for Element {
158 type Output = Element;
159
160 fn mul(self, other: Fr) -> Element {
161 &self * &other
162 }
163}
164
165impl<'b> Mul<&'b Element> for Fr {
166 type Output = Element;
167
168 fn mul(self, other: &'b Element) -> Element {
169 &self * other
170 }
171}
172
173impl<'a> Mul<Element> for &'a Fr {
174 type Output = Element;
175
176 fn mul(self, other: Element) -> Element {
177 self * &other
178 }
179}
180
181impl Mul<Element> for Fr {
182 type Output = Element;
183
184 fn mul(self, other: Element) -> Element {
185 &self * &other
186 }
187}
188
189impl<'a> Add<&'a AffinePoint> for Element {
190 type Output = Element;
191
192 fn add(self, other: &'a AffinePoint) -> Element {
193 let element_other: Element = other.into();
194 &self + element_other
195 }
196}
197
198impl Add<AffinePoint> for Element {
199 type Output = Element;
200
201 fn add(self, other: AffinePoint) -> Element {
202 &self + &other.into()
203 }
204}
205
206impl Add<AffinePoint> for AffinePoint {
207 type Output = Element;
210
211 fn add(self, other: AffinePoint) -> Element {
212 let other_element: Element = other.into();
213 let self_element: Element = other.into();
214 self_element + other_element
215 }
216}
217
218impl Add<Element> for AffinePoint {
219 type Output = Element;
220
221 fn add(self, other: Element) -> Element {
222 &self.into() + &other
223 }
224}
225
226impl<'a> Add<&'a Element> for AffinePoint {
227 type Output = Element;
228
229 fn add(self, other: &'a Element) -> Element {
230 &self.into() + other
231 }
232}
233
234impl<'a> AddAssign<&'a AffinePoint> for Element {
235 fn add_assign(&mut self, other: &'a AffinePoint) {
236 let other_element: Element = other.into();
237 *self += other_element;
238 }
239}
240
241impl AddAssign<AffinePoint> for Element {
242 fn add_assign(&mut self, other: AffinePoint) {
243 *self += &other;
244 }
245}
246
247impl<'a> SubAssign<&'a AffinePoint> for Element {
248 fn sub_assign(&mut self, other: &'a AffinePoint) {
249 let other_element: Element = other.into();
250 *self -= other_element;
251 }
252}
253
254impl SubAssign<AffinePoint> for Element {
255 fn sub_assign(&mut self, other: AffinePoint) {
256 let other_element: Element = other.into();
257 *self -= other_element;
258 }
259}
260
261impl<'a> Sub<&'a AffinePoint> for Element {
262 type Output = Element;
263
264 fn sub(self, other: &'a AffinePoint) -> Element {
265 let other_element: Element = other.into();
266 &self - other_element
267 }
268}
269
270impl Sub<AffinePoint> for Element {
271 type Output = Element;
272
273 fn sub(self, other: AffinePoint) -> Element {
274 &self - &other.into()
275 }
276}