pub struct FieldElement { /* private fields */ }Expand description
素域Fp的域元素
这里我们规定一个有限域Fp
- 取大质数p,则有限域中有p-1个有限元:0,1,2…p-1
- 域元素的加法是整数的模p加法,即若a,b ∈ Fp,则a+b = (a+b) mod p;
- 域元素的乘法是整数的模p乘法,即若a,b ∈ Fp,则a · b = (a · b) mod p
- 域元素的减法是整数的模p减法,即若a,b ∈ Fp,则a - b = (a - b) mod p
- Fp上的除法就是乘除数的乘法逆元
a÷b≡c(mod p),即a×b^(-1)≡c (mod p) - Fp的乘法单位元是整数1
- Fp的加法单位元是整数0
- Fp域上满足交换律,结合律,分配律
Implementations§
Source§impl FieldElement
impl FieldElement
pub fn new(x: Fe) -> FieldElement
pub fn from_slice(x: &[u32]) -> FieldElement
pub fn from_number(x: u64) -> FieldElement
pub fn to_bytes_be(&self) -> Vec<u8> ⓘ
pub fn from_bytes_be(bytes: &[u8]) -> Sm2Result<FieldElement>
pub fn to_biguint(&self) -> BigUint
pub fn from_biguint(bi: &BigUint) -> Sm2Result<FieldElement>
pub fn sqrt(&self) -> Sm2Result<FieldElement>
pub fn to_str_radix(&self, radix: u32) -> String
pub fn zero() -> FieldElement
pub fn one() -> FieldElement
pub fn is_even(&self) -> bool
pub fn is_zero(&self) -> bool
pub fn is_one(&self) -> bool
pub fn square(&self) -> FieldElement
pub fn double(&self) -> FieldElement
pub fn modpow(&self, exponent: &BigUint) -> Self
pub fn modinv(&self) -> FieldElement
Trait Implementations§
Source§impl<'a, 'b> Add<&'b FieldElement> for &'a FieldElement
impl<'a, 'b> Add<&'b FieldElement> for &'a FieldElement
Source§type Output = FieldElement
type Output = FieldElement
The resulting type after applying the
+ operator.Source§fn add(self, other: &FieldElement) -> FieldElement
fn add(self, other: &FieldElement) -> FieldElement
Performs the
+ operation. Read moreSource§impl<'a> Add<&'a FieldElement> for FieldElement
impl<'a> Add<&'a FieldElement> for FieldElement
Source§type Output = FieldElement
type Output = FieldElement
The resulting type after applying the
+ operator.Source§impl<'a> Add<FieldElement> for &'a FieldElement
impl<'a> Add<FieldElement> for &'a FieldElement
Source§type Output = FieldElement
type Output = FieldElement
The resulting type after applying the
+ operator.Source§fn add(self, other: FieldElement) -> FieldElement
fn add(self, other: FieldElement) -> FieldElement
Performs the
+ operation. Read moreSource§impl Add for FieldElement
impl Add for FieldElement
Source§type Output = FieldElement
type Output = FieldElement
The resulting type after applying the
+ operator.Source§fn add(self, other: FieldElement) -> FieldElement
fn add(self, other: FieldElement) -> FieldElement
Performs the
+ operation. Read moreSource§impl Clone for FieldElement
impl Clone for FieldElement
Source§fn clone(&self) -> FieldElement
fn clone(&self) -> FieldElement
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for FieldElement
impl Debug for FieldElement
Source§impl Default for FieldElement
impl Default for FieldElement
Source§fn default() -> FieldElement
fn default() -> FieldElement
Returns the “default value” for a type. Read more
Source§impl<'a, 'b> Mul<&'b FieldElement> for &'a FieldElement
impl<'a, 'b> Mul<&'b FieldElement> for &'a FieldElement
Source§type Output = FieldElement
type Output = FieldElement
The resulting type after applying the
* operator.Source§fn mul(self, other: &FieldElement) -> FieldElement
fn mul(self, other: &FieldElement) -> FieldElement
Performs the
* operation. Read moreSource§impl<'a> Mul<&'a FieldElement> for FieldElement
impl<'a> Mul<&'a FieldElement> for FieldElement
Source§type Output = FieldElement
type Output = FieldElement
The resulting type after applying the
* operator.Source§impl<'a> Mul<FieldElement> for &'a FieldElement
impl<'a> Mul<FieldElement> for &'a FieldElement
Source§type Output = FieldElement
type Output = FieldElement
The resulting type after applying the
* operator.Source§fn mul(self, other: FieldElement) -> FieldElement
fn mul(self, other: FieldElement) -> FieldElement
Performs the
* operation. Read moreSource§impl Mul for FieldElement
impl Mul for FieldElement
Source§type Output = FieldElement
type Output = FieldElement
The resulting type after applying the
* operator.Source§fn mul(self, other: FieldElement) -> FieldElement
fn mul(self, other: FieldElement) -> FieldElement
Performs the
* operation. Read moreSource§impl Ord for FieldElement
impl Ord for FieldElement
Source§fn cmp(&self, other: &FieldElement) -> Ordering
fn cmp(&self, other: &FieldElement) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for FieldElement
impl PartialEq for FieldElement
Source§impl PartialOrd for FieldElement
impl PartialOrd for FieldElement
Source§impl<'a, 'b> Sub<&'b FieldElement> for &'a FieldElement
impl<'a, 'b> Sub<&'b FieldElement> for &'a FieldElement
Source§type Output = FieldElement
type Output = FieldElement
The resulting type after applying the
- operator.Source§fn sub(self, other: &FieldElement) -> FieldElement
fn sub(self, other: &FieldElement) -> FieldElement
Performs the
- operation. Read moreSource§impl<'a> Sub<&'a FieldElement> for FieldElement
impl<'a> Sub<&'a FieldElement> for FieldElement
Source§type Output = FieldElement
type Output = FieldElement
The resulting type after applying the
- operator.Source§impl<'a> Sub<FieldElement> for &'a FieldElement
impl<'a> Sub<FieldElement> for &'a FieldElement
Source§type Output = FieldElement
type Output = FieldElement
The resulting type after applying the
- operator.Source§fn sub(self, other: FieldElement) -> FieldElement
fn sub(self, other: FieldElement) -> FieldElement
Performs the
- operation. Read moreSource§impl Sub for FieldElement
impl Sub for FieldElement
Source§type Output = FieldElement
type Output = FieldElement
The resulting type after applying the
- operator.Source§fn sub(self, other: FieldElement) -> FieldElement
fn sub(self, other: FieldElement) -> FieldElement
Performs the
- operation. Read moreimpl Copy for FieldElement
impl Eq for FieldElement
impl StructuralPartialEq for FieldElement
Auto Trait Implementations§
impl Freeze for FieldElement
impl RefUnwindSafe for FieldElement
impl Send for FieldElement
impl Sync for FieldElement
impl Unpin for FieldElement
impl UnwindSafe for FieldElement
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more