hotspot/test/compiler/codegen/7184394/TestAESBase.java
author ykantser
Mon, 04 May 2015 16:30:07 +0200
changeset 30604 b8d532cb6420
parent 27699 9913b19c0948
child 31404 63e8fcd70bfc
permissions -rw-r--r--
8067013: Rename the com.oracle.java.testlibary package Reviewed-by: dholmes, gtriantafill, sla Contributed-by: alexander.kulyakhtin@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
     1
/*
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 27699
diff changeset
     2
 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
     4
 *
3c1437abcefd 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
3c1437abcefd 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
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
     8
 *
3c1437abcefd 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
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
3c1437abcefd 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
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    13
 * accompanied this code).
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    14
 *
3c1437abcefd 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
3c1437abcefd 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,
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    18
 *
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3c1437abcefd 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
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    21
 * questions.
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    22
 *
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    23
 */
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    24
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    25
/**
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    26
 * @author Tom Deneau
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    27
 */
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    28
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 27699
diff changeset
    29
import jdk.test.lib.Utils;
27453
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents: 24328
diff changeset
    30
import java.security.AlgorithmParameters;
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents: 24328
diff changeset
    31
import java.util.Random;
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    32
import javax.crypto.Cipher;
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    33
import javax.crypto.SecretKey;
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    34
import javax.crypto.spec.IvParameterSpec;
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    35
import javax.crypto.spec.SecretKeySpec;
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    36
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    37
abstract public class TestAESBase {
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    38
  int msgSize = Integer.getInteger("msgSize", 646);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    39
  boolean checkOutput = Boolean.getBoolean("checkOutput");
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    40
  boolean noReinit = Boolean.getBoolean("noReinit");
24328
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
    41
  boolean testingMisalignment;
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
    42
  private static final int ALIGN = 8;
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
    43
  int encInputOffset = Integer.getInteger("encInputOffset", 0) % ALIGN;
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
    44
  int encOutputOffset = Integer.getInteger("encOutputOffset", 0) % ALIGN;
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
    45
  int decOutputOffset = Integer.getInteger("decOutputOffset", 0) % ALIGN;
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
    46
  int lastChunkSize = Integer.getInteger("lastChunkSize", 32);
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    47
  int keySize = Integer.getInteger("keySize", 128);
24328
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
    48
  int inputLength;
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
    49
  int encodeLength;
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
    50
  int decodeLength;
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
    51
  int decodeMsgSize;
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    52
  String algorithm = System.getProperty("algorithm", "AES");
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    53
  String mode = System.getProperty("mode", "CBC");
24328
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
    54
  String paddingStr = System.getProperty("paddingStr", "PKCS5Padding");
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    55
  byte[] input;
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    56
  byte[] encode;
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    57
  byte[] expectedEncode;
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    58
  byte[] decode;
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    59
  byte[] expectedDecode;
27453
9aeb9b97bef6 8044186: Introduce a reproducible random generator
iignatyev
parents: 24328
diff changeset
    60
  final Random random = Utils.getRandomInstance();
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    61
  Cipher cipher;
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    62
  Cipher dCipher;
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    63
  AlgorithmParameters algParams;
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    64
  SecretKey key;
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    65
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    66
  static int numThreads = 0;
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    67
  int  threadId;
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    68
  static synchronized int getThreadId() {
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    69
    int id = numThreads;
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    70
    numThreads++;
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    71
    return id;
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    72
  }
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    73
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    74
  abstract public void run();
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    75
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    76
  public void prepare() {
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    77
    try {
24328
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
    78
    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 );
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
    79
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
    80
      if (encInputOffset % ALIGN != 0 || encOutputOffset % ALIGN != 0 || decOutputOffset % ALIGN !=0 )
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
    81
        testingMisalignment = true;
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    82
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    83
      int keyLenBytes = (keySize == 0 ? 16 : keySize/8);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    84
      byte keyBytes[] = new byte[keyLenBytes];
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    85
      if (keySize == 128)
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    86
        keyBytes = new byte[] {-8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7};
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    87
      else
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    88
        random.nextBytes(keyBytes);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    89
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    90
      key = new SecretKeySpec(keyBytes, algorithm);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    91
      if (threadId == 0) {
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    92
        System.out.println("Algorithm: " + key.getAlgorithm() + "("
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    93
                           + key.getEncoded().length * 8 + "bit)");
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    94
      }
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    95
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    96
      cipher = Cipher.getInstance(algorithm + "/" + mode + "/" + paddingStr, "SunJCE");
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    97
      dCipher = Cipher.getInstance(algorithm + "/" + mode + "/" + paddingStr, "SunJCE");
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
    98
14834
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14132
diff changeset
    99
      if (mode.equals("CBC")) {
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14132
diff changeset
   100
        int ivLen = (algorithm.equals("AES") ? 16 : algorithm.equals("DES") ? 8 : 0);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14132
diff changeset
   101
        IvParameterSpec initVector = new IvParameterSpec(new byte[ivLen]);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14132
diff changeset
   102
        cipher.init(Cipher.ENCRYPT_MODE, key, initVector);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14132
diff changeset
   103
      } else {
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14132
diff changeset
   104
        algParams = cipher.getParameters();
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14132
diff changeset
   105
        cipher.init(Cipher.ENCRYPT_MODE, key, algParams);
f29c91f2f22b 8004835: Improve AES intrinsics on x86
kvn
parents: 14132
diff changeset
   106
      }
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   107
      algParams = cipher.getParameters();
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   108
      dCipher.init(Cipher.DECRYPT_MODE, key, algParams);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   109
      if (threadId == 0) {
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   110
        childShowCipher();
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   111
      }
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   112
24328
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
   113
      inputLength = msgSize + encInputOffset;
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
   114
      if (testingMisalignment) {
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
   115
        encodeLength = cipher.getOutputSize(msgSize - lastChunkSize) + encOutputOffset;
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
   116
        encodeLength += cipher.getOutputSize(lastChunkSize);
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
   117
        decodeLength = dCipher.getOutputSize(encodeLength - lastChunkSize) + decOutputOffset;
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
   118
        decodeLength += dCipher.getOutputSize(lastChunkSize);
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
   119
      } else {
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
   120
        encodeLength = cipher.getOutputSize(msgSize) + encOutputOffset;
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
   121
        decodeLength = dCipher.getOutputSize(encodeLength) + decOutputOffset;
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
   122
      }
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
   123
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
   124
      input = new byte[inputLength];
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
   125
      for (int i=encInputOffset, j=0; i<inputLength; i++, j++) {
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
   126
        input[i] = (byte) (j & 0xff);
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
   127
      }
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
   128
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   129
      // do one encode and decode in preparation
24328
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
   130
      encode = new byte[encodeLength];
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
   131
      decode = new byte[decodeLength];
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
   132
      if (testingMisalignment) {
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
   133
        decodeMsgSize = cipher.update(input, encInputOffset, (msgSize - lastChunkSize), encode, encOutputOffset);
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
   134
        decodeMsgSize += cipher.doFinal(input, (encInputOffset + msgSize - lastChunkSize), lastChunkSize, encode, (encOutputOffset + decodeMsgSize));
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
   135
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
   136
        int tempSize = dCipher.update(encode, encOutputOffset, (decodeMsgSize - lastChunkSize), decode, decOutputOffset);
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
   137
        dCipher.doFinal(encode, (encOutputOffset + decodeMsgSize - lastChunkSize), lastChunkSize, decode, (decOutputOffset + tempSize));
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
   138
      } else {
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
   139
        decodeMsgSize = cipher.doFinal(input, encInputOffset, msgSize, encode, encOutputOffset);
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
   140
        dCipher.doFinal(encode, encOutputOffset, decodeMsgSize, decode, decOutputOffset);
bddefb356fba 8035936: SIGBUS in StubRoutines::aesencryptBlock, solaris-sparc
kvn
parents: 14834
diff changeset
   141
      }
14132
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   142
      if (checkOutput) {
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   143
        expectedEncode = (byte[]) encode.clone();
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   144
        expectedDecode = (byte[]) decode.clone();
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   145
        showArray(key.getEncoded()  ,  "key:    ");
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   146
        showArray(input,  "input:  ");
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   147
        showArray(encode, "encode: ");
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   148
        showArray(decode, "decode: ");
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   149
      }
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   150
    }
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   151
    catch (Exception e) {
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   152
      e.printStackTrace();
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   153
      System.exit(1);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   154
    }
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   155
  }
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   156
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   157
  void showArray(byte b[], String name) {
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   158
    System.out.format("%s [%d]: ", name, b.length);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   159
    for (int i=0; i<Math.min(b.length, 32); i++) {
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   160
      System.out.format("%02x ", b[i] & 0xff);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   161
    }
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   162
    System.out.println();
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   163
  }
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   164
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   165
  void compareArrays(byte b[], byte exp[]) {
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   166
    if (b.length != exp.length) {
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   167
      System.out.format("different lengths for actual and expected output arrays\n");
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   168
      showArray(b, "test: ");
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   169
      showArray(exp, "exp : ");
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   170
      System.exit(1);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   171
    }
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   172
    for (int i=0; i< exp.length; i++) {
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   173
      if (b[i] != exp[i]) {
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   174
        System.out.format("output error at index %d: got %02x, expected %02x\n", i, b[i] & 0xff, exp[i] & 0xff);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   175
        showArray(b, "test: ");
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   176
        showArray(exp, "exp : ");
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   177
        System.exit(1);
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   178
      }
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   179
    }
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   180
  }
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   181
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   182
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   183
  void showCipher(Cipher c, String kind) {
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   184
    System.out.println(kind + " cipher provider: " + cipher.getProvider());
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   185
    System.out.println(kind + " cipher algorithm: " + cipher.getAlgorithm());
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   186
  }
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   187
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   188
  abstract void childShowCipher();
3c1437abcefd 7184394: add intrinsics to use AES instructions
kvn
parents:
diff changeset
   189
}