Top Description Fields Constructors Methods
org.bouncycastle.crypto.engines

public Class CAST5Engine

extends Object
implements BlockCipher
Class Inheritance
All Implemented Interfaces
org.bouncycastle.crypto.BlockCipher
Known Direct Subclasses
org.bouncycastle.crypto.engines.CAST6Engine
Imports
org.bouncycastle.crypto.BlockCipher, .CipherParameters, .CryptoServicePurpose, .CryptoServicesRegistrar, .DataLengthException, .OutputLengthException, org.bouncycastle.crypto.constraints.DefaultServiceProperties, org.bouncycastle.crypto.params.KeyParameter

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

Modifier and TypeField and Description
private boolean
protected int[]
protected int[]
private int
private byte[]
protected static final int
protected static final int
protected static final int
private static final int[]
private static final int[]
private static final int[]
private static final int[]
private static final int[]
private static final int[]
private static final int[]
private static final int[]

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected final void
Bits32ToBytes(int in, byte[] b, int offset)

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

private int
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
the LH-32bits of the plaintext block
L0
,
int
the RH-32bits of the plaintext block
R0
,
int[] result)

Does the 16 rounds to encrypt the block.

protected int
decryptBlock(byte[]
The plaintext buffer
src
,
int
An offset into src
srcIndex
,
byte[]
The ciphertext buffer
dst
,
int
An offset into dst
dstIndex
)

Decrypt the given input starting at the given offset and place the result in the provided buffer starting at the given offset.

protected int
encryptBlock(byte[]
The plaintext buffer
src
,
int
An offset into src
srcIndex
,
byte[]
The ciphertext buffer
dst
,
int
An offset into dst
dstIndex
)

Encrypt the given input starting at the given offset and place the result in the provided buffer starting at the given offset.

protected final int
F1(int
the input to be processed
D
,
int
the mask to be used from Km[n]
Kmi
,
int
the rotation value to be used
Kri
)

The first of the three processing functions for the encryption and decryption.

protected final int
F2(int
the input to be processed
D
,
int
the mask to be used from Km[n]
Kmi
,
int
the rotation value to be used
Kri
)

The second of the three processing functions for the encryption and decryption.

protected final int
F3(int
the input to be processed
D
,
int
the mask to be used from Km[n]
Kmi
,
int
the rotation value to be used
Kri
)

The third of the three processing functions for the encryption and decryption.

public String
getAlgorithmName()

Implements org.bouncycastle.crypto.BlockCipher.getAlgorithmName.

Return the name of the algorithm the cipher implements.
public int
getBlockSize()

Implements org.bouncycastle.crypto.BlockCipher.getBlockSize.

Return the block size for this cipher (in bytes).
private CryptoServicePurpose
public void
init(boolean
whether or not we are for encryption.
encrypting
,
CipherParameters
the parameters required to set up the cipher.
params
)

Implements org.bouncycastle.crypto.BlockCipher.init.

initialise a CAST cipher.
protected final int
IntsTo32bits(int[] b, int i)

public int
processBlock(byte[]
the array containing the input data.
in
,
int
offset into the in array the data starts at.
inOff
,
byte[]
the array the output data will be copied into.
out
,
int
the offset into the out array the output will start at.
outOff
)

Implements org.bouncycastle.crypto.BlockCipher.processBlock.

Process one block of input from the array in and write it to the out array.
public void
reset()

Implements org.bouncycastle.crypto.BlockCipher.reset.

Reset the cipher.
protected void
setKey(byte[] key)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_encryptingback to summary
private boolean _encrypting
_Kmback to summary
protected int[] _Km
_Krback to summary
protected int[] _Kr
_roundsback to summary
private int _rounds
_workingKeyback to summary
private byte[] _workingKey
BLOCK_SIZEback to summary
protected static final int BLOCK_SIZE
MAX_ROUNDSback to summary
protected static final int MAX_ROUNDS
RED_ROUNDSback to summary
protected static final int RED_ROUNDS
S1back to summary
private static final int[] S1
S2back to summary
private static final int[] S2
S3back to summary
private static final int[] S3
S4back to summary
private static final int[] S4
S5back to summary
private static final int[] S5
S6back to summary
private static final int[] S6
S7back to summary
private static final int[] S7
S8back to summary
private static final int[] S8

