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§
Sourcefn mod_add(&self, other: &Self, modulus: &Self) -> Self
fn mod_add(&self, other: &Self, modulus: &Self) -> Self
Returns (self + other) % modulus
.
Panics if the modulus is zero.
Sourcefn mod_sub(&self, other: &Self, modulus: &Self) -> Self
fn mod_sub(&self, other: &Self, modulus: &Self) -> Self
Returns (self - other) % modulus
.
Panics if the modulus is zero.
Sourcefn mod_mul(&self, other: &Self, modulus: &Self) -> Self
fn mod_mul(&self, other: &Self, modulus: &Self) -> Self
Returns (self * other) % modulus
.
Panics if the modulus is zero.
Sourcefn inv(&self, modulus: &Self) -> Self
fn inv(&self, modulus: &Self) -> Self
Extended Eulidean Algorithm(EEA) to calculate x^(-1) mod p
Sourcefn right_shift(&self, carry: u32) -> Self
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.