< prev index next >

test/jdk/com/sun/crypto/provider/Cipher/RSA/TestOAEPParameterSpec.java

Print this page


   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  */
  23 
  24 /*
  25  * @test
  26  * @bug 4923484
  27  * @summary test ASN.1 encoding generation/parsing for the OAEPParameters
  28  * implementation in SunJCE provider.
  29  * @author Valerie Peng
  30  */
  31 import java.math.BigInteger;
  32 import java.util.*;
  33 import java.security.*;
  34 import java.security.spec.MGF1ParameterSpec;
  35 import javax.crypto.*;
  36 import javax.crypto.spec.OAEPParameterSpec;
  37 import javax.crypto.spec.PSource;
  38 
  39 public class TestOAEPParameterSpec {
  40 
  41     private static Provider cp;
  42 
  43     private static boolean runTest(String mdName, MGF1ParameterSpec mgfSpec,
  44         byte[] p) throws Exception {
  45         OAEPParameterSpec spec = new OAEPParameterSpec(mdName, "MGF1",
  46             mgfSpec, new PSource.PSpecified(p));


 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 }
   1 /*
   2  * Copyright (c) 2003, 2018, 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  */
  23 
  24 /*
  25  * @test
  26  * @bug 4923484 8146293
  27  * @summary test ASN.1 encoding generation/parsing for the OAEPParameters
  28  * implementation in SunJCE provider.
  29  * @author Valerie Peng
  30  */
  31 import java.math.BigInteger;
  32 import java.util.*;
  33 import java.security.*;
  34 import java.security.spec.MGF1ParameterSpec;
  35 import javax.crypto.*;
  36 import javax.crypto.spec.OAEPParameterSpec;
  37 import javax.crypto.spec.PSource;
  38 
  39 public class TestOAEPParameterSpec {
  40 
  41     private static Provider cp;
  42 
  43     private static boolean runTest(String mdName, MGF1ParameterSpec mgfSpec,
  44         byte[] p) throws Exception {
  45         OAEPParameterSpec spec = new OAEPParameterSpec(mdName, "MGF1",
  46             mgfSpec, new PSource.PSpecified(p));


 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-512/224", MGF1ParameterSpec.SHA512_224, p);
 129         status &= runTest("SHA-512/256", MGF1ParameterSpec.SHA512_256, p);
 130         status &= runTest("SHA", MGF1ParameterSpec.SHA1, new byte[0]);
 131         status &= runTest("SHA-1", MGF1ParameterSpec.SHA1, new byte[0]);
 132         status &= runTest("SHA1", MGF1ParameterSpec.SHA1, new byte[0]);
 133         if (status) {
 134             System.out.println("Test Passed");
 135         } else {
 136             throw new Exception("One or More Test Failed");
 137         }
 138     }
 139 }
< prev index next >