gnu.crypto.mode

Class BaseMode

Implemented Interfaces:
Cloneable, IBlockCipher, IMode
Known Direct 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.

Version:
$Revision: 1.5 $

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 Object
lock
The instance lock.
protected int
modeBlockSize
The block size, in bytes, in which to operate the mode instance.
protected String
name
The canonical name prefix of this mode.
protected int
state
The state indicator of this instance.

Fields inherited from interface gnu.crypto.cipher.IBlockCipher

CIPHER_BLOCK_SIZE, KEY_MATERIAL

Fields inherited from interface gnu.crypto.mode.IMode

DECRYPTION, ENCRYPTION, IV, MODE_BLOCK_SIZE, STATE

Constructor Summary

BaseMode(String name, IBlockCipher underlyingCipher, int cipherBlockSize)
Trivial constructor for use by concrete subclasses.

Method Summary

Iterator
blockSizes()
Returns an Iterator over the supported block sizes.
Object
clone()
int
currentBlockSize()
void
decryptBlock(byte[] in, int i, byte[] out, int o)
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.
void
encryptBlock(byte[] in, int i, byte[] out, int o)
void
init(Map attributes)
Iterator
keySizes()
Returns an Iterator over the supported underlying block cipher key sizes.
String
name()
void
reset()
boolean
selfTest()
void
setup()
The initialisation phase of the concrete mode implementation.
void
teardown()
The termination phase of the concrete mode implementation.
void
update(byte[] in, int inOffset, byte[] out, int outOffset)

Field Details

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.


iv

protected byte[] iv
The initialisation vector value.


lock

protected Object lock
The instance lock.


modeBlockSize

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


name

protected String name
The canonical name prefix of this mode.


state

protected int state
The state indicator of this instance.

Constructor Details

BaseMode

protected BaseMode(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 Details

blockSizes

public 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.


clone

public Object clone()
Specified by:
clone in interface IBlockCipher


currentBlockSize

public int currentBlockSize()
Specified by:
currentBlockSize in interface IBlockCipher


decryptBlock

public void decryptBlock(byte[] in,
                         int i,
                         byte[] out,
                         int o)
Specified by:
decryptBlock in interface IBlockCipher


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.


encryptBlock

public void encryptBlock(byte[] in,
                         int i,
                         byte[] out,
                         int o)
Specified by:
encryptBlock in interface IBlockCipher


init

public void init(Map attributes)
            throws InvalidKeyException,
                   IllegalStateException
Specified by:
init in interface IBlockCipher


keySizes

public 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.


name

public String name()
Specified by:
name in interface IBlockCipher


reset

public void reset()
Specified by:
reset in interface IBlockCipher


selfTest

public boolean selfTest()
Specified by:
selfTest in interface IBlockCipher


setup

public void setup()
The initialisation phase of the concrete mode implementation.


teardown

public void teardown()
The termination phase of the concrete mode implementation.


update

public void update(byte[] in,
                   int inOffset,
                   byte[] out,
                   int outOffset)
            throws IllegalStateException
Specified by:
update in interface IMode


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