diff --git a/core/src/main/java/org/bouncycastle/crypto/io/CipherInputStream.java b/core/src/main/java/org/bouncycastle/crypto/io/CipherInputStream.java index 93b04e9934..66772df593 100644 --- a/core/src/main/java/org/bouncycastle/crypto/io/CipherInputStream.java +++ b/core/src/main/java/org/bouncycastle/crypto/io/CipherInputStream.java @@ -46,7 +46,9 @@ public CipherInputStream( this.bufferedBlockCipher = cipher; - buf = new byte[cipher.getOutputSize(INPUT_BUF_SIZE)]; + int outSize = cipher.getOutputSize(INPUT_BUF_SIZE); + + buf = new byte[(outSize > INPUT_BUF_SIZE) ? outSize : INPUT_BUF_SIZE]; inBuf = new byte[INPUT_BUF_SIZE]; } @@ -71,7 +73,9 @@ public CipherInputStream(InputStream is, AEADBlockCipher cipher) this.aeadBlockCipher = cipher; - buf = new byte[cipher.getOutputSize(INPUT_BUF_SIZE)]; + int outSize = cipher.getOutputSize(INPUT_BUF_SIZE); + + buf = new byte[(outSize > INPUT_BUF_SIZE) ? outSize : INPUT_BUF_SIZE]; inBuf = new byte[INPUT_BUF_SIZE]; }