tribble.crypto
Class SymmetricCipher

java.lang.Object
  extended bytribble.crypto.AbstractCipher
      extended bytribble.crypto.SymmetricCipher
Direct Known Subclasses:
AESCipher, NullCipher, ZoidfarbCipher

public abstract class SymmetricCipher
extends AbstractCipher

Abstract base class for primitive symmetric cipher (encryption) algorithms. Symmetric ciphers use the same secret key for both encryption and decryption (hence the term symmetric).

Classes that extend this base class implement fundamental symmetric block ciphers, which comprise the foundation upon which this package is built.

Since:
2005-07-05
Version:
$Revision: 1.2 $ $Date: 2005/07/09 14:41:20 $
Author:
David R. Tribble (david@tribble.com).

Copyright ©2005 by David R. Tribble, all rights reserved.
Permission is granted to freely use and distribute this source code provided that the original copyright and authorship notices remain intact.

See Also:
AsymmetricCipher, CipherSpi

Field Summary
protected  int m_blockLen
          Cipher block size (in bytes).
 
Fields inherited from class tribble.crypto.AbstractCipher
m_alg, m_decrypt, m_init, m_keyLen
 
Constructor Summary
protected SymmetricCipher(java.lang.String alg, int blockLen)
          Constructor.
 
Method Summary
protected abstract  void blockDecrypt(byte[] in, int inOff, byte[] out, int outOff)
          Decrypt a block of ciphertext.
protected abstract  void blockEncrypt(byte[] in, int inOff, byte[] out, int outOff)
          Encrypt a block of plaintext.
 int getBlockSize()
          Retrieve the block size of this cipher.
protected static void test(SymmetricCipher ciph, byte[] key, byte[] input)
          Test driver.
protected static void test(SymmetricCipher ciph, java.lang.String[] args)
          Test driver.
 
Methods inherited from class tribble.crypto.AbstractCipher
clear, finalize, getAlgorithm, getKeySize, getKeySizes, initialize
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_blockLen

protected int m_blockLen
Cipher block size (in bytes).

Constructor Detail

SymmetricCipher

protected SymmetricCipher(java.lang.String alg,
                          int blockLen)
Constructor.

Parameters:
alg - Cryptographic cipher algorithm name.
blockLen - Cipher block size (in bytes).
Since:
1.1, 2005-07-05
Method Detail

test

protected static void test(SymmetricCipher ciph,
                           java.lang.String[] args)
                    throws java.lang.Exception
Test driver. This convenience method is used by classes that extend this base class.

Usage java tribble.crypto.SomeCipher [args...]

Parameters:
ciph - Derived class cipher object to test.
Throws:
java.lang.Exception - Thrown if an error occurs in the encryption engine.
Since:
1.1, 2005-07-05

test

protected static void test(SymmetricCipher ciph,
                           byte[] key,
                           byte[] input)
                    throws java.lang.Exception
Test driver. This convenience method is used by classes that extend this base class.

Usage java tribble.crypto.SomeCipher

Parameters:
ciph - Derived class cipher object to test.
key - Symmetric key for the cipher.
input - Input test vector. This array should be exactly the same length as the cipher block size.
Throws:
java.lang.Exception - Thrown if an error occurs in the encryption engine.
Since:
1.1, 2003-04-05

getBlockSize

public int getBlockSize()
Retrieve the block size of this cipher.

Returns:
The block size of this cipher algorithm (in bytes).
Since:
1.1, 2005-07-05

blockEncrypt

protected abstract void blockEncrypt(byte[] in,
                                     int inOff,
                                     byte[] out,
                                     int outOff)
Encrypt a block of plaintext.

Specified by:
blockEncrypt in class AbstractCipher
Parameters:
in - Array containing a single block of plaintext bytes to encrypt. The length of the block is exactly equal to the cipher block size (m_blockLen).
inOff - Index of the first byte of the plaintext block within array in to encrypt.
out - Array that will be filled with the encrypted ciphertext block. The length of the block is exactly equal to the cipher block size (m_blockLen).
outOff - Index of the first byte of array out to fill with the encrypted ciphertext block.
Since:
1.1, 2005-07-05
See Also:
blockDecrypt()

blockDecrypt

protected abstract void blockDecrypt(byte[] in,
                                     int inOff,
                                     byte[] out,
                                     int outOff)
Decrypt a block of ciphertext.

Specified by:
blockDecrypt in class AbstractCipher
Parameters:
in - Array containing a single block of ciphertext bytes to decrypt. The length of the block is exactly equal to the cipher block size (m_blockLen).
inOff - Index of the first byte of the ciphertext block within array in to decrypt.
out - Array that will be filled with the decrypted plaintext block. The length of the block is exactly equal to the cipher block size (m_blockLen).
outOff - Index of the first byte of array out to fill with the decrypted plaintext block.
Since:
1.1, 2005-07-05
See Also:
blockEncrypt()