Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

gnu.javax.crypto.mode
Class BaseMode  view BaseMode download BaseMode.java

java.lang.Object
  extended bygnu.javax.crypto.mode.BaseMode
All Implemented Interfaces:
java.lang.Cloneable, gnu.javax.crypto.cipher.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  gnu.javax.crypto.cipher.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.javax.crypto.mode.IMode
DECRYPTION, ENCRYPTION, IV, MODE_BLOCK_SIZE, STATE
 
Fields inherited from interface gnu.javax.crypto.cipher.IBlockCipher
CIPHER_BLOCK_SIZE, KEY_MATERIAL
 
Constructor Summary
protected BaseMode(java.lang.String name, gnu.javax.crypto.cipher.IBlockCipher underlyingCipher, int cipherBlockSize)
          Trivial constructor for use by concrete subclasses.
 
Method Summary
 java.util.Iterator blockSizes()
          Returns an java.util.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 java.util.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.
private  boolean testSymmetry(int ks, int bs)
           
 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 gnu.javax.crypto.cipher.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,
                   gnu.javax.crypto.cipher.IBlockCipher underlyingCipher,
                   int cipherBlockSize)

Trivial constructor for use by concrete subclasses.

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

name

public java.lang.String name()
Description copied from interface: gnu.javax.crypto.cipher.IBlockCipher

Returns the canonical name of this instance.

Specified by:
name in interface gnu.javax.crypto.cipher.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 gnu.javax.crypto.cipher.IBlockCipher

defaultKeySize

public int defaultKeySize()

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

Specified by:
defaultKeySize in interface gnu.javax.crypto.cipher.IBlockCipher

blockSizes

public java.util.Iterator blockSizes()

Returns an java.util.Iterator over the supported block sizes. Each element returned by this object is an java.lang.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 gnu.javax.crypto.cipher.IBlockCipher

keySizes

public java.util.Iterator keySizes()

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

Specified by:
keySizes in interface gnu.javax.crypto.cipher.IBlockCipher

init

public void init(java.util.Map attributes)
          throws java.security.InvalidKeyException,
                 java.lang.IllegalStateException
Description copied from interface: gnu.javax.crypto.cipher.IBlockCipher

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

Specified by:
init in interface gnu.javax.crypto.cipher.IBlockCipher

currentBlockSize

public int currentBlockSize()
Description copied from interface: gnu.javax.crypto.cipher.IBlockCipher

Returns the currently set block size for this instance.

Specified by:
currentBlockSize in interface gnu.javax.crypto.cipher.IBlockCipher

reset

public void reset()
Description copied from interface: gnu.javax.crypto.cipher.IBlockCipher

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

Specified by:
reset in interface gnu.javax.crypto.cipher.IBlockCipher

selfTest

public boolean selfTest()
Description copied from interface: gnu.javax.crypto.cipher.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 gnu.javax.crypto.cipher.IBlockCipher

clone

public abstract java.lang.Object clone()
Description copied from interface: gnu.javax.crypto.cipher.IBlockCipher

Returns a clone of this instance.

Specified by:
clone in interface gnu.javax.crypto.cipher.IBlockCipher

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: gnu.javax.crypto.cipher.IBlockCipher

Encrypts exactly one block of plaintext.

Specified by:
encryptBlock in interface gnu.javax.crypto.cipher.IBlockCipher

decryptBlock

public abstract void decryptBlock(byte[] in,
                                  int i,
                                  byte[] out,
                                  int o)
Description copied from interface: gnu.javax.crypto.cipher.IBlockCipher

Decrypts exactly one block of ciphertext.

Specified by:
decryptBlock in interface gnu.javax.crypto.cipher.IBlockCipher

testSymmetry

private boolean testSymmetry(int ks,
                             int bs)