de.flexiprovider.core.desede
Class DESede

java.lang.Object
  |
  +--javax.crypto.CipherSpi
        |
        +--de.flexiprovider.api.Cipher
              |
              +--de.flexiprovider.api.BlockCipher
                    |
                    +--de.flexiprovider.core.desede.DESede
Direct Known Subclasses:
DESede.DESede_CBC

public class DESede
extends BlockCipher

This class implements the TripleDES (DESede) block cipher. The implementation conforms to the FIPS 46-3 standard.

Note that the single DES algorithm can be emulated by TripleDES by concatenating the same key three times.

Author:
Norbert Trummel, Sylvain Franke, Torsten Ehli, Oliver Seiler

Inner Class Summary
static class DESede.DESede_CBC
          DESede_CBC
 
Field Summary
static java.lang.String ALG_NAME
          The algorithm name.
static int blockSize
          The DESede block size (8 bytes)
 
Fields inherited from class de.flexiprovider.api.BlockCipher
random
 
Fields inherited from class de.flexiprovider.api.Cipher
DECRYPT_MODE, ENCRYPT_MODE, opMode
 
Constructor Summary
DESede()
           
 
Method Summary
 int getCipherBlockSize()
          Return the blocksize the algorithm uses.
 int getKeySize(Key key)
          Returns the key size of the given key object.
 java.lang.String getName()
           
protected  void initCipherDecrypt(SecretKey key, AlgorithmParameterSpec params)
          Initialize the cipher for decryption.
protected  void initCipherEncrypt(SecretKey key, AlgorithmParameterSpec params)
          Initialize the cipher for encryption.
protected  void singleBlockDecrypt(byte[] input, int inOff, byte[] output, int outOff)
          This method decrypts a single block of data, and may only be called, when the block cipher is in decryption mode.
protected  void singleBlockEncrypt(byte[] input, int inOff, byte[] output, int outOff)
          This method encrypts a single block of data, and may only be called, when the block cipher is in encrytion mode.
 
Methods inherited from class de.flexiprovider.api.BlockCipher
doFinal, doFinal, engineInit, getBlockSize, getIV, getOutputSize, getParameters, initDecrypt, initDecrypt, initDecrypt, initEncrypt, initEncrypt, initEncrypt, initEncrypt, setMode, setPadding, update, update
 
Methods inherited from class de.flexiprovider.api.Cipher
doFinal, doFinal, engineDoFinal, engineDoFinal, engineGetBlockSize, engineGetIV, engineGetKeySize, engineGetOutputSize, engineGetParameters, engineInit, engineInit, engineSetMode, engineSetPadding, engineUpdate, engineUpdate, update
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALG_NAME

public static final java.lang.String ALG_NAME
The algorithm name.

blockSize

public static final int blockSize
The DESede block size (8 bytes)
Constructor Detail

DESede

public DESede()
Method Detail

getName

public java.lang.String getName()
Overrides:
getName in class Cipher
Returns:
the name of this cipher

getKeySize

public int getKeySize(Key key)
               throws InvalidKeyException
Returns the key size of the given key object. Checks whether the key object is an instance of DESedeKey or SecretKeySpec. If the 3 DES keys differ from each other, the effective key strength is 112 bits (not 168 bits, due to a meet in the middle attack), if they are all equal, we're simulating single DES.
Overrides:
getKeySize in class Cipher
Parameters:
key - the key object
Returns:
the key size of the given key object
Throws:
InvalidKeyException - if key is invalid.

getCipherBlockSize

public int getCipherBlockSize()
Return the blocksize the algorithm uses. This method will usually be called by the padding scheme.
Overrides:
getCipherBlockSize in class BlockCipher
Returns:
the used blocksize in Bytes.

initCipherEncrypt

protected void initCipherEncrypt(SecretKey key,
                                 AlgorithmParameterSpec params)
                          throws InvalidKeyException
Initialize the cipher for encryption.
Overrides:
initCipherEncrypt in class BlockCipher
Parameters:
key - the secret key used for encryption
params - algorithm parameters (not used)
Throws:
InvalidKeyException - if the given key is inappropriate for initializing this cipher.

initCipherDecrypt

protected void initCipherDecrypt(SecretKey key,
                                 AlgorithmParameterSpec params)
                          throws InvalidKeyException
Initialize the cipher for decryption.
Overrides:
initCipherDecrypt in class BlockCipher
Parameters:
key - the secret key used for decryption
params - algorithm parameters (not used)
Throws:
InvalidKeyException - if the given key is inappropriate for initializing this cipher.

singleBlockEncrypt

protected void singleBlockEncrypt(byte[] input,
                                  int inOff,
                                  byte[] output,
                                  int outOff)
This method encrypts a single block of data, and may only be called, when the block cipher is in encrytion mode. It has to be assured, too, that the array in contains a whole block starting at inOffset and that out is large enough to hold an encrypted block starting at outOffset. Key schedule is according to the FIPS46.3 standard.
Overrides:
singleBlockEncrypt in class BlockCipher
Parameters:
input - array of bytes which contains the plaintext to be encrypted
inOff - index in array in, where the plaintext block starts
output - array of bytes which will contain the ciphertext starting at outOffset
outOff - index in array out, where the ciphertext block will start

singleBlockDecrypt

protected void singleBlockDecrypt(byte[] input,
                                  int inOff,
                                  byte[] output,
                                  int outOff)
This method decrypts a single block of data, and may only be called, when the block cipher is in decryption mode. It has to be assured, too, that the array in contains a whole block starting at inOffset and that out is large enough to hold a decrypted block starting at outOffset. Key schedule is according to the FIPS46.3 standard.
Overrides:
singleBlockDecrypt in class BlockCipher
Parameters:
input - array of bytes which contains the ciphertext to be decrypted
inOff - index in array in, where the ciphertext block starts
output - array of bytes which will contain the plaintext starting at outOffset
outOff - index in array out, where the plaintext block will start