org.randomness
Class Truerandomness.SPI

java.lang.Object
  extended by org.randomness.Randomness
      extended by org.randomness.Truerandomness
          extended by org.randomness.Truerandomness.SPI
All Implemented Interfaces:
java.io.Closeable, java.nio.channels.Channel, java.nio.channels.ReadableByteChannel, java.nio.channels.ScatteringByteChannel
Enclosing class:
Truerandomness

public abstract class Truerandomness.SPI
extends Truerandomness

This class defines the Service Provider Interface (SPI) for the Truerandomness class.

Author:
Anton Kabysh

Nested Class Summary
 
Nested classes/interfaces inherited from class org.randomness.Truerandomness
Truerandomness.SPI
 
Constructor Summary
Truerandomness.SPI()
           
 
Method Summary
 int read(java.nio.ByteBuffer arg0)
          The generate function harvest random bits from entropy source per request, can determine entropy of requested bits (optional) and reduce to independent bits if requested bits has low quality entropy.
 
Methods inherited from class org.randomness.Truerandomness
close, equals, from, hashCode, isOpen, main, nextHashCodeEntropy, nextTimeEntropy, reset, test
 
Methods inherited from class org.randomness.Randomness
asRandom, bind, map, minlen, mixing, newBuffer, nextBoolean, nextByte, nextChar, nextCharASCII, nextDouble, nextFloat, nextHexString, nextInt, nextInt, nextLong, nextLong, nextProbability, nextShort, read, read, read, readFuture, readSink, reversed, shuffle, toString, tryRead
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Truerandomness.SPI

public Truerandomness.SPI()
Method Detail

read

public int read(java.nio.ByteBuffer arg0)
Description copied from class: Truerandomness
The generate function harvest random bits from entropy source per request, can determine entropy of requested bits (optional) and reduce to independent bits if requested bits has low quality entropy. In other words, reads a sequence harvested bytes from underlying entropy source into the given buffer. An attempt is made to read up to r bytes from TRNG, where r is the number of bytes remaining in the buffer, that is, buffer.remaining(), at the moment this method is invoked.

The process to obtain true-random bits from entropy source typically involves the following steps:

  1. Harvest bits - One first gathers some bits unknown to and unguessable by the adversary. These must come from some entropy source which is referred to a noise source.
  2. Determine entropy(optional) - The word “entropy” is used to describe a measure of randomness, i.e., a description of how hard a value is to guess. The second step is then to determine how many unguessable bits were thus harvested. Some entropy source are better than others in unguessability. But usually it is really hard to measure entropy of random input, so the better strategy to mix different entropy sources using hash mixing function.
  3. Reduce to independent bits (optional) - As a third step, one can compute a hash of the harvested bits to reduce them to independent, random bits. The hash function for this stage of operation needs to have each output bit functionally dependent on all input bits and functionally independent of all other output bits. Barring formal analysis, we assume that the hash functions which are claimed to be cryptographically strong (MD5 and SHA) have this characteristic.

Specified by:
read in interface java.nio.channels.ReadableByteChannel
Specified by:
read in class Truerandomness
Parameters:
arg0 - The buffer into which random bytes are to be transferred.
Returns:
The number of bytes read from TRNG, possibly zero, or -1 if the TRNG has reached end-of-stream.