pub struct PublicKey(/* private fields */);Expand description
P-224 (secp224r1) ECDSA public key.
Supports signature verification and ECDH key agreement. Both compressed
(29-byte) and uncompressed (57-byte) SEC1 encodings are accepted on input;
use to_compressed_bytes to export compressed.
§Verification
use crypto::p224::SecretKey;
let key = SecretKey::generate().unwrap();
let signature = key.sign(b"message").unwrap();
assert!(key.public_key().verify(b"message", &signature).is_ok());Implementations§
Source§impl PublicKey
impl PublicKey
Sourcepub fn from_bytes(key: &[u8]) -> Result<PublicKey, EllipticCurveError>
pub fn from_bytes(key: &[u8]) -> Result<PublicKey, EllipticCurveError>
Parses a compressed (29-byte) or uncompressed (57-byte) SEC1 encoding.
Returns EllipticCurveError::InvalidKey when the encoding is not a
valid point on the P-224 curve.
Sourcepub fn from_x_y(
x_bytes: &[u8; 28],
y_bytes: &[u8; 28],
) -> Result<PublicKey, EllipticCurveError>
pub fn from_x_y( x_bytes: &[u8; 28], y_bytes: &[u8; 28], ) -> Result<PublicKey, EllipticCurveError>
Builds a public key from raw affine x and y coordinates (both
big-endian, 28 bytes each). Returns InvalidKey if the coordinates
are not a valid point on the P-224 curve.
This is useful when importing keys from formats like JWK where x
and y are available directly.
Sourcepub fn verify(
&self,
message: &[u8],
signature: &[u8; 56],
) -> Result<(), EllipticCurveError>
pub fn verify( &self, message: &[u8], signature: &[u8; 56], ) -> Result<(), EllipticCurveError>
Verifies an ECDSA signature over message using SHA-256 (truncated to
the leftmost 224 bits).
Both canonical low-s and non-canonical high-s signatures are accepted,
matching typical ECDSA interoperability. Use Self::verify_strict to
additionally reject high-s signatures.
Sourcepub fn verify_strict(
&self,
message: &[u8],
signature: &[u8; 56],
) -> Result<(), EllipticCurveError>
pub fn verify_strict( &self, message: &[u8], signature: &[u8; 56], ) -> Result<(), EllipticCurveError>
Verifies an ECDSA signature over message using SHA-256, additionally
rejecting non-canonical high-s signatures (s > n / 2).
Use this when signature malleability must be excluded (Bitcoin/EIP-2
style). Note that some third-party signers emit high-s signatures, which
this method will reject; Self::verify accepts both forms.
Sourcepub fn to_bytes(&self) -> [u8; 57]
pub fn to_bytes(&self) -> [u8; 57]
Returns the 57-byte uncompressed SEC1 encoding (0x04 || x || y).
Sourcepub fn to_compressed_bytes(&self) -> [u8; 29]
pub fn to_compressed_bytes(&self) -> [u8; 29]
Returns the 29-byte compressed SEC1 encoding (0x02/0x03 || x).