org.xwiki.crypto.passwd.internal
Class AbstractKeyDerivationFunction

java.lang.Object
  extended by org.xwiki.crypto.passwd.internal.AbstractKeyDerivationFunction
All Implemented Interfaces:
java.io.Serializable, KeyDerivationFunction
Direct Known Subclasses:
PBKDF2KeyDerivationFunction

public abstract class AbstractKeyDerivationFunction
extends java.lang.Object
implements KeyDerivationFunction, java.io.Serializable

The abstract key derivation function. Provides guess/trial based determination of the correct number of iterations for a given processor time requirement.

Since:
2.5M1
Version:
$Id$
See Also:
Serialized Form

Constructor Summary
AbstractKeyDerivationFunction()
           
 
Method Summary
protected  int getDefaultDerivedKeyLength()
           
protected  int getDefaultMillisecondsOfProcessorTime()
           
 void init()
          Initialize with default values.
abstract  void init(byte[] salt, int iterationCount, int derivedKeyLength)
          Initialize the function manually.
 void init(int millisecondsOfProcessorTimeToSpend, int derivedKeyLength)
          Initialize this function with the desired key length and processor cost.
 void init(java.util.Properties parameters)
          Initialize this function with the desired key length and processor cost as a Properties The properties which will be looked for are millisecondsOfProcessorTimeToSpend and derivedKeyLength.
 byte[] serialize()
          Store this function as a byte array so another function of the same class can be initialized with the same array and will then produce the same key for the given password.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.xwiki.crypto.passwd.KeyDerivationFunction
deriveKey
 

Constructor Detail

AbstractKeyDerivationFunction

public AbstractKeyDerivationFunction()
Method Detail

serialize

public byte[] serialize()
                 throws java.io.IOException
Store this function as a byte array so another function of the same class can be initialized with the same array and will then produce the same key for the given password.

Specified by:
serialize in interface KeyDerivationFunction
Returns:
a byte array which can be used to recreate the same function again using init.
Throws:
java.io.IOException - if something fails within the serialization framework.

init

public void init()
Initialize with default values.

Specified by:
init in interface KeyDerivationFunction
See Also:
KeyDerivationFunction.init()

init

public void init(java.util.Properties parameters)
Initialize this function with the desired key length and processor cost as a Properties The properties which will be looked for are millisecondsOfProcessorTimeToSpend and derivedKeyLength. Both will be parsed as Integers. If either or both are missing then default values will be used. If values are not integers or are invalid, an IllegalArgumentException will throw.

Specified by:
init in interface KeyDerivationFunction
Parameters:
parameters - A properties expected to contain millisecondsOfProcessorTimeToSpend and derivedKeyLength which are both expected to parse as integers.
See Also:
KeyDerivationFunction.init(Properties)

init

public void init(int millisecondsOfProcessorTimeToSpend,
                 int derivedKeyLength)
Initialize this function with the desired key length and processor cost.

Specified by:
init in interface KeyDerivationFunction
Parameters:
millisecondsOfProcessorTimeToSpend - number of milliseconds to spend hashing the password. Based on this number and the power of the processor this is running on a number of iterations will be derived. This number will dictate how difficult hashing will be and also how difficult it will be to guess the password using cracking technology.
derivedKeyLength - the desired length of the hash output.
See Also:
KeyDerivationFunction.init(int, int)

init

public abstract void init(byte[] salt,
                          int iterationCount,
                          int derivedKeyLength)
Initialize the function manually.

Parameters:
salt - the random salt to add to the password before hashing.
iterationCount - the number of iterations which the internal function should run.
derivedKeyLength - the number of bytes of length the derived key should be (dkLen)

getDefaultMillisecondsOfProcessorTime

protected int getDefaultMillisecondsOfProcessorTime()
Returns:
the default number of milliseconds of processor time to require.

getDefaultDerivedKeyLength

protected int getDefaultDerivedKeyLength()
Returns:
the default size of the derived key (output) int bytes.


Copyright © 2004-2011 XWiki. All Rights Reserved.