# HG changeset patch # User Doug Simon # Date 1380552504 -7200 # Node ID 6ce3677f09f540d5e121c5a5669c0204cab08dd0 # Parent 0ffb6ed18ea4b82e385f916c99ed29c48dbdbc97 enhanced test for CipherBlockChaining substitutions to cover path where the substitutions call the original (i.e. substituted) methods on slow paths diff -r 0ffb6ed18ea4 -r 6ce3677f09f5 graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/HotSpotCryptoSubstitutionTest.java --- a/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/HotSpotCryptoSubstitutionTest.java Mon Sep 30 10:03:05 2013 +0200 +++ b/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/HotSpotCryptoSubstitutionTest.java Mon Sep 30 16:48:24 2013 +0200 @@ -60,30 +60,42 @@ } @Test - public void testAESEncryptSubstitution() throws Exception { + public void testEncryptSubstitution() throws Exception { byte[] seed = {0x4, 0x7, 0x1, 0x1}; SecureRandom random = new SecureRandom(seed); KeyGenerator aesKeyGen = KeyGenerator.getInstance("AES"); + KeyGenerator desKeyGen = KeyGenerator.getInstance("DESede"); aesKeyGen.init(128, random); + desKeyGen.init(168, random); SecretKey aesKey = aesKeyGen.generateKey(); + SecretKey desKey = desKeyGen.generateKey(); byte[] input = readClassfile16(getClass()); - ByteArrayOutputStream expected = new ByteArrayOutputStream(); - expected.write(runEncryptDecrypt(aesKey, "AES/CBC/NoPadding", input)); - expected.write(runEncryptDecrypt(aesKey, "AES/CBC/PKCS5Padding", input)); + ByteArrayOutputStream aesExpected = new ByteArrayOutputStream(); + aesExpected.write(runEncryptDecrypt(aesKey, "AES/CBC/NoPadding", input)); + aesExpected.write(runEncryptDecrypt(aesKey, "AES/CBC/PKCS5Padding", input)); if (compiledAndInstall("com.sun.crypto.provider.AESCrypt", "encryptBlock", "decryptBlock")) { ByteArrayOutputStream actual = new ByteArrayOutputStream(); actual.write(runEncryptDecrypt(aesKey, "AES/CBC/NoPadding", input)); actual.write(runEncryptDecrypt(aesKey, "AES/CBC/PKCS5Padding", input)); - Assert.assertArrayEquals(expected.toByteArray(), actual.toByteArray()); + Assert.assertArrayEquals(aesExpected.toByteArray(), actual.toByteArray()); } + ByteArrayOutputStream desExpected = new ByteArrayOutputStream(); + desExpected.write(runEncryptDecrypt(desKey, "DESede/CBC/NoPadding", input)); + desExpected.write(runEncryptDecrypt(desKey, "DESede/CBC/PKCS5Padding", input)); + if (compiledAndInstall("com.sun.crypto.provider.CipherBlockChaining", "encrypt", "decrypt")) { ByteArrayOutputStream actual = new ByteArrayOutputStream(); actual.write(runEncryptDecrypt(aesKey, "AES/CBC/NoPadding", input)); actual.write(runEncryptDecrypt(aesKey, "AES/CBC/PKCS5Padding", input)); - Assert.assertArrayEquals(expected.toByteArray(), actual.toByteArray()); + Assert.assertArrayEquals(aesExpected.toByteArray(), actual.toByteArray()); + + actual.reset(); + actual.write(runEncryptDecrypt(desKey, "DESede/CBC/NoPadding", input)); + actual.write(runEncryptDecrypt(desKey, "DESede/CBC/PKCS5Padding", input)); + Assert.assertArrayEquals(desExpected.toByteArray(), actual.toByteArray()); } }