1
use criterion::{criterion_group, criterion_main, Criterion};
2
use custodian_password::{
3
	Ake, Argon2Algorithm, Argon2Params, ClientConfig, ClientLogin, ClientRegistration, Config,
4
	Group, Hash, Mhf, Result, ServerConfig, ServerLogin, ServerRegistration,
5
};
6
#[cfg(feature = "pbkdf2")]
7
use custodian_password::{Pbkdf2Hash, Pbkdf2Params};
8

            
9
72
fn cipher_suite(ake: Ake, group: Group, hash: Hash, mhf_hash: Mhf) -> Result<()> {
10
72
	const PASSWORD: &[u8] = b"password";
11
72

            
12
72
	let config = Config::new(ake, group, hash, mhf_hash);
13
72
	let server_config = ServerConfig::new(config);
14
72
	let client_config = ClientConfig::new(config, None)?;
15

            
16
72
	let (client, request) = ClientRegistration::register(client_config, PASSWORD)?;
17
72
	let (server, response) = ServerRegistration::register(&server_config, request)?;
18
72
	let (client_file, finalization, _) = client.finish(response)?;
19
72
	let server_file = server.finish(finalization)?;
20

            
21
72
	let (client, request) = ClientLogin::login(client_config, Some(client_file), PASSWORD)?;
22
72
	let (server, response) = ServerLogin::login(&server_config, Some(server_file), request)?;
23
72
	let (_, finalization, _) = client.finish(response)?;
24
72
	server.finish(finalization)
25
72
}
26

            
27
1
fn cipher_suites(criterion: &mut Criterion) {
28
1
	let argon2id =
29
1
		Mhf::Argon2(Argon2Params::new(Argon2Algorithm::Argon2id, None, None, None).unwrap());
30
1
	let argon2d =
31
1
		Mhf::Argon2(Argon2Params::new(Argon2Algorithm::Argon2d, None, None, None).unwrap());
32
1
	#[cfg(feature = "pbkdf2")]
33
1
	let pbkdf2sha256 = Mhf::Pbkdf2(Pbkdf2Params::new(Pbkdf2Hash::Sha256, None).unwrap());
34
1
	#[cfg(feature = "pbkdf2")]
35
1
	let pbkdf2sha512 = Mhf::Pbkdf2(Pbkdf2Params::new(Pbkdf2Hash::Sha512, None).unwrap());
36
1

            
37
1
	let akes = [
38
1
		Ake::Ristretto255,
39
1
		Ake::X25519,
40
1
		#[cfg(feature = "p256")]
41
1
		Ake::P256,
42
1
	];
43
1

            
44
1
	let groups = [
45
1
		Group::Ristretto255,
46
1
		#[cfg(feature = "p256")]
47
1
		Group::P256,
48
1
	];
49
1

            
50
1
	let hashs = [
51
1
		Hash::Sha2,
52
1
		#[cfg(feature = "sha3")]
53
1
		Hash::Sha3,
54
1
		#[cfg(feature = "blake3")]
55
1
		Hash::Blake3,
56
1
	];
57
1

            
58
1
	let mhfs = [
59
1
		argon2id,
60
1
		argon2d,
61
1
		#[cfg(feature = "pbkdf2")]
62
1
		pbkdf2sha256,
63
1
		#[cfg(feature = "pbkdf2")]
64
1
		pbkdf2sha512,
65
1
	];
66

            
67
4
	for ake in akes {
68
9
		for group in groups {
69
24
			for hash in hashs {
70
90
				for mhf in mhfs {
71
72
					criterion.bench_function(
72
72
						&format!("{:?} + {:?} + {:?} + {:?}", ake, group, hash, mhf),
73
72
						|bencher| bencher.iter(|| cipher_suite(ake, group, hash, mhf).unwrap()),
74
72
					);
75
72
				}
76
			}
77
		}
78
	}
79
1
}
80

            
81
criterion_group!(benches, cipher_suites);
82
criterion_main!(benches);