Skip to content

Commit

Permalink
wip; no chrono and encaps example
Browse files Browse the repository at this point in the history
  • Loading branch information
franziskuskiefer committed Jun 18, 2024
1 parent 249f3f6 commit dc0c56e
Show file tree
Hide file tree
Showing 6 changed files with 552 additions and 37 deletions.
2 changes: 1 addition & 1 deletion benchmarks/benches/sha2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ macro_rules! impl_comp {
($fun:ident, $libcrux:expr, $ring:expr, $rust_crypto:ty, $openssl:expr) => {
// Comparing libcrux performance for different payload sizes and other implementations.
fn $fun(c: &mut Criterion) {
const PAYLOAD_SIZES: [usize; 1] = [1024 * 1024 * 10];
const PAYLOAD_SIZES: [usize; 5] = [100, 1024, 2048, 4096, 8192];

let mut group = c.benchmark_group(stringify!($fun).replace("_", " "));

Expand Down
16 changes: 8 additions & 8 deletions libcrux-psq/benches/psq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ pub fn comparisons_psq_send(c: &mut Criterion) {
|(_sk, pk)| {
let _ = pk.send_psk(
b"bench context",
chrono::Duration::hours(1),
Duration::from_secs(3600),
&mut thread_rng(),
);
},
Expand All @@ -189,7 +189,7 @@ pub fn comparisons_psq_send(c: &mut Criterion) {
|(_sk, pk)| {
let _ = pk.send_psk(
b"bench context",
chrono::Duration::hours(1),
Duration::from_secs(3600),
&mut thread_rng(),
);
},
Expand All @@ -206,7 +206,7 @@ pub fn comparisons_psq_send(c: &mut Criterion) {
|(_sk, pk)| {
let _ = pk.send_psk(
b"bench context",
chrono::Duration::hours(1),
Duration::from_secs(3600),
&mut thread_rng(),
);
},
Expand All @@ -223,7 +223,7 @@ pub fn comparisons_psq_send(c: &mut Criterion) {
|(_sk, pk)| {
let _ = pk.send_psk(
b"bench context",
chrono::Duration::hours(1),
Duration::from_secs(3600),
&mut thread_rng(),
);
},
Expand All @@ -245,7 +245,7 @@ pub fn comparisons_psq_receive(c: &mut Criterion) {
.unwrap();

let (_psk, message) = pk
.send_psk(b"bench context", chrono::Duration::hours(1), &mut rng)
.send_psk(b"bench context", Duration::from_secs(3600), &mut rng)
.unwrap();
(pk, sk, message)
},
Expand All @@ -264,7 +264,7 @@ pub fn comparisons_psq_receive(c: &mut Criterion) {
.unwrap();

let (_psk, message) = pk
.send_psk(b"bench context", chrono::Duration::hours(1), &mut rng)
.send_psk(b"bench context", Duration::from_secs(3600), &mut rng)
.unwrap();
(pk, sk, message)
},
Expand All @@ -285,7 +285,7 @@ pub fn comparisons_psq_receive(c: &mut Criterion) {
.unwrap();

let (_psk, message) = pk
.send_psk(b"bench context", chrono::Duration::hours(1), &mut rng)
.send_psk(b"bench context", Duration::from_secs(3600), &mut rng)
.unwrap();
(pk, sk, message)
},
Expand All @@ -306,7 +306,7 @@ pub fn comparisons_psq_receive(c: &mut Criterion) {
.unwrap();

let (_psk, message) = pk
.send_psk(b"bench context", chrono::Duration::hours(1), &mut rng)
.send_psk(b"bench context", Duration::from_secs(3600), &mut rng)
.unwrap();
(pk, sk, message)
},
Expand Down
17 changes: 17 additions & 0 deletions libcrux-psq/examples/encaps.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use std::time::Duration;

use libcrux_psq::{generate_key_pair, Algorithm};
use rand::thread_rng;

fn main() {
let mut rng = thread_rng();
let mlkem_keypair = generate_key_pair(Algorithm::MlKem768, &mut rng).unwrap();

for _ in 0..100_000 {
let _ = core::hint::black_box(mlkem_keypair.1.send_psk(
b"size context",
Duration::from_secs(3600),
&mut rng,
));
}
}
11 changes: 6 additions & 5 deletions libcrux-psq/examples/sizes.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use chrono::Duration;
use std::time::Duration;

use libcrux_psq::*;
use rand::{self, thread_rng};

Expand All @@ -11,19 +12,19 @@ fn main() {

let mlkem_message = mlkem_keypair
.1
.send_psk(b"size context", Duration::hours(1), &mut rng)
.send_psk(b"size context", Duration::from_secs(3600), &mut rng)
.unwrap();
let x25519_message = x25519_keypair
.1
.send_psk(b"size context", Duration::hours(1), &mut rng)
.send_psk(b"size context", Duration::from_secs(3600), &mut rng)
.unwrap();
let xwing_message = xwing_keypair
.1
.send_psk(b"size context", Duration::hours(1), &mut rng)
.send_psk(b"size context", Duration::from_secs(3600), &mut rng)
.unwrap();
let classic_mceliece_message = classic_mceliece_keypair
.1
.send_psk(b"size context", Duration::hours(1), &mut rng)
.send_psk(b"size context", Duration::from_secs(3600), &mut rng)
.unwrap();

println!("ML-KEM-768:");
Expand Down
Loading

0 comments on commit dc0c56e

Please sign in to comment.