diff -r c97db0855565 -r 758c07667682 test/compiler/7184394/TestAESBase.java --- a/test/compiler/7184394/TestAESBase.java Tue Feb 04 17:38:01 2020 +0800 +++ b/test/compiler/7184394/TestAESBase.java Tue Feb 04 18:13:14 2020 +0800 @@ -29,6 +29,7 @@ import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; +import javax.crypto.spec.GCMParameterSpec; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; import java.security.AlgorithmParameters; @@ -62,8 +63,12 @@ Random random = new Random(0); Cipher cipher; Cipher dCipher; - AlgorithmParameters algParams; + AlgorithmParameters algParams = null; SecretKey key; + GCMParameterSpec gcm_spec; + byte[] aad = { 0x11, 0x22, 0x33, 0x44, 0x55 }; + int tlen = 12; + byte[] iv = new byte[16]; static int numThreads = 0; int threadId; @@ -77,7 +82,10 @@ public void prepare() { try { - System.out.println("\nalgorithm=" + algorithm + ", mode=" + mode + ", paddingStr=" + paddingStr + ", msgSize=" + msgSize + ", keySize=" + keySize + ", noReinit=" + noReinit + ", checkOutput=" + checkOutput + ", encInputOffset=" + encInputOffset + ", encOutputOffset=" + encOutputOffset + ", decOutputOffset=" + decOutputOffset + ", lastChunkSize=" +lastChunkSize ); + System.out.println("\nalgorithm=" + algorithm + ", mode=" + mode + ", paddingStr=" + paddingStr + + ", msgSize=" + msgSize + ", keySize=" + keySize + ", noReinit=" + noReinit + + ", checkOutput=" + checkOutput + ", encInputOffset=" + encInputOffset + ", encOutputOffset=" + + encOutputOffset + ", decOutputOffset=" + decOutputOffset + ", lastChunkSize=" +lastChunkSize ); if (encInputOffset % ALIGN != 0 || encOutputOffset % ALIGN != 0 || decOutputOffset % ALIGN !=0 ) testingMisalignment = true; @@ -98,16 +106,24 @@ cipher = Cipher.getInstance(algorithm + "/" + mode + "/" + paddingStr, "SunJCE"); dCipher = Cipher.getInstance(algorithm + "/" + mode + "/" + paddingStr, "SunJCE"); + // CBC init if (mode.equals("CBC")) { - int ivLen = (algorithm.equals("AES") ? 16 : algorithm.equals("DES") ? 8 : 0); - IvParameterSpec initVector = new IvParameterSpec(new byte[ivLen]); + IvParameterSpec initVector = new IvParameterSpec(iv); cipher.init(Cipher.ENCRYPT_MODE, key, initVector); + algParams = cipher.getParameters(); + dCipher.init(Cipher.DECRYPT_MODE, key, initVector); + + // GCM init + } else if (mode.equals("GCM")) { + gcm_init(true); + gcm_init(false); + + // ECB init } else { - algParams = cipher.getParameters(); cipher.init(Cipher.ENCRYPT_MODE, key, algParams); + dCipher.init(Cipher.DECRYPT_MODE, key, algParams); } - algParams = cipher.getParameters(); - dCipher.init(Cipher.DECRYPT_MODE, key, algParams); + if (threadId == 0) { childShowCipher(); } @@ -188,4 +204,19 @@ } abstract void childShowCipher(); + + void gcm_init(boolean encrypt) throws Exception { + gcm_spec = new GCMParameterSpec(tlen * 8, iv); + if (encrypt) { + // Get a new instance everytime because of reuse IV restrictions + cipher = Cipher.getInstance(algorithm + "/" + mode + "/" + paddingStr, "SunJCE"); + cipher.init(Cipher.ENCRYPT_MODE, key, gcm_spec); + cipher.updateAAD(aad); + } else { + dCipher.init(Cipher.DECRYPT_MODE, key, gcm_spec); + dCipher.updateAAD(aad); + + + } + } }