From 1c14be38ddd71cde9dcfcd9b52ba7cee060d6b58 Mon Sep 17 00:00:00 2001 From: wucke13 Date: Wed, 3 Jan 2024 18:20:33 +0100 Subject: [PATCH] fix: make benches work again Somehow in the past while splitting into many crates, we broke the bench setup. This commit both fixes it, and adds a CI job that ensures it is still working to avoid such silent failure in the future. The benchmarks are not actually run, they would take forever on the slow GitHub Actions runners, but they are at least compiled. --- .github/workflows/qc.yaml | 20 ++++++++++++++++++++ rosenpass/benches/handshake.rs | 14 ++++++-------- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/.github/workflows/qc.yaml b/.github/workflows/qc.yaml index aa16d38..2f9a0db 100644 --- a/.github/workflows/qc.yaml +++ b/.github/workflows/qc.yaml @@ -33,6 +33,26 @@ jobs: - name: Run Rust Formatting Script run: bash format_rust_code.sh --mode check + cargo-bench: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/cache@v3 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - name: Install libsodium + run: sudo apt-get install -y libsodium-dev + # liboqs requires quite a lot of stack memory, thus we adjust + # the default stack size picked for new threads (which is used + # by `cargo test`) to be _big enough_. Setting it to 8 MiB + - run: RUST_MIN_STACK=8388608 cargo bench --no-run --workspace + cargo-audit: runs-on: ubuntu-latest steps: diff --git a/rosenpass/benches/handshake.rs b/rosenpass/benches/handshake.rs index 1a46df5..e276a9d 100644 --- a/rosenpass/benches/handshake.rs +++ b/rosenpass/benches/handshake.rs @@ -1,10 +1,8 @@ use anyhow::Result; -use rosenpass::pqkem::KEM; -use rosenpass::{ - pqkem::StaticKEM, - protocol::{CryptoServer, HandleMsgResult, MsgBuf, PeerPtr, SPk, SSk, SymKey}, - sodium::sodium_init, -}; +use rosenpass::protocol::{CryptoServer, HandleMsgResult, MsgBuf, PeerPtr, SPk, SSk, SymKey}; + +use rosenpass_cipher_traits::Kem; +use rosenpass_ciphers::kem::StaticKem; use criterion::{black_box, criterion_group, criterion_main, Criterion}; @@ -41,7 +39,7 @@ fn hs(ini: &mut CryptoServer, res: &mut CryptoServer) -> Result<()> { fn keygen() -> Result<(SSk, SPk)> { let (mut sk, mut pk) = (SSk::zero(), SPk::zero()); - StaticKEM::keygen(sk.secret_mut(), pk.secret_mut())?; + StaticKem::keygen(sk.secret_mut(), pk.secret_mut())?; Ok((sk, pk)) } @@ -58,7 +56,7 @@ fn make_server_pair() -> Result<(CryptoServer, CryptoServer)> { } fn criterion_benchmark(c: &mut Criterion) { - sodium_init().unwrap(); + rosenpass_sodium::init().unwrap(); let (mut a, mut b) = make_server_pair().unwrap(); c.bench_function("cca_secret_alloc", |bench| { bench.iter(|| {