org.xwiki.crypto.passwd.internal
Class AbstractMemoryHardKeyDerivationFunction

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

public abstract class AbstractMemoryHardKeyDerivationFunction
extends java.lang.Object
implements MemoryHardKeyDerivationFunction

Abstract memory hard key derivation function. to subclass this, simply implement init(int, int, int) from MemoryHardKeyDerivationFunction and isInitialized() and deriveKey(byte[]) from KeyDerivationFunction. Be careful, this class is serializable, serialization and deserialization should yield a function which provides the same password to key mapping, and make sure fields unnecessary to this are declared transient.

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

Constructor Summary
AbstractMemoryHardKeyDerivationFunction()
           
 
Method Summary
protected  int getDefaultDerivedKeyLength()
           
protected  int getDefaultMillisecondsOfProcessorTime()
           
 int getDefaultNumberOfKilobytesOfMemoryToUse()
           
 void init()
          Initialize with default values.
 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.MemoryHardKeyDerivationFunction
init
 
Methods inherited from interface org.xwiki.crypto.passwd.KeyDerivationFunction
deriveKey
 

Constructor Detail

AbstractMemoryHardKeyDerivationFunction

public AbstractMemoryHardKeyDerivationFunction()
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

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.

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.

getDefaultNumberOfKilobytesOfMemoryToUse

public int getDefaultNumberOfKilobytesOfMemoryToUse()
Returns:
the number of kilobytes of memory to require by default.

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.