pub mod edwards25519;
pub mod integer_field;
mod internal;
use digest::{Digest, FixedOutputReset, Reset, Update};
use serde::de::DeserializeOwned;
use serde::Serialize;
use thiserror::Error;
use crate::cipher::stream::Stream;
use crate::dh::{Dh, HmacCompatible};
use crate::encoding::Marshaling;
use core::fmt::{Debug, Display};
use core::ops::{Add, Mul};
use std::io::Write;
pub trait Scalar:
Marshaling
+ Clone
+ Eq
+ PartialEq
+ Ord
+ PartialOrd
+ Debug
+ Add<Self, Output = Self>
+ Mul<Self, Output = Self>
+ Default
+ Serialize
+ DeserializeOwned
+ Display
{
fn set(self, a: &Self) -> Self;
fn set_int64(self, v: i64) -> Self;
fn zero(self) -> Self;
fn sub(self, a: &Self, b: &Self) -> Self;
fn neg(self, a: &Self) -> Self;
fn one(self) -> Self;
fn div(self, a: &Self, b: &Self) -> Self;
fn inv(self, a: &Self) -> Self;
fn pick(self, rand: &mut impl Stream) -> Self;
fn set_bytes(self, bytes: &[u8]) -> Self;
}
pub trait ScalarCanCheckCanonical {
fn is_canonical(&self, b: &[u8]) -> bool;
}
pub trait PointCanCheckCanonicalAndSmallOrder {
fn has_small_order(&self) -> bool;
fn is_canonical(&self, b: &[u8]) -> bool;
}
pub trait Point:
Marshaling
+ Clone
+ Eq
+ PartialEq
+ Ord
+ PartialOrd
+ Debug
+ Default
+ Serialize
+ DeserializeOwned
+ Debug
+ PartialEq
+ Display
{
type SCALAR: Scalar;
fn null(self) -> Self;
fn base(self) -> Self;
fn pick<S: Stream>(self, rand: &mut S) -> Self;
fn set(&mut self, p: &Self) -> Self;
fn embed_len(&self) -> usize;
fn embed<S: Stream>(self, data: Option<&[u8]>, rand: &mut S) -> Self;
fn data(&self) -> Result<Vec<u8>, PointError>;
fn add(self, a: &Self, b: &Self) -> Self;
fn sub(self, a: &Self, b: &Self) -> Self;
fn neg(&mut self, a: &Self) -> Self;
fn mul(self, s: &Self::SCALAR, p: Option<&Self>) -> Self;
}
pub trait AllowsVarTime {
}
pub trait Group: Dh + Clone + Default + Debug + Display {
type POINT: Point;
fn scalar_len(&self) -> usize;
fn scalar(&self) -> <Self::POINT as Point>::SCALAR;
fn point_len(&self) -> usize;
fn point(&self) -> Self::POINT;
fn is_prime_order(&self) -> Option<bool>;
}
pub trait HashFactory {
type T: Hasher + HmacCompatible + Default + Update + Reset + FixedOutputReset + Clone + 'static;
fn hash(&self) -> Self::T {
Default::default()
}
}
pub trait Hasher: Digest + Write {}
impl<T> Hasher for T
where
T: Digest,
T: Write,
{
}
#[derive(Error, Debug)]
pub enum PointError {
#[error("invalid embedded data length")]
EmbedDataLength,
}