pub struct Point<E: Curve>(/* private fields */);
Expand description
Torsion-free point on elliptic curve E
Any instance of Point
is guaranteed to be on curve E
and free of torsion component. Note that
identity point (sometimes called point at infinity) is a valid point that can be obtained by calling
Point::zero()
.
Point implements all necessary arithmetic operations: points addition, multiplication at scalar, etc.
Implementations§
Source§impl<E: Curve> Point<E>
impl<E: Curve> Point<E>
Sourcepub fn generator() -> Generator<E>
pub fn generator() -> Generator<E>
Curve generator
Curve generator is a regular point defined in curve specs. See Generator<E>
.
Sourcepub fn zero() -> Self
pub fn zero() -> Self
Returns identity point $\O$ (sometimes called as point at infinity)
Identity point has special properties:
$$\forall P \in \G: P + \O = P$$ $$\forall s \in \Zq: s \cdot \O = \O$$
When you validate input from user or message received on wire, you should bear in mind that
any Point<E>
may be zero. If your algorithm does not accept identity points, you may check
whether point is zero by calling .is_zero()
. Alternatively, you may accept
NonZero<Point<E>>
instead, which is guaranteed to be non zero.
Sourcepub fn is_zero(&self) -> bool
pub fn is_zero(&self) -> bool
Indicates whether it’s identity point
use generic_ec::{Point, curves::Secp256k1};
assert!(Point::<Secp256k1>::zero().is_zero());
assert!(!Point::<Secp256k1>::generator().to_point().is_zero());
Sourcepub fn ct_is_zero(&self) -> Choice
pub fn ct_is_zero(&self) -> Choice
Indicates whether it’s identity point (in constant time)
Same as .is_zero()
but performs constant-time comparison.
Sourcepub fn to_bytes(&self, compressed: bool) -> EncodedPoint<E>
pub fn to_bytes(&self, compressed: bool) -> EncodedPoint<E>
Encodes a point as bytes
Function can return both compressed and uncompressed bytes representation of a point. Compressed bytes representation is more compact, but parsing takes a little bit more time. On other hand, uncompressed representation takes ~twice more space, but parsing is instant.
For some curves, compressed
parameter may be ignored, and same bytes representation
is returned.
use generic_ec::{Point, Scalar, curves::Secp256k1};
use rand::rngs::OsRng;
let random_point = Point::<Secp256k1>::generator() * Scalar::random(&mut OsRng);
let point_bytes = random_point.to_bytes(false);
let point_decoded = Point::from_bytes(&point_bytes)?;
assert_eq!(random_point, point_decoded);
Sourcepub fn from_bytes(bytes: impl AsRef<[u8]>) -> Result<Self, InvalidPoint>
pub fn from_bytes(bytes: impl AsRef<[u8]>) -> Result<Self, InvalidPoint>
Decodes a point from bytes
Sourcepub fn serialized_len(compressed: bool) -> usize
pub fn serialized_len(compressed: bool) -> usize
Returns size of bytes buffer that can fit a serialized point
compressed
parameter has the same meaning as for Point::to_bytes
; a
buffer created with length of Point::serialized_len(compress)
would fit
exactly the serialization p.to_bytes(compress)
.
Trait Implementations§
Source§impl<E: Curve> AddAssign<&Generator<E>> for Point<E>
impl<E: Curve> AddAssign<&Generator<E>> for Point<E>
Source§fn add_assign(&mut self, rhs: &Generator<E>)
fn add_assign(&mut self, rhs: &Generator<E>)
+=
operation. Read moreSource§impl<E: Curve> AddAssign<&Point<E>> for Point<E>
impl<E: Curve> AddAssign<&Point<E>> for Point<E>
Source§fn add_assign(&mut self, rhs: &Point<E>)
fn add_assign(&mut self, rhs: &Point<E>)
+=
operation. Read moreSource§impl<E: Curve> AddAssign<Generator<E>> for Point<E>
impl<E: Curve> AddAssign<Generator<E>> for Point<E>
Source§fn add_assign(&mut self, rhs: Generator<E>)
fn add_assign(&mut self, rhs: Generator<E>)
+=
operation. Read moreSource§impl<E: Curve> AddAssign for Point<E>
impl<E: Curve> AddAssign for Point<E>
Source§fn add_assign(&mut self, rhs: Point<E>)
fn add_assign(&mut self, rhs: Point<E>)
+=
operation. Read moreSource§impl<E> AlwaysHasAffineY<E> for Point<E>where
E: AlwaysHasAffineY + Curve,
impl<E> AlwaysHasAffineY<E> for Point<E>where
E: AlwaysHasAffineY + Curve,
Source§fn y(&self) -> Coordinate<E>
fn y(&self) -> Coordinate<E>
Source§impl<E> AlwaysHasAffineYAndSign<E> for Point<E>where
E: AlwaysHasAffineYAndSign + Curve,
impl<E> AlwaysHasAffineYAndSign<E> for Point<E>where
E: AlwaysHasAffineYAndSign + Curve,
Source§fn y_and_sign(&self) -> (Sign, Coordinate<E>)
fn y_and_sign(&self) -> (Sign, Coordinate<E>)
Source§fn from_y_and_sign(x_sign: Sign, y: &Coordinate<E>) -> Option<Self>
fn from_y_and_sign(x_sign: Sign, y: &Coordinate<E>) -> Option<Self>
Source§impl<E: Curve> ConditionallySelectable for Point<E>
impl<E: Curve> ConditionallySelectable for Point<E>
Source§fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self
fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self
Source§fn conditional_assign(&mut self, other: &Self, choice: Choice)
fn conditional_assign(&mut self, other: &Self, choice: Choice)
Source§fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)
fn conditional_swap(a: &mut Self, b: &mut Self, choice: Choice)
self
and other
if choice == 1
; otherwise,
reassign both unto themselves. Read moreSource§impl<E: Curve> ConstantTimeEq for Point<E>
impl<E: Curve> ConstantTimeEq for Point<E>
Source§impl<'de, E: Curve> Deserialize<'de> for Point<E>
Available on crate feature serde
only.
impl<'de, E: Curve> Deserialize<'de> for Point<E>
serde
only.Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Source§impl<'de, E: Curve> DeserializeAs<'de, Point<E>> for Compact
Available on crate feature serde
only.
impl<'de, E: Curve> DeserializeAs<'de, Point<E>> for Compact
serde
only.Source§fn deserialize_as<D>(deserializer: D) -> Result<Point<E>, D::Error>where
D: Deserializer<'de>,
fn deserialize_as<D>(deserializer: D) -> Result<Point<E>, D::Error>where
D: Deserializer<'de>,
Source§impl<E: Curve> Digestable for Point<E>
Available on crate feature udigest
only.
impl<E: Curve> Digestable for Point<E>
udigest
only.Source§fn unambiguously_encode<B>(&self, encoder: EncodeValue<'_, B>)where
B: Buffer,
fn unambiguously_encode<B>(&self, encoder: EncodeValue<'_, B>)where
B: Buffer,
Source§impl<E> HasAffineX<E> for Point<E>where
E: HasAffineX + Curve,
impl<E> HasAffineX<E> for Point<E>where
E: HasAffineX + Curve,
Source§impl<E> HasAffineXAndParity<E> for Point<E>where
E: HasAffineXAndParity + Curve,
impl<E> HasAffineXAndParity<E> for Point<E>where
E: HasAffineXAndParity + Curve,
Source§fn x_and_parity(&self) -> Option<(Coordinate<E>, Parity)>
fn x_and_parity(&self) -> Option<(Coordinate<E>, Parity)>
Source§fn from_x_and_parity(x: &Coordinate<E>, y_parity: Parity) -> Option<Self>
fn from_x_and_parity(x: &Coordinate<E>, y_parity: Parity) -> Option<Self>
Source§impl<E> HasAffineXY<E> for Point<E>where
E: HasAffineXY + Curve,
impl<E> HasAffineXY<E> for Point<E>where
E: HasAffineXY + Curve,
Source§fn from_coords(coords: &Coordinates<E>) -> Option<Self>
fn from_coords(coords: &Coordinates<E>) -> Option<Self>
Source§impl<E> HasAffineY<E> for Point<E>where
E: HasAffineY + Curve,
impl<E> HasAffineY<E> for Point<E>where
E: HasAffineY + Curve,
Source§impl<E: Curve> MulAssign<&NonZero<SecretScalar<E>>> for Point<E>
impl<E: Curve> MulAssign<&NonZero<SecretScalar<E>>> for Point<E>
Source§fn mul_assign(&mut self, rhs: &NonZero<SecretScalar<E>>)
fn mul_assign(&mut self, rhs: &NonZero<SecretScalar<E>>)
*=
operation. Read moreSource§impl<E: Curve> MulAssign<&Scalar<E>> for Point<E>
impl<E: Curve> MulAssign<&Scalar<E>> for Point<E>
Source§fn mul_assign(&mut self, rhs: &Scalar<E>)
fn mul_assign(&mut self, rhs: &Scalar<E>)
*=
operation. Read moreSource§impl<E: Curve> MulAssign<&SecretScalar<E>> for Point<E>
impl<E: Curve> MulAssign<&SecretScalar<E>> for Point<E>
Source§fn mul_assign(&mut self, rhs: &SecretScalar<E>)
fn mul_assign(&mut self, rhs: &SecretScalar<E>)
*=
operation. Read moreSource§impl<E: Curve> MulAssign<NonZero<SecretScalar<E>>> for Point<E>
impl<E: Curve> MulAssign<NonZero<SecretScalar<E>>> for Point<E>
Source§fn mul_assign(&mut self, rhs: NonZero<SecretScalar<E>>)
fn mul_assign(&mut self, rhs: NonZero<SecretScalar<E>>)
*=
operation. Read moreSource§impl<E: Curve> MulAssign<Scalar<E>> for Point<E>
impl<E: Curve> MulAssign<Scalar<E>> for Point<E>
Source§fn mul_assign(&mut self, rhs: Scalar<E>)
fn mul_assign(&mut self, rhs: Scalar<E>)
*=
operation. Read moreSource§impl<E: Curve> MulAssign<SecretScalar<E>> for Point<E>
impl<E: Curve> MulAssign<SecretScalar<E>> for Point<E>
Source§fn mul_assign(&mut self, rhs: SecretScalar<E>)
fn mul_assign(&mut self, rhs: SecretScalar<E>)
*=
operation. Read moreSource§impl<E: Curve> Ord for Point<E>
impl<E: Curve> Ord for Point<E>
Source§impl<E: Curve> PartialOrd<NonZero<Point<E>>> for Point<E>
impl<E: Curve> PartialOrd<NonZero<Point<E>>> for Point<E>
Source§impl<E: Curve> PartialOrd for Point<E>
impl<E: Curve> PartialOrd for Point<E>
Source§impl<E: Curve> SerializeAs<Point<E>> for Compact
Available on crate feature serde
only.
impl<E: Curve> SerializeAs<Point<E>> for Compact
serde
only.Source§fn serialize_as<S>(source: &Point<E>, serializer: S) -> Result<S::Ok, S::Error>where
S: Serializer,
fn serialize_as<S>(source: &Point<E>, serializer: S) -> Result<S::Ok, S::Error>where
S: Serializer,
Source§impl<E: Curve> SubAssign<&Generator<E>> for Point<E>
impl<E: Curve> SubAssign<&Generator<E>> for Point<E>
Source§fn sub_assign(&mut self, rhs: &Generator<E>)
fn sub_assign(&mut self, rhs: &Generator<E>)
-=
operation. Read moreSource§impl<E: Curve> SubAssign<&Point<E>> for Point<E>
impl<E: Curve> SubAssign<&Point<E>> for Point<E>
Source§fn sub_assign(&mut self, rhs: &Point<E>)
fn sub_assign(&mut self, rhs: &Point<E>)
-=
operation. Read moreSource§impl<E: Curve> SubAssign<Generator<E>> for Point<E>
impl<E: Curve> SubAssign<Generator<E>> for Point<E>
Source§fn sub_assign(&mut self, rhs: Generator<E>)
fn sub_assign(&mut self, rhs: Generator<E>)
-=
operation. Read moreSource§impl<E: Curve> SubAssign for Point<E>
impl<E: Curve> SubAssign for Point<E>
Source§fn sub_assign(&mut self, rhs: Point<E>)
fn sub_assign(&mut self, rhs: Point<E>)
-=
operation. Read more