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)
-
byteMask
-
-
currentSalt
-
-
currentSaltbits
-
-
direction
-
-
doPc1
- doPc1: perform pc1 permutation in the key schedule generation.
-
doPc2
- doPc2: perform pc2 permutation in the key schedule generation.
-
efp
- efp: undo an extra e selection and do final
permutation gibing the DES result.
-
eInverse
-
-
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.
-
esel
- The E expansion table wich selects
bits from the 32 bit intermediate result.
-
finalPerm
- This is final permutation matrix.
-
inited
-
-
initialPerm
- This is the initial permutation matrix
-
lock
-
-
longMask
-
-
pc1
- Permutation done once on the 56 bit
key derived from the original 8 byte ASCII key.
-
pc1_1
-
-
pc1_2
-
-
pc1_3
-
-
pc2
- Permutation giving the key of the i' DES round.
-
pc2_1
-
-
pc2_2
-
-
perm32
- Permutation done on the result of sbox lookups.
-
rots
- How much to rotate each 28 bit half of the pc1 permutated
56 bit key before using pc2 to give i' key.
-
sb
- sb arrays:
Workhorses of the inner loop of the DES implementation.
-
sbox
- The sboxes.
-
ufcKeytab
- The 16 DES keys in BITMASK format
-
Crypt()
-
-
asciiToBin(byte)
-
-
binToAscii(long)
-
-
bitMask(long)
- Function to set a bit (0..23)
-
crypt(byte[], byte[])
- crypt function.
-
crypt(byte[], String)
- crypt function
-
crypt(String, String)
- crypt function.
-
initDes()
- Initialze unit - may be invoked directly by user.
-
outputConversion(int, int, byte[])
-
Crypt only: convert from 64 bit to 11 bit ASCII
-
sba(long[], long)
-
-
selfTest(boolean)
- This method test crypt.
-
setupSalt(byte[])
- Setup the unit for a new salt.
-
shuffleSb(long[], int)
- Process the elements of the sb table permuting the
bits swapped in the expansion by the current salt.
-
sLookup(int, int)
- Lookup a 6 bit value in sbox
-
ufcDoFinalPerm(int, int, int, int)
- Undo an extra E selection and do final permutations.
-
ufcDoit(int, int, int, int, int)
-
-
ufcMkKeytab(byte[])
-
lock
private static Object lock
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.
pc1_1
private static int pc1_1
pc1_2
private static int pc1_2
pc1_3
private static int pc1_3
pc2_1
private static int pc2_1
pc2_2
private static int pc2_2
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.
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.
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.
byteMask
private static int byteMask[]
pc1
private static int pc1[]
- Permutation done once on the 56 bit
key derived from the original 8 byte ASCII key.
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.
pc2
private static int pc2[]
- Permutation giving the key of the i' DES round.
esel
private static int esel[]
- The E expansion table wich selects
bits from the 32 bit intermediate result.
eInverse
private static int eInverse[]
perm32
private static int perm32[]
- Permutation done on the result of sbox lookups.
sbox
private static int sbox[][][]
- The sboxes.
initialPerm
private static int initialPerm[]
- This is the initial permutation matrix
finalPerm
private static int finalPerm[]
- This is final permutation matrix.
longMask
private static long longMask[]
ufcKeytab
private static long ufcKeytab[]
- The 16 DES keys in BITMASK format
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.
inited
private static boolean inited
currentSalt
private static byte currentSalt[]
currentSaltbits
private static int currentSaltbits
direction
private static int direction
Crypt
public Crypt()
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.
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
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
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
outputConversion
private static String outputConversion(int v1,
int v2,
byte salt[])
- Crypt only: convert from 64 bit to 11 bit ASCII
sLookup
private static int sLookup(int i,
int s)
- Lookup a 6 bit value in sbox
bitMask
private static long bitMask(long i)
- Function to set a bit (0..23)
initDes
public static void initDes()
- Initialze unit - may be invoked directly by user. Anyway
it is invoked automatically from crypt()
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.
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.
asciiToBin
private static long asciiToBin(byte c)
binToAscii
private static char binToAscii(long c)
ufcMkKeytab
private static void ufcMkKeytab(byte keyInd[])
sba
private static long sba(long sb[],
long v)
ufcDoFinalPerm
private static int[] ufcDoFinalPerm(int l1,
int l2,
int r1,
int r2)
- Undo an extra E selection and do final permutations.
ufcDoit
private static int[] ufcDoit(int l1,
int l2,
int r1,
int r2,
int itr)