diff options
author | Andreas Grois <andi@grois.info> | 2022-10-20 21:42:07 +0200 |
---|---|---|
committer | Andreas Grois <andi@grois.info> | 2022-10-20 21:42:07 +0200 |
commit | ea6789e5b33540270f5de3edb54264e6892fad73 (patch) | |
tree | 886f78169e328bc172dfdb79d171f2f20b7bc8e6 /benches/mock_hashers | |
parent | bc9bd89c17dc41d9b1434866ac2d522070f46597 (diff) |
Group Benchmarks, and make parameters more sane.
The previous parameters for benchmarks were based on gut-feeling.
Now each hash-length has 3 benchmarks:
- Typical is a typical user input
- Max Divisions is a full generate_password_part run
- Worst Case is the worst user input possible: Base 2.
Diffstat (limited to 'benches/mock_hashers')
-rw-r--r-- | benches/mock_hashers/mod.rs | 59 |
1 files changed, 59 insertions, 0 deletions
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 |