public class

CAST5Engine

extends Object
implements BlockCipher
java.lang.Object
   ↳ org.bouncycastle.crypto.engines.CAST5Engine
Known Direct Subclasses

Class Overview

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.

Summary

Constants
int BLOCK_SIZE
int M32
int MAX_ROUNDS
int RED_ROUNDS
Fields
protected static final int[] S1
protected static final int[] S2
protected static final int[] S3
protected static final int[] S4
protected static final int[] S5
protected static final int[] S6
protected static final int[] S7
protected static final int[] S8
protected int[] _Km
protected int[] _Kr
Public Constructors
CAST5Engine()
Public Methods
String getAlgorithmName()
Return the name of the algorithm the cipher implements.
int getBlockSize()
Return the block size for this cipher (in bytes).
void init(boolean encrypting, CipherParameters params)
initialise a CAST cipher.
int processBlock(byte[] in, int inOff, byte[] out, int outOff)
Process one block of input from the array in and write it to the out array.
void reset()
Reset the cipher.
Protected Methods
final void Bits32ToBytes(int in, byte[] b, int offset)
final void Bits32ToInts(int in, int[] b, int offset)
final int BytesTo32bits(byte[] b, int i)
final void CAST_Decipher(int L16, int R16, int[] result)
final void CAST_Encipher(int L0, int R0, int[] result)
Does the 16 rounds to encrypt the block.
final int F1(int D, int Kmi, int Kri)
The first of the three processing functions for the encryption and decryption.
final int F2(int D, int Kmi, int Kri)
The second of the three processing functions for the encryption and decryption.
final int F3(int D, int Kmi, int Kri)
The third of the three processing functions for the encryption and decryption.
final int IntsTo32bits(int[] b, int i)
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.
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.
void setKey(byte[] key)
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.bouncycastle.crypto.BlockCipher

Constants

protected static final int BLOCK_SIZE

Constant Value: 8 (0x00000008)

protected static final int M32

Constant Value: -1 (0xffffffff)

protected static final int MAX_ROUNDS

Constant Value: 16 (0x00000010)

protected static final int RED_ROUNDS

Constant Value: 12 (0x0000000c)

Fields

protected static final int[] S1

protected static final int[] S2

protected static final int[] S3

protected static final int[] S4

protected static final int[] S5

protected static final int[] S6

protected static final int[] S7

protected static final int[] S8

protected int[] _Km

protected int[] _Kr

Public Constructors

public CAST5Engine ()

Public Methods

public String getAlgorithmName ()

Return the name of the algorithm the cipher implements.

Returns
  • the name of the algorithm the cipher implements.

public int getBlockSize ()

Return the block size for this cipher (in bytes).

Returns
  • the block size for this cipher in bytes.

public void init (boolean encrypting, CipherParameters params)

initialise a CAST cipher.

Parameters
encrypting whether or not we are for encryption.
params the parameters required to set up the cipher.
Throws
IllegalArgumentException if the params argument is inappropriate.

public int processBlock (byte[] in, int inOff, byte[] out, int outOff)

Process one block of input from the array in and write it to the out array.

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.

public void reset ()

Reset the cipher. After resetting the cipher is in the same state as it was after the last init (if there was one).

Protected Methods

protected final void Bits32ToBytes (int in, byte[] b, int offset)

protected final void Bits32ToInts (int in, int[] b, int offset)

protected final int BytesTo32bits (byte[] b, int i)

protected final void CAST_Decipher (int L16, int R16, int[] result)

protected 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

protected 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

protected 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

protected 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

protected final int IntsTo32bits (int[] b, int i)

protected 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

protected 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

protected void setKey (byte[] key)