Skip to content

Commit

Permalink
Document that Field::{sqrt, sqrt_alt} provided impls use sqrt_ratio
Browse files Browse the repository at this point in the history
This makes the potential for a cycle clear (if the `Field` implementor
uses `sqrt` to implement `sqrt_ratio`).
  • Loading branch information
str4d committed Nov 2, 2022
1 parent 58741b7 commit cc08c5e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,18 @@ pub trait Field:
fn sqrt_ratio(num: &Self, div: &Self) -> (Choice, Self);

/// Equivalent to `Self::sqrt_ratio(self, one())`.
///
/// The provided method is implemented in terms of [`Self::sqrt_ratio`].
fn sqrt_alt(&self) -> (Choice, Self) {
Self::sqrt_ratio(self, &Self::one())
}

/// Returns the square root of the field element, if it is
/// quadratic residue.
///
/// The provided method is implemented in terms of [`Self::sqrt_ratio`].
fn sqrt(&self) -> CtOption<Self> {
let (is_square, res) = self.sqrt_alt();
let (is_square, res) = Self::sqrt_ratio(self, &Self::one());
CtOption::new(res, is_square)
}

Expand Down

0 comments on commit cc08c5e

Please sign in to comment.