Crypt-DSA

 view release on metacpan or  search on metacpan

lib/Crypt/DSA/Util.pm  view on Meta::CPAN

    my $n1 = $n - 1;
    my $one = $n - $n1;  # not just 1, but a bigint

    # find the power of two for the top bit of $n1
    my $p2 = $one;
    my $p2index = -1;
    ++$p2index, $p2 *= 2
	while $p2 <= $n1;
    $p2 /= 2;

    # number of iterations:  5 for 260-bit numbers, go up to 25 for smaller
    my $last_witness = 5;
    $last_witness += (260 - $p2index) / 13 if $p2index < 260;

    for my $witness_count (1..$last_witness) {
	# Fresh, independent CSPRNG witness every round.  The old code
	# accumulated witnesses from int(rand(1024)) -- Perl's predictable
	# Mersenne-Twister PRNG, and correlated round-to-round -- which
	# both weakens each round and breaks the independence the
	# Miller-Rabin error bound assumes.
	my $witness = _random_base($n);



( run in 0.377 second using v1.01-cache-2.11-cpan-4ab04211f4c )