aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Grois <andi@grois.info>2022-10-20 21:45:43 +0200
committerAndreas Grois <andi@grois.info>2022-10-20 21:45:43 +0200
commite484af8f3c683e81d6445a4d66972ca1fa6897a6 (patch)
treef225e0c0228a576efc7d3b7974ccc7e8526f258b
parentbe766f81b6985b9df3da39d78fb19ec4383075c7 (diff)
parentea6789e5b33540270f5de3edb54264e6892fad73 (diff)
Merge branch 'main' into feature/heap-allocation-free-base-conversion
-rw-r--r--.gitignore4
-rw-r--r--Cargo.toml16
-rw-r--r--benches/hashrate.rs202
-rw-r--r--benches/hashrate_16.rs69
-rw-r--r--benches/hashrate_20.rs69
-rw-r--r--benches/hashrate_32.rs69
-rw-r--r--benches/leet.rs49
-rw-r--r--benches/mock_hashers/mod.rs59
8 files changed, 332 insertions, 205 deletions
diff --git a/.gitignore b/.gitignore
index 317aad4..89e1cba 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,5 @@
/target
/Cargo.lock
-*~ \ No newline at end of file
+*~
+perf.data*
+flamegraph.svg
diff --git a/Cargo.toml b/Cargo.toml
index 62fd7be..24363ab 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -28,5 +28,17 @@ rand = "0.8.5"
rand_xoshiro = "0.6.0"
[[bench]]
-name = "hashrate"
-harness = false \ No newline at end of file
+name = "hashrate_32"
+harness = false
+
+[[bench]]
+name = "hashrate_20"
+harness = false
+
+[[bench]]
+name = "hashrate_16"
+harness = false
+
+[[bench]]
+name = "leet"
+harness = false
diff --git a/benches/hashrate.rs b/benches/hashrate.rs
deleted file mode 100644
index 9691410..0000000
--- a/benches/hashrate.rs
+++ /dev/null
@@ -1,202 +0,0 @@
-use criterion::{black_box, criterion_group, criterion_main, Criterion};
-use passwordmaker_rs::{PasswordMaker, Hasher, HasherList, HashAlgorithm, LeetLevel};
-
-//We want to bench the surrounding string manipulation, not the hashers.
-//For this reason, we fake them with a black_box.
-
-struct MockMd4;
-struct MockMd5;
-struct MockSha1;
-struct MockSha256;
-struct MockRipeMD160;
-impl Hasher for MockMd4{
- type Output = [u8;16];
- fn hash(_data : &[u8]) -> Self::Output {
- black_box([156u8,4u8,123u8,54u8,91u8,85u8,34u8,159u8,243u8,210u8,35u8,41u8,31u8,34u8,75u8,94u8])
- }
-}
-impl Hasher for MockMd5{
- type Output = [u8;16];
- fn hash(_data : &[u8]) -> Self::Output {
- black_box([156u8,4u8,123u8,54u8,91u8,85u8,34u8,159u8,243u8,210u8,35u8,41u8,31u8,34u8,75u8,94u8])
- }
-}
-impl Hasher for MockSha1{
- type Output = [u8;20];
- fn hash(_data : &[u8]) -> Self::Output {
- black_box([156u8,4u8,123u8,54u8,91u8,85u8,34u8,159u8,243u8,210u8,35u8,41u8,31u8,34u8,75u8,94u8,46,49,13,24])
- }
-}
-impl Hasher for MockSha256{
- type Output = [u8;32];
- fn hash(_data : &[u8]) -> Self::Output {
- black_box([156u8,4u8,123u8,54u8,91u8,85u8,34u8,159u8,243u8,210u8,35u8,41u8,31u8,34u8,75u8,94u8,156u8,4u8,123u8,54u8,91u8,85u8,34u8,159u8,243u8,210u8,35u8,41u8,31u8,34u8,75u8,94u8])
- }
-}
-impl Hasher for MockRipeMD160{
- type Output = [u8;20];
- fn hash(_data : &[u8]) -> Self::Output {
- black_box([156u8,4u8,123u8,54u8,91u8,85u8,34u8,159u8,243u8,210u8,35u8,41u8,31u8,34u8,75u8,94u8,46,49,13,24])
- }
-}
-
-impl passwordmaker_rs::Md4 for MockMd4{}
-impl passwordmaker_rs::Md5 for MockMd5{}
-impl passwordmaker_rs::Sha1 for MockSha1{}
-impl passwordmaker_rs::Sha256 for MockSha256{}
-impl passwordmaker_rs::Ripemd160 for MockRipeMD160{}
-
-struct MockHashes{}
-impl HasherList for MockHashes {
- type MD4 = MockMd4;
- type MD5 = MockMd5;
- type SHA1 = MockSha1;
- type SHA256 = MockSha256;
- type RIPEMD160 = MockRipeMD160;
-}
-
-type Pwm<'a> = PasswordMaker<'a, MockHashes>;
-
-fn criterion_bench_32bytes(c: &mut Criterion) {
- let pwm = Pwm::new(
- HashAlgorithm::Sha256,
- passwordmaker_rs::UseLeetWhenGenerating::NotAtAll,
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()_-+={}|[]\\:\";'<>?,./",
- "",
- "",
- 150,
- "",
- ""
- ).unwrap();
- c.bench_function("32 bytes", |b| b.iter(|| {
- pwm.generate(
- black_box("This is a long string. With many, many characters. For no particular reason.".to_owned()),
- black_box("And another relatively long string for no reason other than it being long.".to_owned())
- )
- }));
-}
-
-fn criterion_bench_32bytes_extreme(c: &mut Criterion) {
- let pwm = Pwm::new(
- HashAlgorithm::Sha256,
- passwordmaker_rs::UseLeetWhenGenerating::NotAtAll,
- "XY",
- "",
- "",
- 150,
- "",
- ""
- ).unwrap();
- c.bench_function("32 bytes extreme", |b| b.iter(|| {
- pwm.generate(
- black_box("This is a long string. With many, many characters. For no particular reason.".to_owned()),
- black_box("And another relatively long string for no reason other than it being long.".to_owned())
- )
- }));
-}
-
-fn criterion_bench_20bytes(c: &mut Criterion) {
- let pwm = Pwm::new(
- HashAlgorithm::Ripemd160,
- passwordmaker_rs::UseLeetWhenGenerating::NotAtAll,
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()_-+={}|[]\\:\";'<>?,./",
- "",
- "",
- 150,
- "",
- ""
- ).unwrap();
- c.bench_function("20 bytes", |b| b.iter(|| {
- pwm.generate(
- black_box("This is a long string. With many, many characters. For no particular reason.".to_owned()),
- black_box("And another relatively long string for no reason other than it being long.".to_owned())
- )
- }));
-}
-
-fn criterion_bench_16bytes(c: &mut Criterion) {
- let pwm = Pwm::new(
- HashAlgorithm::Md5,
- passwordmaker_rs::UseLeetWhenGenerating::NotAtAll,
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()_-+={}|[]\\:\";'<>?,./",
- "",
- "",
- 150,
- "",
- ""
- ).unwrap();
- c.bench_function("16 bytes", |b| b.iter(|| {
- pwm.generate(
- black_box("This is a long string. With many, many characters. For no particular reason.".to_owned()),
- black_box("And another relatively long string for no reason other than it being long.".to_owned())
- )
- }));
-}
-
-fn criterion_bench_16bytes_extreme(c: &mut Criterion) {
- let pwm = Pwm::new(
- HashAlgorithm::Md5,
- passwordmaker_rs::UseLeetWhenGenerating::NotAtAll,
- "XY",
- "",
- "",
- 150,
- "",
- ""
- ).unwrap();
- c.bench_function("16 bytes extreme", |b| b.iter(|| {
- pwm.generate(
- black_box("This is a long string. With many, many characters. For no particular reason.".to_owned()),
- black_box("And another relatively long string for no reason other than it being long.".to_owned())
- )
- }));
-}
-
-fn criterion_bench_16bytes_post_leet(c: &mut Criterion) {
- let pwm = Pwm::new(
- HashAlgorithm::Md5,
- passwordmaker_rs::UseLeetWhenGenerating::After { level: LeetLevel::Six },
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()_-+={}|[]\\:\";'<>?,./",
- "",
- "",
- 150,
- "",
- ""
- ).unwrap();
- c.bench_function("16 bytes with post_leet", |b| b.iter(|| {
- pwm.generate(
- black_box("This is a long string. With many, many characters. For no particular reason.".to_owned()),
- black_box("And another relatively long string for no reason other than it being long.".to_owned())
- )
- }));
-}
-
-fn criterion_bench_16bytes_pre_leet(c: &mut Criterion) {
- let pwm = Pwm::new(
- HashAlgorithm::Md5,
- passwordmaker_rs::UseLeetWhenGenerating::Before { level: LeetLevel::Six },
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()_-+={}|[]\\:\";'<>?,./",
- "",
- "",
- 150,
- "",
- ""
- ).unwrap();
- c.bench_function("16 bytes with pre_leet", |b| b.iter(|| {
- pwm.generate(
- black_box("This is a long string. With many, many characters. For no particular reason.".to_owned()),
- black_box("And another relatively long string for no reason other than it being long.".to_owned())
- )
- }));
-}
-
-criterion_group!(benches,
- criterion_bench_32bytes,
- criterion_bench_32bytes_extreme,
- criterion_bench_20bytes,
- criterion_bench_16bytes,
- criterion_bench_16bytes_extreme,
- criterion_bench_16bytes_post_leet,
- criterion_bench_16bytes_pre_leet
-);
-criterion_main!(benches);
diff --git a/benches/hashrate_16.rs b/benches/hashrate_16.rs
new file mode 100644
index 0000000..20602d0
--- /dev/null
+++ b/benches/hashrate_16.rs
@@ -0,0 +1,69 @@
+mod mock_hashers;
+
+use criterion::{black_box, criterion_group, criterion_main, Criterion};
+use passwordmaker_rs::HashAlgorithm;
+use mock_hashers::Pwm;
+
+fn criterion_bench_16bytes_typical(c: &mut Criterion) {
+ let pwm = Pwm::new(
+ HashAlgorithm::Md5,
+ passwordmaker_rs::UseLeetWhenGenerating::NotAtAll,
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()_-+={}|[]\\:\";'<>?,./",
+ "",
+ "",
+ 12,
+ "",
+ ""
+ ).unwrap();
+ c.bench_function("16 bytes typical", |b| b.iter(|| {
+ pwm.generate(
+ black_box("This is a long string. With many, many characters. For no particular reason.".to_owned()),
+ black_box("And another relatively long string for no reason other than it being long.".to_owned())
+ )
+ }));
+}
+
+fn criterion_bench_16bytes_full_divide(c: &mut Criterion) {
+ let pwm = Pwm::new(
+ HashAlgorithm::Md5,
+ passwordmaker_rs::UseLeetWhenGenerating::NotAtAll,
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()_-+={}|[]\\:\";'<>?,./",
+ "",
+ "",
+ 20,
+ "",
+ ""
+ ).unwrap();
+ c.bench_function("16 bytes full divide", |b| b.iter(|| {
+ pwm.generate(
+ black_box("This is a long string. With many, many characters. For no particular reason.".to_owned()),
+ black_box("And another relatively long string for no reason other than it being long.".to_owned())
+ )
+ }));
+}
+
+fn criterion_bench_16bytes_worst_case(c: &mut Criterion) {
+ let pwm = Pwm::new(
+ HashAlgorithm::Md5,
+ passwordmaker_rs::UseLeetWhenGenerating::NotAtAll,
+ "XY",
+ "",
+ "",
+ 128,
+ "",
+ ""
+ ).unwrap();
+ c.bench_function("16 bytes worst case", |b| b.iter(|| {
+ pwm.generate(
+ black_box("This is a long string. With many, many characters. For no particular reason.".to_owned()),
+ black_box("And another relatively long string for no reason other than it being long.".to_owned())
+ )
+ }));
+}
+
+criterion_group!(benches,
+ criterion_bench_16bytes_typical,
+ criterion_bench_16bytes_full_divide,
+ criterion_bench_16bytes_worst_case,
+);
+criterion_main!(benches);
diff --git a/benches/hashrate_20.rs b/benches/hashrate_20.rs
new file mode 100644
index 0000000..6168791
--- /dev/null
+++ b/benches/hashrate_20.rs
@@ -0,0 +1,69 @@
+mod mock_hashers;
+
+use criterion::{black_box, criterion_group, criterion_main, Criterion};
+use passwordmaker_rs::HashAlgorithm;
+use mock_hashers::Pwm;
+
+fn criterion_bench_20bytes_typical(c: &mut Criterion) {
+ let pwm = Pwm::new(
+ HashAlgorithm::Ripemd160,
+ passwordmaker_rs::UseLeetWhenGenerating::NotAtAll,
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()_-+={}|[]\\:\";'<>?,./",
+ "",
+ "",
+ 12,
+ "",
+ ""
+ ).unwrap();
+ c.bench_function("20 bytes typical", |b| b.iter(|| {
+ pwm.generate(
+ black_box("This is a long string. With many, many characters. For no particular reason.".to_owned()),
+ black_box("And another relatively long string for no reason other than it being long.".to_owned())
+ )
+ }));
+}
+
+fn criterion_bench_20bytes_full_divide(c: &mut Criterion) {
+ let pwm = Pwm::new(
+ HashAlgorithm::Ripemd160,
+ passwordmaker_rs::UseLeetWhenGenerating::NotAtAll,
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()_-+={}|[]\\:\";'<>?,./",
+ "",
+ "",
+ 25,
+ "",
+ ""
+ ).unwrap();
+ c.bench_function("20 bytes full divide", |b| b.iter(|| {
+ pwm.generate(
+ black_box("This is a long string. With many, many characters. For no particular reason.".to_owned()),
+ black_box("And another relatively long string for no reason other than it being long.".to_owned())
+ )
+ }));
+}
+
+fn criterion_bench_20bytes_worst_case(c: &mut Criterion) {
+ let pwm = Pwm::new(
+ HashAlgorithm::Md5,
+ passwordmaker_rs::UseLeetWhenGenerating::NotAtAll,
+ "XY",
+ "",
+ "",
+ 160,
+ "",
+ ""
+ ).unwrap();
+ c.bench_function("20 bytes worst case", |b| b.iter(|| {
+ pwm.generate(
+ black_box("This is a long string. With many, many characters. For no particular reason.".to_owned()),
+ black_box("And another relatively long string for no reason other than it being long.".to_owned())
+ )
+ }));
+}
+
+criterion_group!(benches,
+ criterion_bench_20bytes_typical,
+ criterion_bench_20bytes_full_divide,
+ criterion_bench_20bytes_worst_case,
+);
+criterion_main!(benches);
diff --git a/benches/hashrate_32.rs b/benches/hashrate_32.rs
new file mode 100644
index 0000000..7638add
--- /dev/null
+++ b/benches/hashrate_32.rs
@@ -0,0 +1,69 @@
+mod mock_hashers;
+
+use criterion::{black_box, criterion_group, criterion_main, Criterion};
+use passwordmaker_rs::HashAlgorithm;
+use mock_hashers::Pwm;
+
+fn criterion_bench_32bytes_typical(c: &mut Criterion) {
+ let pwm = Pwm::new(
+ HashAlgorithm::Sha256,
+ passwordmaker_rs::UseLeetWhenGenerating::NotAtAll,
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()_-+={}|[]\\:\";'<>?,./",
+ "",
+ "",
+ 12,
+ "",
+ ""
+ ).unwrap();
+ c.bench_function("32 bytes typical", |b| b.iter(|| {
+ pwm.generate(
+ black_box("This is a long string. With many, many characters. For no particular reason.".to_owned()),
+ black_box("And another relatively long string for no reason other than it being long.".to_owned())
+ )
+ }));
+}
+
+fn criterion_bench_32bytes_full_divide(c: &mut Criterion) {
+ let pwm = Pwm::new(
+ HashAlgorithm::Sha256,
+ passwordmaker_rs::UseLeetWhenGenerating::NotAtAll,
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()_-+={}|[]\\:\";'<>?,./",
+ "",
+ "",
+ 40,
+ "",
+ ""
+ ).unwrap();
+ c.bench_function("32 bytes full divide", |b| b.iter(|| {
+ pwm.generate(
+ black_box("This is a long string. With many, many characters. For no particular reason.".to_owned()),
+ black_box("And another relatively long string for no reason other than it being long.".to_owned())
+ )
+ }));
+}
+
+fn criterion_bench_32bytes_worst_case(c: &mut Criterion) {
+ let pwm = Pwm::new(
+ HashAlgorithm::Sha256,
+ passwordmaker_rs::UseLeetWhenGenerating::NotAtAll,
+ "XY",
+ "",
+ "",
+ 256,
+ "",
+ ""
+ ).unwrap();
+ c.bench_function("32 bytes worst case", |b| b.iter(|| {
+ pwm.generate(
+ black_box("This is a long string. With many, many characters. For no particular reason.".to_owned()),
+ black_box("And another relatively long string for no reason other than it being long.".to_owned())
+ )
+ }));
+}
+
+criterion_group!(benches,
+ criterion_bench_32bytes_typical,
+ criterion_bench_32bytes_full_divide,
+ criterion_bench_32bytes_worst_case,
+);
+criterion_main!(benches);
diff --git a/benches/leet.rs b/benches/leet.rs
new file mode 100644
index 0000000..ef3b649
--- /dev/null
+++ b/benches/leet.rs
@@ -0,0 +1,49 @@
+mod mock_hashers;
+
+use criterion::{black_box, criterion_group, criterion_main, Criterion};
+use passwordmaker_rs::{HashAlgorithm, LeetLevel};
+use mock_hashers::Pwm;
+
+fn criterion_bench_16bytes_post_leet(c: &mut Criterion) {
+ let pwm = Pwm::new(
+ HashAlgorithm::Md5,
+ passwordmaker_rs::UseLeetWhenGenerating::After { level: LeetLevel::Six },
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()_-+={}|[]\\:\";'<>?,./",
+ "",
+ "",
+ 150,
+ "",
+ ""
+ ).unwrap();
+ c.bench_function("16 bytes with post_leet", |b| b.iter(|| {
+ pwm.generate(
+ black_box("This is a long string. With many, many characters. For no particular reason.".to_owned()),
+ black_box("And another relatively long string for no reason other than it being long.".to_owned())
+ )
+ }));
+}
+
+fn criterion_bench_16bytes_pre_leet(c: &mut Criterion) {
+ let pwm = Pwm::new(
+ HashAlgorithm::Md5,
+ passwordmaker_rs::UseLeetWhenGenerating::Before { level: LeetLevel::Six },
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`~!@#$%^&*()_-+={}|[]\\:\";'<>?,./",
+ "",
+ "",
+ 150,
+ "",
+ ""
+ ).unwrap();
+ c.bench_function("16 bytes with pre_leet", |b| b.iter(|| {
+ pwm.generate(
+ black_box("This is a long string. With many, many characters. For no particular reason.".to_owned()),
+ black_box("And another relatively long string for no reason other than it being long.".to_owned())
+ )
+ }));
+}
+
+criterion_group!(benches,
+ criterion_bench_16bytes_post_leet,
+ criterion_bench_16bytes_pre_leet
+);
+criterion_main!(benches);
diff --git a/benches/mock_hashers/mod.rs b/benches/mock_hashers/mod.rs
new file mode 100644
index 0000000..29e91b9
--- /dev/null
+++ b/benches/mock_hashers/mod.rs
@@ -0,0 +1,59 @@
+//We want to bench the surrounding string manipulation, not the hashers.
+//For this reason, we fake them with a black_box.
+
+use passwordmaker_rs::{PasswordMaker, Hasher, HasherList, };
+use criterion::{black_box};
+
+
+pub(crate) struct MockMd4;
+pub(crate) struct MockMd5;
+pub(crate) struct MockSha1;
+pub(crate) struct MockSha256;
+pub(crate) struct MockRipeMD160;
+impl Hasher for MockMd4{
+ type Output = [u8;16];
+ fn hash(_data : &[u8]) -> Self::Output {
+ black_box([156u8,4u8,123u8,54u8,91u8,85u8,34u8,159u8,243u8,210u8,35u8,41u8,31u8,34u8,75u8,94u8])
+ }
+}
+impl Hasher for MockMd5{
+ type Output = [u8;16];
+ fn hash(_data : &[u8]) -> Self::Output {
+ black_box([156u8,4u8,123u8,54u8,91u8,85u8,34u8,159u8,243u8,210u8,35u8,41u8,31u8,34u8,75u8,94u8])
+ }
+}
+impl Hasher for MockSha1{
+ type Output = [u8;20];
+ fn hash(_data : &[u8]) -> Self::Output {
+ black_box([156u8,4u8,123u8,54u8,91u8,85u8,34u8,159u8,243u8,210u8,35u8,41u8,31u8,34u8,75u8,94u8,46,49,13,24])
+ }
+}
+impl Hasher for MockSha256{
+ type Output = [u8;32];
+ fn hash(_data : &[u8]) -> Self::Output {
+ black_box([156u8,4u8,123u8,54u8,91u8,85u8,34u8,159u8,243u8,210u8,35u8,41u8,31u8,34u8,75u8,94u8,156u8,4u8,123u8,54u8,91u8,85u8,34u8,159u8,243u8,210u8,35u8,41u8,31u8,34u8,75u8,94u8])
+ }
+}
+impl Hasher for MockRipeMD160{
+ type Output = [u8;20];
+ fn hash(_data : &[u8]) -> Self::Output {
+ black_box([156u8,4u8,123u8,54u8,91u8,85u8,34u8,159u8,243u8,210u8,35u8,41u8,31u8,34u8,75u8,94u8,46,49,13,24])
+ }
+}
+
+impl passwordmaker_rs::Md4 for MockMd4{}
+impl passwordmaker_rs::Md5 for MockMd5{}
+impl passwordmaker_rs::Sha1 for MockSha1{}
+impl passwordmaker_rs::Sha256 for MockSha256{}
+impl passwordmaker_rs::Ripemd160 for MockRipeMD160{}
+
+pub(crate) struct MockHashes{}
+impl HasherList for MockHashes {
+ type MD4 = MockMd4;
+ type MD5 = MockMd5;
+ type SHA1 = MockSha1;
+ type SHA256 = MockSha256;
+ type RIPEMD160 = MockRipeMD160;
+}
+
+pub(crate) type Pwm<'a> = PasswordMaker<'a, MockHashes>; \ No newline at end of file