• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package benchmarks.regression;
18 
19 import com.google.caliper.BeforeExperiment;
20 import com.google.caliper.Param;
21 import java.security.KeyPair;
22 import java.security.KeyPairGenerator;
23 import java.security.SecureRandom;
24 
25 public class KeyPairGeneratorBenchmark {
26     @Param private Algorithm algorithm;
27 
28     public enum Algorithm {
29         RSA,
30         DSA,
31     };
32 
33     @Param private Implementation implementation;
34 
35     public enum Implementation { OpenSSL, BouncyCastle };
36 
37     private String generatorAlgorithm;
38     private KeyPairGenerator generator;
39     private SecureRandom random;
40 
41     @BeforeExperiment
setUp()42     protected void setUp() throws Exception {
43         this.generatorAlgorithm = algorithm.toString();
44 
45         final String provider;
46         if (implementation == Implementation.BouncyCastle) {
47             provider = "BC";
48         } else {
49             provider = "AndroidOpenSSL";
50         }
51 
52         this.generator = KeyPairGenerator.getInstance(generatorAlgorithm, provider);
53         this.random = SecureRandom.getInstance("SHA1PRNG");
54         this.generator.initialize(1024);
55     }
56 
time(int reps)57     public void time(int reps) throws Exception {
58         for (int i = 0; i < reps; ++i) {
59             KeyPair keyPair = generator.generateKeyPair();
60         }
61     }
62 }
63