1 /* MessageDigestSpi.java --- The message digest 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)
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
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
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
;
41 This is the Service Provider Interface (SPI) for MessageDigest
42 class in java.security. It provides the back end functionality
43 for the MessageDigest class so that it can compute message
44 hashes. The default hashes are SHA-1 and MD5. A message hash
45 takes data of arbitrary length and produces a unique number
48 Cryptography service providers who want to implement their
49 own message digest hashes need only to subclass this class.
51 The implementation of a Cloneable interface is left to up to
52 the programmer of a subclass.
56 @author Mark Benvenuto <ivymccough@worldnet.att.net>
58 public abstract class MessageDigestSpi
61 Default constructor of the MessageDigestSpi class
63 public MessageDigestSpi()
68 Returns the length of the digest. It may be overridden by the
69 provider to return the length of the digest. Default is to
70 return 0. It is concrete for backwards compatibility with JDK1.1
71 message digest classes.
73 @return Length of Digest in Bytes
77 protected int engineGetDigestLength()
83 Updates the digest with the specified byte.
85 @param input the byte to update digest with
87 protected abstract void engineUpdate(byte input
);
91 Updates the digest with the specified bytes starting with the
92 offset and proceeding for the specified length.
94 @param input the byte array to update digest with
95 @param offset the offset of the byte to start with
96 @param len the number of the bytes to update with
98 protected abstract void engineUpdate(byte[]input
, int offset
, int len
);
101 Computes the final digest of the stored bytes and returns
102 them. It performs any necessary padding. The message digest
103 should reset sensitive data after performing the digest.
105 @return An array of bytes containing the digest
107 protected abstract byte[] engineDigest();
110 Computes the final digest of the stored bytes and returns
111 them. It performs any necessary padding. The message digest
112 should reset sensitive data after performing the digest. This
113 method is left concrete for backwards compatibility with JDK1.1
114 message digest classes.
116 @param buf An array of bytes to store the digest
117 @param offset An offset to start storing the digest at
118 @param len The length of the buffer
119 @return Returns the length of the buffer
123 protected int engineDigest(byte[]buf
, int offset
, int len
)
124 throws DigestException
126 if (engineGetDigestLength() > len
)
127 throw new DigestException("Buffer is too small.");
129 byte tmp
[] = engineDigest();
130 if (tmp
.length
> len
)
131 throw new DigestException("Buffer is too small");
133 System
.arraycopy(tmp
, 0, buf
, offset
, tmp
.length
);
138 Resets the digest engine. Reinitializes internal variables
139 and clears sensitive data.
141 protected abstract void engineReset();
144 Returns a clone of this class.
146 If cloning is not supported, then by default the class throws a
147 CloneNotSupportedException. The MessageDigestSpi provider
148 implementation has to overload this class in order to be
151 public Object
clone() throws CloneNotSupportedException
153 if (this instanceof Cloneable
)
154 return super.clone();
156 throw new CloneNotSupportedException();