Skip to main content

ClassicMcEliece

Struct ClassicMcEliece 

Source
pub struct ClassicMcEliece { /* private fields */ }
Expand description

Classic McEliece 8192128f (security level 5, fast key-generation variant).

Classic McEliece is a code-based KEM with over 50 years of cryptanalytic history behind its underlying hard problem (decoding random binary Goppa codes). It is one of the most conservative choices available in post-quantum cryptography.

The f (fast) variant uses a different key-generation algorithm that is significantly faster at the cost of slightly larger public keys compared to the standard variant; the ciphertext size and security level are unchanged.

§Sizes

ObjectBytes
Public key1,357,824
Secret key14,120
Ciphertext208
Shared secret32

§Pros

  • Based on coding theory, an entirely different mathematical family from lattice schemes. Serves as a strong hedge in hybrid constructions.
  • ~50 years of cryptanalysis with no fundamental structural breaks.
  • Tiny ciphertext (208 B) — ideal when the encapsulated ciphertext must be transmitted repeatedly but the public key can be stored once (e.g. in a certificate or a static configuration file).
  • Extremely fast encapsulation and decapsulation, even faster than RSA.

§Cons

  • Very large public key (~1.3 MB) — prohibitive for protocols that transmit the public key in every session (e.g. standard TLS handshakes). Plan for out-of-band distribution or long-lived public keys.
  • Key generation is slow even with the f variant; not suitable for ephemeral key exchange patterns where a fresh keypair is needed per session.

§Reuse

Construct once with ClassicMcEliece::new and reuse across operations — each instance owns the underlying liboqs algorithm object, so reusing it avoids re-allocating that object on every encapsulation/decapsulation. This matters most in a tight handshake loop where a responder decapsulates with the same static key repeatedly.

Implementations§

Source§

impl ClassicMcEliece

Source

pub const PUBLIC_KEY_LEN: usize = 1_357_824

Length in bytes of a serialized public key.

Source

pub const SECRET_KEY_LEN: usize = 14_120

Length in bytes of a serialized secret key.

Source

pub const CIPHERTEXT_LEN: usize = 208

Length in bytes of a ciphertext.

Source

pub const SHARED_SECRET_LEN: usize = 32

Length in bytes of the encapsulated shared secret.

Source

pub fn new() -> Self

Construct a reusable Classic McEliece 8192128f instance.

Infallible: Classic McEliece 8192128f is always compiled in via the crate’s oqs feature set, so the underlying algorithm object can always be created.

Source

pub fn keypair(&self) -> Result<(PublicKey, SecretKey)>

Source

pub fn encapsulate( &self, public_key: &PublicKey, ) -> Result<(Ciphertext, SharedSecret)>

Source

pub fn decapsulate( &self, secret_key: &SecretKey, ciphertext: &Ciphertext, ) -> Result<SharedSecret>

Source

pub fn ciphertext_from_bytes(&self, bytes: &[u8]) -> Result<Ciphertext>

Reconstruct a ciphertext from its serialized bytes.

Returns Error::InvalidLength if bytes is not exactly CIPHERTEXT_LEN bytes long.

Source

pub fn public_key_from_bytes(&self, bytes: &[u8]) -> Result<PublicKey>

Reconstruct a public key from its serialized bytes.

Returns Error::InvalidLength if bytes is not exactly PUBLIC_KEY_LEN bytes long.

Source

pub fn secret_key_from_bytes(&self, bytes: &[u8]) -> Result<SecretKey>

Reconstruct a secret key from its serialized bytes.

Returns Error::InvalidLength if bytes is not exactly SECRET_KEY_LEN bytes long.

Trait Implementations§

Source§

impl Default for ClassicMcEliece

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.