pub struct Point { /* private fields */ }
Expand description
P-224 elliptic curve point in affine coordinates (x, y)
Represents points on the NIST P-224 curve. The special point at infinity (identity element) is represented with is_identity = true.
Implementations§
Source§impl Point
impl Point
Sourcepub fn new_uncompressed(x: &[u8; 28], y: &[u8; 28]) -> Result<Self>
pub fn new_uncompressed(x: &[u8; 28], y: &[u8; 28]) -> Result<Self>
Create a new elliptic curve point from uncompressed coordinates
Validates that the given (x, y) coordinates satisfy the P-224 curve equation: y² = x³ - 3x + b (mod p)
Returns an error if the point is not on the curve.
Sourcepub fn identity() -> Self
pub fn identity() -> Self
Create the identity element (point at infinity)
The identity element serves as the additive neutral element for the elliptic curve group operation.
Sourcepub fn is_identity(&self) -> bool
pub fn is_identity(&self) -> bool
Check if this point is the identity element
Sourcepub fn x_coordinate_bytes(&self) -> [u8; 28]
pub fn x_coordinate_bytes(&self) -> [u8; 28]
Get the x-coordinate as a byte array in big-endian format
Sourcepub fn y_coordinate_bytes(&self) -> [u8; 28]
pub fn y_coordinate_bytes(&self) -> [u8; 28]
Get the y-coordinate as a byte array in big-endian format
Sourcepub fn detect_format(bytes: &[u8]) -> Result<PointFormat>
pub fn detect_format(bytes: &[u8]) -> Result<PointFormat>
Detect point format from serialized bytes
Analyzes the leading byte and length to determine the serialization format. Useful for handling points that could be in either compressed or uncompressed form.
§Returns
Ok(PointFormat)
indicating the detected formatErr
if the format is invalid or unrecognized
Sourcepub fn serialize_uncompressed(&self) -> [u8; 57]
pub fn serialize_uncompressed(&self) -> [u8; 57]
Serialize point to uncompressed format: 0x04 || x || y
The uncompressed point format is:
- 1 byte: 0x04 (uncompressed indicator)
- 28 bytes: x-coordinate (big-endian)
- 28 bytes: y-coordinate (big-endian)
The identity point is represented as all zeros.
Sourcepub fn deserialize_uncompressed(bytes: &[u8]) -> Result<Self>
pub fn deserialize_uncompressed(bytes: &[u8]) -> Result<Self>
Deserialize point from uncompressed byte format
Supports the standard uncompressed format (0x04 || x || y) and recognizes the all-zeros encoding for the identity element.
Sourcepub fn serialize_compressed(&self) -> [u8; 29]
pub fn serialize_compressed(&self) -> [u8; 29]
Serialize point to SEC 1 compressed format (0x02/0x03 || x)
The compressed format uses:
- 0x02 prefix if y-coordinate is even
- 0x03 prefix if y-coordinate is odd
- Followed by the x-coordinate in big-endian format
The identity point is encoded as 29 zero bytes for consistency with the uncompressed format.
This format reduces storage/transmission size by ~50% compared to uncompressed points while maintaining full recoverability.
Sourcepub fn deserialize_compressed(bytes: &[u8]) -> Result<Self>
pub fn deserialize_compressed(bytes: &[u8]) -> Result<Self>
Deserialize SEC 1 compressed point
Recovers the full point from compressed format by:
- Extracting the x-coordinate
- Computing y² = x³ - 3x + b
- Finding the square root of y²
- Selecting the root with correct parity based on the prefix
§Errors
Returns an error if:
- The prefix is not 0x02 or 0x03
- The x-coordinate is not in the valid field range
- The x-coordinate corresponds to a non-residue (not on curve)
Sourcepub fn add(&self, other: &Self) -> Self
pub fn add(&self, other: &Self) -> Self
Elliptic curve point addition using the group law
Implements the abelian group operation for P-224 points. Converts to projective coordinates for efficient computation, then converts back to affine form.
Sourcepub fn double(&self) -> Self
pub fn double(&self) -> Self
Elliptic curve point doubling: 2 * self
Computes the sum of a point with itself, which has a more efficient formula than general point addition.
Sourcepub fn mul(&self, scalar: &Scalar) -> Result<Self>
pub fn mul(&self, scalar: &Scalar) -> Result<Self>
Scalar multiplication: compute scalar * self
Uses the binary method (double-and-add) with constant-time execution to prevent timing attacks. Processes scalar bits from most significant to least significant for efficiency.
Returns the identity element if scalar is zero.