Trait SqrtRatio

Source
pub trait SqrtRatio: PrimeField {
    const T_MINUS1_OVER2: [u64; 4];

    // Required method
    fn get_lower_32(&self) -> u32;

    // Provided methods
    fn pow_by_t_minus1_over2(&self) -> Self { ... }
    fn sqrt_ratio(num: &Self, div: &Self) -> (Choice, Self) { ... }
    fn sqrt_alt(&self) -> (Choice, Self) { ... }
}
Expand description

A trait that exposes additional operations related to calculating square roots of prime-order finite fields.

Required Associated Constants§

Source

const T_MINUS1_OVER2: [u64; 4]

The value $(T-1)/2$ such that $2^S \cdot T = p - 1$ with $T$ odd.

Required Methods§

Source

fn get_lower_32(&self) -> u32

Gets the lower 32 bits of this field element when expressed canonically.

Provided Methods§

Source

fn pow_by_t_minus1_over2(&self) -> Self

Raise this field element to the power Self::T_MINUS1_OVER2.

Field implementations may override this to use an efficient addition chain.

Source

fn sqrt_ratio(num: &Self, div: &Self) -> (Choice, Self)

Computes:

  • $(\textsf{true}, \sqrt{\textsf{num}/\textsf{div}})$, if $\textsf{num}$ and $\textsf{div}$ are nonzero and $\textsf{num}/\textsf{div}$ is a square in the field;
  • $(\textsf{true}, 0)$, if $\textsf{num}$ is zero;
  • $(\textsf{false}, 0)$, if $\textsf{num}$ is nonzero and $\textsf{div}$ is zero;
  • $(\textsf{false}, \sqrt{G_S \cdot \textsf{num}/\textsf{div}})$, if $\textsf{num}$ and $\textsf{div}$ are nonzero and $\textsf{num}/\textsf{div}$ is a nonsquare in the field;

where $G_S$ is a non-square.

For pasta_curves, $G_S$ is currently ff::PrimeField::root_of_unity, a generator of the order $2^S$ subgroup. Users of this crate should not rely on this generator being fixed; it may be changed in future crate versions to simplify the implementation of the SSWU hash-to-curve algorithm.

The choice of root from sqrt is unspecified.

Source

fn sqrt_alt(&self) -> (Choice, Self)

Equivalent to Self::sqrt_ratio(self, one()).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl SqrtRatio for Fp

Source§

const T_MINUS1_OVER2: [u64; 4] = T_MINUS1_OVER2

Source§

impl SqrtRatio for Fq

Source§

const T_MINUS1_OVER2: [u64; 4] = T_MINUS1_OVER2