Skip to content

Commit

Permalink
chore: Add missing pub fn docs for Fp
Browse files Browse the repository at this point in the history
  • Loading branch information
CPerezz committed Sep 11, 2023
1 parent fe45ff4 commit 28f1e05
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/fp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ impl Fp {
R
}

/// Checks if a value is equal to zero in constant time.
pub fn is_zero(&self) -> Choice {
self.ct_eq(&Fp::zero())
}
Expand Down Expand Up @@ -321,12 +322,14 @@ impl Fp {
}

#[inline]
/// Performs the square root of an element in constant time.
///
/// NOTE:
/// We use Shank's method, as p = 3 (mod 4). This means
/// we only need to exponentiate by (p+1)/4. This only
/// works for elements that are actually quadratic residue,
/// so we check that we got the correct result at the end.
pub fn sqrt(&self) -> CtOption<Self> {
// We use Shank's method, as p = 3 (mod 4). This means
// we only need to exponentiate by (p+1)/4. This only
// works for elements that are actually quadratic residue,
// so we check that we got the correct result at the end.

let sqrt = self.pow_vartime(&[
0xee7f_bfff_ffff_eaab,
0x07aa_ffff_ac54_ffff,
Expand Down Expand Up @@ -379,6 +382,7 @@ impl Fp {
}

#[inline]
/// Performs constant time addition of two elements.
pub const fn add(&self, rhs: &Fp) -> Fp {
let (d0, carry) = adc(self.0[0], rhs.0[0], 0);
let (d1, carry) = adc(self.0[1], rhs.0[1], carry);
Expand All @@ -393,6 +397,7 @@ impl Fp {
}

#[inline]
/// Performs constant time negation of an element.
pub const fn neg(&self) -> Fp {
let (d0, borrow) = sbb(MODULUS[0], self.0[0], 0);
let (d1, borrow) = sbb(MODULUS[1], self.0[1], borrow);
Expand All @@ -418,6 +423,7 @@ impl Fp {
}

#[inline]
/// Performs constant time subtraction of two elements.
pub const fn sub(&self, rhs: &Fp) -> Fp {
(&rhs.neg()).add(self)
}
Expand Down Expand Up @@ -562,6 +568,7 @@ impl Fp {
}

#[inline]
/// Performs constant time multiplication of two elements.
pub const fn mul(&self, rhs: &Fp) -> Fp {
let (t0, carry) = mac(0, self.0[0], rhs.0[0], 0);
let (t1, carry) = mac(0, self.0[0], rhs.0[1], carry);
Expand Down

0 comments on commit 28f1e05

Please sign in to comment.