|
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.cipher.BaseCipher
A basic abstract class to facilitate implementing symmetric key block ciphers.
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 | |
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. |
void |
decrypt(byte[] in,
int inOffset,
byte[] out,
int outOffset,
java.lang.Object k,
int bs)
Decrypts exactly one block of ciphertext. |
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 |
encrypt(byte[] in,
int inOffset,
byte[] out,
int outOffset,
java.lang.Object k,
int bs)
Encrypts exactly one block of plaintext. |
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.util.Iterator |
keySizes()
Returns an Iterator over the supported key sizes.
|
java.lang.Object |
makeKey(byte[] k,
int bs)
Expands a user-supplied key material into a session key for a designated block size. |
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)
|
protected boolean |
testKat(byte[] kb,
byte[] ct,
byte[] pt)
|
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 |
Field Detail |
protected java.lang.String name
protected int defaultBlockSize
protected int defaultKeySize
protected int currentBlockSize
protected transient java.lang.Object currentKey
protected java.lang.Object lock
Constructor Detail |
protected BaseCipher(java.lang.String name, int defaultBlockSize, int defaultKeySize)
Trivial constructor for use by concrete subclasses.
name
- the canonical name prefix of this instance.defaultBlockSize
- the default block size in bytes.defaultKeySize
- the default key size in bytes.Method Detail |
public abstract java.lang.Object clone()
IBlockCipher
Returns a clone of this instance.
clone
in interface IBlockCipher
public java.lang.String name()
IBlockCipher
Returns the canonical name of this instance.
name
in interface IBlockCipher
public int defaultBlockSize()
IBlockCipher
Returns the default value, in bytes, of the algorithm's block size.
defaultBlockSize
in interface IBlockCipher
public int defaultKeySize()
IBlockCipher
Returns the default value, in bytes, of the algorithm's key size.
defaultKeySize
in interface IBlockCipher
public void init(java.util.Map attributes) throws java.security.InvalidKeyException
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.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 void encryptBlock(byte[] in, int inOffset, byte[] out, int outOffset) throws java.lang.IllegalStateException
IBlockCipher
Encrypts exactly one block of plaintext.
encryptBlock
in interface IBlockCipher
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 void decryptBlock(byte[] in, int inOffset, byte[] out, int outOffset) throws java.lang.IllegalStateException
IBlockCipher
Decrypts exactly one block of ciphertext.
decryptBlock
in interface IBlockCipher
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 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.protected boolean testKat(byte[] kb, byte[] ct)
protected boolean testKat(byte[] kb, byte[] ct, byte[] pt)
public java.util.Iterator blockSizes()
Returns an Iterator
over the supported block sizes.
Each element returned by this object is a Integer
.
Iterator
over the supported block sizes.public java.util.Iterator keySizes()
Returns an Iterator
over the supported key sizes.
Each element returned by this object is a Integer
.
Iterator
over the supported key sizes.public java.lang.Object makeKey(byte[] k, int bs) throws java.security.InvalidKeyException
Expands a user-supplied key material into a session key for a designated block size.
k
- the user-supplied key material.bs
- the desired block size in bytes.
java.lang.IllegalArgumentException
- if the block size is invalid.
java.security.InvalidKeyException
- if the key data is invalid.public void encrypt(byte[] in, int inOffset, byte[] out, int outOffset, java.lang.Object k, int bs)
Encrypts exactly one block of plaintext.
in
- the plaintext.inOffset
- index of in
from which to start considering
data.out
- the ciphertext.outOffset
- index of out
from which to store the result.k
- the session key to use.bs
- the block size to use.
java.lang.IllegalArgumentException
- if the block size is invalid.
java.lang.ArrayIndexOutOfBoundsException
- if there is not enough room in
either the plaintext or ciphertext buffers.public void decrypt(byte[] in, int inOffset, byte[] out, int outOffset, java.lang.Object k, int bs)
Decrypts exactly one block of ciphertext.
in
- the ciphertext.inOffset
- index of in
from which to start considering
data.out
- the plaintext.outOffset
- index of out
from which to store the result.k
- the session key to use.bs
- the block size to use.
java.lang.IllegalArgumentException
- if the block size is invalid.
java.lang.ArrayIndexOutOfBoundsException
- if there is not enough room in
either the plaintext or ciphertext buffers.
|
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 |