001: package org.bouncycastle.crypto.modes;
002:
003: import org.bouncycastle.crypto.BlockCipher;
004: import org.bouncycastle.crypto.CipherParameters;
005: import org.bouncycastle.crypto.DataLengthException;
006: import org.bouncycastle.crypto.InvalidCipherTextException;
007:
008: /**
009: * A block cipher mode that includes authenticated encryption with a streaming mode and optional associated data.
010: * @see org.bouncycastle.crypto.params.AEADParameters
011: */
012: public interface AEADBlockCipher {
013: /**
014: * initialise the underlying cipher. Parameter can either be an AEADParameters or a ParametersWithIV object.
015: *
016: * @param forEncryption true if we are setting up for encryption, false otherwise.
017: * @param params the necessary parameters for the underlying cipher to be initialised.
018: * @exception IllegalArgumentException if the params argument is inappropriate.
019: */
020: public void init(boolean forEncryption, CipherParameters params)
021: throws IllegalArgumentException;
022:
023: /**
024: * Return the name of the algorithm.
025: *
026: * @return the algorithm name.
027: */
028: public String getAlgorithmName();
029:
030: /**
031: * return the cipher this object wraps.
032: *
033: * @return the cipher this object wraps.
034: */
035: public BlockCipher getUnderlyingCipher();
036:
037: /**
038: * encrypt/decrypt a single byte.
039: *
040: * @param in the byte to be processed.
041: * @param out the output buffer the processed byte goes into.
042: * @param outOff the offset into the output byte array the processed data starts at.
043: * @return the number of bytes written to out.
044: * @exception DataLengthException if the output buffer is too small.
045: */
046: public int processByte(byte in, byte[] out, int outOff)
047: throws DataLengthException;
048:
049: /**
050: * process a block of bytes from in putting the result into out.
051: *
052: * @param in the input byte array.
053: * @param inOff the offset into the in array where the data to be processed starts.
054: * @param len the number of bytes to be processed.
055: * @param out the output buffer the processed bytes go into.
056: * @param outOff the offset into the output byte array the processed data starts at.
057: * @return the number of bytes written to out.
058: * @exception DataLengthException if the output buffer is too small.
059: */
060: public int processBytes(byte[] in, int inOff, int len, byte[] out,
061: int outOff) throws DataLengthException;
062:
063: /**
064: * Finish the operation either appending or verifying the MAC at the end of the data.
065: *
066: * @param out space for any resulting output data.
067: * @param outOff offset into out to start copying the data at.
068: * @return number of bytes written into out.
069: * @throws IllegalStateException if the cipher is in an inappropriate state.
070: * @throws org.bouncycastle.crypto.InvalidCipherTextException if the MAC fails to match.
071: */
072: public int doFinal(byte[] out, int outOff)
073: throws IllegalStateException, InvalidCipherTextException;
074:
075: /**
076: * Return the value of the MAC associated with the last stream processed.
077: *
078: * @return MAC for plaintext data.
079: */
080: public byte[] getMac();
081:
082: /**
083: * return the size of the output buffer required for a processBytes
084: * an input of len bytes.
085: *
086: * @param len the length of the input.
087: * @return the space required to accommodate a call to processBytes
088: * with len bytes of input.
089: */
090: public int getUpdateOutputSize(int len);
091:
092: /**
093: * return the size of the output buffer required for a processBytes plus a
094: * doFinal with an input of len bytes.
095: *
096: * @param len the length of the input.
097: * @return the space required to accommodate a call to processBytes and doFinal
098: * with len bytes of input.
099: */
100: public int getOutputSize(int len);
101:
102: /**
103: * Reset the cipher. After resetting the cipher is in the same state
104: * as it was after the last init (if there was one).
105: */
106: public void reset();
107: }
|