diff --git a/ciphers/benches/primitives.rs b/ciphers/benches/primitives.rs index 61a649b..f1ef4d7 100644 --- a/ciphers/benches/primitives.rs +++ b/ciphers/benches/primitives.rs @@ -194,6 +194,33 @@ mod aead { let nonce = [23; NONCE_LEN]; let ad = []; + c.bench_function(&aead_benchid("encrypt", "0byte"), |bench| { + const DATA_LEN: usize = 0; + + let ptxt = []; + let mut ctxt = [0; DATA_LEN + TAG_LEN]; + + bench.iter(|| { + scheme.encrypt(&mut ctxt, &key, &nonce, &ad, &ptxt).unwrap(); + }); + }); + + c.bench_function(&aead_benchid("decrypt", "0byte"), |bench| { + const DATA_LEN: usize = 0; + + let ptxt = []; + let mut ctxt = [0; DATA_LEN + TAG_LEN]; + let mut ptxt_out = [0u8; DATA_LEN]; + + scheme.encrypt(&mut ctxt, &key, &nonce, &ad, &ptxt).unwrap(); + + bench.iter(|| { + scheme + .decrypt(&mut ptxt_out, &key, &nonce, &ad, &mut ctxt) + .unwrap() + }) + }); + c.bench_function(&aead_benchid("encrypt", "32byte"), |bench| { const DATA_LEN: usize = 32; @@ -312,7 +339,14 @@ mod keyed_hash { ]; let keyedhash_benchid = |len| benchid(KvPairs(&base), KvPairs(&[KvPair("length", len)])); - c.bench_function(&keyedhash_benchid("32byte"), |bench| { + c.bench_function(&keyedhash_benchid("0byte"), |bench| { + let bytes = []; + + bench.iter(|| { + H::keyed_hash(&key, &bytes, &mut out).unwrap(); + }) + }) + .bench_function(&keyedhash_benchid("32byte"), |bench| { let bytes = [34u8; 32]; bench.iter(|| { diff --git a/rosenpass/benches/trace_handshake.rs b/rosenpass/benches/trace_handshake.rs index a8f6d16..7710495 100644 --- a/rosenpass/benches/trace_handshake.rs +++ b/rosenpass/benches/trace_handshake.rs @@ -1,4 +1,3 @@ -// Standard library imports use std::{ collections::HashMap, hint::black_box, @@ -7,17 +6,18 @@ use std::{ time::{Duration, Instant}, }; -// External crate imports use anyhow::Result; use libcrux_test_utils::tracing::{EventType, Trace as _}; -use rosenpass::protocol::{ - CryptoServer, HandleMsgResult, MsgBuf, PeerPtr, ProtocolVersion, SPk, SSk, SymKey, -}; + use rosenpass_cipher_traits::primitives::Kem; use rosenpass_ciphers::StaticKem; use rosenpass_secret_memory::secret_policy_try_use_memfd_secrets; use rosenpass_util::trace_bench::{RpEventType, TRACE}; +use rosenpass::protocol::{ + CryptoServer, HandleMsgResult, MsgBuf, PeerPtr, ProtocolVersion, SPk, SSk, SymKey, +}; + const ITERATIONS: usize = 100; fn handle( @@ -116,8 +116,11 @@ fn main() { .expect("error writing json data"); } -/// Takes a vector of trace events, bins them by label, extracts durations, -/// filters empty bins, calculates aggregate statistics (mean, std dev), and returns them. +/// Performs a simple statistical analysis: +/// - bins trace events by label +/// - extracts durations of spamns +/// - filters out empty bins +/// - calculates aggregate statistics (mean, std dev) fn statistical_analysis(trace: Vec) -> Vec<(&'static str, AggregateStat)> { bin_events(trace) .into_iter() @@ -132,9 +135,9 @@ fn statistical_analysis(trace: Vec) -> Vec<(&'static str, Aggregate /// /// # Arguments /// * `w` - The writer to output JSON to (e.g., stdout, file). -/// * `item_groups` - An iterator producing tuples of (`&'static str`, `II`), where -/// `II` is itself an iterator producing (`&'static str`, `AggregateStat`). -/// Represents the protocol_version name and the statistics items within that protocol_version. +/// * `item_groups` - An iterator producing tuples `(version, stats): (&'static str, II)`. +/// Here `II` is itself an iterator producing `(label, agg_stat): (&'static str, AggregateStat)`, +/// where the label is the label of the span, e.g. "IHI2". /// /// # Type Parameters /// * `W` - A type that implements `std::io::Write`. diff --git a/rosenpass/src/protocol/protocol.rs b/rosenpass/src/protocol/protocol.rs index bbc7920..dd95a5c 100644 --- a/rosenpass/src/protocol/protocol.rs +++ b/rosenpass/src/protocol/protocol.rs @@ -3548,7 +3548,7 @@ impl CryptoServer { /// Marks a section of the protocol using the same identifiers as are used in the whitepaper. /// When building with the trace benchmarking feature enabled, this also emits span events into the -/// trace, which allows reconstructing the run times of the individual sections for performace +/// trace, which allows reconstructing the run times of the individual sections for performance /// measurement. macro_rules! protocol_section { ($label:expr, $body:tt) => {{ diff --git a/util/src/trace_bench.rs b/util/src/trace_bench.rs index d659dec..5f1528a 100644 --- a/util/src/trace_bench.rs +++ b/util/src/trace_bench.rs @@ -13,7 +13,7 @@ pub type RpTrace = tracing::MutexTrace<&'static str, Instant>; /// The trace event type used to trace Rosenpass for performance measurement. pub type RpEventType = tracing::TraceEvent<&'static str, Instant>; -// Re-export to make functionality availalable and callers don't need to also directly depend on +// Re-export to make functionality available and callers don't need to also directly depend on // [`libcrux_test_utils`]. pub use libcrux_test_utils::tracing::trace_span; pub use tracing::Trace;