Trait FeOperation

Source
pub trait FeOperation {
    // Required methods
    fn mod_add(&self, other: &Self, modulus: &Self) -> Self;
    fn mod_sub(&self, other: &Self, modulus: &Self) -> Self;
    fn mod_mul(&self, other: &Self, modulus: &Self) -> Self;
    fn inv(&self, modulus: &Self) -> Self;
    fn right_shift(&self, carry: u32) -> Self;
}
Expand description

Fp 的加法,减法,乘法并不是简单的四则运算。其运算结果的值必须在Fp的有限域中,这样保证椭圆曲线变成离散的点

这里我们规定一个有限域Fp

  • 取大质数p,则有限域中有p-1个有限元:0,1,2…p-1
  • Fp上的加法为模p加法a+b≡c(mod p)
  • Fp上的乘法为模p乘法a×b≡c(mod p)
  • Fp上的减法为模p减法a-b≡c(mod p)
  • Fp上的除法就是乘除数的乘法逆元a÷b≡c(mod p),即 a×b^(-1)≡c (mod p)
  • Fp的乘法单位元为1,零元为0
  • Fp域上满足交换律,结合律,分配律

Required Methods§

Source

fn mod_add(&self, other: &Self, modulus: &Self) -> Self

Returns (self + other) % modulus.

Panics if the modulus is zero.

Source

fn mod_sub(&self, other: &Self, modulus: &Self) -> Self

Returns (self - other) % modulus.

Panics if the modulus is zero.

Source

fn mod_mul(&self, other: &Self, modulus: &Self) -> Self

Returns (self * other) % modulus.

Panics if the modulus is zero.

Source

fn inv(&self, modulus: &Self) -> Self

Extended Eulidean Algorithm(EEA) to calculate x^(-1) mod p

Source

fn right_shift(&self, carry: u32) -> Self

Self >>= carry

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.

Implementations on Foreign Types§

Source§

impl FeOperation for BigUint

Source§

fn mod_add(&self, other: &Self, modulus: &Self) -> BigUint

Source§

fn mod_sub(&self, other: &Self, modulus: &Self) -> BigUint

Source§

fn mod_mul(&self, other: &Self, modulus: &Self) -> BigUint

Source§

fn inv(&self, modulus: &Self) -> BigUint

Source§

fn right_shift(&self, carry: u32) -> BigUint

Implementors§