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>
impl<C: Curve> Domain<C>
Sourcepub fn new(
curve: C,
x: &Number,
y: &Number,
order: &Number,
cofactor: &Number,
) -> Result<Domain<C>, CurveError>
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.
Sourcepub fn cofactor(&self) -> &Number
pub fn cofactor(&self) -> &Number
The number of points of the curve over the order of the generator.
Sourcepub fn mul_generator(&self, k: &Number) -> Point<'_, C>
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.
Sourcepub fn mul_add<'c>(
&'c self,
a: &Number,
b: &Number,
point: &Point<'c, C>,
) -> Point<'c, C>
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.
Sourcepub fn in_subgroup(&self, point: &Point<'_, C>) -> bool
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).
Sourcepub fn clear_cofactor<'c>(&self, point: &Point<'c, C>) -> Point<'c, C>
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.