Struct libbgs::numbers::FpNum

source ·
pub struct FpNum<const P: u128>(_);
Expand description

An integer modulo P.

Example

use libbgs::numbers::FpNum;
let x = FpNum::<7>::from(5);
let y = FpNum::<7>::from(6);
let z = x * y;
assert_eq!(z, FpNum::from(30 % 7));

For more informtion on the internal representation, see: Montgomery, Peter (April 1985). “Modular Multiplication Without Trial Division”. Mathematics of Computation. 44 (170): 519-521.

Implementations§

source§

impl<const P: u128> FpNum<P>

source

pub const ZERO: FpNum<P> = _

The constant 0.

source

pub const TWO_INV: FpNum<P> = _

The constant $2^{-1}$.

source

pub const fn legendre(&self) -> FpNum<P>

Returns the Legendre symbol of a modulo P, i.e., $$\left(\frac{a}{p}\right)_L = a^{\frac{p - 1}{2}} \mod p$$.

source

pub const fn int_sqrt(&self) -> Option<FpNum<P>>

Calculates this number’s square root, if it is a quadratic residue; otherwise, returns None.

source

pub const fn find_nonresidue() -> FpNum<P>

Returns a quadratic nonresidue modulo p.

source

pub const fn raw(&self) -> u128

Returns the Montgomery representation of this number.

Trait Implementations§

source§

impl<const P: u128> Add<&FpNum<P>> for &FpNum<P>

§

type Output = FpNum<P>

The resulting type after applying the + operator.
source§

fn add(self, rhs: &FpNum<P>) -> FpNum<P>

Performs the + operation. Read more
source§

impl<const P: u128> Add<&FpNum<P>> for FpNum<P>

§

type Output = FpNum<P>

The resulting type after applying the + operator.
source§

fn add(self, rhs: &FpNum<P>) -> FpNum<P>

Performs the + operation. Read more
source§

impl<const P: u128> Add<FpNum<P>> for &FpNum<P>

§

type Output = FpNum<P>

The resulting type after applying the + operator.
source§

fn add(self, rhs: FpNum<P>) -> FpNum<P>

Performs the + operation. Read more
source§

impl<const P: u128> Add<FpNum<P>> for FpNum<P>

§

type Output = FpNum<P>

The resulting type after applying the + operator.
source§

fn add(self, rhs: FpNum<P>) -> FpNum<P>

Performs the + operation. Read more
source§

impl<const P: u128> Clone for FpNum<P>

source§

fn clone(&self) -> FpNum<P>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<const P: u128> Debug for FpNum<P>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<const P: u128> From<FpNum<P>> for QuadNum<P>

source§

fn from(value: FpNum<P>) -> QuadNum<P>

Converts to this type from the input type.
source§

impl<const P: u128> From<FpNum<P>> for u128

source§

fn from(src: FpNum<P>) -> u128

Converts to this type from the input type.
source§

impl<const P: u128> From<u128> for FpNum<P>

source§

fn from(src: u128) -> FpNum<P>

Converts to this type from the input type.
source§

impl<S, const P: u128> FromChi<S, P> for FpNum<P>where FpNum<P>: Factor<S>,

source§

fn from_chi<const L: usize>( chi: &SylowElem<S, L, FpNum<P>>, decomp: &SylowDecomp<S, L, FpNum<P>> ) -> FpNum<P>

Returns $\chi + \chi^{-1}$.
source§

fn from_chi_conj<const L: usize>( chi: &SylowElem<S, L, FpNum<P>>, decomp: &SylowDecomp<S, L, FpNum<P>> ) -> FpNum<P>

Returns $\chi - \chi^{-1}$.
source§

impl<const P: u128> GroupElem for FpNum<P>

source§

const ONE: Self = _

The unique identity element of this group.
source§

const SIZE: u128 = _

The size of the group this element belongs to.
source§

fn multiply(&self, other: &FpNum<P>) -> FpNum<P>

Returns the product of two elements under the group binary operator. If you implement this trait, you must guarantee that the operation is associative; that is, a.multiply(b.multiply(c)) == a.multiply(b).multiply(c).
source§

fn inverse(&self) -> FpNum<P>

Returns the multiplicative inverse of this element. If you implement this trait, you must guarantee x.inverse().multiply(x) and x.multiply(x.inverse()) both evaluate to ONE.
source§

