source: trunk/src/gcc/libjava/java/security/SignatureSpi.java@ 681

Last change on this file since 681 was 2, checked in by bird, 23 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 7.5 KB
Line 
1/* SignatureSpi.java --- Signature Service Provider Interface
2 Copyright (C) 1999 Free Software Foundation, Inc.
3
4This file is part of GNU Classpath.
5
6GNU Classpath is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU Classpath is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Classpath; see the file COPYING. If not, write to the
18Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
1902111-1307 USA.
20
21Linking this library statically or dynamically with other modules is
22making a combined work based on this library. Thus, the terms and
23conditions of the GNU General Public License cover the whole
24combination.
25
26As a special exception, the copyright holders of this library give you
27permission to link this library with independent modules to produce an
28executable, regardless of the license terms of these independent
29modules, and to copy and distribute the resulting executable under
30terms of your choice, provided that you also meet, for each linked
31independent module, the terms and conditions of the license of that
32module. An independent module is a module which is not derived from
33or based on this library. If you modify this library, you may extend
34this exception to your version of the library, but you are not
35obligated to do so. If you do not wish to do so, delete this
36exception statement from your version. */
37
38package java.security;
39import java.security.spec.AlgorithmParameterSpec;
40
41/**
42 SignatureSpi defines the Service Provider Interface (SPI)
43 for the Signature class. The signature class provides an
44 interface to a digital signature algorithm. Digital signatures
45 are used for authentication and integrity of data.
46
47 @author Mark Benvenuto <[email protected]>
48
49 @since JDK 1.2
50 */
51public abstract class SignatureSpi
52{
53 /**
54 Source of randomness
55 */
56 protected SecureRandom appRandom;
57
58 /**
59 Creates a new instance of SignatureSpi.
60 */
61 public SignatureSpi()
62 {
63 appRandom = null;
64 }
65
66 /**
67 Initializes this class with the public key for
68 verification purposes.
69
70 @param publicKey the public key to verify with
71
72 @throws InvalidKeyException invalid key
73 */
74 protected abstract void engineInitVerify(PublicKey publicKey)
75 throws InvalidKeyException;
76
77 /**
78 Initializes this class with the private key for
79 signing purposes.
80
81 @param privateKey the private key to sign with
82
83 @throws InvalidKeyException invalid key
84 */
85 protected abstract void engineInitSign(PrivateKey privateKey)
86 throws InvalidKeyException;
87
88 /**
89 Initializes this class with the private key and source
90 of randomness for signing purposes.
91
92 This cannot be abstract backward compatibility reasons
93
94 @param privateKey the private key to sign with
95 @param random Source of randomness
96
97 @throws InvalidKeyException invalid key
98
99 @since JDK 1.2
100 */
101 protected void engineInitSign(PrivateKey privateKey, SecureRandom random)
102 throws InvalidKeyException
103 {
104 appRandom = random;
105 engineInitSign(privateKey);
106 }
107
108 /**
109 Updates the data to be signed or verified with the specified
110 byte.
111
112 @param b byte to update with
113
114 @throws SignatureException Engine not properly initialized
115 */
116 protected abstract void engineUpdate(byte b) throws SignatureException;
117
118 /**
119 Updates the data to be signed or verified with the specified
120 bytes.
121
122 @param b array of bytes
123 @param off the offset to start at in the array
124 @param len the length of the bytes to use in the array
125
126 @throws SignatureException engine not properly initialized
127 */
128 protected abstract void engineUpdate(byte[] b, int off, int len)
129 throws SignatureException;
130
131 /**
132 Returns the signature bytes of all the data fed to this class.
133 The format of the output depends on the underlying signature
134 algorithm.
135
136 @return the signature
137
138 @throws SignatureException engine not properly initialized
139 */
140 protected abstract byte[] engineSign() throws SignatureException;
141
142 /**
143 Generates signature bytes of all the data fed to this class
144 and outputs it to the passed array. The format of the
145 output depends on the underlying signature algorithm.
146
147 This cannot be abstract backward compatibility reasons.
148 After calling this method, the signature is reset to its
149 initial state and can be used to generate additional
150 signatures.
151
152 @param outbuff array of bytes
153 @param offset the offset to start at in the array
154 @param len the length of the bytes to put into the array.
155 Neither this method or the GNU provider will
156 return partial digests. If len is less than the
157 signature length, this method will throw
158 SignatureException. If it is greater than or equal
159 then it is ignored.
160
161 @return number of bytes in outbuf
162
163 @throws SignatureException engine not properly initialized
164
165 @since JDK 1.2
166 */
167 protected int engineSign(byte[] outbuf, int offset, int len)
168 throws SignatureException
169 {
170 byte tmp[] = engineSign();
171
172 if (tmp.length > len)
173 throw new SignatureException("Invalid Length");
174
175 System.arraycopy(outbuf, offset, tmp, 0, tmp.length);
176
177 return tmp.length;
178 }
179
180 /**
181 Verifies the passed signature.
182
183 @param sigBytes the signature bytes to verify
184
185 @return true if verified, false otherwise
186
187 @throws SignatureException engine not properly initialized
188 or wrong signature
189 */
190 protected abstract boolean engineVerify(byte[] sigBytes)
191 throws SignatureException;
192
193 /**
194 Sets the specified algorithm parameter to the specified value.
195
196 @param param parameter name
197 @param value parameter value
198
199 @throws InvalidParameterException invalid parameter, parameter
200 already set and cannot set again, a security exception,
201 etc.
202
203 @deprecated use the other setParameter
204 */
205 protected abstract void engineSetParameter(String param, Object value)
206 throws InvalidParameterException;
207
208 /**
209 Sets the signature engine with the specified
210 AlgorithmParameterSpec;
211
212 This cannot be abstract backward compatibility reasons
213 By default this always throws UnsupportedOperationException
214 if not overridden;
215
216 @param params the parameters
217
218 @throws InvalidParameterException invalid parameter, parameter
219 already set and cannot set again, a security exception,
220 etc.
221 */
222 protected void engineSetParameter(AlgorithmParameterSpec params)
223 throws InvalidAlgorithmParameterException
224 {
225 throw new UnsupportedOperationException();
226 }
227
228 /**
229 Gets the value for the specified algorithm parameter.
230
231 @param param parameter name
232
233 @return parameter value
234
235 @throws InvalidParameterException invalid parameter
236
237 @deprecated use the other getParameter
238 */
239 protected abstract Object engineGetParameter(String param)
240 throws InvalidParameterException;
241
242 /**
243 Returns a clone if cloneable.
244
245 @return a clone if cloneable.
246
247 @throws CloneNotSupportedException if the implementation does
248 not support cloning
249 */
250 public Object clone() throws CloneNotSupportedException
251 {
252 throw new CloneNotSupportedException();
253 }
254}
Note: See TracBrowser for help on using the repository browser.