iaik.security.random
Class MessageDigestRandom

java.lang.Object
  |
  +--java.util.Random
        |
        +--java.security.SecureRandom
              |
              +--iaik.security.random.SecRandom
                    |
                    +--iaik.security.random.MessageDigestRandom
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
MD5Random, RipeMd160Random, SHA1Random, SHA256Random, SHA384Random, SHA512Random

public abstract class MessageDigestRandom
extends SecRandom

This class implements a secure pseudo-random number generator based on a MessageDigest. It cannot be used directly and has to be subclassed. Subclasses just have to call the superclass constructor with the MessageDigest object as parameter, everything else is taken care of. It will work for digests of any length.

The method used to generate the random bytes is based on a paper from BSI (Bundesamt fuer Sicherheit in der Informationstechnik) called AIS 20 (Anwendungshinweise und Interpretationen zum Schema), version 2.0, 02.12.1999. This algorithm is described in example E.5 of this paper.

Seeding of this implementation causes the new seed value to be concatenated with the existing internal seed. The hash of this concatenation becomes the new internal seed.
This means that the entropy of the internal seed is limited by the size of the hash values produced by the used hash algorithm; i.e. 160 bit for SHA-1.

Given a good message digest algorithm, the output will be evenly distributed. Due to the one-way property of the message digest function, it is infeasible to deduct the seed from the random bytes. The same holds for predicting future (or past) output knowing only previous and/or following output bytes.

Version:
File Revision 16
See Also:
MD5Random, SHA1Random, SHA256Random, SHA512Random, RipeMd160Random, SeedGenerator, Serialized Form

Constructor Summary
protected MessageDigestRandom(MessageDigest digest)
          Constructor for use by subclasses.
 
Method Summary
protected  void engineNextBytes(byte[] bytes)
          Return bytes.length random bytes.
protected  void engineSetSeed(byte[] seed)
          Add this seed to the internal seed.
 
Methods inherited from class iaik.security.random.SecRandom
getDefault, nextBytes, setDefault, setSeed, setSeed, setSeed
 
Methods inherited from class java.security.SecureRandom
generateSeed, getInstance, getInstance, getProvider, getSeed, next
 
Methods inherited from class java.util.Random
nextBoolean, nextDouble, nextFloat, nextGaussian, nextInt, nextInt, nextLong
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MessageDigestRandom

protected MessageDigestRandom(MessageDigest digest)
Constructor for use by subclasses. The given MessageDigest object itself will be used, it will not be cloned.
Method Detail

engineSetSeed

protected void engineSetSeed(byte[] seed)
Add this seed to the internal seed. This implementation concatenates the internal seed with the given seed and makes hash of this concatenation the new internal seed.
Overrides:
engineSetSeed in class SecRandom

engineNextBytes

protected void engineNextBytes(byte[] bytes)
Return bytes.length random bytes.
Overrides:
engineNextBytes in class SecRandom

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