gnu.crypto.cipher

Class TripleDES

Implemented Interfaces:
Cloneable, IBlockCipher, IBlockCipherSpi

public class TripleDES
extends BaseCipher

Triple-DES, 3DES, or DESede is a combined cipher that uses three iterations of the Data Encryption Standard cipher to improve the security (at the cost of speed) of plain DES.

Triple-DES runs the DES algorithm three times with three independent 56 bit keys. To encrypt:

Ci = Ek3 ( Ek2-1 ( Ek1 ( Pi )))

And to decrypt:

Pi = Ek1-1 ( Ek2 ( Ek3-1 ( Ci )))

(The "ede" comes from the encryption operation, which runs Encrypt-Decrypt-Encrypt)

References:

  1. Bruce Schneier, Applied Cryptography: Protocols, Algorithms, and Source Code in C, Second Edition. (1996 John Wiley and Sons) ISBN 0-471-11709-9. Page 294--295.
Version:
$Revision: 1.2 $

Field Summary

static int
BLOCK_SIZE
Triple-DES only operates on 64 bit blocks.
static int
KEY_SIZE
Triple-DES uses 168 bits of a parity-adjusted 192 bit key.

Fields inherited from class gnu.crypto.cipher.BaseCipher

currentBlockSize, currentKey, defaultBlockSize, defaultKeySize, lock, name

Fields inherited from interface gnu.crypto.cipher.IBlockCipher

CIPHER_BLOCK_SIZE, KEY_MATERIAL

Constructor Summary

TripleDES()
Default 0-arguments constructor.

Method Summary

static void
adjustParity(byte[] kb, int offset)
Transform a key so it will be parity adjusted.
Iterator
blockSizes()
Returns an Iterator over the supported block sizes.
Object
clone()
void
decrypt(byte[] in, int i, byte[] out, int o, Object K, int bs)
Decrypts exactly one block of ciphertext.
void
encrypt(byte[] in, int i, byte[] out, int o, Object K, int bs)
Encrypts exactly one block of plaintext.
static boolean
isParityAdjusted(byte[] kb, int offset)
Tests if a byte array has already been parity adjusted.
Iterator
keySizes()
Returns an Iterator over the supported key sizes.
Object
makeKey(byte[] kb, int bs)
Expands a user-supplied key material into a session key for a designated block size.

Methods inherited from class gnu.crypto.cipher.BaseCipher

clone, currentBlockSize, decryptBlock, defaultBlockSize, defaultKeySize, encryptBlock, init, name, reset, selfTest, testKat, testKat

Field Details

BLOCK_SIZE

public static final int BLOCK_SIZE
Triple-DES only operates on 64 bit blocks.
Field Value:
8

KEY_SIZE

public static final int KEY_SIZE
Triple-DES uses 168 bits of a parity-adjusted 192 bit key.
Field Value:
24

Constructor Details

TripleDES

public TripleDES()
Default 0-arguments constructor.

Method Details

adjustParity

public static void adjustParity(byte[] kb,
                                int offset)
Transform a key so it will be parity adjusted.
Parameters:
kb - The key bytes to adjust.
offset - The starting offset into the key bytes.

blockSizes

public Iterator blockSizes()
Returns an Iterator over the supported block sizes. Each element returned by this object is a Integer.
Specified by:
blockSizes in interface IBlockCipher
blockSizes in interface IBlockCipherSpi
Returns:
an Iterator over the supported block sizes.

clone

public Object clone()
Specified by:
clone in interface IBlockCipher
Overrides:
clone in interface BaseCipher

decrypt

public void decrypt(byte[] in,
                    int i,
                    byte[] out,
                    int o,
                    Object K,
                    int bs)
Decrypts exactly one block of ciphertext.
Specified by:
decrypt in interface IBlockCipherSpi
Parameters:
in - the ciphertext.
out - the plaintext.
bs - the block size to use.

encrypt

public void encrypt(byte[] in,
                    int i,
                    byte[] out,
                    int o,
                    Object K,
                    int bs)
Encrypts exactly one block of plaintext.
Specified by:
encrypt in interface IBlockCipherSpi
Parameters:
in - the plaintext.
out - the ciphertext.
bs - the block size to use.

isParityAdjusted

public static boolean isParityAdjusted(byte[] kb,
                                       int offset)
Tests if a byte array has already been parity adjusted.
Parameters:
kb - The key bytes to test.
offset - The starting offset into the key bytes.
Returns:
true if the bytes in kb starting at offset are parity adjusted.

keySizes

public Iterator keySizes()
Returns an Iterator over the supported key sizes. Each element returned by this object is a Integer.
Specified by:
keySizes in interface IBlockCipher
keySizes in interface IBlockCipherSpi
Returns:
an Iterator over the supported key sizes.

makeKey

public Object makeKey(byte[] kb,
                      int bs)
            throws InvalidKeyException
Expands a user-supplied key material into a session key for a designated block size.
Specified by:
makeKey in interface IBlockCipherSpi
Parameters:
bs - the desired block size in bytes.
Returns:
an Object encapsulating the session key.

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