jdk/test/com/sun/crypto/provider/Mac/MacKAT.java
author katleman
Thu, 05 Jan 2012 08:42:37 -0800
changeset 11376 075fe3928b7f
parent 5506 202f599c92aa
child 12685 8a448b5b9006
permissions -rw-r--r--
Added tag jdk8-b20 for changeset 90e14ec89395
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 4846410 6313661
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Basic known-answer-test for Hmac and SslMac algorithms
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @author Andreas Sterbenz
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.security.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.crypto.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.crypto.spec.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public class MacKAT {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private final static char[] hexDigits = "0123456789abcdef".toCharArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    public static String toString(byte[] b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        if (b == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
            return "(null)";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        StringBuffer sb = new StringBuffer(b.length * 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        for (int i = 0; i < b.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
            int k = b[i] & 0xff;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
            if (i != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
                sb.append(':');
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
            sb.append(hexDigits[k >>> 4]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            sb.append(hexDigits[k & 0xf]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    public static byte[] parse(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            int n = s.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            ByteArrayOutputStream out = new ByteArrayOutputStream(n / 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            StringReader r = new StringReader(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                int b1 = nextNibble(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                if (b1 < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                int b2 = nextNibble(r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                if (b2 < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                    throw new RuntimeException("Invalid string " + s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                int b = (b1 << 4) | b2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                out.write(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            return out.toByteArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            throw new RuntimeException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public static byte[] b(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        return parse(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private static int nextNibble(StringReader r) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            int ch = r.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            if (ch == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            } else if ((ch >= '0') && (ch <= '9')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                return ch - '0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            } else if ((ch >= 'a') && (ch <= 'f')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                return ch - 'a' + 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            } else if ((ch >= 'A') && (ch <= 'F')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                return ch - 'A' + 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    static abstract class Test {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        abstract void run(Provider p) throws Exception;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    static class MacTest extends Test {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        private final String alg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        private final byte[] input;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        private final byte[] macvalue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        private final byte[] key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        MacTest(String alg, byte[] input, byte[] macvalue, byte[] key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            this.alg = alg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            this.input = input;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            this.macvalue = macvalue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            this.key = key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        void run(Provider p) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            Mac mac = Mac.getInstance(alg, p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            SecretKey keySpec = new SecretKeySpec(key, alg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            mac.init(keySpec);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            mac.update(input);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            byte[] macv = mac.doFinal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            if (Arrays.equals(macvalue, macv) == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                System.out.println("Mac test for " + alg + " failed:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                if (input.length < 256) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                    System.out.println("input:       " + toString(input));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                System.out.println("key:        " + toString(key));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                System.out.println("macvalue:   " + toString(macvalue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                System.out.println("calculated: " + toString(macv));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                throw new Exception("Mac test for " + alg + " failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            System.out.println("passed: " + alg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        private static String toString(byte[] b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            return MacKAT.toString(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    private static byte[] s(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            return s.getBytes("UTF8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            throw new RuntimeException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    private static Test t(String alg, String input, String macvalue, String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        return new MacTest(alg, b(input), b(macvalue), b(key));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    private static Test t(String alg, byte[] input, String macvalue, String key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        return new MacTest(alg, input, b(macvalue), b(key));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    private static Test t(String alg, byte[] input, String macvalue, byte[] key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        return new MacTest(alg, input, b(macvalue), key);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    private final static byte[] ALONG, BLONG, BKEY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        ALONG = new byte[1024 * 128];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        Arrays.fill(ALONG, (byte)'a');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        BLONG = new byte[1024 * 128];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        Random random = new Random(12345678);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        random.nextBytes(BLONG);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        BKEY = new byte[128];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        random.nextBytes(BKEY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    private final static Test[] tests = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        t("SslMacMD5", ALONG, "f4:ad:01:71:51:f6:89:56:72:a3:32:bf:d9:2a:f2:a5",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                "1b:34:61:29:05:0d:73:db:25:d0:dd:64:06:29:f6:8a"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        t("SslMacMD5", BLONG, "34:1c:ad:a0:95:57:32:f8:8e:80:8f:ee:b2:d8:23:e5",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                "76:00:4a:72:98:9b:65:ec:2e:f1:43:c4:65:4a:13:71"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        t("SslMacSHA1", ALONG, "11:c1:71:2e:61:be:4b:cf:bc:6d:e2:4c:58:ae:27:30:0b:24:a4:87",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                "23:ae:dd:61:87:6c:7a:45:47:2f:2c:8f:ea:64:99:3e:27:5f:97:a5"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        t("SslMacSHA1", BLONG, "84:af:57:0a:af:ef:16:93:90:50:da:88:f8:ad:1a:c5:66:6c:94:d0",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                "9b:bb:e2:aa:9b:28:1c:95:0e:ea:30:21:98:a5:7e:31:9e:bf:5f:51"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        t("HmacMD5", ALONG, "76:00:4a:72:98:9b:65:ec:2e:f1:43:c4:65:4a:13:71",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                "1b:34:61:29:05:0d:73:db:25:d0:dd:64:06:29:f6:8a"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        t("HmacMD5", BLONG, "6c:22:79:bb:34:9e:da:f4:f5:cf:df:0c:62:3d:59:e0",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                "76:00:4a:72:98:9b:65:ec:2e:f1:43:c4:65:4a:13:71"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        t("HmacMD5", BLONG, "e6:ad:00:c9:49:6b:98:fe:53:a2:b9:2d:7d:41:a2:03",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                BKEY),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        t("HmacSHA1", ALONG, "9e:b3:6e:35:fa:fb:17:2e:2b:f3:b0:4a:9d:38:83:c4:5f:6d:d9:00",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                "1b:34:61:29:05:0d:73:db:25:d0:dd:64:06:29:f6:8a"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        t("HmacSHA1", BLONG, "80:2d:5b:ea:08:df:a4:1f:e5:3e:1c:fa:fc:ad:dd:31:da:15:60:2c",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                "76:00:4a:72:98:9b:65:ec:2e:f1:43:c4:65:4a:13:71"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        t("HmacSHA1", BLONG, "a2:fa:2a:85:18:0e:94:b2:a5:e2:17:8b:2a:29:7a:95:cd:e8:aa:82",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                BKEY),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        t("HmacSHA256", ALONG, "3f:6d:08:df:0c:90:b0:e9:ed:13:4a:2e:c3:48:1d:3d:3e:61:2e:f1:30:c2:63:c4:58:57:03:c2:cb:87:15:07",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                "1b:34:61:29:05:0d:73:db:25:d0:dd:64:06:29:f6:8a"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        t("HmacSHA256", BLONG, "e2:4e:a3:b9:0b:b8:99:e4:71:cf:ca:9f:f8:4e:f0:34:8b:19:9f:33:4b:1a:b7:13:f7:c8:57:92:e3:03:74:78",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                BKEY),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        t("HmacSHA384", ALONG, "d0:f0:d4:54:1c:0a:6d:81:ed:15:20:d7:0c:96:06:61:a0:ff:c9:ff:91:e9:a0:cd:e2:45:64:9d:93:4c:a9:fa:89:ae:c0:90:e6:0b:a1:a0:56:80:57:3b:ed:4b:b0:71",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                "1b:34:61:29:05:0d:73:db:25:d0:dd:64:06:29:f6:8a"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        t("HmacSHA384", BLONG, "75:c4:ca:c7:f7:58:9d:d3:23:b1:1b:5c:93:2d:ec:7a:03:dc:8c:eb:8d:fe:79:46:4f:30:e7:99:62:de:44:e2:38:95:0e:79:91:78:2f:a4:05:0a:f0:17:10:38:a1:8e",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                BKEY),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        t("HmacSHA512", ALONG, "41:ea:4c:e5:31:3f:7c:18:0e:5e:95:a9:25:0a:10:58:e6:40:53:88:82:4f:5a:da:6f:29:de:04:7b:8e:d7:ed:7c:4d:b8:2a:48:2d:17:2a:2d:59:bb:81:9c:bf:33:40:04:77:44:fb:45:25:1f:fd:b9:29:f4:a6:69:a3:43:6f",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                "1b:34:61:29:05:0d:73:db:25:d0:dd:64:06:29:f6:8a"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        t("HmacSHA512", BLONG, "fb:cf:4b:c6:d5:49:5a:5b:0b:d9:2a:32:f5:fa:68:d2:68:a4:0f:ae:53:fc:49:12:e6:1d:53:cf:b2:cb:c5:c5:f2:2d:86:bd:14:61:30:c3:a6:6f:44:1f:77:9b:aa:a1:22:48:a9:dd:d0:45:86:d1:a1:82:53:13:c4:03:06:a3",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                BKEY),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    static void runTests(Test[] tests) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        long start = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        Provider p = Security.getProvider("SunJCE");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        System.out.println("Testing provider " + p.getName() + "...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        Mac.getInstance("HmacSHA256", p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        Mac.getInstance("HmacSHA384", p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        Mac.getInstance("HmacSHA512", p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        KeyGenerator.getInstance("HmacSHA256", p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        KeyGenerator.getInstance("HmacSHA384", p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        KeyGenerator.getInstance("HmacSHA512", p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        for (int i = 0; i < tests.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            Test test = tests[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            test.run(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        System.out.println("All tests passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        long stop = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        System.out.println("Done (" + (stop - start) + " ms).");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        runTests(tests);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
}