Skip to content

Commit

Permalink
feat(concrete_csprng): refactor the csprng to prepare core backend split
Browse files Browse the repository at this point in the history
BREAKING_CHANGE: this commit completely breaks the previous API
  • Loading branch information
aPere3 committed Apr 22, 2022
1 parent 1293596 commit 8c1d140
Show file tree
Hide file tree
Showing 30 changed files with 2,468 additions and 1,730 deletions.
14 changes: 10 additions & 4 deletions concrete-csprng/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@ rand = "0.8.3"
criterion = "0.3"

[features]
slow = []
multithread = ["rayon"]
parallel = ["rayon"]
seeder_x86_64_rdseed = []
seeder_linux = []
generator_x86_64_aesni = []
generator_soft = []

[[bench]]
name = "benchmark"
path = "benches/benchmark.rs"
harness = false
required-features = ["seeder_x86_64_rdseed", "generator_x86_64_aesni"]

[[bin]]
name = "generate_random"
path = "src/generate_random.rs"
name = "generate"
path = "src/main.rs"
required-features = ["seeder_x86_64_rdseed", "generator_x86_64_aesni"]
7 changes: 7 additions & 0 deletions concrete-csprng/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ The implementation is based on the AES blockcipher used in CTR mode, as describe
The current implementation uses special instructions existing on modern *intel* cpus. We may add a
generic implementation in the future.

## Running the benchmarks

To execute the benchmarks on an x86_64 platform:
```shell
RUSTFLAGS="-Ctarget-cpu=native" cargo bench --features=seeder_rdseed,generator_aesni
```

## License

This software is distributed under the BSD-3-Clause-Clear license. If you have any questions,
Expand Down
43 changes: 31 additions & 12 deletions concrete-csprng/benches/benchmark.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,53 @@
use concrete_csprng::RandomGenerator;
use criterion::{criterion_group, criterion_main, Criterion};
use concrete_csprng::generators::{
AesniRandomGenerator, BytesPerChild, ChildrenCount, RandomGenerator,
};
use concrete_csprng::seeders::{RdseedSeeder, Seeder};
use criterion::{black_box, criterion_group, criterion_main, Criterion};

const N_GEN: usize = 1_000_000;

fn unbounded_benchmark(c: &mut Criterion) {
let mut generator = RandomGenerator::new_hardware(None).unwrap();
c.bench_function("unbounded", |b| {
fn parent_generate(c: &mut Criterion) {
let mut seeder = RdseedSeeder;
let mut generator = AesniRandomGenerator::new(seeder.seed());
c.bench_function("parent_generate", |b| {
b.iter(|| {
(0..N_GEN).for_each(|_| {
generator.generate_next();
generator.next();
})
})
});
}

fn bounded_benchmark(c: &mut Criterion) {
let mut generator = RandomGenerator::new_hardware(None).unwrap();
fn child_generate(c: &mut Criterion) {
let mut seeder = RdseedSeeder;
let mut generator = AesniRandomGenerator::new(seeder.seed());
let mut generator = generator
.try_fork(1, N_GEN * 10_000)
.try_fork(ChildrenCount(1), BytesPerChild(N_GEN * 10_000))
.unwrap()
.next()
.unwrap();
c.bench_function("bounded", |b| {
c.bench_function("child_generate", |b| {
b.iter(|| {
(0..N_GEN).for_each(|_| {
generator.generate_next();
generator.next();
})
})
});
}

criterion_group!(benches, unbounded_benchmark, bounded_benchmark);
fn fork(c: &mut Criterion) {
let mut seeder = RdseedSeeder;
let mut generator = AesniRandomGenerator::new(seeder.seed());
c.bench_function("fork", |b| {
b.iter(|| {
black_box(
generator
.try_fork(ChildrenCount(2048), BytesPerChild(2048))
.unwrap(),
)
})
});
}

criterion_group!(benches, parent_generate, child_generate, fork);
criterion_main!(benches);
271 changes: 0 additions & 271 deletions concrete-csprng/src/counter/mod.rs

This file was deleted.

Loading

0 comments on commit 8c1d140

Please sign in to comment.