aboutsummaryrefslogtreecommitdiff
path: root/benches/hashrate.rs
blob: 9691410d9280a7ef2b801735fd2895d65544b5cf (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
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);