Make AES crypto operations use one buffer

All AES implementations being used are 'copy safe', where the source and
destination arrays may be the same. Lets save ourself a copy and reap
the performance wins!
This commit is contained in:
Joe Hirschfeld
2019-10-19 19:20:18 -07:00
parent bd35c6835e
commit a16684564b
6 changed files with 29 additions and 82 deletions

View File

@@ -56,20 +56,18 @@ class VelocityCipherTest {
VelocityCipher encrypt = factory.forEncryption(new SecretKeySpec(AES_KEY, "AES"));
ByteBuf source = bufSupplier.get();
ByteBuf dest = bufSupplier.get();
ByteBuf decryptionBuf = bufSupplier.get();
source.writeBytes(TEST_DATA);
ByteBuf workingBuf = source.copy();
try {
encrypt.process(source, dest);
decrypt.process(dest, decryptionBuf);
source.readerIndex(0);
assertTrue(ByteBufUtil.equals(source, decryptionBuf));
encrypt.process(workingBuf);
decrypt.process(workingBuf);
assertTrue(ByteBufUtil.equals(source, workingBuf));
} finally {
source.release();
dest.release();
decryptionBuf.release();
workingBuf.release();
decrypt.dispose();
encrypt.dispose();
}