1 /*
2 * Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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 */
104 String alg2 = src2.getAlgorithm();
105 if (alg1.equals(alg2)) {
106 // assumes they are PSource.PSpecified
107 return Arrays.equals(((PSource.PSpecified) src1).getValue(),
108 ((PSource.PSpecified) src2).getValue());
109 } else {
110 System.out.println("PSource algos: " + alg1 + " vs " + alg2);
111 return false;
112 }
113 }
114
115 private static boolean compareSpec(OAEPParameterSpec s1,
116 OAEPParameterSpec s2) {
117 return (compareMD(s1, s2) && compareMGF(s1, s2) &&
118 comparePSource(s1, s2));
119 }
120
121 public static void main(String[] argv) throws Exception {
122 boolean status = true;
123 byte[] p = { (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04 };
124 status &= runTest("SHA-256", MGF1ParameterSpec.SHA256, p);
125 status &= runTest("SHA-384", MGF1ParameterSpec.SHA384, p);
126 status &= runTest("SHA-512", MGF1ParameterSpec.SHA512, p);
127 status &= runTest("SHA", MGF1ParameterSpec.SHA1, new byte[0]);
128 status &= runTest("SHA-1", MGF1ParameterSpec.SHA1, new byte[0]);
129 status &= runTest("SHA1", MGF1ParameterSpec.SHA1, new byte[0]);
130 if (status) {
131 System.out.println("Test Passed");
132 } else {
133 throw new Exception("One or More Test Failed");
134 }
135 }
136 }
|
1 /*
2 * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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 */
104 String alg2 = src2.getAlgorithm();
105 if (alg1.equals(alg2)) {
106 // assumes they are PSource.PSpecified
107 return Arrays.equals(((PSource.PSpecified) src1).getValue(),
108 ((PSource.PSpecified) src2).getValue());
109 } else {
110 System.out.println("PSource algos: " + alg1 + " vs " + alg2);
111 return false;
112 }
113 }
114
115 private static boolean compareSpec(OAEPParameterSpec s1,
116 OAEPParameterSpec s2) {
117 return (compareMD(s1, s2) && compareMGF(s1, s2) &&
118 comparePSource(s1, s2));
119 }
120
121 public static void main(String[] argv) throws Exception {
122 boolean status = true;
123 byte[] p = { (byte) 0x01, (byte) 0x02, (byte) 0x03, (byte) 0x04 };
124 status &= runTest("SHA-224", MGF1ParameterSpec.SHA224, p);
125 status &= runTest("SHA-256", MGF1ParameterSpec.SHA256, p);
126 status &= runTest("SHA-384", MGF1ParameterSpec.SHA384, p);
127 status &= runTest("SHA-512", MGF1ParameterSpec.SHA512, p);
128 status &= runTest("SHA", MGF1ParameterSpec.SHA1, new byte[0]);
129 status &= runTest("SHA-1", MGF1ParameterSpec.SHA1, new byte[0]);
130 status &= runTest("SHA1", MGF1ParameterSpec.SHA1, new byte[0]);
131 if (status) {
132 System.out.println("Test Passed");
133 } else {
134 throw new Exception("One or More Test Failed");
135 }
136 }
137 }
|