1 module dcrypt.benchmark.curved25519;
2 
3 import dcrypt.benchmark.Benchmark;
4 import dcrypt.crypto.ecc.curve25519;
5 import dcrypt.crypto.ecc.ed25519;
6 import std.conv;
7 
8 public class Curved25519Benchmark: Benchmark {
9 
10 	this (){
11 	}
12 	
13 	@property
14 	static string[] header() {
15 		return ["curved25519", "scalar mult/s"];
16 	}
17 	
18 	override string[] benchmark(ulong length) {
19 		StopWatch sw;
20 
21 		ubyte[32] secretKey;
22 		secretKey[] = 0x55;
23 		
24 		sw.start();
25 		foreach(size_t i; 0 .. length) {
26 			secretKey = curve25519_scalarmult(secretKey);
27 		}
28 		sw.stop();
29 		
30 		
31 		ulong speed = cast(ulong) (1e9 * length / sw.peek().nsecs());
32 		return ["", text(speed)];
33 	}
34 	
35 }
36 
37 public class Ed25519Benchmark: Benchmark {
38 	
39 	this (){
40 	}
41 	
42 	@property
43 	static string[] header() {
44 		return ["ed25519", "sign/s", "verify/s"];
45 	}
46 	
47 	override string[] benchmark(ulong length) {
48 		StopWatch sw;
49 		
50 		ubyte[32] secretKey;
51 		ubyte[32] msg;
52 		secretKey[] = 0x55;
53 
54 		ubyte[64] buf;
55 		immutable ubyte[32] pk = secret_to_public(secretKey);
56 
57 		// signature
58 		sw.start();
59 		foreach(size_t i; 0 .. length) {
60 			buf = sign(buf, secretKey, pk);
61 		}
62 		sw.stop();
63 		ulong speedSign = cast(ulong) (1e9 * length / sw.peek().nsecs());
64 
65 		// verification
66 		sw.start();
67 		foreach(size_t i; 0 .. length) {
68 			bool v = verify(buf, msg, pk);
69 		}
70 		sw.stop();
71 		ulong speedVerify = cast(ulong) (1e9 * length / sw.peek().nsecs());
72 
73 
74 		return ["", text(speedSign), text(speedVerify)];
75 	}
76 	
77 }