net.vattp.data
Class DES

java.lang.Object
  |
  +--net.vattp.data.DES

public final class DES
extends Object

Untamed:


Field Summary
private static int BLOCK_SIZE
           
private static boolean DEBUG
           
private static int debuglevel
           
private static int DECRYPT
           
private static int ENCRYPT
           
private  int encryptDecryptState
          State for encrypt/decrypt/uninitialized.
private static String HEXSTR
           
private static int INTERNAL_KEY_LENGTH
           
private static int KEY_LENGTH
           
private static int ROUNDS
           
private static int[] SKB
          Table for PC2 permutations in key schedule computation.
private  int[] sKey
          The internal key schedule.
private static int[] SP_TRANS
          Table for S-boxes and permutations, used in encrypt_base.
private static String[][] tests
           
private static int UNINITIALIZED
           
 
Constructor Summary
DES()
          Enabled: Constructs a DES cipher object, in the UNINITIALIZED state.
 
Method Summary
private static boolean areEqual(byte[] a, byte[] b)
           
 int blockSize()
          Enabled: SPI: Returns the length of an input block, in bytes.
 Object clone()
          Suppressed: Always throws a CloneNotSupportedException (cloning of ciphers is not supported for security reasons).
 byte[] crypt(byte[] data)
          Enabled:
private  void decrypt_base(int[] io)
          Implements DES decryption without IP and FP.
private  void des(byte[] in, int inOffset, byte[] out, int outOffset, boolean encrypt)
          Encrypts/decrypts a block, of length BLOCK_SIZE.
private  void encrypt_base(int[] io)
          Implements DES encryption without IP and FP.
private static void finalPermutation(int[] io)
           
private static String getAlgorithm()
           
private static byte[] hexFromString(String s)
           
 void initDecrypt(byte[] key)
          Enabled: SPI: Initializes this cipher for decryption, using the specified key.
 void initEncrypt(byte[] key)
          Enabled: SPI: Initializes this cipher for encryption, using the specified key.
private static void initialPermutation(int[] io)
           
static void main(String[] argv)
          Enabled: Entry point for self_test.
private  void makeKey(byte[] userkey)
          Expands a user-key to a working key schedule.
private static void self_test()
           
 int update(byte[] in, int inOffset, int inLen, byte[] out, int outOffset)
          Enabled: SPI: This is the main method for updating data.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

private static final boolean DEBUG

debuglevel

private static final int debuglevel

ROUNDS

private static final int ROUNDS

BLOCK_SIZE

private static final int BLOCK_SIZE

KEY_LENGTH

private static final int KEY_LENGTH

INTERNAL_KEY_LENGTH

private static final int INTERNAL_KEY_LENGTH

encryptDecryptState

private int encryptDecryptState
State for encrypt/decrypt/uninitialized.


UNINITIALIZED

private static final int UNINITIALIZED

ENCRYPT

private static final int ENCRYPT

DECRYPT

private static final int DECRYPT

SKB

private static final int[] SKB
Table for PC2 permutations in key schedule computation.


sKey

private final int[] sKey
The internal key schedule.


SP_TRANS

private static final int[] SP_TRANS
Table for S-boxes and permutations, used in encrypt_base.


tests

private static final String[][] tests

HEXSTR

private static final String HEXSTR
Constructor Detail

DES

public DES()
Enabled: Constructs a DES cipher object, in the UNINITIALIZED state.

Method Detail

clone

public final Object clone()
                   throws CloneNotSupportedException
Suppressed: Always throws a CloneNotSupportedException (cloning of ciphers is not supported for security reasons).

Overrides:
clone in class Object
Returns:
a clone of this instance.
CloneNotSupportedException
See Also:
java.lang.Cloneable

blockSize

public int blockSize()
Enabled: SPI: Returns the length of an input block, in bytes.

Returns:
the length in bytes of an input block for this cipher.

initEncrypt

public void initEncrypt(byte[] key)
                 throws InvalidKeyException
Enabled: SPI: Initializes this cipher for encryption, using the specified key.

Parameters:
key - the key to use for encryption.
Throws:
InvalidKeyException - if one of the following occurs:
  • key.getEncoded() == null;
  • The length of the user key array is not KEY_LENGTH.

initDecrypt

public void initDecrypt(byte[] key)
                 throws InvalidKeyException
Enabled: SPI: Initializes this cipher for decryption, using the specified key.

Parameters:
key - the key to use for decryption.
Throws:
InvalidKeyException - if one of the following occurs:
  • key.getEncoded() == null;
  • The length of the user key array is not KEY_LENGTH.

crypt

public byte[] crypt(byte[] data)
Enabled:


update

public int update(byte[] in,
                  int inOffset,
                  int inLen,
                  byte[] out,
                  int outOffset)
Enabled: SPI: This is the main method for updating data.

in and out may be the same array, and the input and output regions may overlap.

Parameters:
in - the input data.
inOffset - the offset into in specifying where the data starts.
inLen - the length of the subarray.
out - the output array.
outOffset - the offset indicating where to start writing into the out array.
Returns:
the number of bytes written.

makeKey

private void makeKey(byte[] userkey)
              throws InvalidKeyException
Expands a user-key to a working key schedule.

Parameters:
userkey - the user-key object to use.
Throws:
InvalidKeyException - if one of the following occurs:
  • key.getEncoded() == null;
  • The length of the user key array is not KEY_LENGTH.

des

private void des(byte[] in,
                 int inOffset,
                 byte[] out,
                 int outOffset,
                 boolean encrypt)
Encrypts/decrypts a block, of length BLOCK_SIZE.

Parameters:
in - an array containing the input block
inOffset - the starting offset of the input block
out - an array containing the output block
encrypt - true to encrypt, false to decrypt

encrypt_base

private void encrypt_base(int[] io)
Implements DES encryption without IP and FP.


decrypt_base

private void decrypt_base(int[] io)
Implements DES decryption without IP and FP.


initialPermutation

private static void initialPermutation(int[] io)

finalPermutation

private static void finalPermutation(int[] io)

getAlgorithm

private static String getAlgorithm()

main

public static void main(String[] argv)
Enabled: Entry point for self_test.


self_test

private static void self_test()
                       throws Exception
Exception

areEqual

private static boolean areEqual(byte[] a,
                                byte[] b)

hexFromString

private static byte[] hexFromString(String s)


comments?