001: package org.bouncycastle.jce.provider;
002:
003: import java.security.MessageDigest;
004:
005: import org.bouncycastle.crypto.Digest;
006: import org.bouncycastle.crypto.digests.*;
007:
008: public class JDKMessageDigest extends MessageDigest {
009: Digest digest;
010:
011: protected JDKMessageDigest(Digest digest) {
012: super (digest.getAlgorithmName());
013:
014: this .digest = digest;
015: }
016:
017: public void engineReset() {
018: digest.reset();
019: }
020:
021: public void engineUpdate(byte input) {
022: digest.update(input);
023: }
024:
025: public void engineUpdate(byte[] input, int offset, int len) {
026: digest.update(input, offset, len);
027: }
028:
029: public byte[] engineDigest() {
030: byte[] digestBytes = new byte[digest.getDigestSize()];
031:
032: digest.doFinal(digestBytes, 0);
033:
034: return digestBytes;
035: }
036:
037: /**
038: * classes that extend directly off us.
039: */
040: static public class SHA1 extends JDKMessageDigest implements
041: Cloneable {
042: public SHA1() {
043: super (new SHA1Digest());
044: }
045:
046: public Object clone() throws CloneNotSupportedException {
047: SHA1 d = (SHA1) super .clone();
048: d.digest = new SHA1Digest((SHA1Digest) digest);
049:
050: return d;
051: }
052: }
053:
054: static public class SHA224 extends JDKMessageDigest implements
055: Cloneable {
056: public SHA224() {
057: super (new SHA224Digest());
058: }
059:
060: public Object clone() throws CloneNotSupportedException {
061: SHA224 d = (SHA224) super .clone();
062: d.digest = new SHA224Digest((SHA224Digest) digest);
063:
064: return d;
065: }
066: }
067:
068: static public class SHA256 extends JDKMessageDigest implements
069: Cloneable {
070: public SHA256() {
071: super (new SHA256Digest());
072: }
073:
074: public Object clone() throws CloneNotSupportedException {
075: SHA256 d = (SHA256) super .clone();
076: d.digest = new SHA256Digest((SHA256Digest) digest);
077:
078: return d;
079: }
080: }
081:
082: static public class SHA384 extends JDKMessageDigest implements
083: Cloneable {
084: public SHA384() {
085: super (new SHA384Digest());
086: }
087:
088: public Object clone() throws CloneNotSupportedException {
089: SHA384 d = (SHA384) super .clone();
090: d.digest = new SHA384Digest((SHA384Digest) digest);
091:
092: return d;
093: }
094: }
095:
096: static public class SHA512 extends JDKMessageDigest implements
097: Cloneable {
098: public SHA512() {
099: super (new SHA512Digest());
100: }
101:
102: public Object clone() throws CloneNotSupportedException {
103: SHA512 d = (SHA512) super .clone();
104: d.digest = new SHA512Digest((SHA512Digest) digest);
105:
106: return d;
107: }
108: }
109:
110: static public class MD2 extends JDKMessageDigest implements
111: Cloneable {
112: public MD2() {
113: super (new MD2Digest());
114: }
115:
116: public Object clone() throws CloneNotSupportedException {
117: MD2 d = (MD2) super .clone();
118: d.digest = new MD2Digest((MD2Digest) digest);
119:
120: return d;
121: }
122: }
123:
124: static public class MD4 extends JDKMessageDigest implements
125: Cloneable {
126: public MD4() {
127: super (new MD4Digest());
128: }
129:
130: public Object clone() throws CloneNotSupportedException {
131: MD4 d = (MD4) super .clone();
132: d.digest = new MD4Digest((MD4Digest) digest);
133:
134: return d;
135: }
136: }
137:
138: static public class MD5 extends JDKMessageDigest implements
139: Cloneable {
140: public MD5() {
141: super (new MD5Digest());
142: }
143:
144: public Object clone() throws CloneNotSupportedException {
145: MD5 d = (MD5) super .clone();
146: d.digest = new MD5Digest((MD5Digest) digest);
147:
148: return d;
149: }
150: }
151:
152: static public class RIPEMD128 extends JDKMessageDigest implements
153: Cloneable {
154: public RIPEMD128() {
155: super (new RIPEMD128Digest());
156: }
157:
158: public Object clone() throws CloneNotSupportedException {
159: RIPEMD128 d = (RIPEMD128) super .clone();
160: d.digest = new RIPEMD128Digest((RIPEMD128Digest) digest);
161:
162: return d;
163: }
164: }
165:
166: static public class RIPEMD160 extends JDKMessageDigest implements
167: Cloneable {
168: public RIPEMD160() {
169: super (new RIPEMD160Digest());
170: }
171:
172: public Object clone() throws CloneNotSupportedException {
173: RIPEMD160 d = (RIPEMD160) super .clone();
174: d.digest = new RIPEMD160Digest((RIPEMD160Digest) digest);
175:
176: return d;
177: }
178: }
179:
180: static public class RIPEMD256 extends JDKMessageDigest implements
181: Cloneable {
182: public RIPEMD256() {
183: super (new RIPEMD256Digest());
184: }
185:
186: public Object clone() throws CloneNotSupportedException {
187: RIPEMD256 d = (RIPEMD256) super .clone();
188: d.digest = new RIPEMD256Digest((RIPEMD256Digest) digest);
189:
190: return d;
191: }
192: }
193:
194: static public class RIPEMD320 extends JDKMessageDigest implements
195: Cloneable {
196: public RIPEMD320() {
197: super (new RIPEMD320Digest());
198: }
199:
200: public Object clone() throws CloneNotSupportedException {
201: RIPEMD320 d = (RIPEMD320) super .clone();
202: d.digest = new RIPEMD320Digest((RIPEMD320Digest) digest);
203:
204: return d;
205: }
206: }
207:
208: static public class Tiger extends JDKMessageDigest implements
209: Cloneable {
210: public Tiger() {
211: super (new TigerDigest());
212: }
213:
214: public Object clone() throws CloneNotSupportedException {
215: Tiger d = (Tiger) super .clone();
216: d.digest = new TigerDigest((TigerDigest) digest);
217:
218: return d;
219: }
220: }
221:
222: static public class GOST3411 extends JDKMessageDigest implements
223: Cloneable {
224: public GOST3411() {
225: super (new GOST3411Digest());
226: }
227:
228: public Object clone() throws CloneNotSupportedException {
229: GOST3411 d = (GOST3411) super .clone();
230: d.digest = new GOST3411Digest((GOST3411Digest) digest);
231:
232: return d;
233: }
234: }
235:
236: static public class Whirlpool extends JDKMessageDigest implements
237: Cloneable {
238: public Whirlpool() {
239: super (new WhirlpoolDigest());
240: }
241:
242: public Object clone() throws CloneNotSupportedException {
243: Whirlpool d = (Whirlpool) super .clone();
244: d.digest = new WhirlpoolDigest((WhirlpoolDigest) digest);
245:
246: return d;
247: }
248: }
249: }
|