use fff::{PrimeField, PrimeFieldDecodingError, ScalarEngine, SqrtField};
use rand::RngCore;
use std::fmt;
pub mod tests;
mod wnaf;
pub use self::wnaf::Wnaf;
pub trait CurveProjective:
PartialEq
+ Eq
+ Sized
+ Copy
+ Clone
+ Send
+ Sync
+ fmt::Debug
+ fmt::Display
+ 'static
+ serde::Serialize
+ serde::Deserialize<'static>
{
type Engine: ScalarEngine<Fr = Self::Scalar>;
type Scalar: PrimeField + SqrtField;
type Base: SqrtField;
type Affine: CurveAffine<Projective = Self, Scalar = Self::Scalar>;
fn random<R: RngCore>(rng: &mut R) -> Self;
fn zero() -> Self;
fn one() -> Self;
fn is_zero(&self) -> bool;
fn batch_normalization<S: std::borrow::BorrowMut<Self>>(v: &mut [S]);
fn is_normalized(&self) -> bool;
fn double(&mut self);
fn add_assign(&mut self, other: &Self);
fn sub_assign(&mut self, other: &Self) {
let mut tmp = *other;
tmp.negate();
self.add_assign(&tmp);
}
fn add_assign_mixed(&mut self, other: &Self::Affine);
fn negate(&mut self);
fn mul_assign<S: Into<<Self::Scalar as PrimeField>::Repr>>(&mut self, other: S);
fn into_affine(&self) -> Self::Affine;
fn recommended_wnaf_for_scalar(scalar: <Self::Scalar as PrimeField>::Repr) -> usize;
fn recommended_wnaf_for_num_scalars(num_scalars: usize) -> usize;
fn hash(msg: &[u8]) -> Self;
}
pub trait CurveAffine:
Copy
+ Clone
+ Sized
+ Send
+ Sync
+ fmt::Debug
+ fmt::Display
+ PartialEq
+ Eq
+ 'static
+ serde::Serialize
+ serde::Deserialize<'static>
{
type Engine: ScalarEngine<Fr = Self::Scalar>;
type Scalar: PrimeField + SqrtField;
type Base: SqrtField;
type Projective: CurveProjective<Affine = Self, Scalar = Self::Scalar>;
type Uncompressed: EncodedPoint<Affine = Self>;
type Compressed: EncodedPoint<Affine = Self>;
fn zero() -> Self;
fn one() -> Self;
fn is_zero(&self) -> bool;
fn negate(&mut self);
fn mul<S: Into<<Self::Scalar as PrimeField>::Repr>>(&self, other: S) -> Self::Projective;
fn into_projective(&self) -> Self::Projective;
fn into_compressed(&self) -> Self::Compressed {
<Self::Compressed as EncodedPoint>::from_affine(*self)
}
fn into_uncompressed(&self) -> Self::Uncompressed {
<Self::Uncompressed as EncodedPoint>::from_affine(*self)
}
}
pub trait EncodedPoint:
Sized + Send + Sync + AsRef<[u8]> + AsMut<[u8]> + Clone + Copy + 'static
{
type Affine: CurveAffine;
fn empty() -> Self;
fn size() -> usize;
fn into_affine(&self) -> Result<Self::Affine, GroupDecodingError>;
fn into_affine_unchecked(&self) -> Result<Self::Affine, GroupDecodingError>;
fn from_affine(affine: Self::Affine) -> Self;
}
#[derive(thiserror::Error, Debug)]
pub enum GroupDecodingError {
#[error("coordinate(s) do not lie on the curve")]
NotOnCurve,
#[error("the element is not part of an r-order subgroup")]
NotInSubgroup,
#[error("coordinate(s) could not be decoded")]
CoordinateDecodingError(&'static str, #[source] PrimeFieldDecodingError),
#[error("encoding has unexpected compression mode")]
UnexpectedCompressionMode,
#[error("encoding has unexpected information")]
UnexpectedInformation,
}