From f85158ce074f894d25cfeb3e0325ecf5de5cb384 Mon Sep 17 00:00:00 2001 From: Pete Bentley Date: Thu, 13 Aug 2020 12:15:56 +0100 Subject: [PATCH] Add a boolean to OpenSSLAeadCipher to control optimisations. Controls whether the no-copy optimisations for direct ByteBuffers are enabled. If false, then the inherited default behaciour from CipherSpi is used. --- common/src/main/java/org/conscrypt/OpenSSLAeadCipher.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/common/src/main/java/org/conscrypt/OpenSSLAeadCipher.java b/common/src/main/java/org/conscrypt/OpenSSLAeadCipher.java index f2a8cf6b2..3efbbac80 100644 --- a/common/src/main/java/org/conscrypt/OpenSSLAeadCipher.java +++ b/common/src/main/java/org/conscrypt/OpenSSLAeadCipher.java @@ -32,6 +32,11 @@ @Internal public abstract class OpenSSLAeadCipher extends OpenSSLCipher { + /** + * Controls whether no-copy optimizations for direct ByteBuffers are enabled. + */ + private static final boolean ENABLE_BYTEBUFFER_OPTIMIZATIONS = true; + /** * The default tag size when one is not specified. Default to * full-length tags (128-bits or 16 octets). @@ -223,6 +228,9 @@ boolean allowsNonceReuse() { @Override protected int engineDoFinal(ByteBuffer input, ByteBuffer output) throws ShortBufferException, IllegalBlockSizeException, BadPaddingException { + if (!ENABLE_BYTEBUFFER_OPTIMIZATIONS) { + return super.engineDoFinal(input, output); + } if (input == null || output == null) { throw new NullPointerException("Null ByteBuffer Error"); }