Skip to main content

compress_pubkey

Function compress_pubkey 

Source
pub fn compress_pubkey<const LIMBS: usize>(
    params: &CurveParams<LIMBS>,
    pk: &PublicKey,
) -> Option<Vec<u8>>
Expand description

SEC1 compress: encode a public key as 0x02 || X (y even) or 0x03 || X (y odd).

Accepts either:

  • SEC1 uncompressed input (0x04 || X || Y): slices out X and the last byte of Y directly, after validating that the point is on the curve (defence in depth: we don’t emit a compressed encoding for a pk we wouldn’t accept as input).
  • SEC1 compressed input (0x02/0x03 || X): re-validates and returns a clone (idempotent).

Returns None if the input is malformed or off-curve.