01: package org.bouncycastle.math.ec.test;
02:
03: import java.math.BigInteger;
04: import java.security.SecureRandom;
05:
06: import junit.framework.TestCase;
07:
08: import org.bouncycastle.asn1.sec.SECNamedCurves;
09: import org.bouncycastle.asn1.x9.X9ECParameters;
10: import org.bouncycastle.math.ec.ECPoint;
11:
12: /**
13: * Compares the performance of the the window NAF point multiplication against
14: * conventional point multiplication.
15: */
16: public class ECPointPerformanceTest extends TestCase {
17: public static final int NUM_ROUNDS = 100;
18:
19: private void randMult(final String curveName) throws Exception {
20: final X9ECParameters spec = SECNamedCurves.getByName(curveName);
21:
22: final BigInteger n = spec.getN();
23: final ECPoint g = (ECPoint) spec.getG();
24: final SecureRandom random = SecureRandom.getInstance(
25: "SHA1PRNG", "SUN");
26: final BigInteger k = new BigInteger(n.bitLength() - 1, random);
27:
28: ECPoint qMultiply = null;
29: long startTime = System.currentTimeMillis();
30: for (int i = 0; i < NUM_ROUNDS; i++) {
31: qMultiply = g.multiply(k);
32: }
33: long endTime = System.currentTimeMillis();
34:
35: double avgDuration = (double) (endTime - startTime)
36: / NUM_ROUNDS;
37: System.out.println(curveName);
38: System.out.print("Millis : ");
39: System.out.println(avgDuration);
40: System.out.println();
41: }
42:
43: public void testMultiply() throws Exception {
44: randMult("sect163r2");
45: randMult("sect233r1");
46: randMult("sect283r1");
47: randMult("sect409r1");
48: randMult("sect571r1");
49: randMult("secp224r1");
50: randMult("secp256r1");
51: randMult("secp521r1");
52: }
53:
54: // public static void main(String argv[]) throws Exception
55: // {
56: // ECMultiplyPerformanceTest test = new ECMultiplyPerformanceTest();
57: // test.testMultiply();
58: // }
59: }
|