Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion benches/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use criterion::criterion_main;

pub mod pfdh;
pub mod psf;
pub mod regev;

criterion_main! {regev::benches, pfdh::benches}
criterion_main! {regev::benches, pfdh::benches, psf::benches}
100 changes: 100 additions & 0 deletions benches/psf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
// Copyright © 2025 Niklas Siemer
//
// This file is part of qFALL-crypto.
//
// qFALL-crypto is free software: you can redistribute it and/or modify it under
// the terms of the Mozilla Public License Version 2.0 as published by the
// Mozilla Foundation. See <https://mozilla.org/en-US/MPL/2.0/>.

use criterion::{criterion_group, Criterion};
use qfall_crypto::{
primitive::psf::{PSFPerturbation, PSF, PSFGPV},
sample::g_trapdoor::gadget_parameters::GadgetParameters,
};
use qfall_math::{integer_mod_q::MatZq, rational::Q};

/// Benchmark [bench_psf] with `n = 8`.
///
/// This benchmark can be run with for example:
/// - `cargo criterion PSF\ GPV\ n=8`
/// - `cargo bench --bench benchmarks PSF\ GPV\ n=8`
/// - `cargo flamegraph --bench benchmarks -- --bench PSF\ GPV\ n=8`
///
/// Shorter variants or regex expressions can also be used to specify the
/// benchmark name. The `\ ` is used to escape the space, alternatively,
/// quotation marks can be used.
fn bench_psf(c: &mut Criterion) {
let (n, q) = (8, 128);

let psf = PSFGPV {
gp: GadgetParameters::init_default(n, q),
// multiply with the rounding parameter from next test to have the same samplign parameter
s: Q::from(30) * Q::from(n).log(2).unwrap(),
};

let target = MatZq::sample_uniform(n, 1, q);
let (a, r) = psf.trap_gen();

c.bench_function("PSF GPV n=8", |b| b.iter(|| psf.samp_p(&a, &r, &target)));
}

/// Benchmark [bench_psf_perturbation] with `n = 8`.
///
/// This benchmark can be run with for example:
/// - `cargo criterion PSF\ Perturbation\ n=8`
/// - `cargo bench --bench benchmarks PSF\ Perturbation\ n=8`
/// - `cargo flamegraph --bench benchmarks -- --bench PSF\ Perturbation\ n=8`
///
/// Shorter variants or regex expressions can also be used to specify the
/// benchmark name. The `\ ` is used to escape the space, alternatively,
/// quotation marks can be used.
fn bench_psf_perturbation(c: &mut Criterion) {
let (n, q) = (8, 128);

let psf = PSFPerturbation {
gp: GadgetParameters::init_default(n, q),
s: Q::from(30),
r: Q::from(n).log(2).unwrap(),
};

let target = MatZq::sample_uniform(n, 1, q);
let (a, r) = psf.trap_gen();

c.bench_function("PSF Perturbation n=8", |b| {
b.iter(|| psf.samp_p(&a, &r, &target))
});
}

/// Benchmark [bench_psf_perturbation] with `n = 64`.
///
/// This benchmark can be run with for example:
/// - `cargo criterion PSF\ Perturbation\ n=64`
/// - `cargo bench --bench benchmarks PSF\ Perturbation\ n=64`
/// - `cargo flamegraph --bench benchmarks -- --bench PSF\ Perturbation\ n=64`
///
/// Shorter variants or regex expressions can also be used to specify the
/// benchmark name. The `\ ` is used to escape the space, alternatively,
/// quotation marks can be used.
fn bench_psf_perturbation_larger(c: &mut Criterion) {
let (n, q) = (64, 128);

let psf = PSFPerturbation {
gp: GadgetParameters::init_default(n, q),
s: Q::from(100),
r: Q::from(n).log(2).unwrap(),
};

let target = MatZq::sample_uniform(n, 1, q);
let (a, r) = psf.trap_gen();

c.bench_function("PSF Perturbation n=64", |b| {
b.iter(|| psf.samp_p(&a, &r, &target))
});
}

criterion_group!(
benches,
bench_psf,
bench_psf_perturbation,
bench_psf_perturbation_larger,
);
6 changes: 6 additions & 0 deletions src/primitive/psf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,18 @@
//! January. Implementation and evaluation of improved Gaussian sampling for lattice
//! trapdoors. In Proceedings of the 6th Workshop on Encrypted Computing & Applied
//! Homomorphic Cryptography (pp. 61-71). <https://dl.acm.org/doi/pdf/10.1145/3267973.3267975>
//! - \[3\] Peikert, Chris.
//! An efficient and parallel Gaussian sampler for lattices.
//! In: Annual Cryptology Conference - CRYPTO 2010.
//! Springer, Berlin, Heidelberg. <https://doi.org/10.1007/978-3-642-14623-7_5>

mod gpv;
mod gpv_ring;
mod mp_perturbation;

pub use gpv::PSFGPV;
pub use gpv_ring::PSFGPVRing;
pub use mp_perturbation::PSFPerturbation;

/// This trait should be implemented by all constructions that are
/// actual implementations of a preimage sampleable function.
Expand Down
Loading
Loading