Java Randomness Test Suite

JRandTest at SourceForge

com.fasteasytrade.JRandTest.Algo
Class MicaliSchnorrPrng

java.lang.Object
  extended bycom.fasteasytrade.JRandTest.Algo.Cipher
      extended bycom.fasteasytrade.JRandTest.Algo.MicaliSchnorrPrng

public class MicaliSchnorrPrng
extends Cipher

Micali-Schnorr Prng algorithm.

Implements algorithm directly from public published book.

The following program implements and tests the Micali-Schnorr random bits generator. The test suite is according to FIPS 140-1. See "Handbook of Applied Cryptography" by Alfred J. Menezes et al Section 5.4.4 pages 181 - 183 and 5.37 Algorithm page 186.

Author:
Zur Aougav

Field Summary
(package private)  int bit_length
          n's length/num of bits
(package private)  BigInteger e
          e is a random exponent we calculate on generation (in setup method)
(package private)  int k
          nLength = r + k k is the number of low bits we will use in the prng
(package private)  BigInteger n
          n = p * q, and calculations are done mod n.
(package private)  int nLength
          nLength is length of n
(package private)  BigInteger p
          prime (with probability < 2 ** -100)
(package private)  BigInteger q
          prime (with probability < 2 ** -100)
(package private)  int r
          nLength = r + k r is the number of high bits we will use in the prng
(package private)  BigInteger x
          x is the "state" of the prng.
(package private)  BigInteger x0
          x0 is the "initial state" of the prng.
 
Constructor Summary
(package private) MicaliSchnorrPrng()
           
(package private) MicaliSchnorrPrng(BigInteger n, BigInteger p, BigInteger q)
           
(package private) MicaliSchnorrPrng(BigInteger n, BigInteger p, BigInteger q, BigInteger x)
           
(package private) MicaliSchnorrPrng(int x)
           
 
Method Summary
 BigInteger getE()
           
 int getK()
           
 BigInteger getN()
          Public key.
 void getNextBits(byte[] result)
          calculate x**e mod n and returns lowest k bits, k/8 bytes, in result buffer.
 int getNLength()
           
 BigInteger getP()
          Secret key.
 BigInteger getQ()
          Secret key (need only one of p or q).
 int getR()
           
 BigInteger getX()
          Encryption: you need to get last x and write it to cipher output stream.
 void reset()
          Reset "state" of prng by setting x to x0 (initial x).
(package private)  boolean setup(int l)
          Generate the key and seed for Micali Schnorr Prng.
 
Methods inherited from class com.fasteasytrade.JRandTest.Algo.Cipher
compareBytes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bit_length

final int bit_length
n's length/num of bits

See Also:
Constant Field Values

n

BigInteger n
n = p * q, and calculations are done mod n.


p

BigInteger p
prime (with probability < 2 ** -100)


q

BigInteger q
prime (with probability < 2 ** -100)


x

BigInteger x
x is the "state" of the prng.

x = take r high bits of ( x**e mod n ).

returns k random bits from k low bits of ( x**e mod n ).


x0

BigInteger x0
x0 is the "initial state" of the prng.

reset method set x to x0.


e

BigInteger e
e is a random exponent we calculate on generation (in setup method)


nLength

int nLength
nLength is length of n


k

int k
nLength = r + k

k is the number of low bits we will use in the prng


r

int r
nLength = r + k

r is the number of high bits we will use in the prng

Constructor Detail

MicaliSchnorrPrng

MicaliSchnorrPrng()

MicaliSchnorrPrng

MicaliSchnorrPrng(int x)

MicaliSchnorrPrng

MicaliSchnorrPrng(BigInteger n,
                  BigInteger p,
                  BigInteger q)

MicaliSchnorrPrng

MicaliSchnorrPrng(BigInteger n,
                  BigInteger p,
                  BigInteger q,
                  BigInteger x)
Method Detail

setup

boolean setup(int l)
Generate the key and seed for Micali Schnorr Prng.

Select random p, q, n=p*q, x (mod n).

Parameters:
l - length of n, num of bits.

getNextBits

public void getNextBits(byte[] result)
calculate x**e mod n and returns lowest k bits, k/8 bytes, in result buffer.


getP

public BigInteger getP()
Secret key.

Returns:
p prime (with probability < 2 ** -100)

getQ

public BigInteger getQ()
Secret key (need only one of p or q).

Returns:
q prime (with probability < 2 ** -100)

getN

public BigInteger getN()
Public key.

Returns:
n = p * q

getE

public BigInteger getE()
Returns:
random exponent e

getX

public BigInteger getX()
Encryption: you need to get last x and write it to cipher output stream.

Decryption: you need to read "last x" from input stream, and calculate X0, the first x based on n (public key), p and q (secret key/keys).

Returns:
current x

getNLength

public int getNLength()
Returns:
length of n

getK

public int getK()
Returns:
k

getR

public int getR()
Returns:
r

reset

public void reset()
Reset "state" of prng by setting x to x0 (initial x).


Java Randomness Test Suite

JRandTest at SourceForge

JRandTest at SourceForge
Copyright © 2005 Zur Aougav. All Rights Reserved.