-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chacha20: bring back
rand_core
support (#333)
Allows the crate's AVX2 / NEON implementations to be used as `rand_core`-compatible RNGs. See also: rust-random/rand#934
- Loading branch information
Showing
20 changed files
with
2,038 additions
and
486 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
target/ | ||
**/Cargo.lock | ||
**/Cargo.lock |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Benching ChaCha20 | ||
|
||
## A note from the criterion-cycles-per-byte github | ||
``` | ||
[`criterion-cycles-per-byte`] measures clock ticks rather than cycles. It will not provide accurate results on modern machines unless you calculate the ratio of ticks to cycles and take steps to ensure that that ratio remains consistent. | ||
``` | ||
|
||
## ChaCha20 Cipher benching | ||
You can bench the ChaCha20 cipher using `cargo bench -- apply_keystream` | ||
|
||
## ChaCha20Rng benching | ||
You can bench ChaCha20Rng using `cargo bench -- fill_bytes` | ||
|
||
## Measuring CPB for aarch64 | ||
`criterion-cycles-per-byte` can work on `aarch64` with Linux, but it might produce an error. This error occurred on an up-to-date Raspberry Pi 4b (as of 12/14/2023): | ||
``` | ||
Running src/chacha20.rs (target/release/deps/chacha20-02f555ae0af3670b) | ||
Gnuplot not found, using plotters backend | ||
Benchmarking stream-cipher/apply_keystream/1024: Warming up for 3.0000 serror: bench failed, to rerun pass `--bench chacha20` | ||
Caused by: | ||
process didn't exit successfully: `..../benches/target/release/deps/chacha20-02f555ae0af3670b --bench` (signal: 4, SIGILL: illegal instruction) | ||
``` | ||
|
||
The following adjustment can fix this. | ||
|
||
### Installing the cycle counter Linux Kernel Module on a Raspberry Pi 4b | ||
``` | ||
$ sudo apt-get update | ||
$ sudo apt-get upgrade | ||
$ sudo apt-get install build-essential raspberrypi-kernel-headers | ||
# cd to your chosen directory | ||
$ cd ../.. | ||
$ git clone https://github.com/jerinjacobk/armv8_pmu_cycle_counter_el0.git | ||
$ cd armv8_pmu_cycle_counter_el10 | ||
$ make | ||
$ sudo insmod pmu_el0_cycle_counter.ko | ||
# Verifying that it is installed | ||
$ lsmod | grep pmu_el0_cycle_counter | ||
pmu_el0_cycle_counter 16384 0 | ||
``` | ||
Without any other commands, this module will be deactivated after every reboot, and can be reactivated using | ||
``` | ||
$ cd armv8_pmu_cycle_counter_el10 | ||
$ sudo insmod pmu_el0_cycle_counter.ko | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,24 @@ | ||
use criterion::Criterion; | ||
|
||
#[cfg(any(target_arch = "x86_64", target_arch = "x86", all(target_arch = "aarch64", target_os = "linux")))] | ||
pub type Benchmarker = Criterion<criterion_cycles_per_byte::CyclesPerByte>; | ||
#[cfg(not(any(target_arch = "x86_64", target_arch = "x86", all(target_arch = "aarch64", target_os = "linux"))))] | ||
pub type Benchmarker = Criterion; | ||
|
||
#[macro_export] | ||
macro_rules! criterion_group_bench { | ||
($Name:ident, $Target:ident) => { | ||
#[cfg(any(target_arch = "x86_64", target_arch = "x86", all(target_arch = "aarch64", target_os = "linux")))] | ||
criterion_group!( | ||
name = $Name; | ||
config = Criterion::default().with_measurement(criterion_cycles_per_byte::CyclesPerByte); | ||
targets = $Target | ||
); | ||
#[cfg(not(any(target_arch = "x86_64", target_arch = "x86", all(target_arch = "aarch64", target_os = "linux"))))] | ||
criterion_group!( | ||
name = $Name; | ||
config = Criterion::default(); | ||
targets = $Target | ||
); | ||
} | ||
} |
Oops, something went wrong.