Constructor Detail

CAST5Engineback to summary
public CAST5Engine()

Method Detail

Bits32ToBytesback to summary
protected final void Bits32ToBytes(int in, byte[] b, int offset)
Bits32ToIntsback to summary
protected final void Bits32ToInts(int in, int[] b, int offset)
bitsOfSecurityback to summary
private int bitsOfSecurity()
BytesTo32bitsback to summary
protected final int BytesTo32bits(byte[] b, int i)
CAST_Decipherback to summary
protected final void CAST_Decipher(int L16, int R16, int[] result)
CAST_Encipherback to summary
protected final void CAST_Encipher(int L0, int R0, int[] result)

Does the 16 rounds to encrypt the block.

Parameters
L0:int

the LH-32bits of the plaintext block

R0:int

the RH-32bits of the plaintext block

decryptBlockback to summary
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:byte[]

The plaintext buffer

srcIndex:int

An offset into src

dst:byte[]

The ciphertext buffer

dstIndex:int

An offset into dst

encryptBlockback to summary
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:byte[]

The plaintext buffer

srcIndex:int

An offset into src

dst:byte[]

The ciphertext buffer

dstIndex:int

An offset into dst

F1back to summary
protected final int F1(int D, int Kmi, int Kri)

The first of the three processing functions for the encryption and decryption.

Parameters
D:int

the input to be processed

Kmi:int

the mask to be used from Km[n]

Kri:int

the rotation value to be used

F2back to summary
protected final int F2(int D, int Kmi, int Kri)

The second of the three processing functions for the encryption and decryption.

Parameters
D:int

the input to be processed

Kmi:int

the mask to be used from Km[n]

Kri:int

the rotation value to be used

F3back to summary
protected final int F3(int D, int Kmi, int Kri)

The third of the three processing functions for the encryption and decryption.

Parameters
D:int

the input to be processed

Kmi:int

the mask to be used from Km[n]

Kri:int

the rotation value to be used

getAlgorithmNameback to summary
public String getAlgorithmName()

Implements org.bouncycastle.crypto.BlockCipher.getAlgorithmName.

Doc from org.bouncycastle.crypto.BlockCipher.getAlgorithmName.

Return the name of the algorithm the cipher implements.

Returns:String

the name of the algorithm the cipher implements.

getBlockSizeback to summary
public int getBlockSize()

Implements org.bouncycastle.crypto.BlockCipher.getBlockSize.

Doc from org.bouncycastle.crypto.BlockCipher.getBlockSize.

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

Returns:int

the block size for this cipher in bytes.

getPurposeback to summary
private CryptoServicePurpose getPurpose()
initback to summary
public void init(boolean encrypting, CipherParameters params)

Implements org.bouncycastle.crypto.BlockCipher.init.

initialise a CAST cipher.

Parameters
encrypting:boolean

whether or not we are for encryption.

params:CipherParameters

the parameters required to set up the cipher.

Exceptions
IllegalArgumentException:
if the params argument is inappropriate.
IntsTo32bitsback to summary
protected final int IntsTo32bits(int[] b, int i)
processBlockback to summary
public int processBlock(byte[] in, int inOff, byte[] out, int outOff)

Implements org.bouncycastle.crypto.BlockCipher.processBlock.

Doc from org.bouncycastle.crypto.BlockCipher.processBlock.

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

Parameters
in:byte[]

the array containing the input data.

inOff:int

offset into the in array the data starts at.

out:byte[]

the array the output data will be copied into.

outOff:int

the offset into the out array the output will start at.

Returns:int

the number of bytes processed and produced.

resetback to summary
public void reset()

Implements org.bouncycastle.crypto.BlockCipher.reset.

Doc from org.bouncycastle.crypto.BlockCipher.reset.

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

setKeyback to summary
protected void setKey(byte[] key)