Skip to main content

Affine

Struct Affine 

Source
pub struct Affine<P: DOCurveConfig> { /* private fields */ }
Expand description

Affine coordinates for a point on an elliptic curve in double-odd form, over the base field P::BaseField.

Instead of using the (x,y)-coordinate system of the original double-odd paper (https://doubleodd.group/doubleodd.pdf), the (e,u)-coordinate system from the follow-up paper (https://doubleodd.group/doubleodd-jq.pdf) was implemented. This coordinate system allows for the new curve equation e**2 = (a-4*b)*u**4 - 2a*u**2 + 1, which is of the Jacobi quartic form, allowing for faster addition/doubling formulae. Additionally, these coordinates allow for more efficient en/decoding.

  • In general: P = (e,u) = (u**2*(x - b/x),x/y)
  • P and P+N are representants of the same group element.
  • P+N = (-e,-u), -P = (e,-u), and -P+N = (-e,u)
  • The group neutral is represented by the point at infinity O = (1,0) and N = O+N = (-1,0)

Implementations§

Source§

impl<P: DOCurveConfig> Affine<P>

Source

pub fn new(e: P::BaseField, u: P::BaseField) -> Self

Source

pub const fn new_unchecked(e: P::BaseField, u: P::BaseField) -> Self

Source

pub const fn identity() -> Self

Returns one of the representants for the identity, namely the point-at-infinity (1,0).

The other representant N=(-1,0) of the identity could also be returned, but the implementation of formulas only requires one representant.

Source

pub fn get_point_from_u_unchecked( u: P::BaseField, greatest: bool, ) -> Option<Self>

Source

pub fn get_e_from_u(u: P::BaseField) -> Option<P::BaseField>

Source

pub fn get_es_from_u_unchecked( u: P::BaseField, ) -> Option<(P::BaseField, P::BaseField)>

Source

pub fn is_on_curve(&self) -> bool

Checks if self is a valid point on the curve, using the curve equation e**2 = (a-4*b)*u**4 - 2a*u**2 + 1

Trait Implementations§

Source§

impl<'a, P: DOCurveConfig> Add<&'a Projective<P>> for Affine<P>

Source§

type Output = Projective<P>

The resulting type after applying the + operator.
Source§

fn add(self, other: &'a Projective<P>) -> Projective<P>

Performs the + operation. Read more
Source§

impl<P: DOCurveConfig> Add<Projective<P>> for Affine<P>

Source§

type Output = Projective<P>

The resulting type after applying the + operator.
Source§

fn add(self, other: Projective<P>) -> Projective<P>

Performs the + operation. Read more
Source§

impl<P: DOCurveConfig, T: Borrow<Self>> Add<T> for Affine<P>

Source§

fn add(self, other: T) -> Projective<P>

Using Algorithm 3 from https://doubleodd.group/doubleodd-jq.pdf, simplified because both points are affine (n2 = 1, n5 = T1 + T2).

Source§

type Output = Projective<P>

The resulting type after applying the + operator.
Source§

impl<P: DOCurveConfig> AffineRepr for Affine<P>

Source§

fn mul_by_cofactor_to_group(&self) -> Self::Group

Multiplies this element by the cofactor and output the resulting projective element.

Source§

fn clear_cofactor(&self) -> Self

Performs cofactor clearing. The default method is simply to multiply by the cofactor. Some curves can implement a more efficient algorithm.

Source§

const GENERATOR: Self = P::GENERATOR

Source§

const ZERO: Self

Source§

type Config = P

Source§

type BaseField = <P as CurveConfig>::BaseField

The finite field over which this curve is defined.
Source§

type ScalarField = <P as CurveConfig>::ScalarField

Source§

type Group = Projective<P>

The projective representation of points on this curve.
Source§

fn xy(&self) -> Option<(Self::BaseField, Self::BaseField)>

Returns the x and y coordinates of this affine point.
Source§

fn generator() -> Self

Returns a fixed generator of unknown exponent.
Source§

fn zero() -> Self

Returns the point at infinity.
Source§

fn is_zero(&self) -> bool

Is self the point at infinity?
Source§

fn from_random_bytes(bytes: &[u8]) -> Option<Self>

Returns a group element if the set of bytes forms a valid group element, otherwise returns None. This function is primarily intended for sampling random group elements from a hash-function or RNG output.
Source§

fn mul_bigint(&self, by: impl AsRef<[u64]>) -> Self::Group

Performs scalar multiplication of this element with mixed addition.
Source§

fn x(&self) -> Option<Self::BaseField>

Returns the x coordinate of this affine point.
Source§

fn y(&self) -> Option<Self::BaseField>

Returns the y coordinate of this affine point.
Source§

fn into_group(self) -> Self::Group

Converts self into the projective representation.
Source§

fn mul_by_cofactor(&self) -> Self

Multiplies this element by the cofactor.
Source§

fn mul_by_cofactor_inv(&self) -> Self

Multiplies this element by the inverse of the cofactor in Self::ScalarField.
Source§

impl<P: DOCurveConfig> CanonicalDeserialize for Affine<P>

Source§

fn deserialize_with_mode<R: Read>( reader: R, compress: Compress, validate: Validate, ) -> Result<Self, SerializationError>

The general deserialize method that takes in customization flags.
Source§

fn deserialize_compressed<R>(reader: R) -> Result<Self, SerializationError>
where R: Read,

Reads Self from reader using the compressed form if applicable. Performs validation if applicable.
Source§

fn deserialize_compressed_unchecked<R>( reader: R, ) -> Result<Self, SerializationError>
where R: Read,

Reads Self from reader using the compressed form if applicable, without validating the deserialized value. Read more
Source§

fn deserialize_uncompressed<R>(reader: R) -> Result<Self, SerializationError>
where R: Read,

Reads Self from reader using the uncompressed form. Performs validation if applicable.
Source§

fn deserialize_uncompressed_unchecked<R>( reader: R, ) -> Result<Self, SerializationError>
where R: Read,

Reads Self from reader using the uncompressed form, without validating the deserialized value. Read more
Source§

impl<P: DOCurveConfig> CanonicalSerialize for Affine<P>

Source§

fn serialize_with_mode<W: Write>( &self, writer: W, compress: Compress, ) -> Result<(), SerializationError>

The general serialize method that takes in customization flags.
Source§

fn serialized_size(&self, compress: Compress) -> usize

Returns the size in bytes of the serialized version of self with the given compression mode.
Source§

fn serialize_compressed<W>(&self, writer: W) -> Result<(), SerializationError>
where W: Write,

Serializes self into writer using the compressed form if applicable.
Source§

fn compressed_size(&self) -> usize

Returns the size in bytes of the compressed serialized version of self.
Source§

fn serialize_uncompressed<W>(&self, writer: W) -> Result<(), SerializationError>
where W: Write,

Serializes self into writer using the uncompressed form.
Source§

fn uncompressed_size(&self) -> usize

Returns the size in bytes of the uncompressed serialized version of self.
Source§

impl<P: DOCurveConfig> Clone for Affine<P>
where P::BaseField: Copy,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<P: DOCurveConfig> Debug for Affine<P>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult

Formats the value using the given formatter. Read more
Source§

impl<P: DOCurveConfig> Default for Affine<P>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<P: DOCurveConfig> Display for Affine<P>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult

Formats the value using the given formatter. Read more
Source§

impl<P: DOCurveConfig> Distribution<Affine<P>> for Standard

Source§

fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Affine<P>

Generates a uniformly random point in the prime-order subgroup.

Source§

fn sample_iter<R>(self, rng: R) -> DistIter<Self, R, T>
where R: Rng, Self: Sized,

Create an iterator that generates random values of T, using rng as the source of randomness. Read more
Source§

fn map<F, S>(self, func: F) -> DistMap<Self, F, T, S>
where F: Fn(T) -> S, Self: Sized,

Create a distribution of values of ‘S’ by mapping the output of Self through the closure F Read more
Source§

impl<P: DOCurveConfig> From<Affine<P>> for Projective<P>

Source§

fn from(p: Affine<P>) -> Self

Converts to this type from the input type.
Source§

impl<P: DOCurveConfig> From<Projective<P>> for Affine<P>

Source§

fn from(p: Projective<P>) -> Self

Converts to this type from the input type.
Source§

impl<P: DOCurveConfig> Hash for Affine<P>
where P::BaseField: Hash,

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<P: DOCurveConfig, T: Borrow<P::ScalarField>> Mul<T> for Affine<P>

Source§

type Output = Projective<P>

The resulting type after applying the * operator.
Source§

fn mul(self, other: T) -> Self::Output

Performs the * operation. Read more
Source§

impl<P: DOCurveConfig> Neg for Affine<P>

Source§

type Output = Affine<P>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Self

Performs the unary - operation. Read more
Source§

impl<P: DOCurveConfig> PartialEq<Affine<P>> for Projective<P>

Source§

fn eq(&self, other: &Affine<P>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<P: DOCurveConfig> PartialEq<Projective<P>> for Affine<P>

Source§

fn eq(&self, other: &Projective<P>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<P: DOCurveConfig> PartialEq for Affine<P>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a, P: DOCurveConfig> Sub<&'a Projective<P>> for Affine<P>

Source§

type Output = Projective<P>

The resulting type after applying the - operator.
Source§

fn sub(self, other: &'a Projective<P>) -> Projective<P>

Performs the - operation. Read more
Source§

impl<P: DOCurveConfig> Sub<Projective<P>> for Affine<P>

Source§

type Output = Projective<P>

The resulting type after applying the - operator.
Source§

fn sub(self, other: Projective<P>) -> Projective<P>

Performs the - operation. Read more
Source§

impl<P: DOCurveConfig, T: Borrow<Self>> Sub<T> for Affine<P>

Source§

type Output = Projective<P>

The resulting type after applying the - operator.
Source§

fn sub(self, other: T) -> Projective<P>

Performs the - operation. Read more
Source§

impl<M: DOCurveConfig, ConstraintF: Field> ToConstraintField<ConstraintF> for Affine<M>
where M::BaseField: ToConstraintField<ConstraintF>,

Source§

fn to_field_elements(&self) -> Option<Vec<ConstraintF>>

Source§

impl<P: DOCurveConfig> Valid for Affine<P>

Source§

fn check(&self) -> Result<(), SerializationError>

Checks whether self is valid. If self is valid, returns Ok(()). Otherwise, returns an error describing the failure. This method is called by deserialize_with_mode if validate is Validate::Yes.
Source§

const TRIVIAL_CHECK: bool = false

Whether the check method is trivial (i.e. always returns Ok(())). If this is true, the batch_check method will skip all checks and return Ok(()). This should be set to true for types where check is trivial, e.g. integers, field elements, etc. This is false by default. This is primarily an optimization to skip unnecessary checks in batch_check.
Source§

fn batch_check<'a>( batch: impl Iterator<Item = &'a Self> + Send, ) -> Result<(), SerializationError>
where Self: 'a,

Checks whether all items in batch are valid. If all items are valid, returns Ok(()). Otherwise, returns an error describing the first failure.
Source§

impl<P: DOCurveConfig> Zeroize for Affine<P>

Source§

fn zeroize(&mut self)

Zero out this object from memory using Rust intrinsics which ensure the zeroization operation is not “optimized away” by the compiler.
Source§

impl<P: DOCurveConfig> Copy for Affine<P>
where P::BaseField: Copy,

Source§

impl<P: DOCurveConfig> Eq for Affine<P>

Auto Trait Implementations§

§

impl<P> Freeze for Affine<P>
where <P as CurveConfig>::BaseField: Freeze,

§

impl<P> RefUnwindSafe for Affine<P>

§

impl<P> Send for Affine<P>

§

impl<P> Sync for Affine<P>

§

impl<P> Unpin for Affine<P>
where <P as CurveConfig>::BaseField: Unpin,

§

impl<P> UnsafeUnpin for Affine<P>

§

impl<P> UnwindSafe for Affine<P>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CanonicalSerializeHashExt for T

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> UniformRand for T

Source§

fn rand<R>(rng: &mut R) -> T
where R: Rng + ?Sized,

§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V