FSF GCC merge 02/23/03
[official-gcc.git] / libjava / java / security / SignatureSpi.java
blob01a7280f18be0993d884e2e911e90fe2e01f3c73
1 /* SignatureSpi.java --- Signature Service Provider Interface
2 Copyright (C) 1999 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package java.security;
39 import java.security.spec.AlgorithmParameterSpec;
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.
47 @author Mark Benvenuto <ivymccough@worldnet.att.net>
49 @since JDK 1.2
51 public abstract class SignatureSpi
53 /**
54 Source of randomness
56 protected SecureRandom appRandom;
58 /**
59 Creates a new instance of SignatureSpi.
61 public SignatureSpi()
63 appRandom = null;
66 /**
67 Initializes this class with the public key for
68 verification purposes.
70 @param publicKey the public key to verify with
72 @throws InvalidKeyException invalid key
74 protected abstract void engineInitVerify(PublicKey publicKey)
75 throws InvalidKeyException;
77 /**
78 Initializes this class with the private key for
79 signing purposes.
81 @param privateKey the private key to sign with
83 @throws InvalidKeyException invalid key
85 protected abstract void engineInitSign(PrivateKey privateKey)
86 throws InvalidKeyException;
88 /**
89 Initializes this class with the private key and source
90 of randomness for signing purposes.
92 This cannot be abstract backward compatibility reasons
94 @param privateKey the private key to sign with
95 @param random Source of randomness
97 @throws InvalidKeyException invalid key
99 @since JDK 1.2
101 protected void engineInitSign(PrivateKey privateKey, SecureRandom random)
102 throws InvalidKeyException
104 appRandom = random;
105 engineInitSign(privateKey);
109 Updates the data to be signed or verified with the specified
110 byte.
112 @param b byte to update with
114 @throws SignatureException Engine not properly initialized
116 protected abstract void engineUpdate(byte b) throws SignatureException;
119 Updates the data to be signed or verified with the specified
120 bytes.
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
126 @throws SignatureException engine not properly initialized
128 protected abstract void engineUpdate(byte[] b, int off, int len)
129 throws SignatureException;
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.
136 @return the signature
138 @throws SignatureException engine not properly initialized
140 protected abstract byte[] engineSign() throws SignatureException;
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.
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.
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.
161 @return number of bytes in outbuf
163 @throws SignatureException engine not properly initialized
165 @since JDK 1.2
167 protected int engineSign(byte[] outbuf, int offset, int len)
168 throws SignatureException
170 byte tmp[] = engineSign();
172 if (tmp.length > len)
173 throw new SignatureException("Invalid Length");
175 System.arraycopy(outbuf, offset, tmp, 0, tmp.length);
177 return tmp.length;
181 Verifies the passed signature.
183 @param sigBytes the signature bytes to verify
185 @return true if verified, false otherwise
187 @throws SignatureException engine not properly initialized
188 or wrong signature
190 protected abstract boolean engineVerify(byte[] sigBytes)
191 throws SignatureException;
194 Sets the specified algorithm parameter to the specified value.
196 @param param parameter name
197 @param value parameter value
199 @throws InvalidParameterException invalid parameter, parameter
200 already set and cannot set again, a security exception,
201 etc.
203 @deprecated use the other setParameter
205 protected abstract void engineSetParameter(String param, Object value)
206 throws InvalidParameterException;
209 Sets the signature engine with the specified
210 AlgorithmParameterSpec;
212 This cannot be abstract backward compatibility reasons
213 By default this always throws UnsupportedOperationException
214 if not overridden;
216 @param params the parameters
218 @throws InvalidParameterException invalid parameter, parameter
219 already set and cannot set again, a security exception,
220 etc.
222 protected void engineSetParameter(AlgorithmParameterSpec params)
223 throws InvalidAlgorithmParameterException
225 throw new UnsupportedOperationException();
229 Gets the value for the specified algorithm parameter.
231 @param param parameter name
233 @return parameter value
235 @throws InvalidParameterException invalid parameter
237 @deprecated use the other getParameter
239 protected abstract Object engineGetParameter(String param)
240 throws InvalidParameterException;
243 Returns a clone if cloneable.
245 @return a clone if cloneable.
247 @throws CloneNotSupportedException if the implementation does
248 not support cloning
250 public Object clone() throws CloneNotSupportedException
252 throw new CloneNotSupportedException();