elliptic_curve/point.rs
1//! Traits for elliptic curve points.
2
3#[cfg(feature = "arithmetic")]
4mod non_identity;
5
6#[cfg(feature = "arithmetic")]
7pub use {self::non_identity::NonIdentity, crate::CurveArithmetic};
8
9use crate::{Curve, FieldBytes};
10use subtle::{Choice, CtOption};
11
12/// Affine point type for a given curve with a [`CurveArithmetic`]
13/// implementation.
14#[cfg(feature = "arithmetic")]
15pub type AffinePoint<C> = <C as CurveArithmetic>::AffinePoint;
16
17/// Projective point type for a given curve with a [`CurveArithmetic`]
18/// implementation.
19#[cfg(feature = "arithmetic")]
20pub type ProjectivePoint<C> = <C as CurveArithmetic>::ProjectivePoint;
21
22/// Access to the affine coordinates of an elliptic curve point.
23// TODO: use zkcrypto/group#30 coordinate API when available
24pub trait AffineCoordinates {
25 /// Field element representation.
26 type FieldRepr: AsRef<[u8]>;
27
28 /// Get the affine x-coordinate as a serialized field element.
29 fn x(&self) -> Self::FieldRepr;
30
31 /// Is the affine y-coordinate odd?
32 fn y_is_odd(&self) -> Choice;
33}
34
35/// Normalize point(s) in projective representation by converting them to their affine ones.
36#[cfg(feature = "arithmetic")]
37pub trait BatchNormalize<Points: ?Sized>: group::Curve {
38 /// The output of the batch normalization; a container of affine points.
39 type Output: AsRef<[Self::AffineRepr]>;
40
41 /// Perform a batched conversion to affine representation on a sequence of projective points
42 /// at an amortized cost that should be practically as efficient as a single conversion.
43 /// Internally, implementors should rely upon `InvertBatch`.
44 fn batch_normalize(points: &Points) -> <Self as BatchNormalize<Points>>::Output;
45}
46
47/// Double a point (i.e. add it to itself)
48pub trait Double {
49 /// Double this point.
50 fn double(&self) -> Self;
51}
52
53/// Decompress an elliptic curve point.
54///
55/// Point decompression recovers an original curve point from its x-coordinate
56/// and a boolean flag indicating whether or not the y-coordinate is odd.
57pub trait DecompressPoint<C: Curve>: Sized {
58 /// Attempt to decompress an elliptic curve point.
59 fn decompress(x: &FieldBytes<C>, y_is_odd: Choice) -> CtOption<Self>;
60}
61
62/// Decompact an elliptic curve point from an x-coordinate.
63///
64/// Decompaction relies on properties of specially-generated keys but provides
65/// a more compact representation than standard point compression.
66pub trait DecompactPoint<C: Curve>: Sized {
67 /// Attempt to decompact an elliptic curve point
68 fn decompact(x: &FieldBytes<C>) -> CtOption<Self>;
69}
70
71/// Point compression settings.
72pub trait PointCompression {
73 /// Should point compression be applied by default?
74 const COMPRESS_POINTS: bool;
75}
76
77/// Point compaction settings.
78pub trait PointCompaction {
79 /// Should point compaction be applied by default?
80 const COMPACT_POINTS: bool;
81}