This commit is contained in:
Dmitry Vagner 2023-04-26 09:54:46 -07:00
parent f225ea495d
commit d928a70b6f

View File

@ -1,4 +1,4 @@
use std::ops::Add;
use std::ops::{Add, Mul, Neg};
use ethereum_types::U256;
use rand::Rng;
@ -42,6 +42,38 @@ impl Add for Curve {
}
}
impl Neg for Curve {
type Output = Curve;
fn neg(self) -> Self {
Curve {
x: self.x,
y: -self.y,
}
}
}
impl Mul<i32> for Curve {
type Output = Curve;
fn mul(self, other: i32) -> Self {
let mut result: Curve = self;
if other.is_negative() {
result = -result;
}
let mut multiplier = result;
let mut exp = other.abs() as usize;
while exp > 0 {
if exp % 2 == 1 {
result = result + multiplier;
}
exp >>= 1;
multiplier = multiplier + multiplier;
}
result
}
}
// The twisted curve consists of pairs (x, y): (Fp2, Fp2) | y^2 = x^3 + 3/(9 + i)
#[derive(Debug, Copy, Clone, PartialEq)]
pub struct TwistedCurve {