annotate test/compiler/7184394/TestAESBase.java @ 19148:276bc2752feb

Register plugin for NewFrame intrinsic.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Thu, 05 Feb 2015 03:42:23 +0100
parents 03214612e77e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6894
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
1 /*
17910
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
6894
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
4 *
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
7 * published by the Free Software Foundation.
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
8 *
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
13 * accompanied this code).
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
14 *
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
18 *
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
21 * questions.
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
22 *
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
23 */
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
24
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
25 /**
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
26 * @author Tom Deneau
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
27 */
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
28
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
29 import javax.crypto.Cipher;
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
30 import javax.crypto.KeyGenerator;
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
31 import javax.crypto.SecretKey;
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
32 import javax.crypto.spec.IvParameterSpec;
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
33 import javax.crypto.spec.SecretKeySpec;
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
34 import java.security.AlgorithmParameters;
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
35
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
36 import java.util.Random;
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
37 import java.util.Arrays;
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
38
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
39 abstract public class TestAESBase {
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
40 int msgSize = Integer.getInteger("msgSize", 646);
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
41 boolean checkOutput = Boolean.getBoolean("checkOutput");
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
42 boolean noReinit = Boolean.getBoolean("noReinit");
17910
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
43 boolean testingMisalignment;
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
44 private static final int ALIGN = 8;
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
45 int encInputOffset = Integer.getInteger("encInputOffset", 0) % ALIGN;
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
46 int encOutputOffset = Integer.getInteger("encOutputOffset", 0) % ALIGN;
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
47 int decOutputOffset = Integer.getInteger("decOutputOffset", 0) % ALIGN;
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
48 int lastChunkSize = Integer.getInteger("lastChunkSize", 32);
6894
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
49 int keySize = Integer.getInteger("keySize", 128);
17910
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
50 int inputLength;
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
51 int encodeLength;
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
52 int decodeLength;
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
53 int decodeMsgSize;
6894
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
54 String algorithm = System.getProperty("algorithm", "AES");
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
55 String mode = System.getProperty("mode", "CBC");
17910
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
56 String paddingStr = System.getProperty("paddingStr", "PKCS5Padding");
6894
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
57 byte[] input;
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
58 byte[] encode;
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
59 byte[] expectedEncode;
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
60 byte[] decode;
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
61 byte[] expectedDecode;
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
62 Random random = new Random(0);
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
63 Cipher cipher;
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
64 Cipher dCipher;
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
65 AlgorithmParameters algParams;
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
66 SecretKey key;
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
67
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
68 static int numThreads = 0;
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
69 int threadId;
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
70 static synchronized int getThreadId() {
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
71 int id = numThreads;
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
72 numThreads++;
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
73 return id;
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
74 }
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
75
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
76 abstract public void run();
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
77
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
78 public void prepare() {
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
79 try {
17910
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
80 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 );
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
81
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
82 if (encInputOffset % ALIGN != 0 || encOutputOffset % ALIGN != 0 || decOutputOffset % ALIGN !=0 )
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
83 testingMisalignment = true;
6894
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
84
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
85 int keyLenBytes = (keySize == 0 ? 16 : keySize/8);
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
86 byte keyBytes[] = new byte[keyLenBytes];
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
87 if (keySize == 128)
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
88 keyBytes = new byte[] {-8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7};
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
89 else
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
90 random.nextBytes(keyBytes);
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
91
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
92 key = new SecretKeySpec(keyBytes, algorithm);
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
93 if (threadId == 0) {
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
94 System.out.println("Algorithm: " + key.getAlgorithm() + "("
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
95 + key.getEncoded().length * 8 + "bit)");
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
96 }
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
97
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
98 cipher = Cipher.getInstance(algorithm + "/" + mode + "/" + paddingStr, "SunJCE");
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
99 dCipher = Cipher.getInstance(algorithm + "/" + mode + "/" + paddingStr, "SunJCE");
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
100
7427
2c7f594145dc 8004835: Improve AES intrinsics on x86
kvn
parents: 6894
diff changeset
101 if (mode.equals("CBC")) {
2c7f594145dc 8004835: Improve AES intrinsics on x86
kvn
parents: 6894
diff changeset
102 int ivLen = (algorithm.equals("AES") ? 16 : algorithm.equals("DES") ? 8 : 0);
2c7f594145dc 8004835: Improve AES intrinsics on x86
kvn
parents: 6894
diff changeset
103 IvParameterSpec initVector = new IvParameterSpec(new byte[ivLen]);
2c7f594145dc 8004835: Improve AES intrinsics on x86
kvn
parents: 6894
diff changeset
104 cipher.init(Cipher.ENCRYPT_MODE, key, initVector);
2c7f594145dc 8004835: Improve AES intrinsics on x86
kvn
parents: 6894
diff changeset
105 } else {
2c7f594145dc 8004835: Improve AES intrinsics on x86
kvn
parents: 6894
diff changeset
106 algParams = cipher.getParameters();
2c7f594145dc 8004835: Improve AES intrinsics on x86
kvn
parents: 6894
diff changeset
107 cipher.init(Cipher.ENCRYPT_MODE, key, algParams);
2c7f594145dc 8004835: Improve AES intrinsics on x86
kvn
parents: 6894
diff changeset
108 }
6894
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
109 algParams = cipher.getParameters();
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
110 dCipher.init(Cipher.DECRYPT_MODE, key, algParams);
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
111 if (threadId == 0) {
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
112 childShowCipher();
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
113 }
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
114
17910
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
115 inputLength = msgSize + encInputOffset;
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
116 if (testingMisalignment) {
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
117 encodeLength = cipher.getOutputSize(msgSize - lastChunkSize) + encOutputOffset;
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
118 encodeLength += cipher.getOutputSize(lastChunkSize);
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
119 decodeLength = dCipher.getOutputSize(encodeLength - lastChunkSize) + decOutputOffset;
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
120 decodeLength += dCipher.getOutputSize(lastChunkSize);
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
121 } else {
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
122 encodeLength = cipher.getOutputSize(msgSize) + encOutputOffset;
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
123 decodeLength = dCipher.getOutputSize(encodeLength) + decOutputOffset;
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
124 }
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
125
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
126 input = new byte[inputLength];
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
127 for (int i=encInputOffset, j=0; i<inputLength; i++, j++) {
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
128 input[i] = (byte) (j & 0xff);
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
129 }
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
130
6894
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
131 // do one encode and decode in preparation
17910
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
132 encode = new byte[encodeLength];
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
133 decode = new byte[decodeLength];
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
134 if (testingMisalignment) {
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
135 decodeMsgSize = cipher.update(input, encInputOffset, (msgSize - lastChunkSize), encode, encOutputOffset);
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
136 decodeMsgSize += cipher.doFinal(input, (encInputOffset + msgSize - lastChunkSize), lastChunkSize, encode, (encOutputOffset + decodeMsgSize));
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
137
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
138 int tempSize = dCipher.update(encode, encOutputOffset, (decodeMsgSize - lastChunkSize), decode, decOutputOffset);
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
139 dCipher.doFinal(encode, (encOutputOffset + decodeMsgSize - lastChunkSize), lastChunkSize, decode, (decOutputOffset + tempSize));
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
140 } else {
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
141 decodeMsgSize = cipher.doFinal(input, encInputOffset, msgSize, encode, encOutputOffset);
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
142 dCipher.doFinal(encode, encOutputOffset, decodeMsgSize, decode, decOutputOffset);
03214612e77e 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 7427
diff changeset
143 }
6894
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
144 if (checkOutput) {
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
145 expectedEncode = (byte[]) encode.clone();
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
146 expectedDecode = (byte[]) decode.clone();
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
147 showArray(key.getEncoded() , "key: ");
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
148 showArray(input, "input: ");
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
149 showArray(encode, "encode: ");
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
150 showArray(decode, "decode: ");
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
151 }
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
152 }
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
153 catch (Exception e) {
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
154 e.printStackTrace();
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
155 System.exit(1);
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
156 }
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
157 }
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
158
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
159 void showArray(byte b[], String name) {
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
160 System.out.format("%s [%d]: ", name, b.length);
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
161 for (int i=0; i<Math.min(b.length, 32); i++) {
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
162 System.out.format("%02x ", b[i] & 0xff);
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
163 }
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
164 System.out.println();
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
165 }
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
166
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
167 void compareArrays(byte b[], byte exp[]) {
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
168 if (b.length != exp.length) {
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
169 System.out.format("different lengths for actual and expected output arrays\n");
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
170 showArray(b, "test: ");
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
171 showArray(exp, "exp : ");
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
172 System.exit(1);
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
173 }
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
174 for (int i=0; i< exp.length; i++) {
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
175 if (b[i] != exp[i]) {
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
176 System.out.format("output error at index %d: got %02x, expected %02x\n", i, b[i] & 0xff, exp[i] & 0xff);
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
177 showArray(b, "test: ");
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
178 showArray(exp, "exp : ");
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
179 System.exit(1);
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
180 }
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
181 }
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
182 }
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
183
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
184
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
185 void showCipher(Cipher c, String kind) {
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
186 System.out.println(kind + " cipher provider: " + cipher.getProvider());
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
187 System.out.println(kind + " cipher algorithm: " + cipher.getAlgorithm());
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
188 }
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
189
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
190 abstract void childShowCipher();
a3ecd773a7b9 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
191 }