1.1 --- a/test/compiler/7184394/TestAESBase.java Wed Jun 17 17:48:25 2015 -0700 1.2 +++ b/test/compiler/7184394/TestAESBase.java Fri Jul 10 11:31:49 2015 -0700 1.3 @@ -63,12 +63,12 @@ 1.4 Random random = new Random(0); 1.5 Cipher cipher; 1.6 Cipher dCipher; 1.7 - AlgorithmParameters algParams; 1.8 + AlgorithmParameters algParams = null; 1.9 SecretKey key; 1.10 GCMParameterSpec gcm_spec; 1.11 - byte[] aad; 1.12 + byte[] aad = { 0x11, 0x22, 0x33, 0x44, 0x55 }; 1.13 int tlen = 12; 1.14 - byte[] iv; 1.15 + byte[] iv = new byte[16]; 1.16 1.17 static int numThreads = 0; 1.18 int threadId; 1.19 @@ -82,7 +82,10 @@ 1.20 1.21 public void prepare() { 1.22 try { 1.23 - 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 ); 1.24 + System.out.println("\nalgorithm=" + algorithm + ", mode=" + mode + ", paddingStr=" + paddingStr + 1.25 + ", msgSize=" + msgSize + ", keySize=" + keySize + ", noReinit=" + noReinit + 1.26 + ", checkOutput=" + checkOutput + ", encInputOffset=" + encInputOffset + ", encOutputOffset=" + 1.27 + encOutputOffset + ", decOutputOffset=" + decOutputOffset + ", lastChunkSize=" +lastChunkSize ); 1.28 1.29 if (encInputOffset % ALIGN != 0 || encOutputOffset % ALIGN != 0 || decOutputOffset % ALIGN !=0 ) 1.30 testingMisalignment = true; 1.31 @@ -103,22 +106,24 @@ 1.32 cipher = Cipher.getInstance(algorithm + "/" + mode + "/" + paddingStr, "SunJCE"); 1.33 dCipher = Cipher.getInstance(algorithm + "/" + mode + "/" + paddingStr, "SunJCE"); 1.34 1.35 + // CBC init 1.36 if (mode.equals("CBC")) { 1.37 - int ivLen = (algorithm.equals("AES") ? 16 : algorithm.equals("DES") ? 8 : 0); 1.38 - IvParameterSpec initVector = new IvParameterSpec(new byte[ivLen]); 1.39 + IvParameterSpec initVector = new IvParameterSpec(iv); 1.40 cipher.init(Cipher.ENCRYPT_MODE, key, initVector); 1.41 + algParams = cipher.getParameters(); 1.42 + dCipher.init(Cipher.DECRYPT_MODE, key, initVector); 1.43 + 1.44 + // GCM init 1.45 } else if (mode.equals("GCM")) { 1.46 - iv = new byte[64]; 1.47 - random.nextBytes(iv); 1.48 - aad = new byte[5]; 1.49 - random.nextBytes(aad); 1.50 - gcm_init(); 1.51 + gcm_init(true); 1.52 + gcm_init(false); 1.53 + 1.54 + // ECB init 1.55 } else { 1.56 - algParams = cipher.getParameters(); 1.57 cipher.init(Cipher.ENCRYPT_MODE, key, algParams); 1.58 + dCipher.init(Cipher.DECRYPT_MODE, key, algParams); 1.59 } 1.60 - algParams = cipher.getParameters(); 1.61 - dCipher.init(Cipher.DECRYPT_MODE, key, algParams); 1.62 + 1.63 if (threadId == 0) { 1.64 childShowCipher(); 1.65 } 1.66 @@ -200,11 +205,18 @@ 1.67 1.68 abstract void childShowCipher(); 1.69 1.70 - void gcm_init() throws Exception { 1.71 - tlen = 12; 1.72 + void gcm_init(boolean encrypt) throws Exception { 1.73 gcm_spec = new GCMParameterSpec(tlen * 8, iv); 1.74 - cipher = Cipher.getInstance(algorithm + "/" + mode + "/" + paddingStr, "SunJCE"); 1.75 - cipher.init(Cipher.ENCRYPT_MODE, key, gcm_spec); 1.76 - cipher.update(aad); 1.77 + if (encrypt) { 1.78 + // Get a new instance everytime because of reuse IV restrictions 1.79 + cipher = Cipher.getInstance(algorithm + "/" + mode + "/" + paddingStr, "SunJCE"); 1.80 + cipher.init(Cipher.ENCRYPT_MODE, key, gcm_spec); 1.81 + cipher.updateAAD(aad); 1.82 + } else { 1.83 + dCipher.init(Cipher.DECRYPT_MODE, key, gcm_spec); 1.84 + dCipher.updateAAD(aad); 1.85 + 1.86 + 1.87 + } 1.88 } 1.89 }