iaik.security.random
Class AWT11SeedGenerator

java.lang.Object
  |
  +--iaik.security.random.SeedGenerator
        |
        +--iaik.security.random.HashObjectSeedGenerator
              |
              +--iaik.security.random.AWT11SeedGenerator

public class AWT11SeedGenerator
extends HashObjectSeedGenerator

This class generates a PRNG seed from user generated AWT events following the JDK 1.1 AWT event model. It is a subclass of HashObjectSeedGenerator and uses its API, see there for more documentation.

The API:

  1. Generate an AWT11SeedGenerator using one of the constructors.
  2. Make the user generate AWT Events and feed them to this class. Here you have two choices:
  3. when enough events have been generated, call getSeed() to obtain the random seed. Use a seedGenListener to find out when seed generation is completed, wait for addSeedObject() to return false if you are calling it yourself, or use getStatus().

A seedGenListener should implement at least one of the MouseMotionListener, MouseListener, and KeyListener interfaces. The default listener implements all of them, but only uses the mousePressed, mouseMoved, mouseDragged, and keyTyped events to build the random seed. The other events are ignored for the reasons explained below. If you write your own listener, just make it call addSeedObject() for all events you wish to use for seeding.

Every time addEvent() is called, it will add the current time as returned by System.currentTimeMillis(), the string representation of the event as obtained by toString(), and the identityHashCode() of the event to the input of an SHA-1 hash. The string representation of an event contains all the information about the event (event source, event type, event parameters, etc). When getSeed() is finally called, the hash is returned, therefore it is always 20 bytes long. This also means, that one instance of this class can generate no more than 160 random bits.

This class assumes that the amount of uncertainty per event is (on average) at least three bits per event. In other words this means that an attacker would have to use no more than eight tries (on average) to guess all of these correctly:

Even if one considers redundancy between events (events are likely to occur 10 to 100 ms apart, a mouse moved event if likely to be followed by another mouse moved event, etc.), I still consider this to be a fairly conservative estimate. For example, assume that there is at least one bit of uncertainty in the time the event happened, and the other two bits (i.e. four tries) needed to guess whether the X or Y coordinate has increased or decreased. However, if you believe that this assumptions are too optimistic or pessimistic, just increase (decrease) the parameter passed to the constructor.

Version:
File Revision 14

Fields inherited from class iaik.security.random.SeedGenerator
seedGenListener
 
Constructor Summary
AWT11SeedGenerator()
          Generate a seed generator for the default number of random bits (currently 136).
AWT11SeedGenerator(int numBits)
          Generate a seed generator for the specified number of bits.
 
Method Summary
 boolean addEvent(AWTEvent event)
          Deprecated. use addSeedObject() instead.
 void addEventSource(Component component)
          Add a component as a source of events.
protected  int extractSeedData(Object obj)
          Add the given event to the seed.
 void setEventListener(Object listener)
          Set the event listener that will pass the events to us.
 
Methods inherited from class iaik.security.random.HashObjectSeedGenerator
addSeedObject, getMessageDigest, getSeed, getStatus, updateHash, updateHash, updateHash
 
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

AWT11SeedGenerator

public AWT11SeedGenerator(int numBits)
Generate a seed generator for the specified number of bits.

AWT11SeedGenerator

public AWT11SeedGenerator()
Generate a seed generator for the default number of random bits (currently 136).
Method Detail

setEventListener

public void setEventListener(Object listener)
Set the event listener that will pass the events to us. Per default, or if set to null, a default event listener will be used. The listener has to implement at least one of the MouseMotionListener, MouseListener, or KeyListener interfaces. The listener will automatically added as listener to all the components specified via addEventSource() during seed generation and removed again afterwards. This does not interfere with the normal event handling possibly performed by other listeners.

addEventSource

public void addEventSource(Component component)
Add a component as a source of events.

addEvent

public boolean addEvent(AWTEvent event)
Deprecated. use addSeedObject() instead.

This method is deprecated and supported for compatibility only. It will be removed in the next major release.

extractSeedData

protected int extractSeedData(Object obj)
                       throws IllegalArgumentException
Add the given event to the seed. This method will hash the current time, the toString() representation of the event, and System.identityHashCode(). The uncertainty per event is assumed to be 3 bits. This method is called by addSeedObject() with the object passed to it.
Overrides:
extractSeedData in class HashObjectSeedGenerator
Throws:
RandomException - if obj is not a subclass of java.awt.event.AWTEvent

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