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

## gnu.crypto.mode
Class BaseMode

    java.lang.Object
      |
      +--gnu.crypto.mode.BaseMode

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

Direct Known Subclasses:
  CBC, CFB, CTR, ECB, ICM, OFB

public abstract class BaseMode
extends java.lang.Object
implements IMode

A basic abstract class to facilitate implementing block cipher modes of operations.

Field Summary
`protected IBlockCipher` | `cipher` The underlying block cipher implementation.
`protected int` | `cipherBlockSize` The block size, in bytes, to operate the underlying block cipher in.
`protected byte[]` | `iv` The initialisation vector value.
`protected java.lang.Object` | `lock` The instance lock.
`protected int` | `modeBlockSize` The block size, in bytes, in which to operate the mode instance.
`protected java.lang.String` | `name` The canonical name prefix of this mode.
`protected int` | `state` The state indicator of this instance.

Fields inherited from interface gnu.crypto.mode.IMode
`DECRYPTION, ENCRYPTION, IV, MODE_BLOCK_SIZE, STATE`

Fields inherited from interface gnu.crypto.cipher.IBlockCipher
`CIPHER_BLOCK_SIZE, KEY_MATERIAL`

Constructor Summary
`protected` | `BaseMode(java.lang.String name, IBlockCipher underlyingCipher, int cipherBlockSize)` Trivial constructor for use by concrete subclasses.

Method Summary
`java.util.Iterator` | `blockSizes()` Returns an `Iterator` over the supported block sizes.
`abstract java.lang.Object` | `clone()` Returns a clone of this instance.
`int` | `currentBlockSize()` Returns the currently set block size for this instance.
`abstract void` | `decryptBlock(byte[] in, int i, byte[] out, int o)` Decrypts exactly one block of ciphertext.
`int` | `defaultBlockSize()` Returns the default value, in bytes, of the mode's block size.
`int` | `defaultKeySize()` Returns the default value, in bytes, of the underlying block cipher key size.
`abstract void` | `encryptBlock(byte[] in, int i, byte[] out, int o)` Encrypts exactly one block of plaintext.
`void` | `init(java.util.Map attributes)` Initialises the algorithm with designated attributes.
`java.util.Iterator` | `keySizes()` Returns an `Iterator` over the supported underlying block cipher key sizes.
`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).
`abstract void` | `setup()` The initialisation phase of the concrete mode implementation.
`abstract void` | `teardown()` The termination phase of the concrete mode implementation.
`void` | `update(byte[] in, int inOffset, byte[] out, int outOffset)` A convenience method.

Methods inherited from class java.lang.Object
`equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### name

    protected java.lang.String name

  The canonical name prefix of this mode.

### state

    protected int state

  The state indicator of this instance.

### cipher

    protected IBlockCipher cipher

  The underlying block cipher implementation.

### cipherBlockSize

    protected int cipherBlockSize

  The block size, in bytes, to operate the underlying block cipher in.

### modeBlockSize

    protected int modeBlockSize

  The block size, in bytes, in which to operate the mode instance.

### iv

    protected byte[] iv

  The initialisation vector value.

### lock

    protected java.lang.Object lock

  The instance lock.

Constructor Detail

### BaseMode

    protected BaseMode(java.lang.String name,
                       IBlockCipher underlyingCipher,
                       int cipherBlockSize)

  Trivial constructor for use by concrete subclasses.

Parameters:
  `name` - the canonical name prefix of this mode.
  `underlyingCipher` - the implementation of the underlying cipher.
  `cipherBlockSize` - the block size, in bytes, in which to operate the underlying cipher.

Method Detail

### update

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

  Description copied from interface: `IMode`

  A convenience method. Effectively invokes the `encryptBlock()` or `decryptBlock()` method depending on the operational state of the instance.

  Specified by:
    `update` in interface `IMode`
  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.

### name

    public java.lang.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()

  Returns the default value, in bytes, of the mode's block size. This value is part of the construction arguments passed to the Factory methods in `ModeFactory`. Unless changed by an invocation of any of the `init()` methods, a Mode instance would operate with the same block size as its underlying block cipher. As mentioned earlier, the block size of the underlying block cipher itself is specified in one of the method(s) available in the factory class.

  Specified by:
    `defaultBlockSize` in interface `IBlockCipher`
  Returns:
    the default value, in bytes, of the mode's block size.
  See Also:
    `ModeFactory`

### defaultKeySize

    public int defaultKeySize()

  Returns the default value, in bytes, of the underlying block cipher key size.

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

### blockSizes

    public java.util.Iterator blockSizes()

  Returns an `Iterator` over the supported block sizes. Each element returned by this object is an `Integer`.

  The default behaviour is to return an iterator with just one value, which is that currently configured for the underlying block cipher. Concrete implementations may override this behaviour to signal their ability to support other values.

  Specified by:
    `blockSizes` in interface `IBlockCipher`
  Returns:
    an `Iterator` over the supported block sizes.

### keySizes

    public java.util.Iterator keySizes()

  Returns an `Iterator` over the supported underlying block cipher key sizes. Each element returned by this object is an instance of `Integer`.

  Specified by:
    `keySizes` in interface `IBlockCipher`
  Returns:
    an `Iterator` over the supported key sizes.

### init

    public void init(java.util.Map attributes)
              throws java.security.InvalidKeyException,
                     java.lang.IllegalStateException

  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:
    `java.lang.IllegalStateException` - if the instance is already initialised.
    `java.security.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`

### 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`
  Returns:
    `true` if the implementation passes simple correctness tests. Returns `false` otherwise.

### 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`
  Returns:
    a clone copy of this instance.

### setup

    public abstract void setup()

  The initialisation phase of the concrete mode implementation.

### teardown

    public abstract void teardown()

  The termination phase of the concrete mode implementation.

### encryptBlock

    public abstract void encryptBlock(byte[] in,
                                      int i,
                                      byte[] out,
                                      int o)

  Description copied from interface: `IBlockCipher`

  Encrypts exactly one block of plaintext.

  Specified by:
    `encryptBlock` in interface `IBlockCipher`
  Parameters:
    `in` - the plaintext.
    `i` - index of `in` from which to start considering data.
    `out` - the ciphertext.
    `o` - index of `out` from which to store result.

### decryptBlock

    public abstract void decryptBlock(byte[] in,
                                      int i,
                                      byte[] out,
                                      int o)

  Description copied from interface: `IBlockCipher`

  Decrypts exactly one block of ciphertext.

  Specified by:
    `decryptBlock` in interface `IBlockCipher`
  Parameters:
    `in` - the plaintext.
    `i` - index of `in` from which to start considering data.
    `out` - the ciphertext.
    `o` - index of `out` from which to store result.

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

Copyright © 2001, 2002, 2003, 2004 Free Software Foundation, Inc.