Skip to main content

Point

Struct Point 

Source
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>

Source

pub fn curve(&self) -> &'c C

The curve of the point.

Source

pub fn is_identity(&self) -> bool

Whether this is the neutral element of the curve’s group.

Source

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.

Source

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.

Source

pub fn double(&self) -> Self

2 p, which costs less than p + p.

Source

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.

Source

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.

Source

pub fn prepare(&self, bits: usize) -> Prepared<'c, C>

The multiples of this point computed once for all, for scalars of up to bits bits, as a Divisor is for divisions. Measured on an Apple M4 Max on P-256, building the table for 256 bits took the time of 30 products, and each product afterwards an eighth of the time of one of Mul.

Trait Implementations§

Source§

impl<'c, C: Curve> Add for Point<'c, C>

Source§

type Output = Point<'c, C>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Point<'c, C>) -> Point<'c, C>

Performs the + operation. Read more
Source§

impl<'c, C: Curve> Add<&Point<'c, C>> for Point<'c, C>

Source§

type Output = Point<'c, C>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Point<'c, C>) -> Point<'c, C>

Performs the + operation. Read more
Source§

impl<'c, C: Curve> Add<&Point<'c, C>> for &Point<'c, C>

Source§

type Output = Point<'c, C>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &Point<'c, C>) -> Point<'c, C>

Performs the + operation. Read more
Source§

impl<'c, C: Curve> Add<Point<'c, C>> for &Point<'c, C>

Source§

type Output = Point<'c, C>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: Point<'c, C>) -> Point<'c, C>

Performs the + operation. Read more
Source§

impl<'c, C: Curve> AddAssign for Point<'c, C>

Source§

fn add_assign(&mut self, rhs: Point<'c, C>)

Performs the += operation. Read more
Source§

impl<'c, C: Curve> AddAssign<&Point<'c, C>> for Point<'c, C>

Source§

fn add_assign(&mut self, rhs: &Point<'c, C>)

Performs the += operation. Read more
Source§

impl<C: Curve> Clone for Point<'_, C>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
Source§

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

Performs copy-assignment from source. Read more
Source§

impl<C: Curve> Debug for Point<'_, C>

Source§

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

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

impl<C: Curve> Display for Point<'_, C>

(x, y) in decimal, or infinity.

Source§

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

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

impl<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.

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<'c, C: Curve> Mul<&Number> for Point<'c, C>

Source§

type Output = Point<'c, C>

The resulting type after applying the * operator.
Source§

fn mul(self, k: &Number) -> Point<'c, C>

Performs the * operation. Read more
Source§

impl<'c, C: Curve> Mul<&Number> for &Point<'c, C>

Source§

type Output = Point<'c, C>

The resulting type after applying the * operator.
Source§

fn mul(self, k: &Number) -> Point<'c, C>

Performs the * operation. Read more
Source§

impl<'c, C: Curve> Mul<&Point<'c, C>> for &Number

Source§

type Output = Point<'c, C>

The resulting type after applying the * operator.
Source§

fn mul(self, p: &Point<'c, C>) -> Point<'c, C>

Performs the * operation. Read more
Source§

impl<'c, C: Curve> Mul<&Point<'c, C>> for Number

Source§

type Output = Point<'c, C>

The resulting type after applying the * operator.
Source§

fn mul(self, p: &Point<'c, C>) -> Point<'c, C>

Performs the * operation. Read more
Source§

impl<'c, C: Curve> Mul<Number> for Point<'c, C>

Source§

type Output = Point<'c, C>

The resulting type after applying the * operator.
Source§

fn mul(self, k: Number) -> Point<'c, C>

Performs the * operation. Read more
Source§

impl<'c, C: Curve> Mul<Number> for &Point<'c, C>

Source§

type Output = Point<'c, C>

The resulting type after applying the * operator.
Source§

fn mul(self, k: Number) -> Point<'c, C>

Performs the * operation. Read more
Source§

impl<'c, C: Curve> Mul<Point<'c, C>> for &Number

Source§

type Output = Point<'c, C>

The resulting type after applying the * operator.
Source§

fn mul(self, p: Point<'c, C>) -> Point<'c, C>

Performs the * operation. Read more
Source§

impl<'c, C: Curve> Mul<Point<'c, C>> for Number

Source§

type Output = Point<'c, C>

The resulting type after applying the * operator.
Source§

fn mul(self, p: Point<'c, C>) -> Point<'c, C>

Performs the * operation. Read more
Source§

impl<C: Curve> MulAssign<&Number> for Point<'_, C>

Source§

fn mul_assign(&mut self, k: &Number)

Performs the *= operation. Read more
Source§

impl<C: Curve> MulAssign<Number> for Point<'_, C>

Source§

fn mul_assign(&mut self, k: Number)

Performs the *= operation. Read more
Source§

impl<'c, C: Curve> Neg for &Point<'c, C>

Source§

type Output = Point<'c, C>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Point<'c, C>

Performs the unary - operation. Read more
Source§

impl<'c, C: Curve> Neg for Point<'c, C>

Source§

type Output = Point<'c, C>

The resulting type after applying the - operator.
Source§

fn neg(self) -> Point<'c, C>

Performs the unary - operation. Read more
Source§

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.

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<'c, C: Curve> Sub for Point<'c, C>

Source§

type Output = Point<'c, C>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Point<'c, C>) -> Point<'c, C>

Performs the - operation. Read more
Source§

impl<'c, C: Curve> Sub<&Point<'c, C>> for Point<'c, C>

Source§

type Output = Point<'c, C>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &Point<'c, C>) -> Point<'c, C>

Performs the - operation. Read more
Source§

impl<'c, C: Curve> Sub<&Point<'c, C>> for &Point<'c, C>

Source§

type Output = Point<'c, C>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: &Point<'c, C>) -> Point<'c, C>

Performs the - operation. Read more
Source§

impl<'c, C: Curve> Sub<Point<'c, C>> for &Point<'c, C>

Source§

type Output = Point<'c, C>

The resulting type after applying the - operator.
Source§

fn sub(self, rhs: Point<'c, C>) -> Point<'c, C>

Performs the - operation. Read more
Source§

impl<'c, C: Curve> SubAssign for Point<'c, C>

Source§

fn sub_assign(&mut self, rhs: Point<'c, C>)

Performs the -= operation. Read more
Source§

impl<'c, C: Curve> SubAssign<&Point<'c, C>> for Point<'c, C>

Source§

fn sub_assign(&mut self, rhs: &Point<'c, C>)

Performs the -= operation. Read more

Auto Trait Implementations§

§

impl<'c, C> Freeze for Point<'c, C>
where &'c C: Freeze,

§

impl<'c, C> RefUnwindSafe for Point<'c, C>

§

impl<'c, C> Send for Point<'c, C>
where &'c C: Send,

§

impl<'c, C> Sync for Point<'c, C>
where &'c C: Sync,

§

impl<'c, C> Unpin for Point<'c, C>
where &'c C: Unpin,

§

impl<'c, C> UnsafeUnpin for Point<'c, C>

§

impl<'c, C> UnwindSafe for Point<'c, C>

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> 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<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> 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 = !

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.