test/jdk/sun/security/pkcs11/MessageDigest/DigestKAT.java
author jjiang
Wed, 15 Aug 2018 18:41:18 +0800
changeset 51460 97e361fe3433
parent 47216 71c04702a3d5
permissions -rw-r--r--
8164639: Configure PKCS11 tests to use user-supplied NSS libraries Summary: Provide system property "test.nss.lib.paths" for specifying a set of absolute paths to the custom NSS lib directories Reviewed-by: weijun, rhalade
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
51460
97e361fe3433 8164639: Configure PKCS11 tests to use user-supplied NSS libraries
jjiang
parents: 47216
diff changeset
     2
 * Copyright (c) 2003, 2018, 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
40975
680639c9b307 8165689: Fix module dependencies for sun/security/pkcs11/* tests
skovalev
parents: 35379
diff changeset
    24
/*
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 4856966
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Basic known-answer-test for all our MessageDigest algorithms
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @author Andreas Sterbenz
51460
97e361fe3433 8164639: Configure PKCS11 tests to use user-supplied NSS libraries
jjiang
parents: 47216
diff changeset
    29
 * @library /test/lib ..
43248
5e15de85a1a0 8172527: Rename jdk.crypto.token to jdk.crypto.cryptoki
ascarpino
parents: 42693
diff changeset
    30
 * @modules jdk.crypto.cryptoki
35379
1e8e336ef66b 8144539: Update PKCS11 tests to run with security manager
asmotrak
parents: 12685
diff changeset
    31
 * @run main/othervm DigestKAT
1e8e336ef66b 8144539: Update PKCS11 tests to run with security manager
asmotrak
parents: 12685
diff changeset
    32
 * @run main/othervm DigestKAT sm
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
35379
1e8e336ef66b 8144539: Update PKCS11 tests to run with security manager
asmotrak
parents: 12685
diff changeset
    35
import java.io.ByteArrayOutputStream;
1e8e336ef66b 8144539: Update PKCS11 tests to run with security manager
asmotrak
parents: 12685
diff changeset
    36
import java.io.IOException;
1e8e336ef66b 8144539: Update PKCS11 tests to run with security manager
asmotrak
parents: 12685
diff changeset
    37
import java.io.StringReader;
1e8e336ef66b 8144539: Update PKCS11 tests to run with security manager
asmotrak
parents: 12685
diff changeset
    38
import java.security.MessageDigest;
1e8e336ef66b 8144539: Update PKCS11 tests to run with security manager
asmotrak
parents: 12685
diff changeset
    39
import java.security.Provider;
1e8e336ef66b 8144539: Update PKCS11 tests to run with security manager
asmotrak
parents: 12685
diff changeset
    40
import java.util.Arrays;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
public class DigestKAT extends PKCS11Test {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private final static char[] hexDigits = "0123456789abcdef".toCharArray();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    public static String toString(byte[] b) {
35379
1e8e336ef66b 8144539: Update PKCS11 tests to run with security manager
asmotrak
parents: 12685
diff changeset
    47
        StringBuilder sb = new StringBuilder(b.length * 3);
2
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 DigestTest 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[] data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        private final byte[] digest;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        DigestTest(String alg, byte[] data, byte[] digest) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            this.alg = alg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            this.data = data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            this.digest = digest;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        }
35379
1e8e336ef66b 8144539: Update PKCS11 tests to run with security manager
asmotrak
parents: 12685
diff changeset
   114
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        void run(Provider p) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            if (p.getService("MessageDigest", alg) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                System.out.println("Skipped " + alg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            MessageDigest md = MessageDigest.getInstance(alg, p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            md.update(data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            byte[] myDigest = md.digest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            if (Arrays.equals(digest, myDigest) == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                System.out.println("Digest test for " + alg + " failed:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                if (data.length < 256) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                    System.out.println("data: " + DigestKAT.toString(data));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                System.out.println("dig:  " + DigestKAT.toString(digest));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                System.out.println("out:  " + DigestKAT.toString(myDigest));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                throw new Exception("Digest test for " + alg + " failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    private static byte[] s(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            return s.getBytes("UTF8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            throw new RuntimeException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    private static Test t(String alg, byte[] data, String digest) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        return new DigestTest(alg, data, parse(digest));
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 final static byte[] ALONG;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        ALONG = new byte[1024 * 128];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        Arrays.fill(ALONG, (byte)'a');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    private final static Test[] tests = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        t("MD2", s(""), "8350e5a3e24c153df2275c9f80692773"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        t("MD2", s("a"), "32ec01ec4a6dac72c0ab96fb34c0b5d1"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        t("MD2", s("abc"), "da853b0d3f88d99b30283a69e6ded6bb"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        t("MD2", s("message digest"), "ab4f496bfb2a530b219ff33031fe06b0"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        t("MD2", s("abcdefghijklmnopqrstuvwxyz"), "4e8ddff3650292ab5a4108c3aa47940b"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        t("MD2", s("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), "da33def2a42df13975352846c30338cd"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        t("MD2", s("12345678901234567890123456789012345678901234567890123456789012345678901234567890"), "d5976f79d83d3a0dc9806c3c66f3efd8"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        t("MD2", ALONG, "92:e3:15:b4:d5:35:6f:55:45:e0:08:37:dc:8f:6e:e3"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        t("MD5", s(""), "d41d8cd98f00b204e9800998ecf8427e"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        t("MD5", s("a"), "0cc175b9c0f1b6a831c399e269772661"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        t("MD5", s("abc"), "900150983cd24fb0d6963f7d28e17f72"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        t("MD5", s("message digest"), "f96b697d7cb7938d525a2f31aaf161d0"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        t("MD5", s("abcdefghijklmnopqrstuvwxyz"), "c3fcd3d76192e4007dfb496cca67e13b"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        t("MD5", s("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), "d174ab98d277d9f5a5611c2c9f419d9f"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        t("MD5", s("12345678901234567890123456789012345678901234567890123456789012345678901234567890"), "57edf4a22be3c955ac49da2e2107b67a"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        t("MD5", ALONG, "81:61:54:49:a9:8a:aa:ad:8d:c1:79:b3:be:c8:7f:38"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        t("SHA1", s(""), "da:39:a3:ee:5e:6b:4b:0d:32:55:bf:ef:95:60:18:90:af:d8:07:09"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        t("SHA1", s("a"), "86:f7:e4:37:fa:a5:a7:fc:e1:5d:1d:dc:b9:ea:ea:ea:37:76:67:b8"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        t("SHA1", s("abc"), "a9:99:3e:36:47:06:81:6a:ba:3e:25:71:78:50:c2:6c:9c:d0:d8:9d"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        t("SHA1", s("message digest"), "c1:22:52:ce:da:8b:e8:99:4d:5f:a0:29:0a:47:23:1c:1d:16:aa:e3"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        t("SHA1", s("abcdefghijklmnopqrstuvwxyz"), "32:d1:0c:7b:8c:f9:65:70:ca:04:ce:37:f2:a1:9d:84:24:0d:3a:89"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        t("SHA1", s("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), "76:1c:45:7b:f7:3b:14:d2:7e:9e:92:65:c4:6f:4b:4d:da:11:f9:40"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        t("SHA1", s("12345678901234567890123456789012345678901234567890123456789012345678901234567890"), "50:ab:f5:70:6a:15:09:90:a0:8b:2c:5e:a4:0f:a0:e5:85:55:47:32"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        t("SHA1", ALONG, "ce:56:53:59:08:04:ba:a9:36:9f:72:d4:83:ed:9e:ba:72:f0:4d:29"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
12685
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 5506
diff changeset
   182
        t("SHA-224", s(""), "d1:4a:02:8c:2a:3a:2b:c9:47:61:02:bb:28:82:34:c4:15:a2:b0:1f:82:8e:a6:2a:c5:b3:e4:2f"),
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 5506
diff changeset
   183
        t("SHA-224", s("abc"), "23:09:7d:22:34:05:d8:22:86:42:a4:77:bd:a2:55:b3:2a:ad:bc:e4:bd:a0:b3:f7:e3:6c:9d:a7"),
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 5506
diff changeset
   184
        t("SHA-224", s("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"), "75:38:8b:16:51:27:76:cc:5d:ba:5d:a1:fd:89:01:50:b0:c6:45:5c:b4:f5:8b:19:52:52:25:25"),
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 5506
diff changeset
   185
        t("SHA-224", s("The quick brown fox jumps over the lazy dog"), "73:0e:10:9b:d7:a8:a3:2b:1c:b9:d9:a0:9a:a2:32:5d:24:30:58:7d:db:c0:c3:8b:ad:91:15:25"),
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 5506
diff changeset
   186
        t("SHA-224", s("The quick brown fox jumps over the lazy dog."), "61:9c:ba:8e:8e:05:82:6e:9b:8c:51:9c:0a:5c:68:f4:fb:65:3e:8a:3d:8a:a0:4b:b2:c8:cd:4c"),
8a448b5b9006 4963723: Implement SHA-224
valeriep
parents: 5506
diff changeset
   187
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        t("SHA-256", s(""), "e3:b0:c4:42:98:fc:1c:14:9a:fb:f4:c8:99:6f:b9:24:27:ae:41:e4:64:9b:93:4c:a4:95:99:1b:78:52:b8:55"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        t("SHA-256", s("a"), "ca:97:81:12:ca:1b:bd:ca:fa:c2:31:b3:9a:23:dc:4d:a7:86:ef:f8:14:7c:4e:72:b9:80:77:85:af:ee:48:bb"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        t("SHA-256", s("abc"), "ba:78:16:bf:8f:01:cf:ea:41:41:40:de:5d:ae:22:23:b0:03:61:a3:96:17:7a:9c:b4:10:ff:61:f2:00:15:ad"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        t("SHA-256", s("message digest"), "f7:84:6f:55:cf:23:e1:4e:eb:ea:b5:b4:e1:55:0c:ad:5b:50:9e:33:48:fb:c4:ef:a3:a1:41:3d:39:3c:b6:50"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        t("SHA-256", s("abcdefghijklmnopqrstuvwxyz"), "71:c4:80:df:93:d6:ae:2f:1e:fa:d1:44:7c:66:c9:52:5e:31:62:18:cf:51:fc:8d:9e:d8:32:f2:da:f1:8b:73"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        t("SHA-256", s("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), "db:4b:fc:bd:4d:a0:cd:85:a6:0c:3c:37:d3:fb:d8:80:5c:77:f1:5f:c6:b1:fd:fe:61:4e:e0:a7:c8:fd:b4:c0"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        t("SHA-256", s("12345678901234567890123456789012345678901234567890123456789012345678901234567890"), "f3:71:bc:4a:31:1f:2b:00:9e:ef:95:2d:d8:3c:a8:0e:2b:60:02:6c:8e:93:55:92:d0:f9:c3:08:45:3c:81:3e"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        t("SHA-256", ALONG, "b4:4f:fb:72:fc:c2:59:67:6b:d8:04:95:fe:f1:b4:4b:80:8c:a8:f1:ff:e1:b1:70:6a:4d:79:11:b0:e3:1f:11"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        t("SHA-384", s(""), "38:b0:60:a7:51:ac:96:38:4c:d9:32:7e:b1:b1:e3:6a:21:fd:b7:11:14:be:07:43:4c:0c:c7:bf:63:f6:e1:da:27:4e:de:bf:e7:6f:65:fb:d5:1a:d2:f1:48:98:b9:5b"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        t("SHA-384", s("a"), "54:a5:9b:9f:22:b0:b8:08:80:d8:42:7e:54:8b:7c:23:ab:d8:73:48:6e:1f:03:5d:ce:9c:d6:97:e8:51:75:03:3c:aa:88:e6:d5:7b:c3:5e:fa:e0:b5:af:d3:14:5f:31"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        t("SHA-384", s("abc"), "cb:00:75:3f:45:a3:5e:8b:b5:a0:3d:69:9a:c6:50:07:27:2c:32:ab:0e:de:d1:63:1a:8b:60:5a:43:ff:5b:ed:80:86:07:2b:a1:e7:cc:23:58:ba:ec:a1:34:c8:25:a7"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        t("SHA-384", s("message digest"), "47:3e:d3:51:67:ec:1f:5d:8e:55:03:68:a3:db:39:be:54:63:9f:82:88:68:e9:45:4c:23:9f:c8:b5:2e:3c:61:db:d0:d8:b4:de:13:90:c2:56:dc:bb:5d:5f:d9:9c:d5"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        t("SHA-384", s("abcdefghijklmnopqrstuvwxyz"), "fe:b6:73:49:df:3d:b6:f5:92:48:15:d6:c3:dc:13:3f:09:18:09:21:37:31:fe:5c:7b:5f:49:99:e4:63:47:9f:f2:87:7f:5f:29:36:fa:63:bb:43:78:4b:12:f3:eb:b4"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        t("SHA-384", s("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), "17:61:33:6e:3f:7c:bf:e5:1d:eb:13:7f:02:6f:89:e0:1a:44:8e:3b:1f:af:a6:40:39:c1:46:4e:e8:73:2f:11:a5:34:1a:6f:41:e0:c2:02:29:47:36:ed:64:db:1a:84"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        t("SHA-384", s("12345678901234567890123456789012345678901234567890123456789012345678901234567890"), "b1:29:32:b0:62:7d:1c:06:09:42:f5:44:77:64:15:56:55:bd:4d:a0:c9:af:a6:dd:9b:9e:f5:31:29:af:1b:8f:b0:19:59:96:d2:de:9c:a0:df:9d:82:1f:fe:e6:70:26"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        t("SHA-384", ALONG, "ba:25:a4:25:1a:6c:69:f5:d7:4a:b2:b1:08:be:35:fb:6c:db:35:df:4f:17:c8:08:e7:cc:a2:cb:de:e7:7a:13:4b:35:90:50:10:bf:b9:26:78:65:cf:79:2e:09:79:1c"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        t("SHA-512", s(""), "cf:83:e1:35:7e:ef:b8:bd:f1:54:28:50:d6:6d:80:07:d6:20:e4:05:0b:57:15:dc:83:f4:a9:21:d3:6c:e9:ce:47:d0:d1:3c:5d:85:f2:b0:ff:83:18:d2:87:7e:ec:2f:63:b9:31:bd:47:41:7a:81:a5:38:32:7a:f9:27:da:3e"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        t("SHA-512", s("a"), "1f:40:fc:92:da:24:16:94:75:09:79:ee:6c:f5:82:f2:d5:d7:d2:8e:18:33:5d:e0:5a:bc:54:d0:56:0e:0f:53:02:86:0c:65:2b:f0:8d:56:02:52:aa:5e:74:21:05:46:f3:69:fb:bb:ce:8c:12:cf:c7:95:7b:26:52:fe:9a:75"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        t("SHA-512", s("abc"), "dd:af:35:a1:93:61:7a:ba:cc:41:73:49:ae:20:41:31:12:e6:fa:4e:89:a9:7e:a2:0a:9e:ee:e6:4b:55:d3:9a:21:92:99:2a:27:4f:c1:a8:36:ba:3c:23:a3:fe:eb:bd:45:4d:44:23:64:3c:e8:0e:2a:9a:c9:4f:a5:4c:a4:9f"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        t("SHA-512", s("message digest"), "10:7d:bf:38:9d:9e:9f:71:a3:a9:5f:6c:05:5b:92:51:bc:52:68:c2:be:16:d6:c1:34:92:ea:45:b0:19:9f:33:09:e1:64:55:ab:1e:96:11:8e:8a:90:5d:55:97:b7:20:38:dd:b3:72:a8:98:26:04:6d:e6:66:87:bb:42:0e:7c"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        t("SHA-512", s("abcdefghijklmnopqrstuvwxyz"), "4d:bf:f8:6c:c2:ca:1b:ae:1e:16:46:8a:05:cb:98:81:c9:7f:17:53:bc:e3:61:90:34:89:8f:aa:1a:ab:e4:29:95:5a:1b:f8:ec:48:3d:74:21:fe:3c:16:46:61:3a:59:ed:54:41:fb:0f:32:13:89:f7:7f:48:a8:79:c7:b1:f1"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        t("SHA-512", s("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"), "1e:07:be:23:c2:6a:86:ea:37:ea:81:0c:8e:c7:80:93:52:51:5a:97:0e:92:53:c2:6f:53:6c:fc:7a:99:96:c4:5c:83:70:58:3e:0a:78:fa:4a:90:04:1d:71:a4:ce:ab:74:23:f1:9c:71:b9:d5:a3:e0:12:49:f0:be:bd:58:94"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        t("SHA-512", s("12345678901234567890123456789012345678901234567890123456789012345678901234567890"), "72:ec:1e:f1:12:4a:45:b0:47:e8:b7:c7:5a:93:21:95:13:5b:b6:1d:e2:4e:c0:d1:91:40:42:24:6e:0a:ec:3a:23:54:e0:93:d7:6f:30:48:b4:56:76:43:46:90:0c:b1:30:d2:a4:fd:5d:d1:6a:bb:5e:30:bc:b8:50:de:e8:43"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        t("SHA-512", ALONG, "20:ef:14:68:87:86:cd:1e:1f:ba:e1:0f:6f:83:f8:f0:66:d0:56:3c:94:f6:b4:e5:f4:7e:07:64:60:d0:70:c4:2e:3f:cc:82:4c:a2:ed:35:eb:11:10:7b:ee:70:82:01:99:b6:0c:37:af:12:d0:0f:17:36:b8:56:f4:1f:f7:bf"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    static void runTests(Test[] tests, Provider p) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        long start = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        System.out.println("Testing provider " + p.getName() + "...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        for (int i = 0; i < tests.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            Test test = tests[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            test.run(p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        System.out.println("All tests passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        long stop = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        System.out.println("Done (" + (stop - start) + " ms).");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
35379
1e8e336ef66b 8144539: Update PKCS11 tests to run with security manager
asmotrak
parents: 12685
diff changeset
   229
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    public void main(Provider p) throws Exception{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        runTests(tests, p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    public static void main(String[] args) throws Exception {
35379
1e8e336ef66b 8144539: Update PKCS11 tests to run with security manager
asmotrak
parents: 12685
diff changeset
   235
        main(new DigestKAT(), args);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
}