Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/fields/fp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,12 @@ impl Fp {
/// Doubles this field element.
#[inline]
pub const fn double(&self) -> Fp {
// TODO: This can be achieved more efficiently with a bitshift.
self.add(self)
let d0 = self.0[0] << 1;
let d1 = self.0[1] << 1 | self.0[0] >> 63;
let d2 = self.0[2] << 1 | self.0[1] >> 63;
let d3 = self.0[3] << 1 | self.0[2] >> 63;

(&Fp([d0, d1, d2, d3])).sub(&MODULUS)
}

fn from_u512(limbs: [u64; 8]) -> Fp {
Expand Down
8 changes: 6 additions & 2 deletions src/fields/fq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,12 @@ impl Fq {
/// Doubles this field element.
#[inline]
pub const fn double(&self) -> Fq {
// TODO: This can be achieved more efficiently with a bitshift.
self.add(self)
let d0 = self.0[0] << 1;
let d1 = self.0[1] << 1 | self.0[0] >> 63;
let d2 = self.0[2] << 1 | self.0[1] >> 63;
let d3 = self.0[3] << 1 | self.0[2] >> 63;

(&Fq([d0, d1, d2, d3])).sub(&MODULUS)
}

fn from_u512(limbs: [u64; 8]) -> Fq {
Expand Down