const ONE_256: [Self; 256] = _

👎Deprecated: To be replaced by inline const expressions once stabilized.
! 256 copies of Self::ONE in an array.
source§

fn pow(&self, n: u128) -> Self

Raises this element to the power of n.
source§

fn order<S>(&self) -> u128where Self: Factor<S>,

Returns the order of this element, that is, the smallest positive power p for which a.pow(p).is_one() returns True.
source§

impl<const P: u128> Hash for FpNum<P>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<const P: u128> Mul<&FpNum<P>> for &FpNum<P>

§

type Output = FpNum<P>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: &FpNum<P>) -> FpNum<P>

Performs the * operation. Read more
source§

impl<const P: u128> Mul<&FpNum<P>> for FpNum<P>

§

type Output = FpNum<P>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: &FpNum<P>) -> FpNum<P>

Performs the * operation. Read more
source§

impl<const P: u128> Mul<FpNum<P>> for &FpNum<P>

§

type Output = FpNum<P>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: FpNum<P>) -> FpNum<P>

Performs the * operation. Read more
source§

impl<const P: u128> Mul<FpNum<P>> for FpNum<P>

§

type Output = FpNum<P>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: FpNum<P>) -> FpNum<P>

Performs the * operation. Read more
source§

impl<const P: u128> Mul<FpNum<P>> for u128

§

type Output = FpNum<P>

The resulting type after applying the * operator.
source§

fn mul(self, rhs: FpNum<P>) -> FpNum<P>

Performs the * operation. Read more
source§

impl<const P: u128> MulAssign<FpNum<P>> for FpNum<P>

source§

fn mul_assign(&mut self, rhs: FpNum<P>)

Performs the *= operation. Read more
source§

impl<const P: u128> Neg for &FpNum<P>

§

type Output = FpNum<P>

The resulting type after applying the - operator.
source§

fn neg(self) -> FpNum<P>

Performs the unary - operation. Read more
source§

impl<const P: u128> Neg for FpNum<P>

§

type Output = FpNum<P>

The resulting type after applying the - operator.
source§

fn neg(self) -> FpNum<P>

Performs the unary - operation. Read more
source§

impl<const P: u128> PartialEq<FpNum<P>> for FpNum<P>

source§

fn eq(&self, other: &FpNum<P>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<const P: u128> Sub<&FpNum<P>> for &FpNum<P>

§

type Output = FpNum<P>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: &FpNum<P>) -> FpNum<P>

Performs the - operation. Read more
source§

impl<const P: u128> Sub<&FpNum<P>> for FpNum<P>

§

type Output = FpNum<P>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: &FpNum<P>) -> FpNum<P>

Performs the - operation. Read more
source§

impl<const P: u128> Sub<FpNum<P>> for &FpNum<P>

§

type Output = FpNum<P>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: FpNum<P>) -> FpNum<P>

Performs the - operation. Read more
source§

impl<const P: u128> Sub<FpNum<P>> for FpNum<P>

§

type Output = FpNum<P>

The resulting type after applying the - operator.
source§

fn sub(self, rhs: FpNum<P>) -> FpNum<P>

Performs the - operation. Read more
source§

impl<S, const P: u128> SylowDecomposable<S> for FpNum<P>where FpNum<P>: Factor<S>,

source§

fn find_sylow_generator(i: usize) -> FpNum<P>

Finds a Sylow generator for the Sylow subgroup of prime power index i.
source§

fn is_sylow_generator(candidate: &Self, d: (u128, usize)) -> Option<Self>

True if the given element is a generator of the Sylow subgroup of the prime power represented by d.
source§

fn count_elements_of_order(ds: &[usize]) -> u128

Returns the number of elements of a particular order. The argument is the powers of the prime factors of the group’s order.
source§

impl<const P: u128> Copy for FpNum<P>

source§

impl<const P: u128> Eq for FpNum<P>

source§

impl<const P: u128> StructuralEq for FpNum<P>

source§

impl<const P: u128> StructuralPartialEq for FpNum<P>

Auto Trait Implementations§

§

impl<const P: u128> RefUnwindSafe for FpNum<P>

§

impl<const P: u128> Send for FpNum<P>

§

impl<const P: u128> Sync for FpNum<P>

§

impl<const P: u128> Unpin for FpNum<P>

§

impl<const P: u128> UnwindSafe for FpNum<P>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.