Java Randomness Test Suite

JRandTest at SourceForge

com.fasteasytrade.JRandTest.Algo
Class BBSPrng

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

public class BBSPrng
extends Cipher

BBS encryption algorithm.

The following program implements the Blum-Blum-Shub 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.40 Algorithm page 186.

Author:
Zur Aougav

Field Summary
(package private)  int bit_length
          n's length/num of bits
(package private)  BigInteger n
          n = p * q, and calculations are done mod n.
(package private)  BigInteger p
          prime (with probability < 2 ** -100)
(package private)  BigInteger q
          prime (with probability < 2 ** -100)
(package private)  BigInteger x
          x is the "state" of the prng. x = x**2 mod n.
(package private)  BigInteger x0
          x0 is the "initial state" of the prng.
 
Constructor Summary
(package private) BBSPrng()
           
(package private) BBSPrng(BigInteger n, BigInteger p, BigInteger q)
           
(package private) BBSPrng(BigInteger n, BigInteger p, BigInteger q, BigInteger x)
           
(package private) BBSPrng(int x)
           
 
Method Summary
 BigInteger getN()
          Public key.
 BigInteger getP()
          Secret key.
 BigInteger getQ()
          Secret key (need only one of p or q).
 BigInteger getX()
          Encryption: you need to get last x and write it to cipher output stream.
 long nextLong()
          calculate x**2 mod n and returns lowest 64 bits.
 void reset()
          Reset "state" of prng by setting x to x0 (initial x).
(package private)  void setup(int l)
          select random p, q, n=p*q, x (mod n).
 void setX(BigInteger x)
           
 
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 = x**2 mod n.


x0

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

reset method set x to x0.

Constructor Detail

BBSPrng

BBSPrng()

BBSPrng

BBSPrng(int x)

BBSPrng

BBSPrng(BigInteger n,
        BigInteger p,
        BigInteger q)

BBSPrng

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

setup

void setup(int l)
select random p, q, n=p*q, x (mod n).

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

nextLong

public long nextLong()
calculate x**2 mod n and returns lowest 64 bits.

Returns:
next long, 64 bits

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

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

setX

public void setX(BigInteger x)
Parameters:
x - new x0

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.