pub struct Point<'c, C: Curve> { /* private fields */ }Expand description
A point of the curve C, which it borrows: always on the curve, as every way to get one
checks.
It is held in a projective form in the field’s own representation, so the group’s operations
take no inversion, and coordinates makes the one inversion they need
when they are asked for. Every operator takes the points owned or borrowed; +=, -= and
*=, and the operators on an owned left operand, keep its vector.
Scalars are numbers of any sign and length. Nothing here is constant-time: the times of the additions and doublings, and of a product, depend on the bits of the scalar, so it is not meant for secret scalars, such as private keys, where whoever can time it could learn them.
§Panics
The operators panic for two points of different curves.
§Examples
use a::math::ec::{Curve, 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();
let p = curve.point(&n(3), &n(6)).unwrap();
// The point has order 5.
assert_eq!(&p * &n(2) + &p * &n(3), curve.identity());
assert!((&p * &n(5)).is_identity());
assert_eq!(-&p, &p * &n(4));Implementations§
Source§impl<'c, C: Curve> Point<'c, C>
impl<'c, C: Curve> Point<'c, C>
Sourcepub fn is_identity(&self) -> bool
pub fn is_identity(&self) -> bool
Whether this is the neutral element of the curve’s group.
Sourcepub fn coordinates(&self) -> Option<(Number, Number)>
pub fn coordinates(&self) -> Option<(Number, Number)>
The affine coordinates (x, y), below the prime, or None for the point at infinity. An
Edwards curve has none: its neutral element is (0, 1).
This is the one inversion that the group’s operations leave for the end. For many points,
coordinates_of shares it.
Sourcepub fn coordinates_of(points: &[Point<'c, C>]) -> Vec<Option<(Number, Number)>>
pub fn coordinates_of(points: &[Point<'c, C>]) -> Vec<Option<(Number, Number)>>
The affine coordinates of each of the points, as
coordinates gives them, with one inversion for all of them and
about three products for each.
§Panics
Panics for points of different curves.
Sourcepub fn compress(&self) -> Vec<u8> ⓘ
pub fn compress(&self) -> Vec<u8> ⓘ
The point in its shortest encoding, which Curve::point_from_bytes reads: SEC 1’s compressed
form on Weierstrass and Montgomery curves, a byte for the parity of y and then x in
big-endian order, a single zero byte for the point at infinity; on Edwards curves that of
RFC 8032, y in little-endian order, with the parity of x in the top bit.
Sourcepub fn to_bytes(&self) -> Vec<u8> ⓘ
pub fn to_bytes(&self) -> Vec<u8> ⓘ
The point in the encoding with both coordinates, which Curve::point_from_bytes reads: SEC 1’s
uncompressed form on Weierstrass and Montgomery curves, on Edwards curves x and then y
in little-endian order.
Trait Implementations§
Source§impl<'c, C: Curve> AddAssign for Point<'c, C>
impl<'c, C: Curve> AddAssign for Point<'c, C>
Source§fn add_assign(&mut self, rhs: Point<'c, C>)
fn add_assign(&mut self, rhs: Point<'c, C>)
+= operation. Read moreSource§impl<'c, C: Curve> AddAssign<&Point<'c, C>> for Point<'c, C>
impl<'c, C: Curve> AddAssign<&Point<'c, C>> for Point<'c, C>
Source§fn add_assign(&mut self, rhs: &Point<'c, C>)
fn add_assign(&mut self, rhs: &Point<'c, C>)
+= operation. Read moreimpl<C: Curve> Eq for Point<'_, C>
Source§impl<C: Curve> Hash for Point<'_, C>
By the affine coordinates, the same for equal points: each hash takes an inversion.
impl<C: Curve> Hash for Point<'_, C>
By the affine coordinates, the same for equal points: each hash takes an inversion.
Source§impl<C: Curve> MulAssign<&Number> for Point<'_, C>
impl<C: Curve> MulAssign<&Number> for Point<'_, C>
Source§fn mul_assign(&mut self, k: &Number)
fn mul_assign(&mut self, k: &Number)
*= operation. Read moreSource§impl<C: Curve> MulAssign<Number> for Point<'_, C>
impl<C: Curve> MulAssign<Number> for Point<'_, C>
Source§fn mul_assign(&mut self, k: Number)
fn mul_assign(&mut self, k: Number)
*= operation. Read moreSource§impl<C: Curve> PartialEq for Point<'_, C>
Two points are equal when they are the same point, in whatever projective form each is held.
This needs no inversion.
impl<C: Curve> PartialEq for Point<'_, C>
Two points are equal when they are the same point, in whatever projective form each is held. This needs no inversion.