aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/compiler/7184394/TestAESBase.java54
-rw-r--r--test/compiler/7184394/TestAESDecode.java15
-rw-r--r--test/compiler/7184394/TestAESEncode.java15
-rw-r--r--test/compiler/7184394/TestAESMain.java23
4 files changed, 78 insertions, 29 deletions
diff --git a/test/compiler/7184394/TestAESBase.java b/test/compiler/7184394/TestAESBase.java
index 511b97dc6..4d3204880 100644
--- a/test/compiler/7184394/TestAESBase.java
+++ b/test/compiler/7184394/TestAESBase.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -40,9 +40,20 @@ abstract public class TestAESBase {
int msgSize = Integer.getInteger("msgSize", 646);
boolean checkOutput = Boolean.getBoolean("checkOutput");
boolean noReinit = Boolean.getBoolean("noReinit");
+ boolean testingMisalignment;
+ private static final int ALIGN = 8;
+ int encInputOffset = Integer.getInteger("encInputOffset", 0) % ALIGN;
+ int encOutputOffset = Integer.getInteger("encOutputOffset", 0) % ALIGN;
+ int decOutputOffset = Integer.getInteger("decOutputOffset", 0) % ALIGN;
+ int lastChunkSize = Integer.getInteger("lastChunkSize", 32);
int keySize = Integer.getInteger("keySize", 128);
+ int inputLength;
+ int encodeLength;
+ int decodeLength;
+ int decodeMsgSize;
String algorithm = System.getProperty("algorithm", "AES");
String mode = System.getProperty("mode", "CBC");
+ String paddingStr = System.getProperty("paddingStr", "PKCS5Padding");
byte[] input;
byte[] encode;
byte[] expectedEncode;
@@ -51,7 +62,6 @@ abstract public class TestAESBase {
Random random = new Random(0);
Cipher cipher;
Cipher dCipher;
- String paddingStr = "PKCS5Padding";
AlgorithmParameters algParams;
SecretKey key;
@@ -67,7 +77,10 @@ abstract public class TestAESBase {
public void prepare() {
try {
- System.out.println("\nalgorithm=" + algorithm + ", mode=" + mode + ", msgSize=" + msgSize + ", keySize=" + keySize + ", noReinit=" + noReinit + ", checkOutput=" + checkOutput);
+ 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;
int keyLenBytes = (keySize == 0 ? 16 : keySize/8);
byte keyBytes[] = new byte[keyLenBytes];
@@ -81,10 +94,6 @@ abstract public class TestAESBase {
System.out.println("Algorithm: " + key.getAlgorithm() + "("
+ key.getEncoded().length * 8 + "bit)");
}
- input = new byte[msgSize];
- for (int i=0; i<input.length; i++) {
- input[i] = (byte) (i & 0xff);
- }
cipher = Cipher.getInstance(algorithm + "/" + mode + "/" + paddingStr, "SunJCE");
dCipher = Cipher.getInstance(algorithm + "/" + mode + "/" + paddingStr, "SunJCE");
@@ -103,10 +112,35 @@ abstract public class TestAESBase {
childShowCipher();
}
+ inputLength = msgSize + encInputOffset;
+ if (testingMisalignment) {
+ encodeLength = cipher.getOutputSize(msgSize - lastChunkSize) + encOutputOffset;
+ encodeLength += cipher.getOutputSize(lastChunkSize);
+ decodeLength = dCipher.getOutputSize(encodeLength - lastChunkSize) + decOutputOffset;
+ decodeLength += dCipher.getOutputSize(lastChunkSize);
+ } else {
+ encodeLength = cipher.getOutputSize(msgSize) + encOutputOffset;
+ decodeLength = dCipher.getOutputSize(encodeLength) + decOutputOffset;
+ }
+
+ input = new byte[inputLength];
+ for (int i=encInputOffset, j=0; i<inputLength; i++, j++) {
+ input[i] = (byte) (j & 0xff);
+ }
+
// do one encode and decode in preparation
- // this will also create the encode buffer and decode buffer
- encode = cipher.doFinal(input);
- decode = dCipher.doFinal(encode);
+ encode = new byte[encodeLength];
+ decode = new byte[decodeLength];
+ if (testingMisalignment) {
+ decodeMsgSize = cipher.update(input, encInputOffset, (msgSize - lastChunkSize), encode, encOutputOffset);
+ decodeMsgSize += cipher.doFinal(input, (encInputOffset + msgSize - lastChunkSize), lastChunkSize, encode, (encOutputOffset + decodeMsgSize));
+
+ int tempSize = dCipher.update(encode, encOutputOffset, (decodeMsgSize - lastChunkSize), decode, decOutputOffset);
+ dCipher.doFinal(encode, (encOutputOffset + decodeMsgSize - lastChunkSize), lastChunkSize, decode, (decOutputOffset + tempSize));
+ } else {
+ decodeMsgSize = cipher.doFinal(input, encInputOffset, msgSize, encode, encOutputOffset);
+ dCipher.doFinal(encode, encOutputOffset, decodeMsgSize, decode, decOutputOffset);
+ }
if (checkOutput) {
expectedEncode = (byte[]) encode.clone();
expectedDecode = (byte[]) decode.clone();
diff --git a/test/compiler/7184394/TestAESDecode.java b/test/compiler/7184394/TestAESDecode.java
index f9ec02d15..21f1f5559 100644
--- a/test/compiler/7184394/TestAESDecode.java
+++ b/test/compiler/7184394/TestAESDecode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -33,14 +33,15 @@ public class TestAESDecode extends TestAESBase {
public void run() {
try {
if (!noReinit) dCipher.init(Cipher.DECRYPT_MODE, key, algParams);
+ decode = new byte[decodeLength];
+ if (testingMisalignment) {
+ int tempSize = dCipher.update(encode, encOutputOffset, (decodeMsgSize - lastChunkSize), decode, decOutputOffset);
+ dCipher.doFinal(encode, (encOutputOffset + decodeMsgSize - lastChunkSize), lastChunkSize, decode, (decOutputOffset + tempSize));
+ } else {
+ dCipher.doFinal(encode, encOutputOffset, decodeMsgSize, decode, decOutputOffset);
+ }
if (checkOutput) {
- // checked version creates new output buffer each time
- decode = dCipher.doFinal(encode, 0, encode.length);
compareArrays(decode, expectedDecode);
- } else {
- // non-checked version outputs to existing encode buffer for maximum speed
- decode = new byte[dCipher.getOutputSize(encode.length)];
- dCipher.doFinal(encode, 0, encode.length, decode);
}
}
catch (Exception e) {
diff --git a/test/compiler/7184394/TestAESEncode.java b/test/compiler/7184394/TestAESEncode.java
index 1d6bf7fbd..f1a35bde0 100644
--- a/test/compiler/7184394/TestAESEncode.java
+++ b/test/compiler/7184394/TestAESEncode.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -33,14 +33,15 @@ public class TestAESEncode extends TestAESBase {
public void run() {
try {
if (!noReinit) cipher.init(Cipher.ENCRYPT_MODE, key, algParams);
+ encode = new byte[encodeLength];
+ if (testingMisalignment) {
+ int tempSize = cipher.update(input, encInputOffset, (msgSize - lastChunkSize), encode, encOutputOffset);
+ cipher.doFinal(input, (encInputOffset + msgSize - lastChunkSize), lastChunkSize, encode, (encOutputOffset + tempSize));
+ } else {
+ cipher.doFinal(input, encInputOffset, msgSize, encode, encOutputOffset);
+ }
if (checkOutput) {
- // checked version creates new output buffer each time
- encode = cipher.doFinal(input, 0, msgSize);
compareArrays(encode, expectedEncode);
- } else {
- // non-checked version outputs to existing encode buffer for maximum speed
- encode = new byte[cipher.getOutputSize(msgSize)];
- cipher.doFinal(input, 0, msgSize, encode);
}
}
catch (Exception e) {
diff --git a/test/compiler/7184394/TestAESMain.java b/test/compiler/7184394/TestAESMain.java
index ff9e12bcd..20929e8ba 100644
--- a/test/compiler/7184394/TestAESMain.java
+++ b/test/compiler/7184394/TestAESMain.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012, 2014 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -28,7 +28,19 @@
* @summary add intrinsics to use AES instructions
*
* @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=CBC TestAESMain
+ * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=CBC -DencInputOffset=1 TestAESMain
+ * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=CBC -DencOutputOffset=1 TestAESMain
+ * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=CBC -DdecOutputOffset=1 TestAESMain
+ * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=CBC -DencInputOffset=1 -DencOutputOffset=1 TestAESMain
+ * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=CBC -DencInputOffset=1 -DencOutputOffset=1 -DdecOutputOffset=1 TestAESMain
+ * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=CBC -DencInputOffset=1 -DencOutputOffset=1 -DdecOutputOffset=1 -DpaddingStr=NoPadding -DmsgSize=640 TestAESMain
* @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=ECB TestAESMain
+ * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=ECB -DencInputOffset=1 TestAESMain
+ * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=ECB -DencOutputOffset=1 TestAESMain
+ * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=ECB -DdecOutputOffset=1 TestAESMain
+ * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=ECB -DencInputOffset=1 -DencOutputOffset=1 TestAESMain
+ * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=ECB -DencInputOffset=1 -DencOutputOffset=1 -DdecOutputOffset=1 TestAESMain
+ * @run main/othervm/timeout=600 -Xbatch -DcheckOutput=true -Dmode=ECB -DencInputOffset=1 -DencOutputOffset=1 -DdecOutputOffset=1 -DpaddingStr=NoPadding -DmsgSize=640 TestAESMain
*
* @author Tom Deneau
*/
@@ -36,12 +48,13 @@
public class TestAESMain {
public static void main(String[] args) {
int iters = (args.length > 0 ? Integer.valueOf(args[0]) : 1000000);
+ int warmupIters = (args.length > 1 ? Integer.valueOf(args[1]) : 20000);
System.out.println(iters + " iterations");
TestAESEncode etest = new TestAESEncode();
etest.prepare();
- // warm-up for 20K iterations
+ // warm-up
System.out.println("Starting encryption warm-up");
- for (int i=0; i<20000; i++) {
+ for (int i=0; i<warmupIters; i++) {
etest.run();
}
System.out.println("Finished encryption warm-up");
@@ -54,9 +67,9 @@ public class TestAESMain {
TestAESDecode dtest = new TestAESDecode();
dtest.prepare();
- // warm-up for 20K iterations
+ // warm-up
System.out.println("Starting decryption warm-up");
- for (int i=0; i<20000; i++) {
+ for (int i=0; i<warmupIters; i++) {
dtest.run();
}
System.out.println("Finished decryption warm-up");