Skip to main content

MlKemParams

Trait MlKemParams 

Source
pub trait MlKemParams:
    Sealed
    + Sized
    + Copy
    + Debug
    + 'static {
    type PublicKeyBytes: AsRef<[u8]> + AsMut<[u8]> + Copy + Debug;
    type SecretKeyBytes: AsRef<[u8]> + AsMut<[u8]> + Copy + Debug;
    type CiphertextBytes: AsRef<[u8]> + AsMut<[u8]> + Copy + Debug;
Show 14 associated constants and 3 methods const K: usize; const ETA1: usize; const DU: usize; const DV: usize; const PUBLIC_KEY_BYTES: usize; const SECRET_KEY_BYTES: usize; const CIPHERTEXT_BYTES: usize; const ALGORITHM_ID: &'static str; const OID: &'static str; const ETA2: usize = 2; const N: usize = 256; const Q: usize = 3329; const SHARED_SECRET_BYTES: usize = 32; const SYM_BYTES: usize = 32; // Required methods fn zero_public_key() -> Self::PublicKeyBytes; fn zero_secret_key() -> Self::SecretKeyBytes; fn zero_ciphertext() -> Self::CiphertextBytes;
}
Expand description

FIPS 203 parameter pack — every constant and type the algorithm needs to specialise to one of the three ML-KEM variants.

Implemented by the zero-sized marker types MlKem512, MlKem768, MlKem1024. Sealed: third-party crates cannot add new implementations.

All associated constants come from FIPS 203 §6 (“Parameter sets”) and the IETF LAMPS draft for the OIDs / algorithm identifiers.

§Example

use kyberlib::{MlKem768, MlKemParams};

const PK_LEN: usize = <MlKem768 as MlKemParams>::PUBLIC_KEY_BYTES;
const CT_LEN: usize = <MlKem768 as MlKemParams>::CIPHERTEXT_BYTES;
assert_eq!(PK_LEN, 1184);
assert_eq!(CT_LEN, 1088);

Required Associated Constants§

Source

const K: usize

Module rank k. 2 / 3 / 4 for ML-KEM-512 / 768 / 1024.

Source

const ETA1: usize

Centred-binomial width η₁ for the secret-key sampling. 3 for ML-KEM-512, 2 for ML-KEM-768 and ML-KEM-1024.

Source

const DU: usize

Ciphertext compression bit-width for the u half. 10 for ML-KEM-512/768, 11 for ML-KEM-1024.

Source

const DV: usize

Ciphertext compression bit-width for the v half. 4 for ML-KEM-512/768, 5 for ML-KEM-1024.

Source

const PUBLIC_KEY_BYTES: usize

Public encapsulation-key byte length. K * 384 + 32 per FIPS 203 §6.

Source

const SECRET_KEY_BYTES: usize

Secret decapsulation-key byte length. 24*K*N/8 + 96 per FIPS 203 §6.1.

Source

const CIPHERTEXT_BYTES: usize

Ciphertext byte length. 32*(K*DU + DV) per FIPS 203 §6.

Source

const ALGORITHM_ID: &'static str

Stable algorithm identifier — "ML-KEM-512", "ML-KEM-768", or "ML-KEM-1024".

Source

const OID: &'static str

Object identifier — 2.16.840.1.101.3.4.4.{1,2,3}.

Provided Associated Constants§

Source

const ETA2: usize = 2

Centred-binomial width η₂ for the ciphertext-noise sampling. Always 2.

Source

const N: usize = 256

Polynomial degree N. Always 256.

Source

const Q: usize = 3329

Modulus q. Always 3329.

Source

const SHARED_SECRET_BYTES: usize = 32

Shared-secret length in bytes. Always 32.

Source

const SYM_BYTES: usize = 32

Symmetric primitive byte length (seeds, hashes). Always 32.

Required Associated Types§

Source

type PublicKeyBytes: AsRef<[u8]> + AsMut<[u8]> + Copy + Debug

Concrete encapsulation-key byte buffer type. Each impl instantiates as [u8; PUBLIC_KEY_BYTES].

Source

type SecretKeyBytes: AsRef<[u8]> + AsMut<[u8]> + Copy + Debug

Concrete decapsulation-key byte buffer type. Each impl instantiates as [u8; SECRET_KEY_BYTES]. Zeroized on drop at the wrapper level (see crate::ml_kem).

Source

type CiphertextBytes: AsRef<[u8]> + AsMut<[u8]> + Copy + Debug

Concrete ciphertext byte buffer type. Each impl instantiates as [u8; CIPHERTEXT_BYTES].

Required Methods§

Source

fn zero_public_key() -> Self::PublicKeyBytes

Create a new zeroed public-key buffer. Helper so generic code can construct buffers without naming the concrete array size.

Source

fn zero_secret_key() -> Self::SecretKeyBytes

Create a new zeroed secret-key buffer.

Source

fn zero_ciphertext() -> Self::CiphertextBytes

Create a new zeroed ciphertext buffer.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl MlKemParams for MlKem512

Source§

const K: usize = 2

Source§

const ETA1: usize = 3

Source§

const DU: usize = 10

Source§

const DV: usize = 4

Source§

const PUBLIC_KEY_BYTES: usize = 800

Source§

const SECRET_KEY_BYTES: usize = 1632

Source§

const CIPHERTEXT_BYTES: usize = 768

Source§

const ALGORITHM_ID: &'static str = "ML-KEM-512"

Source§

const OID: &'static str = "2.16.840.1.101.3.4.4.1"

Source§

type PublicKeyBytes = [u8; 800]

Source§

type SecretKeyBytes = [u8; 1632]

Source§

type CiphertextBytes = [u8; 768]

Source§

impl MlKemParams for MlKem768

Source§

const K: usize = 3

Source§

const ETA1: usize = 2

Source§

const DU: usize = 10

Source§

const DV: usize = 4

Source§

const PUBLIC_KEY_BYTES: usize = 1184

Source§

const SECRET_KEY_BYTES: usize = 2400

Source§

const CIPHERTEXT_BYTES: usize = 1088

Source§

const ALGORITHM_ID: &'static str = "ML-KEM-768"

Source§

const OID: &'static str = "2.16.840.1.101.3.4.4.2"

Source§

type PublicKeyBytes = [u8; 1184]

Source§

type SecretKeyBytes = [u8; 2400]

Source§

type CiphertextBytes = [u8; 1088]

Source§

impl MlKemParams for MlKem1024

Source§

const K: usize = 4

Source§

const ETA1: usize = 2

Source§

const DU: usize = 11

Source§

const DV: usize = 5

Source§

const PUBLIC_KEY_BYTES: usize = 1568

Source§

const SECRET_KEY_BYTES: usize = 3168

Source§

const CIPHERTEXT_BYTES: usize = 1568

Source§

const ALGORITHM_ID: &'static str = "ML-KEM-1024"

Source§

const OID: &'static str = "2.16.840.1.101.3.4.4.3"

Source§

type PublicKeyBytes = [u8; 1568]

Source§

type SecretKeyBytes = [u8; 3168]

Source§

type CiphertextBytes = [u8; 1568]