Skip to content

Commit

Permalink
Merge pull request zcash#81 from ebfull/must_use
Browse files Browse the repository at this point in the history
Add must_use to operations over Edwards points
  • Loading branch information
ebfull authored Jul 31, 2018
2 parents b70d6e6 + b4d41b6 commit 21084bd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/jubjub/edwards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ impl<E: JubjubEngine> Point<E, Unknown> {
}

/// This guarantees the point is in the prime order subgroup
#[must_use]
pub fn mul_by_cofactor(&self, params: &E::Params) -> Point<E, PrimeOrder>
{
let tmp = self.double(params)
Expand Down Expand Up @@ -346,6 +347,7 @@ impl<E: JubjubEngine, Subgroup> Point<E, Subgroup> {
(x, y)
}

#[must_use]
pub fn negate(&self) -> Self {
let mut p = self.clone();

Expand All @@ -355,6 +357,7 @@ impl<E: JubjubEngine, Subgroup> Point<E, Subgroup> {
p
}

#[must_use]
pub fn double(&self, _: &E::Params) -> Self {
// See "Twisted Edwards Curves Revisited"
// Huseyin Hisil, Kenneth Koon-Ho Wong, Gary Carter, and Ed Dawson
Expand Down Expand Up @@ -423,6 +426,7 @@ impl<E: JubjubEngine, Subgroup> Point<E, Subgroup> {
}
}

#[must_use]
pub fn add(&self, other: &Self, params: &E::Params) -> Self
{
// See "Twisted Edwards Curves Revisited"
Expand Down Expand Up @@ -495,6 +499,7 @@ impl<E: JubjubEngine, Subgroup> Point<E, Subgroup> {
}
}

#[must_use]
pub fn mul<S: Into<<E::Fs as PrimeField>::Repr>>(
&self,
scalar: S,
Expand Down
5 changes: 5 additions & 0 deletions src/jubjub/montgomery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ impl<E: JubjubEngine> Point<E, Unknown> {
}

/// This guarantees the point is in the prime order subgroup
#[must_use]
pub fn mul_by_cofactor(&self, params: &E::Params) -> Point<E, PrimeOrder>
{
let tmp = self.double(params)
Expand Down Expand Up @@ -216,6 +217,7 @@ impl<E: JubjubEngine, Subgroup> Point<E, Subgroup> {
}
}

#[must_use]
pub fn negate(&self) -> Self {
let mut p = self.clone();

Expand All @@ -224,6 +226,7 @@ impl<E: JubjubEngine, Subgroup> Point<E, Subgroup> {
p
}

#[must_use]
pub fn double(&self, params: &E::Params) -> Self {
if self.infinity {
return Point::zero();
Expand Down Expand Up @@ -280,6 +283,7 @@ impl<E: JubjubEngine, Subgroup> Point<E, Subgroup> {
}
}

#[must_use]
pub fn add(&self, other: &Self, params: &E::Params) -> Self
{
// This is a standard affine point addition formula
Expand Down Expand Up @@ -330,6 +334,7 @@ impl<E: JubjubEngine, Subgroup> Point<E, Subgroup> {
}
}

#[must_use]
pub fn mul<S: Into<<E::Fs as PrimeField>::Repr>>(
&self,
scalar: S,
Expand Down

0 comments on commit 21084bd

Please sign in to comment.