decaf377/ark_curve/ops/
affine.rs1use core::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign};
2
3use ark_ec::twisted_edwards::Projective;
4
5use crate::{
6 ark_curve::element::AffinePoint, ark_curve::Decaf377EdwardsConfig, ark_curve::Element, Fr,
7};
8
9impl<'a, 'b> Add<&'b AffinePoint> for &'a AffinePoint {
10 type Output = AffinePoint;
11
12 fn add(self, other: &'b AffinePoint) -> AffinePoint {
13 AffinePoint {
14 inner: (self.inner + other.inner).into(),
15 }
16 }
17}
18
19impl<'b> Add<&'b AffinePoint> for AffinePoint {
20 type Output = Element;
21
22 fn add(self, other: &'b AffinePoint) -> Element {
23 (&self + other).into()
24 }
25}
26
27impl<'a> Add<AffinePoint> for &'a AffinePoint {
28 type Output = AffinePoint;
29 fn add(self, other: AffinePoint) -> AffinePoint {
30 self + &other
31 }
32}
33
34impl<'b> AddAssign<&'b AffinePoint> for AffinePoint {
35 fn add_assign(&mut self, other: &'b AffinePoint) {
36 *self = AffinePoint {
37 inner: (self.inner + other.inner).into(),
38 }
39 }
40}
41
42impl AddAssign<AffinePoint> for AffinePoint {
43 fn add_assign(&mut self, other: AffinePoint) {
44 *self += &other;
45 }
46}
47
48impl<'a, 'b> Sub<&'b AffinePoint> for &'a AffinePoint {
49 type Output = AffinePoint;
50
51 fn sub(self, other: &'b AffinePoint) -> AffinePoint {
52 AffinePoint {
53 inner: (self.inner - other.inner).into(),
54 }
55 }
56}
57
58impl<'b> Sub<&'b AffinePoint> for AffinePoint {
59 type Output = AffinePoint;
60
61 fn sub(self, other: &'b AffinePoint) -> AffinePoint {
62 &self - other
63 }
64}
65
66impl<'a> Sub<AffinePoint> for &'a AffinePoint {
67 type Output = AffinePoint;
68
69 fn sub(self, other: AffinePoint) -> AffinePoint {
70 self - &other
71 }
72}
73
74impl Sub<AffinePoint> for AffinePoint {
75 type Output = AffinePoint;
76
77 fn sub(self, other: AffinePoint) -> AffinePoint {
78 &self - &other
79 }
80}
81
82impl<'b> SubAssign<&'b AffinePoint> for AffinePoint {
83 fn sub_assign(&mut self, other: &'b AffinePoint) {
84 *self = AffinePoint {
85 inner: (self.inner - other.inner).into(),
86 }
87 }
88}
89
90impl SubAssign<AffinePoint> for AffinePoint {
91 fn sub_assign(&mut self, other: AffinePoint) {
92 *self -= &other;
93 }
94}
95
96impl Neg for AffinePoint {
97 type Output = Self;
98
99 fn neg(self) -> Self {
100 AffinePoint { inner: -self.inner }
101 }
102}
103
104impl<'b> MulAssign<&'b Fr> for AffinePoint {
105 fn mul_assign(&mut self, point: &'b Fr) {
106 let mut p: Projective<Decaf377EdwardsConfig> = self.inner.into();
107 p *= *point;
108 *self = AffinePoint { inner: p.into() }
109 }
110}
111
112impl MulAssign<Fr> for AffinePoint {
113 fn mul_assign(&mut self, other: Fr) {
114 *self *= &other;
115 }
116}
117
118impl<'a, 'b> Mul<&'b Fr> for &'a AffinePoint {
119 type Output = AffinePoint;
120
121 fn mul(self, point: &'b Fr) -> AffinePoint {
122 let mut p: Projective<Decaf377EdwardsConfig> = self.inner.into();
123 p *= *point;
124 AffinePoint { inner: p.into() }
125 }
126}
127
128impl<'a, 'b> Mul<&'b AffinePoint> for &'a Fr {
129 type Output = AffinePoint;
130
131 fn mul(self, point: &'b AffinePoint) -> AffinePoint {
132 point * self
133 }
134}
135
136impl<'b> Mul<&'b Fr> for AffinePoint {
137 type Output = Element;
138
139 fn mul(self, other: &'b Fr) -> Element {
140 (&self * other).into()
141 }
142}
143
144impl<'a> Mul<Fr> for &'a AffinePoint {
145 type Output = AffinePoint;
146
147 fn mul(self, other: Fr) -> AffinePoint {
148 self * &other
149 }
150}
151
152impl Mul<Fr> for AffinePoint {
153 type Output = Element;
154
155 fn mul(self, other: Fr) -> Element {
156 (&self * &other).into()
157 }
158}
159
160impl<'b> Mul<&'b AffinePoint> for Fr {
161 type Output = AffinePoint;
162
163 fn mul(self, other: &'b AffinePoint) -> AffinePoint {
164 &self * other
165 }
166}
167
168impl<'a> Mul<AffinePoint> for &'a Fr {
169 type Output = AffinePoint;
170
171 fn mul(self, other: AffinePoint) -> AffinePoint {
172 self * &other
173 }
174}
175
176impl Mul<AffinePoint> for Fr {
177 type Output = AffinePoint;
178
179 fn mul(self, other: AffinePoint) -> AffinePoint {
180 &self * &other
181 }
182}