use crate::fp::{Fp2, FpBackend};
use crate::params::SecurityLevel;
use zeroize::Zeroize;
pub mod basis;
pub mod curve;
pub mod isogeny;
pub mod jacobian;
pub mod pairing;
pub mod point;
pub use isogeny::{EcKps2, EcKps4};
#[derive(Clone, Debug)]
pub struct EcPoint<L: SecurityLevel> {
pub x: Fp2<L>,
pub z: Fp2<L>,
}
#[derive(Clone, Debug)]
pub struct JacPoint<L: SecurityLevel> {
pub x: Fp2<L>,
pub y: Fp2<L>,
pub z: Fp2<L>,
}
#[derive(Clone, Debug)]
pub struct AddComponents<L: SecurityLevel> {
pub u: Fp2<L>,
pub v: Fp2<L>,
pub w: Fp2<L>,
}
#[derive(Clone, Debug)]
pub struct EcBasis<L: SecurityLevel> {
pub p: EcPoint<L>,
pub q: EcPoint<L>,
pub pmq: EcPoint<L>,
}
#[derive(Clone, Debug)]
pub struct EcCurve<L: SecurityLevel> {
pub a: Fp2<L>,
pub c: Fp2<L>,
pub a24: EcPoint<L>,
pub is_a24_computed_and_normalized: bool,
}
#[derive(Clone, Debug)]
pub struct EcIsomorphism<L: SecurityLevel> {
pub nx: Fp2<L>,
pub nz: Fp2<L>,
pub d: Fp2<L>,
}
#[derive(Clone, Debug)]
pub struct EcIsogEven<L: SecurityLevel> {
pub curve: EcCurve<L>,
pub kernel: EcPoint<L>,
pub length: u32,
}
impl<L: FpBackend> Default for EcPoint<L> {
#[inline]
fn default() -> Self {
EcPoint::identity()
}
}
impl<L: FpBackend> EcPoint<L> {
#[inline]
pub fn identity() -> Self {
Self {
x: Fp2::one(),
z: Fp2::zero(),
}
}
#[inline]
pub fn new(x: Fp2<L>, z: Fp2<L>) -> Self {
Self { x, z }
}
}
impl<L: FpBackend> Default for JacPoint<L> {
#[inline]
fn default() -> Self {
JacPoint::identity()
}
}
impl<L: FpBackend> JacPoint<L> {
#[inline]
pub fn identity() -> Self {
Self {
x: Fp2::zero(),
y: Fp2::one(),
z: Fp2::zero(),
}
}
#[inline]
pub fn new(x: Fp2<L>, y: Fp2<L>, z: Fp2<L>) -> Self {
Self { x, y, z }
}
}
impl<L: FpBackend> Default for EcCurve<L> {
#[inline]
fn default() -> Self {
Self {
a: Fp2::zero(),
c: Fp2::one(),
a24: EcPoint::identity(),
is_a24_computed_and_normalized: false,
}
}
}
impl<L: FpBackend> EcBasis<L> {
#[inline]
pub fn new(p: EcPoint<L>, q: EcPoint<L>, pmq: EcPoint<L>) -> Self {
Self { p, q, pmq }
}
}
impl<L: FpBackend> AddComponents<L> {
#[inline]
pub fn new(u: Fp2<L>, v: Fp2<L>, w: Fp2<L>) -> Self {
Self { u, v, w }
}
}
impl<L: SecurityLevel> Zeroize for EcPoint<L> {
#[inline]
fn zeroize(&mut self) {
self.x.zeroize();
self.z.zeroize();
}
}
impl<L: SecurityLevel> Zeroize for EcBasis<L> {
#[inline]
fn zeroize(&mut self) {
self.p.zeroize();
self.q.zeroize();
self.pmq.zeroize();
}
}
impl<L: SecurityLevel> Zeroize for EcCurve<L> {
#[inline]
fn zeroize(&mut self) {
self.a.zeroize();
self.c.zeroize();
self.a24.zeroize();
self.is_a24_computed_and_normalized = false;
}
}