1 /*
2 * Copyright (c) 2009, 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
27
28 import java.io.IOException;
29 import java.nio.ByteBuffer;
30 import java.math.BigInteger;
31 import java.util.Arrays;
32
33 import java.security.*;
34 import java.security.interfaces.*;
35 import java.security.spec.*;
36
37 import sun.security.jca.JCAUtil;
38 import sun.security.util.*;
39 import sun.security.x509.AlgorithmId;
40
41 /**
42 * ECDSA signature implementation. This class currently supports the
43 * following algorithm names:
44 *
45 * . "NONEwithECDSA"
46 * . "SHA1withECDSA"
47 * . "SHA256withECDSA"
48 * . "SHA384withECDSA"
49 * . "SHA512withECDSA"
50 *
51 * @since 1.7
52 */
53 abstract class ECDSASignature extends SignatureSpi {
54
55 // message digest implementation we use
56 private final MessageDigest messageDigest;
57
58 // supplied entropy
59 private SecureRandom random;
60
61 // flag indicating whether the digest has been reset
62 private boolean needsReset;
63
64 // private key, if initialized for signing
65 private ECPrivateKey privateKey;
66
145
146 // Returns the precomputed message digest value.
147 @Override
148 protected byte[] getDigestValue() throws SignatureException {
149 if (offset > RAW_ECDSA_MAX) {
150 throw new SignatureException("Message digest is too long");
151
152 }
153 byte[] result = new byte[offset];
154 System.arraycopy(precomputedDigest, 0, result, 0, offset);
155 offset = 0;
156
157 return result;
158 }
159 }
160
161 // Nested class for SHA1withECDSA signatures
162 public static final class SHA1 extends ECDSASignature {
163 public SHA1() {
164 super("SHA1");
165 }
166 }
167
168 // Nested class for SHA256withECDSA signatures
169 public static final class SHA256 extends ECDSASignature {
170 public SHA256() {
171 super("SHA-256");
172 }
173 }
174
175 // Nested class for SHA384withECDSA signatures
176 public static final class SHA384 extends ECDSASignature {
177 public SHA384() {
178 super("SHA-384");
179 }
180 }
181
182 // Nested class for SHA512withECDSA signatures
183 public static final class SHA512 extends ECDSASignature {
184 public SHA512() {
|
1 /*
2 * Copyright (c) 2009, 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
27
28 import java.io.IOException;
29 import java.nio.ByteBuffer;
30 import java.math.BigInteger;
31 import java.util.Arrays;
32
33 import java.security.*;
34 import java.security.interfaces.*;
35 import java.security.spec.*;
36
37 import sun.security.jca.JCAUtil;
38 import sun.security.util.*;
39 import sun.security.x509.AlgorithmId;
40
41 /**
42 * ECDSA signature implementation. This class currently supports the
43 * following algorithm names:
44 *
45 * . "NONEwithECDSA"
46 * . "SHA1withECDSA"
47 * . "SHA224withECDSA"
48 * . "SHA256withECDSA"
49 * . "SHA384withECDSA"
50 * . "SHA512withECDSA"
51 *
52 * @since 1.7
53 */
54 abstract class ECDSASignature extends SignatureSpi {
55
56 // message digest implementation we use
57 private final MessageDigest messageDigest;
58
59 // supplied entropy
60 private SecureRandom random;
61
62 // flag indicating whether the digest has been reset
63 private boolean needsReset;
64
65 // private key, if initialized for signing
66 private ECPrivateKey privateKey;
67
146
147 // Returns the precomputed message digest value.
148 @Override
149 protected byte[] getDigestValue() throws SignatureException {
150 if (offset > RAW_ECDSA_MAX) {
151 throw new SignatureException("Message digest is too long");
152
153 }
154 byte[] result = new byte[offset];
155 System.arraycopy(precomputedDigest, 0, result, 0, offset);
156 offset = 0;
157
158 return result;
159 }
160 }
161
162 // Nested class for SHA1withECDSA signatures
163 public static final class SHA1 extends ECDSASignature {
164 public SHA1() {
165 super("SHA1");
166 }
167 }
168
169 // Nested class for SHA224withECDSA signatures
170 public static final class SHA224 extends ECDSASignature {
171 public SHA224() {
172 super("SHA-224");
173 }
174 }
175
176 // Nested class for SHA256withECDSA signatures
177 public static final class SHA256 extends ECDSASignature {
178 public SHA256() {
179 super("SHA-256");
180 }
181 }
182
183 // Nested class for SHA384withECDSA signatures
184 public static final class SHA384 extends ECDSASignature {
185 public SHA384() {
186 super("SHA-384");
187 }
188 }
189
190 // Nested class for SHA512withECDSA signatures
191 public static final class SHA512 extends ECDSASignature {
192 public SHA512() {
|