Skip to content

Commit

Permalink
encaps example
Browse files Browse the repository at this point in the history
  • Loading branch information
franziskuskiefer committed Apr 26, 2024
1 parent 58e5c76 commit f8905e4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
15 changes: 15 additions & 0 deletions libcrux-ml-kem/examples/encapsulate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use libcrux_ml_kem::{kyber768, ENCAPS_SEED_SIZE, KEY_GENERATION_SEED_SIZE};
use rand::{rngs::OsRng, RngCore};

fn main() {
let mut randomness = [0u8; KEY_GENERATION_SEED_SIZE];
OsRng.fill_bytes(&mut randomness);

let key_pair = kyber768::generate_key_pair(randomness);

let mut randomness = [0u8; ENCAPS_SEED_SIZE];
for _ in 0..100_000 {
OsRng.fill_bytes(&mut randomness);
let _ = kyber768::encapsulate(key_pair.public_key(), randomness);
}
}
2 changes: 1 addition & 1 deletion libcrux-ml-kem/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub(crate) const BITS_PER_RING_ELEMENT: usize = COEFFICIENTS_IN_RING_ELEMENT * 1
pub(crate) const BYTES_PER_RING_ELEMENT: usize = BITS_PER_RING_ELEMENT / 8;

/// PKE message size
pub(crate) const SHARED_SECRET_SIZE: usize = 32;
pub const SHARED_SECRET_SIZE: usize = 32;

pub(crate) const CPA_PKE_KEY_GENERATION_SEED_SIZE: usize = 32;

Expand Down
6 changes: 4 additions & 2 deletions libcrux-ml-kem/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ use self::{
};

/// Seed size for key generation
pub(crate) const KEY_GENERATION_SEED_SIZE: usize =
CPA_PKE_KEY_GENERATION_SEED_SIZE + SHARED_SECRET_SIZE;
pub const KEY_GENERATION_SEED_SIZE: usize = CPA_PKE_KEY_GENERATION_SEED_SIZE + SHARED_SECRET_SIZE;

/// Seed size for encapsulation
pub const ENCAPS_SEED_SIZE: usize = constants::SHARED_SECRET_SIZE;

/// Serialize the secret key.
#[inline(always)]
Expand Down

0 comments on commit f8905e4

Please sign in to comment.