summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenny Root <kroot@google.com>2016-02-25 23:17:43 -0800
committerThe Android Automerger <android-build@google.com>2016-03-25 17:48:02 -0700
commite565176fedcadcb6d1256a106bdb93d206d62043 (patch)
tree7ee34efd2fbd7b6b409293c0ffa4fabd323df2ad
parent156bf0a0237c98bfca6826ac9030b1444c391a50 (diff)
downloadlibcore-e565176fedcadcb6d1256a106bdb93d206d62043.zip
libcore-e565176fedcadcb6d1256a106bdb93d206d62043.tar.gz
libcore-e565176fedcadcb6d1256a106bdb93d206d62043.tar.bz2
CipherTest: add test for multiple updateAAD calls
Make sure that multiple updateAAD calls are equivalent to other calls to updateAAD with the same data. (cherry picked from commit 67ee3c5c2dad218e497035de5100e9036d140fdd) Bug: 27371173 Change-Id: Ie69df0906438ad26c566daed3f55b07ba60fe468
-rw-r--r--luni/src/test/java/libcore/javax/crypto/CipherTest.java27
1 files changed, 27 insertions, 0 deletions
diff --git a/luni/src/test/java/libcore/javax/crypto/CipherTest.java b/luni/src/test/java/libcore/javax/crypto/CipherTest.java
index 7cd6133..0f642cf 100644
--- a/luni/src/test/java/libcore/javax/crypto/CipherTest.java
+++ b/luni/src/test/java/libcore/javax/crypto/CipherTest.java
@@ -3539,6 +3539,33 @@ public final class CipherTest extends TestCase {
}
/*
+ * Check that two AAD updates are equivalent to one.
+ * http://b/27371173
+ */
+ public void test_AESGCMNoPadding_UpdateAADTwice_Success() throws Exception {
+ SecretKeySpec key = new SecretKeySpec(new byte[16], "AES");
+ GCMParameterSpec spec = new GCMParameterSpec(128, new byte[12]);
+ Cipher c1 = Cipher.getInstance("AES/GCM/NoPadding");
+ Cipher c2 = Cipher.getInstance("AES/GCM/NoPadding");
+
+ c1.init(Cipher.ENCRYPT_MODE, key, spec);
+ c1.updateAAD(new byte[] {
+ 0x01, 0x02, 0x03, 0x04, 0x05,
+ });
+ c1.updateAAD(new byte[] {
+ 0x06, 0x07, 0x08, 0x09, 0x10,
+ });
+
+ c2.init(Cipher.ENCRYPT_MODE, key, spec);
+ c2.updateAAD(new byte[] {
+ 0x01, 0x02, 0x03, 0x04, 0x05,
+ 0x06, 0x07, 0x08, 0x09, 0x10,
+ });
+
+ assertEquals(Arrays.toString(c1.doFinal()), Arrays.toString(c2.doFinal()));
+ }
+
+ /*
* Check that GCM encryption with old and new instances update correctly.
* http://b/26694388
*/