org.bouncycastle.crypto.engines

Class CAST5Engine

public class CAST5Engine extends 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 Summary
protected static intBLOCK_SIZE
protected static intM32
protected static intMAX_ROUNDS
protected static intRED_ROUNDS
protected static int[]S1
protected static int[]S2
protected static int[]S3
protected static int[]S4
protected static int[]S5
protected static int[]S6
protected static int[]S7
protected static int[]S8
protected int[]_Km
protected int[]_Kr
Constructor Summary
CAST5Engine()
Method Summary
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.
StringgetAlgorithmName()
intgetBlockSize()
voidinit(boolean encrypting, CipherParameters params)
initialise a CAST cipher.
protected intIntsTo32bits(int[] b, int i)
intprocessBlock(byte[] in, int inOff, byte[] out, int outOff)
voidreset()
protected voidsetKey(byte[] key)

Field Detail

BLOCK_SIZE

protected static final int BLOCK_SIZE

M32

protected static final int M32

MAX_ROUNDS

protected static final int MAX_ROUNDS

RED_ROUNDS

protected static final int RED_ROUNDS

S1

protected static final int[] S1

S2

protected static final int[] S2

S3

protected static final int[] S3

S4

protected static final int[] S4

S5

protected static final int[] S5

S6

protected static final int[] S6

S7

protected static final int[] S7

S8

protected static final int[] S8

_Km

protected int[] _Km

_Kr

protected int[] _Kr

Constructor Detail

CAST5Engine

public CAST5Engine()

Method Detail

Bits32ToBytes

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

Bits32ToInts

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

BytesTo32bits

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

CAST_Decipher

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

CAST_Encipher

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

decryptBlock

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

encryptBlock

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

F1

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

F2

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

F3

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

getAlgorithmName

public String getAlgorithmName()

getBlockSize

public int getBlockSize()

init

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.

IntsTo32bits

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

processBlock

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

reset

public void reset()

setKey

protected void setKey(byte[] key)