-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature: eliptic curves #589
Draft
qalisander
wants to merge
26
commits into
main
Choose a base branch
from
openzeppelin-crypto/eliptic-curves
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
a39024b
++
qalisander 925c94d
++
qalisander 6edd263
++
qalisander 18ef0f8
refactor: reorganize imports and remove unused scalar multiplication …
qalisander be5dee0
++
qalisander 7046684
++
qalisander 3b9119f
++
qalisander d460124
++
qalisander cb8c365
++
qalisander 0b16b1c
++
qalisander 80fbc24
++
qalisander 50e4531
++
qalisander 1e7cc0b
++
qalisander 9acaeb4
++
qalisander 620fa07
remove get_point_from_x_unchecked from affine repr
qalisander 036e48e
move sw_double_and_add_affine and sw_double_and_add_projective to con…
qalisander 608ed0c
use BitIteratorBE
qalisander 0a94af1
++
qalisander f8b1d0c
++
qalisander 7802b0f
++
qalisander 7059243
++
qalisander 061e878
++
qalisander c8c483c
++
qalisander 28a915e
Merge remote-tracking branch 'refs/remotes/origin/main' into openzepp…
qalisander e2fcd06
refactor curves implementation
qalisander 112946f
Merge remote-tracking branch 'origin/main' into openzeppelin-crypto/e…
qalisander File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,170 @@ | ||
//! Helper macros for implementing common traits for curve types. | ||
|
||
/// Implements additive operations by deferring to an implementation on &Self. | ||
#[macro_export] | ||
macro_rules! impl_additive_ops_from_ref { | ||
($type:ident, $params:ident) => { | ||
#[allow(unused_qualifications)] | ||
impl<P: $params> core::ops::Add<Self> for $type<P> { | ||
type Output = Self; | ||
|
||
#[inline] | ||
fn add(self, other: Self) -> Self { | ||
let mut result = self; | ||
result += &other; | ||
result | ||
} | ||
} | ||
|
||
#[allow(unused_qualifications)] | ||
impl<'a, P: $params> core::ops::Add<&'a mut Self> for $type<P> { | ||
type Output = Self; | ||
|
||
#[inline] | ||
fn add(self, other: &'a mut Self) -> Self { | ||
let mut result = self; | ||
result += &*other; | ||
result | ||
} | ||
} | ||
|
||
impl<'b, P: $params> core::ops::Add<$type<P>> for &'b $type<P> { | ||
type Output = $type<P>; | ||
|
||
#[inline] | ||
fn add(self, mut other: $type<P>) -> $type<P> { | ||
other += self; | ||
other | ||
} | ||
} | ||
|
||
#[allow(unused_qualifications)] | ||
impl<'a, 'b, P: $params> core::ops::Add<&'a $type<P>> for &'b $type<P> { | ||
type Output = $type<P>; | ||
|
||
#[inline] | ||
fn add(self, other: &'a $type<P>) -> $type<P> { | ||
let mut result = *self; | ||
result += &*other; | ||
result | ||
} | ||
} | ||
|
||
#[allow(unused_qualifications)] | ||
impl<'a, 'b, P: $params> core::ops::Add<&'a mut $type<P>> | ||
for &'b $type<P> | ||
{ | ||
type Output = $type<P>; | ||
|
||
#[inline] | ||
fn add(self, other: &'a mut $type<P>) -> $type<P> { | ||
let mut result = *self; | ||
result += &*other; | ||
result | ||
} | ||
} | ||
|
||
impl<'b, P: $params> core::ops::Sub<$type<P>> for &'b $type<P> { | ||
type Output = $type<P>; | ||
|
||
#[inline] | ||
fn sub(self, other: $type<P>) -> $type<P> { | ||
let mut result = *self; | ||
result -= &other; | ||
result | ||
} | ||
} | ||
|
||
#[allow(unused_qualifications)] | ||
impl<'a, 'b, P: $params> core::ops::Sub<&'a $type<P>> for &'b $type<P> { | ||
type Output = $type<P>; | ||
|
||
#[inline] | ||
fn sub(self, other: &'a $type<P>) -> $type<P> { | ||
let mut result = *self; | ||
result -= &*other; | ||
result | ||
} | ||
} | ||
|
||
#[allow(unused_qualifications)] | ||
impl<'a, 'b, P: $params> core::ops::Sub<&'a mut $type<P>> | ||
for &'b $type<P> | ||
{ | ||
type Output = $type<P>; | ||
|
||
#[inline] | ||
fn sub(self, other: &'a mut $type<P>) -> $type<P> { | ||
let mut result = *self; | ||
result -= &*other; | ||
result | ||
} | ||
} | ||
|
||
#[allow(unused_qualifications)] | ||
impl<P: $params> core::ops::Sub<Self> for $type<P> { | ||
type Output = Self; | ||
|
||
#[inline] | ||
fn sub(self, other: Self) -> Self { | ||
let mut result = self; | ||
result -= &other; | ||
result | ||
} | ||
} | ||
|
||
#[allow(unused_qualifications)] | ||
impl<'a, P: $params> core::ops::Sub<&'a mut Self> for $type<P> { | ||
type Output = Self; | ||
|
||
#[inline] | ||
fn sub(self, other: &'a mut Self) -> Self { | ||
let mut result = self; | ||
result -= &*other; | ||
result | ||
} | ||
} | ||
|
||
#[allow(unused_qualifications)] | ||
impl<P: $params> core::iter::Sum<Self> for $type<P> { | ||
fn sum<I: Iterator<Item = Self>>(iter: I) -> Self { | ||
iter.fold(Self::zero(), core::ops::Add::add) | ||
} | ||
} | ||
|
||
#[allow(unused_qualifications)] | ||
impl<'a, P: $params> core::iter::Sum<&'a Self> for $type<P> { | ||
fn sum<I: Iterator<Item = &'a Self>>(iter: I) -> Self { | ||
iter.fold(Self::zero(), core::ops::Add::add) | ||
} | ||
} | ||
|
||
#[allow(unused_qualifications)] | ||
impl<P: $params> core::ops::AddAssign<Self> for $type<P> { | ||
fn add_assign(&mut self, other: Self) { | ||
*self += &other | ||
} | ||
} | ||
|
||
#[allow(unused_qualifications)] | ||
impl<P: $params> core::ops::SubAssign<Self> for $type<P> { | ||
fn sub_assign(&mut self, other: Self) { | ||
*self -= &other | ||
} | ||
} | ||
|
||
#[allow(unused_qualifications)] | ||
impl<'a, P: $params> core::ops::AddAssign<&'a mut Self> for $type<P> { | ||
fn add_assign(&mut self, other: &'a mut Self) { | ||
*self += &*other | ||
} | ||
} | ||
|
||
#[allow(unused_qualifications)] | ||
impl<'a, P: $params> core::ops::SubAssign<&'a mut Self> for $type<P> { | ||
fn sub_assign(&mut self, other: &'a mut Self) { | ||
*self -= &*other | ||
} | ||
} | ||
}; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't you use just
self + &other
?