diff options
author | Jessica Wagantall <jwagantall@cyngn.com> | 2016-05-03 11:38:52 -0700 |
---|---|---|
committer | Jessica Wagantall <jwagantall@cyngn.com> | 2016-05-03 11:59:57 -0700 |
commit | 7e191c4204235e56c0a9b129f81b58b56b70e3a0 (patch) | |
tree | b1d561d6f86f620d86979601d16249a71bb23470 | |
parent | 3a5c4a7f6a52c6e6f71616940920cb647aafff2b (diff) | |
parent | e565176fedcadcb6d1256a106bdb93d206d62043 (diff) | |
download | libcore-7e191c4204235e56c0a9b129f81b58b56b70e3a0.zip libcore-7e191c4204235e56c0a9b129f81b58b56b70e3a0.tar.gz libcore-7e191c4204235e56c0a9b129f81b58b56b70e3a0.tar.bz2 |
Merge tag 'android-6.0.1_r43' into HEAD
Ticket: CYNGNOS-2373
Android 6.0.1 release 43 (MOB30J)
Change-Id: Ib43d0956f24c0d3c4ce16ab3144f88c21c7feac2
-rw-r--r-- | luni/src/test/java/libcore/javax/crypto/CipherTest.java | 68 |
1 files changed, 68 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 38d6d8d..0f642cf 100644 --- a/luni/src/test/java/libcore/javax/crypto/CipherTest.java +++ b/luni/src/test/java/libcore/javax/crypto/CipherTest.java @@ -3537,4 +3537,72 @@ public final class CipherTest extends TestCase { cipher.init(Cipher.ENCRYPT_MODE, keyGen.generateKeyPair().getPublic()); cipher.doFinal(new byte[] {1,2,3,4}); } + + /* + * 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 + */ + public void test_AESGCMNoPadding_Reuse_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"); + + // Pollute the c1 cipher with AAD + c1.init(Cipher.ENCRYPT_MODE, key, spec); + c1.updateAAD(new byte[] { + 0x01, 0x02, 0x03, 0x04, 0x05, + }); + + // Now init each again and make sure the outputs are the same + c1.init(Cipher.ENCRYPT_MODE, key, spec); + c2.init(Cipher.ENCRYPT_MODE, key, spec); + + byte[] aad = new byte[] { + 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, + }; + c1.updateAAD(aad); + c2.updateAAD(aad); + + assertEquals(Arrays.toString(c1.doFinal()), Arrays.toString(c2.doFinal())); + + // .doFinal should also reset the state, so check that as well. + byte[] aad2 = new byte[] { + 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, + }; + + Cipher c3 = Cipher.getInstance("AES/GCM/NoPadding"); + c3.init(Cipher.ENCRYPT_MODE, key, spec); + + c1.updateAAD(aad2); + c3.updateAAD(aad2); + assertEquals(Arrays.toString(c1.doFinal()), Arrays.toString(c3.doFinal())); + } } |