Skip to main content

Domain

Struct Domain 

Source
pub struct Domain<C: Curve> { /* private fields */ }
Expand description

A curve with a generator of a subgroup, the subgroup’s order and its cofactor: the domain parameters that the named curves are, and that any curve can be given. It dereferences to its curve.

It keeps the multiples of the generator once mul_generator has first needed them, as a Divisor keeps what it prepares.

§Examples

use a::math::ec::{Curve, Domain, Weierstrass};
use a::math::numbers::{ByteOrder, Number};

let n = |x| Number::new_from_u32(x, ByteOrder::BigEndian);
let curve = Weierstrass::new(&n(2), &n(3), &n(97)).unwrap();
// (3, 6) has order 5, and the curve 100 points.
let domain = Domain::new(curve, &n(3), &n(6), &n(5), &n(20)).unwrap();
let p = domain.mul_generator(&n(2));
assert_eq!(p, domain.generator().double());
assert!(domain.in_subgroup(&p));

Implementations§

Source§

impl<C: Curve> Domain<C>

Source

pub fn new( curve: C, x: &Number, y: &Number, order: &Number, cofactor: &Number, ) -> Result<Domain<C>, CurveError>

curve with the generator (x, y) of the given order and cofactor.

§Errors

CurveError::NotOnCurve when (x, y) is not on the curve; CurveError::WrongOrder when order is not positive or order times it is not the neutral element.

Source

pub fn generator(&self) -> Point<'_, C>

The generator.

Source

pub fn order(&self) -> &Number

The order of the generator.

Source

pub fn cofactor(&self) -> &Number

The number of points of the curve over the order of the generator.

Source

pub fn mul_generator(&self, k: &Number) -> Point<'_, C>

k times the generator, from a table of its multiples, several times faster than a product of any other point. The first call builds the table.

Source

pub fn mul_add<'c>( &'c self, a: &Number, b: &Number, point: &Point<'c, C>, ) -> Point<'c, C>

a times the generator plus b times point, as a signature’s verification needs.

§Panics

Panics if point is not on this curve.

Source

pub fn in_subgroup(&self, point: &Point<'_, C>) -> bool

Whether point is on this curve and order times it is the neutral element. When the order is coprime to the cofactor, as on every named curve, those are the points of the generator’s subgroup. Otherwise more can be: on y^2 = x^3 - x modulo 5, with the generator (0, 0) of order 2 and the cofactor 4, so is (1, 0).

Source

pub fn clear_cofactor<'c>(&self, point: &Point<'c, C>) -> Point<'c, C>

point times the cofactor, which lands in the generator’s subgroup when the order is coprime to the cofactor.

§Panics

Panics if point is not on this curve.

Trait Implementations§

Source§

impl<C: Curve> Deref for Domain<C>

Source§

type Target = C

The resulting type after dereferencing.
Source§

fn deref(&self) -> &C

Dereferences the value.

Auto Trait Implementations§

§

impl<C> !Freeze for Domain<C>

§

impl<C> RefUnwindSafe for Domain<C>
where C: RefUnwindSafe,

§

impl<C> Send for Domain<C>
where C: Send,

§

impl<C> Sync for Domain<C>
where C: Sync,

§

impl<C> Unpin for Domain<C>
where C: Unpin,

§

impl<C> UnsafeUnpin for Domain<C>
where C: UnsafeUnpin,

§

impl<C> UnwindSafe for Domain<C>
where C: UnwindSafe,

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> 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.