cryptix.provider.cipher

Class CAST5

Implemented Interfaces:
Parameterized, SymmetricCipher

public final class CAST5
extends Cipher
implements SymmetricCipher

A subclass of Cipher to implement the CAST5 (a.k.a. CAST-128) algorithm in Java, as per RFC 2144 dated May 1997.

In this RFC, Carlisle Adams (the CA in CAST, ST standing for Stafford Tavares) describes CAST5 as:

"...a DES-like Substitution-Permutation Network (SPN) cryptosystem which appears to have good resistance to differential cryptanalysis, linear cryptanalysis, and related-key cryptanalysis. This cipher also possesses a number of other desirable cryptographic properties, including avalanche, Strict Avalanche Criterion (SAC), Bit Independence Criterion (BIC), no complementation property, and an absence of weak and semi-weak keys."

CAST5 is a symmetric block cipher with a block-size of 8 bytes and a variable key-size of up to 128 bits. Its authors and their employer (Entrust Technologies, a Nortel majority-owned company) made it available worldwide on a royalty-free basis for commercial and non-commercial uses.

The CAST5 encryption algorithm has been designed to allow a key size that can vary from 40 bits to 128 bits, in 8-bit increments (that is, the allowable key sizes are 40, 48, 56, 64, ..., 112, 120, and 128 bits. For variable keysize operation, the specification is as follows:

  1. For key sizes up to and including 80 bits (i.e., 40, 48, 56, 64, 72, and 80 bits), the algorithm is exactly as specified but uses 12 rounds instead of 16;
  2. For key sizes greater than 80 bits, the algorithm uses the full 16 rounds;
  3. For key sizes less than 128 bits, the key is padded with zero bytes (in the rightmost, or least significant, positions) out to 128 bits (since the CAST5 key schedule assumes an input key of 128 bits).

References:

  1. Carlisle Adams, RFC 2144, May 1997.

Copyright © 1997 Systemics Ltd on behalf of the Cryptix Development Team.
All rights reserved.

$Revision: 1.6 $

Author:
Raif S. Naffah

Since:
Cryptix 2.2.2

Field Summary

Fields inherited from class xjava.security.Cipher

DECRYPT, ENCRYPT, UNINITIALIZED

Fields inherited from class xjava.security.IJCE_Traceable

tracing

Constructor Summary

CAST5()
Constructs a CAST5 cipher object, in the UNINITIALIZED state.

Method Summary

Object
clone()
Always throws a CloneNotSupportedException (cloning of ciphers is not supported for security reasons).
protected int
engineBlockSize()
SPI: Returns the length of an input block, in bytes.
protected void
engineInitDecrypt(Key key)
SPI: Initializes this cipher for decryption, using the specified key.
protected void
engineInitEncrypt(Key key)
SPI: Initializes this cipher for encryption, using the specified key.
protected int
engineUpdate(byte[] in, int inOffset, int inLen, byte[] out, int outOffset)
SPI: This is the main engine method for updating data.
protected void
finalize()
Cleans up resources used by this instance, if necessary.
static LinkStatus
getLinkStatus()
Gets an object representing the native linking status of this class.

Methods inherited from class xjava.security.Cipher

blockSize, clone, crypt, crypt, crypt, doFinal, doFinal, doFinal, doFinal, engineBlockSize, engineCiphertextBlockSize, engineCrypt, engineGetParameter, engineInBufferSize, engineInitDecrypt, engineInitEncrypt, engineOutBufferSize, enginePlaintextBlockSize, engineSetPaddingScheme, engineSetParameter, engineUpdate, getAlgorithm, getAlgorithms, getAlgorithms, getCiphertextBlockSize, getInputBlockSize, getInstance, getInstance, getInstance, getMode, getOutputBlockSize, getPadding, getPaddingScheme, getParameter, getPlaintextBlockSize, getProvider, getState, inBufferSize, inBufferSizeFinal, initDecrypt, initEncrypt, isPaddingBlockCipher, outBufferSize, outBufferSizeFinal, setParameter, toString, update, update, update, update

Methods inherited from class xjava.security.IJCE_Traceable

disableTracing, enableTracing, traceMethod, traceResult, traceResult, traceVoidMethod

Constructor Details

CAST5

public CAST5()
Constructs a CAST5 cipher object, in the UNINITIALIZED state. This calls the Cipher constructor with implBuffering false, implPadding false and the provider set to "Cryptix".

See Also:
java.security.Cipher.UNINITIALIZED

Method Details

clone

public final Object clone()
            throws CloneNotSupportedException
Always throws a CloneNotSupportedException (cloning of ciphers is not supported for security reasons).
Overrides:
clone in interface Cipher


engineBlockSize

protected int engineBlockSize()
SPI: Returns the length of an input block, in bytes.
Overrides:
engineBlockSize in interface Cipher

Returns:
the length in bytes of an input block for this cipher.


engineInitDecrypt

protected void engineInitDecrypt(Key key)
            throws KeyException
SPI: Initializes this cipher for decryption, using the specified key.
Overrides:
engineInitDecrypt in interface Cipher

Parameters:
key - the key to use for decryption.


engineInitEncrypt

protected void engineInitEncrypt(Key key)
            throws KeyException
SPI: Initializes this cipher for encryption, using the specified key.
Overrides:
engineInitEncrypt in interface Cipher

Parameters:
key - the key to use for encryption.


engineUpdate

protected int engineUpdate(byte[] in,
                           int inOffset,
                           int inLen,
                           byte[] out,
                           int outOffset)
SPI: This is the main engine method for updating data.

in and out may be the same array, and the input and output regions may overlap.

Overrides:
engineUpdate in interface Cipher

Parameters:
in - the input data.
inOffset - the offset into in specifying where the data starts.
inLen - the length of the subarray.
out - the output array.
outOffset - the offset indicating where to start writing into the out array.

Returns:
the number of bytes written.


finalize

protected final void finalize()
Cleans up resources used by this instance, if necessary.


getLinkStatus

public static LinkStatus getLinkStatus()
Gets an object representing the native linking status of this class.