4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 import jdk.testlibrary.Asserts;
25
26 import java.security.MessageDigest;
27 import java.util.Arrays;
28
29 /**
30 * @test
31 * @bug 8051408
32 * @library /lib/testlibrary
33 * @summary testing SHA-512/224 and SHA-512/256.
34 */
35 public class SHA512 {
36 public static void main(String[] args) throws Exception {
37
38 MessageDigest md;
39
40 // Test vectors obtained from
41 // http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA512_224.pdf
42 md = MessageDigest.getInstance("SHA-512/224");
43 Asserts.assertTrue(Arrays.equals(md.digest("abc".getBytes()),
44 xeh("4634270F 707B6A54 DAAE7530 460842E2 0E37ED26 5CEEE9A4 3E8924AA")));
45 Asserts.assertTrue(Arrays.equals(md.digest((
46 "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn" +
47 "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu").getBytes()),
48 xeh("23FEC5BB 94D60B23 30819264 0B0C4533 35D66473 4FE40E72 68674AF9")));
49
50 // Test vectors obtained from
51 // http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA512_256.pdf
52 md = MessageDigest.getInstance("SHA-512/256");
|
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 import jdk.test.lib.Asserts;
25
26 import java.security.MessageDigest;
27 import java.util.Arrays;
28
29 /**
30 * @test
31 * @bug 8051408
32 * @library /test/lib
33 * @summary testing SHA-512/224 and SHA-512/256.
34 */
35 public class SHA512 {
36 public static void main(String[] args) throws Exception {
37
38 MessageDigest md;
39
40 // Test vectors obtained from
41 // http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA512_224.pdf
42 md = MessageDigest.getInstance("SHA-512/224");
43 Asserts.assertTrue(Arrays.equals(md.digest("abc".getBytes()),
44 xeh("4634270F 707B6A54 DAAE7530 460842E2 0E37ED26 5CEEE9A4 3E8924AA")));
45 Asserts.assertTrue(Arrays.equals(md.digest((
46 "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn" +
47 "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu").getBytes()),
48 xeh("23FEC5BB 94D60B23 30819264 0B0C4533 35D66473 4FE40E72 68674AF9")));
49
50 // Test vectors obtained from
51 // http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA512_256.pdf
52 md = MessageDigest.getInstance("SHA-512/256");
|