< prev index next >
test/compiler/codegen/7184394/TestAESBase.java
Print this page
*** 29,38 ****
--- 29,39 ----
import jdk.test.lib.Utils;
import java.security.AlgorithmParameters;
import java.util.Random;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
+ import javax.crypto.spec.GCMParameterSpec;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
abstract public class TestAESBase {
int msgSize = Integer.getInteger("msgSize", 646);
*** 60,69 ****
--- 61,74 ----
final Random random = Utils.getRandomInstance();
Cipher cipher;
Cipher dCipher;
AlgorithmParameters algParams;
SecretKey key;
+ GCMParameterSpec gcm_spec;
+ byte[] aad;
+ int tlen = 12;
+ byte[] iv;
static int numThreads = 0;
int threadId;
static synchronized int getThreadId() {
int id = numThreads;
*** 98,107 ****
--- 103,118 ----
if (mode.equals("CBC")) {
int ivLen = (algorithm.equals("AES") ? 16 : algorithm.equals("DES") ? 8 : 0);
IvParameterSpec initVector = new IvParameterSpec(new byte[ivLen]);
cipher.init(Cipher.ENCRYPT_MODE, key, initVector);
+ } else if (mode.equals("GCM")) {
+ iv = new byte[64];
+ random.nextBytes(iv);
+ aad = new byte[5];
+ random.nextBytes(aad);
+ gcm_init();
} else {
algParams = cipher.getParameters();
cipher.init(Cipher.ENCRYPT_MODE, key, algParams);
}
algParams = cipher.getParameters();
*** 184,189 ****
--- 195,208 ----
System.out.println(kind + " cipher provider: " + cipher.getProvider());
System.out.println(kind + " cipher algorithm: " + cipher.getAlgorithm());
}
abstract void childShowCipher();
+
+ void gcm_init() throws Exception {
+ tlen = 12;
+ gcm_spec = new GCMParameterSpec(tlen * 8, iv);
+ cipher = Cipher.getInstance(algorithm + "/" + mode + "/" + paddingStr, "SunJCE");
+ cipher.init(Cipher.ENCRYPT_MODE, key, gcm_spec);
+ cipher.update(aad);
+ }
}
< prev index next >