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[]bits32private static byte[]compPermprivate static int[][]compPermMaskLeftprivate static int[][]compPermMaskRightprivate static int[]finalPermprivate static int[][]fpMaskLeftprivate static int[][]fpMaskRightprivate byte[]hashprivate static int[]initPermprivate static int[]invCompPermprivate static int[]invKeyPermprivate static byte[]invPBoxprivate static byte[][]invSBoxprivate static byte[]IPprivate static int[][]ipMaskLeftprivate static int[][]ipMaskRightprivate intiterationCountprivate static byte[]keyPermprivate static int[][]keyPermMaskLeftprivate static int[][]keyPermMaskRightprivate static byte[]keyShiftsprivate static int[][]mSBoxprivate static byte[]PBoxprivate static int[][]PSBoxprivate intsaltprivate static byte[][]SBoxprivate static longserialVersionUIDprivate static booleantablesInitialized-
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 BSDUnixDESCryptPasswordImplclone()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.booleanequals(Object obj)private static intfourBytesToInt(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)StringgetAlgorithm()byte[]getHash()Get the hash segment of this password.intgetIterationCount()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)intgetSalt()Get the salt segment of this password as anintvalue.private static byte[]getSaltBytes(int saltVal)private static intgetSaltValue(byte[] saltBytes)inthashCode()private static voidintToFourBytes(int iValue, byte[] b, int offset)private voidreadObject(ObjectInputStream ignored)private static intsetupSalt(int salt)Rearranges the bits in the 24-bit salt.private static voidsetupTables()Initializes the DES tables.(package private) booleanverify(char[] guess)(package private) booleanverify(char[] guess, Charset hashCharset)(package private) ObjectwriteReplace()-
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:
getKeySpecin classAbstractPasswordImpl- Throws:
InvalidKeySpecException
-
verify
boolean verify(char[] guess) throws InvalidKeyException- Specified by:
verifyin classAbstractPasswordImpl- Throws:
InvalidKeyException
-
verify
boolean verify(char[] guess, Charset hashCharset) throws InvalidKeyException- Overrides:
verifyin classAbstractPasswordImpl- Throws:
InvalidKeyException
-
convertibleTo
<T extends KeySpec> boolean convertibleTo(Class<T> keySpecType)
- Specified by:
convertibleToin classAbstractPasswordImpl
-
getAlgorithm
public String getAlgorithm()
- Specified by:
getAlgorithmin interfaceKey
-
getIterationCount
public int getIterationCount()
Description copied from interface:BSDUnixDESCryptPasswordGet the iteration count of this password.- Specified by:
getIterationCountin interfaceBSDUnixDESCryptPassword- Returns:
- the iteration count
-
getSalt
public int getSalt()
Description copied from interface:BSDUnixDESCryptPasswordGet the salt segment of this password as anintvalue.- Specified by:
getSaltin interfaceBSDUnixDESCryptPassword- Returns:
- the salt segment
-
getHash
public byte[] getHash()
Description copied from interface:BSDUnixDESCryptPasswordGet the hash segment of this password.- Specified by:
getHashin 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:
hashCodein classAbstractPasswordImpl
-
equals
public boolean equals(Object obj)
- Specified by:
equalsin classAbstractPasswordImpl
-
writeReplace
Object writeReplace()
-
clone
public BSDUnixDESCryptPasswordImpl clone()
Description copied from interface:PasswordCreates and returns a copy of thisPassword.- Specified by:
clonein interfaceBSDUnixDESCryptPassword- Specified by:
clonein interfaceOneWayPassword- Specified by:
clonein interfacePassword- Specified by:
clonein classAbstractPasswordImpl- Returns:
- a copy of this
Password.
-
-