Class Crypt

java.lang.Object
   |
   +----Crypt

public class Crypt
extends Object
Crypt is the class, that implements UFC crypt (ultra fast crypt implementation ) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. JAVA version.

Author:
Michael Glad (glad@daimi.aau.dk), Pawel Veselov (vps@phoenix.math.spbu.ru)

Variable Index

 o byteMask
 o currentSalt
 o currentSaltbits
 o direction
 o doPc1
doPc1: perform pc1 permutation in the key schedule generation.
 o doPc2
doPc2: perform pc2 permutation in the key schedule generation.
 o efp
efp: undo an extra e selection and do final permutation gibing the DES result.
 o eInverse
 o ePerm32Tab
Do 32 but permutation and E selection The first index is the byte number in the 32 bit value to be permuted - second - is the value of this byte - third - selects the two 32 bit value The table is used and generated internally in initDes() to speed it up.
 o esel
The E expansion table wich selects bits from the 32 bit intermediate result.
 o finalPerm
This is final permutation matrix.
 o inited
 o initialPerm
This is the initial permutation matrix
 o lock
 o longMask
 o pc1
Permutation done once on the 56 bit key derived from the original 8 byte ASCII key.
 o pc1_1
 o pc1_2
 o pc1_3
 o pc2
Permutation giving the key of the i' DES round.
 o pc2_1
 o pc2_2
 o perm32
Permutation done on the result of sbox lookups.
 o rots
How much to rotate each 28 bit half of the pc1 permutated 56 bit key before using pc2 to give i' key.
 o sb
sb arrays: Workhorses of the inner loop of the DES implementation.
 o sbox
The sboxes.
 o ufcKeytab
The 16 DES keys in BITMASK format

Constructor Index

 o Crypt()

Method Index

 o asciiToBin(byte)
 o binToAscii(long)
 o bitMask(long)
Function to set a bit (0..23)
 o crypt(byte[], byte[])
crypt function.
 o crypt(byte[], String)
crypt function
 o crypt(String, String)
crypt function.
 o initDes()
Initialze unit - may be invoked directly by user.
 o outputConversion(int, int, byte[])
Crypt only: convert from 64 bit to 11 bit ASCII
 o sba(long[], long)
 o selfTest(boolean)
This method test crypt.
 o setupSalt(byte[])
Setup the unit for a new salt.
 o shuffleSb(long[], int)
Process the elements of the sb table permuting the bits swapped in the expansion by the current salt.
 o sLookup(int, int)
Lookup a 6 bit value in sbox
 o ufcDoFinalPerm(int, int, int, int)
Undo an extra E selection and do final permutations.
 o ufcDoit(int, int, int, int, int)
 o ufcMkKeytab(byte[])

Variables

 o lock
 private static Object lock
 o ePerm32Tab
 private static long ePerm32Tab[][][]
Do 32 but permutation and E selection The first index is the byte number in the 32 bit value to be permuted - second - is the value of this byte - third - selects the two 32 bit value The table is used and generated internally in initDes() to speed it up.

 o pc1_1
 private static int pc1_1
 o pc1_2
 private static int pc1_2
 o pc1_3
 private static int pc1_3
 o pc2_1
 private static int pc2_1
 o pc2_2
 private static int pc2_2
 o doPc1
 private static long doPc1[]
doPc1: perform pc1 permutation in the key schedule generation. The first index is the byte number in the 8 byte ASCII key - second - - the two 28 bits halfs on the result - third - selects the 7 bits actually used of each byte The result is kept with 28 bit per 32 bit with the 4 most significant bits zero.

 o doPc2
 private static long doPc2[]
doPc2: perform pc2 permutation in the key schedule generation. The first index is the septet number in the two 28 bit intermediate values - second - - - speted values Knowledge of the structure of the pc2 permutation is used. The result is kept with 28 bit per 32 bit with the 4 most significant bits zero.

 o efp
 private static long efp[][][]
efp: undo an extra e selection and do final permutation gibing the DES result. Invoked 6 bit a time on two 48 bit vales giving two 32 bit longs.

 o byteMask
 private static int byteMask[]
 o pc1
 private static int pc1[]
Permutation done once on the 56 bit key derived from the original 8 byte ASCII key.

 o rots
 private static int rots[]
How much to rotate each 28 bit half of the pc1 permutated 56 bit key before using pc2 to give i' key.

 o pc2
 private static int pc2[]
Permutation giving the key of the i' DES round.

 o esel
 private static int esel[]
The E expansion table wich selects bits from the 32 bit intermediate result.

 o eInverse
 private static int eInverse[]
 o perm32
 private static int perm32[]
Permutation done on the result of sbox lookups.

 o sbox
 private static int sbox[][][]
The sboxes.

 o initialPerm
 private static int initialPerm[]
This is the initial permutation matrix

 o finalPerm
 private static int finalPerm[]
This is final permutation matrix.

 o longMask
 private static long longMask[]
 o ufcKeytab
 private static long ufcKeytab[]
The 16 DES keys in BITMASK format

 o sb
 private static long sb[][]
sb arrays: Workhorses of the inner loop of the DES implementation. The do sbox lookup, shifting of this value, 32 bit permutation and E permutation for the next round. Kept in 'BITMASK' format.

 o inited
 private static boolean inited
 o currentSalt
 private static byte currentSalt[]
 o currentSaltbits
 private static int currentSaltbits
 o direction
 private static int direction

Constructors

 o Crypt
 public Crypt()

Methods

 o selfTest
 public static boolean selfTest(boolean show)
This method test crypt.

Parameters:
show - if it is true, print test results to err stream
Returns:
true, if test succeeded, false if failed.
 o crypt
 public static String crypt(byte salt[],
                            byte original[])
crypt function.

Parameters:
salt - two byte array with salt.
original - array, maximum 8 bytes, string to encrypt
 o crypt
 public static String crypt(String salt,
                            String original)
crypt function.

Parameters:
salt - String, maximum length is 2 with salt.
original - String, maximum 8 bytes, string to encrypt
 o crypt
 public static String crypt(byte salt[],
                            String original)
crypt function

Parameters:
salt - Two bytes array with salt
original - String, maximum 8 characters, string to encrypt
 o outputConversion
 private static String outputConversion(int v1,
                                        int v2,
                                        byte salt[])
Crypt only: convert from 64 bit to 11 bit ASCII

 o sLookup
 private static int sLookup(int i,
                            int s)
Lookup a 6 bit value in sbox

 o bitMask
 private static long bitMask(long i)
Function to set a bit (0..23)

 o initDes
 public static void initDes()
Initialze unit - may be invoked directly by user. Anyway it is invoked automatically from crypt()

 o setupSalt
 private static void setupSalt(byte s[])
Setup the unit for a new salt. Hopefully we'll not see a new salt in each crypt call.

 o shuffleSb
 private static void shuffleSb(long k[],
                               int saltbits)
Process the elements of the sb table permuting the bits swapped in the expansion by the current salt.

 o asciiToBin
 private static long asciiToBin(byte c)
 o binToAscii
 private static char binToAscii(long c)
 o ufcMkKeytab
 private static void ufcMkKeytab(byte keyInd[])
 o sba
 private static long sba(long sb[],
                         long v)
 o ufcDoFinalPerm
 private static int[] ufcDoFinalPerm(int l1,
                                     int l2,
                                     int r1,
                                     int r2)
Undo an extra E selection and do final permutations.

 o ufcDoit
 private static int[] ufcDoit(int l1,
                              int l2,
                              int r1,
                              int r2,
                              int itr)