- Timestamp:
- Aug 20, 2017 9:13:57 PM (3 years ago)
- Branches:
- master
- Children:
- a06c3fe
- Parents:
- f9b8a5ec
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
core/java/src/net/i2p/crypto/ElGamalEngine.java
rf9b8a5ec r6615586 251 251 return null; 252 252 } 253 254 /****255 public static void main(String args[]) {256 long eTime = 0;257 long dTime = 0;258 long gTime = 0;259 int numRuns = 100;260 if (args.length > 0) try {261 numRuns = Integer.parseInt(args[0]);262 } catch (NumberFormatException nfe) { // nop263 }264 265 try {266 Thread.sleep(30 * 1000);267 } catch (InterruptedException ie) { // nop268 }269 270 RandomSource.getInstance().nextBoolean();271 I2PAppContext context = new I2PAppContext();272 273 System.out.println("Running " + numRuns + " times");274 275 for (int i = 0; i < numRuns; i++) {276 long startG = Clock.getInstance().now();277 Object pair[] = KeyGenerator.getInstance().generatePKIKeypair();278 long endG = Clock.getInstance().now();279 280 PublicKey pubkey = (PublicKey) pair[0];281 PrivateKey privkey = (PrivateKey) pair[1];282 byte buf[] = new byte[128];283 RandomSource.getInstance().nextBytes(buf);284 long startE = Clock.getInstance().now();285 byte encr[] = context.elGamalEngine().encrypt(buf, pubkey);286 long endE = Clock.getInstance().now();287 byte decr[] = context.elGamalEngine().decrypt(encr, privkey);288 long endD = Clock.getInstance().now();289 eTime += endE - startE;290 dTime += endD - endE;291 gTime += endG - startG;292 293 if (!DataHelper.eq(decr, buf)) {294 System.out.println("PublicKey : " + DataHelper.toString(pubkey.getData(), pubkey.getData().length));295 System.out.println("PrivateKey : " + DataHelper.toString(privkey.getData(), privkey.getData().length));296 System.out.println("orig : " + DataHelper.toString(buf, buf.length));297 System.out.println("d(e(orig) : " + DataHelper.toString(decr, decr.length));298 System.out.println("orig.len : " + buf.length);299 System.out.println("d(e(orig).len : " + decr.length);300 System.out.println("Not equal!");301 System.exit(0);302 } else {303 System.out.println("*Run " + i + " is successful, with encr.length = " + encr.length + " [E: "304 + (endE - startE) + " D: " + (endD - endE) + " G: " + (endG - startG) + "]\n");305 }306 }307 System.out.println("\n\nAll " + numRuns + " tests successful, average encryption time: " + (eTime / numRuns)308 + " average decryption time: " + (dTime / numRuns) + " average key generation time: "309 + (gTime / numRuns));310 }311 ****/312 253 }
Note: See TracChangeset
for help on using the changeset viewer.