KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > crypto > MacSpi


1 /*
2  * @(#)MacSpi.java 1.5 03/12/19
3  *
4  * Copyright (c) 2004 Sun Microsystems, Inc. All Rights Reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7   
8 /*
9  * NOTE:
10  * Because of various external restrictions (i.e. US export
11  * regulations, etc.), the actual source code can not be provided
12  * at this time. This file represents the skeleton of the source
13  * file, so that javadocs of the API can be created.
14  */

15
16 package javax.crypto;
17
18 import java.security.*;
19 import java.security.spec.*;
20
21 import java.nio.ByteBuffer;
22
23 /**
24  * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>)
25  * for the <code>Mac</code> class.
26  * All the abstract methods in this class must be implemented by each
27  * cryptographic service provider who wishes to supply the implementation
28  * of a particular MAC algorithm.
29  *
30  * <p> Implementations are free to implement the Cloneable interface.
31  *
32  * @author Jan Luehe
33  *
34  * @version 1.9, 04/30/03
35  * @since 1.4
36  */

37 public abstract class MacSpi
38 {
39
40     public MacSpi() { }
41
42     /**
43      * Returns the length of the MAC in bytes.
44      *
45      * @return the MAC length in bytes.
46      */

47     protected abstract int engineGetMacLength();
48
49     /**
50      * Initializes the MAC with the given (secret) key and algorithm
51      * parameters.
52      *
53      * @param key the (secret) key.
54      * @param params the algorithm parameters.
55      *
56      * @exception InvalidKeyException if the given key is inappropriate for
57      * initializing this MAC.
58      * @exception InvalidAlgorithmParameterException if the given algorithm
59      * parameters are inappropriate for this MAC.
60      */

61     protected abstract void engineInit(Key key, AlgorithmParameterSpec params)
62         throws InvalidKeyException, InvalidAlgorithmParameterException;
63
64     /**
65      * Processes the given byte.
66      *
67      * @param input the input byte to be processed.
68      */

69     protected abstract void engineUpdate(byte input);
70
71     /**
72      * Processes the first <code>len</code> bytes in <code>input</code>,
73      * starting at <code>offset</code> inclusive.
74      *
75      * @param input the input buffer.
76      * @param offset the offset in <code>input</code> where the input starts.
77      * @param len the number of bytes to process.
78      */

79     protected abstract void engineUpdate(byte[] input, int offset, int len);
80
81     /**
82      * Processes <code>input.remaining()</code> bytes in the ByteBuffer
83      * <code>input</code>, starting at <code>input.position()</code>.
84      * Upon return, the buffer's position will be equal to its limit;
85      * its limit will not have changed.
86      *
87      * <p>Subclasses should consider overriding this method if they can
88      * process ByteBuffers more efficiently than byte arrays.
89      *
90      * @param input the ByteBuffer
91      * @since 1.5
92      */

93     protected void engineUpdate(ByteBuffer input) { }
94
95     /**
96      * Completes the MAC computation and resets the MAC for further use,
97      * maintaining the secret key that the MAC was initialized with.
98      *
99      * @return the MAC result.
100      */

101     protected abstract byte[] engineDoFinal();
102
103     /**
104      * Resets the MAC for further use, maintaining the secret key that the
105      * MAC was initialized with.
106      */

107     protected abstract void engineReset();
108
109     /**
110      * Returns a clone if the implementation is cloneable.
111      *
112      * @return a clone if the implementation is cloneable.
113      *
114      * @exception CloneNotSupportedException if this is called
115      * on an implementation that does not support <code>Cloneable</code>.
116      */

117     public Object clone() throws CloneNotSupportedException { }
118 }
119
Popular Tags