Math_Random
[ class tree: Math_Random ] [ index: Math_Random ] [ all elements ]

Class: Math_Random_BlumBlumShub

Source Location: /Math/Random/BlumBlumShub.php

Class Overview

Math_Random
   |
   --Math_Random_BlumBlumShub

Implementation of the Blum Blum Shub cryptographically strong pseudorandom number generator.


Author(s):

Copyright:

  • 2005 Ants Aasma

Variables

Methods


Inherited Methods

Class: Math_Random

Math_Random::getFloat()
Return a random float
Math_Random::getInteger()
Return a random integer
Math_Random::getMaxInteger()
Return maximum supported integer
Math_Random::getMinInteger()
Return minimum supported integer
Math_Random::getString()
Get a string of random characters

Class Details

[line 71]
Implementation of the Blum Blum Shub cryptographically strong pseudorandom number generator.

The Blum Blum Shub (BBS) random number generator is a provably secure pseudorandom number generator. See this paper for reference about its necessity and references to formal proof of its cryptographic strength.

For this method to be useful a truly random source is needed. It can only be used to expand the initial conditions.

WARNING: currently a patched version of ext/gmp is required to generate blum primes. Support for gmp_nextprime() function is required.




Tags:

license:  BSD License (3 Clause)
copyright:  2005 Ants Aasma
author:  Ants Aasma <ants.aasma@gmail.com>


[ Top ]


Class Variables

$bits =

[line 89]

Number of bits in currently used modulo.



Tags:

access:  protected

Type:   int


[ Top ]

$loglogmodulo =

[line 95]

2nd logarithm of the currently used modulo.



Tags:

access:  protected

Type:   int


[ Top ]

$modulo =

[line 77]

The modulo of used arithmetic. A gmp integer resource.



Tags:

access:  protected

Type:   resource


[ Top ]

$unusedbits =

[line 101]

Number of bits unused from current quadratic residue.



Tags:

access:  protected

Type:   int


[ Top ]

$x =

[line 83]

Current quadratic residue. A gmp integer resource.



Tags:

access:  protected

Type:   resource


[ Top ]



Class Methods


constructor __construct [line 197]

Math_Random_BlumBlumShub __construct( resource $modulo)

Constructor



Parameters:

resource   $modulo   a gmp integer specifing generators modulo

[ Top ]

method generateBlumInt [line 117]

resource generateBlumInt( Math_Random $source, int $bits)

Returns a random Blum prime with requested length

Returns an Blum prime with length of at least $bits. A Blum prime is a prime that has a modulo 4 residue of 3. The returned value is a gmp resource.




Tags:

return:  a random Blum prime
static:  
throws:  Math_Random_Exception when the GMP extension isn't patched.


Parameters:

Math_Random   $source   random source used to generate the prime
int   $bits   the size of the prime to generate in bits

[ Top ]

method getBitstring [line 250]

string getBitstring( int $bits)

Get a string of zeros and ones



Tags:

return:  string of random bits
throws:  Math_Random_UninitializedException when the instance isn't seeded.


Parameters:

int   $bits   number of bits to return

[ Top ]

method getInteger [line 326]

int getInteger( int $min, int $max)

Return a random integer

Returns a random integer between $min and $max (inclusive).




Tags:

return:  Random integer
throws:  Math_Random_UninitializedException when the instance isn't seeded.


Overrides Math_Random::getInteger() (Return a random integer)

Parameters:

int   $min   minimum value of the random number
int   $max   maximum value of the random number

[ Top ]

method getMaxInteger [line 310]

int getMaxInteger( )

Return maximum supported integer

The value returned by this function is the upper limit to the getInteger method parameters. Values above this are not supported by the used class and will most likely not work.




Tags:

return:  Minimum supported integer


Overrides Math_Random::getMaxInteger() (Return maximum supported integer)

[ Top ]

method getMinInteger [line 296]

int getMinInteger( )

Return minimum supported integer

The value returned by this function is the lower limit to the getInteger method parameters. Values below this are not supported by the used class and will most likely not work.




Tags:

return:  Minimum supported integer


Overrides Math_Random::getMinInteger() (Return minimum supported integer)

[ Top ]

method getString [line 282]

string getString( int $len)

Get a string of random characters

Returns a binary string of 8bit characters with the specified length.




Tags:

return:  string of random characters
throws:  Math_Random_UninitializedException when the instance isn't seeded.


Overrides Math_Random::getString() (Get a string of random characters)

Parameters:

int   $len   Length of string to return

[ Top ]

method initializeFromSource [line 165]

void initializeFromSource( Math_Random $modulosource, int $modulobits, [Math_Random $xsource = null], [int $xbits = null], Math_Random_BlumBlumShaw 4)

Factory method to initialize the generator from a random source

Creates an instance of the BBS PRNG and initializes values from specified random source. The length of the modulo generated is at least $modulobits bits in length. Because the BBS algorithm is proven to be at least as strong as the problem of factoring the modulo one can take the bit length of RSA modulo as a guidance of reasonable values.

If $xsource is not specified the random seed is initialized from the same source as the modulo.

If $xbits is not specified the length of the random seed is set to be same as the generated modulo.




Tags:

static:  
throws:  Math_Random_Exception when the GMP extension isn't patched.
throws:  Math_Random_InvalidArgumentException when passed random source isn't an Math_Random instance.


Parameters:

Math_Random   $modulosource   entropy source used to specify the modulo
int   $modulobits   length of modulo to generate
Math_Random   $xsource   entropy source used to seed the generator
int   $xbits   length of the seed
Math_Random_BlumBlumShaw   4   generated instance

[ Top ]

method setModulo [line 210]

void setModulo( resource $modulo)

Reset the instances modulo variable



Tags:

throws:  Math_Random_InvalidArgumentException when passed parameter isn't an GMP resource


Parameters:

resource   $modulo   a gmp integer specifing generators modulo

[ Top ]

method setSeed [line 228]

null setSeed( mixed $x0)

Seeds the pseudorandom number generator



Tags:

throws:  Math_Random_InvalidArgumentException when passed parameter isn't an GMP resource


[ Top ]


Documentation generated on Sun, 09 Oct 2005 06:53:24 +0300 by phpDocumentor 1.3.0RC3