Imported GNU Classpath 0.90
[official-gcc.git] / libjava / classpath / gnu / java / security / sig / ISignature.java
blobe77f39d2cf104d46887c3ba3625b40a1d77f2933
1 /* ISignature.java --
2 Copyright (C) 2001, 2002, 2003, 2006 Free Software Foundation, Inc.
4 This file is a 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 of the License, or (at
9 your option) 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; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
19 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. */
39 package gnu.java.security.sig;
41 import java.util.Map;
43 /**
44 * <p>The visible methods of every signature-with-appendix scheme.</p>
46 * <p>The Handbook of Applied Cryptography (HAC), by A. Menezes &amp; al. states:
47 * "Digital signature schemes which require the message as input to the
48 * verification algorithm are called <i>digital signature schemes with
49 * appendix</i>. ... They rely on cryptographic hash functions rather than
50 * customised redundancy functions, and are less prone to existential forgery
51 * attacks."</p>
53 * <p>References:</p>
54 * <ol>
55 * <li><a href="http://www.cacr.math.uwaterloo.ca/hac/">Handbook of Applied
56 * Cryptography</a>, Alfred J. Menezes, Paul C. van Oorschot and Scott A.
57 * Vanstone. Section 11.2.2 Digital signature schemes with appendix.</li>
58 * </ol>
60 public interface ISignature extends Cloneable
63 // Constants
64 // -------------------------------------------------------------------------
66 /** Property name of the verifier's public key. */
67 public static final String VERIFIER_KEY = "gnu.crypto.sig.public.key";
69 /** Property name of the signer's private key. */
70 public static final String SIGNER_KEY = "gnu.crypto.sig.private.key";
72 /**
73 * Property name of an optional {@link java.security.SecureRandom},
74 * {@link java.util.Random}, or {@link gnu.crypto.prng.IRandom} instance to
75 * use. The default is to use a classloader singleton from
76 * {@link gnu.crypto.util.PRNG}.
78 public static final String SOURCE_OF_RANDOMNESS = "gnu.crypto.sig.prng";
80 // Methods
81 // -------------------------------------------------------------------------
83 /**
84 * <p>Returns the canonical name of this signature scheme.</p>
86 * @return the canonical name of this instance.
88 String name();
90 /**
91 * <p>Initialises this instance for signature verification.</p>
93 * @param attributes the attributes to use for setting up this instance.
94 * @throws IllegalArgumentException if the designated public key is not
95 * appropriate for this signature scheme.
96 * @see #SOURCE_OF_RANDOMNESS
97 * @see #VERIFIER_KEY
99 void setupVerify(Map attributes) throws IllegalArgumentException;
102 * <p>Initialises this instance for signature generation.</p>
104 * @param attributes the attributes to use for setting up this instance.
105 * @throws IllegalArgumentException if the designated private key is not
106 * appropriate for this signature scheme.
107 * @see #SOURCE_OF_RANDOMNESS
108 * @see #SIGNER_KEY
110 void setupSign(Map attributes) throws IllegalArgumentException;
113 * <p>Digests one byte of a message for signing or verification purposes.</p>
115 * @param b the message byte to digest.
116 * @throws IllegalStateException if this instance was not setup for
117 * signature generation/verification.
119 void update(byte b) throws IllegalStateException;
122 * <p>Digests a sequence of bytes from a message for signing or verification
123 * purposes.</p>
125 * @param buffer the byte sequence to consider.
126 * @param offset the byte poisition in <code>buffer</code> of the first byte
127 * to consider.
128 * @param length the number of bytes in <code>buffer</code> starting from the
129 * byte at index <code>offset</code> to digest.
130 * @throws IllegalStateException if this instance was not setup for
131 * signature generation/verification.
133 void update(byte[] buffer, int offset, int length)
134 throws IllegalStateException;
137 * <p>Terminates a signature generation phase by digesting and processing the
138 * context of the underlying message digest algorithm instance.</p>
140 * @return a {@link Object} representing the native output of the signature
141 * scheme implementation.
142 * @throws IllegalStateException if this instance was not setup for
143 * signature generation.
145 Object sign() throws IllegalStateException;
148 * <p>Terminates a signature verification phase by digesting and processing
149 * the context of the underlying message digest algorithm instance.</p>
151 * @param signature a native signature object previously generated by an
152 * invocation of the <code>sign()</code> method.
153 * @return <code>true</code> iff the outpout of the verification phase
154 * confirms that the designated signature object has been generated using the
155 * corresponding public key of the recepient.
156 * @throws IllegalStateException if this instance was not setup for
157 * signature verification.
159 boolean verify(Object signature) throws IllegalStateException;
162 * <p>Returns a clone copy of this instance.</p>
164 * @return a clone copy of this instance.
166 Object clone();