Package org.bouncycastle.crypto.engines
Class CAST5Engine
- java.lang.Object
- 
- org.bouncycastle.crypto.engines.CAST5Engine
 
- 
- All Implemented Interfaces:
- BlockCipher
 - Direct Known Subclasses:
- CAST6Engine
 
 public class CAST5Engine extends java.lang.Object implements BlockCipher A class that provides CAST key encryption operations, such as encoding data and generating keys. All the algorithms herein are from the Internet RFC's RFC2144 - CAST5 (64bit block, 40-128bit key) RFC2612 - CAST6 (128bit block, 128-256bit key) and implement a simplified cryptography interface.
- 
- 
Field SummaryFields Modifier and Type Field Description protected int[]_Kmprotected int[]_Krprotected static intBLOCK_SIZEprotected static intMAX_ROUNDSprotected static intRED_ROUNDS
 - 
Constructor SummaryConstructors Constructor Description CAST5Engine()
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidBits32ToBytes(int in, byte[] b, int offset)protected voidBits32ToInts(int in, int[] b, int offset)protected intBytesTo32bits(byte[] b, int i)protected voidCAST_Decipher(int L16, int R16, int[] result)protected voidCAST_Encipher(int L0, int R0, int[] result)Does the 16 rounds to encrypt the block.protected intdecryptBlock(byte[] src, int srcIndex, byte[] dst, int dstIndex)Decrypt the given input starting at the given offset and place the result in the provided buffer starting at the given offset.protected intencryptBlock(byte[] src, int srcIndex, byte[] dst, int dstIndex)Encrypt the given input starting at the given offset and place the result in the provided buffer starting at the given offset.protected intF1(int D, int Kmi, int Kri)The first of the three processing functions for the encryption and decryption.protected intF2(int D, int Kmi, int Kri)The second of the three processing functions for the encryption and decryption.protected intF3(int D, int Kmi, int Kri)The third of the three processing functions for the encryption and decryption.java.lang.StringgetAlgorithmName()Return the name of the algorithm the cipher implements.intgetBlockSize()Return the block size for this cipher (in bytes).voidinit(boolean encrypting, CipherParameters params)initialise a CAST cipher.protected intIntsTo32bits(int[] b, int i)intprocessBlock(byte[] in, int inOff, byte[] out, int outOff)Process one block of input from the array in and write it to the out array.voidreset()Reset the cipher.protected voidsetKey(byte[] key)
 
- 
- 
- 
Field Detail- 
MAX_ROUNDSprotected static final int MAX_ROUNDS - See Also:
- Constant Field Values
 
 - 
RED_ROUNDSprotected static final int RED_ROUNDS - See Also:
- Constant Field Values
 
 - 
BLOCK_SIZEprotected static final int BLOCK_SIZE - See Also:
- Constant Field Values
 
 - 
_Krprotected int[] _Kr 
 - 
_Kmprotected int[] _Km 
 
- 
 - 
Method Detail- 
initpublic void init(boolean encrypting, CipherParameters params)initialise a CAST cipher.- Specified by:
- initin interface- BlockCipher
- Parameters:
- encrypting- whether or not we are for encryption.
- params- the parameters required to set up the cipher.
- Throws:
- java.lang.IllegalArgumentException- if the params argument is inappropriate.
 
 - 
getAlgorithmNamepublic java.lang.String getAlgorithmName() Description copied from interface:BlockCipherReturn the name of the algorithm the cipher implements.- Specified by:
- getAlgorithmNamein interface- BlockCipher
- Returns:
- the name of the algorithm the cipher implements.
 
 - 
processBlockpublic int processBlock(byte[] in, int inOff, byte[] out, int outOff)Description copied from interface:BlockCipherProcess one block of input from the array in and write it to the out array.- Specified by:
- processBlockin interface- BlockCipher
- Parameters:
- in- the array containing the input data.
- inOff- offset into the in array the data starts at.
- out- the array the output data will be copied into.
- outOff- the offset into the out array the output will start at.
- Returns:
- the number of bytes processed and produced.
 
 - 
resetpublic void reset() Description copied from interface:BlockCipherReset the cipher. After resetting the cipher is in the same state as it was after the last init (if there was one).- Specified by:
- resetin interface- BlockCipher
 
 - 
getBlockSizepublic int getBlockSize() Description copied from interface:BlockCipherReturn the block size for this cipher (in bytes).- Specified by:
- getBlockSizein interface- BlockCipher
- Returns:
- the block size for this cipher in bytes.
 
 - 
setKeyprotected void setKey(byte[] key) 
 - 
encryptBlockprotected int encryptBlock(byte[] src, int srcIndex, byte[] dst, int dstIndex)Encrypt the given input starting at the given offset and place the result in the provided buffer starting at the given offset.- Parameters:
- src- The plaintext buffer
- srcIndex- An offset into src
- dst- The ciphertext buffer
- dstIndex- An offset into dst
 
 - 
decryptBlockprotected int decryptBlock(byte[] src, int srcIndex, byte[] dst, int dstIndex)Decrypt the given input starting at the given offset and place the result in the provided buffer starting at the given offset.- Parameters:
- src- The plaintext buffer
- srcIndex- An offset into src
- dst- The ciphertext buffer
- dstIndex- An offset into dst
 
 - 
F1protected final int F1(int D, int Kmi, int Kri)The first of the three processing functions for the encryption and decryption.- Parameters:
- D- the input to be processed
- Kmi- the mask to be used from Km[n]
- Kri- the rotation value to be used
 
 - 
F2protected final int F2(int D, int Kmi, int Kri)The second of the three processing functions for the encryption and decryption.- Parameters:
- D- the input to be processed
- Kmi- the mask to be used from Km[n]
- Kri- the rotation value to be used
 
 - 
F3protected final int F3(int D, int Kmi, int Kri)The third of the three processing functions for the encryption and decryption.- Parameters:
- D- the input to be processed
- Kmi- the mask to be used from Km[n]
- Kri- the rotation value to be used
 
 - 
CAST_Encipherprotected final void CAST_Encipher(int L0, int R0, int[] result)Does the 16 rounds to encrypt the block.- Parameters:
- L0- the LH-32bits of the plaintext block
- R0- the RH-32bits of the plaintext block
 
 - 
CAST_Decipherprotected final void CAST_Decipher(int L16, int R16, int[] result)
 - 
Bits32ToIntsprotected final void Bits32ToInts(int in, int[] b, int offset)
 - 
IntsTo32bitsprotected final int IntsTo32bits(int[] b, int i)
 - 
Bits32ToBytesprotected final void Bits32ToBytes(int in, byte[] b, int offset)
 - 
BytesTo32bitsprotected final int BytesTo32bits(byte[] b, int i)
 
- 
 
-