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