< prev index next >

test/jdk/sun/security/pkcs11/ec/TestECDSA.java

Print this page
rev 59383 : [mq]: final
   1 /*
   2  * Copyright (c) 2006, 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  */


 109 
 110     private static void sign(Provider provider, String alg, PrivateKey key, byte[] data) throws Exception {
 111         Signature s = Signature.getInstance(alg, provider);
 112         s.initSign(key);
 113         s.update(data);
 114         byte[] sig = s.sign();
 115         System.out.println(toString(sig));
 116     }
 117 
 118     public static void main(String[] args) throws Exception {
 119         main(new TestECDSA(), args);
 120     }
 121 
 122     @Override
 123     protected boolean skipTest(Provider provider) {
 124         if (provider.getService("Signature", "SHA1withECDSA") == null) {
 125             System.out.println("ECDSA not supported, skipping");
 126             return true;
 127         }
 128 
 129         if (isBadNSSVersion(provider) || isBadSolarisSparc(provider)) {
 130             return true;
 131         }
 132 
 133         return false;
 134     }
 135 
 136     @Override
 137     public void main(Provider provider) throws Exception {
 138         long start = System.currentTimeMillis();
 139 
 140         /*
 141          * PKCS11Test.main will remove this provider if needed
 142          */
 143         Providers.setAt(provider, 1);
 144 
 145         if (false) {
 146             KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", provider);
 147             kpg.initialize(571);
 148             KeyPair kp = kpg.generateKeyPair();
 149             PrivateKey priv = kp.getPrivate();


   1 /*
   2  * Copyright (c) 2006, 2020, 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  */


 109 
 110     private static void sign(Provider provider, String alg, PrivateKey key, byte[] data) throws Exception {
 111         Signature s = Signature.getInstance(alg, provider);
 112         s.initSign(key);
 113         s.update(data);
 114         byte[] sig = s.sign();
 115         System.out.println(toString(sig));
 116     }
 117 
 118     public static void main(String[] args) throws Exception {
 119         main(new TestECDSA(), args);
 120     }
 121 
 122     @Override
 123     protected boolean skipTest(Provider provider) {
 124         if (provider.getService("Signature", "SHA1withECDSA") == null) {
 125             System.out.println("ECDSA not supported, skipping");
 126             return true;
 127         }
 128 
 129         if (isBadNSSVersion(provider)) {
 130             return true;
 131         }
 132 
 133         return false;
 134     }
 135 
 136     @Override
 137     public void main(Provider provider) throws Exception {
 138         long start = System.currentTimeMillis();
 139 
 140         /*
 141          * PKCS11Test.main will remove this provider if needed
 142          */
 143         Providers.setAt(provider, 1);
 144 
 145         if (false) {
 146             KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC", provider);
 147             kpg.initialize(571);
 148             KeyPair kp = kpg.generateKeyPair();
 149             PrivateKey priv = kp.getPrivate();


< prev index next >