ed448_goldilocks/decaf/
ops.rs1use std::ops::{Add, Mul, Neg, Sub};
2
3use crate::{Scalar, curve::scalar_mul::double_and_add};
4
5use super::DecafPoint;
6
7impl<'s, 'p> Mul<&'s Scalar> for &'p DecafPoint {
9 type Output = DecafPoint;
10 fn mul(self, scalar: &'s Scalar) -> DecafPoint {
11 DecafPoint(double_and_add(&self.0, &scalar))
13 }
14}
15impl<'p, 's> Mul<&'p DecafPoint> for &'s Scalar {
16 type Output = DecafPoint;
17 fn mul(self, point: &'p DecafPoint) -> DecafPoint {
18 DecafPoint(double_and_add(&point.0,self))
19 }
20}
21impl Mul<DecafPoint> for Scalar {
22 type Output = DecafPoint;
23 fn mul(self, point: DecafPoint) -> DecafPoint {
24 DecafPoint(double_and_add(&point.0,&self))
25 }
26}
27impl Mul<Scalar> for DecafPoint {
28 type Output = DecafPoint;
29 fn mul(self, scalar : Scalar) -> DecafPoint {
30 DecafPoint(double_and_add(&self.0, &scalar))
31 }
32}
33
34impl<'a, 'b> Add<&'a DecafPoint> for &'b DecafPoint {
37 type Output = DecafPoint;
38 fn add(self, other: &'a DecafPoint) -> DecafPoint {
39 DecafPoint(self.0.to_extensible().add_extended(&other.0).to_extended())
40 }
41}
42impl Add<DecafPoint> for DecafPoint {
43 type Output = DecafPoint;
44 fn add(self, other: DecafPoint) -> DecafPoint {
45 (&self).add(&other)
46 }
47}
48
49impl<'a, 'b> Sub<&'a DecafPoint> for &'b DecafPoint {
52 type Output = DecafPoint;
53 fn sub(self, other: &'a DecafPoint) -> DecafPoint {
54 DecafPoint(self.0.to_extensible().sub_extended(&other.0).to_extended())
55 }
56}
57impl Sub<DecafPoint> for DecafPoint {
58 type Output = DecafPoint;
59 fn sub(self, other: DecafPoint) -> DecafPoint {
60 (&self).sub(&other)
61 }
62}
63
64impl<'b> Neg for &'b DecafPoint {
67 type Output = DecafPoint;
68 fn neg(self) -> DecafPoint {
69 DecafPoint(self.0.negate())
70 }
71}
72impl Neg for DecafPoint {
73 type Output = DecafPoint;
74 fn neg(self) -> DecafPoint {
75 (&self).neg()
76 }
77}
78