-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement arkworks-independent projective arithmetic ops
- Loading branch information
1 parent
c8157b6
commit 1f5ff9d
Showing
4 changed files
with
179 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod element; | ||
mod ops; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/// Group operations in projective coordinates. | ||
pub mod projective; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
use core::ops::{Add, AddAssign, Mul, MulAssign, Neg, Sub, SubAssign}; | ||
|
||
use crate::{smol_curve::element::Element, Fr}; | ||
|
||
// Element addition | ||
|
||
impl<'a, 'b> Add<&'b Element> for &'a Element { | ||
type Output = Element; | ||
|
||
fn add(self, other: &'b Element) -> Element { | ||
self + *other | ||
} | ||
} | ||
|
||
impl<'b> Add<&'b Element> for Element { | ||
type Output = Element; | ||
fn add(self, other: &'b Element) -> Element { | ||
self + *other | ||
} | ||
} | ||
|
||
impl<'a> Add<Element> for &'a Element { | ||
type Output = Element; | ||
fn add(self, other: Element) -> Element { | ||
*self + other | ||
} | ||
} | ||
|
||
impl<'b> AddAssign<&'b Element> for Element { | ||
fn add_assign(&mut self, other: &'b Element) { | ||
*self = *self + other | ||
} | ||
} | ||
|
||
impl AddAssign<Element> for Element { | ||
fn add_assign(&mut self, other: Element) { | ||
*self += &other; | ||
} | ||
} | ||
|
||
// Element subtraction | ||
|
||
impl Sub<Element> for Element { | ||
type Output = Element; | ||
|
||
fn sub(self, other: Element) -> Element { | ||
self + other.neg() | ||
} | ||
} | ||
|
||
impl<'a, 'b> Sub<&'b Element> for &'a Element { | ||
type Output = Element; | ||
|
||
fn sub(self, other: &'b Element) -> Element { | ||
*self - *other | ||
} | ||
} | ||
|
||
impl<'b> Sub<&'b Element> for Element { | ||
type Output = Element; | ||
|
||
fn sub(self, other: &'b Element) -> Element { | ||
self - *other | ||
} | ||
} | ||
|
||
impl<'a> Sub<Element> for &'a Element { | ||
type Output = Element; | ||
|
||
fn sub(self, other: Element) -> Element { | ||
*self - other | ||
} | ||
} | ||
|
||
impl<'b> SubAssign<&'b Element> for Element { | ||
fn sub_assign(&mut self, other: &'b Element) { | ||
*self = *self - other; | ||
} | ||
} | ||
|
||
impl SubAssign<Element> for Element { | ||
fn sub_assign(&mut self, other: Element) { | ||
*self -= &other; | ||
} | ||
} | ||
|
||
/// Scalar multiplication | ||
|
||
impl Mul<Fr> for Element { | ||
type Output = Self; | ||
|
||
fn mul(self, rhs: Fr) -> Self::Output { | ||
Self::scalar_mul_vartime(self, &rhs.to_le_limbs()) | ||
} | ||
} | ||
|
||
impl<'b> MulAssign<&'b Fr> for Element { | ||
fn mul_assign(&mut self, rhs: &'b Fr) { | ||
*self = *self * rhs; | ||
} | ||
} | ||
|
||
impl MulAssign<Fr> for Element { | ||
fn mul_assign(&mut self, other: Fr) { | ||
*self *= &other; | ||
} | ||
} | ||
|
||
impl<'a, 'b> Mul<&'b Fr> for &'a Element { | ||
type Output = Element; | ||
|
||
fn mul(self, scalar: &'b Fr) -> Element { | ||
scalar * self | ||
} | ||
} | ||
|
||
impl<'a, 'b> Mul<&'b Element> for &'a Fr { | ||
type Output = Element; | ||
|
||
fn mul(self, point: &'b Element) -> Element { | ||
point * self | ||
} | ||
} | ||
|
||
impl<'b> Mul<&'b Fr> for Element { | ||
type Output = Self; | ||
|
||
fn mul(self, other: &'b Fr) -> Element { | ||
self * *other | ||
} | ||
} | ||
|
||
impl<'a> Mul<Fr> for &'a Element { | ||
type Output = Element; | ||
|
||
fn mul(self, other: Fr) -> Element { | ||
*self * other | ||
} | ||
} | ||
|
||
impl<'b> Mul<&'b Element> for Fr { | ||
type Output = Element; | ||
|
||
fn mul(self, other: &'b Element) -> Element { | ||
other * self | ||
} | ||
} | ||
|
||
impl<'a> Mul<Element> for &'a Fr { | ||
type Output = Element; | ||
|
||
fn mul(self, other: Element) -> Element { | ||
other * *self | ||
} | ||
} | ||
|
||
impl Mul<Element> for Fr { | ||
type Output = Element; | ||
|
||
fn mul(self, other: Element) -> Element { | ||
other * self | ||
} | ||
} |