Overview | Package | Class | Tree | Deprecated | Index | Help
| For the latest news and information visit The GNU Crypto project
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## gnu.crypto.cipher
Class BaseCipher

    java.lang.Object
      |
      +--gnu.crypto.cipher.BaseCipher

All Implemented Interfaces:
  java.lang.Cloneable, IBlockCipher, IBlockCipherSpi

Direct Known Subclasses:
  Anubis, Khazad, NullCipher, Rijndael, Serpent, Square, Twofish

public abstract class BaseCipher
extends java.lang.Object
implements IBlockCipher, IBlockCipherSpi

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

Version:
  $Revision: 1.7 $

Field Summary
`protected int` | `currentBlockSize` The current block size, in bytes.
`protected java.lang.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 java.lang.Object` | `lock` The instance lock.
`protected java.lang.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(java.lang.String name, int defaultBlockSize, int defaultKeySize)` Trivial constructor for use by concrete subclasses.

Method Summary
`abstract java.lang.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(java.util.Map attributes)` Initialises the algorithm with designated attributes.
`java.lang.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)`

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 java.lang.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 java.lang.Object currentKey

  The session key for this instance.

### lock

    protected java.lang.Object lock

  The instance lock.

Constructor Detail

### BaseCipher

    protected BaseCipher(java.lang.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 java.lang.Object clone()

  Description copied from interface: `IBlockCipher`

  Returns a clone of this instance.

  Specified by:
    `clone` in interface `IBlockCipher`
  Overrides:
    `clone` in class `java.lang.Object`
  Following copied from interface: `gnu.crypto.cipher.IBlockCipher`
  Returns:
    a clone copy of this instance.

### name

    public java.lang.String name()

  Description copied from interface: `IBlockCipher`

  Returns the canonical name of this instance.

  Specified by:
    `name` in interface `IBlockCipher`
  Following copied from interface: `gnu.crypto.cipher.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`
  Following copied from interface: `gnu.crypto.cipher.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`
  Following copied from interface: `gnu.crypto.cipher.IBlockCipher`
  Returns:
    the default value, in bytes, of the algorithm's key size.

### init

    public void init(java.util.Map attributes)
              throws java.security.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`
  Following copied from interface: `gnu.crypto.cipher.IBlockCipher`
  Parameters:
    `attributes` - a set of name-value pairs that describes the desired future behaviour of this instance.
  Throws:
    `java.security.InvalidKeyException` - if the key data is invalid.
    `java.lang.IllegalStateException` - if the instance is already initialised.
  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`
  Following copied from interface: `gnu.crypto.cipher.IBlockCipher`
  Returns:
    the current block size for this instance.
  Throws:
    `java.lang.IllegalStateException` - if the instance is not initialised.

### 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 java.lang.IllegalStateException

  Description copied from interface: `IBlockCipher`

  Encrypts exactly one block of plaintext.

  Specified by:
    `encryptBlock` in interface `IBlockCipher`
  Following copied from interface: `gnu.crypto.cipher.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:
    `java.lang.IllegalStateException` - if the instance is not initialised.

### decryptBlock

    public void decryptBlock(byte[] in,
                             int inOffset,
                             byte[] out,
                             int outOffset)
                      throws java.lang.IllegalStateException

  Description copied from interface: `IBlockCipher`

  Decrypts exactly one block of ciphertext.

  Specified by:
    `decryptBlock` in interface `IBlockCipher`
  Following copied from interface: `gnu.crypto.cipher.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:
    `java.lang.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`
  Following copied from interface: `gnu.crypto.cipher.IBlockCipher`
  Returns:
    `true` if the implementation passes simple correctness tests. Returns `false` otherwise.

### testKat

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

Overview | Package | Class | Tree | Deprecated | Index | Help
| For the latest news and information visit The GNU Crypto project
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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