iaik.security.random
Class HashObjectSeedGenerator

java.lang.Object
  |
  +--iaik.security.random.SeedGenerator
        |
        +--iaik.security.random.HashObjectSeedGenerator
Direct Known Subclasses:
AWT10SeedGenerator, AWT11SeedGenerator

public abstract class HashObjectSeedGenerator
extends SeedGenerator

This seed generator is an abstract class designed to help you write seedgenerators that distill randomness from objects fed to it. Often applications will have access to data that includes some amount of randomness, like for example the events generated by the user moving his mouse. This randomness (plus possibly some non-random data) will be hashed by a MessageDigest object, its hash is the seed returned by this class.

The usage is rather simple. You just have to subclass this class and implement the abstract method extractSeedData(). Every time the user passes an object to this class via addSeedObject this object will be passed to extractSeedData(). The task of this method is to extract randomness from the object and call one of the updateHash() methods. Note that it should never hurt to hash not only the random parts but also deterministic data, i.e. you can hash all fields of the object. It is recommended to hash the current time as obtained by System.currentTimeMillis() in addition to be object itself.

For more information see the documentation of the extractSeedData() and getMessageDigest() methods.

Version:
File Revision 11
See Also:
SeedGenerator, AWT11SeedGenerator, AWT10SeedGenerator

Fields inherited from class iaik.security.random.SeedGenerator
seedGenListener
 
Constructor Summary
protected HashObjectSeedGenerator(int numBits)
          Constructor for use by subclasses.
 
Method Summary
 boolean addSeedObject(Object obj)
          Feed a new seed object to this seed generator.
protected abstract  int extractSeedData(Object obj)
          This method extracts the random information from the object and updates the hash accordingly.
protected  MessageDigest getMessageDigest()
          Return a new MessageDigest object to be used to digest the random information.
 byte[] getSeed()
          Return the random seed.
 int[] getStatus()
          Return the current status of seed generation.
protected  void updateHash(byte[] data)
          Update the hash by data.
protected  void updateHash(long l)
          Update the hash by longToBytes(l).
protected  void updateHash(String data)
          Update the hash by data.getBytes().
 
Methods inherited from class iaik.security.random.SeedGenerator
callSeedGenListener, getDefault, getDefaultSeedGenerator, longToBytes, seedAvailable, setDefault, setDefaultSeedGenerator, setSeedGenListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HashObjectSeedGenerator

protected HashObjectSeedGenerator(int numBits)
Constructor for use by subclasses.
Method Detail

getMessageDigest

protected MessageDigest getMessageDigest()
Return a new MessageDigest object to be used to digest the random information. Per default this will return an instance of the IAIK SHA1 implementation, if you want to use a different message digest override this method in your SeedGenerator.

getStatus

public final int[] getStatus()
Return the current status of seed generation.
Overrides:
getStatus in class SeedGenerator

updateHash

protected final void updateHash(byte[] data)
Update the hash by data. For use by subclasses.

updateHash

protected final void updateHash(String data)
Update the hash by data.getBytes(). For use by subclasses.

updateHash

protected final void updateHash(long l)
Update the hash by longToBytes(l). For use by subclasses.

extractSeedData

protected abstract int extractSeedData(Object obj)
                                throws RandomException
This method extracts the random information from the object and updates the hash accordingly. It has to be implemented by subclasses and is called by addSeedObject() only. It should return the number of random bits obtained from the object. If the object is an instance of an unsupported class it should throw a RandomException.

addSeedObject

public final boolean addSeedObject(Object obj)
                            throws RandomException
Feed a new seed object to this seed generator. This method will call extractSeedData() and the SeedGenListener (if one is registered). If more seed objects are needed it return true, otherwise false. If seed generation is already completed when this method is called, it will instantly return false.

getSeed

public final byte[] getSeed()
Return the random seed. If it is not yet ready, this method will return null. The seed returned is always the length of the digest used (per default 20 bytes for SHA-1).
Overrides:
getSeed in class SeedGenerator

This Javadoc may contain text parts from Internet Standard specifications (RFC 2459, 3280, 3039, 2560, 1521, 821, 822, 2253, 1319, 1321, ,2630, 2631, 2268, 3058, 2984, 2104, 2144, 2040, 2311, 2279, see copyright note) and RSA Data Security Public-Key Cryptography Standards (PKCS#1,3,5,7,8,9,10,12, see copyright note).

IAIK-JCE 3.1 with IAIK-JCE CC Core 3.1, (c) 1997-2004 IAIK