gnu.crypto.cipher

Class BaseCipher

Implemented Interfaces:
Cloneable, IBlockCipher, IBlockCipherSpi
Known Direct Subclasses:
Anubis, Blowfish, Cast5, DES, Khazad, NullCipher, Rijndael, Serpent, Square, TripleDES, Twofish

public abstract class BaseCipher
extends Object
implements IBlockCipher, IBlockCipherSpi

A basic abstract class to facilitate implementing symmetric key block ciphers.
Version:
$Revision: 1.11 $

Field Summary

protected int
currentBlockSize
The current block size, in bytes.
protected 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 Object
lock
The instance lock.
protected String
name
The canonical name prefix of the cipher.

Fields inherited from interface gnu.crypto.cipher.IBlockCipher

CIPHER_BLOCK_SIZE, KEY_MATERIAL

Constructor Summary

BaseCipher(String name, int defaultBlockSize, int defaultKeySize)
Trivial constructor for use by concrete subclasses.

Method Summary

abstract Object
clone()
int
currentBlockSize()
void
decryptBlock(byte[] in, int inOffset, byte[] out, int outOffset)
int
defaultBlockSize()
int
defaultKeySize()
void
encryptBlock(byte[] in, int inOffset, byte[] out, int outOffset)
void
init(Map attributes)
String
name()
void
reset()
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)

Field Details

currentBlockSize

protected int currentBlockSize
The current block size, in bytes.

currentKey

protected Object currentKey
The session key for this instance.

defaultBlockSize

protected int defaultBlockSize
The default block size, in bytes.

defaultKeySize

protected int defaultKeySize
The default key size, in bytes.

lock

protected Object lock
The instance lock.

name

protected String name
The canonical name prefix of the cipher.

Constructor Details

BaseCipher

protected BaseCipher(String name,
                     int defaultBlockSize,
                     int defaultKeySize)
Trivial constructor for use by concrete subclasses.
Parameters:
name - the canonical name prefix of this instance.
defaultBlockSize - the default block size in bytes.
defaultKeySize - the default key size in bytes.

Method Details

clone

public abstract 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 inOffset,
                         byte[] out,
                         int outOffset)
            throws IllegalStateException
Specified by:
decryptBlock in interface IBlockCipher

defaultBlockSize

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

defaultKeySize

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

encryptBlock

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

init

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

name

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

reset

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

selfTest

public 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).
Specified by:
selfTest in interface IBlockCipher
selfTest in interface IBlockCipherSpi
Returns:
true if the implementation passes simple correctness tests. Returns false otherwise.

testKat

protected boolean testKat(byte[] kb,
                          byte[] ct)

testKat

protected boolean testKat(byte[] kb,
                          byte[] ct,
                          byte[] pt)

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