forked from I2P_Developers/i2p.i2p
Add benchmarks for ElGamal
This commit is contained in:
@@ -250,63 +250,4 @@ public final class ElGamalEngine {
|
||||
+ Base64.encode(rv), new Exception("Doesn't match"));
|
||||
return null;
|
||||
}
|
||||
|
||||
/****
|
||||
public static void main(String args[]) {
|
||||
long eTime = 0;
|
||||
long dTime = 0;
|
||||
long gTime = 0;
|
||||
int numRuns = 100;
|
||||
if (args.length > 0) try {
|
||||
numRuns = Integer.parseInt(args[0]);
|
||||
} catch (NumberFormatException nfe) { // nop
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(30 * 1000);
|
||||
} catch (InterruptedException ie) { // nop
|
||||
}
|
||||
|
||||
RandomSource.getInstance().nextBoolean();
|
||||
I2PAppContext context = new I2PAppContext();
|
||||
|
||||
System.out.println("Running " + numRuns + " times");
|
||||
|
||||
for (int i = 0; i < numRuns; i++) {
|
||||
long startG = Clock.getInstance().now();
|
||||
Object pair[] = KeyGenerator.getInstance().generatePKIKeypair();
|
||||
long endG = Clock.getInstance().now();
|
||||
|
||||
PublicKey pubkey = (PublicKey) pair[0];
|
||||
PrivateKey privkey = (PrivateKey) pair[1];
|
||||
byte buf[] = new byte[128];
|
||||
RandomSource.getInstance().nextBytes(buf);
|
||||
long startE = Clock.getInstance().now();
|
||||
byte encr[] = context.elGamalEngine().encrypt(buf, pubkey);
|
||||
long endE = Clock.getInstance().now();
|
||||
byte decr[] = context.elGamalEngine().decrypt(encr, privkey);
|
||||
long endD = Clock.getInstance().now();
|
||||
eTime += endE - startE;
|
||||
dTime += endD - endE;
|
||||
gTime += endG - startG;
|
||||
|
||||
if (!DataHelper.eq(decr, buf)) {
|
||||
System.out.println("PublicKey : " + DataHelper.toString(pubkey.getData(), pubkey.getData().length));
|
||||
System.out.println("PrivateKey : " + DataHelper.toString(privkey.getData(), privkey.getData().length));
|
||||
System.out.println("orig : " + DataHelper.toString(buf, buf.length));
|
||||
System.out.println("d(e(orig) : " + DataHelper.toString(decr, decr.length));
|
||||
System.out.println("orig.len : " + buf.length);
|
||||
System.out.println("d(e(orig).len : " + decr.length);
|
||||
System.out.println("Not equal!");
|
||||
System.exit(0);
|
||||
} else {
|
||||
System.out.println("*Run " + i + " is successful, with encr.length = " + encr.length + " [E: "
|
||||
+ (endE - startE) + " D: " + (endD - endE) + " G: " + (endG - startG) + "]\n");
|
||||
}
|
||||
}
|
||||
System.out.println("\n\nAll " + numRuns + " tests successful, average encryption time: " + (eTime / numRuns)
|
||||
+ " average decryption time: " + (dTime / numRuns) + " average key generation time: "
|
||||
+ (gTime / numRuns));
|
||||
}
|
||||
****/
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user