* started reducing the temporary buffers created within various crypto methods , as we've

got some pretty heavy GC churn when under load.  rough estimate is we allocate 5-8x as
much data as we need, copying it all over the place before forwarding it (or processing it).
this should cut down a few of those copies, but not enough yet.  it'd be great to get that
down to 2x.
* lots of logging
This commit is contained in:
jrandom
2004-09-28 20:33:23 +00:00
committed by zzz
parent ff1dfd8f25
commit 774231f347
20 changed files with 254 additions and 184 deletions

View File

@ -72,22 +72,28 @@ public class AES256Bench {
iv[x] = (byte)civ[x];
}
byte[] e = _context.AESEngine().encrypt(plain, key, iv);
byte[] d = _context.AESEngine().decrypt(e, key, iv);
byte[] e = new byte[plain.length];
_context.aes().encrypt(plain, 0, e, 0, key, iv, plain.length);
byte[] d = new byte[e.length];
_context.aes().decrypt(e, 0, d, 0, key, iv, d.length);
boolean same = true;
for (int x = 0; x < d.length; x++) {
if (plain[x] != d[x]) {
same = false;
throw new RuntimeException("Failed decrypt at " + x);
}
}
System.out.println("Standard test D(E(value)) == value? " + same);
if (!same) throw new RuntimeException("moo");
plain = "1234567890123456".getBytes();
e = _context.AESEngine().encrypt(plain, key, iv);
d = _context.AESEngine().decrypt(e, key, iv);
e = new byte[plain.length];
_context.aes().encrypt(plain, 0, e, 0, key, iv, plain.length);
d = new byte[e.length];
_context.aes().decrypt(e, 0, d, 0, key, iv, d.length);
same = DataHelper.eq(plain, d);
System.out.println("Different value test D(E(value)) == value? " + same);
if (!same) throw new RuntimeException("moo");
System.out.println();
System.out.println();
@ -104,9 +110,11 @@ public class AES256Bench {
message[i] = (byte)((i%26)+'a');
for (int x = 0; x < times; x++) {
long startencrypt = System.currentTimeMillis();
e = _context.AESEngine().encrypt(message, key, iv);
e = new byte[message.length];
d = new byte[e.length];
_context.aes().encrypt(message, 0, e, 0, key, iv, message.length);
long endencryptstartdecrypt = System.currentTimeMillis();
d = _context.AESEngine().decrypt(e, key, iv);
_context.aes().decrypt(e, 0, d, 0, key, iv, d.length);
long enddecrypt = System.currentTimeMillis();
System.out.print(".");
encrypttime += endencryptstartdecrypt - startencrypt;

View File

@ -145,8 +145,10 @@ class ElGamalAESEngineTest {
String msg = "Hello world01234012345678901234501234567890123450123456789012345";
h = SHA256Generator.getInstance().calculateHash(msg.getBytes());
_log.debug("Hash of entire aes block before encryption: \n" + DataHelper.toString(h.getData(), 32));
byte aesEncr[] = _context.AESEngine().encrypt(msg.getBytes(), sessionKey, iv);
byte aesDecr[] = _context.AESEngine().decrypt(aesEncr, sessionKey, iv);
byte aesEncr[] = new byte[msg.getBytes().length];
byte aesDecr[] = new byte[aesEncr.length];
_context.aes().encrypt(msg.getBytes(), 0, aesEncr, 0, sessionKey, iv, aesEncr.length);
_context.aes().decrypt(aesEncr, 0, aesDecr, 0, sessionKey, iv, aesEncr.length);
h = SHA256Generator.getInstance().calculateHash(aesDecr);
_log.debug("Hash of entire aes block after decryption: \n" + DataHelper.toString(h.getData(), 32));
if (msg.equals(new String(aesDecr))) {