Class BSDUnixDESCryptPasswordImpl
- java.lang.Object
-
- org.wildfly.security.password.impl.AbstractPasswordImpl
-
- org.wildfly.security.password.impl.BSDUnixDESCryptPasswordImpl
-
- All Implemented Interfaces:
Serializable
,Cloneable
,Key
,BSDUnixDESCryptPassword
,OneWayPassword
,Password
class BSDUnixDESCryptPasswordImpl extends AbstractPasswordImpl implements BSDUnixDESCryptPassword
Implementation of the BSD variant of the Unix DES Crypt password.- Author:
- Farah Juma
-
-
Field Summary
Fields Modifier and Type Field Description private static int[]
bits32
private static byte[]
compPerm
private static int[][]
compPermMaskLeft
private static int[][]
compPermMaskRight
private static int[]
finalPerm
private static int[][]
fpMaskLeft
private static int[][]
fpMaskRight
private byte[]
hash
private static int[]
initPerm
private static int[]
invCompPerm
private static int[]
invKeyPerm
private static byte[]
invPBox
private static byte[][]
invSBox
private static byte[]
IP
private static int[][]
ipMaskLeft
private static int[][]
ipMaskRight
private int
iterationCount
private static byte[]
keyPerm
private static int[][]
keyPermMaskLeft
private static int[][]
keyPermMaskRight
private static byte[]
keyShifts
private static int[][]
mSBox
private static byte[]
PBox
private static int[][]
PSBox
private int
salt
private static byte[][]
SBox
private static long
serialVersionUID
private static boolean
tablesInitialized
-
Fields inherited from interface org.wildfly.security.password.interfaces.BSDUnixDESCryptPassword
ALGORITHM_BSD_CRYPT_DES, BSD_CRYPT_DES_HASH_SIZE, BSD_CRYPT_DES_SALT_SIZE, DEFAULT_ITERATION_COUNT
-
-
Constructor Summary
Constructors Constructor Description BSDUnixDESCryptPasswordImpl(char[] password, int salt, int iterationCount)
BSDUnixDESCryptPasswordImpl(char[] password, int salt, int iterationCount, Charset hashCharset)
BSDUnixDESCryptPasswordImpl(char[] password, Charset hashCharset)
BSDUnixDESCryptPasswordImpl(char[] password, IteratedPasswordAlgorithmSpec spec, Charset hashCharset)
BSDUnixDESCryptPasswordImpl(char[] password, IteratedSaltedPasswordAlgorithmSpec spec, Charset hashCharset)
BSDUnixDESCryptPasswordImpl(char[] password, SaltedPasswordAlgorithmSpec spec, Charset hashCharset)
BSDUnixDESCryptPasswordImpl(int salt, int iterationCount, byte[] hash)
BSDUnixDESCryptPasswordImpl(BSDUnixDESCryptPassword password)
BSDUnixDESCryptPasswordImpl(ClearPasswordSpec passwordSpec)
BSDUnixDESCryptPasswordImpl(IteratedSaltedHashPasswordSpec passwordSpec)
BSDUnixDESCryptPasswordImpl(SaltedHashPasswordSpec passwordSpec)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description BSDUnixDESCryptPasswordImpl
clone()
Creates and returns a copy of thisPassword
.(package private) <T extends KeySpec>
booleanconvertibleTo(Class<T> keySpecType)
(package private) static byte[]
crypt(byte[] password, int salt, int iterationCount)
Hashes the given password using the BSD variant of the Unix DES Crypt algorithm.private static byte[]
desCipher(int[] schedule, int leftInput, int rightInput, int salt, int iterationCount)
Performs DES encryption using the given key schedule, input block, salt, and iteration count.private static int[]
desSetKey(byte[] key)
Calculates the key schedule for the given key.boolean
equals(Object obj)
private static int
fourBytesToInt(byte[] b, int offset)
private static byte[]
generateHash(int salt, int iterationCount, char[] password)
private static byte[]
generateHash(int salt, int iterationCount, char[] password, Charset hashCharset)
String
getAlgorithm()
byte[]
getHash()
Get the hash segment of this password.int
getIterationCount()
Get the iteration count of this password.private static byte[]
getKeyGroup(byte[] password, int startIndex)
Gets the key group from the given password that starts at the given index.(package private) <S extends KeySpec>
SgetKeySpec(Class<S> keySpecType)
int
getSalt()
Get the salt segment of this password as anint
value.private static byte[]
getSaltBytes(int saltVal)
private static int
getSaltValue(byte[] saltBytes)
int
hashCode()
private static void
intToFourBytes(int iValue, byte[] b, int offset)
private void
readObject(ObjectInputStream ignored)
private static int
setupSalt(int salt)
Rearranges the bits in the 24-bit salt.private static void
setupTables()
Initializes the DES tables.(package private) boolean
verify(char[] guess)
(package private) boolean
verify(char[] guess, Charset hashCharset)
(package private) Object
writeReplace()
-
Methods inherited from class org.wildfly.security.password.impl.AbstractPasswordImpl
getEncoded, getFormat, getNormalizedPasswordBytes, getNormalizedPasswordBytes, translate
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.wildfly.security.password.interfaces.BSDUnixDESCryptPassword
getParameterSpec, impliesParameters
-
Methods inherited from interface java.security.Key
getEncoded, getFormat
-
Methods inherited from interface org.wildfly.security.password.Password
castAndApply, castAndApply, castAs, castAs
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
iterationCount
private final int iterationCount
-
salt
private final int salt
-
hash
private final byte[] hash
-
tablesInitialized
private static boolean tablesInitialized
-
IP
private static final byte[] IP
-
ipMaskLeft
private static final int[][] ipMaskLeft
-
ipMaskRight
private static final int[][] ipMaskRight
-
fpMaskLeft
private static final int[][] fpMaskLeft
-
fpMaskRight
private static final int[][] fpMaskRight
-
initPerm
private static final int[] initPerm
-
finalPerm
private static final int[] finalPerm
-
keyShifts
private static final byte[] keyShifts
-
keyPerm
private static final byte[] keyPerm
-
invKeyPerm
private static final int[] invKeyPerm
-
keyPermMaskLeft
private static final int[][] keyPermMaskLeft
-
keyPermMaskRight
private static final int[][] keyPermMaskRight
-
compPerm
private static final byte[] compPerm
-
invCompPerm
private static final int[] invCompPerm
-
compPermMaskLeft
private static final int[][] compPermMaskLeft
-
compPermMaskRight
private static final int[][] compPermMaskRight
-
SBox
private static final byte[][] SBox
-
mSBox
private static final int[][] mSBox
-
invSBox
private static final byte[][] invSBox
-
PBox
private static final byte[] PBox
-
invPBox
private static final byte[] invPBox
-
PSBox
private static final int[][] PSBox
-
bits32
private static final int[] bits32
-
-
Constructor Detail
-
BSDUnixDESCryptPasswordImpl
BSDUnixDESCryptPasswordImpl(int salt, int iterationCount, byte[] hash) throws InvalidKeySpecException
- Throws:
InvalidKeySpecException
-
BSDUnixDESCryptPasswordImpl
BSDUnixDESCryptPasswordImpl(IteratedSaltedHashPasswordSpec passwordSpec) throws InvalidKeySpecException, InvalidParameterSpecException
-
BSDUnixDESCryptPasswordImpl
BSDUnixDESCryptPasswordImpl(SaltedHashPasswordSpec passwordSpec) throws InvalidKeySpecException, InvalidParameterSpecException
-
BSDUnixDESCryptPasswordImpl
BSDUnixDESCryptPasswordImpl(ClearPasswordSpec passwordSpec) throws InvalidKeySpecException
- Throws:
InvalidKeySpecException
-
BSDUnixDESCryptPasswordImpl
BSDUnixDESCryptPasswordImpl(char[] password, Charset hashCharset) throws InvalidKeySpecException, InvalidParameterSpecException
-
BSDUnixDESCryptPasswordImpl
BSDUnixDESCryptPasswordImpl(char[] password, IteratedSaltedPasswordAlgorithmSpec spec, Charset hashCharset) throws InvalidKeySpecException, InvalidParameterSpecException
-
BSDUnixDESCryptPasswordImpl
BSDUnixDESCryptPasswordImpl(char[] password, IteratedPasswordAlgorithmSpec spec, Charset hashCharset) throws InvalidKeySpecException, InvalidParameterSpecException
-
BSDUnixDESCryptPasswordImpl
BSDUnixDESCryptPasswordImpl(char[] password, SaltedPasswordAlgorithmSpec spec, Charset hashCharset) throws InvalidKeySpecException, InvalidParameterSpecException
-
BSDUnixDESCryptPasswordImpl
BSDUnixDESCryptPasswordImpl(char[] password, int salt, int iterationCount) throws InvalidKeySpecException
- Throws:
InvalidKeySpecException
-
BSDUnixDESCryptPasswordImpl
BSDUnixDESCryptPasswordImpl(char[] password, int salt, int iterationCount, Charset hashCharset) throws InvalidKeySpecException
- Throws:
InvalidKeySpecException
-
BSDUnixDESCryptPasswordImpl
BSDUnixDESCryptPasswordImpl(BSDUnixDESCryptPassword password) throws InvalidKeyException
- Throws:
InvalidKeyException
-
-
Method Detail
-
getSaltValue
private static int getSaltValue(byte[] saltBytes) throws InvalidParameterSpecException
- Throws:
InvalidParameterSpecException
-
getSaltBytes
private static byte[] getSaltBytes(int saltVal)
-
getKeySpec
<S extends KeySpec> S getKeySpec(Class<S> keySpecType) throws InvalidKeySpecException
- Specified by:
getKeySpec
in classAbstractPasswordImpl
- Throws:
InvalidKeySpecException
-
verify
boolean verify(char[] guess) throws InvalidKeyException
- Specified by:
verify
in classAbstractPasswordImpl
- Throws:
InvalidKeyException
-
verify
boolean verify(char[] guess, Charset hashCharset) throws InvalidKeyException
- Overrides:
verify
in classAbstractPasswordImpl
- Throws:
InvalidKeyException
-
convertibleTo
<T extends KeySpec> boolean convertibleTo(Class<T> keySpecType)
- Specified by:
convertibleTo
in classAbstractPasswordImpl
-
getAlgorithm
public String getAlgorithm()
- Specified by:
getAlgorithm
in interfaceKey
-
getIterationCount
public int getIterationCount()
Description copied from interface:BSDUnixDESCryptPassword
Get the iteration count of this password.- Specified by:
getIterationCount
in interfaceBSDUnixDESCryptPassword
- Returns:
- the iteration count
-
getSalt
public int getSalt()
Description copied from interface:BSDUnixDESCryptPassword
Get the salt segment of this password as anint
value.- Specified by:
getSalt
in interfaceBSDUnixDESCryptPassword
- Returns:
- the salt segment
-
getHash
public byte[] getHash()
Description copied from interface:BSDUnixDESCryptPassword
Get the hash segment of this password.- Specified by:
getHash
in interfaceBSDUnixDESCryptPassword
- Returns:
- the hash segment
-
generateHash
private static byte[] generateHash(int salt, int iterationCount, char[] password)
-
generateHash
private static byte[] generateHash(int salt, int iterationCount, char[] password, Charset hashCharset)
-
setupTables
private static void setupTables()
Initializes the DES tables.
-
crypt
static byte[] crypt(byte[] password, int salt, int iterationCount)
Hashes the given password using the BSD variant of the Unix DES Crypt algorithm.- Parameters:
password
- the password to be hashedsalt
- the 24-bit salt to be usediterationCount
- the number of iterations to use, must be between 1 and 16777215, inclusive- Returns:
- a
byte[]
containing the hashed password
-
getKeyGroup
private static byte[] getKeyGroup(byte[] password, int startIndex)
Gets the key group from the given password that starts at the given index. The key group contains 8 bytes and is such that the byte at index i contains the lower 7 bits of the byte atpassword[startIndex + i]
.- Parameters:
password
- the passwordstartIndex
- the index where the key group begins- Returns:
- a
byte[]
containing the key group
-
desSetKey
private static int[] desSetKey(byte[] key)
Calculates the key schedule for the given key. The key schedule contains 16 subkeys, each of which can be represented by a pair of integers.- Parameters:
key
- the key- Returns:
- an
int[]
of size 32 containing the key schedule
-
desCipher
private static byte[] desCipher(int[] schedule, int leftInput, int rightInput, int salt, int iterationCount)
Performs DES encryption using the given key schedule, input block, salt, and iteration count.- Parameters:
schedule
- the key scheduleleftInput
- the most significant half of the input blockrightInput
- the least signicant half of the input blocksalt
- the 24-bit salt to be usediterationCount
- the number of iterations to use- Returns:
- a
byte[]
containing the hashed password
-
setupSalt
private static int setupSalt(int salt)
Rearranges the bits in the 24-bit salt.
-
fourBytesToInt
private static int fourBytesToInt(byte[] b, int offset)
-
intToFourBytes
private static void intToFourBytes(int iValue, byte[] b, int offset)
-
readObject
private void readObject(ObjectInputStream ignored) throws NotSerializableException
- Throws:
NotSerializableException
-
hashCode
public int hashCode()
- Specified by:
hashCode
in classAbstractPasswordImpl
-
equals
public boolean equals(Object obj)
- Specified by:
equals
in classAbstractPasswordImpl
-
writeReplace
Object writeReplace()
-
clone
public BSDUnixDESCryptPasswordImpl clone()
Description copied from interface:Password
Creates and returns a copy of thisPassword
.- Specified by:
clone
in interfaceBSDUnixDESCryptPassword
- Specified by:
clone
in interfaceOneWayPassword
- Specified by:
clone
in interfacePassword
- Specified by:
clone
in classAbstractPasswordImpl
- Returns:
- a copy of this
Password
.
-
-