Skip to content

Commit

Permalink
Minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
kayabaNerve committed May 5, 2024
1 parent f8c49ce commit 1f209ad
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
5 changes: 2 additions & 3 deletions crypto/dalek-ff-group/src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,8 @@ impl Field for FieldElement {
}

fn invert(&self) -> CtOption<Self> {
const NEG_2: FieldElement =
FieldElement(ResidueType::new(&MODULUS.saturating_sub(&U256::from_u8(2))));
CtOption::new(self.pow(NEG_2), !self.is_zero())
let res = self.0.invert();
CtOption::new(Self(res.0), res.1.into())
}

// RFC-8032 sqrt8k5
Expand Down
7 changes: 3 additions & 4 deletions crypto/helioselene/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,15 @@ macro_rules! field {
}

fn square(&self) -> Self {
*self * self
Self(self.0.square())
}
fn double(&self) -> Self {
*self + self
}

fn invert(&self) -> CtOption<Self> {
const NEG_2: $FieldName =
Self($ResidueType::sub(&$ResidueType::ZERO, &$ResidueType::new(&U256::from_u8(2))));
CtOption::new(self.pow(NEG_2), !self.is_zero())
let res = self.0.invert();
CtOption::new(Self(res.0), res.1.into())
}

fn sqrt(&self) -> CtOption<Self> {
Expand Down

0 comments on commit 1f209ad

Please sign in to comment.