|
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 |
java.lang.Object gnu.crypto.mode.BaseMode
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 |
protected java.lang.String name
protected int state
protected IBlockCipher cipher
protected int cipherBlockSize
protected int modeBlockSize
protected byte[] iv
protected java.lang.Object lock
Constructor Detail |
protected BaseMode(java.lang.String name, IBlockCipher underlyingCipher, int cipherBlockSize)
Trivial constructor for use by concrete subclasses.
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 |
public void update(byte[] in, int inOffset, byte[] out, int outOffset) throws java.lang.IllegalStateException
IMode
A convenience method. Effectively invokes the encryptBlock()
or decryptBlock()
method depending on the operational state
of the instance.
update
in interface IMode
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.
java.lang.IllegalStateException
- if the instance is not initialised.public java.lang.String name()
IBlockCipher
Returns the canonical name of this instance.
name
in interface IBlockCipher
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.
defaultBlockSize
in interface IBlockCipher
ModeFactory
public int defaultKeySize()
Returns the default value, in bytes, of the underlying block cipher key size.
defaultKeySize
in interface IBlockCipher
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.
blockSizes
in interface IBlockCipher
Iterator
over the supported block sizes.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
.
keySizes
in interface IBlockCipher
Iterator
over the supported key sizes.public void init(java.util.Map attributes) throws java.security.InvalidKeyException, java.lang.IllegalStateException
IBlockCipher
Initialises the algorithm with designated attributes. Permissible names and values are described in the class documentation above.
init
in interface IBlockCipher
attributes
- a set of name-value pairs that describes the desired
future behaviour of this instance.
java.security.InvalidKeyException
- if the key data is invalid.
java.lang.IllegalStateException
- if the instance is already initialised.IBlockCipher.KEY_MATERIAL
,
IBlockCipher.CIPHER_BLOCK_SIZE
public int currentBlockSize()
IBlockCipher
Returns the currently set block size for this instance.
currentBlockSize
in interface IBlockCipher
public void reset()
IBlockCipher
Resets the algorithm instance for re-initialisation and use with other characteristics. This method always succeeds.
reset
in interface IBlockCipher
public boolean selfTest()
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).
selfTest
in interface IBlockCipher
true
if the implementation passes simple
correctness tests. Returns false
otherwise.public abstract java.lang.Object clone()
IBlockCipher
Returns a clone of this instance.
clone
in interface IBlockCipher
public abstract void setup()
public abstract void teardown()
public abstract void encryptBlock(byte[] in, int i, byte[] out, int o)
IBlockCipher
Encrypts exactly one block of plaintext.
encryptBlock
in interface IBlockCipher
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.public abstract void decryptBlock(byte[] in, int i, byte[] out, int o)
IBlockCipher
Decrypts exactly one block of ciphertext.
decryptBlock
in interface IBlockCipher
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.
|
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 |