diff --git a/.github/workflows/c-bench.yml b/.github/workflows/c-bench.yml new file mode 100644 index 000000000..04d03d819 --- /dev/null +++ b/.github/workflows/c-bench.yml @@ -0,0 +1,55 @@ +name: Benchmark C + +on: + workflow_dispatch: + merge_group: + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + benchmark: + strategy: + fail-fast: false + matrix: + os: + - macos-latest + - ubuntu-latest + # - windows-latest # currently runs forever, needs to be investigated before adding again! + + runs-on: ${{ matrix.os }} + defaults: + run: + shell: bash + + steps: + - uses: actions/checkout@v4 + + - name: 🔨 Build libcrux-ml-kem/c + working-directory: libcrux-ml-kem/c + run: | + cmake -B build -DCMAKE_BUILD_TYPE=Release + cmake --build build --config Release + + # FIXME: Benchmarks on Windows CI are not working right now. + # - name: 🏃🏻‍♀️ Benchmark + # working-directory: libcrux-ml-kem/c + # run: ./build/Release/ml_kem_bench + # if: ${{ matrix.os == 'windows-latest' }} + + - name: 🏃🏻‍♀️ Benchmark (libcrux-ml-kem/c) + working-directory: libcrux-ml-kem/c + run: ./build/ml_kem_bench + if: ${{ matrix.os != 'windows-latest' && (github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') }} + + - name: 🔨 Build libcrux-ml-kem/cg + working-directory: libcrux-ml-kem/cg + run: | + cmake -B build -DCMAKE_BUILD_TYPE=Release + cmake --build build --config Release + + - name: 🏃🏻‍♀️ Benchmark libcrux-ml-kem/cg + working-directory: libcrux-ml-kem/cg + run: ./build/ml_kem_bench + if: ${{ matrix.os != 'windows-latest' && (github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') }} diff --git a/.github/workflows/c.yml b/.github/workflows/c.yml index c734bf0de..285eac24a 100644 --- a/.github/workflows/c.yml +++ b/.github/workflows/c.yml @@ -14,7 +14,6 @@ concurrency: jobs: extract: - if: ${{ github.event_name != 'merge_group' }} runs-on: ubuntu-latest container: franziskus/libcrux-c:latest defaults: @@ -36,7 +35,6 @@ jobs: if-no-files-found: error extract-header-only: - if: ${{ github.event_name != 'merge_group' }} runs-on: ubuntu-latest container: franziskus/libcrux-c:latest defaults: @@ -59,7 +57,6 @@ jobs: diff: needs: [extract] - if: ${{ github.event_name != 'merge_group' }} runs-on: ubuntu-latest defaults: run: @@ -80,7 +77,6 @@ jobs: diff-header-only: needs: [extract-header-only] - if: ${{ github.event_name != 'merge_group' }} runs-on: ubuntu-latest defaults: run: @@ -101,7 +97,6 @@ jobs: build: needs: [extract] - if: ${{ github.event_name != 'merge_group' }} strategy: fail-fast: false matrix: @@ -141,7 +136,6 @@ jobs: build-header-only: needs: [extract-header-only] - if: ${{ github.event_name != 'merge_group' }} strategy: fail-fast: false matrix: @@ -174,50 +168,3 @@ jobs: - name: 🏃🏻‍♀️ Test run: ./build/ml_kem_test if: ${{ matrix.os != 'windows-latest' }} - - benchmark: - if: ${{ github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' }} - strategy: - fail-fast: false - matrix: - os: - - macos-latest - - ubuntu-latest - - windows-latest - - runs-on: ${{ matrix.os }} - defaults: - run: - shell: bash - working-directory: libcrux-ml-kem/c - - steps: - - uses: actions/checkout@v4 - - - name: 🔨 Build Release - run: | - cmake -B build -DCMAKE_BUILD_TYPE=Release - cmake --build build --config Release - - # FIXME: Benchmarks on Windows CI are not working right now. - # - name: 🏃🏻‍♀️ Benchmark - # run: ./build/Release/ml_kem_bench - # if: ${{ matrix.os == 'windows-latest' }} - - - name: 🏃🏻‍♀️ Benchmark (c) - run: ./build/ml_kem_bench - if: ${{ matrix.os != 'windows-latest' && (github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') }} - - - name: 🏃🏻‍♀️ Benchmark (cg) - working-directory: libcrux-ml-kem/cg - run: ./build/ml_kem_bench - if: ${{ matrix.os != 'windows-latest' && (github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') }} - - mq_status: - if: | - always() && - (github.event_name == 'workflow_dispatch' || github.event_name == 'merge_group') - needs: [benchmark] - uses: cryspen/actions/.github/workflows/merge-queue-status.yml@jonas/merge-queue-status - with: - needs_json: "${{toJSON(needs)}}" diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index 5fab6fabd..0438fb798 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -6,6 +6,7 @@ on: pull_request: branches: ["main", "dev"] workflow_dispatch: + merge_group: env: CARGO_TERM_COLOR: always diff --git a/.github/workflows/ecdh.yml b/.github/workflows/ecdh.yml index feee99cfa..438386e60 100644 --- a/.github/workflows/ecdh.yml +++ b/.github/workflows/ecdh.yml @@ -6,6 +6,7 @@ on: pull_request: branches: ["main", "dev", "*"] workflow_dispatch: + merge_group: env: CARGO_TERM_COLOR: always diff --git a/.github/workflows/hax.yml b/.github/workflows/hax.yml index bac3854d5..d324bff1c 100644 --- a/.github/workflows/hax.yml +++ b/.github/workflows/hax.yml @@ -11,6 +11,7 @@ on: - cron: "0 0 * * *" workflow_dispatch: + merge_group: env: CARGO_TERM_COLOR: always diff --git a/.github/workflows/kem.yml b/.github/workflows/kem.yml index ca3c7f23f..d4ada3cdf 100644 --- a/.github/workflows/kem.yml +++ b/.github/workflows/kem.yml @@ -6,6 +6,7 @@ on: pull_request: branches: ["main", "dev", "*"] workflow_dispatch: + merge_group: env: CARGO_TERM_COLOR: always diff --git a/.github/workflows/mldsa.yml b/.github/workflows/mldsa.yml index 8c46feafd..a05d1e6c3 100644 --- a/.github/workflows/mldsa.yml +++ b/.github/workflows/mldsa.yml @@ -6,6 +6,7 @@ on: pull_request: branches: ["main", "dev", "*"] workflow_dispatch: + merge_group: env: CARGO_TERM_COLOR: always diff --git a/.github/workflows/mlkem-bench.yml b/.github/workflows/mlkem-bench.yml new file mode 100644 index 000000000..b5c825c09 --- /dev/null +++ b/.github/workflows/mlkem-bench.yml @@ -0,0 +1,103 @@ +name: Benchmark ML-KEM + +on: + workflow_dispatch: + merge_group: + +env: + CARGO_TERM_COLOR: always + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + benchmark: + strategy: + fail-fast: true + matrix: + bits: [32, 64] + os: + - macos-13 + - macos-latest + - ubuntu-latest + - windows-latest + exclude: + # There's no such thing as 32-bit macOS + - bits: 32 + os: "macos-latest" + - bits: 32 + os: "macos-13" + + runs-on: ${{ matrix.os }} + defaults: + run: + shell: bash + working-directory: libcrux-ml-kem + + steps: + - uses: actions/checkout@v4 + + - name: Update dependencies + run: cargo update + + - run: echo "RUST_TARGET_FLAG=" > $GITHUB_ENV + if: ${{ matrix.bits == 64 }} + + - name: 🛠️ Setup Ubuntu x86 + if: ${{ matrix.bits == 32 && matrix.os == 'ubuntu-latest' }} + run: | + rustup target add i686-unknown-linux-gnu + sudo apt-get update + sudo apt-get install -y gcc-multilib g++-multilib + + - name: 🛠️ Setup Ubuntu x64 + if: ${{ matrix.bits == 64 && matrix.os == 'ubuntu-latest' }} + run: | + rustup target add aarch64-unknown-linux-gnu + + - name: 🛠️ Setup macOS + if: ${{ matrix.os == 'macos-latest' }} + run: | + rustup target add aarch64-apple-darwin + + # Set up 32 bit systems + + - name: 🛠️ Config Windows x86 + run: echo "RUST_TARGET_FLAG=--target=i686-pc-windows-msvc" > $GITHUB_ENV + if: ${{ matrix.bits == 32 && matrix.os == 'windows-latest' }} + + - name: 🛠️ Config Linux x86 + run: | + echo "RUST_TARGET_FLAG=--target=i686-unknown-linux-gnu" > $GITHUB_ENV + if: ${{ matrix.bits == 32 && matrix.os == 'ubuntu-latest' }} + + # - name: 🔨 Build + # run: cargo build --benches + + # - name: ⬆ Upload build + # uses: ./.github/actions/upload_artifacts + # with: + # name: benchmarks_${{ matrix.os }}_${{ matrix.bits }} + + # Benchmarks ... + + - name: 🏃🏻‍♀️ Benchmarks + run: cargo bench --verbose $RUST_TARGET_FLAG -- --output-format bencher | tee bench.txt + + - name: 🏃🏻‍♀️ Benchmarks Portable + run: | + cargo clean + LIBCRUX_DISABLE_SIMD128=1 LIBCRUX_DISABLE_SIMD256=1 cargo bench --verbose $RUST_TARGET_FLAG -- --output-format bencher | sed 's/^test \(.*\) \.\.\. bench/test portable \1 ... bench/' | tee -a bench.txt + - name: Store benchmarks + uses: benchmark-action/github-action-benchmark@v1 + with: + name: ML-KEM Benchmark + tool: 'cargo' + output-file-path: libcrux-ml-kem/bench.txt + benchmark-data-dir-path: dev/bench/mlkem + github-token: ${{ secrets.GITHUB_TOKEN }} + auto-push: true + + + diff --git a/.github/workflows/mlkem.yml b/.github/workflows/mlkem.yml index 6e7c59209..575339c5d 100644 --- a/.github/workflows/mlkem.yml +++ b/.github/workflows/mlkem.yml @@ -17,7 +17,6 @@ concurrency: jobs: build: - if: ${{ github.event_name != 'merge_group' }} strategy: fail-fast: false matrix: @@ -174,96 +173,3 @@ jobs: run: | cargo clean cargo hack test --each-feature $EXCLUDE_FEATURES --verbose $RUST_TARGET_FLAG - - benchmarks: - if: ${{ github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' }} - strategy: - fail-fast: true - matrix: - bits: [32, 64] - os: - - macos-13 - - macos-latest - - ubuntu-latest - - windows-latest - exclude: - # There's no such thing as 32-bit macOS - - bits: 32 - os: "macos-latest" - - bits: 32 - os: "macos-13" - - runs-on: ${{ matrix.os }} - defaults: - run: - shell: bash - working-directory: libcrux-ml-kem - - steps: - - uses: actions/checkout@v4 - - - name: Update dependencies - run: cargo update - - - run: echo "RUST_TARGET_FLAG=" > $GITHUB_ENV - if: ${{ matrix.bits == 64 }} - - - name: 🛠️ Setup Ubuntu x86 - if: ${{ matrix.bits == 32 && matrix.os == 'ubuntu-latest' }} - run: | - rustup target add i686-unknown-linux-gnu - sudo apt-get update - sudo apt-get install -y gcc-multilib g++-multilib - - - name: 🛠️ Setup Ubuntu x64 - if: ${{ matrix.bits == 64 && matrix.os == 'ubuntu-latest' }} - run: | - rustup target add aarch64-unknown-linux-gnu - - - name: 🛠️ Setup macOS - if: ${{ matrix.os == 'macos-latest' }} - run: | - rustup target add aarch64-apple-darwin - - # Set up 32 bit systems - - - name: 🛠️ Config Windows x86 - run: echo "RUST_TARGET_FLAG=--target=i686-pc-windows-msvc" > $GITHUB_ENV - if: ${{ matrix.bits == 32 && matrix.os == 'windows-latest' }} - - - name: 🛠️ Config Linux x86 - run: | - echo "RUST_TARGET_FLAG=--target=i686-unknown-linux-gnu" > $GITHUB_ENV - if: ${{ matrix.bits == 32 && matrix.os == 'ubuntu-latest' }} - - # - name: 🔨 Build - # run: cargo build --benches - - # - name: ⬆ Upload build - # uses: ./.github/actions/upload_artifacts - # with: - # name: benchmarks_${{ matrix.os }}_${{ matrix.bits }} - - # Benchmarks ... - - - name: 🏃🏻‍♀️ Benchmarks - run: cargo bench --verbose $RUST_TARGET_FLAG - - - name: 🏃🏻‍♀️ Benchmarks Portable - run: | - cargo clean - LIBCRUX_DISABLE_SIMD128=1 LIBCRUX_DISABLE_SIMD256=1 cargo bench --verbose $RUST_TARGET_FLAG - - mq_status: - if: | - always() && - github.event_name == 'workflow_dispatch' || github.event_name == 'merge_group' - needs: [benchmarks] - runs-on: ubuntu-latest - steps: - - name: Successful - if: ${{ !(contains(needs.*.result, 'failure')) }} - run: exit 0 - - name: Failing - if: ${{ contains(needs.*.result, 'failure') }} - run: exit 1 diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml index aa893300c..f852b95a3 100644 --- a/.github/workflows/nix.yml +++ b/.github/workflows/nix.yml @@ -4,6 +4,7 @@ on: push: branches: [main, dev] pull_request: + merge_group: jobs: nix: diff --git a/.github/workflows/platform.yml b/.github/workflows/platform.yml index 3415ee2f3..074dea37d 100644 --- a/.github/workflows/platform.yml +++ b/.github/workflows/platform.yml @@ -6,6 +6,7 @@ on: pull_request: branches: ["main", "dev", "*"] workflow_dispatch: + merge_group: env: CARGO_TERM_COLOR: always diff --git a/.github/workflows/rust-bench.yml b/.github/workflows/rust-bench.yml new file mode 100644 index 000000000..20644290d --- /dev/null +++ b/.github/workflows/rust-bench.yml @@ -0,0 +1,98 @@ +name: Benchmark + +on: + workflow_dispatch: + merge_group: + +env: + CARGO_TERM_COLOR: always + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + benchmark: + strategy: + fail-fast: true + matrix: + bits: [32, 64] + os: + - macos-latest + - ubuntu-latest + - windows-latest + exclude: + # There's no such thing as 32-bit macOS + - bits: 32 + os: "macos-latest" + # FIXME: Linking isn't working here yet for hacl #42 + - bits: 32 + os: "windows-latest" + + runs-on: ${{ matrix.os }} + defaults: + run: + shell: bash + + steps: + - uses: actions/checkout@v4 + + - run: echo "RUST_TARGET_FLAG=" > $GITHUB_ENV + if: ${{ matrix.bits == 64 }} + + - name: ⚙️ Setup Ubuntu x86 + if: ${{ matrix.bits == 32 && matrix.os == 'ubuntu-latest' }} + run: | + rustup target add i686-unknown-linux-gnu + sudo apt-get update + sudo apt-get install -y gcc-multilib g++-multilib + + - name: ⚙️ Setup Ubuntu x64 + if: ${{ matrix.bits == 64 && matrix.os == 'ubuntu-latest' }} + run: | + rustup target add aarch64-unknown-linux-gnu + + - name: ⚙️ Setup macOS + if: ${{ matrix.os == 'macos-latest' }} + run: | + rustup target add aarch64-apple-darwin + + # Set up 32 bit systems + + - name: 🛠️ Config Windows x86 + run: echo "RUST_TARGET_FLAG=--target=i686-pc-windows-msvc" > $GITHUB_ENV + if: ${{ matrix.bits == 32 && matrix.os == 'windows-latest' }} + + - name: 🛠️ Config Linux x86 + run: | + echo "RUST_TARGET_FLAG=--target=i686-unknown-linux-gnu" > $GITHUB_ENV + if: ${{ matrix.bits == 32 && matrix.os == 'ubuntu-latest' }} + + # Set up windows + + - name: ⚙️ Setup Windows x86 + if: ${{ matrix.bits == 32 && matrix.os == 'windows-latest' }} + shell: pwsh + run: | + echo "VCPKG_ROOT=$env:VCPKG_INSTALLATION_ROOT" | Out-File -FilePath $env:GITHUB_ENV -Append + vcpkg install openssl:x86-windows-static-md + + - name: ⚙️ Setup Windows x64 + if: ${{ matrix.bits == 64 && matrix.os == 'windows-latest' }} + shell: pwsh + run: | + echo "VCPKG_ROOT=$env:VCPKG_INSTALLATION_ROOT" | Out-File -FilePath $env:GITHUB_ENV -Append + vcpkg install openssl:x64-windows-static-md + + # Benchmarks ... + + - name: 🏃🏻‍♀️ Benchmarks + run: cargo bench --verbose $RUST_TARGET_FLAG -p benchmarks -- --output-format bencher | tee bench.txt + - name: Store Benchmarks + uses: benchmark-action/github-action-benchmark@v1 + with: + name: ML-KEM Benchmark + tool: 'cargo' + output-file-path: bench.txt + github-token: ${{ secrets.GITHUB_TOKEN }} + auto-push: true diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 7b4324a5c..c09f98d06 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -17,7 +17,6 @@ concurrency: jobs: build: - if: ${{ github.event_name != 'merge_group' }} strategy: fail-fast: false matrix: @@ -123,7 +122,7 @@ jobs: run: cargo build --verbose $RUST_TARGET_FLAG wasm: - if: ${{ github.event_name == 'workflow_dispatch' || github.event_name == 'merge_group' }} + if: false #${{ github.event_name == 'workflow_dispatch' || github.event_name == 'merge_group' }} runs-on: ubuntu-latest steps: @@ -141,90 +140,4 @@ jobs: - name: 🏃🏻‍♀️ Test run: CC=emcc AR=emar wasm-pack test --node --features wasm - benchmarks: - if: ${{ github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch' }} - strategy: - fail-fast: true - matrix: - bits: [32, 64] - os: - - macos-latest - - ubuntu-latest - - windows-latest - exclude: - # There's no such thing as 32-bit macOS - - bits: 32 - os: "macos-latest" - # FIXME: Linking isn't working here yet for hacl #42 - - bits: 32 - os: "windows-latest" - - runs-on: ${{ matrix.os }} - defaults: - run: - shell: bash - - steps: - - uses: actions/checkout@v4 - - - run: echo "RUST_TARGET_FLAG=" > $GITHUB_ENV - if: ${{ matrix.bits == 64 }} - - - name: ⚙️ Setup Ubuntu x86 - if: ${{ matrix.bits == 32 && matrix.os == 'ubuntu-latest' }} - run: | - rustup target add i686-unknown-linux-gnu - sudo apt-get update - sudo apt-get install -y gcc-multilib g++-multilib - - - name: ⚙️ Setup Ubuntu x64 - if: ${{ matrix.bits == 64 && matrix.os == 'ubuntu-latest' }} - run: | - rustup target add aarch64-unknown-linux-gnu - - - name: ⚙️ Setup macOS - if: ${{ matrix.os == 'macos-latest' }} - run: | - rustup target add aarch64-apple-darwin - - # Set up 32 bit systems - - - name: 🛠️ Config Windows x86 - run: echo "RUST_TARGET_FLAG=--target=i686-pc-windows-msvc" > $GITHUB_ENV - if: ${{ matrix.bits == 32 && matrix.os == 'windows-latest' }} - - - name: 🛠️ Config Linux x86 - run: | - echo "RUST_TARGET_FLAG=--target=i686-unknown-linux-gnu" > $GITHUB_ENV - if: ${{ matrix.bits == 32 && matrix.os == 'ubuntu-latest' }} - - # Set up windows - - - name: ⚙️ Setup Windows x86 - if: ${{ matrix.bits == 32 && matrix.os == 'windows-latest' }} - shell: pwsh - run: | - echo "VCPKG_ROOT=$env:VCPKG_INSTALLATION_ROOT" | Out-File -FilePath $env:GITHUB_ENV -Append - vcpkg install openssl:x86-windows-static-md - - - name: ⚙️ Setup Windows x64 - if: ${{ matrix.bits == 64 && matrix.os == 'windows-latest' }} - shell: pwsh - run: | - echo "VCPKG_ROOT=$env:VCPKG_INSTALLATION_ROOT" | Out-File -FilePath $env:GITHUB_ENV -Append - vcpkg install openssl:x64-windows-static-md - - # Benchmarks ... - - - name: 🏃🏻‍♀️ Benchmarks - run: cargo bench --verbose $RUST_TARGET_FLAG -p benchmarks - - mq_status: - if: | - always() && - (github.event_name == 'workflow_dispatch' || github.event_name == 'merge_group') - needs: [benchmarks] - uses: cryspen/actions/.github/workflows/merge-queue-status.yml@jonas/merge-queue-status - with: - needs_json: "${{toJSON(needs)}}" diff --git a/.github/workflows/skip-benches-in-prs.yml b/.github/workflows/skip-benches-in-prs.yml new file mode 100644 index 000000000..fd259b985 --- /dev/null +++ b/.github/workflows/skip-benches-in-prs.yml @@ -0,0 +1,14 @@ +name: Skip Benchmarks in PRs + +on: [ pull_request ] +jobs: + benchmark: + runs-on: ubuntu-latest + steps: + - run: true + benchmarks: + runs-on: ubuntu-latest + steps: + - run: true + + diff --git a/.github/workflows/specs.yml b/.github/workflows/specs.yml index 83a79e802..383d45cdf 100644 --- a/.github/workflows/specs.yml +++ b/.github/workflows/specs.yml @@ -5,6 +5,7 @@ on: branches: [ "main", "dev" ] pull_request: branches: [ "main", "dev" ] + merge_group: env: CARGO_TERM_COLOR: always diff --git a/Cargo.toml b/Cargo.toml index b2e2765e3..3bd1be7a9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -56,6 +56,7 @@ exclude = [ [lib] crate-type = ["staticlib", "cdylib", "lib"] +bench = false # so libtest doesn't eat the arguments for criterion [build-dependencies] libcrux-platform = { version = "=0.0.2-alpha.3", path = "sys/platform" } @@ -72,6 +73,7 @@ rand = { version = "0.8" } log = { version = "0.4", optional = true } # WASM API wasm-bindgen = { version = "0.2.87", optional = true } +getrandom = { version = "0.2", features = ["js"], optional = true } # When using the hax toolchain, we have more dependencies. # This is only required when doing proofs. @@ -98,7 +100,7 @@ getrandom = { version = "0.2", features = ["js"] } [features] hacspec = [] # TODO: #7 Use specs instead of efficient implementations rand = [] -wasm = ["wasm-bindgen"] +wasm = ["wasm-bindgen", "getrandom"] log = ["dep:log"] tests = [] # Expose functions for testing. experimental = [] # Expose experimental APIs. diff --git a/benchmarks/Cargo.toml b/benchmarks/Cargo.toml index 3e9f3b781..3458bfeda 100644 --- a/benchmarks/Cargo.toml +++ b/benchmarks/Cargo.toml @@ -9,13 +9,16 @@ repository.workspace = true readme.workspace = true publish = false +[lib] +bench = false # so libtest doesn't eat the arguments for criterion + [dependencies] +rand = { version = "0.8" } [dev-dependencies] libcrux = { path = "../", features = ["rand", "tests"] } libcrux-kem = { path = "../libcrux-kem", features = ["tests"] } libcrux-ml-kem = { path = "../libcrux-ml-kem" } -rand = { version = "0.8" } rand_core = { version = "0.6" } # Benchmarking "RustCrypto" chacha20poly1305 = "0.10" diff --git a/benchmarks/benches/aead.rs b/benchmarks/benches/aead.rs index 94994baf3..bfb74a25a 100644 --- a/benchmarks/benches/aead.rs +++ b/benchmarks/benches/aead.rs @@ -2,10 +2,9 @@ use chacha20poly1305::{AeadCore, AeadInPlace, KeyInit}; use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criterion, Throughput}; use libcrux::{aead::*, digest, drbg}; -mod util; +use benchmarks::util::*; use rand_core::OsRng; use ring::aead::UnboundKey; -use util::*; // Comparing libcrux performance for different payload sizes and other implementations. fn comparisons_encrypt(c: &mut Criterion) { diff --git a/benchmarks/benches/p256.rs b/benchmarks/benches/p256.rs index a562bebd2..70296411e 100644 --- a/benchmarks/benches/p256.rs +++ b/benchmarks/benches/p256.rs @@ -1,7 +1,6 @@ use criterion::{criterion_group, criterion_main, BatchSize, Criterion}; use libcrux::ecdh; -mod util; use rand_core::OsRng; fn derive(c: &mut Criterion) { diff --git a/benchmarks/benches/sha2.rs b/benchmarks/benches/sha2.rs index d9f82577e..5e3f16b2b 100644 --- a/benchmarks/benches/sha2.rs +++ b/benchmarks/benches/sha2.rs @@ -3,8 +3,7 @@ use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criteri use libcrux::digest::{self, *}; -mod util; -use util::*; +use benchmarks::util::*; macro_rules! impl_comp { ($fun:ident, $libcrux:expr, $ring:expr, $rust_crypto:ty, $openssl:expr) => { diff --git a/benchmarks/benches/sha3.rs b/benchmarks/benches/sha3.rs index ca9deb998..dbf2494d7 100644 --- a/benchmarks/benches/sha3.rs +++ b/benchmarks/benches/sha3.rs @@ -3,8 +3,7 @@ use criterion::{criterion_group, criterion_main, BatchSize, BenchmarkId, Criteri use libcrux::digest::{self, *}; -mod util; -use util::*; +use benchmarks::util::*; macro_rules! impl_comp { ($fun:ident, $libcrux:expr, $rust_crypto:ty, $openssl:expr) => { diff --git a/benchmarks/benches/util.rs b/benchmarks/benches/util.rs deleted file mode 100644 index 1e7439e8e..000000000 --- a/benchmarks/benches/util.rs +++ /dev/null @@ -1,16 +0,0 @@ -#![allow(dead_code)] - -pub fn randombytes(n: usize) -> Vec { - use rand::rngs::OsRng; - use rand::RngCore; - - let mut bytes = vec![0u8; n]; - OsRng.fill_bytes(&mut bytes); - bytes -} - -pub fn fmt(x: usize) -> String { - let base = (x as f64).log(1024f64).floor() as usize; - let suffix = ["", "KB", "MB", "GB"]; - format!("{} {}", x >> (10 * base), suffix[base]) -} diff --git a/benchmarks/benches/x25519.rs b/benchmarks/benches/x25519.rs index a9d9b793d..af5730814 100644 --- a/benchmarks/benches/x25519.rs +++ b/benchmarks/benches/x25519.rs @@ -1,9 +1,8 @@ use criterion::{criterion_group, criterion_main, BatchSize, Criterion}; use libcrux::ecdh; -mod util; +use benchmarks::util::*; use rand::RngCore; -use util::*; fn derive(c: &mut Criterion) { // Comparing libcrux performance for different payload sizes and other implementations. diff --git a/benchmarks/src/lib.rs b/benchmarks/src/lib.rs index 8b1378917..293e5e4c7 100644 --- a/benchmarks/src/lib.rs +++ b/benchmarks/src/lib.rs @@ -1 +1,16 @@ +pub mod util { + pub fn randombytes(n: usize) -> Vec { + use rand::rngs::OsRng; + use rand::RngCore; + let mut bytes = vec![0u8; n]; + OsRng.fill_bytes(&mut bytes); + bytes + } + + pub fn fmt(x: usize) -> String { + let base = (x as f64).log(1024f64).floor() as usize; + let suffix = ["", "KB", "MB", "GB"]; + format!("{} {}", x >> (10 * base), suffix[base]) + } +} diff --git a/libcrux-ml-dsa/Cargo.toml b/libcrux-ml-dsa/Cargo.toml index 5408a697b..0eb6a57f8 100644 --- a/libcrux-ml-dsa/Cargo.toml +++ b/libcrux-ml-dsa/Cargo.toml @@ -10,6 +10,9 @@ readme.workspace = true description = "Libcrux ML-DSA implementation" publish = false +[lib] +bench = false # so libtest doesn't eat the arguments to criterion + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] diff --git a/libcrux-ml-kem/Cargo.toml b/libcrux-ml-kem/Cargo.toml index c967a416b..1deaa591c 100644 --- a/libcrux-ml-kem/Cargo.toml +++ b/libcrux-ml-kem/Cargo.toml @@ -18,6 +18,9 @@ exclude = [ "/hax.py", ] +[lib] +bench = false # so libtest doesn't eat the arguments to criterion + [dependencies] rand_core = { version = "0.6" } libcrux-platform = { version = "0.0.2-alpha.3", path = "../sys/platform" } diff --git a/libcrux-psq/Cargo.toml b/libcrux-psq/Cargo.toml index 8f9bb74b1..4e0f7395d 100644 --- a/libcrux-psq/Cargo.toml +++ b/libcrux-psq/Cargo.toml @@ -10,6 +10,9 @@ readme.workspace = true description = "Libcrux Pre-Shared post-Quantum key establishement protocol" publish = false +[lib] +bench = false # so libtest doesn't eat the arguments to criterion + [dependencies] libcrux-kem = { version = "0.0.2-alpha.3", path = "../libcrux-kem", features = [ "pre-verification", diff --git a/libcrux-sha3/Cargo.toml b/libcrux-sha3/Cargo.toml index c93712c4b..ebf3dde70 100644 --- a/libcrux-sha3/Cargo.toml +++ b/libcrux-sha3/Cargo.toml @@ -10,6 +10,9 @@ readme = "README.md" description = "Libcrux SHA-3 implementation" exclude = ["/proofs", "/c.sh", "/c.yaml", "/tests/tv", "tests/cavp.rs"] +[lib] +bench = false # so libtest doesn't eat the arguments to criterion + [dependencies] libcrux-platform = { version = "0.0.2-alpha.3", path = "../sys/platform" } libcrux-intrinsics = { version = "0.0.2-alpha.3", path = "../libcrux-intrinsics" }