File Coverage

blib/lib/Crypt/PRNG/Fortuna.pm
Criterion Covered Total %
statement 20 20 100.0
branch n/a
condition n/a
subroutine 12 12 100.0
pod 8 8 100.0
total 40 40 100.0


line stmt bran cond sub pod time code
1             package Crypt::PRNG::Fortuna;
2              
3 2     2   53290 use strict;
  2         10  
  2         48  
4 2     2   8 use warnings;
  2         5  
  2         126  
5             our $VERSION = '0.080';
6              
7 2     2   13 use base qw(Crypt::PRNG Exporter);
  2         3  
  2         502  
8             our %EXPORT_TAGS = ( all => [qw(random_bytes random_bytes_hex random_bytes_b64 random_bytes_b64u random_string random_string_from rand irand)] );
9             our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
10             our @EXPORT = qw();
11              
12 2     2   12 use CryptX;
  2         4  
  2         448  
13              
14             {
15             ### stolen from Bytes::Random::Secure
16             my $RNG_object = undef;
17             my $fetch_RNG = sub { # Lazily, instantiate the RNG object, but only once.
18             $RNG_object = Crypt::PRNG::Fortuna->new unless defined $RNG_object && ref($RNG_object) ne 'SCALAR';
19             return $RNG_object;
20             };
21 2000     2000 1 8116 sub rand { return $fetch_RNG->()->double(@_) }
22 1000     1000 1 1897 sub irand { return $fetch_RNG->()->int32(@_) }
23 1     1 1 6 sub random_bytes { return $fetch_RNG->()->bytes(@_) }
24 1     1 1 4 sub random_bytes_hex { return $fetch_RNG->()->bytes_hex(@_) }
25 1     1 1 3 sub random_bytes_b64 { return $fetch_RNG->()->bytes_b64(@_) }
26 1     1 1 4 sub random_bytes_b64u { return $fetch_RNG->()->bytes_b64u(@_) }
27 1     1 1 3 sub random_string_from { return $fetch_RNG->()->string_from(@_) }
28 1     1 1 3 sub random_string { return $fetch_RNG->()->string(@_) }
29             }
30              
31              
32             1;
33              
34             =pod
35              
36             =head1 NAME
37              
38             Crypt::PRNG::Fortuna - Cryptographically secure PRNG based on Fortuna algorithm
39              
40             =head1 SYNOPSIS
41              
42             ### Functional interface:
43             use Crypt::PRNG::Fortuna qw(random_bytes random_bytes_hex random_bytes_b64 random_bytes_b64u
44             random_string random_string_from rand irand);
45              
46             $octets = random_bytes(45);
47             $hex_string = random_bytes_hex(45);
48             $base64_string = random_bytes_b64(45);
49             $base64url_string = random_bytes_b64u(45);
50             $alphanumeric_string = random_string(30);
51             $string = random_string_from('ACGT', 64);
52             $floating_point_number_0_to_1 = rand;
53             $floating_point_number_0_to_88 = rand(88);
54             $unsigned_32bit_int = irand;
55              
56             ### OO interface:
57             use Crypt::PRNG::Fortuna;
58              
59             $prng = Crypt::PRNG::Fortuna->new;
60             #or
61             $prng = Crypt::PRNG::Fortuna->new("some data used for seeding PRNG");
62              
63             $octets = $prng->bytes(45);
64             $hex_string = $prng->bytes_hex(45);
65             $base64_string = $prng->bytes_b64(45);
66             $base64url_string = $prng->bytes_b64u(45);
67             $alphanumeric_string = $prng->string(30);
68             $string = $prng->string_from('ACGT', 64);
69             $floating_point_number_0_to_1 = rand;
70             $floating_point_number_0_to_88 = rand(88);
71             $unsigned_32bit_int = irand;
72              
73             =head1 DESCRIPTION
74              
75             Provides an interface to the Fortuna based pseudo random number generator
76              
77             All methods and functions are the same as for L.
78              
79             =head1 FUNCTIONS
80              
81             =head2 random_bytes
82              
83             See L.
84              
85             =head2 random_bytes_hex
86              
87             See L.
88              
89             =head2 random_bytes_b64
90              
91             See L.
92              
93             =head2 random_bytes_b64u
94              
95             See L.
96              
97             =head2 random_string
98              
99             See L.
100              
101             =head2 random_string_from
102              
103             See L.
104              
105             =head2 rand
106              
107             See L.
108              
109             =head2 irand
110              
111             See L.
112              
113             =head1 METHODS
114              
115             =head2 new
116              
117             See L.
118              
119             =head2 bytes
120              
121             See L.
122              
123             =head2 bytes_hex
124              
125             See L.
126              
127             =head2 bytes_b64
128              
129             See L.
130              
131             =head2 bytes_b64u
132              
133             See L.
134              
135             =head2 string
136              
137             See L.
138              
139             =head2 string_from
140              
141             See L.
142              
143             =head2 double
144              
145             See L.
146              
147             =head2 int32
148              
149             See L.
150              
151             =head1 SEE ALSO
152              
153             =over
154              
155             =item * L
156              
157             =item * L
158              
159             =back
160              
161             =cut