summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--luni/src/main/java/javax/crypto/Cipher.java5
-rw-r--r--luni/src/test/java/libcore/javax/crypto/CipherTest.java11
2 files changed, 13 insertions, 3 deletions
diff --git a/luni/src/main/java/javax/crypto/Cipher.java b/luni/src/main/java/javax/crypto/Cipher.java
index 2e3b341..889ac9f 100644
--- a/luni/src/main/java/javax/crypto/Cipher.java
+++ b/luni/src/main/java/javax/crypto/Cipher.java
@@ -1005,8 +1005,7 @@ public class Cipher {
* the offset in the input to start.
* @param inputLen
* the length of the input to transform.
- * @return the transformed bytes in a new buffer, or {@code null} if the
- * input has zero length.
+ * @return the transformed bytes in a new buffer, or {@code null} if {@code inputLen} is zero.
* @throws IllegalStateException
* if this cipher instance is not initialized for encryption or
* decryption.
@@ -1023,7 +1022,7 @@ public class Cipher {
throw new IllegalArgumentException("input == null");
}
checkInputOffsetAndCount(input.length, inputOffset, inputLen);
- if (input.length == 0) {
+ if (inputLen == 0) {
return null;
}
return getSpi().engineUpdate(input, inputOffset, inputLen);
diff --git a/luni/src/test/java/libcore/javax/crypto/CipherTest.java b/luni/src/test/java/libcore/javax/crypto/CipherTest.java
index c89886c..29112fb 100644
--- a/luni/src/test/java/libcore/javax/crypto/CipherTest.java
+++ b/luni/src/test/java/libcore/javax/crypto/CipherTest.java
@@ -2797,6 +2797,17 @@ public final class CipherTest extends TestCase {
}
}
+ public void testCipher_Update_WithZeroLengthInput_ReturnsNull() throws Exception {
+ SecretKey key = new SecretKeySpec(AES_128_KEY, "AES");
+ Cipher c = Cipher.getInstance("AES/ECB/NoPadding");
+ c.init(Cipher.ENCRYPT_MODE, key);
+ assertNull(c.update(new byte[0]));
+ assertNull(c.update(new byte[c.getBlockSize() * 2], 0, 0));
+
+ // Try with non-zero offset just in case the implementation mixes up offset and inputLen
+ assertNull(c.update(new byte[c.getBlockSize() * 2], 16, 0));
+ }
+
private void checkCipher_ShortBlock_Failure(CipherTestParam p, String provider) throws Exception {
SecretKey key = new SecretKeySpec(p.key, "AES");
Cipher c = Cipher.getInstance(