For the latest news and information visit
The GNU Crypto project

gnu.crypto.cipher
Class BaseCipher

java.lang.Object
  extended by gnu.crypto.cipher.BaseCipher
All Implemented Interfaces:
IBlockCipher, IBlockCipherSpi, Cloneable
Direct Known Subclasses:
Anubis, Blowfish, Cast5, DES, Khazad, NullCipher, Rijndael, Serpent, Square, TripleDES, Twofish

public abstract class BaseCipher
extends Object
implements IBlockCipher, IBlockCipherSpi

A basic abstract class to facilitate implementing symmetric key block ciphers.

Version:
$Revision: 1.11 $

Field Summary
protected  int currentBlockSize
          The current block size, in bytes.
protected  Object currentKey
          The session key for this instance.
protected  int defaultBlockSize
          The default block size, in bytes.
protected  int defaultKeySize
          The default key size, in bytes.
protected  Object lock
          The instance lock.
protected  String name
          The canonical name prefix of the cipher.
 
Fields inherited from interface gnu.crypto.cipher.IBlockCipher
CIPHER_BLOCK_SIZE, KEY_MATERIAL
 
Constructor Summary
protected BaseCipher(String name, int defaultBlockSize, int defaultKeySize)
          Trivial constructor for use by concrete subclasses.
 
Method Summary
abstract  Object clone()
          Returns a clone of this instance.
 int currentBlockSize()
          Returns the currently set block size for this instance.
 void decryptBlock(byte[] in, int inOffset, byte[] out, int outOffset)
          Decrypts exactly one block of ciphertext.
 int defaultBlockSize()
          Returns the default value, in bytes, of the algorithm's block size.
 int defaultKeySize()
          Returns the default value, in bytes, of the algorithm's key size.
 void encryptBlock(byte[] in, int inOffset, byte[] out, int outOffset)
          Encrypts exactly one block of plaintext.
 void init(Map attributes)
          Initialises the algorithm with designated attributes.
 String name()
          Returns the canonical name of this instance.
 void reset()
          Resets the algorithm instance for re-initialisation and use with other characteristics.
 boolean selfTest()
          A correctness test that consists of basic symmetric encryption / decryption test(s) for all supported block and key sizes, as well as one (1) variable key Known Answer Test (KAT).
protected  boolean testKat(byte[] kb, byte[] ct)
           
protected  boolean testKat(byte[] kb, byte[] ct, byte[] pt)
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface gnu.crypto.cipher.IBlockCipher
blockSizes, keySizes
 
Methods inherited from interface gnu.crypto.cipher.IBlockCipherSpi
blockSizes, decrypt, encrypt, keySizes, makeKey
 

Field Detail

name

protected String name
The canonical name prefix of the cipher.


defaultBlockSize

protected int defaultBlockSize
The default block size, in bytes.


defaultKeySize

protected int defaultKeySize
The default key size, in bytes.


currentBlockSize

protected int currentBlockSize
The current block size, in bytes.


currentKey

protected transient Object currentKey
The session key for this instance.


lock

protected Object lock
The instance lock.

Constructor Detail

BaseCipher

protected BaseCipher(String name,
                     int defaultBlockSize,
                     int defaultKeySize)

Trivial constructor for use by concrete subclasses.

Parameters:
name - the canonical name prefix of this instance.
defaultBlockSize - the default block size in bytes.
defaultKeySize - the default key size in bytes.
Method Detail

clone

public abstract Object clone()
Description copied from interface: IBlockCipher

Returns a clone of this instance.

Specified by:
clone in interface IBlockCipher
Overrides:
clone in class Object
Returns:
a clone copy of this instance.

name

public String name()
Description copied from interface: IBlockCipher

Returns the canonical name of this instance.

Specified by:
name in interface IBlockCipher
Returns:
the canonical name of this instance.

defaultBlockSize

public int defaultBlockSize()
Description copied from interface: IBlockCipher

Returns the default value, in bytes, of the algorithm's block size.

Specified by:
defaultBlockSize in interface IBlockCipher
Returns:
the default value, in bytes, of the algorithm's block size.

defaultKeySize

public int defaultKeySize()
Description copied from interface: IBlockCipher

Returns the default value, in bytes, of the algorithm's key size.

Specified by:
defaultKeySize in interface IBlockCipher
Returns:
the default value, in bytes, of the algorithm's key size.

init

public void init(Map attributes)
          throws InvalidKeyException
Description copied from interface: IBlockCipher

Initialises the algorithm with designated attributes. Permissible names and values are described in the class documentation above.

Specified by:
init in interface IBlockCipher
Parameters:
attributes - a set of name-value pairs that describes the desired future behaviour of this instance.
Throws:
InvalidKeyException - if the key data is invalid.
See Also:
IBlockCipher.KEY_MATERIAL, IBlockCipher.CIPHER_BLOCK_SIZE

currentBlockSize

public int currentBlockSize()
Description copied from interface: IBlockCipher

Returns the currently set block size for this instance.

Specified by:
currentBlockSize in interface IBlockCipher
Returns:
the current block size for this instance.

reset

public void reset()
Description copied from interface: IBlockCipher

Resets the algorithm instance for re-initialisation and use with other characteristics. This method always succeeds.

Specified by:
reset in interface IBlockCipher

encryptBlock

public void encryptBlock(byte[] in,
                         int inOffset,
                         byte[] out,
                         int outOffset)
                  throws IllegalStateException
Description copied from interface: IBlockCipher

Encrypts exactly one block of plaintext.

Specified by:
encryptBlock in interface IBlockCipher
Parameters:
in - the plaintext.
inOffset - index of in from which to start considering data.
out - the ciphertext.
outOffset - index of out from which to store result.
Throws:
IllegalStateException - if the instance is not initialised.

decryptBlock

public void decryptBlock(byte[] in,
                         int inOffset,
                         byte[] out,
                         int outOffset)
                  throws IllegalStateException
Description copied from interface: IBlockCipher

Decrypts exactly one block of ciphertext.

Specified by:
decryptBlock in interface IBlockCipher
Parameters:
in - the plaintext.
inOffset - index of in from which to start considering data.
out - the ciphertext.
outOffset - index of out from which to store result.
Throws:
IllegalStateException - if the instance is not initialised.

selfTest

public boolean selfTest()
Description copied from interface: IBlockCipher

A correctness test that consists of basic symmetric encryption / decryption test(s) for all supported block and key sizes, as well as one (1) variable key Known Answer Test (KAT).

Specified by:
selfTest in interface IBlockCipher
Specified by:
selfTest in interface IBlockCipherSpi
Returns:
true if the implementation passes simple correctness tests. Returns false otherwise.

testKat

protected boolean testKat(byte[] kb,
                          byte[] ct)

testKat

protected boolean testKat(byte[] kb,
                          byte[] ct,
                          byte[] pt)

For the latest news and information visit
The GNU Crypto project

Copyright © 2001, 2002, 2003 Free Software Foundation, Inc. All Rights Reserved.