pub struct PublicKey { /* private fields */ }Expand description
X-Wing hybrid KEM encapsulation (public) key.
See SecretKey for a full usage example.
Implementations§
Source§impl PublicKey
impl PublicKey
Sourcepub fn from_bytes(bytes: &[u8; 1216]) -> Result<PublicKey, MlKemError>
pub fn from_bytes(bytes: &[u8; 1216]) -> Result<PublicKey, MlKemError>
Parses an encapsulation key from its 1216-byte encoding (ML-KEM-768 encapsulation key followed by the X25519 public key).
§Errors
Returns MlKemError::InvalidKey when the ML-KEM-768 part is not a
valid encapsulation key (FIPS 203 modulus check).
pub fn to_bytes(&self) -> [u8; 1216]
Sourcepub fn encapsulate(&self) -> Result<([u8; 32], [u8; 1120]), XWingError>
pub fn encapsulate(&self) -> Result<([u8; 32], [u8; 1120]), XWingError>
Encapsulates a fresh random shared secret against this public key.
Returns XWingError::Random when the operating system’s random
number generator is unavailable or fails.
Sourcepub fn encapsulate_derand(&self, eseed: &[u8; 64]) -> ([u8; 32], [u8; 1120])
pub fn encapsulate_derand(&self, eseed: &[u8; 64]) -> ([u8; 32], [u8; 1120])
Encapsulates a shared secret against this public key using the given 64-byte seed, returning the shared secret and the ciphertext.
This is the deterministic variant of encapsulate,
intended for protocols that need reproducible encapsulation (e.g. HPKE
and test vectors). The seed MUST be uniformly random and MUST NOT be
reused across encapsulations.