bbs(
$o
,
$p
,
$q
,
$seed
,
$bits
);
"$o"
,
"$p"
,
"$q"
, and
"$seed"
are all Math::GMP or Math::GMPz objects.
$p
and
$q
must be large primes congruent to 3 modulus 4. (The bbs
function checks
$p
and
$q
for
congruence to 3 modulus 4, but does not
verify that
$p
and
$q
are, in fact, prime.)
Output a
$bits
-bit random bitstream to
$o
- calculated using the
Blum-Blum-Shub algorithm, based on the inputs
$p
,
$q
, and
$seed
. See
the bbs_seedgen documentation below
for
the requirements that
$seed
needs to meet.
bbs_seedgen(
$seed
,
$p
,
$q
);
"$seed"
,
"$p"
, and
"$q"
are all Math::GMP or Math::GMPz objects.
$p
and
$q
are the 2 large primes being used by the BlumBlumShub PRBG.
The seed needs to be less than N =
$p
*
$q
, and gcd(seed, N) must be 1.
This routine uses the mpz_urandomm() function to pseudorandomly
generate a seed less than N. (The supplied value of
$seed
is used to
seed mpz_urandomm.) If gcd(seed, N) != 1, then the seed is decremented
until
gcd(seed, N) == 1.
$seed
is then set to that seed value.
You can, of course,
write
your own routine to create the seed.
$bool
= monobit(
$op
);
$bool
= longrun(
$op
);
$bool
= runs(
$op
);
$bool
= poker(
$op
);
These are the 4 standard FIPS-140 statistical tests
for
testing
prbg
's. They return '
1
' for success and '
0'
for
failure.
They test 20000-bit pseudorandom sequences, stored in the
Math::GMPz/Math::GMP object
$op
.
$bool
= autocorrelation_20000(
$op
,
$offset
);
$op
is a sequence (Math::GMPz/Math::GMP object) of 20000 +
$offset
bits.
Returns true (
"success"
)
if
the
no
. of bits in
$op
not equal to their
$offset
-leftshifts lies in the range [9655 .. 10345] (inclusive).
Else returns 0 (
"failure"
).
(
$count
,
$x5val
) = autocorrelation(
$op
,
$offset
);
$op
is a sequence (Math::GMPz/Math::GMP object) of 20000 bits.
Returns (resp.) the
no
. of bits in
$op
not equal to their
$offset
-leftshifts, and the X5 value as specified in section 5.4.4
of
"Handbook of Applied Cryptography"
(Menezes at al).